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. */
49 #if defined HAVE_MSGPACK
54 /* Define BFD64 here, even if our default architecture is 32 bit ELF
55 as this will allow us to read in and parse 64bit and 32bit ELF files.
56 Only do this if we believe that the compiler can support a 64 bit
57 data type. For now we only rely on GCC being able to do this. */
64 #include "demanguse.h"
69 #include "elf/common.h"
70 #include "elf/external.h"
71 #include "elf/internal.h"
74 /* Included here, before RELOC_MACROS_GEN_FUNC is defined, so that
75 we can obtain the H8 reloc numbers. We need these for the
76 get_reloc_size() function. We include h8.h again after defining
77 RELOC_MACROS_GEN_FUNC so that we get the naming function as well. */
82 /* Undo the effects of #including reloc-macros.h. */
84 #undef START_RELOC_NUMBERS
88 #undef END_RELOC_NUMBERS
89 #undef _RELOC_MACROS_H
91 /* The following headers use the elf/reloc-macros.h file to
92 automatically generate relocation recognition functions
93 such as elf_mips_reloc_type() */
95 #define RELOC_MACROS_GEN_FUNC
97 #include "elf/aarch64.h"
98 #include "elf/alpha.h"
99 #include "elf/amdgpu.h"
103 #include "elf/bfin.h"
104 #include "elf/cr16.h"
105 #include "elf/cris.h"
107 #include "elf/csky.h"
108 #include "elf/d10v.h"
109 #include "elf/d30v.h"
112 #include "elf/epiphany.h"
113 #include "elf/fr30.h"
115 #include "elf/ft32.h"
117 #include "elf/hppa.h"
118 #include "elf/i386.h"
119 #include "elf/i370.h"
120 #include "elf/i860.h"
121 #include "elf/i960.h"
122 #include "elf/ia64.h"
123 #include "elf/ip2k.h"
124 #include "elf/lm32.h"
125 #include "elf/iq2000.h"
126 #include "elf/m32c.h"
127 #include "elf/m32r.h"
128 #include "elf/m68k.h"
129 #include "elf/m68hc11.h"
130 #include "elf/s12z.h"
131 #include "elf/mcore.h"
133 #include "elf/metag.h"
134 #include "elf/microblaze.h"
135 #include "elf/mips.h"
136 #include "elf/mmix.h"
137 #include "elf/mn10200.h"
138 #include "elf/mn10300.h"
139 #include "elf/moxie.h"
141 #include "elf/msp430.h"
142 #include "elf/nds32.h"
144 #include "elf/nios2.h"
145 #include "elf/or1k.h"
148 #include "elf/ppc64.h"
150 #include "elf/riscv.h"
151 #include "elf/rl78.h"
153 #include "elf/s390.h"
154 #include "elf/score.h"
156 #include "elf/sparc.h"
158 #include "elf/tic6x.h"
159 #include "elf/tilegx.h"
160 #include "elf/tilepro.h"
161 #include "elf/v850.h"
163 #include "elf/visium.h"
164 #include "elf/wasm32.h"
165 #include "elf/x86-64.h"
166 #include "elf/xgate.h"
167 #include "elf/xstormy16.h"
168 #include "elf/xtensa.h"
170 #include "elf/loongarch.h"
173 #include "libiberty.h"
174 #include "safe-ctype.h"
175 #include "filenames.h"
178 #define offsetof(TYPE, MEMBER) ((size_t) &(((TYPE *) 0)->MEMBER))
181 typedef struct elf_section_list
183 Elf_Internal_Shdr
* hdr
;
184 struct elf_section_list
* next
;
187 /* Flag bits indicating particular types of dump. */
188 #define HEX_DUMP (1 << 0) /* The -x command line switch. */
189 #define DISASS_DUMP (1 << 1) /* The -i command line switch. */
190 #define DEBUG_DUMP (1 << 2) /* The -w command line switch. */
191 #define STRING_DUMP (1 << 3) /* The -p command line switch. */
192 #define RELOC_DUMP (1 << 4) /* The -R command line switch. */
193 #define CTF_DUMP (1 << 5) /* The --ctf command line switch. */
195 typedef unsigned char dump_type
;
197 /* A linked list of the section names for which dumps were requested. */
198 struct dump_list_entry
202 struct dump_list_entry
* next
;
205 /* A dynamic array of flags indicating for which sections a dump
206 has been requested via command line switches. */
209 dump_type
* dump_sects
;
210 unsigned int num_dump_sects
;
213 static struct dump_data cmdline
;
215 static struct dump_list_entry
* dump_sects_byname
;
217 char * program_name
= "readelf";
219 static bool show_name
= false;
220 static bool do_dynamic
= false;
221 static bool do_syms
= false;
222 static bool do_dyn_syms
= false;
223 static bool do_lto_syms
= false;
224 static bool do_reloc
= false;
225 static bool do_sections
= false;
226 static bool do_section_groups
= false;
227 static bool do_section_details
= false;
228 static bool do_segments
= false;
229 static bool do_unwind
= false;
230 static bool do_using_dynamic
= false;
231 static bool do_header
= false;
232 static bool do_dump
= false;
233 static bool do_version
= false;
234 static bool do_histogram
= false;
235 static bool do_debugging
= false;
236 static bool do_ctf
= false;
237 static bool do_arch
= false;
238 static bool do_notes
= false;
239 static bool do_archive_index
= false;
240 static bool check_all
= false;
241 static bool is_32bit_elf
= false;
242 static bool decompress_dumps
= false;
243 static bool do_not_show_symbol_truncation
= false;
244 static bool do_demangle
= false; /* Pretty print C++ symbol names. */
245 static bool process_links
= false;
246 static bool dump_any_debugging
= false;
247 static int demangle_flags
= DMGL_ANSI
| DMGL_PARAMS
;
248 static int sym_base
= 0;
250 static char *dump_ctf_parent_name
;
251 static char *dump_ctf_symtab_name
;
252 static char *dump_ctf_strtab_name
;
256 struct group_list
* next
;
257 unsigned int section_index
;
262 struct group_list
* root
;
263 unsigned int group_index
;
266 typedef struct filedata
268 const char * file_name
;
271 bfd_size_type file_size
;
272 Elf_Internal_Ehdr file_header
;
273 unsigned long archive_file_offset
;
274 unsigned long archive_file_size
;
275 /* Everything below this point is cleared out by free_filedata. */
276 Elf_Internal_Shdr
* section_headers
;
277 Elf_Internal_Phdr
* program_headers
;
279 unsigned long string_table_length
;
280 unsigned long dynamic_addr
;
281 bfd_size_type dynamic_size
;
283 Elf_Internal_Dyn
* dynamic_section
;
284 Elf_Internal_Shdr
* dynamic_strtab_section
;
285 char * dynamic_strings
;
286 unsigned long dynamic_strings_length
;
287 Elf_Internal_Shdr
* dynamic_symtab_section
;
288 unsigned long num_dynamic_syms
;
289 Elf_Internal_Sym
* dynamic_symbols
;
290 bfd_vma version_info
[16];
291 unsigned int dynamic_syminfo_nent
;
292 Elf_Internal_Syminfo
* dynamic_syminfo
;
293 unsigned long dynamic_syminfo_offset
;
294 bfd_size_type nbuckets
;
295 bfd_size_type nchains
;
298 bfd_size_type ngnubuckets
;
299 bfd_size_type ngnuchains
;
300 bfd_vma
* gnubuckets
;
304 char * program_interpreter
;
305 bfd_vma dynamic_info
[DT_ENCODING
];
306 bfd_vma dynamic_info_DT_GNU_HASH
;
307 bfd_vma dynamic_info_DT_MIPS_XHASH
;
308 elf_section_list
* symtab_shndx_list
;
310 struct group
* section_groups
;
311 struct group
** section_headers_groups
;
312 /* A dynamic array of flags indicating for which sections a dump of
313 some kind has been requested. It is reset on a per-object file
314 basis and then initialised from the cmdline_dump_sects array,
315 the results of interpreting the -w switch, and the
316 dump_sects_byname list. */
317 struct dump_data dump
;
320 /* How to print a vma value. */
321 typedef enum print_mode
338 typedef enum unicode_display_type
346 } unicode_display_type
;
348 static unicode_display_type unicode_display
= unicode_default
;
358 /* Versioned symbol info. */
359 enum versioned_symbol_info
366 static const char * get_symbol_version_string
367 (Filedata
*, bool, const char *, unsigned long, unsigned,
368 Elf_Internal_Sym
*, enum versioned_symbol_info
*, unsigned short *);
372 static inline const char *
373 section_name (const Filedata
*filedata
, const Elf_Internal_Shdr
*hdr
)
375 return filedata
->string_table
+ hdr
->sh_name
;
379 section_name_valid (const Filedata
*filedata
, const Elf_Internal_Shdr
*hdr
)
382 && filedata
->string_table
!= NULL
383 && hdr
->sh_name
< filedata
->string_table_length
);
386 static inline const char *
387 section_name_print (const Filedata
*filedata
, const Elf_Internal_Shdr
*hdr
)
391 if (filedata
->string_table
== NULL
)
392 return _("<no-strings>");
393 if (hdr
->sh_name
>= filedata
->string_table_length
)
394 return _("<corrupt>");
395 return section_name (filedata
, hdr
);
398 #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
401 valid_symbol_name (const char *strtab
, size_t strtab_size
, uint64_t offset
)
403 return strtab
!= NULL
&& offset
< strtab_size
;
407 valid_dynamic_name (const Filedata
*filedata
, uint64_t offset
)
409 return valid_symbol_name (filedata
->dynamic_strings
,
410 filedata
->dynamic_strings_length
, offset
);
413 /* GET_DYNAMIC_NAME asssumes that VALID_DYNAMIC_NAME has
414 already been called and verified that the string exists. */
415 static inline const char *
416 get_dynamic_name (const Filedata
*filedata
, size_t offset
)
418 return filedata
->dynamic_strings
+ offset
;
421 #define REMOVE_ARCH_BITS(ADDR) \
424 if (filedata->file_header.e_machine == EM_ARM) \
429 /* Get the correct GNU hash section name. */
430 #define GNU_HASH_SECTION_NAME(filedata) \
431 filedata->dynamic_info_DT_MIPS_XHASH ? ".MIPS.xhash" : ".gnu.hash"
433 /* Print a BFD_VMA to an internal buffer, for use in error messages.
434 BFD_FMA_FMT can't be used in translated strings. */
437 bfd_vmatoa (char *fmtch
, bfd_vma value
)
439 /* bfd_vmatoa is used more then once in a printf call for output.
440 Cycle through an array of buffers. */
441 static int buf_pos
= 0;
442 static struct bfd_vmatoa_buf
449 ret
= buf
[buf_pos
++].place
;
450 buf_pos
%= ARRAY_SIZE (buf
);
452 sprintf (fmt
, "%%%s%s", BFD_VMA_FMT
, fmtch
);
453 snprintf (ret
, sizeof (buf
[0].place
), fmt
, value
);
457 /* Retrieve NMEMB structures, each SIZE bytes long from FILEDATA starting at
458 OFFSET + the offset of the current archive member, if we are examining an
459 archive. Put the retrieved data into VAR, if it is not NULL. Otherwise
460 allocate a buffer using malloc and fill that. In either case return the
461 pointer to the start of the retrieved data or NULL if something went wrong.
462 If something does go wrong and REASON is not NULL then emit an error
463 message using REASON as part of the context. */
466 get_data (void * var
,
468 unsigned long offset
,
474 bfd_size_type amt
= size
* nmemb
;
476 if (size
== 0 || nmemb
== 0)
479 /* If the size_t type is smaller than the bfd_size_type, eg because
480 you are building a 32-bit tool on a 64-bit host, then make sure
481 that when the sizes are cast to (size_t) no information is lost. */
482 if ((size_t) size
!= size
483 || (size_t) nmemb
!= nmemb
484 || (size_t) amt
!= amt
)
487 error (_("Size truncation prevents reading %s"
488 " elements of size %s for %s\n"),
489 bfd_vmatoa ("u", nmemb
), bfd_vmatoa ("u", size
), reason
);
493 /* Check for size overflow. */
494 if (amt
/ size
!= nmemb
|| (size_t) amt
+ 1 == 0)
497 error (_("Size overflow prevents reading %s"
498 " elements of size %s for %s\n"),
499 bfd_vmatoa ("u", nmemb
), bfd_vmatoa ("u", size
), reason
);
503 /* Be kind to memory checkers (eg valgrind, address sanitizer) by not
504 attempting to allocate memory when the read is bound to fail. */
505 if (filedata
->archive_file_offset
> filedata
->file_size
506 || offset
> filedata
->file_size
- filedata
->archive_file_offset
507 || amt
> filedata
->file_size
- filedata
->archive_file_offset
- offset
)
510 error (_("Reading %s bytes extends past end of file for %s\n"),
511 bfd_vmatoa ("u", amt
), reason
);
515 if (fseek (filedata
->handle
, filedata
->archive_file_offset
+ offset
,
519 error (_("Unable to seek to 0x%lx for %s\n"),
520 filedata
->archive_file_offset
+ offset
, reason
);
527 /* + 1 so that we can '\0' terminate invalid string table sections. */
528 mvar
= malloc ((size_t) amt
+ 1);
533 error (_("Out of memory allocating %s bytes for %s\n"),
534 bfd_vmatoa ("u", amt
), reason
);
538 ((char *) mvar
)[amt
] = '\0';
541 if (fread (mvar
, (size_t) size
, (size_t) nmemb
, filedata
->handle
) != nmemb
)
544 error (_("Unable to read in %s bytes of %s\n"),
545 bfd_vmatoa ("u", amt
), reason
);
554 /* Print a VMA value in the MODE specified.
555 Returns the number of characters displayed. */
558 print_vma (bfd_vma vma
, print_mode mode
)
570 return nc
+ printf ("%16.16" PRIx64
, (uint64_t) vma
);
572 return nc
+ printf ("%8.8" PRIx64
, (uint64_t) vma
);
576 return printf ("%5" BFD_VMA_FMT
"d", vma
);
582 return nc
+ printf ("%" BFD_VMA_FMT
"x", vma
);
588 return nc
+ printf ("%05" BFD_VMA_FMT
"x", vma
);
591 return printf ("%" BFD_VMA_FMT
"d", vma
);
594 return printf ("%" BFD_VMA_FMT
"u", vma
);
597 return printf ("%5" BFD_VMA_FMT
"u", vma
);
600 return printf ("%" BFD_VMA_FMT
"o", vma
);
603 return printf ("%5" BFD_VMA_FMT
"o", vma
);
606 /* FIXME: Report unrecognised mode ? */
612 /* Display a symbol on stdout. Handles the display of control characters and
613 multibye characters (assuming the host environment supports them).
615 Display at most abs(WIDTH) characters, truncating as necessary, unless do_wide is true.
617 If truncation will happen and do_not_show_symbol_truncation is FALSE then display
618 abs(WIDTH) - 5 characters followed by "[...]".
620 If WIDTH is negative then ensure that the output is at least (- WIDTH) characters,
621 padding as necessary.
623 Returns the number of emitted characters. */
626 print_symbol (signed int width
, const char * symbol
)
628 bool extra_padding
= false;
629 bool do_dots
= false;
630 signed int num_printed
= 0;
631 #ifdef HAVE_MBSTATE_T
634 unsigned int width_remaining
;
635 const void * alloced_symbol
= NULL
;
639 /* Keep the width positive. This helps the code below. */
641 extra_padding
= true;
647 /* Set the remaining width to a very large value.
648 This simplifies the code below. */
649 width_remaining
= INT_MAX
;
652 width_remaining
= width
;
653 if (! do_not_show_symbol_truncation
654 && (int) strlen (symbol
) > width
)
656 width_remaining
-= 5;
657 if ((int) width_remaining
< 0)
663 #ifdef HAVE_MBSTATE_T
664 /* Initialise the multibyte conversion state. */
665 memset (& state
, 0, sizeof (state
));
668 if (do_demangle
&& *symbol
)
670 const char * res
= cplus_demangle (symbol
, demangle_flags
);
673 alloced_symbol
= symbol
= res
;
676 while (width_remaining
)
679 const char c
= *symbol
++;
690 else if (ISCNTRL (c
))
692 /* Do not print control characters directly as they can affect terminal
693 settings. Such characters usually appear in the names generated
694 by the assembler for local labels. */
696 if (width_remaining
< 2)
699 printf ("^%c", c
+ 0x40);
700 width_remaining
-= 2;
705 if (width_remaining
< 5)
708 width_remaining
-= 5;
711 else if (unicode_display
!= unicode_locale
712 && unicode_display
!= unicode_default
)
714 /* Display unicode characters as something else. */
715 unsigned char bytes
[4];
728 bytes
[1] = *symbol
++;
730 if ((bytes
[1] & 0xc0) != 0x80)
733 /* Do not consume this character. It may only
734 be the first byte in the sequence that was
739 else if ((bytes
[0] & 0x20) == 0)
746 bytes
[2] = *symbol
++;
748 if ((bytes
[2] & 0xc0) != 0x80)
754 else if ((bytes
[0] & 0x10) == 0)
761 bytes
[3] = *symbol
++;
765 if ((bytes
[3] & 0xc0) != 0x80)
777 if (unicode_display
== unicode_invalid
)
780 if (unicode_display
== unicode_hex
|| ! is_utf8
)
784 if (width_remaining
< (nbytes
* 2) + 2)
787 putchar (is_utf8
? '<' : '{');
789 for (i
= 0; i
< nbytes
; i
++)
790 printf ("%02x", bytes
[i
]);
791 putchar (is_utf8
? '>' : '}');
795 if (unicode_display
== unicode_highlight
&& isatty (1))
796 printf ("\x1B[31;47m"); /* Red. */
801 if (width_remaining
< 6)
803 printf ("\\u%02x%02x",
804 (bytes
[0] & 0x1c) >> 2,
805 ((bytes
[0] & 0x03) << 6) | (bytes
[1] & 0x3f));
808 if (width_remaining
< 6)
810 printf ("\\u%02x%02x",
811 ((bytes
[0] & 0x0f) << 4) | ((bytes
[1] & 0x3c) >> 2),
812 ((bytes
[1] & 0x03) << 6) | (bytes
[2] & 0x3f));
815 if (width_remaining
< 8)
817 printf ("\\u%02x%02x%02x",
818 ((bytes
[0] & 0x07) << 6) | ((bytes
[1] & 0x3c) >> 2),
819 ((bytes
[1] & 0x03) << 6) | ((bytes
[2] & 0x3c) >> 2),
820 ((bytes
[2] & 0x03) << 6) | (bytes
[3] & 0x3f));
828 if (unicode_display
== unicode_highlight
&& isatty (1))
829 printf ("\033[0m"); /* Default colour. */
832 if (bytes
[nbytes
- 1] == 0)
837 #ifdef HAVE_MBSTATE_T
840 /* Let printf do the hard work of displaying multibyte characters. */
841 printf ("%.1s", symbol
- 1);
845 #ifdef HAVE_MBSTATE_T
846 /* Try to find out how many bytes made up the character that was
847 just printed. Advance the symbol pointer past the bytes that
849 n
= mbrtowc (& w
, symbol
- 1, MB_CUR_MAX
, & state
);
853 if (n
!= (size_t) -1 && n
!= (size_t) -2 && n
> 0)
859 num_printed
+= printf ("[...]");
861 if (extra_padding
&& num_printed
< width
)
863 /* Fill in the remaining spaces. */
864 printf ("%-*s", width
- num_printed
, " ");
868 free ((void *) alloced_symbol
);
872 /* Returns a pointer to a static buffer containing a printable version of
873 the given section's name. Like print_symbol, except that it does not try
874 to print multibyte characters, it just interprets them as hex values. */
877 printable_section_name (Filedata
* filedata
, const Elf_Internal_Shdr
* sec
)
879 #define MAX_PRINT_SEC_NAME_LEN 256
880 static char sec_name_buf
[MAX_PRINT_SEC_NAME_LEN
+ 1];
881 const char * name
= section_name_print (filedata
, sec
);
882 char * buf
= sec_name_buf
;
884 unsigned int remaining
= MAX_PRINT_SEC_NAME_LEN
;
886 while ((c
= * name
++) != 0)
897 else if (ISPRINT (c
))
904 static char hex
[17] = "0123456789ABCDEF";
909 * buf
++ = hex
[(c
& 0xf0) >> 4];
910 * buf
++ = hex
[c
& 0x0f];
924 printable_section_name_from_index (Filedata
* filedata
, unsigned long ndx
)
926 if (ndx
>= filedata
->file_header
.e_shnum
)
927 return _("<corrupt>");
929 return printable_section_name (filedata
, filedata
->section_headers
+ ndx
);
932 /* Return a pointer to section NAME, or NULL if no such section exists. */
934 static Elf_Internal_Shdr
*
935 find_section (Filedata
* filedata
, const char * name
)
939 if (filedata
->section_headers
== NULL
)
942 for (i
= 0; i
< filedata
->file_header
.e_shnum
; i
++)
943 if (section_name_valid (filedata
, filedata
->section_headers
+ i
)
944 && streq (section_name (filedata
, filedata
->section_headers
+ i
),
946 return filedata
->section_headers
+ i
;
951 /* Return a pointer to a section containing ADDR, or NULL if no such
954 static Elf_Internal_Shdr
*
955 find_section_by_address (Filedata
* filedata
, bfd_vma addr
)
959 if (filedata
->section_headers
== NULL
)
962 for (i
= 0; i
< filedata
->file_header
.e_shnum
; i
++)
964 Elf_Internal_Shdr
*sec
= filedata
->section_headers
+ i
;
966 if (addr
>= sec
->sh_addr
&& addr
< sec
->sh_addr
+ sec
->sh_size
)
973 static Elf_Internal_Shdr
*
974 find_section_by_type (Filedata
* filedata
, unsigned int type
)
978 if (filedata
->section_headers
== NULL
)
981 for (i
= 0; i
< filedata
->file_header
.e_shnum
; i
++)
983 Elf_Internal_Shdr
*sec
= filedata
->section_headers
+ i
;
985 if (sec
->sh_type
== type
)
992 /* Return a pointer to section NAME, or NULL if no such section exists,
993 restricted to the list of sections given in SET. */
995 static Elf_Internal_Shdr
*
996 find_section_in_set (Filedata
* filedata
, const char * name
, unsigned int * set
)
1000 if (filedata
->section_headers
== NULL
)
1005 while ((i
= *set
++) > 0)
1007 /* See PR 21156 for a reproducer. */
1008 if (i
>= filedata
->file_header
.e_shnum
)
1009 continue; /* FIXME: Should we issue an error message ? */
1011 if (section_name_valid (filedata
, filedata
->section_headers
+ i
)
1012 && streq (section_name (filedata
, filedata
->section_headers
+ i
),
1014 return filedata
->section_headers
+ i
;
1018 return find_section (filedata
, name
);
1021 /* Return TRUE if the current file is for IA-64 machine and OpenVMS ABI.
1022 This OS has so many departures from the ELF standard that we test it at
1026 is_ia64_vms (Filedata
* filedata
)
1028 return filedata
->file_header
.e_machine
== EM_IA_64
1029 && filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_OPENVMS
;
1032 /* Guess the relocation size commonly used by the specific machines. */
1035 guess_is_rela (unsigned int e_machine
)
1039 /* Targets that use REL relocations. */
1045 case EM_CYGNUS_D10V
:
1048 case EM_MIPS_RS3_LE
:
1049 case EM_CYGNUS_M32R
:
1056 /* Targets that use RELA relocations. */
1060 case EM_ADAPTEVA_EPIPHANY
:
1062 case EM_ALTERA_NIOS2
:
1064 case EM_ARC_COMPACT
:
1065 case EM_ARC_COMPACT2
:
1074 case EM_CYGNUS_D30V
:
1077 case EM_CYGNUS_FR30
:
1086 case EM_LATTICEMICO32
:
1095 case EM_CYGNUS_MN10200
:
1097 case EM_CYGNUS_MN10300
:
1115 case EM_SPARC32PLUS
:
1123 case EM_CYGNUS_V850
:
1133 case EM_MICROBLAZE_OLD
:
1134 case EM_WEBASSEMBLY
:
1155 warn (_("Don't know about relocations on this machine architecture\n"));
1160 /* Load RELA type relocations from FILEDATA at REL_OFFSET extending for REL_SIZE bytes.
1161 Returns TRUE upon success, FALSE otherwise. If successful then a
1162 pointer to a malloc'ed buffer containing the relocs is placed in *RELASP,
1163 and the number of relocs loaded is placed in *NRELASP. It is the caller's
1164 responsibility to free the allocated buffer. */
1167 slurp_rela_relocs (Filedata
* filedata
,
1168 unsigned long rel_offset
,
1169 unsigned long rel_size
,
1170 Elf_Internal_Rela
** relasp
,
1171 unsigned long * nrelasp
)
1173 Elf_Internal_Rela
* relas
;
1179 Elf32_External_Rela
* erelas
;
1181 erelas
= (Elf32_External_Rela
*) get_data (NULL
, filedata
, rel_offset
, 1,
1182 rel_size
, _("32-bit relocation data"));
1186 nrelas
= rel_size
/ sizeof (Elf32_External_Rela
);
1188 relas
= (Elf_Internal_Rela
*) cmalloc (nrelas
,
1189 sizeof (Elf_Internal_Rela
));
1194 error (_("out of memory parsing relocs\n"));
1198 for (i
= 0; i
< nrelas
; i
++)
1200 relas
[i
].r_offset
= BYTE_GET (erelas
[i
].r_offset
);
1201 relas
[i
].r_info
= BYTE_GET (erelas
[i
].r_info
);
1202 relas
[i
].r_addend
= BYTE_GET_SIGNED (erelas
[i
].r_addend
);
1209 Elf64_External_Rela
* erelas
;
1211 erelas
= (Elf64_External_Rela
*) get_data (NULL
, filedata
, rel_offset
, 1,
1212 rel_size
, _("64-bit relocation data"));
1216 nrelas
= rel_size
/ sizeof (Elf64_External_Rela
);
1218 relas
= (Elf_Internal_Rela
*) cmalloc (nrelas
,
1219 sizeof (Elf_Internal_Rela
));
1224 error (_("out of memory parsing relocs\n"));
1228 for (i
= 0; i
< nrelas
; i
++)
1230 relas
[i
].r_offset
= BYTE_GET (erelas
[i
].r_offset
);
1231 relas
[i
].r_info
= BYTE_GET (erelas
[i
].r_info
);
1232 relas
[i
].r_addend
= BYTE_GET_SIGNED (erelas
[i
].r_addend
);
1234 /* The #ifdef BFD64 below is to prevent a compile time
1235 warning. We know that if we do not have a 64 bit data
1236 type that we will never execute this code anyway. */
1238 if (filedata
->file_header
.e_machine
== EM_MIPS
1239 && filedata
->file_header
.e_ident
[EI_DATA
] != ELFDATA2MSB
)
1241 /* In little-endian objects, r_info isn't really a
1242 64-bit little-endian value: it has a 32-bit
1243 little-endian symbol index followed by four
1244 individual byte fields. Reorder INFO
1246 bfd_vma inf
= relas
[i
].r_info
;
1247 inf
= (((inf
& 0xffffffff) << 32)
1248 | ((inf
>> 56) & 0xff)
1249 | ((inf
>> 40) & 0xff00)
1250 | ((inf
>> 24) & 0xff0000)
1251 | ((inf
>> 8) & 0xff000000));
1252 relas
[i
].r_info
= inf
;
1265 /* Load REL type relocations from FILEDATA at REL_OFFSET extending for REL_SIZE bytes.
1266 Returns TRUE upon success, FALSE otherwise. If successful then a
1267 pointer to a malloc'ed buffer containing the relocs is placed in *RELSP,
1268 and the number of relocs loaded is placed in *NRELSP. It is the caller's
1269 responsibility to free the allocated buffer. */
1272 slurp_rel_relocs (Filedata
* filedata
,
1273 unsigned long rel_offset
,
1274 unsigned long rel_size
,
1275 Elf_Internal_Rela
** relsp
,
1276 unsigned long * nrelsp
)
1278 Elf_Internal_Rela
* rels
;
1284 Elf32_External_Rel
* erels
;
1286 erels
= (Elf32_External_Rel
*) get_data (NULL
, filedata
, rel_offset
, 1,
1287 rel_size
, _("32-bit relocation data"));
1291 nrels
= rel_size
/ sizeof (Elf32_External_Rel
);
1293 rels
= (Elf_Internal_Rela
*) cmalloc (nrels
, sizeof (Elf_Internal_Rela
));
1298 error (_("out of memory parsing relocs\n"));
1302 for (i
= 0; i
< nrels
; i
++)
1304 rels
[i
].r_offset
= BYTE_GET (erels
[i
].r_offset
);
1305 rels
[i
].r_info
= BYTE_GET (erels
[i
].r_info
);
1306 rels
[i
].r_addend
= 0;
1313 Elf64_External_Rel
* erels
;
1315 erels
= (Elf64_External_Rel
*) get_data (NULL
, filedata
, rel_offset
, 1,
1316 rel_size
, _("64-bit relocation data"));
1320 nrels
= rel_size
/ sizeof (Elf64_External_Rel
);
1322 rels
= (Elf_Internal_Rela
*) cmalloc (nrels
, sizeof (Elf_Internal_Rela
));
1327 error (_("out of memory parsing relocs\n"));
1331 for (i
= 0; i
< nrels
; i
++)
1333 rels
[i
].r_offset
= BYTE_GET (erels
[i
].r_offset
);
1334 rels
[i
].r_info
= BYTE_GET (erels
[i
].r_info
);
1335 rels
[i
].r_addend
= 0;
1337 /* The #ifdef BFD64 below is to prevent a compile time
1338 warning. We know that if we do not have a 64 bit data
1339 type that we will never execute this code anyway. */
1341 if (filedata
->file_header
.e_machine
== EM_MIPS
1342 && filedata
->file_header
.e_ident
[EI_DATA
] != ELFDATA2MSB
)
1344 /* In little-endian objects, r_info isn't really a
1345 64-bit little-endian value: it has a 32-bit
1346 little-endian symbol index followed by four
1347 individual byte fields. Reorder INFO
1349 bfd_vma inf
= rels
[i
].r_info
;
1350 inf
= (((inf
& 0xffffffff) << 32)
1351 | ((inf
>> 56) & 0xff)
1352 | ((inf
>> 40) & 0xff00)
1353 | ((inf
>> 24) & 0xff0000)
1354 | ((inf
>> 8) & 0xff000000));
1355 rels
[i
].r_info
= inf
;
1369 slurp_relr_relocs (Filedata
* filedata
,
1370 unsigned long relr_offset
,
1371 unsigned long relr_size
,
1373 unsigned long * nrelrsp
)
1376 size_t size
= 0, nentries
, i
;
1377 bfd_vma base
= 0, addr
, entry
;
1379 relrs
= get_data (NULL
, filedata
, relr_offset
, 1, relr_size
,
1380 _("RELR relocation data"));
1385 nentries
= relr_size
/ sizeof (Elf32_External_Relr
);
1387 nentries
= relr_size
/ sizeof (Elf64_External_Relr
);
1388 for (i
= 0; i
< nentries
; i
++)
1391 entry
= BYTE_GET (((Elf32_External_Relr
*)relrs
)[i
].r_data
);
1393 entry
= BYTE_GET (((Elf64_External_Relr
*)relrs
)[i
].r_data
);
1394 if ((entry
& 1) == 0)
1397 while ((entry
>>= 1) != 0)
1398 if ((entry
& 1) == 1)
1402 *relrsp
= (bfd_vma
*) malloc (size
* sizeof (bfd_vma
));
1403 if (*relrsp
== NULL
)
1406 error (_("out of memory parsing relocs\n"));
1411 for (i
= 0; i
< nentries
; i
++)
1413 const bfd_vma entry_bytes
= is_32bit_elf
? 4 : 8;
1416 entry
= BYTE_GET (((Elf32_External_Relr
*)relrs
)[i
].r_data
);
1418 entry
= BYTE_GET (((Elf64_External_Relr
*)relrs
)[i
].r_data
);
1419 if ((entry
& 1) == 0)
1421 (*relrsp
)[size
++] = entry
;
1422 base
= entry
+ entry_bytes
;
1426 for (addr
= base
; (entry
>>= 1) != 0; addr
+= entry_bytes
)
1427 if ((entry
& 1) != 0)
1428 (*relrsp
)[size
++] = addr
;
1429 base
+= entry_bytes
* (entry_bytes
* CHAR_BIT
- 1);
1438 /* Returns the reloc type extracted from the reloc info field. */
1441 get_reloc_type (Filedata
* filedata
, bfd_vma reloc_info
)
1444 return ELF32_R_TYPE (reloc_info
);
1446 switch (filedata
->file_header
.e_machine
)
1449 /* Note: We assume that reloc_info has already been adjusted for us. */
1450 return ELF64_MIPS_R_TYPE (reloc_info
);
1453 return ELF64_R_TYPE_ID (reloc_info
);
1456 return ELF64_R_TYPE (reloc_info
);
1460 /* Return the symbol index extracted from the reloc info field. */
1463 get_reloc_symindex (bfd_vma reloc_info
)
1465 return is_32bit_elf
? ELF32_R_SYM (reloc_info
) : ELF64_R_SYM (reloc_info
);
1469 uses_msp430x_relocs (Filedata
* filedata
)
1472 filedata
->file_header
.e_machine
== EM_MSP430
/* Paranoia. */
1473 /* GCC uses osabi == ELFOSBI_STANDALONE. */
1474 && (((filedata
->file_header
.e_flags
& EF_MSP430_MACH
) == E_MSP430_MACH_MSP430X
)
1475 /* TI compiler uses ELFOSABI_NONE. */
1476 || (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_NONE
));
1479 /* Display the contents of the relocation data found at the specified
1483 dump_relocations (Filedata
* filedata
,
1484 unsigned long rel_offset
,
1485 unsigned long rel_size
,
1486 Elf_Internal_Sym
* symtab
,
1487 unsigned long nsyms
,
1489 unsigned long strtablen
,
1490 relocation_type rel_type
,
1494 Elf_Internal_Rela
* rels
;
1497 if (rel_type
== reltype_unknown
)
1498 rel_type
= guess_is_rela (filedata
->file_header
.e_machine
) ? reltype_rela
: reltype_rel
;
1500 if (rel_type
== reltype_rela
)
1502 if (!slurp_rela_relocs (filedata
, rel_offset
, rel_size
, &rels
, &rel_size
))
1505 else if (rel_type
== reltype_rel
)
1507 if (!slurp_rel_relocs (filedata
, rel_offset
, rel_size
, &rels
, &rel_size
))
1510 else if (rel_type
== reltype_relr
)
1514 = is_32bit_elf
? "%08" BFD_VMA_FMT
"x\n" : "%016" BFD_VMA_FMT
"x\n";
1516 if (!slurp_relr_relocs (filedata
, rel_offset
, rel_size
, &relrs
,
1520 printf (ngettext (" %lu offset\n", " %lu offsets\n", rel_size
), rel_size
);
1521 for (i
= 0; i
< rel_size
; i
++)
1522 printf (format
, relrs
[i
]);
1529 if (rel_type
== reltype_rela
)
1532 printf (_(" Offset Info Type Sym. Value Symbol's Name + Addend\n"));
1534 printf (_(" Offset Info Type Sym.Value Sym. Name + Addend\n"));
1539 printf (_(" Offset Info Type Sym. Value Symbol's Name\n"));
1541 printf (_(" Offset Info Type Sym.Value Sym. Name\n"));
1546 if (rel_type
== reltype_rela
)
1549 printf (_(" Offset Info Type Symbol's Value Symbol's Name + Addend\n"));
1551 printf (_(" Offset Info Type Sym. Value Sym. Name + Addend\n"));
1556 printf (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
1558 printf (_(" Offset Info Type Sym. Value Sym. Name\n"));
1562 for (i
= 0; i
< rel_size
; i
++)
1567 bfd_vma symtab_index
;
1570 offset
= rels
[i
].r_offset
;
1571 inf
= rels
[i
].r_info
;
1573 type
= get_reloc_type (filedata
, inf
);
1574 symtab_index
= get_reloc_symindex (inf
);
1578 printf ("%8.8lx %8.8lx ",
1579 (unsigned long) offset
& 0xffffffff,
1580 (unsigned long) inf
& 0xffffffff);
1585 ? "%16.16" BFD_VMA_FMT
"x %16.16" BFD_VMA_FMT
"x "
1586 : "%12.12" BFD_VMA_FMT
"x %12.12" BFD_VMA_FMT
"x ",
1590 switch (filedata
->file_header
.e_machine
)
1597 rtype
= elf_aarch64_reloc_type (type
);
1601 case EM_CYGNUS_M32R
:
1602 rtype
= elf_m32r_reloc_type (type
);
1607 rtype
= elf_i386_reloc_type (type
);
1612 rtype
= elf_m68hc11_reloc_type (type
);
1616 rtype
= elf_s12z_reloc_type (type
);
1620 rtype
= elf_m68k_reloc_type (type
);
1624 rtype
= elf_i960_reloc_type (type
);
1629 rtype
= elf_avr_reloc_type (type
);
1632 case EM_OLD_SPARCV9
:
1633 case EM_SPARC32PLUS
:
1636 rtype
= elf_sparc_reloc_type (type
);
1640 rtype
= elf_spu_reloc_type (type
);
1644 rtype
= v800_reloc_type (type
);
1647 case EM_CYGNUS_V850
:
1648 rtype
= v850_reloc_type (type
);
1652 case EM_CYGNUS_D10V
:
1653 rtype
= elf_d10v_reloc_type (type
);
1657 case EM_CYGNUS_D30V
:
1658 rtype
= elf_d30v_reloc_type (type
);
1662 rtype
= elf_dlx_reloc_type (type
);
1666 rtype
= elf_sh_reloc_type (type
);
1670 case EM_CYGNUS_MN10300
:
1671 rtype
= elf_mn10300_reloc_type (type
);
1675 case EM_CYGNUS_MN10200
:
1676 rtype
= elf_mn10200_reloc_type (type
);
1680 case EM_CYGNUS_FR30
:
1681 rtype
= elf_fr30_reloc_type (type
);
1685 rtype
= elf_frv_reloc_type (type
);
1689 rtype
= elf_csky_reloc_type (type
);
1693 rtype
= elf_ft32_reloc_type (type
);
1697 rtype
= elf_mcore_reloc_type (type
);
1701 rtype
= elf_mmix_reloc_type (type
);
1705 rtype
= elf_moxie_reloc_type (type
);
1709 if (uses_msp430x_relocs (filedata
))
1711 rtype
= elf_msp430x_reloc_type (type
);
1716 rtype
= elf_msp430_reloc_type (type
);
1720 rtype
= elf_nds32_reloc_type (type
);
1724 rtype
= elf_ppc_reloc_type (type
);
1728 rtype
= elf_ppc64_reloc_type (type
);
1732 case EM_MIPS_RS3_LE
:
1733 rtype
= elf_mips_reloc_type (type
);
1737 rtype
= elf_riscv_reloc_type (type
);
1741 rtype
= elf_alpha_reloc_type (type
);
1745 rtype
= elf_arm_reloc_type (type
);
1749 case EM_ARC_COMPACT
:
1750 case EM_ARC_COMPACT2
:
1751 rtype
= elf_arc_reloc_type (type
);
1755 rtype
= elf_hppa_reloc_type (type
);
1761 rtype
= elf_h8_reloc_type (type
);
1765 rtype
= elf_or1k_reloc_type (type
);
1770 rtype
= elf_pj_reloc_type (type
);
1773 rtype
= elf_ia64_reloc_type (type
);
1777 rtype
= elf_cris_reloc_type (type
);
1781 rtype
= elf_i860_reloc_type (type
);
1787 rtype
= elf_x86_64_reloc_type (type
);
1791 rtype
= i370_reloc_type (type
);
1796 rtype
= elf_s390_reloc_type (type
);
1800 rtype
= elf_score_reloc_type (type
);
1804 rtype
= elf_xstormy16_reloc_type (type
);
1808 rtype
= elf_crx_reloc_type (type
);
1812 rtype
= elf_vax_reloc_type (type
);
1816 rtype
= elf_visium_reloc_type (type
);
1820 rtype
= elf_bpf_reloc_type (type
);
1823 case EM_ADAPTEVA_EPIPHANY
:
1824 rtype
= elf_epiphany_reloc_type (type
);
1829 rtype
= elf_ip2k_reloc_type (type
);
1833 rtype
= elf_iq2000_reloc_type (type
);
1838 rtype
= elf_xtensa_reloc_type (type
);
1841 case EM_LATTICEMICO32
:
1842 rtype
= elf_lm32_reloc_type (type
);
1847 rtype
= elf_m32c_reloc_type (type
);
1851 rtype
= elf_mt_reloc_type (type
);
1855 rtype
= elf_bfin_reloc_type (type
);
1859 rtype
= elf_mep_reloc_type (type
);
1863 rtype
= elf_cr16_reloc_type (type
);
1867 case EM_MICROBLAZE_OLD
:
1868 rtype
= elf_microblaze_reloc_type (type
);
1872 rtype
= elf_rl78_reloc_type (type
);
1876 rtype
= elf_rx_reloc_type (type
);
1880 rtype
= elf_metag_reloc_type (type
);
1884 rtype
= elf_tic6x_reloc_type (type
);
1888 rtype
= elf_tilegx_reloc_type (type
);
1892 rtype
= elf_tilepro_reloc_type (type
);
1895 case EM_WEBASSEMBLY
:
1896 rtype
= elf_wasm32_reloc_type (type
);
1900 rtype
= elf_xgate_reloc_type (type
);
1903 case EM_ALTERA_NIOS2
:
1904 rtype
= elf_nios2_reloc_type (type
);
1908 rtype
= elf_pru_reloc_type (type
);
1912 if (EF_NFP_MACH (filedata
->file_header
.e_flags
) == E_NFP_MACH_3200
)
1913 rtype
= elf_nfp3200_reloc_type (type
);
1915 rtype
= elf_nfp_reloc_type (type
);
1919 rtype
= elf_z80_reloc_type (type
);
1923 rtype
= elf_loongarch_reloc_type (type
);
1927 rtype
= elf_amdgpu_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 case PT_AARCH64_MEMTAG_MTE
: return "AARCH64_MEMTAG_MTE";
4496 default: return NULL
;
4501 get_arm_segment_type (unsigned long type
)
4505 case PT_ARM_EXIDX
: return "EXIDX";
4506 default: return NULL
;
4511 get_s390_segment_type (unsigned long type
)
4515 case PT_S390_PGSTE
: return "S390_PGSTE";
4516 default: return NULL
;
4521 get_mips_segment_type (unsigned long type
)
4525 case PT_MIPS_REGINFO
: return "REGINFO";
4526 case PT_MIPS_RTPROC
: return "RTPROC";
4527 case PT_MIPS_OPTIONS
: return "OPTIONS";
4528 case PT_MIPS_ABIFLAGS
: return "ABIFLAGS";
4529 default: return NULL
;
4534 get_parisc_segment_type (unsigned long type
)
4538 case PT_PARISC_ARCHEXT
: return "PARISC_ARCHEXT";
4539 case PT_PARISC_UNWIND
: return "PARISC_UNWIND";
4540 case PT_PARISC_WEAKORDER
: return "PARISC_WEAKORDER";
4541 default: return NULL
;
4546 get_ia64_segment_type (unsigned long type
)
4550 case PT_IA_64_ARCHEXT
: return "IA_64_ARCHEXT";
4551 case PT_IA_64_UNWIND
: return "IA_64_UNWIND";
4552 default: return NULL
;
4557 get_tic6x_segment_type (unsigned long type
)
4561 case PT_C6000_PHATTR
: return "C6000_PHATTR";
4562 default: return NULL
;
4567 get_riscv_segment_type (unsigned long type
)
4571 case PT_RISCV_ATTRIBUTES
: return "RISCV_ATTRIBUTES";
4572 default: return NULL
;
4577 get_hpux_segment_type (unsigned long type
, unsigned e_machine
)
4579 if (e_machine
== EM_PARISC
)
4582 case PT_HP_TLS
: return "HP_TLS";
4583 case PT_HP_CORE_NONE
: return "HP_CORE_NONE";
4584 case PT_HP_CORE_VERSION
: return "HP_CORE_VERSION";
4585 case PT_HP_CORE_KERNEL
: return "HP_CORE_KERNEL";
4586 case PT_HP_CORE_COMM
: return "HP_CORE_COMM";
4587 case PT_HP_CORE_PROC
: return "HP_CORE_PROC";
4588 case PT_HP_CORE_LOADABLE
: return "HP_CORE_LOADABLE";
4589 case PT_HP_CORE_STACK
: return "HP_CORE_STACK";
4590 case PT_HP_CORE_SHM
: return "HP_CORE_SHM";
4591 case PT_HP_CORE_MMF
: return "HP_CORE_MMF";
4592 case PT_HP_PARALLEL
: return "HP_PARALLEL";
4593 case PT_HP_FASTBIND
: return "HP_FASTBIND";
4594 case PT_HP_OPT_ANNOT
: return "HP_OPT_ANNOT";
4595 case PT_HP_HSL_ANNOT
: return "HP_HSL_ANNOT";
4596 case PT_HP_STACK
: return "HP_STACK";
4597 case PT_HP_CORE_UTSNAME
: return "HP_CORE_UTSNAME";
4598 default: return NULL
;
4601 if (e_machine
== EM_IA_64
)
4604 case PT_HP_TLS
: return "HP_TLS";
4605 case PT_IA_64_HP_OPT_ANOT
: return "HP_OPT_ANNOT";
4606 case PT_IA_64_HP_HSL_ANOT
: return "HP_HSL_ANNOT";
4607 case PT_IA_64_HP_STACK
: return "HP_STACK";
4608 default: return NULL
;
4615 get_solaris_segment_type (unsigned long type
)
4619 case 0x6464e550: return "PT_SUNW_UNWIND";
4620 case 0x6474e550: return "PT_SUNW_EH_FRAME";
4621 case 0x6ffffff7: return "PT_LOSUNW";
4622 case 0x6ffffffa: return "PT_SUNWBSS";
4623 case 0x6ffffffb: return "PT_SUNWSTACK";
4624 case 0x6ffffffc: return "PT_SUNWDTRACE";
4625 case 0x6ffffffd: return "PT_SUNWCAP";
4626 case 0x6fffffff: return "PT_HISUNW";
4627 default: return NULL
;
4632 get_segment_type (Filedata
* filedata
, unsigned long p_type
)
4634 static char buff
[32];
4638 case PT_NULL
: return "NULL";
4639 case PT_LOAD
: return "LOAD";
4640 case PT_DYNAMIC
: return "DYNAMIC";
4641 case PT_INTERP
: return "INTERP";
4642 case PT_NOTE
: return "NOTE";
4643 case PT_SHLIB
: return "SHLIB";
4644 case PT_PHDR
: return "PHDR";
4645 case PT_TLS
: return "TLS";
4646 case PT_GNU_EH_FRAME
: return "GNU_EH_FRAME";
4647 case PT_GNU_STACK
: return "GNU_STACK";
4648 case PT_GNU_RELRO
: return "GNU_RELRO";
4649 case PT_GNU_PROPERTY
: return "GNU_PROPERTY";
4651 case PT_OPENBSD_RANDOMIZE
: return "OPENBSD_RANDOMIZE";
4652 case PT_OPENBSD_WXNEEDED
: return "OPENBSD_WXNEEDED";
4653 case PT_OPENBSD_BOOTDATA
: return "OPENBSD_BOOTDATA";
4656 if ((p_type
>= PT_LOPROC
) && (p_type
<= PT_HIPROC
))
4658 const char * result
;
4660 switch (filedata
->file_header
.e_machine
)
4663 result
= get_aarch64_segment_type (p_type
);
4666 result
= get_arm_segment_type (p_type
);
4669 case EM_MIPS_RS3_LE
:
4670 result
= get_mips_segment_type (p_type
);
4673 result
= get_parisc_segment_type (p_type
);
4676 result
= get_ia64_segment_type (p_type
);
4679 result
= get_tic6x_segment_type (p_type
);
4683 result
= get_s390_segment_type (p_type
);
4686 result
= get_riscv_segment_type (p_type
);
4696 sprintf (buff
, "LOPROC+%#lx", p_type
- PT_LOPROC
);
4698 else if ((p_type
>= PT_LOOS
) && (p_type
<= PT_HIOS
))
4700 const char * result
= NULL
;
4702 switch (filedata
->file_header
.e_ident
[EI_OSABI
])
4705 case ELFOSABI_FREEBSD
:
4706 if (p_type
>= PT_GNU_MBIND_LO
&& p_type
<= PT_GNU_MBIND_HI
)
4708 sprintf (buff
, "GNU_MBIND+%#lx", p_type
- PT_GNU_MBIND_LO
);
4713 result
= get_hpux_segment_type (p_type
,
4714 filedata
->file_header
.e_machine
);
4716 case ELFOSABI_SOLARIS
:
4717 result
= get_solaris_segment_type (p_type
);
4725 sprintf (buff
, "LOOS+%#lx", p_type
- PT_LOOS
);
4728 snprintf (buff
, sizeof (buff
), _("<unknown>: %lx"), p_type
);
4735 get_arc_section_type_name (unsigned int sh_type
)
4739 case SHT_ARC_ATTRIBUTES
: return "ARC_ATTRIBUTES";
4747 get_mips_section_type_name (unsigned int sh_type
)
4751 case SHT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
4752 case SHT_MIPS_MSYM
: return "MIPS_MSYM";
4753 case SHT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
4754 case SHT_MIPS_GPTAB
: return "MIPS_GPTAB";
4755 case SHT_MIPS_UCODE
: return "MIPS_UCODE";
4756 case SHT_MIPS_DEBUG
: return "MIPS_DEBUG";
4757 case SHT_MIPS_REGINFO
: return "MIPS_REGINFO";
4758 case SHT_MIPS_PACKAGE
: return "MIPS_PACKAGE";
4759 case SHT_MIPS_PACKSYM
: return "MIPS_PACKSYM";
4760 case SHT_MIPS_RELD
: return "MIPS_RELD";
4761 case SHT_MIPS_IFACE
: return "MIPS_IFACE";
4762 case SHT_MIPS_CONTENT
: return "MIPS_CONTENT";
4763 case SHT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
4764 case SHT_MIPS_SHDR
: return "MIPS_SHDR";
4765 case SHT_MIPS_FDESC
: return "MIPS_FDESC";
4766 case SHT_MIPS_EXTSYM
: return "MIPS_EXTSYM";
4767 case SHT_MIPS_DENSE
: return "MIPS_DENSE";
4768 case SHT_MIPS_PDESC
: return "MIPS_PDESC";
4769 case SHT_MIPS_LOCSYM
: return "MIPS_LOCSYM";
4770 case SHT_MIPS_AUXSYM
: return "MIPS_AUXSYM";
4771 case SHT_MIPS_OPTSYM
: return "MIPS_OPTSYM";
4772 case SHT_MIPS_LOCSTR
: return "MIPS_LOCSTR";
4773 case SHT_MIPS_LINE
: return "MIPS_LINE";
4774 case SHT_MIPS_RFDESC
: return "MIPS_RFDESC";
4775 case SHT_MIPS_DELTASYM
: return "MIPS_DELTASYM";
4776 case SHT_MIPS_DELTAINST
: return "MIPS_DELTAINST";
4777 case SHT_MIPS_DELTACLASS
: return "MIPS_DELTACLASS";
4778 case SHT_MIPS_DWARF
: return "MIPS_DWARF";
4779 case SHT_MIPS_DELTADECL
: return "MIPS_DELTADECL";
4780 case SHT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
4781 case SHT_MIPS_EVENTS
: return "MIPS_EVENTS";
4782 case SHT_MIPS_TRANSLATE
: return "MIPS_TRANSLATE";
4783 case SHT_MIPS_PIXIE
: return "MIPS_PIXIE";
4784 case SHT_MIPS_XLATE
: return "MIPS_XLATE";
4785 case SHT_MIPS_XLATE_DEBUG
: return "MIPS_XLATE_DEBUG";
4786 case SHT_MIPS_WHIRL
: return "MIPS_WHIRL";
4787 case SHT_MIPS_EH_REGION
: return "MIPS_EH_REGION";
4788 case SHT_MIPS_XLATE_OLD
: return "MIPS_XLATE_OLD";
4789 case SHT_MIPS_PDR_EXCEPTION
: return "MIPS_PDR_EXCEPTION";
4790 case SHT_MIPS_ABIFLAGS
: return "MIPS_ABIFLAGS";
4791 case SHT_MIPS_XHASH
: return "MIPS_XHASH";
4799 get_parisc_section_type_name (unsigned int sh_type
)
4803 case SHT_PARISC_EXT
: return "PARISC_EXT";
4804 case SHT_PARISC_UNWIND
: return "PARISC_UNWIND";
4805 case SHT_PARISC_DOC
: return "PARISC_DOC";
4806 case SHT_PARISC_ANNOT
: return "PARISC_ANNOT";
4807 case SHT_PARISC_SYMEXTN
: return "PARISC_SYMEXTN";
4808 case SHT_PARISC_STUBS
: return "PARISC_STUBS";
4809 case SHT_PARISC_DLKM
: return "PARISC_DLKM";
4810 default: return NULL
;
4815 get_ia64_section_type_name (Filedata
* filedata
, unsigned int sh_type
)
4817 /* If the top 8 bits are 0x78 the next 8 are the os/abi ID. */
4818 if ((sh_type
& 0xFF000000) == SHT_IA_64_LOPSREG
)
4819 return get_osabi_name (filedata
, (sh_type
& 0x00FF0000) >> 16);
4823 case SHT_IA_64_EXT
: return "IA_64_EXT";
4824 case SHT_IA_64_UNWIND
: return "IA_64_UNWIND";
4825 case SHT_IA_64_PRIORITY_INIT
: return "IA_64_PRIORITY_INIT";
4826 case SHT_IA_64_VMS_TRACE
: return "VMS_TRACE";
4827 case SHT_IA_64_VMS_TIE_SIGNATURES
: return "VMS_TIE_SIGNATURES";
4828 case SHT_IA_64_VMS_DEBUG
: return "VMS_DEBUG";
4829 case SHT_IA_64_VMS_DEBUG_STR
: return "VMS_DEBUG_STR";
4830 case SHT_IA_64_VMS_LINKAGES
: return "VMS_LINKAGES";
4831 case SHT_IA_64_VMS_SYMBOL_VECTOR
: return "VMS_SYMBOL_VECTOR";
4832 case SHT_IA_64_VMS_FIXUP
: return "VMS_FIXUP";
4840 get_x86_64_section_type_name (unsigned int sh_type
)
4844 case SHT_X86_64_UNWIND
: return "X86_64_UNWIND";
4845 default: return NULL
;
4850 get_aarch64_section_type_name (unsigned int sh_type
)
4854 case SHT_AARCH64_ATTRIBUTES
: return "AARCH64_ATTRIBUTES";
4855 default: return NULL
;
4860 get_arm_section_type_name (unsigned int sh_type
)
4864 case SHT_ARM_EXIDX
: return "ARM_EXIDX";
4865 case SHT_ARM_PREEMPTMAP
: return "ARM_PREEMPTMAP";
4866 case SHT_ARM_ATTRIBUTES
: return "ARM_ATTRIBUTES";
4867 case SHT_ARM_DEBUGOVERLAY
: return "ARM_DEBUGOVERLAY";
4868 case SHT_ARM_OVERLAYSECTION
: return "ARM_OVERLAYSECTION";
4869 default: return NULL
;
4874 get_tic6x_section_type_name (unsigned int sh_type
)
4878 case SHT_C6000_UNWIND
: return "C6000_UNWIND";
4879 case SHT_C6000_PREEMPTMAP
: return "C6000_PREEMPTMAP";
4880 case SHT_C6000_ATTRIBUTES
: return "C6000_ATTRIBUTES";
4881 case SHT_TI_ICODE
: return "TI_ICODE";
4882 case SHT_TI_XREF
: return "TI_XREF";
4883 case SHT_TI_HANDLER
: return "TI_HANDLER";
4884 case SHT_TI_INITINFO
: return "TI_INITINFO";
4885 case SHT_TI_PHATTRS
: return "TI_PHATTRS";
4886 default: return NULL
;
4891 get_msp430_section_type_name (unsigned int sh_type
)
4895 case SHT_MSP430_SEC_FLAGS
: return "MSP430_SEC_FLAGS";
4896 case SHT_MSP430_SYM_ALIASES
: return "MSP430_SYM_ALIASES";
4897 case SHT_MSP430_ATTRIBUTES
: return "MSP430_ATTRIBUTES";
4898 default: return NULL
;
4903 get_nfp_section_type_name (unsigned int sh_type
)
4907 case SHT_NFP_MECONFIG
: return "NFP_MECONFIG";
4908 case SHT_NFP_INITREG
: return "NFP_INITREG";
4909 case SHT_NFP_UDEBUG
: return "NFP_UDEBUG";
4910 default: return NULL
;
4915 get_v850_section_type_name (unsigned int sh_type
)
4919 case SHT_V850_SCOMMON
: return "V850 Small Common";
4920 case SHT_V850_TCOMMON
: return "V850 Tiny Common";
4921 case SHT_V850_ZCOMMON
: return "V850 Zero Common";
4922 case SHT_RENESAS_IOP
: return "RENESAS IOP";
4923 case SHT_RENESAS_INFO
: return "RENESAS INFO";
4924 default: return NULL
;
4929 get_riscv_section_type_name (unsigned int sh_type
)
4933 case SHT_RISCV_ATTRIBUTES
: return "RISCV_ATTRIBUTES";
4934 default: return NULL
;
4939 get_csky_section_type_name (unsigned int sh_type
)
4943 case SHT_CSKY_ATTRIBUTES
: return "CSKY_ATTRIBUTES";
4944 default: return NULL
;
4949 get_section_type_name (Filedata
* filedata
, unsigned int sh_type
)
4951 static char buff
[32];
4952 const char * result
;
4956 case SHT_NULL
: return "NULL";
4957 case SHT_PROGBITS
: return "PROGBITS";
4958 case SHT_SYMTAB
: return "SYMTAB";
4959 case SHT_STRTAB
: return "STRTAB";
4960 case SHT_RELA
: return "RELA";
4961 case SHT_RELR
: return "RELR";
4962 case SHT_HASH
: return "HASH";
4963 case SHT_DYNAMIC
: return "DYNAMIC";
4964 case SHT_NOTE
: return "NOTE";
4965 case SHT_NOBITS
: return "NOBITS";
4966 case SHT_REL
: return "REL";
4967 case SHT_SHLIB
: return "SHLIB";
4968 case SHT_DYNSYM
: return "DYNSYM";
4969 case SHT_INIT_ARRAY
: return "INIT_ARRAY";
4970 case SHT_FINI_ARRAY
: return "FINI_ARRAY";
4971 case SHT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
4972 case SHT_GNU_HASH
: return "GNU_HASH";
4973 case SHT_GROUP
: return "GROUP";
4974 case SHT_SYMTAB_SHNDX
: return "SYMTAB SECTION INDICES";
4975 case SHT_GNU_verdef
: return "VERDEF";
4976 case SHT_GNU_verneed
: return "VERNEED";
4977 case SHT_GNU_versym
: return "VERSYM";
4978 case 0x6ffffff0: return "VERSYM";
4979 case 0x6ffffffc: return "VERDEF";
4980 case 0x7ffffffd: return "AUXILIARY";
4981 case 0x7fffffff: return "FILTER";
4982 case SHT_GNU_LIBLIST
: return "GNU_LIBLIST";
4985 if ((sh_type
>= SHT_LOPROC
) && (sh_type
<= SHT_HIPROC
))
4987 switch (filedata
->file_header
.e_machine
)
4990 case EM_ARC_COMPACT
:
4991 case EM_ARC_COMPACT2
:
4992 result
= get_arc_section_type_name (sh_type
);
4995 case EM_MIPS_RS3_LE
:
4996 result
= get_mips_section_type_name (sh_type
);
4999 result
= get_parisc_section_type_name (sh_type
);
5002 result
= get_ia64_section_type_name (filedata
, sh_type
);
5007 result
= get_x86_64_section_type_name (sh_type
);
5010 result
= get_aarch64_section_type_name (sh_type
);
5013 result
= get_arm_section_type_name (sh_type
);
5016 result
= get_tic6x_section_type_name (sh_type
);
5019 result
= get_msp430_section_type_name (sh_type
);
5022 result
= get_nfp_section_type_name (sh_type
);
5026 case EM_CYGNUS_V850
:
5027 result
= get_v850_section_type_name (sh_type
);
5030 result
= get_riscv_section_type_name (sh_type
);
5033 result
= get_csky_section_type_name (sh_type
);
5043 sprintf (buff
, "LOPROC+%#x", sh_type
- SHT_LOPROC
);
5045 else if ((sh_type
>= SHT_LOOS
) && (sh_type
<= SHT_HIOS
))
5047 switch (filedata
->file_header
.e_machine
)
5050 result
= get_ia64_section_type_name (filedata
, sh_type
);
5053 if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_SOLARIS
)
5054 result
= get_solaris_section_type (sh_type
);
5059 case SHT_GNU_INCREMENTAL_INPUTS
: result
= "GNU_INCREMENTAL_INPUTS"; break;
5060 case SHT_GNU_ATTRIBUTES
: result
= "GNU_ATTRIBUTES"; break;
5061 case SHT_GNU_HASH
: result
= "GNU_HASH"; break;
5062 case SHT_GNU_LIBLIST
: result
= "GNU_LIBLIST"; break;
5074 sprintf (buff
, "LOOS+%#x", sh_type
- SHT_LOOS
);
5076 else if ((sh_type
>= SHT_LOUSER
) && (sh_type
<= SHT_HIUSER
))
5078 switch (filedata
->file_header
.e_machine
)
5082 case EM_CYGNUS_V850
:
5083 result
= get_v850_section_type_name (sh_type
);
5093 sprintf (buff
, "LOUSER+%#x", sh_type
- SHT_LOUSER
);
5096 /* This message is probably going to be displayed in a 15
5097 character wide field, so put the hex value first. */
5098 snprintf (buff
, sizeof (buff
), _("%08x: <unknown>"), sh_type
);
5104 enum long_option_values
5106 OPTION_DEBUG_DUMP
= 512,
5116 OPTION_WITH_SYMBOL_VERSIONS
,
5117 OPTION_RECURSE_LIMIT
,
5118 OPTION_NO_RECURSE_LIMIT
,
5119 OPTION_NO_DEMANGLING
,
5123 static struct option options
[] =
5125 /* Note - This table is alpha-sorted on the 'val'
5126 field in order to make adding new options easier. */
5127 {"arch-specific", no_argument
, 0, 'A'},
5128 {"all", no_argument
, 0, 'a'},
5129 {"demangle", optional_argument
, 0, 'C'},
5130 {"archive-index", no_argument
, 0, 'c'},
5131 {"use-dynamic", no_argument
, 0, 'D'},
5132 {"dynamic", no_argument
, 0, 'd'},
5133 {"headers", no_argument
, 0, 'e'},
5134 {"section-groups", no_argument
, 0, 'g'},
5135 {"help", no_argument
, 0, 'H'},
5136 {"file-header", no_argument
, 0, 'h'},
5137 {"histogram", no_argument
, 0, 'I'},
5138 {"lint", no_argument
, 0, 'L'},
5139 {"enable-checks", no_argument
, 0, 'L'},
5140 {"program-headers", no_argument
, 0, 'l'},
5141 {"segments", no_argument
, 0, 'l'},
5142 {"full-section-name",no_argument
, 0, 'N'},
5143 {"notes", no_argument
, 0, 'n'},
5144 {"process-links", no_argument
, 0, 'P'},
5145 {"string-dump", required_argument
, 0, 'p'},
5146 {"relocated-dump", required_argument
, 0, 'R'},
5147 {"relocs", no_argument
, 0, 'r'},
5148 {"section-headers", no_argument
, 0, 'S'},
5149 {"sections", no_argument
, 0, 'S'},
5150 {"symbols", no_argument
, 0, 's'},
5151 {"syms", no_argument
, 0, 's'},
5152 {"silent-truncation",no_argument
, 0, 'T'},
5153 {"section-details", no_argument
, 0, 't'},
5154 {"unicode", required_argument
, NULL
, 'U'},
5155 {"unwind", no_argument
, 0, 'u'},
5156 {"version-info", no_argument
, 0, 'V'},
5157 {"version", no_argument
, 0, 'v'},
5158 {"wide", no_argument
, 0, 'W'},
5159 {"hex-dump", required_argument
, 0, 'x'},
5160 {"decompress", no_argument
, 0, 'z'},
5162 {"no-demangle", no_argument
, 0, OPTION_NO_DEMANGLING
},
5163 {"recurse-limit", no_argument
, NULL
, OPTION_RECURSE_LIMIT
},
5164 {"no-recurse-limit", no_argument
, NULL
, OPTION_NO_RECURSE_LIMIT
},
5165 {"no-recursion-limit", no_argument
, NULL
, OPTION_NO_RECURSE_LIMIT
},
5166 {"dyn-syms", no_argument
, 0, OPTION_DYN_SYMS
},
5167 {"lto-syms", no_argument
, 0, OPTION_LTO_SYMS
},
5168 {"debug-dump", optional_argument
, 0, OPTION_DEBUG_DUMP
},
5169 {"dwarf-depth", required_argument
, 0, OPTION_DWARF_DEPTH
},
5170 {"dwarf-start", required_argument
, 0, OPTION_DWARF_START
},
5171 {"dwarf-check", no_argument
, 0, OPTION_DWARF_CHECK
},
5172 #ifdef ENABLE_LIBCTF
5173 {"ctf", required_argument
, 0, OPTION_CTF_DUMP
},
5174 {"ctf-symbols", required_argument
, 0, OPTION_CTF_SYMBOLS
},
5175 {"ctf-strings", required_argument
, 0, OPTION_CTF_STRINGS
},
5176 {"ctf-parent", required_argument
, 0, OPTION_CTF_PARENT
},
5178 {"sym-base", optional_argument
, 0, OPTION_SYM_BASE
},
5180 {0, no_argument
, 0, 0}
5184 usage (FILE * stream
)
5186 fprintf (stream
, _("Usage: readelf <option(s)> elf-file(s)\n"));
5187 fprintf (stream
, _(" Display information about the contents of ELF format files\n"));
5188 fprintf (stream
, _(" Options are:\n"));
5189 fprintf (stream
, _("\
5190 -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n"));
5191 fprintf (stream
, _("\
5192 -h --file-header Display the ELF file header\n"));
5193 fprintf (stream
, _("\
5194 -l --program-headers Display the program headers\n"));
5195 fprintf (stream
, _("\
5196 --segments An alias for --program-headers\n"));
5197 fprintf (stream
, _("\
5198 -S --section-headers Display the sections' header\n"));
5199 fprintf (stream
, _("\
5200 --sections An alias for --section-headers\n"));
5201 fprintf (stream
, _("\
5202 -g --section-groups Display the section groups\n"));
5203 fprintf (stream
, _("\
5204 -t --section-details Display the section details\n"));
5205 fprintf (stream
, _("\
5206 -e --headers Equivalent to: -h -l -S\n"));
5207 fprintf (stream
, _("\
5208 -s --syms Display the symbol table\n"));
5209 fprintf (stream
, _("\
5210 --symbols An alias for --syms\n"));
5211 fprintf (stream
, _("\
5212 --dyn-syms Display the dynamic symbol table\n"));
5213 fprintf (stream
, _("\
5214 --lto-syms Display LTO symbol tables\n"));
5215 fprintf (stream
, _("\
5216 --sym-base=[0|8|10|16] \n\
5217 Force base for symbol sizes. The options are \n\
5218 mixed (the default), octal, decimal, hexadecimal.\n"));
5219 fprintf (stream
, _("\
5220 -C --demangle[=STYLE] Decode mangled/processed symbol names\n"));
5221 display_demangler_styles (stream
, _("\
5223 fprintf (stream
, _("\
5224 --no-demangle Do not demangle low-level symbol names. (default)\n"));
5225 fprintf (stream
, _("\
5226 --recurse-limit Enable a demangling recursion limit. (default)\n"));
5227 fprintf (stream
, _("\
5228 --no-recurse-limit Disable a demangling recursion limit\n"));
5229 fprintf (stream
, _("\
5230 -U[dlexhi] --unicode=[default|locale|escape|hex|highlight|invalid]\n\
5231 Display unicode characters as determined by the current locale\n\
5232 (default), escape sequences, \"<hex sequences>\", highlighted\n\
5233 escape sequences, or treat them as invalid and display as\n\
5234 \"{hex sequences}\"\n"));
5235 fprintf (stream
, _("\
5236 -n --notes Display the core notes (if present)\n"));
5237 fprintf (stream
, _("\
5238 -r --relocs Display the relocations (if present)\n"));
5239 fprintf (stream
, _("\
5240 -u --unwind Display the unwind info (if present)\n"));
5241 fprintf (stream
, _("\
5242 -d --dynamic Display the dynamic section (if present)\n"));
5243 fprintf (stream
, _("\
5244 -V --version-info Display the version sections (if present)\n"));
5245 fprintf (stream
, _("\
5246 -A --arch-specific Display architecture specific information (if any)\n"));
5247 fprintf (stream
, _("\
5248 -c --archive-index Display the symbol/file index in an archive\n"));
5249 fprintf (stream
, _("\
5250 -D --use-dynamic Use the dynamic section info when displaying symbols\n"));
5251 fprintf (stream
, _("\
5252 -L --lint|--enable-checks\n\
5253 Display warning messages for possible problems\n"));
5254 fprintf (stream
, _("\
5255 -x --hex-dump=<number|name>\n\
5256 Dump the contents of section <number|name> as bytes\n"));
5257 fprintf (stream
, _("\
5258 -p --string-dump=<number|name>\n\
5259 Dump the contents of section <number|name> as strings\n"));
5260 fprintf (stream
, _("\
5261 -R --relocated-dump=<number|name>\n\
5262 Dump the relocated contents of section <number|name>\n"));
5263 fprintf (stream
, _("\
5264 -z --decompress Decompress section before dumping it\n"));
5265 fprintf (stream
, _("\
5266 -w --debug-dump[a/=abbrev, A/=addr, r/=aranges, c/=cu_index, L/=decodedline,\n\
5267 f/=frames, F/=frames-interp, g/=gdb_index, i/=info, o/=loc,\n\
5268 m/=macro, p/=pubnames, t/=pubtypes, R/=Ranges, l/=rawline,\n\
5269 s/=str, O/=str-offsets, u/=trace_abbrev, T/=trace_aranges,\n\
5271 Display the contents of DWARF debug sections\n"));
5272 fprintf (stream
, _("\
5273 -wk --debug-dump=links Display the contents of sections that link to separate\n\
5274 debuginfo files\n"));
5275 fprintf (stream
, _("\
5276 -P --process-links Display the contents of non-debug sections in separate\n\
5277 debuginfo files. (Implies -wK)\n"));
5278 #if DEFAULT_FOR_FOLLOW_LINKS
5279 fprintf (stream
, _("\
5280 -wK --debug-dump=follow-links\n\
5281 Follow links to separate debug info files (default)\n"));
5282 fprintf (stream
, _("\
5283 -wN --debug-dump=no-follow-links\n\
5284 Do not follow links to separate debug info files\n"));
5286 fprintf (stream
, _("\
5287 -wK --debug-dump=follow-links\n\
5288 Follow links to separate debug info files\n"));
5289 fprintf (stream
, _("\
5290 -wN --debug-dump=no-follow-links\n\
5291 Do not follow links to separate debug info files\n\
5294 #if HAVE_LIBDEBUGINFOD
5295 fprintf (stream
, _("\
5296 -wD --debug-dump=use-debuginfod\n\
5297 When following links, also query debuginfod servers (default)\n"));
5298 fprintf (stream
, _("\
5299 -wE --debug-dump=do-not-use-debuginfod\n\
5300 When following links, do not query debuginfod servers\n"));
5302 fprintf (stream
, _("\
5303 --dwarf-depth=N Do not display DIEs at depth N or greater\n"));
5304 fprintf (stream
, _("\
5305 --dwarf-start=N Display DIEs starting at offset N\n"));
5306 #ifdef ENABLE_LIBCTF
5307 fprintf (stream
, _("\
5308 --ctf=<number|name> Display CTF info from section <number|name>\n"));
5309 fprintf (stream
, _("\
5310 --ctf-parent=<name> Use CTF archive member <name> as the CTF parent\n"));
5311 fprintf (stream
, _("\
5312 --ctf-symbols=<number|name>\n\
5313 Use section <number|name> as the CTF external symtab\n"));
5314 fprintf (stream
, _("\
5315 --ctf-strings=<number|name>\n\
5316 Use section <number|name> as the CTF external strtab\n"));
5319 #ifdef SUPPORT_DISASSEMBLY
5320 fprintf (stream
, _("\
5321 -i --instruction-dump=<number|name>\n\
5322 Disassemble the contents of section <number|name>\n"));
5324 fprintf (stream
, _("\
5325 -I --histogram Display histogram of bucket list lengths\n"));
5326 fprintf (stream
, _("\
5327 -W --wide Allow output width to exceed 80 characters\n"));
5328 fprintf (stream
, _("\
5329 -T --silent-truncation If a symbol name is truncated, do not add [...] suffix\n"));
5330 fprintf (stream
, _("\
5331 @<file> Read options from <file>\n"));
5332 fprintf (stream
, _("\
5333 -H --help Display this information\n"));
5334 fprintf (stream
, _("\
5335 -v --version Display the version number of readelf\n"));
5337 if (REPORT_BUGS_TO
[0] && stream
== stdout
)
5338 fprintf (stdout
, _("Report bugs to %s\n"), REPORT_BUGS_TO
);
5340 exit (stream
== stdout
? 0 : 1);
5343 /* Record the fact that the user wants the contents of section number
5344 SECTION to be displayed using the method(s) encoded as flags bits
5345 in TYPE. Note, TYPE can be zero if we are creating the array for
5349 request_dump_bynumber (struct dump_data
*dumpdata
,
5350 unsigned int section
, dump_type type
)
5352 if (section
>= dumpdata
->num_dump_sects
)
5354 dump_type
* new_dump_sects
;
5356 new_dump_sects
= (dump_type
*) calloc (section
+ 1,
5357 sizeof (* new_dump_sects
));
5359 if (new_dump_sects
== NULL
)
5360 error (_("Out of memory allocating dump request table.\n"));
5363 if (dumpdata
->dump_sects
)
5365 /* Copy current flag settings. */
5366 memcpy (new_dump_sects
, dumpdata
->dump_sects
,
5367 dumpdata
->num_dump_sects
* sizeof (* new_dump_sects
));
5369 free (dumpdata
->dump_sects
);
5372 dumpdata
->dump_sects
= new_dump_sects
;
5373 dumpdata
->num_dump_sects
= section
+ 1;
5377 if (dumpdata
->dump_sects
)
5378 dumpdata
->dump_sects
[section
] |= type
;
5381 /* Request a dump by section name. */
5384 request_dump_byname (const char * section
, dump_type type
)
5386 struct dump_list_entry
* new_request
;
5388 new_request
= (struct dump_list_entry
*)
5389 malloc (sizeof (struct dump_list_entry
));
5391 error (_("Out of memory allocating dump request table.\n"));
5393 new_request
->name
= strdup (section
);
5394 if (!new_request
->name
)
5395 error (_("Out of memory allocating dump request table.\n"));
5397 new_request
->type
= type
;
5399 new_request
->next
= dump_sects_byname
;
5400 dump_sects_byname
= new_request
;
5404 request_dump (struct dump_data
*dumpdata
, dump_type type
)
5410 section
= strtoul (optarg
, & cp
, 0);
5412 if (! *cp
&& section
>= 0)
5413 request_dump_bynumber (dumpdata
, section
, type
);
5415 request_dump_byname (optarg
, type
);
5419 parse_args (struct dump_data
*dumpdata
, int argc
, char ** argv
)
5426 while ((c
= getopt_long
5427 (argc
, argv
, "ACDHILNPR:STU:VWacdeghi:lnp:rstuvw::x:z", options
, NULL
)) != EOF
)
5445 do_section_groups
= true;
5448 do_histogram
= true;
5454 do_section_groups
= true;
5459 do_section_details
= true;
5470 do_using_dynamic
= true;
5494 do_histogram
= true;
5500 do_archive_index
= true;
5506 process_links
= true;
5507 do_follow_links
= true;
5508 dump_any_debugging
= true;
5511 request_dump (dumpdata
, HEX_DUMP
);
5514 request_dump (dumpdata
, STRING_DUMP
);
5517 request_dump (dumpdata
, RELOC_DUMP
);
5520 decompress_dumps
= true;
5525 do_debugging
= true;
5527 dump_any_debugging
= true;
5528 dwarf_select_sections_all ();
5532 do_debugging
= false;
5533 if (dwarf_select_sections_by_letters (optarg
))
5536 dump_any_debugging
= true;
5540 case OPTION_DEBUG_DUMP
:
5544 do_debugging
= true;
5545 dump_any_debugging
= true;
5546 dwarf_select_sections_all ();
5550 do_debugging
= false;
5551 if (dwarf_select_sections_by_names (optarg
))
5554 dump_any_debugging
= true;
5558 case OPTION_DWARF_DEPTH
:
5562 dwarf_cutoff_level
= strtoul (optarg
, & cp
, 0);
5565 case OPTION_DWARF_START
:
5569 dwarf_start_die
= strtoul (optarg
, & cp
, 0);
5572 case OPTION_DWARF_CHECK
:
5575 case OPTION_CTF_DUMP
:
5577 request_dump (dumpdata
, CTF_DUMP
);
5579 case OPTION_CTF_SYMBOLS
:
5580 free (dump_ctf_symtab_name
);
5581 dump_ctf_symtab_name
= strdup (optarg
);
5583 case OPTION_CTF_STRINGS
:
5584 free (dump_ctf_strtab_name
);
5585 dump_ctf_strtab_name
= strdup (optarg
);
5587 case OPTION_CTF_PARENT
:
5588 free (dump_ctf_parent_name
);
5589 dump_ctf_parent_name
= strdup (optarg
);
5591 case OPTION_DYN_SYMS
:
5594 case OPTION_LTO_SYMS
:
5597 #ifdef SUPPORT_DISASSEMBLY
5599 request_dump (dumpdata
, DISASS_DUMP
);
5603 print_version (program_name
);
5612 do_not_show_symbol_truncation
= true;
5618 enum demangling_styles style
;
5620 style
= cplus_demangle_name_to_style (optarg
);
5621 if (style
== unknown_demangling
)
5622 error (_("unknown demangling style `%s'"), optarg
);
5624 cplus_demangle_set_style (style
);
5627 case OPTION_NO_DEMANGLING
:
5628 do_demangle
= false;
5630 case OPTION_RECURSE_LIMIT
:
5631 demangle_flags
&= ~ DMGL_NO_RECURSE_LIMIT
;
5633 case OPTION_NO_RECURSE_LIMIT
:
5634 demangle_flags
|= DMGL_NO_RECURSE_LIMIT
;
5636 case OPTION_WITH_SYMBOL_VERSIONS
:
5637 /* Ignored for backward compatibility. */
5642 error (_("Missing arg to -U/--unicode")); /* Can this happen ? */
5643 else if (streq (optarg
, "default") || streq (optarg
, "d"))
5644 unicode_display
= unicode_default
;
5645 else if (streq (optarg
, "locale") || streq (optarg
, "l"))
5646 unicode_display
= unicode_locale
;
5647 else if (streq (optarg
, "escape") || streq (optarg
, "e"))
5648 unicode_display
= unicode_escape
;
5649 else if (streq (optarg
, "invalid") || streq (optarg
, "i"))
5650 unicode_display
= unicode_invalid
;
5651 else if (streq (optarg
, "hex") || streq (optarg
, "x"))
5652 unicode_display
= unicode_hex
;
5653 else if (streq (optarg
, "highlight") || streq (optarg
, "h"))
5654 unicode_display
= unicode_highlight
;
5656 error (_("invalid argument to -U/--unicode: %s"), optarg
);
5659 case OPTION_SYM_BASE
:
5663 sym_base
= strtoul (optarg
, NULL
, 0);
5680 /* xgettext:c-format */
5681 error (_("Invalid option '-%c'\n"), c
);
5688 if (!do_dynamic
&& !do_syms
&& !do_reloc
&& !do_unwind
&& !do_sections
5689 && !do_segments
&& !do_header
&& !do_dump
&& !do_version
5690 && !do_histogram
&& !do_debugging
&& !do_arch
&& !do_notes
5691 && !do_section_groups
&& !do_archive_index
5692 && !do_dyn_syms
&& !do_lto_syms
)
5697 do_dynamic
= do_syms
= do_reloc
= do_unwind
= do_sections
= true;
5698 do_segments
= do_header
= do_dump
= do_version
= true;
5699 do_histogram
= do_debugging
= do_arch
= do_notes
= true;
5700 do_section_groups
= do_archive_index
= do_dyn_syms
= true;
5709 get_elf_class (unsigned int elf_class
)
5711 static char buff
[32];
5715 case ELFCLASSNONE
: return _("none");
5716 case ELFCLASS32
: return "ELF32";
5717 case ELFCLASS64
: return "ELF64";
5719 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), elf_class
);
5725 get_data_encoding (unsigned int encoding
)
5727 static char buff
[32];
5731 case ELFDATANONE
: return _("none");
5732 case ELFDATA2LSB
: return _("2's complement, little endian");
5733 case ELFDATA2MSB
: return _("2's complement, big endian");
5735 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), encoding
);
5740 /* Decode the data held in 'filedata->file_header'. */
5743 process_file_header (Filedata
* filedata
)
5745 Elf_Internal_Ehdr
* header
= & filedata
->file_header
;
5747 if ( header
->e_ident
[EI_MAG0
] != ELFMAG0
5748 || header
->e_ident
[EI_MAG1
] != ELFMAG1
5749 || header
->e_ident
[EI_MAG2
] != ELFMAG2
5750 || header
->e_ident
[EI_MAG3
] != ELFMAG3
)
5753 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
5757 if (! filedata
->is_separate
)
5758 init_dwarf_regnames_by_elf_machine_code (header
->e_machine
);
5764 if (filedata
->is_separate
)
5765 printf (_("ELF Header in linked file '%s':\n"), filedata
->file_name
);
5767 printf (_("ELF Header:\n"));
5768 printf (_(" Magic: "));
5769 for (i
= 0; i
< EI_NIDENT
; i
++)
5770 printf ("%2.2x ", header
->e_ident
[i
]);
5772 printf (_(" Class: %s\n"),
5773 get_elf_class (header
->e_ident
[EI_CLASS
]));
5774 printf (_(" Data: %s\n"),
5775 get_data_encoding (header
->e_ident
[EI_DATA
]));
5776 printf (_(" Version: %d%s\n"),
5777 header
->e_ident
[EI_VERSION
],
5778 (header
->e_ident
[EI_VERSION
] == EV_CURRENT
5780 : (header
->e_ident
[EI_VERSION
] != EV_NONE
5783 printf (_(" OS/ABI: %s\n"),
5784 get_osabi_name (filedata
, header
->e_ident
[EI_OSABI
]));
5785 printf (_(" ABI Version: %d\n"),
5786 header
->e_ident
[EI_ABIVERSION
]);
5787 printf (_(" Type: %s\n"),
5788 get_file_type (filedata
));
5789 printf (_(" Machine: %s\n"),
5790 get_machine_name (header
->e_machine
));
5791 printf (_(" Version: 0x%lx\n"),
5794 printf (_(" Entry point address: "));
5795 print_vma (header
->e_entry
, PREFIX_HEX
);
5796 printf (_("\n Start of program headers: "));
5797 print_vma (header
->e_phoff
, DEC
);
5798 printf (_(" (bytes into file)\n Start of section headers: "));
5799 print_vma (header
->e_shoff
, DEC
);
5800 printf (_(" (bytes into file)\n"));
5802 printf (_(" Flags: 0x%lx%s\n"),
5804 get_machine_flags (filedata
, header
->e_flags
, header
->e_machine
));
5805 printf (_(" Size of this header: %u (bytes)\n"),
5807 printf (_(" Size of program headers: %u (bytes)\n"),
5808 header
->e_phentsize
);
5809 printf (_(" Number of program headers: %u"),
5811 if (filedata
->section_headers
!= NULL
5812 && header
->e_phnum
== PN_XNUM
5813 && filedata
->section_headers
[0].sh_info
!= 0)
5814 printf (" (%u)", filedata
->section_headers
[0].sh_info
);
5815 putc ('\n', stdout
);
5816 printf (_(" Size of section headers: %u (bytes)\n"),
5817 header
->e_shentsize
);
5818 printf (_(" Number of section headers: %u"),
5820 if (filedata
->section_headers
!= NULL
&& header
->e_shnum
== SHN_UNDEF
)
5822 header
->e_shnum
= filedata
->section_headers
[0].sh_size
;
5823 printf (" (%u)", header
->e_shnum
);
5825 putc ('\n', stdout
);
5826 printf (_(" Section header string table index: %u"),
5827 header
->e_shstrndx
);
5828 if (filedata
->section_headers
!= NULL
5829 && header
->e_shstrndx
== (SHN_XINDEX
& 0xffff))
5831 header
->e_shstrndx
= filedata
->section_headers
[0].sh_link
;
5832 printf (" (%u)", header
->e_shstrndx
);
5834 if (header
->e_shstrndx
!= SHN_UNDEF
5835 && header
->e_shstrndx
>= header
->e_shnum
)
5837 header
->e_shstrndx
= SHN_UNDEF
;
5838 printf (_(" <corrupt: out of range>"));
5840 putc ('\n', stdout
);
5843 if (filedata
->section_headers
!= NULL
)
5845 if (header
->e_phnum
== PN_XNUM
5846 && filedata
->section_headers
[0].sh_info
!= 0)
5848 /* Throw away any cached read of PN_XNUM headers. */
5849 free (filedata
->program_headers
);
5850 filedata
->program_headers
= NULL
;
5851 header
->e_phnum
= filedata
->section_headers
[0].sh_info
;
5853 if (header
->e_shnum
== SHN_UNDEF
)
5854 header
->e_shnum
= filedata
->section_headers
[0].sh_size
;
5855 if (header
->e_shstrndx
== (SHN_XINDEX
& 0xffff))
5856 header
->e_shstrndx
= filedata
->section_headers
[0].sh_link
;
5857 if (header
->e_shstrndx
>= header
->e_shnum
)
5858 header
->e_shstrndx
= SHN_UNDEF
;
5864 /* Read in the program headers from FILEDATA and store them in PHEADERS.
5865 Returns TRUE upon success, FALSE otherwise. Loads 32-bit headers. */
5868 get_32bit_program_headers (Filedata
* filedata
, Elf_Internal_Phdr
* pheaders
)
5870 Elf32_External_Phdr
* phdrs
;
5871 Elf32_External_Phdr
* external
;
5872 Elf_Internal_Phdr
* internal
;
5874 unsigned int size
= filedata
->file_header
.e_phentsize
;
5875 unsigned int num
= filedata
->file_header
.e_phnum
;
5877 /* PR binutils/17531: Cope with unexpected section header sizes. */
5878 if (size
== 0 || num
== 0)
5880 if (size
< sizeof * phdrs
)
5882 error (_("The e_phentsize field in the ELF header is less than the size of an ELF program header\n"));
5885 if (size
> sizeof * phdrs
)
5886 warn (_("The e_phentsize field in the ELF header is larger than the size of an ELF program header\n"));
5888 phdrs
= (Elf32_External_Phdr
*) get_data (NULL
, filedata
, filedata
->file_header
.e_phoff
,
5889 size
, num
, _("program headers"));
5893 for (i
= 0, internal
= pheaders
, external
= phdrs
;
5894 i
< filedata
->file_header
.e_phnum
;
5895 i
++, internal
++, external
++)
5897 internal
->p_type
= BYTE_GET (external
->p_type
);
5898 internal
->p_offset
= BYTE_GET (external
->p_offset
);
5899 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
5900 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
5901 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
5902 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
5903 internal
->p_flags
= BYTE_GET (external
->p_flags
);
5904 internal
->p_align
= BYTE_GET (external
->p_align
);
5911 /* Read in the program headers from FILEDATA and store them in PHEADERS.
5912 Returns TRUE upon success, FALSE otherwise. Loads 64-bit headers. */
5915 get_64bit_program_headers (Filedata
* filedata
, Elf_Internal_Phdr
* pheaders
)
5917 Elf64_External_Phdr
* phdrs
;
5918 Elf64_External_Phdr
* external
;
5919 Elf_Internal_Phdr
* internal
;
5921 unsigned int size
= filedata
->file_header
.e_phentsize
;
5922 unsigned int num
= filedata
->file_header
.e_phnum
;
5924 /* PR binutils/17531: Cope with unexpected section header sizes. */
5925 if (size
== 0 || num
== 0)
5927 if (size
< sizeof * phdrs
)
5929 error (_("The e_phentsize field in the ELF header is less than the size of an ELF program header\n"));
5932 if (size
> sizeof * phdrs
)
5933 warn (_("The e_phentsize field in the ELF header is larger than the size of an ELF program header\n"));
5935 phdrs
= (Elf64_External_Phdr
*) get_data (NULL
, filedata
, filedata
->file_header
.e_phoff
,
5936 size
, num
, _("program headers"));
5940 for (i
= 0, internal
= pheaders
, external
= phdrs
;
5941 i
< filedata
->file_header
.e_phnum
;
5942 i
++, internal
++, external
++)
5944 internal
->p_type
= BYTE_GET (external
->p_type
);
5945 internal
->p_flags
= BYTE_GET (external
->p_flags
);
5946 internal
->p_offset
= BYTE_GET (external
->p_offset
);
5947 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
5948 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
5949 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
5950 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
5951 internal
->p_align
= BYTE_GET (external
->p_align
);
5958 /* Returns TRUE if the program headers were read into `program_headers'. */
5961 get_program_headers (Filedata
* filedata
)
5963 Elf_Internal_Phdr
* phdrs
;
5965 /* Check cache of prior read. */
5966 if (filedata
->program_headers
!= NULL
)
5969 /* Be kind to memory checkers by looking for
5970 e_phnum values which we know must be invalid. */
5971 if (filedata
->file_header
.e_phnum
5972 * (is_32bit_elf
? sizeof (Elf32_External_Phdr
) : sizeof (Elf64_External_Phdr
))
5973 >= filedata
->file_size
)
5975 error (_("Too many program headers - %#x - the file is not that big\n"),
5976 filedata
->file_header
.e_phnum
);
5980 phdrs
= (Elf_Internal_Phdr
*) cmalloc (filedata
->file_header
.e_phnum
,
5981 sizeof (Elf_Internal_Phdr
));
5984 error (_("Out of memory reading %u program headers\n"),
5985 filedata
->file_header
.e_phnum
);
5990 ? get_32bit_program_headers (filedata
, phdrs
)
5991 : get_64bit_program_headers (filedata
, phdrs
))
5993 filedata
->program_headers
= phdrs
;
6001 /* Print program header info and locate dynamic section. */
6004 process_program_headers (Filedata
* filedata
)
6006 Elf_Internal_Phdr
* segment
;
6008 Elf_Internal_Phdr
* previous_load
= NULL
;
6010 if (filedata
->file_header
.e_phnum
== 0)
6012 /* PR binutils/12467. */
6013 if (filedata
->file_header
.e_phoff
!= 0)
6014 warn (_("possibly corrupt ELF header - it has a non-zero program"
6015 " header offset, but no program headers\n"));
6016 else if (do_segments
)
6018 if (filedata
->is_separate
)
6019 printf (_("\nThere are no program headers in linked file '%s'.\n"),
6020 filedata
->file_name
);
6022 printf (_("\nThere are no program headers in this file.\n"));
6027 if (do_segments
&& !do_header
)
6029 if (filedata
->is_separate
)
6030 printf ("\nIn linked file '%s' the ELF file type is %s\n",
6031 filedata
->file_name
, get_file_type (filedata
));
6033 printf (_("\nElf file type is %s\n"), get_file_type (filedata
));
6034 printf (_("Entry point 0x%s\n"), bfd_vmatoa ("x", filedata
->file_header
.e_entry
));
6035 printf (ngettext ("There is %d program header, starting at offset %s\n",
6036 "There are %d program headers, starting at offset %s\n",
6037 filedata
->file_header
.e_phnum
),
6038 filedata
->file_header
.e_phnum
,
6039 bfd_vmatoa ("u", filedata
->file_header
.e_phoff
));
6042 if (! get_program_headers (filedata
))
6047 if (filedata
->file_header
.e_phnum
> 1)
6048 printf (_("\nProgram Headers:\n"));
6050 printf (_("\nProgram Headers:\n"));
6054 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
6057 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
6061 (_(" Type Offset VirtAddr PhysAddr\n"));
6063 (_(" FileSiz MemSiz Flags Align\n"));
6067 unsigned long dynamic_addr
= 0;
6068 bfd_size_type dynamic_size
= 0;
6069 for (i
= 0, segment
= filedata
->program_headers
;
6070 i
< filedata
->file_header
.e_phnum
;
6075 printf (" %-14.14s ", get_segment_type (filedata
, segment
->p_type
));
6079 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
6080 printf ("0x%8.8lx ", (unsigned long) segment
->p_vaddr
);
6081 printf ("0x%8.8lx ", (unsigned long) segment
->p_paddr
);
6082 printf ("0x%5.5lx ", (unsigned long) segment
->p_filesz
);
6083 printf ("0x%5.5lx ", (unsigned long) segment
->p_memsz
);
6085 (segment
->p_flags
& PF_R
? 'R' : ' '),
6086 (segment
->p_flags
& PF_W
? 'W' : ' '),
6087 (segment
->p_flags
& PF_X
? 'E' : ' '));
6088 printf ("%#lx", (unsigned long) segment
->p_align
);
6092 if ((unsigned long) segment
->p_offset
== segment
->p_offset
)
6093 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
6096 print_vma (segment
->p_offset
, FULL_HEX
);
6100 print_vma (segment
->p_vaddr
, FULL_HEX
);
6102 print_vma (segment
->p_paddr
, FULL_HEX
);
6105 if ((unsigned long) segment
->p_filesz
== segment
->p_filesz
)
6106 printf ("0x%6.6lx ", (unsigned long) segment
->p_filesz
);
6109 print_vma (segment
->p_filesz
, FULL_HEX
);
6113 if ((unsigned long) segment
->p_memsz
== segment
->p_memsz
)
6114 printf ("0x%6.6lx", (unsigned long) segment
->p_memsz
);
6117 print_vma (segment
->p_memsz
, FULL_HEX
);
6121 (segment
->p_flags
& PF_R
? 'R' : ' '),
6122 (segment
->p_flags
& PF_W
? 'W' : ' '),
6123 (segment
->p_flags
& PF_X
? 'E' : ' '));
6125 if ((unsigned long) segment
->p_align
== segment
->p_align
)
6126 printf ("%#lx", (unsigned long) segment
->p_align
);
6129 print_vma (segment
->p_align
, PREFIX_HEX
);
6134 print_vma (segment
->p_offset
, FULL_HEX
);
6136 print_vma (segment
->p_vaddr
, FULL_HEX
);
6138 print_vma (segment
->p_paddr
, FULL_HEX
);
6140 print_vma (segment
->p_filesz
, FULL_HEX
);
6142 print_vma (segment
->p_memsz
, FULL_HEX
);
6144 (segment
->p_flags
& PF_R
? 'R' : ' '),
6145 (segment
->p_flags
& PF_W
? 'W' : ' '),
6146 (segment
->p_flags
& PF_X
? 'E' : ' '));
6147 print_vma (segment
->p_align
, PREFIX_HEX
);
6150 putc ('\n', stdout
);
6153 switch (segment
->p_type
)
6156 #if 0 /* Do not warn about out of order PT_LOAD segments. Although officially
6157 required by the ELF standard, several programs, including the Linux
6158 kernel, make use of non-ordered segments. */
6160 && previous_load
->p_vaddr
> segment
->p_vaddr
)
6161 error (_("LOAD segments must be sorted in order of increasing VirtAddr\n"));
6163 if (segment
->p_memsz
< segment
->p_filesz
)
6164 error (_("the segment's file size is larger than its memory size\n"));
6165 previous_load
= segment
;
6169 /* PR 20815 - Verify that the program header is loaded into memory. */
6170 if (i
> 0 && previous_load
!= NULL
)
6171 error (_("the PHDR segment must occur before any LOAD segment\n"));
6172 if (filedata
->file_header
.e_machine
!= EM_PARISC
)
6176 for (j
= 1; j
< filedata
->file_header
.e_phnum
; j
++)
6178 Elf_Internal_Phdr
*load
= filedata
->program_headers
+ j
;
6179 if (load
->p_type
== PT_LOAD
6180 && load
->p_offset
<= segment
->p_offset
6181 && (load
->p_offset
+ load
->p_filesz
6182 >= segment
->p_offset
+ segment
->p_filesz
)
6183 && load
->p_vaddr
<= segment
->p_vaddr
6184 && (load
->p_vaddr
+ load
->p_filesz
6185 >= segment
->p_vaddr
+ segment
->p_filesz
))
6188 if (j
== filedata
->file_header
.e_phnum
)
6189 error (_("the PHDR segment is not covered by a LOAD segment\n"));
6195 error (_("more than one dynamic segment\n"));
6197 /* By default, assume that the .dynamic section is the first
6198 section in the DYNAMIC segment. */
6199 dynamic_addr
= segment
->p_offset
;
6200 dynamic_size
= segment
->p_filesz
;
6202 /* Try to locate the .dynamic section. If there is
6203 a section header table, we can easily locate it. */
6204 if (filedata
->section_headers
!= NULL
)
6206 Elf_Internal_Shdr
* sec
;
6208 sec
= find_section (filedata
, ".dynamic");
6209 if (sec
== NULL
|| sec
->sh_size
== 0)
6211 /* A corresponding .dynamic section is expected, but on
6212 IA-64/OpenVMS it is OK for it to be missing. */
6213 if (!is_ia64_vms (filedata
))
6214 error (_("no .dynamic section in the dynamic segment\n"));
6218 if (sec
->sh_type
== SHT_NOBITS
)
6225 dynamic_addr
= sec
->sh_offset
;
6226 dynamic_size
= sec
->sh_size
;
6228 /* The PT_DYNAMIC segment, which is used by the run-time
6229 loader, should exactly match the .dynamic section. */
6231 && (dynamic_addr
!= segment
->p_offset
6232 || dynamic_size
!= segment
->p_filesz
))
6234 the .dynamic section is not the same as the dynamic segment\n"));
6237 /* PR binutils/17512: Avoid corrupt dynamic section info in the
6238 segment. Check this after matching against the section headers
6239 so we don't warn on debuginfo file (which have NOBITS .dynamic
6241 if (dynamic_addr
> filedata
->file_size
6242 || (dynamic_size
> filedata
->file_size
- dynamic_addr
))
6244 error (_("the dynamic segment offset + size exceeds the size of the file\n"));
6251 if (segment
->p_offset
>= filedata
->file_size
6252 || segment
->p_filesz
> filedata
->file_size
- segment
->p_offset
6253 || segment
->p_filesz
- 1 >= (size_t) -2
6254 || fseek (filedata
->handle
,
6255 filedata
->archive_file_offset
+ (long) segment
->p_offset
,
6257 error (_("Unable to find program interpreter name\n"));
6260 size_t len
= segment
->p_filesz
;
6261 free (filedata
->program_interpreter
);
6262 filedata
->program_interpreter
= xmalloc (len
+ 1);
6263 len
= fread (filedata
->program_interpreter
, 1, len
,
6265 filedata
->program_interpreter
[len
] = 0;
6268 printf (_(" [Requesting program interpreter: %s]\n"),
6269 filedata
->program_interpreter
);
6276 && filedata
->section_headers
!= NULL
6277 && filedata
->string_table
!= NULL
)
6279 printf (_("\n Section to Segment mapping:\n"));
6280 printf (_(" Segment Sections...\n"));
6282 for (i
= 0; i
< filedata
->file_header
.e_phnum
; i
++)
6285 Elf_Internal_Shdr
* section
;
6287 segment
= filedata
->program_headers
+ i
;
6288 section
= filedata
->section_headers
+ 1;
6290 printf (" %2.2d ", i
);
6292 for (j
= 1; j
< filedata
->file_header
.e_shnum
; j
++, section
++)
6294 if (!ELF_TBSS_SPECIAL (section
, segment
)
6295 && ELF_SECTION_IN_SEGMENT_STRICT (section
, segment
))
6296 printf ("%s ", printable_section_name (filedata
, section
));
6303 filedata
->dynamic_addr
= dynamic_addr
;
6304 filedata
->dynamic_size
= dynamic_size
? dynamic_size
: 1;
6308 filedata
->dynamic_addr
= 0;
6309 filedata
->dynamic_size
= 1;
6313 /* Find the file offset corresponding to VMA by using the program headers. */
6316 offset_from_vma (Filedata
* filedata
, bfd_vma vma
, bfd_size_type size
)
6318 Elf_Internal_Phdr
* seg
;
6320 if (! get_program_headers (filedata
))
6322 warn (_("Cannot interpret virtual addresses without program headers.\n"));
6326 for (seg
= filedata
->program_headers
;
6327 seg
< filedata
->program_headers
+ filedata
->file_header
.e_phnum
;
6330 if (seg
->p_type
!= PT_LOAD
)
6333 if (vma
>= (seg
->p_vaddr
& -seg
->p_align
)
6334 && vma
+ size
<= seg
->p_vaddr
+ seg
->p_filesz
)
6335 return vma
- seg
->p_vaddr
+ seg
->p_offset
;
6338 warn (_("Virtual address 0x%lx not located in any PT_LOAD segment.\n"),
6339 (unsigned long) vma
);
6344 /* Allocate memory and load the sections headers into FILEDATA->filedata->section_headers.
6345 If PROBE is true, this is just a probe and we do not generate any error
6346 messages if the load fails. */
6349 get_32bit_section_headers (Filedata
* filedata
, bool probe
)
6351 Elf32_External_Shdr
* shdrs
;
6352 Elf_Internal_Shdr
* internal
;
6354 unsigned int size
= filedata
->file_header
.e_shentsize
;
6355 unsigned int num
= probe
? 1 : filedata
->file_header
.e_shnum
;
6357 /* PR binutils/17531: Cope with unexpected section header sizes. */
6358 if (size
== 0 || num
== 0)
6360 if (size
< sizeof * shdrs
)
6363 error (_("The e_shentsize field in the ELF header is less than the size of an ELF section header\n"));
6366 if (!probe
&& size
> sizeof * shdrs
)
6367 warn (_("The e_shentsize field in the ELF header is larger than the size of an ELF section header\n"));
6369 shdrs
= (Elf32_External_Shdr
*) get_data (NULL
, filedata
, filedata
->file_header
.e_shoff
,
6371 probe
? NULL
: _("section headers"));
6375 filedata
->section_headers
= (Elf_Internal_Shdr
*)
6376 cmalloc (num
, sizeof (Elf_Internal_Shdr
));
6377 if (filedata
->section_headers
== NULL
)
6380 error (_("Out of memory reading %u section headers\n"), num
);
6385 for (i
= 0, internal
= filedata
->section_headers
;
6389 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
6390 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
6391 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
6392 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
6393 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
6394 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
6395 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
6396 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
6397 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
6398 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
6399 if (!probe
&& internal
->sh_link
> num
)
6400 warn (_("Section %u has an out of range sh_link value of %u\n"), i
, internal
->sh_link
);
6401 if (!probe
&& internal
->sh_flags
& SHF_INFO_LINK
&& internal
->sh_info
> num
)
6402 warn (_("Section %u has an out of range sh_info value of %u\n"), i
, internal
->sh_info
);
6409 /* Like get_32bit_section_headers, except that it fetches 64-bit headers. */
6412 get_64bit_section_headers (Filedata
* filedata
, bool probe
)
6414 Elf64_External_Shdr
* shdrs
;
6415 Elf_Internal_Shdr
* internal
;
6417 unsigned int size
= filedata
->file_header
.e_shentsize
;
6418 unsigned int num
= probe
? 1 : filedata
->file_header
.e_shnum
;
6420 /* PR binutils/17531: Cope with unexpected section header sizes. */
6421 if (size
== 0 || num
== 0)
6424 if (size
< sizeof * shdrs
)
6427 error (_("The e_shentsize field in the ELF header is less than the size of an ELF section header\n"));
6431 if (! probe
&& size
> sizeof * shdrs
)
6432 warn (_("The e_shentsize field in the ELF header is larger than the size of an ELF section header\n"));
6434 shdrs
= (Elf64_External_Shdr
*) get_data (NULL
, filedata
,
6435 filedata
->file_header
.e_shoff
,
6437 probe
? NULL
: _("section headers"));
6441 filedata
->section_headers
= (Elf_Internal_Shdr
*)
6442 cmalloc (num
, sizeof (Elf_Internal_Shdr
));
6443 if (filedata
->section_headers
== NULL
)
6446 error (_("Out of memory reading %u section headers\n"), num
);
6451 for (i
= 0, internal
= filedata
->section_headers
;
6455 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
6456 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
6457 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
6458 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
6459 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
6460 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
6461 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
6462 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
6463 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
6464 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
6465 if (!probe
&& internal
->sh_link
> num
)
6466 warn (_("Section %u has an out of range sh_link value of %u\n"), i
, internal
->sh_link
);
6467 if (!probe
&& internal
->sh_flags
& SHF_INFO_LINK
&& internal
->sh_info
> num
)
6468 warn (_("Section %u has an out of range sh_info value of %u\n"), i
, internal
->sh_info
);
6476 get_section_headers (Filedata
*filedata
, bool probe
)
6478 if (filedata
->section_headers
!= NULL
)
6482 return get_32bit_section_headers (filedata
, probe
);
6484 return get_64bit_section_headers (filedata
, probe
);
6487 static Elf_Internal_Sym
*
6488 get_32bit_elf_symbols (Filedata
* filedata
,
6489 Elf_Internal_Shdr
* section
,
6490 unsigned long * num_syms_return
)
6492 unsigned long number
= 0;
6493 Elf32_External_Sym
* esyms
= NULL
;
6494 Elf_External_Sym_Shndx
* shndx
= NULL
;
6495 Elf_Internal_Sym
* isyms
= NULL
;
6496 Elf_Internal_Sym
* psym
;
6498 elf_section_list
* entry
;
6500 if (section
->sh_size
== 0)
6502 if (num_syms_return
!= NULL
)
6503 * num_syms_return
= 0;
6507 /* Run some sanity checks first. */
6508 if (section
->sh_entsize
== 0 || section
->sh_entsize
> section
->sh_size
)
6510 error (_("Section %s has an invalid sh_entsize of 0x%lx\n"),
6511 printable_section_name (filedata
, section
),
6512 (unsigned long) section
->sh_entsize
);
6516 if (section
->sh_size
> filedata
->file_size
)
6518 error (_("Section %s has an invalid sh_size of 0x%lx\n"),
6519 printable_section_name (filedata
, section
),
6520 (unsigned long) section
->sh_size
);
6524 number
= section
->sh_size
/ section
->sh_entsize
;
6526 if (number
* sizeof (Elf32_External_Sym
) > section
->sh_size
+ 1)
6528 error (_("Size (0x%lx) of section %s is not a multiple of its sh_entsize (0x%lx)\n"),
6529 (unsigned long) section
->sh_size
,
6530 printable_section_name (filedata
, section
),
6531 (unsigned long) section
->sh_entsize
);
6535 esyms
= (Elf32_External_Sym
*) get_data (NULL
, filedata
, section
->sh_offset
, 1,
6536 section
->sh_size
, _("symbols"));
6541 for (entry
= filedata
->symtab_shndx_list
; entry
!= NULL
; entry
= entry
->next
)
6543 if (entry
->hdr
->sh_link
!= (unsigned long) (section
- filedata
->section_headers
))
6548 error (_("Multiple symbol table index sections associated with the same symbol section\n"));
6552 shndx
= (Elf_External_Sym_Shndx
*) get_data (NULL
, filedata
,
6553 entry
->hdr
->sh_offset
,
6554 1, entry
->hdr
->sh_size
,
6555 _("symbol table section indices"));
6559 /* PR17531: file: heap-buffer-overflow */
6560 if (entry
->hdr
->sh_size
/ sizeof (Elf_External_Sym_Shndx
) < number
)
6562 error (_("Index section %s has an sh_size of 0x%lx - expected 0x%lx\n"),
6563 printable_section_name (filedata
, entry
->hdr
),
6564 (unsigned long) entry
->hdr
->sh_size
,
6565 (unsigned long) section
->sh_size
);
6570 isyms
= (Elf_Internal_Sym
*) cmalloc (number
, sizeof (Elf_Internal_Sym
));
6574 error (_("Out of memory reading %lu symbols\n"),
6575 (unsigned long) number
);
6579 for (j
= 0, psym
= isyms
; j
< number
; j
++, psym
++)
6581 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
6582 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
6583 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
6584 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
6585 if (psym
->st_shndx
== (SHN_XINDEX
& 0xffff) && shndx
!= NULL
)
6587 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
6588 else if (psym
->st_shndx
>= (SHN_LORESERVE
& 0xffff))
6589 psym
->st_shndx
+= SHN_LORESERVE
- (SHN_LORESERVE
& 0xffff);
6590 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
6591 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
6598 if (num_syms_return
!= NULL
)
6599 * num_syms_return
= isyms
== NULL
? 0 : number
;
6604 static Elf_Internal_Sym
*
6605 get_64bit_elf_symbols (Filedata
* filedata
,
6606 Elf_Internal_Shdr
* section
,
6607 unsigned long * num_syms_return
)
6609 unsigned long number
= 0;
6610 Elf64_External_Sym
* esyms
= NULL
;
6611 Elf_External_Sym_Shndx
* shndx
= NULL
;
6612 Elf_Internal_Sym
* isyms
= NULL
;
6613 Elf_Internal_Sym
* psym
;
6615 elf_section_list
* entry
;
6617 if (section
->sh_size
== 0)
6619 if (num_syms_return
!= NULL
)
6620 * num_syms_return
= 0;
6624 /* Run some sanity checks first. */
6625 if (section
->sh_entsize
== 0 || section
->sh_entsize
> section
->sh_size
)
6627 error (_("Section %s has an invalid sh_entsize of 0x%lx\n"),
6628 printable_section_name (filedata
, section
),
6629 (unsigned long) section
->sh_entsize
);
6633 if (section
->sh_size
> filedata
->file_size
)
6635 error (_("Section %s has an invalid sh_size of 0x%lx\n"),
6636 printable_section_name (filedata
, section
),
6637 (unsigned long) section
->sh_size
);
6641 number
= section
->sh_size
/ section
->sh_entsize
;
6643 if (number
* sizeof (Elf64_External_Sym
) > section
->sh_size
+ 1)
6645 error (_("Size (0x%lx) of section %s is not a multiple of its sh_entsize (0x%lx)\n"),
6646 (unsigned long) section
->sh_size
,
6647 printable_section_name (filedata
, section
),
6648 (unsigned long) section
->sh_entsize
);
6652 esyms
= (Elf64_External_Sym
*) get_data (NULL
, filedata
, section
->sh_offset
, 1,
6653 section
->sh_size
, _("symbols"));
6658 for (entry
= filedata
->symtab_shndx_list
; entry
!= NULL
; entry
= entry
->next
)
6660 if (entry
->hdr
->sh_link
!= (unsigned long) (section
- filedata
->section_headers
))
6665 error (_("Multiple symbol table index sections associated with the same symbol section\n"));
6669 shndx
= (Elf_External_Sym_Shndx
*) get_data (NULL
, filedata
,
6670 entry
->hdr
->sh_offset
,
6671 1, entry
->hdr
->sh_size
,
6672 _("symbol table section indices"));
6676 /* PR17531: file: heap-buffer-overflow */
6677 if (entry
->hdr
->sh_size
/ sizeof (Elf_External_Sym_Shndx
) < number
)
6679 error (_("Index section %s has an sh_size of 0x%lx - expected 0x%lx\n"),
6680 printable_section_name (filedata
, entry
->hdr
),
6681 (unsigned long) entry
->hdr
->sh_size
,
6682 (unsigned long) section
->sh_size
);
6687 isyms
= (Elf_Internal_Sym
*) cmalloc (number
, sizeof (Elf_Internal_Sym
));
6691 error (_("Out of memory reading %lu symbols\n"),
6692 (unsigned long) number
);
6696 for (j
= 0, psym
= isyms
; j
< number
; j
++, psym
++)
6698 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
6699 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
6700 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
6701 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
6703 if (psym
->st_shndx
== (SHN_XINDEX
& 0xffff) && shndx
!= NULL
)
6705 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
6706 else if (psym
->st_shndx
>= (SHN_LORESERVE
& 0xffff))
6707 psym
->st_shndx
+= SHN_LORESERVE
- (SHN_LORESERVE
& 0xffff);
6709 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
6710 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
6717 if (num_syms_return
!= NULL
)
6718 * num_syms_return
= isyms
== NULL
? 0 : number
;
6723 static Elf_Internal_Sym
*
6724 get_elf_symbols (Filedata
*filedata
,
6725 Elf_Internal_Shdr
*section
,
6726 unsigned long *num_syms_return
)
6729 return get_32bit_elf_symbols (filedata
, section
, num_syms_return
);
6731 return get_64bit_elf_symbols (filedata
, section
, num_syms_return
);
6735 get_elf_section_flags (Filedata
* filedata
, bfd_vma sh_flags
)
6737 static char buff
[1024];
6739 unsigned int field_size
= is_32bit_elf
? 8 : 16;
6741 unsigned int size
= sizeof (buff
) - (field_size
+ 4 + 1);
6742 bfd_vma os_flags
= 0;
6743 bfd_vma proc_flags
= 0;
6744 bfd_vma unknown_flags
= 0;
6752 /* 0 */ { STRING_COMMA_LEN ("WRITE") },
6753 /* 1 */ { STRING_COMMA_LEN ("ALLOC") },
6754 /* 2 */ { STRING_COMMA_LEN ("EXEC") },
6755 /* 3 */ { STRING_COMMA_LEN ("MERGE") },
6756 /* 4 */ { STRING_COMMA_LEN ("STRINGS") },
6757 /* 5 */ { STRING_COMMA_LEN ("INFO LINK") },
6758 /* 6 */ { STRING_COMMA_LEN ("LINK ORDER") },
6759 /* 7 */ { STRING_COMMA_LEN ("OS NONCONF") },
6760 /* 8 */ { STRING_COMMA_LEN ("GROUP") },
6761 /* 9 */ { STRING_COMMA_LEN ("TLS") },
6762 /* IA-64 specific. */
6763 /* 10 */ { STRING_COMMA_LEN ("SHORT") },
6764 /* 11 */ { STRING_COMMA_LEN ("NORECOV") },
6765 /* IA-64 OpenVMS specific. */
6766 /* 12 */ { STRING_COMMA_LEN ("VMS_GLOBAL") },
6767 /* 13 */ { STRING_COMMA_LEN ("VMS_OVERLAID") },
6768 /* 14 */ { STRING_COMMA_LEN ("VMS_SHARED") },
6769 /* 15 */ { STRING_COMMA_LEN ("VMS_VECTOR") },
6770 /* 16 */ { STRING_COMMA_LEN ("VMS_ALLOC_64BIT") },
6771 /* 17 */ { STRING_COMMA_LEN ("VMS_PROTECTED") },
6773 /* 18 */ { STRING_COMMA_LEN ("EXCLUDE") },
6774 /* SPARC specific. */
6775 /* 19 */ { STRING_COMMA_LEN ("ORDERED") },
6776 /* 20 */ { STRING_COMMA_LEN ("COMPRESSED") },
6778 /* 21 */ { STRING_COMMA_LEN ("ENTRYSECT") },
6779 /* 22 */ { STRING_COMMA_LEN ("ARM_PURECODE") },
6780 /* 23 */ { STRING_COMMA_LEN ("COMDEF") },
6782 /* 24 */ { STRING_COMMA_LEN ("GNU_MBIND") },
6784 /* 25 */ { STRING_COMMA_LEN ("VLE") },
6786 /* 26 */ { STRING_COMMA_LEN ("GNU_RETAIN") },
6789 if (do_section_details
)
6791 sprintf (buff
, "[%*.*lx]: ",
6792 field_size
, field_size
, (unsigned long) sh_flags
);
6793 p
+= field_size
+ 4;
6800 flag
= sh_flags
& - sh_flags
;
6803 if (do_section_details
)
6807 case SHF_WRITE
: sindex
= 0; break;
6808 case SHF_ALLOC
: sindex
= 1; break;
6809 case SHF_EXECINSTR
: sindex
= 2; break;
6810 case SHF_MERGE
: sindex
= 3; break;
6811 case SHF_STRINGS
: sindex
= 4; break;
6812 case SHF_INFO_LINK
: sindex
= 5; break;
6813 case SHF_LINK_ORDER
: sindex
= 6; break;
6814 case SHF_OS_NONCONFORMING
: sindex
= 7; break;
6815 case SHF_GROUP
: sindex
= 8; break;
6816 case SHF_TLS
: sindex
= 9; break;
6817 case SHF_EXCLUDE
: sindex
= 18; break;
6818 case SHF_COMPRESSED
: sindex
= 20; break;
6822 switch (filedata
->file_header
.e_machine
)
6825 if (flag
== SHF_IA_64_SHORT
)
6827 else if (flag
== SHF_IA_64_NORECOV
)
6830 else if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_OPENVMS
)
6833 case SHF_IA_64_VMS_GLOBAL
: sindex
= 12; break;
6834 case SHF_IA_64_VMS_OVERLAID
: sindex
= 13; break;
6835 case SHF_IA_64_VMS_SHARED
: sindex
= 14; break;
6836 case SHF_IA_64_VMS_VECTOR
: sindex
= 15; break;
6837 case SHF_IA_64_VMS_ALLOC_64BIT
: sindex
= 16; break;
6838 case SHF_IA_64_VMS_PROTECTED
: sindex
= 17; break;
6849 case EM_OLD_SPARCV9
:
6850 case EM_SPARC32PLUS
:
6853 if (flag
== SHF_ORDERED
)
6860 case SHF_ENTRYSECT
: sindex
= 21; break;
6861 case SHF_ARM_PURECODE
: sindex
= 22; break;
6862 case SHF_COMDEF
: sindex
= 23; break;
6867 if (flag
== SHF_PPC_VLE
)
6874 switch (filedata
->file_header
.e_ident
[EI_OSABI
])
6877 case ELFOSABI_FREEBSD
:
6878 if (flag
== SHF_GNU_RETAIN
)
6882 if (flag
== SHF_GNU_MBIND
)
6883 /* We should not recognize SHF_GNU_MBIND for
6884 ELFOSABI_NONE, but binutils as of 2019-07-23 did
6885 not set the EI_OSABI header byte. */
6896 if (p
!= buff
+ field_size
+ 4)
6898 if (size
< (10 + 2))
6900 warn (_("Internal error: not enough buffer room for section flag info"));
6901 return _("<unknown>");
6908 size
-= flags
[sindex
].len
;
6909 p
= stpcpy (p
, flags
[sindex
].str
);
6911 else if (flag
& SHF_MASKOS
)
6913 else if (flag
& SHF_MASKPROC
)
6916 unknown_flags
|= flag
;
6922 case SHF_WRITE
: *p
= 'W'; break;
6923 case SHF_ALLOC
: *p
= 'A'; break;
6924 case SHF_EXECINSTR
: *p
= 'X'; break;
6925 case SHF_MERGE
: *p
= 'M'; break;
6926 case SHF_STRINGS
: *p
= 'S'; break;
6927 case SHF_INFO_LINK
: *p
= 'I'; break;
6928 case SHF_LINK_ORDER
: *p
= 'L'; break;
6929 case SHF_OS_NONCONFORMING
: *p
= 'O'; break;
6930 case SHF_GROUP
: *p
= 'G'; break;
6931 case SHF_TLS
: *p
= 'T'; break;
6932 case SHF_EXCLUDE
: *p
= 'E'; break;
6933 case SHF_COMPRESSED
: *p
= 'C'; break;
6936 if ((filedata
->file_header
.e_machine
== EM_X86_64
6937 || filedata
->file_header
.e_machine
== EM_L1OM
6938 || filedata
->file_header
.e_machine
== EM_K1OM
)
6939 && flag
== SHF_X86_64_LARGE
)
6941 else if (filedata
->file_header
.e_machine
== EM_ARM
6942 && flag
== SHF_ARM_PURECODE
)
6944 else if (filedata
->file_header
.e_machine
== EM_PPC
6945 && flag
== SHF_PPC_VLE
)
6947 else if (flag
& SHF_MASKOS
)
6949 switch (filedata
->file_header
.e_ident
[EI_OSABI
])
6952 case ELFOSABI_FREEBSD
:
6953 if (flag
== SHF_GNU_RETAIN
)
6960 if (flag
== SHF_GNU_MBIND
)
6962 /* We should not recognize SHF_GNU_MBIND for
6963 ELFOSABI_NONE, but binutils as of 2019-07-23 did
6964 not set the EI_OSABI header byte. */
6971 sh_flags
&= ~SHF_MASKOS
;
6975 else if (flag
& SHF_MASKPROC
)
6978 sh_flags
&= ~ SHF_MASKPROC
;
6988 if (do_section_details
)
6992 size
-= 5 + field_size
;
6993 if (p
!= buff
+ field_size
+ 4)
6997 warn (_("Internal error: not enough buffer room for section flag info"));
6998 return _("<unknown>");
7004 sprintf (p
, "OS (%*.*lx)", field_size
, field_size
,
7005 (unsigned long) os_flags
);
7006 p
+= 5 + field_size
;
7010 size
-= 7 + field_size
;
7011 if (p
!= buff
+ field_size
+ 4)
7015 warn (_("Internal error: not enough buffer room for section flag info"));
7016 return _("<unknown>");
7022 sprintf (p
, "PROC (%*.*lx)", field_size
, field_size
,
7023 (unsigned long) proc_flags
);
7024 p
+= 7 + field_size
;
7028 size
-= 10 + field_size
;
7029 if (p
!= buff
+ field_size
+ 4)
7033 warn (_("Internal error: not enough buffer room for section flag info"));
7034 return _("<unknown>");
7040 sprintf (p
, _("UNKNOWN (%*.*lx)"), field_size
, field_size
,
7041 (unsigned long) unknown_flags
);
7042 p
+= 10 + field_size
;
7050 static unsigned int ATTRIBUTE_WARN_UNUSED_RESULT
7051 get_compression_header (Elf_Internal_Chdr
*chdr
, unsigned char *buf
, bfd_size_type size
)
7055 Elf32_External_Chdr
*echdr
= (Elf32_External_Chdr
*) buf
;
7057 if (size
< sizeof (* echdr
))
7059 error (_("Compressed section is too small even for a compression header\n"));
7063 chdr
->ch_type
= BYTE_GET (echdr
->ch_type
);
7064 chdr
->ch_size
= BYTE_GET (echdr
->ch_size
);
7065 chdr
->ch_addralign
= BYTE_GET (echdr
->ch_addralign
);
7066 return sizeof (*echdr
);
7070 Elf64_External_Chdr
*echdr
= (Elf64_External_Chdr
*) buf
;
7072 if (size
< sizeof (* echdr
))
7074 error (_("Compressed section is too small even for a compression header\n"));
7078 chdr
->ch_type
= BYTE_GET (echdr
->ch_type
);
7079 chdr
->ch_size
= BYTE_GET (echdr
->ch_size
);
7080 chdr
->ch_addralign
= BYTE_GET (echdr
->ch_addralign
);
7081 return sizeof (*echdr
);
7086 process_section_headers (Filedata
* filedata
)
7088 Elf_Internal_Shdr
* section
;
7091 if (filedata
->file_header
.e_shnum
== 0)
7093 /* PR binutils/12467. */
7094 if (filedata
->file_header
.e_shoff
!= 0)
7096 warn (_("possibly corrupt ELF file header - it has a non-zero"
7097 " section header offset, but no section headers\n"));
7100 else if (do_sections
)
7101 printf (_("\nThere are no sections in this file.\n"));
7106 if (do_sections
&& !do_header
)
7108 if (filedata
->is_separate
&& process_links
)
7109 printf (_("In linked file '%s': "), filedata
->file_name
);
7110 if (! filedata
->is_separate
|| process_links
)
7111 printf (ngettext ("There is %d section header, "
7112 "starting at offset 0x%lx:\n",
7113 "There are %d section headers, "
7114 "starting at offset 0x%lx:\n",
7115 filedata
->file_header
.e_shnum
),
7116 filedata
->file_header
.e_shnum
,
7117 (unsigned long) filedata
->file_header
.e_shoff
);
7120 if (!get_section_headers (filedata
, false))
7123 /* Read in the string table, so that we have names to display. */
7124 if (filedata
->file_header
.e_shstrndx
!= SHN_UNDEF
7125 && filedata
->file_header
.e_shstrndx
< filedata
->file_header
.e_shnum
)
7127 section
= filedata
->section_headers
+ filedata
->file_header
.e_shstrndx
;
7129 if (section
->sh_size
!= 0)
7131 filedata
->string_table
= (char *) get_data (NULL
, filedata
, section
->sh_offset
,
7132 1, section
->sh_size
,
7135 filedata
->string_table_length
= filedata
->string_table
!= NULL
? section
->sh_size
: 0;
7139 /* Scan the sections for the dynamic symbol table
7140 and dynamic string table and debug sections. */
7141 eh_addr_size
= is_32bit_elf
? 4 : 8;
7142 switch (filedata
->file_header
.e_machine
)
7145 case EM_MIPS_RS3_LE
:
7146 /* The 64-bit MIPS EABI uses a combination of 32-bit ELF and 64-bit
7147 FDE addresses. However, the ABI also has a semi-official ILP32
7148 variant for which the normal FDE address size rules apply.
7150 GCC 4.0 marks EABI64 objects with a dummy .gcc_compiled_longXX
7151 section, where XX is the size of longs in bits. Unfortunately,
7152 earlier compilers provided no way of distinguishing ILP32 objects
7153 from LP64 objects, so if there's any doubt, we should assume that
7154 the official LP64 form is being used. */
7155 if ((filedata
->file_header
.e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
7156 && find_section (filedata
, ".gcc_compiled_long32") == NULL
)
7162 switch (filedata
->file_header
.e_flags
& EF_H8_MACH
)
7164 case E_H8_MACH_H8300
:
7165 case E_H8_MACH_H8300HN
:
7166 case E_H8_MACH_H8300SN
:
7167 case E_H8_MACH_H8300SXN
:
7170 case E_H8_MACH_H8300H
:
7171 case E_H8_MACH_H8300S
:
7172 case E_H8_MACH_H8300SX
:
7180 switch (filedata
->file_header
.e_flags
& EF_M32C_CPU_MASK
)
7182 case EF_M32C_CPU_M16C
:
7189 #define CHECK_ENTSIZE_VALUES(section, i, size32, size64) \
7192 bfd_size_type expected_entsize = is_32bit_elf ? size32 : size64; \
7193 if (section->sh_entsize != expected_entsize) \
7195 error (_("Section %d has invalid sh_entsize of %" PRIx64 "\n"), \
7196 i, (uint64_t) section->sh_entsize); \
7197 error (_("(Using the expected size of %" PRIx64 " for the rest of this dump)\n"), \
7198 (uint64_t) expected_entsize); \
7199 section->sh_entsize = expected_entsize; \
7204 #define CHECK_ENTSIZE(section, i, type) \
7205 CHECK_ENTSIZE_VALUES (section, i, sizeof (Elf32_External_##type), \
7206 sizeof (Elf64_External_##type))
7208 for (i
= 0, section
= filedata
->section_headers
;
7209 i
< filedata
->file_header
.e_shnum
;
7212 const char *name
= section_name_print (filedata
, section
);
7214 /* Run some sanity checks on the headers and
7215 possibly fill in some file data as well. */
7216 switch (section
->sh_type
)
7219 if (filedata
->dynamic_symbols
!= NULL
)
7221 error (_("File contains multiple dynamic symbol tables\n"));
7225 CHECK_ENTSIZE (section
, i
, Sym
);
7226 filedata
->dynamic_symbols
7227 = get_elf_symbols (filedata
, section
, &filedata
->num_dynamic_syms
);
7228 filedata
->dynamic_symtab_section
= section
;
7232 if (streq (name
, ".dynstr"))
7234 if (filedata
->dynamic_strings
!= NULL
)
7236 error (_("File contains multiple dynamic string tables\n"));
7240 filedata
->dynamic_strings
7241 = (char *) get_data (NULL
, filedata
, section
->sh_offset
,
7242 1, section
->sh_size
, _("dynamic strings"));
7243 filedata
->dynamic_strings_length
7244 = filedata
->dynamic_strings
== NULL
? 0 : section
->sh_size
;
7245 filedata
->dynamic_strtab_section
= section
;
7249 case SHT_SYMTAB_SHNDX
:
7251 elf_section_list
* entry
= xmalloc (sizeof * entry
);
7253 entry
->hdr
= section
;
7254 entry
->next
= filedata
->symtab_shndx_list
;
7255 filedata
->symtab_shndx_list
= entry
;
7260 CHECK_ENTSIZE (section
, i
, Sym
);
7264 CHECK_ENTSIZE_VALUES (section
, i
, GRP_ENTRY_SIZE
, GRP_ENTRY_SIZE
);
7268 CHECK_ENTSIZE (section
, i
, Rel
);
7269 if (do_checks
&& section
->sh_size
== 0)
7270 warn (_("Section '%s': zero-sized relocation section\n"), name
);
7274 CHECK_ENTSIZE (section
, i
, Rela
);
7275 if (do_checks
&& section
->sh_size
== 0)
7276 warn (_("Section '%s': zero-sized relocation section\n"), name
);
7280 CHECK_ENTSIZE (section
, i
, Relr
);
7285 /* Having a zero sized section is not illegal according to the
7286 ELF standard, but it might be an indication that something
7287 is wrong. So issue a warning if we are running in lint mode. */
7288 if (do_checks
&& section
->sh_size
== 0)
7289 warn (_("Section '%s': has a size of zero - is this intended ?\n"), name
);
7296 if ((do_debugging
|| do_debug_info
|| do_debug_abbrevs
7297 || do_debug_lines
|| do_debug_pubnames
|| do_debug_pubtypes
7298 || do_debug_aranges
|| do_debug_frames
|| do_debug_macinfo
7299 || do_debug_str
|| do_debug_str_offsets
|| do_debug_loc
7301 || do_debug_addr
|| do_debug_cu_index
|| do_debug_links
)
7302 && (startswith (name
, ".debug_")
7303 || startswith (name
, ".zdebug_")))
7306 name
+= sizeof (".zdebug_") - 1;
7308 name
+= sizeof (".debug_") - 1;
7311 || (do_debug_info
&& startswith (name
, "info"))
7312 || (do_debug_info
&& startswith (name
, "types"))
7313 || (do_debug_abbrevs
&& startswith (name
, "abbrev"))
7314 || (do_debug_lines
&& strcmp (name
, "line") == 0)
7315 || (do_debug_lines
&& startswith (name
, "line."))
7316 || (do_debug_pubnames
&& startswith (name
, "pubnames"))
7317 || (do_debug_pubtypes
&& startswith (name
, "pubtypes"))
7318 || (do_debug_pubnames
&& startswith (name
, "gnu_pubnames"))
7319 || (do_debug_pubtypes
&& startswith (name
, "gnu_pubtypes"))
7320 || (do_debug_aranges
&& startswith (name
, "aranges"))
7321 || (do_debug_ranges
&& startswith (name
, "ranges"))
7322 || (do_debug_ranges
&& startswith (name
, "rnglists"))
7323 || (do_debug_frames
&& startswith (name
, "frame"))
7324 || (do_debug_macinfo
&& startswith (name
, "macinfo"))
7325 || (do_debug_macinfo
&& startswith (name
, "macro"))
7326 || (do_debug_str
&& startswith (name
, "str"))
7327 || (do_debug_links
&& startswith (name
, "sup"))
7328 || (do_debug_str_offsets
&& startswith (name
, "str_offsets"))
7329 || (do_debug_loc
&& startswith (name
, "loc"))
7330 || (do_debug_loc
&& startswith (name
, "loclists"))
7331 || (do_debug_addr
&& startswith (name
, "addr"))
7332 || (do_debug_cu_index
&& startswith (name
, "cu_index"))
7333 || (do_debug_cu_index
&& startswith (name
, "tu_index"))
7335 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
7337 /* Linkonce section to be combined with .debug_info at link time. */
7338 else if ((do_debugging
|| do_debug_info
)
7339 && startswith (name
, ".gnu.linkonce.wi."))
7340 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
7341 else if (do_debug_frames
&& streq (name
, ".eh_frame"))
7342 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
7343 else if (do_gdb_index
&& (streq (name
, ".gdb_index")
7344 || streq (name
, ".debug_names")))
7345 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
7346 /* Trace sections for Itanium VMS. */
7347 else if ((do_debugging
|| do_trace_info
|| do_trace_abbrevs
7348 || do_trace_aranges
)
7349 && startswith (name
, ".trace_"))
7351 name
+= sizeof (".trace_") - 1;
7354 || (do_trace_info
&& streq (name
, "info"))
7355 || (do_trace_abbrevs
&& streq (name
, "abbrev"))
7356 || (do_trace_aranges
&& streq (name
, "aranges"))
7358 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
7360 else if ((do_debugging
|| do_debug_links
)
7361 && (startswith (name
, ".gnu_debuglink")
7362 || startswith (name
, ".gnu_debugaltlink")))
7363 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
7369 if (filedata
->is_separate
&& ! process_links
)
7372 if (filedata
->is_separate
)
7373 printf (_("\nSection Headers in linked file '%s':\n"), filedata
->file_name
);
7374 else if (filedata
->file_header
.e_shnum
> 1)
7375 printf (_("\nSection Headers:\n"));
7377 printf (_("\nSection Header:\n"));
7381 if (do_section_details
)
7383 printf (_(" [Nr] Name\n"));
7384 printf (_(" Type Addr Off Size ES Lk Inf Al\n"));
7388 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
7392 if (do_section_details
)
7394 printf (_(" [Nr] Name\n"));
7395 printf (_(" Type Address Off Size ES Lk Inf Al\n"));
7399 (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n"));
7403 if (do_section_details
)
7405 printf (_(" [Nr] Name\n"));
7406 printf (_(" Type Address Offset Link\n"));
7407 printf (_(" Size EntSize Info Align\n"));
7411 printf (_(" [Nr] Name Type Address Offset\n"));
7412 printf (_(" Size EntSize Flags Link Info Align\n"));
7416 if (do_section_details
)
7417 printf (_(" Flags\n"));
7419 for (i
= 0, section
= filedata
->section_headers
;
7420 i
< filedata
->file_header
.e_shnum
;
7423 /* Run some sanity checks on the section header. */
7425 /* Check the sh_link field. */
7426 switch (section
->sh_type
)
7430 if (section
->sh_link
== 0
7431 && (filedata
->file_header
.e_type
== ET_EXEC
7432 || filedata
->file_header
.e_type
== ET_DYN
))
7433 /* A dynamic relocation section where all entries use a
7434 zero symbol index need not specify a symtab section. */
7437 case SHT_SYMTAB_SHNDX
:
7441 case SHT_GNU_versym
:
7442 if (section
->sh_link
== 0
7443 || section
->sh_link
>= filedata
->file_header
.e_shnum
7444 || (filedata
->section_headers
[section
->sh_link
].sh_type
!= SHT_SYMTAB
7445 && filedata
->section_headers
[section
->sh_link
].sh_type
!= SHT_DYNSYM
))
7446 warn (_("[%2u]: Link field (%u) should index a symtab section.\n"),
7447 i
, section
->sh_link
);
7453 case SHT_GNU_verneed
:
7454 case SHT_GNU_verdef
:
7455 case SHT_GNU_LIBLIST
:
7456 if (section
->sh_link
== 0
7457 || section
->sh_link
>= filedata
->file_header
.e_shnum
7458 || filedata
->section_headers
[section
->sh_link
].sh_type
!= SHT_STRTAB
)
7459 warn (_("[%2u]: Link field (%u) should index a string section.\n"),
7460 i
, section
->sh_link
);
7463 case SHT_INIT_ARRAY
:
7464 case SHT_FINI_ARRAY
:
7465 case SHT_PREINIT_ARRAY
:
7466 if (section
->sh_type
< SHT_LOOS
&& section
->sh_link
!= 0)
7467 warn (_("[%2u]: Unexpected value (%u) in link field.\n"),
7468 i
, section
->sh_link
);
7472 /* FIXME: Add support for target specific section types. */
7473 #if 0 /* Currently we do not check other section types as there are too
7474 many special cases. Stab sections for example have a type
7475 of SHT_PROGBITS but an sh_link field that links to the .stabstr
7477 if (section
->sh_type
< SHT_LOOS
&& section
->sh_link
!= 0)
7478 warn (_("[%2u]: Unexpected value (%u) in link field.\n"),
7479 i
, section
->sh_link
);
7484 /* Check the sh_info field. */
7485 switch (section
->sh_type
)
7489 if (section
->sh_info
== 0
7490 && (filedata
->file_header
.e_type
== ET_EXEC
7491 || filedata
->file_header
.e_type
== ET_DYN
))
7492 /* Dynamic relocations apply to segments, so they do not
7493 need to specify the section they relocate. */
7495 if (section
->sh_info
== 0
7496 || section
->sh_info
>= filedata
->file_header
.e_shnum
7497 || (filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_PROGBITS
7498 && filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_NOBITS
7499 && filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_NOTE
7500 && filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_INIT_ARRAY
7501 && filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_FINI_ARRAY
7502 && filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_PREINIT_ARRAY
7503 /* FIXME: Are other section types valid ? */
7504 && filedata
->section_headers
[section
->sh_info
].sh_type
< SHT_LOOS
))
7505 warn (_("[%2u]: Info field (%u) should index a relocatable section.\n"),
7506 i
, section
->sh_info
);
7511 case SHT_SYMTAB_SHNDX
:
7512 case SHT_INIT_ARRAY
:
7513 case SHT_FINI_ARRAY
:
7514 case SHT_PREINIT_ARRAY
:
7515 if (section
->sh_info
!= 0)
7516 warn (_("[%2u]: Unexpected value (%u) in info field.\n"),
7517 i
, section
->sh_info
);
7523 /* A symbol index - we assume that it is valid. */
7527 /* FIXME: Add support for target specific section types. */
7528 if (section
->sh_type
== SHT_NOBITS
)
7529 /* NOBITS section headers with non-zero sh_info fields can be
7530 created when a binary is stripped of everything but its debug
7531 information. The stripped sections have their headers
7532 preserved but their types set to SHT_NOBITS. So do not check
7533 this type of section. */
7535 else if (section
->sh_flags
& SHF_INFO_LINK
)
7537 if (section
->sh_info
< 1 || section
->sh_info
>= filedata
->file_header
.e_shnum
)
7538 warn (_("[%2u]: Expected link to another section in info field"), i
);
7540 else if (section
->sh_type
< SHT_LOOS
7541 && (section
->sh_flags
& SHF_GNU_MBIND
) == 0
7542 && section
->sh_info
!= 0)
7543 warn (_("[%2u]: Unexpected value (%u) in info field.\n"),
7544 i
, section
->sh_info
);
7548 /* Check the sh_size field. */
7549 if (section
->sh_size
> filedata
->file_size
7550 && section
->sh_type
!= SHT_NOBITS
7551 && section
->sh_type
!= SHT_NULL
7552 && section
->sh_type
< SHT_LOOS
)
7553 warn (_("Size of section %u is larger than the entire file!\n"), i
);
7555 printf (" [%2u] ", i
);
7556 if (do_section_details
)
7557 printf ("%s\n ", printable_section_name (filedata
, section
));
7559 print_symbol (-17, section_name_print (filedata
, section
));
7561 printf (do_wide
? " %-15s " : " %-15.15s ",
7562 get_section_type_name (filedata
, section
->sh_type
));
7566 const char * link_too_big
= NULL
;
7568 print_vma (section
->sh_addr
, LONG_HEX
);
7570 printf ( " %6.6lx %6.6lx %2.2lx",
7571 (unsigned long) section
->sh_offset
,
7572 (unsigned long) section
->sh_size
,
7573 (unsigned long) section
->sh_entsize
);
7575 if (do_section_details
)
7576 fputs (" ", stdout
);
7578 printf (" %3s ", get_elf_section_flags (filedata
, section
->sh_flags
));
7580 if (section
->sh_link
>= filedata
->file_header
.e_shnum
)
7583 /* The sh_link value is out of range. Normally this indicates
7584 an error but it can have special values in Solaris binaries. */
7585 switch (filedata
->file_header
.e_machine
)
7592 case EM_OLD_SPARCV9
:
7593 case EM_SPARC32PLUS
:
7596 if (section
->sh_link
== (SHN_BEFORE
& 0xffff))
7597 link_too_big
= "BEFORE";
7598 else if (section
->sh_link
== (SHN_AFTER
& 0xffff))
7599 link_too_big
= "AFTER";
7606 if (do_section_details
)
7608 if (link_too_big
!= NULL
&& * link_too_big
)
7609 printf ("<%s> ", link_too_big
);
7611 printf ("%2u ", section
->sh_link
);
7612 printf ("%3u %2lu\n", section
->sh_info
,
7613 (unsigned long) section
->sh_addralign
);
7616 printf ("%2u %3u %2lu\n",
7619 (unsigned long) section
->sh_addralign
);
7621 if (link_too_big
&& ! * link_too_big
)
7622 warn (_("section %u: sh_link value of %u is larger than the number of sections\n"),
7623 i
, section
->sh_link
);
7627 print_vma (section
->sh_addr
, LONG_HEX
);
7629 if ((long) section
->sh_offset
== section
->sh_offset
)
7630 printf (" %6.6lx", (unsigned long) section
->sh_offset
);
7634 print_vma (section
->sh_offset
, LONG_HEX
);
7637 if ((unsigned long) section
->sh_size
== section
->sh_size
)
7638 printf (" %6.6lx", (unsigned long) section
->sh_size
);
7642 print_vma (section
->sh_size
, LONG_HEX
);
7645 if ((unsigned long) section
->sh_entsize
== section
->sh_entsize
)
7646 printf (" %2.2lx", (unsigned long) section
->sh_entsize
);
7650 print_vma (section
->sh_entsize
, LONG_HEX
);
7653 if (do_section_details
)
7654 fputs (" ", stdout
);
7656 printf (" %3s ", get_elf_section_flags (filedata
, section
->sh_flags
));
7658 printf ("%2u %3u ", section
->sh_link
, section
->sh_info
);
7660 if ((unsigned long) section
->sh_addralign
== section
->sh_addralign
)
7661 printf ("%2lu\n", (unsigned long) section
->sh_addralign
);
7664 print_vma (section
->sh_addralign
, DEC
);
7668 else if (do_section_details
)
7671 print_vma (section
->sh_addr
, LONG_HEX
);
7672 if ((long) section
->sh_offset
== section
->sh_offset
)
7673 printf (" %16.16lx", (unsigned long) section
->sh_offset
);
7677 print_vma (section
->sh_offset
, LONG_HEX
);
7679 printf (" %u\n ", section
->sh_link
);
7680 print_vma (section
->sh_size
, LONG_HEX
);
7682 print_vma (section
->sh_entsize
, LONG_HEX
);
7684 printf (" %-16u %lu\n",
7686 (unsigned long) section
->sh_addralign
);
7691 print_vma (section
->sh_addr
, LONG_HEX
);
7692 if ((long) section
->sh_offset
== section
->sh_offset
)
7693 printf (" %8.8lx", (unsigned long) section
->sh_offset
);
7697 print_vma (section
->sh_offset
, LONG_HEX
);
7700 print_vma (section
->sh_size
, LONG_HEX
);
7702 print_vma (section
->sh_entsize
, LONG_HEX
);
7704 printf (" %3s ", get_elf_section_flags (filedata
, section
->sh_flags
));
7706 printf (" %2u %3u %lu\n",
7709 (unsigned long) section
->sh_addralign
);
7712 if (do_section_details
)
7714 printf (" %s\n", get_elf_section_flags (filedata
, section
->sh_flags
));
7715 if ((section
->sh_flags
& SHF_COMPRESSED
) != 0)
7717 /* Minimum section size is 12 bytes for 32-bit compression
7718 header + 12 bytes for compressed data header. */
7719 unsigned char buf
[24];
7721 assert (sizeof (buf
) >= sizeof (Elf64_External_Chdr
));
7722 if (get_data (&buf
, filedata
, section
->sh_offset
, 1,
7723 sizeof (buf
), _("compression header")))
7725 Elf_Internal_Chdr chdr
;
7727 if (get_compression_header (&chdr
, buf
, sizeof (buf
)) == 0)
7728 printf (_(" [<corrupt>]\n"));
7731 if (chdr
.ch_type
== ELFCOMPRESS_ZLIB
)
7734 printf (_(" [<unknown>: 0x%x], "),
7736 print_vma (chdr
.ch_size
, LONG_HEX
);
7737 printf (", %lu\n", (unsigned long) chdr
.ch_addralign
);
7744 if (!do_section_details
)
7746 /* The ordering of the letters shown here matches the ordering of the
7747 corresponding SHF_xxx values, and hence the order in which these
7748 letters will be displayed to the user. */
7749 printf (_("Key to Flags:\n\
7750 W (write), A (alloc), X (execute), M (merge), S (strings), I (info),\n\
7751 L (link order), O (extra OS processing required), G (group), T (TLS),\n\
7752 C (compressed), x (unknown), o (OS specific), E (exclude),\n "));
7753 switch (filedata
->file_header
.e_ident
[EI_OSABI
])
7756 case ELFOSABI_FREEBSD
:
7757 printf (_("R (retain), "));
7760 printf (_("D (mbind), "));
7765 if (filedata
->file_header
.e_machine
== EM_X86_64
7766 || filedata
->file_header
.e_machine
== EM_L1OM
7767 || filedata
->file_header
.e_machine
== EM_K1OM
)
7768 printf (_("l (large), "));
7769 else if (filedata
->file_header
.e_machine
== EM_ARM
)
7770 printf (_("y (purecode), "));
7771 else if (filedata
->file_header
.e_machine
== EM_PPC
)
7772 printf (_("v (VLE), "));
7773 printf ("p (processor specific)\n");
7780 get_symtab (Filedata
*filedata
, Elf_Internal_Shdr
*symsec
,
7781 Elf_Internal_Sym
**symtab
, unsigned long *nsyms
,
7782 char **strtab
, unsigned long *strtablen
)
7786 *symtab
= get_elf_symbols (filedata
, symsec
, nsyms
);
7788 if (*symtab
== NULL
)
7791 if (symsec
->sh_link
!= 0)
7793 Elf_Internal_Shdr
*strsec
;
7795 if (symsec
->sh_link
>= filedata
->file_header
.e_shnum
)
7797 error (_("Bad sh_link in symbol table section\n"));
7804 strsec
= filedata
->section_headers
+ symsec
->sh_link
;
7806 *strtab
= (char *) get_data (NULL
, filedata
, strsec
->sh_offset
,
7807 1, strsec
->sh_size
, _("string table"));
7808 if (*strtab
== NULL
)
7815 *strtablen
= strsec
->sh_size
;
7821 get_group_flags (unsigned int flags
)
7823 static char buff
[128];
7827 else if (flags
== GRP_COMDAT
)
7830 snprintf (buff
, sizeof buff
, "[0x%x: %s%s%s]",
7832 flags
& GRP_MASKOS
? _("<OS specific>") : "",
7833 flags
& GRP_MASKPROC
? _("<PROC specific>") : "",
7834 (flags
& ~(GRP_COMDAT
| GRP_MASKOS
| GRP_MASKPROC
)
7835 ? _("<unknown>") : ""));
7841 process_section_groups (Filedata
* filedata
)
7843 Elf_Internal_Shdr
* section
;
7845 struct group
* group
;
7846 Elf_Internal_Shdr
* symtab_sec
;
7847 Elf_Internal_Shdr
* strtab_sec
;
7848 Elf_Internal_Sym
* symtab
;
7849 unsigned long num_syms
;
7853 /* Don't process section groups unless needed. */
7854 if (!do_unwind
&& !do_section_groups
)
7857 if (filedata
->file_header
.e_shnum
== 0)
7859 if (do_section_groups
)
7861 if (filedata
->is_separate
)
7862 printf (_("\nThere are no sections group in linked file '%s'.\n"),
7863 filedata
->file_name
);
7865 printf (_("\nThere are no section groups in this file.\n"));
7870 if (filedata
->section_headers
== NULL
)
7872 error (_("Section headers are not available!\n"));
7873 /* PR 13622: This can happen with a corrupt ELF header. */
7877 filedata
->section_headers_groups
7878 = (struct group
**) calloc (filedata
->file_header
.e_shnum
,
7879 sizeof (struct group
*));
7881 if (filedata
->section_headers_groups
== NULL
)
7883 error (_("Out of memory reading %u section group headers\n"),
7884 filedata
->file_header
.e_shnum
);
7888 /* Scan the sections for the group section. */
7889 filedata
->group_count
= 0;
7890 for (i
= 0, section
= filedata
->section_headers
;
7891 i
< filedata
->file_header
.e_shnum
;
7893 if (section
->sh_type
== SHT_GROUP
)
7894 filedata
->group_count
++;
7896 if (filedata
->group_count
== 0)
7898 if (do_section_groups
)
7900 if (filedata
->is_separate
)
7901 printf (_("\nThere are no section groups in linked file '%s'.\n"),
7902 filedata
->file_name
);
7904 printf (_("\nThere are no section groups in this file.\n"));
7910 filedata
->section_groups
= (struct group
*) calloc (filedata
->group_count
,
7911 sizeof (struct group
));
7913 if (filedata
->section_groups
== NULL
)
7915 error (_("Out of memory reading %lu groups\n"),
7916 (unsigned long) filedata
->group_count
);
7927 if (filedata
->is_separate
)
7928 printf (_("Section groups in linked file '%s'\n"), filedata
->file_name
);
7930 for (i
= 0, section
= filedata
->section_headers
, group
= filedata
->section_groups
;
7931 i
< filedata
->file_header
.e_shnum
;
7934 if (section
->sh_type
== SHT_GROUP
)
7936 const char * name
= printable_section_name (filedata
, section
);
7937 const char * group_name
;
7938 unsigned char * start
;
7939 unsigned char * indices
;
7940 unsigned int entry
, j
, size
;
7941 Elf_Internal_Shdr
* sec
;
7942 Elf_Internal_Sym
* sym
;
7944 /* Get the symbol table. */
7945 if (section
->sh_link
>= filedata
->file_header
.e_shnum
7946 || ((sec
= filedata
->section_headers
+ section
->sh_link
)->sh_type
7949 error (_("Bad sh_link in group section `%s'\n"), name
);
7953 if (symtab_sec
!= sec
)
7957 symtab
= get_elf_symbols (filedata
, symtab_sec
, & num_syms
);
7962 error (_("Corrupt header in group section `%s'\n"), name
);
7966 if (section
->sh_info
>= num_syms
)
7968 error (_("Bad sh_info in group section `%s'\n"), name
);
7972 sym
= symtab
+ section
->sh_info
;
7974 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
7976 if (sym
->st_shndx
== 0
7977 || sym
->st_shndx
>= filedata
->file_header
.e_shnum
)
7979 error (_("Bad sh_info in group section `%s'\n"), name
);
7983 group_name
= section_name_print (filedata
,
7984 filedata
->section_headers
7993 /* Get the string table. */
7994 if (symtab_sec
->sh_link
>= filedata
->file_header
.e_shnum
)
8002 != (sec
= filedata
->section_headers
+ symtab_sec
->sh_link
))
8007 strtab
= (char *) get_data (NULL
, filedata
, strtab_sec
->sh_offset
,
8008 1, strtab_sec
->sh_size
,
8010 strtab_size
= strtab
!= NULL
? strtab_sec
->sh_size
: 0;
8012 group_name
= sym
->st_name
< strtab_size
8013 ? strtab
+ sym
->st_name
: _("<corrupt>");
8016 /* PR 17531: file: loop. */
8017 if (section
->sh_entsize
> section
->sh_size
)
8019 error (_("Section %s has sh_entsize (0x%lx) which is larger than its size (0x%lx)\n"),
8020 printable_section_name (filedata
, section
),
8021 (unsigned long) section
->sh_entsize
,
8022 (unsigned long) section
->sh_size
);
8026 start
= (unsigned char *) get_data (NULL
, filedata
, section
->sh_offset
,
8027 1, section
->sh_size
,
8033 size
= (section
->sh_size
/ section
->sh_entsize
) - 1;
8034 entry
= byte_get (indices
, 4);
8037 if (do_section_groups
)
8039 printf (_("\n%sgroup section [%5u] `%s' [%s] contains %u sections:\n"),
8040 get_group_flags (entry
), i
, name
, group_name
, size
);
8042 printf (_(" [Index] Name\n"));
8045 group
->group_index
= i
;
8047 for (j
= 0; j
< size
; j
++)
8049 struct group_list
* g
;
8051 entry
= byte_get (indices
, 4);
8054 if (entry
>= filedata
->file_header
.e_shnum
)
8056 static unsigned num_group_errors
= 0;
8058 if (num_group_errors
++ < 10)
8060 error (_("section [%5u] in group section [%5u] > maximum section [%5u]\n"),
8061 entry
, i
, filedata
->file_header
.e_shnum
- 1);
8062 if (num_group_errors
== 10)
8063 warn (_("Further error messages about overlarge group section indices suppressed\n"));
8068 if (filedata
->section_headers_groups
[entry
] != NULL
)
8072 static unsigned num_errs
= 0;
8074 if (num_errs
++ < 10)
8076 error (_("section [%5u] in group section [%5u] already in group section [%5u]\n"),
8078 filedata
->section_headers_groups
[entry
]->group_index
);
8080 warn (_("Further error messages about already contained group sections suppressed\n"));
8086 /* Intel C/C++ compiler may put section 0 in a
8087 section group. We just warn it the first time
8088 and ignore it afterwards. */
8089 static bool warned
= false;
8092 error (_("section 0 in group section [%5u]\n"),
8093 filedata
->section_headers_groups
[entry
]->group_index
);
8099 filedata
->section_headers_groups
[entry
] = group
;
8101 if (do_section_groups
)
8103 sec
= filedata
->section_headers
+ entry
;
8104 printf (" [%5u] %s\n", entry
, printable_section_name (filedata
, sec
));
8107 g
= (struct group_list
*) xmalloc (sizeof (struct group_list
));
8108 g
->section_index
= entry
;
8109 g
->next
= group
->root
;
8124 /* Data used to display dynamic fixups. */
8126 struct ia64_vms_dynfixup
8128 bfd_vma needed_ident
; /* Library ident number. */
8129 bfd_vma needed
; /* Index in the dstrtab of the library name. */
8130 bfd_vma fixup_needed
; /* Index of the library. */
8131 bfd_vma fixup_rela_cnt
; /* Number of fixups. */
8132 bfd_vma fixup_rela_off
; /* Fixups offset in the dynamic segment. */
8135 /* Data used to display dynamic relocations. */
8137 struct ia64_vms_dynimgrela
8139 bfd_vma img_rela_cnt
; /* Number of relocations. */
8140 bfd_vma img_rela_off
; /* Reloc offset in the dynamic segment. */
8143 /* Display IA-64 OpenVMS dynamic fixups (used to dynamically link a shared
8147 dump_ia64_vms_dynamic_fixups (Filedata
* filedata
,
8148 struct ia64_vms_dynfixup
* fixup
,
8149 const char * strtab
,
8150 unsigned int strtab_sz
)
8152 Elf64_External_VMS_IMAGE_FIXUP
* imfs
;
8154 const char * lib_name
;
8156 imfs
= get_data (NULL
, filedata
,
8157 filedata
->dynamic_addr
+ fixup
->fixup_rela_off
,
8158 sizeof (*imfs
), fixup
->fixup_rela_cnt
,
8159 _("dynamic section image fixups"));
8163 if (fixup
->needed
< strtab_sz
)
8164 lib_name
= strtab
+ fixup
->needed
;
8167 warn (_("corrupt library name index of 0x%lx found in dynamic entry"),
8168 (unsigned long) fixup
->needed
);
8172 printf (_("\nImage fixups for needed library #%d: %s - ident: %lx\n"),
8173 (int) fixup
->fixup_needed
, lib_name
, (long) fixup
->needed_ident
);
8175 (_("Seg Offset Type SymVec DataType\n"));
8177 for (i
= 0; i
< (long) fixup
->fixup_rela_cnt
; i
++)
8182 printf ("%3u ", (unsigned) BYTE_GET (imfs
[i
].fixup_seg
));
8183 printf ("%016" PRIx64
" ", (uint64_t) BYTE_GET (imfs
[i
].fixup_offset
));
8184 type
= BYTE_GET (imfs
[i
].type
);
8185 rtype
= elf_ia64_reloc_type (type
);
8187 printf ("0x%08x ", type
);
8189 printf ("%-32s ", rtype
);
8190 printf ("%6u ", (unsigned) BYTE_GET (imfs
[i
].symvec_index
));
8191 printf ("0x%08x\n", (unsigned) BYTE_GET (imfs
[i
].data_type
));
8198 /* Display IA-64 OpenVMS dynamic relocations (used to relocate an image). */
8201 dump_ia64_vms_dynamic_relocs (Filedata
* filedata
, struct ia64_vms_dynimgrela
*imgrela
)
8203 Elf64_External_VMS_IMAGE_RELA
*imrs
;
8206 imrs
= get_data (NULL
, filedata
,
8207 filedata
->dynamic_addr
+ imgrela
->img_rela_off
,
8208 sizeof (*imrs
), imgrela
->img_rela_cnt
,
8209 _("dynamic section image relocations"));
8213 printf (_("\nImage relocs\n"));
8215 (_("Seg Offset Type Addend Seg Sym Off\n"));
8217 for (i
= 0; i
< (long) imgrela
->img_rela_cnt
; i
++)
8222 printf ("%3u ", (unsigned) BYTE_GET (imrs
[i
].rela_seg
));
8223 printf ("%08" BFD_VMA_FMT
"x ",
8224 (bfd_vma
) BYTE_GET (imrs
[i
].rela_offset
));
8225 type
= BYTE_GET (imrs
[i
].type
);
8226 rtype
= elf_ia64_reloc_type (type
);
8228 printf ("0x%08x ", type
);
8230 printf ("%-31s ", rtype
);
8231 print_vma (BYTE_GET (imrs
[i
].addend
), FULL_HEX
);
8232 printf ("%3u ", (unsigned) BYTE_GET (imrs
[i
].sym_seg
));
8233 printf ("%08" BFD_VMA_FMT
"x\n",
8234 (bfd_vma
) BYTE_GET (imrs
[i
].sym_offset
));
8241 /* Display IA-64 OpenVMS dynamic relocations and fixups. */
8244 process_ia64_vms_dynamic_relocs (Filedata
* filedata
)
8246 struct ia64_vms_dynfixup fixup
;
8247 struct ia64_vms_dynimgrela imgrela
;
8248 Elf_Internal_Dyn
*entry
;
8249 bfd_vma strtab_off
= 0;
8250 bfd_vma strtab_sz
= 0;
8251 char *strtab
= NULL
;
8254 memset (&fixup
, 0, sizeof (fixup
));
8255 memset (&imgrela
, 0, sizeof (imgrela
));
8257 /* Note: the order of the entries is specified by the OpenVMS specs. */
8258 for (entry
= filedata
->dynamic_section
;
8259 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
8262 switch (entry
->d_tag
)
8264 case DT_IA_64_VMS_STRTAB_OFFSET
:
8265 strtab_off
= entry
->d_un
.d_val
;
8268 strtab_sz
= entry
->d_un
.d_val
;
8270 strtab
= get_data (NULL
, filedata
,
8271 filedata
->dynamic_addr
+ strtab_off
,
8272 1, strtab_sz
, _("dynamic string section"));
8277 case DT_IA_64_VMS_NEEDED_IDENT
:
8278 fixup
.needed_ident
= entry
->d_un
.d_val
;
8281 fixup
.needed
= entry
->d_un
.d_val
;
8283 case DT_IA_64_VMS_FIXUP_NEEDED
:
8284 fixup
.fixup_needed
= entry
->d_un
.d_val
;
8286 case DT_IA_64_VMS_FIXUP_RELA_CNT
:
8287 fixup
.fixup_rela_cnt
= entry
->d_un
.d_val
;
8289 case DT_IA_64_VMS_FIXUP_RELA_OFF
:
8290 fixup
.fixup_rela_off
= entry
->d_un
.d_val
;
8291 if (! dump_ia64_vms_dynamic_fixups (filedata
, &fixup
, strtab
, strtab_sz
))
8294 case DT_IA_64_VMS_IMG_RELA_CNT
:
8295 imgrela
.img_rela_cnt
= entry
->d_un
.d_val
;
8297 case DT_IA_64_VMS_IMG_RELA_OFF
:
8298 imgrela
.img_rela_off
= entry
->d_un
.d_val
;
8299 if (! dump_ia64_vms_dynamic_relocs (filedata
, &imgrela
))
8318 relocation_type rel_type
;
8320 dynamic_relocations
[] =
8322 { "REL", DT_REL
, DT_RELSZ
, reltype_rel
},
8323 { "RELA", DT_RELA
, DT_RELASZ
, reltype_rela
},
8324 { "RELR", DT_RELR
, DT_RELRSZ
, reltype_relr
},
8325 { "PLT", DT_JMPREL
, DT_PLTRELSZ
, reltype_unknown
}
8328 /* Process the reloc section. */
8331 process_relocs (Filedata
* filedata
)
8333 unsigned long rel_size
;
8334 unsigned long rel_offset
;
8339 if (do_using_dynamic
)
8341 relocation_type rel_type
;
8343 bool has_dynamic_reloc
;
8346 has_dynamic_reloc
= false;
8348 for (i
= 0; i
< ARRAY_SIZE (dynamic_relocations
); i
++)
8350 rel_type
= dynamic_relocations
[i
].rel_type
;
8351 name
= dynamic_relocations
[i
].name
;
8352 rel_size
= filedata
->dynamic_info
[dynamic_relocations
[i
].size
];
8353 rel_offset
= filedata
->dynamic_info
[dynamic_relocations
[i
].reloc
];
8356 has_dynamic_reloc
= true;
8358 if (rel_type
== reltype_unknown
)
8360 if (dynamic_relocations
[i
].reloc
== DT_JMPREL
)
8361 switch (filedata
->dynamic_info
[DT_PLTREL
])
8364 rel_type
= reltype_rel
;
8367 rel_type
= reltype_rela
;
8374 if (filedata
->is_separate
)
8376 (_("\nIn linked file '%s' section '%s' at offset 0x%lx contains %ld bytes:\n"),
8377 filedata
->file_name
, name
, rel_offset
, rel_size
);
8380 (_("\n'%s' relocation section at offset 0x%lx contains %ld bytes:\n"),
8381 name
, rel_offset
, rel_size
);
8383 dump_relocations (filedata
,
8384 offset_from_vma (filedata
, rel_offset
, rel_size
),
8386 filedata
->dynamic_symbols
,
8387 filedata
->num_dynamic_syms
,
8388 filedata
->dynamic_strings
,
8389 filedata
->dynamic_strings_length
,
8390 rel_type
, true /* is_dynamic */);
8394 if (is_ia64_vms (filedata
))
8395 if (process_ia64_vms_dynamic_relocs (filedata
))
8396 has_dynamic_reloc
= true;
8398 if (! has_dynamic_reloc
)
8400 if (filedata
->is_separate
)
8401 printf (_("\nThere are no dynamic relocations in linked file '%s'.\n"),
8402 filedata
->file_name
);
8404 printf (_("\nThere are no dynamic relocations in this file.\n"));
8409 Elf_Internal_Shdr
* section
;
8413 for (i
= 0, section
= filedata
->section_headers
;
8414 i
< filedata
->file_header
.e_shnum
;
8417 if ( section
->sh_type
!= SHT_RELA
8418 && section
->sh_type
!= SHT_REL
8419 && section
->sh_type
!= SHT_RELR
)
8422 rel_offset
= section
->sh_offset
;
8423 rel_size
= section
->sh_size
;
8427 relocation_type rel_type
;
8428 unsigned long num_rela
;
8430 if (filedata
->is_separate
)
8431 printf (_("\nIn linked file '%s' relocation section "),
8432 filedata
->file_name
);
8434 printf (_("\nRelocation section "));
8436 if (filedata
->string_table
== NULL
)
8437 printf ("%d", section
->sh_name
);
8439 printf ("'%s'", printable_section_name (filedata
, section
));
8441 num_rela
= rel_size
/ section
->sh_entsize
;
8442 printf (ngettext (" at offset 0x%lx contains %lu entry:\n",
8443 " at offset 0x%lx contains %lu entries:\n",
8445 rel_offset
, num_rela
);
8447 rel_type
= section
->sh_type
== SHT_RELA
? reltype_rela
:
8448 section
->sh_type
== SHT_REL
? reltype_rel
: reltype_relr
;
8450 if (section
->sh_link
!= 0
8451 && section
->sh_link
< filedata
->file_header
.e_shnum
)
8453 Elf_Internal_Shdr
* symsec
;
8454 Elf_Internal_Sym
* symtab
;
8455 unsigned long nsyms
;
8456 unsigned long strtablen
= 0;
8457 char * strtab
= NULL
;
8459 symsec
= filedata
->section_headers
+ section
->sh_link
;
8460 if (symsec
->sh_type
!= SHT_SYMTAB
8461 && symsec
->sh_type
!= SHT_DYNSYM
)
8464 if (!get_symtab (filedata
, symsec
,
8465 &symtab
, &nsyms
, &strtab
, &strtablen
))
8468 dump_relocations (filedata
, rel_offset
, rel_size
,
8469 symtab
, nsyms
, strtab
, strtablen
,
8471 symsec
->sh_type
== SHT_DYNSYM
);
8476 dump_relocations (filedata
, rel_offset
, rel_size
,
8477 NULL
, 0, NULL
, 0, rel_type
, false /* is_dynamic */);
8485 /* Users sometimes forget the -D option, so try to be helpful. */
8486 for (i
= 0; i
< ARRAY_SIZE (dynamic_relocations
); i
++)
8488 if (filedata
->dynamic_info
[dynamic_relocations
[i
].size
])
8490 if (filedata
->is_separate
)
8491 printf (_("\nThere are no static relocations in linked file '%s'."),
8492 filedata
->file_name
);
8494 printf (_("\nThere are no static relocations in this file."));
8495 printf (_("\nTo see the dynamic relocations add --use-dynamic to the command line.\n"));
8500 if (i
== ARRAY_SIZE (dynamic_relocations
))
8502 if (filedata
->is_separate
)
8503 printf (_("\nThere are no relocations in linked file '%s'.\n"),
8504 filedata
->file_name
);
8506 printf (_("\nThere are no relocations in this file.\n"));
8514 /* An absolute address consists of a section and an offset. If the
8515 section is NULL, the offset itself is the address, otherwise, the
8516 address equals to LOAD_ADDRESS(section) + offset. */
8520 unsigned short section
;
8524 /* Find the nearest symbol at or below ADDR. Returns the symbol
8525 name, if found, and the offset from the symbol to ADDR. */
8528 find_symbol_for_address (Filedata
* filedata
,
8529 Elf_Internal_Sym
* symtab
,
8530 unsigned long nsyms
,
8531 const char * strtab
,
8532 unsigned long strtab_size
,
8533 struct absaddr addr
,
8534 const char ** symname
,
8537 bfd_vma dist
= 0x100000;
8538 Elf_Internal_Sym
* sym
;
8539 Elf_Internal_Sym
* beg
;
8540 Elf_Internal_Sym
* end
;
8541 Elf_Internal_Sym
* best
= NULL
;
8543 REMOVE_ARCH_BITS (addr
.offset
);
8545 end
= symtab
+ nsyms
;
8551 sym
= beg
+ (end
- beg
) / 2;
8553 value
= sym
->st_value
;
8554 REMOVE_ARCH_BITS (value
);
8556 if (sym
->st_name
!= 0
8557 && (addr
.section
== SHN_UNDEF
|| addr
.section
== sym
->st_shndx
)
8558 && addr
.offset
>= value
8559 && addr
.offset
- value
< dist
)
8562 dist
= addr
.offset
- value
;
8567 if (addr
.offset
< value
)
8575 *symname
= (best
->st_name
>= strtab_size
8576 ? _("<corrupt>") : strtab
+ best
->st_name
);
8582 *offset
= addr
.offset
;
8585 static /* signed */ int
8586 symcmp (const void *p
, const void *q
)
8588 Elf_Internal_Sym
*sp
= (Elf_Internal_Sym
*) p
;
8589 Elf_Internal_Sym
*sq
= (Elf_Internal_Sym
*) q
;
8591 return sp
->st_value
> sq
->st_value
? 1 : (sp
->st_value
< sq
->st_value
? -1 : 0);
8594 /* Process the unwind section. */
8596 #include "unwind-ia64.h"
8598 struct ia64_unw_table_entry
8600 struct absaddr start
;
8602 struct absaddr info
;
8605 struct ia64_unw_aux_info
8607 struct ia64_unw_table_entry
* table
; /* Unwind table. */
8608 unsigned long table_len
; /* Length of unwind table. */
8609 unsigned char * info
; /* Unwind info. */
8610 unsigned long info_size
; /* Size of unwind info. */
8611 bfd_vma info_addr
; /* Starting address of unwind info. */
8612 bfd_vma seg_base
; /* Starting address of segment. */
8613 Elf_Internal_Sym
* symtab
; /* The symbol table. */
8614 unsigned long nsyms
; /* Number of symbols. */
8615 Elf_Internal_Sym
* funtab
; /* Sorted table of STT_FUNC symbols. */
8616 unsigned long nfuns
; /* Number of entries in funtab. */
8617 char * strtab
; /* The string table. */
8618 unsigned long strtab_size
; /* Size of string table. */
8622 dump_ia64_unwind (Filedata
* filedata
, struct ia64_unw_aux_info
* aux
)
8624 struct ia64_unw_table_entry
* tp
;
8625 unsigned long j
, nfuns
;
8629 aux
->funtab
= xmalloc (aux
->nsyms
* sizeof (Elf_Internal_Sym
));
8630 for (nfuns
= 0, j
= 0; j
< aux
->nsyms
; j
++)
8631 if (aux
->symtab
[j
].st_value
&& ELF_ST_TYPE (aux
->symtab
[j
].st_info
) == STT_FUNC
)
8632 aux
->funtab
[nfuns
++] = aux
->symtab
[j
];
8634 qsort (aux
->funtab
, aux
->nfuns
, sizeof (Elf_Internal_Sym
), symcmp
);
8636 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
8640 const unsigned char * dp
;
8641 const unsigned char * head
;
8642 const unsigned char * end
;
8643 const char * procname
;
8645 find_symbol_for_address (filedata
, aux
->funtab
, aux
->nfuns
, aux
->strtab
,
8646 aux
->strtab_size
, tp
->start
, &procname
, &offset
);
8648 fputs ("\n<", stdout
);
8652 fputs (procname
, stdout
);
8655 printf ("+%lx", (unsigned long) offset
);
8658 fputs (">: [", stdout
);
8659 print_vma (tp
->start
.offset
, PREFIX_HEX
);
8660 fputc ('-', stdout
);
8661 print_vma (tp
->end
.offset
, PREFIX_HEX
);
8662 printf ("], info at +0x%lx\n",
8663 (unsigned long) (tp
->info
.offset
- aux
->seg_base
));
8665 /* PR 17531: file: 86232b32. */
8666 if (aux
->info
== NULL
)
8669 offset
= tp
->info
.offset
;
8670 if (tp
->info
.section
)
8672 if (tp
->info
.section
>= filedata
->file_header
.e_shnum
)
8674 warn (_("Invalid section %u in table entry %ld\n"),
8675 tp
->info
.section
, (long) (tp
- aux
->table
));
8679 offset
+= filedata
->section_headers
[tp
->info
.section
].sh_addr
;
8681 offset
-= aux
->info_addr
;
8682 /* PR 17531: file: 0997b4d1. */
8683 if (offset
>= aux
->info_size
8684 || aux
->info_size
- offset
< 8)
8686 warn (_("Invalid offset %lx in table entry %ld\n"),
8687 (long) tp
->info
.offset
, (long) (tp
- aux
->table
));
8692 head
= aux
->info
+ offset
;
8693 stamp
= byte_get ((unsigned char *) head
, sizeof (stamp
));
8695 printf (" v%u, flags=0x%lx (%s%s), len=%lu bytes\n",
8696 (unsigned) UNW_VER (stamp
),
8697 (unsigned long) ((stamp
& UNW_FLAG_MASK
) >> 32),
8698 UNW_FLAG_EHANDLER (stamp
) ? " ehandler" : "",
8699 UNW_FLAG_UHANDLER (stamp
) ? " uhandler" : "",
8700 (unsigned long) (eh_addr_size
* UNW_LENGTH (stamp
)));
8702 if (UNW_VER (stamp
) != 1)
8704 printf (_("\tUnknown version.\n"));
8709 end
= head
+ 8 + eh_addr_size
* UNW_LENGTH (stamp
);
8710 /* PR 17531: file: 16ceda89. */
8711 if (end
> aux
->info
+ aux
->info_size
)
8712 end
= aux
->info
+ aux
->info_size
;
8713 for (dp
= head
+ 8; dp
< end
;)
8714 dp
= unw_decode (dp
, in_body
, & in_body
, end
);
8723 slurp_ia64_unwind_table (Filedata
* filedata
,
8724 struct ia64_unw_aux_info
* aux
,
8725 Elf_Internal_Shdr
* sec
)
8727 unsigned long size
, nrelas
, i
;
8728 Elf_Internal_Phdr
* seg
;
8729 struct ia64_unw_table_entry
* tep
;
8730 Elf_Internal_Shdr
* relsec
;
8731 Elf_Internal_Rela
* rela
;
8732 Elf_Internal_Rela
* rp
;
8733 unsigned char * table
;
8735 Elf_Internal_Sym
* sym
;
8736 const char * relname
;
8740 /* First, find the starting address of the segment that includes
8743 if (filedata
->file_header
.e_phnum
)
8745 if (! get_program_headers (filedata
))
8748 for (seg
= filedata
->program_headers
;
8749 seg
< filedata
->program_headers
+ filedata
->file_header
.e_phnum
;
8752 if (seg
->p_type
!= PT_LOAD
)
8755 if (sec
->sh_addr
>= seg
->p_vaddr
8756 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
8758 aux
->seg_base
= seg
->p_vaddr
;
8764 /* Second, build the unwind table from the contents of the unwind section: */
8765 size
= sec
->sh_size
;
8766 table
= (unsigned char *) get_data (NULL
, filedata
, sec
->sh_offset
, 1, size
,
8771 aux
->table_len
= size
/ (3 * eh_addr_size
);
8772 aux
->table
= (struct ia64_unw_table_entry
*)
8773 xcmalloc (aux
->table_len
, sizeof (aux
->table
[0]));
8776 for (tp
= table
; tp
<= table
+ size
- (3 * eh_addr_size
); ++tep
)
8778 tep
->start
.section
= SHN_UNDEF
;
8779 tep
->end
.section
= SHN_UNDEF
;
8780 tep
->info
.section
= SHN_UNDEF
;
8781 tep
->start
.offset
= byte_get (tp
, eh_addr_size
); tp
+= eh_addr_size
;
8782 tep
->end
.offset
= byte_get (tp
, eh_addr_size
); tp
+= eh_addr_size
;
8783 tep
->info
.offset
= byte_get (tp
, eh_addr_size
); tp
+= eh_addr_size
;
8784 tep
->start
.offset
+= aux
->seg_base
;
8785 tep
->end
.offset
+= aux
->seg_base
;
8786 tep
->info
.offset
+= aux
->seg_base
;
8790 /* Third, apply any relocations to the unwind table: */
8791 for (relsec
= filedata
->section_headers
;
8792 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
8795 if (relsec
->sh_type
!= SHT_RELA
8796 || relsec
->sh_info
>= filedata
->file_header
.e_shnum
8797 || filedata
->section_headers
+ relsec
->sh_info
!= sec
)
8800 if (!slurp_rela_relocs (filedata
, relsec
->sh_offset
, relsec
->sh_size
,
8809 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
8811 unsigned int sym_ndx
;
8812 unsigned int r_type
= get_reloc_type (filedata
, rp
->r_info
);
8813 relname
= elf_ia64_reloc_type (r_type
);
8815 /* PR 17531: file: 9fa67536. */
8816 if (relname
== NULL
)
8818 warn (_("Skipping unknown relocation type: %u\n"), r_type
);
8822 if (! startswith (relname
, "R_IA64_SEGREL"))
8824 warn (_("Skipping unexpected relocation type: %s\n"), relname
);
8828 i
= rp
->r_offset
/ (3 * eh_addr_size
);
8830 /* PR 17531: file: 5bc8d9bf. */
8831 if (i
>= aux
->table_len
)
8833 warn (_("Skipping reloc with overlarge offset: %lx\n"), i
);
8837 sym_ndx
= get_reloc_symindex (rp
->r_info
);
8838 if (sym_ndx
>= aux
->nsyms
)
8840 warn (_("Skipping reloc with invalid symbol index: %u\n"),
8844 sym
= aux
->symtab
+ sym_ndx
;
8846 switch (rp
->r_offset
/ eh_addr_size
% 3)
8849 aux
->table
[i
].start
.section
= sym
->st_shndx
;
8850 aux
->table
[i
].start
.offset
= rp
->r_addend
+ sym
->st_value
;
8853 aux
->table
[i
].end
.section
= sym
->st_shndx
;
8854 aux
->table
[i
].end
.offset
= rp
->r_addend
+ sym
->st_value
;
8857 aux
->table
[i
].info
.section
= sym
->st_shndx
;
8858 aux
->table
[i
].info
.offset
= rp
->r_addend
+ sym
->st_value
;
8872 ia64_process_unwind (Filedata
* filedata
)
8874 Elf_Internal_Shdr
* sec
;
8875 Elf_Internal_Shdr
* unwsec
= NULL
;
8876 unsigned long i
, unwcount
= 0, unwstart
= 0;
8877 struct ia64_unw_aux_info aux
;
8880 memset (& aux
, 0, sizeof (aux
));
8882 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
8884 if (sec
->sh_type
== SHT_SYMTAB
)
8888 error (_("Multiple symbol tables encountered\n"));
8894 if (!get_symtab (filedata
, sec
, &aux
.symtab
, &aux
.nsyms
,
8895 &aux
.strtab
, &aux
.strtab_size
))
8898 else if (sec
->sh_type
== SHT_IA_64_UNWIND
)
8903 printf (_("\nThere are no unwind sections in this file.\n"));
8905 while (unwcount
-- > 0)
8910 for (i
= unwstart
, sec
= filedata
->section_headers
+ unwstart
, unwsec
= NULL
;
8911 i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
8912 if (sec
->sh_type
== SHT_IA_64_UNWIND
)
8917 /* We have already counted the number of SHT_IA64_UNWIND
8918 sections so the loop above should never fail. */
8919 assert (unwsec
!= NULL
);
8922 len
= sizeof (ELF_STRING_ia64_unwind_once
) - 1;
8924 if ((unwsec
->sh_flags
& SHF_GROUP
) != 0)
8926 /* We need to find which section group it is in. */
8927 struct group_list
* g
;
8929 if (filedata
->section_headers_groups
== NULL
8930 || filedata
->section_headers_groups
[i
] == NULL
)
8931 i
= filedata
->file_header
.e_shnum
;
8934 g
= filedata
->section_headers_groups
[i
]->root
;
8936 for (; g
!= NULL
; g
= g
->next
)
8938 sec
= filedata
->section_headers
+ g
->section_index
;
8940 if (section_name_valid (filedata
, sec
)
8941 && streq (section_name (filedata
, sec
),
8942 ELF_STRING_ia64_unwind_info
))
8947 i
= filedata
->file_header
.e_shnum
;
8950 else if (section_name_valid (filedata
, unwsec
)
8951 && startswith (section_name (filedata
, unwsec
),
8952 ELF_STRING_ia64_unwind_once
))
8954 /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO. */
8955 len2
= sizeof (ELF_STRING_ia64_unwind_info_once
) - 1;
8956 suffix
= section_name (filedata
, unwsec
) + len
;
8957 for (i
= 0, sec
= filedata
->section_headers
;
8958 i
< filedata
->file_header
.e_shnum
;
8960 if (section_name_valid (filedata
, sec
)
8961 && startswith (section_name (filedata
, sec
),
8962 ELF_STRING_ia64_unwind_info_once
)
8963 && streq (section_name (filedata
, sec
) + len2
, suffix
))
8968 /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
8969 .IA_64.unwind or BAR -> .IA_64.unwind_info. */
8970 len
= sizeof (ELF_STRING_ia64_unwind
) - 1;
8971 len2
= sizeof (ELF_STRING_ia64_unwind_info
) - 1;
8973 if (section_name_valid (filedata
, unwsec
)
8974 && startswith (section_name (filedata
, unwsec
),
8975 ELF_STRING_ia64_unwind
))
8976 suffix
= section_name (filedata
, unwsec
) + len
;
8977 for (i
= 0, sec
= filedata
->section_headers
;
8978 i
< filedata
->file_header
.e_shnum
;
8980 if (section_name_valid (filedata
, sec
)
8981 && startswith (section_name (filedata
, sec
),
8982 ELF_STRING_ia64_unwind_info
)
8983 && streq (section_name (filedata
, sec
) + len2
, suffix
))
8987 if (i
== filedata
->file_header
.e_shnum
)
8989 printf (_("\nCould not find unwind info section for "));
8991 if (filedata
->string_table
== NULL
)
8992 printf ("%d", unwsec
->sh_name
);
8994 printf ("'%s'", printable_section_name (filedata
, unwsec
));
8998 aux
.info_addr
= sec
->sh_addr
;
8999 aux
.info
= (unsigned char *) get_data (NULL
, filedata
, sec
->sh_offset
, 1,
9002 aux
.info_size
= aux
.info
== NULL
? 0 : sec
->sh_size
;
9004 printf (_("\nUnwind section "));
9006 if (filedata
->string_table
== NULL
)
9007 printf ("%d", unwsec
->sh_name
);
9009 printf ("'%s'", printable_section_name (filedata
, unwsec
));
9011 printf (_(" at offset 0x%lx contains %lu entries:\n"),
9012 (unsigned long) unwsec
->sh_offset
,
9013 (unsigned long) (unwsec
->sh_size
/ (3 * eh_addr_size
)));
9015 if (slurp_ia64_unwind_table (filedata
, & aux
, unwsec
)
9016 && aux
.table_len
> 0)
9017 dump_ia64_unwind (filedata
, & aux
);
9019 free ((char *) aux
.table
);
9020 free ((char *) aux
.info
);
9027 free ((char *) aux
.strtab
);
9032 struct hppa_unw_table_entry
9034 struct absaddr start
;
9036 unsigned int Cannot_unwind
:1; /* 0 */
9037 unsigned int Millicode
:1; /* 1 */
9038 unsigned int Millicode_save_sr0
:1; /* 2 */
9039 unsigned int Region_description
:2; /* 3..4 */
9040 unsigned int reserved1
:1; /* 5 */
9041 unsigned int Entry_SR
:1; /* 6 */
9042 unsigned int Entry_FR
:4; /* Number saved 7..10 */
9043 unsigned int Entry_GR
:5; /* Number saved 11..15 */
9044 unsigned int Args_stored
:1; /* 16 */
9045 unsigned int Variable_Frame
:1; /* 17 */
9046 unsigned int Separate_Package_Body
:1; /* 18 */
9047 unsigned int Frame_Extension_Millicode
:1; /* 19 */
9048 unsigned int Stack_Overflow_Check
:1; /* 20 */
9049 unsigned int Two_Instruction_SP_Increment
:1; /* 21 */
9050 unsigned int Ada_Region
:1; /* 22 */
9051 unsigned int cxx_info
:1; /* 23 */
9052 unsigned int cxx_try_catch
:1; /* 24 */
9053 unsigned int sched_entry_seq
:1; /* 25 */
9054 unsigned int reserved2
:1; /* 26 */
9055 unsigned int Save_SP
:1; /* 27 */
9056 unsigned int Save_RP
:1; /* 28 */
9057 unsigned int Save_MRP_in_frame
:1; /* 29 */
9058 unsigned int extn_ptr_defined
:1; /* 30 */
9059 unsigned int Cleanup_defined
:1; /* 31 */
9061 unsigned int MPE_XL_interrupt_marker
:1; /* 0 */
9062 unsigned int HP_UX_interrupt_marker
:1; /* 1 */
9063 unsigned int Large_frame
:1; /* 2 */
9064 unsigned int Pseudo_SP_Set
:1; /* 3 */
9065 unsigned int reserved4
:1; /* 4 */
9066 unsigned int Total_frame_size
:27; /* 5..31 */
9069 struct hppa_unw_aux_info
9071 struct hppa_unw_table_entry
* table
; /* Unwind table. */
9072 unsigned long table_len
; /* Length of unwind table. */
9073 bfd_vma seg_base
; /* Starting address of segment. */
9074 Elf_Internal_Sym
* symtab
; /* The symbol table. */
9075 unsigned long nsyms
; /* Number of symbols. */
9076 Elf_Internal_Sym
* funtab
; /* Sorted table of STT_FUNC symbols. */
9077 unsigned long nfuns
; /* Number of entries in funtab. */
9078 char * strtab
; /* The string table. */
9079 unsigned long strtab_size
; /* Size of string table. */
9083 dump_hppa_unwind (Filedata
* filedata
, struct hppa_unw_aux_info
* aux
)
9085 struct hppa_unw_table_entry
* tp
;
9086 unsigned long j
, nfuns
;
9089 aux
->funtab
= xmalloc (aux
->nsyms
* sizeof (Elf_Internal_Sym
));
9090 for (nfuns
= 0, j
= 0; j
< aux
->nsyms
; j
++)
9091 if (aux
->symtab
[j
].st_value
&& ELF_ST_TYPE (aux
->symtab
[j
].st_info
) == STT_FUNC
)
9092 aux
->funtab
[nfuns
++] = aux
->symtab
[j
];
9094 qsort (aux
->funtab
, aux
->nfuns
, sizeof (Elf_Internal_Sym
), symcmp
);
9096 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
9099 const char * procname
;
9101 find_symbol_for_address (filedata
, aux
->funtab
, aux
->nfuns
, aux
->strtab
,
9102 aux
->strtab_size
, tp
->start
, &procname
,
9105 fputs ("\n<", stdout
);
9109 fputs (procname
, stdout
);
9112 printf ("+%lx", (unsigned long) offset
);
9115 fputs (">: [", stdout
);
9116 print_vma (tp
->start
.offset
, PREFIX_HEX
);
9117 fputc ('-', stdout
);
9118 print_vma (tp
->end
.offset
, PREFIX_HEX
);
9121 #define PF(_m) if (tp->_m) printf (#_m " ");
9122 #define PV(_m) if (tp->_m) printf (#_m "=%d ", tp->_m);
9125 PF(Millicode_save_sr0
);
9126 /* PV(Region_description); */
9132 PF(Separate_Package_Body
);
9133 PF(Frame_Extension_Millicode
);
9134 PF(Stack_Overflow_Check
);
9135 PF(Two_Instruction_SP_Increment
);
9139 PF(sched_entry_seq
);
9142 PF(Save_MRP_in_frame
);
9143 PF(extn_ptr_defined
);
9144 PF(Cleanup_defined
);
9145 PF(MPE_XL_interrupt_marker
);
9146 PF(HP_UX_interrupt_marker
);
9149 PV(Total_frame_size
);
9162 slurp_hppa_unwind_table (Filedata
* filedata
,
9163 struct hppa_unw_aux_info
* aux
,
9164 Elf_Internal_Shdr
* sec
)
9166 unsigned long size
, unw_ent_size
, nentries
, nrelas
, i
;
9167 Elf_Internal_Phdr
* seg
;
9168 struct hppa_unw_table_entry
* tep
;
9169 Elf_Internal_Shdr
* relsec
;
9170 Elf_Internal_Rela
* rela
;
9171 Elf_Internal_Rela
* rp
;
9172 unsigned char * table
;
9174 Elf_Internal_Sym
* sym
;
9175 const char * relname
;
9177 /* First, find the starting address of the segment that includes
9179 if (filedata
->file_header
.e_phnum
)
9181 if (! get_program_headers (filedata
))
9184 for (seg
= filedata
->program_headers
;
9185 seg
< filedata
->program_headers
+ filedata
->file_header
.e_phnum
;
9188 if (seg
->p_type
!= PT_LOAD
)
9191 if (sec
->sh_addr
>= seg
->p_vaddr
9192 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
9194 aux
->seg_base
= seg
->p_vaddr
;
9200 /* Second, build the unwind table from the contents of the unwind
9202 size
= sec
->sh_size
;
9203 table
= (unsigned char *) get_data (NULL
, filedata
, sec
->sh_offset
, 1, size
,
9209 nentries
= size
/ unw_ent_size
;
9210 size
= unw_ent_size
* nentries
;
9212 aux
->table_len
= nentries
;
9213 tep
= aux
->table
= (struct hppa_unw_table_entry
*)
9214 xcmalloc (nentries
, sizeof (aux
->table
[0]));
9216 for (tp
= table
; tp
< table
+ size
; tp
+= unw_ent_size
, ++tep
)
9218 unsigned int tmp1
, tmp2
;
9220 tep
->start
.section
= SHN_UNDEF
;
9221 tep
->end
.section
= SHN_UNDEF
;
9223 tep
->start
.offset
= byte_get ((unsigned char *) tp
+ 0, 4);
9224 tep
->end
.offset
= byte_get ((unsigned char *) tp
+ 4, 4);
9225 tmp1
= byte_get ((unsigned char *) tp
+ 8, 4);
9226 tmp2
= byte_get ((unsigned char *) tp
+ 12, 4);
9228 tep
->start
.offset
+= aux
->seg_base
;
9229 tep
->end
.offset
+= aux
->seg_base
;
9231 tep
->Cannot_unwind
= (tmp1
>> 31) & 0x1;
9232 tep
->Millicode
= (tmp1
>> 30) & 0x1;
9233 tep
->Millicode_save_sr0
= (tmp1
>> 29) & 0x1;
9234 tep
->Region_description
= (tmp1
>> 27) & 0x3;
9235 tep
->reserved1
= (tmp1
>> 26) & 0x1;
9236 tep
->Entry_SR
= (tmp1
>> 25) & 0x1;
9237 tep
->Entry_FR
= (tmp1
>> 21) & 0xf;
9238 tep
->Entry_GR
= (tmp1
>> 16) & 0x1f;
9239 tep
->Args_stored
= (tmp1
>> 15) & 0x1;
9240 tep
->Variable_Frame
= (tmp1
>> 14) & 0x1;
9241 tep
->Separate_Package_Body
= (tmp1
>> 13) & 0x1;
9242 tep
->Frame_Extension_Millicode
= (tmp1
>> 12) & 0x1;
9243 tep
->Stack_Overflow_Check
= (tmp1
>> 11) & 0x1;
9244 tep
->Two_Instruction_SP_Increment
= (tmp1
>> 10) & 0x1;
9245 tep
->Ada_Region
= (tmp1
>> 9) & 0x1;
9246 tep
->cxx_info
= (tmp1
>> 8) & 0x1;
9247 tep
->cxx_try_catch
= (tmp1
>> 7) & 0x1;
9248 tep
->sched_entry_seq
= (tmp1
>> 6) & 0x1;
9249 tep
->reserved2
= (tmp1
>> 5) & 0x1;
9250 tep
->Save_SP
= (tmp1
>> 4) & 0x1;
9251 tep
->Save_RP
= (tmp1
>> 3) & 0x1;
9252 tep
->Save_MRP_in_frame
= (tmp1
>> 2) & 0x1;
9253 tep
->extn_ptr_defined
= (tmp1
>> 1) & 0x1;
9254 tep
->Cleanup_defined
= tmp1
& 0x1;
9256 tep
->MPE_XL_interrupt_marker
= (tmp2
>> 31) & 0x1;
9257 tep
->HP_UX_interrupt_marker
= (tmp2
>> 30) & 0x1;
9258 tep
->Large_frame
= (tmp2
>> 29) & 0x1;
9259 tep
->Pseudo_SP_Set
= (tmp2
>> 28) & 0x1;
9260 tep
->reserved4
= (tmp2
>> 27) & 0x1;
9261 tep
->Total_frame_size
= tmp2
& 0x7ffffff;
9265 /* Third, apply any relocations to the unwind table. */
9266 for (relsec
= filedata
->section_headers
;
9267 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
9270 if (relsec
->sh_type
!= SHT_RELA
9271 || relsec
->sh_info
>= filedata
->file_header
.e_shnum
9272 || filedata
->section_headers
+ relsec
->sh_info
!= sec
)
9275 if (!slurp_rela_relocs (filedata
, relsec
->sh_offset
, relsec
->sh_size
,
9279 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
9281 unsigned int sym_ndx
;
9282 unsigned int r_type
= get_reloc_type (filedata
, rp
->r_info
);
9283 relname
= elf_hppa_reloc_type (r_type
);
9285 if (relname
== NULL
)
9287 warn (_("Skipping unknown relocation type: %u\n"), r_type
);
9291 /* R_PARISC_SEGREL32 or R_PARISC_SEGREL64. */
9292 if (! startswith (relname
, "R_PARISC_SEGREL"))
9294 warn (_("Skipping unexpected relocation type: %s\n"), relname
);
9298 i
= rp
->r_offset
/ unw_ent_size
;
9299 if (i
>= aux
->table_len
)
9301 warn (_("Skipping reloc with overlarge offset: %lx\n"), i
);
9305 sym_ndx
= get_reloc_symindex (rp
->r_info
);
9306 if (sym_ndx
>= aux
->nsyms
)
9308 warn (_("Skipping reloc with invalid symbol index: %u\n"),
9312 sym
= aux
->symtab
+ sym_ndx
;
9314 switch ((rp
->r_offset
% unw_ent_size
) / 4)
9317 aux
->table
[i
].start
.section
= sym
->st_shndx
;
9318 aux
->table
[i
].start
.offset
= sym
->st_value
+ rp
->r_addend
;
9321 aux
->table
[i
].end
.section
= sym
->st_shndx
;
9322 aux
->table
[i
].end
.offset
= sym
->st_value
+ rp
->r_addend
;
9336 hppa_process_unwind (Filedata
* filedata
)
9338 struct hppa_unw_aux_info aux
;
9339 Elf_Internal_Shdr
* unwsec
= NULL
;
9340 Elf_Internal_Shdr
* sec
;
9344 if (filedata
->string_table
== NULL
)
9347 memset (& aux
, 0, sizeof (aux
));
9349 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
9351 if (sec
->sh_type
== SHT_SYMTAB
)
9355 error (_("Multiple symbol tables encountered\n"));
9361 if (!get_symtab (filedata
, sec
, &aux
.symtab
, &aux
.nsyms
,
9362 &aux
.strtab
, &aux
.strtab_size
))
9365 else if (section_name_valid (filedata
, sec
)
9366 && streq (section_name (filedata
, sec
), ".PARISC.unwind"))
9371 printf (_("\nThere are no unwind sections in this file.\n"));
9373 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
9375 if (section_name_valid (filedata
, sec
)
9376 && streq (section_name (filedata
, sec
), ".PARISC.unwind"))
9378 unsigned long num_unwind
= sec
->sh_size
/ 16;
9380 printf (ngettext ("\nUnwind section '%s' at offset 0x%lx "
9381 "contains %lu entry:\n",
9382 "\nUnwind section '%s' at offset 0x%lx "
9383 "contains %lu entries:\n",
9385 printable_section_name (filedata
, sec
),
9386 (unsigned long) sec
->sh_offset
,
9389 if (! slurp_hppa_unwind_table (filedata
, &aux
, sec
))
9392 if (res
&& aux
.table_len
> 0)
9394 if (! dump_hppa_unwind (filedata
, &aux
))
9398 free ((char *) aux
.table
);
9404 free ((char *) aux
.strtab
);
9411 unsigned char * data
; /* The unwind data. */
9412 Elf_Internal_Shdr
* sec
; /* The cached unwind section header. */
9413 Elf_Internal_Rela
* rela
; /* The cached relocations for this section. */
9414 unsigned long nrelas
; /* The number of relocations. */
9415 unsigned int rel_type
; /* REL or RELA ? */
9416 Elf_Internal_Rela
* next_rela
; /* Cyclic pointer to the next reloc to process. */
9419 struct arm_unw_aux_info
9421 Filedata
* filedata
; /* The file containing the unwind sections. */
9422 Elf_Internal_Sym
* symtab
; /* The file's symbol table. */
9423 unsigned long nsyms
; /* Number of symbols. */
9424 Elf_Internal_Sym
* funtab
; /* Sorted table of STT_FUNC symbols. */
9425 unsigned long nfuns
; /* Number of these symbols. */
9426 char * strtab
; /* The file's string table. */
9427 unsigned long strtab_size
; /* Size of string table. */
9431 arm_print_vma_and_name (Filedata
* filedata
,
9432 struct arm_unw_aux_info
* aux
,
9434 struct absaddr addr
)
9436 const char *procname
;
9439 if (addr
.section
== SHN_UNDEF
)
9442 find_symbol_for_address (filedata
, aux
->funtab
, aux
->nfuns
, aux
->strtab
,
9443 aux
->strtab_size
, addr
, &procname
,
9446 print_vma (fn
, PREFIX_HEX
);
9450 fputs (" <", stdout
);
9451 fputs (procname
, stdout
);
9454 printf ("+0x%lx", (unsigned long) sym_offset
);
9455 fputc ('>', stdout
);
9462 arm_free_section (struct arm_section
*arm_sec
)
9464 free (arm_sec
->data
);
9465 free (arm_sec
->rela
);
9468 /* 1) If SEC does not match the one cached in ARM_SEC, then free the current
9469 cached section and install SEC instead.
9470 2) Locate the 32-bit word at WORD_OFFSET in unwind section SEC
9471 and return its valued in * WORDP, relocating if necessary.
9472 3) Update the NEXT_RELA field in ARM_SEC and store the section index and
9473 relocation's offset in ADDR.
9474 4) If SYM_NAME is non-NULL and a relocation was applied, record the offset
9475 into the string table of the symbol associated with the reloc. If no
9476 reloc was applied store -1 there.
9477 5) Return TRUE upon success, FALSE otherwise. */
9480 get_unwind_section_word (Filedata
* filedata
,
9481 struct arm_unw_aux_info
* aux
,
9482 struct arm_section
* arm_sec
,
9483 Elf_Internal_Shdr
* sec
,
9484 bfd_vma word_offset
,
9485 unsigned int * wordp
,
9486 struct absaddr
* addr
,
9489 Elf_Internal_Rela
*rp
;
9490 Elf_Internal_Sym
*sym
;
9491 const char * relname
;
9495 if (sec
== NULL
|| arm_sec
== NULL
)
9498 addr
->section
= SHN_UNDEF
;
9501 if (sym_name
!= NULL
)
9502 *sym_name
= (bfd_vma
) -1;
9504 /* If necessary, update the section cache. */
9505 if (sec
!= arm_sec
->sec
)
9507 Elf_Internal_Shdr
*relsec
;
9509 arm_free_section (arm_sec
);
9512 arm_sec
->data
= get_data (NULL
, aux
->filedata
, sec
->sh_offset
, 1,
9513 sec
->sh_size
, _("unwind data"));
9514 arm_sec
->rela
= NULL
;
9515 arm_sec
->nrelas
= 0;
9517 for (relsec
= filedata
->section_headers
;
9518 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
9521 if (relsec
->sh_info
>= filedata
->file_header
.e_shnum
9522 || filedata
->section_headers
+ relsec
->sh_info
!= sec
9523 /* PR 15745: Check the section type as well. */
9524 || (relsec
->sh_type
!= SHT_REL
9525 && relsec
->sh_type
!= SHT_RELA
))
9528 arm_sec
->rel_type
= relsec
->sh_type
;
9529 if (relsec
->sh_type
== SHT_REL
)
9531 if (!slurp_rel_relocs (aux
->filedata
, relsec
->sh_offset
,
9533 & arm_sec
->rela
, & arm_sec
->nrelas
))
9536 else /* relsec->sh_type == SHT_RELA */
9538 if (!slurp_rela_relocs (aux
->filedata
, relsec
->sh_offset
,
9540 & arm_sec
->rela
, & arm_sec
->nrelas
))
9546 arm_sec
->next_rela
= arm_sec
->rela
;
9549 /* If there is no unwind data we can do nothing. */
9550 if (arm_sec
->data
== NULL
)
9553 /* If the offset is invalid then fail. */
9554 if (/* PR 21343 *//* PR 18879 */
9556 || word_offset
> (sec
->sh_size
- 4)
9557 || ((bfd_signed_vma
) word_offset
) < 0)
9560 /* Get the word at the required offset. */
9561 word
= byte_get (arm_sec
->data
+ word_offset
, 4);
9563 /* PR 17531: file: id:000001,src:001266+003044,op:splice,rep:128. */
9564 if (arm_sec
->rela
== NULL
)
9570 /* Look through the relocs to find the one that applies to the provided offset. */
9572 for (rp
= arm_sec
->next_rela
; rp
!= arm_sec
->rela
+ arm_sec
->nrelas
; rp
++)
9574 bfd_vma prelval
, offset
;
9576 if (rp
->r_offset
> word_offset
&& !wrapped
)
9581 if (rp
->r_offset
> word_offset
)
9584 if (rp
->r_offset
& 3)
9586 warn (_("Skipping unexpected relocation at offset 0x%lx\n"),
9587 (unsigned long) rp
->r_offset
);
9591 if (rp
->r_offset
< word_offset
)
9594 /* PR 17531: file: 027-161405-0.004 */
9595 if (aux
->symtab
== NULL
)
9598 if (arm_sec
->rel_type
== SHT_REL
)
9600 offset
= word
& 0x7fffffff;
9601 if (offset
& 0x40000000)
9602 offset
|= ~ (bfd_vma
) 0x7fffffff;
9604 else if (arm_sec
->rel_type
== SHT_RELA
)
9605 offset
= rp
->r_addend
;
9608 error (_("Unknown section relocation type %d encountered\n"),
9613 /* PR 17531 file: 027-1241568-0.004. */
9614 if (ELF32_R_SYM (rp
->r_info
) >= aux
->nsyms
)
9616 error (_("Bad symbol index in unwind relocation (%lu > %lu)\n"),
9617 (unsigned long) ELF32_R_SYM (rp
->r_info
), aux
->nsyms
);
9621 sym
= aux
->symtab
+ ELF32_R_SYM (rp
->r_info
);
9622 offset
+= sym
->st_value
;
9623 prelval
= offset
- (arm_sec
->sec
->sh_addr
+ rp
->r_offset
);
9625 /* Check that we are processing the expected reloc type. */
9626 if (filedata
->file_header
.e_machine
== EM_ARM
)
9628 relname
= elf_arm_reloc_type (ELF32_R_TYPE (rp
->r_info
));
9629 if (relname
== NULL
)
9631 warn (_("Skipping unknown ARM relocation type: %d\n"),
9632 (int) ELF32_R_TYPE (rp
->r_info
));
9636 if (streq (relname
, "R_ARM_NONE"))
9639 if (! streq (relname
, "R_ARM_PREL31"))
9641 warn (_("Skipping unexpected ARM relocation type %s\n"), relname
);
9645 else if (filedata
->file_header
.e_machine
== EM_TI_C6000
)
9647 relname
= elf_tic6x_reloc_type (ELF32_R_TYPE (rp
->r_info
));
9648 if (relname
== NULL
)
9650 warn (_("Skipping unknown C6000 relocation type: %d\n"),
9651 (int) ELF32_R_TYPE (rp
->r_info
));
9655 if (streq (relname
, "R_C6000_NONE"))
9658 if (! streq (relname
, "R_C6000_PREL31"))
9660 warn (_("Skipping unexpected C6000 relocation type %s\n"), relname
);
9668 /* This function currently only supports ARM and TI unwinders. */
9669 warn (_("Only TI and ARM unwinders are currently supported\n"));
9673 word
= (word
& ~ (bfd_vma
) 0x7fffffff) | (prelval
& 0x7fffffff);
9674 addr
->section
= sym
->st_shndx
;
9675 addr
->offset
= offset
;
9678 * sym_name
= sym
->st_name
;
9683 arm_sec
->next_rela
= rp
;
9688 static const char *tic6x_unwind_regnames
[16] =
9690 "A15", "B15", "B14", "B13", "B12", "B11", "B10", "B3",
9691 "A14", "A13", "A12", "A11", "A10",
9692 "[invalid reg 13]", "[invalid reg 14]", "[invalid reg 15]"
9696 decode_tic6x_unwind_regmask (unsigned int mask
)
9700 for (i
= 12; mask
; mask
>>= 1, i
--)
9704 fputs (tic6x_unwind_regnames
[i
], stdout
);
9706 fputs (", ", stdout
);
9712 if (remaining == 0 && more_words) \
9715 if (! get_unwind_section_word (filedata, aux, data_arm_sec, data_sec, \
9716 data_offset, & word, & addr, NULL)) \
9722 #define GET_OP(OP) \
9727 (OP) = word >> 24; \
9732 printf (_("[Truncated opcode]\n")); \
9735 printf ("0x%02x ", OP)
9738 decode_arm_unwind_bytecode (Filedata
* filedata
,
9739 struct arm_unw_aux_info
* aux
,
9741 unsigned int remaining
,
9742 unsigned int more_words
,
9743 bfd_vma data_offset
,
9744 Elf_Internal_Shdr
* data_sec
,
9745 struct arm_section
* data_arm_sec
)
9747 struct absaddr addr
;
9750 /* Decode the unwinding instructions. */
9753 unsigned int op
, op2
;
9762 printf (" 0x%02x ", op
);
9764 if ((op
& 0xc0) == 0x00)
9766 int offset
= ((op
& 0x3f) << 2) + 4;
9768 printf (" vsp = vsp + %d", offset
);
9770 else if ((op
& 0xc0) == 0x40)
9772 int offset
= ((op
& 0x3f) << 2) + 4;
9774 printf (" vsp = vsp - %d", offset
);
9776 else if ((op
& 0xf0) == 0x80)
9779 if (op
== 0x80 && op2
== 0)
9780 printf (_("Refuse to unwind"));
9783 unsigned int mask
= ((op
& 0x0f) << 8) | op2
;
9788 for (i
= 0; i
< 12; i
++)
9789 if (mask
& (1 << i
))
9795 printf ("r%d", 4 + i
);
9800 else if ((op
& 0xf0) == 0x90)
9802 if (op
== 0x9d || op
== 0x9f)
9803 printf (_(" [Reserved]"));
9805 printf (" vsp = r%d", op
& 0x0f);
9807 else if ((op
& 0xf0) == 0xa0)
9809 int end
= 4 + (op
& 0x07);
9814 for (i
= 4; i
<= end
; i
++)
9830 else if (op
== 0xb0)
9831 printf (_(" finish"));
9832 else if (op
== 0xb1)
9835 if (op2
== 0 || (op2
& 0xf0) != 0)
9836 printf (_("[Spare]"));
9839 unsigned int mask
= op2
& 0x0f;
9844 for (i
= 0; i
< 12; i
++)
9845 if (mask
& (1 << i
))
9856 else if (op
== 0xb2)
9858 unsigned char buf
[9];
9859 unsigned int i
, len
;
9860 unsigned long offset
;
9862 for (i
= 0; i
< sizeof (buf
); i
++)
9865 if ((buf
[i
] & 0x80) == 0)
9868 if (i
== sizeof (buf
))
9870 error (_("corrupt change to vsp\n"));
9875 offset
= read_leb128 (buf
, buf
+ i
+ 1, false, &len
, NULL
);
9876 assert (len
== i
+ 1);
9877 offset
= offset
* 4 + 0x204;
9878 printf ("vsp = vsp + %ld", offset
);
9881 else if (op
== 0xb3 || op
== 0xc8 || op
== 0xc9)
9883 unsigned int first
, last
;
9890 printf ("pop {D%d", first
);
9892 printf ("-D%d", first
+ last
);
9895 else if (op
== 0xb4)
9896 printf (_(" pop {ra_auth_code}"));
9897 else if ((op
& 0xf8) == 0xb8 || (op
& 0xf8) == 0xd0)
9899 unsigned int count
= op
& 0x07;
9903 printf ("-D%d", 8 + count
);
9906 else if (op
>= 0xc0 && op
<= 0xc5)
9908 unsigned int count
= op
& 0x07;
9910 printf (" pop {wR10");
9912 printf ("-wR%d", 10 + count
);
9915 else if (op
== 0xc6)
9917 unsigned int first
, last
;
9922 printf ("pop {wR%d", first
);
9924 printf ("-wR%d", first
+ last
);
9927 else if (op
== 0xc7)
9930 if (op2
== 0 || (op2
& 0xf0) != 0)
9931 printf (_("[Spare]"));
9934 unsigned int mask
= op2
& 0x0f;
9939 for (i
= 0; i
< 4; i
++)
9940 if (mask
& (1 << i
))
9946 printf ("wCGR%d", i
);
9953 printf (_(" [unsupported opcode]"));
9964 decode_tic6x_unwind_bytecode (Filedata
* filedata
,
9965 struct arm_unw_aux_info
* aux
,
9967 unsigned int remaining
,
9968 unsigned int more_words
,
9969 bfd_vma data_offset
,
9970 Elf_Internal_Shdr
* data_sec
,
9971 struct arm_section
* data_arm_sec
)
9973 struct absaddr addr
;
9975 /* Decode the unwinding instructions. */
9978 unsigned int op
, op2
;
9987 printf (" 0x%02x ", op
);
9989 if ((op
& 0xc0) == 0x00)
9991 int offset
= ((op
& 0x3f) << 3) + 8;
9992 printf (" sp = sp + %d", offset
);
9994 else if ((op
& 0xc0) == 0x80)
9997 if (op
== 0x80 && op2
== 0)
9998 printf (_("Refuse to unwind"));
10001 unsigned int mask
= ((op
& 0x1f) << 8) | op2
;
10003 printf ("pop compact {");
10007 decode_tic6x_unwind_regmask (mask
);
10011 else if ((op
& 0xf0) == 0xc0)
10014 unsigned int nregs
;
10019 unsigned int offset
;
10023 /* Scan entire instruction first so that GET_OP output is not
10024 interleaved with disassembly. */
10026 for (i
= 0; nregs
< (op
& 0xf); i
++)
10032 regpos
[nregs
].offset
= i
* 2;
10033 regpos
[nregs
].reg
= reg
;
10040 regpos
[nregs
].offset
= i
* 2 + 1;
10041 regpos
[nregs
].reg
= reg
;
10046 printf (_("pop frame {"));
10049 printf (_("*corrupt* - no registers specified"));
10054 for (i
= i
* 2; i
> 0; i
--)
10056 if (regpos
[reg
].offset
== i
- 1)
10058 name
= tic6x_unwind_regnames
[regpos
[reg
].reg
];
10065 fputs (name
, stdout
);
10073 else if (op
== 0xd0)
10074 printf (" MOV FP, SP");
10075 else if (op
== 0xd1)
10076 printf (" __c6xabi_pop_rts");
10077 else if (op
== 0xd2)
10079 unsigned char buf
[9];
10080 unsigned int i
, len
;
10081 unsigned long offset
;
10083 for (i
= 0; i
< sizeof (buf
); i
++)
10086 if ((buf
[i
] & 0x80) == 0)
10089 /* PR 17531: file: id:000001,src:001906+004739,op:splice,rep:2. */
10090 if (i
== sizeof (buf
))
10092 warn (_("Corrupt stack pointer adjustment detected\n"));
10096 offset
= read_leb128 (buf
, buf
+ i
+ 1, false, &len
, NULL
);
10097 assert (len
== i
+ 1);
10098 offset
= offset
* 8 + 0x408;
10099 printf (_("sp = sp + %ld"), offset
);
10101 else if ((op
& 0xf0) == 0xe0)
10103 if ((op
& 0x0f) == 7)
10104 printf (" RETURN");
10106 printf (" MV %s, B3", tic6x_unwind_regnames
[op
& 0x0f]);
10110 printf (_(" [unsupported opcode]"));
10119 arm_expand_prel31 (Filedata
* filedata
, bfd_vma word
, bfd_vma where
)
10123 offset
= word
& 0x7fffffff;
10124 if (offset
& 0x40000000)
10125 offset
|= ~ (bfd_vma
) 0x7fffffff;
10127 if (filedata
->file_header
.e_machine
== EM_TI_C6000
)
10130 return offset
+ where
;
10134 decode_arm_unwind (Filedata
* filedata
,
10135 struct arm_unw_aux_info
* aux
,
10137 unsigned int remaining
,
10138 bfd_vma data_offset
,
10139 Elf_Internal_Shdr
* data_sec
,
10140 struct arm_section
* data_arm_sec
)
10143 unsigned int more_words
= 0;
10144 struct absaddr addr
;
10145 bfd_vma sym_name
= (bfd_vma
) -1;
10148 if (remaining
== 0)
10150 /* Fetch the first word.
10151 Note - when decoding an object file the address extracted
10152 here will always be 0. So we also pass in the sym_name
10153 parameter so that we can find the symbol associated with
10154 the personality routine. */
10155 if (! get_unwind_section_word (filedata
, aux
, data_arm_sec
, data_sec
, data_offset
,
10156 & word
, & addr
, & sym_name
))
10163 addr
.section
= SHN_UNDEF
;
10167 if ((word
& 0x80000000) == 0)
10169 /* Expand prel31 for personality routine. */
10171 const char *procname
;
10173 fn
= arm_expand_prel31 (filedata
, word
, data_sec
->sh_addr
+ data_offset
);
10174 printf (_(" Personality routine: "));
10176 && addr
.section
== SHN_UNDEF
&& addr
.offset
== 0
10177 && sym_name
!= (bfd_vma
) -1 && sym_name
< aux
->strtab_size
)
10179 procname
= aux
->strtab
+ sym_name
;
10180 print_vma (fn
, PREFIX_HEX
);
10183 fputs (" <", stdout
);
10184 fputs (procname
, stdout
);
10185 fputc ('>', stdout
);
10189 procname
= arm_print_vma_and_name (filedata
, aux
, fn
, addr
);
10190 fputc ('\n', stdout
);
10192 /* The GCC personality routines use the standard compact
10193 encoding, starting with one byte giving the number of
10195 if (procname
!= NULL
10196 && (startswith (procname
, "__gcc_personality_v0")
10197 || startswith (procname
, "__gxx_personality_v0")
10198 || startswith (procname
, "__gcj_personality_v0")
10199 || startswith (procname
, "__gnu_objc_personality_v0")))
10206 printf (_(" [Truncated data]\n"));
10209 more_words
= word
>> 24;
10219 /* ARM EHABI Section 6.3:
10221 An exception-handling table entry for the compact model looks like:
10223 31 30-28 27-24 23-0
10224 -- ----- ----- ----
10225 1 0 index Data for personalityRoutine[index] */
10227 if (filedata
->file_header
.e_machine
== EM_ARM
10228 && (word
& 0x70000000))
10230 warn (_("Corrupt ARM compact model table entry: %x \n"), word
);
10234 per_index
= (word
>> 24) & 0x7f;
10235 printf (_(" Compact model index: %d\n"), per_index
);
10236 if (per_index
== 0)
10242 else if (per_index
< 3)
10244 more_words
= (word
>> 16) & 0xff;
10250 switch (filedata
->file_header
.e_machine
)
10255 if (! decode_arm_unwind_bytecode (filedata
, aux
, word
, remaining
, more_words
,
10256 data_offset
, data_sec
, data_arm_sec
))
10261 warn (_("Unknown ARM compact model index encountered\n"));
10262 printf (_(" [reserved]\n"));
10270 if (! decode_tic6x_unwind_bytecode (filedata
, aux
, word
, remaining
, more_words
,
10271 data_offset
, data_sec
, data_arm_sec
))
10274 else if (per_index
< 5)
10276 if (((word
>> 17) & 0x7f) == 0x7f)
10277 printf (_(" Restore stack from frame pointer\n"));
10279 printf (_(" Stack increment %d\n"), (word
>> 14) & 0x1fc);
10280 printf (_(" Registers restored: "));
10281 if (per_index
== 4)
10282 printf (" (compact) ");
10283 decode_tic6x_unwind_regmask ((word
>> 4) & 0x1fff);
10285 printf (_(" Return register: %s\n"),
10286 tic6x_unwind_regnames
[word
& 0xf]);
10289 printf (_(" [reserved (%d)]\n"), per_index
);
10293 error (_("Unsupported architecture type %d encountered when decoding unwind table\n"),
10294 filedata
->file_header
.e_machine
);
10298 /* Decode the descriptors. Not implemented. */
10304 dump_arm_unwind (Filedata
* filedata
,
10305 struct arm_unw_aux_info
* aux
,
10306 Elf_Internal_Shdr
* exidx_sec
)
10308 struct arm_section exidx_arm_sec
, extab_arm_sec
;
10309 unsigned int i
, exidx_len
;
10310 unsigned long j
, nfuns
;
10313 memset (&exidx_arm_sec
, 0, sizeof (exidx_arm_sec
));
10314 memset (&extab_arm_sec
, 0, sizeof (extab_arm_sec
));
10315 exidx_len
= exidx_sec
->sh_size
/ 8;
10317 aux
->funtab
= xmalloc (aux
->nsyms
* sizeof (Elf_Internal_Sym
));
10318 for (nfuns
= 0, j
= 0; j
< aux
->nsyms
; j
++)
10319 if (aux
->symtab
[j
].st_value
&& ELF_ST_TYPE (aux
->symtab
[j
].st_info
) == STT_FUNC
)
10320 aux
->funtab
[nfuns
++] = aux
->symtab
[j
];
10321 aux
->nfuns
= nfuns
;
10322 qsort (aux
->funtab
, aux
->nfuns
, sizeof (Elf_Internal_Sym
), symcmp
);
10324 for (i
= 0; i
< exidx_len
; i
++)
10326 unsigned int exidx_fn
, exidx_entry
;
10327 struct absaddr fn_addr
, entry_addr
;
10330 fputc ('\n', stdout
);
10332 if (! get_unwind_section_word (filedata
, aux
, & exidx_arm_sec
, exidx_sec
,
10333 8 * i
, & exidx_fn
, & fn_addr
, NULL
)
10334 || ! get_unwind_section_word (filedata
, aux
, & exidx_arm_sec
, exidx_sec
,
10335 8 * i
+ 4, & exidx_entry
, & entry_addr
, NULL
))
10337 free (aux
->funtab
);
10338 arm_free_section (& exidx_arm_sec
);
10339 arm_free_section (& extab_arm_sec
);
10343 /* ARM EHABI, Section 5:
10344 An index table entry consists of 2 words.
10345 The first word contains a prel31 offset to the start of a function, with bit 31 clear. */
10346 if (exidx_fn
& 0x80000000)
10348 warn (_("corrupt index table entry: %x\n"), exidx_fn
);
10352 fn
= arm_expand_prel31 (filedata
, exidx_fn
, exidx_sec
->sh_addr
+ 8 * i
);
10354 arm_print_vma_and_name (filedata
, aux
, fn
, fn_addr
);
10355 fputs (": ", stdout
);
10357 if (exidx_entry
== 1)
10359 print_vma (exidx_entry
, PREFIX_HEX
);
10360 fputs (" [cantunwind]\n", stdout
);
10362 else if (exidx_entry
& 0x80000000)
10364 print_vma (exidx_entry
, PREFIX_HEX
);
10365 fputc ('\n', stdout
);
10366 decode_arm_unwind (filedata
, aux
, exidx_entry
, 4, 0, NULL
, NULL
);
10370 bfd_vma table
, table_offset
= 0;
10371 Elf_Internal_Shdr
*table_sec
;
10373 fputs ("@", stdout
);
10374 table
= arm_expand_prel31 (filedata
, exidx_entry
, exidx_sec
->sh_addr
+ 8 * i
+ 4);
10375 print_vma (table
, PREFIX_HEX
);
10378 /* Locate the matching .ARM.extab. */
10379 if (entry_addr
.section
!= SHN_UNDEF
10380 && entry_addr
.section
< filedata
->file_header
.e_shnum
)
10382 table_sec
= filedata
->section_headers
+ entry_addr
.section
;
10383 table_offset
= entry_addr
.offset
;
10385 if (table_offset
> table_sec
->sh_size
10386 || ((bfd_signed_vma
) table_offset
) < 0)
10388 warn (_("Unwind entry contains corrupt offset (0x%lx) into section %s\n"),
10389 (unsigned long) table_offset
,
10390 printable_section_name (filedata
, table_sec
));
10397 table_sec
= find_section_by_address (filedata
, table
);
10398 if (table_sec
!= NULL
)
10399 table_offset
= table
- table_sec
->sh_addr
;
10402 if (table_sec
== NULL
)
10404 warn (_("Could not locate .ARM.extab section containing 0x%lx.\n"),
10405 (unsigned long) table
);
10410 if (! decode_arm_unwind (filedata
, aux
, 0, 0, table_offset
, table_sec
,
10418 free (aux
->funtab
);
10419 arm_free_section (&exidx_arm_sec
);
10420 arm_free_section (&extab_arm_sec
);
10425 /* Used for both ARM and C6X unwinding tables. */
10428 arm_process_unwind (Filedata
* filedata
)
10430 struct arm_unw_aux_info aux
;
10431 Elf_Internal_Shdr
*unwsec
= NULL
;
10432 Elf_Internal_Shdr
*sec
;
10434 unsigned int sec_type
;
10437 switch (filedata
->file_header
.e_machine
)
10440 sec_type
= SHT_ARM_EXIDX
;
10444 sec_type
= SHT_C6000_UNWIND
;
10448 error (_("Unsupported architecture type %d encountered when processing unwind table\n"),
10449 filedata
->file_header
.e_machine
);
10453 if (filedata
->string_table
== NULL
)
10456 memset (& aux
, 0, sizeof (aux
));
10457 aux
.filedata
= filedata
;
10459 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
10461 if (sec
->sh_type
== SHT_SYMTAB
)
10465 error (_("Multiple symbol tables encountered\n"));
10471 if (!get_symtab (filedata
, sec
, &aux
.symtab
, &aux
.nsyms
,
10472 &aux
.strtab
, &aux
.strtab_size
))
10475 else if (sec
->sh_type
== sec_type
)
10479 if (unwsec
== NULL
)
10480 printf (_("\nThere are no unwind sections in this file.\n"));
10482 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
10484 if (sec
->sh_type
== sec_type
)
10486 unsigned long num_unwind
= sec
->sh_size
/ (2 * eh_addr_size
);
10487 printf (ngettext ("\nUnwind section '%s' at offset 0x%lx "
10488 "contains %lu entry:\n",
10489 "\nUnwind section '%s' at offset 0x%lx "
10490 "contains %lu entries:\n",
10492 printable_section_name (filedata
, sec
),
10493 (unsigned long) sec
->sh_offset
,
10496 if (! dump_arm_unwind (filedata
, &aux
, sec
))
10502 free ((char *) aux
.strtab
);
10508 no_processor_specific_unwind (Filedata
* filedata ATTRIBUTE_UNUSED
)
10510 printf (_("No processor specific unwind information to decode\n"));
10515 process_unwind (Filedata
* filedata
)
10517 struct unwind_handler
10519 unsigned int machtype
;
10520 bool (* handler
)(Filedata
*);
10523 { EM_ARM
, arm_process_unwind
},
10524 { EM_IA_64
, ia64_process_unwind
},
10525 { EM_PARISC
, hppa_process_unwind
},
10526 { EM_TI_C6000
, arm_process_unwind
},
10527 { EM_386
, no_processor_specific_unwind
},
10528 { EM_X86_64
, no_processor_specific_unwind
},
10536 for (i
= 0; handlers
[i
].handler
!= NULL
; i
++)
10537 if (filedata
->file_header
.e_machine
== handlers
[i
].machtype
)
10538 return handlers
[i
].handler (filedata
);
10540 printf (_("\nThe decoding of unwind sections for machine type %s is not currently supported.\n"),
10541 get_machine_name (filedata
->file_header
.e_machine
));
10546 dynamic_section_aarch64_val (Elf_Internal_Dyn
* entry
)
10548 switch (entry
->d_tag
)
10550 case DT_AARCH64_BTI_PLT
:
10551 case DT_AARCH64_PAC_PLT
:
10554 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
10561 dynamic_section_mips_val (Filedata
* filedata
, Elf_Internal_Dyn
* entry
)
10563 switch (entry
->d_tag
)
10565 case DT_MIPS_FLAGS
:
10566 if (entry
->d_un
.d_val
== 0)
10567 printf (_("NONE"));
10570 static const char * opts
[] =
10572 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
10573 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
10574 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
10575 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
10581 for (cnt
= 0; cnt
< ARRAY_SIZE (opts
); ++cnt
)
10582 if (entry
->d_un
.d_val
& (1 << cnt
))
10584 printf ("%s%s", first
? "" : " ", opts
[cnt
]);
10590 case DT_MIPS_IVERSION
:
10591 if (valid_dynamic_name (filedata
, entry
->d_un
.d_val
))
10592 printf (_("Interface Version: %s"),
10593 get_dynamic_name (filedata
, entry
->d_un
.d_val
));
10595 printf (_("Interface Version: <corrupt: %" PRIx64
">"),
10596 (uint64_t) entry
->d_un
.d_ptr
);
10599 case DT_MIPS_TIME_STAMP
:
10603 time_t atime
= entry
->d_un
.d_val
;
10605 tmp
= gmtime (&atime
);
10606 /* PR 17531: file: 6accc532. */
10608 snprintf (timebuf
, sizeof (timebuf
), _("<corrupt>"));
10610 snprintf (timebuf
, sizeof (timebuf
), "%04u-%02u-%02uT%02u:%02u:%02u",
10611 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
10612 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
10613 printf (_("Time Stamp: %s"), timebuf
);
10617 case DT_MIPS_RLD_VERSION
:
10618 case DT_MIPS_LOCAL_GOTNO
:
10619 case DT_MIPS_CONFLICTNO
:
10620 case DT_MIPS_LIBLISTNO
:
10621 case DT_MIPS_SYMTABNO
:
10622 case DT_MIPS_UNREFEXTNO
:
10623 case DT_MIPS_HIPAGENO
:
10624 case DT_MIPS_DELTA_CLASS_NO
:
10625 case DT_MIPS_DELTA_INSTANCE_NO
:
10626 case DT_MIPS_DELTA_RELOC_NO
:
10627 case DT_MIPS_DELTA_SYM_NO
:
10628 case DT_MIPS_DELTA_CLASSSYM_NO
:
10629 case DT_MIPS_COMPACT_SIZE
:
10630 print_vma (entry
->d_un
.d_val
, DEC
);
10633 case DT_MIPS_XHASH
:
10634 filedata
->dynamic_info_DT_MIPS_XHASH
= entry
->d_un
.d_val
;
10635 filedata
->dynamic_info_DT_GNU_HASH
= entry
->d_un
.d_val
;
10636 /* Falls through. */
10639 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
10645 dynamic_section_parisc_val (Elf_Internal_Dyn
* entry
)
10647 switch (entry
->d_tag
)
10649 case DT_HP_DLD_FLAGS
:
10658 { DT_HP_DEBUG_PRIVATE
, "HP_DEBUG_PRIVATE" },
10659 { DT_HP_DEBUG_CALLBACK
, "HP_DEBUG_CALLBACK" },
10660 { DT_HP_DEBUG_CALLBACK_BOR
, "HP_DEBUG_CALLBACK_BOR" },
10661 { DT_HP_NO_ENVVAR
, "HP_NO_ENVVAR" },
10662 { DT_HP_BIND_NOW
, "HP_BIND_NOW" },
10663 { DT_HP_BIND_NONFATAL
, "HP_BIND_NONFATAL" },
10664 { DT_HP_BIND_VERBOSE
, "HP_BIND_VERBOSE" },
10665 { DT_HP_BIND_RESTRICTED
, "HP_BIND_RESTRICTED" },
10666 { DT_HP_BIND_SYMBOLIC
, "HP_BIND_SYMBOLIC" },
10667 { DT_HP_RPATH_FIRST
, "HP_RPATH_FIRST" },
10668 { DT_HP_BIND_DEPTH_FIRST
, "HP_BIND_DEPTH_FIRST" },
10669 { DT_HP_GST
, "HP_GST" },
10670 { DT_HP_SHLIB_FIXED
, "HP_SHLIB_FIXED" },
10671 { DT_HP_MERGE_SHLIB_SEG
, "HP_MERGE_SHLIB_SEG" },
10672 { DT_HP_NODELETE
, "HP_NODELETE" },
10673 { DT_HP_GROUP
, "HP_GROUP" },
10674 { DT_HP_PROTECT_LINKAGE_TABLE
, "HP_PROTECT_LINKAGE_TABLE" }
10678 bfd_vma val
= entry
->d_un
.d_val
;
10680 for (cnt
= 0; cnt
< ARRAY_SIZE (flags
); ++cnt
)
10681 if (val
& flags
[cnt
].bit
)
10685 fputs (flags
[cnt
].str
, stdout
);
10687 val
^= flags
[cnt
].bit
;
10690 if (val
!= 0 || first
)
10694 print_vma (val
, HEX
);
10700 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
10708 /* VMS vs Unix time offset and factor. */
10710 #define VMS_EPOCH_OFFSET 35067168000000000LL
10711 #define VMS_GRANULARITY_FACTOR 10000000
10713 #define INT64_MIN (-9223372036854775807LL - 1)
10716 /* Display a VMS time in a human readable format. */
10719 print_vms_time (int64_t vmstime
)
10721 struct tm
*tm
= NULL
;
10724 if (vmstime
>= INT64_MIN
+ VMS_EPOCH_OFFSET
)
10726 vmstime
= (vmstime
- VMS_EPOCH_OFFSET
) / VMS_GRANULARITY_FACTOR
;
10728 if (unxtime
== vmstime
)
10729 tm
= gmtime (&unxtime
);
10732 printf ("%04u-%02u-%02uT%02u:%02u:%02u",
10733 tm
->tm_year
+ 1900, tm
->tm_mon
+ 1, tm
->tm_mday
,
10734 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
);
10739 dynamic_section_ia64_val (Elf_Internal_Dyn
* entry
)
10741 switch (entry
->d_tag
)
10743 case DT_IA_64_PLT_RESERVE
:
10744 /* First 3 slots reserved. */
10745 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
10747 print_vma (entry
->d_un
.d_ptr
+ (3 * 8), PREFIX_HEX
);
10750 case DT_IA_64_VMS_LINKTIME
:
10752 print_vms_time (entry
->d_un
.d_val
);
10756 case DT_IA_64_VMS_LNKFLAGS
:
10757 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
10758 if (entry
->d_un
.d_val
& VMS_LF_CALL_DEBUG
)
10759 printf (" CALL_DEBUG");
10760 if (entry
->d_un
.d_val
& VMS_LF_NOP0BUFS
)
10761 printf (" NOP0BUFS");
10762 if (entry
->d_un
.d_val
& VMS_LF_P0IMAGE
)
10763 printf (" P0IMAGE");
10764 if (entry
->d_un
.d_val
& VMS_LF_MKTHREADS
)
10765 printf (" MKTHREADS");
10766 if (entry
->d_un
.d_val
& VMS_LF_UPCALLS
)
10767 printf (" UPCALLS");
10768 if (entry
->d_un
.d_val
& VMS_LF_IMGSTA
)
10769 printf (" IMGSTA");
10770 if (entry
->d_un
.d_val
& VMS_LF_INITIALIZE
)
10771 printf (" INITIALIZE");
10772 if (entry
->d_un
.d_val
& VMS_LF_MAIN
)
10774 if (entry
->d_un
.d_val
& VMS_LF_EXE_INIT
)
10775 printf (" EXE_INIT");
10776 if (entry
->d_un
.d_val
& VMS_LF_TBK_IN_IMG
)
10777 printf (" TBK_IN_IMG");
10778 if (entry
->d_un
.d_val
& VMS_LF_DBG_IN_IMG
)
10779 printf (" DBG_IN_IMG");
10780 if (entry
->d_un
.d_val
& VMS_LF_TBK_IN_DSF
)
10781 printf (" TBK_IN_DSF");
10782 if (entry
->d_un
.d_val
& VMS_LF_DBG_IN_DSF
)
10783 printf (" DBG_IN_DSF");
10784 if (entry
->d_un
.d_val
& VMS_LF_SIGNATURES
)
10785 printf (" SIGNATURES");
10786 if (entry
->d_un
.d_val
& VMS_LF_REL_SEG_OFF
)
10787 printf (" REL_SEG_OFF");
10791 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
10798 get_32bit_dynamic_section (Filedata
* filedata
)
10800 Elf32_External_Dyn
* edyn
;
10801 Elf32_External_Dyn
* ext
;
10802 Elf_Internal_Dyn
* entry
;
10804 edyn
= (Elf32_External_Dyn
*) get_data (NULL
, filedata
,
10805 filedata
->dynamic_addr
, 1,
10806 filedata
->dynamic_size
,
10807 _("dynamic section"));
10811 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
10812 might not have the luxury of section headers. Look for the DT_NULL
10813 terminator to determine the number of entries. */
10814 for (ext
= edyn
, filedata
->dynamic_nent
= 0;
10815 (char *) (ext
+ 1) <= (char *) edyn
+ filedata
->dynamic_size
;
10818 filedata
->dynamic_nent
++;
10819 if (BYTE_GET (ext
->d_tag
) == DT_NULL
)
10823 filedata
->dynamic_section
10824 = (Elf_Internal_Dyn
*) cmalloc (filedata
->dynamic_nent
, sizeof (* entry
));
10825 if (filedata
->dynamic_section
== NULL
)
10827 error (_("Out of memory allocating space for %lu dynamic entries\n"),
10828 (unsigned long) filedata
->dynamic_nent
);
10833 for (ext
= edyn
, entry
= filedata
->dynamic_section
;
10834 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
10837 entry
->d_tag
= BYTE_GET (ext
->d_tag
);
10838 entry
->d_un
.d_val
= BYTE_GET (ext
->d_un
.d_val
);
10847 get_64bit_dynamic_section (Filedata
* filedata
)
10849 Elf64_External_Dyn
* edyn
;
10850 Elf64_External_Dyn
* ext
;
10851 Elf_Internal_Dyn
* entry
;
10853 /* Read in the data. */
10854 edyn
= (Elf64_External_Dyn
*) get_data (NULL
, filedata
,
10855 filedata
->dynamic_addr
, 1,
10856 filedata
->dynamic_size
,
10857 _("dynamic section"));
10861 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
10862 might not have the luxury of section headers. Look for the DT_NULL
10863 terminator to determine the number of entries. */
10864 for (ext
= edyn
, filedata
->dynamic_nent
= 0;
10865 /* PR 17533 file: 033-67080-0.004 - do not read past end of buffer. */
10866 (char *) (ext
+ 1) <= (char *) edyn
+ filedata
->dynamic_size
;
10869 filedata
->dynamic_nent
++;
10870 if (BYTE_GET (ext
->d_tag
) == DT_NULL
)
10874 filedata
->dynamic_section
10875 = (Elf_Internal_Dyn
*) cmalloc (filedata
->dynamic_nent
, sizeof (* entry
));
10876 if (filedata
->dynamic_section
== NULL
)
10878 error (_("Out of memory allocating space for %lu dynamic entries\n"),
10879 (unsigned long) filedata
->dynamic_nent
);
10884 /* Convert from external to internal formats. */
10885 for (ext
= edyn
, entry
= filedata
->dynamic_section
;
10886 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
10889 entry
->d_tag
= BYTE_GET (ext
->d_tag
);
10890 entry
->d_un
.d_val
= BYTE_GET (ext
->d_un
.d_val
);
10899 get_dynamic_section (Filedata
*filedata
)
10901 if (filedata
->dynamic_section
)
10905 return get_32bit_dynamic_section (filedata
);
10907 return get_64bit_dynamic_section (filedata
);
10911 print_dynamic_flags (bfd_vma flags
)
10919 flag
= flags
& - flags
;
10925 putc (' ', stdout
);
10929 case DF_ORIGIN
: fputs ("ORIGIN", stdout
); break;
10930 case DF_SYMBOLIC
: fputs ("SYMBOLIC", stdout
); break;
10931 case DF_TEXTREL
: fputs ("TEXTREL", stdout
); break;
10932 case DF_BIND_NOW
: fputs ("BIND_NOW", stdout
); break;
10933 case DF_STATIC_TLS
: fputs ("STATIC_TLS", stdout
); break;
10934 default: fputs (_("unknown"), stdout
); break;
10941 get_dynamic_data (Filedata
* filedata
, bfd_size_type number
, unsigned int ent_size
)
10943 unsigned char * e_data
;
10946 /* If the size_t type is smaller than the bfd_size_type, eg because
10947 you are building a 32-bit tool on a 64-bit host, then make sure
10948 that when (number) is cast to (size_t) no information is lost. */
10949 if (sizeof (size_t) < sizeof (bfd_size_type
)
10950 && (bfd_size_type
) ((size_t) number
) != number
)
10952 error (_("Size truncation prevents reading %s elements of size %u\n"),
10953 bfd_vmatoa ("u", number
), ent_size
);
10957 /* Be kind to memory checkers (eg valgrind, address sanitizer) by not
10958 attempting to allocate memory when the read is bound to fail. */
10959 if (ent_size
* number
> filedata
->file_size
)
10961 error (_("Invalid number of dynamic entries: %s\n"),
10962 bfd_vmatoa ("u", number
));
10966 e_data
= (unsigned char *) cmalloc ((size_t) number
, ent_size
);
10967 if (e_data
== NULL
)
10969 error (_("Out of memory reading %s dynamic entries\n"),
10970 bfd_vmatoa ("u", number
));
10974 if (fread (e_data
, ent_size
, (size_t) number
, filedata
->handle
) != number
)
10976 error (_("Unable to read in %s bytes of dynamic data\n"),
10977 bfd_vmatoa ("u", number
* ent_size
));
10982 i_data
= (bfd_vma
*) cmalloc ((size_t) number
, sizeof (*i_data
));
10983 if (i_data
== NULL
)
10985 error (_("Out of memory allocating space for %s dynamic entries\n"),
10986 bfd_vmatoa ("u", number
));
10992 i_data
[number
] = byte_get (e_data
+ number
* ent_size
, ent_size
);
10999 static unsigned long
11000 get_num_dynamic_syms (Filedata
* filedata
)
11002 unsigned long num_of_syms
= 0;
11004 if (!do_histogram
&& (!do_using_dynamic
|| do_dyn_syms
))
11005 return num_of_syms
;
11007 if (filedata
->dynamic_info
[DT_HASH
])
11009 unsigned char nb
[8];
11010 unsigned char nc
[8];
11011 unsigned int hash_ent_size
= 4;
11013 if ((filedata
->file_header
.e_machine
== EM_ALPHA
11014 || filedata
->file_header
.e_machine
== EM_S390
11015 || filedata
->file_header
.e_machine
== EM_S390_OLD
)
11016 && filedata
->file_header
.e_ident
[EI_CLASS
] == ELFCLASS64
)
11019 if (fseek (filedata
->handle
,
11020 (filedata
->archive_file_offset
11021 + offset_from_vma (filedata
, filedata
->dynamic_info
[DT_HASH
],
11022 sizeof nb
+ sizeof nc
)),
11025 error (_("Unable to seek to start of dynamic information\n"));
11029 if (fread (nb
, hash_ent_size
, 1, filedata
->handle
) != 1)
11031 error (_("Failed to read in number of buckets\n"));
11035 if (fread (nc
, hash_ent_size
, 1, filedata
->handle
) != 1)
11037 error (_("Failed to read in number of chains\n"));
11041 filedata
->nbuckets
= byte_get (nb
, hash_ent_size
);
11042 filedata
->nchains
= byte_get (nc
, hash_ent_size
);
11044 if (filedata
->nbuckets
!= 0 && filedata
->nchains
!= 0)
11046 filedata
->buckets
= get_dynamic_data (filedata
, filedata
->nbuckets
,
11048 filedata
->chains
= get_dynamic_data (filedata
, filedata
->nchains
,
11051 if (filedata
->buckets
!= NULL
&& filedata
->chains
!= NULL
)
11052 num_of_syms
= filedata
->nchains
;
11055 if (num_of_syms
== 0)
11057 free (filedata
->buckets
);
11058 filedata
->buckets
= NULL
;
11059 free (filedata
->chains
);
11060 filedata
->chains
= NULL
;
11061 filedata
->nbuckets
= 0;
11065 if (filedata
->dynamic_info_DT_GNU_HASH
)
11067 unsigned char nb
[16];
11068 bfd_vma i
, maxchain
= 0xffffffff, bitmaskwords
;
11069 bfd_vma buckets_vma
;
11072 if (fseek (filedata
->handle
,
11073 (filedata
->archive_file_offset
11074 + offset_from_vma (filedata
,
11075 filedata
->dynamic_info_DT_GNU_HASH
,
11079 error (_("Unable to seek to start of dynamic information\n"));
11083 if (fread (nb
, 16, 1, filedata
->handle
) != 1)
11085 error (_("Failed to read in number of buckets\n"));
11089 filedata
->ngnubuckets
= byte_get (nb
, 4);
11090 filedata
->gnusymidx
= byte_get (nb
+ 4, 4);
11091 bitmaskwords
= byte_get (nb
+ 8, 4);
11092 buckets_vma
= filedata
->dynamic_info_DT_GNU_HASH
+ 16;
11094 buckets_vma
+= bitmaskwords
* 4;
11096 buckets_vma
+= bitmaskwords
* 8;
11098 if (fseek (filedata
->handle
,
11099 (filedata
->archive_file_offset
11100 + offset_from_vma (filedata
, buckets_vma
, 4)),
11103 error (_("Unable to seek to start of dynamic information\n"));
11107 filedata
->gnubuckets
11108 = get_dynamic_data (filedata
, filedata
->ngnubuckets
, 4);
11110 if (filedata
->gnubuckets
== NULL
)
11113 for (i
= 0; i
< filedata
->ngnubuckets
; i
++)
11114 if (filedata
->gnubuckets
[i
] != 0)
11116 if (filedata
->gnubuckets
[i
] < filedata
->gnusymidx
)
11119 if (maxchain
== 0xffffffff || filedata
->gnubuckets
[i
] > maxchain
)
11120 maxchain
= filedata
->gnubuckets
[i
];
11123 if (maxchain
== 0xffffffff)
11126 maxchain
-= filedata
->gnusymidx
;
11128 if (fseek (filedata
->handle
,
11129 (filedata
->archive_file_offset
11130 + offset_from_vma (filedata
,
11131 buckets_vma
+ 4 * (filedata
->ngnubuckets
11136 error (_("Unable to seek to start of dynamic information\n"));
11142 if (fread (nb
, 4, 1, filedata
->handle
) != 1)
11144 error (_("Failed to determine last chain length\n"));
11148 if (maxchain
+ 1 == 0)
11153 while ((byte_get (nb
, 4) & 1) == 0);
11155 if (fseek (filedata
->handle
,
11156 (filedata
->archive_file_offset
11157 + offset_from_vma (filedata
, (buckets_vma
11158 + 4 * filedata
->ngnubuckets
),
11162 error (_("Unable to seek to start of dynamic information\n"));
11166 filedata
->gnuchains
= get_dynamic_data (filedata
, maxchain
, 4);
11167 filedata
->ngnuchains
= maxchain
;
11169 if (filedata
->gnuchains
== NULL
)
11172 if (filedata
->dynamic_info_DT_MIPS_XHASH
)
11174 if (fseek (filedata
->handle
,
11175 (filedata
->archive_file_offset
11176 + offset_from_vma (filedata
, (buckets_vma
11177 + 4 * (filedata
->ngnubuckets
11181 error (_("Unable to seek to start of dynamic information\n"));
11185 filedata
->mipsxlat
= get_dynamic_data (filedata
, maxchain
, 4);
11186 if (filedata
->mipsxlat
== NULL
)
11190 for (hn
= 0; hn
< filedata
->ngnubuckets
; ++hn
)
11191 if (filedata
->gnubuckets
[hn
] != 0)
11193 bfd_vma si
= filedata
->gnubuckets
[hn
];
11194 bfd_vma off
= si
- filedata
->gnusymidx
;
11198 if (filedata
->dynamic_info_DT_MIPS_XHASH
)
11200 if (off
< filedata
->ngnuchains
11201 && filedata
->mipsxlat
[off
] >= num_of_syms
)
11202 num_of_syms
= filedata
->mipsxlat
[off
] + 1;
11206 if (si
>= num_of_syms
)
11207 num_of_syms
= si
+ 1;
11211 while (off
< filedata
->ngnuchains
11212 && (filedata
->gnuchains
[off
++] & 1) == 0);
11215 if (num_of_syms
== 0)
11218 free (filedata
->mipsxlat
);
11219 filedata
->mipsxlat
= NULL
;
11220 free (filedata
->gnuchains
);
11221 filedata
->gnuchains
= NULL
;
11222 free (filedata
->gnubuckets
);
11223 filedata
->gnubuckets
= NULL
;
11224 filedata
->ngnubuckets
= 0;
11225 filedata
->ngnuchains
= 0;
11229 return num_of_syms
;
11232 /* Parse and display the contents of the dynamic section. */
11235 process_dynamic_section (Filedata
* filedata
)
11237 Elf_Internal_Dyn
* entry
;
11239 if (filedata
->dynamic_size
<= 1)
11243 if (filedata
->is_separate
)
11244 printf (_("\nThere is no dynamic section in linked file '%s'.\n"),
11245 filedata
->file_name
);
11247 printf (_("\nThere is no dynamic section in this file.\n"));
11253 if (!get_dynamic_section (filedata
))
11256 /* Find the appropriate symbol table. */
11257 if (filedata
->dynamic_symbols
== NULL
|| do_histogram
)
11259 unsigned long num_of_syms
;
11261 for (entry
= filedata
->dynamic_section
;
11262 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
11264 if (entry
->d_tag
== DT_SYMTAB
)
11265 filedata
->dynamic_info
[DT_SYMTAB
] = entry
->d_un
.d_val
;
11266 else if (entry
->d_tag
== DT_SYMENT
)
11267 filedata
->dynamic_info
[DT_SYMENT
] = entry
->d_un
.d_val
;
11268 else if (entry
->d_tag
== DT_HASH
)
11269 filedata
->dynamic_info
[DT_HASH
] = entry
->d_un
.d_val
;
11270 else if (entry
->d_tag
== DT_GNU_HASH
)
11271 filedata
->dynamic_info_DT_GNU_HASH
= entry
->d_un
.d_val
;
11272 else if ((filedata
->file_header
.e_machine
== EM_MIPS
11273 || filedata
->file_header
.e_machine
== EM_MIPS_RS3_LE
)
11274 && entry
->d_tag
== DT_MIPS_XHASH
)
11276 filedata
->dynamic_info_DT_MIPS_XHASH
= entry
->d_un
.d_val
;
11277 filedata
->dynamic_info_DT_GNU_HASH
= entry
->d_un
.d_val
;
11280 num_of_syms
= get_num_dynamic_syms (filedata
);
11282 if (num_of_syms
!= 0
11283 && filedata
->dynamic_symbols
== NULL
11284 && filedata
->dynamic_info
[DT_SYMTAB
]
11285 && filedata
->dynamic_info
[DT_SYMENT
])
11287 Elf_Internal_Phdr
*seg
;
11288 bfd_vma vma
= filedata
->dynamic_info
[DT_SYMTAB
];
11290 if (! get_program_headers (filedata
))
11292 error (_("Cannot interpret virtual addresses "
11293 "without program headers.\n"));
11297 for (seg
= filedata
->program_headers
;
11298 seg
< filedata
->program_headers
+ filedata
->file_header
.e_phnum
;
11301 if (seg
->p_type
!= PT_LOAD
)
11304 if (seg
->p_offset
+ seg
->p_filesz
> filedata
->file_size
)
11306 /* See PR 21379 for a reproducer. */
11307 error (_("Invalid PT_LOAD entry\n"));
11311 if (vma
>= (seg
->p_vaddr
& -seg
->p_align
)
11312 && vma
< seg
->p_vaddr
+ seg
->p_filesz
)
11314 /* Since we do not know how big the symbol table is,
11315 we default to reading in up to the end of PT_LOAD
11316 segment and processing that. This is overkill, I
11317 know, but it should work. */
11318 Elf_Internal_Shdr section
;
11319 section
.sh_offset
= (vma
- seg
->p_vaddr
11321 section
.sh_size
= (num_of_syms
11322 * filedata
->dynamic_info
[DT_SYMENT
]);
11323 section
.sh_entsize
= filedata
->dynamic_info
[DT_SYMENT
];
11326 && filedata
->dynamic_symtab_section
!= NULL
11327 && ((filedata
->dynamic_symtab_section
->sh_offset
11328 != section
.sh_offset
)
11329 || (filedata
->dynamic_symtab_section
->sh_size
11330 != section
.sh_size
)
11331 || (filedata
->dynamic_symtab_section
->sh_entsize
11332 != section
.sh_entsize
)))
11334 the .dynsym section doesn't match the DT_SYMTAB and DT_SYMENT tags\n"));
11336 section
.sh_name
= filedata
->string_table_length
;
11337 filedata
->dynamic_symbols
11338 = get_elf_symbols (filedata
, §ion
,
11339 &filedata
->num_dynamic_syms
);
11340 if (filedata
->dynamic_symbols
== NULL
11341 || filedata
->num_dynamic_syms
!= num_of_syms
)
11343 error (_("Corrupt DT_SYMTAB dynamic entry\n"));
11352 /* Similarly find a string table. */
11353 if (filedata
->dynamic_strings
== NULL
)
11354 for (entry
= filedata
->dynamic_section
;
11355 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
11358 if (entry
->d_tag
== DT_STRTAB
)
11359 filedata
->dynamic_info
[DT_STRTAB
] = entry
->d_un
.d_val
;
11361 if (entry
->d_tag
== DT_STRSZ
)
11362 filedata
->dynamic_info
[DT_STRSZ
] = entry
->d_un
.d_val
;
11364 if (filedata
->dynamic_info
[DT_STRTAB
]
11365 && filedata
->dynamic_info
[DT_STRSZ
])
11367 unsigned long offset
;
11368 bfd_size_type str_tab_len
= filedata
->dynamic_info
[DT_STRSZ
];
11370 offset
= offset_from_vma (filedata
,
11371 filedata
->dynamic_info
[DT_STRTAB
],
11374 && filedata
->dynamic_strtab_section
11375 && ((filedata
->dynamic_strtab_section
->sh_offset
11376 != (file_ptr
) offset
)
11377 || (filedata
->dynamic_strtab_section
->sh_size
11380 the .dynstr section doesn't match the DT_STRTAB and DT_STRSZ tags\n"));
11382 filedata
->dynamic_strings
11383 = (char *) get_data (NULL
, filedata
, offset
, 1, str_tab_len
,
11384 _("dynamic string table"));
11385 if (filedata
->dynamic_strings
== NULL
)
11387 error (_("Corrupt DT_STRTAB dynamic entry\n"));
11391 filedata
->dynamic_strings_length
= str_tab_len
;
11396 /* And find the syminfo section if available. */
11397 if (filedata
->dynamic_syminfo
== NULL
)
11399 unsigned long syminsz
= 0;
11401 for (entry
= filedata
->dynamic_section
;
11402 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
11405 if (entry
->d_tag
== DT_SYMINENT
)
11407 /* Note: these braces are necessary to avoid a syntax
11408 error from the SunOS4 C compiler. */
11409 /* PR binutils/17531: A corrupt file can trigger this test.
11410 So do not use an assert, instead generate an error message. */
11411 if (sizeof (Elf_External_Syminfo
) != entry
->d_un
.d_val
)
11412 error (_("Bad value (%d) for SYMINENT entry\n"),
11413 (int) entry
->d_un
.d_val
);
11415 else if (entry
->d_tag
== DT_SYMINSZ
)
11416 syminsz
= entry
->d_un
.d_val
;
11417 else if (entry
->d_tag
== DT_SYMINFO
)
11418 filedata
->dynamic_syminfo_offset
11419 = offset_from_vma (filedata
, entry
->d_un
.d_val
, syminsz
);
11422 if (filedata
->dynamic_syminfo_offset
!= 0 && syminsz
!= 0)
11424 Elf_External_Syminfo
* extsyminfo
;
11425 Elf_External_Syminfo
* extsym
;
11426 Elf_Internal_Syminfo
* syminfo
;
11428 /* There is a syminfo section. Read the data. */
11429 extsyminfo
= (Elf_External_Syminfo
*)
11430 get_data (NULL
, filedata
, filedata
->dynamic_syminfo_offset
,
11431 1, syminsz
, _("symbol information"));
11435 if (filedata
->dynamic_syminfo
!= NULL
)
11437 error (_("Multiple dynamic symbol information sections found\n"));
11438 free (filedata
->dynamic_syminfo
);
11440 filedata
->dynamic_syminfo
= (Elf_Internal_Syminfo
*) malloc (syminsz
);
11441 if (filedata
->dynamic_syminfo
== NULL
)
11443 error (_("Out of memory allocating %lu bytes "
11444 "for dynamic symbol info\n"),
11445 (unsigned long) syminsz
);
11449 filedata
->dynamic_syminfo_nent
11450 = syminsz
/ sizeof (Elf_External_Syminfo
);
11451 for (syminfo
= filedata
->dynamic_syminfo
, extsym
= extsyminfo
;
11452 syminfo
< (filedata
->dynamic_syminfo
11453 + filedata
->dynamic_syminfo_nent
);
11454 ++syminfo
, ++extsym
)
11456 syminfo
->si_boundto
= BYTE_GET (extsym
->si_boundto
);
11457 syminfo
->si_flags
= BYTE_GET (extsym
->si_flags
);
11464 if (do_dynamic
&& filedata
->dynamic_addr
)
11466 if (filedata
->is_separate
)
11467 printf (ngettext ("\nIn linked file '%s' the dynamic section at offset 0x%lx contains %lu entry:\n",
11468 "\nIn linked file '%s' the dynamic section at offset 0x%lx contains %lu entries:\n",
11469 (unsigned long) filedata
->dynamic_nent
),
11470 filedata
->file_name
,
11471 filedata
->dynamic_addr
,
11472 (unsigned long) filedata
->dynamic_nent
);
11474 printf (ngettext ("\nDynamic section at offset 0x%lx contains %lu entry:\n",
11475 "\nDynamic section at offset 0x%lx contains %lu entries:\n",
11476 (unsigned long) filedata
->dynamic_nent
),
11477 filedata
->dynamic_addr
,
11478 (unsigned long) filedata
->dynamic_nent
);
11481 printf (_(" Tag Type Name/Value\n"));
11483 for (entry
= filedata
->dynamic_section
;
11484 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
11489 const char * dtype
;
11492 print_vma (entry
->d_tag
, FULL_HEX
);
11493 dtype
= get_dynamic_type (filedata
, entry
->d_tag
);
11494 printf (" (%s)%*s", dtype
,
11495 ((is_32bit_elf
? 27 : 19) - (int) strlen (dtype
)), " ");
11498 switch (entry
->d_tag
)
11502 print_dynamic_flags (entry
->d_un
.d_val
);
11512 switch (entry
->d_tag
)
11515 printf (_("Auxiliary library"));
11519 printf (_("Filter library"));
11523 printf (_("Configuration file"));
11527 printf (_("Dependency audit library"));
11531 printf (_("Audit library"));
11535 if (valid_dynamic_name (filedata
, entry
->d_un
.d_val
))
11536 printf (": [%s]\n",
11537 get_dynamic_name (filedata
, entry
->d_un
.d_val
));
11541 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
11550 printf (_("Flags:"));
11552 if (entry
->d_un
.d_val
== 0)
11553 printf (_(" None\n"));
11556 unsigned long int val
= entry
->d_un
.d_val
;
11558 if (val
& DTF_1_PARINIT
)
11560 printf (" PARINIT");
11561 val
^= DTF_1_PARINIT
;
11563 if (val
& DTF_1_CONFEXP
)
11565 printf (" CONFEXP");
11566 val
^= DTF_1_CONFEXP
;
11569 printf (" %lx", val
);
11578 printf (_("Flags:"));
11580 if (entry
->d_un
.d_val
== 0)
11581 printf (_(" None\n"));
11584 unsigned long int val
= entry
->d_un
.d_val
;
11586 if (val
& DF_P1_LAZYLOAD
)
11588 printf (" LAZYLOAD");
11589 val
^= DF_P1_LAZYLOAD
;
11591 if (val
& DF_P1_GROUPPERM
)
11593 printf (" GROUPPERM");
11594 val
^= DF_P1_GROUPPERM
;
11597 printf (" %lx", val
);
11606 printf (_("Flags:"));
11607 if (entry
->d_un
.d_val
== 0)
11608 printf (_(" None\n"));
11611 unsigned long int val
= entry
->d_un
.d_val
;
11613 if (val
& DF_1_NOW
)
11618 if (val
& DF_1_GLOBAL
)
11620 printf (" GLOBAL");
11621 val
^= DF_1_GLOBAL
;
11623 if (val
& DF_1_GROUP
)
11628 if (val
& DF_1_NODELETE
)
11630 printf (" NODELETE");
11631 val
^= DF_1_NODELETE
;
11633 if (val
& DF_1_LOADFLTR
)
11635 printf (" LOADFLTR");
11636 val
^= DF_1_LOADFLTR
;
11638 if (val
& DF_1_INITFIRST
)
11640 printf (" INITFIRST");
11641 val
^= DF_1_INITFIRST
;
11643 if (val
& DF_1_NOOPEN
)
11645 printf (" NOOPEN");
11646 val
^= DF_1_NOOPEN
;
11648 if (val
& DF_1_ORIGIN
)
11650 printf (" ORIGIN");
11651 val
^= DF_1_ORIGIN
;
11653 if (val
& DF_1_DIRECT
)
11655 printf (" DIRECT");
11656 val
^= DF_1_DIRECT
;
11658 if (val
& DF_1_TRANS
)
11663 if (val
& DF_1_INTERPOSE
)
11665 printf (" INTERPOSE");
11666 val
^= DF_1_INTERPOSE
;
11668 if (val
& DF_1_NODEFLIB
)
11670 printf (" NODEFLIB");
11671 val
^= DF_1_NODEFLIB
;
11673 if (val
& DF_1_NODUMP
)
11675 printf (" NODUMP");
11676 val
^= DF_1_NODUMP
;
11678 if (val
& DF_1_CONFALT
)
11680 printf (" CONFALT");
11681 val
^= DF_1_CONFALT
;
11683 if (val
& DF_1_ENDFILTEE
)
11685 printf (" ENDFILTEE");
11686 val
^= DF_1_ENDFILTEE
;
11688 if (val
& DF_1_DISPRELDNE
)
11690 printf (" DISPRELDNE");
11691 val
^= DF_1_DISPRELDNE
;
11693 if (val
& DF_1_DISPRELPND
)
11695 printf (" DISPRELPND");
11696 val
^= DF_1_DISPRELPND
;
11698 if (val
& DF_1_NODIRECT
)
11700 printf (" NODIRECT");
11701 val
^= DF_1_NODIRECT
;
11703 if (val
& DF_1_IGNMULDEF
)
11705 printf (" IGNMULDEF");
11706 val
^= DF_1_IGNMULDEF
;
11708 if (val
& DF_1_NOKSYMS
)
11710 printf (" NOKSYMS");
11711 val
^= DF_1_NOKSYMS
;
11713 if (val
& DF_1_NOHDR
)
11718 if (val
& DF_1_EDITED
)
11720 printf (" EDITED");
11721 val
^= DF_1_EDITED
;
11723 if (val
& DF_1_NORELOC
)
11725 printf (" NORELOC");
11726 val
^= DF_1_NORELOC
;
11728 if (val
& DF_1_SYMINTPOSE
)
11730 printf (" SYMINTPOSE");
11731 val
^= DF_1_SYMINTPOSE
;
11733 if (val
& DF_1_GLOBAUDIT
)
11735 printf (" GLOBAUDIT");
11736 val
^= DF_1_GLOBAUDIT
;
11738 if (val
& DF_1_SINGLETON
)
11740 printf (" SINGLETON");
11741 val
^= DF_1_SINGLETON
;
11743 if (val
& DF_1_STUB
)
11748 if (val
& DF_1_PIE
)
11753 if (val
& DF_1_KMOD
)
11758 if (val
& DF_1_WEAKFILTER
)
11760 printf (" WEAKFILTER");
11761 val
^= DF_1_WEAKFILTER
;
11763 if (val
& DF_1_NOCOMMON
)
11765 printf (" NOCOMMON");
11766 val
^= DF_1_NOCOMMON
;
11769 printf (" %lx", val
);
11776 filedata
->dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
11778 puts (get_dynamic_type (filedata
, entry
->d_un
.d_val
));
11799 filedata
->dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
11805 if (valid_dynamic_name (filedata
, entry
->d_un
.d_val
))
11806 name
= get_dynamic_name (filedata
, entry
->d_un
.d_val
);
11812 switch (entry
->d_tag
)
11815 printf (_("Shared library: [%s]"), name
);
11817 if (filedata
->program_interpreter
11818 && streq (name
, filedata
->program_interpreter
))
11819 printf (_(" program interpreter"));
11823 printf (_("Library soname: [%s]"), name
);
11827 printf (_("Library rpath: [%s]"), name
);
11831 printf (_("Library runpath: [%s]"), name
);
11835 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
11840 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
11855 filedata
->dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
11856 /* Fall through. */
11860 case DT_PREINIT_ARRAYSZ
:
11861 case DT_INIT_ARRAYSZ
:
11862 case DT_FINI_ARRAYSZ
:
11863 case DT_GNU_CONFLICTSZ
:
11864 case DT_GNU_LIBLISTSZ
:
11867 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
11868 printf (_(" (bytes)\n"));
11873 case DT_VERNEEDNUM
:
11878 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
11887 case DT_INIT_ARRAY
:
11888 case DT_FINI_ARRAY
:
11891 if (entry
->d_tag
== DT_USED
11892 && valid_dynamic_name (filedata
, entry
->d_un
.d_val
))
11895 = get_dynamic_name (filedata
, entry
->d_un
.d_val
);
11899 printf (_("Not needed object: [%s]\n"), name
);
11904 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
11910 /* The value of this entry is ignored. */
11915 case DT_GNU_PRELINKED
:
11919 time_t atime
= entry
->d_un
.d_val
;
11921 tmp
= gmtime (&atime
);
11922 /* PR 17533 file: 041-1244816-0.004. */
11924 printf (_("<corrupt time val: %lx"),
11925 (unsigned long) atime
);
11927 printf ("%04u-%02u-%02uT%02u:%02u:%02u\n",
11928 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
11929 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
11935 filedata
->dynamic_info_DT_GNU_HASH
= entry
->d_un
.d_val
;
11938 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
11943 case DT_GNU_FLAGS_1
:
11946 printf (_("Flags:"));
11947 if (entry
->d_un
.d_val
== 0)
11948 printf (_(" None\n"));
11951 unsigned long int val
= entry
->d_un
.d_val
;
11953 if (val
& DF_GNU_1_UNIQUE
)
11955 printf (" UNIQUE");
11956 val
^= DF_GNU_1_UNIQUE
;
11959 printf (" %lx", val
);
11966 if ((entry
->d_tag
>= DT_VERSYM
) && (entry
->d_tag
<= DT_VERNEEDNUM
))
11967 filedata
->version_info
[DT_VERSIONTAGIDX (entry
->d_tag
)]
11968 = entry
->d_un
.d_val
;
11972 switch (filedata
->file_header
.e_machine
)
11975 dynamic_section_aarch64_val (entry
);
11978 case EM_MIPS_RS3_LE
:
11979 dynamic_section_mips_val (filedata
, entry
);
11982 dynamic_section_parisc_val (entry
);
11985 dynamic_section_ia64_val (entry
);
11988 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
12000 get_ver_flags (unsigned int flags
)
12002 static char buff
[128];
12009 if (flags
& VER_FLG_BASE
)
12010 strcat (buff
, "BASE");
12012 if (flags
& VER_FLG_WEAK
)
12014 if (flags
& VER_FLG_BASE
)
12015 strcat (buff
, " | ");
12017 strcat (buff
, "WEAK");
12020 if (flags
& VER_FLG_INFO
)
12022 if (flags
& (VER_FLG_BASE
|VER_FLG_WEAK
))
12023 strcat (buff
, " | ");
12025 strcat (buff
, "INFO");
12028 if (flags
& ~(VER_FLG_BASE
| VER_FLG_WEAK
| VER_FLG_INFO
))
12030 if (flags
& (VER_FLG_BASE
| VER_FLG_WEAK
| VER_FLG_INFO
))
12031 strcat (buff
, " | ");
12033 strcat (buff
, _("<unknown>"));
12039 /* Display the contents of the version sections. */
12042 process_version_sections (Filedata
* filedata
)
12044 Elf_Internal_Shdr
* section
;
12046 bool found
= false;
12051 for (i
= 0, section
= filedata
->section_headers
;
12052 i
< filedata
->file_header
.e_shnum
;
12055 switch (section
->sh_type
)
12057 case SHT_GNU_verdef
:
12059 Elf_External_Verdef
* edefs
;
12066 if (filedata
->is_separate
)
12067 printf (ngettext ("\nIn linked file '%s' the version definition section '%s' contains %u entry:\n",
12068 "\nIn linked file '%s' the version definition section '%s' contains %u entries:\n",
12070 filedata
->file_name
,
12071 printable_section_name (filedata
, section
),
12074 printf (ngettext ("\nVersion definition section '%s' "
12075 "contains %u entry:\n",
12076 "\nVersion definition section '%s' "
12077 "contains %u entries:\n",
12079 printable_section_name (filedata
, section
),
12082 printf (_(" Addr: 0x%016" PRIx64
), (uint64_t) section
->sh_addr
);
12083 printf (_(" Offset: %#08lx Link: %u (%s)\n"),
12084 (unsigned long) section
->sh_offset
, section
->sh_link
,
12085 printable_section_name_from_index (filedata
, section
->sh_link
));
12087 edefs
= (Elf_External_Verdef
*)
12088 get_data (NULL
, filedata
, section
->sh_offset
, 1,section
->sh_size
,
12089 _("version definition section"));
12092 endbuf
= (char *) edefs
+ section
->sh_size
;
12094 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
12097 Elf_External_Verdef
* edef
;
12098 Elf_Internal_Verdef ent
;
12099 Elf_External_Verdaux
* eaux
;
12100 Elf_Internal_Verdaux aux
;
12101 unsigned long isum
;
12104 vstart
= ((char *) edefs
) + idx
;
12105 if (vstart
+ sizeof (*edef
) > endbuf
)
12108 edef
= (Elf_External_Verdef
*) vstart
;
12110 ent
.vd_version
= BYTE_GET (edef
->vd_version
);
12111 ent
.vd_flags
= BYTE_GET (edef
->vd_flags
);
12112 ent
.vd_ndx
= BYTE_GET (edef
->vd_ndx
);
12113 ent
.vd_cnt
= BYTE_GET (edef
->vd_cnt
);
12114 ent
.vd_hash
= BYTE_GET (edef
->vd_hash
);
12115 ent
.vd_aux
= BYTE_GET (edef
->vd_aux
);
12116 ent
.vd_next
= BYTE_GET (edef
->vd_next
);
12118 printf (_(" %#06lx: Rev: %d Flags: %s"),
12119 idx
, ent
.vd_version
, get_ver_flags (ent
.vd_flags
));
12121 printf (_(" Index: %d Cnt: %d "),
12122 ent
.vd_ndx
, ent
.vd_cnt
);
12124 /* Check for overflow. */
12125 if (ent
.vd_aux
> (size_t) (endbuf
- vstart
))
12128 vstart
+= ent
.vd_aux
;
12130 if (vstart
+ sizeof (*eaux
) > endbuf
)
12132 eaux
= (Elf_External_Verdaux
*) vstart
;
12134 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
12135 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
12137 if (valid_dynamic_name (filedata
, aux
.vda_name
))
12138 printf (_("Name: %s\n"),
12139 get_dynamic_name (filedata
, aux
.vda_name
));
12141 printf (_("Name index: %ld\n"), aux
.vda_name
);
12143 isum
= idx
+ ent
.vd_aux
;
12145 for (j
= 1; j
< ent
.vd_cnt
; j
++)
12147 if (aux
.vda_next
< sizeof (*eaux
)
12148 && !(j
== ent
.vd_cnt
- 1 && aux
.vda_next
== 0))
12150 warn (_("Invalid vda_next field of %lx\n"),
12155 /* Check for overflow. */
12156 if (aux
.vda_next
> (size_t) (endbuf
- vstart
))
12159 isum
+= aux
.vda_next
;
12160 vstart
+= aux
.vda_next
;
12162 if (vstart
+ sizeof (*eaux
) > endbuf
)
12164 eaux
= (Elf_External_Verdaux
*) vstart
;
12166 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
12167 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
12169 if (valid_dynamic_name (filedata
, aux
.vda_name
))
12170 printf (_(" %#06lx: Parent %d: %s\n"),
12172 get_dynamic_name (filedata
, aux
.vda_name
));
12174 printf (_(" %#06lx: Parent %d, name index: %ld\n"),
12175 isum
, j
, aux
.vda_name
);
12178 if (j
< ent
.vd_cnt
)
12179 printf (_(" Version def aux past end of section\n"));
12182 file: id:000001,src:000172+005151,op:splice,rep:2. */
12183 if (ent
.vd_next
< sizeof (*edef
)
12184 && !(cnt
== section
->sh_info
- 1 && ent
.vd_next
== 0))
12186 warn (_("Invalid vd_next field of %lx\n"), ent
.vd_next
);
12187 cnt
= section
->sh_info
;
12190 if (ent
.vd_next
> (size_t) (endbuf
- ((char *) edefs
+ idx
)))
12193 idx
+= ent
.vd_next
;
12196 if (cnt
< section
->sh_info
)
12197 printf (_(" Version definition past end of section\n"));
12203 case SHT_GNU_verneed
:
12205 Elf_External_Verneed
* eneed
;
12212 if (filedata
->is_separate
)
12213 printf (ngettext ("\nIn linked file '%s' the version needs section '%s' contains %u entry:\n",
12214 "\nIn linked file '%s' the version needs section '%s' contains %u entries:\n",
12216 filedata
->file_name
,
12217 printable_section_name (filedata
, section
),
12220 printf (ngettext ("\nVersion needs section '%s' "
12221 "contains %u entry:\n",
12222 "\nVersion needs section '%s' "
12223 "contains %u entries:\n",
12225 printable_section_name (filedata
, section
),
12228 printf (_(" Addr: 0x%016" PRIx64
), (uint64_t) 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%016" PRIx64
), (uint64_t) section
->sh_addr
);
12394 printf (_(" Offset: %#08lx Link: %u (%s)\n"),
12395 (unsigned long) section
->sh_offset
, section
->sh_link
,
12396 printable_section_name (filedata
, link_section
));
12398 off
= offset_from_vma (filedata
,
12399 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)],
12400 total
* sizeof (short));
12401 edata
= (unsigned char *) get_data (NULL
, filedata
, off
,
12402 sizeof (short), total
,
12403 _("version symbol data"));
12411 data
= (short unsigned int *) cmalloc (total
, sizeof (short));
12413 for (cnt
= total
; cnt
--;)
12414 data
[cnt
] = byte_get (edata
+ cnt
* sizeof (short),
12419 for (cnt
= 0; cnt
< total
; cnt
+= 4)
12423 char *invalid
= _("*invalid*");
12425 printf (" %03x:", cnt
);
12427 for (j
= 0; (j
< 4) && (cnt
+ j
) < total
; ++j
)
12428 switch (data
[cnt
+ j
])
12431 fputs (_(" 0 (*local*) "), stdout
);
12435 fputs (_(" 1 (*global*) "), stdout
);
12439 nn
= printf ("%4x%c", data
[cnt
+ j
] & VERSYM_VERSION
,
12440 data
[cnt
+ j
] & VERSYM_HIDDEN
? 'h' : ' ');
12442 /* If this index value is greater than the size of the symbols
12443 array, break to avoid an out-of-bounds read. */
12444 if ((unsigned long)(cnt
+ j
) >= num_syms
)
12446 warn (_("invalid index into symbol array\n"));
12451 if (filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)])
12453 Elf_Internal_Verneed ivn
;
12454 unsigned long offset
;
12456 offset
= offset_from_vma
12458 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)],
12459 sizeof (Elf_External_Verneed
));
12463 Elf_Internal_Vernaux ivna
;
12464 Elf_External_Verneed evn
;
12465 Elf_External_Vernaux evna
;
12466 unsigned long a_off
;
12468 if (get_data (&evn
, filedata
, offset
, sizeof (evn
), 1,
12469 _("version need")) == NULL
)
12472 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
12473 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
12475 a_off
= offset
+ ivn
.vn_aux
;
12479 if (get_data (&evna
, filedata
, a_off
, sizeof (evna
),
12480 1, _("version need aux (2)")) == NULL
)
12483 ivna
.vna_other
= 0;
12487 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
12488 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
12491 a_off
+= ivna
.vna_next
;
12493 while (ivna
.vna_other
!= data
[cnt
+ j
]
12494 && ivna
.vna_next
!= 0);
12496 if (ivna
.vna_other
== data
[cnt
+ j
])
12498 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
12500 if (ivna
.vna_name
>= string_sec
->sh_size
)
12503 name
= strtab
+ ivna
.vna_name
;
12507 offset
+= ivn
.vn_next
;
12509 while (ivn
.vn_next
);
12512 if (data
[cnt
+ j
] != 0x8001
12513 && filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
12515 Elf_Internal_Verdef ivd
;
12516 Elf_External_Verdef evd
;
12517 unsigned long offset
;
12519 offset
= offset_from_vma
12521 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)],
12526 if (get_data (&evd
, filedata
, offset
, sizeof (evd
), 1,
12527 _("version def")) == NULL
)
12530 /* PR 17531: file: 046-1082287-0.004. */
12531 ivd
.vd_ndx
= (data
[cnt
+ j
] & VERSYM_VERSION
) + 1;
12536 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
12537 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
12540 offset
+= ivd
.vd_next
;
12542 while (ivd
.vd_ndx
!= (data
[cnt
+ j
] & VERSYM_VERSION
)
12543 && ivd
.vd_next
!= 0);
12545 if (ivd
.vd_ndx
== (data
[cnt
+ j
] & VERSYM_VERSION
))
12547 Elf_External_Verdaux evda
;
12548 Elf_Internal_Verdaux ivda
;
12550 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
12552 if (get_data (&evda
, filedata
,
12553 offset
- ivd
.vd_next
+ ivd
.vd_aux
,
12555 _("version def aux")) == NULL
)
12558 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
12560 if (ivda
.vda_name
>= string_sec
->sh_size
)
12562 else if (name
!= NULL
&& name
!= invalid
)
12563 name
= _("*both*");
12565 name
= strtab
+ ivda
.vda_name
;
12569 nn
+= printf ("(%s%-*s",
12571 12 - (int) strlen (name
),
12575 printf ("%*c", 18 - nn
, ' ');
12594 if (filedata
->is_separate
)
12595 printf (_("\nNo version information found in linked file '%s'.\n"),
12596 filedata
->file_name
);
12598 printf (_("\nNo version information found in this file.\n"));
12604 static const char *
12605 get_symbol_binding (Filedata
* filedata
, unsigned int binding
)
12607 static char buff
[64];
12611 case STB_LOCAL
: return "LOCAL";
12612 case STB_GLOBAL
: return "GLOBAL";
12613 case STB_WEAK
: return "WEAK";
12615 if (binding
>= STB_LOPROC
&& binding
<= STB_HIPROC
)
12616 snprintf (buff
, sizeof (buff
), _("<processor specific>: %d"),
12618 else if (binding
>= STB_LOOS
&& binding
<= STB_HIOS
)
12620 if (binding
== STB_GNU_UNIQUE
12621 && filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_GNU
)
12623 snprintf (buff
, sizeof (buff
), _("<OS specific>: %d"), binding
);
12626 snprintf (buff
, sizeof (buff
), _("<unknown>: %d"), binding
);
12631 static const char *
12632 get_symbol_type (Filedata
* filedata
, unsigned int type
)
12634 static char buff
[64];
12638 case STT_NOTYPE
: return "NOTYPE";
12639 case STT_OBJECT
: return "OBJECT";
12640 case STT_FUNC
: return "FUNC";
12641 case STT_SECTION
: return "SECTION";
12642 case STT_FILE
: return "FILE";
12643 case STT_COMMON
: return "COMMON";
12644 case STT_TLS
: return "TLS";
12645 case STT_RELC
: return "RELC";
12646 case STT_SRELC
: return "SRELC";
12648 if (type
>= STT_LOPROC
&& type
<= STT_HIPROC
)
12650 if (filedata
->file_header
.e_machine
== EM_ARM
&& type
== STT_ARM_TFUNC
)
12651 return "THUMB_FUNC";
12653 if (filedata
->file_header
.e_machine
== EM_SPARCV9
&& type
== STT_REGISTER
)
12656 if (filedata
->file_header
.e_machine
== EM_PARISC
&& type
== STT_PARISC_MILLI
)
12657 return "PARISC_MILLI";
12659 snprintf (buff
, sizeof (buff
), _("<processor specific>: %d"), type
);
12661 else if (type
>= STT_LOOS
&& type
<= STT_HIOS
)
12663 if (filedata
->file_header
.e_machine
== EM_PARISC
)
12665 if (type
== STT_HP_OPAQUE
)
12666 return "HP_OPAQUE";
12667 if (type
== STT_HP_STUB
)
12671 if (type
== STT_GNU_IFUNC
12672 && (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_GNU
12673 || filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_FREEBSD
))
12676 snprintf (buff
, sizeof (buff
), _("<OS specific>: %d"), type
);
12679 snprintf (buff
, sizeof (buff
), _("<unknown>: %d"), type
);
12684 static const char *
12685 get_symbol_visibility (unsigned int visibility
)
12687 switch (visibility
)
12689 case STV_DEFAULT
: return "DEFAULT";
12690 case STV_INTERNAL
: return "INTERNAL";
12691 case STV_HIDDEN
: return "HIDDEN";
12692 case STV_PROTECTED
: return "PROTECTED";
12694 error (_("Unrecognized visibility value: %u\n"), visibility
);
12695 return _("<unknown>");
12699 static const char *
12700 get_alpha_symbol_other (unsigned int other
)
12704 case STO_ALPHA_NOPV
: return "NOPV";
12705 case STO_ALPHA_STD_GPLOAD
: return "STD GPLOAD";
12707 error (_("Unrecognized alpha specific other value: %u\n"), other
);
12708 return _("<unknown>");
12712 static const char *
12713 get_solaris_symbol_visibility (unsigned int visibility
)
12715 switch (visibility
)
12717 case 4: return "EXPORTED";
12718 case 5: return "SINGLETON";
12719 case 6: return "ELIMINATE";
12720 default: return get_symbol_visibility (visibility
);
12724 static const char *
12725 get_aarch64_symbol_other (unsigned int other
)
12727 static char buf
[32];
12729 if (other
& STO_AARCH64_VARIANT_PCS
)
12731 other
&= ~STO_AARCH64_VARIANT_PCS
;
12733 return "VARIANT_PCS";
12734 snprintf (buf
, sizeof buf
, "VARIANT_PCS | %x", other
);
12740 static const char *
12741 get_mips_symbol_other (unsigned int other
)
12745 case STO_OPTIONAL
: return "OPTIONAL";
12746 case STO_MIPS_PLT
: return "MIPS PLT";
12747 case STO_MIPS_PIC
: return "MIPS PIC";
12748 case STO_MICROMIPS
: return "MICROMIPS";
12749 case STO_MICROMIPS
| STO_MIPS_PIC
: return "MICROMIPS, MIPS PIC";
12750 case STO_MIPS16
: return "MIPS16";
12751 default: return NULL
;
12755 static const char *
12756 get_ia64_symbol_other (Filedata
* filedata
, unsigned int other
)
12758 if (is_ia64_vms (filedata
))
12760 static char res
[32];
12764 /* Function types is for images and .STB files only. */
12765 switch (filedata
->file_header
.e_type
)
12769 switch (VMS_ST_FUNC_TYPE (other
))
12771 case VMS_SFT_CODE_ADDR
:
12772 strcat (res
, " CA");
12774 case VMS_SFT_SYMV_IDX
:
12775 strcat (res
, " VEC");
12778 strcat (res
, " FD");
12780 case VMS_SFT_RESERVE
:
12781 strcat (res
, " RSV");
12784 warn (_("Unrecognized IA64 VMS ST Function type: %d\n"),
12785 VMS_ST_FUNC_TYPE (other
));
12786 strcat (res
, " <unknown>");
12793 switch (VMS_ST_LINKAGE (other
))
12795 case VMS_STL_IGNORE
:
12796 strcat (res
, " IGN");
12798 case VMS_STL_RESERVE
:
12799 strcat (res
, " RSV");
12802 strcat (res
, " STD");
12805 strcat (res
, " LNK");
12808 warn (_("Unrecognized IA64 VMS ST Linkage: %d\n"),
12809 VMS_ST_LINKAGE (other
));
12810 strcat (res
, " <unknown>");
12822 static const char *
12823 get_ppc64_symbol_other (unsigned int other
)
12825 if ((other
& ~STO_PPC64_LOCAL_MASK
) != 0)
12828 other
>>= STO_PPC64_LOCAL_BIT
;
12831 static char buf
[64];
12833 other
= ppc64_decode_local_entry (other
);
12834 snprintf (buf
, sizeof buf
, _("<localentry>: %d"), other
);
12840 static const char *
12841 get_riscv_symbol_other (unsigned int other
)
12843 static char buf
[32];
12846 if (other
& STO_RISCV_VARIANT_CC
)
12848 strcat (buf
, _(" VARIANT_CC"));
12849 other
&= ~STO_RISCV_VARIANT_CC
;
12853 snprintf (buf
, sizeof buf
, " %x", other
);
12862 static const char *
12863 get_symbol_other (Filedata
* filedata
, unsigned int other
)
12865 const char * result
= NULL
;
12866 static char buff
[64];
12871 switch (filedata
->file_header
.e_machine
)
12874 result
= get_alpha_symbol_other (other
);
12877 result
= get_aarch64_symbol_other (other
);
12880 result
= get_mips_symbol_other (other
);
12883 result
= get_ia64_symbol_other (filedata
, other
);
12886 result
= get_ppc64_symbol_other (other
);
12889 result
= get_riscv_symbol_other (other
);
12899 snprintf (buff
, sizeof buff
, _("<other>: %x"), other
);
12903 static const char *
12904 get_symbol_index_type (Filedata
* filedata
, unsigned int type
)
12906 static char buff
[32];
12910 case SHN_UNDEF
: return "UND";
12911 case SHN_ABS
: return "ABS";
12912 case SHN_COMMON
: return "COM";
12914 if (type
== SHN_IA_64_ANSI_COMMON
12915 && filedata
->file_header
.e_machine
== EM_IA_64
12916 && filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_HPUX
)
12918 else if ((filedata
->file_header
.e_machine
== EM_X86_64
12919 || filedata
->file_header
.e_machine
== EM_L1OM
12920 || filedata
->file_header
.e_machine
== EM_K1OM
)
12921 && type
== SHN_X86_64_LCOMMON
)
12922 return "LARGE_COM";
12923 else if ((type
== SHN_MIPS_SCOMMON
12924 && filedata
->file_header
.e_machine
== EM_MIPS
)
12925 || (type
== SHN_TIC6X_SCOMMON
12926 && filedata
->file_header
.e_machine
== EM_TI_C6000
))
12928 else if (type
== SHN_MIPS_SUNDEFINED
12929 && filedata
->file_header
.e_machine
== EM_MIPS
)
12931 else if (type
>= SHN_LOPROC
&& type
<= SHN_HIPROC
)
12932 sprintf (buff
, "PRC[0x%04x]", type
& 0xffff);
12933 else if (type
>= SHN_LOOS
&& type
<= SHN_HIOS
)
12934 sprintf (buff
, "OS [0x%04x]", type
& 0xffff);
12935 else if (type
>= SHN_LORESERVE
)
12936 sprintf (buff
, "RSV[0x%04x]", type
& 0xffff);
12937 else if (filedata
->file_header
.e_shnum
!= 0
12938 && type
>= filedata
->file_header
.e_shnum
)
12939 sprintf (buff
, _("bad section index[%3d]"), type
);
12941 sprintf (buff
, "%3d", type
);
12948 static const char *
12949 get_symbol_version_string (Filedata
* filedata
,
12951 const char * strtab
,
12952 unsigned long int strtab_size
,
12954 Elf_Internal_Sym
* psym
,
12955 enum versioned_symbol_info
* sym_info
,
12956 unsigned short * vna_other
)
12958 unsigned char data
[2];
12959 unsigned short vers_data
;
12960 unsigned long offset
;
12961 unsigned short max_vd_ndx
;
12964 || filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)] == 0)
12967 offset
= offset_from_vma (filedata
,
12968 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)],
12969 sizeof data
+ si
* sizeof (vers_data
));
12971 if (get_data (&data
, filedata
, offset
+ si
* sizeof (vers_data
),
12972 sizeof (data
), 1, _("version data")) == NULL
)
12975 vers_data
= byte_get (data
, 2);
12977 if ((vers_data
& VERSYM_HIDDEN
) == 0 && vers_data
== 0)
12980 *sym_info
= (vers_data
& VERSYM_HIDDEN
) != 0 ? symbol_hidden
: symbol_public
;
12983 /* Usually we'd only see verdef for defined symbols, and verneed for
12984 undefined symbols. However, symbols defined by the linker in
12985 .dynbss for variables copied from a shared library in order to
12986 avoid text relocations are defined yet have verneed. We could
12987 use a heuristic to detect the special case, for example, check
12988 for verneed first on symbols defined in SHT_NOBITS sections, but
12989 it is simpler and more reliable to just look for both verdef and
12990 verneed. .dynbss might not be mapped to a SHT_NOBITS section. */
12992 if (psym
->st_shndx
!= SHN_UNDEF
12993 && vers_data
!= 0x8001
12994 && filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
12996 Elf_Internal_Verdef ivd
;
12997 Elf_Internal_Verdaux ivda
;
12998 Elf_External_Verdaux evda
;
13001 off
= offset_from_vma (filedata
,
13002 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)],
13003 sizeof (Elf_External_Verdef
));
13007 Elf_External_Verdef evd
;
13009 if (get_data (&evd
, filedata
, off
, sizeof (evd
), 1,
13010 _("version def")) == NULL
)
13019 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
13020 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
13021 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
13022 ivd
.vd_flags
= BYTE_GET (evd
.vd_flags
);
13025 if ((ivd
.vd_ndx
& VERSYM_VERSION
) > max_vd_ndx
)
13026 max_vd_ndx
= ivd
.vd_ndx
& VERSYM_VERSION
;
13028 off
+= ivd
.vd_next
;
13030 while (ivd
.vd_ndx
!= (vers_data
& VERSYM_VERSION
) && ivd
.vd_next
!= 0);
13032 if (ivd
.vd_ndx
== (vers_data
& VERSYM_VERSION
))
13034 if (ivd
.vd_ndx
== 1 && ivd
.vd_flags
== VER_FLG_BASE
)
13037 off
-= ivd
.vd_next
;
13040 if (get_data (&evda
, filedata
, off
, sizeof (evda
), 1,
13041 _("version def aux")) != NULL
)
13043 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
13045 if (psym
->st_name
!= ivda
.vda_name
)
13046 return (ivda
.vda_name
< strtab_size
13047 ? strtab
+ ivda
.vda_name
: _("<corrupt>"));
13052 if (filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)])
13054 Elf_External_Verneed evn
;
13055 Elf_Internal_Verneed ivn
;
13056 Elf_Internal_Vernaux ivna
;
13058 offset
= offset_from_vma (filedata
,
13059 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)],
13063 unsigned long vna_off
;
13065 if (get_data (&evn
, filedata
, offset
, sizeof (evn
), 1,
13066 _("version need")) == NULL
)
13069 ivna
.vna_other
= 0;
13074 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
13075 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
13077 vna_off
= offset
+ ivn
.vn_aux
;
13081 Elf_External_Vernaux evna
;
13083 if (get_data (&evna
, filedata
, vna_off
, sizeof (evna
), 1,
13084 _("version need aux (3)")) == NULL
)
13087 ivna
.vna_other
= 0;
13092 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
13093 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
13094 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
13097 vna_off
+= ivna
.vna_next
;
13099 while (ivna
.vna_other
!= vers_data
&& ivna
.vna_next
!= 0);
13101 if (ivna
.vna_other
== vers_data
)
13104 offset
+= ivn
.vn_next
;
13106 while (ivn
.vn_next
!= 0);
13108 if (ivna
.vna_other
== vers_data
)
13110 *sym_info
= symbol_undefined
;
13111 *vna_other
= ivna
.vna_other
;
13112 return (ivna
.vna_name
< strtab_size
13113 ? strtab
+ ivna
.vna_name
: _("<corrupt>"));
13115 else if ((max_vd_ndx
|| (vers_data
& VERSYM_VERSION
) != 1)
13116 && (vers_data
& VERSYM_VERSION
) > max_vd_ndx
)
13117 return _("<corrupt>");
13122 /* Display a symbol size on stdout. Format is based on --sym-base setting. */
13124 static unsigned int
13125 print_dynamic_symbol_size (bfd_vma vma
, int base
)
13130 return print_vma (vma
, OCTAL_5
);
13133 return print_vma (vma
, UNSIGNED_5
);
13136 return print_vma (vma
, PREFIX_HEX_5
);
13140 return print_vma (vma
, DEC_5
);
13145 print_dynamic_symbol (Filedata
*filedata
, unsigned long si
,
13146 Elf_Internal_Sym
*symtab
,
13147 Elf_Internal_Shdr
*section
,
13148 char *strtab
, size_t strtab_size
)
13150 const char *version_string
;
13151 enum versioned_symbol_info sym_info
;
13152 unsigned short vna_other
;
13155 Elf_Internal_Sym
*psym
= symtab
+ si
;
13157 printf ("%6ld: ", si
);
13158 print_vma (psym
->st_value
, LONG_HEX
);
13160 print_dynamic_symbol_size (psym
->st_size
, sym_base
);
13161 printf (" %-7s", get_symbol_type (filedata
, ELF_ST_TYPE (psym
->st_info
)));
13162 printf (" %-6s", get_symbol_binding (filedata
, ELF_ST_BIND (psym
->st_info
)));
13163 if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_SOLARIS
)
13164 printf (" %-7s", get_solaris_symbol_visibility (psym
->st_other
));
13167 unsigned int vis
= ELF_ST_VISIBILITY (psym
->st_other
);
13169 printf (" %-7s", get_symbol_visibility (vis
));
13170 /* Check to see if any other bits in the st_other field are set.
13171 Note - displaying this information disrupts the layout of the
13172 table being generated, but for the moment this case is very rare. */
13173 if (psym
->st_other
^ vis
)
13174 printf (" [%s] ", get_symbol_other (filedata
, psym
->st_other
^ vis
));
13176 printf (" %4s ", get_symbol_index_type (filedata
, psym
->st_shndx
));
13178 if (ELF_ST_TYPE (psym
->st_info
) == STT_SECTION
13179 && psym
->st_shndx
< filedata
->file_header
.e_shnum
13180 && filedata
->section_headers
!= NULL
13181 && psym
->st_name
== 0)
13184 = section_name_valid (filedata
,
13185 filedata
->section_headers
+ psym
->st_shndx
);
13187 section_name_print (filedata
,
13188 filedata
->section_headers
+ psym
->st_shndx
)
13193 is_valid
= valid_symbol_name (strtab
, strtab_size
, psym
->st_name
);
13194 sstr
= is_valid
? strtab
+ psym
->st_name
: _("<corrupt>");
13198 = get_symbol_version_string (filedata
,
13200 || section
->sh_type
== SHT_DYNSYM
),
13201 strtab
, strtab_size
, si
,
13202 psym
, &sym_info
, &vna_other
);
13204 int len_avail
= 21;
13205 if (! do_wide
&& version_string
!= NULL
)
13209 len_avail
-= 1 + strlen (version_string
);
13211 if (sym_info
== symbol_undefined
)
13212 len_avail
-= sprintf (buffer
," (%d)", vna_other
);
13213 else if (sym_info
!= symbol_hidden
)
13217 print_symbol (len_avail
, sstr
);
13219 if (version_string
)
13221 if (sym_info
== symbol_undefined
)
13222 printf ("@%s (%d)", version_string
, vna_other
);
13224 printf (sym_info
== symbol_hidden
? "@%s" : "@@%s",
13230 if (ELF_ST_BIND (psym
->st_info
) == STB_LOCAL
13232 && si
>= section
->sh_info
13233 /* Irix 5 and 6 MIPS binaries are known to ignore this requirement. */
13234 && filedata
->file_header
.e_machine
!= EM_MIPS
13235 /* Solaris binaries have been found to violate this requirement as
13236 well. Not sure if this is a bug or an ABI requirement. */
13237 && filedata
->file_header
.e_ident
[EI_OSABI
] != ELFOSABI_SOLARIS
)
13238 warn (_("local symbol %lu found at index >= %s's sh_info value of %u\n"),
13239 si
, printable_section_name (filedata
, section
), section
->sh_info
);
13242 static const char *
13243 get_lto_kind (unsigned int kind
)
13247 case 0: return "DEF";
13248 case 1: return "WEAKDEF";
13249 case 2: return "UNDEF";
13250 case 3: return "WEAKUNDEF";
13251 case 4: return "COMMON";
13256 static char buffer
[30];
13257 error (_("Unknown LTO symbol definition encountered: %u\n"), kind
);
13258 sprintf (buffer
, "<unknown: %u>", kind
);
13262 static const char *
13263 get_lto_visibility (unsigned int visibility
)
13265 switch (visibility
)
13267 case 0: return "DEFAULT";
13268 case 1: return "PROTECTED";
13269 case 2: return "INTERNAL";
13270 case 3: return "HIDDEN";
13275 static char buffer
[30];
13276 error (_("Unknown LTO symbol visibility encountered: %u\n"), visibility
);
13277 sprintf (buffer
, "<unknown: %u>", visibility
);
13281 static const char *
13282 get_lto_sym_type (unsigned int sym_type
)
13286 case 0: return "UNKNOWN";
13287 case 1: return "FUNCTION";
13288 case 2: return "VARIABLE";
13293 static char buffer
[30];
13294 error (_("Unknown LTO symbol type encountered: %u\n"), sym_type
);
13295 sprintf (buffer
, "<unknown: %u>", sym_type
);
13299 /* Display an LTO format symbol table.
13300 FIXME: The format of LTO symbol tables is not formalized.
13301 So this code could need changing in the future. */
13304 display_lto_symtab (Filedata
* filedata
,
13305 Elf_Internal_Shdr
* section
)
13307 if (section
->sh_size
== 0)
13309 if (filedata
->is_separate
)
13310 printf (_("\nThe LTO Symbol table section '%s' in linked file '%s' is empty!\n"),
13311 printable_section_name (filedata
, section
),
13312 filedata
->file_name
);
13314 printf (_("\nLTO Symbol table '%s' is empty!\n"),
13315 printable_section_name (filedata
, section
));
13320 if (section
->sh_size
> filedata
->file_size
)
13322 error (_("Section %s has an invalid sh_size of 0x%lx\n"),
13323 printable_section_name (filedata
, section
),
13324 (unsigned long) section
->sh_size
);
13328 void * alloced_data
= get_data (NULL
, filedata
, section
->sh_offset
,
13329 section
->sh_size
, 1, _("LTO symbols"));
13330 if (alloced_data
== NULL
)
13333 /* Look for extended data for the symbol table. */
13334 Elf_Internal_Shdr
* ext
;
13335 void * ext_data_orig
= NULL
;
13336 char * ext_data
= NULL
;
13337 char * ext_data_end
= NULL
;
13338 char * ext_name
= NULL
;
13340 if (asprintf (& ext_name
, ".gnu.lto_.ext_symtab.%s",
13341 (section_name (filedata
, section
)
13342 + sizeof (".gnu.lto_.symtab.") - 1)) > 0
13343 && ext_name
!= NULL
/* Paranoia. */
13344 && (ext
= find_section (filedata
, ext_name
)) != NULL
)
13346 if (ext
->sh_size
< 3)
13347 error (_("LTO Symbol extension table '%s' is empty!\n"),
13348 printable_section_name (filedata
, ext
));
13351 ext_data_orig
= ext_data
= get_data (NULL
, filedata
, ext
->sh_offset
,
13353 _("LTO ext symbol data"));
13354 if (ext_data
!= NULL
)
13356 ext_data_end
= ext_data
+ ext
->sh_size
;
13357 if (* ext_data
++ != 1)
13358 error (_("Unexpected version number in symbol extension table\n"));
13363 const unsigned char * data
= (const unsigned char *) alloced_data
;
13364 const unsigned char * end
= data
+ section
->sh_size
;
13366 if (filedata
->is_separate
)
13367 printf (_("\nIn linked file '%s': "), filedata
->file_name
);
13371 if (ext_data_orig
!= NULL
)
13374 printf (_("LTO Symbol table '%s' and extension table '%s' contain:\n"),
13375 printable_section_name (filedata
, section
),
13376 printable_section_name (filedata
, ext
));
13379 printf (_("LTO Symbol table '%s'\n"),
13380 printable_section_name (filedata
, section
));
13381 printf (_(" and extension table '%s' contain:\n"),
13382 printable_section_name (filedata
, ext
));
13386 printf (_("LTO Symbol table '%s' contains:\n"),
13387 printable_section_name (filedata
, section
));
13389 /* FIXME: Add a wide version. */
13390 if (ext_data_orig
!= NULL
)
13391 printf (_(" Comdat_Key Kind Visibility Size Slot Type Section Name\n"));
13393 printf (_(" Comdat_Key Kind Visibility Size Slot Name\n"));
13395 /* FIXME: We do not handle style prefixes. */
13399 const unsigned char * sym_name
= data
;
13400 data
+= strnlen ((const char *) sym_name
, end
- data
) + 1;
13404 const unsigned char * comdat_key
= data
;
13405 data
+= strnlen ((const char *) comdat_key
, end
- data
) + 1;
13409 if (data
+ 2 + 8 + 4 > end
)
13412 unsigned int kind
= *data
++;
13413 unsigned int visibility
= *data
++;
13415 elf_vma size
= byte_get (data
, 8);
13418 elf_vma slot
= byte_get (data
, 4);
13421 if (ext_data
!= NULL
)
13423 if (ext_data
< (ext_data_end
- 1))
13425 unsigned int sym_type
= * ext_data
++;
13426 unsigned int sec_kind
= * ext_data
++;
13428 printf (" %10s %10s %11s %08lx %08lx %9s %08lx _",
13429 * comdat_key
== 0 ? "-" : (char *) comdat_key
,
13430 get_lto_kind (kind
),
13431 get_lto_visibility (visibility
),
13434 get_lto_sym_type (sym_type
),
13436 print_symbol (6, (const char *) sym_name
);
13440 error (_("Ran out of LTO symbol extension data\n"));
13442 /* FIXME: return FAIL result ? */
13447 printf (" %10s %10s %11s %08lx %08lx _",
13448 * comdat_key
== 0 ? "-" : (char *) comdat_key
,
13449 get_lto_kind (kind
),
13450 get_lto_visibility (visibility
),
13453 print_symbol (21, (const char *) sym_name
);
13458 if (ext_data
!= NULL
&& ext_data
< ext_data_end
)
13460 error (_("Data remains in the LTO symbol extension table\n"));
13464 free (alloced_data
);
13465 free (ext_data_orig
);
13470 error (_("Buffer overrun encountered whilst decoding LTO symbol table\n"));
13471 free (alloced_data
);
13472 free (ext_data_orig
);
13477 /* Display LTO symbol tables. */
13480 process_lto_symbol_tables (Filedata
* filedata
)
13482 Elf_Internal_Shdr
* section
;
13489 if (filedata
->section_headers
== NULL
)
13492 for (i
= 0, section
= filedata
->section_headers
;
13493 i
< filedata
->file_header
.e_shnum
;
13495 if (section_name_valid (filedata
, section
)
13496 && startswith (section_name (filedata
, section
), ".gnu.lto_.symtab."))
13497 res
&= display_lto_symtab (filedata
, section
);
13502 /* Dump the symbol table. */
13505 process_symbol_table (Filedata
* filedata
)
13507 Elf_Internal_Shdr
* section
;
13509 if (!do_syms
&& !do_dyn_syms
&& !do_histogram
)
13512 if ((filedata
->dynamic_info
[DT_HASH
] || filedata
->dynamic_info_DT_GNU_HASH
)
13514 && do_using_dynamic
13515 && filedata
->dynamic_strings
!= NULL
13516 && filedata
->dynamic_symbols
!= NULL
)
13520 if (filedata
->is_separate
)
13522 printf (ngettext ("\nIn linked file '%s' the dynamic symbol table contains %lu entry:\n",
13523 "\nIn linked file '%s' the dynamic symbol table contains %lu entries:\n",
13524 filedata
->num_dynamic_syms
),
13525 filedata
->file_name
,
13526 filedata
->num_dynamic_syms
);
13530 printf (ngettext ("\nSymbol table for image contains %lu entry:\n",
13531 "\nSymbol table for image contains %lu entries:\n",
13532 filedata
->num_dynamic_syms
),
13533 filedata
->num_dynamic_syms
);
13536 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
13538 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
13540 for (si
= 0; si
< filedata
->num_dynamic_syms
; si
++)
13541 print_dynamic_symbol (filedata
, si
, filedata
->dynamic_symbols
, NULL
,
13542 filedata
->dynamic_strings
,
13543 filedata
->dynamic_strings_length
);
13545 else if ((do_dyn_syms
|| (do_syms
&& !do_using_dynamic
))
13546 && filedata
->section_headers
!= NULL
)
13550 for (i
= 0, section
= filedata
->section_headers
;
13551 i
< filedata
->file_header
.e_shnum
;
13554 char * strtab
= NULL
;
13555 unsigned long int strtab_size
= 0;
13556 Elf_Internal_Sym
* symtab
;
13557 unsigned long si
, num_syms
;
13559 if ((section
->sh_type
!= SHT_SYMTAB
13560 && section
->sh_type
!= SHT_DYNSYM
)
13562 && section
->sh_type
== SHT_SYMTAB
))
13565 if (section
->sh_entsize
== 0)
13567 printf (_("\nSymbol table '%s' has a sh_entsize of zero!\n"),
13568 printable_section_name (filedata
, section
));
13572 num_syms
= section
->sh_size
/ section
->sh_entsize
;
13574 if (filedata
->is_separate
)
13575 printf (ngettext ("\nIn linked file '%s' symbol section '%s' contains %lu entry:\n",
13576 "\nIn linked file '%s' symbol section '%s' contains %lu entries:\n",
13578 filedata
->file_name
,
13579 printable_section_name (filedata
, section
),
13582 printf (ngettext ("\nSymbol table '%s' contains %lu entry:\n",
13583 "\nSymbol table '%s' contains %lu entries:\n",
13585 printable_section_name (filedata
, section
),
13589 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
13591 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
13593 symtab
= get_elf_symbols (filedata
, section
, & num_syms
);
13594 if (symtab
== NULL
)
13597 if (section
->sh_link
== filedata
->file_header
.e_shstrndx
)
13599 strtab
= filedata
->string_table
;
13600 strtab_size
= filedata
->string_table_length
;
13602 else if (section
->sh_link
< filedata
->file_header
.e_shnum
)
13604 Elf_Internal_Shdr
* string_sec
;
13606 string_sec
= filedata
->section_headers
+ section
->sh_link
;
13608 strtab
= (char *) get_data (NULL
, filedata
, string_sec
->sh_offset
,
13609 1, string_sec
->sh_size
,
13610 _("string table"));
13611 strtab_size
= strtab
!= NULL
? string_sec
->sh_size
: 0;
13614 for (si
= 0; si
< num_syms
; si
++)
13615 print_dynamic_symbol (filedata
, si
, symtab
, section
,
13616 strtab
, strtab_size
);
13619 if (strtab
!= filedata
->string_table
)
13625 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
13627 if (do_histogram
&& filedata
->buckets
!= NULL
)
13629 unsigned long * lengths
;
13630 unsigned long * counts
;
13633 unsigned long maxlength
= 0;
13634 unsigned long nzero_counts
= 0;
13635 unsigned long nsyms
= 0;
13638 printf (ngettext ("\nHistogram for bucket list length "
13639 "(total of %lu bucket):\n",
13640 "\nHistogram for bucket list length "
13641 "(total of %lu buckets):\n",
13642 (unsigned long) filedata
->nbuckets
),
13643 (unsigned long) filedata
->nbuckets
);
13645 lengths
= (unsigned long *) calloc (filedata
->nbuckets
,
13646 sizeof (*lengths
));
13647 if (lengths
== NULL
)
13649 error (_("Out of memory allocating space for histogram buckets\n"));
13652 visited
= xcmalloc (filedata
->nchains
, 1);
13653 memset (visited
, 0, filedata
->nchains
);
13655 printf (_(" Length Number %% of total Coverage\n"));
13656 for (hn
= 0; hn
< filedata
->nbuckets
; ++hn
)
13658 for (si
= filedata
->buckets
[hn
]; si
> 0; si
= filedata
->chains
[si
])
13661 if (maxlength
< ++lengths
[hn
])
13663 if (si
>= filedata
->nchains
|| visited
[si
])
13665 error (_("histogram chain is corrupt\n"));
13673 counts
= (unsigned long *) calloc (maxlength
+ 1, sizeof (*counts
));
13674 if (counts
== NULL
)
13677 error (_("Out of memory allocating space for histogram counts\n"));
13681 for (hn
= 0; hn
< filedata
->nbuckets
; ++hn
)
13682 ++counts
[lengths
[hn
]];
13684 if (filedata
->nbuckets
> 0)
13687 printf (" 0 %-10lu (%5.1f%%)\n",
13688 counts
[0], (counts
[0] * 100.0) / filedata
->nbuckets
);
13689 for (i
= 1; i
<= maxlength
; ++i
)
13691 nzero_counts
+= counts
[i
] * i
;
13692 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
13693 i
, counts
[i
], (counts
[i
] * 100.0) / filedata
->nbuckets
,
13694 (nzero_counts
* 100.0) / nsyms
);
13702 free (filedata
->buckets
);
13703 filedata
->buckets
= NULL
;
13704 filedata
->nbuckets
= 0;
13705 free (filedata
->chains
);
13706 filedata
->chains
= NULL
;
13708 if (do_histogram
&& filedata
->gnubuckets
!= NULL
)
13710 unsigned long * lengths
;
13711 unsigned long * counts
;
13713 unsigned long maxlength
= 0;
13714 unsigned long nzero_counts
= 0;
13715 unsigned long nsyms
= 0;
13717 printf (ngettext ("\nHistogram for `%s' bucket list length "
13718 "(total of %lu bucket):\n",
13719 "\nHistogram for `%s' bucket list length "
13720 "(total of %lu buckets):\n",
13721 (unsigned long) filedata
->ngnubuckets
),
13722 GNU_HASH_SECTION_NAME (filedata
),
13723 (unsigned long) filedata
->ngnubuckets
);
13725 lengths
= (unsigned long *) calloc (filedata
->ngnubuckets
,
13726 sizeof (*lengths
));
13727 if (lengths
== NULL
)
13729 error (_("Out of memory allocating space for gnu histogram buckets\n"));
13733 printf (_(" Length Number %% of total Coverage\n"));
13735 for (hn
= 0; hn
< filedata
->ngnubuckets
; ++hn
)
13736 if (filedata
->gnubuckets
[hn
] != 0)
13738 bfd_vma off
, length
= 1;
13740 for (off
= filedata
->gnubuckets
[hn
] - filedata
->gnusymidx
;
13741 /* PR 17531 file: 010-77222-0.004. */
13742 off
< filedata
->ngnuchains
13743 && (filedata
->gnuchains
[off
] & 1) == 0;
13746 lengths
[hn
] = length
;
13747 if (length
> maxlength
)
13748 maxlength
= length
;
13752 counts
= (unsigned long *) calloc (maxlength
+ 1, sizeof (*counts
));
13753 if (counts
== NULL
)
13756 error (_("Out of memory allocating space for gnu histogram counts\n"));
13760 for (hn
= 0; hn
< filedata
->ngnubuckets
; ++hn
)
13761 ++counts
[lengths
[hn
]];
13763 if (filedata
->ngnubuckets
> 0)
13766 printf (" 0 %-10lu (%5.1f%%)\n",
13767 counts
[0], (counts
[0] * 100.0) / filedata
->ngnubuckets
);
13768 for (j
= 1; j
<= maxlength
; ++j
)
13770 nzero_counts
+= counts
[j
] * j
;
13771 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
13772 j
, counts
[j
], (counts
[j
] * 100.0) / filedata
->ngnubuckets
,
13773 (nzero_counts
* 100.0) / nsyms
);
13780 free (filedata
->gnubuckets
);
13781 filedata
->gnubuckets
= NULL
;
13782 filedata
->ngnubuckets
= 0;
13783 free (filedata
->gnuchains
);
13784 filedata
->gnuchains
= NULL
;
13785 filedata
->ngnuchains
= 0;
13786 free (filedata
->mipsxlat
);
13787 filedata
->mipsxlat
= NULL
;
13791 free (filedata
->gnubuckets
);
13792 filedata
->gnubuckets
= NULL
;
13793 filedata
->ngnubuckets
= 0;
13794 free (filedata
->gnuchains
);
13795 filedata
->gnuchains
= NULL
;
13796 filedata
->ngnuchains
= 0;
13797 free (filedata
->mipsxlat
);
13798 filedata
->mipsxlat
= NULL
;
13799 free (filedata
->buckets
);
13800 filedata
->buckets
= NULL
;
13801 filedata
->nbuckets
= 0;
13802 free (filedata
->chains
);
13803 filedata
->chains
= NULL
;
13808 process_syminfo (Filedata
* filedata
)
13812 if (filedata
->dynamic_syminfo
== NULL
13814 /* No syminfo, this is ok. */
13817 /* There better should be a dynamic symbol section. */
13818 if (filedata
->dynamic_symbols
== NULL
|| filedata
->dynamic_strings
== NULL
)
13821 if (filedata
->is_separate
)
13822 printf (ngettext ("\nIn linked file '%s: the dynamic info segment at offset 0x%lx contains %d entry:\n",
13823 "\nIn linked file '%s: the dynamic info segment at offset 0x%lx contains %d entries:\n",
13824 filedata
->dynamic_syminfo_nent
),
13825 filedata
->file_name
,
13826 filedata
->dynamic_syminfo_offset
,
13827 filedata
->dynamic_syminfo_nent
);
13829 printf (ngettext ("\nDynamic info segment at offset 0x%lx "
13830 "contains %d entry:\n",
13831 "\nDynamic info segment at offset 0x%lx "
13832 "contains %d entries:\n",
13833 filedata
->dynamic_syminfo_nent
),
13834 filedata
->dynamic_syminfo_offset
,
13835 filedata
->dynamic_syminfo_nent
);
13837 printf (_(" Num: Name BoundTo Flags\n"));
13838 for (i
= 0; i
< filedata
->dynamic_syminfo_nent
; ++i
)
13840 unsigned short int flags
= filedata
->dynamic_syminfo
[i
].si_flags
;
13842 printf ("%4d: ", i
);
13843 if (i
>= filedata
->num_dynamic_syms
)
13844 printf (_("<corrupt index>"));
13845 else if (valid_dynamic_name (filedata
, filedata
->dynamic_symbols
[i
].st_name
))
13846 print_symbol (30, get_dynamic_name (filedata
,
13847 filedata
->dynamic_symbols
[i
].st_name
));
13849 printf (_("<corrupt: %19ld>"), filedata
->dynamic_symbols
[i
].st_name
);
13852 switch (filedata
->dynamic_syminfo
[i
].si_boundto
)
13854 case SYMINFO_BT_SELF
:
13855 fputs ("SELF ", stdout
);
13857 case SYMINFO_BT_PARENT
:
13858 fputs ("PARENT ", stdout
);
13861 if (filedata
->dynamic_syminfo
[i
].si_boundto
> 0
13862 && filedata
->dynamic_syminfo
[i
].si_boundto
< filedata
->dynamic_nent
13863 && valid_dynamic_name (filedata
,
13864 filedata
->dynamic_section
[filedata
->dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
))
13866 print_symbol (10, get_dynamic_name (filedata
,
13867 filedata
->dynamic_section
[filedata
->dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
));
13871 printf ("%-10d ", filedata
->dynamic_syminfo
[i
].si_boundto
);
13875 if (flags
& SYMINFO_FLG_DIRECT
)
13876 printf (" DIRECT");
13877 if (flags
& SYMINFO_FLG_PASSTHRU
)
13878 printf (" PASSTHRU");
13879 if (flags
& SYMINFO_FLG_COPY
)
13881 if (flags
& SYMINFO_FLG_LAZYLOAD
)
13882 printf (" LAZYLOAD");
13890 /* A macro which evaluates to TRUE if the region ADDR .. ADDR + NELEM
13891 is contained by the region START .. END. The types of ADDR, START
13892 and END should all be the same. Note both ADDR + NELEM and END
13893 point to just beyond the end of the regions that are being tested. */
13894 #define IN_RANGE(START,END,ADDR,NELEM) \
13895 (((ADDR) >= (START)) && ((ADDR) < (END)) && ((ADDR) + (NELEM) <= (END)))
13897 /* Check to see if the given reloc needs to be handled in a target specific
13898 manner. If so then process the reloc and return TRUE otherwise return
13901 If called with reloc == NULL, then this is a signal that reloc processing
13902 for the current section has finished, and any saved state should be
13906 target_specific_reloc_handling (Filedata
* filedata
,
13907 Elf_Internal_Rela
* reloc
,
13908 unsigned char * start
,
13909 unsigned char * end
,
13910 Elf_Internal_Sym
* symtab
,
13911 unsigned long num_syms
)
13913 unsigned int reloc_type
= 0;
13914 unsigned long sym_index
= 0;
13918 reloc_type
= get_reloc_type (filedata
, reloc
->r_info
);
13919 sym_index
= get_reloc_symindex (reloc
->r_info
);
13922 switch (filedata
->file_header
.e_machine
)
13925 case EM_MSP430_OLD
:
13927 static Elf_Internal_Sym
* saved_sym
= NULL
;
13935 switch (reloc_type
)
13937 case 10: /* R_MSP430_SYM_DIFF */
13938 case 12: /* R_MSP430_GNU_SUB_ULEB128 */
13939 if (uses_msp430x_relocs (filedata
))
13941 /* Fall through. */
13942 case 21: /* R_MSP430X_SYM_DIFF */
13943 case 23: /* R_MSP430X_GNU_SUB_ULEB128 */
13945 if (sym_index
>= num_syms
)
13946 error (_("MSP430 SYM_DIFF reloc contains invalid symbol index %lu\n"),
13949 saved_sym
= symtab
+ sym_index
;
13952 case 1: /* R_MSP430_32 or R_MSP430_ABS32 */
13953 case 3: /* R_MSP430_16 or R_MSP430_ABS8 */
13954 goto handle_sym_diff
;
13956 case 5: /* R_MSP430_16_BYTE */
13957 case 9: /* R_MSP430_8 */
13958 case 11: /* R_MSP430_GNU_SET_ULEB128 */
13959 if (uses_msp430x_relocs (filedata
))
13961 goto handle_sym_diff
;
13963 case 2: /* R_MSP430_ABS16 */
13964 case 15: /* R_MSP430X_ABS16 */
13965 case 22: /* R_MSP430X_GNU_SET_ULEB128 */
13966 if (! uses_msp430x_relocs (filedata
))
13968 goto handle_sym_diff
;
13971 if (saved_sym
!= NULL
)
13974 unsigned int reloc_size
= 0;
13976 switch (reloc_type
)
13978 case 1: /* R_MSP430_32 or R_MSP430_ABS32 */
13981 case 11: /* R_MSP430_GNU_SET_ULEB128 */
13982 case 22: /* R_MSP430X_GNU_SET_ULEB128 */
13983 if (reloc
->r_offset
< (size_t) (end
- start
))
13984 read_leb128 (start
+ reloc
->r_offset
, end
, false,
13985 &reloc_size
, &leb_ret
);
13992 if (leb_ret
!= 0 || reloc_size
== 0 || reloc_size
> 8)
13993 error (_("MSP430 ULEB128 field at 0x%lx contains invalid "
13994 "ULEB128 value\n"),
13995 (long) reloc
->r_offset
);
13996 else if (sym_index
>= num_syms
)
13997 error (_("MSP430 reloc contains invalid symbol index %lu\n"),
14001 value
= reloc
->r_addend
+ (symtab
[sym_index
].st_value
14002 - saved_sym
->st_value
);
14004 if (IN_RANGE (start
, end
, start
+ reloc
->r_offset
, reloc_size
))
14005 byte_put (start
+ reloc
->r_offset
, value
, reloc_size
);
14008 error (_("MSP430 sym diff reloc contains invalid offset: 0x%lx\n"),
14009 (long) reloc
->r_offset
);
14018 if (saved_sym
!= NULL
)
14019 error (_("Unhandled MSP430 reloc type found after SYM_DIFF reloc\n"));
14026 case EM_CYGNUS_MN10300
:
14028 static Elf_Internal_Sym
* saved_sym
= NULL
;
14036 switch (reloc_type
)
14038 case 34: /* R_MN10300_ALIGN */
14040 case 33: /* R_MN10300_SYM_DIFF */
14041 if (sym_index
>= num_syms
)
14042 error (_("MN10300_SYM_DIFF reloc contains invalid symbol index %lu\n"),
14045 saved_sym
= symtab
+ sym_index
;
14048 case 1: /* R_MN10300_32 */
14049 case 2: /* R_MN10300_16 */
14050 if (saved_sym
!= NULL
)
14052 int reloc_size
= reloc_type
== 1 ? 4 : 2;
14055 if (sym_index
>= num_syms
)
14056 error (_("MN10300 reloc contains invalid symbol index %lu\n"),
14060 value
= reloc
->r_addend
+ (symtab
[sym_index
].st_value
14061 - saved_sym
->st_value
);
14063 if (IN_RANGE (start
, end
, start
+ reloc
->r_offset
, reloc_size
))
14064 byte_put (start
+ reloc
->r_offset
, value
, reloc_size
);
14066 error (_("MN10300 sym diff reloc contains invalid offset: 0x%lx\n"),
14067 (long) reloc
->r_offset
);
14075 if (saved_sym
!= NULL
)
14076 error (_("Unhandled MN10300 reloc type found after SYM_DIFF reloc\n"));
14084 static bfd_vma saved_sym1
= 0;
14085 static bfd_vma saved_sym2
= 0;
14086 static bfd_vma value
;
14090 saved_sym1
= saved_sym2
= 0;
14094 switch (reloc_type
)
14096 case 0x80: /* R_RL78_SYM. */
14097 saved_sym1
= saved_sym2
;
14098 if (sym_index
>= num_syms
)
14099 error (_("RL78_SYM reloc contains invalid symbol index %lu\n"),
14103 saved_sym2
= symtab
[sym_index
].st_value
;
14104 saved_sym2
+= reloc
->r_addend
;
14108 case 0x83: /* R_RL78_OPsub. */
14109 value
= saved_sym1
- saved_sym2
;
14110 saved_sym2
= saved_sym1
= 0;
14114 case 0x41: /* R_RL78_ABS32. */
14115 if (IN_RANGE (start
, end
, start
+ reloc
->r_offset
, 4))
14116 byte_put (start
+ reloc
->r_offset
, value
, 4);
14118 error (_("RL78 sym diff reloc contains invalid offset: 0x%lx\n"),
14119 (long) reloc
->r_offset
);
14123 case 0x43: /* R_RL78_ABS16. */
14124 if (IN_RANGE (start
, end
, start
+ reloc
->r_offset
, 2))
14125 byte_put (start
+ reloc
->r_offset
, value
, 2);
14127 error (_("RL78 sym diff reloc contains invalid offset: 0x%lx\n"),
14128 (long) reloc
->r_offset
);
14142 /* Returns TRUE iff RELOC_TYPE is a 32-bit absolute RELA relocation used in
14143 DWARF debug sections. This is a target specific test. Note - we do not
14144 go through the whole including-target-headers-multiple-times route, (as
14145 we have already done with <elf/h8.h>) because this would become very
14146 messy and even then this function would have to contain target specific
14147 information (the names of the relocs instead of their numeric values).
14148 FIXME: This is not the correct way to solve this problem. The proper way
14149 is to have target specific reloc sizing and typing functions created by
14150 the reloc-macros.h header, in the same way that it already creates the
14151 reloc naming functions. */
14154 is_32bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14156 /* Please keep this table alpha-sorted for ease of visual lookup. */
14157 switch (filedata
->file_header
.e_machine
)
14161 return reloc_type
== 1; /* R_386_32. */
14163 return reloc_type
== 1; /* R_68K_32. */
14165 return reloc_type
== 1; /* R_860_32. */
14167 return reloc_type
== 2; /* R_960_32. */
14169 return (reloc_type
== 258
14170 || reloc_type
== 1); /* R_AARCH64_ABS32 || R_AARCH64_P32_ABS32 */
14172 return reloc_type
== 11; /* R_BPF_DATA_32 */
14173 case EM_ADAPTEVA_EPIPHANY
:
14174 return reloc_type
== 3;
14176 return reloc_type
== 1; /* R_ALPHA_REFLONG. */
14178 return reloc_type
== 1; /* R_ARC_32. */
14179 case EM_ARC_COMPACT
:
14180 case EM_ARC_COMPACT2
:
14181 return reloc_type
== 4; /* R_ARC_32. */
14183 return reloc_type
== 2; /* R_ARM_ABS32 */
14186 return reloc_type
== 1;
14188 return reloc_type
== 0x12; /* R_byte4_data. */
14190 return reloc_type
== 3; /* R_CRIS_32. */
14192 return reloc_type
== 3; /* R_CR16_NUM32. */
14194 return reloc_type
== 15; /* R_CRX_NUM32. */
14196 return reloc_type
== 1; /* R_CKCORE_ADDR32. */
14197 case EM_CYGNUS_FRV
:
14198 return reloc_type
== 1;
14199 case EM_CYGNUS_D10V
:
14201 return reloc_type
== 6; /* R_D10V_32. */
14202 case EM_CYGNUS_D30V
:
14204 return reloc_type
== 12; /* R_D30V_32_NORMAL. */
14206 return reloc_type
== 3; /* R_DLX_RELOC_32. */
14207 case EM_CYGNUS_FR30
:
14209 return reloc_type
== 3; /* R_FR30_32. */
14211 return reloc_type
== 1; /* R_FT32_32. */
14215 return reloc_type
== 1; /* R_H8_DIR32. */
14217 return (reloc_type
== 0x64 /* R_IA64_SECREL32MSB. */
14218 || reloc_type
== 0x65 /* R_IA64_SECREL32LSB. */
14219 || reloc_type
== 0x24 /* R_IA64_DIR32MSB. */
14220 || reloc_type
== 0x25 /* R_IA64_DIR32LSB. */);
14223 return reloc_type
== 2; /* R_IP2K_32. */
14225 return reloc_type
== 2; /* R_IQ2000_32. */
14226 case EM_LATTICEMICO32
:
14227 return reloc_type
== 3; /* R_LM32_32. */
14229 return reloc_type
== 1; /* R_LARCH_32. */
14232 return reloc_type
== 3; /* R_M32C_32. */
14234 return reloc_type
== 34; /* R_M32R_32_RELA. */
14237 return reloc_type
== 6; /* R_M68HC11_32. */
14239 return reloc_type
== 7 || /* R_S12Z_EXT32 */
14240 reloc_type
== 6; /* R_S12Z_CW32. */
14242 return reloc_type
== 1; /* R_MCORE_ADDR32. */
14243 case EM_CYGNUS_MEP
:
14244 return reloc_type
== 4; /* R_MEP_32. */
14246 return reloc_type
== 2; /* R_METAG_ADDR32. */
14247 case EM_MICROBLAZE
:
14248 return reloc_type
== 1; /* R_MICROBLAZE_32. */
14250 return reloc_type
== 2; /* R_MIPS_32. */
14252 return reloc_type
== 4; /* R_MMIX_32. */
14253 case EM_CYGNUS_MN10200
:
14255 return reloc_type
== 1; /* R_MN10200_32. */
14256 case EM_CYGNUS_MN10300
:
14258 return reloc_type
== 1; /* R_MN10300_32. */
14260 return reloc_type
== 1; /* R_MOXIE_32. */
14261 case EM_MSP430_OLD
:
14263 return reloc_type
== 1; /* R_MSP430_32 or R_MSP320_ABS32. */
14265 return reloc_type
== 2; /* R_MT_32. */
14267 return reloc_type
== 20; /* R_NDS32_32_RELA. */
14268 case EM_ALTERA_NIOS2
:
14269 return reloc_type
== 12; /* R_NIOS2_BFD_RELOC_32. */
14271 return reloc_type
== 1; /* R_NIOS_32. */
14273 return reloc_type
== 1; /* R_OR1K_32. */
14275 return (reloc_type
== 1 /* R_PARISC_DIR32. */
14276 || reloc_type
== 2 /* R_PARISC_DIR21L. */
14277 || reloc_type
== 41); /* R_PARISC_SECREL32. */
14280 return reloc_type
== 1; /* R_PJ_DATA_DIR32. */
14282 return reloc_type
== 1; /* R_PPC64_ADDR32. */
14284 return reloc_type
== 1; /* R_PPC_ADDR32. */
14286 return reloc_type
== 11; /* R_PRU_BFD_RELOC_32. */
14288 return reloc_type
== 1; /* R_RISCV_32. */
14290 return reloc_type
== 1; /* R_RL78_DIR32. */
14292 return reloc_type
== 1; /* R_RX_DIR32. */
14294 return reloc_type
== 1; /* R_I370_ADDR31. */
14297 return reloc_type
== 4; /* R_S390_32. */
14299 return reloc_type
== 8; /* R_SCORE_ABS32. */
14301 return reloc_type
== 1; /* R_SH_DIR32. */
14302 case EM_SPARC32PLUS
:
14305 return reloc_type
== 3 /* R_SPARC_32. */
14306 || reloc_type
== 23; /* R_SPARC_UA32. */
14308 return reloc_type
== 6; /* R_SPU_ADDR32 */
14310 return reloc_type
== 1; /* R_C6000_ABS32. */
14312 return reloc_type
== 2; /* R_TILEGX_32. */
14314 return reloc_type
== 1; /* R_TILEPRO_32. */
14315 case EM_CYGNUS_V850
:
14317 return reloc_type
== 6; /* R_V850_ABS32. */
14319 return reloc_type
== 0x33; /* R_V810_WORD. */
14321 return reloc_type
== 1; /* R_VAX_32. */
14323 return reloc_type
== 3; /* R_VISIUM_32. */
14324 case EM_WEBASSEMBLY
:
14325 return reloc_type
== 1; /* R_WASM32_32. */
14329 return reloc_type
== 10; /* R_X86_64_32. */
14331 return reloc_type
== 4; /* R_XGATE_32. */
14333 return reloc_type
== 1; /* R_XSTROMY16_32. */
14334 case EM_XTENSA_OLD
:
14336 return reloc_type
== 1; /* R_XTENSA_32. */
14338 return reloc_type
== 6; /* R_Z80_32. */
14341 static unsigned int prev_warn
= 0;
14343 /* Avoid repeating the same warning multiple times. */
14344 if (prev_warn
!= filedata
->file_header
.e_machine
)
14345 error (_("Missing knowledge of 32-bit reloc types used in DWARF sections of machine number %d\n"),
14346 filedata
->file_header
.e_machine
);
14347 prev_warn
= filedata
->file_header
.e_machine
;
14353 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14354 a 32-bit pc-relative RELA relocation used in DWARF debug sections. */
14357 is_32bit_pcrel_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14359 switch (filedata
->file_header
.e_machine
)
14360 /* Please keep this table alpha-sorted for ease of visual lookup. */
14364 return reloc_type
== 2; /* R_386_PC32. */
14366 return reloc_type
== 4; /* R_68K_PC32. */
14368 return reloc_type
== 261; /* R_AARCH64_PREL32 */
14369 case EM_ADAPTEVA_EPIPHANY
:
14370 return reloc_type
== 6;
14372 return reloc_type
== 10; /* R_ALPHA_SREL32. */
14373 case EM_ARC_COMPACT
:
14374 case EM_ARC_COMPACT2
:
14375 return reloc_type
== 49; /* R_ARC_32_PCREL. */
14377 return reloc_type
== 3; /* R_ARM_REL32 */
14380 return reloc_type
== 36; /* R_AVR_32_PCREL. */
14382 return reloc_type
== 99; /* R_LARCH_32_PCREL. */
14383 case EM_MICROBLAZE
:
14384 return reloc_type
== 2; /* R_MICROBLAZE_32_PCREL. */
14386 return reloc_type
== 9; /* R_OR1K_32_PCREL. */
14388 return reloc_type
== 9; /* R_PARISC_PCREL32. */
14390 return reloc_type
== 26; /* R_PPC_REL32. */
14392 return reloc_type
== 26; /* R_PPC64_REL32. */
14394 return reloc_type
== 57; /* R_RISCV_32_PCREL. */
14397 return reloc_type
== 5; /* R_390_PC32. */
14399 return reloc_type
== 2; /* R_SH_REL32. */
14400 case EM_SPARC32PLUS
:
14403 return reloc_type
== 6; /* R_SPARC_DISP32. */
14405 return reloc_type
== 13; /* R_SPU_REL32. */
14407 return reloc_type
== 6; /* R_TILEGX_32_PCREL. */
14409 return reloc_type
== 4; /* R_TILEPRO_32_PCREL. */
14411 return reloc_type
== 6; /* R_VISIUM_32_PCREL */
14415 return reloc_type
== 2; /* R_X86_64_PC32. */
14417 return reloc_type
== 4; /* R_VAX_PCREL32. */
14418 case EM_XTENSA_OLD
:
14420 return reloc_type
== 14; /* R_XTENSA_32_PCREL. */
14422 /* Do not abort or issue an error message here. Not all targets use
14423 pc-relative 32-bit relocs in their DWARF debug information and we
14424 have already tested for target coverage in is_32bit_abs_reloc. A
14425 more helpful warning message will be generated by apply_relocations
14426 anyway, so just return. */
14431 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14432 a 64-bit absolute RELA relocation used in DWARF debug sections. */
14435 is_64bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14437 switch (filedata
->file_header
.e_machine
)
14440 return reloc_type
== 257; /* R_AARCH64_ABS64. */
14442 return reloc_type
== 2; /* R_ALPHA_REFQUAD. */
14444 return (reloc_type
== 0x26 /* R_IA64_DIR64MSB. */
14445 || reloc_type
== 0x27 /* R_IA64_DIR64LSB. */);
14447 return reloc_type
== 2; /* R_LARCH_64 */
14449 return reloc_type
== 80; /* R_PARISC_DIR64. */
14451 return reloc_type
== 38; /* R_PPC64_ADDR64. */
14453 return reloc_type
== 2; /* R_RISCV_64. */
14454 case EM_SPARC32PLUS
:
14457 return reloc_type
== 32 /* R_SPARC_64. */
14458 || reloc_type
== 54; /* R_SPARC_UA64. */
14462 return reloc_type
== 1; /* R_X86_64_64. */
14465 return reloc_type
== 22; /* R_S390_64. */
14467 return reloc_type
== 1; /* R_TILEGX_64. */
14469 return reloc_type
== 18; /* R_MIPS_64. */
14475 /* Like is_32bit_pcrel_reloc except that it returns TRUE iff RELOC_TYPE is
14476 a 64-bit pc-relative RELA relocation used in DWARF debug sections. */
14479 is_64bit_pcrel_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14481 switch (filedata
->file_header
.e_machine
)
14484 return reloc_type
== 260; /* R_AARCH64_PREL64. */
14486 return reloc_type
== 11; /* R_ALPHA_SREL64. */
14488 return (reloc_type
== 0x4e /* R_IA64_PCREL64MSB. */
14489 || reloc_type
== 0x4f /* R_IA64_PCREL64LSB. */);
14491 return reloc_type
== 72; /* R_PARISC_PCREL64. */
14493 return reloc_type
== 44; /* R_PPC64_REL64. */
14494 case EM_SPARC32PLUS
:
14497 return reloc_type
== 46; /* R_SPARC_DISP64. */
14501 return reloc_type
== 24; /* R_X86_64_PC64. */
14504 return reloc_type
== 23; /* R_S390_PC64. */
14506 return reloc_type
== 5; /* R_TILEGX_64_PCREL. */
14512 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14513 a 24-bit absolute RELA relocation used in DWARF debug sections. */
14516 is_24bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14518 switch (filedata
->file_header
.e_machine
)
14520 case EM_CYGNUS_MN10200
:
14522 return reloc_type
== 4; /* R_MN10200_24. */
14524 return reloc_type
== 5; /* R_FT32_20. */
14526 return reloc_type
== 5; /* R_Z80_24. */
14532 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14533 a 16-bit absolute RELA relocation used in DWARF debug sections. */
14536 is_16bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14538 /* Please keep this table alpha-sorted for ease of visual lookup. */
14539 switch (filedata
->file_header
.e_machine
)
14542 case EM_ARC_COMPACT
:
14543 case EM_ARC_COMPACT2
:
14544 return reloc_type
== 2; /* R_ARC_16. */
14545 case EM_ADAPTEVA_EPIPHANY
:
14546 return reloc_type
== 5;
14549 return reloc_type
== 4; /* R_AVR_16. */
14550 case EM_CYGNUS_D10V
:
14552 return reloc_type
== 3; /* R_D10V_16. */
14554 return reloc_type
== 2; /* R_FT32_16. */
14558 return reloc_type
== R_H8_DIR16
;
14561 return reloc_type
== 1; /* R_IP2K_16. */
14564 return reloc_type
== 1; /* R_M32C_16 */
14565 case EM_CYGNUS_MN10200
:
14567 return reloc_type
== 2; /* R_MN10200_16. */
14568 case EM_CYGNUS_MN10300
:
14570 return reloc_type
== 2; /* R_MN10300_16. */
14572 if (uses_msp430x_relocs (filedata
))
14573 return reloc_type
== 2; /* R_MSP430_ABS16. */
14574 /* Fall through. */
14575 case EM_MSP430_OLD
:
14576 return reloc_type
== 5; /* R_MSP430_16_BYTE. */
14578 return reloc_type
== 19; /* R_NDS32_16_RELA. */
14579 case EM_ALTERA_NIOS2
:
14580 return reloc_type
== 13; /* R_NIOS2_BFD_RELOC_16. */
14582 return reloc_type
== 9; /* R_NIOS_16. */
14584 return reloc_type
== 2; /* R_OR1K_16. */
14586 return reloc_type
== 55; /* R_RISCV_SET16. */
14588 return reloc_type
== 8; /* R_PRU_BFD_RELOC_16. */
14590 return reloc_type
== 2; /* R_C6000_ABS16. */
14592 return reloc_type
== 2; /* R_VISIUM_16. */
14594 return reloc_type
== 3; /* R_XGATE_16. */
14596 return reloc_type
== 4; /* R_Z80_16. */
14602 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14603 a 8-bit absolute RELA relocation used in DWARF debug sections. */
14606 is_8bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14608 switch (filedata
->file_header
.e_machine
)
14611 return reloc_type
== 54; /* R_RISCV_SET8. */
14613 return reloc_type
== 1; /* R_Z80_8. */
14619 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14620 a 6-bit absolute RELA relocation used in DWARF debug sections. */
14623 is_6bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14625 switch (filedata
->file_header
.e_machine
)
14628 return reloc_type
== 53; /* R_RISCV_SET6. */
14634 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14635 a 32-bit inplace add RELA relocation used in DWARF debug sections. */
14638 is_32bit_inplace_add_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14640 /* Please keep this table alpha-sorted for ease of visual lookup. */
14641 switch (filedata
->file_header
.e_machine
)
14644 return reloc_type
== 35; /* R_RISCV_ADD32. */
14650 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14651 a 32-bit inplace sub RELA relocation used in DWARF debug sections. */
14654 is_32bit_inplace_sub_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14656 /* Please keep this table alpha-sorted for ease of visual lookup. */
14657 switch (filedata
->file_header
.e_machine
)
14660 return reloc_type
== 39; /* R_RISCV_SUB32. */
14666 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14667 a 64-bit inplace add RELA relocation used in DWARF debug sections. */
14670 is_64bit_inplace_add_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14672 /* Please keep this table alpha-sorted for ease of visual lookup. */
14673 switch (filedata
->file_header
.e_machine
)
14676 return reloc_type
== 36; /* R_RISCV_ADD64. */
14682 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14683 a 64-bit inplace sub RELA relocation used in DWARF debug sections. */
14686 is_64bit_inplace_sub_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14688 /* Please keep this table alpha-sorted for ease of visual lookup. */
14689 switch (filedata
->file_header
.e_machine
)
14692 return reloc_type
== 40; /* R_RISCV_SUB64. */
14698 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14699 a 16-bit inplace add RELA relocation used in DWARF debug sections. */
14702 is_16bit_inplace_add_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14704 /* Please keep this table alpha-sorted for ease of visual lookup. */
14705 switch (filedata
->file_header
.e_machine
)
14708 return reloc_type
== 34; /* R_RISCV_ADD16. */
14714 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14715 a 16-bit inplace sub RELA relocation used in DWARF debug sections. */
14718 is_16bit_inplace_sub_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14720 /* Please keep this table alpha-sorted for ease of visual lookup. */
14721 switch (filedata
->file_header
.e_machine
)
14724 return reloc_type
== 38; /* R_RISCV_SUB16. */
14730 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14731 a 8-bit inplace add RELA relocation used in DWARF debug sections. */
14734 is_8bit_inplace_add_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14736 /* Please keep this table alpha-sorted for ease of visual lookup. */
14737 switch (filedata
->file_header
.e_machine
)
14740 return reloc_type
== 33; /* R_RISCV_ADD8. */
14746 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14747 a 8-bit inplace sub RELA relocation used in DWARF debug sections. */
14750 is_8bit_inplace_sub_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14752 /* Please keep this table alpha-sorted for ease of visual lookup. */
14753 switch (filedata
->file_header
.e_machine
)
14756 return reloc_type
== 37; /* R_RISCV_SUB8. */
14762 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
14763 a 6-bit inplace sub RELA relocation used in DWARF debug sections. */
14766 is_6bit_inplace_sub_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14768 switch (filedata
->file_header
.e_machine
)
14771 return reloc_type
== 52; /* R_RISCV_SUB6. */
14777 /* Returns TRUE iff RELOC_TYPE is a NONE relocation used for discarded
14778 relocation entries (possibly formerly used for SHT_GROUP sections). */
14781 is_none_reloc (Filedata
* filedata
, unsigned int reloc_type
)
14783 switch (filedata
->file_header
.e_machine
)
14785 case EM_386
: /* R_386_NONE. */
14786 case EM_68K
: /* R_68K_NONE. */
14787 case EM_ADAPTEVA_EPIPHANY
:
14788 case EM_ALPHA
: /* R_ALPHA_NONE. */
14789 case EM_ALTERA_NIOS2
: /* R_NIOS2_NONE. */
14790 case EM_ARC
: /* R_ARC_NONE. */
14791 case EM_ARC_COMPACT2
: /* R_ARC_NONE. */
14792 case EM_ARC_COMPACT
: /* R_ARC_NONE. */
14793 case EM_ARM
: /* R_ARM_NONE. */
14794 case EM_CRIS
: /* R_CRIS_NONE. */
14795 case EM_FT32
: /* R_FT32_NONE. */
14796 case EM_IA_64
: /* R_IA64_NONE. */
14797 case EM_K1OM
: /* R_X86_64_NONE. */
14798 case EM_L1OM
: /* R_X86_64_NONE. */
14799 case EM_M32R
: /* R_M32R_NONE. */
14800 case EM_MIPS
: /* R_MIPS_NONE. */
14801 case EM_MN10300
: /* R_MN10300_NONE. */
14802 case EM_MOXIE
: /* R_MOXIE_NONE. */
14803 case EM_NIOS32
: /* R_NIOS_NONE. */
14804 case EM_OR1K
: /* R_OR1K_NONE. */
14805 case EM_PARISC
: /* R_PARISC_NONE. */
14806 case EM_PPC64
: /* R_PPC64_NONE. */
14807 case EM_PPC
: /* R_PPC_NONE. */
14808 case EM_RISCV
: /* R_RISCV_NONE. */
14809 case EM_S390
: /* R_390_NONE. */
14811 case EM_SH
: /* R_SH_NONE. */
14812 case EM_SPARC32PLUS
:
14813 case EM_SPARC
: /* R_SPARC_NONE. */
14815 case EM_TILEGX
: /* R_TILEGX_NONE. */
14816 case EM_TILEPRO
: /* R_TILEPRO_NONE. */
14817 case EM_TI_C6000
:/* R_C6000_NONE. */
14818 case EM_X86_64
: /* R_X86_64_NONE. */
14819 case EM_Z80
: /* R_Z80_NONE. */
14820 case EM_WEBASSEMBLY
: /* R_WASM32_NONE. */
14821 return reloc_type
== 0;
14824 return reloc_type
== 0 || reloc_type
== 256;
14827 return (reloc_type
== 0 /* R_AVR_NONE. */
14828 || reloc_type
== 30 /* R_AVR_DIFF8. */
14829 || reloc_type
== 31 /* R_AVR_DIFF16. */
14830 || reloc_type
== 32 /* R_AVR_DIFF32. */);
14832 return reloc_type
== 3; /* R_METAG_NONE. */
14834 return (reloc_type
== 0 /* R_NDS32_NONE. */
14835 || reloc_type
== 205 /* R_NDS32_DIFF8. */
14836 || reloc_type
== 206 /* R_NDS32_DIFF16. */
14837 || reloc_type
== 207 /* R_NDS32_DIFF32. */
14838 || reloc_type
== 208 /* R_NDS32_DIFF_ULEB128. */);
14840 return (reloc_type
== 0 /* R_PRU_NONE. */
14841 || reloc_type
== 65 /* R_PRU_DIFF8. */
14842 || reloc_type
== 66 /* R_PRU_DIFF16. */
14843 || reloc_type
== 67 /* R_PRU_DIFF32. */);
14844 case EM_XTENSA_OLD
:
14846 return (reloc_type
== 0 /* R_XTENSA_NONE. */
14847 || reloc_type
== 17 /* R_XTENSA_DIFF8. */
14848 || reloc_type
== 18 /* R_XTENSA_DIFF16. */
14849 || reloc_type
== 19 /* R_XTENSA_DIFF32. */
14850 || reloc_type
== 57 /* R_XTENSA_PDIFF8. */
14851 || reloc_type
== 58 /* R_XTENSA_PDIFF16. */
14852 || reloc_type
== 59 /* R_XTENSA_PDIFF32. */
14853 || reloc_type
== 60 /* R_XTENSA_NDIFF8. */
14854 || reloc_type
== 61 /* R_XTENSA_NDIFF16. */
14855 || reloc_type
== 62 /* R_XTENSA_NDIFF32. */);
14860 /* Returns TRUE if there is a relocation against
14861 section NAME at OFFSET bytes. */
14864 reloc_at (struct dwarf_section
* dsec
, dwarf_vma offset
)
14866 Elf_Internal_Rela
* relocs
;
14867 Elf_Internal_Rela
* rp
;
14869 if (dsec
== NULL
|| dsec
->reloc_info
== NULL
)
14872 relocs
= (Elf_Internal_Rela
*) dsec
->reloc_info
;
14874 for (rp
= relocs
; rp
< relocs
+ dsec
->num_relocs
; ++rp
)
14875 if (rp
->r_offset
== offset
)
14881 /* Apply relocations to a section.
14882 Returns TRUE upon success, FALSE otherwise.
14883 If RELOCS_RETURN is non-NULL then it is set to point to the loaded relocs.
14884 It is then the caller's responsibility to free them. NUM_RELOCS_RETURN
14885 will be set to the number of relocs loaded.
14887 Note: So far support has been added only for those relocations
14888 which can be found in debug sections. FIXME: Add support for
14889 more relocations ? */
14892 apply_relocations (Filedata
* filedata
,
14893 const Elf_Internal_Shdr
* section
,
14894 unsigned char * start
,
14895 bfd_size_type size
,
14896 void ** relocs_return
,
14897 unsigned long * num_relocs_return
)
14899 Elf_Internal_Shdr
* relsec
;
14900 unsigned char * end
= start
+ size
;
14902 if (relocs_return
!= NULL
)
14904 * (Elf_Internal_Rela
**) relocs_return
= NULL
;
14905 * num_relocs_return
= 0;
14908 if (filedata
->file_header
.e_type
!= ET_REL
)
14909 /* No relocs to apply. */
14912 /* Find the reloc section associated with the section. */
14913 for (relsec
= filedata
->section_headers
;
14914 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
14918 unsigned long num_relocs
;
14919 Elf_Internal_Rela
* relocs
;
14920 Elf_Internal_Rela
* rp
;
14921 Elf_Internal_Shdr
* symsec
;
14922 Elf_Internal_Sym
* symtab
;
14923 unsigned long num_syms
;
14924 Elf_Internal_Sym
* sym
;
14926 if ((relsec
->sh_type
!= SHT_RELA
&& relsec
->sh_type
!= SHT_REL
)
14927 || relsec
->sh_info
>= filedata
->file_header
.e_shnum
14928 || filedata
->section_headers
+ relsec
->sh_info
!= section
14929 || relsec
->sh_size
== 0
14930 || relsec
->sh_link
>= filedata
->file_header
.e_shnum
)
14933 symsec
= filedata
->section_headers
+ relsec
->sh_link
;
14934 if (symsec
->sh_type
!= SHT_SYMTAB
14935 && symsec
->sh_type
!= SHT_DYNSYM
)
14938 is_rela
= relsec
->sh_type
== SHT_RELA
;
14942 if (!slurp_rela_relocs (filedata
, relsec
->sh_offset
,
14943 relsec
->sh_size
, & relocs
, & num_relocs
))
14948 if (!slurp_rel_relocs (filedata
, relsec
->sh_offset
,
14949 relsec
->sh_size
, & relocs
, & num_relocs
))
14953 /* SH uses RELA but uses in place value instead of the addend field. */
14954 if (filedata
->file_header
.e_machine
== EM_SH
)
14957 symtab
= get_elf_symbols (filedata
, symsec
, & num_syms
);
14959 for (rp
= relocs
; rp
< relocs
+ num_relocs
; ++rp
)
14962 unsigned int reloc_type
;
14963 unsigned int reloc_size
;
14964 bool reloc_inplace
= false;
14965 bool reloc_subtract
= false;
14966 unsigned char *rloc
;
14967 unsigned long sym_index
;
14969 reloc_type
= get_reloc_type (filedata
, rp
->r_info
);
14971 if (target_specific_reloc_handling (filedata
, rp
, start
, end
, symtab
, num_syms
))
14973 else if (is_none_reloc (filedata
, reloc_type
))
14975 else if (is_32bit_abs_reloc (filedata
, reloc_type
)
14976 || is_32bit_pcrel_reloc (filedata
, reloc_type
))
14978 else if (is_64bit_abs_reloc (filedata
, reloc_type
)
14979 || is_64bit_pcrel_reloc (filedata
, reloc_type
))
14981 else if (is_24bit_abs_reloc (filedata
, reloc_type
))
14983 else if (is_16bit_abs_reloc (filedata
, reloc_type
))
14985 else if (is_8bit_abs_reloc (filedata
, reloc_type
)
14986 || is_6bit_abs_reloc (filedata
, reloc_type
))
14988 else if ((reloc_subtract
= is_32bit_inplace_sub_reloc (filedata
,
14990 || is_32bit_inplace_add_reloc (filedata
, reloc_type
))
14993 reloc_inplace
= true;
14995 else if ((reloc_subtract
= is_64bit_inplace_sub_reloc (filedata
,
14997 || is_64bit_inplace_add_reloc (filedata
, reloc_type
))
15000 reloc_inplace
= true;
15002 else if ((reloc_subtract
= is_16bit_inplace_sub_reloc (filedata
,
15004 || is_16bit_inplace_add_reloc (filedata
, reloc_type
))
15007 reloc_inplace
= true;
15009 else if ((reloc_subtract
= is_8bit_inplace_sub_reloc (filedata
,
15011 || is_8bit_inplace_add_reloc (filedata
, reloc_type
))
15014 reloc_inplace
= true;
15016 else if ((reloc_subtract
= is_6bit_inplace_sub_reloc (filedata
,
15020 reloc_inplace
= true;
15024 static unsigned int prev_reloc
= 0;
15026 if (reloc_type
!= prev_reloc
)
15027 warn (_("unable to apply unsupported reloc type %d to section %s\n"),
15028 reloc_type
, printable_section_name (filedata
, section
));
15029 prev_reloc
= reloc_type
;
15033 rloc
= start
+ rp
->r_offset
;
15034 if (!IN_RANGE (start
, end
, rloc
, reloc_size
))
15036 warn (_("skipping invalid relocation offset 0x%lx in section %s\n"),
15037 (unsigned long) rp
->r_offset
,
15038 printable_section_name (filedata
, section
));
15042 sym_index
= (unsigned long) get_reloc_symindex (rp
->r_info
);
15043 if (sym_index
>= num_syms
)
15045 warn (_("skipping invalid relocation symbol index 0x%lx in section %s\n"),
15046 sym_index
, printable_section_name (filedata
, section
));
15049 sym
= symtab
+ sym_index
;
15051 /* If the reloc has a symbol associated with it,
15052 make sure that it is of an appropriate type.
15054 Relocations against symbols without type can happen.
15055 Gcc -feliminate-dwarf2-dups may generate symbols
15056 without type for debug info.
15058 Icc generates relocations against function symbols
15059 instead of local labels.
15061 Relocations against object symbols can happen, eg when
15062 referencing a global array. For an example of this see
15063 the _clz.o binary in libgcc.a. */
15065 && ELF_ST_TYPE (sym
->st_info
) != STT_COMMON
15066 && ELF_ST_TYPE (sym
->st_info
) > STT_SECTION
)
15068 warn (_("skipping unexpected symbol type %s in section %s relocation %ld\n"),
15069 get_symbol_type (filedata
, ELF_ST_TYPE (sym
->st_info
)),
15070 printable_section_name (filedata
, relsec
),
15071 (long int)(rp
- relocs
));
15077 addend
+= rp
->r_addend
;
15078 /* R_XTENSA_32, R_PJ_DATA_DIR32 and R_D30V_32_NORMAL are
15079 partial_inplace. */
15081 || (filedata
->file_header
.e_machine
== EM_XTENSA
15082 && reloc_type
== 1)
15083 || ((filedata
->file_header
.e_machine
== EM_PJ
15084 || filedata
->file_header
.e_machine
== EM_PJ_OLD
)
15085 && reloc_type
== 1)
15086 || ((filedata
->file_header
.e_machine
== EM_D30V
15087 || filedata
->file_header
.e_machine
== EM_CYGNUS_D30V
)
15088 && reloc_type
== 12)
15091 if (is_6bit_inplace_sub_reloc (filedata
, reloc_type
))
15092 addend
+= byte_get (rloc
, reloc_size
) & 0x3f;
15094 addend
+= byte_get (rloc
, reloc_size
);
15097 if (is_32bit_pcrel_reloc (filedata
, reloc_type
)
15098 || is_64bit_pcrel_reloc (filedata
, reloc_type
))
15100 /* On HPPA, all pc-relative relocations are biased by 8. */
15101 if (filedata
->file_header
.e_machine
== EM_PARISC
)
15103 byte_put (rloc
, (addend
+ sym
->st_value
) - rp
->r_offset
,
15106 else if (is_6bit_abs_reloc (filedata
, reloc_type
)
15107 || is_6bit_inplace_sub_reloc (filedata
, reloc_type
))
15109 if (reloc_subtract
)
15110 addend
-= sym
->st_value
;
15112 addend
+= sym
->st_value
;
15113 addend
= (addend
& 0x3f) | (byte_get (rloc
, reloc_size
) & 0xc0);
15114 byte_put (rloc
, addend
, reloc_size
);
15116 else if (reloc_subtract
)
15117 byte_put (rloc
, addend
- sym
->st_value
, reloc_size
);
15119 byte_put (rloc
, addend
+ sym
->st_value
, reloc_size
);
15123 /* Let the target specific reloc processing code know that
15124 we have finished with these relocs. */
15125 target_specific_reloc_handling (filedata
, NULL
, NULL
, NULL
, NULL
, 0);
15129 * (Elf_Internal_Rela
**) relocs_return
= relocs
;
15130 * num_relocs_return
= num_relocs
;
15141 #ifdef SUPPORT_DISASSEMBLY
15143 disassemble_section (Elf_Internal_Shdr
* section
, Filedata
* filedata
)
15145 printf (_("\nAssembly dump of section %s\n"), printable_section_name (filedata
, section
));
15147 /* FIXME: XXX -- to be done --- XXX */
15153 /* Reads in the contents of SECTION from FILE, returning a pointer
15154 to a malloc'ed buffer or NULL if something went wrong. */
15157 get_section_contents (Elf_Internal_Shdr
* section
, Filedata
* filedata
)
15159 bfd_size_type num_bytes
= section
->sh_size
;
15161 if (num_bytes
== 0 || section
->sh_type
== SHT_NOBITS
)
15163 printf (_("Section '%s' has no data to dump.\n"),
15164 printable_section_name (filedata
, section
));
15168 return (char *) get_data (NULL
, filedata
, section
->sh_offset
, 1, num_bytes
,
15169 _("section contents"));
15172 /* Uncompresses a section that was compressed using zlib, in place. */
15175 uncompress_section_contents (unsigned char ** buffer
,
15176 dwarf_size_type uncompressed_size
,
15177 dwarf_size_type
* size
)
15179 dwarf_size_type compressed_size
= *size
;
15180 unsigned char * compressed_buffer
= *buffer
;
15181 unsigned char * uncompressed_buffer
;
15185 /* It is possible the section consists of several compressed
15186 buffers concatenated together, so we uncompress in a loop. */
15187 /* PR 18313: The state field in the z_stream structure is supposed
15188 to be invisible to the user (ie us), but some compilers will
15189 still complain about it being used without initialisation. So
15190 we first zero the entire z_stream structure and then set the fields
15192 memset (& strm
, 0, sizeof strm
);
15193 strm
.avail_in
= compressed_size
;
15194 strm
.next_in
= (Bytef
*) compressed_buffer
;
15195 strm
.avail_out
= uncompressed_size
;
15196 uncompressed_buffer
= (unsigned char *) xmalloc (uncompressed_size
);
15198 rc
= inflateInit (& strm
);
15199 while (strm
.avail_in
> 0)
15203 strm
.next_out
= ((Bytef
*) uncompressed_buffer
15204 + (uncompressed_size
- strm
.avail_out
));
15205 rc
= inflate (&strm
, Z_FINISH
);
15206 if (rc
!= Z_STREAM_END
)
15208 rc
= inflateReset (& strm
);
15210 if (inflateEnd (& strm
) != Z_OK
15212 || strm
.avail_out
!= 0)
15215 *buffer
= uncompressed_buffer
;
15216 *size
= uncompressed_size
;
15220 free (uncompressed_buffer
);
15221 /* Indicate decompression failure. */
15227 dump_section_as_strings (Elf_Internal_Shdr
* section
, Filedata
* filedata
)
15229 Elf_Internal_Shdr
*relsec
;
15230 bfd_size_type num_bytes
;
15231 unsigned char *data
;
15232 unsigned char *end
;
15233 unsigned char *real_start
;
15234 unsigned char *start
;
15235 bool some_strings_shown
;
15237 real_start
= start
= (unsigned char *) get_section_contents (section
, filedata
);
15239 /* PR 21820: Do not fail if the section was empty. */
15240 return section
->sh_size
== 0 || section
->sh_type
== SHT_NOBITS
;
15242 num_bytes
= section
->sh_size
;
15244 if (filedata
->is_separate
)
15245 printf (_("\nString dump of section '%s' in linked file %s:\n"),
15246 printable_section_name (filedata
, section
),
15247 filedata
->file_name
);
15249 printf (_("\nString dump of section '%s':\n"),
15250 printable_section_name (filedata
, section
));
15252 if (decompress_dumps
)
15254 dwarf_size_type new_size
= num_bytes
;
15255 dwarf_size_type uncompressed_size
= 0;
15257 if ((section
->sh_flags
& SHF_COMPRESSED
) != 0)
15259 Elf_Internal_Chdr chdr
;
15260 unsigned int compression_header_size
15261 = get_compression_header (& chdr
, (unsigned char *) start
,
15263 if (compression_header_size
== 0)
15264 /* An error message will have already been generated
15265 by get_compression_header. */
15268 if (chdr
.ch_type
!= ELFCOMPRESS_ZLIB
)
15270 warn (_("section '%s' has unsupported compress type: %d\n"),
15271 printable_section_name (filedata
, section
), chdr
.ch_type
);
15274 uncompressed_size
= chdr
.ch_size
;
15275 start
+= compression_header_size
;
15276 new_size
-= compression_header_size
;
15278 else if (new_size
> 12 && streq ((char *) start
, "ZLIB"))
15280 /* Read the zlib header. In this case, it should be "ZLIB"
15281 followed by the uncompressed section size, 8 bytes in
15282 big-endian order. */
15283 uncompressed_size
= start
[4]; uncompressed_size
<<= 8;
15284 uncompressed_size
+= start
[5]; uncompressed_size
<<= 8;
15285 uncompressed_size
+= start
[6]; uncompressed_size
<<= 8;
15286 uncompressed_size
+= start
[7]; uncompressed_size
<<= 8;
15287 uncompressed_size
+= start
[8]; uncompressed_size
<<= 8;
15288 uncompressed_size
+= start
[9]; uncompressed_size
<<= 8;
15289 uncompressed_size
+= start
[10]; uncompressed_size
<<= 8;
15290 uncompressed_size
+= start
[11];
15295 if (uncompressed_size
)
15297 if (uncompress_section_contents (& start
,
15298 uncompressed_size
, & new_size
))
15299 num_bytes
= new_size
;
15302 error (_("Unable to decompress section %s\n"),
15303 printable_section_name (filedata
, section
));
15308 start
= real_start
;
15311 /* If the section being dumped has relocations against it the user might
15312 be expecting these relocations to have been applied. Check for this
15313 case and issue a warning message in order to avoid confusion.
15314 FIXME: Maybe we ought to have an option that dumps a section with
15315 relocs applied ? */
15316 for (relsec
= filedata
->section_headers
;
15317 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
15320 if ((relsec
->sh_type
!= SHT_RELA
&& relsec
->sh_type
!= SHT_REL
)
15321 || relsec
->sh_info
>= filedata
->file_header
.e_shnum
15322 || filedata
->section_headers
+ relsec
->sh_info
!= section
15323 || relsec
->sh_size
== 0
15324 || relsec
->sh_link
>= filedata
->file_header
.e_shnum
)
15327 printf (_(" Note: This section has relocations against it, but these have NOT been applied to this dump.\n"));
15332 end
= start
+ num_bytes
;
15333 some_strings_shown
= false;
15335 #ifdef HAVE_MBSTATE_T
15337 /* Initialise the multibyte conversion state. */
15338 memset (& state
, 0, sizeof (state
));
15341 bool continuing
= false;
15345 while (!ISPRINT (* data
))
15346 if (++ data
>= end
)
15351 size_t maxlen
= end
- data
;
15356 continuing
= false;
15360 printf (" [%6lx] ", (unsigned long) (data
- start
));
15374 /* PR 25543: Treat new-lines as string-ending characters. */
15383 /* Do not print control characters directly as they can affect terminal
15384 settings. Such characters usually appear in the names generated
15385 by the assembler for local labels. */
15388 printf ("^%c", c
+ 0x40);
15390 else if (ISPRINT (c
))
15397 #ifdef HAVE_MBSTATE_T
15400 /* Let printf do the hard work of displaying multibyte characters. */
15401 printf ("%.1s", data
- 1);
15402 #ifdef HAVE_MBSTATE_T
15403 /* Try to find out how many bytes made up the character that was
15404 just printed. Advance the symbol pointer past the bytes that
15406 n
= mbrtowc (& w
, (char *)(data
- 1), MB_CUR_MAX
, & state
);
15410 if (n
!= (size_t) -1 && n
!= (size_t) -2 && n
> 0)
15420 printf (_("<corrupt>\n"));
15423 some_strings_shown
= true;
15427 if (! some_strings_shown
)
15428 printf (_(" No strings found in this section."));
15441 dump_section_as_bytes (Elf_Internal_Shdr
*section
,
15442 Filedata
*filedata
,
15445 Elf_Internal_Shdr
* relsec
;
15446 bfd_size_type bytes
;
15447 bfd_size_type section_size
;
15449 unsigned char * data
;
15450 unsigned char * real_start
;
15451 unsigned char * start
;
15453 real_start
= start
= (unsigned char *) get_section_contents (section
, filedata
);
15455 /* PR 21820: Do not fail if the section was empty. */
15456 return section
->sh_size
== 0 || section
->sh_type
== SHT_NOBITS
;
15458 section_size
= section
->sh_size
;
15460 if (filedata
->is_separate
)
15461 printf (_("\nHex dump of section '%s' in linked file %s:\n"),
15462 printable_section_name (filedata
, section
),
15463 filedata
->file_name
);
15465 printf (_("\nHex dump of section '%s':\n"),
15466 printable_section_name (filedata
, section
));
15468 if (decompress_dumps
)
15470 dwarf_size_type new_size
= section_size
;
15471 dwarf_size_type uncompressed_size
= 0;
15473 if ((section
->sh_flags
& SHF_COMPRESSED
) != 0)
15475 Elf_Internal_Chdr chdr
;
15476 unsigned int compression_header_size
15477 = get_compression_header (& chdr
, start
, section_size
);
15479 if (compression_header_size
== 0)
15480 /* An error message will have already been generated
15481 by get_compression_header. */
15484 if (chdr
.ch_type
!= ELFCOMPRESS_ZLIB
)
15486 warn (_("section '%s' has unsupported compress type: %d\n"),
15487 printable_section_name (filedata
, section
), chdr
.ch_type
);
15490 uncompressed_size
= chdr
.ch_size
;
15491 start
+= compression_header_size
;
15492 new_size
-= compression_header_size
;
15494 else if (new_size
> 12 && streq ((char *) start
, "ZLIB"))
15496 /* Read the zlib header. In this case, it should be "ZLIB"
15497 followed by the uncompressed section size, 8 bytes in
15498 big-endian order. */
15499 uncompressed_size
= start
[4]; uncompressed_size
<<= 8;
15500 uncompressed_size
+= start
[5]; uncompressed_size
<<= 8;
15501 uncompressed_size
+= start
[6]; uncompressed_size
<<= 8;
15502 uncompressed_size
+= start
[7]; uncompressed_size
<<= 8;
15503 uncompressed_size
+= start
[8]; uncompressed_size
<<= 8;
15504 uncompressed_size
+= start
[9]; uncompressed_size
<<= 8;
15505 uncompressed_size
+= start
[10]; uncompressed_size
<<= 8;
15506 uncompressed_size
+= start
[11];
15511 if (uncompressed_size
)
15513 if (uncompress_section_contents (& start
, uncompressed_size
,
15516 section_size
= new_size
;
15520 error (_("Unable to decompress section %s\n"),
15521 printable_section_name (filedata
, section
));
15522 /* FIXME: Print the section anyway ? */
15527 start
= real_start
;
15532 if (! apply_relocations (filedata
, section
, start
, section_size
, NULL
, NULL
))
15537 /* If the section being dumped has relocations against it the user might
15538 be expecting these relocations to have been applied. Check for this
15539 case and issue a warning message in order to avoid confusion.
15540 FIXME: Maybe we ought to have an option that dumps a section with
15541 relocs applied ? */
15542 for (relsec
= filedata
->section_headers
;
15543 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
15546 if ((relsec
->sh_type
!= SHT_RELA
&& relsec
->sh_type
!= SHT_REL
)
15547 || relsec
->sh_info
>= filedata
->file_header
.e_shnum
15548 || filedata
->section_headers
+ relsec
->sh_info
!= section
15549 || relsec
->sh_size
== 0
15550 || relsec
->sh_link
>= filedata
->file_header
.e_shnum
)
15553 printf (_(" NOTE: This section has relocations against it, but these have NOT been applied to this dump.\n"));
15558 addr
= section
->sh_addr
;
15559 bytes
= section_size
;
15568 lbytes
= (bytes
> 16 ? 16 : bytes
);
15570 printf (" 0x%8.8lx ", (unsigned long) addr
);
15572 for (j
= 0; j
< 16; j
++)
15575 printf ("%2.2x", data
[j
]);
15583 for (j
= 0; j
< lbytes
; j
++)
15586 if (k
>= ' ' && k
< 0x7f)
15609 #ifdef ENABLE_LIBCTF
15610 static ctf_sect_t
*
15611 shdr_to_ctf_sect (ctf_sect_t
*buf
, Elf_Internal_Shdr
*shdr
, Filedata
*filedata
)
15613 buf
->cts_name
= section_name_print (filedata
, shdr
);
15614 buf
->cts_size
= shdr
->sh_size
;
15615 buf
->cts_entsize
= shdr
->sh_entsize
;
15620 /* Formatting callback function passed to ctf_dump. Returns either the pointer
15621 it is passed, or a pointer to newly-allocated storage, in which case
15622 dump_ctf() will free it when it no longer needs it. */
15625 dump_ctf_indent_lines (ctf_sect_names_t sect ATTRIBUTE_UNUSED
,
15626 char *s
, void *arg
)
15628 const char *blanks
= arg
;
15631 if (asprintf (&new_s
, "%s%s", blanks
, s
) < 0)
15636 /* Dump CTF errors/warnings. */
15638 dump_ctf_errs (ctf_dict_t
*fp
)
15640 ctf_next_t
*it
= NULL
;
15645 /* Dump accumulated errors and warnings. */
15646 while ((errtext
= ctf_errwarning_next (fp
, &it
, &is_warning
, &err
)) != NULL
)
15648 error (_("%s: %s"), is_warning
? _("warning"): _("error"),
15652 if (err
!= ECTF_NEXT_END
)
15653 error (_("CTF error: cannot get CTF errors: `%s'"), ctf_errmsg (err
));
15656 /* Dump one CTF archive member. */
15659 dump_ctf_archive_member (ctf_dict_t
*ctf
, const char *name
, ctf_dict_t
*parent
,
15662 const char *things
[] = {"Header", "Labels", "Data objects",
15663 "Function objects", "Variables", "Types", "Strings",
15665 const char **thing
;
15668 /* Don't print out the name of the default-named archive member if it appears
15669 first in the list. The name .ctf appears everywhere, even for things that
15670 aren't really archives, so printing it out is liable to be confusing; also,
15671 the common case by far is for only one archive member to exist, and hiding
15672 it in that case seems worthwhile. */
15674 if (strcmp (name
, ".ctf") != 0 || member
!= 0)
15675 printf (_("\nCTF archive member: %s:\n"), name
);
15677 if (ctf_parent_name (ctf
) != NULL
)
15678 ctf_import (ctf
, parent
);
15680 for (i
= 0, thing
= things
; *thing
[0]; thing
++, i
++)
15682 ctf_dump_state_t
*s
= NULL
;
15685 printf ("\n %s:\n", *thing
);
15686 while ((item
= ctf_dump (ctf
, &s
, i
, dump_ctf_indent_lines
,
15687 (void *) " ")) != NULL
)
15689 printf ("%s\n", item
);
15693 if (ctf_errno (ctf
))
15695 error (_("Iteration failed: %s, %s\n"), *thing
,
15696 ctf_errmsg (ctf_errno (ctf
)));
15701 dump_ctf_errs (ctf
);
15705 dump_section_as_ctf (Elf_Internal_Shdr
* section
, Filedata
* filedata
)
15707 Elf_Internal_Shdr
* symtab_sec
= NULL
;
15708 Elf_Internal_Shdr
* strtab_sec
= NULL
;
15709 void * data
= NULL
;
15710 void * symdata
= NULL
;
15711 void * strdata
= NULL
;
15712 ctf_sect_t ctfsect
, symsect
, strsect
;
15713 ctf_sect_t
* symsectp
= NULL
;
15714 ctf_sect_t
* strsectp
= NULL
;
15715 ctf_archive_t
* ctfa
= NULL
;
15716 ctf_dict_t
* parent
= NULL
;
15719 ctf_next_t
*i
= NULL
;
15725 shdr_to_ctf_sect (&ctfsect
, section
, filedata
);
15726 data
= get_section_contents (section
, filedata
);
15727 ctfsect
.cts_data
= data
;
15729 if (!dump_ctf_symtab_name
)
15730 dump_ctf_symtab_name
= strdup (".dynsym");
15732 if (!dump_ctf_strtab_name
)
15733 dump_ctf_strtab_name
= strdup (".dynstr");
15735 if (dump_ctf_symtab_name
&& dump_ctf_symtab_name
[0] != 0)
15737 if ((symtab_sec
= find_section (filedata
, dump_ctf_symtab_name
)) == NULL
)
15739 error (_("No symbol section named %s\n"), dump_ctf_symtab_name
);
15742 if ((symdata
= (void *) get_data (NULL
, filedata
,
15743 symtab_sec
->sh_offset
, 1,
15744 symtab_sec
->sh_size
,
15745 _("symbols"))) == NULL
)
15747 symsectp
= shdr_to_ctf_sect (&symsect
, symtab_sec
, filedata
);
15748 symsect
.cts_data
= symdata
;
15751 if (dump_ctf_strtab_name
&& dump_ctf_strtab_name
[0] != 0)
15753 if ((strtab_sec
= find_section (filedata
, dump_ctf_strtab_name
)) == NULL
)
15755 error (_("No string table section named %s\n"),
15756 dump_ctf_strtab_name
);
15759 if ((strdata
= (void *) get_data (NULL
, filedata
,
15760 strtab_sec
->sh_offset
, 1,
15761 strtab_sec
->sh_size
,
15762 _("strings"))) == NULL
)
15764 strsectp
= shdr_to_ctf_sect (&strsect
, strtab_sec
, filedata
);
15765 strsect
.cts_data
= strdata
;
15768 /* Load the CTF file and dump it. It may be a raw CTF section, or an archive:
15769 libctf papers over the difference, so we can pretend it is always an
15772 if ((ctfa
= ctf_arc_bufopen (&ctfsect
, symsectp
, strsectp
, &err
)) == NULL
)
15774 dump_ctf_errs (NULL
);
15775 error (_("CTF open failure: %s\n"), ctf_errmsg (err
));
15779 ctf_arc_symsect_endianness (ctfa
, filedata
->file_header
.e_ident
[EI_DATA
]
15782 /* Preload the parent dict, since it will need to be imported into every
15784 if ((parent
= ctf_dict_open (ctfa
, dump_ctf_parent_name
, &err
)) == NULL
)
15786 dump_ctf_errs (NULL
);
15787 error (_("CTF open failure: %s\n"), ctf_errmsg (err
));
15793 if (filedata
->is_separate
)
15794 printf (_("\nDump of CTF section '%s' in linked file %s:\n"),
15795 printable_section_name (filedata
, section
),
15796 filedata
->file_name
);
15798 printf (_("\nDump of CTF section '%s':\n"),
15799 printable_section_name (filedata
, section
));
15801 while ((fp
= ctf_archive_next (ctfa
, &i
, &name
, 0, &err
)) != NULL
)
15802 dump_ctf_archive_member (fp
, name
, parent
, member
++);
15803 if (err
!= ECTF_NEXT_END
)
15805 dump_ctf_errs (NULL
);
15806 error (_("CTF member open failure: %s\n"), ctf_errmsg (err
));
15811 ctf_dict_close (parent
);
15821 load_specific_debug_section (enum dwarf_section_display_enum debug
,
15822 const Elf_Internal_Shdr
* sec
,
15825 struct dwarf_section
* section
= &debug_displays
[debug
].section
;
15827 Filedata
* filedata
= (Filedata
*) data
;
15829 if (section
->start
!= NULL
)
15831 /* If it is already loaded, do nothing. */
15832 if (streq (section
->filename
, filedata
->file_name
))
15834 free (section
->start
);
15837 snprintf (buf
, sizeof (buf
), _("%s section data"), section
->name
);
15838 section
->address
= sec
->sh_addr
;
15839 section
->filename
= filedata
->file_name
;
15840 section
->start
= (unsigned char *) get_data (NULL
, filedata
,
15842 sec
->sh_size
, buf
);
15843 if (section
->start
== NULL
)
15847 unsigned char *start
= section
->start
;
15848 dwarf_size_type size
= sec
->sh_size
;
15849 dwarf_size_type uncompressed_size
= 0;
15851 if ((sec
->sh_flags
& SHF_COMPRESSED
) != 0)
15853 Elf_Internal_Chdr chdr
;
15854 unsigned int compression_header_size
;
15856 if (size
< (is_32bit_elf
15857 ? sizeof (Elf32_External_Chdr
)
15858 : sizeof (Elf64_External_Chdr
)))
15860 warn (_("compressed section %s is too small to contain a compression header\n"),
15865 compression_header_size
= get_compression_header (&chdr
, start
, size
);
15866 if (compression_header_size
== 0)
15867 /* An error message will have already been generated
15868 by get_compression_header. */
15871 if (chdr
.ch_type
!= ELFCOMPRESS_ZLIB
)
15873 warn (_("section '%s' has unsupported compress type: %d\n"),
15874 section
->name
, chdr
.ch_type
);
15877 uncompressed_size
= chdr
.ch_size
;
15878 start
+= compression_header_size
;
15879 size
-= compression_header_size
;
15881 else if (size
> 12 && streq ((char *) start
, "ZLIB"))
15883 /* Read the zlib header. In this case, it should be "ZLIB"
15884 followed by the uncompressed section size, 8 bytes in
15885 big-endian order. */
15886 uncompressed_size
= start
[4]; uncompressed_size
<<= 8;
15887 uncompressed_size
+= start
[5]; uncompressed_size
<<= 8;
15888 uncompressed_size
+= start
[6]; uncompressed_size
<<= 8;
15889 uncompressed_size
+= start
[7]; uncompressed_size
<<= 8;
15890 uncompressed_size
+= start
[8]; uncompressed_size
<<= 8;
15891 uncompressed_size
+= start
[9]; uncompressed_size
<<= 8;
15892 uncompressed_size
+= start
[10]; uncompressed_size
<<= 8;
15893 uncompressed_size
+= start
[11];
15898 if (uncompressed_size
)
15900 if (uncompress_section_contents (&start
, uncompressed_size
,
15903 /* Free the compressed buffer, update the section buffer
15904 and the section size if uncompress is successful. */
15905 free (section
->start
);
15906 section
->start
= start
;
15910 error (_("Unable to decompress section %s\n"),
15911 printable_section_name (filedata
, sec
));
15916 section
->size
= size
;
15919 if (section
->start
== NULL
)
15922 if (debug_displays
[debug
].relocate
)
15924 if (! apply_relocations (filedata
, sec
, section
->start
, section
->size
,
15925 & section
->reloc_info
, & section
->num_relocs
))
15930 section
->reloc_info
= NULL
;
15931 section
->num_relocs
= 0;
15937 #if HAVE_LIBDEBUGINFOD
15938 /* Return a hex string representation of the build-id. */
15940 get_build_id (void * data
)
15942 Filedata
* filedata
= (Filedata
*) data
;
15943 Elf_Internal_Shdr
* shdr
;
15946 /* Iterate through notes to find note.gnu.build-id.
15947 FIXME: Only the first note in any note section is examined. */
15948 for (i
= 0, shdr
= filedata
->section_headers
;
15949 i
< filedata
->file_header
.e_shnum
&& shdr
!= NULL
;
15952 if (shdr
->sh_type
!= SHT_NOTE
)
15957 size_t data_remaining
;
15959 Elf_External_Note
* enote
;
15960 Elf_Internal_Note inote
;
15962 bfd_vma offset
= shdr
->sh_offset
;
15963 bfd_vma align
= shdr
->sh_addralign
;
15964 bfd_vma length
= shdr
->sh_size
;
15966 enote
= (Elf_External_Note
*) get_section_contents (shdr
, filedata
);
15972 else if (align
!= 4 && align
!= 8)
15978 end
= (char *) enote
+ length
;
15979 data_remaining
= end
- (char *) enote
;
15981 if (!is_ia64_vms (filedata
))
15983 min_notesz
= offsetof (Elf_External_Note
, name
);
15984 if (data_remaining
< min_notesz
)
15987 malformed note encountered in section %s whilst scanning for build-id note\n"),
15988 printable_section_name (filedata
, shdr
));
15992 data_remaining
-= min_notesz
;
15994 inote
.type
= BYTE_GET (enote
->type
);
15995 inote
.namesz
= BYTE_GET (enote
->namesz
);
15996 inote
.namedata
= enote
->name
;
15997 inote
.descsz
= BYTE_GET (enote
->descsz
);
15998 inote
.descdata
= ((char *) enote
15999 + ELF_NOTE_DESC_OFFSET (inote
.namesz
, align
));
16000 inote
.descpos
= offset
+ (inote
.descdata
- (char *) enote
);
16001 next
= ((char *) enote
16002 + ELF_NOTE_NEXT_OFFSET (inote
.namesz
, inote
.descsz
, align
));
16006 Elf64_External_VMS_Note
*vms_enote
;
16008 /* PR binutils/15191
16009 Make sure that there is enough data to read. */
16010 min_notesz
= offsetof (Elf64_External_VMS_Note
, name
);
16011 if (data_remaining
< min_notesz
)
16014 malformed note encountered in section %s whilst scanning for build-id note\n"),
16015 printable_section_name (filedata
, shdr
));
16019 data_remaining
-= min_notesz
;
16021 vms_enote
= (Elf64_External_VMS_Note
*) enote
;
16022 inote
.type
= BYTE_GET (vms_enote
->type
);
16023 inote
.namesz
= BYTE_GET (vms_enote
->namesz
);
16024 inote
.namedata
= vms_enote
->name
;
16025 inote
.descsz
= BYTE_GET (vms_enote
->descsz
);
16026 inote
.descdata
= inote
.namedata
+ align_power (inote
.namesz
, 3);
16027 inote
.descpos
= offset
+ (inote
.descdata
- (char *) enote
);
16028 next
= inote
.descdata
+ align_power (inote
.descsz
, 3);
16031 /* Skip malformed notes. */
16032 if ((size_t) (inote
.descdata
- inote
.namedata
) < inote
.namesz
16033 || (size_t) (inote
.descdata
- inote
.namedata
) > data_remaining
16034 || (size_t) (next
- inote
.descdata
) < inote
.descsz
16035 || ((size_t) (next
- inote
.descdata
)
16036 > data_remaining
- (size_t) (inote
.descdata
- inote
.namedata
)))
16039 malformed note encountered in section %s whilst scanning for build-id note\n"),
16040 printable_section_name (filedata
, shdr
));
16045 /* Check if this is the build-id note. If so then convert the build-id
16046 bytes to a hex string. */
16047 if (inote
.namesz
> 0
16048 && startswith (inote
.namedata
, "GNU")
16049 && inote
.type
== NT_GNU_BUILD_ID
)
16054 build_id
= malloc (inote
.descsz
* 2 + 1);
16055 if (build_id
== NULL
)
16061 for (j
= 0; j
< inote
.descsz
; ++j
)
16062 sprintf (build_id
+ (j
* 2), "%02x", inote
.descdata
[j
] & 0xff);
16063 build_id
[inote
.descsz
* 2] = '\0';
16066 return (unsigned char *) build_id
;
16073 #endif /* HAVE_LIBDEBUGINFOD */
16075 /* If this is not NULL, load_debug_section will only look for sections
16076 within the list of sections given here. */
16077 static unsigned int * section_subset
= NULL
;
16080 load_debug_section (enum dwarf_section_display_enum debug
, void * data
)
16082 struct dwarf_section
* section
= &debug_displays
[debug
].section
;
16083 Elf_Internal_Shdr
* sec
;
16084 Filedata
* filedata
= (Filedata
*) data
;
16086 if (!dump_any_debugging
)
16089 /* Without section headers we cannot find any sections. */
16090 if (filedata
->section_headers
== NULL
)
16093 if (filedata
->string_table
== NULL
16094 && filedata
->file_header
.e_shstrndx
!= SHN_UNDEF
16095 && filedata
->file_header
.e_shstrndx
< filedata
->file_header
.e_shnum
)
16097 Elf_Internal_Shdr
* strs
;
16099 /* Read in the string table, so that we have section names to scan. */
16100 strs
= filedata
->section_headers
+ filedata
->file_header
.e_shstrndx
;
16102 if (strs
!= NULL
&& strs
->sh_size
!= 0)
16104 filedata
->string_table
16105 = (char *) get_data (NULL
, filedata
, strs
->sh_offset
,
16106 1, strs
->sh_size
, _("string table"));
16108 filedata
->string_table_length
16109 = filedata
->string_table
!= NULL
? strs
->sh_size
: 0;
16113 /* Locate the debug section. */
16114 sec
= find_section_in_set (filedata
, section
->uncompressed_name
, section_subset
);
16116 section
->name
= section
->uncompressed_name
;
16119 sec
= find_section_in_set (filedata
, section
->compressed_name
, section_subset
);
16121 section
->name
= section
->compressed_name
;
16126 /* If we're loading from a subset of sections, and we've loaded
16127 a section matching this name before, it's likely that it's a
16129 if (section_subset
!= NULL
)
16130 free_debug_section (debug
);
16132 return load_specific_debug_section (debug
, sec
, data
);
16136 free_debug_section (enum dwarf_section_display_enum debug
)
16138 struct dwarf_section
* section
= &debug_displays
[debug
].section
;
16140 if (section
->start
== NULL
)
16143 free ((char *) section
->start
);
16144 section
->start
= NULL
;
16145 section
->address
= 0;
16148 free (section
->reloc_info
);
16149 section
->reloc_info
= NULL
;
16150 section
->num_relocs
= 0;
16154 display_debug_section (int shndx
, Elf_Internal_Shdr
* section
, Filedata
* filedata
)
16156 const char *name
= (section_name_valid (filedata
, section
)
16157 ? section_name (filedata
, section
) : "");
16158 const char *print_name
= printable_section_name (filedata
, section
);
16159 bfd_size_type length
;
16160 bool result
= true;
16163 length
= section
->sh_size
;
16166 printf (_("\nSection '%s' has no debugging data.\n"), print_name
);
16169 if (section
->sh_type
== SHT_NOBITS
)
16171 /* There is no point in dumping the contents of a debugging section
16172 which has the NOBITS type - the bits in the file will be random.
16173 This can happen when a file containing a .eh_frame section is
16174 stripped with the --only-keep-debug command line option. */
16175 printf (_("section '%s' has the NOBITS type - its contents are unreliable.\n"),
16180 if (startswith (name
, ".gnu.linkonce.wi."))
16181 name
= ".debug_info";
16183 /* See if we know how to display the contents of this section. */
16184 for (i
= 0; i
< max
; i
++)
16186 enum dwarf_section_display_enum id
= (enum dwarf_section_display_enum
) i
;
16187 struct dwarf_section_display
* display
= debug_displays
+ i
;
16188 struct dwarf_section
* sec
= & display
->section
;
16190 if (streq (sec
->uncompressed_name
, name
)
16191 || (id
== line
&& startswith (name
, ".debug_line."))
16192 || streq (sec
->compressed_name
, name
))
16194 bool secondary
= (section
!= find_section (filedata
, name
));
16197 free_debug_section (id
);
16199 if (i
== line
&& startswith (name
, ".debug_line."))
16201 else if (streq (sec
->uncompressed_name
, name
))
16202 sec
->name
= sec
->uncompressed_name
;
16204 sec
->name
= sec
->compressed_name
;
16206 if (load_specific_debug_section (id
, section
, filedata
))
16208 /* If this debug section is part of a CU/TU set in a .dwp file,
16209 restrict load_debug_section to the sections in that set. */
16210 section_subset
= find_cu_tu_set (filedata
, shndx
);
16212 result
&= display
->display (sec
, filedata
);
16214 section_subset
= NULL
;
16216 if (secondary
|| (id
!= info
&& id
!= abbrev
&& id
!= debug_addr
))
16217 free_debug_section (id
);
16225 printf (_("Unrecognized debug section: %s\n"), print_name
);
16232 /* Set DUMP_SECTS for all sections where dumps were requested
16233 based on section name. */
16236 initialise_dumps_byname (Filedata
* filedata
)
16238 struct dump_list_entry
* cur
;
16240 for (cur
= dump_sects_byname
; cur
; cur
= cur
->next
)
16245 for (i
= 0; i
< filedata
->file_header
.e_shnum
; i
++)
16246 if (section_name_valid (filedata
, filedata
->section_headers
+ i
)
16247 && streq (section_name (filedata
, filedata
->section_headers
+ i
),
16250 request_dump_bynumber (&filedata
->dump
, i
, cur
->type
);
16254 if (!any
&& !filedata
->is_separate
)
16255 warn (_("Section '%s' was not dumped because it does not exist\n"),
16261 process_section_contents (Filedata
* filedata
)
16263 Elf_Internal_Shdr
* section
;
16270 initialise_dumps_byname (filedata
);
16272 for (i
= 0, section
= filedata
->section_headers
;
16273 i
< filedata
->file_header
.e_shnum
&& i
< filedata
->dump
.num_dump_sects
;
16276 dump_type dump
= filedata
->dump
.dump_sects
[i
];
16278 if (filedata
->is_separate
&& ! process_links
)
16279 dump
&= DEBUG_DUMP
;
16281 #ifdef SUPPORT_DISASSEMBLY
16282 if (dump
& DISASS_DUMP
)
16284 if (! disassemble_section (section
, filedata
))
16288 if (dump
& HEX_DUMP
)
16290 if (! dump_section_as_bytes (section
, filedata
, false))
16294 if (dump
& RELOC_DUMP
)
16296 if (! dump_section_as_bytes (section
, filedata
, true))
16300 if (dump
& STRING_DUMP
)
16302 if (! dump_section_as_strings (section
, filedata
))
16306 if (dump
& DEBUG_DUMP
)
16308 if (! display_debug_section (i
, section
, filedata
))
16312 #ifdef ENABLE_LIBCTF
16313 if (dump
& CTF_DUMP
)
16315 if (! dump_section_as_ctf (section
, filedata
))
16321 if (! filedata
->is_separate
)
16323 /* Check to see if the user requested a
16324 dump of a section that does not exist. */
16325 for (; i
< filedata
->dump
.num_dump_sects
; i
++)
16326 if (filedata
->dump
.dump_sects
[i
])
16328 warn (_("Section %d was not dumped because it does not exist!\n"), i
);
16337 process_mips_fpe_exception (int mask
)
16343 if (mask
& OEX_FPU_INEX
)
16344 fputs ("INEX", stdout
), first
= false;
16345 if (mask
& OEX_FPU_UFLO
)
16346 printf ("%sUFLO", first
? "" : "|"), first
= false;
16347 if (mask
& OEX_FPU_OFLO
)
16348 printf ("%sOFLO", first
? "" : "|"), first
= false;
16349 if (mask
& OEX_FPU_DIV0
)
16350 printf ("%sDIV0", first
? "" : "|"), first
= false;
16351 if (mask
& OEX_FPU_INVAL
)
16352 printf ("%sINVAL", first
? "" : "|");
16355 fputs ("0", stdout
);
16358 /* Display's the value of TAG at location P. If TAG is
16359 greater than 0 it is assumed to be an unknown tag, and
16360 a message is printed to this effect. Otherwise it is
16361 assumed that a message has already been printed.
16363 If the bottom bit of TAG is set it assumed to have a
16364 string value, otherwise it is assumed to have an integer
16367 Returns an updated P pointing to the first unread byte
16368 beyond the end of TAG's value.
16370 Reads at or beyond END will not be made. */
16372 static unsigned char *
16373 display_tag_value (signed int tag
,
16375 const unsigned char * const end
)
16380 printf (" Tag_unknown_%d: ", tag
);
16384 warn (_("<corrupt tag>\n"));
16388 /* PR 17531 file: 027-19978-0.004. */
16389 size_t maxlen
= (end
- p
) - 1;
16394 print_symbol ((int) maxlen
, (const char *) p
);
16395 p
+= strnlen ((char *) p
, maxlen
) + 1;
16399 printf (_("<corrupt string tag>"));
16400 p
= (unsigned char *) end
;
16406 READ_ULEB (val
, p
, end
);
16407 printf ("%ld (0x%lx)\n", val
, val
);
16414 /* ARC ABI attributes section. */
16416 static unsigned char *
16417 display_arc_attribute (unsigned char * p
,
16418 const unsigned char * const end
)
16423 READ_ULEB (tag
, p
, end
);
16427 case Tag_ARC_PCS_config
:
16428 READ_ULEB (val
, p
, end
);
16429 printf (" Tag_ARC_PCS_config: ");
16433 printf (_("Absent/Non standard\n"));
16436 printf (_("Bare metal/mwdt\n"));
16439 printf (_("Bare metal/newlib\n"));
16442 printf (_("Linux/uclibc\n"));
16445 printf (_("Linux/glibc\n"));
16448 printf (_("Unknown\n"));
16453 case Tag_ARC_CPU_base
:
16454 READ_ULEB (val
, p
, end
);
16455 printf (" Tag_ARC_CPU_base: ");
16460 printf (_("Absent\n"));
16462 case TAG_CPU_ARC6xx
:
16463 printf ("ARC6xx\n");
16465 case TAG_CPU_ARC7xx
:
16466 printf ("ARC7xx\n");
16468 case TAG_CPU_ARCEM
:
16469 printf ("ARCEM\n");
16471 case TAG_CPU_ARCHS
:
16472 printf ("ARCHS\n");
16477 case Tag_ARC_CPU_variation
:
16478 READ_ULEB (val
, p
, end
);
16479 printf (" Tag_ARC_CPU_variation: ");
16483 if (val
> 0 && val
< 16)
16484 printf ("Core%d\n", val
);
16486 printf ("Unknown\n");
16490 printf (_("Absent\n"));
16495 case Tag_ARC_CPU_name
:
16496 printf (" Tag_ARC_CPU_name: ");
16497 p
= display_tag_value (-1, p
, end
);
16500 case Tag_ARC_ABI_rf16
:
16501 READ_ULEB (val
, p
, end
);
16502 printf (" Tag_ARC_ABI_rf16: %s\n", val
? _("yes") : _("no"));
16505 case Tag_ARC_ABI_osver
:
16506 READ_ULEB (val
, p
, end
);
16507 printf (" Tag_ARC_ABI_osver: v%d\n", val
);
16510 case Tag_ARC_ABI_pic
:
16511 case Tag_ARC_ABI_sda
:
16512 READ_ULEB (val
, p
, end
);
16513 printf (tag
== Tag_ARC_ABI_sda
? " Tag_ARC_ABI_sda: "
16514 : " Tag_ARC_ABI_pic: ");
16518 printf (_("Absent\n"));
16527 printf (_("Unknown\n"));
16532 case Tag_ARC_ABI_tls
:
16533 READ_ULEB (val
, p
, end
);
16534 printf (" Tag_ARC_ABI_tls: %s\n", val
? "r25": "none");
16537 case Tag_ARC_ABI_enumsize
:
16538 READ_ULEB (val
, p
, end
);
16539 printf (" Tag_ARC_ABI_enumsize: %s\n", val
? _("default") :
16543 case Tag_ARC_ABI_exceptions
:
16544 READ_ULEB (val
, p
, end
);
16545 printf (" Tag_ARC_ABI_exceptions: %s\n", val
? _("OPTFP")
16549 case Tag_ARC_ABI_double_size
:
16550 READ_ULEB (val
, p
, end
);
16551 printf (" Tag_ARC_ABI_double_size: %d\n", val
);
16554 case Tag_ARC_ISA_config
:
16555 printf (" Tag_ARC_ISA_config: ");
16556 p
= display_tag_value (-1, p
, end
);
16559 case Tag_ARC_ISA_apex
:
16560 printf (" Tag_ARC_ISA_apex: ");
16561 p
= display_tag_value (-1, p
, end
);
16564 case Tag_ARC_ISA_mpy_option
:
16565 READ_ULEB (val
, p
, end
);
16566 printf (" Tag_ARC_ISA_mpy_option: %d\n", val
);
16569 case Tag_ARC_ATR_version
:
16570 READ_ULEB (val
, p
, end
);
16571 printf (" Tag_ARC_ATR_version: %d\n", val
);
16575 return display_tag_value (tag
& 1, p
, end
);
16581 /* ARM EABI attributes section. */
16586 /* 0 = special, 1 = string, 2 = uleb123, > 0x80 == table lookup. */
16588 const char *const *table
;
16589 } arm_attr_public_tag
;
16591 static const char *const arm_attr_tag_CPU_arch
[] =
16592 {"Pre-v4", "v4", "v4T", "v5T", "v5TE", "v5TEJ", "v6", "v6KZ", "v6T2",
16593 "v6K", "v7", "v6-M", "v6S-M", "v7E-M", "v8", "v8-R", "v8-M.baseline",
16594 "v8-M.mainline", "v8.1-A", "v8.2-A", "v8.3-A",
16595 "v8.1-M.mainline", "v9"};
16596 static const char *const arm_attr_tag_ARM_ISA_use
[] = {"No", "Yes"};
16597 static const char *const arm_attr_tag_THUMB_ISA_use
[] =
16598 {"No", "Thumb-1", "Thumb-2", "Yes"};
16599 static const char *const arm_attr_tag_FP_arch
[] =
16600 {"No", "VFPv1", "VFPv2", "VFPv3", "VFPv3-D16", "VFPv4", "VFPv4-D16",
16601 "FP for ARMv8", "FPv5/FP-D16 for ARMv8"};
16602 static const char *const arm_attr_tag_WMMX_arch
[] = {"No", "WMMXv1", "WMMXv2"};
16603 static const char *const arm_attr_tag_Advanced_SIMD_arch
[] =
16604 {"No", "NEONv1", "NEONv1 with Fused-MAC", "NEON for ARMv8",
16605 "NEON for ARMv8.1"};
16606 static const char *const arm_attr_tag_PCS_config
[] =
16607 {"None", "Bare platform", "Linux application", "Linux DSO", "PalmOS 2004",
16608 "PalmOS (reserved)", "SymbianOS 2004", "SymbianOS (reserved)"};
16609 static const char *const arm_attr_tag_ABI_PCS_R9_use
[] =
16610 {"V6", "SB", "TLS", "Unused"};
16611 static const char *const arm_attr_tag_ABI_PCS_RW_data
[] =
16612 {"Absolute", "PC-relative", "SB-relative", "None"};
16613 static const char *const arm_attr_tag_ABI_PCS_RO_data
[] =
16614 {"Absolute", "PC-relative", "None"};
16615 static const char *const arm_attr_tag_ABI_PCS_GOT_use
[] =
16616 {"None", "direct", "GOT-indirect"};
16617 static const char *const arm_attr_tag_ABI_PCS_wchar_t
[] =
16618 {"None", "??? 1", "2", "??? 3", "4"};
16619 static const char *const arm_attr_tag_ABI_FP_rounding
[] = {"Unused", "Needed"};
16620 static const char *const arm_attr_tag_ABI_FP_denormal
[] =
16621 {"Unused", "Needed", "Sign only"};
16622 static const char *const arm_attr_tag_ABI_FP_exceptions
[] = {"Unused", "Needed"};
16623 static const char *const arm_attr_tag_ABI_FP_user_exceptions
[] = {"Unused", "Needed"};
16624 static const char *const arm_attr_tag_ABI_FP_number_model
[] =
16625 {"Unused", "Finite", "RTABI", "IEEE 754"};
16626 static const char *const arm_attr_tag_ABI_enum_size
[] =
16627 {"Unused", "small", "int", "forced to int"};
16628 static const char *const arm_attr_tag_ABI_HardFP_use
[] =
16629 {"As Tag_FP_arch", "SP only", "Reserved", "Deprecated"};
16630 static const char *const arm_attr_tag_ABI_VFP_args
[] =
16631 {"AAPCS", "VFP registers", "custom", "compatible"};
16632 static const char *const arm_attr_tag_ABI_WMMX_args
[] =
16633 {"AAPCS", "WMMX registers", "custom"};
16634 static const char *const arm_attr_tag_ABI_optimization_goals
[] =
16635 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
16636 "Aggressive Size", "Prefer Debug", "Aggressive Debug"};
16637 static const char *const arm_attr_tag_ABI_FP_optimization_goals
[] =
16638 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
16639 "Aggressive Size", "Prefer Accuracy", "Aggressive Accuracy"};
16640 static const char *const arm_attr_tag_CPU_unaligned_access
[] = {"None", "v6"};
16641 static const char *const arm_attr_tag_FP_HP_extension
[] =
16642 {"Not Allowed", "Allowed"};
16643 static const char *const arm_attr_tag_ABI_FP_16bit_format
[] =
16644 {"None", "IEEE 754", "Alternative Format"};
16645 static const char *const arm_attr_tag_DSP_extension
[] =
16646 {"Follow architecture", "Allowed"};
16647 static const char *const arm_attr_tag_MPextension_use
[] =
16648 {"Not Allowed", "Allowed"};
16649 static const char *const arm_attr_tag_DIV_use
[] =
16650 {"Allowed in Thumb-ISA, v7-R or v7-M", "Not allowed",
16651 "Allowed in v7-A with integer division extension"};
16652 static const char *const arm_attr_tag_T2EE_use
[] = {"Not Allowed", "Allowed"};
16653 static const char *const arm_attr_tag_Virtualization_use
[] =
16654 {"Not Allowed", "TrustZone", "Virtualization Extensions",
16655 "TrustZone and Virtualization Extensions"};
16656 static const char *const arm_attr_tag_MPextension_use_legacy
[] =
16657 {"Not Allowed", "Allowed"};
16659 static const char *const arm_attr_tag_MVE_arch
[] =
16660 {"No MVE", "MVE Integer only", "MVE Integer and FP"};
16662 static const char * arm_attr_tag_PAC_extension
[] =
16663 {"No PAC/AUT instructions",
16664 "PAC/AUT instructions permitted in the NOP space",
16665 "PAC/AUT instructions permitted in the NOP and in the non-NOP space"};
16667 static const char * arm_attr_tag_BTI_extension
[] =
16668 {"BTI instructions not permitted",
16669 "BTI instructions permitted in the NOP space",
16670 "BTI instructions permitted in the NOP and in the non-NOP space"};
16672 static const char * arm_attr_tag_BTI_use
[] =
16673 {"Compiled without branch target enforcement",
16674 "Compiled with branch target enforcement"};
16676 static const char * arm_attr_tag_PACRET_use
[] =
16677 {"Compiled without return address signing and authentication",
16678 "Compiled with return address signing and authentication"};
16680 #define LOOKUP(id, name) \
16681 {id, #name, 0x80 | ARRAY_SIZE(arm_attr_tag_##name), arm_attr_tag_##name}
16682 static arm_attr_public_tag arm_attr_public_tags
[] =
16684 {4, "CPU_raw_name", 1, NULL
},
16685 {5, "CPU_name", 1, NULL
},
16686 LOOKUP(6, CPU_arch
),
16687 {7, "CPU_arch_profile", 0, NULL
},
16688 LOOKUP(8, ARM_ISA_use
),
16689 LOOKUP(9, THUMB_ISA_use
),
16690 LOOKUP(10, FP_arch
),
16691 LOOKUP(11, WMMX_arch
),
16692 LOOKUP(12, Advanced_SIMD_arch
),
16693 LOOKUP(13, PCS_config
),
16694 LOOKUP(14, ABI_PCS_R9_use
),
16695 LOOKUP(15, ABI_PCS_RW_data
),
16696 LOOKUP(16, ABI_PCS_RO_data
),
16697 LOOKUP(17, ABI_PCS_GOT_use
),
16698 LOOKUP(18, ABI_PCS_wchar_t
),
16699 LOOKUP(19, ABI_FP_rounding
),
16700 LOOKUP(20, ABI_FP_denormal
),
16701 LOOKUP(21, ABI_FP_exceptions
),
16702 LOOKUP(22, ABI_FP_user_exceptions
),
16703 LOOKUP(23, ABI_FP_number_model
),
16704 {24, "ABI_align_needed", 0, NULL
},
16705 {25, "ABI_align_preserved", 0, NULL
},
16706 LOOKUP(26, ABI_enum_size
),
16707 LOOKUP(27, ABI_HardFP_use
),
16708 LOOKUP(28, ABI_VFP_args
),
16709 LOOKUP(29, ABI_WMMX_args
),
16710 LOOKUP(30, ABI_optimization_goals
),
16711 LOOKUP(31, ABI_FP_optimization_goals
),
16712 {32, "compatibility", 0, NULL
},
16713 LOOKUP(34, CPU_unaligned_access
),
16714 LOOKUP(36, FP_HP_extension
),
16715 LOOKUP(38, ABI_FP_16bit_format
),
16716 LOOKUP(42, MPextension_use
),
16717 LOOKUP(44, DIV_use
),
16718 LOOKUP(46, DSP_extension
),
16719 LOOKUP(48, MVE_arch
),
16720 LOOKUP(50, PAC_extension
),
16721 LOOKUP(52, BTI_extension
),
16722 LOOKUP(74, BTI_use
),
16723 LOOKUP(76, PACRET_use
),
16724 {64, "nodefaults", 0, NULL
},
16725 {65, "also_compatible_with", 0, NULL
},
16726 LOOKUP(66, T2EE_use
),
16727 {67, "conformance", 1, NULL
},
16728 LOOKUP(68, Virtualization_use
),
16729 LOOKUP(70, MPextension_use_legacy
)
16733 static unsigned char *
16734 display_arm_attribute (unsigned char * p
,
16735 const unsigned char * const end
)
16739 arm_attr_public_tag
* attr
;
16743 READ_ULEB (tag
, p
, end
);
16745 for (i
= 0; i
< ARRAY_SIZE (arm_attr_public_tags
); i
++)
16747 if (arm_attr_public_tags
[i
].tag
== tag
)
16749 attr
= &arm_attr_public_tags
[i
];
16756 printf (" Tag_%s: ", attr
->name
);
16757 switch (attr
->type
)
16762 case 7: /* Tag_CPU_arch_profile. */
16763 READ_ULEB (val
, p
, end
);
16766 case 0: printf (_("None\n")); break;
16767 case 'A': printf (_("Application\n")); break;
16768 case 'R': printf (_("Realtime\n")); break;
16769 case 'M': printf (_("Microcontroller\n")); break;
16770 case 'S': printf (_("Application or Realtime\n")); break;
16771 default: printf ("??? (%d)\n", val
); break;
16775 case 24: /* Tag_align_needed. */
16776 READ_ULEB (val
, p
, end
);
16779 case 0: printf (_("None\n")); break;
16780 case 1: printf (_("8-byte\n")); break;
16781 case 2: printf (_("4-byte\n")); break;
16782 case 3: printf ("??? 3\n"); break;
16785 printf (_("8-byte and up to %d-byte extended\n"),
16788 printf ("??? (%d)\n", val
);
16793 case 25: /* Tag_align_preserved. */
16794 READ_ULEB (val
, p
, end
);
16797 case 0: printf (_("None\n")); break;
16798 case 1: printf (_("8-byte, except leaf SP\n")); break;
16799 case 2: printf (_("8-byte\n")); break;
16800 case 3: printf ("??? 3\n"); break;
16803 printf (_("8-byte and up to %d-byte extended\n"),
16806 printf ("??? (%d)\n", val
);
16811 case 32: /* Tag_compatibility. */
16813 READ_ULEB (val
, p
, end
);
16814 printf (_("flag = %d, vendor = "), val
);
16817 size_t maxlen
= (end
- p
) - 1;
16819 print_symbol ((int) maxlen
, (const char *) p
);
16820 p
+= strnlen ((char *) p
, maxlen
) + 1;
16824 printf (_("<corrupt>"));
16825 p
= (unsigned char *) end
;
16831 case 64: /* Tag_nodefaults. */
16832 /* PR 17531: file: 001-505008-0.01. */
16835 printf (_("True\n"));
16838 case 65: /* Tag_also_compatible_with. */
16839 READ_ULEB (val
, p
, end
);
16840 if (val
== 6 /* Tag_CPU_arch. */)
16842 READ_ULEB (val
, p
, end
);
16843 if ((unsigned int) val
>= ARRAY_SIZE (arm_attr_tag_CPU_arch
))
16844 printf ("??? (%d)\n", val
);
16846 printf ("%s\n", arm_attr_tag_CPU_arch
[val
]);
16850 while (p
< end
&& *(p
++) != '\0' /* NUL terminator. */)
16855 printf (_("<unknown: %d>\n"), tag
);
16861 return display_tag_value (-1, p
, end
);
16863 return display_tag_value (0, p
, end
);
16866 assert (attr
->type
& 0x80);
16867 READ_ULEB (val
, p
, end
);
16868 type
= attr
->type
& 0x7f;
16870 printf ("??? (%d)\n", val
);
16872 printf ("%s\n", attr
->table
[val
]);
16877 return display_tag_value (tag
, p
, end
);
16880 static unsigned char *
16881 display_gnu_attribute (unsigned char * p
,
16882 unsigned char * (* display_proc_gnu_attribute
) (unsigned char *, unsigned int, const unsigned char * const),
16883 const unsigned char * const end
)
16888 READ_ULEB (tag
, p
, end
);
16890 /* Tag_compatibility is the only generic GNU attribute defined at
16894 READ_ULEB (val
, p
, end
);
16896 printf (_("flag = %d, vendor = "), val
);
16899 printf (_("<corrupt>\n"));
16900 warn (_("corrupt vendor attribute\n"));
16906 size_t maxlen
= (end
- p
) - 1;
16908 print_symbol ((int) maxlen
, (const char *) p
);
16909 p
+= strnlen ((char *) p
, maxlen
) + 1;
16913 printf (_("<corrupt>"));
16914 p
= (unsigned char *) end
;
16921 if ((tag
& 2) == 0 && display_proc_gnu_attribute
)
16922 return display_proc_gnu_attribute (p
, tag
, end
);
16924 return display_tag_value (tag
, p
, end
);
16927 static unsigned char *
16928 display_m68k_gnu_attribute (unsigned char * p
,
16930 const unsigned char * const end
)
16934 if (tag
== Tag_GNU_M68K_ABI_FP
)
16936 printf (" Tag_GNU_M68K_ABI_FP: ");
16939 printf (_("<corrupt>\n"));
16942 READ_ULEB (val
, p
, end
);
16945 printf ("(%#x), ", val
);
16950 printf (_("unspecified hard/soft float\n"));
16953 printf (_("hard float\n"));
16956 printf (_("soft float\n"));
16962 return display_tag_value (tag
& 1, p
, end
);
16965 static unsigned char *
16966 display_power_gnu_attribute (unsigned char * p
,
16968 const unsigned char * const end
)
16972 if (tag
== Tag_GNU_Power_ABI_FP
)
16974 printf (" Tag_GNU_Power_ABI_FP: ");
16977 printf (_("<corrupt>\n"));
16980 READ_ULEB (val
, p
, end
);
16983 printf ("(%#x), ", val
);
16988 printf (_("unspecified hard/soft float, "));
16991 printf (_("hard float, "));
16994 printf (_("soft float, "));
16997 printf (_("single-precision hard float, "));
17004 printf (_("unspecified long double\n"));
17007 printf (_("128-bit IBM long double\n"));
17010 printf (_("64-bit long double\n"));
17013 printf (_("128-bit IEEE long double\n"));
17019 if (tag
== Tag_GNU_Power_ABI_Vector
)
17021 printf (" Tag_GNU_Power_ABI_Vector: ");
17024 printf (_("<corrupt>\n"));
17027 READ_ULEB (val
, p
, end
);
17030 printf ("(%#x), ", val
);
17035 printf (_("unspecified\n"));
17038 printf (_("generic\n"));
17041 printf ("AltiVec\n");
17050 if (tag
== Tag_GNU_Power_ABI_Struct_Return
)
17052 printf (" Tag_GNU_Power_ABI_Struct_Return: ");
17055 printf (_("<corrupt>\n"));
17058 READ_ULEB (val
, p
, end
);
17061 printf ("(%#x), ", val
);
17066 printf (_("unspecified\n"));
17069 printf ("r3/r4\n");
17072 printf (_("memory\n"));
17081 return display_tag_value (tag
& 1, p
, end
);
17084 static unsigned char *
17085 display_s390_gnu_attribute (unsigned char * p
,
17087 const unsigned char * const end
)
17091 if (tag
== Tag_GNU_S390_ABI_Vector
)
17093 printf (" Tag_GNU_S390_ABI_Vector: ");
17094 READ_ULEB (val
, p
, end
);
17099 printf (_("any\n"));
17102 printf (_("software\n"));
17105 printf (_("hardware\n"));
17108 printf ("??? (%d)\n", val
);
17114 return display_tag_value (tag
& 1, p
, end
);
17118 display_sparc_hwcaps (unsigned int mask
)
17124 if (mask
& ELF_SPARC_HWCAP_MUL32
)
17125 fputs ("mul32", stdout
), first
= false;
17126 if (mask
& ELF_SPARC_HWCAP_DIV32
)
17127 printf ("%sdiv32", first
? "" : "|"), first
= false;
17128 if (mask
& ELF_SPARC_HWCAP_FSMULD
)
17129 printf ("%sfsmuld", first
? "" : "|"), first
= false;
17130 if (mask
& ELF_SPARC_HWCAP_V8PLUS
)
17131 printf ("%sv8plus", first
? "" : "|"), first
= false;
17132 if (mask
& ELF_SPARC_HWCAP_POPC
)
17133 printf ("%spopc", first
? "" : "|"), first
= false;
17134 if (mask
& ELF_SPARC_HWCAP_VIS
)
17135 printf ("%svis", first
? "" : "|"), first
= false;
17136 if (mask
& ELF_SPARC_HWCAP_VIS2
)
17137 printf ("%svis2", first
? "" : "|"), first
= false;
17138 if (mask
& ELF_SPARC_HWCAP_ASI_BLK_INIT
)
17139 printf ("%sASIBlkInit", first
? "" : "|"), first
= false;
17140 if (mask
& ELF_SPARC_HWCAP_FMAF
)
17141 printf ("%sfmaf", first
? "" : "|"), first
= false;
17142 if (mask
& ELF_SPARC_HWCAP_VIS3
)
17143 printf ("%svis3", first
? "" : "|"), first
= false;
17144 if (mask
& ELF_SPARC_HWCAP_HPC
)
17145 printf ("%shpc", first
? "" : "|"), first
= false;
17146 if (mask
& ELF_SPARC_HWCAP_RANDOM
)
17147 printf ("%srandom", first
? "" : "|"), first
= false;
17148 if (mask
& ELF_SPARC_HWCAP_TRANS
)
17149 printf ("%strans", first
? "" : "|"), first
= false;
17150 if (mask
& ELF_SPARC_HWCAP_FJFMAU
)
17151 printf ("%sfjfmau", first
? "" : "|"), first
= false;
17152 if (mask
& ELF_SPARC_HWCAP_IMA
)
17153 printf ("%sima", first
? "" : "|"), first
= false;
17154 if (mask
& ELF_SPARC_HWCAP_ASI_CACHE_SPARING
)
17155 printf ("%scspare", first
? "" : "|"), first
= false;
17158 fputc ('0', stdout
);
17159 fputc ('\n', stdout
);
17163 display_sparc_hwcaps2 (unsigned int mask
)
17169 if (mask
& ELF_SPARC_HWCAP2_FJATHPLUS
)
17170 fputs ("fjathplus", stdout
), first
= false;
17171 if (mask
& ELF_SPARC_HWCAP2_VIS3B
)
17172 printf ("%svis3b", first
? "" : "|"), first
= false;
17173 if (mask
& ELF_SPARC_HWCAP2_ADP
)
17174 printf ("%sadp", first
? "" : "|"), first
= false;
17175 if (mask
& ELF_SPARC_HWCAP2_SPARC5
)
17176 printf ("%ssparc5", first
? "" : "|"), first
= false;
17177 if (mask
& ELF_SPARC_HWCAP2_MWAIT
)
17178 printf ("%smwait", first
? "" : "|"), first
= false;
17179 if (mask
& ELF_SPARC_HWCAP2_XMPMUL
)
17180 printf ("%sxmpmul", first
? "" : "|"), first
= false;
17181 if (mask
& ELF_SPARC_HWCAP2_XMONT
)
17182 printf ("%sxmont2", first
? "" : "|"), first
= false;
17183 if (mask
& ELF_SPARC_HWCAP2_NSEC
)
17184 printf ("%snsec", first
? "" : "|"), first
= false;
17185 if (mask
& ELF_SPARC_HWCAP2_FJATHHPC
)
17186 printf ("%sfjathhpc", first
? "" : "|"), first
= false;
17187 if (mask
& ELF_SPARC_HWCAP2_FJDES
)
17188 printf ("%sfjdes", first
? "" : "|"), first
= false;
17189 if (mask
& ELF_SPARC_HWCAP2_FJAES
)
17190 printf ("%sfjaes", first
? "" : "|"), first
= false;
17193 fputc ('0', stdout
);
17194 fputc ('\n', stdout
);
17197 static unsigned char *
17198 display_sparc_gnu_attribute (unsigned char * p
,
17200 const unsigned char * const end
)
17204 if (tag
== Tag_GNU_Sparc_HWCAPS
)
17206 READ_ULEB (val
, p
, end
);
17207 printf (" Tag_GNU_Sparc_HWCAPS: ");
17208 display_sparc_hwcaps (val
);
17211 if (tag
== Tag_GNU_Sparc_HWCAPS2
)
17213 READ_ULEB (val
, p
, end
);
17214 printf (" Tag_GNU_Sparc_HWCAPS2: ");
17215 display_sparc_hwcaps2 (val
);
17219 return display_tag_value (tag
, p
, end
);
17223 print_mips_fp_abi_value (unsigned int val
)
17227 case Val_GNU_MIPS_ABI_FP_ANY
:
17228 printf (_("Hard or soft float\n"));
17230 case Val_GNU_MIPS_ABI_FP_DOUBLE
:
17231 printf (_("Hard float (double precision)\n"));
17233 case Val_GNU_MIPS_ABI_FP_SINGLE
:
17234 printf (_("Hard float (single precision)\n"));
17236 case Val_GNU_MIPS_ABI_FP_SOFT
:
17237 printf (_("Soft float\n"));
17239 case Val_GNU_MIPS_ABI_FP_OLD_64
:
17240 printf (_("Hard float (MIPS32r2 64-bit FPU 12 callee-saved)\n"));
17242 case Val_GNU_MIPS_ABI_FP_XX
:
17243 printf (_("Hard float (32-bit CPU, Any FPU)\n"));
17245 case Val_GNU_MIPS_ABI_FP_64
:
17246 printf (_("Hard float (32-bit CPU, 64-bit FPU)\n"));
17248 case Val_GNU_MIPS_ABI_FP_64A
:
17249 printf (_("Hard float compat (32-bit CPU, 64-bit FPU)\n"));
17251 case Val_GNU_MIPS_ABI_FP_NAN2008
:
17252 printf (_("NaN 2008 compatibility\n"));
17255 printf ("??? (%d)\n", val
);
17260 static unsigned char *
17261 display_mips_gnu_attribute (unsigned char * p
,
17263 const unsigned char * const end
)
17265 if (tag
== Tag_GNU_MIPS_ABI_FP
)
17269 printf (" Tag_GNU_MIPS_ABI_FP: ");
17270 READ_ULEB (val
, p
, end
);
17271 print_mips_fp_abi_value (val
);
17275 if (tag
== Tag_GNU_MIPS_ABI_MSA
)
17279 printf (" Tag_GNU_MIPS_ABI_MSA: ");
17280 READ_ULEB (val
, p
, end
);
17284 case Val_GNU_MIPS_ABI_MSA_ANY
:
17285 printf (_("Any MSA or not\n"));
17287 case Val_GNU_MIPS_ABI_MSA_128
:
17288 printf (_("128-bit MSA\n"));
17291 printf ("??? (%d)\n", val
);
17297 return display_tag_value (tag
& 1, p
, end
);
17300 static unsigned char *
17301 display_tic6x_attribute (unsigned char * p
,
17302 const unsigned char * const end
)
17307 READ_ULEB (tag
, p
, end
);
17312 printf (" Tag_ISA: ");
17313 READ_ULEB (val
, p
, end
);
17317 case C6XABI_Tag_ISA_none
:
17318 printf (_("None\n"));
17320 case C6XABI_Tag_ISA_C62X
:
17323 case C6XABI_Tag_ISA_C67X
:
17326 case C6XABI_Tag_ISA_C67XP
:
17327 printf ("C67x+\n");
17329 case C6XABI_Tag_ISA_C64X
:
17332 case C6XABI_Tag_ISA_C64XP
:
17333 printf ("C64x+\n");
17335 case C6XABI_Tag_ISA_C674X
:
17336 printf ("C674x\n");
17339 printf ("??? (%d)\n", val
);
17344 case Tag_ABI_wchar_t
:
17345 printf (" Tag_ABI_wchar_t: ");
17346 READ_ULEB (val
, p
, end
);
17350 printf (_("Not used\n"));
17353 printf (_("2 bytes\n"));
17356 printf (_("4 bytes\n"));
17359 printf ("??? (%d)\n", val
);
17364 case Tag_ABI_stack_align_needed
:
17365 printf (" Tag_ABI_stack_align_needed: ");
17366 READ_ULEB (val
, p
, end
);
17370 printf (_("8-byte\n"));
17373 printf (_("16-byte\n"));
17376 printf ("??? (%d)\n", val
);
17381 case Tag_ABI_stack_align_preserved
:
17382 READ_ULEB (val
, p
, end
);
17383 printf (" Tag_ABI_stack_align_preserved: ");
17387 printf (_("8-byte\n"));
17390 printf (_("16-byte\n"));
17393 printf ("??? (%d)\n", val
);
17399 READ_ULEB (val
, p
, end
);
17400 printf (" Tag_ABI_DSBT: ");
17404 printf (_("DSBT addressing not used\n"));
17407 printf (_("DSBT addressing used\n"));
17410 printf ("??? (%d)\n", val
);
17416 READ_ULEB (val
, p
, end
);
17417 printf (" Tag_ABI_PID: ");
17421 printf (_("Data addressing position-dependent\n"));
17424 printf (_("Data addressing position-independent, GOT near DP\n"));
17427 printf (_("Data addressing position-independent, GOT far from DP\n"));
17430 printf ("??? (%d)\n", val
);
17436 READ_ULEB (val
, p
, end
);
17437 printf (" Tag_ABI_PIC: ");
17441 printf (_("Code addressing position-dependent\n"));
17444 printf (_("Code addressing position-independent\n"));
17447 printf ("??? (%d)\n", val
);
17452 case Tag_ABI_array_object_alignment
:
17453 READ_ULEB (val
, p
, end
);
17454 printf (" Tag_ABI_array_object_alignment: ");
17458 printf (_("8-byte\n"));
17461 printf (_("4-byte\n"));
17464 printf (_("16-byte\n"));
17467 printf ("??? (%d)\n", val
);
17472 case Tag_ABI_array_object_align_expected
:
17473 READ_ULEB (val
, p
, end
);
17474 printf (" Tag_ABI_array_object_align_expected: ");
17478 printf (_("8-byte\n"));
17481 printf (_("4-byte\n"));
17484 printf (_("16-byte\n"));
17487 printf ("??? (%d)\n", val
);
17492 case Tag_ABI_compatibility
:
17494 READ_ULEB (val
, p
, end
);
17495 printf (" Tag_ABI_compatibility: ");
17496 printf (_("flag = %d, vendor = "), val
);
17499 size_t maxlen
= (end
- p
) - 1;
17501 print_symbol ((int) maxlen
, (const char *) p
);
17502 p
+= strnlen ((char *) p
, maxlen
) + 1;
17506 printf (_("<corrupt>"));
17507 p
= (unsigned char *) end
;
17513 case Tag_ABI_conformance
:
17515 printf (" Tag_ABI_conformance: \"");
17518 size_t maxlen
= (end
- p
) - 1;
17520 print_symbol ((int) maxlen
, (const char *) p
);
17521 p
+= strnlen ((char *) p
, maxlen
) + 1;
17525 printf (_("<corrupt>"));
17526 p
= (unsigned char *) end
;
17533 return display_tag_value (tag
, p
, end
);
17537 display_raw_attribute (unsigned char * p
, unsigned char const * const end
)
17539 unsigned long addr
= 0;
17540 size_t bytes
= end
- p
;
17547 int lbytes
= (bytes
> 16 ? 16 : bytes
);
17549 printf (" 0x%8.8lx ", addr
);
17551 for (j
= 0; j
< 16; j
++)
17554 printf ("%2.2x", p
[j
]);
17562 for (j
= 0; j
< lbytes
; j
++)
17565 if (k
>= ' ' && k
< 0x7f)
17581 static unsigned char *
17582 display_msp430_attribute (unsigned char * p
,
17583 const unsigned char * const end
)
17588 READ_ULEB (tag
, p
, end
);
17592 case OFBA_MSPABI_Tag_ISA
:
17593 printf (" Tag_ISA: ");
17594 READ_ULEB (val
, p
, end
);
17597 case 0: printf (_("None\n")); break;
17598 case 1: printf (_("MSP430\n")); break;
17599 case 2: printf (_("MSP430X\n")); break;
17600 default: printf ("??? (%d)\n", val
); break;
17604 case OFBA_MSPABI_Tag_Code_Model
:
17605 printf (" Tag_Code_Model: ");
17606 READ_ULEB (val
, p
, end
);
17609 case 0: printf (_("None\n")); break;
17610 case 1: printf (_("Small\n")); break;
17611 case 2: printf (_("Large\n")); break;
17612 default: printf ("??? (%d)\n", val
); break;
17616 case OFBA_MSPABI_Tag_Data_Model
:
17617 printf (" Tag_Data_Model: ");
17618 READ_ULEB (val
, p
, end
);
17621 case 0: printf (_("None\n")); break;
17622 case 1: printf (_("Small\n")); break;
17623 case 2: printf (_("Large\n")); break;
17624 case 3: printf (_("Restricted Large\n")); break;
17625 default: printf ("??? (%d)\n", val
); break;
17630 printf (_(" <unknown tag %d>: "), tag
);
17637 size_t maxlen
= (end
- p
) - 1;
17639 print_symbol ((int) maxlen
, (const char *) p
);
17640 p
+= strnlen ((char *) p
, maxlen
) + 1;
17644 printf (_("<corrupt>"));
17645 p
= (unsigned char *) end
;
17651 READ_ULEB (val
, p
, end
);
17652 printf ("%d (0x%x)\n", val
, val
);
17661 static unsigned char *
17662 display_msp430_gnu_attribute (unsigned char * p
,
17664 const unsigned char * const end
)
17666 if (tag
== Tag_GNU_MSP430_Data_Region
)
17670 printf (" Tag_GNU_MSP430_Data_Region: ");
17671 READ_ULEB (val
, p
, end
);
17675 case Val_GNU_MSP430_Data_Region_Any
:
17676 printf (_("Any Region\n"));
17678 case Val_GNU_MSP430_Data_Region_Lower
:
17679 printf (_("Lower Region Only\n"));
17682 printf ("??? (%u)\n", val
);
17686 return display_tag_value (tag
& 1, p
, end
);
17689 struct riscv_attr_tag_t
{
17694 static struct riscv_attr_tag_t riscv_attr_tag
[] =
17696 #define T(tag) {"Tag_RISCV_" #tag, Tag_RISCV_##tag}
17699 T(priv_spec_minor
),
17700 T(priv_spec_revision
),
17701 T(unaligned_access
),
17706 static unsigned char *
17707 display_riscv_attribute (unsigned char *p
,
17708 const unsigned char * const end
)
17712 struct riscv_attr_tag_t
*attr
= NULL
;
17715 READ_ULEB (tag
, p
, end
);
17717 /* Find the name of attribute. */
17718 for (i
= 0; i
< ARRAY_SIZE (riscv_attr_tag
); i
++)
17720 if (riscv_attr_tag
[i
].tag
== tag
)
17722 attr
= &riscv_attr_tag
[i
];
17728 printf (" %s: ", attr
->name
);
17730 return display_tag_value (tag
, p
, end
);
17734 case Tag_RISCV_priv_spec
:
17735 case Tag_RISCV_priv_spec_minor
:
17736 case Tag_RISCV_priv_spec_revision
:
17737 READ_ULEB (val
, p
, end
);
17738 printf (_("%u\n"), val
);
17740 case Tag_RISCV_unaligned_access
:
17741 READ_ULEB (val
, p
, end
);
17745 printf (_("No unaligned access\n"));
17748 printf (_("Unaligned access\n"));
17752 case Tag_RISCV_stack_align
:
17753 READ_ULEB (val
, p
, end
);
17754 printf (_("%u-bytes\n"), val
);
17756 case Tag_RISCV_arch
:
17757 p
= display_tag_value (-1, p
, end
);
17760 return display_tag_value (tag
, p
, end
);
17766 static unsigned char *
17767 display_csky_attribute (unsigned char * p
,
17768 const unsigned char * const end
)
17772 READ_ULEB (tag
, p
, end
);
17774 if (tag
>= Tag_CSKY_MAX
)
17776 return display_tag_value (-1, p
, end
);
17781 case Tag_CSKY_ARCH_NAME
:
17782 printf (" Tag_CSKY_ARCH_NAME:\t\t");
17783 return display_tag_value (-1, p
, end
);
17784 case Tag_CSKY_CPU_NAME
:
17785 printf (" Tag_CSKY_CPU_NAME:\t\t");
17786 return display_tag_value (-1, p
, end
);
17788 case Tag_CSKY_ISA_FLAGS
:
17789 printf (" Tag_CSKY_ISA_FLAGS:\t\t");
17790 return display_tag_value (0, p
, end
);
17791 case Tag_CSKY_ISA_EXT_FLAGS
:
17792 printf (" Tag_CSKY_ISA_EXT_FLAGS:\t");
17793 return display_tag_value (0, p
, end
);
17795 case Tag_CSKY_DSP_VERSION
:
17796 printf (" Tag_CSKY_DSP_VERSION:\t\t");
17797 READ_ULEB (val
, p
, end
);
17798 if (val
== VAL_CSKY_DSP_VERSION_EXTENSION
)
17799 printf ("DSP Extension\n");
17800 else if (val
== VAL_CSKY_DSP_VERSION_2
)
17801 printf ("DSP 2.0\n");
17804 case Tag_CSKY_VDSP_VERSION
:
17805 printf (" Tag_CSKY_VDSP_VERSION:\t");
17806 READ_ULEB (val
, p
, end
);
17807 printf ("VDSP Version %d\n", val
);
17810 case Tag_CSKY_FPU_VERSION
:
17811 printf (" Tag_CSKY_FPU_VERSION:\t\t");
17812 READ_ULEB (val
, p
, end
);
17813 if (val
== VAL_CSKY_FPU_VERSION_1
)
17814 printf ("ABIV1 FPU Version 1\n");
17815 else if (val
== VAL_CSKY_FPU_VERSION_2
)
17816 printf ("FPU Version 2\n");
17819 case Tag_CSKY_FPU_ABI
:
17820 printf (" Tag_CSKY_FPU_ABI:\t\t");
17821 READ_ULEB (val
, p
, end
);
17822 if (val
== VAL_CSKY_FPU_ABI_HARD
)
17824 else if (val
== VAL_CSKY_FPU_ABI_SOFTFP
)
17825 printf ("SoftFP\n");
17826 else if (val
== VAL_CSKY_FPU_ABI_SOFT
)
17829 case Tag_CSKY_FPU_ROUNDING
:
17830 READ_ULEB (val
, p
, end
);
17833 printf (" Tag_CSKY_FPU_ROUNDING:\t");
17834 printf ("Needed\n");
17837 case Tag_CSKY_FPU_DENORMAL
:
17838 READ_ULEB (val
, p
, end
);
17841 printf (" Tag_CSKY_FPU_DENORMAL:\t");
17842 printf ("Needed\n");
17845 case Tag_CSKY_FPU_Exception
:
17846 READ_ULEB (val
, p
, end
);
17849 printf (" Tag_CSKY_FPU_Exception:\t");
17850 printf ("Needed\n");
17853 case Tag_CSKY_FPU_NUMBER_MODULE
:
17854 printf (" Tag_CSKY_FPU_NUMBER_MODULE:\t");
17855 return display_tag_value (-1, p
, end
);
17856 case Tag_CSKY_FPU_HARDFP
:
17857 printf (" Tag_CSKY_FPU_HARDFP:\t\t");
17858 READ_ULEB (val
, p
, end
);
17859 if (val
& VAL_CSKY_FPU_HARDFP_HALF
)
17861 if (val
& VAL_CSKY_FPU_HARDFP_SINGLE
)
17862 printf (" Single");
17863 if (val
& VAL_CSKY_FPU_HARDFP_DOUBLE
)
17864 printf (" Double");
17868 return display_tag_value (tag
, p
, end
);
17874 process_attributes (Filedata
* filedata
,
17875 const char * public_name
,
17876 unsigned int proc_type
,
17877 unsigned char * (* display_pub_attribute
) (unsigned char *, const unsigned char * const),
17878 unsigned char * (* display_proc_gnu_attribute
) (unsigned char *, unsigned int, const unsigned char * const))
17880 Elf_Internal_Shdr
* sect
;
17884 /* Find the section header so that we get the size. */
17885 for (i
= 0, sect
= filedata
->section_headers
;
17886 i
< filedata
->file_header
.e_shnum
;
17889 unsigned char * contents
;
17892 if (sect
->sh_type
!= proc_type
&& sect
->sh_type
!= SHT_GNU_ATTRIBUTES
)
17895 contents
= (unsigned char *) get_data (NULL
, filedata
, sect
->sh_offset
, 1,
17896 sect
->sh_size
, _("attributes"));
17897 if (contents
== NULL
)
17904 /* The first character is the version of the attributes.
17905 Currently only version 1, (aka 'A') is recognised here. */
17908 printf (_("Unknown attributes version '%c'(%d) - expecting 'A'\n"), *p
, *p
);
17913 bfd_vma section_len
;
17915 section_len
= sect
->sh_size
- 1;
17918 while (section_len
> 0)
17921 unsigned int namelen
;
17922 bool public_section
;
17925 if (section_len
<= 4)
17927 error (_("Tag section ends prematurely\n"));
17931 attr_len
= byte_get (p
, 4);
17934 if (attr_len
> section_len
)
17936 error (_("Bad attribute length (%u > %u)\n"),
17937 (unsigned) attr_len
, (unsigned) section_len
);
17938 attr_len
= section_len
;
17941 /* PR 17531: file: 001-101425-0.004 */
17942 else if (attr_len
< 5)
17944 error (_("Attribute length of %u is too small\n"), (unsigned) attr_len
);
17949 section_len
-= attr_len
;
17952 namelen
= strnlen ((char *) p
, attr_len
) + 1;
17953 if (namelen
== 0 || namelen
>= attr_len
)
17955 error (_("Corrupt attribute section name\n"));
17960 printf (_("Attribute Section: "));
17961 print_symbol (INT_MAX
, (const char *) p
);
17964 if (public_name
&& streq ((char *) p
, public_name
))
17965 public_section
= true;
17967 public_section
= false;
17969 if (streq ((char *) p
, "gnu"))
17970 gnu_section
= true;
17972 gnu_section
= false;
17975 attr_len
-= namelen
;
17977 while (attr_len
> 0 && p
< contents
+ sect
->sh_size
)
17982 unsigned char * end
;
17984 /* PR binutils/17531: Safe handling of corrupt files. */
17987 error (_("Unused bytes at end of section\n"));
17994 size
= byte_get (p
, 4);
17995 if (size
> attr_len
)
17997 error (_("Bad subsection length (%u > %u)\n"),
17998 (unsigned) size
, (unsigned) attr_len
);
18002 /* PR binutils/17531: Safe handling of corrupt files. */
18005 error (_("Bad subsection length (%u < 6)\n"),
18013 end
= p
+ size
- 1;
18014 assert (end
<= contents
+ sect
->sh_size
);
18020 printf (_("File Attributes\n"));
18023 printf (_("Section Attributes:"));
18026 printf (_("Symbol Attributes:"));
18027 /* Fall through. */
18031 READ_ULEB (val
, p
, end
);
18034 printf (" %d", val
);
18039 printf (_("Unknown tag: %d\n"), tag
);
18040 public_section
= false;
18044 if (public_section
&& display_pub_attribute
!= NULL
)
18047 p
= display_pub_attribute (p
, end
);
18050 else if (gnu_section
&& display_proc_gnu_attribute
!= NULL
)
18053 p
= display_gnu_attribute (p
,
18054 display_proc_gnu_attribute
,
18060 printf (_(" Unknown attribute:\n"));
18061 display_raw_attribute (p
, end
);
18076 /* DATA points to the contents of a MIPS GOT that starts at VMA PLTGOT.
18077 Print the Address, Access and Initial fields of an entry at VMA ADDR
18078 and return the VMA of the next entry, or -1 if there was a problem.
18079 Does not read from DATA_END or beyond. */
18082 print_mips_got_entry (unsigned char * data
, bfd_vma pltgot
, bfd_vma addr
,
18083 unsigned char * data_end
)
18086 print_vma (addr
, LONG_HEX
);
18088 if (addr
< pltgot
+ 0xfff0)
18089 printf ("%6d(gp)", (int) (addr
- pltgot
- 0x7ff0));
18091 printf ("%10s", "");
18094 printf ("%*s", is_32bit_elf
? 8 : 16, _("<unknown>"));
18098 unsigned char * from
= data
+ addr
- pltgot
;
18100 if (from
+ (is_32bit_elf
? 4 : 8) > data_end
)
18102 warn (_("MIPS GOT entry extends beyond the end of available data\n"));
18103 printf ("%*s", is_32bit_elf
? 8 : 16, _("<corrupt>"));
18104 return (bfd_vma
) -1;
18108 entry
= byte_get (data
+ addr
- pltgot
, is_32bit_elf
? 4 : 8);
18109 print_vma (entry
, LONG_HEX
);
18112 return addr
+ (is_32bit_elf
? 4 : 8);
18115 /* DATA points to the contents of a MIPS PLT GOT that starts at VMA
18116 PLTGOT. Print the Address and Initial fields of an entry at VMA
18117 ADDR and return the VMA of the next entry. */
18120 print_mips_pltgot_entry (unsigned char * data
, bfd_vma pltgot
, bfd_vma addr
)
18123 print_vma (addr
, LONG_HEX
);
18126 printf ("%*s", is_32bit_elf
? 8 : 16, _("<unknown>"));
18131 entry
= byte_get (data
+ addr
- pltgot
, is_32bit_elf
? 4 : 8);
18132 print_vma (entry
, LONG_HEX
);
18134 return addr
+ (is_32bit_elf
? 4 : 8);
18138 print_mips_ases (unsigned int mask
)
18140 if (mask
& AFL_ASE_DSP
)
18141 fputs ("\n\tDSP ASE", stdout
);
18142 if (mask
& AFL_ASE_DSPR2
)
18143 fputs ("\n\tDSP R2 ASE", stdout
);
18144 if (mask
& AFL_ASE_DSPR3
)
18145 fputs ("\n\tDSP R3 ASE", stdout
);
18146 if (mask
& AFL_ASE_EVA
)
18147 fputs ("\n\tEnhanced VA Scheme", stdout
);
18148 if (mask
& AFL_ASE_MCU
)
18149 fputs ("\n\tMCU (MicroController) ASE", stdout
);
18150 if (mask
& AFL_ASE_MDMX
)
18151 fputs ("\n\tMDMX ASE", stdout
);
18152 if (mask
& AFL_ASE_MIPS3D
)
18153 fputs ("\n\tMIPS-3D ASE", stdout
);
18154 if (mask
& AFL_ASE_MT
)
18155 fputs ("\n\tMT ASE", stdout
);
18156 if (mask
& AFL_ASE_SMARTMIPS
)
18157 fputs ("\n\tSmartMIPS ASE", stdout
);
18158 if (mask
& AFL_ASE_VIRT
)
18159 fputs ("\n\tVZ ASE", stdout
);
18160 if (mask
& AFL_ASE_MSA
)
18161 fputs ("\n\tMSA ASE", stdout
);
18162 if (mask
& AFL_ASE_MIPS16
)
18163 fputs ("\n\tMIPS16 ASE", stdout
);
18164 if (mask
& AFL_ASE_MICROMIPS
)
18165 fputs ("\n\tMICROMIPS ASE", stdout
);
18166 if (mask
& AFL_ASE_XPA
)
18167 fputs ("\n\tXPA ASE", stdout
);
18168 if (mask
& AFL_ASE_MIPS16E2
)
18169 fputs ("\n\tMIPS16e2 ASE", stdout
);
18170 if (mask
& AFL_ASE_CRC
)
18171 fputs ("\n\tCRC ASE", stdout
);
18172 if (mask
& AFL_ASE_GINV
)
18173 fputs ("\n\tGINV ASE", stdout
);
18174 if (mask
& AFL_ASE_LOONGSON_MMI
)
18175 fputs ("\n\tLoongson MMI ASE", stdout
);
18176 if (mask
& AFL_ASE_LOONGSON_CAM
)
18177 fputs ("\n\tLoongson CAM ASE", stdout
);
18178 if (mask
& AFL_ASE_LOONGSON_EXT
)
18179 fputs ("\n\tLoongson EXT ASE", stdout
);
18180 if (mask
& AFL_ASE_LOONGSON_EXT2
)
18181 fputs ("\n\tLoongson EXT2 ASE", stdout
);
18183 fprintf (stdout
, "\n\t%s", _("None"));
18184 else if ((mask
& ~AFL_ASE_MASK
) != 0)
18185 fprintf (stdout
, "\n\t%s (%x)", _("Unknown"), mask
& ~AFL_ASE_MASK
);
18189 print_mips_isa_ext (unsigned int isa_ext
)
18194 fputs (_("None"), stdout
);
18197 fputs ("RMI XLR", stdout
);
18199 case AFL_EXT_OCTEON3
:
18200 fputs ("Cavium Networks Octeon3", stdout
);
18202 case AFL_EXT_OCTEON2
:
18203 fputs ("Cavium Networks Octeon2", stdout
);
18205 case AFL_EXT_OCTEONP
:
18206 fputs ("Cavium Networks OcteonP", stdout
);
18208 case AFL_EXT_OCTEON
:
18209 fputs ("Cavium Networks Octeon", stdout
);
18212 fputs ("Toshiba R5900", stdout
);
18215 fputs ("MIPS R4650", stdout
);
18218 fputs ("LSI R4010", stdout
);
18221 fputs ("NEC VR4100", stdout
);
18224 fputs ("Toshiba R3900", stdout
);
18226 case AFL_EXT_10000
:
18227 fputs ("MIPS R10000", stdout
);
18230 fputs ("Broadcom SB-1", stdout
);
18233 fputs ("NEC VR4111/VR4181", stdout
);
18236 fputs ("NEC VR4120", stdout
);
18239 fputs ("NEC VR5400", stdout
);
18242 fputs ("NEC VR5500", stdout
);
18244 case AFL_EXT_LOONGSON_2E
:
18245 fputs ("ST Microelectronics Loongson 2E", stdout
);
18247 case AFL_EXT_LOONGSON_2F
:
18248 fputs ("ST Microelectronics Loongson 2F", stdout
);
18250 case AFL_EXT_INTERAPTIV_MR2
:
18251 fputs ("Imagination interAptiv MR2", stdout
);
18254 fprintf (stdout
, "%s (%d)", _("Unknown"), isa_ext
);
18259 get_mips_reg_size (int reg_size
)
18261 return (reg_size
== AFL_REG_NONE
) ? 0
18262 : (reg_size
== AFL_REG_32
) ? 32
18263 : (reg_size
== AFL_REG_64
) ? 64
18264 : (reg_size
== AFL_REG_128
) ? 128
18269 process_mips_specific (Filedata
* filedata
)
18271 Elf_Internal_Dyn
* entry
;
18272 Elf_Internal_Shdr
*sect
= NULL
;
18273 size_t liblist_offset
= 0;
18274 size_t liblistno
= 0;
18275 size_t conflictsno
= 0;
18276 size_t options_offset
= 0;
18277 size_t conflicts_offset
= 0;
18278 size_t pltrelsz
= 0;
18280 bfd_vma pltgot
= 0;
18281 bfd_vma mips_pltgot
= 0;
18282 bfd_vma jmprel
= 0;
18283 bfd_vma local_gotno
= 0;
18284 bfd_vma gotsym
= 0;
18285 bfd_vma symtabno
= 0;
18288 if (! process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
18289 display_mips_gnu_attribute
))
18292 sect
= find_section (filedata
, ".MIPS.abiflags");
18296 Elf_External_ABIFlags_v0
*abiflags_ext
;
18297 Elf_Internal_ABIFlags_v0 abiflags_in
;
18299 if (sizeof (Elf_External_ABIFlags_v0
) != sect
->sh_size
)
18301 error (_("Corrupt MIPS ABI Flags section.\n"));
18306 abiflags_ext
= get_data (NULL
, filedata
, sect
->sh_offset
, 1,
18307 sect
->sh_size
, _("MIPS ABI Flags section"));
18310 abiflags_in
.version
= BYTE_GET (abiflags_ext
->version
);
18311 abiflags_in
.isa_level
= BYTE_GET (abiflags_ext
->isa_level
);
18312 abiflags_in
.isa_rev
= BYTE_GET (abiflags_ext
->isa_rev
);
18313 abiflags_in
.gpr_size
= BYTE_GET (abiflags_ext
->gpr_size
);
18314 abiflags_in
.cpr1_size
= BYTE_GET (abiflags_ext
->cpr1_size
);
18315 abiflags_in
.cpr2_size
= BYTE_GET (abiflags_ext
->cpr2_size
);
18316 abiflags_in
.fp_abi
= BYTE_GET (abiflags_ext
->fp_abi
);
18317 abiflags_in
.isa_ext
= BYTE_GET (abiflags_ext
->isa_ext
);
18318 abiflags_in
.ases
= BYTE_GET (abiflags_ext
->ases
);
18319 abiflags_in
.flags1
= BYTE_GET (abiflags_ext
->flags1
);
18320 abiflags_in
.flags2
= BYTE_GET (abiflags_ext
->flags2
);
18322 printf ("\nMIPS ABI Flags Version: %d\n", abiflags_in
.version
);
18323 printf ("\nISA: MIPS%d", abiflags_in
.isa_level
);
18324 if (abiflags_in
.isa_rev
> 1)
18325 printf ("r%d", abiflags_in
.isa_rev
);
18326 printf ("\nGPR size: %d",
18327 get_mips_reg_size (abiflags_in
.gpr_size
));
18328 printf ("\nCPR1 size: %d",
18329 get_mips_reg_size (abiflags_in
.cpr1_size
));
18330 printf ("\nCPR2 size: %d",
18331 get_mips_reg_size (abiflags_in
.cpr2_size
));
18332 fputs ("\nFP ABI: ", stdout
);
18333 print_mips_fp_abi_value (abiflags_in
.fp_abi
);
18334 fputs ("ISA Extension: ", stdout
);
18335 print_mips_isa_ext (abiflags_in
.isa_ext
);
18336 fputs ("\nASEs:", stdout
);
18337 print_mips_ases (abiflags_in
.ases
);
18338 printf ("\nFLAGS 1: %8.8lx", abiflags_in
.flags1
);
18339 printf ("\nFLAGS 2: %8.8lx", abiflags_in
.flags2
);
18340 fputc ('\n', stdout
);
18341 free (abiflags_ext
);
18346 /* We have a lot of special sections. Thanks SGI! */
18347 if (filedata
->dynamic_section
== NULL
)
18349 /* No dynamic information available. See if there is static GOT. */
18350 sect
= find_section (filedata
, ".got");
18353 unsigned char *data_end
;
18354 unsigned char *data
;
18358 pltgot
= sect
->sh_addr
;
18361 addr_size
= (is_32bit_elf
? 4 : 8);
18362 end
= pltgot
+ sect
->sh_size
;
18364 data
= (unsigned char *) get_data (NULL
, filedata
, sect
->sh_offset
,
18366 _("Global Offset Table data"));
18367 /* PR 12855: Null data is handled gracefully throughout. */
18368 data_end
= data
+ (end
- pltgot
);
18370 printf (_("\nStatic GOT:\n"));
18371 printf (_(" Canonical gp value: "));
18372 print_vma (ent
+ 0x7ff0, LONG_HEX
);
18375 /* In a dynamic binary GOT[0] is reserved for the dynamic
18376 loader to store the lazy resolver pointer, however in
18377 a static binary it may well have been omitted and GOT
18378 reduced to a table of addresses.
18379 PR 21344: Check for the entry being fully available
18380 before fetching it. */
18382 && data
+ ent
- pltgot
+ addr_size
<= data_end
18383 && byte_get (data
+ ent
- pltgot
, addr_size
) == 0)
18385 printf (_(" Reserved entries:\n"));
18386 printf (_(" %*s %10s %*s\n"),
18387 addr_size
* 2, _("Address"), _("Access"),
18388 addr_size
* 2, _("Value"));
18389 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
18391 if (ent
== (bfd_vma
) -1)
18392 goto sgot_print_fail
;
18394 /* Check for the MSB of GOT[1] being set, identifying a
18395 GNU object. This entry will be used by some runtime
18396 loaders, to store the module pointer. Otherwise this
18397 is an ordinary local entry.
18398 PR 21344: Check for the entry being fully available
18399 before fetching it. */
18401 && data
+ ent
- pltgot
+ addr_size
<= data_end
18402 && (byte_get (data
+ ent
- pltgot
, addr_size
)
18403 >> (addr_size
* 8 - 1)) != 0)
18405 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
18407 if (ent
== (bfd_vma
) -1)
18408 goto sgot_print_fail
;
18413 if (data
!= NULL
&& ent
< end
)
18415 printf (_(" Local entries:\n"));
18416 printf (" %*s %10s %*s\n",
18417 addr_size
* 2, _("Address"), _("Access"),
18418 addr_size
* 2, _("Value"));
18421 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
18423 if (ent
== (bfd_vma
) -1)
18424 goto sgot_print_fail
;
18435 for (entry
= filedata
->dynamic_section
;
18436 /* PR 17531 file: 012-50589-0.004. */
18437 (entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
18438 && entry
->d_tag
!= DT_NULL
);
18440 switch (entry
->d_tag
)
18442 case DT_MIPS_LIBLIST
:
18444 = offset_from_vma (filedata
, entry
->d_un
.d_val
,
18445 liblistno
* sizeof (Elf32_External_Lib
));
18447 case DT_MIPS_LIBLISTNO
:
18448 liblistno
= entry
->d_un
.d_val
;
18450 case DT_MIPS_OPTIONS
:
18451 options_offset
= offset_from_vma (filedata
, entry
->d_un
.d_val
, 0);
18453 case DT_MIPS_CONFLICT
:
18455 = offset_from_vma (filedata
, entry
->d_un
.d_val
,
18456 conflictsno
* sizeof (Elf32_External_Conflict
));
18458 case DT_MIPS_CONFLICTNO
:
18459 conflictsno
= entry
->d_un
.d_val
;
18462 pltgot
= entry
->d_un
.d_ptr
;
18464 case DT_MIPS_LOCAL_GOTNO
:
18465 local_gotno
= entry
->d_un
.d_val
;
18467 case DT_MIPS_GOTSYM
:
18468 gotsym
= entry
->d_un
.d_val
;
18470 case DT_MIPS_SYMTABNO
:
18471 symtabno
= entry
->d_un
.d_val
;
18473 case DT_MIPS_PLTGOT
:
18474 mips_pltgot
= entry
->d_un
.d_ptr
;
18477 pltrel
= entry
->d_un
.d_val
;
18480 pltrelsz
= entry
->d_un
.d_val
;
18483 jmprel
= entry
->d_un
.d_ptr
;
18489 if (liblist_offset
!= 0 && liblistno
!= 0 && do_dynamic
)
18491 Elf32_External_Lib
* elib
;
18494 elib
= (Elf32_External_Lib
*) get_data (NULL
, filedata
, liblist_offset
,
18495 sizeof (Elf32_External_Lib
),
18497 _("liblist section data"));
18500 printf (ngettext ("\nSection '.liblist' contains %lu entry:\n",
18501 "\nSection '.liblist' contains %lu entries:\n",
18502 (unsigned long) liblistno
),
18503 (unsigned long) liblistno
);
18504 fputs (_(" Library Time Stamp Checksum Version Flags\n"),
18507 for (cnt
= 0; cnt
< liblistno
; ++cnt
)
18514 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
18515 atime
= BYTE_GET (elib
[cnt
].l_time_stamp
);
18516 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
18517 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
18518 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
18520 tmp
= gmtime (&atime
);
18521 snprintf (timebuf
, sizeof (timebuf
),
18522 "%04u-%02u-%02uT%02u:%02u:%02u",
18523 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
18524 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
18526 printf ("%3lu: ", (unsigned long) cnt
);
18527 if (valid_dynamic_name (filedata
, liblist
.l_name
))
18528 print_symbol (20, get_dynamic_name (filedata
, liblist
.l_name
));
18530 printf (_("<corrupt: %9ld>"), liblist
.l_name
);
18531 printf (" %s %#10lx %-7ld", timebuf
, liblist
.l_checksum
,
18532 liblist
.l_version
);
18534 if (liblist
.l_flags
== 0)
18538 static const struct
18545 { " EXACT_MATCH", LL_EXACT_MATCH
},
18546 { " IGNORE_INT_VER", LL_IGNORE_INT_VER
},
18547 { " REQUIRE_MINOR", LL_REQUIRE_MINOR
},
18548 { " EXPORTS", LL_EXPORTS
},
18549 { " DELAY_LOAD", LL_DELAY_LOAD
},
18550 { " DELTA", LL_DELTA
}
18552 int flags
= liblist
.l_flags
;
18555 for (fcnt
= 0; fcnt
< ARRAY_SIZE (l_flags_vals
); ++fcnt
)
18556 if ((flags
& l_flags_vals
[fcnt
].bit
) != 0)
18558 fputs (l_flags_vals
[fcnt
].name
, stdout
);
18559 flags
^= l_flags_vals
[fcnt
].bit
;
18562 printf (" %#x", (unsigned int) flags
);
18574 if (options_offset
!= 0)
18576 Elf_External_Options
* eopt
;
18580 /* Find the section header so that we get the size. */
18581 sect
= find_section_by_type (filedata
, SHT_MIPS_OPTIONS
);
18582 /* PR 17533 file: 012-277276-0.004. */
18585 error (_("No MIPS_OPTIONS header found\n"));
18589 if (sect
->sh_size
< sizeof (* eopt
))
18591 error (_("The MIPS options section is too small.\n"));
18595 eopt
= (Elf_External_Options
*) get_data (NULL
, filedata
, options_offset
, 1,
18596 sect
->sh_size
, _("options"));
18599 Elf_Internal_Options option
;
18602 while (offset
<= sect
->sh_size
- sizeof (* eopt
))
18604 Elf_External_Options
* eoption
;
18605 unsigned int optsize
;
18607 eoption
= (Elf_External_Options
*) ((char *) eopt
+ offset
);
18609 optsize
= BYTE_GET (eoption
->size
);
18611 /* PR 17531: file: ffa0fa3b. */
18612 if (optsize
< sizeof (* eopt
)
18613 || optsize
> sect
->sh_size
- offset
)
18615 error (_("Invalid size (%u) for MIPS option\n"),
18624 printf (ngettext ("\nSection '%s' contains %d entry:\n",
18625 "\nSection '%s' contains %d entries:\n",
18627 printable_section_name (filedata
, sect
), cnt
);
18633 Elf_External_Options
* eoption
;
18635 eoption
= (Elf_External_Options
*) ((char *) eopt
+ offset
);
18637 option
.kind
= BYTE_GET (eoption
->kind
);
18638 option
.size
= BYTE_GET (eoption
->size
);
18639 option
.section
= BYTE_GET (eoption
->section
);
18640 option
.info
= BYTE_GET (eoption
->info
);
18642 switch (option
.kind
)
18645 /* This shouldn't happen. */
18646 printf (" NULL %" PRId16
" %" PRIx32
,
18647 option
.section
, option
.info
);
18651 printf (" REGINFO ");
18652 if (filedata
->file_header
.e_machine
== EM_MIPS
)
18654 Elf32_External_RegInfo
* ereg
;
18655 Elf32_RegInfo reginfo
;
18658 if (option
.size
< (sizeof (Elf_External_Options
)
18659 + sizeof (Elf32_External_RegInfo
)))
18661 printf (_("<corrupt>\n"));
18662 error (_("Truncated MIPS REGINFO option\n"));
18667 ereg
= (Elf32_External_RegInfo
*) (eoption
+ 1);
18669 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
18670 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
18671 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
18672 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
18673 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
18674 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
18676 printf ("GPR %08" PRIx32
" GP 0x%" PRIx32
"\n",
18677 reginfo
.ri_gprmask
, reginfo
.ri_gp_value
);
18679 " CPR0 %08" PRIx32
" CPR1 %08" PRIx32
18680 " CPR2 %08" PRIx32
" CPR3 %08" PRIx32
"\n",
18681 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
18682 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
18687 Elf64_External_RegInfo
* ereg
;
18688 Elf64_Internal_RegInfo reginfo
;
18690 if (option
.size
< (sizeof (Elf_External_Options
)
18691 + sizeof (Elf64_External_RegInfo
)))
18693 printf (_("<corrupt>\n"));
18694 error (_("Truncated MIPS REGINFO option\n"));
18699 ereg
= (Elf64_External_RegInfo
*) (eoption
+ 1);
18700 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
18701 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
18702 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
18703 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
18704 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
18705 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
18707 printf ("GPR %08" PRIx32
" GP 0x%" PRIx64
"\n",
18708 reginfo
.ri_gprmask
, reginfo
.ri_gp_value
);
18710 " CPR0 %08" PRIx32
" CPR1 %08" PRIx32
18711 " CPR2 %08" PRIx32
" CPR3 %08" PRIx32
"\n",
18712 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
18713 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
18715 offset
+= option
.size
;
18718 case ODK_EXCEPTIONS
:
18719 fputs (" EXCEPTIONS fpe_min(", stdout
);
18720 process_mips_fpe_exception (option
.info
& OEX_FPU_MIN
);
18721 fputs (") fpe_max(", stdout
);
18722 process_mips_fpe_exception ((option
.info
& OEX_FPU_MAX
) >> 8);
18723 fputs (")", stdout
);
18725 if (option
.info
& OEX_PAGE0
)
18726 fputs (" PAGE0", stdout
);
18727 if (option
.info
& OEX_SMM
)
18728 fputs (" SMM", stdout
);
18729 if (option
.info
& OEX_FPDBUG
)
18730 fputs (" FPDBUG", stdout
);
18731 if (option
.info
& OEX_DISMISS
)
18732 fputs (" DISMISS", stdout
);
18736 fputs (" PAD ", stdout
);
18737 if (option
.info
& OPAD_PREFIX
)
18738 fputs (" PREFIX", stdout
);
18739 if (option
.info
& OPAD_POSTFIX
)
18740 fputs (" POSTFIX", stdout
);
18741 if (option
.info
& OPAD_SYMBOL
)
18742 fputs (" SYMBOL", stdout
);
18746 fputs (" HWPATCH ", stdout
);
18747 if (option
.info
& OHW_R4KEOP
)
18748 fputs (" R4KEOP", stdout
);
18749 if (option
.info
& OHW_R8KPFETCH
)
18750 fputs (" R8KPFETCH", stdout
);
18751 if (option
.info
& OHW_R5KEOP
)
18752 fputs (" R5KEOP", stdout
);
18753 if (option
.info
& OHW_R5KCVTL
)
18754 fputs (" R5KCVTL", stdout
);
18758 fputs (" FILL ", stdout
);
18759 /* XXX Print content of info word? */
18763 fputs (" TAGS ", stdout
);
18764 /* XXX Print content of info word? */
18768 fputs (" HWAND ", stdout
);
18769 if (option
.info
& OHWA0_R4KEOP_CHECKED
)
18770 fputs (" R4KEOP_CHECKED", stdout
);
18771 if (option
.info
& OHWA0_R4KEOP_CLEAN
)
18772 fputs (" R4KEOP_CLEAN", stdout
);
18776 fputs (" HWOR ", stdout
);
18777 if (option
.info
& OHWA0_R4KEOP_CHECKED
)
18778 fputs (" R4KEOP_CHECKED", stdout
);
18779 if (option
.info
& OHWA0_R4KEOP_CLEAN
)
18780 fputs (" R4KEOP_CLEAN", stdout
);
18784 printf (" GP_GROUP %#06x self-contained %#06x",
18785 option
.info
& OGP_GROUP
,
18786 (option
.info
& OGP_SELF
) >> 16);
18790 printf (" IDENT %#06x self-contained %#06x",
18791 option
.info
& OGP_GROUP
,
18792 (option
.info
& OGP_SELF
) >> 16);
18796 /* This shouldn't happen. */
18797 printf (" %3d ??? %" PRId16
" %" PRIx32
,
18798 option
.kind
, option
.section
, option
.info
);
18802 len
= sizeof (* eopt
);
18803 while (len
< option
.size
)
18805 unsigned char datum
= *((unsigned char *) eoption
+ len
);
18807 if (ISPRINT (datum
))
18808 printf ("%c", datum
);
18810 printf ("\\%03o", datum
);
18813 fputs ("\n", stdout
);
18815 offset
+= option
.size
;
18823 if (conflicts_offset
!= 0 && conflictsno
!= 0)
18825 Elf32_Conflict
* iconf
;
18828 if (filedata
->dynamic_symbols
== NULL
)
18830 error (_("conflict list found without a dynamic symbol table\n"));
18834 /* PR 21345 - print a slightly more helpful error message
18835 if we are sure that the cmalloc will fail. */
18836 if (conflictsno
> filedata
->file_size
/ sizeof (* iconf
))
18838 error (_("Overlarge number of conflicts detected: %lx\n"),
18839 (long) conflictsno
);
18843 iconf
= (Elf32_Conflict
*) cmalloc (conflictsno
, sizeof (* iconf
));
18846 error (_("Out of memory allocating space for dynamic conflicts\n"));
18852 Elf32_External_Conflict
* econf32
;
18854 econf32
= (Elf32_External_Conflict
*)
18855 get_data (NULL
, filedata
, conflicts_offset
,
18856 sizeof (*econf32
), conflictsno
, _("conflict"));
18863 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
18864 iconf
[cnt
] = BYTE_GET (econf32
[cnt
]);
18870 Elf64_External_Conflict
* econf64
;
18872 econf64
= (Elf64_External_Conflict
*)
18873 get_data (NULL
, filedata
, conflicts_offset
,
18874 sizeof (*econf64
), conflictsno
, _("conflict"));
18881 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
18882 iconf
[cnt
] = BYTE_GET (econf64
[cnt
]);
18887 printf (ngettext ("\nSection '.conflict' contains %lu entry:\n",
18888 "\nSection '.conflict' contains %lu entries:\n",
18889 (unsigned long) conflictsno
),
18890 (unsigned long) conflictsno
);
18891 puts (_(" Num: Index Value Name"));
18893 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
18895 printf ("%5lu: %8lu ", (unsigned long) cnt
, iconf
[cnt
]);
18897 if (iconf
[cnt
] >= filedata
->num_dynamic_syms
)
18898 printf (_("<corrupt symbol index>"));
18901 Elf_Internal_Sym
* psym
;
18903 psym
= & filedata
->dynamic_symbols
[iconf
[cnt
]];
18904 print_vma (psym
->st_value
, FULL_HEX
);
18906 if (valid_dynamic_name (filedata
, psym
->st_name
))
18907 print_symbol (25, get_dynamic_name (filedata
, psym
->st_name
));
18909 printf (_("<corrupt: %14ld>"), psym
->st_name
);
18917 if (pltgot
!= 0 && local_gotno
!= 0)
18919 bfd_vma ent
, local_end
, global_end
;
18921 unsigned char * data
;
18922 unsigned char * data_end
;
18926 addr_size
= (is_32bit_elf
? 4 : 8);
18927 local_end
= pltgot
+ local_gotno
* addr_size
;
18929 /* PR binutils/17533 file: 012-111227-0.004 */
18930 if (symtabno
< gotsym
)
18932 error (_("The GOT symbol offset (%lu) is greater than the symbol table size (%lu)\n"),
18933 (unsigned long) gotsym
, (unsigned long) symtabno
);
18937 global_end
= local_end
+ (symtabno
- gotsym
) * addr_size
;
18938 /* PR 17531: file: 54c91a34. */
18939 if (global_end
< local_end
)
18941 error (_("Too many GOT symbols: %lu\n"), (unsigned long) symtabno
);
18945 offset
= offset_from_vma (filedata
, pltgot
, global_end
- pltgot
);
18946 data
= (unsigned char *) get_data (NULL
, filedata
, offset
,
18947 global_end
- pltgot
, 1,
18948 _("Global Offset Table data"));
18949 /* PR 12855: Null data is handled gracefully throughout. */
18950 data_end
= data
+ (global_end
- pltgot
);
18952 printf (_("\nPrimary GOT:\n"));
18953 printf (_(" Canonical gp value: "));
18954 print_vma (pltgot
+ 0x7ff0, LONG_HEX
);
18957 printf (_(" Reserved entries:\n"));
18958 printf (_(" %*s %10s %*s Purpose\n"),
18959 addr_size
* 2, _("Address"), _("Access"),
18960 addr_size
* 2, _("Initial"));
18961 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
18962 printf (_(" Lazy resolver\n"));
18963 if (ent
== (bfd_vma
) -1)
18964 goto got_print_fail
;
18966 /* Check for the MSB of GOT[1] being set, denoting a GNU object.
18967 This entry will be used by some runtime loaders, to store the
18968 module pointer. Otherwise this is an ordinary local entry.
18969 PR 21344: Check for the entry being fully available before
18972 && data
+ ent
- pltgot
+ addr_size
<= data_end
18973 && (byte_get (data
+ ent
- pltgot
, addr_size
)
18974 >> (addr_size
* 8 - 1)) != 0)
18976 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
18977 printf (_(" Module pointer (GNU extension)\n"));
18978 if (ent
== (bfd_vma
) -1)
18979 goto got_print_fail
;
18983 if (data
!= NULL
&& ent
< local_end
)
18985 printf (_(" Local entries:\n"));
18986 printf (" %*s %10s %*s\n",
18987 addr_size
* 2, _("Address"), _("Access"),
18988 addr_size
* 2, _("Initial"));
18989 while (ent
< local_end
)
18991 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
18993 if (ent
== (bfd_vma
) -1)
18994 goto got_print_fail
;
18999 if (data
!= NULL
&& gotsym
< symtabno
)
19003 printf (_(" Global entries:\n"));
19004 printf (" %*s %10s %*s %*s %-7s %3s %s\n",
19005 addr_size
* 2, _("Address"),
19007 addr_size
* 2, _("Initial"),
19008 addr_size
* 2, _("Sym.Val."),
19010 /* Note for translators: "Ndx" = abbreviated form of "Index". */
19011 _("Ndx"), _("Name"));
19013 sym_width
= (is_32bit_elf
? 80 : 160) - 28 - addr_size
* 6 - 1;
19015 for (i
= gotsym
; i
< symtabno
; i
++)
19017 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
19020 if (filedata
->dynamic_symbols
== NULL
)
19021 printf (_("<no dynamic symbols>"));
19022 else if (i
< filedata
->num_dynamic_syms
)
19024 Elf_Internal_Sym
* psym
= filedata
->dynamic_symbols
+ i
;
19026 print_vma (psym
->st_value
, LONG_HEX
);
19027 printf (" %-7s %3s ",
19028 get_symbol_type (filedata
, ELF_ST_TYPE (psym
->st_info
)),
19029 get_symbol_index_type (filedata
, psym
->st_shndx
));
19031 if (valid_dynamic_name (filedata
, psym
->st_name
))
19032 print_symbol (sym_width
,
19033 get_dynamic_name (filedata
, psym
->st_name
));
19035 printf (_("<corrupt: %14ld>"), psym
->st_name
);
19038 printf (_("<symbol index %lu exceeds number of dynamic symbols>"),
19039 (unsigned long) i
);
19042 if (ent
== (bfd_vma
) -1)
19052 if (mips_pltgot
!= 0 && jmprel
!= 0 && pltrel
!= 0 && pltrelsz
!= 0)
19055 size_t offset
, rel_offset
;
19056 unsigned long count
, i
;
19057 unsigned char * data
;
19058 int addr_size
, sym_width
;
19059 Elf_Internal_Rela
* rels
;
19061 rel_offset
= offset_from_vma (filedata
, jmprel
, pltrelsz
);
19062 if (pltrel
== DT_RELA
)
19064 if (!slurp_rela_relocs (filedata
, rel_offset
, pltrelsz
, &rels
, &count
))
19069 if (!slurp_rel_relocs (filedata
, rel_offset
, pltrelsz
, &rels
, &count
))
19074 addr_size
= (is_32bit_elf
? 4 : 8);
19075 end
= mips_pltgot
+ (2 + count
) * addr_size
;
19077 offset
= offset_from_vma (filedata
, mips_pltgot
, end
- mips_pltgot
);
19078 data
= (unsigned char *) get_data (NULL
, filedata
, offset
, end
- mips_pltgot
,
19079 1, _("Procedure Linkage Table data"));
19086 printf ("\nPLT GOT:\n\n");
19087 printf (_(" Reserved entries:\n"));
19088 printf (_(" %*s %*s Purpose\n"),
19089 addr_size
* 2, _("Address"), addr_size
* 2, _("Initial"));
19090 ent
= print_mips_pltgot_entry (data
, mips_pltgot
, ent
);
19091 printf (_(" PLT lazy resolver\n"));
19092 ent
= print_mips_pltgot_entry (data
, mips_pltgot
, ent
);
19093 printf (_(" Module pointer\n"));
19096 printf (_(" Entries:\n"));
19097 printf (" %*s %*s %*s %-7s %3s %s\n",
19098 addr_size
* 2, _("Address"),
19099 addr_size
* 2, _("Initial"),
19100 addr_size
* 2, _("Sym.Val."), _("Type"), _("Ndx"), _("Name"));
19101 sym_width
= (is_32bit_elf
? 80 : 160) - 17 - addr_size
* 6 - 1;
19102 for (i
= 0; i
< count
; i
++)
19104 unsigned long idx
= get_reloc_symindex (rels
[i
].r_info
);
19106 ent
= print_mips_pltgot_entry (data
, mips_pltgot
, ent
);
19109 if (idx
>= filedata
->num_dynamic_syms
)
19110 printf (_("<corrupt symbol index: %lu>"), idx
);
19113 Elf_Internal_Sym
* psym
= filedata
->dynamic_symbols
+ idx
;
19115 print_vma (psym
->st_value
, LONG_HEX
);
19116 printf (" %-7s %3s ",
19117 get_symbol_type (filedata
, ELF_ST_TYPE (psym
->st_info
)),
19118 get_symbol_index_type (filedata
, psym
->st_shndx
));
19119 if (valid_dynamic_name (filedata
, psym
->st_name
))
19120 print_symbol (sym_width
,
19121 get_dynamic_name (filedata
, psym
->st_name
));
19123 printf (_("<corrupt: %14ld>"), psym
->st_name
);
19137 process_nds32_specific (Filedata
* filedata
)
19139 Elf_Internal_Shdr
*sect
= NULL
;
19141 sect
= find_section (filedata
, ".nds32_e_flags");
19142 if (sect
!= NULL
&& sect
->sh_size
>= 4)
19144 unsigned char *buf
;
19147 printf ("\nNDS32 elf flags section:\n");
19148 buf
= get_data (NULL
, filedata
, sect
->sh_offset
, 1, 4,
19149 _("NDS32 elf flags section"));
19154 flag
= byte_get (buf
, 4);
19156 switch (flag
& 0x3)
19159 printf ("(VEC_SIZE):\tNo entry.\n");
19162 printf ("(VEC_SIZE):\t4 bytes\n");
19165 printf ("(VEC_SIZE):\t16 bytes\n");
19168 printf ("(VEC_SIZE):\treserved\n");
19177 process_gnu_liblist (Filedata
* filedata
)
19179 Elf_Internal_Shdr
* section
;
19180 Elf_Internal_Shdr
* string_sec
;
19181 Elf32_External_Lib
* elib
;
19183 size_t strtab_size
;
19185 unsigned long num_liblist
;
19192 for (i
= 0, section
= filedata
->section_headers
;
19193 i
< filedata
->file_header
.e_shnum
;
19196 switch (section
->sh_type
)
19198 case SHT_GNU_LIBLIST
:
19199 if (section
->sh_link
>= filedata
->file_header
.e_shnum
)
19202 elib
= (Elf32_External_Lib
*)
19203 get_data (NULL
, filedata
, section
->sh_offset
, 1, section
->sh_size
,
19204 _("liblist section data"));
19212 string_sec
= filedata
->section_headers
+ section
->sh_link
;
19213 strtab
= (char *) get_data (NULL
, filedata
, string_sec
->sh_offset
, 1,
19214 string_sec
->sh_size
,
19215 _("liblist string table"));
19217 || section
->sh_entsize
!= sizeof (Elf32_External_Lib
))
19224 strtab_size
= string_sec
->sh_size
;
19226 num_liblist
= section
->sh_size
/ sizeof (Elf32_External_Lib
);
19227 printf (ngettext ("\nLibrary list section '%s' contains %lu entries:\n",
19228 "\nLibrary list section '%s' contains %lu entries:\n",
19230 printable_section_name (filedata
, section
),
19233 puts (_(" Library Time Stamp Checksum Version Flags"));
19235 for (cnt
= 0; cnt
< section
->sh_size
/ sizeof (Elf32_External_Lib
);
19243 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
19244 atime
= BYTE_GET (elib
[cnt
].l_time_stamp
);
19245 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
19246 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
19247 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
19249 tmp
= gmtime (&atime
);
19250 snprintf (timebuf
, sizeof (timebuf
),
19251 "%04u-%02u-%02uT%02u:%02u:%02u",
19252 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
19253 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
19255 printf ("%3lu: ", (unsigned long) cnt
);
19257 printf ("%-20s", liblist
.l_name
< strtab_size
19258 ? strtab
+ liblist
.l_name
: _("<corrupt>"));
19260 printf ("%-20.20s", liblist
.l_name
< strtab_size
19261 ? strtab
+ liblist
.l_name
: _("<corrupt>"));
19262 printf (" %s %#010lx %-7ld %-7ld\n", timebuf
, liblist
.l_checksum
,
19263 liblist
.l_version
, liblist
.l_flags
);
19274 static const char *
19275 get_note_type (Filedata
* filedata
, unsigned e_type
)
19277 static char buff
[64];
19279 if (filedata
->file_header
.e_type
== ET_CORE
)
19283 return _("NT_AUXV (auxiliary vector)");
19285 return _("NT_PRSTATUS (prstatus structure)");
19287 return _("NT_FPREGSET (floating point registers)");
19289 return _("NT_PRPSINFO (prpsinfo structure)");
19290 case NT_TASKSTRUCT
:
19291 return _("NT_TASKSTRUCT (task structure)");
19293 return _("NT_GDB_TDESC (GDB XML target description)");
19295 return _("NT_PRXFPREG (user_xfpregs structure)");
19297 return _("NT_PPC_VMX (ppc Altivec registers)");
19299 return _("NT_PPC_VSX (ppc VSX registers)");
19301 return _("NT_PPC_TAR (ppc TAR register)");
19303 return _("NT_PPC_PPR (ppc PPR register)");
19305 return _("NT_PPC_DSCR (ppc DSCR register)");
19307 return _("NT_PPC_EBB (ppc EBB registers)");
19309 return _("NT_PPC_PMU (ppc PMU registers)");
19310 case NT_PPC_TM_CGPR
:
19311 return _("NT_PPC_TM_CGPR (ppc checkpointed GPR registers)");
19312 case NT_PPC_TM_CFPR
:
19313 return _("NT_PPC_TM_CFPR (ppc checkpointed floating point registers)");
19314 case NT_PPC_TM_CVMX
:
19315 return _("NT_PPC_TM_CVMX (ppc checkpointed Altivec registers)");
19316 case NT_PPC_TM_CVSX
:
19317 return _("NT_PPC_TM_CVSX (ppc checkpointed VSX registers)");
19318 case NT_PPC_TM_SPR
:
19319 return _("NT_PPC_TM_SPR (ppc TM special purpose registers)");
19320 case NT_PPC_TM_CTAR
:
19321 return _("NT_PPC_TM_CTAR (ppc checkpointed TAR register)");
19322 case NT_PPC_TM_CPPR
:
19323 return _("NT_PPC_TM_CPPR (ppc checkpointed PPR register)");
19324 case NT_PPC_TM_CDSCR
:
19325 return _("NT_PPC_TM_CDSCR (ppc checkpointed DSCR register)");
19327 return _("NT_386_TLS (x86 TLS information)");
19328 case NT_386_IOPERM
:
19329 return _("NT_386_IOPERM (x86 I/O permissions)");
19330 case NT_X86_XSTATE
:
19331 return _("NT_X86_XSTATE (x86 XSAVE extended state)");
19333 return _("NT_X86_CET (x86 CET state)");
19334 case NT_S390_HIGH_GPRS
:
19335 return _("NT_S390_HIGH_GPRS (s390 upper register halves)");
19336 case NT_S390_TIMER
:
19337 return _("NT_S390_TIMER (s390 timer register)");
19338 case NT_S390_TODCMP
:
19339 return _("NT_S390_TODCMP (s390 TOD comparator register)");
19340 case NT_S390_TODPREG
:
19341 return _("NT_S390_TODPREG (s390 TOD programmable register)");
19343 return _("NT_S390_CTRS (s390 control registers)");
19344 case NT_S390_PREFIX
:
19345 return _("NT_S390_PREFIX (s390 prefix register)");
19346 case NT_S390_LAST_BREAK
:
19347 return _("NT_S390_LAST_BREAK (s390 last breaking event address)");
19348 case NT_S390_SYSTEM_CALL
:
19349 return _("NT_S390_SYSTEM_CALL (s390 system call restart data)");
19351 return _("NT_S390_TDB (s390 transaction diagnostic block)");
19352 case NT_S390_VXRS_LOW
:
19353 return _("NT_S390_VXRS_LOW (s390 vector registers 0-15 upper half)");
19354 case NT_S390_VXRS_HIGH
:
19355 return _("NT_S390_VXRS_HIGH (s390 vector registers 16-31)");
19356 case NT_S390_GS_CB
:
19357 return _("NT_S390_GS_CB (s390 guarded-storage registers)");
19358 case NT_S390_GS_BC
:
19359 return _("NT_S390_GS_BC (s390 guarded-storage broadcast control)");
19361 return _("NT_ARM_VFP (arm VFP registers)");
19363 return _("NT_ARM_TLS (AArch TLS registers)");
19364 case NT_ARM_HW_BREAK
:
19365 return _("NT_ARM_HW_BREAK (AArch hardware breakpoint registers)");
19366 case NT_ARM_HW_WATCH
:
19367 return _("NT_ARM_HW_WATCH (AArch hardware watchpoint registers)");
19368 case NT_ARM_SYSTEM_CALL
:
19369 return _("NT_ARM_SYSTEM_CALL (AArch system call number)");
19371 return _("NT_ARM_SVE (AArch SVE registers)");
19372 case NT_ARM_PAC_MASK
:
19373 return _("NT_ARM_PAC_MASK (AArch pointer authentication code masks)");
19374 case NT_ARM_PACA_KEYS
:
19375 return _("NT_ARM_PACA_KEYS (ARM pointer authentication address keys)");
19376 case NT_ARM_PACG_KEYS
:
19377 return _("NT_ARM_PACG_KEYS (ARM pointer authentication generic keys)");
19378 case NT_ARM_TAGGED_ADDR_CTRL
:
19379 return _("NT_ARM_TAGGED_ADDR_CTRL (AArch tagged address control)");
19380 case NT_ARM_PAC_ENABLED_KEYS
:
19381 return _("NT_ARM_PAC_ENABLED_KEYS (AArch64 pointer authentication enabled keys)");
19383 return _("NT_ARC_V2 (ARC HS accumulator/extra registers)");
19385 return _("NT_RISCV_CSR (RISC-V control and status registers)");
19387 return _("NT_PSTATUS (pstatus structure)");
19389 return _("NT_FPREGS (floating point registers)");
19391 return _("NT_PSINFO (psinfo structure)");
19393 return _("NT_LWPSTATUS (lwpstatus_t structure)");
19395 return _("NT_LWPSINFO (lwpsinfo_t structure)");
19396 case NT_WIN32PSTATUS
:
19397 return _("NT_WIN32PSTATUS (win32_pstatus structure)");
19399 return _("NT_SIGINFO (siginfo_t data)");
19401 return _("NT_FILE (mapped files)");
19409 return _("NT_VERSION (version)");
19411 return _("NT_ARCH (architecture)");
19412 case NT_GNU_BUILD_ATTRIBUTE_OPEN
:
19414 case NT_GNU_BUILD_ATTRIBUTE_FUNC
:
19416 case NT_GO_BUILDID
:
19417 return _("GO BUILDID");
19418 case FDO_PACKAGING_METADATA
:
19419 return _("FDO_PACKAGING_METADATA");
19424 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
19429 print_core_note (Elf_Internal_Note
*pnote
)
19431 unsigned int addr_size
= is_32bit_elf
? 4 : 8;
19432 bfd_vma count
, page_size
;
19433 unsigned char *descdata
, *filenames
, *descend
;
19435 if (pnote
->type
!= NT_FILE
)
19445 printf (_(" Cannot decode 64-bit note in 32-bit build\n"));
19446 /* Still "successful". */
19451 if (pnote
->descsz
< 2 * addr_size
)
19453 error (_(" Malformed note - too short for header\n"));
19457 descdata
= (unsigned char *) pnote
->descdata
;
19458 descend
= descdata
+ pnote
->descsz
;
19460 if (descdata
[pnote
->descsz
- 1] != '\0')
19462 error (_(" Malformed note - does not end with \\0\n"));
19466 count
= byte_get (descdata
, addr_size
);
19467 descdata
+= addr_size
;
19469 page_size
= byte_get (descdata
, addr_size
);
19470 descdata
+= addr_size
;
19472 if (count
> ((bfd_vma
) -1 - 2 * addr_size
) / (3 * addr_size
)
19473 || pnote
->descsz
< 2 * addr_size
+ count
* 3 * addr_size
)
19475 error (_(" Malformed note - too short for supplied file count\n"));
19479 printf (_(" Page size: "));
19480 print_vma (page_size
, DEC
);
19483 printf (_(" %*s%*s%*s\n"),
19484 (int) (2 + 2 * addr_size
), _("Start"),
19485 (int) (4 + 2 * addr_size
), _("End"),
19486 (int) (4 + 2 * addr_size
), _("Page Offset"));
19487 filenames
= descdata
+ count
* 3 * addr_size
;
19488 while (count
-- > 0)
19490 bfd_vma start
, end
, file_ofs
;
19492 if (filenames
== descend
)
19494 error (_(" Malformed note - filenames end too early\n"));
19498 start
= byte_get (descdata
, addr_size
);
19499 descdata
+= addr_size
;
19500 end
= byte_get (descdata
, addr_size
);
19501 descdata
+= addr_size
;
19502 file_ofs
= byte_get (descdata
, addr_size
);
19503 descdata
+= addr_size
;
19506 print_vma (start
, FULL_HEX
);
19508 print_vma (end
, FULL_HEX
);
19510 print_vma (file_ofs
, FULL_HEX
);
19511 printf ("\n %s\n", filenames
);
19513 filenames
+= 1 + strlen ((char *) filenames
);
19519 static const char *
19520 get_gnu_elf_note_type (unsigned e_type
)
19522 /* NB/ Keep this switch statement in sync with print_gnu_note (). */
19525 case NT_GNU_ABI_TAG
:
19526 return _("NT_GNU_ABI_TAG (ABI version tag)");
19528 return _("NT_GNU_HWCAP (DSO-supplied software HWCAP info)");
19529 case NT_GNU_BUILD_ID
:
19530 return _("NT_GNU_BUILD_ID (unique build ID bitstring)");
19531 case NT_GNU_GOLD_VERSION
:
19532 return _("NT_GNU_GOLD_VERSION (gold version)");
19533 case NT_GNU_PROPERTY_TYPE_0
:
19534 return _("NT_GNU_PROPERTY_TYPE_0");
19535 case NT_GNU_BUILD_ATTRIBUTE_OPEN
:
19536 return _("NT_GNU_BUILD_ATTRIBUTE_OPEN");
19537 case NT_GNU_BUILD_ATTRIBUTE_FUNC
:
19538 return _("NT_GNU_BUILD_ATTRIBUTE_FUNC");
19541 static char buff
[64];
19543 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
19550 decode_x86_compat_isa (unsigned int bitmask
)
19554 unsigned int bit
= bitmask
& (- bitmask
);
19559 case GNU_PROPERTY_X86_COMPAT_ISA_1_486
:
19562 case GNU_PROPERTY_X86_COMPAT_ISA_1_586
:
19565 case GNU_PROPERTY_X86_COMPAT_ISA_1_686
:
19568 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE
:
19571 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE2
:
19574 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE3
:
19577 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSSE3
:
19580 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE4_1
:
19583 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE4_2
:
19586 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX
:
19589 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX2
:
19592 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512F
:
19593 printf ("AVX512F");
19595 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512CD
:
19596 printf ("AVX512CD");
19598 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512ER
:
19599 printf ("AVX512ER");
19601 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512PF
:
19602 printf ("AVX512PF");
19604 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512VL
:
19605 printf ("AVX512VL");
19607 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512DQ
:
19608 printf ("AVX512DQ");
19610 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512BW
:
19611 printf ("AVX512BW");
19614 printf (_("<unknown: %x>"), bit
);
19623 decode_x86_compat_2_isa (unsigned int bitmask
)
19627 printf (_("<None>"));
19633 unsigned int bit
= bitmask
& (- bitmask
);
19638 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_CMOV
:
19641 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE
:
19644 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE2
:
19647 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE3
:
19650 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSSE3
:
19653 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE4_1
:
19656 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE4_2
:
19659 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX
:
19662 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX2
:
19665 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_FMA
:
19668 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512F
:
19669 printf ("AVX512F");
19671 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512CD
:
19672 printf ("AVX512CD");
19674 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512ER
:
19675 printf ("AVX512ER");
19677 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512PF
:
19678 printf ("AVX512PF");
19680 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512VL
:
19681 printf ("AVX512VL");
19683 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512DQ
:
19684 printf ("AVX512DQ");
19686 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512BW
:
19687 printf ("AVX512BW");
19689 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_4FMAPS
:
19690 printf ("AVX512_4FMAPS");
19692 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_4VNNIW
:
19693 printf ("AVX512_4VNNIW");
19695 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_BITALG
:
19696 printf ("AVX512_BITALG");
19698 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_IFMA
:
19699 printf ("AVX512_IFMA");
19701 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_VBMI
:
19702 printf ("AVX512_VBMI");
19704 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_VBMI2
:
19705 printf ("AVX512_VBMI2");
19707 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_VNNI
:
19708 printf ("AVX512_VNNI");
19710 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_BF16
:
19711 printf ("AVX512_BF16");
19714 printf (_("<unknown: %x>"), bit
);
19722 static const char *
19723 get_amdgpu_elf_note_type (unsigned int e_type
)
19727 case NT_AMDGPU_METADATA
:
19728 return _("NT_AMDGPU_METADATA (code object metadata)");
19731 static char buf
[64];
19732 snprintf (buf
, sizeof (buf
), _("Unknown note type: (0x%08x)"), e_type
);
19739 decode_x86_isa (unsigned int bitmask
)
19743 unsigned int bit
= bitmask
& (- bitmask
);
19748 case GNU_PROPERTY_X86_ISA_1_BASELINE
:
19749 printf ("x86-64-baseline");
19751 case GNU_PROPERTY_X86_ISA_1_V2
:
19752 printf ("x86-64-v2");
19754 case GNU_PROPERTY_X86_ISA_1_V3
:
19755 printf ("x86-64-v3");
19757 case GNU_PROPERTY_X86_ISA_1_V4
:
19758 printf ("x86-64-v4");
19761 printf (_("<unknown: %x>"), bit
);
19770 decode_x86_feature_1 (unsigned int bitmask
)
19774 printf (_("<None>"));
19780 unsigned int bit
= bitmask
& (- bitmask
);
19785 case GNU_PROPERTY_X86_FEATURE_1_IBT
:
19788 case GNU_PROPERTY_X86_FEATURE_1_SHSTK
:
19791 case GNU_PROPERTY_X86_FEATURE_1_LAM_U48
:
19792 printf ("LAM_U48");
19794 case GNU_PROPERTY_X86_FEATURE_1_LAM_U57
:
19795 printf ("LAM_U57");
19798 printf (_("<unknown: %x>"), bit
);
19807 decode_x86_feature_2 (unsigned int bitmask
)
19811 printf (_("<None>"));
19817 unsigned int bit
= bitmask
& (- bitmask
);
19822 case GNU_PROPERTY_X86_FEATURE_2_X86
:
19825 case GNU_PROPERTY_X86_FEATURE_2_X87
:
19828 case GNU_PROPERTY_X86_FEATURE_2_MMX
:
19831 case GNU_PROPERTY_X86_FEATURE_2_XMM
:
19834 case GNU_PROPERTY_X86_FEATURE_2_YMM
:
19837 case GNU_PROPERTY_X86_FEATURE_2_ZMM
:
19840 case GNU_PROPERTY_X86_FEATURE_2_TMM
:
19843 case GNU_PROPERTY_X86_FEATURE_2_MASK
:
19846 case GNU_PROPERTY_X86_FEATURE_2_FXSR
:
19849 case GNU_PROPERTY_X86_FEATURE_2_XSAVE
:
19852 case GNU_PROPERTY_X86_FEATURE_2_XSAVEOPT
:
19853 printf ("XSAVEOPT");
19855 case GNU_PROPERTY_X86_FEATURE_2_XSAVEC
:
19859 printf (_("<unknown: %x>"), bit
);
19868 decode_aarch64_feature_1_and (unsigned int bitmask
)
19872 unsigned int bit
= bitmask
& (- bitmask
);
19877 case GNU_PROPERTY_AARCH64_FEATURE_1_BTI
:
19881 case GNU_PROPERTY_AARCH64_FEATURE_1_PAC
:
19886 printf (_("<unknown: %x>"), bit
);
19895 decode_1_needed (unsigned int bitmask
)
19899 unsigned int bit
= bitmask
& (- bitmask
);
19904 case GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS
:
19905 printf ("indirect external access");
19908 printf (_("<unknown: %x>"), bit
);
19917 print_gnu_property_note (Filedata
* filedata
, Elf_Internal_Note
* pnote
)
19919 unsigned char * ptr
= (unsigned char *) pnote
->descdata
;
19920 unsigned char * ptr_end
= ptr
+ pnote
->descsz
;
19921 unsigned int size
= is_32bit_elf
? 4 : 8;
19923 printf (_(" Properties: "));
19925 if (pnote
->descsz
< 8 || (pnote
->descsz
% size
) != 0)
19927 printf (_("<corrupt GNU_PROPERTY_TYPE, size = %#lx>\n"), pnote
->descsz
);
19931 while (ptr
< ptr_end
)
19935 unsigned int datasz
;
19937 if ((size_t) (ptr_end
- ptr
) < 8)
19939 printf (_("<corrupt descsz: %#lx>\n"), pnote
->descsz
);
19943 type
= byte_get (ptr
, 4);
19944 datasz
= byte_get (ptr
+ 4, 4);
19948 if (datasz
> (size_t) (ptr_end
- ptr
))
19950 printf (_("<corrupt type (%#x) datasz: %#x>\n"),
19955 if (type
>= GNU_PROPERTY_LOPROC
&& type
<= GNU_PROPERTY_HIPROC
)
19957 if (filedata
->file_header
.e_machine
== EM_X86_64
19958 || filedata
->file_header
.e_machine
== EM_IAMCU
19959 || filedata
->file_header
.e_machine
== EM_386
)
19961 unsigned int bitmask
;
19964 bitmask
= byte_get (ptr
, 4);
19970 case GNU_PROPERTY_X86_ISA_1_USED
:
19972 printf (_("x86 ISA used: <corrupt length: %#x> "),
19976 printf ("x86 ISA used: ");
19977 decode_x86_isa (bitmask
);
19981 case GNU_PROPERTY_X86_ISA_1_NEEDED
:
19983 printf (_("x86 ISA needed: <corrupt length: %#x> "),
19987 printf ("x86 ISA needed: ");
19988 decode_x86_isa (bitmask
);
19992 case GNU_PROPERTY_X86_FEATURE_1_AND
:
19994 printf (_("x86 feature: <corrupt length: %#x> "),
19998 printf ("x86 feature: ");
19999 decode_x86_feature_1 (bitmask
);
20003 case GNU_PROPERTY_X86_FEATURE_2_USED
:
20005 printf (_("x86 feature used: <corrupt length: %#x> "),
20009 printf ("x86 feature used: ");
20010 decode_x86_feature_2 (bitmask
);
20014 case GNU_PROPERTY_X86_FEATURE_2_NEEDED
:
20016 printf (_("x86 feature needed: <corrupt length: %#x> "), datasz
);
20019 printf ("x86 feature needed: ");
20020 decode_x86_feature_2 (bitmask
);
20024 case GNU_PROPERTY_X86_COMPAT_ISA_1_USED
:
20026 printf (_("x86 ISA used: <corrupt length: %#x> "),
20030 printf ("x86 ISA used: ");
20031 decode_x86_compat_isa (bitmask
);
20035 case GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED
:
20037 printf (_("x86 ISA needed: <corrupt length: %#x> "),
20041 printf ("x86 ISA needed: ");
20042 decode_x86_compat_isa (bitmask
);
20046 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_USED
:
20048 printf (_("x86 ISA used: <corrupt length: %#x> "),
20052 printf ("x86 ISA used: ");
20053 decode_x86_compat_2_isa (bitmask
);
20057 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_NEEDED
:
20059 printf (_("x86 ISA needed: <corrupt length: %#x> "),
20063 printf ("x86 ISA needed: ");
20064 decode_x86_compat_2_isa (bitmask
);
20072 else if (filedata
->file_header
.e_machine
== EM_AARCH64
)
20074 if (type
== GNU_PROPERTY_AARCH64_FEATURE_1_AND
)
20076 printf ("AArch64 feature: ");
20078 printf (_("<corrupt length: %#x> "), datasz
);
20080 decode_aarch64_feature_1_and (byte_get (ptr
, 4));
20089 case GNU_PROPERTY_STACK_SIZE
:
20090 printf (_("stack size: "));
20091 if (datasz
!= size
)
20092 printf (_("<corrupt length: %#x> "), datasz
);
20094 printf ("%#lx", (unsigned long) byte_get (ptr
, size
));
20097 case GNU_PROPERTY_NO_COPY_ON_PROTECTED
:
20098 printf ("no copy on protected ");
20100 printf (_("<corrupt length: %#x> "), datasz
);
20104 if ((type
>= GNU_PROPERTY_UINT32_AND_LO
20105 && type
<= GNU_PROPERTY_UINT32_AND_HI
)
20106 || (type
>= GNU_PROPERTY_UINT32_OR_LO
20107 && type
<= GNU_PROPERTY_UINT32_OR_HI
))
20111 case GNU_PROPERTY_1_NEEDED
:
20113 printf (_("1_needed: <corrupt length: %#x> "),
20117 unsigned int bitmask
= byte_get (ptr
, 4);
20118 printf ("1_needed: ");
20119 decode_1_needed (bitmask
);
20126 if (type
<= GNU_PROPERTY_UINT32_AND_HI
)
20127 printf (_("UINT32_AND (%#x): "), type
);
20129 printf (_("UINT32_OR (%#x): "), type
);
20131 printf (_("<corrupt length: %#x> "), datasz
);
20133 printf ("%#x", (unsigned int) byte_get (ptr
, 4));
20140 if (type
< GNU_PROPERTY_LOPROC
)
20141 printf (_("<unknown type %#x data: "), type
);
20142 else if (type
< GNU_PROPERTY_LOUSER
)
20143 printf (_("<processor-specific type %#x data: "), type
);
20145 printf (_("<application-specific type %#x data: "), type
);
20146 for (j
= 0; j
< datasz
; ++j
)
20147 printf ("%02x ", ptr
[j
] & 0xff);
20151 ptr
+= ((datasz
+ (size
- 1)) & ~ (size
- 1));
20152 if (ptr
== ptr_end
)
20165 print_gnu_note (Filedata
* filedata
, Elf_Internal_Note
*pnote
)
20167 /* NB/ Keep this switch statement in sync with get_gnu_elf_note_type (). */
20168 switch (pnote
->type
)
20170 case NT_GNU_BUILD_ID
:
20174 printf (_(" Build ID: "));
20175 for (i
= 0; i
< pnote
->descsz
; ++i
)
20176 printf ("%02x", pnote
->descdata
[i
] & 0xff);
20181 case NT_GNU_ABI_TAG
:
20183 unsigned long os
, major
, minor
, subminor
;
20184 const char *osname
;
20186 /* PR 17531: file: 030-599401-0.004. */
20187 if (pnote
->descsz
< 16)
20189 printf (_(" <corrupt GNU_ABI_TAG>\n"));
20193 os
= byte_get ((unsigned char *) pnote
->descdata
, 4);
20194 major
= byte_get ((unsigned char *) pnote
->descdata
+ 4, 4);
20195 minor
= byte_get ((unsigned char *) pnote
->descdata
+ 8, 4);
20196 subminor
= byte_get ((unsigned char *) pnote
->descdata
+ 12, 4);
20200 case GNU_ABI_TAG_LINUX
:
20203 case GNU_ABI_TAG_HURD
:
20206 case GNU_ABI_TAG_SOLARIS
:
20207 osname
= "Solaris";
20209 case GNU_ABI_TAG_FREEBSD
:
20210 osname
= "FreeBSD";
20212 case GNU_ABI_TAG_NETBSD
:
20215 case GNU_ABI_TAG_SYLLABLE
:
20216 osname
= "Syllable";
20218 case GNU_ABI_TAG_NACL
:
20222 osname
= "Unknown";
20226 printf (_(" OS: %s, ABI: %ld.%ld.%ld\n"), osname
,
20227 major
, minor
, subminor
);
20231 case NT_GNU_GOLD_VERSION
:
20235 printf (_(" Version: "));
20236 for (i
= 0; i
< pnote
->descsz
&& pnote
->descdata
[i
] != '\0'; ++i
)
20237 printf ("%c", pnote
->descdata
[i
]);
20244 unsigned long num_entries
, mask
;
20246 /* Hardware capabilities information. Word 0 is the number of entries.
20247 Word 1 is a bitmask of enabled entries. The rest of the descriptor
20248 is a series of entries, where each entry is a single byte followed
20249 by a nul terminated string. The byte gives the bit number to test
20250 if enabled in the bitmask. */
20251 printf (_(" Hardware Capabilities: "));
20252 if (pnote
->descsz
< 8)
20254 error (_("<corrupt GNU_HWCAP>\n"));
20257 num_entries
= byte_get ((unsigned char *) pnote
->descdata
, 4);
20258 mask
= byte_get ((unsigned char *) pnote
->descdata
+ 4, 4);
20259 printf (_("num entries: %ld, enabled mask: %lx\n"), num_entries
, mask
);
20260 /* FIXME: Add code to display the entries... */
20264 case NT_GNU_PROPERTY_TYPE_0
:
20265 print_gnu_property_note (filedata
, pnote
);
20269 /* Handle unrecognised types. An error message should have already been
20270 created by get_gnu_elf_note_type(), so all that we need to do is to
20271 display the data. */
20275 printf (_(" Description data: "));
20276 for (i
= 0; i
< pnote
->descsz
; ++i
)
20277 printf ("%02x ", pnote
->descdata
[i
] & 0xff);
20286 static const char *
20287 get_v850_elf_note_type (enum v850_notes n_type
)
20289 static char buff
[64];
20293 case V850_NOTE_ALIGNMENT
: return _("Alignment of 8-byte objects");
20294 case V850_NOTE_DATA_SIZE
: return _("Sizeof double and long double");
20295 case V850_NOTE_FPU_INFO
: return _("Type of FPU support needed");
20296 case V850_NOTE_SIMD_INFO
: return _("Use of SIMD instructions");
20297 case V850_NOTE_CACHE_INFO
: return _("Use of cache");
20298 case V850_NOTE_MMU_INFO
: return _("Use of MMU");
20300 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), n_type
);
20306 print_v850_note (Elf_Internal_Note
* pnote
)
20310 if (pnote
->descsz
!= 4)
20313 val
= byte_get ((unsigned char *) pnote
->descdata
, pnote
->descsz
);
20317 printf (_("not set\n"));
20321 switch (pnote
->type
)
20323 case V850_NOTE_ALIGNMENT
:
20326 case EF_RH850_DATA_ALIGN4
: printf (_("4-byte\n")); return true;
20327 case EF_RH850_DATA_ALIGN8
: printf (_("8-byte\n")); return true;
20331 case V850_NOTE_DATA_SIZE
:
20334 case EF_RH850_DOUBLE32
: printf (_("4-bytes\n")); return true;
20335 case EF_RH850_DOUBLE64
: printf (_("8-bytes\n")); return true;
20339 case V850_NOTE_FPU_INFO
:
20342 case EF_RH850_FPU20
: printf (_("FPU-2.0\n")); return true;
20343 case EF_RH850_FPU30
: printf (_("FPU-3.0\n")); return true;
20347 case V850_NOTE_MMU_INFO
:
20348 case V850_NOTE_CACHE_INFO
:
20349 case V850_NOTE_SIMD_INFO
:
20350 if (val
== EF_RH850_SIMD
)
20352 printf (_("yes\n"));
20358 /* An 'unknown note type' message will already have been displayed. */
20362 printf (_("unknown value: %x\n"), val
);
20367 process_netbsd_elf_note (Elf_Internal_Note
* pnote
)
20369 unsigned int version
;
20371 switch (pnote
->type
)
20373 case NT_NETBSD_IDENT
:
20374 if (pnote
->descsz
< 1)
20376 version
= byte_get ((unsigned char *) pnote
->descdata
, sizeof (version
));
20377 if ((version
/ 10000) % 100)
20378 printf (" NetBSD\t\t0x%08lx\tIDENT %u (%u.%u%s%c)\n", pnote
->descsz
,
20379 version
, version
/ 100000000, (version
/ 1000000) % 100,
20380 (version
/ 10000) % 100 > 26 ? "Z" : "",
20381 'A' + (version
/ 10000) % 26);
20383 printf (" NetBSD\t\t0x%08lx\tIDENT %u (%u.%u.%u)\n", pnote
->descsz
,
20384 version
, version
/ 100000000, (version
/ 1000000) % 100,
20385 (version
/ 100) % 100);
20388 case NT_NETBSD_MARCH
:
20389 printf (" NetBSD\t\t0x%08lx\tMARCH <%s>\n", pnote
->descsz
,
20393 case NT_NETBSD_PAX
:
20394 if (pnote
->descsz
< 1)
20396 version
= byte_get ((unsigned char *) pnote
->descdata
, sizeof (version
));
20397 printf (" NetBSD\t\t0x%08lx\tPaX <%s%s%s%s%s%s>\n", pnote
->descsz
,
20398 ((version
& NT_NETBSD_PAX_MPROTECT
) ? "+mprotect" : ""),
20399 ((version
& NT_NETBSD_PAX_NOMPROTECT
) ? "-mprotect" : ""),
20400 ((version
& NT_NETBSD_PAX_GUARD
) ? "+guard" : ""),
20401 ((version
& NT_NETBSD_PAX_NOGUARD
) ? "-guard" : ""),
20402 ((version
& NT_NETBSD_PAX_ASLR
) ? "+ASLR" : ""),
20403 ((version
& NT_NETBSD_PAX_NOASLR
) ? "-ASLR" : ""));
20407 printf (" NetBSD\t0x%08lx\tUnknown note type: (0x%08lx)\n",
20408 pnote
->descsz
, pnote
->type
);
20412 static const char *
20413 get_freebsd_elfcore_note_type (Filedata
* filedata
, unsigned e_type
)
20417 case NT_FREEBSD_THRMISC
:
20418 return _("NT_THRMISC (thrmisc structure)");
20419 case NT_FREEBSD_PROCSTAT_PROC
:
20420 return _("NT_PROCSTAT_PROC (proc data)");
20421 case NT_FREEBSD_PROCSTAT_FILES
:
20422 return _("NT_PROCSTAT_FILES (files data)");
20423 case NT_FREEBSD_PROCSTAT_VMMAP
:
20424 return _("NT_PROCSTAT_VMMAP (vmmap data)");
20425 case NT_FREEBSD_PROCSTAT_GROUPS
:
20426 return _("NT_PROCSTAT_GROUPS (groups data)");
20427 case NT_FREEBSD_PROCSTAT_UMASK
:
20428 return _("NT_PROCSTAT_UMASK (umask data)");
20429 case NT_FREEBSD_PROCSTAT_RLIMIT
:
20430 return _("NT_PROCSTAT_RLIMIT (rlimit data)");
20431 case NT_FREEBSD_PROCSTAT_OSREL
:
20432 return _("NT_PROCSTAT_OSREL (osreldate data)");
20433 case NT_FREEBSD_PROCSTAT_PSSTRINGS
:
20434 return _("NT_PROCSTAT_PSSTRINGS (ps_strings data)");
20435 case NT_FREEBSD_PROCSTAT_AUXV
:
20436 return _("NT_PROCSTAT_AUXV (auxv data)");
20437 case NT_FREEBSD_PTLWPINFO
:
20438 return _("NT_PTLWPINFO (ptrace_lwpinfo structure)");
20439 case NT_FREEBSD_X86_SEGBASES
:
20440 return _("NT_X86_SEGBASES (x86 segment base registers)");
20442 return get_note_type (filedata
, e_type
);
20445 static const char *
20446 get_netbsd_elfcore_note_type (Filedata
* filedata
, unsigned e_type
)
20448 static char buff
[64];
20452 case NT_NETBSDCORE_PROCINFO
:
20453 /* NetBSD core "procinfo" structure. */
20454 return _("NetBSD procinfo structure");
20456 case NT_NETBSDCORE_AUXV
:
20457 return _("NetBSD ELF auxiliary vector data");
20459 case NT_NETBSDCORE_LWPSTATUS
:
20460 return _("PT_LWPSTATUS (ptrace_lwpstatus structure)");
20463 /* As of Jan 2020 there are no other machine-independent notes
20464 defined for NetBSD core files. If the note type is less
20465 than the start of the machine-dependent note types, we don't
20468 if (e_type
< NT_NETBSDCORE_FIRSTMACH
)
20470 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
20476 switch (filedata
->file_header
.e_machine
)
20478 /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0
20479 and PT_GETFPREGS == mach+2. */
20484 case EM_SPARC32PLUS
:
20488 case NT_NETBSDCORE_FIRSTMACH
+ 0:
20489 return _("PT_GETREGS (reg structure)");
20490 case NT_NETBSDCORE_FIRSTMACH
+ 2:
20491 return _("PT_GETFPREGS (fpreg structure)");
20497 /* On SuperH, PT_GETREGS == mach+3 and PT_GETFPREGS == mach+5.
20498 There's also old PT___GETREGS40 == mach + 1 for old reg
20499 structure which lacks GBR. */
20503 case NT_NETBSDCORE_FIRSTMACH
+ 1:
20504 return _("PT___GETREGS40 (old reg structure)");
20505 case NT_NETBSDCORE_FIRSTMACH
+ 3:
20506 return _("PT_GETREGS (reg structure)");
20507 case NT_NETBSDCORE_FIRSTMACH
+ 5:
20508 return _("PT_GETFPREGS (fpreg structure)");
20514 /* On all other arch's, PT_GETREGS == mach+1 and
20515 PT_GETFPREGS == mach+3. */
20519 case NT_NETBSDCORE_FIRSTMACH
+ 1:
20520 return _("PT_GETREGS (reg structure)");
20521 case NT_NETBSDCORE_FIRSTMACH
+ 3:
20522 return _("PT_GETFPREGS (fpreg structure)");
20528 snprintf (buff
, sizeof (buff
), "PT_FIRSTMACH+%d",
20529 e_type
- NT_NETBSDCORE_FIRSTMACH
);
20533 static const char *
20534 get_openbsd_elfcore_note_type (Filedata
* filedata
, unsigned e_type
)
20538 case NT_OPENBSD_PROCINFO
:
20539 return _("OpenBSD procinfo structure");
20540 case NT_OPENBSD_AUXV
:
20541 return _("OpenBSD ELF auxiliary vector data");
20542 case NT_OPENBSD_REGS
:
20543 return _("OpenBSD regular registers");
20544 case NT_OPENBSD_FPREGS
:
20545 return _("OpenBSD floating point registers");
20546 case NT_OPENBSD_WCOOKIE
:
20547 return _("OpenBSD window cookie");
20550 return get_note_type (filedata
, e_type
);
20553 static const char *
20554 get_stapsdt_note_type (unsigned e_type
)
20556 static char buff
[64];
20561 return _("NT_STAPSDT (SystemTap probe descriptors)");
20567 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
20572 print_stapsdt_note (Elf_Internal_Note
*pnote
)
20574 size_t len
, maxlen
;
20575 unsigned long addr_size
= is_32bit_elf
? 4 : 8;
20576 char *data
= pnote
->descdata
;
20577 char *data_end
= pnote
->descdata
+ pnote
->descsz
;
20578 bfd_vma pc
, base_addr
, semaphore
;
20579 char *provider
, *probe
, *arg_fmt
;
20581 if (pnote
->descsz
< (addr_size
* 3))
20582 goto stapdt_note_too_small
;
20584 pc
= byte_get ((unsigned char *) data
, addr_size
);
20587 base_addr
= byte_get ((unsigned char *) data
, addr_size
);
20590 semaphore
= byte_get ((unsigned char *) data
, addr_size
);
20593 if (data
>= data_end
)
20594 goto stapdt_note_too_small
;
20595 maxlen
= data_end
- data
;
20596 len
= strnlen (data
, maxlen
);
20603 goto stapdt_note_too_small
;
20605 if (data
>= data_end
)
20606 goto stapdt_note_too_small
;
20607 maxlen
= data_end
- data
;
20608 len
= strnlen (data
, maxlen
);
20615 goto stapdt_note_too_small
;
20617 if (data
>= data_end
)
20618 goto stapdt_note_too_small
;
20619 maxlen
= data_end
- data
;
20620 len
= strnlen (data
, maxlen
);
20627 goto stapdt_note_too_small
;
20629 printf (_(" Provider: %s\n"), provider
);
20630 printf (_(" Name: %s\n"), probe
);
20631 printf (_(" Location: "));
20632 print_vma (pc
, FULL_HEX
);
20633 printf (_(", Base: "));
20634 print_vma (base_addr
, FULL_HEX
);
20635 printf (_(", Semaphore: "));
20636 print_vma (semaphore
, FULL_HEX
);
20638 printf (_(" Arguments: %s\n"), arg_fmt
);
20640 return data
== data_end
;
20642 stapdt_note_too_small
:
20643 printf (_(" <corrupt - note is too small>\n"));
20644 error (_("corrupt stapdt note - the data size is too small\n"));
20649 print_fdo_note (Elf_Internal_Note
* pnote
)
20651 if (pnote
->descsz
> 0 && pnote
->type
== FDO_PACKAGING_METADATA
)
20653 printf (_(" Packaging Metadata: %.*s\n"), (int) pnote
->descsz
, pnote
->descdata
);
20659 static const char *
20660 get_ia64_vms_note_type (unsigned e_type
)
20662 static char buff
[64];
20667 return _("NT_VMS_MHD (module header)");
20669 return _("NT_VMS_LNM (language name)");
20671 return _("NT_VMS_SRC (source files)");
20673 return "NT_VMS_TITLE";
20675 return _("NT_VMS_EIDC (consistency check)");
20676 case NT_VMS_FPMODE
:
20677 return _("NT_VMS_FPMODE (FP mode)");
20678 case NT_VMS_LINKTIME
:
20679 return "NT_VMS_LINKTIME";
20680 case NT_VMS_IMGNAM
:
20681 return _("NT_VMS_IMGNAM (image name)");
20683 return _("NT_VMS_IMGID (image id)");
20684 case NT_VMS_LINKID
:
20685 return _("NT_VMS_LINKID (link id)");
20686 case NT_VMS_IMGBID
:
20687 return _("NT_VMS_IMGBID (build id)");
20688 case NT_VMS_GSTNAM
:
20689 return _("NT_VMS_GSTNAM (sym table name)");
20690 case NT_VMS_ORIG_DYN
:
20691 return "NT_VMS_ORIG_DYN";
20692 case NT_VMS_PATCHTIME
:
20693 return "NT_VMS_PATCHTIME";
20695 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
20701 print_ia64_vms_note (Elf_Internal_Note
* pnote
)
20703 int maxlen
= pnote
->descsz
;
20705 if (maxlen
< 2 || (unsigned long) maxlen
!= pnote
->descsz
)
20706 goto desc_size_fail
;
20708 switch (pnote
->type
)
20712 goto desc_size_fail
;
20714 int l
= (int) strnlen (pnote
->descdata
+ 34, maxlen
- 34);
20716 printf (_(" Creation date : %.17s\n"), pnote
->descdata
);
20717 printf (_(" Last patch date: %.17s\n"), pnote
->descdata
+ 17);
20718 if (l
+ 34 < maxlen
)
20720 printf (_(" Module name : %s\n"), pnote
->descdata
+ 34);
20721 if (l
+ 35 < maxlen
)
20722 printf (_(" Module version : %s\n"), pnote
->descdata
+ 34 + l
+ 1);
20724 printf (_(" Module version : <missing>\n"));
20728 printf (_(" Module name : <missing>\n"));
20729 printf (_(" Module version : <missing>\n"));
20734 printf (_(" Language: %.*s\n"), maxlen
, pnote
->descdata
);
20738 case NT_VMS_FPMODE
:
20739 printf (_(" Floating Point mode: "));
20741 goto desc_size_fail
;
20742 /* FIXME: Generate an error if descsz > 8 ? */
20744 printf ("0x%016" BFD_VMA_FMT
"x\n",
20745 (bfd_vma
) byte_get ((unsigned char *) pnote
->descdata
, 8));
20748 case NT_VMS_LINKTIME
:
20749 printf (_(" Link time: "));
20751 goto desc_size_fail
;
20752 /* FIXME: Generate an error if descsz > 8 ? */
20754 print_vms_time (byte_get ((unsigned char *) pnote
->descdata
, 8));
20758 case NT_VMS_PATCHTIME
:
20759 printf (_(" Patch time: "));
20761 goto desc_size_fail
;
20762 /* FIXME: Generate an error if descsz > 8 ? */
20764 print_vms_time (byte_get ((unsigned char *) pnote
->descdata
, 8));
20768 case NT_VMS_ORIG_DYN
:
20770 goto desc_size_fail
;
20772 printf (_(" Major id: %u, minor id: %u\n"),
20773 (unsigned) byte_get ((unsigned char *) pnote
->descdata
, 4),
20774 (unsigned) byte_get ((unsigned char *) pnote
->descdata
+ 4, 4));
20775 printf (_(" Last modified : "));
20776 print_vms_time (byte_get ((unsigned char *) pnote
->descdata
+ 8, 8));
20777 printf (_("\n Link flags : "));
20778 printf ("0x%016" BFD_VMA_FMT
"x\n",
20779 (bfd_vma
) byte_get ((unsigned char *) pnote
->descdata
+ 16, 8));
20780 printf (_(" Header flags: 0x%08x\n"),
20781 (unsigned) byte_get ((unsigned char *) pnote
->descdata
+ 24, 4));
20782 printf (_(" Image id : %.*s\n"), maxlen
- 32, pnote
->descdata
+ 32);
20786 case NT_VMS_IMGNAM
:
20787 printf (_(" Image name: %.*s\n"), maxlen
, pnote
->descdata
);
20790 case NT_VMS_GSTNAM
:
20791 printf (_(" Global symbol table name: %.*s\n"), maxlen
, pnote
->descdata
);
20795 printf (_(" Image id: %.*s\n"), maxlen
, pnote
->descdata
);
20798 case NT_VMS_LINKID
:
20799 printf (_(" Linker id: %.*s\n"), maxlen
, pnote
->descdata
);
20809 printf (_(" <corrupt - data size is too small>\n"));
20810 error (_("corrupt IA64 note: data size is too small\n"));
20814 struct build_attr_cache
{
20815 Filedata
*filedata
;
20817 unsigned long strtablen
;
20818 Elf_Internal_Sym
*symtab
;
20819 unsigned long nsyms
;
20822 /* Find the symbol associated with a build attribute that is attached
20823 to address OFFSET. If PNAME is non-NULL then store the name of
20824 the symbol (if found) in the provided pointer, Returns NULL if a
20825 symbol could not be found. */
20827 static Elf_Internal_Sym
*
20828 get_symbol_for_build_attribute (Filedata
*filedata
,
20829 unsigned long offset
,
20831 const char **pname
)
20833 Elf_Internal_Sym
*saved_sym
= NULL
;
20834 Elf_Internal_Sym
*sym
;
20836 if (filedata
->section_headers
!= NULL
20837 && (ba_cache
.filedata
== NULL
|| filedata
!= ba_cache
.filedata
))
20839 Elf_Internal_Shdr
* symsec
;
20841 free (ba_cache
.strtab
);
20842 ba_cache
.strtab
= NULL
;
20843 free (ba_cache
.symtab
);
20844 ba_cache
.symtab
= NULL
;
20846 /* Load the symbol and string sections. */
20847 for (symsec
= filedata
->section_headers
;
20848 symsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
20851 if (symsec
->sh_type
== SHT_SYMTAB
20852 && get_symtab (filedata
, symsec
,
20853 &ba_cache
.symtab
, &ba_cache
.nsyms
,
20854 &ba_cache
.strtab
, &ba_cache
.strtablen
))
20857 ba_cache
.filedata
= filedata
;
20860 if (ba_cache
.symtab
== NULL
)
20863 /* Find a symbol whose value matches offset. */
20864 for (sym
= ba_cache
.symtab
; sym
< ba_cache
.symtab
+ ba_cache
.nsyms
; sym
++)
20865 if (sym
->st_value
== offset
)
20867 if (sym
->st_name
>= ba_cache
.strtablen
)
20868 /* Huh ? This should not happen. */
20871 if (ba_cache
.strtab
[sym
->st_name
] == 0)
20874 /* The AArch64, ARM and RISC-V architectures define mapping symbols
20875 (eg $d, $x, $t) which we want to ignore. */
20876 if (ba_cache
.strtab
[sym
->st_name
] == '$'
20877 && ba_cache
.strtab
[sym
->st_name
+ 1] != 0
20878 && ba_cache
.strtab
[sym
->st_name
+ 2] == 0)
20883 /* For OPEN attributes we prefer GLOBAL over LOCAL symbols
20884 and FILE or OBJECT symbols over NOTYPE symbols. We skip
20885 FUNC symbols entirely. */
20886 switch (ELF_ST_TYPE (sym
->st_info
))
20893 /* If the symbol has a size associated
20894 with it then we can stop searching. */
20895 sym
= ba_cache
.symtab
+ ba_cache
.nsyms
;
20900 /* Ignore function symbols. */
20907 switch (ELF_ST_BIND (sym
->st_info
))
20910 if (saved_sym
== NULL
20911 || ELF_ST_TYPE (saved_sym
->st_info
) != STT_OBJECT
)
20916 if (saved_sym
== NULL
)
20926 if (ELF_ST_TYPE (sym
->st_info
) != STT_FUNC
)
20934 if (saved_sym
&& pname
)
20935 * pname
= ba_cache
.strtab
+ saved_sym
->st_name
;
20940 /* Returns true iff addr1 and addr2 are in the same section. */
20943 same_section (Filedata
* filedata
, unsigned long addr1
, unsigned long addr2
)
20945 Elf_Internal_Shdr
* a1
;
20946 Elf_Internal_Shdr
* a2
;
20948 a1
= find_section_by_address (filedata
, addr1
);
20949 a2
= find_section_by_address (filedata
, addr2
);
20951 return a1
== a2
&& a1
!= NULL
;
20955 print_gnu_build_attribute_description (Elf_Internal_Note
* pnote
,
20956 Filedata
* filedata
)
20958 static unsigned long global_offset
= 0;
20959 static unsigned long global_end
= 0;
20960 static unsigned long func_offset
= 0;
20961 static unsigned long func_end
= 0;
20963 Elf_Internal_Sym
*sym
;
20965 unsigned long start
;
20967 bool is_open_attr
= pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_OPEN
;
20969 switch (pnote
->descsz
)
20972 /* A zero-length description means that the range of
20973 the previous note of the same type should be used. */
20976 if (global_end
> global_offset
)
20977 printf (_(" Applies to region from %#lx to %#lx\n"),
20978 global_offset
, global_end
);
20980 printf (_(" Applies to region from %#lx\n"), global_offset
);
20984 if (func_end
> func_offset
)
20985 printf (_(" Applies to region from %#lx to %#lx\n"), func_offset
, func_end
);
20987 printf (_(" Applies to region from %#lx\n"), func_offset
);
20992 start
= byte_get ((unsigned char *) pnote
->descdata
, 4);
20997 start
= byte_get ((unsigned char *) pnote
->descdata
, 4);
20998 end
= byte_get ((unsigned char *) pnote
->descdata
+ 4, 4);
21002 start
= byte_get ((unsigned char *) pnote
->descdata
, 8);
21003 end
= byte_get ((unsigned char *) pnote
->descdata
+ 8, 8);
21007 error (_(" <invalid description size: %lx>\n"), pnote
->descsz
);
21008 printf (_(" <invalid descsz>"));
21013 sym
= get_symbol_for_build_attribute (filedata
, start
, is_open_attr
, & name
);
21014 /* As of version 5 of the annobin plugin, filename symbols are biased by 2
21015 in order to avoid them being confused with the start address of the
21016 first function in the file... */
21017 if (sym
== NULL
&& is_open_attr
)
21018 sym
= get_symbol_for_build_attribute (filedata
, start
+ 2, is_open_attr
,
21021 if (end
== 0 && sym
!= NULL
&& sym
->st_size
> 0)
21022 end
= start
+ sym
->st_size
;
21026 /* FIXME: Need to properly allow for section alignment.
21027 16 is just the alignment used on x86_64. */
21029 && start
> BFD_ALIGN (global_end
, 16)
21030 /* Build notes are not guaranteed to be organised in order of
21031 increasing address, but we should find the all of the notes
21032 for one section in the same place. */
21033 && same_section (filedata
, start
, global_end
))
21034 warn (_("Gap in build notes detected from %#lx to %#lx\n"),
21035 global_end
+ 1, start
- 1);
21037 printf (_(" Applies to region from %#lx"), start
);
21038 global_offset
= start
;
21042 printf (_(" to %#lx"), end
);
21048 printf (_(" Applies to region from %#lx"), start
);
21049 func_offset
= start
;
21053 printf (_(" to %#lx"), end
);
21059 printf (_(" (%s)"), name
);
21066 print_gnu_build_attribute_name (Elf_Internal_Note
* pnote
)
21068 static const char string_expected
[2] = { GNU_BUILD_ATTRIBUTE_TYPE_STRING
, 0 };
21069 static const char number_expected
[2] = { GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC
, 0 };
21070 static const char bool_expected
[3] = { GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE
, GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE
, 0 };
21072 char name_attribute
;
21073 const char * expected_types
;
21074 const char * name
= pnote
->namedata
;
21078 if (name
== NULL
|| pnote
->namesz
< 2)
21080 error (_("corrupt name field in GNU build attribute note: size = %ld\n"), pnote
->namesz
);
21081 print_symbol (-20, _(" <corrupt name>"));
21090 /* Version 2 of the spec adds a "GA" prefix to the name field. */
21091 if (name
[0] == 'G' && name
[1] == 'A')
21093 if (pnote
->namesz
< 4)
21095 error (_("corrupt name field in GNU build attribute note: size = %ld\n"), pnote
->namesz
);
21096 print_symbol (-20, _(" <corrupt name>"));
21105 switch ((name_type
= * name
))
21107 case GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC
:
21108 case GNU_BUILD_ATTRIBUTE_TYPE_STRING
:
21109 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE
:
21110 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE
:
21111 printf ("%c", * name
);
21115 error (_("unrecognised attribute type in name field: %d\n"), name_type
);
21116 print_symbol (-20, _("<unknown name type>"));
21123 switch ((name_attribute
= * name
))
21125 case GNU_BUILD_ATTRIBUTE_VERSION
:
21126 text
= _("<version>");
21127 expected_types
= string_expected
;
21130 case GNU_BUILD_ATTRIBUTE_STACK_PROT
:
21131 text
= _("<stack prot>");
21132 expected_types
= "!+*";
21135 case GNU_BUILD_ATTRIBUTE_RELRO
:
21136 text
= _("<relro>");
21137 expected_types
= bool_expected
;
21140 case GNU_BUILD_ATTRIBUTE_STACK_SIZE
:
21141 text
= _("<stack size>");
21142 expected_types
= number_expected
;
21145 case GNU_BUILD_ATTRIBUTE_TOOL
:
21146 text
= _("<tool>");
21147 expected_types
= string_expected
;
21150 case GNU_BUILD_ATTRIBUTE_ABI
:
21152 expected_types
= "$*";
21155 case GNU_BUILD_ATTRIBUTE_PIC
:
21157 expected_types
= number_expected
;
21160 case GNU_BUILD_ATTRIBUTE_SHORT_ENUM
:
21161 text
= _("<short enum>");
21162 expected_types
= bool_expected
;
21166 if (ISPRINT (* name
))
21168 int len
= strnlen (name
, pnote
->namesz
- (name
- pnote
->namedata
)) + 1;
21170 if (len
> left
&& ! do_wide
)
21172 printf ("%.*s:", len
, name
);
21178 static char tmpbuf
[128];
21180 error (_("unrecognised byte in name field: %d\n"), * name
);
21181 sprintf (tmpbuf
, _("<unknown:_%d>"), * name
);
21185 expected_types
= "*$!+";
21190 left
-= printf ("%s", text
);
21192 if (strchr (expected_types
, name_type
) == NULL
)
21193 warn (_("attribute does not have an expected type (%c)\n"), name_type
);
21195 if ((unsigned long)(name
- pnote
->namedata
) > pnote
->namesz
)
21197 error (_("corrupt name field: namesz: %lu but parsing gets to %ld\n"),
21198 (unsigned long) pnote
->namesz
,
21199 (long) (name
- pnote
->namedata
));
21203 if (left
< 1 && ! do_wide
)
21208 case GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC
:
21210 unsigned int bytes
;
21211 unsigned long long val
= 0;
21212 unsigned int shift
= 0;
21213 char * decoded
= NULL
;
21215 bytes
= pnote
->namesz
- (name
- pnote
->namedata
);
21217 /* The -1 is because the name field is always 0 terminated, and we
21218 want to be able to ensure that the shift in the while loop below
21219 will not overflow. */
21222 if (bytes
> sizeof (val
))
21224 error (_("corrupt numeric name field: too many bytes in the value: %x\n"),
21226 bytes
= sizeof (val
);
21228 /* We do not bother to warn if bytes == 0 as this can
21229 happen with some early versions of the gcc plugin. */
21233 unsigned long long byte
= *name
++ & 0xff;
21235 val
|= byte
<< shift
;
21239 switch (name_attribute
)
21241 case GNU_BUILD_ATTRIBUTE_PIC
:
21244 case 0: decoded
= "static"; break;
21245 case 1: decoded
= "pic"; break;
21246 case 2: decoded
= "PIC"; break;
21247 case 3: decoded
= "pie"; break;
21248 case 4: decoded
= "PIE"; break;
21252 case GNU_BUILD_ATTRIBUTE_STACK_PROT
:
21255 /* Based upon the SPCT_FLAG_xxx enum values in gcc/cfgexpand.c. */
21256 case 0: decoded
= "off"; break;
21257 case 1: decoded
= "on"; break;
21258 case 2: decoded
= "all"; break;
21259 case 3: decoded
= "strong"; break;
21260 case 4: decoded
= "explicit"; break;
21268 if (decoded
!= NULL
)
21270 print_symbol (-left
, decoded
);
21281 left
-= printf ("0x%llx", val
);
21283 left
-= printf ("0x%-.*llx", left
, val
);
21287 case GNU_BUILD_ATTRIBUTE_TYPE_STRING
:
21288 left
-= print_symbol (- left
, name
);
21290 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE
:
21291 left
-= print_symbol (- left
, "true");
21293 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE
:
21294 left
-= print_symbol (- left
, "false");
21298 if (do_wide
&& left
> 0)
21299 printf ("%-*s", left
, " ");
21304 /* Print the contents of PNOTE as hex. */
21307 print_note_contents_hex (Elf_Internal_Note
*pnote
)
21313 printf (_(" description data: "));
21314 for (i
= 0; i
< pnote
->descsz
; i
++)
21315 printf ("%02x ", pnote
->descdata
[i
] & 0xff);
21324 #if defined HAVE_MSGPACK
21327 print_indents (int n
)
21331 for (int i
= 0; i
< n
; i
++)
21335 /* Print OBJ in human-readable form. */
21338 dump_msgpack_obj (const msgpack_object
*obj
, int indent
)
21342 case MSGPACK_OBJECT_NIL
:
21346 case MSGPACK_OBJECT_BOOLEAN
:
21347 printf ("%s", obj
->via
.boolean
? "true" : "false");
21350 case MSGPACK_OBJECT_POSITIVE_INTEGER
:
21351 printf ("%" PRIu64
, obj
->via
.u64
);
21354 case MSGPACK_OBJECT_NEGATIVE_INTEGER
:
21355 printf ("%" PRIi64
, obj
->via
.i64
);
21358 case MSGPACK_OBJECT_FLOAT32
:
21359 case MSGPACK_OBJECT_FLOAT64
:
21360 printf ("%f", obj
->via
.f64
);
21363 case MSGPACK_OBJECT_STR
:
21364 printf ("\"%.*s\"", obj
->via
.str
.size
, obj
->via
.str
.ptr
);
21367 case MSGPACK_OBJECT_ARRAY
:
21369 const msgpack_object_array
*array
= &obj
->via
.array
;
21374 for (uint32_t i
= 0; i
< array
->size
; ++i
)
21376 const msgpack_object
*item
= &array
->ptr
[i
];
21378 print_indents (indent
);
21379 dump_msgpack_obj (item
, indent
);
21384 print_indents (indent
);
21390 case MSGPACK_OBJECT_MAP
:
21392 const msgpack_object_map
*map
= &obj
->via
.map
;
21397 for (uint32_t i
= 0; i
< map
->size
; ++i
)
21399 const msgpack_object_kv
*kv
= &map
->ptr
[i
];
21400 const msgpack_object
*key
= &kv
->key
;
21401 const msgpack_object
*val
= &kv
->val
;
21403 print_indents (indent
);
21404 dump_msgpack_obj (key
, indent
);
21406 dump_msgpack_obj (val
, indent
);
21412 print_indents (indent
);
21418 case MSGPACK_OBJECT_BIN
:
21422 case MSGPACK_OBJECT_EXT
:
21429 dump_msgpack (const msgpack_unpacked
*msg
)
21432 dump_msgpack_obj (&msg
->data
, 0);
21436 #endif /* defined HAVE_MSGPACK */
21439 print_amdgpu_note (Elf_Internal_Note
*pnote
)
21441 #if defined HAVE_MSGPACK
21442 /* If msgpack is available, decode and dump the note's content. */
21444 msgpack_unpacked msg
;
21445 msgpack_unpack_return msgpack_ret
;
21447 assert (pnote
->type
== NT_AMDGPU_METADATA
);
21449 msgpack_unpacked_init (&msg
);
21450 msgpack_ret
= msgpack_unpack_next (&msg
, pnote
->descdata
, pnote
->descsz
,
21453 switch (msgpack_ret
)
21455 case MSGPACK_UNPACK_SUCCESS
:
21456 dump_msgpack (&msg
);
21461 error (_("failed to unpack msgpack contents in NT_AMDGPU_METADATA note"));
21466 msgpack_unpacked_destroy (&msg
);
21469 /* msgpack is not available, dump contents as hex. */
21470 print_note_contents_hex (pnote
);
21475 /* Note that by the ELF standard, the name field is already null byte
21476 terminated, and namesz includes the terminating null byte.
21477 I.E. the value of namesz for the name "FSF" is 4.
21479 If the value of namesz is zero, there is no name present. */
21482 process_note (Elf_Internal_Note
* pnote
,
21483 Filedata
* filedata
)
21485 const char * name
= pnote
->namesz
? pnote
->namedata
: "(NONE)";
21488 if (pnote
->namesz
== 0)
21489 /* If there is no note name, then use the default set of
21490 note type strings. */
21491 nt
= get_note_type (filedata
, pnote
->type
);
21493 else if (startswith (pnote
->namedata
, "GNU"))
21494 /* GNU-specific object file notes. */
21495 nt
= get_gnu_elf_note_type (pnote
->type
);
21497 else if (startswith (pnote
->namedata
, "AMDGPU"))
21498 /* AMDGPU-specific object file notes. */
21499 nt
= get_amdgpu_elf_note_type (pnote
->type
);
21501 else if (startswith (pnote
->namedata
, "FreeBSD"))
21502 /* FreeBSD-specific core file notes. */
21503 nt
= get_freebsd_elfcore_note_type (filedata
, pnote
->type
);
21505 else if (startswith (pnote
->namedata
, "NetBSD-CORE"))
21506 /* NetBSD-specific core file notes. */
21507 nt
= get_netbsd_elfcore_note_type (filedata
, pnote
->type
);
21509 else if (startswith (pnote
->namedata
, "NetBSD"))
21510 /* NetBSD-specific core file notes. */
21511 return process_netbsd_elf_note (pnote
);
21513 else if (startswith (pnote
->namedata
, "PaX"))
21514 /* NetBSD-specific core file notes. */
21515 return process_netbsd_elf_note (pnote
);
21517 else if (startswith (pnote
->namedata
, "OpenBSD"))
21518 /* OpenBSD-specific core file notes. */
21519 nt
= get_openbsd_elfcore_note_type (filedata
, pnote
->type
);
21521 else if (startswith (pnote
->namedata
, "SPU/"))
21523 /* SPU-specific core file notes. */
21524 nt
= pnote
->namedata
+ 4;
21528 else if (startswith (pnote
->namedata
, "IPF/VMS"))
21529 /* VMS/ia64-specific file notes. */
21530 nt
= get_ia64_vms_note_type (pnote
->type
);
21532 else if (startswith (pnote
->namedata
, "stapsdt"))
21533 nt
= get_stapsdt_note_type (pnote
->type
);
21536 /* Don't recognize this note name; just use the default set of
21537 note type strings. */
21538 nt
= get_note_type (filedata
, pnote
->type
);
21542 if (((startswith (pnote
->namedata
, "GA")
21543 && strchr ("*$!+", pnote
->namedata
[2]) != NULL
)
21544 || strchr ("*$!+", pnote
->namedata
[0]) != NULL
)
21545 && (pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_OPEN
21546 || pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_FUNC
))
21547 print_gnu_build_attribute_name (pnote
);
21549 print_symbol (-20, name
);
21552 printf (" 0x%08lx\t%s\t", pnote
->descsz
, nt
);
21554 printf (" 0x%08lx\t%s\n", pnote
->descsz
, nt
);
21556 if (startswith (pnote
->namedata
, "IPF/VMS"))
21557 return print_ia64_vms_note (pnote
);
21558 else if (startswith (pnote
->namedata
, "GNU"))
21559 return print_gnu_note (filedata
, pnote
);
21560 else if (startswith (pnote
->namedata
, "stapsdt"))
21561 return print_stapsdt_note (pnote
);
21562 else if (startswith (pnote
->namedata
, "CORE"))
21563 return print_core_note (pnote
);
21564 else if (startswith (pnote
->namedata
, "FDO"))
21565 return print_fdo_note (pnote
);
21566 else if (((startswith (pnote
->namedata
, "GA")
21567 && strchr ("*$!+", pnote
->namedata
[2]) != NULL
)
21568 || strchr ("*$!+", pnote
->namedata
[0]) != NULL
)
21569 && (pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_OPEN
21570 || pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_FUNC
))
21571 return print_gnu_build_attribute_description (pnote
, filedata
);
21572 else if (startswith (pnote
->namedata
, "AMDGPU")
21573 && pnote
->type
== NT_AMDGPU_METADATA
)
21574 return print_amdgpu_note (pnote
);
21576 print_note_contents_hex (pnote
);
21581 process_notes_at (Filedata
* filedata
,
21582 Elf_Internal_Shdr
* section
,
21587 Elf_External_Note
*pnotes
;
21588 Elf_External_Note
*external
;
21597 pnotes
= (Elf_External_Note
*) get_section_contents (section
, filedata
);
21600 if (! apply_relocations (filedata
, section
, (unsigned char *) pnotes
, length
, NULL
, NULL
))
21608 pnotes
= (Elf_External_Note
*) get_data (NULL
, filedata
, offset
, 1, length
,
21611 if (pnotes
== NULL
)
21616 if (filedata
->is_separate
)
21617 printf (_("In linked file '%s': "), filedata
->file_name
);
21621 printf (_("Displaying notes found in: %s\n"), printable_section_name (filedata
, section
));
21623 printf (_("Displaying notes found at file offset 0x%08lx with length 0x%08lx:\n"),
21624 (unsigned long) offset
, (unsigned long) length
);
21626 /* NB: Some note sections may have alignment value of 0 or 1. gABI
21627 specifies that notes should be aligned to 4 bytes in 32-bit
21628 objects and to 8 bytes in 64-bit objects. As a Linux extension,
21629 we also support 4 byte alignment in 64-bit objects. If section
21630 alignment is less than 4, we treate alignment as 4 bytes. */
21633 else if (align
!= 4 && align
!= 8)
21635 warn (_("Corrupt note: alignment %ld, expecting 4 or 8\n"),
21641 printf (_(" %-20s %-10s\tDescription\n"), _("Owner"), _("Data size"));
21643 end
= (char *) pnotes
+ length
;
21644 while ((char *) external
< end
)
21646 Elf_Internal_Note inote
;
21649 char * temp
= NULL
;
21650 size_t data_remaining
= end
- (char *) external
;
21652 if (!is_ia64_vms (filedata
))
21654 /* PR binutils/15191
21655 Make sure that there is enough data to read. */
21656 min_notesz
= offsetof (Elf_External_Note
, name
);
21657 if (data_remaining
< min_notesz
)
21659 warn (ngettext ("Corrupt note: only %ld byte remains, "
21660 "not enough for a full note\n",
21661 "Corrupt note: only %ld bytes remain, "
21662 "not enough for a full note\n",
21664 (long) data_remaining
);
21667 data_remaining
-= min_notesz
;
21669 inote
.type
= BYTE_GET (external
->type
);
21670 inote
.namesz
= BYTE_GET (external
->namesz
);
21671 inote
.namedata
= external
->name
;
21672 inote
.descsz
= BYTE_GET (external
->descsz
);
21673 inote
.descdata
= ((char *) external
21674 + ELF_NOTE_DESC_OFFSET (inote
.namesz
, align
));
21675 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
21676 next
= ((char *) external
21677 + ELF_NOTE_NEXT_OFFSET (inote
.namesz
, inote
.descsz
, align
));
21681 Elf64_External_VMS_Note
*vms_external
;
21683 /* PR binutils/15191
21684 Make sure that there is enough data to read. */
21685 min_notesz
= offsetof (Elf64_External_VMS_Note
, name
);
21686 if (data_remaining
< min_notesz
)
21688 warn (ngettext ("Corrupt note: only %ld byte remains, "
21689 "not enough for a full note\n",
21690 "Corrupt note: only %ld bytes remain, "
21691 "not enough for a full note\n",
21693 (long) data_remaining
);
21696 data_remaining
-= min_notesz
;
21698 vms_external
= (Elf64_External_VMS_Note
*) external
;
21699 inote
.type
= BYTE_GET (vms_external
->type
);
21700 inote
.namesz
= BYTE_GET (vms_external
->namesz
);
21701 inote
.namedata
= vms_external
->name
;
21702 inote
.descsz
= BYTE_GET (vms_external
->descsz
);
21703 inote
.descdata
= inote
.namedata
+ align_power (inote
.namesz
, 3);
21704 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
21705 next
= inote
.descdata
+ align_power (inote
.descsz
, 3);
21708 /* PR 17531: file: 3443835e. */
21709 /* PR 17531: file: id:000000,sig:11,src:006986,op:havoc,rep:4. */
21710 if ((size_t) (inote
.descdata
- inote
.namedata
) < inote
.namesz
21711 || (size_t) (inote
.descdata
- inote
.namedata
) > data_remaining
21712 || (size_t) (next
- inote
.descdata
) < inote
.descsz
21713 || ((size_t) (next
- inote
.descdata
)
21714 > data_remaining
- (size_t) (inote
.descdata
- inote
.namedata
)))
21716 warn (_("note with invalid namesz and/or descsz found at offset 0x%lx\n"),
21717 (unsigned long) ((char *) external
- (char *) pnotes
));
21718 warn (_(" type: 0x%lx, namesize: 0x%08lx, descsize: 0x%08lx, alignment: %u\n"),
21719 inote
.type
, inote
.namesz
, inote
.descsz
, (int) align
);
21723 external
= (Elf_External_Note
*) next
;
21725 /* Verify that name is null terminated. It appears that at least
21726 one version of Linux (RedHat 6.0) generates corefiles that don't
21727 comply with the ELF spec by failing to include the null byte in
21729 if (inote
.namesz
> 0 && inote
.namedata
[inote
.namesz
- 1] != '\0')
21731 if ((size_t) (inote
.descdata
- inote
.namedata
) == inote
.namesz
)
21733 temp
= (char *) malloc (inote
.namesz
+ 1);
21736 error (_("Out of memory allocating space for inote name\n"));
21741 memcpy (temp
, inote
.namedata
, inote
.namesz
);
21742 inote
.namedata
= temp
;
21744 inote
.namedata
[inote
.namesz
] = 0;
21747 if (! process_note (& inote
, filedata
))
21760 process_corefile_note_segments (Filedata
* filedata
)
21762 Elf_Internal_Phdr
*segment
;
21766 if (! get_program_headers (filedata
))
21769 for (i
= 0, segment
= filedata
->program_headers
;
21770 i
< filedata
->file_header
.e_phnum
;
21773 if (segment
->p_type
== PT_NOTE
)
21774 if (! process_notes_at (filedata
, NULL
,
21775 (bfd_vma
) segment
->p_offset
,
21776 (bfd_vma
) segment
->p_filesz
,
21777 (bfd_vma
) segment
->p_align
))
21785 process_v850_notes (Filedata
* filedata
, bfd_vma offset
, bfd_vma length
)
21787 Elf_External_Note
* pnotes
;
21788 Elf_External_Note
* external
;
21795 pnotes
= (Elf_External_Note
*) get_data (NULL
, filedata
, offset
, 1, length
,
21797 if (pnotes
== NULL
)
21801 end
= (char*) pnotes
+ length
;
21803 printf (_("\nDisplaying contents of Renesas V850 notes section at offset 0x%lx with length 0x%lx:\n"),
21804 (unsigned long) offset
, (unsigned long) length
);
21806 while ((char *) external
+ sizeof (Elf_External_Note
) < end
)
21808 Elf_External_Note
* next
;
21809 Elf_Internal_Note inote
;
21811 inote
.type
= BYTE_GET (external
->type
);
21812 inote
.namesz
= BYTE_GET (external
->namesz
);
21813 inote
.namedata
= external
->name
;
21814 inote
.descsz
= BYTE_GET (external
->descsz
);
21815 inote
.descdata
= inote
.namedata
+ align_power (inote
.namesz
, 2);
21816 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
21818 if (inote
.descdata
< (char *) pnotes
|| inote
.descdata
>= end
)
21820 warn (_("Corrupt note: name size is too big: %lx\n"), inote
.namesz
);
21821 inote
.descdata
= inote
.namedata
;
21825 next
= (Elf_External_Note
*) (inote
.descdata
+ align_power (inote
.descsz
, 2));
21827 if ( ((char *) next
> end
)
21828 || ((char *) next
< (char *) pnotes
))
21830 warn (_("corrupt descsz found in note at offset 0x%lx\n"),
21831 (unsigned long) ((char *) external
- (char *) pnotes
));
21832 warn (_(" type: 0x%lx, namesize: 0x%lx, descsize: 0x%lx\n"),
21833 inote
.type
, inote
.namesz
, inote
.descsz
);
21839 /* Prevent out-of-bounds indexing. */
21840 if ( inote
.namedata
+ inote
.namesz
> end
21841 || inote
.namedata
+ inote
.namesz
< inote
.namedata
)
21843 warn (_("corrupt namesz found in note at offset 0x%lx\n"),
21844 (unsigned long) ((char *) external
- (char *) pnotes
));
21845 warn (_(" type: 0x%lx, namesize: 0x%lx, descsize: 0x%lx\n"),
21846 inote
.type
, inote
.namesz
, inote
.descsz
);
21850 printf (" %s: ", get_v850_elf_note_type (inote
.type
));
21852 if (! print_v850_note (& inote
))
21855 printf ("<corrupt sizes: namesz: %lx, descsz: %lx>\n",
21856 inote
.namesz
, inote
.descsz
);
21866 process_note_sections (Filedata
* filedata
)
21868 Elf_Internal_Shdr
*section
;
21870 unsigned int n
= 0;
21873 for (i
= 0, section
= filedata
->section_headers
;
21874 i
< filedata
->file_header
.e_shnum
&& section
!= NULL
;
21877 if (section
->sh_type
== SHT_NOTE
)
21879 if (! process_notes_at (filedata
, section
,
21880 (bfd_vma
) section
->sh_offset
,
21881 (bfd_vma
) section
->sh_size
,
21882 (bfd_vma
) section
->sh_addralign
))
21887 if (( filedata
->file_header
.e_machine
== EM_V800
21888 || filedata
->file_header
.e_machine
== EM_V850
21889 || filedata
->file_header
.e_machine
== EM_CYGNUS_V850
)
21890 && section
->sh_type
== SHT_RENESAS_INFO
)
21892 if (! process_v850_notes (filedata
,
21893 (bfd_vma
) section
->sh_offset
,
21894 (bfd_vma
) section
->sh_size
))
21901 /* Try processing NOTE segments instead. */
21902 return process_corefile_note_segments (filedata
);
21908 process_notes (Filedata
* filedata
)
21910 /* If we have not been asked to display the notes then do nothing. */
21914 if (filedata
->file_header
.e_type
!= ET_CORE
)
21915 return process_note_sections (filedata
);
21917 /* No program headers means no NOTE segment. */
21918 if (filedata
->file_header
.e_phnum
> 0)
21919 return process_corefile_note_segments (filedata
);
21921 if (filedata
->is_separate
)
21922 printf (_("No notes found in linked file '%s'.\n"),
21923 filedata
->file_name
);
21925 printf (_("No notes found file.\n"));
21930 static unsigned char *
21931 display_public_gnu_attributes (unsigned char * start
,
21932 const unsigned char * const end
)
21934 printf (_(" Unknown GNU attribute: %s\n"), start
);
21936 start
+= strnlen ((char *) start
, end
- start
);
21937 display_raw_attribute (start
, end
);
21939 return (unsigned char *) end
;
21942 static unsigned char *
21943 display_generic_attribute (unsigned char * start
,
21945 const unsigned char * const end
)
21948 return (unsigned char *) end
;
21950 return display_tag_value (tag
, start
, end
);
21954 process_arch_specific (Filedata
* filedata
)
21959 switch (filedata
->file_header
.e_machine
)
21962 case EM_ARC_COMPACT
:
21963 case EM_ARC_COMPACT2
:
21964 return process_attributes (filedata
, "ARC", SHT_ARC_ATTRIBUTES
,
21965 display_arc_attribute
,
21966 display_generic_attribute
);
21968 return process_attributes (filedata
, "aeabi", SHT_ARM_ATTRIBUTES
,
21969 display_arm_attribute
,
21970 display_generic_attribute
);
21973 case EM_MIPS_RS3_LE
:
21974 return process_mips_specific (filedata
);
21977 return process_attributes (filedata
, "mspabi", SHT_MSP430_ATTRIBUTES
,
21978 display_msp430_attribute
,
21979 display_msp430_gnu_attribute
);
21982 return process_attributes (filedata
, "riscv", SHT_RISCV_ATTRIBUTES
,
21983 display_riscv_attribute
,
21984 display_generic_attribute
);
21987 return process_nds32_specific (filedata
);
21990 return process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
21991 display_m68k_gnu_attribute
);
21995 return process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
21996 display_power_gnu_attribute
);
22000 return process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
22001 display_s390_gnu_attribute
);
22004 case EM_SPARC32PLUS
:
22006 return process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
22007 display_sparc_gnu_attribute
);
22010 return process_attributes (filedata
, "c6xabi", SHT_C6000_ATTRIBUTES
,
22011 display_tic6x_attribute
,
22012 display_generic_attribute
);
22015 return process_attributes (filedata
, "csky", SHT_CSKY_ATTRIBUTES
,
22016 display_csky_attribute
, NULL
);
22019 return process_attributes (filedata
, "gnu", SHT_GNU_ATTRIBUTES
,
22020 display_public_gnu_attributes
,
22021 display_generic_attribute
);
22026 get_file_header (Filedata
* filedata
)
22028 /* Read in the identity array. */
22029 if (fread (filedata
->file_header
.e_ident
, EI_NIDENT
, 1, filedata
->handle
) != 1)
22032 /* Determine how to read the rest of the header. */
22033 switch (filedata
->file_header
.e_ident
[EI_DATA
])
22038 byte_get
= byte_get_little_endian
;
22039 byte_put
= byte_put_little_endian
;
22042 byte_get
= byte_get_big_endian
;
22043 byte_put
= byte_put_big_endian
;
22047 /* For now we only support 32 bit and 64 bit ELF files. */
22048 is_32bit_elf
= (filedata
->file_header
.e_ident
[EI_CLASS
] != ELFCLASS64
);
22050 /* Read in the rest of the header. */
22053 Elf32_External_Ehdr ehdr32
;
22055 if (fread (ehdr32
.e_type
, sizeof (ehdr32
) - EI_NIDENT
, 1, filedata
->handle
) != 1)
22058 filedata
->file_header
.e_type
= BYTE_GET (ehdr32
.e_type
);
22059 filedata
->file_header
.e_machine
= BYTE_GET (ehdr32
.e_machine
);
22060 filedata
->file_header
.e_version
= BYTE_GET (ehdr32
.e_version
);
22061 filedata
->file_header
.e_entry
= BYTE_GET (ehdr32
.e_entry
);
22062 filedata
->file_header
.e_phoff
= BYTE_GET (ehdr32
.e_phoff
);
22063 filedata
->file_header
.e_shoff
= BYTE_GET (ehdr32
.e_shoff
);
22064 filedata
->file_header
.e_flags
= BYTE_GET (ehdr32
.e_flags
);
22065 filedata
->file_header
.e_ehsize
= BYTE_GET (ehdr32
.e_ehsize
);
22066 filedata
->file_header
.e_phentsize
= BYTE_GET (ehdr32
.e_phentsize
);
22067 filedata
->file_header
.e_phnum
= BYTE_GET (ehdr32
.e_phnum
);
22068 filedata
->file_header
.e_shentsize
= BYTE_GET (ehdr32
.e_shentsize
);
22069 filedata
->file_header
.e_shnum
= BYTE_GET (ehdr32
.e_shnum
);
22070 filedata
->file_header
.e_shstrndx
= BYTE_GET (ehdr32
.e_shstrndx
);
22074 Elf64_External_Ehdr ehdr64
;
22076 /* If we have been compiled with sizeof (bfd_vma) == 4, then
22077 we will not be able to cope with the 64bit data found in
22078 64 ELF files. Detect this now and abort before we start
22079 overwriting things. */
22080 if (sizeof (bfd_vma
) < 8)
22082 error (_("This instance of readelf has been built without support for a\n\
22083 64 bit data type and so it cannot read 64 bit ELF files.\n"));
22087 if (fread (ehdr64
.e_type
, sizeof (ehdr64
) - EI_NIDENT
, 1, filedata
->handle
) != 1)
22090 filedata
->file_header
.e_type
= BYTE_GET (ehdr64
.e_type
);
22091 filedata
->file_header
.e_machine
= BYTE_GET (ehdr64
.e_machine
);
22092 filedata
->file_header
.e_version
= BYTE_GET (ehdr64
.e_version
);
22093 filedata
->file_header
.e_entry
= BYTE_GET (ehdr64
.e_entry
);
22094 filedata
->file_header
.e_phoff
= BYTE_GET (ehdr64
.e_phoff
);
22095 filedata
->file_header
.e_shoff
= BYTE_GET (ehdr64
.e_shoff
);
22096 filedata
->file_header
.e_flags
= BYTE_GET (ehdr64
.e_flags
);
22097 filedata
->file_header
.e_ehsize
= BYTE_GET (ehdr64
.e_ehsize
);
22098 filedata
->file_header
.e_phentsize
= BYTE_GET (ehdr64
.e_phentsize
);
22099 filedata
->file_header
.e_phnum
= BYTE_GET (ehdr64
.e_phnum
);
22100 filedata
->file_header
.e_shentsize
= BYTE_GET (ehdr64
.e_shentsize
);
22101 filedata
->file_header
.e_shnum
= BYTE_GET (ehdr64
.e_shnum
);
22102 filedata
->file_header
.e_shstrndx
= BYTE_GET (ehdr64
.e_shstrndx
);
22109 free_filedata (Filedata
*filedata
)
22111 free (filedata
->program_interpreter
);
22112 free (filedata
->program_headers
);
22113 free (filedata
->section_headers
);
22114 free (filedata
->string_table
);
22115 free (filedata
->dump
.dump_sects
);
22116 free (filedata
->dynamic_strings
);
22117 free (filedata
->dynamic_symbols
);
22118 free (filedata
->dynamic_syminfo
);
22119 free (filedata
->dynamic_section
);
22121 while (filedata
->symtab_shndx_list
!= NULL
)
22123 elf_section_list
*next
= filedata
->symtab_shndx_list
->next
;
22124 free (filedata
->symtab_shndx_list
);
22125 filedata
->symtab_shndx_list
= next
;
22128 free (filedata
->section_headers_groups
);
22130 if (filedata
->section_groups
)
22133 struct group_list
* g
;
22134 struct group_list
* next
;
22136 for (i
= 0; i
< filedata
->group_count
; i
++)
22138 for (g
= filedata
->section_groups
[i
].root
; g
!= NULL
; g
= next
)
22145 free (filedata
->section_groups
);
22147 memset (&filedata
->section_headers
, 0,
22148 sizeof (Filedata
) - offsetof (Filedata
, section_headers
));
22152 close_file (Filedata
* filedata
)
22156 if (filedata
->handle
)
22157 fclose (filedata
->handle
);
22163 close_debug_file (void * data
)
22165 free_filedata ((Filedata
*) data
);
22166 close_file ((Filedata
*) data
);
22170 open_file (const char * pathname
, bool is_separate
)
22172 struct stat statbuf
;
22173 Filedata
* filedata
= NULL
;
22175 if (stat (pathname
, & statbuf
) < 0
22176 || ! S_ISREG (statbuf
.st_mode
))
22179 filedata
= calloc (1, sizeof * filedata
);
22180 if (filedata
== NULL
)
22183 filedata
->handle
= fopen (pathname
, "rb");
22184 if (filedata
->handle
== NULL
)
22187 filedata
->file_size
= (bfd_size_type
) statbuf
.st_size
;
22188 filedata
->file_name
= pathname
;
22189 filedata
->is_separate
= is_separate
;
22191 if (! get_file_header (filedata
))
22194 if (!get_section_headers (filedata
, false))
22202 if (filedata
->handle
)
22203 fclose (filedata
->handle
);
22210 open_debug_file (const char * pathname
)
22212 return open_file (pathname
, true);
22216 initialise_dump_sects (Filedata
* filedata
)
22218 /* Initialise the dump_sects array from the cmdline_dump_sects array.
22219 Note we do this even if cmdline_dump_sects is empty because we
22220 must make sure that the dump_sets array is zeroed out before each
22221 object file is processed. */
22222 if (filedata
->dump
.num_dump_sects
> cmdline
.num_dump_sects
)
22223 memset (filedata
->dump
.dump_sects
, 0,
22224 filedata
->dump
.num_dump_sects
* sizeof (*filedata
->dump
.dump_sects
));
22226 if (cmdline
.num_dump_sects
> 0)
22228 if (filedata
->dump
.num_dump_sects
== 0)
22229 /* A sneaky way of allocating the dump_sects array. */
22230 request_dump_bynumber (&filedata
->dump
, cmdline
.num_dump_sects
, 0);
22232 assert (filedata
->dump
.num_dump_sects
>= cmdline
.num_dump_sects
);
22233 memcpy (filedata
->dump
.dump_sects
, cmdline
.dump_sects
,
22234 cmdline
.num_dump_sects
* sizeof (*filedata
->dump
.dump_sects
));
22239 might_need_separate_debug_info (Filedata
* filedata
)
22241 /* Debuginfo files do not need further separate file loading. */
22242 if (filedata
->file_header
.e_shstrndx
== SHN_UNDEF
)
22245 /* Since do_follow_links might be enabled by default, only treat it as an
22246 indication that separate files should be loaded if setting it was a
22247 deliberate user action. */
22248 if (DEFAULT_FOR_FOLLOW_LINKS
== 0 && do_follow_links
)
22251 if (process_links
|| do_syms
|| do_unwind
22252 || dump_any_debugging
|| do_dump
|| do_debugging
)
22258 /* Process one ELF object file according to the command line options.
22259 This file may actually be stored in an archive. The file is
22260 positioned at the start of the ELF object. Returns TRUE if no
22261 problems were encountered, FALSE otherwise. */
22264 process_object (Filedata
* filedata
)
22266 bool have_separate_files
;
22270 if (! get_file_header (filedata
))
22272 error (_("%s: Failed to read file header\n"), filedata
->file_name
);
22276 /* Initialise per file variables. */
22277 for (i
= ARRAY_SIZE (filedata
->version_info
); i
--;)
22278 filedata
->version_info
[i
] = 0;
22280 for (i
= ARRAY_SIZE (filedata
->dynamic_info
); i
--;)
22281 filedata
->dynamic_info
[i
] = 0;
22282 filedata
->dynamic_info_DT_GNU_HASH
= 0;
22283 filedata
->dynamic_info_DT_MIPS_XHASH
= 0;
22285 /* Process the file. */
22287 printf (_("\nFile: %s\n"), filedata
->file_name
);
22289 initialise_dump_sects (filedata
);
22291 /* There may be some extensions in the first section header. Don't
22292 bomb if we can't read it. */
22293 get_section_headers (filedata
, true);
22295 if (! process_file_header (filedata
))
22301 /* Throw away the single section header read above, so that we
22302 re-read the entire set. */
22303 free (filedata
->section_headers
);
22304 filedata
->section_headers
= NULL
;
22306 if (! process_section_headers (filedata
))
22308 /* Without loaded section headers we cannot process lots of things. */
22309 do_unwind
= do_version
= do_dump
= do_arch
= false;
22311 if (! do_using_dynamic
)
22312 do_syms
= do_dyn_syms
= do_reloc
= false;
22315 if (! process_section_groups (filedata
))
22316 /* Without loaded section groups we cannot process unwind. */
22319 process_program_headers (filedata
);
22321 res
= process_dynamic_section (filedata
);
22323 if (! process_relocs (filedata
))
22326 if (! process_unwind (filedata
))
22329 if (! process_symbol_table (filedata
))
22332 if (! process_lto_symbol_tables (filedata
))
22335 if (! process_syminfo (filedata
))
22338 if (! process_version_sections (filedata
))
22341 if (might_need_separate_debug_info (filedata
))
22342 have_separate_files
= load_separate_debug_files (filedata
, filedata
->file_name
);
22344 have_separate_files
= false;
22346 if (! process_section_contents (filedata
))
22349 if (have_separate_files
)
22353 for (d
= first_separate_info
; d
!= NULL
; d
= d
->next
)
22355 initialise_dump_sects (d
->handle
);
22357 if (process_links
&& ! process_file_header (d
->handle
))
22359 else if (! process_section_headers (d
->handle
))
22361 else if (! process_section_contents (d
->handle
))
22363 else if (process_links
)
22365 if (! process_section_groups (d
->handle
))
22367 process_program_headers (d
->handle
);
22368 if (! process_dynamic_section (d
->handle
))
22370 if (! process_relocs (d
->handle
))
22372 if (! process_unwind (d
->handle
))
22374 if (! process_symbol_table (d
->handle
))
22376 if (! process_lto_symbol_tables (d
->handle
))
22378 if (! process_syminfo (d
->handle
))
22380 if (! process_version_sections (d
->handle
))
22382 if (! process_notes (d
->handle
))
22387 /* The file handles are closed by the call to free_debug_memory() below. */
22390 if (! process_notes (filedata
))
22393 if (! process_gnu_liblist (filedata
))
22396 if (! process_arch_specific (filedata
))
22400 free_filedata (filedata
);
22402 free_debug_memory ();
22407 /* Process an ELF archive.
22408 On entry the file is positioned just after the ARMAG string.
22409 Returns TRUE upon success, FALSE otherwise. */
22412 process_archive (Filedata
* filedata
, bool is_thin_archive
)
22414 struct archive_info arch
;
22415 struct archive_info nested_arch
;
22421 /* The ARCH structure is used to hold information about this archive. */
22422 arch
.file_name
= NULL
;
22424 arch
.index_array
= NULL
;
22425 arch
.sym_table
= NULL
;
22426 arch
.longnames
= NULL
;
22428 /* The NESTED_ARCH structure is used as a single-item cache of information
22429 about a nested archive (when members of a thin archive reside within
22430 another regular archive file). */
22431 nested_arch
.file_name
= NULL
;
22432 nested_arch
.file
= NULL
;
22433 nested_arch
.index_array
= NULL
;
22434 nested_arch
.sym_table
= NULL
;
22435 nested_arch
.longnames
= NULL
;
22437 if (setup_archive (&arch
, filedata
->file_name
, filedata
->handle
,
22438 filedata
->file_size
, is_thin_archive
,
22439 do_archive_index
) != 0)
22445 if (do_archive_index
)
22447 if (arch
.sym_table
== NULL
)
22448 error (_("%s: unable to dump the index as none was found\n"),
22449 filedata
->file_name
);
22452 unsigned long i
, l
;
22453 unsigned long current_pos
;
22455 printf (_("Index of archive %s: (%lu entries, 0x%lx bytes "
22456 "in the symbol table)\n"),
22457 filedata
->file_name
, (unsigned long) arch
.index_num
,
22460 current_pos
= ftell (filedata
->handle
);
22462 for (i
= l
= 0; i
< arch
.index_num
; i
++)
22465 || (i
> 0 && arch
.index_array
[i
] != arch
.index_array
[i
- 1]))
22468 = get_archive_member_name_at (&arch
, arch
.index_array
[i
],
22471 if (member_name
!= NULL
)
22473 char * qualified_name
22474 = make_qualified_name (&arch
, &nested_arch
,
22477 if (qualified_name
!= NULL
)
22479 printf (_("Contents of binary %s at offset "),
22481 (void) print_vma (arch
.index_array
[i
], PREFIX_HEX
);
22483 free (qualified_name
);
22485 free (member_name
);
22489 if (l
>= arch
.sym_size
)
22491 error (_("%s: end of the symbol table reached "
22492 "before the end of the index\n"),
22493 filedata
->file_name
);
22497 /* PR 17531: file: 0b6630b2. */
22498 printf ("\t%.*s\n",
22499 (int) (arch
.sym_size
- l
), arch
.sym_table
+ l
);
22500 l
+= strnlen (arch
.sym_table
+ l
, arch
.sym_size
- l
) + 1;
22503 if (arch
.uses_64bit_indices
)
22508 if (l
< arch
.sym_size
)
22510 error (ngettext ("%s: %ld byte remains in the symbol table, "
22511 "but without corresponding entries in "
22512 "the index table\n",
22513 "%s: %ld bytes remain in the symbol table, "
22514 "but without corresponding entries in "
22515 "the index table\n",
22516 arch
.sym_size
- l
),
22517 filedata
->file_name
, arch
.sym_size
- l
);
22521 if (fseek (filedata
->handle
, current_pos
, SEEK_SET
) != 0)
22523 error (_("%s: failed to seek back to start of object files "
22524 "in the archive\n"),
22525 filedata
->file_name
);
22531 if (!do_dynamic
&& !do_syms
&& !do_reloc
&& !do_unwind
&& !do_sections
22532 && !do_segments
&& !do_header
&& !do_dump
&& !do_version
22533 && !do_histogram
&& !do_debugging
&& !do_arch
&& !do_notes
22534 && !do_section_groups
&& !do_dyn_syms
)
22536 ret
= true; /* Archive index only. */
22545 char * qualified_name
;
22547 /* Read the next archive header. */
22548 if (fseek (filedata
->handle
, arch
.next_arhdr_offset
, SEEK_SET
) != 0)
22550 error (_("%s: failed to seek to next archive header\n"),
22555 got
= fread (&arch
.arhdr
, 1, sizeof arch
.arhdr
, filedata
->handle
);
22556 if (got
!= sizeof arch
.arhdr
)
22560 /* PR 24049 - we cannot use filedata->file_name as this will
22561 have already been freed. */
22562 error (_("%s: failed to read archive header\n"), arch
.file_name
);
22567 if (memcmp (arch
.arhdr
.ar_fmag
, ARFMAG
, 2) != 0)
22569 error (_("%s: did not find a valid archive header\n"),
22575 arch
.next_arhdr_offset
+= sizeof arch
.arhdr
;
22577 filedata
->archive_file_size
= strtoul (arch
.arhdr
.ar_size
, NULL
, 10);
22579 name
= get_archive_member_name (&arch
, &nested_arch
);
22582 error (_("%s: bad archive file name\n"), arch
.file_name
);
22586 namelen
= strlen (name
);
22588 qualified_name
= make_qualified_name (&arch
, &nested_arch
, name
);
22589 if (qualified_name
== NULL
)
22591 error (_("%s: bad archive file name\n"), arch
.file_name
);
22597 if (is_thin_archive
&& arch
.nested_member_origin
== 0)
22599 /* This is a proxy for an external member of a thin archive. */
22600 Filedata
* member_filedata
;
22601 char * member_file_name
= adjust_relative_path
22602 (filedata
->file_name
, name
, namelen
);
22605 if (member_file_name
== NULL
)
22607 free (qualified_name
);
22612 member_filedata
= open_file (member_file_name
, false);
22613 if (member_filedata
== NULL
)
22615 error (_("Input file '%s' is not readable.\n"), member_file_name
);
22616 free (member_file_name
);
22617 free (qualified_name
);
22622 filedata
->archive_file_offset
= arch
.nested_member_origin
;
22623 member_filedata
->file_name
= qualified_name
;
22625 /* The call to process_object() expects the file to be at the beginning. */
22626 rewind (member_filedata
->handle
);
22628 if (! process_object (member_filedata
))
22631 close_file (member_filedata
);
22632 free (member_file_name
);
22634 else if (is_thin_archive
)
22636 Filedata thin_filedata
;
22638 memset (&thin_filedata
, 0, sizeof (thin_filedata
));
22640 /* PR 15140: Allow for corrupt thin archives. */
22641 if (nested_arch
.file
== NULL
)
22643 error (_("%s: contains corrupt thin archive: %s\n"),
22644 qualified_name
, name
);
22645 free (qualified_name
);
22652 /* This is a proxy for a member of a nested archive. */
22653 filedata
->archive_file_offset
22654 = arch
.nested_member_origin
+ sizeof arch
.arhdr
;
22656 /* The nested archive file will have been opened and setup by
22657 get_archive_member_name. */
22658 if (fseek (nested_arch
.file
, filedata
->archive_file_offset
,
22661 error (_("%s: failed to seek to archive member.\n"),
22662 nested_arch
.file_name
);
22663 free (qualified_name
);
22668 thin_filedata
.handle
= nested_arch
.file
;
22669 thin_filedata
.file_name
= qualified_name
;
22671 if (! process_object (& thin_filedata
))
22677 filedata
->archive_file_offset
= arch
.next_arhdr_offset
;
22678 filedata
->file_name
= qualified_name
;
22679 if (! process_object (filedata
))
22681 arch
.next_arhdr_offset
+= (filedata
->archive_file_size
+ 1) & -2;
22682 /* Stop looping with "negative" archive_file_size. */
22683 if (arch
.next_arhdr_offset
< filedata
->archive_file_size
)
22684 arch
.next_arhdr_offset
= -1ul;
22687 free (qualified_name
);
22691 if (nested_arch
.file
!= NULL
)
22692 fclose (nested_arch
.file
);
22693 release_archive (&nested_arch
);
22694 release_archive (&arch
);
22700 process_file (char * file_name
)
22702 Filedata
* filedata
= NULL
;
22703 struct stat statbuf
;
22704 char armag
[SARMAG
];
22707 if (stat (file_name
, &statbuf
) < 0)
22709 if (errno
== ENOENT
)
22710 error (_("'%s': No such file\n"), file_name
);
22712 error (_("Could not locate '%s'. System error message: %s\n"),
22713 file_name
, strerror (errno
));
22717 if (! S_ISREG (statbuf
.st_mode
))
22719 error (_("'%s' is not an ordinary file\n"), file_name
);
22723 filedata
= calloc (1, sizeof * filedata
);
22724 if (filedata
== NULL
)
22726 error (_("Out of memory allocating file data structure\n"));
22730 filedata
->file_name
= file_name
;
22731 filedata
->handle
= fopen (file_name
, "rb");
22732 if (filedata
->handle
== NULL
)
22734 error (_("Input file '%s' is not readable.\n"), file_name
);
22739 if (fread (armag
, SARMAG
, 1, filedata
->handle
) != 1)
22741 error (_("%s: Failed to read file's magic number\n"), file_name
);
22742 fclose (filedata
->handle
);
22747 filedata
->file_size
= (bfd_size_type
) statbuf
.st_size
;
22748 filedata
->is_separate
= false;
22750 if (memcmp (armag
, ARMAG
, SARMAG
) == 0)
22752 if (! process_archive (filedata
, false))
22755 else if (memcmp (armag
, ARMAGT
, SARMAG
) == 0)
22757 if ( ! process_archive (filedata
, true))
22762 if (do_archive_index
&& !check_all
)
22763 error (_("File %s is not an archive so its index cannot be displayed.\n"),
22766 rewind (filedata
->handle
);
22767 filedata
->archive_file_size
= filedata
->archive_file_offset
= 0;
22769 if (! process_object (filedata
))
22773 fclose (filedata
->handle
);
22774 free (filedata
->section_headers
);
22775 free (filedata
->program_headers
);
22776 free (filedata
->string_table
);
22777 free (filedata
->dump
.dump_sects
);
22780 free (ba_cache
.strtab
);
22781 ba_cache
.strtab
= NULL
;
22782 free (ba_cache
.symtab
);
22783 ba_cache
.symtab
= NULL
;
22784 ba_cache
.filedata
= NULL
;
22789 #ifdef SUPPORT_DISASSEMBLY
22790 /* Needed by the i386 disassembler. For extra credit, someone could
22791 fix this so that we insert symbolic addresses here, esp for GOT/PLT
22795 print_address (unsigned int addr
, FILE * outfile
)
22797 fprintf (outfile
,"0x%8.8x", addr
);
22800 /* Needed by the i386 disassembler. */
22803 db_task_printsym (unsigned int addr
)
22805 print_address (addr
, stderr
);
22810 main (int argc
, char ** argv
)
22814 #ifdef HAVE_LC_MESSAGES
22815 setlocale (LC_MESSAGES
, "");
22817 setlocale (LC_CTYPE
, "");
22818 bindtextdomain (PACKAGE
, LOCALEDIR
);
22819 textdomain (PACKAGE
);
22821 expandargv (&argc
, &argv
);
22823 parse_args (& cmdline
, argc
, argv
);
22825 if (optind
< (argc
- 1))
22826 /* When displaying information for more than one file,
22827 prefix the information with the file name. */
22829 else if (optind
>= argc
)
22831 /* Ensure that the warning is always displayed. */
22834 warn (_("Nothing to do.\n"));
22839 while (optind
< argc
)
22840 if (! process_file (argv
[optind
++]))
22843 free (cmdline
.dump_sects
);
22845 free (dump_ctf_symtab_name
);
22846 free (dump_ctf_strtab_name
);
22847 free (dump_ctf_parent_name
);
22849 return err
? EXIT_FAILURE
: EXIT_SUCCESS
;