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
] != 0x8001
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 /* Usually we'd only see verdef for defined symbols, and verneed for
14504 undefined symbols. However, symbols defined by the linker in
14505 .dynbss for variables copied from a shared library in order to
14506 avoid text relocations are defined yet have verneed. We could
14507 use a heuristic to detect the special case, for example, check
14508 for verneed first on symbols defined in SHT_NOBITS sections, but
14509 it is simpler and more reliable to just look for both verdef and
14510 verneed. .dynbss might not be mapped to a SHT_NOBITS section. */
14512 if (psym
->st_shndx
!= SHN_UNDEF
14513 && vers_data
!= 0x8001
14514 && filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
14516 Elf_Internal_Verdef ivd
;
14517 Elf_Internal_Verdaux ivda
;
14518 Elf_External_Verdaux evda
;
14521 off
= offset_from_vma (filedata
,
14522 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)],
14523 sizeof (Elf_External_Verdef
));
14527 Elf_External_Verdef evd
;
14529 if (get_data (&evd
, filedata
, off
, sizeof (evd
), 1,
14530 _("version def")) == NULL
)
14539 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
14540 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
14541 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
14542 ivd
.vd_flags
= BYTE_GET (evd
.vd_flags
);
14545 if ((ivd
.vd_ndx
& VERSYM_VERSION
) > max_vd_ndx
)
14546 max_vd_ndx
= ivd
.vd_ndx
& VERSYM_VERSION
;
14548 off
+= ivd
.vd_next
;
14550 while (ivd
.vd_ndx
!= (vers_data
& VERSYM_VERSION
) && ivd
.vd_next
!= 0);
14552 if (ivd
.vd_ndx
== (vers_data
& VERSYM_VERSION
))
14554 if (ivd
.vd_ndx
== 1 && ivd
.vd_flags
== VER_FLG_BASE
)
14557 off
-= ivd
.vd_next
;
14560 if (get_data (&evda
, filedata
, off
, sizeof (evda
), 1,
14561 _("version def aux")) != NULL
)
14563 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
14565 if (psym
->st_name
!= ivda
.vda_name
)
14566 return (ivda
.vda_name
< strtab_size
14567 ? strtab
+ ivda
.vda_name
: _("<corrupt>"));
14572 if (filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)])
14574 Elf_External_Verneed evn
;
14575 Elf_Internal_Verneed ivn
;
14576 Elf_Internal_Vernaux ivna
;
14578 offset
= offset_from_vma (filedata
,
14579 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)],
14585 if (get_data (&evn
, filedata
, offset
, sizeof (evn
), 1,
14586 _("version need")) == NULL
)
14589 ivna
.vna_other
= 0;
14594 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
14595 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
14597 vna_off
= offset
+ ivn
.vn_aux
;
14601 Elf_External_Vernaux evna
;
14603 if (get_data (&evna
, filedata
, vna_off
, sizeof (evna
), 1,
14604 _("version need aux (3)")) == NULL
)
14607 ivna
.vna_other
= 0;
14612 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
14613 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
14614 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
14617 vna_off
+= ivna
.vna_next
;
14619 while (ivna
.vna_other
!= vers_data
&& ivna
.vna_next
!= 0);
14621 if (ivna
.vna_other
== vers_data
)
14624 offset
+= ivn
.vn_next
;
14626 while (ivn
.vn_next
!= 0);
14628 if (ivna
.vna_other
== vers_data
)
14630 *sym_info
= symbol_undefined
;
14631 *vna_other
= ivna
.vna_other
;
14632 return (ivna
.vna_name
< strtab_size
14633 ? strtab
+ ivna
.vna_name
: _("<corrupt>"));
14635 else if ((max_vd_ndx
|| (vers_data
& VERSYM_VERSION
) != 1)
14636 && (vers_data
& VERSYM_VERSION
) > max_vd_ndx
)
14637 return _("<corrupt>");
14642 /* Display a symbol size on stdout. Format is based on --sym-base setting. */
14644 static unsigned int
14645 print_symbol_size (uint64_t vma
, int base
)
14650 return print_vma (vma
, OCTAL_5
);
14653 return print_vma (vma
, UNSIGNED_5
);
14656 return print_vma (vma
, PREFIX_HEX_5
);
14660 return print_vma (vma
, DEC_5
);
14664 /* Print information on a single symbol. */
14667 print_symbol (Filedata
* filedata
,
14668 uint64_t symbol_index
,
14669 Elf_Internal_Sym
* symtab
,
14670 Elf_Internal_Shdr
* section
,
14672 size_t strtab_size
)
14674 const char *version_string
;
14675 enum versioned_symbol_info sym_info
;
14676 unsigned short vna_other
;
14678 Elf_Internal_Sym
*psym
= symtab
+ symbol_index
;
14680 /* FIXME: We should have a table of field widths,
14681 rather than using hard coded constants. */
14682 printf ("%6" PRId64
": ", symbol_index
);
14683 print_vma (psym
->st_value
, LONG_HEX
);
14685 print_symbol_size (psym
->st_size
, sym_base
);
14686 printf (" %-7s", get_symbol_type (filedata
, ELF_ST_TYPE (psym
->st_info
)));
14687 printf (" %-6s", get_symbol_binding (filedata
, ELF_ST_BIND (psym
->st_info
)));
14688 if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_SOLARIS
)
14689 printf (" %-7s", get_solaris_symbol_visibility (psym
->st_other
));
14692 unsigned int vis
= ELF_ST_VISIBILITY (psym
->st_other
);
14694 printf (" %-7s", get_symbol_visibility (vis
));
14696 /* Check to see if any other bits in the st_other field are set.
14697 FIXME: Displaying this information here disrupts the layout
14698 of the table being generated. */
14699 if (psym
->st_other
^ vis
)
14700 printf (" [%s] ", get_symbol_other (filedata
, psym
->st_other
^ vis
));
14705 sstr
= printable_section_name_from_index (filedata
, psym
->st_shndx
, & is_special
);
14707 /* Print the symbol's section index. If the index is special
14708 then print the index's name rather than its number. */
14713 /* Special case: If there are no section headers, and the printable
14714 name is "<section 0x...." then just display the section number
14715 as a decimal. This happens when objcopy --strip -section-headers
14717 if (filedata
->file_header
.e_shnum
== 0 && startswith (sstr
, "<section"))
14718 printed
= printf (" %4d ", psym
->st_shndx
);
14720 printed
= printf (" %4s ", sstr
);
14722 if (extra_sym_info
&& printed
< 16)
14723 printf ("%*s", 16 - printed
, "");
14727 printf (" %4u ", psym
->st_shndx
);
14729 if (extra_sym_info
)
14731 /* Display the section name referenced by the section index. */
14732 int printed
= printf ("(%s) ", sstr
);
14734 printf ("%*s", 10 - printed
, "");
14738 /* Get the symbol's name. For section symbols without a
14739 specific name use the (already computed) section name. */
14740 if (ELF_ST_TYPE (psym
->st_info
) == STT_SECTION
14741 && section_index_real (filedata
, psym
->st_shndx
)
14742 && psym
->st_name
== 0)
14750 is_valid
= valid_symbol_name (strtab
, strtab_size
, psym
->st_name
);
14751 sstr
= is_valid
? strtab
+ psym
->st_name
: _("<corrupt>");
14755 = get_symbol_version_string (filedata
,
14757 || section
->sh_type
== SHT_DYNSYM
),
14758 strtab
, strtab_size
, symbol_index
,
14759 psym
, &sym_info
, &vna_other
);
14761 int len_avail
= 21;
14762 if (! do_wide
&& version_string
!= NULL
)
14766 len_avail
-= 1 + strlen (version_string
);
14768 if (sym_info
== symbol_undefined
)
14769 len_avail
-= sprintf (buffer
," (%d)", vna_other
);
14770 else if (sym_info
!= symbol_hidden
)
14774 print_symbol_name (len_avail
, sstr
);
14776 if (version_string
)
14778 if (sym_info
== symbol_undefined
)
14779 printf ("@%s (%d)", version_string
, vna_other
);
14781 printf (sym_info
== symbol_hidden
? "@%s" : "@@%s",
14787 if (ELF_ST_BIND (psym
->st_info
) == STB_LOCAL
14789 && symbol_index
>= section
->sh_info
14790 /* Irix 5 and 6 MIPS binaries are known to ignore this requirement. */
14791 && filedata
->file_header
.e_machine
!= EM_MIPS
14792 /* Solaris binaries have been found to violate this requirement as
14793 well. Not sure if this is a bug or an ABI requirement. */
14794 && filedata
->file_header
.e_ident
[EI_OSABI
] != ELFOSABI_SOLARIS
)
14795 warn (_("local symbol %" PRIu64
" found at index >= %s's sh_info value of %u\n"),
14796 symbol_index
, printable_section_name (filedata
, section
), section
->sh_info
);
14799 static const char *
14800 get_lto_kind (unsigned int kind
)
14804 case 0: return "DEF";
14805 case 1: return "WEAKDEF";
14806 case 2: return "UNDEF";
14807 case 3: return "WEAKUNDEF";
14808 case 4: return "COMMON";
14813 static char buffer
[30];
14814 error (_("Unknown LTO symbol definition encountered: %u\n"), kind
);
14815 sprintf (buffer
, "<unknown: %u>", kind
);
14819 static const char *
14820 get_lto_visibility (unsigned int visibility
)
14822 switch (visibility
)
14824 case 0: return "DEFAULT";
14825 case 1: return "PROTECTED";
14826 case 2: return "INTERNAL";
14827 case 3: return "HIDDEN";
14832 static char buffer
[30];
14833 error (_("Unknown LTO symbol visibility encountered: %u\n"), visibility
);
14834 sprintf (buffer
, "<unknown: %u>", visibility
);
14838 static const char *
14839 get_lto_sym_type (unsigned int sym_type
)
14843 case 0: return "UNKNOWN";
14844 case 1: return "FUNCTION";
14845 case 2: return "VARIABLE";
14850 static char buffer
[30];
14851 error (_("Unknown LTO symbol type encountered: %u\n"), sym_type
);
14852 sprintf (buffer
, "<unknown: %u>", sym_type
);
14856 /* Display an LTO format symbol table.
14857 FIXME: The format of LTO symbol tables is not formalized.
14858 So this code could need changing in the future. */
14861 display_lto_symtab (Filedata
* filedata
,
14862 Elf_Internal_Shdr
* section
)
14864 if (section
->sh_size
== 0)
14866 if (filedata
->is_separate
)
14867 printf (_("\nThe LTO Symbol table section '%s' in linked file '%s' is empty!\n"),
14868 printable_section_name (filedata
, section
),
14869 filedata
->file_name
);
14871 printf (_("\nLTO Symbol table '%s' is empty!\n"),
14872 printable_section_name (filedata
, section
));
14877 if (section
->sh_size
> filedata
->file_size
)
14879 error (_("Section %s has an invalid sh_size of %#" PRIx64
"\n"),
14880 printable_section_name (filedata
, section
),
14885 void * alloced_data
= get_data (NULL
, filedata
, section
->sh_offset
,
14886 section
->sh_size
, 1, _("LTO symbols"));
14887 if (alloced_data
== NULL
)
14890 /* Look for extended data for the symbol table. */
14891 void * ext_data_orig
= NULL
;
14892 char * ext_data
= NULL
;
14893 char * ext_data_end
= NULL
;
14894 char *ext_name
= xasprintf (".gnu.lto_.ext_symtab.%s",
14895 (section_name (filedata
, section
)
14896 + sizeof (".gnu.lto_.symtab.")));
14897 Elf_Internal_Shdr
*ext
= find_section (filedata
, ext_name
);
14900 if (ext
->sh_size
< 3)
14901 error (_("LTO Symbol extension table '%s' is empty!\n"),
14902 printable_section_name (filedata
, ext
));
14905 ext_data_orig
= ext_data
= get_data (NULL
, filedata
, ext
->sh_offset
,
14907 _("LTO ext symbol data"));
14908 if (ext_data
!= NULL
)
14910 ext_data_end
= ext_data
+ ext
->sh_size
;
14911 if (* ext_data
++ != 1)
14912 error (_("Unexpected version number in symbol extension table\n"));
14917 const unsigned char * data
= (const unsigned char *) alloced_data
;
14918 const unsigned char * end
= data
+ section
->sh_size
;
14920 if (filedata
->is_separate
)
14921 printf (_("\nIn linked file '%s': "), filedata
->file_name
);
14925 if (ext_data_orig
!= NULL
)
14928 printf (_("LTO Symbol table '%s' and extension table '%s' contain:\n"),
14929 printable_section_name (filedata
, section
),
14930 printable_section_name (filedata
, ext
));
14933 printf (_("LTO Symbol table '%s'\n"),
14934 printable_section_name (filedata
, section
));
14935 printf (_(" and extension table '%s' contain:\n"),
14936 printable_section_name (filedata
, ext
));
14940 printf (_("LTO Symbol table '%s' contains:\n"),
14941 printable_section_name (filedata
, section
));
14943 /* FIXME: Add a wide version. */
14944 if (ext_data_orig
!= NULL
)
14945 printf (_(" Comdat_Key Kind Visibility Size Slot Type Section Name\n"));
14947 printf (_(" Comdat_Key Kind Visibility Size Slot Name\n"));
14949 /* FIXME: We do not handle style prefixes. */
14953 const unsigned char * sym_name
= data
;
14954 data
+= strnlen ((const char *) sym_name
, end
- data
) + 1;
14958 const unsigned char * comdat_key
= data
;
14959 data
+= strnlen ((const char *) comdat_key
, end
- data
) + 1;
14963 if (data
+ 2 + 8 + 4 > end
)
14966 unsigned int kind
= *data
++;
14967 unsigned int visibility
= *data
++;
14969 uint64_t size
= byte_get (data
, 8);
14972 uint64_t slot
= byte_get (data
, 4);
14975 if (ext_data
!= NULL
)
14977 if (ext_data
< (ext_data_end
- 1))
14979 unsigned int sym_type
= * ext_data
++;
14980 unsigned int sec_kind
= * ext_data
++;
14982 printf (" %10s %10s %11s %08" PRIx64
" %08" PRIx64
" %9s %08x _",
14983 * comdat_key
== 0 ? "-" : (char *) comdat_key
,
14984 get_lto_kind (kind
),
14985 get_lto_visibility (visibility
),
14988 get_lto_sym_type (sym_type
),
14990 print_symbol_name (6, (const char *) sym_name
);
14994 error (_("Ran out of LTO symbol extension data\n"));
14996 /* FIXME: return FAIL result ? */
15001 printf (" %10s %10s %11s %08" PRIx64
" %08" PRIx64
" _",
15002 * comdat_key
== 0 ? "-" : (char *) comdat_key
,
15003 get_lto_kind (kind
),
15004 get_lto_visibility (visibility
),
15007 print_symbol_name (21, (const char *) sym_name
);
15012 if (ext_data
!= NULL
&& ext_data
< ext_data_end
)
15014 error (_("Data remains in the LTO symbol extension table\n"));
15018 free (alloced_data
);
15019 free (ext_data_orig
);
15024 error (_("Buffer overrun encountered whilst decoding LTO symbol table\n"));
15025 free (alloced_data
);
15026 free (ext_data_orig
);
15031 /* Display LTO symbol tables. */
15034 process_lto_symbol_tables (Filedata
* filedata
)
15036 Elf_Internal_Shdr
* section
;
15043 if (filedata
->section_headers
== NULL
)
15046 for (i
= 0, section
= filedata
->section_headers
;
15047 i
< filedata
->file_header
.e_shnum
;
15049 if (section_name_valid (filedata
, section
)
15050 && startswith (section_name (filedata
, section
), ".gnu.lto_.symtab."))
15051 res
&= display_lto_symtab (filedata
, section
);
15057 print_symbol_table_heading (void)
15059 /* FIXME: We should store the size of each field in the display in a table and
15060 then use the values inside print_symbol(), instead of that function using
15061 hard coded constants. */
15064 if (extra_sym_info
)
15066 printf (_(" Num: Value Size Type Bind Vis+Other Ndx(SecName) Name [+ Version Info]\n"));
15067 /* |--6-|: |--8---| |-5-| |--7--| |-6--| |--7--| |---8--| |----13.....| |........... */
15068 /* eg: 5: 00000000 14 FUNC LOCAL DEFAULT 1 (.text) get_sections */
15072 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
15073 /* |--6-|: |--8---| |-5-| |--7--| |-6--| |--7--| |-4| |........... */
15074 /* eg: 5: 00000000 14 FUNC LOCAL DEFAULT 1 get_sections */
15078 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
15079 /* |--6-|: |--8---| |-5-| |--7--| |-6--| |--7--| |-4| |------------29-------------| */
15080 /* eg: 5: 00000000 14 FUNC LOCAL DEFAULT 1 get_sections */
15085 if (extra_sym_info
)
15087 printf (_(" Num: Value Size Type Bind Vis+Other Ndx(SecName) Name [+ Version Info]\n"));
15088 /* |--6-|: |------16------| |-5-| |--7--| |-6--| |--7--| |-------14---| |..... */
15089 /* eg: 2: 0000000000000000 0 FUNC LOCAL DEFAULT 1 (.text) .very_long_function_name */
15094 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
15095 /* |--6-|: |------16------| |-5-| |--7--| |-6--| |--7--| |-4| |........... */
15096 /* eg: 5: 0000000000000000 14 FUNC LOCAL DEFAULT 1 very_long_function_name */
15100 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
15101 /* |--6-|: |------16------| |-5-| |--7--| |-6--| |--7--| |-4| |--------21---------| */
15102 /* eg: 5: 0000000000000000 14 FUNC LOCAL DEFAULT 1 very_long_functi[...] */
15108 dump_symbol_section (Elf_Internal_Shdr
* section
,
15109 Filedata
* filedata
)
15111 if (section
->sh_entsize
== 0)
15113 printf (_("\nSymbol table '%s' has a sh_entsize of zero!\n"),
15114 printable_section_name (filedata
, section
));
15118 uint64_t num_syms
= section
->sh_size
/ section
->sh_entsize
;
15120 if (filedata
->is_separate
)
15121 printf (ngettext ("\nIn linked file '%s' symbol section '%s'"
15122 " contains %" PRIu64
" entry:\n",
15123 "\nIn linked file '%s' symbol section '%s'"
15124 " contains %" PRIu64
" entries:\n",
15126 filedata
->file_name
,
15127 printable_section_name (filedata
, section
),
15130 printf (ngettext ("\nSymbol table '%s' contains %" PRIu64
15132 "\nSymbol table '%s' contains %" PRIu64
15135 printable_section_name (filedata
, section
),
15138 print_symbol_table_heading ();
15140 Elf_Internal_Sym
* symtab
= get_elf_symbols (filedata
, section
, & num_syms
);
15141 if (symtab
== NULL
)
15142 /* An error message will have already been displayed. */
15145 char * strtab
= NULL
;
15146 uint64_t strtab_size
= 0;
15148 if (section
->sh_link
== filedata
->file_header
.e_shstrndx
)
15150 strtab
= filedata
->string_table
;
15151 strtab_size
= filedata
->string_table_length
;
15153 else if (section
->sh_link
< filedata
->file_header
.e_shnum
)
15155 Elf_Internal_Shdr
* string_sec
;
15157 string_sec
= filedata
->section_headers
+ section
->sh_link
;
15159 strtab
= (char *) get_data (NULL
, filedata
, string_sec
->sh_offset
,
15160 1, string_sec
->sh_size
,
15161 _("string table"));
15162 strtab_size
= strtab
!= NULL
? string_sec
->sh_size
: 0;
15167 for (si
= 0; si
< num_syms
; si
++)
15168 print_symbol (filedata
, si
, symtab
, section
, strtab
, strtab_size
);
15172 if (strtab
!= filedata
->string_table
)
15178 /* Dump the symbol table. */
15181 process_symbol_table (Filedata
* filedata
)
15183 Elf_Internal_Shdr
* section
;
15185 if (!do_syms
&& !do_dyn_syms
&& !do_histogram
)
15188 if ((filedata
->dynamic_info
[DT_HASH
] || filedata
->dynamic_info_DT_GNU_HASH
)
15190 && do_using_dynamic
15191 && filedata
->dynamic_strings
!= NULL
15192 && filedata
->dynamic_symbols
!= NULL
)
15196 if (filedata
->is_separate
)
15198 printf (ngettext ("\nIn linked file '%s' the dynamic symbol table"
15199 " contains %" PRIu64
" entry:\n",
15200 "\nIn linked file '%s' the dynamic symbol table"
15201 " contains %" PRIu64
" entries:\n",
15202 filedata
->num_dynamic_syms
),
15203 filedata
->file_name
,
15204 filedata
->num_dynamic_syms
);
15208 printf (ngettext ("\nSymbol table for image contains %" PRIu64
15210 "\nSymbol table for image contains %" PRIu64
15212 filedata
->num_dynamic_syms
),
15213 filedata
->num_dynamic_syms
);
15216 print_symbol_table_heading ();
15218 for (si
= 0; si
< filedata
->num_dynamic_syms
; si
++)
15219 print_symbol (filedata
, si
, filedata
->dynamic_symbols
, NULL
,
15220 filedata
->dynamic_strings
,
15221 filedata
->dynamic_strings_length
);
15223 else if ((do_dyn_syms
|| (do_syms
&& !do_using_dynamic
))
15224 && filedata
->section_headers
!= NULL
)
15228 for (i
= 0, section
= filedata
->section_headers
;
15229 i
< filedata
->file_header
.e_shnum
;
15232 if ((section
->sh_type
!= SHT_SYMTAB
15233 && section
->sh_type
!= SHT_DYNSYM
)
15235 && section
->sh_type
== SHT_SYMTAB
))
15238 dump_symbol_section (section
, filedata
);
15243 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
15245 if (do_histogram
&& filedata
->buckets
!= NULL
)
15251 uint64_t maxlength
= 0;
15252 uint64_t nzero_counts
= 0;
15253 uint64_t nsyms
= 0;
15256 printf (ngettext ("\nHistogram for bucket list length "
15257 "(total of %" PRIu64
" bucket):\n",
15258 "\nHistogram for bucket list length "
15259 "(total of %" PRIu64
" buckets):\n",
15260 filedata
->nbuckets
),
15261 filedata
->nbuckets
);
15263 lengths
= calloc (filedata
->nbuckets
, sizeof (*lengths
));
15264 if (lengths
== NULL
)
15266 error (_("Out of memory allocating space for histogram buckets\n"));
15269 visited
= xcmalloc (filedata
->nchains
, 1);
15270 memset (visited
, 0, filedata
->nchains
);
15272 printf (_(" Length Number %% of total Coverage\n"));
15273 for (hn
= 0; hn
< filedata
->nbuckets
; ++hn
)
15275 for (si
= filedata
->buckets
[hn
]; si
> 0; si
= filedata
->chains
[si
])
15278 if (maxlength
< ++lengths
[hn
])
15280 if (si
>= filedata
->nchains
|| visited
[si
])
15282 error (_("histogram chain is corrupt\n"));
15290 counts
= calloc (maxlength
+ 1, sizeof (*counts
));
15291 if (counts
== NULL
)
15294 error (_("Out of memory allocating space for histogram counts\n"));
15298 for (hn
= 0; hn
< filedata
->nbuckets
; ++hn
)
15299 ++counts
[lengths
[hn
]];
15301 if (filedata
->nbuckets
> 0)
15304 printf (" 0 %-10" PRIu64
" (%5.1f%%)\n",
15305 counts
[0], (counts
[0] * 100.0) / filedata
->nbuckets
);
15306 for (i
= 1; i
<= maxlength
; ++i
)
15308 nzero_counts
+= counts
[i
] * i
;
15309 printf ("%7" PRIu64
" %-10" PRIu64
" (%5.1f%%) %5.1f%%\n",
15310 i
, counts
[i
], (counts
[i
] * 100.0) / filedata
->nbuckets
,
15311 (nzero_counts
* 100.0) / nsyms
);
15319 free (filedata
->buckets
);
15320 filedata
->buckets
= NULL
;
15321 filedata
->nbuckets
= 0;
15322 free (filedata
->chains
);
15323 filedata
->chains
= NULL
;
15325 if (do_histogram
&& filedata
->gnubuckets
!= NULL
)
15330 uint64_t maxlength
= 0;
15331 uint64_t nzero_counts
= 0;
15332 uint64_t nsyms
= 0;
15334 printf (ngettext ("\nHistogram for `%s' bucket list length "
15335 "(total of %" PRIu64
" bucket):\n",
15336 "\nHistogram for `%s' bucket list length "
15337 "(total of %" PRIu64
" buckets):\n",
15338 filedata
->ngnubuckets
),
15339 GNU_HASH_SECTION_NAME (filedata
),
15340 filedata
->ngnubuckets
);
15342 lengths
= calloc (filedata
->ngnubuckets
, sizeof (*lengths
));
15343 if (lengths
== NULL
)
15345 error (_("Out of memory allocating space for gnu histogram buckets\n"));
15349 printf (_(" Length Number %% of total Coverage\n"));
15351 for (hn
= 0; hn
< filedata
->ngnubuckets
; ++hn
)
15352 if (filedata
->gnubuckets
[hn
] != 0)
15354 uint64_t off
, length
= 1;
15356 for (off
= filedata
->gnubuckets
[hn
] - filedata
->gnusymidx
;
15357 /* PR 17531 file: 010-77222-0.004. */
15358 off
< filedata
->ngnuchains
15359 && (filedata
->gnuchains
[off
] & 1) == 0;
15362 lengths
[hn
] = length
;
15363 if (length
> maxlength
)
15364 maxlength
= length
;
15368 counts
= calloc (maxlength
+ 1, sizeof (*counts
));
15369 if (counts
== NULL
)
15372 error (_("Out of memory allocating space for gnu histogram counts\n"));
15376 for (hn
= 0; hn
< filedata
->ngnubuckets
; ++hn
)
15377 ++counts
[lengths
[hn
]];
15379 if (filedata
->ngnubuckets
> 0)
15382 printf (" 0 %-10" PRIu64
" (%5.1f%%)\n",
15383 counts
[0], (counts
[0] * 100.0) / filedata
->ngnubuckets
);
15384 for (j
= 1; j
<= maxlength
; ++j
)
15386 nzero_counts
+= counts
[j
] * j
;
15387 printf ("%7" PRIu64
" %-10" PRIu64
" (%5.1f%%) %5.1f%%\n",
15388 j
, counts
[j
], (counts
[j
] * 100.0) / filedata
->ngnubuckets
,
15389 (nzero_counts
* 100.0) / nsyms
);
15396 free (filedata
->gnubuckets
);
15397 filedata
->gnubuckets
= NULL
;
15398 filedata
->ngnubuckets
= 0;
15399 free (filedata
->gnuchains
);
15400 filedata
->gnuchains
= NULL
;
15401 filedata
->ngnuchains
= 0;
15402 free (filedata
->mipsxlat
);
15403 filedata
->mipsxlat
= NULL
;
15407 free (filedata
->gnubuckets
);
15408 filedata
->gnubuckets
= NULL
;
15409 filedata
->ngnubuckets
= 0;
15410 free (filedata
->gnuchains
);
15411 filedata
->gnuchains
= NULL
;
15412 filedata
->ngnuchains
= 0;
15413 free (filedata
->mipsxlat
);
15414 filedata
->mipsxlat
= NULL
;
15415 free (filedata
->buckets
);
15416 filedata
->buckets
= NULL
;
15417 filedata
->nbuckets
= 0;
15418 free (filedata
->chains
);
15419 filedata
->chains
= NULL
;
15424 process_syminfo (Filedata
* filedata
)
15428 if (filedata
->dynamic_syminfo
== NULL
15430 /* No syminfo, this is ok. */
15433 /* There better should be a dynamic symbol section. */
15434 if (filedata
->dynamic_symbols
== NULL
|| filedata
->dynamic_strings
== NULL
)
15437 if (filedata
->is_separate
)
15438 printf (ngettext ("\nIn linked file '%s: the dynamic info segment at offset %#" PRIx64
" contains %d entry:\n",
15439 "\nIn linked file '%s: the dynamic info segment at offset %#" PRIx64
" contains %d entries:\n",
15440 filedata
->dynamic_syminfo_nent
),
15441 filedata
->file_name
,
15442 filedata
->dynamic_syminfo_offset
,
15443 filedata
->dynamic_syminfo_nent
);
15445 printf (ngettext ("\nDynamic info segment at offset %#" PRIx64
15446 " contains %d entry:\n",
15447 "\nDynamic info segment at offset %#" PRIx64
15448 " contains %d entries:\n",
15449 filedata
->dynamic_syminfo_nent
),
15450 filedata
->dynamic_syminfo_offset
,
15451 filedata
->dynamic_syminfo_nent
);
15453 printf (_(" Num: Name BoundTo Flags\n"));
15454 for (i
= 0; i
< filedata
->dynamic_syminfo_nent
; ++i
)
15456 unsigned short int flags
= filedata
->dynamic_syminfo
[i
].si_flags
;
15458 printf ("%4d: ", i
);
15459 if (i
>= filedata
->num_dynamic_syms
)
15460 printf (_("<corrupt index>"));
15461 else if (valid_dynamic_name (filedata
, filedata
->dynamic_symbols
[i
].st_name
))
15462 print_symbol_name (30, get_dynamic_name (filedata
,
15463 filedata
->dynamic_symbols
[i
].st_name
));
15465 printf (_("<corrupt: %19ld>"), filedata
->dynamic_symbols
[i
].st_name
);
15468 switch (filedata
->dynamic_syminfo
[i
].si_boundto
)
15470 case SYMINFO_BT_SELF
:
15471 fputs ("SELF ", stdout
);
15473 case SYMINFO_BT_PARENT
:
15474 fputs ("PARENT ", stdout
);
15477 if (filedata
->dynamic_syminfo
[i
].si_boundto
> 0
15478 && filedata
->dynamic_syminfo
[i
].si_boundto
< filedata
->dynamic_nent
15479 && valid_dynamic_name (filedata
,
15480 filedata
->dynamic_section
[filedata
->dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
))
15482 print_symbol_name (10, get_dynamic_name (filedata
,
15483 filedata
->dynamic_section
[filedata
->dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
));
15487 printf ("%-10d ", filedata
->dynamic_syminfo
[i
].si_boundto
);
15491 if (flags
& SYMINFO_FLG_DIRECT
)
15492 printf (" DIRECT");
15493 if (flags
& SYMINFO_FLG_PASSTHRU
)
15494 printf (" PASSTHRU");
15495 if (flags
& SYMINFO_FLG_COPY
)
15497 if (flags
& SYMINFO_FLG_LAZYLOAD
)
15498 printf (" LAZYLOAD");
15506 /* A macro which evaluates to TRUE if the region ADDR .. ADDR + NELEM
15507 is contained by the region START .. END. The types of ADDR, START
15508 and END should all be the same. Note both ADDR + NELEM and END
15509 point to just beyond the end of the regions that are being tested. */
15510 #define IN_RANGE(START,END,ADDR,NELEM) \
15511 (((ADDR) >= (START)) && ((ADDR) < (END)) && ((ADDR) + (NELEM) <= (END)))
15513 /* Check to see if the given reloc needs to be handled in a target specific
15514 manner. If so then process the reloc and return TRUE otherwise return
15517 If called with reloc == NULL, then this is a signal that reloc processing
15518 for the current section has finished, and any saved state should be
15522 target_specific_reloc_handling (Filedata
*filedata
,
15523 Elf_Internal_Rela
*reloc
,
15524 unsigned char *start
,
15525 unsigned char *end
,
15526 Elf_Internal_Sym
*symtab
,
15529 unsigned int reloc_type
= 0;
15530 uint64_t sym_index
= 0;
15534 reloc_type
= get_reloc_type (filedata
, reloc
->r_info
);
15535 sym_index
= get_reloc_symindex (reloc
->r_info
);
15538 switch (filedata
->file_header
.e_machine
)
15542 switch (reloc_type
)
15544 /* For .uleb128 .LFE1-.LFB1, loongarch write 0 to object file
15545 at assembly time. */
15546 case 107: /* R_LARCH_ADD_ULEB128. */
15547 case 108: /* R_LARCH_SUB_ULEB128. */
15549 uint64_t value
= 0;
15550 unsigned int reloc_size
= 0;
15553 if (reloc
->r_offset
< (size_t) (end
- start
))
15554 value
= read_leb128 (start
+ reloc
->r_offset
, end
, false,
15555 &reloc_size
, &leb_ret
);
15556 if (leb_ret
!= 0 || reloc_size
== 0 || reloc_size
> 8)
15557 error (_("LoongArch ULEB128 field at 0x%lx contains invalid "
15558 "ULEB128 value\n"),
15559 (long) reloc
->r_offset
);
15561 else if (sym_index
>= num_syms
)
15562 error (_("%s reloc contains invalid symbol index "
15565 ? "R_LARCH_ADD_ULEB128"
15566 : "R_LARCH_SUB_ULEB128"),
15570 if (reloc_type
== 107)
15571 value
+= reloc
->r_addend
+ symtab
[sym_index
].st_value
;
15573 value
-= reloc
->r_addend
+ symtab
[sym_index
].st_value
;
15575 /* Write uleb128 value to p. */
15576 bfd_byte
*p
= start
+ reloc
->r_offset
;
15579 bfd_byte c
= value
& 0x7f;
15581 if (--reloc_size
!= 0)
15585 while (reloc_size
);
15595 case EM_MSP430_OLD
:
15597 static Elf_Internal_Sym
* saved_sym
= NULL
;
15605 switch (reloc_type
)
15607 case 10: /* R_MSP430_SYM_DIFF */
15608 case 12: /* R_MSP430_GNU_SUB_ULEB128 */
15609 if (uses_msp430x_relocs (filedata
))
15611 /* Fall through. */
15612 case 21: /* R_MSP430X_SYM_DIFF */
15613 case 23: /* R_MSP430X_GNU_SUB_ULEB128 */
15615 if (sym_index
>= num_syms
)
15616 error (_("%s reloc contains invalid symbol index "
15617 "%" PRIu64
"\n"), "MSP430 SYM_DIFF", sym_index
);
15619 saved_sym
= symtab
+ sym_index
;
15622 case 1: /* R_MSP430_32 or R_MSP430_ABS32 */
15623 case 3: /* R_MSP430_16 or R_MSP430_ABS8 */
15624 goto handle_sym_diff
;
15626 case 5: /* R_MSP430_16_BYTE */
15627 case 9: /* R_MSP430_8 */
15628 case 11: /* R_MSP430_GNU_SET_ULEB128 */
15629 if (uses_msp430x_relocs (filedata
))
15631 goto handle_sym_diff
;
15633 case 2: /* R_MSP430_ABS16 */
15634 case 15: /* R_MSP430X_ABS16 */
15635 case 22: /* R_MSP430X_GNU_SET_ULEB128 */
15636 if (! uses_msp430x_relocs (filedata
))
15638 goto handle_sym_diff
;
15641 if (saved_sym
!= NULL
)
15644 unsigned int reloc_size
= 0;
15646 switch (reloc_type
)
15648 case 1: /* R_MSP430_32 or R_MSP430_ABS32 */
15651 case 11: /* R_MSP430_GNU_SET_ULEB128 */
15652 case 22: /* R_MSP430X_GNU_SET_ULEB128 */
15653 if (reloc
->r_offset
< (size_t) (end
- start
))
15654 read_leb128 (start
+ reloc
->r_offset
, end
, false,
15655 &reloc_size
, &leb_ret
);
15662 if (leb_ret
!= 0 || reloc_size
== 0 || reloc_size
> 8)
15663 error (_("MSP430 ULEB128 field at %#" PRIx64
15664 " contains invalid ULEB128 value\n"),
15666 else if (sym_index
>= num_syms
)
15667 error (_("%s reloc contains invalid symbol index "
15668 "%" PRIu64
"\n"), "MSP430", sym_index
);
15671 value
= reloc
->r_addend
+ (symtab
[sym_index
].st_value
15672 - saved_sym
->st_value
);
15674 if (IN_RANGE (start
, end
, start
+ reloc
->r_offset
, reloc_size
))
15675 byte_put (start
+ reloc
->r_offset
, value
, reloc_size
);
15678 error (_("MSP430 sym diff reloc contains invalid offset: "
15689 if (saved_sym
!= NULL
)
15690 error (_("Unhandled MSP430 reloc type found after SYM_DIFF reloc\n"));
15697 case EM_CYGNUS_MN10300
:
15699 static Elf_Internal_Sym
* saved_sym
= NULL
;
15707 switch (reloc_type
)
15709 case 34: /* R_MN10300_ALIGN */
15711 case 33: /* R_MN10300_SYM_DIFF */
15712 if (sym_index
>= num_syms
)
15713 error (_("%s reloc contains invalid symbol index "
15714 "%" PRIu64
"\n"), "MN10300_SYM_DIFF", sym_index
);
15716 saved_sym
= symtab
+ sym_index
;
15719 case 1: /* R_MN10300_32 */
15720 case 2: /* R_MN10300_16 */
15721 if (saved_sym
!= NULL
)
15723 int reloc_size
= reloc_type
== 1 ? 4 : 2;
15726 if (sym_index
>= num_syms
)
15727 error (_("%s reloc contains invalid symbol index "
15728 "%" PRIu64
"\n"), "MN10300", sym_index
);
15731 value
= reloc
->r_addend
+ (symtab
[sym_index
].st_value
15732 - saved_sym
->st_value
);
15734 if (IN_RANGE (start
, end
, start
+ reloc
->r_offset
, reloc_size
))
15735 byte_put (start
+ reloc
->r_offset
, value
, reloc_size
);
15737 error (_("MN10300 sym diff reloc contains invalid offset:"
15738 " %#" PRIx64
"\n"),
15747 if (saved_sym
!= NULL
)
15748 error (_("Unhandled MN10300 reloc type found after SYM_DIFF reloc\n"));
15756 static uint64_t saved_sym1
= 0;
15757 static uint64_t saved_sym2
= 0;
15758 static uint64_t value
;
15762 saved_sym1
= saved_sym2
= 0;
15766 switch (reloc_type
)
15768 case 0x80: /* R_RL78_SYM. */
15769 saved_sym1
= saved_sym2
;
15770 if (sym_index
>= num_syms
)
15771 error (_("%s reloc contains invalid symbol index "
15772 "%" PRIu64
"\n"), "RL78_SYM", sym_index
);
15775 saved_sym2
= symtab
[sym_index
].st_value
;
15776 saved_sym2
+= reloc
->r_addend
;
15780 case 0x83: /* R_RL78_OPsub. */
15781 value
= saved_sym1
- saved_sym2
;
15782 saved_sym2
= saved_sym1
= 0;
15786 case 0x41: /* R_RL78_ABS32. */
15787 if (IN_RANGE (start
, end
, start
+ reloc
->r_offset
, 4))
15788 byte_put (start
+ reloc
->r_offset
, value
, 4);
15790 error (_("RL78 sym diff reloc contains invalid offset: "
15796 case 0x43: /* R_RL78_ABS16. */
15797 if (IN_RANGE (start
, end
, start
+ reloc
->r_offset
, 2))
15798 byte_put (start
+ reloc
->r_offset
, value
, 2);
15800 error (_("RL78 sym diff reloc contains invalid offset: "
15816 /* Returns TRUE iff RELOC_TYPE is a 32-bit absolute RELA relocation used in
15817 DWARF debug sections. This is a target specific test. Note - we do not
15818 go through the whole including-target-headers-multiple-times route, (as
15819 we have already done with <elf/h8.h>) because this would become very
15820 messy and even then this function would have to contain target specific
15821 information (the names of the relocs instead of their numeric values).
15822 FIXME: This is not the correct way to solve this problem. The proper way
15823 is to have target specific reloc sizing and typing functions created by
15824 the reloc-macros.h header, in the same way that it already creates the
15825 reloc naming functions. */
15828 is_32bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
15830 /* Please keep this table alpha-sorted for ease of visual lookup. */
15831 switch (filedata
->file_header
.e_machine
)
15835 return reloc_type
== 1; /* R_386_32. */
15837 return reloc_type
== 1; /* R_68K_32. */
15839 return reloc_type
== 1; /* R_860_32. */
15841 return reloc_type
== 2; /* R_960_32. */
15843 return (reloc_type
== 258
15844 || reloc_type
== 1); /* R_AARCH64_ABS32 || R_AARCH64_P32_ABS32 */
15846 return reloc_type
== 11; /* R_BPF_DATA_32 */
15847 case EM_ADAPTEVA_EPIPHANY
:
15848 return reloc_type
== 3;
15850 return reloc_type
== 1; /* R_ALPHA_REFLONG. */
15852 return reloc_type
== 1; /* R_ARC_32. */
15853 case EM_ARC_COMPACT
:
15854 case EM_ARC_COMPACT2
:
15855 case EM_ARC_COMPACT3
:
15856 case EM_ARC_COMPACT3_64
:
15857 return reloc_type
== 4; /* R_ARC_32. */
15859 return reloc_type
== 2; /* R_ARM_ABS32 */
15862 return reloc_type
== 1;
15864 return reloc_type
== 0x12; /* R_byte4_data. */
15866 return reloc_type
== 3; /* R_CRIS_32. */
15868 return reloc_type
== 3; /* R_CR16_NUM32. */
15870 return reloc_type
== 15; /* R_CRX_NUM32. */
15872 return reloc_type
== 1; /* R_CKCORE_ADDR32. */
15873 case EM_CYGNUS_FRV
:
15874 return reloc_type
== 1;
15875 case EM_CYGNUS_D10V
:
15877 return reloc_type
== 6; /* R_D10V_32. */
15878 case EM_CYGNUS_D30V
:
15880 return reloc_type
== 12; /* R_D30V_32_NORMAL. */
15882 return reloc_type
== 3; /* R_DLX_RELOC_32. */
15883 case EM_CYGNUS_FR30
:
15885 return reloc_type
== 3; /* R_FR30_32. */
15887 return reloc_type
== 1; /* R_FT32_32. */
15891 return reloc_type
== 1; /* R_H8_DIR32. */
15893 return (reloc_type
== 0x64 /* R_IA64_SECREL32MSB. */
15894 || reloc_type
== 0x65 /* R_IA64_SECREL32LSB. */
15895 || reloc_type
== 0x24 /* R_IA64_DIR32MSB. */
15896 || reloc_type
== 0x25 /* R_IA64_DIR32LSB. */);
15899 return reloc_type
== 2; /* R_IP2K_32. */
15901 return reloc_type
== 2; /* R_IQ2000_32. */
15903 return reloc_type
== 2; /* R_KVX_32. */
15904 case EM_LATTICEMICO32
:
15905 return reloc_type
== 3; /* R_LM32_32. */
15907 return reloc_type
== 1; /* R_LARCH_32. */
15910 return reloc_type
== 3; /* R_M32C_32. */
15912 return reloc_type
== 34; /* R_M32R_32_RELA. */
15915 return reloc_type
== 6; /* R_M68HC11_32. */
15917 return reloc_type
== 7 || /* R_S12Z_EXT32 */
15918 reloc_type
== 6; /* R_S12Z_CW32. */
15920 return reloc_type
== 1; /* R_MCORE_ADDR32. */
15921 case EM_CYGNUS_MEP
:
15922 return reloc_type
== 4; /* R_MEP_32. */
15924 return reloc_type
== 2; /* R_METAG_ADDR32. */
15925 case EM_MICROBLAZE
:
15926 return reloc_type
== 1; /* R_MICROBLAZE_32. */
15928 return reloc_type
== 2; /* R_MIPS_32. */
15930 return reloc_type
== 4; /* R_MMIX_32. */
15931 case EM_CYGNUS_MN10200
:
15933 return reloc_type
== 1; /* R_MN10200_32. */
15934 case EM_CYGNUS_MN10300
:
15936 return reloc_type
== 1; /* R_MN10300_32. */
15938 return reloc_type
== 1; /* R_MOXIE_32. */
15939 case EM_MSP430_OLD
:
15941 return reloc_type
== 1; /* R_MSP430_32 or R_MSP320_ABS32. */
15943 return reloc_type
== 2; /* R_MT_32. */
15945 return reloc_type
== 20; /* R_NDS32_32_RELA. */
15946 case EM_ALTERA_NIOS2
:
15947 return reloc_type
== 12; /* R_NIOS2_BFD_RELOC_32. */
15949 return reloc_type
== 1; /* R_NIOS_32. */
15951 return reloc_type
== 1; /* R_OR1K_32. */
15953 return (reloc_type
== 1 /* R_PARISC_DIR32. */
15954 || reloc_type
== 2 /* R_PARISC_DIR21L. */
15955 || reloc_type
== 41); /* R_PARISC_SECREL32. */
15958 return reloc_type
== 1; /* R_PJ_DATA_DIR32. */
15960 return reloc_type
== 1; /* R_PPC64_ADDR32. */
15962 return reloc_type
== 1; /* R_PPC_ADDR32. */
15964 return reloc_type
== 11; /* R_PRU_BFD_RELOC_32. */
15966 return reloc_type
== 1; /* R_RISCV_32. */
15968 return reloc_type
== 1; /* R_RL78_DIR32. */
15970 return reloc_type
== 1; /* R_RX_DIR32. */
15972 return reloc_type
== 1; /* R_I370_ADDR31. */
15975 return reloc_type
== 4; /* R_S390_32. */
15977 return reloc_type
== 8; /* R_SCORE_ABS32. */
15979 return reloc_type
== 1; /* R_SH_DIR32. */
15980 case EM_SPARC32PLUS
:
15983 return reloc_type
== 3 /* R_SPARC_32. */
15984 || reloc_type
== 23; /* R_SPARC_UA32. */
15986 return reloc_type
== 6; /* R_SPU_ADDR32 */
15988 return reloc_type
== 1; /* R_C6000_ABS32. */
15990 return reloc_type
== 2; /* R_TILEGX_32. */
15992 return reloc_type
== 1; /* R_TILEPRO_32. */
15993 case EM_CYGNUS_V850
:
15995 return reloc_type
== 6; /* R_V850_ABS32. */
15997 return reloc_type
== 0x33; /* R_V810_WORD. */
15999 return reloc_type
== 1; /* R_VAX_32. */
16001 return reloc_type
== 3; /* R_VISIUM_32. */
16002 case EM_WEBASSEMBLY
:
16003 return reloc_type
== 1; /* R_WASM32_32. */
16007 return reloc_type
== 10; /* R_X86_64_32. */
16009 return reloc_type
== 4; /* R_XGATE_32. */
16011 return reloc_type
== 1; /* R_XSTROMY16_32. */
16012 case EM_XTENSA_OLD
:
16014 return reloc_type
== 1; /* R_XTENSA_32. */
16016 return reloc_type
== 6; /* R_Z80_32. */
16019 static unsigned int prev_warn
= 0;
16021 /* Avoid repeating the same warning multiple times. */
16022 if (prev_warn
!= filedata
->file_header
.e_machine
)
16023 error (_("Missing knowledge of 32-bit reloc types used in DWARF sections of machine number %d\n"),
16024 filedata
->file_header
.e_machine
);
16025 prev_warn
= filedata
->file_header
.e_machine
;
16031 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
16032 a 32-bit pc-relative RELA relocation used in DWARF debug sections. */
16035 is_32bit_pcrel_reloc (Filedata
* filedata
, unsigned int reloc_type
)
16037 switch (filedata
->file_header
.e_machine
)
16038 /* Please keep this table alpha-sorted for ease of visual lookup. */
16042 return reloc_type
== 2; /* R_386_PC32. */
16044 return reloc_type
== 4; /* R_68K_PC32. */
16046 return reloc_type
== 261; /* R_AARCH64_PREL32 */
16047 case EM_ADAPTEVA_EPIPHANY
:
16048 return reloc_type
== 6;
16050 return reloc_type
== 10; /* R_ALPHA_SREL32. */
16051 case EM_ARC_COMPACT
:
16052 case EM_ARC_COMPACT2
:
16053 case EM_ARC_COMPACT3
:
16054 case EM_ARC_COMPACT3_64
:
16055 return reloc_type
== 49; /* R_ARC_32_PCREL. */
16057 return reloc_type
== 3; /* R_ARM_REL32 */
16060 return reloc_type
== 36; /* R_AVR_32_PCREL. */
16062 return reloc_type
== 99; /* R_LARCH_32_PCREL. */
16063 case EM_MICROBLAZE
:
16064 return reloc_type
== 2; /* R_MICROBLAZE_32_PCREL. */
16066 return reloc_type
== 9; /* R_OR1K_32_PCREL. */
16068 return reloc_type
== 9; /* R_PARISC_PCREL32. */
16070 return reloc_type
== 26; /* R_PPC_REL32. */
16072 return reloc_type
== 26; /* R_PPC64_REL32. */
16074 return reloc_type
== 57; /* R_RISCV_32_PCREL. */
16077 return reloc_type
== 5; /* R_390_PC32. */
16079 return reloc_type
== 2; /* R_SH_REL32. */
16080 case EM_SPARC32PLUS
:
16083 return reloc_type
== 6; /* R_SPARC_DISP32. */
16085 return reloc_type
== 13; /* R_SPU_REL32. */
16087 return reloc_type
== 6; /* R_TILEGX_32_PCREL. */
16089 return reloc_type
== 4; /* R_TILEPRO_32_PCREL. */
16091 return reloc_type
== 6; /* R_VISIUM_32_PCREL */
16095 return reloc_type
== 2; /* R_X86_64_PC32. */
16097 return reloc_type
== 4; /* R_VAX_PCREL32. */
16098 case EM_XTENSA_OLD
:
16100 return reloc_type
== 14; /* R_XTENSA_32_PCREL. */
16102 return reloc_type
== 7; /* R_KVX_32_PCREL */
16104 /* Do not abort or issue an error message here. Not all targets use
16105 pc-relative 32-bit relocs in their DWARF debug information and we
16106 have already tested for target coverage in is_32bit_abs_reloc. A
16107 more helpful warning message will be generated by apply_relocations
16108 anyway, so just return. */
16113 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
16114 a 64-bit absolute RELA relocation used in DWARF debug sections. */
16117 is_64bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
16119 switch (filedata
->file_header
.e_machine
)
16122 return reloc_type
== 257; /* R_AARCH64_ABS64. */
16123 case EM_ARC_COMPACT3_64
:
16124 return reloc_type
== 5; /* R_ARC_64. */
16126 return reloc_type
== 2; /* R_ALPHA_REFQUAD. */
16128 return (reloc_type
== 0x26 /* R_IA64_DIR64MSB. */
16129 || reloc_type
== 0x27 /* R_IA64_DIR64LSB. */);
16131 return reloc_type
== 2; /* R_LARCH_64 */
16133 return reloc_type
== 80; /* R_PARISC_DIR64. */
16135 return reloc_type
== 38; /* R_PPC64_ADDR64. */
16137 return reloc_type
== 2; /* R_RISCV_64. */
16138 case EM_SPARC32PLUS
:
16141 return reloc_type
== 32 /* R_SPARC_64. */
16142 || reloc_type
== 54; /* R_SPARC_UA64. */
16146 return reloc_type
== 1; /* R_X86_64_64. */
16149 return reloc_type
== 22; /* R_S390_64. */
16151 return reloc_type
== 1; /* R_TILEGX_64. */
16153 return reloc_type
== 18; /* R_MIPS_64. */
16155 return reloc_type
== 3; /* R_KVX_64 */
16161 /* Like is_32bit_pcrel_reloc except that it returns TRUE iff RELOC_TYPE is
16162 a 64-bit pc-relative RELA relocation used in DWARF debug sections. */
16165 is_64bit_pcrel_reloc (Filedata
* filedata
, unsigned int reloc_type
)
16167 switch (filedata
->file_header
.e_machine
)
16170 return reloc_type
== 260; /* R_AARCH64_PREL64. */
16172 return reloc_type
== 11; /* R_ALPHA_SREL64. */
16174 return (reloc_type
== 0x4e /* R_IA64_PCREL64MSB. */
16175 || reloc_type
== 0x4f /* R_IA64_PCREL64LSB. */);
16177 return reloc_type
== 72; /* R_PARISC_PCREL64. */
16179 return reloc_type
== 44; /* R_PPC64_REL64. */
16180 case EM_SPARC32PLUS
:
16183 return reloc_type
== 46; /* R_SPARC_DISP64. */
16187 return reloc_type
== 24; /* R_X86_64_PC64. */
16190 return reloc_type
== 23; /* R_S390_PC64. */
16192 return reloc_type
== 5; /* R_TILEGX_64_PCREL. */
16198 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
16199 a 24-bit absolute RELA relocation used in DWARF debug sections. */
16202 is_24bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
16204 switch (filedata
->file_header
.e_machine
)
16206 case EM_CYGNUS_MN10200
:
16208 return reloc_type
== 4; /* R_MN10200_24. */
16210 return reloc_type
== 5; /* R_FT32_20. */
16212 return reloc_type
== 5; /* R_Z80_24. */
16218 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
16219 a 16-bit absolute RELA relocation used in DWARF debug sections. */
16222 is_16bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
16224 /* Please keep this table alpha-sorted for ease of visual lookup. */
16225 switch (filedata
->file_header
.e_machine
)
16228 case EM_ARC_COMPACT
:
16229 case EM_ARC_COMPACT2
:
16230 case EM_ARC_COMPACT3
:
16231 case EM_ARC_COMPACT3_64
:
16232 return reloc_type
== 2; /* R_ARC_16. */
16233 case EM_ADAPTEVA_EPIPHANY
:
16234 return reloc_type
== 5;
16237 return reloc_type
== 4; /* R_AVR_16. */
16238 case EM_CYGNUS_D10V
:
16240 return reloc_type
== 3; /* R_D10V_16. */
16242 return reloc_type
== 2; /* R_FT32_16. */
16246 return reloc_type
== R_H8_DIR16
;
16249 return reloc_type
== 1; /* R_IP2K_16. */
16252 return reloc_type
== 1; /* R_M32C_16 */
16253 case EM_CYGNUS_MN10200
:
16255 return reloc_type
== 2; /* R_MN10200_16. */
16256 case EM_CYGNUS_MN10300
:
16258 return reloc_type
== 2; /* R_MN10300_16. */
16260 return reloc_type
== 1; /* R_KVX_16 */
16262 if (uses_msp430x_relocs (filedata
))
16263 return reloc_type
== 2; /* R_MSP430_ABS16. */
16264 /* Fall through. */
16265 case EM_MSP430_OLD
:
16266 return reloc_type
== 5; /* R_MSP430_16_BYTE. */
16268 return reloc_type
== 19; /* R_NDS32_16_RELA. */
16269 case EM_ALTERA_NIOS2
:
16270 return reloc_type
== 13; /* R_NIOS2_BFD_RELOC_16. */
16272 return reloc_type
== 9; /* R_NIOS_16. */
16274 return reloc_type
== 2; /* R_OR1K_16. */
16276 return reloc_type
== 55; /* R_RISCV_SET16. */
16278 return reloc_type
== 8; /* R_PRU_BFD_RELOC_16. */
16280 return reloc_type
== 2; /* R_C6000_ABS16. */
16282 return reloc_type
== 2; /* R_VISIUM_16. */
16284 return reloc_type
== 3; /* R_XGATE_16. */
16286 return reloc_type
== 4; /* R_Z80_16. */
16292 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
16293 a 8-bit absolute RELA relocation used in DWARF debug sections. */
16296 is_8bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
16298 switch (filedata
->file_header
.e_machine
)
16301 return reloc_type
== 54; /* R_RISCV_SET8. */
16303 return reloc_type
== 1; /* R_Z80_8. */
16304 case EM_MICROBLAZE
:
16305 return (reloc_type
== 33 /* R_MICROBLAZE_32_NONE. */
16306 || reloc_type
== 0 /* R_MICROBLAZE_NONE. */
16307 || reloc_type
== 9 /* R_MICROBLAZE_64_NONE. */);
16313 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
16314 a 6-bit absolute RELA relocation used in DWARF debug sections. */
16317 is_6bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
16319 switch (filedata
->file_header
.e_machine
)
16322 return reloc_type
== 53; /* R_RISCV_SET6. */
16328 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
16329 a 32-bit inplace add RELA relocation used in DWARF debug sections. */
16332 is_32bit_inplace_add_reloc (Filedata
* filedata
, unsigned int reloc_type
)
16334 /* Please keep this table alpha-sorted for ease of visual lookup. */
16335 switch (filedata
->file_header
.e_machine
)
16338 return reloc_type
== 50; /* R_LARCH_ADD32. */
16340 return reloc_type
== 35; /* R_RISCV_ADD32. */
16346 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
16347 a 32-bit inplace sub RELA relocation used in DWARF debug sections. */
16350 is_32bit_inplace_sub_reloc (Filedata
* filedata
, unsigned int reloc_type
)
16352 /* Please keep this table alpha-sorted for ease of visual lookup. */
16353 switch (filedata
->file_header
.e_machine
)
16356 return reloc_type
== 55; /* R_LARCH_SUB32. */
16358 return reloc_type
== 39; /* R_RISCV_SUB32. */
16364 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
16365 a 64-bit inplace add RELA relocation used in DWARF debug sections. */
16368 is_64bit_inplace_add_reloc (Filedata
* filedata
, unsigned int reloc_type
)
16370 /* Please keep this table alpha-sorted for ease of visual lookup. */
16371 switch (filedata
->file_header
.e_machine
)
16374 return reloc_type
== 51; /* R_LARCH_ADD64. */
16376 return reloc_type
== 36; /* R_RISCV_ADD64. */
16382 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
16383 a 64-bit inplace sub RELA relocation used in DWARF debug sections. */
16386 is_64bit_inplace_sub_reloc (Filedata
* filedata
, unsigned int reloc_type
)
16388 /* Please keep this table alpha-sorted for ease of visual lookup. */
16389 switch (filedata
->file_header
.e_machine
)
16392 return reloc_type
== 56; /* R_LARCH_SUB64. */
16394 return reloc_type
== 40; /* R_RISCV_SUB64. */
16400 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
16401 a 16-bit inplace add RELA relocation used in DWARF debug sections. */
16404 is_16bit_inplace_add_reloc (Filedata
* filedata
, unsigned int reloc_type
)
16406 /* Please keep this table alpha-sorted for ease of visual lookup. */
16407 switch (filedata
->file_header
.e_machine
)
16410 return reloc_type
== 48; /* R_LARCH_ADD16. */
16412 return reloc_type
== 34; /* R_RISCV_ADD16. */
16418 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
16419 a 16-bit inplace sub RELA relocation used in DWARF debug sections. */
16422 is_16bit_inplace_sub_reloc (Filedata
* filedata
, unsigned int reloc_type
)
16424 /* Please keep this table alpha-sorted for ease of visual lookup. */
16425 switch (filedata
->file_header
.e_machine
)
16428 return reloc_type
== 53; /* R_LARCH_SUB16. */
16430 return reloc_type
== 38; /* R_RISCV_SUB16. */
16436 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
16437 a 8-bit inplace add RELA relocation used in DWARF debug sections. */
16440 is_8bit_inplace_add_reloc (Filedata
* filedata
, unsigned int reloc_type
)
16442 /* Please keep this table alpha-sorted for ease of visual lookup. */
16443 switch (filedata
->file_header
.e_machine
)
16446 return reloc_type
== 47; /* R_LARCH_ADD8. */
16448 return reloc_type
== 33; /* R_RISCV_ADD8. */
16454 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
16455 a 8-bit inplace sub RELA relocation used in DWARF debug sections. */
16458 is_8bit_inplace_sub_reloc (Filedata
* filedata
, unsigned int reloc_type
)
16460 /* Please keep this table alpha-sorted for ease of visual lookup. */
16461 switch (filedata
->file_header
.e_machine
)
16464 return reloc_type
== 52; /* R_LARCH_SUB8. */
16466 return reloc_type
== 37; /* R_RISCV_SUB8. */
16472 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
16473 a 6-bit inplace add RELA relocation used in DWARF debug sections. */
16476 is_6bit_inplace_add_reloc (Filedata
* filedata
, unsigned int reloc_type
)
16478 switch (filedata
->file_header
.e_machine
)
16481 return reloc_type
== 105; /* R_LARCH_ADD6. */
16487 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
16488 a 6-bit inplace sub RELA relocation used in DWARF debug sections. */
16491 is_6bit_inplace_sub_reloc (Filedata
* filedata
, unsigned int reloc_type
)
16493 switch (filedata
->file_header
.e_machine
)
16496 return reloc_type
== 106; /* R_LARCH_SUB6. */
16498 return reloc_type
== 52; /* R_RISCV_SUB6. */
16504 /* Returns TRUE iff RELOC_TYPE is a NONE relocation used for discarded
16505 relocation entries (possibly formerly used for SHT_GROUP sections). */
16508 is_none_reloc (Filedata
* filedata
, unsigned int reloc_type
)
16510 switch (filedata
->file_header
.e_machine
)
16512 case EM_386
: /* R_386_NONE. */
16513 case EM_68K
: /* R_68K_NONE. */
16514 case EM_ADAPTEVA_EPIPHANY
:
16515 case EM_ALPHA
: /* R_ALPHA_NONE. */
16516 case EM_ALTERA_NIOS2
: /* R_NIOS2_NONE. */
16517 case EM_ARC
: /* R_ARC_NONE. */
16518 case EM_ARC_COMPACT2
: /* R_ARC_NONE. */
16519 case EM_ARC_COMPACT
: /* R_ARC_NONE. */
16520 case EM_ARC_COMPACT3
: /* R_ARC_NONE. */
16521 case EM_ARC_COMPACT3_64
: /* R_ARC_NONE. */
16522 case EM_ARM
: /* R_ARM_NONE. */
16523 case EM_CRIS
: /* R_CRIS_NONE. */
16524 case EM_FT32
: /* R_FT32_NONE. */
16525 case EM_IA_64
: /* R_IA64_NONE. */
16526 case EM_K1OM
: /* R_X86_64_NONE. */
16527 case EM_KVX
: /* R_KVX_NONE. */
16528 case EM_L1OM
: /* R_X86_64_NONE. */
16529 case EM_M32R
: /* R_M32R_NONE. */
16530 case EM_MIPS
: /* R_MIPS_NONE. */
16531 case EM_MN10300
: /* R_MN10300_NONE. */
16532 case EM_MOXIE
: /* R_MOXIE_NONE. */
16533 case EM_NIOS32
: /* R_NIOS_NONE. */
16534 case EM_OR1K
: /* R_OR1K_NONE. */
16535 case EM_PARISC
: /* R_PARISC_NONE. */
16536 case EM_PPC64
: /* R_PPC64_NONE. */
16537 case EM_PPC
: /* R_PPC_NONE. */
16538 case EM_RISCV
: /* R_RISCV_NONE. */
16539 case EM_S390
: /* R_390_NONE. */
16541 case EM_SH
: /* R_SH_NONE. */
16542 case EM_SPARC32PLUS
:
16543 case EM_SPARC
: /* R_SPARC_NONE. */
16545 case EM_TILEGX
: /* R_TILEGX_NONE. */
16546 case EM_TILEPRO
: /* R_TILEPRO_NONE. */
16547 case EM_TI_C6000
:/* R_C6000_NONE. */
16548 case EM_X86_64
: /* R_X86_64_NONE. */
16549 case EM_Z80
: /* R_Z80_NONE. */
16550 case EM_WEBASSEMBLY
: /* R_WASM32_NONE. */
16551 return reloc_type
== 0;
16554 return reloc_type
== 0 || reloc_type
== 256;
16557 return (reloc_type
== 0 /* R_AVR_NONE. */
16558 || reloc_type
== 30 /* R_AVR_DIFF8. */
16559 || reloc_type
== 31 /* R_AVR_DIFF16. */
16560 || reloc_type
== 32 /* R_AVR_DIFF32. */);
16562 return reloc_type
== 3; /* R_METAG_NONE. */
16564 return (reloc_type
== 0 /* R_NDS32_NONE. */
16565 || reloc_type
== 205 /* R_NDS32_DIFF8. */
16566 || reloc_type
== 206 /* R_NDS32_DIFF16. */
16567 || reloc_type
== 207 /* R_NDS32_DIFF32. */
16568 || reloc_type
== 208 /* R_NDS32_DIFF_ULEB128. */);
16570 return (reloc_type
== 0 /* R_PRU_NONE. */
16571 || reloc_type
== 65 /* R_PRU_DIFF8. */
16572 || reloc_type
== 66 /* R_PRU_DIFF16. */
16573 || reloc_type
== 67 /* R_PRU_DIFF32. */);
16574 case EM_XTENSA_OLD
:
16576 return (reloc_type
== 0 /* R_XTENSA_NONE. */
16577 || reloc_type
== 17 /* R_XTENSA_DIFF8. */
16578 || reloc_type
== 18 /* R_XTENSA_DIFF16. */
16579 || reloc_type
== 19 /* R_XTENSA_DIFF32. */
16580 || reloc_type
== 57 /* R_XTENSA_PDIFF8. */
16581 || reloc_type
== 58 /* R_XTENSA_PDIFF16. */
16582 || reloc_type
== 59 /* R_XTENSA_PDIFF32. */
16583 || reloc_type
== 60 /* R_XTENSA_NDIFF8. */
16584 || reloc_type
== 61 /* R_XTENSA_NDIFF16. */
16585 || reloc_type
== 62 /* R_XTENSA_NDIFF32. */);
16590 /* Returns TRUE if there is a relocation against
16591 section NAME at OFFSET bytes. */
16594 reloc_at (struct dwarf_section
* dsec
, uint64_t offset
)
16596 Elf_Internal_Rela
* relocs
;
16597 Elf_Internal_Rela
* rp
;
16599 if (dsec
== NULL
|| dsec
->reloc_info
== NULL
)
16602 relocs
= (Elf_Internal_Rela
*) dsec
->reloc_info
;
16604 for (rp
= relocs
; rp
< relocs
+ dsec
->num_relocs
; ++rp
)
16605 if (rp
->r_offset
== offset
)
16611 /* Apply relocations to a section.
16612 Returns TRUE upon success, FALSE otherwise.
16613 If RELOCS_RETURN is non-NULL then it is set to point to the loaded relocs.
16614 It is then the caller's responsibility to free them. NUM_RELOCS_RETURN
16615 will be set to the number of relocs loaded.
16617 Note: So far support has been added only for those relocations
16618 which can be found in debug sections. FIXME: Add support for
16619 more relocations ? */
16622 apply_relocations (Filedata
*filedata
,
16623 const Elf_Internal_Shdr
*section
,
16624 unsigned char *start
,
16626 void **relocs_return
,
16627 uint64_t *num_relocs_return
)
16629 Elf_Internal_Shdr
* relsec
;
16630 unsigned char * end
= start
+ size
;
16632 if (relocs_return
!= NULL
)
16634 * (Elf_Internal_Rela
**) relocs_return
= NULL
;
16635 * num_relocs_return
= 0;
16638 if (filedata
->file_header
.e_type
!= ET_REL
)
16639 /* No relocs to apply. */
16642 /* Find the reloc section associated with the section. */
16643 for (relsec
= filedata
->section_headers
;
16644 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
16648 uint64_t num_relocs
;
16649 Elf_Internal_Rela
* relocs
;
16650 Elf_Internal_Rela
* rp
;
16651 Elf_Internal_Shdr
* symsec
;
16652 Elf_Internal_Sym
* symtab
;
16654 Elf_Internal_Sym
* sym
;
16656 if ((relsec
->sh_type
!= SHT_RELA
&& relsec
->sh_type
!= SHT_REL
)
16657 || relsec
->sh_info
>= filedata
->file_header
.e_shnum
16658 || filedata
->section_headers
+ relsec
->sh_info
!= section
16659 || relsec
->sh_size
== 0
16660 || relsec
->sh_link
>= filedata
->file_header
.e_shnum
)
16663 symsec
= filedata
->section_headers
+ relsec
->sh_link
;
16664 if (symsec
->sh_type
!= SHT_SYMTAB
16665 && symsec
->sh_type
!= SHT_DYNSYM
)
16668 is_rela
= relsec
->sh_type
== SHT_RELA
;
16672 if (!slurp_rela_relocs (filedata
, relsec
->sh_offset
,
16673 relsec
->sh_size
, & relocs
, & num_relocs
))
16678 if (!slurp_rel_relocs (filedata
, relsec
->sh_offset
,
16679 relsec
->sh_size
, & relocs
, & num_relocs
))
16683 /* SH uses RELA but uses in place value instead of the addend field. */
16684 if (filedata
->file_header
.e_machine
== EM_SH
)
16687 symtab
= get_elf_symbols (filedata
, symsec
, & num_syms
);
16689 for (rp
= relocs
; rp
< relocs
+ num_relocs
; ++rp
)
16692 unsigned int reloc_type
;
16693 unsigned int reloc_size
;
16694 bool reloc_inplace
= false;
16695 bool reloc_subtract
= false;
16696 unsigned char *rloc
;
16697 uint64_t sym_index
;
16699 reloc_type
= get_reloc_type (filedata
, rp
->r_info
);
16701 if (target_specific_reloc_handling (filedata
, rp
, start
, end
, symtab
, num_syms
))
16703 else if (is_none_reloc (filedata
, reloc_type
))
16705 else if (is_32bit_abs_reloc (filedata
, reloc_type
)
16706 || is_32bit_pcrel_reloc (filedata
, reloc_type
))
16708 else if (is_64bit_abs_reloc (filedata
, reloc_type
)
16709 || is_64bit_pcrel_reloc (filedata
, reloc_type
))
16711 else if (is_24bit_abs_reloc (filedata
, reloc_type
))
16713 else if (is_16bit_abs_reloc (filedata
, reloc_type
))
16715 else if (is_8bit_abs_reloc (filedata
, reloc_type
)
16716 || is_6bit_abs_reloc (filedata
, reloc_type
))
16718 else if ((reloc_subtract
= is_32bit_inplace_sub_reloc (filedata
,
16720 || is_32bit_inplace_add_reloc (filedata
, reloc_type
))
16723 reloc_inplace
= true;
16725 else if ((reloc_subtract
= is_64bit_inplace_sub_reloc (filedata
,
16727 || is_64bit_inplace_add_reloc (filedata
, reloc_type
))
16730 reloc_inplace
= true;
16732 else if ((reloc_subtract
= is_16bit_inplace_sub_reloc (filedata
,
16734 || is_16bit_inplace_add_reloc (filedata
, reloc_type
))
16737 reloc_inplace
= true;
16739 else if ((reloc_subtract
= is_8bit_inplace_sub_reloc (filedata
,
16741 || is_8bit_inplace_add_reloc (filedata
, reloc_type
))
16744 reloc_inplace
= true;
16746 else if ((reloc_subtract
= is_6bit_inplace_sub_reloc (filedata
,
16748 || is_6bit_inplace_add_reloc (filedata
, reloc_type
))
16751 reloc_inplace
= true;
16755 static unsigned int prev_reloc
= 0;
16757 if (reloc_type
!= prev_reloc
)
16758 warn (_("unable to apply unsupported reloc type %d to section %s\n"),
16759 reloc_type
, printable_section_name (filedata
, section
));
16760 prev_reloc
= reloc_type
;
16764 rloc
= start
+ rp
->r_offset
;
16765 if (!IN_RANGE (start
, end
, rloc
, reloc_size
))
16767 warn (_("skipping invalid relocation offset %#" PRIx64
16768 " in section %s\n"),
16770 printable_section_name (filedata
, section
));
16774 sym_index
= get_reloc_symindex (rp
->r_info
);
16775 if (sym_index
>= num_syms
)
16777 warn (_("skipping invalid relocation symbol index %#" PRIx64
16778 " in section %s\n"),
16779 sym_index
, printable_section_name (filedata
, section
));
16782 sym
= symtab
+ sym_index
;
16784 /* If the reloc has a symbol associated with it,
16785 make sure that it is of an appropriate type.
16787 Relocations against symbols without type can happen.
16788 Gcc -feliminate-dwarf2-dups may generate symbols
16789 without type for debug info.
16791 Icc generates relocations against function symbols
16792 instead of local labels.
16794 Relocations against object symbols can happen, eg when
16795 referencing a global array. For an example of this see
16796 the _clz.o binary in libgcc.a. */
16798 && ELF_ST_TYPE (sym
->st_info
) != STT_COMMON
16799 && ELF_ST_TYPE (sym
->st_info
) > STT_SECTION
)
16801 warn (_("skipping unexpected symbol type %s in section %s relocation %tu\n"),
16802 get_symbol_type (filedata
, ELF_ST_TYPE (sym
->st_info
)),
16803 printable_section_name (filedata
, relsec
),
16810 addend
+= rp
->r_addend
;
16811 /* R_XTENSA_32, R_PJ_DATA_DIR32 and R_D30V_32_NORMAL are
16812 partial_inplace. */
16814 || (filedata
->file_header
.e_machine
== EM_XTENSA
16815 && reloc_type
== 1)
16816 || ((filedata
->file_header
.e_machine
== EM_PJ
16817 || filedata
->file_header
.e_machine
== EM_PJ_OLD
)
16818 && reloc_type
== 1)
16819 || ((filedata
->file_header
.e_machine
== EM_D30V
16820 || filedata
->file_header
.e_machine
== EM_CYGNUS_D30V
)
16821 && reloc_type
== 12)
16824 if (is_6bit_inplace_sub_reloc (filedata
, reloc_type
))
16825 addend
+= byte_get (rloc
, reloc_size
) & 0x3f;
16827 addend
+= byte_get (rloc
, reloc_size
);
16830 if (is_32bit_pcrel_reloc (filedata
, reloc_type
)
16831 || is_64bit_pcrel_reloc (filedata
, reloc_type
))
16833 /* On HPPA, all pc-relative relocations are biased by 8. */
16834 if (filedata
->file_header
.e_machine
== EM_PARISC
)
16836 byte_put (rloc
, (addend
+ sym
->st_value
) - rp
->r_offset
,
16839 else if (is_6bit_abs_reloc (filedata
, reloc_type
)
16840 || is_6bit_inplace_sub_reloc (filedata
, reloc_type
)
16841 || is_6bit_inplace_add_reloc (filedata
, reloc_type
))
16843 if (reloc_subtract
)
16844 addend
-= sym
->st_value
;
16846 addend
+= sym
->st_value
;
16847 addend
= (addend
& 0x3f) | (byte_get (rloc
, reloc_size
) & 0xc0);
16848 byte_put (rloc
, addend
, reloc_size
);
16850 else if (reloc_subtract
)
16851 byte_put (rloc
, addend
- sym
->st_value
, reloc_size
);
16853 byte_put (rloc
, addend
+ sym
->st_value
, reloc_size
);
16857 /* Let the target specific reloc processing code know that
16858 we have finished with these relocs. */
16859 target_specific_reloc_handling (filedata
, NULL
, NULL
, NULL
, NULL
, 0);
16863 * (Elf_Internal_Rela
**) relocs_return
= relocs
;
16864 * num_relocs_return
= num_relocs
;
16875 #ifdef SUPPORT_DISASSEMBLY
16877 disassemble_section (Elf_Internal_Shdr
* section
, Filedata
* filedata
)
16879 printf (_("\nAssembly dump of section %s\n"), printable_section_name (filedata
, section
));
16881 /* FIXME: XXX -- to be done --- XXX */
16887 /* Reads in the contents of SECTION from FILE, returning a pointer
16888 to a malloc'ed buffer or NULL if something went wrong. */
16891 get_section_contents (Elf_Internal_Shdr
* section
, Filedata
* filedata
)
16893 uint64_t num_bytes
= section
->sh_size
;
16895 if (num_bytes
== 0 || section
->sh_type
== SHT_NOBITS
)
16897 printf (_("Section '%s' has no data to dump.\n"),
16898 printable_section_name (filedata
, section
));
16902 return (char *) get_data (NULL
, filedata
, section
->sh_offset
, 1, num_bytes
,
16903 _("section contents"));
16906 /* Uncompresses a section that was compressed using zlib/zstd, in place. */
16909 uncompress_section_contents (bool is_zstd
,
16910 unsigned char ** buffer
,
16911 uint64_t uncompressed_size
,
16913 uint64_t file_size
)
16915 uint64_t compressed_size
= *size
;
16916 unsigned char *compressed_buffer
= *buffer
;
16917 unsigned char *uncompressed_buffer
= NULL
;
16921 /* Similar to bfd_section_size_insane() in the BFD library we expect an
16922 upper limit of ~10x compression. Any compression larger than that is
16923 thought to be due to fuzzing of the compression header. */
16924 if (uncompressed_size
> file_size
* 10)
16926 error (_("Uncompressed section size is suspiciously large: 0x%" PRIu64
"\n"),
16927 uncompressed_size
);
16931 uncompressed_buffer
= xmalloc (uncompressed_size
);
16936 size_t ret
= ZSTD_decompress (uncompressed_buffer
, uncompressed_size
,
16937 compressed_buffer
, compressed_size
);
16938 if (ZSTD_isError (ret
))
16944 /* It is possible the section consists of several compressed
16945 buffers concatenated together, so we uncompress in a loop. */
16946 /* PR 18313: The state field in the z_stream structure is supposed
16947 to be invisible to the user (ie us), but some compilers will
16948 still complain about it being used without initialisation. So
16949 we first zero the entire z_stream structure and then set the fields
16951 memset (&strm
, 0, sizeof strm
);
16952 strm
.avail_in
= compressed_size
;
16953 strm
.next_in
= (Bytef
*)compressed_buffer
;
16954 strm
.avail_out
= uncompressed_size
;
16956 rc
= inflateInit (&strm
);
16957 while (strm
.avail_in
> 0)
16961 strm
.next_out
= ((Bytef
*)uncompressed_buffer
16962 + (uncompressed_size
- strm
.avail_out
));
16963 rc
= inflate (&strm
, Z_FINISH
);
16964 if (rc
!= Z_STREAM_END
)
16966 rc
= inflateReset (&strm
);
16968 if (inflateEnd (&strm
) != Z_OK
|| rc
!= Z_OK
|| strm
.avail_out
!= 0)
16972 *buffer
= uncompressed_buffer
;
16973 *size
= uncompressed_size
;
16977 free (uncompressed_buffer
);
16978 /* Indicate decompression failure. */
16984 maybe_expand_or_relocate_section (Elf_Internal_Shdr
* section
,
16985 Filedata
* filedata
,
16986 unsigned char ** start_ptr
,
16987 unsigned char ** decomp_buf
,
16990 uint64_t section_size
= section
->sh_size
;
16991 unsigned char * start
= * start_ptr
;
16993 if (decompress_dumps
)
16995 uint64_t new_size
= section_size
;
16996 uint64_t uncompressed_size
= 0;
16997 bool is_zstd
= false;
16999 if ((section
->sh_flags
& SHF_COMPRESSED
) != 0)
17001 Elf_Internal_Chdr chdr
;
17002 unsigned int compression_header_size
17003 = get_compression_header (& chdr
, start
, section_size
);
17005 if (compression_header_size
== 0)
17006 /* An error message will have already been generated
17007 by get_compression_header. */
17008 return (uint64_t) -1;
17010 if (chdr
.ch_type
== ch_compress_zlib
)
17013 else if (chdr
.ch_type
== ch_compress_zstd
)
17018 warn (_("section '%s' has unsupported compress type: %d\n"),
17019 printable_section_name (filedata
, section
), chdr
.ch_type
);
17020 return (uint64_t) -1;
17023 uncompressed_size
= chdr
.ch_size
;
17024 start
+= compression_header_size
;
17025 new_size
-= compression_header_size
;
17027 else if (new_size
> 12 && streq ((char *) start
, "ZLIB"))
17029 /* Read the zlib header. In this case, it should be "ZLIB"
17030 followed by the uncompressed section size, 8 bytes in
17031 big-endian order. */
17032 uncompressed_size
= start
[4]; uncompressed_size
<<= 8;
17033 uncompressed_size
+= start
[5]; uncompressed_size
<<= 8;
17034 uncompressed_size
+= start
[6]; uncompressed_size
<<= 8;
17035 uncompressed_size
+= start
[7]; uncompressed_size
<<= 8;
17036 uncompressed_size
+= start
[8]; uncompressed_size
<<= 8;
17037 uncompressed_size
+= start
[9]; uncompressed_size
<<= 8;
17038 uncompressed_size
+= start
[10]; uncompressed_size
<<= 8;
17039 uncompressed_size
+= start
[11];
17044 if (uncompressed_size
)
17046 if (uncompress_section_contents (is_zstd
, &start
, uncompressed_size
,
17047 &new_size
, filedata
->file_size
))
17049 *decomp_buf
= start
;
17050 section_size
= new_size
;
17054 error (_("Unable to decompress section %s\n"),
17055 printable_section_name (filedata
, section
));
17056 return (uint64_t) -1;
17060 start
= * start_ptr
;
17062 else if (((section
->sh_flags
& SHF_COMPRESSED
) != 0)
17063 || (section_size
> 12 && streq ((char *) start
, "ZLIB")))
17065 printf (_(" NOTE: This section is compressed, but its contents have NOT been expanded for this dump.\n"));
17070 if (! apply_relocations (filedata
, section
, start
, section_size
, NULL
, NULL
))
17071 return (uint64_t) -1;
17075 Elf_Internal_Shdr
*relsec
;
17077 /* If the section being dumped has relocations against it the user might
17078 be expecting these relocations to have been applied. Check for this
17079 case and issue a warning message in order to avoid confusion.
17080 FIXME: Maybe we ought to have an option that dumps a section with
17081 relocs applied ? */
17082 for (relsec
= filedata
->section_headers
;
17083 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
17086 if ((relsec
->sh_type
!= SHT_RELA
&& relsec
->sh_type
!= SHT_REL
)
17087 || relsec
->sh_info
>= filedata
->file_header
.e_shnum
17088 || filedata
->section_headers
+ relsec
->sh_info
!= section
17089 || relsec
->sh_size
== 0
17090 || relsec
->sh_link
>= filedata
->file_header
.e_shnum
)
17093 printf (_(" NOTE: This section has relocations against it, but these have NOT been applied to this dump.\n"));
17098 * start_ptr
= start
;
17099 return section_size
;
17103 dump_section_as_strings (Elf_Internal_Shdr
* section
, Filedata
* filedata
)
17105 uint64_t num_bytes
;
17106 unsigned char *data
;
17107 unsigned char *end
;
17108 unsigned char *real_start
;
17109 unsigned char *start
;
17110 unsigned char *decomp_buf
;
17111 bool some_strings_shown
;
17113 real_start
= start
= (unsigned char *) get_section_contents (section
, filedata
);
17115 /* PR 21820: Do not fail if the section was empty. */
17116 return section
->sh_size
== 0 || section
->sh_type
== SHT_NOBITS
;
17118 num_bytes
= section
->sh_size
;
17120 if (filedata
->is_separate
)
17121 printf (_("\nString dump of section '%s' in linked file %s:\n"),
17122 printable_section_name (filedata
, section
),
17123 filedata
->file_name
);
17125 printf (_("\nString dump of section '%s':\n"),
17126 printable_section_name (filedata
, section
));
17129 num_bytes
= maybe_expand_or_relocate_section (section
, filedata
, &start
,
17130 &decomp_buf
, false);
17131 if (num_bytes
== (uint64_t) -1)
17135 end
= start
+ num_bytes
;
17136 some_strings_shown
= false;
17138 #ifdef HAVE_MBSTATE_T
17140 /* Initialise the multibyte conversion state. */
17141 memset (& state
, 0, sizeof (state
));
17144 bool continuing
= false;
17148 while (!ISPRINT (* data
))
17149 if (++ data
>= end
)
17154 size_t maxlen
= end
- data
;
17159 continuing
= false;
17163 printf (" [%6tx] ", data
- start
);
17177 /* PR 25543: Treat new-lines as string-ending characters. */
17186 /* Do not print control characters directly as they can affect terminal
17187 settings. Such characters usually appear in the names generated
17188 by the assembler for local labels. */
17191 printf ("^%c", c
+ 0x40);
17193 else if (ISPRINT (c
))
17200 #ifdef HAVE_MBSTATE_T
17203 /* Let printf do the hard work of displaying multibyte characters. */
17204 printf ("%.1s", data
- 1);
17205 #ifdef HAVE_MBSTATE_T
17206 /* Try to find out how many bytes made up the character that was
17207 just printed. Advance the symbol pointer past the bytes that
17209 n
= mbrtowc (& w
, (char *)(data
- 1), MB_CUR_MAX
, & state
);
17213 if (n
!= (size_t) -1 && n
!= (size_t) -2 && n
> 0)
17223 printf (_("<corrupt>\n"));
17226 some_strings_shown
= true;
17230 if (! some_strings_shown
)
17231 printf (_(" No strings found in this section."));
17246 dump_section_as_bytes (Elf_Internal_Shdr
*section
,
17247 Filedata
*filedata
,
17251 uint64_t section_size
;
17253 unsigned char *data
;
17254 unsigned char *real_start
;
17255 unsigned char *start
;
17256 unsigned char *decomp_buf
;
17258 real_start
= start
= (unsigned char *) get_section_contents (section
, filedata
);
17260 /* PR 21820: Do not fail if the section was empty. */
17261 return section
->sh_size
== 0 || section
->sh_type
== SHT_NOBITS
;
17263 section_size
= section
->sh_size
;
17265 if (filedata
->is_separate
)
17266 printf (_("\nHex dump of section '%s' in linked file %s:\n"),
17267 printable_section_name (filedata
, section
),
17268 filedata
->file_name
);
17270 printf (_("\nHex dump of section '%s':\n"),
17271 printable_section_name (filedata
, section
));
17274 section_size
= maybe_expand_or_relocate_section (section
, filedata
, &start
,
17275 &decomp_buf
, relocate
);
17276 if (section_size
== (uint64_t) -1)
17279 addr
= section
->sh_addr
;
17280 bytes
= section_size
;
17289 lbytes
= (bytes
> 16 ? 16 : bytes
);
17291 printf (" 0x%8.8" PRIx64
" ", addr
);
17293 for (j
= 0; j
< 16; j
++)
17296 printf ("%2.2x", data
[j
]);
17304 for (j
= 0; j
< lbytes
; j
++)
17307 if (k
>= ' ' && k
< 0x7f)
17332 #ifdef ENABLE_LIBCTF
17333 static ctf_sect_t
*
17334 shdr_to_ctf_sect (ctf_sect_t
*buf
, Elf_Internal_Shdr
*shdr
, Filedata
*filedata
)
17336 buf
->cts_name
= printable_section_name (filedata
, shdr
);
17337 buf
->cts_size
= shdr
->sh_size
;
17338 buf
->cts_entsize
= shdr
->sh_entsize
;
17343 /* Formatting callback function passed to ctf_dump. Returns either the pointer
17344 it is passed, or a pointer to newly-allocated storage, in which case
17345 dump_ctf() will free it when it no longer needs it. */
17348 dump_ctf_indent_lines (ctf_sect_names_t sect ATTRIBUTE_UNUSED
,
17349 char *s
, void *arg
)
17351 const char *blanks
= arg
;
17352 return xasprintf ("%s%s", blanks
, s
);
17355 /* Dump CTF errors/warnings. */
17357 dump_ctf_errs (ctf_dict_t
*fp
)
17359 ctf_next_t
*it
= NULL
;
17364 /* Dump accumulated errors and warnings. */
17365 while ((errtext
= ctf_errwarning_next (fp
, &it
, &is_warning
, &err
)) != NULL
)
17367 error (_("%s: %s"), is_warning
? _("warning"): _("error"),
17371 if (err
!= ECTF_NEXT_END
)
17372 error (_("CTF error: cannot get CTF errors: `%s'"), ctf_errmsg (err
));
17375 /* Dump one CTF archive member. */
17378 dump_ctf_archive_member (ctf_dict_t
*ctf
, const char *name
, ctf_dict_t
*parent
,
17381 const char *things
[] = {"Header", "Labels", "Data objects",
17382 "Function objects", "Variables", "Types", "Strings",
17384 const char **thing
;
17387 /* Don't print out the name of the default-named archive member if it appears
17388 first in the list. The name .ctf appears everywhere, even for things that
17389 aren't really archives, so printing it out is liable to be confusing; also,
17390 the common case by far is for only one archive member to exist, and hiding
17391 it in that case seems worthwhile. */
17393 if (strcmp (name
, ".ctf") != 0 || member
!= 0)
17394 printf (_("\nCTF archive member: %s:\n"), name
);
17396 if (ctf_parent_name (ctf
) != NULL
)
17397 ctf_import (ctf
, parent
);
17399 for (i
= 0, thing
= things
; *thing
[0]; thing
++, i
++)
17401 ctf_dump_state_t
*s
= NULL
;
17404 printf ("\n %s:\n", *thing
);
17405 while ((item
= ctf_dump (ctf
, &s
, i
, dump_ctf_indent_lines
,
17406 (void *) " ")) != NULL
)
17408 printf ("%s\n", item
);
17412 if (ctf_errno (ctf
))
17414 error (_("Iteration failed: %s, %s\n"), *thing
,
17415 ctf_errmsg (ctf_errno (ctf
)));
17420 dump_ctf_errs (ctf
);
17424 dump_section_as_ctf (Elf_Internal_Shdr
* section
, Filedata
* filedata
)
17426 Elf_Internal_Shdr
* symtab_sec
= NULL
;
17427 Elf_Internal_Shdr
* strtab_sec
= NULL
;
17428 void * data
= NULL
;
17429 void * symdata
= NULL
;
17430 void * strdata
= NULL
;
17431 ctf_sect_t ctfsect
, symsect
, strsect
;
17432 ctf_sect_t
* symsectp
= NULL
;
17433 ctf_sect_t
* strsectp
= NULL
;
17434 ctf_archive_t
* ctfa
= NULL
;
17435 ctf_dict_t
* parent
= NULL
;
17438 ctf_next_t
*i
= NULL
;
17444 shdr_to_ctf_sect (&ctfsect
, section
, filedata
);
17445 data
= get_section_contents (section
, filedata
);
17446 ctfsect
.cts_data
= data
;
17448 if (!dump_ctf_symtab_name
)
17449 dump_ctf_symtab_name
= strdup (".dynsym");
17451 if (!dump_ctf_strtab_name
)
17452 dump_ctf_strtab_name
= strdup (".dynstr");
17454 if (dump_ctf_symtab_name
&& dump_ctf_symtab_name
[0] != 0)
17456 if ((symtab_sec
= find_section (filedata
, dump_ctf_symtab_name
)) == NULL
)
17458 error (_("No symbol section named %s\n"), dump_ctf_symtab_name
);
17461 if ((symdata
= (void *) get_data (NULL
, filedata
,
17462 symtab_sec
->sh_offset
, 1,
17463 symtab_sec
->sh_size
,
17464 _("symbols"))) == NULL
)
17466 symsectp
= shdr_to_ctf_sect (&symsect
, symtab_sec
, filedata
);
17467 symsect
.cts_data
= symdata
;
17470 if (dump_ctf_strtab_name
&& dump_ctf_strtab_name
[0] != 0)
17472 if ((strtab_sec
= find_section (filedata
, dump_ctf_strtab_name
)) == NULL
)
17474 error (_("No string table section named %s\n"),
17475 dump_ctf_strtab_name
);
17478 if ((strdata
= (void *) get_data (NULL
, filedata
,
17479 strtab_sec
->sh_offset
, 1,
17480 strtab_sec
->sh_size
,
17481 _("strings"))) == NULL
)
17483 strsectp
= shdr_to_ctf_sect (&strsect
, strtab_sec
, filedata
);
17484 strsect
.cts_data
= strdata
;
17487 /* Load the CTF file and dump it. It may be a raw CTF section, or an archive:
17488 libctf papers over the difference, so we can pretend it is always an
17491 if ((ctfa
= ctf_arc_bufopen (&ctfsect
, symsectp
, strsectp
, &err
)) == NULL
)
17493 dump_ctf_errs (NULL
);
17494 error (_("CTF open failure: %s\n"), ctf_errmsg (err
));
17498 ctf_arc_symsect_endianness (ctfa
, filedata
->file_header
.e_ident
[EI_DATA
]
17501 /* Preload the parent dict, since it will need to be imported into every
17503 if ((parent
= ctf_dict_open (ctfa
, dump_ctf_parent_name
, &err
)) == NULL
)
17505 dump_ctf_errs (NULL
);
17506 error (_("CTF open failure: %s\n"), ctf_errmsg (err
));
17512 if (filedata
->is_separate
)
17513 printf (_("\nDump of CTF section '%s' in linked file %s:\n"),
17514 printable_section_name (filedata
, section
),
17515 filedata
->file_name
);
17517 printf (_("\nDump of CTF section '%s':\n"),
17518 printable_section_name (filedata
, section
));
17520 while ((fp
= ctf_archive_next (ctfa
, &i
, &name
, 0, &err
)) != NULL
)
17522 dump_ctf_archive_member (fp
, name
, parent
, member
++);
17523 ctf_dict_close (fp
);
17525 if (err
!= ECTF_NEXT_END
)
17527 dump_ctf_errs (NULL
);
17528 error (_("CTF member open failure: %s\n"), ctf_errmsg (err
));
17533 ctf_dict_close (parent
);
17543 load_specific_debug_section (enum dwarf_section_display_enum debug
,
17544 const Elf_Internal_Shdr
* sec
,
17547 struct dwarf_section
* section
= &debug_displays
[debug
].section
;
17549 Filedata
* filedata
= (Filedata
*) data
;
17551 if (section
->start
!= NULL
)
17553 /* If it is already loaded, do nothing. */
17554 if (streq (section
->filename
, filedata
->file_name
))
17556 free (section
->start
);
17559 snprintf (buf
, sizeof (buf
), _("%s section data"), section
->name
);
17560 section
->address
= sec
->sh_addr
;
17561 section
->filename
= filedata
->file_name
;
17562 section
->start
= (unsigned char *) get_data (NULL
, filedata
,
17564 sec
->sh_size
, buf
);
17565 if (section
->start
== NULL
)
17569 unsigned char *start
= section
->start
;
17570 uint64_t size
= sec
->sh_size
;
17571 uint64_t uncompressed_size
= 0;
17572 bool is_zstd
= false;
17574 if ((sec
->sh_flags
& SHF_COMPRESSED
) != 0)
17576 Elf_Internal_Chdr chdr
;
17577 unsigned int compression_header_size
;
17579 if (size
< (is_32bit_elf
17580 ? sizeof (Elf32_External_Chdr
)
17581 : sizeof (Elf64_External_Chdr
)))
17583 warn (_("compressed section %s is too small to contain a compression header\n"),
17588 compression_header_size
= get_compression_header (&chdr
, start
, size
);
17589 if (compression_header_size
== 0)
17590 /* An error message will have already been generated
17591 by get_compression_header. */
17594 if (chdr
.ch_type
== ch_compress_zlib
)
17597 else if (chdr
.ch_type
== ch_compress_zstd
)
17602 warn (_("section '%s' has unsupported compress type: %d\n"),
17603 section
->name
, chdr
.ch_type
);
17606 uncompressed_size
= chdr
.ch_size
;
17607 start
+= compression_header_size
;
17608 size
-= compression_header_size
;
17610 else if (size
> 12 && streq ((char *) start
, "ZLIB"))
17612 /* Read the zlib header. In this case, it should be "ZLIB"
17613 followed by the uncompressed section size, 8 bytes in
17614 big-endian order. */
17615 uncompressed_size
= start
[4]; uncompressed_size
<<= 8;
17616 uncompressed_size
+= start
[5]; uncompressed_size
<<= 8;
17617 uncompressed_size
+= start
[6]; uncompressed_size
<<= 8;
17618 uncompressed_size
+= start
[7]; uncompressed_size
<<= 8;
17619 uncompressed_size
+= start
[8]; uncompressed_size
<<= 8;
17620 uncompressed_size
+= start
[9]; uncompressed_size
<<= 8;
17621 uncompressed_size
+= start
[10]; uncompressed_size
<<= 8;
17622 uncompressed_size
+= start
[11];
17627 if (uncompressed_size
)
17629 if (uncompress_section_contents (is_zstd
, &start
, uncompressed_size
,
17630 &size
, filedata
->file_size
))
17632 /* Free the compressed buffer, update the section buffer
17633 and the section size if uncompress is successful. */
17634 free (section
->start
);
17635 section
->start
= start
;
17639 error (_("Unable to decompress section %s\n"),
17640 printable_section_name (filedata
, sec
));
17645 section
->size
= size
;
17648 if (section
->start
== NULL
)
17651 if (debug_displays
[debug
].relocate
)
17653 if (! apply_relocations (filedata
, sec
, section
->start
, section
->size
,
17654 & section
->reloc_info
, & section
->num_relocs
))
17659 section
->reloc_info
= NULL
;
17660 section
->num_relocs
= 0;
17666 #if HAVE_LIBDEBUGINFOD
17667 /* Return a hex string representation of the build-id. */
17669 get_build_id (void * data
)
17671 Filedata
* filedata
= (Filedata
*) data
;
17672 Elf_Internal_Shdr
* shdr
;
17675 /* Iterate through notes to find note.gnu.build-id.
17676 FIXME: Only the first note in any note section is examined. */
17677 for (i
= 0, shdr
= filedata
->section_headers
;
17678 i
< filedata
->file_header
.e_shnum
&& shdr
!= NULL
;
17681 if (shdr
->sh_type
!= SHT_NOTE
)
17686 size_t data_remaining
;
17688 Elf_External_Note
* enote
;
17689 Elf_Internal_Note inote
;
17691 uint64_t offset
= shdr
->sh_offset
;
17692 uint64_t align
= shdr
->sh_addralign
;
17693 uint64_t length
= shdr
->sh_size
;
17695 enote
= (Elf_External_Note
*) get_section_contents (shdr
, filedata
);
17701 else if (align
!= 4 && align
!= 8)
17707 end
= (char *) enote
+ length
;
17708 data_remaining
= end
- (char *) enote
;
17710 if (!is_ia64_vms (filedata
))
17712 min_notesz
= offsetof (Elf_External_Note
, name
);
17713 if (data_remaining
< min_notesz
)
17716 malformed note encountered in section %s whilst scanning for build-id note\n"),
17717 printable_section_name (filedata
, shdr
));
17721 data_remaining
-= min_notesz
;
17723 inote
.type
= BYTE_GET (enote
->type
);
17724 inote
.namesz
= BYTE_GET (enote
->namesz
);
17725 inote
.namedata
= enote
->name
;
17726 inote
.descsz
= BYTE_GET (enote
->descsz
);
17727 inote
.descdata
= ((char *) enote
17728 + ELF_NOTE_DESC_OFFSET (inote
.namesz
, align
));
17729 inote
.descpos
= offset
+ (inote
.descdata
- (char *) enote
);
17730 next
= ((char *) enote
17731 + ELF_NOTE_NEXT_OFFSET (inote
.namesz
, inote
.descsz
, align
));
17735 Elf64_External_VMS_Note
*vms_enote
;
17737 /* PR binutils/15191
17738 Make sure that there is enough data to read. */
17739 min_notesz
= offsetof (Elf64_External_VMS_Note
, name
);
17740 if (data_remaining
< min_notesz
)
17743 malformed note encountered in section %s whilst scanning for build-id note\n"),
17744 printable_section_name (filedata
, shdr
));
17748 data_remaining
-= min_notesz
;
17750 vms_enote
= (Elf64_External_VMS_Note
*) enote
;
17751 inote
.type
= BYTE_GET (vms_enote
->type
);
17752 inote
.namesz
= BYTE_GET (vms_enote
->namesz
);
17753 inote
.namedata
= vms_enote
->name
;
17754 inote
.descsz
= BYTE_GET (vms_enote
->descsz
);
17755 inote
.descdata
= inote
.namedata
+ align_power (inote
.namesz
, 3);
17756 inote
.descpos
= offset
+ (inote
.descdata
- (char *) enote
);
17757 next
= inote
.descdata
+ align_power (inote
.descsz
, 3);
17760 /* Skip malformed notes. */
17761 if ((size_t) (inote
.descdata
- inote
.namedata
) < inote
.namesz
17762 || (size_t) (inote
.descdata
- inote
.namedata
) > data_remaining
17763 || (size_t) (next
- inote
.descdata
) < inote
.descsz
17764 || ((size_t) (next
- inote
.descdata
)
17765 > data_remaining
- (size_t) (inote
.descdata
- inote
.namedata
)))
17768 malformed note encountered in section %s whilst scanning for build-id note\n"),
17769 printable_section_name (filedata
, shdr
));
17774 /* Check if this is the build-id note. If so then convert the build-id
17775 bytes to a hex string. */
17776 if (inote
.namesz
> 0
17777 && startswith (inote
.namedata
, "GNU")
17778 && inote
.type
== NT_GNU_BUILD_ID
)
17783 build_id
= malloc (inote
.descsz
* 2 + 1);
17784 if (build_id
== NULL
)
17790 for (j
= 0; j
< inote
.descsz
; ++j
)
17791 sprintf (build_id
+ (j
* 2), "%02x", inote
.descdata
[j
] & 0xff);
17792 build_id
[inote
.descsz
* 2] = '\0';
17795 return (unsigned char *) build_id
;
17802 #endif /* HAVE_LIBDEBUGINFOD */
17804 /* If this is not NULL, load_debug_section will only look for sections
17805 within the list of sections given here. */
17806 static unsigned int * section_subset
= NULL
;
17809 load_debug_section (enum dwarf_section_display_enum debug
, void * data
)
17811 struct dwarf_section
* section
= &debug_displays
[debug
].section
;
17812 Elf_Internal_Shdr
* sec
;
17813 Filedata
* filedata
= (Filedata
*) data
;
17815 if (!dump_any_debugging
)
17818 /* Without section headers we cannot find any sections. */
17819 if (filedata
->section_headers
== NULL
)
17822 if (filedata
->string_table
== NULL
17823 && filedata
->file_header
.e_shstrndx
!= SHN_UNDEF
17824 && filedata
->file_header
.e_shstrndx
< filedata
->file_header
.e_shnum
)
17826 Elf_Internal_Shdr
* strs
;
17828 /* Read in the string table, so that we have section names to scan. */
17829 strs
= filedata
->section_headers
+ filedata
->file_header
.e_shstrndx
;
17831 if (strs
!= NULL
&& strs
->sh_size
!= 0)
17833 filedata
->string_table
17834 = (char *) get_data (NULL
, filedata
, strs
->sh_offset
,
17835 1, strs
->sh_size
, _("string table"));
17837 filedata
->string_table_length
17838 = filedata
->string_table
!= NULL
? strs
->sh_size
: 0;
17842 /* Locate the debug section. */
17843 sec
= find_section_in_set (filedata
, section
->uncompressed_name
, section_subset
);
17845 section
->name
= section
->uncompressed_name
;
17848 sec
= find_section_in_set (filedata
, section
->compressed_name
, section_subset
);
17850 section
->name
= section
->compressed_name
;
17855 /* If we're loading from a subset of sections, and we've loaded
17856 a section matching this name before, it's likely that it's a
17858 if (section_subset
!= NULL
)
17859 free_debug_section (debug
);
17861 return load_specific_debug_section (debug
, sec
, data
);
17865 free_debug_section (enum dwarf_section_display_enum debug
)
17867 struct dwarf_section
* section
= &debug_displays
[debug
].section
;
17869 if (section
->start
== NULL
)
17872 free ((char *) section
->start
);
17873 section
->start
= NULL
;
17874 section
->address
= 0;
17877 free (section
->reloc_info
);
17878 section
->reloc_info
= NULL
;
17879 section
->num_relocs
= 0;
17883 display_debug_section (int shndx
, Elf_Internal_Shdr
* section
, Filedata
* filedata
)
17885 const char *name
= (section_name_valid (filedata
, section
)
17886 ? section_name (filedata
, section
) : "");
17887 const char *print_name
= printable_section_name (filedata
, section
);
17889 bool result
= true;
17892 length
= section
->sh_size
;
17895 printf (_("\nSection '%s' has no debugging data.\n"), print_name
);
17898 if (section
->sh_type
== SHT_NOBITS
)
17900 /* There is no point in dumping the contents of a debugging section
17901 which has the NOBITS type - the bits in the file will be random.
17902 This can happen when a file containing a .eh_frame section is
17903 stripped with the --only-keep-debug command line option. */
17904 printf (_("section '%s' has the NOBITS type - its contents are unreliable.\n"),
17909 if (startswith (name
, ".gnu.linkonce.wi."))
17910 name
= ".debug_info";
17912 /* See if we know how to display the contents of this section. */
17913 for (i
= 0; i
< max
; i
++)
17915 enum dwarf_section_display_enum id
= (enum dwarf_section_display_enum
) i
;
17916 struct dwarf_section_display
* display
= debug_displays
+ i
;
17917 struct dwarf_section
* sec
= & display
->section
;
17919 if (streq (sec
->uncompressed_name
, name
)
17920 || (id
== line
&& startswith (name
, ".debug_line."))
17921 || (id
== sframe
&& section
->sh_type
== SHT_GNU_SFRAME
)
17922 || streq (sec
->compressed_name
, name
))
17924 bool secondary
= (section
!= find_section (filedata
, name
));
17927 free_debug_section (id
);
17929 if (i
== line
&& startswith (name
, ".debug_line."))
17931 else if (id
== sframe
&& section
->sh_type
== SHT_GNU_SFRAME
)
17933 else if (streq (sec
->uncompressed_name
, name
))
17934 sec
->name
= sec
->uncompressed_name
;
17936 sec
->name
= sec
->compressed_name
;
17938 if (load_specific_debug_section (id
, section
, filedata
))
17940 /* If this debug section is part of a CU/TU set in a .dwp file,
17941 restrict load_debug_section to the sections in that set. */
17942 section_subset
= find_cu_tu_set (filedata
, shndx
);
17944 result
&= display
->display (sec
, filedata
);
17946 section_subset
= NULL
;
17948 if (secondary
|| (id
!= info
&& id
!= abbrev
&& id
!= debug_addr
))
17949 free_debug_section (id
);
17957 printf (_("Unrecognized debug section: %s\n"), print_name
);
17964 /* Set DUMP_SECTS for all sections where dumps were requested
17965 based on section name. */
17968 initialise_dumps_byname (Filedata
* filedata
)
17970 struct dump_list_entry
* cur
;
17972 for (cur
= dump_sects_byname
; cur
; cur
= cur
->next
)
17977 for (i
= 0; i
< filedata
->file_header
.e_shnum
; i
++)
17978 if (section_name_valid (filedata
, filedata
->section_headers
+ i
)
17979 && streq (section_name (filedata
, filedata
->section_headers
+ i
),
17982 request_dump_bynumber (&filedata
->dump
, i
, cur
->type
);
17986 if (!any
&& !filedata
->is_separate
)
17987 warn (_("Section '%s' was not dumped because it does not exist\n"),
17993 process_section_contents (Filedata
* filedata
)
17995 Elf_Internal_Shdr
* section
;
18002 initialise_dumps_byname (filedata
);
18004 for (i
= 0, section
= filedata
->section_headers
;
18005 i
< filedata
->file_header
.e_shnum
&& i
< filedata
->dump
.num_dump_sects
;
18008 dump_type dump
= filedata
->dump
.dump_sects
[i
];
18010 if (filedata
->is_separate
&& ! process_links
)
18011 dump
&= DEBUG_DUMP
;
18013 if (dump
& AUTO_DUMP
)
18015 switch (section
->sh_type
)
18018 /* FIXME: There are lots of different type of section that have
18019 SHT_PROGBITS set in their header - code, debug info, etc. So
18020 we should check the section's name and interpret its contents
18021 that way, rather than just defaulting to a byte dump. */
18022 #ifdef SUPPORT_DISASSEMBLY
18023 res
&= disassemble_section (section
, filedata
);
18025 res
&= dump_section_as_bytes (section
, filedata
, false);
18031 res
&= dump_symbol_section (section
, filedata
);
18035 res
&= dump_section_as_strings (section
, filedata
);
18041 res
&= display_relocations (section
, filedata
, true);
18045 res
&= process_notes_at (filedata
, section
, section
->sh_offset
,
18046 section
->sh_size
, section
->sh_addralign
);
18050 inform (_("Unable to display section %d - it has a NULL type\n"), i
);
18054 inform (_("Unable to display section %d - it has no contents\n"), i
);
18060 case SHT_GNU_ATTRIBUTES
:
18061 /* FIXME: Implement these. */
18062 /* Fall through. */
18064 /* FIXME: Add Proc and OS specific section types ? */
18065 warn (_("Unable to determine how to dump section %d (type %#x)\n"),
18066 i
, section
->sh_type
);
18072 #ifdef SUPPORT_DISASSEMBLY
18073 if (dump
& DISASS_DUMP
)
18075 if (! disassemble_section (section
, filedata
))
18079 if (dump
& HEX_DUMP
)
18081 if (! dump_section_as_bytes (section
, filedata
, false))
18085 if (dump
& RELOC_DUMP
)
18087 if (! dump_section_as_bytes (section
, filedata
, true))
18091 if (dump
& STRING_DUMP
)
18093 if (! dump_section_as_strings (section
, filedata
))
18097 if (dump
& DEBUG_DUMP
)
18099 if (! display_debug_section (i
, section
, filedata
))
18103 #ifdef ENABLE_LIBCTF
18104 if (dump
& CTF_DUMP
)
18106 if (! dump_section_as_ctf (section
, filedata
))
18110 if (dump
& SFRAME_DUMP
)
18112 if (! display_debug_section (i
, section
, filedata
))
18117 if (! filedata
->is_separate
)
18119 /* Check to see if the user requested a
18120 dump of a section that does not exist. */
18121 for (; i
< filedata
->dump
.num_dump_sects
; i
++)
18122 if (filedata
->dump
.dump_sects
[i
])
18124 warn (_("Section %d was not dumped because it does not exist!\n"), i
);
18133 process_mips_fpe_exception (int mask
)
18139 if (mask
& OEX_FPU_INEX
)
18140 fputs ("INEX", stdout
), first
= false;
18141 if (mask
& OEX_FPU_UFLO
)
18142 printf ("%sUFLO", first
? "" : "|"), first
= false;
18143 if (mask
& OEX_FPU_OFLO
)
18144 printf ("%sOFLO", first
? "" : "|"), first
= false;
18145 if (mask
& OEX_FPU_DIV0
)
18146 printf ("%sDIV0", first
? "" : "|"), first
= false;
18147 if (mask
& OEX_FPU_INVAL
)
18148 printf ("%sINVAL", first
? "" : "|");
18151 fputs ("0", stdout
);
18154 /* Display's the value of TAG at location P. If TAG is
18155 greater than 0 it is assumed to be an unknown tag, and
18156 a message is printed to this effect. Otherwise it is
18157 assumed that a message has already been printed.
18159 If the bottom bit of TAG is set it assumed to have a
18160 string value, otherwise it is assumed to have an integer
18163 Returns an updated P pointing to the first unread byte
18164 beyond the end of TAG's value.
18166 Reads at or beyond END will not be made. */
18168 static unsigned char *
18169 display_tag_value (signed int tag
,
18171 const unsigned char * const end
)
18176 printf (" Tag_unknown_%d: ", tag
);
18180 warn (_("<corrupt tag>\n"));
18184 /* PR 17531 file: 027-19978-0.004. */
18185 size_t maxlen
= end
- p
;
18190 maxlen
-= 1; /* Remove \0 from the character count. */
18191 print_symbol_name ((int) maxlen
, (const char *) p
);
18192 size_t len
= strnlen ((char *) p
, maxlen
);
18193 if (len
== maxlen
&& p
[maxlen
] != '\0')
18194 printf (_("<corrupt string tag>"));
18199 printf (_("<corrupt string tag>"));
18200 p
= (unsigned char *) end
;
18206 READ_ULEB (val
, p
, end
);
18207 printf ("%" PRId64
" (0x%" PRIx64
")\n", val
, val
);
18214 /* ARC ABI attributes section. */
18216 static unsigned char *
18217 display_arc_attribute (unsigned char * p
,
18218 const unsigned char * const end
)
18223 READ_ULEB (tag
, p
, end
);
18227 case Tag_ARC_PCS_config
:
18228 READ_ULEB (val
, p
, end
);
18229 printf (" Tag_ARC_PCS_config: ");
18233 printf (_("Absent/Non standard\n"));
18236 printf (_("Bare metal/mwdt\n"));
18239 printf (_("Bare metal/newlib\n"));
18242 printf (_("Linux/uclibc\n"));
18245 printf (_("Linux/glibc\n"));
18248 printf (_("Unknown\n"));
18253 case Tag_ARC_CPU_base
:
18254 READ_ULEB (val
, p
, end
);
18255 printf (" Tag_ARC_CPU_base: ");
18260 printf (_("Absent\n"));
18262 case TAG_CPU_ARC6xx
:
18263 printf ("ARC6xx\n");
18265 case TAG_CPU_ARC7xx
:
18266 printf ("ARC7xx\n");
18268 case TAG_CPU_ARCEM
:
18269 printf ("ARCEM\n");
18271 case TAG_CPU_ARCHS
:
18272 printf ("ARCHS\n");
18277 case Tag_ARC_CPU_variation
:
18278 READ_ULEB (val
, p
, end
);
18279 printf (" Tag_ARC_CPU_variation: ");
18283 if (val
> 0 && val
< 16)
18284 printf ("Core%d\n", val
);
18286 printf ("Unknown\n");
18290 printf (_("Absent\n"));
18295 case Tag_ARC_CPU_name
:
18296 printf (" Tag_ARC_CPU_name: ");
18297 p
= display_tag_value (-1, p
, end
);
18300 case Tag_ARC_ABI_rf16
:
18301 READ_ULEB (val
, p
, end
);
18302 printf (" Tag_ARC_ABI_rf16: %s\n", val
? _("yes") : _("no"));
18305 case Tag_ARC_ABI_osver
:
18306 READ_ULEB (val
, p
, end
);
18307 printf (" Tag_ARC_ABI_osver: v%d\n", val
);
18310 case Tag_ARC_ABI_pic
:
18311 case Tag_ARC_ABI_sda
:
18312 READ_ULEB (val
, p
, end
);
18313 printf (tag
== Tag_ARC_ABI_sda
? " Tag_ARC_ABI_sda: "
18314 : " Tag_ARC_ABI_pic: ");
18318 printf (_("Absent\n"));
18327 printf (_("Unknown\n"));
18332 case Tag_ARC_ABI_tls
:
18333 READ_ULEB (val
, p
, end
);
18334 printf (" Tag_ARC_ABI_tls: %s\n", val
? "r25": "none");
18337 case Tag_ARC_ABI_enumsize
:
18338 READ_ULEB (val
, p
, end
);
18339 printf (" Tag_ARC_ABI_enumsize: %s\n", val
? _("default") :
18343 case Tag_ARC_ABI_exceptions
:
18344 READ_ULEB (val
, p
, end
);
18345 printf (" Tag_ARC_ABI_exceptions: %s\n", val
? _("OPTFP")
18349 case Tag_ARC_ABI_double_size
:
18350 READ_ULEB (val
, p
, end
);
18351 printf (" Tag_ARC_ABI_double_size: %d\n", val
);
18354 case Tag_ARC_ISA_config
:
18355 printf (" Tag_ARC_ISA_config: ");
18356 p
= display_tag_value (-1, p
, end
);
18359 case Tag_ARC_ISA_apex
:
18360 printf (" Tag_ARC_ISA_apex: ");
18361 p
= display_tag_value (-1, p
, end
);
18364 case Tag_ARC_ISA_mpy_option
:
18365 READ_ULEB (val
, p
, end
);
18366 printf (" Tag_ARC_ISA_mpy_option: %d\n", val
);
18369 case Tag_ARC_ATR_version
:
18370 READ_ULEB (val
, p
, end
);
18371 printf (" Tag_ARC_ATR_version: %d\n", val
);
18375 return display_tag_value (tag
& 1, p
, end
);
18381 /* ARM EABI attributes section. */
18386 /* 0 = special, 1 = string, 2 = uleb123, > 0x80 == table lookup. */
18388 const char *const *table
;
18389 } arm_attr_public_tag
;
18391 static const char *const arm_attr_tag_CPU_arch
[] =
18392 {"Pre-v4", "v4", "v4T", "v5T", "v5TE", "v5TEJ", "v6", "v6KZ", "v6T2",
18393 "v6K", "v7", "v6-M", "v6S-M", "v7E-M", "v8", "v8-R", "v8-M.baseline",
18394 "v8-M.mainline", "v8.1-A", "v8.2-A", "v8.3-A",
18395 "v8.1-M.mainline", "v9"};
18396 static const char *const arm_attr_tag_ARM_ISA_use
[] = {"No", "Yes"};
18397 static const char *const arm_attr_tag_THUMB_ISA_use
[] =
18398 {"No", "Thumb-1", "Thumb-2", "Yes"};
18399 static const char *const arm_attr_tag_FP_arch
[] =
18400 {"No", "VFPv1", "VFPv2", "VFPv3", "VFPv3-D16", "VFPv4", "VFPv4-D16",
18401 "FP for ARMv8", "FPv5/FP-D16 for ARMv8"};
18402 static const char *const arm_attr_tag_WMMX_arch
[] = {"No", "WMMXv1", "WMMXv2"};
18403 static const char *const arm_attr_tag_Advanced_SIMD_arch
[] =
18404 {"No", "NEONv1", "NEONv1 with Fused-MAC", "NEON for ARMv8",
18405 "NEON for ARMv8.1"};
18406 static const char *const arm_attr_tag_PCS_config
[] =
18407 {"None", "Bare platform", "Linux application", "Linux DSO", "PalmOS 2004",
18408 "PalmOS (reserved)", "SymbianOS 2004", "SymbianOS (reserved)"};
18409 static const char *const arm_attr_tag_ABI_PCS_R9_use
[] =
18410 {"V6", "SB", "TLS", "Unused"};
18411 static const char *const arm_attr_tag_ABI_PCS_RW_data
[] =
18412 {"Absolute", "PC-relative", "SB-relative", "None"};
18413 static const char *const arm_attr_tag_ABI_PCS_RO_data
[] =
18414 {"Absolute", "PC-relative", "None"};
18415 static const char *const arm_attr_tag_ABI_PCS_GOT_use
[] =
18416 {"None", "direct", "GOT-indirect"};
18417 static const char *const arm_attr_tag_ABI_PCS_wchar_t
[] =
18418 {"None", "??? 1", "2", "??? 3", "4"};
18419 static const char *const arm_attr_tag_ABI_FP_rounding
[] = {"Unused", "Needed"};
18420 static const char *const arm_attr_tag_ABI_FP_denormal
[] =
18421 {"Unused", "Needed", "Sign only"};
18422 static const char *const arm_attr_tag_ABI_FP_exceptions
[] = {"Unused", "Needed"};
18423 static const char *const arm_attr_tag_ABI_FP_user_exceptions
[] = {"Unused", "Needed"};
18424 static const char *const arm_attr_tag_ABI_FP_number_model
[] =
18425 {"Unused", "Finite", "RTABI", "IEEE 754"};
18426 static const char *const arm_attr_tag_ABI_enum_size
[] =
18427 {"Unused", "small", "int", "forced to int"};
18428 static const char *const arm_attr_tag_ABI_HardFP_use
[] =
18429 {"As Tag_FP_arch", "SP only", "Reserved", "Deprecated"};
18430 static const char *const arm_attr_tag_ABI_VFP_args
[] =
18431 {"AAPCS", "VFP registers", "custom", "compatible"};
18432 static const char *const arm_attr_tag_ABI_WMMX_args
[] =
18433 {"AAPCS", "WMMX registers", "custom"};
18434 static const char *const arm_attr_tag_ABI_optimization_goals
[] =
18435 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
18436 "Aggressive Size", "Prefer Debug", "Aggressive Debug"};
18437 static const char *const arm_attr_tag_ABI_FP_optimization_goals
[] =
18438 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
18439 "Aggressive Size", "Prefer Accuracy", "Aggressive Accuracy"};
18440 static const char *const arm_attr_tag_CPU_unaligned_access
[] = {"None", "v6"};
18441 static const char *const arm_attr_tag_FP_HP_extension
[] =
18442 {"Not Allowed", "Allowed"};
18443 static const char *const arm_attr_tag_ABI_FP_16bit_format
[] =
18444 {"None", "IEEE 754", "Alternative Format"};
18445 static const char *const arm_attr_tag_DSP_extension
[] =
18446 {"Follow architecture", "Allowed"};
18447 static const char *const arm_attr_tag_MPextension_use
[] =
18448 {"Not Allowed", "Allowed"};
18449 static const char *const arm_attr_tag_DIV_use
[] =
18450 {"Allowed in Thumb-ISA, v7-R or v7-M", "Not allowed",
18451 "Allowed in v7-A with integer division extension"};
18452 static const char *const arm_attr_tag_T2EE_use
[] = {"Not Allowed", "Allowed"};
18453 static const char *const arm_attr_tag_Virtualization_use
[] =
18454 {"Not Allowed", "TrustZone", "Virtualization Extensions",
18455 "TrustZone and Virtualization Extensions"};
18456 static const char *const arm_attr_tag_MPextension_use_legacy
[] =
18457 {"Not Allowed", "Allowed"};
18459 static const char *const arm_attr_tag_MVE_arch
[] =
18460 {"No MVE", "MVE Integer only", "MVE Integer and FP"};
18462 static const char * arm_attr_tag_PAC_extension
[] =
18463 {"No PAC/AUT instructions",
18464 "PAC/AUT instructions permitted in the NOP space",
18465 "PAC/AUT instructions permitted in the NOP and in the non-NOP space"};
18467 static const char * arm_attr_tag_BTI_extension
[] =
18468 {"BTI instructions not permitted",
18469 "BTI instructions permitted in the NOP space",
18470 "BTI instructions permitted in the NOP and in the non-NOP space"};
18472 static const char * arm_attr_tag_BTI_use
[] =
18473 {"Compiled without branch target enforcement",
18474 "Compiled with branch target enforcement"};
18476 static const char * arm_attr_tag_PACRET_use
[] =
18477 {"Compiled without return address signing and authentication",
18478 "Compiled with return address signing and authentication"};
18480 #define LOOKUP(id, name) \
18481 {id, #name, 0x80 | ARRAY_SIZE(arm_attr_tag_##name), arm_attr_tag_##name}
18482 static arm_attr_public_tag arm_attr_public_tags
[] =
18484 {4, "CPU_raw_name", 1, NULL
},
18485 {5, "CPU_name", 1, NULL
},
18486 LOOKUP(6, CPU_arch
),
18487 {7, "CPU_arch_profile", 0, NULL
},
18488 LOOKUP(8, ARM_ISA_use
),
18489 LOOKUP(9, THUMB_ISA_use
),
18490 LOOKUP(10, FP_arch
),
18491 LOOKUP(11, WMMX_arch
),
18492 LOOKUP(12, Advanced_SIMD_arch
),
18493 LOOKUP(13, PCS_config
),
18494 LOOKUP(14, ABI_PCS_R9_use
),
18495 LOOKUP(15, ABI_PCS_RW_data
),
18496 LOOKUP(16, ABI_PCS_RO_data
),
18497 LOOKUP(17, ABI_PCS_GOT_use
),
18498 LOOKUP(18, ABI_PCS_wchar_t
),
18499 LOOKUP(19, ABI_FP_rounding
),
18500 LOOKUP(20, ABI_FP_denormal
),
18501 LOOKUP(21, ABI_FP_exceptions
),
18502 LOOKUP(22, ABI_FP_user_exceptions
),
18503 LOOKUP(23, ABI_FP_number_model
),
18504 {24, "ABI_align_needed", 0, NULL
},
18505 {25, "ABI_align_preserved", 0, NULL
},
18506 LOOKUP(26, ABI_enum_size
),
18507 LOOKUP(27, ABI_HardFP_use
),
18508 LOOKUP(28, ABI_VFP_args
),
18509 LOOKUP(29, ABI_WMMX_args
),
18510 LOOKUP(30, ABI_optimization_goals
),
18511 LOOKUP(31, ABI_FP_optimization_goals
),
18512 {32, "compatibility", 0, NULL
},
18513 LOOKUP(34, CPU_unaligned_access
),
18514 LOOKUP(36, FP_HP_extension
),
18515 LOOKUP(38, ABI_FP_16bit_format
),
18516 LOOKUP(42, MPextension_use
),
18517 LOOKUP(44, DIV_use
),
18518 LOOKUP(46, DSP_extension
),
18519 LOOKUP(48, MVE_arch
),
18520 LOOKUP(50, PAC_extension
),
18521 LOOKUP(52, BTI_extension
),
18522 LOOKUP(74, BTI_use
),
18523 LOOKUP(76, PACRET_use
),
18524 {64, "nodefaults", 0, NULL
},
18525 {65, "also_compatible_with", 0, NULL
},
18526 LOOKUP(66, T2EE_use
),
18527 {67, "conformance", 1, NULL
},
18528 LOOKUP(68, Virtualization_use
),
18529 LOOKUP(70, MPextension_use_legacy
)
18533 static unsigned char *
18534 display_arm_attribute (unsigned char * p
,
18535 const unsigned char * const end
)
18539 arm_attr_public_tag
* attr
;
18543 READ_ULEB (tag
, p
, end
);
18545 for (i
= 0; i
< ARRAY_SIZE (arm_attr_public_tags
); i
++)
18547 if (arm_attr_public_tags
[i
].tag
== tag
)
18549 attr
= &arm_attr_public_tags
[i
];
18556 printf (" Tag_%s: ", attr
->name
);
18557 switch (attr
->type
)
18562 case 7: /* Tag_CPU_arch_profile. */
18563 READ_ULEB (val
, p
, end
);
18566 case 0: printf (_("None\n")); break;
18567 case 'A': printf (_("Application\n")); break;
18568 case 'R': printf (_("Realtime\n")); break;
18569 case 'M': printf (_("Microcontroller\n")); break;
18570 case 'S': printf (_("Application or Realtime\n")); break;
18571 default: printf ("??? (%d)\n", val
); break;
18575 case 24: /* Tag_align_needed. */
18576 READ_ULEB (val
, p
, end
);
18579 case 0: printf (_("None\n")); break;
18580 case 1: printf (_("8-byte\n")); break;
18581 case 2: printf (_("4-byte\n")); break;
18582 case 3: printf ("??? 3\n"); break;
18585 printf (_("8-byte and up to %d-byte extended\n"),
18588 printf ("??? (%d)\n", val
);
18593 case 25: /* Tag_align_preserved. */
18594 READ_ULEB (val
, p
, end
);
18597 case 0: printf (_("None\n")); break;
18598 case 1: printf (_("8-byte, except leaf SP\n")); break;
18599 case 2: printf (_("8-byte\n")); break;
18600 case 3: printf ("??? 3\n"); break;
18603 printf (_("8-byte and up to %d-byte extended\n"),
18606 printf ("??? (%d)\n", val
);
18611 case 32: /* Tag_compatibility. */
18613 READ_ULEB (val
, p
, end
);
18614 printf (_("flag = %d, vendor = "), val
);
18617 size_t maxlen
= (end
- p
) - 1;
18619 print_symbol_name ((int) maxlen
, (const char *) p
);
18620 p
+= strnlen ((char *) p
, maxlen
) + 1;
18624 printf (_("<corrupt>"));
18625 p
= (unsigned char *) end
;
18631 case 64: /* Tag_nodefaults. */
18632 /* PR 17531: file: 001-505008-0.01. */
18635 printf (_("True\n"));
18638 case 65: /* Tag_also_compatible_with. */
18639 READ_ULEB (val
, p
, end
);
18640 if (val
== 6 /* Tag_CPU_arch. */)
18642 READ_ULEB (val
, p
, end
);
18643 if ((unsigned int) val
>= ARRAY_SIZE (arm_attr_tag_CPU_arch
))
18644 printf ("??? (%d)\n", val
);
18646 printf ("%s\n", arm_attr_tag_CPU_arch
[val
]);
18650 while (p
< end
&& *(p
++) != '\0' /* NUL terminator. */)
18655 printf (_("<unknown: %d>\n"), tag
);
18661 return display_tag_value (-1, p
, end
);
18663 return display_tag_value (0, p
, end
);
18666 assert (attr
->type
& 0x80);
18667 READ_ULEB (val
, p
, end
);
18668 type
= attr
->type
& 0x7f;
18670 printf ("??? (%d)\n", val
);
18672 printf ("%s\n", attr
->table
[val
]);
18677 return display_tag_value (tag
, p
, end
);
18680 static unsigned char *
18681 display_gnu_attribute (unsigned char * p
,
18682 unsigned char * (* display_proc_gnu_attribute
)
18683 (unsigned char *, unsigned int, const unsigned char * const),
18684 const unsigned char * const end
)
18689 READ_ULEB (tag
, p
, end
);
18691 /* Tag_compatibility is the only generic GNU attribute defined at
18695 READ_ULEB (val
, p
, end
);
18697 printf (_("flag = %d, vendor = "), val
);
18700 printf (_("<corrupt>\n"));
18701 warn (_("corrupt vendor attribute\n"));
18707 size_t maxlen
= (end
- p
) - 1;
18709 print_symbol_name ((int) maxlen
, (const char *) p
);
18710 p
+= strnlen ((char *) p
, maxlen
) + 1;
18714 printf (_("<corrupt>"));
18715 p
= (unsigned char *) end
;
18722 if ((tag
& 2) == 0 && display_proc_gnu_attribute
)
18723 return display_proc_gnu_attribute (p
, tag
, end
);
18725 return display_tag_value (tag
, p
, end
);
18728 static unsigned char *
18729 display_m68k_gnu_attribute (unsigned char * p
,
18731 const unsigned char * const end
)
18735 if (tag
== Tag_GNU_M68K_ABI_FP
)
18737 printf (" Tag_GNU_M68K_ABI_FP: ");
18740 printf (_("<corrupt>\n"));
18743 READ_ULEB (val
, p
, end
);
18746 printf ("(%#x), ", val
);
18751 printf (_("unspecified hard/soft float\n"));
18754 printf (_("hard float\n"));
18757 printf (_("soft float\n"));
18763 return display_tag_value (tag
& 1, p
, end
);
18766 static unsigned char *
18767 display_power_gnu_attribute (unsigned char * p
,
18769 const unsigned char * const end
)
18773 if (tag
== Tag_GNU_Power_ABI_FP
)
18775 printf (" Tag_GNU_Power_ABI_FP: ");
18778 printf (_("<corrupt>\n"));
18781 READ_ULEB (val
, p
, end
);
18784 printf ("(%#x), ", val
);
18789 printf (_("unspecified hard/soft float, "));
18792 printf (_("hard float, "));
18795 printf (_("soft float, "));
18798 printf (_("single-precision hard float, "));
18805 printf (_("unspecified long double\n"));
18808 printf (_("128-bit IBM long double\n"));
18811 printf (_("64-bit long double\n"));
18814 printf (_("128-bit IEEE long double\n"));
18820 if (tag
== Tag_GNU_Power_ABI_Vector
)
18822 printf (" Tag_GNU_Power_ABI_Vector: ");
18825 printf (_("<corrupt>\n"));
18828 READ_ULEB (val
, p
, end
);
18831 printf ("(%#x), ", val
);
18836 printf (_("unspecified\n"));
18839 printf (_("generic\n"));
18842 printf ("AltiVec\n");
18851 if (tag
== Tag_GNU_Power_ABI_Struct_Return
)
18853 printf (" Tag_GNU_Power_ABI_Struct_Return: ");
18856 printf (_("<corrupt>\n"));
18859 READ_ULEB (val
, p
, end
);
18862 printf ("(%#x), ", val
);
18867 printf (_("unspecified\n"));
18870 printf ("r3/r4\n");
18873 printf (_("memory\n"));
18882 return display_tag_value (tag
& 1, p
, end
);
18885 static unsigned char *
18886 display_s390_gnu_attribute (unsigned char * p
,
18888 const unsigned char * const end
)
18892 if (tag
== Tag_GNU_S390_ABI_Vector
)
18894 printf (" Tag_GNU_S390_ABI_Vector: ");
18895 READ_ULEB (val
, p
, end
);
18900 printf (_("any\n"));
18903 printf (_("software\n"));
18906 printf (_("hardware\n"));
18909 printf ("??? (%d)\n", val
);
18915 return display_tag_value (tag
& 1, p
, end
);
18919 display_sparc_hwcaps (unsigned int mask
)
18925 if (mask
& ELF_SPARC_HWCAP_MUL32
)
18926 fputs ("mul32", stdout
), first
= false;
18927 if (mask
& ELF_SPARC_HWCAP_DIV32
)
18928 printf ("%sdiv32", first
? "" : "|"), first
= false;
18929 if (mask
& ELF_SPARC_HWCAP_FSMULD
)
18930 printf ("%sfsmuld", first
? "" : "|"), first
= false;
18931 if (mask
& ELF_SPARC_HWCAP_V8PLUS
)
18932 printf ("%sv8plus", first
? "" : "|"), first
= false;
18933 if (mask
& ELF_SPARC_HWCAP_POPC
)
18934 printf ("%spopc", first
? "" : "|"), first
= false;
18935 if (mask
& ELF_SPARC_HWCAP_VIS
)
18936 printf ("%svis", first
? "" : "|"), first
= false;
18937 if (mask
& ELF_SPARC_HWCAP_VIS2
)
18938 printf ("%svis2", first
? "" : "|"), first
= false;
18939 if (mask
& ELF_SPARC_HWCAP_ASI_BLK_INIT
)
18940 printf ("%sASIBlkInit", first
? "" : "|"), first
= false;
18941 if (mask
& ELF_SPARC_HWCAP_FMAF
)
18942 printf ("%sfmaf", first
? "" : "|"), first
= false;
18943 if (mask
& ELF_SPARC_HWCAP_VIS3
)
18944 printf ("%svis3", first
? "" : "|"), first
= false;
18945 if (mask
& ELF_SPARC_HWCAP_HPC
)
18946 printf ("%shpc", first
? "" : "|"), first
= false;
18947 if (mask
& ELF_SPARC_HWCAP_RANDOM
)
18948 printf ("%srandom", first
? "" : "|"), first
= false;
18949 if (mask
& ELF_SPARC_HWCAP_TRANS
)
18950 printf ("%strans", first
? "" : "|"), first
= false;
18951 if (mask
& ELF_SPARC_HWCAP_FJFMAU
)
18952 printf ("%sfjfmau", first
? "" : "|"), first
= false;
18953 if (mask
& ELF_SPARC_HWCAP_IMA
)
18954 printf ("%sima", first
? "" : "|"), first
= false;
18955 if (mask
& ELF_SPARC_HWCAP_ASI_CACHE_SPARING
)
18956 printf ("%scspare", first
? "" : "|"), first
= false;
18959 fputc ('0', stdout
);
18960 fputc ('\n', stdout
);
18964 display_sparc_hwcaps2 (unsigned int mask
)
18970 if (mask
& ELF_SPARC_HWCAP2_FJATHPLUS
)
18971 fputs ("fjathplus", stdout
), first
= false;
18972 if (mask
& ELF_SPARC_HWCAP2_VIS3B
)
18973 printf ("%svis3b", first
? "" : "|"), first
= false;
18974 if (mask
& ELF_SPARC_HWCAP2_ADP
)
18975 printf ("%sadp", first
? "" : "|"), first
= false;
18976 if (mask
& ELF_SPARC_HWCAP2_SPARC5
)
18977 printf ("%ssparc5", first
? "" : "|"), first
= false;
18978 if (mask
& ELF_SPARC_HWCAP2_MWAIT
)
18979 printf ("%smwait", first
? "" : "|"), first
= false;
18980 if (mask
& ELF_SPARC_HWCAP2_XMPMUL
)
18981 printf ("%sxmpmul", first
? "" : "|"), first
= false;
18982 if (mask
& ELF_SPARC_HWCAP2_XMONT
)
18983 printf ("%sxmont2", first
? "" : "|"), first
= false;
18984 if (mask
& ELF_SPARC_HWCAP2_NSEC
)
18985 printf ("%snsec", first
? "" : "|"), first
= false;
18986 if (mask
& ELF_SPARC_HWCAP2_FJATHHPC
)
18987 printf ("%sfjathhpc", first
? "" : "|"), first
= false;
18988 if (mask
& ELF_SPARC_HWCAP2_FJDES
)
18989 printf ("%sfjdes", first
? "" : "|"), first
= false;
18990 if (mask
& ELF_SPARC_HWCAP2_FJAES
)
18991 printf ("%sfjaes", first
? "" : "|"), first
= false;
18994 fputc ('0', stdout
);
18995 fputc ('\n', stdout
);
18998 static unsigned char *
18999 display_sparc_gnu_attribute (unsigned char * p
,
19001 const unsigned char * const end
)
19005 if (tag
== Tag_GNU_Sparc_HWCAPS
)
19007 READ_ULEB (val
, p
, end
);
19008 printf (" Tag_GNU_Sparc_HWCAPS: ");
19009 display_sparc_hwcaps (val
);
19012 if (tag
== Tag_GNU_Sparc_HWCAPS2
)
19014 READ_ULEB (val
, p
, end
);
19015 printf (" Tag_GNU_Sparc_HWCAPS2: ");
19016 display_sparc_hwcaps2 (val
);
19020 return display_tag_value (tag
, p
, end
);
19024 print_mips_fp_abi_value (unsigned int val
)
19028 case Val_GNU_MIPS_ABI_FP_ANY
:
19029 printf (_("Hard or soft float\n"));
19031 case Val_GNU_MIPS_ABI_FP_DOUBLE
:
19032 printf (_("Hard float (double precision)\n"));
19034 case Val_GNU_MIPS_ABI_FP_SINGLE
:
19035 printf (_("Hard float (single precision)\n"));
19037 case Val_GNU_MIPS_ABI_FP_SOFT
:
19038 printf (_("Soft float\n"));
19040 case Val_GNU_MIPS_ABI_FP_OLD_64
:
19041 printf (_("Hard float (MIPS32r2 64-bit FPU 12 callee-saved)\n"));
19043 case Val_GNU_MIPS_ABI_FP_XX
:
19044 printf (_("Hard float (32-bit CPU, Any FPU)\n"));
19046 case Val_GNU_MIPS_ABI_FP_64
:
19047 printf (_("Hard float (32-bit CPU, 64-bit FPU)\n"));
19049 case Val_GNU_MIPS_ABI_FP_64A
:
19050 printf (_("Hard float compat (32-bit CPU, 64-bit FPU)\n"));
19052 case Val_GNU_MIPS_ABI_FP_NAN2008
:
19053 printf (_("NaN 2008 compatibility\n"));
19056 printf ("??? (%d)\n", val
);
19061 static unsigned char *
19062 display_mips_gnu_attribute (unsigned char * p
,
19064 const unsigned char * const end
)
19066 if (tag
== Tag_GNU_MIPS_ABI_FP
)
19070 printf (" Tag_GNU_MIPS_ABI_FP: ");
19071 READ_ULEB (val
, p
, end
);
19072 print_mips_fp_abi_value (val
);
19076 if (tag
== Tag_GNU_MIPS_ABI_MSA
)
19080 printf (" Tag_GNU_MIPS_ABI_MSA: ");
19081 READ_ULEB (val
, p
, end
);
19085 case Val_GNU_MIPS_ABI_MSA_ANY
:
19086 printf (_("Any MSA or not\n"));
19088 case Val_GNU_MIPS_ABI_MSA_128
:
19089 printf (_("128-bit MSA\n"));
19092 printf ("??? (%d)\n", val
);
19098 return display_tag_value (tag
& 1, p
, end
);
19101 static unsigned char *
19102 display_tic6x_attribute (unsigned char * p
,
19103 const unsigned char * const end
)
19108 READ_ULEB (tag
, p
, end
);
19113 printf (" Tag_ISA: ");
19114 READ_ULEB (val
, p
, end
);
19118 case C6XABI_Tag_ISA_none
:
19119 printf (_("None\n"));
19121 case C6XABI_Tag_ISA_C62X
:
19124 case C6XABI_Tag_ISA_C67X
:
19127 case C6XABI_Tag_ISA_C67XP
:
19128 printf ("C67x+\n");
19130 case C6XABI_Tag_ISA_C64X
:
19133 case C6XABI_Tag_ISA_C64XP
:
19134 printf ("C64x+\n");
19136 case C6XABI_Tag_ISA_C674X
:
19137 printf ("C674x\n");
19140 printf ("??? (%d)\n", val
);
19145 case Tag_ABI_wchar_t
:
19146 printf (" Tag_ABI_wchar_t: ");
19147 READ_ULEB (val
, p
, end
);
19151 printf (_("Not used\n"));
19154 printf (_("2 bytes\n"));
19157 printf (_("4 bytes\n"));
19160 printf ("??? (%d)\n", val
);
19165 case Tag_ABI_stack_align_needed
:
19166 printf (" Tag_ABI_stack_align_needed: ");
19167 READ_ULEB (val
, p
, end
);
19171 printf (_("8-byte\n"));
19174 printf (_("16-byte\n"));
19177 printf ("??? (%d)\n", val
);
19182 case Tag_ABI_stack_align_preserved
:
19183 READ_ULEB (val
, p
, end
);
19184 printf (" Tag_ABI_stack_align_preserved: ");
19188 printf (_("8-byte\n"));
19191 printf (_("16-byte\n"));
19194 printf ("??? (%d)\n", val
);
19200 READ_ULEB (val
, p
, end
);
19201 printf (" Tag_ABI_DSBT: ");
19205 printf (_("DSBT addressing not used\n"));
19208 printf (_("DSBT addressing used\n"));
19211 printf ("??? (%d)\n", val
);
19217 READ_ULEB (val
, p
, end
);
19218 printf (" Tag_ABI_PID: ");
19222 printf (_("Data addressing position-dependent\n"));
19225 printf (_("Data addressing position-independent, GOT near DP\n"));
19228 printf (_("Data addressing position-independent, GOT far from DP\n"));
19231 printf ("??? (%d)\n", val
);
19237 READ_ULEB (val
, p
, end
);
19238 printf (" Tag_ABI_PIC: ");
19242 printf (_("Code addressing position-dependent\n"));
19245 printf (_("Code addressing position-independent\n"));
19248 printf ("??? (%d)\n", val
);
19253 case Tag_ABI_array_object_alignment
:
19254 READ_ULEB (val
, p
, end
);
19255 printf (" Tag_ABI_array_object_alignment: ");
19259 printf (_("8-byte\n"));
19262 printf (_("4-byte\n"));
19265 printf (_("16-byte\n"));
19268 printf ("??? (%d)\n", val
);
19273 case Tag_ABI_array_object_align_expected
:
19274 READ_ULEB (val
, p
, end
);
19275 printf (" Tag_ABI_array_object_align_expected: ");
19279 printf (_("8-byte\n"));
19282 printf (_("4-byte\n"));
19285 printf (_("16-byte\n"));
19288 printf ("??? (%d)\n", val
);
19293 case Tag_ABI_compatibility
:
19295 READ_ULEB (val
, p
, end
);
19296 printf (" Tag_ABI_compatibility: ");
19297 printf (_("flag = %d, vendor = "), val
);
19300 size_t maxlen
= (end
- p
) - 1;
19302 print_symbol_name ((int) maxlen
, (const char *) p
);
19303 p
+= strnlen ((char *) p
, maxlen
) + 1;
19307 printf (_("<corrupt>"));
19308 p
= (unsigned char *) end
;
19314 case Tag_ABI_conformance
:
19316 printf (" Tag_ABI_conformance: \"");
19319 size_t maxlen
= (end
- p
) - 1;
19321 print_symbol_name ((int) maxlen
, (const char *) p
);
19322 p
+= strnlen ((char *) p
, maxlen
) + 1;
19326 printf (_("<corrupt>"));
19327 p
= (unsigned char *) end
;
19334 return display_tag_value (tag
, p
, end
);
19338 display_raw_attribute (unsigned char * p
, unsigned char const * const end
)
19341 size_t bytes
= end
- p
;
19348 int lbytes
= (bytes
> 16 ? 16 : bytes
);
19350 printf (" 0x%8.8" PRIx64
" ", addr
);
19352 for (j
= 0; j
< 16; j
++)
19355 printf ("%2.2x", p
[j
]);
19363 for (j
= 0; j
< lbytes
; j
++)
19366 if (k
>= ' ' && k
< 0x7f)
19382 static unsigned char *
19383 display_msp430_attribute (unsigned char * p
,
19384 const unsigned char * const end
)
19389 READ_ULEB (tag
, p
, end
);
19393 case OFBA_MSPABI_Tag_ISA
:
19394 printf (" Tag_ISA: ");
19395 READ_ULEB (val
, p
, end
);
19398 case 0: printf (_("None\n")); break;
19399 case 1: printf (_("MSP430\n")); break;
19400 case 2: printf (_("MSP430X\n")); break;
19401 default: printf ("??? (%" PRId64
")\n", val
); break;
19405 case OFBA_MSPABI_Tag_Code_Model
:
19406 printf (" Tag_Code_Model: ");
19407 READ_ULEB (val
, p
, end
);
19410 case 0: printf (_("None\n")); break;
19411 case 1: printf (_("Small\n")); break;
19412 case 2: printf (_("Large\n")); break;
19413 default: printf ("??? (%" PRId64
")\n", val
); break;
19417 case OFBA_MSPABI_Tag_Data_Model
:
19418 printf (" Tag_Data_Model: ");
19419 READ_ULEB (val
, p
, end
);
19422 case 0: printf (_("None\n")); break;
19423 case 1: printf (_("Small\n")); break;
19424 case 2: printf (_("Large\n")); break;
19425 case 3: printf (_("Restricted Large\n")); break;
19426 default: printf ("??? (%" PRId64
")\n", val
); break;
19431 printf (_(" <unknown tag %" PRId64
">: "), tag
);
19438 size_t maxlen
= (end
- p
) - 1;
19440 print_symbol_name ((int) maxlen
, (const char *) p
);
19441 p
+= strnlen ((char *) p
, maxlen
) + 1;
19445 printf (_("<corrupt>"));
19446 p
= (unsigned char *) end
;
19452 READ_ULEB (val
, p
, end
);
19453 printf ("%" PRId64
" (0x%" PRIx64
")\n", val
, val
);
19462 static unsigned char *
19463 display_msp430_gnu_attribute (unsigned char * p
,
19465 const unsigned char * const end
)
19467 if (tag
== Tag_GNU_MSP430_Data_Region
)
19471 printf (" Tag_GNU_MSP430_Data_Region: ");
19472 READ_ULEB (val
, p
, end
);
19476 case Val_GNU_MSP430_Data_Region_Any
:
19477 printf (_("Any Region\n"));
19479 case Val_GNU_MSP430_Data_Region_Lower
:
19480 printf (_("Lower Region Only\n"));
19483 printf ("??? (%" PRIu64
")\n", val
);
19487 return display_tag_value (tag
& 1, p
, end
);
19490 struct riscv_attr_tag_t
{
19495 static struct riscv_attr_tag_t riscv_attr_tag
[] =
19497 #define T(tag) {"Tag_RISCV_" #tag, Tag_RISCV_##tag}
19500 T(priv_spec_minor
),
19501 T(priv_spec_revision
),
19502 T(unaligned_access
),
19507 static unsigned char *
19508 display_riscv_attribute (unsigned char *p
,
19509 const unsigned char * const end
)
19513 struct riscv_attr_tag_t
*attr
= NULL
;
19516 READ_ULEB (tag
, p
, end
);
19518 /* Find the name of attribute. */
19519 for (i
= 0; i
< ARRAY_SIZE (riscv_attr_tag
); i
++)
19521 if (riscv_attr_tag
[i
].tag
== tag
)
19523 attr
= &riscv_attr_tag
[i
];
19529 printf (" %s: ", attr
->name
);
19531 return display_tag_value (tag
, p
, end
);
19535 case Tag_RISCV_priv_spec
:
19536 case Tag_RISCV_priv_spec_minor
:
19537 case Tag_RISCV_priv_spec_revision
:
19538 READ_ULEB (val
, p
, end
);
19539 printf ("%" PRIu64
"\n", val
);
19541 case Tag_RISCV_unaligned_access
:
19542 READ_ULEB (val
, p
, end
);
19546 printf (_("No unaligned access\n"));
19549 printf (_("Unaligned access\n"));
19553 case Tag_RISCV_stack_align
:
19554 READ_ULEB (val
, p
, end
);
19555 printf (_("%" PRIu64
"-bytes\n"), val
);
19557 case Tag_RISCV_arch
:
19558 p
= display_tag_value (-1, p
, end
);
19561 return display_tag_value (tag
, p
, end
);
19567 static unsigned char *
19568 display_csky_attribute (unsigned char * p
,
19569 const unsigned char * const end
)
19573 READ_ULEB (tag
, p
, end
);
19575 if (tag
>= Tag_CSKY_MAX
)
19577 return display_tag_value (-1, p
, end
);
19582 case Tag_CSKY_ARCH_NAME
:
19583 printf (" Tag_CSKY_ARCH_NAME:\t\t");
19584 return display_tag_value (-1, p
, end
);
19585 case Tag_CSKY_CPU_NAME
:
19586 printf (" Tag_CSKY_CPU_NAME:\t\t");
19587 return display_tag_value (-1, p
, end
);
19589 case Tag_CSKY_ISA_FLAGS
:
19590 printf (" Tag_CSKY_ISA_FLAGS:\t\t");
19591 return display_tag_value (0, p
, end
);
19592 case Tag_CSKY_ISA_EXT_FLAGS
:
19593 printf (" Tag_CSKY_ISA_EXT_FLAGS:\t");
19594 return display_tag_value (0, p
, end
);
19596 case Tag_CSKY_DSP_VERSION
:
19597 printf (" Tag_CSKY_DSP_VERSION:\t\t");
19598 READ_ULEB (val
, p
, end
);
19599 if (val
== VAL_CSKY_DSP_VERSION_EXTENSION
)
19600 printf ("DSP Extension\n");
19601 else if (val
== VAL_CSKY_DSP_VERSION_2
)
19602 printf ("DSP 2.0\n");
19605 case Tag_CSKY_VDSP_VERSION
:
19606 printf (" Tag_CSKY_VDSP_VERSION:\t");
19607 READ_ULEB (val
, p
, end
);
19608 printf ("VDSP Version %" PRId64
"\n", val
);
19611 case Tag_CSKY_FPU_VERSION
:
19612 printf (" Tag_CSKY_FPU_VERSION:\t\t");
19613 READ_ULEB (val
, p
, end
);
19614 if (val
== VAL_CSKY_FPU_VERSION_1
)
19615 printf ("ABIV1 FPU Version 1\n");
19616 else if (val
== VAL_CSKY_FPU_VERSION_2
)
19617 printf ("FPU Version 2\n");
19620 case Tag_CSKY_FPU_ABI
:
19621 printf (" Tag_CSKY_FPU_ABI:\t\t");
19622 READ_ULEB (val
, p
, end
);
19623 if (val
== VAL_CSKY_FPU_ABI_HARD
)
19625 else if (val
== VAL_CSKY_FPU_ABI_SOFTFP
)
19626 printf ("SoftFP\n");
19627 else if (val
== VAL_CSKY_FPU_ABI_SOFT
)
19630 case Tag_CSKY_FPU_ROUNDING
:
19631 READ_ULEB (val
, p
, end
);
19634 printf (" Tag_CSKY_FPU_ROUNDING:\t");
19635 printf ("Needed\n");
19638 case Tag_CSKY_FPU_DENORMAL
:
19639 READ_ULEB (val
, p
, end
);
19642 printf (" Tag_CSKY_FPU_DENORMAL:\t");
19643 printf ("Needed\n");
19646 case Tag_CSKY_FPU_Exception
:
19647 READ_ULEB (val
, p
, end
);
19650 printf (" Tag_CSKY_FPU_Exception:\t");
19651 printf ("Needed\n");
19654 case Tag_CSKY_FPU_NUMBER_MODULE
:
19655 printf (" Tag_CSKY_FPU_NUMBER_MODULE:\t");
19656 return display_tag_value (-1, p
, end
);
19657 case Tag_CSKY_FPU_HARDFP
:
19658 printf (" Tag_CSKY_FPU_HARDFP:\t\t");
19659 READ_ULEB (val
, p
, end
);
19660 if (val
& VAL_CSKY_FPU_HARDFP_HALF
)
19662 if (val
& VAL_CSKY_FPU_HARDFP_SINGLE
)
19663 printf (" Single");
19664 if (val
& VAL_CSKY_FPU_HARDFP_DOUBLE
)
19665 printf (" Double");
19669 return display_tag_value (tag
, p
, end
);
19675 process_attributes (Filedata
* filedata
,
19676 const char * public_name
,
19677 unsigned int proc_type
,
19678 unsigned char * (* display_pub_attribute
) (unsigned char *, const unsigned char * const),
19679 unsigned char * (* display_proc_gnu_attribute
) (unsigned char *, unsigned int, const unsigned char * const))
19681 /* Find the section header so that we get the size. */
19682 Elf_Internal_Shdr
* sect
= find_section_by_type (filedata
, proc_type
);
19684 sect
= find_section_by_type (filedata
, SHT_GNU_ATTRIBUTES
);
19687 /* No section, exit without error. */
19690 unsigned char * contents
= (unsigned char *)
19691 get_data (NULL
, filedata
, sect
->sh_offset
, 1, sect
->sh_size
, _("attributes"));
19692 if (contents
== NULL
)
19696 unsigned char * p
= contents
;
19697 /* The first character is the version of the attributes.
19698 Currently only version 1, (aka 'A') is recognised here. */
19701 printf (_("Unknown attributes version '%c'(%d) - expecting 'A'\n"), *p
, *p
);
19706 uint64_t section_len
= sect
->sh_size
- 1;
19709 while (section_len
> 0)
19712 unsigned int namelen
;
19713 bool public_section
;
19716 if (section_len
<= 4)
19718 error (_("Tag section ends prematurely\n"));
19722 attr_len
= byte_get (p
, 4);
19725 if (attr_len
> section_len
)
19727 error (_("Bad attribute length (%u > %u)\n"),
19728 (unsigned) attr_len
, (unsigned) section_len
);
19729 attr_len
= section_len
;
19732 /* PR 17531: file: 001-101425-0.004 */
19733 else if (attr_len
< 5)
19735 error (_("Attribute length of %u is too small\n"), (unsigned) attr_len
);
19740 section_len
-= attr_len
;
19743 namelen
= strnlen ((char *) p
, attr_len
) + 1;
19744 if (namelen
== 0 || namelen
>= attr_len
)
19746 error (_("Corrupt attribute section name\n"));
19751 printf (_("Attribute Section: "));
19752 print_symbol_name (INT_MAX
, (const char *) p
);
19755 if (public_name
&& streq ((char *) p
, public_name
))
19756 public_section
= true;
19758 public_section
= false;
19760 if (streq ((char *) p
, "gnu"))
19761 gnu_section
= true;
19763 gnu_section
= false;
19766 attr_len
-= namelen
;
19768 while (attr_len
> 0 && p
< contents
+ sect
->sh_size
)
19773 unsigned char * end
;
19775 /* PR binutils/17531: Safe handling of corrupt files. */
19778 error (_("Unused bytes at end of section\n"));
19785 size
= byte_get (p
, 4);
19786 if (size
> attr_len
)
19788 error (_("Bad subsection length (%u > %u)\n"),
19789 (unsigned) size
, (unsigned) attr_len
);
19793 /* PR binutils/17531: Safe handling of corrupt files. */
19796 error (_("Bad subsection length (%u < 6)\n"),
19804 end
= p
+ size
- 1;
19805 assert (end
<= contents
+ sect
->sh_size
);
19811 printf (_("File Attributes\n"));
19814 printf (_("Section Attributes:"));
19817 printf (_("Symbol Attributes:"));
19818 /* Fall through. */
19822 READ_ULEB (val
, p
, end
);
19825 printf (" %d", val
);
19830 printf (_("Unknown tag: %d\n"), tag
);
19831 public_section
= false;
19835 if (public_section
&& display_pub_attribute
!= NULL
)
19838 p
= display_pub_attribute (p
, end
);
19841 else if (gnu_section
&& display_proc_gnu_attribute
!= NULL
)
19844 p
= display_gnu_attribute (p
,
19845 display_proc_gnu_attribute
,
19851 printf (_(" Unknown attribute:\n"));
19852 display_raw_attribute (p
, end
);
19866 /* DATA points to the contents of a MIPS GOT that starts at VMA PLTGOT.
19867 Print the Address, Access and Initial fields of an entry at VMA ADDR
19868 and return the VMA of the next entry, or -1 if there was a problem.
19869 Does not read from DATA_END or beyond. */
19872 print_mips_got_entry (unsigned char * data
, uint64_t pltgot
, uint64_t addr
,
19873 unsigned char * data_end
)
19876 print_vma (addr
, LONG_HEX
);
19878 if (addr
< pltgot
+ 0xfff0)
19879 printf ("%6d(gp)", (int) (addr
- pltgot
- 0x7ff0));
19881 printf ("%10s", "");
19884 printf ("%*s", is_32bit_elf
? 8 : 16, _("<unknown>"));
19888 unsigned char * from
= data
+ addr
- pltgot
;
19890 if (from
+ (is_32bit_elf
? 4 : 8) > data_end
)
19892 warn (_("MIPS GOT entry extends beyond the end of available data\n"));
19893 printf ("%*s", is_32bit_elf
? 8 : 16, _("<corrupt>"));
19894 return (uint64_t) -1;
19898 entry
= byte_get (data
+ addr
- pltgot
, is_32bit_elf
? 4 : 8);
19899 print_vma (entry
, LONG_HEX
);
19902 return addr
+ (is_32bit_elf
? 4 : 8);
19905 /* DATA points to the contents of a MIPS PLT GOT that starts at VMA
19906 PLTGOT. Print the Address and Initial fields of an entry at VMA
19907 ADDR and return the VMA of the next entry. */
19910 print_mips_pltgot_entry (unsigned char * data
, uint64_t pltgot
, uint64_t addr
)
19913 print_vma (addr
, LONG_HEX
);
19916 printf ("%*s", is_32bit_elf
? 8 : 16, _("<unknown>"));
19921 entry
= byte_get (data
+ addr
- pltgot
, is_32bit_elf
? 4 : 8);
19922 print_vma (entry
, LONG_HEX
);
19924 return addr
+ (is_32bit_elf
? 4 : 8);
19928 print_mips_ases (unsigned int mask
)
19930 if (mask
& AFL_ASE_DSP
)
19931 fputs ("\n\tDSP ASE", stdout
);
19932 if (mask
& AFL_ASE_DSPR2
)
19933 fputs ("\n\tDSP R2 ASE", stdout
);
19934 if (mask
& AFL_ASE_DSPR3
)
19935 fputs ("\n\tDSP R3 ASE", stdout
);
19936 if (mask
& AFL_ASE_EVA
)
19937 fputs ("\n\tEnhanced VA Scheme", stdout
);
19938 if (mask
& AFL_ASE_MCU
)
19939 fputs ("\n\tMCU (MicroController) ASE", stdout
);
19940 if (mask
& AFL_ASE_MDMX
)
19941 fputs ("\n\tMDMX ASE", stdout
);
19942 if (mask
& AFL_ASE_MIPS3D
)
19943 fputs ("\n\tMIPS-3D ASE", stdout
);
19944 if (mask
& AFL_ASE_MT
)
19945 fputs ("\n\tMT ASE", stdout
);
19946 if (mask
& AFL_ASE_SMARTMIPS
)
19947 fputs ("\n\tSmartMIPS ASE", stdout
);
19948 if (mask
& AFL_ASE_VIRT
)
19949 fputs ("\n\tVZ ASE", stdout
);
19950 if (mask
& AFL_ASE_MSA
)
19951 fputs ("\n\tMSA ASE", stdout
);
19952 if (mask
& AFL_ASE_MIPS16
)
19953 fputs ("\n\tMIPS16 ASE", stdout
);
19954 if (mask
& AFL_ASE_MICROMIPS
)
19955 fputs ("\n\tMICROMIPS ASE", stdout
);
19956 if (mask
& AFL_ASE_XPA
)
19957 fputs ("\n\tXPA ASE", stdout
);
19958 if (mask
& AFL_ASE_MIPS16E2
)
19959 fputs ("\n\tMIPS16e2 ASE", stdout
);
19960 if (mask
& AFL_ASE_CRC
)
19961 fputs ("\n\tCRC ASE", stdout
);
19962 if (mask
& AFL_ASE_GINV
)
19963 fputs ("\n\tGINV ASE", stdout
);
19964 if (mask
& AFL_ASE_LOONGSON_MMI
)
19965 fputs ("\n\tLoongson MMI ASE", stdout
);
19966 if (mask
& AFL_ASE_LOONGSON_CAM
)
19967 fputs ("\n\tLoongson CAM ASE", stdout
);
19968 if (mask
& AFL_ASE_LOONGSON_EXT
)
19969 fputs ("\n\tLoongson EXT ASE", stdout
);
19970 if (mask
& AFL_ASE_LOONGSON_EXT2
)
19971 fputs ("\n\tLoongson EXT2 ASE", stdout
);
19973 fprintf (stdout
, "\n\t%s", _("None"));
19974 else if ((mask
& ~AFL_ASE_MASK
) != 0)
19975 fprintf (stdout
, "\n\t%s (%x)", _("Unknown"), mask
& ~AFL_ASE_MASK
);
19979 print_mips_isa_ext (unsigned int isa_ext
)
19984 fputs (_("None"), stdout
);
19987 fputs ("RMI XLR", stdout
);
19989 case AFL_EXT_OCTEON3
:
19990 fputs ("Cavium Networks Octeon3", stdout
);
19992 case AFL_EXT_OCTEON2
:
19993 fputs ("Cavium Networks Octeon2", stdout
);
19995 case AFL_EXT_OCTEONP
:
19996 fputs ("Cavium Networks OcteonP", stdout
);
19998 case AFL_EXT_OCTEON
:
19999 fputs ("Cavium Networks Octeon", stdout
);
20002 fputs ("Toshiba R5900", stdout
);
20005 fputs ("MIPS R4650", stdout
);
20008 fputs ("LSI R4010", stdout
);
20011 fputs ("NEC VR4100", stdout
);
20014 fputs ("Toshiba R3900", stdout
);
20016 case AFL_EXT_10000
:
20017 fputs ("MIPS R10000", stdout
);
20020 fputs ("Broadcom SB-1", stdout
);
20023 fputs ("NEC VR4111/VR4181", stdout
);
20026 fputs ("NEC VR4120", stdout
);
20029 fputs ("NEC VR5400", stdout
);
20032 fputs ("NEC VR5500", stdout
);
20034 case AFL_EXT_LOONGSON_2E
:
20035 fputs ("ST Microelectronics Loongson 2E", stdout
);
20037 case AFL_EXT_LOONGSON_2F
:
20038 fputs ("ST Microelectronics Loongson 2F", stdout
);
20040 case AFL_EXT_INTERAPTIV_MR2
:
20041 fputs ("Imagination interAptiv MR2", stdout
);
20044 fprintf (stdout
, "%s (%d)", _("Unknown"), isa_ext
);
20049 get_mips_reg_size (int reg_size
)
20051 return (reg_size
== AFL_REG_NONE
) ? 0
20052 : (reg_size
== AFL_REG_32
) ? 32
20053 : (reg_size
== AFL_REG_64
) ? 64
20054 : (reg_size
== AFL_REG_128
) ? 128
20058 /* If DUMP_GOT is true, display only the GOT related contents.
20059 Otherwise, display all MIPS specific information. */
20062 process_mips_specific (Filedata
* filedata
, bool dump_got
)
20064 Elf_Internal_Dyn
* entry
;
20065 Elf_Internal_Shdr
*sect
= NULL
;
20066 size_t liblist_offset
= 0;
20067 size_t liblistno
= 0;
20068 size_t conflictsno
= 0;
20069 size_t options_offset
= 0;
20070 size_t conflicts_offset
= 0;
20071 size_t pltrelsz
= 0;
20073 uint64_t pltgot
= 0;
20074 uint64_t mips_pltgot
= 0;
20075 uint64_t jmprel
= 0;
20076 uint64_t local_gotno
= 0;
20077 uint64_t gotsym
= 0;
20078 uint64_t symtabno
= 0;
20083 if (! process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
20084 display_mips_gnu_attribute
))
20087 sect
= find_section (filedata
, ".MIPS.abiflags");
20091 Elf_External_ABIFlags_v0
*abiflags_ext
;
20092 Elf_Internal_ABIFlags_v0 abiflags_in
;
20094 if (sizeof (Elf_External_ABIFlags_v0
) != sect
->sh_size
)
20096 error (_("Corrupt MIPS ABI Flags section.\n"));
20101 abiflags_ext
= get_data (NULL
, filedata
, sect
->sh_offset
, 1,
20102 sect
->sh_size
, _("MIPS ABI Flags section"));
20105 abiflags_in
.version
= BYTE_GET (abiflags_ext
->version
);
20106 abiflags_in
.isa_level
= BYTE_GET (abiflags_ext
->isa_level
);
20107 abiflags_in
.isa_rev
= BYTE_GET (abiflags_ext
->isa_rev
);
20108 abiflags_in
.gpr_size
= BYTE_GET (abiflags_ext
->gpr_size
);
20109 abiflags_in
.cpr1_size
= BYTE_GET (abiflags_ext
->cpr1_size
);
20110 abiflags_in
.cpr2_size
= BYTE_GET (abiflags_ext
->cpr2_size
);
20111 abiflags_in
.fp_abi
= BYTE_GET (abiflags_ext
->fp_abi
);
20112 abiflags_in
.isa_ext
= BYTE_GET (abiflags_ext
->isa_ext
);
20113 abiflags_in
.ases
= BYTE_GET (abiflags_ext
->ases
);
20114 abiflags_in
.flags1
= BYTE_GET (abiflags_ext
->flags1
);
20115 abiflags_in
.flags2
= BYTE_GET (abiflags_ext
->flags2
);
20117 printf ("\nMIPS ABI Flags Version: %d\n", abiflags_in
.version
);
20118 printf ("\nISA: MIPS%d", abiflags_in
.isa_level
);
20119 if (abiflags_in
.isa_rev
> 1)
20120 printf ("r%d", abiflags_in
.isa_rev
);
20121 printf ("\nGPR size: %d",
20122 get_mips_reg_size (abiflags_in
.gpr_size
));
20123 printf ("\nCPR1 size: %d",
20124 get_mips_reg_size (abiflags_in
.cpr1_size
));
20125 printf ("\nCPR2 size: %d",
20126 get_mips_reg_size (abiflags_in
.cpr2_size
));
20127 fputs ("\nFP ABI: ", stdout
);
20128 print_mips_fp_abi_value (abiflags_in
.fp_abi
);
20129 fputs ("ISA Extension: ", stdout
);
20130 print_mips_isa_ext (abiflags_in
.isa_ext
);
20131 fputs ("\nASEs:", stdout
);
20132 print_mips_ases (abiflags_in
.ases
);
20133 printf ("\nFLAGS 1: %8.8lx", abiflags_in
.flags1
);
20134 printf ("\nFLAGS 2: %8.8lx", abiflags_in
.flags2
);
20135 fputc ('\n', stdout
);
20136 free (abiflags_ext
);
20142 /* We have a lot of special sections. Thanks SGI! */
20143 if (filedata
->dynamic_section
== NULL
)
20145 /* No dynamic information available. See if there is static GOT. */
20146 sect
= find_section (filedata
, ".got");
20149 unsigned char *data_end
;
20150 unsigned char *data
;
20154 pltgot
= sect
->sh_addr
;
20157 addr_size
= (is_32bit_elf
? 4 : 8);
20158 end
= pltgot
+ sect
->sh_size
;
20160 data
= (unsigned char *) get_data (NULL
, filedata
, sect
->sh_offset
,
20162 _("Global Offset Table data"));
20163 /* PR 12855: Null data is handled gracefully throughout. */
20164 data_end
= data
+ (end
- pltgot
);
20166 printf (_("\nStatic GOT:\n"));
20167 printf (_(" Canonical gp value: "));
20168 print_vma (ent
+ 0x7ff0, LONG_HEX
);
20171 /* In a dynamic binary GOT[0] is reserved for the dynamic
20172 loader to store the lazy resolver pointer, however in
20173 a static binary it may well have been omitted and GOT
20174 reduced to a table of addresses.
20175 PR 21344: Check for the entry being fully available
20176 before fetching it. */
20178 && data
+ ent
- pltgot
+ addr_size
<= data_end
20179 && byte_get (data
+ ent
- pltgot
, addr_size
) == 0)
20181 printf (_(" Reserved entries:\n"));
20182 printf (_(" %*s %10s %*s\n"),
20183 addr_size
* 2, _("Address"), _("Access"),
20184 addr_size
* 2, _("Value"));
20185 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
20187 if (ent
== (uint64_t) -1)
20188 goto sgot_print_fail
;
20190 /* Check for the MSB of GOT[1] being set, identifying a
20191 GNU object. This entry will be used by some runtime
20192 loaders, to store the module pointer. Otherwise this
20193 is an ordinary local entry.
20194 PR 21344: Check for the entry being fully available
20195 before fetching it. */
20197 && data
+ ent
- pltgot
+ addr_size
<= data_end
20198 && (byte_get (data
+ ent
- pltgot
, addr_size
)
20199 >> (addr_size
* 8 - 1)) != 0)
20201 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
20203 if (ent
== (uint64_t) -1)
20204 goto sgot_print_fail
;
20209 if (data
!= NULL
&& ent
< end
)
20211 printf (_(" Local entries:\n"));
20212 printf (" %*s %10s %*s\n",
20213 addr_size
* 2, _("Address"), _("Access"),
20214 addr_size
* 2, _("Value"));
20217 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
20219 if (ent
== (uint64_t) -1)
20220 goto sgot_print_fail
;
20231 for (entry
= filedata
->dynamic_section
;
20232 /* PR 17531 file: 012-50589-0.004. */
20233 (entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
20234 && entry
->d_tag
!= DT_NULL
);
20236 switch (entry
->d_tag
)
20238 case DT_MIPS_LIBLIST
:
20240 = offset_from_vma (filedata
, entry
->d_un
.d_val
,
20241 liblistno
* sizeof (Elf32_External_Lib
));
20243 case DT_MIPS_LIBLISTNO
:
20244 liblistno
= entry
->d_un
.d_val
;
20246 case DT_MIPS_OPTIONS
:
20247 options_offset
= offset_from_vma (filedata
, entry
->d_un
.d_val
, 0);
20249 case DT_MIPS_CONFLICT
:
20251 = offset_from_vma (filedata
, entry
->d_un
.d_val
,
20252 conflictsno
* sizeof (Elf32_External_Conflict
));
20254 case DT_MIPS_CONFLICTNO
:
20255 conflictsno
= entry
->d_un
.d_val
;
20258 pltgot
= entry
->d_un
.d_ptr
;
20260 case DT_MIPS_LOCAL_GOTNO
:
20261 local_gotno
= entry
->d_un
.d_val
;
20263 case DT_MIPS_GOTSYM
:
20264 gotsym
= entry
->d_un
.d_val
;
20266 case DT_MIPS_SYMTABNO
:
20267 symtabno
= entry
->d_un
.d_val
;
20269 case DT_MIPS_PLTGOT
:
20270 mips_pltgot
= entry
->d_un
.d_ptr
;
20273 pltrel
= entry
->d_un
.d_val
;
20276 pltrelsz
= entry
->d_un
.d_val
;
20279 jmprel
= entry
->d_un
.d_ptr
;
20285 if (!dump_got
&& liblist_offset
!= 0 && liblistno
!= 0 && do_dynamic
)
20287 Elf32_External_Lib
* elib
;
20290 elib
= (Elf32_External_Lib
*) get_data (NULL
, filedata
, liblist_offset
,
20291 sizeof (Elf32_External_Lib
),
20293 _("liblist section data"));
20296 printf (ngettext ("\nSection '.liblist' contains %zu entry:\n",
20297 "\nSection '.liblist' contains %zu entries:\n",
20300 fputs (_(" Library Time Stamp Checksum Version Flags\n"),
20303 for (cnt
= 0; cnt
< liblistno
; ++cnt
)
20310 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
20311 atime
= BYTE_GET (elib
[cnt
].l_time_stamp
);
20312 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
20313 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
20314 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
20316 tmp
= gmtime (&atime
);
20317 snprintf (timebuf
, sizeof (timebuf
),
20318 "%04u-%02u-%02uT%02u:%02u:%02u",
20319 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
20320 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
20322 printf ("%3zu: ", cnt
);
20323 if (valid_dynamic_name (filedata
, liblist
.l_name
))
20324 print_symbol_name (20, get_dynamic_name (filedata
, liblist
.l_name
));
20326 printf (_("<corrupt: %9ld>"), liblist
.l_name
);
20327 printf (" %s %#10lx %-7ld", timebuf
, liblist
.l_checksum
,
20328 liblist
.l_version
);
20330 if (liblist
.l_flags
== 0)
20334 static const struct
20341 { " EXACT_MATCH", LL_EXACT_MATCH
},
20342 { " IGNORE_INT_VER", LL_IGNORE_INT_VER
},
20343 { " REQUIRE_MINOR", LL_REQUIRE_MINOR
},
20344 { " EXPORTS", LL_EXPORTS
},
20345 { " DELAY_LOAD", LL_DELAY_LOAD
},
20346 { " DELTA", LL_DELTA
}
20348 int flags
= liblist
.l_flags
;
20351 for (fcnt
= 0; fcnt
< ARRAY_SIZE (l_flags_vals
); ++fcnt
)
20352 if ((flags
& l_flags_vals
[fcnt
].bit
) != 0)
20354 fputs (l_flags_vals
[fcnt
].name
, stdout
);
20355 flags
^= l_flags_vals
[fcnt
].bit
;
20358 printf (" %#x", (unsigned int) flags
);
20370 if (!dump_got
&& options_offset
!= 0)
20372 Elf_External_Options
* eopt
;
20376 /* Find the section header so that we get the size. */
20377 sect
= find_section_by_type (filedata
, SHT_MIPS_OPTIONS
);
20378 /* PR 17533 file: 012-277276-0.004. */
20381 error (_("No MIPS_OPTIONS header found\n"));
20385 if (sect
->sh_size
< sizeof (* eopt
))
20387 error (_("The MIPS options section is too small.\n"));
20391 eopt
= (Elf_External_Options
*) get_data (NULL
, filedata
, options_offset
, 1,
20392 sect
->sh_size
, _("options"));
20395 Elf_Internal_Options option
;
20398 while (offset
<= sect
->sh_size
- sizeof (* eopt
))
20400 Elf_External_Options
* eoption
;
20401 unsigned int optsize
;
20403 eoption
= (Elf_External_Options
*) ((char *) eopt
+ offset
);
20405 optsize
= BYTE_GET (eoption
->size
);
20407 /* PR 17531: file: ffa0fa3b. */
20408 if (optsize
< sizeof (* eopt
)
20409 || optsize
> sect
->sh_size
- offset
)
20411 error (_("Invalid size (%u) for MIPS option\n"),
20420 printf (ngettext ("\nSection '%s' contains %d entry:\n",
20421 "\nSection '%s' contains %d entries:\n",
20423 printable_section_name (filedata
, sect
), cnt
);
20429 Elf_External_Options
* eoption
;
20431 eoption
= (Elf_External_Options
*) ((char *) eopt
+ offset
);
20433 option
.kind
= BYTE_GET (eoption
->kind
);
20434 option
.size
= BYTE_GET (eoption
->size
);
20435 option
.section
= BYTE_GET (eoption
->section
);
20436 option
.info
= BYTE_GET (eoption
->info
);
20438 switch (option
.kind
)
20441 /* This shouldn't happen. */
20442 printf (" NULL %" PRId16
" %" PRIx32
,
20443 option
.section
, option
.info
);
20447 printf (" REGINFO ");
20448 if (filedata
->file_header
.e_machine
== EM_MIPS
)
20450 Elf32_External_RegInfo
* ereg
;
20451 Elf32_RegInfo reginfo
;
20454 if (option
.size
< (sizeof (Elf_External_Options
)
20455 + sizeof (Elf32_External_RegInfo
)))
20457 printf (_("<corrupt>\n"));
20458 error (_("Truncated MIPS REGINFO option\n"));
20463 ereg
= (Elf32_External_RegInfo
*) (eoption
+ 1);
20465 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
20466 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
20467 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
20468 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
20469 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
20470 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
20472 printf ("GPR %08" PRIx32
" GP 0x%" PRIx32
"\n",
20473 reginfo
.ri_gprmask
, reginfo
.ri_gp_value
);
20475 " CPR0 %08" PRIx32
" CPR1 %08" PRIx32
20476 " CPR2 %08" PRIx32
" CPR3 %08" PRIx32
"\n",
20477 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
20478 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
20483 Elf64_External_RegInfo
* ereg
;
20484 Elf64_Internal_RegInfo reginfo
;
20486 if (option
.size
< (sizeof (Elf_External_Options
)
20487 + sizeof (Elf64_External_RegInfo
)))
20489 printf (_("<corrupt>\n"));
20490 error (_("Truncated MIPS REGINFO option\n"));
20495 ereg
= (Elf64_External_RegInfo
*) (eoption
+ 1);
20496 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
20497 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
20498 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
20499 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
20500 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
20501 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
20503 printf ("GPR %08" PRIx32
" GP 0x%" PRIx64
"\n",
20504 reginfo
.ri_gprmask
, reginfo
.ri_gp_value
);
20506 " CPR0 %08" PRIx32
" CPR1 %08" PRIx32
20507 " CPR2 %08" PRIx32
" CPR3 %08" PRIx32
"\n",
20508 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
20509 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
20511 offset
+= option
.size
;
20514 case ODK_EXCEPTIONS
:
20515 fputs (" EXCEPTIONS fpe_min(", stdout
);
20516 process_mips_fpe_exception (option
.info
& OEX_FPU_MIN
);
20517 fputs (") fpe_max(", stdout
);
20518 process_mips_fpe_exception ((option
.info
& OEX_FPU_MAX
) >> 8);
20519 fputs (")", stdout
);
20521 if (option
.info
& OEX_PAGE0
)
20522 fputs (" PAGE0", stdout
);
20523 if (option
.info
& OEX_SMM
)
20524 fputs (" SMM", stdout
);
20525 if (option
.info
& OEX_FPDBUG
)
20526 fputs (" FPDBUG", stdout
);
20527 if (option
.info
& OEX_DISMISS
)
20528 fputs (" DISMISS", stdout
);
20532 fputs (" PAD ", stdout
);
20533 if (option
.info
& OPAD_PREFIX
)
20534 fputs (" PREFIX", stdout
);
20535 if (option
.info
& OPAD_POSTFIX
)
20536 fputs (" POSTFIX", stdout
);
20537 if (option
.info
& OPAD_SYMBOL
)
20538 fputs (" SYMBOL", stdout
);
20542 fputs (" HWPATCH ", stdout
);
20543 if (option
.info
& OHW_R4KEOP
)
20544 fputs (" R4KEOP", stdout
);
20545 if (option
.info
& OHW_R8KPFETCH
)
20546 fputs (" R8KPFETCH", stdout
);
20547 if (option
.info
& OHW_R5KEOP
)
20548 fputs (" R5KEOP", stdout
);
20549 if (option
.info
& OHW_R5KCVTL
)
20550 fputs (" R5KCVTL", stdout
);
20554 fputs (" FILL ", stdout
);
20555 /* XXX Print content of info word? */
20559 fputs (" TAGS ", stdout
);
20560 /* XXX Print content of info word? */
20564 fputs (" HWAND ", stdout
);
20565 if (option
.info
& OHWA0_R4KEOP_CHECKED
)
20566 fputs (" R4KEOP_CHECKED", stdout
);
20567 if (option
.info
& OHWA0_R4KEOP_CLEAN
)
20568 fputs (" R4KEOP_CLEAN", stdout
);
20572 fputs (" HWOR ", stdout
);
20573 if (option
.info
& OHWA0_R4KEOP_CHECKED
)
20574 fputs (" R4KEOP_CHECKED", stdout
);
20575 if (option
.info
& OHWA0_R4KEOP_CLEAN
)
20576 fputs (" R4KEOP_CLEAN", stdout
);
20580 printf (" GP_GROUP %#06x self-contained %#06x",
20581 option
.info
& OGP_GROUP
,
20582 (option
.info
& OGP_SELF
) >> 16);
20586 printf (" IDENT %#06x self-contained %#06x",
20587 option
.info
& OGP_GROUP
,
20588 (option
.info
& OGP_SELF
) >> 16);
20592 /* This shouldn't happen. */
20593 printf (" %3d ??? %" PRId16
" %" PRIx32
,
20594 option
.kind
, option
.section
, option
.info
);
20598 len
= sizeof (* eopt
);
20599 while (len
< option
.size
)
20601 unsigned char datum
= *((unsigned char *) eoption
+ len
);
20603 if (ISPRINT (datum
))
20604 printf ("%c", datum
);
20606 printf ("\\%03o", datum
);
20609 fputs ("\n", stdout
);
20611 offset
+= option
.size
;
20619 if (!dump_got
&& conflicts_offset
!= 0 && conflictsno
!= 0)
20621 Elf32_Conflict
* iconf
;
20624 if (filedata
->dynamic_symbols
== NULL
)
20626 error (_("conflict list found without a dynamic symbol table\n"));
20630 /* PR 21345 - print a slightly more helpful error message
20631 if we are sure that the cmalloc will fail. */
20632 if (conflictsno
> filedata
->file_size
/ sizeof (* iconf
))
20634 error (_("Overlarge number of conflicts detected: %zx\n"),
20639 iconf
= (Elf32_Conflict
*) cmalloc (conflictsno
, sizeof (* iconf
));
20642 error (_("Out of memory allocating space for dynamic conflicts\n"));
20648 Elf32_External_Conflict
* econf32
;
20650 econf32
= (Elf32_External_Conflict
*)
20651 get_data (NULL
, filedata
, conflicts_offset
,
20652 sizeof (*econf32
), conflictsno
, _("conflict"));
20659 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
20660 iconf
[cnt
] = BYTE_GET (econf32
[cnt
]);
20666 Elf64_External_Conflict
* econf64
;
20668 econf64
= (Elf64_External_Conflict
*)
20669 get_data (NULL
, filedata
, conflicts_offset
,
20670 sizeof (*econf64
), conflictsno
, _("conflict"));
20677 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
20678 iconf
[cnt
] = BYTE_GET (econf64
[cnt
]);
20683 printf (ngettext ("\nSection '.conflict' contains %zu entry:\n",
20684 "\nSection '.conflict' contains %zu entries:\n",
20687 puts (_(" Num: Index Value Name"));
20689 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
20691 printf ("%5zu: %8lu ", cnt
, iconf
[cnt
]);
20693 if (iconf
[cnt
] >= filedata
->num_dynamic_syms
)
20694 printf (_("<corrupt symbol index>"));
20697 Elf_Internal_Sym
* psym
;
20699 psym
= & filedata
->dynamic_symbols
[iconf
[cnt
]];
20700 print_vma (psym
->st_value
, FULL_HEX
);
20702 if (valid_dynamic_name (filedata
, psym
->st_name
))
20703 print_symbol_name (25, get_dynamic_name (filedata
, psym
->st_name
));
20705 printf (_("<corrupt: %14ld>"), psym
->st_name
);
20713 if (pltgot
!= 0 && local_gotno
!= 0)
20715 uint64_t ent
, local_end
, global_end
;
20717 unsigned char * data
;
20718 unsigned char * data_end
;
20722 addr_size
= (is_32bit_elf
? 4 : 8);
20723 local_end
= pltgot
+ local_gotno
* addr_size
;
20725 /* PR binutils/17533 file: 012-111227-0.004 */
20726 if (symtabno
< gotsym
)
20728 error (_("The GOT symbol offset (%" PRIu64
20729 ") is greater than the symbol table size (%" PRIu64
")\n"),
20734 global_end
= local_end
+ (symtabno
- gotsym
) * addr_size
;
20735 /* PR 17531: file: 54c91a34. */
20736 if (global_end
< local_end
)
20738 error (_("Too many GOT symbols: %" PRIu64
"\n"), symtabno
);
20742 offset
= offset_from_vma (filedata
, pltgot
, global_end
- pltgot
);
20743 data
= (unsigned char *) get_data (NULL
, filedata
, offset
,
20744 global_end
- pltgot
, 1,
20745 _("Global Offset Table data"));
20746 /* PR 12855: Null data is handled gracefully throughout. */
20747 data_end
= data
+ (global_end
- pltgot
);
20749 printf (_("\nPrimary GOT:\n"));
20750 printf (_(" Canonical gp value: "));
20751 print_vma (pltgot
+ 0x7ff0, LONG_HEX
);
20754 printf (_(" Reserved entries:\n"));
20755 printf (_(" %*s %10s %*s Purpose\n"),
20756 addr_size
* 2, _("Address"), _("Access"),
20757 addr_size
* 2, _("Initial"));
20758 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
20759 printf (_(" Lazy resolver\n"));
20760 if (ent
== (uint64_t) -1)
20761 goto got_print_fail
;
20763 /* Check for the MSB of GOT[1] being set, denoting a GNU object.
20764 This entry will be used by some runtime loaders, to store the
20765 module pointer. Otherwise this is an ordinary local entry.
20766 PR 21344: Check for the entry being fully available before
20769 && data
+ ent
- pltgot
+ addr_size
<= data_end
20770 && (byte_get (data
+ ent
- pltgot
, addr_size
)
20771 >> (addr_size
* 8 - 1)) != 0)
20773 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
20774 printf (_(" Module pointer (GNU extension)\n"));
20775 if (ent
== (uint64_t) -1)
20776 goto got_print_fail
;
20780 if (data
!= NULL
&& ent
< local_end
)
20782 printf (_(" Local entries:\n"));
20783 printf (" %*s %10s %*s\n",
20784 addr_size
* 2, _("Address"), _("Access"),
20785 addr_size
* 2, _("Initial"));
20786 while (ent
< local_end
)
20788 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
20790 if (ent
== (uint64_t) -1)
20791 goto got_print_fail
;
20796 if (data
!= NULL
&& gotsym
< symtabno
)
20800 printf (_(" Global entries:\n"));
20801 printf (" %*s %10s %*s %*s %-7s %3s %s\n",
20802 addr_size
* 2, _("Address"),
20804 addr_size
* 2, _("Initial"),
20805 addr_size
* 2, _("Sym.Val."),
20807 /* Note for translators: "Ndx" = abbreviated form of "Index". */
20808 _("Ndx"), _("Name"));
20810 sym_width
= (is_32bit_elf
? 80 : 160) - 28 - addr_size
* 6 - 1;
20812 for (i
= gotsym
; i
< symtabno
; i
++)
20814 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
20817 if (filedata
->dynamic_symbols
== NULL
)
20818 printf (_("<no dynamic symbols>"));
20819 else if (i
< filedata
->num_dynamic_syms
)
20821 Elf_Internal_Sym
* psym
= filedata
->dynamic_symbols
+ i
;
20823 print_vma (psym
->st_value
, LONG_HEX
);
20824 printf (" %-7s ", get_symbol_type (filedata
, ELF_ST_TYPE (psym
->st_info
)));
20827 const char * s
= printable_section_name_from_index (filedata
, psym
->st_shndx
, & is_special
);
20829 printf ("%3s ", s
);
20831 printf ("%3u ", psym
->st_shndx
);
20833 if (valid_dynamic_name (filedata
, psym
->st_name
))
20834 print_symbol_name (sym_width
,
20835 get_dynamic_name (filedata
, psym
->st_name
));
20837 printf (_("<corrupt: %14ld>"), psym
->st_name
);
20840 printf (_("<symbol index %zu exceeds number of dynamic symbols>"),
20844 if (ent
== (uint64_t) -1)
20854 if (mips_pltgot
!= 0 && jmprel
!= 0 && pltrel
!= 0 && pltrelsz
!= 0)
20857 uint64_t offset
, rel_offset
;
20859 unsigned char * data
;
20860 int addr_size
, sym_width
;
20861 Elf_Internal_Rela
* rels
;
20863 rel_offset
= offset_from_vma (filedata
, jmprel
, pltrelsz
);
20864 if (pltrel
== DT_RELA
)
20866 if (!slurp_rela_relocs (filedata
, rel_offset
, pltrelsz
, &rels
, &count
))
20871 if (!slurp_rel_relocs (filedata
, rel_offset
, pltrelsz
, &rels
, &count
))
20876 addr_size
= (is_32bit_elf
? 4 : 8);
20877 end
= mips_pltgot
+ (2 + count
) * addr_size
;
20879 offset
= offset_from_vma (filedata
, mips_pltgot
, end
- mips_pltgot
);
20880 data
= (unsigned char *) get_data (NULL
, filedata
, offset
, end
- mips_pltgot
,
20881 1, _("Procedure Linkage Table data"));
20888 printf ("\nPLT GOT:\n\n");
20889 printf (_(" Reserved entries:\n"));
20890 printf (_(" %*s %*s Purpose\n"),
20891 addr_size
* 2, _("Address"), addr_size
* 2, _("Initial"));
20892 ent
= print_mips_pltgot_entry (data
, mips_pltgot
, ent
);
20893 printf (_(" PLT lazy resolver\n"));
20894 ent
= print_mips_pltgot_entry (data
, mips_pltgot
, ent
);
20895 printf (_(" Module pointer\n"));
20898 printf (_(" Entries:\n"));
20899 printf (" %*s %*s %*s %-7s %3s %s\n",
20900 addr_size
* 2, _("Address"),
20901 addr_size
* 2, _("Initial"),
20902 addr_size
* 2, _("Sym.Val."), _("Type"), _("Ndx"), _("Name"));
20903 sym_width
= (is_32bit_elf
? 80 : 160) - 17 - addr_size
* 6 - 1;
20904 for (i
= 0; i
< count
; i
++)
20906 uint64_t idx
= get_reloc_symindex (rels
[i
].r_info
);
20908 ent
= print_mips_pltgot_entry (data
, mips_pltgot
, ent
);
20911 if (idx
>= filedata
->num_dynamic_syms
)
20912 printf (_("<corrupt symbol index: %" PRIu64
">"), idx
);
20915 Elf_Internal_Sym
* psym
= filedata
->dynamic_symbols
+ idx
;
20917 print_vma (psym
->st_value
, LONG_HEX
);
20918 printf (" %-7s %3s ",
20919 get_symbol_type (filedata
, ELF_ST_TYPE (psym
->st_info
)),
20920 printable_section_name_from_index (filedata
, psym
->st_shndx
, NULL
));
20921 if (valid_dynamic_name (filedata
, psym
->st_name
))
20922 print_symbol_name (sym_width
,
20923 get_dynamic_name (filedata
, psym
->st_name
));
20925 printf (_("<corrupt: %14ld>"), psym
->st_name
);
20939 process_nds32_specific (Filedata
* filedata
)
20941 Elf_Internal_Shdr
*sect
= NULL
;
20943 sect
= find_section (filedata
, ".nds32_e_flags");
20944 if (sect
!= NULL
&& sect
->sh_size
>= 4)
20946 unsigned char *buf
;
20949 printf ("\nNDS32 elf flags section:\n");
20950 buf
= get_data (NULL
, filedata
, sect
->sh_offset
, 1, 4,
20951 _("NDS32 elf flags section"));
20956 flag
= byte_get (buf
, 4);
20958 switch (flag
& 0x3)
20961 printf ("(VEC_SIZE):\tNo entry.\n");
20964 printf ("(VEC_SIZE):\t4 bytes\n");
20967 printf ("(VEC_SIZE):\t16 bytes\n");
20970 printf ("(VEC_SIZE):\treserved\n");
20979 elf_relocation_cmp (const void *p
, const void *q
)
20981 const elf_relocation
*rp
= (const elf_relocation
*) p
;
20982 const elf_relocation
*rq
= (const elf_relocation
*) q
;
20984 return (rp
->r_offset
> rq
->r_offset
20986 : (rp
->r_offset
< rq
->r_offset
? -1 : 0));
20990 display_elf_relocation_at (uint64_t offset
, uint64_t g
)
20992 bool matched
= false;
20994 for (size_t i
= 0; i
< all_relocations_count
; i
++)
20995 if (all_relocations_root
[i
].r_offset
== offset
)
20998 printf (" %-22s", all_relocations_root
[i
].r_name
);
21000 printf (" %-17.17s", all_relocations_root
[i
].r_name
);
21003 switch (all_relocations_root
[i
].r_type
)
21012 off
= all_relocations_root
[i
].r_addend
;
21016 if (all_relocations_root
[i
].r_symbol
)
21018 printf (" %s", all_relocations_root
[i
].r_symbol
);
21019 if ((int64_t) off
< 0)
21020 printf (" - %" PRIx64
, -off
);
21022 printf (" + %" PRIx64
, off
);
21026 if ((int64_t) off
< 0)
21027 printf (" -%" PRIx64
, -off
);
21029 printf (" %" PRIx64
, off
);
21035 else if (all_relocations_root
[i
].r_offset
> offset
)
21041 printf ("%*c", 24, ' ');
21043 printf ("%*c", 19, ' ');
21044 printf ("%" PRIx64
, g
);
21049 process_got_section_contents (Filedata
* filedata
)
21051 Elf_Internal_Shdr
* section
;
21054 unsigned char *data
;
21056 bool found
= false;
21058 if (!do_got_section_contents
)
21061 switch (filedata
->file_header
.e_type
)
21070 switch (filedata
->file_header
.e_machine
)
21073 case EM_MIPS_RS3_LE
:
21074 /* process_mips_specific also displays GOT related contents. */
21076 res
= process_mips_specific (filedata
, true);
21081 if (all_relocations_count
> 1)
21082 qsort (all_relocations_root
, all_relocations_count
,
21083 sizeof (elf_relocation
), elf_relocation_cmp
);
21085 initialise_dumps_byname (filedata
);
21087 for (i
= 0, section
= filedata
->section_headers
;
21088 i
< filedata
->file_header
.e_shnum
;
21090 if (section
->sh_type
== SHT_PROGBITS
21091 && section
->sh_size
!= 0)
21093 const char *name
= printable_section_name (filedata
, section
);
21095 if (!startswith (name
, ".got"))
21100 data
= (unsigned char *) get_section_contents (section
,
21108 uint32_t entsz
= section
->sh_entsize
;
21109 /* NB: Gold, lld and mold set sh_entsize to 0 on .got and
21110 .got.plt sections. */
21114 switch (filedata
->file_header
.e_machine
)
21120 /* x32 uses 8 byte GOT sh_entsize. */
21128 entries
= section
->sh_size
/ entsz
;
21130 printf (_("\nGlobal Offset Table '%s' contains 1 entry:\n"),
21133 printf (_("\nGlobal Offset Table '%s' contains %" PRIu64
21134 " entries:\n"), name
, entries
);
21140 uint32_t j
, n
= entries
;
21144 unsigned char bytes
[4];
21148 printf (_(" Index: Address Reloc Sym. Name + Addend/Value\n"));
21149 /* |---9---| |---8--| |---------22---------| |........... */
21151 printf (_(" Index: Address Reloc Sym. Name + Addend/Value\n"));
21152 /* |--7--| |---8--| |-------17------| |........... */
21154 addr
= section
->sh_addr
;
21155 got
= (struct got32
*) data
;
21156 for (j
= 0; j
< n
; j
++)
21158 g
= BYTE_GET (got
[j
].bytes
);
21160 printf ("%8" PRIu32
": %8.8" PRIx32
, j
, addr
);
21162 printf ("%6" PRIu32
": %8.8" PRIx32
, j
, addr
);
21163 display_elf_relocation_at (addr
, g
);
21173 unsigned char bytes
[4];
21177 printf (_(" Index: Address Reloc Sym. Name + Addend/Value\n"));
21178 /* |---9---| |------16------| |---------22---------| |........... */
21180 printf (_(" Index: Address Reloc Sym. Name + Addend/Value\n"));
21181 /* |--7--| |----12----| |------17-------| |........... */
21183 addr
= section
->sh_addr
;
21184 got
= (struct got64
*) data
;
21185 for (j
= 0; j
< entries
; j
++)
21187 g
= BYTE_GET (got
[j
].bytes
);
21189 printf ("%8" PRIu64
": %16.16" PRIx64
, j
, addr
);
21191 printf ("%6" PRIu64
": %12.12" PRIx64
, j
, addr
);
21192 display_elf_relocation_at (addr
, g
);
21204 if (filedata
->is_separate
)
21205 printf (_("\nThere is no GOT section in linked file '%s'.\n"),
21206 filedata
->file_name
);
21208 printf (_("\nThere is no GOT section in this file.\n"));
21211 for (size_t j
= 0; j
< all_relocations_count
; j
++)
21212 free (all_relocations_root
[j
].r_symbol
);
21213 free (all_relocations_root
);
21214 all_relocations_root
= NULL
;
21215 all_relocations
= NULL
;
21216 all_relocations_count
= 0;
21221 process_gnu_liblist (Filedata
* filedata
)
21223 Elf_Internal_Shdr
* section
;
21224 Elf_Internal_Shdr
* string_sec
;
21225 Elf32_External_Lib
* elib
;
21227 size_t strtab_size
;
21229 uint64_t num_liblist
;
21236 for (i
= 0, section
= filedata
->section_headers
;
21237 i
< filedata
->file_header
.e_shnum
;
21240 switch (section
->sh_type
)
21242 case SHT_GNU_LIBLIST
:
21243 if (section
->sh_link
>= filedata
->file_header
.e_shnum
)
21246 elib
= (Elf32_External_Lib
*)
21247 get_data (NULL
, filedata
, section
->sh_offset
, 1, section
->sh_size
,
21248 _("liblist section data"));
21256 string_sec
= filedata
->section_headers
+ section
->sh_link
;
21257 strtab
= (char *) get_data (NULL
, filedata
, string_sec
->sh_offset
, 1,
21258 string_sec
->sh_size
,
21259 _("liblist string table"));
21261 || section
->sh_entsize
!= sizeof (Elf32_External_Lib
))
21268 strtab_size
= string_sec
->sh_size
;
21270 num_liblist
= section
->sh_size
/ sizeof (Elf32_External_Lib
);
21271 printf (ngettext ("\nLibrary list section '%s' contains %" PRIu64
21273 "\nLibrary list section '%s' contains %" PRIu64
21276 printable_section_name (filedata
, section
),
21279 puts (_(" Library Time Stamp Checksum Version Flags"));
21281 for (cnt
= 0; cnt
< section
->sh_size
/ sizeof (Elf32_External_Lib
);
21289 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
21290 atime
= BYTE_GET (elib
[cnt
].l_time_stamp
);
21291 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
21292 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
21293 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
21295 tmp
= gmtime (&atime
);
21296 snprintf (timebuf
, sizeof (timebuf
),
21297 "%04u-%02u-%02uT%02u:%02u:%02u",
21298 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
21299 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
21301 printf ("%3zu: ", cnt
);
21303 printf ("%-20s", liblist
.l_name
< strtab_size
21304 ? strtab
+ liblist
.l_name
: _("<corrupt>"));
21306 printf ("%-20.20s", liblist
.l_name
< strtab_size
21307 ? strtab
+ liblist
.l_name
: _("<corrupt>"));
21308 printf (" %s %#010lx %-7ld %-7ld\n", timebuf
, liblist
.l_checksum
,
21309 liblist
.l_version
, liblist
.l_flags
);
21320 static const char *
21321 get_note_type (Filedata
* filedata
, unsigned e_type
)
21323 static char buff
[64];
21325 if (filedata
->file_header
.e_type
== ET_CORE
)
21329 return _("NT_AUXV (auxiliary vector)");
21331 return _("NT_PRSTATUS (prstatus structure)");
21333 return _("NT_FPREGSET (floating point registers)");
21335 return _("NT_PRPSINFO (prpsinfo structure)");
21336 case NT_TASKSTRUCT
:
21337 return _("NT_TASKSTRUCT (task structure)");
21339 return _("NT_GDB_TDESC (GDB XML target description)");
21341 return _("NT_PRXFPREG (user_xfpregs structure)");
21343 return _("NT_PPC_VMX (ppc Altivec registers)");
21345 return _("NT_PPC_VSX (ppc VSX registers)");
21347 return _("NT_PPC_TAR (ppc TAR register)");
21349 return _("NT_PPC_PPR (ppc PPR register)");
21351 return _("NT_PPC_DSCR (ppc DSCR register)");
21353 return _("NT_PPC_EBB (ppc EBB registers)");
21355 return _("NT_PPC_PMU (ppc PMU registers)");
21356 case NT_PPC_TM_CGPR
:
21357 return _("NT_PPC_TM_CGPR (ppc checkpointed GPR registers)");
21358 case NT_PPC_TM_CFPR
:
21359 return _("NT_PPC_TM_CFPR (ppc checkpointed floating point registers)");
21360 case NT_PPC_TM_CVMX
:
21361 return _("NT_PPC_TM_CVMX (ppc checkpointed Altivec registers)");
21362 case NT_PPC_TM_CVSX
:
21363 return _("NT_PPC_TM_CVSX (ppc checkpointed VSX registers)");
21364 case NT_PPC_TM_SPR
:
21365 return _("NT_PPC_TM_SPR (ppc TM special purpose registers)");
21366 case NT_PPC_TM_CTAR
:
21367 return _("NT_PPC_TM_CTAR (ppc checkpointed TAR register)");
21368 case NT_PPC_TM_CPPR
:
21369 return _("NT_PPC_TM_CPPR (ppc checkpointed PPR register)");
21370 case NT_PPC_TM_CDSCR
:
21371 return _("NT_PPC_TM_CDSCR (ppc checkpointed DSCR register)");
21373 return _("NT_386_TLS (x86 TLS information)");
21374 case NT_386_IOPERM
:
21375 return _("NT_386_IOPERM (x86 I/O permissions)");
21376 case NT_X86_XSTATE
:
21377 return _("NT_X86_XSTATE (x86 XSAVE extended state)");
21379 return _("NT_X86_CET (x86 CET state)");
21381 return _("NT_X86_SHSTK (x86 SHSTK state)");
21382 case NT_S390_HIGH_GPRS
:
21383 return _("NT_S390_HIGH_GPRS (s390 upper register halves)");
21384 case NT_S390_TIMER
:
21385 return _("NT_S390_TIMER (s390 timer register)");
21386 case NT_S390_TODCMP
:
21387 return _("NT_S390_TODCMP (s390 TOD comparator register)");
21388 case NT_S390_TODPREG
:
21389 return _("NT_S390_TODPREG (s390 TOD programmable register)");
21391 return _("NT_S390_CTRS (s390 control registers)");
21392 case NT_S390_PREFIX
:
21393 return _("NT_S390_PREFIX (s390 prefix register)");
21394 case NT_S390_LAST_BREAK
:
21395 return _("NT_S390_LAST_BREAK (s390 last breaking event address)");
21396 case NT_S390_SYSTEM_CALL
:
21397 return _("NT_S390_SYSTEM_CALL (s390 system call restart data)");
21399 return _("NT_S390_TDB (s390 transaction diagnostic block)");
21400 case NT_S390_VXRS_LOW
:
21401 return _("NT_S390_VXRS_LOW (s390 vector registers 0-15 upper half)");
21402 case NT_S390_VXRS_HIGH
:
21403 return _("NT_S390_VXRS_HIGH (s390 vector registers 16-31)");
21404 case NT_S390_GS_CB
:
21405 return _("NT_S390_GS_CB (s390 guarded-storage registers)");
21406 case NT_S390_GS_BC
:
21407 return _("NT_S390_GS_BC (s390 guarded-storage broadcast control)");
21409 return _("NT_ARM_VFP (arm VFP registers)");
21411 return _("NT_ARM_TLS (AArch TLS registers)");
21412 case NT_ARM_HW_BREAK
:
21413 return _("NT_ARM_HW_BREAK (AArch hardware breakpoint registers)");
21414 case NT_ARM_HW_WATCH
:
21415 return _("NT_ARM_HW_WATCH (AArch hardware watchpoint registers)");
21416 case NT_ARM_SYSTEM_CALL
:
21417 return _("NT_ARM_SYSTEM_CALL (AArch system call number)");
21419 return _("NT_ARM_SVE (AArch SVE registers)");
21420 case NT_ARM_PAC_MASK
:
21421 return _("NT_ARM_PAC_MASK (AArch pointer authentication code masks)");
21422 case NT_ARM_PACA_KEYS
:
21423 return _("NT_ARM_PACA_KEYS (ARM pointer authentication address keys)");
21424 case NT_ARM_PACG_KEYS
:
21425 return _("NT_ARM_PACG_KEYS (ARM pointer authentication generic keys)");
21426 case NT_ARM_TAGGED_ADDR_CTRL
:
21427 return _("NT_ARM_TAGGED_ADDR_CTRL (AArch tagged address control)");
21429 return _("NT_ARM_SSVE (AArch64 streaming SVE registers)");
21431 return _("NT_ARM_ZA (AArch64 SME ZA register)");
21433 return _("NT_ARM_ZT (AArch64 SME2 ZT registers)");
21434 case NT_ARM_PAC_ENABLED_KEYS
:
21435 return _("NT_ARM_PAC_ENABLED_KEYS (AArch64 pointer authentication enabled keys)");
21437 return _("NT_ARC_V2 (ARC HS accumulator/extra registers)");
21439 return _("NT_RISCV_CSR (RISC-V control and status registers)");
21441 return _("NT_PSTATUS (pstatus structure)");
21443 return _("NT_FPREGS (floating point registers)");
21445 return _("NT_PSINFO (psinfo structure)");
21447 return _("NT_LWPSTATUS (lwpstatus_t structure)");
21449 return _("NT_LWPSINFO (lwpsinfo_t structure)");
21450 case NT_WIN32PSTATUS
:
21451 return _("NT_WIN32PSTATUS (win32_pstatus structure)");
21453 return _("NT_SIGINFO (siginfo_t data)");
21455 return _("NT_FILE (mapped files)");
21463 return _("NT_VERSION (version)");
21465 return _("NT_ARCH (architecture)");
21466 case NT_GNU_BUILD_ATTRIBUTE_OPEN
:
21468 case NT_GNU_BUILD_ATTRIBUTE_FUNC
:
21470 case NT_GO_BUILDID
:
21471 return _("GO BUILDID");
21472 case FDO_PACKAGING_METADATA
:
21473 return _("FDO_PACKAGING_METADATA");
21474 case FDO_DLOPEN_METADATA
:
21475 return _("FDO_DLOPEN_METADATA");
21480 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
21485 print_core_note (Elf_Internal_Note
*pnote
)
21487 unsigned int addr_size
= is_32bit_elf
? 4 : 8;
21488 uint64_t count
, page_size
;
21489 unsigned char *descdata
, *filenames
, *descend
;
21491 if (pnote
->type
!= NT_FILE
)
21498 if (pnote
->descsz
< 2 * addr_size
)
21500 error (_(" Malformed note - too short for header\n"));
21504 descdata
= (unsigned char *) pnote
->descdata
;
21505 descend
= descdata
+ pnote
->descsz
;
21507 if (descdata
[pnote
->descsz
- 1] != '\0')
21509 error (_(" Malformed note - does not end with \\0\n"));
21513 count
= byte_get (descdata
, addr_size
);
21514 descdata
+= addr_size
;
21516 page_size
= byte_get (descdata
, addr_size
);
21517 descdata
+= addr_size
;
21519 if (count
> ((uint64_t) -1 - 2 * addr_size
) / (3 * addr_size
)
21520 || pnote
->descsz
< 2 * addr_size
+ count
* 3 * addr_size
)
21522 error (_(" Malformed note - too short for supplied file count\n"));
21526 printf (_(" Page size: "));
21527 print_vma (page_size
, DEC
);
21530 printf (_(" %*s%*s%*s\n"),
21531 (int) (2 + 2 * addr_size
), _("Start"),
21532 (int) (4 + 2 * addr_size
), _("End"),
21533 (int) (4 + 2 * addr_size
), _("Page Offset"));
21534 filenames
= descdata
+ count
* 3 * addr_size
;
21535 while (count
-- > 0)
21537 uint64_t start
, end
, file_ofs
;
21539 if (filenames
== descend
)
21541 error (_(" Malformed note - filenames end too early\n"));
21545 start
= byte_get (descdata
, addr_size
);
21546 descdata
+= addr_size
;
21547 end
= byte_get (descdata
, addr_size
);
21548 descdata
+= addr_size
;
21549 file_ofs
= byte_get (descdata
, addr_size
);
21550 descdata
+= addr_size
;
21553 print_vma (start
, FULL_HEX
);
21555 print_vma (end
, FULL_HEX
);
21557 print_vma (file_ofs
, FULL_HEX
);
21558 printf ("\n %s\n", filenames
);
21560 filenames
+= 1 + strlen ((char *) filenames
);
21566 static const char *
21567 get_gnu_elf_note_type (unsigned e_type
)
21569 /* NB/ Keep this switch statement in sync with print_gnu_note (). */
21572 case NT_GNU_ABI_TAG
:
21573 return _("NT_GNU_ABI_TAG (ABI version tag)");
21575 return _("NT_GNU_HWCAP (DSO-supplied software HWCAP info)");
21576 case NT_GNU_BUILD_ID
:
21577 return _("NT_GNU_BUILD_ID (unique build ID bitstring)");
21578 case NT_GNU_GOLD_VERSION
:
21579 return _("NT_GNU_GOLD_VERSION (gold version)");
21580 case NT_GNU_PROPERTY_TYPE_0
:
21581 return _("NT_GNU_PROPERTY_TYPE_0");
21582 case NT_GNU_BUILD_ATTRIBUTE_OPEN
:
21583 return _("NT_GNU_BUILD_ATTRIBUTE_OPEN");
21584 case NT_GNU_BUILD_ATTRIBUTE_FUNC
:
21585 return _("NT_GNU_BUILD_ATTRIBUTE_FUNC");
21588 static char buff
[64];
21590 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
21597 decode_x86_compat_isa (unsigned int bitmask
)
21601 unsigned int bit
= bitmask
& (- bitmask
);
21606 case GNU_PROPERTY_X86_COMPAT_ISA_1_486
:
21609 case GNU_PROPERTY_X86_COMPAT_ISA_1_586
:
21612 case GNU_PROPERTY_X86_COMPAT_ISA_1_686
:
21615 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE
:
21618 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE2
:
21621 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE3
:
21624 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSSE3
:
21627 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE4_1
:
21630 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE4_2
:
21633 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX
:
21636 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX2
:
21639 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512F
:
21640 printf ("AVX512F");
21642 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512CD
:
21643 printf ("AVX512CD");
21645 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512ER
:
21646 printf ("AVX512ER");
21648 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512PF
:
21649 printf ("AVX512PF");
21651 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512VL
:
21652 printf ("AVX512VL");
21654 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512DQ
:
21655 printf ("AVX512DQ");
21657 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512BW
:
21658 printf ("AVX512BW");
21661 printf (_("<unknown: %x>"), bit
);
21670 decode_x86_compat_2_isa (unsigned int bitmask
)
21674 printf (_("<None>"));
21680 unsigned int bit
= bitmask
& (- bitmask
);
21685 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_CMOV
:
21688 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE
:
21691 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE2
:
21694 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE3
:
21697 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSSE3
:
21700 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE4_1
:
21703 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE4_2
:
21706 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX
:
21709 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX2
:
21712 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_FMA
:
21715 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512F
:
21716 printf ("AVX512F");
21718 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512CD
:
21719 printf ("AVX512CD");
21721 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512ER
:
21722 printf ("AVX512ER");
21724 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512PF
:
21725 printf ("AVX512PF");
21727 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512VL
:
21728 printf ("AVX512VL");
21730 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512DQ
:
21731 printf ("AVX512DQ");
21733 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512BW
:
21734 printf ("AVX512BW");
21736 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_4FMAPS
:
21737 printf ("AVX512_4FMAPS");
21739 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_4VNNIW
:
21740 printf ("AVX512_4VNNIW");
21742 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_BITALG
:
21743 printf ("AVX512_BITALG");
21745 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_IFMA
:
21746 printf ("AVX512_IFMA");
21748 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_VBMI
:
21749 printf ("AVX512_VBMI");
21751 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_VBMI2
:
21752 printf ("AVX512_VBMI2");
21754 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_VNNI
:
21755 printf ("AVX512_VNNI");
21757 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_BF16
:
21758 printf ("AVX512_BF16");
21761 printf (_("<unknown: %x>"), bit
);
21769 static const char *
21770 get_amdgpu_elf_note_type (unsigned int e_type
)
21774 case NT_AMDGPU_METADATA
:
21775 return _("NT_AMDGPU_METADATA (code object metadata)");
21778 static char buf
[64];
21779 snprintf (buf
, sizeof (buf
), _("Unknown note type: (0x%08x)"), e_type
);
21786 decode_x86_isa (unsigned int bitmask
)
21790 unsigned int bit
= bitmask
& (- bitmask
);
21795 case GNU_PROPERTY_X86_ISA_1_BASELINE
:
21796 printf ("x86-64-baseline");
21798 case GNU_PROPERTY_X86_ISA_1_V2
:
21799 printf ("x86-64-v2");
21801 case GNU_PROPERTY_X86_ISA_1_V3
:
21802 printf ("x86-64-v3");
21804 case GNU_PROPERTY_X86_ISA_1_V4
:
21805 printf ("x86-64-v4");
21808 printf (_("<unknown: %x>"), bit
);
21817 decode_x86_feature_1 (unsigned int bitmask
)
21821 printf (_("<None>"));
21827 unsigned int bit
= bitmask
& (- bitmask
);
21832 case GNU_PROPERTY_X86_FEATURE_1_IBT
:
21835 case GNU_PROPERTY_X86_FEATURE_1_SHSTK
:
21838 case GNU_PROPERTY_X86_FEATURE_1_LAM_U48
:
21839 printf ("LAM_U48");
21841 case GNU_PROPERTY_X86_FEATURE_1_LAM_U57
:
21842 printf ("LAM_U57");
21845 printf (_("<unknown: %x>"), bit
);
21854 decode_x86_feature_2 (unsigned int bitmask
)
21858 printf (_("<None>"));
21864 unsigned int bit
= bitmask
& (- bitmask
);
21869 case GNU_PROPERTY_X86_FEATURE_2_X86
:
21872 case GNU_PROPERTY_X86_FEATURE_2_X87
:
21875 case GNU_PROPERTY_X86_FEATURE_2_MMX
:
21878 case GNU_PROPERTY_X86_FEATURE_2_XMM
:
21881 case GNU_PROPERTY_X86_FEATURE_2_YMM
:
21884 case GNU_PROPERTY_X86_FEATURE_2_ZMM
:
21887 case GNU_PROPERTY_X86_FEATURE_2_TMM
:
21890 case GNU_PROPERTY_X86_FEATURE_2_MASK
:
21893 case GNU_PROPERTY_X86_FEATURE_2_FXSR
:
21896 case GNU_PROPERTY_X86_FEATURE_2_XSAVE
:
21899 case GNU_PROPERTY_X86_FEATURE_2_XSAVEOPT
:
21900 printf ("XSAVEOPT");
21902 case GNU_PROPERTY_X86_FEATURE_2_XSAVEC
:
21906 printf (_("<unknown: %x>"), bit
);
21915 decode_aarch64_feature_1_and (unsigned int bitmask
)
21919 unsigned int bit
= bitmask
& (- bitmask
);
21924 case GNU_PROPERTY_AARCH64_FEATURE_1_BTI
:
21928 case GNU_PROPERTY_AARCH64_FEATURE_1_PAC
:
21932 case GNU_PROPERTY_AARCH64_FEATURE_1_GCS
:
21937 printf (_("<unknown: %x>"), bit
);
21946 decode_riscv_feature_1_and (unsigned int bitmask
)
21950 unsigned int bit
= bitmask
& (- bitmask
);
21955 case GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_UNLABELED
:
21956 printf ("CFI_LP_UNLABELED");
21959 case GNU_PROPERTY_RISCV_FEATURE_1_CFI_SS
:
21964 printf (_("<unknown: %x>"), bit
);
21973 decode_1_needed (unsigned int bitmask
)
21977 unsigned int bit
= bitmask
& (- bitmask
);
21982 case GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS
:
21983 printf ("indirect external access");
21986 printf (_("<unknown: %x>"), bit
);
21995 print_gnu_property_note (Filedata
* filedata
, Elf_Internal_Note
* pnote
)
21997 unsigned char * ptr
= (unsigned char *) pnote
->descdata
;
21998 unsigned char * ptr_end
= ptr
+ pnote
->descsz
;
21999 unsigned int size
= is_32bit_elf
? 4 : 8;
22001 printf (_(" Properties: "));
22003 if (pnote
->descsz
< 8 || (pnote
->descsz
% size
) != 0)
22005 printf (_("<corrupt GNU_PROPERTY_TYPE, size = %#lx>\n"), pnote
->descsz
);
22009 while (ptr
< ptr_end
)
22013 unsigned int datasz
;
22015 if ((size_t) (ptr_end
- ptr
) < 8)
22017 printf (_("<corrupt descsz: %#lx>\n"), pnote
->descsz
);
22021 type
= byte_get (ptr
, 4);
22022 datasz
= byte_get (ptr
+ 4, 4);
22026 if (datasz
> (size_t) (ptr_end
- ptr
))
22028 printf (_("<corrupt type (%#x) datasz: %#x>\n"),
22033 if (type
>= GNU_PROPERTY_LOPROC
&& type
<= GNU_PROPERTY_HIPROC
)
22035 if (filedata
->file_header
.e_machine
== EM_X86_64
22036 || filedata
->file_header
.e_machine
== EM_IAMCU
22037 || filedata
->file_header
.e_machine
== EM_386
)
22039 unsigned int bitmask
;
22042 bitmask
= byte_get (ptr
, 4);
22048 case GNU_PROPERTY_X86_ISA_1_USED
:
22050 printf (_("x86 ISA used: <corrupt length: %#x> "),
22054 printf ("x86 ISA used: ");
22055 decode_x86_isa (bitmask
);
22059 case GNU_PROPERTY_X86_ISA_1_NEEDED
:
22061 printf (_("x86 ISA needed: <corrupt length: %#x> "),
22065 printf ("x86 ISA needed: ");
22066 decode_x86_isa (bitmask
);
22070 case GNU_PROPERTY_X86_FEATURE_1_AND
:
22072 printf (_("x86 feature: <corrupt length: %#x> "),
22076 printf ("x86 feature: ");
22077 decode_x86_feature_1 (bitmask
);
22081 case GNU_PROPERTY_X86_FEATURE_2_USED
:
22083 printf (_("x86 feature used: <corrupt length: %#x> "),
22087 printf ("x86 feature used: ");
22088 decode_x86_feature_2 (bitmask
);
22092 case GNU_PROPERTY_X86_FEATURE_2_NEEDED
:
22094 printf (_("x86 feature needed: <corrupt length: %#x> "), datasz
);
22097 printf ("x86 feature needed: ");
22098 decode_x86_feature_2 (bitmask
);
22102 case GNU_PROPERTY_X86_COMPAT_ISA_1_USED
:
22104 printf (_("x86 ISA used: <corrupt length: %#x> "),
22108 printf ("x86 ISA used: ");
22109 decode_x86_compat_isa (bitmask
);
22113 case GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED
:
22115 printf (_("x86 ISA needed: <corrupt length: %#x> "),
22119 printf ("x86 ISA needed: ");
22120 decode_x86_compat_isa (bitmask
);
22124 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_USED
:
22126 printf (_("x86 ISA used: <corrupt length: %#x> "),
22130 printf ("x86 ISA used: ");
22131 decode_x86_compat_2_isa (bitmask
);
22135 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_NEEDED
:
22137 printf (_("x86 ISA needed: <corrupt length: %#x> "),
22141 printf ("x86 ISA needed: ");
22142 decode_x86_compat_2_isa (bitmask
);
22150 else if (filedata
->file_header
.e_machine
== EM_AARCH64
)
22152 if (type
== GNU_PROPERTY_AARCH64_FEATURE_1_AND
)
22154 printf ("AArch64 feature: ");
22156 printf (_("<corrupt length: %#x> "), datasz
);
22158 decode_aarch64_feature_1_and (byte_get (ptr
, 4));
22162 else if (filedata
->file_header
.e_machine
== EM_RISCV
)
22164 if (type
== GNU_PROPERTY_RISCV_FEATURE_1_AND
)
22166 printf ("RISC-V AND feature: ");
22168 printf (_("<corrupt length: %#x> "), datasz
);
22170 decode_riscv_feature_1_and (byte_get (ptr
, 4));
22179 case GNU_PROPERTY_STACK_SIZE
:
22180 printf (_("stack size: "));
22181 if (datasz
!= size
)
22182 printf (_("<corrupt length: %#x> "), datasz
);
22184 printf ("%#" PRIx64
, byte_get (ptr
, size
));
22187 case GNU_PROPERTY_NO_COPY_ON_PROTECTED
:
22188 printf ("no copy on protected ");
22190 printf (_("<corrupt length: %#x> "), datasz
);
22193 case GNU_PROPERTY_MEMORY_SEAL
:
22194 printf ("memory seal ");
22196 printf (_("<corrupt length: %#x> "), datasz
);
22200 if ((type
>= GNU_PROPERTY_UINT32_AND_LO
22201 && type
<= GNU_PROPERTY_UINT32_AND_HI
)
22202 || (type
>= GNU_PROPERTY_UINT32_OR_LO
22203 && type
<= GNU_PROPERTY_UINT32_OR_HI
))
22207 case GNU_PROPERTY_1_NEEDED
:
22209 printf (_("1_needed: <corrupt length: %#x> "),
22213 unsigned int bitmask
= byte_get (ptr
, 4);
22214 printf ("1_needed: ");
22215 decode_1_needed (bitmask
);
22222 if (type
<= GNU_PROPERTY_UINT32_AND_HI
)
22223 printf (_("UINT32_AND (%#x): "), type
);
22225 printf (_("UINT32_OR (%#x): "), type
);
22227 printf (_("<corrupt length: %#x> "), datasz
);
22229 printf ("%#x", (unsigned int) byte_get (ptr
, 4));
22236 if (type
< GNU_PROPERTY_LOPROC
)
22237 printf (_("<unknown type %#x data: "), type
);
22238 else if (type
< GNU_PROPERTY_LOUSER
)
22239 printf (_("<processor-specific type %#x data: "), type
);
22241 printf (_("<application-specific type %#x data: "), type
);
22242 for (j
= 0; j
< datasz
; ++j
)
22243 printf ("%02x ", ptr
[j
] & 0xff);
22247 ptr
+= ((datasz
+ (size
- 1)) & ~ (size
- 1));
22248 if (ptr
== ptr_end
)
22261 print_gnu_note (Filedata
* filedata
, Elf_Internal_Note
*pnote
)
22263 /* NB/ Keep this switch statement in sync with get_gnu_elf_note_type (). */
22264 switch (pnote
->type
)
22266 case NT_GNU_BUILD_ID
:
22270 printf (_(" Build ID: "));
22271 for (i
= 0; i
< pnote
->descsz
; ++i
)
22272 printf ("%02x", pnote
->descdata
[i
] & 0xff);
22277 case NT_GNU_ABI_TAG
:
22279 unsigned int os
, major
, minor
, subminor
;
22280 const char *osname
;
22282 /* PR 17531: file: 030-599401-0.004. */
22283 if (pnote
->descsz
< 16)
22285 printf (_(" <corrupt GNU_ABI_TAG>\n"));
22289 os
= byte_get ((unsigned char *) pnote
->descdata
, 4);
22290 major
= byte_get ((unsigned char *) pnote
->descdata
+ 4, 4);
22291 minor
= byte_get ((unsigned char *) pnote
->descdata
+ 8, 4);
22292 subminor
= byte_get ((unsigned char *) pnote
->descdata
+ 12, 4);
22296 case GNU_ABI_TAG_LINUX
:
22299 case GNU_ABI_TAG_HURD
:
22302 case GNU_ABI_TAG_SOLARIS
:
22303 osname
= "Solaris";
22305 case GNU_ABI_TAG_FREEBSD
:
22306 osname
= "FreeBSD";
22308 case GNU_ABI_TAG_NETBSD
:
22311 case GNU_ABI_TAG_SYLLABLE
:
22312 osname
= "Syllable";
22314 case GNU_ABI_TAG_NACL
:
22318 osname
= "Unknown";
22322 printf (_(" OS: %s, ABI: %d.%d.%d\n"), osname
,
22323 major
, minor
, subminor
);
22327 case NT_GNU_GOLD_VERSION
:
22331 printf (_(" Version: "));
22332 for (i
= 0; i
< pnote
->descsz
&& pnote
->descdata
[i
] != '\0'; ++i
)
22333 printf ("%c", pnote
->descdata
[i
]);
22340 unsigned int num_entries
, mask
;
22342 /* Hardware capabilities information. Word 0 is the number of entries.
22343 Word 1 is a bitmask of enabled entries. The rest of the descriptor
22344 is a series of entries, where each entry is a single byte followed
22345 by a nul terminated string. The byte gives the bit number to test
22346 if enabled in the bitmask. */
22347 printf (_(" Hardware Capabilities: "));
22348 if (pnote
->descsz
< 8)
22350 error (_("<corrupt GNU_HWCAP>\n"));
22353 num_entries
= byte_get ((unsigned char *) pnote
->descdata
, 4);
22354 mask
= byte_get ((unsigned char *) pnote
->descdata
+ 4, 4);
22355 printf (_("num entries: %d, enabled mask: %x\n"), num_entries
, mask
);
22356 /* FIXME: Add code to display the entries... */
22360 case NT_GNU_PROPERTY_TYPE_0
:
22361 print_gnu_property_note (filedata
, pnote
);
22365 /* Handle unrecognised types. An error message should have already been
22366 created by get_gnu_elf_note_type(), so all that we need to do is to
22367 display the data. */
22371 printf (_(" Description data: "));
22372 for (i
= 0; i
< pnote
->descsz
; ++i
)
22373 printf ("%02x ", pnote
->descdata
[i
] & 0xff);
22382 static const char *
22383 get_v850_elf_note_type (enum v850_notes n_type
)
22385 static char buff
[64];
22389 case V850_NOTE_ALIGNMENT
: return _("Alignment of 8-byte objects");
22390 case V850_NOTE_DATA_SIZE
: return _("Sizeof double and long double");
22391 case V850_NOTE_FPU_INFO
: return _("Type of FPU support needed");
22392 case V850_NOTE_SIMD_INFO
: return _("Use of SIMD instructions");
22393 case V850_NOTE_CACHE_INFO
: return _("Use of cache");
22394 case V850_NOTE_MMU_INFO
: return _("Use of MMU");
22396 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), n_type
);
22402 print_v850_note (Elf_Internal_Note
* pnote
)
22406 printf (" %s: ", get_v850_elf_note_type (pnote
->type
));
22408 if (pnote
->descsz
!= 4)
22410 printf ("<corrupt descsz: %#lx>\n", pnote
->descsz
);
22414 val
= byte_get ((unsigned char *) pnote
->descdata
, pnote
->descsz
);
22418 printf (_("not set\n"));
22422 switch (pnote
->type
)
22424 case V850_NOTE_ALIGNMENT
:
22427 case EF_RH850_DATA_ALIGN4
: printf (_("4-byte\n")); return true;
22428 case EF_RH850_DATA_ALIGN8
: printf (_("8-byte\n")); return true;
22432 case V850_NOTE_DATA_SIZE
:
22435 case EF_RH850_DOUBLE32
: printf (_("4-bytes\n")); return true;
22436 case EF_RH850_DOUBLE64
: printf (_("8-bytes\n")); return true;
22440 case V850_NOTE_FPU_INFO
:
22443 case EF_RH850_FPU20
: printf (_("FPU-2.0\n")); return true;
22444 case EF_RH850_FPU30
: printf (_("FPU-3.0\n")); return true;
22448 case V850_NOTE_MMU_INFO
:
22449 case V850_NOTE_CACHE_INFO
:
22450 case V850_NOTE_SIMD_INFO
:
22451 if (val
== EF_RH850_SIMD
)
22453 printf (_("yes\n"));
22459 /* An 'unknown note type' message will already have been displayed. */
22463 printf (_("unknown value: %x\n"), val
);
22468 process_netbsd_elf_note (Elf_Internal_Note
* pnote
)
22470 unsigned int version
;
22472 switch (pnote
->type
)
22474 case NT_NETBSD_IDENT
:
22475 if (pnote
->descsz
< 1)
22477 version
= byte_get ((unsigned char *) pnote
->descdata
, sizeof (version
));
22478 if ((version
/ 10000) % 100)
22479 printf (" NetBSD\t\t0x%08lx\tIDENT %u (%u.%u%s%c)\n", pnote
->descsz
,
22480 version
, version
/ 100000000, (version
/ 1000000) % 100,
22481 (version
/ 10000) % 100 > 26 ? "Z" : "",
22482 'A' + (version
/ 10000) % 26);
22484 printf (" NetBSD\t\t0x%08lx\tIDENT %u (%u.%u.%u)\n", pnote
->descsz
,
22485 version
, version
/ 100000000, (version
/ 1000000) % 100,
22486 (version
/ 100) % 100);
22489 case NT_NETBSD_MARCH
:
22490 printf (" NetBSD\t\t0x%08lx\tMARCH <%s>\n", pnote
->descsz
,
22494 case NT_NETBSD_PAX
:
22495 if (pnote
->descsz
< 1)
22497 version
= byte_get ((unsigned char *) pnote
->descdata
, sizeof (version
));
22498 printf (" NetBSD\t\t0x%08lx\tPaX <%s%s%s%s%s%s>\n", pnote
->descsz
,
22499 ((version
& NT_NETBSD_PAX_MPROTECT
) ? "+mprotect" : ""),
22500 ((version
& NT_NETBSD_PAX_NOMPROTECT
) ? "-mprotect" : ""),
22501 ((version
& NT_NETBSD_PAX_GUARD
) ? "+guard" : ""),
22502 ((version
& NT_NETBSD_PAX_NOGUARD
) ? "-guard" : ""),
22503 ((version
& NT_NETBSD_PAX_ASLR
) ? "+ASLR" : ""),
22504 ((version
& NT_NETBSD_PAX_NOASLR
) ? "-ASLR" : ""));
22508 printf (" NetBSD\t0x%08lx\tUnknown note type: (0x%08lx)\n",
22509 pnote
->descsz
, pnote
->type
);
22513 static const char *
22514 get_freebsd_elfcore_note_type (Filedata
* filedata
, unsigned e_type
)
22518 case NT_FREEBSD_THRMISC
:
22519 return _("NT_THRMISC (thrmisc structure)");
22520 case NT_FREEBSD_PROCSTAT_PROC
:
22521 return _("NT_PROCSTAT_PROC (proc data)");
22522 case NT_FREEBSD_PROCSTAT_FILES
:
22523 return _("NT_PROCSTAT_FILES (files data)");
22524 case NT_FREEBSD_PROCSTAT_VMMAP
:
22525 return _("NT_PROCSTAT_VMMAP (vmmap data)");
22526 case NT_FREEBSD_PROCSTAT_GROUPS
:
22527 return _("NT_PROCSTAT_GROUPS (groups data)");
22528 case NT_FREEBSD_PROCSTAT_UMASK
:
22529 return _("NT_PROCSTAT_UMASK (umask data)");
22530 case NT_FREEBSD_PROCSTAT_RLIMIT
:
22531 return _("NT_PROCSTAT_RLIMIT (rlimit data)");
22532 case NT_FREEBSD_PROCSTAT_OSREL
:
22533 return _("NT_PROCSTAT_OSREL (osreldate data)");
22534 case NT_FREEBSD_PROCSTAT_PSSTRINGS
:
22535 return _("NT_PROCSTAT_PSSTRINGS (ps_strings data)");
22536 case NT_FREEBSD_PROCSTAT_AUXV
:
22537 return _("NT_PROCSTAT_AUXV (auxv data)");
22538 case NT_FREEBSD_PTLWPINFO
:
22539 return _("NT_PTLWPINFO (ptrace_lwpinfo structure)");
22540 case NT_FREEBSD_X86_SEGBASES
:
22541 return _("NT_X86_SEGBASES (x86 segment base registers)");
22543 return get_note_type (filedata
, e_type
);
22546 static const char *
22547 get_netbsd_elfcore_note_type (Filedata
* filedata
, unsigned e_type
)
22549 static char buff
[64];
22553 case NT_NETBSDCORE_PROCINFO
:
22554 /* NetBSD core "procinfo" structure. */
22555 return _("NetBSD procinfo structure");
22557 case NT_NETBSDCORE_AUXV
:
22558 return _("NetBSD ELF auxiliary vector data");
22560 case NT_NETBSDCORE_LWPSTATUS
:
22561 return _("PT_LWPSTATUS (ptrace_lwpstatus structure)");
22564 /* As of Jan 2020 there are no other machine-independent notes
22565 defined for NetBSD core files. If the note type is less
22566 than the start of the machine-dependent note types, we don't
22569 if (e_type
< NT_NETBSDCORE_FIRSTMACH
)
22571 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
22577 switch (filedata
->file_header
.e_machine
)
22579 /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0
22580 and PT_GETFPREGS == mach+2. */
22585 case EM_SPARC32PLUS
:
22589 case NT_NETBSDCORE_FIRSTMACH
+ 0:
22590 return _("PT_GETREGS (reg structure)");
22591 case NT_NETBSDCORE_FIRSTMACH
+ 2:
22592 return _("PT_GETFPREGS (fpreg structure)");
22598 /* On SuperH, PT_GETREGS == mach+3 and PT_GETFPREGS == mach+5.
22599 There's also old PT___GETREGS40 == mach + 1 for old reg
22600 structure which lacks GBR. */
22604 case NT_NETBSDCORE_FIRSTMACH
+ 1:
22605 return _("PT___GETREGS40 (old reg structure)");
22606 case NT_NETBSDCORE_FIRSTMACH
+ 3:
22607 return _("PT_GETREGS (reg structure)");
22608 case NT_NETBSDCORE_FIRSTMACH
+ 5:
22609 return _("PT_GETFPREGS (fpreg structure)");
22615 /* On all other arch's, PT_GETREGS == mach+1 and
22616 PT_GETFPREGS == mach+3. */
22620 case NT_NETBSDCORE_FIRSTMACH
+ 1:
22621 return _("PT_GETREGS (reg structure)");
22622 case NT_NETBSDCORE_FIRSTMACH
+ 3:
22623 return _("PT_GETFPREGS (fpreg structure)");
22629 snprintf (buff
, sizeof (buff
), "PT_FIRSTMACH+%d",
22630 e_type
- NT_NETBSDCORE_FIRSTMACH
);
22634 static const char *
22635 get_openbsd_elfcore_note_type (Filedata
* filedata
, unsigned e_type
)
22639 case NT_OPENBSD_PROCINFO
:
22640 return _("OpenBSD procinfo structure");
22641 case NT_OPENBSD_AUXV
:
22642 return _("OpenBSD ELF auxiliary vector data");
22643 case NT_OPENBSD_REGS
:
22644 return _("OpenBSD regular registers");
22645 case NT_OPENBSD_FPREGS
:
22646 return _("OpenBSD floating point registers");
22647 case NT_OPENBSD_WCOOKIE
:
22648 return _("OpenBSD window cookie");
22651 return get_note_type (filedata
, e_type
);
22654 static const char *
22655 get_qnx_elfcore_note_type (Filedata
* filedata
, unsigned e_type
)
22659 case QNT_DEBUG_FULLPATH
:
22660 return _("QNX debug fullpath");
22661 case QNT_DEBUG_RELOC
:
22662 return _("QNX debug relocation");
22664 return _("QNX stack");
22665 case QNT_GENERATOR
:
22666 return _("QNX generator");
22667 case QNT_DEFAULT_LIB
:
22668 return _("QNX default library");
22669 case QNT_CORE_SYSINFO
:
22670 return _("QNX core sysinfo");
22671 case QNT_CORE_INFO
:
22672 return _("QNX core info");
22673 case QNT_CORE_STATUS
:
22674 return _("QNX core status");
22675 case QNT_CORE_GREG
:
22676 return _("QNX general registers");
22677 case QNT_CORE_FPREG
:
22678 return _("QNX floating point registers");
22680 return _("QNX link map");
22683 return get_note_type (filedata
, e_type
);
22686 static const char *
22687 get_stapsdt_note_type (unsigned e_type
)
22689 static char buff
[64];
22694 return _("NT_STAPSDT (SystemTap probe descriptors)");
22700 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
22705 print_stapsdt_note (Elf_Internal_Note
*pnote
)
22707 size_t len
, maxlen
;
22708 size_t addr_size
= is_32bit_elf
? 4 : 8;
22709 char *data
= pnote
->descdata
;
22710 char *data_end
= pnote
->descdata
+ pnote
->descsz
;
22711 uint64_t pc
, base_addr
, semaphore
;
22712 char *provider
, *probe
, *arg_fmt
;
22714 if (pnote
->descsz
< (addr_size
* 3))
22715 goto stapdt_note_too_small
;
22717 pc
= byte_get ((unsigned char *) data
, addr_size
);
22720 base_addr
= byte_get ((unsigned char *) data
, addr_size
);
22723 semaphore
= byte_get ((unsigned char *) data
, addr_size
);
22726 if (data
>= data_end
)
22727 goto stapdt_note_too_small
;
22728 maxlen
= data_end
- data
;
22729 len
= strnlen (data
, maxlen
);
22736 goto stapdt_note_too_small
;
22738 if (data
>= data_end
)
22739 goto stapdt_note_too_small
;
22740 maxlen
= data_end
- data
;
22741 len
= strnlen (data
, maxlen
);
22748 goto stapdt_note_too_small
;
22750 if (data
>= data_end
)
22751 goto stapdt_note_too_small
;
22752 maxlen
= data_end
- data
;
22753 len
= strnlen (data
, maxlen
);
22760 goto stapdt_note_too_small
;
22762 printf (_(" Provider: %s\n"), provider
);
22763 printf (_(" Name: %s\n"), probe
);
22764 printf (_(" Location: "));
22765 print_vma (pc
, FULL_HEX
);
22766 printf (_(", Base: "));
22767 print_vma (base_addr
, FULL_HEX
);
22768 printf (_(", Semaphore: "));
22769 print_vma (semaphore
, FULL_HEX
);
22771 printf (_(" Arguments: %s\n"), arg_fmt
);
22773 return data
== data_end
;
22775 stapdt_note_too_small
:
22776 printf (_(" <corrupt - note is too small>\n"));
22777 error (_("corrupt stapdt note - the data size is too small\n"));
22782 print_fdo_note (Elf_Internal_Note
* pnote
)
22784 if (pnote
->descsz
> 0 && pnote
->type
== FDO_PACKAGING_METADATA
)
22786 printf (_(" Packaging Metadata: %.*s\n"), (int) pnote
->descsz
, pnote
->descdata
);
22789 if (pnote
->descsz
> 0 && pnote
->type
== FDO_DLOPEN_METADATA
)
22791 printf (_(" Dlopen Metadata: %.*s\n"), (int) pnote
->descsz
, pnote
->descdata
);
22797 static const char *
22798 get_ia64_vms_note_type (unsigned e_type
)
22800 static char buff
[64];
22805 return _("NT_VMS_MHD (module header)");
22807 return _("NT_VMS_LNM (language name)");
22809 return _("NT_VMS_SRC (source files)");
22811 return "NT_VMS_TITLE";
22813 return _("NT_VMS_EIDC (consistency check)");
22814 case NT_VMS_FPMODE
:
22815 return _("NT_VMS_FPMODE (FP mode)");
22816 case NT_VMS_LINKTIME
:
22817 return "NT_VMS_LINKTIME";
22818 case NT_VMS_IMGNAM
:
22819 return _("NT_VMS_IMGNAM (image name)");
22821 return _("NT_VMS_IMGID (image id)");
22822 case NT_VMS_LINKID
:
22823 return _("NT_VMS_LINKID (link id)");
22824 case NT_VMS_IMGBID
:
22825 return _("NT_VMS_IMGBID (build id)");
22826 case NT_VMS_GSTNAM
:
22827 return _("NT_VMS_GSTNAM (sym table name)");
22828 case NT_VMS_ORIG_DYN
:
22829 return "NT_VMS_ORIG_DYN";
22830 case NT_VMS_PATCHTIME
:
22831 return "NT_VMS_PATCHTIME";
22833 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
22839 print_ia64_vms_note (Elf_Internal_Note
* pnote
)
22841 unsigned int maxlen
= pnote
->descsz
;
22843 if (maxlen
< 2 || maxlen
!= pnote
->descsz
)
22844 goto desc_size_fail
;
22846 switch (pnote
->type
)
22850 goto desc_size_fail
;
22852 size_t l
= strnlen (pnote
->descdata
+ 34, maxlen
- 34);
22854 printf (_(" Creation date : %.17s\n"), pnote
->descdata
);
22855 printf (_(" Last patch date: %.17s\n"), pnote
->descdata
+ 17);
22856 if (l
+ 34 < maxlen
)
22858 printf (_(" Module name : %s\n"), pnote
->descdata
+ 34);
22859 if (l
+ 35 < maxlen
)
22860 printf (_(" Module version : %s\n"), pnote
->descdata
+ 34 + l
+ 1);
22862 printf (_(" Module version : <missing>\n"));
22866 printf (_(" Module name : <missing>\n"));
22867 printf (_(" Module version : <missing>\n"));
22872 printf (_(" Language: %.*s\n"), maxlen
, pnote
->descdata
);
22875 case NT_VMS_FPMODE
:
22876 printf (_(" Floating Point mode: "));
22878 goto desc_size_fail
;
22879 /* FIXME: Generate an error if descsz > 8 ? */
22881 printf ("0x%016" PRIx64
"\n",
22882 byte_get ((unsigned char *) pnote
->descdata
, 8));
22885 case NT_VMS_LINKTIME
:
22886 printf (_(" Link time: "));
22888 goto desc_size_fail
;
22889 /* FIXME: Generate an error if descsz > 8 ? */
22891 print_vms_time (byte_get ((unsigned char *) pnote
->descdata
, 8));
22895 case NT_VMS_PATCHTIME
:
22896 printf (_(" Patch time: "));
22898 goto desc_size_fail
;
22899 /* FIXME: Generate an error if descsz > 8 ? */
22901 print_vms_time (byte_get ((unsigned char *) pnote
->descdata
, 8));
22905 case NT_VMS_ORIG_DYN
:
22907 goto desc_size_fail
;
22909 printf (_(" Major id: %u, minor id: %u\n"),
22910 (unsigned) byte_get ((unsigned char *) pnote
->descdata
, 4),
22911 (unsigned) byte_get ((unsigned char *) pnote
->descdata
+ 4, 4));
22912 printf (_(" Last modified : "));
22913 print_vms_time (byte_get ((unsigned char *) pnote
->descdata
+ 8, 8));
22914 printf (_("\n Link flags : "));
22915 printf ("0x%016" PRIx64
"\n",
22916 byte_get ((unsigned char *) pnote
->descdata
+ 16, 8));
22917 printf (_(" Header flags: 0x%08x\n"),
22918 (unsigned) byte_get ((unsigned char *) pnote
->descdata
+ 24, 4));
22919 printf (_(" Image id : %.*s\n"), maxlen
- 32, pnote
->descdata
+ 32);
22922 case NT_VMS_IMGNAM
:
22923 printf (_(" Image name: %.*s\n"), maxlen
, pnote
->descdata
);
22926 case NT_VMS_GSTNAM
:
22927 printf (_(" Global symbol table name: %.*s\n"), maxlen
, pnote
->descdata
);
22931 printf (_(" Image id: %.*s\n"), maxlen
, pnote
->descdata
);
22934 case NT_VMS_LINKID
:
22935 printf (_(" Linker id: %.*s\n"), maxlen
, pnote
->descdata
);
22945 printf (_(" <corrupt - data size is too small>\n"));
22946 error (_("corrupt IA64 note: data size is too small\n"));
22950 struct build_attr_cache
{
22951 Filedata
*filedata
;
22953 uint64_t strtablen
;
22954 Elf_Internal_Sym
*symtab
;
22958 /* Find the symbol associated with a build attribute that is attached
22959 to address OFFSET. If PNAME is non-NULL then store the name of
22960 the symbol (if found) in the provided pointer, Returns NULL if a
22961 symbol could not be found. */
22963 static Elf_Internal_Sym
*
22964 get_symbol_for_build_attribute (Filedata
*filedata
,
22967 const char **pname
)
22969 Elf_Internal_Sym
*saved_sym
= NULL
;
22970 Elf_Internal_Sym
*sym
;
22972 if (filedata
->section_headers
!= NULL
22973 && (ba_cache
.filedata
== NULL
|| filedata
!= ba_cache
.filedata
))
22975 Elf_Internal_Shdr
* symsec
;
22977 free (ba_cache
.strtab
);
22978 ba_cache
.strtab
= NULL
;
22979 free (ba_cache
.symtab
);
22980 ba_cache
.symtab
= NULL
;
22982 /* Load the symbol and string sections. */
22983 for (symsec
= filedata
->section_headers
;
22984 symsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
22987 if (symsec
->sh_type
== SHT_SYMTAB
22988 && get_symtab (filedata
, symsec
,
22989 &ba_cache
.symtab
, &ba_cache
.nsyms
,
22990 &ba_cache
.strtab
, &ba_cache
.strtablen
))
22993 ba_cache
.filedata
= filedata
;
22996 if (ba_cache
.symtab
== NULL
)
22999 /* Find a symbol whose value matches offset. */
23000 for (sym
= ba_cache
.symtab
; sym
< ba_cache
.symtab
+ ba_cache
.nsyms
; sym
++)
23001 if (sym
->st_value
== offset
)
23003 if (sym
->st_name
>= ba_cache
.strtablen
)
23004 /* Huh ? This should not happen. */
23007 if (ba_cache
.strtab
[sym
->st_name
] == 0)
23010 /* The AArch64, ARM and RISC-V architectures define mapping symbols
23011 (eg $d, $x, $t) which we want to ignore. */
23012 if (ba_cache
.strtab
[sym
->st_name
] == '$'
23013 && ba_cache
.strtab
[sym
->st_name
+ 1] != 0
23014 && ba_cache
.strtab
[sym
->st_name
+ 2] == 0)
23019 /* For OPEN attributes we prefer GLOBAL over LOCAL symbols
23020 and FILE or OBJECT symbols over NOTYPE symbols. We skip
23021 FUNC symbols entirely. */
23022 switch (ELF_ST_TYPE (sym
->st_info
))
23029 /* If the symbol has a size associated
23030 with it then we can stop searching. */
23031 sym
= ba_cache
.symtab
+ ba_cache
.nsyms
;
23036 /* Ignore function symbols. */
23043 switch (ELF_ST_BIND (sym
->st_info
))
23046 if (saved_sym
== NULL
23047 || ELF_ST_TYPE (saved_sym
->st_info
) != STT_OBJECT
)
23052 if (saved_sym
== NULL
)
23062 if (ELF_ST_TYPE (sym
->st_info
) != STT_FUNC
)
23070 if (saved_sym
&& pname
)
23071 * pname
= ba_cache
.strtab
+ saved_sym
->st_name
;
23076 /* Returns true iff addr1 and addr2 are in the same section. */
23079 same_section (Filedata
* filedata
, uint64_t addr1
, uint64_t addr2
)
23081 Elf_Internal_Shdr
* a1
;
23082 Elf_Internal_Shdr
* a2
;
23084 a1
= find_section_by_address (filedata
, addr1
);
23085 a2
= find_section_by_address (filedata
, addr2
);
23087 return a1
== a2
&& a1
!= NULL
;
23091 print_gnu_build_attribute_description (Elf_Internal_Note
* pnote
,
23092 Filedata
* filedata
)
23094 static uint64_t global_offset
= 0;
23095 static uint64_t global_end
= 0;
23096 static uint64_t func_offset
= 0;
23097 static uint64_t func_end
= 0;
23099 Elf_Internal_Sym
*sym
;
23103 bool is_open_attr
= pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_OPEN
;
23105 switch (pnote
->descsz
)
23108 /* A zero-length description means that the range of
23109 the previous note of the same type should be used. */
23112 if (global_end
> global_offset
)
23113 printf (_(" Applies to region from %#" PRIx64
23114 " to %#" PRIx64
"\n"), global_offset
, global_end
);
23116 printf (_(" Applies to region from %#" PRIx64
23117 "\n"), global_offset
);
23121 if (func_end
> func_offset
)
23122 printf (_(" Applies to region from %#" PRIx64
23123 " to %#" PRIx64
"\n"), func_offset
, func_end
);
23125 printf (_(" Applies to region from %#" PRIx64
23126 "\n"), func_offset
);
23131 start
= byte_get ((unsigned char *) pnote
->descdata
, 4);
23136 start
= byte_get ((unsigned char *) pnote
->descdata
, 4);
23137 end
= byte_get ((unsigned char *) pnote
->descdata
+ 4, 4);
23141 start
= byte_get ((unsigned char *) pnote
->descdata
, 8);
23142 end
= byte_get ((unsigned char *) pnote
->descdata
+ 8, 8);
23146 error (_(" <invalid description size: %lx>\n"), pnote
->descsz
);
23147 printf (_(" <invalid descsz>"));
23152 sym
= get_symbol_for_build_attribute (filedata
, start
, is_open_attr
, & name
);
23153 /* As of version 5 of the annobin plugin, filename symbols are biased by 2
23154 in order to avoid them being confused with the start address of the
23155 first function in the file... */
23156 if (sym
== NULL
&& is_open_attr
)
23157 sym
= get_symbol_for_build_attribute (filedata
, start
+ 2, is_open_attr
,
23160 if (end
== 0 && sym
!= NULL
&& sym
->st_size
> 0)
23161 end
= start
+ sym
->st_size
;
23165 /* FIXME: Need to properly allow for section alignment.
23166 16 is just the alignment used on x86_64. */
23168 && start
> BFD_ALIGN (global_end
, 16)
23169 /* Build notes are not guaranteed to be organised in order of
23170 increasing address, but we should find the all of the notes
23171 for one section in the same place. */
23172 && same_section (filedata
, start
, global_end
))
23173 warn (_("Gap in build notes detected from %#" PRIx64
23174 " to %#" PRIx64
"\n"),
23175 global_end
+ 1, start
- 1);
23177 printf (_(" Applies to region from %#" PRIx64
), start
);
23178 global_offset
= start
;
23182 printf (_(" to %#" PRIx64
), end
);
23188 printf (_(" Applies to region from %#" PRIx64
), start
);
23189 func_offset
= start
;
23193 printf (_(" to %#" PRIx64
), end
);
23199 printf (_(" (%s)"), name
);
23206 print_gnu_build_attribute_name (Elf_Internal_Note
* pnote
)
23208 static const char string_expected
[2] = { GNU_BUILD_ATTRIBUTE_TYPE_STRING
, 0 };
23209 static const char number_expected
[2] = { GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC
, 0 };
23210 static const char bool_expected
[3] = { GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE
, GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE
, 0 };
23212 char name_attribute
;
23213 const char * expected_types
;
23214 const char * name
= pnote
->namedata
;
23218 if (name
== NULL
|| pnote
->namesz
< 2)
23220 error (_("corrupt name field in GNU build attribute note: size = %ld\n"), pnote
->namesz
);
23221 print_symbol_name (-20, _(" <corrupt name>"));
23230 /* Version 2 of the spec adds a "GA" prefix to the name field. */
23231 if (name
[0] == 'G' && name
[1] == 'A')
23233 if (pnote
->namesz
< 4)
23235 error (_("corrupt name field in GNU build attribute note: size = %ld\n"), pnote
->namesz
);
23236 print_symbol_name (-20, _(" <corrupt name>"));
23245 switch ((name_type
= * name
))
23247 case GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC
:
23248 case GNU_BUILD_ATTRIBUTE_TYPE_STRING
:
23249 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE
:
23250 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE
:
23251 printf ("%c", * name
);
23255 error (_("unrecognised attribute type in name field: %d\n"), name_type
);
23256 print_symbol_name (-20, _("<unknown name type>"));
23263 switch ((name_attribute
= * name
))
23265 case GNU_BUILD_ATTRIBUTE_VERSION
:
23266 text
= _("<version>");
23267 expected_types
= string_expected
;
23270 case GNU_BUILD_ATTRIBUTE_STACK_PROT
:
23271 text
= _("<stack prot>");
23272 expected_types
= "!+*";
23275 case GNU_BUILD_ATTRIBUTE_RELRO
:
23276 text
= _("<relro>");
23277 expected_types
= bool_expected
;
23280 case GNU_BUILD_ATTRIBUTE_STACK_SIZE
:
23281 text
= _("<stack size>");
23282 expected_types
= number_expected
;
23285 case GNU_BUILD_ATTRIBUTE_TOOL
:
23286 text
= _("<tool>");
23287 expected_types
= string_expected
;
23290 case GNU_BUILD_ATTRIBUTE_ABI
:
23292 expected_types
= "$*";
23295 case GNU_BUILD_ATTRIBUTE_PIC
:
23297 expected_types
= number_expected
;
23300 case GNU_BUILD_ATTRIBUTE_SHORT_ENUM
:
23301 text
= _("<short enum>");
23302 expected_types
= bool_expected
;
23306 if (ISPRINT (* name
))
23308 int len
= strnlen (name
, pnote
->namesz
- (name
- pnote
->namedata
)) + 1;
23310 if (len
> left
&& ! do_wide
)
23312 printf ("%.*s:", len
, name
);
23318 static char tmpbuf
[128];
23320 error (_("unrecognised byte in name field: %d\n"), * name
);
23321 sprintf (tmpbuf
, _("<unknown:_%d>"), * name
);
23325 expected_types
= "*$!+";
23330 left
-= printf ("%s", text
);
23332 if (strchr (expected_types
, name_type
) == NULL
)
23333 warn (_("attribute does not have an expected type (%c)\n"), name_type
);
23335 if ((size_t) (name
- pnote
->namedata
) > pnote
->namesz
)
23337 error (_("corrupt name field: namesz: %lu but parsing gets to %td\n"),
23339 name
- pnote
->namedata
);
23343 if (left
< 1 && ! do_wide
)
23348 case GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC
:
23350 unsigned int bytes
;
23352 unsigned int shift
= 0;
23353 char *decoded
= NULL
;
23355 bytes
= pnote
->namesz
- (name
- pnote
->namedata
);
23357 /* The -1 is because the name field is always 0 terminated, and we
23358 want to be able to ensure that the shift in the while loop below
23359 will not overflow. */
23362 if (bytes
> sizeof (val
))
23364 error (_("corrupt numeric name field: too many bytes in the value: %x\n"),
23366 bytes
= sizeof (val
);
23368 /* We do not bother to warn if bytes == 0 as this can
23369 happen with some early versions of the gcc plugin. */
23373 uint64_t byte
= *name
++ & 0xff;
23375 val
|= byte
<< shift
;
23379 switch (name_attribute
)
23381 case GNU_BUILD_ATTRIBUTE_PIC
:
23384 case 0: decoded
= "static"; break;
23385 case 1: decoded
= "pic"; break;
23386 case 2: decoded
= "PIC"; break;
23387 case 3: decoded
= "pie"; break;
23388 case 4: decoded
= "PIE"; break;
23392 case GNU_BUILD_ATTRIBUTE_STACK_PROT
:
23395 /* Based upon the SPCT_FLAG_xxx enum values in gcc/cfgexpand.c. */
23396 case 0: decoded
= "off"; break;
23397 case 1: decoded
= "on"; break;
23398 case 2: decoded
= "all"; break;
23399 case 3: decoded
= "strong"; break;
23400 case 4: decoded
= "explicit"; break;
23408 if (decoded
!= NULL
)
23410 print_symbol_name (-left
, decoded
);
23421 left
-= printf ("0x%" PRIx64
, val
);
23423 left
-= printf ("0x%-.*" PRIx64
, left
, val
);
23427 case GNU_BUILD_ATTRIBUTE_TYPE_STRING
:
23428 left
-= print_symbol_name (- left
, name
);
23430 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE
:
23431 left
-= print_symbol_name (- left
, "true");
23433 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE
:
23434 left
-= print_symbol_name (- left
, "false");
23438 if (do_wide
&& left
> 0)
23439 printf ("%-*s", left
, " ");
23444 /* Print the contents of PNOTE as hex. */
23447 print_note_contents_hex (Elf_Internal_Note
*pnote
)
23453 printf (_(" description data: "));
23454 for (i
= 0; i
< pnote
->descsz
; i
++)
23455 printf ("%02x ", pnote
->descdata
[i
] & 0xff);
23464 #if defined HAVE_MSGPACK
23467 print_indents (int n
)
23471 for (int i
= 0; i
< n
; i
++)
23475 /* Print OBJ in human-readable form. */
23478 dump_msgpack_obj (const msgpack_object
*obj
, int indent
)
23482 case MSGPACK_OBJECT_NIL
:
23486 case MSGPACK_OBJECT_BOOLEAN
:
23487 printf ("%s", obj
->via
.boolean
? "true" : "false");
23490 case MSGPACK_OBJECT_POSITIVE_INTEGER
:
23491 printf ("%" PRIu64
, obj
->via
.u64
);
23494 case MSGPACK_OBJECT_NEGATIVE_INTEGER
:
23495 printf ("%" PRIi64
, obj
->via
.i64
);
23498 case MSGPACK_OBJECT_FLOAT32
:
23499 case MSGPACK_OBJECT_FLOAT64
:
23500 printf ("%f", obj
->via
.f64
);
23503 case MSGPACK_OBJECT_STR
:
23504 printf ("\"%.*s\"", obj
->via
.str
.size
, obj
->via
.str
.ptr
);
23507 case MSGPACK_OBJECT_ARRAY
:
23509 const msgpack_object_array
*array
= &obj
->via
.array
;
23514 for (uint32_t i
= 0; i
< array
->size
; ++i
)
23516 const msgpack_object
*item
= &array
->ptr
[i
];
23518 print_indents (indent
);
23519 dump_msgpack_obj (item
, indent
);
23524 print_indents (indent
);
23530 case MSGPACK_OBJECT_MAP
:
23532 const msgpack_object_map
*map
= &obj
->via
.map
;
23537 for (uint32_t i
= 0; i
< map
->size
; ++i
)
23539 const msgpack_object_kv
*kv
= &map
->ptr
[i
];
23540 const msgpack_object
*key
= &kv
->key
;
23541 const msgpack_object
*val
= &kv
->val
;
23543 print_indents (indent
);
23544 dump_msgpack_obj (key
, indent
);
23546 dump_msgpack_obj (val
, indent
);
23552 print_indents (indent
);
23558 case MSGPACK_OBJECT_BIN
:
23562 case MSGPACK_OBJECT_EXT
:
23569 dump_msgpack (const msgpack_unpacked
*msg
)
23572 dump_msgpack_obj (&msg
->data
, 0);
23576 #endif /* defined HAVE_MSGPACK */
23579 print_amdgpu_note (Elf_Internal_Note
*pnote
)
23581 #if defined HAVE_MSGPACK
23582 /* If msgpack is available, decode and dump the note's content. */
23584 msgpack_unpacked msg
;
23585 msgpack_unpack_return msgpack_ret
;
23587 assert (pnote
->type
== NT_AMDGPU_METADATA
);
23589 msgpack_unpacked_init (&msg
);
23590 msgpack_ret
= msgpack_unpack_next (&msg
, pnote
->descdata
, pnote
->descsz
,
23593 switch (msgpack_ret
)
23595 case MSGPACK_UNPACK_SUCCESS
:
23596 dump_msgpack (&msg
);
23601 error (_("failed to unpack msgpack contents in NT_AMDGPU_METADATA note"));
23606 msgpack_unpacked_destroy (&msg
);
23609 /* msgpack is not available, dump contents as hex. */
23610 print_note_contents_hex (pnote
);
23616 print_qnx_note (Elf_Internal_Note
*pnote
)
23618 switch (pnote
->type
)
23621 if (pnote
->descsz
!= 12)
23622 goto desc_size_fail
;
23624 printf (_(" Stack Size: 0x%" PRIx32
"\n"),
23625 (unsigned) byte_get ((unsigned char *) pnote
->descdata
, 4));
23626 printf (_(" Stack allocated: %" PRIx32
"\n"),
23627 (unsigned) byte_get ((unsigned char *) pnote
->descdata
+ 4, 4));
23628 printf (_(" Executable: %s\n"),
23629 ((unsigned) byte_get ((unsigned char *) pnote
->descdata
+ 8, 1)) ? "no": "yes");
23633 print_note_contents_hex(pnote
);
23638 printf (_(" <corrupt - data size is too small>\n"));
23639 error (_("corrupt QNX note: data size is too small\n"));
23644 /* Note that by the ELF standard, the name field is already null byte
23645 terminated, and namesz includes the terminating null byte.
23646 I.E. the value of namesz for the name "FSF" is 4.
23648 If the value of namesz is zero, there is no name present. */
23651 process_note (Elf_Internal_Note
* pnote
,
23652 Filedata
* filedata
)
23654 const char * name
= pnote
->namesz
? pnote
->namedata
: "(NONE)";
23657 if (pnote
->namesz
== 0)
23658 /* If there is no note name, then use the default set of
23659 note type strings. */
23660 nt
= get_note_type (filedata
, pnote
->type
);
23662 else if (startswith (pnote
->namedata
, "GNU"))
23663 /* GNU-specific object file notes. */
23664 nt
= get_gnu_elf_note_type (pnote
->type
);
23666 else if (startswith (pnote
->namedata
, "AMDGPU"))
23667 /* AMDGPU-specific object file notes. */
23668 nt
= get_amdgpu_elf_note_type (pnote
->type
);
23670 else if (startswith (pnote
->namedata
, "FreeBSD"))
23671 /* FreeBSD-specific core file notes. */
23672 nt
= get_freebsd_elfcore_note_type (filedata
, pnote
->type
);
23674 else if (startswith (pnote
->namedata
, "NetBSD-CORE"))
23675 /* NetBSD-specific core file notes. */
23676 nt
= get_netbsd_elfcore_note_type (filedata
, pnote
->type
);
23678 else if (startswith (pnote
->namedata
, "NetBSD"))
23679 /* NetBSD-specific core file notes. */
23680 return process_netbsd_elf_note (pnote
);
23682 else if (startswith (pnote
->namedata
, "PaX"))
23683 /* NetBSD-specific core file notes. */
23684 return process_netbsd_elf_note (pnote
);
23686 else if (startswith (pnote
->namedata
, "OpenBSD"))
23687 /* OpenBSD-specific core file notes. */
23688 nt
= get_openbsd_elfcore_note_type (filedata
, pnote
->type
);
23690 else if (startswith (pnote
->namedata
, "QNX"))
23691 /* QNX-specific core file notes. */
23692 nt
= get_qnx_elfcore_note_type (filedata
, pnote
->type
);
23694 else if (startswith (pnote
->namedata
, "SPU/"))
23696 /* SPU-specific core file notes. */
23697 nt
= pnote
->namedata
+ 4;
23701 else if (startswith (pnote
->namedata
, "IPF/VMS"))
23702 /* VMS/ia64-specific file notes. */
23703 nt
= get_ia64_vms_note_type (pnote
->type
);
23705 else if (startswith (pnote
->namedata
, "stapsdt"))
23706 nt
= get_stapsdt_note_type (pnote
->type
);
23709 /* Don't recognize this note name; just use the default set of
23710 note type strings. */
23711 nt
= get_note_type (filedata
, pnote
->type
);
23715 if (((startswith (pnote
->namedata
, "GA")
23716 && strchr ("*$!+", pnote
->namedata
[2]) != NULL
)
23717 || strchr ("*$!+", pnote
->namedata
[0]) != NULL
)
23718 && (pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_OPEN
23719 || pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_FUNC
))
23720 print_gnu_build_attribute_name (pnote
);
23722 print_symbol_name (-20, name
);
23725 printf (" 0x%08lx\t%s\t", pnote
->descsz
, nt
);
23727 printf (" 0x%08lx\t%s\n", pnote
->descsz
, nt
);
23729 if (startswith (pnote
->namedata
, "IPF/VMS"))
23730 return print_ia64_vms_note (pnote
);
23731 else if (startswith (pnote
->namedata
, "GNU"))
23732 return print_gnu_note (filedata
, pnote
);
23733 else if (startswith (pnote
->namedata
, "stapsdt"))
23734 return print_stapsdt_note (pnote
);
23735 else if (startswith (pnote
->namedata
, "CORE"))
23736 return print_core_note (pnote
);
23737 else if (startswith (pnote
->namedata
, "FDO"))
23738 return print_fdo_note (pnote
);
23739 else if (((startswith (pnote
->namedata
, "GA")
23740 && strchr ("*$!+", pnote
->namedata
[2]) != NULL
)
23741 || strchr ("*$!+", pnote
->namedata
[0]) != NULL
)
23742 && (pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_OPEN
23743 || pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_FUNC
))
23744 return print_gnu_build_attribute_description (pnote
, filedata
);
23745 else if (startswith (pnote
->namedata
, "AMDGPU")
23746 && pnote
->type
== NT_AMDGPU_METADATA
)
23747 return print_amdgpu_note (pnote
);
23748 else if (startswith (pnote
->namedata
, "QNX"))
23749 return print_qnx_note (pnote
);
23751 print_note_contents_hex (pnote
);
23756 process_notes_at (Filedata
* filedata
,
23757 Elf_Internal_Shdr
* section
,
23762 Elf_External_Note
*pnotes
;
23763 Elf_External_Note
*external
;
23772 pnotes
= (Elf_External_Note
*) get_section_contents (section
, filedata
);
23775 if (! apply_relocations (filedata
, section
, (unsigned char *) pnotes
, length
, NULL
, NULL
))
23783 pnotes
= (Elf_External_Note
*) get_data (NULL
, filedata
, offset
, 1, length
,
23786 if (pnotes
== NULL
)
23791 if (filedata
->is_separate
)
23792 printf (_("In linked file '%s': "), filedata
->file_name
);
23796 printf (_("Displaying notes found in: %s\n"), printable_section_name (filedata
, section
));
23798 printf (_("Displaying notes found at file offset 0x%08" PRIx64
23799 " with length 0x%08" PRIx64
":\n"),
23802 /* NB: Some note sections may have alignment value of 0 or 1. gABI
23803 specifies that notes should be aligned to 4 bytes in 32-bit
23804 objects and to 8 bytes in 64-bit objects. As a Linux extension,
23805 we also support 4 byte alignment in 64-bit objects. If section
23806 alignment is less than 4, we treate alignment as 4 bytes. */
23809 else if (align
!= 4 && align
!= 8)
23811 warn (_("Corrupt note: alignment %" PRId64
", expecting 4 or 8\n"),
23817 printf (_(" %-20s %-10s\tDescription\n"), _("Owner"), _("Data size"));
23819 end
= (char *) pnotes
+ length
;
23820 while ((char *) external
< end
)
23822 Elf_Internal_Note inote
;
23825 char * temp
= NULL
;
23826 size_t data_remaining
= end
- (char *) external
;
23828 if (!is_ia64_vms (filedata
))
23830 /* PR binutils/15191
23831 Make sure that there is enough data to read. */
23832 min_notesz
= offsetof (Elf_External_Note
, name
);
23833 if (data_remaining
< min_notesz
)
23835 warn (ngettext ("Corrupt note: only %zd byte remains, "
23836 "not enough for a full note\n",
23837 "Corrupt note: only %zd bytes remain, "
23838 "not enough for a full note\n",
23843 data_remaining
-= min_notesz
;
23845 inote
.type
= BYTE_GET (external
->type
);
23846 inote
.namesz
= BYTE_GET (external
->namesz
);
23847 inote
.namedata
= external
->name
;
23848 inote
.descsz
= BYTE_GET (external
->descsz
);
23849 inote
.descdata
= ((char *) external
23850 + ELF_NOTE_DESC_OFFSET (inote
.namesz
, align
));
23851 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
23852 next
= ((char *) external
23853 + ELF_NOTE_NEXT_OFFSET (inote
.namesz
, inote
.descsz
, align
));
23857 Elf64_External_VMS_Note
*vms_external
;
23859 /* PR binutils/15191
23860 Make sure that there is enough data to read. */
23861 min_notesz
= offsetof (Elf64_External_VMS_Note
, name
);
23862 if (data_remaining
< min_notesz
)
23864 warn (ngettext ("Corrupt note: only %zd byte remains, "
23865 "not enough for a full note\n",
23866 "Corrupt note: only %zd bytes remain, "
23867 "not enough for a full note\n",
23872 data_remaining
-= min_notesz
;
23874 vms_external
= (Elf64_External_VMS_Note
*) external
;
23875 inote
.type
= BYTE_GET (vms_external
->type
);
23876 inote
.namesz
= BYTE_GET (vms_external
->namesz
);
23877 inote
.namedata
= vms_external
->name
;
23878 inote
.descsz
= BYTE_GET (vms_external
->descsz
);
23879 inote
.descdata
= inote
.namedata
+ align_power (inote
.namesz
, 3);
23880 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
23881 next
= inote
.descdata
+ align_power (inote
.descsz
, 3);
23884 /* PR 17531: file: 3443835e. */
23885 /* PR 17531: file: id:000000,sig:11,src:006986,op:havoc,rep:4. */
23886 if ((size_t) (inote
.descdata
- inote
.namedata
) < inote
.namesz
23887 || (size_t) (inote
.descdata
- inote
.namedata
) > data_remaining
23888 || (size_t) (next
- inote
.descdata
) < inote
.descsz
23889 || ((size_t) (next
- inote
.descdata
)
23890 > data_remaining
- (size_t) (inote
.descdata
- inote
.namedata
)))
23892 warn (_("note with invalid namesz and/or descsz found at offset %#tx\n"),
23893 (char *) external
- (char *) pnotes
);
23894 warn (_(" type: %#lx, namesize: %#lx, descsize: %#lx, alignment: %u\n"),
23895 inote
.type
, inote
.namesz
, inote
.descsz
, (int) align
);
23899 external
= (Elf_External_Note
*) next
;
23901 /* Verify that name is null terminated. It appears that at least
23902 one version of Linux (RedHat 6.0) generates corefiles that don't
23903 comply with the ELF spec by failing to include the null byte in
23905 if (inote
.namesz
> 0 && inote
.namedata
[inote
.namesz
- 1] != '\0')
23907 if ((size_t) (inote
.descdata
- inote
.namedata
) == inote
.namesz
)
23909 temp
= (char *) malloc (inote
.namesz
+ 1);
23912 error (_("Out of memory allocating space for inote name\n"));
23917 memcpy (temp
, inote
.namedata
, inote
.namesz
);
23918 inote
.namedata
= temp
;
23920 inote
.namedata
[inote
.namesz
] = 0;
23923 if (! process_note (& inote
, filedata
))
23936 process_corefile_note_segments (Filedata
* filedata
)
23938 Elf_Internal_Phdr
*segment
;
23942 if (! get_program_headers (filedata
))
23945 for (i
= 0, segment
= filedata
->program_headers
;
23946 i
< filedata
->file_header
.e_phnum
;
23949 if (segment
->p_type
== PT_NOTE
)
23950 if (! process_notes_at (filedata
, NULL
, segment
->p_offset
,
23951 segment
->p_filesz
, segment
->p_align
))
23959 process_v850_notes (Filedata
* filedata
, uint64_t offset
, uint64_t length
)
23961 Elf_External_Note
* pnotes
;
23962 Elf_External_Note
* external
;
23969 pnotes
= (Elf_External_Note
*) get_data (NULL
, filedata
, offset
, 1, length
,
23971 if (pnotes
== NULL
)
23975 end
= (char*) pnotes
+ length
;
23977 printf (_("\nDisplaying contents of Renesas V850 notes section at offset"
23978 " %#" PRIx64
" with length %#" PRIx64
":\n"),
23981 while ((char *) external
< end
)
23984 Elf_Internal_Note inote
;
23985 size_t data_remaining
= end
- (char *) external
;
23987 if (data_remaining
< offsetof (Elf_External_Note
, name
))
23989 data_remaining
-= offsetof (Elf_External_Note
, name
);
23991 inote
.type
= BYTE_GET (external
->type
);
23992 inote
.namesz
= BYTE_GET (external
->namesz
);
23993 inote
.namedata
= external
->name
;
23994 inote
.descsz
= BYTE_GET (external
->descsz
);
23995 inote
.descdata
= inote
.namedata
+ align_power (inote
.namesz
, 2);
23996 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
23997 next
= inote
.descdata
+ align_power (inote
.descsz
, 2);
23999 if ((size_t) (inote
.descdata
- inote
.namedata
) < inote
.namesz
24000 || (size_t) (inote
.descdata
- inote
.namedata
) > data_remaining
24001 || (size_t) (next
- inote
.descdata
) < inote
.descsz
24002 || ((size_t) (next
- inote
.descdata
)
24003 > data_remaining
- (size_t) (inote
.descdata
- inote
.namedata
)))
24005 warn (_("note with invalid namesz and/or descsz found at offset %#tx\n"),
24006 (char *) external
- (char *) pnotes
);
24007 warn (_(" type: %#lx, namesize: %#lx, descsize: %#lx, alignment: %u\n"),
24008 inote
.type
, inote
.namesz
, inote
.descsz
, 2);
24012 external
= (Elf_External_Note
*) next
;
24014 if (! print_v850_note (& inote
))
24024 process_note_sections (Filedata
* filedata
)
24026 Elf_Internal_Shdr
*section
;
24028 unsigned int n
= 0;
24031 for (i
= 0, section
= filedata
->section_headers
;
24032 i
< filedata
->file_header
.e_shnum
&& section
!= NULL
;
24035 if (section
->sh_type
== SHT_NOTE
)
24037 if (! process_notes_at (filedata
, section
, section
->sh_offset
,
24038 section
->sh_size
, section
->sh_addralign
))
24043 if (( filedata
->file_header
.e_machine
== EM_V800
24044 || filedata
->file_header
.e_machine
== EM_V850
24045 || filedata
->file_header
.e_machine
== EM_CYGNUS_V850
)
24046 && section
->sh_type
== SHT_RENESAS_INFO
)
24048 if (! process_v850_notes (filedata
, section
->sh_offset
,
24056 /* Try processing NOTE segments instead. */
24057 return process_corefile_note_segments (filedata
);
24063 process_notes (Filedata
* filedata
)
24065 /* If we have not been asked to display the notes then do nothing. */
24069 if (filedata
->file_header
.e_type
!= ET_CORE
)
24070 return process_note_sections (filedata
);
24072 /* No program headers means no NOTE segment. */
24073 if (filedata
->file_header
.e_phnum
> 0)
24074 return process_corefile_note_segments (filedata
);
24076 if (filedata
->is_separate
)
24077 printf (_("No notes found in linked file '%s'.\n"),
24078 filedata
->file_name
);
24080 printf (_("No notes found file.\n"));
24085 static unsigned char *
24086 display_public_gnu_attributes (unsigned char * start
,
24087 const unsigned char * const end
)
24089 printf (_(" Unknown GNU attribute: %s\n"), start
);
24091 start
+= strnlen ((char *) start
, end
- start
);
24092 display_raw_attribute (start
, end
);
24094 return (unsigned char *) end
;
24097 static unsigned char *
24098 display_generic_attribute (unsigned char * start
,
24100 const unsigned char * const end
)
24103 return (unsigned char *) end
;
24105 return display_tag_value (tag
, start
, end
);
24109 process_arch_specific (Filedata
* filedata
)
24114 switch (filedata
->file_header
.e_machine
)
24117 case EM_ARC_COMPACT
:
24118 case EM_ARC_COMPACT2
:
24119 case EM_ARC_COMPACT3
:
24120 case EM_ARC_COMPACT3_64
:
24121 return process_attributes (filedata
, "ARC", SHT_ARC_ATTRIBUTES
,
24122 display_arc_attribute
,
24123 display_generic_attribute
);
24125 return process_attributes (filedata
, "aeabi", SHT_ARM_ATTRIBUTES
,
24126 display_arm_attribute
,
24127 display_generic_attribute
);
24130 case EM_MIPS_RS3_LE
:
24131 return process_mips_specific (filedata
, false);
24134 return process_attributes (filedata
, "mspabi", SHT_MSP430_ATTRIBUTES
,
24135 display_msp430_attribute
,
24136 display_msp430_gnu_attribute
);
24139 return process_attributes (filedata
, "riscv", SHT_RISCV_ATTRIBUTES
,
24140 display_riscv_attribute
,
24141 display_generic_attribute
);
24144 return process_nds32_specific (filedata
);
24147 return process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
24148 display_m68k_gnu_attribute
);
24152 return process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
24153 display_power_gnu_attribute
);
24157 return process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
24158 display_s390_gnu_attribute
);
24161 case EM_SPARC32PLUS
:
24163 return process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
24164 display_sparc_gnu_attribute
);
24167 return process_attributes (filedata
, "c6xabi", SHT_C6000_ATTRIBUTES
,
24168 display_tic6x_attribute
,
24169 display_generic_attribute
);
24172 return process_attributes (filedata
, "csky", SHT_CSKY_ATTRIBUTES
,
24173 display_csky_attribute
, NULL
);
24176 return process_attributes (filedata
, "gnu", SHT_GNU_ATTRIBUTES
,
24177 display_public_gnu_attributes
,
24178 display_generic_attribute
);
24183 get_file_header (Filedata
* filedata
)
24185 /* Read in the identity array. */
24186 if (fread (filedata
->file_header
.e_ident
, EI_NIDENT
, 1, filedata
->handle
) != 1)
24189 /* Determine how to read the rest of the header. */
24190 switch (filedata
->file_header
.e_ident
[EI_DATA
])
24195 byte_get
= byte_get_little_endian
;
24196 byte_put
= byte_put_little_endian
;
24199 byte_get
= byte_get_big_endian
;
24200 byte_put
= byte_put_big_endian
;
24204 /* For now we only support 32 bit and 64 bit ELF files. */
24205 is_32bit_elf
= (filedata
->file_header
.e_ident
[EI_CLASS
] != ELFCLASS64
);
24207 /* Read in the rest of the header. */
24210 Elf32_External_Ehdr ehdr32
;
24212 if (fread (ehdr32
.e_type
, sizeof (ehdr32
) - EI_NIDENT
, 1, filedata
->handle
) != 1)
24215 filedata
->file_header
.e_type
= BYTE_GET (ehdr32
.e_type
);
24216 filedata
->file_header
.e_machine
= BYTE_GET (ehdr32
.e_machine
);
24217 filedata
->file_header
.e_version
= BYTE_GET (ehdr32
.e_version
);
24218 filedata
->file_header
.e_entry
= BYTE_GET (ehdr32
.e_entry
);
24219 filedata
->file_header
.e_phoff
= BYTE_GET (ehdr32
.e_phoff
);
24220 filedata
->file_header
.e_shoff
= BYTE_GET (ehdr32
.e_shoff
);
24221 filedata
->file_header
.e_flags
= BYTE_GET (ehdr32
.e_flags
);
24222 filedata
->file_header
.e_ehsize
= BYTE_GET (ehdr32
.e_ehsize
);
24223 filedata
->file_header
.e_phentsize
= BYTE_GET (ehdr32
.e_phentsize
);
24224 filedata
->file_header
.e_phnum
= BYTE_GET (ehdr32
.e_phnum
);
24225 filedata
->file_header
.e_shentsize
= BYTE_GET (ehdr32
.e_shentsize
);
24226 filedata
->file_header
.e_shnum
= BYTE_GET (ehdr32
.e_shnum
);
24227 filedata
->file_header
.e_shstrndx
= BYTE_GET (ehdr32
.e_shstrndx
);
24231 Elf64_External_Ehdr ehdr64
;
24233 if (fread (ehdr64
.e_type
, sizeof (ehdr64
) - EI_NIDENT
, 1, filedata
->handle
) != 1)
24236 filedata
->file_header
.e_type
= BYTE_GET (ehdr64
.e_type
);
24237 filedata
->file_header
.e_machine
= BYTE_GET (ehdr64
.e_machine
);
24238 filedata
->file_header
.e_version
= BYTE_GET (ehdr64
.e_version
);
24239 filedata
->file_header
.e_entry
= BYTE_GET (ehdr64
.e_entry
);
24240 filedata
->file_header
.e_phoff
= BYTE_GET (ehdr64
.e_phoff
);
24241 filedata
->file_header
.e_shoff
= BYTE_GET (ehdr64
.e_shoff
);
24242 filedata
->file_header
.e_flags
= BYTE_GET (ehdr64
.e_flags
);
24243 filedata
->file_header
.e_ehsize
= BYTE_GET (ehdr64
.e_ehsize
);
24244 filedata
->file_header
.e_phentsize
= BYTE_GET (ehdr64
.e_phentsize
);
24245 filedata
->file_header
.e_phnum
= BYTE_GET (ehdr64
.e_phnum
);
24246 filedata
->file_header
.e_shentsize
= BYTE_GET (ehdr64
.e_shentsize
);
24247 filedata
->file_header
.e_shnum
= BYTE_GET (ehdr64
.e_shnum
);
24248 filedata
->file_header
.e_shstrndx
= BYTE_GET (ehdr64
.e_shstrndx
);
24255 free_filedata (Filedata
*filedata
)
24257 free (filedata
->program_interpreter
);
24258 free (filedata
->program_headers
);
24259 free (filedata
->section_headers
);
24260 free (filedata
->string_table
);
24261 free (filedata
->dump
.dump_sects
);
24262 free (filedata
->dynamic_strings
);
24263 free (filedata
->dynamic_symbols
);
24264 free (filedata
->dynamic_syminfo
);
24265 free (filedata
->dynamic_section
);
24267 while (filedata
->symtab_shndx_list
!= NULL
)
24269 elf_section_list
*next
= filedata
->symtab_shndx_list
->next
;
24270 free (filedata
->symtab_shndx_list
);
24271 filedata
->symtab_shndx_list
= next
;
24274 free (filedata
->section_headers_groups
);
24276 if (filedata
->section_groups
)
24279 struct group_list
* g
;
24280 struct group_list
* next
;
24282 for (i
= 0; i
< filedata
->group_count
; i
++)
24284 for (g
= filedata
->section_groups
[i
].root
; g
!= NULL
; g
= next
)
24291 free (filedata
->section_groups
);
24293 memset (&filedata
->section_headers
, 0,
24294 sizeof (Filedata
) - offsetof (Filedata
, section_headers
));
24298 close_file (Filedata
* filedata
)
24302 if (filedata
->handle
)
24303 fclose (filedata
->handle
);
24309 close_debug_file (void * data
)
24311 free_filedata ((Filedata
*) data
);
24312 close_file ((Filedata
*) data
);
24316 open_file (const char * pathname
, bool is_separate
)
24318 struct stat statbuf
;
24319 Filedata
* filedata
= NULL
;
24321 if (stat (pathname
, & statbuf
) < 0
24322 || ! S_ISREG (statbuf
.st_mode
))
24325 filedata
= calloc (1, sizeof * filedata
);
24326 if (filedata
== NULL
)
24329 filedata
->handle
= fopen (pathname
, "rb");
24330 if (filedata
->handle
== NULL
)
24333 filedata
->file_size
= statbuf
.st_size
;
24334 filedata
->file_name
= pathname
;
24335 filedata
->is_separate
= is_separate
;
24337 if (! get_file_header (filedata
))
24340 if (!get_section_headers (filedata
, false))
24348 if (filedata
->handle
)
24349 fclose (filedata
->handle
);
24356 open_debug_file (const char * pathname
)
24358 return open_file (pathname
, true);
24362 initialise_dump_sects (Filedata
* filedata
)
24364 /* Initialise the dump_sects array from the cmdline_dump_sects array.
24365 Note we do this even if cmdline_dump_sects is empty because we
24366 must make sure that the dump_sets array is zeroed out before each
24367 object file is processed. */
24368 if (filedata
->dump
.num_dump_sects
> cmdline
.num_dump_sects
)
24369 memset (filedata
->dump
.dump_sects
, 0,
24370 filedata
->dump
.num_dump_sects
* sizeof (*filedata
->dump
.dump_sects
));
24372 if (cmdline
.num_dump_sects
> 0)
24374 if (filedata
->dump
.num_dump_sects
== 0)
24375 /* A sneaky way of allocating the dump_sects array. */
24376 request_dump_bynumber (&filedata
->dump
, cmdline
.num_dump_sects
, 0);
24378 assert (filedata
->dump
.num_dump_sects
>= cmdline
.num_dump_sects
);
24379 memcpy (filedata
->dump
.dump_sects
, cmdline
.dump_sects
,
24380 cmdline
.num_dump_sects
* sizeof (*filedata
->dump
.dump_sects
));
24385 might_need_separate_debug_info (Filedata
* filedata
)
24387 /* Debuginfo files do not need further separate file loading. */
24388 if (filedata
->file_header
.e_shstrndx
== SHN_UNDEF
)
24391 /* Since do_follow_links might be enabled by default, only treat it as an
24392 indication that separate files should be loaded if setting it was a
24393 deliberate user action. */
24394 if (DEFAULT_FOR_FOLLOW_LINKS
== 0 && do_follow_links
)
24397 if (process_links
|| do_syms
|| do_unwind
24398 || dump_any_debugging
|| do_dump
|| do_debugging
)
24404 /* Process one ELF object file according to the command line options.
24405 This file may actually be stored in an archive. The file is
24406 positioned at the start of the ELF object. Returns TRUE if no
24407 problems were encountered, FALSE otherwise. */
24410 process_object (Filedata
* filedata
)
24412 bool have_separate_files
;
24416 if (! get_file_header (filedata
))
24418 error (_("%s: Failed to read file header\n"), filedata
->file_name
);
24422 /* Initialise per file variables. */
24423 for (i
= ARRAY_SIZE (filedata
->version_info
); i
--;)
24424 filedata
->version_info
[i
] = 0;
24426 for (i
= ARRAY_SIZE (filedata
->dynamic_info
); i
--;)
24427 filedata
->dynamic_info
[i
] = 0;
24428 filedata
->dynamic_info_DT_GNU_HASH
= 0;
24429 filedata
->dynamic_info_DT_MIPS_XHASH
= 0;
24431 /* Process the file. */
24433 printf (_("\nFile: %s\n"), filedata
->file_name
);
24435 initialise_dump_sects (filedata
);
24437 /* There may be some extensions in the first section header. Don't
24438 bomb if we can't read it. */
24439 get_section_headers (filedata
, true);
24441 if (! process_file_header (filedata
))
24447 /* Throw away the single section header read above, so that we
24448 re-read the entire set. */
24449 free (filedata
->section_headers
);
24450 filedata
->section_headers
= NULL
;
24452 if (! process_section_headers (filedata
))
24454 /* Without loaded section headers we cannot process lots of things. */
24455 do_unwind
= do_version
= do_dump
= do_arch
= false;
24457 if (! do_using_dynamic
)
24458 do_syms
= do_dyn_syms
= do_reloc
= false;
24461 if (! process_section_groups (filedata
))
24462 /* Without loaded section groups we cannot process unwind. */
24465 process_program_headers (filedata
);
24467 res
= process_dynamic_section (filedata
);
24469 if (! process_relocs (filedata
))
24472 if (! process_unwind (filedata
))
24475 if (! process_symbol_table (filedata
))
24478 if (! process_lto_symbol_tables (filedata
))
24481 if (! process_syminfo (filedata
))
24484 if (! process_version_sections (filedata
))
24487 if (might_need_separate_debug_info (filedata
))
24488 have_separate_files
= load_separate_debug_files (filedata
, filedata
->file_name
);
24490 have_separate_files
= false;
24492 if (! process_section_contents (filedata
))
24495 if (! process_got_section_contents (filedata
))
24498 if (have_separate_files
)
24502 for (d
= first_separate_info
; d
!= NULL
; d
= d
->next
)
24504 initialise_dump_sects (d
->handle
);
24506 if (process_links
&& ! process_file_header (d
->handle
))
24508 else if (! process_section_headers (d
->handle
))
24510 else if (! process_section_contents (d
->handle
))
24512 else if (process_links
)
24514 if (! process_section_groups (d
->handle
))
24516 process_program_headers (d
->handle
);
24517 if (! process_dynamic_section (d
->handle
))
24519 if (! process_relocs (d
->handle
))
24521 if (! process_unwind (d
->handle
))
24523 if (! process_symbol_table (d
->handle
))
24525 if (! process_lto_symbol_tables (d
->handle
))
24527 if (! process_syminfo (d
->handle
))
24529 if (! process_version_sections (d
->handle
))
24531 if (! process_notes (d
->handle
))
24536 /* The file handles are closed by the call to free_debug_memory() below. */
24539 if (! process_notes (filedata
))
24542 if (! process_gnu_liblist (filedata
))
24545 if (! process_arch_specific (filedata
))
24549 free_filedata (filedata
);
24551 free_debug_memory ();
24556 /* Process an ELF archive.
24557 On entry the file is positioned just after the ARMAG string.
24558 Returns TRUE upon success, FALSE otherwise. */
24561 process_archive (Filedata
* filedata
, bool is_thin_archive
)
24563 struct archive_info arch
;
24564 struct archive_info nested_arch
;
24570 /* The ARCH structure is used to hold information about this archive. */
24571 arch
.file_name
= NULL
;
24573 arch
.index_array
= NULL
;
24574 arch
.sym_table
= NULL
;
24575 arch
.longnames
= NULL
;
24577 /* The NESTED_ARCH structure is used as a single-item cache of information
24578 about a nested archive (when members of a thin archive reside within
24579 another regular archive file). */
24580 nested_arch
.file_name
= NULL
;
24581 nested_arch
.file
= NULL
;
24582 nested_arch
.index_array
= NULL
;
24583 nested_arch
.sym_table
= NULL
;
24584 nested_arch
.longnames
= NULL
;
24586 if (setup_archive (&arch
, filedata
->file_name
, filedata
->handle
,
24587 filedata
->file_size
, is_thin_archive
,
24588 do_archive_index
) != 0)
24594 if (do_archive_index
)
24596 if (arch
.sym_table
== NULL
)
24597 error (_("%s: unable to dump the index as none was found\n"),
24598 filedata
->file_name
);
24602 uint64_t current_pos
;
24604 printf (_("Index of archive %s: (%" PRIu64
" entries,"
24605 " %#" PRIx64
" bytes in the symbol table)\n"),
24606 filedata
->file_name
, arch
.index_num
,
24609 current_pos
= ftell (filedata
->handle
);
24611 for (i
= l
= 0; i
< arch
.index_num
; i
++)
24614 || (i
> 0 && arch
.index_array
[i
] != arch
.index_array
[i
- 1]))
24617 = get_archive_member_name_at (&arch
, arch
.index_array
[i
],
24620 if (member_name
!= NULL
)
24622 char * qualified_name
24623 = make_qualified_name (&arch
, &nested_arch
,
24626 if (qualified_name
!= NULL
)
24628 printf (_("Contents of binary %s at offset "),
24630 (void) print_vma (arch
.index_array
[i
], PREFIX_HEX
);
24632 free (qualified_name
);
24634 free (member_name
);
24638 if (l
>= arch
.sym_size
)
24640 error (_("%s: end of the symbol table reached "
24641 "before the end of the index\n"),
24642 filedata
->file_name
);
24646 /* PR 17531: file: 0b6630b2. */
24647 printf ("\t%.*s\n",
24648 (int) (arch
.sym_size
- l
), arch
.sym_table
+ l
);
24649 l
+= strnlen (arch
.sym_table
+ l
, arch
.sym_size
- l
) + 1;
24652 if (arch
.uses_64bit_indices
)
24657 if (l
< arch
.sym_size
)
24659 error (ngettext ("%s: %" PRId64
" byte remains in the symbol table, "
24660 "but without corresponding entries in "
24661 "the index table\n",
24662 "%s: %" PRId64
" bytes remain in the symbol table, "
24663 "but without corresponding entries in "
24664 "the index table\n",
24665 arch
.sym_size
- l
),
24666 filedata
->file_name
, arch
.sym_size
- l
);
24670 if (fseek64 (filedata
->handle
, current_pos
, SEEK_SET
) != 0)
24672 error (_("%s: failed to seek back to start of object files "
24673 "in the archive\n"),
24674 filedata
->file_name
);
24680 if (!do_dynamic
&& !do_syms
&& !do_reloc
&& !do_unwind
&& !do_sections
24681 && !do_segments
&& !do_header
&& !do_dump
&& !do_version
24682 && !do_histogram
&& !do_debugging
&& !do_arch
&& !do_notes
24683 && !do_section_groups
&& !do_dyn_syms
)
24685 ret
= true; /* Archive index only. */
24694 char * qualified_name
;
24696 /* Read the next archive header. */
24697 if (fseek64 (filedata
->handle
, arch
.next_arhdr_offset
, SEEK_SET
) != 0)
24699 error (_("%s: failed to seek to next archive header\n"),
24704 got
= fread (&arch
.arhdr
, 1, sizeof arch
.arhdr
, filedata
->handle
);
24705 if (got
!= sizeof arch
.arhdr
)
24709 /* PR 24049 - we cannot use filedata->file_name as this will
24710 have already been freed. */
24711 error (_("%s: failed to read archive header\n"), arch
.file_name
);
24716 if (memcmp (arch
.arhdr
.ar_fmag
, ARFMAG
, 2) != 0)
24718 error (_("%s: did not find a valid archive header\n"),
24724 arch
.next_arhdr_offset
+= sizeof arch
.arhdr
;
24726 filedata
->archive_file_size
= strtoul (arch
.arhdr
.ar_size
, NULL
, 10);
24728 name
= get_archive_member_name (&arch
, &nested_arch
);
24731 error (_("%s: bad archive file name\n"), arch
.file_name
);
24735 namelen
= strlen (name
);
24737 qualified_name
= make_qualified_name (&arch
, &nested_arch
, name
);
24738 if (qualified_name
== NULL
)
24740 error (_("%s: bad archive file name\n"), arch
.file_name
);
24746 if (is_thin_archive
&& arch
.nested_member_origin
== 0)
24748 /* This is a proxy for an external member of a thin archive. */
24749 Filedata
* member_filedata
;
24750 char * member_file_name
= adjust_relative_path
24751 (filedata
->file_name
, name
, namelen
);
24754 if (member_file_name
== NULL
)
24756 free (qualified_name
);
24761 member_filedata
= open_file (member_file_name
, false);
24762 if (member_filedata
== NULL
)
24764 error (_("Input file '%s' is not readable.\n"), member_file_name
);
24765 free (member_file_name
);
24766 free (qualified_name
);
24771 filedata
->archive_file_offset
= arch
.nested_member_origin
;
24772 member_filedata
->file_name
= qualified_name
;
24774 /* The call to process_object() expects the file to be at the beginning. */
24775 rewind (member_filedata
->handle
);
24777 if (! process_object (member_filedata
))
24780 close_file (member_filedata
);
24781 free (member_file_name
);
24783 else if (is_thin_archive
)
24785 Filedata thin_filedata
;
24787 memset (&thin_filedata
, 0, sizeof (thin_filedata
));
24789 /* PR 15140: Allow for corrupt thin archives. */
24790 if (nested_arch
.file
== NULL
)
24792 error (_("%s: contains corrupt thin archive: %s\n"),
24793 qualified_name
, name
);
24794 free (qualified_name
);
24801 /* This is a proxy for a member of a nested archive. */
24802 filedata
->archive_file_offset
24803 = arch
.nested_member_origin
+ sizeof arch
.arhdr
;
24805 /* The nested archive file will have been opened and setup by
24806 get_archive_member_name. */
24807 if (fseek64 (nested_arch
.file
, filedata
->archive_file_offset
,
24810 error (_("%s: failed to seek to archive member.\n"),
24811 nested_arch
.file_name
);
24812 free (qualified_name
);
24817 thin_filedata
.handle
= nested_arch
.file
;
24818 thin_filedata
.file_name
= qualified_name
;
24820 if (! process_object (& thin_filedata
))
24826 filedata
->archive_file_offset
= arch
.next_arhdr_offset
;
24827 filedata
->file_name
= qualified_name
;
24828 if (! process_object (filedata
))
24830 arch
.next_arhdr_offset
+= (filedata
->archive_file_size
+ 1) & -2;
24831 /* Stop looping with "negative" archive_file_size. */
24832 if (arch
.next_arhdr_offset
< filedata
->archive_file_size
)
24833 arch
.next_arhdr_offset
= -1ul;
24836 free (qualified_name
);
24840 if (nested_arch
.file
!= NULL
)
24841 fclose (nested_arch
.file
);
24842 release_archive (&nested_arch
);
24843 release_archive (&arch
);
24849 process_file (char * file_name
)
24851 Filedata
* filedata
= NULL
;
24852 struct stat statbuf
;
24853 char armag
[SARMAG
];
24856 if (stat (file_name
, &statbuf
) < 0)
24858 if (errno
== ENOENT
)
24859 error (_("'%s': No such file\n"), file_name
);
24861 error (_("Could not locate '%s'. System error message: %s\n"),
24862 file_name
, strerror (errno
));
24866 if (! S_ISREG (statbuf
.st_mode
))
24868 error (_("'%s' is not an ordinary file\n"), file_name
);
24872 filedata
= calloc (1, sizeof * filedata
);
24873 if (filedata
== NULL
)
24875 error (_("Out of memory allocating file data structure\n"));
24879 filedata
->file_name
= file_name
;
24880 filedata
->handle
= fopen (file_name
, "rb");
24881 if (filedata
->handle
== NULL
)
24883 error (_("Input file '%s' is not readable.\n"), file_name
);
24888 if (fread (armag
, SARMAG
, 1, filedata
->handle
) != 1)
24890 error (_("%s: Failed to read file's magic number\n"), file_name
);
24891 fclose (filedata
->handle
);
24896 filedata
->file_size
= statbuf
.st_size
;
24897 filedata
->is_separate
= false;
24899 if (memcmp (armag
, ARMAG
, SARMAG
) == 0)
24901 if (! process_archive (filedata
, false))
24904 else if (memcmp (armag
, ARMAGT
, SARMAG
) == 0)
24906 if ( ! process_archive (filedata
, true))
24911 if (do_archive_index
&& !check_all
)
24912 error (_("File %s is not an archive so its index cannot be displayed.\n"),
24915 rewind (filedata
->handle
);
24916 filedata
->archive_file_size
= filedata
->archive_file_offset
= 0;
24918 if (! process_object (filedata
))
24922 close_debug_file (filedata
);
24924 free (ba_cache
.strtab
);
24925 ba_cache
.strtab
= NULL
;
24926 free (ba_cache
.symtab
);
24927 ba_cache
.symtab
= NULL
;
24928 ba_cache
.filedata
= NULL
;
24933 #ifdef SUPPORT_DISASSEMBLY
24934 /* Needed by the i386 disassembler. For extra credit, someone could
24935 fix this so that we insert symbolic addresses here, esp for GOT/PLT
24939 print_address (unsigned int addr
, FILE * outfile
)
24941 fprintf (outfile
,"0x%8.8x", addr
);
24944 /* Needed by the i386 disassembler. */
24947 db_task_printsym (unsigned int addr
)
24949 print_address (addr
, stderr
);
24954 main (int argc
, char ** argv
)
24958 #ifdef HAVE_LC_MESSAGES
24959 setlocale (LC_MESSAGES
, "");
24961 setlocale (LC_CTYPE
, "");
24962 bindtextdomain (PACKAGE
, LOCALEDIR
);
24963 textdomain (PACKAGE
);
24965 expandargv (&argc
, &argv
);
24967 parse_args (& cmdline
, argc
, argv
);
24969 if (optind
< (argc
- 1))
24970 /* When displaying information for more than one file,
24971 prefix the information with the file name. */
24973 else if (optind
>= argc
)
24975 /* Ensure that the warning is always displayed. */
24978 warn (_("Nothing to do.\n"));
24983 while (optind
< argc
)
24984 if (! process_file (argv
[optind
++]))
24987 free (cmdline
.dump_sects
);
24989 free (dump_ctf_symtab_name
);
24990 free (dump_ctf_strtab_name
);
24991 free (dump_ctf_parent_name
);
24993 return err
? EXIT_FAILURE
: EXIT_SUCCESS
;