1 /* readelf.c -- display contents of an ELF format file
2 Copyright (C) 1998-2022 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. */
50 /* Define BFD64 here, even if our default architecture is 32 bit ELF
51 as this will allow us to read in and parse 64bit and 32bit ELF files.
52 Only do this if we believe that the compiler can support a 64 bit
53 data type. For now we only rely on GCC being able to do this. */
60 #include "demanguse.h"
65 #include "elf/common.h"
66 #include "elf/external.h"
67 #include "elf/internal.h"
70 /* Included here, before RELOC_MACROS_GEN_FUNC is defined, so that
71 we can obtain the H8 reloc numbers. We need these for the
72 get_reloc_size() function. We include h8.h again after defining
73 RELOC_MACROS_GEN_FUNC so that we get the naming function as well. */
78 /* Undo the effects of #including reloc-macros.h. */
80 #undef START_RELOC_NUMBERS
84 #undef END_RELOC_NUMBERS
85 #undef _RELOC_MACROS_H
87 /* The following headers use the elf/reloc-macros.h file to
88 automatically generate relocation recognition functions
89 such as elf_mips_reloc_type() */
91 #define RELOC_MACROS_GEN_FUNC
93 #include "elf/aarch64.h"
94 #include "elf/alpha.h"
95 #include "elf/amdgpu.h"
100 #include "elf/cr16.h"
101 #include "elf/cris.h"
103 #include "elf/csky.h"
104 #include "elf/d10v.h"
105 #include "elf/d30v.h"
108 #include "elf/epiphany.h"
109 #include "elf/fr30.h"
111 #include "elf/ft32.h"
113 #include "elf/hppa.h"
114 #include "elf/i386.h"
115 #include "elf/i370.h"
116 #include "elf/i860.h"
117 #include "elf/i960.h"
118 #include "elf/ia64.h"
119 #include "elf/ip2k.h"
120 #include "elf/lm32.h"
121 #include "elf/iq2000.h"
122 #include "elf/m32c.h"
123 #include "elf/m32r.h"
124 #include "elf/m68k.h"
125 #include "elf/m68hc11.h"
126 #include "elf/s12z.h"
127 #include "elf/mcore.h"
129 #include "elf/metag.h"
130 #include "elf/microblaze.h"
131 #include "elf/mips.h"
132 #include "elf/mmix.h"
133 #include "elf/mn10200.h"
134 #include "elf/mn10300.h"
135 #include "elf/moxie.h"
137 #include "elf/msp430.h"
138 #include "elf/nds32.h"
140 #include "elf/nios2.h"
141 #include "elf/or1k.h"
144 #include "elf/ppc64.h"
146 #include "elf/riscv.h"
147 #include "elf/rl78.h"
149 #include "elf/s390.h"
150 #include "elf/score.h"
152 #include "elf/sparc.h"
154 #include "elf/tic6x.h"
155 #include "elf/tilegx.h"
156 #include "elf/tilepro.h"
157 #include "elf/v850.h"
159 #include "elf/visium.h"
160 #include "elf/wasm32.h"
161 #include "elf/x86-64.h"
162 #include "elf/xc16x.h"
163 #include "elf/xgate.h"
164 #include "elf/xstormy16.h"
165 #include "elf/xtensa.h"
167 #include "elf/loongarch.h"
170 #include "libiberty.h"
171 #include "safe-ctype.h"
172 #include "filenames.h"
175 #define offsetof(TYPE, MEMBER) ((size_t) &(((TYPE *) 0)->MEMBER))
178 typedef struct elf_section_list
180 Elf_Internal_Shdr
* hdr
;
181 struct elf_section_list
* next
;
184 /* Flag bits indicating particular types of dump. */
185 #define HEX_DUMP (1 << 0) /* The -x command line switch. */
186 #define DISASS_DUMP (1 << 1) /* The -i command line switch. */
187 #define DEBUG_DUMP (1 << 2) /* The -w command line switch. */
188 #define STRING_DUMP (1 << 3) /* The -p command line switch. */
189 #define RELOC_DUMP (1 << 4) /* The -R command line switch. */
190 #define CTF_DUMP (1 << 5) /* The --ctf command line switch. */
192 typedef unsigned char dump_type
;
194 /* A linked list of the section names for which dumps were requested. */
195 struct dump_list_entry
199 struct dump_list_entry
* next
;
202 /* A dynamic array of flags indicating for which sections a dump
203 has been requested via command line switches. */
206 dump_type
* dump_sects
;
207 unsigned int num_dump_sects
;
210 static struct dump_data cmdline
;
212 static struct dump_list_entry
* dump_sects_byname
;
214 char * program_name
= "readelf";
216 static bool show_name
= false;
217 static bool do_dynamic
= false;
218 static bool do_syms
= false;
219 static bool do_dyn_syms
= false;
220 static bool do_lto_syms
= false;
221 static bool do_reloc
= false;
222 static bool do_sections
= false;
223 static bool do_section_groups
= false;
224 static bool do_section_details
= false;
225 static bool do_segments
= false;
226 static bool do_unwind
= false;
227 static bool do_using_dynamic
= false;
228 static bool do_header
= false;
229 static bool do_dump
= false;
230 static bool do_version
= false;
231 static bool do_histogram
= false;
232 static bool do_debugging
= false;
233 static bool do_ctf
= false;
234 static bool do_arch
= false;
235 static bool do_notes
= false;
236 static bool do_archive_index
= false;
237 static bool check_all
= false;
238 static bool is_32bit_elf
= false;
239 static bool decompress_dumps
= false;
240 static bool do_not_show_symbol_truncation
= false;
241 static bool do_demangle
= false; /* Pretty print C++ symbol names. */
242 static bool process_links
= false;
243 static bool dump_any_debugging
= false;
244 static int demangle_flags
= DMGL_ANSI
| DMGL_PARAMS
;
245 static int sym_base
= 0;
247 static char *dump_ctf_parent_name
;
248 static char *dump_ctf_symtab_name
;
249 static char *dump_ctf_strtab_name
;
253 struct group_list
* next
;
254 unsigned int section_index
;
259 struct group_list
* root
;
260 unsigned int group_index
;
263 typedef struct filedata
265 const char * file_name
;
268 bfd_size_type file_size
;
269 Elf_Internal_Ehdr file_header
;
270 unsigned long archive_file_offset
;
271 unsigned long archive_file_size
;
272 /* Everything below this point is cleared out by free_filedata. */
273 Elf_Internal_Shdr
* section_headers
;
274 Elf_Internal_Phdr
* program_headers
;
276 unsigned long string_table_length
;
277 unsigned long dynamic_addr
;
278 bfd_size_type dynamic_size
;
280 Elf_Internal_Dyn
* dynamic_section
;
281 Elf_Internal_Shdr
* dynamic_strtab_section
;
282 char * dynamic_strings
;
283 unsigned long dynamic_strings_length
;
284 Elf_Internal_Shdr
* dynamic_symtab_section
;
285 unsigned long num_dynamic_syms
;
286 Elf_Internal_Sym
* dynamic_symbols
;
287 bfd_vma version_info
[16];
288 unsigned int dynamic_syminfo_nent
;
289 Elf_Internal_Syminfo
* dynamic_syminfo
;
290 unsigned long dynamic_syminfo_offset
;
291 bfd_size_type nbuckets
;
292 bfd_size_type nchains
;
295 bfd_size_type ngnubuckets
;
296 bfd_size_type ngnuchains
;
297 bfd_vma
* gnubuckets
;
301 char * program_interpreter
;
302 bfd_vma dynamic_info
[DT_ENCODING
];
303 bfd_vma dynamic_info_DT_GNU_HASH
;
304 bfd_vma dynamic_info_DT_MIPS_XHASH
;
305 elf_section_list
* symtab_shndx_list
;
307 struct group
* section_groups
;
308 struct group
** section_headers_groups
;
309 /* A dynamic array of flags indicating for which sections a dump of
310 some kind has been requested. It is reset on a per-object file
311 basis and then initialised from the cmdline_dump_sects array,
312 the results of interpreting the -w switch, and the
313 dump_sects_byname list. */
314 struct dump_data dump
;
317 /* How to print a vma value. */
318 typedef enum print_mode
335 typedef enum unicode_display_type
343 } unicode_display_type
;
345 static unicode_display_type unicode_display
= unicode_default
;
355 /* Versioned symbol info. */
356 enum versioned_symbol_info
363 static const char * get_symbol_version_string
364 (Filedata
*, bool, const char *, unsigned long, unsigned,
365 Elf_Internal_Sym
*, enum versioned_symbol_info
*, unsigned short *);
369 static inline const char *
370 section_name (const Filedata
*filedata
, const Elf_Internal_Shdr
*hdr
)
372 return filedata
->string_table
+ hdr
->sh_name
;
376 section_name_valid (const Filedata
*filedata
, const Elf_Internal_Shdr
*hdr
)
379 && filedata
->string_table
!= NULL
380 && hdr
->sh_name
< filedata
->string_table_length
);
383 static inline const char *
384 section_name_print (const Filedata
*filedata
, const Elf_Internal_Shdr
*hdr
)
388 if (filedata
->string_table
== NULL
)
389 return _("<no-strings>");
390 if (hdr
->sh_name
>= filedata
->string_table_length
)
391 return _("<corrupt>");
392 return section_name (filedata
, hdr
);
395 #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
398 valid_symbol_name (const char *strtab
, size_t strtab_size
, uint64_t offset
)
400 return strtab
!= NULL
&& offset
< strtab_size
;
404 valid_dynamic_name (const Filedata
*filedata
, uint64_t offset
)
406 return valid_symbol_name (filedata
->dynamic_strings
,
407 filedata
->dynamic_strings_length
, offset
);
410 /* GET_DYNAMIC_NAME asssumes that VALID_DYNAMIC_NAME has
411 already been called and verified that the string exists. */
412 static inline const char *
413 get_dynamic_name (const Filedata
*filedata
, size_t offset
)
415 return filedata
->dynamic_strings
+ offset
;
418 #define REMOVE_ARCH_BITS(ADDR) \
421 if (filedata->file_header.e_machine == EM_ARM) \
426 /* Get the correct GNU hash section name. */
427 #define GNU_HASH_SECTION_NAME(filedata) \
428 filedata->dynamic_info_DT_MIPS_XHASH ? ".MIPS.xhash" : ".gnu.hash"
430 /* Print a BFD_VMA to an internal buffer, for use in error messages.
431 BFD_FMA_FMT can't be used in translated strings. */
434 bfd_vmatoa (char *fmtch
, bfd_vma value
)
436 /* bfd_vmatoa is used more then once in a printf call for output.
437 Cycle through an array of buffers. */
438 static int buf_pos
= 0;
439 static struct bfd_vmatoa_buf
446 ret
= buf
[buf_pos
++].place
;
447 buf_pos
%= ARRAY_SIZE (buf
);
449 sprintf (fmt
, "%%%s%s", BFD_VMA_FMT
, fmtch
);
450 snprintf (ret
, sizeof (buf
[0].place
), fmt
, value
);
454 /* Retrieve NMEMB structures, each SIZE bytes long from FILEDATA starting at
455 OFFSET + the offset of the current archive member, if we are examining an
456 archive. Put the retrieved data into VAR, if it is not NULL. Otherwise
457 allocate a buffer using malloc and fill that. In either case return the
458 pointer to the start of the retrieved data or NULL if something went wrong.
459 If something does go wrong and REASON is not NULL then emit an error
460 message using REASON as part of the context. */
463 get_data (void * var
,
465 unsigned long offset
,
471 bfd_size_type amt
= size
* nmemb
;
473 if (size
== 0 || nmemb
== 0)
476 /* If the size_t type is smaller than the bfd_size_type, eg because
477 you are building a 32-bit tool on a 64-bit host, then make sure
478 that when the sizes are cast to (size_t) no information is lost. */
479 if ((size_t) size
!= size
480 || (size_t) nmemb
!= nmemb
481 || (size_t) amt
!= amt
)
484 error (_("Size truncation prevents reading %s"
485 " elements of size %s for %s\n"),
486 bfd_vmatoa ("u", nmemb
), bfd_vmatoa ("u", size
), reason
);
490 /* Check for size overflow. */
491 if (amt
/ size
!= nmemb
|| (size_t) amt
+ 1 == 0)
494 error (_("Size overflow prevents reading %s"
495 " elements of size %s for %s\n"),
496 bfd_vmatoa ("u", nmemb
), bfd_vmatoa ("u", size
), reason
);
500 /* Be kind to memory checkers (eg valgrind, address sanitizer) by not
501 attempting to allocate memory when the read is bound to fail. */
502 if (filedata
->archive_file_offset
> filedata
->file_size
503 || offset
> filedata
->file_size
- filedata
->archive_file_offset
504 || amt
> filedata
->file_size
- filedata
->archive_file_offset
- offset
)
507 error (_("Reading %s bytes extends past end of file for %s\n"),
508 bfd_vmatoa ("u", amt
), reason
);
512 if (fseek (filedata
->handle
, filedata
->archive_file_offset
+ offset
,
516 error (_("Unable to seek to 0x%lx for %s\n"),
517 filedata
->archive_file_offset
+ offset
, reason
);
524 /* + 1 so that we can '\0' terminate invalid string table sections. */
525 mvar
= malloc ((size_t) amt
+ 1);
530 error (_("Out of memory allocating %s bytes for %s\n"),
531 bfd_vmatoa ("u", amt
), reason
);
535 ((char *) mvar
)[amt
] = '\0';
538 if (fread (mvar
, (size_t) size
, (size_t) nmemb
, filedata
->handle
) != nmemb
)
541 error (_("Unable to read in %s bytes of %s\n"),
542 bfd_vmatoa ("u", amt
), reason
);
551 /* Print a VMA value in the MODE specified.
552 Returns the number of characters displayed. */
555 print_vma (bfd_vma vma
, print_mode mode
)
567 return nc
+ printf ("%8.8" BFD_VMA_FMT
"x", vma
);
574 return printf ("%5" BFD_VMA_FMT
"d", vma
);
580 return nc
+ printf ("%" BFD_VMA_FMT
"x", vma
);
586 return nc
+ printf ("%05" BFD_VMA_FMT
"x", vma
);
589 return printf ("%" BFD_VMA_FMT
"d", vma
);
592 return printf ("%" BFD_VMA_FMT
"u", vma
);
595 return printf ("%5" BFD_VMA_FMT
"u", vma
);
598 return printf ("%" BFD_VMA_FMT
"o", vma
);
601 return printf ("%5" BFD_VMA_FMT
"o", vma
);
604 /* FIXME: Report unrecognised mode ? */
610 /* Display a symbol on stdout. Handles the display of control characters and
611 multibye characters (assuming the host environment supports them).
613 Display at most abs(WIDTH) characters, truncating as necessary, unless do_wide is true.
615 If truncation will happen and do_not_show_symbol_truncation is FALSE then display
616 abs(WIDTH) - 5 characters followed by "[...]".
618 If WIDTH is negative then ensure that the output is at least (- WIDTH) characters,
619 padding as necessary.
621 Returns the number of emitted characters. */
624 print_symbol (signed int width
, const char * symbol
)
626 bool extra_padding
= false;
627 bool do_dots
= false;
628 signed int num_printed
= 0;
629 #ifdef HAVE_MBSTATE_T
632 unsigned int width_remaining
;
633 const void * alloced_symbol
= NULL
;
637 /* Keep the width positive. This helps the code below. */
639 extra_padding
= true;
645 /* Set the remaining width to a very large value.
646 This simplifies the code below. */
647 width_remaining
= INT_MAX
;
650 width_remaining
= width
;
651 if (! do_not_show_symbol_truncation
652 && (int) strlen (symbol
) > width
)
654 width_remaining
-= 5;
655 if ((int) width_remaining
< 0)
661 #ifdef HAVE_MBSTATE_T
662 /* Initialise the multibyte conversion state. */
663 memset (& state
, 0, sizeof (state
));
666 if (do_demangle
&& *symbol
)
668 const char * res
= cplus_demangle (symbol
, demangle_flags
);
671 alloced_symbol
= symbol
= res
;
674 while (width_remaining
)
677 const char c
= *symbol
++;
688 else if (ISCNTRL (c
))
690 /* Do not print control characters directly as they can affect terminal
691 settings. Such characters usually appear in the names generated
692 by the assembler for local labels. */
694 if (width_remaining
< 2)
697 printf ("^%c", c
+ 0x40);
698 width_remaining
-= 2;
703 if (width_remaining
< 5)
706 width_remaining
-= 5;
709 else if (unicode_display
!= unicode_locale
710 && unicode_display
!= unicode_default
)
712 /* Display unicode characters as something else. */
713 unsigned char bytes
[4];
726 bytes
[1] = *symbol
++;
728 if ((bytes
[1] & 0xc0) != 0x80)
731 /* Do not consume this character. It may only
732 be the first byte in the sequence that was
737 else if ((bytes
[0] & 0x20) == 0)
744 bytes
[2] = *symbol
++;
746 if ((bytes
[2] & 0xc0) != 0x80)
752 else if ((bytes
[0] & 0x10) == 0)
759 bytes
[3] = *symbol
++;
763 if ((bytes
[3] & 0xc0) != 0x80)
775 if (unicode_display
== unicode_invalid
)
778 if (unicode_display
== unicode_hex
|| ! is_utf8
)
782 if (width_remaining
< (nbytes
* 2) + 2)
785 putchar (is_utf8
? '<' : '{');
787 for (i
= 0; i
< nbytes
; i
++)
788 printf ("%02x", bytes
[i
]);
789 putchar (is_utf8
? '>' : '}');
793 if (unicode_display
== unicode_highlight
&& isatty (1))
794 printf ("\x1B[31;47m"); /* Red. */
799 if (width_remaining
< 6)
801 printf ("\\u%02x%02x",
802 (bytes
[0] & 0x1c) >> 2,
803 ((bytes
[0] & 0x03) << 6) | (bytes
[1] & 0x3f));
806 if (width_remaining
< 6)
808 printf ("\\u%02x%02x",
809 ((bytes
[0] & 0x0f) << 4) | ((bytes
[1] & 0x3c) >> 2),
810 ((bytes
[1] & 0x03) << 6) | (bytes
[2] & 0x3f));
813 if (width_remaining
< 8)
815 printf ("\\u%02x%02x%02x",
816 ((bytes
[0] & 0x07) << 6) | ((bytes
[1] & 0x3c) >> 2),
817 ((bytes
[1] & 0x03) << 6) | ((bytes
[2] & 0x3c) >> 2),
818 ((bytes
[2] & 0x03) << 6) | (bytes
[3] & 0x3f));
826 if (unicode_display
== unicode_highlight
&& isatty (1))
827 printf ("\033[0m"); /* Default colour. */
830 if (bytes
[nbytes
- 1] == 0)
835 #ifdef HAVE_MBSTATE_T
838 /* Let printf do the hard work of displaying multibyte characters. */
839 printf ("%.1s", symbol
- 1);
843 #ifdef HAVE_MBSTATE_T
844 /* Try to find out how many bytes made up the character that was
845 just printed. Advance the symbol pointer past the bytes that
847 n
= mbrtowc (& w
, symbol
- 1, MB_CUR_MAX
, & state
);
851 if (n
!= (size_t) -1 && n
!= (size_t) -2 && n
> 0)
857 num_printed
+= printf ("[...]");
859 if (extra_padding
&& num_printed
< width
)
861 /* Fill in the remaining spaces. */
862 printf ("%-*s", width
- num_printed
, " ");
866 free ((void *) alloced_symbol
);
870 /* Returns a pointer to a static buffer containing a printable version of
871 the given section's name. Like print_symbol, except that it does not try
872 to print multibyte characters, it just interprets them as hex values. */
875 printable_section_name (Filedata
* filedata
, const Elf_Internal_Shdr
* sec
)
877 #define MAX_PRINT_SEC_NAME_LEN 256
878 static char sec_name_buf
[MAX_PRINT_SEC_NAME_LEN
+ 1];
879 const char * name
= section_name_print (filedata
, sec
);
880 char * buf
= sec_name_buf
;
882 unsigned int remaining
= MAX_PRINT_SEC_NAME_LEN
;
884 while ((c
= * name
++) != 0)
895 else if (ISPRINT (c
))
902 static char hex
[17] = "0123456789ABCDEF";
907 * buf
++ = hex
[(c
& 0xf0) >> 4];
908 * buf
++ = hex
[c
& 0x0f];
922 printable_section_name_from_index (Filedata
* filedata
, unsigned long ndx
)
924 if (ndx
>= filedata
->file_header
.e_shnum
)
925 return _("<corrupt>");
927 return printable_section_name (filedata
, filedata
->section_headers
+ ndx
);
930 /* Return a pointer to section NAME, or NULL if no such section exists. */
932 static Elf_Internal_Shdr
*
933 find_section (Filedata
* filedata
, const char * name
)
937 if (filedata
->section_headers
== NULL
)
940 for (i
= 0; i
< filedata
->file_header
.e_shnum
; i
++)
941 if (section_name_valid (filedata
, filedata
->section_headers
+ i
)
942 && streq (section_name (filedata
, filedata
->section_headers
+ i
),
944 return filedata
->section_headers
+ i
;
949 /* Return a pointer to a section containing ADDR, or NULL if no such
952 static Elf_Internal_Shdr
*
953 find_section_by_address (Filedata
* filedata
, bfd_vma addr
)
957 if (filedata
->section_headers
== NULL
)
960 for (i
= 0; i
< filedata
->file_header
.e_shnum
; i
++)
962 Elf_Internal_Shdr
*sec
= filedata
->section_headers
+ i
;
964 if (addr
>= sec
->sh_addr
&& addr
< sec
->sh_addr
+ sec
->sh_size
)
971 static Elf_Internal_Shdr
*
972 find_section_by_type (Filedata
* filedata
, unsigned int type
)
976 if (filedata
->section_headers
== NULL
)
979 for (i
= 0; i
< filedata
->file_header
.e_shnum
; i
++)
981 Elf_Internal_Shdr
*sec
= filedata
->section_headers
+ i
;
983 if (sec
->sh_type
== type
)
990 /* Return a pointer to section NAME, or NULL if no such section exists,
991 restricted to the list of sections given in SET. */
993 static Elf_Internal_Shdr
*
994 find_section_in_set (Filedata
* filedata
, const char * name
, unsigned int * set
)
998 if (filedata
->section_headers
== NULL
)
1003 while ((i
= *set
++) > 0)
1005 /* See PR 21156 for a reproducer. */
1006 if (i
>= filedata
->file_header
.e_shnum
)
1007 continue; /* FIXME: Should we issue an error message ? */
1009 if (section_name_valid (filedata
, filedata
->section_headers
+ i
)
1010 && streq (section_name (filedata
, filedata
->section_headers
+ i
),
1012 return filedata
->section_headers
+ i
;
1016 return find_section (filedata
, name
);
1019 /* Return TRUE if the current file is for IA-64 machine and OpenVMS ABI.
1020 This OS has so many departures from the ELF standard that we test it at
1024 is_ia64_vms (Filedata
* filedata
)
1026 return filedata
->file_header
.e_machine
== EM_IA_64
1027 && filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_OPENVMS
;
1030 /* Guess the relocation size commonly used by the specific machines. */
1033 guess_is_rela (unsigned int e_machine
)
1037 /* Targets that use REL relocations. */
1043 case EM_CYGNUS_D10V
:
1046 case EM_MIPS_RS3_LE
:
1047 case EM_CYGNUS_M32R
:
1054 /* Targets that use RELA relocations. */
1058 case EM_ADAPTEVA_EPIPHANY
:
1060 case EM_ALTERA_NIOS2
:
1062 case EM_ARC_COMPACT
:
1063 case EM_ARC_COMPACT2
:
1072 case EM_CYGNUS_D30V
:
1075 case EM_CYGNUS_FR30
:
1084 case EM_LATTICEMICO32
:
1093 case EM_CYGNUS_MN10200
:
1095 case EM_CYGNUS_MN10300
:
1113 case EM_SPARC32PLUS
:
1121 case EM_CYGNUS_V850
:
1131 case EM_MICROBLAZE_OLD
:
1132 case EM_WEBASSEMBLY
:
1153 warn (_("Don't know about relocations on this machine architecture\n"));
1158 /* Load RELA type relocations from FILEDATA at REL_OFFSET extending for REL_SIZE bytes.
1159 Returns TRUE upon success, FALSE otherwise. If successful then a
1160 pointer to a malloc'ed buffer containing the relocs is placed in *RELASP,
1161 and the number of relocs loaded is placed in *NRELASP. It is the caller's
1162 responsibility to free the allocated buffer. */
1165 slurp_rela_relocs (Filedata
* filedata
,
1166 unsigned long rel_offset
,
1167 unsigned long rel_size
,
1168 Elf_Internal_Rela
** relasp
,
1169 unsigned long * nrelasp
)
1171 Elf_Internal_Rela
* relas
;
1177 Elf32_External_Rela
* erelas
;
1179 erelas
= (Elf32_External_Rela
*) get_data (NULL
, filedata
, rel_offset
, 1,
1180 rel_size
, _("32-bit relocation data"));
1184 nrelas
= rel_size
/ sizeof (Elf32_External_Rela
);
1186 relas
= (Elf_Internal_Rela
*) cmalloc (nrelas
,
1187 sizeof (Elf_Internal_Rela
));
1192 error (_("out of memory parsing relocs\n"));
1196 for (i
= 0; i
< nrelas
; i
++)
1198 relas
[i
].r_offset
= BYTE_GET (erelas
[i
].r_offset
);
1199 relas
[i
].r_info
= BYTE_GET (erelas
[i
].r_info
);
1200 relas
[i
].r_addend
= BYTE_GET_SIGNED (erelas
[i
].r_addend
);
1207 Elf64_External_Rela
* erelas
;
1209 erelas
= (Elf64_External_Rela
*) get_data (NULL
, filedata
, rel_offset
, 1,
1210 rel_size
, _("64-bit relocation data"));
1214 nrelas
= rel_size
/ sizeof (Elf64_External_Rela
);
1216 relas
= (Elf_Internal_Rela
*) cmalloc (nrelas
,
1217 sizeof (Elf_Internal_Rela
));
1222 error (_("out of memory parsing relocs\n"));
1226 for (i
= 0; i
< nrelas
; i
++)
1228 relas
[i
].r_offset
= BYTE_GET (erelas
[i
].r_offset
);
1229 relas
[i
].r_info
= BYTE_GET (erelas
[i
].r_info
);
1230 relas
[i
].r_addend
= BYTE_GET_SIGNED (erelas
[i
].r_addend
);
1232 /* The #ifdef BFD64 below is to prevent a compile time
1233 warning. We know that if we do not have a 64 bit data
1234 type that we will never execute this code anyway. */
1236 if (filedata
->file_header
.e_machine
== EM_MIPS
1237 && filedata
->file_header
.e_ident
[EI_DATA
] != ELFDATA2MSB
)
1239 /* In little-endian objects, r_info isn't really a
1240 64-bit little-endian value: it has a 32-bit
1241 little-endian symbol index followed by four
1242 individual byte fields. Reorder INFO
1244 bfd_vma inf
= relas
[i
].r_info
;
1245 inf
= (((inf
& 0xffffffff) << 32)
1246 | ((inf
>> 56) & 0xff)
1247 | ((inf
>> 40) & 0xff00)
1248 | ((inf
>> 24) & 0xff0000)
1249 | ((inf
>> 8) & 0xff000000));
1250 relas
[i
].r_info
= inf
;
1263 /* Load REL type relocations from FILEDATA at REL_OFFSET extending for REL_SIZE bytes.
1264 Returns TRUE upon success, FALSE otherwise. If successful then a
1265 pointer to a malloc'ed buffer containing the relocs is placed in *RELSP,
1266 and the number of relocs loaded is placed in *NRELSP. It is the caller's
1267 responsibility to free the allocated buffer. */
1270 slurp_rel_relocs (Filedata
* filedata
,
1271 unsigned long rel_offset
,
1272 unsigned long rel_size
,
1273 Elf_Internal_Rela
** relsp
,
1274 unsigned long * nrelsp
)
1276 Elf_Internal_Rela
* rels
;
1282 Elf32_External_Rel
* erels
;
1284 erels
= (Elf32_External_Rel
*) get_data (NULL
, filedata
, rel_offset
, 1,
1285 rel_size
, _("32-bit relocation data"));
1289 nrels
= rel_size
/ sizeof (Elf32_External_Rel
);
1291 rels
= (Elf_Internal_Rela
*) cmalloc (nrels
, sizeof (Elf_Internal_Rela
));
1296 error (_("out of memory parsing relocs\n"));
1300 for (i
= 0; i
< nrels
; i
++)
1302 rels
[i
].r_offset
= BYTE_GET (erels
[i
].r_offset
);
1303 rels
[i
].r_info
= BYTE_GET (erels
[i
].r_info
);
1304 rels
[i
].r_addend
= 0;
1311 Elf64_External_Rel
* erels
;
1313 erels
= (Elf64_External_Rel
*) get_data (NULL
, filedata
, rel_offset
, 1,
1314 rel_size
, _("64-bit relocation data"));
1318 nrels
= rel_size
/ sizeof (Elf64_External_Rel
);
1320 rels
= (Elf_Internal_Rela
*) cmalloc (nrels
, sizeof (Elf_Internal_Rela
));
1325 error (_("out of memory parsing relocs\n"));
1329 for (i
= 0; i
< nrels
; i
++)
1331 rels
[i
].r_offset
= BYTE_GET (erels
[i
].r_offset
);
1332 rels
[i
].r_info
= BYTE_GET (erels
[i
].r_info
);
1333 rels
[i
].r_addend
= 0;
1335 /* The #ifdef BFD64 below is to prevent a compile time
1336 warning. We know that if we do not have a 64 bit data
1337 type that we will never execute this code anyway. */
1339 if (filedata
->file_header
.e_machine
== EM_MIPS
1340 && filedata
->file_header
.e_ident
[EI_DATA
] != ELFDATA2MSB
)
1342 /* In little-endian objects, r_info isn't really a
1343 64-bit little-endian value: it has a 32-bit
1344 little-endian symbol index followed by four
1345 individual byte fields. Reorder INFO
1347 bfd_vma inf
= rels
[i
].r_info
;
1348 inf
= (((inf
& 0xffffffff) << 32)
1349 | ((inf
>> 56) & 0xff)
1350 | ((inf
>> 40) & 0xff00)
1351 | ((inf
>> 24) & 0xff0000)
1352 | ((inf
>> 8) & 0xff000000));
1353 rels
[i
].r_info
= inf
;
1367 slurp_relr_relocs (Filedata
* filedata
,
1368 unsigned long relr_offset
,
1369 unsigned long relr_size
,
1371 unsigned long * nrelrsp
)
1374 size_t size
= 0, nentries
, i
;
1375 bfd_vma base
= 0, addr
, entry
;
1377 relrs
= get_data (NULL
, filedata
, relr_offset
, 1, relr_size
,
1378 _("RELR relocation data"));
1383 nentries
= relr_size
/ sizeof (Elf32_External_Relr
);
1385 nentries
= relr_size
/ sizeof (Elf64_External_Relr
);
1386 for (i
= 0; i
< nentries
; i
++)
1389 entry
= BYTE_GET (((Elf32_External_Relr
*)relrs
)[i
].r_data
);
1391 entry
= BYTE_GET (((Elf64_External_Relr
*)relrs
)[i
].r_data
);
1392 if ((entry
& 1) == 0)
1395 while ((entry
>>= 1) != 0)
1396 if ((entry
& 1) == 1)
1400 *relrsp
= (bfd_vma
*) xmalloc (size
* sizeof (bfd_vma
));
1401 if (*relrsp
== NULL
)
1404 error (_("out of memory parsing relocs\n"));
1409 for (i
= 0; i
< nentries
; i
++)
1411 const bfd_vma entry_bytes
= is_32bit_elf
? 4 : 8;
1414 entry
= BYTE_GET (((Elf32_External_Relr
*)relrs
)[i
].r_data
);
1416 entry
= BYTE_GET (((Elf64_External_Relr
*)relrs
)[i
].r_data
);
1417 if ((entry
& 1) == 0)
1419 (*relrsp
)[size
++] = entry
;
1420 base
= entry
+ entry_bytes
;
1424 for (addr
= base
; (entry
>>= 1) != 0; addr
+= entry_bytes
)
1425 if ((entry
& 1) != 0)
1426 (*relrsp
)[size
++] = addr
;
1427 base
+= entry_bytes
* (entry_bytes
* CHAR_BIT
- 1);
1436 /* Returns the reloc type extracted from the reloc info field. */
1439 get_reloc_type (Filedata
* filedata
, bfd_vma reloc_info
)
1442 return ELF32_R_TYPE (reloc_info
);
1444 switch (filedata
->file_header
.e_machine
)
1447 /* Note: We assume that reloc_info has already been adjusted for us. */
1448 return ELF64_MIPS_R_TYPE (reloc_info
);
1451 return ELF64_R_TYPE_ID (reloc_info
);
1454 return ELF64_R_TYPE (reloc_info
);
1458 /* Return the symbol index extracted from the reloc info field. */
1461 get_reloc_symindex (bfd_vma reloc_info
)
1463 return is_32bit_elf
? ELF32_R_SYM (reloc_info
) : ELF64_R_SYM (reloc_info
);
1467 uses_msp430x_relocs (Filedata
* filedata
)
1470 filedata
->file_header
.e_machine
== EM_MSP430
/* Paranoia. */
1471 /* GCC uses osabi == ELFOSBI_STANDALONE. */
1472 && (((filedata
->file_header
.e_flags
& EF_MSP430_MACH
) == E_MSP430_MACH_MSP430X
)
1473 /* TI compiler uses ELFOSABI_NONE. */
1474 || (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_NONE
));
1477 /* Display the contents of the relocation data found at the specified
1481 dump_relocations (Filedata
* filedata
,
1482 unsigned long rel_offset
,
1483 unsigned long rel_size
,
1484 Elf_Internal_Sym
* symtab
,
1485 unsigned long nsyms
,
1487 unsigned long strtablen
,
1488 relocation_type rel_type
,
1492 Elf_Internal_Rela
* rels
;
1495 if (rel_type
== reltype_unknown
)
1496 rel_type
= guess_is_rela (filedata
->file_header
.e_machine
) ? reltype_rela
: reltype_rel
;
1498 if (rel_type
== reltype_rela
)
1500 if (!slurp_rela_relocs (filedata
, rel_offset
, rel_size
, &rels
, &rel_size
))
1503 else if (rel_type
== reltype_rel
)
1505 if (!slurp_rel_relocs (filedata
, rel_offset
, rel_size
, &rels
, &rel_size
))
1508 else if (rel_type
== reltype_relr
)
1512 = is_32bit_elf
? "%08" BFD_VMA_FMT
"x\n" : "%016" BFD_VMA_FMT
"x\n";
1514 if (!slurp_relr_relocs (filedata
, rel_offset
, rel_size
, &relrs
,
1518 printf (ngettext (" %lu offset\n", " %lu offsets\n", rel_size
), rel_size
);
1519 for (i
= 0; i
< rel_size
; i
++)
1520 printf (format
, relrs
[i
]);
1527 if (rel_type
== reltype_rela
)
1530 printf (_(" Offset Info Type Sym. Value Symbol's Name + Addend\n"));
1532 printf (_(" Offset Info Type Sym.Value Sym. Name + Addend\n"));
1537 printf (_(" Offset Info Type Sym. Value Symbol's Name\n"));
1539 printf (_(" Offset Info Type Sym.Value Sym. Name\n"));
1544 if (rel_type
== reltype_rela
)
1547 printf (_(" Offset Info Type Symbol's Value Symbol's Name + Addend\n"));
1549 printf (_(" Offset Info Type Sym. Value Sym. Name + Addend\n"));
1554 printf (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
1556 printf (_(" Offset Info Type Sym. Value Sym. Name\n"));
1560 for (i
= 0; i
< rel_size
; i
++)
1565 bfd_vma symtab_index
;
1568 offset
= rels
[i
].r_offset
;
1569 inf
= rels
[i
].r_info
;
1571 type
= get_reloc_type (filedata
, inf
);
1572 symtab_index
= get_reloc_symindex (inf
);
1576 printf ("%8.8lx %8.8lx ",
1577 (unsigned long) offset
& 0xffffffff,
1578 (unsigned long) inf
& 0xffffffff);
1583 ? "%16.16" BFD_VMA_FMT
"x %16.16" BFD_VMA_FMT
"x "
1584 : "%12.12" BFD_VMA_FMT
"x %12.12" BFD_VMA_FMT
"x ",
1588 switch (filedata
->file_header
.e_machine
)
1595 rtype
= elf_aarch64_reloc_type (type
);
1599 case EM_CYGNUS_M32R
:
1600 rtype
= elf_m32r_reloc_type (type
);
1605 rtype
= elf_i386_reloc_type (type
);
1610 rtype
= elf_m68hc11_reloc_type (type
);
1614 rtype
= elf_s12z_reloc_type (type
);
1618 rtype
= elf_m68k_reloc_type (type
);
1622 rtype
= elf_i960_reloc_type (type
);
1627 rtype
= elf_avr_reloc_type (type
);
1630 case EM_OLD_SPARCV9
:
1631 case EM_SPARC32PLUS
:
1634 rtype
= elf_sparc_reloc_type (type
);
1638 rtype
= elf_spu_reloc_type (type
);
1642 rtype
= v800_reloc_type (type
);
1645 case EM_CYGNUS_V850
:
1646 rtype
= v850_reloc_type (type
);
1650 case EM_CYGNUS_D10V
:
1651 rtype
= elf_d10v_reloc_type (type
);
1655 case EM_CYGNUS_D30V
:
1656 rtype
= elf_d30v_reloc_type (type
);
1660 rtype
= elf_dlx_reloc_type (type
);
1664 rtype
= elf_sh_reloc_type (type
);
1668 case EM_CYGNUS_MN10300
:
1669 rtype
= elf_mn10300_reloc_type (type
);
1673 case EM_CYGNUS_MN10200
:
1674 rtype
= elf_mn10200_reloc_type (type
);
1678 case EM_CYGNUS_FR30
:
1679 rtype
= elf_fr30_reloc_type (type
);
1683 rtype
= elf_frv_reloc_type (type
);
1687 rtype
= elf_csky_reloc_type (type
);
1691 rtype
= elf_ft32_reloc_type (type
);
1695 rtype
= elf_mcore_reloc_type (type
);
1699 rtype
= elf_mmix_reloc_type (type
);
1703 rtype
= elf_moxie_reloc_type (type
);
1707 if (uses_msp430x_relocs (filedata
))
1709 rtype
= elf_msp430x_reloc_type (type
);
1714 rtype
= elf_msp430_reloc_type (type
);
1718 rtype
= elf_nds32_reloc_type (type
);
1722 rtype
= elf_ppc_reloc_type (type
);
1726 rtype
= elf_ppc64_reloc_type (type
);
1730 case EM_MIPS_RS3_LE
:
1731 rtype
= elf_mips_reloc_type (type
);
1735 rtype
= elf_riscv_reloc_type (type
);
1739 rtype
= elf_alpha_reloc_type (type
);
1743 rtype
= elf_arm_reloc_type (type
);
1747 case EM_ARC_COMPACT
:
1748 case EM_ARC_COMPACT2
:
1749 rtype
= elf_arc_reloc_type (type
);
1753 rtype
= elf_hppa_reloc_type (type
);
1759 rtype
= elf_h8_reloc_type (type
);
1763 rtype
= elf_or1k_reloc_type (type
);
1768 rtype
= elf_pj_reloc_type (type
);
1771 rtype
= elf_ia64_reloc_type (type
);
1775 rtype
= elf_cris_reloc_type (type
);
1779 rtype
= elf_i860_reloc_type (type
);
1785 rtype
= elf_x86_64_reloc_type (type
);
1789 rtype
= i370_reloc_type (type
);
1794 rtype
= elf_s390_reloc_type (type
);
1798 rtype
= elf_score_reloc_type (type
);
1802 rtype
= elf_xstormy16_reloc_type (type
);
1806 rtype
= elf_crx_reloc_type (type
);
1810 rtype
= elf_vax_reloc_type (type
);
1814 rtype
= elf_visium_reloc_type (type
);
1818 rtype
= elf_bpf_reloc_type (type
);
1821 case EM_ADAPTEVA_EPIPHANY
:
1822 rtype
= elf_epiphany_reloc_type (type
);
1827 rtype
= elf_ip2k_reloc_type (type
);
1831 rtype
= elf_iq2000_reloc_type (type
);
1836 rtype
= elf_xtensa_reloc_type (type
);
1839 case EM_LATTICEMICO32
:
1840 rtype
= elf_lm32_reloc_type (type
);
1845 rtype
= elf_m32c_reloc_type (type
);
1849 rtype
= elf_mt_reloc_type (type
);
1853 rtype
= elf_bfin_reloc_type (type
);
1857 rtype
= elf_mep_reloc_type (type
);
1861 rtype
= elf_cr16_reloc_type (type
);
1865 case EM_MICROBLAZE_OLD
:
1866 rtype
= elf_microblaze_reloc_type (type
);
1870 rtype
= elf_rl78_reloc_type (type
);
1874 rtype
= elf_rx_reloc_type (type
);
1878 rtype
= elf_metag_reloc_type (type
);
1883 rtype
= elf_xc16x_reloc_type (type
);
1887 rtype
= elf_tic6x_reloc_type (type
);
1891 rtype
= elf_tilegx_reloc_type (type
);
1895 rtype
= elf_tilepro_reloc_type (type
);
1898 case EM_WEBASSEMBLY
:
1899 rtype
= elf_wasm32_reloc_type (type
);
1903 rtype
= elf_xgate_reloc_type (type
);
1906 case EM_ALTERA_NIOS2
:
1907 rtype
= elf_nios2_reloc_type (type
);
1911 rtype
= elf_pru_reloc_type (type
);
1915 if (EF_NFP_MACH (filedata
->file_header
.e_flags
) == E_NFP_MACH_3200
)
1916 rtype
= elf_nfp3200_reloc_type (type
);
1918 rtype
= elf_nfp_reloc_type (type
);
1922 rtype
= elf_z80_reloc_type (type
);
1926 rtype
= elf_loongarch_reloc_type (type
);
1932 printf (_("unrecognized: %-7lx"), (unsigned long) type
& 0xffffffff);
1934 printf (do_wide
? "%-22s" : "%-17.17s", rtype
);
1936 if (filedata
->file_header
.e_machine
== EM_ALPHA
1938 && streq (rtype
, "R_ALPHA_LITUSE")
1939 && rel_type
== reltype_rela
)
1941 switch (rels
[i
].r_addend
)
1943 case LITUSE_ALPHA_ADDR
: rtype
= "ADDR"; break;
1944 case LITUSE_ALPHA_BASE
: rtype
= "BASE"; break;
1945 case LITUSE_ALPHA_BYTOFF
: rtype
= "BYTOFF"; break;
1946 case LITUSE_ALPHA_JSR
: rtype
= "JSR"; break;
1947 case LITUSE_ALPHA_TLSGD
: rtype
= "TLSGD"; break;
1948 case LITUSE_ALPHA_TLSLDM
: rtype
= "TLSLDM"; break;
1949 case LITUSE_ALPHA_JSRDIRECT
: rtype
= "JSRDIRECT"; break;
1950 default: rtype
= NULL
;
1954 printf (" (%s)", rtype
);
1958 printf (_("<unknown addend: %lx>"),
1959 (unsigned long) rels
[i
].r_addend
);
1963 else if (symtab_index
)
1965 if (symtab
== NULL
|| symtab_index
>= nsyms
)
1967 error (_(" bad symbol index: %08lx in reloc\n"),
1968 (unsigned long) symtab_index
);
1973 Elf_Internal_Sym
* psym
;
1974 const char * version_string
;
1975 enum versioned_symbol_info sym_info
;
1976 unsigned short vna_other
;
1978 psym
= symtab
+ symtab_index
;
1981 = get_symbol_version_string (filedata
, is_dynsym
,
1990 if (ELF_ST_TYPE (psym
->st_info
) == STT_GNU_IFUNC
)
1994 unsigned int width
= is_32bit_elf
? 8 : 14;
1996 /* Relocations against GNU_IFUNC symbols do not use the value
1997 of the symbol as the address to relocate against. Instead
1998 they invoke the function named by the symbol and use its
1999 result as the address for relocation.
2001 To indicate this to the user, do not display the value of
2002 the symbol in the "Symbols's Value" field. Instead show
2003 its name followed by () as a hint that the symbol is
2007 || psym
->st_name
== 0
2008 || psym
->st_name
>= strtablen
)
2011 name
= strtab
+ psym
->st_name
;
2013 len
= print_symbol (width
, name
);
2015 printf (sym_info
== symbol_public
? "@@%s" : "@%s",
2017 printf ("()%-*s", len
<= width
? (width
+ 1) - len
: 1, " ");
2021 print_vma (psym
->st_value
, LONG_HEX
);
2023 printf (is_32bit_elf
? " " : " ");
2026 if (psym
->st_name
== 0)
2028 const char * sec_name
= "<null>";
2031 if (ELF_ST_TYPE (psym
->st_info
) == STT_SECTION
)
2033 if (psym
->st_shndx
< filedata
->file_header
.e_shnum
2034 && filedata
->section_headers
!= NULL
)
2035 sec_name
= section_name_print (filedata
,
2036 filedata
->section_headers
2038 else if (psym
->st_shndx
== SHN_ABS
)
2040 else if (psym
->st_shndx
== SHN_COMMON
)
2041 sec_name
= "COMMON";
2042 else if ((filedata
->file_header
.e_machine
== EM_MIPS
2043 && psym
->st_shndx
== SHN_MIPS_SCOMMON
)
2044 || (filedata
->file_header
.e_machine
== EM_TI_C6000
2045 && psym
->st_shndx
== SHN_TIC6X_SCOMMON
))
2046 sec_name
= "SCOMMON";
2047 else if (filedata
->file_header
.e_machine
== EM_MIPS
2048 && psym
->st_shndx
== SHN_MIPS_SUNDEFINED
)
2049 sec_name
= "SUNDEF";
2050 else if ((filedata
->file_header
.e_machine
== EM_X86_64
2051 || filedata
->file_header
.e_machine
== EM_L1OM
2052 || filedata
->file_header
.e_machine
== EM_K1OM
)
2053 && psym
->st_shndx
== SHN_X86_64_LCOMMON
)
2054 sec_name
= "LARGE_COMMON";
2055 else if (filedata
->file_header
.e_machine
== EM_IA_64
2056 && filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_HPUX
2057 && psym
->st_shndx
== SHN_IA_64_ANSI_COMMON
)
2058 sec_name
= "ANSI_COM";
2059 else if (is_ia64_vms (filedata
)
2060 && psym
->st_shndx
== SHN_IA_64_VMS_SYMVEC
)
2061 sec_name
= "VMS_SYMVEC";
2064 sprintf (name_buf
, "<section 0x%x>",
2065 (unsigned int) psym
->st_shndx
);
2066 sec_name
= name_buf
;
2069 print_symbol (22, sec_name
);
2071 else if (strtab
== NULL
)
2072 printf (_("<string table index: %3ld>"), psym
->st_name
);
2073 else if (psym
->st_name
>= strtablen
)
2075 error (_("<corrupt string table index: %3ld>\n"),
2081 print_symbol (22, strtab
+ psym
->st_name
);
2083 printf (sym_info
== symbol_public
? "@@%s" : "@%s",
2087 if (rel_type
== reltype_rela
)
2089 bfd_vma off
= rels
[i
].r_addend
;
2091 if ((bfd_signed_vma
) off
< 0)
2092 printf (" - %" BFD_VMA_FMT
"x", - off
);
2094 printf (" + %" BFD_VMA_FMT
"x", off
);
2098 else if (rel_type
== reltype_rela
)
2100 bfd_vma off
= rels
[i
].r_addend
;
2102 printf ("%*c", is_32bit_elf
? 12 : 20, ' ');
2103 if ((bfd_signed_vma
) off
< 0)
2104 printf ("-%" BFD_VMA_FMT
"x", - off
);
2106 printf ("%" BFD_VMA_FMT
"x", off
);
2109 if (filedata
->file_header
.e_machine
== EM_SPARCV9
2111 && streq (rtype
, "R_SPARC_OLO10"))
2112 printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (inf
));
2117 if (! is_32bit_elf
&& filedata
->file_header
.e_machine
== EM_MIPS
)
2119 bfd_vma type2
= ELF64_MIPS_R_TYPE2 (inf
);
2120 bfd_vma type3
= ELF64_MIPS_R_TYPE3 (inf
);
2121 const char * rtype2
= elf_mips_reloc_type (type2
);
2122 const char * rtype3
= elf_mips_reloc_type (type3
);
2124 printf (" Type2: ");
2127 printf (_("unrecognized: %-7lx"),
2128 (unsigned long) type2
& 0xffffffff);
2130 printf ("%-17.17s", rtype2
);
2132 printf ("\n Type3: ");
2135 printf (_("unrecognized: %-7lx"),
2136 (unsigned long) type3
& 0xffffffff);
2138 printf ("%-17.17s", rtype3
);
2151 get_aarch64_dynamic_type (unsigned long type
)
2155 case DT_AARCH64_BTI_PLT
: return "AARCH64_BTI_PLT";
2156 case DT_AARCH64_PAC_PLT
: return "AARCH64_PAC_PLT";
2157 case DT_AARCH64_VARIANT_PCS
: return "AARCH64_VARIANT_PCS";
2164 get_mips_dynamic_type (unsigned long type
)
2168 case DT_MIPS_RLD_VERSION
: return "MIPS_RLD_VERSION";
2169 case DT_MIPS_TIME_STAMP
: return "MIPS_TIME_STAMP";
2170 case DT_MIPS_ICHECKSUM
: return "MIPS_ICHECKSUM";
2171 case DT_MIPS_IVERSION
: return "MIPS_IVERSION";
2172 case DT_MIPS_FLAGS
: return "MIPS_FLAGS";
2173 case DT_MIPS_BASE_ADDRESS
: return "MIPS_BASE_ADDRESS";
2174 case DT_MIPS_MSYM
: return "MIPS_MSYM";
2175 case DT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
2176 case DT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
2177 case DT_MIPS_LOCAL_GOTNO
: return "MIPS_LOCAL_GOTNO";
2178 case DT_MIPS_CONFLICTNO
: return "MIPS_CONFLICTNO";
2179 case DT_MIPS_LIBLISTNO
: return "MIPS_LIBLISTNO";
2180 case DT_MIPS_SYMTABNO
: return "MIPS_SYMTABNO";
2181 case DT_MIPS_UNREFEXTNO
: return "MIPS_UNREFEXTNO";
2182 case DT_MIPS_GOTSYM
: return "MIPS_GOTSYM";
2183 case DT_MIPS_HIPAGENO
: return "MIPS_HIPAGENO";
2184 case DT_MIPS_RLD_MAP
: return "MIPS_RLD_MAP";
2185 case DT_MIPS_RLD_MAP_REL
: return "MIPS_RLD_MAP_REL";
2186 case DT_MIPS_DELTA_CLASS
: return "MIPS_DELTA_CLASS";
2187 case DT_MIPS_DELTA_CLASS_NO
: return "MIPS_DELTA_CLASS_NO";
2188 case DT_MIPS_DELTA_INSTANCE
: return "MIPS_DELTA_INSTANCE";
2189 case DT_MIPS_DELTA_INSTANCE_NO
: return "MIPS_DELTA_INSTANCE_NO";
2190 case DT_MIPS_DELTA_RELOC
: return "MIPS_DELTA_RELOC";
2191 case DT_MIPS_DELTA_RELOC_NO
: return "MIPS_DELTA_RELOC_NO";
2192 case DT_MIPS_DELTA_SYM
: return "MIPS_DELTA_SYM";
2193 case DT_MIPS_DELTA_SYM_NO
: return "MIPS_DELTA_SYM_NO";
2194 case DT_MIPS_DELTA_CLASSSYM
: return "MIPS_DELTA_CLASSSYM";
2195 case DT_MIPS_DELTA_CLASSSYM_NO
: return "MIPS_DELTA_CLASSSYM_NO";
2196 case DT_MIPS_CXX_FLAGS
: return "MIPS_CXX_FLAGS";
2197 case DT_MIPS_PIXIE_INIT
: return "MIPS_PIXIE_INIT";
2198 case DT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
2199 case DT_MIPS_LOCALPAGE_GOTIDX
: return "MIPS_LOCALPAGE_GOTIDX";
2200 case DT_MIPS_LOCAL_GOTIDX
: return "MIPS_LOCAL_GOTIDX";
2201 case DT_MIPS_HIDDEN_GOTIDX
: return "MIPS_HIDDEN_GOTIDX";
2202 case DT_MIPS_PROTECTED_GOTIDX
: return "MIPS_PROTECTED_GOTIDX";
2203 case DT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
2204 case DT_MIPS_INTERFACE
: return "MIPS_INTERFACE";
2205 case DT_MIPS_DYNSTR_ALIGN
: return "MIPS_DYNSTR_ALIGN";
2206 case DT_MIPS_INTERFACE_SIZE
: return "MIPS_INTERFACE_SIZE";
2207 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR
: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
2208 case DT_MIPS_PERF_SUFFIX
: return "MIPS_PERF_SUFFIX";
2209 case DT_MIPS_COMPACT_SIZE
: return "MIPS_COMPACT_SIZE";
2210 case DT_MIPS_GP_VALUE
: return "MIPS_GP_VALUE";
2211 case DT_MIPS_AUX_DYNAMIC
: return "MIPS_AUX_DYNAMIC";
2212 case DT_MIPS_PLTGOT
: return "MIPS_PLTGOT";
2213 case DT_MIPS_RWPLT
: return "MIPS_RWPLT";
2214 case DT_MIPS_XHASH
: return "MIPS_XHASH";
2221 get_sparc64_dynamic_type (unsigned long type
)
2225 case DT_SPARC_REGISTER
: return "SPARC_REGISTER";
2232 get_ppc_dynamic_type (unsigned long type
)
2236 case DT_PPC_GOT
: return "PPC_GOT";
2237 case DT_PPC_OPT
: return "PPC_OPT";
2244 get_ppc64_dynamic_type (unsigned long type
)
2248 case DT_PPC64_GLINK
: return "PPC64_GLINK";
2249 case DT_PPC64_OPD
: return "PPC64_OPD";
2250 case DT_PPC64_OPDSZ
: return "PPC64_OPDSZ";
2251 case DT_PPC64_OPT
: return "PPC64_OPT";
2258 get_parisc_dynamic_type (unsigned long type
)
2262 case DT_HP_LOAD_MAP
: return "HP_LOAD_MAP";
2263 case DT_HP_DLD_FLAGS
: return "HP_DLD_FLAGS";
2264 case DT_HP_DLD_HOOK
: return "HP_DLD_HOOK";
2265 case DT_HP_UX10_INIT
: return "HP_UX10_INIT";
2266 case DT_HP_UX10_INITSZ
: return "HP_UX10_INITSZ";
2267 case DT_HP_PREINIT
: return "HP_PREINIT";
2268 case DT_HP_PREINITSZ
: return "HP_PREINITSZ";
2269 case DT_HP_NEEDED
: return "HP_NEEDED";
2270 case DT_HP_TIME_STAMP
: return "HP_TIME_STAMP";
2271 case DT_HP_CHECKSUM
: return "HP_CHECKSUM";
2272 case DT_HP_GST_SIZE
: return "HP_GST_SIZE";
2273 case DT_HP_GST_VERSION
: return "HP_GST_VERSION";
2274 case DT_HP_GST_HASHVAL
: return "HP_GST_HASHVAL";
2275 case DT_HP_EPLTREL
: return "HP_GST_EPLTREL";
2276 case DT_HP_EPLTRELSZ
: return "HP_GST_EPLTRELSZ";
2277 case DT_HP_FILTERED
: return "HP_FILTERED";
2278 case DT_HP_FILTER_TLS
: return "HP_FILTER_TLS";
2279 case DT_HP_COMPAT_FILTERED
: return "HP_COMPAT_FILTERED";
2280 case DT_HP_LAZYLOAD
: return "HP_LAZYLOAD";
2281 case DT_HP_BIND_NOW_COUNT
: return "HP_BIND_NOW_COUNT";
2282 case DT_PLT
: return "PLT";
2283 case DT_PLT_SIZE
: return "PLT_SIZE";
2284 case DT_DLT
: return "DLT";
2285 case DT_DLT_SIZE
: return "DLT_SIZE";
2292 get_ia64_dynamic_type (unsigned long type
)
2296 case DT_IA_64_PLT_RESERVE
: return "IA_64_PLT_RESERVE";
2297 case DT_IA_64_VMS_SUBTYPE
: return "VMS_SUBTYPE";
2298 case DT_IA_64_VMS_IMGIOCNT
: return "VMS_IMGIOCNT";
2299 case DT_IA_64_VMS_LNKFLAGS
: return "VMS_LNKFLAGS";
2300 case DT_IA_64_VMS_VIR_MEM_BLK_SIZ
: return "VMS_VIR_MEM_BLK_SIZ";
2301 case DT_IA_64_VMS_IDENT
: return "VMS_IDENT";
2302 case DT_IA_64_VMS_NEEDED_IDENT
: return "VMS_NEEDED_IDENT";
2303 case DT_IA_64_VMS_IMG_RELA_CNT
: return "VMS_IMG_RELA_CNT";
2304 case DT_IA_64_VMS_SEG_RELA_CNT
: return "VMS_SEG_RELA_CNT";
2305 case DT_IA_64_VMS_FIXUP_RELA_CNT
: return "VMS_FIXUP_RELA_CNT";
2306 case DT_IA_64_VMS_FIXUP_NEEDED
: return "VMS_FIXUP_NEEDED";
2307 case DT_IA_64_VMS_SYMVEC_CNT
: return "VMS_SYMVEC_CNT";
2308 case DT_IA_64_VMS_XLATED
: return "VMS_XLATED";
2309 case DT_IA_64_VMS_STACKSIZE
: return "VMS_STACKSIZE";
2310 case DT_IA_64_VMS_UNWINDSZ
: return "VMS_UNWINDSZ";
2311 case DT_IA_64_VMS_UNWIND_CODSEG
: return "VMS_UNWIND_CODSEG";
2312 case DT_IA_64_VMS_UNWIND_INFOSEG
: return "VMS_UNWIND_INFOSEG";
2313 case DT_IA_64_VMS_LINKTIME
: return "VMS_LINKTIME";
2314 case DT_IA_64_VMS_SEG_NO
: return "VMS_SEG_NO";
2315 case DT_IA_64_VMS_SYMVEC_OFFSET
: return "VMS_SYMVEC_OFFSET";
2316 case DT_IA_64_VMS_SYMVEC_SEG
: return "VMS_SYMVEC_SEG";
2317 case DT_IA_64_VMS_UNWIND_OFFSET
: return "VMS_UNWIND_OFFSET";
2318 case DT_IA_64_VMS_UNWIND_SEG
: return "VMS_UNWIND_SEG";
2319 case DT_IA_64_VMS_STRTAB_OFFSET
: return "VMS_STRTAB_OFFSET";
2320 case DT_IA_64_VMS_SYSVER_OFFSET
: return "VMS_SYSVER_OFFSET";
2321 case DT_IA_64_VMS_IMG_RELA_OFF
: return "VMS_IMG_RELA_OFF";
2322 case DT_IA_64_VMS_SEG_RELA_OFF
: return "VMS_SEG_RELA_OFF";
2323 case DT_IA_64_VMS_FIXUP_RELA_OFF
: return "VMS_FIXUP_RELA_OFF";
2324 case DT_IA_64_VMS_PLTGOT_OFFSET
: return "VMS_PLTGOT_OFFSET";
2325 case DT_IA_64_VMS_PLTGOT_SEG
: return "VMS_PLTGOT_SEG";
2326 case DT_IA_64_VMS_FPMODE
: return "VMS_FPMODE";
2333 get_solaris_section_type (unsigned long type
)
2337 case 0x6fffffee: return "SUNW_ancillary";
2338 case 0x6fffffef: return "SUNW_capchain";
2339 case 0x6ffffff0: return "SUNW_capinfo";
2340 case 0x6ffffff1: return "SUNW_symsort";
2341 case 0x6ffffff2: return "SUNW_tlssort";
2342 case 0x6ffffff3: return "SUNW_LDYNSYM";
2343 case 0x6ffffff4: return "SUNW_dof";
2344 case 0x6ffffff5: return "SUNW_cap";
2345 case 0x6ffffff6: return "SUNW_SIGNATURE";
2346 case 0x6ffffff7: return "SUNW_ANNOTATE";
2347 case 0x6ffffff8: return "SUNW_DEBUGSTR";
2348 case 0x6ffffff9: return "SUNW_DEBUG";
2349 case 0x6ffffffa: return "SUNW_move";
2350 case 0x6ffffffb: return "SUNW_COMDAT";
2351 case 0x6ffffffc: return "SUNW_syminfo";
2352 case 0x6ffffffd: return "SUNW_verdef";
2353 case 0x6ffffffe: return "SUNW_verneed";
2354 case 0x6fffffff: return "SUNW_versym";
2355 case 0x70000000: return "SPARC_GOTDATA";
2356 default: return NULL
;
2361 get_alpha_dynamic_type (unsigned long type
)
2365 case DT_ALPHA_PLTRO
: return "ALPHA_PLTRO";
2366 default: return NULL
;
2371 get_score_dynamic_type (unsigned long type
)
2375 case DT_SCORE_BASE_ADDRESS
: return "SCORE_BASE_ADDRESS";
2376 case DT_SCORE_LOCAL_GOTNO
: return "SCORE_LOCAL_GOTNO";
2377 case DT_SCORE_SYMTABNO
: return "SCORE_SYMTABNO";
2378 case DT_SCORE_GOTSYM
: return "SCORE_GOTSYM";
2379 case DT_SCORE_UNREFEXTNO
: return "SCORE_UNREFEXTNO";
2380 case DT_SCORE_HIPAGENO
: return "SCORE_HIPAGENO";
2381 default: return NULL
;
2386 get_tic6x_dynamic_type (unsigned long type
)
2390 case DT_C6000_GSYM_OFFSET
: return "C6000_GSYM_OFFSET";
2391 case DT_C6000_GSTR_OFFSET
: return "C6000_GSTR_OFFSET";
2392 case DT_C6000_DSBT_BASE
: return "C6000_DSBT_BASE";
2393 case DT_C6000_DSBT_SIZE
: return "C6000_DSBT_SIZE";
2394 case DT_C6000_PREEMPTMAP
: return "C6000_PREEMPTMAP";
2395 case DT_C6000_DSBT_INDEX
: return "C6000_DSBT_INDEX";
2396 default: return NULL
;
2401 get_nios2_dynamic_type (unsigned long type
)
2405 case DT_NIOS2_GP
: return "NIOS2_GP";
2406 default: return NULL
;
2411 get_solaris_dynamic_type (unsigned long type
)
2415 case 0x6000000d: return "SUNW_AUXILIARY";
2416 case 0x6000000e: return "SUNW_RTLDINF";
2417 case 0x6000000f: return "SUNW_FILTER";
2418 case 0x60000010: return "SUNW_CAP";
2419 case 0x60000011: return "SUNW_SYMTAB";
2420 case 0x60000012: return "SUNW_SYMSZ";
2421 case 0x60000013: return "SUNW_SORTENT";
2422 case 0x60000014: return "SUNW_SYMSORT";
2423 case 0x60000015: return "SUNW_SYMSORTSZ";
2424 case 0x60000016: return "SUNW_TLSSORT";
2425 case 0x60000017: return "SUNW_TLSSORTSZ";
2426 case 0x60000018: return "SUNW_CAPINFO";
2427 case 0x60000019: return "SUNW_STRPAD";
2428 case 0x6000001a: return "SUNW_CAPCHAIN";
2429 case 0x6000001b: return "SUNW_LDMACH";
2430 case 0x6000001d: return "SUNW_CAPCHAINENT";
2431 case 0x6000001f: return "SUNW_CAPCHAINSZ";
2432 case 0x60000021: return "SUNW_PARENT";
2433 case 0x60000023: return "SUNW_ASLR";
2434 case 0x60000025: return "SUNW_RELAX";
2435 case 0x60000029: return "SUNW_NXHEAP";
2436 case 0x6000002b: return "SUNW_NXSTACK";
2438 case 0x70000001: return "SPARC_REGISTER";
2439 case 0x7ffffffd: return "AUXILIARY";
2440 case 0x7ffffffe: return "USED";
2441 case 0x7fffffff: return "FILTER";
2443 default: return NULL
;
2448 get_riscv_dynamic_type (unsigned long type
)
2452 case DT_RISCV_VARIANT_CC
: return "RISCV_VARIANT_CC";
2459 get_dynamic_type (Filedata
* filedata
, unsigned long type
)
2461 static char buff
[64];
2465 case DT_NULL
: return "NULL";
2466 case DT_NEEDED
: return "NEEDED";
2467 case DT_PLTRELSZ
: return "PLTRELSZ";
2468 case DT_PLTGOT
: return "PLTGOT";
2469 case DT_HASH
: return "HASH";
2470 case DT_STRTAB
: return "STRTAB";
2471 case DT_SYMTAB
: return "SYMTAB";
2472 case DT_RELA
: return "RELA";
2473 case DT_RELASZ
: return "RELASZ";
2474 case DT_RELAENT
: return "RELAENT";
2475 case DT_STRSZ
: return "STRSZ";
2476 case DT_SYMENT
: return "SYMENT";
2477 case DT_INIT
: return "INIT";
2478 case DT_FINI
: return "FINI";
2479 case DT_SONAME
: return "SONAME";
2480 case DT_RPATH
: return "RPATH";
2481 case DT_SYMBOLIC
: return "SYMBOLIC";
2482 case DT_REL
: return "REL";
2483 case DT_RELSZ
: return "RELSZ";
2484 case DT_RELENT
: return "RELENT";
2485 case DT_RELR
: return "RELR";
2486 case DT_RELRSZ
: return "RELRSZ";
2487 case DT_RELRENT
: return "RELRENT";
2488 case DT_PLTREL
: return "PLTREL";
2489 case DT_DEBUG
: return "DEBUG";
2490 case DT_TEXTREL
: return "TEXTREL";
2491 case DT_JMPREL
: return "JMPREL";
2492 case DT_BIND_NOW
: return "BIND_NOW";
2493 case DT_INIT_ARRAY
: return "INIT_ARRAY";
2494 case DT_FINI_ARRAY
: return "FINI_ARRAY";
2495 case DT_INIT_ARRAYSZ
: return "INIT_ARRAYSZ";
2496 case DT_FINI_ARRAYSZ
: return "FINI_ARRAYSZ";
2497 case DT_RUNPATH
: return "RUNPATH";
2498 case DT_FLAGS
: return "FLAGS";
2500 case DT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
2501 case DT_PREINIT_ARRAYSZ
: return "PREINIT_ARRAYSZ";
2502 case DT_SYMTAB_SHNDX
: return "SYMTAB_SHNDX";
2504 case DT_CHECKSUM
: return "CHECKSUM";
2505 case DT_PLTPADSZ
: return "PLTPADSZ";
2506 case DT_MOVEENT
: return "MOVEENT";
2507 case DT_MOVESZ
: return "MOVESZ";
2508 case DT_FEATURE
: return "FEATURE";
2509 case DT_POSFLAG_1
: return "POSFLAG_1";
2510 case DT_SYMINSZ
: return "SYMINSZ";
2511 case DT_SYMINENT
: return "SYMINENT"; /* aka VALRNGHI */
2513 case DT_ADDRRNGLO
: return "ADDRRNGLO";
2514 case DT_CONFIG
: return "CONFIG";
2515 case DT_DEPAUDIT
: return "DEPAUDIT";
2516 case DT_AUDIT
: return "AUDIT";
2517 case DT_PLTPAD
: return "PLTPAD";
2518 case DT_MOVETAB
: return "MOVETAB";
2519 case DT_SYMINFO
: return "SYMINFO"; /* aka ADDRRNGHI */
2521 case DT_VERSYM
: return "VERSYM";
2523 case DT_TLSDESC_GOT
: return "TLSDESC_GOT";
2524 case DT_TLSDESC_PLT
: return "TLSDESC_PLT";
2525 case DT_RELACOUNT
: return "RELACOUNT";
2526 case DT_RELCOUNT
: return "RELCOUNT";
2527 case DT_FLAGS_1
: return "FLAGS_1";
2528 case DT_VERDEF
: return "VERDEF";
2529 case DT_VERDEFNUM
: return "VERDEFNUM";
2530 case DT_VERNEED
: return "VERNEED";
2531 case DT_VERNEEDNUM
: return "VERNEEDNUM";
2533 case DT_AUXILIARY
: return "AUXILIARY";
2534 case DT_USED
: return "USED";
2535 case DT_FILTER
: return "FILTER";
2537 case DT_GNU_PRELINKED
: return "GNU_PRELINKED";
2538 case DT_GNU_CONFLICT
: return "GNU_CONFLICT";
2539 case DT_GNU_CONFLICTSZ
: return "GNU_CONFLICTSZ";
2540 case DT_GNU_LIBLIST
: return "GNU_LIBLIST";
2541 case DT_GNU_LIBLISTSZ
: return "GNU_LIBLISTSZ";
2542 case DT_GNU_HASH
: return "GNU_HASH";
2543 case DT_GNU_FLAGS_1
: return "GNU_FLAGS_1";
2546 if ((type
>= DT_LOPROC
) && (type
<= DT_HIPROC
))
2548 const char * result
;
2550 switch (filedata
->file_header
.e_machine
)
2553 result
= get_aarch64_dynamic_type (type
);
2556 case EM_MIPS_RS3_LE
:
2557 result
= get_mips_dynamic_type (type
);
2560 result
= get_sparc64_dynamic_type (type
);
2563 result
= get_ppc_dynamic_type (type
);
2566 result
= get_ppc64_dynamic_type (type
);
2569 result
= get_ia64_dynamic_type (type
);
2572 result
= get_alpha_dynamic_type (type
);
2575 result
= get_score_dynamic_type (type
);
2578 result
= get_tic6x_dynamic_type (type
);
2580 case EM_ALTERA_NIOS2
:
2581 result
= get_nios2_dynamic_type (type
);
2584 result
= get_riscv_dynamic_type (type
);
2587 if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_SOLARIS
)
2588 result
= get_solaris_dynamic_type (type
);
2597 snprintf (buff
, sizeof (buff
), _("Processor Specific: %lx"), type
);
2599 else if (((type
>= DT_LOOS
) && (type
<= DT_HIOS
))
2600 || (filedata
->file_header
.e_machine
== EM_PARISC
2601 && (type
>= OLD_DT_LOOS
) && (type
<= OLD_DT_HIOS
)))
2603 const char * result
;
2605 switch (filedata
->file_header
.e_machine
)
2608 result
= get_parisc_dynamic_type (type
);
2611 result
= get_ia64_dynamic_type (type
);
2614 if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_SOLARIS
)
2615 result
= get_solaris_dynamic_type (type
);
2624 snprintf (buff
, sizeof (buff
), _("Operating System specific: %lx"),
2628 snprintf (buff
, sizeof (buff
), _("<unknown>: %lx"), type
);
2634 static bool get_program_headers (Filedata
*);
2635 static bool get_dynamic_section (Filedata
*);
2638 locate_dynamic_section (Filedata
*filedata
)
2640 unsigned long dynamic_addr
= 0;
2641 bfd_size_type dynamic_size
= 0;
2643 if (filedata
->file_header
.e_phnum
!= 0
2644 && get_program_headers (filedata
))
2646 Elf_Internal_Phdr
*segment
;
2649 for (i
= 0, segment
= filedata
->program_headers
;
2650 i
< filedata
->file_header
.e_phnum
;
2653 if (segment
->p_type
== PT_DYNAMIC
)
2655 dynamic_addr
= segment
->p_offset
;
2656 dynamic_size
= segment
->p_filesz
;
2658 if (filedata
->section_headers
!= NULL
)
2660 Elf_Internal_Shdr
*sec
;
2662 sec
= find_section (filedata
, ".dynamic");
2665 if (sec
->sh_size
== 0
2666 || sec
->sh_type
== SHT_NOBITS
)
2673 dynamic_addr
= sec
->sh_offset
;
2674 dynamic_size
= sec
->sh_size
;
2679 if (dynamic_addr
> filedata
->file_size
2680 || (dynamic_size
> filedata
->file_size
- dynamic_addr
))
2689 filedata
->dynamic_addr
= dynamic_addr
;
2690 filedata
->dynamic_size
= dynamic_size
? dynamic_size
: 1;
2694 is_pie (Filedata
*filedata
)
2696 Elf_Internal_Dyn
*entry
;
2698 if (filedata
->dynamic_size
== 0)
2699 locate_dynamic_section (filedata
);
2700 if (filedata
->dynamic_size
<= 1)
2703 if (!get_dynamic_section (filedata
))
2706 for (entry
= filedata
->dynamic_section
;
2707 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
2710 if (entry
->d_tag
== DT_FLAGS_1
)
2712 if ((entry
->d_un
.d_val
& DF_1_PIE
) != 0)
2721 get_file_type (Filedata
*filedata
)
2723 unsigned e_type
= filedata
->file_header
.e_type
;
2724 static char buff
[64];
2728 case ET_NONE
: return _("NONE (None)");
2729 case ET_REL
: return _("REL (Relocatable file)");
2730 case ET_EXEC
: return _("EXEC (Executable file)");
2732 if (is_pie (filedata
))
2733 return _("DYN (Position-Independent Executable file)");
2735 return _("DYN (Shared object file)");
2736 case ET_CORE
: return _("CORE (Core file)");
2739 if ((e_type
>= ET_LOPROC
) && (e_type
<= ET_HIPROC
))
2740 snprintf (buff
, sizeof (buff
), _("Processor Specific: (%x)"), e_type
);
2741 else if ((e_type
>= ET_LOOS
) && (e_type
<= ET_HIOS
))
2742 snprintf (buff
, sizeof (buff
), _("OS Specific: (%x)"), e_type
);
2744 snprintf (buff
, sizeof (buff
), _("<unknown>: %x"), e_type
);
2750 get_machine_name (unsigned e_machine
)
2752 static char buff
[64]; /* XXX */
2756 /* Please keep this switch table sorted by increasing EM_ value. */
2758 case EM_NONE
: return _("None");
2759 case EM_M32
: return "WE32100";
2760 case EM_SPARC
: return "Sparc";
2761 case EM_386
: return "Intel 80386";
2762 case EM_68K
: return "MC68000";
2763 case EM_88K
: return "MC88000";
2764 case EM_IAMCU
: return "Intel MCU";
2765 case EM_860
: return "Intel 80860";
2766 case EM_MIPS
: return "MIPS R3000";
2767 case EM_S370
: return "IBM System/370";
2769 case EM_MIPS_RS3_LE
: return "MIPS R4000 big-endian";
2770 case EM_OLD_SPARCV9
: return "Sparc v9 (old)";
2771 case EM_PARISC
: return "HPPA";
2772 case EM_VPP550
: return "Fujitsu VPP500";
2773 case EM_SPARC32PLUS
: return "Sparc v8+" ;
2774 case EM_960
: return "Intel 80960";
2775 case EM_PPC
: return "PowerPC";
2777 case EM_PPC64
: return "PowerPC64";
2779 case EM_S390
: return "IBM S/390";
2780 case EM_SPU
: return "SPU";
2782 case EM_V800
: return "Renesas V850 (using RH850 ABI)";
2783 case EM_FR20
: return "Fujitsu FR20";
2784 case EM_RH32
: return "TRW RH32";
2785 case EM_MCORE
: return "MCORE";
2787 case EM_ARM
: return "ARM";
2788 case EM_OLD_ALPHA
: return "Digital Alpha (old)";
2789 case EM_SH
: return "Renesas / SuperH SH";
2790 case EM_SPARCV9
: return "Sparc v9";
2791 case EM_TRICORE
: return "Siemens Tricore";
2792 case EM_ARC
: return "ARC";
2793 case EM_H8_300
: return "Renesas H8/300";
2794 case EM_H8_300H
: return "Renesas H8/300H";
2795 case EM_H8S
: return "Renesas H8S";
2796 case EM_H8_500
: return "Renesas H8/500";
2798 case EM_IA_64
: return "Intel IA-64";
2799 case EM_MIPS_X
: return "Stanford MIPS-X";
2800 case EM_COLDFIRE
: return "Motorola Coldfire";
2801 case EM_68HC12
: return "Motorola MC68HC12 Microcontroller";
2802 case EM_MMA
: return "Fujitsu Multimedia Accelerator";
2803 case EM_PCP
: return "Siemens PCP";
2804 case EM_NCPU
: return "Sony nCPU embedded RISC processor";
2805 case EM_NDR1
: return "Denso NDR1 microprocesspr";
2806 case EM_STARCORE
: return "Motorola Star*Core processor";
2807 case EM_ME16
: return "Toyota ME16 processor";
2809 case EM_ST100
: return "STMicroelectronics ST100 processor";
2810 case EM_TINYJ
: return "Advanced Logic Corp. TinyJ embedded processor";
2811 case EM_X86_64
: return "Advanced Micro Devices X86-64";
2812 case EM_PDSP
: return "Sony DSP processor";
2813 case EM_PDP10
: return "Digital Equipment Corp. PDP-10";
2814 case EM_PDP11
: return "Digital Equipment Corp. PDP-11";
2815 case EM_FX66
: return "Siemens FX66 microcontroller";
2816 case EM_ST9PLUS
: return "STMicroelectronics ST9+ 8/16 bit microcontroller";
2817 case EM_ST7
: return "STMicroelectronics ST7 8-bit microcontroller";
2818 case EM_68HC16
: return "Motorola MC68HC16 Microcontroller";
2820 case EM_68HC11
: return "Motorola MC68HC11 Microcontroller";
2821 case EM_68HC08
: return "Motorola MC68HC08 Microcontroller";
2822 case EM_68HC05
: return "Motorola MC68HC05 Microcontroller";
2823 case EM_SVX
: return "Silicon Graphics SVx";
2824 case EM_ST19
: return "STMicroelectronics ST19 8-bit microcontroller";
2825 case EM_VAX
: return "Digital VAX";
2826 case EM_CRIS
: return "Axis Communications 32-bit embedded processor";
2827 case EM_JAVELIN
: return "Infineon Technologies 32-bit embedded cpu";
2828 case EM_FIREPATH
: return "Element 14 64-bit DSP processor";
2829 case EM_ZSP
: return "LSI Logic's 16-bit DSP processor";
2831 case EM_MMIX
: return "Donald Knuth's educational 64-bit processor";
2832 case EM_HUANY
: return "Harvard Universitys's machine-independent object format";
2833 case EM_PRISM
: return "Vitesse Prism";
2835 case EM_AVR
: return "Atmel AVR 8-bit microcontroller";
2836 case EM_CYGNUS_FR30
:
2837 case EM_FR30
: return "Fujitsu FR30";
2838 case EM_CYGNUS_D10V
:
2839 case EM_D10V
: return "d10v";
2840 case EM_CYGNUS_D30V
:
2841 case EM_D30V
: return "d30v";
2842 case EM_CYGNUS_V850
:
2843 case EM_V850
: return "Renesas V850";
2844 case EM_CYGNUS_M32R
:
2845 case EM_M32R
: return "Renesas M32R (formerly Mitsubishi M32r)";
2846 case EM_CYGNUS_MN10300
:
2847 case EM_MN10300
: return "mn10300";
2849 case EM_CYGNUS_MN10200
:
2850 case EM_MN10200
: return "mn10200";
2851 case EM_PJ
: return "picoJava";
2852 case EM_OR1K
: return "OpenRISC 1000";
2853 case EM_ARC_COMPACT
: return "ARCompact";
2855 case EM_XTENSA
: return "Tensilica Xtensa Processor";
2856 case EM_VIDEOCORE
: return "Alphamosaic VideoCore processor";
2857 case EM_TMM_GPP
: return "Thompson Multimedia General Purpose Processor";
2858 case EM_NS32K
: return "National Semiconductor 32000 series";
2859 case EM_TPC
: return "Tenor Network TPC processor";
2860 case EM_SNP1K
: return "Trebia SNP 1000 processor";
2862 case EM_ST200
: return "STMicroelectronics ST200 microcontroller";
2864 case EM_IP2K
: return "Ubicom IP2xxx 8-bit microcontrollers";
2865 case EM_MAX
: return "MAX Processor";
2866 case EM_CR
: return "National Semiconductor CompactRISC";
2867 case EM_F2MC16
: return "Fujitsu F2MC16";
2868 case EM_MSP430
: return "Texas Instruments msp430 microcontroller";
2869 case EM_BLACKFIN
: return "Analog Devices Blackfin";
2870 case EM_SE_C33
: return "S1C33 Family of Seiko Epson processors";
2871 case EM_SEP
: return "Sharp embedded microprocessor";
2872 case EM_ARCA
: return "Arca RISC microprocessor";
2874 case EM_UNICORE
: return "Unicore";
2875 case EM_EXCESS
: return "eXcess 16/32/64-bit configurable embedded CPU";
2876 case EM_DXP
: return "Icera Semiconductor Inc. Deep Execution Processor";
2877 case EM_ALTERA_NIOS2
: return "Altera Nios II";
2878 case EM_CRX
: return "National Semiconductor CRX microprocessor";
2879 case EM_XGATE
: return "Motorola XGATE embedded processor";
2881 case EM_XC16X
: return "Infineon Technologies xc16x";
2882 case EM_M16C
: return "Renesas M16C series microprocessors";
2883 case EM_DSPIC30F
: return "Microchip Technology dsPIC30F Digital Signal Controller";
2884 case EM_CE
: return "Freescale Communication Engine RISC core";
2886 case EM_M32C
: return "Renesas M32c";
2888 case EM_TSK3000
: return "Altium TSK3000 core";
2889 case EM_RS08
: return "Freescale RS08 embedded processor";
2890 case EM_ECOG2
: return "Cyan Technology eCOG2 microprocessor";
2891 case EM_SCORE
: return "SUNPLUS S+Core";
2892 case EM_DSP24
: return "New Japan Radio (NJR) 24-bit DSP Processor";
2893 case EM_VIDEOCORE3
: return "Broadcom VideoCore III processor";
2894 case EM_LATTICEMICO32
: return "Lattice Mico32";
2895 case EM_SE_C17
: return "Seiko Epson C17 family";
2897 case EM_TI_C6000
: return "Texas Instruments TMS320C6000 DSP family";
2898 case EM_TI_C2000
: return "Texas Instruments TMS320C2000 DSP family";
2899 case EM_TI_C5500
: return "Texas Instruments TMS320C55x DSP family";
2900 case EM_TI_PRU
: return "TI PRU I/O processor";
2902 case EM_MMDSP_PLUS
: return "STMicroelectronics 64bit VLIW Data Signal Processor";
2903 case EM_CYPRESS_M8C
: return "Cypress M8C microprocessor";
2904 case EM_R32C
: return "Renesas R32C series microprocessors";
2905 case EM_TRIMEDIA
: return "NXP Semiconductors TriMedia architecture family";
2906 case EM_QDSP6
: return "QUALCOMM DSP6 Processor";
2907 case EM_8051
: return "Intel 8051 and variants";
2908 case EM_STXP7X
: return "STMicroelectronics STxP7x family";
2909 case EM_NDS32
: return "Andes Technology compact code size embedded RISC processor family";
2910 case EM_ECOG1X
: return "Cyan Technology eCOG1X family";
2911 case EM_MAXQ30
: return "Dallas Semiconductor MAXQ30 Core microcontrollers";
2913 case EM_XIMO16
: return "New Japan Radio (NJR) 16-bit DSP Processor";
2914 case EM_MANIK
: return "M2000 Reconfigurable RISC Microprocessor";
2915 case EM_CRAYNV2
: return "Cray Inc. NV2 vector architecture";
2916 case EM_RX
: return "Renesas RX";
2917 case EM_METAG
: return "Imagination Technologies Meta processor architecture";
2918 case EM_MCST_ELBRUS
: return "MCST Elbrus general purpose hardware architecture";
2919 case EM_ECOG16
: return "Cyan Technology eCOG16 family";
2922 case EM_MICROBLAZE_OLD
: return "Xilinx MicroBlaze";
2923 case EM_ETPU
: return "Freescale Extended Time Processing Unit";
2924 case EM_SLE9X
: return "Infineon Technologies SLE9X core";
2926 case EM_L1OM
: return "Intel L1OM";
2927 case EM_K1OM
: return "Intel K1OM";
2928 case EM_INTEL182
: return "Intel (reserved)";
2929 case EM_AARCH64
: return "AArch64";
2930 case EM_ARM184
: return "ARM (reserved)";
2931 case EM_AVR32
: return "Atmel Corporation 32-bit microprocessor";
2932 case EM_STM8
: return "STMicroeletronics STM8 8-bit microcontroller";
2933 case EM_TILE64
: return "Tilera TILE64 multicore architecture family";
2934 case EM_TILEPRO
: return "Tilera TILEPro multicore architecture family";
2936 case EM_CUDA
: return "NVIDIA CUDA architecture";
2937 case EM_TILEGX
: return "Tilera TILE-Gx multicore architecture family";
2938 case EM_CLOUDSHIELD
: return "CloudShield architecture family";
2939 case EM_COREA_1ST
: return "KIPO-KAIST Core-A 1st generation processor family";
2940 case EM_COREA_2ND
: return "KIPO-KAIST Core-A 2nd generation processor family";
2941 case EM_ARC_COMPACT2
: return "ARCv2";
2942 case EM_OPEN8
: return "Open8 8-bit RISC soft processor core";
2943 case EM_RL78
: return "Renesas RL78";
2944 case EM_VIDEOCORE5
: return "Broadcom VideoCore V processor";
2945 case EM_78K0R
: return "Renesas 78K0R";
2947 case EM_56800EX
: return "Freescale 56800EX Digital Signal Controller (DSC)";
2948 case EM_BA1
: return "Beyond BA1 CPU architecture";
2949 case EM_BA2
: return "Beyond BA2 CPU architecture";
2950 case EM_XCORE
: return "XMOS xCORE processor family";
2951 case EM_MCHP_PIC
: return "Microchip 8-bit PIC(r) family";
2952 case EM_INTELGT
: return "Intel Graphics Technology";
2954 case EM_KM32
: return "KM211 KM32 32-bit processor";
2955 case EM_KMX32
: return "KM211 KMX32 32-bit processor";
2956 case EM_KMX16
: return "KM211 KMX16 16-bit processor";
2957 case EM_KMX8
: return "KM211 KMX8 8-bit processor";
2958 case EM_KVARC
: return "KM211 KVARC processor";
2959 case EM_CDP
: return "Paneve CDP architecture family";
2960 case EM_COGE
: return "Cognitive Smart Memory Processor";
2961 case EM_COOL
: return "Bluechip Systems CoolEngine";
2962 case EM_NORC
: return "Nanoradio Optimized RISC";
2963 case EM_CSR_KALIMBA
: return "CSR Kalimba architecture family";
2965 case EM_Z80
: return "Zilog Z80";
2966 case EM_VISIUM
: return "CDS VISIUMcore processor";
2967 case EM_FT32
: return "FTDI Chip FT32";
2968 case EM_MOXIE
: return "Moxie";
2969 case EM_AMDGPU
: return "AMD GPU";
2970 /* 230 (all reserved) */
2972 case EM_RISCV
: return "RISC-V";
2973 case EM_LANAI
: return "Lanai 32-bit processor";
2974 case EM_CEVA
: return "CEVA Processor Architecture Family";
2975 case EM_CEVA_X2
: return "CEVA X2 Processor Family";
2976 case EM_BPF
: return "Linux BPF";
2977 case EM_GRAPHCORE_IPU
: return "Graphcore Intelligent Processing Unit";
2978 case EM_IMG1
: return "Imagination Technologies";
2980 case EM_NFP
: return "Netronome Flow Processor";
2981 case EM_VE
: return "NEC Vector Engine";
2982 case EM_CSKY
: return "C-SKY";
2983 case EM_ARC_COMPACT3_64
: return "Synopsys ARCv2.3 64-bit";
2984 case EM_MCS6502
: return "MOS Technology MCS 6502 processor";
2985 case EM_ARC_COMPACT3
: return "Synopsys ARCv2.3 32-bit";
2986 case EM_KVX
: return "Kalray VLIW core of the MPPA processor family";
2987 case EM_65816
: return "WDC 65816/65C816";
2988 case EM_LOONGARCH
: return "LoongArch";
2989 case EM_KF32
: return "ChipON KungFu32";
2991 /* Large numbers... */
2992 case EM_MT
: return "Morpho Techologies MT processor";
2993 case EM_ALPHA
: return "Alpha";
2994 case EM_WEBASSEMBLY
: return "Web Assembly";
2995 case EM_DLX
: return "OpenDLX";
2996 case EM_XSTORMY16
: return "Sanyo XStormy16 CPU core";
2997 case EM_IQ2000
: return "Vitesse IQ2000";
2999 case EM_NIOS32
: return "Altera Nios";
3000 case EM_CYGNUS_MEP
: return "Toshiba MeP Media Engine";
3001 case EM_ADAPTEVA_EPIPHANY
: return "Adapteva EPIPHANY";
3002 case EM_CYGNUS_FRV
: return "Fujitsu FR-V";
3003 case EM_S12Z
: return "Freescale S12Z";
3006 snprintf (buff
, sizeof (buff
), _("<unknown>: 0x%x"), e_machine
);
3012 decode_ARC_machine_flags (unsigned e_flags
, unsigned e_machine
, char buf
[])
3014 /* ARC has two machine types EM_ARC_COMPACT and EM_ARC_COMPACT2. Some
3015 other compilers don't specify an architecture type in the e_flags, and
3016 instead use EM_ARC_COMPACT for old ARC600, ARC601, and ARC700
3017 architectures, and switch to EM_ARC_COMPACT2 for newer ARCEM and ARCHS
3020 Th GNU tools follows this use of EM_ARC_COMPACT and EM_ARC_COMPACT2,
3021 but also sets a specific architecture type in the e_flags field.
3023 However, when decoding the flags we don't worry if we see an
3024 unexpected pairing, for example EM_ARC_COMPACT machine type, with
3025 ARCEM architecture type. */
3027 switch (e_flags
& EF_ARC_MACH_MSK
)
3029 /* We only expect these to occur for EM_ARC_COMPACT2. */
3030 case EF_ARC_CPU_ARCV2EM
:
3031 strcat (buf
, ", ARC EM");
3033 case EF_ARC_CPU_ARCV2HS
:
3034 strcat (buf
, ", ARC HS");
3037 /* We only expect these to occur for EM_ARC_COMPACT. */
3038 case E_ARC_MACH_ARC600
:
3039 strcat (buf
, ", ARC600");
3041 case E_ARC_MACH_ARC601
:
3042 strcat (buf
, ", ARC601");
3044 case E_ARC_MACH_ARC700
:
3045 strcat (buf
, ", ARC700");
3048 /* The only times we should end up here are (a) A corrupt ELF, (b) A
3049 new ELF with new architecture being read by an old version of
3050 readelf, or (c) An ELF built with non-GNU compiler that does not
3051 set the architecture in the e_flags. */
3053 if (e_machine
== EM_ARC_COMPACT
)
3054 strcat (buf
, ", Unknown ARCompact");
3056 strcat (buf
, ", Unknown ARC");
3060 switch (e_flags
& EF_ARC_OSABI_MSK
)
3062 case E_ARC_OSABI_ORIG
:
3063 strcat (buf
, ", (ABI:legacy)");
3065 case E_ARC_OSABI_V2
:
3066 strcat (buf
, ", (ABI:v2)");
3068 /* Only upstream 3.9+ kernels will support ARCv2 ISA. */
3069 case E_ARC_OSABI_V3
:
3070 strcat (buf
, ", v3 no-legacy-syscalls ABI");
3072 case E_ARC_OSABI_V4
:
3073 strcat (buf
, ", v4 ABI");
3076 strcat (buf
, ", unrecognised ARC OSABI flag");
3082 decode_ARM_machine_flags (unsigned e_flags
, char buf
[])
3085 bool unknown
= false;
3087 eabi
= EF_ARM_EABI_VERSION (e_flags
);
3088 e_flags
&= ~ EF_ARM_EABIMASK
;
3090 /* Handle "generic" ARM flags. */
3091 if (e_flags
& EF_ARM_RELEXEC
)
3093 strcat (buf
, ", relocatable executable");
3094 e_flags
&= ~ EF_ARM_RELEXEC
;
3097 if (e_flags
& EF_ARM_PIC
)
3099 strcat (buf
, ", position independent");
3100 e_flags
&= ~ EF_ARM_PIC
;
3103 /* Now handle EABI specific flags. */
3107 strcat (buf
, ", <unrecognized EABI>");
3112 case EF_ARM_EABI_VER1
:
3113 strcat (buf
, ", Version1 EABI");
3118 /* Process flags one bit at a time. */
3119 flag
= e_flags
& - e_flags
;
3124 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
3125 strcat (buf
, ", sorted symbol tables");
3135 case EF_ARM_EABI_VER2
:
3136 strcat (buf
, ", Version2 EABI");
3141 /* Process flags one bit at a time. */
3142 flag
= e_flags
& - e_flags
;
3147 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
3148 strcat (buf
, ", sorted symbol tables");
3151 case EF_ARM_DYNSYMSUSESEGIDX
:
3152 strcat (buf
, ", dynamic symbols use segment index");
3155 case EF_ARM_MAPSYMSFIRST
:
3156 strcat (buf
, ", mapping symbols precede others");
3166 case EF_ARM_EABI_VER3
:
3167 strcat (buf
, ", Version3 EABI");
3170 case EF_ARM_EABI_VER4
:
3171 strcat (buf
, ", Version4 EABI");
3176 /* Process flags one bit at a time. */
3177 flag
= e_flags
& - e_flags
;
3183 strcat (buf
, ", BE8");
3187 strcat (buf
, ", LE8");
3197 case EF_ARM_EABI_VER5
:
3198 strcat (buf
, ", Version5 EABI");
3203 /* Process flags one bit at a time. */
3204 flag
= e_flags
& - e_flags
;
3210 strcat (buf
, ", BE8");
3214 strcat (buf
, ", LE8");
3217 case EF_ARM_ABI_FLOAT_SOFT
: /* Conflicts with EF_ARM_SOFT_FLOAT. */
3218 strcat (buf
, ", soft-float ABI");
3221 case EF_ARM_ABI_FLOAT_HARD
: /* Conflicts with EF_ARM_VFP_FLOAT. */
3222 strcat (buf
, ", hard-float ABI");
3232 case EF_ARM_EABI_UNKNOWN
:
3233 strcat (buf
, ", GNU EABI");
3238 /* Process flags one bit at a time. */
3239 flag
= e_flags
& - e_flags
;
3244 case EF_ARM_INTERWORK
:
3245 strcat (buf
, ", interworking enabled");
3248 case EF_ARM_APCS_26
:
3249 strcat (buf
, ", uses APCS/26");
3252 case EF_ARM_APCS_FLOAT
:
3253 strcat (buf
, ", uses APCS/float");
3257 strcat (buf
, ", position independent");
3261 strcat (buf
, ", 8 bit structure alignment");
3264 case EF_ARM_NEW_ABI
:
3265 strcat (buf
, ", uses new ABI");
3268 case EF_ARM_OLD_ABI
:
3269 strcat (buf
, ", uses old ABI");
3272 case EF_ARM_SOFT_FLOAT
:
3273 strcat (buf
, ", software FP");
3276 case EF_ARM_VFP_FLOAT
:
3277 strcat (buf
, ", VFP");
3280 case EF_ARM_MAVERICK_FLOAT
:
3281 strcat (buf
, ", Maverick FP");
3292 strcat (buf
,_(", <unknown>"));
3296 decode_AVR_machine_flags (unsigned e_flags
, char buf
[], size_t size
)
3298 --size
; /* Leave space for null terminator. */
3300 switch (e_flags
& EF_AVR_MACH
)
3302 case E_AVR_MACH_AVR1
:
3303 strncat (buf
, ", avr:1", size
);
3305 case E_AVR_MACH_AVR2
:
3306 strncat (buf
, ", avr:2", size
);
3308 case E_AVR_MACH_AVR25
:
3309 strncat (buf
, ", avr:25", size
);
3311 case E_AVR_MACH_AVR3
:
3312 strncat (buf
, ", avr:3", size
);
3314 case E_AVR_MACH_AVR31
:
3315 strncat (buf
, ", avr:31", size
);
3317 case E_AVR_MACH_AVR35
:
3318 strncat (buf
, ", avr:35", size
);
3320 case E_AVR_MACH_AVR4
:
3321 strncat (buf
, ", avr:4", size
);
3323 case E_AVR_MACH_AVR5
:
3324 strncat (buf
, ", avr:5", size
);
3326 case E_AVR_MACH_AVR51
:
3327 strncat (buf
, ", avr:51", size
);
3329 case E_AVR_MACH_AVR6
:
3330 strncat (buf
, ", avr:6", size
);
3332 case E_AVR_MACH_AVRTINY
:
3333 strncat (buf
, ", avr:100", size
);
3335 case E_AVR_MACH_XMEGA1
:
3336 strncat (buf
, ", avr:101", size
);
3338 case E_AVR_MACH_XMEGA2
:
3339 strncat (buf
, ", avr:102", size
);
3341 case E_AVR_MACH_XMEGA3
:
3342 strncat (buf
, ", avr:103", size
);
3344 case E_AVR_MACH_XMEGA4
:
3345 strncat (buf
, ", avr:104", size
);
3347 case E_AVR_MACH_XMEGA5
:
3348 strncat (buf
, ", avr:105", size
);
3350 case E_AVR_MACH_XMEGA6
:
3351 strncat (buf
, ", avr:106", size
);
3353 case E_AVR_MACH_XMEGA7
:
3354 strncat (buf
, ", avr:107", size
);
3357 strncat (buf
, ", avr:<unknown>", size
);
3361 size
-= strlen (buf
);
3362 if (e_flags
& EF_AVR_LINKRELAX_PREPARED
)
3363 strncat (buf
, ", link-relax", size
);
3367 decode_NDS32_machine_flags (unsigned e_flags
, char buf
[], size_t size
)
3373 bool has_fpu
= false;
3376 static const char *ABI_STRINGS
[] =
3378 "ABI v0", /* use r5 as return register; only used in N1213HC */
3379 "ABI v1", /* use r0 as return register */
3380 "ABI v2", /* use r0 as return register and don't reserve 24 bytes for arguments */
3381 "ABI v2fp", /* for FPU */
3385 static const char *VER_STRINGS
[] =
3387 "Andes ELF V1.3 or older",
3391 static const char *ARCH_STRINGS
[] =
3400 abi
= EF_NDS_ABI
& e_flags
;
3401 arch
= EF_NDS_ARCH
& e_flags
;
3402 config
= EF_NDS_INST
& e_flags
;
3403 version
= EF_NDS32_ELF_VERSION
& e_flags
;
3405 memset (buf
, 0, size
);
3412 case E_NDS_ABI_V2FP
:
3413 case E_NDS_ABI_AABI
:
3414 case E_NDS_ABI_V2FP_PLUS
:
3415 /* In case there are holes in the array. */
3416 r
+= snprintf (buf
+ r
, size
- r
, ", %s", ABI_STRINGS
[abi
>> EF_NDS_ABI_SHIFT
]);
3420 r
+= snprintf (buf
+ r
, size
- r
, ", <unrecognized ABI>");
3426 case E_NDS32_ELF_VER_1_2
:
3427 case E_NDS32_ELF_VER_1_3
:
3428 case E_NDS32_ELF_VER_1_4
:
3429 r
+= snprintf (buf
+ r
, size
- r
, ", %s", VER_STRINGS
[version
>> EF_NDS32_ELF_VERSION_SHIFT
]);
3433 r
+= snprintf (buf
+ r
, size
- r
, ", <unrecognized ELF version number>");
3437 if (E_NDS_ABI_V0
== abi
)
3439 /* OLD ABI; only used in N1213HC, has performance extension 1. */
3440 r
+= snprintf (buf
+ r
, size
- r
, ", Andes Star v1.0, N1213HC, MAC, PERF1");
3441 if (arch
== E_NDS_ARCH_STAR_V1_0
)
3442 r
+= snprintf (buf
+ r
, size
-r
, ", 16b"); /* has 16-bit instructions */
3448 case E_NDS_ARCH_STAR_V1_0
:
3449 case E_NDS_ARCH_STAR_V2_0
:
3450 case E_NDS_ARCH_STAR_V3_0
:
3451 case E_NDS_ARCH_STAR_V3_M
:
3452 r
+= snprintf (buf
+ r
, size
- r
, ", %s", ARCH_STRINGS
[arch
>> EF_NDS_ARCH_SHIFT
]);
3456 r
+= snprintf (buf
+ r
, size
- r
, ", <unrecognized architecture>");
3457 /* ARCH version determines how the e_flags are interpreted.
3458 If it is unknown, we cannot proceed. */
3462 /* Newer ABI; Now handle architecture specific flags. */
3463 if (arch
== E_NDS_ARCH_STAR_V1_0
)
3465 if (config
& E_NDS32_HAS_MFUSR_PC_INST
)
3466 r
+= snprintf (buf
+ r
, size
-r
, ", MFUSR_PC");
3468 if (!(config
& E_NDS32_HAS_NO_MAC_INST
))
3469 r
+= snprintf (buf
+ r
, size
-r
, ", MAC");
3471 if (config
& E_NDS32_HAS_DIV_INST
)
3472 r
+= snprintf (buf
+ r
, size
-r
, ", DIV");
3474 if (config
& E_NDS32_HAS_16BIT_INST
)
3475 r
+= snprintf (buf
+ r
, size
-r
, ", 16b");
3479 if (config
& E_NDS32_HAS_MFUSR_PC_INST
)
3481 if (version
<= E_NDS32_ELF_VER_1_3
)
3482 r
+= snprintf (buf
+ r
, size
-r
, ", [B8]");
3484 r
+= snprintf (buf
+ r
, size
-r
, ", EX9");
3487 if (config
& E_NDS32_HAS_MAC_DX_INST
)
3488 r
+= snprintf (buf
+ r
, size
-r
, ", MAC_DX");
3490 if (config
& E_NDS32_HAS_DIV_DX_INST
)
3491 r
+= snprintf (buf
+ r
, size
-r
, ", DIV_DX");
3493 if (config
& E_NDS32_HAS_16BIT_INST
)
3495 if (version
<= E_NDS32_ELF_VER_1_3
)
3496 r
+= snprintf (buf
+ r
, size
-r
, ", 16b");
3498 r
+= snprintf (buf
+ r
, size
-r
, ", IFC");
3502 if (config
& E_NDS32_HAS_EXT_INST
)
3503 r
+= snprintf (buf
+ r
, size
-r
, ", PERF1");
3505 if (config
& E_NDS32_HAS_EXT2_INST
)
3506 r
+= snprintf (buf
+ r
, size
-r
, ", PERF2");
3508 if (config
& E_NDS32_HAS_FPU_INST
)
3511 r
+= snprintf (buf
+ r
, size
-r
, ", FPU_SP");
3514 if (config
& E_NDS32_HAS_FPU_DP_INST
)
3517 r
+= snprintf (buf
+ r
, size
-r
, ", FPU_DP");
3520 if (config
& E_NDS32_HAS_FPU_MAC_INST
)
3523 r
+= snprintf (buf
+ r
, size
-r
, ", FPU_MAC");
3528 switch ((config
& E_NDS32_FPU_REG_CONF
) >> E_NDS32_FPU_REG_CONF_SHIFT
)
3530 case E_NDS32_FPU_REG_8SP_4DP
:
3531 r
+= snprintf (buf
+ r
, size
-r
, ", FPU_REG:8/4");
3533 case E_NDS32_FPU_REG_16SP_8DP
:
3534 r
+= snprintf (buf
+ r
, size
-r
, ", FPU_REG:16/8");
3536 case E_NDS32_FPU_REG_32SP_16DP
:
3537 r
+= snprintf (buf
+ r
, size
-r
, ", FPU_REG:32/16");
3539 case E_NDS32_FPU_REG_32SP_32DP
:
3540 r
+= snprintf (buf
+ r
, size
-r
, ", FPU_REG:32/32");
3545 if (config
& E_NDS32_HAS_AUDIO_INST
)
3546 r
+= snprintf (buf
+ r
, size
-r
, ", AUDIO");
3548 if (config
& E_NDS32_HAS_STRING_INST
)
3549 r
+= snprintf (buf
+ r
, size
-r
, ", STR");
3551 if (config
& E_NDS32_HAS_REDUCED_REGS
)
3552 r
+= snprintf (buf
+ r
, size
-r
, ", 16REG");
3554 if (config
& E_NDS32_HAS_VIDEO_INST
)
3556 if (version
<= E_NDS32_ELF_VER_1_3
)
3557 r
+= snprintf (buf
+ r
, size
-r
, ", VIDEO");
3559 r
+= snprintf (buf
+ r
, size
-r
, ", SATURATION");
3562 if (config
& E_NDS32_HAS_ENCRIPT_INST
)
3563 r
+= snprintf (buf
+ r
, size
-r
, ", ENCRP");
3565 if (config
& E_NDS32_HAS_L2C_INST
)
3566 r
+= snprintf (buf
+ r
, size
-r
, ", L2C");
3570 decode_AMDGPU_machine_flags (Filedata
*filedata
, unsigned int e_flags
,
3573 unsigned char *e_ident
= filedata
->file_header
.e_ident
;
3574 unsigned char osabi
= e_ident
[EI_OSABI
];
3575 unsigned char abiversion
= e_ident
[EI_ABIVERSION
];
3578 /* HSA OS ABI v2 used a different encoding, but we don't need to support it,
3579 it has been deprecated for a while.
3581 The PAL, MESA3D and NONE OS ABIs are not properly versioned, at the time
3582 of writing, they use the same flags as HSA v3, so the code below uses that
3584 if (osabi
== ELFOSABI_AMDGPU_HSA
&& abiversion
< ELFABIVERSION_AMDGPU_HSA_V3
)
3587 mach
= e_flags
& EF_AMDGPU_MACH
;
3590 #define AMDGPU_CASE(code, string) \
3591 case code: strcat (buf, ", " string); break;
3592 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX600
, "gfx600")
3593 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX601
, "gfx601")
3594 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX700
, "gfx700")
3595 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX701
, "gfx701")
3596 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX702
, "gfx702")
3597 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX703
, "gfx703")
3598 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX704
, "gfx704")
3599 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX801
, "gfx801")
3600 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX802
, "gfx802")
3601 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX803
, "gfx803")
3602 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX810
, "gfx810")
3603 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX900
, "gfx900")
3604 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX902
, "gfx902")
3605 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX904
, "gfx904")
3606 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX906
, "gfx906")
3607 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX908
, "gfx908")
3608 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX909
, "gfx909")
3609 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX90C
, "gfx90c")
3610 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1010
, "gfx1010")
3611 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1011
, "gfx1011")
3612 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1012
, "gfx1012")
3613 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1030
, "gfx1030")
3614 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1031
, "gfx1031")
3615 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1032
, "gfx1032")
3616 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1033
, "gfx1033")
3617 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX602
, "gfx602")
3618 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX705
, "gfx705")
3619 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX805
, "gfx805")
3620 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1035
, "gfx1035")
3621 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1034
, "gfx1034")
3622 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX90A
, "gfx90a")
3623 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX940
, "gfx940")
3624 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1013
, "gfx1013")
3625 AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1036
, "gfx1036")
3627 sprintf (buf
, _(", <unknown AMDGPU GPU type: %#x>"), mach
);
3632 buf
+= strlen (buf
);
3633 e_flags
&= ~EF_AMDGPU_MACH
;
3635 if ((osabi
== ELFOSABI_AMDGPU_HSA
3636 && abiversion
== ELFABIVERSION_AMDGPU_HSA_V3
)
3637 || osabi
!= ELFOSABI_AMDGPU_HSA
)
3639 /* For HSA v3 and other OS ABIs. */
3640 if (e_flags
& EF_AMDGPU_FEATURE_XNACK_V3
)
3642 strcat (buf
, ", xnack on");
3643 buf
+= strlen (buf
);
3644 e_flags
&= ~EF_AMDGPU_FEATURE_XNACK_V3
;
3647 if (e_flags
& EF_AMDGPU_FEATURE_SRAMECC_V3
)
3649 strcat (buf
, ", sramecc on");
3650 buf
+= strlen (buf
);
3651 e_flags
&= ~EF_AMDGPU_FEATURE_SRAMECC_V3
;
3659 xnack
= e_flags
& EF_AMDGPU_FEATURE_XNACK_V4
;
3662 case EF_AMDGPU_FEATURE_XNACK_UNSUPPORTED_V4
:
3665 case EF_AMDGPU_FEATURE_XNACK_ANY_V4
:
3666 strcat (buf
, ", xnack any");
3669 case EF_AMDGPU_FEATURE_XNACK_OFF_V4
:
3670 strcat (buf
, ", xnack off");
3673 case EF_AMDGPU_FEATURE_XNACK_ON_V4
:
3674 strcat (buf
, ", xnack on");
3678 sprintf (buf
, _(", <unknown xnack value: %#x>"), xnack
);
3682 buf
+= strlen (buf
);
3683 e_flags
&= ~EF_AMDGPU_FEATURE_XNACK_V4
;
3685 sramecc
= e_flags
& EF_AMDGPU_FEATURE_SRAMECC_V4
;
3688 case EF_AMDGPU_FEATURE_SRAMECC_UNSUPPORTED_V4
:
3691 case EF_AMDGPU_FEATURE_SRAMECC_ANY_V4
:
3692 strcat (buf
, ", sramecc any");
3695 case EF_AMDGPU_FEATURE_SRAMECC_OFF_V4
:
3696 strcat (buf
, ", sramecc off");
3699 case EF_AMDGPU_FEATURE_SRAMECC_ON_V4
:
3700 strcat (buf
, ", sramecc on");
3704 sprintf (buf
, _(", <unknown sramecc value: %#x>"), sramecc
);
3708 buf
+= strlen (buf
);
3709 e_flags
&= ~EF_AMDGPU_FEATURE_SRAMECC_V4
;
3713 sprintf (buf
, _(", unknown flags bits: %#x"), e_flags
);
3717 get_machine_flags (Filedata
* filedata
, unsigned e_flags
, unsigned e_machine
)
3719 static char buf
[1024];
3730 case EM_ARC_COMPACT2
:
3731 case EM_ARC_COMPACT
:
3732 decode_ARC_machine_flags (e_flags
, e_machine
, buf
);
3736 decode_ARM_machine_flags (e_flags
, buf
);
3740 decode_AVR_machine_flags (e_flags
, buf
, sizeof buf
);
3744 if (e_flags
& EF_BFIN_PIC
)
3745 strcat (buf
, ", PIC");
3747 if (e_flags
& EF_BFIN_FDPIC
)
3748 strcat (buf
, ", FDPIC");
3750 if (e_flags
& EF_BFIN_CODE_IN_L1
)
3751 strcat (buf
, ", code in L1");
3753 if (e_flags
& EF_BFIN_DATA_IN_L1
)
3754 strcat (buf
, ", data in L1");
3759 switch (e_flags
& EF_FRV_CPU_MASK
)
3761 case EF_FRV_CPU_GENERIC
:
3765 strcat (buf
, ", fr???");
3768 case EF_FRV_CPU_FR300
:
3769 strcat (buf
, ", fr300");
3772 case EF_FRV_CPU_FR400
:
3773 strcat (buf
, ", fr400");
3775 case EF_FRV_CPU_FR405
:
3776 strcat (buf
, ", fr405");
3779 case EF_FRV_CPU_FR450
:
3780 strcat (buf
, ", fr450");
3783 case EF_FRV_CPU_FR500
:
3784 strcat (buf
, ", fr500");
3786 case EF_FRV_CPU_FR550
:
3787 strcat (buf
, ", fr550");
3790 case EF_FRV_CPU_SIMPLE
:
3791 strcat (buf
, ", simple");
3793 case EF_FRV_CPU_TOMCAT
:
3794 strcat (buf
, ", tomcat");
3800 if ((e_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_M68000
)
3801 strcat (buf
, ", m68000");
3802 else if ((e_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_CPU32
)
3803 strcat (buf
, ", cpu32");
3804 else if ((e_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_FIDO
)
3805 strcat (buf
, ", fido_a");
3808 char const * isa
= _("unknown");
3809 char const * mac
= _("unknown mac");
3810 char const * additional
= NULL
;
3812 switch (e_flags
& EF_M68K_CF_ISA_MASK
)
3814 case EF_M68K_CF_ISA_A_NODIV
:
3816 additional
= ", nodiv";
3818 case EF_M68K_CF_ISA_A
:
3821 case EF_M68K_CF_ISA_A_PLUS
:
3824 case EF_M68K_CF_ISA_B_NOUSP
:
3826 additional
= ", nousp";
3828 case EF_M68K_CF_ISA_B
:
3831 case EF_M68K_CF_ISA_C
:
3834 case EF_M68K_CF_ISA_C_NODIV
:
3836 additional
= ", nodiv";
3839 strcat (buf
, ", cf, isa ");
3842 strcat (buf
, additional
);
3843 if (e_flags
& EF_M68K_CF_FLOAT
)
3844 strcat (buf
, ", float");
3845 switch (e_flags
& EF_M68K_CF_MAC_MASK
)
3850 case EF_M68K_CF_MAC
:
3853 case EF_M68K_CF_EMAC
:
3856 case EF_M68K_CF_EMAC_B
:
3869 decode_AMDGPU_machine_flags (filedata
, e_flags
, buf
);
3873 switch (e_flags
& EF_MEP_CPU_MASK
)
3875 case EF_MEP_CPU_MEP
: strcat (buf
, ", generic MeP"); break;
3876 case EF_MEP_CPU_C2
: strcat (buf
, ", MeP C2"); break;
3877 case EF_MEP_CPU_C3
: strcat (buf
, ", MeP C3"); break;
3878 case EF_MEP_CPU_C4
: strcat (buf
, ", MeP C4"); break;
3879 case EF_MEP_CPU_C5
: strcat (buf
, ", MeP C5"); break;
3880 case EF_MEP_CPU_H1
: strcat (buf
, ", MeP H1"); break;
3881 default: strcat (buf
, _(", <unknown MeP cpu type>")); break;
3884 switch (e_flags
& EF_MEP_COP_MASK
)
3886 case EF_MEP_COP_NONE
: break;
3887 case EF_MEP_COP_AVC
: strcat (buf
, ", AVC coprocessor"); break;
3888 case EF_MEP_COP_AVC2
: strcat (buf
, ", AVC2 coprocessor"); break;
3889 case EF_MEP_COP_FMAX
: strcat (buf
, ", FMAX coprocessor"); break;
3890 case EF_MEP_COP_IVC2
: strcat (buf
, ", IVC2 coprocessor"); break;
3891 default: strcat (buf
, _("<unknown MeP copro type>")); break;
3894 if (e_flags
& EF_MEP_LIBRARY
)
3895 strcat (buf
, ", Built for Library");
3897 if (e_flags
& EF_MEP_INDEX_MASK
)
3898 sprintf (buf
+ strlen (buf
), ", Configuration Index: %#x",
3899 e_flags
& EF_MEP_INDEX_MASK
);
3901 if (e_flags
& ~ EF_MEP_ALL_FLAGS
)
3902 sprintf (buf
+ strlen (buf
), _(", unknown flags bits: %#x"),
3903 e_flags
& ~ EF_MEP_ALL_FLAGS
);
3907 if (e_flags
& EF_PPC_EMB
)
3908 strcat (buf
, ", emb");
3910 if (e_flags
& EF_PPC_RELOCATABLE
)
3911 strcat (buf
, _(", relocatable"));
3913 if (e_flags
& EF_PPC_RELOCATABLE_LIB
)
3914 strcat (buf
, _(", relocatable-lib"));
3918 if (e_flags
& EF_PPC64_ABI
)
3920 char abi
[] = ", abiv0";
3922 abi
[6] += e_flags
& EF_PPC64_ABI
;
3928 if ((e_flags
& EF_RH850_ABI
) == EF_RH850_ABI
)
3929 strcat (buf
, ", RH850 ABI");
3931 if (e_flags
& EF_V800_850E3
)
3932 strcat (buf
, ", V3 architecture");
3934 if ((e_flags
& (EF_RH850_FPU_DOUBLE
| EF_RH850_FPU_SINGLE
)) == 0)
3935 strcat (buf
, ", FPU not used");
3937 if ((e_flags
& (EF_RH850_REGMODE22
| EF_RH850_REGMODE32
)) == 0)
3938 strcat (buf
, ", regmode: COMMON");
3940 if ((e_flags
& (EF_RH850_GP_FIX
| EF_RH850_GP_NOFIX
)) == 0)
3941 strcat (buf
, ", r4 not used");
3943 if ((e_flags
& (EF_RH850_EP_FIX
| EF_RH850_EP_NOFIX
)) == 0)
3944 strcat (buf
, ", r30 not used");
3946 if ((e_flags
& (EF_RH850_TP_FIX
| EF_RH850_TP_NOFIX
)) == 0)
3947 strcat (buf
, ", r5 not used");
3949 if ((e_flags
& (EF_RH850_REG2_RESERVE
| EF_RH850_REG2_NORESERVE
)) == 0)
3950 strcat (buf
, ", r2 not used");
3952 for (e_flags
&= 0xFFFF; e_flags
; e_flags
&= ~ (e_flags
& - e_flags
))
3954 switch (e_flags
& - e_flags
)
3956 case EF_RH850_FPU_DOUBLE
: strcat (buf
, ", double precision FPU"); break;
3957 case EF_RH850_FPU_SINGLE
: strcat (buf
, ", single precision FPU"); break;
3958 case EF_RH850_REGMODE22
: strcat (buf
, ", regmode:22"); break;
3959 case EF_RH850_REGMODE32
: strcat (buf
, ", regmode:23"); break;
3960 case EF_RH850_GP_FIX
: strcat (buf
, ", r4 fixed"); break;
3961 case EF_RH850_GP_NOFIX
: strcat (buf
, ", r4 free"); break;
3962 case EF_RH850_EP_FIX
: strcat (buf
, ", r30 fixed"); break;
3963 case EF_RH850_EP_NOFIX
: strcat (buf
, ", r30 free"); break;
3964 case EF_RH850_TP_FIX
: strcat (buf
, ", r5 fixed"); break;
3965 case EF_RH850_TP_NOFIX
: strcat (buf
, ", r5 free"); break;
3966 case EF_RH850_REG2_RESERVE
: strcat (buf
, ", r2 fixed"); break;
3967 case EF_RH850_REG2_NORESERVE
: strcat (buf
, ", r2 free"); break;
3974 case EM_CYGNUS_V850
:
3975 switch (e_flags
& EF_V850_ARCH
)
3977 case E_V850E3V5_ARCH
:
3978 strcat (buf
, ", v850e3v5");
3980 case E_V850E2V3_ARCH
:
3981 strcat (buf
, ", v850e2v3");
3984 strcat (buf
, ", v850e2");
3987 strcat (buf
, ", v850e1");
3990 strcat (buf
, ", v850e");
3993 strcat (buf
, ", v850");
3996 strcat (buf
, _(", unknown v850 architecture variant"));
4002 case EM_CYGNUS_M32R
:
4003 if ((e_flags
& EF_M32R_ARCH
) == E_M32R_ARCH
)
4004 strcat (buf
, ", m32r");
4008 case EM_MIPS_RS3_LE
:
4009 if (e_flags
& EF_MIPS_NOREORDER
)
4010 strcat (buf
, ", noreorder");
4012 if (e_flags
& EF_MIPS_PIC
)
4013 strcat (buf
, ", pic");
4015 if (e_flags
& EF_MIPS_CPIC
)
4016 strcat (buf
, ", cpic");
4018 if (e_flags
& EF_MIPS_UCODE
)
4019 strcat (buf
, ", ugen_reserved");
4021 if (e_flags
& EF_MIPS_ABI2
)
4022 strcat (buf
, ", abi2");
4024 if (e_flags
& EF_MIPS_OPTIONS_FIRST
)
4025 strcat (buf
, ", odk first");
4027 if (e_flags
& EF_MIPS_32BITMODE
)
4028 strcat (buf
, ", 32bitmode");
4030 if (e_flags
& EF_MIPS_NAN2008
)
4031 strcat (buf
, ", nan2008");
4033 if (e_flags
& EF_MIPS_FP64
)
4034 strcat (buf
, ", fp64");
4036 switch ((e_flags
& EF_MIPS_MACH
))
4038 case E_MIPS_MACH_3900
: strcat (buf
, ", 3900"); break;
4039 case E_MIPS_MACH_4010
: strcat (buf
, ", 4010"); break;
4040 case E_MIPS_MACH_4100
: strcat (buf
, ", 4100"); break;
4041 case E_MIPS_MACH_4111
: strcat (buf
, ", 4111"); break;
4042 case E_MIPS_MACH_4120
: strcat (buf
, ", 4120"); break;
4043 case E_MIPS_MACH_4650
: strcat (buf
, ", 4650"); break;
4044 case E_MIPS_MACH_5400
: strcat (buf
, ", 5400"); break;
4045 case E_MIPS_MACH_5500
: strcat (buf
, ", 5500"); break;
4046 case E_MIPS_MACH_5900
: strcat (buf
, ", 5900"); break;
4047 case E_MIPS_MACH_SB1
: strcat (buf
, ", sb1"); break;
4048 case E_MIPS_MACH_9000
: strcat (buf
, ", 9000"); break;
4049 case E_MIPS_MACH_LS2E
: strcat (buf
, ", loongson-2e"); break;
4050 case E_MIPS_MACH_LS2F
: strcat (buf
, ", loongson-2f"); break;
4051 case E_MIPS_MACH_GS464
: strcat (buf
, ", gs464"); break;
4052 case E_MIPS_MACH_GS464E
: strcat (buf
, ", gs464e"); break;
4053 case E_MIPS_MACH_GS264E
: strcat (buf
, ", gs264e"); break;
4054 case E_MIPS_MACH_OCTEON
: strcat (buf
, ", octeon"); break;
4055 case E_MIPS_MACH_OCTEON2
: strcat (buf
, ", octeon2"); break;
4056 case E_MIPS_MACH_OCTEON3
: strcat (buf
, ", octeon3"); break;
4057 case E_MIPS_MACH_XLR
: strcat (buf
, ", xlr"); break;
4058 case E_MIPS_MACH_IAMR2
: strcat (buf
, ", interaptiv-mr2"); break;
4060 /* We simply ignore the field in this case to avoid confusion:
4061 MIPS ELF does not specify EF_MIPS_MACH, it is a GNU
4064 default: strcat (buf
, _(", unknown CPU")); break;
4067 switch ((e_flags
& EF_MIPS_ABI
))
4069 case E_MIPS_ABI_O32
: strcat (buf
, ", o32"); break;
4070 case E_MIPS_ABI_O64
: strcat (buf
, ", o64"); break;
4071 case E_MIPS_ABI_EABI32
: strcat (buf
, ", eabi32"); break;
4072 case E_MIPS_ABI_EABI64
: strcat (buf
, ", eabi64"); break;
4074 /* We simply ignore the field in this case to avoid confusion:
4075 MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension.
4076 This means it is likely to be an o32 file, but not for
4079 default: strcat (buf
, _(", unknown ABI")); break;
4082 if (e_flags
& EF_MIPS_ARCH_ASE_MDMX
)
4083 strcat (buf
, ", mdmx");
4085 if (e_flags
& EF_MIPS_ARCH_ASE_M16
)
4086 strcat (buf
, ", mips16");
4088 if (e_flags
& EF_MIPS_ARCH_ASE_MICROMIPS
)
4089 strcat (buf
, ", micromips");
4091 switch ((e_flags
& EF_MIPS_ARCH
))
4093 case E_MIPS_ARCH_1
: strcat (buf
, ", mips1"); break;
4094 case E_MIPS_ARCH_2
: strcat (buf
, ", mips2"); break;
4095 case E_MIPS_ARCH_3
: strcat (buf
, ", mips3"); break;
4096 case E_MIPS_ARCH_4
: strcat (buf
, ", mips4"); break;
4097 case E_MIPS_ARCH_5
: strcat (buf
, ", mips5"); break;
4098 case E_MIPS_ARCH_32
: strcat (buf
, ", mips32"); break;
4099 case E_MIPS_ARCH_32R2
: strcat (buf
, ", mips32r2"); break;
4100 case E_MIPS_ARCH_32R6
: strcat (buf
, ", mips32r6"); break;
4101 case E_MIPS_ARCH_64
: strcat (buf
, ", mips64"); break;
4102 case E_MIPS_ARCH_64R2
: strcat (buf
, ", mips64r2"); break;
4103 case E_MIPS_ARCH_64R6
: strcat (buf
, ", mips64r6"); break;
4104 default: strcat (buf
, _(", unknown ISA")); break;
4109 decode_NDS32_machine_flags (e_flags
, buf
, sizeof buf
);
4113 switch (EF_NFP_MACH (e_flags
))
4115 case E_NFP_MACH_3200
:
4116 strcat (buf
, ", NFP-32xx");
4118 case E_NFP_MACH_6000
:
4119 strcat (buf
, ", NFP-6xxx");
4125 if (e_flags
& EF_RISCV_RVC
)
4126 strcat (buf
, ", RVC");
4128 if (e_flags
& EF_RISCV_RVE
)
4129 strcat (buf
, ", RVE");
4131 switch (e_flags
& EF_RISCV_FLOAT_ABI
)
4133 case EF_RISCV_FLOAT_ABI_SOFT
:
4134 strcat (buf
, ", soft-float ABI");
4137 case EF_RISCV_FLOAT_ABI_SINGLE
:
4138 strcat (buf
, ", single-float ABI");
4141 case EF_RISCV_FLOAT_ABI_DOUBLE
:
4142 strcat (buf
, ", double-float ABI");
4145 case EF_RISCV_FLOAT_ABI_QUAD
:
4146 strcat (buf
, ", quad-float ABI");
4152 switch ((e_flags
& EF_SH_MACH_MASK
))
4154 case EF_SH1
: strcat (buf
, ", sh1"); break;
4155 case EF_SH2
: strcat (buf
, ", sh2"); break;
4156 case EF_SH3
: strcat (buf
, ", sh3"); break;
4157 case EF_SH_DSP
: strcat (buf
, ", sh-dsp"); break;
4158 case EF_SH3_DSP
: strcat (buf
, ", sh3-dsp"); break;
4159 case EF_SH4AL_DSP
: strcat (buf
, ", sh4al-dsp"); break;
4160 case EF_SH3E
: strcat (buf
, ", sh3e"); break;
4161 case EF_SH4
: strcat (buf
, ", sh4"); break;
4162 case EF_SH5
: strcat (buf
, ", sh5"); break;
4163 case EF_SH2E
: strcat (buf
, ", sh2e"); break;
4164 case EF_SH4A
: strcat (buf
, ", sh4a"); break;
4165 case EF_SH2A
: strcat (buf
, ", sh2a"); break;
4166 case EF_SH4_NOFPU
: strcat (buf
, ", sh4-nofpu"); break;
4167 case EF_SH4A_NOFPU
: strcat (buf
, ", sh4a-nofpu"); break;
4168 case EF_SH2A_NOFPU
: strcat (buf
, ", sh2a-nofpu"); break;
4169 case EF_SH3_NOMMU
: strcat (buf
, ", sh3-nommu"); break;
4170 case EF_SH4_NOMMU_NOFPU
: strcat (buf
, ", sh4-nommu-nofpu"); break;
4171 case EF_SH2A_SH4_NOFPU
: strcat (buf
, ", sh2a-nofpu-or-sh4-nommu-nofpu"); break;
4172 case EF_SH2A_SH3_NOFPU
: strcat (buf
, ", sh2a-nofpu-or-sh3-nommu"); break;
4173 case EF_SH2A_SH4
: strcat (buf
, ", sh2a-or-sh4"); break;
4174 case EF_SH2A_SH3E
: strcat (buf
, ", sh2a-or-sh3e"); break;
4175 default: strcat (buf
, _(", unknown ISA")); break;
4178 if (e_flags
& EF_SH_PIC
)
4179 strcat (buf
, ", pic");
4181 if (e_flags
& EF_SH_FDPIC
)
4182 strcat (buf
, ", fdpic");
4186 if (e_flags
& EF_OR1K_NODELAY
)
4187 strcat (buf
, ", no delay");
4191 if (e_flags
& EF_SPARC_32PLUS
)
4192 strcat (buf
, ", v8+");
4194 if (e_flags
& EF_SPARC_SUN_US1
)
4195 strcat (buf
, ", ultrasparcI");
4197 if (e_flags
& EF_SPARC_SUN_US3
)
4198 strcat (buf
, ", ultrasparcIII");
4200 if (e_flags
& EF_SPARC_HAL_R1
)
4201 strcat (buf
, ", halr1");
4203 if (e_flags
& EF_SPARC_LEDATA
)
4204 strcat (buf
, ", ledata");
4206 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_TSO
)
4207 strcat (buf
, ", tso");
4209 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_PSO
)
4210 strcat (buf
, ", pso");
4212 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_RMO
)
4213 strcat (buf
, ", rmo");
4217 switch (e_flags
& EF_PARISC_ARCH
)
4219 case EFA_PARISC_1_0
:
4220 strcpy (buf
, ", PA-RISC 1.0");
4222 case EFA_PARISC_1_1
:
4223 strcpy (buf
, ", PA-RISC 1.1");
4225 case EFA_PARISC_2_0
:
4226 strcpy (buf
, ", PA-RISC 2.0");
4231 if (e_flags
& EF_PARISC_TRAPNIL
)
4232 strcat (buf
, ", trapnil");
4233 if (e_flags
& EF_PARISC_EXT
)
4234 strcat (buf
, ", ext");
4235 if (e_flags
& EF_PARISC_LSB
)
4236 strcat (buf
, ", lsb");
4237 if (e_flags
& EF_PARISC_WIDE
)
4238 strcat (buf
, ", wide");
4239 if (e_flags
& EF_PARISC_NO_KABP
)
4240 strcat (buf
, ", no kabp");
4241 if (e_flags
& EF_PARISC_LAZYSWAP
)
4242 strcat (buf
, ", lazyswap");
4247 if ((e_flags
& EF_PICOJAVA_NEWCALLS
) == EF_PICOJAVA_NEWCALLS
)
4248 strcat (buf
, ", new calling convention");
4250 if ((e_flags
& EF_PICOJAVA_GNUCALLS
) == EF_PICOJAVA_GNUCALLS
)
4251 strcat (buf
, ", gnu calling convention");
4255 if ((e_flags
& EF_IA_64_ABI64
))
4256 strcat (buf
, ", 64-bit");
4258 strcat (buf
, ", 32-bit");
4259 if ((e_flags
& EF_IA_64_REDUCEDFP
))
4260 strcat (buf
, ", reduced fp model");
4261 if ((e_flags
& EF_IA_64_NOFUNCDESC_CONS_GP
))
4262 strcat (buf
, ", no function descriptors, constant gp");
4263 else if ((e_flags
& EF_IA_64_CONS_GP
))
4264 strcat (buf
, ", constant gp");
4265 if ((e_flags
& EF_IA_64_ABSOLUTE
))
4266 strcat (buf
, ", absolute");
4267 if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_OPENVMS
)
4269 if ((e_flags
& EF_IA_64_VMS_LINKAGES
))
4270 strcat (buf
, ", vms_linkages");
4271 switch ((e_flags
& EF_IA_64_VMS_COMCOD
))
4273 case EF_IA_64_VMS_COMCOD_SUCCESS
:
4275 case EF_IA_64_VMS_COMCOD_WARNING
:
4276 strcat (buf
, ", warning");
4278 case EF_IA_64_VMS_COMCOD_ERROR
:
4279 strcat (buf
, ", error");
4281 case EF_IA_64_VMS_COMCOD_ABORT
:
4282 strcat (buf
, ", abort");
4285 warn (_("Unrecognised IA64 VMS Command Code: %x\n"),
4286 e_flags
& EF_IA_64_VMS_COMCOD
);
4287 strcat (buf
, ", <unknown>");
4293 if ((e_flags
& EF_VAX_NONPIC
))
4294 strcat (buf
, ", non-PIC");
4295 if ((e_flags
& EF_VAX_DFLOAT
))
4296 strcat (buf
, ", D-Float");
4297 if ((e_flags
& EF_VAX_GFLOAT
))
4298 strcat (buf
, ", G-Float");
4302 if (e_flags
& EF_VISIUM_ARCH_MCM
)
4303 strcat (buf
, ", mcm");
4304 else if (e_flags
& EF_VISIUM_ARCH_MCM24
)
4305 strcat (buf
, ", mcm24");
4306 if (e_flags
& EF_VISIUM_ARCH_GR6
)
4307 strcat (buf
, ", gr6");
4311 switch (e_flags
& E_FLAG_RL78_CPU_MASK
)
4313 case E_FLAG_RL78_ANY_CPU
: break;
4314 case E_FLAG_RL78_G10
: strcat (buf
, ", G10"); break;
4315 case E_FLAG_RL78_G13
: strcat (buf
, ", G13"); break;
4316 case E_FLAG_RL78_G14
: strcat (buf
, ", G14"); break;
4318 if (e_flags
& E_FLAG_RL78_64BIT_DOUBLES
)
4319 strcat (buf
, ", 64-bit doubles");
4323 if (e_flags
& E_FLAG_RX_64BIT_DOUBLES
)
4324 strcat (buf
, ", 64-bit doubles");
4325 if (e_flags
& E_FLAG_RX_DSP
)
4326 strcat (buf
, ", dsp");
4327 if (e_flags
& E_FLAG_RX_PID
)
4328 strcat (buf
, ", pid");
4329 if (e_flags
& E_FLAG_RX_ABI
)
4330 strcat (buf
, ", RX ABI");
4331 if (e_flags
& E_FLAG_RX_SINSNS_SET
)
4332 strcat (buf
, e_flags
& E_FLAG_RX_SINSNS_YES
4333 ? ", uses String instructions" : ", bans String instructions");
4334 if (e_flags
& E_FLAG_RX_V2
)
4335 strcat (buf
, ", V2");
4336 if (e_flags
& E_FLAG_RX_V3
)
4337 strcat (buf
, ", V3");
4341 if (e_flags
& EF_S390_HIGH_GPRS
)
4342 strcat (buf
, ", highgprs");
4346 if ((e_flags
& EF_C6000_REL
))
4347 strcat (buf
, ", relocatable module");
4351 strcat (buf
, _(": architecture variant: "));
4352 switch (e_flags
& EF_MSP430_MACH
)
4354 case E_MSP430_MACH_MSP430x11
: strcat (buf
, "MSP430x11"); break;
4355 case E_MSP430_MACH_MSP430x11x1
: strcat (buf
, "MSP430x11x1 "); break;
4356 case E_MSP430_MACH_MSP430x12
: strcat (buf
, "MSP430x12"); break;
4357 case E_MSP430_MACH_MSP430x13
: strcat (buf
, "MSP430x13"); break;
4358 case E_MSP430_MACH_MSP430x14
: strcat (buf
, "MSP430x14"); break;
4359 case E_MSP430_MACH_MSP430x15
: strcat (buf
, "MSP430x15"); break;
4360 case E_MSP430_MACH_MSP430x16
: strcat (buf
, "MSP430x16"); break;
4361 case E_MSP430_MACH_MSP430x31
: strcat (buf
, "MSP430x31"); break;
4362 case E_MSP430_MACH_MSP430x32
: strcat (buf
, "MSP430x32"); break;
4363 case E_MSP430_MACH_MSP430x33
: strcat (buf
, "MSP430x33"); break;
4364 case E_MSP430_MACH_MSP430x41
: strcat (buf
, "MSP430x41"); break;
4365 case E_MSP430_MACH_MSP430x42
: strcat (buf
, "MSP430x42"); break;
4366 case E_MSP430_MACH_MSP430x43
: strcat (buf
, "MSP430x43"); break;
4367 case E_MSP430_MACH_MSP430x44
: strcat (buf
, "MSP430x44"); break;
4368 case E_MSP430_MACH_MSP430X
: strcat (buf
, "MSP430X"); break;
4370 strcat (buf
, _(": unknown")); break;
4373 if (e_flags
& ~ EF_MSP430_MACH
)
4374 strcat (buf
, _(": unknown extra flag bits also present"));
4378 switch (e_flags
& EF_Z80_MACH_MSK
)
4380 case EF_Z80_MACH_Z80
: strcat (buf
, ", Z80"); break;
4381 case EF_Z80_MACH_Z180
: strcat (buf
, ", Z180"); break;
4382 case EF_Z80_MACH_R800
: strcat (buf
, ", R800"); break;
4383 case EF_Z80_MACH_EZ80_Z80
: strcat (buf
, ", EZ80"); break;
4384 case EF_Z80_MACH_EZ80_ADL
: strcat (buf
, ", EZ80, ADL"); break;
4385 case EF_Z80_MACH_GBZ80
: strcat (buf
, ", GBZ80"); break;
4386 case EF_Z80_MACH_Z80N
: strcat (buf
, ", Z80N"); break;
4388 strcat (buf
, _(", unknown")); break;
4392 if (EF_LOONGARCH_IS_LP64 (e_flags
))
4393 strcat (buf
, ", LP64");
4394 else if (EF_LOONGARCH_IS_ILP32 (e_flags
))
4395 strcat (buf
, ", ILP32");
4397 if (EF_LOONGARCH_IS_SOFT_FLOAT (e_flags
))
4398 strcat (buf
, ", SOFT-FLOAT");
4399 else if (EF_LOONGARCH_IS_SINGLE_FLOAT (e_flags
))
4400 strcat (buf
, ", SINGLE-FLOAT");
4401 else if (EF_LOONGARCH_IS_DOUBLE_FLOAT (e_flags
))
4402 strcat (buf
, ", DOUBLE-FLOAT");
4412 get_osabi_name (Filedata
* filedata
, unsigned int osabi
)
4414 static char buff
[32];
4418 case ELFOSABI_NONE
: return "UNIX - System V";
4419 case ELFOSABI_HPUX
: return "UNIX - HP-UX";
4420 case ELFOSABI_NETBSD
: return "UNIX - NetBSD";
4421 case ELFOSABI_GNU
: return "UNIX - GNU";
4422 case ELFOSABI_SOLARIS
: return "UNIX - Solaris";
4423 case ELFOSABI_AIX
: return "UNIX - AIX";
4424 case ELFOSABI_IRIX
: return "UNIX - IRIX";
4425 case ELFOSABI_FREEBSD
: return "UNIX - FreeBSD";
4426 case ELFOSABI_TRU64
: return "UNIX - TRU64";
4427 case ELFOSABI_MODESTO
: return "Novell - Modesto";
4428 case ELFOSABI_OPENBSD
: return "UNIX - OpenBSD";
4429 case ELFOSABI_OPENVMS
: return "VMS - OpenVMS";
4430 case ELFOSABI_NSK
: return "HP - Non-Stop Kernel";
4431 case ELFOSABI_AROS
: return "AROS";
4432 case ELFOSABI_FENIXOS
: return "FenixOS";
4433 case ELFOSABI_CLOUDABI
: return "Nuxi CloudABI";
4434 case ELFOSABI_OPENVOS
: return "Stratus Technologies OpenVOS";
4437 switch (filedata
->file_header
.e_machine
)
4442 case ELFOSABI_AMDGPU_HSA
: return "AMD HSA";
4443 case ELFOSABI_AMDGPU_PAL
: return "AMD PAL";
4444 case ELFOSABI_AMDGPU_MESA3D
: return "AMD Mesa3D";
4453 case ELFOSABI_ARM
: return "ARM";
4454 case ELFOSABI_ARM_FDPIC
: return "ARM FDPIC";
4465 case ELFOSABI_STANDALONE
: return _("Standalone App");
4474 case ELFOSABI_C6000_ELFABI
: return _("Bare-metal C6000");
4475 case ELFOSABI_C6000_LINUX
: return "Linux C6000";
4484 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), osabi
);
4490 get_aarch64_segment_type (unsigned long type
)
4494 case PT_AARCH64_ARCHEXT
: return "AARCH64_ARCHEXT";
4495 default: return NULL
;
4500 get_arm_segment_type (unsigned long type
)
4504 case PT_ARM_EXIDX
: return "EXIDX";
4505 default: return NULL
;
4510 get_s390_segment_type (unsigned long type
)
4514 case PT_S390_PGSTE
: return "S390_PGSTE";
4515 default: return NULL
;
4520 get_mips_segment_type (unsigned long type
)
4524 case PT_MIPS_REGINFO
: return "REGINFO";
4525 case PT_MIPS_RTPROC
: return "RTPROC";
4526 case PT_MIPS_OPTIONS
: return "OPTIONS";
4527 case PT_MIPS_ABIFLAGS
: return "ABIFLAGS";
4528 default: return NULL
;
4533 get_parisc_segment_type (unsigned long type
)
4537 case PT_PARISC_ARCHEXT
: return "PARISC_ARCHEXT";
4538 case PT_PARISC_UNWIND
: return "PARISC_UNWIND";
4539 case PT_PARISC_WEAKORDER
: return "PARISC_WEAKORDER";
4540 default: return NULL
;
4545 get_ia64_segment_type (unsigned long type
)
4549 case PT_IA_64_ARCHEXT
: return "IA_64_ARCHEXT";
4550 case PT_IA_64_UNWIND
: return "IA_64_UNWIND";
4551 default: return NULL
;
4556 get_tic6x_segment_type (unsigned long type
)
4560 case PT_C6000_PHATTR
: return "C6000_PHATTR";
4561 default: return NULL
;
4566 get_riscv_segment_type (unsigned long type
)
4570 case PT_RISCV_ATTRIBUTES
: return "RISCV_ATTRIBUTES";
4571 default: return NULL
;
4576 get_hpux_segment_type (unsigned long type
, unsigned e_machine
)
4578 if (e_machine
== EM_PARISC
)
4581 case PT_HP_TLS
: return "HP_TLS";
4582 case PT_HP_CORE_NONE
: return "HP_CORE_NONE";
4583 case PT_HP_CORE_VERSION
: return "HP_CORE_VERSION";
4584 case PT_HP_CORE_KERNEL
: return "HP_CORE_KERNEL";
4585 case PT_HP_CORE_COMM
: return "HP_CORE_COMM";
4586 case PT_HP_CORE_PROC
: return "HP_CORE_PROC";
4587 case PT_HP_CORE_LOADABLE
: return "HP_CORE_LOADABLE";
4588 case PT_HP_CORE_STACK
: return "HP_CORE_STACK";
4589 case PT_HP_CORE_SHM
: return "HP_CORE_SHM";
4590 case PT_HP_CORE_MMF
: return "HP_CORE_MMF";
4591 case PT_HP_PARALLEL
: return "HP_PARALLEL";
4592 case PT_HP_FASTBIND
: return "HP_FASTBIND";
4593 case PT_HP_OPT_ANNOT
: return "HP_OPT_ANNOT";
4594 case PT_HP_HSL_ANNOT
: return "HP_HSL_ANNOT";
4595 case PT_HP_STACK
: return "HP_STACK";
4596 case PT_HP_CORE_UTSNAME
: return "HP_CORE_UTSNAME";
4597 default: return NULL
;
4600 if (e_machine
== EM_IA_64
)
4603 case PT_HP_TLS
: return "HP_TLS";
4604 case PT_IA_64_HP_OPT_ANOT
: return "HP_OPT_ANNOT";
4605 case PT_IA_64_HP_HSL_ANOT
: return "HP_HSL_ANNOT";
4606 case PT_IA_64_HP_STACK
: return "HP_STACK";
4607 default: return NULL
;
4614 get_solaris_segment_type (unsigned long type
)
4618 case 0x6464e550: return "PT_SUNW_UNWIND";
4619 case 0x6474e550: return "PT_SUNW_EH_FRAME";
4620 case 0x6ffffff7: return "PT_LOSUNW";
4621 case 0x6ffffffa: return "PT_SUNWBSS";
4622 case 0x6ffffffb: return "PT_SUNWSTACK";
4623 case 0x6ffffffc: return "PT_SUNWDTRACE";
4624 case 0x6ffffffd: return "PT_SUNWCAP";
4625 case 0x6fffffff: return "PT_HISUNW";
4626 default: return NULL
;
4631 get_segment_type (Filedata
* filedata
, unsigned long p_type
)
4633 static char buff
[32];
4637 case PT_NULL
: return "NULL";
4638 case PT_LOAD
: return "LOAD";
4639 case PT_DYNAMIC
: return "DYNAMIC";
4640 case PT_INTERP
: return "INTERP";
4641 case PT_NOTE
: return "NOTE";
4642 case PT_SHLIB
: return "SHLIB";
4643 case PT_PHDR
: return "PHDR";
4644 case PT_TLS
: return "TLS";
4645 case PT_GNU_EH_FRAME
: return "GNU_EH_FRAME";
4646 case PT_GNU_STACK
: return "GNU_STACK";
4647 case PT_GNU_RELRO
: return "GNU_RELRO";
4648 case PT_GNU_PROPERTY
: return "GNU_PROPERTY";
4650 case PT_OPENBSD_RANDOMIZE
: return "OPENBSD_RANDOMIZE";
4651 case PT_OPENBSD_WXNEEDED
: return "OPENBSD_WXNEEDED";
4652 case PT_OPENBSD_BOOTDATA
: return "OPENBSD_BOOTDATA";
4655 if ((p_type
>= PT_LOPROC
) && (p_type
<= PT_HIPROC
))
4657 const char * result
;
4659 switch (filedata
->file_header
.e_machine
)
4662 result
= get_aarch64_segment_type (p_type
);
4665 result
= get_arm_segment_type (p_type
);
4668 case EM_MIPS_RS3_LE
:
4669 result
= get_mips_segment_type (p_type
);
4672 result
= get_parisc_segment_type (p_type
);
4675 result
= get_ia64_segment_type (p_type
);
4678 result
= get_tic6x_segment_type (p_type
);
4682 result
= get_s390_segment_type (p_type
);
4685 result
= get_riscv_segment_type (p_type
);
4695 sprintf (buff
, "LOPROC+%#lx", p_type
- PT_LOPROC
);
4697 else if ((p_type
>= PT_LOOS
) && (p_type
<= PT_HIOS
))
4699 const char * result
= NULL
;
4701 switch (filedata
->file_header
.e_ident
[EI_OSABI
])
4704 case ELFOSABI_FREEBSD
:
4705 if (p_type
>= PT_GNU_MBIND_LO
&& p_type
<= PT_GNU_MBIND_HI
)
4707 sprintf (buff
, "GNU_MBIND+%#lx", p_type
- PT_GNU_MBIND_LO
);
4712 result
= get_hpux_segment_type (p_type
,
4713 filedata
->file_header
.e_machine
);
4715 case ELFOSABI_SOLARIS
:
4716 result
= get_solaris_segment_type (p_type
);
4724 sprintf (buff
, "LOOS+%#lx", p_type
- PT_LOOS
);
4727 snprintf (buff
, sizeof (buff
), _("<unknown>: %lx"), p_type
);
4734 get_arc_section_type_name (unsigned int sh_type
)
4738 case SHT_ARC_ATTRIBUTES
: return "ARC_ATTRIBUTES";
4746 get_mips_section_type_name (unsigned int sh_type
)
4750 case SHT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
4751 case SHT_MIPS_MSYM
: return "MIPS_MSYM";
4752 case SHT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
4753 case SHT_MIPS_GPTAB
: return "MIPS_GPTAB";
4754 case SHT_MIPS_UCODE
: return "MIPS_UCODE";
4755 case SHT_MIPS_DEBUG
: return "MIPS_DEBUG";
4756 case SHT_MIPS_REGINFO
: return "MIPS_REGINFO";
4757 case SHT_MIPS_PACKAGE
: return "MIPS_PACKAGE";
4758 case SHT_MIPS_PACKSYM
: return "MIPS_PACKSYM";
4759 case SHT_MIPS_RELD
: return "MIPS_RELD";
4760 case SHT_MIPS_IFACE
: return "MIPS_IFACE";
4761 case SHT_MIPS_CONTENT
: return "MIPS_CONTENT";
4762 case SHT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
4763 case SHT_MIPS_SHDR
: return "MIPS_SHDR";
4764 case SHT_MIPS_FDESC
: return "MIPS_FDESC";
4765 case SHT_MIPS_EXTSYM
: return "MIPS_EXTSYM";
4766 case SHT_MIPS_DENSE
: return "MIPS_DENSE";
4767 case SHT_MIPS_PDESC
: return "MIPS_PDESC";
4768 case SHT_MIPS_LOCSYM
: return "MIPS_LOCSYM";
4769 case SHT_MIPS_AUXSYM
: return "MIPS_AUXSYM";
4770 case SHT_MIPS_OPTSYM
: return "MIPS_OPTSYM";
4771 case SHT_MIPS_LOCSTR
: return "MIPS_LOCSTR";
4772 case SHT_MIPS_LINE
: return "MIPS_LINE";
4773 case SHT_MIPS_RFDESC
: return "MIPS_RFDESC";
4774 case SHT_MIPS_DELTASYM
: return "MIPS_DELTASYM";
4775 case SHT_MIPS_DELTAINST
: return "MIPS_DELTAINST";
4776 case SHT_MIPS_DELTACLASS
: return "MIPS_DELTACLASS";
4777 case SHT_MIPS_DWARF
: return "MIPS_DWARF";
4778 case SHT_MIPS_DELTADECL
: return "MIPS_DELTADECL";
4779 case SHT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
4780 case SHT_MIPS_EVENTS
: return "MIPS_EVENTS";
4781 case SHT_MIPS_TRANSLATE
: return "MIPS_TRANSLATE";
4782 case SHT_MIPS_PIXIE
: return "MIPS_PIXIE";
4783 case SHT_MIPS_XLATE
: return "MIPS_XLATE";
4784 case SHT_MIPS_XLATE_DEBUG
: return "MIPS_XLATE_DEBUG";
4785 case SHT_MIPS_WHIRL
: return "MIPS_WHIRL";
4786 case SHT_MIPS_EH_REGION
: return "MIPS_EH_REGION";
4787 case SHT_MIPS_XLATE_OLD
: return "MIPS_XLATE_OLD";
4788 case SHT_MIPS_PDR_EXCEPTION
: return "MIPS_PDR_EXCEPTION";
4789 case SHT_MIPS_ABIFLAGS
: return "MIPS_ABIFLAGS";
4790 case SHT_MIPS_XHASH
: return "MIPS_XHASH";
4798 get_parisc_section_type_name (unsigned int sh_type
)
4802 case SHT_PARISC_EXT
: return "PARISC_EXT";
4803 case SHT_PARISC_UNWIND
: return "PARISC_UNWIND";
4804 case SHT_PARISC_DOC
: return "PARISC_DOC";
4805 case SHT_PARISC_ANNOT
: return "PARISC_ANNOT";
4806 case SHT_PARISC_SYMEXTN
: return "PARISC_SYMEXTN";
4807 case SHT_PARISC_STUBS
: return "PARISC_STUBS";
4808 case SHT_PARISC_DLKM
: return "PARISC_DLKM";
4809 default: return NULL
;
4814 get_ia64_section_type_name (Filedata
* filedata
, unsigned int sh_type
)
4816 /* If the top 8 bits are 0x78 the next 8 are the os/abi ID. */
4817 if ((sh_type
& 0xFF000000) == SHT_IA_64_LOPSREG
)
4818 return get_osabi_name (filedata
, (sh_type
& 0x00FF0000) >> 16);
4822 case SHT_IA_64_EXT
: return "IA_64_EXT";
4823 case SHT_IA_64_UNWIND
: return "IA_64_UNWIND";
4824 case SHT_IA_64_PRIORITY_INIT
: return "IA_64_PRIORITY_INIT";
4825 case SHT_IA_64_VMS_TRACE
: return "VMS_TRACE";
4826 case SHT_IA_64_VMS_TIE_SIGNATURES
: return "VMS_TIE_SIGNATURES";
4827 case SHT_IA_64_VMS_DEBUG
: return "VMS_DEBUG";
4828 case SHT_IA_64_VMS_DEBUG_STR
: return "VMS_DEBUG_STR";
4829 case SHT_IA_64_VMS_LINKAGES
: return "VMS_LINKAGES";
4830 case SHT_IA_64_VMS_SYMBOL_VECTOR
: return "VMS_SYMBOL_VECTOR";
4831 case SHT_IA_64_VMS_FIXUP
: return "VMS_FIXUP";
4839 get_x86_64_section_type_name (unsigned int sh_type
)
4843 case SHT_X86_64_UNWIND
: return "X86_64_UNWIND";
4844 default: return NULL
;
4849 get_aarch64_section_type_name (unsigned int sh_type
)
4853 case SHT_AARCH64_ATTRIBUTES
: return "AARCH64_ATTRIBUTES";
4854 default: return NULL
;
4859 get_arm_section_type_name (unsigned int sh_type
)
4863 case SHT_ARM_EXIDX
: return "ARM_EXIDX";
4864 case SHT_ARM_PREEMPTMAP
: return "ARM_PREEMPTMAP";
4865 case SHT_ARM_ATTRIBUTES
: return "ARM_ATTRIBUTES";
4866 case SHT_ARM_DEBUGOVERLAY
: return "ARM_DEBUGOVERLAY";
4867 case SHT_ARM_OVERLAYSECTION
: return "ARM_OVERLAYSECTION";
4868 default: return NULL
;
4873 get_tic6x_section_type_name (unsigned int sh_type
)
4877 case SHT_C6000_UNWIND
: return "C6000_UNWIND";
4878 case SHT_C6000_PREEMPTMAP
: return "C6000_PREEMPTMAP";
4879 case SHT_C6000_ATTRIBUTES
: return "C6000_ATTRIBUTES";
4880 case SHT_TI_ICODE
: return "TI_ICODE";
4881 case SHT_TI_XREF
: return "TI_XREF";
4882 case SHT_TI_HANDLER
: return "TI_HANDLER";
4883 case SHT_TI_INITINFO
: return "TI_INITINFO";
4884 case SHT_TI_PHATTRS
: return "TI_PHATTRS";
4885 default: return NULL
;
4890 get_msp430_section_type_name (unsigned int sh_type
)
4894 case SHT_MSP430_SEC_FLAGS
: return "MSP430_SEC_FLAGS";
4895 case SHT_MSP430_SYM_ALIASES
: return "MSP430_SYM_ALIASES";
4896 case SHT_MSP430_ATTRIBUTES
: return "MSP430_ATTRIBUTES";
4897 default: return NULL
;
4902 get_nfp_section_type_name (unsigned int sh_type
)
4906 case SHT_NFP_MECONFIG
: return "NFP_MECONFIG";
4907 case SHT_NFP_INITREG
: return "NFP_INITREG";
4908 case SHT_NFP_UDEBUG
: return "NFP_UDEBUG";
4909 default: return NULL
;
4914 get_v850_section_type_name (unsigned int sh_type
)
4918 case SHT_V850_SCOMMON
: return "V850 Small Common";
4919 case SHT_V850_TCOMMON
: return "V850 Tiny Common";
4920 case SHT_V850_ZCOMMON
: return "V850 Zero Common";
4921 case SHT_RENESAS_IOP
: return "RENESAS IOP";
4922 case SHT_RENESAS_INFO
: return "RENESAS INFO";
4923 default: return NULL
;
4928 get_riscv_section_type_name (unsigned int sh_type
)
4932 case SHT_RISCV_ATTRIBUTES
: return "RISCV_ATTRIBUTES";
4933 default: return NULL
;
4938 get_csky_section_type_name (unsigned int sh_type
)
4942 case SHT_CSKY_ATTRIBUTES
: return "CSKY_ATTRIBUTES";
4943 default: return NULL
;
4948 get_section_type_name (Filedata
* filedata
, unsigned int sh_type
)
4950 static char buff
[32];
4951 const char * result
;
4955 case SHT_NULL
: return "NULL";
4956 case SHT_PROGBITS
: return "PROGBITS";
4957 case SHT_SYMTAB
: return "SYMTAB";
4958 case SHT_STRTAB
: return "STRTAB";
4959 case SHT_RELA
: return "RELA";
4960 case SHT_RELR
: return "RELR";
4961 case SHT_HASH
: return "HASH";
4962 case SHT_DYNAMIC
: return "DYNAMIC";
4963 case SHT_NOTE
: return "NOTE";
4964 case SHT_NOBITS
: return "NOBITS";
4965 case SHT_REL
: return "REL";
4966 case SHT_SHLIB
: return "SHLIB";
4967 case SHT_DYNSYM
: return "DYNSYM";
4968 case SHT_INIT_ARRAY
: return "INIT_ARRAY";
4969 case SHT_FINI_ARRAY
: return "FINI_ARRAY";
4970 case SHT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
4971 case SHT_GNU_HASH
: return "GNU_HASH";
4972 case SHT_GROUP
: return "GROUP";
4973 case SHT_SYMTAB_SHNDX
: return "SYMTAB SECTION INDICES";
4974 case SHT_GNU_verdef
: return "VERDEF";
4975 case SHT_GNU_verneed
: return "VERNEED";
4976 case SHT_GNU_versym
: return "VERSYM";
4977 case 0x6ffffff0: return "VERSYM";
4978 case 0x6ffffffc: return "VERDEF";
4979 case 0x7ffffffd: return "AUXILIARY";
4980 case 0x7fffffff: return "FILTER";
4981 case SHT_GNU_LIBLIST
: return "GNU_LIBLIST";
4984 if ((sh_type
>= SHT_LOPROC
) && (sh_type
<= SHT_HIPROC
))
4986 switch (filedata
->file_header
.e_machine
)
4989 case EM_ARC_COMPACT
:
4990 case EM_ARC_COMPACT2
:
4991 result
= get_arc_section_type_name (sh_type
);
4994 case EM_MIPS_RS3_LE
:
4995 result
= get_mips_section_type_name (sh_type
);
4998 result
= get_parisc_section_type_name (sh_type
);
5001 result
= get_ia64_section_type_name (filedata
, sh_type
);
5006 result
= get_x86_64_section_type_name (sh_type
);
5009 result
= get_aarch64_section_type_name (sh_type
);
5012 result
= get_arm_section_type_name (sh_type
);
5015 result
= get_tic6x_section_type_name (sh_type
);
5018 result
= get_msp430_section_type_name (sh_type
);
5021 result
= get_nfp_section_type_name (sh_type
);
5025 case EM_CYGNUS_V850
:
5026 result
= get_v850_section_type_name (sh_type
);
5029 result
= get_riscv_section_type_name (sh_type
);
5032 result
= get_csky_section_type_name (sh_type
);
5042 sprintf (buff
, "LOPROC+%#x", sh_type
- SHT_LOPROC
);
5044 else if ((sh_type
>= SHT_LOOS
) && (sh_type
<= SHT_HIOS
))
5046 switch (filedata
->file_header
.e_machine
)
5049 result
= get_ia64_section_type_name (filedata
, sh_type
);
5052 if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_SOLARIS
)
5053 result
= get_solaris_section_type (sh_type
);
5058 case SHT_GNU_INCREMENTAL_INPUTS
: result
= "GNU_INCREMENTAL_INPUTS"; break;
5059 case SHT_GNU_ATTRIBUTES
: result
= "GNU_ATTRIBUTES"; break;
5060 case SHT_GNU_HASH
: result
= "GNU_HASH"; break;
5061 case SHT_GNU_LIBLIST
: result
= "GNU_LIBLIST"; break;
5073 sprintf (buff
, "LOOS+%#x", sh_type
- SHT_LOOS
);
5075 else if ((sh_type
>= SHT_LOUSER
) && (sh_type
<= SHT_HIUSER
))
5077 switch (filedata
->file_header
.e_machine
)
5081 case EM_CYGNUS_V850
:
5082 result
= get_v850_section_type_name (sh_type
);
5092 sprintf (buff
, "LOUSER+%#x", sh_type
- SHT_LOUSER
);
5095 /* This message is probably going to be displayed in a 15
5096 character wide field, so put the hex value first. */
5097 snprintf (buff
, sizeof (buff
), _("%08x: <unknown>"), sh_type
);
5103 enum long_option_values
5105 OPTION_DEBUG_DUMP
= 512,
5115 OPTION_WITH_SYMBOL_VERSIONS
,
5116 OPTION_RECURSE_LIMIT
,
5117 OPTION_NO_RECURSE_LIMIT
,
5118 OPTION_NO_DEMANGLING
,
5122 static struct option options
[] =
5124 /* Note - This table is alpha-sorted on the 'val'
5125 field in order to make adding new options easier. */
5126 {"arch-specific", no_argument
, 0, 'A'},
5127 {"all", no_argument
, 0, 'a'},
5128 {"demangle", optional_argument
, 0, 'C'},
5129 {"archive-index", no_argument
, 0, 'c'},
5130 {"use-dynamic", no_argument
, 0, 'D'},
5131 {"dynamic", no_argument
, 0, 'd'},
5132 {"headers", no_argument
, 0, 'e'},
5133 {"section-groups", no_argument
, 0, 'g'},
5134 {"help", no_argument
, 0, 'H'},
5135 {"file-header", no_argument
, 0, 'h'},
5136 {"histogram", no_argument
, 0, 'I'},
5137 {"lint", no_argument
, 0, 'L'},
5138 {"enable-checks", no_argument
, 0, 'L'},
5139 {"program-headers", no_argument
, 0, 'l'},
5140 {"segments", no_argument
, 0, 'l'},
5141 {"full-section-name",no_argument
, 0, 'N'},
5142 {"notes", no_argument
, 0, 'n'},
5143 {"process-links", no_argument
, 0, 'P'},
5144 {"string-dump", required_argument
, 0, 'p'},
5145 {"relocated-dump", required_argument
, 0, 'R'},
5146 {"relocs", no_argument
, 0, 'r'},
5147 {"section-headers", no_argument
, 0, 'S'},
5148 {"sections", no_argument
, 0, 'S'},
5149 {"symbols", no_argument
, 0, 's'},
5150 {"syms", no_argument
, 0, 's'},
5151 {"silent-truncation",no_argument
, 0, 'T'},
5152 {"section-details", no_argument
, 0, 't'},
5153 {"unicode", required_argument
, NULL
, 'U'},
5154 {"unwind", no_argument
, 0, 'u'},
5155 {"version-info", no_argument
, 0, 'V'},
5156 {"version", no_argument
, 0, 'v'},
5157 {"wide", no_argument
, 0, 'W'},
5158 {"hex-dump", required_argument
, 0, 'x'},
5159 {"decompress", no_argument
, 0, 'z'},
5161 {"no-demangle", no_argument
, 0, OPTION_NO_DEMANGLING
},
5162 {"recurse-limit", no_argument
, NULL
, OPTION_RECURSE_LIMIT
},
5163 {"no-recurse-limit", no_argument
, NULL
, OPTION_NO_RECURSE_LIMIT
},
5164 {"no-recursion-limit", no_argument
, NULL
, OPTION_NO_RECURSE_LIMIT
},
5165 {"dyn-syms", no_argument
, 0, OPTION_DYN_SYMS
},
5166 {"lto-syms", no_argument
, 0, OPTION_LTO_SYMS
},
5167 {"debug-dump", optional_argument
, 0, OPTION_DEBUG_DUMP
},
5168 {"dwarf-depth", required_argument
, 0, OPTION_DWARF_DEPTH
},
5169 {"dwarf-start", required_argument
, 0, OPTION_DWARF_START
},
5170 {"dwarf-check", no_argument
, 0, OPTION_DWARF_CHECK
},
5171 #ifdef ENABLE_LIBCTF
5172 {"ctf", required_argument
, 0, OPTION_CTF_DUMP
},
5173 {"ctf-symbols", required_argument
, 0, OPTION_CTF_SYMBOLS
},
5174 {"ctf-strings", required_argument
, 0, OPTION_CTF_STRINGS
},
5175 {"ctf-parent", required_argument
, 0, OPTION_CTF_PARENT
},
5177 {"sym-base", optional_argument
, 0, OPTION_SYM_BASE
},
5179 {0, no_argument
, 0, 0}
5183 usage (FILE * stream
)
5185 fprintf (stream
, _("Usage: readelf <option(s)> elf-file(s)\n"));
5186 fprintf (stream
, _(" Display information about the contents of ELF format files\n"));
5187 fprintf (stream
, _(" Options are:\n"));
5188 fprintf (stream
, _("\
5189 -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n"));
5190 fprintf (stream
, _("\
5191 -h --file-header Display the ELF file header\n"));
5192 fprintf (stream
, _("\
5193 -l --program-headers Display the program headers\n"));
5194 fprintf (stream
, _("\
5195 --segments An alias for --program-headers\n"));
5196 fprintf (stream
, _("\
5197 -S --section-headers Display the sections' header\n"));
5198 fprintf (stream
, _("\
5199 --sections An alias for --section-headers\n"));
5200 fprintf (stream
, _("\
5201 -g --section-groups Display the section groups\n"));
5202 fprintf (stream
, _("\
5203 -t --section-details Display the section details\n"));
5204 fprintf (stream
, _("\
5205 -e --headers Equivalent to: -h -l -S\n"));
5206 fprintf (stream
, _("\
5207 -s --syms Display the symbol table\n"));
5208 fprintf (stream
, _("\
5209 --symbols An alias for --syms\n"));
5210 fprintf (stream
, _("\
5211 --dyn-syms Display the dynamic symbol table\n"));
5212 fprintf (stream
, _("\
5213 --lto-syms Display LTO symbol tables\n"));
5214 fprintf (stream
, _("\
5215 --sym-base=[0|8|10|16] \n\
5216 Force base for symbol sizes. The options are \n\
5217 mixed (the default), octal, decimal, hexadecimal.\n"));
5218 fprintf (stream
, _("\
5219 -C --demangle[=STYLE] Decode mangled/processed symbol names\n"));
5220 display_demangler_styles (stream
, _("\
5222 fprintf (stream
, _("\
5223 --no-demangle Do not demangle low-level symbol names. (default)\n"));
5224 fprintf (stream
, _("\
5225 --recurse-limit Enable a demangling recursion limit. (default)\n"));
5226 fprintf (stream
, _("\
5227 --no-recurse-limit Disable a demangling recursion limit\n"));
5228 fprintf (stream
, _("\
5229 -U[dlexhi] --unicode=[default|locale|escape|hex|highlight|invalid]\n\
5230 Display unicode characters as determined by the current locale\n\
5231 (default), escape sequences, \"<hex sequences>\", highlighted\n\
5232 escape sequences, or treat them as invalid and display as\n\
5233 \"{hex sequences}\"\n"));
5234 fprintf (stream
, _("\
5235 -n --notes Display the core notes (if present)\n"));
5236 fprintf (stream
, _("\
5237 -r --relocs Display the relocations (if present)\n"));
5238 fprintf (stream
, _("\
5239 -u --unwind Display the unwind info (if present)\n"));
5240 fprintf (stream
, _("\
5241 -d --dynamic Display the dynamic section (if present)\n"));
5242 fprintf (stream
, _("\
5243 -V --version-info Display the version sections (if present)\n"));
5244 fprintf (stream
, _("\
5245 -A --arch-specific Display architecture specific information (if any)\n"));
5246 fprintf (stream
, _("\
5247 -c --archive-index Display the symbol/file index in an archive\n"));
5248 fprintf (stream
, _("\
5249 -D --use-dynamic Use the dynamic section info when displaying symbols\n"));
5250 fprintf (stream
, _("\
5251 -L --lint|--enable-checks\n\
5252 Display warning messages for possible problems\n"));
5253 fprintf (stream
, _("\
5254 -x --hex-dump=<number|name>\n\
5255 Dump the contents of section <number|name> as bytes\n"));
5256 fprintf (stream
, _("\
5257 -p --string-dump=<number|name>\n\
5258 Dump the contents of section <number|name> as strings\n"));
5259 fprintf (stream
, _("\
5260 -R --relocated-dump=<number|name>\n\
5261 Dump the relocated contents of section <number|name>\n"));
5262 fprintf (stream
, _("\
5263 -z --decompress Decompress section before dumping it\n"));
5264 fprintf (stream
, _("\
5265 -w --debug-dump[a/=abbrev, A/=addr, r/=aranges, c/=cu_index, L/=decodedline,\n\
5266 f/=frames, F/=frames-interp, g/=gdb_index, i/=info, o/=loc,\n\
5267 m/=macro, p/=pubnames, t/=pubtypes, R/=Ranges, l/=rawline,\n\
5268 s/=str, O/=str-offsets, u/=trace_abbrev, T/=trace_aranges,\n\
5270 Display the contents of DWARF debug sections\n"));
5271 fprintf (stream
, _("\
5272 -wk --debug-dump=links Display the contents of sections that link to separate\n\
5273 debuginfo files\n"));
5274 fprintf (stream
, _("\
5275 -P --process-links Display the contents of non-debug sections in separate\n\
5276 debuginfo files. (Implies -wK)\n"));
5277 #if DEFAULT_FOR_FOLLOW_LINKS
5278 fprintf (stream
, _("\
5279 -wK --debug-dump=follow-links\n\
5280 Follow links to separate debug info files (default)\n"));
5281 fprintf (stream
, _("\
5282 -wN --debug-dump=no-follow-links\n\
5283 Do not follow links to separate debug info files\n"));
5285 fprintf (stream
, _("\
5286 -wK --debug-dump=follow-links\n\
5287 Follow links to separate debug info files\n"));
5288 fprintf (stream
, _("\
5289 -wN --debug-dump=no-follow-links\n\
5290 Do not follow links to separate debug info files\n\
5293 #if HAVE_LIBDEBUGINFOD
5294 fprintf (stream
, _("\
5295 -wD --debug-dump=use-debuginfod\n\
5296 When following links, also query debuginfod servers (default)\n"));
5297 fprintf (stream
, _("\
5298 -wE --debug-dump=do-not-use-debuginfod\n\
5299 When following links, do not query debuginfod servers\n"));
5301 fprintf (stream
, _("\
5302 --dwarf-depth=N Do not display DIEs at depth N or greater\n"));
5303 fprintf (stream
, _("\
5304 --dwarf-start=N Display DIEs starting at offset N\n"));
5305 #ifdef ENABLE_LIBCTF
5306 fprintf (stream
, _("\
5307 --ctf=<number|name> Display CTF info from section <number|name>\n"));
5308 fprintf (stream
, _("\
5309 --ctf-parent=<name> Use CTF archive member <name> as the CTF parent\n"));
5310 fprintf (stream
, _("\
5311 --ctf-symbols=<number|name>\n\
5312 Use section <number|name> as the CTF external symtab\n"));
5313 fprintf (stream
, _("\
5314 --ctf-strings=<number|name>\n\
5315 Use section <number|name> as the CTF external strtab\n"));
5318 #ifdef SUPPORT_DISASSEMBLY
5319 fprintf (stream
, _("\
5320 -i --instruction-dump=<number|name>\n\
5321 Disassemble the contents of section <number|name>\n"));
5323 fprintf (stream
, _("\
5324 -I --histogram Display histogram of bucket list lengths\n"));
5325 fprintf (stream
, _("\
5326 -W --wide Allow output width to exceed 80 characters\n"));
5327 fprintf (stream
, _("\
5328 -T --silent-truncation If a symbol name is truncated, do not add [...] suffix\n"));
5329 fprintf (stream
, _("\
5330 @<file> Read options from <file>\n"));
5331 fprintf (stream
, _("\
5332 -H --help Display this information\n"));
5333 fprintf (stream
, _("\
5334 -v --version Display the version number of readelf\n"));
5336 if (REPORT_BUGS_TO
[0] && stream
== stdout
)
5337 fprintf (stdout
, _("Report bugs to %s\n"), REPORT_BUGS_TO
);
5339 exit (stream
== stdout
? 0 : 1);
5342 /* Record the fact that the user wants the contents of section number
5343 SECTION to be displayed using the method(s) encoded as flags bits
5344 in TYPE. Note, TYPE can be zero if we are creating the array for
5348 request_dump_bynumber (struct dump_data
*dumpdata
,
5349 unsigned int section
, dump_type type
)
5351 if (section
>= dumpdata
->num_dump_sects
)
5353 dump_type
* new_dump_sects
;
5355 new_dump_sects
= (dump_type
*) calloc (section
+ 1,
5356 sizeof (* new_dump_sects
));
5358 if (new_dump_sects
== NULL
)
5359 error (_("Out of memory allocating dump request table.\n"));
5362 if (dumpdata
->dump_sects
)
5364 /* Copy current flag settings. */
5365 memcpy (new_dump_sects
, dumpdata
->dump_sects
,
5366 dumpdata
->num_dump_sects
* sizeof (* new_dump_sects
));
5368 free (dumpdata
->dump_sects
);
5371 dumpdata
->dump_sects
= new_dump_sects
;
5372 dumpdata
->num_dump_sects
= section
+ 1;
5376 if (dumpdata
->dump_sects
)
5377 dumpdata
->dump_sects
[section
] |= type
;
5380 /* Request a dump by section name. */
5383 request_dump_byname (const char * section
, dump_type type
)
5385 struct dump_list_entry
* new_request
;
5387 new_request
= (struct dump_list_entry
*)
5388 malloc (sizeof (struct dump_list_entry
));
5390 error (_("Out of memory allocating dump request table.\n"));
5392 new_request
->name
= strdup (section
);
5393 if (!new_request
->name
)
5394 error (_("Out of memory allocating dump request table.\n"));
5396 new_request
->type
= type
;
5398 new_request
->next
= dump_sects_byname
;
5399 dump_sects_byname
= new_request
;
5403 request_dump (struct dump_data
*dumpdata
, dump_type type
)
5409 section
= strtoul (optarg
, & cp
, 0);
5411 if (! *cp
&& section
>= 0)
5412 request_dump_bynumber (dumpdata
, section
, type
);
5414 request_dump_byname (optarg
, type
);
5418 parse_args (struct dump_data
*dumpdata
, int argc
, char ** argv
)
5425 while ((c
= getopt_long
5426 (argc
, argv
, "ACDHILNPR:STU:VWacdeghi:lnp:rstuvw::x:z", options
, NULL
)) != EOF
)
5444 do_section_groups
= true;
5447 do_histogram
= true;
5453 do_section_groups
= true;
5458 do_section_details
= true;
5469 do_using_dynamic
= true;
5493 do_histogram
= true;
5499 do_archive_index
= true;
5505 process_links
= true;
5506 do_follow_links
= true;
5507 dump_any_debugging
= true;
5510 request_dump (dumpdata
, HEX_DUMP
);
5513 request_dump (dumpdata
, STRING_DUMP
);
5516 request_dump (dumpdata
, RELOC_DUMP
);
5519 decompress_dumps
= true;
5523 dump_any_debugging
= true;
5526 do_debugging
= true;
5527 dwarf_select_sections_all ();
5531 do_debugging
= false;
5532 dwarf_select_sections_by_letters (optarg
);
5535 case OPTION_DEBUG_DUMP
:
5537 dump_any_debugging
= true;
5540 do_debugging
= true;
5541 dwarf_select_sections_all ();
5545 do_debugging
= false;
5546 dwarf_select_sections_by_names (optarg
);
5549 case OPTION_DWARF_DEPTH
:
5553 dwarf_cutoff_level
= strtoul (optarg
, & cp
, 0);
5556 case OPTION_DWARF_START
:
5560 dwarf_start_die
= strtoul (optarg
, & cp
, 0);
5563 case OPTION_DWARF_CHECK
:
5566 case OPTION_CTF_DUMP
:
5568 request_dump (dumpdata
, CTF_DUMP
);
5570 case OPTION_CTF_SYMBOLS
:
5571 free (dump_ctf_symtab_name
);
5572 dump_ctf_symtab_name
= strdup (optarg
);
5574 case OPTION_CTF_STRINGS
:
5575 free (dump_ctf_strtab_name
);
5576 dump_ctf_strtab_name
= strdup (optarg
);
5578 case OPTION_CTF_PARENT
:
5579 free (dump_ctf_parent_name
);
5580 dump_ctf_parent_name
= strdup (optarg
);
5582 case OPTION_DYN_SYMS
:
5585 case OPTION_LTO_SYMS
:
5588 #ifdef SUPPORT_DISASSEMBLY
5590 request_dump (dumpdata
, DISASS_DUMP
);
5594 print_version (program_name
);
5603 do_not_show_symbol_truncation
= true;
5609 enum demangling_styles style
;
5611 style
= cplus_demangle_name_to_style (optarg
);
5612 if (style
== unknown_demangling
)
5613 error (_("unknown demangling style `%s'"), optarg
);
5615 cplus_demangle_set_style (style
);
5618 case OPTION_NO_DEMANGLING
:
5619 do_demangle
= false;
5621 case OPTION_RECURSE_LIMIT
:
5622 demangle_flags
&= ~ DMGL_NO_RECURSE_LIMIT
;
5624 case OPTION_NO_RECURSE_LIMIT
:
5625 demangle_flags
|= DMGL_NO_RECURSE_LIMIT
;
5627 case OPTION_WITH_SYMBOL_VERSIONS
:
5628 /* Ignored for backward compatibility. */
5633 error (_("Missing arg to -U/--unicode")); /* Can this happen ? */
5634 else if (streq (optarg
, "default") || streq (optarg
, "d"))
5635 unicode_display
= unicode_default
;
5636 else if (streq (optarg
, "locale") || streq (optarg
, "l"))
5637 unicode_display
= unicode_locale
;
5638 else if (streq (optarg
, "escape") || streq (optarg
, "e"))
5639 unicode_display
= unicode_escape
;
5640 else if (streq (optarg
, "invalid") || streq (optarg
, "i"))
5641 unicode_display
= unicode_invalid
;
5642 else if (streq (optarg
, "hex") || streq (optarg
, "x"))
5643 unicode_display
= unicode_hex
;
5644 else if (streq (optarg
, "highlight") || streq (optarg
, "h"))
5645 unicode_display
= unicode_highlight
;
5647 error (_("invalid argument to -U/--unicode: %s"), optarg
);
5650 case OPTION_SYM_BASE
:
5654 sym_base
= strtoul (optarg
, NULL
, 0);
5671 /* xgettext:c-format */
5672 error (_("Invalid option '-%c'\n"), c
);
5679 if (!do_dynamic
&& !do_syms
&& !do_reloc
&& !do_unwind
&& !do_sections
5680 && !do_segments
&& !do_header
&& !do_dump
&& !do_version
5681 && !do_histogram
&& !do_debugging
&& !do_arch
&& !do_notes
5682 && !do_section_groups
&& !do_archive_index
5683 && !do_dyn_syms
&& !do_lto_syms
)
5688 do_dynamic
= do_syms
= do_reloc
= do_unwind
= do_sections
= true;
5689 do_segments
= do_header
= do_dump
= do_version
= true;
5690 do_histogram
= do_debugging
= do_arch
= do_notes
= true;
5691 do_section_groups
= do_archive_index
= do_dyn_syms
= true;
5700 get_elf_class (unsigned int elf_class
)
5702 static char buff
[32];
5706 case ELFCLASSNONE
: return _("none");
5707 case ELFCLASS32
: return "ELF32";
5708 case ELFCLASS64
: return "ELF64";
5710 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), elf_class
);
5716 get_data_encoding (unsigned int encoding
)
5718 static char buff
[32];
5722 case ELFDATANONE
: return _("none");
5723 case ELFDATA2LSB
: return _("2's complement, little endian");
5724 case ELFDATA2MSB
: return _("2's complement, big endian");
5726 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), encoding
);
5731 /* Decode the data held in 'filedata->file_header'. */
5734 process_file_header (Filedata
* filedata
)
5736 Elf_Internal_Ehdr
* header
= & filedata
->file_header
;
5738 if ( header
->e_ident
[EI_MAG0
] != ELFMAG0
5739 || header
->e_ident
[EI_MAG1
] != ELFMAG1
5740 || header
->e_ident
[EI_MAG2
] != ELFMAG2
5741 || header
->e_ident
[EI_MAG3
] != ELFMAG3
)
5744 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
5748 if (! filedata
->is_separate
)
5749 init_dwarf_regnames_by_elf_machine_code (header
->e_machine
);
5755 if (filedata
->is_separate
)
5756 printf (_("ELF Header in linked file '%s':\n"), filedata
->file_name
);
5758 printf (_("ELF Header:\n"));
5759 printf (_(" Magic: "));
5760 for (i
= 0; i
< EI_NIDENT
; i
++)
5761 printf ("%2.2x ", header
->e_ident
[i
]);
5763 printf (_(" Class: %s\n"),
5764 get_elf_class (header
->e_ident
[EI_CLASS
]));
5765 printf (_(" Data: %s\n"),
5766 get_data_encoding (header
->e_ident
[EI_DATA
]));
5767 printf (_(" Version: %d%s\n"),
5768 header
->e_ident
[EI_VERSION
],
5769 (header
->e_ident
[EI_VERSION
] == EV_CURRENT
5771 : (header
->e_ident
[EI_VERSION
] != EV_NONE
5774 printf (_(" OS/ABI: %s\n"),
5775 get_osabi_name (filedata
, header
->e_ident
[EI_OSABI
]));
5776 printf (_(" ABI Version: %d\n"),
5777 header
->e_ident
[EI_ABIVERSION
]);
5778 printf (_(" Type: %s\n"),
5779 get_file_type (filedata
));
5780 printf (_(" Machine: %s\n"),
5781 get_machine_name (header
->e_machine
));
5782 printf (_(" Version: 0x%lx\n"),
5785 printf (_(" Entry point address: "));
5786 print_vma (header
->e_entry
, PREFIX_HEX
);
5787 printf (_("\n Start of program headers: "));
5788 print_vma (header
->e_phoff
, DEC
);
5789 printf (_(" (bytes into file)\n Start of section headers: "));
5790 print_vma (header
->e_shoff
, DEC
);
5791 printf (_(" (bytes into file)\n"));
5793 printf (_(" Flags: 0x%lx%s\n"),
5795 get_machine_flags (filedata
, header
->e_flags
, header
->e_machine
));
5796 printf (_(" Size of this header: %u (bytes)\n"),
5798 printf (_(" Size of program headers: %u (bytes)\n"),
5799 header
->e_phentsize
);
5800 printf (_(" Number of program headers: %u"),
5802 if (filedata
->section_headers
!= NULL
5803 && header
->e_phnum
== PN_XNUM
5804 && filedata
->section_headers
[0].sh_info
!= 0)
5805 printf (" (%u)", filedata
->section_headers
[0].sh_info
);
5806 putc ('\n', stdout
);
5807 printf (_(" Size of section headers: %u (bytes)\n"),
5808 header
->e_shentsize
);
5809 printf (_(" Number of section headers: %u"),
5811 if (filedata
->section_headers
!= NULL
&& header
->e_shnum
== SHN_UNDEF
)
5813 header
->e_shnum
= filedata
->section_headers
[0].sh_size
;
5814 printf (" (%u)", header
->e_shnum
);
5816 putc ('\n', stdout
);
5817 printf (_(" Section header string table index: %u"),
5818 header
->e_shstrndx
);
5819 if (filedata
->section_headers
!= NULL
5820 && header
->e_shstrndx
== (SHN_XINDEX
& 0xffff))
5822 header
->e_shstrndx
= filedata
->section_headers
[0].sh_link
;
5823 printf (" (%u)", header
->e_shstrndx
);
5825 if (header
->e_shstrndx
!= SHN_UNDEF
5826 && header
->e_shstrndx
>= header
->e_shnum
)
5828 header
->e_shstrndx
= SHN_UNDEF
;
5829 printf (_(" <corrupt: out of range>"));
5831 putc ('\n', stdout
);
5834 if (filedata
->section_headers
!= NULL
)
5836 if (header
->e_phnum
== PN_XNUM
5837 && filedata
->section_headers
[0].sh_info
!= 0)
5839 /* Throw away any cached read of PN_XNUM headers. */
5840 free (filedata
->program_headers
);
5841 filedata
->program_headers
= NULL
;
5842 header
->e_phnum
= filedata
->section_headers
[0].sh_info
;
5844 if (header
->e_shnum
== SHN_UNDEF
)
5845 header
->e_shnum
= filedata
->section_headers
[0].sh_size
;
5846 if (header
->e_shstrndx
== (SHN_XINDEX
& 0xffff))
5847 header
->e_shstrndx
= filedata
->section_headers
[0].sh_link
;
5848 if (header
->e_shstrndx
>= header
->e_shnum
)
5849 header
->e_shstrndx
= SHN_UNDEF
;
5855 /* Read in the program headers from FILEDATA and store them in PHEADERS.
5856 Returns TRUE upon success, FALSE otherwise. Loads 32-bit headers. */
5859 get_32bit_program_headers (Filedata
* filedata
, Elf_Internal_Phdr
* pheaders
)
5861 Elf32_External_Phdr
* phdrs
;
5862 Elf32_External_Phdr
* external
;
5863 Elf_Internal_Phdr
* internal
;
5865 unsigned int size
= filedata
->file_header
.e_phentsize
;
5866 unsigned int num
= filedata
->file_header
.e_phnum
;
5868 /* PR binutils/17531: Cope with unexpected section header sizes. */
5869 if (size
== 0 || num
== 0)
5871 if (size
< sizeof * phdrs
)
5873 error (_("The e_phentsize field in the ELF header is less than the size of an ELF program header\n"));
5876 if (size
> sizeof * phdrs
)
5877 warn (_("The e_phentsize field in the ELF header is larger than the size of an ELF program header\n"));
5879 phdrs
= (Elf32_External_Phdr
*) get_data (NULL
, filedata
, filedata
->file_header
.e_phoff
,
5880 size
, num
, _("program headers"));
5884 for (i
= 0, internal
= pheaders
, external
= phdrs
;
5885 i
< filedata
->file_header
.e_phnum
;
5886 i
++, internal
++, external
++)
5888 internal
->p_type
= BYTE_GET (external
->p_type
);
5889 internal
->p_offset
= BYTE_GET (external
->p_offset
);
5890 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
5891 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
5892 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
5893 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
5894 internal
->p_flags
= BYTE_GET (external
->p_flags
);
5895 internal
->p_align
= BYTE_GET (external
->p_align
);
5902 /* Read in the program headers from FILEDATA and store them in PHEADERS.
5903 Returns TRUE upon success, FALSE otherwise. Loads 64-bit headers. */
5906 get_64bit_program_headers (Filedata
* filedata
, Elf_Internal_Phdr
* pheaders
)
5908 Elf64_External_Phdr
* phdrs
;
5909 Elf64_External_Phdr
* external
;
5910 Elf_Internal_Phdr
* internal
;
5912 unsigned int size
= filedata
->file_header
.e_phentsize
;
5913 unsigned int num
= filedata
->file_header
.e_phnum
;
5915 /* PR binutils/17531: Cope with unexpected section header sizes. */
5916 if (size
== 0 || num
== 0)
5918 if (size
< sizeof * phdrs
)
5920 error (_("The e_phentsize field in the ELF header is less than the size of an ELF program header\n"));
5923 if (size
> sizeof * phdrs
)
5924 warn (_("The e_phentsize field in the ELF header is larger than the size of an ELF program header\n"));
5926 phdrs
= (Elf64_External_Phdr
*) get_data (NULL
, filedata
, filedata
->file_header
.e_phoff
,
5927 size
, num
, _("program headers"));
5931 for (i
= 0, internal
= pheaders
, external
= phdrs
;
5932 i
< filedata
->file_header
.e_phnum
;
5933 i
++, internal
++, external
++)
5935 internal
->p_type
= BYTE_GET (external
->p_type
);
5936 internal
->p_flags
= BYTE_GET (external
->p_flags
);
5937 internal
->p_offset
= BYTE_GET (external
->p_offset
);
5938 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
5939 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
5940 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
5941 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
5942 internal
->p_align
= BYTE_GET (external
->p_align
);
5949 /* Returns TRUE if the program headers were read into `program_headers'. */
5952 get_program_headers (Filedata
* filedata
)
5954 Elf_Internal_Phdr
* phdrs
;
5956 /* Check cache of prior read. */
5957 if (filedata
->program_headers
!= NULL
)
5960 /* Be kind to memory checkers by looking for
5961 e_phnum values which we know must be invalid. */
5962 if (filedata
->file_header
.e_phnum
5963 * (is_32bit_elf
? sizeof (Elf32_External_Phdr
) : sizeof (Elf64_External_Phdr
))
5964 >= filedata
->file_size
)
5966 error (_("Too many program headers - %#x - the file is not that big\n"),
5967 filedata
->file_header
.e_phnum
);
5971 phdrs
= (Elf_Internal_Phdr
*) cmalloc (filedata
->file_header
.e_phnum
,
5972 sizeof (Elf_Internal_Phdr
));
5975 error (_("Out of memory reading %u program headers\n"),
5976 filedata
->file_header
.e_phnum
);
5981 ? get_32bit_program_headers (filedata
, phdrs
)
5982 : get_64bit_program_headers (filedata
, phdrs
))
5984 filedata
->program_headers
= phdrs
;
5992 /* Print program header info and locate dynamic section. */
5995 process_program_headers (Filedata
* filedata
)
5997 Elf_Internal_Phdr
* segment
;
5999 Elf_Internal_Phdr
* previous_load
= NULL
;
6001 if (filedata
->file_header
.e_phnum
== 0)
6003 /* PR binutils/12467. */
6004 if (filedata
->file_header
.e_phoff
!= 0)
6005 warn (_("possibly corrupt ELF header - it has a non-zero program"
6006 " header offset, but no program headers\n"));
6007 else if (do_segments
)
6009 if (filedata
->is_separate
)
6010 printf (_("\nThere are no program headers in linked file '%s'.\n"),
6011 filedata
->file_name
);
6013 printf (_("\nThere are no program headers in this file.\n"));
6018 if (do_segments
&& !do_header
)
6020 if (filedata
->is_separate
)
6021 printf ("\nIn linked file '%s' the ELF file type is %s\n",
6022 filedata
->file_name
, get_file_type (filedata
));
6024 printf (_("\nElf file type is %s\n"), get_file_type (filedata
));
6025 printf (_("Entry point 0x%s\n"), bfd_vmatoa ("x", filedata
->file_header
.e_entry
));
6026 printf (ngettext ("There is %d program header, starting at offset %s\n",
6027 "There are %d program headers, starting at offset %s\n",
6028 filedata
->file_header
.e_phnum
),
6029 filedata
->file_header
.e_phnum
,
6030 bfd_vmatoa ("u", filedata
->file_header
.e_phoff
));
6033 if (! get_program_headers (filedata
))
6038 if (filedata
->file_header
.e_phnum
> 1)
6039 printf (_("\nProgram Headers:\n"));
6041 printf (_("\nProgram Headers:\n"));
6045 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
6048 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
6052 (_(" Type Offset VirtAddr PhysAddr\n"));
6054 (_(" FileSiz MemSiz Flags Align\n"));
6058 unsigned long dynamic_addr
= 0;
6059 bfd_size_type dynamic_size
= 0;
6060 for (i
= 0, segment
= filedata
->program_headers
;
6061 i
< filedata
->file_header
.e_phnum
;
6066 printf (" %-14.14s ", get_segment_type (filedata
, segment
->p_type
));
6070 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
6071 printf ("0x%8.8lx ", (unsigned long) segment
->p_vaddr
);
6072 printf ("0x%8.8lx ", (unsigned long) segment
->p_paddr
);
6073 printf ("0x%5.5lx ", (unsigned long) segment
->p_filesz
);
6074 printf ("0x%5.5lx ", (unsigned long) segment
->p_memsz
);
6076 (segment
->p_flags
& PF_R
? 'R' : ' '),
6077 (segment
->p_flags
& PF_W
? 'W' : ' '),
6078 (segment
->p_flags
& PF_X
? 'E' : ' '));
6079 printf ("%#lx", (unsigned long) segment
->p_align
);
6083 if ((unsigned long) segment
->p_offset
== segment
->p_offset
)
6084 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
6087 print_vma (segment
->p_offset
, FULL_HEX
);
6091 print_vma (segment
->p_vaddr
, FULL_HEX
);
6093 print_vma (segment
->p_paddr
, FULL_HEX
);
6096 if ((unsigned long) segment
->p_filesz
== segment
->p_filesz
)
6097 printf ("0x%6.6lx ", (unsigned long) segment
->p_filesz
);
6100 print_vma (segment
->p_filesz
, FULL_HEX
);
6104 if ((unsigned long) segment
->p_memsz
== segment
->p_memsz
)
6105 printf ("0x%6.6lx", (unsigned long) segment
->p_memsz
);
6108 print_vma (segment
->p_memsz
, FULL_HEX
);
6112 (segment
->p_flags
& PF_R
? 'R' : ' '),
6113 (segment
->p_flags
& PF_W
? 'W' : ' '),
6114 (segment
->p_flags
& PF_X
? 'E' : ' '));
6116 if ((unsigned long) segment
->p_align
== segment
->p_align
)
6117 printf ("%#lx", (unsigned long) segment
->p_align
);
6120 print_vma (segment
->p_align
, PREFIX_HEX
);
6125 print_vma (segment
->p_offset
, FULL_HEX
);
6127 print_vma (segment
->p_vaddr
, FULL_HEX
);
6129 print_vma (segment
->p_paddr
, FULL_HEX
);
6131 print_vma (segment
->p_filesz
, FULL_HEX
);
6133 print_vma (segment
->p_memsz
, FULL_HEX
);
6135 (segment
->p_flags
& PF_R
? 'R' : ' '),
6136 (segment
->p_flags
& PF_W
? 'W' : ' '),
6137 (segment
->p_flags
& PF_X
? 'E' : ' '));
6138 print_vma (segment
->p_align
, PREFIX_HEX
);
6141 putc ('\n', stdout
);
6144 switch (segment
->p_type
)
6147 #if 0 /* Do not warn about out of order PT_LOAD segments. Although officially
6148 required by the ELF standard, several programs, including the Linux
6149 kernel, make use of non-ordered segments. */
6151 && previous_load
->p_vaddr
> segment
->p_vaddr
)
6152 error (_("LOAD segments must be sorted in order of increasing VirtAddr\n"));
6154 if (segment
->p_memsz
< segment
->p_filesz
)
6155 error (_("the segment's file size is larger than its memory size\n"));
6156 previous_load
= segment
;
6160 /* PR 20815 - Verify that the program header is loaded into memory. */
6161 if (i
> 0 && previous_load
!= NULL
)
6162 error (_("the PHDR segment must occur before any LOAD segment\n"));
6163 if (filedata
->file_header
.e_machine
!= EM_PARISC
)
6167 for (j
= 1; j
< filedata
->file_header
.e_phnum
; j
++)
6169 Elf_Internal_Phdr
*load
= filedata
->program_headers
+ j
;
6170 if (load
->p_type
== PT_LOAD
6171 && load
->p_offset
<= segment
->p_offset
6172 && (load
->p_offset
+ load
->p_filesz
6173 >= segment
->p_offset
+ segment
->p_filesz
)
6174 && load
->p_vaddr
<= segment
->p_vaddr
6175 && (load
->p_vaddr
+ load
->p_filesz
6176 >= segment
->p_vaddr
+ segment
->p_filesz
))
6179 if (j
== filedata
->file_header
.e_phnum
)
6180 error (_("the PHDR segment is not covered by a LOAD segment\n"));
6186 error (_("more than one dynamic segment\n"));
6188 /* By default, assume that the .dynamic section is the first
6189 section in the DYNAMIC segment. */
6190 dynamic_addr
= segment
->p_offset
;
6191 dynamic_size
= segment
->p_filesz
;
6193 /* Try to locate the .dynamic section. If there is
6194 a section header table, we can easily locate it. */
6195 if (filedata
->section_headers
!= NULL
)
6197 Elf_Internal_Shdr
* sec
;
6199 sec
= find_section (filedata
, ".dynamic");
6200 if (sec
== NULL
|| sec
->sh_size
== 0)
6202 /* A corresponding .dynamic section is expected, but on
6203 IA-64/OpenVMS it is OK for it to be missing. */
6204 if (!is_ia64_vms (filedata
))
6205 error (_("no .dynamic section in the dynamic segment\n"));
6209 if (sec
->sh_type
== SHT_NOBITS
)
6216 dynamic_addr
= sec
->sh_offset
;
6217 dynamic_size
= sec
->sh_size
;
6219 /* The PT_DYNAMIC segment, which is used by the run-time
6220 loader, should exactly match the .dynamic section. */
6222 && (dynamic_addr
!= segment
->p_offset
6223 || dynamic_size
!= segment
->p_filesz
))
6225 the .dynamic section is not the same as the dynamic segment\n"));
6228 /* PR binutils/17512: Avoid corrupt dynamic section info in the
6229 segment. Check this after matching against the section headers
6230 so we don't warn on debuginfo file (which have NOBITS .dynamic
6232 if (dynamic_addr
> filedata
->file_size
6233 || (dynamic_size
> filedata
->file_size
- dynamic_addr
))
6235 error (_("the dynamic segment offset + size exceeds the size of the file\n"));
6242 if (segment
->p_offset
>= filedata
->file_size
6243 || segment
->p_filesz
> filedata
->file_size
- segment
->p_offset
6244 || segment
->p_filesz
- 1 >= (size_t) -2
6245 || fseek (filedata
->handle
,
6246 filedata
->archive_file_offset
+ (long) segment
->p_offset
,
6248 error (_("Unable to find program interpreter name\n"));
6251 size_t len
= segment
->p_filesz
;
6252 free (filedata
->program_interpreter
);
6253 filedata
->program_interpreter
= xmalloc (len
+ 1);
6254 len
= fread (filedata
->program_interpreter
, 1, len
,
6256 filedata
->program_interpreter
[len
] = 0;
6259 printf (_(" [Requesting program interpreter: %s]\n"),
6260 filedata
->program_interpreter
);
6267 && filedata
->section_headers
!= NULL
6268 && filedata
->string_table
!= NULL
)
6270 printf (_("\n Section to Segment mapping:\n"));
6271 printf (_(" Segment Sections...\n"));
6273 for (i
= 0; i
< filedata
->file_header
.e_phnum
; i
++)
6276 Elf_Internal_Shdr
* section
;
6278 segment
= filedata
->program_headers
+ i
;
6279 section
= filedata
->section_headers
+ 1;
6281 printf (" %2.2d ", i
);
6283 for (j
= 1; j
< filedata
->file_header
.e_shnum
; j
++, section
++)
6285 if (!ELF_TBSS_SPECIAL (section
, segment
)
6286 && ELF_SECTION_IN_SEGMENT_STRICT (section
, segment
))
6287 printf ("%s ", printable_section_name (filedata
, section
));
6294 filedata
->dynamic_addr
= dynamic_addr
;
6295 filedata
->dynamic_size
= dynamic_size
? dynamic_size
: 1;
6299 filedata
->dynamic_addr
= 0;
6300 filedata
->dynamic_size
= 1;
6304 /* Find the file offset corresponding to VMA by using the program headers. */
6307 offset_from_vma (Filedata
* filedata
, bfd_vma vma
, bfd_size_type size
)
6309 Elf_Internal_Phdr
* seg
;
6311 if (! get_program_headers (filedata
))
6313 warn (_("Cannot interpret virtual addresses without program headers.\n"));
6317 for (seg
= filedata
->program_headers
;
6318 seg
< filedata
->program_headers
+ filedata
->file_header
.e_phnum
;
6321 if (seg
->p_type
!= PT_LOAD
)
6324 if (vma
>= (seg
->p_vaddr
& -seg
->p_align
)
6325 && vma
+ size
<= seg
->p_vaddr
+ seg
->p_filesz
)
6326 return vma
- seg
->p_vaddr
+ seg
->p_offset
;
6329 warn (_("Virtual address 0x%lx not located in any PT_LOAD segment.\n"),
6330 (unsigned long) vma
);
6335 /* Allocate memory and load the sections headers into FILEDATA->filedata->section_headers.
6336 If PROBE is true, this is just a probe and we do not generate any error
6337 messages if the load fails. */
6340 get_32bit_section_headers (Filedata
* filedata
, bool probe
)
6342 Elf32_External_Shdr
* shdrs
;
6343 Elf_Internal_Shdr
* internal
;
6345 unsigned int size
= filedata
->file_header
.e_shentsize
;
6346 unsigned int num
= probe
? 1 : filedata
->file_header
.e_shnum
;
6348 /* PR binutils/17531: Cope with unexpected section header sizes. */
6349 if (size
== 0 || num
== 0)
6351 if (size
< sizeof * shdrs
)
6354 error (_("The e_shentsize field in the ELF header is less than the size of an ELF section header\n"));
6357 if (!probe
&& size
> sizeof * shdrs
)
6358 warn (_("The e_shentsize field in the ELF header is larger than the size of an ELF section header\n"));
6360 shdrs
= (Elf32_External_Shdr
*) get_data (NULL
, filedata
, filedata
->file_header
.e_shoff
,
6362 probe
? NULL
: _("section headers"));
6366 filedata
->section_headers
= (Elf_Internal_Shdr
*)
6367 cmalloc (num
, sizeof (Elf_Internal_Shdr
));
6368 if (filedata
->section_headers
== NULL
)
6371 error (_("Out of memory reading %u section headers\n"), num
);
6376 for (i
= 0, internal
= filedata
->section_headers
;
6380 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
6381 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
6382 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
6383 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
6384 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
6385 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
6386 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
6387 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
6388 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
6389 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
6390 if (!probe
&& internal
->sh_link
> num
)
6391 warn (_("Section %u has an out of range sh_link value of %u\n"), i
, internal
->sh_link
);
6392 if (!probe
&& internal
->sh_flags
& SHF_INFO_LINK
&& internal
->sh_info
> num
)
6393 warn (_("Section %u has an out of range sh_info value of %u\n"), i
, internal
->sh_info
);
6400 /* Like get_32bit_section_headers, except that it fetches 64-bit headers. */
6403 get_64bit_section_headers (Filedata
* filedata
, bool probe
)
6405 Elf64_External_Shdr
* shdrs
;
6406 Elf_Internal_Shdr
* internal
;
6408 unsigned int size
= filedata
->file_header
.e_shentsize
;
6409 unsigned int num
= probe
? 1 : filedata
->file_header
.e_shnum
;
6411 /* PR binutils/17531: Cope with unexpected section header sizes. */
6412 if (size
== 0 || num
== 0)
6415 if (size
< sizeof * shdrs
)
6418 error (_("The e_shentsize field in the ELF header is less than the size of an ELF section header\n"));
6422 if (! probe
&& size
> sizeof * shdrs
)
6423 warn (_("The e_shentsize field in the ELF header is larger than the size of an ELF section header\n"));
6425 shdrs
= (Elf64_External_Shdr
*) get_data (NULL
, filedata
,
6426 filedata
->file_header
.e_shoff
,
6428 probe
? NULL
: _("section headers"));
6432 filedata
->section_headers
= (Elf_Internal_Shdr
*)
6433 cmalloc (num
, sizeof (Elf_Internal_Shdr
));
6434 if (filedata
->section_headers
== NULL
)
6437 error (_("Out of memory reading %u section headers\n"), num
);
6442 for (i
= 0, internal
= filedata
->section_headers
;
6446 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
6447 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
6448 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
6449 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
6450 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
6451 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
6452 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
6453 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
6454 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
6455 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
6456 if (!probe
&& internal
->sh_link
> num
)
6457 warn (_("Section %u has an out of range sh_link value of %u\n"), i
, internal
->sh_link
);
6458 if (!probe
&& internal
->sh_flags
& SHF_INFO_LINK
&& internal
->sh_info
> num
)
6459 warn (_("Section %u has an out of range sh_info value of %u\n"), i
, internal
->sh_info
);
6467 get_section_headers (Filedata
*filedata
, bool probe
)
6469 if (filedata
->section_headers
!= NULL
)
6473 return get_32bit_section_headers (filedata
, probe
);
6475 return get_64bit_section_headers (filedata
, probe
);
6478 static Elf_Internal_Sym
*
6479 get_32bit_elf_symbols (Filedata
* filedata
,
6480 Elf_Internal_Shdr
* section
,
6481 unsigned long * num_syms_return
)
6483 unsigned long number
= 0;
6484 Elf32_External_Sym
* esyms
= NULL
;
6485 Elf_External_Sym_Shndx
* shndx
= NULL
;
6486 Elf_Internal_Sym
* isyms
= NULL
;
6487 Elf_Internal_Sym
* psym
;
6489 elf_section_list
* entry
;
6491 if (section
->sh_size
== 0)
6493 if (num_syms_return
!= NULL
)
6494 * num_syms_return
= 0;
6498 /* Run some sanity checks first. */
6499 if (section
->sh_entsize
== 0 || section
->sh_entsize
> section
->sh_size
)
6501 error (_("Section %s has an invalid sh_entsize of 0x%lx\n"),
6502 printable_section_name (filedata
, section
),
6503 (unsigned long) section
->sh_entsize
);
6507 if (section
->sh_size
> filedata
->file_size
)
6509 error (_("Section %s has an invalid sh_size of 0x%lx\n"),
6510 printable_section_name (filedata
, section
),
6511 (unsigned long) section
->sh_size
);
6515 number
= section
->sh_size
/ section
->sh_entsize
;
6517 if (number
* sizeof (Elf32_External_Sym
) > section
->sh_size
+ 1)
6519 error (_("Size (0x%lx) of section %s is not a multiple of its sh_entsize (0x%lx)\n"),
6520 (unsigned long) section
->sh_size
,
6521 printable_section_name (filedata
, section
),
6522 (unsigned long) section
->sh_entsize
);
6526 esyms
= (Elf32_External_Sym
*) get_data (NULL
, filedata
, section
->sh_offset
, 1,
6527 section
->sh_size
, _("symbols"));
6532 for (entry
= filedata
->symtab_shndx_list
; entry
!= NULL
; entry
= entry
->next
)
6534 if (entry
->hdr
->sh_link
!= (unsigned long) (section
- filedata
->section_headers
))
6539 error (_("Multiple symbol table index sections associated with the same symbol section\n"));
6543 shndx
= (Elf_External_Sym_Shndx
*) get_data (NULL
, filedata
,
6544 entry
->hdr
->sh_offset
,
6545 1, entry
->hdr
->sh_size
,
6546 _("symbol table section indices"));
6550 /* PR17531: file: heap-buffer-overflow */
6551 if (entry
->hdr
->sh_size
/ sizeof (Elf_External_Sym_Shndx
) < number
)
6553 error (_("Index section %s has an sh_size of 0x%lx - expected 0x%lx\n"),
6554 printable_section_name (filedata
, entry
->hdr
),
6555 (unsigned long) entry
->hdr
->sh_size
,
6556 (unsigned long) section
->sh_size
);
6561 isyms
= (Elf_Internal_Sym
*) cmalloc (number
, sizeof (Elf_Internal_Sym
));
6565 error (_("Out of memory reading %lu symbols\n"),
6566 (unsigned long) number
);
6570 for (j
= 0, psym
= isyms
; j
< number
; j
++, psym
++)
6572 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
6573 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
6574 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
6575 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
6576 if (psym
->st_shndx
== (SHN_XINDEX
& 0xffff) && shndx
!= NULL
)
6578 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
6579 else if (psym
->st_shndx
>= (SHN_LORESERVE
& 0xffff))
6580 psym
->st_shndx
+= SHN_LORESERVE
- (SHN_LORESERVE
& 0xffff);
6581 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
6582 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
6589 if (num_syms_return
!= NULL
)
6590 * num_syms_return
= isyms
== NULL
? 0 : number
;
6595 static Elf_Internal_Sym
*
6596 get_64bit_elf_symbols (Filedata
* filedata
,
6597 Elf_Internal_Shdr
* section
,
6598 unsigned long * num_syms_return
)
6600 unsigned long number
= 0;
6601 Elf64_External_Sym
* esyms
= NULL
;
6602 Elf_External_Sym_Shndx
* shndx
= NULL
;
6603 Elf_Internal_Sym
* isyms
= NULL
;
6604 Elf_Internal_Sym
* psym
;
6606 elf_section_list
* entry
;
6608 if (section
->sh_size
== 0)
6610 if (num_syms_return
!= NULL
)
6611 * num_syms_return
= 0;
6615 /* Run some sanity checks first. */
6616 if (section
->sh_entsize
== 0 || section
->sh_entsize
> section
->sh_size
)
6618 error (_("Section %s has an invalid sh_entsize of 0x%lx\n"),
6619 printable_section_name (filedata
, section
),
6620 (unsigned long) section
->sh_entsize
);
6624 if (section
->sh_size
> filedata
->file_size
)
6626 error (_("Section %s has an invalid sh_size of 0x%lx\n"),
6627 printable_section_name (filedata
, section
),
6628 (unsigned long) section
->sh_size
);
6632 number
= section
->sh_size
/ section
->sh_entsize
;
6634 if (number
* sizeof (Elf64_External_Sym
) > section
->sh_size
+ 1)
6636 error (_("Size (0x%lx) of section %s is not a multiple of its sh_entsize (0x%lx)\n"),
6637 (unsigned long) section
->sh_size
,
6638 printable_section_name (filedata
, section
),
6639 (unsigned long) section
->sh_entsize
);
6643 esyms
= (Elf64_External_Sym
*) get_data (NULL
, filedata
, section
->sh_offset
, 1,
6644 section
->sh_size
, _("symbols"));
6649 for (entry
= filedata
->symtab_shndx_list
; entry
!= NULL
; entry
= entry
->next
)
6651 if (entry
->hdr
->sh_link
!= (unsigned long) (section
- filedata
->section_headers
))
6656 error (_("Multiple symbol table index sections associated with the same symbol section\n"));
6660 shndx
= (Elf_External_Sym_Shndx
*) get_data (NULL
, filedata
,
6661 entry
->hdr
->sh_offset
,
6662 1, entry
->hdr
->sh_size
,
6663 _("symbol table section indices"));
6667 /* PR17531: file: heap-buffer-overflow */
6668 if (entry
->hdr
->sh_size
/ sizeof (Elf_External_Sym_Shndx
) < number
)
6670 error (_("Index section %s has an sh_size of 0x%lx - expected 0x%lx\n"),
6671 printable_section_name (filedata
, entry
->hdr
),
6672 (unsigned long) entry
->hdr
->sh_size
,
6673 (unsigned long) section
->sh_size
);
6678 isyms
= (Elf_Internal_Sym
*) cmalloc (number
, sizeof (Elf_Internal_Sym
));
6682 error (_("Out of memory reading %lu symbols\n"),
6683 (unsigned long) number
);
6687 for (j
= 0, psym
= isyms
; j
< number
; j
++, psym
++)
6689 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
6690 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
6691 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
6692 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
6694 if (psym
->st_shndx
== (SHN_XINDEX
& 0xffff) && shndx
!= NULL
)
6696 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
6697 else if (psym
->st_shndx
>= (SHN_LORESERVE
& 0xffff))
6698 psym
->st_shndx
+= SHN_LORESERVE
- (SHN_LORESERVE
& 0xffff);
6700 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
6701 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
6708 if (num_syms_return
!= NULL
)
6709 * num_syms_return
= isyms
== NULL
? 0 : number
;
6714 static Elf_Internal_Sym
*
6715 get_elf_symbols (Filedata
*filedata
,
6716 Elf_Internal_Shdr
*section
,
6717 unsigned long *num_syms_return
)
6720 return get_32bit_elf_symbols (filedata
, section
, num_syms_return
);
6722 return get_64bit_elf_symbols (filedata
, section
, num_syms_return
);
6726 get_elf_section_flags (Filedata
* filedata
, bfd_vma sh_flags
)
6728 static char buff
[1024];
6730 unsigned int field_size
= is_32bit_elf
? 8 : 16;
6732 unsigned int size
= sizeof (buff
) - (field_size
+ 4 + 1);
6733 bfd_vma os_flags
= 0;
6734 bfd_vma proc_flags
= 0;
6735 bfd_vma unknown_flags
= 0;
6743 /* 0 */ { STRING_COMMA_LEN ("WRITE") },
6744 /* 1 */ { STRING_COMMA_LEN ("ALLOC") },
6745 /* 2 */ { STRING_COMMA_LEN ("EXEC") },
6746 /* 3 */ { STRING_COMMA_LEN ("MERGE") },
6747 /* 4 */ { STRING_COMMA_LEN ("STRINGS") },
6748 /* 5 */ { STRING_COMMA_LEN ("INFO LINK") },
6749 /* 6 */ { STRING_COMMA_LEN ("LINK ORDER") },
6750 /* 7 */ { STRING_COMMA_LEN ("OS NONCONF") },
6751 /* 8 */ { STRING_COMMA_LEN ("GROUP") },
6752 /* 9 */ { STRING_COMMA_LEN ("TLS") },
6753 /* IA-64 specific. */
6754 /* 10 */ { STRING_COMMA_LEN ("SHORT") },
6755 /* 11 */ { STRING_COMMA_LEN ("NORECOV") },
6756 /* IA-64 OpenVMS specific. */
6757 /* 12 */ { STRING_COMMA_LEN ("VMS_GLOBAL") },
6758 /* 13 */ { STRING_COMMA_LEN ("VMS_OVERLAID") },
6759 /* 14 */ { STRING_COMMA_LEN ("VMS_SHARED") },
6760 /* 15 */ { STRING_COMMA_LEN ("VMS_VECTOR") },
6761 /* 16 */ { STRING_COMMA_LEN ("VMS_ALLOC_64BIT") },
6762 /* 17 */ { STRING_COMMA_LEN ("VMS_PROTECTED") },
6764 /* 18 */ { STRING_COMMA_LEN ("EXCLUDE") },
6765 /* SPARC specific. */
6766 /* 19 */ { STRING_COMMA_LEN ("ORDERED") },
6767 /* 20 */ { STRING_COMMA_LEN ("COMPRESSED") },
6769 /* 21 */ { STRING_COMMA_LEN ("ENTRYSECT") },
6770 /* 22 */ { STRING_COMMA_LEN ("ARM_PURECODE") },
6771 /* 23 */ { STRING_COMMA_LEN ("COMDEF") },
6773 /* 24 */ { STRING_COMMA_LEN ("GNU_MBIND") },
6775 /* 25 */ { STRING_COMMA_LEN ("VLE") },
6777 /* 26 */ { STRING_COMMA_LEN ("GNU_RETAIN") },
6780 if (do_section_details
)
6782 sprintf (buff
, "[%*.*lx]: ",
6783 field_size
, field_size
, (unsigned long) sh_flags
);
6784 p
+= field_size
+ 4;
6791 flag
= sh_flags
& - sh_flags
;
6794 if (do_section_details
)
6798 case SHF_WRITE
: sindex
= 0; break;
6799 case SHF_ALLOC
: sindex
= 1; break;
6800 case SHF_EXECINSTR
: sindex
= 2; break;
6801 case SHF_MERGE
: sindex
= 3; break;
6802 case SHF_STRINGS
: sindex
= 4; break;
6803 case SHF_INFO_LINK
: sindex
= 5; break;
6804 case SHF_LINK_ORDER
: sindex
= 6; break;
6805 case SHF_OS_NONCONFORMING
: sindex
= 7; break;
6806 case SHF_GROUP
: sindex
= 8; break;
6807 case SHF_TLS
: sindex
= 9; break;
6808 case SHF_EXCLUDE
: sindex
= 18; break;
6809 case SHF_COMPRESSED
: sindex
= 20; break;
6813 switch (filedata
->file_header
.e_machine
)
6816 if (flag
== SHF_IA_64_SHORT
)
6818 else if (flag
== SHF_IA_64_NORECOV
)
6821 else if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_OPENVMS
)
6824 case SHF_IA_64_VMS_GLOBAL
: sindex
= 12; break;
6825 case SHF_IA_64_VMS_OVERLAID
: sindex
= 13; break;
6826 case SHF_IA_64_VMS_SHARED
: sindex
= 14; break;
6827 case SHF_IA_64_VMS_VECTOR
: sindex
= 15; break;
6828 case SHF_IA_64_VMS_ALLOC_64BIT
: sindex
= 16; break;
6829 case SHF_IA_64_VMS_PROTECTED
: sindex
= 17; break;
6840 case EM_OLD_SPARCV9
:
6841 case EM_SPARC32PLUS
:
6844 if (flag
== SHF_ORDERED
)
6851 case SHF_ENTRYSECT
: sindex
= 21; break;
6852 case SHF_ARM_PURECODE
: sindex
= 22; break;
6853 case SHF_COMDEF
: sindex
= 23; break;
6858 if (flag
== SHF_PPC_VLE
)
6865 switch (filedata
->file_header
.e_ident
[EI_OSABI
])
6868 case ELFOSABI_FREEBSD
:
6869 if (flag
== SHF_GNU_RETAIN
)
6873 if (flag
== SHF_GNU_MBIND
)
6874 /* We should not recognize SHF_GNU_MBIND for
6875 ELFOSABI_NONE, but binutils as of 2019-07-23 did
6876 not set the EI_OSABI header byte. */
6887 if (p
!= buff
+ field_size
+ 4)
6889 if (size
< (10 + 2))
6891 warn (_("Internal error: not enough buffer room for section flag info"));
6892 return _("<unknown>");
6899 size
-= flags
[sindex
].len
;
6900 p
= stpcpy (p
, flags
[sindex
].str
);
6902 else if (flag
& SHF_MASKOS
)
6904 else if (flag
& SHF_MASKPROC
)
6907 unknown_flags
|= flag
;
6913 case SHF_WRITE
: *p
= 'W'; break;
6914 case SHF_ALLOC
: *p
= 'A'; break;
6915 case SHF_EXECINSTR
: *p
= 'X'; break;
6916 case SHF_MERGE
: *p
= 'M'; break;
6917 case SHF_STRINGS
: *p
= 'S'; break;
6918 case SHF_INFO_LINK
: *p
= 'I'; break;
6919 case SHF_LINK_ORDER
: *p
= 'L'; break;
6920 case SHF_OS_NONCONFORMING
: *p
= 'O'; break;
6921 case SHF_GROUP
: *p
= 'G'; break;
6922 case SHF_TLS
: *p
= 'T'; break;
6923 case SHF_EXCLUDE
: *p
= 'E'; break;
6924 case SHF_COMPRESSED
: *p
= 'C'; break;
6927 if ((filedata
->file_header
.e_machine
== EM_X86_64
6928 || filedata
->file_header
.e_machine
== EM_L1OM
6929 || filedata
->file_header
.e_machine
== EM_K1OM
)
6930 && flag
== SHF_X86_64_LARGE
)
6932 else if (filedata
->file_header
.e_machine
== EM_ARM
6933 && flag
== SHF_ARM_PURECODE
)
6935 else if (filedata
->file_header
.e_machine
== EM_PPC
6936 && flag
== SHF_PPC_VLE
)
6938 else if (flag
& SHF_MASKOS
)
6940 switch (filedata
->file_header
.e_ident
[EI_OSABI
])
6943 case ELFOSABI_FREEBSD
:
6944 if (flag
== SHF_GNU_RETAIN
)
6951 if (flag
== SHF_GNU_MBIND
)
6953 /* We should not recognize SHF_GNU_MBIND for
6954 ELFOSABI_NONE, but binutils as of 2019-07-23 did
6955 not set the EI_OSABI header byte. */
6962 sh_flags
&= ~SHF_MASKOS
;
6966 else if (flag
& SHF_MASKPROC
)
6969 sh_flags
&= ~ SHF_MASKPROC
;
6979 if (do_section_details
)
6983 size
-= 5 + field_size
;
6984 if (p
!= buff
+ field_size
+ 4)
6988 warn (_("Internal error: not enough buffer room for section flag info"));
6989 return _("<unknown>");
6995 sprintf (p
, "OS (%*.*lx)", field_size
, field_size
,
6996 (unsigned long) os_flags
);
6997 p
+= 5 + field_size
;
7001 size
-= 7 + field_size
;
7002 if (p
!= buff
+ field_size
+ 4)
7006 warn (_("Internal error: not enough buffer room for section flag info"));
7007 return _("<unknown>");
7013 sprintf (p
, "PROC (%*.*lx)", field_size
, field_size
,
7014 (unsigned long) proc_flags
);
7015 p
+= 7 + field_size
;
7019 size
-= 10 + field_size
;
7020 if (p
!= buff
+ field_size
+ 4)
7024 warn (_("Internal error: not enough buffer room for section flag info"));
7025 return _("<unknown>");
7031 sprintf (p
, _("UNKNOWN (%*.*lx)"), field_size
, field_size
,
7032 (unsigned long) unknown_flags
);
7033 p
+= 10 + field_size
;
7041 static unsigned int ATTRIBUTE_WARN_UNUSED_RESULT
7042 get_compression_header (Elf_Internal_Chdr
*chdr
, unsigned char *buf
, bfd_size_type size
)
7046 Elf32_External_Chdr
*echdr
= (Elf32_External_Chdr
*) buf
;
7048 if (size
< sizeof (* echdr
))
7050 error (_("Compressed section is too small even for a compression header\n"));
7054 chdr
->ch_type
= BYTE_GET (echdr
->ch_type
);
7055 chdr
->ch_size
= BYTE_GET (echdr
->ch_size
);
7056 chdr
->ch_addralign
= BYTE_GET (echdr
->ch_addralign
);
7057 return sizeof (*echdr
);
7061 Elf64_External_Chdr
*echdr
= (Elf64_External_Chdr
*) buf
;
7063 if (size
< sizeof (* echdr
))
7065 error (_("Compressed section is too small even for a compression header\n"));
7069 chdr
->ch_type
= BYTE_GET (echdr
->ch_type
);
7070 chdr
->ch_size
= BYTE_GET (echdr
->ch_size
);
7071 chdr
->ch_addralign
= BYTE_GET (echdr
->ch_addralign
);
7072 return sizeof (*echdr
);
7077 process_section_headers (Filedata
* filedata
)
7079 Elf_Internal_Shdr
* section
;
7082 if (filedata
->file_header
.e_shnum
== 0)
7084 /* PR binutils/12467. */
7085 if (filedata
->file_header
.e_shoff
!= 0)
7087 warn (_("possibly corrupt ELF file header - it has a non-zero"
7088 " section header offset, but no section headers\n"));
7091 else if (do_sections
)
7092 printf (_("\nThere are no sections in this file.\n"));
7097 if (do_sections
&& !do_header
)
7099 if (filedata
->is_separate
&& process_links
)
7100 printf (_("In linked file '%s': "), filedata
->file_name
);
7101 if (! filedata
->is_separate
|| process_links
)
7102 printf (ngettext ("There is %d section header, "
7103 "starting at offset 0x%lx:\n",
7104 "There are %d section headers, "
7105 "starting at offset 0x%lx:\n",
7106 filedata
->file_header
.e_shnum
),
7107 filedata
->file_header
.e_shnum
,
7108 (unsigned long) filedata
->file_header
.e_shoff
);
7111 if (!get_section_headers (filedata
, false))
7114 /* Read in the string table, so that we have names to display. */
7115 if (filedata
->file_header
.e_shstrndx
!= SHN_UNDEF
7116 && filedata
->file_header
.e_shstrndx
< filedata
->file_header
.e_shnum
)
7118 section
= filedata
->section_headers
+ filedata
->file_header
.e_shstrndx
;
7120 if (section
->sh_size
!= 0)
7122 filedata
->string_table
= (char *) get_data (NULL
, filedata
, section
->sh_offset
,
7123 1, section
->sh_size
,
7126 filedata
->string_table_length
= filedata
->string_table
!= NULL
? section
->sh_size
: 0;
7130 /* Scan the sections for the dynamic symbol table
7131 and dynamic string table and debug sections. */
7132 eh_addr_size
= is_32bit_elf
? 4 : 8;
7133 switch (filedata
->file_header
.e_machine
)
7136 case EM_MIPS_RS3_LE
:
7137 /* The 64-bit MIPS EABI uses a combination of 32-bit ELF and 64-bit
7138 FDE addresses. However, the ABI also has a semi-official ILP32
7139 variant for which the normal FDE address size rules apply.
7141 GCC 4.0 marks EABI64 objects with a dummy .gcc_compiled_longXX
7142 section, where XX is the size of longs in bits. Unfortunately,
7143 earlier compilers provided no way of distinguishing ILP32 objects
7144 from LP64 objects, so if there's any doubt, we should assume that
7145 the official LP64 form is being used. */
7146 if ((filedata
->file_header
.e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
7147 && find_section (filedata
, ".gcc_compiled_long32") == NULL
)
7153 switch (filedata
->file_header
.e_flags
& EF_H8_MACH
)
7155 case E_H8_MACH_H8300
:
7156 case E_H8_MACH_H8300HN
:
7157 case E_H8_MACH_H8300SN
:
7158 case E_H8_MACH_H8300SXN
:
7161 case E_H8_MACH_H8300H
:
7162 case E_H8_MACH_H8300S
:
7163 case E_H8_MACH_H8300SX
:
7171 switch (filedata
->file_header
.e_flags
& EF_M32C_CPU_MASK
)
7173 case EF_M32C_CPU_M16C
:
7180 #define CHECK_ENTSIZE_VALUES(section, i, size32, size64) \
7183 bfd_size_type expected_entsize = is_32bit_elf ? size32 : size64; \
7184 if (section->sh_entsize != expected_entsize) \
7187 sprintf_vma (buf, section->sh_entsize); \
7188 /* Note: coded this way so that there is a single string for \
7190 error (_("Section %d has invalid sh_entsize of %s\n"), i, buf); \
7191 error (_("(Using the expected size of %u for the rest of this dump)\n"), \
7192 (unsigned) expected_entsize); \
7193 section->sh_entsize = expected_entsize; \
7198 #define CHECK_ENTSIZE(section, i, type) \
7199 CHECK_ENTSIZE_VALUES (section, i, sizeof (Elf32_External_##type), \
7200 sizeof (Elf64_External_##type))
7202 for (i
= 0, section
= filedata
->section_headers
;
7203 i
< filedata
->file_header
.e_shnum
;
7206 const char *name
= section_name_print (filedata
, section
);
7208 /* Run some sanity checks on the headers and
7209 possibly fill in some file data as well. */
7210 switch (section
->sh_type
)
7213 if (filedata
->dynamic_symbols
!= NULL
)
7215 error (_("File contains multiple dynamic symbol tables\n"));
7219 CHECK_ENTSIZE (section
, i
, Sym
);
7220 filedata
->dynamic_symbols
7221 = get_elf_symbols (filedata
, section
, &filedata
->num_dynamic_syms
);
7222 filedata
->dynamic_symtab_section
= section
;
7226 if (streq (name
, ".dynstr"))
7228 if (filedata
->dynamic_strings
!= NULL
)
7230 error (_("File contains multiple dynamic string tables\n"));
7234 filedata
->dynamic_strings
7235 = (char *) get_data (NULL
, filedata
, section
->sh_offset
,
7236 1, section
->sh_size
, _("dynamic strings"));
7237 filedata
->dynamic_strings_length
7238 = filedata
->dynamic_strings
== NULL
? 0 : section
->sh_size
;
7239 filedata
->dynamic_strtab_section
= section
;
7243 case SHT_SYMTAB_SHNDX
:
7245 elf_section_list
* entry
= xmalloc (sizeof * entry
);
7247 entry
->hdr
= section
;
7248 entry
->next
= filedata
->symtab_shndx_list
;
7249 filedata
->symtab_shndx_list
= entry
;
7254 CHECK_ENTSIZE (section
, i
, Sym
);
7258 CHECK_ENTSIZE_VALUES (section
, i
, GRP_ENTRY_SIZE
, GRP_ENTRY_SIZE
);
7262 CHECK_ENTSIZE (section
, i
, Rel
);
7263 if (do_checks
&& section
->sh_size
== 0)
7264 warn (_("Section '%s': zero-sized relocation section\n"), name
);
7268 CHECK_ENTSIZE (section
, i
, Rela
);
7269 if (do_checks
&& section
->sh_size
== 0)
7270 warn (_("Section '%s': zero-sized relocation section\n"), name
);
7274 CHECK_ENTSIZE (section
, i
, Relr
);
7279 /* Having a zero sized section is not illegal according to the
7280 ELF standard, but it might be an indication that something
7281 is wrong. So issue a warning if we are running in lint mode. */
7282 if (do_checks
&& section
->sh_size
== 0)
7283 warn (_("Section '%s': has a size of zero - is this intended ?\n"), name
);
7290 if ((do_debugging
|| do_debug_info
|| do_debug_abbrevs
7291 || do_debug_lines
|| do_debug_pubnames
|| do_debug_pubtypes
7292 || do_debug_aranges
|| do_debug_frames
|| do_debug_macinfo
7293 || do_debug_str
|| do_debug_str_offsets
|| do_debug_loc
7295 || do_debug_addr
|| do_debug_cu_index
|| do_debug_links
)
7296 && (startswith (name
, ".debug_")
7297 || startswith (name
, ".zdebug_")))
7300 name
+= sizeof (".zdebug_") - 1;
7302 name
+= sizeof (".debug_") - 1;
7305 || (do_debug_info
&& startswith (name
, "info"))
7306 || (do_debug_info
&& startswith (name
, "types"))
7307 || (do_debug_abbrevs
&& startswith (name
, "abbrev"))
7308 || (do_debug_lines
&& strcmp (name
, "line") == 0)
7309 || (do_debug_lines
&& startswith (name
, "line."))
7310 || (do_debug_pubnames
&& startswith (name
, "pubnames"))
7311 || (do_debug_pubtypes
&& startswith (name
, "pubtypes"))
7312 || (do_debug_pubnames
&& startswith (name
, "gnu_pubnames"))
7313 || (do_debug_pubtypes
&& startswith (name
, "gnu_pubtypes"))
7314 || (do_debug_aranges
&& startswith (name
, "aranges"))
7315 || (do_debug_ranges
&& startswith (name
, "ranges"))
7316 || (do_debug_ranges
&& startswith (name
, "rnglists"))
7317 || (do_debug_frames
&& startswith (name
, "frame"))
7318 || (do_debug_macinfo
&& startswith (name
, "macinfo"))
7319 || (do_debug_macinfo
&& startswith (name
, "macro"))
7320 || (do_debug_str
&& startswith (name
, "str"))
7321 || (do_debug_links
&& startswith (name
, "sup"))
7322 || (do_debug_str_offsets
&& startswith (name
, "str_offsets"))
7323 || (do_debug_loc
&& startswith (name
, "loc"))
7324 || (do_debug_loc
&& startswith (name
, "loclists"))
7325 || (do_debug_addr
&& startswith (name
, "addr"))
7326 || (do_debug_cu_index
&& startswith (name
, "cu_index"))
7327 || (do_debug_cu_index
&& startswith (name
, "tu_index"))
7329 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
7331 /* Linkonce section to be combined with .debug_info at link time. */
7332 else if ((do_debugging
|| do_debug_info
)
7333 && startswith (name
, ".gnu.linkonce.wi."))
7334 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
7335 else if (do_debug_frames
&& streq (name
, ".eh_frame"))
7336 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
7337 else if (do_gdb_index
&& (streq (name
, ".gdb_index")
7338 || streq (name
, ".debug_names")))
7339 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
7340 /* Trace sections for Itanium VMS. */
7341 else if ((do_debugging
|| do_trace_info
|| do_trace_abbrevs
7342 || do_trace_aranges
)
7343 && startswith (name
, ".trace_"))
7345 name
+= sizeof (".trace_") - 1;
7348 || (do_trace_info
&& streq (name
, "info"))
7349 || (do_trace_abbrevs
&& streq (name
, "abbrev"))
7350 || (do_trace_aranges
&& streq (name
, "aranges"))
7352 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
7354 else if ((do_debugging
|| do_debug_links
)
7355 && (startswith (name
, ".gnu_debuglink")
7356 || startswith (name
, ".gnu_debugaltlink")))
7357 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
7363 if (filedata
->is_separate
&& ! process_links
)
7366 if (filedata
->is_separate
)
7367 printf (_("\nSection Headers in linked file '%s':\n"), filedata
->file_name
);
7368 else if (filedata
->file_header
.e_shnum
> 1)
7369 printf (_("\nSection Headers:\n"));
7371 printf (_("\nSection Header:\n"));
7375 if (do_section_details
)
7377 printf (_(" [Nr] Name\n"));
7378 printf (_(" Type Addr Off Size ES Lk Inf Al\n"));
7382 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
7386 if (do_section_details
)
7388 printf (_(" [Nr] Name\n"));
7389 printf (_(" Type Address Off Size ES Lk Inf Al\n"));
7393 (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n"));
7397 if (do_section_details
)
7399 printf (_(" [Nr] Name\n"));
7400 printf (_(" Type Address Offset Link\n"));
7401 printf (_(" Size EntSize Info Align\n"));
7405 printf (_(" [Nr] Name Type Address Offset\n"));
7406 printf (_(" Size EntSize Flags Link Info Align\n"));
7410 if (do_section_details
)
7411 printf (_(" Flags\n"));
7413 for (i
= 0, section
= filedata
->section_headers
;
7414 i
< filedata
->file_header
.e_shnum
;
7417 /* Run some sanity checks on the section header. */
7419 /* Check the sh_link field. */
7420 switch (section
->sh_type
)
7424 if (section
->sh_link
== 0
7425 && (filedata
->file_header
.e_type
== ET_EXEC
7426 || filedata
->file_header
.e_type
== ET_DYN
))
7427 /* A dynamic relocation section where all entries use a
7428 zero symbol index need not specify a symtab section. */
7431 case SHT_SYMTAB_SHNDX
:
7435 case SHT_GNU_versym
:
7436 if (section
->sh_link
== 0
7437 || section
->sh_link
>= filedata
->file_header
.e_shnum
7438 || (filedata
->section_headers
[section
->sh_link
].sh_type
!= SHT_SYMTAB
7439 && filedata
->section_headers
[section
->sh_link
].sh_type
!= SHT_DYNSYM
))
7440 warn (_("[%2u]: Link field (%u) should index a symtab section.\n"),
7441 i
, section
->sh_link
);
7447 case SHT_GNU_verneed
:
7448 case SHT_GNU_verdef
:
7449 case SHT_GNU_LIBLIST
:
7450 if (section
->sh_link
== 0
7451 || section
->sh_link
>= filedata
->file_header
.e_shnum
7452 || filedata
->section_headers
[section
->sh_link
].sh_type
!= SHT_STRTAB
)
7453 warn (_("[%2u]: Link field (%u) should index a string section.\n"),
7454 i
, section
->sh_link
);
7457 case SHT_INIT_ARRAY
:
7458 case SHT_FINI_ARRAY
:
7459 case SHT_PREINIT_ARRAY
:
7460 if (section
->sh_type
< SHT_LOOS
&& section
->sh_link
!= 0)
7461 warn (_("[%2u]: Unexpected value (%u) in link field.\n"),
7462 i
, section
->sh_link
);
7466 /* FIXME: Add support for target specific section types. */
7467 #if 0 /* Currently we do not check other section types as there are too
7468 many special cases. Stab sections for example have a type
7469 of SHT_PROGBITS but an sh_link field that links to the .stabstr
7471 if (section
->sh_type
< SHT_LOOS
&& section
->sh_link
!= 0)
7472 warn (_("[%2u]: Unexpected value (%u) in link field.\n"),
7473 i
, section
->sh_link
);
7478 /* Check the sh_info field. */
7479 switch (section
->sh_type
)
7483 if (section
->sh_info
== 0
7484 && (filedata
->file_header
.e_type
== ET_EXEC
7485 || filedata
->file_header
.e_type
== ET_DYN
))
7486 /* Dynamic relocations apply to segments, so they do not
7487 need to specify the section they relocate. */
7489 if (section
->sh_info
== 0
7490 || section
->sh_info
>= filedata
->file_header
.e_shnum
7491 || (filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_PROGBITS
7492 && filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_NOBITS
7493 && filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_NOTE
7494 && filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_INIT_ARRAY
7495 && filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_FINI_ARRAY
7496 && filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_PREINIT_ARRAY
7497 /* FIXME: Are other section types valid ? */
7498 && filedata
->section_headers
[section
->sh_info
].sh_type
< SHT_LOOS
))
7499 warn (_("[%2u]: Info field (%u) should index a relocatable section.\n"),
7500 i
, section
->sh_info
);
7505 case SHT_SYMTAB_SHNDX
:
7506 case SHT_INIT_ARRAY
:
7507 case SHT_FINI_ARRAY
:
7508 case SHT_PREINIT_ARRAY
:
7509 if (section
->sh_info
!= 0)
7510 warn (_("[%2u]: Unexpected value (%u) in info field.\n"),
7511 i
, section
->sh_info
);
7517 /* A symbol index - we assume that it is valid. */
7521 /* FIXME: Add support for target specific section types. */
7522 if (section
->sh_type
== SHT_NOBITS
)
7523 /* NOBITS section headers with non-zero sh_info fields can be
7524 created when a binary is stripped of everything but its debug
7525 information. The stripped sections have their headers
7526 preserved but their types set to SHT_NOBITS. So do not check
7527 this type of section. */
7529 else if (section
->sh_flags
& SHF_INFO_LINK
)
7531 if (section
->sh_info
< 1 || section
->sh_info
>= filedata
->file_header
.e_shnum
)
7532 warn (_("[%2u]: Expected link to another section in info field"), i
);
7534 else if (section
->sh_type
< SHT_LOOS
7535 && (section
->sh_flags
& SHF_GNU_MBIND
) == 0
7536 && section
->sh_info
!= 0)
7537 warn (_("[%2u]: Unexpected value (%u) in info field.\n"),
7538 i
, section
->sh_info
);
7542 /* Check the sh_size field. */
7543 if (section
->sh_size
> filedata
->file_size
7544 && section
->sh_type
!= SHT_NOBITS
7545 && section
->sh_type
!= SHT_NULL
7546 && section
->sh_type
< SHT_LOOS
)
7547 warn (_("Size of section %u is larger than the entire file!\n"), i
);
7549 printf (" [%2u] ", i
);
7550 if (do_section_details
)
7551 printf ("%s\n ", printable_section_name (filedata
, section
));
7553 print_symbol (-17, section_name_print (filedata
, section
));
7555 printf (do_wide
? " %-15s " : " %-15.15s ",
7556 get_section_type_name (filedata
, section
->sh_type
));
7560 const char * link_too_big
= NULL
;
7562 print_vma (section
->sh_addr
, LONG_HEX
);
7564 printf ( " %6.6lx %6.6lx %2.2lx",
7565 (unsigned long) section
->sh_offset
,
7566 (unsigned long) section
->sh_size
,
7567 (unsigned long) section
->sh_entsize
);
7569 if (do_section_details
)
7570 fputs (" ", stdout
);
7572 printf (" %3s ", get_elf_section_flags (filedata
, section
->sh_flags
));
7574 if (section
->sh_link
>= filedata
->file_header
.e_shnum
)
7577 /* The sh_link value is out of range. Normally this indicates
7578 an error but it can have special values in Solaris binaries. */
7579 switch (filedata
->file_header
.e_machine
)
7586 case EM_OLD_SPARCV9
:
7587 case EM_SPARC32PLUS
:
7590 if (section
->sh_link
== (SHN_BEFORE
& 0xffff))
7591 link_too_big
= "BEFORE";
7592 else if (section
->sh_link
== (SHN_AFTER
& 0xffff))
7593 link_too_big
= "AFTER";
7600 if (do_section_details
)
7602 if (link_too_big
!= NULL
&& * link_too_big
)
7603 printf ("<%s> ", link_too_big
);
7605 printf ("%2u ", section
->sh_link
);
7606 printf ("%3u %2lu\n", section
->sh_info
,
7607 (unsigned long) section
->sh_addralign
);
7610 printf ("%2u %3u %2lu\n",
7613 (unsigned long) section
->sh_addralign
);
7615 if (link_too_big
&& ! * link_too_big
)
7616 warn (_("section %u: sh_link value of %u is larger than the number of sections\n"),
7617 i
, section
->sh_link
);
7621 print_vma (section
->sh_addr
, LONG_HEX
);
7623 if ((long) section
->sh_offset
== section
->sh_offset
)
7624 printf (" %6.6lx", (unsigned long) section
->sh_offset
);
7628 print_vma (section
->sh_offset
, LONG_HEX
);
7631 if ((unsigned long) section
->sh_size
== section
->sh_size
)
7632 printf (" %6.6lx", (unsigned long) section
->sh_size
);
7636 print_vma (section
->sh_size
, LONG_HEX
);
7639 if ((unsigned long) section
->sh_entsize
== section
->sh_entsize
)
7640 printf (" %2.2lx", (unsigned long) section
->sh_entsize
);
7644 print_vma (section
->sh_entsize
, LONG_HEX
);
7647 if (do_section_details
)
7648 fputs (" ", stdout
);
7650 printf (" %3s ", get_elf_section_flags (filedata
, section
->sh_flags
));
7652 printf ("%2u %3u ", section
->sh_link
, section
->sh_info
);
7654 if ((unsigned long) section
->sh_addralign
== section
->sh_addralign
)
7655 printf ("%2lu\n", (unsigned long) section
->sh_addralign
);
7658 print_vma (section
->sh_addralign
, DEC
);
7662 else if (do_section_details
)
7665 print_vma (section
->sh_addr
, LONG_HEX
);
7666 if ((long) section
->sh_offset
== section
->sh_offset
)
7667 printf (" %16.16lx", (unsigned long) section
->sh_offset
);
7671 print_vma (section
->sh_offset
, LONG_HEX
);
7673 printf (" %u\n ", section
->sh_link
);
7674 print_vma (section
->sh_size
, LONG_HEX
);
7676 print_vma (section
->sh_entsize
, LONG_HEX
);
7678 printf (" %-16u %lu\n",
7680 (unsigned long) section
->sh_addralign
);
7685 print_vma (section
->sh_addr
, LONG_HEX
);
7686 if ((long) section
->sh_offset
== section
->sh_offset
)
7687 printf (" %8.8lx", (unsigned long) section
->sh_offset
);
7691 print_vma (section
->sh_offset
, LONG_HEX
);
7694 print_vma (section
->sh_size
, LONG_HEX
);
7696 print_vma (section
->sh_entsize
, LONG_HEX
);
7698 printf (" %3s ", get_elf_section_flags (filedata
, section
->sh_flags
));
7700 printf (" %2u %3u %lu\n",
7703 (unsigned long) section
->sh_addralign
);
7706 if (do_section_details
)
7708 printf (" %s\n", get_elf_section_flags (filedata
, section
->sh_flags
));
7709 if ((section
->sh_flags
& SHF_COMPRESSED
) != 0)
7711 /* Minimum section size is 12 bytes for 32-bit compression
7712 header + 12 bytes for compressed data header. */
7713 unsigned char buf
[24];
7715 assert (sizeof (buf
) >= sizeof (Elf64_External_Chdr
));
7716 if (get_data (&buf
, filedata
, section
->sh_offset
, 1,
7717 sizeof (buf
), _("compression header")))
7719 Elf_Internal_Chdr chdr
;
7721 if (get_compression_header (&chdr
, buf
, sizeof (buf
)) == 0)
7722 printf (_(" [<corrupt>]\n"));
7725 if (chdr
.ch_type
== ELFCOMPRESS_ZLIB
)
7728 printf (_(" [<unknown>: 0x%x], "),
7730 print_vma (chdr
.ch_size
, LONG_HEX
);
7731 printf (", %lu\n", (unsigned long) chdr
.ch_addralign
);
7738 if (!do_section_details
)
7740 /* The ordering of the letters shown here matches the ordering of the
7741 corresponding SHF_xxx values, and hence the order in which these
7742 letters will be displayed to the user. */
7743 printf (_("Key to Flags:\n\
7744 W (write), A (alloc), X (execute), M (merge), S (strings), I (info),\n\
7745 L (link order), O (extra OS processing required), G (group), T (TLS),\n\
7746 C (compressed), x (unknown), o (OS specific), E (exclude),\n "));
7747 switch (filedata
->file_header
.e_ident
[EI_OSABI
])
7750 case ELFOSABI_FREEBSD
:
7751 printf (_("R (retain), "));
7754 printf (_("D (mbind), "));
7759 if (filedata
->file_header
.e_machine
== EM_X86_64
7760 || filedata
->file_header
.e_machine
== EM_L1OM
7761 || filedata
->file_header
.e_machine
== EM_K1OM
)
7762 printf (_("l (large), "));
7763 else if (filedata
->file_header
.e_machine
== EM_ARM
)
7764 printf (_("y (purecode), "));
7765 else if (filedata
->file_header
.e_machine
== EM_PPC
)
7766 printf (_("v (VLE), "));
7767 printf ("p (processor specific)\n");
7774 get_symtab (Filedata
*filedata
, Elf_Internal_Shdr
*symsec
,
7775 Elf_Internal_Sym
**symtab
, unsigned long *nsyms
,
7776 char **strtab
, unsigned long *strtablen
)
7780 *symtab
= get_elf_symbols (filedata
, symsec
, nsyms
);
7782 if (*symtab
== NULL
)
7785 if (symsec
->sh_link
!= 0)
7787 Elf_Internal_Shdr
*strsec
;
7789 if (symsec
->sh_link
>= filedata
->file_header
.e_shnum
)
7791 error (_("Bad sh_link in symbol table section\n"));
7798 strsec
= filedata
->section_headers
+ symsec
->sh_link
;
7800 *strtab
= (char *) get_data (NULL
, filedata
, strsec
->sh_offset
,
7801 1, strsec
->sh_size
, _("string table"));
7802 if (*strtab
== NULL
)
7809 *strtablen
= strsec
->sh_size
;
7815 get_group_flags (unsigned int flags
)
7817 static char buff
[128];
7821 else if (flags
== GRP_COMDAT
)
7824 snprintf (buff
, sizeof buff
, "[0x%x: %s%s%s]",
7826 flags
& GRP_MASKOS
? _("<OS specific>") : "",
7827 flags
& GRP_MASKPROC
? _("<PROC specific>") : "",
7828 (flags
& ~(GRP_COMDAT
| GRP_MASKOS
| GRP_MASKPROC
)
7829 ? _("<unknown>") : ""));
7835 process_section_groups (Filedata
* filedata
)
7837 Elf_Internal_Shdr
* section
;
7839 struct group
* group
;
7840 Elf_Internal_Shdr
* symtab_sec
;
7841 Elf_Internal_Shdr
* strtab_sec
;
7842 Elf_Internal_Sym
* symtab
;
7843 unsigned long num_syms
;
7847 /* Don't process section groups unless needed. */
7848 if (!do_unwind
&& !do_section_groups
)
7851 if (filedata
->file_header
.e_shnum
== 0)
7853 if (do_section_groups
)
7855 if (filedata
->is_separate
)
7856 printf (_("\nThere are no sections group in linked file '%s'.\n"),
7857 filedata
->file_name
);
7859 printf (_("\nThere are no section groups in this file.\n"));
7864 if (filedata
->section_headers
== NULL
)
7866 error (_("Section headers are not available!\n"));
7867 /* PR 13622: This can happen with a corrupt ELF header. */
7871 filedata
->section_headers_groups
7872 = (struct group
**) calloc (filedata
->file_header
.e_shnum
,
7873 sizeof (struct group
*));
7875 if (filedata
->section_headers_groups
== NULL
)
7877 error (_("Out of memory reading %u section group headers\n"),
7878 filedata
->file_header
.e_shnum
);
7882 /* Scan the sections for the group section. */
7883 filedata
->group_count
= 0;
7884 for (i
= 0, section
= filedata
->section_headers
;
7885 i
< filedata
->file_header
.e_shnum
;
7887 if (section
->sh_type
== SHT_GROUP
)
7888 filedata
->group_count
++;
7890 if (filedata
->group_count
== 0)
7892 if (do_section_groups
)
7894 if (filedata
->is_separate
)
7895 printf (_("\nThere are no section groups in linked file '%s'.\n"),
7896 filedata
->file_name
);
7898 printf (_("\nThere are no section groups in this file.\n"));
7904 filedata
->section_groups
= (struct group
*) calloc (filedata
->group_count
,
7905 sizeof (struct group
));
7907 if (filedata
->section_groups
== NULL
)
7909 error (_("Out of memory reading %lu groups\n"),
7910 (unsigned long) filedata
->group_count
);
7921 if (filedata
->is_separate
)
7922 printf (_("Section groups in linked file '%s'\n"), filedata
->file_name
);
7924 for (i
= 0, section
= filedata
->section_headers
, group
= filedata
->section_groups
;
7925 i
< filedata
->file_header
.e_shnum
;
7928 if (section
->sh_type
== SHT_GROUP
)
7930 const char * name
= printable_section_name (filedata
, section
);
7931 const char * group_name
;
7932 unsigned char * start
;
7933 unsigned char * indices
;
7934 unsigned int entry
, j
, size
;
7935 Elf_Internal_Shdr
* sec
;
7936 Elf_Internal_Sym
* sym
;
7938 /* Get the symbol table. */
7939 if (section
->sh_link
>= filedata
->file_header
.e_shnum
7940 || ((sec
= filedata
->section_headers
+ section
->sh_link
)->sh_type
7943 error (_("Bad sh_link in group section `%s'\n"), name
);
7947 if (symtab_sec
!= sec
)
7951 symtab
= get_elf_symbols (filedata
, symtab_sec
, & num_syms
);
7956 error (_("Corrupt header in group section `%s'\n"), name
);
7960 if (section
->sh_info
>= num_syms
)
7962 error (_("Bad sh_info in group section `%s'\n"), name
);
7966 sym
= symtab
+ section
->sh_info
;
7968 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
7970 if (sym
->st_shndx
== 0
7971 || sym
->st_shndx
>= filedata
->file_header
.e_shnum
)
7973 error (_("Bad sh_info in group section `%s'\n"), name
);
7977 group_name
= section_name_print (filedata
,
7978 filedata
->section_headers
7987 /* Get the string table. */
7988 if (symtab_sec
->sh_link
>= filedata
->file_header
.e_shnum
)
7996 != (sec
= filedata
->section_headers
+ symtab_sec
->sh_link
))
8001 strtab
= (char *) get_data (NULL
, filedata
, strtab_sec
->sh_offset
,
8002 1, strtab_sec
->sh_size
,
8004 strtab_size
= strtab
!= NULL
? strtab_sec
->sh_size
: 0;
8006 group_name
= sym
->st_name
< strtab_size
8007 ? strtab
+ sym
->st_name
: _("<corrupt>");
8010 /* PR 17531: file: loop. */
8011 if (section
->sh_entsize
> section
->sh_size
)
8013 error (_("Section %s has sh_entsize (0x%lx) which is larger than its size (0x%lx)\n"),
8014 printable_section_name (filedata
, section
),
8015 (unsigned long) section
->sh_entsize
,
8016 (unsigned long) section
->sh_size
);
8020 start
= (unsigned char *) get_data (NULL
, filedata
, section
->sh_offset
,
8021 1, section
->sh_size
,
8027 size
= (section
->sh_size
/ section
->sh_entsize
) - 1;
8028 entry
= byte_get (indices
, 4);
8031 if (do_section_groups
)
8033 printf (_("\n%sgroup section [%5u] `%s' [%s] contains %u sections:\n"),
8034 get_group_flags (entry
), i
, name
, group_name
, size
);
8036 printf (_(" [Index] Name\n"));
8039 group
->group_index
= i
;
8041 for (j
= 0; j
< size
; j
++)
8043 struct group_list
* g
;
8045 entry
= byte_get (indices
, 4);
8048 if (entry
>= filedata
->file_header
.e_shnum
)
8050 static unsigned num_group_errors
= 0;
8052 if (num_group_errors
++ < 10)
8054 error (_("section [%5u] in group section [%5u] > maximum section [%5u]\n"),
8055 entry
, i
, filedata
->file_header
.e_shnum
- 1);
8056 if (num_group_errors
== 10)
8057 warn (_("Further error messages about overlarge group section indices suppressed\n"));
8062 if (filedata
->section_headers_groups
[entry
] != NULL
)
8066 static unsigned num_errs
= 0;
8068 if (num_errs
++ < 10)
8070 error (_("section [%5u] in group section [%5u] already in group section [%5u]\n"),
8072 filedata
->section_headers_groups
[entry
]->group_index
);
8074 warn (_("Further error messages about already contained group sections suppressed\n"));
8080 /* Intel C/C++ compiler may put section 0 in a
8081 section group. We just warn it the first time
8082 and ignore it afterwards. */
8083 static bool warned
= false;
8086 error (_("section 0 in group section [%5u]\n"),
8087 filedata
->section_headers_groups
[entry
]->group_index
);
8093 filedata
->section_headers_groups
[entry
] = group
;
8095 if (do_section_groups
)
8097 sec
= filedata
->section_headers
+ entry
;
8098 printf (" [%5u] %s\n", entry
, printable_section_name (filedata
, sec
));
8101 g
= (struct group_list
*) xmalloc (sizeof (struct group_list
));
8102 g
->section_index
= entry
;
8103 g
->next
= group
->root
;
8118 /* Data used to display dynamic fixups. */
8120 struct ia64_vms_dynfixup
8122 bfd_vma needed_ident
; /* Library ident number. */
8123 bfd_vma needed
; /* Index in the dstrtab of the library name. */
8124 bfd_vma fixup_needed
; /* Index of the library. */
8125 bfd_vma fixup_rela_cnt
; /* Number of fixups. */
8126 bfd_vma fixup_rela_off
; /* Fixups offset in the dynamic segment. */
8129 /* Data used to display dynamic relocations. */
8131 struct ia64_vms_dynimgrela
8133 bfd_vma img_rela_cnt
; /* Number of relocations. */
8134 bfd_vma img_rela_off
; /* Reloc offset in the dynamic segment. */
8137 /* Display IA-64 OpenVMS dynamic fixups (used to dynamically link a shared
8141 dump_ia64_vms_dynamic_fixups (Filedata
* filedata
,
8142 struct ia64_vms_dynfixup
* fixup
,
8143 const char * strtab
,
8144 unsigned int strtab_sz
)
8146 Elf64_External_VMS_IMAGE_FIXUP
* imfs
;
8148 const char * lib_name
;
8150 imfs
= get_data (NULL
, filedata
,
8151 filedata
->dynamic_addr
+ fixup
->fixup_rela_off
,
8152 sizeof (*imfs
), fixup
->fixup_rela_cnt
,
8153 _("dynamic section image fixups"));
8157 if (fixup
->needed
< strtab_sz
)
8158 lib_name
= strtab
+ fixup
->needed
;
8161 warn (_("corrupt library name index of 0x%lx found in dynamic entry"),
8162 (unsigned long) fixup
->needed
);
8166 printf (_("\nImage fixups for needed library #%d: %s - ident: %lx\n"),
8167 (int) fixup
->fixup_needed
, lib_name
, (long) fixup
->needed_ident
);
8169 (_("Seg Offset Type SymVec DataType\n"));
8171 for (i
= 0; i
< (long) fixup
->fixup_rela_cnt
; i
++)
8176 printf ("%3u ", (unsigned) BYTE_GET (imfs
[i
].fixup_seg
));
8177 printf_vma ((bfd_vma
) BYTE_GET (imfs
[i
].fixup_offset
));
8178 type
= BYTE_GET (imfs
[i
].type
);
8179 rtype
= elf_ia64_reloc_type (type
);
8181 printf (" 0x%08x ", type
);
8183 printf (" %-32s ", rtype
);
8184 printf ("%6u ", (unsigned) BYTE_GET (imfs
[i
].symvec_index
));
8185 printf ("0x%08x\n", (unsigned) BYTE_GET (imfs
[i
].data_type
));
8192 /* Display IA-64 OpenVMS dynamic relocations (used to relocate an image). */
8195 dump_ia64_vms_dynamic_relocs (Filedata
* filedata
, struct ia64_vms_dynimgrela
*imgrela
)
8197 Elf64_External_VMS_IMAGE_RELA
*imrs
;
8200 imrs
= get_data (NULL
, filedata
,
8201 filedata
->dynamic_addr
+ imgrela
->img_rela_off
,
8202 sizeof (*imrs
), imgrela
->img_rela_cnt
,
8203 _("dynamic section image relocations"));
8207 printf (_("\nImage relocs\n"));
8209 (_("Seg Offset Type Addend Seg Sym Off\n"));
8211 for (i
= 0; i
< (long) imgrela
->img_rela_cnt
; i
++)
8216 printf ("%3u ", (unsigned) BYTE_GET (imrs
[i
].rela_seg
));
8217 printf ("%08" BFD_VMA_FMT
"x ",
8218 (bfd_vma
) BYTE_GET (imrs
[i
].rela_offset
));
8219 type
= BYTE_GET (imrs
[i
].type
);
8220 rtype
= elf_ia64_reloc_type (type
);
8222 printf ("0x%08x ", type
);
8224 printf ("%-31s ", rtype
);
8225 print_vma (BYTE_GET (imrs
[i
].addend
), FULL_HEX
);
8226 printf ("%3u ", (unsigned) BYTE_GET (imrs
[i
].sym_seg
));
8227 printf ("%08" BFD_VMA_FMT
"x\n",
8228 (bfd_vma
) BYTE_GET (imrs
[i
].sym_offset
));
8235 /* Display IA-64 OpenVMS dynamic relocations and fixups. */
8238 process_ia64_vms_dynamic_relocs (Filedata
* filedata
)
8240 struct ia64_vms_dynfixup fixup
;
8241 struct ia64_vms_dynimgrela imgrela
;
8242 Elf_Internal_Dyn
*entry
;
8243 bfd_vma strtab_off
= 0;
8244 bfd_vma strtab_sz
= 0;
8245 char *strtab
= NULL
;
8248 memset (&fixup
, 0, sizeof (fixup
));
8249 memset (&imgrela
, 0, sizeof (imgrela
));
8251 /* Note: the order of the entries is specified by the OpenVMS specs. */
8252 for (entry
= filedata
->dynamic_section
;
8253 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
8256 switch (entry
->d_tag
)
8258 case DT_IA_64_VMS_STRTAB_OFFSET
:
8259 strtab_off
= entry
->d_un
.d_val
;
8262 strtab_sz
= entry
->d_un
.d_val
;
8264 strtab
= get_data (NULL
, filedata
,
8265 filedata
->dynamic_addr
+ strtab_off
,
8266 1, strtab_sz
, _("dynamic string section"));
8271 case DT_IA_64_VMS_NEEDED_IDENT
:
8272 fixup
.needed_ident
= entry
->d_un
.d_val
;
8275 fixup
.needed
= entry
->d_un
.d_val
;
8277 case DT_IA_64_VMS_FIXUP_NEEDED
:
8278 fixup
.fixup_needed
= entry
->d_un
.d_val
;
8280 case DT_IA_64_VMS_FIXUP_RELA_CNT
:
8281 fixup
.fixup_rela_cnt
= entry
->d_un
.d_val
;
8283 case DT_IA_64_VMS_FIXUP_RELA_OFF
:
8284 fixup
.fixup_rela_off
= entry
->d_un
.d_val
;
8285 if (! dump_ia64_vms_dynamic_fixups (filedata
, &fixup
, strtab
, strtab_sz
))
8288 case DT_IA_64_VMS_IMG_RELA_CNT
:
8289 imgrela
.img_rela_cnt
= entry
->d_un
.d_val
;
8291 case DT_IA_64_VMS_IMG_RELA_OFF
:
8292 imgrela
.img_rela_off
= entry
->d_un
.d_val
;
8293 if (! dump_ia64_vms_dynamic_relocs (filedata
, &imgrela
))
8312 relocation_type rel_type
;
8314 dynamic_relocations
[] =
8316 { "REL", DT_REL
, DT_RELSZ
, reltype_rel
},
8317 { "RELA", DT_RELA
, DT_RELASZ
, reltype_rela
},
8318 { "RELR", DT_RELR
, DT_RELRSZ
, reltype_relr
},
8319 { "PLT", DT_JMPREL
, DT_PLTRELSZ
, reltype_unknown
}
8322 /* Process the reloc section. */
8325 process_relocs (Filedata
* filedata
)
8327 unsigned long rel_size
;
8328 unsigned long rel_offset
;
8333 if (do_using_dynamic
)
8335 relocation_type rel_type
;
8337 bool has_dynamic_reloc
;
8340 has_dynamic_reloc
= false;
8342 for (i
= 0; i
< ARRAY_SIZE (dynamic_relocations
); i
++)
8344 rel_type
= dynamic_relocations
[i
].rel_type
;
8345 name
= dynamic_relocations
[i
].name
;
8346 rel_size
= filedata
->dynamic_info
[dynamic_relocations
[i
].size
];
8347 rel_offset
= filedata
->dynamic_info
[dynamic_relocations
[i
].reloc
];
8350 has_dynamic_reloc
= true;
8352 if (rel_type
== reltype_unknown
)
8354 if (dynamic_relocations
[i
].reloc
== DT_JMPREL
)
8355 switch (filedata
->dynamic_info
[DT_PLTREL
])
8358 rel_type
= reltype_rel
;
8361 rel_type
= reltype_rela
;
8368 if (filedata
->is_separate
)
8370 (_("\nIn linked file '%s' section '%s' at offset 0x%lx contains %ld bytes:\n"),
8371 filedata
->file_name
, name
, rel_offset
, rel_size
);
8374 (_("\n'%s' relocation section at offset 0x%lx contains %ld bytes:\n"),
8375 name
, rel_offset
, rel_size
);
8377 dump_relocations (filedata
,
8378 offset_from_vma (filedata
, rel_offset
, rel_size
),
8380 filedata
->dynamic_symbols
,
8381 filedata
->num_dynamic_syms
,
8382 filedata
->dynamic_strings
,
8383 filedata
->dynamic_strings_length
,
8384 rel_type
, true /* is_dynamic */);
8388 if (is_ia64_vms (filedata
))
8389 if (process_ia64_vms_dynamic_relocs (filedata
))
8390 has_dynamic_reloc
= true;
8392 if (! has_dynamic_reloc
)
8394 if (filedata
->is_separate
)
8395 printf (_("\nThere are no dynamic relocations in linked file '%s'.\n"),
8396 filedata
->file_name
);
8398 printf (_("\nThere are no dynamic relocations in this file.\n"));
8403 Elf_Internal_Shdr
* section
;
8407 for (i
= 0, section
= filedata
->section_headers
;
8408 i
< filedata
->file_header
.e_shnum
;
8411 if ( section
->sh_type
!= SHT_RELA
8412 && section
->sh_type
!= SHT_REL
8413 && section
->sh_type
!= SHT_RELR
)
8416 rel_offset
= section
->sh_offset
;
8417 rel_size
= section
->sh_size
;
8421 relocation_type rel_type
;
8422 unsigned long num_rela
;
8424 if (filedata
->is_separate
)
8425 printf (_("\nIn linked file '%s' relocation section "),
8426 filedata
->file_name
);
8428 printf (_("\nRelocation section "));
8430 if (filedata
->string_table
== NULL
)
8431 printf ("%d", section
->sh_name
);
8433 printf ("'%s'", printable_section_name (filedata
, section
));
8435 num_rela
= rel_size
/ section
->sh_entsize
;
8436 printf (ngettext (" at offset 0x%lx contains %lu entry:\n",
8437 " at offset 0x%lx contains %lu entries:\n",
8439 rel_offset
, num_rela
);
8441 rel_type
= section
->sh_type
== SHT_RELA
? reltype_rela
:
8442 section
->sh_type
== SHT_REL
? reltype_rel
: reltype_relr
;
8444 if (section
->sh_link
!= 0
8445 && section
->sh_link
< filedata
->file_header
.e_shnum
)
8447 Elf_Internal_Shdr
* symsec
;
8448 Elf_Internal_Sym
* symtab
;
8449 unsigned long nsyms
;
8450 unsigned long strtablen
= 0;
8451 char * strtab
= NULL
;
8453 symsec
= filedata
->section_headers
+ section
->sh_link
;
8454 if (symsec
->sh_type
!= SHT_SYMTAB
8455 && symsec
->sh_type
!= SHT_DYNSYM
)
8458 if (!get_symtab (filedata
, symsec
,
8459 &symtab
, &nsyms
, &strtab
, &strtablen
))
8462 dump_relocations (filedata
, rel_offset
, rel_size
,
8463 symtab
, nsyms
, strtab
, strtablen
,
8465 symsec
->sh_type
== SHT_DYNSYM
);
8470 dump_relocations (filedata
, rel_offset
, rel_size
,
8471 NULL
, 0, NULL
, 0, rel_type
, false /* is_dynamic */);
8479 /* Users sometimes forget the -D option, so try to be helpful. */
8480 for (i
= 0; i
< ARRAY_SIZE (dynamic_relocations
); i
++)
8482 if (filedata
->dynamic_info
[dynamic_relocations
[i
].size
])
8484 if (filedata
->is_separate
)
8485 printf (_("\nThere are no static relocations in linked file '%s'."),
8486 filedata
->file_name
);
8488 printf (_("\nThere are no static relocations in this file."));
8489 printf (_("\nTo see the dynamic relocations add --use-dynamic to the command line.\n"));
8494 if (i
== ARRAY_SIZE (dynamic_relocations
))
8496 if (filedata
->is_separate
)
8497 printf (_("\nThere are no relocations in linked file '%s'.\n"),
8498 filedata
->file_name
);
8500 printf (_("\nThere are no relocations in this file.\n"));
8508 /* An absolute address consists of a section and an offset. If the
8509 section is NULL, the offset itself is the address, otherwise, the
8510 address equals to LOAD_ADDRESS(section) + offset. */
8514 unsigned short section
;
8518 /* Find the nearest symbol at or below ADDR. Returns the symbol
8519 name, if found, and the offset from the symbol to ADDR. */
8522 find_symbol_for_address (Filedata
* filedata
,
8523 Elf_Internal_Sym
* symtab
,
8524 unsigned long nsyms
,
8525 const char * strtab
,
8526 unsigned long strtab_size
,
8527 struct absaddr addr
,
8528 const char ** symname
,
8531 bfd_vma dist
= 0x100000;
8532 Elf_Internal_Sym
* sym
;
8533 Elf_Internal_Sym
* beg
;
8534 Elf_Internal_Sym
* end
;
8535 Elf_Internal_Sym
* best
= NULL
;
8537 REMOVE_ARCH_BITS (addr
.offset
);
8539 end
= symtab
+ nsyms
;
8545 sym
= beg
+ (end
- beg
) / 2;
8547 value
= sym
->st_value
;
8548 REMOVE_ARCH_BITS (value
);
8550 if (sym
->st_name
!= 0
8551 && (addr
.section
== SHN_UNDEF
|| addr
.section
== sym
->st_shndx
)
8552 && addr
.offset
>= value
8553 && addr
.offset
- value
< dist
)
8556 dist
= addr
.offset
- value
;
8561 if (addr
.offset
< value
)
8569 *symname
= (best
->st_name
>= strtab_size
8570 ? _("<corrupt>") : strtab
+ best
->st_name
);
8576 *offset
= addr
.offset
;
8579 static /* signed */ int
8580 symcmp (const void *p
, const void *q
)
8582 Elf_Internal_Sym
*sp
= (Elf_Internal_Sym
*) p
;
8583 Elf_Internal_Sym
*sq
= (Elf_Internal_Sym
*) q
;
8585 return sp
->st_value
> sq
->st_value
? 1 : (sp
->st_value
< sq
->st_value
? -1 : 0);
8588 /* Process the unwind section. */
8590 #include "unwind-ia64.h"
8592 struct ia64_unw_table_entry
8594 struct absaddr start
;
8596 struct absaddr info
;
8599 struct ia64_unw_aux_info
8601 struct ia64_unw_table_entry
* table
; /* Unwind table. */
8602 unsigned long table_len
; /* Length of unwind table. */
8603 unsigned char * info
; /* Unwind info. */
8604 unsigned long info_size
; /* Size of unwind info. */
8605 bfd_vma info_addr
; /* Starting address of unwind info. */
8606 bfd_vma seg_base
; /* Starting address of segment. */
8607 Elf_Internal_Sym
* symtab
; /* The symbol table. */
8608 unsigned long nsyms
; /* Number of symbols. */
8609 Elf_Internal_Sym
* funtab
; /* Sorted table of STT_FUNC symbols. */
8610 unsigned long nfuns
; /* Number of entries in funtab. */
8611 char * strtab
; /* The string table. */
8612 unsigned long strtab_size
; /* Size of string table. */
8616 dump_ia64_unwind (Filedata
* filedata
, struct ia64_unw_aux_info
* aux
)
8618 struct ia64_unw_table_entry
* tp
;
8619 unsigned long j
, nfuns
;
8623 aux
->funtab
= xmalloc (aux
->nsyms
* sizeof (Elf_Internal_Sym
));
8624 for (nfuns
= 0, j
= 0; j
< aux
->nsyms
; j
++)
8625 if (aux
->symtab
[j
].st_value
&& ELF_ST_TYPE (aux
->symtab
[j
].st_info
) == STT_FUNC
)
8626 aux
->funtab
[nfuns
++] = aux
->symtab
[j
];
8628 qsort (aux
->funtab
, aux
->nfuns
, sizeof (Elf_Internal_Sym
), symcmp
);
8630 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
8634 const unsigned char * dp
;
8635 const unsigned char * head
;
8636 const unsigned char * end
;
8637 const char * procname
;
8639 find_symbol_for_address (filedata
, aux
->funtab
, aux
->nfuns
, aux
->strtab
,
8640 aux
->strtab_size
, tp
->start
, &procname
, &offset
);
8642 fputs ("\n<", stdout
);
8646 fputs (procname
, stdout
);
8649 printf ("+%lx", (unsigned long) offset
);
8652 fputs (">: [", stdout
);
8653 print_vma (tp
->start
.offset
, PREFIX_HEX
);
8654 fputc ('-', stdout
);
8655 print_vma (tp
->end
.offset
, PREFIX_HEX
);
8656 printf ("], info at +0x%lx\n",
8657 (unsigned long) (tp
->info
.offset
- aux
->seg_base
));
8659 /* PR 17531: file: 86232b32. */
8660 if (aux
->info
== NULL
)
8663 offset
= tp
->info
.offset
;
8664 if (tp
->info
.section
)
8666 if (tp
->info
.section
>= filedata
->file_header
.e_shnum
)
8668 warn (_("Invalid section %u in table entry %ld\n"),
8669 tp
->info
.section
, (long) (tp
- aux
->table
));
8673 offset
+= filedata
->section_headers
[tp
->info
.section
].sh_addr
;
8675 offset
-= aux
->info_addr
;
8676 /* PR 17531: file: 0997b4d1. */
8677 if (offset
>= aux
->info_size
8678 || aux
->info_size
- offset
< 8)
8680 warn (_("Invalid offset %lx in table entry %ld\n"),
8681 (long) tp
->info
.offset
, (long) (tp
- aux
->table
));
8686 head
= aux
->info
+ offset
;
8687 stamp
= byte_get ((unsigned char *) head
, sizeof (stamp
));
8689 printf (" v%u, flags=0x%lx (%s%s), len=%lu bytes\n",
8690 (unsigned) UNW_VER (stamp
),
8691 (unsigned long) ((stamp
& UNW_FLAG_MASK
) >> 32),
8692 UNW_FLAG_EHANDLER (stamp
) ? " ehandler" : "",
8693 UNW_FLAG_UHANDLER (stamp
) ? " uhandler" : "",
8694 (unsigned long) (eh_addr_size
* UNW_LENGTH (stamp
)));
8696 if (UNW_VER (stamp
) != 1)
8698 printf (_("\tUnknown version.\n"));
8703 end
= head
+ 8 + eh_addr_size
* UNW_LENGTH (stamp
);
8704 /* PR 17531: file: 16ceda89. */
8705 if (end
> aux
->info
+ aux
->info_size
)
8706 end
= aux
->info
+ aux
->info_size
;
8707 for (dp
= head
+ 8; dp
< end
;)
8708 dp
= unw_decode (dp
, in_body
, & in_body
, end
);
8717 slurp_ia64_unwind_table (Filedata
* filedata
,
8718 struct ia64_unw_aux_info
* aux
,
8719 Elf_Internal_Shdr
* sec
)
8721 unsigned long size
, nrelas
, i
;
8722 Elf_Internal_Phdr
* seg
;
8723 struct ia64_unw_table_entry
* tep
;
8724 Elf_Internal_Shdr
* relsec
;
8725 Elf_Internal_Rela
* rela
;
8726 Elf_Internal_Rela
* rp
;
8727 unsigned char * table
;
8729 Elf_Internal_Sym
* sym
;
8730 const char * relname
;
8734 /* First, find the starting address of the segment that includes
8737 if (filedata
->file_header
.e_phnum
)
8739 if (! get_program_headers (filedata
))
8742 for (seg
= filedata
->program_headers
;
8743 seg
< filedata
->program_headers
+ filedata
->file_header
.e_phnum
;
8746 if (seg
->p_type
!= PT_LOAD
)
8749 if (sec
->sh_addr
>= seg
->p_vaddr
8750 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
8752 aux
->seg_base
= seg
->p_vaddr
;
8758 /* Second, build the unwind table from the contents of the unwind section: */
8759 size
= sec
->sh_size
;
8760 table
= (unsigned char *) get_data (NULL
, filedata
, sec
->sh_offset
, 1, size
,
8765 aux
->table_len
= size
/ (3 * eh_addr_size
);
8766 aux
->table
= (struct ia64_unw_table_entry
*)
8767 xcmalloc (aux
->table_len
, sizeof (aux
->table
[0]));
8770 for (tp
= table
; tp
<= table
+ size
- (3 * eh_addr_size
); ++tep
)
8772 tep
->start
.section
= SHN_UNDEF
;
8773 tep
->end
.section
= SHN_UNDEF
;
8774 tep
->info
.section
= SHN_UNDEF
;
8775 tep
->start
.offset
= byte_get (tp
, eh_addr_size
); tp
+= eh_addr_size
;
8776 tep
->end
.offset
= byte_get (tp
, eh_addr_size
); tp
+= eh_addr_size
;
8777 tep
->info
.offset
= byte_get (tp
, eh_addr_size
); tp
+= eh_addr_size
;
8778 tep
->start
.offset
+= aux
->seg_base
;
8779 tep
->end
.offset
+= aux
->seg_base
;
8780 tep
->info
.offset
+= aux
->seg_base
;
8784 /* Third, apply any relocations to the unwind table: */
8785 for (relsec
= filedata
->section_headers
;
8786 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
8789 if (relsec
->sh_type
!= SHT_RELA
8790 || relsec
->sh_info
>= filedata
->file_header
.e_shnum
8791 || filedata
->section_headers
+ relsec
->sh_info
!= sec
)
8794 if (!slurp_rela_relocs (filedata
, relsec
->sh_offset
, relsec
->sh_size
,
8803 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
8805 unsigned int sym_ndx
;
8806 unsigned int r_type
= get_reloc_type (filedata
, rp
->r_info
);
8807 relname
= elf_ia64_reloc_type (r_type
);
8809 /* PR 17531: file: 9fa67536. */
8810 if (relname
== NULL
)
8812 warn (_("Skipping unknown relocation type: %u\n"), r_type
);
8816 if (! startswith (relname
, "R_IA64_SEGREL"))
8818 warn (_("Skipping unexpected relocation type: %s\n"), relname
);
8822 i
= rp
->r_offset
/ (3 * eh_addr_size
);
8824 /* PR 17531: file: 5bc8d9bf. */
8825 if (i
>= aux
->table_len
)
8827 warn (_("Skipping reloc with overlarge offset: %lx\n"), i
);
8831 sym_ndx
= get_reloc_symindex (rp
->r_info
);
8832 if (sym_ndx
>= aux
->nsyms
)
8834 warn (_("Skipping reloc with invalid symbol index: %u\n"),
8838 sym
= aux
->symtab
+ sym_ndx
;
8840 switch (rp
->r_offset
/ eh_addr_size
% 3)
8843 aux
->table
[i
].start
.section
= sym
->st_shndx
;
8844 aux
->table
[i
].start
.offset
= rp
->r_addend
+ sym
->st_value
;
8847 aux
->table
[i
].end
.section
= sym
->st_shndx
;
8848 aux
->table
[i
].end
.offset
= rp
->r_addend
+ sym
->st_value
;
8851 aux
->table
[i
].info
.section
= sym
->st_shndx
;
8852 aux
->table
[i
].info
.offset
= rp
->r_addend
+ sym
->st_value
;
8866 ia64_process_unwind (Filedata
* filedata
)
8868 Elf_Internal_Shdr
* sec
;
8869 Elf_Internal_Shdr
* unwsec
= NULL
;
8870 unsigned long i
, unwcount
= 0, unwstart
= 0;
8871 struct ia64_unw_aux_info aux
;
8874 memset (& aux
, 0, sizeof (aux
));
8876 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
8878 if (sec
->sh_type
== SHT_SYMTAB
)
8882 error (_("Multiple symbol tables encountered\n"));
8888 if (!get_symtab (filedata
, sec
, &aux
.symtab
, &aux
.nsyms
,
8889 &aux
.strtab
, &aux
.strtab_size
))
8892 else if (sec
->sh_type
== SHT_IA_64_UNWIND
)
8897 printf (_("\nThere are no unwind sections in this file.\n"));
8899 while (unwcount
-- > 0)
8904 for (i
= unwstart
, sec
= filedata
->section_headers
+ unwstart
, unwsec
= NULL
;
8905 i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
8906 if (sec
->sh_type
== SHT_IA_64_UNWIND
)
8911 /* We have already counted the number of SHT_IA64_UNWIND
8912 sections so the loop above should never fail. */
8913 assert (unwsec
!= NULL
);
8916 len
= sizeof (ELF_STRING_ia64_unwind_once
) - 1;
8918 if ((unwsec
->sh_flags
& SHF_GROUP
) != 0)
8920 /* We need to find which section group it is in. */
8921 struct group_list
* g
;
8923 if (filedata
->section_headers_groups
== NULL
8924 || filedata
->section_headers_groups
[i
] == NULL
)
8925 i
= filedata
->file_header
.e_shnum
;
8928 g
= filedata
->section_headers_groups
[i
]->root
;
8930 for (; g
!= NULL
; g
= g
->next
)
8932 sec
= filedata
->section_headers
+ g
->section_index
;
8934 if (section_name_valid (filedata
, sec
)
8935 && streq (section_name (filedata
, sec
),
8936 ELF_STRING_ia64_unwind_info
))
8941 i
= filedata
->file_header
.e_shnum
;
8944 else if (section_name_valid (filedata
, unwsec
)
8945 && startswith (section_name (filedata
, unwsec
),
8946 ELF_STRING_ia64_unwind_once
))
8948 /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO. */
8949 len2
= sizeof (ELF_STRING_ia64_unwind_info_once
) - 1;
8950 suffix
= section_name (filedata
, unwsec
) + len
;
8951 for (i
= 0, sec
= filedata
->section_headers
;
8952 i
< filedata
->file_header
.e_shnum
;
8954 if (section_name_valid (filedata
, sec
)
8955 && startswith (section_name (filedata
, sec
),
8956 ELF_STRING_ia64_unwind_info_once
)
8957 && streq (section_name (filedata
, sec
) + len2
, suffix
))
8962 /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
8963 .IA_64.unwind or BAR -> .IA_64.unwind_info. */
8964 len
= sizeof (ELF_STRING_ia64_unwind
) - 1;
8965 len2
= sizeof (ELF_STRING_ia64_unwind_info
) - 1;
8967 if (section_name_valid (filedata
, unwsec
)
8968 && startswith (section_name (filedata
, unwsec
),
8969 ELF_STRING_ia64_unwind
))
8970 suffix
= section_name (filedata
, unwsec
) + len
;
8971 for (i
= 0, sec
= filedata
->section_headers
;
8972 i
< filedata
->file_header
.e_shnum
;
8974 if (section_name_valid (filedata
, sec
)
8975 && startswith (section_name (filedata
, sec
),
8976 ELF_STRING_ia64_unwind_info
)
8977 && streq (section_name (filedata
, sec
) + len2
, suffix
))
8981 if (i
== filedata
->file_header
.e_shnum
)
8983 printf (_("\nCould not find unwind info section for "));
8985 if (filedata
->string_table
== NULL
)
8986 printf ("%d", unwsec
->sh_name
);
8988 printf ("'%s'", printable_section_name (filedata
, unwsec
));
8992 aux
.info_addr
= sec
->sh_addr
;
8993 aux
.info
= (unsigned char *) get_data (NULL
, filedata
, sec
->sh_offset
, 1,
8996 aux
.info_size
= aux
.info
== NULL
? 0 : sec
->sh_size
;
8998 printf (_("\nUnwind section "));
9000 if (filedata
->string_table
== NULL
)
9001 printf ("%d", unwsec
->sh_name
);
9003 printf ("'%s'", printable_section_name (filedata
, unwsec
));
9005 printf (_(" at offset 0x%lx contains %lu entries:\n"),
9006 (unsigned long) unwsec
->sh_offset
,
9007 (unsigned long) (unwsec
->sh_size
/ (3 * eh_addr_size
)));
9009 if (slurp_ia64_unwind_table (filedata
, & aux
, unwsec
)
9010 && aux
.table_len
> 0)
9011 dump_ia64_unwind (filedata
, & aux
);
9013 free ((char *) aux
.table
);
9014 free ((char *) aux
.info
);
9021 free ((char *) aux
.strtab
);
9026 struct hppa_unw_table_entry
9028 struct absaddr start
;
9030 unsigned int Cannot_unwind
:1; /* 0 */
9031 unsigned int Millicode
:1; /* 1 */
9032 unsigned int Millicode_save_sr0
:1; /* 2 */
9033 unsigned int Region_description
:2; /* 3..4 */
9034 unsigned int reserved1
:1; /* 5 */
9035 unsigned int Entry_SR
:1; /* 6 */
9036 unsigned int Entry_FR
:4; /* Number saved 7..10 */
9037 unsigned int Entry_GR
:5; /* Number saved 11..15 */
9038 unsigned int Args_stored
:1; /* 16 */
9039 unsigned int Variable_Frame
:1; /* 17 */
9040 unsigned int Separate_Package_Body
:1; /* 18 */
9041 unsigned int Frame_Extension_Millicode
:1; /* 19 */
9042 unsigned int Stack_Overflow_Check
:1; /* 20 */
9043 unsigned int Two_Instruction_SP_Increment
:1; /* 21 */
9044 unsigned int Ada_Region
:1; /* 22 */
9045 unsigned int cxx_info
:1; /* 23 */
9046 unsigned int cxx_try_catch
:1; /* 24 */
9047 unsigned int sched_entry_seq
:1; /* 25 */
9048 unsigned int reserved2
:1; /* 26 */
9049 unsigned int Save_SP
:1; /* 27 */
9050 unsigned int Save_RP
:1; /* 28 */
9051 unsigned int Save_MRP_in_frame
:1; /* 29 */
9052 unsigned int extn_ptr_defined
:1; /* 30 */
9053 unsigned int Cleanup_defined
:1; /* 31 */
9055 unsigned int MPE_XL_interrupt_marker
:1; /* 0 */
9056 unsigned int HP_UX_interrupt_marker
:1; /* 1 */
9057 unsigned int Large_frame
:1; /* 2 */
9058 unsigned int Pseudo_SP_Set
:1; /* 3 */
9059 unsigned int reserved4
:1; /* 4 */
9060 unsigned int Total_frame_size
:27; /* 5..31 */
9063 struct hppa_unw_aux_info
9065 struct hppa_unw_table_entry
* table
; /* Unwind table. */
9066 unsigned long table_len
; /* Length of unwind table. */
9067 bfd_vma seg_base
; /* Starting address of segment. */
9068 Elf_Internal_Sym
* symtab
; /* The symbol table. */
9069 unsigned long nsyms
; /* Number of symbols. */
9070 Elf_Internal_Sym
* funtab
; /* Sorted table of STT_FUNC symbols. */
9071 unsigned long nfuns
; /* Number of entries in funtab. */
9072 char * strtab
; /* The string table. */
9073 unsigned long strtab_size
; /* Size of string table. */
9077 dump_hppa_unwind (Filedata
* filedata
, struct hppa_unw_aux_info
* aux
)
9079 struct hppa_unw_table_entry
* tp
;
9080 unsigned long j
, nfuns
;
9083 aux
->funtab
= xmalloc (aux
->nsyms
* sizeof (Elf_Internal_Sym
));
9084 for (nfuns
= 0, j
= 0; j
< aux
->nsyms
; j
++)
9085 if (aux
->symtab
[j
].st_value
&& ELF_ST_TYPE (aux
->symtab
[j
].st_info
) == STT_FUNC
)
9086 aux
->funtab
[nfuns
++] = aux
->symtab
[j
];
9088 qsort (aux
->funtab
, aux
->nfuns
, sizeof (Elf_Internal_Sym
), symcmp
);
9090 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
9093 const char * procname
;
9095 find_symbol_for_address (filedata
, aux
->funtab
, aux
->nfuns
, aux
->strtab
,
9096 aux
->strtab_size
, tp
->start
, &procname
,
9099 fputs ("\n<", stdout
);
9103 fputs (procname
, stdout
);
9106 printf ("+%lx", (unsigned long) offset
);
9109 fputs (">: [", stdout
);
9110 print_vma (tp
->start
.offset
, PREFIX_HEX
);
9111 fputc ('-', stdout
);
9112 print_vma (tp
->end
.offset
, PREFIX_HEX
);
9115 #define PF(_m) if (tp->_m) printf (#_m " ");
9116 #define PV(_m) if (tp->_m) printf (#_m "=%d ", tp->_m);
9119 PF(Millicode_save_sr0
);
9120 /* PV(Region_description); */
9126 PF(Separate_Package_Body
);
9127 PF(Frame_Extension_Millicode
);
9128 PF(Stack_Overflow_Check
);
9129 PF(Two_Instruction_SP_Increment
);
9133 PF(sched_entry_seq
);
9136 PF(Save_MRP_in_frame
);
9137 PF(extn_ptr_defined
);
9138 PF(Cleanup_defined
);
9139 PF(MPE_XL_interrupt_marker
);
9140 PF(HP_UX_interrupt_marker
);
9143 PV(Total_frame_size
);
9156 slurp_hppa_unwind_table (Filedata
* filedata
,
9157 struct hppa_unw_aux_info
* aux
,
9158 Elf_Internal_Shdr
* sec
)
9160 unsigned long size
, unw_ent_size
, nentries
, nrelas
, i
;
9161 Elf_Internal_Phdr
* seg
;
9162 struct hppa_unw_table_entry
* tep
;
9163 Elf_Internal_Shdr
* relsec
;
9164 Elf_Internal_Rela
* rela
;
9165 Elf_Internal_Rela
* rp
;
9166 unsigned char * table
;
9168 Elf_Internal_Sym
* sym
;
9169 const char * relname
;
9171 /* First, find the starting address of the segment that includes
9173 if (filedata
->file_header
.e_phnum
)
9175 if (! get_program_headers (filedata
))
9178 for (seg
= filedata
->program_headers
;
9179 seg
< filedata
->program_headers
+ filedata
->file_header
.e_phnum
;
9182 if (seg
->p_type
!= PT_LOAD
)
9185 if (sec
->sh_addr
>= seg
->p_vaddr
9186 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
9188 aux
->seg_base
= seg
->p_vaddr
;
9194 /* Second, build the unwind table from the contents of the unwind
9196 size
= sec
->sh_size
;
9197 table
= (unsigned char *) get_data (NULL
, filedata
, sec
->sh_offset
, 1, size
,
9203 nentries
= size
/ unw_ent_size
;
9204 size
= unw_ent_size
* nentries
;
9206 aux
->table_len
= nentries
;
9207 tep
= aux
->table
= (struct hppa_unw_table_entry
*)
9208 xcmalloc (nentries
, sizeof (aux
->table
[0]));
9210 for (tp
= table
; tp
< table
+ size
; tp
+= unw_ent_size
, ++tep
)
9212 unsigned int tmp1
, tmp2
;
9214 tep
->start
.section
= SHN_UNDEF
;
9215 tep
->end
.section
= SHN_UNDEF
;
9217 tep
->start
.offset
= byte_get ((unsigned char *) tp
+ 0, 4);
9218 tep
->end
.offset
= byte_get ((unsigned char *) tp
+ 4, 4);
9219 tmp1
= byte_get ((unsigned char *) tp
+ 8, 4);
9220 tmp2
= byte_get ((unsigned char *) tp
+ 12, 4);
9222 tep
->start
.offset
+= aux
->seg_base
;
9223 tep
->end
.offset
+= aux
->seg_base
;
9225 tep
->Cannot_unwind
= (tmp1
>> 31) & 0x1;
9226 tep
->Millicode
= (tmp1
>> 30) & 0x1;
9227 tep
->Millicode_save_sr0
= (tmp1
>> 29) & 0x1;
9228 tep
->Region_description
= (tmp1
>> 27) & 0x3;
9229 tep
->reserved1
= (tmp1
>> 26) & 0x1;
9230 tep
->Entry_SR
= (tmp1
>> 25) & 0x1;
9231 tep
->Entry_FR
= (tmp1
>> 21) & 0xf;
9232 tep
->Entry_GR
= (tmp1
>> 16) & 0x1f;
9233 tep
->Args_stored
= (tmp1
>> 15) & 0x1;
9234 tep
->Variable_Frame
= (tmp1
>> 14) & 0x1;
9235 tep
->Separate_Package_Body
= (tmp1
>> 13) & 0x1;
9236 tep
->Frame_Extension_Millicode
= (tmp1
>> 12) & 0x1;
9237 tep
->Stack_Overflow_Check
= (tmp1
>> 11) & 0x1;
9238 tep
->Two_Instruction_SP_Increment
= (tmp1
>> 10) & 0x1;
9239 tep
->Ada_Region
= (tmp1
>> 9) & 0x1;
9240 tep
->cxx_info
= (tmp1
>> 8) & 0x1;
9241 tep
->cxx_try_catch
= (tmp1
>> 7) & 0x1;
9242 tep
->sched_entry_seq
= (tmp1
>> 6) & 0x1;
9243 tep
->reserved2
= (tmp1
>> 5) & 0x1;
9244 tep
->Save_SP
= (tmp1
>> 4) & 0x1;
9245 tep
->Save_RP
= (tmp1
>> 3) & 0x1;
9246 tep
->Save_MRP_in_frame
= (tmp1
>> 2) & 0x1;
9247 tep
->extn_ptr_defined
= (tmp1
>> 1) & 0x1;
9248 tep
->Cleanup_defined
= tmp1
& 0x1;
9250 tep
->MPE_XL_interrupt_marker
= (tmp2
>> 31) & 0x1;
9251 tep
->HP_UX_interrupt_marker
= (tmp2
>> 30) & 0x1;
9252 tep
->Large_frame
= (tmp2
>> 29) & 0x1;
9253 tep
->Pseudo_SP_Set
= (tmp2
>> 28) & 0x1;
9254 tep
->reserved4
= (tmp2
>> 27) & 0x1;
9255 tep
->Total_frame_size
= tmp2
& 0x7ffffff;
9259 /* Third, apply any relocations to the unwind table. */
9260 for (relsec
= filedata
->section_headers
;
9261 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
9264 if (relsec
->sh_type
!= SHT_RELA
9265 || relsec
->sh_info
>= filedata
->file_header
.e_shnum
9266 || filedata
->section_headers
+ relsec
->sh_info
!= sec
)
9269 if (!slurp_rela_relocs (filedata
, relsec
->sh_offset
, relsec
->sh_size
,
9273 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
9275 unsigned int sym_ndx
;
9276 unsigned int r_type
= get_reloc_type (filedata
, rp
->r_info
);
9277 relname
= elf_hppa_reloc_type (r_type
);
9279 if (relname
== NULL
)
9281 warn (_("Skipping unknown relocation type: %u\n"), r_type
);
9285 /* R_PARISC_SEGREL32 or R_PARISC_SEGREL64. */
9286 if (! startswith (relname
, "R_PARISC_SEGREL"))
9288 warn (_("Skipping unexpected relocation type: %s\n"), relname
);
9292 i
= rp
->r_offset
/ unw_ent_size
;
9293 if (i
>= aux
->table_len
)
9295 warn (_("Skipping reloc with overlarge offset: %lx\n"), i
);
9299 sym_ndx
= get_reloc_symindex (rp
->r_info
);
9300 if (sym_ndx
>= aux
->nsyms
)
9302 warn (_("Skipping reloc with invalid symbol index: %u\n"),
9306 sym
= aux
->symtab
+ sym_ndx
;
9308 switch ((rp
->r_offset
% unw_ent_size
) / 4)
9311 aux
->table
[i
].start
.section
= sym
->st_shndx
;
9312 aux
->table
[i
].start
.offset
= sym
->st_value
+ rp
->r_addend
;
9315 aux
->table
[i
].end
.section
= sym
->st_shndx
;
9316 aux
->table
[i
].end
.offset
= sym
->st_value
+ rp
->r_addend
;
9330 hppa_process_unwind (Filedata
* filedata
)
9332 struct hppa_unw_aux_info aux
;
9333 Elf_Internal_Shdr
* unwsec
= NULL
;
9334 Elf_Internal_Shdr
* sec
;
9338 if (filedata
->string_table
== NULL
)
9341 memset (& aux
, 0, sizeof (aux
));
9343 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
9345 if (sec
->sh_type
== SHT_SYMTAB
)
9349 error (_("Multiple symbol tables encountered\n"));
9355 if (!get_symtab (filedata
, sec
, &aux
.symtab
, &aux
.nsyms
,
9356 &aux
.strtab
, &aux
.strtab_size
))
9359 else if (section_name_valid (filedata
, sec
)
9360 && streq (section_name (filedata
, sec
), ".PARISC.unwind"))
9365 printf (_("\nThere are no unwind sections in this file.\n"));
9367 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
9369 if (section_name_valid (filedata
, sec
)
9370 && streq (section_name (filedata
, sec
), ".PARISC.unwind"))
9372 unsigned long num_unwind
= sec
->sh_size
/ 16;
9374 printf (ngettext ("\nUnwind section '%s' at offset 0x%lx "
9375 "contains %lu entry:\n",
9376 "\nUnwind section '%s' at offset 0x%lx "
9377 "contains %lu entries:\n",
9379 printable_section_name (filedata
, sec
),
9380 (unsigned long) sec
->sh_offset
,
9383 if (! slurp_hppa_unwind_table (filedata
, &aux
, sec
))
9386 if (res
&& aux
.table_len
> 0)
9388 if (! dump_hppa_unwind (filedata
, &aux
))
9392 free ((char *) aux
.table
);
9398 free ((char *) aux
.strtab
);
9405 unsigned char * data
; /* The unwind data. */
9406 Elf_Internal_Shdr
* sec
; /* The cached unwind section header. */
9407 Elf_Internal_Rela
* rela
; /* The cached relocations for this section. */
9408 unsigned long nrelas
; /* The number of relocations. */
9409 unsigned int rel_type
; /* REL or RELA ? */
9410 Elf_Internal_Rela
* next_rela
; /* Cyclic pointer to the next reloc to process. */
9413 struct arm_unw_aux_info
9415 Filedata
* filedata
; /* The file containing the unwind sections. */
9416 Elf_Internal_Sym
* symtab
; /* The file's symbol table. */
9417 unsigned long nsyms
; /* Number of symbols. */
9418 Elf_Internal_Sym
* funtab
; /* Sorted table of STT_FUNC symbols. */
9419 unsigned long nfuns
; /* Number of these symbols. */
9420 char * strtab
; /* The file's string table. */
9421 unsigned long strtab_size
; /* Size of string table. */
9425 arm_print_vma_and_name (Filedata
* filedata
,
9426 struct arm_unw_aux_info
* aux
,
9428 struct absaddr addr
)
9430 const char *procname
;
9433 if (addr
.section
== SHN_UNDEF
)
9436 find_symbol_for_address (filedata
, aux
->funtab
, aux
->nfuns
, aux
->strtab
,
9437 aux
->strtab_size
, addr
, &procname
,
9440 print_vma (fn
, PREFIX_HEX
);
9444 fputs (" <", stdout
);
9445 fputs (procname
, stdout
);
9448 printf ("+0x%lx", (unsigned long) sym_offset
);
9449 fputc ('>', stdout
);
9456 arm_free_section (struct arm_section
*arm_sec
)
9458 free (arm_sec
->data
);
9459 free (arm_sec
->rela
);
9462 /* 1) If SEC does not match the one cached in ARM_SEC, then free the current
9463 cached section and install SEC instead.
9464 2) Locate the 32-bit word at WORD_OFFSET in unwind section SEC
9465 and return its valued in * WORDP, relocating if necessary.
9466 3) Update the NEXT_RELA field in ARM_SEC and store the section index and
9467 relocation's offset in ADDR.
9468 4) If SYM_NAME is non-NULL and a relocation was applied, record the offset
9469 into the string table of the symbol associated with the reloc. If no
9470 reloc was applied store -1 there.
9471 5) Return TRUE upon success, FALSE otherwise. */
9474 get_unwind_section_word (Filedata
* filedata
,
9475 struct arm_unw_aux_info
* aux
,
9476 struct arm_section
* arm_sec
,
9477 Elf_Internal_Shdr
* sec
,
9478 bfd_vma word_offset
,
9479 unsigned int * wordp
,
9480 struct absaddr
* addr
,
9483 Elf_Internal_Rela
*rp
;
9484 Elf_Internal_Sym
*sym
;
9485 const char * relname
;
9489 if (sec
== NULL
|| arm_sec
== NULL
)
9492 addr
->section
= SHN_UNDEF
;
9495 if (sym_name
!= NULL
)
9496 *sym_name
= (bfd_vma
) -1;
9498 /* If necessary, update the section cache. */
9499 if (sec
!= arm_sec
->sec
)
9501 Elf_Internal_Shdr
*relsec
;
9503 arm_free_section (arm_sec
);
9506 arm_sec
->data
= get_data (NULL
, aux
->filedata
, sec
->sh_offset
, 1,
9507 sec
->sh_size
, _("unwind data"));
9508 arm_sec
->rela
= NULL
;
9509 arm_sec
->nrelas
= 0;
9511 for (relsec
= filedata
->section_headers
;
9512 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
9515 if (relsec
->sh_info
>= filedata
->file_header
.e_shnum
9516 || filedata
->section_headers
+ relsec
->sh_info
!= sec
9517 /* PR 15745: Check the section type as well. */
9518 || (relsec
->sh_type
!= SHT_REL
9519 && relsec
->sh_type
!= SHT_RELA
))
9522 arm_sec
->rel_type
= relsec
->sh_type
;
9523 if (relsec
->sh_type
== SHT_REL
)
9525 if (!slurp_rel_relocs (aux
->filedata
, relsec
->sh_offset
,
9527 & arm_sec
->rela
, & arm_sec
->nrelas
))
9530 else /* relsec->sh_type == SHT_RELA */
9532 if (!slurp_rela_relocs (aux
->filedata
, relsec
->sh_offset
,
9534 & arm_sec
->rela
, & arm_sec
->nrelas
))
9540 arm_sec
->next_rela
= arm_sec
->rela
;
9543 /* If there is no unwind data we can do nothing. */
9544 if (arm_sec
->data
== NULL
)
9547 /* If the offset is invalid then fail. */
9548 if (/* PR 21343 *//* PR 18879 */
9550 || word_offset
> (sec
->sh_size
- 4)
9551 || ((bfd_signed_vma
) word_offset
) < 0)
9554 /* Get the word at the required offset. */
9555 word
= byte_get (arm_sec
->data
+ word_offset
, 4);
9557 /* PR 17531: file: id:000001,src:001266+003044,op:splice,rep:128. */
9558 if (arm_sec
->rela
== NULL
)
9564 /* Look through the relocs to find the one that applies to the provided offset. */
9566 for (rp
= arm_sec
->next_rela
; rp
!= arm_sec
->rela
+ arm_sec
->nrelas
; rp
++)
9568 bfd_vma prelval
, offset
;
9570 if (rp
->r_offset
> word_offset
&& !wrapped
)
9575 if (rp
->r_offset
> word_offset
)
9578 if (rp
->r_offset
& 3)
9580 warn (_("Skipping unexpected relocation at offset 0x%lx\n"),
9581 (unsigned long) rp
->r_offset
);
9585 if (rp
->r_offset
< word_offset
)
9588 /* PR 17531: file: 027-161405-0.004 */
9589 if (aux
->symtab
== NULL
)
9592 if (arm_sec
->rel_type
== SHT_REL
)
9594 offset
= word
& 0x7fffffff;
9595 if (offset
& 0x40000000)
9596 offset
|= ~ (bfd_vma
) 0x7fffffff;
9598 else if (arm_sec
->rel_type
== SHT_RELA
)
9599 offset
= rp
->r_addend
;
9602 error (_("Unknown section relocation type %d encountered\n"),
9607 /* PR 17531 file: 027-1241568-0.004. */
9608 if (ELF32_R_SYM (rp
->r_info
) >= aux
->nsyms
)
9610 error (_("Bad symbol index in unwind relocation (%lu > %lu)\n"),
9611 (unsigned long) ELF32_R_SYM (rp
->r_info
), aux
->nsyms
);
9615 sym
= aux
->symtab
+ ELF32_R_SYM (rp
->r_info
);
9616 offset
+= sym
->st_value
;
9617 prelval
= offset
- (arm_sec
->sec
->sh_addr
+ rp
->r_offset
);
9619 /* Check that we are processing the expected reloc type. */
9620 if (filedata
->file_header
.e_machine
== EM_ARM
)
9622 relname
= elf_arm_reloc_type (ELF32_R_TYPE (rp
->r_info
));
9623 if (relname
== NULL
)
9625 warn (_("Skipping unknown ARM relocation type: %d\n"),
9626 (int) ELF32_R_TYPE (rp
->r_info
));
9630 if (streq (relname
, "R_ARM_NONE"))
9633 if (! streq (relname
, "R_ARM_PREL31"))
9635 warn (_("Skipping unexpected ARM relocation type %s\n"), relname
);
9639 else if (filedata
->file_header
.e_machine
== EM_TI_C6000
)
9641 relname
= elf_tic6x_reloc_type (ELF32_R_TYPE (rp
->r_info
));
9642 if (relname
== NULL
)
9644 warn (_("Skipping unknown C6000 relocation type: %d\n"),
9645 (int) ELF32_R_TYPE (rp
->r_info
));
9649 if (streq (relname
, "R_C6000_NONE"))
9652 if (! streq (relname
, "R_C6000_PREL31"))
9654 warn (_("Skipping unexpected C6000 relocation type %s\n"), relname
);
9662 /* This function currently only supports ARM and TI unwinders. */
9663 warn (_("Only TI and ARM unwinders are currently supported\n"));
9667 word
= (word
& ~ (bfd_vma
) 0x7fffffff) | (prelval
& 0x7fffffff);
9668 addr
->section
= sym
->st_shndx
;
9669 addr
->offset
= offset
;
9672 * sym_name
= sym
->st_name
;
9677 arm_sec
->next_rela
= rp
;
9682 static const char *tic6x_unwind_regnames
[16] =
9684 "A15", "B15", "B14", "B13", "B12", "B11", "B10", "B3",
9685 "A14", "A13", "A12", "A11", "A10",
9686 "[invalid reg 13]", "[invalid reg 14]", "[invalid reg 15]"
9690 decode_tic6x_unwind_regmask (unsigned int mask
)
9694 for (i
= 12; mask
; mask
>>= 1, i
--)
9698 fputs (tic6x_unwind_regnames
[i
], stdout
);
9700 fputs (", ", stdout
);
9706 if (remaining == 0 && more_words) \
9709 if (! get_unwind_section_word (filedata, aux, data_arm_sec, data_sec, \
9710 data_offset, & word, & addr, NULL)) \
9716 #define GET_OP(OP) \
9721 (OP) = word >> 24; \
9726 printf (_("[Truncated opcode]\n")); \
9729 printf ("0x%02x ", OP)
9732 decode_arm_unwind_bytecode (Filedata
* filedata
,
9733 struct arm_unw_aux_info
* aux
,
9735 unsigned int remaining
,
9736 unsigned int more_words
,
9737 bfd_vma data_offset
,
9738 Elf_Internal_Shdr
* data_sec
,
9739 struct arm_section
* data_arm_sec
)
9741 struct absaddr addr
;
9744 /* Decode the unwinding instructions. */
9747 unsigned int op
, op2
;
9756 printf (" 0x%02x ", op
);
9758 if ((op
& 0xc0) == 0x00)
9760 int offset
= ((op
& 0x3f) << 2) + 4;
9762 printf (" vsp = vsp + %d", offset
);
9764 else if ((op
& 0xc0) == 0x40)
9766 int offset
= ((op
& 0x3f) << 2) + 4;
9768 printf (" vsp = vsp - %d", offset
);
9770 else if ((op
& 0xf0) == 0x80)
9773 if (op
== 0x80 && op2
== 0)
9774 printf (_("Refuse to unwind"));
9777 unsigned int mask
= ((op
& 0x0f) << 8) | op2
;
9782 for (i
= 0; i
< 12; i
++)
9783 if (mask
& (1 << i
))
9789 printf ("r%d", 4 + i
);
9794 else if ((op
& 0xf0) == 0x90)
9796 if (op
== 0x9d || op
== 0x9f)
9797 printf (_(" [Reserved]"));
9799 printf (" vsp = r%d", op
& 0x0f);
9801 else if ((op
& 0xf0) == 0xa0)
9803 int end
= 4 + (op
& 0x07);
9808 for (i
= 4; i
<= end
; i
++)
9824 else if (op
== 0xb0)
9825 printf (_(" finish"));
9826 else if (op
== 0xb1)
9829 if (op2
== 0 || (op2
& 0xf0) != 0)
9830 printf (_("[Spare]"));
9833 unsigned int mask
= op2
& 0x0f;
9838 for (i
= 0; i
< 12; i
++)
9839 if (mask
& (1 << i
))
9850 else if (op
== 0xb2)
9852 unsigned char buf
[9];
9853 unsigned int i
, len
;
9854 unsigned long offset
;
9856 for (i
= 0; i
< sizeof (buf
); i
++)
9859 if ((buf
[i
] & 0x80) == 0)
9862 if (i
== sizeof (buf
))
9864 error (_("corrupt change to vsp\n"));
9869 offset
= read_leb128 (buf
, buf
+ i
+ 1, false, &len
, NULL
);
9870 assert (len
== i
+ 1);
9871 offset
= offset
* 4 + 0x204;
9872 printf ("vsp = vsp + %ld", offset
);
9875 else if (op
== 0xb3 || op
== 0xc8 || op
== 0xc9)
9877 unsigned int first
, last
;
9884 printf ("pop {D%d", first
);
9886 printf ("-D%d", first
+ last
);
9889 else if (op
== 0xb4)
9890 printf (_(" pop {ra_auth_code}"));
9891 else if ((op
& 0xf8) == 0xb8 || (op
& 0xf8) == 0xd0)
9893 unsigned int count
= op
& 0x07;
9897 printf ("-D%d", 8 + count
);
9900 else if (op
>= 0xc0 && op
<= 0xc5)
9902 unsigned int count
= op
& 0x07;
9904 printf (" pop {wR10");
9906 printf ("-wR%d", 10 + count
);
9909 else if (op
== 0xc6)
9911 unsigned int first
, last
;
9916 printf ("pop {wR%d", first
);
9918 printf ("-wR%d", first
+ last
);
9921 else if (op
== 0xc7)
9924 if (op2
== 0 || (op2
& 0xf0) != 0)
9925 printf (_("[Spare]"));
9928 unsigned int mask
= op2
& 0x0f;
9933 for (i
= 0; i
< 4; i
++)
9934 if (mask
& (1 << i
))
9940 printf ("wCGR%d", i
);
9947 printf (_(" [unsupported opcode]"));
9958 decode_tic6x_unwind_bytecode (Filedata
* filedata
,
9959 struct arm_unw_aux_info
* aux
,
9961 unsigned int remaining
,
9962 unsigned int more_words
,
9963 bfd_vma data_offset
,
9964 Elf_Internal_Shdr
* data_sec
,
9965 struct arm_section
* data_arm_sec
)
9967 struct absaddr addr
;
9969 /* Decode the unwinding instructions. */
9972 unsigned int op
, op2
;
9981 printf (" 0x%02x ", op
);
9983 if ((op
& 0xc0) == 0x00)
9985 int offset
= ((op
& 0x3f) << 3) + 8;
9986 printf (" sp = sp + %d", offset
);
9988 else if ((op
& 0xc0) == 0x80)
9991 if (op
== 0x80 && op2
== 0)
9992 printf (_("Refuse to unwind"));
9995 unsigned int mask
= ((op
& 0x1f) << 8) | op2
;
9997 printf ("pop compact {");
10001 decode_tic6x_unwind_regmask (mask
);
10005 else if ((op
& 0xf0) == 0xc0)
10008 unsigned int nregs
;
10013 unsigned int offset
;
10017 /* Scan entire instruction first so that GET_OP output is not
10018 interleaved with disassembly. */
10020 for (i
= 0; nregs
< (op
& 0xf); i
++)
10026 regpos
[nregs
].offset
= i
* 2;
10027 regpos
[nregs
].reg
= reg
;
10034 regpos
[nregs
].offset
= i
* 2 + 1;
10035 regpos
[nregs
].reg
= reg
;
10040 printf (_("pop frame {"));
10043 printf (_("*corrupt* - no registers specified"));
10048 for (i
= i
* 2; i
> 0; i
--)
10050 if (regpos
[reg
].offset
== i
- 1)
10052 name
= tic6x_unwind_regnames
[regpos
[reg
].reg
];
10059 fputs (name
, stdout
);
10067 else if (op
== 0xd0)
10068 printf (" MOV FP, SP");
10069 else if (op
== 0xd1)
10070 printf (" __c6xabi_pop_rts");
10071 else if (op
== 0xd2)
10073 unsigned char buf
[9];
10074 unsigned int i
, len
;
10075 unsigned long offset
;
10077 for (i
= 0; i
< sizeof (buf
); i
++)
10080 if ((buf
[i
] & 0x80) == 0)
10083 /* PR 17531: file: id:000001,src:001906+004739,op:splice,rep:2. */
10084 if (i
== sizeof (buf
))
10086 warn (_("Corrupt stack pointer adjustment detected\n"));
10090 offset
= read_leb128 (buf
, buf
+ i
+ 1, false, &len
, NULL
);
10091 assert (len
== i
+ 1);
10092 offset
= offset
* 8 + 0x408;
10093 printf (_("sp = sp + %ld"), offset
);
10095 else if ((op
& 0xf0) == 0xe0)
10097 if ((op
& 0x0f) == 7)
10098 printf (" RETURN");
10100 printf (" MV %s, B3", tic6x_unwind_regnames
[op
& 0x0f]);
10104 printf (_(" [unsupported opcode]"));
10113 arm_expand_prel31 (Filedata
* filedata
, bfd_vma word
, bfd_vma where
)
10117 offset
= word
& 0x7fffffff;
10118 if (offset
& 0x40000000)
10119 offset
|= ~ (bfd_vma
) 0x7fffffff;
10121 if (filedata
->file_header
.e_machine
== EM_TI_C6000
)
10124 return offset
+ where
;
10128 decode_arm_unwind (Filedata
* filedata
,
10129 struct arm_unw_aux_info
* aux
,
10131 unsigned int remaining
,
10132 bfd_vma data_offset
,
10133 Elf_Internal_Shdr
* data_sec
,
10134 struct arm_section
* data_arm_sec
)
10137 unsigned int more_words
= 0;
10138 struct absaddr addr
;
10139 bfd_vma sym_name
= (bfd_vma
) -1;
10142 if (remaining
== 0)
10144 /* Fetch the first word.
10145 Note - when decoding an object file the address extracted
10146 here will always be 0. So we also pass in the sym_name
10147 parameter so that we can find the symbol associated with
10148 the personality routine. */
10149 if (! get_unwind_section_word (filedata
, aux
, data_arm_sec
, data_sec
, data_offset
,
10150 & word
, & addr
, & sym_name
))
10157 addr
.section
= SHN_UNDEF
;
10161 if ((word
& 0x80000000) == 0)
10163 /* Expand prel31 for personality routine. */
10165 const char *procname
;
10167 fn
= arm_expand_prel31 (filedata
, word
, data_sec
->sh_addr
+ data_offset
);
10168 printf (_(" Personality routine: "));
10170 && addr
.section
== SHN_UNDEF
&& addr
.offset
== 0
10171 && sym_name
!= (bfd_vma
) -1 && sym_name
< aux
->strtab_size
)
10173 procname
= aux
->strtab
+ sym_name
;
10174 print_vma (fn
, PREFIX_HEX
);
10177 fputs (" <", stdout
);
10178 fputs (procname
, stdout
);
10179 fputc ('>', stdout
);
10183 procname
= arm_print_vma_and_name (filedata
, aux
, fn
, addr
);
10184 fputc ('\n', stdout
);
10186 /* The GCC personality routines use the standard compact
10187 encoding, starting with one byte giving the number of
10189 if (procname
!= NULL
10190 && (startswith (procname
, "__gcc_personality_v0")
10191 || startswith (procname
, "__gxx_personality_v0")
10192 || startswith (procname
, "__gcj_personality_v0")
10193 || startswith (procname
, "__gnu_objc_personality_v0")))
10200 printf (_(" [Truncated data]\n"));
10203 more_words
= word
>> 24;
10213 /* ARM EHABI Section 6.3:
10215 An exception-handling table entry for the compact model looks like:
10217 31 30-28 27-24 23-0
10218 -- ----- ----- ----
10219 1 0 index Data for personalityRoutine[index] */
10221 if (filedata
->file_header
.e_machine
== EM_ARM
10222 && (word
& 0x70000000))
10224 warn (_("Corrupt ARM compact model table entry: %x \n"), word
);
10228 per_index
= (word
>> 24) & 0x7f;
10229 printf (_(" Compact model index: %d\n"), per_index
);
10230 if (per_index
== 0)
10236 else if (per_index
< 3)
10238 more_words
= (word
>> 16) & 0xff;
10244 switch (filedata
->file_header
.e_machine
)
10249 if (! decode_arm_unwind_bytecode (filedata
, aux
, word
, remaining
, more_words
,
10250 data_offset
, data_sec
, data_arm_sec
))
10255 warn (_("Unknown ARM compact model index encountered\n"));
10256 printf (_(" [reserved]\n"));
10264 if (! decode_tic6x_unwind_bytecode (filedata
, aux
, word
, remaining
, more_words
,
10265 data_offset
, data_sec
, data_arm_sec
))
10268 else if (per_index
< 5)
10270 if (((word
>> 17) & 0x7f) == 0x7f)
10271 printf (_(" Restore stack from frame pointer\n"));
10273 printf (_(" Stack increment %d\n"), (word
>> 14) & 0x1fc);
10274 printf (_(" Registers restored: "));
10275 if (per_index
== 4)
10276 printf (" (compact) ");
10277 decode_tic6x_unwind_regmask ((word
>> 4) & 0x1fff);
10279 printf (_(" Return register: %s\n"),
10280 tic6x_unwind_regnames
[word
& 0xf]);
10283 printf (_(" [reserved (%d)]\n"), per_index
);
10287 error (_("Unsupported architecture type %d encountered when decoding unwind table\n"),
10288 filedata
->file_header
.e_machine
);
10292 /* Decode the descriptors. Not implemented. */
10298 dump_arm_unwind (Filedata
* filedata
,
10299 struct arm_unw_aux_info
* aux
,
10300 Elf_Internal_Shdr
* exidx_sec
)
10302 struct arm_section exidx_arm_sec
, extab_arm_sec
;
10303 unsigned int i
, exidx_len
;
10304 unsigned long j
, nfuns
;
10307 memset (&exidx_arm_sec
, 0, sizeof (exidx_arm_sec
));
10308 memset (&extab_arm_sec
, 0, sizeof (extab_arm_sec
));
10309 exidx_len
= exidx_sec
->sh_size
/ 8;
10311 aux
->funtab
= xmalloc (aux
->nsyms
* sizeof (Elf_Internal_Sym
));
10312 for (nfuns
= 0, j
= 0; j
< aux
->nsyms
; j
++)
10313 if (aux
->symtab
[j
].st_value
&& ELF_ST_TYPE (aux
->symtab
[j
].st_info
) == STT_FUNC
)
10314 aux
->funtab
[nfuns
++] = aux
->symtab
[j
];
10315 aux
->nfuns
= nfuns
;
10316 qsort (aux
->funtab
, aux
->nfuns
, sizeof (Elf_Internal_Sym
), symcmp
);
10318 for (i
= 0; i
< exidx_len
; i
++)
10320 unsigned int exidx_fn
, exidx_entry
;
10321 struct absaddr fn_addr
, entry_addr
;
10324 fputc ('\n', stdout
);
10326 if (! get_unwind_section_word (filedata
, aux
, & exidx_arm_sec
, exidx_sec
,
10327 8 * i
, & exidx_fn
, & fn_addr
, NULL
)
10328 || ! get_unwind_section_word (filedata
, aux
, & exidx_arm_sec
, exidx_sec
,
10329 8 * i
+ 4, & exidx_entry
, & entry_addr
, NULL
))
10331 free (aux
->funtab
);
10332 arm_free_section (& exidx_arm_sec
);
10333 arm_free_section (& extab_arm_sec
);
10337 /* ARM EHABI, Section 5:
10338 An index table entry consists of 2 words.
10339 The first word contains a prel31 offset to the start of a function, with bit 31 clear. */
10340 if (exidx_fn
& 0x80000000)
10342 warn (_("corrupt index table entry: %x\n"), exidx_fn
);
10346 fn
= arm_expand_prel31 (filedata
, exidx_fn
, exidx_sec
->sh_addr
+ 8 * i
);
10348 arm_print_vma_and_name (filedata
, aux
, fn
, fn_addr
);
10349 fputs (": ", stdout
);
10351 if (exidx_entry
== 1)
10353 print_vma (exidx_entry
, PREFIX_HEX
);
10354 fputs (" [cantunwind]\n", stdout
);
10356 else if (exidx_entry
& 0x80000000)
10358 print_vma (exidx_entry
, PREFIX_HEX
);
10359 fputc ('\n', stdout
);
10360 decode_arm_unwind (filedata
, aux
, exidx_entry
, 4, 0, NULL
, NULL
);
10364 bfd_vma table
, table_offset
= 0;
10365 Elf_Internal_Shdr
*table_sec
;
10367 fputs ("@", stdout
);
10368 table
= arm_expand_prel31 (filedata
, exidx_entry
, exidx_sec
->sh_addr
+ 8 * i
+ 4);
10369 print_vma (table
, PREFIX_HEX
);
10372 /* Locate the matching .ARM.extab. */
10373 if (entry_addr
.section
!= SHN_UNDEF
10374 && entry_addr
.section
< filedata
->file_header
.e_shnum
)
10376 table_sec
= filedata
->section_headers
+ entry_addr
.section
;
10377 table_offset
= entry_addr
.offset
;
10379 if (table_offset
> table_sec
->sh_size
10380 || ((bfd_signed_vma
) table_offset
) < 0)
10382 warn (_("Unwind entry contains corrupt offset (0x%lx) into section %s\n"),
10383 (unsigned long) table_offset
,
10384 printable_section_name (filedata
, table_sec
));
10391 table_sec
= find_section_by_address (filedata
, table
);
10392 if (table_sec
!= NULL
)
10393 table_offset
= table
- table_sec
->sh_addr
;
10396 if (table_sec
== NULL
)
10398 warn (_("Could not locate .ARM.extab section containing 0x%lx.\n"),
10399 (unsigned long) table
);
10404 if (! decode_arm_unwind (filedata
, aux
, 0, 0, table_offset
, table_sec
,
10412 free (aux
->funtab
);
10413 arm_free_section (&exidx_arm_sec
);
10414 arm_free_section (&extab_arm_sec
);
10419 /* Used for both ARM and C6X unwinding tables. */
10422 arm_process_unwind (Filedata
* filedata
)
10424 struct arm_unw_aux_info aux
;
10425 Elf_Internal_Shdr
*unwsec
= NULL
;
10426 Elf_Internal_Shdr
*sec
;
10428 unsigned int sec_type
;
10431 switch (filedata
->file_header
.e_machine
)
10434 sec_type
= SHT_ARM_EXIDX
;
10438 sec_type
= SHT_C6000_UNWIND
;
10442 error (_("Unsupported architecture type %d encountered when processing unwind table\n"),
10443 filedata
->file_header
.e_machine
);
10447 if (filedata
->string_table
== NULL
)
10450 memset (& aux
, 0, sizeof (aux
));
10451 aux
.filedata
= filedata
;
10453 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
10455 if (sec
->sh_type
== SHT_SYMTAB
)
10459 error (_("Multiple symbol tables encountered\n"));
10465 if (!get_symtab (filedata
, sec
, &aux
.symtab
, &aux
.nsyms
,
10466 &aux
.strtab
, &aux
.strtab_size
))
10469 else if (sec
->sh_type
== sec_type
)
10473 if (unwsec
== NULL
)
10474 printf (_("\nThere are no unwind sections in this file.\n"));
10476 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
10478 if (sec
->sh_type
== sec_type
)
10480 unsigned long num_unwind
= sec
->sh_size
/ (2 * eh_addr_size
);
10481 printf (ngettext ("\nUnwind section '%s' at offset 0x%lx "
10482 "contains %lu entry:\n",
10483 "\nUnwind section '%s' at offset 0x%lx "
10484 "contains %lu entries:\n",
10486 printable_section_name (filedata
, sec
),
10487 (unsigned long) sec
->sh_offset
,
10490 if (! dump_arm_unwind (filedata
, &aux
, sec
))
10496 free ((char *) aux
.strtab
);
10502 no_processor_specific_unwind (Filedata
* filedata ATTRIBUTE_UNUSED
)
10504 printf (_("No processor specific unwind information to decode\n"));
10509 process_unwind (Filedata
* filedata
)
10511 struct unwind_handler
10513 unsigned int machtype
;
10514 bool (* handler
)(Filedata
*);
10517 { EM_ARM
, arm_process_unwind
},
10518 { EM_IA_64
, ia64_process_unwind
},
10519 { EM_PARISC
, hppa_process_unwind
},
10520 { EM_TI_C6000
, arm_process_unwind
},
10521 { EM_386
, no_processor_specific_unwind
},
10522 { EM_X86_64
, no_processor_specific_unwind
},
10530 for (i
= 0; handlers
[i
].handler
!= NULL
; i
++)
10531 if (filedata
->file_header
.e_machine
== handlers
[i
].machtype
)
10532 return handlers
[i
].handler (filedata
);
10534 printf (_("\nThe decoding of unwind sections for machine type %s is not currently supported.\n"),
10535 get_machine_name (filedata
->file_header
.e_machine
));
10540 dynamic_section_aarch64_val (Elf_Internal_Dyn
* entry
)
10542 switch (entry
->d_tag
)
10544 case DT_AARCH64_BTI_PLT
:
10545 case DT_AARCH64_PAC_PLT
:
10548 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
10555 dynamic_section_mips_val (Filedata
* filedata
, Elf_Internal_Dyn
* entry
)
10557 switch (entry
->d_tag
)
10559 case DT_MIPS_FLAGS
:
10560 if (entry
->d_un
.d_val
== 0)
10561 printf (_("NONE"));
10564 static const char * opts
[] =
10566 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
10567 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
10568 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
10569 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
10575 for (cnt
= 0; cnt
< ARRAY_SIZE (opts
); ++cnt
)
10576 if (entry
->d_un
.d_val
& (1 << cnt
))
10578 printf ("%s%s", first
? "" : " ", opts
[cnt
]);
10584 case DT_MIPS_IVERSION
:
10585 if (valid_dynamic_name (filedata
, entry
->d_un
.d_val
))
10586 printf (_("Interface Version: %s"),
10587 get_dynamic_name (filedata
, entry
->d_un
.d_val
));
10591 sprintf_vma (buf
, entry
->d_un
.d_ptr
);
10592 /* Note: coded this way so that there is a single string for translation. */
10593 printf (_("<corrupt: %s>"), buf
);
10597 case DT_MIPS_TIME_STAMP
:
10601 time_t atime
= entry
->d_un
.d_val
;
10603 tmp
= gmtime (&atime
);
10604 /* PR 17531: file: 6accc532. */
10606 snprintf (timebuf
, sizeof (timebuf
), _("<corrupt>"));
10608 snprintf (timebuf
, sizeof (timebuf
), "%04u-%02u-%02uT%02u:%02u:%02u",
10609 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
10610 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
10611 printf (_("Time Stamp: %s"), timebuf
);
10615 case DT_MIPS_RLD_VERSION
:
10616 case DT_MIPS_LOCAL_GOTNO
:
10617 case DT_MIPS_CONFLICTNO
:
10618 case DT_MIPS_LIBLISTNO
:
10619 case DT_MIPS_SYMTABNO
:
10620 case DT_MIPS_UNREFEXTNO
:
10621 case DT_MIPS_HIPAGENO
:
10622 case DT_MIPS_DELTA_CLASS_NO
:
10623 case DT_MIPS_DELTA_INSTANCE_NO
:
10624 case DT_MIPS_DELTA_RELOC_NO
:
10625 case DT_MIPS_DELTA_SYM_NO
:
10626 case DT_MIPS_DELTA_CLASSSYM_NO
:
10627 case DT_MIPS_COMPACT_SIZE
:
10628 print_vma (entry
->d_un
.d_val
, DEC
);
10631 case DT_MIPS_XHASH
:
10632 filedata
->dynamic_info_DT_MIPS_XHASH
= entry
->d_un
.d_val
;
10633 filedata
->dynamic_info_DT_GNU_HASH
= entry
->d_un
.d_val
;
10634 /* Falls through. */
10637 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
10643 dynamic_section_parisc_val (Elf_Internal_Dyn
* entry
)
10645 switch (entry
->d_tag
)
10647 case DT_HP_DLD_FLAGS
:
10656 { DT_HP_DEBUG_PRIVATE
, "HP_DEBUG_PRIVATE" },
10657 { DT_HP_DEBUG_CALLBACK
, "HP_DEBUG_CALLBACK" },
10658 { DT_HP_DEBUG_CALLBACK_BOR
, "HP_DEBUG_CALLBACK_BOR" },
10659 { DT_HP_NO_ENVVAR
, "HP_NO_ENVVAR" },
10660 { DT_HP_BIND_NOW
, "HP_BIND_NOW" },
10661 { DT_HP_BIND_NONFATAL
, "HP_BIND_NONFATAL" },
10662 { DT_HP_BIND_VERBOSE
, "HP_BIND_VERBOSE" },
10663 { DT_HP_BIND_RESTRICTED
, "HP_BIND_RESTRICTED" },
10664 { DT_HP_BIND_SYMBOLIC
, "HP_BIND_SYMBOLIC" },
10665 { DT_HP_RPATH_FIRST
, "HP_RPATH_FIRST" },
10666 { DT_HP_BIND_DEPTH_FIRST
, "HP_BIND_DEPTH_FIRST" },
10667 { DT_HP_GST
, "HP_GST" },
10668 { DT_HP_SHLIB_FIXED
, "HP_SHLIB_FIXED" },
10669 { DT_HP_MERGE_SHLIB_SEG
, "HP_MERGE_SHLIB_SEG" },
10670 { DT_HP_NODELETE
, "HP_NODELETE" },
10671 { DT_HP_GROUP
, "HP_GROUP" },
10672 { DT_HP_PROTECT_LINKAGE_TABLE
, "HP_PROTECT_LINKAGE_TABLE" }
10676 bfd_vma val
= entry
->d_un
.d_val
;
10678 for (cnt
= 0; cnt
< ARRAY_SIZE (flags
); ++cnt
)
10679 if (val
& flags
[cnt
].bit
)
10683 fputs (flags
[cnt
].str
, stdout
);
10685 val
^= flags
[cnt
].bit
;
10688 if (val
!= 0 || first
)
10692 print_vma (val
, HEX
);
10698 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
10706 /* VMS vs Unix time offset and factor. */
10708 #define VMS_EPOCH_OFFSET 35067168000000000LL
10709 #define VMS_GRANULARITY_FACTOR 10000000
10711 #define INT64_MIN (-9223372036854775807LL - 1)
10714 /* Display a VMS time in a human readable format. */
10717 print_vms_time (bfd_int64_t vmstime
)
10719 struct tm
*tm
= NULL
;
10722 if (vmstime
>= INT64_MIN
+ VMS_EPOCH_OFFSET
)
10724 vmstime
= (vmstime
- VMS_EPOCH_OFFSET
) / VMS_GRANULARITY_FACTOR
;
10726 if (unxtime
== vmstime
)
10727 tm
= gmtime (&unxtime
);
10730 printf ("%04u-%02u-%02uT%02u:%02u:%02u",
10731 tm
->tm_year
+ 1900, tm
->tm_mon
+ 1, tm
->tm_mday
,
10732 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
);
10737 dynamic_section_ia64_val (Elf_Internal_Dyn
* entry
)
10739 switch (entry
->d_tag
)
10741 case DT_IA_64_PLT_RESERVE
:
10742 /* First 3 slots reserved. */
10743 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
10745 print_vma (entry
->d_un
.d_ptr
+ (3 * 8), PREFIX_HEX
);
10748 case DT_IA_64_VMS_LINKTIME
:
10750 print_vms_time (entry
->d_un
.d_val
);
10754 case DT_IA_64_VMS_LNKFLAGS
:
10755 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
10756 if (entry
->d_un
.d_val
& VMS_LF_CALL_DEBUG
)
10757 printf (" CALL_DEBUG");
10758 if (entry
->d_un
.d_val
& VMS_LF_NOP0BUFS
)
10759 printf (" NOP0BUFS");
10760 if (entry
->d_un
.d_val
& VMS_LF_P0IMAGE
)
10761 printf (" P0IMAGE");
10762 if (entry
->d_un
.d_val
& VMS_LF_MKTHREADS
)
10763 printf (" MKTHREADS");
10764 if (entry
->d_un
.d_val
& VMS_LF_UPCALLS
)
10765 printf (" UPCALLS");
10766 if (entry
->d_un
.d_val
& VMS_LF_IMGSTA
)
10767 printf (" IMGSTA");
10768 if (entry
->d_un
.d_val
& VMS_LF_INITIALIZE
)
10769 printf (" INITIALIZE");
10770 if (entry
->d_un
.d_val
& VMS_LF_MAIN
)
10772 if (entry
->d_un
.d_val
& VMS_LF_EXE_INIT
)
10773 printf (" EXE_INIT");
10774 if (entry
->d_un
.d_val
& VMS_LF_TBK_IN_IMG
)
10775 printf (" TBK_IN_IMG");
10776 if (entry
->d_un
.d_val
& VMS_LF_DBG_IN_IMG
)
10777 printf (" DBG_IN_IMG");
10778 if (entry
->d_un
.d_val
& VMS_LF_TBK_IN_DSF
)
10779 printf (" TBK_IN_DSF");
10780 if (entry
->d_un
.d_val
& VMS_LF_DBG_IN_DSF
)
10781 printf (" DBG_IN_DSF");
10782 if (entry
->d_un
.d_val
& VMS_LF_SIGNATURES
)
10783 printf (" SIGNATURES");
10784 if (entry
->d_un
.d_val
& VMS_LF_REL_SEG_OFF
)
10785 printf (" REL_SEG_OFF");
10789 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
10796 get_32bit_dynamic_section (Filedata
* filedata
)
10798 Elf32_External_Dyn
* edyn
;
10799 Elf32_External_Dyn
* ext
;
10800 Elf_Internal_Dyn
* entry
;
10802 edyn
= (Elf32_External_Dyn
*) get_data (NULL
, filedata
,
10803 filedata
->dynamic_addr
, 1,
10804 filedata
->dynamic_size
,
10805 _("dynamic section"));
10809 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
10810 might not have the luxury of section headers. Look for the DT_NULL
10811 terminator to determine the number of entries. */
10812 for (ext
= edyn
, filedata
->dynamic_nent
= 0;
10813 (char *) (ext
+ 1) <= (char *) edyn
+ filedata
->dynamic_size
;
10816 filedata
->dynamic_nent
++;
10817 if (BYTE_GET (ext
->d_tag
) == DT_NULL
)
10821 filedata
->dynamic_section
10822 = (Elf_Internal_Dyn
*) cmalloc (filedata
->dynamic_nent
, sizeof (* entry
));
10823 if (filedata
->dynamic_section
== NULL
)
10825 error (_("Out of memory allocating space for %lu dynamic entries\n"),
10826 (unsigned long) filedata
->dynamic_nent
);
10831 for (ext
= edyn
, entry
= filedata
->dynamic_section
;
10832 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
10835 entry
->d_tag
= BYTE_GET (ext
->d_tag
);
10836 entry
->d_un
.d_val
= BYTE_GET (ext
->d_un
.d_val
);
10845 get_64bit_dynamic_section (Filedata
* filedata
)
10847 Elf64_External_Dyn
* edyn
;
10848 Elf64_External_Dyn
* ext
;
10849 Elf_Internal_Dyn
* entry
;
10851 /* Read in the data. */
10852 edyn
= (Elf64_External_Dyn
*) get_data (NULL
, filedata
,
10853 filedata
->dynamic_addr
, 1,
10854 filedata
->dynamic_size
,
10855 _("dynamic section"));
10859 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
10860 might not have the luxury of section headers. Look for the DT_NULL
10861 terminator to determine the number of entries. */
10862 for (ext
= edyn
, filedata
->dynamic_nent
= 0;
10863 /* PR 17533 file: 033-67080-0.004 - do not read past end of buffer. */
10864 (char *) (ext
+ 1) <= (char *) edyn
+ filedata
->dynamic_size
;
10867 filedata
->dynamic_nent
++;
10868 if (BYTE_GET (ext
->d_tag
) == DT_NULL
)
10872 filedata
->dynamic_section
10873 = (Elf_Internal_Dyn
*) cmalloc (filedata
->dynamic_nent
, sizeof (* entry
));
10874 if (filedata
->dynamic_section
== NULL
)
10876 error (_("Out of memory allocating space for %lu dynamic entries\n"),
10877 (unsigned long) filedata
->dynamic_nent
);
10882 /* Convert from external to internal formats. */
10883 for (ext
= edyn
, entry
= filedata
->dynamic_section
;
10884 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
10887 entry
->d_tag
= BYTE_GET (ext
->d_tag
);
10888 entry
->d_un
.d_val
= BYTE_GET (ext
->d_un
.d_val
);
10897 get_dynamic_section (Filedata
*filedata
)
10899 if (filedata
->dynamic_section
)
10903 return get_32bit_dynamic_section (filedata
);
10905 return get_64bit_dynamic_section (filedata
);
10909 print_dynamic_flags (bfd_vma flags
)
10917 flag
= flags
& - flags
;
10923 putc (' ', stdout
);
10927 case DF_ORIGIN
: fputs ("ORIGIN", stdout
); break;
10928 case DF_SYMBOLIC
: fputs ("SYMBOLIC", stdout
); break;
10929 case DF_TEXTREL
: fputs ("TEXTREL", stdout
); break;
10930 case DF_BIND_NOW
: fputs ("BIND_NOW", stdout
); break;
10931 case DF_STATIC_TLS
: fputs ("STATIC_TLS", stdout
); break;
10932 default: fputs (_("unknown"), stdout
); break;
10939 get_dynamic_data (Filedata
* filedata
, bfd_size_type number
, unsigned int ent_size
)
10941 unsigned char * e_data
;
10944 /* If the size_t type is smaller than the bfd_size_type, eg because
10945 you are building a 32-bit tool on a 64-bit host, then make sure
10946 that when (number) is cast to (size_t) no information is lost. */
10947 if (sizeof (size_t) < sizeof (bfd_size_type
)
10948 && (bfd_size_type
) ((size_t) number
) != number
)
10950 error (_("Size truncation prevents reading %s elements of size %u\n"),
10951 bfd_vmatoa ("u", number
), ent_size
);
10955 /* Be kind to memory checkers (eg valgrind, address sanitizer) by not
10956 attempting to allocate memory when the read is bound to fail. */
10957 if (ent_size
* number
> filedata
->file_size
)
10959 error (_("Invalid number of dynamic entries: %s\n"),
10960 bfd_vmatoa ("u", number
));
10964 e_data
= (unsigned char *) cmalloc ((size_t) number
, ent_size
);
10965 if (e_data
== NULL
)
10967 error (_("Out of memory reading %s dynamic entries\n"),
10968 bfd_vmatoa ("u", number
));
10972 if (fread (e_data
, ent_size
, (size_t) number
, filedata
->handle
) != number
)
10974 error (_("Unable to read in %s bytes of dynamic data\n"),
10975 bfd_vmatoa ("u", number
* ent_size
));
10980 i_data
= (bfd_vma
*) cmalloc ((size_t) number
, sizeof (*i_data
));
10981 if (i_data
== NULL
)
10983 error (_("Out of memory allocating space for %s dynamic entries\n"),
10984 bfd_vmatoa ("u", number
));
10990 i_data
[number
] = byte_get (e_data
+ number
* ent_size
, ent_size
);
10997 static unsigned long
10998 get_num_dynamic_syms (Filedata
* filedata
)
11000 unsigned long num_of_syms
= 0;
11002 if (!do_histogram
&& (!do_using_dynamic
|| do_dyn_syms
))
11003 return num_of_syms
;
11005 if (filedata
->dynamic_info
[DT_HASH
])
11007 unsigned char nb
[8];
11008 unsigned char nc
[8];
11009 unsigned int hash_ent_size
= 4;
11011 if ((filedata
->file_header
.e_machine
== EM_ALPHA
11012 || filedata
->file_header
.e_machine
== EM_S390
11013 || filedata
->file_header
.e_machine
== EM_S390_OLD
)
11014 && filedata
->file_header
.e_ident
[EI_CLASS
] == ELFCLASS64
)
11017 if (fseek (filedata
->handle
,
11018 (filedata
->archive_file_offset
11019 + offset_from_vma (filedata
, filedata
->dynamic_info
[DT_HASH
],
11020 sizeof nb
+ sizeof nc
)),
11023 error (_("Unable to seek to start of dynamic information\n"));
11027 if (fread (nb
, hash_ent_size
, 1, filedata
->handle
) != 1)
11029 error (_("Failed to read in number of buckets\n"));
11033 if (fread (nc
, hash_ent_size
, 1, filedata
->handle
) != 1)
11035 error (_("Failed to read in number of chains\n"));
11039 filedata
->nbuckets
= byte_get (nb
, hash_ent_size
);
11040 filedata
->nchains
= byte_get (nc
, hash_ent_size
);
11042 if (filedata
->nbuckets
!= 0 && filedata
->nchains
!= 0)
11044 filedata
->buckets
= get_dynamic_data (filedata
, filedata
->nbuckets
,
11046 filedata
->chains
= get_dynamic_data (filedata
, filedata
->nchains
,
11049 if (filedata
->buckets
!= NULL
&& filedata
->chains
!= NULL
)
11050 num_of_syms
= filedata
->nchains
;
11053 if (num_of_syms
== 0)
11055 free (filedata
->buckets
);
11056 filedata
->buckets
= NULL
;
11057 free (filedata
->chains
);
11058 filedata
->chains
= NULL
;
11059 filedata
->nbuckets
= 0;
11063 if (filedata
->dynamic_info_DT_GNU_HASH
)
11065 unsigned char nb
[16];
11066 bfd_vma i
, maxchain
= 0xffffffff, bitmaskwords
;
11067 bfd_vma buckets_vma
;
11070 if (fseek (filedata
->handle
,
11071 (filedata
->archive_file_offset
11072 + offset_from_vma (filedata
,
11073 filedata
->dynamic_info_DT_GNU_HASH
,
11077 error (_("Unable to seek to start of dynamic information\n"));
11081 if (fread (nb
, 16, 1, filedata
->handle
) != 1)
11083 error (_("Failed to read in number of buckets\n"));
11087 filedata
->ngnubuckets
= byte_get (nb
, 4);
11088 filedata
->gnusymidx
= byte_get (nb
+ 4, 4);
11089 bitmaskwords
= byte_get (nb
+ 8, 4);
11090 buckets_vma
= filedata
->dynamic_info_DT_GNU_HASH
+ 16;
11092 buckets_vma
+= bitmaskwords
* 4;
11094 buckets_vma
+= bitmaskwords
* 8;
11096 if (fseek (filedata
->handle
,
11097 (filedata
->archive_file_offset
11098 + offset_from_vma (filedata
, buckets_vma
, 4)),
11101 error (_("Unable to seek to start of dynamic information\n"));
11105 filedata
->gnubuckets
11106 = get_dynamic_data (filedata
, filedata
->ngnubuckets
, 4);
11108 if (filedata
->gnubuckets
== NULL
)
11111 for (i
= 0; i
< filedata
->ngnubuckets
; i
++)
11112 if (filedata
->gnubuckets
[i
] != 0)
11114 if (filedata
->gnubuckets
[i
] < filedata
->gnusymidx
)
11117 if (maxchain
== 0xffffffff || filedata
->gnubuckets
[i
] > maxchain
)
11118 maxchain
= filedata
->gnubuckets
[i
];
11121 if (maxchain
== 0xffffffff)
11124 maxchain
-= filedata
->gnusymidx
;
11126 if (fseek (filedata
->handle
,
11127 (filedata
->archive_file_offset
11128 + offset_from_vma (filedata
,
11129 buckets_vma
+ 4 * (filedata
->ngnubuckets
11134 error (_("Unable to seek to start of dynamic information\n"));
11140 if (fread (nb
, 4, 1, filedata
->handle
) != 1)
11142 error (_("Failed to determine last chain length\n"));
11146 if (maxchain
+ 1 == 0)
11151 while ((byte_get (nb
, 4) & 1) == 0);
11153 if (fseek (filedata
->handle
,
11154 (filedata
->archive_file_offset
11155 + offset_from_vma (filedata
, (buckets_vma
11156 + 4 * filedata
->ngnubuckets
),
11160 error (_("Unable to seek to start of dynamic information\n"));
11164 filedata
->gnuchains
= get_dynamic_data (filedata
, maxchain
, 4);
11165 filedata
->ngnuchains
= maxchain
;
11167 if (filedata
->gnuchains
== NULL
)
11170 if (filedata
->dynamic_info_DT_MIPS_XHASH
)
11172 if (fseek (filedata
->handle
,
11173 (filedata
->archive_file_offset
11174 + offset_from_vma (filedata
, (buckets_vma
11175 + 4 * (filedata
->ngnubuckets
11179 error (_("Unable to seek to start of dynamic information\n"));
11183 filedata
->mipsxlat
= get_dynamic_data (filedata
, maxchain
, 4);
11184 if (filedata
->mipsxlat
== NULL
)
11188 for (hn
= 0; hn
< filedata
->ngnubuckets
; ++hn
)
11189 if (filedata
->gnubuckets
[hn
] != 0)
11191 bfd_vma si
= filedata
->gnubuckets
[hn
];
11192 bfd_vma off
= si
- filedata
->gnusymidx
;
11196 if (filedata
->dynamic_info_DT_MIPS_XHASH
)
11198 if (off
< filedata
->ngnuchains
11199 && filedata
->mipsxlat
[off
] >= num_of_syms
)
11200 num_of_syms
= filedata
->mipsxlat
[off
] + 1;
11204 if (si
>= num_of_syms
)
11205 num_of_syms
= si
+ 1;
11209 while (off
< filedata
->ngnuchains
11210 && (filedata
->gnuchains
[off
++] & 1) == 0);
11213 if (num_of_syms
== 0)
11216 free (filedata
->mipsxlat
);
11217 filedata
->mipsxlat
= NULL
;
11218 free (filedata
->gnuchains
);
11219 filedata
->gnuchains
= NULL
;
11220 free (filedata
->gnubuckets
);
11221 filedata
->gnubuckets
= NULL
;
11222 filedata
->ngnubuckets
= 0;
11223 filedata
->ngnuchains
= 0;
11227 return num_of_syms
;
11230 /* Parse and display the contents of the dynamic section. */
11233 process_dynamic_section (Filedata
* filedata
)
11235 Elf_Internal_Dyn
* entry
;
11237 if (filedata
->dynamic_size
<= 1)
11241 if (filedata
->is_separate
)
11242 printf (_("\nThere is no dynamic section in linked file '%s'.\n"),
11243 filedata
->file_name
);
11245 printf (_("\nThere is no dynamic section in this file.\n"));
11251 if (!get_dynamic_section (filedata
))
11254 /* Find the appropriate symbol table. */
11255 if (filedata
->dynamic_symbols
== NULL
|| do_histogram
)
11257 unsigned long num_of_syms
;
11259 for (entry
= filedata
->dynamic_section
;
11260 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
11262 if (entry
->d_tag
== DT_SYMTAB
)
11263 filedata
->dynamic_info
[DT_SYMTAB
] = entry
->d_un
.d_val
;
11264 else if (entry
->d_tag
== DT_SYMENT
)
11265 filedata
->dynamic_info
[DT_SYMENT
] = entry
->d_un
.d_val
;
11266 else if (entry
->d_tag
== DT_HASH
)
11267 filedata
->dynamic_info
[DT_HASH
] = entry
->d_un
.d_val
;
11268 else if (entry
->d_tag
== DT_GNU_HASH
)
11269 filedata
->dynamic_info_DT_GNU_HASH
= entry
->d_un
.d_val
;
11270 else if ((filedata
->file_header
.e_machine
== EM_MIPS
11271 || filedata
->file_header
.e_machine
== EM_MIPS_RS3_LE
)
11272 && entry
->d_tag
== DT_MIPS_XHASH
)
11274 filedata
->dynamic_info_DT_MIPS_XHASH
= entry
->d_un
.d_val
;
11275 filedata
->dynamic_info_DT_GNU_HASH
= entry
->d_un
.d_val
;
11278 num_of_syms
= get_num_dynamic_syms (filedata
);
11280 if (num_of_syms
!= 0
11281 && filedata
->dynamic_symbols
== NULL
11282 && filedata
->dynamic_info
[DT_SYMTAB
]
11283 && filedata
->dynamic_info
[DT_SYMENT
])
11285 Elf_Internal_Phdr
*seg
;
11286 bfd_vma vma
= filedata
->dynamic_info
[DT_SYMTAB
];
11288 if (! get_program_headers (filedata
))
11290 error (_("Cannot interpret virtual addresses "
11291 "without program headers.\n"));
11295 for (seg
= filedata
->program_headers
;
11296 seg
< filedata
->program_headers
+ filedata
->file_header
.e_phnum
;
11299 if (seg
->p_type
!= PT_LOAD
)
11302 if (seg
->p_offset
+ seg
->p_filesz
> filedata
->file_size
)
11304 /* See PR 21379 for a reproducer. */
11305 error (_("Invalid PT_LOAD entry\n"));
11309 if (vma
>= (seg
->p_vaddr
& -seg
->p_align
)
11310 && vma
< seg
->p_vaddr
+ seg
->p_filesz
)
11312 /* Since we do not know how big the symbol table is,
11313 we default to reading in up to the end of PT_LOAD
11314 segment and processing that. This is overkill, I
11315 know, but it should work. */
11316 Elf_Internal_Shdr section
;
11317 section
.sh_offset
= (vma
- seg
->p_vaddr
11319 section
.sh_size
= (num_of_syms
11320 * filedata
->dynamic_info
[DT_SYMENT
]);
11321 section
.sh_entsize
= filedata
->dynamic_info
[DT_SYMENT
];
11324 && filedata
->dynamic_symtab_section
!= NULL
11325 && ((filedata
->dynamic_symtab_section
->sh_offset
11326 != section
.sh_offset
)
11327 || (filedata
->dynamic_symtab_section
->sh_size
11328 != section
.sh_size
)
11329 || (filedata
->dynamic_symtab_section
->sh_entsize
11330 != section
.sh_entsize
)))
11332 the .dynsym section doesn't match the DT_SYMTAB and DT_SYMENT tags\n"));
11334 section
.sh_name
= filedata
->string_table_length
;
11335 filedata
->dynamic_symbols
11336 = get_elf_symbols (filedata
, §ion
,
11337 &filedata
->num_dynamic_syms
);
11338 if (filedata
->dynamic_symbols
== NULL
11339 || filedata
->num_dynamic_syms
!= num_of_syms
)
11341 error (_("Corrupt DT_SYMTAB dynamic entry\n"));
11350 /* Similarly find a string table. */
11351 if (filedata
->dynamic_strings
== NULL
)
11352 for (entry
= filedata
->dynamic_section
;
11353 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
11356 if (entry
->d_tag
== DT_STRTAB
)
11357 filedata
->dynamic_info
[DT_STRTAB
] = entry
->d_un
.d_val
;
11359 if (entry
->d_tag
== DT_STRSZ
)
11360 filedata
->dynamic_info
[DT_STRSZ
] = entry
->d_un
.d_val
;
11362 if (filedata
->dynamic_info
[DT_STRTAB
]
11363 && filedata
->dynamic_info
[DT_STRSZ
])
11365 unsigned long offset
;
11366 bfd_size_type str_tab_len
= filedata
->dynamic_info
[DT_STRSZ
];
11368 offset
= offset_from_vma (filedata
,
11369 filedata
->dynamic_info
[DT_STRTAB
],
11372 && filedata
->dynamic_strtab_section
11373 && ((filedata
->dynamic_strtab_section
->sh_offset
11374 != (file_ptr
) offset
)
11375 || (filedata
->dynamic_strtab_section
->sh_size
11378 the .dynstr section doesn't match the DT_STRTAB and DT_STRSZ tags\n"));
11380 filedata
->dynamic_strings
11381 = (char *) get_data (NULL
, filedata
, offset
, 1, str_tab_len
,
11382 _("dynamic string table"));
11383 if (filedata
->dynamic_strings
== NULL
)
11385 error (_("Corrupt DT_STRTAB dynamic entry\n"));
11389 filedata
->dynamic_strings_length
= str_tab_len
;
11394 /* And find the syminfo section if available. */
11395 if (filedata
->dynamic_syminfo
== NULL
)
11397 unsigned long syminsz
= 0;
11399 for (entry
= filedata
->dynamic_section
;
11400 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
11403 if (entry
->d_tag
== DT_SYMINENT
)
11405 /* Note: these braces are necessary to avoid a syntax
11406 error from the SunOS4 C compiler. */
11407 /* PR binutils/17531: A corrupt file can trigger this test.
11408 So do not use an assert, instead generate an error message. */
11409 if (sizeof (Elf_External_Syminfo
) != entry
->d_un
.d_val
)
11410 error (_("Bad value (%d) for SYMINENT entry\n"),
11411 (int) entry
->d_un
.d_val
);
11413 else if (entry
->d_tag
== DT_SYMINSZ
)
11414 syminsz
= entry
->d_un
.d_val
;
11415 else if (entry
->d_tag
== DT_SYMINFO
)
11416 filedata
->dynamic_syminfo_offset
11417 = offset_from_vma (filedata
, entry
->d_un
.d_val
, syminsz
);
11420 if (filedata
->dynamic_syminfo_offset
!= 0 && syminsz
!= 0)
11422 Elf_External_Syminfo
* extsyminfo
;
11423 Elf_External_Syminfo
* extsym
;
11424 Elf_Internal_Syminfo
* syminfo
;
11426 /* There is a syminfo section. Read the data. */
11427 extsyminfo
= (Elf_External_Syminfo
*)
11428 get_data (NULL
, filedata
, filedata
->dynamic_syminfo_offset
,
11429 1, syminsz
, _("symbol information"));
11433 if (filedata
->dynamic_syminfo
!= NULL
)
11435 error (_("Multiple dynamic symbol information sections found\n"));
11436 free (filedata
->dynamic_syminfo
);
11438 filedata
->dynamic_syminfo
= (Elf_Internal_Syminfo
*) malloc (syminsz
);
11439 if (filedata
->dynamic_syminfo
== NULL
)
11441 error (_("Out of memory allocating %lu bytes "
11442 "for dynamic symbol info\n"),
11443 (unsigned long) syminsz
);
11447 filedata
->dynamic_syminfo_nent
11448 = syminsz
/ sizeof (Elf_External_Syminfo
);
11449 for (syminfo
= filedata
->dynamic_syminfo
, extsym
= extsyminfo
;
11450 syminfo
< (filedata
->dynamic_syminfo
11451 + filedata
->dynamic_syminfo_nent
);
11452 ++syminfo
, ++extsym
)
11454 syminfo
->si_boundto
= BYTE_GET (extsym
->si_boundto
);
11455 syminfo
->si_flags
= BYTE_GET (extsym
->si_flags
);
11462 if (do_dynamic
&& filedata
->dynamic_addr
)
11464 if (filedata
->is_separate
)
11465 printf (ngettext ("\nIn linked file '%s' the dynamic section at offset 0x%lx contains %lu entry:\n",
11466 "\nIn linked file '%s' the dynamic section at offset 0x%lx contains %lu entries:\n",
11467 (unsigned long) filedata
->dynamic_nent
),
11468 filedata
->file_name
,
11469 filedata
->dynamic_addr
,
11470 (unsigned long) filedata
->dynamic_nent
);
11472 printf (ngettext ("\nDynamic section at offset 0x%lx contains %lu entry:\n",
11473 "\nDynamic section at offset 0x%lx contains %lu entries:\n",
11474 (unsigned long) filedata
->dynamic_nent
),
11475 filedata
->dynamic_addr
,
11476 (unsigned long) filedata
->dynamic_nent
);
11479 printf (_(" Tag Type Name/Value\n"));
11481 for (entry
= filedata
->dynamic_section
;
11482 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
11487 const char * dtype
;
11490 print_vma (entry
->d_tag
, FULL_HEX
);
11491 dtype
= get_dynamic_type (filedata
, entry
->d_tag
);
11492 printf (" (%s)%*s", dtype
,
11493 ((is_32bit_elf
? 27 : 19) - (int) strlen (dtype
)), " ");
11496 switch (entry
->d_tag
)
11500 print_dynamic_flags (entry
->d_un
.d_val
);
11510 switch (entry
->d_tag
)
11513 printf (_("Auxiliary library"));
11517 printf (_("Filter library"));
11521 printf (_("Configuration file"));
11525 printf (_("Dependency audit library"));
11529 printf (_("Audit library"));
11533 if (valid_dynamic_name (filedata
, entry
->d_un
.d_val
))
11534 printf (": [%s]\n",
11535 get_dynamic_name (filedata
, entry
->d_un
.d_val
));
11539 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
11548 printf (_("Flags:"));
11550 if (entry
->d_un
.d_val
== 0)
11551 printf (_(" None\n"));
11554 unsigned long int val
= entry
->d_un
.d_val
;
11556 if (val
& DTF_1_PARINIT
)
11558 printf (" PARINIT");
11559 val
^= DTF_1_PARINIT
;
11561 if (val
& DTF_1_CONFEXP
)
11563 printf (" CONFEXP");
11564 val
^= DTF_1_CONFEXP
;
11567 printf (" %lx", val
);
11576 printf (_("Flags:"));
11578 if (entry
->d_un
.d_val
== 0)
11579 printf (_(" None\n"));
11582 unsigned long int val
= entry
->d_un
.d_val
;
11584 if (val
& DF_P1_LAZYLOAD
)
11586 printf (" LAZYLOAD");
11587 val
^= DF_P1_LAZYLOAD
;
11589 if (val
& DF_P1_GROUPPERM
)
11591 printf (" GROUPPERM");
11592 val
^= DF_P1_GROUPPERM
;
11595 printf (" %lx", val
);
11604 printf (_("Flags:"));
11605 if (entry
->d_un
.d_val
== 0)
11606 printf (_(" None\n"));
11609 unsigned long int val
= entry
->d_un
.d_val
;
11611 if (val
& DF_1_NOW
)
11616 if (val
& DF_1_GLOBAL
)
11618 printf (" GLOBAL");
11619 val
^= DF_1_GLOBAL
;
11621 if (val
& DF_1_GROUP
)
11626 if (val
& DF_1_NODELETE
)
11628 printf (" NODELETE");
11629 val
^= DF_1_NODELETE
;
11631 if (val
& DF_1_LOADFLTR
)
11633 printf (" LOADFLTR");
11634 val
^= DF_1_LOADFLTR
;
11636 if (val
& DF_1_INITFIRST
)
11638 printf (" INITFIRST");
11639 val
^= DF_1_INITFIRST
;
11641 if (val
& DF_1_NOOPEN
)
11643 printf (" NOOPEN");
11644 val
^= DF_1_NOOPEN
;
11646 if (val
& DF_1_ORIGIN
)
11648 printf (" ORIGIN");
11649 val
^= DF_1_ORIGIN
;
11651 if (val
& DF_1_DIRECT
)
11653 printf (" DIRECT");
11654 val
^= DF_1_DIRECT
;
11656 if (val
& DF_1_TRANS
)
11661 if (val
& DF_1_INTERPOSE
)
11663 printf (" INTERPOSE");
11664 val
^= DF_1_INTERPOSE
;
11666 if (val
& DF_1_NODEFLIB
)
11668 printf (" NODEFLIB");
11669 val
^= DF_1_NODEFLIB
;
11671 if (val
& DF_1_NODUMP
)
11673 printf (" NODUMP");
11674 val
^= DF_1_NODUMP
;
11676 if (val
& DF_1_CONFALT
)
11678 printf (" CONFALT");
11679 val
^= DF_1_CONFALT
;
11681 if (val
& DF_1_ENDFILTEE
)
11683 printf (" ENDFILTEE");
11684 val
^= DF_1_ENDFILTEE
;
11686 if (val
& DF_1_DISPRELDNE
)
11688 printf (" DISPRELDNE");
11689 val
^= DF_1_DISPRELDNE
;
11691 if (val
& DF_1_DISPRELPND
)
11693 printf (" DISPRELPND");
11694 val
^= DF_1_DISPRELPND
;
11696 if (val
& DF_1_NODIRECT
)
11698 printf (" NODIRECT");
11699 val
^= DF_1_NODIRECT
;
11701 if (val
& DF_1_IGNMULDEF
)
11703 printf (" IGNMULDEF");
11704 val
^= DF_1_IGNMULDEF
;
11706 if (val
& DF_1_NOKSYMS
)
11708 printf (" NOKSYMS");
11709 val
^= DF_1_NOKSYMS
;
11711 if (val
& DF_1_NOHDR
)
11716 if (val
& DF_1_EDITED
)
11718 printf (" EDITED");
11719 val
^= DF_1_EDITED
;
11721 if (val
& DF_1_NORELOC
)
11723 printf (" NORELOC");
11724 val
^= DF_1_NORELOC
;
11726 if (val
& DF_1_SYMINTPOSE
)
11728 printf (" SYMINTPOSE");
11729 val
^= DF_1_SYMINTPOSE
;
11731 if (val
& DF_1_GLOBAUDIT
)
11733 printf (" GLOBAUDIT");
11734 val
^= DF_1_GLOBAUDIT
;
11736 if (val
& DF_1_SINGLETON
)
11738 printf (" SINGLETON");
11739 val
^= DF_1_SINGLETON
;
11741 if (val
& DF_1_STUB
)
11746 if (val
& DF_1_PIE
)
11751 if (val
& DF_1_KMOD
)
11756 if (val
& DF_1_WEAKFILTER
)
11758 printf (" WEAKFILTER");
11759 val
^= DF_1_WEAKFILTER
;
11761 if (val
& DF_1_NOCOMMON
)
11763 printf (" NOCOMMON");
11764 val
^= DF_1_NOCOMMON
;
11767 printf (" %lx", val
);
11774 filedata
->dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
11776 puts (get_dynamic_type (filedata
, entry
->d_un
.d_val
));
11797 filedata
->dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
11803 if (valid_dynamic_name (filedata
, entry
->d_un
.d_val
))
11804 name
= get_dynamic_name (filedata
, entry
->d_un
.d_val
);
11810 switch (entry
->d_tag
)
11813 printf (_("Shared library: [%s]"), name
);
11815 if (filedata
->program_interpreter
11816 && streq (name
, filedata
->program_interpreter
))
11817 printf (_(" program interpreter"));
11821 printf (_("Library soname: [%s]"), name
);
11825 printf (_("Library rpath: [%s]"), name
);
11829 printf (_("Library runpath: [%s]"), name
);
11833 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
11838 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
11853 filedata
->dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
11854 /* Fall through. */
11858 case DT_PREINIT_ARRAYSZ
:
11859 case DT_INIT_ARRAYSZ
:
11860 case DT_FINI_ARRAYSZ
:
11861 case DT_GNU_CONFLICTSZ
:
11862 case DT_GNU_LIBLISTSZ
:
11865 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
11866 printf (_(" (bytes)\n"));
11871 case DT_VERNEEDNUM
:
11876 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
11885 case DT_INIT_ARRAY
:
11886 case DT_FINI_ARRAY
:
11889 if (entry
->d_tag
== DT_USED
11890 && valid_dynamic_name (filedata
, entry
->d_un
.d_val
))
11893 = get_dynamic_name (filedata
, entry
->d_un
.d_val
);
11897 printf (_("Not needed object: [%s]\n"), name
);
11902 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
11908 /* The value of this entry is ignored. */
11913 case DT_GNU_PRELINKED
:
11917 time_t atime
= entry
->d_un
.d_val
;
11919 tmp
= gmtime (&atime
);
11920 /* PR 17533 file: 041-1244816-0.004. */
11922 printf (_("<corrupt time val: %lx"),
11923 (unsigned long) atime
);
11925 printf ("%04u-%02u-%02uT%02u:%02u:%02u\n",
11926 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
11927 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
11933 filedata
->dynamic_info_DT_GNU_HASH
= entry
->d_un
.d_val
;
11936 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
11941 case DT_GNU_FLAGS_1
:
11944 printf (_("Flags:"));
11945 if (entry
->d_un
.d_val
== 0)
11946 printf (_(" None\n"));
11949 unsigned long int val
= entry
->d_un
.d_val
;
11951 if (val
& DF_GNU_1_UNIQUE
)
11953 printf (" UNIQUE");
11954 val
^= DF_GNU_1_UNIQUE
;
11957 printf (" %lx", val
);
11964 if ((entry
->d_tag
>= DT_VERSYM
) && (entry
->d_tag
<= DT_VERNEEDNUM
))
11965 filedata
->version_info
[DT_VERSIONTAGIDX (entry
->d_tag
)]
11966 = entry
->d_un
.d_val
;
11970 switch (filedata
->file_header
.e_machine
)
11973 dynamic_section_aarch64_val (entry
);
11976 case EM_MIPS_RS3_LE
:
11977 dynamic_section_mips_val (filedata
, entry
);
11980 dynamic_section_parisc_val (entry
);
11983 dynamic_section_ia64_val (entry
);
11986 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
11998 get_ver_flags (unsigned int flags
)
12000 static char buff
[128];
12007 if (flags
& VER_FLG_BASE
)
12008 strcat (buff
, "BASE");
12010 if (flags
& VER_FLG_WEAK
)
12012 if (flags
& VER_FLG_BASE
)
12013 strcat (buff
, " | ");
12015 strcat (buff
, "WEAK");
12018 if (flags
& VER_FLG_INFO
)
12020 if (flags
& (VER_FLG_BASE
|VER_FLG_WEAK
))
12021 strcat (buff
, " | ");
12023 strcat (buff
, "INFO");
12026 if (flags
& ~(VER_FLG_BASE
| VER_FLG_WEAK
| VER_FLG_INFO
))
12028 if (flags
& (VER_FLG_BASE
| VER_FLG_WEAK
| VER_FLG_INFO
))
12029 strcat (buff
, " | ");
12031 strcat (buff
, _("<unknown>"));
12037 /* Display the contents of the version sections. */
12040 process_version_sections (Filedata
* filedata
)
12042 Elf_Internal_Shdr
* section
;
12044 bool found
= false;
12049 for (i
= 0, section
= filedata
->section_headers
;
12050 i
< filedata
->file_header
.e_shnum
;
12053 switch (section
->sh_type
)
12055 case SHT_GNU_verdef
:
12057 Elf_External_Verdef
* edefs
;
12064 if (filedata
->is_separate
)
12065 printf (ngettext ("\nIn linked file '%s' the version definition section '%s' contains %u entry:\n",
12066 "\nIn linked file '%s' the version definition section '%s' contains %u entries:\n",
12068 filedata
->file_name
,
12069 printable_section_name (filedata
, section
),
12072 printf (ngettext ("\nVersion definition section '%s' "
12073 "contains %u entry:\n",
12074 "\nVersion definition section '%s' "
12075 "contains %u entries:\n",
12077 printable_section_name (filedata
, section
),
12080 printf (_(" Addr: 0x"));
12081 printf_vma (section
->sh_addr
);
12082 printf (_(" Offset: %#08lx Link: %u (%s)\n"),
12083 (unsigned long) section
->sh_offset
, section
->sh_link
,
12084 printable_section_name_from_index (filedata
, section
->sh_link
));
12086 edefs
= (Elf_External_Verdef
*)
12087 get_data (NULL
, filedata
, section
->sh_offset
, 1,section
->sh_size
,
12088 _("version definition section"));
12091 endbuf
= (char *) edefs
+ section
->sh_size
;
12093 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
12096 Elf_External_Verdef
* edef
;
12097 Elf_Internal_Verdef ent
;
12098 Elf_External_Verdaux
* eaux
;
12099 Elf_Internal_Verdaux aux
;
12100 unsigned long isum
;
12103 vstart
= ((char *) edefs
) + idx
;
12104 if (vstart
+ sizeof (*edef
) > endbuf
)
12107 edef
= (Elf_External_Verdef
*) vstart
;
12109 ent
.vd_version
= BYTE_GET (edef
->vd_version
);
12110 ent
.vd_flags
= BYTE_GET (edef
->vd_flags
);
12111 ent
.vd_ndx
= BYTE_GET (edef
->vd_ndx
);
12112 ent
.vd_cnt
= BYTE_GET (edef
->vd_cnt
);
12113 ent
.vd_hash
= BYTE_GET (edef
->vd_hash
);
12114 ent
.vd_aux
= BYTE_GET (edef
->vd_aux
);
12115 ent
.vd_next
= BYTE_GET (edef
->vd_next
);
12117 printf (_(" %#06lx: Rev: %d Flags: %s"),
12118 idx
, ent
.vd_version
, get_ver_flags (ent
.vd_flags
));
12120 printf (_(" Index: %d Cnt: %d "),
12121 ent
.vd_ndx
, ent
.vd_cnt
);
12123 /* Check for overflow. */
12124 if (ent
.vd_aux
> (size_t) (endbuf
- vstart
))
12127 vstart
+= ent
.vd_aux
;
12129 if (vstart
+ sizeof (*eaux
) > endbuf
)
12131 eaux
= (Elf_External_Verdaux
*) vstart
;
12133 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
12134 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
12136 if (valid_dynamic_name (filedata
, aux
.vda_name
))
12137 printf (_("Name: %s\n"),
12138 get_dynamic_name (filedata
, aux
.vda_name
));
12140 printf (_("Name index: %ld\n"), aux
.vda_name
);
12142 isum
= idx
+ ent
.vd_aux
;
12144 for (j
= 1; j
< ent
.vd_cnt
; j
++)
12146 if (aux
.vda_next
< sizeof (*eaux
)
12147 && !(j
== ent
.vd_cnt
- 1 && aux
.vda_next
== 0))
12149 warn (_("Invalid vda_next field of %lx\n"),
12154 /* Check for overflow. */
12155 if (aux
.vda_next
> (size_t) (endbuf
- vstart
))
12158 isum
+= aux
.vda_next
;
12159 vstart
+= aux
.vda_next
;
12161 if (vstart
+ sizeof (*eaux
) > endbuf
)
12163 eaux
= (Elf_External_Verdaux
*) vstart
;
12165 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
12166 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
12168 if (valid_dynamic_name (filedata
, aux
.vda_name
))
12169 printf (_(" %#06lx: Parent %d: %s\n"),
12171 get_dynamic_name (filedata
, aux
.vda_name
));
12173 printf (_(" %#06lx: Parent %d, name index: %ld\n"),
12174 isum
, j
, aux
.vda_name
);
12177 if (j
< ent
.vd_cnt
)
12178 printf (_(" Version def aux past end of section\n"));
12181 file: id:000001,src:000172+005151,op:splice,rep:2. */
12182 if (ent
.vd_next
< sizeof (*edef
)
12183 && !(cnt
== section
->sh_info
- 1 && ent
.vd_next
== 0))
12185 warn (_("Invalid vd_next field of %lx\n"), ent
.vd_next
);
12186 cnt
= section
->sh_info
;
12189 if (ent
.vd_next
> (size_t) (endbuf
- ((char *) edefs
+ idx
)))
12192 idx
+= ent
.vd_next
;
12195 if (cnt
< section
->sh_info
)
12196 printf (_(" Version definition past end of section\n"));
12202 case SHT_GNU_verneed
:
12204 Elf_External_Verneed
* eneed
;
12211 if (filedata
->is_separate
)
12212 printf (ngettext ("\nIn linked file '%s' the version needs section '%s' contains %u entry:\n",
12213 "\nIn linked file '%s' the version needs section '%s' contains %u entries:\n",
12215 filedata
->file_name
,
12216 printable_section_name (filedata
, section
),
12219 printf (ngettext ("\nVersion needs section '%s' "
12220 "contains %u entry:\n",
12221 "\nVersion needs section '%s' "
12222 "contains %u entries:\n",
12224 printable_section_name (filedata
, section
),
12227 printf (_(" Addr: 0x"));
12228 printf_vma (section
->sh_addr
);
12229 printf (_(" Offset: %#08lx Link: %u (%s)\n"),
12230 (unsigned long) section
->sh_offset
, section
->sh_link
,
12231 printable_section_name_from_index (filedata
, section
->sh_link
));
12233 eneed
= (Elf_External_Verneed
*) get_data (NULL
, filedata
,
12234 section
->sh_offset
, 1,
12236 _("Version Needs section"));
12239 endbuf
= (char *) eneed
+ section
->sh_size
;
12241 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
12243 Elf_External_Verneed
* entry
;
12244 Elf_Internal_Verneed ent
;
12245 unsigned long isum
;
12249 vstart
= ((char *) eneed
) + idx
;
12250 if (vstart
+ sizeof (*entry
) > endbuf
)
12253 entry
= (Elf_External_Verneed
*) vstart
;
12255 ent
.vn_version
= BYTE_GET (entry
->vn_version
);
12256 ent
.vn_cnt
= BYTE_GET (entry
->vn_cnt
);
12257 ent
.vn_file
= BYTE_GET (entry
->vn_file
);
12258 ent
.vn_aux
= BYTE_GET (entry
->vn_aux
);
12259 ent
.vn_next
= BYTE_GET (entry
->vn_next
);
12261 printf (_(" %#06lx: Version: %d"), idx
, ent
.vn_version
);
12263 if (valid_dynamic_name (filedata
, ent
.vn_file
))
12264 printf (_(" File: %s"),
12265 get_dynamic_name (filedata
, ent
.vn_file
));
12267 printf (_(" File: %lx"), ent
.vn_file
);
12269 printf (_(" Cnt: %d\n"), ent
.vn_cnt
);
12271 /* Check for overflow. */
12272 if (ent
.vn_aux
> (size_t) (endbuf
- vstart
))
12274 vstart
+= ent
.vn_aux
;
12276 for (j
= 0, isum
= idx
+ ent
.vn_aux
; j
< ent
.vn_cnt
; ++j
)
12278 Elf_External_Vernaux
* eaux
;
12279 Elf_Internal_Vernaux aux
;
12281 if (vstart
+ sizeof (*eaux
) > endbuf
)
12283 eaux
= (Elf_External_Vernaux
*) vstart
;
12285 aux
.vna_hash
= BYTE_GET (eaux
->vna_hash
);
12286 aux
.vna_flags
= BYTE_GET (eaux
->vna_flags
);
12287 aux
.vna_other
= BYTE_GET (eaux
->vna_other
);
12288 aux
.vna_name
= BYTE_GET (eaux
->vna_name
);
12289 aux
.vna_next
= BYTE_GET (eaux
->vna_next
);
12291 if (valid_dynamic_name (filedata
, aux
.vna_name
))
12292 printf (_(" %#06lx: Name: %s"),
12293 isum
, get_dynamic_name (filedata
, aux
.vna_name
));
12295 printf (_(" %#06lx: Name index: %lx"),
12296 isum
, aux
.vna_name
);
12298 printf (_(" Flags: %s Version: %d\n"),
12299 get_ver_flags (aux
.vna_flags
), aux
.vna_other
);
12301 if (aux
.vna_next
< sizeof (*eaux
)
12302 && !(j
== ent
.vn_cnt
- 1 && aux
.vna_next
== 0))
12304 warn (_("Invalid vna_next field of %lx\n"),
12309 /* Check for overflow. */
12310 if (aux
.vna_next
> (size_t) (endbuf
- vstart
))
12312 isum
+= aux
.vna_next
;
12313 vstart
+= aux
.vna_next
;
12316 if (j
< ent
.vn_cnt
)
12317 warn (_("Missing Version Needs auxiliary information\n"));
12319 if (ent
.vn_next
< sizeof (*entry
)
12320 && !(cnt
== section
->sh_info
- 1 && ent
.vn_next
== 0))
12322 warn (_("Invalid vn_next field of %lx\n"), ent
.vn_next
);
12323 cnt
= section
->sh_info
;
12326 if (ent
.vn_next
> (size_t) (endbuf
- ((char *) eneed
+ idx
)))
12328 idx
+= ent
.vn_next
;
12331 if (cnt
< section
->sh_info
)
12332 warn (_("Missing Version Needs information\n"));
12338 case SHT_GNU_versym
:
12340 Elf_Internal_Shdr
* link_section
;
12343 unsigned char * edata
;
12344 unsigned short * data
;
12346 Elf_Internal_Sym
* symbols
;
12347 Elf_Internal_Shdr
* string_sec
;
12348 unsigned long num_syms
;
12351 if (section
->sh_link
>= filedata
->file_header
.e_shnum
)
12354 link_section
= filedata
->section_headers
+ section
->sh_link
;
12355 total
= section
->sh_size
/ sizeof (Elf_External_Versym
);
12357 if (link_section
->sh_link
>= filedata
->file_header
.e_shnum
)
12362 symbols
= get_elf_symbols (filedata
, link_section
, & num_syms
);
12363 if (symbols
== NULL
)
12366 string_sec
= filedata
->section_headers
+ link_section
->sh_link
;
12368 strtab
= (char *) get_data (NULL
, filedata
, string_sec
->sh_offset
, 1,
12369 string_sec
->sh_size
,
12370 _("version string table"));
12377 if (filedata
->is_separate
)
12378 printf (ngettext ("\nIn linked file '%s' the version symbols section '%s' contains %lu entry:\n",
12379 "\nIn linked file '%s' the version symbols section '%s' contains %lu entries:\n",
12381 filedata
->file_name
,
12382 printable_section_name (filedata
, section
),
12383 (unsigned long) total
);
12385 printf (ngettext ("\nVersion symbols section '%s' "
12386 "contains %lu entry:\n",
12387 "\nVersion symbols section '%s' "
12388 "contains %lu entries:\n",
12390 printable_section_name (filedata
, section
),
12391 (unsigned long) total
);
12393 printf (_(" Addr: 0x"));
12394 printf_vma (section
->sh_addr
);
12395 printf (_(" Offset: %#08lx Link: %u (%s)\n"),
12396 (unsigned long) section
->sh_offset
, section
->sh_link
,
12397 printable_section_name (filedata
, link_section
));
12399 off
= offset_from_vma (filedata
,
12400 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)],
12401 total
* sizeof (short));
12402 edata
= (unsigned char *) get_data (NULL
, filedata
, off
,
12403 sizeof (short), total
,
12404 _("version symbol data"));
12412 data
= (short unsigned int *) cmalloc (total
, sizeof (short));
12414 for (cnt
= total
; cnt
--;)
12415 data
[cnt
] = byte_get (edata
+ cnt
* sizeof (short),
12420 for (cnt
= 0; cnt
< total
; cnt
+= 4)
12424 char *invalid
= _("*invalid*");
12426 printf (" %03x:", cnt
);
12428 for (j
= 0; (j
< 4) && (cnt
+ j
) < total
; ++j
)
12429 switch (data
[cnt
+ j
])
12432 fputs (_(" 0 (*local*) "), stdout
);
12436 fputs (_(" 1 (*global*) "), stdout
);
12440 nn
= printf ("%4x%c", data
[cnt
+ j
] & VERSYM_VERSION
,
12441 data
[cnt
+ j
] & VERSYM_HIDDEN
? 'h' : ' ');
12443 /* If this index value is greater than the size of the symbols
12444 array, break to avoid an out-of-bounds read. */
12445 if ((unsigned long)(cnt
+ j
) >= num_syms
)
12447 warn (_("invalid index into symbol array\n"));
12452 if (filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)])
12454 Elf_Internal_Verneed ivn
;
12455 unsigned long offset
;
12457 offset
= offset_from_vma
12459 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)],
12460 sizeof (Elf_External_Verneed
));
12464 Elf_Internal_Vernaux ivna
;
12465 Elf_External_Verneed evn
;
12466 Elf_External_Vernaux evna
;
12467 unsigned long a_off
;
12469 if (get_data (&evn
, filedata
, offset
, sizeof (evn
), 1,
12470 _("version need")) == NULL
)
12473 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
12474 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
12476 a_off
= offset
+ ivn
.vn_aux
;
12480 if (get_data (&evna
, filedata
, a_off
, sizeof (evna
),
12481 1, _("version need aux (2)")) == NULL
)
12484 ivna
.vna_other
= 0;
12488 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
12489 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
12492 a_off
+= ivna
.vna_next
;
12494 while (ivna
.vna_other
!= data
[cnt
+ j
]
12495 && ivna
.vna_next
!= 0);
12497 if (ivna
.vna_other
== data
[cnt
+ j
])
12499 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
12501 if (ivna
.vna_name
>= string_sec
->sh_size
)
12504 name
= strtab
+ ivna
.vna_name
;
12508 offset
+= ivn
.vn_next
;
12510 while (ivn
.vn_next
);
12513 if (data
[cnt
+ j
] != 0x8001
12514 && filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
12516 Elf_Internal_Verdef ivd
;
12517 Elf_External_Verdef evd
;
12518 unsigned long offset
;
12520 offset
= offset_from_vma
12522 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)],
12527 if (get_data (&evd
, filedata
, offset
, sizeof (evd
), 1,
12528 _("version def")) == NULL
)
12531 /* PR 17531: file: 046-1082287-0.004. */
12532 ivd
.vd_ndx
= (data
[cnt
+ j
] & VERSYM_VERSION
) + 1;
12537 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
12538 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
12541 offset
+= ivd
.vd_next
;
12543 while (ivd
.vd_ndx
!= (data
[cnt
+ j
] & VERSYM_VERSION
)
12544 && ivd
.vd_next
!= 0);
12546 if (ivd
.vd_ndx
== (data
[cnt
+ j
] & VERSYM_VERSION
))
12548 Elf_External_Verdaux evda
;
12549 Elf_Internal_Verdaux ivda
;
12551 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
12553 if (get_data (&evda
, filedata
,
12554 offset
- ivd
.vd_next
+ ivd
.vd_aux
,
12556 _("version def aux")) == NULL
)
12559 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
12561 if (ivda
.vda_name
>= string_sec
->sh_size
)
12563 else if (name
!= NULL
&& name
!= invalid
)
12564 name
= _("*both*");
12566 name
= strtab
+ ivda
.vda_name
;
12570 nn
+= printf ("(%s%-*s",
12572 12 - (int) strlen (name
),
12576 printf ("%*c", 18 - nn
, ' ');
12595 if (filedata
->is_separate
)
12596 printf (_("\nNo version information found in linked file '%s'.\n"),
12597 filedata
->file_name
);
12599 printf (_("\nNo version information found in this file.\n"));
12605 static const char *
12606 get_symbol_binding (Filedata
* filedata
, unsigned int binding
)
12608 static char buff
[64];
12612 case STB_LOCAL
: return "LOCAL";
12613 case STB_GLOBAL
: return "GLOBAL";
12614 case STB_WEAK
: return "WEAK";
12616 if (binding
>= STB_LOPROC
&& binding
<= STB_HIPROC
)
12617 snprintf (buff
, sizeof (buff
), _("<processor specific>: %d"),
12619 else if (binding
>= STB_LOOS
&& binding
<= STB_HIOS
)
12621 if (binding
== STB_GNU_UNIQUE
12622 && filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_GNU
)
12624 snprintf (buff
, sizeof (buff
), _("<OS specific>: %d"), binding
);
12627 snprintf (buff
, sizeof (buff
), _("<unknown>: %d"), binding
);
12632 static const char *
12633 get_symbol_type (Filedata
* filedata
, unsigned int type
)
12635 static char buff
[64];
12639 case STT_NOTYPE
: return "NOTYPE";
12640 case STT_OBJECT
: return "OBJECT";
12641 case STT_FUNC
: return "FUNC";
12642 case STT_SECTION
: return "SECTION";
12643 case STT_FILE
: return "FILE";
12644 case STT_COMMON
: return "COMMON";
12645 case STT_TLS
: return "TLS";
12646 case STT_RELC
: return "RELC";
12647 case STT_SRELC
: return "SRELC";
12649 if (type
>= STT_LOPROC
&& type
<= STT_HIPROC
)
12651 if (filedata
->file_header
.e_machine
== EM_ARM
&& type
== STT_ARM_TFUNC
)
12652 return "THUMB_FUNC";
12654 if (filedata
->file_header
.e_machine
== EM_SPARCV9
&& type
== STT_REGISTER
)
12657 if (filedata
->file_header
.e_machine
== EM_PARISC
&& type
== STT_PARISC_MILLI
)
12658 return "PARISC_MILLI";
12660 snprintf (buff
, sizeof (buff
), _("<processor specific>: %d"), type
);
12662 else if (type
>= STT_LOOS
&& type
<= STT_HIOS
)
12664 if (filedata
->file_header
.e_machine
== EM_PARISC
)
12666 if (type
== STT_HP_OPAQUE
)
12667 return "HP_OPAQUE";
12668 if (type
== STT_HP_STUB
)
12672 if (type
== STT_GNU_IFUNC
12673 && (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_GNU
12674 || filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_FREEBSD
))
12677 snprintf (buff
, sizeof (buff
), _("<OS specific>: %d"), type
);
12680 snprintf (buff
, sizeof (buff
), _("<unknown>: %d"), type
);
12685 static const char *
12686 get_symbol_visibility (unsigned int visibility
)
12688 switch (visibility
)
12690 case STV_DEFAULT
: return "DEFAULT";
12691 case STV_INTERNAL
: return "INTERNAL";
12692 case STV_HIDDEN
: return "HIDDEN";
12693 case STV_PROTECTED
: return "PROTECTED";
12695 error (_("Unrecognized visibility value: %u\n"), visibility
);
12696 return _("<unknown>");
12700 static const char *
12701 get_alpha_symbol_other (unsigned int other
)
12705 case STO_ALPHA_NOPV
: return "NOPV";
12706 case STO_ALPHA_STD_GPLOAD
: return "STD GPLOAD";
12708 error (_("Unrecognized alpha specific other value: %u\n"), other
);
12709 return _("<unknown>");
12713 static const char *
12714 get_solaris_symbol_visibility (unsigned int visibility
)
12716 switch (visibility
)
12718 case 4: return "EXPORTED";
12719 case 5: return "SINGLETON";
12720 case 6: return "ELIMINATE";
12721 default: return get_symbol_visibility (visibility
);
12725 static const char *
12726 get_aarch64_symbol_other (unsigned int other
)
12728 static char buf
[32];
12730 if (other
& STO_AARCH64_VARIANT_PCS
)
12732 other
&= ~STO_AARCH64_VARIANT_PCS
;
12734 return "VARIANT_PCS";
12735 snprintf (buf
, sizeof buf
, "VARIANT_PCS | %x", other
);
12741 static const char *
12742 get_mips_symbol_other (unsigned int other
)
12746 case STO_OPTIONAL
: return "OPTIONAL";
12747 case STO_MIPS_PLT
: return "MIPS PLT";
12748 case STO_MIPS_PIC
: return "MIPS PIC";
12749 case STO_MICROMIPS
: return "MICROMIPS";
12750 case STO_MICROMIPS
| STO_MIPS_PIC
: return "MICROMIPS, MIPS PIC";
12751 case STO_MIPS16
: return "MIPS16";
12752 default: return NULL
;
12756 static const char *
12757 get_ia64_symbol_other (Filedata
* filedata
, unsigned int other
)
12759 if (is_ia64_vms (filedata
))
12761 static char res
[32];
12765 /* Function types is for images and .STB files only. */
12766 switch (filedata
->file_header
.e_type
)
12770 switch (VMS_ST_FUNC_TYPE (other
))
12772 case VMS_SFT_CODE_ADDR
:
12773 strcat (res
, " CA");
12775 case VMS_SFT_SYMV_IDX
:
12776 strcat (res
, " VEC");
12779 strcat (res
, " FD");
12781 case VMS_SFT_RESERVE
:
12782 strcat (res
, " RSV");
12785 warn (_("Unrecognized IA64 VMS ST Function type: %d\n"),
12786 VMS_ST_FUNC_TYPE (other
));
12787 strcat (res
, " <unknown>");
12794 switch (VMS_ST_LINKAGE (other
))
12796 case VMS_STL_IGNORE
:
12797 strcat (res
, " IGN");
12799 case VMS_STL_RESERVE
:
12800 strcat (res
, " RSV");
12803 strcat (res
, " STD");
12806 strcat (res
, " LNK");
12809 warn (_("Unrecognized IA64 VMS ST Linkage: %d\n"),
12810 VMS_ST_LINKAGE (other
));
12811 strcat (res
, " <unknown>");
12823 static const char *
12824 get_ppc64_symbol_other (unsigned int other
)
12826 if ((other
& ~STO_PPC64_LOCAL_MASK
) != 0)
12829 other
>>= STO_PPC64_LOCAL_BIT
;
12832 static char buf
[64];
12834 other
= ppc64_decode_local_entry (other
);
12835 snprintf (buf
, sizeof buf
, _("<localentry>: %d"), other
);
12841 static const char *
12842 get_riscv_symbol_other (unsigned int other
)
12844 static char buf
[32];
12847 if (other
& STO_RISCV_VARIANT_CC
)
12849 strcat (buf
, _(" VARIANT_CC"));
12850 other
&= ~STO_RISCV_VARIANT_CC
;
12854 snprintf (buf
, sizeof buf
, " %x", other
);
12863 static const char *
12864 get_symbol_other (Filedata
* filedata
, unsigned int other
)
12866 const char * result
= NULL
;
12867 static char buff
[64];
12872 switch (filedata
->file_header
.e_machine
)
12875 result
= get_alpha_symbol_other (other
);
12878 result
= get_aarch64_symbol_other (other
);
12881 result
= get_mips_symbol_other (other
);
12884 result
= get_ia64_symbol_other (filedata
, other
);
12887 result
= get_ppc64_symbol_other (other
);
12890 result
= get_riscv_symbol_other (other
);
12900 snprintf (buff
, sizeof buff
, _("<other>: %x"), other
);
12904 static const char *
12905 get_symbol_index_type (Filedata
* filedata
, unsigned int type
)
12907 static char buff
[32];
12911 case SHN_UNDEF
: return "UND";
12912 case SHN_ABS
: return "ABS";
12913 case SHN_COMMON
: return "COM";
12915 if (type
== SHN_IA_64_ANSI_COMMON
12916 && filedata
->file_header
.e_machine
== EM_IA_64
12917 && filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_HPUX
)
12919 else if ((filedata
->file_header
.e_machine
== EM_X86_64
12920 || filedata
->file_header
.e_machine
== EM_L1OM
12921 || filedata
->file_header
.e_machine
== EM_K1OM
)
12922 && type
== SHN_X86_64_LCOMMON
)
12923 return "LARGE_COM";
12924 else if ((type
== SHN_MIPS_SCOMMON
12925 && filedata
->file_header
.e_machine
== EM_MIPS
)
12926 || (type
== SHN_TIC6X_SCOMMON
12927 && filedata
->file_header
.e_machine
== EM_TI_C6000
))
12929 else if (type
== SHN_MIPS_SUNDEFINED
12930 && filedata
->file_header
.e_machine
== EM_MIPS
)
12932 else if (type
>= SHN_LOPROC
&& type
<= SHN_HIPROC
)
12933 sprintf (buff
, "PRC[0x%04x]", type
& 0xffff);
12934 else if (type
>= SHN_LOOS
&& type
<= SHN_HIOS
)
12935 sprintf (buff
, "OS [0x%04x]", type
& 0xffff);
12936 else if (type
>= SHN_LORESERVE
)
12937 sprintf (buff
, "RSV[0x%04x]", type
& 0xffff);
12938 else if (filedata
->file_header
.e_shnum
!= 0
12939 && type
>= filedata
->file_header
.e_shnum
)
12940 sprintf (buff
, _("bad section index[%3d]"), type
);
12942 sprintf (buff
, "%3d", type
);
12949 static const char *
12950 get_symbol_version_string (Filedata
* filedata
,
12952 const char * strtab
,
12953 unsigned long int strtab_size
,
12955 Elf_Internal_Sym
* psym
,
12956 enum versioned_symbol_info
* sym_info
,
12957 unsigned short * vna_other
)
12959 unsigned char data
[2];
12960 unsigned short vers_data
;
12961 unsigned long offset
;
12962 unsigned short max_vd_ndx
;
12965 || filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)] == 0)
12968 offset
= offset_from_vma (filedata
,
12969 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)],
12970 sizeof data
+ si
* sizeof (vers_data
));
12972 if (get_data (&data
, filedata
, offset
+ si
* sizeof (vers_data
),
12973 sizeof (data
), 1, _("version data")) == NULL
)
12976 vers_data
= byte_get (data
, 2);
12978 if ((vers_data
& VERSYM_HIDDEN
) == 0 && vers_data
== 0)
12981 *sym_info
= (vers_data
& VERSYM_HIDDEN
) != 0 ? symbol_hidden
: symbol_public
;
12984 /* Usually we'd only see verdef for defined symbols, and verneed for
12985 undefined symbols. However, symbols defined by the linker in
12986 .dynbss for variables copied from a shared library in order to
12987 avoid text relocations are defined yet have verneed. We could
12988 use a heuristic to detect the special case, for example, check
12989 for verneed first on symbols defined in SHT_NOBITS sections, but
12990 it is simpler and more reliable to just look for both verdef and
12991 verneed. .dynbss might not be mapped to a SHT_NOBITS section. */
12993 if (psym
->st_shndx
!= SHN_UNDEF
12994 && vers_data
!= 0x8001
12995 && filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
12997 Elf_Internal_Verdef ivd
;
12998 Elf_Internal_Verdaux ivda
;
12999 Elf_External_Verdaux evda
;
13002 off
= offset_from_vma (filedata
,
13003 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)],
13004 sizeof (Elf_External_Verdef
));
13008 Elf_External_Verdef evd
;
13010 if (get_data (&evd
, filedata
, off
, sizeof (evd
), 1,
13011 _("version def")) == NULL
)
13020 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
13021 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
13022 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
13023 ivd
.vd_flags
= BYTE_GET (evd
.vd_flags
);
13026 if ((ivd
.vd_ndx
& VERSYM_VERSION
) > max_vd_ndx
)
13027 max_vd_ndx
= ivd
.vd_ndx
& VERSYM_VERSION
;
13029 off
+= ivd
.vd_next
;
13031 while (ivd
.vd_ndx
!= (vers_data
& VERSYM_VERSION
) && ivd
.vd_next
!= 0);
13033 if (ivd
.vd_ndx
== (vers_data
& VERSYM_VERSION
))
13035 if (ivd
.vd_ndx
== 1 && ivd
.vd_flags
== VER_FLG_BASE
)
13038 off
-= ivd
.vd_next
;
13041 if (get_data (&evda
, filedata
, off
, sizeof (evda
), 1,
13042 _("version def aux")) != NULL
)
13044 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
13046 if (psym
->st_name
!= ivda
.vda_name
)
13047 return (ivda
.vda_name
< strtab_size
13048 ? strtab
+ ivda
.vda_name
: _("<corrupt>"));
13053 if (filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)])
13055 Elf_External_Verneed evn
;
13056 Elf_Internal_Verneed ivn
;
13057 Elf_Internal_Vernaux ivna
;
13059 offset
= offset_from_vma (filedata
,
13060 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)],
13064 unsigned long vna_off
;
13066 if (get_data (&evn
, filedata
, offset
, sizeof (evn
), 1,
13067 _("version need")) == NULL
)
13070 ivna
.vna_other
= 0;
13075 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
13076 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
13078 vna_off
= offset
+ ivn
.vn_aux
;
13082 Elf_External_Vernaux evna
;
13084 if (get_data (&evna
, filedata
, vna_off
, sizeof (evna
), 1,
13085 _("version need aux (3)")) == NULL
)
13088 ivna
.vna_other
= 0;
13093 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
13094 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
13095 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
13098 vna_off
+= ivna
.vna_next
;
13100 while (ivna
.vna_other
!= vers_data
&& ivna
.vna_next
!= 0);
13102 if (ivna
.vna_other
== vers_data
)
13105 offset
+= ivn
.vn_next
;
13107 while (ivn
.vn_next
!= 0);
13109 if (ivna
.vna_other
== vers_data
)
13111 *sym_info
= symbol_undefined
;
13112 *vna_other
= ivna
.vna_other
;
13113 return (ivna
.vna_name
< strtab_size
13114 ? strtab
+ ivna
.vna_name
: _("<corrupt>"));
13116 else if ((max_vd_ndx
|| (vers_data
& VERSYM_VERSION
) != 1)
13117 && (vers_data
& VERSYM_VERSION
) > max_vd_ndx
)
13118 return _("<corrupt>");
13123 /* Display a symbol size on stdout. Format is based on --sym-base setting. */
13125 static unsigned int
13126 print_dynamic_symbol_size (bfd_vma vma
, int base
)
13131 return print_vma (vma
, OCTAL_5
);
13134 return print_vma (vma
, UNSIGNED_5
);
13137 return print_vma (vma
, PREFIX_HEX_5
);
13141 return print_vma (vma
, DEC_5
);
13146 print_dynamic_symbol (Filedata
*filedata
, unsigned long si
,
13147 Elf_Internal_Sym
*symtab
,
13148 Elf_Internal_Shdr
*section
,
13149 char *strtab
, size_t strtab_size
)
13151 const char *version_string
;
13152 enum versioned_symbol_info sym_info
;
13153 unsigned short vna_other
;
13156 Elf_Internal_Sym
*psym
= symtab
+ si
;
13158 printf ("%6ld: ", si
);
13159 print_vma (psym
->st_value
, LONG_HEX
);
13161 print_dynamic_symbol_size (psym
->st_size
, sym_base
);
13162 printf (" %-7s", get_symbol_type (filedata
, ELF_ST_TYPE (psym
->st_info
)));
13163 printf (" %-6s", get_symbol_binding (filedata
, ELF_ST_BIND (psym
->st_info
)));
13164 if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_SOLARIS
)
13165 printf (" %-7s", get_solaris_symbol_visibility (psym
->st_other
));
13168 unsigned int vis
= ELF_ST_VISIBILITY (psym
->st_other
);
13170 printf (" %-7s", get_symbol_visibility (vis
));
13171 /* Check to see if any other bits in the st_other field are set.
13172 Note - displaying this information disrupts the layout of the
13173 table being generated, but for the moment this case is very rare. */
13174 if (psym
->st_other
^ vis
)
13175 printf (" [%s] ", get_symbol_other (filedata
, psym
->st_other
^ vis
));
13177 printf (" %4s ", get_symbol_index_type (filedata
, psym
->st_shndx
));
13179 if (ELF_ST_TYPE (psym
->st_info
) == STT_SECTION
13180 && psym
->st_shndx
< filedata
->file_header
.e_shnum
13181 && filedata
->section_headers
!= NULL
13182 && psym
->st_name
== 0)
13185 = section_name_valid (filedata
,
13186 filedata
->section_headers
+ psym
->st_shndx
);
13188 section_name_print (filedata
,
13189 filedata
->section_headers
+ psym
->st_shndx
)
13194 is_valid
= valid_symbol_name (strtab
, strtab_size
, psym
->st_name
);
13195 sstr
= is_valid
? strtab
+ psym
->st_name
: _("<corrupt>");
13199 = get_symbol_version_string (filedata
,
13201 || section
->sh_type
== SHT_DYNSYM
),
13202 strtab
, strtab_size
, si
,
13203 psym
, &sym_info
, &vna_other
);
13205 int len_avail
= 21;
13206 if (! do_wide
&& version_string
!= NULL
)
13210 len_avail
-= 1 + strlen (version_string
);
13212 if (sym_info
== symbol_undefined
)
13213 len_avail
-= sprintf (buffer
," (%d)", vna_other
);
13214 else if (sym_info
!= symbol_hidden
)
13218 print_symbol (len_avail
, sstr
);
13220 if (version_string
)
13222 if (sym_info
== symbol_undefined
)
13223 printf ("@%s (%d)", version_string
, vna_other
);
13225 printf (sym_info
== symbol_hidden
? "@%s" : "@@%s",
13231 if (ELF_ST_BIND (psym
->st_info
) == STB_LOCAL
13233 && si
>= section
->sh_info
13234 /* Irix 5 and 6 MIPS binaries are known to ignore this requirement. */
13235 && filedata
->file_header
.e_machine
!= EM_MIPS
13236 /* Solaris binaries have been found to violate this requirement as
13237 well. Not sure if this is a bug or an ABI requirement. */
13238 && filedata
->file_header
.e_ident
[EI_OSABI
] != ELFOSABI_SOLARIS
)
13239 warn (_("local symbol %lu found at index >= %s's sh_info value of %u\n"),
13240 si
, printable_section_name (filedata
, section
), section
->sh_info
);
13243 static const char *
13244 get_lto_kind (unsigned int kind
)
13248 case 0: return "DEF";
13249 case 1: return "WEAKDEF";
13250 case 2: return "UNDEF";
13251 case 3: return "WEAKUNDEF";
13252 case 4: return "COMMON";
13257 static char buffer
[30];
13258 error (_("Unknown LTO symbol definition encountered: %u\n"), kind
);
13259 sprintf (buffer
, "<unknown: %u>", kind
);
13263 static const char *
13264 get_lto_visibility (unsigned int visibility
)
13266 switch (visibility
)
13268 case 0: return "DEFAULT";
13269 case 1: return "PROTECTED";
13270 case 2: return "INTERNAL";
13271 case 3: return "HIDDEN";
13276 static char buffer
[30];
13277 error (_("Unknown LTO symbol visibility encountered: %u\n"), visibility
);
13278 sprintf (buffer
, "<unknown: %u>", visibility
);
13282 static const char *
13283 get_lto_sym_type (unsigned int sym_type
)
13287 case 0: return "UNKNOWN";
13288 case 1: return "FUNCTION";
13289 case 2: return "VARIABLE";
13294 static char buffer
[30];
13295 error (_("Unknown LTO symbol type encountered: %u\n"), sym_type
);
13296 sprintf (buffer
, "<unknown: %u>", sym_type
);
13300 /* Display an LTO format symbol table.
13301 FIXME: The format of LTO symbol tables is not formalized.
13302 So this code could need changing in the future. */
13305 display_lto_symtab (Filedata
* filedata
,
13306 Elf_Internal_Shdr
* section
)
13308 if (section
->sh_size
== 0)
13310 if (filedata
->is_separate
)
13311 printf (_("\nThe LTO Symbol table section '%s' in linked file '%s' is empty!\n"),
13312 printable_section_name (filedata
, section
),
13313 filedata
->file_name
);
13315 printf (_("\nLTO Symbol table '%s' is empty!\n"),
13316 printable_section_name (filedata
, section
));
13321 if (section
->sh_size
> filedata
->file_size
)
13323 error (_("Section %s has an invalid sh_size of 0x%lx\n"),
13324 printable_section_name (filedata
, section
),
13325 (unsigned long) section
->sh_size
);
13329 void * alloced_data
= get_data (NULL
, filedata
, section
->sh_offset
,
13330 section
->sh_size
, 1, _("LTO symbols"));
13331 if (alloced_data
== NULL
)
13334 /* Look for extended data for the symbol table. */
13335 Elf_Internal_Shdr
* ext
;
13336 void * ext_data_orig
= NULL
;
13337 char * ext_data
= NULL
;
13338 char * ext_data_end
= NULL
;
13339 char * ext_name
= NULL
;
13341 if (asprintf (& ext_name
, ".gnu.lto_.ext_symtab.%s",
13342 (section_name (filedata
, section
)
13343 + sizeof (".gnu.lto_.symtab.") - 1)) > 0
13344 && ext_name
!= NULL
/* Paranoia. */
13345 && (ext
= find_section (filedata
, ext_name
)) != NULL
)
13347 if (ext
->sh_size
< 3)
13348 error (_("LTO Symbol extension table '%s' is empty!\n"),
13349 printable_section_name (filedata
, ext
));
13352 ext_data_orig
= ext_data
= get_data (NULL
, filedata
, ext
->sh_offset
,
13354 _("LTO ext symbol data"));
13355 if (ext_data
!= NULL
)
13357 ext_data_end
= ext_data
+ ext
->sh_size
;
13358 if (* ext_data
++ != 1)
13359 error (_("Unexpected version number in symbol extension table\n"));
13364 const unsigned char * data
= (const unsigned char *) alloced_data
;
13365 const unsigned char * end
= data
+ section
->sh_size
;
13367 if (filedata
->is_separate
)
13368 printf (_("\nIn linked file '%s': "), filedata
->file_name
);
13372 if (ext_data_orig
!= NULL
)
13375 printf (_("LTO Symbol table '%s' and extension table '%s' contain:\n"),
13376 printable_section_name (filedata
, section
),
13377 printable_section_name (filedata
, ext
));
13380 printf (_("LTO Symbol table '%s'\n"),
13381 printable_section_name (filedata
, section
));
13382 printf (_(" and extension table '%s' contain:\n"),
13383 printable_section_name (filedata
, ext
));
13387 printf (_("LTO Symbol table '%s' contains:\n"),
13388 printable_section_name (filedata
, section
));
13390 /* FIXME: Add a wide version. */
13391 if (ext_data_orig
!= NULL
)
13392 printf (_(" Comdat_Key Kind Visibility Size Slot Type Section Name\n"));
13394 printf (_(" Comdat_Key Kind Visibility Size Slot Name\n"));
13396 /* FIXME: We do not handle style prefixes. */
13400 const unsigned char * sym_name
= data
;
13401 data
+= strnlen ((const char *) sym_name
, end
- data
) + 1;
13405 const unsigned char * comdat_key
= data
;
13406 data
+= strnlen ((const char *) comdat_key
, end
- data
) + 1;
13410 if (data
+ 2 + 8 + 4 > end
)
13413 unsigned int kind
= *data
++;
13414 unsigned int visibility
= *data
++;
13416 elf_vma size
= byte_get (data
, 8);
13419 elf_vma slot
= byte_get (data
, 4);
13422 if (ext_data
!= NULL
)
13424 if (ext_data
< (ext_data_end
- 1))
13426 unsigned int sym_type
= * ext_data
++;
13427 unsigned int sec_kind
= * ext_data
++;
13429 printf (" %10s %10s %11s %08lx %08lx %9s %08lx _",
13430 * comdat_key
== 0 ? "-" : (char *) comdat_key
,
13431 get_lto_kind (kind
),
13432 get_lto_visibility (visibility
),
13435 get_lto_sym_type (sym_type
),
13437 print_symbol (6, (const char *) sym_name
);
13441 error (_("Ran out of LTO symbol extension data\n"));
13443 /* FIXME: return FAIL result ? */
13448 printf (" %10s %10s %11s %08lx %08lx _",
13449 * comdat_key
== 0 ? "-" : (char *) comdat_key
,
13450 get_lto_kind (kind
),
13451 get_lto_visibility (visibility
),
13454 print_symbol (21, (const char *) sym_name
);
13459 if (ext_data
!= NULL
&& ext_data
< ext_data_end
)
13461 error (_("Data remains in the LTO symbol extension table\n"));
13465 free (alloced_data
);
13466 free (ext_data_orig
);
13471 error (_("Buffer overrun encountered whilst decoding LTO symbol table\n"));
13472 free (alloced_data
);
13473 free (ext_data_orig
);
13478 /* Display LTO symbol tables. */
13481 process_lto_symbol_tables (Filedata
* filedata
)
13483 Elf_Internal_Shdr
* section
;
13490 if (filedata
->section_headers
== NULL
)
13493 for (i
= 0, section
= filedata
->section_headers
;
13494 i
< filedata
->file_header
.e_shnum
;
13496 if (section_name_valid (filedata
, section
)
13497 && startswith (section_name (filedata
, section
), ".gnu.lto_.symtab."))
13498 res
&= display_lto_symtab (filedata
, section
);
13503 /* Dump the symbol table. */
13506 process_symbol_table (Filedata
* filedata
)
13508 Elf_Internal_Shdr
* section
;
13510 if (!do_syms
&& !do_dyn_syms
&& !do_histogram
)
13513 if ((filedata
->dynamic_info
[DT_HASH
] || filedata
->dynamic_info_DT_GNU_HASH
)
13515 && do_using_dynamic
13516 && filedata
->dynamic_strings
!= NULL
13517 && filedata
->dynamic_symbols
!= NULL
)
13521 if (filedata
->is_separate
)
13523 printf (ngettext ("\nIn linked file '%s' the dynamic symbol table contains %lu entry:\n",
13524 "\nIn linked file '%s' the dynamic symbol table contains %lu entries:\n",
13525 filedata
->num_dynamic_syms
),
13526 filedata
->file_name
,
13527 filedata
->num_dynamic_syms
);
13531 printf (ngettext ("\nSymbol table for image contains %lu entry:\n",
13532 "\nSymbol table for image contains %lu entries:\n",
13533 filedata
->num_dynamic_syms
),
13534 filedata
->num_dynamic_syms
);
13537 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
13539 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
13541 for (si
= 0; si
< filedata
->num_dynamic_syms
; si
++)
13542 print_dynamic_symbol (filedata
, si
, filedata
->dynamic_symbols
, NULL
,
13543 filedata
->dynamic_strings
,
13544 filedata
->dynamic_strings_length
);
13546 else if ((do_dyn_syms
|| (do_syms
&& !do_using_dynamic
))
13547 && filedata
->section_headers
!= NULL
)
13551 for (i
= 0, section
= filedata
->section_headers
;
13552 i
< filedata
->file_header
.e_shnum
;
13555 char * strtab
= NULL
;
13556 unsigned long int strtab_size
= 0;
13557 Elf_Internal_Sym
* symtab
;
13558 unsigned long si
, num_syms
;
13560 if ((section
->sh_type
!= SHT_SYMTAB
13561 && section
->sh_type
!= SHT_DYNSYM
)
13563 && section
->sh_type
== SHT_SYMTAB
))
13566 if (section
->sh_entsize
== 0)
13568 printf (_("\nSymbol table '%s' has a sh_entsize of zero!\n"),
13569 printable_section_name (filedata
, section
));
13573 num_syms
= section
->sh_size
/ section
->sh_entsize
;
13575 if (filedata
->is_separate
)
13576 printf (ngettext ("\nIn linked file '%s' symbol section '%s' contains %lu entry:\n",
13577 "\nIn linked file '%s' symbol section '%s' contains %lu entries:\n",
13579 filedata
->file_name
,
13580 printable_section_name (filedata
, section
),
13583 printf (ngettext ("\nSymbol table '%s' contains %lu entry:\n",
13584 "\nSymbol table '%s' contains %lu entries:\n",
13586 printable_section_name (filedata
, section
),
13590 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
13592 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
13594 symtab
= get_elf_symbols (filedata
, section
, & num_syms
);
13595 if (symtab
== NULL
)
13598 if (section
->sh_link
== filedata
->file_header
.e_shstrndx
)
13600 strtab
= filedata
->string_table
;
13601 strtab_size
= filedata
->string_table_length
;
13603 else if (section
->sh_link
< filedata
->file_header
.e_shnum
)
13605 Elf_Internal_Shdr
* string_sec
;
13607 string_sec
= filedata
->section_headers
+ section
->sh_link
;
13609 strtab
= (char *) get_data (NULL
, filedata
, string_sec
->sh_offset
,
13610 1, string_sec
->sh_size
,
13611 _("string table"));
13612 strtab_size
= strtab
!= NULL
? string_sec
->sh_size
: 0;
13615 for (si
= 0; si
< num_syms
; si
++)
13616 print_dynamic_symbol (filedata
, si
, symtab
, section
,
13617 strtab
, strtab_size
);
13620 if (strtab
!= filedata
->string_table
)
13626 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
13628 if (do_histogram
&& filedata
->buckets
!= NULL
)
13630 unsigned long * lengths
;
13631 unsigned long * counts
;
13634 unsigned long maxlength
= 0;
13635 unsigned long nzero_counts
= 0;
13636 unsigned long nsyms
= 0;
13639 printf (ngettext ("\nHistogram for bucket list length "
13640 "(total of %lu bucket):\n",
13641 "\nHistogram for bucket list length "
13642 "(total of %lu buckets):\n",
13643 (unsigned long) filedata
->nbuckets
),
13644 (unsigned long) filedata
->nbuckets
);
13646 lengths
= (unsigned long *) calloc (filedata
->nbuckets
,
13647 sizeof (*lengths
));
13648 if (lengths
== NULL
)
13650 error (_("Out of memory allocating space for histogram buckets\n"));
13653 visited
= xcmalloc (filedata
->nchains
, 1);
13654 memset (visited
, 0, filedata
->nchains
);
13656 printf (_(" Length Number %% of total Coverage\n"));
13657 for (hn
= 0; hn
< filedata
->nbuckets
; ++hn
)
13659 for (si
= filedata
->buckets
[hn
]; si
> 0; si
= filedata
->chains
[si
])
13662 if (maxlength
< ++lengths
[hn
])
13664 if (si
>= filedata
->nchains
|| visited
[si
])
13666 error (_("histogram chain is corrupt\n"));
13674 counts
= (unsigned long *) calloc (maxlength
+ 1, sizeof (*counts
));
13675 if (counts
== NULL
)
13678 error (_("Out of memory allocating space for histogram counts\n"));
13682 for (hn
= 0; hn
< filedata
->nbuckets
; ++hn
)
13683 ++counts
[lengths
[hn
]];
13685 if (filedata
->nbuckets
> 0)
13688 printf (" 0 %-10lu (%5.1f%%)\n",
13689 counts
[0], (counts
[0] * 100.0) / filedata
->nbuckets
);
13690 for (i
= 1; i
<= maxlength
; ++i
)
13692 nzero_counts
+= counts
[i
] * i
;
13693 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
13694 i
, counts
[i
], (counts
[i
] * 100.0) / filedata
->nbuckets
,
13695 (nzero_counts
* 100.0) / nsyms
);
13703 free (filedata
->buckets
);
13704 filedata
->buckets
= NULL
;
13705 filedata
->nbuckets
= 0;
13706 free (filedata
->chains
);
13707 filedata
->chains
= NULL
;
13709 if (do_histogram
&& filedata
->gnubuckets
!= NULL
)
13711 unsigned long * lengths
;
13712 unsigned long * counts
;
13714 unsigned long maxlength
= 0;
13715 unsigned long nzero_counts
= 0;
13716 unsigned long nsyms
= 0;
13718 printf (ngettext ("\nHistogram for `%s' bucket list length "
13719 "(total of %lu bucket):\n",
13720 "\nHistogram for `%s' bucket list length "
13721 "(total of %lu buckets):\n",
13722 (unsigned long) filedata
->ngnubuckets
),
13723 GNU_HASH_SECTION_NAME (filedata
),
13724 (unsigned long) filedata
->ngnubuckets
);
13726 lengths
= (unsigned long *) calloc (filedata
->ngnubuckets
,
13727 sizeof (*lengths
));
13728 if (lengths
== NULL
)
13730 error (_("Out of memory allocating space for gnu histogram buckets\n"));
13734 printf (_(" Length Number %% of total Coverage\n"));
13736 for (hn
= 0; hn
< filedata
->ngnubuckets
; ++hn
)
13737 if (filedata
->gnubuckets
[hn
] != 0)
13739 bfd_vma off
, length
= 1;
13741 for (off
= filedata
->gnubuckets
[hn
] - filedata
->gnusymidx
;
13742 /* PR 17531 file: 010-77222-0.004. */
13743 off
< filedata
->ngnuchains
13744 && (filedata
->gnuchains
[off
] & 1) == 0;
13747 lengths
[hn
] = length
;
13748 if (length
> maxlength
)
13749 maxlength
= length
;
13753 counts
= (unsigned long *) calloc (maxlength
+ 1, sizeof (*counts
));
13754 if (counts
== NULL
)
13757 error (_("Out of memory allocating space for gnu histogram counts\n"));
13761 for (hn
= 0; hn
< filedata
->ngnubuckets
; ++hn
)
13762 ++counts
[lengths
[hn
]];
13764 if (filedata
->ngnubuckets
> 0)
13767 printf (" 0 %-10lu (%5.1f%%)\n",
13768 counts
[0], (counts
[0] * 100.0) / filedata
->ngnubuckets
);
13769 for (j
= 1; j
<= maxlength
; ++j
)
13771 nzero_counts
+= counts
[j
] * j
;
13772 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
13773 j
, counts
[j
], (counts
[j
] * 100.0) / filedata
->ngnubuckets
,
13774 (nzero_counts
* 100.0) / nsyms
);
13781 free (filedata
->gnubuckets
);
13782 filedata
->gnubuckets
= NULL
;
13783 filedata
->ngnubuckets
= 0;
13784 free (filedata
->gnuchains
);
13785 filedata
->gnuchains
= NULL
;
13786 filedata
->ngnuchains
= 0;
13787 free (filedata
->mipsxlat
);
13788 filedata
->mipsxlat
= NULL
;
13792 free (filedata
->gnubuckets
);
13793 filedata
->gnubuckets
= NULL
;
13794 filedata
->ngnubuckets
= 0;
13795 free (filedata
->gnuchains
);
13796 filedata
->gnuchains
= NULL
;
13797 filedata
->ngnuchains
= 0;
13798 free (filedata
->mipsxlat
);
13799 filedata
->mipsxlat
= NULL
;
13800 free (filedata
->buckets
);
13801 filedata
->buckets
= NULL
;
13802 filedata
->nbuckets
= 0;
13803 free (filedata
->chains
);
13804 filedata
->chains
= NULL
;
13809 process_syminfo (Filedata
* filedata
)
13813 if (filedata
->dynamic_syminfo
== NULL
13815 /* No syminfo, this is ok. */
13818 /* There better should be a dynamic symbol section. */
13819 if (filedata
->dynamic_symbols
== NULL
|| filedata
->dynamic_strings
== NULL
)
13822 if (filedata
->is_separate
)
13823 printf (ngettext ("\nIn linked file '%s: the dynamic info segment at offset 0x%lx contains %d entry:\n",
13824 "\nIn linked file '%s: the dynamic info segment at offset 0x%lx contains %d entries:\n",
13825 filedata
->dynamic_syminfo_nent
),
13826 filedata
->file_name
,
13827 filedata
->dynamic_syminfo_offset
,
13828 filedata
->dynamic_syminfo_nent
);
13830 printf (ngettext ("\nDynamic info segment at offset 0x%lx "
13831 "contains %d entry:\n",
13832 "\nDynamic info segment at offset 0x%lx "
13833 "contains %d entries:\n",
13834 filedata
->dynamic_syminfo_nent
),
13835 filedata
->dynamic_syminfo_offset
,
13836 filedata
->dynamic_syminfo_nent
);
13838 printf (_(" Num: Name BoundTo Flags\n"));
13839 for (i
= 0; i
< filedata
->dynamic_syminfo_nent
; ++i
)
13841 unsigned short int flags
= filedata
->dynamic_syminfo
[i
].si_flags
;
13843 printf ("%4d: ", i
);
13844 if (i
>= filedata
->num_dynamic_syms
)
13845 printf (_("<corrupt index>"));
13846 else if (valid_dynamic_name (filedata
, filedata
->dynamic_symbols
[i
].st_name
))
13847 print_symbol (30, get_dynamic_name (filedata
,
13848 filedata
->dynamic_symbols
[i
].st_name
));
13850 printf (_("<corrupt: %19ld>"), filedata
->dynamic_symbols
[i
].st_name
);
13853 switch (filedata
->dynamic_syminfo
[i
].si_boundto
)
13855 case SYMINFO_BT_SELF
:
13856 fputs ("SELF ", stdout
);
13858 case SYMINFO_BT_PARENT
:
13859 fputs ("PARENT ", stdout
);
13862 if (filedata
->dynamic_syminfo
[i
].si_boundto
> 0
13863 && filedata
->dynamic_syminfo
[i
].si_boundto
< filedata
->dynamic_nent
13864 && valid_dynamic_name (filedata
,
13865 filedata
->dynamic_section
[filedata
->dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
))
13867 print_symbol (10, get_dynamic_name (filedata
,
13868 filedata
->dynamic_section
[filedata
->dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
));
13872 printf ("%-10d ", filedata
->dynamic_syminfo
[i
].si_boundto
);
13876 if (flags
& SYMINFO_FLG_DIRECT
)
13877 printf (" DIRECT");
13878 if (flags
& SYMINFO_FLG_PASSTHRU
)
13879 printf (" PASSTHRU");
13880 if (flags
& SYMINFO_FLG_COPY
)
13882 if (flags
& SYMINFO_FLG_LAZYLOAD
)
13883 printf (" LAZYLOAD");
13891 /* A macro which evaluates to TRUE if the region ADDR .. ADDR + NELEM
13892 is contained by the region START .. END. The types of ADDR, START
13893 and END should all be the same. Note both ADDR + NELEM and END
13894 point to just beyond the end of the regions that are being tested. */
13895 #define IN_RANGE(START,END,ADDR,NELEM) \
13896 (((ADDR) >= (START)) && ((ADDR) < (END)) && ((ADDR) + (NELEM) <= (END)))
13898 /* Check to see if the given reloc needs to be handled in a target specific
13899 manner. If so then process the reloc and return TRUE otherwise return
13902 If called with reloc == NULL, then this is a signal that reloc processing
13903 for the current section has finished, and any saved state should be
13907 target_specific_reloc_handling (Filedata
* filedata
,
13908 Elf_Internal_Rela
* reloc
,
13909 unsigned char * start
,
13910 unsigned char * end
,
13911 Elf_Internal_Sym
* symtab
,
13912 unsigned long num_syms
)
13914 unsigned int reloc_type
= 0;
13915 unsigned long sym_index
= 0;
13919 reloc_type
= get_reloc_type (filedata
, reloc
->r_info
);
13920 sym_index
= get_reloc_symindex (reloc
->r_info
);
13923 switch (filedata
->file_header
.e_machine
)
13926 case EM_MSP430_OLD
:
13928 static Elf_Internal_Sym
* saved_sym
= NULL
;
13936 switch (reloc_type
)
13938 case 10: /* R_MSP430_SYM_DIFF */
13939 case 12: /* R_MSP430_GNU_SUB_ULEB128 */
13940 if (uses_msp430x_relocs (filedata
))
13942 /* Fall through. */
13943 case 21: /* R_MSP430X_SYM_DIFF */
13944 case 23: /* R_MSP430X_GNU_SUB_ULEB128 */
13946 if (sym_index
>= num_syms
)
13947 error (_("MSP430 SYM_DIFF reloc contains invalid symbol index %lu\n"),
13950 saved_sym
= symtab
+ sym_index
;
13953 case 1: /* R_MSP430_32 or R_MSP430_ABS32 */
13954 case 3: /* R_MSP430_16 or R_MSP430_ABS8 */
13955 goto handle_sym_diff
;
13957 case 5: /* R_MSP430_16_BYTE */
13958 case 9: /* R_MSP430_8 */
13959 case 11: /* R_MSP430_GNU_SET_ULEB128 */
13960 if (uses_msp430x_relocs (filedata
))
13962 goto handle_sym_diff
;
13964 case 2: /* R_MSP430_ABS16 */
13965 case 15: /* R_MSP430X_ABS16 */
13966 case 22: /* R_MSP430X_GNU_SET_ULEB128 */
13967 if (! uses_msp430x_relocs (filedata
))
13969 goto handle_sym_diff
;
13972 if (saved_sym
!= NULL
)
13975 unsigned int reloc_size
= 0;
13977 switch (reloc_type
)
13979 case 1: /* R_MSP430_32 or R_MSP430_ABS32 */
13982 case 11: /* R_MSP430_GNU_SET_ULEB128 */
13983 case 22: /* R_MSP430X_GNU_SET_ULEB128 */
13984 if (reloc
->r_offset
< (size_t) (end
- start
))
13985 read_leb128 (start
+ reloc
->r_offset
, end
, false,
13986 &reloc_size
, &leb_ret
);
13993 if (leb_ret
!= 0 || reloc_size
== 0 || reloc_size
> 8)
13994 error (_("MSP430 ULEB128 field at 0x%lx contains invalid "
13995 "ULEB128 value\n"),
13996 (long) reloc
->r_offset
);
13997 else if (sym_index
>= num_syms
)
13998 error (_("MSP430 reloc contains invalid symbol index %lu\n"),
14002 value
= reloc
->r_addend
+ (symtab
[sym_index
].st_value
14003 - saved_sym
->st_value
);
14005 if (IN_RANGE (start
, end
, start
+ reloc
->r_offset
, reloc_size
))
14006 byte_put (start
+ reloc
->r_offset
, value
, reloc_size
);
14009 error (_("MSP430 sym diff reloc contains invalid offset: 0x%lx\n"),
14010 (long) reloc
->r_offset
);
14019 if (saved_sym
!= NULL
)
14020 error (_("Unhandled MSP430 reloc type found after SYM_DIFF reloc\n"));
14027 case EM_CYGNUS_MN10300
:
14029 static Elf_Internal_Sym
* saved_sym
= NULL
;
14037 switch (reloc_type
)
14039 case 34: /* R_MN10300_ALIGN */
14041 case 33: /* R_MN10300_SYM_DIFF */
14042 if (sym_index
>= num_syms
)
14043 error (_("MN10300_SYM_DIFF reloc contains invalid symbol index %lu\n"),
14046 saved_sym
= symtab
+ sym_index
;
14049 case 1: /* R_MN10300_32 */
14050 case 2: /* R_MN10300_16 */
14051 if (saved_sym
!= NULL
)
14053 int reloc_size
= reloc_type
== 1 ? 4 : 2;
14056 if (sym_index
>= num_syms
)
14057 error (_("MN10300 reloc contains invalid symbol index %lu\n"),
14061 value
= reloc
->r_addend
+ (symtab
[sym_index
].st_value
14062 - saved_sym
->st_value
);
14064 if (IN_RANGE (start
, end
, start
+ reloc
->r_offset
, reloc_size
))
14065 byte_put (start
+ reloc
->r_offset
, value
, reloc_size
);
14067 error (_("MN10300 sym diff reloc contains invalid offset: 0x%lx\n"),
14068 (long) reloc
->r_offset
);
14076 if (saved_sym
!= NULL
)
14077 error (_("Unhandled MN10300 reloc type found after SYM_DIFF reloc\n"));
14085 static bfd_vma saved_sym1
= 0;
14086 static bfd_vma saved_sym2
= 0;
14087 static bfd_vma value
;
14091 saved_sym1
= saved_sym2
= 0;
14095 switch (reloc_type
)
14097 case 0x80: /* R_RL78_SYM. */
14098 saved_sym1
= saved_sym2
;
14099 if (sym_index
>= num_syms
)
14100 error (_("RL78_SYM reloc contains invalid symbol index %lu\n"),
14104 saved_sym2
= symtab
[sym_index
].st_value
;
14105 saved_sym2
+= reloc
->r_addend
;
14109 case 0x83: /* R_RL78_OPsub. */
14110 value
= saved_sym1
- saved_sym2
;
14111 saved_sym2
= saved_sym1
= 0;
14115 case 0x41: /* R_RL78_ABS32. */
14116 if (IN_RANGE (start
, end
, start
+ reloc
->r_offset
, 4))
14117 byte_put (start
+ reloc
->r_offset
, value
, 4);
14119 error (_("RL78 sym diff reloc contains invalid offset: 0x%lx\n"),
14120 (long) reloc
->r_offset
);
14124 case 0x43: /* R_RL78_ABS16. */
14125 if (IN_RANGE (start
, end
, start
+ reloc
->r_offset
, 2))
14126 byte_put (start
+ reloc
->r_offset
, value
, 2);
14128 error (_("RL78 sym diff reloc contains invalid offset: 0x%lx\n"),
14129 (long) reloc
->r_offset
);
14143 /* Returns TRUE iff RELOC_TYPE is a 32-bit absolute RELA relocation used in
14144 DWARF debug sections. This is a target specific test. Note - we do not
14145 go through the whole including-target-headers-multiple-times route, (as
14146 we have already done with <elf/h8.h>) because this would become very
14147 messy and even then this function would have to contain target specific
14148 information (the names of the relocs instead of their numeric values).
14149 FIXME: This is not the correct way to solve this problem. The proper way
14150 is to have target specific reloc sizing and typing functions created by
14151 the reloc-macros.h header, in the same way that it already creates the
14152 reloc naming functions. */
14155 is_32bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14157 /* Please keep this table alpha-sorted for ease of visual lookup. */
14158 switch (filedata
->file_header
.e_machine
)
14162 return reloc_type
== 1; /* R_386_32. */
14164 return reloc_type
== 1; /* R_68K_32. */
14166 return reloc_type
== 1; /* R_860_32. */
14168 return reloc_type
== 2; /* R_960_32. */
14170 return (reloc_type
== 258
14171 || reloc_type
== 1); /* R_AARCH64_ABS32 || R_AARCH64_P32_ABS32 */
14173 return reloc_type
== 11; /* R_BPF_DATA_32 */
14174 case EM_ADAPTEVA_EPIPHANY
:
14175 return reloc_type
== 3;
14177 return reloc_type
== 1; /* R_ALPHA_REFLONG. */
14179 return reloc_type
== 1; /* R_ARC_32. */
14180 case EM_ARC_COMPACT
:
14181 case EM_ARC_COMPACT2
:
14182 return reloc_type
== 4; /* R_ARC_32. */
14184 return reloc_type
== 2; /* R_ARM_ABS32 */
14187 return reloc_type
== 1;
14189 return reloc_type
== 0x12; /* R_byte4_data. */
14191 return reloc_type
== 3; /* R_CRIS_32. */
14193 return reloc_type
== 3; /* R_CR16_NUM32. */
14195 return reloc_type
== 15; /* R_CRX_NUM32. */
14197 return reloc_type
== 1; /* R_CKCORE_ADDR32. */
14198 case EM_CYGNUS_FRV
:
14199 return reloc_type
== 1;
14200 case EM_CYGNUS_D10V
:
14202 return reloc_type
== 6; /* R_D10V_32. */
14203 case EM_CYGNUS_D30V
:
14205 return reloc_type
== 12; /* R_D30V_32_NORMAL. */
14207 return reloc_type
== 3; /* R_DLX_RELOC_32. */
14208 case EM_CYGNUS_FR30
:
14210 return reloc_type
== 3; /* R_FR30_32. */
14212 return reloc_type
== 1; /* R_FT32_32. */
14216 return reloc_type
== 1; /* R_H8_DIR32. */
14218 return (reloc_type
== 0x64 /* R_IA64_SECREL32MSB. */
14219 || reloc_type
== 0x65 /* R_IA64_SECREL32LSB. */
14220 || reloc_type
== 0x24 /* R_IA64_DIR32MSB. */
14221 || reloc_type
== 0x25 /* R_IA64_DIR32LSB. */);
14224 return reloc_type
== 2; /* R_IP2K_32. */
14226 return reloc_type
== 2; /* R_IQ2000_32. */
14227 case EM_LATTICEMICO32
:
14228 return reloc_type
== 3; /* R_LM32_32. */
14230 return reloc_type
== 1; /* R_LARCH_32. */
14233 return reloc_type
== 3; /* R_M32C_32. */
14235 return reloc_type
== 34; /* R_M32R_32_RELA. */
14238 return reloc_type
== 6; /* R_M68HC11_32. */
14240 return reloc_type
== 7 || /* R_S12Z_EXT32 */
14241 reloc_type
== 6; /* R_S12Z_CW32. */
14243 return reloc_type
== 1; /* R_MCORE_ADDR32. */
14244 case EM_CYGNUS_MEP
:
14245 return reloc_type
== 4; /* R_MEP_32. */
14247 return reloc_type
== 2; /* R_METAG_ADDR32. */
14248 case EM_MICROBLAZE
:
14249 return reloc_type
== 1; /* R_MICROBLAZE_32. */
14251 return reloc_type
== 2; /* R_MIPS_32. */
14253 return reloc_type
== 4; /* R_MMIX_32. */
14254 case EM_CYGNUS_MN10200
:
14256 return reloc_type
== 1; /* R_MN10200_32. */
14257 case EM_CYGNUS_MN10300
:
14259 return reloc_type
== 1; /* R_MN10300_32. */
14261 return reloc_type
== 1; /* R_MOXIE_32. */
14262 case EM_MSP430_OLD
:
14264 return reloc_type
== 1; /* R_MSP430_32 or R_MSP320_ABS32. */
14266 return reloc_type
== 2; /* R_MT_32. */
14268 return reloc_type
== 20; /* R_NDS32_RELA. */
14269 case EM_ALTERA_NIOS2
:
14270 return reloc_type
== 12; /* R_NIOS2_BFD_RELOC_32. */
14272 return reloc_type
== 1; /* R_NIOS_32. */
14274 return reloc_type
== 1; /* R_OR1K_32. */
14276 return (reloc_type
== 1 /* R_PARISC_DIR32. */
14277 || reloc_type
== 2 /* R_PARISC_DIR21L. */
14278 || reloc_type
== 41); /* R_PARISC_SECREL32. */
14281 return reloc_type
== 1; /* R_PJ_DATA_DIR32. */
14283 return reloc_type
== 1; /* R_PPC64_ADDR32. */
14285 return reloc_type
== 1; /* R_PPC_ADDR32. */
14287 return reloc_type
== 11; /* R_PRU_BFD_RELOC_32. */
14289 return reloc_type
== 1; /* R_RISCV_32. */
14291 return reloc_type
== 1; /* R_RL78_DIR32. */
14293 return reloc_type
== 1; /* R_RX_DIR32. */
14295 return reloc_type
== 1; /* R_I370_ADDR31. */
14298 return reloc_type
== 4; /* R_S390_32. */
14300 return reloc_type
== 8; /* R_SCORE_ABS32. */
14302 return reloc_type
== 1; /* R_SH_DIR32. */
14303 case EM_SPARC32PLUS
:
14306 return reloc_type
== 3 /* R_SPARC_32. */
14307 || reloc_type
== 23; /* R_SPARC_UA32. */
14309 return reloc_type
== 6; /* R_SPU_ADDR32 */
14311 return reloc_type
== 1; /* R_C6000_ABS32. */
14313 return reloc_type
== 2; /* R_TILEGX_32. */
14315 return reloc_type
== 1; /* R_TILEPRO_32. */
14316 case EM_CYGNUS_V850
:
14318 return reloc_type
== 6; /* R_V850_ABS32. */
14320 return reloc_type
== 0x33; /* R_V810_WORD. */
14322 return reloc_type
== 1; /* R_VAX_32. */
14324 return reloc_type
== 3; /* R_VISIUM_32. */
14325 case EM_WEBASSEMBLY
:
14326 return reloc_type
== 1; /* R_WASM32_32. */
14330 return reloc_type
== 10; /* R_X86_64_32. */
14333 return reloc_type
== 3; /* R_XC16C_ABS_32. */
14335 return reloc_type
== 4; /* R_XGATE_32. */
14337 return reloc_type
== 1; /* R_XSTROMY16_32. */
14338 case EM_XTENSA_OLD
:
14340 return reloc_type
== 1; /* R_XTENSA_32. */
14342 return reloc_type
== 6; /* R_Z80_32. */
14345 static unsigned int prev_warn
= 0;
14347 /* Avoid repeating the same warning multiple times. */
14348 if (prev_warn
!= filedata
->file_header
.e_machine
)
14349 error (_("Missing knowledge of 32-bit reloc types used in DWARF sections of machine number %d\n"),
14350 filedata
->file_header
.e_machine
);
14351 prev_warn
= filedata
->file_header
.e_machine
;
14357 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14358 a 32-bit pc-relative RELA relocation used in DWARF debug sections. */
14361 is_32bit_pcrel_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14363 switch (filedata
->file_header
.e_machine
)
14364 /* Please keep this table alpha-sorted for ease of visual lookup. */
14368 return reloc_type
== 2; /* R_386_PC32. */
14370 return reloc_type
== 4; /* R_68K_PC32. */
14372 return reloc_type
== 261; /* R_AARCH64_PREL32 */
14373 case EM_ADAPTEVA_EPIPHANY
:
14374 return reloc_type
== 6;
14376 return reloc_type
== 10; /* R_ALPHA_SREL32. */
14377 case EM_ARC_COMPACT
:
14378 case EM_ARC_COMPACT2
:
14379 return reloc_type
== 49; /* R_ARC_32_PCREL. */
14381 return reloc_type
== 3; /* R_ARM_REL32 */
14384 return reloc_type
== 36; /* R_AVR_32_PCREL. */
14385 case EM_MICROBLAZE
:
14386 return reloc_type
== 2; /* R_MICROBLAZE_32_PCREL. */
14388 return reloc_type
== 9; /* R_OR1K_32_PCREL. */
14390 return reloc_type
== 9; /* R_PARISC_PCREL32. */
14392 return reloc_type
== 26; /* R_PPC_REL32. */
14394 return reloc_type
== 26; /* R_PPC64_REL32. */
14396 return reloc_type
== 57; /* R_RISCV_32_PCREL. */
14399 return reloc_type
== 5; /* R_390_PC32. */
14401 return reloc_type
== 2; /* R_SH_REL32. */
14402 case EM_SPARC32PLUS
:
14405 return reloc_type
== 6; /* R_SPARC_DISP32. */
14407 return reloc_type
== 13; /* R_SPU_REL32. */
14409 return reloc_type
== 6; /* R_TILEGX_32_PCREL. */
14411 return reloc_type
== 4; /* R_TILEPRO_32_PCREL. */
14413 return reloc_type
== 6; /* R_VISIUM_32_PCREL */
14417 return reloc_type
== 2; /* R_X86_64_PC32. */
14419 return reloc_type
== 4; /* R_VAX_PCREL32. */
14420 case EM_XTENSA_OLD
:
14422 return reloc_type
== 14; /* R_XTENSA_32_PCREL. */
14424 /* Do not abort or issue an error message here. Not all targets use
14425 pc-relative 32-bit relocs in their DWARF debug information and we
14426 have already tested for target coverage in is_32bit_abs_reloc. A
14427 more helpful warning message will be generated by apply_relocations
14428 anyway, so just return. */
14433 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14434 a 64-bit absolute RELA relocation used in DWARF debug sections. */
14437 is_64bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14439 switch (filedata
->file_header
.e_machine
)
14442 return reloc_type
== 257; /* R_AARCH64_ABS64. */
14444 return reloc_type
== 2; /* R_ALPHA_REFQUAD. */
14446 return (reloc_type
== 0x26 /* R_IA64_DIR64MSB. */
14447 || reloc_type
== 0x27 /* R_IA64_DIR64LSB. */);
14449 return reloc_type
== 2; /* R_LARCH_64 */
14451 return reloc_type
== 80; /* R_PARISC_DIR64. */
14453 return reloc_type
== 38; /* R_PPC64_ADDR64. */
14455 return reloc_type
== 2; /* R_RISCV_64. */
14456 case EM_SPARC32PLUS
:
14459 return reloc_type
== 32 /* R_SPARC_64. */
14460 || reloc_type
== 54; /* R_SPARC_UA64. */
14464 return reloc_type
== 1; /* R_X86_64_64. */
14467 return reloc_type
== 22; /* R_S390_64. */
14469 return reloc_type
== 1; /* R_TILEGX_64. */
14471 return reloc_type
== 18; /* R_MIPS_64. */
14477 /* Like is_32bit_pcrel_reloc except that it returns TRUE iff RELOC_TYPE is
14478 a 64-bit pc-relative RELA relocation used in DWARF debug sections. */
14481 is_64bit_pcrel_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14483 switch (filedata
->file_header
.e_machine
)
14486 return reloc_type
== 260; /* R_AARCH64_PREL64. */
14488 return reloc_type
== 11; /* R_ALPHA_SREL64. */
14490 return (reloc_type
== 0x4e /* R_IA64_PCREL64MSB. */
14491 || reloc_type
== 0x4f /* R_IA64_PCREL64LSB. */);
14493 return reloc_type
== 72; /* R_PARISC_PCREL64. */
14495 return reloc_type
== 44; /* R_PPC64_REL64. */
14496 case EM_SPARC32PLUS
:
14499 return reloc_type
== 46; /* R_SPARC_DISP64. */
14503 return reloc_type
== 24; /* R_X86_64_PC64. */
14506 return reloc_type
== 23; /* R_S390_PC64. */
14508 return reloc_type
== 5; /* R_TILEGX_64_PCREL. */
14514 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14515 a 24-bit absolute RELA relocation used in DWARF debug sections. */
14518 is_24bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14520 switch (filedata
->file_header
.e_machine
)
14522 case EM_CYGNUS_MN10200
:
14524 return reloc_type
== 4; /* R_MN10200_24. */
14526 return reloc_type
== 5; /* R_FT32_20. */
14528 return reloc_type
== 5; /* R_Z80_24. */
14534 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14535 a 16-bit absolute RELA relocation used in DWARF debug sections. */
14538 is_16bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14540 /* Please keep this table alpha-sorted for ease of visual lookup. */
14541 switch (filedata
->file_header
.e_machine
)
14544 case EM_ARC_COMPACT
:
14545 case EM_ARC_COMPACT2
:
14546 return reloc_type
== 2; /* R_ARC_16. */
14547 case EM_ADAPTEVA_EPIPHANY
:
14548 return reloc_type
== 5;
14551 return reloc_type
== 4; /* R_AVR_16. */
14552 case EM_CYGNUS_D10V
:
14554 return reloc_type
== 3; /* R_D10V_16. */
14556 return reloc_type
== 2; /* R_FT32_16. */
14560 return reloc_type
== R_H8_DIR16
;
14563 return reloc_type
== 1; /* R_IP2K_16. */
14566 return reloc_type
== 1; /* R_M32C_16 */
14567 case EM_CYGNUS_MN10200
:
14569 return reloc_type
== 2; /* R_MN10200_16. */
14570 case EM_CYGNUS_MN10300
:
14572 return reloc_type
== 2; /* R_MN10300_16. */
14574 if (uses_msp430x_relocs (filedata
))
14575 return reloc_type
== 2; /* R_MSP430_ABS16. */
14576 /* Fall through. */
14577 case EM_MSP430_OLD
:
14578 return reloc_type
== 5; /* R_MSP430_16_BYTE. */
14580 return reloc_type
== 19; /* R_NDS32_RELA. */
14581 case EM_ALTERA_NIOS2
:
14582 return reloc_type
== 13; /* R_NIOS2_BFD_RELOC_16. */
14584 return reloc_type
== 9; /* R_NIOS_16. */
14586 return reloc_type
== 2; /* R_OR1K_16. */
14588 return reloc_type
== 55; /* R_RISCV_SET16. */
14590 return reloc_type
== 8; /* R_PRU_BFD_RELOC_16. */
14592 return reloc_type
== 2; /* R_C6000_ABS16. */
14594 return reloc_type
== 2; /* R_VISIUM_16. */
14597 return reloc_type
== 2; /* R_XC16C_ABS_16. */
14599 return reloc_type
== 3; /* R_XGATE_16. */
14601 return reloc_type
== 4; /* R_Z80_16. */
14607 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14608 a 8-bit absolute RELA relocation used in DWARF debug sections. */
14611 is_8bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14613 switch (filedata
->file_header
.e_machine
)
14616 return reloc_type
== 54; /* R_RISCV_SET8. */
14618 return reloc_type
== 1; /* R_Z80_8. */
14624 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14625 a 6-bit absolute RELA relocation used in DWARF debug sections. */
14628 is_6bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14630 switch (filedata
->file_header
.e_machine
)
14633 return reloc_type
== 53; /* R_RISCV_SET6. */
14639 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14640 a 32-bit inplace add RELA relocation used in DWARF debug sections. */
14643 is_32bit_inplace_add_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14645 /* Please keep this table alpha-sorted for ease of visual lookup. */
14646 switch (filedata
->file_header
.e_machine
)
14649 return reloc_type
== 35; /* R_RISCV_ADD32. */
14655 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14656 a 32-bit inplace sub RELA relocation used in DWARF debug sections. */
14659 is_32bit_inplace_sub_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14661 /* Please keep this table alpha-sorted for ease of visual lookup. */
14662 switch (filedata
->file_header
.e_machine
)
14665 return reloc_type
== 39; /* R_RISCV_SUB32. */
14671 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14672 a 64-bit inplace add RELA relocation used in DWARF debug sections. */
14675 is_64bit_inplace_add_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14677 /* Please keep this table alpha-sorted for ease of visual lookup. */
14678 switch (filedata
->file_header
.e_machine
)
14681 return reloc_type
== 36; /* R_RISCV_ADD64. */
14687 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14688 a 64-bit inplace sub RELA relocation used in DWARF debug sections. */
14691 is_64bit_inplace_sub_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14693 /* Please keep this table alpha-sorted for ease of visual lookup. */
14694 switch (filedata
->file_header
.e_machine
)
14697 return reloc_type
== 40; /* R_RISCV_SUB64. */
14703 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14704 a 16-bit inplace add RELA relocation used in DWARF debug sections. */
14707 is_16bit_inplace_add_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14709 /* Please keep this table alpha-sorted for ease of visual lookup. */
14710 switch (filedata
->file_header
.e_machine
)
14713 return reloc_type
== 34; /* R_RISCV_ADD16. */
14719 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14720 a 16-bit inplace sub RELA relocation used in DWARF debug sections. */
14723 is_16bit_inplace_sub_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14725 /* Please keep this table alpha-sorted for ease of visual lookup. */
14726 switch (filedata
->file_header
.e_machine
)
14729 return reloc_type
== 38; /* R_RISCV_SUB16. */
14735 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14736 a 8-bit inplace add RELA relocation used in DWARF debug sections. */
14739 is_8bit_inplace_add_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14741 /* Please keep this table alpha-sorted for ease of visual lookup. */
14742 switch (filedata
->file_header
.e_machine
)
14745 return reloc_type
== 33; /* R_RISCV_ADD8. */
14751 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14752 a 8-bit inplace sub RELA relocation used in DWARF debug sections. */
14755 is_8bit_inplace_sub_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14757 /* Please keep this table alpha-sorted for ease of visual lookup. */
14758 switch (filedata
->file_header
.e_machine
)
14761 return reloc_type
== 37; /* R_RISCV_SUB8. */
14767 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14768 a 6-bit inplace sub RELA relocation used in DWARF debug sections. */
14771 is_6bit_inplace_sub_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14773 switch (filedata
->file_header
.e_machine
)
14776 return reloc_type
== 52; /* R_RISCV_SUB6. */
14782 /* Returns TRUE iff RELOC_TYPE is a NONE relocation used for discarded
14783 relocation entries (possibly formerly used for SHT_GROUP sections). */
14786 is_none_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14788 switch (filedata
->file_header
.e_machine
)
14790 case EM_386
: /* R_386_NONE. */
14791 case EM_68K
: /* R_68K_NONE. */
14792 case EM_ADAPTEVA_EPIPHANY
:
14793 case EM_ALPHA
: /* R_ALPHA_NONE. */
14794 case EM_ALTERA_NIOS2
: /* R_NIOS2_NONE. */
14795 case EM_ARC
: /* R_ARC_NONE. */
14796 case EM_ARC_COMPACT2
: /* R_ARC_NONE. */
14797 case EM_ARC_COMPACT
: /* R_ARC_NONE. */
14798 case EM_ARM
: /* R_ARM_NONE. */
14799 case EM_C166
: /* R_XC16X_NONE. */
14800 case EM_CRIS
: /* R_CRIS_NONE. */
14801 case EM_FT32
: /* R_FT32_NONE. */
14802 case EM_IA_64
: /* R_IA64_NONE. */
14803 case EM_K1OM
: /* R_X86_64_NONE. */
14804 case EM_L1OM
: /* R_X86_64_NONE. */
14805 case EM_M32R
: /* R_M32R_NONE. */
14806 case EM_MIPS
: /* R_MIPS_NONE. */
14807 case EM_MN10300
: /* R_MN10300_NONE. */
14808 case EM_MOXIE
: /* R_MOXIE_NONE. */
14809 case EM_NIOS32
: /* R_NIOS_NONE. */
14810 case EM_OR1K
: /* R_OR1K_NONE. */
14811 case EM_PARISC
: /* R_PARISC_NONE. */
14812 case EM_PPC64
: /* R_PPC64_NONE. */
14813 case EM_PPC
: /* R_PPC_NONE. */
14814 case EM_RISCV
: /* R_RISCV_NONE. */
14815 case EM_S390
: /* R_390_NONE. */
14817 case EM_SH
: /* R_SH_NONE. */
14818 case EM_SPARC32PLUS
:
14819 case EM_SPARC
: /* R_SPARC_NONE. */
14821 case EM_TILEGX
: /* R_TILEGX_NONE. */
14822 case EM_TILEPRO
: /* R_TILEPRO_NONE. */
14823 case EM_TI_C6000
:/* R_C6000_NONE. */
14824 case EM_X86_64
: /* R_X86_64_NONE. */
14826 case EM_Z80
: /* R_Z80_NONE. */
14827 case EM_WEBASSEMBLY
: /* R_WASM32_NONE. */
14828 return reloc_type
== 0;
14831 return reloc_type
== 0 || reloc_type
== 256;
14834 return (reloc_type
== 0 /* R_AVR_NONE. */
14835 || reloc_type
== 30 /* R_AVR_DIFF8. */
14836 || reloc_type
== 31 /* R_AVR_DIFF16. */
14837 || reloc_type
== 32 /* R_AVR_DIFF32. */);
14839 return reloc_type
== 3; /* R_METAG_NONE. */
14841 return (reloc_type
== 0 /* R_XTENSA_NONE. */
14842 || reloc_type
== 204 /* R_NDS32_DIFF8. */
14843 || reloc_type
== 205 /* R_NDS32_DIFF16. */
14844 || reloc_type
== 206 /* R_NDS32_DIFF32. */
14845 || reloc_type
== 207 /* R_NDS32_ULEB128. */);
14847 return (reloc_type
== 0 /* R_PRU_NONE. */
14848 || reloc_type
== 65 /* R_PRU_DIFF8. */
14849 || reloc_type
== 66 /* R_PRU_DIFF16. */
14850 || reloc_type
== 67 /* R_PRU_DIFF32. */);
14851 case EM_XTENSA_OLD
:
14853 return (reloc_type
== 0 /* R_XTENSA_NONE. */
14854 || reloc_type
== 17 /* R_XTENSA_DIFF8. */
14855 || reloc_type
== 18 /* R_XTENSA_DIFF16. */
14856 || reloc_type
== 19 /* R_XTENSA_DIFF32. */
14857 || reloc_type
== 57 /* R_XTENSA_PDIFF8. */
14858 || reloc_type
== 58 /* R_XTENSA_PDIFF16. */
14859 || reloc_type
== 59 /* R_XTENSA_PDIFF32. */
14860 || reloc_type
== 60 /* R_XTENSA_NDIFF8. */
14861 || reloc_type
== 61 /* R_XTENSA_NDIFF16. */
14862 || reloc_type
== 62 /* R_XTENSA_NDIFF32. */);
14867 /* Returns TRUE if there is a relocation against
14868 section NAME at OFFSET bytes. */
14871 reloc_at (struct dwarf_section
* dsec
, dwarf_vma offset
)
14873 Elf_Internal_Rela
* relocs
;
14874 Elf_Internal_Rela
* rp
;
14876 if (dsec
== NULL
|| dsec
->reloc_info
== NULL
)
14879 relocs
= (Elf_Internal_Rela
*) dsec
->reloc_info
;
14881 for (rp
= relocs
; rp
< relocs
+ dsec
->num_relocs
; ++rp
)
14882 if (rp
->r_offset
== offset
)
14888 /* Apply relocations to a section.
14889 Returns TRUE upon success, FALSE otherwise.
14890 If RELOCS_RETURN is non-NULL then it is set to point to the loaded relocs.
14891 It is then the caller's responsibility to free them. NUM_RELOCS_RETURN
14892 will be set to the number of relocs loaded.
14894 Note: So far support has been added only for those relocations
14895 which can be found in debug sections. FIXME: Add support for
14896 more relocations ? */
14899 apply_relocations (Filedata
* filedata
,
14900 const Elf_Internal_Shdr
* section
,
14901 unsigned char * start
,
14902 bfd_size_type size
,
14903 void ** relocs_return
,
14904 unsigned long * num_relocs_return
)
14906 Elf_Internal_Shdr
* relsec
;
14907 unsigned char * end
= start
+ size
;
14909 if (relocs_return
!= NULL
)
14911 * (Elf_Internal_Rela
**) relocs_return
= NULL
;
14912 * num_relocs_return
= 0;
14915 if (filedata
->file_header
.e_type
!= ET_REL
)
14916 /* No relocs to apply. */
14919 /* Find the reloc section associated with the section. */
14920 for (relsec
= filedata
->section_headers
;
14921 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
14925 unsigned long num_relocs
;
14926 Elf_Internal_Rela
* relocs
;
14927 Elf_Internal_Rela
* rp
;
14928 Elf_Internal_Shdr
* symsec
;
14929 Elf_Internal_Sym
* symtab
;
14930 unsigned long num_syms
;
14931 Elf_Internal_Sym
* sym
;
14933 if ((relsec
->sh_type
!= SHT_RELA
&& relsec
->sh_type
!= SHT_REL
)
14934 || relsec
->sh_info
>= filedata
->file_header
.e_shnum
14935 || filedata
->section_headers
+ relsec
->sh_info
!= section
14936 || relsec
->sh_size
== 0
14937 || relsec
->sh_link
>= filedata
->file_header
.e_shnum
)
14940 symsec
= filedata
->section_headers
+ relsec
->sh_link
;
14941 if (symsec
->sh_type
!= SHT_SYMTAB
14942 && symsec
->sh_type
!= SHT_DYNSYM
)
14945 is_rela
= relsec
->sh_type
== SHT_RELA
;
14949 if (!slurp_rela_relocs (filedata
, relsec
->sh_offset
,
14950 relsec
->sh_size
, & relocs
, & num_relocs
))
14955 if (!slurp_rel_relocs (filedata
, relsec
->sh_offset
,
14956 relsec
->sh_size
, & relocs
, & num_relocs
))
14960 /* SH uses RELA but uses in place value instead of the addend field. */
14961 if (filedata
->file_header
.e_machine
== EM_SH
)
14964 symtab
= get_elf_symbols (filedata
, symsec
, & num_syms
);
14966 for (rp
= relocs
; rp
< relocs
+ num_relocs
; ++rp
)
14969 unsigned int reloc_type
;
14970 unsigned int reloc_size
;
14971 bool reloc_inplace
= false;
14972 bool reloc_subtract
= false;
14973 unsigned char *rloc
;
14974 unsigned long sym_index
;
14976 reloc_type
= get_reloc_type (filedata
, rp
->r_info
);
14978 if (target_specific_reloc_handling (filedata
, rp
, start
, end
, symtab
, num_syms
))
14980 else if (is_none_reloc (filedata
, reloc_type
))
14982 else if (is_32bit_abs_reloc (filedata
, reloc_type
)
14983 || is_32bit_pcrel_reloc (filedata
, reloc_type
))
14985 else if (is_64bit_abs_reloc (filedata
, reloc_type
)
14986 || is_64bit_pcrel_reloc (filedata
, reloc_type
))
14988 else if (is_24bit_abs_reloc (filedata
, reloc_type
))
14990 else if (is_16bit_abs_reloc (filedata
, reloc_type
))
14992 else if (is_8bit_abs_reloc (filedata
, reloc_type
)
14993 || is_6bit_abs_reloc (filedata
, reloc_type
))
14995 else if ((reloc_subtract
= is_32bit_inplace_sub_reloc (filedata
,
14997 || is_32bit_inplace_add_reloc (filedata
, reloc_type
))
15000 reloc_inplace
= true;
15002 else if ((reloc_subtract
= is_64bit_inplace_sub_reloc (filedata
,
15004 || is_64bit_inplace_add_reloc (filedata
, reloc_type
))
15007 reloc_inplace
= true;
15009 else if ((reloc_subtract
= is_16bit_inplace_sub_reloc (filedata
,
15011 || is_16bit_inplace_add_reloc (filedata
, reloc_type
))
15014 reloc_inplace
= true;
15016 else if ((reloc_subtract
= is_8bit_inplace_sub_reloc (filedata
,
15018 || is_8bit_inplace_add_reloc (filedata
, reloc_type
))
15021 reloc_inplace
= true;
15023 else if ((reloc_subtract
= is_6bit_inplace_sub_reloc (filedata
,
15027 reloc_inplace
= true;
15031 static unsigned int prev_reloc
= 0;
15033 if (reloc_type
!= prev_reloc
)
15034 warn (_("unable to apply unsupported reloc type %d to section %s\n"),
15035 reloc_type
, printable_section_name (filedata
, section
));
15036 prev_reloc
= reloc_type
;
15040 rloc
= start
+ rp
->r_offset
;
15041 if (!IN_RANGE (start
, end
, rloc
, reloc_size
))
15043 warn (_("skipping invalid relocation offset 0x%lx in section %s\n"),
15044 (unsigned long) rp
->r_offset
,
15045 printable_section_name (filedata
, section
));
15049 sym_index
= (unsigned long) get_reloc_symindex (rp
->r_info
);
15050 if (sym_index
>= num_syms
)
15052 warn (_("skipping invalid relocation symbol index 0x%lx in section %s\n"),
15053 sym_index
, printable_section_name (filedata
, section
));
15056 sym
= symtab
+ sym_index
;
15058 /* If the reloc has a symbol associated with it,
15059 make sure that it is of an appropriate type.
15061 Relocations against symbols without type can happen.
15062 Gcc -feliminate-dwarf2-dups may generate symbols
15063 without type for debug info.
15065 Icc generates relocations against function symbols
15066 instead of local labels.
15068 Relocations against object symbols can happen, eg when
15069 referencing a global array. For an example of this see
15070 the _clz.o binary in libgcc.a. */
15072 && ELF_ST_TYPE (sym
->st_info
) != STT_COMMON
15073 && ELF_ST_TYPE (sym
->st_info
) > STT_SECTION
)
15075 warn (_("skipping unexpected symbol type %s in section %s relocation %ld\n"),
15076 get_symbol_type (filedata
, ELF_ST_TYPE (sym
->st_info
)),
15077 printable_section_name (filedata
, relsec
),
15078 (long int)(rp
- relocs
));
15084 addend
+= rp
->r_addend
;
15085 /* R_XTENSA_32, R_PJ_DATA_DIR32 and R_D30V_32_NORMAL are
15086 partial_inplace. */
15088 || (filedata
->file_header
.e_machine
== EM_XTENSA
15089 && reloc_type
== 1)
15090 || ((filedata
->file_header
.e_machine
== EM_PJ
15091 || filedata
->file_header
.e_machine
== EM_PJ_OLD
)
15092 && reloc_type
== 1)
15093 || ((filedata
->file_header
.e_machine
== EM_D30V
15094 || filedata
->file_header
.e_machine
== EM_CYGNUS_D30V
)
15095 && reloc_type
== 12)
15098 if (is_6bit_inplace_sub_reloc (filedata
, reloc_type
))
15099 addend
+= byte_get (rloc
, reloc_size
) & 0x3f;
15101 addend
+= byte_get (rloc
, reloc_size
);
15104 if (is_32bit_pcrel_reloc (filedata
, reloc_type
)
15105 || is_64bit_pcrel_reloc (filedata
, reloc_type
))
15107 /* On HPPA, all pc-relative relocations are biased by 8. */
15108 if (filedata
->file_header
.e_machine
== EM_PARISC
)
15110 byte_put (rloc
, (addend
+ sym
->st_value
) - rp
->r_offset
,
15113 else if (is_6bit_abs_reloc (filedata
, reloc_type
)
15114 || is_6bit_inplace_sub_reloc (filedata
, reloc_type
))
15116 if (reloc_subtract
)
15117 addend
-= sym
->st_value
;
15119 addend
+= sym
->st_value
;
15120 addend
= (addend
& 0x3f) | (byte_get (rloc
, reloc_size
) & 0xc0);
15121 byte_put (rloc
, addend
, reloc_size
);
15123 else if (reloc_subtract
)
15124 byte_put (rloc
, addend
- sym
->st_value
, reloc_size
);
15126 byte_put (rloc
, addend
+ sym
->st_value
, reloc_size
);
15130 /* Let the target specific reloc processing code know that
15131 we have finished with these relocs. */
15132 target_specific_reloc_handling (filedata
, NULL
, NULL
, NULL
, NULL
, 0);
15136 * (Elf_Internal_Rela
**) relocs_return
= relocs
;
15137 * num_relocs_return
= num_relocs
;
15148 #ifdef SUPPORT_DISASSEMBLY
15150 disassemble_section (Elf_Internal_Shdr
* section
, Filedata
* filedata
)
15152 printf (_("\nAssembly dump of section %s\n"), printable_section_name (filedata
, section
));
15154 /* FIXME: XXX -- to be done --- XXX */
15160 /* Reads in the contents of SECTION from FILE, returning a pointer
15161 to a malloc'ed buffer or NULL if something went wrong. */
15164 get_section_contents (Elf_Internal_Shdr
* section
, Filedata
* filedata
)
15166 bfd_size_type num_bytes
= section
->sh_size
;
15168 if (num_bytes
== 0 || section
->sh_type
== SHT_NOBITS
)
15170 printf (_("Section '%s' has no data to dump.\n"),
15171 printable_section_name (filedata
, section
));
15175 return (char *) get_data (NULL
, filedata
, section
->sh_offset
, 1, num_bytes
,
15176 _("section contents"));
15179 /* Uncompresses a section that was compressed using zlib, in place. */
15182 uncompress_section_contents (unsigned char ** buffer
,
15183 dwarf_size_type uncompressed_size
,
15184 dwarf_size_type
* size
)
15186 dwarf_size_type compressed_size
= *size
;
15187 unsigned char * compressed_buffer
= *buffer
;
15188 unsigned char * uncompressed_buffer
;
15192 /* It is possible the section consists of several compressed
15193 buffers concatenated together, so we uncompress in a loop. */
15194 /* PR 18313: The state field in the z_stream structure is supposed
15195 to be invisible to the user (ie us), but some compilers will
15196 still complain about it being used without initialisation. So
15197 we first zero the entire z_stream structure and then set the fields
15199 memset (& strm
, 0, sizeof strm
);
15200 strm
.avail_in
= compressed_size
;
15201 strm
.next_in
= (Bytef
*) compressed_buffer
;
15202 strm
.avail_out
= uncompressed_size
;
15203 uncompressed_buffer
= (unsigned char *) xmalloc (uncompressed_size
);
15205 rc
= inflateInit (& strm
);
15206 while (strm
.avail_in
> 0)
15210 strm
.next_out
= ((Bytef
*) uncompressed_buffer
15211 + (uncompressed_size
- strm
.avail_out
));
15212 rc
= inflate (&strm
, Z_FINISH
);
15213 if (rc
!= Z_STREAM_END
)
15215 rc
= inflateReset (& strm
);
15217 if (inflateEnd (& strm
) != Z_OK
15219 || strm
.avail_out
!= 0)
15222 *buffer
= uncompressed_buffer
;
15223 *size
= uncompressed_size
;
15227 free (uncompressed_buffer
);
15228 /* Indicate decompression failure. */
15234 dump_section_as_strings (Elf_Internal_Shdr
* section
, Filedata
* filedata
)
15236 Elf_Internal_Shdr
*relsec
;
15237 bfd_size_type num_bytes
;
15238 unsigned char *data
;
15239 unsigned char *end
;
15240 unsigned char *real_start
;
15241 unsigned char *start
;
15242 bool some_strings_shown
;
15244 real_start
= start
= (unsigned char *) get_section_contents (section
, filedata
);
15246 /* PR 21820: Do not fail if the section was empty. */
15247 return section
->sh_size
== 0 || section
->sh_type
== SHT_NOBITS
;
15249 num_bytes
= section
->sh_size
;
15251 if (filedata
->is_separate
)
15252 printf (_("\nString dump of section '%s' in linked file %s:\n"),
15253 printable_section_name (filedata
, section
),
15254 filedata
->file_name
);
15256 printf (_("\nString dump of section '%s':\n"),
15257 printable_section_name (filedata
, section
));
15259 if (decompress_dumps
)
15261 dwarf_size_type new_size
= num_bytes
;
15262 dwarf_size_type uncompressed_size
= 0;
15264 if ((section
->sh_flags
& SHF_COMPRESSED
) != 0)
15266 Elf_Internal_Chdr chdr
;
15267 unsigned int compression_header_size
15268 = get_compression_header (& chdr
, (unsigned char *) start
,
15270 if (compression_header_size
== 0)
15271 /* An error message will have already been generated
15272 by get_compression_header. */
15275 if (chdr
.ch_type
!= ELFCOMPRESS_ZLIB
)
15277 warn (_("section '%s' has unsupported compress type: %d\n"),
15278 printable_section_name (filedata
, section
), chdr
.ch_type
);
15281 uncompressed_size
= chdr
.ch_size
;
15282 start
+= compression_header_size
;
15283 new_size
-= compression_header_size
;
15285 else if (new_size
> 12 && streq ((char *) start
, "ZLIB"))
15287 /* Read the zlib header. In this case, it should be "ZLIB"
15288 followed by the uncompressed section size, 8 bytes in
15289 big-endian order. */
15290 uncompressed_size
= start
[4]; uncompressed_size
<<= 8;
15291 uncompressed_size
+= start
[5]; uncompressed_size
<<= 8;
15292 uncompressed_size
+= start
[6]; uncompressed_size
<<= 8;
15293 uncompressed_size
+= start
[7]; uncompressed_size
<<= 8;
15294 uncompressed_size
+= start
[8]; uncompressed_size
<<= 8;
15295 uncompressed_size
+= start
[9]; uncompressed_size
<<= 8;
15296 uncompressed_size
+= start
[10]; uncompressed_size
<<= 8;
15297 uncompressed_size
+= start
[11];
15302 if (uncompressed_size
)
15304 if (uncompress_section_contents (& start
,
15305 uncompressed_size
, & new_size
))
15306 num_bytes
= new_size
;
15309 error (_("Unable to decompress section %s\n"),
15310 printable_section_name (filedata
, section
));
15315 start
= real_start
;
15318 /* If the section being dumped has relocations against it the user might
15319 be expecting these relocations to have been applied. Check for this
15320 case and issue a warning message in order to avoid confusion.
15321 FIXME: Maybe we ought to have an option that dumps a section with
15322 relocs applied ? */
15323 for (relsec
= filedata
->section_headers
;
15324 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
15327 if ((relsec
->sh_type
!= SHT_RELA
&& relsec
->sh_type
!= SHT_REL
)
15328 || relsec
->sh_info
>= filedata
->file_header
.e_shnum
15329 || filedata
->section_headers
+ relsec
->sh_info
!= section
15330 || relsec
->sh_size
== 0
15331 || relsec
->sh_link
>= filedata
->file_header
.e_shnum
)
15334 printf (_(" Note: This section has relocations against it, but these have NOT been applied to this dump.\n"));
15339 end
= start
+ num_bytes
;
15340 some_strings_shown
= false;
15342 #ifdef HAVE_MBSTATE_T
15344 /* Initialise the multibyte conversion state. */
15345 memset (& state
, 0, sizeof (state
));
15348 bool continuing
= false;
15352 while (!ISPRINT (* data
))
15353 if (++ data
>= end
)
15358 size_t maxlen
= end
- data
;
15363 continuing
= false;
15367 printf (" [%6lx] ", (unsigned long) (data
- start
));
15381 /* PR 25543: Treat new-lines as string-ending characters. */
15390 /* Do not print control characters directly as they can affect terminal
15391 settings. Such characters usually appear in the names generated
15392 by the assembler for local labels. */
15395 printf ("^%c", c
+ 0x40);
15397 else if (ISPRINT (c
))
15404 #ifdef HAVE_MBSTATE_T
15407 /* Let printf do the hard work of displaying multibyte characters. */
15408 printf ("%.1s", data
- 1);
15409 #ifdef HAVE_MBSTATE_T
15410 /* Try to find out how many bytes made up the character that was
15411 just printed. Advance the symbol pointer past the bytes that
15413 n
= mbrtowc (& w
, (char *)(data
- 1), MB_CUR_MAX
, & state
);
15417 if (n
!= (size_t) -1 && n
!= (size_t) -2 && n
> 0)
15427 printf (_("<corrupt>\n"));
15430 some_strings_shown
= true;
15434 if (! some_strings_shown
)
15435 printf (_(" No strings found in this section."));
15448 dump_section_as_bytes (Elf_Internal_Shdr
*section
,
15449 Filedata
*filedata
,
15452 Elf_Internal_Shdr
* relsec
;
15453 bfd_size_type bytes
;
15454 bfd_size_type section_size
;
15456 unsigned char * data
;
15457 unsigned char * real_start
;
15458 unsigned char * start
;
15460 real_start
= start
= (unsigned char *) get_section_contents (section
, filedata
);
15462 /* PR 21820: Do not fail if the section was empty. */
15463 return section
->sh_size
== 0 || section
->sh_type
== SHT_NOBITS
;
15465 section_size
= section
->sh_size
;
15467 if (filedata
->is_separate
)
15468 printf (_("\nHex dump of section '%s' in linked file %s:\n"),
15469 printable_section_name (filedata
, section
),
15470 filedata
->file_name
);
15472 printf (_("\nHex dump of section '%s':\n"),
15473 printable_section_name (filedata
, section
));
15475 if (decompress_dumps
)
15477 dwarf_size_type new_size
= section_size
;
15478 dwarf_size_type uncompressed_size
= 0;
15480 if ((section
->sh_flags
& SHF_COMPRESSED
) != 0)
15482 Elf_Internal_Chdr chdr
;
15483 unsigned int compression_header_size
15484 = get_compression_header (& chdr
, start
, section_size
);
15486 if (compression_header_size
== 0)
15487 /* An error message will have already been generated
15488 by get_compression_header. */
15491 if (chdr
.ch_type
!= ELFCOMPRESS_ZLIB
)
15493 warn (_("section '%s' has unsupported compress type: %d\n"),
15494 printable_section_name (filedata
, section
), chdr
.ch_type
);
15497 uncompressed_size
= chdr
.ch_size
;
15498 start
+= compression_header_size
;
15499 new_size
-= compression_header_size
;
15501 else if (new_size
> 12 && streq ((char *) start
, "ZLIB"))
15503 /* Read the zlib header. In this case, it should be "ZLIB"
15504 followed by the uncompressed section size, 8 bytes in
15505 big-endian order. */
15506 uncompressed_size
= start
[4]; uncompressed_size
<<= 8;
15507 uncompressed_size
+= start
[5]; uncompressed_size
<<= 8;
15508 uncompressed_size
+= start
[6]; uncompressed_size
<<= 8;
15509 uncompressed_size
+= start
[7]; uncompressed_size
<<= 8;
15510 uncompressed_size
+= start
[8]; uncompressed_size
<<= 8;
15511 uncompressed_size
+= start
[9]; uncompressed_size
<<= 8;
15512 uncompressed_size
+= start
[10]; uncompressed_size
<<= 8;
15513 uncompressed_size
+= start
[11];
15518 if (uncompressed_size
)
15520 if (uncompress_section_contents (& start
, uncompressed_size
,
15523 section_size
= new_size
;
15527 error (_("Unable to decompress section %s\n"),
15528 printable_section_name (filedata
, section
));
15529 /* FIXME: Print the section anyway ? */
15534 start
= real_start
;
15539 if (! apply_relocations (filedata
, section
, start
, section_size
, NULL
, NULL
))
15544 /* If the section being dumped has relocations against it the user might
15545 be expecting these relocations to have been applied. Check for this
15546 case and issue a warning message in order to avoid confusion.
15547 FIXME: Maybe we ought to have an option that dumps a section with
15548 relocs applied ? */
15549 for (relsec
= filedata
->section_headers
;
15550 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
15553 if ((relsec
->sh_type
!= SHT_RELA
&& relsec
->sh_type
!= SHT_REL
)
15554 || relsec
->sh_info
>= filedata
->file_header
.e_shnum
15555 || filedata
->section_headers
+ relsec
->sh_info
!= section
15556 || relsec
->sh_size
== 0
15557 || relsec
->sh_link
>= filedata
->file_header
.e_shnum
)
15560 printf (_(" NOTE: This section has relocations against it, but these have NOT been applied to this dump.\n"));
15565 addr
= section
->sh_addr
;
15566 bytes
= section_size
;
15575 lbytes
= (bytes
> 16 ? 16 : bytes
);
15577 printf (" 0x%8.8lx ", (unsigned long) addr
);
15579 for (j
= 0; j
< 16; j
++)
15582 printf ("%2.2x", data
[j
]);
15590 for (j
= 0; j
< lbytes
; j
++)
15593 if (k
>= ' ' && k
< 0x7f)
15616 #ifdef ENABLE_LIBCTF
15617 static ctf_sect_t
*
15618 shdr_to_ctf_sect (ctf_sect_t
*buf
, Elf_Internal_Shdr
*shdr
, Filedata
*filedata
)
15620 buf
->cts_name
= section_name_print (filedata
, shdr
);
15621 buf
->cts_size
= shdr
->sh_size
;
15622 buf
->cts_entsize
= shdr
->sh_entsize
;
15627 /* Formatting callback function passed to ctf_dump. Returns either the pointer
15628 it is passed, or a pointer to newly-allocated storage, in which case
15629 dump_ctf() will free it when it no longer needs it. */
15632 dump_ctf_indent_lines (ctf_sect_names_t sect ATTRIBUTE_UNUSED
,
15633 char *s
, void *arg
)
15635 const char *blanks
= arg
;
15638 if (asprintf (&new_s
, "%s%s", blanks
, s
) < 0)
15643 /* Dump CTF errors/warnings. */
15645 dump_ctf_errs (ctf_dict_t
*fp
)
15647 ctf_next_t
*it
= NULL
;
15652 /* Dump accumulated errors and warnings. */
15653 while ((errtext
= ctf_errwarning_next (fp
, &it
, &is_warning
, &err
)) != NULL
)
15655 error (_("%s: %s"), is_warning
? _("warning"): _("error"),
15659 if (err
!= ECTF_NEXT_END
)
15660 error (_("CTF error: cannot get CTF errors: `%s'"), ctf_errmsg (err
));
15663 /* Dump one CTF archive member. */
15666 dump_ctf_archive_member (ctf_dict_t
*ctf
, const char *name
, ctf_dict_t
*parent
,
15669 const char *things
[] = {"Header", "Labels", "Data objects",
15670 "Function objects", "Variables", "Types", "Strings",
15672 const char **thing
;
15675 /* Don't print out the name of the default-named archive member if it appears
15676 first in the list. The name .ctf appears everywhere, even for things that
15677 aren't really archives, so printing it out is liable to be confusing; also,
15678 the common case by far is for only one archive member to exist, and hiding
15679 it in that case seems worthwhile. */
15681 if (strcmp (name
, ".ctf") != 0 || member
!= 0)
15682 printf (_("\nCTF archive member: %s:\n"), name
);
15684 if (ctf_parent_name (ctf
) != NULL
)
15685 ctf_import (ctf
, parent
);
15687 for (i
= 0, thing
= things
; *thing
[0]; thing
++, i
++)
15689 ctf_dump_state_t
*s
= NULL
;
15692 printf ("\n %s:\n", *thing
);
15693 while ((item
= ctf_dump (ctf
, &s
, i
, dump_ctf_indent_lines
,
15694 (void *) " ")) != NULL
)
15696 printf ("%s\n", item
);
15700 if (ctf_errno (ctf
))
15702 error (_("Iteration failed: %s, %s\n"), *thing
,
15703 ctf_errmsg (ctf_errno (ctf
)));
15708 dump_ctf_errs (ctf
);
15712 dump_section_as_ctf (Elf_Internal_Shdr
* section
, Filedata
* filedata
)
15714 Elf_Internal_Shdr
* symtab_sec
= NULL
;
15715 Elf_Internal_Shdr
* strtab_sec
= NULL
;
15716 void * data
= NULL
;
15717 void * symdata
= NULL
;
15718 void * strdata
= NULL
;
15719 ctf_sect_t ctfsect
, symsect
, strsect
;
15720 ctf_sect_t
* symsectp
= NULL
;
15721 ctf_sect_t
* strsectp
= NULL
;
15722 ctf_archive_t
* ctfa
= NULL
;
15723 ctf_dict_t
* parent
= NULL
;
15726 ctf_next_t
*i
= NULL
;
15732 shdr_to_ctf_sect (&ctfsect
, section
, filedata
);
15733 data
= get_section_contents (section
, filedata
);
15734 ctfsect
.cts_data
= data
;
15736 if (!dump_ctf_symtab_name
)
15737 dump_ctf_symtab_name
= strdup (".dynsym");
15739 if (!dump_ctf_strtab_name
)
15740 dump_ctf_strtab_name
= strdup (".dynstr");
15742 if (dump_ctf_symtab_name
&& dump_ctf_symtab_name
[0] != 0)
15744 if ((symtab_sec
= find_section (filedata
, dump_ctf_symtab_name
)) == NULL
)
15746 error (_("No symbol section named %s\n"), dump_ctf_symtab_name
);
15749 if ((symdata
= (void *) get_data (NULL
, filedata
,
15750 symtab_sec
->sh_offset
, 1,
15751 symtab_sec
->sh_size
,
15752 _("symbols"))) == NULL
)
15754 symsectp
= shdr_to_ctf_sect (&symsect
, symtab_sec
, filedata
);
15755 symsect
.cts_data
= symdata
;
15758 if (dump_ctf_strtab_name
&& dump_ctf_strtab_name
[0] != 0)
15760 if ((strtab_sec
= find_section (filedata
, dump_ctf_strtab_name
)) == NULL
)
15762 error (_("No string table section named %s\n"),
15763 dump_ctf_strtab_name
);
15766 if ((strdata
= (void *) get_data (NULL
, filedata
,
15767 strtab_sec
->sh_offset
, 1,
15768 strtab_sec
->sh_size
,
15769 _("strings"))) == NULL
)
15771 strsectp
= shdr_to_ctf_sect (&strsect
, strtab_sec
, filedata
);
15772 strsect
.cts_data
= strdata
;
15775 /* Load the CTF file and dump it. It may be a raw CTF section, or an archive:
15776 libctf papers over the difference, so we can pretend it is always an
15779 if ((ctfa
= ctf_arc_bufopen (&ctfsect
, symsectp
, strsectp
, &err
)) == NULL
)
15781 dump_ctf_errs (NULL
);
15782 error (_("CTF open failure: %s\n"), ctf_errmsg (err
));
15786 ctf_arc_symsect_endianness (ctfa
, filedata
->file_header
.e_ident
[EI_DATA
]
15789 /* Preload the parent dict, since it will need to be imported into every
15791 if ((parent
= ctf_dict_open (ctfa
, dump_ctf_parent_name
, &err
)) == NULL
)
15793 dump_ctf_errs (NULL
);
15794 error (_("CTF open failure: %s\n"), ctf_errmsg (err
));
15800 if (filedata
->is_separate
)
15801 printf (_("\nDump of CTF section '%s' in linked file %s:\n"),
15802 printable_section_name (filedata
, section
),
15803 filedata
->file_name
);
15805 printf (_("\nDump of CTF section '%s':\n"),
15806 printable_section_name (filedata
, section
));
15808 while ((fp
= ctf_archive_next (ctfa
, &i
, &name
, 0, &err
)) != NULL
)
15809 dump_ctf_archive_member (fp
, name
, parent
, member
++);
15810 if (err
!= ECTF_NEXT_END
)
15812 dump_ctf_errs (NULL
);
15813 error (_("CTF member open failure: %s\n"), ctf_errmsg (err
));
15818 ctf_dict_close (parent
);
15828 load_specific_debug_section (enum dwarf_section_display_enum debug
,
15829 const Elf_Internal_Shdr
* sec
,
15832 struct dwarf_section
* section
= &debug_displays
[debug
].section
;
15834 Filedata
* filedata
= (Filedata
*) data
;
15836 if (section
->start
!= NULL
)
15838 /* If it is already loaded, do nothing. */
15839 if (streq (section
->filename
, filedata
->file_name
))
15841 free (section
->start
);
15844 snprintf (buf
, sizeof (buf
), _("%s section data"), section
->name
);
15845 section
->address
= sec
->sh_addr
;
15846 section
->filename
= filedata
->file_name
;
15847 section
->start
= (unsigned char *) get_data (NULL
, filedata
,
15849 sec
->sh_size
, buf
);
15850 if (section
->start
== NULL
)
15854 unsigned char *start
= section
->start
;
15855 dwarf_size_type size
= sec
->sh_size
;
15856 dwarf_size_type uncompressed_size
= 0;
15858 if ((sec
->sh_flags
& SHF_COMPRESSED
) != 0)
15860 Elf_Internal_Chdr chdr
;
15861 unsigned int compression_header_size
;
15863 if (size
< (is_32bit_elf
15864 ? sizeof (Elf32_External_Chdr
)
15865 : sizeof (Elf64_External_Chdr
)))
15867 warn (_("compressed section %s is too small to contain a compression header\n"),
15872 compression_header_size
= get_compression_header (&chdr
, start
, size
);
15873 if (compression_header_size
== 0)
15874 /* An error message will have already been generated
15875 by get_compression_header. */
15878 if (chdr
.ch_type
!= ELFCOMPRESS_ZLIB
)
15880 warn (_("section '%s' has unsupported compress type: %d\n"),
15881 section
->name
, chdr
.ch_type
);
15884 uncompressed_size
= chdr
.ch_size
;
15885 start
+= compression_header_size
;
15886 size
-= compression_header_size
;
15888 else if (size
> 12 && streq ((char *) start
, "ZLIB"))
15890 /* Read the zlib header. In this case, it should be "ZLIB"
15891 followed by the uncompressed section size, 8 bytes in
15892 big-endian order. */
15893 uncompressed_size
= start
[4]; uncompressed_size
<<= 8;
15894 uncompressed_size
+= start
[5]; uncompressed_size
<<= 8;
15895 uncompressed_size
+= start
[6]; uncompressed_size
<<= 8;
15896 uncompressed_size
+= start
[7]; uncompressed_size
<<= 8;
15897 uncompressed_size
+= start
[8]; uncompressed_size
<<= 8;
15898 uncompressed_size
+= start
[9]; uncompressed_size
<<= 8;
15899 uncompressed_size
+= start
[10]; uncompressed_size
<<= 8;
15900 uncompressed_size
+= start
[11];
15905 if (uncompressed_size
)
15907 if (uncompress_section_contents (&start
, uncompressed_size
,
15910 /* Free the compressed buffer, update the section buffer
15911 and the section size if uncompress is successful. */
15912 free (section
->start
);
15913 section
->start
= start
;
15917 error (_("Unable to decompress section %s\n"),
15918 printable_section_name (filedata
, sec
));
15923 section
->size
= size
;
15926 if (section
->start
== NULL
)
15929 if (debug_displays
[debug
].relocate
)
15931 if (! apply_relocations (filedata
, sec
, section
->start
, section
->size
,
15932 & section
->reloc_info
, & section
->num_relocs
))
15937 section
->reloc_info
= NULL
;
15938 section
->num_relocs
= 0;
15944 #if HAVE_LIBDEBUGINFOD
15945 /* Return a hex string representation of the build-id. */
15947 get_build_id (void * data
)
15949 Filedata
* filedata
= (Filedata
*) data
;
15950 Elf_Internal_Shdr
* shdr
;
15953 /* Iterate through notes to find note.gnu.build-id.
15954 FIXME: Only the first note in any note section is examined. */
15955 for (i
= 0, shdr
= filedata
->section_headers
;
15956 i
< filedata
->file_header
.e_shnum
&& shdr
!= NULL
;
15959 if (shdr
->sh_type
!= SHT_NOTE
)
15964 size_t data_remaining
;
15966 Elf_External_Note
* enote
;
15967 Elf_Internal_Note inote
;
15969 bfd_vma offset
= shdr
->sh_offset
;
15970 bfd_vma align
= shdr
->sh_addralign
;
15971 bfd_vma length
= shdr
->sh_size
;
15973 enote
= (Elf_External_Note
*) get_section_contents (shdr
, filedata
);
15979 else if (align
!= 4 && align
!= 8)
15985 end
= (char *) enote
+ length
;
15986 data_remaining
= end
- (char *) enote
;
15988 if (!is_ia64_vms (filedata
))
15990 min_notesz
= offsetof (Elf_External_Note
, name
);
15991 if (data_remaining
< min_notesz
)
15994 malformed note encountered in section %s whilst scanning for build-id note\n"),
15995 printable_section_name (filedata
, shdr
));
15999 data_remaining
-= min_notesz
;
16001 inote
.type
= BYTE_GET (enote
->type
);
16002 inote
.namesz
= BYTE_GET (enote
->namesz
);
16003 inote
.namedata
= enote
->name
;
16004 inote
.descsz
= BYTE_GET (enote
->descsz
);
16005 inote
.descdata
= ((char *) enote
16006 + ELF_NOTE_DESC_OFFSET (inote
.namesz
, align
));
16007 inote
.descpos
= offset
+ (inote
.descdata
- (char *) enote
);
16008 next
= ((char *) enote
16009 + ELF_NOTE_NEXT_OFFSET (inote
.namesz
, inote
.descsz
, align
));
16013 Elf64_External_VMS_Note
*vms_enote
;
16015 /* PR binutils/15191
16016 Make sure that there is enough data to read. */
16017 min_notesz
= offsetof (Elf64_External_VMS_Note
, name
);
16018 if (data_remaining
< min_notesz
)
16021 malformed note encountered in section %s whilst scanning for build-id note\n"),
16022 printable_section_name (filedata
, shdr
));
16026 data_remaining
-= min_notesz
;
16028 vms_enote
= (Elf64_External_VMS_Note
*) enote
;
16029 inote
.type
= BYTE_GET (vms_enote
->type
);
16030 inote
.namesz
= BYTE_GET (vms_enote
->namesz
);
16031 inote
.namedata
= vms_enote
->name
;
16032 inote
.descsz
= BYTE_GET (vms_enote
->descsz
);
16033 inote
.descdata
= inote
.namedata
+ align_power (inote
.namesz
, 3);
16034 inote
.descpos
= offset
+ (inote
.descdata
- (char *) enote
);
16035 next
= inote
.descdata
+ align_power (inote
.descsz
, 3);
16038 /* Skip malformed notes. */
16039 if ((size_t) (inote
.descdata
- inote
.namedata
) < inote
.namesz
16040 || (size_t) (inote
.descdata
- inote
.namedata
) > data_remaining
16041 || (size_t) (next
- inote
.descdata
) < inote
.descsz
16042 || ((size_t) (next
- inote
.descdata
)
16043 > data_remaining
- (size_t) (inote
.descdata
- inote
.namedata
)))
16046 malformed note encountered in section %s whilst scanning for build-id note\n"),
16047 printable_section_name (filedata
, shdr
));
16052 /* Check if this is the build-id note. If so then convert the build-id
16053 bytes to a hex string. */
16054 if (inote
.namesz
> 0
16055 && startswith (inote
.namedata
, "GNU")
16056 && inote
.type
== NT_GNU_BUILD_ID
)
16061 build_id
= malloc (inote
.descsz
* 2 + 1);
16062 if (build_id
== NULL
)
16068 for (j
= 0; j
< inote
.descsz
; ++j
)
16069 sprintf (build_id
+ (j
* 2), "%02x", inote
.descdata
[j
] & 0xff);
16070 build_id
[inote
.descsz
* 2] = '\0';
16073 return (unsigned char *) build_id
;
16080 #endif /* HAVE_LIBDEBUGINFOD */
16082 /* If this is not NULL, load_debug_section will only look for sections
16083 within the list of sections given here. */
16084 static unsigned int * section_subset
= NULL
;
16087 load_debug_section (enum dwarf_section_display_enum debug
, void * data
)
16089 struct dwarf_section
* section
= &debug_displays
[debug
].section
;
16090 Elf_Internal_Shdr
* sec
;
16091 Filedata
* filedata
= (Filedata
*) data
;
16093 if (!dump_any_debugging
)
16096 /* Without section headers we cannot find any sections. */
16097 if (filedata
->section_headers
== NULL
)
16100 if (filedata
->string_table
== NULL
16101 && filedata
->file_header
.e_shstrndx
!= SHN_UNDEF
16102 && filedata
->file_header
.e_shstrndx
< filedata
->file_header
.e_shnum
)
16104 Elf_Internal_Shdr
* strs
;
16106 /* Read in the string table, so that we have section names to scan. */
16107 strs
= filedata
->section_headers
+ filedata
->file_header
.e_shstrndx
;
16109 if (strs
!= NULL
&& strs
->sh_size
!= 0)
16111 filedata
->string_table
16112 = (char *) get_data (NULL
, filedata
, strs
->sh_offset
,
16113 1, strs
->sh_size
, _("string table"));
16115 filedata
->string_table_length
16116 = filedata
->string_table
!= NULL
? strs
->sh_size
: 0;
16120 /* Locate the debug section. */
16121 sec
= find_section_in_set (filedata
, section
->uncompressed_name
, section_subset
);
16123 section
->name
= section
->uncompressed_name
;
16126 sec
= find_section_in_set (filedata
, section
->compressed_name
, section_subset
);
16128 section
->name
= section
->compressed_name
;
16133 /* If we're loading from a subset of sections, and we've loaded
16134 a section matching this name before, it's likely that it's a
16136 if (section_subset
!= NULL
)
16137 free_debug_section (debug
);
16139 return load_specific_debug_section (debug
, sec
, data
);
16143 free_debug_section (enum dwarf_section_display_enum debug
)
16145 struct dwarf_section
* section
= &debug_displays
[debug
].section
;
16147 if (section
->start
== NULL
)
16150 free ((char *) section
->start
);
16151 section
->start
= NULL
;
16152 section
->address
= 0;
16155 free (section
->reloc_info
);
16156 section
->reloc_info
= NULL
;
16157 section
->num_relocs
= 0;
16161 display_debug_section (int shndx
, Elf_Internal_Shdr
* section
, Filedata
* filedata
)
16163 const char *name
= (section_name_valid (filedata
, section
)
16164 ? section_name (filedata
, section
) : "");
16165 const char *print_name
= printable_section_name (filedata
, section
);
16166 bfd_size_type length
;
16167 bool result
= true;
16170 length
= section
->sh_size
;
16173 printf (_("\nSection '%s' has no debugging data.\n"), print_name
);
16176 if (section
->sh_type
== SHT_NOBITS
)
16178 /* There is no point in dumping the contents of a debugging section
16179 which has the NOBITS type - the bits in the file will be random.
16180 This can happen when a file containing a .eh_frame section is
16181 stripped with the --only-keep-debug command line option. */
16182 printf (_("section '%s' has the NOBITS type - its contents are unreliable.\n"),
16187 if (startswith (name
, ".gnu.linkonce.wi."))
16188 name
= ".debug_info";
16190 /* See if we know how to display the contents of this section. */
16191 for (i
= 0; i
< max
; i
++)
16193 enum dwarf_section_display_enum id
= (enum dwarf_section_display_enum
) i
;
16194 struct dwarf_section_display
* display
= debug_displays
+ i
;
16195 struct dwarf_section
* sec
= & display
->section
;
16197 if (streq (sec
->uncompressed_name
, name
)
16198 || (id
== line
&& startswith (name
, ".debug_line."))
16199 || streq (sec
->compressed_name
, name
))
16201 bool secondary
= (section
!= find_section (filedata
, name
));
16204 free_debug_section (id
);
16206 if (i
== line
&& startswith (name
, ".debug_line."))
16208 else if (streq (sec
->uncompressed_name
, name
))
16209 sec
->name
= sec
->uncompressed_name
;
16211 sec
->name
= sec
->compressed_name
;
16213 if (load_specific_debug_section (id
, section
, filedata
))
16215 /* If this debug section is part of a CU/TU set in a .dwp file,
16216 restrict load_debug_section to the sections in that set. */
16217 section_subset
= find_cu_tu_set (filedata
, shndx
);
16219 result
&= display
->display (sec
, filedata
);
16221 section_subset
= NULL
;
16223 if (secondary
|| (id
!= info
&& id
!= abbrev
&& id
!= debug_addr
))
16224 free_debug_section (id
);
16232 printf (_("Unrecognized debug section: %s\n"), print_name
);
16239 /* Set DUMP_SECTS for all sections where dumps were requested
16240 based on section name. */
16243 initialise_dumps_byname (Filedata
* filedata
)
16245 struct dump_list_entry
* cur
;
16247 for (cur
= dump_sects_byname
; cur
; cur
= cur
->next
)
16252 for (i
= 0; i
< filedata
->file_header
.e_shnum
; i
++)
16253 if (section_name_valid (filedata
, filedata
->section_headers
+ i
)
16254 && streq (section_name (filedata
, filedata
->section_headers
+ i
),
16257 request_dump_bynumber (&filedata
->dump
, i
, cur
->type
);
16261 if (!any
&& !filedata
->is_separate
)
16262 warn (_("Section '%s' was not dumped because it does not exist\n"),
16268 process_section_contents (Filedata
* filedata
)
16270 Elf_Internal_Shdr
* section
;
16277 initialise_dumps_byname (filedata
);
16279 for (i
= 0, section
= filedata
->section_headers
;
16280 i
< filedata
->file_header
.e_shnum
&& i
< filedata
->dump
.num_dump_sects
;
16283 dump_type dump
= filedata
->dump
.dump_sects
[i
];
16285 if (filedata
->is_separate
&& ! process_links
)
16286 dump
&= DEBUG_DUMP
;
16288 #ifdef SUPPORT_DISASSEMBLY
16289 if (dump
& DISASS_DUMP
)
16291 if (! disassemble_section (section
, filedata
))
16295 if (dump
& HEX_DUMP
)
16297 if (! dump_section_as_bytes (section
, filedata
, false))
16301 if (dump
& RELOC_DUMP
)
16303 if (! dump_section_as_bytes (section
, filedata
, true))
16307 if (dump
& STRING_DUMP
)
16309 if (! dump_section_as_strings (section
, filedata
))
16313 if (dump
& DEBUG_DUMP
)
16315 if (! display_debug_section (i
, section
, filedata
))
16319 #ifdef ENABLE_LIBCTF
16320 if (dump
& CTF_DUMP
)
16322 if (! dump_section_as_ctf (section
, filedata
))
16328 if (! filedata
->is_separate
)
16330 /* Check to see if the user requested a
16331 dump of a section that does not exist. */
16332 for (; i
< filedata
->dump
.num_dump_sects
; i
++)
16333 if (filedata
->dump
.dump_sects
[i
])
16335 warn (_("Section %d was not dumped because it does not exist!\n"), i
);
16344 process_mips_fpe_exception (int mask
)
16350 if (mask
& OEX_FPU_INEX
)
16351 fputs ("INEX", stdout
), first
= false;
16352 if (mask
& OEX_FPU_UFLO
)
16353 printf ("%sUFLO", first
? "" : "|"), first
= false;
16354 if (mask
& OEX_FPU_OFLO
)
16355 printf ("%sOFLO", first
? "" : "|"), first
= false;
16356 if (mask
& OEX_FPU_DIV0
)
16357 printf ("%sDIV0", first
? "" : "|"), first
= false;
16358 if (mask
& OEX_FPU_INVAL
)
16359 printf ("%sINVAL", first
? "" : "|");
16362 fputs ("0", stdout
);
16365 /* Display's the value of TAG at location P. If TAG is
16366 greater than 0 it is assumed to be an unknown tag, and
16367 a message is printed to this effect. Otherwise it is
16368 assumed that a message has already been printed.
16370 If the bottom bit of TAG is set it assumed to have a
16371 string value, otherwise it is assumed to have an integer
16374 Returns an updated P pointing to the first unread byte
16375 beyond the end of TAG's value.
16377 Reads at or beyond END will not be made. */
16379 static unsigned char *
16380 display_tag_value (signed int tag
,
16382 const unsigned char * const end
)
16387 printf (" Tag_unknown_%d: ", tag
);
16391 warn (_("<corrupt tag>\n"));
16395 /* PR 17531 file: 027-19978-0.004. */
16396 size_t maxlen
= (end
- p
) - 1;
16401 print_symbol ((int) maxlen
, (const char *) p
);
16402 p
+= strnlen ((char *) p
, maxlen
) + 1;
16406 printf (_("<corrupt string tag>"));
16407 p
= (unsigned char *) end
;
16413 READ_ULEB (val
, p
, end
);
16414 printf ("%ld (0x%lx)\n", val
, val
);
16421 /* ARC ABI attributes section. */
16423 static unsigned char *
16424 display_arc_attribute (unsigned char * p
,
16425 const unsigned char * const end
)
16430 READ_ULEB (tag
, p
, end
);
16434 case Tag_ARC_PCS_config
:
16435 READ_ULEB (val
, p
, end
);
16436 printf (" Tag_ARC_PCS_config: ");
16440 printf (_("Absent/Non standard\n"));
16443 printf (_("Bare metal/mwdt\n"));
16446 printf (_("Bare metal/newlib\n"));
16449 printf (_("Linux/uclibc\n"));
16452 printf (_("Linux/glibc\n"));
16455 printf (_("Unknown\n"));
16460 case Tag_ARC_CPU_base
:
16461 READ_ULEB (val
, p
, end
);
16462 printf (" Tag_ARC_CPU_base: ");
16467 printf (_("Absent\n"));
16469 case TAG_CPU_ARC6xx
:
16470 printf ("ARC6xx\n");
16472 case TAG_CPU_ARC7xx
:
16473 printf ("ARC7xx\n");
16475 case TAG_CPU_ARCEM
:
16476 printf ("ARCEM\n");
16478 case TAG_CPU_ARCHS
:
16479 printf ("ARCHS\n");
16484 case Tag_ARC_CPU_variation
:
16485 READ_ULEB (val
, p
, end
);
16486 printf (" Tag_ARC_CPU_variation: ");
16490 if (val
> 0 && val
< 16)
16491 printf ("Core%d\n", val
);
16493 printf ("Unknown\n");
16497 printf (_("Absent\n"));
16502 case Tag_ARC_CPU_name
:
16503 printf (" Tag_ARC_CPU_name: ");
16504 p
= display_tag_value (-1, p
, end
);
16507 case Tag_ARC_ABI_rf16
:
16508 READ_ULEB (val
, p
, end
);
16509 printf (" Tag_ARC_ABI_rf16: %s\n", val
? _("yes") : _("no"));
16512 case Tag_ARC_ABI_osver
:
16513 READ_ULEB (val
, p
, end
);
16514 printf (" Tag_ARC_ABI_osver: v%d\n", val
);
16517 case Tag_ARC_ABI_pic
:
16518 case Tag_ARC_ABI_sda
:
16519 READ_ULEB (val
, p
, end
);
16520 printf (tag
== Tag_ARC_ABI_sda
? " Tag_ARC_ABI_sda: "
16521 : " Tag_ARC_ABI_pic: ");
16525 printf (_("Absent\n"));
16534 printf (_("Unknown\n"));
16539 case Tag_ARC_ABI_tls
:
16540 READ_ULEB (val
, p
, end
);
16541 printf (" Tag_ARC_ABI_tls: %s\n", val
? "r25": "none");
16544 case Tag_ARC_ABI_enumsize
:
16545 READ_ULEB (val
, p
, end
);
16546 printf (" Tag_ARC_ABI_enumsize: %s\n", val
? _("default") :
16550 case Tag_ARC_ABI_exceptions
:
16551 READ_ULEB (val
, p
, end
);
16552 printf (" Tag_ARC_ABI_exceptions: %s\n", val
? _("OPTFP")
16556 case Tag_ARC_ABI_double_size
:
16557 READ_ULEB (val
, p
, end
);
16558 printf (" Tag_ARC_ABI_double_size: %d\n", val
);
16561 case Tag_ARC_ISA_config
:
16562 printf (" Tag_ARC_ISA_config: ");
16563 p
= display_tag_value (-1, p
, end
);
16566 case Tag_ARC_ISA_apex
:
16567 printf (" Tag_ARC_ISA_apex: ");
16568 p
= display_tag_value (-1, p
, end
);
16571 case Tag_ARC_ISA_mpy_option
:
16572 READ_ULEB (val
, p
, end
);
16573 printf (" Tag_ARC_ISA_mpy_option: %d\n", val
);
16576 case Tag_ARC_ATR_version
:
16577 READ_ULEB (val
, p
, end
);
16578 printf (" Tag_ARC_ATR_version: %d\n", val
);
16582 return display_tag_value (tag
& 1, p
, end
);
16588 /* ARM EABI attributes section. */
16593 /* 0 = special, 1 = string, 2 = uleb123, > 0x80 == table lookup. */
16595 const char *const *table
;
16596 } arm_attr_public_tag
;
16598 static const char *const arm_attr_tag_CPU_arch
[] =
16599 {"Pre-v4", "v4", "v4T", "v5T", "v5TE", "v5TEJ", "v6", "v6KZ", "v6T2",
16600 "v6K", "v7", "v6-M", "v6S-M", "v7E-M", "v8", "v8-R", "v8-M.baseline",
16601 "v8-M.mainline", "v8.1-A", "v8.2-A", "v8.3-A",
16602 "v8.1-M.mainline", "v9"};
16603 static const char *const arm_attr_tag_ARM_ISA_use
[] = {"No", "Yes"};
16604 static const char *const arm_attr_tag_THUMB_ISA_use
[] =
16605 {"No", "Thumb-1", "Thumb-2", "Yes"};
16606 static const char *const arm_attr_tag_FP_arch
[] =
16607 {"No", "VFPv1", "VFPv2", "VFPv3", "VFPv3-D16", "VFPv4", "VFPv4-D16",
16608 "FP for ARMv8", "FPv5/FP-D16 for ARMv8"};
16609 static const char *const arm_attr_tag_WMMX_arch
[] = {"No", "WMMXv1", "WMMXv2"};
16610 static const char *const arm_attr_tag_Advanced_SIMD_arch
[] =
16611 {"No", "NEONv1", "NEONv1 with Fused-MAC", "NEON for ARMv8",
16612 "NEON for ARMv8.1"};
16613 static const char *const arm_attr_tag_PCS_config
[] =
16614 {"None", "Bare platform", "Linux application", "Linux DSO", "PalmOS 2004",
16615 "PalmOS (reserved)", "SymbianOS 2004", "SymbianOS (reserved)"};
16616 static const char *const arm_attr_tag_ABI_PCS_R9_use
[] =
16617 {"V6", "SB", "TLS", "Unused"};
16618 static const char *const arm_attr_tag_ABI_PCS_RW_data
[] =
16619 {"Absolute", "PC-relative", "SB-relative", "None"};
16620 static const char *const arm_attr_tag_ABI_PCS_RO_data
[] =
16621 {"Absolute", "PC-relative", "None"};
16622 static const char *const arm_attr_tag_ABI_PCS_GOT_use
[] =
16623 {"None", "direct", "GOT-indirect"};
16624 static const char *const arm_attr_tag_ABI_PCS_wchar_t
[] =
16625 {"None", "??? 1", "2", "??? 3", "4"};
16626 static const char *const arm_attr_tag_ABI_FP_rounding
[] = {"Unused", "Needed"};
16627 static const char *const arm_attr_tag_ABI_FP_denormal
[] =
16628 {"Unused", "Needed", "Sign only"};
16629 static const char *const arm_attr_tag_ABI_FP_exceptions
[] = {"Unused", "Needed"};
16630 static const char *const arm_attr_tag_ABI_FP_user_exceptions
[] = {"Unused", "Needed"};
16631 static const char *const arm_attr_tag_ABI_FP_number_model
[] =
16632 {"Unused", "Finite", "RTABI", "IEEE 754"};
16633 static const char *const arm_attr_tag_ABI_enum_size
[] =
16634 {"Unused", "small", "int", "forced to int"};
16635 static const char *const arm_attr_tag_ABI_HardFP_use
[] =
16636 {"As Tag_FP_arch", "SP only", "Reserved", "Deprecated"};
16637 static const char *const arm_attr_tag_ABI_VFP_args
[] =
16638 {"AAPCS", "VFP registers", "custom", "compatible"};
16639 static const char *const arm_attr_tag_ABI_WMMX_args
[] =
16640 {"AAPCS", "WMMX registers", "custom"};
16641 static const char *const arm_attr_tag_ABI_optimization_goals
[] =
16642 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
16643 "Aggressive Size", "Prefer Debug", "Aggressive Debug"};
16644 static const char *const arm_attr_tag_ABI_FP_optimization_goals
[] =
16645 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
16646 "Aggressive Size", "Prefer Accuracy", "Aggressive Accuracy"};
16647 static const char *const arm_attr_tag_CPU_unaligned_access
[] = {"None", "v6"};
16648 static const char *const arm_attr_tag_FP_HP_extension
[] =
16649 {"Not Allowed", "Allowed"};
16650 static const char *const arm_attr_tag_ABI_FP_16bit_format
[] =
16651 {"None", "IEEE 754", "Alternative Format"};
16652 static const char *const arm_attr_tag_DSP_extension
[] =
16653 {"Follow architecture", "Allowed"};
16654 static const char *const arm_attr_tag_MPextension_use
[] =
16655 {"Not Allowed", "Allowed"};
16656 static const char *const arm_attr_tag_DIV_use
[] =
16657 {"Allowed in Thumb-ISA, v7-R or v7-M", "Not allowed",
16658 "Allowed in v7-A with integer division extension"};
16659 static const char *const arm_attr_tag_T2EE_use
[] = {"Not Allowed", "Allowed"};
16660 static const char *const arm_attr_tag_Virtualization_use
[] =
16661 {"Not Allowed", "TrustZone", "Virtualization Extensions",
16662 "TrustZone and Virtualization Extensions"};
16663 static const char *const arm_attr_tag_MPextension_use_legacy
[] =
16664 {"Not Allowed", "Allowed"};
16666 static const char *const arm_attr_tag_MVE_arch
[] =
16667 {"No MVE", "MVE Integer only", "MVE Integer and FP"};
16669 static const char * arm_attr_tag_PAC_extension
[] =
16670 {"No PAC/AUT instructions",
16671 "PAC/AUT instructions permitted in the NOP space",
16672 "PAC/AUT instructions permitted in the NOP and in the non-NOP space"};
16674 static const char * arm_attr_tag_BTI_extension
[] =
16675 {"BTI instructions not permitted",
16676 "BTI instructions permitted in the NOP space",
16677 "BTI instructions permitted in the NOP and in the non-NOP space"};
16679 static const char * arm_attr_tag_BTI_use
[] =
16680 {"Compiled without branch target enforcement",
16681 "Compiled with branch target enforcement"};
16683 static const char * arm_attr_tag_PACRET_use
[] =
16684 {"Compiled without return address signing and authentication",
16685 "Compiled with return address signing and authentication"};
16687 #define LOOKUP(id, name) \
16688 {id, #name, 0x80 | ARRAY_SIZE(arm_attr_tag_##name), arm_attr_tag_##name}
16689 static arm_attr_public_tag arm_attr_public_tags
[] =
16691 {4, "CPU_raw_name", 1, NULL
},
16692 {5, "CPU_name", 1, NULL
},
16693 LOOKUP(6, CPU_arch
),
16694 {7, "CPU_arch_profile", 0, NULL
},
16695 LOOKUP(8, ARM_ISA_use
),
16696 LOOKUP(9, THUMB_ISA_use
),
16697 LOOKUP(10, FP_arch
),
16698 LOOKUP(11, WMMX_arch
),
16699 LOOKUP(12, Advanced_SIMD_arch
),
16700 LOOKUP(13, PCS_config
),
16701 LOOKUP(14, ABI_PCS_R9_use
),
16702 LOOKUP(15, ABI_PCS_RW_data
),
16703 LOOKUP(16, ABI_PCS_RO_data
),
16704 LOOKUP(17, ABI_PCS_GOT_use
),
16705 LOOKUP(18, ABI_PCS_wchar_t
),
16706 LOOKUP(19, ABI_FP_rounding
),
16707 LOOKUP(20, ABI_FP_denormal
),
16708 LOOKUP(21, ABI_FP_exceptions
),
16709 LOOKUP(22, ABI_FP_user_exceptions
),
16710 LOOKUP(23, ABI_FP_number_model
),
16711 {24, "ABI_align_needed", 0, NULL
},
16712 {25, "ABI_align_preserved", 0, NULL
},
16713 LOOKUP(26, ABI_enum_size
),
16714 LOOKUP(27, ABI_HardFP_use
),
16715 LOOKUP(28, ABI_VFP_args
),
16716 LOOKUP(29, ABI_WMMX_args
),
16717 LOOKUP(30, ABI_optimization_goals
),
16718 LOOKUP(31, ABI_FP_optimization_goals
),
16719 {32, "compatibility", 0, NULL
},
16720 LOOKUP(34, CPU_unaligned_access
),
16721 LOOKUP(36, FP_HP_extension
),
16722 LOOKUP(38, ABI_FP_16bit_format
),
16723 LOOKUP(42, MPextension_use
),
16724 LOOKUP(44, DIV_use
),
16725 LOOKUP(46, DSP_extension
),
16726 LOOKUP(48, MVE_arch
),
16727 LOOKUP(50, PAC_extension
),
16728 LOOKUP(52, BTI_extension
),
16729 LOOKUP(74, BTI_use
),
16730 LOOKUP(76, PACRET_use
),
16731 {64, "nodefaults", 0, NULL
},
16732 {65, "also_compatible_with", 0, NULL
},
16733 LOOKUP(66, T2EE_use
),
16734 {67, "conformance", 1, NULL
},
16735 LOOKUP(68, Virtualization_use
),
16736 LOOKUP(70, MPextension_use_legacy
)
16740 static unsigned char *
16741 display_arm_attribute (unsigned char * p
,
16742 const unsigned char * const end
)
16746 arm_attr_public_tag
* attr
;
16750 READ_ULEB (tag
, p
, end
);
16752 for (i
= 0; i
< ARRAY_SIZE (arm_attr_public_tags
); i
++)
16754 if (arm_attr_public_tags
[i
].tag
== tag
)
16756 attr
= &arm_attr_public_tags
[i
];
16763 printf (" Tag_%s: ", attr
->name
);
16764 switch (attr
->type
)
16769 case 7: /* Tag_CPU_arch_profile. */
16770 READ_ULEB (val
, p
, end
);
16773 case 0: printf (_("None\n")); break;
16774 case 'A': printf (_("Application\n")); break;
16775 case 'R': printf (_("Realtime\n")); break;
16776 case 'M': printf (_("Microcontroller\n")); break;
16777 case 'S': printf (_("Application or Realtime\n")); break;
16778 default: printf ("??? (%d)\n", val
); break;
16782 case 24: /* Tag_align_needed. */
16783 READ_ULEB (val
, p
, end
);
16786 case 0: printf (_("None\n")); break;
16787 case 1: printf (_("8-byte\n")); break;
16788 case 2: printf (_("4-byte\n")); break;
16789 case 3: printf ("??? 3\n"); break;
16792 printf (_("8-byte and up to %d-byte extended\n"),
16795 printf ("??? (%d)\n", val
);
16800 case 25: /* Tag_align_preserved. */
16801 READ_ULEB (val
, p
, end
);
16804 case 0: printf (_("None\n")); break;
16805 case 1: printf (_("8-byte, except leaf SP\n")); break;
16806 case 2: printf (_("8-byte\n")); break;
16807 case 3: printf ("??? 3\n"); break;
16810 printf (_("8-byte and up to %d-byte extended\n"),
16813 printf ("??? (%d)\n", val
);
16818 case 32: /* Tag_compatibility. */
16820 READ_ULEB (val
, p
, end
);
16821 printf (_("flag = %d, vendor = "), val
);
16824 size_t maxlen
= (end
- p
) - 1;
16826 print_symbol ((int) maxlen
, (const char *) p
);
16827 p
+= strnlen ((char *) p
, maxlen
) + 1;
16831 printf (_("<corrupt>"));
16832 p
= (unsigned char *) end
;
16838 case 64: /* Tag_nodefaults. */
16839 /* PR 17531: file: 001-505008-0.01. */
16842 printf (_("True\n"));
16845 case 65: /* Tag_also_compatible_with. */
16846 READ_ULEB (val
, p
, end
);
16847 if (val
== 6 /* Tag_CPU_arch. */)
16849 READ_ULEB (val
, p
, end
);
16850 if ((unsigned int) val
>= ARRAY_SIZE (arm_attr_tag_CPU_arch
))
16851 printf ("??? (%d)\n", val
);
16853 printf ("%s\n", arm_attr_tag_CPU_arch
[val
]);
16857 while (p
< end
&& *(p
++) != '\0' /* NUL terminator. */)
16862 printf (_("<unknown: %d>\n"), tag
);
16868 return display_tag_value (-1, p
, end
);
16870 return display_tag_value (0, p
, end
);
16873 assert (attr
->type
& 0x80);
16874 READ_ULEB (val
, p
, end
);
16875 type
= attr
->type
& 0x7f;
16877 printf ("??? (%d)\n", val
);
16879 printf ("%s\n", attr
->table
[val
]);
16884 return display_tag_value (tag
, p
, end
);
16887 static unsigned char *
16888 display_gnu_attribute (unsigned char * p
,
16889 unsigned char * (* display_proc_gnu_attribute
) (unsigned char *, unsigned int, const unsigned char * const),
16890 const unsigned char * const end
)
16895 READ_ULEB (tag
, p
, end
);
16897 /* Tag_compatibility is the only generic GNU attribute defined at
16901 READ_ULEB (val
, p
, end
);
16903 printf (_("flag = %d, vendor = "), val
);
16906 printf (_("<corrupt>\n"));
16907 warn (_("corrupt vendor attribute\n"));
16913 size_t maxlen
= (end
- p
) - 1;
16915 print_symbol ((int) maxlen
, (const char *) p
);
16916 p
+= strnlen ((char *) p
, maxlen
) + 1;
16920 printf (_("<corrupt>"));
16921 p
= (unsigned char *) end
;
16928 if ((tag
& 2) == 0 && display_proc_gnu_attribute
)
16929 return display_proc_gnu_attribute (p
, tag
, end
);
16931 return display_tag_value (tag
, p
, end
);
16934 static unsigned char *
16935 display_m68k_gnu_attribute (unsigned char * p
,
16937 const unsigned char * const end
)
16941 if (tag
== Tag_GNU_M68K_ABI_FP
)
16943 printf (" Tag_GNU_M68K_ABI_FP: ");
16946 printf (_("<corrupt>\n"));
16949 READ_ULEB (val
, p
, end
);
16952 printf ("(%#x), ", val
);
16957 printf (_("unspecified hard/soft float\n"));
16960 printf (_("hard float\n"));
16963 printf (_("soft float\n"));
16969 return display_tag_value (tag
& 1, p
, end
);
16972 static unsigned char *
16973 display_power_gnu_attribute (unsigned char * p
,
16975 const unsigned char * const end
)
16979 if (tag
== Tag_GNU_Power_ABI_FP
)
16981 printf (" Tag_GNU_Power_ABI_FP: ");
16984 printf (_("<corrupt>\n"));
16987 READ_ULEB (val
, p
, end
);
16990 printf ("(%#x), ", val
);
16995 printf (_("unspecified hard/soft float, "));
16998 printf (_("hard float, "));
17001 printf (_("soft float, "));
17004 printf (_("single-precision hard float, "));
17011 printf (_("unspecified long double\n"));
17014 printf (_("128-bit IBM long double\n"));
17017 printf (_("64-bit long double\n"));
17020 printf (_("128-bit IEEE long double\n"));
17026 if (tag
== Tag_GNU_Power_ABI_Vector
)
17028 printf (" Tag_GNU_Power_ABI_Vector: ");
17031 printf (_("<corrupt>\n"));
17034 READ_ULEB (val
, p
, end
);
17037 printf ("(%#x), ", val
);
17042 printf (_("unspecified\n"));
17045 printf (_("generic\n"));
17048 printf ("AltiVec\n");
17057 if (tag
== Tag_GNU_Power_ABI_Struct_Return
)
17059 printf (" Tag_GNU_Power_ABI_Struct_Return: ");
17062 printf (_("<corrupt>\n"));
17065 READ_ULEB (val
, p
, end
);
17068 printf ("(%#x), ", val
);
17073 printf (_("unspecified\n"));
17076 printf ("r3/r4\n");
17079 printf (_("memory\n"));
17088 return display_tag_value (tag
& 1, p
, end
);
17091 static unsigned char *
17092 display_s390_gnu_attribute (unsigned char * p
,
17094 const unsigned char * const end
)
17098 if (tag
== Tag_GNU_S390_ABI_Vector
)
17100 printf (" Tag_GNU_S390_ABI_Vector: ");
17101 READ_ULEB (val
, p
, end
);
17106 printf (_("any\n"));
17109 printf (_("software\n"));
17112 printf (_("hardware\n"));
17115 printf ("??? (%d)\n", val
);
17121 return display_tag_value (tag
& 1, p
, end
);
17125 display_sparc_hwcaps (unsigned int mask
)
17131 if (mask
& ELF_SPARC_HWCAP_MUL32
)
17132 fputs ("mul32", stdout
), first
= false;
17133 if (mask
& ELF_SPARC_HWCAP_DIV32
)
17134 printf ("%sdiv32", first
? "" : "|"), first
= false;
17135 if (mask
& ELF_SPARC_HWCAP_FSMULD
)
17136 printf ("%sfsmuld", first
? "" : "|"), first
= false;
17137 if (mask
& ELF_SPARC_HWCAP_V8PLUS
)
17138 printf ("%sv8plus", first
? "" : "|"), first
= false;
17139 if (mask
& ELF_SPARC_HWCAP_POPC
)
17140 printf ("%spopc", first
? "" : "|"), first
= false;
17141 if (mask
& ELF_SPARC_HWCAP_VIS
)
17142 printf ("%svis", first
? "" : "|"), first
= false;
17143 if (mask
& ELF_SPARC_HWCAP_VIS2
)
17144 printf ("%svis2", first
? "" : "|"), first
= false;
17145 if (mask
& ELF_SPARC_HWCAP_ASI_BLK_INIT
)
17146 printf ("%sASIBlkInit", first
? "" : "|"), first
= false;
17147 if (mask
& ELF_SPARC_HWCAP_FMAF
)
17148 printf ("%sfmaf", first
? "" : "|"), first
= false;
17149 if (mask
& ELF_SPARC_HWCAP_VIS3
)
17150 printf ("%svis3", first
? "" : "|"), first
= false;
17151 if (mask
& ELF_SPARC_HWCAP_HPC
)
17152 printf ("%shpc", first
? "" : "|"), first
= false;
17153 if (mask
& ELF_SPARC_HWCAP_RANDOM
)
17154 printf ("%srandom", first
? "" : "|"), first
= false;
17155 if (mask
& ELF_SPARC_HWCAP_TRANS
)
17156 printf ("%strans", first
? "" : "|"), first
= false;
17157 if (mask
& ELF_SPARC_HWCAP_FJFMAU
)
17158 printf ("%sfjfmau", first
? "" : "|"), first
= false;
17159 if (mask
& ELF_SPARC_HWCAP_IMA
)
17160 printf ("%sima", first
? "" : "|"), first
= false;
17161 if (mask
& ELF_SPARC_HWCAP_ASI_CACHE_SPARING
)
17162 printf ("%scspare", first
? "" : "|"), first
= false;
17165 fputc ('0', stdout
);
17166 fputc ('\n', stdout
);
17170 display_sparc_hwcaps2 (unsigned int mask
)
17176 if (mask
& ELF_SPARC_HWCAP2_FJATHPLUS
)
17177 fputs ("fjathplus", stdout
), first
= false;
17178 if (mask
& ELF_SPARC_HWCAP2_VIS3B
)
17179 printf ("%svis3b", first
? "" : "|"), first
= false;
17180 if (mask
& ELF_SPARC_HWCAP2_ADP
)
17181 printf ("%sadp", first
? "" : "|"), first
= false;
17182 if (mask
& ELF_SPARC_HWCAP2_SPARC5
)
17183 printf ("%ssparc5", first
? "" : "|"), first
= false;
17184 if (mask
& ELF_SPARC_HWCAP2_MWAIT
)
17185 printf ("%smwait", first
? "" : "|"), first
= false;
17186 if (mask
& ELF_SPARC_HWCAP2_XMPMUL
)
17187 printf ("%sxmpmul", first
? "" : "|"), first
= false;
17188 if (mask
& ELF_SPARC_HWCAP2_XMONT
)
17189 printf ("%sxmont2", first
? "" : "|"), first
= false;
17190 if (mask
& ELF_SPARC_HWCAP2_NSEC
)
17191 printf ("%snsec", first
? "" : "|"), first
= false;
17192 if (mask
& ELF_SPARC_HWCAP2_FJATHHPC
)
17193 printf ("%sfjathhpc", first
? "" : "|"), first
= false;
17194 if (mask
& ELF_SPARC_HWCAP2_FJDES
)
17195 printf ("%sfjdes", first
? "" : "|"), first
= false;
17196 if (mask
& ELF_SPARC_HWCAP2_FJAES
)
17197 printf ("%sfjaes", first
? "" : "|"), first
= false;
17200 fputc ('0', stdout
);
17201 fputc ('\n', stdout
);
17204 static unsigned char *
17205 display_sparc_gnu_attribute (unsigned char * p
,
17207 const unsigned char * const end
)
17211 if (tag
== Tag_GNU_Sparc_HWCAPS
)
17213 READ_ULEB (val
, p
, end
);
17214 printf (" Tag_GNU_Sparc_HWCAPS: ");
17215 display_sparc_hwcaps (val
);
17218 if (tag
== Tag_GNU_Sparc_HWCAPS2
)
17220 READ_ULEB (val
, p
, end
);
17221 printf (" Tag_GNU_Sparc_HWCAPS2: ");
17222 display_sparc_hwcaps2 (val
);
17226 return display_tag_value (tag
, p
, end
);
17230 print_mips_fp_abi_value (unsigned int val
)
17234 case Val_GNU_MIPS_ABI_FP_ANY
:
17235 printf (_("Hard or soft float\n"));
17237 case Val_GNU_MIPS_ABI_FP_DOUBLE
:
17238 printf (_("Hard float (double precision)\n"));
17240 case Val_GNU_MIPS_ABI_FP_SINGLE
:
17241 printf (_("Hard float (single precision)\n"));
17243 case Val_GNU_MIPS_ABI_FP_SOFT
:
17244 printf (_("Soft float\n"));
17246 case Val_GNU_MIPS_ABI_FP_OLD_64
:
17247 printf (_("Hard float (MIPS32r2 64-bit FPU 12 callee-saved)\n"));
17249 case Val_GNU_MIPS_ABI_FP_XX
:
17250 printf (_("Hard float (32-bit CPU, Any FPU)\n"));
17252 case Val_GNU_MIPS_ABI_FP_64
:
17253 printf (_("Hard float (32-bit CPU, 64-bit FPU)\n"));
17255 case Val_GNU_MIPS_ABI_FP_64A
:
17256 printf (_("Hard float compat (32-bit CPU, 64-bit FPU)\n"));
17258 case Val_GNU_MIPS_ABI_FP_NAN2008
:
17259 printf (_("NaN 2008 compatibility\n"));
17262 printf ("??? (%d)\n", val
);
17267 static unsigned char *
17268 display_mips_gnu_attribute (unsigned char * p
,
17270 const unsigned char * const end
)
17272 if (tag
== Tag_GNU_MIPS_ABI_FP
)
17276 printf (" Tag_GNU_MIPS_ABI_FP: ");
17277 READ_ULEB (val
, p
, end
);
17278 print_mips_fp_abi_value (val
);
17282 if (tag
== Tag_GNU_MIPS_ABI_MSA
)
17286 printf (" Tag_GNU_MIPS_ABI_MSA: ");
17287 READ_ULEB (val
, p
, end
);
17291 case Val_GNU_MIPS_ABI_MSA_ANY
:
17292 printf (_("Any MSA or not\n"));
17294 case Val_GNU_MIPS_ABI_MSA_128
:
17295 printf (_("128-bit MSA\n"));
17298 printf ("??? (%d)\n", val
);
17304 return display_tag_value (tag
& 1, p
, end
);
17307 static unsigned char *
17308 display_tic6x_attribute (unsigned char * p
,
17309 const unsigned char * const end
)
17314 READ_ULEB (tag
, p
, end
);
17319 printf (" Tag_ISA: ");
17320 READ_ULEB (val
, p
, end
);
17324 case C6XABI_Tag_ISA_none
:
17325 printf (_("None\n"));
17327 case C6XABI_Tag_ISA_C62X
:
17330 case C6XABI_Tag_ISA_C67X
:
17333 case C6XABI_Tag_ISA_C67XP
:
17334 printf ("C67x+\n");
17336 case C6XABI_Tag_ISA_C64X
:
17339 case C6XABI_Tag_ISA_C64XP
:
17340 printf ("C64x+\n");
17342 case C6XABI_Tag_ISA_C674X
:
17343 printf ("C674x\n");
17346 printf ("??? (%d)\n", val
);
17351 case Tag_ABI_wchar_t
:
17352 printf (" Tag_ABI_wchar_t: ");
17353 READ_ULEB (val
, p
, end
);
17357 printf (_("Not used\n"));
17360 printf (_("2 bytes\n"));
17363 printf (_("4 bytes\n"));
17366 printf ("??? (%d)\n", val
);
17371 case Tag_ABI_stack_align_needed
:
17372 printf (" Tag_ABI_stack_align_needed: ");
17373 READ_ULEB (val
, p
, end
);
17377 printf (_("8-byte\n"));
17380 printf (_("16-byte\n"));
17383 printf ("??? (%d)\n", val
);
17388 case Tag_ABI_stack_align_preserved
:
17389 READ_ULEB (val
, p
, end
);
17390 printf (" Tag_ABI_stack_align_preserved: ");
17394 printf (_("8-byte\n"));
17397 printf (_("16-byte\n"));
17400 printf ("??? (%d)\n", val
);
17406 READ_ULEB (val
, p
, end
);
17407 printf (" Tag_ABI_DSBT: ");
17411 printf (_("DSBT addressing not used\n"));
17414 printf (_("DSBT addressing used\n"));
17417 printf ("??? (%d)\n", val
);
17423 READ_ULEB (val
, p
, end
);
17424 printf (" Tag_ABI_PID: ");
17428 printf (_("Data addressing position-dependent\n"));
17431 printf (_("Data addressing position-independent, GOT near DP\n"));
17434 printf (_("Data addressing position-independent, GOT far from DP\n"));
17437 printf ("??? (%d)\n", val
);
17443 READ_ULEB (val
, p
, end
);
17444 printf (" Tag_ABI_PIC: ");
17448 printf (_("Code addressing position-dependent\n"));
17451 printf (_("Code addressing position-independent\n"));
17454 printf ("??? (%d)\n", val
);
17459 case Tag_ABI_array_object_alignment
:
17460 READ_ULEB (val
, p
, end
);
17461 printf (" Tag_ABI_array_object_alignment: ");
17465 printf (_("8-byte\n"));
17468 printf (_("4-byte\n"));
17471 printf (_("16-byte\n"));
17474 printf ("??? (%d)\n", val
);
17479 case Tag_ABI_array_object_align_expected
:
17480 READ_ULEB (val
, p
, end
);
17481 printf (" Tag_ABI_array_object_align_expected: ");
17485 printf (_("8-byte\n"));
17488 printf (_("4-byte\n"));
17491 printf (_("16-byte\n"));
17494 printf ("??? (%d)\n", val
);
17499 case Tag_ABI_compatibility
:
17501 READ_ULEB (val
, p
, end
);
17502 printf (" Tag_ABI_compatibility: ");
17503 printf (_("flag = %d, vendor = "), val
);
17506 size_t maxlen
= (end
- p
) - 1;
17508 print_symbol ((int) maxlen
, (const char *) p
);
17509 p
+= strnlen ((char *) p
, maxlen
) + 1;
17513 printf (_("<corrupt>"));
17514 p
= (unsigned char *) end
;
17520 case Tag_ABI_conformance
:
17522 printf (" Tag_ABI_conformance: \"");
17525 size_t maxlen
= (end
- p
) - 1;
17527 print_symbol ((int) maxlen
, (const char *) p
);
17528 p
+= strnlen ((char *) p
, maxlen
) + 1;
17532 printf (_("<corrupt>"));
17533 p
= (unsigned char *) end
;
17540 return display_tag_value (tag
, p
, end
);
17544 display_raw_attribute (unsigned char * p
, unsigned char const * const end
)
17546 unsigned long addr
= 0;
17547 size_t bytes
= end
- p
;
17554 int lbytes
= (bytes
> 16 ? 16 : bytes
);
17556 printf (" 0x%8.8lx ", addr
);
17558 for (j
= 0; j
< 16; j
++)
17561 printf ("%2.2x", p
[j
]);
17569 for (j
= 0; j
< lbytes
; j
++)
17572 if (k
>= ' ' && k
< 0x7f)
17588 static unsigned char *
17589 display_msp430_attribute (unsigned char * p
,
17590 const unsigned char * const end
)
17595 READ_ULEB (tag
, p
, end
);
17599 case OFBA_MSPABI_Tag_ISA
:
17600 printf (" Tag_ISA: ");
17601 READ_ULEB (val
, p
, end
);
17604 case 0: printf (_("None\n")); break;
17605 case 1: printf (_("MSP430\n")); break;
17606 case 2: printf (_("MSP430X\n")); break;
17607 default: printf ("??? (%d)\n", val
); break;
17611 case OFBA_MSPABI_Tag_Code_Model
:
17612 printf (" Tag_Code_Model: ");
17613 READ_ULEB (val
, p
, end
);
17616 case 0: printf (_("None\n")); break;
17617 case 1: printf (_("Small\n")); break;
17618 case 2: printf (_("Large\n")); break;
17619 default: printf ("??? (%d)\n", val
); break;
17623 case OFBA_MSPABI_Tag_Data_Model
:
17624 printf (" Tag_Data_Model: ");
17625 READ_ULEB (val
, p
, end
);
17628 case 0: printf (_("None\n")); break;
17629 case 1: printf (_("Small\n")); break;
17630 case 2: printf (_("Large\n")); break;
17631 case 3: printf (_("Restricted Large\n")); break;
17632 default: printf ("??? (%d)\n", val
); break;
17637 printf (_(" <unknown tag %d>: "), tag
);
17644 size_t maxlen
= (end
- p
) - 1;
17646 print_symbol ((int) maxlen
, (const char *) p
);
17647 p
+= strnlen ((char *) p
, maxlen
) + 1;
17651 printf (_("<corrupt>"));
17652 p
= (unsigned char *) end
;
17658 READ_ULEB (val
, p
, end
);
17659 printf ("%d (0x%x)\n", val
, val
);
17668 static unsigned char *
17669 display_msp430_gnu_attribute (unsigned char * p
,
17671 const unsigned char * const end
)
17673 if (tag
== Tag_GNU_MSP430_Data_Region
)
17677 printf (" Tag_GNU_MSP430_Data_Region: ");
17678 READ_ULEB (val
, p
, end
);
17682 case Val_GNU_MSP430_Data_Region_Any
:
17683 printf (_("Any Region\n"));
17685 case Val_GNU_MSP430_Data_Region_Lower
:
17686 printf (_("Lower Region Only\n"));
17689 printf ("??? (%u)\n", val
);
17693 return display_tag_value (tag
& 1, p
, end
);
17696 struct riscv_attr_tag_t
{
17701 static struct riscv_attr_tag_t riscv_attr_tag
[] =
17703 #define T(tag) {"Tag_RISCV_" #tag, Tag_RISCV_##tag}
17706 T(priv_spec_minor
),
17707 T(priv_spec_revision
),
17708 T(unaligned_access
),
17713 static unsigned char *
17714 display_riscv_attribute (unsigned char *p
,
17715 const unsigned char * const end
)
17719 struct riscv_attr_tag_t
*attr
= NULL
;
17722 READ_ULEB (tag
, p
, end
);
17724 /* Find the name of attribute. */
17725 for (i
= 0; i
< ARRAY_SIZE (riscv_attr_tag
); i
++)
17727 if (riscv_attr_tag
[i
].tag
== tag
)
17729 attr
= &riscv_attr_tag
[i
];
17735 printf (" %s: ", attr
->name
);
17737 return display_tag_value (tag
, p
, end
);
17741 case Tag_RISCV_priv_spec
:
17742 case Tag_RISCV_priv_spec_minor
:
17743 case Tag_RISCV_priv_spec_revision
:
17744 READ_ULEB (val
, p
, end
);
17745 printf (_("%u\n"), val
);
17747 case Tag_RISCV_unaligned_access
:
17748 READ_ULEB (val
, p
, end
);
17752 printf (_("No unaligned access\n"));
17755 printf (_("Unaligned access\n"));
17759 case Tag_RISCV_stack_align
:
17760 READ_ULEB (val
, p
, end
);
17761 printf (_("%u-bytes\n"), val
);
17763 case Tag_RISCV_arch
:
17764 p
= display_tag_value (-1, p
, end
);
17767 return display_tag_value (tag
, p
, end
);
17773 static unsigned char *
17774 display_csky_attribute (unsigned char * p
,
17775 const unsigned char * const end
)
17779 READ_ULEB (tag
, p
, end
);
17781 if (tag
>= Tag_CSKY_MAX
)
17783 return display_tag_value (-1, p
, end
);
17788 case Tag_CSKY_ARCH_NAME
:
17789 printf (" Tag_CSKY_ARCH_NAME:\t\t");
17790 return display_tag_value (-1, p
, end
);
17791 case Tag_CSKY_CPU_NAME
:
17792 printf (" Tag_CSKY_CPU_NAME:\t\t");
17793 return display_tag_value (-1, p
, end
);
17795 case Tag_CSKY_ISA_FLAGS
:
17796 printf (" Tag_CSKY_ISA_FLAGS:\t\t");
17797 return display_tag_value (0, p
, end
);
17798 case Tag_CSKY_ISA_EXT_FLAGS
:
17799 printf (" Tag_CSKY_ISA_EXT_FLAGS:\t");
17800 return display_tag_value (0, p
, end
);
17802 case Tag_CSKY_DSP_VERSION
:
17803 printf (" Tag_CSKY_DSP_VERSION:\t\t");
17804 READ_ULEB (val
, p
, end
);
17805 if (val
== VAL_CSKY_DSP_VERSION_EXTENSION
)
17806 printf ("DSP Extension\n");
17807 else if (val
== VAL_CSKY_DSP_VERSION_2
)
17808 printf ("DSP 2.0\n");
17811 case Tag_CSKY_VDSP_VERSION
:
17812 printf (" Tag_CSKY_VDSP_VERSION:\t");
17813 READ_ULEB (val
, p
, end
);
17814 printf ("VDSP Version %d\n", val
);
17817 case Tag_CSKY_FPU_VERSION
:
17818 printf (" Tag_CSKY_FPU_VERSION:\t\t");
17819 READ_ULEB (val
, p
, end
);
17820 if (val
== VAL_CSKY_FPU_VERSION_1
)
17821 printf ("ABIV1 FPU Version 1\n");
17822 else if (val
== VAL_CSKY_FPU_VERSION_2
)
17823 printf ("FPU Version 2\n");
17826 case Tag_CSKY_FPU_ABI
:
17827 printf (" Tag_CSKY_FPU_ABI:\t\t");
17828 READ_ULEB (val
, p
, end
);
17829 if (val
== VAL_CSKY_FPU_ABI_HARD
)
17831 else if (val
== VAL_CSKY_FPU_ABI_SOFTFP
)
17832 printf ("SoftFP\n");
17833 else if (val
== VAL_CSKY_FPU_ABI_SOFT
)
17836 case Tag_CSKY_FPU_ROUNDING
:
17837 READ_ULEB (val
, p
, end
);
17840 printf (" Tag_CSKY_FPU_ROUNDING:\t");
17841 printf ("Needed\n");
17844 case Tag_CSKY_FPU_DENORMAL
:
17845 READ_ULEB (val
, p
, end
);
17848 printf (" Tag_CSKY_FPU_DENORMAL:\t");
17849 printf ("Needed\n");
17852 case Tag_CSKY_FPU_Exception
:
17853 READ_ULEB (val
, p
, end
);
17856 printf (" Tag_CSKY_FPU_Exception:\t");
17857 printf ("Needed\n");
17860 case Tag_CSKY_FPU_NUMBER_MODULE
:
17861 printf (" Tag_CSKY_FPU_NUMBER_MODULE:\t");
17862 return display_tag_value (-1, p
, end
);
17863 case Tag_CSKY_FPU_HARDFP
:
17864 printf (" Tag_CSKY_FPU_HARDFP:\t\t");
17865 READ_ULEB (val
, p
, end
);
17866 if (val
& VAL_CSKY_FPU_HARDFP_HALF
)
17868 if (val
& VAL_CSKY_FPU_HARDFP_SINGLE
)
17869 printf (" Single");
17870 if (val
& VAL_CSKY_FPU_HARDFP_DOUBLE
)
17871 printf (" Double");
17875 return display_tag_value (tag
, p
, end
);
17881 process_attributes (Filedata
* filedata
,
17882 const char * public_name
,
17883 unsigned int proc_type
,
17884 unsigned char * (* display_pub_attribute
) (unsigned char *, const unsigned char * const),
17885 unsigned char * (* display_proc_gnu_attribute
) (unsigned char *, unsigned int, const unsigned char * const))
17887 Elf_Internal_Shdr
* sect
;
17891 /* Find the section header so that we get the size. */
17892 for (i
= 0, sect
= filedata
->section_headers
;
17893 i
< filedata
->file_header
.e_shnum
;
17896 unsigned char * contents
;
17899 if (sect
->sh_type
!= proc_type
&& sect
->sh_type
!= SHT_GNU_ATTRIBUTES
)
17902 contents
= (unsigned char *) get_data (NULL
, filedata
, sect
->sh_offset
, 1,
17903 sect
->sh_size
, _("attributes"));
17904 if (contents
== NULL
)
17911 /* The first character is the version of the attributes.
17912 Currently only version 1, (aka 'A') is recognised here. */
17915 printf (_("Unknown attributes version '%c'(%d) - expecting 'A'\n"), *p
, *p
);
17920 bfd_vma section_len
;
17922 section_len
= sect
->sh_size
- 1;
17925 while (section_len
> 0)
17928 unsigned int namelen
;
17929 bool public_section
;
17932 if (section_len
<= 4)
17934 error (_("Tag section ends prematurely\n"));
17938 attr_len
= byte_get (p
, 4);
17941 if (attr_len
> section_len
)
17943 error (_("Bad attribute length (%u > %u)\n"),
17944 (unsigned) attr_len
, (unsigned) section_len
);
17945 attr_len
= section_len
;
17948 /* PR 17531: file: 001-101425-0.004 */
17949 else if (attr_len
< 5)
17951 error (_("Attribute length of %u is too small\n"), (unsigned) attr_len
);
17956 section_len
-= attr_len
;
17959 namelen
= strnlen ((char *) p
, attr_len
) + 1;
17960 if (namelen
== 0 || namelen
>= attr_len
)
17962 error (_("Corrupt attribute section name\n"));
17967 printf (_("Attribute Section: "));
17968 print_symbol (INT_MAX
, (const char *) p
);
17971 if (public_name
&& streq ((char *) p
, public_name
))
17972 public_section
= true;
17974 public_section
= false;
17976 if (streq ((char *) p
, "gnu"))
17977 gnu_section
= true;
17979 gnu_section
= false;
17982 attr_len
-= namelen
;
17984 while (attr_len
> 0 && p
< contents
+ sect
->sh_size
)
17989 unsigned char * end
;
17991 /* PR binutils/17531: Safe handling of corrupt files. */
17994 error (_("Unused bytes at end of section\n"));
18001 size
= byte_get (p
, 4);
18002 if (size
> attr_len
)
18004 error (_("Bad subsection length (%u > %u)\n"),
18005 (unsigned) size
, (unsigned) attr_len
);
18009 /* PR binutils/17531: Safe handling of corrupt files. */
18012 error (_("Bad subsection length (%u < 6)\n"),
18020 end
= p
+ size
- 1;
18021 assert (end
<= contents
+ sect
->sh_size
);
18027 printf (_("File Attributes\n"));
18030 printf (_("Section Attributes:"));
18033 printf (_("Symbol Attributes:"));
18034 /* Fall through. */
18038 READ_ULEB (val
, p
, end
);
18041 printf (" %d", val
);
18046 printf (_("Unknown tag: %d\n"), tag
);
18047 public_section
= false;
18051 if (public_section
&& display_pub_attribute
!= NULL
)
18054 p
= display_pub_attribute (p
, end
);
18057 else if (gnu_section
&& display_proc_gnu_attribute
!= NULL
)
18060 p
= display_gnu_attribute (p
,
18061 display_proc_gnu_attribute
,
18067 printf (_(" Unknown attribute:\n"));
18068 display_raw_attribute (p
, end
);
18083 /* DATA points to the contents of a MIPS GOT that starts at VMA PLTGOT.
18084 Print the Address, Access and Initial fields of an entry at VMA ADDR
18085 and return the VMA of the next entry, or -1 if there was a problem.
18086 Does not read from DATA_END or beyond. */
18089 print_mips_got_entry (unsigned char * data
, bfd_vma pltgot
, bfd_vma addr
,
18090 unsigned char * data_end
)
18093 print_vma (addr
, LONG_HEX
);
18095 if (addr
< pltgot
+ 0xfff0)
18096 printf ("%6d(gp)", (int) (addr
- pltgot
- 0x7ff0));
18098 printf ("%10s", "");
18101 printf ("%*s", is_32bit_elf
? 8 : 16, _("<unknown>"));
18105 unsigned char * from
= data
+ addr
- pltgot
;
18107 if (from
+ (is_32bit_elf
? 4 : 8) > data_end
)
18109 warn (_("MIPS GOT entry extends beyond the end of available data\n"));
18110 printf ("%*s", is_32bit_elf
? 8 : 16, _("<corrupt>"));
18111 return (bfd_vma
) -1;
18115 entry
= byte_get (data
+ addr
- pltgot
, is_32bit_elf
? 4 : 8);
18116 print_vma (entry
, LONG_HEX
);
18119 return addr
+ (is_32bit_elf
? 4 : 8);
18122 /* DATA points to the contents of a MIPS PLT GOT that starts at VMA
18123 PLTGOT. Print the Address and Initial fields of an entry at VMA
18124 ADDR and return the VMA of the next entry. */
18127 print_mips_pltgot_entry (unsigned char * data
, bfd_vma pltgot
, bfd_vma addr
)
18130 print_vma (addr
, LONG_HEX
);
18133 printf ("%*s", is_32bit_elf
? 8 : 16, _("<unknown>"));
18138 entry
= byte_get (data
+ addr
- pltgot
, is_32bit_elf
? 4 : 8);
18139 print_vma (entry
, LONG_HEX
);
18141 return addr
+ (is_32bit_elf
? 4 : 8);
18145 print_mips_ases (unsigned int mask
)
18147 if (mask
& AFL_ASE_DSP
)
18148 fputs ("\n\tDSP ASE", stdout
);
18149 if (mask
& AFL_ASE_DSPR2
)
18150 fputs ("\n\tDSP R2 ASE", stdout
);
18151 if (mask
& AFL_ASE_DSPR3
)
18152 fputs ("\n\tDSP R3 ASE", stdout
);
18153 if (mask
& AFL_ASE_EVA
)
18154 fputs ("\n\tEnhanced VA Scheme", stdout
);
18155 if (mask
& AFL_ASE_MCU
)
18156 fputs ("\n\tMCU (MicroController) ASE", stdout
);
18157 if (mask
& AFL_ASE_MDMX
)
18158 fputs ("\n\tMDMX ASE", stdout
);
18159 if (mask
& AFL_ASE_MIPS3D
)
18160 fputs ("\n\tMIPS-3D ASE", stdout
);
18161 if (mask
& AFL_ASE_MT
)
18162 fputs ("\n\tMT ASE", stdout
);
18163 if (mask
& AFL_ASE_SMARTMIPS
)
18164 fputs ("\n\tSmartMIPS ASE", stdout
);
18165 if (mask
& AFL_ASE_VIRT
)
18166 fputs ("\n\tVZ ASE", stdout
);
18167 if (mask
& AFL_ASE_MSA
)
18168 fputs ("\n\tMSA ASE", stdout
);
18169 if (mask
& AFL_ASE_MIPS16
)
18170 fputs ("\n\tMIPS16 ASE", stdout
);
18171 if (mask
& AFL_ASE_MICROMIPS
)
18172 fputs ("\n\tMICROMIPS ASE", stdout
);
18173 if (mask
& AFL_ASE_XPA
)
18174 fputs ("\n\tXPA ASE", stdout
);
18175 if (mask
& AFL_ASE_MIPS16E2
)
18176 fputs ("\n\tMIPS16e2 ASE", stdout
);
18177 if (mask
& AFL_ASE_CRC
)
18178 fputs ("\n\tCRC ASE", stdout
);
18179 if (mask
& AFL_ASE_GINV
)
18180 fputs ("\n\tGINV ASE", stdout
);
18181 if (mask
& AFL_ASE_LOONGSON_MMI
)
18182 fputs ("\n\tLoongson MMI ASE", stdout
);
18183 if (mask
& AFL_ASE_LOONGSON_CAM
)
18184 fputs ("\n\tLoongson CAM ASE", stdout
);
18185 if (mask
& AFL_ASE_LOONGSON_EXT
)
18186 fputs ("\n\tLoongson EXT ASE", stdout
);
18187 if (mask
& AFL_ASE_LOONGSON_EXT2
)
18188 fputs ("\n\tLoongson EXT2 ASE", stdout
);
18190 fprintf (stdout
, "\n\t%s", _("None"));
18191 else if ((mask
& ~AFL_ASE_MASK
) != 0)
18192 fprintf (stdout
, "\n\t%s (%x)", _("Unknown"), mask
& ~AFL_ASE_MASK
);
18196 print_mips_isa_ext (unsigned int isa_ext
)
18201 fputs (_("None"), stdout
);
18204 fputs ("RMI XLR", stdout
);
18206 case AFL_EXT_OCTEON3
:
18207 fputs ("Cavium Networks Octeon3", stdout
);
18209 case AFL_EXT_OCTEON2
:
18210 fputs ("Cavium Networks Octeon2", stdout
);
18212 case AFL_EXT_OCTEONP
:
18213 fputs ("Cavium Networks OcteonP", stdout
);
18215 case AFL_EXT_OCTEON
:
18216 fputs ("Cavium Networks Octeon", stdout
);
18219 fputs ("Toshiba R5900", stdout
);
18222 fputs ("MIPS R4650", stdout
);
18225 fputs ("LSI R4010", stdout
);
18228 fputs ("NEC VR4100", stdout
);
18231 fputs ("Toshiba R3900", stdout
);
18233 case AFL_EXT_10000
:
18234 fputs ("MIPS R10000", stdout
);
18237 fputs ("Broadcom SB-1", stdout
);
18240 fputs ("NEC VR4111/VR4181", stdout
);
18243 fputs ("NEC VR4120", stdout
);
18246 fputs ("NEC VR5400", stdout
);
18249 fputs ("NEC VR5500", stdout
);
18251 case AFL_EXT_LOONGSON_2E
:
18252 fputs ("ST Microelectronics Loongson 2E", stdout
);
18254 case AFL_EXT_LOONGSON_2F
:
18255 fputs ("ST Microelectronics Loongson 2F", stdout
);
18257 case AFL_EXT_INTERAPTIV_MR2
:
18258 fputs ("Imagination interAptiv MR2", stdout
);
18261 fprintf (stdout
, "%s (%d)", _("Unknown"), isa_ext
);
18266 get_mips_reg_size (int reg_size
)
18268 return (reg_size
== AFL_REG_NONE
) ? 0
18269 : (reg_size
== AFL_REG_32
) ? 32
18270 : (reg_size
== AFL_REG_64
) ? 64
18271 : (reg_size
== AFL_REG_128
) ? 128
18276 process_mips_specific (Filedata
* filedata
)
18278 Elf_Internal_Dyn
* entry
;
18279 Elf_Internal_Shdr
*sect
= NULL
;
18280 size_t liblist_offset
= 0;
18281 size_t liblistno
= 0;
18282 size_t conflictsno
= 0;
18283 size_t options_offset
= 0;
18284 size_t conflicts_offset
= 0;
18285 size_t pltrelsz
= 0;
18287 bfd_vma pltgot
= 0;
18288 bfd_vma mips_pltgot
= 0;
18289 bfd_vma jmprel
= 0;
18290 bfd_vma local_gotno
= 0;
18291 bfd_vma gotsym
= 0;
18292 bfd_vma symtabno
= 0;
18295 if (! process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
18296 display_mips_gnu_attribute
))
18299 sect
= find_section (filedata
, ".MIPS.abiflags");
18303 Elf_External_ABIFlags_v0
*abiflags_ext
;
18304 Elf_Internal_ABIFlags_v0 abiflags_in
;
18306 if (sizeof (Elf_External_ABIFlags_v0
) != sect
->sh_size
)
18308 error (_("Corrupt MIPS ABI Flags section.\n"));
18313 abiflags_ext
= get_data (NULL
, filedata
, sect
->sh_offset
, 1,
18314 sect
->sh_size
, _("MIPS ABI Flags section"));
18317 abiflags_in
.version
= BYTE_GET (abiflags_ext
->version
);
18318 abiflags_in
.isa_level
= BYTE_GET (abiflags_ext
->isa_level
);
18319 abiflags_in
.isa_rev
= BYTE_GET (abiflags_ext
->isa_rev
);
18320 abiflags_in
.gpr_size
= BYTE_GET (abiflags_ext
->gpr_size
);
18321 abiflags_in
.cpr1_size
= BYTE_GET (abiflags_ext
->cpr1_size
);
18322 abiflags_in
.cpr2_size
= BYTE_GET (abiflags_ext
->cpr2_size
);
18323 abiflags_in
.fp_abi
= BYTE_GET (abiflags_ext
->fp_abi
);
18324 abiflags_in
.isa_ext
= BYTE_GET (abiflags_ext
->isa_ext
);
18325 abiflags_in
.ases
= BYTE_GET (abiflags_ext
->ases
);
18326 abiflags_in
.flags1
= BYTE_GET (abiflags_ext
->flags1
);
18327 abiflags_in
.flags2
= BYTE_GET (abiflags_ext
->flags2
);
18329 printf ("\nMIPS ABI Flags Version: %d\n", abiflags_in
.version
);
18330 printf ("\nISA: MIPS%d", abiflags_in
.isa_level
);
18331 if (abiflags_in
.isa_rev
> 1)
18332 printf ("r%d", abiflags_in
.isa_rev
);
18333 printf ("\nGPR size: %d",
18334 get_mips_reg_size (abiflags_in
.gpr_size
));
18335 printf ("\nCPR1 size: %d",
18336 get_mips_reg_size (abiflags_in
.cpr1_size
));
18337 printf ("\nCPR2 size: %d",
18338 get_mips_reg_size (abiflags_in
.cpr2_size
));
18339 fputs ("\nFP ABI: ", stdout
);
18340 print_mips_fp_abi_value (abiflags_in
.fp_abi
);
18341 fputs ("ISA Extension: ", stdout
);
18342 print_mips_isa_ext (abiflags_in
.isa_ext
);
18343 fputs ("\nASEs:", stdout
);
18344 print_mips_ases (abiflags_in
.ases
);
18345 printf ("\nFLAGS 1: %8.8lx", abiflags_in
.flags1
);
18346 printf ("\nFLAGS 2: %8.8lx", abiflags_in
.flags2
);
18347 fputc ('\n', stdout
);
18348 free (abiflags_ext
);
18353 /* We have a lot of special sections. Thanks SGI! */
18354 if (filedata
->dynamic_section
== NULL
)
18356 /* No dynamic information available. See if there is static GOT. */
18357 sect
= find_section (filedata
, ".got");
18360 unsigned char *data_end
;
18361 unsigned char *data
;
18365 pltgot
= sect
->sh_addr
;
18368 addr_size
= (is_32bit_elf
? 4 : 8);
18369 end
= pltgot
+ sect
->sh_size
;
18371 data
= (unsigned char *) get_data (NULL
, filedata
, sect
->sh_offset
,
18373 _("Global Offset Table data"));
18374 /* PR 12855: Null data is handled gracefully throughout. */
18375 data_end
= data
+ (end
- pltgot
);
18377 printf (_("\nStatic GOT:\n"));
18378 printf (_(" Canonical gp value: "));
18379 print_vma (ent
+ 0x7ff0, LONG_HEX
);
18382 /* In a dynamic binary GOT[0] is reserved for the dynamic
18383 loader to store the lazy resolver pointer, however in
18384 a static binary it may well have been omitted and GOT
18385 reduced to a table of addresses.
18386 PR 21344: Check for the entry being fully available
18387 before fetching it. */
18389 && data
+ ent
- pltgot
+ addr_size
<= data_end
18390 && byte_get (data
+ ent
- pltgot
, addr_size
) == 0)
18392 printf (_(" Reserved entries:\n"));
18393 printf (_(" %*s %10s %*s\n"),
18394 addr_size
* 2, _("Address"), _("Access"),
18395 addr_size
* 2, _("Value"));
18396 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
18398 if (ent
== (bfd_vma
) -1)
18399 goto sgot_print_fail
;
18401 /* Check for the MSB of GOT[1] being set, identifying a
18402 GNU object. This entry will be used by some runtime
18403 loaders, to store the module pointer. Otherwise this
18404 is an ordinary local entry.
18405 PR 21344: Check for the entry being fully available
18406 before fetching it. */
18408 && data
+ ent
- pltgot
+ addr_size
<= data_end
18409 && (byte_get (data
+ ent
- pltgot
, addr_size
)
18410 >> (addr_size
* 8 - 1)) != 0)
18412 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
18414 if (ent
== (bfd_vma
) -1)
18415 goto sgot_print_fail
;
18420 if (data
!= NULL
&& ent
< end
)
18422 printf (_(" Local entries:\n"));
18423 printf (" %*s %10s %*s\n",
18424 addr_size
* 2, _("Address"), _("Access"),
18425 addr_size
* 2, _("Value"));
18428 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
18430 if (ent
== (bfd_vma
) -1)
18431 goto sgot_print_fail
;
18442 for (entry
= filedata
->dynamic_section
;
18443 /* PR 17531 file: 012-50589-0.004. */
18444 (entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
18445 && entry
->d_tag
!= DT_NULL
);
18447 switch (entry
->d_tag
)
18449 case DT_MIPS_LIBLIST
:
18451 = offset_from_vma (filedata
, entry
->d_un
.d_val
,
18452 liblistno
* sizeof (Elf32_External_Lib
));
18454 case DT_MIPS_LIBLISTNO
:
18455 liblistno
= entry
->d_un
.d_val
;
18457 case DT_MIPS_OPTIONS
:
18458 options_offset
= offset_from_vma (filedata
, entry
->d_un
.d_val
, 0);
18460 case DT_MIPS_CONFLICT
:
18462 = offset_from_vma (filedata
, entry
->d_un
.d_val
,
18463 conflictsno
* sizeof (Elf32_External_Conflict
));
18465 case DT_MIPS_CONFLICTNO
:
18466 conflictsno
= entry
->d_un
.d_val
;
18469 pltgot
= entry
->d_un
.d_ptr
;
18471 case DT_MIPS_LOCAL_GOTNO
:
18472 local_gotno
= entry
->d_un
.d_val
;
18474 case DT_MIPS_GOTSYM
:
18475 gotsym
= entry
->d_un
.d_val
;
18477 case DT_MIPS_SYMTABNO
:
18478 symtabno
= entry
->d_un
.d_val
;
18480 case DT_MIPS_PLTGOT
:
18481 mips_pltgot
= entry
->d_un
.d_ptr
;
18484 pltrel
= entry
->d_un
.d_val
;
18487 pltrelsz
= entry
->d_un
.d_val
;
18490 jmprel
= entry
->d_un
.d_ptr
;
18496 if (liblist_offset
!= 0 && liblistno
!= 0 && do_dynamic
)
18498 Elf32_External_Lib
* elib
;
18501 elib
= (Elf32_External_Lib
*) get_data (NULL
, filedata
, liblist_offset
,
18502 sizeof (Elf32_External_Lib
),
18504 _("liblist section data"));
18507 printf (ngettext ("\nSection '.liblist' contains %lu entry:\n",
18508 "\nSection '.liblist' contains %lu entries:\n",
18509 (unsigned long) liblistno
),
18510 (unsigned long) liblistno
);
18511 fputs (_(" Library Time Stamp Checksum Version Flags\n"),
18514 for (cnt
= 0; cnt
< liblistno
; ++cnt
)
18521 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
18522 atime
= BYTE_GET (elib
[cnt
].l_time_stamp
);
18523 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
18524 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
18525 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
18527 tmp
= gmtime (&atime
);
18528 snprintf (timebuf
, sizeof (timebuf
),
18529 "%04u-%02u-%02uT%02u:%02u:%02u",
18530 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
18531 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
18533 printf ("%3lu: ", (unsigned long) cnt
);
18534 if (valid_dynamic_name (filedata
, liblist
.l_name
))
18535 print_symbol (20, get_dynamic_name (filedata
, liblist
.l_name
));
18537 printf (_("<corrupt: %9ld>"), liblist
.l_name
);
18538 printf (" %s %#10lx %-7ld", timebuf
, liblist
.l_checksum
,
18539 liblist
.l_version
);
18541 if (liblist
.l_flags
== 0)
18545 static const struct
18552 { " EXACT_MATCH", LL_EXACT_MATCH
},
18553 { " IGNORE_INT_VER", LL_IGNORE_INT_VER
},
18554 { " REQUIRE_MINOR", LL_REQUIRE_MINOR
},
18555 { " EXPORTS", LL_EXPORTS
},
18556 { " DELAY_LOAD", LL_DELAY_LOAD
},
18557 { " DELTA", LL_DELTA
}
18559 int flags
= liblist
.l_flags
;
18562 for (fcnt
= 0; fcnt
< ARRAY_SIZE (l_flags_vals
); ++fcnt
)
18563 if ((flags
& l_flags_vals
[fcnt
].bit
) != 0)
18565 fputs (l_flags_vals
[fcnt
].name
, stdout
);
18566 flags
^= l_flags_vals
[fcnt
].bit
;
18569 printf (" %#x", (unsigned int) flags
);
18581 if (options_offset
!= 0)
18583 Elf_External_Options
* eopt
;
18587 /* Find the section header so that we get the size. */
18588 sect
= find_section_by_type (filedata
, SHT_MIPS_OPTIONS
);
18589 /* PR 17533 file: 012-277276-0.004. */
18592 error (_("No MIPS_OPTIONS header found\n"));
18596 if (sect
->sh_size
< sizeof (* eopt
))
18598 error (_("The MIPS options section is too small.\n"));
18602 eopt
= (Elf_External_Options
*) get_data (NULL
, filedata
, options_offset
, 1,
18603 sect
->sh_size
, _("options"));
18606 Elf_Internal_Options option
;
18609 while (offset
<= sect
->sh_size
- sizeof (* eopt
))
18611 Elf_External_Options
* eoption
;
18612 unsigned int optsize
;
18614 eoption
= (Elf_External_Options
*) ((char *) eopt
+ offset
);
18616 optsize
= BYTE_GET (eoption
->size
);
18618 /* PR 17531: file: ffa0fa3b. */
18619 if (optsize
< sizeof (* eopt
)
18620 || optsize
> sect
->sh_size
- offset
)
18622 error (_("Invalid size (%u) for MIPS option\n"),
18631 printf (ngettext ("\nSection '%s' contains %d entry:\n",
18632 "\nSection '%s' contains %d entries:\n",
18634 printable_section_name (filedata
, sect
), cnt
);
18640 Elf_External_Options
* eoption
;
18642 eoption
= (Elf_External_Options
*) ((char *) eopt
+ offset
);
18644 option
.kind
= BYTE_GET (eoption
->kind
);
18645 option
.size
= BYTE_GET (eoption
->size
);
18646 option
.section
= BYTE_GET (eoption
->section
);
18647 option
.info
= BYTE_GET (eoption
->info
);
18649 switch (option
.kind
)
18652 /* This shouldn't happen. */
18653 printf (" NULL %" PRId16
" %" PRIx32
,
18654 option
.section
, option
.info
);
18658 printf (" REGINFO ");
18659 if (filedata
->file_header
.e_machine
== EM_MIPS
)
18661 Elf32_External_RegInfo
* ereg
;
18662 Elf32_RegInfo reginfo
;
18665 if (option
.size
< (sizeof (Elf_External_Options
)
18666 + sizeof (Elf32_External_RegInfo
)))
18668 printf (_("<corrupt>\n"));
18669 error (_("Truncated MIPS REGINFO option\n"));
18674 ereg
= (Elf32_External_RegInfo
*) (eoption
+ 1);
18676 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
18677 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
18678 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
18679 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
18680 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
18681 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
18683 printf ("GPR %08" PRIx32
" GP 0x%" PRIx32
"\n",
18684 reginfo
.ri_gprmask
, reginfo
.ri_gp_value
);
18686 " CPR0 %08" PRIx32
" CPR1 %08" PRIx32
18687 " CPR2 %08" PRIx32
" CPR3 %08" PRIx32
"\n",
18688 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
18689 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
18694 Elf64_External_RegInfo
* ereg
;
18695 Elf64_Internal_RegInfo reginfo
;
18697 if (option
.size
< (sizeof (Elf_External_Options
)
18698 + sizeof (Elf64_External_RegInfo
)))
18700 printf (_("<corrupt>\n"));
18701 error (_("Truncated MIPS REGINFO option\n"));
18706 ereg
= (Elf64_External_RegInfo
*) (eoption
+ 1);
18707 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
18708 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
18709 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
18710 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
18711 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
18712 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
18714 printf ("GPR %08" PRIx32
" GP 0x%" PRIx64
"\n",
18715 reginfo
.ri_gprmask
, reginfo
.ri_gp_value
);
18717 " CPR0 %08" PRIx32
" CPR1 %08" PRIx32
18718 " CPR2 %08" PRIx32
" CPR3 %08" PRIx32
"\n",
18719 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
18720 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
18722 offset
+= option
.size
;
18725 case ODK_EXCEPTIONS
:
18726 fputs (" EXCEPTIONS fpe_min(", stdout
);
18727 process_mips_fpe_exception (option
.info
& OEX_FPU_MIN
);
18728 fputs (") fpe_max(", stdout
);
18729 process_mips_fpe_exception ((option
.info
& OEX_FPU_MAX
) >> 8);
18730 fputs (")", stdout
);
18732 if (option
.info
& OEX_PAGE0
)
18733 fputs (" PAGE0", stdout
);
18734 if (option
.info
& OEX_SMM
)
18735 fputs (" SMM", stdout
);
18736 if (option
.info
& OEX_FPDBUG
)
18737 fputs (" FPDBUG", stdout
);
18738 if (option
.info
& OEX_DISMISS
)
18739 fputs (" DISMISS", stdout
);
18743 fputs (" PAD ", stdout
);
18744 if (option
.info
& OPAD_PREFIX
)
18745 fputs (" PREFIX", stdout
);
18746 if (option
.info
& OPAD_POSTFIX
)
18747 fputs (" POSTFIX", stdout
);
18748 if (option
.info
& OPAD_SYMBOL
)
18749 fputs (" SYMBOL", stdout
);
18753 fputs (" HWPATCH ", stdout
);
18754 if (option
.info
& OHW_R4KEOP
)
18755 fputs (" R4KEOP", stdout
);
18756 if (option
.info
& OHW_R8KPFETCH
)
18757 fputs (" R8KPFETCH", stdout
);
18758 if (option
.info
& OHW_R5KEOP
)
18759 fputs (" R5KEOP", stdout
);
18760 if (option
.info
& OHW_R5KCVTL
)
18761 fputs (" R5KCVTL", stdout
);
18765 fputs (" FILL ", stdout
);
18766 /* XXX Print content of info word? */
18770 fputs (" TAGS ", stdout
);
18771 /* XXX Print content of info word? */
18775 fputs (" HWAND ", stdout
);
18776 if (option
.info
& OHWA0_R4KEOP_CHECKED
)
18777 fputs (" R4KEOP_CHECKED", stdout
);
18778 if (option
.info
& OHWA0_R4KEOP_CLEAN
)
18779 fputs (" R4KEOP_CLEAN", stdout
);
18783 fputs (" HWOR ", stdout
);
18784 if (option
.info
& OHWA0_R4KEOP_CHECKED
)
18785 fputs (" R4KEOP_CHECKED", stdout
);
18786 if (option
.info
& OHWA0_R4KEOP_CLEAN
)
18787 fputs (" R4KEOP_CLEAN", stdout
);
18791 printf (" GP_GROUP %#06x self-contained %#06x",
18792 option
.info
& OGP_GROUP
,
18793 (option
.info
& OGP_SELF
) >> 16);
18797 printf (" IDENT %#06x self-contained %#06x",
18798 option
.info
& OGP_GROUP
,
18799 (option
.info
& OGP_SELF
) >> 16);
18803 /* This shouldn't happen. */
18804 printf (" %3d ??? %" PRId16
" %" PRIx32
,
18805 option
.kind
, option
.section
, option
.info
);
18809 len
= sizeof (* eopt
);
18810 while (len
< option
.size
)
18812 unsigned char datum
= *((unsigned char *) eoption
+ len
);
18814 if (ISPRINT (datum
))
18815 printf ("%c", datum
);
18817 printf ("\\%03o", datum
);
18820 fputs ("\n", stdout
);
18822 offset
+= option
.size
;
18830 if (conflicts_offset
!= 0 && conflictsno
!= 0)
18832 Elf32_Conflict
* iconf
;
18835 if (filedata
->dynamic_symbols
== NULL
)
18837 error (_("conflict list found without a dynamic symbol table\n"));
18841 /* PR 21345 - print a slightly more helpful error message
18842 if we are sure that the cmalloc will fail. */
18843 if (conflictsno
> filedata
->file_size
/ sizeof (* iconf
))
18845 error (_("Overlarge number of conflicts detected: %lx\n"),
18846 (long) conflictsno
);
18850 iconf
= (Elf32_Conflict
*) cmalloc (conflictsno
, sizeof (* iconf
));
18853 error (_("Out of memory allocating space for dynamic conflicts\n"));
18859 Elf32_External_Conflict
* econf32
;
18861 econf32
= (Elf32_External_Conflict
*)
18862 get_data (NULL
, filedata
, conflicts_offset
,
18863 sizeof (*econf32
), conflictsno
, _("conflict"));
18870 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
18871 iconf
[cnt
] = BYTE_GET (econf32
[cnt
]);
18877 Elf64_External_Conflict
* econf64
;
18879 econf64
= (Elf64_External_Conflict
*)
18880 get_data (NULL
, filedata
, conflicts_offset
,
18881 sizeof (*econf64
), conflictsno
, _("conflict"));
18888 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
18889 iconf
[cnt
] = BYTE_GET (econf64
[cnt
]);
18894 printf (ngettext ("\nSection '.conflict' contains %lu entry:\n",
18895 "\nSection '.conflict' contains %lu entries:\n",
18896 (unsigned long) conflictsno
),
18897 (unsigned long) conflictsno
);
18898 puts (_(" Num: Index Value Name"));
18900 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
18902 printf ("%5lu: %8lu ", (unsigned long) cnt
, iconf
[cnt
]);
18904 if (iconf
[cnt
] >= filedata
->num_dynamic_syms
)
18905 printf (_("<corrupt symbol index>"));
18908 Elf_Internal_Sym
* psym
;
18910 psym
= & filedata
->dynamic_symbols
[iconf
[cnt
]];
18911 print_vma (psym
->st_value
, FULL_HEX
);
18913 if (valid_dynamic_name (filedata
, psym
->st_name
))
18914 print_symbol (25, get_dynamic_name (filedata
, psym
->st_name
));
18916 printf (_("<corrupt: %14ld>"), psym
->st_name
);
18924 if (pltgot
!= 0 && local_gotno
!= 0)
18926 bfd_vma ent
, local_end
, global_end
;
18928 unsigned char * data
;
18929 unsigned char * data_end
;
18933 addr_size
= (is_32bit_elf
? 4 : 8);
18934 local_end
= pltgot
+ local_gotno
* addr_size
;
18936 /* PR binutils/17533 file: 012-111227-0.004 */
18937 if (symtabno
< gotsym
)
18939 error (_("The GOT symbol offset (%lu) is greater than the symbol table size (%lu)\n"),
18940 (unsigned long) gotsym
, (unsigned long) symtabno
);
18944 global_end
= local_end
+ (symtabno
- gotsym
) * addr_size
;
18945 /* PR 17531: file: 54c91a34. */
18946 if (global_end
< local_end
)
18948 error (_("Too many GOT symbols: %lu\n"), (unsigned long) symtabno
);
18952 offset
= offset_from_vma (filedata
, pltgot
, global_end
- pltgot
);
18953 data
= (unsigned char *) get_data (NULL
, filedata
, offset
,
18954 global_end
- pltgot
, 1,
18955 _("Global Offset Table data"));
18956 /* PR 12855: Null data is handled gracefully throughout. */
18957 data_end
= data
+ (global_end
- pltgot
);
18959 printf (_("\nPrimary GOT:\n"));
18960 printf (_(" Canonical gp value: "));
18961 print_vma (pltgot
+ 0x7ff0, LONG_HEX
);
18964 printf (_(" Reserved entries:\n"));
18965 printf (_(" %*s %10s %*s Purpose\n"),
18966 addr_size
* 2, _("Address"), _("Access"),
18967 addr_size
* 2, _("Initial"));
18968 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
18969 printf (_(" Lazy resolver\n"));
18970 if (ent
== (bfd_vma
) -1)
18971 goto got_print_fail
;
18973 /* Check for the MSB of GOT[1] being set, denoting a GNU object.
18974 This entry will be used by some runtime loaders, to store the
18975 module pointer. Otherwise this is an ordinary local entry.
18976 PR 21344: Check for the entry being fully available before
18979 && data
+ ent
- pltgot
+ addr_size
<= data_end
18980 && (byte_get (data
+ ent
- pltgot
, addr_size
)
18981 >> (addr_size
* 8 - 1)) != 0)
18983 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
18984 printf (_(" Module pointer (GNU extension)\n"));
18985 if (ent
== (bfd_vma
) -1)
18986 goto got_print_fail
;
18990 if (data
!= NULL
&& ent
< local_end
)
18992 printf (_(" Local entries:\n"));
18993 printf (" %*s %10s %*s\n",
18994 addr_size
* 2, _("Address"), _("Access"),
18995 addr_size
* 2, _("Initial"));
18996 while (ent
< local_end
)
18998 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
19000 if (ent
== (bfd_vma
) -1)
19001 goto got_print_fail
;
19006 if (data
!= NULL
&& gotsym
< symtabno
)
19010 printf (_(" Global entries:\n"));
19011 printf (" %*s %10s %*s %*s %-7s %3s %s\n",
19012 addr_size
* 2, _("Address"),
19014 addr_size
* 2, _("Initial"),
19015 addr_size
* 2, _("Sym.Val."),
19017 /* Note for translators: "Ndx" = abbreviated form of "Index". */
19018 _("Ndx"), _("Name"));
19020 sym_width
= (is_32bit_elf
? 80 : 160) - 28 - addr_size
* 6 - 1;
19022 for (i
= gotsym
; i
< symtabno
; i
++)
19024 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
19027 if (filedata
->dynamic_symbols
== NULL
)
19028 printf (_("<no dynamic symbols>"));
19029 else if (i
< filedata
->num_dynamic_syms
)
19031 Elf_Internal_Sym
* psym
= filedata
->dynamic_symbols
+ i
;
19033 print_vma (psym
->st_value
, LONG_HEX
);
19034 printf (" %-7s %3s ",
19035 get_symbol_type (filedata
, ELF_ST_TYPE (psym
->st_info
)),
19036 get_symbol_index_type (filedata
, psym
->st_shndx
));
19038 if (valid_dynamic_name (filedata
, psym
->st_name
))
19039 print_symbol (sym_width
,
19040 get_dynamic_name (filedata
, psym
->st_name
));
19042 printf (_("<corrupt: %14ld>"), psym
->st_name
);
19045 printf (_("<symbol index %lu exceeds number of dynamic symbols>"),
19046 (unsigned long) i
);
19049 if (ent
== (bfd_vma
) -1)
19059 if (mips_pltgot
!= 0 && jmprel
!= 0 && pltrel
!= 0 && pltrelsz
!= 0)
19062 size_t offset
, rel_offset
;
19063 unsigned long count
, i
;
19064 unsigned char * data
;
19065 int addr_size
, sym_width
;
19066 Elf_Internal_Rela
* rels
;
19068 rel_offset
= offset_from_vma (filedata
, jmprel
, pltrelsz
);
19069 if (pltrel
== DT_RELA
)
19071 if (!slurp_rela_relocs (filedata
, rel_offset
, pltrelsz
, &rels
, &count
))
19076 if (!slurp_rel_relocs (filedata
, rel_offset
, pltrelsz
, &rels
, &count
))
19081 addr_size
= (is_32bit_elf
? 4 : 8);
19082 end
= mips_pltgot
+ (2 + count
) * addr_size
;
19084 offset
= offset_from_vma (filedata
, mips_pltgot
, end
- mips_pltgot
);
19085 data
= (unsigned char *) get_data (NULL
, filedata
, offset
, end
- mips_pltgot
,
19086 1, _("Procedure Linkage Table data"));
19093 printf ("\nPLT GOT:\n\n");
19094 printf (_(" Reserved entries:\n"));
19095 printf (_(" %*s %*s Purpose\n"),
19096 addr_size
* 2, _("Address"), addr_size
* 2, _("Initial"));
19097 ent
= print_mips_pltgot_entry (data
, mips_pltgot
, ent
);
19098 printf (_(" PLT lazy resolver\n"));
19099 ent
= print_mips_pltgot_entry (data
, mips_pltgot
, ent
);
19100 printf (_(" Module pointer\n"));
19103 printf (_(" Entries:\n"));
19104 printf (" %*s %*s %*s %-7s %3s %s\n",
19105 addr_size
* 2, _("Address"),
19106 addr_size
* 2, _("Initial"),
19107 addr_size
* 2, _("Sym.Val."), _("Type"), _("Ndx"), _("Name"));
19108 sym_width
= (is_32bit_elf
? 80 : 160) - 17 - addr_size
* 6 - 1;
19109 for (i
= 0; i
< count
; i
++)
19111 unsigned long idx
= get_reloc_symindex (rels
[i
].r_info
);
19113 ent
= print_mips_pltgot_entry (data
, mips_pltgot
, ent
);
19116 if (idx
>= filedata
->num_dynamic_syms
)
19117 printf (_("<corrupt symbol index: %lu>"), idx
);
19120 Elf_Internal_Sym
* psym
= filedata
->dynamic_symbols
+ idx
;
19122 print_vma (psym
->st_value
, LONG_HEX
);
19123 printf (" %-7s %3s ",
19124 get_symbol_type (filedata
, ELF_ST_TYPE (psym
->st_info
)),
19125 get_symbol_index_type (filedata
, psym
->st_shndx
));
19126 if (valid_dynamic_name (filedata
, psym
->st_name
))
19127 print_symbol (sym_width
,
19128 get_dynamic_name (filedata
, psym
->st_name
));
19130 printf (_("<corrupt: %14ld>"), psym
->st_name
);
19144 process_nds32_specific (Filedata
* filedata
)
19146 Elf_Internal_Shdr
*sect
= NULL
;
19148 sect
= find_section (filedata
, ".nds32_e_flags");
19149 if (sect
!= NULL
&& sect
->sh_size
>= 4)
19151 unsigned char *buf
;
19154 printf ("\nNDS32 elf flags section:\n");
19155 buf
= get_data (NULL
, filedata
, sect
->sh_offset
, 1, 4,
19156 _("NDS32 elf flags section"));
19161 flag
= byte_get (buf
, 4);
19163 switch (flag
& 0x3)
19166 printf ("(VEC_SIZE):\tNo entry.\n");
19169 printf ("(VEC_SIZE):\t4 bytes\n");
19172 printf ("(VEC_SIZE):\t16 bytes\n");
19175 printf ("(VEC_SIZE):\treserved\n");
19184 process_gnu_liblist (Filedata
* filedata
)
19186 Elf_Internal_Shdr
* section
;
19187 Elf_Internal_Shdr
* string_sec
;
19188 Elf32_External_Lib
* elib
;
19190 size_t strtab_size
;
19192 unsigned long num_liblist
;
19199 for (i
= 0, section
= filedata
->section_headers
;
19200 i
< filedata
->file_header
.e_shnum
;
19203 switch (section
->sh_type
)
19205 case SHT_GNU_LIBLIST
:
19206 if (section
->sh_link
>= filedata
->file_header
.e_shnum
)
19209 elib
= (Elf32_External_Lib
*)
19210 get_data (NULL
, filedata
, section
->sh_offset
, 1, section
->sh_size
,
19211 _("liblist section data"));
19219 string_sec
= filedata
->section_headers
+ section
->sh_link
;
19220 strtab
= (char *) get_data (NULL
, filedata
, string_sec
->sh_offset
, 1,
19221 string_sec
->sh_size
,
19222 _("liblist string table"));
19224 || section
->sh_entsize
!= sizeof (Elf32_External_Lib
))
19231 strtab_size
= string_sec
->sh_size
;
19233 num_liblist
= section
->sh_size
/ sizeof (Elf32_External_Lib
);
19234 printf (ngettext ("\nLibrary list section '%s' contains %lu entries:\n",
19235 "\nLibrary list section '%s' contains %lu entries:\n",
19237 printable_section_name (filedata
, section
),
19240 puts (_(" Library Time Stamp Checksum Version Flags"));
19242 for (cnt
= 0; cnt
< section
->sh_size
/ sizeof (Elf32_External_Lib
);
19250 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
19251 atime
= BYTE_GET (elib
[cnt
].l_time_stamp
);
19252 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
19253 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
19254 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
19256 tmp
= gmtime (&atime
);
19257 snprintf (timebuf
, sizeof (timebuf
),
19258 "%04u-%02u-%02uT%02u:%02u:%02u",
19259 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
19260 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
19262 printf ("%3lu: ", (unsigned long) cnt
);
19264 printf ("%-20s", liblist
.l_name
< strtab_size
19265 ? strtab
+ liblist
.l_name
: _("<corrupt>"));
19267 printf ("%-20.20s", liblist
.l_name
< strtab_size
19268 ? strtab
+ liblist
.l_name
: _("<corrupt>"));
19269 printf (" %s %#010lx %-7ld %-7ld\n", timebuf
, liblist
.l_checksum
,
19270 liblist
.l_version
, liblist
.l_flags
);
19281 static const char *
19282 get_note_type (Filedata
* filedata
, unsigned e_type
)
19284 static char buff
[64];
19286 if (filedata
->file_header
.e_type
== ET_CORE
)
19290 return _("NT_AUXV (auxiliary vector)");
19292 return _("NT_PRSTATUS (prstatus structure)");
19294 return _("NT_FPREGSET (floating point registers)");
19296 return _("NT_PRPSINFO (prpsinfo structure)");
19297 case NT_TASKSTRUCT
:
19298 return _("NT_TASKSTRUCT (task structure)");
19300 return _("NT_GDB_TDESC (GDB XML target description)");
19302 return _("NT_PRXFPREG (user_xfpregs structure)");
19304 return _("NT_PPC_VMX (ppc Altivec registers)");
19306 return _("NT_PPC_VSX (ppc VSX registers)");
19308 return _("NT_PPC_TAR (ppc TAR register)");
19310 return _("NT_PPC_PPR (ppc PPR register)");
19312 return _("NT_PPC_DSCR (ppc DSCR register)");
19314 return _("NT_PPC_EBB (ppc EBB registers)");
19316 return _("NT_PPC_PMU (ppc PMU registers)");
19317 case NT_PPC_TM_CGPR
:
19318 return _("NT_PPC_TM_CGPR (ppc checkpointed GPR registers)");
19319 case NT_PPC_TM_CFPR
:
19320 return _("NT_PPC_TM_CFPR (ppc checkpointed floating point registers)");
19321 case NT_PPC_TM_CVMX
:
19322 return _("NT_PPC_TM_CVMX (ppc checkpointed Altivec registers)");
19323 case NT_PPC_TM_CVSX
:
19324 return _("NT_PPC_TM_CVSX (ppc checkpointed VSX registers)");
19325 case NT_PPC_TM_SPR
:
19326 return _("NT_PPC_TM_SPR (ppc TM special purpose registers)");
19327 case NT_PPC_TM_CTAR
:
19328 return _("NT_PPC_TM_CTAR (ppc checkpointed TAR register)");
19329 case NT_PPC_TM_CPPR
:
19330 return _("NT_PPC_TM_CPPR (ppc checkpointed PPR register)");
19331 case NT_PPC_TM_CDSCR
:
19332 return _("NT_PPC_TM_CDSCR (ppc checkpointed DSCR register)");
19334 return _("NT_386_TLS (x86 TLS information)");
19335 case NT_386_IOPERM
:
19336 return _("NT_386_IOPERM (x86 I/O permissions)");
19337 case NT_X86_XSTATE
:
19338 return _("NT_X86_XSTATE (x86 XSAVE extended state)");
19340 return _("NT_X86_CET (x86 CET state)");
19341 case NT_S390_HIGH_GPRS
:
19342 return _("NT_S390_HIGH_GPRS (s390 upper register halves)");
19343 case NT_S390_TIMER
:
19344 return _("NT_S390_TIMER (s390 timer register)");
19345 case NT_S390_TODCMP
:
19346 return _("NT_S390_TODCMP (s390 TOD comparator register)");
19347 case NT_S390_TODPREG
:
19348 return _("NT_S390_TODPREG (s390 TOD programmable register)");
19350 return _("NT_S390_CTRS (s390 control registers)");
19351 case NT_S390_PREFIX
:
19352 return _("NT_S390_PREFIX (s390 prefix register)");
19353 case NT_S390_LAST_BREAK
:
19354 return _("NT_S390_LAST_BREAK (s390 last breaking event address)");
19355 case NT_S390_SYSTEM_CALL
:
19356 return _("NT_S390_SYSTEM_CALL (s390 system call restart data)");
19358 return _("NT_S390_TDB (s390 transaction diagnostic block)");
19359 case NT_S390_VXRS_LOW
:
19360 return _("NT_S390_VXRS_LOW (s390 vector registers 0-15 upper half)");
19361 case NT_S390_VXRS_HIGH
:
19362 return _("NT_S390_VXRS_HIGH (s390 vector registers 16-31)");
19363 case NT_S390_GS_CB
:
19364 return _("NT_S390_GS_CB (s390 guarded-storage registers)");
19365 case NT_S390_GS_BC
:
19366 return _("NT_S390_GS_BC (s390 guarded-storage broadcast control)");
19368 return _("NT_ARM_VFP (arm VFP registers)");
19370 return _("NT_ARM_TLS (AArch TLS registers)");
19371 case NT_ARM_HW_BREAK
:
19372 return _("NT_ARM_HW_BREAK (AArch hardware breakpoint registers)");
19373 case NT_ARM_HW_WATCH
:
19374 return _("NT_ARM_HW_WATCH (AArch hardware watchpoint registers)");
19376 return _("NT_ARM_SVE (AArch SVE registers)");
19377 case NT_ARM_PAC_MASK
:
19378 return _("NT_ARM_PAC_MASK (AArch pointer authentication code masks)");
19379 case NT_ARM_PACA_KEYS
:
19380 return _("NT_ARM_PACA_KEYS (ARM pointer authentication address keys)");
19381 case NT_ARM_PACG_KEYS
:
19382 return _("NT_ARM_PACG_KEYS (ARM pointer authentication generic keys)");
19383 case NT_ARM_TAGGED_ADDR_CTRL
:
19384 return _("NT_ARM_TAGGED_ADDR_CTRL (AArch tagged address control)");
19385 case NT_ARM_PAC_ENABLED_KEYS
:
19386 return _("NT_ARM_PAC_ENABLED_KEYS (AArch64 pointer authentication enabled keys)");
19388 return _("NT_ARC_V2 (ARC HS accumulator/extra registers)");
19390 return _("NT_RISCV_CSR (RISC-V control and status registers)");
19392 return _("NT_PSTATUS (pstatus structure)");
19394 return _("NT_FPREGS (floating point registers)");
19396 return _("NT_PSINFO (psinfo structure)");
19398 return _("NT_LWPSTATUS (lwpstatus_t structure)");
19400 return _("NT_LWPSINFO (lwpsinfo_t structure)");
19401 case NT_WIN32PSTATUS
:
19402 return _("NT_WIN32PSTATUS (win32_pstatus structure)");
19404 return _("NT_SIGINFO (siginfo_t data)");
19406 return _("NT_FILE (mapped files)");
19414 return _("NT_VERSION (version)");
19416 return _("NT_ARCH (architecture)");
19417 case NT_GNU_BUILD_ATTRIBUTE_OPEN
:
19419 case NT_GNU_BUILD_ATTRIBUTE_FUNC
:
19421 case NT_GO_BUILDID
:
19422 return _("GO BUILDID");
19423 case FDO_PACKAGING_METADATA
:
19424 return _("FDO_PACKAGING_METADATA");
19429 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
19434 print_core_note (Elf_Internal_Note
*pnote
)
19436 unsigned int addr_size
= is_32bit_elf
? 4 : 8;
19437 bfd_vma count
, page_size
;
19438 unsigned char *descdata
, *filenames
, *descend
;
19440 if (pnote
->type
!= NT_FILE
)
19450 printf (_(" Cannot decode 64-bit note in 32-bit build\n"));
19451 /* Still "successful". */
19456 if (pnote
->descsz
< 2 * addr_size
)
19458 error (_(" Malformed note - too short for header\n"));
19462 descdata
= (unsigned char *) pnote
->descdata
;
19463 descend
= descdata
+ pnote
->descsz
;
19465 if (descdata
[pnote
->descsz
- 1] != '\0')
19467 error (_(" Malformed note - does not end with \\0\n"));
19471 count
= byte_get (descdata
, addr_size
);
19472 descdata
+= addr_size
;
19474 page_size
= byte_get (descdata
, addr_size
);
19475 descdata
+= addr_size
;
19477 if (count
> ((bfd_vma
) -1 - 2 * addr_size
) / (3 * addr_size
)
19478 || pnote
->descsz
< 2 * addr_size
+ count
* 3 * addr_size
)
19480 error (_(" Malformed note - too short for supplied file count\n"));
19484 printf (_(" Page size: "));
19485 print_vma (page_size
, DEC
);
19488 printf (_(" %*s%*s%*s\n"),
19489 (int) (2 + 2 * addr_size
), _("Start"),
19490 (int) (4 + 2 * addr_size
), _("End"),
19491 (int) (4 + 2 * addr_size
), _("Page Offset"));
19492 filenames
= descdata
+ count
* 3 * addr_size
;
19493 while (count
-- > 0)
19495 bfd_vma start
, end
, file_ofs
;
19497 if (filenames
== descend
)
19499 error (_(" Malformed note - filenames end too early\n"));
19503 start
= byte_get (descdata
, addr_size
);
19504 descdata
+= addr_size
;
19505 end
= byte_get (descdata
, addr_size
);
19506 descdata
+= addr_size
;
19507 file_ofs
= byte_get (descdata
, addr_size
);
19508 descdata
+= addr_size
;
19511 print_vma (start
, FULL_HEX
);
19513 print_vma (end
, FULL_HEX
);
19515 print_vma (file_ofs
, FULL_HEX
);
19516 printf ("\n %s\n", filenames
);
19518 filenames
+= 1 + strlen ((char *) filenames
);
19524 static const char *
19525 get_gnu_elf_note_type (unsigned e_type
)
19527 /* NB/ Keep this switch statement in sync with print_gnu_note (). */
19530 case NT_GNU_ABI_TAG
:
19531 return _("NT_GNU_ABI_TAG (ABI version tag)");
19533 return _("NT_GNU_HWCAP (DSO-supplied software HWCAP info)");
19534 case NT_GNU_BUILD_ID
:
19535 return _("NT_GNU_BUILD_ID (unique build ID bitstring)");
19536 case NT_GNU_GOLD_VERSION
:
19537 return _("NT_GNU_GOLD_VERSION (gold version)");
19538 case NT_GNU_PROPERTY_TYPE_0
:
19539 return _("NT_GNU_PROPERTY_TYPE_0");
19540 case NT_GNU_BUILD_ATTRIBUTE_OPEN
:
19541 return _("NT_GNU_BUILD_ATTRIBUTE_OPEN");
19542 case NT_GNU_BUILD_ATTRIBUTE_FUNC
:
19543 return _("NT_GNU_BUILD_ATTRIBUTE_FUNC");
19546 static char buff
[64];
19548 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
19555 decode_x86_compat_isa (unsigned int bitmask
)
19559 unsigned int bit
= bitmask
& (- bitmask
);
19564 case GNU_PROPERTY_X86_COMPAT_ISA_1_486
:
19567 case GNU_PROPERTY_X86_COMPAT_ISA_1_586
:
19570 case GNU_PROPERTY_X86_COMPAT_ISA_1_686
:
19573 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE
:
19576 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE2
:
19579 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE3
:
19582 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSSE3
:
19585 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE4_1
:
19588 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE4_2
:
19591 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX
:
19594 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX2
:
19597 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512F
:
19598 printf ("AVX512F");
19600 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512CD
:
19601 printf ("AVX512CD");
19603 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512ER
:
19604 printf ("AVX512ER");
19606 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512PF
:
19607 printf ("AVX512PF");
19609 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512VL
:
19610 printf ("AVX512VL");
19612 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512DQ
:
19613 printf ("AVX512DQ");
19615 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512BW
:
19616 printf ("AVX512BW");
19619 printf (_("<unknown: %x>"), bit
);
19628 decode_x86_compat_2_isa (unsigned int bitmask
)
19632 printf (_("<None>"));
19638 unsigned int bit
= bitmask
& (- bitmask
);
19643 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_CMOV
:
19646 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE
:
19649 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE2
:
19652 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE3
:
19655 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSSE3
:
19658 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE4_1
:
19661 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE4_2
:
19664 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX
:
19667 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX2
:
19670 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_FMA
:
19673 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512F
:
19674 printf ("AVX512F");
19676 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512CD
:
19677 printf ("AVX512CD");
19679 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512ER
:
19680 printf ("AVX512ER");
19682 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512PF
:
19683 printf ("AVX512PF");
19685 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512VL
:
19686 printf ("AVX512VL");
19688 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512DQ
:
19689 printf ("AVX512DQ");
19691 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512BW
:
19692 printf ("AVX512BW");
19694 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_4FMAPS
:
19695 printf ("AVX512_4FMAPS");
19697 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_4VNNIW
:
19698 printf ("AVX512_4VNNIW");
19700 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_BITALG
:
19701 printf ("AVX512_BITALG");
19703 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_IFMA
:
19704 printf ("AVX512_IFMA");
19706 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_VBMI
:
19707 printf ("AVX512_VBMI");
19709 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_VBMI2
:
19710 printf ("AVX512_VBMI2");
19712 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_VNNI
:
19713 printf ("AVX512_VNNI");
19715 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_BF16
:
19716 printf ("AVX512_BF16");
19719 printf (_("<unknown: %x>"), bit
);
19727 static const char *
19728 get_amdgpu_elf_note_type (unsigned int e_type
)
19732 case NT_AMDGPU_METADATA
:
19733 return _("NT_AMDGPU_METADATA (code object metadata)");
19736 static char buf
[64];
19737 snprintf (buf
, sizeof (buf
), _("Unknown note type: (0x%08x)"), e_type
);
19744 decode_x86_isa (unsigned int bitmask
)
19748 unsigned int bit
= bitmask
& (- bitmask
);
19753 case GNU_PROPERTY_X86_ISA_1_BASELINE
:
19754 printf ("x86-64-baseline");
19756 case GNU_PROPERTY_X86_ISA_1_V2
:
19757 printf ("x86-64-v2");
19759 case GNU_PROPERTY_X86_ISA_1_V3
:
19760 printf ("x86-64-v3");
19762 case GNU_PROPERTY_X86_ISA_1_V4
:
19763 printf ("x86-64-v4");
19766 printf (_("<unknown: %x>"), bit
);
19775 decode_x86_feature_1 (unsigned int bitmask
)
19779 printf (_("<None>"));
19785 unsigned int bit
= bitmask
& (- bitmask
);
19790 case GNU_PROPERTY_X86_FEATURE_1_IBT
:
19793 case GNU_PROPERTY_X86_FEATURE_1_SHSTK
:
19796 case GNU_PROPERTY_X86_FEATURE_1_LAM_U48
:
19797 printf ("LAM_U48");
19799 case GNU_PROPERTY_X86_FEATURE_1_LAM_U57
:
19800 printf ("LAM_U57");
19803 printf (_("<unknown: %x>"), bit
);
19812 decode_x86_feature_2 (unsigned int bitmask
)
19816 printf (_("<None>"));
19822 unsigned int bit
= bitmask
& (- bitmask
);
19827 case GNU_PROPERTY_X86_FEATURE_2_X86
:
19830 case GNU_PROPERTY_X86_FEATURE_2_X87
:
19833 case GNU_PROPERTY_X86_FEATURE_2_MMX
:
19836 case GNU_PROPERTY_X86_FEATURE_2_XMM
:
19839 case GNU_PROPERTY_X86_FEATURE_2_YMM
:
19842 case GNU_PROPERTY_X86_FEATURE_2_ZMM
:
19845 case GNU_PROPERTY_X86_FEATURE_2_TMM
:
19848 case GNU_PROPERTY_X86_FEATURE_2_MASK
:
19851 case GNU_PROPERTY_X86_FEATURE_2_FXSR
:
19854 case GNU_PROPERTY_X86_FEATURE_2_XSAVE
:
19857 case GNU_PROPERTY_X86_FEATURE_2_XSAVEOPT
:
19858 printf ("XSAVEOPT");
19860 case GNU_PROPERTY_X86_FEATURE_2_XSAVEC
:
19864 printf (_("<unknown: %x>"), bit
);
19873 decode_aarch64_feature_1_and (unsigned int bitmask
)
19877 unsigned int bit
= bitmask
& (- bitmask
);
19882 case GNU_PROPERTY_AARCH64_FEATURE_1_BTI
:
19886 case GNU_PROPERTY_AARCH64_FEATURE_1_PAC
:
19891 printf (_("<unknown: %x>"), bit
);
19900 decode_1_needed (unsigned int bitmask
)
19904 unsigned int bit
= bitmask
& (- bitmask
);
19909 case GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS
:
19910 printf ("indirect external access");
19913 printf (_("<unknown: %x>"), bit
);
19922 print_gnu_property_note (Filedata
* filedata
, Elf_Internal_Note
* pnote
)
19924 unsigned char * ptr
= (unsigned char *) pnote
->descdata
;
19925 unsigned char * ptr_end
= ptr
+ pnote
->descsz
;
19926 unsigned int size
= is_32bit_elf
? 4 : 8;
19928 printf (_(" Properties: "));
19930 if (pnote
->descsz
< 8 || (pnote
->descsz
% size
) != 0)
19932 printf (_("<corrupt GNU_PROPERTY_TYPE, size = %#lx>\n"), pnote
->descsz
);
19936 while (ptr
< ptr_end
)
19940 unsigned int datasz
;
19942 if ((size_t) (ptr_end
- ptr
) < 8)
19944 printf (_("<corrupt descsz: %#lx>\n"), pnote
->descsz
);
19948 type
= byte_get (ptr
, 4);
19949 datasz
= byte_get (ptr
+ 4, 4);
19953 if (datasz
> (size_t) (ptr_end
- ptr
))
19955 printf (_("<corrupt type (%#x) datasz: %#x>\n"),
19960 if (type
>= GNU_PROPERTY_LOPROC
&& type
<= GNU_PROPERTY_HIPROC
)
19962 if (filedata
->file_header
.e_machine
== EM_X86_64
19963 || filedata
->file_header
.e_machine
== EM_IAMCU
19964 || filedata
->file_header
.e_machine
== EM_386
)
19966 unsigned int bitmask
;
19969 bitmask
= byte_get (ptr
, 4);
19975 case GNU_PROPERTY_X86_ISA_1_USED
:
19977 printf (_("x86 ISA used: <corrupt length: %#x> "),
19981 printf ("x86 ISA used: ");
19982 decode_x86_isa (bitmask
);
19986 case GNU_PROPERTY_X86_ISA_1_NEEDED
:
19988 printf (_("x86 ISA needed: <corrupt length: %#x> "),
19992 printf ("x86 ISA needed: ");
19993 decode_x86_isa (bitmask
);
19997 case GNU_PROPERTY_X86_FEATURE_1_AND
:
19999 printf (_("x86 feature: <corrupt length: %#x> "),
20003 printf ("x86 feature: ");
20004 decode_x86_feature_1 (bitmask
);
20008 case GNU_PROPERTY_X86_FEATURE_2_USED
:
20010 printf (_("x86 feature used: <corrupt length: %#x> "),
20014 printf ("x86 feature used: ");
20015 decode_x86_feature_2 (bitmask
);
20019 case GNU_PROPERTY_X86_FEATURE_2_NEEDED
:
20021 printf (_("x86 feature needed: <corrupt length: %#x> "), datasz
);
20024 printf ("x86 feature needed: ");
20025 decode_x86_feature_2 (bitmask
);
20029 case GNU_PROPERTY_X86_COMPAT_ISA_1_USED
:
20031 printf (_("x86 ISA used: <corrupt length: %#x> "),
20035 printf ("x86 ISA used: ");
20036 decode_x86_compat_isa (bitmask
);
20040 case GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED
:
20042 printf (_("x86 ISA needed: <corrupt length: %#x> "),
20046 printf ("x86 ISA needed: ");
20047 decode_x86_compat_isa (bitmask
);
20051 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_USED
:
20053 printf (_("x86 ISA used: <corrupt length: %#x> "),
20057 printf ("x86 ISA used: ");
20058 decode_x86_compat_2_isa (bitmask
);
20062 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_NEEDED
:
20064 printf (_("x86 ISA needed: <corrupt length: %#x> "),
20068 printf ("x86 ISA needed: ");
20069 decode_x86_compat_2_isa (bitmask
);
20077 else if (filedata
->file_header
.e_machine
== EM_AARCH64
)
20079 if (type
== GNU_PROPERTY_AARCH64_FEATURE_1_AND
)
20081 printf ("AArch64 feature: ");
20083 printf (_("<corrupt length: %#x> "), datasz
);
20085 decode_aarch64_feature_1_and (byte_get (ptr
, 4));
20094 case GNU_PROPERTY_STACK_SIZE
:
20095 printf (_("stack size: "));
20096 if (datasz
!= size
)
20097 printf (_("<corrupt length: %#x> "), datasz
);
20099 printf ("%#lx", (unsigned long) byte_get (ptr
, size
));
20102 case GNU_PROPERTY_NO_COPY_ON_PROTECTED
:
20103 printf ("no copy on protected ");
20105 printf (_("<corrupt length: %#x> "), datasz
);
20109 if ((type
>= GNU_PROPERTY_UINT32_AND_LO
20110 && type
<= GNU_PROPERTY_UINT32_AND_HI
)
20111 || (type
>= GNU_PROPERTY_UINT32_OR_LO
20112 && type
<= GNU_PROPERTY_UINT32_OR_HI
))
20116 case GNU_PROPERTY_1_NEEDED
:
20118 printf (_("1_needed: <corrupt length: %#x> "),
20122 unsigned int bitmask
= byte_get (ptr
, 4);
20123 printf ("1_needed: ");
20124 decode_1_needed (bitmask
);
20131 if (type
<= GNU_PROPERTY_UINT32_AND_HI
)
20132 printf (_("UINT32_AND (%#x): "), type
);
20134 printf (_("UINT32_OR (%#x): "), type
);
20136 printf (_("<corrupt length: %#x> "), datasz
);
20138 printf ("%#x", (unsigned int) byte_get (ptr
, 4));
20145 if (type
< GNU_PROPERTY_LOPROC
)
20146 printf (_("<unknown type %#x data: "), type
);
20147 else if (type
< GNU_PROPERTY_LOUSER
)
20148 printf (_("<processor-specific type %#x data: "), type
);
20150 printf (_("<application-specific type %#x data: "), type
);
20151 for (j
= 0; j
< datasz
; ++j
)
20152 printf ("%02x ", ptr
[j
] & 0xff);
20156 ptr
+= ((datasz
+ (size
- 1)) & ~ (size
- 1));
20157 if (ptr
== ptr_end
)
20170 print_gnu_note (Filedata
* filedata
, Elf_Internal_Note
*pnote
)
20172 /* NB/ Keep this switch statement in sync with get_gnu_elf_note_type (). */
20173 switch (pnote
->type
)
20175 case NT_GNU_BUILD_ID
:
20179 printf (_(" Build ID: "));
20180 for (i
= 0; i
< pnote
->descsz
; ++i
)
20181 printf ("%02x", pnote
->descdata
[i
] & 0xff);
20186 case NT_GNU_ABI_TAG
:
20188 unsigned long os
, major
, minor
, subminor
;
20189 const char *osname
;
20191 /* PR 17531: file: 030-599401-0.004. */
20192 if (pnote
->descsz
< 16)
20194 printf (_(" <corrupt GNU_ABI_TAG>\n"));
20198 os
= byte_get ((unsigned char *) pnote
->descdata
, 4);
20199 major
= byte_get ((unsigned char *) pnote
->descdata
+ 4, 4);
20200 minor
= byte_get ((unsigned char *) pnote
->descdata
+ 8, 4);
20201 subminor
= byte_get ((unsigned char *) pnote
->descdata
+ 12, 4);
20205 case GNU_ABI_TAG_LINUX
:
20208 case GNU_ABI_TAG_HURD
:
20211 case GNU_ABI_TAG_SOLARIS
:
20212 osname
= "Solaris";
20214 case GNU_ABI_TAG_FREEBSD
:
20215 osname
= "FreeBSD";
20217 case GNU_ABI_TAG_NETBSD
:
20220 case GNU_ABI_TAG_SYLLABLE
:
20221 osname
= "Syllable";
20223 case GNU_ABI_TAG_NACL
:
20227 osname
= "Unknown";
20231 printf (_(" OS: %s, ABI: %ld.%ld.%ld\n"), osname
,
20232 major
, minor
, subminor
);
20236 case NT_GNU_GOLD_VERSION
:
20240 printf (_(" Version: "));
20241 for (i
= 0; i
< pnote
->descsz
&& pnote
->descdata
[i
] != '\0'; ++i
)
20242 printf ("%c", pnote
->descdata
[i
]);
20249 unsigned long num_entries
, mask
;
20251 /* Hardware capabilities information. Word 0 is the number of entries.
20252 Word 1 is a bitmask of enabled entries. The rest of the descriptor
20253 is a series of entries, where each entry is a single byte followed
20254 by a nul terminated string. The byte gives the bit number to test
20255 if enabled in the bitmask. */
20256 printf (_(" Hardware Capabilities: "));
20257 if (pnote
->descsz
< 8)
20259 error (_("<corrupt GNU_HWCAP>\n"));
20262 num_entries
= byte_get ((unsigned char *) pnote
->descdata
, 4);
20263 mask
= byte_get ((unsigned char *) pnote
->descdata
+ 4, 4);
20264 printf (_("num entries: %ld, enabled mask: %lx\n"), num_entries
, mask
);
20265 /* FIXME: Add code to display the entries... */
20269 case NT_GNU_PROPERTY_TYPE_0
:
20270 print_gnu_property_note (filedata
, pnote
);
20274 /* Handle unrecognised types. An error message should have already been
20275 created by get_gnu_elf_note_type(), so all that we need to do is to
20276 display the data. */
20280 printf (_(" Description data: "));
20281 for (i
= 0; i
< pnote
->descsz
; ++i
)
20282 printf ("%02x ", pnote
->descdata
[i
] & 0xff);
20291 static const char *
20292 get_v850_elf_note_type (enum v850_notes n_type
)
20294 static char buff
[64];
20298 case V850_NOTE_ALIGNMENT
: return _("Alignment of 8-byte objects");
20299 case V850_NOTE_DATA_SIZE
: return _("Sizeof double and long double");
20300 case V850_NOTE_FPU_INFO
: return _("Type of FPU support needed");
20301 case V850_NOTE_SIMD_INFO
: return _("Use of SIMD instructions");
20302 case V850_NOTE_CACHE_INFO
: return _("Use of cache");
20303 case V850_NOTE_MMU_INFO
: return _("Use of MMU");
20305 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), n_type
);
20311 print_v850_note (Elf_Internal_Note
* pnote
)
20315 if (pnote
->descsz
!= 4)
20318 val
= byte_get ((unsigned char *) pnote
->descdata
, pnote
->descsz
);
20322 printf (_("not set\n"));
20326 switch (pnote
->type
)
20328 case V850_NOTE_ALIGNMENT
:
20331 case EF_RH850_DATA_ALIGN4
: printf (_("4-byte\n")); return true;
20332 case EF_RH850_DATA_ALIGN8
: printf (_("8-byte\n")); return true;
20336 case V850_NOTE_DATA_SIZE
:
20339 case EF_RH850_DOUBLE32
: printf (_("4-bytes\n")); return true;
20340 case EF_RH850_DOUBLE64
: printf (_("8-bytes\n")); return true;
20344 case V850_NOTE_FPU_INFO
:
20347 case EF_RH850_FPU20
: printf (_("FPU-2.0\n")); return true;
20348 case EF_RH850_FPU30
: printf (_("FPU-3.0\n")); return true;
20352 case V850_NOTE_MMU_INFO
:
20353 case V850_NOTE_CACHE_INFO
:
20354 case V850_NOTE_SIMD_INFO
:
20355 if (val
== EF_RH850_SIMD
)
20357 printf (_("yes\n"));
20363 /* An 'unknown note type' message will already have been displayed. */
20367 printf (_("unknown value: %x\n"), val
);
20372 process_netbsd_elf_note (Elf_Internal_Note
* pnote
)
20374 unsigned int version
;
20376 switch (pnote
->type
)
20378 case NT_NETBSD_IDENT
:
20379 if (pnote
->descsz
< 1)
20381 version
= byte_get ((unsigned char *) pnote
->descdata
, sizeof (version
));
20382 if ((version
/ 10000) % 100)
20383 printf (" NetBSD\t\t0x%08lx\tIDENT %u (%u.%u%s%c)\n", pnote
->descsz
,
20384 version
, version
/ 100000000, (version
/ 1000000) % 100,
20385 (version
/ 10000) % 100 > 26 ? "Z" : "",
20386 'A' + (version
/ 10000) % 26);
20388 printf (" NetBSD\t\t0x%08lx\tIDENT %u (%u.%u.%u)\n", pnote
->descsz
,
20389 version
, version
/ 100000000, (version
/ 1000000) % 100,
20390 (version
/ 100) % 100);
20393 case NT_NETBSD_MARCH
:
20394 printf (" NetBSD\t\t0x%08lx\tMARCH <%s>\n", pnote
->descsz
,
20398 case NT_NETBSD_PAX
:
20399 if (pnote
->descsz
< 1)
20401 version
= byte_get ((unsigned char *) pnote
->descdata
, sizeof (version
));
20402 printf (" NetBSD\t\t0x%08lx\tPaX <%s%s%s%s%s%s>\n", pnote
->descsz
,
20403 ((version
& NT_NETBSD_PAX_MPROTECT
) ? "+mprotect" : ""),
20404 ((version
& NT_NETBSD_PAX_NOMPROTECT
) ? "-mprotect" : ""),
20405 ((version
& NT_NETBSD_PAX_GUARD
) ? "+guard" : ""),
20406 ((version
& NT_NETBSD_PAX_NOGUARD
) ? "-guard" : ""),
20407 ((version
& NT_NETBSD_PAX_ASLR
) ? "+ASLR" : ""),
20408 ((version
& NT_NETBSD_PAX_NOASLR
) ? "-ASLR" : ""));
20412 printf (" NetBSD\t0x%08lx\tUnknown note type: (0x%08lx)\n",
20413 pnote
->descsz
, pnote
->type
);
20417 static const char *
20418 get_freebsd_elfcore_note_type (Filedata
* filedata
, unsigned e_type
)
20422 case NT_FREEBSD_THRMISC
:
20423 return _("NT_THRMISC (thrmisc structure)");
20424 case NT_FREEBSD_PROCSTAT_PROC
:
20425 return _("NT_PROCSTAT_PROC (proc data)");
20426 case NT_FREEBSD_PROCSTAT_FILES
:
20427 return _("NT_PROCSTAT_FILES (files data)");
20428 case NT_FREEBSD_PROCSTAT_VMMAP
:
20429 return _("NT_PROCSTAT_VMMAP (vmmap data)");
20430 case NT_FREEBSD_PROCSTAT_GROUPS
:
20431 return _("NT_PROCSTAT_GROUPS (groups data)");
20432 case NT_FREEBSD_PROCSTAT_UMASK
:
20433 return _("NT_PROCSTAT_UMASK (umask data)");
20434 case NT_FREEBSD_PROCSTAT_RLIMIT
:
20435 return _("NT_PROCSTAT_RLIMIT (rlimit data)");
20436 case NT_FREEBSD_PROCSTAT_OSREL
:
20437 return _("NT_PROCSTAT_OSREL (osreldate data)");
20438 case NT_FREEBSD_PROCSTAT_PSSTRINGS
:
20439 return _("NT_PROCSTAT_PSSTRINGS (ps_strings data)");
20440 case NT_FREEBSD_PROCSTAT_AUXV
:
20441 return _("NT_PROCSTAT_AUXV (auxv data)");
20442 case NT_FREEBSD_PTLWPINFO
:
20443 return _("NT_PTLWPINFO (ptrace_lwpinfo structure)");
20445 return get_note_type (filedata
, e_type
);
20448 static const char *
20449 get_netbsd_elfcore_note_type (Filedata
* filedata
, unsigned e_type
)
20451 static char buff
[64];
20455 case NT_NETBSDCORE_PROCINFO
:
20456 /* NetBSD core "procinfo" structure. */
20457 return _("NetBSD procinfo structure");
20459 case NT_NETBSDCORE_AUXV
:
20460 return _("NetBSD ELF auxiliary vector data");
20462 case NT_NETBSDCORE_LWPSTATUS
:
20463 return _("PT_LWPSTATUS (ptrace_lwpstatus structure)");
20466 /* As of Jan 2020 there are no other machine-independent notes
20467 defined for NetBSD core files. If the note type is less
20468 than the start of the machine-dependent note types, we don't
20471 if (e_type
< NT_NETBSDCORE_FIRSTMACH
)
20473 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
20479 switch (filedata
->file_header
.e_machine
)
20481 /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0
20482 and PT_GETFPREGS == mach+2. */
20487 case EM_SPARC32PLUS
:
20491 case NT_NETBSDCORE_FIRSTMACH
+ 0:
20492 return _("PT_GETREGS (reg structure)");
20493 case NT_NETBSDCORE_FIRSTMACH
+ 2:
20494 return _("PT_GETFPREGS (fpreg structure)");
20500 /* On SuperH, PT_GETREGS == mach+3 and PT_GETFPREGS == mach+5.
20501 There's also old PT___GETREGS40 == mach + 1 for old reg
20502 structure which lacks GBR. */
20506 case NT_NETBSDCORE_FIRSTMACH
+ 1:
20507 return _("PT___GETREGS40 (old reg structure)");
20508 case NT_NETBSDCORE_FIRSTMACH
+ 3:
20509 return _("PT_GETREGS (reg structure)");
20510 case NT_NETBSDCORE_FIRSTMACH
+ 5:
20511 return _("PT_GETFPREGS (fpreg structure)");
20517 /* On all other arch's, PT_GETREGS == mach+1 and
20518 PT_GETFPREGS == mach+3. */
20522 case NT_NETBSDCORE_FIRSTMACH
+ 1:
20523 return _("PT_GETREGS (reg structure)");
20524 case NT_NETBSDCORE_FIRSTMACH
+ 3:
20525 return _("PT_GETFPREGS (fpreg structure)");
20531 snprintf (buff
, sizeof (buff
), "PT_FIRSTMACH+%d",
20532 e_type
- NT_NETBSDCORE_FIRSTMACH
);
20536 static const char *
20537 get_openbsd_elfcore_note_type (Filedata
* filedata
, unsigned e_type
)
20541 case NT_OPENBSD_PROCINFO
:
20542 return _("OpenBSD procinfo structure");
20543 case NT_OPENBSD_AUXV
:
20544 return _("OpenBSD ELF auxiliary vector data");
20545 case NT_OPENBSD_REGS
:
20546 return _("OpenBSD regular registers");
20547 case NT_OPENBSD_FPREGS
:
20548 return _("OpenBSD floating point registers");
20549 case NT_OPENBSD_WCOOKIE
:
20550 return _("OpenBSD window cookie");
20553 return get_note_type (filedata
, e_type
);
20556 static const char *
20557 get_stapsdt_note_type (unsigned e_type
)
20559 static char buff
[64];
20564 return _("NT_STAPSDT (SystemTap probe descriptors)");
20570 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
20575 print_stapsdt_note (Elf_Internal_Note
*pnote
)
20577 size_t len
, maxlen
;
20578 unsigned long addr_size
= is_32bit_elf
? 4 : 8;
20579 char *data
= pnote
->descdata
;
20580 char *data_end
= pnote
->descdata
+ pnote
->descsz
;
20581 bfd_vma pc
, base_addr
, semaphore
;
20582 char *provider
, *probe
, *arg_fmt
;
20584 if (pnote
->descsz
< (addr_size
* 3))
20585 goto stapdt_note_too_small
;
20587 pc
= byte_get ((unsigned char *) data
, addr_size
);
20590 base_addr
= byte_get ((unsigned char *) data
, addr_size
);
20593 semaphore
= byte_get ((unsigned char *) data
, addr_size
);
20596 if (data
>= data_end
)
20597 goto stapdt_note_too_small
;
20598 maxlen
= data_end
- data
;
20599 len
= strnlen (data
, maxlen
);
20606 goto stapdt_note_too_small
;
20608 if (data
>= data_end
)
20609 goto stapdt_note_too_small
;
20610 maxlen
= data_end
- data
;
20611 len
= strnlen (data
, maxlen
);
20618 goto stapdt_note_too_small
;
20620 if (data
>= data_end
)
20621 goto stapdt_note_too_small
;
20622 maxlen
= data_end
- data
;
20623 len
= strnlen (data
, maxlen
);
20630 goto stapdt_note_too_small
;
20632 printf (_(" Provider: %s\n"), provider
);
20633 printf (_(" Name: %s\n"), probe
);
20634 printf (_(" Location: "));
20635 print_vma (pc
, FULL_HEX
);
20636 printf (_(", Base: "));
20637 print_vma (base_addr
, FULL_HEX
);
20638 printf (_(", Semaphore: "));
20639 print_vma (semaphore
, FULL_HEX
);
20641 printf (_(" Arguments: %s\n"), arg_fmt
);
20643 return data
== data_end
;
20645 stapdt_note_too_small
:
20646 printf (_(" <corrupt - note is too small>\n"));
20647 error (_("corrupt stapdt note - the data size is too small\n"));
20652 print_fdo_note (Elf_Internal_Note
* pnote
)
20654 if (pnote
->descsz
> 0 && pnote
->type
== FDO_PACKAGING_METADATA
)
20656 printf (_(" Packaging Metadata: %.*s\n"), (int) pnote
->descsz
, pnote
->descdata
);
20662 static const char *
20663 get_ia64_vms_note_type (unsigned e_type
)
20665 static char buff
[64];
20670 return _("NT_VMS_MHD (module header)");
20672 return _("NT_VMS_LNM (language name)");
20674 return _("NT_VMS_SRC (source files)");
20676 return "NT_VMS_TITLE";
20678 return _("NT_VMS_EIDC (consistency check)");
20679 case NT_VMS_FPMODE
:
20680 return _("NT_VMS_FPMODE (FP mode)");
20681 case NT_VMS_LINKTIME
:
20682 return "NT_VMS_LINKTIME";
20683 case NT_VMS_IMGNAM
:
20684 return _("NT_VMS_IMGNAM (image name)");
20686 return _("NT_VMS_IMGID (image id)");
20687 case NT_VMS_LINKID
:
20688 return _("NT_VMS_LINKID (link id)");
20689 case NT_VMS_IMGBID
:
20690 return _("NT_VMS_IMGBID (build id)");
20691 case NT_VMS_GSTNAM
:
20692 return _("NT_VMS_GSTNAM (sym table name)");
20693 case NT_VMS_ORIG_DYN
:
20694 return "NT_VMS_ORIG_DYN";
20695 case NT_VMS_PATCHTIME
:
20696 return "NT_VMS_PATCHTIME";
20698 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
20704 print_ia64_vms_note (Elf_Internal_Note
* pnote
)
20706 int maxlen
= pnote
->descsz
;
20708 if (maxlen
< 2 || (unsigned long) maxlen
!= pnote
->descsz
)
20709 goto desc_size_fail
;
20711 switch (pnote
->type
)
20715 goto desc_size_fail
;
20717 int l
= (int) strnlen (pnote
->descdata
+ 34, maxlen
- 34);
20719 printf (_(" Creation date : %.17s\n"), pnote
->descdata
);
20720 printf (_(" Last patch date: %.17s\n"), pnote
->descdata
+ 17);
20721 if (l
+ 34 < maxlen
)
20723 printf (_(" Module name : %s\n"), pnote
->descdata
+ 34);
20724 if (l
+ 35 < maxlen
)
20725 printf (_(" Module version : %s\n"), pnote
->descdata
+ 34 + l
+ 1);
20727 printf (_(" Module version : <missing>\n"));
20731 printf (_(" Module name : <missing>\n"));
20732 printf (_(" Module version : <missing>\n"));
20737 printf (_(" Language: %.*s\n"), maxlen
, pnote
->descdata
);
20741 case NT_VMS_FPMODE
:
20742 printf (_(" Floating Point mode: "));
20744 goto desc_size_fail
;
20745 /* FIXME: Generate an error if descsz > 8 ? */
20747 printf ("0x%016" BFD_VMA_FMT
"x\n",
20748 (bfd_vma
) byte_get ((unsigned char *)pnote
->descdata
, 8));
20751 case NT_VMS_LINKTIME
:
20752 printf (_(" Link time: "));
20754 goto desc_size_fail
;
20755 /* FIXME: Generate an error if descsz > 8 ? */
20758 ((bfd_int64_t
) byte_get ((unsigned char *)pnote
->descdata
, 8));
20762 case NT_VMS_PATCHTIME
:
20763 printf (_(" Patch time: "));
20765 goto desc_size_fail
;
20766 /* FIXME: Generate an error if descsz > 8 ? */
20769 ((bfd_int64_t
) byte_get ((unsigned char *)pnote
->descdata
, 8));
20773 case NT_VMS_ORIG_DYN
:
20775 goto desc_size_fail
;
20777 printf (_(" Major id: %u, minor id: %u\n"),
20778 (unsigned) byte_get ((unsigned char *)pnote
->descdata
, 4),
20779 (unsigned) byte_get ((unsigned char *)pnote
->descdata
+ 4, 4));
20780 printf (_(" Last modified : "));
20782 ((bfd_int64_t
) byte_get ((unsigned char *)pnote
->descdata
+ 8, 8));
20783 printf (_("\n Link flags : "));
20784 printf ("0x%016" BFD_VMA_FMT
"x\n",
20785 (bfd_vma
) byte_get ((unsigned char *)pnote
->descdata
+ 16, 8));
20786 printf (_(" Header flags: 0x%08x\n"),
20787 (unsigned) byte_get ((unsigned char *)pnote
->descdata
+ 24, 4));
20788 printf (_(" Image id : %.*s\n"), maxlen
- 32, pnote
->descdata
+ 32);
20792 case NT_VMS_IMGNAM
:
20793 printf (_(" Image name: %.*s\n"), maxlen
, pnote
->descdata
);
20796 case NT_VMS_GSTNAM
:
20797 printf (_(" Global symbol table name: %.*s\n"), maxlen
, pnote
->descdata
);
20801 printf (_(" Image id: %.*s\n"), maxlen
, pnote
->descdata
);
20804 case NT_VMS_LINKID
:
20805 printf (_(" Linker id: %.*s\n"), maxlen
, pnote
->descdata
);
20815 printf (_(" <corrupt - data size is too small>\n"));
20816 error (_("corrupt IA64 note: data size is too small\n"));
20820 struct build_attr_cache
{
20821 Filedata
*filedata
;
20823 unsigned long strtablen
;
20824 Elf_Internal_Sym
*symtab
;
20825 unsigned long nsyms
;
20828 /* Find the symbol associated with a build attribute that is attached
20829 to address OFFSET. If PNAME is non-NULL then store the name of
20830 the symbol (if found) in the provided pointer, Returns NULL if a
20831 symbol could not be found. */
20833 static Elf_Internal_Sym
*
20834 get_symbol_for_build_attribute (Filedata
*filedata
,
20835 unsigned long offset
,
20837 const char **pname
)
20839 Elf_Internal_Sym
*saved_sym
= NULL
;
20840 Elf_Internal_Sym
*sym
;
20842 if (filedata
->section_headers
!= NULL
20843 && (ba_cache
.filedata
== NULL
|| filedata
!= ba_cache
.filedata
))
20845 Elf_Internal_Shdr
* symsec
;
20847 free (ba_cache
.strtab
);
20848 ba_cache
.strtab
= NULL
;
20849 free (ba_cache
.symtab
);
20850 ba_cache
.symtab
= NULL
;
20852 /* Load the symbol and string sections. */
20853 for (symsec
= filedata
->section_headers
;
20854 symsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
20857 if (symsec
->sh_type
== SHT_SYMTAB
20858 && get_symtab (filedata
, symsec
,
20859 &ba_cache
.symtab
, &ba_cache
.nsyms
,
20860 &ba_cache
.strtab
, &ba_cache
.strtablen
))
20863 ba_cache
.filedata
= filedata
;
20866 if (ba_cache
.symtab
== NULL
)
20869 /* Find a symbol whose value matches offset. */
20870 for (sym
= ba_cache
.symtab
; sym
< ba_cache
.symtab
+ ba_cache
.nsyms
; sym
++)
20871 if (sym
->st_value
== offset
)
20873 if (sym
->st_name
>= ba_cache
.strtablen
)
20874 /* Huh ? This should not happen. */
20877 if (ba_cache
.strtab
[sym
->st_name
] == 0)
20880 /* The AArch64, ARM and RISC-V architectures define mapping symbols
20881 (eg $d, $x, $t) which we want to ignore. */
20882 if (ba_cache
.strtab
[sym
->st_name
] == '$'
20883 && ba_cache
.strtab
[sym
->st_name
+ 1] != 0
20884 && ba_cache
.strtab
[sym
->st_name
+ 2] == 0)
20889 /* For OPEN attributes we prefer GLOBAL over LOCAL symbols
20890 and FILE or OBJECT symbols over NOTYPE symbols. We skip
20891 FUNC symbols entirely. */
20892 switch (ELF_ST_TYPE (sym
->st_info
))
20899 /* If the symbol has a size associated
20900 with it then we can stop searching. */
20901 sym
= ba_cache
.symtab
+ ba_cache
.nsyms
;
20906 /* Ignore function symbols. */
20913 switch (ELF_ST_BIND (sym
->st_info
))
20916 if (saved_sym
== NULL
20917 || ELF_ST_TYPE (saved_sym
->st_info
) != STT_OBJECT
)
20922 if (saved_sym
== NULL
)
20932 if (ELF_ST_TYPE (sym
->st_info
) != STT_FUNC
)
20940 if (saved_sym
&& pname
)
20941 * pname
= ba_cache
.strtab
+ saved_sym
->st_name
;
20946 /* Returns true iff addr1 and addr2 are in the same section. */
20949 same_section (Filedata
* filedata
, unsigned long addr1
, unsigned long addr2
)
20951 Elf_Internal_Shdr
* a1
;
20952 Elf_Internal_Shdr
* a2
;
20954 a1
= find_section_by_address (filedata
, addr1
);
20955 a2
= find_section_by_address (filedata
, addr2
);
20957 return a1
== a2
&& a1
!= NULL
;
20961 print_gnu_build_attribute_description (Elf_Internal_Note
* pnote
,
20962 Filedata
* filedata
)
20964 static unsigned long global_offset
= 0;
20965 static unsigned long global_end
= 0;
20966 static unsigned long func_offset
= 0;
20967 static unsigned long func_end
= 0;
20969 Elf_Internal_Sym
*sym
;
20971 unsigned long start
;
20973 bool is_open_attr
= pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_OPEN
;
20975 switch (pnote
->descsz
)
20978 /* A zero-length description means that the range of
20979 the previous note of the same type should be used. */
20982 if (global_end
> global_offset
)
20983 printf (_(" Applies to region from %#lx to %#lx\n"),
20984 global_offset
, global_end
);
20986 printf (_(" Applies to region from %#lx\n"), global_offset
);
20990 if (func_end
> func_offset
)
20991 printf (_(" Applies to region from %#lx to %#lx\n"), func_offset
, func_end
);
20993 printf (_(" Applies to region from %#lx\n"), func_offset
);
20998 start
= byte_get ((unsigned char *) pnote
->descdata
, 4);
21003 start
= byte_get ((unsigned char *) pnote
->descdata
, 4);
21004 end
= byte_get ((unsigned char *) pnote
->descdata
+ 4, 4);
21008 start
= byte_get ((unsigned char *) pnote
->descdata
, 8);
21009 end
= byte_get ((unsigned char *) pnote
->descdata
+ 8, 8);
21013 error (_(" <invalid description size: %lx>\n"), pnote
->descsz
);
21014 printf (_(" <invalid descsz>"));
21019 sym
= get_symbol_for_build_attribute (filedata
, start
, is_open_attr
, & name
);
21020 /* As of version 5 of the annobin plugin, filename symbols are biased by 2
21021 in order to avoid them being confused with the start address of the
21022 first function in the file... */
21023 if (sym
== NULL
&& is_open_attr
)
21024 sym
= get_symbol_for_build_attribute (filedata
, start
+ 2, is_open_attr
,
21027 if (end
== 0 && sym
!= NULL
&& sym
->st_size
> 0)
21028 end
= start
+ sym
->st_size
;
21032 /* FIXME: Need to properly allow for section alignment.
21033 16 is just the alignment used on x86_64. */
21035 && start
> BFD_ALIGN (global_end
, 16)
21036 /* Build notes are not guaranteed to be organised in order of
21037 increasing address, but we should find the all of the notes
21038 for one section in the same place. */
21039 && same_section (filedata
, start
, global_end
))
21040 warn (_("Gap in build notes detected from %#lx to %#lx\n"),
21041 global_end
+ 1, start
- 1);
21043 printf (_(" Applies to region from %#lx"), start
);
21044 global_offset
= start
;
21048 printf (_(" to %#lx"), end
);
21054 printf (_(" Applies to region from %#lx"), start
);
21055 func_offset
= start
;
21059 printf (_(" to %#lx"), end
);
21065 printf (_(" (%s)"), name
);
21072 print_gnu_build_attribute_name (Elf_Internal_Note
* pnote
)
21074 static const char string_expected
[2] = { GNU_BUILD_ATTRIBUTE_TYPE_STRING
, 0 };
21075 static const char number_expected
[2] = { GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC
, 0 };
21076 static const char bool_expected
[3] = { GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE
, GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE
, 0 };
21078 char name_attribute
;
21079 const char * expected_types
;
21080 const char * name
= pnote
->namedata
;
21084 if (name
== NULL
|| pnote
->namesz
< 2)
21086 error (_("corrupt name field in GNU build attribute note: size = %ld\n"), pnote
->namesz
);
21087 print_symbol (-20, _(" <corrupt name>"));
21096 /* Version 2 of the spec adds a "GA" prefix to the name field. */
21097 if (name
[0] == 'G' && name
[1] == 'A')
21099 if (pnote
->namesz
< 4)
21101 error (_("corrupt name field in GNU build attribute note: size = %ld\n"), pnote
->namesz
);
21102 print_symbol (-20, _(" <corrupt name>"));
21111 switch ((name_type
= * name
))
21113 case GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC
:
21114 case GNU_BUILD_ATTRIBUTE_TYPE_STRING
:
21115 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE
:
21116 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE
:
21117 printf ("%c", * name
);
21121 error (_("unrecognised attribute type in name field: %d\n"), name_type
);
21122 print_symbol (-20, _("<unknown name type>"));
21129 switch ((name_attribute
= * name
))
21131 case GNU_BUILD_ATTRIBUTE_VERSION
:
21132 text
= _("<version>");
21133 expected_types
= string_expected
;
21136 case GNU_BUILD_ATTRIBUTE_STACK_PROT
:
21137 text
= _("<stack prot>");
21138 expected_types
= "!+*";
21141 case GNU_BUILD_ATTRIBUTE_RELRO
:
21142 text
= _("<relro>");
21143 expected_types
= bool_expected
;
21146 case GNU_BUILD_ATTRIBUTE_STACK_SIZE
:
21147 text
= _("<stack size>");
21148 expected_types
= number_expected
;
21151 case GNU_BUILD_ATTRIBUTE_TOOL
:
21152 text
= _("<tool>");
21153 expected_types
= string_expected
;
21156 case GNU_BUILD_ATTRIBUTE_ABI
:
21158 expected_types
= "$*";
21161 case GNU_BUILD_ATTRIBUTE_PIC
:
21163 expected_types
= number_expected
;
21166 case GNU_BUILD_ATTRIBUTE_SHORT_ENUM
:
21167 text
= _("<short enum>");
21168 expected_types
= bool_expected
;
21172 if (ISPRINT (* name
))
21174 int len
= strnlen (name
, pnote
->namesz
- (name
- pnote
->namedata
)) + 1;
21176 if (len
> left
&& ! do_wide
)
21178 printf ("%.*s:", len
, name
);
21184 static char tmpbuf
[128];
21186 error (_("unrecognised byte in name field: %d\n"), * name
);
21187 sprintf (tmpbuf
, _("<unknown:_%d>"), * name
);
21191 expected_types
= "*$!+";
21196 left
-= printf ("%s", text
);
21198 if (strchr (expected_types
, name_type
) == NULL
)
21199 warn (_("attribute does not have an expected type (%c)\n"), name_type
);
21201 if ((unsigned long)(name
- pnote
->namedata
) > pnote
->namesz
)
21203 error (_("corrupt name field: namesz: %lu but parsing gets to %ld\n"),
21204 (unsigned long) pnote
->namesz
,
21205 (long) (name
- pnote
->namedata
));
21209 if (left
< 1 && ! do_wide
)
21214 case GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC
:
21216 unsigned int bytes
;
21217 unsigned long long val
= 0;
21218 unsigned int shift
= 0;
21219 char * decoded
= NULL
;
21221 bytes
= pnote
->namesz
- (name
- pnote
->namedata
);
21223 /* The -1 is because the name field is always 0 terminated, and we
21224 want to be able to ensure that the shift in the while loop below
21225 will not overflow. */
21228 if (bytes
> sizeof (val
))
21230 error (_("corrupt numeric name field: too many bytes in the value: %x\n"),
21232 bytes
= sizeof (val
);
21234 /* We do not bother to warn if bytes == 0 as this can
21235 happen with some early versions of the gcc plugin. */
21239 unsigned long long byte
= *name
++ & 0xff;
21241 val
|= byte
<< shift
;
21245 switch (name_attribute
)
21247 case GNU_BUILD_ATTRIBUTE_PIC
:
21250 case 0: decoded
= "static"; break;
21251 case 1: decoded
= "pic"; break;
21252 case 2: decoded
= "PIC"; break;
21253 case 3: decoded
= "pie"; break;
21254 case 4: decoded
= "PIE"; break;
21258 case GNU_BUILD_ATTRIBUTE_STACK_PROT
:
21261 /* Based upon the SPCT_FLAG_xxx enum values in gcc/cfgexpand.c. */
21262 case 0: decoded
= "off"; break;
21263 case 1: decoded
= "on"; break;
21264 case 2: decoded
= "all"; break;
21265 case 3: decoded
= "strong"; break;
21266 case 4: decoded
= "explicit"; break;
21274 if (decoded
!= NULL
)
21276 print_symbol (-left
, decoded
);
21287 left
-= printf ("0x%llx", val
);
21289 left
-= printf ("0x%-.*llx", left
, val
);
21293 case GNU_BUILD_ATTRIBUTE_TYPE_STRING
:
21294 left
-= print_symbol (- left
, name
);
21296 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE
:
21297 left
-= print_symbol (- left
, "true");
21299 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE
:
21300 left
-= print_symbol (- left
, "false");
21304 if (do_wide
&& left
> 0)
21305 printf ("%-*s", left
, " ");
21310 /* Note that by the ELF standard, the name field is already null byte
21311 terminated, and namesz includes the terminating null byte.
21312 I.E. the value of namesz for the name "FSF" is 4.
21314 If the value of namesz is zero, there is no name present. */
21317 process_note (Elf_Internal_Note
* pnote
,
21318 Filedata
* filedata
)
21320 const char * name
= pnote
->namesz
? pnote
->namedata
: "(NONE)";
21323 if (pnote
->namesz
== 0)
21324 /* If there is no note name, then use the default set of
21325 note type strings. */
21326 nt
= get_note_type (filedata
, pnote
->type
);
21328 else if (startswith (pnote
->namedata
, "GNU"))
21329 /* GNU-specific object file notes. */
21330 nt
= get_gnu_elf_note_type (pnote
->type
);
21332 else if (startswith (pnote
->namedata
, "AMDGPU"))
21333 /* AMDGPU-specific object file notes. */
21334 nt
= get_amdgpu_elf_note_type (pnote
->type
);
21336 else if (startswith (pnote
->namedata
, "FreeBSD"))
21337 /* FreeBSD-specific core file notes. */
21338 nt
= get_freebsd_elfcore_note_type (filedata
, pnote
->type
);
21340 else if (startswith (pnote
->namedata
, "NetBSD-CORE"))
21341 /* NetBSD-specific core file notes. */
21342 nt
= get_netbsd_elfcore_note_type (filedata
, pnote
->type
);
21344 else if (startswith (pnote
->namedata
, "NetBSD"))
21345 /* NetBSD-specific core file notes. */
21346 return process_netbsd_elf_note (pnote
);
21348 else if (startswith (pnote
->namedata
, "PaX"))
21349 /* NetBSD-specific core file notes. */
21350 return process_netbsd_elf_note (pnote
);
21352 else if (startswith (pnote
->namedata
, "OpenBSD"))
21353 /* OpenBSD-specific core file notes. */
21354 nt
= get_openbsd_elfcore_note_type (filedata
, pnote
->type
);
21356 else if (startswith (pnote
->namedata
, "SPU/"))
21358 /* SPU-specific core file notes. */
21359 nt
= pnote
->namedata
+ 4;
21363 else if (startswith (pnote
->namedata
, "IPF/VMS"))
21364 /* VMS/ia64-specific file notes. */
21365 nt
= get_ia64_vms_note_type (pnote
->type
);
21367 else if (startswith (pnote
->namedata
, "stapsdt"))
21368 nt
= get_stapsdt_note_type (pnote
->type
);
21371 /* Don't recognize this note name; just use the default set of
21372 note type strings. */
21373 nt
= get_note_type (filedata
, pnote
->type
);
21377 if (((startswith (pnote
->namedata
, "GA")
21378 && strchr ("*$!+", pnote
->namedata
[2]) != NULL
)
21379 || strchr ("*$!+", pnote
->namedata
[0]) != NULL
)
21380 && (pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_OPEN
21381 || pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_FUNC
))
21382 print_gnu_build_attribute_name (pnote
);
21384 print_symbol (-20, name
);
21387 printf (" 0x%08lx\t%s\t", pnote
->descsz
, nt
);
21389 printf (" 0x%08lx\t%s\n", pnote
->descsz
, nt
);
21391 if (startswith (pnote
->namedata
, "IPF/VMS"))
21392 return print_ia64_vms_note (pnote
);
21393 else if (startswith (pnote
->namedata
, "GNU"))
21394 return print_gnu_note (filedata
, pnote
);
21395 else if (startswith (pnote
->namedata
, "stapsdt"))
21396 return print_stapsdt_note (pnote
);
21397 else if (startswith (pnote
->namedata
, "CORE"))
21398 return print_core_note (pnote
);
21399 else if (startswith (pnote
->namedata
, "FDO"))
21400 return print_fdo_note (pnote
);
21401 else if (((startswith (pnote
->namedata
, "GA")
21402 && strchr ("*$!+", pnote
->namedata
[2]) != NULL
)
21403 || strchr ("*$!+", pnote
->namedata
[0]) != NULL
)
21404 && (pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_OPEN
21405 || pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_FUNC
))
21406 return print_gnu_build_attribute_description (pnote
, filedata
);
21412 printf (_(" description data: "));
21413 for (i
= 0; i
< pnote
->descsz
; i
++)
21414 printf ("%02x ", pnote
->descdata
[i
] & 0xff);
21426 process_notes_at (Filedata
* filedata
,
21427 Elf_Internal_Shdr
* section
,
21432 Elf_External_Note
*pnotes
;
21433 Elf_External_Note
*external
;
21442 pnotes
= (Elf_External_Note
*) get_section_contents (section
, filedata
);
21445 if (! apply_relocations (filedata
, section
, (unsigned char *) pnotes
, length
, NULL
, NULL
))
21453 pnotes
= (Elf_External_Note
*) get_data (NULL
, filedata
, offset
, 1, length
,
21456 if (pnotes
== NULL
)
21461 if (filedata
->is_separate
)
21462 printf (_("In linked file '%s': "), filedata
->file_name
);
21466 printf (_("Displaying notes found in: %s\n"), printable_section_name (filedata
, section
));
21468 printf (_("Displaying notes found at file offset 0x%08lx with length 0x%08lx:\n"),
21469 (unsigned long) offset
, (unsigned long) length
);
21471 /* NB: Some note sections may have alignment value of 0 or 1. gABI
21472 specifies that notes should be aligned to 4 bytes in 32-bit
21473 objects and to 8 bytes in 64-bit objects. As a Linux extension,
21474 we also support 4 byte alignment in 64-bit objects. If section
21475 alignment is less than 4, we treate alignment as 4 bytes. */
21478 else if (align
!= 4 && align
!= 8)
21480 warn (_("Corrupt note: alignment %ld, expecting 4 or 8\n"),
21486 printf (_(" %-20s %-10s\tDescription\n"), _("Owner"), _("Data size"));
21488 end
= (char *) pnotes
+ length
;
21489 while ((char *) external
< end
)
21491 Elf_Internal_Note inote
;
21494 char * temp
= NULL
;
21495 size_t data_remaining
= end
- (char *) external
;
21497 if (!is_ia64_vms (filedata
))
21499 /* PR binutils/15191
21500 Make sure that there is enough data to read. */
21501 min_notesz
= offsetof (Elf_External_Note
, name
);
21502 if (data_remaining
< min_notesz
)
21504 warn (ngettext ("Corrupt note: only %ld byte remains, "
21505 "not enough for a full note\n",
21506 "Corrupt note: only %ld bytes remain, "
21507 "not enough for a full note\n",
21509 (long) data_remaining
);
21512 data_remaining
-= min_notesz
;
21514 inote
.type
= BYTE_GET (external
->type
);
21515 inote
.namesz
= BYTE_GET (external
->namesz
);
21516 inote
.namedata
= external
->name
;
21517 inote
.descsz
= BYTE_GET (external
->descsz
);
21518 inote
.descdata
= ((char *) external
21519 + ELF_NOTE_DESC_OFFSET (inote
.namesz
, align
));
21520 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
21521 next
= ((char *) external
21522 + ELF_NOTE_NEXT_OFFSET (inote
.namesz
, inote
.descsz
, align
));
21526 Elf64_External_VMS_Note
*vms_external
;
21528 /* PR binutils/15191
21529 Make sure that there is enough data to read. */
21530 min_notesz
= offsetof (Elf64_External_VMS_Note
, name
);
21531 if (data_remaining
< min_notesz
)
21533 warn (ngettext ("Corrupt note: only %ld byte remains, "
21534 "not enough for a full note\n",
21535 "Corrupt note: only %ld bytes remain, "
21536 "not enough for a full note\n",
21538 (long) data_remaining
);
21541 data_remaining
-= min_notesz
;
21543 vms_external
= (Elf64_External_VMS_Note
*) external
;
21544 inote
.type
= BYTE_GET (vms_external
->type
);
21545 inote
.namesz
= BYTE_GET (vms_external
->namesz
);
21546 inote
.namedata
= vms_external
->name
;
21547 inote
.descsz
= BYTE_GET (vms_external
->descsz
);
21548 inote
.descdata
= inote
.namedata
+ align_power (inote
.namesz
, 3);
21549 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
21550 next
= inote
.descdata
+ align_power (inote
.descsz
, 3);
21553 /* PR 17531: file: 3443835e. */
21554 /* PR 17531: file: id:000000,sig:11,src:006986,op:havoc,rep:4. */
21555 if ((size_t) (inote
.descdata
- inote
.namedata
) < inote
.namesz
21556 || (size_t) (inote
.descdata
- inote
.namedata
) > data_remaining
21557 || (size_t) (next
- inote
.descdata
) < inote
.descsz
21558 || ((size_t) (next
- inote
.descdata
)
21559 > data_remaining
- (size_t) (inote
.descdata
- inote
.namedata
)))
21561 warn (_("note with invalid namesz and/or descsz found at offset 0x%lx\n"),
21562 (unsigned long) ((char *) external
- (char *) pnotes
));
21563 warn (_(" type: 0x%lx, namesize: 0x%08lx, descsize: 0x%08lx, alignment: %u\n"),
21564 inote
.type
, inote
.namesz
, inote
.descsz
, (int) align
);
21568 external
= (Elf_External_Note
*) next
;
21570 /* Verify that name is null terminated. It appears that at least
21571 one version of Linux (RedHat 6.0) generates corefiles that don't
21572 comply with the ELF spec by failing to include the null byte in
21574 if (inote
.namesz
> 0 && inote
.namedata
[inote
.namesz
- 1] != '\0')
21576 if ((size_t) (inote
.descdata
- inote
.namedata
) == inote
.namesz
)
21578 temp
= (char *) malloc (inote
.namesz
+ 1);
21581 error (_("Out of memory allocating space for inote name\n"));
21586 memcpy (temp
, inote
.namedata
, inote
.namesz
);
21587 inote
.namedata
= temp
;
21589 inote
.namedata
[inote
.namesz
] = 0;
21592 if (! process_note (& inote
, filedata
))
21605 process_corefile_note_segments (Filedata
* filedata
)
21607 Elf_Internal_Phdr
*segment
;
21611 if (! get_program_headers (filedata
))
21614 for (i
= 0, segment
= filedata
->program_headers
;
21615 i
< filedata
->file_header
.e_phnum
;
21618 if (segment
->p_type
== PT_NOTE
)
21619 if (! process_notes_at (filedata
, NULL
,
21620 (bfd_vma
) segment
->p_offset
,
21621 (bfd_vma
) segment
->p_filesz
,
21622 (bfd_vma
) segment
->p_align
))
21630 process_v850_notes (Filedata
* filedata
, bfd_vma offset
, bfd_vma length
)
21632 Elf_External_Note
* pnotes
;
21633 Elf_External_Note
* external
;
21640 pnotes
= (Elf_External_Note
*) get_data (NULL
, filedata
, offset
, 1, length
,
21642 if (pnotes
== NULL
)
21646 end
= (char*) pnotes
+ length
;
21648 printf (_("\nDisplaying contents of Renesas V850 notes section at offset 0x%lx with length 0x%lx:\n"),
21649 (unsigned long) offset
, (unsigned long) length
);
21651 while ((char *) external
+ sizeof (Elf_External_Note
) < end
)
21653 Elf_External_Note
* next
;
21654 Elf_Internal_Note inote
;
21656 inote
.type
= BYTE_GET (external
->type
);
21657 inote
.namesz
= BYTE_GET (external
->namesz
);
21658 inote
.namedata
= external
->name
;
21659 inote
.descsz
= BYTE_GET (external
->descsz
);
21660 inote
.descdata
= inote
.namedata
+ align_power (inote
.namesz
, 2);
21661 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
21663 if (inote
.descdata
< (char *) pnotes
|| inote
.descdata
>= end
)
21665 warn (_("Corrupt note: name size is too big: %lx\n"), inote
.namesz
);
21666 inote
.descdata
= inote
.namedata
;
21670 next
= (Elf_External_Note
*) (inote
.descdata
+ align_power (inote
.descsz
, 2));
21672 if ( ((char *) next
> end
)
21673 || ((char *) next
< (char *) pnotes
))
21675 warn (_("corrupt descsz found in note at offset 0x%lx\n"),
21676 (unsigned long) ((char *) external
- (char *) pnotes
));
21677 warn (_(" type: 0x%lx, namesize: 0x%lx, descsize: 0x%lx\n"),
21678 inote
.type
, inote
.namesz
, inote
.descsz
);
21684 /* Prevent out-of-bounds indexing. */
21685 if ( inote
.namedata
+ inote
.namesz
> end
21686 || inote
.namedata
+ inote
.namesz
< inote
.namedata
)
21688 warn (_("corrupt namesz found in note at offset 0x%lx\n"),
21689 (unsigned long) ((char *) external
- (char *) pnotes
));
21690 warn (_(" type: 0x%lx, namesize: 0x%lx, descsize: 0x%lx\n"),
21691 inote
.type
, inote
.namesz
, inote
.descsz
);
21695 printf (" %s: ", get_v850_elf_note_type (inote
.type
));
21697 if (! print_v850_note (& inote
))
21700 printf ("<corrupt sizes: namesz: %lx, descsz: %lx>\n",
21701 inote
.namesz
, inote
.descsz
);
21711 process_note_sections (Filedata
* filedata
)
21713 Elf_Internal_Shdr
*section
;
21715 unsigned int n
= 0;
21718 for (i
= 0, section
= filedata
->section_headers
;
21719 i
< filedata
->file_header
.e_shnum
&& section
!= NULL
;
21722 if (section
->sh_type
== SHT_NOTE
)
21724 if (! process_notes_at (filedata
, section
,
21725 (bfd_vma
) section
->sh_offset
,
21726 (bfd_vma
) section
->sh_size
,
21727 (bfd_vma
) section
->sh_addralign
))
21732 if (( filedata
->file_header
.e_machine
== EM_V800
21733 || filedata
->file_header
.e_machine
== EM_V850
21734 || filedata
->file_header
.e_machine
== EM_CYGNUS_V850
)
21735 && section
->sh_type
== SHT_RENESAS_INFO
)
21737 if (! process_v850_notes (filedata
,
21738 (bfd_vma
) section
->sh_offset
,
21739 (bfd_vma
) section
->sh_size
))
21746 /* Try processing NOTE segments instead. */
21747 return process_corefile_note_segments (filedata
);
21753 process_notes (Filedata
* filedata
)
21755 /* If we have not been asked to display the notes then do nothing. */
21759 if (filedata
->file_header
.e_type
!= ET_CORE
)
21760 return process_note_sections (filedata
);
21762 /* No program headers means no NOTE segment. */
21763 if (filedata
->file_header
.e_phnum
> 0)
21764 return process_corefile_note_segments (filedata
);
21766 if (filedata
->is_separate
)
21767 printf (_("No notes found in linked file '%s'.\n"),
21768 filedata
->file_name
);
21770 printf (_("No notes found file.\n"));
21775 static unsigned char *
21776 display_public_gnu_attributes (unsigned char * start
,
21777 const unsigned char * const end
)
21779 printf (_(" Unknown GNU attribute: %s\n"), start
);
21781 start
+= strnlen ((char *) start
, end
- start
);
21782 display_raw_attribute (start
, end
);
21784 return (unsigned char *) end
;
21787 static unsigned char *
21788 display_generic_attribute (unsigned char * start
,
21790 const unsigned char * const end
)
21793 return (unsigned char *) end
;
21795 return display_tag_value (tag
, start
, end
);
21799 process_arch_specific (Filedata
* filedata
)
21804 switch (filedata
->file_header
.e_machine
)
21807 case EM_ARC_COMPACT
:
21808 case EM_ARC_COMPACT2
:
21809 return process_attributes (filedata
, "ARC", SHT_ARC_ATTRIBUTES
,
21810 display_arc_attribute
,
21811 display_generic_attribute
);
21813 return process_attributes (filedata
, "aeabi", SHT_ARM_ATTRIBUTES
,
21814 display_arm_attribute
,
21815 display_generic_attribute
);
21818 case EM_MIPS_RS3_LE
:
21819 return process_mips_specific (filedata
);
21822 return process_attributes (filedata
, "mspabi", SHT_MSP430_ATTRIBUTES
,
21823 display_msp430_attribute
,
21824 display_msp430_gnu_attribute
);
21827 return process_attributes (filedata
, "riscv", SHT_RISCV_ATTRIBUTES
,
21828 display_riscv_attribute
,
21829 display_generic_attribute
);
21832 return process_nds32_specific (filedata
);
21835 return process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
21836 display_m68k_gnu_attribute
);
21840 return process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
21841 display_power_gnu_attribute
);
21845 return process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
21846 display_s390_gnu_attribute
);
21849 case EM_SPARC32PLUS
:
21851 return process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
21852 display_sparc_gnu_attribute
);
21855 return process_attributes (filedata
, "c6xabi", SHT_C6000_ATTRIBUTES
,
21856 display_tic6x_attribute
,
21857 display_generic_attribute
);
21860 return process_attributes (filedata
, "csky", SHT_CSKY_ATTRIBUTES
,
21861 display_csky_attribute
, NULL
);
21864 return process_attributes (filedata
, "gnu", SHT_GNU_ATTRIBUTES
,
21865 display_public_gnu_attributes
,
21866 display_generic_attribute
);
21871 get_file_header (Filedata
* filedata
)
21873 /* Read in the identity array. */
21874 if (fread (filedata
->file_header
.e_ident
, EI_NIDENT
, 1, filedata
->handle
) != 1)
21877 /* Determine how to read the rest of the header. */
21878 switch (filedata
->file_header
.e_ident
[EI_DATA
])
21883 byte_get
= byte_get_little_endian
;
21884 byte_put
= byte_put_little_endian
;
21887 byte_get
= byte_get_big_endian
;
21888 byte_put
= byte_put_big_endian
;
21892 /* For now we only support 32 bit and 64 bit ELF files. */
21893 is_32bit_elf
= (filedata
->file_header
.e_ident
[EI_CLASS
] != ELFCLASS64
);
21895 /* Read in the rest of the header. */
21898 Elf32_External_Ehdr ehdr32
;
21900 if (fread (ehdr32
.e_type
, sizeof (ehdr32
) - EI_NIDENT
, 1, filedata
->handle
) != 1)
21903 filedata
->file_header
.e_type
= BYTE_GET (ehdr32
.e_type
);
21904 filedata
->file_header
.e_machine
= BYTE_GET (ehdr32
.e_machine
);
21905 filedata
->file_header
.e_version
= BYTE_GET (ehdr32
.e_version
);
21906 filedata
->file_header
.e_entry
= BYTE_GET (ehdr32
.e_entry
);
21907 filedata
->file_header
.e_phoff
= BYTE_GET (ehdr32
.e_phoff
);
21908 filedata
->file_header
.e_shoff
= BYTE_GET (ehdr32
.e_shoff
);
21909 filedata
->file_header
.e_flags
= BYTE_GET (ehdr32
.e_flags
);
21910 filedata
->file_header
.e_ehsize
= BYTE_GET (ehdr32
.e_ehsize
);
21911 filedata
->file_header
.e_phentsize
= BYTE_GET (ehdr32
.e_phentsize
);
21912 filedata
->file_header
.e_phnum
= BYTE_GET (ehdr32
.e_phnum
);
21913 filedata
->file_header
.e_shentsize
= BYTE_GET (ehdr32
.e_shentsize
);
21914 filedata
->file_header
.e_shnum
= BYTE_GET (ehdr32
.e_shnum
);
21915 filedata
->file_header
.e_shstrndx
= BYTE_GET (ehdr32
.e_shstrndx
);
21919 Elf64_External_Ehdr ehdr64
;
21921 /* If we have been compiled with sizeof (bfd_vma) == 4, then
21922 we will not be able to cope with the 64bit data found in
21923 64 ELF files. Detect this now and abort before we start
21924 overwriting things. */
21925 if (sizeof (bfd_vma
) < 8)
21927 error (_("This instance of readelf has been built without support for a\n\
21928 64 bit data type and so it cannot read 64 bit ELF files.\n"));
21932 if (fread (ehdr64
.e_type
, sizeof (ehdr64
) - EI_NIDENT
, 1, filedata
->handle
) != 1)
21935 filedata
->file_header
.e_type
= BYTE_GET (ehdr64
.e_type
);
21936 filedata
->file_header
.e_machine
= BYTE_GET (ehdr64
.e_machine
);
21937 filedata
->file_header
.e_version
= BYTE_GET (ehdr64
.e_version
);
21938 filedata
->file_header
.e_entry
= BYTE_GET (ehdr64
.e_entry
);
21939 filedata
->file_header
.e_phoff
= BYTE_GET (ehdr64
.e_phoff
);
21940 filedata
->file_header
.e_shoff
= BYTE_GET (ehdr64
.e_shoff
);
21941 filedata
->file_header
.e_flags
= BYTE_GET (ehdr64
.e_flags
);
21942 filedata
->file_header
.e_ehsize
= BYTE_GET (ehdr64
.e_ehsize
);
21943 filedata
->file_header
.e_phentsize
= BYTE_GET (ehdr64
.e_phentsize
);
21944 filedata
->file_header
.e_phnum
= BYTE_GET (ehdr64
.e_phnum
);
21945 filedata
->file_header
.e_shentsize
= BYTE_GET (ehdr64
.e_shentsize
);
21946 filedata
->file_header
.e_shnum
= BYTE_GET (ehdr64
.e_shnum
);
21947 filedata
->file_header
.e_shstrndx
= BYTE_GET (ehdr64
.e_shstrndx
);
21954 free_filedata (Filedata
*filedata
)
21956 free (filedata
->program_interpreter
);
21957 free (filedata
->program_headers
);
21958 free (filedata
->section_headers
);
21959 free (filedata
->string_table
);
21960 free (filedata
->dump
.dump_sects
);
21961 free (filedata
->dynamic_strings
);
21962 free (filedata
->dynamic_symbols
);
21963 free (filedata
->dynamic_syminfo
);
21964 free (filedata
->dynamic_section
);
21966 while (filedata
->symtab_shndx_list
!= NULL
)
21968 elf_section_list
*next
= filedata
->symtab_shndx_list
->next
;
21969 free (filedata
->symtab_shndx_list
);
21970 filedata
->symtab_shndx_list
= next
;
21973 free (filedata
->section_headers_groups
);
21975 if (filedata
->section_groups
)
21978 struct group_list
* g
;
21979 struct group_list
* next
;
21981 for (i
= 0; i
< filedata
->group_count
; i
++)
21983 for (g
= filedata
->section_groups
[i
].root
; g
!= NULL
; g
= next
)
21990 free (filedata
->section_groups
);
21992 memset (&filedata
->section_headers
, 0,
21993 sizeof (Filedata
) - offsetof (Filedata
, section_headers
));
21997 close_file (Filedata
* filedata
)
22001 if (filedata
->handle
)
22002 fclose (filedata
->handle
);
22008 close_debug_file (void * data
)
22010 free_filedata ((Filedata
*) data
);
22011 close_file ((Filedata
*) data
);
22015 open_file (const char * pathname
, bool is_separate
)
22017 struct stat statbuf
;
22018 Filedata
* filedata
= NULL
;
22020 if (stat (pathname
, & statbuf
) < 0
22021 || ! S_ISREG (statbuf
.st_mode
))
22024 filedata
= calloc (1, sizeof * filedata
);
22025 if (filedata
== NULL
)
22028 filedata
->handle
= fopen (pathname
, "rb");
22029 if (filedata
->handle
== NULL
)
22032 filedata
->file_size
= (bfd_size_type
) statbuf
.st_size
;
22033 filedata
->file_name
= pathname
;
22034 filedata
->is_separate
= is_separate
;
22036 if (! get_file_header (filedata
))
22039 if (!get_section_headers (filedata
, false))
22047 if (filedata
->handle
)
22048 fclose (filedata
->handle
);
22055 open_debug_file (const char * pathname
)
22057 return open_file (pathname
, true);
22061 initialise_dump_sects (Filedata
* filedata
)
22063 /* Initialise the dump_sects array from the cmdline_dump_sects array.
22064 Note we do this even if cmdline_dump_sects is empty because we
22065 must make sure that the dump_sets array is zeroed out before each
22066 object file is processed. */
22067 if (filedata
->dump
.num_dump_sects
> cmdline
.num_dump_sects
)
22068 memset (filedata
->dump
.dump_sects
, 0,
22069 filedata
->dump
.num_dump_sects
* sizeof (*filedata
->dump
.dump_sects
));
22071 if (cmdline
.num_dump_sects
> 0)
22073 if (filedata
->dump
.num_dump_sects
== 0)
22074 /* A sneaky way of allocating the dump_sects array. */
22075 request_dump_bynumber (&filedata
->dump
, cmdline
.num_dump_sects
, 0);
22077 assert (filedata
->dump
.num_dump_sects
>= cmdline
.num_dump_sects
);
22078 memcpy (filedata
->dump
.dump_sects
, cmdline
.dump_sects
,
22079 cmdline
.num_dump_sects
* sizeof (*filedata
->dump
.dump_sects
));
22083 /* Process one ELF object file according to the command line options.
22084 This file may actually be stored in an archive. The file is
22085 positioned at the start of the ELF object. Returns TRUE if no
22086 problems were encountered, FALSE otherwise. */
22089 process_object (Filedata
* filedata
)
22091 bool have_separate_files
;
22095 if (! get_file_header (filedata
))
22097 error (_("%s: Failed to read file header\n"), filedata
->file_name
);
22101 /* Initialise per file variables. */
22102 for (i
= ARRAY_SIZE (filedata
->version_info
); i
--;)
22103 filedata
->version_info
[i
] = 0;
22105 for (i
= ARRAY_SIZE (filedata
->dynamic_info
); i
--;)
22106 filedata
->dynamic_info
[i
] = 0;
22107 filedata
->dynamic_info_DT_GNU_HASH
= 0;
22108 filedata
->dynamic_info_DT_MIPS_XHASH
= 0;
22110 /* Process the file. */
22112 printf (_("\nFile: %s\n"), filedata
->file_name
);
22114 initialise_dump_sects (filedata
);
22116 /* There may be some extensions in the first section header. Don't
22117 bomb if we can't read it. */
22118 get_section_headers (filedata
, true);
22120 if (! process_file_header (filedata
))
22126 /* Throw away the single section header read above, so that we
22127 re-read the entire set. */
22128 free (filedata
->section_headers
);
22129 filedata
->section_headers
= NULL
;
22131 if (! process_section_headers (filedata
))
22133 /* Without loaded section headers we cannot process lots of things. */
22134 do_unwind
= do_version
= do_dump
= do_arch
= false;
22136 if (! do_using_dynamic
)
22137 do_syms
= do_dyn_syms
= do_reloc
= false;
22140 if (! process_section_groups (filedata
))
22141 /* Without loaded section groups we cannot process unwind. */
22144 process_program_headers (filedata
);
22146 res
= process_dynamic_section (filedata
);
22148 if (! process_relocs (filedata
))
22151 if (! process_unwind (filedata
))
22154 if (! process_symbol_table (filedata
))
22157 if (! process_lto_symbol_tables (filedata
))
22160 if (! process_syminfo (filedata
))
22163 if (! process_version_sections (filedata
))
22166 if (filedata
->file_header
.e_shstrndx
!= SHN_UNDEF
)
22167 have_separate_files
= load_separate_debug_files (filedata
, filedata
->file_name
);
22169 have_separate_files
= false;
22171 if (! process_section_contents (filedata
))
22174 if (have_separate_files
)
22178 for (d
= first_separate_info
; d
!= NULL
; d
= d
->next
)
22180 initialise_dump_sects (d
->handle
);
22182 if (process_links
&& ! process_file_header (d
->handle
))
22184 else if (! process_section_headers (d
->handle
))
22186 else if (! process_section_contents (d
->handle
))
22188 else if (process_links
)
22190 if (! process_section_groups (d
->handle
))
22192 process_program_headers (d
->handle
);
22193 if (! process_dynamic_section (d
->handle
))
22195 if (! process_relocs (d
->handle
))
22197 if (! process_unwind (d
->handle
))
22199 if (! process_symbol_table (d
->handle
))
22201 if (! process_lto_symbol_tables (d
->handle
))
22203 if (! process_syminfo (d
->handle
))
22205 if (! process_version_sections (d
->handle
))
22207 if (! process_notes (d
->handle
))
22212 /* The file handles are closed by the call to free_debug_memory() below. */
22215 if (! process_notes (filedata
))
22218 if (! process_gnu_liblist (filedata
))
22221 if (! process_arch_specific (filedata
))
22225 free_filedata (filedata
);
22227 free_debug_memory ();
22232 /* Process an ELF archive.
22233 On entry the file is positioned just after the ARMAG string.
22234 Returns TRUE upon success, FALSE otherwise. */
22237 process_archive (Filedata
* filedata
, bool is_thin_archive
)
22239 struct archive_info arch
;
22240 struct archive_info nested_arch
;
22246 /* The ARCH structure is used to hold information about this archive. */
22247 arch
.file_name
= NULL
;
22249 arch
.index_array
= NULL
;
22250 arch
.sym_table
= NULL
;
22251 arch
.longnames
= NULL
;
22253 /* The NESTED_ARCH structure is used as a single-item cache of information
22254 about a nested archive (when members of a thin archive reside within
22255 another regular archive file). */
22256 nested_arch
.file_name
= NULL
;
22257 nested_arch
.file
= NULL
;
22258 nested_arch
.index_array
= NULL
;
22259 nested_arch
.sym_table
= NULL
;
22260 nested_arch
.longnames
= NULL
;
22262 if (setup_archive (&arch
, filedata
->file_name
, filedata
->handle
,
22263 filedata
->file_size
, is_thin_archive
,
22264 do_archive_index
) != 0)
22270 if (do_archive_index
)
22272 if (arch
.sym_table
== NULL
)
22273 error (_("%s: unable to dump the index as none was found\n"),
22274 filedata
->file_name
);
22277 unsigned long i
, l
;
22278 unsigned long current_pos
;
22280 printf (_("Index of archive %s: (%lu entries, 0x%lx bytes "
22281 "in the symbol table)\n"),
22282 filedata
->file_name
, (unsigned long) arch
.index_num
,
22285 current_pos
= ftell (filedata
->handle
);
22287 for (i
= l
= 0; i
< arch
.index_num
; i
++)
22290 || (i
> 0 && arch
.index_array
[i
] != arch
.index_array
[i
- 1]))
22293 = get_archive_member_name_at (&arch
, arch
.index_array
[i
],
22296 if (member_name
!= NULL
)
22298 char * qualified_name
22299 = make_qualified_name (&arch
, &nested_arch
,
22302 if (qualified_name
!= NULL
)
22304 printf (_("Contents of binary %s at offset "),
22306 (void) print_vma (arch
.index_array
[i
], PREFIX_HEX
);
22308 free (qualified_name
);
22310 free (member_name
);
22314 if (l
>= arch
.sym_size
)
22316 error (_("%s: end of the symbol table reached "
22317 "before the end of the index\n"),
22318 filedata
->file_name
);
22322 /* PR 17531: file: 0b6630b2. */
22323 printf ("\t%.*s\n",
22324 (int) (arch
.sym_size
- l
), arch
.sym_table
+ l
);
22325 l
+= strnlen (arch
.sym_table
+ l
, arch
.sym_size
- l
) + 1;
22328 if (arch
.uses_64bit_indices
)
22333 if (l
< arch
.sym_size
)
22335 error (ngettext ("%s: %ld byte remains in the symbol table, "
22336 "but without corresponding entries in "
22337 "the index table\n",
22338 "%s: %ld bytes remain in the symbol table, "
22339 "but without corresponding entries in "
22340 "the index table\n",
22341 arch
.sym_size
- l
),
22342 filedata
->file_name
, arch
.sym_size
- l
);
22346 if (fseek (filedata
->handle
, current_pos
, SEEK_SET
) != 0)
22348 error (_("%s: failed to seek back to start of object files "
22349 "in the archive\n"),
22350 filedata
->file_name
);
22356 if (!do_dynamic
&& !do_syms
&& !do_reloc
&& !do_unwind
&& !do_sections
22357 && !do_segments
&& !do_header
&& !do_dump
&& !do_version
22358 && !do_histogram
&& !do_debugging
&& !do_arch
&& !do_notes
22359 && !do_section_groups
&& !do_dyn_syms
)
22361 ret
= true; /* Archive index only. */
22370 char * qualified_name
;
22372 /* Read the next archive header. */
22373 if (fseek (filedata
->handle
, arch
.next_arhdr_offset
, SEEK_SET
) != 0)
22375 error (_("%s: failed to seek to next archive header\n"),
22380 got
= fread (&arch
.arhdr
, 1, sizeof arch
.arhdr
, filedata
->handle
);
22381 if (got
!= sizeof arch
.arhdr
)
22385 /* PR 24049 - we cannot use filedata->file_name as this will
22386 have already been freed. */
22387 error (_("%s: failed to read archive header\n"), arch
.file_name
);
22392 if (memcmp (arch
.arhdr
.ar_fmag
, ARFMAG
, 2) != 0)
22394 error (_("%s: did not find a valid archive header\n"),
22400 arch
.next_arhdr_offset
+= sizeof arch
.arhdr
;
22402 filedata
->archive_file_size
= strtoul (arch
.arhdr
.ar_size
, NULL
, 10);
22404 name
= get_archive_member_name (&arch
, &nested_arch
);
22407 error (_("%s: bad archive file name\n"), arch
.file_name
);
22411 namelen
= strlen (name
);
22413 qualified_name
= make_qualified_name (&arch
, &nested_arch
, name
);
22414 if (qualified_name
== NULL
)
22416 error (_("%s: bad archive file name\n"), arch
.file_name
);
22422 if (is_thin_archive
&& arch
.nested_member_origin
== 0)
22424 /* This is a proxy for an external member of a thin archive. */
22425 Filedata
* member_filedata
;
22426 char * member_file_name
= adjust_relative_path
22427 (filedata
->file_name
, name
, namelen
);
22430 if (member_file_name
== NULL
)
22432 free (qualified_name
);
22437 member_filedata
= open_file (member_file_name
, false);
22438 if (member_filedata
== NULL
)
22440 error (_("Input file '%s' is not readable.\n"), member_file_name
);
22441 free (member_file_name
);
22442 free (qualified_name
);
22447 filedata
->archive_file_offset
= arch
.nested_member_origin
;
22448 member_filedata
->file_name
= qualified_name
;
22450 /* The call to process_object() expects the file to be at the beginning. */
22451 rewind (member_filedata
->handle
);
22453 if (! process_object (member_filedata
))
22456 close_file (member_filedata
);
22457 free (member_file_name
);
22459 else if (is_thin_archive
)
22461 Filedata thin_filedata
;
22463 memset (&thin_filedata
, 0, sizeof (thin_filedata
));
22465 /* PR 15140: Allow for corrupt thin archives. */
22466 if (nested_arch
.file
== NULL
)
22468 error (_("%s: contains corrupt thin archive: %s\n"),
22469 qualified_name
, name
);
22470 free (qualified_name
);
22477 /* This is a proxy for a member of a nested archive. */
22478 filedata
->archive_file_offset
22479 = arch
.nested_member_origin
+ sizeof arch
.arhdr
;
22481 /* The nested archive file will have been opened and setup by
22482 get_archive_member_name. */
22483 if (fseek (nested_arch
.file
, filedata
->archive_file_offset
,
22486 error (_("%s: failed to seek to archive member.\n"),
22487 nested_arch
.file_name
);
22488 free (qualified_name
);
22493 thin_filedata
.handle
= nested_arch
.file
;
22494 thin_filedata
.file_name
= qualified_name
;
22496 if (! process_object (& thin_filedata
))
22502 filedata
->archive_file_offset
= arch
.next_arhdr_offset
;
22503 filedata
->file_name
= qualified_name
;
22504 if (! process_object (filedata
))
22506 arch
.next_arhdr_offset
+= (filedata
->archive_file_size
+ 1) & -2;
22507 /* Stop looping with "negative" archive_file_size. */
22508 if (arch
.next_arhdr_offset
< filedata
->archive_file_size
)
22509 arch
.next_arhdr_offset
= -1ul;
22512 free (qualified_name
);
22516 if (nested_arch
.file
!= NULL
)
22517 fclose (nested_arch
.file
);
22518 release_archive (&nested_arch
);
22519 release_archive (&arch
);
22525 process_file (char * file_name
)
22527 Filedata
* filedata
= NULL
;
22528 struct stat statbuf
;
22529 char armag
[SARMAG
];
22532 if (stat (file_name
, &statbuf
) < 0)
22534 if (errno
== ENOENT
)
22535 error (_("'%s': No such file\n"), file_name
);
22537 error (_("Could not locate '%s'. System error message: %s\n"),
22538 file_name
, strerror (errno
));
22542 if (! S_ISREG (statbuf
.st_mode
))
22544 error (_("'%s' is not an ordinary file\n"), file_name
);
22548 filedata
= calloc (1, sizeof * filedata
);
22549 if (filedata
== NULL
)
22551 error (_("Out of memory allocating file data structure\n"));
22555 filedata
->file_name
= file_name
;
22556 filedata
->handle
= fopen (file_name
, "rb");
22557 if (filedata
->handle
== NULL
)
22559 error (_("Input file '%s' is not readable.\n"), file_name
);
22564 if (fread (armag
, SARMAG
, 1, filedata
->handle
) != 1)
22566 error (_("%s: Failed to read file's magic number\n"), file_name
);
22567 fclose (filedata
->handle
);
22572 filedata
->file_size
= (bfd_size_type
) statbuf
.st_size
;
22573 filedata
->is_separate
= false;
22575 if (memcmp (armag
, ARMAG
, SARMAG
) == 0)
22577 if (! process_archive (filedata
, false))
22580 else if (memcmp (armag
, ARMAGT
, SARMAG
) == 0)
22582 if ( ! process_archive (filedata
, true))
22587 if (do_archive_index
&& !check_all
)
22588 error (_("File %s is not an archive so its index cannot be displayed.\n"),
22591 rewind (filedata
->handle
);
22592 filedata
->archive_file_size
= filedata
->archive_file_offset
= 0;
22594 if (! process_object (filedata
))
22598 fclose (filedata
->handle
);
22599 free (filedata
->section_headers
);
22600 free (filedata
->program_headers
);
22601 free (filedata
->string_table
);
22602 free (filedata
->dump
.dump_sects
);
22605 free (ba_cache
.strtab
);
22606 ba_cache
.strtab
= NULL
;
22607 free (ba_cache
.symtab
);
22608 ba_cache
.symtab
= NULL
;
22609 ba_cache
.filedata
= NULL
;
22614 #ifdef SUPPORT_DISASSEMBLY
22615 /* Needed by the i386 disassembler. For extra credit, someone could
22616 fix this so that we insert symbolic addresses here, esp for GOT/PLT
22620 print_address (unsigned int addr
, FILE * outfile
)
22622 fprintf (outfile
,"0x%8.8x", addr
);
22625 /* Needed by the i386 disassembler. */
22628 db_task_printsym (unsigned int addr
)
22630 print_address (addr
, stderr
);
22635 main (int argc
, char ** argv
)
22639 #ifdef HAVE_LC_MESSAGES
22640 setlocale (LC_MESSAGES
, "");
22642 setlocale (LC_CTYPE
, "");
22643 bindtextdomain (PACKAGE
, LOCALEDIR
);
22644 textdomain (PACKAGE
);
22646 expandargv (&argc
, &argv
);
22648 parse_args (& cmdline
, argc
, argv
);
22650 if (optind
< (argc
- 1))
22651 /* When displaying information for more than one file,
22652 prefix the information with the file name. */
22654 else if (optind
>= argc
)
22656 /* Ensure that the warning is always displayed. */
22659 warn (_("Nothing to do.\n"));
22664 while (optind
< argc
)
22665 if (! process_file (argv
[optind
++]))
22668 free (cmdline
.dump_sects
);
22670 free (dump_ctf_symtab_name
);
22671 free (dump_ctf_strtab_name
);
22672 free (dump_ctf_parent_name
);
22674 return err
? EXIT_FAILURE
: EXIT_SUCCESS
;