1 /* readelf.c -- display contents of an ELF format file
2 Copyright (C) 1998-2025 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 #ifdef SUPPORT_DISASSEMBLY
192 #define DISASS_DUMP (1 << 1) /* The -i command line switch. */
194 #define DEBUG_DUMP (1 << 2) /* The -w command line switch. */
195 #define STRING_DUMP (1 << 3) /* The -p command line switch. */
196 #define RELOC_DUMP (1 << 4) /* The -R command line switch. */
197 #define CTF_DUMP (1 << 5) /* The --ctf command line switch. */
198 #define SFRAME_DUMP (1 << 6) /* The --sframe command line switch. */
199 #define AUTO_DUMP (1 << 7) /* The -j command line switch. */
201 typedef unsigned char dump_type
;
203 /* A linked list of the section names for which dumps were requested. */
204 struct dump_list_entry
208 struct dump_list_entry
* next
;
211 /* A dynamic array of flags indicating for which sections a dump
212 has been requested via command line switches. */
215 dump_type
* dump_sects
;
216 unsigned int num_dump_sects
;
219 static struct dump_data cmdline
;
221 static struct dump_list_entry
* dump_sects_byname
;
223 char * program_name
= "readelf";
225 static bool show_name
= false;
226 static bool do_dynamic
= false;
227 static bool do_syms
= false;
228 static bool do_dyn_syms
= false;
229 static bool do_lto_syms
= false;
230 static bool do_reloc
= false;
231 static bool do_sections
= false;
232 static bool do_got_section_contents
= false;
233 static bool do_section_groups
= false;
234 static bool do_section_details
= false;
235 static bool do_segments
= false;
236 static bool do_unwind
= false;
237 static bool do_using_dynamic
= false;
238 static bool do_header
= false;
239 static bool do_dump
= false;
240 static bool do_version
= false;
241 static bool do_histogram
= false;
242 static bool do_debugging
= false;
243 static bool do_ctf
= false;
244 static bool do_sframe
= false;
245 static bool do_arch
= false;
246 static bool do_notes
= false;
247 static bool do_archive_index
= false;
248 static bool check_all
= false;
249 static bool is_32bit_elf
= false;
250 static bool decompress_dumps
= false;
251 static bool do_not_show_symbol_truncation
= false;
252 static bool do_demangle
= false; /* Pretty print C++ symbol names. */
253 static bool process_links
= false;
254 static bool dump_any_debugging
= false;
255 static bool extra_sym_info
= false;
256 static int demangle_flags
= DMGL_ANSI
| DMGL_PARAMS
;
257 static int sym_base
= 0;
259 static char *dump_ctf_parent_name
;
260 static char *dump_ctf_symtab_name
;
261 static char *dump_ctf_strtab_name
;
265 struct group_list
* next
;
266 unsigned int section_index
;
271 struct group_list
* root
;
272 unsigned int group_index
;
275 typedef struct filedata
277 const char * file_name
;
281 Elf_Internal_Ehdr file_header
;
282 uint64_t archive_file_offset
;
283 uint64_t archive_file_size
;
284 /* Everything below this point is cleared out by free_filedata. */
285 Elf_Internal_Shdr
* section_headers
;
286 Elf_Internal_Phdr
* program_headers
;
288 uint64_t string_table_length
;
289 uint64_t dynamic_addr
;
290 uint64_t dynamic_size
;
291 uint64_t dynamic_nent
;
292 Elf_Internal_Dyn
* dynamic_section
;
293 Elf_Internal_Shdr
* dynamic_strtab_section
;
294 char * dynamic_strings
;
295 uint64_t dynamic_strings_length
;
296 Elf_Internal_Shdr
* dynamic_symtab_section
;
297 uint64_t num_dynamic_syms
;
298 Elf_Internal_Sym
* dynamic_symbols
;
299 uint64_t version_info
[16];
300 unsigned int dynamic_syminfo_nent
;
301 Elf_Internal_Syminfo
* dynamic_syminfo
;
302 uint64_t dynamic_syminfo_offset
;
307 uint64_t ngnubuckets
;
309 uint64_t * gnubuckets
;
310 uint64_t * gnuchains
;
313 char * program_interpreter
;
314 uint64_t dynamic_info
[DT_RELRENT
+ 1];
315 uint64_t dynamic_info_DT_GNU_HASH
;
316 uint64_t dynamic_info_DT_MIPS_XHASH
;
317 elf_section_list
* symtab_shndx_list
;
319 struct group
* section_groups
;
320 struct group
** section_headers_groups
;
321 /* A dynamic array of flags indicating for which sections a dump of
322 some kind has been requested. It is reset on a per-object file
323 basis and then initialised from the cmdline_dump_sects array,
324 the results of interpreting the -w switch, and the
325 dump_sects_byname list. */
326 struct dump_data dump
;
329 /* How to print a vma value. */
330 typedef enum print_mode
348 typedef enum unicode_display_type
356 } unicode_display_type
;
358 static unicode_display_type unicode_display
= unicode_default
;
368 /* Versioned symbol info. */
369 enum versioned_symbol_info
376 /* Relocation entries */
378 typedef struct elf_relocation
380 bfd_vma r_offset
; /* Location at which to apply the action */
381 bfd_vma r_addend
; /* Constant addend used to compute value */
382 const char *r_name
; /* Relocation name. */
383 char *r_symbol
; /* Relocation symbol. */
384 relocation_type r_type
; /* Relocation type. */
387 static elf_relocation
*all_relocations_root
;
388 static elf_relocation
*all_relocations
;
389 static size_t all_relocations_count
;
392 fseek64 (FILE *stream
, int64_t offset
, int whence
)
394 #if defined (HAVE_FSEEKO64)
401 return fseeko64 (stream
, o
, whence
);
402 #elif defined (HAVE_FSEEKO)
409 return fseeko (stream
, o
, whence
);
417 return fseek (stream
, o
, whence
);
421 static const char * get_symbol_version_string
422 (Filedata
*, bool, const char *, size_t, unsigned,
423 Elf_Internal_Sym
*, enum versioned_symbol_info
*, unsigned short *);
425 static bool process_notes_at
426 (Filedata
*, Elf_Internal_Shdr
*, uint64_t, uint64_t, uint64_t);
430 static inline const char *
431 section_name (const Filedata
*filedata
, const Elf_Internal_Shdr
*hdr
)
433 return filedata
->string_table
+ hdr
->sh_name
;
437 section_name_valid (const Filedata
*filedata
, const Elf_Internal_Shdr
*hdr
)
439 return (filedata
!= NULL
441 && filedata
->string_table
!= NULL
442 && hdr
->sh_name
< filedata
->string_table_length
);
445 /* Returns true if the given index is real/valid. Note: "real" here
446 means "references a real section in the section header" and not
447 "is a valid section index as per the ELF standard". */
450 section_index_real (const Filedata
*filedata
, unsigned int ndx
)
452 return (filedata
!= NULL
453 && filedata
->section_headers
!= NULL
454 && ndx
< filedata
->file_header
.e_shnum
458 #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
461 valid_symbol_name (const char *strtab
, size_t strtab_size
, uint64_t offset
)
463 return strtab
!= NULL
&& offset
< strtab_size
;
467 valid_dynamic_name (const Filedata
*filedata
, uint64_t offset
)
469 return valid_symbol_name (filedata
->dynamic_strings
,
470 filedata
->dynamic_strings_length
, offset
);
473 /* GET_DYNAMIC_NAME asssumes that VALID_DYNAMIC_NAME has
474 already been called and verified that the string exists. */
475 static inline const char *
476 get_dynamic_name (const Filedata
*filedata
, size_t offset
)
478 return filedata
->dynamic_strings
+ offset
;
481 #define REMOVE_ARCH_BITS(ADDR) \
484 if (filedata->file_header.e_machine == EM_ARM) \
489 /* Get the correct GNU hash section name. */
490 #define GNU_HASH_SECTION_NAME(filedata) \
491 filedata->dynamic_info_DT_MIPS_XHASH ? ".MIPS.xhash" : ".gnu.hash"
493 /* Retrieve NMEMB structures, each SIZE bytes long from FILEDATA starting at
494 OFFSET + the offset of the current archive member, if we are examining an
495 archive. Put the retrieved data into VAR, if it is not NULL. Otherwise
496 allocate a buffer using malloc and fill that. In either case return the
497 pointer to the start of the retrieved data or NULL if something went wrong.
498 If something does go wrong and REASON is not NULL then emit an error
499 message using REASON as part of the context. */
510 uint64_t amt
= size
* nmemb
;
512 if (size
== 0 || nmemb
== 0)
515 /* If size_t is smaller than uint64_t, eg because you are building
516 on a 32-bit host, then make sure that when the sizes are cast to
517 size_t no information is lost. */
518 if ((size_t) size
!= size
519 || (size_t) nmemb
!= nmemb
520 || (size_t) amt
!= amt
521 || amt
/ size
!= nmemb
522 || (size_t) amt
+ 1 == 0)
525 error (_("Size overflow prevents reading %" PRIu64
526 " elements of size %" PRIu64
" for %s\n"),
527 nmemb
, size
, reason
);
531 /* Be kind to memory checkers (eg valgrind, address sanitizer) by not
532 attempting to allocate memory when the read is bound to fail. */
533 if (filedata
->archive_file_offset
> filedata
->file_size
534 || offset
> filedata
->file_size
- filedata
->archive_file_offset
535 || amt
> filedata
->file_size
- filedata
->archive_file_offset
- offset
)
538 error (_("Reading %" PRIu64
" bytes extends past end of file for %s\n"),
543 if (fseek64 (filedata
->handle
, filedata
->archive_file_offset
+ offset
,
547 error (_("Unable to seek to %#" PRIx64
" for %s\n"),
548 filedata
->archive_file_offset
+ offset
, reason
);
555 /* + 1 so that we can '\0' terminate invalid string table sections. */
556 mvar
= malloc ((size_t) amt
+ 1);
561 error (_("Out of memory allocating %" PRIu64
" bytes for %s\n"),
566 ((char *) mvar
)[amt
] = '\0';
569 if (fread (mvar
, (size_t) size
, (size_t) nmemb
, filedata
->handle
) != nmemb
)
572 error (_("Unable to read in %" PRIu64
" bytes of %s\n"),
582 /* Print a VMA value in the MODE specified.
583 Returns the number of characters displayed. */
586 print_vma (uint64_t vma
, print_mode mode
)
597 return nc
+ printf ("%16.16" PRIx64
, vma
);
598 return nc
+ printf ("%8.8" PRIx64
, vma
);
602 return printf ("%08" PRIx64
, vma
);
603 return printf ("%016" PRIx64
, vma
);
607 return printf ("%5" PRId64
, vma
);
613 return nc
+ printf ("%" PRIx64
, vma
);
619 return nc
+ printf ("%05" PRIx64
, vma
);
622 return printf ("%" PRId64
, vma
);
625 return printf ("%" PRIu64
, vma
);
628 return printf ("%5" PRIu64
, vma
);
631 return printf ("%" PRIo64
, vma
);
634 return printf ("%5" PRIo64
, vma
);
637 /* FIXME: Report unrecognised mode ? */
643 /* Display a symbol on stdout. Handles the display of control characters and
644 multibye characters (assuming the host environment supports them).
646 Display at most abs(WIDTH) characters, truncating as necessary,
647 unless do_wide or extra_sym_info is true.
649 If truncation will happen and do_not_show_symbol_truncation is FALSE then display
650 abs(WIDTH) - 5 characters followed by "[...]".
652 If WIDTH is negative then ensure that the output is at least (- WIDTH) characters,
653 padding as necessary.
655 Returns the number of emitted characters. */
658 print_symbol_name (signed int width
, const char * symbol
)
660 bool extra_padding
= false;
661 bool do_dots
= false;
662 signed int num_printed
= 0;
663 #ifdef HAVE_MBSTATE_T
666 unsigned int width_remaining
;
667 const void * alloced_symbol
= NULL
;
671 /* Keep the width positive. This helps the code below. */
673 extra_padding
= true;
678 if (do_wide
|| extra_sym_info
)
679 /* Set the remaining width to a very large value.
680 This simplifies the code below. */
681 width_remaining
= INT_MAX
;
684 width_remaining
= width
;
686 if (! do_not_show_symbol_truncation
687 && (int) strlen (symbol
) > width
)
689 width_remaining
-= 5;
690 if ((int) width_remaining
< 0)
696 #ifdef HAVE_MBSTATE_T
697 /* Initialise the multibyte conversion state. */
698 memset (& state
, 0, sizeof (state
));
701 if (do_demangle
&& *symbol
)
703 const char * res
= cplus_demangle (symbol
, demangle_flags
);
706 alloced_symbol
= symbol
= res
;
709 while (width_remaining
)
712 const char c
= *symbol
++;
723 else if (ISCNTRL (c
))
725 /* Do not print control characters directly as they can affect terminal
726 settings. Such characters usually appear in the names generated
727 by the assembler for local labels. */
729 if (width_remaining
< 2)
732 printf ("^%c", c
+ 0x40);
733 width_remaining
-= 2;
738 if (width_remaining
< 5)
741 width_remaining
-= 5;
744 else if (unicode_display
!= unicode_locale
745 && unicode_display
!= unicode_default
)
747 /* Display unicode characters as something else. */
748 unsigned char bytes
[4];
761 bytes
[1] = *symbol
++;
763 if ((bytes
[1] & 0xc0) != 0x80)
766 /* Do not consume this character. It may only
767 be the first byte in the sequence that was
772 else if ((bytes
[0] & 0x20) == 0)
779 bytes
[2] = *symbol
++;
781 if ((bytes
[2] & 0xc0) != 0x80)
787 else if ((bytes
[0] & 0x10) == 0)
794 bytes
[3] = *symbol
++;
798 if ((bytes
[3] & 0xc0) != 0x80)
810 if (unicode_display
== unicode_invalid
)
813 if (unicode_display
== unicode_hex
|| ! is_utf8
)
817 if (width_remaining
< (nbytes
* 2) + 2)
820 putchar (is_utf8
? '<' : '{');
822 for (i
= 0; i
< nbytes
; i
++)
823 printf ("%02x", bytes
[i
]);
824 putchar (is_utf8
? '>' : '}');
828 if (unicode_display
== unicode_highlight
&& isatty (1))
829 printf ("\x1B[31;47m"); /* Red. */
834 if (width_remaining
< 6)
836 printf ("\\u%02x%02x",
837 (bytes
[0] & 0x1c) >> 2,
838 ((bytes
[0] & 0x03) << 6) | (bytes
[1] & 0x3f));
841 if (width_remaining
< 6)
843 printf ("\\u%02x%02x",
844 ((bytes
[0] & 0x0f) << 4) | ((bytes
[1] & 0x3c) >> 2),
845 ((bytes
[1] & 0x03) << 6) | (bytes
[2] & 0x3f));
848 if (width_remaining
< 8)
850 printf ("\\u%02x%02x%02x",
851 ((bytes
[0] & 0x07) << 2) | ((bytes
[1] & 0x30) >> 4),
852 ((bytes
[1] & 0x0f) << 4) | ((bytes
[2] & 0x3c) >> 2),
853 ((bytes
[2] & 0x03) << 6) | (bytes
[3] & 0x3f));
861 if (unicode_display
== unicode_highlight
&& isatty (1))
862 printf ("\033[0m"); /* Default colour. */
865 if (bytes
[nbytes
- 1] == 0)
870 #ifdef HAVE_MBSTATE_T
873 /* Let printf do the hard work of displaying multibyte characters. */
874 printf ("%.1s", symbol
- 1);
878 #ifdef HAVE_MBSTATE_T
879 /* Try to find out how many bytes made up the character that was
880 just printed. Advance the symbol pointer past the bytes that
882 n
= mbrtowc (& w
, symbol
- 1, MB_CUR_MAX
, & state
);
886 if (n
!= (size_t) -1 && n
!= (size_t) -2 && n
> 0)
892 num_printed
+= printf ("[...]");
894 if (extra_padding
&& num_printed
< width
)
896 /* Fill in the remaining spaces. */
897 printf ("%-*s", width
- num_printed
, " ");
901 free ((void *) alloced_symbol
);
905 /* Returns a pointer to a static buffer containing a printable version of
906 STRING. Uses a rotating array of static buffers, so that multiple
907 successive calls will still work. eg when used in a call to printf().
909 If supplied MAX_LEN is the maximum number of characters to be read
910 starting from STRING.
912 This function is similar to print_symbol_name(), except that it does
913 not try to print multibyte characters, it just shows them as hex values.
915 If the string is too long for the static buffer or if it is not
916 terminated then a truncated version of the string will be returned. */
919 printable_string (const char * string
, unsigned int max_len
)
921 #define NUM_STRING_BUFS 5
922 #define MAX_STRING_LEN 256
924 static int string_buf_index
= 0;
925 static char string_buf
[NUM_STRING_BUFS
][MAX_STRING_LEN
+ 1];
930 /* Select a buffer to use. */
931 buf_start
= buf
= string_buf
[string_buf_index
];
932 if (++ string_buf_index
>= NUM_STRING_BUFS
)
933 string_buf_index
= 0;
936 unsigned int remaining
= MAX_STRING_LEN
;
938 while ((c
= * string
++) != 0)
949 else if (ISPRINT (c
))
956 static char hex
[17] = "0123456789ABCDEF";
961 * buf
++ = hex
[(c
& 0xf0) >> 4];
962 * buf
++ = hex
[c
& 0x0f];
982 /* Returns a pointer to a static buffer containing a
983 printable version of the given section's name. */
986 printable_section_name (Filedata
* filedata
, const Elf_Internal_Shdr
* sec
)
988 /* Validate the input parameters. */
989 if (filedata
== NULL
)
990 return _("<internal error>");
993 if (filedata
->string_table
== NULL
)
994 return _("<no-strings>");
995 if (sec
->sh_name
>= filedata
->string_table_length
)
996 return _("<corrupt>");
998 return printable_string (section_name (filedata
, sec
),
999 filedata
->string_table_length
- sec
->sh_name
);
1002 /* Return TRUE if the current file is for IA-64 machine and OpenVMS ABI.
1003 This OS has so many departures from the ELF standard that we test it at
1007 is_ia64_vms (Filedata
* filedata
)
1009 return filedata
->file_header
.e_machine
== EM_IA_64
1010 && filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_OPENVMS
;
1014 printable_section_name_from_index (Filedata
* filedata
,
1018 if (is_special
!= NULL
)
1019 * is_special
= true;
1023 case SHN_UNDEF
: return "UND";
1024 case SHN_ABS
: return "ABS";
1025 case SHN_COMMON
: return "COM";
1029 if (filedata
!= NULL
)
1031 switch (filedata
->file_header
.e_machine
)
1034 if (ndx
== SHN_MIPS_SCOMMON
)
1036 if (ndx
== SHN_MIPS_SUNDEFINED
)
1041 if (ndx
== SHN_TIC6X_SCOMMON
)
1048 if (ndx
== SHN_X86_64_LCOMMON
)
1053 if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_HPUX
1054 && ndx
== SHN_IA_64_ANSI_COMMON
)
1057 if (is_ia64_vms (filedata
) && ndx
== SHN_IA_64_VMS_SYMVEC
)
1058 return "VMS_SYMVEC";
1065 if (filedata
->section_headers
!= NULL
1066 && ndx
< filedata
->file_header
.e_shnum
)
1070 res
= printable_section_name (filedata
, filedata
->section_headers
+ ndx
);
1071 if (is_special
!= NULL
)
1072 * is_special
= (res
[0] == '<');
1078 static char name_buf
[40];
1079 unsigned int short_ndx
= (unsigned int) (ndx
& 0xffff);
1081 if (ndx
>= SHN_LOPROC
&& ndx
<= SHN_HIPROC
)
1082 sprintf (name_buf
, "PRC[0x%04x]", short_ndx
);
1083 else if (ndx
>= SHN_LOOS
&& ndx
<= SHN_HIOS
)
1084 sprintf (name_buf
, "OS [0x%04x]", short_ndx
);
1085 else if (ndx
>= SHN_LORESERVE
)
1086 sprintf (name_buf
, "RSV[0x%04x]", short_ndx
);
1087 else if (filedata
->file_header
.e_shnum
!= 0
1088 && ndx
>= filedata
->file_header
.e_shnum
)
1089 sprintf (name_buf
, _("BAD[0x%lx]"), (long) ndx
);
1091 sprintf (name_buf
, "<section 0x%lx>", (long) ndx
);
1096 /* Return a pointer to section NAME, or NULL if no such section exists. */
1098 static Elf_Internal_Shdr
*
1099 find_section (Filedata
* filedata
, const char * name
)
1103 if (filedata
->section_headers
== NULL
)
1106 for (i
= 0; i
< filedata
->file_header
.e_shnum
; i
++)
1107 if (section_name_valid (filedata
, filedata
->section_headers
+ i
)
1108 && streq (section_name (filedata
, filedata
->section_headers
+ i
),
1110 return filedata
->section_headers
+ i
;
1115 /* Return a pointer to a section containing ADDR, or NULL if no such
1118 static Elf_Internal_Shdr
*
1119 find_section_by_address (Filedata
* filedata
, uint64_t addr
)
1123 if (filedata
->section_headers
== NULL
)
1126 for (i
= 0; i
< filedata
->file_header
.e_shnum
; i
++)
1128 Elf_Internal_Shdr
*sec
= filedata
->section_headers
+ i
;
1130 if (addr
>= sec
->sh_addr
&& addr
< sec
->sh_addr
+ sec
->sh_size
)
1137 static Elf_Internal_Shdr
*
1138 find_section_by_type (Filedata
* filedata
, unsigned int type
)
1142 if (filedata
->section_headers
== NULL
)
1145 for (i
= 0; i
< filedata
->file_header
.e_shnum
; i
++)
1147 Elf_Internal_Shdr
*sec
= filedata
->section_headers
+ i
;
1149 if (sec
->sh_type
== type
)
1156 static Elf_Internal_Shdr
*
1157 find_section_by_name (Filedata
* filedata
, const char * name
)
1161 if (filedata
->section_headers
== NULL
|| filedata
->string_table_length
== 0)
1164 for (i
= 0; i
< filedata
->file_header
.e_shnum
; i
++)
1166 Elf_Internal_Shdr
*sec
= filedata
->section_headers
+ i
;
1168 if (sec
->sh_name
< filedata
->string_table_length
1169 && streq (name
, filedata
->string_table
+ sec
->sh_name
))
1176 /* Return a pointer to section NAME, or NULL if no such section exists,
1177 restricted to the list of sections given in SET. */
1179 static Elf_Internal_Shdr
*
1180 find_section_in_set (Filedata
* filedata
, const char * name
, unsigned int * set
)
1184 if (filedata
->section_headers
== NULL
)
1189 while ((i
= *set
++) > 0)
1191 /* See PR 21156 for a reproducer. */
1192 if (i
>= filedata
->file_header
.e_shnum
)
1193 continue; /* FIXME: Should we issue an error message ? */
1195 if (section_name_valid (filedata
, filedata
->section_headers
+ i
)
1196 && streq (section_name (filedata
, filedata
->section_headers
+ i
),
1198 return filedata
->section_headers
+ i
;
1202 return find_section (filedata
, name
);
1205 /* Guess the relocation size commonly used by the specific machines. */
1208 guess_is_rela (unsigned int e_machine
)
1212 /* Targets that use REL relocations. */
1218 case EM_CYGNUS_D10V
:
1221 case EM_MIPS_RS3_LE
:
1222 case EM_CYGNUS_M32R
:
1229 /* Targets that use RELA relocations. */
1233 case EM_ADAPTEVA_EPIPHANY
:
1235 case EM_ALTERA_NIOS2
:
1237 case EM_ARC_COMPACT
:
1238 case EM_ARC_COMPACT2
:
1239 case EM_ARC_COMPACT3
:
1240 case EM_ARC_COMPACT3_64
:
1249 case EM_CYGNUS_D30V
:
1252 case EM_CYGNUS_FR30
:
1262 case EM_LATTICEMICO32
:
1271 case EM_CYGNUS_MN10200
:
1273 case EM_CYGNUS_MN10300
:
1291 case EM_SPARC32PLUS
:
1299 case EM_CYGNUS_V850
:
1309 case EM_MICROBLAZE_OLD
:
1310 case EM_WEBASSEMBLY
:
1331 warn (_("Don't know about relocations on this machine architecture\n"));
1336 /* Load RELA type relocations from FILEDATA at REL_OFFSET extending for REL_SIZE bytes.
1337 Returns TRUE upon success, FALSE otherwise. If successful then a
1338 pointer to a malloc'ed buffer containing the relocs is placed in *RELASP,
1339 and the number of relocs loaded is placed in *NRELASP. It is the caller's
1340 responsibility to free the allocated buffer. */
1343 slurp_rela_relocs (Filedata
*filedata
,
1344 uint64_t rel_offset
,
1346 Elf_Internal_Rela
**relasp
,
1349 Elf_Internal_Rela
* relas
;
1355 Elf32_External_Rela
* erelas
;
1357 erelas
= (Elf32_External_Rela
*) get_data (NULL
, filedata
, rel_offset
, 1,
1358 rel_size
, _("32-bit relocation data"));
1362 nrelas
= rel_size
/ sizeof (Elf32_External_Rela
);
1364 relas
= (Elf_Internal_Rela
*) cmalloc (nrelas
,
1365 sizeof (Elf_Internal_Rela
));
1370 error (_("out of memory parsing relocs\n"));
1374 for (i
= 0; i
< nrelas
; i
++)
1376 relas
[i
].r_offset
= BYTE_GET (erelas
[i
].r_offset
);
1377 relas
[i
].r_info
= BYTE_GET (erelas
[i
].r_info
);
1378 relas
[i
].r_addend
= BYTE_GET_SIGNED (erelas
[i
].r_addend
);
1385 Elf64_External_Rela
* erelas
;
1387 erelas
= (Elf64_External_Rela
*) get_data (NULL
, filedata
, rel_offset
, 1,
1388 rel_size
, _("64-bit relocation data"));
1392 nrelas
= rel_size
/ sizeof (Elf64_External_Rela
);
1394 relas
= (Elf_Internal_Rela
*) cmalloc (nrelas
,
1395 sizeof (Elf_Internal_Rela
));
1400 error (_("out of memory parsing relocs\n"));
1404 for (i
= 0; i
< nrelas
; i
++)
1406 relas
[i
].r_offset
= BYTE_GET (erelas
[i
].r_offset
);
1407 relas
[i
].r_info
= BYTE_GET (erelas
[i
].r_info
);
1408 relas
[i
].r_addend
= BYTE_GET_SIGNED (erelas
[i
].r_addend
);
1410 if (filedata
->file_header
.e_machine
== EM_MIPS
1411 && filedata
->file_header
.e_ident
[EI_DATA
] != ELFDATA2MSB
)
1413 /* In little-endian objects, r_info isn't really a
1414 64-bit little-endian value: it has a 32-bit
1415 little-endian symbol index followed by four
1416 individual byte fields. Reorder INFO
1418 uint64_t inf
= relas
[i
].r_info
;
1419 inf
= (((inf
& 0xffffffff) << 32)
1420 | ((inf
>> 56) & 0xff)
1421 | ((inf
>> 40) & 0xff00)
1422 | ((inf
>> 24) & 0xff0000)
1423 | ((inf
>> 8) & 0xff000000));
1424 relas
[i
].r_info
= inf
;
1436 /* Load REL type relocations from FILEDATA at REL_OFFSET extending for REL_SIZE bytes.
1437 Returns TRUE upon success, FALSE otherwise. If successful then a
1438 pointer to a malloc'ed buffer containing the relocs is placed in *RELSP,
1439 and the number of relocs loaded is placed in *NRELSP. It is the caller's
1440 responsibility to free the allocated buffer. */
1443 slurp_rel_relocs (Filedata
*filedata
,
1444 uint64_t rel_offset
,
1446 Elf_Internal_Rela
**relsp
,
1449 Elf_Internal_Rela
* rels
;
1455 Elf32_External_Rel
* erels
;
1457 erels
= (Elf32_External_Rel
*) get_data (NULL
, filedata
, rel_offset
, 1,
1458 rel_size
, _("32-bit relocation data"));
1462 nrels
= rel_size
/ sizeof (Elf32_External_Rel
);
1464 rels
= (Elf_Internal_Rela
*) cmalloc (nrels
, sizeof (Elf_Internal_Rela
));
1469 error (_("out of memory parsing relocs\n"));
1473 for (i
= 0; i
< nrels
; i
++)
1475 rels
[i
].r_offset
= BYTE_GET (erels
[i
].r_offset
);
1476 rels
[i
].r_info
= BYTE_GET (erels
[i
].r_info
);
1477 rels
[i
].r_addend
= 0;
1484 Elf64_External_Rel
* erels
;
1486 erels
= (Elf64_External_Rel
*) get_data (NULL
, filedata
, rel_offset
, 1,
1487 rel_size
, _("64-bit relocation data"));
1491 nrels
= rel_size
/ sizeof (Elf64_External_Rel
);
1493 rels
= (Elf_Internal_Rela
*) cmalloc (nrels
, sizeof (Elf_Internal_Rela
));
1498 error (_("out of memory parsing relocs\n"));
1502 for (i
= 0; i
< nrels
; i
++)
1504 rels
[i
].r_offset
= BYTE_GET (erels
[i
].r_offset
);
1505 rels
[i
].r_info
= BYTE_GET (erels
[i
].r_info
);
1506 rels
[i
].r_addend
= 0;
1508 if (filedata
->file_header
.e_machine
== EM_MIPS
1509 && filedata
->file_header
.e_ident
[EI_DATA
] != ELFDATA2MSB
)
1511 /* In little-endian objects, r_info isn't really a
1512 64-bit little-endian value: it has a 32-bit
1513 little-endian symbol index followed by four
1514 individual byte fields. Reorder INFO
1516 uint64_t inf
= rels
[i
].r_info
;
1517 inf
= (((inf
& 0xffffffff) << 32)
1518 | ((inf
>> 56) & 0xff)
1519 | ((inf
>> 40) & 0xff00)
1520 | ((inf
>> 24) & 0xff0000)
1521 | ((inf
>> 8) & 0xff000000));
1522 rels
[i
].r_info
= inf
;
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
));
1577 get_symbol_at (Filedata
* filedata
,
1578 Elf_Internal_Sym
* symtab
,
1582 uint64_t * offset_return
)
1584 Elf_Internal_Sym
* beg
= symtab
;
1585 Elf_Internal_Sym
* end
= symtab
+ nsyms
;
1586 Elf_Internal_Sym
* best
= NULL
;
1587 uint64_t dist
= 0x100000;
1589 /* FIXME: Since this function is likely to be called repeatedly with
1590 slightly increasing addresses each time, we could speed things up by
1591 caching the last returned value and starting our search from there. */
1594 Elf_Internal_Sym
* sym
;
1597 sym
= beg
+ (end
- beg
) / 2;
1599 value
= sym
->st_value
;
1602 && where
- value
< dist
)
1605 dist
= where
- value
;
1618 /* If there is a section start closer than the found symbol then
1619 use that for symbolizing the address. */
1620 Elf_Internal_Shdr
*sec
= find_section_by_address (filedata
, where
);
1622 && where
- sec
->sh_addr
< dist
1623 && section_name_valid (filedata
, sec
))
1625 name
= section_name (filedata
, sec
);
1626 dist
= where
- sec
->sh_addr
;
1628 else if (best
!= NULL
)
1629 name
= strtab
+ best
->st_name
;
1633 if (offset_return
!= NULL
)
1634 * offset_return
= dist
;
1640 print_relr_addr_and_sym (Filedata
* filedata
,
1641 Elf_Internal_Sym
* symtab
,
1646 const char * symname
= NULL
;
1647 uint64_t offset
= 0;
1649 print_vma (where
, ZERO_HEX
);
1652 symname
= get_symbol_at (filedata
, symtab
, nsyms
, strtab
, where
, & offset
);
1654 if (symname
== NULL
)
1655 printf ("<no sym>");
1656 else if (offset
== 0)
1657 print_symbol_name (38, symname
);
1660 print_symbol_name (28, symname
);
1662 print_vma (offset
, PREFIX_HEX
);
1666 /* See bfd_is_aarch64_special_symbol_name. */
1669 is_aarch64_special_symbol_name (const char *name
)
1671 if (!name
|| name
[0] != '$')
1673 if (name
[1] == 'x' || name
[1] == 'd')
1675 else if (name
[1] == 'm' || name
[1] == 'f' || name
[1] == 'p')
1679 return name
[2] == 0 || name
[2] == '.';
1683 is_special_symbol_name (Filedata
* filedata
, const char * s
)
1685 switch (filedata
->file_header
.e_machine
)
1688 return is_aarch64_special_symbol_name (s
);
1695 /* Allows selecting the best symbol from a set for displaying addresses.
1696 BEST is the current best or NULL if there are no good symbols yet.
1697 SYM is the next symbol to consider, if it is better than BEST then
1698 return SYM else return BEST. */
1700 static Elf_Internal_Sym
*
1701 select_display_sym (Filedata
* filedata
,
1704 Elf_Internal_Sym
* best
,
1705 Elf_Internal_Sym
* sym
)
1707 /* Ignore empty or invalid syms. */
1708 if (sym
->st_name
== 0)
1710 if (sym
->st_name
>= strtablen
)
1712 /* Ignore undefined or TLS syms. */
1713 if (sym
->st_shndx
== SHN_UNDEF
)
1715 if (ELF_ST_TYPE (sym
->st_info
) == STT_TLS
)
1718 char *s
= strtab
+ sym
->st_name
;
1720 /* Don't display special symbols. */
1721 if (is_special_symbol_name (filedata
, s
))
1724 /* Here SYM is good for display. */
1729 char *sbest
= strtab
+ best
->st_name
;
1731 /* Prefer non-local symbols. */
1732 if (ELF_ST_BIND (sym
->st_info
) == STB_LOCAL
1733 && ELF_ST_BIND (best
->st_info
) != STB_LOCAL
)
1735 if (ELF_ST_BIND (sym
->st_info
) != STB_LOCAL
1736 && ELF_ST_BIND (best
->st_info
) == STB_LOCAL
)
1739 /* Select based on lexicographic order. */
1740 return strcmp (s
, sbest
) < 0 ? sym
: best
;
1743 /* Filter the sorted SYMTAB symbol array in-place to select at most one
1744 symbol for an address and drop symbols that are not good to display.
1745 Returns the new array length. */
1748 filter_display_syms (Filedata
* filedata
,
1749 Elf_Internal_Sym
* symtab
,
1754 Elf_Internal_Sym
*r
= symtab
;
1755 Elf_Internal_Sym
*w
= symtab
;
1756 Elf_Internal_Sym
*best
= NULL
;
1757 Elf_Internal_Sym
*end
= symtab
+ nsyms
;
1760 /* Select the best symbol for an address. */
1762 && (best
== NULL
|| best
->st_value
== r
->st_value
))
1764 best
= select_display_sym (filedata
, strtab
, strtablen
, best
, r
);
1777 static /* signed */ int
1778 symcmp (const void *p
, const void *q
)
1780 Elf_Internal_Sym
*sp
= (Elf_Internal_Sym
*) p
;
1781 Elf_Internal_Sym
*sq
= (Elf_Internal_Sym
*) q
;
1783 return sp
->st_value
> sq
->st_value
? 1 : (sp
->st_value
< sq
->st_value
? -1 : 0);
1787 update_all_relocations (size_t nentries
)
1791 if (!do_got_section_contents
)
1794 if (!all_relocations_root
)
1796 sz
= nentries
* sizeof (elf_relocation
);
1797 all_relocations_root
= (elf_relocation
*) xmalloc (sz
);
1798 all_relocations
= all_relocations_root
;
1799 all_relocations_count
= nentries
;
1803 size_t orig_count
= all_relocations_count
;
1804 sz
= (orig_count
+ nentries
) * sizeof (elf_relocation
);
1805 all_relocations_root
= (elf_relocation
*)
1806 xrealloc (all_relocations_root
, sz
);
1807 all_relocations
= all_relocations_root
+ orig_count
;
1808 all_relocations_count
+= nentries
;
1813 count_relr_relocations (Filedata
* filedata
,
1814 Elf_Internal_Shdr
* section
,
1815 uint64_t ** relrs_p
)
1824 || section
->sh_type
!= SHT_RELR
1825 || section
->sh_size
== 0)
1828 entsize
= section
->sh_entsize
;
1830 entsize
= is_32bit_elf
1831 ? sizeof (Elf32_External_Relr
) : sizeof (Elf64_External_Relr
);
1832 else if (entsize
!= sizeof (Elf32_External_Relr
)
1833 && entsize
!= sizeof (Elf64_External_Relr
))
1836 nentries
= section
->sh_size
/ entsize
;
1840 relrs
= get_data (NULL
, filedata
, section
->sh_offset
, 1,
1841 section
->sh_size
, _("RELR relocation data"));
1845 for (count
= i
= 0; i
< nentries
; i
++)
1849 if (entsize
== sizeof (Elf32_External_Relr
))
1850 entry
= BYTE_GET (((Elf32_External_Relr
*)relrs
)[i
].r_data
);
1852 entry
= BYTE_GET (((Elf64_External_Relr
*)relrs
)[i
].r_data
);
1854 if ((entry
& 1) == 0)
1863 for (; entry
>>= 1;)
1864 if ((entry
& 1) == 1)
1874 /* If DUMP_RELOC is false, don't display RELR relocations, just collect
1875 RELR relocations for displaying GOT section contents later. */
1878 dump_relr_relocations (Filedata
* filedata
,
1881 uint64_t relr_offset
,
1883 const Elf_Internal_Sym
* symtab_p
,
1889 uint64_t nentries
, i
;
1891 int num_bits_in_entry
;
1893 if (relr_entsize
== 0)
1894 relr_entsize
= is_32bit_elf
1895 ? sizeof (Elf32_External_Relr
) : sizeof (Elf64_External_Relr
);
1897 nentries
= relr_size
/ relr_entsize
;
1902 if (relr_entsize
== sizeof (Elf32_External_Relr
))
1903 num_bits_in_entry
= 31;
1904 else if (relr_entsize
== sizeof (Elf64_External_Relr
))
1905 num_bits_in_entry
= 63;
1909 warn (_("Unexpected entsize for RELR section\n"));
1913 uint64_t *alloc_relrs
= NULL
;
1916 relrs
= get_data (NULL
, filedata
, relr_offset
, 1, relr_size
,
1917 _("RELR relocation data"));
1920 alloc_relrs
= relrs
;
1926 if (symtab_p
== NULL
)
1929 const char *rtype
= NULL
;
1930 if (do_got_section_contents
)
1931 switch (filedata
->file_header
.e_machine
)
1938 rtype
= "R_386_RELATIVE";
1942 rtype
= "R_68K_RELATIVE";
1946 rtype
= "R_860_RELATIVE";
1950 rtype
= "R_AARCH64_RELATIVE";
1954 rtype
= "R_AMDGPU_RELATIVE64";
1958 rtype
= "R_ALPHA_RELATIVE";
1961 case EM_ALTERA_NIOS2
:
1962 rtype
= "R_NIOS2_RELATIVE";
1966 rtype
= "R_ARM_RELATIVE";
1970 case EM_ARC_COMPACT
:
1971 case EM_ARC_COMPACT2
:
1972 case EM_ARC_COMPACT3
:
1973 case EM_ARC_COMPACT3_64
:
1974 rtype
= "R_ARC_RELATIVE";
1978 rtype
= "R_CRIS_RELATIVE";
1982 rtype
= "R_CKCORE_RELATIVE";
1986 rtype
= "R_KVX_RELATIVE";
1989 case EM_LATTICEMICO32
:
1990 rtype
= "R_LM32_RELATIVE";
1994 rtype
= "R_LARCH_RELATIVE";
1998 case EM_CYGNUS_M32R
:
1999 rtype
= "R_M32R_RELATIVE";
2003 rtype
= "R_MCORE_RELATIVE";
2007 rtype
= "R_METAG_RELATIVE";
2011 case EM_CYGNUS_MN10300
:
2012 rtype
= "R_MN10300_RELATIVE";
2016 rtype
= "R_NDS32_RELATIVE";
2020 rtype
= "R_OR1K_RELATIVE";
2024 rtype
= "R_PPC_RELATIVE";
2028 rtype
= "R_PPC64_RELATIVE";
2032 rtype
= "R_RISCV_RELATIVE";
2036 rtype
= "R_I370_RELATIVE";
2041 rtype
= "R_390_RELATIVE";
2045 rtype
= "R_SH_RELATIVE";
2048 case EM_OLD_SPARCV9
:
2049 case EM_SPARC32PLUS
:
2052 rtype
= "R_SPARC_RELATIVE";
2056 rtype
= "R_TILEGX_RELATIVE";
2060 rtype
= "R_TILEPRO_RELATIVE";
2064 case EM_CYGNUS_V850
:
2065 rtype
= "R_V850_RELATIVE";
2069 rtype
= "R_VAX_RELATIVE";
2075 rtype
= "R_X86_64_RELATIVE";
2080 rtype
= "R_XTENSA_RELATIVE";
2084 Elf_Internal_Sym
*symtab
= NULL
;
2085 if (symtab_p
!= NULL
)
2087 /* Symbol tables are not sorted on address, but we want a quick lookup
2088 for the symbol associated with each address computed below, so sort
2089 the table then filter out unwanted entries. */
2090 size_t sz
= nsyms
* sizeof (*symtab
);
2091 symtab
= xmemdup (symtab_p
, sz
, sz
);
2092 qsort (symtab
, nsyms
, sizeof (Elf_Internal_Sym
), symcmp
);
2093 nsyms
= filter_display_syms (filedata
, symtab
, nsyms
, strtab
, strtablen
);
2098 if (relr_entsize
== sizeof (Elf32_External_Relr
))
2099 printf (_ ("Index: Entry Address Symbolic Address\n"));
2101 printf (_ ("Index: Entry Address Symbolic Address\n"));
2105 for (i
= 0; i
< nentries
; i
++)
2109 if (relr_entsize
== sizeof (Elf32_External_Relr
))
2110 entry
= BYTE_GET (((Elf32_External_Relr
*)relrs
)[i
].r_data
);
2112 entry
= BYTE_GET (((Elf64_External_Relr
*)relrs
)[i
].r_data
);
2116 /* We assume that there will never be more than 9999
2118 printf (_("%04u: "), (unsigned int) i
);
2119 print_vma (entry
, ZERO_HEX
);
2123 if ((entry
& 1) == 0)
2128 print_relr_addr_and_sym (filedata
, symtab
, nsyms
, strtab
,
2133 if (do_got_section_contents
)
2135 all_relocations
[r
].r_offset
= where
;
2136 all_relocations
[r
].r_name
= rtype
;
2137 all_relocations
[r
].r_symbol
= NULL
;
2138 all_relocations
[r
].r_type
= reltype_relr
;
2142 where
+= relr_entsize
;
2149 /* The least significant bit is ignored. */
2151 /* This can actually happen when the linker is allowed to shrink
2152 RELR sections. For more details see: https://reviews.llvm.org/D67164. */
2154 else if (dump_reloc
&& i
== 0)
2155 warn (_("Unusual RELR bitmap - no previous entry to set the base address\n"));
2157 for (j
= 0; entry
>>= 1; j
++)
2158 if ((entry
& 1) == 1)
2160 uint64_t addr
= where
+ (j
* relr_entsize
);
2166 print_relr_addr_and_sym (filedata
, symtab
, nsyms
,
2172 printf (_("\n%*s "),
2173 relr_entsize
== 4 ? 15 : 23, " ");
2174 print_relr_addr_and_sym (filedata
, symtab
, nsyms
,
2179 if (do_got_section_contents
)
2181 all_relocations
[r
].r_offset
= addr
;
2182 all_relocations
[r
].r_name
= rtype
;
2183 all_relocations
[r
].r_symbol
= NULL
;
2184 all_relocations
[r
].r_type
= reltype_relr
;
2191 where
+= num_bits_in_entry
* relr_entsize
;
2200 /* Display the contents of the relocation data found at the specified
2201 offset. If DUMP_RELOC is false, don't display relocations, just
2202 collect relocations for displaying GOT section contents later. */
2205 dump_relocations (Filedata
* filedata
,
2206 uint64_t rel_offset
,
2208 Elf_Internal_Sym
* symtab
,
2212 relocation_type rel_type
,
2217 Elf_Internal_Rela
* rels
;
2220 if (rel_type
== reltype_unknown
)
2221 rel_type
= guess_is_rela (filedata
->file_header
.e_machine
) ? reltype_rela
: reltype_rel
;
2223 if (rel_type
== reltype_rela
)
2225 if (!slurp_rela_relocs (filedata
, rel_offset
, rel_size
, &rels
, &rel_size
))
2228 else if (rel_type
== reltype_rel
)
2230 if (!slurp_rel_relocs (filedata
, rel_offset
, rel_size
, &rels
, &rel_size
))
2233 else if (rel_type
== reltype_relr
)
2235 /* This should have been handled by display_relocations(). */
2243 if (rel_type
== reltype_rela
)
2246 printf (_(" Offset Info Type Sym. Value Symbol's Name + Addend\n"));
2248 printf (_(" Offset Info Type Sym.Value Sym. Name + Addend\n"));
2253 printf (_(" Offset Info Type Sym. Value Symbol's Name\n"));
2255 printf (_(" Offset Info Type Sym.Value Sym. Name\n"));
2258 else if (rel_type
== reltype_rela
)
2261 printf (_(" Offset Info Type Symbol's Value Symbol's Name + Addend\n"));
2263 printf (_(" Offset Info Type Sym. Value Sym. Name + Addend\n"));
2268 printf (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
2270 printf (_(" Offset Info Type Sym. Value Sym. Name\n"));
2274 for (i
= 0; i
< rel_size
; i
++)
2279 uint64_t symtab_index
;
2282 offset
= rels
[i
].r_offset
;
2283 inf
= rels
[i
].r_info
;
2285 type
= get_reloc_type (filedata
, inf
);
2286 symtab_index
= get_reloc_symindex (inf
);
2291 printf ("%8.8" PRIx32
" %8.8" PRIx32
" ",
2292 (uint32_t) offset
, (uint32_t) inf
);
2295 ? "%16.16" PRIx64
" %16.16" PRIx64
" "
2296 : "%12.12" PRIx64
" %12.12" PRIx64
" ",
2300 switch (filedata
->file_header
.e_machine
)
2307 rtype
= elf_aarch64_reloc_type (type
);
2311 case EM_CYGNUS_M32R
:
2312 rtype
= elf_m32r_reloc_type (type
);
2317 rtype
= elf_i386_reloc_type (type
);
2322 rtype
= elf_m68hc11_reloc_type (type
);
2326 rtype
= elf_s12z_reloc_type (type
);
2330 rtype
= elf_m68k_reloc_type (type
);
2334 rtype
= elf_i960_reloc_type (type
);
2339 rtype
= elf_avr_reloc_type (type
);
2342 case EM_OLD_SPARCV9
:
2343 case EM_SPARC32PLUS
:
2346 rtype
= elf_sparc_reloc_type (type
);
2350 rtype
= elf_spu_reloc_type (type
);
2354 rtype
= v800_reloc_type (type
);
2357 case EM_CYGNUS_V850
:
2358 rtype
= v850_reloc_type (type
);
2362 case EM_CYGNUS_D10V
:
2363 rtype
= elf_d10v_reloc_type (type
);
2367 case EM_CYGNUS_D30V
:
2368 rtype
= elf_d30v_reloc_type (type
);
2372 rtype
= elf_dlx_reloc_type (type
);
2376 rtype
= elf_sh_reloc_type (type
);
2380 case EM_CYGNUS_MN10300
:
2381 rtype
= elf_mn10300_reloc_type (type
);
2385 case EM_CYGNUS_MN10200
:
2386 rtype
= elf_mn10200_reloc_type (type
);
2390 case EM_CYGNUS_FR30
:
2391 rtype
= elf_fr30_reloc_type (type
);
2395 rtype
= elf_frv_reloc_type (type
);
2399 rtype
= elf_csky_reloc_type (type
);
2403 rtype
= elf_ft32_reloc_type (type
);
2407 rtype
= elf_mcore_reloc_type (type
);
2411 rtype
= elf_mmix_reloc_type (type
);
2415 rtype
= elf_moxie_reloc_type (type
);
2419 if (uses_msp430x_relocs (filedata
))
2421 rtype
= elf_msp430x_reloc_type (type
);
2426 rtype
= elf_msp430_reloc_type (type
);
2430 rtype
= elf_nds32_reloc_type (type
);
2434 rtype
= elf_ppc_reloc_type (type
);
2438 rtype
= elf_ppc64_reloc_type (type
);
2442 case EM_MIPS_RS3_LE
:
2443 rtype
= elf_mips_reloc_type (type
);
2447 rtype
= elf_riscv_reloc_type (type
);
2451 rtype
= elf_alpha_reloc_type (type
);
2455 rtype
= elf_arm_reloc_type (type
);
2459 case EM_ARC_COMPACT
:
2460 case EM_ARC_COMPACT2
:
2461 case EM_ARC_COMPACT3
:
2462 case EM_ARC_COMPACT3_64
:
2463 rtype
= elf_arc_reloc_type (type
);
2467 rtype
= elf_hppa_reloc_type (type
);
2473 rtype
= elf_h8_reloc_type (type
);
2477 rtype
= elf_or1k_reloc_type (type
);
2482 rtype
= elf_pj_reloc_type (type
);
2485 rtype
= elf_ia64_reloc_type (type
);
2489 rtype
= elf_kvx_reloc_type (type
);
2493 rtype
= elf_cris_reloc_type (type
);
2497 rtype
= elf_i860_reloc_type (type
);
2503 rtype
= elf_x86_64_reloc_type (type
);
2507 rtype
= i370_reloc_type (type
);
2512 rtype
= elf_s390_reloc_type (type
);
2516 rtype
= elf_score_reloc_type (type
);
2520 rtype
= elf_xstormy16_reloc_type (type
);
2524 rtype
= elf_crx_reloc_type (type
);
2528 rtype
= elf_vax_reloc_type (type
);
2532 rtype
= elf_visium_reloc_type (type
);
2536 rtype
= elf_bpf_reloc_type (type
);
2539 case EM_ADAPTEVA_EPIPHANY
:
2540 rtype
= elf_epiphany_reloc_type (type
);
2545 rtype
= elf_ip2k_reloc_type (type
);
2549 rtype
= elf_iq2000_reloc_type (type
);
2554 rtype
= elf_xtensa_reloc_type (type
);
2557 case EM_LATTICEMICO32
:
2558 rtype
= elf_lm32_reloc_type (type
);
2563 rtype
= elf_m32c_reloc_type (type
);
2567 rtype
= elf_mt_reloc_type (type
);
2571 rtype
= elf_bfin_reloc_type (type
);
2575 rtype
= elf_mep_reloc_type (type
);
2579 rtype
= elf_cr16_reloc_type (type
);
2583 case EM_MICROBLAZE_OLD
:
2584 rtype
= elf_microblaze_reloc_type (type
);
2588 rtype
= elf_rl78_reloc_type (type
);
2592 rtype
= elf_rx_reloc_type (type
);
2596 rtype
= elf_metag_reloc_type (type
);
2600 rtype
= elf_tic6x_reloc_type (type
);
2604 rtype
= elf_tilegx_reloc_type (type
);
2608 rtype
= elf_tilepro_reloc_type (type
);
2611 case EM_WEBASSEMBLY
:
2612 rtype
= elf_wasm32_reloc_type (type
);
2616 rtype
= elf_xgate_reloc_type (type
);
2619 case EM_ALTERA_NIOS2
:
2620 rtype
= elf_nios2_reloc_type (type
);
2624 rtype
= elf_pru_reloc_type (type
);
2628 if (EF_NFP_MACH (filedata
->file_header
.e_flags
) == E_NFP_MACH_3200
)
2629 rtype
= elf_nfp3200_reloc_type (type
);
2631 rtype
= elf_nfp_reloc_type (type
);
2635 rtype
= elf_z80_reloc_type (type
);
2639 rtype
= elf_loongarch_reloc_type (type
);
2643 rtype
= elf_amdgpu_reloc_type (type
);
2647 char *symbol_name
= NULL
;
2651 printf (_("unrecognized: %-7lx"),
2652 (unsigned long) type
& 0xffffffff);
2654 printf (do_wide
? "%-22s" : "%-17.17s", rtype
);
2657 if (filedata
->file_header
.e_machine
== EM_ALPHA
2659 && streq (rtype
, "R_ALPHA_LITUSE")
2660 && rel_type
== reltype_rela
)
2662 switch (rels
[i
].r_addend
)
2664 case LITUSE_ALPHA_ADDR
: rtype
= "ADDR"; break;
2665 case LITUSE_ALPHA_BASE
: rtype
= "BASE"; break;
2666 case LITUSE_ALPHA_BYTOFF
: rtype
= "BYTOFF"; break;
2667 case LITUSE_ALPHA_JSR
: rtype
= "JSR"; break;
2668 case LITUSE_ALPHA_TLSGD
: rtype
= "TLSGD"; break;
2669 case LITUSE_ALPHA_TLSLDM
: rtype
= "TLSLDM"; break;
2670 case LITUSE_ALPHA_JSRDIRECT
: rtype
= "JSRDIRECT"; break;
2671 default: rtype
= NULL
;
2677 printf (" (%s)", rtype
);
2681 printf (_("<unknown addend: %" PRIx64
">"),
2687 else if (symtab_index
)
2689 if (symtab
== NULL
|| symtab_index
>= nsyms
)
2693 error (_(" bad symbol index: %08lx in reloc\n"),
2694 (unsigned long) symtab_index
);
2700 Elf_Internal_Sym
* psym
;
2701 const char * version_string
;
2702 enum versioned_symbol_info sym_info
;
2703 unsigned short vna_other
;
2705 psym
= symtab
+ symtab_index
;
2708 = get_symbol_version_string (filedata
, is_dynsym
,
2718 if (ELF_ST_TYPE (psym
->st_info
) == STT_GNU_IFUNC
)
2722 unsigned int width
= is_32bit_elf
? 8 : 14;
2724 /* Relocations against GNU_IFUNC symbols do not use the value
2725 of the symbol as the address to relocate against. Instead
2726 they invoke the function named by the symbol and use its
2727 result as the address for relocation.
2729 To indicate this to the user, do not display the value of
2730 the symbol in the "Symbols's Value" field. Instead show
2731 its name followed by () as a hint that the symbol is
2735 || psym
->st_name
== 0
2736 || psym
->st_name
>= strtablen
)
2739 name
= strtab
+ psym
->st_name
;
2741 if (do_got_section_contents
)
2744 symbol_name
= concat (name
,
2745 sym_info
== symbol_public
2747 version_string
, NULL
);
2749 symbol_name
= xstrdup (name
);
2754 len
= print_symbol_name (width
, name
);
2756 printf (sym_info
== symbol_public
2760 len
<= width
? (width
+ 1) - len
: 1,
2764 else if (dump_reloc
)
2766 print_vma (psym
->st_value
, LONG_HEX
);
2768 printf (is_32bit_elf
? " " : " ");
2771 if (psym
->st_name
== 0)
2773 const char * sec_name
= "<null>";
2775 if (ELF_ST_TYPE (psym
->st_info
) == STT_SECTION
)
2776 sec_name
= printable_section_name_from_index
2777 (filedata
, psym
->st_shndx
, NULL
);
2779 if (do_got_section_contents
)
2780 symbol_name
= xstrdup (sec_name
);
2782 print_symbol_name (22, sec_name
);
2784 else if (strtab
== NULL
)
2787 printf (_("<string table index: %3ld>"),
2790 else if (psym
->st_name
>= strtablen
)
2794 error (_("<corrupt string table index: %3ld>\n"),
2803 print_symbol_name (22, strtab
+ psym
->st_name
);
2805 printf (sym_info
== symbol_public
2809 if (do_got_section_contents
)
2812 symbol_name
= concat (strtab
+ psym
->st_name
,
2813 sym_info
== symbol_public
2815 version_string
, NULL
);
2817 symbol_name
= xstrdup (strtab
+ psym
->st_name
);
2821 if (dump_reloc
&& rel_type
== reltype_rela
)
2823 uint64_t off
= rels
[i
].r_addend
;
2825 if ((int64_t) off
< 0)
2826 printf (" - %" PRIx64
, -off
);
2828 printf (" + %" PRIx64
, off
);
2832 else if (dump_reloc
&& rel_type
== reltype_rela
)
2834 uint64_t off
= rels
[i
].r_addend
;
2836 printf ("%*c", is_32bit_elf
? 12 : 20, ' ');
2837 if ((int64_t) off
< 0)
2838 printf ("-%" PRIx64
, -off
);
2840 printf ("%" PRIx64
, off
);
2843 if (do_got_section_contents
)
2845 all_relocations
[i
].r_offset
= offset
;
2846 all_relocations
[i
].r_name
= rtype
;
2847 all_relocations
[i
].r_symbol
= symbol_name
;
2848 all_relocations
[i
].r_addend
= rels
[i
].r_addend
;
2849 all_relocations
[i
].r_type
= rel_type
;
2854 if (filedata
->file_header
.e_machine
== EM_SPARCV9
2856 && streq (rtype
, "R_SPARC_OLO10"))
2857 printf (" + %" PRIx64
, ELF64_R_TYPE_DATA (inf
));
2862 && filedata
->file_header
.e_machine
== EM_MIPS
)
2864 uint64_t type2
= ELF64_MIPS_R_TYPE2 (inf
);
2865 uint64_t type3
= ELF64_MIPS_R_TYPE3 (inf
);
2866 const char * rtype2
= elf_mips_reloc_type (type2
);
2867 const char * rtype3
= elf_mips_reloc_type (type3
);
2869 printf (" Type2: ");
2872 printf (_("unrecognized: %-7lx"),
2873 (unsigned long) type2
& 0xffffffff);
2875 printf ("%-17.17s", rtype2
);
2877 printf ("\n Type3: ");
2880 printf (_("unrecognized: %-7lx"),
2881 (unsigned long) type3
& 0xffffffff);
2883 printf ("%-17.17s", rtype3
);
2896 get_aarch64_dynamic_type (unsigned long type
)
2900 case DT_AARCH64_BTI_PLT
: return "AARCH64_BTI_PLT";
2901 case DT_AARCH64_PAC_PLT
: return "AARCH64_PAC_PLT";
2902 case DT_AARCH64_VARIANT_PCS
: return "AARCH64_VARIANT_PCS";
2903 case DT_AARCH64_MEMTAG_MODE
: return "AARCH64_MEMTAG_MODE";
2904 case DT_AARCH64_MEMTAG_STACK
: return "AARCH64_MEMTAG_STACK";
2912 get_mips_dynamic_type (unsigned long type
)
2916 case DT_MIPS_RLD_VERSION
: return "MIPS_RLD_VERSION";
2917 case DT_MIPS_TIME_STAMP
: return "MIPS_TIME_STAMP";
2918 case DT_MIPS_ICHECKSUM
: return "MIPS_ICHECKSUM";
2919 case DT_MIPS_IVERSION
: return "MIPS_IVERSION";
2920 case DT_MIPS_FLAGS
: return "MIPS_FLAGS";
2921 case DT_MIPS_BASE_ADDRESS
: return "MIPS_BASE_ADDRESS";
2922 case DT_MIPS_MSYM
: return "MIPS_MSYM";
2923 case DT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
2924 case DT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
2925 case DT_MIPS_LOCAL_GOTNO
: return "MIPS_LOCAL_GOTNO";
2926 case DT_MIPS_CONFLICTNO
: return "MIPS_CONFLICTNO";
2927 case DT_MIPS_LIBLISTNO
: return "MIPS_LIBLISTNO";
2928 case DT_MIPS_SYMTABNO
: return "MIPS_SYMTABNO";
2929 case DT_MIPS_UNREFEXTNO
: return "MIPS_UNREFEXTNO";
2930 case DT_MIPS_GOTSYM
: return "MIPS_GOTSYM";
2931 case DT_MIPS_HIPAGENO
: return "MIPS_HIPAGENO";
2932 case DT_MIPS_RLD_MAP
: return "MIPS_RLD_MAP";
2933 case DT_MIPS_RLD_MAP_REL
: return "MIPS_RLD_MAP_REL";
2934 case DT_MIPS_DELTA_CLASS
: return "MIPS_DELTA_CLASS";
2935 case DT_MIPS_DELTA_CLASS_NO
: return "MIPS_DELTA_CLASS_NO";
2936 case DT_MIPS_DELTA_INSTANCE
: return "MIPS_DELTA_INSTANCE";
2937 case DT_MIPS_DELTA_INSTANCE_NO
: return "MIPS_DELTA_INSTANCE_NO";
2938 case DT_MIPS_DELTA_RELOC
: return "MIPS_DELTA_RELOC";
2939 case DT_MIPS_DELTA_RELOC_NO
: return "MIPS_DELTA_RELOC_NO";
2940 case DT_MIPS_DELTA_SYM
: return "MIPS_DELTA_SYM";
2941 case DT_MIPS_DELTA_SYM_NO
: return "MIPS_DELTA_SYM_NO";
2942 case DT_MIPS_DELTA_CLASSSYM
: return "MIPS_DELTA_CLASSSYM";
2943 case DT_MIPS_DELTA_CLASSSYM_NO
: return "MIPS_DELTA_CLASSSYM_NO";
2944 case DT_MIPS_CXX_FLAGS
: return "MIPS_CXX_FLAGS";
2945 case DT_MIPS_PIXIE_INIT
: return "MIPS_PIXIE_INIT";
2946 case DT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
2947 case DT_MIPS_LOCALPAGE_GOTIDX
: return "MIPS_LOCALPAGE_GOTIDX";
2948 case DT_MIPS_LOCAL_GOTIDX
: return "MIPS_LOCAL_GOTIDX";
2949 case DT_MIPS_HIDDEN_GOTIDX
: return "MIPS_HIDDEN_GOTIDX";
2950 case DT_MIPS_PROTECTED_GOTIDX
: return "MIPS_PROTECTED_GOTIDX";
2951 case DT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
2952 case DT_MIPS_INTERFACE
: return "MIPS_INTERFACE";
2953 case DT_MIPS_DYNSTR_ALIGN
: return "MIPS_DYNSTR_ALIGN";
2954 case DT_MIPS_INTERFACE_SIZE
: return "MIPS_INTERFACE_SIZE";
2955 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR
: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
2956 case DT_MIPS_PERF_SUFFIX
: return "MIPS_PERF_SUFFIX";
2957 case DT_MIPS_COMPACT_SIZE
: return "MIPS_COMPACT_SIZE";
2958 case DT_MIPS_GP_VALUE
: return "MIPS_GP_VALUE";
2959 case DT_MIPS_AUX_DYNAMIC
: return "MIPS_AUX_DYNAMIC";
2960 case DT_MIPS_PLTGOT
: return "MIPS_PLTGOT";
2961 case DT_MIPS_RWPLT
: return "MIPS_RWPLT";
2962 case DT_MIPS_XHASH
: return "MIPS_XHASH";
2969 get_sparc64_dynamic_type (unsigned long type
)
2973 case DT_SPARC_REGISTER
: return "SPARC_REGISTER";
2980 get_ppc_dynamic_type (unsigned long type
)
2984 case DT_PPC_GOT
: return "PPC_GOT";
2985 case DT_PPC_OPT
: return "PPC_OPT";
2992 get_ppc64_dynamic_type (unsigned long type
)
2996 case DT_PPC64_GLINK
: return "PPC64_GLINK";
2997 case DT_PPC64_OPD
: return "PPC64_OPD";
2998 case DT_PPC64_OPDSZ
: return "PPC64_OPDSZ";
2999 case DT_PPC64_OPT
: return "PPC64_OPT";
3006 get_parisc_dynamic_type (unsigned long type
)
3010 case DT_HP_LOAD_MAP
: return "HP_LOAD_MAP";
3011 case DT_HP_DLD_FLAGS
: return "HP_DLD_FLAGS";
3012 case DT_HP_DLD_HOOK
: return "HP_DLD_HOOK";
3013 case DT_HP_UX10_INIT
: return "HP_UX10_INIT";
3014 case DT_HP_UX10_INITSZ
: return "HP_UX10_INITSZ";
3015 case DT_HP_PREINIT
: return "HP_PREINIT";
3016 case DT_HP_PREINITSZ
: return "HP_PREINITSZ";
3017 case DT_HP_NEEDED
: return "HP_NEEDED";
3018 case DT_HP_TIME_STAMP
: return "HP_TIME_STAMP";
3019 case DT_HP_CHECKSUM
: return "HP_CHECKSUM";
3020 case DT_HP_GST_SIZE
: return "HP_GST_SIZE";
3021 case DT_HP_GST_VERSION
: return "HP_GST_VERSION";
3022 case DT_HP_GST_HASHVAL
: return "HP_GST_HASHVAL";
3023 case DT_HP_EPLTREL
: return "HP_GST_EPLTREL";
3024 case DT_HP_EPLTRELSZ
: return "HP_GST_EPLTRELSZ";
3025 case DT_HP_FILTERED
: return "HP_FILTERED";
3026 case DT_HP_FILTER_TLS
: return "HP_FILTER_TLS";
3027 case DT_HP_COMPAT_FILTERED
: return "HP_COMPAT_FILTERED";
3028 case DT_HP_LAZYLOAD
: return "HP_LAZYLOAD";
3029 case DT_HP_BIND_NOW_COUNT
: return "HP_BIND_NOW_COUNT";
3030 case DT_PLT
: return "PLT";
3031 case DT_PLT_SIZE
: return "PLT_SIZE";
3032 case DT_DLT
: return "DLT";
3033 case DT_DLT_SIZE
: return "DLT_SIZE";
3040 get_ia64_dynamic_type (unsigned long type
)
3044 case DT_IA_64_PLT_RESERVE
: return "IA_64_PLT_RESERVE";
3045 case DT_IA_64_VMS_SUBTYPE
: return "VMS_SUBTYPE";
3046 case DT_IA_64_VMS_IMGIOCNT
: return "VMS_IMGIOCNT";
3047 case DT_IA_64_VMS_LNKFLAGS
: return "VMS_LNKFLAGS";
3048 case DT_IA_64_VMS_VIR_MEM_BLK_SIZ
: return "VMS_VIR_MEM_BLK_SIZ";
3049 case DT_IA_64_VMS_IDENT
: return "VMS_IDENT";
3050 case DT_IA_64_VMS_NEEDED_IDENT
: return "VMS_NEEDED_IDENT";
3051 case DT_IA_64_VMS_IMG_RELA_CNT
: return "VMS_IMG_RELA_CNT";
3052 case DT_IA_64_VMS_SEG_RELA_CNT
: return "VMS_SEG_RELA_CNT";
3053 case DT_IA_64_VMS_FIXUP_RELA_CNT
: return "VMS_FIXUP_RELA_CNT";
3054 case DT_IA_64_VMS_FIXUP_NEEDED
: return "VMS_FIXUP_NEEDED";
3055 case DT_IA_64_VMS_SYMVEC_CNT
: return "VMS_SYMVEC_CNT";
3056 case DT_IA_64_VMS_XLATED
: return "VMS_XLATED";
3057 case DT_IA_64_VMS_STACKSIZE
: return "VMS_STACKSIZE";
3058 case DT_IA_64_VMS_UNWINDSZ
: return "VMS_UNWINDSZ";
3059 case DT_IA_64_VMS_UNWIND_CODSEG
: return "VMS_UNWIND_CODSEG";
3060 case DT_IA_64_VMS_UNWIND_INFOSEG
: return "VMS_UNWIND_INFOSEG";
3061 case DT_IA_64_VMS_LINKTIME
: return "VMS_LINKTIME";
3062 case DT_IA_64_VMS_SEG_NO
: return "VMS_SEG_NO";
3063 case DT_IA_64_VMS_SYMVEC_OFFSET
: return "VMS_SYMVEC_OFFSET";
3064 case DT_IA_64_VMS_SYMVEC_SEG
: return "VMS_SYMVEC_SEG";
3065 case DT_IA_64_VMS_UNWIND_OFFSET
: return "VMS_UNWIND_OFFSET";
3066 case DT_IA_64_VMS_UNWIND_SEG
: return "VMS_UNWIND_SEG";
3067 case DT_IA_64_VMS_STRTAB_OFFSET
: return "VMS_STRTAB_OFFSET";
3068 case DT_IA_64_VMS_SYSVER_OFFSET
: return "VMS_SYSVER_OFFSET";
3069 case DT_IA_64_VMS_IMG_RELA_OFF
: return "VMS_IMG_RELA_OFF";
3070 case DT_IA_64_VMS_SEG_RELA_OFF
: return "VMS_SEG_RELA_OFF";
3071 case DT_IA_64_VMS_FIXUP_RELA_OFF
: return "VMS_FIXUP_RELA_OFF";
3072 case DT_IA_64_VMS_PLTGOT_OFFSET
: return "VMS_PLTGOT_OFFSET";
3073 case DT_IA_64_VMS_PLTGOT_SEG
: return "VMS_PLTGOT_SEG";
3074 case DT_IA_64_VMS_FPMODE
: return "VMS_FPMODE";
3081 get_solaris_section_type (unsigned long type
)
3085 case SHT_SUNW_symtabnsort
:
3086 return "SUNW_symtabnsort";
3087 case SHT_SUNW_ancillary
:
3088 return "SUNW_ancillary";
3089 case SHT_SUNW_phname
:
3090 return "SUNW_phname";
3091 case SHT_SUNW_capchain
:
3092 return "SUNW_capchain";
3093 case SHT_SUNW_capinfo
:
3094 return "SUNW_capinfo";
3095 case SHT_SUNW_symsort
:
3096 return "SUNW_symsort";
3097 case SHT_SUNW_tlssort
:
3098 return "SUNW_tlssort";
3099 case SHT_SUNW_LDYNSYM
:
3100 return "SUNW_LDYNSYM";
3105 case SHT_SUNW_SIGNATURE
:
3106 return "SUNW_SIGNATURE";
3107 case SHT_SUNW_ANNOTATE
:
3108 return "SUNW_ANNOTATE";
3109 case SHT_SUNW_DEBUGSTR
:
3110 return "SUNW_DEBUGSTR";
3111 case SHT_SUNW_DEBUG
:
3112 return "SUNW_DEBUG";
3115 case SHT_SUNW_COMDAT
:
3116 return "SUNW_COMDAT";
3117 case SHT_SUNW_syminfo
:
3118 return "SUNW_syminfo";
3119 case SHT_SUNW_verdef
:
3120 return "SUNW_verdef";
3121 case SHT_SUNW_verneed
:
3122 return "SUNW_verneed";
3123 case SHT_SUNW_versym
:
3124 return "SUNW_versym";
3126 return "SPARC_GOTDATA";
3133 get_alpha_dynamic_type (unsigned long type
)
3137 case DT_ALPHA_PLTRO
: return "ALPHA_PLTRO";
3138 default: return NULL
;
3143 get_score_dynamic_type (unsigned long type
)
3147 case DT_SCORE_BASE_ADDRESS
: return "SCORE_BASE_ADDRESS";
3148 case DT_SCORE_LOCAL_GOTNO
: return "SCORE_LOCAL_GOTNO";
3149 case DT_SCORE_SYMTABNO
: return "SCORE_SYMTABNO";
3150 case DT_SCORE_GOTSYM
: return "SCORE_GOTSYM";
3151 case DT_SCORE_UNREFEXTNO
: return "SCORE_UNREFEXTNO";
3152 case DT_SCORE_HIPAGENO
: return "SCORE_HIPAGENO";
3153 default: return NULL
;
3158 get_tic6x_dynamic_type (unsigned long type
)
3162 case DT_C6000_GSYM_OFFSET
: return "C6000_GSYM_OFFSET";
3163 case DT_C6000_GSTR_OFFSET
: return "C6000_GSTR_OFFSET";
3164 case DT_C6000_DSBT_BASE
: return "C6000_DSBT_BASE";
3165 case DT_C6000_DSBT_SIZE
: return "C6000_DSBT_SIZE";
3166 case DT_C6000_PREEMPTMAP
: return "C6000_PREEMPTMAP";
3167 case DT_C6000_DSBT_INDEX
: return "C6000_DSBT_INDEX";
3168 default: return NULL
;
3173 get_nios2_dynamic_type (unsigned long type
)
3177 case DT_NIOS2_GP
: return "NIOS2_GP";
3178 default: return NULL
;
3183 get_solaris_dynamic_type (unsigned long type
)
3187 case 0x6000000d: return "SUNW_AUXILIARY";
3188 case 0x6000000e: return "SUNW_RTLDINF";
3189 case 0x6000000f: return "SUNW_FILTER";
3190 case 0x60000010: return "SUNW_CAP";
3191 case 0x60000011: return "SUNW_SYMTAB";
3192 case 0x60000012: return "SUNW_SYMSZ";
3193 case 0x60000013: return "SUNW_SORTENT";
3194 case 0x60000014: return "SUNW_SYMSORT";
3195 case 0x60000015: return "SUNW_SYMSORTSZ";
3196 case 0x60000016: return "SUNW_TLSSORT";
3197 case 0x60000017: return "SUNW_TLSSORTSZ";
3198 case 0x60000018: return "SUNW_CAPINFO";
3199 case 0x60000019: return "SUNW_STRPAD";
3200 case 0x6000001a: return "SUNW_CAPCHAIN";
3201 case 0x6000001b: return "SUNW_LDMACH";
3202 case 0x6000001d: return "SUNW_CAPCHAINENT";
3203 case 0x6000001f: return "SUNW_CAPCHAINSZ";
3204 case 0x60000021: return "SUNW_PARENT";
3205 case 0x60000023: return "SUNW_ASLR";
3206 case 0x60000025: return "SUNW_RELAX";
3207 case 0x60000029: return "SUNW_NXHEAP";
3208 case 0x6000002b: return "SUNW_NXSTACK";
3210 case 0x70000001: return "SPARC_REGISTER";
3211 case 0x7ffffffd: return "AUXILIARY";
3212 case 0x7ffffffe: return "USED";
3213 case 0x7fffffff: return "FILTER";
3215 default: return NULL
;
3220 get_riscv_dynamic_type (unsigned long type
)
3224 case DT_RISCV_VARIANT_CC
: return "RISCV_VARIANT_CC";
3231 get_x86_64_dynamic_type (unsigned long type
)
3236 return "DT_X86_64_PLT";
3237 case DT_X86_64_PLTSZ
:
3238 return "DT_X86_64_PLTSZ";
3239 case DT_X86_64_PLTENT
:
3240 return "DT_X86_64_PLTENT";
3247 get_dynamic_type (Filedata
* filedata
, unsigned long type
)
3249 static char buff
[64];
3253 case DT_NULL
: return "NULL";
3254 case DT_NEEDED
: return "NEEDED";
3255 case DT_PLTRELSZ
: return "PLTRELSZ";
3256 case DT_PLTGOT
: return "PLTGOT";
3257 case DT_HASH
: return "HASH";
3258 case DT_STRTAB
: return "STRTAB";
3259 case DT_SYMTAB
: return "SYMTAB";
3260 case DT_RELA
: return "RELA";
3261 case DT_RELASZ
: return "RELASZ";
3262 case DT_RELAENT
: return "RELAENT";
3263 case DT_STRSZ
: return "STRSZ";
3264 case DT_SYMENT
: return "SYMENT";
3265 case DT_INIT
: return "INIT";
3266 case DT_FINI
: return "FINI";
3267 case DT_SONAME
: return "SONAME";
3268 case DT_RPATH
: return "RPATH";
3269 case DT_SYMBOLIC
: return "SYMBOLIC";
3270 case DT_REL
: return "REL";
3271 case DT_RELSZ
: return "RELSZ";
3272 case DT_RELENT
: return "RELENT";
3273 case DT_RELR
: return "RELR";
3274 case DT_RELRSZ
: return "RELRSZ";
3275 case DT_RELRENT
: return "RELRENT";
3276 case DT_PLTREL
: return "PLTREL";
3277 case DT_DEBUG
: return "DEBUG";
3278 case DT_TEXTREL
: return "TEXTREL";
3279 case DT_JMPREL
: return "JMPREL";
3280 case DT_BIND_NOW
: return "BIND_NOW";
3281 case DT_INIT_ARRAY
: return "INIT_ARRAY";
3282 case DT_FINI_ARRAY
: return "FINI_ARRAY";
3283 case DT_INIT_ARRAYSZ
: return "INIT_ARRAYSZ";
3284 case DT_FINI_ARRAYSZ
: return "FINI_ARRAYSZ";
3285 case DT_RUNPATH
: return "RUNPATH";
3286 case DT_FLAGS
: return "FLAGS";
3288 case DT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
3289 case DT_PREINIT_ARRAYSZ
: return "PREINIT_ARRAYSZ";
3290 case DT_SYMTAB_SHNDX
: return "SYMTAB_SHNDX";
3292 case DT_CHECKSUM
: return "CHECKSUM";
3293 case DT_PLTPADSZ
: return "PLTPADSZ";
3294 case DT_MOVEENT
: return "MOVEENT";
3295 case DT_MOVESZ
: return "MOVESZ";
3296 case DT_FEATURE
: return "FEATURE";
3297 case DT_POSFLAG_1
: return "POSFLAG_1";
3298 case DT_SYMINSZ
: return "SYMINSZ";
3299 case DT_SYMINENT
: return "SYMINENT"; /* aka VALRNGHI */
3301 case DT_ADDRRNGLO
: return "ADDRRNGLO";
3302 case DT_CONFIG
: return "CONFIG";
3303 case DT_DEPAUDIT
: return "DEPAUDIT";
3304 case DT_AUDIT
: return "AUDIT";
3305 case DT_PLTPAD
: return "PLTPAD";
3306 case DT_MOVETAB
: return "MOVETAB";
3307 case DT_SYMINFO
: return "SYMINFO"; /* aka ADDRRNGHI */
3309 case DT_VERSYM
: return "VERSYM";
3311 case DT_TLSDESC_GOT
: return "TLSDESC_GOT";
3312 case DT_TLSDESC_PLT
: return "TLSDESC_PLT";
3313 case DT_RELACOUNT
: return "RELACOUNT";
3314 case DT_RELCOUNT
: return "RELCOUNT";
3315 case DT_FLAGS_1
: return "FLAGS_1";
3316 case DT_VERDEF
: return "VERDEF";
3317 case DT_VERDEFNUM
: return "VERDEFNUM";
3318 case DT_VERNEED
: return "VERNEED";
3319 case DT_VERNEEDNUM
: return "VERNEEDNUM";
3321 case DT_AUXILIARY
: return "AUXILIARY";
3322 case DT_USED
: return "USED";
3323 case DT_FILTER
: return "FILTER";
3325 case DT_GNU_PRELINKED
: return "GNU_PRELINKED";
3326 case DT_GNU_CONFLICT
: return "GNU_CONFLICT";
3327 case DT_GNU_CONFLICTSZ
: return "GNU_CONFLICTSZ";
3328 case DT_GNU_LIBLIST
: return "GNU_LIBLIST";
3329 case DT_GNU_LIBLISTSZ
: return "GNU_LIBLISTSZ";
3330 case DT_GNU_HASH
: return "GNU_HASH";
3331 case DT_GNU_FLAGS_1
: return "GNU_FLAGS_1";
3334 if ((type
>= DT_LOPROC
) && (type
<= DT_HIPROC
))
3336 const char * result
;
3338 switch (filedata
->file_header
.e_machine
)
3341 result
= get_aarch64_dynamic_type (type
);
3344 case EM_MIPS_RS3_LE
:
3345 result
= get_mips_dynamic_type (type
);
3348 result
= get_sparc64_dynamic_type (type
);
3351 result
= get_ppc_dynamic_type (type
);
3354 result
= get_ppc64_dynamic_type (type
);
3357 result
= get_ia64_dynamic_type (type
);
3360 result
= get_alpha_dynamic_type (type
);
3363 result
= get_score_dynamic_type (type
);
3366 result
= get_tic6x_dynamic_type (type
);
3368 case EM_ALTERA_NIOS2
:
3369 result
= get_nios2_dynamic_type (type
);
3372 result
= get_riscv_dynamic_type (type
);
3375 result
= get_x86_64_dynamic_type (type
);
3378 if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_SOLARIS
)
3379 result
= get_solaris_dynamic_type (type
);
3388 snprintf (buff
, sizeof (buff
), _("Processor Specific: %lx"), type
);
3390 else if (((type
>= DT_LOOS
) && (type
<= DT_HIOS
))
3391 || (filedata
->file_header
.e_machine
== EM_PARISC
3392 && (type
>= OLD_DT_LOOS
) && (type
<= OLD_DT_HIOS
)))
3394 const char * result
;
3396 switch (filedata
->file_header
.e_machine
)
3399 result
= get_parisc_dynamic_type (type
);
3402 result
= get_ia64_dynamic_type (type
);
3405 if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_SOLARIS
)
3406 result
= get_solaris_dynamic_type (type
);
3415 snprintf (buff
, sizeof (buff
), _("Operating System specific: %lx"),
3419 snprintf (buff
, sizeof (buff
), _("<unknown>: %lx"), type
);
3425 static bool get_program_headers (Filedata
*);
3426 static bool get_dynamic_section (Filedata
*);
3429 locate_dynamic_section (Filedata
*filedata
)
3431 uint64_t dynamic_addr
= 0;
3432 uint64_t dynamic_size
= 0;
3434 if (filedata
->file_header
.e_phnum
!= 0
3435 && get_program_headers (filedata
))
3437 Elf_Internal_Phdr
*segment
;
3440 for (i
= 0, segment
= filedata
->program_headers
;
3441 i
< filedata
->file_header
.e_phnum
;
3444 if (segment
->p_type
== PT_DYNAMIC
)
3446 dynamic_addr
= segment
->p_offset
;
3447 dynamic_size
= segment
->p_filesz
;
3449 if (filedata
->section_headers
!= NULL
)
3451 Elf_Internal_Shdr
*sec
;
3453 sec
= find_section (filedata
, ".dynamic");
3456 if (sec
->sh_size
== 0
3457 || sec
->sh_type
== SHT_NOBITS
)
3464 dynamic_addr
= sec
->sh_offset
;
3465 dynamic_size
= sec
->sh_size
;
3470 if (dynamic_addr
> filedata
->file_size
3471 || (dynamic_size
> filedata
->file_size
- dynamic_addr
))
3480 filedata
->dynamic_addr
= dynamic_addr
;
3481 filedata
->dynamic_size
= dynamic_size
? dynamic_size
: 1;
3485 is_pie (Filedata
*filedata
)
3487 Elf_Internal_Dyn
*entry
;
3489 if (filedata
->dynamic_size
== 0)
3490 locate_dynamic_section (filedata
);
3491 if (filedata
->dynamic_size
<= 1)
3494 if (!get_dynamic_section (filedata
))
3497 for (entry
= filedata
->dynamic_section
;
3498 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
3501 if (entry
->d_tag
== DT_FLAGS_1
)
3503 if ((entry
->d_un
.d_val
& DF_1_PIE
) != 0)
3512 get_file_type (Filedata
*filedata
)
3514 unsigned e_type
= filedata
->file_header
.e_type
;
3515 static char buff
[64];
3519 case ET_NONE
: return _("NONE (None)");
3520 case ET_REL
: return _("REL (Relocatable file)");
3521 case ET_EXEC
: return _("EXEC (Executable file)");
3523 if (is_pie (filedata
))
3524 return _("DYN (Position-Independent Executable file)");
3526 return _("DYN (Shared object file)");
3527 case ET_CORE
: return _("CORE (Core file)");
3530 if ((e_type
>= ET_LOPROC
) && (e_type
<= ET_HIPROC
))
3531 snprintf (buff
, sizeof (buff
), _("Processor Specific: (%x)"), e_type
);
3532 else if ((e_type
>= ET_LOOS
) && (e_type
<= ET_HIOS
))
3533 snprintf (buff
, sizeof (buff
), _("OS Specific: (%x)"), e_type
);
3535 snprintf (buff
, sizeof (buff
), _("<unknown>: %x"), e_type
);
3541 get_machine_name (unsigned e_machine
)
3543 static char buff
[64]; /* XXX */
3547 /* Please keep this switch table sorted by increasing EM_ value. */
3549 case EM_NONE
: return _("None");
3550 case EM_M32
: return "WE32100";
3551 case EM_SPARC
: return "Sparc";
3552 case EM_386
: return "Intel 80386";
3553 case EM_68K
: return "MC68000";
3554 case EM_88K
: return "MC88000";
3555 case EM_IAMCU
: return "Intel MCU";
3556 case EM_860
: return "Intel 80860";
3557 case EM_MIPS
: return "MIPS R3000";
3558 case EM_S370
: return "IBM System/370";
3560 case EM_MIPS_RS3_LE
: return "MIPS R4000 big-endian";
3561 case EM_OLD_SPARCV9
: return "Sparc v9 (old)";
3562 case EM_PARISC
: return "HPPA";
3563 case EM_VPP550
: return "Fujitsu VPP500";
3564 case EM_SPARC32PLUS
: return "Sparc v8+" ;
3565 case EM_960
: return "Intel 80960";
3566 case EM_PPC
: return "PowerPC";
3568 case EM_PPC64
: return "PowerPC64";
3570 case EM_S390
: return "IBM S/390";
3571 case EM_SPU
: return "SPU";
3573 case EM_V800
: return "Renesas V850 (using RH850 ABI)";
3574 case EM_FR20
: return "Fujitsu FR20";
3575 case EM_RH32
: return "TRW RH32";
3576 case EM_MCORE
: return "MCORE";
3578 case EM_ARM
: return "ARM";
3579 case EM_OLD_ALPHA
: return "Digital Alpha (old)";
3580 case EM_SH
: return "Renesas / SuperH SH";
3581 case EM_SPARCV9
: return "Sparc v9";
3582 case EM_TRICORE
: return "Siemens Tricore";
3583 case EM_ARC
: return "ARC";
3584 case EM_H8_300
: return "Renesas H8/300";
3585 case EM_H8_300H
: return "Renesas H8/300H";
3586 case EM_H8S
: return "Renesas H8S";
3587 case EM_H8_500
: return "Renesas H8/500";
3589 case EM_IA_64
: return "Intel IA-64";
3590 case EM_MIPS_X
: return "Stanford MIPS-X";
3591 case EM_COLDFIRE
: return "Motorola Coldfire";
3592 case EM_68HC12
: return "Motorola MC68HC12 Microcontroller";
3593 case EM_MMA
: return "Fujitsu Multimedia Accelerator";
3594 case EM_PCP
: return "Siemens PCP";
3595 case EM_NCPU
: return "Sony nCPU embedded RISC processor";
3596 case EM_NDR1
: return "Denso NDR1 microprocessor";
3597 case EM_STARCORE
: return "Motorola Star*Core processor";
3598 case EM_ME16
: return "Toyota ME16 processor";
3600 case EM_ST100
: return "STMicroelectronics ST100 processor";
3601 case EM_TINYJ
: return "Advanced Logic Corp. TinyJ embedded processor";
3602 case EM_X86_64
: return "Advanced Micro Devices X86-64";
3603 case EM_PDSP
: return "Sony DSP processor";
3604 case EM_PDP10
: return "Digital Equipment Corp. PDP-10";
3605 case EM_PDP11
: return "Digital Equipment Corp. PDP-11";
3606 case EM_FX66
: return "Siemens FX66 microcontroller";
3607 case EM_ST9PLUS
: return "STMicroelectronics ST9+ 8/16 bit microcontroller";
3608 case EM_ST7
: return "STMicroelectronics ST7 8-bit microcontroller";
3609 case EM_68HC16
: return "Motorola MC68HC16 Microcontroller";
3611 case EM_68HC11
: return "Motorola MC68HC11 Microcontroller";
3612 case EM_68HC08
: return "Motorola MC68HC08 Microcontroller";
3613 case EM_68HC05
: return "Motorola MC68HC05 Microcontroller";
3614 case EM_SVX
: return "Silicon Graphics SVx";
3615 case EM_ST19
: return "STMicroelectronics ST19 8-bit microcontroller";
3616 case EM_VAX
: return "Digital VAX";
3617 case EM_CRIS
: return "Axis Communications 32-bit embedded processor";
3618 case EM_JAVELIN
: return "Infineon Technologies 32-bit embedded cpu";
3619 case EM_FIREPATH
: return "Element 14 64-bit DSP processor";
3620 case EM_ZSP
: return "LSI Logic's 16-bit DSP processor";
3622 case EM_MMIX
: return "Donald Knuth's educational 64-bit processor";
3623 case EM_HUANY
: return "Harvard Universitys's machine-independent object format";
3624 case EM_PRISM
: return "Vitesse Prism";
3626 case EM_AVR
: return "Atmel AVR 8-bit microcontroller";
3627 case EM_CYGNUS_FR30
:
3628 case EM_FR30
: return "Fujitsu FR30";
3629 case EM_CYGNUS_D10V
:
3630 case EM_D10V
: return "d10v";
3631 case EM_CYGNUS_D30V
:
3632 case EM_D30V
: return "d30v";
3633 case EM_CYGNUS_V850
:
3634 case EM_V850
: return "Renesas V850";
3635 case EM_CYGNUS_M32R
:
3636 case EM_M32R
: return "Renesas M32R (formerly Mitsubishi M32r)";
3637 case EM_CYGNUS_MN10300
:
3638 case EM_MN10300
: return "mn10300";
3640 case EM_CYGNUS_MN10200
:
3641 case EM_MN10200
: return "mn10200";
3642 case EM_PJ
: return "picoJava";
3643 case EM_OR1K
: return "OpenRISC 1000";
3644 case EM_ARC_COMPACT
: return "ARCompact";
3646 case EM_XTENSA
: return "Tensilica Xtensa Processor";
3647 case EM_VIDEOCORE
: return "Alphamosaic VideoCore processor";
3648 case EM_TMM_GPP
: return "Thompson Multimedia General Purpose Processor";
3649 case EM_NS32K
: return "National Semiconductor 32000 series";
3650 case EM_TPC
: return "Tenor Network TPC processor";
3651 case EM_SNP1K
: return "Trebia SNP 1000 processor";
3653 case EM_ST200
: return "STMicroelectronics ST200 microcontroller";
3655 case EM_IP2K
: return "Ubicom IP2xxx 8-bit microcontrollers";
3656 case EM_MAX
: return "MAX Processor";
3657 case EM_CR
: return "National Semiconductor CompactRISC";
3658 case EM_F2MC16
: return "Fujitsu F2MC16";
3659 case EM_MSP430
: return "Texas Instruments msp430 microcontroller";
3660 case EM_BLACKFIN
: return "Analog Devices Blackfin";
3661 case EM_SE_C33
: return "S1C33 Family of Seiko Epson processors";
3662 case EM_SEP
: return "Sharp embedded microprocessor";
3663 case EM_ARCA
: return "Arca RISC microprocessor";
3665 case EM_UNICORE
: return "Unicore";
3666 case EM_EXCESS
: return "eXcess 16/32/64-bit configurable embedded CPU";
3667 case EM_DXP
: return "Icera Semiconductor Inc. Deep Execution Processor";
3668 case EM_ALTERA_NIOS2
: return "Altera Nios II";
3669 case EM_CRX
: return "National Semiconductor CRX microprocessor";
3670 case EM_XGATE
: return "Motorola XGATE embedded processor";
3672 case EM_XC16X
: return "Infineon Technologies xc16x";
3673 case EM_M16C
: return "Renesas M16C series microprocessors";
3674 case EM_DSPIC30F
: return "Microchip Technology dsPIC30F Digital Signal Controller";
3675 case EM_CE
: return "Freescale Communication Engine RISC core";
3677 case EM_M32C
: return "Renesas M32c";
3679 case EM_TSK3000
: return "Altium TSK3000 core";
3680 case EM_RS08
: return "Freescale RS08 embedded processor";
3681 case EM_ECOG2
: return "Cyan Technology eCOG2 microprocessor";
3682 case EM_SCORE
: return "SUNPLUS S+Core";
3683 case EM_DSP24
: return "New Japan Radio (NJR) 24-bit DSP Processor";
3684 case EM_VIDEOCORE3
: return "Broadcom VideoCore III processor";
3685 case EM_LATTICEMICO32
: return "Lattice Mico32";
3686 case EM_SE_C17
: return "Seiko Epson C17 family";
3688 case EM_TI_C6000
: return "Texas Instruments TMS320C6000 DSP family";
3689 case EM_TI_C2000
: return "Texas Instruments TMS320C2000 DSP family";
3690 case EM_TI_C5500
: return "Texas Instruments TMS320C55x DSP family";
3691 case EM_TI_PRU
: return "TI PRU I/O processor";
3693 case EM_MMDSP_PLUS
: return "STMicroelectronics 64bit VLIW Data Signal Processor";
3694 case EM_CYPRESS_M8C
: return "Cypress M8C microprocessor";
3695 case EM_R32C
: return "Renesas R32C series microprocessors";
3696 case EM_TRIMEDIA
: return "NXP Semiconductors TriMedia architecture family";
3697 case EM_QDSP6
: return "QUALCOMM DSP6 Processor";
3698 case EM_8051
: return "Intel 8051 and variants";
3699 case EM_STXP7X
: return "STMicroelectronics STxP7x family";
3700 case EM_NDS32
: return "Andes Technology compact code size embedded RISC processor family";
3701 case EM_ECOG1X
: return "Cyan Technology eCOG1X family";
3702 case EM_MAXQ30
: return "Dallas Semiconductor MAXQ30 Core microcontrollers";
3704 case EM_XIMO16
: return "New Japan Radio (NJR) 16-bit DSP Processor";
3705 case EM_MANIK
: return "M2000 Reconfigurable RISC Microprocessor";
3706 case EM_CRAYNV2
: return "Cray Inc. NV2 vector architecture";
3707 case EM_RX
: return "Renesas RX";
3708 case EM_METAG
: return "Imagination Technologies Meta processor architecture";
3709 case EM_MCST_ELBRUS
: return "MCST Elbrus general purpose hardware architecture";
3710 case EM_ECOG16
: return "Cyan Technology eCOG16 family";
3713 case EM_MICROBLAZE_OLD
: return "Xilinx MicroBlaze";
3714 case EM_ETPU
: return "Freescale Extended Time Processing Unit";
3715 case EM_SLE9X
: return "Infineon Technologies SLE9X core";
3717 case EM_L1OM
: return "Intel L1OM";
3718 case EM_K1OM
: return "Intel K1OM";
3719 case EM_INTEL182
: return "Intel (reserved)";
3720 case EM_AARCH64
: return "AArch64";
3721 case EM_ARM184
: return "ARM (reserved)";
3722 case EM_AVR32
: return "Atmel Corporation 32-bit microprocessor";
3723 case EM_STM8
: return "STMicroeletronics STM8 8-bit microcontroller";
3724 case EM_TILE64
: return "Tilera TILE64 multicore architecture family";
3725 case EM_TILEPRO
: return "Tilera TILEPro multicore architecture family";
3727 case EM_CUDA
: return "NVIDIA CUDA architecture";
3728 case EM_TILEGX
: return "Tilera TILE-Gx multicore architecture family";
3729 case EM_CLOUDSHIELD
: return "CloudShield architecture family";
3730 case EM_COREA_1ST
: return "KIPO-KAIST Core-A 1st generation processor family";
3731 case EM_COREA_2ND
: return "KIPO-KAIST Core-A 2nd generation processor family";
3732 case EM_ARC_COMPACT2
: return "ARCv2";
3733 case EM_OPEN8
: return "Open8 8-bit RISC soft processor core";
3734 case EM_RL78
: return "Renesas RL78";
3735 case EM_VIDEOCORE5
: return "Broadcom VideoCore V processor";
3736 case EM_78K0R
: return "Renesas 78K0R";
3738 case EM_56800EX
: return "Freescale 56800EX Digital Signal Controller (DSC)";
3739 case EM_BA1
: return "Beyond BA1 CPU architecture";
3740 case EM_BA2
: return "Beyond BA2 CPU architecture";
3741 case EM_XCORE
: return "XMOS xCORE processor family";
3742 case EM_MCHP_PIC
: return "Microchip 8-bit PIC(r) family";
3743 case EM_INTELGT
: return "Intel Graphics Technology";
3745 case EM_KM32
: return "KM211 KM32 32-bit processor";
3746 case EM_KMX32
: return "KM211 KMX32 32-bit processor";
3747 case EM_KMX16
: return "KM211 KMX16 16-bit processor";
3748 case EM_KMX8
: return "KM211 KMX8 8-bit processor";
3749 case EM_KVARC
: return "KM211 KVARC processor";
3750 case EM_CDP
: return "Paneve CDP architecture family";
3751 case EM_COGE
: return "Cognitive Smart Memory Processor";
3752 case EM_COOL
: return "Bluechip Systems CoolEngine";
3753 case EM_NORC
: return "Nanoradio Optimized RISC";
3754 case EM_CSR_KALIMBA
: return "CSR Kalimba architecture family";
3756 case EM_Z80
: return "Zilog Z80";
3757 case EM_VISIUM
: return "CDS VISIUMcore processor";
3758 case EM_FT32
: return "FTDI Chip FT32";
3759 case EM_MOXIE
: return "Moxie";
3760 case EM_AMDGPU
: return "AMD GPU";
3761 /* 230 (all reserved) */
3763 case EM_RISCV
: return "RISC-V";
3764 case EM_LANAI
: return "Lanai 32-bit processor";
3765 case EM_CEVA
: return "CEVA Processor Architecture Family";
3766 case EM_CEVA_X2
: return "CEVA X2 Processor Family";
3767 case EM_BPF
: return "Linux BPF";
3768 case EM_GRAPHCORE_IPU
: return "Graphcore Intelligent Processing Unit";
3769 case EM_IMG1
: return "Imagination Technologies";
3771 case EM_NFP
: return "Netronome Flow Processor";
3772 case EM_VE
: return "NEC Vector Engine";
3773 case EM_CSKY
: return "C-SKY";
3774 case EM_ARC_COMPACT3_64
: return "Synopsys ARCv3 64-bit processor";
3775 case EM_MCS6502
: return "MOS Technology MCS 6502 processor";
3776 case EM_ARC_COMPACT3
: return "Synopsys ARCv3 32-bit processor";
3777 case EM_KVX
: return "Kalray VLIW core of the MPPA processor family";
3778 case EM_65816
: return "WDC 65816/65C816";
3779 case EM_LOONGARCH
: return "LoongArch";
3780 case EM_KF32
: return "ChipON KungFu32";
3782 /* Large numbers... */
3783 case EM_MT
: return "Morpho Techologies MT processor";
3784 case EM_ALPHA
: return "Alpha";
3785 case EM_WEBASSEMBLY
: return "Web Assembly";
3786 case EM_DLX
: return "OpenDLX";
3787 case EM_XSTORMY16
: return "Sanyo XStormy16 CPU core";
3788 case EM_IQ2000
: return "Vitesse IQ2000";
3790 case EM_NIOS32
: return "Altera Nios";
3791 case EM_CYGNUS_MEP
: return "Toshiba MeP Media Engine";
3792 case EM_ADAPTEVA_EPIPHANY
: return "Adapteva EPIPHANY";
3793 case EM_CYGNUS_FRV
: return "Fujitsu FR-V";
3794 case EM_S12Z
: return "Freescale S12Z";
3797 snprintf (buff
, sizeof (buff
), _("<unknown>: 0x%x"), e_machine
);
3803 decode_ARC_machine_flags (char *out
, unsigned e_flags
, unsigned e_machine
)
3805 /* ARC has two machine types EM_ARC_COMPACT and EM_ARC_COMPACT2. Some
3806 other compilers don't specify an architecture type in the e_flags, and
3807 instead use EM_ARC_COMPACT for old ARC600, ARC601, and ARC700
3808 architectures, and switch to EM_ARC_COMPACT2 for newer ARCEM and ARCHS
3811 Th GNU tools follows this use of EM_ARC_COMPACT and EM_ARC_COMPACT2,
3812 but also sets a specific architecture type in the e_flags field.
3814 However, when decoding the flags we don't worry if we see an
3815 unexpected pairing, for example EM_ARC_COMPACT machine type, with
3816 ARCEM architecture type. */
3818 switch (e_flags
& EF_ARC_MACH_MSK
)
3820 /* We only expect these to occur for EM_ARC_COMPACT2. */
3821 case EF_ARC_CPU_ARCV2EM
:
3822 out
= stpcpy (out
, ", ARC EM");
3824 case EF_ARC_CPU_ARCV2HS
:
3825 out
= stpcpy (out
, ", ARC HS");
3828 /* We only expect these to occur for EM_ARC_COMPACT. */
3829 case E_ARC_MACH_ARC600
:
3830 out
= stpcpy (out
, ", ARC600");
3832 case E_ARC_MACH_ARC601
:
3833 out
= stpcpy (out
, ", ARC601");
3835 case E_ARC_MACH_ARC700
:
3836 out
= stpcpy (out
, ", ARC700");
3839 /* The only times we should end up here are (a) A corrupt ELF, (b) A
3840 new ELF with new architecture being read by an old version of
3841 readelf, or (c) An ELF built with non-GNU compiler that does not
3842 set the architecture in the e_flags. */
3844 if (e_machine
== EM_ARC_COMPACT
)
3845 out
= stpcpy (out
, ", Unknown ARCompact");
3847 out
= stpcpy (out
, ", Unknown ARC");
3851 switch (e_flags
& EF_ARC_OSABI_MSK
)
3853 case E_ARC_OSABI_ORIG
:
3854 out
= stpcpy (out
, ", (ABI:legacy)");
3856 case E_ARC_OSABI_V2
:
3857 out
= stpcpy (out
, ", (ABI:v2)");
3859 /* Only upstream 3.9+ kernels will support ARCv2 ISA. */
3860 case E_ARC_OSABI_V3
:
3861 out
= stpcpy (out
, ", v3 no-legacy-syscalls ABI");
3863 case E_ARC_OSABI_V4
:
3864 out
= stpcpy (out
, ", v4 ABI");
3867 out
= stpcpy (out
, ", unrecognised ARC OSABI flag");
3874 decode_ARM_machine_flags (char *out
, unsigned e_flags
)
3877 bool unknown_abi
= false;
3879 eabi
= EF_ARM_EABI_VERSION (e_flags
);
3880 e_flags
&= ~ EF_ARM_EABIMASK
;
3882 /* Handle "generic" ARM flags. */
3883 if (e_flags
& EF_ARM_RELEXEC
)
3885 out
= stpcpy (out
, ", relocatable executable");
3886 e_flags
&= ~ EF_ARM_RELEXEC
;
3889 if (e_flags
& EF_ARM_PIC
)
3891 out
= stpcpy (out
, ", position independent");
3892 e_flags
&= ~ EF_ARM_PIC
;
3895 /* Now handle EABI specific flags. */
3899 out
= stpcpy (out
, ", <unrecognized EABI>");
3904 case EF_ARM_EABI_VER1
:
3905 out
= stpcpy (out
, ", Version1 EABI");
3910 /* Process flags one bit at a time. */
3911 flag
= e_flags
& - e_flags
;
3916 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
3917 out
= stpcpy (out
, ", sorted symbol tables");
3927 case EF_ARM_EABI_VER2
:
3928 out
= stpcpy (out
, ", Version2 EABI");
3933 /* Process flags one bit at a time. */
3934 flag
= e_flags
& - e_flags
;
3939 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
3940 out
= stpcpy (out
, ", sorted symbol tables");
3943 case EF_ARM_DYNSYMSUSESEGIDX
:
3944 out
= stpcpy (out
, ", dynamic symbols use segment index");
3947 case EF_ARM_MAPSYMSFIRST
:
3948 out
= stpcpy (out
, ", mapping symbols precede others");
3958 case EF_ARM_EABI_VER3
:
3959 out
= stpcpy (out
, ", Version3 EABI");
3962 case EF_ARM_EABI_VER4
:
3963 out
= stpcpy (out
, ", Version4 EABI");
3968 /* Process flags one bit at a time. */
3969 flag
= e_flags
& - e_flags
;
3975 out
= stpcpy (out
, ", BE8");
3979 out
= stpcpy (out
, ", LE8");
3989 case EF_ARM_EABI_VER5
:
3990 out
= stpcpy (out
, ", Version5 EABI");
3995 /* Process flags one bit at a time. */
3996 flag
= e_flags
& - e_flags
;
4002 out
= stpcpy (out
, ", BE8");
4006 out
= stpcpy (out
, ", LE8");
4009 case EF_ARM_ABI_FLOAT_SOFT
: /* Conflicts with EF_ARM_SOFT_FLOAT. */
4010 out
= stpcpy (out
, ", soft-float ABI");
4013 case EF_ARM_ABI_FLOAT_HARD
: /* Conflicts with EF_ARM_VFP_FLOAT. */
4014 out
= stpcpy (out
, ", hard-float ABI");
4024 case EF_ARM_EABI_UNKNOWN
:
4025 out
= stpcpy (out
, ", GNU EABI");
4030 /* Process flags one bit at a time. */
4031 flag
= e_flags
& - e_flags
;
4036 case EF_ARM_INTERWORK
:
4037 out
= stpcpy (out
, ", interworking enabled");
4040 case EF_ARM_APCS_26
:
4041 out
= stpcpy (out
, ", uses APCS/26");
4044 case EF_ARM_APCS_FLOAT
:
4045 out
= stpcpy (out
, ", uses APCS/float");
4049 out
= stpcpy (out
, ", position independent");
4053 out
= stpcpy (out
, ", 8 bit structure alignment");
4056 case EF_ARM_NEW_ABI
:
4057 out
= stpcpy (out
, ", uses new ABI");
4060 case EF_ARM_OLD_ABI
:
4061 out
= stpcpy (out
, ", uses old ABI");
4064 case EF_ARM_SOFT_FLOAT
:
4065 out
= stpcpy (out
, ", software FP");
4068 case EF_ARM_VFP_FLOAT
:
4069 out
= stpcpy (out
, ", VFP");
4080 out
= stpcpy (out
,_(", <unknown>"));
4085 decode_AVR_machine_flags (char *out
, unsigned e_flags
)
4087 switch (e_flags
& EF_AVR_MACH
)
4089 case E_AVR_MACH_AVR1
:
4090 out
= stpcpy (out
, ", avr:1");
4092 case E_AVR_MACH_AVR2
:
4093 out
= stpcpy (out
, ", avr:2");
4095 case E_AVR_MACH_AVR25
:
4096 out
= stpcpy (out
, ", avr:25");
4098 case E_AVR_MACH_AVR3
:
4099 out
= stpcpy (out
, ", avr:3");
4101 case E_AVR_MACH_AVR31
:
4102 out
= stpcpy (out
, ", avr:31");
4104 case E_AVR_MACH_AVR35
:
4105 out
= stpcpy (out
, ", avr:35");
4107 case E_AVR_MACH_AVR4
:
4108 out
= stpcpy (out
, ", avr:4");
4110 case E_AVR_MACH_AVR5
:
4111 out
= stpcpy (out
, ", avr:5");
4113 case E_AVR_MACH_AVR51
:
4114 out
= stpcpy (out
, ", avr:51");
4116 case E_AVR_MACH_AVR6
:
4117 out
= stpcpy (out
, ", avr:6");
4119 case E_AVR_MACH_AVRTINY
:
4120 out
= stpcpy (out
, ", avr:100");
4122 case E_AVR_MACH_XMEGA1
:
4123 out
= stpcpy (out
, ", avr:101");
4125 case E_AVR_MACH_XMEGA2
:
4126 out
= stpcpy (out
, ", avr:102");
4128 case E_AVR_MACH_XMEGA3
:
4129 out
= stpcpy (out
, ", avr:103");
4131 case E_AVR_MACH_XMEGA4
:
4132 out
= stpcpy (out
, ", avr:104");
4134 case E_AVR_MACH_XMEGA5
:
4135 out
= stpcpy (out
, ", avr:105");
4137 case E_AVR_MACH_XMEGA6
:
4138 out
= stpcpy (out
, ", avr:106");
4140 case E_AVR_MACH_XMEGA7
:
4141 out
= stpcpy (out
, ", avr:107");
4144 out
= stpcpy (out
, ", avr:<unknown>");
4148 if (e_flags
& EF_AVR_LINKRELAX_PREPARED
)
4149 out
= stpcpy (out
, ", link-relax");
4154 decode_BLACKFIN_machine_flags (char *out
, unsigned e_flags
)
4156 if (e_flags
& EF_BFIN_PIC
)
4157 out
= stpcpy (out
, ", PIC");
4159 if (e_flags
& EF_BFIN_FDPIC
)
4160 out
= stpcpy (out
, ", FDPIC");
4162 if (e_flags
& EF_BFIN_CODE_IN_L1
)
4163 out
= stpcpy (out
, ", code in L1");
4165 if (e_flags
& EF_BFIN_DATA_IN_L1
)
4166 out
= stpcpy (out
, ", data in L1");
4171 decode_FRV_machine_flags (char *out
, unsigned e_flags
)
4173 switch (e_flags
& EF_FRV_CPU_MASK
)
4175 case EF_FRV_CPU_GENERIC
:
4179 out
= stpcpy (out
, ", fr???");
4182 case EF_FRV_CPU_FR300
:
4183 out
= stpcpy (out
, ", fr300");
4186 case EF_FRV_CPU_FR400
:
4187 out
= stpcpy (out
, ", fr400");
4189 case EF_FRV_CPU_FR405
:
4190 out
= stpcpy (out
, ", fr405");
4193 case EF_FRV_CPU_FR450
:
4194 out
= stpcpy (out
, ", fr450");
4197 case EF_FRV_CPU_FR500
:
4198 out
= stpcpy (out
, ", fr500");
4200 case EF_FRV_CPU_FR550
:
4201 out
= stpcpy (out
, ", fr550");
4204 case EF_FRV_CPU_SIMPLE
:
4205 out
= stpcpy (out
, ", simple");
4207 case EF_FRV_CPU_TOMCAT
:
4208 out
= stpcpy (out
, ", tomcat");
4215 decode_IA64_machine_flags (char *out
, unsigned e_flags
, Filedata
*filedata
)
4217 if ((e_flags
& EF_IA_64_ABI64
))
4218 out
= stpcpy (out
, ", 64-bit");
4220 out
= stpcpy (out
, ", 32-bit");
4221 if ((e_flags
& EF_IA_64_REDUCEDFP
))
4222 out
= stpcpy (out
, ", reduced fp model");
4223 if ((e_flags
& EF_IA_64_NOFUNCDESC_CONS_GP
))
4224 out
= stpcpy (out
, ", no function descriptors, constant gp");
4225 else if ((e_flags
& EF_IA_64_CONS_GP
))
4226 out
= stpcpy (out
, ", constant gp");
4227 if ((e_flags
& EF_IA_64_ABSOLUTE
))
4228 out
= stpcpy (out
, ", absolute");
4229 if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_OPENVMS
)
4231 if ((e_flags
& EF_IA_64_VMS_LINKAGES
))
4232 out
= stpcpy (out
, ", vms_linkages");
4233 switch ((e_flags
& EF_IA_64_VMS_COMCOD
))
4235 case EF_IA_64_VMS_COMCOD_SUCCESS
:
4237 case EF_IA_64_VMS_COMCOD_WARNING
:
4238 out
= stpcpy (out
, ", warning");
4240 case EF_IA_64_VMS_COMCOD_ERROR
:
4241 out
= stpcpy (out
, ", error");
4243 case EF_IA_64_VMS_COMCOD_ABORT
:
4244 out
= stpcpy (out
, ", abort");
4247 warn (_("Unrecognised IA64 VMS Command Code: %x\n"),
4248 e_flags
& EF_IA_64_VMS_COMCOD
);
4249 out
= stpcpy (out
, ", <unknown>");
4256 decode_LOONGARCH_machine_flags (char *out
, unsigned int e_flags
)
4258 if (EF_LOONGARCH_IS_SOFT_FLOAT (e_flags
))
4259 out
= stpcpy (out
, ", SOFT-FLOAT");
4260 else if (EF_LOONGARCH_IS_SINGLE_FLOAT (e_flags
))
4261 out
= stpcpy (out
, ", SINGLE-FLOAT");
4262 else if (EF_LOONGARCH_IS_DOUBLE_FLOAT (e_flags
))
4263 out
= stpcpy (out
, ", DOUBLE-FLOAT");
4265 if (EF_LOONGARCH_IS_OBJ_V0 (e_flags
))
4266 out
= stpcpy (out
, ", OBJ-v0");
4267 else if (EF_LOONGARCH_IS_OBJ_V1 (e_flags
))
4268 out
= stpcpy (out
, ", OBJ-v1");
4273 decode_M68K_machine_flags (char *out
, unsigned int e_flags
)
4275 if ((e_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_M68000
)
4276 out
= stpcpy (out
, ", m68000");
4277 else if ((e_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_CPU32
)
4278 out
= stpcpy (out
, ", cpu32");
4279 else if ((e_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_FIDO
)
4280 out
= stpcpy (out
, ", fido_a");
4283 char const *isa
= _("unknown");
4284 char const *mac
= _("unknown mac");
4285 char const *additional
= NULL
;
4287 switch (e_flags
& EF_M68K_CF_ISA_MASK
)
4289 case EF_M68K_CF_ISA_A_NODIV
:
4291 additional
= ", nodiv";
4293 case EF_M68K_CF_ISA_A
:
4296 case EF_M68K_CF_ISA_A_PLUS
:
4299 case EF_M68K_CF_ISA_B_NOUSP
:
4301 additional
= ", nousp";
4303 case EF_M68K_CF_ISA_B
:
4306 case EF_M68K_CF_ISA_C
:
4309 case EF_M68K_CF_ISA_C_NODIV
:
4311 additional
= ", nodiv";
4314 out
= stpcpy (out
, ", cf, isa ");
4315 out
= stpcpy (out
, isa
);
4317 out
= stpcpy (out
, additional
);
4318 if (e_flags
& EF_M68K_CF_FLOAT
)
4319 out
= stpcpy (out
, ", float");
4320 switch (e_flags
& EF_M68K_CF_MAC_MASK
)
4325 case EF_M68K_CF_MAC
:
4328 case EF_M68K_CF_EMAC
:
4331 case EF_M68K_CF_EMAC_B
:
4337 out
= stpcpy (out
, ", ");
4338 out
= stpcpy (out
, mac
);
4345 decode_MeP_machine_flags (char *out
, unsigned int e_flags
)
4347 switch (e_flags
& EF_MEP_CPU_MASK
)
4349 case EF_MEP_CPU_MEP
:
4350 out
= stpcpy (out
, ", generic MeP");
4353 out
= stpcpy (out
, ", MeP C2");
4356 out
= stpcpy (out
, ", MeP C3");
4359 out
= stpcpy (out
, ", MeP C4");
4362 out
= stpcpy (out
, ", MeP C5");
4365 out
= stpcpy (out
, ", MeP H1");
4368 out
= stpcpy (out
, _(", <unknown MeP cpu type>"));
4372 switch (e_flags
& EF_MEP_COP_MASK
)
4374 case EF_MEP_COP_NONE
:
4376 case EF_MEP_COP_AVC
:
4377 out
= stpcpy (out
, ", AVC coprocessor");
4379 case EF_MEP_COP_AVC2
:
4380 out
= stpcpy (out
, ", AVC2 coprocessor");
4382 case EF_MEP_COP_FMAX
:
4383 out
= stpcpy (out
, ", FMAX coprocessor");
4385 case EF_MEP_COP_IVC2
:
4386 out
= stpcpy (out
, ", IVC2 coprocessor");
4389 out
= stpcpy (out
, _("<unknown MeP copro type>"));
4393 if (e_flags
& EF_MEP_LIBRARY
)
4394 out
= stpcpy (out
, ", Built for Library");
4396 if (e_flags
& EF_MEP_INDEX_MASK
)
4397 out
+= sprintf (out
, ", Configuration Index: %#x",
4398 e_flags
& EF_MEP_INDEX_MASK
);
4400 if (e_flags
& ~ EF_MEP_ALL_FLAGS
)
4401 out
+= sprintf (out
, _(", unknown flags bits: %#x"),
4402 e_flags
& ~ EF_MEP_ALL_FLAGS
);
4407 decode_MIPS_machine_flags (char *out
, unsigned int e_flags
)
4409 if (e_flags
& EF_MIPS_NOREORDER
)
4410 out
= stpcpy (out
, ", noreorder");
4412 if (e_flags
& EF_MIPS_PIC
)
4413 out
= stpcpy (out
, ", pic");
4415 if (e_flags
& EF_MIPS_CPIC
)
4416 out
= stpcpy (out
, ", cpic");
4418 if (e_flags
& EF_MIPS_UCODE
)
4419 out
= stpcpy (out
, ", ugen_reserved");
4421 if (e_flags
& EF_MIPS_ABI2
)
4422 out
= stpcpy (out
, ", abi2");
4424 if (e_flags
& EF_MIPS_OPTIONS_FIRST
)
4425 out
= stpcpy (out
, ", odk first");
4427 if (e_flags
& EF_MIPS_32BITMODE
)
4428 out
= stpcpy (out
, ", 32bitmode");
4430 if (e_flags
& EF_MIPS_NAN2008
)
4431 out
= stpcpy (out
, ", nan2008");
4433 if (e_flags
& EF_MIPS_FP64
)
4434 out
= stpcpy (out
, ", fp64");
4436 switch ((e_flags
& EF_MIPS_MACH
))
4438 case EF_MIPS_MACH_3900
:
4439 out
= stpcpy (out
, ", 3900");
4441 case EF_MIPS_MACH_4010
:
4442 out
= stpcpy (out
, ", 4010");
4444 case EF_MIPS_MACH_4100
:
4445 out
= stpcpy (out
, ", 4100");
4447 case EF_MIPS_MACH_4111
:
4448 out
= stpcpy (out
, ", 4111");
4450 case EF_MIPS_MACH_4120
:
4451 out
= stpcpy (out
, ", 4120");
4453 case EF_MIPS_MACH_4650
:
4454 out
= stpcpy (out
, ", 4650");
4456 case EF_MIPS_MACH_5400
:
4457 out
= stpcpy (out
, ", 5400");
4459 case EF_MIPS_MACH_5500
:
4460 out
= stpcpy (out
, ", 5500");
4462 case EF_MIPS_MACH_5900
:
4463 out
= stpcpy (out
, ", 5900");
4465 case EF_MIPS_MACH_SB1
:
4466 out
= stpcpy (out
, ", sb1");
4468 case EF_MIPS_MACH_9000
:
4469 out
= stpcpy (out
, ", 9000");
4471 case EF_MIPS_MACH_LS2E
:
4472 out
= stpcpy (out
, ", loongson-2e");
4474 case EF_MIPS_MACH_LS2F
:
4475 out
= stpcpy (out
, ", loongson-2f");
4477 case EF_MIPS_MACH_GS464
:
4478 out
= stpcpy (out
, ", gs464");
4480 case EF_MIPS_MACH_GS464E
:
4481 out
= stpcpy (out
, ", gs464e");
4483 case EF_MIPS_MACH_GS264E
:
4484 out
= stpcpy (out
, ", gs264e");
4486 case EF_MIPS_MACH_OCTEON
:
4487 out
= stpcpy (out
, ", octeon");
4489 case EF_MIPS_MACH_OCTEON2
:
4490 out
= stpcpy (out
, ", octeon2");
4492 case EF_MIPS_MACH_OCTEON3
:
4493 out
= stpcpy (out
, ", octeon3");
4495 case EF_MIPS_MACH_XLR
:
4496 out
= stpcpy (out
, ", xlr");
4498 case EF_MIPS_MACH_IAMR2
:
4499 out
= stpcpy (out
, ", interaptiv-mr2");
4501 case EF_MIPS_MACH_ALLEGREX
:
4502 out
= stpcpy (out
, ", allegrex");
4505 /* We simply ignore the field in this case to avoid confusion:
4506 MIPS ELF does not specify EF_MIPS_MACH, it is a GNU
4510 out
= stpcpy (out
, _(", unknown CPU"));
4514 switch ((e_flags
& EF_MIPS_ABI
))
4516 case EF_MIPS_ABI_O32
:
4517 out
= stpcpy (out
, ", o32");
4519 case EF_MIPS_ABI_O64
:
4520 out
= stpcpy (out
, ", o64");
4522 case EF_MIPS_ABI_EABI32
:
4523 out
= stpcpy (out
, ", eabi32");
4525 case EF_MIPS_ABI_EABI64
:
4526 out
= stpcpy (out
, ", eabi64");
4529 /* We simply ignore the field in this case to avoid confusion:
4530 MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension.
4531 This means it is likely to be an o32 file, but not for
4535 out
= stpcpy (out
, _(", unknown ABI"));
4539 if (e_flags
& EF_MIPS_ARCH_ASE_MDMX
)
4540 out
= stpcpy (out
, ", mdmx");
4542 if (e_flags
& EF_MIPS_ARCH_ASE_M16
)
4543 out
= stpcpy (out
, ", mips16");
4545 if (e_flags
& EF_MIPS_ARCH_ASE_MICROMIPS
)
4546 out
= stpcpy (out
, ", micromips");
4548 switch ((e_flags
& EF_MIPS_ARCH
))
4550 case EF_MIPS_ARCH_1
:
4551 out
= stpcpy (out
, ", mips1");
4553 case EF_MIPS_ARCH_2
:
4554 out
= stpcpy (out
, ", mips2");
4556 case EF_MIPS_ARCH_3
:
4557 out
= stpcpy (out
, ", mips3");
4559 case EF_MIPS_ARCH_4
:
4560 out
= stpcpy (out
, ", mips4");
4562 case EF_MIPS_ARCH_5
:
4563 out
= stpcpy (out
, ", mips5");
4565 case EF_MIPS_ARCH_32
:
4566 out
= stpcpy (out
, ", mips32");
4568 case EF_MIPS_ARCH_32R2
:
4569 out
= stpcpy (out
, ", mips32r2");
4571 case EF_MIPS_ARCH_32R6
:
4572 out
= stpcpy (out
, ", mips32r6");
4574 case EF_MIPS_ARCH_64
:
4575 out
= stpcpy (out
, ", mips64");
4577 case EF_MIPS_ARCH_64R2
:
4578 out
= stpcpy (out
, ", mips64r2");
4580 case EF_MIPS_ARCH_64R6
:
4581 out
= stpcpy (out
, ", mips64r6");
4584 out
= stpcpy (out
, _(", unknown ISA"));
4591 decode_MSP430_machine_flags (char *out
, unsigned e_flags
)
4593 out
= stpcpy (out
, _(": architecture variant: "));
4594 switch (e_flags
& EF_MSP430_MACH
)
4596 case E_MSP430_MACH_MSP430x11
:
4597 out
= stpcpy (out
, "MSP430x11");
4599 case E_MSP430_MACH_MSP430x11x1
:
4600 out
= stpcpy (out
, "MSP430x11x1 ");
4602 case E_MSP430_MACH_MSP430x12
:
4603 out
= stpcpy (out
, "MSP430x12");
4605 case E_MSP430_MACH_MSP430x13
:
4606 out
= stpcpy (out
, "MSP430x13");
4608 case E_MSP430_MACH_MSP430x14
:
4609 out
= stpcpy (out
, "MSP430x14");
4611 case E_MSP430_MACH_MSP430x15
:
4612 out
= stpcpy (out
, "MSP430x15");
4614 case E_MSP430_MACH_MSP430x16
:
4615 out
= stpcpy (out
, "MSP430x16");
4617 case E_MSP430_MACH_MSP430x31
:
4618 out
= stpcpy (out
, "MSP430x31");
4620 case E_MSP430_MACH_MSP430x32
:
4621 out
= stpcpy (out
, "MSP430x32");
4623 case E_MSP430_MACH_MSP430x33
:
4624 out
= stpcpy (out
, "MSP430x33");
4626 case E_MSP430_MACH_MSP430x41
:
4627 out
= stpcpy (out
, "MSP430x41");
4629 case E_MSP430_MACH_MSP430x42
:
4630 out
= stpcpy (out
, "MSP430x42");
4632 case E_MSP430_MACH_MSP430x43
:
4633 out
= stpcpy (out
, "MSP430x43");
4635 case E_MSP430_MACH_MSP430x44
:
4636 out
= stpcpy (out
, "MSP430x44");
4638 case E_MSP430_MACH_MSP430X
:
4639 out
= stpcpy (out
, "MSP430X");
4642 out
= stpcpy (out
, _(": unknown"));
4646 if (e_flags
& ~ EF_MSP430_MACH
)
4647 out
= stpcpy (out
, _(": unknown extra flag bits also present"));
4652 decode_NDS32_machine_flags (char *out
, unsigned e_flags
)
4658 bool has_fpu
= false;
4660 static const char *ABI_STRINGS
[] =
4662 "ABI v0", /* use r5 as return register; only used in N1213HC */
4663 "ABI v1", /* use r0 as return register */
4664 "ABI v2", /* use r0 as return register and don't reserve 24 bytes for arguments */
4665 "ABI v2fp", /* for FPU */
4669 static const char *VER_STRINGS
[] =
4671 "Andes ELF V1.3 or older",
4675 static const char *ARCH_STRINGS
[] =
4684 abi
= EF_NDS_ABI
& e_flags
;
4685 arch
= EF_NDS_ARCH
& e_flags
;
4686 config
= EF_NDS_INST
& e_flags
;
4687 version
= EF_NDS32_ELF_VERSION
& e_flags
;
4694 case E_NDS_ABI_V2FP
:
4695 case E_NDS_ABI_AABI
:
4696 case E_NDS_ABI_V2FP_PLUS
:
4697 /* In case there are holes in the array. */
4698 out
+= sprintf (out
, ", %s", ABI_STRINGS
[abi
>> EF_NDS_ABI_SHIFT
]);
4702 out
= stpcpy (out
, ", <unrecognized ABI>");
4708 case E_NDS32_ELF_VER_1_2
:
4709 case E_NDS32_ELF_VER_1_3
:
4710 case E_NDS32_ELF_VER_1_4
:
4711 out
+= sprintf (out
, ", %s", VER_STRINGS
[version
>> EF_NDS32_ELF_VERSION_SHIFT
]);
4715 out
= stpcpy (out
, ", <unrecognized ELF version number>");
4719 if (E_NDS_ABI_V0
== abi
)
4721 /* OLD ABI; only used in N1213HC, has performance extension 1. */
4722 out
= stpcpy (out
, ", Andes Star v1.0, N1213HC, MAC, PERF1");
4723 if (arch
== E_NDS_ARCH_STAR_V1_0
)
4724 out
= stpcpy (out
, ", 16b"); /* has 16-bit instructions */
4730 case E_NDS_ARCH_STAR_V1_0
:
4731 case E_NDS_ARCH_STAR_V2_0
:
4732 case E_NDS_ARCH_STAR_V3_0
:
4733 case E_NDS_ARCH_STAR_V3_M
:
4734 out
+= sprintf (out
, ", %s", ARCH_STRINGS
[arch
>> EF_NDS_ARCH_SHIFT
]);
4738 out
= stpcpy (out
, ", <unrecognized architecture>");
4739 /* ARCH version determines how the e_flags are interpreted.
4740 If it is unknown, we cannot proceed. */
4744 /* Newer ABI; Now handle architecture specific flags. */
4745 if (arch
== E_NDS_ARCH_STAR_V1_0
)
4747 if (config
& E_NDS32_HAS_MFUSR_PC_INST
)
4748 out
= stpcpy (out
, ", MFUSR_PC");
4750 if (!(config
& E_NDS32_HAS_NO_MAC_INST
))
4751 out
= stpcpy (out
, ", MAC");
4753 if (config
& E_NDS32_HAS_DIV_INST
)
4754 out
= stpcpy (out
, ", DIV");
4756 if (config
& E_NDS32_HAS_16BIT_INST
)
4757 out
= stpcpy (out
, ", 16b");
4761 if (config
& E_NDS32_HAS_MFUSR_PC_INST
)
4763 if (version
<= E_NDS32_ELF_VER_1_3
)
4764 out
= stpcpy (out
, ", [B8]");
4766 out
= stpcpy (out
, ", EX9");
4769 if (config
& E_NDS32_HAS_MAC_DX_INST
)
4770 out
= stpcpy (out
, ", MAC_DX");
4772 if (config
& E_NDS32_HAS_DIV_DX_INST
)
4773 out
= stpcpy (out
, ", DIV_DX");
4775 if (config
& E_NDS32_HAS_16BIT_INST
)
4777 if (version
<= E_NDS32_ELF_VER_1_3
)
4778 out
= stpcpy (out
, ", 16b");
4780 out
= stpcpy (out
, ", IFC");
4784 if (config
& E_NDS32_HAS_EXT_INST
)
4785 out
= stpcpy (out
, ", PERF1");
4787 if (config
& E_NDS32_HAS_EXT2_INST
)
4788 out
= stpcpy (out
, ", PERF2");
4790 if (config
& E_NDS32_HAS_FPU_INST
)
4793 out
= stpcpy (out
, ", FPU_SP");
4796 if (config
& E_NDS32_HAS_FPU_DP_INST
)
4799 out
= stpcpy (out
, ", FPU_DP");
4802 if (config
& E_NDS32_HAS_FPU_MAC_INST
)
4805 out
= stpcpy (out
, ", FPU_MAC");
4810 switch ((config
& E_NDS32_FPU_REG_CONF
) >> E_NDS32_FPU_REG_CONF_SHIFT
)
4812 case E_NDS32_FPU_REG_8SP_4DP
:
4813 out
= stpcpy (out
, ", FPU_REG:8/4");
4815 case E_NDS32_FPU_REG_16SP_8DP
:
4816 out
= stpcpy (out
, ", FPU_REG:16/8");
4818 case E_NDS32_FPU_REG_32SP_16DP
:
4819 out
= stpcpy (out
, ", FPU_REG:32/16");
4821 case E_NDS32_FPU_REG_32SP_32DP
:
4822 out
= stpcpy (out
, ", FPU_REG:32/32");
4827 if (config
& E_NDS32_HAS_AUDIO_INST
)
4828 out
= stpcpy (out
, ", AUDIO");
4830 if (config
& E_NDS32_HAS_STRING_INST
)
4831 out
= stpcpy (out
, ", STR");
4833 if (config
& E_NDS32_HAS_REDUCED_REGS
)
4834 out
= stpcpy (out
, ", 16REG");
4836 if (config
& E_NDS32_HAS_VIDEO_INST
)
4838 if (version
<= E_NDS32_ELF_VER_1_3
)
4839 out
= stpcpy (out
, ", VIDEO");
4841 out
= stpcpy (out
, ", SATURATION");
4844 if (config
& E_NDS32_HAS_ENCRIPT_INST
)
4845 out
= stpcpy (out
, ", ENCRP");
4847 if (config
& E_NDS32_HAS_L2C_INST
)
4848 out
= stpcpy (out
, ", L2C");
4854 decode_PARISC_machine_flags (char *out
, unsigned e_flags
)
4856 switch (e_flags
& EF_PARISC_ARCH
)
4858 case EFA_PARISC_1_0
:
4859 out
= stpcpy (out
, ", PA-RISC 1.0");
4861 case EFA_PARISC_1_1
:
4862 out
= stpcpy (out
, ", PA-RISC 1.1");
4864 case EFA_PARISC_2_0
:
4865 out
= stpcpy (out
, ", PA-RISC 2.0");
4870 if (e_flags
& EF_PARISC_TRAPNIL
)
4871 out
= stpcpy (out
, ", trapnil");
4872 if (e_flags
& EF_PARISC_EXT
)
4873 out
= stpcpy (out
, ", ext");
4874 if (e_flags
& EF_PARISC_LSB
)
4875 out
= stpcpy (out
, ", lsb");
4876 if (e_flags
& EF_PARISC_WIDE
)
4877 out
= stpcpy (out
, ", wide");
4878 if (e_flags
& EF_PARISC_NO_KABP
)
4879 out
= stpcpy (out
, ", no kabp");
4880 if (e_flags
& EF_PARISC_LAZYSWAP
)
4881 out
= stpcpy (out
, ", lazyswap");
4886 decode_RISCV_machine_flags (char *out
, unsigned e_flags
)
4888 if (e_flags
& EF_RISCV_RVC
)
4889 out
= stpcpy (out
, ", RVC");
4891 if (e_flags
& EF_RISCV_RVE
)
4892 out
= stpcpy (out
, ", RVE");
4894 if (e_flags
& EF_RISCV_TSO
)
4895 out
= stpcpy (out
, ", TSO");
4897 switch (e_flags
& EF_RISCV_FLOAT_ABI
)
4899 case EF_RISCV_FLOAT_ABI_SOFT
:
4900 out
= stpcpy (out
, ", soft-float ABI");
4903 case EF_RISCV_FLOAT_ABI_SINGLE
:
4904 out
= stpcpy (out
, ", single-float ABI");
4907 case EF_RISCV_FLOAT_ABI_DOUBLE
:
4908 out
= stpcpy (out
, ", double-float ABI");
4911 case EF_RISCV_FLOAT_ABI_QUAD
:
4912 out
= stpcpy (out
, ", quad-float ABI");
4919 decode_RL78_machine_flags (char *out
, unsigned e_flags
)
4921 switch (e_flags
& E_FLAG_RL78_CPU_MASK
)
4923 case E_FLAG_RL78_ANY_CPU
:
4925 case E_FLAG_RL78_G10
:
4926 out
= stpcpy (out
, ", G10");
4928 case E_FLAG_RL78_G13
:
4929 out
= stpcpy (out
, ", G13");
4931 case E_FLAG_RL78_G14
:
4932 out
= stpcpy (out
, ", G14");
4935 if (e_flags
& E_FLAG_RL78_64BIT_DOUBLES
)
4936 out
= stpcpy (out
, ", 64-bit doubles");
4941 decode_RX_machine_flags (char *out
, unsigned e_flags
)
4943 if (e_flags
& E_FLAG_RX_64BIT_DOUBLES
)
4944 out
= stpcpy (out
, ", 64-bit doubles");
4945 if (e_flags
& E_FLAG_RX_DSP
)
4946 out
= stpcpy (out
, ", dsp");
4947 if (e_flags
& E_FLAG_RX_PID
)
4948 out
= stpcpy (out
, ", pid");
4949 if (e_flags
& E_FLAG_RX_ABI
)
4950 out
= stpcpy (out
, ", RX ABI");
4951 if (e_flags
& E_FLAG_RX_SINSNS_SET
)
4952 out
= stpcpy (out
, (e_flags
& E_FLAG_RX_SINSNS_YES
4953 ? ", uses String instructions"
4954 : ", bans String instructions"));
4955 if (e_flags
& E_FLAG_RX_V2
)
4956 out
= stpcpy (out
, ", V2");
4957 if (e_flags
& E_FLAG_RX_V3
)
4958 out
= stpcpy (out
, ", V3");
4963 decode_SH_machine_flags (char *out
, unsigned e_flags
)
4965 switch ((e_flags
& EF_SH_MACH_MASK
))
4968 out
= stpcpy (out
, ", sh1");
4971 out
= stpcpy (out
, ", sh2");
4974 out
= stpcpy (out
, ", sh3");
4977 out
= stpcpy (out
, ", sh-dsp");
4980 out
= stpcpy (out
, ", sh3-dsp");
4983 out
= stpcpy (out
, ", sh4al-dsp");
4986 out
= stpcpy (out
, ", sh3e");
4989 out
= stpcpy (out
, ", sh4");
4992 out
= stpcpy (out
, ", sh5");
4995 out
= stpcpy (out
, ", sh2e");
4998 out
= stpcpy (out
, ", sh4a");
5001 out
= stpcpy (out
, ", sh2a");
5004 out
= stpcpy (out
, ", sh4-nofpu");
5007 out
= stpcpy (out
, ", sh4a-nofpu");
5010 out
= stpcpy (out
, ", sh2a-nofpu");
5013 out
= stpcpy (out
, ", sh3-nommu");
5015 case EF_SH4_NOMMU_NOFPU
:
5016 out
= stpcpy (out
, ", sh4-nommu-nofpu");
5018 case EF_SH2A_SH4_NOFPU
:
5019 out
= stpcpy (out
, ", sh2a-nofpu-or-sh4-nommu-nofpu");
5021 case EF_SH2A_SH3_NOFPU
:
5022 out
= stpcpy (out
, ", sh2a-nofpu-or-sh3-nommu");
5025 out
= stpcpy (out
, ", sh2a-or-sh4");
5028 out
= stpcpy (out
, ", sh2a-or-sh3e");
5031 out
= stpcpy (out
, _(", unknown ISA"));
5035 if (e_flags
& EF_SH_PIC
)
5036 out
= stpcpy (out
, ", pic");
5038 if (e_flags
& EF_SH_FDPIC
)
5039 out
= stpcpy (out
, ", fdpic");
5044 decode_SPARC_machine_flags (char *out
, unsigned e_flags
)
5046 if (e_flags
& EF_SPARC_32PLUS
)
5047 out
= stpcpy (out
, ", v8+");
5049 if (e_flags
& EF_SPARC_SUN_US1
)
5050 out
= stpcpy (out
, ", ultrasparcI");
5052 if (e_flags
& EF_SPARC_SUN_US3
)
5053 out
= stpcpy (out
, ", ultrasparcIII");
5055 if (e_flags
& EF_SPARC_HAL_R1
)
5056 out
= stpcpy (out
, ", halr1");
5058 if (e_flags
& EF_SPARC_LEDATA
)
5059 out
= stpcpy (out
, ", ledata");
5061 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_TSO
)
5062 out
= stpcpy (out
, ", tso");
5064 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_PSO
)
5065 out
= stpcpy (out
, ", pso");
5067 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_RMO
)
5068 out
= stpcpy (out
, ", rmo");
5073 decode_V800_machine_flags (char *out
, unsigned int e_flags
)
5075 if ((e_flags
& EF_RH850_ABI
) == EF_RH850_ABI
)
5076 out
= stpcpy (out
, ", RH850 ABI");
5078 if (e_flags
& EF_V800_850E3
)
5079 out
= stpcpy (out
, ", V3 architecture");
5081 if ((e_flags
& (EF_RH850_FPU_DOUBLE
| EF_RH850_FPU_SINGLE
)) == 0)
5082 out
= stpcpy (out
, ", FPU not used");
5084 if ((e_flags
& (EF_RH850_REGMODE22
| EF_RH850_REGMODE32
)) == 0)
5085 out
= stpcpy (out
, ", regmode: COMMON");
5087 if ((e_flags
& (EF_RH850_GP_FIX
| EF_RH850_GP_NOFIX
)) == 0)
5088 out
= stpcpy (out
, ", r4 not used");
5090 if ((e_flags
& (EF_RH850_EP_FIX
| EF_RH850_EP_NOFIX
)) == 0)
5091 out
= stpcpy (out
, ", r30 not used");
5093 if ((e_flags
& (EF_RH850_TP_FIX
| EF_RH850_TP_NOFIX
)) == 0)
5094 out
= stpcpy (out
, ", r5 not used");
5096 if ((e_flags
& (EF_RH850_REG2_RESERVE
| EF_RH850_REG2_NORESERVE
)) == 0)
5097 out
= stpcpy (out
, ", r2 not used");
5099 for (e_flags
&= 0xFFFF; e_flags
; e_flags
&= ~ (e_flags
& - e_flags
))
5101 switch (e_flags
& - e_flags
)
5103 case EF_RH850_FPU_DOUBLE
:
5104 out
= stpcpy (out
, ", double precision FPU");
5106 case EF_RH850_FPU_SINGLE
:
5107 out
= stpcpy (out
, ", single precision FPU");
5109 case EF_RH850_REGMODE22
:
5110 out
= stpcpy (out
, ", regmode:22");
5112 case EF_RH850_REGMODE32
:
5113 out
= stpcpy (out
, ", regmode:23");
5115 case EF_RH850_GP_FIX
:
5116 out
= stpcpy (out
, ", r4 fixed");
5118 case EF_RH850_GP_NOFIX
:
5119 out
= stpcpy (out
, ", r4 free");
5121 case EF_RH850_EP_FIX
:
5122 out
= stpcpy (out
, ", r30 fixed");
5124 case EF_RH850_EP_NOFIX
:
5125 out
= stpcpy (out
, ", r30 free");
5127 case EF_RH850_TP_FIX
:
5128 out
= stpcpy (out
, ", r5 fixed");
5130 case EF_RH850_TP_NOFIX
:
5131 out
= stpcpy (out
, ", r5 free");
5133 case EF_RH850_REG2_RESERVE
:
5134 out
= stpcpy (out
, ", r2 fixed");
5136 case EF_RH850_REG2_NORESERVE
:
5137 out
= stpcpy (out
, ", r2 free");
5147 decode_V850_machine_flags (char *out
, unsigned int e_flags
)
5149 switch (e_flags
& EF_V850_ARCH
)
5151 case E_V850E3V5_ARCH
:
5152 out
= stpcpy (out
, ", v850e3v5");
5154 case E_V850E2V3_ARCH
:
5155 out
= stpcpy (out
, ", v850e2v3");
5158 out
= stpcpy (out
, ", v850e2");
5161 out
= stpcpy (out
, ", v850e1");
5164 out
= stpcpy (out
, ", v850e");
5167 out
= stpcpy (out
, ", v850");
5170 out
= stpcpy (out
, _(", unknown v850 architecture variant"));
5177 decode_Z80_machine_flags (char *out
, unsigned int e_flags
)
5179 switch (e_flags
& EF_Z80_MACH_MSK
)
5181 case EF_Z80_MACH_Z80
:
5182 out
= stpcpy (out
, ", Z80");
5184 case EF_Z80_MACH_Z180
:
5185 out
= stpcpy (out
, ", Z180");
5187 case EF_Z80_MACH_R800
:
5188 out
= stpcpy (out
, ", R800");
5190 case EF_Z80_MACH_EZ80_Z80
:
5191 out
= stpcpy (out
, ", EZ80");
5193 case EF_Z80_MACH_EZ80_ADL
:
5194 out
= stpcpy (out
, ", EZ80, ADL");
5196 case EF_Z80_MACH_GBZ80
:
5197 out
= stpcpy (out
, ", GBZ80");
5199 case EF_Z80_MACH_Z80N
:
5200 out
= stpcpy (out
, ", Z80N");
5203 out
= stpcpy (out
, _(", unknown"));
5210 decode_AMDGPU_machine_flags (char *out
, unsigned int e_flags
, Filedata
*filedata
)
5212 unsigned char *e_ident
= filedata
->file_header
.e_ident
;
5213 unsigned char osabi
= e_ident
[EI_OSABI
];
5214 unsigned char abiversion
= e_ident
[EI_ABIVERSION
];
5217 /* HSA OS ABI v2 used a different encoding, but we don't need to support it,
5218 it has been deprecated for a while.
5220 The PAL, MESA3D and NONE OS ABIs are not properly versioned, at the time
5221 of writing, they use the same flags as HSA v3, so the code below uses that
5223 if (osabi
== ELFOSABI_AMDGPU_HSA
&& abiversion
< ELFABIVERSION_AMDGPU_HSA_V3
)
5226 mach
= e_flags
& EF_AMDGPU_MACH
;
5229 #define AMDGPU_CASE(code, string) \
5230 case code: out = stpcpy (out, ", " string); break;
5231 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX600
, "gfx600")
5232 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX601
, "gfx601")
5233 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX700
, "gfx700")
5234 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX701
, "gfx701")
5235 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX702
, "gfx702")
5236 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX703
, "gfx703")
5237 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX704
, "gfx704")
5238 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX801
, "gfx801")
5239 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX802
, "gfx802")
5240 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX803
, "gfx803")
5241 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX810
, "gfx810")
5242 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX900
, "gfx900")
5243 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX902
, "gfx902")
5244 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX904
, "gfx904")
5245 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX906
, "gfx906")
5246 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX908
, "gfx908")
5247 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX909
, "gfx909")
5248 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX90C
, "gfx90c")
5249 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1010
, "gfx1010")
5250 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1011
, "gfx1011")
5251 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1012
, "gfx1012")
5252 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1030
, "gfx1030")
5253 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1031
, "gfx1031")
5254 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1032
, "gfx1032")
5255 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1033
, "gfx1033")
5256 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1100
, "gfx1100")
5257 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1101
, "gfx1101")
5258 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1102
, "gfx1102")
5259 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX602
, "gfx602")
5260 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX705
, "gfx705")
5261 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX805
, "gfx805")
5262 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1035
, "gfx1035")
5263 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1034
, "gfx1034")
5264 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX90A
, "gfx90a")
5265 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX940
, "gfx940")
5266 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1013
, "gfx1013")
5267 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1036
, "gfx1036")
5269 out
+= sprintf (out
, _(", <unknown AMDGPU GPU type: %#x>"), mach
);
5274 e_flags
&= ~EF_AMDGPU_MACH
;
5276 if ((osabi
== ELFOSABI_AMDGPU_HSA
5277 && abiversion
== ELFABIVERSION_AMDGPU_HSA_V3
)
5278 || osabi
!= ELFOSABI_AMDGPU_HSA
)
5280 /* For HSA v3 and other OS ABIs. */
5281 if (e_flags
& EF_AMDGPU_FEATURE_XNACK_V3
)
5283 out
= stpcpy (out
, ", xnack on");
5284 e_flags
&= ~EF_AMDGPU_FEATURE_XNACK_V3
;
5287 if (e_flags
& EF_AMDGPU_FEATURE_SRAMECC_V3
)
5289 out
= stpcpy (out
, ", sramecc on");
5290 e_flags
&= ~EF_AMDGPU_FEATURE_SRAMECC_V3
;
5298 xnack
= e_flags
& EF_AMDGPU_FEATURE_XNACK_V4
;
5301 case EF_AMDGPU_FEATURE_XNACK_UNSUPPORTED_V4
:
5304 case EF_AMDGPU_FEATURE_XNACK_ANY_V4
:
5305 out
= stpcpy (out
, ", xnack any");
5308 case EF_AMDGPU_FEATURE_XNACK_OFF_V4
:
5309 out
= stpcpy (out
, ", xnack off");
5312 case EF_AMDGPU_FEATURE_XNACK_ON_V4
:
5313 out
= stpcpy (out
, ", xnack on");
5317 out
+= sprintf (out
, _(", <unknown xnack value: %#x>"), xnack
);
5321 e_flags
&= ~EF_AMDGPU_FEATURE_XNACK_V4
;
5323 sramecc
= e_flags
& EF_AMDGPU_FEATURE_SRAMECC_V4
;
5326 case EF_AMDGPU_FEATURE_SRAMECC_UNSUPPORTED_V4
:
5329 case EF_AMDGPU_FEATURE_SRAMECC_ANY_V4
:
5330 out
= stpcpy (out
, ", sramecc any");
5333 case EF_AMDGPU_FEATURE_SRAMECC_OFF_V4
:
5334 out
= stpcpy (out
, ", sramecc off");
5337 case EF_AMDGPU_FEATURE_SRAMECC_ON_V4
:
5338 out
= stpcpy (out
, ", sramecc on");
5342 out
+= sprintf (out
, _(", <unknown sramecc value: %#x>"), sramecc
);
5346 e_flags
&= ~EF_AMDGPU_FEATURE_SRAMECC_V4
;
5350 out
+= sprintf (out
, _(", unknown flags bits: %#x"), e_flags
);
5355 get_machine_flags (Filedata
* filedata
, unsigned e_flags
, unsigned e_machine
)
5357 static char buf
[1024];
5369 case EM_ARC_COMPACT3
:
5370 out
= stpcpy (out
, ", HS5x");
5373 case EM_ARC_COMPACT3_64
:
5374 out
= stpcpy (out
, ", HS6x");
5377 case EM_ARC_COMPACT2
:
5378 case EM_ARC_COMPACT
:
5379 out
= decode_ARC_machine_flags (out
, e_flags
, e_machine
);
5383 out
= decode_ARM_machine_flags (out
, e_flags
);
5387 out
= decode_AVR_machine_flags (out
, e_flags
);
5391 out
= decode_BLACKFIN_machine_flags (out
, e_flags
);
5395 out
= decode_FRV_machine_flags (out
, e_flags
);
5399 out
= decode_M68K_machine_flags (out
, e_flags
);
5403 out
= decode_AMDGPU_machine_flags (out
, e_flags
, filedata
);
5407 out
= decode_MeP_machine_flags (out
, e_flags
);
5411 if (e_flags
& EF_PPC_EMB
)
5412 out
= stpcpy (out
, ", emb");
5414 if (e_flags
& EF_PPC_RELOCATABLE
)
5415 out
= stpcpy (out
, _(", relocatable"));
5417 if (e_flags
& EF_PPC_RELOCATABLE_LIB
)
5418 out
= stpcpy (out
, _(", relocatable-lib"));
5422 if (e_flags
& EF_PPC64_ABI
)
5423 out
+= sprintf (out
, ", abiv%d", e_flags
& EF_PPC64_ABI
);
5427 out
= decode_V800_machine_flags (out
, e_flags
);
5431 case EM_CYGNUS_V850
:
5432 out
= decode_V850_machine_flags (out
, e_flags
);
5436 case EM_CYGNUS_M32R
:
5437 if ((e_flags
& EF_M32R_ARCH
) == E_M32R_ARCH
)
5438 out
= stpcpy (out
, ", m32r");
5442 case EM_MIPS_RS3_LE
:
5443 out
= decode_MIPS_machine_flags (out
, e_flags
);
5447 out
= decode_NDS32_machine_flags (out
, e_flags
);
5451 switch (EF_NFP_MACH (e_flags
))
5453 case E_NFP_MACH_3200
:
5454 out
= stpcpy (out
, ", NFP-32xx");
5456 case E_NFP_MACH_6000
:
5457 out
= stpcpy (out
, ", NFP-6xxx");
5463 out
= decode_RISCV_machine_flags (out
, e_flags
);
5467 out
= decode_SH_machine_flags (out
, e_flags
);
5471 if (e_flags
& EF_OR1K_NODELAY
)
5472 out
= stpcpy (out
, ", no delay");
5476 out
+= sprintf (out
, ", CPU Version: %u", e_flags
& EF_BPF_CPUVER
);
5480 out
= decode_SPARC_machine_flags (out
, e_flags
);
5484 out
= decode_PARISC_machine_flags (out
, e_flags
);
5489 if ((e_flags
& EF_PICOJAVA_NEWCALLS
) == EF_PICOJAVA_NEWCALLS
)
5490 out
= stpcpy (out
, ", new calling convention");
5492 if ((e_flags
& EF_PICOJAVA_GNUCALLS
) == EF_PICOJAVA_GNUCALLS
)
5493 out
= stpcpy (out
, ", gnu calling convention");
5497 out
= decode_IA64_machine_flags (out
, e_flags
, filedata
);
5501 if ((e_flags
& EF_VAX_NONPIC
))
5502 out
= stpcpy (out
, ", non-PIC");
5503 if ((e_flags
& EF_VAX_DFLOAT
))
5504 out
= stpcpy (out
, ", D-Float");
5505 if ((e_flags
& EF_VAX_GFLOAT
))
5506 out
= stpcpy (out
, ", G-Float");
5510 if (e_flags
& EF_VISIUM_ARCH_MCM
)
5511 out
= stpcpy (out
, ", mcm");
5512 else if (e_flags
& EF_VISIUM_ARCH_MCM24
)
5513 out
= stpcpy (out
, ", mcm24");
5514 if (e_flags
& EF_VISIUM_ARCH_GR6
)
5515 out
= stpcpy (out
, ", gr6");
5519 out
= decode_RL78_machine_flags (out
, e_flags
);
5523 out
= decode_RX_machine_flags (out
, e_flags
);
5527 if (e_flags
& EF_S390_HIGH_GPRS
)
5528 out
= stpcpy (out
, ", highgprs");
5532 if ((e_flags
& EF_C6000_REL
))
5533 out
= stpcpy (out
, ", relocatable module");
5537 if ((e_flags
& (ELF_KVX_CORE_MAJOR_MASK
| ELF_KVX_CORE_MINOR_MASK
)) == ELF_KVX_CORE_KV3_1
)
5538 strcat (buf
, ", Kalray VLIW kv3-1");
5539 else if ((e_flags
& (ELF_KVX_CORE_MAJOR_MASK
| ELF_KVX_CORE_MINOR_MASK
)) == ELF_KVX_CORE_KV3_2
)
5540 strcat (buf
, ", Kalray VLIW kv3-2");
5541 else if ((e_flags
& (ELF_KVX_CORE_MAJOR_MASK
| ELF_KVX_CORE_MINOR_MASK
)) == ELF_KVX_CORE_KV4_1
)
5542 strcat (buf
, ", Kalray VLIW kv4-1");
5544 strcat (buf
, ", unknown KVX MPPA");
5548 out
= decode_MSP430_machine_flags (out
, e_flags
);
5552 out
= decode_Z80_machine_flags (out
, e_flags
);
5556 out
= decode_LOONGARCH_machine_flags (out
, e_flags
);
5565 get_osabi_name (Filedata
* filedata
, unsigned int osabi
)
5567 static char buff
[32];
5571 case ELFOSABI_NONE
: return "UNIX - System V";
5572 case ELFOSABI_HPUX
: return "UNIX - HP-UX";
5573 case ELFOSABI_NETBSD
: return "UNIX - NetBSD";
5574 case ELFOSABI_GNU
: return "UNIX - GNU";
5575 case ELFOSABI_SOLARIS
: return "UNIX - Solaris";
5576 case ELFOSABI_AIX
: return "UNIX - AIX";
5577 case ELFOSABI_IRIX
: return "UNIX - IRIX";
5578 case ELFOSABI_FREEBSD
: return "UNIX - FreeBSD";
5579 case ELFOSABI_TRU64
: return "UNIX - TRU64";
5580 case ELFOSABI_MODESTO
: return "Novell - Modesto";
5581 case ELFOSABI_OPENBSD
: return "UNIX - OpenBSD";
5582 case ELFOSABI_OPENVMS
: return "VMS - OpenVMS";
5583 case ELFOSABI_NSK
: return "HP - Non-Stop Kernel";
5584 case ELFOSABI_AROS
: return "AROS";
5585 case ELFOSABI_FENIXOS
: return "FenixOS";
5586 case ELFOSABI_CLOUDABI
: return "Nuxi CloudABI";
5587 case ELFOSABI_OPENVOS
: return "Stratus Technologies OpenVOS";
5588 case ELFOSABI_CUDA
: return "CUDA";
5591 switch (filedata
->file_header
.e_machine
)
5596 case ELFOSABI_AMDGPU_HSA
: return "AMD HSA";
5597 case ELFOSABI_AMDGPU_PAL
: return "AMD PAL";
5598 case ELFOSABI_AMDGPU_MESA3D
: return "AMD Mesa3D";
5607 case ELFOSABI_ARM
: return "ARM";
5608 case ELFOSABI_ARM_FDPIC
: return "ARM FDPIC";
5619 case ELFOSABI_STANDALONE
: return _("Standalone App");
5628 case ELFOSABI_C6000_ELFABI
: return _("Bare-metal C6000");
5629 case ELFOSABI_C6000_LINUX
: return "Linux C6000";
5638 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), osabi
);
5644 get_aarch64_segment_type (unsigned long type
)
5648 case PT_AARCH64_ARCHEXT
: return "AARCH64_ARCHEXT";
5649 case PT_AARCH64_MEMTAG_MTE
: return "AARCH64_MEMTAG_MTE";
5650 default: return NULL
;
5655 get_arm_segment_type (unsigned long type
)
5659 case PT_ARM_ARCHEXT
: return "ARM_ARCHEXT";
5660 case PT_ARM_EXIDX
: return "ARM_EXIDX";
5661 default: return NULL
;
5666 get_s390_segment_type (unsigned long type
)
5670 case PT_S390_PGSTE
: return "S390_PGSTE";
5671 default: return NULL
;
5676 get_mips_segment_type (unsigned long type
)
5680 case PT_MIPS_REGINFO
: return "REGINFO";
5681 case PT_MIPS_RTPROC
: return "RTPROC";
5682 case PT_MIPS_OPTIONS
: return "OPTIONS";
5683 case PT_MIPS_ABIFLAGS
: return "ABIFLAGS";
5684 default: return NULL
;
5689 get_parisc_segment_type (unsigned long type
)
5693 case PT_PARISC_ARCHEXT
: return "PARISC_ARCHEXT";
5694 case PT_PARISC_UNWIND
: return "PARISC_UNWIND";
5695 case PT_PARISC_WEAKORDER
: return "PARISC_WEAKORDER";
5696 default: return NULL
;
5701 get_ia64_segment_type (unsigned long type
)
5705 case PT_IA_64_ARCHEXT
: return "IA_64_ARCHEXT";
5706 case PT_IA_64_UNWIND
: return "IA_64_UNWIND";
5707 default: return NULL
;
5712 get_tic6x_segment_type (unsigned long type
)
5716 case PT_C6000_PHATTR
: return "C6000_PHATTR";
5717 default: return NULL
;
5722 get_riscv_segment_type (unsigned long type
)
5726 case PT_RISCV_ATTRIBUTES
: return "RISCV_ATTRIBUTES";
5727 default: return NULL
;
5732 get_hpux_segment_type (unsigned long type
, unsigned e_machine
)
5734 if (e_machine
== EM_PARISC
)
5737 case PT_HP_TLS
: return "HP_TLS";
5738 case PT_HP_CORE_NONE
: return "HP_CORE_NONE";
5739 case PT_HP_CORE_VERSION
: return "HP_CORE_VERSION";
5740 case PT_HP_CORE_KERNEL
: return "HP_CORE_KERNEL";
5741 case PT_HP_CORE_COMM
: return "HP_CORE_COMM";
5742 case PT_HP_CORE_PROC
: return "HP_CORE_PROC";
5743 case PT_HP_CORE_LOADABLE
: return "HP_CORE_LOADABLE";
5744 case PT_HP_CORE_STACK
: return "HP_CORE_STACK";
5745 case PT_HP_CORE_SHM
: return "HP_CORE_SHM";
5746 case PT_HP_CORE_MMF
: return "HP_CORE_MMF";
5747 case PT_HP_PARALLEL
: return "HP_PARALLEL";
5748 case PT_HP_FASTBIND
: return "HP_FASTBIND";
5749 case PT_HP_OPT_ANNOT
: return "HP_OPT_ANNOT";
5750 case PT_HP_HSL_ANNOT
: return "HP_HSL_ANNOT";
5751 case PT_HP_STACK
: return "HP_STACK";
5752 case PT_HP_CORE_UTSNAME
: return "HP_CORE_UTSNAME";
5757 if (e_machine
== EM_IA_64
)
5760 case PT_HP_TLS
: return "HP_TLS";
5761 case PT_IA_64_HP_OPT_ANOT
: return "HP_OPT_ANNOT";
5762 case PT_IA_64_HP_HSL_ANOT
: return "HP_HSL_ANNOT";
5763 case PT_IA_64_HP_STACK
: return "HP_STACK";
5772 get_solaris_segment_type (unsigned long type
)
5776 case PT_SUNW_UNWIND
: return "SUNW_UNWIND";
5777 case PT_SUNW_EH_FRAME
: return "SUNW_EH_FRAME";
5778 case PT_SUNWBSS
: return "SUNW_BSS";
5779 case PT_SUNWSTACK
: return "SUNW_STACK";
5780 case PT_SUNWDTRACE
: return "SUNW_DTRACE";
5781 case PT_SUNWCAP
: return "SUNW_CAP";
5782 default: return NULL
;
5787 get_os_specific_segment_type (Filedata
* filedata
, unsigned long p_type
)
5789 static char buff
[32];
5790 const char * result
= NULL
;
5792 switch (filedata
->file_header
.e_ident
[EI_OSABI
])
5795 case ELFOSABI_FREEBSD
:
5796 if (p_type
>= PT_GNU_MBIND_LO
&& p_type
<= PT_GNU_MBIND_HI
)
5798 sprintf (buff
, "GNU_MBIND+%#lx", p_type
- PT_GNU_MBIND_LO
);
5804 result
= get_hpux_segment_type (p_type
,
5805 filedata
->file_header
.e_machine
);
5808 case ELFOSABI_SOLARIS
:
5809 result
= get_solaris_segment_type (p_type
);
5821 case PT_GNU_EH_FRAME
: return "GNU_EH_FRAME";
5822 case PT_GNU_STACK
: return "GNU_STACK";
5823 case PT_GNU_RELRO
: return "GNU_RELRO";
5824 case PT_GNU_PROPERTY
: return "GNU_PROPERTY";
5825 case PT_GNU_SFRAME
: return "GNU_SFRAME";
5827 case PT_OPENBSD_MUTABLE
: return "OPENBSD_MUTABLE";
5828 case PT_OPENBSD_RANDOMIZE
: return "OPENBSD_RANDOMIZE";
5829 case PT_OPENBSD_WXNEEDED
: return "OPENBSD_WXNEEDED";
5830 case PT_OPENBSD_NOBTCFI
: return "OPENBSD_NOBTCFI";
5831 case PT_OPENBSD_SYSCALLS
: return "OPENBSD_SYSCALLS";
5832 case PT_OPENBSD_BOOTDATA
: return "OPENBSD_BOOTDATA";
5838 sprintf (buff
, "LOOS+%#lx", p_type
- PT_LOOS
);
5843 get_processor_specific_segment_type (Filedata
* filedata
, unsigned long p_type
)
5845 static char buff
[32];
5846 const char * result
= NULL
;
5848 switch (filedata
->file_header
.e_machine
)
5851 result
= get_aarch64_segment_type (p_type
);
5855 result
= get_arm_segment_type (p_type
);
5859 case EM_MIPS_RS3_LE
:
5860 result
= get_mips_segment_type (p_type
);
5864 result
= get_parisc_segment_type (p_type
);
5868 result
= get_ia64_segment_type (p_type
);
5872 result
= get_tic6x_segment_type (p_type
);
5877 result
= get_s390_segment_type (p_type
);
5881 result
= get_riscv_segment_type (p_type
);
5892 sprintf (buff
, "LOPROC+%#lx", p_type
- PT_LOPROC
);
5897 get_segment_type (Filedata
* filedata
, unsigned long p_type
)
5899 static char buff
[32];
5903 case PT_NULL
: return "NULL";
5904 case PT_LOAD
: return "LOAD";
5905 case PT_DYNAMIC
: return "DYNAMIC";
5906 case PT_INTERP
: return "INTERP";
5907 case PT_NOTE
: return "NOTE";
5908 case PT_SHLIB
: return "SHLIB";
5909 case PT_PHDR
: return "PHDR";
5910 case PT_TLS
: return "TLS";
5911 case PT_NUM
: return "NUM";
5914 if ((p_type
>= PT_LOOS
) && (p_type
<= PT_HIOS
))
5915 return get_os_specific_segment_type (filedata
, p_type
);
5917 if ((p_type
>= PT_LOPROC
) && (p_type
<= PT_HIPROC
))
5918 return get_processor_specific_segment_type (filedata
, p_type
);
5920 snprintf (buff
, sizeof (buff
), _("<unknown>: %lx"), p_type
);
5925 get_arc_section_type_name (unsigned int sh_type
)
5929 case SHT_ARC_ATTRIBUTES
: return "ARC_ATTRIBUTES";
5937 get_mips_section_type_name (unsigned int sh_type
)
5941 case SHT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
5942 case SHT_MIPS_MSYM
: return "MIPS_MSYM";
5943 case SHT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
5944 case SHT_MIPS_GPTAB
: return "MIPS_GPTAB";
5945 case SHT_MIPS_UCODE
: return "MIPS_UCODE";
5946 case SHT_MIPS_DEBUG
: return "MIPS_DEBUG";
5947 case SHT_MIPS_REGINFO
: return "MIPS_REGINFO";
5948 case SHT_MIPS_PACKAGE
: return "MIPS_PACKAGE";
5949 case SHT_MIPS_PACKSYM
: return "MIPS_PACKSYM";
5950 case SHT_MIPS_RELD
: return "MIPS_RELD";
5951 case SHT_MIPS_IFACE
: return "MIPS_IFACE";
5952 case SHT_MIPS_CONTENT
: return "MIPS_CONTENT";
5953 case SHT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
5954 case SHT_MIPS_SHDR
: return "MIPS_SHDR";
5955 case SHT_MIPS_FDESC
: return "MIPS_FDESC";
5956 case SHT_MIPS_EXTSYM
: return "MIPS_EXTSYM";
5957 case SHT_MIPS_DENSE
: return "MIPS_DENSE";
5958 case SHT_MIPS_PDESC
: return "MIPS_PDESC";
5959 case SHT_MIPS_LOCSYM
: return "MIPS_LOCSYM";
5960 case SHT_MIPS_AUXSYM
: return "MIPS_AUXSYM";
5961 case SHT_MIPS_OPTSYM
: return "MIPS_OPTSYM";
5962 case SHT_MIPS_LOCSTR
: return "MIPS_LOCSTR";
5963 case SHT_MIPS_LINE
: return "MIPS_LINE";
5964 case SHT_MIPS_RFDESC
: return "MIPS_RFDESC";
5965 case SHT_MIPS_DELTASYM
: return "MIPS_DELTASYM";
5966 case SHT_MIPS_DELTAINST
: return "MIPS_DELTAINST";
5967 case SHT_MIPS_DELTACLASS
: return "MIPS_DELTACLASS";
5968 case SHT_MIPS_DWARF
: return "MIPS_DWARF";
5969 case SHT_MIPS_DELTADECL
: return "MIPS_DELTADECL";
5970 case SHT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
5971 case SHT_MIPS_EVENTS
: return "MIPS_EVENTS";
5972 case SHT_MIPS_TRANSLATE
: return "MIPS_TRANSLATE";
5973 case SHT_MIPS_PIXIE
: return "MIPS_PIXIE";
5974 case SHT_MIPS_XLATE
: return "MIPS_XLATE";
5975 case SHT_MIPS_XLATE_DEBUG
: return "MIPS_XLATE_DEBUG";
5976 case SHT_MIPS_WHIRL
: return "MIPS_WHIRL";
5977 case SHT_MIPS_EH_REGION
: return "MIPS_EH_REGION";
5978 case SHT_MIPS_XLATE_OLD
: return "MIPS_XLATE_OLD";
5979 case SHT_MIPS_PDR_EXCEPTION
: return "MIPS_PDR_EXCEPTION";
5980 case SHT_MIPS_ABIFLAGS
: return "MIPS_ABIFLAGS";
5981 case SHT_MIPS_XHASH
: return "MIPS_XHASH";
5989 get_parisc_section_type_name (unsigned int sh_type
)
5993 case SHT_PARISC_EXT
: return "PARISC_EXT";
5994 case SHT_PARISC_UNWIND
: return "PARISC_UNWIND";
5995 case SHT_PARISC_DOC
: return "PARISC_DOC";
5996 case SHT_PARISC_ANNOT
: return "PARISC_ANNOT";
5997 case SHT_PARISC_DLKM
: return "PARISC_DLKM";
5998 case SHT_PARISC_SYMEXTN
: return "PARISC_SYMEXTN";
5999 case SHT_PARISC_STUBS
: return "PARISC_STUBS";
6000 default: return NULL
;
6005 get_ia64_section_type_name (Filedata
* filedata
, unsigned int sh_type
)
6007 /* If the top 8 bits are 0x78 the next 8 are the os/abi ID. */
6008 if ((sh_type
& 0xFF000000) == SHT_IA_64_LOPSREG
)
6009 return get_osabi_name (filedata
, (sh_type
& 0x00FF0000) >> 16);
6013 case SHT_IA_64_EXT
: return "IA_64_EXT";
6014 case SHT_IA_64_UNWIND
: return "IA_64_UNWIND";
6015 case SHT_IA_64_PRIORITY_INIT
: return "IA_64_PRIORITY_INIT";
6023 get_vms_section_type_name (unsigned int sh_type
)
6027 case SHT_IA_64_VMS_TRACE
: return "VMS_TRACE";
6028 case SHT_IA_64_VMS_TIE_SIGNATURES
: return "VMS_TIE_SIGNATURES";
6029 case SHT_IA_64_VMS_DEBUG
: return "VMS_DEBUG";
6030 case SHT_IA_64_VMS_DEBUG_STR
: return "VMS_DEBUG_STR";
6031 case SHT_IA_64_VMS_LINKAGES
: return "VMS_LINKAGES";
6032 case SHT_IA_64_VMS_SYMBOL_VECTOR
: return "VMS_SYMBOL_VECTOR";
6033 case SHT_IA_64_VMS_FIXUP
: return "VMS_FIXUP";
6041 get_x86_64_section_type_name (unsigned int sh_type
)
6045 case SHT_X86_64_UNWIND
: return "X86_64_UNWIND";
6046 default: return NULL
;
6051 get_aarch64_section_type_name (unsigned int sh_type
)
6055 case SHT_AARCH64_ATTRIBUTES
:
6056 return "AARCH64_ATTRIBUTES";
6057 case SHT_AARCH64_AUTH_RELR
:
6058 return "AARCH64_AUTH_RELR";
6059 case SHT_AARCH64_MEMTAG_GLOBALS_STATIC
:
6060 return "AARCH64_MEMTAG_GLOBALS_STATIC";
6061 case SHT_AARCH64_MEMTAG_GLOBALS_DYNAMIC
:
6062 return "AARCH64_MEMTAG_GLOBALS_DYNAMIC";
6069 get_arm_section_type_name (unsigned int sh_type
)
6073 case SHT_ARM_EXIDX
: return "ARM_EXIDX";
6074 case SHT_ARM_PREEMPTMAP
: return "ARM_PREEMPTMAP";
6075 case SHT_ARM_ATTRIBUTES
: return "ARM_ATTRIBUTES";
6076 case SHT_ARM_DEBUGOVERLAY
: return "ARM_DEBUGOVERLAY";
6077 case SHT_ARM_OVERLAYSECTION
: return "ARM_OVERLAYSECTION";
6078 default: return NULL
;
6083 get_tic6x_section_type_name (unsigned int sh_type
)
6087 case SHT_C6000_UNWIND
: return "C6000_UNWIND";
6088 case SHT_C6000_PREEMPTMAP
: return "C6000_PREEMPTMAP";
6089 case SHT_C6000_ATTRIBUTES
: return "C6000_ATTRIBUTES";
6090 case SHT_TI_ICODE
: return "TI_ICODE";
6091 case SHT_TI_XREF
: return "TI_XREF";
6092 case SHT_TI_HANDLER
: return "TI_HANDLER";
6093 case SHT_TI_INITINFO
: return "TI_INITINFO";
6094 case SHT_TI_PHATTRS
: return "TI_PHATTRS";
6095 default: return NULL
;
6100 get_msp430_section_type_name (unsigned int sh_type
)
6104 case SHT_MSP430_SEC_FLAGS
: return "MSP430_SEC_FLAGS";
6105 case SHT_MSP430_SYM_ALIASES
: return "MSP430_SYM_ALIASES";
6106 case SHT_MSP430_ATTRIBUTES
: return "MSP430_ATTRIBUTES";
6107 default: return NULL
;
6112 get_nfp_section_type_name (unsigned int sh_type
)
6116 case SHT_NFP_MECONFIG
: return "NFP_MECONFIG";
6117 case SHT_NFP_INITREG
: return "NFP_INITREG";
6118 case SHT_NFP_UDEBUG
: return "NFP_UDEBUG";
6119 default: return NULL
;
6124 get_v850_section_type_name (unsigned int sh_type
)
6128 case SHT_V850_SCOMMON
: return "V850 Small Common";
6129 case SHT_V850_TCOMMON
: return "V850 Tiny Common";
6130 case SHT_V850_ZCOMMON
: return "V850 Zero Common";
6131 case SHT_RENESAS_IOP
: return "RENESAS IOP";
6132 case SHT_RENESAS_INFO
: return "RENESAS INFO";
6133 default: return NULL
;
6138 get_riscv_section_type_name (unsigned int sh_type
)
6142 case SHT_RISCV_ATTRIBUTES
: return "RISCV_ATTRIBUTES";
6143 default: return NULL
;
6148 get_csky_section_type_name (unsigned int sh_type
)
6152 case SHT_CSKY_ATTRIBUTES
: return "CSKY_ATTRIBUTES";
6153 default: return NULL
;
6158 get_powerpc_section_type_name (unsigned int sh_type
)
6162 case SHT_ORDERED
: return "ORDERED";
6163 default: return NULL
;
6168 get_alpha_section_type_name (unsigned int sh_type
)
6172 case SHT_ALPHA_DEBUG
: return "DEBUG";
6173 case SHT_ALPHA_REGINFO
: return "REGINFO";
6174 default: return NULL
;
6179 get_processor_specific_section_type_name (Filedata
* filedata
, unsigned int sh_type
)
6181 static char buff
[32];
6182 const char * result
= NULL
;
6184 switch (filedata
->file_header
.e_machine
)
6187 result
= get_aarch64_section_type_name (sh_type
);
6191 result
= get_alpha_section_type_name (sh_type
);
6195 case EM_ARC_COMPACT
:
6196 case EM_ARC_COMPACT2
:
6197 case EM_ARC_COMPACT3
:
6198 case EM_ARC_COMPACT3_64
:
6199 result
= get_arc_section_type_name (sh_type
);
6203 result
= get_arm_section_type_name (sh_type
);
6207 result
= get_csky_section_type_name (sh_type
);
6211 result
= get_ia64_section_type_name (filedata
, sh_type
);
6215 case EM_MIPS_RS3_LE
:
6216 result
= get_mips_section_type_name (sh_type
);
6220 result
= get_msp430_section_type_name (sh_type
);
6224 result
= get_nfp_section_type_name (sh_type
);
6228 result
= get_parisc_section_type_name (sh_type
);
6233 return get_powerpc_section_type_name (sh_type
);
6237 result
= get_riscv_section_type_name (sh_type
);
6241 result
= get_tic6x_section_type_name (sh_type
);
6246 case EM_CYGNUS_V850
:
6247 result
= get_v850_section_type_name (sh_type
);
6253 result
= get_x86_64_section_type_name (sh_type
);
6265 /* FIXME: Are these correct ? If so, why do they not have #define's ? */
6266 case 0x7ffffffd: return "AUXILIARY";
6267 case 0x7fffffff: return "FILTER";
6272 sprintf (buff
, "LOPROC+%#x", sh_type
- SHT_LOPROC
);
6277 get_os_specific_section_type_name (Filedata
* filedata
, unsigned int sh_type
)
6279 static char buff
[32];
6280 const char * result
= NULL
;
6282 switch (filedata
->file_header
.e_machine
)
6285 result
= get_vms_section_type_name (sh_type
);
6294 if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_SOLARIS
)
6295 result
= get_solaris_section_type (sh_type
);
6302 case SHT_GNU_INCREMENTAL_INPUTS
: return "GNU_INCREMENTAL_INPUTS";
6303 case SHT_GNU_ATTRIBUTES
: return "GNU_ATTRIBUTES";
6304 case SHT_GNU_HASH
: return "GNU_HASH";
6305 case SHT_GNU_LIBLIST
: return "GNU_LIBLIST";
6306 case SHT_GNU_OBJECT_ONLY
: return "GNU_OBJECT_ONLY";
6307 case SHT_GNU_SFRAME
: return "GNU_SFRAME";
6309 case SHT_SUNW_move
: return "SUNW_MOVE";
6310 case SHT_SUNW_COMDAT
: return "SUNW_COMDAT";
6311 case SHT_SUNW_syminfo
: return "SUNW_SYMINFO";
6312 case SHT_GNU_verdef
: return "VERDEF";
6313 case SHT_GNU_verneed
: return "VERNEED";
6314 case SHT_GNU_versym
: return "VERSYM";
6316 case SHT_LLVM_ODRTAB
: return "LLVM_ODRTAB";
6317 case SHT_LLVM_LINKER_OPTIONS
: return "LLVM_LINKER_OPTIONS";
6318 case SHT_LLVM_ADDRSIG
: return "LLVM_ADDRSIG";
6319 case SHT_LLVM_DEPENDENT_LIBRARIES
: return "LLVM_DEPENDENT_LIBRARIES";
6320 case SHT_LLVM_SYMPART
: return "LLVM_SYMPART";
6321 case SHT_LLVM_PART_EHDR
: return "LLVM_PART_EHDR";
6322 case SHT_LLVM_PART_PHDR
: return "LLVM_PART_PHDR";
6323 case SHT_LLVM_BB_ADDR_MAP_V0
: return "LLVM_BB_ADDR_MAP_V0";
6324 case SHT_LLVM_CALL_GRAPH_PROFILE
: return "LLVM_CALL_GRAPH_PROFILE";
6325 case SHT_LLVM_BB_ADDR_MAP
: return "LLVM_BB_ADDR_MAP";
6326 case SHT_LLVM_OFFLOADING
: return "LLVM_OFFLOADING";
6327 case SHT_LLVM_LTO
: return "LLVM_LTO";
6329 case SHT_ANDROID_REL
: return "ANDROID_REL";
6330 case SHT_ANDROID_RELA
: return "ANDROID_RELA";
6331 case SHT_ANDROID_RELR
: return "ANDROID_RELR";
6333 case SHT_CHECKSUM
: return "CHECKSUM";
6335 /* FIXME: Are these correct ? If so, why do they not have #define's ? */
6336 case 0x6ffffff0: return "VERSYM";
6342 sprintf (buff
, "LOOS+%#x", sh_type
- SHT_LOOS
);
6347 get_user_specific_section_type_name (Filedata
* filedata
, unsigned int sh_type
)
6349 static char buff
[32];
6350 const char * result
;
6352 switch (filedata
->file_header
.e_machine
)
6356 case EM_CYGNUS_V850
:
6357 result
= get_v850_section_type_name (sh_type
);
6368 sprintf (buff
, "LOUSER+%#x", sh_type
- SHT_LOUSER
);
6373 get_section_type_name (Filedata
* filedata
,
6374 unsigned int sh_type
)
6378 case SHT_NULL
: return "NULL";
6379 case SHT_PROGBITS
: return "PROGBITS";
6380 case SHT_SYMTAB
: return "SYMTAB";
6381 case SHT_STRTAB
: return "STRTAB";
6382 case SHT_RELA
: return "RELA";
6383 case SHT_HASH
: return "HASH";
6384 case SHT_DYNAMIC
: return "DYNAMIC";
6385 case SHT_NOTE
: return "NOTE";
6386 case SHT_NOBITS
: return "NOBITS";
6387 case SHT_REL
: return "REL";
6388 case SHT_SHLIB
: return "SHLIB";
6389 case SHT_DYNSYM
: return "DYNSYM";
6390 /* 12 and 13 are not defined. */
6391 case SHT_INIT_ARRAY
: return "INIT_ARRAY";
6392 case SHT_FINI_ARRAY
: return "FINI_ARRAY";
6393 case SHT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
6394 case SHT_GROUP
: return "GROUP";
6395 case SHT_SYMTAB_SHNDX
: return "SYMTAB SECTION INDICES";
6396 case SHT_RELR
: return "RELR";
6397 /* End of generic section types. */
6403 if ((sh_type
>= SHT_LOPROC
) && (sh_type
<= SHT_HIPROC
))
6404 return get_processor_specific_section_type_name (filedata
, sh_type
);
6406 if ((sh_type
>= SHT_LOOS
) && (sh_type
<= SHT_HIOS
))
6407 return get_os_specific_section_type_name (filedata
, sh_type
);
6409 if ((sh_type
>= SHT_LOUSER
) && (sh_type
<= SHT_HIUSER
))
6410 return get_user_specific_section_type_name (filedata
, sh_type
);
6412 static char buff
[32];
6414 /* This message is probably going to be displayed in a 15
6415 character wide field, so put the hex value first. */
6416 snprintf (buff
, sizeof (buff
), _("%08x: <unknown>"), sh_type
);
6420 enum long_option_values
6422 OPTION_DEBUG_DUMP
= 512,
6433 OPTION_WITH_SYMBOL_VERSIONS
,
6434 OPTION_RECURSE_LIMIT
,
6435 OPTION_NO_RECURSE_LIMIT
,
6436 OPTION_NO_DEMANGLING
,
6437 OPTION_NO_EXTRA_SYM_INFO
,
6442 static struct option options
[] =
6444 /* Note - This table is alpha-sorted on the 'val'
6445 field in order to make adding new options easier. */
6446 {"arch-specific", no_argument
, 0, 'A'},
6447 {"all", no_argument
, 0, 'a'},
6448 {"demangle", optional_argument
, 0, 'C'},
6449 {"archive-index", no_argument
, 0, 'c'},
6450 {"use-dynamic", no_argument
, 0, 'D'},
6451 {"dynamic", no_argument
, 0, 'd'},
6452 {"headers", no_argument
, 0, 'e'},
6453 {"section-groups", no_argument
, 0, 'g'},
6454 {"help", no_argument
, 0, 'H'},
6455 {"file-header", no_argument
, 0, 'h'},
6456 {"histogram", no_argument
, 0, 'I'},
6457 {"display-section", required_argument
, 0, 'j'},
6458 {"lint", no_argument
, 0, 'L'},
6459 {"enable-checks", no_argument
, 0, 'L'},
6460 {"program-headers", no_argument
, 0, 'l'},
6461 {"segments", no_argument
, 0, 'l'},
6462 {"full-section-name",no_argument
, 0, 'N'},
6463 {"notes", no_argument
, 0, 'n'},
6464 {"process-links", no_argument
, 0, 'P'},
6465 {"string-dump", required_argument
, 0, 'p'},
6466 {"relocated-dump", required_argument
, 0, 'R'},
6467 {"relocs", no_argument
, 0, 'r'},
6468 {"section-headers", no_argument
, 0, 'S'},
6469 {"sections", no_argument
, 0, 'S'},
6470 {"symbols", no_argument
, 0, 's'},
6471 {"syms", no_argument
, 0, 's'},
6472 {"silent-truncation",no_argument
, 0, 'T'},
6473 {"section-details", no_argument
, 0, 't'},
6474 {"unicode", required_argument
, NULL
, 'U'},
6475 {"unwind", no_argument
, 0, 'u'},
6476 {"version-info", no_argument
, 0, 'V'},
6477 {"version", no_argument
, 0, 'v'},
6478 {"wide", no_argument
, 0, 'W'},
6479 {"extra-sym-info", no_argument
, 0, 'X'},
6480 {"hex-dump", required_argument
, 0, 'x'},
6481 {"decompress", no_argument
, 0, 'z'},
6483 {"no-demangle", no_argument
, 0, OPTION_NO_DEMANGLING
},
6484 {"no-extra-sym-info",no_argument
, 0, OPTION_NO_EXTRA_SYM_INFO
},
6485 {"recurse-limit", no_argument
, NULL
, OPTION_RECURSE_LIMIT
},
6486 {"no-recurse-limit", no_argument
, NULL
, OPTION_NO_RECURSE_LIMIT
},
6487 {"no-recursion-limit", no_argument
, NULL
, OPTION_NO_RECURSE_LIMIT
},
6488 {"dyn-syms", no_argument
, 0, OPTION_DYN_SYMS
},
6489 {"lto-syms", no_argument
, 0, OPTION_LTO_SYMS
},
6490 {"debug-dump", optional_argument
, 0, OPTION_DEBUG_DUMP
},
6491 {"dwarf-depth", required_argument
, 0, OPTION_DWARF_DEPTH
},
6492 {"dwarf-start", required_argument
, 0, OPTION_DWARF_START
},
6493 {"dwarf-check", no_argument
, 0, OPTION_DWARF_CHECK
},
6494 #ifdef ENABLE_LIBCTF
6495 {"ctf", required_argument
, 0, OPTION_CTF_DUMP
},
6496 {"ctf-symbols", required_argument
, 0, OPTION_CTF_SYMBOLS
},
6497 {"ctf-strings", required_argument
, 0, OPTION_CTF_STRINGS
},
6498 {"ctf-parent", required_argument
, 0, OPTION_CTF_PARENT
},
6500 {"sframe", optional_argument
, 0, OPTION_SFRAME_DUMP
},
6501 {"sym-base", optional_argument
, 0, OPTION_SYM_BASE
},
6502 {"got-contents", no_argument
, 0, OPTION_GOT_CONTENTS
},
6504 {0, no_argument
, 0, 0}
6508 usage (FILE * stream
)
6510 fprintf (stream
, _("Usage: readelf <option(s)> elf-file(s)\n"));
6511 fprintf (stream
, _(" Display information about the contents of ELF format files\n"));
6512 fprintf (stream
, _(" Options are:\n"));
6513 fprintf (stream
, _("\
6514 -a --all Equivalent to: -h -l -S -s -r -d -V -A -I --got-contents\n"));
6515 fprintf (stream
, _("\
6516 -h --file-header Display the ELF file header\n"));
6517 fprintf (stream
, _("\
6518 -l --program-headers Display the program headers\n"));
6519 fprintf (stream
, _("\
6520 --segments An alias for --program-headers\n"));
6521 fprintf (stream
, _("\
6522 -S --section-headers Display the sections' header\n"));
6523 fprintf (stream
, _("\
6524 --sections An alias for --section-headers\n"));
6525 fprintf (stream
, _("\
6526 -g --section-groups Display the section groups\n"));
6527 fprintf (stream
, _("\
6528 -t --section-details Display the section details\n"));
6529 fprintf (stream
, _("\
6530 -e --headers Equivalent to: -h -l -S\n"));
6531 fprintf (stream
, _("\
6532 -s --syms Display the symbol table\n"));
6533 fprintf (stream
, _("\
6534 --symbols An alias for --syms\n"));
6535 fprintf (stream
, _("\
6536 --dyn-syms Display the dynamic symbol table\n"));
6537 fprintf (stream
, _("\
6538 --lto-syms Display LTO symbol tables\n"));
6539 fprintf (stream
, _("\
6540 --sym-base=[0|8|10|16] \n\
6541 Force base for symbol sizes. The options are \n\
6542 mixed (the default), octal, decimal, hexadecimal.\n"));
6543 fprintf (stream
, _("\
6544 -C --demangle[=STYLE] Decode mangled/processed symbol names\n"));
6545 display_demangler_styles (stream
, _("\
6547 fprintf (stream
, _("\
6548 --no-demangle Do not demangle low-level symbol names. (default)\n"));
6549 fprintf (stream
, _("\
6550 --recurse-limit Enable a demangling recursion limit. (default)\n"));
6551 fprintf (stream
, _("\
6552 --no-recurse-limit Disable a demangling recursion limit\n"));
6553 fprintf (stream
, _("\
6554 -U[dlexhi] --unicode=[default|locale|escape|hex|highlight|invalid]\n\
6555 Display unicode characters as determined by the current locale\n\
6556 (default), escape sequences, \"<hex sequences>\", highlighted\n\
6557 escape sequences, or treat them as invalid and display as\n\
6558 \"{hex sequences}\"\n"));
6559 fprintf (stream
, _("\
6560 -X --extra-sym-info Display extra information when showing symbols\n"));
6561 fprintf (stream
, _("\
6562 --no-extra-sym-info Do not display extra information when showing symbols (default)\n"));
6563 fprintf (stream
, _("\
6564 -n --notes Display the contents of note sections (if present)\n"));
6565 fprintf (stream
, _("\
6566 -r --relocs Display the relocations (if present)\n"));
6567 fprintf (stream
, _("\
6568 -u --unwind Display the unwind info (if present)\n"));
6569 fprintf (stream
, _("\
6570 -d --dynamic Display the dynamic section (if present)\n"));
6571 fprintf (stream
, _("\
6572 -V --version-info Display the version sections (if present)\n"));
6573 fprintf (stream
, _("\
6574 -A --arch-specific Display architecture specific information (if any)\n"));
6575 fprintf (stream
, _("\
6576 -c --archive-index Display the symbol/file index in an archive\n"));
6577 fprintf (stream
, _("\
6578 -D --use-dynamic Use the dynamic section info when displaying symbols\n"));
6579 fprintf (stream
, _("\
6580 -L --lint|--enable-checks\n\
6581 Display warning messages for possible problems\n"));
6582 fprintf (stream
, _("\
6583 -x --hex-dump=<number|name>\n\
6584 Dump the contents of section <number|name> as bytes\n"));
6585 fprintf (stream
, _("\
6586 -p --string-dump=<number|name>\n\
6587 Dump the contents of section <number|name> as strings\n"));
6588 fprintf (stream
, _("\
6589 -R --relocated-dump=<number|name>\n\
6590 Dump the relocated contents of section <number|name>\n"));
6591 fprintf (stream
, _("\
6592 -z --decompress Decompress section before dumping it\n"));
6593 fprintf (stream
, _("\n\
6594 -j --display-section=<name|number>\n\
6595 Display the contents of the indicated section. Can be repeated\n"));
6596 fprintf (stream
, _("\
6597 -w --debug-dump[a/=abbrev, A/=addr, r/=aranges, c/=cu_index, L/=decodedline,\n\
6598 f/=frames, F/=frames-interp, g/=gdb_index, i/=info, o/=loc,\n\
6599 m/=macro, p/=pubnames, t/=pubtypes, R/=Ranges, l/=rawline,\n\
6600 s/=str, O/=str-offsets, u/=trace_abbrev, T/=trace_aranges,\n\
6602 Display the contents of DWARF debug sections\n"));
6603 fprintf (stream
, _("\
6604 -wk --debug-dump=links Display the contents of sections that link to separate\n\
6605 debuginfo files\n"));
6606 fprintf (stream
, _("\
6607 -P --process-links Display the contents of non-debug sections in separate\n\
6608 debuginfo files. (Implies -wK)\n"));
6609 #if DEFAULT_FOR_FOLLOW_LINKS
6610 fprintf (stream
, _("\
6611 -wK --debug-dump=follow-links\n\
6612 Follow links to separate debug info files (default)\n"));
6613 fprintf (stream
, _("\
6614 -wN --debug-dump=no-follow-links\n\
6615 Do not follow links to separate debug info files\n"));
6617 fprintf (stream
, _("\
6618 -wK --debug-dump=follow-links\n\
6619 Follow links to separate debug info files\n"));
6620 fprintf (stream
, _("\
6621 -wN --debug-dump=no-follow-links\n\
6622 Do not follow links to separate debug info files\n\
6625 #if HAVE_LIBDEBUGINFOD
6626 fprintf (stream
, _("\
6627 -wD --debug-dump=use-debuginfod\n\
6628 When following links, also query debuginfod servers (default)\n"));
6629 fprintf (stream
, _("\
6630 -wE --debug-dump=do-not-use-debuginfod\n\
6631 When following links, do not query debuginfod servers\n"));
6633 fprintf (stream
, _("\
6634 --dwarf-depth=N Do not display DIEs at depth N or greater\n"));
6635 fprintf (stream
, _("\
6636 --dwarf-start=N Display DIEs starting at offset N\n"));
6637 #ifdef ENABLE_LIBCTF
6638 fprintf (stream
, _("\
6639 --ctf=<number|name> Display CTF info from section <number|name>\n"));
6640 fprintf (stream
, _("\
6641 --ctf-parent=<name> Use CTF archive member <name> as the CTF parent\n"));
6642 fprintf (stream
, _("\
6643 --ctf-symbols=<number|name>\n\
6644 Use section <number|name> as the CTF external symtab\n"));
6645 fprintf (stream
, _("\
6646 --ctf-strings=<number|name>\n\
6647 Use section <number|name> as the CTF external strtab\n"));
6649 fprintf (stream
, _("\
6650 --sframe[=NAME] Display SFrame info from section NAME, (default '.sframe')\n"));
6652 #ifdef SUPPORT_DISASSEMBLY
6653 fprintf (stream
, _("\
6654 -i --instruction-dump=<number|name>\n\
6655 Disassemble the contents of section <number|name>\n"));
6657 fprintf (stream
, _("\
6658 -I --histogram Display histogram of bucket list lengths\n"));
6659 fprintf (stream
, _("\
6660 --got-contents Display GOT section contents\n"));
6661 fprintf (stream
, _("\
6662 -W --wide Allow output width to exceed 80 characters\n"));
6663 fprintf (stream
, _("\
6664 -T --silent-truncation If a symbol name is truncated, do not add [...] suffix\n"));
6665 fprintf (stream
, _("\
6666 @<file> Read options from <file>\n"));
6667 fprintf (stream
, _("\
6668 -H --help Display this information\n"));
6669 fprintf (stream
, _("\
6670 -v --version Display the version number of readelf\n"));
6672 if (REPORT_BUGS_TO
[0] && stream
== stdout
)
6673 fprintf (stdout
, _("Report bugs to %s\n"), REPORT_BUGS_TO
);
6675 exit (stream
== stdout
? 0 : 1);
6678 /* Record the fact that the user wants the contents of section number
6679 SECTION to be displayed using the method(s) encoded as flags bits
6680 in TYPE. Note, TYPE can be zero if we are creating the array for
6684 request_dump_bynumber (struct dump_data
*dumpdata
,
6685 unsigned int section
, dump_type type
)
6687 if (section
>= dumpdata
->num_dump_sects
)
6689 dump_type
* new_dump_sects
;
6691 new_dump_sects
= (dump_type
*) calloc (section
+ 1,
6692 sizeof (* new_dump_sects
));
6694 if (new_dump_sects
== NULL
)
6695 error (_("Out of memory allocating dump request table.\n"));
6698 if (dumpdata
->dump_sects
)
6700 /* Copy current flag settings. */
6701 memcpy (new_dump_sects
, dumpdata
->dump_sects
,
6702 dumpdata
->num_dump_sects
* sizeof (* new_dump_sects
));
6704 free (dumpdata
->dump_sects
);
6707 dumpdata
->dump_sects
= new_dump_sects
;
6708 dumpdata
->num_dump_sects
= section
+ 1;
6712 if (dumpdata
->dump_sects
)
6713 dumpdata
->dump_sects
[section
] |= type
;
6716 /* Request a dump by section name. */
6719 request_dump_byname (const char * section
, dump_type type
)
6721 struct dump_list_entry
* new_request
;
6723 new_request
= (struct dump_list_entry
*)
6724 malloc (sizeof (struct dump_list_entry
));
6726 error (_("Out of memory allocating dump request table.\n"));
6728 new_request
->name
= strdup (section
);
6729 if (!new_request
->name
)
6730 error (_("Out of memory allocating dump request table.\n"));
6732 new_request
->type
= type
;
6734 new_request
->next
= dump_sects_byname
;
6735 dump_sects_byname
= new_request
;
6739 request_dump (struct dump_data
*dumpdata
, dump_type type
)
6745 section
= strtoul (optarg
, & cp
, 0);
6747 if (! *cp
&& section
>= 0)
6748 request_dump_bynumber (dumpdata
, section
, type
);
6750 request_dump_byname (optarg
, type
);
6754 parse_args (struct dump_data
*dumpdata
, int argc
, char ** argv
)
6761 while ((c
= getopt_long
6762 (argc
, argv
, "ACDHILNPR:STU:VWXacdeghi:j:lnp:rstuvw::x:z", options
, NULL
)) != EOF
)
6780 do_section_groups
= true;
6783 do_histogram
= true;
6786 do_got_section_contents
= true;
6790 do_section_groups
= true;
6795 do_section_details
= true;
6806 do_using_dynamic
= true;
6830 do_histogram
= true;
6836 do_archive_index
= true;
6842 process_links
= true;
6843 do_follow_links
= true;
6844 dump_any_debugging
= true;
6847 request_dump (dumpdata
, AUTO_DUMP
);
6850 request_dump (dumpdata
, HEX_DUMP
);
6853 request_dump (dumpdata
, STRING_DUMP
);
6856 request_dump (dumpdata
, RELOC_DUMP
);
6859 decompress_dumps
= true;
6864 do_debugging
= true;
6866 dump_any_debugging
= true;
6867 dwarf_select_sections_all ();
6871 do_debugging
= false;
6872 if (dwarf_select_sections_by_letters (optarg
))
6875 dump_any_debugging
= true;
6879 case OPTION_DEBUG_DUMP
:
6883 do_debugging
= true;
6884 dump_any_debugging
= true;
6885 dwarf_select_sections_all ();
6887 else if (strcmp (optarg
, "sframe-internal-only") == 0)
6888 warn (_("Unrecognized debug option 'sframe-internal-only'\n"));
6891 do_debugging
= false;
6892 if (dwarf_select_sections_by_names (optarg
))
6895 dump_any_debugging
= true;
6899 case OPTION_DWARF_DEPTH
:
6903 dwarf_cutoff_level
= strtoul (optarg
, & cp
, 0);
6906 case OPTION_DWARF_START
:
6910 dwarf_start_die
= strtoul (optarg
, & cp
, 0);
6913 case OPTION_DWARF_CHECK
:
6916 case OPTION_CTF_DUMP
:
6918 request_dump (dumpdata
, CTF_DUMP
);
6920 case OPTION_CTF_SYMBOLS
:
6921 free (dump_ctf_symtab_name
);
6922 dump_ctf_symtab_name
= strdup (optarg
);
6924 case OPTION_CTF_STRINGS
:
6925 free (dump_ctf_strtab_name
);
6926 dump_ctf_strtab_name
= strdup (optarg
);
6928 case OPTION_CTF_PARENT
:
6929 free (dump_ctf_parent_name
);
6930 dump_ctf_parent_name
= strdup (optarg
);
6932 case OPTION_SFRAME_DUMP
:
6934 /* Fix PR/32589 but keep the error messaging same ? */
6935 if (optarg
!= NULL
&& strcmp (optarg
, "") == 0)
6938 error (_("Section name must be provided\n"));
6940 /* Providing section name is optional. request_dump (), however,
6941 thrives on non NULL optarg. Handle it explicitly here. */
6942 else if (optarg
!= NULL
)
6943 request_dump (dumpdata
, SFRAME_DUMP
);
6947 const char *sframe_sec_name
= strdup (".sframe");
6948 request_dump_byname (sframe_sec_name
, SFRAME_DUMP
);
6951 case OPTION_DYN_SYMS
:
6954 case OPTION_LTO_SYMS
:
6958 extra_sym_info
= true;
6960 case OPTION_NO_EXTRA_SYM_INFO
:
6961 extra_sym_info
= false;
6964 #ifdef SUPPORT_DISASSEMBLY
6966 request_dump (dumpdata
, DISASS_DUMP
);
6970 print_version (program_name
);
6979 do_not_show_symbol_truncation
= true;
6985 enum demangling_styles style
;
6987 style
= cplus_demangle_name_to_style (optarg
);
6988 if (style
== unknown_demangling
)
6989 error (_("unknown demangling style `%s'"), optarg
);
6991 cplus_demangle_set_style (style
);
6994 case OPTION_NO_DEMANGLING
:
6995 do_demangle
= false;
6997 case OPTION_RECURSE_LIMIT
:
6998 demangle_flags
&= ~ DMGL_NO_RECURSE_LIMIT
;
7000 case OPTION_NO_RECURSE_LIMIT
:
7001 demangle_flags
|= DMGL_NO_RECURSE_LIMIT
;
7003 case OPTION_WITH_SYMBOL_VERSIONS
:
7004 /* Ignored for backward compatibility. */
7009 error (_("Missing arg to -U/--unicode")); /* Can this happen ? */
7010 else if (streq (optarg
, "default") || streq (optarg
, "d"))
7011 unicode_display
= unicode_default
;
7012 else if (streq (optarg
, "locale") || streq (optarg
, "l"))
7013 unicode_display
= unicode_locale
;
7014 else if (streq (optarg
, "escape") || streq (optarg
, "e"))
7015 unicode_display
= unicode_escape
;
7016 else if (streq (optarg
, "invalid") || streq (optarg
, "i"))
7017 unicode_display
= unicode_invalid
;
7018 else if (streq (optarg
, "hex") || streq (optarg
, "x"))
7019 unicode_display
= unicode_hex
;
7020 else if (streq (optarg
, "highlight") || streq (optarg
, "h"))
7021 unicode_display
= unicode_highlight
;
7023 error (_("invalid argument to -U/--unicode: %s"), optarg
);
7026 case OPTION_SYM_BASE
:
7030 sym_base
= strtoul (optarg
, NULL
, 0);
7046 case OPTION_GOT_CONTENTS
:
7047 do_got_section_contents
= true;
7052 /* xgettext:c-format */
7053 error (_("Invalid option '-%c'\n"), c
);
7060 if (!do_dynamic
&& !do_syms
&& !do_reloc
&& !do_unwind
&& !do_sections
7061 && !do_segments
&& !do_header
&& !do_dump
&& !do_version
7062 && !do_histogram
&& !do_debugging
&& !do_arch
&& !do_notes
7063 && !do_section_groups
&& !do_archive_index
7064 && !do_dyn_syms
&& !do_lto_syms
)
7069 do_dynamic
= do_syms
= do_reloc
= do_unwind
= do_sections
= true;
7070 do_segments
= do_header
= do_dump
= do_version
= true;
7071 do_histogram
= do_debugging
= do_arch
= do_notes
= true;
7072 do_section_groups
= do_archive_index
= do_dyn_syms
= true;
7081 get_elf_class (unsigned int elf_class
)
7083 static char buff
[32];
7087 case ELFCLASSNONE
: return _("none");
7088 case ELFCLASS32
: return "ELF32";
7089 case ELFCLASS64
: return "ELF64";
7091 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), elf_class
);
7097 get_data_encoding (unsigned int encoding
)
7099 static char buff
[32];
7103 case ELFDATANONE
: return _("none");
7104 case ELFDATA2LSB
: return _("2's complement, little endian");
7105 case ELFDATA2MSB
: return _("2's complement, big endian");
7107 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), encoding
);
7113 check_magic_number (Filedata
* filedata
, Elf_Internal_Ehdr
* header
)
7115 if (header
->e_ident
[EI_MAG0
] == ELFMAG0
7116 && header
->e_ident
[EI_MAG1
] == ELFMAG1
7117 && header
->e_ident
[EI_MAG2
] == ELFMAG2
7118 && header
->e_ident
[EI_MAG3
] == ELFMAG3
)
7121 /* Some compilers produce object files that are not in the ELF file format.
7122 As an aid to users of readelf, try to identify these cases and suggest
7125 FIXME: It is not clear if all four bytes are used as constant magic
7126 valus by all compilers. It may be necessary to recode this function if
7127 different tools use different length sequences. */
7131 unsigned char magic
[4];
7132 const char * obj_message
;
7133 const char * ar_message
;
7137 { { 'B', 'C', 0xc0, 0xde },
7138 N_("This is a LLVM bitcode file - try using llvm-bcanalyzer\n"),
7139 N_("This is a LLVM bitcode file - try extracting and then using llvm-bcanalyzer\n")
7141 { { 'g', 'o', ' ', 'o' },
7142 N_("This is a GO binary file - try using 'go tool objdump' or 'go tool nm'\n"),
7148 for (i
= ARRAY_SIZE (known_magic
); i
--;)
7150 if (header
->e_ident
[EI_MAG0
] == known_magic
[i
].magic
[0]
7151 && header
->e_ident
[EI_MAG1
] == known_magic
[i
].magic
[1]
7152 && header
->e_ident
[EI_MAG2
] == known_magic
[i
].magic
[2]
7153 && header
->e_ident
[EI_MAG3
] == known_magic
[i
].magic
[3])
7155 /* Some compiler's analyzer tools do not handle archives,
7156 so we provide two different kinds of error message. */
7157 if (filedata
->archive_file_size
> 0
7158 && known_magic
[i
].ar_message
!= NULL
)
7159 error ("%s", known_magic
[i
].ar_message
);
7161 error ("%s", known_magic
[i
].obj_message
);
7166 error (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
7170 /* Decode the data held in 'filedata->file_header'. */
7173 process_file_header (Filedata
* filedata
)
7175 Elf_Internal_Ehdr
* header
= & filedata
->file_header
;
7177 if (! check_magic_number (filedata
, header
))
7180 if (! filedata
->is_separate
)
7181 init_dwarf_by_elf_machine_code (header
->e_machine
);
7187 if (filedata
->is_separate
)
7188 printf (_("ELF Header in linked file '%s':\n"),
7189 printable_string (filedata
->file_name
, 0));
7191 printf (_("ELF Header:\n"));
7192 printf (_(" Magic: "));
7193 for (i
= 0; i
< EI_NIDENT
; i
++)
7194 printf ("%2.2x ", header
->e_ident
[i
]);
7196 printf (_(" Class: %s\n"),
7197 get_elf_class (header
->e_ident
[EI_CLASS
]));
7198 printf (_(" Data: %s\n"),
7199 get_data_encoding (header
->e_ident
[EI_DATA
]));
7200 printf (_(" Version: %d%s\n"),
7201 header
->e_ident
[EI_VERSION
],
7202 (header
->e_ident
[EI_VERSION
] == EV_CURRENT
7204 : (header
->e_ident
[EI_VERSION
] != EV_NONE
7207 printf (_(" OS/ABI: %s\n"),
7208 get_osabi_name (filedata
, header
->e_ident
[EI_OSABI
]));
7209 printf (_(" ABI Version: %d\n"),
7210 header
->e_ident
[EI_ABIVERSION
]);
7211 printf (_(" Type: %s\n"),
7212 get_file_type (filedata
));
7213 printf (_(" Machine: %s\n"),
7214 get_machine_name (header
->e_machine
));
7215 printf (_(" Version: 0x%lx\n"),
7218 printf (_(" Entry point address: "));
7219 print_vma (header
->e_entry
, PREFIX_HEX
);
7220 printf (_("\n Start of program headers: "));
7221 print_vma (header
->e_phoff
, DEC
);
7222 printf (_(" (bytes into file)\n Start of section headers: "));
7223 print_vma (header
->e_shoff
, DEC
);
7224 printf (_(" (bytes into file)\n"));
7226 printf (_(" Flags: 0x%lx%s\n"),
7228 get_machine_flags (filedata
, header
->e_flags
, header
->e_machine
));
7229 printf (_(" Size of this header: %u (bytes)\n"),
7231 printf (_(" Size of program headers: %u (bytes)\n"),
7232 header
->e_phentsize
);
7233 printf (_(" Number of program headers: %u"),
7235 if (filedata
->section_headers
!= NULL
7236 && header
->e_phnum
== PN_XNUM
7237 && filedata
->section_headers
[0].sh_info
!= 0)
7238 printf (" (%u)", filedata
->section_headers
[0].sh_info
);
7239 putc ('\n', stdout
);
7240 printf (_(" Size of section headers: %u (bytes)\n"),
7241 header
->e_shentsize
);
7242 printf (_(" Number of section headers: %u"),
7244 if (filedata
->section_headers
!= NULL
&& header
->e_shnum
== SHN_UNDEF
)
7246 header
->e_shnum
= filedata
->section_headers
[0].sh_size
;
7247 printf (" (%u)", header
->e_shnum
);
7249 putc ('\n', stdout
);
7250 printf (_(" Section header string table index: %u"),
7251 header
->e_shstrndx
);
7252 if (filedata
->section_headers
!= NULL
7253 && header
->e_shstrndx
== (SHN_XINDEX
& 0xffff))
7255 header
->e_shstrndx
= filedata
->section_headers
[0].sh_link
;
7256 printf (" (%u)", header
->e_shstrndx
);
7258 if (header
->e_shstrndx
!= SHN_UNDEF
7259 && header
->e_shstrndx
>= header
->e_shnum
)
7261 header
->e_shstrndx
= SHN_UNDEF
;
7262 printf (_(" <corrupt: out of range>"));
7264 putc ('\n', stdout
);
7267 if (filedata
->section_headers
!= NULL
)
7269 if (header
->e_phnum
== PN_XNUM
7270 && filedata
->section_headers
[0].sh_info
!= 0)
7272 /* Throw away any cached read of PN_XNUM headers. */
7273 free (filedata
->program_headers
);
7274 filedata
->program_headers
= NULL
;
7275 header
->e_phnum
= filedata
->section_headers
[0].sh_info
;
7277 if (header
->e_shnum
== SHN_UNDEF
)
7278 header
->e_shnum
= filedata
->section_headers
[0].sh_size
;
7279 if (header
->e_shstrndx
== (SHN_XINDEX
& 0xffff))
7280 header
->e_shstrndx
= filedata
->section_headers
[0].sh_link
;
7281 if (header
->e_shstrndx
>= header
->e_shnum
)
7282 header
->e_shstrndx
= SHN_UNDEF
;
7288 /* Read in the program headers from FILEDATA and store them in PHEADERS.
7289 Returns TRUE upon success, FALSE otherwise. Loads 32-bit headers. */
7292 get_32bit_program_headers (Filedata
* filedata
, Elf_Internal_Phdr
* pheaders
)
7294 Elf32_External_Phdr
* phdrs
;
7295 Elf32_External_Phdr
* external
;
7296 Elf_Internal_Phdr
* internal
;
7298 unsigned int size
= filedata
->file_header
.e_phentsize
;
7299 unsigned int num
= filedata
->file_header
.e_phnum
;
7301 /* PR binutils/17531: Cope with unexpected section header sizes. */
7302 if (size
== 0 || num
== 0)
7304 if (size
< sizeof * phdrs
)
7306 error (_("The e_phentsize field in the ELF header is less than the size of an ELF program header\n"));
7309 if (size
> sizeof * phdrs
)
7310 warn (_("The e_phentsize field in the ELF header is larger than the size of an ELF program header\n"));
7312 phdrs
= (Elf32_External_Phdr
*) get_data (NULL
, filedata
, filedata
->file_header
.e_phoff
,
7313 size
, num
, _("program headers"));
7317 for (i
= 0, internal
= pheaders
, external
= phdrs
;
7318 i
< filedata
->file_header
.e_phnum
;
7319 i
++, internal
++, external
++)
7321 internal
->p_type
= BYTE_GET (external
->p_type
);
7322 internal
->p_offset
= BYTE_GET (external
->p_offset
);
7323 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
7324 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
7325 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
7326 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
7327 internal
->p_flags
= BYTE_GET (external
->p_flags
);
7328 internal
->p_align
= BYTE_GET (external
->p_align
);
7335 /* Read in the program headers from FILEDATA and store them in PHEADERS.
7336 Returns TRUE upon success, FALSE otherwise. Loads 64-bit headers. */
7339 get_64bit_program_headers (Filedata
* filedata
, Elf_Internal_Phdr
* pheaders
)
7341 Elf64_External_Phdr
* phdrs
;
7342 Elf64_External_Phdr
* external
;
7343 Elf_Internal_Phdr
* internal
;
7345 unsigned int size
= filedata
->file_header
.e_phentsize
;
7346 unsigned int num
= filedata
->file_header
.e_phnum
;
7348 /* PR binutils/17531: Cope with unexpected section header sizes. */
7349 if (size
== 0 || num
== 0)
7351 if (size
< sizeof * phdrs
)
7353 error (_("The e_phentsize field in the ELF header is less than the size of an ELF program header\n"));
7356 if (size
> sizeof * phdrs
)
7357 warn (_("The e_phentsize field in the ELF header is larger than the size of an ELF program header\n"));
7359 phdrs
= (Elf64_External_Phdr
*) get_data (NULL
, filedata
, filedata
->file_header
.e_phoff
,
7360 size
, num
, _("program headers"));
7364 for (i
= 0, internal
= pheaders
, external
= phdrs
;
7365 i
< filedata
->file_header
.e_phnum
;
7366 i
++, internal
++, external
++)
7368 internal
->p_type
= BYTE_GET (external
->p_type
);
7369 internal
->p_flags
= BYTE_GET (external
->p_flags
);
7370 internal
->p_offset
= BYTE_GET (external
->p_offset
);
7371 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
7372 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
7373 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
7374 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
7375 internal
->p_align
= BYTE_GET (external
->p_align
);
7382 /* Returns TRUE if the program headers were read into `program_headers'. */
7385 get_program_headers (Filedata
* filedata
)
7387 Elf_Internal_Phdr
* phdrs
;
7389 /* Check cache of prior read. */
7390 if (filedata
->program_headers
!= NULL
)
7393 /* Be kind to memory checkers by looking for
7394 e_phnum values which we know must be invalid. */
7395 if (filedata
->file_header
.e_phnum
7396 * (is_32bit_elf
? sizeof (Elf32_External_Phdr
) : sizeof (Elf64_External_Phdr
))
7397 >= filedata
->file_size
)
7399 error (_("Too many program headers - %#x - the file is not that big\n"),
7400 filedata
->file_header
.e_phnum
);
7404 phdrs
= (Elf_Internal_Phdr
*) cmalloc (filedata
->file_header
.e_phnum
,
7405 sizeof (Elf_Internal_Phdr
));
7408 error (_("Out of memory reading %u program headers\n"),
7409 filedata
->file_header
.e_phnum
);
7414 ? get_32bit_program_headers (filedata
, phdrs
)
7415 : get_64bit_program_headers (filedata
, phdrs
))
7417 filedata
->program_headers
= phdrs
;
7425 /* Print program header info and locate dynamic section. */
7428 process_program_headers (Filedata
* filedata
)
7430 Elf_Internal_Phdr
* segment
;
7432 Elf_Internal_Phdr
* previous_load
= NULL
;
7434 if (filedata
->file_header
.e_phnum
== 0)
7436 /* PR binutils/12467. */
7437 if (filedata
->file_header
.e_phoff
!= 0)
7438 warn (_("possibly corrupt ELF header - it has a non-zero program"
7439 " header offset, but no program headers\n"));
7440 else if (do_segments
)
7442 if (filedata
->is_separate
)
7443 printf (_("\nThere are no program headers in linked file '%s'.\n"),
7444 printable_string (filedata
->file_name
, 0));
7446 printf (_("\nThere are no program headers in this file.\n"));
7451 if (do_segments
&& !do_header
)
7453 if (filedata
->is_separate
)
7454 printf ("\nIn linked file '%s' the ELF file type is %s\n",
7455 printable_string (filedata
->file_name
, 0),
7456 get_file_type (filedata
));
7458 printf (_("\nElf file type is %s\n"), get_file_type (filedata
));
7459 printf (_("Entry point 0x%" PRIx64
"\n"),
7460 filedata
->file_header
.e_entry
);
7461 printf (ngettext ("There is %d program header,"
7462 " starting at offset %" PRIu64
"\n",
7463 "There are %d program headers,"
7464 " starting at offset %" PRIu64
"\n",
7465 filedata
->file_header
.e_phnum
),
7466 filedata
->file_header
.e_phnum
,
7467 filedata
->file_header
.e_phoff
);
7470 if (! get_program_headers (filedata
))
7475 if (filedata
->file_header
.e_phnum
> 1)
7476 printf (_("\nProgram Headers:\n"));
7478 printf (_("\nProgram Headers:\n"));
7482 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
7485 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
7489 (_(" Type Offset VirtAddr PhysAddr\n"));
7491 (_(" FileSiz MemSiz Flags Align\n"));
7495 uint64_t dynamic_addr
= 0;
7496 uint64_t dynamic_size
= 0;
7497 for (i
= 0, segment
= filedata
->program_headers
;
7498 i
< filedata
->file_header
.e_phnum
;
7503 printf (" %-14.14s ", get_segment_type (filedata
, segment
->p_type
));
7507 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
7508 printf ("0x%8.8lx ", (unsigned long) segment
->p_vaddr
);
7509 printf ("0x%8.8lx ", (unsigned long) segment
->p_paddr
);
7510 printf ("0x%5.5lx ", (unsigned long) segment
->p_filesz
);
7511 printf ("0x%5.5lx ", (unsigned long) segment
->p_memsz
);
7513 (segment
->p_flags
& PF_R
? 'R' : ' '),
7514 (segment
->p_flags
& PF_W
? 'W' : ' '),
7515 (segment
->p_flags
& PF_X
? 'E' : ' '));
7516 printf ("%#lx", (unsigned long) segment
->p_align
);
7520 if ((unsigned long) segment
->p_offset
== segment
->p_offset
)
7521 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
7524 print_vma (segment
->p_offset
, FULL_HEX
);
7528 print_vma (segment
->p_vaddr
, FULL_HEX
);
7530 print_vma (segment
->p_paddr
, FULL_HEX
);
7533 if ((unsigned long) segment
->p_filesz
== segment
->p_filesz
)
7534 printf ("0x%6.6lx ", (unsigned long) segment
->p_filesz
);
7537 print_vma (segment
->p_filesz
, FULL_HEX
);
7541 if ((unsigned long) segment
->p_memsz
== segment
->p_memsz
)
7542 printf ("0x%6.6lx", (unsigned long) segment
->p_memsz
);
7545 print_vma (segment
->p_memsz
, FULL_HEX
);
7549 (segment
->p_flags
& PF_R
? 'R' : ' '),
7550 (segment
->p_flags
& PF_W
? 'W' : ' '),
7551 (segment
->p_flags
& PF_X
? 'E' : ' '));
7553 if ((unsigned long) segment
->p_align
== segment
->p_align
)
7554 printf ("%#lx", (unsigned long) segment
->p_align
);
7557 print_vma (segment
->p_align
, PREFIX_HEX
);
7562 print_vma (segment
->p_offset
, FULL_HEX
);
7564 print_vma (segment
->p_vaddr
, FULL_HEX
);
7566 print_vma (segment
->p_paddr
, FULL_HEX
);
7568 print_vma (segment
->p_filesz
, FULL_HEX
);
7570 print_vma (segment
->p_memsz
, FULL_HEX
);
7572 (segment
->p_flags
& PF_R
? 'R' : ' '),
7573 (segment
->p_flags
& PF_W
? 'W' : ' '),
7574 (segment
->p_flags
& PF_X
? 'E' : ' '));
7575 print_vma (segment
->p_align
, PREFIX_HEX
);
7578 putc ('\n', stdout
);
7581 switch (segment
->p_type
)
7584 #if 0 /* Do not warn about out of order PT_LOAD segments. Although officially
7585 required by the ELF standard, several programs, including the Linux
7586 kernel, make use of non-ordered segments. */
7588 && previous_load
->p_vaddr
> segment
->p_vaddr
)
7589 error (_("LOAD segments must be sorted in order of increasing VirtAddr\n"));
7591 if (segment
->p_memsz
< segment
->p_filesz
)
7592 error (_("the segment's file size is larger than its memory size\n"));
7593 previous_load
= segment
;
7597 /* PR 20815 - Verify that the program header is loaded into memory. */
7598 if (i
> 0 && previous_load
!= NULL
)
7599 error (_("the PHDR segment must occur before any LOAD segment\n"));
7600 if (filedata
->file_header
.e_machine
!= EM_PARISC
)
7604 for (j
= 1; j
< filedata
->file_header
.e_phnum
; j
++)
7606 Elf_Internal_Phdr
*load
= filedata
->program_headers
+ j
;
7607 if (load
->p_type
== PT_LOAD
7608 && load
->p_offset
<= segment
->p_offset
7609 && (load
->p_offset
+ load
->p_filesz
7610 >= segment
->p_offset
+ segment
->p_filesz
)
7611 && load
->p_vaddr
<= segment
->p_vaddr
7612 && (load
->p_vaddr
+ load
->p_filesz
7613 >= segment
->p_vaddr
+ segment
->p_filesz
))
7616 if (j
== filedata
->file_header
.e_phnum
)
7617 error (_("the PHDR segment is not covered by a LOAD segment\n"));
7623 error (_("more than one dynamic segment\n"));
7625 /* By default, assume that the .dynamic section is the first
7626 section in the DYNAMIC segment. */
7627 dynamic_addr
= segment
->p_offset
;
7628 dynamic_size
= segment
->p_filesz
;
7630 /* Try to locate the .dynamic section. If there is
7631 a section header table, we can easily locate it. */
7632 if (filedata
->section_headers
!= NULL
)
7634 Elf_Internal_Shdr
* sec
;
7636 sec
= find_section (filedata
, ".dynamic");
7637 if (sec
== NULL
|| sec
->sh_size
== 0)
7639 /* A corresponding .dynamic section is expected, but on
7640 IA-64/OpenVMS it is OK for it to be missing. */
7641 if (!is_ia64_vms (filedata
))
7642 error (_("no .dynamic section in the dynamic segment\n"));
7646 if (sec
->sh_type
== SHT_NOBITS
)
7653 dynamic_addr
= sec
->sh_offset
;
7654 dynamic_size
= sec
->sh_size
;
7656 /* The PT_DYNAMIC segment, which is used by the run-time
7657 loader, should exactly match the .dynamic section. */
7659 && (dynamic_addr
!= segment
->p_offset
7660 || dynamic_size
!= segment
->p_filesz
))
7662 the .dynamic section is not the same as the dynamic segment\n"));
7665 /* PR binutils/17512: Avoid corrupt dynamic section info in the
7666 segment. Check this after matching against the section headers
7667 so we don't warn on debuginfo file (which have NOBITS .dynamic
7669 if (dynamic_addr
> filedata
->file_size
7670 || (dynamic_size
> filedata
->file_size
- dynamic_addr
))
7672 error (_("the dynamic segment offset + size exceeds the size of the file\n"));
7679 if (segment
->p_offset
>= filedata
->file_size
7680 || segment
->p_filesz
> filedata
->file_size
- segment
->p_offset
7681 || segment
->p_filesz
- 1 >= (size_t) -2
7682 || fseek64 (filedata
->handle
,
7683 filedata
->archive_file_offset
+ segment
->p_offset
,
7685 error (_("Unable to find program interpreter name\n"));
7688 size_t len
= segment
->p_filesz
;
7689 free (filedata
->program_interpreter
);
7690 filedata
->program_interpreter
= xmalloc (len
+ 1);
7691 len
= fread (filedata
->program_interpreter
, 1, len
,
7693 filedata
->program_interpreter
[len
] = 0;
7696 printf (_(" [Requesting program interpreter: %s]\n"),
7697 printable_string (filedata
->program_interpreter
, 0));
7704 && filedata
->section_headers
!= NULL
7705 && filedata
->string_table
!= NULL
)
7707 printf (_("\n Section to Segment mapping:\n"));
7708 printf (_(" Segment Sections...\n"));
7710 for (i
= 0; i
< filedata
->file_header
.e_phnum
; i
++)
7713 Elf_Internal_Shdr
* section
;
7715 segment
= filedata
->program_headers
+ i
;
7716 section
= filedata
->section_headers
+ 1;
7718 printf (" %2.2d ", i
);
7720 for (j
= 1; j
< filedata
->file_header
.e_shnum
; j
++, section
++)
7722 if (!ELF_TBSS_SPECIAL (section
, segment
)
7723 && ELF_SECTION_IN_SEGMENT_STRICT (section
, segment
))
7724 printf ("%s ", printable_section_name (filedata
, section
));
7731 filedata
->dynamic_addr
= dynamic_addr
;
7732 filedata
->dynamic_size
= dynamic_size
? dynamic_size
: 1;
7736 filedata
->dynamic_addr
= 0;
7737 filedata
->dynamic_size
= 1;
7741 /* Find the file offset corresponding to VMA by using the program headers. */
7744 offset_from_vma (Filedata
* filedata
, uint64_t vma
, uint64_t size
)
7746 Elf_Internal_Phdr
* seg
;
7748 if (! get_program_headers (filedata
))
7750 warn (_("Cannot interpret virtual addresses without program headers.\n"));
7754 for (seg
= filedata
->program_headers
;
7755 seg
< filedata
->program_headers
+ filedata
->file_header
.e_phnum
;
7758 if (seg
->p_type
!= PT_LOAD
)
7761 if (vma
>= (seg
->p_vaddr
& -seg
->p_align
)
7762 && vma
+ size
<= seg
->p_vaddr
+ seg
->p_filesz
)
7763 return vma
- seg
->p_vaddr
+ seg
->p_offset
;
7766 warn (_("Virtual address %#" PRIx64
7767 " not located in any PT_LOAD segment.\n"), vma
);
7772 /* Allocate memory and load the sections headers into FILEDATA->filedata->section_headers.
7773 If PROBE is true, this is just a probe and we do not generate any error
7774 messages if the load fails. */
7777 get_32bit_section_headers (Filedata
* filedata
, bool probe
)
7779 Elf32_External_Shdr
* shdrs
;
7780 Elf_Internal_Shdr
* internal
;
7782 unsigned int size
= filedata
->file_header
.e_shentsize
;
7783 unsigned int num
= probe
? 1 : filedata
->file_header
.e_shnum
;
7785 /* PR binutils/17531: Cope with unexpected section header sizes. */
7786 if (size
== 0 || num
== 0)
7789 /* The section header cannot be at the start of the file - that is
7790 where the ELF file header is located. A file with absolutely no
7791 sections in it will use a shoff of 0. */
7792 if (filedata
->file_header
.e_shoff
== 0)
7795 if (size
< sizeof * shdrs
)
7798 error (_("The e_shentsize field in the ELF header is less than the size of an ELF section header\n"));
7801 if (!probe
&& size
> sizeof * shdrs
)
7802 warn (_("The e_shentsize field in the ELF header is larger than the size of an ELF section header\n"));
7804 shdrs
= (Elf32_External_Shdr
*) get_data (NULL
, filedata
, filedata
->file_header
.e_shoff
,
7806 probe
? NULL
: _("section headers"));
7810 filedata
->section_headers
= (Elf_Internal_Shdr
*)
7811 cmalloc (num
, sizeof (Elf_Internal_Shdr
));
7812 if (filedata
->section_headers
== NULL
)
7815 error (_("Out of memory reading %u section headers\n"), num
);
7820 for (i
= 0, internal
= filedata
->section_headers
;
7824 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
7825 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
7826 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
7827 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
7828 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
7829 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
7830 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
7831 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
7832 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
7833 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
7834 if (!probe
&& internal
->sh_link
> num
)
7835 warn (_("Section %u has an out of range sh_link value of %u\n"), i
, internal
->sh_link
);
7836 if (!probe
&& internal
->sh_flags
& SHF_INFO_LINK
&& internal
->sh_info
> num
)
7837 warn (_("Section %u has an out of range sh_info value of %u\n"), i
, internal
->sh_info
);
7844 /* Like get_32bit_section_headers, except that it fetches 64-bit headers. */
7847 get_64bit_section_headers (Filedata
* filedata
, bool probe
)
7849 Elf64_External_Shdr
* shdrs
;
7850 Elf_Internal_Shdr
* internal
;
7852 unsigned int size
= filedata
->file_header
.e_shentsize
;
7853 unsigned int num
= probe
? 1 : filedata
->file_header
.e_shnum
;
7855 /* PR binutils/17531: Cope with unexpected section header sizes. */
7856 if (size
== 0 || num
== 0)
7859 /* The section header cannot be at the start of the file - that is
7860 where the ELF file header is located. A file with absolutely no
7861 sections in it will use a shoff of 0. */
7862 if (filedata
->file_header
.e_shoff
== 0)
7865 if (size
< sizeof * shdrs
)
7868 error (_("The e_shentsize field in the ELF header is less than the size of an ELF section header\n"));
7872 if (! probe
&& size
> sizeof * shdrs
)
7873 warn (_("The e_shentsize field in the ELF header is larger than the size of an ELF section header\n"));
7875 shdrs
= (Elf64_External_Shdr
*) get_data (NULL
, filedata
,
7876 filedata
->file_header
.e_shoff
,
7878 probe
? NULL
: _("section headers"));
7882 filedata
->section_headers
= (Elf_Internal_Shdr
*)
7883 cmalloc (num
, sizeof (Elf_Internal_Shdr
));
7884 if (filedata
->section_headers
== NULL
)
7887 error (_("Out of memory reading %u section headers\n"), num
);
7892 for (i
= 0, internal
= filedata
->section_headers
;
7896 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
7897 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
7898 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
7899 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
7900 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
7901 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
7902 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
7903 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
7904 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
7905 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
7906 if (!probe
&& internal
->sh_link
> num
)
7907 warn (_("Section %u has an out of range sh_link value of %u\n"), i
, internal
->sh_link
);
7908 if (!probe
&& internal
->sh_flags
& SHF_INFO_LINK
&& internal
->sh_info
> num
)
7909 warn (_("Section %u has an out of range sh_info value of %u\n"), i
, internal
->sh_info
);
7917 get_section_headers (Filedata
*filedata
, bool probe
)
7919 if (filedata
->section_headers
!= NULL
)
7923 return get_32bit_section_headers (filedata
, probe
);
7925 return get_64bit_section_headers (filedata
, probe
);
7928 static Elf_Internal_Sym
*
7929 get_32bit_elf_symbols (Filedata
*filedata
,
7930 Elf_Internal_Shdr
*section
,
7931 uint64_t *num_syms_return
)
7933 uint64_t number
= 0;
7934 Elf32_External_Sym
* esyms
= NULL
;
7935 Elf_External_Sym_Shndx
* shndx
= NULL
;
7936 Elf_Internal_Sym
* isyms
= NULL
;
7937 Elf_Internal_Sym
* psym
;
7939 elf_section_list
* entry
;
7941 if (section
->sh_size
== 0)
7943 if (num_syms_return
!= NULL
)
7944 * num_syms_return
= 0;
7948 /* Run some sanity checks first. */
7949 if (section
->sh_entsize
== 0 || section
->sh_entsize
> section
->sh_size
)
7951 error (_("Section %s has an invalid sh_entsize of %#" PRIx64
"\n"),
7952 printable_section_name (filedata
, section
),
7953 section
->sh_entsize
);
7957 if (section
->sh_size
> filedata
->file_size
)
7959 error (_("Section %s has an invalid sh_size of %#" PRIx64
"\n"),
7960 printable_section_name (filedata
, section
),
7965 number
= section
->sh_size
/ section
->sh_entsize
;
7967 if (number
* sizeof (Elf32_External_Sym
) > section
->sh_size
+ 1)
7969 error (_("Size (%#" PRIx64
") of section %s "
7970 "is not a multiple of its sh_entsize (%#" PRIx64
")\n"),
7972 printable_section_name (filedata
, section
),
7973 section
->sh_entsize
);
7977 esyms
= (Elf32_External_Sym
*) get_data (NULL
, filedata
, section
->sh_offset
, 1,
7978 section
->sh_size
, _("symbols"));
7983 for (entry
= filedata
->symtab_shndx_list
; entry
!= NULL
; entry
= entry
->next
)
7985 if (entry
->hdr
->sh_link
!= (size_t) (section
- filedata
->section_headers
))
7990 error (_("Multiple symbol table index sections associated with the same symbol section\n"));
7994 shndx
= (Elf_External_Sym_Shndx
*) get_data (NULL
, filedata
,
7995 entry
->hdr
->sh_offset
,
7996 1, entry
->hdr
->sh_size
,
7997 _("symbol table section indices"));
8001 /* PR17531: file: heap-buffer-overflow */
8002 if (entry
->hdr
->sh_size
/ sizeof (Elf_External_Sym_Shndx
) < number
)
8004 error (_("Index section %s has an sh_size of %#" PRIx64
" - expected %#" PRIx64
"\n"),
8005 printable_section_name (filedata
, entry
->hdr
),
8006 entry
->hdr
->sh_size
,
8012 isyms
= (Elf_Internal_Sym
*) cmalloc (number
, sizeof (Elf_Internal_Sym
));
8016 error (_("Out of memory reading %" PRIu64
" symbols\n"), number
);
8020 for (j
= 0, psym
= isyms
; j
< number
; j
++, psym
++)
8022 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
8023 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
8024 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
8025 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
8026 if (psym
->st_shndx
== (SHN_XINDEX
& 0xffff) && shndx
!= NULL
)
8028 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
8029 else if (psym
->st_shndx
>= (SHN_LORESERVE
& 0xffff))
8030 psym
->st_shndx
+= SHN_LORESERVE
- (SHN_LORESERVE
& 0xffff);
8031 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
8032 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
8039 if (num_syms_return
!= NULL
)
8040 * num_syms_return
= isyms
== NULL
? 0 : number
;
8045 static Elf_Internal_Sym
*
8046 get_64bit_elf_symbols (Filedata
*filedata
,
8047 Elf_Internal_Shdr
*section
,
8048 uint64_t *num_syms_return
)
8050 uint64_t number
= 0;
8051 Elf64_External_Sym
* esyms
= NULL
;
8052 Elf_External_Sym_Shndx
* shndx
= NULL
;
8053 Elf_Internal_Sym
* isyms
= NULL
;
8054 Elf_Internal_Sym
* psym
;
8056 elf_section_list
* entry
;
8058 if (section
->sh_size
== 0)
8060 if (num_syms_return
!= NULL
)
8061 * num_syms_return
= 0;
8065 /* Run some sanity checks first. */
8066 if (section
->sh_entsize
== 0 || section
->sh_entsize
> section
->sh_size
)
8068 error (_("Section %s has an invalid sh_entsize of %#" PRIx64
"\n"),
8069 printable_section_name (filedata
, section
),
8070 section
->sh_entsize
);
8074 if (section
->sh_size
> filedata
->file_size
)
8076 error (_("Section %s has an invalid sh_size of %#" PRIx64
"\n"),
8077 printable_section_name (filedata
, section
),
8082 number
= section
->sh_size
/ section
->sh_entsize
;
8084 if (number
* sizeof (Elf64_External_Sym
) > section
->sh_size
+ 1)
8086 error (_("Size (%#" PRIx64
") of section %s "
8087 "is not a multiple of its sh_entsize (%#" PRIx64
")\n"),
8089 printable_section_name (filedata
, section
),
8090 section
->sh_entsize
);
8094 esyms
= (Elf64_External_Sym
*) get_data (NULL
, filedata
, section
->sh_offset
, 1,
8095 section
->sh_size
, _("symbols"));
8100 for (entry
= filedata
->symtab_shndx_list
; entry
!= NULL
; entry
= entry
->next
)
8102 if (entry
->hdr
->sh_link
!= (size_t) (section
- filedata
->section_headers
))
8107 error (_("Multiple symbol table index sections associated with the same symbol section\n"));
8111 shndx
= (Elf_External_Sym_Shndx
*) get_data (NULL
, filedata
,
8112 entry
->hdr
->sh_offset
,
8113 1, entry
->hdr
->sh_size
,
8114 _("symbol table section indices"));
8118 /* PR17531: file: heap-buffer-overflow */
8119 if (entry
->hdr
->sh_size
/ sizeof (Elf_External_Sym_Shndx
) < number
)
8121 error (_("Index section %s has an sh_size of %#" PRIx64
" - expected %#" PRIx64
"\n"),
8122 printable_section_name (filedata
, entry
->hdr
),
8123 entry
->hdr
->sh_size
,
8129 isyms
= (Elf_Internal_Sym
*) cmalloc (number
, sizeof (Elf_Internal_Sym
));
8133 error (_("Out of memory reading %" PRIu64
" symbols\n"), number
);
8137 for (j
= 0, psym
= isyms
; j
< number
; j
++, psym
++)
8139 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
8140 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
8141 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
8142 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
8144 if (psym
->st_shndx
== (SHN_XINDEX
& 0xffff) && shndx
!= NULL
)
8146 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
8147 else if (psym
->st_shndx
>= (SHN_LORESERVE
& 0xffff))
8148 psym
->st_shndx
+= SHN_LORESERVE
- (SHN_LORESERVE
& 0xffff);
8150 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
8151 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
8158 if (num_syms_return
!= NULL
)
8159 * num_syms_return
= isyms
== NULL
? 0 : number
;
8164 static Elf_Internal_Sym
*
8165 get_elf_symbols (Filedata
*filedata
,
8166 Elf_Internal_Shdr
*section
,
8167 uint64_t *num_syms_return
)
8170 return get_32bit_elf_symbols (filedata
, section
, num_syms_return
);
8172 return get_64bit_elf_symbols (filedata
, section
, num_syms_return
);
8176 get_elf_section_flags (Filedata
* filedata
, uint64_t sh_flags
)
8178 static char buff
[1024];
8180 unsigned int field_size
= is_32bit_elf
? 8 : 16;
8182 unsigned int size
= sizeof (buff
) - (field_size
+ 4 + 1);
8183 uint64_t os_flags
= 0;
8184 uint64_t proc_flags
= 0;
8185 uint64_t unknown_flags
= 0;
8193 /* 0 */ { STRING_COMMA_LEN ("WRITE") },
8194 /* 1 */ { STRING_COMMA_LEN ("ALLOC") },
8195 /* 2 */ { STRING_COMMA_LEN ("EXEC") },
8196 /* 3 */ { STRING_COMMA_LEN ("MERGE") },
8197 /* 4 */ { STRING_COMMA_LEN ("STRINGS") },
8198 /* 5 */ { STRING_COMMA_LEN ("INFO LINK") },
8199 /* 6 */ { STRING_COMMA_LEN ("LINK ORDER") },
8200 /* 7 */ { STRING_COMMA_LEN ("OS NONCONF") },
8201 /* 8 */ { STRING_COMMA_LEN ("GROUP") },
8202 /* 9 */ { STRING_COMMA_LEN ("TLS") },
8203 /* IA-64 specific. */
8204 /* 10 */ { STRING_COMMA_LEN ("SHORT") },
8205 /* 11 */ { STRING_COMMA_LEN ("NORECOV") },
8206 /* IA-64 OpenVMS specific. */
8207 /* 12 */ { STRING_COMMA_LEN ("VMS_GLOBAL") },
8208 /* 13 */ { STRING_COMMA_LEN ("VMS_OVERLAID") },
8209 /* 14 */ { STRING_COMMA_LEN ("VMS_SHARED") },
8210 /* 15 */ { STRING_COMMA_LEN ("VMS_VECTOR") },
8211 /* 16 */ { STRING_COMMA_LEN ("VMS_ALLOC_64BIT") },
8212 /* 17 */ { STRING_COMMA_LEN ("VMS_PROTECTED") },
8214 /* 18 */ { STRING_COMMA_LEN ("EXCLUDE") },
8215 /* SPARC specific. */
8216 /* 19 */ { STRING_COMMA_LEN ("ORDERED") },
8217 /* 20 */ { STRING_COMMA_LEN ("COMPRESSED") },
8219 /* 21 */ { STRING_COMMA_LEN ("ENTRYSECT") },
8220 /* 22 */ { STRING_COMMA_LEN ("ARM_PURECODE") },
8221 /* 23 */ { STRING_COMMA_LEN ("COMDEF") },
8223 /* 24 */ { STRING_COMMA_LEN ("GNU_MBIND") },
8225 /* 25 */ { STRING_COMMA_LEN ("VLE") },
8227 /* 26 */ { STRING_COMMA_LEN ("GNU_RETAIN") },
8230 if (do_section_details
)
8231 p
+= sprintf (p
, "[%*.*lx]: ",
8232 field_size
, field_size
, (unsigned long) sh_flags
);
8238 flag
= sh_flags
& - sh_flags
;
8241 if (do_section_details
)
8245 case SHF_WRITE
: sindex
= 0; break;
8246 case SHF_ALLOC
: sindex
= 1; break;
8247 case SHF_EXECINSTR
: sindex
= 2; break;
8248 case SHF_MERGE
: sindex
= 3; break;
8249 case SHF_STRINGS
: sindex
= 4; break;
8250 case SHF_INFO_LINK
: sindex
= 5; break;
8251 case SHF_LINK_ORDER
: sindex
= 6; break;
8252 case SHF_OS_NONCONFORMING
: sindex
= 7; break;
8253 case SHF_GROUP
: sindex
= 8; break;
8254 case SHF_TLS
: sindex
= 9; break;
8255 case SHF_EXCLUDE
: sindex
= 18; break;
8256 case SHF_COMPRESSED
: sindex
= 20; break;
8260 switch (filedata
->file_header
.e_machine
)
8263 if (flag
== SHF_IA_64_SHORT
)
8265 else if (flag
== SHF_IA_64_NORECOV
)
8267 else if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_OPENVMS
)
8270 case SHF_IA_64_VMS_GLOBAL
: sindex
= 12; break;
8271 case SHF_IA_64_VMS_OVERLAID
: sindex
= 13; break;
8272 case SHF_IA_64_VMS_SHARED
: sindex
= 14; break;
8273 case SHF_IA_64_VMS_VECTOR
: sindex
= 15; break;
8274 case SHF_IA_64_VMS_ALLOC_64BIT
: sindex
= 16; break;
8275 case SHF_IA_64_VMS_PROTECTED
: sindex
= 17; break;
8285 case EM_OLD_SPARCV9
:
8286 case EM_SPARC32PLUS
:
8289 if (flag
== SHF_ORDERED
)
8296 case SHF_ENTRYSECT
: sindex
= 21; break;
8297 case SHF_ARM_PURECODE
: sindex
= 22; break;
8298 case SHF_COMDEF
: sindex
= 23; break;
8303 if (flag
== SHF_PPC_VLE
)
8310 switch (filedata
->file_header
.e_ident
[EI_OSABI
])
8313 case ELFOSABI_FREEBSD
:
8314 if (flag
== SHF_GNU_RETAIN
)
8318 if (flag
== SHF_GNU_MBIND
)
8319 /* We should not recognize SHF_GNU_MBIND for
8320 ELFOSABI_NONE, but binutils as of 2019-07-23 did
8321 not set the EI_OSABI header byte. */
8332 if (p
!= buff
+ field_size
+ 4)
8334 if (size
< (10 + 2))
8336 warn (_("Internal error: not enough buffer room for section flag info"));
8337 return _("<unknown>");
8344 size
-= flags
[sindex
].len
;
8345 p
= stpcpy (p
, flags
[sindex
].str
);
8347 else if (flag
& SHF_MASKOS
)
8349 else if (flag
& SHF_MASKPROC
)
8352 unknown_flags
|= flag
;
8358 case SHF_WRITE
: *p
= 'W'; break;
8359 case SHF_ALLOC
: *p
= 'A'; break;
8360 case SHF_EXECINSTR
: *p
= 'X'; break;
8361 case SHF_MERGE
: *p
= 'M'; break;
8362 case SHF_STRINGS
: *p
= 'S'; break;
8363 case SHF_INFO_LINK
: *p
= 'I'; break;
8364 case SHF_LINK_ORDER
: *p
= 'L'; break;
8365 case SHF_OS_NONCONFORMING
: *p
= 'O'; break;
8366 case SHF_GROUP
: *p
= 'G'; break;
8367 case SHF_TLS
: *p
= 'T'; break;
8368 case SHF_EXCLUDE
: *p
= 'E'; break;
8369 case SHF_COMPRESSED
: *p
= 'C'; break;
8372 if ((filedata
->file_header
.e_machine
== EM_X86_64
8373 || filedata
->file_header
.e_machine
== EM_L1OM
8374 || filedata
->file_header
.e_machine
== EM_K1OM
)
8375 && flag
== SHF_X86_64_LARGE
)
8377 else if (filedata
->file_header
.e_machine
== EM_ARM
8378 && flag
== SHF_ARM_PURECODE
)
8380 else if (filedata
->file_header
.e_machine
== EM_PPC
8381 && flag
== SHF_PPC_VLE
)
8383 else if (flag
& SHF_MASKOS
)
8385 switch (filedata
->file_header
.e_ident
[EI_OSABI
])
8388 case ELFOSABI_FREEBSD
:
8389 if (flag
== SHF_GNU_RETAIN
)
8396 if (flag
== SHF_GNU_MBIND
)
8398 /* We should not recognize SHF_GNU_MBIND for
8399 ELFOSABI_NONE, but binutils as of 2019-07-23 did
8400 not set the EI_OSABI header byte. */
8407 sh_flags
&= ~SHF_MASKOS
;
8411 else if (flag
& SHF_MASKPROC
)
8414 sh_flags
&= ~ SHF_MASKPROC
;
8424 if (do_section_details
)
8428 if (p
!= buff
+ field_size
+ 4)
8430 if (size
< 2 + 5 + field_size
+ 1)
8432 warn (_("Internal error: not enough buffer room for section flag info"));
8433 return _("<unknown>");
8439 size
-= 5 + field_size
;
8440 p
+= sprintf (p
, "OS (%*.*lx)", field_size
, field_size
,
8441 (unsigned long) os_flags
);
8445 if (p
!= buff
+ field_size
+ 4)
8447 if (size
< 2 + 7 + field_size
+ 1)
8449 warn (_("Internal error: not enough buffer room for section flag info"));
8450 return _("<unknown>");
8456 size
-= 7 + field_size
;
8457 p
+= sprintf (p
, "PROC (%*.*lx)", field_size
, field_size
,
8458 (unsigned long) proc_flags
);
8462 if (p
!= buff
+ field_size
+ 4)
8464 if (size
< 2 + 10 + field_size
+ 1)
8466 warn (_("Internal error: not enough buffer room for section flag info"));
8467 return _("<unknown>");
8473 size
-= 10 + field_size
;
8474 p
+= sprintf (p
, _("UNKNOWN (%*.*lx)"), field_size
, field_size
,
8475 (unsigned long) unknown_flags
);
8483 static unsigned int ATTRIBUTE_WARN_UNUSED_RESULT
8484 get_compression_header (Elf_Internal_Chdr
*chdr
, unsigned char *buf
,
8489 Elf32_External_Chdr
*echdr
= (Elf32_External_Chdr
*) buf
;
8491 if (size
< sizeof (* echdr
))
8493 error (_("Compressed section is too small even for a compression header\n"));
8497 chdr
->ch_type
= BYTE_GET (echdr
->ch_type
);
8498 chdr
->ch_size
= BYTE_GET (echdr
->ch_size
);
8499 chdr
->ch_addralign
= BYTE_GET (echdr
->ch_addralign
);
8500 return sizeof (*echdr
);
8504 Elf64_External_Chdr
*echdr
= (Elf64_External_Chdr
*) buf
;
8506 if (size
< sizeof (* echdr
))
8508 error (_("Compressed section is too small even for a compression header\n"));
8512 chdr
->ch_type
= BYTE_GET (echdr
->ch_type
);
8513 chdr
->ch_size
= BYTE_GET (echdr
->ch_size
);
8514 chdr
->ch_addralign
= BYTE_GET (echdr
->ch_addralign
);
8515 return sizeof (*echdr
);
8520 process_section_headers (Filedata
* filedata
)
8522 Elf_Internal_Shdr
* section
;
8525 if (filedata
->file_header
.e_shnum
== 0)
8527 /* PR binutils/12467. */
8528 if (filedata
->file_header
.e_shoff
!= 0)
8530 warn (_("possibly corrupt ELF file header - it has a non-zero"
8531 " section header offset, but no section headers\n"));
8534 else if (do_sections
)
8535 printf (_("\nThere are no sections in this file.\n"));
8540 if (do_sections
&& !do_header
)
8542 if (filedata
->is_separate
&& process_links
)
8543 printf (_("In linked file '%s': "),
8544 printable_string (filedata
->file_name
, 0));
8545 if (! filedata
->is_separate
|| process_links
)
8546 printf (ngettext ("There is %d section header, "
8547 "starting at offset %#" PRIx64
":\n",
8548 "There are %d section headers, "
8549 "starting at offset %#" PRIx64
":\n",
8550 filedata
->file_header
.e_shnum
),
8551 filedata
->file_header
.e_shnum
,
8552 filedata
->file_header
.e_shoff
);
8555 if (!get_section_headers (filedata
, false))
8558 /* Read in the string table, so that we have names to display. */
8559 if (filedata
->string_table
== NULL
8560 && filedata
->file_header
.e_shstrndx
!= SHN_UNDEF
8561 && filedata
->file_header
.e_shstrndx
< filedata
->file_header
.e_shnum
)
8563 section
= filedata
->section_headers
+ filedata
->file_header
.e_shstrndx
;
8565 if (section
->sh_size
!= 0)
8567 filedata
->string_table
= (char *) get_data (NULL
, filedata
, section
->sh_offset
,
8568 1, section
->sh_size
,
8571 filedata
->string_table_length
= filedata
->string_table
!= NULL
? section
->sh_size
: 0;
8575 /* Scan the sections for the dynamic symbol table
8576 and dynamic string table and debug sections. */
8577 eh_addr_size
= is_32bit_elf
? 4 : 8;
8578 switch (filedata
->file_header
.e_machine
)
8581 case EM_MIPS_RS3_LE
:
8582 /* The 64-bit MIPS EABI uses a combination of 32-bit ELF and 64-bit
8583 FDE addresses. However, the ABI also has a semi-official ILP32
8584 variant for which the normal FDE address size rules apply.
8586 GCC 4.0 marks EABI64 objects with a dummy .gcc_compiled_longXX
8587 section, where XX is the size of longs in bits. Unfortunately,
8588 earlier compilers provided no way of distinguishing ILP32 objects
8589 from LP64 objects, so if there's any doubt, we should assume that
8590 the official LP64 form is being used. */
8591 if ((filedata
->file_header
.e_flags
& EF_MIPS_ABI
) == EF_MIPS_ABI_EABI64
8592 && find_section (filedata
, ".gcc_compiled_long32") == NULL
)
8598 switch (filedata
->file_header
.e_flags
& EF_H8_MACH
)
8600 case E_H8_MACH_H8300
:
8601 case E_H8_MACH_H8300HN
:
8602 case E_H8_MACH_H8300SN
:
8603 case E_H8_MACH_H8300SXN
:
8606 case E_H8_MACH_H8300H
:
8607 case E_H8_MACH_H8300S
:
8608 case E_H8_MACH_H8300SX
:
8616 switch (filedata
->file_header
.e_flags
& EF_M32C_CPU_MASK
)
8618 case EF_M32C_CPU_M16C
:
8625 #define CHECK_ENTSIZE_VALUES(section, i, size32, size64) \
8628 uint64_t expected_entsize = is_32bit_elf ? size32 : size64; \
8629 if (section->sh_entsize != expected_entsize) \
8631 error (_("Section %d has invalid sh_entsize of %" PRIx64 "\n"), \
8632 i, section->sh_entsize); \
8633 error (_("(Using the expected size of %" PRIx64 " for the rest of this dump)\n"), \
8634 expected_entsize); \
8635 section->sh_entsize = expected_entsize; \
8640 #define CHECK_ENTSIZE(section, i, type) \
8641 CHECK_ENTSIZE_VALUES (section, i, sizeof (Elf32_External_##type), \
8642 sizeof (Elf64_External_##type))
8644 for (i
= 0, section
= filedata
->section_headers
;
8645 i
< filedata
->file_header
.e_shnum
;
8648 const char *name
= printable_section_name (filedata
, section
);
8650 /* Run some sanity checks on the headers and
8651 possibly fill in some file data as well. */
8652 switch (section
->sh_type
)
8655 if (filedata
->dynamic_symbols
!= NULL
)
8657 error (_("File contains multiple dynamic symbol tables\n"));
8661 CHECK_ENTSIZE (section
, i
, Sym
);
8662 filedata
->dynamic_symbols
8663 = get_elf_symbols (filedata
, section
, &filedata
->num_dynamic_syms
);
8664 filedata
->dynamic_symtab_section
= section
;
8668 if (streq (name
, ".dynstr"))
8670 if (filedata
->dynamic_strings
!= NULL
)
8672 error (_("File contains multiple dynamic string tables\n"));
8676 filedata
->dynamic_strings
8677 = (char *) get_data (NULL
, filedata
, section
->sh_offset
,
8678 1, section
->sh_size
, _("dynamic strings"));
8679 filedata
->dynamic_strings_length
8680 = filedata
->dynamic_strings
== NULL
? 0 : section
->sh_size
;
8681 filedata
->dynamic_strtab_section
= section
;
8685 case SHT_SYMTAB_SHNDX
:
8687 elf_section_list
* entry
= xmalloc (sizeof * entry
);
8689 entry
->hdr
= section
;
8690 entry
->next
= filedata
->symtab_shndx_list
;
8691 filedata
->symtab_shndx_list
= entry
;
8696 CHECK_ENTSIZE (section
, i
, Sym
);
8700 CHECK_ENTSIZE_VALUES (section
, i
, GRP_ENTRY_SIZE
, GRP_ENTRY_SIZE
);
8704 CHECK_ENTSIZE (section
, i
, Rel
);
8705 if (do_checks
&& section
->sh_size
== 0)
8706 warn (_("Section '%s': zero-sized relocation section\n"), name
);
8710 CHECK_ENTSIZE (section
, i
, Rela
);
8711 if (do_checks
&& section
->sh_size
== 0)
8712 warn (_("Section '%s': zero-sized relocation section\n"), name
);
8716 CHECK_ENTSIZE (section
, i
, Relr
);
8721 case SHT_GNU_SFRAME
:
8722 /* Having a zero sized section is not illegal according to the
8723 ELF standard, but it might be an indication that something
8724 is wrong. So issue a warning if we are running in lint mode. */
8725 if (do_checks
&& section
->sh_size
== 0)
8726 warn (_("Section '%s': has a size of zero - is this intended ?\n"), name
);
8733 if ((do_debugging
|| do_debug_info
|| do_debug_abbrevs
8734 || do_debug_lines
|| do_debug_pubnames
|| do_debug_pubtypes
8735 || do_debug_aranges
|| do_debug_frames
|| do_debug_macinfo
8736 || do_debug_str
|| do_debug_str_offsets
|| do_debug_loc
8738 || do_debug_addr
|| do_debug_cu_index
|| do_debug_links
)
8739 && (startswith (name
, ".debug_")
8740 || startswith (name
, ".zdebug_")))
8743 name
+= sizeof (".zdebug_") - 1;
8745 name
+= sizeof (".debug_") - 1;
8748 || (do_debug_info
&& startswith (name
, "info"))
8749 || (do_debug_info
&& startswith (name
, "types"))
8750 || (do_debug_abbrevs
&& startswith (name
, "abbrev"))
8751 || (do_debug_lines
&& strcmp (name
, "line") == 0)
8752 || (do_debug_lines
&& startswith (name
, "line."))
8753 || (do_debug_pubnames
&& startswith (name
, "pubnames"))
8754 || (do_debug_pubtypes
&& startswith (name
, "pubtypes"))
8755 || (do_debug_pubnames
&& startswith (name
, "gnu_pubnames"))
8756 || (do_debug_pubtypes
&& startswith (name
, "gnu_pubtypes"))
8757 || (do_debug_aranges
&& startswith (name
, "aranges"))
8758 || (do_debug_ranges
&& startswith (name
, "ranges"))
8759 || (do_debug_ranges
&& startswith (name
, "rnglists"))
8760 || (do_debug_frames
&& startswith (name
, "frame"))
8761 || (do_debug_macinfo
&& startswith (name
, "macinfo"))
8762 || (do_debug_macinfo
&& startswith (name
, "macro"))
8763 || (do_debug_str
&& startswith (name
, "str"))
8764 || (do_debug_links
&& startswith (name
, "sup"))
8765 || (do_debug_str_offsets
&& startswith (name
, "str_offsets"))
8766 || (do_debug_loc
&& startswith (name
, "loc"))
8767 || (do_debug_loc
&& startswith (name
, "loclists"))
8768 || (do_debug_addr
&& startswith (name
, "addr"))
8769 || (do_debug_cu_index
&& startswith (name
, "cu_index"))
8770 || (do_debug_cu_index
&& startswith (name
, "tu_index"))
8772 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
8774 /* Linkonce section to be combined with .debug_info at link time. */
8775 else if ((do_debugging
|| do_debug_info
)
8776 && startswith (name
, ".gnu.linkonce.wi."))
8777 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
8778 else if (do_debug_frames
&& streq (name
, ".eh_frame"))
8779 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
8780 else if (do_debug_frames
&& streq (name
, ".eh_frame_hdr"))
8781 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
8782 else if (do_gdb_index
&& (streq (name
, ".gdb_index")
8783 || streq (name
, ".debug_names")))
8784 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
8785 /* Trace sections for Itanium VMS. */
8786 else if ((do_debugging
|| do_trace_info
|| do_trace_abbrevs
8787 || do_trace_aranges
)
8788 && startswith (name
, ".trace_"))
8790 name
+= sizeof (".trace_") - 1;
8793 || (do_trace_info
&& streq (name
, "info"))
8794 || (do_trace_abbrevs
&& streq (name
, "abbrev"))
8795 || (do_trace_aranges
&& streq (name
, "aranges"))
8797 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
8799 else if ((do_debugging
|| do_debug_links
)
8800 && (startswith (name
, ".gnu_debuglink")
8801 || startswith (name
, ".gnu_debugaltlink")))
8802 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
8808 if (filedata
->is_separate
&& ! process_links
)
8811 if (filedata
->is_separate
)
8812 printf (_("\nSection Headers in linked file '%s':\n"),
8813 printable_string (filedata
->file_name
, 0));
8814 else if (filedata
->file_header
.e_shnum
> 1)
8815 printf (_("\nSection Headers:\n"));
8817 printf (_("\nSection Header:\n"));
8821 if (do_section_details
)
8823 printf (_(" [Nr] Name\n"));
8824 printf (_(" Type Addr Off Size ES Lk Inf Al\n"));
8828 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
8832 if (do_section_details
)
8834 printf (_(" [Nr] Name\n"));
8835 printf (_(" Type Address Off Size ES Lk Inf Al\n"));
8839 (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n"));
8843 if (do_section_details
)
8845 printf (_(" [Nr] Name\n"));
8846 printf (_(" Type Address Offset Link\n"));
8847 printf (_(" Size EntSize Info Align\n"));
8851 printf (_(" [Nr] Name Type Address Offset\n"));
8852 printf (_(" Size EntSize Flags Link Info Align\n"));
8856 if (do_section_details
)
8857 printf (_(" Flags\n"));
8859 for (i
= 0, section
= filedata
->section_headers
;
8860 i
< filedata
->file_header
.e_shnum
;
8863 /* Run some sanity checks on the section header. */
8865 /* Check the sh_link field. */
8866 switch (section
->sh_type
)
8871 if (section
->sh_link
== 0
8872 && (filedata
->file_header
.e_type
== ET_EXEC
8873 || filedata
->file_header
.e_type
== ET_DYN
))
8874 /* A dynamic relocation section where all entries use a
8875 zero symbol index need not specify a symtab section. */
8878 case SHT_SYMTAB_SHNDX
:
8882 case SHT_GNU_versym
:
8883 if (section
->sh_link
== 0
8884 || section
->sh_link
>= filedata
->file_header
.e_shnum
8885 || (filedata
->section_headers
[section
->sh_link
].sh_type
!= SHT_SYMTAB
8886 && filedata
->section_headers
[section
->sh_link
].sh_type
!= SHT_DYNSYM
))
8887 warn (_("[%2u]: Link field (%u) should index a symtab section.\n"),
8888 i
, section
->sh_link
);
8894 case SHT_GNU_verneed
:
8895 case SHT_GNU_verdef
:
8896 case SHT_GNU_LIBLIST
:
8897 if (section
->sh_link
== 0
8898 || section
->sh_link
>= filedata
->file_header
.e_shnum
8899 || filedata
->section_headers
[section
->sh_link
].sh_type
!= SHT_STRTAB
)
8900 warn (_("[%2u]: Link field (%u) should index a string section.\n"),
8901 i
, section
->sh_link
);
8904 case SHT_INIT_ARRAY
:
8905 case SHT_FINI_ARRAY
:
8906 case SHT_PREINIT_ARRAY
:
8907 if (section
->sh_type
< SHT_LOOS
&& section
->sh_link
!= 0)
8908 warn (_("[%2u]: Unexpected value (%u) in link field.\n"),
8909 i
, section
->sh_link
);
8913 /* FIXME: Add support for target specific section types. */
8914 #if 0 /* Currently we do not check other section types as there are too
8915 many special cases. Stab sections for example have a type
8916 of SHT_PROGBITS but an sh_link field that links to the .stabstr
8918 if (section
->sh_type
< SHT_LOOS
&& section
->sh_link
!= 0)
8919 warn (_("[%2u]: Unexpected value (%u) in link field.\n"),
8920 i
, section
->sh_link
);
8925 /* Check the sh_info field. */
8926 switch (section
->sh_type
)
8930 if (section
->sh_info
== 0
8931 && (filedata
->file_header
.e_type
== ET_EXEC
8932 || filedata
->file_header
.e_type
== ET_DYN
))
8933 /* Dynamic relocations apply to segments, so they do not
8934 need to specify the section they relocate. */
8936 if (section
->sh_info
== 0
8937 || section
->sh_info
>= filedata
->file_header
.e_shnum
8938 || (filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_PROGBITS
8939 && filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_NOBITS
8940 && filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_NOTE
8941 && filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_INIT_ARRAY
8942 && filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_FINI_ARRAY
8943 && filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_PREINIT_ARRAY
8944 /* FIXME: Are other section types valid ? */
8945 && filedata
->section_headers
[section
->sh_info
].sh_type
< SHT_LOOS
))
8946 warn (_("[%2u]: Info field (%u) should index a relocatable section.\n"),
8947 i
, section
->sh_info
);
8952 case SHT_SYMTAB_SHNDX
:
8953 case SHT_INIT_ARRAY
:
8954 case SHT_FINI_ARRAY
:
8955 case SHT_PREINIT_ARRAY
:
8956 if (section
->sh_info
!= 0)
8957 warn (_("[%2u]: Unexpected value (%u) in info field.\n"),
8958 i
, section
->sh_info
);
8964 /* A symbol index - we assume that it is valid. */
8968 /* FIXME: Add support for target specific section types. */
8969 if (section
->sh_type
== SHT_NOBITS
)
8970 /* NOBITS section headers with non-zero sh_info fields can be
8971 created when a binary is stripped of everything but its debug
8972 information. The stripped sections have their headers
8973 preserved but their types set to SHT_NOBITS. So do not check
8974 this type of section. */
8976 else if (section
->sh_flags
& SHF_INFO_LINK
)
8978 if (section
->sh_info
< 1 || section
->sh_info
>= filedata
->file_header
.e_shnum
)
8979 warn (_("[%2u]: Expected link to another section in info field"), i
);
8981 else if (section
->sh_type
< SHT_LOOS
8982 && (section
->sh_flags
& SHF_GNU_MBIND
) == 0
8983 && section
->sh_info
!= 0)
8984 warn (_("[%2u]: Unexpected value (%u) in info field.\n"),
8985 i
, section
->sh_info
);
8989 /* Check the sh_size field. */
8990 if (section
->sh_size
> filedata
->file_size
8991 && section
->sh_type
!= SHT_NOBITS
8992 && section
->sh_type
!= SHT_NULL
8993 && section
->sh_type
< SHT_LOOS
)
8994 warn (_("Size of section %u is larger than the entire file!\n"), i
);
8996 printf (" [%2u] ", i
);
8997 if (do_section_details
)
8998 printf ("%s\n ", printable_section_name (filedata
, section
));
9000 print_symbol_name (-17, printable_section_name (filedata
, section
));
9002 printf (do_wide
? " %-15s " : " %-15.15s ",
9003 get_section_type_name (filedata
, section
->sh_type
));
9007 const char * link_too_big
= NULL
;
9009 print_vma (section
->sh_addr
, LONG_HEX
);
9011 printf ( " %6.6lx %6.6lx %2.2lx",
9012 (unsigned long) section
->sh_offset
,
9013 (unsigned long) section
->sh_size
,
9014 (unsigned long) section
->sh_entsize
);
9016 if (do_section_details
)
9017 fputs (" ", stdout
);
9019 printf (" %3s ", get_elf_section_flags (filedata
, section
->sh_flags
));
9021 if (section
->sh_link
>= filedata
->file_header
.e_shnum
)
9024 /* The sh_link value is out of range. Normally this indicates
9025 an error but it can have special values in Solaris binaries. */
9026 switch (filedata
->file_header
.e_machine
)
9033 case EM_OLD_SPARCV9
:
9034 case EM_SPARC32PLUS
:
9037 if (section
->sh_link
== (SHN_BEFORE
& 0xffff))
9038 link_too_big
= "BEFORE";
9039 else if (section
->sh_link
== (SHN_AFTER
& 0xffff))
9040 link_too_big
= "AFTER";
9047 if (do_section_details
)
9049 if (link_too_big
!= NULL
&& * link_too_big
)
9050 printf ("<%s> ", link_too_big
);
9052 printf ("%2u ", section
->sh_link
);
9053 printf ("%3u %2lu\n", section
->sh_info
,
9054 (unsigned long) section
->sh_addralign
);
9057 printf ("%2u %3u %2lu\n",
9060 (unsigned long) section
->sh_addralign
);
9062 if (link_too_big
&& ! * link_too_big
)
9063 warn (_("section %u: sh_link value of %u is larger than the number of sections\n"),
9064 i
, section
->sh_link
);
9068 print_vma (section
->sh_addr
, LONG_HEX
);
9070 if ((long) section
->sh_offset
== section
->sh_offset
)
9071 printf (" %6.6lx", (unsigned long) section
->sh_offset
);
9075 print_vma (section
->sh_offset
, LONG_HEX
);
9078 if ((unsigned long) section
->sh_size
== section
->sh_size
)
9079 printf (" %6.6lx", (unsigned long) section
->sh_size
);
9083 print_vma (section
->sh_size
, LONG_HEX
);
9086 if ((unsigned long) section
->sh_entsize
== section
->sh_entsize
)
9087 printf (" %2.2lx", (unsigned long) section
->sh_entsize
);
9091 print_vma (section
->sh_entsize
, LONG_HEX
);
9094 if (do_section_details
)
9095 fputs (" ", stdout
);
9097 printf (" %3s ", get_elf_section_flags (filedata
, section
->sh_flags
));
9099 printf ("%2u %3u ", section
->sh_link
, section
->sh_info
);
9101 if ((unsigned long) section
->sh_addralign
== section
->sh_addralign
)
9102 printf ("%2lu\n", (unsigned long) section
->sh_addralign
);
9105 print_vma (section
->sh_addralign
, DEC
);
9109 else if (do_section_details
)
9112 print_vma (section
->sh_addr
, LONG_HEX
);
9113 if ((long) section
->sh_offset
== section
->sh_offset
)
9114 printf (" %16.16lx", (unsigned long) section
->sh_offset
);
9118 print_vma (section
->sh_offset
, LONG_HEX
);
9120 printf (" %u\n ", section
->sh_link
);
9121 print_vma (section
->sh_size
, LONG_HEX
);
9123 print_vma (section
->sh_entsize
, LONG_HEX
);
9125 printf (" %-16u %lu\n",
9127 (unsigned long) section
->sh_addralign
);
9132 print_vma (section
->sh_addr
, LONG_HEX
);
9133 if ((long) section
->sh_offset
== section
->sh_offset
)
9134 printf (" %8.8lx", (unsigned long) section
->sh_offset
);
9138 print_vma (section
->sh_offset
, LONG_HEX
);
9141 print_vma (section
->sh_size
, LONG_HEX
);
9143 print_vma (section
->sh_entsize
, LONG_HEX
);
9145 printf (" %3s ", get_elf_section_flags (filedata
, section
->sh_flags
));
9147 printf (" %2u %3u %lu\n",
9150 (unsigned long) section
->sh_addralign
);
9153 if (do_section_details
)
9155 printf (" %s\n", get_elf_section_flags (filedata
, section
->sh_flags
));
9156 if ((section
->sh_flags
& SHF_COMPRESSED
) != 0)
9158 /* Minimum section size is 12 bytes for 32-bit compression
9159 header + 12 bytes for compressed data header. */
9160 unsigned char buf
[24];
9162 assert (sizeof (buf
) >= sizeof (Elf64_External_Chdr
));
9163 if (get_data (&buf
, filedata
, section
->sh_offset
, 1,
9164 sizeof (buf
), _("compression header")))
9166 Elf_Internal_Chdr chdr
;
9168 if (get_compression_header (&chdr
, buf
, sizeof (buf
)) == 0)
9169 printf (_(" [<corrupt>]\n"));
9172 if (chdr
.ch_type
== ch_compress_zlib
)
9174 else if (chdr
.ch_type
== ch_compress_zstd
)
9177 printf (_(" [<unknown>: 0x%x], "),
9179 print_vma (chdr
.ch_size
, LONG_HEX
);
9180 printf (", %lu\n", (unsigned long) chdr
.ch_addralign
);
9187 if (!do_section_details
)
9189 /* The ordering of the letters shown here matches the ordering of the
9190 corresponding SHF_xxx values, and hence the order in which these
9191 letters will be displayed to the user. */
9192 printf (_("Key to Flags:\n\
9193 W (write), A (alloc), X (execute), M (merge), S (strings), I (info),\n\
9194 L (link order), O (extra OS processing required), G (group), T (TLS),\n\
9195 C (compressed), x (unknown), o (OS specific), E (exclude),\n "));
9196 switch (filedata
->file_header
.e_ident
[EI_OSABI
])
9199 case ELFOSABI_FREEBSD
:
9200 printf (_("R (retain), "));
9203 printf (_("D (mbind), "));
9208 if (filedata
->file_header
.e_machine
== EM_X86_64
9209 || filedata
->file_header
.e_machine
== EM_L1OM
9210 || filedata
->file_header
.e_machine
== EM_K1OM
)
9211 printf (_("l (large), "));
9212 else if (filedata
->file_header
.e_machine
== EM_ARM
)
9213 printf (_("y (purecode), "));
9214 else if (filedata
->file_header
.e_machine
== EM_PPC
)
9215 printf (_("v (VLE), "));
9216 printf ("p (processor specific)\n");
9223 get_symtab (Filedata
* filedata
,
9224 Elf_Internal_Shdr
* symsec
,
9225 Elf_Internal_Sym
** symtab
,
9228 uint64_t * strtablen
)
9232 *symtab
= get_elf_symbols (filedata
, symsec
, nsyms
);
9234 if (*symtab
== NULL
)
9237 if (symsec
->sh_link
!= 0)
9239 Elf_Internal_Shdr
*strsec
;
9241 if (symsec
->sh_link
>= filedata
->file_header
.e_shnum
)
9243 error (_("Bad sh_link in symbol table section\n"));
9250 strsec
= filedata
->section_headers
+ symsec
->sh_link
;
9252 *strtab
= (char *) get_data (NULL
, filedata
, strsec
->sh_offset
,
9253 1, strsec
->sh_size
, _("string table"));
9254 if (*strtab
== NULL
)
9261 *strtablen
= strsec
->sh_size
;
9267 get_group_flags (unsigned int flags
)
9269 static char buff
[128];
9273 else if (flags
== GRP_COMDAT
)
9276 snprintf (buff
, sizeof buff
, "[0x%x: %s%s%s]",
9278 flags
& GRP_MASKOS
? _("<OS specific>") : "",
9279 flags
& GRP_MASKPROC
? _("<PROC specific>") : "",
9280 (flags
& ~(GRP_COMDAT
| GRP_MASKOS
| GRP_MASKPROC
)
9281 ? _("<unknown>") : ""));
9287 process_section_groups (Filedata
* filedata
)
9289 Elf_Internal_Shdr
* section
;
9291 struct group
* group
;
9292 Elf_Internal_Shdr
* symtab_sec
;
9293 Elf_Internal_Shdr
* strtab_sec
;
9294 Elf_Internal_Sym
* symtab
;
9299 /* Don't process section groups unless needed. */
9300 if (!do_unwind
&& !do_section_groups
)
9303 if (filedata
->file_header
.e_shnum
== 0)
9305 if (do_section_groups
)
9307 if (filedata
->is_separate
)
9308 printf (_("\nThere are no sections group in linked file '%s'.\n"),
9309 printable_string (filedata
->file_name
, 0));
9311 printf (_("\nThere are no section groups in this file.\n"));
9316 if (filedata
->section_headers
== NULL
)
9318 error (_("Section headers are not available!\n"));
9319 /* PR 13622: This can happen with a corrupt ELF header. */
9323 filedata
->section_headers_groups
9324 = (struct group
**) calloc (filedata
->file_header
.e_shnum
,
9325 sizeof (struct group
*));
9327 if (filedata
->section_headers_groups
== NULL
)
9329 error (_("Out of memory reading %u section group headers\n"),
9330 filedata
->file_header
.e_shnum
);
9334 /* Scan the sections for the group section. */
9335 filedata
->group_count
= 0;
9336 for (i
= 0, section
= filedata
->section_headers
;
9337 i
< filedata
->file_header
.e_shnum
;
9339 if (section
->sh_type
== SHT_GROUP
)
9340 filedata
->group_count
++;
9342 if (filedata
->group_count
== 0)
9344 if (do_section_groups
)
9346 if (filedata
->is_separate
)
9347 printf (_("\nThere are no section groups in linked file '%s'.\n"),
9348 printable_string (filedata
->file_name
, 0));
9350 printf (_("\nThere are no section groups in this file.\n"));
9356 filedata
->section_groups
= (struct group
*) calloc (filedata
->group_count
,
9357 sizeof (struct group
));
9359 if (filedata
->section_groups
== NULL
)
9361 error (_("Out of memory reading %zu groups\n"), filedata
->group_count
);
9372 if (filedata
->is_separate
)
9373 printf (_("Section groups in linked file '%s'\n"),
9374 printable_string (filedata
->file_name
, 0));
9376 for (i
= 0, section
= filedata
->section_headers
, group
= filedata
->section_groups
;
9377 i
< filedata
->file_header
.e_shnum
;
9380 if (section
->sh_type
== SHT_GROUP
)
9382 const char * name
= printable_section_name (filedata
, section
);
9383 const char * group_name
;
9384 unsigned char * start
;
9385 unsigned char * indices
;
9386 unsigned int entry
, j
, size
;
9387 Elf_Internal_Shdr
* sec
;
9388 Elf_Internal_Sym
* sym
;
9390 /* Get the symbol table. */
9391 if (section
->sh_link
>= filedata
->file_header
.e_shnum
9392 || ((sec
= filedata
->section_headers
+ section
->sh_link
)->sh_type
9395 error (_("Bad sh_link in group section `%s'\n"), name
);
9399 if (symtab_sec
!= sec
)
9403 symtab
= get_elf_symbols (filedata
, symtab_sec
, & num_syms
);
9408 error (_("Corrupt header in group section `%s'\n"), name
);
9412 if (section
->sh_info
>= num_syms
)
9414 error (_("Bad sh_info in group section `%s'\n"), name
);
9418 sym
= symtab
+ section
->sh_info
;
9420 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
9422 if (sym
->st_shndx
== 0
9423 || sym
->st_shndx
>= filedata
->file_header
.e_shnum
)
9425 error (_("Bad sh_info in group section `%s'\n"), name
);
9429 group_name
= printable_section_name (filedata
,
9430 filedata
->section_headers
9439 /* Get the string table. */
9440 if (symtab_sec
->sh_link
>= filedata
->file_header
.e_shnum
)
9448 != (sec
= filedata
->section_headers
+ symtab_sec
->sh_link
))
9453 strtab
= (char *) get_data (NULL
, filedata
, strtab_sec
->sh_offset
,
9454 1, strtab_sec
->sh_size
,
9456 strtab_size
= strtab
!= NULL
? strtab_sec
->sh_size
: 0;
9458 group_name
= sym
->st_name
< strtab_size
9459 ? strtab
+ sym
->st_name
: _("<corrupt>");
9462 /* PR 17531: file: loop. */
9463 if (section
->sh_entsize
> section
->sh_size
)
9465 error (_("Section %s has sh_entsize (%#" PRIx64
")"
9466 " which is larger than its size (%#" PRIx64
")\n"),
9467 printable_section_name (filedata
, section
),
9468 section
->sh_entsize
,
9473 start
= (unsigned char *) get_data (NULL
, filedata
, section
->sh_offset
,
9474 1, section
->sh_size
,
9480 size
= (section
->sh_size
/ section
->sh_entsize
) - 1;
9481 entry
= byte_get (indices
, 4);
9484 if (do_section_groups
)
9486 printf (_("\n%sgroup section [%5u] `%s' [%s] contains %u sections:\n"),
9487 get_group_flags (entry
), i
, name
, group_name
, size
);
9489 printf (_(" [Index] Name\n"));
9492 group
->group_index
= i
;
9494 for (j
= 0; j
< size
; j
++)
9496 struct group_list
* g
;
9498 entry
= byte_get (indices
, 4);
9501 if (entry
>= filedata
->file_header
.e_shnum
)
9503 static unsigned num_group_errors
= 0;
9505 if (num_group_errors
++ < 10)
9507 error (_("section [%5u] in group section [%5u] > maximum section [%5u]\n"),
9508 entry
, i
, filedata
->file_header
.e_shnum
- 1);
9509 if (num_group_errors
== 10)
9510 warn (_("Further error messages about overlarge group section indices suppressed\n"));
9515 if (filedata
->section_headers_groups
[entry
] != NULL
)
9519 static unsigned num_errs
= 0;
9521 if (num_errs
++ < 10)
9523 error (_("section [%5u] in group section [%5u] already in group section [%5u]\n"),
9525 filedata
->section_headers_groups
[entry
]->group_index
);
9527 warn (_("Further error messages about already contained group sections suppressed\n"));
9533 /* Intel C/C++ compiler may put section 0 in a
9534 section group. We just warn it the first time
9535 and ignore it afterwards. */
9536 static bool warned
= false;
9539 error (_("section 0 in group section [%5u]\n"),
9540 filedata
->section_headers_groups
[entry
]->group_index
);
9546 filedata
->section_headers_groups
[entry
] = group
;
9548 if (do_section_groups
)
9550 sec
= filedata
->section_headers
+ entry
;
9551 printf (" [%5u] %s\n", entry
, printable_section_name (filedata
, sec
));
9554 g
= (struct group_list
*) xmalloc (sizeof (struct group_list
));
9555 g
->section_index
= entry
;
9556 g
->next
= group
->root
;
9571 /* Data used to display dynamic fixups. */
9573 struct ia64_vms_dynfixup
9575 uint64_t needed_ident
; /* Library ident number. */
9576 uint64_t needed
; /* Index in the dstrtab of the library name. */
9577 uint64_t fixup_needed
; /* Index of the library. */
9578 uint64_t fixup_rela_cnt
; /* Number of fixups. */
9579 uint64_t fixup_rela_off
; /* Fixups offset in the dynamic segment. */
9582 /* Data used to display dynamic relocations. */
9584 struct ia64_vms_dynimgrela
9586 uint64_t img_rela_cnt
; /* Number of relocations. */
9587 uint64_t img_rela_off
; /* Reloc offset in the dynamic segment. */
9590 /* Display IA-64 OpenVMS dynamic fixups (used to dynamically link a shared
9594 dump_ia64_vms_dynamic_fixups (Filedata
* filedata
,
9595 struct ia64_vms_dynfixup
* fixup
,
9596 const char * strtab
,
9597 unsigned int strtab_sz
)
9599 Elf64_External_VMS_IMAGE_FIXUP
* imfs
;
9601 const char * lib_name
;
9603 imfs
= get_data (NULL
, filedata
,
9604 filedata
->dynamic_addr
+ fixup
->fixup_rela_off
,
9605 sizeof (*imfs
), fixup
->fixup_rela_cnt
,
9606 _("dynamic section image fixups"));
9610 if (fixup
->needed
< strtab_sz
)
9611 lib_name
= strtab
+ fixup
->needed
;
9614 warn (_("corrupt library name index of %#" PRIx64
9615 " found in dynamic entry"), fixup
->needed
);
9619 printf (_("\nImage fixups for needed library #%" PRId64
9620 ": %s - ident: %" PRIx64
"\n"),
9621 fixup
->fixup_needed
, lib_name
, fixup
->needed_ident
);
9623 (_("Seg Offset Type SymVec DataType\n"));
9625 for (i
= 0; i
< (size_t) fixup
->fixup_rela_cnt
; i
++)
9630 printf ("%3u ", (unsigned) BYTE_GET (imfs
[i
].fixup_seg
));
9631 printf ("%016" PRIx64
" ", BYTE_GET (imfs
[i
].fixup_offset
));
9632 type
= BYTE_GET (imfs
[i
].type
);
9633 rtype
= elf_ia64_reloc_type (type
);
9635 printf ("0x%08x ", type
);
9637 printf ("%-32s ", rtype
);
9638 printf ("%6u ", (unsigned) BYTE_GET (imfs
[i
].symvec_index
));
9639 printf ("0x%08x\n", (unsigned) BYTE_GET (imfs
[i
].data_type
));
9646 /* Display IA-64 OpenVMS dynamic relocations (used to relocate an image). */
9649 dump_ia64_vms_dynamic_relocs (Filedata
* filedata
, struct ia64_vms_dynimgrela
*imgrela
)
9651 Elf64_External_VMS_IMAGE_RELA
*imrs
;
9654 imrs
= get_data (NULL
, filedata
,
9655 filedata
->dynamic_addr
+ imgrela
->img_rela_off
,
9656 sizeof (*imrs
), imgrela
->img_rela_cnt
,
9657 _("dynamic section image relocations"));
9661 printf (_("\nImage relocs\n"));
9663 (_("Seg Offset Type Addend Seg Sym Off\n"));
9665 for (i
= 0; i
< (size_t) imgrela
->img_rela_cnt
; i
++)
9670 printf ("%3u ", (unsigned) BYTE_GET (imrs
[i
].rela_seg
));
9671 printf ("%08" PRIx64
" ", BYTE_GET (imrs
[i
].rela_offset
));
9672 type
= BYTE_GET (imrs
[i
].type
);
9673 rtype
= elf_ia64_reloc_type (type
);
9675 printf ("0x%08x ", type
);
9677 printf ("%-31s ", rtype
);
9678 print_vma (BYTE_GET (imrs
[i
].addend
), FULL_HEX
);
9679 printf ("%3u ", (unsigned) BYTE_GET (imrs
[i
].sym_seg
));
9680 printf ("%08" PRIx64
"\n", BYTE_GET (imrs
[i
].sym_offset
));
9687 /* Display IA-64 OpenVMS dynamic relocations and fixups. */
9690 process_ia64_vms_dynamic_relocs (Filedata
* filedata
)
9692 struct ia64_vms_dynfixup fixup
;
9693 struct ia64_vms_dynimgrela imgrela
;
9694 Elf_Internal_Dyn
*entry
;
9695 uint64_t strtab_off
= 0;
9696 uint64_t strtab_sz
= 0;
9697 char *strtab
= NULL
;
9700 memset (&fixup
, 0, sizeof (fixup
));
9701 memset (&imgrela
, 0, sizeof (imgrela
));
9703 /* Note: the order of the entries is specified by the OpenVMS specs. */
9704 for (entry
= filedata
->dynamic_section
;
9705 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
9708 switch (entry
->d_tag
)
9710 case DT_IA_64_VMS_STRTAB_OFFSET
:
9711 strtab_off
= entry
->d_un
.d_val
;
9714 strtab_sz
= entry
->d_un
.d_val
;
9716 strtab
= get_data (NULL
, filedata
,
9717 filedata
->dynamic_addr
+ strtab_off
,
9718 1, strtab_sz
, _("dynamic string section"));
9723 case DT_IA_64_VMS_NEEDED_IDENT
:
9724 fixup
.needed_ident
= entry
->d_un
.d_val
;
9727 fixup
.needed
= entry
->d_un
.d_val
;
9729 case DT_IA_64_VMS_FIXUP_NEEDED
:
9730 fixup
.fixup_needed
= entry
->d_un
.d_val
;
9732 case DT_IA_64_VMS_FIXUP_RELA_CNT
:
9733 fixup
.fixup_rela_cnt
= entry
->d_un
.d_val
;
9735 case DT_IA_64_VMS_FIXUP_RELA_OFF
:
9736 fixup
.fixup_rela_off
= entry
->d_un
.d_val
;
9737 if (! dump_ia64_vms_dynamic_fixups (filedata
, &fixup
, strtab
, strtab_sz
))
9740 case DT_IA_64_VMS_IMG_RELA_CNT
:
9741 imgrela
.img_rela_cnt
= entry
->d_un
.d_val
;
9743 case DT_IA_64_VMS_IMG_RELA_OFF
:
9744 imgrela
.img_rela_off
= entry
->d_un
.d_val
;
9745 if (! dump_ia64_vms_dynamic_relocs (filedata
, &imgrela
))
9764 relocation_type rel_type
;
9766 dynamic_relocations
[] =
9768 { "REL", DT_REL
, DT_RELSZ
, reltype_rel
},
9769 { "RELA", DT_RELA
, DT_RELASZ
, reltype_rela
},
9770 { "RELR", DT_RELR
, DT_RELRSZ
, reltype_relr
},
9771 { "PLT", DT_JMPREL
, DT_PLTRELSZ
, reltype_unknown
}
9774 static relocation_type
9775 rel_type_from_sh_type (unsigned int sh_type
)
9779 case SHT_RELA
: return reltype_rela
;
9780 case SHT_REL
: return reltype_rel
;
9781 case SHT_RELR
: return reltype_relr
;
9782 default: return reltype_unknown
;
9787 display_relocations (Elf_Internal_Shdr
* section
,
9788 Filedata
* filedata
,
9791 relocation_type rel_type
= rel_type_from_sh_type (section
->sh_type
);
9793 if (rel_type
== reltype_unknown
)
9796 uint64_t rel_size
= section
->sh_size
;
9803 if (filedata
->is_separate
)
9804 printf (_("\nIn linked file '%s' relocation section "),
9805 printable_string (filedata
->file_name
, 0));
9807 printf (_("\nRelocation section "));
9809 if (filedata
->string_table
== NULL
)
9810 printf ("%d", section
->sh_name
);
9812 printf ("'%s'", printable_section_name (filedata
, section
));
9815 uint64_t rel_offset
= section
->sh_offset
;
9816 uint64_t num_rela
= rel_size
/ section
->sh_entsize
;
9818 uint64_t *relrs
= NULL
;
9820 if (rel_type
== reltype_relr
)
9822 /* Just stating the 'number of entries' in a RELR section can be
9823 misleading, since this is not the number of locations relocated, but
9824 the number of words in the compressed RELR format. So also provide
9825 the number of locations affected. */
9827 num_reloc
= count_relr_relocations (filedata
, section
, &relrs
);
9831 printf (_(" at offset %#" PRIx64
), rel_offset
);
9832 printf (ngettext (" contains %" PRIu64
" entry which relocates",
9833 " contains %" PRIu64
" entries which relocate",
9834 num_rela
), num_rela
);
9835 printf (ngettext (" %" PRIu64
" location:\n",
9836 " %" PRIu64
" locations:\n",
9837 num_reloc
), num_reloc
);
9842 num_reloc
= num_rela
;
9844 printf (ngettext (" at offset %#" PRIx64
9845 " contains %" PRIu64
" entry:\n",
9846 " at offset %#" PRIx64
9847 " contains %" PRIu64
" entries:\n",
9849 rel_offset
, num_rela
);
9852 update_all_relocations (num_reloc
);
9854 Elf_Internal_Shdr
* symsec
;
9855 Elf_Internal_Sym
* symtab
= NULL
;
9857 uint64_t strtablen
= 0;
9858 char * strtab
= NULL
;
9860 if (section
->sh_link
== 0
9861 || section
->sh_link
>= filedata
->file_header
.e_shnum
)
9863 /* Symbol data not available.
9864 This can happen, especially with RELR relocs.
9865 See if there is a .symtab section present.
9866 If so then use it. */
9867 symsec
= find_section_by_name (filedata
, ".symtab");
9871 symsec
= filedata
->section_headers
+ section
->sh_link
;
9873 if (symsec
->sh_type
!= SHT_SYMTAB
9874 && symsec
->sh_type
!= SHT_DYNSYM
)
9882 && !get_symtab (filedata
, symsec
, &symtab
, &nsyms
, &strtab
, &strtablen
))
9890 if (rel_type
== reltype_relr
)
9892 res
= dump_relr_relocations (filedata
, section
->sh_size
,
9893 section
->sh_entsize
,
9896 symtab
, nsyms
, strtab
, strtablen
,
9901 res
= dump_relocations (filedata
, rel_offset
, rel_size
,
9902 symtab
, nsyms
, strtab
, strtablen
,
9905 ? false : symsec
->sh_type
== SHT_DYNSYM
,
9913 /* Process the reloc section. */
9916 process_relocs (Filedata
* filedata
)
9919 uint64_t rel_offset
;
9920 unsigned int rel_entsz
;
9922 if (!do_reloc
&& !do_got_section_contents
)
9925 if (do_using_dynamic
)
9927 relocation_type rel_type
;
9929 const char * entsz_name
;
9930 bool has_dynamic_reloc
;
9933 has_dynamic_reloc
= false;
9935 for (i
= 0; i
< ARRAY_SIZE (dynamic_relocations
); i
++)
9937 rel_size
= filedata
->dynamic_info
[dynamic_relocations
[i
].size
];
9942 has_dynamic_reloc
= true;
9944 rel_type
= dynamic_relocations
[i
].rel_type
;
9945 name
= dynamic_relocations
[i
].name
;
9946 rel_offset
= filedata
->dynamic_info
[dynamic_relocations
[i
].reloc
];
9948 if (rel_type
== reltype_unknown
)
9950 if (dynamic_relocations
[i
].reloc
!= DT_JMPREL
)
9952 switch (filedata
->dynamic_info
[DT_PLTREL
])
9955 rel_type
= reltype_rel
;
9958 rel_type
= reltype_rela
;
9968 rel_entsz
= filedata
->dynamic_info
[DT_RELENT
];
9969 entsz_name
= "DT_RELENT";
9972 rel_entsz
= filedata
->dynamic_info
[DT_RELAENT
];
9973 entsz_name
= "DT_RELAENT";
9976 rel_entsz
= filedata
->dynamic_info
[DT_RELRENT
];
9977 entsz_name
= "DT_RELRENT";
9983 if (filedata
->is_separate
)
9985 (_("\nIn linked file '%s' section '%s' at offset"
9986 "%#" PRIx64
" contains %" PRId64
" bytes:\n"),
9987 filedata
->file_name
, name
, rel_offset
, rel_size
);
9990 (_("\n'%s' relocation section at offset %#" PRIx64
9991 " contains %" PRId64
" bytes:\n"),
9992 name
, rel_offset
, rel_size
);
9995 if (rel_type
== reltype_relr
)
9996 dump_relr_relocations (filedata
,
9997 filedata
->dynamic_info
[DT_RELRSZ
],
9998 filedata
->dynamic_info
[DT_RELRENT
],
9999 filedata
->dynamic_info
[DT_RELR
],
10001 filedata
->dynamic_symbols
,
10002 filedata
->num_dynamic_syms
,
10003 filedata
->dynamic_strings
,
10004 filedata
->dynamic_strings_length
,
10008 if (rel_entsz
== 0)
10010 printf (_("<missing or corrupt dynamic tag: %s>\n"),
10015 update_all_relocations (rel_size
/ rel_entsz
);
10017 dump_relocations (filedata
,
10018 offset_from_vma (filedata
, rel_offset
,
10021 filedata
->dynamic_symbols
,
10022 filedata
->num_dynamic_syms
,
10023 filedata
->dynamic_strings
,
10024 filedata
->dynamic_strings_length
,
10025 rel_type
, true /* is_dynamic */,
10030 if (is_ia64_vms (filedata
)
10031 && process_ia64_vms_dynamic_relocs (filedata
))
10032 has_dynamic_reloc
= true;
10034 if (do_reloc
&& ! has_dynamic_reloc
)
10036 if (filedata
->is_separate
)
10037 printf (_("\nThere are no dynamic relocations in linked file '%s'.\n"),
10038 filedata
->file_name
);
10040 printf (_("\nThere are no dynamic relocations in this file.\n"));
10045 Elf_Internal_Shdr
* section
;
10047 bool found
= false;
10049 for (i
= 0, section
= filedata
->section_headers
;
10050 i
< filedata
->file_header
.e_shnum
;
10053 if (display_relocations (section
, filedata
, do_reloc
))
10057 if (do_reloc
&& ! found
)
10059 /* Users sometimes forget the -D option, so try to be helpful. */
10060 for (i
= 0; i
< ARRAY_SIZE (dynamic_relocations
); i
++)
10062 if (filedata
->dynamic_info
[dynamic_relocations
[i
].size
])
10064 if (filedata
->is_separate
)
10065 printf (_("\nThere are no static relocations in linked file '%s'."),
10066 filedata
->file_name
);
10068 printf (_("\nThere are no static relocations in this file."));
10069 printf (_("\nTo see the dynamic relocations add --use-dynamic to the command line.\n"));
10074 if (i
== ARRAY_SIZE (dynamic_relocations
))
10076 if (filedata
->is_separate
)
10077 printf (_("\nThere are no relocations in linked file '%s'.\n"),
10078 filedata
->file_name
);
10080 printf (_("\nThere are no relocations in this file.\n"));
10088 /* An absolute address consists of a section and an offset. If the
10089 section is NULL, the offset itself is the address, otherwise, the
10090 address equals to LOAD_ADDRESS(section) + offset. */
10094 unsigned short section
;
10098 /* Find the nearest symbol at or below ADDR. Returns the symbol
10099 name, if found, and the offset from the symbol to ADDR. */
10102 find_symbol_for_address (Filedata
*filedata
,
10103 Elf_Internal_Sym
*symtab
,
10105 const char *strtab
,
10106 uint64_t strtab_size
,
10107 struct absaddr addr
,
10108 const char **symname
,
10111 uint64_t dist
= 0x100000;
10112 Elf_Internal_Sym
* sym
;
10113 Elf_Internal_Sym
* beg
;
10114 Elf_Internal_Sym
* end
;
10115 Elf_Internal_Sym
* best
= NULL
;
10117 REMOVE_ARCH_BITS (addr
.offset
);
10119 end
= symtab
+ nsyms
;
10125 sym
= beg
+ (end
- beg
) / 2;
10127 value
= sym
->st_value
;
10128 REMOVE_ARCH_BITS (value
);
10130 if (sym
->st_name
!= 0
10131 && (addr
.section
== SHN_UNDEF
|| addr
.section
== sym
->st_shndx
)
10132 && addr
.offset
>= value
10133 && addr
.offset
- value
< dist
)
10136 dist
= addr
.offset
- value
;
10141 if (addr
.offset
< value
)
10149 *symname
= (best
->st_name
>= strtab_size
10150 ? _("<corrupt>") : strtab
+ best
->st_name
);
10156 *offset
= addr
.offset
;
10159 /* Process the unwind section. */
10161 #include "unwind-ia64.h"
10163 struct ia64_unw_table_entry
10165 struct absaddr start
;
10166 struct absaddr end
;
10167 struct absaddr info
;
10170 struct ia64_unw_aux_info
10172 struct ia64_unw_table_entry
* table
; /* Unwind table. */
10173 uint64_t table_len
; /* Length of unwind table. */
10174 unsigned char * info
; /* Unwind info. */
10175 uint64_t info_size
; /* Size of unwind info. */
10176 uint64_t info_addr
; /* Starting address of unwind info. */
10177 uint64_t seg_base
; /* Starting address of segment. */
10178 Elf_Internal_Sym
* symtab
; /* The symbol table. */
10179 uint64_t nsyms
; /* Number of symbols. */
10180 Elf_Internal_Sym
* funtab
; /* Sorted table of STT_FUNC symbols. */
10181 uint64_t nfuns
; /* Number of entries in funtab. */
10182 char * strtab
; /* The string table. */
10183 uint64_t strtab_size
; /* Size of string table. */
10187 dump_ia64_unwind (Filedata
* filedata
, struct ia64_unw_aux_info
* aux
)
10189 struct ia64_unw_table_entry
* tp
;
10194 aux
->funtab
= xmalloc (aux
->nsyms
* sizeof (Elf_Internal_Sym
));
10195 for (nfuns
= 0, j
= 0; j
< aux
->nsyms
; j
++)
10196 if (aux
->symtab
[j
].st_value
&& ELF_ST_TYPE (aux
->symtab
[j
].st_info
) == STT_FUNC
)
10197 aux
->funtab
[nfuns
++] = aux
->symtab
[j
];
10198 aux
->nfuns
= nfuns
;
10199 qsort (aux
->funtab
, aux
->nfuns
, sizeof (Elf_Internal_Sym
), symcmp
);
10201 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
10205 const unsigned char * dp
;
10206 const unsigned char * head
;
10207 const unsigned char * end
;
10208 const char * procname
;
10210 find_symbol_for_address (filedata
, aux
->funtab
, aux
->nfuns
, aux
->strtab
,
10211 aux
->strtab_size
, tp
->start
, &procname
, &offset
);
10213 fputs ("\n<", stdout
);
10217 fputs (procname
, stdout
);
10220 printf ("+%" PRIx64
, offset
);
10223 fputs (">: [", stdout
);
10224 print_vma (tp
->start
.offset
, PREFIX_HEX
);
10225 fputc ('-', stdout
);
10226 print_vma (tp
->end
.offset
, PREFIX_HEX
);
10227 printf ("], info at +0x%" PRIx64
"\n",
10228 tp
->info
.offset
- aux
->seg_base
);
10230 /* PR 17531: file: 86232b32. */
10231 if (aux
->info
== NULL
)
10234 offset
= tp
->info
.offset
;
10235 if (tp
->info
.section
)
10237 if (tp
->info
.section
>= filedata
->file_header
.e_shnum
)
10239 warn (_("Invalid section %u in table entry %td\n"),
10240 tp
->info
.section
, tp
- aux
->table
);
10244 offset
+= filedata
->section_headers
[tp
->info
.section
].sh_addr
;
10246 offset
-= aux
->info_addr
;
10247 /* PR 17531: file: 0997b4d1. */
10248 if (offset
>= aux
->info_size
10249 || aux
->info_size
- offset
< 8)
10251 warn (_("Invalid offset %" PRIx64
" in table entry %td\n"),
10252 tp
->info
.offset
, tp
- aux
->table
);
10257 head
= aux
->info
+ offset
;
10258 stamp
= byte_get ((unsigned char *) head
, sizeof (stamp
));
10260 printf (" v%u, flags=0x%lx (%s%s), len=%lu bytes\n",
10261 (unsigned) UNW_VER (stamp
),
10262 (unsigned long) ((stamp
& UNW_FLAG_MASK
) >> 32),
10263 UNW_FLAG_EHANDLER (stamp
) ? " ehandler" : "",
10264 UNW_FLAG_UHANDLER (stamp
) ? " uhandler" : "",
10265 (unsigned long) (eh_addr_size
* UNW_LENGTH (stamp
)));
10267 if (UNW_VER (stamp
) != 1)
10269 printf (_("\tUnknown version.\n"));
10274 end
= head
+ 8 + eh_addr_size
* UNW_LENGTH (stamp
);
10275 /* PR 17531: file: 16ceda89. */
10276 if (end
> aux
->info
+ aux
->info_size
)
10277 end
= aux
->info
+ aux
->info_size
;
10278 for (dp
= head
+ 8; dp
< end
;)
10279 dp
= unw_decode (dp
, in_body
, & in_body
, end
);
10282 free (aux
->funtab
);
10288 slurp_ia64_unwind_table (Filedata
* filedata
,
10289 struct ia64_unw_aux_info
* aux
,
10290 Elf_Internal_Shdr
* sec
)
10292 uint64_t size
, nrelas
, i
;
10293 Elf_Internal_Phdr
* seg
;
10294 struct ia64_unw_table_entry
* tep
;
10295 Elf_Internal_Shdr
* relsec
;
10296 Elf_Internal_Rela
* rela
;
10297 Elf_Internal_Rela
* rp
;
10298 unsigned char * table
;
10299 unsigned char * tp
;
10300 Elf_Internal_Sym
* sym
;
10301 const char * relname
;
10303 aux
->table_len
= 0;
10305 /* First, find the starting address of the segment that includes
10308 if (filedata
->file_header
.e_phnum
)
10310 if (! get_program_headers (filedata
))
10313 for (seg
= filedata
->program_headers
;
10314 seg
< filedata
->program_headers
+ filedata
->file_header
.e_phnum
;
10317 if (seg
->p_type
!= PT_LOAD
)
10320 if (sec
->sh_addr
>= seg
->p_vaddr
10321 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
10323 aux
->seg_base
= seg
->p_vaddr
;
10329 /* Second, build the unwind table from the contents of the unwind section: */
10330 size
= sec
->sh_size
;
10331 table
= (unsigned char *) get_data (NULL
, filedata
, sec
->sh_offset
, 1, size
,
10332 _("unwind table"));
10336 aux
->table_len
= size
/ (3 * eh_addr_size
);
10337 aux
->table
= (struct ia64_unw_table_entry
*)
10338 xcmalloc (aux
->table_len
, sizeof (aux
->table
[0]));
10341 for (tp
= table
; tp
<= table
+ size
- (3 * eh_addr_size
); ++tep
)
10343 tep
->start
.section
= SHN_UNDEF
;
10344 tep
->end
.section
= SHN_UNDEF
;
10345 tep
->info
.section
= SHN_UNDEF
;
10346 tep
->start
.offset
= byte_get (tp
, eh_addr_size
); tp
+= eh_addr_size
;
10347 tep
->end
.offset
= byte_get (tp
, eh_addr_size
); tp
+= eh_addr_size
;
10348 tep
->info
.offset
= byte_get (tp
, eh_addr_size
); tp
+= eh_addr_size
;
10349 tep
->start
.offset
+= aux
->seg_base
;
10350 tep
->end
.offset
+= aux
->seg_base
;
10351 tep
->info
.offset
+= aux
->seg_base
;
10355 /* Third, apply any relocations to the unwind table: */
10356 for (relsec
= filedata
->section_headers
;
10357 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
10360 if (relsec
->sh_type
!= SHT_RELA
10361 || relsec
->sh_info
>= filedata
->file_header
.e_shnum
10362 || filedata
->section_headers
+ relsec
->sh_info
!= sec
)
10365 if (!slurp_rela_relocs (filedata
, relsec
->sh_offset
, relsec
->sh_size
,
10370 aux
->table_len
= 0;
10374 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
10376 unsigned int sym_ndx
;
10377 unsigned int r_type
= get_reloc_type (filedata
, rp
->r_info
);
10378 relname
= elf_ia64_reloc_type (r_type
);
10380 /* PR 17531: file: 9fa67536. */
10381 if (relname
== NULL
)
10383 warn (_("Skipping unknown relocation type: %u\n"), r_type
);
10387 if (! startswith (relname
, "R_IA64_SEGREL"))
10389 warn (_("Skipping unexpected relocation type: %s\n"), relname
);
10393 i
= rp
->r_offset
/ (3 * eh_addr_size
);
10395 /* PR 17531: file: 5bc8d9bf. */
10396 if (i
>= aux
->table_len
)
10398 warn (_("Skipping reloc with overlarge offset: %#" PRIx64
"\n"),
10403 sym_ndx
= get_reloc_symindex (rp
->r_info
);
10404 if (sym_ndx
>= aux
->nsyms
)
10406 warn (_("Skipping reloc with invalid symbol index: %u\n"),
10410 sym
= aux
->symtab
+ sym_ndx
;
10412 switch (rp
->r_offset
/ eh_addr_size
% 3)
10415 aux
->table
[i
].start
.section
= sym
->st_shndx
;
10416 aux
->table
[i
].start
.offset
= rp
->r_addend
+ sym
->st_value
;
10419 aux
->table
[i
].end
.section
= sym
->st_shndx
;
10420 aux
->table
[i
].end
.offset
= rp
->r_addend
+ sym
->st_value
;
10423 aux
->table
[i
].info
.section
= sym
->st_shndx
;
10424 aux
->table
[i
].info
.offset
= rp
->r_addend
+ sym
->st_value
;
10438 ia64_process_unwind (Filedata
* filedata
)
10440 Elf_Internal_Shdr
* sec
;
10441 Elf_Internal_Shdr
* unwsec
= NULL
;
10442 uint64_t i
, unwcount
= 0, unwstart
= 0;
10443 struct ia64_unw_aux_info aux
;
10446 memset (& aux
, 0, sizeof (aux
));
10448 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
10450 if (sec
->sh_type
== SHT_SYMTAB
)
10454 error (_("Multiple symbol tables encountered\n"));
10460 if (!get_symtab (filedata
, sec
, &aux
.symtab
, &aux
.nsyms
,
10461 &aux
.strtab
, &aux
.strtab_size
))
10464 else if (sec
->sh_type
== SHT_IA_64_UNWIND
)
10469 printf (_("\nThere are no unwind sections in this file.\n"));
10471 while (unwcount
-- > 0)
10473 const char *suffix
;
10476 for (i
= unwstart
, sec
= filedata
->section_headers
+ unwstart
, unwsec
= NULL
;
10477 i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
10478 if (sec
->sh_type
== SHT_IA_64_UNWIND
)
10483 /* We have already counted the number of SHT_IA64_UNWIND
10484 sections so the loop above should never fail. */
10485 assert (unwsec
!= NULL
);
10488 len
= sizeof (ELF_STRING_ia64_unwind_once
) - 1;
10490 if ((unwsec
->sh_flags
& SHF_GROUP
) != 0)
10492 /* We need to find which section group it is in. */
10493 struct group_list
* g
;
10495 if (filedata
->section_headers_groups
== NULL
10496 || filedata
->section_headers_groups
[i
] == NULL
)
10497 i
= filedata
->file_header
.e_shnum
;
10500 g
= filedata
->section_headers_groups
[i
]->root
;
10502 for (; g
!= NULL
; g
= g
->next
)
10504 sec
= filedata
->section_headers
+ g
->section_index
;
10506 if (section_name_valid (filedata
, sec
)
10507 && streq (section_name (filedata
, sec
),
10508 ELF_STRING_ia64_unwind_info
))
10513 i
= filedata
->file_header
.e_shnum
;
10516 else if (section_name_valid (filedata
, unwsec
)
10517 && startswith (section_name (filedata
, unwsec
),
10518 ELF_STRING_ia64_unwind_once
))
10520 /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO. */
10521 len2
= sizeof (ELF_STRING_ia64_unwind_info_once
) - 1;
10522 suffix
= section_name (filedata
, unwsec
) + len
;
10523 for (i
= 0, sec
= filedata
->section_headers
;
10524 i
< filedata
->file_header
.e_shnum
;
10526 if (section_name_valid (filedata
, sec
)
10527 && startswith (section_name (filedata
, sec
),
10528 ELF_STRING_ia64_unwind_info_once
)
10529 && streq (section_name (filedata
, sec
) + len2
, suffix
))
10534 /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
10535 .IA_64.unwind or BAR -> .IA_64.unwind_info. */
10536 len
= sizeof (ELF_STRING_ia64_unwind
) - 1;
10537 len2
= sizeof (ELF_STRING_ia64_unwind_info
) - 1;
10539 if (section_name_valid (filedata
, unwsec
)
10540 && startswith (section_name (filedata
, unwsec
),
10541 ELF_STRING_ia64_unwind
))
10542 suffix
= section_name (filedata
, unwsec
) + len
;
10543 for (i
= 0, sec
= filedata
->section_headers
;
10544 i
< filedata
->file_header
.e_shnum
;
10546 if (section_name_valid (filedata
, sec
)
10547 && startswith (section_name (filedata
, sec
),
10548 ELF_STRING_ia64_unwind_info
)
10549 && streq (section_name (filedata
, sec
) + len2
, suffix
))
10553 if (i
== filedata
->file_header
.e_shnum
)
10555 printf (_("\nCould not find unwind info section for "));
10557 if (filedata
->string_table
== NULL
)
10558 printf ("%d", unwsec
->sh_name
);
10560 printf ("'%s'", printable_section_name (filedata
, unwsec
));
10564 aux
.info_addr
= sec
->sh_addr
;
10565 aux
.info
= (unsigned char *) get_data (NULL
, filedata
, sec
->sh_offset
, 1,
10568 aux
.info_size
= aux
.info
== NULL
? 0 : sec
->sh_size
;
10570 printf (_("\nUnwind section "));
10572 if (filedata
->string_table
== NULL
)
10573 printf ("%d", unwsec
->sh_name
);
10575 printf ("'%s'", printable_section_name (filedata
, unwsec
));
10577 printf (_(" at offset %#" PRIx64
" contains %" PRIu64
" entries:\n"),
10579 unwsec
->sh_size
/ (3 * eh_addr_size
));
10581 if (slurp_ia64_unwind_table (filedata
, & aux
, unwsec
)
10582 && aux
.table_len
> 0)
10583 dump_ia64_unwind (filedata
, & aux
);
10585 free ((char *) aux
.table
);
10586 free ((char *) aux
.info
);
10593 free ((char *) aux
.strtab
);
10598 struct hppa_unw_table_entry
10600 struct absaddr start
;
10601 struct absaddr end
;
10602 unsigned int Cannot_unwind
:1; /* 0 */
10603 unsigned int Millicode
:1; /* 1 */
10604 unsigned int Millicode_save_sr0
:1; /* 2 */
10605 unsigned int Region_description
:2; /* 3..4 */
10606 unsigned int reserved1
:1; /* 5 */
10607 unsigned int Entry_SR
:1; /* 6 */
10608 unsigned int Entry_FR
:4; /* Number saved 7..10 */
10609 unsigned int Entry_GR
:5; /* Number saved 11..15 */
10610 unsigned int Args_stored
:1; /* 16 */
10611 unsigned int Variable_Frame
:1; /* 17 */
10612 unsigned int Separate_Package_Body
:1; /* 18 */
10613 unsigned int Frame_Extension_Millicode
:1; /* 19 */
10614 unsigned int Stack_Overflow_Check
:1; /* 20 */
10615 unsigned int Two_Instruction_SP_Increment
:1; /* 21 */
10616 unsigned int Ada_Region
:1; /* 22 */
10617 unsigned int cxx_info
:1; /* 23 */
10618 unsigned int cxx_try_catch
:1; /* 24 */
10619 unsigned int sched_entry_seq
:1; /* 25 */
10620 unsigned int reserved2
:1; /* 26 */
10621 unsigned int Save_SP
:1; /* 27 */
10622 unsigned int Save_RP
:1; /* 28 */
10623 unsigned int Save_MRP_in_frame
:1; /* 29 */
10624 unsigned int extn_ptr_defined
:1; /* 30 */
10625 unsigned int Cleanup_defined
:1; /* 31 */
10627 unsigned int MPE_XL_interrupt_marker
:1; /* 0 */
10628 unsigned int HP_UX_interrupt_marker
:1; /* 1 */
10629 unsigned int Large_frame
:1; /* 2 */
10630 unsigned int Pseudo_SP_Set
:1; /* 3 */
10631 unsigned int reserved4
:1; /* 4 */
10632 unsigned int Total_frame_size
:27; /* 5..31 */
10635 struct hppa_unw_aux_info
10637 struct hppa_unw_table_entry
* table
; /* Unwind table. */
10638 uint64_t table_len
; /* Length of unwind table. */
10639 uint64_t seg_base
; /* Starting address of segment. */
10640 Elf_Internal_Sym
* symtab
; /* The symbol table. */
10641 uint64_t nsyms
; /* Number of symbols. */
10642 Elf_Internal_Sym
* funtab
; /* Sorted table of STT_FUNC symbols. */
10643 uint64_t nfuns
; /* Number of entries in funtab. */
10644 char * strtab
; /* The string table. */
10645 uint64_t strtab_size
; /* Size of string table. */
10649 dump_hppa_unwind (Filedata
* filedata
, struct hppa_unw_aux_info
* aux
)
10651 struct hppa_unw_table_entry
* tp
;
10655 aux
->funtab
= xmalloc (aux
->nsyms
* sizeof (Elf_Internal_Sym
));
10656 for (nfuns
= 0, j
= 0; j
< aux
->nsyms
; j
++)
10657 if (aux
->symtab
[j
].st_value
&& ELF_ST_TYPE (aux
->symtab
[j
].st_info
) == STT_FUNC
)
10658 aux
->funtab
[nfuns
++] = aux
->symtab
[j
];
10659 aux
->nfuns
= nfuns
;
10660 qsort (aux
->funtab
, aux
->nfuns
, sizeof (Elf_Internal_Sym
), symcmp
);
10662 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
10665 const char * procname
;
10667 find_symbol_for_address (filedata
, aux
->funtab
, aux
->nfuns
, aux
->strtab
,
10668 aux
->strtab_size
, tp
->start
, &procname
,
10671 fputs ("\n<", stdout
);
10675 fputs (procname
, stdout
);
10678 printf ("+%" PRIx64
, offset
);
10681 fputs (">: [", stdout
);
10682 print_vma (tp
->start
.offset
, PREFIX_HEX
);
10683 fputc ('-', stdout
);
10684 print_vma (tp
->end
.offset
, PREFIX_HEX
);
10687 #define PF(_m) if (tp->_m) printf (#_m " ");
10688 #define PV(_m) if (tp->_m) printf (#_m "=%d ", tp->_m);
10691 PF(Millicode_save_sr0
);
10692 /* PV(Region_description); */
10697 PF(Variable_Frame
);
10698 PF(Separate_Package_Body
);
10699 PF(Frame_Extension_Millicode
);
10700 PF(Stack_Overflow_Check
);
10701 PF(Two_Instruction_SP_Increment
);
10705 PF(sched_entry_seq
);
10708 PF(Save_MRP_in_frame
);
10709 PF(extn_ptr_defined
);
10710 PF(Cleanup_defined
);
10711 PF(MPE_XL_interrupt_marker
);
10712 PF(HP_UX_interrupt_marker
);
10715 PV(Total_frame_size
);
10722 free (aux
->funtab
);
10728 slurp_hppa_unwind_table (Filedata
* filedata
,
10729 struct hppa_unw_aux_info
* aux
,
10730 Elf_Internal_Shdr
* sec
)
10732 uint64_t size
, unw_ent_size
, nentries
, nrelas
, i
;
10733 Elf_Internal_Phdr
* seg
;
10734 struct hppa_unw_table_entry
* tep
;
10735 Elf_Internal_Shdr
* relsec
;
10736 Elf_Internal_Rela
* rela
;
10737 Elf_Internal_Rela
* rp
;
10738 unsigned char * table
;
10739 unsigned char * tp
;
10740 Elf_Internal_Sym
* sym
;
10741 const char * relname
;
10743 /* First, find the starting address of the segment that includes
10745 if (filedata
->file_header
.e_phnum
)
10747 if (! get_program_headers (filedata
))
10750 for (seg
= filedata
->program_headers
;
10751 seg
< filedata
->program_headers
+ filedata
->file_header
.e_phnum
;
10754 if (seg
->p_type
!= PT_LOAD
)
10757 if (sec
->sh_addr
>= seg
->p_vaddr
10758 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
10760 aux
->seg_base
= seg
->p_vaddr
;
10766 /* Second, build the unwind table from the contents of the unwind
10768 size
= sec
->sh_size
;
10769 table
= (unsigned char *) get_data (NULL
, filedata
, sec
->sh_offset
, 1, size
,
10770 _("unwind table"));
10775 nentries
= size
/ unw_ent_size
;
10776 size
= unw_ent_size
* nentries
;
10778 aux
->table_len
= nentries
;
10779 tep
= aux
->table
= (struct hppa_unw_table_entry
*)
10780 xcmalloc (nentries
, sizeof (aux
->table
[0]));
10782 for (tp
= table
; tp
< table
+ size
; tp
+= unw_ent_size
, ++tep
)
10784 unsigned int tmp1
, tmp2
;
10786 tep
->start
.section
= SHN_UNDEF
;
10787 tep
->end
.section
= SHN_UNDEF
;
10789 tep
->start
.offset
= byte_get ((unsigned char *) tp
+ 0, 4);
10790 tep
->end
.offset
= byte_get ((unsigned char *) tp
+ 4, 4);
10791 tmp1
= byte_get ((unsigned char *) tp
+ 8, 4);
10792 tmp2
= byte_get ((unsigned char *) tp
+ 12, 4);
10794 tep
->start
.offset
+= aux
->seg_base
;
10795 tep
->end
.offset
+= aux
->seg_base
;
10797 tep
->Cannot_unwind
= (tmp1
>> 31) & 0x1;
10798 tep
->Millicode
= (tmp1
>> 30) & 0x1;
10799 tep
->Millicode_save_sr0
= (tmp1
>> 29) & 0x1;
10800 tep
->Region_description
= (tmp1
>> 27) & 0x3;
10801 tep
->reserved1
= (tmp1
>> 26) & 0x1;
10802 tep
->Entry_SR
= (tmp1
>> 25) & 0x1;
10803 tep
->Entry_FR
= (tmp1
>> 21) & 0xf;
10804 tep
->Entry_GR
= (tmp1
>> 16) & 0x1f;
10805 tep
->Args_stored
= (tmp1
>> 15) & 0x1;
10806 tep
->Variable_Frame
= (tmp1
>> 14) & 0x1;
10807 tep
->Separate_Package_Body
= (tmp1
>> 13) & 0x1;
10808 tep
->Frame_Extension_Millicode
= (tmp1
>> 12) & 0x1;
10809 tep
->Stack_Overflow_Check
= (tmp1
>> 11) & 0x1;
10810 tep
->Two_Instruction_SP_Increment
= (tmp1
>> 10) & 0x1;
10811 tep
->Ada_Region
= (tmp1
>> 9) & 0x1;
10812 tep
->cxx_info
= (tmp1
>> 8) & 0x1;
10813 tep
->cxx_try_catch
= (tmp1
>> 7) & 0x1;
10814 tep
->sched_entry_seq
= (tmp1
>> 6) & 0x1;
10815 tep
->reserved2
= (tmp1
>> 5) & 0x1;
10816 tep
->Save_SP
= (tmp1
>> 4) & 0x1;
10817 tep
->Save_RP
= (tmp1
>> 3) & 0x1;
10818 tep
->Save_MRP_in_frame
= (tmp1
>> 2) & 0x1;
10819 tep
->extn_ptr_defined
= (tmp1
>> 1) & 0x1;
10820 tep
->Cleanup_defined
= tmp1
& 0x1;
10822 tep
->MPE_XL_interrupt_marker
= (tmp2
>> 31) & 0x1;
10823 tep
->HP_UX_interrupt_marker
= (tmp2
>> 30) & 0x1;
10824 tep
->Large_frame
= (tmp2
>> 29) & 0x1;
10825 tep
->Pseudo_SP_Set
= (tmp2
>> 28) & 0x1;
10826 tep
->reserved4
= (tmp2
>> 27) & 0x1;
10827 tep
->Total_frame_size
= tmp2
& 0x7ffffff;
10831 /* Third, apply any relocations to the unwind table. */
10832 for (relsec
= filedata
->section_headers
;
10833 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
10836 if (relsec
->sh_type
!= SHT_RELA
10837 || relsec
->sh_info
>= filedata
->file_header
.e_shnum
10838 || filedata
->section_headers
+ relsec
->sh_info
!= sec
)
10841 if (!slurp_rela_relocs (filedata
, relsec
->sh_offset
, relsec
->sh_size
,
10845 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
10847 unsigned int sym_ndx
;
10848 unsigned int r_type
= get_reloc_type (filedata
, rp
->r_info
);
10849 relname
= elf_hppa_reloc_type (r_type
);
10851 if (relname
== NULL
)
10853 warn (_("Skipping unknown relocation type: %u\n"), r_type
);
10857 /* R_PARISC_SEGREL32 or R_PARISC_SEGREL64. */
10858 if (! startswith (relname
, "R_PARISC_SEGREL"))
10860 warn (_("Skipping unexpected relocation type: %s\n"), relname
);
10864 i
= rp
->r_offset
/ unw_ent_size
;
10865 if (i
>= aux
->table_len
)
10867 warn (_("Skipping reloc with overlarge offset: %#" PRIx64
"\n"),
10872 sym_ndx
= get_reloc_symindex (rp
->r_info
);
10873 if (sym_ndx
>= aux
->nsyms
)
10875 warn (_("Skipping reloc with invalid symbol index: %u\n"),
10879 sym
= aux
->symtab
+ sym_ndx
;
10881 switch ((rp
->r_offset
% unw_ent_size
) / 4)
10884 aux
->table
[i
].start
.section
= sym
->st_shndx
;
10885 aux
->table
[i
].start
.offset
= sym
->st_value
+ rp
->r_addend
;
10888 aux
->table
[i
].end
.section
= sym
->st_shndx
;
10889 aux
->table
[i
].end
.offset
= sym
->st_value
+ rp
->r_addend
;
10903 hppa_process_unwind (Filedata
* filedata
)
10905 struct hppa_unw_aux_info aux
;
10906 Elf_Internal_Shdr
* unwsec
= NULL
;
10907 Elf_Internal_Shdr
* sec
;
10911 if (filedata
->string_table
== NULL
)
10914 memset (& aux
, 0, sizeof (aux
));
10916 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
10918 if (sec
->sh_type
== SHT_SYMTAB
)
10922 error (_("Multiple symbol tables encountered\n"));
10928 if (!get_symtab (filedata
, sec
, &aux
.symtab
, &aux
.nsyms
,
10929 &aux
.strtab
, &aux
.strtab_size
))
10932 else if (section_name_valid (filedata
, sec
)
10933 && streq (section_name (filedata
, sec
), ".PARISC.unwind"))
10938 printf (_("\nThere are no unwind sections in this file.\n"));
10940 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
10942 if (section_name_valid (filedata
, sec
)
10943 && streq (section_name (filedata
, sec
), ".PARISC.unwind"))
10945 uint64_t num_unwind
= sec
->sh_size
/ 16;
10947 printf (ngettext ("\nUnwind section '%s' at offset %#" PRIx64
" "
10948 "contains %" PRIu64
" entry:\n",
10949 "\nUnwind section '%s' at offset %#" PRIx64
" "
10950 "contains %" PRIu64
" entries:\n",
10952 printable_section_name (filedata
, sec
),
10956 if (! slurp_hppa_unwind_table (filedata
, &aux
, sec
))
10959 if (res
&& aux
.table_len
> 0)
10961 if (! dump_hppa_unwind (filedata
, &aux
))
10965 free ((char *) aux
.table
);
10971 free ((char *) aux
.strtab
);
10978 unsigned char * data
; /* The unwind data. */
10979 Elf_Internal_Shdr
* sec
; /* The cached unwind section header. */
10980 Elf_Internal_Rela
* rela
; /* The cached relocations for this section. */
10981 uint64_t nrelas
; /* The number of relocations. */
10982 unsigned int rel_type
; /* REL or RELA ? */
10983 Elf_Internal_Rela
* next_rela
; /* Cyclic pointer to the next reloc to process. */
10986 struct arm_unw_aux_info
10988 Filedata
* filedata
; /* The file containing the unwind sections. */
10989 Elf_Internal_Sym
* symtab
; /* The file's symbol table. */
10990 uint64_t nsyms
; /* Number of symbols. */
10991 Elf_Internal_Sym
* funtab
; /* Sorted table of STT_FUNC symbols. */
10992 uint64_t nfuns
; /* Number of these symbols. */
10993 char * strtab
; /* The file's string table. */
10994 uint64_t strtab_size
; /* Size of string table. */
10997 static const char *
10998 arm_print_vma_and_name (Filedata
* filedata
,
10999 struct arm_unw_aux_info
* aux
,
11001 struct absaddr addr
)
11003 const char *procname
;
11004 uint64_t sym_offset
;
11006 if (addr
.section
== SHN_UNDEF
)
11009 find_symbol_for_address (filedata
, aux
->funtab
, aux
->nfuns
, aux
->strtab
,
11010 aux
->strtab_size
, addr
, &procname
,
11013 print_vma (fn
, PREFIX_HEX
);
11017 fputs (" <", stdout
);
11018 fputs (procname
, stdout
);
11021 printf ("+0x%" PRIx64
, sym_offset
);
11022 fputc ('>', stdout
);
11029 arm_free_section (struct arm_section
*arm_sec
)
11031 free (arm_sec
->data
);
11032 free (arm_sec
->rela
);
11035 /* 1) If SEC does not match the one cached in ARM_SEC, then free the current
11036 cached section and install SEC instead.
11037 2) Locate the 32-bit word at WORD_OFFSET in unwind section SEC
11038 and return its valued in * WORDP, relocating if necessary.
11039 3) Update the NEXT_RELA field in ARM_SEC and store the section index and
11040 relocation's offset in ADDR.
11041 4) If SYM_NAME is non-NULL and a relocation was applied, record the offset
11042 into the string table of the symbol associated with the reloc. If no
11043 reloc was applied store -1 there.
11044 5) Return TRUE upon success, FALSE otherwise. */
11047 get_unwind_section_word (Filedata
* filedata
,
11048 struct arm_unw_aux_info
* aux
,
11049 struct arm_section
* arm_sec
,
11050 Elf_Internal_Shdr
* sec
,
11051 uint64_t word_offset
,
11052 unsigned int * wordp
,
11053 struct absaddr
* addr
,
11054 uint64_t * sym_name
)
11056 Elf_Internal_Rela
*rp
;
11057 Elf_Internal_Sym
*sym
;
11058 const char * relname
;
11062 if (sec
== NULL
|| arm_sec
== NULL
)
11065 addr
->section
= SHN_UNDEF
;
11068 if (sym_name
!= NULL
)
11069 *sym_name
= (uint64_t) -1;
11071 /* If necessary, update the section cache. */
11072 if (sec
!= arm_sec
->sec
)
11074 Elf_Internal_Shdr
*relsec
;
11076 arm_free_section (arm_sec
);
11078 arm_sec
->sec
= sec
;
11079 arm_sec
->data
= get_data (NULL
, aux
->filedata
, sec
->sh_offset
, 1,
11080 sec
->sh_size
, _("unwind data"));
11081 arm_sec
->rela
= NULL
;
11082 arm_sec
->nrelas
= 0;
11084 for (relsec
= filedata
->section_headers
;
11085 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
11088 if (relsec
->sh_info
>= filedata
->file_header
.e_shnum
11089 || filedata
->section_headers
+ relsec
->sh_info
!= sec
11090 /* PR 15745: Check the section type as well. */
11091 || (relsec
->sh_type
!= SHT_REL
11092 && relsec
->sh_type
!= SHT_RELA
))
11095 arm_sec
->rel_type
= relsec
->sh_type
;
11096 if (relsec
->sh_type
== SHT_REL
)
11098 if (!slurp_rel_relocs (aux
->filedata
, relsec
->sh_offset
,
11100 & arm_sec
->rela
, & arm_sec
->nrelas
))
11103 else /* relsec->sh_type == SHT_RELA */
11105 if (!slurp_rela_relocs (aux
->filedata
, relsec
->sh_offset
,
11107 & arm_sec
->rela
, & arm_sec
->nrelas
))
11113 arm_sec
->next_rela
= arm_sec
->rela
;
11116 /* If there is no unwind data we can do nothing. */
11117 if (arm_sec
->data
== NULL
)
11120 /* If the offset is invalid then fail. */
11121 if (/* PR 21343 *//* PR 18879 */
11123 || word_offset
> sec
->sh_size
- 4)
11126 /* Get the word at the required offset. */
11127 word
= byte_get (arm_sec
->data
+ word_offset
, 4);
11129 /* PR 17531: file: id:000001,src:001266+003044,op:splice,rep:128. */
11130 if (arm_sec
->rela
== NULL
)
11136 /* Look through the relocs to find the one that applies to the provided offset. */
11138 for (rp
= arm_sec
->next_rela
; rp
!= arm_sec
->rela
+ arm_sec
->nrelas
; rp
++)
11140 uint64_t prelval
, offset
;
11142 if (rp
->r_offset
> word_offset
&& !wrapped
)
11144 rp
= arm_sec
->rela
;
11147 if (rp
->r_offset
> word_offset
)
11150 if (rp
->r_offset
& 3)
11152 warn (_("Skipping unexpected relocation at offset %#" PRIx64
"\n"),
11157 if (rp
->r_offset
< word_offset
)
11160 /* PR 17531: file: 027-161405-0.004 */
11161 if (aux
->symtab
== NULL
)
11164 if (arm_sec
->rel_type
== SHT_REL
)
11166 offset
= word
& 0x7fffffff;
11167 if (offset
& 0x40000000)
11168 offset
|= ~ (uint64_t) 0x7fffffff;
11170 else if (arm_sec
->rel_type
== SHT_RELA
)
11171 offset
= rp
->r_addend
;
11174 error (_("Unknown section relocation type %d encountered\n"),
11175 arm_sec
->rel_type
);
11179 /* PR 17531 file: 027-1241568-0.004. */
11180 if (ELF32_R_SYM (rp
->r_info
) >= aux
->nsyms
)
11182 error (_("Bad symbol index in unwind relocation "
11183 "(%" PRIu64
" > %" PRIu64
")\n"),
11184 ELF32_R_SYM (rp
->r_info
), aux
->nsyms
);
11188 sym
= aux
->symtab
+ ELF32_R_SYM (rp
->r_info
);
11189 offset
+= sym
->st_value
;
11190 prelval
= offset
- (arm_sec
->sec
->sh_addr
+ rp
->r_offset
);
11192 /* Check that we are processing the expected reloc type. */
11193 if (filedata
->file_header
.e_machine
== EM_ARM
)
11195 relname
= elf_arm_reloc_type (ELF32_R_TYPE (rp
->r_info
));
11196 if (relname
== NULL
)
11198 warn (_("Skipping unknown ARM relocation type: %d\n"),
11199 (int) ELF32_R_TYPE (rp
->r_info
));
11203 if (streq (relname
, "R_ARM_NONE"))
11206 if (! streq (relname
, "R_ARM_PREL31"))
11208 warn (_("Skipping unexpected ARM relocation type %s\n"), relname
);
11212 else if (filedata
->file_header
.e_machine
== EM_TI_C6000
)
11214 relname
= elf_tic6x_reloc_type (ELF32_R_TYPE (rp
->r_info
));
11215 if (relname
== NULL
)
11217 warn (_("Skipping unknown C6000 relocation type: %d\n"),
11218 (int) ELF32_R_TYPE (rp
->r_info
));
11222 if (streq (relname
, "R_C6000_NONE"))
11225 if (! streq (relname
, "R_C6000_PREL31"))
11227 warn (_("Skipping unexpected C6000 relocation type %s\n"), relname
);
11235 /* This function currently only supports ARM and TI unwinders. */
11236 warn (_("Only TI and ARM unwinders are currently supported\n"));
11240 word
= (word
& ~ (uint64_t) 0x7fffffff) | (prelval
& 0x7fffffff);
11241 addr
->section
= sym
->st_shndx
;
11242 addr
->offset
= offset
;
11245 * sym_name
= sym
->st_name
;
11250 arm_sec
->next_rela
= rp
;
11255 static const char *tic6x_unwind_regnames
[16] =
11257 "A15", "B15", "B14", "B13", "B12", "B11", "B10", "B3",
11258 "A14", "A13", "A12", "A11", "A10",
11259 "[invalid reg 13]", "[invalid reg 14]", "[invalid reg 15]"
11263 decode_tic6x_unwind_regmask (unsigned int mask
)
11267 for (i
= 12; mask
; mask
>>= 1, i
--)
11271 fputs (tic6x_unwind_regnames
[i
], stdout
);
11273 fputs (", ", stdout
);
11279 if (remaining == 0 && more_words) \
11281 data_offset += 4; \
11282 if (! get_unwind_section_word (filedata, aux, data_arm_sec, data_sec, \
11283 data_offset, & word, & addr, NULL)) \
11289 #define GET_OP(OP) \
11294 (OP) = word >> 24; \
11299 printf (_("[Truncated opcode]\n")); \
11302 printf ("0x%02x ", OP)
11305 decode_arm_unwind_bytecode (Filedata
* filedata
,
11306 struct arm_unw_aux_info
* aux
,
11308 unsigned int remaining
,
11309 unsigned int more_words
,
11310 uint64_t data_offset
,
11311 Elf_Internal_Shdr
* data_sec
,
11312 struct arm_section
* data_arm_sec
)
11314 struct absaddr addr
;
11317 /* Decode the unwinding instructions. */
11320 unsigned int op
, op2
;
11323 if (remaining
== 0)
11329 printf (" 0x%02x ", op
);
11331 if ((op
& 0xc0) == 0x00)
11333 int offset
= ((op
& 0x3f) << 2) + 4;
11335 printf (" vsp = vsp + %d", offset
);
11337 else if ((op
& 0xc0) == 0x40)
11339 int offset
= ((op
& 0x3f) << 2) + 4;
11341 printf (" vsp = vsp - %d", offset
);
11343 else if ((op
& 0xf0) == 0x80)
11346 if (op
== 0x80 && op2
== 0)
11347 printf (_("Refuse to unwind"));
11350 unsigned int mask
= ((op
& 0x0f) << 8) | op2
;
11355 for (i
= 0; i
< 12; i
++)
11356 if (mask
& (1 << i
))
11362 printf ("r%d", 4 + i
);
11367 else if ((op
& 0xf0) == 0x90)
11369 if (op
== 0x9d || op
== 0x9f)
11370 printf (_(" [Reserved]"));
11372 printf (" vsp = r%d", op
& 0x0f);
11374 else if ((op
& 0xf0) == 0xa0)
11376 int end
= 4 + (op
& 0x07);
11381 for (i
= 4; i
<= end
; i
++)
11397 else if (op
== 0xb0)
11398 printf (_(" finish"));
11399 else if (op
== 0xb1)
11402 if (op2
== 0 || (op2
& 0xf0) != 0)
11403 printf (_("[Spare]"));
11406 unsigned int mask
= op2
& 0x0f;
11411 for (i
= 0; i
< 12; i
++)
11412 if (mask
& (1 << i
))
11423 else if (op
== 0xb2)
11425 unsigned char buf
[9];
11426 unsigned int i
, len
;
11429 for (i
= 0; i
< sizeof (buf
); i
++)
11432 if ((buf
[i
] & 0x80) == 0)
11435 if (i
== sizeof (buf
))
11437 error (_("corrupt change to vsp\n"));
11442 offset
= read_leb128 (buf
, buf
+ i
+ 1, false, &len
, NULL
);
11443 assert (len
== i
+ 1);
11444 offset
= offset
* 4 + 0x204;
11445 printf ("vsp = vsp + %" PRId64
, offset
);
11448 else if (op
== 0xb3 || op
== 0xc8 || op
== 0xc9)
11450 unsigned int first
, last
;
11456 first
= first
+ 16;
11457 printf ("pop {D%d", first
);
11459 printf ("-D%d", first
+ last
);
11462 else if (op
== 0xb4)
11463 printf (_(" pop {ra_auth_code}"));
11464 else if (op
== 0xb5)
11465 printf (_(" vsp as modifier for PAC validation"));
11466 else if ((op
& 0xf8) == 0xb8 || (op
& 0xf8) == 0xd0)
11468 unsigned int count
= op
& 0x07;
11470 printf ("pop {D8");
11472 printf ("-D%d", 8 + count
);
11475 else if (op
>= 0xc0 && op
<= 0xc5)
11477 unsigned int count
= op
& 0x07;
11479 printf (" pop {wR10");
11481 printf ("-wR%d", 10 + count
);
11484 else if (op
== 0xc6)
11486 unsigned int first
, last
;
11491 printf ("pop {wR%d", first
);
11493 printf ("-wR%d", first
+ last
);
11496 else if (op
== 0xc7)
11499 if (op2
== 0 || (op2
& 0xf0) != 0)
11500 printf (_("[Spare]"));
11503 unsigned int mask
= op2
& 0x0f;
11508 for (i
= 0; i
< 4; i
++)
11509 if (mask
& (1 << i
))
11515 printf ("wCGR%d", i
);
11522 printf (_(" [unsupported opcode]"));
11533 decode_tic6x_unwind_bytecode (Filedata
* filedata
,
11534 struct arm_unw_aux_info
* aux
,
11536 unsigned int remaining
,
11537 unsigned int more_words
,
11538 uint64_t data_offset
,
11539 Elf_Internal_Shdr
* data_sec
,
11540 struct arm_section
* data_arm_sec
)
11542 struct absaddr addr
;
11544 /* Decode the unwinding instructions. */
11547 unsigned int op
, op2
;
11550 if (remaining
== 0)
11556 printf (" 0x%02x ", op
);
11558 if ((op
& 0xc0) == 0x00)
11560 int offset
= ((op
& 0x3f) << 3) + 8;
11561 printf (" sp = sp + %d", offset
);
11563 else if ((op
& 0xc0) == 0x80)
11566 if (op
== 0x80 && op2
== 0)
11567 printf (_("Refuse to unwind"));
11570 unsigned int mask
= ((op
& 0x1f) << 8) | op2
;
11572 printf ("pop compact {");
11576 decode_tic6x_unwind_regmask (mask
);
11580 else if ((op
& 0xf0) == 0xc0)
11583 unsigned int nregs
;
11588 unsigned int offset
;
11592 /* Scan entire instruction first so that GET_OP output is not
11593 interleaved with disassembly. */
11595 for (i
= 0; nregs
< (op
& 0xf); i
++)
11601 regpos
[nregs
].offset
= i
* 2;
11602 regpos
[nregs
].reg
= reg
;
11609 regpos
[nregs
].offset
= i
* 2 + 1;
11610 regpos
[nregs
].reg
= reg
;
11615 printf (_("pop frame {"));
11618 printf (_("*corrupt* - no registers specified"));
11623 for (i
= i
* 2; i
> 0; i
--)
11625 if (regpos
[reg
].offset
== i
- 1)
11627 name
= tic6x_unwind_regnames
[regpos
[reg
].reg
];
11634 fputs (name
, stdout
);
11642 else if (op
== 0xd0)
11643 printf (" MOV FP, SP");
11644 else if (op
== 0xd1)
11645 printf (" __c6xabi_pop_rts");
11646 else if (op
== 0xd2)
11648 unsigned char buf
[9];
11649 unsigned int i
, len
;
11652 for (i
= 0; i
< sizeof (buf
); i
++)
11655 if ((buf
[i
] & 0x80) == 0)
11658 /* PR 17531: file: id:000001,src:001906+004739,op:splice,rep:2. */
11659 if (i
== sizeof (buf
))
11661 warn (_("Corrupt stack pointer adjustment detected\n"));
11665 offset
= read_leb128 (buf
, buf
+ i
+ 1, false, &len
, NULL
);
11666 assert (len
== i
+ 1);
11667 offset
= offset
* 8 + 0x408;
11668 printf (_("sp = sp + %" PRId64
), offset
);
11670 else if ((op
& 0xf0) == 0xe0)
11672 if ((op
& 0x0f) == 7)
11673 printf (" RETURN");
11675 printf (" MV %s, B3", tic6x_unwind_regnames
[op
& 0x0f]);
11679 printf (_(" [unsupported opcode]"));
11688 arm_expand_prel31 (Filedata
* filedata
, uint64_t word
, uint64_t where
)
11692 offset
= word
& 0x7fffffff;
11693 if (offset
& 0x40000000)
11694 offset
|= ~ (uint64_t) 0x7fffffff;
11696 if (filedata
->file_header
.e_machine
== EM_TI_C6000
)
11699 return offset
+ where
;
11703 decode_arm_unwind (Filedata
* filedata
,
11704 struct arm_unw_aux_info
* aux
,
11706 unsigned int remaining
,
11707 uint64_t data_offset
,
11708 Elf_Internal_Shdr
* data_sec
,
11709 struct arm_section
* data_arm_sec
)
11712 unsigned int more_words
= 0;
11713 struct absaddr addr
;
11714 uint64_t sym_name
= (uint64_t) -1;
11717 if (remaining
== 0)
11719 /* Fetch the first word.
11720 Note - when decoding an object file the address extracted
11721 here will always be 0. So we also pass in the sym_name
11722 parameter so that we can find the symbol associated with
11723 the personality routine. */
11724 if (! get_unwind_section_word (filedata
, aux
, data_arm_sec
, data_sec
, data_offset
,
11725 & word
, & addr
, & sym_name
))
11732 addr
.section
= SHN_UNDEF
;
11736 if ((word
& 0x80000000) == 0)
11738 /* Expand prel31 for personality routine. */
11740 const char *procname
;
11742 fn
= arm_expand_prel31 (filedata
, word
, data_sec
->sh_addr
+ data_offset
);
11743 printf (_(" Personality routine: "));
11745 && addr
.section
== SHN_UNDEF
&& addr
.offset
== 0
11746 && sym_name
!= (uint64_t) -1 && sym_name
< aux
->strtab_size
)
11748 procname
= aux
->strtab
+ sym_name
;
11749 print_vma (fn
, PREFIX_HEX
);
11752 fputs (" <", stdout
);
11753 fputs (procname
, stdout
);
11754 fputc ('>', stdout
);
11758 procname
= arm_print_vma_and_name (filedata
, aux
, fn
, addr
);
11759 fputc ('\n', stdout
);
11761 /* The GCC personality routines use the standard compact
11762 encoding, starting with one byte giving the number of
11764 if (procname
!= NULL
11765 && (startswith (procname
, "__gcc_personality_v0")
11766 || startswith (procname
, "__gxx_personality_v0")
11767 || startswith (procname
, "__gcj_personality_v0")
11768 || startswith (procname
, "__gnu_objc_personality_v0")))
11775 printf (_(" [Truncated data]\n"));
11778 more_words
= word
>> 24;
11788 /* ARM EHABI Section 6.3:
11790 An exception-handling table entry for the compact model looks like:
11792 31 30-28 27-24 23-0
11793 -- ----- ----- ----
11794 1 0 index Data for personalityRoutine[index] */
11796 if (filedata
->file_header
.e_machine
== EM_ARM
11797 && (word
& 0x70000000))
11799 warn (_("Corrupt ARM compact model table entry: %x \n"), word
);
11803 per_index
= (word
>> 24) & 0x7f;
11804 printf (_(" Compact model index: %d\n"), per_index
);
11805 if (per_index
== 0)
11811 else if (per_index
< 3)
11813 more_words
= (word
>> 16) & 0xff;
11819 switch (filedata
->file_header
.e_machine
)
11824 if (! decode_arm_unwind_bytecode (filedata
, aux
, word
, remaining
, more_words
,
11825 data_offset
, data_sec
, data_arm_sec
))
11830 warn (_("Unknown ARM compact model index encountered\n"));
11831 printf (_(" [reserved]\n"));
11839 if (! decode_tic6x_unwind_bytecode (filedata
, aux
, word
, remaining
, more_words
,
11840 data_offset
, data_sec
, data_arm_sec
))
11843 else if (per_index
< 5)
11845 if (((word
>> 17) & 0x7f) == 0x7f)
11846 printf (_(" Restore stack from frame pointer\n"));
11848 printf (_(" Stack increment %d\n"), (word
>> 14) & 0x1fc);
11849 printf (_(" Registers restored: "));
11850 if (per_index
== 4)
11851 printf (" (compact) ");
11852 decode_tic6x_unwind_regmask ((word
>> 4) & 0x1fff);
11854 printf (_(" Return register: %s\n"),
11855 tic6x_unwind_regnames
[word
& 0xf]);
11858 printf (_(" [reserved (%d)]\n"), per_index
);
11862 error (_("Unsupported architecture type %d encountered when decoding unwind table\n"),
11863 filedata
->file_header
.e_machine
);
11867 /* Decode the descriptors. Not implemented. */
11873 dump_arm_unwind (Filedata
* filedata
,
11874 struct arm_unw_aux_info
* aux
,
11875 Elf_Internal_Shdr
* exidx_sec
)
11877 struct arm_section exidx_arm_sec
, extab_arm_sec
;
11878 unsigned int i
, exidx_len
;
11882 memset (&exidx_arm_sec
, 0, sizeof (exidx_arm_sec
));
11883 memset (&extab_arm_sec
, 0, sizeof (extab_arm_sec
));
11884 exidx_len
= exidx_sec
->sh_size
/ 8;
11886 aux
->funtab
= xmalloc (aux
->nsyms
* sizeof (Elf_Internal_Sym
));
11887 for (nfuns
= 0, j
= 0; j
< aux
->nsyms
; j
++)
11888 if (aux
->symtab
[j
].st_value
&& ELF_ST_TYPE (aux
->symtab
[j
].st_info
) == STT_FUNC
)
11889 aux
->funtab
[nfuns
++] = aux
->symtab
[j
];
11890 aux
->nfuns
= nfuns
;
11891 qsort (aux
->funtab
, aux
->nfuns
, sizeof (Elf_Internal_Sym
), symcmp
);
11893 for (i
= 0; i
< exidx_len
; i
++)
11895 unsigned int exidx_fn
, exidx_entry
;
11896 struct absaddr fn_addr
, entry_addr
;
11899 fputc ('\n', stdout
);
11901 if (! get_unwind_section_word (filedata
, aux
, & exidx_arm_sec
, exidx_sec
,
11902 8 * i
, & exidx_fn
, & fn_addr
, NULL
)
11903 || ! get_unwind_section_word (filedata
, aux
, & exidx_arm_sec
, exidx_sec
,
11904 8 * i
+ 4, & exidx_entry
, & entry_addr
, NULL
))
11906 free (aux
->funtab
);
11907 arm_free_section (& exidx_arm_sec
);
11908 arm_free_section (& extab_arm_sec
);
11912 /* ARM EHABI, Section 5:
11913 An index table entry consists of 2 words.
11914 The first word contains a prel31 offset to the start of a function, with bit 31 clear. */
11915 if (exidx_fn
& 0x80000000)
11917 warn (_("corrupt index table entry: %x\n"), exidx_fn
);
11921 fn
= arm_expand_prel31 (filedata
, exidx_fn
, exidx_sec
->sh_addr
+ 8 * i
);
11923 arm_print_vma_and_name (filedata
, aux
, fn
, fn_addr
);
11924 fputs (": ", stdout
);
11926 if (exidx_entry
== 1)
11928 print_vma (exidx_entry
, PREFIX_HEX
);
11929 fputs (" [cantunwind]\n", stdout
);
11931 else if (exidx_entry
& 0x80000000)
11933 print_vma (exidx_entry
, PREFIX_HEX
);
11934 fputc ('\n', stdout
);
11935 decode_arm_unwind (filedata
, aux
, exidx_entry
, 4, 0, NULL
, NULL
);
11939 uint64_t table
, table_offset
= 0;
11940 Elf_Internal_Shdr
*table_sec
;
11942 fputs ("@", stdout
);
11943 table
= arm_expand_prel31 (filedata
, exidx_entry
, exidx_sec
->sh_addr
+ 8 * i
+ 4);
11944 print_vma (table
, PREFIX_HEX
);
11947 /* Locate the matching .ARM.extab. */
11948 if (entry_addr
.section
!= SHN_UNDEF
11949 && entry_addr
.section
< filedata
->file_header
.e_shnum
)
11951 table_sec
= filedata
->section_headers
+ entry_addr
.section
;
11952 table_offset
= entry_addr
.offset
;
11954 if (table_offset
> table_sec
->sh_size
)
11956 warn (_("Unwind entry contains corrupt offset (%#" PRIx64
") into section %s\n"),
11958 printable_section_name (filedata
, table_sec
));
11965 table_sec
= find_section_by_address (filedata
, table
);
11966 if (table_sec
!= NULL
)
11967 table_offset
= table
- table_sec
->sh_addr
;
11970 if (table_sec
== NULL
)
11972 warn (_("Could not locate .ARM.extab section containing %#" PRIx64
".\n"),
11978 if (! decode_arm_unwind (filedata
, aux
, 0, 0, table_offset
, table_sec
,
11986 free (aux
->funtab
);
11987 arm_free_section (&exidx_arm_sec
);
11988 arm_free_section (&extab_arm_sec
);
11993 /* Used for both ARM and C6X unwinding tables. */
11996 arm_process_unwind (Filedata
* filedata
)
11998 struct arm_unw_aux_info aux
;
11999 Elf_Internal_Shdr
*unwsec
= NULL
;
12000 Elf_Internal_Shdr
*sec
;
12002 unsigned int sec_type
;
12005 switch (filedata
->file_header
.e_machine
)
12008 sec_type
= SHT_ARM_EXIDX
;
12012 sec_type
= SHT_C6000_UNWIND
;
12016 error (_("Unsupported architecture type %d encountered when processing unwind table\n"),
12017 filedata
->file_header
.e_machine
);
12021 if (filedata
->string_table
== NULL
)
12024 memset (& aux
, 0, sizeof (aux
));
12025 aux
.filedata
= filedata
;
12027 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
12029 if (sec
->sh_type
== SHT_SYMTAB
)
12033 error (_("Multiple symbol tables encountered\n"));
12039 if (!get_symtab (filedata
, sec
, &aux
.symtab
, &aux
.nsyms
,
12040 &aux
.strtab
, &aux
.strtab_size
))
12043 else if (sec
->sh_type
== sec_type
)
12047 if (unwsec
== NULL
)
12048 printf (_("\nThere are no unwind sections in this file.\n"));
12050 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
12052 if (sec
->sh_type
== sec_type
)
12054 uint64_t num_unwind
= sec
->sh_size
/ (2 * eh_addr_size
);
12055 printf (ngettext ("\nUnwind section '%s' at offset %#" PRIx64
" "
12056 "contains %" PRIu64
" entry:\n",
12057 "\nUnwind section '%s' at offset %#" PRIx64
" "
12058 "contains %" PRIu64
" entries:\n",
12060 printable_section_name (filedata
, sec
),
12064 if (! dump_arm_unwind (filedata
, &aux
, sec
))
12070 free ((char *) aux
.strtab
);
12076 no_processor_specific_unwind (Filedata
* filedata ATTRIBUTE_UNUSED
)
12078 printf (_("No processor specific unwind information to decode\n"));
12083 process_unwind (Filedata
* filedata
)
12085 struct unwind_handler
12087 unsigned int machtype
;
12088 bool (* handler
)(Filedata
*);
12091 { EM_ARM
, arm_process_unwind
},
12092 { EM_IA_64
, ia64_process_unwind
},
12093 { EM_PARISC
, hppa_process_unwind
},
12094 { EM_TI_C6000
, arm_process_unwind
},
12095 { EM_386
, no_processor_specific_unwind
},
12096 { EM_X86_64
, no_processor_specific_unwind
},
12104 for (i
= 0; handlers
[i
].handler
!= NULL
; i
++)
12105 if (filedata
->file_header
.e_machine
== handlers
[i
].machtype
)
12106 return handlers
[i
].handler (filedata
);
12108 printf (_("\nThe decoding of unwind sections for machine type %s is not currently supported.\n"),
12109 get_machine_name (filedata
->file_header
.e_machine
));
12114 dynamic_section_aarch64_val (Elf_Internal_Dyn
* entry
)
12116 switch (entry
->d_tag
)
12118 case DT_AARCH64_BTI_PLT
:
12119 case DT_AARCH64_PAC_PLT
:
12122 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
12129 dynamic_section_mips_val (Filedata
* filedata
, Elf_Internal_Dyn
* entry
)
12131 switch (entry
->d_tag
)
12133 case DT_MIPS_FLAGS
:
12134 if (entry
->d_un
.d_val
== 0)
12135 printf (_("NONE"));
12138 static const char * opts
[] =
12140 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
12141 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
12142 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
12143 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
12149 for (cnt
= 0; cnt
< ARRAY_SIZE (opts
); ++cnt
)
12150 if (entry
->d_un
.d_val
& (1 << cnt
))
12152 printf ("%s%s", first
? "" : " ", opts
[cnt
]);
12158 case DT_MIPS_IVERSION
:
12159 if (valid_dynamic_name (filedata
, entry
->d_un
.d_val
))
12160 printf (_("Interface Version: %s"),
12161 get_dynamic_name (filedata
, entry
->d_un
.d_val
));
12163 printf (_("Interface Version: <corrupt: %" PRIx64
">"),
12164 entry
->d_un
.d_ptr
);
12167 case DT_MIPS_TIME_STAMP
:
12171 time_t atime
= entry
->d_un
.d_val
;
12173 tmp
= gmtime (&atime
);
12174 /* PR 17531: file: 6accc532. */
12176 snprintf (timebuf
, sizeof (timebuf
), _("<corrupt>"));
12178 snprintf (timebuf
, sizeof (timebuf
), "%04u-%02u-%02uT%02u:%02u:%02u",
12179 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
12180 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
12181 printf (_("Time Stamp: %s"), timebuf
);
12185 case DT_MIPS_RLD_VERSION
:
12186 case DT_MIPS_LOCAL_GOTNO
:
12187 case DT_MIPS_CONFLICTNO
:
12188 case DT_MIPS_LIBLISTNO
:
12189 case DT_MIPS_SYMTABNO
:
12190 case DT_MIPS_UNREFEXTNO
:
12191 case DT_MIPS_HIPAGENO
:
12192 case DT_MIPS_DELTA_CLASS_NO
:
12193 case DT_MIPS_DELTA_INSTANCE_NO
:
12194 case DT_MIPS_DELTA_RELOC_NO
:
12195 case DT_MIPS_DELTA_SYM_NO
:
12196 case DT_MIPS_DELTA_CLASSSYM_NO
:
12197 case DT_MIPS_COMPACT_SIZE
:
12198 print_vma (entry
->d_un
.d_val
, DEC
);
12201 case DT_MIPS_XHASH
:
12202 filedata
->dynamic_info_DT_MIPS_XHASH
= entry
->d_un
.d_val
;
12203 filedata
->dynamic_info_DT_GNU_HASH
= entry
->d_un
.d_val
;
12204 /* Falls through. */
12207 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
12213 dynamic_section_parisc_val (Elf_Internal_Dyn
* entry
)
12215 switch (entry
->d_tag
)
12217 case DT_HP_DLD_FLAGS
:
12226 { DT_HP_DEBUG_PRIVATE
, "HP_DEBUG_PRIVATE" },
12227 { DT_HP_DEBUG_CALLBACK
, "HP_DEBUG_CALLBACK" },
12228 { DT_HP_DEBUG_CALLBACK_BOR
, "HP_DEBUG_CALLBACK_BOR" },
12229 { DT_HP_NO_ENVVAR
, "HP_NO_ENVVAR" },
12230 { DT_HP_BIND_NOW
, "HP_BIND_NOW" },
12231 { DT_HP_BIND_NONFATAL
, "HP_BIND_NONFATAL" },
12232 { DT_HP_BIND_VERBOSE
, "HP_BIND_VERBOSE" },
12233 { DT_HP_BIND_RESTRICTED
, "HP_BIND_RESTRICTED" },
12234 { DT_HP_BIND_SYMBOLIC
, "HP_BIND_SYMBOLIC" },
12235 { DT_HP_RPATH_FIRST
, "HP_RPATH_FIRST" },
12236 { DT_HP_BIND_DEPTH_FIRST
, "HP_BIND_DEPTH_FIRST" },
12237 { DT_HP_GST
, "HP_GST" },
12238 { DT_HP_SHLIB_FIXED
, "HP_SHLIB_FIXED" },
12239 { DT_HP_MERGE_SHLIB_SEG
, "HP_MERGE_SHLIB_SEG" },
12240 { DT_HP_NODELETE
, "HP_NODELETE" },
12241 { DT_HP_GROUP
, "HP_GROUP" },
12242 { DT_HP_PROTECT_LINKAGE_TABLE
, "HP_PROTECT_LINKAGE_TABLE" }
12246 uint64_t val
= entry
->d_un
.d_val
;
12248 for (cnt
= 0; cnt
< ARRAY_SIZE (flags
); ++cnt
)
12249 if (val
& flags
[cnt
].bit
)
12253 fputs (flags
[cnt
].str
, stdout
);
12255 val
^= flags
[cnt
].bit
;
12258 if (val
!= 0 || first
)
12262 print_vma (val
, HEX
);
12268 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
12274 /* VMS vs Unix time offset and factor. */
12276 #define VMS_EPOCH_OFFSET 35067168000000000LL
12277 #define VMS_GRANULARITY_FACTOR 10000000
12279 #define INT64_MIN (-9223372036854775807LL - 1)
12282 /* Display a VMS time in a human readable format. */
12285 print_vms_time (int64_t vmstime
)
12287 struct tm
*tm
= NULL
;
12290 if (vmstime
>= INT64_MIN
+ VMS_EPOCH_OFFSET
)
12292 vmstime
= (vmstime
- VMS_EPOCH_OFFSET
) / VMS_GRANULARITY_FACTOR
;
12294 if (unxtime
== vmstime
)
12295 tm
= gmtime (&unxtime
);
12298 printf ("%04u-%02u-%02uT%02u:%02u:%02u",
12299 tm
->tm_year
+ 1900, tm
->tm_mon
+ 1, tm
->tm_mday
,
12300 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
);
12304 dynamic_section_ia64_val (Elf_Internal_Dyn
* entry
)
12306 switch (entry
->d_tag
)
12308 case DT_IA_64_PLT_RESERVE
:
12309 /* First 3 slots reserved. */
12310 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
12312 print_vma (entry
->d_un
.d_ptr
+ (3 * 8), PREFIX_HEX
);
12315 case DT_IA_64_VMS_LINKTIME
:
12316 print_vms_time (entry
->d_un
.d_val
);
12319 case DT_IA_64_VMS_LNKFLAGS
:
12320 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
12321 if (entry
->d_un
.d_val
& VMS_LF_CALL_DEBUG
)
12322 printf (" CALL_DEBUG");
12323 if (entry
->d_un
.d_val
& VMS_LF_NOP0BUFS
)
12324 printf (" NOP0BUFS");
12325 if (entry
->d_un
.d_val
& VMS_LF_P0IMAGE
)
12326 printf (" P0IMAGE");
12327 if (entry
->d_un
.d_val
& VMS_LF_MKTHREADS
)
12328 printf (" MKTHREADS");
12329 if (entry
->d_un
.d_val
& VMS_LF_UPCALLS
)
12330 printf (" UPCALLS");
12331 if (entry
->d_un
.d_val
& VMS_LF_IMGSTA
)
12332 printf (" IMGSTA");
12333 if (entry
->d_un
.d_val
& VMS_LF_INITIALIZE
)
12334 printf (" INITIALIZE");
12335 if (entry
->d_un
.d_val
& VMS_LF_MAIN
)
12337 if (entry
->d_un
.d_val
& VMS_LF_EXE_INIT
)
12338 printf (" EXE_INIT");
12339 if (entry
->d_un
.d_val
& VMS_LF_TBK_IN_IMG
)
12340 printf (" TBK_IN_IMG");
12341 if (entry
->d_un
.d_val
& VMS_LF_DBG_IN_IMG
)
12342 printf (" DBG_IN_IMG");
12343 if (entry
->d_un
.d_val
& VMS_LF_TBK_IN_DSF
)
12344 printf (" TBK_IN_DSF");
12345 if (entry
->d_un
.d_val
& VMS_LF_DBG_IN_DSF
)
12346 printf (" DBG_IN_DSF");
12347 if (entry
->d_un
.d_val
& VMS_LF_SIGNATURES
)
12348 printf (" SIGNATURES");
12349 if (entry
->d_un
.d_val
& VMS_LF_REL_SEG_OFF
)
12350 printf (" REL_SEG_OFF");
12354 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
12361 get_32bit_dynamic_section (Filedata
* filedata
)
12363 Elf32_External_Dyn
* edyn
;
12364 Elf32_External_Dyn
* ext
;
12365 Elf_Internal_Dyn
* entry
;
12367 edyn
= (Elf32_External_Dyn
*) get_data (NULL
, filedata
,
12368 filedata
->dynamic_addr
, 1,
12369 filedata
->dynamic_size
,
12370 _("dynamic section"));
12374 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
12375 might not have the luxury of section headers. Look for the DT_NULL
12376 terminator to determine the number of entries. */
12377 for (ext
= edyn
, filedata
->dynamic_nent
= 0;
12378 (char *) (ext
+ 1) <= (char *) edyn
+ filedata
->dynamic_size
;
12381 filedata
->dynamic_nent
++;
12382 if (BYTE_GET (ext
->d_tag
) == DT_NULL
)
12386 filedata
->dynamic_section
12387 = (Elf_Internal_Dyn
*) cmalloc (filedata
->dynamic_nent
, sizeof (* entry
));
12388 if (filedata
->dynamic_section
== NULL
)
12390 error (_("Out of memory allocating space for %" PRIu64
" dynamic entries\n"),
12391 filedata
->dynamic_nent
);
12396 for (ext
= edyn
, entry
= filedata
->dynamic_section
;
12397 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
12400 entry
->d_tag
= BYTE_GET (ext
->d_tag
);
12401 entry
->d_un
.d_val
= BYTE_GET (ext
->d_un
.d_val
);
12410 get_64bit_dynamic_section (Filedata
* filedata
)
12412 Elf64_External_Dyn
* edyn
;
12413 Elf64_External_Dyn
* ext
;
12414 Elf_Internal_Dyn
* entry
;
12416 /* Read in the data. */
12417 edyn
= (Elf64_External_Dyn
*) get_data (NULL
, filedata
,
12418 filedata
->dynamic_addr
, 1,
12419 filedata
->dynamic_size
,
12420 _("dynamic section"));
12424 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
12425 might not have the luxury of section headers. Look for the DT_NULL
12426 terminator to determine the number of entries. */
12427 for (ext
= edyn
, filedata
->dynamic_nent
= 0;
12428 /* PR 17533 file: 033-67080-0.004 - do not read past end of buffer. */
12429 (char *) (ext
+ 1) <= (char *) edyn
+ filedata
->dynamic_size
;
12432 filedata
->dynamic_nent
++;
12433 if (BYTE_GET (ext
->d_tag
) == DT_NULL
)
12437 filedata
->dynamic_section
12438 = (Elf_Internal_Dyn
*) cmalloc (filedata
->dynamic_nent
, sizeof (* entry
));
12439 if (filedata
->dynamic_section
== NULL
)
12441 error (_("Out of memory allocating space for %" PRIu64
" dynamic entries\n"),
12442 filedata
->dynamic_nent
);
12447 /* Convert from external to internal formats. */
12448 for (ext
= edyn
, entry
= filedata
->dynamic_section
;
12449 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
12452 entry
->d_tag
= BYTE_GET (ext
->d_tag
);
12453 entry
->d_un
.d_val
= BYTE_GET (ext
->d_un
.d_val
);
12462 get_dynamic_section (Filedata
*filedata
)
12464 if (filedata
->dynamic_section
)
12468 return get_32bit_dynamic_section (filedata
);
12470 return get_64bit_dynamic_section (filedata
);
12474 print_dynamic_flags (uint64_t flags
)
12482 flag
= flags
& - flags
;
12488 putc (' ', stdout
);
12492 case DF_ORIGIN
: fputs ("ORIGIN", stdout
); break;
12493 case DF_SYMBOLIC
: fputs ("SYMBOLIC", stdout
); break;
12494 case DF_TEXTREL
: fputs ("TEXTREL", stdout
); break;
12495 case DF_BIND_NOW
: fputs ("BIND_NOW", stdout
); break;
12496 case DF_STATIC_TLS
: fputs ("STATIC_TLS", stdout
); break;
12497 default: fputs (_("unknown"), stdout
); break;
12504 get_dynamic_data (Filedata
* filedata
, uint64_t number
, unsigned int ent_size
)
12506 unsigned char * e_data
;
12509 /* If size_t is smaller than uint64_t, eg because you are building
12510 on a 32-bit host, then make sure that when number is cast to
12511 size_t no information is lost. */
12512 if ((size_t) number
!= number
12513 || ent_size
* number
/ ent_size
!= number
)
12515 error (_("Size overflow prevents reading %" PRIu64
12516 " elements of size %u\n"),
12521 /* Be kind to memory checkers (eg valgrind, address sanitizer) by not
12522 attempting to allocate memory when the read is bound to fail. */
12523 if (ent_size
* number
> filedata
->file_size
)
12525 error (_("Invalid number of dynamic entries: %" PRIu64
"\n"),
12530 e_data
= (unsigned char *) cmalloc ((size_t) number
, ent_size
);
12531 if (e_data
== NULL
)
12533 error (_("Out of memory reading %" PRIu64
" dynamic entries\n"),
12538 if (fread (e_data
, ent_size
, (size_t) number
, filedata
->handle
) != number
)
12540 error (_("Unable to read in %" PRIu64
" bytes of dynamic data\n"),
12541 number
* ent_size
);
12546 i_data
= (uint64_t *) cmalloc ((size_t) number
, sizeof (*i_data
));
12547 if (i_data
== NULL
)
12549 error (_("Out of memory allocating space for %" PRIu64
" dynamic entries\n"),
12556 i_data
[number
] = byte_get (e_data
+ number
* ent_size
, ent_size
);
12564 get_num_dynamic_syms (Filedata
* filedata
)
12566 uint64_t num_of_syms
= 0;
12568 if (!do_histogram
&& (!do_using_dynamic
|| do_dyn_syms
))
12569 return num_of_syms
;
12571 if (filedata
->dynamic_info
[DT_HASH
])
12573 unsigned char nb
[8];
12574 unsigned char nc
[8];
12575 unsigned int hash_ent_size
= 4;
12577 if ((filedata
->file_header
.e_machine
== EM_ALPHA
12578 || filedata
->file_header
.e_machine
== EM_S390
12579 || filedata
->file_header
.e_machine
== EM_S390_OLD
)
12580 && filedata
->file_header
.e_ident
[EI_CLASS
] == ELFCLASS64
)
12583 if (fseek64 (filedata
->handle
,
12584 (filedata
->archive_file_offset
12585 + offset_from_vma (filedata
,
12586 filedata
->dynamic_info
[DT_HASH
],
12587 sizeof nb
+ sizeof nc
)),
12590 error (_("Unable to seek to start of dynamic information\n"));
12594 if (fread (nb
, hash_ent_size
, 1, filedata
->handle
) != 1)
12596 error (_("Failed to read in number of buckets\n"));
12600 if (fread (nc
, hash_ent_size
, 1, filedata
->handle
) != 1)
12602 error (_("Failed to read in number of chains\n"));
12606 filedata
->nbuckets
= byte_get (nb
, hash_ent_size
);
12607 filedata
->nchains
= byte_get (nc
, hash_ent_size
);
12609 if (filedata
->nbuckets
!= 0 && filedata
->nchains
!= 0)
12611 filedata
->buckets
= get_dynamic_data (filedata
, filedata
->nbuckets
,
12613 filedata
->chains
= get_dynamic_data (filedata
, filedata
->nchains
,
12616 if (filedata
->buckets
!= NULL
&& filedata
->chains
!= NULL
)
12617 num_of_syms
= filedata
->nchains
;
12620 if (num_of_syms
== 0)
12622 free (filedata
->buckets
);
12623 filedata
->buckets
= NULL
;
12624 free (filedata
->chains
);
12625 filedata
->chains
= NULL
;
12626 filedata
->nbuckets
= 0;
12630 if (filedata
->dynamic_info_DT_GNU_HASH
)
12632 unsigned char nb
[16];
12633 uint64_t i
, maxchain
= 0xffffffff, bitmaskwords
;
12634 uint64_t buckets_vma
;
12637 if (fseek64 (filedata
->handle
,
12638 (filedata
->archive_file_offset
12639 + offset_from_vma (filedata
,
12640 filedata
->dynamic_info_DT_GNU_HASH
,
12644 error (_("Unable to seek to start of dynamic information\n"));
12648 if (fread (nb
, 16, 1, filedata
->handle
) != 1)
12650 error (_("Failed to read in number of buckets\n"));
12654 filedata
->ngnubuckets
= byte_get (nb
, 4);
12655 filedata
->gnusymidx
= byte_get (nb
+ 4, 4);
12656 bitmaskwords
= byte_get (nb
+ 8, 4);
12657 buckets_vma
= filedata
->dynamic_info_DT_GNU_HASH
+ 16;
12659 buckets_vma
+= bitmaskwords
* 4;
12661 buckets_vma
+= bitmaskwords
* 8;
12663 if (fseek64 (filedata
->handle
,
12664 (filedata
->archive_file_offset
12665 + offset_from_vma (filedata
, buckets_vma
, 4)),
12668 error (_("Unable to seek to start of dynamic information\n"));
12672 filedata
->gnubuckets
12673 = get_dynamic_data (filedata
, filedata
->ngnubuckets
, 4);
12675 if (filedata
->gnubuckets
== NULL
)
12678 for (i
= 0; i
< filedata
->ngnubuckets
; i
++)
12679 if (filedata
->gnubuckets
[i
] != 0)
12681 if (filedata
->gnubuckets
[i
] < filedata
->gnusymidx
)
12684 if (maxchain
== 0xffffffff || filedata
->gnubuckets
[i
] > maxchain
)
12685 maxchain
= filedata
->gnubuckets
[i
];
12688 if (maxchain
== 0xffffffff)
12691 maxchain
-= filedata
->gnusymidx
;
12693 if (fseek64 (filedata
->handle
,
12694 (filedata
->archive_file_offset
12695 + offset_from_vma (filedata
,
12696 buckets_vma
+ 4 * (filedata
->ngnubuckets
12701 error (_("Unable to seek to start of dynamic information\n"));
12707 if (fread (nb
, 4, 1, filedata
->handle
) != 1)
12709 error (_("Failed to determine last chain length\n"));
12713 if (maxchain
+ 1 == 0)
12718 while ((byte_get (nb
, 4) & 1) == 0);
12720 if (fseek64 (filedata
->handle
,
12721 (filedata
->archive_file_offset
12722 + offset_from_vma (filedata
, (buckets_vma
12723 + 4 * filedata
->ngnubuckets
),
12727 error (_("Unable to seek to start of dynamic information\n"));
12731 filedata
->gnuchains
= get_dynamic_data (filedata
, maxchain
, 4);
12732 filedata
->ngnuchains
= maxchain
;
12734 if (filedata
->gnuchains
== NULL
)
12737 if (filedata
->dynamic_info_DT_MIPS_XHASH
)
12739 if (fseek64 (filedata
->handle
,
12740 (filedata
->archive_file_offset
12741 + offset_from_vma (filedata
, (buckets_vma
12742 + 4 * (filedata
->ngnubuckets
12746 error (_("Unable to seek to start of dynamic information\n"));
12750 filedata
->mipsxlat
= get_dynamic_data (filedata
, maxchain
, 4);
12751 if (filedata
->mipsxlat
== NULL
)
12755 for (hn
= 0; hn
< filedata
->ngnubuckets
; ++hn
)
12756 if (filedata
->gnubuckets
[hn
] != 0)
12758 uint64_t si
= filedata
->gnubuckets
[hn
];
12759 uint64_t off
= si
- filedata
->gnusymidx
;
12763 if (filedata
->dynamic_info_DT_MIPS_XHASH
)
12765 if (off
< filedata
->ngnuchains
12766 && filedata
->mipsxlat
[off
] >= num_of_syms
)
12767 num_of_syms
= filedata
->mipsxlat
[off
] + 1;
12771 if (si
>= num_of_syms
)
12772 num_of_syms
= si
+ 1;
12776 while (off
< filedata
->ngnuchains
12777 && (filedata
->gnuchains
[off
++] & 1) == 0);
12780 if (num_of_syms
== 0)
12783 free (filedata
->mipsxlat
);
12784 filedata
->mipsxlat
= NULL
;
12785 free (filedata
->gnuchains
);
12786 filedata
->gnuchains
= NULL
;
12787 free (filedata
->gnubuckets
);
12788 filedata
->gnubuckets
= NULL
;
12789 filedata
->ngnubuckets
= 0;
12790 filedata
->ngnuchains
= 0;
12794 return num_of_syms
;
12797 /* Parse and display the contents of the dynamic section. */
12800 process_dynamic_section (Filedata
* filedata
)
12802 Elf_Internal_Dyn
* entry
;
12804 if (filedata
->dynamic_size
<= 1)
12808 if (filedata
->is_separate
)
12809 printf (_("\nThere is no dynamic section in linked file '%s'.\n"),
12810 printable_string (filedata
->file_name
, 0));
12812 printf (_("\nThere is no dynamic section in this file.\n"));
12818 if (!get_dynamic_section (filedata
))
12821 /* Find the appropriate symbol table. */
12822 if (filedata
->dynamic_symbols
== NULL
|| do_histogram
)
12824 uint64_t num_of_syms
;
12826 for (entry
= filedata
->dynamic_section
;
12827 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
12829 if (entry
->d_tag
== DT_SYMTAB
)
12830 filedata
->dynamic_info
[DT_SYMTAB
] = entry
->d_un
.d_val
;
12831 else if (entry
->d_tag
== DT_SYMENT
)
12832 filedata
->dynamic_info
[DT_SYMENT
] = entry
->d_un
.d_val
;
12833 else if (entry
->d_tag
== DT_HASH
)
12834 filedata
->dynamic_info
[DT_HASH
] = entry
->d_un
.d_val
;
12835 else if (entry
->d_tag
== DT_GNU_HASH
)
12836 filedata
->dynamic_info_DT_GNU_HASH
= entry
->d_un
.d_val
;
12837 else if ((filedata
->file_header
.e_machine
== EM_MIPS
12838 || filedata
->file_header
.e_machine
== EM_MIPS_RS3_LE
)
12839 && entry
->d_tag
== DT_MIPS_XHASH
)
12841 filedata
->dynamic_info_DT_MIPS_XHASH
= entry
->d_un
.d_val
;
12842 filedata
->dynamic_info_DT_GNU_HASH
= entry
->d_un
.d_val
;
12845 num_of_syms
= get_num_dynamic_syms (filedata
);
12847 if (num_of_syms
!= 0
12848 && filedata
->dynamic_symbols
== NULL
12849 && filedata
->dynamic_info
[DT_SYMTAB
]
12850 && filedata
->dynamic_info
[DT_SYMENT
])
12852 Elf_Internal_Phdr
*seg
;
12853 uint64_t vma
= filedata
->dynamic_info
[DT_SYMTAB
];
12855 if (! get_program_headers (filedata
))
12857 error (_("Cannot interpret virtual addresses "
12858 "without program headers.\n"));
12862 for (seg
= filedata
->program_headers
;
12863 seg
< filedata
->program_headers
+ filedata
->file_header
.e_phnum
;
12866 if (seg
->p_type
!= PT_LOAD
)
12869 if (seg
->p_offset
+ seg
->p_filesz
> filedata
->file_size
)
12871 /* See PR 21379 for a reproducer. */
12872 error (_("Invalid PT_LOAD entry\n"));
12876 if (vma
>= (seg
->p_vaddr
& -seg
->p_align
)
12877 && vma
< seg
->p_vaddr
+ seg
->p_filesz
)
12879 /* Since we do not know how big the symbol table is,
12880 we default to reading in up to the end of PT_LOAD
12881 segment and processing that. This is overkill, I
12882 know, but it should work. */
12883 Elf_Internal_Shdr section
;
12884 section
.sh_offset
= (vma
- seg
->p_vaddr
12886 section
.sh_size
= (num_of_syms
12887 * filedata
->dynamic_info
[DT_SYMENT
]);
12888 section
.sh_entsize
= filedata
->dynamic_info
[DT_SYMENT
];
12891 && filedata
->dynamic_symtab_section
!= NULL
12892 && ((filedata
->dynamic_symtab_section
->sh_offset
12893 != section
.sh_offset
)
12894 || (filedata
->dynamic_symtab_section
->sh_size
12895 != section
.sh_size
)
12896 || (filedata
->dynamic_symtab_section
->sh_entsize
12897 != section
.sh_entsize
)))
12899 the .dynsym section doesn't match the DT_SYMTAB and DT_SYMENT tags\n"));
12901 section
.sh_name
= filedata
->string_table_length
;
12902 filedata
->dynamic_symbols
12903 = get_elf_symbols (filedata
, §ion
,
12904 &filedata
->num_dynamic_syms
);
12905 if (filedata
->dynamic_symbols
== NULL
12906 || filedata
->num_dynamic_syms
!= num_of_syms
)
12908 error (_("Corrupt DT_SYMTAB dynamic entry\n"));
12917 /* Similarly find a string table. */
12918 if (filedata
->dynamic_strings
== NULL
)
12919 for (entry
= filedata
->dynamic_section
;
12920 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
12923 if (entry
->d_tag
== DT_STRTAB
)
12924 filedata
->dynamic_info
[DT_STRTAB
] = entry
->d_un
.d_val
;
12926 if (entry
->d_tag
== DT_STRSZ
)
12927 filedata
->dynamic_info
[DT_STRSZ
] = entry
->d_un
.d_val
;
12929 if (filedata
->dynamic_info
[DT_STRTAB
]
12930 && filedata
->dynamic_info
[DT_STRSZ
])
12933 uint64_t str_tab_len
= filedata
->dynamic_info
[DT_STRSZ
];
12935 offset
= offset_from_vma (filedata
,
12936 filedata
->dynamic_info
[DT_STRTAB
],
12939 && filedata
->dynamic_strtab_section
12940 && ((filedata
->dynamic_strtab_section
->sh_offset
12941 != (file_ptr
) offset
)
12942 || (filedata
->dynamic_strtab_section
->sh_size
12945 the .dynstr section doesn't match the DT_STRTAB and DT_STRSZ tags\n"));
12947 filedata
->dynamic_strings
12948 = (char *) get_data (NULL
, filedata
, offset
, 1, str_tab_len
,
12949 _("dynamic string table"));
12950 if (filedata
->dynamic_strings
== NULL
)
12952 error (_("Corrupt DT_STRTAB dynamic entry\n"));
12956 filedata
->dynamic_strings_length
= str_tab_len
;
12961 /* And find the syminfo section if available. */
12962 if (filedata
->dynamic_syminfo
== NULL
)
12964 uint64_t syminsz
= 0;
12966 for (entry
= filedata
->dynamic_section
;
12967 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
12970 if (entry
->d_tag
== DT_SYMINENT
)
12972 /* Note: these braces are necessary to avoid a syntax
12973 error from the SunOS4 C compiler. */
12974 /* PR binutils/17531: A corrupt file can trigger this test.
12975 So do not use an assert, instead generate an error message. */
12976 if (sizeof (Elf_External_Syminfo
) != entry
->d_un
.d_val
)
12977 error (_("Bad value (%d) for SYMINENT entry\n"),
12978 (int) entry
->d_un
.d_val
);
12980 else if (entry
->d_tag
== DT_SYMINSZ
)
12981 syminsz
= entry
->d_un
.d_val
;
12982 else if (entry
->d_tag
== DT_SYMINFO
)
12983 filedata
->dynamic_syminfo_offset
12984 = offset_from_vma (filedata
, entry
->d_un
.d_val
, syminsz
);
12987 if (filedata
->dynamic_syminfo_offset
!= 0 && syminsz
!= 0)
12989 Elf_External_Syminfo
* extsyminfo
;
12990 Elf_External_Syminfo
* extsym
;
12991 Elf_Internal_Syminfo
* syminfo
;
12993 /* There is a syminfo section. Read the data. */
12994 extsyminfo
= (Elf_External_Syminfo
*)
12995 get_data (NULL
, filedata
, filedata
->dynamic_syminfo_offset
,
12996 1, syminsz
, _("symbol information"));
13000 if (filedata
->dynamic_syminfo
!= NULL
)
13002 error (_("Multiple dynamic symbol information sections found\n"));
13003 free (filedata
->dynamic_syminfo
);
13005 filedata
->dynamic_syminfo
= (Elf_Internal_Syminfo
*) malloc (syminsz
);
13006 if (filedata
->dynamic_syminfo
== NULL
)
13008 error (_("Out of memory allocating %" PRIu64
13009 " bytes for dynamic symbol info\n"),
13014 filedata
->dynamic_syminfo_nent
13015 = syminsz
/ sizeof (Elf_External_Syminfo
);
13016 for (syminfo
= filedata
->dynamic_syminfo
, extsym
= extsyminfo
;
13017 syminfo
< (filedata
->dynamic_syminfo
13018 + filedata
->dynamic_syminfo_nent
);
13019 ++syminfo
, ++extsym
)
13021 syminfo
->si_boundto
= BYTE_GET (extsym
->si_boundto
);
13022 syminfo
->si_flags
= BYTE_GET (extsym
->si_flags
);
13029 if (do_dynamic
&& filedata
->dynamic_addr
)
13031 if (filedata
->is_separate
)
13032 printf (ngettext ("\nIn linked file '%s' the dynamic section at offset %#" PRIx64
" contains %" PRIu64
" entry:\n",
13033 "\nIn linked file '%s' the dynamic section at offset %#" PRIx64
" contains %" PRIu64
" entries:\n",
13034 filedata
->dynamic_nent
),
13035 filedata
->file_name
,
13036 filedata
->dynamic_addr
,
13037 filedata
->dynamic_nent
);
13039 printf (ngettext ("\nDynamic section at offset %#" PRIx64
" contains %" PRIu64
" entry:\n",
13040 "\nDynamic section at offset %#" PRIx64
" contains %" PRIu64
" entries:\n",
13041 filedata
->dynamic_nent
),
13042 filedata
->dynamic_addr
,
13043 filedata
->dynamic_nent
);
13046 printf (_(" Tag Type Name/Value\n"));
13048 for (entry
= filedata
->dynamic_section
;
13049 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
13054 const char * dtype
;
13057 print_vma (entry
->d_tag
, FULL_HEX
);
13058 dtype
= get_dynamic_type (filedata
, entry
->d_tag
);
13059 printf (" (%s)%*s", dtype
,
13060 ((is_32bit_elf
? 27 : 19) - (int) strlen (dtype
)), " ");
13063 switch (entry
->d_tag
)
13067 print_dynamic_flags (entry
->d_un
.d_val
);
13077 switch (entry
->d_tag
)
13080 printf (_("Auxiliary library"));
13084 printf (_("Filter library"));
13088 printf (_("Configuration file"));
13092 printf (_("Dependency audit library"));
13096 printf (_("Audit library"));
13100 if (valid_dynamic_name (filedata
, entry
->d_un
.d_val
))
13101 printf (": [%s]\n",
13102 get_dynamic_name (filedata
, entry
->d_un
.d_val
));
13106 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
13115 printf (_("Flags:"));
13117 if (entry
->d_un
.d_val
== 0)
13118 printf (_(" None\n"));
13121 uint64_t val
= entry
->d_un
.d_val
;
13123 if (val
& DTF_1_PARINIT
)
13125 printf (" PARINIT");
13126 val
^= DTF_1_PARINIT
;
13128 if (val
& DTF_1_CONFEXP
)
13130 printf (" CONFEXP");
13131 val
^= DTF_1_CONFEXP
;
13134 printf (" %" PRIx64
, val
);
13143 printf (_("Flags:"));
13145 if (entry
->d_un
.d_val
== 0)
13146 printf (_(" None\n"));
13149 uint64_t val
= entry
->d_un
.d_val
;
13151 if (val
& DF_P1_LAZYLOAD
)
13153 printf (" LAZYLOAD");
13154 val
^= DF_P1_LAZYLOAD
;
13156 if (val
& DF_P1_GROUPPERM
)
13158 printf (" GROUPPERM");
13159 val
^= DF_P1_GROUPPERM
;
13162 printf (" %" PRIx64
, val
);
13171 printf (_("Flags:"));
13172 if (entry
->d_un
.d_val
== 0)
13173 printf (_(" None\n"));
13176 uint64_t val
= entry
->d_un
.d_val
;
13178 if (val
& DF_1_NOW
)
13183 if (val
& DF_1_GLOBAL
)
13185 printf (" GLOBAL");
13186 val
^= DF_1_GLOBAL
;
13188 if (val
& DF_1_GROUP
)
13193 if (val
& DF_1_NODELETE
)
13195 printf (" NODELETE");
13196 val
^= DF_1_NODELETE
;
13198 if (val
& DF_1_LOADFLTR
)
13200 printf (" LOADFLTR");
13201 val
^= DF_1_LOADFLTR
;
13203 if (val
& DF_1_INITFIRST
)
13205 printf (" INITFIRST");
13206 val
^= DF_1_INITFIRST
;
13208 if (val
& DF_1_NOOPEN
)
13210 printf (" NOOPEN");
13211 val
^= DF_1_NOOPEN
;
13213 if (val
& DF_1_ORIGIN
)
13215 printf (" ORIGIN");
13216 val
^= DF_1_ORIGIN
;
13218 if (val
& DF_1_DIRECT
)
13220 printf (" DIRECT");
13221 val
^= DF_1_DIRECT
;
13223 if (val
& DF_1_TRANS
)
13228 if (val
& DF_1_INTERPOSE
)
13230 printf (" INTERPOSE");
13231 val
^= DF_1_INTERPOSE
;
13233 if (val
& DF_1_NODEFLIB
)
13235 printf (" NODEFLIB");
13236 val
^= DF_1_NODEFLIB
;
13238 if (val
& DF_1_NODUMP
)
13240 printf (" NODUMP");
13241 val
^= DF_1_NODUMP
;
13243 if (val
& DF_1_CONFALT
)
13245 printf (" CONFALT");
13246 val
^= DF_1_CONFALT
;
13248 if (val
& DF_1_ENDFILTEE
)
13250 printf (" ENDFILTEE");
13251 val
^= DF_1_ENDFILTEE
;
13253 if (val
& DF_1_DISPRELDNE
)
13255 printf (" DISPRELDNE");
13256 val
^= DF_1_DISPRELDNE
;
13258 if (val
& DF_1_DISPRELPND
)
13260 printf (" DISPRELPND");
13261 val
^= DF_1_DISPRELPND
;
13263 if (val
& DF_1_NODIRECT
)
13265 printf (" NODIRECT");
13266 val
^= DF_1_NODIRECT
;
13268 if (val
& DF_1_IGNMULDEF
)
13270 printf (" IGNMULDEF");
13271 val
^= DF_1_IGNMULDEF
;
13273 if (val
& DF_1_NOKSYMS
)
13275 printf (" NOKSYMS");
13276 val
^= DF_1_NOKSYMS
;
13278 if (val
& DF_1_NOHDR
)
13283 if (val
& DF_1_EDITED
)
13285 printf (" EDITED");
13286 val
^= DF_1_EDITED
;
13288 if (val
& DF_1_NORELOC
)
13290 printf (" NORELOC");
13291 val
^= DF_1_NORELOC
;
13293 if (val
& DF_1_SYMINTPOSE
)
13295 printf (" SYMINTPOSE");
13296 val
^= DF_1_SYMINTPOSE
;
13298 if (val
& DF_1_GLOBAUDIT
)
13300 printf (" GLOBAUDIT");
13301 val
^= DF_1_GLOBAUDIT
;
13303 if (val
& DF_1_SINGLETON
)
13305 printf (" SINGLETON");
13306 val
^= DF_1_SINGLETON
;
13308 if (val
& DF_1_STUB
)
13313 if (val
& DF_1_PIE
)
13318 if (val
& DF_1_KMOD
)
13323 if (val
& DF_1_WEAKFILTER
)
13325 printf (" WEAKFILTER");
13326 val
^= DF_1_WEAKFILTER
;
13328 if (val
& DF_1_NOCOMMON
)
13330 printf (" NOCOMMON");
13331 val
^= DF_1_NOCOMMON
;
13334 printf (" %" PRIx64
, val
);
13341 filedata
->dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
13343 puts (get_dynamic_type (filedata
, entry
->d_un
.d_val
));
13364 filedata
->dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
13370 if (valid_dynamic_name (filedata
, entry
->d_un
.d_val
))
13371 name
= get_dynamic_name (filedata
, entry
->d_un
.d_val
);
13377 switch (entry
->d_tag
)
13380 printf (_("Shared library: [%s]"), name
);
13382 if (filedata
->program_interpreter
13383 && streq (name
, filedata
->program_interpreter
))
13384 printf (_(" program interpreter"));
13388 printf (_("Library soname: [%s]"), name
);
13392 printf (_("Library rpath: [%s]"), name
);
13396 printf (_("Library runpath: [%s]"), name
);
13400 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
13405 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
13420 filedata
->dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
13421 /* Fall through. */
13425 case DT_PREINIT_ARRAYSZ
:
13426 case DT_INIT_ARRAYSZ
:
13427 case DT_FINI_ARRAYSZ
:
13428 case DT_GNU_CONFLICTSZ
:
13429 case DT_GNU_LIBLISTSZ
:
13432 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
13433 printf (_(" (bytes)\n"));
13438 case DT_VERNEEDNUM
:
13443 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
13452 case DT_INIT_ARRAY
:
13453 case DT_FINI_ARRAY
:
13456 if (entry
->d_tag
== DT_USED
13457 && valid_dynamic_name (filedata
, entry
->d_un
.d_val
))
13460 = get_dynamic_name (filedata
, entry
->d_un
.d_val
);
13464 printf (_("Not needed object: [%s]\n"), name
);
13469 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
13475 /* The value of this entry is ignored. */
13480 case DT_GNU_PRELINKED
:
13484 time_t atime
= entry
->d_un
.d_val
;
13486 tmp
= gmtime (&atime
);
13487 /* PR 17533 file: 041-1244816-0.004. */
13489 printf (_("<corrupt time val: %" PRIx64
),
13492 printf ("%04u-%02u-%02uT%02u:%02u:%02u\n",
13493 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
13494 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
13500 filedata
->dynamic_info_DT_GNU_HASH
= entry
->d_un
.d_val
;
13503 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
13508 case DT_GNU_FLAGS_1
:
13511 printf (_("Flags:"));
13512 if (entry
->d_un
.d_val
== 0)
13513 printf (_(" None\n"));
13516 uint64_t val
= entry
->d_un
.d_val
;
13518 if (val
& DF_GNU_1_UNIQUE
)
13520 printf (" UNIQUE");
13521 val
^= DF_GNU_1_UNIQUE
;
13524 printf (" %" PRIx64
, val
);
13531 if ((entry
->d_tag
>= DT_VERSYM
) && (entry
->d_tag
<= DT_VERNEEDNUM
))
13532 filedata
->version_info
[DT_VERSIONTAGIDX (entry
->d_tag
)]
13533 = entry
->d_un
.d_val
;
13537 switch (filedata
->file_header
.e_machine
)
13540 dynamic_section_aarch64_val (entry
);
13543 case EM_MIPS_RS3_LE
:
13544 dynamic_section_mips_val (filedata
, entry
);
13547 dynamic_section_parisc_val (entry
);
13550 dynamic_section_ia64_val (entry
);
13553 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
13565 get_ver_flags (unsigned int flags
)
13567 static char buff
[128];
13574 if (flags
& VER_FLG_BASE
)
13575 strcat (buff
, "BASE");
13577 if (flags
& VER_FLG_WEAK
)
13579 if (flags
& VER_FLG_BASE
)
13580 strcat (buff
, " | ");
13582 strcat (buff
, "WEAK");
13585 if (flags
& VER_FLG_INFO
)
13587 if (flags
& (VER_FLG_BASE
|VER_FLG_WEAK
))
13588 strcat (buff
, " | ");
13590 strcat (buff
, "INFO");
13593 if (flags
& ~(VER_FLG_BASE
| VER_FLG_WEAK
| VER_FLG_INFO
))
13595 if (flags
& (VER_FLG_BASE
| VER_FLG_WEAK
| VER_FLG_INFO
))
13596 strcat (buff
, " | ");
13598 strcat (buff
, _("<unknown>"));
13604 /* Display the contents of the version sections. */
13607 process_version_sections (Filedata
* filedata
)
13609 Elf_Internal_Shdr
* section
;
13611 bool found
= false;
13616 for (i
= 0, section
= filedata
->section_headers
;
13617 i
< filedata
->file_header
.e_shnum
;
13620 switch (section
->sh_type
)
13622 case SHT_GNU_verdef
:
13624 Elf_External_Verdef
* edefs
;
13631 if (filedata
->is_separate
)
13632 printf (ngettext ("\nIn linked file '%s' the version definition section '%s' contains %u entry:\n",
13633 "\nIn linked file '%s' the version definition section '%s' contains %u entries:\n",
13635 filedata
->file_name
,
13636 printable_section_name (filedata
, section
),
13639 printf (ngettext ("\nVersion definition section '%s' "
13640 "contains %u entry:\n",
13641 "\nVersion definition section '%s' "
13642 "contains %u entries:\n",
13644 printable_section_name (filedata
, section
),
13647 printf (_(" Addr: 0x%016" PRIx64
), section
->sh_addr
);
13648 printf (_(" Offset: 0x%08" PRIx64
" Link: %u (%s)\n"),
13649 section
->sh_offset
, section
->sh_link
,
13650 printable_section_name_from_index (filedata
, section
->sh_link
, NULL
));
13652 edefs
= (Elf_External_Verdef
*)
13653 get_data (NULL
, filedata
, section
->sh_offset
, 1,section
->sh_size
,
13654 _("version definition section"));
13657 endbuf
= (char *) edefs
+ section
->sh_size
;
13659 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
13662 Elf_External_Verdef
* edef
;
13663 Elf_Internal_Verdef ent
;
13664 Elf_External_Verdaux
* eaux
;
13665 Elf_Internal_Verdaux aux
;
13669 vstart
= ((char *) edefs
) + idx
;
13670 if (vstart
+ sizeof (*edef
) > endbuf
)
13673 edef
= (Elf_External_Verdef
*) vstart
;
13675 ent
.vd_version
= BYTE_GET (edef
->vd_version
);
13676 ent
.vd_flags
= BYTE_GET (edef
->vd_flags
);
13677 ent
.vd_ndx
= BYTE_GET (edef
->vd_ndx
);
13678 ent
.vd_cnt
= BYTE_GET (edef
->vd_cnt
);
13679 ent
.vd_hash
= BYTE_GET (edef
->vd_hash
);
13680 ent
.vd_aux
= BYTE_GET (edef
->vd_aux
);
13681 ent
.vd_next
= BYTE_GET (edef
->vd_next
);
13683 printf (_(" %#06zx: Rev: %d Flags: %s"),
13684 idx
, ent
.vd_version
, get_ver_flags (ent
.vd_flags
));
13686 printf (_(" Index: %d Cnt: %d "),
13687 ent
.vd_ndx
, ent
.vd_cnt
);
13689 /* Check for overflow. */
13690 if (ent
.vd_aux
> (size_t) (endbuf
- vstart
))
13693 vstart
+= ent
.vd_aux
;
13695 if (vstart
+ sizeof (*eaux
) > endbuf
)
13697 eaux
= (Elf_External_Verdaux
*) vstart
;
13699 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
13700 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
13702 if (valid_dynamic_name (filedata
, aux
.vda_name
))
13703 printf (_("Name: %s\n"),
13704 get_dynamic_name (filedata
, aux
.vda_name
));
13706 printf (_("Name index: %ld\n"), aux
.vda_name
);
13708 isum
= idx
+ ent
.vd_aux
;
13710 for (j
= 1; j
< ent
.vd_cnt
; j
++)
13712 if (aux
.vda_next
< sizeof (*eaux
)
13713 && !(j
== ent
.vd_cnt
- 1 && aux
.vda_next
== 0))
13715 warn (_("Invalid vda_next field of %lx\n"),
13720 /* Check for overflow. */
13721 if (aux
.vda_next
> (size_t) (endbuf
- vstart
))
13724 isum
+= aux
.vda_next
;
13725 vstart
+= aux
.vda_next
;
13727 if (vstart
+ sizeof (*eaux
) > endbuf
)
13729 eaux
= (Elf_External_Verdaux
*) vstart
;
13731 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
13732 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
13734 if (valid_dynamic_name (filedata
, aux
.vda_name
))
13735 printf (_(" %#06zx: Parent %d: %s\n"),
13737 get_dynamic_name (filedata
, aux
.vda_name
));
13739 printf (_(" %#06zx: Parent %d, name index: %ld\n"),
13740 isum
, j
, aux
.vda_name
);
13743 if (j
< ent
.vd_cnt
)
13744 printf (_(" Version def aux past end of section\n"));
13747 file: id:000001,src:000172+005151,op:splice,rep:2. */
13748 if (ent
.vd_next
< sizeof (*edef
)
13749 && !(cnt
== section
->sh_info
- 1 && ent
.vd_next
== 0))
13751 warn (_("Invalid vd_next field of %lx\n"), ent
.vd_next
);
13752 cnt
= section
->sh_info
;
13755 if (ent
.vd_next
> (size_t) (endbuf
- ((char *) edefs
+ idx
)))
13758 idx
+= ent
.vd_next
;
13761 if (cnt
< section
->sh_info
)
13762 printf (_(" Version definition past end of section\n"));
13768 case SHT_GNU_verneed
:
13770 Elf_External_Verneed
* eneed
;
13777 if (filedata
->is_separate
)
13778 printf (ngettext ("\nIn linked file '%s' the version needs section '%s' contains %u entry:\n",
13779 "\nIn linked file '%s' the version needs section '%s' contains %u entries:\n",
13781 filedata
->file_name
,
13782 printable_section_name (filedata
, section
),
13785 printf (ngettext ("\nVersion needs section '%s' "
13786 "contains %u entry:\n",
13787 "\nVersion needs section '%s' "
13788 "contains %u entries:\n",
13790 printable_section_name (filedata
, section
),
13793 printf (_(" Addr: 0x%016" PRIx64
), section
->sh_addr
);
13794 printf (_(" Offset: 0x%08" PRIx64
" Link: %u (%s)\n"),
13795 section
->sh_offset
, section
->sh_link
,
13796 printable_section_name_from_index (filedata
, section
->sh_link
, NULL
));
13798 eneed
= (Elf_External_Verneed
*) get_data (NULL
, filedata
,
13799 section
->sh_offset
, 1,
13801 _("Version Needs section"));
13804 endbuf
= (char *) eneed
+ section
->sh_size
;
13806 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
13808 Elf_External_Verneed
* entry
;
13809 Elf_Internal_Verneed ent
;
13814 vstart
= ((char *) eneed
) + idx
;
13815 if (vstart
+ sizeof (*entry
) > endbuf
)
13818 entry
= (Elf_External_Verneed
*) vstart
;
13820 ent
.vn_version
= BYTE_GET (entry
->vn_version
);
13821 ent
.vn_cnt
= BYTE_GET (entry
->vn_cnt
);
13822 ent
.vn_file
= BYTE_GET (entry
->vn_file
);
13823 ent
.vn_aux
= BYTE_GET (entry
->vn_aux
);
13824 ent
.vn_next
= BYTE_GET (entry
->vn_next
);
13826 printf (_(" %#06zx: Version: %d"), idx
, ent
.vn_version
);
13828 if (valid_dynamic_name (filedata
, ent
.vn_file
))
13829 printf (_(" File: %s"),
13830 get_dynamic_name (filedata
, ent
.vn_file
));
13832 printf (_(" File: %lx"), ent
.vn_file
);
13834 printf (_(" Cnt: %d\n"), ent
.vn_cnt
);
13836 /* Check for overflow. */
13837 if (ent
.vn_aux
> (size_t) (endbuf
- vstart
))
13839 vstart
+= ent
.vn_aux
;
13841 for (j
= 0, isum
= idx
+ ent
.vn_aux
; j
< ent
.vn_cnt
; ++j
)
13843 Elf_External_Vernaux
* eaux
;
13844 Elf_Internal_Vernaux aux
;
13846 if (vstart
+ sizeof (*eaux
) > endbuf
)
13848 eaux
= (Elf_External_Vernaux
*) vstart
;
13850 aux
.vna_hash
= BYTE_GET (eaux
->vna_hash
);
13851 aux
.vna_flags
= BYTE_GET (eaux
->vna_flags
);
13852 aux
.vna_other
= BYTE_GET (eaux
->vna_other
);
13853 aux
.vna_name
= BYTE_GET (eaux
->vna_name
);
13854 aux
.vna_next
= BYTE_GET (eaux
->vna_next
);
13856 if (valid_dynamic_name (filedata
, aux
.vna_name
))
13857 printf (_(" %#06zx: Name: %s"),
13858 isum
, get_dynamic_name (filedata
, aux
.vna_name
));
13860 printf (_(" %#06zx: Name index: %lx"),
13861 isum
, aux
.vna_name
);
13863 printf (_(" Flags: %s Version: %d\n"),
13864 get_ver_flags (aux
.vna_flags
), aux
.vna_other
);
13866 if (aux
.vna_next
< sizeof (*eaux
)
13867 && !(j
== ent
.vn_cnt
- 1 && aux
.vna_next
== 0))
13869 warn (_("Invalid vna_next field of %lx\n"),
13874 /* Check for overflow. */
13875 if (aux
.vna_next
> (size_t) (endbuf
- vstart
))
13877 isum
+= aux
.vna_next
;
13878 vstart
+= aux
.vna_next
;
13881 if (j
< ent
.vn_cnt
)
13882 warn (_("Missing Version Needs auxiliary information\n"));
13884 if (ent
.vn_next
< sizeof (*entry
)
13885 && !(cnt
== section
->sh_info
- 1 && ent
.vn_next
== 0))
13887 warn (_("Invalid vn_next field of %lx\n"), ent
.vn_next
);
13888 cnt
= section
->sh_info
;
13891 if (ent
.vn_next
> (size_t) (endbuf
- ((char *) eneed
+ idx
)))
13893 idx
+= ent
.vn_next
;
13896 if (cnt
< section
->sh_info
)
13897 warn (_("Missing Version Needs information\n"));
13903 case SHT_GNU_versym
:
13905 Elf_Internal_Shdr
* link_section
;
13908 unsigned char * edata
;
13909 unsigned short * data
;
13911 Elf_Internal_Sym
* symbols
;
13912 Elf_Internal_Shdr
* string_sec
;
13916 if (section
->sh_link
>= filedata
->file_header
.e_shnum
)
13919 link_section
= filedata
->section_headers
+ section
->sh_link
;
13920 total
= section
->sh_size
/ sizeof (Elf_External_Versym
);
13922 if (link_section
->sh_link
>= filedata
->file_header
.e_shnum
)
13927 symbols
= get_elf_symbols (filedata
, link_section
, & num_syms
);
13928 if (symbols
== NULL
)
13931 string_sec
= filedata
->section_headers
+ link_section
->sh_link
;
13933 strtab
= (char *) get_data (NULL
, filedata
, string_sec
->sh_offset
, 1,
13934 string_sec
->sh_size
,
13935 _("version string table"));
13942 if (filedata
->is_separate
)
13943 printf (ngettext ("\nIn linked file '%s' the version symbols section '%s' contains %" PRIu64
" entry:\n",
13944 "\nIn linked file '%s' the version symbols section '%s' contains %" PRIu64
" entries:\n",
13946 filedata
->file_name
,
13947 printable_section_name (filedata
, section
),
13950 printf (ngettext ("\nVersion symbols section '%s' "
13951 "contains %" PRIu64
" entry:\n",
13952 "\nVersion symbols section '%s' "
13953 "contains %" PRIu64
" entries:\n",
13955 printable_section_name (filedata
, section
),
13958 printf (_(" Addr: 0x%016" PRIx64
), section
->sh_addr
);
13959 printf (_(" Offset: 0x%08" PRIx64
" Link: %u (%s)\n"),
13960 section
->sh_offset
, section
->sh_link
,
13961 printable_section_name (filedata
, link_section
));
13963 off
= offset_from_vma (filedata
,
13964 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)],
13965 total
* sizeof (short));
13966 edata
= (unsigned char *) get_data (NULL
, filedata
, off
,
13967 sizeof (short), total
,
13968 _("version symbol data"));
13976 data
= (short unsigned int *) cmalloc (total
, sizeof (short));
13978 for (cnt
= total
; cnt
--;)
13979 data
[cnt
] = byte_get (edata
+ cnt
* sizeof (short),
13984 for (cnt
= 0; cnt
< total
; cnt
+= 4)
13988 char *invalid
= _("*invalid*");
13990 printf (" %03x:", cnt
);
13992 for (j
= 0; (j
< 4) && (cnt
+ j
) < total
; ++j
)
13993 switch (data
[cnt
+ j
])
13996 fputs (_(" 0 (*local*) "), stdout
);
14000 fputs (_(" 1 (*global*) "), stdout
);
14004 nn
= printf ("%4x%c", data
[cnt
+ j
] & VERSYM_VERSION
,
14005 data
[cnt
+ j
] & VERSYM_HIDDEN
? 'h' : ' ');
14007 /* If this index value is greater than the size of the symbols
14008 array, break to avoid an out-of-bounds read. */
14009 if (cnt
+ j
>= num_syms
)
14011 warn (_("invalid index into symbol array\n"));
14016 if (filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)])
14018 Elf_Internal_Verneed ivn
;
14021 offset
= offset_from_vma
14023 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)],
14024 sizeof (Elf_External_Verneed
));
14028 Elf_Internal_Vernaux ivna
;
14029 Elf_External_Verneed evn
;
14030 Elf_External_Vernaux evna
;
14033 if (get_data (&evn
, filedata
, offset
, sizeof (evn
), 1,
14034 _("version need")) == NULL
)
14037 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
14038 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
14040 a_off
= offset
+ ivn
.vn_aux
;
14044 if (get_data (&evna
, filedata
, a_off
, sizeof (evna
),
14045 1, _("version need aux (2)")) == NULL
)
14048 ivna
.vna_other
= 0;
14052 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
14053 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
14056 a_off
+= ivna
.vna_next
;
14058 while (ivna
.vna_other
!= data
[cnt
+ j
]
14059 && ivna
.vna_next
!= 0);
14061 if (ivna
.vna_other
== data
[cnt
+ j
])
14063 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
14065 if (ivna
.vna_name
>= string_sec
->sh_size
)
14068 name
= strtab
+ ivna
.vna_name
;
14072 offset
+= ivn
.vn_next
;
14074 while (ivn
.vn_next
);
14077 if (data
[cnt
+ j
] != (VERSYM_HIDDEN
| VERSYM_BASE
)
14078 && filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
14080 Elf_Internal_Verdef ivd
;
14081 Elf_External_Verdef evd
;
14084 offset
= offset_from_vma
14086 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)],
14091 if (get_data (&evd
, filedata
, offset
, sizeof (evd
), 1,
14092 _("version def")) == NULL
)
14095 /* PR 17531: file: 046-1082287-0.004. */
14096 ivd
.vd_ndx
= (data
[cnt
+ j
] & VERSYM_VERSION
) + 1;
14101 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
14102 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
14105 offset
+= ivd
.vd_next
;
14107 while (ivd
.vd_ndx
!= (data
[cnt
+ j
] & VERSYM_VERSION
)
14108 && ivd
.vd_next
!= 0);
14110 if (ivd
.vd_ndx
== (data
[cnt
+ j
] & VERSYM_VERSION
))
14112 Elf_External_Verdaux evda
;
14113 Elf_Internal_Verdaux ivda
;
14115 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
14117 if (get_data (&evda
, filedata
,
14118 offset
- ivd
.vd_next
+ ivd
.vd_aux
,
14120 _("version def aux")) == NULL
)
14123 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
14125 if (ivda
.vda_name
>= string_sec
->sh_size
)
14127 else if (name
!= NULL
&& name
!= invalid
)
14128 name
= _("*both*");
14130 name
= strtab
+ ivda
.vda_name
;
14134 nn
+= printf ("(%s%-*s",
14136 12 - (int) strlen (name
),
14140 printf ("%*c", 18 - nn
, ' ');
14159 if (filedata
->is_separate
)
14160 printf (_("\nNo version information found in linked file '%s'.\n"),
14161 filedata
->file_name
);
14163 printf (_("\nNo version information found in this file.\n"));
14169 static const char *
14170 get_symbol_binding (Filedata
* filedata
, unsigned int binding
)
14172 static char buff
[64];
14176 case STB_LOCAL
: return "LOCAL";
14177 case STB_GLOBAL
: return "GLOBAL";
14178 case STB_WEAK
: return "WEAK";
14180 if (binding
>= STB_LOPROC
&& binding
<= STB_HIPROC
)
14181 snprintf (buff
, sizeof (buff
), _("<processor specific>: %d"),
14183 else if (binding
>= STB_LOOS
&& binding
<= STB_HIOS
)
14185 if (binding
== STB_GNU_UNIQUE
14186 && filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_GNU
)
14188 snprintf (buff
, sizeof (buff
), _("<OS specific>: %d"), binding
);
14191 snprintf (buff
, sizeof (buff
), _("<unknown>: %d"), binding
);
14196 static const char *
14197 get_symbol_type (Filedata
* filedata
, unsigned int type
)
14199 static char buff
[64];
14203 case STT_NOTYPE
: return "NOTYPE";
14204 case STT_OBJECT
: return "OBJECT";
14205 case STT_FUNC
: return "FUNC";
14206 case STT_SECTION
: return "SECTION";
14207 case STT_FILE
: return "FILE";
14208 case STT_COMMON
: return "COMMON";
14209 case STT_TLS
: return "TLS";
14210 case STT_RELC
: return "RELC";
14211 case STT_SRELC
: return "SRELC";
14213 if (type
>= STT_LOPROC
&& type
<= STT_HIPROC
)
14215 if (filedata
->file_header
.e_machine
== EM_ARM
&& type
== STT_ARM_TFUNC
)
14216 return "THUMB_FUNC";
14218 if (filedata
->file_header
.e_machine
== EM_SPARCV9
&& type
== STT_REGISTER
)
14221 if (filedata
->file_header
.e_machine
== EM_PARISC
&& type
== STT_PARISC_MILLI
)
14222 return "PARISC_MILLI";
14224 snprintf (buff
, sizeof (buff
), _("<processor specific>: %d"), type
);
14226 else if (type
>= STT_LOOS
&& type
<= STT_HIOS
)
14228 if (filedata
->file_header
.e_machine
== EM_PARISC
)
14230 if (type
== STT_HP_OPAQUE
)
14231 return "HP_OPAQUE";
14232 if (type
== STT_HP_STUB
)
14236 if (type
== STT_GNU_IFUNC
14237 && (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_GNU
14238 || filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_FREEBSD
))
14241 snprintf (buff
, sizeof (buff
), _("<OS specific>: %d"), type
);
14244 snprintf (buff
, sizeof (buff
), _("<unknown>: %d"), type
);
14249 static const char *
14250 get_symbol_visibility (unsigned int visibility
)
14252 switch (visibility
)
14254 case STV_DEFAULT
: return "DEFAULT";
14255 case STV_INTERNAL
: return "INTERNAL";
14256 case STV_HIDDEN
: return "HIDDEN";
14257 case STV_PROTECTED
: return "PROTECTED";
14259 error (_("Unrecognized visibility value: %u\n"), visibility
);
14260 return _("<unknown>");
14264 static const char *
14265 get_alpha_symbol_other (unsigned int other
)
14269 case STO_ALPHA_NOPV
: return "NOPV";
14270 case STO_ALPHA_STD_GPLOAD
: return "STD GPLOAD";
14272 error (_("Unrecognized alpha specific other value: %u\n"), other
);
14273 return _("<unknown>");
14277 static const char *
14278 get_solaris_symbol_visibility (unsigned int visibility
)
14280 switch (visibility
)
14282 case 4: return "EXPORTED";
14283 case 5: return "SINGLETON";
14284 case 6: return "ELIMINATE";
14285 default: return get_symbol_visibility (visibility
);
14289 static const char *
14290 get_aarch64_symbol_other (unsigned int other
)
14292 static char buf
[32];
14294 if (other
& STO_AARCH64_VARIANT_PCS
)
14296 other
&= ~STO_AARCH64_VARIANT_PCS
;
14298 return "VARIANT_PCS";
14299 snprintf (buf
, sizeof buf
, "VARIANT_PCS | %x", other
);
14305 static const char *
14306 get_mips_symbol_other (unsigned int other
)
14310 case STO_OPTIONAL
: return "OPTIONAL";
14311 case STO_MIPS_PLT
: return "MIPS PLT";
14312 case STO_MIPS_PIC
: return "MIPS PIC";
14313 case STO_MICROMIPS
: return "MICROMIPS";
14314 case STO_MICROMIPS
| STO_MIPS_PIC
: return "MICROMIPS, MIPS PIC";
14315 case STO_MIPS16
: return "MIPS16";
14316 default: return NULL
;
14320 static const char *
14321 get_ia64_symbol_other (Filedata
* filedata
, unsigned int other
)
14323 if (is_ia64_vms (filedata
))
14325 static char res
[32];
14329 /* Function types is for images and .STB files only. */
14330 switch (filedata
->file_header
.e_type
)
14334 switch (VMS_ST_FUNC_TYPE (other
))
14336 case VMS_SFT_CODE_ADDR
:
14337 strcat (res
, " CA");
14339 case VMS_SFT_SYMV_IDX
:
14340 strcat (res
, " VEC");
14343 strcat (res
, " FD");
14345 case VMS_SFT_RESERVE
:
14346 strcat (res
, " RSV");
14349 warn (_("Unrecognized IA64 VMS ST Function type: %d\n"),
14350 VMS_ST_FUNC_TYPE (other
));
14351 strcat (res
, " <unknown>");
14358 switch (VMS_ST_LINKAGE (other
))
14360 case VMS_STL_IGNORE
:
14361 strcat (res
, " IGN");
14363 case VMS_STL_RESERVE
:
14364 strcat (res
, " RSV");
14367 strcat (res
, " STD");
14370 strcat (res
, " LNK");
14373 warn (_("Unrecognized IA64 VMS ST Linkage: %d\n"),
14374 VMS_ST_LINKAGE (other
));
14375 strcat (res
, " <unknown>");
14387 static const char *
14388 get_ppc64_symbol_other (unsigned int other
)
14390 if ((other
& ~STO_PPC64_LOCAL_MASK
) != 0)
14393 other
>>= STO_PPC64_LOCAL_BIT
;
14396 static char buf
[64];
14398 other
= ppc64_decode_local_entry (other
);
14399 snprintf (buf
, sizeof buf
, _("<localentry>: %d"), other
);
14405 static const char *
14406 get_riscv_symbol_other (unsigned int other
)
14408 static char buf
[32];
14411 if (other
& STO_RISCV_VARIANT_CC
)
14413 strcat (buf
, _(" VARIANT_CC"));
14414 other
&= ~STO_RISCV_VARIANT_CC
;
14418 snprintf (buf
, sizeof buf
, " %x", other
);
14427 static const char *
14428 get_symbol_other (Filedata
* filedata
, unsigned int other
)
14430 const char * result
= NULL
;
14431 static char buff
[64];
14436 switch (filedata
->file_header
.e_machine
)
14439 result
= get_alpha_symbol_other (other
);
14442 result
= get_aarch64_symbol_other (other
);
14445 result
= get_mips_symbol_other (other
);
14448 result
= get_ia64_symbol_other (filedata
, other
);
14451 result
= get_ppc64_symbol_other (other
);
14454 result
= get_riscv_symbol_other (other
);
14464 snprintf (buff
, sizeof buff
, _("<other>: %x"), other
);
14468 static const char *
14469 get_symbol_version_string (Filedata
*filedata
,
14471 const char *strtab
,
14472 size_t strtab_size
,
14474 Elf_Internal_Sym
*psym
,
14475 enum versioned_symbol_info
*sym_info
,
14476 unsigned short *vna_other
)
14478 unsigned char data
[2];
14479 unsigned short vers_data
;
14481 unsigned short max_vd_ndx
;
14484 || filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)] == 0)
14487 offset
= offset_from_vma (filedata
,
14488 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)],
14489 sizeof data
+ si
* sizeof (vers_data
));
14491 if (get_data (&data
, filedata
, offset
+ si
* sizeof (vers_data
),
14492 sizeof (data
), 1, _("version data")) == NULL
)
14495 vers_data
= byte_get (data
, 2);
14497 if ((vers_data
& VERSYM_HIDDEN
) == 0 && vers_data
== 0)
14500 *sym_info
= (vers_data
& VERSYM_HIDDEN
) != 0 ? symbol_hidden
: symbol_public
;
14503 /* Return the empty string for the base version. */
14504 if ((vers_data
& VERSYM_VERSION
) == VERSYM_BASE
)
14507 /* Usually we'd only see verdef for defined symbols, and verneed for
14508 undefined symbols. However, symbols defined by the linker in
14509 .dynbss for variables copied from a shared library in order to
14510 avoid text relocations are defined yet have verneed. We could
14511 use a heuristic to detect the special case, for example, check
14512 for verneed first on symbols defined in SHT_NOBITS sections, but
14513 it is simpler and more reliable to just look for both verdef and
14514 verneed. .dynbss might not be mapped to a SHT_NOBITS section. */
14516 if (psym
->st_shndx
!= SHN_UNDEF
14517 && vers_data
!= (VERSYM_HIDDEN
| VERSYM_BASE
)
14518 && filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
14520 Elf_Internal_Verdef ivd
;
14521 Elf_Internal_Verdaux ivda
;
14522 Elf_External_Verdaux evda
;
14525 off
= offset_from_vma (filedata
,
14526 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)],
14527 sizeof (Elf_External_Verdef
));
14531 Elf_External_Verdef evd
;
14533 if (get_data (&evd
, filedata
, off
, sizeof (evd
), 1,
14534 _("version def")) == NULL
)
14543 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
14544 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
14545 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
14546 ivd
.vd_flags
= BYTE_GET (evd
.vd_flags
);
14549 if ((ivd
.vd_ndx
& VERSYM_VERSION
) > max_vd_ndx
)
14550 max_vd_ndx
= ivd
.vd_ndx
& VERSYM_VERSION
;
14552 off
+= ivd
.vd_next
;
14554 while (ivd
.vd_ndx
!= (vers_data
& VERSYM_VERSION
) && ivd
.vd_next
!= 0);
14556 if (ivd
.vd_ndx
== (vers_data
& VERSYM_VERSION
))
14558 if (ivd
.vd_ndx
== 1 && ivd
.vd_flags
== VER_FLG_BASE
)
14561 off
-= ivd
.vd_next
;
14564 if (get_data (&evda
, filedata
, off
, sizeof (evda
), 1,
14565 _("version def aux")) != NULL
)
14567 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
14569 if (psym
->st_name
!= ivda
.vda_name
)
14570 return (ivda
.vda_name
< strtab_size
14571 ? strtab
+ ivda
.vda_name
: _("<corrupt>"));
14576 if (filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)])
14578 Elf_External_Verneed evn
;
14579 Elf_Internal_Verneed ivn
;
14580 Elf_Internal_Vernaux ivna
;
14582 offset
= offset_from_vma (filedata
,
14583 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)],
14589 if (get_data (&evn
, filedata
, offset
, sizeof (evn
), 1,
14590 _("version need")) == NULL
)
14593 ivna
.vna_other
= 0;
14598 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
14599 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
14601 vna_off
= offset
+ ivn
.vn_aux
;
14605 Elf_External_Vernaux evna
;
14607 if (get_data (&evna
, filedata
, vna_off
, sizeof (evna
), 1,
14608 _("version need aux (3)")) == NULL
)
14611 ivna
.vna_other
= 0;
14616 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
14617 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
14618 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
14621 vna_off
+= ivna
.vna_next
;
14623 while (ivna
.vna_other
!= vers_data
&& ivna
.vna_next
!= 0);
14625 if (ivna
.vna_other
== vers_data
)
14628 offset
+= ivn
.vn_next
;
14630 while (ivn
.vn_next
!= 0);
14632 if (ivna
.vna_other
== vers_data
)
14634 *sym_info
= symbol_undefined
;
14635 *vna_other
= ivna
.vna_other
;
14636 return (ivna
.vna_name
< strtab_size
14637 ? strtab
+ ivna
.vna_name
: _("<corrupt>"));
14639 else if ((max_vd_ndx
|| (vers_data
& VERSYM_VERSION
) != 1)
14640 && (vers_data
& VERSYM_VERSION
) > max_vd_ndx
)
14641 return _("<corrupt>");
14646 /* Display a symbol size on stdout. Format is based on --sym-base setting. */
14648 static unsigned int
14649 print_symbol_size (uint64_t vma
, int base
)
14654 return print_vma (vma
, OCTAL_5
);
14657 return print_vma (vma
, UNSIGNED_5
);
14660 return print_vma (vma
, PREFIX_HEX_5
);
14664 return print_vma (vma
, DEC_5
);
14668 /* Print information on a single symbol. */
14671 print_symbol (Filedata
* filedata
,
14672 uint64_t symbol_index
,
14673 Elf_Internal_Sym
* symtab
,
14674 Elf_Internal_Shdr
* section
,
14676 size_t strtab_size
)
14678 const char *version_string
;
14679 enum versioned_symbol_info sym_info
;
14680 unsigned short vna_other
;
14682 Elf_Internal_Sym
*psym
= symtab
+ symbol_index
;
14684 /* FIXME: We should have a table of field widths,
14685 rather than using hard coded constants. */
14686 printf ("%6" PRId64
": ", symbol_index
);
14687 print_vma (psym
->st_value
, LONG_HEX
);
14689 print_symbol_size (psym
->st_size
, sym_base
);
14690 printf (" %-7s", get_symbol_type (filedata
, ELF_ST_TYPE (psym
->st_info
)));
14691 printf (" %-6s", get_symbol_binding (filedata
, ELF_ST_BIND (psym
->st_info
)));
14692 if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_SOLARIS
)
14693 printf (" %-7s", get_solaris_symbol_visibility (psym
->st_other
));
14696 unsigned int vis
= ELF_ST_VISIBILITY (psym
->st_other
);
14698 printf (" %-7s", get_symbol_visibility (vis
));
14700 /* Check to see if any other bits in the st_other field are set.
14701 FIXME: Displaying this information here disrupts the layout
14702 of the table being generated. */
14703 if (psym
->st_other
^ vis
)
14704 printf (" [%s] ", get_symbol_other (filedata
, psym
->st_other
^ vis
));
14709 sstr
= printable_section_name_from_index (filedata
, psym
->st_shndx
, & is_special
);
14711 /* Print the symbol's section index. If the index is special
14712 then print the index's name rather than its number. */
14717 /* Special case: If there are no section headers, and the printable
14718 name is "<section 0x...." then just display the section number
14719 as a decimal. This happens when objcopy --strip -section-headers
14721 if (filedata
->file_header
.e_shnum
== 0 && startswith (sstr
, "<section"))
14722 printed
= printf (" %4d ", psym
->st_shndx
);
14724 printed
= printf (" %4s ", sstr
);
14726 if (extra_sym_info
&& printed
< 16)
14727 printf ("%*s", 16 - printed
, "");
14731 printf (" %4u ", psym
->st_shndx
);
14733 if (extra_sym_info
)
14735 /* Display the section name referenced by the section index. */
14736 int printed
= printf ("(%s) ", sstr
);
14738 printf ("%*s", 10 - printed
, "");
14742 /* Get the symbol's name. For section symbols without a
14743 specific name use the (already computed) section name. */
14744 if (ELF_ST_TYPE (psym
->st_info
) == STT_SECTION
14745 && section_index_real (filedata
, psym
->st_shndx
)
14746 && psym
->st_name
== 0)
14754 is_valid
= valid_symbol_name (strtab
, strtab_size
, psym
->st_name
);
14755 sstr
= is_valid
? strtab
+ psym
->st_name
: _("<corrupt>");
14759 = get_symbol_version_string (filedata
,
14761 || section
->sh_type
== SHT_DYNSYM
),
14762 strtab
, strtab_size
, symbol_index
,
14763 psym
, &sym_info
, &vna_other
);
14765 int len_avail
= 21;
14766 if (! do_wide
&& version_string
!= NULL
)
14770 len_avail
-= 1 + strlen (version_string
);
14772 if (sym_info
== symbol_undefined
)
14773 len_avail
-= sprintf (buffer
," (%d)", vna_other
);
14774 else if (sym_info
!= symbol_hidden
)
14778 print_symbol_name (len_avail
, sstr
);
14780 if (version_string
)
14782 if (sym_info
== symbol_undefined
)
14783 printf ("@%s (%d)", version_string
, vna_other
);
14785 printf (sym_info
== symbol_hidden
? "@%s" : "@@%s",
14791 if (ELF_ST_BIND (psym
->st_info
) == STB_LOCAL
14793 && symbol_index
>= section
->sh_info
14794 /* Irix 5 and 6 MIPS binaries are known to ignore this requirement. */
14795 && filedata
->file_header
.e_machine
!= EM_MIPS
14796 /* Solaris binaries have been found to violate this requirement as
14797 well. Not sure if this is a bug or an ABI requirement. */
14798 && filedata
->file_header
.e_ident
[EI_OSABI
] != ELFOSABI_SOLARIS
)
14799 warn (_("local symbol %" PRIu64
" found at index >= %s's sh_info value of %u\n"),
14800 symbol_index
, printable_section_name (filedata
, section
), section
->sh_info
);
14803 static const char *
14804 get_lto_kind (unsigned int kind
)
14808 case 0: return "DEF";
14809 case 1: return "WEAKDEF";
14810 case 2: return "UNDEF";
14811 case 3: return "WEAKUNDEF";
14812 case 4: return "COMMON";
14817 static char buffer
[30];
14818 error (_("Unknown LTO symbol definition encountered: %u\n"), kind
);
14819 sprintf (buffer
, "<unknown: %u>", kind
);
14823 static const char *
14824 get_lto_visibility (unsigned int visibility
)
14826 switch (visibility
)
14828 case 0: return "DEFAULT";
14829 case 1: return "PROTECTED";
14830 case 2: return "INTERNAL";
14831 case 3: return "HIDDEN";
14836 static char buffer
[30];
14837 error (_("Unknown LTO symbol visibility encountered: %u\n"), visibility
);
14838 sprintf (buffer
, "<unknown: %u>", visibility
);
14842 static const char *
14843 get_lto_sym_type (unsigned int sym_type
)
14847 case 0: return "UNKNOWN";
14848 case 1: return "FUNCTION";
14849 case 2: return "VARIABLE";
14854 static char buffer
[30];
14855 error (_("Unknown LTO symbol type encountered: %u\n"), sym_type
);
14856 sprintf (buffer
, "<unknown: %u>", sym_type
);
14860 /* Display an LTO format symbol table.
14861 FIXME: The format of LTO symbol tables is not formalized.
14862 So this code could need changing in the future. */
14865 display_lto_symtab (Filedata
* filedata
,
14866 Elf_Internal_Shdr
* section
)
14868 if (section
->sh_size
== 0)
14870 if (filedata
->is_separate
)
14871 printf (_("\nThe LTO Symbol table section '%s' in linked file '%s' is empty!\n"),
14872 printable_section_name (filedata
, section
),
14873 filedata
->file_name
);
14875 printf (_("\nLTO Symbol table '%s' is empty!\n"),
14876 printable_section_name (filedata
, section
));
14881 if (section
->sh_size
> filedata
->file_size
)
14883 error (_("Section %s has an invalid sh_size of %#" PRIx64
"\n"),
14884 printable_section_name (filedata
, section
),
14889 void * alloced_data
= get_data (NULL
, filedata
, section
->sh_offset
,
14890 section
->sh_size
, 1, _("LTO symbols"));
14891 if (alloced_data
== NULL
)
14894 /* Look for extended data for the symbol table. */
14895 void * ext_data_orig
= NULL
;
14896 char * ext_data
= NULL
;
14897 char * ext_data_end
= NULL
;
14898 char *ext_name
= xasprintf (".gnu.lto_.ext_symtab.%s",
14899 (section_name (filedata
, section
)
14900 + sizeof (".gnu.lto_.symtab.")));
14901 Elf_Internal_Shdr
*ext
= find_section (filedata
, ext_name
);
14904 if (ext
->sh_size
< 3)
14905 error (_("LTO Symbol extension table '%s' is empty!\n"),
14906 printable_section_name (filedata
, ext
));
14909 ext_data_orig
= ext_data
= get_data (NULL
, filedata
, ext
->sh_offset
,
14911 _("LTO ext symbol data"));
14912 if (ext_data
!= NULL
)
14914 ext_data_end
= ext_data
+ ext
->sh_size
;
14915 if (* ext_data
++ != 1)
14916 error (_("Unexpected version number in symbol extension table\n"));
14921 const unsigned char * data
= (const unsigned char *) alloced_data
;
14922 const unsigned char * end
= data
+ section
->sh_size
;
14924 if (filedata
->is_separate
)
14925 printf (_("\nIn linked file '%s': "), filedata
->file_name
);
14929 if (ext_data_orig
!= NULL
)
14932 printf (_("LTO Symbol table '%s' and extension table '%s' contain:\n"),
14933 printable_section_name (filedata
, section
),
14934 printable_section_name (filedata
, ext
));
14937 printf (_("LTO Symbol table '%s'\n"),
14938 printable_section_name (filedata
, section
));
14939 printf (_(" and extension table '%s' contain:\n"),
14940 printable_section_name (filedata
, ext
));
14944 printf (_("LTO Symbol table '%s' contains:\n"),
14945 printable_section_name (filedata
, section
));
14947 /* FIXME: Add a wide version. */
14948 if (ext_data_orig
!= NULL
)
14949 printf (_(" Comdat_Key Kind Visibility Size Slot Type Section Name\n"));
14951 printf (_(" Comdat_Key Kind Visibility Size Slot Name\n"));
14953 /* FIXME: We do not handle style prefixes. */
14957 const unsigned char * sym_name
= data
;
14958 data
+= strnlen ((const char *) sym_name
, end
- data
) + 1;
14962 const unsigned char * comdat_key
= data
;
14963 data
+= strnlen ((const char *) comdat_key
, end
- data
) + 1;
14967 if (data
+ 2 + 8 + 4 > end
)
14970 unsigned int kind
= *data
++;
14971 unsigned int visibility
= *data
++;
14973 uint64_t size
= byte_get (data
, 8);
14976 uint64_t slot
= byte_get (data
, 4);
14979 if (ext_data
!= NULL
)
14981 if (ext_data
< (ext_data_end
- 1))
14983 unsigned int sym_type
= * ext_data
++;
14984 unsigned int sec_kind
= * ext_data
++;
14986 printf (" %10s %10s %11s %08" PRIx64
" %08" PRIx64
" %9s %08x _",
14987 * comdat_key
== 0 ? "-" : (char *) comdat_key
,
14988 get_lto_kind (kind
),
14989 get_lto_visibility (visibility
),
14992 get_lto_sym_type (sym_type
),
14994 print_symbol_name (6, (const char *) sym_name
);
14998 error (_("Ran out of LTO symbol extension data\n"));
15000 /* FIXME: return FAIL result ? */
15005 printf (" %10s %10s %11s %08" PRIx64
" %08" PRIx64
" _",
15006 * comdat_key
== 0 ? "-" : (char *) comdat_key
,
15007 get_lto_kind (kind
),
15008 get_lto_visibility (visibility
),
15011 print_symbol_name (21, (const char *) sym_name
);
15016 if (ext_data
!= NULL
&& ext_data
< ext_data_end
)
15018 error (_("Data remains in the LTO symbol extension table\n"));
15022 free (alloced_data
);
15023 free (ext_data_orig
);
15028 error (_("Buffer overrun encountered whilst decoding LTO symbol table\n"));
15029 free (alloced_data
);
15030 free (ext_data_orig
);
15035 /* Display LTO symbol tables. */
15038 process_lto_symbol_tables (Filedata
* filedata
)
15040 Elf_Internal_Shdr
* section
;
15047 if (filedata
->section_headers
== NULL
)
15050 for (i
= 0, section
= filedata
->section_headers
;
15051 i
< filedata
->file_header
.e_shnum
;
15053 if (section_name_valid (filedata
, section
)
15054 && startswith (section_name (filedata
, section
), ".gnu.lto_.symtab."))
15055 res
&= display_lto_symtab (filedata
, section
);
15061 print_symbol_table_heading (void)
15063 /* FIXME: We should store the size of each field in the display in a table and
15064 then use the values inside print_symbol(), instead of that function using
15065 hard coded constants. */
15068 if (extra_sym_info
)
15070 printf (_(" Num: Value Size Type Bind Vis+Other Ndx(SecName) Name [+ Version Info]\n"));
15071 /* |--6-|: |--8---| |-5-| |--7--| |-6--| |--7--| |---8--| |----13.....| |........... */
15072 /* eg: 5: 00000000 14 FUNC LOCAL DEFAULT 1 (.text) get_sections */
15076 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
15077 /* |--6-|: |--8---| |-5-| |--7--| |-6--| |--7--| |-4| |........... */
15078 /* eg: 5: 00000000 14 FUNC LOCAL DEFAULT 1 get_sections */
15082 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
15083 /* |--6-|: |--8---| |-5-| |--7--| |-6--| |--7--| |-4| |------------29-------------| */
15084 /* eg: 5: 00000000 14 FUNC LOCAL DEFAULT 1 get_sections */
15089 if (extra_sym_info
)
15091 printf (_(" Num: Value Size Type Bind Vis+Other Ndx(SecName) Name [+ Version Info]\n"));
15092 /* |--6-|: |------16------| |-5-| |--7--| |-6--| |--7--| |-------14---| |..... */
15093 /* eg: 2: 0000000000000000 0 FUNC LOCAL DEFAULT 1 (.text) .very_long_function_name */
15098 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
15099 /* |--6-|: |------16------| |-5-| |--7--| |-6--| |--7--| |-4| |........... */
15100 /* eg: 5: 0000000000000000 14 FUNC LOCAL DEFAULT 1 very_long_function_name */
15104 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
15105 /* |--6-|: |------16------| |-5-| |--7--| |-6--| |--7--| |-4| |--------21---------| */
15106 /* eg: 5: 0000000000000000 14 FUNC LOCAL DEFAULT 1 very_long_functi[...] */
15112 dump_symbol_section (Elf_Internal_Shdr
* section
,
15113 Filedata
* filedata
)
15115 if (section
->sh_entsize
== 0)
15117 printf (_("\nSymbol table '%s' has a sh_entsize of zero!\n"),
15118 printable_section_name (filedata
, section
));
15122 uint64_t num_syms
= section
->sh_size
/ section
->sh_entsize
;
15124 if (filedata
->is_separate
)
15125 printf (ngettext ("\nIn linked file '%s' symbol section '%s'"
15126 " contains %" PRIu64
" entry:\n",
15127 "\nIn linked file '%s' symbol section '%s'"
15128 " contains %" PRIu64
" entries:\n",
15130 filedata
->file_name
,
15131 printable_section_name (filedata
, section
),
15134 printf (ngettext ("\nSymbol table '%s' contains %" PRIu64
15136 "\nSymbol table '%s' contains %" PRIu64
15139 printable_section_name (filedata
, section
),
15142 print_symbol_table_heading ();
15144 Elf_Internal_Sym
* symtab
= get_elf_symbols (filedata
, section
, & num_syms
);
15145 if (symtab
== NULL
)
15146 /* An error message will have already been displayed. */
15149 char * strtab
= NULL
;
15150 uint64_t strtab_size
= 0;
15152 if (section
->sh_link
== filedata
->file_header
.e_shstrndx
)
15154 strtab
= filedata
->string_table
;
15155 strtab_size
= filedata
->string_table_length
;
15157 else if (section
->sh_link
< filedata
->file_header
.e_shnum
)
15159 Elf_Internal_Shdr
* string_sec
;
15161 string_sec
= filedata
->section_headers
+ section
->sh_link
;
15163 strtab
= (char *) get_data (NULL
, filedata
, string_sec
->sh_offset
,
15164 1, string_sec
->sh_size
,
15165 _("string table"));
15166 strtab_size
= strtab
!= NULL
? string_sec
->sh_size
: 0;
15171 for (si
= 0; si
< num_syms
; si
++)
15172 print_symbol (filedata
, si
, symtab
, section
, strtab
, strtab_size
);
15176 if (strtab
!= filedata
->string_table
)
15182 /* Dump the symbol table. */
15185 process_symbol_table (Filedata
* filedata
)
15187 Elf_Internal_Shdr
* section
;
15189 if (!do_syms
&& !do_dyn_syms
&& !do_histogram
)
15192 if ((filedata
->dynamic_info
[DT_HASH
] || filedata
->dynamic_info_DT_GNU_HASH
)
15194 && do_using_dynamic
15195 && filedata
->dynamic_strings
!= NULL
15196 && filedata
->dynamic_symbols
!= NULL
)
15200 if (filedata
->is_separate
)
15202 printf (ngettext ("\nIn linked file '%s' the dynamic symbol table"
15203 " contains %" PRIu64
" entry:\n",
15204 "\nIn linked file '%s' the dynamic symbol table"
15205 " contains %" PRIu64
" entries:\n",
15206 filedata
->num_dynamic_syms
),
15207 filedata
->file_name
,
15208 filedata
->num_dynamic_syms
);
15212 printf (ngettext ("\nSymbol table for image contains %" PRIu64
15214 "\nSymbol table for image contains %" PRIu64
15216 filedata
->num_dynamic_syms
),
15217 filedata
->num_dynamic_syms
);
15220 print_symbol_table_heading ();
15222 for (si
= 0; si
< filedata
->num_dynamic_syms
; si
++)
15223 print_symbol (filedata
, si
, filedata
->dynamic_symbols
, NULL
,
15224 filedata
->dynamic_strings
,
15225 filedata
->dynamic_strings_length
);
15227 else if ((do_dyn_syms
|| (do_syms
&& !do_using_dynamic
))
15228 && filedata
->section_headers
!= NULL
)
15232 for (i
= 0, section
= filedata
->section_headers
;
15233 i
< filedata
->file_header
.e_shnum
;
15236 if ((section
->sh_type
!= SHT_SYMTAB
15237 && section
->sh_type
!= SHT_DYNSYM
)
15239 && section
->sh_type
== SHT_SYMTAB
))
15242 dump_symbol_section (section
, filedata
);
15247 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
15249 if (do_histogram
&& filedata
->buckets
!= NULL
)
15255 uint64_t maxlength
= 0;
15256 uint64_t nzero_counts
= 0;
15257 uint64_t nsyms
= 0;
15260 printf (ngettext ("\nHistogram for bucket list length "
15261 "(total of %" PRIu64
" bucket):\n",
15262 "\nHistogram for bucket list length "
15263 "(total of %" PRIu64
" buckets):\n",
15264 filedata
->nbuckets
),
15265 filedata
->nbuckets
);
15267 lengths
= calloc (filedata
->nbuckets
, sizeof (*lengths
));
15268 if (lengths
== NULL
)
15270 error (_("Out of memory allocating space for histogram buckets\n"));
15273 visited
= xcmalloc (filedata
->nchains
, 1);
15274 memset (visited
, 0, filedata
->nchains
);
15276 printf (_(" Length Number %% of total Coverage\n"));
15277 for (hn
= 0; hn
< filedata
->nbuckets
; ++hn
)
15279 for (si
= filedata
->buckets
[hn
]; si
> 0; si
= filedata
->chains
[si
])
15282 if (maxlength
< ++lengths
[hn
])
15284 if (si
>= filedata
->nchains
|| visited
[si
])
15286 error (_("histogram chain is corrupt\n"));
15294 counts
= calloc (maxlength
+ 1, sizeof (*counts
));
15295 if (counts
== NULL
)
15298 error (_("Out of memory allocating space for histogram counts\n"));
15302 for (hn
= 0; hn
< filedata
->nbuckets
; ++hn
)
15303 ++counts
[lengths
[hn
]];
15305 if (filedata
->nbuckets
> 0)
15308 printf (" 0 %-10" PRIu64
" (%5.1f%%)\n",
15309 counts
[0], (counts
[0] * 100.0) / filedata
->nbuckets
);
15310 for (i
= 1; i
<= maxlength
; ++i
)
15312 nzero_counts
+= counts
[i
] * i
;
15313 printf ("%7" PRIu64
" %-10" PRIu64
" (%5.1f%%) %5.1f%%\n",
15314 i
, counts
[i
], (counts
[i
] * 100.0) / filedata
->nbuckets
,
15315 (nzero_counts
* 100.0) / nsyms
);
15323 free (filedata
->buckets
);
15324 filedata
->buckets
= NULL
;
15325 filedata
->nbuckets
= 0;
15326 free (filedata
->chains
);
15327 filedata
->chains
= NULL
;
15329 if (do_histogram
&& filedata
->gnubuckets
!= NULL
)
15334 uint64_t maxlength
= 0;
15335 uint64_t nzero_counts
= 0;
15336 uint64_t nsyms
= 0;
15338 printf (ngettext ("\nHistogram for `%s' bucket list length "
15339 "(total of %" PRIu64
" bucket):\n",
15340 "\nHistogram for `%s' bucket list length "
15341 "(total of %" PRIu64
" buckets):\n",
15342 filedata
->ngnubuckets
),
15343 GNU_HASH_SECTION_NAME (filedata
),
15344 filedata
->ngnubuckets
);
15346 lengths
= calloc (filedata
->ngnubuckets
, sizeof (*lengths
));
15347 if (lengths
== NULL
)
15349 error (_("Out of memory allocating space for gnu histogram buckets\n"));
15353 printf (_(" Length Number %% of total Coverage\n"));
15355 for (hn
= 0; hn
< filedata
->ngnubuckets
; ++hn
)
15356 if (filedata
->gnubuckets
[hn
] != 0)
15358 uint64_t off
, length
= 1;
15360 for (off
= filedata
->gnubuckets
[hn
] - filedata
->gnusymidx
;
15361 /* PR 17531 file: 010-77222-0.004. */
15362 off
< filedata
->ngnuchains
15363 && (filedata
->gnuchains
[off
] & 1) == 0;
15366 lengths
[hn
] = length
;
15367 if (length
> maxlength
)
15368 maxlength
= length
;
15372 counts
= calloc (maxlength
+ 1, sizeof (*counts
));
15373 if (counts
== NULL
)
15376 error (_("Out of memory allocating space for gnu histogram counts\n"));
15380 for (hn
= 0; hn
< filedata
->ngnubuckets
; ++hn
)
15381 ++counts
[lengths
[hn
]];
15383 if (filedata
->ngnubuckets
> 0)
15386 printf (" 0 %-10" PRIu64
" (%5.1f%%)\n",
15387 counts
[0], (counts
[0] * 100.0) / filedata
->ngnubuckets
);
15388 for (j
= 1; j
<= maxlength
; ++j
)
15390 nzero_counts
+= counts
[j
] * j
;
15391 printf ("%7" PRIu64
" %-10" PRIu64
" (%5.1f%%) %5.1f%%\n",
15392 j
, counts
[j
], (counts
[j
] * 100.0) / filedata
->ngnubuckets
,
15393 (nzero_counts
* 100.0) / nsyms
);
15400 free (filedata
->gnubuckets
);
15401 filedata
->gnubuckets
= NULL
;
15402 filedata
->ngnubuckets
= 0;
15403 free (filedata
->gnuchains
);
15404 filedata
->gnuchains
= NULL
;
15405 filedata
->ngnuchains
= 0;
15406 free (filedata
->mipsxlat
);
15407 filedata
->mipsxlat
= NULL
;
15411 free (filedata
->gnubuckets
);
15412 filedata
->gnubuckets
= NULL
;
15413 filedata
->ngnubuckets
= 0;
15414 free (filedata
->gnuchains
);
15415 filedata
->gnuchains
= NULL
;
15416 filedata
->ngnuchains
= 0;
15417 free (filedata
->mipsxlat
);
15418 filedata
->mipsxlat
= NULL
;
15419 free (filedata
->buckets
);
15420 filedata
->buckets
= NULL
;
15421 filedata
->nbuckets
= 0;
15422 free (filedata
->chains
);
15423 filedata
->chains
= NULL
;
15428 process_syminfo (Filedata
* filedata
)
15432 if (filedata
->dynamic_syminfo
== NULL
15434 /* No syminfo, this is ok. */
15437 /* There better should be a dynamic symbol section. */
15438 if (filedata
->dynamic_symbols
== NULL
|| filedata
->dynamic_strings
== NULL
)
15441 if (filedata
->is_separate
)
15442 printf (ngettext ("\nIn linked file '%s: the dynamic info segment at offset %#" PRIx64
" contains %d entry:\n",
15443 "\nIn linked file '%s: the dynamic info segment at offset %#" PRIx64
" contains %d entries:\n",
15444 filedata
->dynamic_syminfo_nent
),
15445 filedata
->file_name
,
15446 filedata
->dynamic_syminfo_offset
,
15447 filedata
->dynamic_syminfo_nent
);
15449 printf (ngettext ("\nDynamic info segment at offset %#" PRIx64
15450 " contains %d entry:\n",
15451 "\nDynamic info segment at offset %#" PRIx64
15452 " contains %d entries:\n",
15453 filedata
->dynamic_syminfo_nent
),
15454 filedata
->dynamic_syminfo_offset
,
15455 filedata
->dynamic_syminfo_nent
);
15457 printf (_(" Num: Name BoundTo Flags\n"));
15458 for (i
= 0; i
< filedata
->dynamic_syminfo_nent
; ++i
)
15460 unsigned short int flags
= filedata
->dynamic_syminfo
[i
].si_flags
;
15462 printf ("%4d: ", i
);
15463 if (i
>= filedata
->num_dynamic_syms
)
15464 printf (_("<corrupt index>"));
15465 else if (valid_dynamic_name (filedata
, filedata
->dynamic_symbols
[i
].st_name
))
15466 print_symbol_name (30, get_dynamic_name (filedata
,
15467 filedata
->dynamic_symbols
[i
].st_name
));
15469 printf (_("<corrupt: %19ld>"), filedata
->dynamic_symbols
[i
].st_name
);
15472 switch (filedata
->dynamic_syminfo
[i
].si_boundto
)
15474 case SYMINFO_BT_SELF
:
15475 fputs ("SELF ", stdout
);
15477 case SYMINFO_BT_PARENT
:
15478 fputs ("PARENT ", stdout
);
15481 if (filedata
->dynamic_syminfo
[i
].si_boundto
> 0
15482 && filedata
->dynamic_syminfo
[i
].si_boundto
< filedata
->dynamic_nent
15483 && valid_dynamic_name (filedata
,
15484 filedata
->dynamic_section
[filedata
->dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
))
15486 print_symbol_name (10, get_dynamic_name (filedata
,
15487 filedata
->dynamic_section
[filedata
->dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
));
15491 printf ("%-10d ", filedata
->dynamic_syminfo
[i
].si_boundto
);
15495 if (flags
& SYMINFO_FLG_DIRECT
)
15496 printf (" DIRECT");
15497 if (flags
& SYMINFO_FLG_PASSTHRU
)
15498 printf (" PASSTHRU");
15499 if (flags
& SYMINFO_FLG_COPY
)
15501 if (flags
& SYMINFO_FLG_LAZYLOAD
)
15502 printf (" LAZYLOAD");
15510 /* Check that reloc at R_OFFSET of size R_SIZE can apply to LEN bytes. */
15513 in_range (size_t len
, bfd_vma r_offset
, unsigned int r_size
)
15515 return r_offset
<= len
&& r_size
<= len
- r_offset
;
15518 /* Check to see if the given reloc needs to be handled in a target specific
15519 manner. If so then process the reloc and return TRUE otherwise return
15522 If called with reloc == NULL, then this is a signal that reloc processing
15523 for the current section has finished, and any saved state should be
15527 target_specific_reloc_handling (Filedata
*filedata
,
15528 Elf_Internal_Rela
*reloc
,
15529 unsigned char *start
,
15531 Elf_Internal_Sym
*symtab
,
15534 unsigned int reloc_type
= 0;
15535 uint64_t sym_index
= 0;
15539 reloc_type
= get_reloc_type (filedata
, reloc
->r_info
);
15540 sym_index
= get_reloc_symindex (reloc
->r_info
);
15543 switch (filedata
->file_header
.e_machine
)
15547 switch (reloc_type
)
15549 /* For .uleb128 .LFE1-.LFB1, loongarch write 0 to object file
15550 at assembly time. */
15551 case 107: /* R_LARCH_ADD_ULEB128. */
15552 case 108: /* R_LARCH_SUB_ULEB128. */
15554 uint64_t value
= 0;
15555 unsigned int reloc_size
= 0;
15558 if (reloc
->r_offset
< size
)
15559 value
= read_leb128 (start
+ reloc
->r_offset
, start
+ size
,
15560 false, &reloc_size
, &leb_ret
);
15561 if (leb_ret
!= 0 || reloc_size
== 0 || reloc_size
> 8)
15562 error (_("LoongArch ULEB128 field at 0x%lx contains invalid "
15563 "ULEB128 value\n"),
15564 (long) reloc
->r_offset
);
15566 else if (sym_index
>= num_syms
)
15567 error (_("%s reloc contains invalid symbol index "
15570 ? "R_LARCH_ADD_ULEB128"
15571 : "R_LARCH_SUB_ULEB128"),
15575 if (reloc_type
== 107)
15576 value
+= reloc
->r_addend
+ symtab
[sym_index
].st_value
;
15578 value
-= reloc
->r_addend
+ symtab
[sym_index
].st_value
;
15580 /* Write uleb128 value to p. */
15581 bfd_byte
*p
= start
+ reloc
->r_offset
;
15584 bfd_byte c
= value
& 0x7f;
15586 if (--reloc_size
!= 0)
15590 while (reloc_size
);
15600 case EM_MSP430_OLD
:
15602 static Elf_Internal_Sym
* saved_sym
= NULL
;
15610 switch (reloc_type
)
15612 case 10: /* R_MSP430_SYM_DIFF */
15613 case 12: /* R_MSP430_GNU_SUB_ULEB128 */
15614 if (uses_msp430x_relocs (filedata
))
15616 /* Fall through. */
15617 case 21: /* R_MSP430X_SYM_DIFF */
15618 case 23: /* R_MSP430X_GNU_SUB_ULEB128 */
15620 if (sym_index
>= num_syms
)
15621 error (_("%s reloc contains invalid symbol index "
15622 "%" PRIu64
"\n"), "MSP430 SYM_DIFF", sym_index
);
15624 saved_sym
= symtab
+ sym_index
;
15627 case 1: /* R_MSP430_32 or R_MSP430_ABS32 */
15628 case 3: /* R_MSP430_16 or R_MSP430_ABS8 */
15629 goto handle_sym_diff
;
15631 case 5: /* R_MSP430_16_BYTE */
15632 case 9: /* R_MSP430_8 */
15633 case 11: /* R_MSP430_GNU_SET_ULEB128 */
15634 if (uses_msp430x_relocs (filedata
))
15636 goto handle_sym_diff
;
15638 case 2: /* R_MSP430_ABS16 */
15639 case 15: /* R_MSP430X_ABS16 */
15640 case 22: /* R_MSP430X_GNU_SET_ULEB128 */
15641 if (! uses_msp430x_relocs (filedata
))
15643 goto handle_sym_diff
;
15646 if (saved_sym
!= NULL
)
15649 unsigned int reloc_size
= 0;
15651 switch (reloc_type
)
15653 case 1: /* R_MSP430_32 or R_MSP430_ABS32 */
15656 case 11: /* R_MSP430_GNU_SET_ULEB128 */
15657 case 22: /* R_MSP430X_GNU_SET_ULEB128 */
15658 if (reloc
->r_offset
< size
)
15659 read_leb128 (start
+ reloc
->r_offset
, start
+ size
, false,
15660 &reloc_size
, &leb_ret
);
15667 if (leb_ret
!= 0 || reloc_size
== 0 || reloc_size
> 8)
15668 error (_("MSP430 ULEB128 field at %#" PRIx64
15669 " contains invalid ULEB128 value\n"),
15671 else if (sym_index
>= num_syms
)
15672 error (_("%s reloc contains invalid symbol index "
15673 "%" PRIu64
"\n"), "MSP430", sym_index
);
15676 value
= reloc
->r_addend
+ (symtab
[sym_index
].st_value
15677 - saved_sym
->st_value
);
15679 if (in_range (size
, reloc
->r_offset
, reloc_size
))
15680 byte_put (start
+ reloc
->r_offset
, value
, reloc_size
);
15683 error (_("MSP430 sym diff reloc contains invalid offset: "
15694 if (saved_sym
!= NULL
)
15695 error (_("Unhandled MSP430 reloc type found after SYM_DIFF reloc\n"));
15702 case EM_CYGNUS_MN10300
:
15704 static Elf_Internal_Sym
* saved_sym
= NULL
;
15712 switch (reloc_type
)
15714 case 34: /* R_MN10300_ALIGN */
15716 case 33: /* R_MN10300_SYM_DIFF */
15717 if (sym_index
>= num_syms
)
15718 error (_("%s reloc contains invalid symbol index "
15719 "%" PRIu64
"\n"), "MN10300_SYM_DIFF", sym_index
);
15721 saved_sym
= symtab
+ sym_index
;
15724 case 1: /* R_MN10300_32 */
15725 case 2: /* R_MN10300_16 */
15726 if (saved_sym
!= NULL
)
15728 int reloc_size
= reloc_type
== 1 ? 4 : 2;
15731 if (sym_index
>= num_syms
)
15732 error (_("%s reloc contains invalid symbol index "
15733 "%" PRIu64
"\n"), "MN10300", sym_index
);
15736 value
= reloc
->r_addend
+ (symtab
[sym_index
].st_value
15737 - saved_sym
->st_value
);
15739 if (in_range (size
, reloc
->r_offset
, reloc_size
))
15740 byte_put (start
+ reloc
->r_offset
, value
, reloc_size
);
15742 error (_("MN10300 sym diff reloc contains invalid offset:"
15743 " %#" PRIx64
"\n"),
15752 if (saved_sym
!= NULL
)
15753 error (_("Unhandled MN10300 reloc type found after SYM_DIFF reloc\n"));
15761 static uint64_t saved_sym1
= 0;
15762 static uint64_t saved_sym2
= 0;
15763 static uint64_t value
;
15767 saved_sym1
= saved_sym2
= 0;
15771 switch (reloc_type
)
15773 case 0x80: /* R_RL78_SYM. */
15774 saved_sym1
= saved_sym2
;
15775 if (sym_index
>= num_syms
)
15776 error (_("%s reloc contains invalid symbol index "
15777 "%" PRIu64
"\n"), "RL78_SYM", sym_index
);
15780 saved_sym2
= symtab
[sym_index
].st_value
;
15781 saved_sym2
+= reloc
->r_addend
;
15785 case 0x83: /* R_RL78_OPsub. */
15786 value
= saved_sym1
- saved_sym2
;
15787 saved_sym2
= saved_sym1
= 0;
15791 case 0x41: /* R_RL78_ABS32. */
15792 if (in_range (size
, reloc
->r_offset
, 4))
15793 byte_put (start
+ reloc
->r_offset
, value
, 4);
15795 error (_("RL78 sym diff reloc contains invalid offset: "
15801 case 0x43: /* R_RL78_ABS16. */
15802 if (in_range (size
, reloc
->r_offset
, 2))
15803 byte_put (start
+ reloc
->r_offset
, value
, 2);
15805 error (_("RL78 sym diff reloc contains invalid offset: "
15821 /* Returns TRUE iff RELOC_TYPE is a 32-bit absolute RELA relocation used in
15822 DWARF debug sections. This is a target specific test. Note - we do not
15823 go through the whole including-target-headers-multiple-times route, (as
15824 we have already done with <elf/h8.h>) because this would become very
15825 messy and even then this function would have to contain target specific
15826 information (the names of the relocs instead of their numeric values).
15827 FIXME: This is not the correct way to solve this problem. The proper way
15828 is to have target specific reloc sizing and typing functions created by
15829 the reloc-macros.h header, in the same way that it already creates the
15830 reloc naming functions. */
15833 is_32bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
15835 /* Please keep this table alpha-sorted for ease of visual lookup. */
15836 switch (filedata
->file_header
.e_machine
)
15840 return reloc_type
== 1; /* R_386_32. */
15842 return reloc_type
== 1; /* R_68K_32. */
15844 return reloc_type
== 1; /* R_860_32. */
15846 return reloc_type
== 2; /* R_960_32. */
15848 return (reloc_type
== 258
15849 || reloc_type
== 1); /* R_AARCH64_ABS32 || R_AARCH64_P32_ABS32 */
15851 return reloc_type
== 11; /* R_BPF_DATA_32 */
15852 case EM_ADAPTEVA_EPIPHANY
:
15853 return reloc_type
== 3;
15855 return reloc_type
== 1; /* R_ALPHA_REFLONG. */
15857 return reloc_type
== 1; /* R_ARC_32. */
15858 case EM_ARC_COMPACT
:
15859 case EM_ARC_COMPACT2
:
15860 case EM_ARC_COMPACT3
:
15861 case EM_ARC_COMPACT3_64
:
15862 return reloc_type
== 4; /* R_ARC_32. */
15864 return reloc_type
== 2; /* R_ARM_ABS32 */
15867 return reloc_type
== 1;
15869 return reloc_type
== 0x12; /* R_byte4_data. */
15871 return reloc_type
== 3; /* R_CRIS_32. */
15873 return reloc_type
== 3; /* R_CR16_NUM32. */
15875 return reloc_type
== 15; /* R_CRX_NUM32. */
15877 return reloc_type
== 1; /* R_CKCORE_ADDR32. */
15878 case EM_CYGNUS_FRV
:
15879 return reloc_type
== 1;
15880 case EM_CYGNUS_D10V
:
15882 return reloc_type
== 6; /* R_D10V_32. */
15883 case EM_CYGNUS_D30V
:
15885 return reloc_type
== 12; /* R_D30V_32_NORMAL. */
15887 return reloc_type
== 3; /* R_DLX_RELOC_32. */
15888 case EM_CYGNUS_FR30
:
15890 return reloc_type
== 3; /* R_FR30_32. */
15892 return reloc_type
== 1; /* R_FT32_32. */
15896 return reloc_type
== 1; /* R_H8_DIR32. */
15898 return (reloc_type
== 0x64 /* R_IA64_SECREL32MSB. */
15899 || reloc_type
== 0x65 /* R_IA64_SECREL32LSB. */
15900 || reloc_type
== 0x24 /* R_IA64_DIR32MSB. */
15901 || reloc_type
== 0x25 /* R_IA64_DIR32LSB. */);
15904 return reloc_type
== 2; /* R_IP2K_32. */
15906 return reloc_type
== 2; /* R_IQ2000_32. */
15908 return reloc_type
== 2; /* R_KVX_32. */
15909 case EM_LATTICEMICO32
:
15910 return reloc_type
== 3; /* R_LM32_32. */
15912 return reloc_type
== 1; /* R_LARCH_32. */
15915 return reloc_type
== 3; /* R_M32C_32. */
15917 return reloc_type
== 34; /* R_M32R_32_RELA. */
15920 return reloc_type
== 6; /* R_M68HC11_32. */
15922 return reloc_type
== 7 || /* R_S12Z_EXT32 */
15923 reloc_type
== 6; /* R_S12Z_CW32. */
15925 return reloc_type
== 1; /* R_MCORE_ADDR32. */
15926 case EM_CYGNUS_MEP
:
15927 return reloc_type
== 4; /* R_MEP_32. */
15929 return reloc_type
== 2; /* R_METAG_ADDR32. */
15930 case EM_MICROBLAZE
:
15931 return reloc_type
== 1; /* R_MICROBLAZE_32. */
15933 return reloc_type
== 2; /* R_MIPS_32. */
15935 return reloc_type
== 4; /* R_MMIX_32. */
15936 case EM_CYGNUS_MN10200
:
15938 return reloc_type
== 1; /* R_MN10200_32. */
15939 case EM_CYGNUS_MN10300
:
15941 return reloc_type
== 1; /* R_MN10300_32. */
15943 return reloc_type
== 1; /* R_MOXIE_32. */
15944 case EM_MSP430_OLD
:
15946 return reloc_type
== 1; /* R_MSP430_32 or R_MSP320_ABS32. */
15948 return reloc_type
== 2; /* R_MT_32. */
15950 return reloc_type
== 20; /* R_NDS32_32_RELA. */
15951 case EM_ALTERA_NIOS2
:
15952 return reloc_type
== 12; /* R_NIOS2_BFD_RELOC_32. */
15954 return reloc_type
== 1; /* R_NIOS_32. */
15956 return reloc_type
== 1; /* R_OR1K_32. */
15958 return (reloc_type
== 1 /* R_PARISC_DIR32. */
15959 || reloc_type
== 2 /* R_PARISC_DIR21L. */
15960 || reloc_type
== 41); /* R_PARISC_SECREL32. */
15963 return reloc_type
== 1; /* R_PJ_DATA_DIR32. */
15965 return reloc_type
== 1; /* R_PPC64_ADDR32. */
15967 return reloc_type
== 1; /* R_PPC_ADDR32. */
15969 return reloc_type
== 11; /* R_PRU_BFD_RELOC_32. */
15971 return reloc_type
== 1; /* R_RISCV_32. */
15973 return reloc_type
== 1; /* R_RL78_DIR32. */
15975 return reloc_type
== 1; /* R_RX_DIR32. */
15977 return reloc_type
== 1; /* R_I370_ADDR31. */
15980 return reloc_type
== 4; /* R_S390_32. */
15982 return reloc_type
== 8; /* R_SCORE_ABS32. */
15984 return reloc_type
== 1; /* R_SH_DIR32. */
15985 case EM_SPARC32PLUS
:
15988 return reloc_type
== 3 /* R_SPARC_32. */
15989 || reloc_type
== 23; /* R_SPARC_UA32. */
15991 return reloc_type
== 6; /* R_SPU_ADDR32 */
15993 return reloc_type
== 1; /* R_C6000_ABS32. */
15995 return reloc_type
== 2; /* R_TILEGX_32. */
15997 return reloc_type
== 1; /* R_TILEPRO_32. */
15998 case EM_CYGNUS_V850
:
16000 return reloc_type
== 6; /* R_V850_ABS32. */
16002 return reloc_type
== 0x33; /* R_V810_WORD. */
16004 return reloc_type
== 1; /* R_VAX_32. */
16006 return reloc_type
== 3; /* R_VISIUM_32. */
16007 case EM_WEBASSEMBLY
:
16008 return reloc_type
== 1; /* R_WASM32_32. */
16012 return reloc_type
== 10; /* R_X86_64_32. */
16014 return reloc_type
== 4; /* R_XGATE_32. */
16016 return reloc_type
== 1; /* R_XSTROMY16_32. */
16017 case EM_XTENSA_OLD
:
16019 return reloc_type
== 1; /* R_XTENSA_32. */
16021 return reloc_type
== 6; /* R_Z80_32. */
16024 static unsigned int prev_warn
= 0;
16026 /* Avoid repeating the same warning multiple times. */
16027 if (prev_warn
!= filedata
->file_header
.e_machine
)
16028 error (_("Missing knowledge of 32-bit reloc types used in DWARF sections of machine number %d\n"),
16029 filedata
->file_header
.e_machine
);
16030 prev_warn
= filedata
->file_header
.e_machine
;
16036 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
16037 a 32-bit pc-relative RELA relocation used in DWARF debug sections. */
16040 is_32bit_pcrel_reloc (Filedata
* filedata
, unsigned int reloc_type
)
16042 switch (filedata
->file_header
.e_machine
)
16043 /* Please keep this table alpha-sorted for ease of visual lookup. */
16047 return reloc_type
== 2; /* R_386_PC32. */
16049 return reloc_type
== 4; /* R_68K_PC32. */
16051 return reloc_type
== 261; /* R_AARCH64_PREL32 */
16052 case EM_ADAPTEVA_EPIPHANY
:
16053 return reloc_type
== 6;
16055 return reloc_type
== 10; /* R_ALPHA_SREL32. */
16056 case EM_ARC_COMPACT
:
16057 case EM_ARC_COMPACT2
:
16058 case EM_ARC_COMPACT3
:
16059 case EM_ARC_COMPACT3_64
:
16060 return reloc_type
== 49; /* R_ARC_32_PCREL. */
16062 return reloc_type
== 3; /* R_ARM_REL32 */
16065 return reloc_type
== 36; /* R_AVR_32_PCREL. */
16067 return reloc_type
== 99; /* R_LARCH_32_PCREL. */
16068 case EM_MICROBLAZE
:
16069 return reloc_type
== 2; /* R_MICROBLAZE_32_PCREL. */
16071 return reloc_type
== 9; /* R_OR1K_32_PCREL. */
16073 return reloc_type
== 9; /* R_PARISC_PCREL32. */
16075 return reloc_type
== 26; /* R_PPC_REL32. */
16077 return reloc_type
== 26; /* R_PPC64_REL32. */
16079 return reloc_type
== 57; /* R_RISCV_32_PCREL. */
16082 return reloc_type
== 5; /* R_390_PC32. */
16084 return reloc_type
== 2; /* R_SH_REL32. */
16085 case EM_SPARC32PLUS
:
16088 return reloc_type
== 6; /* R_SPARC_DISP32. */
16090 return reloc_type
== 13; /* R_SPU_REL32. */
16092 return reloc_type
== 6; /* R_TILEGX_32_PCREL. */
16094 return reloc_type
== 4; /* R_TILEPRO_32_PCREL. */
16096 return reloc_type
== 6; /* R_VISIUM_32_PCREL */
16100 return reloc_type
== 2; /* R_X86_64_PC32. */
16102 return reloc_type
== 4; /* R_VAX_PCREL32. */
16103 case EM_XTENSA_OLD
:
16105 return reloc_type
== 14; /* R_XTENSA_32_PCREL. */
16107 return reloc_type
== 7; /* R_KVX_32_PCREL */
16109 /* Do not abort or issue an error message here. Not all targets use
16110 pc-relative 32-bit relocs in their DWARF debug information and we
16111 have already tested for target coverage in is_32bit_abs_reloc. A
16112 more helpful warning message will be generated by apply_relocations
16113 anyway, so just return. */
16118 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
16119 a 64-bit absolute RELA relocation used in DWARF debug sections. */
16122 is_64bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
16124 switch (filedata
->file_header
.e_machine
)
16127 return reloc_type
== 257; /* R_AARCH64_ABS64. */
16128 case EM_ARC_COMPACT3_64
:
16129 return reloc_type
== 5; /* R_ARC_64. */
16131 return reloc_type
== 2; /* R_ALPHA_REFQUAD. */
16133 return (reloc_type
== 0x26 /* R_IA64_DIR64MSB. */
16134 || reloc_type
== 0x27 /* R_IA64_DIR64LSB. */);
16136 return reloc_type
== 2; /* R_LARCH_64 */
16138 return reloc_type
== 80; /* R_PARISC_DIR64. */
16140 return reloc_type
== 38; /* R_PPC64_ADDR64. */
16142 return reloc_type
== 2; /* R_RISCV_64. */
16143 case EM_SPARC32PLUS
:
16146 return reloc_type
== 32 /* R_SPARC_64. */
16147 || reloc_type
== 54; /* R_SPARC_UA64. */
16151 return reloc_type
== 1; /* R_X86_64_64. */
16154 return reloc_type
== 22; /* R_S390_64. */
16156 return reloc_type
== 1; /* R_TILEGX_64. */
16158 return reloc_type
== 18; /* R_MIPS_64. */
16160 return reloc_type
== 3; /* R_KVX_64 */
16166 /* Like is_32bit_pcrel_reloc except that it returns TRUE iff RELOC_TYPE is
16167 a 64-bit pc-relative RELA relocation used in DWARF debug sections. */
16170 is_64bit_pcrel_reloc (Filedata
* filedata
, unsigned int reloc_type
)
16172 switch (filedata
->file_header
.e_machine
)
16175 return reloc_type
== 260; /* R_AARCH64_PREL64. */
16177 return reloc_type
== 11; /* R_ALPHA_SREL64. */
16179 return (reloc_type
== 0x4e /* R_IA64_PCREL64MSB. */
16180 || reloc_type
== 0x4f /* R_IA64_PCREL64LSB. */);
16182 return reloc_type
== 72; /* R_PARISC_PCREL64. */
16184 return reloc_type
== 44; /* R_PPC64_REL64. */
16185 case EM_SPARC32PLUS
:
16188 return reloc_type
== 46; /* R_SPARC_DISP64. */
16192 return reloc_type
== 24; /* R_X86_64_PC64. */
16195 return reloc_type
== 23; /* R_S390_PC64. */
16197 return reloc_type
== 5; /* R_TILEGX_64_PCREL. */
16203 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
16204 a 24-bit absolute RELA relocation used in DWARF debug sections. */
16207 is_24bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
16209 switch (filedata
->file_header
.e_machine
)
16211 case EM_CYGNUS_MN10200
:
16213 return reloc_type
== 4; /* R_MN10200_24. */
16215 return reloc_type
== 5; /* R_FT32_20. */
16217 return reloc_type
== 5; /* R_Z80_24. */
16223 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
16224 a 16-bit absolute RELA relocation used in DWARF debug sections. */
16227 is_16bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
16229 /* Please keep this table alpha-sorted for ease of visual lookup. */
16230 switch (filedata
->file_header
.e_machine
)
16233 case EM_ARC_COMPACT
:
16234 case EM_ARC_COMPACT2
:
16235 case EM_ARC_COMPACT3
:
16236 case EM_ARC_COMPACT3_64
:
16237 return reloc_type
== 2; /* R_ARC_16. */
16238 case EM_ADAPTEVA_EPIPHANY
:
16239 return reloc_type
== 5;
16242 return reloc_type
== 4; /* R_AVR_16. */
16243 case EM_CYGNUS_D10V
:
16245 return reloc_type
== 3; /* R_D10V_16. */
16247 return reloc_type
== 2; /* R_FT32_16. */
16251 return reloc_type
== R_H8_DIR16
;
16254 return reloc_type
== 1; /* R_IP2K_16. */
16257 return reloc_type
== 1; /* R_M32C_16 */
16258 case EM_CYGNUS_MN10200
:
16260 return reloc_type
== 2; /* R_MN10200_16. */
16261 case EM_CYGNUS_MN10300
:
16263 return reloc_type
== 2; /* R_MN10300_16. */
16265 return reloc_type
== 1; /* R_KVX_16 */
16267 if (uses_msp430x_relocs (filedata
))
16268 return reloc_type
== 2; /* R_MSP430_ABS16. */
16269 /* Fall through. */
16270 case EM_MSP430_OLD
:
16271 return reloc_type
== 5; /* R_MSP430_16_BYTE. */
16273 return reloc_type
== 19; /* R_NDS32_16_RELA. */
16274 case EM_ALTERA_NIOS2
:
16275 return reloc_type
== 13; /* R_NIOS2_BFD_RELOC_16. */
16277 return reloc_type
== 9; /* R_NIOS_16. */
16279 return reloc_type
== 2; /* R_OR1K_16. */
16281 return reloc_type
== 55; /* R_RISCV_SET16. */
16283 return reloc_type
== 8; /* R_PRU_BFD_RELOC_16. */
16285 return reloc_type
== 2; /* R_C6000_ABS16. */
16287 return reloc_type
== 2; /* R_VISIUM_16. */
16289 return reloc_type
== 3; /* R_XGATE_16. */
16291 return reloc_type
== 4; /* R_Z80_16. */
16297 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
16298 a 8-bit absolute RELA relocation used in DWARF debug sections. */
16301 is_8bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
16303 switch (filedata
->file_header
.e_machine
)
16306 return reloc_type
== 54; /* R_RISCV_SET8. */
16308 return reloc_type
== 1; /* R_Z80_8. */
16309 case EM_MICROBLAZE
:
16310 return (reloc_type
== 33 /* R_MICROBLAZE_32_NONE. */
16311 || reloc_type
== 0 /* R_MICROBLAZE_NONE. */
16312 || reloc_type
== 9 /* R_MICROBLAZE_64_NONE. */);
16318 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
16319 a 6-bit absolute RELA relocation used in DWARF debug sections. */
16322 is_6bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
16324 switch (filedata
->file_header
.e_machine
)
16327 return reloc_type
== 53; /* R_RISCV_SET6. */
16333 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
16334 a 32-bit inplace add RELA relocation used in DWARF debug sections. */
16337 is_32bit_inplace_add_reloc (Filedata
* filedata
, unsigned int reloc_type
)
16339 /* Please keep this table alpha-sorted for ease of visual lookup. */
16340 switch (filedata
->file_header
.e_machine
)
16343 return reloc_type
== 50; /* R_LARCH_ADD32. */
16345 return reloc_type
== 35; /* R_RISCV_ADD32. */
16351 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
16352 a 32-bit inplace sub RELA relocation used in DWARF debug sections. */
16355 is_32bit_inplace_sub_reloc (Filedata
* filedata
, unsigned int reloc_type
)
16357 /* Please keep this table alpha-sorted for ease of visual lookup. */
16358 switch (filedata
->file_header
.e_machine
)
16361 return reloc_type
== 55; /* R_LARCH_SUB32. */
16363 return reloc_type
== 39; /* R_RISCV_SUB32. */
16369 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
16370 a 64-bit inplace add RELA relocation used in DWARF debug sections. */
16373 is_64bit_inplace_add_reloc (Filedata
* filedata
, unsigned int reloc_type
)
16375 /* Please keep this table alpha-sorted for ease of visual lookup. */
16376 switch (filedata
->file_header
.e_machine
)
16379 return reloc_type
== 51; /* R_LARCH_ADD64. */
16381 return reloc_type
== 36; /* R_RISCV_ADD64. */
16387 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
16388 a 64-bit inplace sub RELA relocation used in DWARF debug sections. */
16391 is_64bit_inplace_sub_reloc (Filedata
* filedata
, unsigned int reloc_type
)
16393 /* Please keep this table alpha-sorted for ease of visual lookup. */
16394 switch (filedata
->file_header
.e_machine
)
16397 return reloc_type
== 56; /* R_LARCH_SUB64. */
16399 return reloc_type
== 40; /* R_RISCV_SUB64. */
16405 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
16406 a 16-bit inplace add RELA relocation used in DWARF debug sections. */
16409 is_16bit_inplace_add_reloc (Filedata
* filedata
, unsigned int reloc_type
)
16411 /* Please keep this table alpha-sorted for ease of visual lookup. */
16412 switch (filedata
->file_header
.e_machine
)
16415 return reloc_type
== 48; /* R_LARCH_ADD16. */
16417 return reloc_type
== 34; /* R_RISCV_ADD16. */
16423 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
16424 a 16-bit inplace sub RELA relocation used in DWARF debug sections. */
16427 is_16bit_inplace_sub_reloc (Filedata
* filedata
, unsigned int reloc_type
)
16429 /* Please keep this table alpha-sorted for ease of visual lookup. */
16430 switch (filedata
->file_header
.e_machine
)
16433 return reloc_type
== 53; /* R_LARCH_SUB16. */
16435 return reloc_type
== 38; /* R_RISCV_SUB16. */
16441 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
16442 a 8-bit inplace add RELA relocation used in DWARF debug sections. */
16445 is_8bit_inplace_add_reloc (Filedata
* filedata
, unsigned int reloc_type
)
16447 /* Please keep this table alpha-sorted for ease of visual lookup. */
16448 switch (filedata
->file_header
.e_machine
)
16451 return reloc_type
== 47; /* R_LARCH_ADD8. */
16453 return reloc_type
== 33; /* R_RISCV_ADD8. */
16459 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
16460 a 8-bit inplace sub RELA relocation used in DWARF debug sections. */
16463 is_8bit_inplace_sub_reloc (Filedata
* filedata
, unsigned int reloc_type
)
16465 /* Please keep this table alpha-sorted for ease of visual lookup. */
16466 switch (filedata
->file_header
.e_machine
)
16469 return reloc_type
== 52; /* R_LARCH_SUB8. */
16471 return reloc_type
== 37; /* R_RISCV_SUB8. */
16477 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
16478 a 6-bit inplace add RELA relocation used in DWARF debug sections. */
16481 is_6bit_inplace_add_reloc (Filedata
* filedata
, unsigned int reloc_type
)
16483 switch (filedata
->file_header
.e_machine
)
16486 return reloc_type
== 105; /* R_LARCH_ADD6. */
16492 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
16493 a 6-bit inplace sub RELA relocation used in DWARF debug sections. */
16496 is_6bit_inplace_sub_reloc (Filedata
* filedata
, unsigned int reloc_type
)
16498 switch (filedata
->file_header
.e_machine
)
16501 return reloc_type
== 106; /* R_LARCH_SUB6. */
16503 return reloc_type
== 52; /* R_RISCV_SUB6. */
16509 /* Returns TRUE iff RELOC_TYPE is a NONE relocation used for discarded
16510 relocation entries (possibly formerly used for SHT_GROUP sections). */
16513 is_none_reloc (Filedata
* filedata
, unsigned int reloc_type
)
16515 switch (filedata
->file_header
.e_machine
)
16517 case EM_386
: /* R_386_NONE. */
16518 case EM_68K
: /* R_68K_NONE. */
16519 case EM_ADAPTEVA_EPIPHANY
:
16520 case EM_ALPHA
: /* R_ALPHA_NONE. */
16521 case EM_ALTERA_NIOS2
: /* R_NIOS2_NONE. */
16522 case EM_ARC
: /* R_ARC_NONE. */
16523 case EM_ARC_COMPACT2
: /* R_ARC_NONE. */
16524 case EM_ARC_COMPACT
: /* R_ARC_NONE. */
16525 case EM_ARC_COMPACT3
: /* R_ARC_NONE. */
16526 case EM_ARC_COMPACT3_64
: /* R_ARC_NONE. */
16527 case EM_ARM
: /* R_ARM_NONE. */
16528 case EM_CRIS
: /* R_CRIS_NONE. */
16529 case EM_FT32
: /* R_FT32_NONE. */
16530 case EM_IA_64
: /* R_IA64_NONE. */
16531 case EM_K1OM
: /* R_X86_64_NONE. */
16532 case EM_KVX
: /* R_KVX_NONE. */
16533 case EM_L1OM
: /* R_X86_64_NONE. */
16534 case EM_M32R
: /* R_M32R_NONE. */
16535 case EM_MIPS
: /* R_MIPS_NONE. */
16536 case EM_MN10300
: /* R_MN10300_NONE. */
16537 case EM_MOXIE
: /* R_MOXIE_NONE. */
16538 case EM_NIOS32
: /* R_NIOS_NONE. */
16539 case EM_OR1K
: /* R_OR1K_NONE. */
16540 case EM_PARISC
: /* R_PARISC_NONE. */
16541 case EM_PPC64
: /* R_PPC64_NONE. */
16542 case EM_PPC
: /* R_PPC_NONE. */
16543 case EM_RISCV
: /* R_RISCV_NONE. */
16544 case EM_S390
: /* R_390_NONE. */
16546 case EM_SH
: /* R_SH_NONE. */
16547 case EM_SPARC32PLUS
:
16548 case EM_SPARC
: /* R_SPARC_NONE. */
16550 case EM_TILEGX
: /* R_TILEGX_NONE. */
16551 case EM_TILEPRO
: /* R_TILEPRO_NONE. */
16552 case EM_TI_C6000
:/* R_C6000_NONE. */
16553 case EM_X86_64
: /* R_X86_64_NONE. */
16554 case EM_Z80
: /* R_Z80_NONE. */
16555 case EM_WEBASSEMBLY
: /* R_WASM32_NONE. */
16556 return reloc_type
== 0;
16559 return reloc_type
== 0 || reloc_type
== 256;
16562 return (reloc_type
== 0 /* R_AVR_NONE. */
16563 || reloc_type
== 30 /* R_AVR_DIFF8. */
16564 || reloc_type
== 31 /* R_AVR_DIFF16. */
16565 || reloc_type
== 32 /* R_AVR_DIFF32. */);
16567 return reloc_type
== 3; /* R_METAG_NONE. */
16569 return (reloc_type
== 0 /* R_NDS32_NONE. */
16570 || reloc_type
== 205 /* R_NDS32_DIFF8. */
16571 || reloc_type
== 206 /* R_NDS32_DIFF16. */
16572 || reloc_type
== 207 /* R_NDS32_DIFF32. */
16573 || reloc_type
== 208 /* R_NDS32_DIFF_ULEB128. */);
16575 return (reloc_type
== 0 /* R_PRU_NONE. */
16576 || reloc_type
== 65 /* R_PRU_DIFF8. */
16577 || reloc_type
== 66 /* R_PRU_DIFF16. */
16578 || reloc_type
== 67 /* R_PRU_DIFF32. */);
16579 case EM_XTENSA_OLD
:
16581 return (reloc_type
== 0 /* R_XTENSA_NONE. */
16582 || reloc_type
== 17 /* R_XTENSA_DIFF8. */
16583 || reloc_type
== 18 /* R_XTENSA_DIFF16. */
16584 || reloc_type
== 19 /* R_XTENSA_DIFF32. */
16585 || reloc_type
== 57 /* R_XTENSA_PDIFF8. */
16586 || reloc_type
== 58 /* R_XTENSA_PDIFF16. */
16587 || reloc_type
== 59 /* R_XTENSA_PDIFF32. */
16588 || reloc_type
== 60 /* R_XTENSA_NDIFF8. */
16589 || reloc_type
== 61 /* R_XTENSA_NDIFF16. */
16590 || reloc_type
== 62 /* R_XTENSA_NDIFF32. */);
16595 /* Returns TRUE if there is a relocation against
16596 section NAME at OFFSET bytes. */
16599 reloc_at (struct dwarf_section
* dsec
, uint64_t offset
)
16601 Elf_Internal_Rela
* relocs
;
16602 Elf_Internal_Rela
* rp
;
16604 if (dsec
== NULL
|| dsec
->reloc_info
== NULL
)
16607 relocs
= (Elf_Internal_Rela
*) dsec
->reloc_info
;
16609 for (rp
= relocs
; rp
< relocs
+ dsec
->num_relocs
; ++rp
)
16610 if (rp
->r_offset
== offset
)
16616 /* Apply relocations to a section.
16617 Returns TRUE upon success, FALSE otherwise.
16618 If RELOCS_RETURN is non-NULL then it is set to point to the loaded relocs.
16619 It is then the caller's responsibility to free them. NUM_RELOCS_RETURN
16620 will be set to the number of relocs loaded.
16622 Note: So far support has been added only for those relocations
16623 which can be found in debug sections. FIXME: Add support for
16624 more relocations ? */
16627 apply_relocations (Filedata
*filedata
,
16628 const Elf_Internal_Shdr
*section
,
16629 unsigned char *start
,
16631 void **relocs_return
,
16632 uint64_t *num_relocs_return
)
16634 Elf_Internal_Shdr
* relsec
;
16636 if (relocs_return
!= NULL
)
16638 * (Elf_Internal_Rela
**) relocs_return
= NULL
;
16639 * num_relocs_return
= 0;
16642 if (filedata
->file_header
.e_type
!= ET_REL
)
16643 /* No relocs to apply. */
16646 /* Find the reloc section associated with the section. */
16647 for (relsec
= filedata
->section_headers
;
16648 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
16652 uint64_t num_relocs
;
16653 Elf_Internal_Rela
* relocs
;
16654 Elf_Internal_Rela
* rp
;
16655 Elf_Internal_Shdr
* symsec
;
16656 Elf_Internal_Sym
* symtab
;
16658 Elf_Internal_Sym
* sym
;
16660 if ((relsec
->sh_type
!= SHT_RELA
&& relsec
->sh_type
!= SHT_REL
)
16661 || relsec
->sh_info
>= filedata
->file_header
.e_shnum
16662 || filedata
->section_headers
+ relsec
->sh_info
!= section
16663 || relsec
->sh_size
== 0
16664 || relsec
->sh_link
>= filedata
->file_header
.e_shnum
)
16667 symsec
= filedata
->section_headers
+ relsec
->sh_link
;
16668 if (symsec
->sh_type
!= SHT_SYMTAB
16669 && symsec
->sh_type
!= SHT_DYNSYM
)
16672 is_rela
= relsec
->sh_type
== SHT_RELA
;
16676 if (!slurp_rela_relocs (filedata
, relsec
->sh_offset
,
16677 relsec
->sh_size
, & relocs
, & num_relocs
))
16682 if (!slurp_rel_relocs (filedata
, relsec
->sh_offset
,
16683 relsec
->sh_size
, & relocs
, & num_relocs
))
16687 /* SH uses RELA but uses in place value instead of the addend field. */
16688 if (filedata
->file_header
.e_machine
== EM_SH
)
16691 symtab
= get_elf_symbols (filedata
, symsec
, & num_syms
);
16693 for (rp
= relocs
; rp
< relocs
+ num_relocs
; ++rp
)
16696 unsigned int reloc_type
;
16697 unsigned int reloc_size
;
16698 bool reloc_inplace
= false;
16699 bool reloc_subtract
= false;
16700 unsigned char *rloc
;
16701 uint64_t sym_index
;
16703 reloc_type
= get_reloc_type (filedata
, rp
->r_info
);
16705 if (target_specific_reloc_handling (filedata
, rp
, start
, size
, symtab
, num_syms
))
16707 else if (is_none_reloc (filedata
, reloc_type
))
16709 else if (is_32bit_abs_reloc (filedata
, reloc_type
)
16710 || is_32bit_pcrel_reloc (filedata
, reloc_type
))
16712 else if (is_64bit_abs_reloc (filedata
, reloc_type
)
16713 || is_64bit_pcrel_reloc (filedata
, reloc_type
))
16715 else if (is_24bit_abs_reloc (filedata
, reloc_type
))
16717 else if (is_16bit_abs_reloc (filedata
, reloc_type
))
16719 else if (is_8bit_abs_reloc (filedata
, reloc_type
)
16720 || is_6bit_abs_reloc (filedata
, reloc_type
))
16722 else if ((reloc_subtract
= is_32bit_inplace_sub_reloc (filedata
,
16724 || is_32bit_inplace_add_reloc (filedata
, reloc_type
))
16727 reloc_inplace
= true;
16729 else if ((reloc_subtract
= is_64bit_inplace_sub_reloc (filedata
,
16731 || is_64bit_inplace_add_reloc (filedata
, reloc_type
))
16734 reloc_inplace
= true;
16736 else if ((reloc_subtract
= is_16bit_inplace_sub_reloc (filedata
,
16738 || is_16bit_inplace_add_reloc (filedata
, reloc_type
))
16741 reloc_inplace
= true;
16743 else if ((reloc_subtract
= is_8bit_inplace_sub_reloc (filedata
,
16745 || is_8bit_inplace_add_reloc (filedata
, reloc_type
))
16748 reloc_inplace
= true;
16750 else if ((reloc_subtract
= is_6bit_inplace_sub_reloc (filedata
,
16752 || is_6bit_inplace_add_reloc (filedata
, reloc_type
))
16755 reloc_inplace
= true;
16759 static unsigned int prev_reloc
= 0;
16761 if (reloc_type
!= prev_reloc
)
16762 warn (_("unable to apply unsupported reloc type %d to section %s\n"),
16763 reloc_type
, printable_section_name (filedata
, section
));
16764 prev_reloc
= reloc_type
;
16768 if (!in_range (size
, rp
->r_offset
, reloc_size
))
16770 warn (_("skipping invalid relocation offset %#" PRIx64
16771 " in section %s\n"),
16773 printable_section_name (filedata
, section
));
16776 rloc
= start
+ rp
->r_offset
;
16778 sym_index
= get_reloc_symindex (rp
->r_info
);
16779 if (sym_index
>= num_syms
)
16781 warn (_("skipping invalid relocation symbol index %#" PRIx64
16782 " in section %s\n"),
16783 sym_index
, printable_section_name (filedata
, section
));
16786 sym
= symtab
+ sym_index
;
16788 /* If the reloc has a symbol associated with it,
16789 make sure that it is of an appropriate type.
16791 Relocations against symbols without type can happen.
16792 Gcc -feliminate-dwarf2-dups may generate symbols
16793 without type for debug info.
16795 Icc generates relocations against function symbols
16796 instead of local labels.
16798 Relocations against object symbols can happen, eg when
16799 referencing a global array. For an example of this see
16800 the _clz.o binary in libgcc.a. */
16802 && ELF_ST_TYPE (sym
->st_info
) != STT_COMMON
16803 && ELF_ST_TYPE (sym
->st_info
) > STT_SECTION
)
16805 warn (_("skipping unexpected symbol type %s in section %s relocation %tu\n"),
16806 get_symbol_type (filedata
, ELF_ST_TYPE (sym
->st_info
)),
16807 printable_section_name (filedata
, relsec
),
16814 addend
+= rp
->r_addend
;
16815 /* R_XTENSA_32, R_PJ_DATA_DIR32 and R_D30V_32_NORMAL are
16816 partial_inplace. */
16818 || (filedata
->file_header
.e_machine
== EM_XTENSA
16819 && reloc_type
== 1)
16820 || ((filedata
->file_header
.e_machine
== EM_PJ
16821 || filedata
->file_header
.e_machine
== EM_PJ_OLD
)
16822 && reloc_type
== 1)
16823 || ((filedata
->file_header
.e_machine
== EM_D30V
16824 || filedata
->file_header
.e_machine
== EM_CYGNUS_D30V
)
16825 && reloc_type
== 12)
16828 if (is_6bit_inplace_sub_reloc (filedata
, reloc_type
))
16829 addend
+= byte_get (rloc
, reloc_size
) & 0x3f;
16831 addend
+= byte_get (rloc
, reloc_size
);
16834 if (is_32bit_pcrel_reloc (filedata
, reloc_type
)
16835 || is_64bit_pcrel_reloc (filedata
, reloc_type
))
16837 /* On HPPA, all pc-relative relocations are biased by 8. */
16838 if (filedata
->file_header
.e_machine
== EM_PARISC
)
16840 byte_put (rloc
, (addend
+ sym
->st_value
) - rp
->r_offset
,
16843 else if (is_6bit_abs_reloc (filedata
, reloc_type
)
16844 || is_6bit_inplace_sub_reloc (filedata
, reloc_type
)
16845 || is_6bit_inplace_add_reloc (filedata
, reloc_type
))
16847 if (reloc_subtract
)
16848 addend
-= sym
->st_value
;
16850 addend
+= sym
->st_value
;
16851 addend
= (addend
& 0x3f) | (byte_get (rloc
, reloc_size
) & 0xc0);
16852 byte_put (rloc
, addend
, reloc_size
);
16854 else if (reloc_subtract
)
16855 byte_put (rloc
, addend
- sym
->st_value
, reloc_size
);
16857 byte_put (rloc
, addend
+ sym
->st_value
, reloc_size
);
16861 /* Let the target specific reloc processing code know that
16862 we have finished with these relocs. */
16863 target_specific_reloc_handling (filedata
, NULL
, NULL
, 0, NULL
, 0);
16867 * (Elf_Internal_Rela
**) relocs_return
= relocs
;
16868 * num_relocs_return
= num_relocs
;
16879 #ifdef SUPPORT_DISASSEMBLY
16881 disassemble_section (Elf_Internal_Shdr
* section
, Filedata
* filedata
)
16883 printf (_("\nAssembly dump of section %s\n"), printable_section_name (filedata
, section
));
16885 /* FIXME: XXX -- to be done --- XXX */
16891 /* Reads in the contents of SECTION from FILE, returning a pointer
16892 to a malloc'ed buffer or NULL if something went wrong. */
16895 get_section_contents (Elf_Internal_Shdr
* section
, Filedata
* filedata
)
16897 uint64_t num_bytes
= section
->sh_size
;
16899 if (num_bytes
== 0 || section
->sh_type
== SHT_NOBITS
)
16901 printf (_("Section '%s' has no data to dump.\n"),
16902 printable_section_name (filedata
, section
));
16906 return (char *) get_data (NULL
, filedata
, section
->sh_offset
, 1, num_bytes
,
16907 _("section contents"));
16910 /* Uncompresses a section that was compressed using zlib/zstd, in place. */
16913 uncompress_section_contents (bool is_zstd
,
16914 unsigned char ** buffer
,
16915 uint64_t uncompressed_size
,
16917 uint64_t file_size
)
16919 uint64_t compressed_size
= *size
;
16920 unsigned char *compressed_buffer
= *buffer
;
16921 unsigned char *uncompressed_buffer
= NULL
;
16925 /* Similar to bfd_section_size_insane() in the BFD library we expect an
16926 upper limit of ~10x compression. Any compression larger than that is
16927 thought to be due to fuzzing of the compression header. */
16928 if (uncompressed_size
> file_size
* 10)
16930 error (_("Uncompressed section size is suspiciously large: 0x%" PRIu64
"\n"),
16931 uncompressed_size
);
16935 uncompressed_buffer
= xmalloc (uncompressed_size
);
16940 size_t ret
= ZSTD_decompress (uncompressed_buffer
, uncompressed_size
,
16941 compressed_buffer
, compressed_size
);
16942 if (ZSTD_isError (ret
))
16948 /* It is possible the section consists of several compressed
16949 buffers concatenated together, so we uncompress in a loop. */
16950 /* PR 18313: The state field in the z_stream structure is supposed
16951 to be invisible to the user (ie us), but some compilers will
16952 still complain about it being used without initialisation. So
16953 we first zero the entire z_stream structure and then set the fields
16955 memset (&strm
, 0, sizeof strm
);
16956 strm
.avail_in
= compressed_size
;
16957 strm
.next_in
= (Bytef
*)compressed_buffer
;
16958 strm
.avail_out
= uncompressed_size
;
16960 rc
= inflateInit (&strm
);
16961 while (strm
.avail_in
> 0)
16965 strm
.next_out
= ((Bytef
*)uncompressed_buffer
16966 + (uncompressed_size
- strm
.avail_out
));
16967 rc
= inflate (&strm
, Z_FINISH
);
16968 if (rc
!= Z_STREAM_END
)
16970 rc
= inflateReset (&strm
);
16972 if (inflateEnd (&strm
) != Z_OK
|| rc
!= Z_OK
|| strm
.avail_out
!= 0)
16976 *buffer
= uncompressed_buffer
;
16977 *size
= uncompressed_size
;
16981 free (uncompressed_buffer
);
16982 /* Indicate decompression failure. */
16988 maybe_expand_or_relocate_section (Elf_Internal_Shdr
* section
,
16989 Filedata
* filedata
,
16990 unsigned char ** start_ptr
,
16991 unsigned char ** decomp_buf
,
16994 uint64_t section_size
= section
->sh_size
;
16995 unsigned char * start
= * start_ptr
;
16997 if (decompress_dumps
)
16999 uint64_t new_size
= section_size
;
17000 uint64_t uncompressed_size
= 0;
17001 bool is_zstd
= false;
17003 if ((section
->sh_flags
& SHF_COMPRESSED
) != 0)
17005 Elf_Internal_Chdr chdr
;
17006 unsigned int compression_header_size
17007 = get_compression_header (& chdr
, start
, section_size
);
17009 if (compression_header_size
== 0)
17010 /* An error message will have already been generated
17011 by get_compression_header. */
17012 return (uint64_t) -1;
17014 if (chdr
.ch_type
== ch_compress_zlib
)
17017 else if (chdr
.ch_type
== ch_compress_zstd
)
17022 warn (_("section '%s' has unsupported compress type: %d\n"),
17023 printable_section_name (filedata
, section
), chdr
.ch_type
);
17024 return (uint64_t) -1;
17027 uncompressed_size
= chdr
.ch_size
;
17028 start
+= compression_header_size
;
17029 new_size
-= compression_header_size
;
17031 else if (new_size
> 12 && streq ((char *) start
, "ZLIB"))
17033 /* Read the zlib header. In this case, it should be "ZLIB"
17034 followed by the uncompressed section size, 8 bytes in
17035 big-endian order. */
17036 uncompressed_size
= start
[4]; uncompressed_size
<<= 8;
17037 uncompressed_size
+= start
[5]; uncompressed_size
<<= 8;
17038 uncompressed_size
+= start
[6]; uncompressed_size
<<= 8;
17039 uncompressed_size
+= start
[7]; uncompressed_size
<<= 8;
17040 uncompressed_size
+= start
[8]; uncompressed_size
<<= 8;
17041 uncompressed_size
+= start
[9]; uncompressed_size
<<= 8;
17042 uncompressed_size
+= start
[10]; uncompressed_size
<<= 8;
17043 uncompressed_size
+= start
[11];
17048 if (uncompressed_size
)
17050 if (uncompress_section_contents (is_zstd
, &start
, uncompressed_size
,
17051 &new_size
, filedata
->file_size
))
17053 *decomp_buf
= start
;
17054 section_size
= new_size
;
17058 error (_("Unable to decompress section %s\n"),
17059 printable_section_name (filedata
, section
));
17060 return (uint64_t) -1;
17064 start
= * start_ptr
;
17066 else if (((section
->sh_flags
& SHF_COMPRESSED
) != 0)
17067 || (section_size
> 12 && streq ((char *) start
, "ZLIB")))
17069 printf (_(" NOTE: This section is compressed, but its contents have NOT been expanded for this dump.\n"));
17074 if (! apply_relocations (filedata
, section
, start
, section_size
, NULL
, NULL
))
17075 return (uint64_t) -1;
17079 Elf_Internal_Shdr
*relsec
;
17081 /* If the section being dumped has relocations against it the user might
17082 be expecting these relocations to have been applied. Check for this
17083 case and issue a warning message in order to avoid confusion.
17084 FIXME: Maybe we ought to have an option that dumps a section with
17085 relocs applied ? */
17086 for (relsec
= filedata
->section_headers
;
17087 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
17090 if ((relsec
->sh_type
!= SHT_RELA
&& relsec
->sh_type
!= SHT_REL
)
17091 || relsec
->sh_info
>= filedata
->file_header
.e_shnum
17092 || filedata
->section_headers
+ relsec
->sh_info
!= section
17093 || relsec
->sh_size
== 0
17094 || relsec
->sh_link
>= filedata
->file_header
.e_shnum
)
17097 printf (_(" NOTE: This section has relocations against it, but these have NOT been applied to this dump.\n"));
17102 * start_ptr
= start
;
17103 return section_size
;
17107 dump_section_as_strings (Elf_Internal_Shdr
* section
, Filedata
* filedata
)
17109 uint64_t num_bytes
;
17110 unsigned char *data
;
17111 unsigned char *end
;
17112 unsigned char *real_start
;
17113 unsigned char *start
;
17114 unsigned char *decomp_buf
;
17115 bool some_strings_shown
;
17117 real_start
= start
= (unsigned char *) get_section_contents (section
, filedata
);
17119 /* PR 21820: Do not fail if the section was empty. */
17120 return section
->sh_size
== 0 || section
->sh_type
== SHT_NOBITS
;
17122 num_bytes
= section
->sh_size
;
17124 if (filedata
->is_separate
)
17125 printf (_("\nString dump of section '%s' in linked file %s:\n"),
17126 printable_section_name (filedata
, section
),
17127 filedata
->file_name
);
17129 printf (_("\nString dump of section '%s':\n"),
17130 printable_section_name (filedata
, section
));
17133 num_bytes
= maybe_expand_or_relocate_section (section
, filedata
, &start
,
17134 &decomp_buf
, false);
17135 if (num_bytes
== (uint64_t) -1)
17139 end
= start
+ num_bytes
;
17140 some_strings_shown
= false;
17142 #ifdef HAVE_MBSTATE_T
17144 /* Initialise the multibyte conversion state. */
17145 memset (& state
, 0, sizeof (state
));
17148 bool continuing
= false;
17152 while (!ISPRINT (* data
))
17153 if (++ data
>= end
)
17158 size_t maxlen
= end
- data
;
17163 continuing
= false;
17167 printf (" [%6tx] ", data
- start
);
17181 /* PR 25543: Treat new-lines as string-ending characters. */
17190 /* Do not print control characters directly as they can affect terminal
17191 settings. Such characters usually appear in the names generated
17192 by the assembler for local labels. */
17195 printf ("^%c", c
+ 0x40);
17197 else if (ISPRINT (c
))
17204 #ifdef HAVE_MBSTATE_T
17207 /* Let printf do the hard work of displaying multibyte characters. */
17208 printf ("%.1s", data
- 1);
17209 #ifdef HAVE_MBSTATE_T
17210 /* Try to find out how many bytes made up the character that was
17211 just printed. Advance the symbol pointer past the bytes that
17213 n
= mbrtowc (& w
, (char *)(data
- 1), MB_CUR_MAX
, & state
);
17217 if (n
!= (size_t) -1 && n
!= (size_t) -2 && n
> 0)
17227 printf (_("<corrupt>\n"));
17230 some_strings_shown
= true;
17234 if (! some_strings_shown
)
17235 printf (_(" No strings found in this section."));
17250 dump_section_as_bytes (Elf_Internal_Shdr
*section
,
17251 Filedata
*filedata
,
17255 uint64_t section_size
;
17257 unsigned char *data
;
17258 unsigned char *real_start
;
17259 unsigned char *start
;
17260 unsigned char *decomp_buf
;
17262 real_start
= start
= (unsigned char *) get_section_contents (section
, filedata
);
17264 /* PR 21820: Do not fail if the section was empty. */
17265 return section
->sh_size
== 0 || section
->sh_type
== SHT_NOBITS
;
17267 section_size
= section
->sh_size
;
17269 if (filedata
->is_separate
)
17270 printf (_("\nHex dump of section '%s' in linked file %s:\n"),
17271 printable_section_name (filedata
, section
),
17272 filedata
->file_name
);
17274 printf (_("\nHex dump of section '%s':\n"),
17275 printable_section_name (filedata
, section
));
17278 section_size
= maybe_expand_or_relocate_section (section
, filedata
, &start
,
17279 &decomp_buf
, relocate
);
17280 if (section_size
== (uint64_t) -1)
17283 addr
= section
->sh_addr
;
17284 bytes
= section_size
;
17293 lbytes
= (bytes
> 16 ? 16 : bytes
);
17295 printf (" 0x%8.8" PRIx64
" ", addr
);
17297 for (j
= 0; j
< 16; j
++)
17300 printf ("%2.2x", data
[j
]);
17308 for (j
= 0; j
< lbytes
; j
++)
17311 if (k
>= ' ' && k
< 0x7f)
17336 #ifdef ENABLE_LIBCTF
17337 static ctf_sect_t
*
17338 shdr_to_ctf_sect (ctf_sect_t
*buf
, Elf_Internal_Shdr
*shdr
, Filedata
*filedata
)
17340 buf
->cts_name
= printable_section_name (filedata
, shdr
);
17341 buf
->cts_size
= shdr
->sh_size
;
17342 buf
->cts_entsize
= shdr
->sh_entsize
;
17347 /* Formatting callback function passed to ctf_dump. Returns either the pointer
17348 it is passed, or a pointer to newly-allocated storage, in which case
17349 dump_ctf() will free it when it no longer needs it. */
17352 dump_ctf_indent_lines (ctf_sect_names_t sect ATTRIBUTE_UNUSED
,
17353 char *s
, void *arg
)
17355 const char *blanks
= arg
;
17356 return xasprintf ("%s%s", blanks
, s
);
17359 /* Dump CTF errors/warnings. */
17361 dump_ctf_errs (ctf_dict_t
*fp
)
17363 ctf_next_t
*it
= NULL
;
17368 /* Dump accumulated errors and warnings. */
17369 while ((errtext
= ctf_errwarning_next (fp
, &it
, &is_warning
, &err
)) != NULL
)
17371 error (_("%s: %s"), is_warning
? _("warning"): _("error"),
17375 if (err
!= ECTF_NEXT_END
)
17376 error (_("CTF error: cannot get CTF errors: `%s'"), ctf_errmsg (err
));
17379 /* Dump one CTF archive member. */
17382 dump_ctf_archive_member (ctf_dict_t
*ctf
, const char *name
, ctf_dict_t
*parent
,
17385 const char *things
[] = {"Header", "Labels", "Data objects",
17386 "Function objects", "Variables", "Types", "Strings",
17388 const char **thing
;
17391 /* Don't print out the name of the default-named archive member if it appears
17392 first in the list. The name .ctf appears everywhere, even for things that
17393 aren't really archives, so printing it out is liable to be confusing; also,
17394 the common case by far is for only one archive member to exist, and hiding
17395 it in that case seems worthwhile. */
17397 if (strcmp (name
, ".ctf") != 0 || member
!= 0)
17398 printf (_("\nCTF archive member: %s:\n"), name
);
17400 if (ctf_parent_name (ctf
) != NULL
)
17401 ctf_import (ctf
, parent
);
17403 for (i
= 0, thing
= things
; *thing
[0]; thing
++, i
++)
17405 ctf_dump_state_t
*s
= NULL
;
17408 printf ("\n %s:\n", *thing
);
17409 while ((item
= ctf_dump (ctf
, &s
, i
, dump_ctf_indent_lines
,
17410 (void *) " ")) != NULL
)
17412 printf ("%s\n", item
);
17416 if (ctf_errno (ctf
))
17418 error (_("Iteration failed: %s, %s\n"), *thing
,
17419 ctf_errmsg (ctf_errno (ctf
)));
17424 dump_ctf_errs (ctf
);
17428 dump_section_as_ctf (Elf_Internal_Shdr
* section
, Filedata
* filedata
)
17430 Elf_Internal_Shdr
* symtab_sec
= NULL
;
17431 Elf_Internal_Shdr
* strtab_sec
= NULL
;
17432 void * data
= NULL
;
17433 void * symdata
= NULL
;
17434 void * strdata
= NULL
;
17435 ctf_sect_t ctfsect
, symsect
, strsect
;
17436 ctf_sect_t
* symsectp
= NULL
;
17437 ctf_sect_t
* strsectp
= NULL
;
17438 ctf_archive_t
* ctfa
= NULL
;
17439 ctf_dict_t
* parent
= NULL
;
17442 ctf_next_t
*i
= NULL
;
17448 shdr_to_ctf_sect (&ctfsect
, section
, filedata
);
17449 data
= get_section_contents (section
, filedata
);
17450 ctfsect
.cts_data
= data
;
17452 if (!dump_ctf_symtab_name
)
17453 dump_ctf_symtab_name
= strdup (".dynsym");
17455 if (!dump_ctf_strtab_name
)
17456 dump_ctf_strtab_name
= strdup (".dynstr");
17458 if (dump_ctf_symtab_name
&& dump_ctf_symtab_name
[0] != 0)
17460 if ((symtab_sec
= find_section (filedata
, dump_ctf_symtab_name
)) == NULL
)
17462 error (_("No symbol section named %s\n"), dump_ctf_symtab_name
);
17465 if ((symdata
= (void *) get_data (NULL
, filedata
,
17466 symtab_sec
->sh_offset
, 1,
17467 symtab_sec
->sh_size
,
17468 _("symbols"))) == NULL
)
17470 symsectp
= shdr_to_ctf_sect (&symsect
, symtab_sec
, filedata
);
17471 symsect
.cts_data
= symdata
;
17474 if (dump_ctf_strtab_name
&& dump_ctf_strtab_name
[0] != 0)
17476 if ((strtab_sec
= find_section (filedata
, dump_ctf_strtab_name
)) == NULL
)
17478 error (_("No string table section named %s\n"),
17479 dump_ctf_strtab_name
);
17482 if ((strdata
= (void *) get_data (NULL
, filedata
,
17483 strtab_sec
->sh_offset
, 1,
17484 strtab_sec
->sh_size
,
17485 _("strings"))) == NULL
)
17487 strsectp
= shdr_to_ctf_sect (&strsect
, strtab_sec
, filedata
);
17488 strsect
.cts_data
= strdata
;
17491 /* Load the CTF file and dump it. It may be a raw CTF section, or an archive:
17492 libctf papers over the difference, so we can pretend it is always an
17495 if ((ctfa
= ctf_arc_bufopen (&ctfsect
, symsectp
, strsectp
, &err
)) == NULL
)
17497 dump_ctf_errs (NULL
);
17498 error (_("CTF open failure: %s\n"), ctf_errmsg (err
));
17502 ctf_arc_symsect_endianness (ctfa
, filedata
->file_header
.e_ident
[EI_DATA
]
17505 /* Preload the parent dict, since it will need to be imported into every
17507 if ((parent
= ctf_dict_open (ctfa
, dump_ctf_parent_name
, &err
)) == NULL
)
17509 dump_ctf_errs (NULL
);
17510 error (_("CTF open failure: %s\n"), ctf_errmsg (err
));
17516 if (filedata
->is_separate
)
17517 printf (_("\nDump of CTF section '%s' in linked file %s:\n"),
17518 printable_section_name (filedata
, section
),
17519 filedata
->file_name
);
17521 printf (_("\nDump of CTF section '%s':\n"),
17522 printable_section_name (filedata
, section
));
17524 while ((fp
= ctf_archive_next (ctfa
, &i
, &name
, 0, &err
)) != NULL
)
17526 dump_ctf_archive_member (fp
, name
, parent
, member
++);
17527 ctf_dict_close (fp
);
17529 if (err
!= ECTF_NEXT_END
)
17531 dump_ctf_errs (NULL
);
17532 error (_("CTF member open failure: %s\n"), ctf_errmsg (err
));
17537 ctf_dict_close (parent
);
17547 load_specific_debug_section (enum dwarf_section_display_enum debug
,
17548 const Elf_Internal_Shdr
* sec
,
17551 struct dwarf_section
* section
= &debug_displays
[debug
].section
;
17553 Filedata
* filedata
= (Filedata
*) data
;
17555 if (section
->start
!= NULL
)
17557 /* If it is already loaded, do nothing. */
17558 if (streq (section
->filename
, filedata
->file_name
))
17560 free (section
->start
);
17563 snprintf (buf
, sizeof (buf
), _("%s section data"), section
->name
);
17564 section
->address
= sec
->sh_addr
;
17565 section
->filename
= filedata
->file_name
;
17566 section
->start
= (unsigned char *) get_data (NULL
, filedata
,
17568 sec
->sh_size
, buf
);
17569 if (section
->start
== NULL
)
17573 unsigned char *start
= section
->start
;
17574 uint64_t size
= sec
->sh_size
;
17575 uint64_t uncompressed_size
= 0;
17576 bool is_zstd
= false;
17578 if ((sec
->sh_flags
& SHF_COMPRESSED
) != 0)
17580 Elf_Internal_Chdr chdr
;
17581 unsigned int compression_header_size
;
17583 if (size
< (is_32bit_elf
17584 ? sizeof (Elf32_External_Chdr
)
17585 : sizeof (Elf64_External_Chdr
)))
17587 warn (_("compressed section %s is too small to contain a compression header\n"),
17592 compression_header_size
= get_compression_header (&chdr
, start
, size
);
17593 if (compression_header_size
== 0)
17594 /* An error message will have already been generated
17595 by get_compression_header. */
17598 if (chdr
.ch_type
== ch_compress_zlib
)
17601 else if (chdr
.ch_type
== ch_compress_zstd
)
17606 warn (_("section '%s' has unsupported compress type: %d\n"),
17607 section
->name
, chdr
.ch_type
);
17610 uncompressed_size
= chdr
.ch_size
;
17611 start
+= compression_header_size
;
17612 size
-= compression_header_size
;
17614 else if (size
> 12 && streq ((char *) start
, "ZLIB"))
17616 /* Read the zlib header. In this case, it should be "ZLIB"
17617 followed by the uncompressed section size, 8 bytes in
17618 big-endian order. */
17619 uncompressed_size
= start
[4]; uncompressed_size
<<= 8;
17620 uncompressed_size
+= start
[5]; uncompressed_size
<<= 8;
17621 uncompressed_size
+= start
[6]; uncompressed_size
<<= 8;
17622 uncompressed_size
+= start
[7]; uncompressed_size
<<= 8;
17623 uncompressed_size
+= start
[8]; uncompressed_size
<<= 8;
17624 uncompressed_size
+= start
[9]; uncompressed_size
<<= 8;
17625 uncompressed_size
+= start
[10]; uncompressed_size
<<= 8;
17626 uncompressed_size
+= start
[11];
17631 if (uncompressed_size
)
17633 if (uncompress_section_contents (is_zstd
, &start
, uncompressed_size
,
17634 &size
, filedata
->file_size
))
17636 /* Free the compressed buffer, update the section buffer
17637 and the section size if uncompress is successful. */
17638 free (section
->start
);
17639 section
->start
= start
;
17643 error (_("Unable to decompress section %s\n"),
17644 printable_section_name (filedata
, sec
));
17649 section
->size
= size
;
17652 if (section
->start
== NULL
)
17655 if (debug_displays
[debug
].relocate
)
17657 if (! apply_relocations (filedata
, sec
, section
->start
, section
->size
,
17658 & section
->reloc_info
, & section
->num_relocs
))
17663 section
->reloc_info
= NULL
;
17664 section
->num_relocs
= 0;
17670 #if HAVE_LIBDEBUGINFOD
17671 /* Return a hex string representation of the build-id. */
17673 get_build_id (void * data
)
17675 Filedata
* filedata
= (Filedata
*) data
;
17676 Elf_Internal_Shdr
* shdr
;
17679 /* Iterate through notes to find note.gnu.build-id.
17680 FIXME: Only the first note in any note section is examined. */
17681 for (i
= 0, shdr
= filedata
->section_headers
;
17682 i
< filedata
->file_header
.e_shnum
&& shdr
!= NULL
;
17685 if (shdr
->sh_type
!= SHT_NOTE
)
17690 size_t data_remaining
;
17692 Elf_External_Note
* enote
;
17693 Elf_Internal_Note inote
;
17695 uint64_t offset
= shdr
->sh_offset
;
17696 uint64_t align
= shdr
->sh_addralign
;
17697 uint64_t length
= shdr
->sh_size
;
17699 enote
= (Elf_External_Note
*) get_section_contents (shdr
, filedata
);
17705 else if (align
!= 4 && align
!= 8)
17711 end
= (char *) enote
+ length
;
17712 data_remaining
= end
- (char *) enote
;
17714 if (!is_ia64_vms (filedata
))
17716 min_notesz
= offsetof (Elf_External_Note
, name
);
17717 if (data_remaining
< min_notesz
)
17720 malformed note encountered in section %s whilst scanning for build-id note\n"),
17721 printable_section_name (filedata
, shdr
));
17725 data_remaining
-= min_notesz
;
17727 inote
.type
= BYTE_GET (enote
->type
);
17728 inote
.namesz
= BYTE_GET (enote
->namesz
);
17729 inote
.namedata
= enote
->name
;
17730 inote
.descsz
= BYTE_GET (enote
->descsz
);
17731 inote
.descdata
= ((char *) enote
17732 + ELF_NOTE_DESC_OFFSET (inote
.namesz
, align
));
17733 inote
.descpos
= offset
+ (inote
.descdata
- (char *) enote
);
17734 next
= ((char *) enote
17735 + ELF_NOTE_NEXT_OFFSET (inote
.namesz
, inote
.descsz
, align
));
17739 Elf64_External_VMS_Note
*vms_enote
;
17741 /* PR binutils/15191
17742 Make sure that there is enough data to read. */
17743 min_notesz
= offsetof (Elf64_External_VMS_Note
, name
);
17744 if (data_remaining
< min_notesz
)
17747 malformed note encountered in section %s whilst scanning for build-id note\n"),
17748 printable_section_name (filedata
, shdr
));
17752 data_remaining
-= min_notesz
;
17754 vms_enote
= (Elf64_External_VMS_Note
*) enote
;
17755 inote
.type
= BYTE_GET (vms_enote
->type
);
17756 inote
.namesz
= BYTE_GET (vms_enote
->namesz
);
17757 inote
.namedata
= vms_enote
->name
;
17758 inote
.descsz
= BYTE_GET (vms_enote
->descsz
);
17759 inote
.descdata
= inote
.namedata
+ align_power (inote
.namesz
, 3);
17760 inote
.descpos
= offset
+ (inote
.descdata
- (char *) enote
);
17761 next
= inote
.descdata
+ align_power (inote
.descsz
, 3);
17764 /* Skip malformed notes. */
17765 if ((size_t) (inote
.descdata
- inote
.namedata
) < inote
.namesz
17766 || (size_t) (inote
.descdata
- inote
.namedata
) > data_remaining
17767 || (size_t) (next
- inote
.descdata
) < inote
.descsz
17768 || ((size_t) (next
- inote
.descdata
)
17769 > data_remaining
- (size_t) (inote
.descdata
- inote
.namedata
)))
17772 malformed note encountered in section %s whilst scanning for build-id note\n"),
17773 printable_section_name (filedata
, shdr
));
17778 /* Check if this is the build-id note. If so then convert the build-id
17779 bytes to a hex string. */
17780 if (inote
.namesz
> 0
17781 && startswith (inote
.namedata
, "GNU")
17782 && inote
.type
== NT_GNU_BUILD_ID
)
17787 build_id
= malloc (inote
.descsz
* 2 + 1);
17788 if (build_id
== NULL
)
17794 for (j
= 0; j
< inote
.descsz
; ++j
)
17795 sprintf (build_id
+ (j
* 2), "%02x", inote
.descdata
[j
] & 0xff);
17796 build_id
[inote
.descsz
* 2] = '\0';
17799 return (unsigned char *) build_id
;
17806 #endif /* HAVE_LIBDEBUGINFOD */
17808 /* If this is not NULL, load_debug_section will only look for sections
17809 within the list of sections given here. */
17810 static unsigned int * section_subset
= NULL
;
17813 load_debug_section (enum dwarf_section_display_enum debug
, void * data
)
17815 struct dwarf_section
* section
= &debug_displays
[debug
].section
;
17816 Elf_Internal_Shdr
* sec
;
17817 Filedata
* filedata
= (Filedata
*) data
;
17819 if (!dump_any_debugging
)
17822 /* Without section headers we cannot find any sections. */
17823 if (filedata
->section_headers
== NULL
)
17826 if (filedata
->string_table
== NULL
17827 && filedata
->file_header
.e_shstrndx
!= SHN_UNDEF
17828 && filedata
->file_header
.e_shstrndx
< filedata
->file_header
.e_shnum
)
17830 Elf_Internal_Shdr
* strs
;
17832 /* Read in the string table, so that we have section names to scan. */
17833 strs
= filedata
->section_headers
+ filedata
->file_header
.e_shstrndx
;
17835 if (strs
!= NULL
&& strs
->sh_size
!= 0)
17837 filedata
->string_table
17838 = (char *) get_data (NULL
, filedata
, strs
->sh_offset
,
17839 1, strs
->sh_size
, _("string table"));
17841 filedata
->string_table_length
17842 = filedata
->string_table
!= NULL
? strs
->sh_size
: 0;
17846 /* Locate the debug section. */
17847 sec
= find_section_in_set (filedata
, section
->uncompressed_name
, section_subset
);
17849 section
->name
= section
->uncompressed_name
;
17852 sec
= find_section_in_set (filedata
, section
->compressed_name
, section_subset
);
17854 section
->name
= section
->compressed_name
;
17859 /* If we're loading from a subset of sections, and we've loaded
17860 a section matching this name before, it's likely that it's a
17862 if (section_subset
!= NULL
)
17863 free_debug_section (debug
);
17865 return load_specific_debug_section (debug
, sec
, data
);
17869 free_debug_section (enum dwarf_section_display_enum debug
)
17871 struct dwarf_section
* section
= &debug_displays
[debug
].section
;
17873 if (section
->start
== NULL
)
17876 free ((char *) section
->start
);
17877 section
->start
= NULL
;
17878 section
->address
= 0;
17881 free (section
->reloc_info
);
17882 section
->reloc_info
= NULL
;
17883 section
->num_relocs
= 0;
17887 display_debug_section (int shndx
, Elf_Internal_Shdr
* section
, Filedata
* filedata
)
17889 const char *name
= (section_name_valid (filedata
, section
)
17890 ? section_name (filedata
, section
) : "");
17891 const char *print_name
= printable_section_name (filedata
, section
);
17893 bool result
= true;
17896 length
= section
->sh_size
;
17899 printf (_("\nSection '%s' has no debugging data.\n"), print_name
);
17902 if (section
->sh_type
== SHT_NOBITS
)
17904 /* There is no point in dumping the contents of a debugging section
17905 which has the NOBITS type - the bits in the file will be random.
17906 This can happen when a file containing a .eh_frame section is
17907 stripped with the --only-keep-debug command line option. */
17908 printf (_("section '%s' has the NOBITS type - its contents are unreliable.\n"),
17913 if (startswith (name
, ".gnu.linkonce.wi."))
17914 name
= ".debug_info";
17916 /* See if we know how to display the contents of this section. */
17917 for (i
= 0; i
< max
; i
++)
17919 enum dwarf_section_display_enum id
= (enum dwarf_section_display_enum
) i
;
17920 struct dwarf_section_display
* display
= debug_displays
+ i
;
17921 struct dwarf_section
* sec
= & display
->section
;
17923 if (streq (sec
->uncompressed_name
, name
)
17924 || (id
== line
&& startswith (name
, ".debug_line."))
17925 || (id
== sframe
&& section
->sh_type
== SHT_GNU_SFRAME
)
17926 || streq (sec
->compressed_name
, name
))
17928 bool secondary
= (section
!= find_section (filedata
, name
));
17931 free_debug_section (id
);
17933 if (i
== line
&& startswith (name
, ".debug_line."))
17935 else if (id
== sframe
&& section
->sh_type
== SHT_GNU_SFRAME
)
17937 else if (streq (sec
->uncompressed_name
, name
))
17938 sec
->name
= sec
->uncompressed_name
;
17940 sec
->name
= sec
->compressed_name
;
17942 if (load_specific_debug_section (id
, section
, filedata
))
17944 /* If this debug section is part of a CU/TU set in a .dwp file,
17945 restrict load_debug_section to the sections in that set. */
17946 section_subset
= find_cu_tu_set (filedata
, shndx
);
17948 result
&= display
->display (sec
, filedata
);
17950 section_subset
= NULL
;
17952 if (secondary
|| (id
!= info
&& id
!= abbrev
&& id
!= debug_addr
))
17953 free_debug_section (id
);
17961 printf (_("Unrecognized debug section: %s\n"), print_name
);
17968 /* Set DUMP_SECTS for all sections where dumps were requested
17969 based on section name. */
17972 initialise_dumps_byname (Filedata
* filedata
)
17974 struct dump_list_entry
* cur
;
17976 for (cur
= dump_sects_byname
; cur
; cur
= cur
->next
)
17981 for (i
= 0; i
< filedata
->file_header
.e_shnum
; i
++)
17982 if (section_name_valid (filedata
, filedata
->section_headers
+ i
)
17983 && streq (section_name (filedata
, filedata
->section_headers
+ i
),
17986 request_dump_bynumber (&filedata
->dump
, i
, cur
->type
);
17990 if (!any
&& !filedata
->is_separate
)
17991 warn (_("Section '%s' was not dumped because it does not exist\n"),
17997 process_section_contents (Filedata
* filedata
)
17999 Elf_Internal_Shdr
* section
;
18006 initialise_dumps_byname (filedata
);
18008 for (i
= 0, section
= filedata
->section_headers
;
18009 i
< filedata
->file_header
.e_shnum
&& i
< filedata
->dump
.num_dump_sects
;
18012 dump_type dump
= filedata
->dump
.dump_sects
[i
];
18014 if (filedata
->is_separate
&& ! process_links
)
18015 dump
&= DEBUG_DUMP
;
18017 if (dump
& AUTO_DUMP
)
18019 switch (section
->sh_type
)
18022 /* FIXME: There are lots of different type of section that have
18023 SHT_PROGBITS set in their header - code, debug info, etc. So
18024 we should check the section's name and interpret its contents
18025 that way, rather than just defaulting to a byte dump. */
18026 #ifdef SUPPORT_DISASSEMBLY
18027 res
&= disassemble_section (section
, filedata
);
18029 res
&= dump_section_as_bytes (section
, filedata
, false);
18035 res
&= dump_symbol_section (section
, filedata
);
18039 res
&= dump_section_as_strings (section
, filedata
);
18045 res
&= display_relocations (section
, filedata
, true);
18049 res
&= process_notes_at (filedata
, section
, section
->sh_offset
,
18050 section
->sh_size
, section
->sh_addralign
);
18054 inform (_("Unable to display section %d - it has a NULL type\n"), i
);
18058 inform (_("Unable to display section %d - it has no contents\n"), i
);
18064 case SHT_GNU_ATTRIBUTES
:
18065 /* FIXME: Implement these. */
18066 /* Fall through. */
18068 /* FIXME: Add Proc and OS specific section types ? */
18069 warn (_("Unable to determine how to dump section %d (type %#x)\n"),
18070 i
, section
->sh_type
);
18076 #ifdef SUPPORT_DISASSEMBLY
18077 if (dump
& DISASS_DUMP
)
18079 if (! disassemble_section (section
, filedata
))
18083 if (dump
& HEX_DUMP
)
18085 if (! dump_section_as_bytes (section
, filedata
, false))
18089 if (dump
& RELOC_DUMP
)
18091 if (! dump_section_as_bytes (section
, filedata
, true))
18095 if (dump
& STRING_DUMP
)
18097 if (! dump_section_as_strings (section
, filedata
))
18101 if (dump
& DEBUG_DUMP
)
18103 if (! display_debug_section (i
, section
, filedata
))
18107 #ifdef ENABLE_LIBCTF
18108 if (dump
& CTF_DUMP
)
18110 if (! dump_section_as_ctf (section
, filedata
))
18114 if (dump
& SFRAME_DUMP
)
18116 if (! display_debug_section (i
, section
, filedata
))
18121 if (! filedata
->is_separate
)
18123 /* Check to see if the user requested a
18124 dump of a section that does not exist. */
18125 for (; i
< filedata
->dump
.num_dump_sects
; i
++)
18126 if (filedata
->dump
.dump_sects
[i
])
18128 warn (_("Section %d was not dumped because it does not exist!\n"), i
);
18137 process_mips_fpe_exception (int mask
)
18143 if (mask
& OEX_FPU_INEX
)
18144 fputs ("INEX", stdout
), first
= false;
18145 if (mask
& OEX_FPU_UFLO
)
18146 printf ("%sUFLO", first
? "" : "|"), first
= false;
18147 if (mask
& OEX_FPU_OFLO
)
18148 printf ("%sOFLO", first
? "" : "|"), first
= false;
18149 if (mask
& OEX_FPU_DIV0
)
18150 printf ("%sDIV0", first
? "" : "|"), first
= false;
18151 if (mask
& OEX_FPU_INVAL
)
18152 printf ("%sINVAL", first
? "" : "|");
18155 fputs ("0", stdout
);
18158 /* Display's the value of TAG at location P. If TAG is
18159 greater than 0 it is assumed to be an unknown tag, and
18160 a message is printed to this effect. Otherwise it is
18161 assumed that a message has already been printed.
18163 If the bottom bit of TAG is set it assumed to have a
18164 string value, otherwise it is assumed to have an integer
18167 Returns an updated P pointing to the first unread byte
18168 beyond the end of TAG's value.
18170 Reads at or beyond END will not be made. */
18172 static unsigned char *
18173 display_tag_value (signed int tag
,
18175 const unsigned char * const end
)
18180 printf (" Tag_unknown_%d: ", tag
);
18184 warn (_("<corrupt tag>\n"));
18188 /* PR 17531 file: 027-19978-0.004. */
18189 size_t maxlen
= end
- p
;
18194 maxlen
-= 1; /* Remove \0 from the character count. */
18195 print_symbol_name ((int) maxlen
, (const char *) p
);
18196 size_t len
= strnlen ((char *) p
, maxlen
);
18197 if (len
== maxlen
&& p
[maxlen
] != '\0')
18198 printf (_("<corrupt string tag>"));
18203 printf (_("<corrupt string tag>"));
18204 p
= (unsigned char *) end
;
18210 READ_ULEB (val
, p
, end
);
18211 printf ("%" PRId64
" (0x%" PRIx64
")\n", val
, val
);
18218 /* ARC ABI attributes section. */
18220 static unsigned char *
18221 display_arc_attribute (unsigned char * p
,
18222 const unsigned char * const end
)
18227 READ_ULEB (tag
, p
, end
);
18231 case Tag_ARC_PCS_config
:
18232 READ_ULEB (val
, p
, end
);
18233 printf (" Tag_ARC_PCS_config: ");
18237 printf (_("Absent/Non standard\n"));
18240 printf (_("Bare metal/mwdt\n"));
18243 printf (_("Bare metal/newlib\n"));
18246 printf (_("Linux/uclibc\n"));
18249 printf (_("Linux/glibc\n"));
18252 printf (_("Unknown\n"));
18257 case Tag_ARC_CPU_base
:
18258 READ_ULEB (val
, p
, end
);
18259 printf (" Tag_ARC_CPU_base: ");
18264 printf (_("Absent\n"));
18266 case TAG_CPU_ARC6xx
:
18267 printf ("ARC6xx\n");
18269 case TAG_CPU_ARC7xx
:
18270 printf ("ARC7xx\n");
18272 case TAG_CPU_ARCEM
:
18273 printf ("ARCEM\n");
18275 case TAG_CPU_ARCHS
:
18276 printf ("ARCHS\n");
18281 case Tag_ARC_CPU_variation
:
18282 READ_ULEB (val
, p
, end
);
18283 printf (" Tag_ARC_CPU_variation: ");
18287 if (val
> 0 && val
< 16)
18288 printf ("Core%d\n", val
);
18290 printf ("Unknown\n");
18294 printf (_("Absent\n"));
18299 case Tag_ARC_CPU_name
:
18300 printf (" Tag_ARC_CPU_name: ");
18301 p
= display_tag_value (-1, p
, end
);
18304 case Tag_ARC_ABI_rf16
:
18305 READ_ULEB (val
, p
, end
);
18306 printf (" Tag_ARC_ABI_rf16: %s\n", val
? _("yes") : _("no"));
18309 case Tag_ARC_ABI_osver
:
18310 READ_ULEB (val
, p
, end
);
18311 printf (" Tag_ARC_ABI_osver: v%d\n", val
);
18314 case Tag_ARC_ABI_pic
:
18315 case Tag_ARC_ABI_sda
:
18316 READ_ULEB (val
, p
, end
);
18317 printf (tag
== Tag_ARC_ABI_sda
? " Tag_ARC_ABI_sda: "
18318 : " Tag_ARC_ABI_pic: ");
18322 printf (_("Absent\n"));
18331 printf (_("Unknown\n"));
18336 case Tag_ARC_ABI_tls
:
18337 READ_ULEB (val
, p
, end
);
18338 printf (" Tag_ARC_ABI_tls: %s\n", val
? "r25": "none");
18341 case Tag_ARC_ABI_enumsize
:
18342 READ_ULEB (val
, p
, end
);
18343 printf (" Tag_ARC_ABI_enumsize: %s\n", val
? _("default") :
18347 case Tag_ARC_ABI_exceptions
:
18348 READ_ULEB (val
, p
, end
);
18349 printf (" Tag_ARC_ABI_exceptions: %s\n", val
? _("OPTFP")
18353 case Tag_ARC_ABI_double_size
:
18354 READ_ULEB (val
, p
, end
);
18355 printf (" Tag_ARC_ABI_double_size: %d\n", val
);
18358 case Tag_ARC_ISA_config
:
18359 printf (" Tag_ARC_ISA_config: ");
18360 p
= display_tag_value (-1, p
, end
);
18363 case Tag_ARC_ISA_apex
:
18364 printf (" Tag_ARC_ISA_apex: ");
18365 p
= display_tag_value (-1, p
, end
);
18368 case Tag_ARC_ISA_mpy_option
:
18369 READ_ULEB (val
, p
, end
);
18370 printf (" Tag_ARC_ISA_mpy_option: %d\n", val
);
18373 case Tag_ARC_ATR_version
:
18374 READ_ULEB (val
, p
, end
);
18375 printf (" Tag_ARC_ATR_version: %d\n", val
);
18379 return display_tag_value (tag
& 1, p
, end
);
18385 /* ARM EABI attributes section. */
18390 /* 0 = special, 1 = string, 2 = uleb123, > 0x80 == table lookup. */
18392 const char *const *table
;
18393 } arm_attr_public_tag
;
18395 static const char *const arm_attr_tag_CPU_arch
[] =
18396 {"Pre-v4", "v4", "v4T", "v5T", "v5TE", "v5TEJ", "v6", "v6KZ", "v6T2",
18397 "v6K", "v7", "v6-M", "v6S-M", "v7E-M", "v8", "v8-R", "v8-M.baseline",
18398 "v8-M.mainline", "v8.1-A", "v8.2-A", "v8.3-A",
18399 "v8.1-M.mainline", "v9"};
18400 static const char *const arm_attr_tag_ARM_ISA_use
[] = {"No", "Yes"};
18401 static const char *const arm_attr_tag_THUMB_ISA_use
[] =
18402 {"No", "Thumb-1", "Thumb-2", "Yes"};
18403 static const char *const arm_attr_tag_FP_arch
[] =
18404 {"No", "VFPv1", "VFPv2", "VFPv3", "VFPv3-D16", "VFPv4", "VFPv4-D16",
18405 "FP for ARMv8", "FPv5/FP-D16 for ARMv8"};
18406 static const char *const arm_attr_tag_WMMX_arch
[] = {"No", "WMMXv1", "WMMXv2"};
18407 static const char *const arm_attr_tag_Advanced_SIMD_arch
[] =
18408 {"No", "NEONv1", "NEONv1 with Fused-MAC", "NEON for ARMv8",
18409 "NEON for ARMv8.1"};
18410 static const char *const arm_attr_tag_PCS_config
[] =
18411 {"None", "Bare platform", "Linux application", "Linux DSO", "PalmOS 2004",
18412 "PalmOS (reserved)", "SymbianOS 2004", "SymbianOS (reserved)"};
18413 static const char *const arm_attr_tag_ABI_PCS_R9_use
[] =
18414 {"V6", "SB", "TLS", "Unused"};
18415 static const char *const arm_attr_tag_ABI_PCS_RW_data
[] =
18416 {"Absolute", "PC-relative", "SB-relative", "None"};
18417 static const char *const arm_attr_tag_ABI_PCS_RO_data
[] =
18418 {"Absolute", "PC-relative", "None"};
18419 static const char *const arm_attr_tag_ABI_PCS_GOT_use
[] =
18420 {"None", "direct", "GOT-indirect"};
18421 static const char *const arm_attr_tag_ABI_PCS_wchar_t
[] =
18422 {"None", "??? 1", "2", "??? 3", "4"};
18423 static const char *const arm_attr_tag_ABI_FP_rounding
[] = {"Unused", "Needed"};
18424 static const char *const arm_attr_tag_ABI_FP_denormal
[] =
18425 {"Unused", "Needed", "Sign only"};
18426 static const char *const arm_attr_tag_ABI_FP_exceptions
[] = {"Unused", "Needed"};
18427 static const char *const arm_attr_tag_ABI_FP_user_exceptions
[] = {"Unused", "Needed"};
18428 static const char *const arm_attr_tag_ABI_FP_number_model
[] =
18429 {"Unused", "Finite", "RTABI", "IEEE 754"};
18430 static const char *const arm_attr_tag_ABI_enum_size
[] =
18431 {"Unused", "small", "int", "forced to int"};
18432 static const char *const arm_attr_tag_ABI_HardFP_use
[] =
18433 {"As Tag_FP_arch", "SP only", "Reserved", "Deprecated"};
18434 static const char *const arm_attr_tag_ABI_VFP_args
[] =
18435 {"AAPCS", "VFP registers", "custom", "compatible"};
18436 static const char *const arm_attr_tag_ABI_WMMX_args
[] =
18437 {"AAPCS", "WMMX registers", "custom"};
18438 static const char *const arm_attr_tag_ABI_optimization_goals
[] =
18439 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
18440 "Aggressive Size", "Prefer Debug", "Aggressive Debug"};
18441 static const char *const arm_attr_tag_ABI_FP_optimization_goals
[] =
18442 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
18443 "Aggressive Size", "Prefer Accuracy", "Aggressive Accuracy"};
18444 static const char *const arm_attr_tag_CPU_unaligned_access
[] = {"None", "v6"};
18445 static const char *const arm_attr_tag_FP_HP_extension
[] =
18446 {"Not Allowed", "Allowed"};
18447 static const char *const arm_attr_tag_ABI_FP_16bit_format
[] =
18448 {"None", "IEEE 754", "Alternative Format"};
18449 static const char *const arm_attr_tag_DSP_extension
[] =
18450 {"Follow architecture", "Allowed"};
18451 static const char *const arm_attr_tag_MPextension_use
[] =
18452 {"Not Allowed", "Allowed"};
18453 static const char *const arm_attr_tag_DIV_use
[] =
18454 {"Allowed in Thumb-ISA, v7-R or v7-M", "Not allowed",
18455 "Allowed in v7-A with integer division extension"};
18456 static const char *const arm_attr_tag_T2EE_use
[] = {"Not Allowed", "Allowed"};
18457 static const char *const arm_attr_tag_Virtualization_use
[] =
18458 {"Not Allowed", "TrustZone", "Virtualization Extensions",
18459 "TrustZone and Virtualization Extensions"};
18460 static const char *const arm_attr_tag_MPextension_use_legacy
[] =
18461 {"Not Allowed", "Allowed"};
18463 static const char *const arm_attr_tag_MVE_arch
[] =
18464 {"No MVE", "MVE Integer only", "MVE Integer and FP"};
18466 static const char * arm_attr_tag_PAC_extension
[] =
18467 {"No PAC/AUT instructions",
18468 "PAC/AUT instructions permitted in the NOP space",
18469 "PAC/AUT instructions permitted in the NOP and in the non-NOP space"};
18471 static const char * arm_attr_tag_BTI_extension
[] =
18472 {"BTI instructions not permitted",
18473 "BTI instructions permitted in the NOP space",
18474 "BTI instructions permitted in the NOP and in the non-NOP space"};
18476 static const char * arm_attr_tag_BTI_use
[] =
18477 {"Compiled without branch target enforcement",
18478 "Compiled with branch target enforcement"};
18480 static const char * arm_attr_tag_PACRET_use
[] =
18481 {"Compiled without return address signing and authentication",
18482 "Compiled with return address signing and authentication"};
18484 #define LOOKUP(id, name) \
18485 {id, #name, 0x80 | ARRAY_SIZE(arm_attr_tag_##name), arm_attr_tag_##name}
18486 static arm_attr_public_tag arm_attr_public_tags
[] =
18488 {4, "CPU_raw_name", 1, NULL
},
18489 {5, "CPU_name", 1, NULL
},
18490 LOOKUP(6, CPU_arch
),
18491 {7, "CPU_arch_profile", 0, NULL
},
18492 LOOKUP(8, ARM_ISA_use
),
18493 LOOKUP(9, THUMB_ISA_use
),
18494 LOOKUP(10, FP_arch
),
18495 LOOKUP(11, WMMX_arch
),
18496 LOOKUP(12, Advanced_SIMD_arch
),
18497 LOOKUP(13, PCS_config
),
18498 LOOKUP(14, ABI_PCS_R9_use
),
18499 LOOKUP(15, ABI_PCS_RW_data
),
18500 LOOKUP(16, ABI_PCS_RO_data
),
18501 LOOKUP(17, ABI_PCS_GOT_use
),
18502 LOOKUP(18, ABI_PCS_wchar_t
),
18503 LOOKUP(19, ABI_FP_rounding
),
18504 LOOKUP(20, ABI_FP_denormal
),
18505 LOOKUP(21, ABI_FP_exceptions
),
18506 LOOKUP(22, ABI_FP_user_exceptions
),
18507 LOOKUP(23, ABI_FP_number_model
),
18508 {24, "ABI_align_needed", 0, NULL
},
18509 {25, "ABI_align_preserved", 0, NULL
},
18510 LOOKUP(26, ABI_enum_size
),
18511 LOOKUP(27, ABI_HardFP_use
),
18512 LOOKUP(28, ABI_VFP_args
),
18513 LOOKUP(29, ABI_WMMX_args
),
18514 LOOKUP(30, ABI_optimization_goals
),
18515 LOOKUP(31, ABI_FP_optimization_goals
),
18516 {32, "compatibility", 0, NULL
},
18517 LOOKUP(34, CPU_unaligned_access
),
18518 LOOKUP(36, FP_HP_extension
),
18519 LOOKUP(38, ABI_FP_16bit_format
),
18520 LOOKUP(42, MPextension_use
),
18521 LOOKUP(44, DIV_use
),
18522 LOOKUP(46, DSP_extension
),
18523 LOOKUP(48, MVE_arch
),
18524 LOOKUP(50, PAC_extension
),
18525 LOOKUP(52, BTI_extension
),
18526 LOOKUP(74, BTI_use
),
18527 LOOKUP(76, PACRET_use
),
18528 {64, "nodefaults", 0, NULL
},
18529 {65, "also_compatible_with", 0, NULL
},
18530 LOOKUP(66, T2EE_use
),
18531 {67, "conformance", 1, NULL
},
18532 LOOKUP(68, Virtualization_use
),
18533 LOOKUP(70, MPextension_use_legacy
)
18537 static unsigned char *
18538 display_arm_attribute (unsigned char * p
,
18539 const unsigned char * const end
)
18543 arm_attr_public_tag
* attr
;
18547 READ_ULEB (tag
, p
, end
);
18549 for (i
= 0; i
< ARRAY_SIZE (arm_attr_public_tags
); i
++)
18551 if (arm_attr_public_tags
[i
].tag
== tag
)
18553 attr
= &arm_attr_public_tags
[i
];
18560 printf (" Tag_%s: ", attr
->name
);
18561 switch (attr
->type
)
18566 case 7: /* Tag_CPU_arch_profile. */
18567 READ_ULEB (val
, p
, end
);
18570 case 0: printf (_("None\n")); break;
18571 case 'A': printf (_("Application\n")); break;
18572 case 'R': printf (_("Realtime\n")); break;
18573 case 'M': printf (_("Microcontroller\n")); break;
18574 case 'S': printf (_("Application or Realtime\n")); break;
18575 default: printf ("??? (%d)\n", val
); break;
18579 case 24: /* Tag_align_needed. */
18580 READ_ULEB (val
, p
, end
);
18583 case 0: printf (_("None\n")); break;
18584 case 1: printf (_("8-byte\n")); break;
18585 case 2: printf (_("4-byte\n")); break;
18586 case 3: printf ("??? 3\n"); break;
18589 printf (_("8-byte and up to %d-byte extended\n"),
18592 printf ("??? (%d)\n", val
);
18597 case 25: /* Tag_align_preserved. */
18598 READ_ULEB (val
, p
, end
);
18601 case 0: printf (_("None\n")); break;
18602 case 1: printf (_("8-byte, except leaf SP\n")); break;
18603 case 2: printf (_("8-byte\n")); break;
18604 case 3: printf ("??? 3\n"); break;
18607 printf (_("8-byte and up to %d-byte extended\n"),
18610 printf ("??? (%d)\n", val
);
18615 case 32: /* Tag_compatibility. */
18617 READ_ULEB (val
, p
, end
);
18618 printf (_("flag = %d, vendor = "), val
);
18621 size_t maxlen
= (end
- p
) - 1;
18623 print_symbol_name ((int) maxlen
, (const char *) p
);
18624 p
+= strnlen ((char *) p
, maxlen
) + 1;
18628 printf (_("<corrupt>"));
18629 p
= (unsigned char *) end
;
18635 case 64: /* Tag_nodefaults. */
18636 /* PR 17531: file: 001-505008-0.01. */
18639 printf (_("True\n"));
18642 case 65: /* Tag_also_compatible_with. */
18643 READ_ULEB (val
, p
, end
);
18644 if (val
== 6 /* Tag_CPU_arch. */)
18646 READ_ULEB (val
, p
, end
);
18647 if ((unsigned int) val
>= ARRAY_SIZE (arm_attr_tag_CPU_arch
))
18648 printf ("??? (%d)\n", val
);
18650 printf ("%s\n", arm_attr_tag_CPU_arch
[val
]);
18654 while (p
< end
&& *(p
++) != '\0' /* NUL terminator. */)
18659 printf (_("<unknown: %d>\n"), tag
);
18665 return display_tag_value (-1, p
, end
);
18667 return display_tag_value (0, p
, end
);
18670 assert (attr
->type
& 0x80);
18671 READ_ULEB (val
, p
, end
);
18672 type
= attr
->type
& 0x7f;
18674 printf ("??? (%d)\n", val
);
18676 printf ("%s\n", attr
->table
[val
]);
18681 return display_tag_value (tag
, p
, end
);
18684 static unsigned char *
18685 display_gnu_attribute (unsigned char * p
,
18686 unsigned char * (* display_proc_gnu_attribute
)
18687 (unsigned char *, unsigned int, const unsigned char * const),
18688 const unsigned char * const end
)
18693 READ_ULEB (tag
, p
, end
);
18695 /* Tag_compatibility is the only generic GNU attribute defined at
18699 READ_ULEB (val
, p
, end
);
18701 printf (_("flag = %d, vendor = "), val
);
18704 printf (_("<corrupt>\n"));
18705 warn (_("corrupt vendor attribute\n"));
18711 size_t maxlen
= (end
- p
) - 1;
18713 print_symbol_name ((int) maxlen
, (const char *) p
);
18714 p
+= strnlen ((char *) p
, maxlen
) + 1;
18718 printf (_("<corrupt>"));
18719 p
= (unsigned char *) end
;
18726 if ((tag
& 2) == 0 && display_proc_gnu_attribute
)
18727 return display_proc_gnu_attribute (p
, tag
, end
);
18729 return display_tag_value (tag
, p
, end
);
18732 static unsigned char *
18733 display_m68k_gnu_attribute (unsigned char * p
,
18735 const unsigned char * const end
)
18739 if (tag
== Tag_GNU_M68K_ABI_FP
)
18741 printf (" Tag_GNU_M68K_ABI_FP: ");
18744 printf (_("<corrupt>\n"));
18747 READ_ULEB (val
, p
, end
);
18750 printf ("(%#x), ", val
);
18755 printf (_("unspecified hard/soft float\n"));
18758 printf (_("hard float\n"));
18761 printf (_("soft float\n"));
18767 return display_tag_value (tag
& 1, p
, end
);
18770 static unsigned char *
18771 display_power_gnu_attribute (unsigned char * p
,
18773 const unsigned char * const end
)
18777 if (tag
== Tag_GNU_Power_ABI_FP
)
18779 printf (" Tag_GNU_Power_ABI_FP: ");
18782 printf (_("<corrupt>\n"));
18785 READ_ULEB (val
, p
, end
);
18788 printf ("(%#x), ", val
);
18793 printf (_("unspecified hard/soft float, "));
18796 printf (_("hard float, "));
18799 printf (_("soft float, "));
18802 printf (_("single-precision hard float, "));
18809 printf (_("unspecified long double\n"));
18812 printf (_("128-bit IBM long double\n"));
18815 printf (_("64-bit long double\n"));
18818 printf (_("128-bit IEEE long double\n"));
18824 if (tag
== Tag_GNU_Power_ABI_Vector
)
18826 printf (" Tag_GNU_Power_ABI_Vector: ");
18829 printf (_("<corrupt>\n"));
18832 READ_ULEB (val
, p
, end
);
18835 printf ("(%#x), ", val
);
18840 printf (_("unspecified\n"));
18843 printf (_("generic\n"));
18846 printf ("AltiVec\n");
18855 if (tag
== Tag_GNU_Power_ABI_Struct_Return
)
18857 printf (" Tag_GNU_Power_ABI_Struct_Return: ");
18860 printf (_("<corrupt>\n"));
18863 READ_ULEB (val
, p
, end
);
18866 printf ("(%#x), ", val
);
18871 printf (_("unspecified\n"));
18874 printf ("r3/r4\n");
18877 printf (_("memory\n"));
18886 return display_tag_value (tag
& 1, p
, end
);
18889 static unsigned char *
18890 display_s390_gnu_attribute (unsigned char * p
,
18892 const unsigned char * const end
)
18896 if (tag
== Tag_GNU_S390_ABI_Vector
)
18898 printf (" Tag_GNU_S390_ABI_Vector: ");
18899 READ_ULEB (val
, p
, end
);
18904 printf (_("any\n"));
18907 printf (_("software\n"));
18910 printf (_("hardware\n"));
18913 printf ("??? (%d)\n", val
);
18919 return display_tag_value (tag
& 1, p
, end
);
18923 display_sparc_hwcaps (unsigned int mask
)
18929 if (mask
& ELF_SPARC_HWCAP_MUL32
)
18930 fputs ("mul32", stdout
), first
= false;
18931 if (mask
& ELF_SPARC_HWCAP_DIV32
)
18932 printf ("%sdiv32", first
? "" : "|"), first
= false;
18933 if (mask
& ELF_SPARC_HWCAP_FSMULD
)
18934 printf ("%sfsmuld", first
? "" : "|"), first
= false;
18935 if (mask
& ELF_SPARC_HWCAP_V8PLUS
)
18936 printf ("%sv8plus", first
? "" : "|"), first
= false;
18937 if (mask
& ELF_SPARC_HWCAP_POPC
)
18938 printf ("%spopc", first
? "" : "|"), first
= false;
18939 if (mask
& ELF_SPARC_HWCAP_VIS
)
18940 printf ("%svis", first
? "" : "|"), first
= false;
18941 if (mask
& ELF_SPARC_HWCAP_VIS2
)
18942 printf ("%svis2", first
? "" : "|"), first
= false;
18943 if (mask
& ELF_SPARC_HWCAP_ASI_BLK_INIT
)
18944 printf ("%sASIBlkInit", first
? "" : "|"), first
= false;
18945 if (mask
& ELF_SPARC_HWCAP_FMAF
)
18946 printf ("%sfmaf", first
? "" : "|"), first
= false;
18947 if (mask
& ELF_SPARC_HWCAP_VIS3
)
18948 printf ("%svis3", first
? "" : "|"), first
= false;
18949 if (mask
& ELF_SPARC_HWCAP_HPC
)
18950 printf ("%shpc", first
? "" : "|"), first
= false;
18951 if (mask
& ELF_SPARC_HWCAP_RANDOM
)
18952 printf ("%srandom", first
? "" : "|"), first
= false;
18953 if (mask
& ELF_SPARC_HWCAP_TRANS
)
18954 printf ("%strans", first
? "" : "|"), first
= false;
18955 if (mask
& ELF_SPARC_HWCAP_FJFMAU
)
18956 printf ("%sfjfmau", first
? "" : "|"), first
= false;
18957 if (mask
& ELF_SPARC_HWCAP_IMA
)
18958 printf ("%sima", first
? "" : "|"), first
= false;
18959 if (mask
& ELF_SPARC_HWCAP_ASI_CACHE_SPARING
)
18960 printf ("%scspare", first
? "" : "|"), first
= false;
18963 fputc ('0', stdout
);
18964 fputc ('\n', stdout
);
18968 display_sparc_hwcaps2 (unsigned int mask
)
18974 if (mask
& ELF_SPARC_HWCAP2_FJATHPLUS
)
18975 fputs ("fjathplus", stdout
), first
= false;
18976 if (mask
& ELF_SPARC_HWCAP2_VIS3B
)
18977 printf ("%svis3b", first
? "" : "|"), first
= false;
18978 if (mask
& ELF_SPARC_HWCAP2_ADP
)
18979 printf ("%sadp", first
? "" : "|"), first
= false;
18980 if (mask
& ELF_SPARC_HWCAP2_SPARC5
)
18981 printf ("%ssparc5", first
? "" : "|"), first
= false;
18982 if (mask
& ELF_SPARC_HWCAP2_MWAIT
)
18983 printf ("%smwait", first
? "" : "|"), first
= false;
18984 if (mask
& ELF_SPARC_HWCAP2_XMPMUL
)
18985 printf ("%sxmpmul", first
? "" : "|"), first
= false;
18986 if (mask
& ELF_SPARC_HWCAP2_XMONT
)
18987 printf ("%sxmont2", first
? "" : "|"), first
= false;
18988 if (mask
& ELF_SPARC_HWCAP2_NSEC
)
18989 printf ("%snsec", first
? "" : "|"), first
= false;
18990 if (mask
& ELF_SPARC_HWCAP2_FJATHHPC
)
18991 printf ("%sfjathhpc", first
? "" : "|"), first
= false;
18992 if (mask
& ELF_SPARC_HWCAP2_FJDES
)
18993 printf ("%sfjdes", first
? "" : "|"), first
= false;
18994 if (mask
& ELF_SPARC_HWCAP2_FJAES
)
18995 printf ("%sfjaes", first
? "" : "|"), first
= false;
18998 fputc ('0', stdout
);
18999 fputc ('\n', stdout
);
19002 static unsigned char *
19003 display_sparc_gnu_attribute (unsigned char * p
,
19005 const unsigned char * const end
)
19009 if (tag
== Tag_GNU_Sparc_HWCAPS
)
19011 READ_ULEB (val
, p
, end
);
19012 printf (" Tag_GNU_Sparc_HWCAPS: ");
19013 display_sparc_hwcaps (val
);
19016 if (tag
== Tag_GNU_Sparc_HWCAPS2
)
19018 READ_ULEB (val
, p
, end
);
19019 printf (" Tag_GNU_Sparc_HWCAPS2: ");
19020 display_sparc_hwcaps2 (val
);
19024 return display_tag_value (tag
, p
, end
);
19028 print_mips_fp_abi_value (unsigned int val
)
19032 case Val_GNU_MIPS_ABI_FP_ANY
:
19033 printf (_("Hard or soft float\n"));
19035 case Val_GNU_MIPS_ABI_FP_DOUBLE
:
19036 printf (_("Hard float (double precision)\n"));
19038 case Val_GNU_MIPS_ABI_FP_SINGLE
:
19039 printf (_("Hard float (single precision)\n"));
19041 case Val_GNU_MIPS_ABI_FP_SOFT
:
19042 printf (_("Soft float\n"));
19044 case Val_GNU_MIPS_ABI_FP_OLD_64
:
19045 printf (_("Hard float (MIPS32r2 64-bit FPU 12 callee-saved)\n"));
19047 case Val_GNU_MIPS_ABI_FP_XX
:
19048 printf (_("Hard float (32-bit CPU, Any FPU)\n"));
19050 case Val_GNU_MIPS_ABI_FP_64
:
19051 printf (_("Hard float (32-bit CPU, 64-bit FPU)\n"));
19053 case Val_GNU_MIPS_ABI_FP_64A
:
19054 printf (_("Hard float compat (32-bit CPU, 64-bit FPU)\n"));
19056 case Val_GNU_MIPS_ABI_FP_NAN2008
:
19057 printf (_("NaN 2008 compatibility\n"));
19060 printf ("??? (%d)\n", val
);
19065 static unsigned char *
19066 display_mips_gnu_attribute (unsigned char * p
,
19068 const unsigned char * const end
)
19070 if (tag
== Tag_GNU_MIPS_ABI_FP
)
19074 printf (" Tag_GNU_MIPS_ABI_FP: ");
19075 READ_ULEB (val
, p
, end
);
19076 print_mips_fp_abi_value (val
);
19080 if (tag
== Tag_GNU_MIPS_ABI_MSA
)
19084 printf (" Tag_GNU_MIPS_ABI_MSA: ");
19085 READ_ULEB (val
, p
, end
);
19089 case Val_GNU_MIPS_ABI_MSA_ANY
:
19090 printf (_("Any MSA or not\n"));
19092 case Val_GNU_MIPS_ABI_MSA_128
:
19093 printf (_("128-bit MSA\n"));
19096 printf ("??? (%d)\n", val
);
19102 return display_tag_value (tag
& 1, p
, end
);
19105 static unsigned char *
19106 display_tic6x_attribute (unsigned char * p
,
19107 const unsigned char * const end
)
19112 READ_ULEB (tag
, p
, end
);
19117 printf (" Tag_ISA: ");
19118 READ_ULEB (val
, p
, end
);
19122 case C6XABI_Tag_ISA_none
:
19123 printf (_("None\n"));
19125 case C6XABI_Tag_ISA_C62X
:
19128 case C6XABI_Tag_ISA_C67X
:
19131 case C6XABI_Tag_ISA_C67XP
:
19132 printf ("C67x+\n");
19134 case C6XABI_Tag_ISA_C64X
:
19137 case C6XABI_Tag_ISA_C64XP
:
19138 printf ("C64x+\n");
19140 case C6XABI_Tag_ISA_C674X
:
19141 printf ("C674x\n");
19144 printf ("??? (%d)\n", val
);
19149 case Tag_ABI_wchar_t
:
19150 printf (" Tag_ABI_wchar_t: ");
19151 READ_ULEB (val
, p
, end
);
19155 printf (_("Not used\n"));
19158 printf (_("2 bytes\n"));
19161 printf (_("4 bytes\n"));
19164 printf ("??? (%d)\n", val
);
19169 case Tag_ABI_stack_align_needed
:
19170 printf (" Tag_ABI_stack_align_needed: ");
19171 READ_ULEB (val
, p
, end
);
19175 printf (_("8-byte\n"));
19178 printf (_("16-byte\n"));
19181 printf ("??? (%d)\n", val
);
19186 case Tag_ABI_stack_align_preserved
:
19187 READ_ULEB (val
, p
, end
);
19188 printf (" Tag_ABI_stack_align_preserved: ");
19192 printf (_("8-byte\n"));
19195 printf (_("16-byte\n"));
19198 printf ("??? (%d)\n", val
);
19204 READ_ULEB (val
, p
, end
);
19205 printf (" Tag_ABI_DSBT: ");
19209 printf (_("DSBT addressing not used\n"));
19212 printf (_("DSBT addressing used\n"));
19215 printf ("??? (%d)\n", val
);
19221 READ_ULEB (val
, p
, end
);
19222 printf (" Tag_ABI_PID: ");
19226 printf (_("Data addressing position-dependent\n"));
19229 printf (_("Data addressing position-independent, GOT near DP\n"));
19232 printf (_("Data addressing position-independent, GOT far from DP\n"));
19235 printf ("??? (%d)\n", val
);
19241 READ_ULEB (val
, p
, end
);
19242 printf (" Tag_ABI_PIC: ");
19246 printf (_("Code addressing position-dependent\n"));
19249 printf (_("Code addressing position-independent\n"));
19252 printf ("??? (%d)\n", val
);
19257 case Tag_ABI_array_object_alignment
:
19258 READ_ULEB (val
, p
, end
);
19259 printf (" Tag_ABI_array_object_alignment: ");
19263 printf (_("8-byte\n"));
19266 printf (_("4-byte\n"));
19269 printf (_("16-byte\n"));
19272 printf ("??? (%d)\n", val
);
19277 case Tag_ABI_array_object_align_expected
:
19278 READ_ULEB (val
, p
, end
);
19279 printf (" Tag_ABI_array_object_align_expected: ");
19283 printf (_("8-byte\n"));
19286 printf (_("4-byte\n"));
19289 printf (_("16-byte\n"));
19292 printf ("??? (%d)\n", val
);
19297 case Tag_ABI_compatibility
:
19299 READ_ULEB (val
, p
, end
);
19300 printf (" Tag_ABI_compatibility: ");
19301 printf (_("flag = %d, vendor = "), val
);
19304 size_t maxlen
= (end
- p
) - 1;
19306 print_symbol_name ((int) maxlen
, (const char *) p
);
19307 p
+= strnlen ((char *) p
, maxlen
) + 1;
19311 printf (_("<corrupt>"));
19312 p
= (unsigned char *) end
;
19318 case Tag_ABI_conformance
:
19320 printf (" Tag_ABI_conformance: \"");
19323 size_t maxlen
= (end
- p
) - 1;
19325 print_symbol_name ((int) maxlen
, (const char *) p
);
19326 p
+= strnlen ((char *) p
, maxlen
) + 1;
19330 printf (_("<corrupt>"));
19331 p
= (unsigned char *) end
;
19338 return display_tag_value (tag
, p
, end
);
19342 display_raw_attribute (unsigned char * p
, unsigned char const * const end
)
19345 size_t bytes
= end
- p
;
19352 int lbytes
= (bytes
> 16 ? 16 : bytes
);
19354 printf (" 0x%8.8" PRIx64
" ", addr
);
19356 for (j
= 0; j
< 16; j
++)
19359 printf ("%2.2x", p
[j
]);
19367 for (j
= 0; j
< lbytes
; j
++)
19370 if (k
>= ' ' && k
< 0x7f)
19386 static unsigned char *
19387 display_msp430_attribute (unsigned char * p
,
19388 const unsigned char * const end
)
19393 READ_ULEB (tag
, p
, end
);
19397 case OFBA_MSPABI_Tag_ISA
:
19398 printf (" Tag_ISA: ");
19399 READ_ULEB (val
, p
, end
);
19402 case 0: printf (_("None\n")); break;
19403 case 1: printf (_("MSP430\n")); break;
19404 case 2: printf (_("MSP430X\n")); break;
19405 default: printf ("??? (%" PRId64
")\n", val
); break;
19409 case OFBA_MSPABI_Tag_Code_Model
:
19410 printf (" Tag_Code_Model: ");
19411 READ_ULEB (val
, p
, end
);
19414 case 0: printf (_("None\n")); break;
19415 case 1: printf (_("Small\n")); break;
19416 case 2: printf (_("Large\n")); break;
19417 default: printf ("??? (%" PRId64
")\n", val
); break;
19421 case OFBA_MSPABI_Tag_Data_Model
:
19422 printf (" Tag_Data_Model: ");
19423 READ_ULEB (val
, p
, end
);
19426 case 0: printf (_("None\n")); break;
19427 case 1: printf (_("Small\n")); break;
19428 case 2: printf (_("Large\n")); break;
19429 case 3: printf (_("Restricted Large\n")); break;
19430 default: printf ("??? (%" PRId64
")\n", val
); break;
19435 printf (_(" <unknown tag %" PRId64
">: "), tag
);
19442 size_t maxlen
= (end
- p
) - 1;
19444 print_symbol_name ((int) maxlen
, (const char *) p
);
19445 p
+= strnlen ((char *) p
, maxlen
) + 1;
19449 printf (_("<corrupt>"));
19450 p
= (unsigned char *) end
;
19456 READ_ULEB (val
, p
, end
);
19457 printf ("%" PRId64
" (0x%" PRIx64
")\n", val
, val
);
19466 static unsigned char *
19467 display_msp430_gnu_attribute (unsigned char * p
,
19469 const unsigned char * const end
)
19471 if (tag
== Tag_GNU_MSP430_Data_Region
)
19475 printf (" Tag_GNU_MSP430_Data_Region: ");
19476 READ_ULEB (val
, p
, end
);
19480 case Val_GNU_MSP430_Data_Region_Any
:
19481 printf (_("Any Region\n"));
19483 case Val_GNU_MSP430_Data_Region_Lower
:
19484 printf (_("Lower Region Only\n"));
19487 printf ("??? (%" PRIu64
")\n", val
);
19491 return display_tag_value (tag
& 1, p
, end
);
19494 struct riscv_attr_tag_t
{
19499 static struct riscv_attr_tag_t riscv_attr_tag
[] =
19501 #define T(tag) {"Tag_RISCV_" #tag, Tag_RISCV_##tag}
19504 T(priv_spec_minor
),
19505 T(priv_spec_revision
),
19506 T(unaligned_access
),
19511 static unsigned char *
19512 display_riscv_attribute (unsigned char *p
,
19513 const unsigned char * const end
)
19517 struct riscv_attr_tag_t
*attr
= NULL
;
19520 READ_ULEB (tag
, p
, end
);
19522 /* Find the name of attribute. */
19523 for (i
= 0; i
< ARRAY_SIZE (riscv_attr_tag
); i
++)
19525 if (riscv_attr_tag
[i
].tag
== tag
)
19527 attr
= &riscv_attr_tag
[i
];
19533 printf (" %s: ", attr
->name
);
19535 return display_tag_value (tag
, p
, end
);
19539 case Tag_RISCV_priv_spec
:
19540 case Tag_RISCV_priv_spec_minor
:
19541 case Tag_RISCV_priv_spec_revision
:
19542 READ_ULEB (val
, p
, end
);
19543 printf ("%" PRIu64
"\n", val
);
19545 case Tag_RISCV_unaligned_access
:
19546 READ_ULEB (val
, p
, end
);
19550 printf (_("No unaligned access\n"));
19553 printf (_("Unaligned access\n"));
19557 case Tag_RISCV_stack_align
:
19558 READ_ULEB (val
, p
, end
);
19559 printf (_("%" PRIu64
"-bytes\n"), val
);
19561 case Tag_RISCV_arch
:
19562 p
= display_tag_value (-1, p
, end
);
19565 return display_tag_value (tag
, p
, end
);
19571 static unsigned char *
19572 display_csky_attribute (unsigned char * p
,
19573 const unsigned char * const end
)
19577 READ_ULEB (tag
, p
, end
);
19579 if (tag
>= Tag_CSKY_MAX
)
19581 return display_tag_value (-1, p
, end
);
19586 case Tag_CSKY_ARCH_NAME
:
19587 printf (" Tag_CSKY_ARCH_NAME:\t\t");
19588 return display_tag_value (-1, p
, end
);
19589 case Tag_CSKY_CPU_NAME
:
19590 printf (" Tag_CSKY_CPU_NAME:\t\t");
19591 return display_tag_value (-1, p
, end
);
19593 case Tag_CSKY_ISA_FLAGS
:
19594 printf (" Tag_CSKY_ISA_FLAGS:\t\t");
19595 return display_tag_value (0, p
, end
);
19596 case Tag_CSKY_ISA_EXT_FLAGS
:
19597 printf (" Tag_CSKY_ISA_EXT_FLAGS:\t");
19598 return display_tag_value (0, p
, end
);
19600 case Tag_CSKY_DSP_VERSION
:
19601 printf (" Tag_CSKY_DSP_VERSION:\t\t");
19602 READ_ULEB (val
, p
, end
);
19603 if (val
== VAL_CSKY_DSP_VERSION_EXTENSION
)
19604 printf ("DSP Extension\n");
19605 else if (val
== VAL_CSKY_DSP_VERSION_2
)
19606 printf ("DSP 2.0\n");
19609 case Tag_CSKY_VDSP_VERSION
:
19610 printf (" Tag_CSKY_VDSP_VERSION:\t");
19611 READ_ULEB (val
, p
, end
);
19612 printf ("VDSP Version %" PRId64
"\n", val
);
19615 case Tag_CSKY_FPU_VERSION
:
19616 printf (" Tag_CSKY_FPU_VERSION:\t\t");
19617 READ_ULEB (val
, p
, end
);
19618 if (val
== VAL_CSKY_FPU_VERSION_1
)
19619 printf ("ABIV1 FPU Version 1\n");
19620 else if (val
== VAL_CSKY_FPU_VERSION_2
)
19621 printf ("FPU Version 2\n");
19624 case Tag_CSKY_FPU_ABI
:
19625 printf (" Tag_CSKY_FPU_ABI:\t\t");
19626 READ_ULEB (val
, p
, end
);
19627 if (val
== VAL_CSKY_FPU_ABI_HARD
)
19629 else if (val
== VAL_CSKY_FPU_ABI_SOFTFP
)
19630 printf ("SoftFP\n");
19631 else if (val
== VAL_CSKY_FPU_ABI_SOFT
)
19634 case Tag_CSKY_FPU_ROUNDING
:
19635 READ_ULEB (val
, p
, end
);
19638 printf (" Tag_CSKY_FPU_ROUNDING:\t");
19639 printf ("Needed\n");
19642 case Tag_CSKY_FPU_DENORMAL
:
19643 READ_ULEB (val
, p
, end
);
19646 printf (" Tag_CSKY_FPU_DENORMAL:\t");
19647 printf ("Needed\n");
19650 case Tag_CSKY_FPU_Exception
:
19651 READ_ULEB (val
, p
, end
);
19654 printf (" Tag_CSKY_FPU_Exception:\t");
19655 printf ("Needed\n");
19658 case Tag_CSKY_FPU_NUMBER_MODULE
:
19659 printf (" Tag_CSKY_FPU_NUMBER_MODULE:\t");
19660 return display_tag_value (-1, p
, end
);
19661 case Tag_CSKY_FPU_HARDFP
:
19662 printf (" Tag_CSKY_FPU_HARDFP:\t\t");
19663 READ_ULEB (val
, p
, end
);
19664 if (val
& VAL_CSKY_FPU_HARDFP_HALF
)
19666 if (val
& VAL_CSKY_FPU_HARDFP_SINGLE
)
19667 printf (" Single");
19668 if (val
& VAL_CSKY_FPU_HARDFP_DOUBLE
)
19669 printf (" Double");
19673 return display_tag_value (tag
, p
, end
);
19679 process_attributes (Filedata
* filedata
,
19680 const char * public_name
,
19681 unsigned int proc_type
,
19682 unsigned char * (* display_pub_attribute
) (unsigned char *, const unsigned char * const),
19683 unsigned char * (* display_proc_gnu_attribute
) (unsigned char *, unsigned int, const unsigned char * const))
19685 /* Find the section header so that we get the size. */
19686 Elf_Internal_Shdr
* sect
= find_section_by_type (filedata
, proc_type
);
19688 sect
= find_section_by_type (filedata
, SHT_GNU_ATTRIBUTES
);
19691 /* No section, exit without error. */
19694 unsigned char * contents
= (unsigned char *)
19695 get_data (NULL
, filedata
, sect
->sh_offset
, 1, sect
->sh_size
, _("attributes"));
19696 if (contents
== NULL
)
19700 unsigned char * p
= contents
;
19701 /* The first character is the version of the attributes.
19702 Currently only version 1, (aka 'A') is recognised here. */
19705 printf (_("Unknown attributes version '%c'(%d) - expecting 'A'\n"), *p
, *p
);
19710 uint64_t section_len
= sect
->sh_size
- 1;
19713 while (section_len
> 0)
19716 unsigned int namelen
;
19717 bool public_section
;
19720 if (section_len
<= 4)
19722 error (_("Tag section ends prematurely\n"));
19726 attr_len
= byte_get (p
, 4);
19729 if (attr_len
> section_len
)
19731 error (_("Bad attribute length (%u > %u)\n"),
19732 (unsigned) attr_len
, (unsigned) section_len
);
19733 attr_len
= section_len
;
19736 /* PR 17531: file: 001-101425-0.004 */
19737 else if (attr_len
< 5)
19739 error (_("Attribute length of %u is too small\n"), (unsigned) attr_len
);
19744 section_len
-= attr_len
;
19747 namelen
= strnlen ((char *) p
, attr_len
) + 1;
19748 if (namelen
== 0 || namelen
>= attr_len
)
19750 error (_("Corrupt attribute section name\n"));
19755 printf (_("Attribute Section: "));
19756 print_symbol_name (INT_MAX
, (const char *) p
);
19759 if (public_name
&& streq ((char *) p
, public_name
))
19760 public_section
= true;
19762 public_section
= false;
19764 if (streq ((char *) p
, "gnu"))
19765 gnu_section
= true;
19767 gnu_section
= false;
19770 attr_len
-= namelen
;
19772 while (attr_len
> 0 && p
< contents
+ sect
->sh_size
)
19777 unsigned char * end
;
19779 /* PR binutils/17531: Safe handling of corrupt files. */
19782 error (_("Unused bytes at end of section\n"));
19789 size
= byte_get (p
, 4);
19790 if (size
> attr_len
)
19792 error (_("Bad subsection length (%u > %u)\n"),
19793 (unsigned) size
, (unsigned) attr_len
);
19797 /* PR binutils/17531: Safe handling of corrupt files. */
19800 error (_("Bad subsection length (%u < 6)\n"),
19808 end
= p
+ size
- 1;
19809 assert (end
<= contents
+ sect
->sh_size
);
19815 printf (_("File Attributes\n"));
19818 printf (_("Section Attributes:"));
19821 printf (_("Symbol Attributes:"));
19822 /* Fall through. */
19826 READ_ULEB (val
, p
, end
);
19829 printf (" %d", val
);
19834 printf (_("Unknown tag: %d\n"), tag
);
19835 public_section
= false;
19839 if (public_section
&& display_pub_attribute
!= NULL
)
19842 p
= display_pub_attribute (p
, end
);
19845 else if (gnu_section
&& display_proc_gnu_attribute
!= NULL
)
19848 p
= display_gnu_attribute (p
,
19849 display_proc_gnu_attribute
,
19855 printf (_(" Unknown attribute:\n"));
19856 display_raw_attribute (p
, end
);
19870 /* DATA points to the contents of a MIPS GOT that starts at VMA PLTGOT.
19871 Print the Address, Access and Initial fields of an entry at VMA ADDR
19872 and return the VMA of the next entry, or -1 if there was a problem.
19873 Does not read from DATA_END or beyond. */
19876 print_mips_got_entry (unsigned char * data
, uint64_t pltgot
, uint64_t addr
,
19877 unsigned char * data_end
)
19880 print_vma (addr
, LONG_HEX
);
19882 if (addr
< pltgot
+ 0xfff0)
19883 printf ("%6d(gp)", (int) (addr
- pltgot
- 0x7ff0));
19885 printf ("%10s", "");
19888 printf ("%*s", is_32bit_elf
? 8 : 16, _("<unknown>"));
19892 unsigned char * from
= data
+ addr
- pltgot
;
19894 if (from
+ (is_32bit_elf
? 4 : 8) > data_end
)
19896 warn (_("MIPS GOT entry extends beyond the end of available data\n"));
19897 printf ("%*s", is_32bit_elf
? 8 : 16, _("<corrupt>"));
19898 return (uint64_t) -1;
19902 entry
= byte_get (data
+ addr
- pltgot
, is_32bit_elf
? 4 : 8);
19903 print_vma (entry
, LONG_HEX
);
19906 return addr
+ (is_32bit_elf
? 4 : 8);
19909 /* DATA points to the contents of a MIPS PLT GOT that starts at VMA
19910 PLTGOT. Print the Address and Initial fields of an entry at VMA
19911 ADDR and return the VMA of the next entry. */
19914 print_mips_pltgot_entry (unsigned char * data
, uint64_t pltgot
, uint64_t addr
)
19917 print_vma (addr
, LONG_HEX
);
19920 printf ("%*s", is_32bit_elf
? 8 : 16, _("<unknown>"));
19925 entry
= byte_get (data
+ addr
- pltgot
, is_32bit_elf
? 4 : 8);
19926 print_vma (entry
, LONG_HEX
);
19928 return addr
+ (is_32bit_elf
? 4 : 8);
19932 print_mips_ases (unsigned int mask
)
19934 if (mask
& AFL_ASE_DSP
)
19935 fputs ("\n\tDSP ASE", stdout
);
19936 if (mask
& AFL_ASE_DSPR2
)
19937 fputs ("\n\tDSP R2 ASE", stdout
);
19938 if (mask
& AFL_ASE_DSPR3
)
19939 fputs ("\n\tDSP R3 ASE", stdout
);
19940 if (mask
& AFL_ASE_EVA
)
19941 fputs ("\n\tEnhanced VA Scheme", stdout
);
19942 if (mask
& AFL_ASE_MCU
)
19943 fputs ("\n\tMCU (MicroController) ASE", stdout
);
19944 if (mask
& AFL_ASE_MDMX
)
19945 fputs ("\n\tMDMX ASE", stdout
);
19946 if (mask
& AFL_ASE_MIPS3D
)
19947 fputs ("\n\tMIPS-3D ASE", stdout
);
19948 if (mask
& AFL_ASE_MT
)
19949 fputs ("\n\tMT ASE", stdout
);
19950 if (mask
& AFL_ASE_SMARTMIPS
)
19951 fputs ("\n\tSmartMIPS ASE", stdout
);
19952 if (mask
& AFL_ASE_VIRT
)
19953 fputs ("\n\tVZ ASE", stdout
);
19954 if (mask
& AFL_ASE_MSA
)
19955 fputs ("\n\tMSA ASE", stdout
);
19956 if (mask
& AFL_ASE_MIPS16
)
19957 fputs ("\n\tMIPS16 ASE", stdout
);
19958 if (mask
& AFL_ASE_MICROMIPS
)
19959 fputs ("\n\tMICROMIPS ASE", stdout
);
19960 if (mask
& AFL_ASE_XPA
)
19961 fputs ("\n\tXPA ASE", stdout
);
19962 if (mask
& AFL_ASE_MIPS16E2
)
19963 fputs ("\n\tMIPS16e2 ASE", stdout
);
19964 if (mask
& AFL_ASE_CRC
)
19965 fputs ("\n\tCRC ASE", stdout
);
19966 if (mask
& AFL_ASE_GINV
)
19967 fputs ("\n\tGINV ASE", stdout
);
19968 if (mask
& AFL_ASE_LOONGSON_MMI
)
19969 fputs ("\n\tLoongson MMI ASE", stdout
);
19970 if (mask
& AFL_ASE_LOONGSON_CAM
)
19971 fputs ("\n\tLoongson CAM ASE", stdout
);
19972 if (mask
& AFL_ASE_LOONGSON_EXT
)
19973 fputs ("\n\tLoongson EXT ASE", stdout
);
19974 if (mask
& AFL_ASE_LOONGSON_EXT2
)
19975 fputs ("\n\tLoongson EXT2 ASE", stdout
);
19977 fprintf (stdout
, "\n\t%s", _("None"));
19978 else if ((mask
& ~AFL_ASE_MASK
) != 0)
19979 fprintf (stdout
, "\n\t%s (%x)", _("Unknown"), mask
& ~AFL_ASE_MASK
);
19983 print_mips_isa_ext (unsigned int isa_ext
)
19988 fputs (_("None"), stdout
);
19991 fputs ("RMI XLR", stdout
);
19993 case AFL_EXT_OCTEON3
:
19994 fputs ("Cavium Networks Octeon3", stdout
);
19996 case AFL_EXT_OCTEON2
:
19997 fputs ("Cavium Networks Octeon2", stdout
);
19999 case AFL_EXT_OCTEONP
:
20000 fputs ("Cavium Networks OcteonP", stdout
);
20002 case AFL_EXT_OCTEON
:
20003 fputs ("Cavium Networks Octeon", stdout
);
20006 fputs ("Toshiba R5900", stdout
);
20009 fputs ("MIPS R4650", stdout
);
20012 fputs ("LSI R4010", stdout
);
20015 fputs ("NEC VR4100", stdout
);
20018 fputs ("Toshiba R3900", stdout
);
20020 case AFL_EXT_10000
:
20021 fputs ("MIPS R10000", stdout
);
20024 fputs ("Broadcom SB-1", stdout
);
20027 fputs ("NEC VR4111/VR4181", stdout
);
20030 fputs ("NEC VR4120", stdout
);
20033 fputs ("NEC VR5400", stdout
);
20036 fputs ("NEC VR5500", stdout
);
20038 case AFL_EXT_LOONGSON_2E
:
20039 fputs ("ST Microelectronics Loongson 2E", stdout
);
20041 case AFL_EXT_LOONGSON_2F
:
20042 fputs ("ST Microelectronics Loongson 2F", stdout
);
20044 case AFL_EXT_INTERAPTIV_MR2
:
20045 fputs ("Imagination interAptiv MR2", stdout
);
20048 fprintf (stdout
, "%s (%d)", _("Unknown"), isa_ext
);
20053 get_mips_reg_size (int reg_size
)
20055 return (reg_size
== AFL_REG_NONE
) ? 0
20056 : (reg_size
== AFL_REG_32
) ? 32
20057 : (reg_size
== AFL_REG_64
) ? 64
20058 : (reg_size
== AFL_REG_128
) ? 128
20062 /* If DUMP_GOT is true, display only the GOT related contents.
20063 Otherwise, display all MIPS specific information. */
20066 process_mips_specific (Filedata
* filedata
, bool dump_got
)
20068 Elf_Internal_Dyn
* entry
;
20069 Elf_Internal_Shdr
*sect
= NULL
;
20070 size_t liblist_offset
= 0;
20071 size_t liblistno
= 0;
20072 size_t conflictsno
= 0;
20073 size_t options_offset
= 0;
20074 size_t conflicts_offset
= 0;
20075 size_t pltrelsz
= 0;
20077 uint64_t pltgot
= 0;
20078 uint64_t mips_pltgot
= 0;
20079 uint64_t jmprel
= 0;
20080 uint64_t local_gotno
= 0;
20081 uint64_t gotsym
= 0;
20082 uint64_t symtabno
= 0;
20087 if (! process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
20088 display_mips_gnu_attribute
))
20091 sect
= find_section (filedata
, ".MIPS.abiflags");
20095 Elf_External_ABIFlags_v0
*abiflags_ext
;
20096 Elf_Internal_ABIFlags_v0 abiflags_in
;
20098 if (sizeof (Elf_External_ABIFlags_v0
) != sect
->sh_size
)
20100 error (_("Corrupt MIPS ABI Flags section.\n"));
20105 abiflags_ext
= get_data (NULL
, filedata
, sect
->sh_offset
, 1,
20106 sect
->sh_size
, _("MIPS ABI Flags section"));
20109 abiflags_in
.version
= BYTE_GET (abiflags_ext
->version
);
20110 abiflags_in
.isa_level
= BYTE_GET (abiflags_ext
->isa_level
);
20111 abiflags_in
.isa_rev
= BYTE_GET (abiflags_ext
->isa_rev
);
20112 abiflags_in
.gpr_size
= BYTE_GET (abiflags_ext
->gpr_size
);
20113 abiflags_in
.cpr1_size
= BYTE_GET (abiflags_ext
->cpr1_size
);
20114 abiflags_in
.cpr2_size
= BYTE_GET (abiflags_ext
->cpr2_size
);
20115 abiflags_in
.fp_abi
= BYTE_GET (abiflags_ext
->fp_abi
);
20116 abiflags_in
.isa_ext
= BYTE_GET (abiflags_ext
->isa_ext
);
20117 abiflags_in
.ases
= BYTE_GET (abiflags_ext
->ases
);
20118 abiflags_in
.flags1
= BYTE_GET (abiflags_ext
->flags1
);
20119 abiflags_in
.flags2
= BYTE_GET (abiflags_ext
->flags2
);
20121 printf ("\nMIPS ABI Flags Version: %d\n", abiflags_in
.version
);
20122 printf ("\nISA: MIPS%d", abiflags_in
.isa_level
);
20123 if (abiflags_in
.isa_rev
> 1)
20124 printf ("r%d", abiflags_in
.isa_rev
);
20125 printf ("\nGPR size: %d",
20126 get_mips_reg_size (abiflags_in
.gpr_size
));
20127 printf ("\nCPR1 size: %d",
20128 get_mips_reg_size (abiflags_in
.cpr1_size
));
20129 printf ("\nCPR2 size: %d",
20130 get_mips_reg_size (abiflags_in
.cpr2_size
));
20131 fputs ("\nFP ABI: ", stdout
);
20132 print_mips_fp_abi_value (abiflags_in
.fp_abi
);
20133 fputs ("ISA Extension: ", stdout
);
20134 print_mips_isa_ext (abiflags_in
.isa_ext
);
20135 fputs ("\nASEs:", stdout
);
20136 print_mips_ases (abiflags_in
.ases
);
20137 printf ("\nFLAGS 1: %8.8lx", abiflags_in
.flags1
);
20138 printf ("\nFLAGS 2: %8.8lx", abiflags_in
.flags2
);
20139 fputc ('\n', stdout
);
20140 free (abiflags_ext
);
20146 /* We have a lot of special sections. Thanks SGI! */
20147 if (filedata
->dynamic_section
== NULL
)
20149 /* No dynamic information available. See if there is static GOT. */
20150 sect
= find_section (filedata
, ".got");
20153 unsigned char *data_end
;
20154 unsigned char *data
;
20158 pltgot
= sect
->sh_addr
;
20161 addr_size
= (is_32bit_elf
? 4 : 8);
20162 end
= pltgot
+ sect
->sh_size
;
20164 data
= (unsigned char *) get_data (NULL
, filedata
, sect
->sh_offset
,
20166 _("Global Offset Table data"));
20167 /* PR 12855: Null data is handled gracefully throughout. */
20168 data_end
= data
+ (end
- pltgot
);
20170 printf (_("\nStatic GOT:\n"));
20171 printf (_(" Canonical gp value: "));
20172 print_vma (ent
+ 0x7ff0, LONG_HEX
);
20175 /* In a dynamic binary GOT[0] is reserved for the dynamic
20176 loader to store the lazy resolver pointer, however in
20177 a static binary it may well have been omitted and GOT
20178 reduced to a table of addresses.
20179 PR 21344: Check for the entry being fully available
20180 before fetching it. */
20182 && data
+ ent
- pltgot
+ addr_size
<= data_end
20183 && byte_get (data
+ ent
- pltgot
, addr_size
) == 0)
20185 printf (_(" Reserved entries:\n"));
20186 printf (_(" %*s %10s %*s\n"),
20187 addr_size
* 2, _("Address"), _("Access"),
20188 addr_size
* 2, _("Value"));
20189 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
20191 if (ent
== (uint64_t) -1)
20192 goto sgot_print_fail
;
20194 /* Check for the MSB of GOT[1] being set, identifying a
20195 GNU object. This entry will be used by some runtime
20196 loaders, to store the module pointer. Otherwise this
20197 is an ordinary local entry.
20198 PR 21344: Check for the entry being fully available
20199 before fetching it. */
20201 && data
+ ent
- pltgot
+ addr_size
<= data_end
20202 && (byte_get (data
+ ent
- pltgot
, addr_size
)
20203 >> (addr_size
* 8 - 1)) != 0)
20205 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
20207 if (ent
== (uint64_t) -1)
20208 goto sgot_print_fail
;
20213 if (data
!= NULL
&& ent
< end
)
20215 printf (_(" Local entries:\n"));
20216 printf (" %*s %10s %*s\n",
20217 addr_size
* 2, _("Address"), _("Access"),
20218 addr_size
* 2, _("Value"));
20221 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
20223 if (ent
== (uint64_t) -1)
20224 goto sgot_print_fail
;
20235 for (entry
= filedata
->dynamic_section
;
20236 /* PR 17531 file: 012-50589-0.004. */
20237 (entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
20238 && entry
->d_tag
!= DT_NULL
);
20240 switch (entry
->d_tag
)
20242 case DT_MIPS_LIBLIST
:
20244 = offset_from_vma (filedata
, entry
->d_un
.d_val
,
20245 liblistno
* sizeof (Elf32_External_Lib
));
20247 case DT_MIPS_LIBLISTNO
:
20248 liblistno
= entry
->d_un
.d_val
;
20250 case DT_MIPS_OPTIONS
:
20251 options_offset
= offset_from_vma (filedata
, entry
->d_un
.d_val
, 0);
20253 case DT_MIPS_CONFLICT
:
20255 = offset_from_vma (filedata
, entry
->d_un
.d_val
,
20256 conflictsno
* sizeof (Elf32_External_Conflict
));
20258 case DT_MIPS_CONFLICTNO
:
20259 conflictsno
= entry
->d_un
.d_val
;
20262 pltgot
= entry
->d_un
.d_ptr
;
20264 case DT_MIPS_LOCAL_GOTNO
:
20265 local_gotno
= entry
->d_un
.d_val
;
20267 case DT_MIPS_GOTSYM
:
20268 gotsym
= entry
->d_un
.d_val
;
20270 case DT_MIPS_SYMTABNO
:
20271 symtabno
= entry
->d_un
.d_val
;
20273 case DT_MIPS_PLTGOT
:
20274 mips_pltgot
= entry
->d_un
.d_ptr
;
20277 pltrel
= entry
->d_un
.d_val
;
20280 pltrelsz
= entry
->d_un
.d_val
;
20283 jmprel
= entry
->d_un
.d_ptr
;
20289 if (!dump_got
&& liblist_offset
!= 0 && liblistno
!= 0 && do_dynamic
)
20291 Elf32_External_Lib
* elib
;
20294 elib
= (Elf32_External_Lib
*) get_data (NULL
, filedata
, liblist_offset
,
20295 sizeof (Elf32_External_Lib
),
20297 _("liblist section data"));
20300 printf (ngettext ("\nSection '.liblist' contains %zu entry:\n",
20301 "\nSection '.liblist' contains %zu entries:\n",
20304 fputs (_(" Library Time Stamp Checksum Version Flags\n"),
20307 for (cnt
= 0; cnt
< liblistno
; ++cnt
)
20314 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
20315 atime
= BYTE_GET (elib
[cnt
].l_time_stamp
);
20316 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
20317 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
20318 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
20320 tmp
= gmtime (&atime
);
20321 snprintf (timebuf
, sizeof (timebuf
),
20322 "%04u-%02u-%02uT%02u:%02u:%02u",
20323 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
20324 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
20326 printf ("%3zu: ", cnt
);
20327 if (valid_dynamic_name (filedata
, liblist
.l_name
))
20328 print_symbol_name (20, get_dynamic_name (filedata
, liblist
.l_name
));
20330 printf (_("<corrupt: %9ld>"), liblist
.l_name
);
20331 printf (" %s %#10lx %-7ld", timebuf
, liblist
.l_checksum
,
20332 liblist
.l_version
);
20334 if (liblist
.l_flags
== 0)
20338 static const struct
20345 { " EXACT_MATCH", LL_EXACT_MATCH
},
20346 { " IGNORE_INT_VER", LL_IGNORE_INT_VER
},
20347 { " REQUIRE_MINOR", LL_REQUIRE_MINOR
},
20348 { " EXPORTS", LL_EXPORTS
},
20349 { " DELAY_LOAD", LL_DELAY_LOAD
},
20350 { " DELTA", LL_DELTA
}
20352 int flags
= liblist
.l_flags
;
20355 for (fcnt
= 0; fcnt
< ARRAY_SIZE (l_flags_vals
); ++fcnt
)
20356 if ((flags
& l_flags_vals
[fcnt
].bit
) != 0)
20358 fputs (l_flags_vals
[fcnt
].name
, stdout
);
20359 flags
^= l_flags_vals
[fcnt
].bit
;
20362 printf (" %#x", (unsigned int) flags
);
20374 if (!dump_got
&& options_offset
!= 0)
20376 Elf_External_Options
* eopt
;
20380 /* Find the section header so that we get the size. */
20381 sect
= find_section_by_type (filedata
, SHT_MIPS_OPTIONS
);
20382 /* PR 17533 file: 012-277276-0.004. */
20385 error (_("No MIPS_OPTIONS header found\n"));
20389 if (sect
->sh_size
< sizeof (* eopt
))
20391 error (_("The MIPS options section is too small.\n"));
20395 eopt
= (Elf_External_Options
*) get_data (NULL
, filedata
, options_offset
, 1,
20396 sect
->sh_size
, _("options"));
20399 Elf_Internal_Options option
;
20402 while (offset
<= sect
->sh_size
- sizeof (* eopt
))
20404 Elf_External_Options
* eoption
;
20405 unsigned int optsize
;
20407 eoption
= (Elf_External_Options
*) ((char *) eopt
+ offset
);
20409 optsize
= BYTE_GET (eoption
->size
);
20411 /* PR 17531: file: ffa0fa3b. */
20412 if (optsize
< sizeof (* eopt
)
20413 || optsize
> sect
->sh_size
- offset
)
20415 error (_("Invalid size (%u) for MIPS option\n"),
20424 printf (ngettext ("\nSection '%s' contains %d entry:\n",
20425 "\nSection '%s' contains %d entries:\n",
20427 printable_section_name (filedata
, sect
), cnt
);
20433 Elf_External_Options
* eoption
;
20435 eoption
= (Elf_External_Options
*) ((char *) eopt
+ offset
);
20437 option
.kind
= BYTE_GET (eoption
->kind
);
20438 option
.size
= BYTE_GET (eoption
->size
);
20439 option
.section
= BYTE_GET (eoption
->section
);
20440 option
.info
= BYTE_GET (eoption
->info
);
20442 switch (option
.kind
)
20445 /* This shouldn't happen. */
20446 printf (" NULL %" PRId16
" %" PRIx32
,
20447 option
.section
, option
.info
);
20451 printf (" REGINFO ");
20452 if (filedata
->file_header
.e_machine
== EM_MIPS
)
20454 Elf32_External_RegInfo
* ereg
;
20455 Elf32_RegInfo reginfo
;
20458 if (option
.size
< (sizeof (Elf_External_Options
)
20459 + sizeof (Elf32_External_RegInfo
)))
20461 printf (_("<corrupt>\n"));
20462 error (_("Truncated MIPS REGINFO option\n"));
20467 ereg
= (Elf32_External_RegInfo
*) (eoption
+ 1);
20469 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
20470 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
20471 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
20472 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
20473 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
20474 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
20476 printf ("GPR %08" PRIx32
" GP 0x%" PRIx32
"\n",
20477 reginfo
.ri_gprmask
, reginfo
.ri_gp_value
);
20479 " CPR0 %08" PRIx32
" CPR1 %08" PRIx32
20480 " CPR2 %08" PRIx32
" CPR3 %08" PRIx32
"\n",
20481 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
20482 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
20487 Elf64_External_RegInfo
* ereg
;
20488 Elf64_Internal_RegInfo reginfo
;
20490 if (option
.size
< (sizeof (Elf_External_Options
)
20491 + sizeof (Elf64_External_RegInfo
)))
20493 printf (_("<corrupt>\n"));
20494 error (_("Truncated MIPS REGINFO option\n"));
20499 ereg
= (Elf64_External_RegInfo
*) (eoption
+ 1);
20500 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
20501 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
20502 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
20503 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
20504 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
20505 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
20507 printf ("GPR %08" PRIx32
" GP 0x%" PRIx64
"\n",
20508 reginfo
.ri_gprmask
, reginfo
.ri_gp_value
);
20510 " CPR0 %08" PRIx32
" CPR1 %08" PRIx32
20511 " CPR2 %08" PRIx32
" CPR3 %08" PRIx32
"\n",
20512 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
20513 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
20515 offset
+= option
.size
;
20518 case ODK_EXCEPTIONS
:
20519 fputs (" EXCEPTIONS fpe_min(", stdout
);
20520 process_mips_fpe_exception (option
.info
& OEX_FPU_MIN
);
20521 fputs (") fpe_max(", stdout
);
20522 process_mips_fpe_exception ((option
.info
& OEX_FPU_MAX
) >> 8);
20523 fputs (")", stdout
);
20525 if (option
.info
& OEX_PAGE0
)
20526 fputs (" PAGE0", stdout
);
20527 if (option
.info
& OEX_SMM
)
20528 fputs (" SMM", stdout
);
20529 if (option
.info
& OEX_FPDBUG
)
20530 fputs (" FPDBUG", stdout
);
20531 if (option
.info
& OEX_DISMISS
)
20532 fputs (" DISMISS", stdout
);
20536 fputs (" PAD ", stdout
);
20537 if (option
.info
& OPAD_PREFIX
)
20538 fputs (" PREFIX", stdout
);
20539 if (option
.info
& OPAD_POSTFIX
)
20540 fputs (" POSTFIX", stdout
);
20541 if (option
.info
& OPAD_SYMBOL
)
20542 fputs (" SYMBOL", stdout
);
20546 fputs (" HWPATCH ", stdout
);
20547 if (option
.info
& OHW_R4KEOP
)
20548 fputs (" R4KEOP", stdout
);
20549 if (option
.info
& OHW_R8KPFETCH
)
20550 fputs (" R8KPFETCH", stdout
);
20551 if (option
.info
& OHW_R5KEOP
)
20552 fputs (" R5KEOP", stdout
);
20553 if (option
.info
& OHW_R5KCVTL
)
20554 fputs (" R5KCVTL", stdout
);
20558 fputs (" FILL ", stdout
);
20559 /* XXX Print content of info word? */
20563 fputs (" TAGS ", stdout
);
20564 /* XXX Print content of info word? */
20568 fputs (" HWAND ", stdout
);
20569 if (option
.info
& OHWA0_R4KEOP_CHECKED
)
20570 fputs (" R4KEOP_CHECKED", stdout
);
20571 if (option
.info
& OHWA0_R4KEOP_CLEAN
)
20572 fputs (" R4KEOP_CLEAN", stdout
);
20576 fputs (" HWOR ", stdout
);
20577 if (option
.info
& OHWA0_R4KEOP_CHECKED
)
20578 fputs (" R4KEOP_CHECKED", stdout
);
20579 if (option
.info
& OHWA0_R4KEOP_CLEAN
)
20580 fputs (" R4KEOP_CLEAN", stdout
);
20584 printf (" GP_GROUP %#06x self-contained %#06x",
20585 option
.info
& OGP_GROUP
,
20586 (option
.info
& OGP_SELF
) >> 16);
20590 printf (" IDENT %#06x self-contained %#06x",
20591 option
.info
& OGP_GROUP
,
20592 (option
.info
& OGP_SELF
) >> 16);
20596 /* This shouldn't happen. */
20597 printf (" %3d ??? %" PRId16
" %" PRIx32
,
20598 option
.kind
, option
.section
, option
.info
);
20602 len
= sizeof (* eopt
);
20603 while (len
< option
.size
)
20605 unsigned char datum
= *((unsigned char *) eoption
+ len
);
20607 if (ISPRINT (datum
))
20608 printf ("%c", datum
);
20610 printf ("\\%03o", datum
);
20613 fputs ("\n", stdout
);
20615 offset
+= option
.size
;
20623 if (!dump_got
&& conflicts_offset
!= 0 && conflictsno
!= 0)
20625 Elf32_Conflict
* iconf
;
20628 if (filedata
->dynamic_symbols
== NULL
)
20630 error (_("conflict list found without a dynamic symbol table\n"));
20634 /* PR 21345 - print a slightly more helpful error message
20635 if we are sure that the cmalloc will fail. */
20636 if (conflictsno
> filedata
->file_size
/ sizeof (* iconf
))
20638 error (_("Overlarge number of conflicts detected: %zx\n"),
20643 iconf
= (Elf32_Conflict
*) cmalloc (conflictsno
, sizeof (* iconf
));
20646 error (_("Out of memory allocating space for dynamic conflicts\n"));
20652 Elf32_External_Conflict
* econf32
;
20654 econf32
= (Elf32_External_Conflict
*)
20655 get_data (NULL
, filedata
, conflicts_offset
,
20656 sizeof (*econf32
), conflictsno
, _("conflict"));
20663 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
20664 iconf
[cnt
] = BYTE_GET (econf32
[cnt
]);
20670 Elf64_External_Conflict
* econf64
;
20672 econf64
= (Elf64_External_Conflict
*)
20673 get_data (NULL
, filedata
, conflicts_offset
,
20674 sizeof (*econf64
), conflictsno
, _("conflict"));
20681 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
20682 iconf
[cnt
] = BYTE_GET (econf64
[cnt
]);
20687 printf (ngettext ("\nSection '.conflict' contains %zu entry:\n",
20688 "\nSection '.conflict' contains %zu entries:\n",
20691 puts (_(" Num: Index Value Name"));
20693 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
20695 printf ("%5zu: %8lu ", cnt
, iconf
[cnt
]);
20697 if (iconf
[cnt
] >= filedata
->num_dynamic_syms
)
20698 printf (_("<corrupt symbol index>"));
20701 Elf_Internal_Sym
* psym
;
20703 psym
= & filedata
->dynamic_symbols
[iconf
[cnt
]];
20704 print_vma (psym
->st_value
, FULL_HEX
);
20706 if (valid_dynamic_name (filedata
, psym
->st_name
))
20707 print_symbol_name (25, get_dynamic_name (filedata
, psym
->st_name
));
20709 printf (_("<corrupt: %14ld>"), psym
->st_name
);
20717 if (pltgot
!= 0 && local_gotno
!= 0)
20719 uint64_t ent
, local_end
, global_end
;
20721 unsigned char * data
;
20722 unsigned char * data_end
;
20726 addr_size
= (is_32bit_elf
? 4 : 8);
20727 local_end
= pltgot
+ local_gotno
* addr_size
;
20729 /* PR binutils/17533 file: 012-111227-0.004 */
20730 if (symtabno
< gotsym
)
20732 error (_("The GOT symbol offset (%" PRIu64
20733 ") is greater than the symbol table size (%" PRIu64
")\n"),
20738 global_end
= local_end
+ (symtabno
- gotsym
) * addr_size
;
20739 /* PR 17531: file: 54c91a34. */
20740 if (global_end
< local_end
)
20742 error (_("Too many GOT symbols: %" PRIu64
"\n"), symtabno
);
20746 offset
= offset_from_vma (filedata
, pltgot
, global_end
- pltgot
);
20747 data
= (unsigned char *) get_data (NULL
, filedata
, offset
,
20748 global_end
- pltgot
, 1,
20749 _("Global Offset Table data"));
20750 /* PR 12855: Null data is handled gracefully throughout. */
20751 data_end
= data
+ (global_end
- pltgot
);
20753 printf (_("\nPrimary GOT:\n"));
20754 printf (_(" Canonical gp value: "));
20755 print_vma (pltgot
+ 0x7ff0, LONG_HEX
);
20758 printf (_(" Reserved entries:\n"));
20759 printf (_(" %*s %10s %*s Purpose\n"),
20760 addr_size
* 2, _("Address"), _("Access"),
20761 addr_size
* 2, _("Initial"));
20762 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
20763 printf (_(" Lazy resolver\n"));
20764 if (ent
== (uint64_t) -1)
20765 goto got_print_fail
;
20767 /* Check for the MSB of GOT[1] being set, denoting a GNU object.
20768 This entry will be used by some runtime loaders, to store the
20769 module pointer. Otherwise this is an ordinary local entry.
20770 PR 21344: Check for the entry being fully available before
20773 && data
+ ent
- pltgot
+ addr_size
<= data_end
20774 && (byte_get (data
+ ent
- pltgot
, addr_size
)
20775 >> (addr_size
* 8 - 1)) != 0)
20777 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
20778 printf (_(" Module pointer (GNU extension)\n"));
20779 if (ent
== (uint64_t) -1)
20780 goto got_print_fail
;
20784 if (data
!= NULL
&& ent
< local_end
)
20786 printf (_(" Local entries:\n"));
20787 printf (" %*s %10s %*s\n",
20788 addr_size
* 2, _("Address"), _("Access"),
20789 addr_size
* 2, _("Initial"));
20790 while (ent
< local_end
)
20792 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
20794 if (ent
== (uint64_t) -1)
20795 goto got_print_fail
;
20800 if (data
!= NULL
&& gotsym
< symtabno
)
20804 printf (_(" Global entries:\n"));
20805 printf (" %*s %10s %*s %*s %-7s %3s %s\n",
20806 addr_size
* 2, _("Address"),
20808 addr_size
* 2, _("Initial"),
20809 addr_size
* 2, _("Sym.Val."),
20811 /* Note for translators: "Ndx" = abbreviated form of "Index". */
20812 _("Ndx"), _("Name"));
20814 sym_width
= (is_32bit_elf
? 80 : 160) - 28 - addr_size
* 6 - 1;
20816 for (i
= gotsym
; i
< symtabno
; i
++)
20818 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
20821 if (filedata
->dynamic_symbols
== NULL
)
20822 printf (_("<no dynamic symbols>"));
20823 else if (i
< filedata
->num_dynamic_syms
)
20825 Elf_Internal_Sym
* psym
= filedata
->dynamic_symbols
+ i
;
20827 print_vma (psym
->st_value
, LONG_HEX
);
20828 printf (" %-7s ", get_symbol_type (filedata
, ELF_ST_TYPE (psym
->st_info
)));
20831 const char * s
= printable_section_name_from_index (filedata
, psym
->st_shndx
, & is_special
);
20833 printf ("%3s ", s
);
20835 printf ("%3u ", psym
->st_shndx
);
20837 if (valid_dynamic_name (filedata
, psym
->st_name
))
20838 print_symbol_name (sym_width
,
20839 get_dynamic_name (filedata
, psym
->st_name
));
20841 printf (_("<corrupt: %14ld>"), psym
->st_name
);
20844 printf (_("<symbol index %zu exceeds number of dynamic symbols>"),
20848 if (ent
== (uint64_t) -1)
20858 if (mips_pltgot
!= 0 && jmprel
!= 0 && pltrel
!= 0 && pltrelsz
!= 0)
20861 uint64_t offset
, rel_offset
;
20863 unsigned char * data
;
20864 int addr_size
, sym_width
;
20865 Elf_Internal_Rela
* rels
;
20867 rel_offset
= offset_from_vma (filedata
, jmprel
, pltrelsz
);
20868 if (pltrel
== DT_RELA
)
20870 if (!slurp_rela_relocs (filedata
, rel_offset
, pltrelsz
, &rels
, &count
))
20875 if (!slurp_rel_relocs (filedata
, rel_offset
, pltrelsz
, &rels
, &count
))
20880 addr_size
= (is_32bit_elf
? 4 : 8);
20881 end
= mips_pltgot
+ (2 + count
) * addr_size
;
20883 offset
= offset_from_vma (filedata
, mips_pltgot
, end
- mips_pltgot
);
20884 data
= (unsigned char *) get_data (NULL
, filedata
, offset
, end
- mips_pltgot
,
20885 1, _("Procedure Linkage Table data"));
20892 printf ("\nPLT GOT:\n\n");
20893 printf (_(" Reserved entries:\n"));
20894 printf (_(" %*s %*s Purpose\n"),
20895 addr_size
* 2, _("Address"), addr_size
* 2, _("Initial"));
20896 ent
= print_mips_pltgot_entry (data
, mips_pltgot
, ent
);
20897 printf (_(" PLT lazy resolver\n"));
20898 ent
= print_mips_pltgot_entry (data
, mips_pltgot
, ent
);
20899 printf (_(" Module pointer\n"));
20902 printf (_(" Entries:\n"));
20903 printf (" %*s %*s %*s %-7s %3s %s\n",
20904 addr_size
* 2, _("Address"),
20905 addr_size
* 2, _("Initial"),
20906 addr_size
* 2, _("Sym.Val."), _("Type"), _("Ndx"), _("Name"));
20907 sym_width
= (is_32bit_elf
? 80 : 160) - 17 - addr_size
* 6 - 1;
20908 for (i
= 0; i
< count
; i
++)
20910 uint64_t idx
= get_reloc_symindex (rels
[i
].r_info
);
20912 ent
= print_mips_pltgot_entry (data
, mips_pltgot
, ent
);
20915 if (idx
>= filedata
->num_dynamic_syms
)
20916 printf (_("<corrupt symbol index: %" PRIu64
">"), idx
);
20919 Elf_Internal_Sym
* psym
= filedata
->dynamic_symbols
+ idx
;
20921 print_vma (psym
->st_value
, LONG_HEX
);
20922 printf (" %-7s %3s ",
20923 get_symbol_type (filedata
, ELF_ST_TYPE (psym
->st_info
)),
20924 printable_section_name_from_index (filedata
, psym
->st_shndx
, NULL
));
20925 if (valid_dynamic_name (filedata
, psym
->st_name
))
20926 print_symbol_name (sym_width
,
20927 get_dynamic_name (filedata
, psym
->st_name
));
20929 printf (_("<corrupt: %14ld>"), psym
->st_name
);
20943 process_nds32_specific (Filedata
* filedata
)
20945 Elf_Internal_Shdr
*sect
= NULL
;
20947 sect
= find_section (filedata
, ".nds32_e_flags");
20948 if (sect
!= NULL
&& sect
->sh_size
>= 4)
20950 unsigned char *buf
;
20953 printf ("\nNDS32 elf flags section:\n");
20954 buf
= get_data (NULL
, filedata
, sect
->sh_offset
, 1, 4,
20955 _("NDS32 elf flags section"));
20960 flag
= byte_get (buf
, 4);
20962 switch (flag
& 0x3)
20965 printf ("(VEC_SIZE):\tNo entry.\n");
20968 printf ("(VEC_SIZE):\t4 bytes\n");
20971 printf ("(VEC_SIZE):\t16 bytes\n");
20974 printf ("(VEC_SIZE):\treserved\n");
20983 elf_relocation_cmp (const void *p
, const void *q
)
20985 const elf_relocation
*rp
= (const elf_relocation
*) p
;
20986 const elf_relocation
*rq
= (const elf_relocation
*) q
;
20988 return (rp
->r_offset
> rq
->r_offset
20990 : (rp
->r_offset
< rq
->r_offset
? -1 : 0));
20994 display_elf_relocation_at (uint64_t offset
, uint64_t g
)
20996 bool matched
= false;
20998 for (size_t i
= 0; i
< all_relocations_count
; i
++)
20999 if (all_relocations_root
[i
].r_offset
== offset
)
21002 printf (" %-22s", all_relocations_root
[i
].r_name
);
21004 printf (" %-17.17s", all_relocations_root
[i
].r_name
);
21007 switch (all_relocations_root
[i
].r_type
)
21016 off
= all_relocations_root
[i
].r_addend
;
21020 if (all_relocations_root
[i
].r_symbol
)
21022 printf (" %s", all_relocations_root
[i
].r_symbol
);
21023 if ((int64_t) off
< 0)
21024 printf (" - %" PRIx64
, -off
);
21026 printf (" + %" PRIx64
, off
);
21030 if ((int64_t) off
< 0)
21031 printf (" -%" PRIx64
, -off
);
21033 printf (" %" PRIx64
, off
);
21039 else if (all_relocations_root
[i
].r_offset
> offset
)
21045 printf ("%*c", 24, ' ');
21047 printf ("%*c", 19, ' ');
21048 printf ("%" PRIx64
, g
);
21053 process_got_section_contents (Filedata
* filedata
)
21055 Elf_Internal_Shdr
* section
;
21058 unsigned char *data
;
21060 bool found
= false;
21062 if (!do_got_section_contents
)
21065 switch (filedata
->file_header
.e_type
)
21074 switch (filedata
->file_header
.e_machine
)
21077 case EM_MIPS_RS3_LE
:
21078 /* process_mips_specific also displays GOT related contents. */
21080 res
= process_mips_specific (filedata
, true);
21085 if (all_relocations_count
> 1)
21086 qsort (all_relocations_root
, all_relocations_count
,
21087 sizeof (elf_relocation
), elf_relocation_cmp
);
21089 initialise_dumps_byname (filedata
);
21091 for (i
= 0, section
= filedata
->section_headers
;
21092 i
< filedata
->file_header
.e_shnum
;
21094 if (section
->sh_type
== SHT_PROGBITS
21095 && section
->sh_size
!= 0)
21097 const char *name
= printable_section_name (filedata
, section
);
21099 if (!startswith (name
, ".got"))
21104 data
= (unsigned char *) get_section_contents (section
,
21112 uint32_t entsz
= section
->sh_entsize
;
21113 /* NB: Gold, lld and mold set sh_entsize to 0 on .got and
21114 .got.plt sections. */
21118 switch (filedata
->file_header
.e_machine
)
21124 /* x32 uses 8 byte GOT sh_entsize. */
21132 entries
= section
->sh_size
/ entsz
;
21134 printf (_("\nGlobal Offset Table '%s' contains 1 entry:\n"),
21137 printf (_("\nGlobal Offset Table '%s' contains %" PRIu64
21138 " entries:\n"), name
, entries
);
21144 uint32_t j
, n
= entries
;
21148 unsigned char bytes
[4];
21152 printf (_(" Index: Address Reloc Sym. Name + Addend/Value\n"));
21153 /* |---9---| |---8--| |---------22---------| |........... */
21155 printf (_(" Index: Address Reloc Sym. Name + Addend/Value\n"));
21156 /* |--7--| |---8--| |-------17------| |........... */
21158 addr
= section
->sh_addr
;
21159 got
= (struct got32
*) data
;
21160 for (j
= 0; j
< n
; j
++)
21162 g
= BYTE_GET (got
[j
].bytes
);
21164 printf ("%8" PRIu32
": %8.8" PRIx32
, j
, addr
);
21166 printf ("%6" PRIu32
": %8.8" PRIx32
, j
, addr
);
21167 display_elf_relocation_at (addr
, g
);
21177 unsigned char bytes
[4];
21181 printf (_(" Index: Address Reloc Sym. Name + Addend/Value\n"));
21182 /* |---9---| |------16------| |---------22---------| |........... */
21184 printf (_(" Index: Address Reloc Sym. Name + Addend/Value\n"));
21185 /* |--7--| |----12----| |------17-------| |........... */
21187 addr
= section
->sh_addr
;
21188 got
= (struct got64
*) data
;
21189 for (j
= 0; j
< entries
; j
++)
21191 g
= BYTE_GET (got
[j
].bytes
);
21193 printf ("%8" PRIu64
": %16.16" PRIx64
, j
, addr
);
21195 printf ("%6" PRIu64
": %12.12" PRIx64
, j
, addr
);
21196 display_elf_relocation_at (addr
, g
);
21208 if (filedata
->is_separate
)
21209 printf (_("\nThere is no GOT section in linked file '%s'.\n"),
21210 filedata
->file_name
);
21212 printf (_("\nThere is no GOT section in this file.\n"));
21215 for (size_t j
= 0; j
< all_relocations_count
; j
++)
21216 free (all_relocations_root
[j
].r_symbol
);
21217 free (all_relocations_root
);
21218 all_relocations_root
= NULL
;
21219 all_relocations
= NULL
;
21220 all_relocations_count
= 0;
21225 process_gnu_liblist (Filedata
* filedata
)
21227 Elf_Internal_Shdr
* section
;
21228 Elf_Internal_Shdr
* string_sec
;
21229 Elf32_External_Lib
* elib
;
21231 size_t strtab_size
;
21233 uint64_t num_liblist
;
21240 for (i
= 0, section
= filedata
->section_headers
;
21241 i
< filedata
->file_header
.e_shnum
;
21244 switch (section
->sh_type
)
21246 case SHT_GNU_LIBLIST
:
21247 if (section
->sh_link
>= filedata
->file_header
.e_shnum
)
21250 elib
= (Elf32_External_Lib
*)
21251 get_data (NULL
, filedata
, section
->sh_offset
, 1, section
->sh_size
,
21252 _("liblist section data"));
21260 string_sec
= filedata
->section_headers
+ section
->sh_link
;
21261 strtab
= (char *) get_data (NULL
, filedata
, string_sec
->sh_offset
, 1,
21262 string_sec
->sh_size
,
21263 _("liblist string table"));
21265 || section
->sh_entsize
!= sizeof (Elf32_External_Lib
))
21272 strtab_size
= string_sec
->sh_size
;
21274 num_liblist
= section
->sh_size
/ sizeof (Elf32_External_Lib
);
21275 printf (ngettext ("\nLibrary list section '%s' contains %" PRIu64
21277 "\nLibrary list section '%s' contains %" PRIu64
21280 printable_section_name (filedata
, section
),
21283 puts (_(" Library Time Stamp Checksum Version Flags"));
21285 for (cnt
= 0; cnt
< section
->sh_size
/ sizeof (Elf32_External_Lib
);
21293 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
21294 atime
= BYTE_GET (elib
[cnt
].l_time_stamp
);
21295 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
21296 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
21297 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
21299 tmp
= gmtime (&atime
);
21300 snprintf (timebuf
, sizeof (timebuf
),
21301 "%04u-%02u-%02uT%02u:%02u:%02u",
21302 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
21303 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
21305 printf ("%3zu: ", cnt
);
21307 printf ("%-20s", liblist
.l_name
< strtab_size
21308 ? strtab
+ liblist
.l_name
: _("<corrupt>"));
21310 printf ("%-20.20s", liblist
.l_name
< strtab_size
21311 ? strtab
+ liblist
.l_name
: _("<corrupt>"));
21312 printf (" %s %#010lx %-7ld %-7ld\n", timebuf
, liblist
.l_checksum
,
21313 liblist
.l_version
, liblist
.l_flags
);
21324 static const char *
21325 get_note_type (Filedata
* filedata
, unsigned e_type
)
21327 static char buff
[64];
21329 if (filedata
->file_header
.e_type
== ET_CORE
)
21333 return _("NT_AUXV (auxiliary vector)");
21335 return _("NT_PRSTATUS (prstatus structure)");
21337 return _("NT_FPREGSET (floating point registers)");
21339 return _("NT_PRPSINFO (prpsinfo structure)");
21340 case NT_TASKSTRUCT
:
21341 return _("NT_TASKSTRUCT (task structure)");
21343 return _("NT_GDB_TDESC (GDB XML target description)");
21345 return _("NT_PRXFPREG (user_xfpregs structure)");
21347 return _("NT_PPC_VMX (ppc Altivec registers)");
21349 return _("NT_PPC_VSX (ppc VSX registers)");
21351 return _("NT_PPC_TAR (ppc TAR register)");
21353 return _("NT_PPC_PPR (ppc PPR register)");
21355 return _("NT_PPC_DSCR (ppc DSCR register)");
21357 return _("NT_PPC_EBB (ppc EBB registers)");
21359 return _("NT_PPC_PMU (ppc PMU registers)");
21360 case NT_PPC_TM_CGPR
:
21361 return _("NT_PPC_TM_CGPR (ppc checkpointed GPR registers)");
21362 case NT_PPC_TM_CFPR
:
21363 return _("NT_PPC_TM_CFPR (ppc checkpointed floating point registers)");
21364 case NT_PPC_TM_CVMX
:
21365 return _("NT_PPC_TM_CVMX (ppc checkpointed Altivec registers)");
21366 case NT_PPC_TM_CVSX
:
21367 return _("NT_PPC_TM_CVSX (ppc checkpointed VSX registers)");
21368 case NT_PPC_TM_SPR
:
21369 return _("NT_PPC_TM_SPR (ppc TM special purpose registers)");
21370 case NT_PPC_TM_CTAR
:
21371 return _("NT_PPC_TM_CTAR (ppc checkpointed TAR register)");
21372 case NT_PPC_TM_CPPR
:
21373 return _("NT_PPC_TM_CPPR (ppc checkpointed PPR register)");
21374 case NT_PPC_TM_CDSCR
:
21375 return _("NT_PPC_TM_CDSCR (ppc checkpointed DSCR register)");
21377 return _("NT_386_TLS (x86 TLS information)");
21378 case NT_386_IOPERM
:
21379 return _("NT_386_IOPERM (x86 I/O permissions)");
21380 case NT_X86_XSTATE
:
21381 return _("NT_X86_XSTATE (x86 XSAVE extended state)");
21383 return _("NT_X86_CET (x86 CET state)");
21385 return _("NT_X86_SHSTK (x86 SHSTK state)");
21386 case NT_S390_HIGH_GPRS
:
21387 return _("NT_S390_HIGH_GPRS (s390 upper register halves)");
21388 case NT_S390_TIMER
:
21389 return _("NT_S390_TIMER (s390 timer register)");
21390 case NT_S390_TODCMP
:
21391 return _("NT_S390_TODCMP (s390 TOD comparator register)");
21392 case NT_S390_TODPREG
:
21393 return _("NT_S390_TODPREG (s390 TOD programmable register)");
21395 return _("NT_S390_CTRS (s390 control registers)");
21396 case NT_S390_PREFIX
:
21397 return _("NT_S390_PREFIX (s390 prefix register)");
21398 case NT_S390_LAST_BREAK
:
21399 return _("NT_S390_LAST_BREAK (s390 last breaking event address)");
21400 case NT_S390_SYSTEM_CALL
:
21401 return _("NT_S390_SYSTEM_CALL (s390 system call restart data)");
21403 return _("NT_S390_TDB (s390 transaction diagnostic block)");
21404 case NT_S390_VXRS_LOW
:
21405 return _("NT_S390_VXRS_LOW (s390 vector registers 0-15 upper half)");
21406 case NT_S390_VXRS_HIGH
:
21407 return _("NT_S390_VXRS_HIGH (s390 vector registers 16-31)");
21408 case NT_S390_GS_CB
:
21409 return _("NT_S390_GS_CB (s390 guarded-storage registers)");
21410 case NT_S390_GS_BC
:
21411 return _("NT_S390_GS_BC (s390 guarded-storage broadcast control)");
21413 return _("NT_ARM_VFP (arm VFP registers)");
21415 return _("NT_ARM_TLS (AArch TLS registers)");
21416 case NT_ARM_HW_BREAK
:
21417 return _("NT_ARM_HW_BREAK (AArch hardware breakpoint registers)");
21418 case NT_ARM_HW_WATCH
:
21419 return _("NT_ARM_HW_WATCH (AArch hardware watchpoint registers)");
21420 case NT_ARM_SYSTEM_CALL
:
21421 return _("NT_ARM_SYSTEM_CALL (AArch system call number)");
21423 return _("NT_ARM_SVE (AArch SVE registers)");
21424 case NT_ARM_PAC_MASK
:
21425 return _("NT_ARM_PAC_MASK (AArch pointer authentication code masks)");
21426 case NT_ARM_PACA_KEYS
:
21427 return _("NT_ARM_PACA_KEYS (ARM pointer authentication address keys)");
21428 case NT_ARM_PACG_KEYS
:
21429 return _("NT_ARM_PACG_KEYS (ARM pointer authentication generic keys)");
21430 case NT_ARM_TAGGED_ADDR_CTRL
:
21431 return _("NT_ARM_TAGGED_ADDR_CTRL (AArch tagged address control)");
21433 return _("NT_ARM_SSVE (AArch64 streaming SVE registers)");
21435 return _("NT_ARM_ZA (AArch64 SME ZA register)");
21437 return _("NT_ARM_ZT (AArch64 SME2 ZT registers)");
21438 case NT_ARM_PAC_ENABLED_KEYS
:
21439 return _("NT_ARM_PAC_ENABLED_KEYS (AArch64 pointer authentication enabled keys)");
21441 return _("NT_ARC_V2 (ARC HS accumulator/extra registers)");
21443 return _("NT_RISCV_CSR (RISC-V control and status registers)");
21445 return _("NT_PSTATUS (pstatus structure)");
21447 return _("NT_FPREGS (floating point registers)");
21449 return _("NT_PSINFO (psinfo structure)");
21451 return _("NT_LWPSTATUS (lwpstatus_t structure)");
21453 return _("NT_LWPSINFO (lwpsinfo_t structure)");
21454 case NT_WIN32PSTATUS
:
21455 return _("NT_WIN32PSTATUS (win32_pstatus structure)");
21457 return _("NT_SIGINFO (siginfo_t data)");
21459 return _("NT_FILE (mapped files)");
21467 return _("NT_VERSION (version)");
21469 return _("NT_ARCH (architecture)");
21470 case NT_GNU_BUILD_ATTRIBUTE_OPEN
:
21472 case NT_GNU_BUILD_ATTRIBUTE_FUNC
:
21474 case NT_GO_BUILDID
:
21475 return _("GO BUILDID");
21476 case FDO_PACKAGING_METADATA
:
21477 return _("FDO_PACKAGING_METADATA");
21478 case FDO_DLOPEN_METADATA
:
21479 return _("FDO_DLOPEN_METADATA");
21484 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
21489 print_core_note (Elf_Internal_Note
*pnote
)
21491 unsigned int addr_size
= is_32bit_elf
? 4 : 8;
21492 uint64_t count
, page_size
;
21493 unsigned char *descdata
, *filenames
, *descend
;
21495 if (pnote
->type
!= NT_FILE
)
21502 if (pnote
->descsz
< 2 * addr_size
)
21504 error (_(" Malformed note - too short for header\n"));
21508 descdata
= (unsigned char *) pnote
->descdata
;
21509 descend
= descdata
+ pnote
->descsz
;
21511 if (descdata
[pnote
->descsz
- 1] != '\0')
21513 error (_(" Malformed note - does not end with \\0\n"));
21517 count
= byte_get (descdata
, addr_size
);
21518 descdata
+= addr_size
;
21520 page_size
= byte_get (descdata
, addr_size
);
21521 descdata
+= addr_size
;
21523 if (count
> ((uint64_t) -1 - 2 * addr_size
) / (3 * addr_size
)
21524 || pnote
->descsz
< 2 * addr_size
+ count
* 3 * addr_size
)
21526 error (_(" Malformed note - too short for supplied file count\n"));
21530 printf (_(" Page size: "));
21531 print_vma (page_size
, DEC
);
21534 printf (_(" %*s%*s%*s\n"),
21535 (int) (2 + 2 * addr_size
), _("Start"),
21536 (int) (4 + 2 * addr_size
), _("End"),
21537 (int) (4 + 2 * addr_size
), _("Page Offset"));
21538 filenames
= descdata
+ count
* 3 * addr_size
;
21539 while (count
-- > 0)
21541 uint64_t start
, end
, file_ofs
;
21543 if (filenames
== descend
)
21545 error (_(" Malformed note - filenames end too early\n"));
21549 start
= byte_get (descdata
, addr_size
);
21550 descdata
+= addr_size
;
21551 end
= byte_get (descdata
, addr_size
);
21552 descdata
+= addr_size
;
21553 file_ofs
= byte_get (descdata
, addr_size
);
21554 descdata
+= addr_size
;
21557 print_vma (start
, FULL_HEX
);
21559 print_vma (end
, FULL_HEX
);
21561 print_vma (file_ofs
, FULL_HEX
);
21562 printf ("\n %s\n", filenames
);
21564 filenames
+= 1 + strlen ((char *) filenames
);
21570 static const char *
21571 get_gnu_elf_note_type (unsigned e_type
)
21573 /* NB/ Keep this switch statement in sync with print_gnu_note (). */
21576 case NT_GNU_ABI_TAG
:
21577 return _("NT_GNU_ABI_TAG (ABI version tag)");
21579 return _("NT_GNU_HWCAP (DSO-supplied software HWCAP info)");
21580 case NT_GNU_BUILD_ID
:
21581 return _("NT_GNU_BUILD_ID (unique build ID bitstring)");
21582 case NT_GNU_GOLD_VERSION
:
21583 return _("NT_GNU_GOLD_VERSION (gold version)");
21584 case NT_GNU_PROPERTY_TYPE_0
:
21585 return _("NT_GNU_PROPERTY_TYPE_0");
21586 case NT_GNU_BUILD_ATTRIBUTE_OPEN
:
21587 return _("NT_GNU_BUILD_ATTRIBUTE_OPEN");
21588 case NT_GNU_BUILD_ATTRIBUTE_FUNC
:
21589 return _("NT_GNU_BUILD_ATTRIBUTE_FUNC");
21592 static char buff
[64];
21594 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
21601 decode_x86_compat_isa (unsigned int bitmask
)
21605 unsigned int bit
= bitmask
& (- bitmask
);
21610 case GNU_PROPERTY_X86_COMPAT_ISA_1_486
:
21613 case GNU_PROPERTY_X86_COMPAT_ISA_1_586
:
21616 case GNU_PROPERTY_X86_COMPAT_ISA_1_686
:
21619 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE
:
21622 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE2
:
21625 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE3
:
21628 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSSE3
:
21631 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE4_1
:
21634 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE4_2
:
21637 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX
:
21640 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX2
:
21643 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512F
:
21644 printf ("AVX512F");
21646 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512CD
:
21647 printf ("AVX512CD");
21649 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512ER
:
21650 printf ("AVX512ER");
21652 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512PF
:
21653 printf ("AVX512PF");
21655 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512VL
:
21656 printf ("AVX512VL");
21658 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512DQ
:
21659 printf ("AVX512DQ");
21661 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512BW
:
21662 printf ("AVX512BW");
21665 printf (_("<unknown: %x>"), bit
);
21674 decode_x86_compat_2_isa (unsigned int bitmask
)
21678 printf (_("<None>"));
21684 unsigned int bit
= bitmask
& (- bitmask
);
21689 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_CMOV
:
21692 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE
:
21695 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE2
:
21698 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE3
:
21701 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSSE3
:
21704 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE4_1
:
21707 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE4_2
:
21710 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX
:
21713 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX2
:
21716 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_FMA
:
21719 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512F
:
21720 printf ("AVX512F");
21722 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512CD
:
21723 printf ("AVX512CD");
21725 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512ER
:
21726 printf ("AVX512ER");
21728 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512PF
:
21729 printf ("AVX512PF");
21731 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512VL
:
21732 printf ("AVX512VL");
21734 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512DQ
:
21735 printf ("AVX512DQ");
21737 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512BW
:
21738 printf ("AVX512BW");
21740 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_4FMAPS
:
21741 printf ("AVX512_4FMAPS");
21743 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_4VNNIW
:
21744 printf ("AVX512_4VNNIW");
21746 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_BITALG
:
21747 printf ("AVX512_BITALG");
21749 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_IFMA
:
21750 printf ("AVX512_IFMA");
21752 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_VBMI
:
21753 printf ("AVX512_VBMI");
21755 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_VBMI2
:
21756 printf ("AVX512_VBMI2");
21758 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_VNNI
:
21759 printf ("AVX512_VNNI");
21761 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_BF16
:
21762 printf ("AVX512_BF16");
21765 printf (_("<unknown: %x>"), bit
);
21773 static const char *
21774 get_amdgpu_elf_note_type (unsigned int e_type
)
21778 case NT_AMDGPU_METADATA
:
21779 return _("NT_AMDGPU_METADATA (code object metadata)");
21782 static char buf
[64];
21783 snprintf (buf
, sizeof (buf
), _("Unknown note type: (0x%08x)"), e_type
);
21790 decode_x86_isa (unsigned int bitmask
)
21794 unsigned int bit
= bitmask
& (- bitmask
);
21799 case GNU_PROPERTY_X86_ISA_1_BASELINE
:
21800 printf ("x86-64-baseline");
21802 case GNU_PROPERTY_X86_ISA_1_V2
:
21803 printf ("x86-64-v2");
21805 case GNU_PROPERTY_X86_ISA_1_V3
:
21806 printf ("x86-64-v3");
21808 case GNU_PROPERTY_X86_ISA_1_V4
:
21809 printf ("x86-64-v4");
21812 printf (_("<unknown: %x>"), bit
);
21821 decode_x86_feature_1 (unsigned int bitmask
)
21825 printf (_("<None>"));
21831 unsigned int bit
= bitmask
& (- bitmask
);
21836 case GNU_PROPERTY_X86_FEATURE_1_IBT
:
21839 case GNU_PROPERTY_X86_FEATURE_1_SHSTK
:
21842 case GNU_PROPERTY_X86_FEATURE_1_LAM_U48
:
21843 printf ("LAM_U48");
21845 case GNU_PROPERTY_X86_FEATURE_1_LAM_U57
:
21846 printf ("LAM_U57");
21849 printf (_("<unknown: %x>"), bit
);
21858 decode_x86_feature_2 (unsigned int bitmask
)
21862 printf (_("<None>"));
21868 unsigned int bit
= bitmask
& (- bitmask
);
21873 case GNU_PROPERTY_X86_FEATURE_2_X86
:
21876 case GNU_PROPERTY_X86_FEATURE_2_X87
:
21879 case GNU_PROPERTY_X86_FEATURE_2_MMX
:
21882 case GNU_PROPERTY_X86_FEATURE_2_XMM
:
21885 case GNU_PROPERTY_X86_FEATURE_2_YMM
:
21888 case GNU_PROPERTY_X86_FEATURE_2_ZMM
:
21891 case GNU_PROPERTY_X86_FEATURE_2_TMM
:
21894 case GNU_PROPERTY_X86_FEATURE_2_MASK
:
21897 case GNU_PROPERTY_X86_FEATURE_2_FXSR
:
21900 case GNU_PROPERTY_X86_FEATURE_2_XSAVE
:
21903 case GNU_PROPERTY_X86_FEATURE_2_XSAVEOPT
:
21904 printf ("XSAVEOPT");
21906 case GNU_PROPERTY_X86_FEATURE_2_XSAVEC
:
21910 printf (_("<unknown: %x>"), bit
);
21919 decode_aarch64_feature_1_and (unsigned int bitmask
)
21923 unsigned int bit
= bitmask
& (- bitmask
);
21928 case GNU_PROPERTY_AARCH64_FEATURE_1_BTI
:
21932 case GNU_PROPERTY_AARCH64_FEATURE_1_PAC
:
21936 case GNU_PROPERTY_AARCH64_FEATURE_1_GCS
:
21941 printf (_("<unknown: %x>"), bit
);
21950 decode_riscv_feature_1_and (unsigned int bitmask
)
21954 unsigned int bit
= bitmask
& (- bitmask
);
21959 case GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_UNLABELED
:
21960 printf ("CFI_LP_UNLABELED");
21963 case GNU_PROPERTY_RISCV_FEATURE_1_CFI_SS
:
21968 printf (_("<unknown: %x>"), bit
);
21977 decode_1_needed (unsigned int bitmask
)
21981 unsigned int bit
= bitmask
& (- bitmask
);
21986 case GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS
:
21987 printf ("indirect external access");
21990 printf (_("<unknown: %x>"), bit
);
21999 print_gnu_property_note (Filedata
* filedata
, Elf_Internal_Note
* pnote
)
22001 unsigned char * ptr
= (unsigned char *) pnote
->descdata
;
22002 unsigned char * ptr_end
= ptr
+ pnote
->descsz
;
22003 unsigned int size
= is_32bit_elf
? 4 : 8;
22005 printf (_(" Properties: "));
22007 if (pnote
->descsz
< 8 || (pnote
->descsz
% size
) != 0)
22009 printf (_("<corrupt GNU_PROPERTY_TYPE, size = %#lx>\n"), pnote
->descsz
);
22013 while (ptr
< ptr_end
)
22017 unsigned int datasz
;
22019 if ((size_t) (ptr_end
- ptr
) < 8)
22021 printf (_("<corrupt descsz: %#lx>\n"), pnote
->descsz
);
22025 type
= byte_get (ptr
, 4);
22026 datasz
= byte_get (ptr
+ 4, 4);
22030 if (datasz
> (size_t) (ptr_end
- ptr
))
22032 printf (_("<corrupt type (%#x) datasz: %#x>\n"),
22037 if (type
>= GNU_PROPERTY_LOPROC
&& type
<= GNU_PROPERTY_HIPROC
)
22039 if (filedata
->file_header
.e_machine
== EM_X86_64
22040 || filedata
->file_header
.e_machine
== EM_IAMCU
22041 || filedata
->file_header
.e_machine
== EM_386
)
22043 unsigned int bitmask
;
22046 bitmask
= byte_get (ptr
, 4);
22052 case GNU_PROPERTY_X86_ISA_1_USED
:
22054 printf (_("x86 ISA used: <corrupt length: %#x> "),
22058 printf ("x86 ISA used: ");
22059 decode_x86_isa (bitmask
);
22063 case GNU_PROPERTY_X86_ISA_1_NEEDED
:
22065 printf (_("x86 ISA needed: <corrupt length: %#x> "),
22069 printf ("x86 ISA needed: ");
22070 decode_x86_isa (bitmask
);
22074 case GNU_PROPERTY_X86_FEATURE_1_AND
:
22076 printf (_("x86 feature: <corrupt length: %#x> "),
22080 printf ("x86 feature: ");
22081 decode_x86_feature_1 (bitmask
);
22085 case GNU_PROPERTY_X86_FEATURE_2_USED
:
22087 printf (_("x86 feature used: <corrupt length: %#x> "),
22091 printf ("x86 feature used: ");
22092 decode_x86_feature_2 (bitmask
);
22096 case GNU_PROPERTY_X86_FEATURE_2_NEEDED
:
22098 printf (_("x86 feature needed: <corrupt length: %#x> "), datasz
);
22101 printf ("x86 feature needed: ");
22102 decode_x86_feature_2 (bitmask
);
22106 case GNU_PROPERTY_X86_COMPAT_ISA_1_USED
:
22108 printf (_("x86 ISA used: <corrupt length: %#x> "),
22112 printf ("x86 ISA used: ");
22113 decode_x86_compat_isa (bitmask
);
22117 case GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED
:
22119 printf (_("x86 ISA needed: <corrupt length: %#x> "),
22123 printf ("x86 ISA needed: ");
22124 decode_x86_compat_isa (bitmask
);
22128 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_USED
:
22130 printf (_("x86 ISA used: <corrupt length: %#x> "),
22134 printf ("x86 ISA used: ");
22135 decode_x86_compat_2_isa (bitmask
);
22139 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_NEEDED
:
22141 printf (_("x86 ISA needed: <corrupt length: %#x> "),
22145 printf ("x86 ISA needed: ");
22146 decode_x86_compat_2_isa (bitmask
);
22154 else if (filedata
->file_header
.e_machine
== EM_AARCH64
)
22156 if (type
== GNU_PROPERTY_AARCH64_FEATURE_1_AND
)
22158 printf ("AArch64 feature: ");
22160 printf (_("<corrupt length: %#x> "), datasz
);
22162 decode_aarch64_feature_1_and (byte_get (ptr
, 4));
22166 else if (filedata
->file_header
.e_machine
== EM_RISCV
)
22168 if (type
== GNU_PROPERTY_RISCV_FEATURE_1_AND
)
22170 printf ("RISC-V AND feature: ");
22172 printf (_("<corrupt length: %#x> "), datasz
);
22174 decode_riscv_feature_1_and (byte_get (ptr
, 4));
22183 case GNU_PROPERTY_STACK_SIZE
:
22184 printf (_("stack size: "));
22185 if (datasz
!= size
)
22186 printf (_("<corrupt length: %#x> "), datasz
);
22188 printf ("%#" PRIx64
, byte_get (ptr
, size
));
22191 case GNU_PROPERTY_NO_COPY_ON_PROTECTED
:
22192 printf ("no copy on protected ");
22194 printf (_("<corrupt length: %#x> "), datasz
);
22197 case GNU_PROPERTY_MEMORY_SEAL
:
22198 printf ("memory seal ");
22200 printf (_("<corrupt length: %#x> "), datasz
);
22204 if ((type
>= GNU_PROPERTY_UINT32_AND_LO
22205 && type
<= GNU_PROPERTY_UINT32_AND_HI
)
22206 || (type
>= GNU_PROPERTY_UINT32_OR_LO
22207 && type
<= GNU_PROPERTY_UINT32_OR_HI
))
22211 case GNU_PROPERTY_1_NEEDED
:
22213 printf (_("1_needed: <corrupt length: %#x> "),
22217 unsigned int bitmask
= byte_get (ptr
, 4);
22218 printf ("1_needed: ");
22219 decode_1_needed (bitmask
);
22226 if (type
<= GNU_PROPERTY_UINT32_AND_HI
)
22227 printf (_("UINT32_AND (%#x): "), type
);
22229 printf (_("UINT32_OR (%#x): "), type
);
22231 printf (_("<corrupt length: %#x> "), datasz
);
22233 printf ("%#x", (unsigned int) byte_get (ptr
, 4));
22240 if (type
< GNU_PROPERTY_LOPROC
)
22241 printf (_("<unknown type %#x data: "), type
);
22242 else if (type
< GNU_PROPERTY_LOUSER
)
22243 printf (_("<processor-specific type %#x data: "), type
);
22245 printf (_("<application-specific type %#x data: "), type
);
22246 for (j
= 0; j
< datasz
; ++j
)
22247 printf ("%02x ", ptr
[j
] & 0xff);
22251 ptr
+= ((datasz
+ (size
- 1)) & ~ (size
- 1));
22252 if (ptr
== ptr_end
)
22265 print_gnu_note (Filedata
* filedata
, Elf_Internal_Note
*pnote
)
22267 /* NB/ Keep this switch statement in sync with get_gnu_elf_note_type (). */
22268 switch (pnote
->type
)
22270 case NT_GNU_BUILD_ID
:
22274 printf (_(" Build ID: "));
22275 for (i
= 0; i
< pnote
->descsz
; ++i
)
22276 printf ("%02x", pnote
->descdata
[i
] & 0xff);
22281 case NT_GNU_ABI_TAG
:
22283 unsigned int os
, major
, minor
, subminor
;
22284 const char *osname
;
22286 /* PR 17531: file: 030-599401-0.004. */
22287 if (pnote
->descsz
< 16)
22289 printf (_(" <corrupt GNU_ABI_TAG>\n"));
22293 os
= byte_get ((unsigned char *) pnote
->descdata
, 4);
22294 major
= byte_get ((unsigned char *) pnote
->descdata
+ 4, 4);
22295 minor
= byte_get ((unsigned char *) pnote
->descdata
+ 8, 4);
22296 subminor
= byte_get ((unsigned char *) pnote
->descdata
+ 12, 4);
22300 case GNU_ABI_TAG_LINUX
:
22303 case GNU_ABI_TAG_HURD
:
22306 case GNU_ABI_TAG_SOLARIS
:
22307 osname
= "Solaris";
22309 case GNU_ABI_TAG_FREEBSD
:
22310 osname
= "FreeBSD";
22312 case GNU_ABI_TAG_NETBSD
:
22315 case GNU_ABI_TAG_SYLLABLE
:
22316 osname
= "Syllable";
22318 case GNU_ABI_TAG_NACL
:
22322 osname
= "Unknown";
22326 printf (_(" OS: %s, ABI: %d.%d.%d\n"), osname
,
22327 major
, minor
, subminor
);
22331 case NT_GNU_GOLD_VERSION
:
22335 printf (_(" Version: "));
22336 for (i
= 0; i
< pnote
->descsz
&& pnote
->descdata
[i
] != '\0'; ++i
)
22337 printf ("%c", pnote
->descdata
[i
]);
22344 unsigned int num_entries
, mask
;
22346 /* Hardware capabilities information. Word 0 is the number of entries.
22347 Word 1 is a bitmask of enabled entries. The rest of the descriptor
22348 is a series of entries, where each entry is a single byte followed
22349 by a nul terminated string. The byte gives the bit number to test
22350 if enabled in the bitmask. */
22351 printf (_(" Hardware Capabilities: "));
22352 if (pnote
->descsz
< 8)
22354 error (_("<corrupt GNU_HWCAP>\n"));
22357 num_entries
= byte_get ((unsigned char *) pnote
->descdata
, 4);
22358 mask
= byte_get ((unsigned char *) pnote
->descdata
+ 4, 4);
22359 printf (_("num entries: %d, enabled mask: %x\n"), num_entries
, mask
);
22360 /* FIXME: Add code to display the entries... */
22364 case NT_GNU_PROPERTY_TYPE_0
:
22365 print_gnu_property_note (filedata
, pnote
);
22369 /* Handle unrecognised types. An error message should have already been
22370 created by get_gnu_elf_note_type(), so all that we need to do is to
22371 display the data. */
22375 printf (_(" Description data: "));
22376 for (i
= 0; i
< pnote
->descsz
; ++i
)
22377 printf ("%02x ", pnote
->descdata
[i
] & 0xff);
22386 static const char *
22387 get_v850_elf_note_type (enum v850_notes n_type
)
22389 static char buff
[64];
22393 case V850_NOTE_ALIGNMENT
: return _("Alignment of 8-byte objects");
22394 case V850_NOTE_DATA_SIZE
: return _("Sizeof double and long double");
22395 case V850_NOTE_FPU_INFO
: return _("Type of FPU support needed");
22396 case V850_NOTE_SIMD_INFO
: return _("Use of SIMD instructions");
22397 case V850_NOTE_CACHE_INFO
: return _("Use of cache");
22398 case V850_NOTE_MMU_INFO
: return _("Use of MMU");
22400 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), n_type
);
22406 print_v850_note (Elf_Internal_Note
* pnote
)
22410 printf (" %s: ", get_v850_elf_note_type (pnote
->type
));
22412 if (pnote
->descsz
!= 4)
22414 printf ("<corrupt descsz: %#lx>\n", pnote
->descsz
);
22418 val
= byte_get ((unsigned char *) pnote
->descdata
, pnote
->descsz
);
22422 printf (_("not set\n"));
22426 switch (pnote
->type
)
22428 case V850_NOTE_ALIGNMENT
:
22431 case EF_RH850_DATA_ALIGN4
: printf (_("4-byte\n")); return true;
22432 case EF_RH850_DATA_ALIGN8
: printf (_("8-byte\n")); return true;
22436 case V850_NOTE_DATA_SIZE
:
22439 case EF_RH850_DOUBLE32
: printf (_("4-bytes\n")); return true;
22440 case EF_RH850_DOUBLE64
: printf (_("8-bytes\n")); return true;
22444 case V850_NOTE_FPU_INFO
:
22447 case EF_RH850_FPU20
: printf (_("FPU-2.0\n")); return true;
22448 case EF_RH850_FPU30
: printf (_("FPU-3.0\n")); return true;
22452 case V850_NOTE_MMU_INFO
:
22453 case V850_NOTE_CACHE_INFO
:
22454 case V850_NOTE_SIMD_INFO
:
22455 if (val
== EF_RH850_SIMD
)
22457 printf (_("yes\n"));
22463 /* An 'unknown note type' message will already have been displayed. */
22467 printf (_("unknown value: %x\n"), val
);
22472 process_netbsd_elf_note (Elf_Internal_Note
* pnote
)
22474 unsigned int version
;
22476 switch (pnote
->type
)
22478 case NT_NETBSD_IDENT
:
22479 if (pnote
->descsz
< 1)
22481 version
= byte_get ((unsigned char *) pnote
->descdata
, sizeof (version
));
22482 if ((version
/ 10000) % 100)
22483 printf (" NetBSD\t\t0x%08lx\tIDENT %u (%u.%u%s%c)\n", pnote
->descsz
,
22484 version
, version
/ 100000000, (version
/ 1000000) % 100,
22485 (version
/ 10000) % 100 > 26 ? "Z" : "",
22486 'A' + (version
/ 10000) % 26);
22488 printf (" NetBSD\t\t0x%08lx\tIDENT %u (%u.%u.%u)\n", pnote
->descsz
,
22489 version
, version
/ 100000000, (version
/ 1000000) % 100,
22490 (version
/ 100) % 100);
22493 case NT_NETBSD_MARCH
:
22494 printf (" NetBSD\t\t0x%08lx\tMARCH <%s>\n", pnote
->descsz
,
22498 case NT_NETBSD_PAX
:
22499 if (pnote
->descsz
< 1)
22501 version
= byte_get ((unsigned char *) pnote
->descdata
, sizeof (version
));
22502 printf (" NetBSD\t\t0x%08lx\tPaX <%s%s%s%s%s%s>\n", pnote
->descsz
,
22503 ((version
& NT_NETBSD_PAX_MPROTECT
) ? "+mprotect" : ""),
22504 ((version
& NT_NETBSD_PAX_NOMPROTECT
) ? "-mprotect" : ""),
22505 ((version
& NT_NETBSD_PAX_GUARD
) ? "+guard" : ""),
22506 ((version
& NT_NETBSD_PAX_NOGUARD
) ? "-guard" : ""),
22507 ((version
& NT_NETBSD_PAX_ASLR
) ? "+ASLR" : ""),
22508 ((version
& NT_NETBSD_PAX_NOASLR
) ? "-ASLR" : ""));
22512 printf (" NetBSD\t0x%08lx\tUnknown note type: (0x%08lx)\n",
22513 pnote
->descsz
, pnote
->type
);
22517 static const char *
22518 get_freebsd_elfcore_note_type (Filedata
* filedata
, unsigned e_type
)
22522 case NT_FREEBSD_THRMISC
:
22523 return _("NT_THRMISC (thrmisc structure)");
22524 case NT_FREEBSD_PROCSTAT_PROC
:
22525 return _("NT_PROCSTAT_PROC (proc data)");
22526 case NT_FREEBSD_PROCSTAT_FILES
:
22527 return _("NT_PROCSTAT_FILES (files data)");
22528 case NT_FREEBSD_PROCSTAT_VMMAP
:
22529 return _("NT_PROCSTAT_VMMAP (vmmap data)");
22530 case NT_FREEBSD_PROCSTAT_GROUPS
:
22531 return _("NT_PROCSTAT_GROUPS (groups data)");
22532 case NT_FREEBSD_PROCSTAT_UMASK
:
22533 return _("NT_PROCSTAT_UMASK (umask data)");
22534 case NT_FREEBSD_PROCSTAT_RLIMIT
:
22535 return _("NT_PROCSTAT_RLIMIT (rlimit data)");
22536 case NT_FREEBSD_PROCSTAT_OSREL
:
22537 return _("NT_PROCSTAT_OSREL (osreldate data)");
22538 case NT_FREEBSD_PROCSTAT_PSSTRINGS
:
22539 return _("NT_PROCSTAT_PSSTRINGS (ps_strings data)");
22540 case NT_FREEBSD_PROCSTAT_AUXV
:
22541 return _("NT_PROCSTAT_AUXV (auxv data)");
22542 case NT_FREEBSD_PTLWPINFO
:
22543 return _("NT_PTLWPINFO (ptrace_lwpinfo structure)");
22544 case NT_FREEBSD_X86_SEGBASES
:
22545 return _("NT_X86_SEGBASES (x86 segment base registers)");
22547 return get_note_type (filedata
, e_type
);
22550 static const char *
22551 get_netbsd_elfcore_note_type (Filedata
* filedata
, unsigned e_type
)
22553 static char buff
[64];
22557 case NT_NETBSDCORE_PROCINFO
:
22558 /* NetBSD core "procinfo" structure. */
22559 return _("NetBSD procinfo structure");
22561 case NT_NETBSDCORE_AUXV
:
22562 return _("NetBSD ELF auxiliary vector data");
22564 case NT_NETBSDCORE_LWPSTATUS
:
22565 return _("PT_LWPSTATUS (ptrace_lwpstatus structure)");
22568 /* As of Jan 2020 there are no other machine-independent notes
22569 defined for NetBSD core files. If the note type is less
22570 than the start of the machine-dependent note types, we don't
22573 if (e_type
< NT_NETBSDCORE_FIRSTMACH
)
22575 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
22581 switch (filedata
->file_header
.e_machine
)
22583 /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0
22584 and PT_GETFPREGS == mach+2. */
22589 case EM_SPARC32PLUS
:
22593 case NT_NETBSDCORE_FIRSTMACH
+ 0:
22594 return _("PT_GETREGS (reg structure)");
22595 case NT_NETBSDCORE_FIRSTMACH
+ 2:
22596 return _("PT_GETFPREGS (fpreg structure)");
22602 /* On SuperH, PT_GETREGS == mach+3 and PT_GETFPREGS == mach+5.
22603 There's also old PT___GETREGS40 == mach + 1 for old reg
22604 structure which lacks GBR. */
22608 case NT_NETBSDCORE_FIRSTMACH
+ 1:
22609 return _("PT___GETREGS40 (old reg structure)");
22610 case NT_NETBSDCORE_FIRSTMACH
+ 3:
22611 return _("PT_GETREGS (reg structure)");
22612 case NT_NETBSDCORE_FIRSTMACH
+ 5:
22613 return _("PT_GETFPREGS (fpreg structure)");
22619 /* On all other arch's, PT_GETREGS == mach+1 and
22620 PT_GETFPREGS == mach+3. */
22624 case NT_NETBSDCORE_FIRSTMACH
+ 1:
22625 return _("PT_GETREGS (reg structure)");
22626 case NT_NETBSDCORE_FIRSTMACH
+ 3:
22627 return _("PT_GETFPREGS (fpreg structure)");
22633 snprintf (buff
, sizeof (buff
), "PT_FIRSTMACH+%d",
22634 e_type
- NT_NETBSDCORE_FIRSTMACH
);
22638 static const char *
22639 get_openbsd_elfcore_note_type (Filedata
* filedata
, unsigned e_type
)
22643 case NT_OPENBSD_PROCINFO
:
22644 return _("OpenBSD procinfo structure");
22645 case NT_OPENBSD_AUXV
:
22646 return _("OpenBSD ELF auxiliary vector data");
22647 case NT_OPENBSD_REGS
:
22648 return _("OpenBSD regular registers");
22649 case NT_OPENBSD_FPREGS
:
22650 return _("OpenBSD floating point registers");
22651 case NT_OPENBSD_WCOOKIE
:
22652 return _("OpenBSD window cookie");
22655 return get_note_type (filedata
, e_type
);
22658 static const char *
22659 get_qnx_elfcore_note_type (Filedata
* filedata
, unsigned e_type
)
22663 case QNT_DEBUG_FULLPATH
:
22664 return _("QNX debug fullpath");
22665 case QNT_DEBUG_RELOC
:
22666 return _("QNX debug relocation");
22668 return _("QNX stack");
22669 case QNT_GENERATOR
:
22670 return _("QNX generator");
22671 case QNT_DEFAULT_LIB
:
22672 return _("QNX default library");
22673 case QNT_CORE_SYSINFO
:
22674 return _("QNX core sysinfo");
22675 case QNT_CORE_INFO
:
22676 return _("QNX core info");
22677 case QNT_CORE_STATUS
:
22678 return _("QNX core status");
22679 case QNT_CORE_GREG
:
22680 return _("QNX general registers");
22681 case QNT_CORE_FPREG
:
22682 return _("QNX floating point registers");
22684 return _("QNX link map");
22687 return get_note_type (filedata
, e_type
);
22690 static const char *
22691 get_stapsdt_note_type (unsigned e_type
)
22693 static char buff
[64];
22698 return _("NT_STAPSDT (SystemTap probe descriptors)");
22704 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
22709 print_stapsdt_note (Elf_Internal_Note
*pnote
)
22711 size_t len
, maxlen
;
22712 size_t addr_size
= is_32bit_elf
? 4 : 8;
22713 char *data
= pnote
->descdata
;
22714 char *data_end
= pnote
->descdata
+ pnote
->descsz
;
22715 uint64_t pc
, base_addr
, semaphore
;
22716 char *provider
, *probe
, *arg_fmt
;
22718 if (pnote
->descsz
< (addr_size
* 3))
22719 goto stapdt_note_too_small
;
22721 pc
= byte_get ((unsigned char *) data
, addr_size
);
22724 base_addr
= byte_get ((unsigned char *) data
, addr_size
);
22727 semaphore
= byte_get ((unsigned char *) data
, addr_size
);
22730 if (data
>= data_end
)
22731 goto stapdt_note_too_small
;
22732 maxlen
= data_end
- data
;
22733 len
= strnlen (data
, maxlen
);
22740 goto stapdt_note_too_small
;
22742 if (data
>= data_end
)
22743 goto stapdt_note_too_small
;
22744 maxlen
= data_end
- data
;
22745 len
= strnlen (data
, maxlen
);
22752 goto stapdt_note_too_small
;
22754 if (data
>= data_end
)
22755 goto stapdt_note_too_small
;
22756 maxlen
= data_end
- data
;
22757 len
= strnlen (data
, maxlen
);
22764 goto stapdt_note_too_small
;
22766 printf (_(" Provider: %s\n"), provider
);
22767 printf (_(" Name: %s\n"), probe
);
22768 printf (_(" Location: "));
22769 print_vma (pc
, FULL_HEX
);
22770 printf (_(", Base: "));
22771 print_vma (base_addr
, FULL_HEX
);
22772 printf (_(", Semaphore: "));
22773 print_vma (semaphore
, FULL_HEX
);
22775 printf (_(" Arguments: %s\n"), arg_fmt
);
22777 return data
== data_end
;
22779 stapdt_note_too_small
:
22780 printf (_(" <corrupt - note is too small>\n"));
22781 error (_("corrupt stapdt note - the data size is too small\n"));
22786 print_fdo_note (Elf_Internal_Note
* pnote
)
22788 if (pnote
->descsz
> 0 && pnote
->type
== FDO_PACKAGING_METADATA
)
22790 printf (_(" Packaging Metadata: %.*s\n"), (int) pnote
->descsz
, pnote
->descdata
);
22793 if (pnote
->descsz
> 0 && pnote
->type
== FDO_DLOPEN_METADATA
)
22795 printf (_(" Dlopen Metadata: %.*s\n"), (int) pnote
->descsz
, pnote
->descdata
);
22801 static const char *
22802 get_ia64_vms_note_type (unsigned e_type
)
22804 static char buff
[64];
22809 return _("NT_VMS_MHD (module header)");
22811 return _("NT_VMS_LNM (language name)");
22813 return _("NT_VMS_SRC (source files)");
22815 return "NT_VMS_TITLE";
22817 return _("NT_VMS_EIDC (consistency check)");
22818 case NT_VMS_FPMODE
:
22819 return _("NT_VMS_FPMODE (FP mode)");
22820 case NT_VMS_LINKTIME
:
22821 return "NT_VMS_LINKTIME";
22822 case NT_VMS_IMGNAM
:
22823 return _("NT_VMS_IMGNAM (image name)");
22825 return _("NT_VMS_IMGID (image id)");
22826 case NT_VMS_LINKID
:
22827 return _("NT_VMS_LINKID (link id)");
22828 case NT_VMS_IMGBID
:
22829 return _("NT_VMS_IMGBID (build id)");
22830 case NT_VMS_GSTNAM
:
22831 return _("NT_VMS_GSTNAM (sym table name)");
22832 case NT_VMS_ORIG_DYN
:
22833 return "NT_VMS_ORIG_DYN";
22834 case NT_VMS_PATCHTIME
:
22835 return "NT_VMS_PATCHTIME";
22837 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
22843 print_ia64_vms_note (Elf_Internal_Note
* pnote
)
22845 unsigned int maxlen
= pnote
->descsz
;
22847 if (maxlen
< 2 || maxlen
!= pnote
->descsz
)
22848 goto desc_size_fail
;
22850 switch (pnote
->type
)
22854 goto desc_size_fail
;
22856 size_t l
= strnlen (pnote
->descdata
+ 34, maxlen
- 34);
22858 printf (_(" Creation date : %.17s\n"), pnote
->descdata
);
22859 printf (_(" Last patch date: %.17s\n"), pnote
->descdata
+ 17);
22860 if (l
+ 34 < maxlen
)
22862 printf (_(" Module name : %s\n"), pnote
->descdata
+ 34);
22863 if (l
+ 35 < maxlen
)
22864 printf (_(" Module version : %s\n"), pnote
->descdata
+ 34 + l
+ 1);
22866 printf (_(" Module version : <missing>\n"));
22870 printf (_(" Module name : <missing>\n"));
22871 printf (_(" Module version : <missing>\n"));
22876 printf (_(" Language: %.*s\n"), maxlen
, pnote
->descdata
);
22879 case NT_VMS_FPMODE
:
22880 printf (_(" Floating Point mode: "));
22882 goto desc_size_fail
;
22883 /* FIXME: Generate an error if descsz > 8 ? */
22885 printf ("0x%016" PRIx64
"\n",
22886 byte_get ((unsigned char *) pnote
->descdata
, 8));
22889 case NT_VMS_LINKTIME
:
22890 printf (_(" Link time: "));
22892 goto desc_size_fail
;
22893 /* FIXME: Generate an error if descsz > 8 ? */
22895 print_vms_time (byte_get ((unsigned char *) pnote
->descdata
, 8));
22899 case NT_VMS_PATCHTIME
:
22900 printf (_(" Patch time: "));
22902 goto desc_size_fail
;
22903 /* FIXME: Generate an error if descsz > 8 ? */
22905 print_vms_time (byte_get ((unsigned char *) pnote
->descdata
, 8));
22909 case NT_VMS_ORIG_DYN
:
22911 goto desc_size_fail
;
22913 printf (_(" Major id: %u, minor id: %u\n"),
22914 (unsigned) byte_get ((unsigned char *) pnote
->descdata
, 4),
22915 (unsigned) byte_get ((unsigned char *) pnote
->descdata
+ 4, 4));
22916 printf (_(" Last modified : "));
22917 print_vms_time (byte_get ((unsigned char *) pnote
->descdata
+ 8, 8));
22918 printf (_("\n Link flags : "));
22919 printf ("0x%016" PRIx64
"\n",
22920 byte_get ((unsigned char *) pnote
->descdata
+ 16, 8));
22921 printf (_(" Header flags: 0x%08x\n"),
22922 (unsigned) byte_get ((unsigned char *) pnote
->descdata
+ 24, 4));
22923 printf (_(" Image id : %.*s\n"), maxlen
- 32, pnote
->descdata
+ 32);
22926 case NT_VMS_IMGNAM
:
22927 printf (_(" Image name: %.*s\n"), maxlen
, pnote
->descdata
);
22930 case NT_VMS_GSTNAM
:
22931 printf (_(" Global symbol table name: %.*s\n"), maxlen
, pnote
->descdata
);
22935 printf (_(" Image id: %.*s\n"), maxlen
, pnote
->descdata
);
22938 case NT_VMS_LINKID
:
22939 printf (_(" Linker id: %.*s\n"), maxlen
, pnote
->descdata
);
22949 printf (_(" <corrupt - data size is too small>\n"));
22950 error (_("corrupt IA64 note: data size is too small\n"));
22954 struct build_attr_cache
{
22955 Filedata
*filedata
;
22957 uint64_t strtablen
;
22958 Elf_Internal_Sym
*symtab
;
22962 /* Find the symbol associated with a build attribute that is attached
22963 to address OFFSET. If PNAME is non-NULL then store the name of
22964 the symbol (if found) in the provided pointer, Returns NULL if a
22965 symbol could not be found. */
22967 static Elf_Internal_Sym
*
22968 get_symbol_for_build_attribute (Filedata
*filedata
,
22971 const char **pname
)
22973 Elf_Internal_Sym
*saved_sym
= NULL
;
22974 Elf_Internal_Sym
*sym
;
22976 if (filedata
->section_headers
!= NULL
22977 && (ba_cache
.filedata
== NULL
|| filedata
!= ba_cache
.filedata
))
22979 Elf_Internal_Shdr
* symsec
;
22981 free (ba_cache
.strtab
);
22982 ba_cache
.strtab
= NULL
;
22983 free (ba_cache
.symtab
);
22984 ba_cache
.symtab
= NULL
;
22986 /* Load the symbol and string sections. */
22987 for (symsec
= filedata
->section_headers
;
22988 symsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
22991 if (symsec
->sh_type
== SHT_SYMTAB
22992 && get_symtab (filedata
, symsec
,
22993 &ba_cache
.symtab
, &ba_cache
.nsyms
,
22994 &ba_cache
.strtab
, &ba_cache
.strtablen
))
22997 ba_cache
.filedata
= filedata
;
23000 if (ba_cache
.symtab
== NULL
)
23003 /* Find a symbol whose value matches offset. */
23004 for (sym
= ba_cache
.symtab
; sym
< ba_cache
.symtab
+ ba_cache
.nsyms
; sym
++)
23005 if (sym
->st_value
== offset
)
23007 if (sym
->st_name
>= ba_cache
.strtablen
)
23008 /* Huh ? This should not happen. */
23011 if (ba_cache
.strtab
[sym
->st_name
] == 0)
23014 /* The AArch64, ARM and RISC-V architectures define mapping symbols
23015 (eg $d, $x, $t) which we want to ignore. */
23016 if (ba_cache
.strtab
[sym
->st_name
] == '$'
23017 && ba_cache
.strtab
[sym
->st_name
+ 1] != 0
23018 && ba_cache
.strtab
[sym
->st_name
+ 2] == 0)
23023 /* For OPEN attributes we prefer GLOBAL over LOCAL symbols
23024 and FILE or OBJECT symbols over NOTYPE symbols. We skip
23025 FUNC symbols entirely. */
23026 switch (ELF_ST_TYPE (sym
->st_info
))
23033 /* If the symbol has a size associated
23034 with it then we can stop searching. */
23035 sym
= ba_cache
.symtab
+ ba_cache
.nsyms
;
23040 /* Ignore function symbols. */
23047 switch (ELF_ST_BIND (sym
->st_info
))
23050 if (saved_sym
== NULL
23051 || ELF_ST_TYPE (saved_sym
->st_info
) != STT_OBJECT
)
23056 if (saved_sym
== NULL
)
23066 if (ELF_ST_TYPE (sym
->st_info
) != STT_FUNC
)
23074 if (saved_sym
&& pname
)
23075 * pname
= ba_cache
.strtab
+ saved_sym
->st_name
;
23080 /* Returns true iff addr1 and addr2 are in the same section. */
23083 same_section (Filedata
* filedata
, uint64_t addr1
, uint64_t addr2
)
23085 Elf_Internal_Shdr
* a1
;
23086 Elf_Internal_Shdr
* a2
;
23088 a1
= find_section_by_address (filedata
, addr1
);
23089 a2
= find_section_by_address (filedata
, addr2
);
23091 return a1
== a2
&& a1
!= NULL
;
23095 print_gnu_build_attribute_description (Elf_Internal_Note
* pnote
,
23096 Filedata
* filedata
)
23098 static uint64_t global_offset
= 0;
23099 static uint64_t global_end
= 0;
23100 static uint64_t func_offset
= 0;
23101 static uint64_t func_end
= 0;
23103 Elf_Internal_Sym
*sym
;
23107 bool is_open_attr
= pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_OPEN
;
23109 switch (pnote
->descsz
)
23112 /* A zero-length description means that the range of
23113 the previous note of the same type should be used. */
23116 if (global_end
> global_offset
)
23117 printf (_(" Applies to region from %#" PRIx64
23118 " to %#" PRIx64
"\n"), global_offset
, global_end
);
23120 printf (_(" Applies to region from %#" PRIx64
23121 "\n"), global_offset
);
23125 if (func_end
> func_offset
)
23126 printf (_(" Applies to region from %#" PRIx64
23127 " to %#" PRIx64
"\n"), func_offset
, func_end
);
23129 printf (_(" Applies to region from %#" PRIx64
23130 "\n"), func_offset
);
23135 start
= byte_get ((unsigned char *) pnote
->descdata
, 4);
23140 start
= byte_get ((unsigned char *) pnote
->descdata
, 4);
23141 end
= byte_get ((unsigned char *) pnote
->descdata
+ 4, 4);
23145 start
= byte_get ((unsigned char *) pnote
->descdata
, 8);
23146 end
= byte_get ((unsigned char *) pnote
->descdata
+ 8, 8);
23150 error (_(" <invalid description size: %lx>\n"), pnote
->descsz
);
23151 printf (_(" <invalid descsz>"));
23156 sym
= get_symbol_for_build_attribute (filedata
, start
, is_open_attr
, & name
);
23157 /* As of version 5 of the annobin plugin, filename symbols are biased by 2
23158 in order to avoid them being confused with the start address of the
23159 first function in the file... */
23160 if (sym
== NULL
&& is_open_attr
)
23161 sym
= get_symbol_for_build_attribute (filedata
, start
+ 2, is_open_attr
,
23164 if (end
== 0 && sym
!= NULL
&& sym
->st_size
> 0)
23165 end
= start
+ sym
->st_size
;
23169 /* FIXME: Need to properly allow for section alignment.
23170 16 is just the alignment used on x86_64. */
23172 && start
> BFD_ALIGN (global_end
, 16)
23173 /* Build notes are not guaranteed to be organised in order of
23174 increasing address, but we should find the all of the notes
23175 for one section in the same place. */
23176 && same_section (filedata
, start
, global_end
))
23177 warn (_("Gap in build notes detected from %#" PRIx64
23178 " to %#" PRIx64
"\n"),
23179 global_end
+ 1, start
- 1);
23181 printf (_(" Applies to region from %#" PRIx64
), start
);
23182 global_offset
= start
;
23186 printf (_(" to %#" PRIx64
), end
);
23192 printf (_(" Applies to region from %#" PRIx64
), start
);
23193 func_offset
= start
;
23197 printf (_(" to %#" PRIx64
), end
);
23203 printf (_(" (%s)"), name
);
23210 print_gnu_build_attribute_name (Elf_Internal_Note
* pnote
)
23212 static const char string_expected
[2] = { GNU_BUILD_ATTRIBUTE_TYPE_STRING
, 0 };
23213 static const char number_expected
[2] = { GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC
, 0 };
23214 static const char bool_expected
[3] = { GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE
, GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE
, 0 };
23216 char name_attribute
;
23217 const char * expected_types
;
23218 const char * name
= pnote
->namedata
;
23222 if (name
== NULL
|| pnote
->namesz
< 2)
23224 error (_("corrupt name field in GNU build attribute note: size = %ld\n"), pnote
->namesz
);
23225 print_symbol_name (-20, _(" <corrupt name>"));
23234 /* Version 2 of the spec adds a "GA" prefix to the name field. */
23235 if (name
[0] == 'G' && name
[1] == 'A')
23237 if (pnote
->namesz
< 4)
23239 error (_("corrupt name field in GNU build attribute note: size = %ld\n"), pnote
->namesz
);
23240 print_symbol_name (-20, _(" <corrupt name>"));
23249 switch ((name_type
= * name
))
23251 case GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC
:
23252 case GNU_BUILD_ATTRIBUTE_TYPE_STRING
:
23253 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE
:
23254 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE
:
23255 printf ("%c", * name
);
23259 error (_("unrecognised attribute type in name field: %d\n"), name_type
);
23260 print_symbol_name (-20, _("<unknown name type>"));
23267 switch ((name_attribute
= * name
))
23269 case GNU_BUILD_ATTRIBUTE_VERSION
:
23270 text
= _("<version>");
23271 expected_types
= string_expected
;
23274 case GNU_BUILD_ATTRIBUTE_STACK_PROT
:
23275 text
= _("<stack prot>");
23276 expected_types
= "!+*";
23279 case GNU_BUILD_ATTRIBUTE_RELRO
:
23280 text
= _("<relro>");
23281 expected_types
= bool_expected
;
23284 case GNU_BUILD_ATTRIBUTE_STACK_SIZE
:
23285 text
= _("<stack size>");
23286 expected_types
= number_expected
;
23289 case GNU_BUILD_ATTRIBUTE_TOOL
:
23290 text
= _("<tool>");
23291 expected_types
= string_expected
;
23294 case GNU_BUILD_ATTRIBUTE_ABI
:
23296 expected_types
= "$*";
23299 case GNU_BUILD_ATTRIBUTE_PIC
:
23301 expected_types
= number_expected
;
23304 case GNU_BUILD_ATTRIBUTE_SHORT_ENUM
:
23305 text
= _("<short enum>");
23306 expected_types
= bool_expected
;
23310 if (ISPRINT (* name
))
23312 int len
= strnlen (name
, pnote
->namesz
- (name
- pnote
->namedata
)) + 1;
23314 if (len
> left
&& ! do_wide
)
23316 printf ("%.*s:", len
, name
);
23322 static char tmpbuf
[128];
23324 error (_("unrecognised byte in name field: %d\n"), * name
);
23325 sprintf (tmpbuf
, _("<unknown:_%d>"), * name
);
23329 expected_types
= "*$!+";
23334 left
-= printf ("%s", text
);
23336 if (strchr (expected_types
, name_type
) == NULL
)
23337 warn (_("attribute does not have an expected type (%c)\n"), name_type
);
23339 if ((size_t) (name
- pnote
->namedata
) > pnote
->namesz
)
23341 error (_("corrupt name field: namesz: %lu but parsing gets to %td\n"),
23343 name
- pnote
->namedata
);
23347 if (left
< 1 && ! do_wide
)
23352 case GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC
:
23354 unsigned int bytes
;
23356 unsigned int shift
= 0;
23357 char *decoded
= NULL
;
23359 bytes
= pnote
->namesz
- (name
- pnote
->namedata
);
23361 /* The -1 is because the name field is always 0 terminated, and we
23362 want to be able to ensure that the shift in the while loop below
23363 will not overflow. */
23366 if (bytes
> sizeof (val
))
23368 error (_("corrupt numeric name field: too many bytes in the value: %x\n"),
23370 bytes
= sizeof (val
);
23372 /* We do not bother to warn if bytes == 0 as this can
23373 happen with some early versions of the gcc plugin. */
23377 uint64_t byte
= *name
++ & 0xff;
23379 val
|= byte
<< shift
;
23383 switch (name_attribute
)
23385 case GNU_BUILD_ATTRIBUTE_PIC
:
23388 case 0: decoded
= "static"; break;
23389 case 1: decoded
= "pic"; break;
23390 case 2: decoded
= "PIC"; break;
23391 case 3: decoded
= "pie"; break;
23392 case 4: decoded
= "PIE"; break;
23396 case GNU_BUILD_ATTRIBUTE_STACK_PROT
:
23399 /* Based upon the SPCT_FLAG_xxx enum values in gcc/cfgexpand.c. */
23400 case 0: decoded
= "off"; break;
23401 case 1: decoded
= "on"; break;
23402 case 2: decoded
= "all"; break;
23403 case 3: decoded
= "strong"; break;
23404 case 4: decoded
= "explicit"; break;
23412 if (decoded
!= NULL
)
23414 print_symbol_name (-left
, decoded
);
23425 left
-= printf ("0x%" PRIx64
, val
);
23427 left
-= printf ("0x%-.*" PRIx64
, left
, val
);
23431 case GNU_BUILD_ATTRIBUTE_TYPE_STRING
:
23432 left
-= print_symbol_name (- left
, name
);
23434 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE
:
23435 left
-= print_symbol_name (- left
, "true");
23437 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE
:
23438 left
-= print_symbol_name (- left
, "false");
23442 if (do_wide
&& left
> 0)
23443 printf ("%-*s", left
, " ");
23448 /* Print the contents of PNOTE as hex. */
23451 print_note_contents_hex (Elf_Internal_Note
*pnote
)
23457 printf (_(" description data: "));
23458 for (i
= 0; i
< pnote
->descsz
; i
++)
23459 printf ("%02x ", pnote
->descdata
[i
] & 0xff);
23468 #if defined HAVE_MSGPACK
23471 print_indents (int n
)
23475 for (int i
= 0; i
< n
; i
++)
23479 /* Print OBJ in human-readable form. */
23482 dump_msgpack_obj (const msgpack_object
*obj
, int indent
)
23486 case MSGPACK_OBJECT_NIL
:
23490 case MSGPACK_OBJECT_BOOLEAN
:
23491 printf ("%s", obj
->via
.boolean
? "true" : "false");
23494 case MSGPACK_OBJECT_POSITIVE_INTEGER
:
23495 printf ("%" PRIu64
, obj
->via
.u64
);
23498 case MSGPACK_OBJECT_NEGATIVE_INTEGER
:
23499 printf ("%" PRIi64
, obj
->via
.i64
);
23502 case MSGPACK_OBJECT_FLOAT32
:
23503 case MSGPACK_OBJECT_FLOAT64
:
23504 printf ("%f", obj
->via
.f64
);
23507 case MSGPACK_OBJECT_STR
:
23508 printf ("\"%.*s\"", obj
->via
.str
.size
, obj
->via
.str
.ptr
);
23511 case MSGPACK_OBJECT_ARRAY
:
23513 const msgpack_object_array
*array
= &obj
->via
.array
;
23518 for (uint32_t i
= 0; i
< array
->size
; ++i
)
23520 const msgpack_object
*item
= &array
->ptr
[i
];
23522 print_indents (indent
);
23523 dump_msgpack_obj (item
, indent
);
23528 print_indents (indent
);
23534 case MSGPACK_OBJECT_MAP
:
23536 const msgpack_object_map
*map
= &obj
->via
.map
;
23541 for (uint32_t i
= 0; i
< map
->size
; ++i
)
23543 const msgpack_object_kv
*kv
= &map
->ptr
[i
];
23544 const msgpack_object
*key
= &kv
->key
;
23545 const msgpack_object
*val
= &kv
->val
;
23547 print_indents (indent
);
23548 dump_msgpack_obj (key
, indent
);
23550 dump_msgpack_obj (val
, indent
);
23556 print_indents (indent
);
23562 case MSGPACK_OBJECT_BIN
:
23566 case MSGPACK_OBJECT_EXT
:
23573 dump_msgpack (const msgpack_unpacked
*msg
)
23576 dump_msgpack_obj (&msg
->data
, 0);
23580 #endif /* defined HAVE_MSGPACK */
23583 print_amdgpu_note (Elf_Internal_Note
*pnote
)
23585 #if defined HAVE_MSGPACK
23586 /* If msgpack is available, decode and dump the note's content. */
23588 msgpack_unpacked msg
;
23589 msgpack_unpack_return msgpack_ret
;
23591 assert (pnote
->type
== NT_AMDGPU_METADATA
);
23593 msgpack_unpacked_init (&msg
);
23594 msgpack_ret
= msgpack_unpack_next (&msg
, pnote
->descdata
, pnote
->descsz
,
23597 switch (msgpack_ret
)
23599 case MSGPACK_UNPACK_SUCCESS
:
23600 dump_msgpack (&msg
);
23605 error (_("failed to unpack msgpack contents in NT_AMDGPU_METADATA note"));
23610 msgpack_unpacked_destroy (&msg
);
23613 /* msgpack is not available, dump contents as hex. */
23614 print_note_contents_hex (pnote
);
23620 print_qnx_note (Elf_Internal_Note
*pnote
)
23622 switch (pnote
->type
)
23625 if (pnote
->descsz
!= 12)
23626 goto desc_size_fail
;
23628 printf (_(" Stack Size: 0x%" PRIx32
"\n"),
23629 (unsigned) byte_get ((unsigned char *) pnote
->descdata
, 4));
23630 printf (_(" Stack allocated: %" PRIx32
"\n"),
23631 (unsigned) byte_get ((unsigned char *) pnote
->descdata
+ 4, 4));
23632 printf (_(" Executable: %s\n"),
23633 ((unsigned) byte_get ((unsigned char *) pnote
->descdata
+ 8, 1)) ? "no": "yes");
23637 print_note_contents_hex(pnote
);
23642 printf (_(" <corrupt - data size is too small>\n"));
23643 error (_("corrupt QNX note: data size is too small\n"));
23648 /* Note that by the ELF standard, the name field is already null byte
23649 terminated, and namesz includes the terminating null byte.
23650 I.E. the value of namesz for the name "FSF" is 4.
23652 If the value of namesz is zero, there is no name present. */
23655 process_note (Elf_Internal_Note
* pnote
,
23656 Filedata
* filedata
)
23658 const char * name
= pnote
->namesz
? pnote
->namedata
: "(NONE)";
23661 if (pnote
->namesz
== 0)
23662 /* If there is no note name, then use the default set of
23663 note type strings. */
23664 nt
= get_note_type (filedata
, pnote
->type
);
23666 else if (startswith (pnote
->namedata
, "GNU"))
23667 /* GNU-specific object file notes. */
23668 nt
= get_gnu_elf_note_type (pnote
->type
);
23670 else if (startswith (pnote
->namedata
, "AMDGPU"))
23671 /* AMDGPU-specific object file notes. */
23672 nt
= get_amdgpu_elf_note_type (pnote
->type
);
23674 else if (startswith (pnote
->namedata
, "FreeBSD"))
23675 /* FreeBSD-specific core file notes. */
23676 nt
= get_freebsd_elfcore_note_type (filedata
, pnote
->type
);
23678 else if (startswith (pnote
->namedata
, "NetBSD-CORE"))
23679 /* NetBSD-specific core file notes. */
23680 nt
= get_netbsd_elfcore_note_type (filedata
, pnote
->type
);
23682 else if (startswith (pnote
->namedata
, "NetBSD"))
23683 /* NetBSD-specific core file notes. */
23684 return process_netbsd_elf_note (pnote
);
23686 else if (startswith (pnote
->namedata
, "PaX"))
23687 /* NetBSD-specific core file notes. */
23688 return process_netbsd_elf_note (pnote
);
23690 else if (startswith (pnote
->namedata
, "OpenBSD"))
23691 /* OpenBSD-specific core file notes. */
23692 nt
= get_openbsd_elfcore_note_type (filedata
, pnote
->type
);
23694 else if (startswith (pnote
->namedata
, "QNX"))
23695 /* QNX-specific core file notes. */
23696 nt
= get_qnx_elfcore_note_type (filedata
, pnote
->type
);
23698 else if (startswith (pnote
->namedata
, "SPU/"))
23700 /* SPU-specific core file notes. */
23701 nt
= pnote
->namedata
+ 4;
23705 else if (startswith (pnote
->namedata
, "IPF/VMS"))
23706 /* VMS/ia64-specific file notes. */
23707 nt
= get_ia64_vms_note_type (pnote
->type
);
23709 else if (startswith (pnote
->namedata
, "stapsdt"))
23710 nt
= get_stapsdt_note_type (pnote
->type
);
23713 /* Don't recognize this note name; just use the default set of
23714 note type strings. */
23715 nt
= get_note_type (filedata
, pnote
->type
);
23719 if (((startswith (pnote
->namedata
, "GA")
23720 && strchr ("*$!+", pnote
->namedata
[2]) != NULL
)
23721 || strchr ("*$!+", pnote
->namedata
[0]) != NULL
)
23722 && (pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_OPEN
23723 || pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_FUNC
))
23724 print_gnu_build_attribute_name (pnote
);
23726 print_symbol_name (-20, name
);
23729 printf (" 0x%08lx\t%s\t", pnote
->descsz
, nt
);
23731 printf (" 0x%08lx\t%s\n", pnote
->descsz
, nt
);
23733 if (startswith (pnote
->namedata
, "IPF/VMS"))
23734 return print_ia64_vms_note (pnote
);
23735 else if (startswith (pnote
->namedata
, "GNU"))
23736 return print_gnu_note (filedata
, pnote
);
23737 else if (startswith (pnote
->namedata
, "stapsdt"))
23738 return print_stapsdt_note (pnote
);
23739 else if (startswith (pnote
->namedata
, "CORE"))
23740 return print_core_note (pnote
);
23741 else if (startswith (pnote
->namedata
, "FDO"))
23742 return print_fdo_note (pnote
);
23743 else if (((startswith (pnote
->namedata
, "GA")
23744 && strchr ("*$!+", pnote
->namedata
[2]) != NULL
)
23745 || strchr ("*$!+", pnote
->namedata
[0]) != NULL
)
23746 && (pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_OPEN
23747 || pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_FUNC
))
23748 return print_gnu_build_attribute_description (pnote
, filedata
);
23749 else if (startswith (pnote
->namedata
, "AMDGPU")
23750 && pnote
->type
== NT_AMDGPU_METADATA
)
23751 return print_amdgpu_note (pnote
);
23752 else if (startswith (pnote
->namedata
, "QNX"))
23753 return print_qnx_note (pnote
);
23755 print_note_contents_hex (pnote
);
23760 process_notes_at (Filedata
* filedata
,
23761 Elf_Internal_Shdr
* section
,
23766 Elf_External_Note
*pnotes
;
23767 Elf_External_Note
*external
;
23776 pnotes
= (Elf_External_Note
*) get_section_contents (section
, filedata
);
23779 if (! apply_relocations (filedata
, section
, (unsigned char *) pnotes
, length
, NULL
, NULL
))
23787 pnotes
= (Elf_External_Note
*) get_data (NULL
, filedata
, offset
, 1, length
,
23790 if (pnotes
== NULL
)
23795 if (filedata
->is_separate
)
23796 printf (_("In linked file '%s': "), filedata
->file_name
);
23800 printf (_("Displaying notes found in: %s\n"), printable_section_name (filedata
, section
));
23802 printf (_("Displaying notes found at file offset 0x%08" PRIx64
23803 " with length 0x%08" PRIx64
":\n"),
23806 /* NB: Some note sections may have alignment value of 0 or 1. gABI
23807 specifies that notes should be aligned to 4 bytes in 32-bit
23808 objects and to 8 bytes in 64-bit objects. As a Linux extension,
23809 we also support 4 byte alignment in 64-bit objects. If section
23810 alignment is less than 4, we treate alignment as 4 bytes. */
23813 else if (align
!= 4 && align
!= 8)
23815 warn (_("Corrupt note: alignment %" PRId64
", expecting 4 or 8\n"),
23821 printf (_(" %-20s %-10s\tDescription\n"), _("Owner"), _("Data size"));
23823 end
= (char *) pnotes
+ length
;
23824 while ((char *) external
< end
)
23826 Elf_Internal_Note inote
;
23829 char * temp
= NULL
;
23830 size_t data_remaining
= end
- (char *) external
;
23832 if (!is_ia64_vms (filedata
))
23834 /* PR binutils/15191
23835 Make sure that there is enough data to read. */
23836 min_notesz
= offsetof (Elf_External_Note
, name
);
23837 if (data_remaining
< min_notesz
)
23839 warn (ngettext ("Corrupt note: only %zd byte remains, "
23840 "not enough for a full note\n",
23841 "Corrupt note: only %zd bytes remain, "
23842 "not enough for a full note\n",
23847 data_remaining
-= min_notesz
;
23849 inote
.type
= BYTE_GET (external
->type
);
23850 inote
.namesz
= BYTE_GET (external
->namesz
);
23851 inote
.namedata
= external
->name
;
23852 inote
.descsz
= BYTE_GET (external
->descsz
);
23853 inote
.descdata
= ((char *) external
23854 + ELF_NOTE_DESC_OFFSET (inote
.namesz
, align
));
23855 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
23856 next
= ((char *) external
23857 + ELF_NOTE_NEXT_OFFSET (inote
.namesz
, inote
.descsz
, align
));
23861 Elf64_External_VMS_Note
*vms_external
;
23863 /* PR binutils/15191
23864 Make sure that there is enough data to read. */
23865 min_notesz
= offsetof (Elf64_External_VMS_Note
, name
);
23866 if (data_remaining
< min_notesz
)
23868 warn (ngettext ("Corrupt note: only %zd byte remains, "
23869 "not enough for a full note\n",
23870 "Corrupt note: only %zd bytes remain, "
23871 "not enough for a full note\n",
23876 data_remaining
-= min_notesz
;
23878 vms_external
= (Elf64_External_VMS_Note
*) external
;
23879 inote
.type
= BYTE_GET (vms_external
->type
);
23880 inote
.namesz
= BYTE_GET (vms_external
->namesz
);
23881 inote
.namedata
= vms_external
->name
;
23882 inote
.descsz
= BYTE_GET (vms_external
->descsz
);
23883 inote
.descdata
= inote
.namedata
+ align_power (inote
.namesz
, 3);
23884 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
23885 next
= inote
.descdata
+ align_power (inote
.descsz
, 3);
23888 /* PR 17531: file: 3443835e. */
23889 /* PR 17531: file: id:000000,sig:11,src:006986,op:havoc,rep:4. */
23890 if ((size_t) (inote
.descdata
- inote
.namedata
) < inote
.namesz
23891 || (size_t) (inote
.descdata
- inote
.namedata
) > data_remaining
23892 || (size_t) (next
- inote
.descdata
) < inote
.descsz
23893 || ((size_t) (next
- inote
.descdata
)
23894 > data_remaining
- (size_t) (inote
.descdata
- inote
.namedata
)))
23896 warn (_("note with invalid namesz and/or descsz found at offset %#tx\n"),
23897 (char *) external
- (char *) pnotes
);
23898 warn (_(" type: %#lx, namesize: %#lx, descsize: %#lx, alignment: %u\n"),
23899 inote
.type
, inote
.namesz
, inote
.descsz
, (int) align
);
23903 external
= (Elf_External_Note
*) next
;
23905 /* Verify that name is null terminated. It appears that at least
23906 one version of Linux (RedHat 6.0) generates corefiles that don't
23907 comply with the ELF spec by failing to include the null byte in
23909 if (inote
.namesz
> 0 && inote
.namedata
[inote
.namesz
- 1] != '\0')
23911 if ((size_t) (inote
.descdata
- inote
.namedata
) == inote
.namesz
)
23913 temp
= (char *) malloc (inote
.namesz
+ 1);
23916 error (_("Out of memory allocating space for inote name\n"));
23921 memcpy (temp
, inote
.namedata
, inote
.namesz
);
23922 inote
.namedata
= temp
;
23924 inote
.namedata
[inote
.namesz
] = 0;
23927 if (! process_note (& inote
, filedata
))
23940 process_corefile_note_segments (Filedata
* filedata
)
23942 Elf_Internal_Phdr
*segment
;
23946 if (! get_program_headers (filedata
))
23949 for (i
= 0, segment
= filedata
->program_headers
;
23950 i
< filedata
->file_header
.e_phnum
;
23953 if (segment
->p_type
== PT_NOTE
)
23954 if (! process_notes_at (filedata
, NULL
, segment
->p_offset
,
23955 segment
->p_filesz
, segment
->p_align
))
23963 process_v850_notes (Filedata
* filedata
, uint64_t offset
, uint64_t length
)
23965 Elf_External_Note
* pnotes
;
23966 Elf_External_Note
* external
;
23973 pnotes
= (Elf_External_Note
*) get_data (NULL
, filedata
, offset
, 1, length
,
23975 if (pnotes
== NULL
)
23979 end
= (char*) pnotes
+ length
;
23981 printf (_("\nDisplaying contents of Renesas V850 notes section at offset"
23982 " %#" PRIx64
" with length %#" PRIx64
":\n"),
23985 while ((char *) external
< end
)
23988 Elf_Internal_Note inote
;
23989 size_t data_remaining
= end
- (char *) external
;
23991 if (data_remaining
< offsetof (Elf_External_Note
, name
))
23993 data_remaining
-= offsetof (Elf_External_Note
, name
);
23995 inote
.type
= BYTE_GET (external
->type
);
23996 inote
.namesz
= BYTE_GET (external
->namesz
);
23997 inote
.namedata
= external
->name
;
23998 inote
.descsz
= BYTE_GET (external
->descsz
);
23999 inote
.descdata
= inote
.namedata
+ align_power (inote
.namesz
, 2);
24000 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
24001 next
= inote
.descdata
+ align_power (inote
.descsz
, 2);
24003 if ((size_t) (inote
.descdata
- inote
.namedata
) < inote
.namesz
24004 || (size_t) (inote
.descdata
- inote
.namedata
) > data_remaining
24005 || (size_t) (next
- inote
.descdata
) < inote
.descsz
24006 || ((size_t) (next
- inote
.descdata
)
24007 > data_remaining
- (size_t) (inote
.descdata
- inote
.namedata
)))
24009 warn (_("note with invalid namesz and/or descsz found at offset %#tx\n"),
24010 (char *) external
- (char *) pnotes
);
24011 warn (_(" type: %#lx, namesize: %#lx, descsize: %#lx, alignment: %u\n"),
24012 inote
.type
, inote
.namesz
, inote
.descsz
, 2);
24016 external
= (Elf_External_Note
*) next
;
24018 if (! print_v850_note (& inote
))
24028 process_note_sections (Filedata
* filedata
)
24030 Elf_Internal_Shdr
*section
;
24032 unsigned int n
= 0;
24035 for (i
= 0, section
= filedata
->section_headers
;
24036 i
< filedata
->file_header
.e_shnum
&& section
!= NULL
;
24039 if (section
->sh_type
== SHT_NOTE
)
24041 if (! process_notes_at (filedata
, section
, section
->sh_offset
,
24042 section
->sh_size
, section
->sh_addralign
))
24047 if (( filedata
->file_header
.e_machine
== EM_V800
24048 || filedata
->file_header
.e_machine
== EM_V850
24049 || filedata
->file_header
.e_machine
== EM_CYGNUS_V850
)
24050 && section
->sh_type
== SHT_RENESAS_INFO
)
24052 if (! process_v850_notes (filedata
, section
->sh_offset
,
24060 /* Try processing NOTE segments instead. */
24061 return process_corefile_note_segments (filedata
);
24067 process_notes (Filedata
* filedata
)
24069 /* If we have not been asked to display the notes then do nothing. */
24073 if (filedata
->file_header
.e_type
!= ET_CORE
)
24074 return process_note_sections (filedata
);
24076 /* No program headers means no NOTE segment. */
24077 if (filedata
->file_header
.e_phnum
> 0)
24078 return process_corefile_note_segments (filedata
);
24080 if (filedata
->is_separate
)
24081 printf (_("No notes found in linked file '%s'.\n"),
24082 filedata
->file_name
);
24084 printf (_("No notes found file.\n"));
24089 static unsigned char *
24090 display_public_gnu_attributes (unsigned char * start
,
24091 const unsigned char * const end
)
24093 printf (_(" Unknown GNU attribute: %s\n"), start
);
24095 start
+= strnlen ((char *) start
, end
- start
);
24096 display_raw_attribute (start
, end
);
24098 return (unsigned char *) end
;
24101 static unsigned char *
24102 display_generic_attribute (unsigned char * start
,
24104 const unsigned char * const end
)
24107 return (unsigned char *) end
;
24109 return display_tag_value (tag
, start
, end
);
24113 process_arch_specific (Filedata
* filedata
)
24118 switch (filedata
->file_header
.e_machine
)
24121 case EM_ARC_COMPACT
:
24122 case EM_ARC_COMPACT2
:
24123 case EM_ARC_COMPACT3
:
24124 case EM_ARC_COMPACT3_64
:
24125 return process_attributes (filedata
, "ARC", SHT_ARC_ATTRIBUTES
,
24126 display_arc_attribute
,
24127 display_generic_attribute
);
24129 return process_attributes (filedata
, "aeabi", SHT_ARM_ATTRIBUTES
,
24130 display_arm_attribute
,
24131 display_generic_attribute
);
24134 case EM_MIPS_RS3_LE
:
24135 return process_mips_specific (filedata
, false);
24138 return process_attributes (filedata
, "mspabi", SHT_MSP430_ATTRIBUTES
,
24139 display_msp430_attribute
,
24140 display_msp430_gnu_attribute
);
24143 return process_attributes (filedata
, "riscv", SHT_RISCV_ATTRIBUTES
,
24144 display_riscv_attribute
,
24145 display_generic_attribute
);
24148 return process_nds32_specific (filedata
);
24151 return process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
24152 display_m68k_gnu_attribute
);
24156 return process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
24157 display_power_gnu_attribute
);
24161 return process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
24162 display_s390_gnu_attribute
);
24165 case EM_SPARC32PLUS
:
24167 return process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
24168 display_sparc_gnu_attribute
);
24171 return process_attributes (filedata
, "c6xabi", SHT_C6000_ATTRIBUTES
,
24172 display_tic6x_attribute
,
24173 display_generic_attribute
);
24176 return process_attributes (filedata
, "csky", SHT_CSKY_ATTRIBUTES
,
24177 display_csky_attribute
, NULL
);
24180 return process_attributes (filedata
, "gnu", SHT_GNU_ATTRIBUTES
,
24181 display_public_gnu_attributes
,
24182 display_generic_attribute
);
24187 get_file_header (Filedata
* filedata
)
24189 /* Read in the identity array. */
24190 if (fread (filedata
->file_header
.e_ident
, EI_NIDENT
, 1, filedata
->handle
) != 1)
24193 /* Determine how to read the rest of the header. */
24194 switch (filedata
->file_header
.e_ident
[EI_DATA
])
24199 byte_get
= byte_get_little_endian
;
24200 byte_put
= byte_put_little_endian
;
24203 byte_get
= byte_get_big_endian
;
24204 byte_put
= byte_put_big_endian
;
24208 /* For now we only support 32 bit and 64 bit ELF files. */
24209 is_32bit_elf
= (filedata
->file_header
.e_ident
[EI_CLASS
] != ELFCLASS64
);
24211 /* Read in the rest of the header. */
24214 Elf32_External_Ehdr ehdr32
;
24216 if (fread (ehdr32
.e_type
, sizeof (ehdr32
) - EI_NIDENT
, 1, filedata
->handle
) != 1)
24219 filedata
->file_header
.e_type
= BYTE_GET (ehdr32
.e_type
);
24220 filedata
->file_header
.e_machine
= BYTE_GET (ehdr32
.e_machine
);
24221 filedata
->file_header
.e_version
= BYTE_GET (ehdr32
.e_version
);
24222 filedata
->file_header
.e_entry
= BYTE_GET (ehdr32
.e_entry
);
24223 filedata
->file_header
.e_phoff
= BYTE_GET (ehdr32
.e_phoff
);
24224 filedata
->file_header
.e_shoff
= BYTE_GET (ehdr32
.e_shoff
);
24225 filedata
->file_header
.e_flags
= BYTE_GET (ehdr32
.e_flags
);
24226 filedata
->file_header
.e_ehsize
= BYTE_GET (ehdr32
.e_ehsize
);
24227 filedata
->file_header
.e_phentsize
= BYTE_GET (ehdr32
.e_phentsize
);
24228 filedata
->file_header
.e_phnum
= BYTE_GET (ehdr32
.e_phnum
);
24229 filedata
->file_header
.e_shentsize
= BYTE_GET (ehdr32
.e_shentsize
);
24230 filedata
->file_header
.e_shnum
= BYTE_GET (ehdr32
.e_shnum
);
24231 filedata
->file_header
.e_shstrndx
= BYTE_GET (ehdr32
.e_shstrndx
);
24235 Elf64_External_Ehdr ehdr64
;
24237 if (fread (ehdr64
.e_type
, sizeof (ehdr64
) - EI_NIDENT
, 1, filedata
->handle
) != 1)
24240 filedata
->file_header
.e_type
= BYTE_GET (ehdr64
.e_type
);
24241 filedata
->file_header
.e_machine
= BYTE_GET (ehdr64
.e_machine
);
24242 filedata
->file_header
.e_version
= BYTE_GET (ehdr64
.e_version
);
24243 filedata
->file_header
.e_entry
= BYTE_GET (ehdr64
.e_entry
);
24244 filedata
->file_header
.e_phoff
= BYTE_GET (ehdr64
.e_phoff
);
24245 filedata
->file_header
.e_shoff
= BYTE_GET (ehdr64
.e_shoff
);
24246 filedata
->file_header
.e_flags
= BYTE_GET (ehdr64
.e_flags
);
24247 filedata
->file_header
.e_ehsize
= BYTE_GET (ehdr64
.e_ehsize
);
24248 filedata
->file_header
.e_phentsize
= BYTE_GET (ehdr64
.e_phentsize
);
24249 filedata
->file_header
.e_phnum
= BYTE_GET (ehdr64
.e_phnum
);
24250 filedata
->file_header
.e_shentsize
= BYTE_GET (ehdr64
.e_shentsize
);
24251 filedata
->file_header
.e_shnum
= BYTE_GET (ehdr64
.e_shnum
);
24252 filedata
->file_header
.e_shstrndx
= BYTE_GET (ehdr64
.e_shstrndx
);
24259 free_filedata (Filedata
*filedata
)
24261 free (filedata
->program_interpreter
);
24262 free (filedata
->program_headers
);
24263 free (filedata
->section_headers
);
24264 free (filedata
->string_table
);
24265 free (filedata
->dump
.dump_sects
);
24266 free (filedata
->dynamic_strings
);
24267 free (filedata
->dynamic_symbols
);
24268 free (filedata
->dynamic_syminfo
);
24269 free (filedata
->dynamic_section
);
24271 while (filedata
->symtab_shndx_list
!= NULL
)
24273 elf_section_list
*next
= filedata
->symtab_shndx_list
->next
;
24274 free (filedata
->symtab_shndx_list
);
24275 filedata
->symtab_shndx_list
= next
;
24278 free (filedata
->section_headers_groups
);
24280 if (filedata
->section_groups
)
24283 struct group_list
* g
;
24284 struct group_list
* next
;
24286 for (i
= 0; i
< filedata
->group_count
; i
++)
24288 for (g
= filedata
->section_groups
[i
].root
; g
!= NULL
; g
= next
)
24295 free (filedata
->section_groups
);
24297 memset (&filedata
->section_headers
, 0,
24298 sizeof (Filedata
) - offsetof (Filedata
, section_headers
));
24302 close_file (Filedata
* filedata
)
24306 if (filedata
->handle
)
24307 fclose (filedata
->handle
);
24313 close_debug_file (void * data
)
24315 free_filedata ((Filedata
*) data
);
24316 close_file ((Filedata
*) data
);
24320 open_file (const char * pathname
, bool is_separate
)
24322 struct stat statbuf
;
24323 Filedata
* filedata
= NULL
;
24325 if (stat (pathname
, & statbuf
) < 0
24326 || ! S_ISREG (statbuf
.st_mode
))
24329 filedata
= calloc (1, sizeof * filedata
);
24330 if (filedata
== NULL
)
24333 filedata
->handle
= fopen (pathname
, "rb");
24334 if (filedata
->handle
== NULL
)
24337 filedata
->file_size
= statbuf
.st_size
;
24338 filedata
->file_name
= pathname
;
24339 filedata
->is_separate
= is_separate
;
24341 if (! get_file_header (filedata
))
24344 if (!get_section_headers (filedata
, false))
24352 if (filedata
->handle
)
24353 fclose (filedata
->handle
);
24360 open_debug_file (const char * pathname
)
24362 return open_file (pathname
, true);
24366 initialise_dump_sects (Filedata
* filedata
)
24368 /* Initialise the dump_sects array from the cmdline_dump_sects array.
24369 Note we do this even if cmdline_dump_sects is empty because we
24370 must make sure that the dump_sets array is zeroed out before each
24371 object file is processed. */
24372 if (filedata
->dump
.num_dump_sects
> cmdline
.num_dump_sects
)
24373 memset (filedata
->dump
.dump_sects
, 0,
24374 filedata
->dump
.num_dump_sects
* sizeof (*filedata
->dump
.dump_sects
));
24376 if (cmdline
.num_dump_sects
> 0)
24378 if (filedata
->dump
.num_dump_sects
== 0)
24379 /* A sneaky way of allocating the dump_sects array. */
24380 request_dump_bynumber (&filedata
->dump
, cmdline
.num_dump_sects
, 0);
24382 assert (filedata
->dump
.num_dump_sects
>= cmdline
.num_dump_sects
);
24383 memcpy (filedata
->dump
.dump_sects
, cmdline
.dump_sects
,
24384 cmdline
.num_dump_sects
* sizeof (*filedata
->dump
.dump_sects
));
24389 might_need_separate_debug_info (Filedata
* filedata
)
24391 /* Debuginfo files do not need further separate file loading. */
24392 if (filedata
->file_header
.e_shstrndx
== SHN_UNDEF
)
24395 /* Since do_follow_links might be enabled by default, only treat it as an
24396 indication that separate files should be loaded if setting it was a
24397 deliberate user action. */
24398 if (DEFAULT_FOR_FOLLOW_LINKS
== 0 && do_follow_links
)
24401 if (process_links
|| do_syms
|| do_unwind
24402 || dump_any_debugging
|| do_dump
|| do_debugging
)
24408 /* Process one ELF object file according to the command line options.
24409 This file may actually be stored in an archive. The file is
24410 positioned at the start of the ELF object. Returns TRUE if no
24411 problems were encountered, FALSE otherwise. */
24414 process_object (Filedata
* filedata
)
24416 bool have_separate_files
;
24420 if (! get_file_header (filedata
))
24422 error (_("%s: Failed to read file header\n"), filedata
->file_name
);
24426 /* Initialise per file variables. */
24427 for (i
= ARRAY_SIZE (filedata
->version_info
); i
--;)
24428 filedata
->version_info
[i
] = 0;
24430 for (i
= ARRAY_SIZE (filedata
->dynamic_info
); i
--;)
24431 filedata
->dynamic_info
[i
] = 0;
24432 filedata
->dynamic_info_DT_GNU_HASH
= 0;
24433 filedata
->dynamic_info_DT_MIPS_XHASH
= 0;
24435 /* Process the file. */
24437 printf (_("\nFile: %s\n"), filedata
->file_name
);
24439 initialise_dump_sects (filedata
);
24441 /* There may be some extensions in the first section header. Don't
24442 bomb if we can't read it. */
24443 get_section_headers (filedata
, true);
24445 if (! process_file_header (filedata
))
24451 /* Throw away the single section header read above, so that we
24452 re-read the entire set. */
24453 free (filedata
->section_headers
);
24454 filedata
->section_headers
= NULL
;
24456 if (! process_section_headers (filedata
))
24458 /* Without loaded section headers we cannot process lots of things. */
24459 do_unwind
= do_version
= do_dump
= do_arch
= false;
24461 if (! do_using_dynamic
)
24462 do_syms
= do_dyn_syms
= do_reloc
= false;
24465 if (! process_section_groups (filedata
))
24466 /* Without loaded section groups we cannot process unwind. */
24469 process_program_headers (filedata
);
24471 res
= process_dynamic_section (filedata
);
24473 if (! process_relocs (filedata
))
24476 if (! process_unwind (filedata
))
24479 if (! process_symbol_table (filedata
))
24482 if (! process_lto_symbol_tables (filedata
))
24485 if (! process_syminfo (filedata
))
24488 if (! process_version_sections (filedata
))
24491 if (might_need_separate_debug_info (filedata
))
24492 have_separate_files
= load_separate_debug_files (filedata
, filedata
->file_name
);
24494 have_separate_files
= false;
24496 if (! process_section_contents (filedata
))
24499 if (! process_got_section_contents (filedata
))
24502 if (have_separate_files
)
24506 for (d
= first_separate_info
; d
!= NULL
; d
= d
->next
)
24508 initialise_dump_sects (d
->handle
);
24510 if (process_links
&& ! process_file_header (d
->handle
))
24512 else if (! process_section_headers (d
->handle
))
24514 else if (! process_section_contents (d
->handle
))
24516 else if (process_links
)
24518 if (! process_section_groups (d
->handle
))
24520 process_program_headers (d
->handle
);
24521 if (! process_dynamic_section (d
->handle
))
24523 if (! process_relocs (d
->handle
))
24525 if (! process_unwind (d
->handle
))
24527 if (! process_symbol_table (d
->handle
))
24529 if (! process_lto_symbol_tables (d
->handle
))
24531 if (! process_syminfo (d
->handle
))
24533 if (! process_version_sections (d
->handle
))
24535 if (! process_notes (d
->handle
))
24540 /* The file handles are closed by the call to free_debug_memory() below. */
24543 if (! process_notes (filedata
))
24546 if (! process_gnu_liblist (filedata
))
24549 if (! process_arch_specific (filedata
))
24553 free_filedata (filedata
);
24555 free_debug_memory ();
24560 /* Process an ELF archive.
24561 On entry the file is positioned just after the ARMAG string.
24562 Returns TRUE upon success, FALSE otherwise. */
24565 process_archive (Filedata
* filedata
, bool is_thin_archive
)
24567 struct archive_info arch
;
24568 struct archive_info nested_arch
;
24574 /* The ARCH structure is used to hold information about this archive. */
24575 arch
.file_name
= NULL
;
24577 arch
.index_array
= NULL
;
24578 arch
.sym_table
= NULL
;
24579 arch
.longnames
= NULL
;
24581 /* The NESTED_ARCH structure is used as a single-item cache of information
24582 about a nested archive (when members of a thin archive reside within
24583 another regular archive file). */
24584 nested_arch
.file_name
= NULL
;
24585 nested_arch
.file
= NULL
;
24586 nested_arch
.index_array
= NULL
;
24587 nested_arch
.sym_table
= NULL
;
24588 nested_arch
.longnames
= NULL
;
24590 if (setup_archive (&arch
, filedata
->file_name
, filedata
->handle
,
24591 filedata
->file_size
, is_thin_archive
,
24592 do_archive_index
) != 0)
24598 if (do_archive_index
)
24600 if (arch
.sym_table
== NULL
)
24601 error (_("%s: unable to dump the index as none was found\n"),
24602 filedata
->file_name
);
24606 uint64_t current_pos
;
24608 printf (_("Index of archive %s: (%" PRIu64
" entries,"
24609 " %#" PRIx64
" bytes in the symbol table)\n"),
24610 filedata
->file_name
, arch
.index_num
,
24613 current_pos
= ftell (filedata
->handle
);
24615 for (i
= l
= 0; i
< arch
.index_num
; i
++)
24618 || (i
> 0 && arch
.index_array
[i
] != arch
.index_array
[i
- 1]))
24621 = get_archive_member_name_at (&arch
, arch
.index_array
[i
],
24624 if (member_name
!= NULL
)
24626 char * qualified_name
24627 = make_qualified_name (&arch
, &nested_arch
,
24630 if (qualified_name
!= NULL
)
24632 printf (_("Contents of binary %s at offset "),
24634 (void) print_vma (arch
.index_array
[i
], PREFIX_HEX
);
24636 free (qualified_name
);
24638 free (member_name
);
24642 if (l
>= arch
.sym_size
)
24644 error (_("%s: end of the symbol table reached "
24645 "before the end of the index\n"),
24646 filedata
->file_name
);
24650 /* PR 17531: file: 0b6630b2. */
24651 printf ("\t%.*s\n",
24652 (int) (arch
.sym_size
- l
), arch
.sym_table
+ l
);
24653 l
+= strnlen (arch
.sym_table
+ l
, arch
.sym_size
- l
) + 1;
24656 if (arch
.uses_64bit_indices
)
24661 if (l
< arch
.sym_size
)
24663 error (ngettext ("%s: %" PRId64
" byte remains in the symbol table, "
24664 "but without corresponding entries in "
24665 "the index table\n",
24666 "%s: %" PRId64
" bytes remain in the symbol table, "
24667 "but without corresponding entries in "
24668 "the index table\n",
24669 arch
.sym_size
- l
),
24670 filedata
->file_name
, arch
.sym_size
- l
);
24674 if (fseek64 (filedata
->handle
, current_pos
, SEEK_SET
) != 0)
24676 error (_("%s: failed to seek back to start of object files "
24677 "in the archive\n"),
24678 filedata
->file_name
);
24684 if (!do_dynamic
&& !do_syms
&& !do_reloc
&& !do_unwind
&& !do_sections
24685 && !do_segments
&& !do_header
&& !do_dump
&& !do_version
24686 && !do_histogram
&& !do_debugging
&& !do_arch
&& !do_notes
24687 && !do_section_groups
&& !do_dyn_syms
)
24689 ret
= true; /* Archive index only. */
24698 char * qualified_name
;
24700 /* Read the next archive header. */
24701 if (fseek64 (filedata
->handle
, arch
.next_arhdr_offset
, SEEK_SET
) != 0)
24703 error (_("%s: failed to seek to next archive header\n"),
24708 got
= fread (&arch
.arhdr
, 1, sizeof arch
.arhdr
, filedata
->handle
);
24709 if (got
!= sizeof arch
.arhdr
)
24713 /* PR 24049 - we cannot use filedata->file_name as this will
24714 have already been freed. */
24715 error (_("%s: failed to read archive header\n"), arch
.file_name
);
24720 if (memcmp (arch
.arhdr
.ar_fmag
, ARFMAG
, 2) != 0)
24722 error (_("%s: did not find a valid archive header\n"),
24728 arch
.next_arhdr_offset
+= sizeof arch
.arhdr
;
24730 filedata
->archive_file_size
= strtoul (arch
.arhdr
.ar_size
, NULL
, 10);
24732 name
= get_archive_member_name (&arch
, &nested_arch
);
24735 error (_("%s: bad archive file name\n"), arch
.file_name
);
24739 namelen
= strlen (name
);
24741 qualified_name
= make_qualified_name (&arch
, &nested_arch
, name
);
24742 if (qualified_name
== NULL
)
24744 error (_("%s: bad archive file name\n"), arch
.file_name
);
24750 if (is_thin_archive
&& arch
.nested_member_origin
== 0)
24752 /* This is a proxy for an external member of a thin archive. */
24753 Filedata
* member_filedata
;
24754 char * member_file_name
= adjust_relative_path
24755 (filedata
->file_name
, name
, namelen
);
24758 if (member_file_name
== NULL
)
24760 free (qualified_name
);
24765 member_filedata
= open_file (member_file_name
, false);
24766 if (member_filedata
== NULL
)
24768 error (_("Input file '%s' is not readable.\n"), member_file_name
);
24769 free (member_file_name
);
24770 free (qualified_name
);
24775 filedata
->archive_file_offset
= arch
.nested_member_origin
;
24776 member_filedata
->file_name
= qualified_name
;
24778 /* The call to process_object() expects the file to be at the beginning. */
24779 rewind (member_filedata
->handle
);
24781 if (! process_object (member_filedata
))
24784 close_file (member_filedata
);
24785 free (member_file_name
);
24787 else if (is_thin_archive
)
24789 Filedata thin_filedata
;
24791 memset (&thin_filedata
, 0, sizeof (thin_filedata
));
24793 /* PR 15140: Allow for corrupt thin archives. */
24794 if (nested_arch
.file
== NULL
)
24796 error (_("%s: contains corrupt thin archive: %s\n"),
24797 qualified_name
, name
);
24798 free (qualified_name
);
24805 /* This is a proxy for a member of a nested archive. */
24806 filedata
->archive_file_offset
24807 = arch
.nested_member_origin
+ sizeof arch
.arhdr
;
24809 /* The nested archive file will have been opened and setup by
24810 get_archive_member_name. */
24811 if (fseek64 (nested_arch
.file
, filedata
->archive_file_offset
,
24814 error (_("%s: failed to seek to archive member.\n"),
24815 nested_arch
.file_name
);
24816 free (qualified_name
);
24821 thin_filedata
.handle
= nested_arch
.file
;
24822 thin_filedata
.file_name
= qualified_name
;
24824 if (! process_object (& thin_filedata
))
24830 filedata
->archive_file_offset
= arch
.next_arhdr_offset
;
24831 filedata
->file_name
= qualified_name
;
24832 if (! process_object (filedata
))
24834 arch
.next_arhdr_offset
+= (filedata
->archive_file_size
+ 1) & -2;
24835 /* Stop looping with "negative" archive_file_size. */
24836 if (arch
.next_arhdr_offset
< filedata
->archive_file_size
)
24837 arch
.next_arhdr_offset
= -1ul;
24840 free (qualified_name
);
24844 if (nested_arch
.file
!= NULL
)
24845 fclose (nested_arch
.file
);
24846 release_archive (&nested_arch
);
24847 release_archive (&arch
);
24853 process_file (char * file_name
)
24855 Filedata
* filedata
= NULL
;
24856 struct stat statbuf
;
24857 char armag
[SARMAG
];
24860 if (stat (file_name
, &statbuf
) < 0)
24862 if (errno
== ENOENT
)
24863 error (_("'%s': No such file\n"), file_name
);
24865 error (_("Could not locate '%s'. System error message: %s\n"),
24866 file_name
, strerror (errno
));
24870 if (! S_ISREG (statbuf
.st_mode
))
24872 error (_("'%s' is not an ordinary file\n"), file_name
);
24876 filedata
= calloc (1, sizeof * filedata
);
24877 if (filedata
== NULL
)
24879 error (_("Out of memory allocating file data structure\n"));
24883 filedata
->file_name
= file_name
;
24884 filedata
->handle
= fopen (file_name
, "rb");
24885 if (filedata
->handle
== NULL
)
24887 error (_("Input file '%s' is not readable.\n"), file_name
);
24892 if (fread (armag
, SARMAG
, 1, filedata
->handle
) != 1)
24894 error (_("%s: Failed to read file's magic number\n"), file_name
);
24895 fclose (filedata
->handle
);
24900 filedata
->file_size
= statbuf
.st_size
;
24901 filedata
->is_separate
= false;
24903 if (memcmp (armag
, ARMAG
, SARMAG
) == 0)
24905 if (! process_archive (filedata
, false))
24908 else if (memcmp (armag
, ARMAGT
, SARMAG
) == 0)
24910 if ( ! process_archive (filedata
, true))
24915 if (do_archive_index
&& !check_all
)
24916 error (_("File %s is not an archive so its index cannot be displayed.\n"),
24919 rewind (filedata
->handle
);
24920 filedata
->archive_file_size
= filedata
->archive_file_offset
= 0;
24922 if (! process_object (filedata
))
24926 close_debug_file (filedata
);
24928 free (ba_cache
.strtab
);
24929 ba_cache
.strtab
= NULL
;
24930 free (ba_cache
.symtab
);
24931 ba_cache
.symtab
= NULL
;
24932 ba_cache
.filedata
= NULL
;
24937 #ifdef SUPPORT_DISASSEMBLY
24938 /* Needed by the i386 disassembler. For extra credit, someone could
24939 fix this so that we insert symbolic addresses here, esp for GOT/PLT
24943 print_address (unsigned int addr
, FILE * outfile
)
24945 fprintf (outfile
,"0x%8.8x", addr
);
24948 /* Needed by the i386 disassembler. */
24951 db_task_printsym (unsigned int addr
)
24953 print_address (addr
, stderr
);
24958 main (int argc
, char ** argv
)
24962 #ifdef HAVE_LC_MESSAGES
24963 setlocale (LC_MESSAGES
, "");
24965 setlocale (LC_CTYPE
, "");
24966 bindtextdomain (PACKAGE
, LOCALEDIR
);
24967 textdomain (PACKAGE
);
24969 expandargv (&argc
, &argv
);
24971 parse_args (& cmdline
, argc
, argv
);
24973 if (optind
< (argc
- 1))
24974 /* When displaying information for more than one file,
24975 prefix the information with the file name. */
24977 else if (optind
>= argc
)
24979 /* Ensure that the warning is always displayed. */
24982 warn (_("Nothing to do.\n"));
24987 while (optind
< argc
)
24988 if (! process_file (argv
[optind
++]))
24991 free (cmdline
.dump_sects
);
24993 free (dump_ctf_symtab_name
);
24994 free (dump_ctf_strtab_name
);
24995 free (dump_ctf_parent_name
);
24997 return err
? EXIT_FAILURE
: EXIT_SUCCESS
;