1 /* readelf.c -- display contents of an ELF format file
2 Copyright (C) 1998-2021 Free Software Foundation, Inc.
4 Originally developed by Eric Youngdale <eric@andante.jic.com>
5 Modifications by Nick Clifton <nickc@redhat.com>
7 This file is part of GNU Binutils.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
24 /* The difference between readelf and objdump:
26 Both programs are capable of displaying the contents of ELF format files,
27 so why does the binutils project have two file dumpers ?
29 The reason is that objdump sees an ELF file through a BFD filter of the
30 world; if BFD has a bug where, say, it disagrees about a machine constant
31 in e_flags, then the odds are good that it will remain internally
32 consistent. The linker sees it the BFD way, objdump sees it the BFD way,
33 GAS sees it the BFD way. There was need for a tool to go find out what
34 the file actually says.
36 This is why the readelf program does not link against the BFD library - it
37 exists as an independent program to help verify the correct working of BFD.
39 There is also the case that readelf can provide more information about an
40 ELF file than is provided by objdump. In particular it can display DWARF
41 debugging information which (at the moment) objdump cannot. */
52 /* Define BFD64 here, even if our default architecture is 32 bit ELF
53 as this will allow us to read in and parse 64bit and 32bit ELF files.
54 Only do this if we believe that the compiler can support a 64 bit
55 data type. For now we only rely on GCC being able to do this. */
66 #include "elf/common.h"
67 #include "elf/external.h"
68 #include "elf/internal.h"
71 /* Included here, before RELOC_MACROS_GEN_FUNC is defined, so that
72 we can obtain the H8 reloc numbers. We need these for the
73 get_reloc_size() function. We include h8.h again after defining
74 RELOC_MACROS_GEN_FUNC so that we get the naming function as well. */
79 /* Undo the effects of #including reloc-macros.h. */
81 #undef START_RELOC_NUMBERS
85 #undef END_RELOC_NUMBERS
86 #undef _RELOC_MACROS_H
88 /* The following headers use the elf/reloc-macros.h file to
89 automatically generate relocation recognition functions
90 such as elf_mips_reloc_type() */
92 #define RELOC_MACROS_GEN_FUNC
94 #include "elf/aarch64.h"
95 #include "elf/alpha.h"
100 #include "elf/cr16.h"
101 #include "elf/cris.h"
103 #include "elf/csky.h"
104 #include "elf/d10v.h"
105 #include "elf/d30v.h"
108 #include "elf/epiphany.h"
109 #include "elf/fr30.h"
111 #include "elf/ft32.h"
113 #include "elf/hppa.h"
114 #include "elf/i386.h"
115 #include "elf/i370.h"
116 #include "elf/i860.h"
117 #include "elf/i960.h"
118 #include "elf/ia64.h"
119 #include "elf/ip2k.h"
120 #include "elf/lm32.h"
121 #include "elf/iq2000.h"
122 #include "elf/m32c.h"
123 #include "elf/m32r.h"
124 #include "elf/m68k.h"
125 #include "elf/m68hc11.h"
126 #include "elf/s12z.h"
127 #include "elf/mcore.h"
129 #include "elf/metag.h"
130 #include "elf/microblaze.h"
131 #include "elf/mips.h"
132 #include "elf/mmix.h"
133 #include "elf/mn10200.h"
134 #include "elf/mn10300.h"
135 #include "elf/moxie.h"
137 #include "elf/msp430.h"
138 #include "elf/nds32.h"
140 #include "elf/nios2.h"
141 #include "elf/or1k.h"
144 #include "elf/ppc64.h"
146 #include "elf/riscv.h"
147 #include "elf/rl78.h"
149 #include "elf/s390.h"
150 #include "elf/score.h"
152 #include "elf/sparc.h"
154 #include "elf/tic6x.h"
155 #include "elf/tilegx.h"
156 #include "elf/tilepro.h"
157 #include "elf/v850.h"
159 #include "elf/visium.h"
160 #include "elf/wasm32.h"
161 #include "elf/x86-64.h"
162 #include "elf/xc16x.h"
163 #include "elf/xgate.h"
164 #include "elf/xstormy16.h"
165 #include "elf/xtensa.h"
169 #include "libiberty.h"
170 #include "safe-ctype.h"
171 #include "filenames.h"
174 #define offsetof(TYPE, MEMBER) ((size_t) &(((TYPE *) 0)->MEMBER))
177 typedef struct elf_section_list
179 Elf_Internal_Shdr
* hdr
;
180 struct elf_section_list
* next
;
183 /* Flag bits indicating particular types of dump. */
184 #define HEX_DUMP (1 << 0) /* The -x command line switch. */
185 #define DISASS_DUMP (1 << 1) /* The -i command line switch. */
186 #define DEBUG_DUMP (1 << 2) /* The -w command line switch. */
187 #define STRING_DUMP (1 << 3) /* The -p command line switch. */
188 #define RELOC_DUMP (1 << 4) /* The -R command line switch. */
189 #define CTF_DUMP (1 << 5) /* The --ctf command line switch. */
191 typedef unsigned char dump_type
;
193 /* A linked list of the section names for which dumps were requested. */
194 struct dump_list_entry
198 struct dump_list_entry
* next
;
201 /* A dynamic array of flags indicating for which sections a dump
202 has been requested via command line switches. */
205 dump_type
* dump_sects
;
206 unsigned int num_dump_sects
;
209 static struct dump_data cmdline
;
211 static struct dump_list_entry
* dump_sects_byname
;
213 char * program_name
= "readelf";
215 static bfd_boolean show_name
= FALSE
;
216 static bfd_boolean do_dynamic
= FALSE
;
217 static bfd_boolean do_syms
= FALSE
;
218 static bfd_boolean do_dyn_syms
= FALSE
;
219 static bfd_boolean do_lto_syms
= FALSE
;
220 static bfd_boolean do_reloc
= FALSE
;
221 static bfd_boolean do_sections
= FALSE
;
222 static bfd_boolean do_section_groups
= FALSE
;
223 static bfd_boolean do_section_details
= FALSE
;
224 static bfd_boolean do_segments
= FALSE
;
225 static bfd_boolean do_unwind
= FALSE
;
226 static bfd_boolean do_using_dynamic
= FALSE
;
227 static bfd_boolean do_header
= FALSE
;
228 static bfd_boolean do_dump
= FALSE
;
229 static bfd_boolean do_version
= FALSE
;
230 static bfd_boolean do_histogram
= FALSE
;
231 static bfd_boolean do_debugging
= FALSE
;
232 static bfd_boolean do_ctf
= FALSE
;
233 static bfd_boolean do_arch
= FALSE
;
234 static bfd_boolean do_notes
= FALSE
;
235 static bfd_boolean do_archive_index
= FALSE
;
236 static bfd_boolean check_all
= FALSE
;
237 static bfd_boolean is_32bit_elf
= FALSE
;
238 static bfd_boolean decompress_dumps
= FALSE
;
239 static bfd_boolean do_not_show_symbol_truncation
= FALSE
;
240 static bfd_boolean do_demangle
= FALSE
; /* Pretty print C++ symbol names. */
241 static bfd_boolean process_links
= FALSE
;
242 static int demangle_flags
= DMGL_ANSI
| DMGL_PARAMS
;
244 static char *dump_ctf_parent_name
;
245 static char *dump_ctf_symtab_name
;
246 static char *dump_ctf_strtab_name
;
250 struct group_list
* next
;
251 unsigned int section_index
;
256 struct group_list
* root
;
257 unsigned int group_index
;
260 typedef struct filedata
262 const char * file_name
;
263 bfd_boolean is_separate
;
265 bfd_size_type file_size
;
266 Elf_Internal_Ehdr file_header
;
267 Elf_Internal_Shdr
* section_headers
;
268 Elf_Internal_Phdr
* program_headers
;
270 unsigned long string_table_length
;
271 unsigned long archive_file_offset
;
272 unsigned long archive_file_size
;
273 unsigned long dynamic_addr
;
274 bfd_size_type dynamic_size
;
276 Elf_Internal_Dyn
* dynamic_section
;
277 Elf_Internal_Shdr
* dynamic_strtab_section
;
278 char * dynamic_strings
;
279 unsigned long dynamic_strings_length
;
280 Elf_Internal_Shdr
* dynamic_symtab_section
;
281 unsigned long num_dynamic_syms
;
282 Elf_Internal_Sym
* dynamic_symbols
;
283 bfd_vma version_info
[16];
284 unsigned int dynamic_syminfo_nent
;
285 Elf_Internal_Syminfo
* dynamic_syminfo
;
286 unsigned long dynamic_syminfo_offset
;
287 bfd_size_type nbuckets
;
288 bfd_size_type nchains
;
291 bfd_size_type ngnubuckets
;
292 bfd_size_type ngnuchains
;
293 bfd_vma
* gnubuckets
;
297 char program_interpreter
[PATH_MAX
];
298 bfd_vma dynamic_info
[DT_ENCODING
];
299 bfd_vma dynamic_info_DT_GNU_HASH
;
300 bfd_vma dynamic_info_DT_MIPS_XHASH
;
301 elf_section_list
* symtab_shndx_list
;
303 struct group
* section_groups
;
304 struct group
** section_headers_groups
;
305 /* A dynamic array of flags indicating for which sections a dump of
306 some kind has been requested. It is reset on a per-object file
307 basis and then initialised from the cmdline_dump_sects array,
308 the results of interpreting the -w switch, and the
309 dump_sects_byname list. */
310 struct dump_data dump
;
313 /* How to print a vma value. */
314 typedef enum print_mode
326 /* Versioned symbol info. */
327 enum versioned_symbol_info
334 static const char * get_symbol_version_string
335 (Filedata
*, bfd_boolean
, const char *, unsigned long, unsigned,
336 Elf_Internal_Sym
*, enum versioned_symbol_info
*, unsigned short *);
340 #define SECTION_NAME(X) \
341 (filedata->string_table + (X)->sh_name)
343 #define SECTION_NAME_VALID(X) \
345 && filedata->string_table != NULL \
346 && (X)->sh_name < filedata->string_table_length)
348 #define SECTION_NAME_PRINT(X) \
349 ((X) == NULL ? _("<none>") \
350 : filedata->string_table == NULL ? _("<no-strings>") \
351 : (X)->sh_name >= filedata->string_table_length ? _("<corrupt>") \
352 : filedata->string_table + (X)->sh_name)
354 #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
356 #define GET_ELF_SYMBOLS(file, section, sym_count) \
357 (is_32bit_elf ? get_32bit_elf_symbols (file, section, sym_count) \
358 : get_64bit_elf_symbols (file, section, sym_count))
360 #define VALID_SYMBOL_NAME(strtab, strtab_size, offset) \
361 (strtab != NULL && offset < strtab_size)
362 #define VALID_DYNAMIC_NAME(filedata, offset) \
363 VALID_SYMBOL_NAME (filedata->dynamic_strings, \
364 filedata->dynamic_strings_length, offset)
365 /* GET_DYNAMIC_NAME asssumes that VALID_DYNAMIC_NAME has
366 already been called and verified that the string exists. */
367 #define GET_DYNAMIC_NAME(filedata, offset) \
368 (filedata->dynamic_strings + offset)
370 #define REMOVE_ARCH_BITS(ADDR) \
373 if (filedata->file_header.e_machine == EM_ARM) \
378 /* Get the correct GNU hash section name. */
379 #define GNU_HASH_SECTION_NAME(filedata) \
380 filedata->dynamic_info_DT_MIPS_XHASH ? ".MIPS.xhash" : ".gnu.hash"
382 /* Print a BFD_VMA to an internal buffer, for use in error messages.
383 BFD_FMA_FMT can't be used in translated strings. */
386 bfd_vmatoa (char *fmtch
, bfd_vma value
)
388 /* bfd_vmatoa is used more then once in a printf call for output.
389 Cycle through an array of buffers. */
390 static int buf_pos
= 0;
391 static struct bfd_vmatoa_buf
398 ret
= buf
[buf_pos
++].place
;
399 buf_pos
%= ARRAY_SIZE (buf
);
401 sprintf (fmt
, "%%%s%s", BFD_VMA_FMT
, fmtch
);
402 snprintf (ret
, sizeof (buf
[0].place
), fmt
, value
);
406 /* Retrieve NMEMB structures, each SIZE bytes long from FILEDATA starting at
407 OFFSET + the offset of the current archive member, if we are examining an
408 archive. Put the retrieved data into VAR, if it is not NULL. Otherwise
409 allocate a buffer using malloc and fill that. In either case return the
410 pointer to the start of the retrieved data or NULL if something went wrong.
411 If something does go wrong and REASON is not NULL then emit an error
412 message using REASON as part of the context. */
415 get_data (void * var
,
417 unsigned long offset
,
423 bfd_size_type amt
= size
* nmemb
;
425 if (size
== 0 || nmemb
== 0)
428 /* If the size_t type is smaller than the bfd_size_type, eg because
429 you are building a 32-bit tool on a 64-bit host, then make sure
430 that when the sizes are cast to (size_t) no information is lost. */
431 if ((size_t) size
!= size
432 || (size_t) nmemb
!= nmemb
433 || (size_t) amt
!= amt
)
436 error (_("Size truncation prevents reading %s"
437 " elements of size %s for %s\n"),
438 bfd_vmatoa ("u", nmemb
), bfd_vmatoa ("u", size
), reason
);
442 /* Check for size overflow. */
443 if (amt
/ size
!= nmemb
|| (size_t) amt
+ 1 == 0)
446 error (_("Size overflow prevents reading %s"
447 " elements of size %s for %s\n"),
448 bfd_vmatoa ("u", nmemb
), bfd_vmatoa ("u", size
), reason
);
452 /* Be kind to memory checkers (eg valgrind, address sanitizer) by not
453 attempting to allocate memory when the read is bound to fail. */
454 if (filedata
->archive_file_offset
> filedata
->file_size
455 || offset
> filedata
->file_size
- filedata
->archive_file_offset
456 || amt
> filedata
->file_size
- filedata
->archive_file_offset
- offset
)
459 error (_("Reading %s bytes extends past end of file for %s\n"),
460 bfd_vmatoa ("u", amt
), reason
);
464 if (fseek (filedata
->handle
, filedata
->archive_file_offset
+ offset
,
468 error (_("Unable to seek to 0x%lx for %s\n"),
469 filedata
->archive_file_offset
+ offset
, reason
);
476 /* + 1 so that we can '\0' terminate invalid string table sections. */
477 mvar
= malloc ((size_t) amt
+ 1);
482 error (_("Out of memory allocating %s bytes for %s\n"),
483 bfd_vmatoa ("u", amt
), reason
);
487 ((char *) mvar
)[amt
] = '\0';
490 if (fread (mvar
, (size_t) size
, (size_t) nmemb
, filedata
->handle
) != nmemb
)
493 error (_("Unable to read in %s bytes of %s\n"),
494 bfd_vmatoa ("u", amt
), reason
);
503 /* Print a VMA value in the MODE specified.
504 Returns the number of characters displayed. */
507 print_vma (bfd_vma vma
, print_mode mode
)
519 return nc
+ printf ("%8.8" BFD_VMA_FMT
"x", vma
);
526 return printf ("%5" BFD_VMA_FMT
"d", vma
);
532 return nc
+ printf ("%" BFD_VMA_FMT
"x", vma
);
535 return printf ("%" BFD_VMA_FMT
"d", vma
);
538 return printf ("%" BFD_VMA_FMT
"u", vma
);
541 /* FIXME: Report unrecognised mode ? */
546 /* Display a symbol on stdout. Handles the display of control characters and
547 multibye characters (assuming the host environment supports them).
549 Display at most abs(WIDTH) characters, truncating as necessary, unless do_wide is true.
551 If truncation will happen and do_not_show_symbol_truncation is FALSE then display
552 abs(WIDTH) - 5 characters followed by "[...]".
554 If WIDTH is negative then ensure that the output is at least (- WIDTH) characters,
555 padding as necessary.
557 Returns the number of emitted characters. */
560 print_symbol (signed int width
, const char * symbol
)
562 bfd_boolean extra_padding
= FALSE
;
563 bfd_boolean do_dots
= FALSE
;
564 signed int num_printed
= 0;
565 #ifdef HAVE_MBSTATE_T
568 unsigned int width_remaining
;
569 const void * alloced_symbol
= NULL
;
573 /* Keep the width positive. This helps the code below. */
575 extra_padding
= TRUE
;
581 /* Set the remaining width to a very large value.
582 This simplifies the code below. */
583 width_remaining
= INT_MAX
;
586 width_remaining
= width
;
587 if (! do_not_show_symbol_truncation
588 && (int) strlen (symbol
) > width
)
590 width_remaining
-= 5;
591 if ((int) width_remaining
< 0)
597 #ifdef HAVE_MBSTATE_T
598 /* Initialise the multibyte conversion state. */
599 memset (& state
, 0, sizeof (state
));
602 if (do_demangle
&& *symbol
)
604 const char * res
= cplus_demangle (symbol
, demangle_flags
);
607 alloced_symbol
= symbol
= res
;
610 while (width_remaining
)
613 const char c
= *symbol
++;
618 /* Do not print control characters directly as they can affect terminal
619 settings. Such characters usually appear in the names generated
620 by the assembler for local labels. */
623 if (width_remaining
< 2)
626 printf ("^%c", c
+ 0x40);
627 width_remaining
-= 2;
630 else if (ISPRINT (c
))
638 #ifdef HAVE_MBSTATE_T
641 /* Let printf do the hard work of displaying multibyte characters. */
642 printf ("%.1s", symbol
- 1);
646 #ifdef HAVE_MBSTATE_T
647 /* Try to find out how many bytes made up the character that was
648 just printed. Advance the symbol pointer past the bytes that
650 n
= mbrtowc (& w
, symbol
- 1, MB_CUR_MAX
, & state
);
654 if (n
!= (size_t) -1 && n
!= (size_t) -2 && n
> 0)
660 num_printed
+= printf ("[...]");
662 if (extra_padding
&& num_printed
< width
)
664 /* Fill in the remaining spaces. */
665 printf ("%-*s", width
- num_printed
, " ");
669 free ((void *) alloced_symbol
);
673 /* Returns a pointer to a static buffer containing a printable version of
674 the given section's name. Like print_symbol, except that it does not try
675 to print multibyte characters, it just interprets them as hex values. */
678 printable_section_name (Filedata
* filedata
, const Elf_Internal_Shdr
* sec
)
680 #define MAX_PRINT_SEC_NAME_LEN 256
681 static char sec_name_buf
[MAX_PRINT_SEC_NAME_LEN
+ 1];
682 const char * name
= SECTION_NAME_PRINT (sec
);
683 char * buf
= sec_name_buf
;
685 unsigned int remaining
= MAX_PRINT_SEC_NAME_LEN
;
687 while ((c
= * name
++) != 0)
698 else if (ISPRINT (c
))
705 static char hex
[17] = "0123456789ABCDEF";
710 * buf
++ = hex
[(c
& 0xf0) >> 4];
711 * buf
++ = hex
[c
& 0x0f];
725 printable_section_name_from_index (Filedata
* filedata
, unsigned long ndx
)
727 if (ndx
>= filedata
->file_header
.e_shnum
)
728 return _("<corrupt>");
730 return printable_section_name (filedata
, filedata
->section_headers
+ ndx
);
733 /* Return a pointer to section NAME, or NULL if no such section exists. */
735 static Elf_Internal_Shdr
*
736 find_section (Filedata
* filedata
, const char * name
)
740 if (filedata
->section_headers
== NULL
)
743 for (i
= 0; i
< filedata
->file_header
.e_shnum
; i
++)
744 if (SECTION_NAME_VALID (filedata
->section_headers
+ i
)
745 && streq (SECTION_NAME (filedata
->section_headers
+ i
), name
))
746 return filedata
->section_headers
+ i
;
751 /* Return a pointer to a section containing ADDR, or NULL if no such
754 static Elf_Internal_Shdr
*
755 find_section_by_address (Filedata
* filedata
, bfd_vma addr
)
759 if (filedata
->section_headers
== NULL
)
762 for (i
= 0; i
< filedata
->file_header
.e_shnum
; i
++)
764 Elf_Internal_Shdr
*sec
= filedata
->section_headers
+ i
;
766 if (addr
>= sec
->sh_addr
&& addr
< sec
->sh_addr
+ sec
->sh_size
)
773 static Elf_Internal_Shdr
*
774 find_section_by_type (Filedata
* filedata
, unsigned int type
)
778 if (filedata
->section_headers
== NULL
)
781 for (i
= 0; i
< filedata
->file_header
.e_shnum
; i
++)
783 Elf_Internal_Shdr
*sec
= filedata
->section_headers
+ i
;
785 if (sec
->sh_type
== type
)
792 /* Return a pointer to section NAME, or NULL if no such section exists,
793 restricted to the list of sections given in SET. */
795 static Elf_Internal_Shdr
*
796 find_section_in_set (Filedata
* filedata
, const char * name
, unsigned int * set
)
800 if (filedata
->section_headers
== NULL
)
805 while ((i
= *set
++) > 0)
807 /* See PR 21156 for a reproducer. */
808 if (i
>= filedata
->file_header
.e_shnum
)
809 continue; /* FIXME: Should we issue an error message ? */
811 if (SECTION_NAME_VALID (filedata
->section_headers
+ i
)
812 && streq (SECTION_NAME (filedata
->section_headers
+ i
), name
))
813 return filedata
->section_headers
+ i
;
817 return find_section (filedata
, name
);
820 /* Return TRUE if the current file is for IA-64 machine and OpenVMS ABI.
821 This OS has so many departures from the ELF standard that we test it at
824 static inline bfd_boolean
825 is_ia64_vms (Filedata
* filedata
)
827 return filedata
->file_header
.e_machine
== EM_IA_64
828 && filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_OPENVMS
;
831 /* Guess the relocation size commonly used by the specific machines. */
834 guess_is_rela (unsigned int e_machine
)
838 /* Targets that use REL relocations. */
855 /* Targets that use RELA relocations. */
859 case EM_ADAPTEVA_EPIPHANY
:
861 case EM_ALTERA_NIOS2
:
864 case EM_ARC_COMPACT2
:
885 case EM_LATTICEMICO32
:
894 case EM_CYGNUS_MN10200
:
896 case EM_CYGNUS_MN10300
:
932 case EM_MICROBLAZE_OLD
:
954 warn (_("Don't know about relocations on this machine architecture\n"));
959 /* Load RELA type relocations from FILEDATA at REL_OFFSET extending for REL_SIZE bytes.
960 Returns TRUE upon success, FALSE otherwise. If successful then a
961 pointer to a malloc'ed buffer containing the relocs is placed in *RELASP,
962 and the number of relocs loaded is placed in *NRELASP. It is the caller's
963 responsibility to free the allocated buffer. */
966 slurp_rela_relocs (Filedata
* filedata
,
967 unsigned long rel_offset
,
968 unsigned long rel_size
,
969 Elf_Internal_Rela
** relasp
,
970 unsigned long * nrelasp
)
972 Elf_Internal_Rela
* relas
;
978 Elf32_External_Rela
* erelas
;
980 erelas
= (Elf32_External_Rela
*) get_data (NULL
, filedata
, rel_offset
, 1,
981 rel_size
, _("32-bit relocation data"));
985 nrelas
= rel_size
/ sizeof (Elf32_External_Rela
);
987 relas
= (Elf_Internal_Rela
*) cmalloc (nrelas
,
988 sizeof (Elf_Internal_Rela
));
993 error (_("out of memory parsing relocs\n"));
997 for (i
= 0; i
< nrelas
; i
++)
999 relas
[i
].r_offset
= BYTE_GET (erelas
[i
].r_offset
);
1000 relas
[i
].r_info
= BYTE_GET (erelas
[i
].r_info
);
1001 relas
[i
].r_addend
= BYTE_GET_SIGNED (erelas
[i
].r_addend
);
1008 Elf64_External_Rela
* erelas
;
1010 erelas
= (Elf64_External_Rela
*) get_data (NULL
, filedata
, rel_offset
, 1,
1011 rel_size
, _("64-bit relocation data"));
1015 nrelas
= rel_size
/ sizeof (Elf64_External_Rela
);
1017 relas
= (Elf_Internal_Rela
*) cmalloc (nrelas
,
1018 sizeof (Elf_Internal_Rela
));
1023 error (_("out of memory parsing relocs\n"));
1027 for (i
= 0; i
< nrelas
; i
++)
1029 relas
[i
].r_offset
= BYTE_GET (erelas
[i
].r_offset
);
1030 relas
[i
].r_info
= BYTE_GET (erelas
[i
].r_info
);
1031 relas
[i
].r_addend
= BYTE_GET_SIGNED (erelas
[i
].r_addend
);
1033 /* The #ifdef BFD64 below is to prevent a compile time
1034 warning. We know that if we do not have a 64 bit data
1035 type that we will never execute this code anyway. */
1037 if (filedata
->file_header
.e_machine
== EM_MIPS
1038 && filedata
->file_header
.e_ident
[EI_DATA
] != ELFDATA2MSB
)
1040 /* In little-endian objects, r_info isn't really a
1041 64-bit little-endian value: it has a 32-bit
1042 little-endian symbol index followed by four
1043 individual byte fields. Reorder INFO
1045 bfd_vma inf
= relas
[i
].r_info
;
1046 inf
= (((inf
& 0xffffffff) << 32)
1047 | ((inf
>> 56) & 0xff)
1048 | ((inf
>> 40) & 0xff00)
1049 | ((inf
>> 24) & 0xff0000)
1050 | ((inf
>> 8) & 0xff000000));
1051 relas
[i
].r_info
= inf
;
1064 /* Load REL type relocations from FILEDATA at REL_OFFSET extending for REL_SIZE bytes.
1065 Returns TRUE upon success, FALSE otherwise. If successful then a
1066 pointer to a malloc'ed buffer containing the relocs is placed in *RELSP,
1067 and the number of relocs loaded is placed in *NRELSP. It is the caller's
1068 responsibility to free the allocated buffer. */
1071 slurp_rel_relocs (Filedata
* filedata
,
1072 unsigned long rel_offset
,
1073 unsigned long rel_size
,
1074 Elf_Internal_Rela
** relsp
,
1075 unsigned long * nrelsp
)
1077 Elf_Internal_Rela
* rels
;
1083 Elf32_External_Rel
* erels
;
1085 erels
= (Elf32_External_Rel
*) get_data (NULL
, filedata
, rel_offset
, 1,
1086 rel_size
, _("32-bit relocation data"));
1090 nrels
= rel_size
/ sizeof (Elf32_External_Rel
);
1092 rels
= (Elf_Internal_Rela
*) cmalloc (nrels
, sizeof (Elf_Internal_Rela
));
1097 error (_("out of memory parsing relocs\n"));
1101 for (i
= 0; i
< nrels
; i
++)
1103 rels
[i
].r_offset
= BYTE_GET (erels
[i
].r_offset
);
1104 rels
[i
].r_info
= BYTE_GET (erels
[i
].r_info
);
1105 rels
[i
].r_addend
= 0;
1112 Elf64_External_Rel
* erels
;
1114 erels
= (Elf64_External_Rel
*) get_data (NULL
, filedata
, rel_offset
, 1,
1115 rel_size
, _("64-bit relocation data"));
1119 nrels
= rel_size
/ sizeof (Elf64_External_Rel
);
1121 rels
= (Elf_Internal_Rela
*) cmalloc (nrels
, sizeof (Elf_Internal_Rela
));
1126 error (_("out of memory parsing relocs\n"));
1130 for (i
= 0; i
< nrels
; i
++)
1132 rels
[i
].r_offset
= BYTE_GET (erels
[i
].r_offset
);
1133 rels
[i
].r_info
= BYTE_GET (erels
[i
].r_info
);
1134 rels
[i
].r_addend
= 0;
1136 /* The #ifdef BFD64 below is to prevent a compile time
1137 warning. We know that if we do not have a 64 bit data
1138 type that we will never execute this code anyway. */
1140 if (filedata
->file_header
.e_machine
== EM_MIPS
1141 && filedata
->file_header
.e_ident
[EI_DATA
] != ELFDATA2MSB
)
1143 /* In little-endian objects, r_info isn't really a
1144 64-bit little-endian value: it has a 32-bit
1145 little-endian symbol index followed by four
1146 individual byte fields. Reorder INFO
1148 bfd_vma inf
= rels
[i
].r_info
;
1149 inf
= (((inf
& 0xffffffff) << 32)
1150 | ((inf
>> 56) & 0xff)
1151 | ((inf
>> 40) & 0xff00)
1152 | ((inf
>> 24) & 0xff0000)
1153 | ((inf
>> 8) & 0xff000000));
1154 rels
[i
].r_info
= inf
;
1167 /* Returns the reloc type extracted from the reloc info field. */
1170 get_reloc_type (Filedata
* filedata
, bfd_vma reloc_info
)
1173 return ELF32_R_TYPE (reloc_info
);
1175 switch (filedata
->file_header
.e_machine
)
1178 /* Note: We assume that reloc_info has already been adjusted for us. */
1179 return ELF64_MIPS_R_TYPE (reloc_info
);
1182 return ELF64_R_TYPE_ID (reloc_info
);
1185 return ELF64_R_TYPE (reloc_info
);
1189 /* Return the symbol index extracted from the reloc info field. */
1192 get_reloc_symindex (bfd_vma reloc_info
)
1194 return is_32bit_elf
? ELF32_R_SYM (reloc_info
) : ELF64_R_SYM (reloc_info
);
1197 static inline bfd_boolean
1198 uses_msp430x_relocs (Filedata
* filedata
)
1201 filedata
->file_header
.e_machine
== EM_MSP430
/* Paranoia. */
1202 /* GCC uses osabi == ELFOSBI_STANDALONE. */
1203 && (((filedata
->file_header
.e_flags
& EF_MSP430_MACH
) == E_MSP430_MACH_MSP430X
)
1204 /* TI compiler uses ELFOSABI_NONE. */
1205 || (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_NONE
));
1208 /* Display the contents of the relocation data found at the specified
1212 dump_relocations (Filedata
* filedata
,
1213 unsigned long rel_offset
,
1214 unsigned long rel_size
,
1215 Elf_Internal_Sym
* symtab
,
1216 unsigned long nsyms
,
1218 unsigned long strtablen
,
1220 bfd_boolean is_dynsym
)
1223 Elf_Internal_Rela
* rels
;
1224 bfd_boolean res
= TRUE
;
1226 if (is_rela
== UNKNOWN
)
1227 is_rela
= guess_is_rela (filedata
->file_header
.e_machine
);
1231 if (!slurp_rela_relocs (filedata
, rel_offset
, rel_size
, &rels
, &rel_size
))
1236 if (!slurp_rel_relocs (filedata
, rel_offset
, rel_size
, &rels
, &rel_size
))
1245 printf (_(" Offset Info Type Sym. Value Symbol's Name + Addend\n"));
1247 printf (_(" Offset Info Type Sym.Value Sym. Name + Addend\n"));
1252 printf (_(" Offset Info Type Sym. Value Symbol's Name\n"));
1254 printf (_(" Offset Info Type Sym.Value Sym. Name\n"));
1262 printf (_(" Offset Info Type Symbol's Value Symbol's Name + Addend\n"));
1264 printf (_(" Offset Info Type Sym. Value Sym. Name + Addend\n"));
1269 printf (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
1271 printf (_(" Offset Info Type Sym. Value Sym. Name\n"));
1275 for (i
= 0; i
< rel_size
; i
++)
1280 bfd_vma symtab_index
;
1283 offset
= rels
[i
].r_offset
;
1284 inf
= rels
[i
].r_info
;
1286 type
= get_reloc_type (filedata
, inf
);
1287 symtab_index
= get_reloc_symindex (inf
);
1291 printf ("%8.8lx %8.8lx ",
1292 (unsigned long) offset
& 0xffffffff,
1293 (unsigned long) inf
& 0xffffffff);
1298 ? "%16.16" BFD_VMA_FMT
"x %16.16" BFD_VMA_FMT
"x "
1299 : "%12.12" BFD_VMA_FMT
"x %12.12" BFD_VMA_FMT
"x ",
1303 switch (filedata
->file_header
.e_machine
)
1310 rtype
= elf_aarch64_reloc_type (type
);
1314 case EM_CYGNUS_M32R
:
1315 rtype
= elf_m32r_reloc_type (type
);
1320 rtype
= elf_i386_reloc_type (type
);
1325 rtype
= elf_m68hc11_reloc_type (type
);
1329 rtype
= elf_s12z_reloc_type (type
);
1333 rtype
= elf_m68k_reloc_type (type
);
1337 rtype
= elf_i960_reloc_type (type
);
1342 rtype
= elf_avr_reloc_type (type
);
1345 case EM_OLD_SPARCV9
:
1346 case EM_SPARC32PLUS
:
1349 rtype
= elf_sparc_reloc_type (type
);
1353 rtype
= elf_spu_reloc_type (type
);
1357 rtype
= v800_reloc_type (type
);
1360 case EM_CYGNUS_V850
:
1361 rtype
= v850_reloc_type (type
);
1365 case EM_CYGNUS_D10V
:
1366 rtype
= elf_d10v_reloc_type (type
);
1370 case EM_CYGNUS_D30V
:
1371 rtype
= elf_d30v_reloc_type (type
);
1375 rtype
= elf_dlx_reloc_type (type
);
1379 rtype
= elf_sh_reloc_type (type
);
1383 case EM_CYGNUS_MN10300
:
1384 rtype
= elf_mn10300_reloc_type (type
);
1388 case EM_CYGNUS_MN10200
:
1389 rtype
= elf_mn10200_reloc_type (type
);
1393 case EM_CYGNUS_FR30
:
1394 rtype
= elf_fr30_reloc_type (type
);
1398 rtype
= elf_frv_reloc_type (type
);
1402 rtype
= elf_csky_reloc_type (type
);
1406 rtype
= elf_ft32_reloc_type (type
);
1410 rtype
= elf_mcore_reloc_type (type
);
1414 rtype
= elf_mmix_reloc_type (type
);
1418 rtype
= elf_moxie_reloc_type (type
);
1422 if (uses_msp430x_relocs (filedata
))
1424 rtype
= elf_msp430x_reloc_type (type
);
1429 rtype
= elf_msp430_reloc_type (type
);
1433 rtype
= elf_nds32_reloc_type (type
);
1437 rtype
= elf_ppc_reloc_type (type
);
1441 rtype
= elf_ppc64_reloc_type (type
);
1445 case EM_MIPS_RS3_LE
:
1446 rtype
= elf_mips_reloc_type (type
);
1450 rtype
= elf_riscv_reloc_type (type
);
1454 rtype
= elf_alpha_reloc_type (type
);
1458 rtype
= elf_arm_reloc_type (type
);
1462 case EM_ARC_COMPACT
:
1463 case EM_ARC_COMPACT2
:
1464 rtype
= elf_arc_reloc_type (type
);
1468 rtype
= elf_hppa_reloc_type (type
);
1474 rtype
= elf_h8_reloc_type (type
);
1478 rtype
= elf_or1k_reloc_type (type
);
1483 rtype
= elf_pj_reloc_type (type
);
1486 rtype
= elf_ia64_reloc_type (type
);
1490 rtype
= elf_cris_reloc_type (type
);
1494 rtype
= elf_i860_reloc_type (type
);
1500 rtype
= elf_x86_64_reloc_type (type
);
1504 rtype
= i370_reloc_type (type
);
1509 rtype
= elf_s390_reloc_type (type
);
1513 rtype
= elf_score_reloc_type (type
);
1517 rtype
= elf_xstormy16_reloc_type (type
);
1521 rtype
= elf_crx_reloc_type (type
);
1525 rtype
= elf_vax_reloc_type (type
);
1529 rtype
= elf_visium_reloc_type (type
);
1533 rtype
= elf_bpf_reloc_type (type
);
1536 case EM_ADAPTEVA_EPIPHANY
:
1537 rtype
= elf_epiphany_reloc_type (type
);
1542 rtype
= elf_ip2k_reloc_type (type
);
1546 rtype
= elf_iq2000_reloc_type (type
);
1551 rtype
= elf_xtensa_reloc_type (type
);
1554 case EM_LATTICEMICO32
:
1555 rtype
= elf_lm32_reloc_type (type
);
1560 rtype
= elf_m32c_reloc_type (type
);
1564 rtype
= elf_mt_reloc_type (type
);
1568 rtype
= elf_bfin_reloc_type (type
);
1572 rtype
= elf_mep_reloc_type (type
);
1576 rtype
= elf_cr16_reloc_type (type
);
1580 case EM_MICROBLAZE_OLD
:
1581 rtype
= elf_microblaze_reloc_type (type
);
1585 rtype
= elf_rl78_reloc_type (type
);
1589 rtype
= elf_rx_reloc_type (type
);
1593 rtype
= elf_metag_reloc_type (type
);
1598 rtype
= elf_xc16x_reloc_type (type
);
1602 rtype
= elf_tic6x_reloc_type (type
);
1606 rtype
= elf_tilegx_reloc_type (type
);
1610 rtype
= elf_tilepro_reloc_type (type
);
1613 case EM_WEBASSEMBLY
:
1614 rtype
= elf_wasm32_reloc_type (type
);
1618 rtype
= elf_xgate_reloc_type (type
);
1621 case EM_ALTERA_NIOS2
:
1622 rtype
= elf_nios2_reloc_type (type
);
1626 rtype
= elf_pru_reloc_type (type
);
1630 if (EF_NFP_MACH (filedata
->file_header
.e_flags
) == E_NFP_MACH_3200
)
1631 rtype
= elf_nfp3200_reloc_type (type
);
1633 rtype
= elf_nfp_reloc_type (type
);
1637 rtype
= elf_z80_reloc_type (type
);
1642 printf (_("unrecognized: %-7lx"), (unsigned long) type
& 0xffffffff);
1644 printf (do_wide
? "%-22s" : "%-17.17s", rtype
);
1646 if (filedata
->file_header
.e_machine
== EM_ALPHA
1648 && streq (rtype
, "R_ALPHA_LITUSE")
1651 switch (rels
[i
].r_addend
)
1653 case LITUSE_ALPHA_ADDR
: rtype
= "ADDR"; break;
1654 case LITUSE_ALPHA_BASE
: rtype
= "BASE"; break;
1655 case LITUSE_ALPHA_BYTOFF
: rtype
= "BYTOFF"; break;
1656 case LITUSE_ALPHA_JSR
: rtype
= "JSR"; break;
1657 case LITUSE_ALPHA_TLSGD
: rtype
= "TLSGD"; break;
1658 case LITUSE_ALPHA_TLSLDM
: rtype
= "TLSLDM"; break;
1659 case LITUSE_ALPHA_JSRDIRECT
: rtype
= "JSRDIRECT"; break;
1660 default: rtype
= NULL
;
1664 printf (" (%s)", rtype
);
1668 printf (_("<unknown addend: %lx>"),
1669 (unsigned long) rels
[i
].r_addend
);
1673 else if (symtab_index
)
1675 if (symtab
== NULL
|| symtab_index
>= nsyms
)
1677 error (_(" bad symbol index: %08lx in reloc\n"),
1678 (unsigned long) symtab_index
);
1683 Elf_Internal_Sym
* psym
;
1684 const char * version_string
;
1685 enum versioned_symbol_info sym_info
;
1686 unsigned short vna_other
;
1688 psym
= symtab
+ symtab_index
;
1691 = get_symbol_version_string (filedata
, is_dynsym
,
1700 if (ELF_ST_TYPE (psym
->st_info
) == STT_GNU_IFUNC
)
1704 unsigned int width
= is_32bit_elf
? 8 : 14;
1706 /* Relocations against GNU_IFUNC symbols do not use the value
1707 of the symbol as the address to relocate against. Instead
1708 they invoke the function named by the symbol and use its
1709 result as the address for relocation.
1711 To indicate this to the user, do not display the value of
1712 the symbol in the "Symbols's Value" field. Instead show
1713 its name followed by () as a hint that the symbol is
1717 || psym
->st_name
== 0
1718 || psym
->st_name
>= strtablen
)
1721 name
= strtab
+ psym
->st_name
;
1723 len
= print_symbol (width
, name
);
1725 printf (sym_info
== symbol_public
? "@@%s" : "@%s",
1727 printf ("()%-*s", len
<= width
? (width
+ 1) - len
: 1, " ");
1731 print_vma (psym
->st_value
, LONG_HEX
);
1733 printf (is_32bit_elf
? " " : " ");
1736 if (psym
->st_name
== 0)
1738 const char * sec_name
= "<null>";
1741 if (ELF_ST_TYPE (psym
->st_info
) == STT_SECTION
)
1743 if (psym
->st_shndx
< filedata
->file_header
.e_shnum
)
1744 sec_name
= SECTION_NAME_PRINT (filedata
->section_headers
1746 else if (psym
->st_shndx
== SHN_ABS
)
1748 else if (psym
->st_shndx
== SHN_COMMON
)
1749 sec_name
= "COMMON";
1750 else if ((filedata
->file_header
.e_machine
== EM_MIPS
1751 && psym
->st_shndx
== SHN_MIPS_SCOMMON
)
1752 || (filedata
->file_header
.e_machine
== EM_TI_C6000
1753 && psym
->st_shndx
== SHN_TIC6X_SCOMMON
))
1754 sec_name
= "SCOMMON";
1755 else if (filedata
->file_header
.e_machine
== EM_MIPS
1756 && psym
->st_shndx
== SHN_MIPS_SUNDEFINED
)
1757 sec_name
= "SUNDEF";
1758 else if ((filedata
->file_header
.e_machine
== EM_X86_64
1759 || filedata
->file_header
.e_machine
== EM_L1OM
1760 || filedata
->file_header
.e_machine
== EM_K1OM
)
1761 && psym
->st_shndx
== SHN_X86_64_LCOMMON
)
1762 sec_name
= "LARGE_COMMON";
1763 else if (filedata
->file_header
.e_machine
== EM_IA_64
1764 && filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_HPUX
1765 && psym
->st_shndx
== SHN_IA_64_ANSI_COMMON
)
1766 sec_name
= "ANSI_COM";
1767 else if (is_ia64_vms (filedata
)
1768 && psym
->st_shndx
== SHN_IA_64_VMS_SYMVEC
)
1769 sec_name
= "VMS_SYMVEC";
1772 sprintf (name_buf
, "<section 0x%x>",
1773 (unsigned int) psym
->st_shndx
);
1774 sec_name
= name_buf
;
1777 print_symbol (22, sec_name
);
1779 else if (strtab
== NULL
)
1780 printf (_("<string table index: %3ld>"), psym
->st_name
);
1781 else if (psym
->st_name
>= strtablen
)
1783 error (_("<corrupt string table index: %3ld>\n"),
1789 print_symbol (22, strtab
+ psym
->st_name
);
1791 printf (sym_info
== symbol_public
? "@@%s" : "@%s",
1797 bfd_vma off
= rels
[i
].r_addend
;
1799 if ((bfd_signed_vma
) off
< 0)
1800 printf (" - %" BFD_VMA_FMT
"x", - off
);
1802 printf (" + %" BFD_VMA_FMT
"x", off
);
1808 bfd_vma off
= rels
[i
].r_addend
;
1810 printf ("%*c", is_32bit_elf
? 12 : 20, ' ');
1811 if ((bfd_signed_vma
) off
< 0)
1812 printf ("-%" BFD_VMA_FMT
"x", - off
);
1814 printf ("%" BFD_VMA_FMT
"x", off
);
1817 if (filedata
->file_header
.e_machine
== EM_SPARCV9
1819 && streq (rtype
, "R_SPARC_OLO10"))
1820 printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (inf
));
1825 if (! is_32bit_elf
&& filedata
->file_header
.e_machine
== EM_MIPS
)
1827 bfd_vma type2
= ELF64_MIPS_R_TYPE2 (inf
);
1828 bfd_vma type3
= ELF64_MIPS_R_TYPE3 (inf
);
1829 const char * rtype2
= elf_mips_reloc_type (type2
);
1830 const char * rtype3
= elf_mips_reloc_type (type3
);
1832 printf (" Type2: ");
1835 printf (_("unrecognized: %-7lx"),
1836 (unsigned long) type2
& 0xffffffff);
1838 printf ("%-17.17s", rtype2
);
1840 printf ("\n Type3: ");
1843 printf (_("unrecognized: %-7lx"),
1844 (unsigned long) type3
& 0xffffffff);
1846 printf ("%-17.17s", rtype3
);
1859 get_aarch64_dynamic_type (unsigned long type
)
1863 case DT_AARCH64_BTI_PLT
: return "AARCH64_BTI_PLT";
1864 case DT_AARCH64_PAC_PLT
: return "AARCH64_PAC_PLT";
1865 case DT_AARCH64_VARIANT_PCS
: return "AARCH64_VARIANT_PCS";
1872 get_mips_dynamic_type (unsigned long type
)
1876 case DT_MIPS_RLD_VERSION
: return "MIPS_RLD_VERSION";
1877 case DT_MIPS_TIME_STAMP
: return "MIPS_TIME_STAMP";
1878 case DT_MIPS_ICHECKSUM
: return "MIPS_ICHECKSUM";
1879 case DT_MIPS_IVERSION
: return "MIPS_IVERSION";
1880 case DT_MIPS_FLAGS
: return "MIPS_FLAGS";
1881 case DT_MIPS_BASE_ADDRESS
: return "MIPS_BASE_ADDRESS";
1882 case DT_MIPS_MSYM
: return "MIPS_MSYM";
1883 case DT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
1884 case DT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
1885 case DT_MIPS_LOCAL_GOTNO
: return "MIPS_LOCAL_GOTNO";
1886 case DT_MIPS_CONFLICTNO
: return "MIPS_CONFLICTNO";
1887 case DT_MIPS_LIBLISTNO
: return "MIPS_LIBLISTNO";
1888 case DT_MIPS_SYMTABNO
: return "MIPS_SYMTABNO";
1889 case DT_MIPS_UNREFEXTNO
: return "MIPS_UNREFEXTNO";
1890 case DT_MIPS_GOTSYM
: return "MIPS_GOTSYM";
1891 case DT_MIPS_HIPAGENO
: return "MIPS_HIPAGENO";
1892 case DT_MIPS_RLD_MAP
: return "MIPS_RLD_MAP";
1893 case DT_MIPS_RLD_MAP_REL
: return "MIPS_RLD_MAP_REL";
1894 case DT_MIPS_DELTA_CLASS
: return "MIPS_DELTA_CLASS";
1895 case DT_MIPS_DELTA_CLASS_NO
: return "MIPS_DELTA_CLASS_NO";
1896 case DT_MIPS_DELTA_INSTANCE
: return "MIPS_DELTA_INSTANCE";
1897 case DT_MIPS_DELTA_INSTANCE_NO
: return "MIPS_DELTA_INSTANCE_NO";
1898 case DT_MIPS_DELTA_RELOC
: return "MIPS_DELTA_RELOC";
1899 case DT_MIPS_DELTA_RELOC_NO
: return "MIPS_DELTA_RELOC_NO";
1900 case DT_MIPS_DELTA_SYM
: return "MIPS_DELTA_SYM";
1901 case DT_MIPS_DELTA_SYM_NO
: return "MIPS_DELTA_SYM_NO";
1902 case DT_MIPS_DELTA_CLASSSYM
: return "MIPS_DELTA_CLASSSYM";
1903 case DT_MIPS_DELTA_CLASSSYM_NO
: return "MIPS_DELTA_CLASSSYM_NO";
1904 case DT_MIPS_CXX_FLAGS
: return "MIPS_CXX_FLAGS";
1905 case DT_MIPS_PIXIE_INIT
: return "MIPS_PIXIE_INIT";
1906 case DT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
1907 case DT_MIPS_LOCALPAGE_GOTIDX
: return "MIPS_LOCALPAGE_GOTIDX";
1908 case DT_MIPS_LOCAL_GOTIDX
: return "MIPS_LOCAL_GOTIDX";
1909 case DT_MIPS_HIDDEN_GOTIDX
: return "MIPS_HIDDEN_GOTIDX";
1910 case DT_MIPS_PROTECTED_GOTIDX
: return "MIPS_PROTECTED_GOTIDX";
1911 case DT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
1912 case DT_MIPS_INTERFACE
: return "MIPS_INTERFACE";
1913 case DT_MIPS_DYNSTR_ALIGN
: return "MIPS_DYNSTR_ALIGN";
1914 case DT_MIPS_INTERFACE_SIZE
: return "MIPS_INTERFACE_SIZE";
1915 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR
: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
1916 case DT_MIPS_PERF_SUFFIX
: return "MIPS_PERF_SUFFIX";
1917 case DT_MIPS_COMPACT_SIZE
: return "MIPS_COMPACT_SIZE";
1918 case DT_MIPS_GP_VALUE
: return "MIPS_GP_VALUE";
1919 case DT_MIPS_AUX_DYNAMIC
: return "MIPS_AUX_DYNAMIC";
1920 case DT_MIPS_PLTGOT
: return "MIPS_PLTGOT";
1921 case DT_MIPS_RWPLT
: return "MIPS_RWPLT";
1922 case DT_MIPS_XHASH
: return "MIPS_XHASH";
1929 get_sparc64_dynamic_type (unsigned long type
)
1933 case DT_SPARC_REGISTER
: return "SPARC_REGISTER";
1940 get_ppc_dynamic_type (unsigned long type
)
1944 case DT_PPC_GOT
: return "PPC_GOT";
1945 case DT_PPC_OPT
: return "PPC_OPT";
1952 get_ppc64_dynamic_type (unsigned long type
)
1956 case DT_PPC64_GLINK
: return "PPC64_GLINK";
1957 case DT_PPC64_OPD
: return "PPC64_OPD";
1958 case DT_PPC64_OPDSZ
: return "PPC64_OPDSZ";
1959 case DT_PPC64_OPT
: return "PPC64_OPT";
1966 get_parisc_dynamic_type (unsigned long type
)
1970 case DT_HP_LOAD_MAP
: return "HP_LOAD_MAP";
1971 case DT_HP_DLD_FLAGS
: return "HP_DLD_FLAGS";
1972 case DT_HP_DLD_HOOK
: return "HP_DLD_HOOK";
1973 case DT_HP_UX10_INIT
: return "HP_UX10_INIT";
1974 case DT_HP_UX10_INITSZ
: return "HP_UX10_INITSZ";
1975 case DT_HP_PREINIT
: return "HP_PREINIT";
1976 case DT_HP_PREINITSZ
: return "HP_PREINITSZ";
1977 case DT_HP_NEEDED
: return "HP_NEEDED";
1978 case DT_HP_TIME_STAMP
: return "HP_TIME_STAMP";
1979 case DT_HP_CHECKSUM
: return "HP_CHECKSUM";
1980 case DT_HP_GST_SIZE
: return "HP_GST_SIZE";
1981 case DT_HP_GST_VERSION
: return "HP_GST_VERSION";
1982 case DT_HP_GST_HASHVAL
: return "HP_GST_HASHVAL";
1983 case DT_HP_EPLTREL
: return "HP_GST_EPLTREL";
1984 case DT_HP_EPLTRELSZ
: return "HP_GST_EPLTRELSZ";
1985 case DT_HP_FILTERED
: return "HP_FILTERED";
1986 case DT_HP_FILTER_TLS
: return "HP_FILTER_TLS";
1987 case DT_HP_COMPAT_FILTERED
: return "HP_COMPAT_FILTERED";
1988 case DT_HP_LAZYLOAD
: return "HP_LAZYLOAD";
1989 case DT_HP_BIND_NOW_COUNT
: return "HP_BIND_NOW_COUNT";
1990 case DT_PLT
: return "PLT";
1991 case DT_PLT_SIZE
: return "PLT_SIZE";
1992 case DT_DLT
: return "DLT";
1993 case DT_DLT_SIZE
: return "DLT_SIZE";
2000 get_ia64_dynamic_type (unsigned long type
)
2004 case DT_IA_64_PLT_RESERVE
: return "IA_64_PLT_RESERVE";
2005 case DT_IA_64_VMS_SUBTYPE
: return "VMS_SUBTYPE";
2006 case DT_IA_64_VMS_IMGIOCNT
: return "VMS_IMGIOCNT";
2007 case DT_IA_64_VMS_LNKFLAGS
: return "VMS_LNKFLAGS";
2008 case DT_IA_64_VMS_VIR_MEM_BLK_SIZ
: return "VMS_VIR_MEM_BLK_SIZ";
2009 case DT_IA_64_VMS_IDENT
: return "VMS_IDENT";
2010 case DT_IA_64_VMS_NEEDED_IDENT
: return "VMS_NEEDED_IDENT";
2011 case DT_IA_64_VMS_IMG_RELA_CNT
: return "VMS_IMG_RELA_CNT";
2012 case DT_IA_64_VMS_SEG_RELA_CNT
: return "VMS_SEG_RELA_CNT";
2013 case DT_IA_64_VMS_FIXUP_RELA_CNT
: return "VMS_FIXUP_RELA_CNT";
2014 case DT_IA_64_VMS_FIXUP_NEEDED
: return "VMS_FIXUP_NEEDED";
2015 case DT_IA_64_VMS_SYMVEC_CNT
: return "VMS_SYMVEC_CNT";
2016 case DT_IA_64_VMS_XLATED
: return "VMS_XLATED";
2017 case DT_IA_64_VMS_STACKSIZE
: return "VMS_STACKSIZE";
2018 case DT_IA_64_VMS_UNWINDSZ
: return "VMS_UNWINDSZ";
2019 case DT_IA_64_VMS_UNWIND_CODSEG
: return "VMS_UNWIND_CODSEG";
2020 case DT_IA_64_VMS_UNWIND_INFOSEG
: return "VMS_UNWIND_INFOSEG";
2021 case DT_IA_64_VMS_LINKTIME
: return "VMS_LINKTIME";
2022 case DT_IA_64_VMS_SEG_NO
: return "VMS_SEG_NO";
2023 case DT_IA_64_VMS_SYMVEC_OFFSET
: return "VMS_SYMVEC_OFFSET";
2024 case DT_IA_64_VMS_SYMVEC_SEG
: return "VMS_SYMVEC_SEG";
2025 case DT_IA_64_VMS_UNWIND_OFFSET
: return "VMS_UNWIND_OFFSET";
2026 case DT_IA_64_VMS_UNWIND_SEG
: return "VMS_UNWIND_SEG";
2027 case DT_IA_64_VMS_STRTAB_OFFSET
: return "VMS_STRTAB_OFFSET";
2028 case DT_IA_64_VMS_SYSVER_OFFSET
: return "VMS_SYSVER_OFFSET";
2029 case DT_IA_64_VMS_IMG_RELA_OFF
: return "VMS_IMG_RELA_OFF";
2030 case DT_IA_64_VMS_SEG_RELA_OFF
: return "VMS_SEG_RELA_OFF";
2031 case DT_IA_64_VMS_FIXUP_RELA_OFF
: return "VMS_FIXUP_RELA_OFF";
2032 case DT_IA_64_VMS_PLTGOT_OFFSET
: return "VMS_PLTGOT_OFFSET";
2033 case DT_IA_64_VMS_PLTGOT_SEG
: return "VMS_PLTGOT_SEG";
2034 case DT_IA_64_VMS_FPMODE
: return "VMS_FPMODE";
2041 get_solaris_section_type (unsigned long type
)
2045 case 0x6fffffee: return "SUNW_ancillary";
2046 case 0x6fffffef: return "SUNW_capchain";
2047 case 0x6ffffff0: return "SUNW_capinfo";
2048 case 0x6ffffff1: return "SUNW_symsort";
2049 case 0x6ffffff2: return "SUNW_tlssort";
2050 case 0x6ffffff3: return "SUNW_LDYNSYM";
2051 case 0x6ffffff4: return "SUNW_dof";
2052 case 0x6ffffff5: return "SUNW_cap";
2053 case 0x6ffffff6: return "SUNW_SIGNATURE";
2054 case 0x6ffffff7: return "SUNW_ANNOTATE";
2055 case 0x6ffffff8: return "SUNW_DEBUGSTR";
2056 case 0x6ffffff9: return "SUNW_DEBUG";
2057 case 0x6ffffffa: return "SUNW_move";
2058 case 0x6ffffffb: return "SUNW_COMDAT";
2059 case 0x6ffffffc: return "SUNW_syminfo";
2060 case 0x6ffffffd: return "SUNW_verdef";
2061 case 0x6ffffffe: return "SUNW_verneed";
2062 case 0x6fffffff: return "SUNW_versym";
2063 case 0x70000000: return "SPARC_GOTDATA";
2064 default: return NULL
;
2069 get_alpha_dynamic_type (unsigned long type
)
2073 case DT_ALPHA_PLTRO
: return "ALPHA_PLTRO";
2074 default: return NULL
;
2079 get_score_dynamic_type (unsigned long type
)
2083 case DT_SCORE_BASE_ADDRESS
: return "SCORE_BASE_ADDRESS";
2084 case DT_SCORE_LOCAL_GOTNO
: return "SCORE_LOCAL_GOTNO";
2085 case DT_SCORE_SYMTABNO
: return "SCORE_SYMTABNO";
2086 case DT_SCORE_GOTSYM
: return "SCORE_GOTSYM";
2087 case DT_SCORE_UNREFEXTNO
: return "SCORE_UNREFEXTNO";
2088 case DT_SCORE_HIPAGENO
: return "SCORE_HIPAGENO";
2089 default: return NULL
;
2094 get_tic6x_dynamic_type (unsigned long type
)
2098 case DT_C6000_GSYM_OFFSET
: return "C6000_GSYM_OFFSET";
2099 case DT_C6000_GSTR_OFFSET
: return "C6000_GSTR_OFFSET";
2100 case DT_C6000_DSBT_BASE
: return "C6000_DSBT_BASE";
2101 case DT_C6000_DSBT_SIZE
: return "C6000_DSBT_SIZE";
2102 case DT_C6000_PREEMPTMAP
: return "C6000_PREEMPTMAP";
2103 case DT_C6000_DSBT_INDEX
: return "C6000_DSBT_INDEX";
2104 default: return NULL
;
2109 get_nios2_dynamic_type (unsigned long type
)
2113 case DT_NIOS2_GP
: return "NIOS2_GP";
2114 default: return NULL
;
2119 get_solaris_dynamic_type (unsigned long type
)
2123 case 0x6000000d: return "SUNW_AUXILIARY";
2124 case 0x6000000e: return "SUNW_RTLDINF";
2125 case 0x6000000f: return "SUNW_FILTER";
2126 case 0x60000010: return "SUNW_CAP";
2127 case 0x60000011: return "SUNW_SYMTAB";
2128 case 0x60000012: return "SUNW_SYMSZ";
2129 case 0x60000013: return "SUNW_SORTENT";
2130 case 0x60000014: return "SUNW_SYMSORT";
2131 case 0x60000015: return "SUNW_SYMSORTSZ";
2132 case 0x60000016: return "SUNW_TLSSORT";
2133 case 0x60000017: return "SUNW_TLSSORTSZ";
2134 case 0x60000018: return "SUNW_CAPINFO";
2135 case 0x60000019: return "SUNW_STRPAD";
2136 case 0x6000001a: return "SUNW_CAPCHAIN";
2137 case 0x6000001b: return "SUNW_LDMACH";
2138 case 0x6000001d: return "SUNW_CAPCHAINENT";
2139 case 0x6000001f: return "SUNW_CAPCHAINSZ";
2140 case 0x60000021: return "SUNW_PARENT";
2141 case 0x60000023: return "SUNW_ASLR";
2142 case 0x60000025: return "SUNW_RELAX";
2143 case 0x60000029: return "SUNW_NXHEAP";
2144 case 0x6000002b: return "SUNW_NXSTACK";
2146 case 0x70000001: return "SPARC_REGISTER";
2147 case 0x7ffffffd: return "AUXILIARY";
2148 case 0x7ffffffe: return "USED";
2149 case 0x7fffffff: return "FILTER";
2151 default: return NULL
;
2156 get_dynamic_type (Filedata
* filedata
, unsigned long type
)
2158 static char buff
[64];
2162 case DT_NULL
: return "NULL";
2163 case DT_NEEDED
: return "NEEDED";
2164 case DT_PLTRELSZ
: return "PLTRELSZ";
2165 case DT_PLTGOT
: return "PLTGOT";
2166 case DT_HASH
: return "HASH";
2167 case DT_STRTAB
: return "STRTAB";
2168 case DT_SYMTAB
: return "SYMTAB";
2169 case DT_RELA
: return "RELA";
2170 case DT_RELASZ
: return "RELASZ";
2171 case DT_RELAENT
: return "RELAENT";
2172 case DT_STRSZ
: return "STRSZ";
2173 case DT_SYMENT
: return "SYMENT";
2174 case DT_INIT
: return "INIT";
2175 case DT_FINI
: return "FINI";
2176 case DT_SONAME
: return "SONAME";
2177 case DT_RPATH
: return "RPATH";
2178 case DT_SYMBOLIC
: return "SYMBOLIC";
2179 case DT_REL
: return "REL";
2180 case DT_RELSZ
: return "RELSZ";
2181 case DT_RELENT
: return "RELENT";
2182 case DT_PLTREL
: return "PLTREL";
2183 case DT_DEBUG
: return "DEBUG";
2184 case DT_TEXTREL
: return "TEXTREL";
2185 case DT_JMPREL
: return "JMPREL";
2186 case DT_BIND_NOW
: return "BIND_NOW";
2187 case DT_INIT_ARRAY
: return "INIT_ARRAY";
2188 case DT_FINI_ARRAY
: return "FINI_ARRAY";
2189 case DT_INIT_ARRAYSZ
: return "INIT_ARRAYSZ";
2190 case DT_FINI_ARRAYSZ
: return "FINI_ARRAYSZ";
2191 case DT_RUNPATH
: return "RUNPATH";
2192 case DT_FLAGS
: return "FLAGS";
2194 case DT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
2195 case DT_PREINIT_ARRAYSZ
: return "PREINIT_ARRAYSZ";
2196 case DT_SYMTAB_SHNDX
: return "SYMTAB_SHNDX";
2198 case DT_CHECKSUM
: return "CHECKSUM";
2199 case DT_PLTPADSZ
: return "PLTPADSZ";
2200 case DT_MOVEENT
: return "MOVEENT";
2201 case DT_MOVESZ
: return "MOVESZ";
2202 case DT_FEATURE
: return "FEATURE";
2203 case DT_POSFLAG_1
: return "POSFLAG_1";
2204 case DT_SYMINSZ
: return "SYMINSZ";
2205 case DT_SYMINENT
: return "SYMINENT"; /* aka VALRNGHI */
2207 case DT_ADDRRNGLO
: return "ADDRRNGLO";
2208 case DT_CONFIG
: return "CONFIG";
2209 case DT_DEPAUDIT
: return "DEPAUDIT";
2210 case DT_AUDIT
: return "AUDIT";
2211 case DT_PLTPAD
: return "PLTPAD";
2212 case DT_MOVETAB
: return "MOVETAB";
2213 case DT_SYMINFO
: return "SYMINFO"; /* aka ADDRRNGHI */
2215 case DT_VERSYM
: return "VERSYM";
2217 case DT_TLSDESC_GOT
: return "TLSDESC_GOT";
2218 case DT_TLSDESC_PLT
: return "TLSDESC_PLT";
2219 case DT_RELACOUNT
: return "RELACOUNT";
2220 case DT_RELCOUNT
: return "RELCOUNT";
2221 case DT_FLAGS_1
: return "FLAGS_1";
2222 case DT_VERDEF
: return "VERDEF";
2223 case DT_VERDEFNUM
: return "VERDEFNUM";
2224 case DT_VERNEED
: return "VERNEED";
2225 case DT_VERNEEDNUM
: return "VERNEEDNUM";
2227 case DT_AUXILIARY
: return "AUXILIARY";
2228 case DT_USED
: return "USED";
2229 case DT_FILTER
: return "FILTER";
2231 case DT_GNU_PRELINKED
: return "GNU_PRELINKED";
2232 case DT_GNU_CONFLICT
: return "GNU_CONFLICT";
2233 case DT_GNU_CONFLICTSZ
: return "GNU_CONFLICTSZ";
2234 case DT_GNU_LIBLIST
: return "GNU_LIBLIST";
2235 case DT_GNU_LIBLISTSZ
: return "GNU_LIBLISTSZ";
2236 case DT_GNU_HASH
: return "GNU_HASH";
2237 case DT_GNU_FLAGS_1
: return "GNU_FLAGS_1";
2240 if ((type
>= DT_LOPROC
) && (type
<= DT_HIPROC
))
2242 const char * result
;
2244 switch (filedata
->file_header
.e_machine
)
2247 result
= get_aarch64_dynamic_type (type
);
2250 case EM_MIPS_RS3_LE
:
2251 result
= get_mips_dynamic_type (type
);
2254 result
= get_sparc64_dynamic_type (type
);
2257 result
= get_ppc_dynamic_type (type
);
2260 result
= get_ppc64_dynamic_type (type
);
2263 result
= get_ia64_dynamic_type (type
);
2266 result
= get_alpha_dynamic_type (type
);
2269 result
= get_score_dynamic_type (type
);
2272 result
= get_tic6x_dynamic_type (type
);
2274 case EM_ALTERA_NIOS2
:
2275 result
= get_nios2_dynamic_type (type
);
2278 if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_SOLARIS
)
2279 result
= get_solaris_dynamic_type (type
);
2288 snprintf (buff
, sizeof (buff
), _("Processor Specific: %lx"), type
);
2290 else if (((type
>= DT_LOOS
) && (type
<= DT_HIOS
))
2291 || (filedata
->file_header
.e_machine
== EM_PARISC
2292 && (type
>= OLD_DT_LOOS
) && (type
<= OLD_DT_HIOS
)))
2294 const char * result
;
2296 switch (filedata
->file_header
.e_machine
)
2299 result
= get_parisc_dynamic_type (type
);
2302 result
= get_ia64_dynamic_type (type
);
2305 if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_SOLARIS
)
2306 result
= get_solaris_dynamic_type (type
);
2315 snprintf (buff
, sizeof (buff
), _("Operating System specific: %lx"),
2319 snprintf (buff
, sizeof (buff
), _("<unknown>: %lx"), type
);
2326 get_file_type (unsigned e_type
)
2328 static char buff
[64];
2332 case ET_NONE
: return _("NONE (None)");
2333 case ET_REL
: return _("REL (Relocatable file)");
2334 case ET_EXEC
: return _("EXEC (Executable file)");
2335 case ET_DYN
: return _("DYN (Shared object file)");
2336 case ET_CORE
: return _("CORE (Core file)");
2339 if ((e_type
>= ET_LOPROC
) && (e_type
<= ET_HIPROC
))
2340 snprintf (buff
, sizeof (buff
), _("Processor Specific: (%x)"), e_type
);
2341 else if ((e_type
>= ET_LOOS
) && (e_type
<= ET_HIOS
))
2342 snprintf (buff
, sizeof (buff
), _("OS Specific: (%x)"), e_type
);
2344 snprintf (buff
, sizeof (buff
), _("<unknown>: %x"), e_type
);
2350 get_machine_name (unsigned e_machine
)
2352 static char buff
[64]; /* XXX */
2356 /* Please keep this switch table sorted by increasing EM_ value. */
2358 case EM_NONE
: return _("None");
2359 case EM_M32
: return "WE32100";
2360 case EM_SPARC
: return "Sparc";
2361 case EM_386
: return "Intel 80386";
2362 case EM_68K
: return "MC68000";
2363 case EM_88K
: return "MC88000";
2364 case EM_IAMCU
: return "Intel MCU";
2365 case EM_860
: return "Intel 80860";
2366 case EM_MIPS
: return "MIPS R3000";
2367 case EM_S370
: return "IBM System/370";
2369 case EM_MIPS_RS3_LE
: return "MIPS R4000 big-endian";
2370 case EM_OLD_SPARCV9
: return "Sparc v9 (old)";
2371 case EM_PARISC
: return "HPPA";
2372 case EM_VPP550
: return "Fujitsu VPP500";
2373 case EM_SPARC32PLUS
: return "Sparc v8+" ;
2374 case EM_960
: return "Intel 80960";
2375 case EM_PPC
: return "PowerPC";
2377 case EM_PPC64
: return "PowerPC64";
2379 case EM_S390
: return "IBM S/390";
2380 case EM_SPU
: return "SPU";
2382 case EM_V800
: return "Renesas V850 (using RH850 ABI)";
2383 case EM_FR20
: return "Fujitsu FR20";
2384 case EM_RH32
: return "TRW RH32";
2385 case EM_MCORE
: return "MCORE";
2387 case EM_ARM
: return "ARM";
2388 case EM_OLD_ALPHA
: return "Digital Alpha (old)";
2389 case EM_SH
: return "Renesas / SuperH SH";
2390 case EM_SPARCV9
: return "Sparc v9";
2391 case EM_TRICORE
: return "Siemens Tricore";
2392 case EM_ARC
: return "ARC";
2393 case EM_H8_300
: return "Renesas H8/300";
2394 case EM_H8_300H
: return "Renesas H8/300H";
2395 case EM_H8S
: return "Renesas H8S";
2396 case EM_H8_500
: return "Renesas H8/500";
2398 case EM_IA_64
: return "Intel IA-64";
2399 case EM_MIPS_X
: return "Stanford MIPS-X";
2400 case EM_COLDFIRE
: return "Motorola Coldfire";
2401 case EM_68HC12
: return "Motorola MC68HC12 Microcontroller";
2402 case EM_MMA
: return "Fujitsu Multimedia Accelerator";
2403 case EM_PCP
: return "Siemens PCP";
2404 case EM_NCPU
: return "Sony nCPU embedded RISC processor";
2405 case EM_NDR1
: return "Denso NDR1 microprocesspr";
2406 case EM_STARCORE
: return "Motorola Star*Core processor";
2407 case EM_ME16
: return "Toyota ME16 processor";
2409 case EM_ST100
: return "STMicroelectronics ST100 processor";
2410 case EM_TINYJ
: return "Advanced Logic Corp. TinyJ embedded processor";
2411 case EM_X86_64
: return "Advanced Micro Devices X86-64";
2412 case EM_PDSP
: return "Sony DSP processor";
2413 case EM_PDP10
: return "Digital Equipment Corp. PDP-10";
2414 case EM_PDP11
: return "Digital Equipment Corp. PDP-11";
2415 case EM_FX66
: return "Siemens FX66 microcontroller";
2416 case EM_ST9PLUS
: return "STMicroelectronics ST9+ 8/16 bit microcontroller";
2417 case EM_ST7
: return "STMicroelectronics ST7 8-bit microcontroller";
2418 case EM_68HC16
: return "Motorola MC68HC16 Microcontroller";
2420 case EM_68HC11
: return "Motorola MC68HC11 Microcontroller";
2421 case EM_68HC08
: return "Motorola MC68HC08 Microcontroller";
2422 case EM_68HC05
: return "Motorola MC68HC05 Microcontroller";
2423 case EM_SVX
: return "Silicon Graphics SVx";
2424 case EM_ST19
: return "STMicroelectronics ST19 8-bit microcontroller";
2425 case EM_VAX
: return "Digital VAX";
2426 case EM_CRIS
: return "Axis Communications 32-bit embedded processor";
2427 case EM_JAVELIN
: return "Infineon Technologies 32-bit embedded cpu";
2428 case EM_FIREPATH
: return "Element 14 64-bit DSP processor";
2429 case EM_ZSP
: return "LSI Logic's 16-bit DSP processor";
2431 case EM_MMIX
: return "Donald Knuth's educational 64-bit processor";
2432 case EM_HUANY
: return "Harvard Universitys's machine-independent object format";
2433 case EM_PRISM
: return "Vitesse Prism";
2435 case EM_AVR
: return "Atmel AVR 8-bit microcontroller";
2436 case EM_CYGNUS_FR30
:
2437 case EM_FR30
: return "Fujitsu FR30";
2438 case EM_CYGNUS_D10V
:
2439 case EM_D10V
: return "d10v";
2440 case EM_CYGNUS_D30V
:
2441 case EM_D30V
: return "d30v";
2442 case EM_CYGNUS_V850
:
2443 case EM_V850
: return "Renesas V850";
2444 case EM_CYGNUS_M32R
:
2445 case EM_M32R
: return "Renesas M32R (formerly Mitsubishi M32r)";
2446 case EM_CYGNUS_MN10300
:
2447 case EM_MN10300
: return "mn10300";
2449 case EM_CYGNUS_MN10200
:
2450 case EM_MN10200
: return "mn10200";
2451 case EM_PJ
: return "picoJava";
2452 case EM_OR1K
: return "OpenRISC 1000";
2453 case EM_ARC_COMPACT
: return "ARCompact";
2455 case EM_XTENSA
: return "Tensilica Xtensa Processor";
2456 case EM_VIDEOCORE
: return "Alphamosaic VideoCore processor";
2457 case EM_TMM_GPP
: return "Thompson Multimedia General Purpose Processor";
2458 case EM_NS32K
: return "National Semiconductor 32000 series";
2459 case EM_TPC
: return "Tenor Network TPC processor";
2460 case EM_SNP1K
: return "Trebia SNP 1000 processor";
2462 case EM_ST200
: return "STMicroelectronics ST200 microcontroller";
2464 case EM_IP2K
: return "Ubicom IP2xxx 8-bit microcontrollers";
2465 case EM_MAX
: return "MAX Processor";
2466 case EM_CR
: return "National Semiconductor CompactRISC";
2467 case EM_F2MC16
: return "Fujitsu F2MC16";
2468 case EM_MSP430
: return "Texas Instruments msp430 microcontroller";
2469 case EM_BLACKFIN
: return "Analog Devices Blackfin";
2470 case EM_SE_C33
: return "S1C33 Family of Seiko Epson processors";
2471 case EM_SEP
: return "Sharp embedded microprocessor";
2472 case EM_ARCA
: return "Arca RISC microprocessor";
2474 case EM_UNICORE
: return "Unicore";
2475 case EM_EXCESS
: return "eXcess 16/32/64-bit configurable embedded CPU";
2476 case EM_DXP
: return "Icera Semiconductor Inc. Deep Execution Processor";
2477 case EM_ALTERA_NIOS2
: return "Altera Nios II";
2478 case EM_CRX
: return "National Semiconductor CRX microprocessor";
2479 case EM_XGATE
: return "Motorola XGATE embedded processor";
2481 case EM_XC16X
: return "Infineon Technologies xc16x";
2482 case EM_M16C
: return "Renesas M16C series microprocessors";
2483 case EM_DSPIC30F
: return "Microchip Technology dsPIC30F Digital Signal Controller";
2484 case EM_CE
: return "Freescale Communication Engine RISC core";
2486 case EM_M32C
: return "Renesas M32c";
2488 case EM_TSK3000
: return "Altium TSK3000 core";
2489 case EM_RS08
: return "Freescale RS08 embedded processor";
2490 case EM_ECOG2
: return "Cyan Technology eCOG2 microprocessor";
2491 case EM_SCORE
: return "SUNPLUS S+Core";
2492 case EM_DSP24
: return "New Japan Radio (NJR) 24-bit DSP Processor";
2493 case EM_VIDEOCORE3
: return "Broadcom VideoCore III processor";
2494 case EM_LATTICEMICO32
: return "Lattice Mico32";
2495 case EM_SE_C17
: return "Seiko Epson C17 family";
2497 case EM_TI_C6000
: return "Texas Instruments TMS320C6000 DSP family";
2498 case EM_TI_C2000
: return "Texas Instruments TMS320C2000 DSP family";
2499 case EM_TI_C5500
: return "Texas Instruments TMS320C55x DSP family";
2500 case EM_TI_PRU
: return "TI PRU I/O processor";
2502 case EM_MMDSP_PLUS
: return "STMicroelectronics 64bit VLIW Data Signal Processor";
2503 case EM_CYPRESS_M8C
: return "Cypress M8C microprocessor";
2504 case EM_R32C
: return "Renesas R32C series microprocessors";
2505 case EM_TRIMEDIA
: return "NXP Semiconductors TriMedia architecture family";
2506 case EM_QDSP6
: return "QUALCOMM DSP6 Processor";
2507 case EM_8051
: return "Intel 8051 and variants";
2508 case EM_STXP7X
: return "STMicroelectronics STxP7x family";
2509 case EM_NDS32
: return "Andes Technology compact code size embedded RISC processor family";
2510 case EM_ECOG1X
: return "Cyan Technology eCOG1X family";
2511 case EM_MAXQ30
: return "Dallas Semiconductor MAXQ30 Core microcontrollers";
2513 case EM_XIMO16
: return "New Japan Radio (NJR) 16-bit DSP Processor";
2514 case EM_MANIK
: return "M2000 Reconfigurable RISC Microprocessor";
2515 case EM_CRAYNV2
: return "Cray Inc. NV2 vector architecture";
2516 case EM_RX
: return "Renesas RX";
2517 case EM_METAG
: return "Imagination Technologies Meta processor architecture";
2518 case EM_MCST_ELBRUS
: return "MCST Elbrus general purpose hardware architecture";
2519 case EM_ECOG16
: return "Cyan Technology eCOG16 family";
2522 case EM_MICROBLAZE_OLD
: return "Xilinx MicroBlaze";
2523 case EM_ETPU
: return "Freescale Extended Time Processing Unit";
2524 case EM_SLE9X
: return "Infineon Technologies SLE9X core";
2526 case EM_L1OM
: return "Intel L1OM";
2527 case EM_K1OM
: return "Intel K1OM";
2528 case EM_INTEL182
: return "Intel (reserved)";
2529 case EM_AARCH64
: return "AArch64";
2530 case EM_ARM184
: return "ARM (reserved)";
2531 case EM_AVR32
: return "Atmel Corporation 32-bit microprocessor";
2532 case EM_STM8
: return "STMicroeletronics STM8 8-bit microcontroller";
2533 case EM_TILE64
: return "Tilera TILE64 multicore architecture family";
2534 case EM_TILEPRO
: return "Tilera TILEPro multicore architecture family";
2536 case EM_CUDA
: return "NVIDIA CUDA architecture";
2537 case EM_TILEGX
: return "Tilera TILE-Gx multicore architecture family";
2538 case EM_CLOUDSHIELD
: return "CloudShield architecture family";
2539 case EM_COREA_1ST
: return "KIPO-KAIST Core-A 1st generation processor family";
2540 case EM_COREA_2ND
: return "KIPO-KAIST Core-A 2nd generation processor family";
2541 case EM_ARC_COMPACT2
: return "ARCv2";
2542 case EM_OPEN8
: return "Open8 8-bit RISC soft processor core";
2543 case EM_RL78
: return "Renesas RL78";
2544 case EM_VIDEOCORE5
: return "Broadcom VideoCore V processor";
2545 case EM_78K0R
: return "Renesas 78K0R";
2547 case EM_56800EX
: return "Freescale 56800EX Digital Signal Controller (DSC)";
2548 case EM_BA1
: return "Beyond BA1 CPU architecture";
2549 case EM_BA2
: return "Beyond BA2 CPU architecture";
2550 case EM_XCORE
: return "XMOS xCORE processor family";
2551 case EM_MCHP_PIC
: return "Microchip 8-bit PIC(r) family";
2553 case EM_KM32
: return "KM211 KM32 32-bit processor";
2554 case EM_KMX32
: return "KM211 KMX32 32-bit processor";
2555 case EM_KMX16
: return "KM211 KMX16 16-bit processor";
2556 case EM_KMX8
: return "KM211 KMX8 8-bit processor";
2557 case EM_KVARC
: return "KM211 KVARC processor";
2558 case EM_CDP
: return "Paneve CDP architecture family";
2559 case EM_COGE
: return "Cognitive Smart Memory Processor";
2560 case EM_COOL
: return "Bluechip Systems CoolEngine";
2561 case EM_NORC
: return "Nanoradio Optimized RISC";
2562 case EM_CSR_KALIMBA
: return "CSR Kalimba architecture family";
2564 case EM_Z80
: return "Zilog Z80";
2565 case EM_VISIUM
: return "CDS VISIUMcore processor";
2566 case EM_FT32
: return "FTDI Chip FT32";
2567 case EM_MOXIE
: return "Moxie";
2568 case EM_AMDGPU
: return "AMD GPU";
2569 /* 230 (all reserved) */
2571 case EM_RISCV
: return "RISC-V";
2572 case EM_LANAI
: return "Lanai 32-bit processor";
2573 case EM_CEVA
: return "CEVA Processor Architecture Family";
2574 case EM_CEVA_X2
: return "CEVA X2 Processor Family";
2575 case EM_BPF
: return "Linux BPF";
2576 case EM_GRAPHCORE_IPU
: return "Graphcore Intelligent Processing Unit";
2577 case EM_IMG1
: return "Imagination Technologies";
2579 case EM_NFP
: return "Netronome Flow Processor";
2580 case EM_VE
: return "NEC Vector Engine";
2581 case EM_CSKY
: return "C-SKY";
2582 case EM_ARC_COMPACT3_64
: return "Synopsys ARCv2.3 64-bit";
2583 case EM_MCS6502
: return "MOS Technology MCS 6502 processor";
2584 case EM_ARC_COMPACT3
: return "Synopsys ARCv2.3 32-bit";
2585 case EM_KVX
: return "Kalray VLIW core of the MPPA processor family";
2586 case EM_65816
: return "WDC 65816/65C816";
2587 case EM_LOONGARCH
: return "Loongson Loongarch";
2588 case EM_KF32
: return "ChipON KungFu32";
2590 /* Large numbers... */
2591 case EM_MT
: return "Morpho Techologies MT processor";
2592 case EM_ALPHA
: return "Alpha";
2593 case EM_WEBASSEMBLY
: return "Web Assembly";
2594 case EM_DLX
: return "OpenDLX";
2595 case EM_XSTORMY16
: return "Sanyo XStormy16 CPU core";
2596 case EM_IQ2000
: return "Vitesse IQ2000";
2598 case EM_NIOS32
: return "Altera Nios";
2599 case EM_CYGNUS_MEP
: return "Toshiba MeP Media Engine";
2600 case EM_ADAPTEVA_EPIPHANY
: return "Adapteva EPIPHANY";
2601 case EM_CYGNUS_FRV
: return "Fujitsu FR-V";
2602 case EM_S12Z
: return "Freescale S12Z";
2605 snprintf (buff
, sizeof (buff
), _("<unknown>: 0x%x"), e_machine
);
2611 decode_ARC_machine_flags (unsigned e_flags
, unsigned e_machine
, char buf
[])
2613 /* ARC has two machine types EM_ARC_COMPACT and EM_ARC_COMPACT2. Some
2614 other compilers don't specify an architecture type in the e_flags, and
2615 instead use EM_ARC_COMPACT for old ARC600, ARC601, and ARC700
2616 architectures, and switch to EM_ARC_COMPACT2 for newer ARCEM and ARCHS
2619 Th GNU tools follows this use of EM_ARC_COMPACT and EM_ARC_COMPACT2,
2620 but also sets a specific architecture type in the e_flags field.
2622 However, when decoding the flags we don't worry if we see an
2623 unexpected pairing, for example EM_ARC_COMPACT machine type, with
2624 ARCEM architecture type. */
2626 switch (e_flags
& EF_ARC_MACH_MSK
)
2628 /* We only expect these to occur for EM_ARC_COMPACT2. */
2629 case EF_ARC_CPU_ARCV2EM
:
2630 strcat (buf
, ", ARC EM");
2632 case EF_ARC_CPU_ARCV2HS
:
2633 strcat (buf
, ", ARC HS");
2636 /* We only expect these to occur for EM_ARC_COMPACT. */
2637 case E_ARC_MACH_ARC600
:
2638 strcat (buf
, ", ARC600");
2640 case E_ARC_MACH_ARC601
:
2641 strcat (buf
, ", ARC601");
2643 case E_ARC_MACH_ARC700
:
2644 strcat (buf
, ", ARC700");
2647 /* The only times we should end up here are (a) A corrupt ELF, (b) A
2648 new ELF with new architecture being read by an old version of
2649 readelf, or (c) An ELF built with non-GNU compiler that does not
2650 set the architecture in the e_flags. */
2652 if (e_machine
== EM_ARC_COMPACT
)
2653 strcat (buf
, ", Unknown ARCompact");
2655 strcat (buf
, ", Unknown ARC");
2659 switch (e_flags
& EF_ARC_OSABI_MSK
)
2661 case E_ARC_OSABI_ORIG
:
2662 strcat (buf
, ", (ABI:legacy)");
2664 case E_ARC_OSABI_V2
:
2665 strcat (buf
, ", (ABI:v2)");
2667 /* Only upstream 3.9+ kernels will support ARCv2 ISA. */
2668 case E_ARC_OSABI_V3
:
2669 strcat (buf
, ", v3 no-legacy-syscalls ABI");
2671 case E_ARC_OSABI_V4
:
2672 strcat (buf
, ", v4 ABI");
2675 strcat (buf
, ", unrecognised ARC OSABI flag");
2681 decode_ARM_machine_flags (unsigned e_flags
, char buf
[])
2684 bfd_boolean unknown
= FALSE
;
2686 eabi
= EF_ARM_EABI_VERSION (e_flags
);
2687 e_flags
&= ~ EF_ARM_EABIMASK
;
2689 /* Handle "generic" ARM flags. */
2690 if (e_flags
& EF_ARM_RELEXEC
)
2692 strcat (buf
, ", relocatable executable");
2693 e_flags
&= ~ EF_ARM_RELEXEC
;
2696 if (e_flags
& EF_ARM_PIC
)
2698 strcat (buf
, ", position independent");
2699 e_flags
&= ~ EF_ARM_PIC
;
2702 /* Now handle EABI specific flags. */
2706 strcat (buf
, ", <unrecognized EABI>");
2711 case EF_ARM_EABI_VER1
:
2712 strcat (buf
, ", Version1 EABI");
2717 /* Process flags one bit at a time. */
2718 flag
= e_flags
& - e_flags
;
2723 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
2724 strcat (buf
, ", sorted symbol tables");
2734 case EF_ARM_EABI_VER2
:
2735 strcat (buf
, ", Version2 EABI");
2740 /* Process flags one bit at a time. */
2741 flag
= e_flags
& - e_flags
;
2746 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
2747 strcat (buf
, ", sorted symbol tables");
2750 case EF_ARM_DYNSYMSUSESEGIDX
:
2751 strcat (buf
, ", dynamic symbols use segment index");
2754 case EF_ARM_MAPSYMSFIRST
:
2755 strcat (buf
, ", mapping symbols precede others");
2765 case EF_ARM_EABI_VER3
:
2766 strcat (buf
, ", Version3 EABI");
2769 case EF_ARM_EABI_VER4
:
2770 strcat (buf
, ", Version4 EABI");
2775 /* Process flags one bit at a time. */
2776 flag
= e_flags
& - e_flags
;
2782 strcat (buf
, ", BE8");
2786 strcat (buf
, ", LE8");
2796 case EF_ARM_EABI_VER5
:
2797 strcat (buf
, ", Version5 EABI");
2802 /* Process flags one bit at a time. */
2803 flag
= e_flags
& - e_flags
;
2809 strcat (buf
, ", BE8");
2813 strcat (buf
, ", LE8");
2816 case EF_ARM_ABI_FLOAT_SOFT
: /* Conflicts with EF_ARM_SOFT_FLOAT. */
2817 strcat (buf
, ", soft-float ABI");
2820 case EF_ARM_ABI_FLOAT_HARD
: /* Conflicts with EF_ARM_VFP_FLOAT. */
2821 strcat (buf
, ", hard-float ABI");
2831 case EF_ARM_EABI_UNKNOWN
:
2832 strcat (buf
, ", GNU EABI");
2837 /* Process flags one bit at a time. */
2838 flag
= e_flags
& - e_flags
;
2843 case EF_ARM_INTERWORK
:
2844 strcat (buf
, ", interworking enabled");
2847 case EF_ARM_APCS_26
:
2848 strcat (buf
, ", uses APCS/26");
2851 case EF_ARM_APCS_FLOAT
:
2852 strcat (buf
, ", uses APCS/float");
2856 strcat (buf
, ", position independent");
2860 strcat (buf
, ", 8 bit structure alignment");
2863 case EF_ARM_NEW_ABI
:
2864 strcat (buf
, ", uses new ABI");
2867 case EF_ARM_OLD_ABI
:
2868 strcat (buf
, ", uses old ABI");
2871 case EF_ARM_SOFT_FLOAT
:
2872 strcat (buf
, ", software FP");
2875 case EF_ARM_VFP_FLOAT
:
2876 strcat (buf
, ", VFP");
2879 case EF_ARM_MAVERICK_FLOAT
:
2880 strcat (buf
, ", Maverick FP");
2891 strcat (buf
,_(", <unknown>"));
2895 decode_AVR_machine_flags (unsigned e_flags
, char buf
[], size_t size
)
2897 --size
; /* Leave space for null terminator. */
2899 switch (e_flags
& EF_AVR_MACH
)
2901 case E_AVR_MACH_AVR1
:
2902 strncat (buf
, ", avr:1", size
);
2904 case E_AVR_MACH_AVR2
:
2905 strncat (buf
, ", avr:2", size
);
2907 case E_AVR_MACH_AVR25
:
2908 strncat (buf
, ", avr:25", size
);
2910 case E_AVR_MACH_AVR3
:
2911 strncat (buf
, ", avr:3", size
);
2913 case E_AVR_MACH_AVR31
:
2914 strncat (buf
, ", avr:31", size
);
2916 case E_AVR_MACH_AVR35
:
2917 strncat (buf
, ", avr:35", size
);
2919 case E_AVR_MACH_AVR4
:
2920 strncat (buf
, ", avr:4", size
);
2922 case E_AVR_MACH_AVR5
:
2923 strncat (buf
, ", avr:5", size
);
2925 case E_AVR_MACH_AVR51
:
2926 strncat (buf
, ", avr:51", size
);
2928 case E_AVR_MACH_AVR6
:
2929 strncat (buf
, ", avr:6", size
);
2931 case E_AVR_MACH_AVRTINY
:
2932 strncat (buf
, ", avr:100", size
);
2934 case E_AVR_MACH_XMEGA1
:
2935 strncat (buf
, ", avr:101", size
);
2937 case E_AVR_MACH_XMEGA2
:
2938 strncat (buf
, ", avr:102", size
);
2940 case E_AVR_MACH_XMEGA3
:
2941 strncat (buf
, ", avr:103", size
);
2943 case E_AVR_MACH_XMEGA4
:
2944 strncat (buf
, ", avr:104", size
);
2946 case E_AVR_MACH_XMEGA5
:
2947 strncat (buf
, ", avr:105", size
);
2949 case E_AVR_MACH_XMEGA6
:
2950 strncat (buf
, ", avr:106", size
);
2952 case E_AVR_MACH_XMEGA7
:
2953 strncat (buf
, ", avr:107", size
);
2956 strncat (buf
, ", avr:<unknown>", size
);
2960 size
-= strlen (buf
);
2961 if (e_flags
& EF_AVR_LINKRELAX_PREPARED
)
2962 strncat (buf
, ", link-relax", size
);
2966 decode_NDS32_machine_flags (unsigned e_flags
, char buf
[], size_t size
)
2972 bfd_boolean has_fpu
= FALSE
;
2975 static const char *ABI_STRINGS
[] =
2977 "ABI v0", /* use r5 as return register; only used in N1213HC */
2978 "ABI v1", /* use r0 as return register */
2979 "ABI v2", /* use r0 as return register and don't reserve 24 bytes for arguments */
2980 "ABI v2fp", /* for FPU */
2984 static const char *VER_STRINGS
[] =
2986 "Andes ELF V1.3 or older",
2990 static const char *ARCH_STRINGS
[] =
2999 abi
= EF_NDS_ABI
& e_flags
;
3000 arch
= EF_NDS_ARCH
& e_flags
;
3001 config
= EF_NDS_INST
& e_flags
;
3002 version
= EF_NDS32_ELF_VERSION
& e_flags
;
3004 memset (buf
, 0, size
);
3011 case E_NDS_ABI_V2FP
:
3012 case E_NDS_ABI_AABI
:
3013 case E_NDS_ABI_V2FP_PLUS
:
3014 /* In case there are holes in the array. */
3015 r
+= snprintf (buf
+ r
, size
- r
, ", %s", ABI_STRINGS
[abi
>> EF_NDS_ABI_SHIFT
]);
3019 r
+= snprintf (buf
+ r
, size
- r
, ", <unrecognized ABI>");
3025 case E_NDS32_ELF_VER_1_2
:
3026 case E_NDS32_ELF_VER_1_3
:
3027 case E_NDS32_ELF_VER_1_4
:
3028 r
+= snprintf (buf
+ r
, size
- r
, ", %s", VER_STRINGS
[version
>> EF_NDS32_ELF_VERSION_SHIFT
]);
3032 r
+= snprintf (buf
+ r
, size
- r
, ", <unrecognized ELF version number>");
3036 if (E_NDS_ABI_V0
== abi
)
3038 /* OLD ABI; only used in N1213HC, has performance extension 1. */
3039 r
+= snprintf (buf
+ r
, size
- r
, ", Andes Star v1.0, N1213HC, MAC, PERF1");
3040 if (arch
== E_NDS_ARCH_STAR_V1_0
)
3041 r
+= snprintf (buf
+ r
, size
-r
, ", 16b"); /* has 16-bit instructions */
3047 case E_NDS_ARCH_STAR_V1_0
:
3048 case E_NDS_ARCH_STAR_V2_0
:
3049 case E_NDS_ARCH_STAR_V3_0
:
3050 case E_NDS_ARCH_STAR_V3_M
:
3051 r
+= snprintf (buf
+ r
, size
- r
, ", %s", ARCH_STRINGS
[arch
>> EF_NDS_ARCH_SHIFT
]);
3055 r
+= snprintf (buf
+ r
, size
- r
, ", <unrecognized architecture>");
3056 /* ARCH version determines how the e_flags are interpreted.
3057 If it is unknown, we cannot proceed. */
3061 /* Newer ABI; Now handle architecture specific flags. */
3062 if (arch
== E_NDS_ARCH_STAR_V1_0
)
3064 if (config
& E_NDS32_HAS_MFUSR_PC_INST
)
3065 r
+= snprintf (buf
+ r
, size
-r
, ", MFUSR_PC");
3067 if (!(config
& E_NDS32_HAS_NO_MAC_INST
))
3068 r
+= snprintf (buf
+ r
, size
-r
, ", MAC");
3070 if (config
& E_NDS32_HAS_DIV_INST
)
3071 r
+= snprintf (buf
+ r
, size
-r
, ", DIV");
3073 if (config
& E_NDS32_HAS_16BIT_INST
)
3074 r
+= snprintf (buf
+ r
, size
-r
, ", 16b");
3078 if (config
& E_NDS32_HAS_MFUSR_PC_INST
)
3080 if (version
<= E_NDS32_ELF_VER_1_3
)
3081 r
+= snprintf (buf
+ r
, size
-r
, ", [B8]");
3083 r
+= snprintf (buf
+ r
, size
-r
, ", EX9");
3086 if (config
& E_NDS32_HAS_MAC_DX_INST
)
3087 r
+= snprintf (buf
+ r
, size
-r
, ", MAC_DX");
3089 if (config
& E_NDS32_HAS_DIV_DX_INST
)
3090 r
+= snprintf (buf
+ r
, size
-r
, ", DIV_DX");
3092 if (config
& E_NDS32_HAS_16BIT_INST
)
3094 if (version
<= E_NDS32_ELF_VER_1_3
)
3095 r
+= snprintf (buf
+ r
, size
-r
, ", 16b");
3097 r
+= snprintf (buf
+ r
, size
-r
, ", IFC");
3101 if (config
& E_NDS32_HAS_EXT_INST
)
3102 r
+= snprintf (buf
+ r
, size
-r
, ", PERF1");
3104 if (config
& E_NDS32_HAS_EXT2_INST
)
3105 r
+= snprintf (buf
+ r
, size
-r
, ", PERF2");
3107 if (config
& E_NDS32_HAS_FPU_INST
)
3110 r
+= snprintf (buf
+ r
, size
-r
, ", FPU_SP");
3113 if (config
& E_NDS32_HAS_FPU_DP_INST
)
3116 r
+= snprintf (buf
+ r
, size
-r
, ", FPU_DP");
3119 if (config
& E_NDS32_HAS_FPU_MAC_INST
)
3122 r
+= snprintf (buf
+ r
, size
-r
, ", FPU_MAC");
3127 switch ((config
& E_NDS32_FPU_REG_CONF
) >> E_NDS32_FPU_REG_CONF_SHIFT
)
3129 case E_NDS32_FPU_REG_8SP_4DP
:
3130 r
+= snprintf (buf
+ r
, size
-r
, ", FPU_REG:8/4");
3132 case E_NDS32_FPU_REG_16SP_8DP
:
3133 r
+= snprintf (buf
+ r
, size
-r
, ", FPU_REG:16/8");
3135 case E_NDS32_FPU_REG_32SP_16DP
:
3136 r
+= snprintf (buf
+ r
, size
-r
, ", FPU_REG:32/16");
3138 case E_NDS32_FPU_REG_32SP_32DP
:
3139 r
+= snprintf (buf
+ r
, size
-r
, ", FPU_REG:32/32");
3144 if (config
& E_NDS32_HAS_AUDIO_INST
)
3145 r
+= snprintf (buf
+ r
, size
-r
, ", AUDIO");
3147 if (config
& E_NDS32_HAS_STRING_INST
)
3148 r
+= snprintf (buf
+ r
, size
-r
, ", STR");
3150 if (config
& E_NDS32_HAS_REDUCED_REGS
)
3151 r
+= snprintf (buf
+ r
, size
-r
, ", 16REG");
3153 if (config
& E_NDS32_HAS_VIDEO_INST
)
3155 if (version
<= E_NDS32_ELF_VER_1_3
)
3156 r
+= snprintf (buf
+ r
, size
-r
, ", VIDEO");
3158 r
+= snprintf (buf
+ r
, size
-r
, ", SATURATION");
3161 if (config
& E_NDS32_HAS_ENCRIPT_INST
)
3162 r
+= snprintf (buf
+ r
, size
-r
, ", ENCRP");
3164 if (config
& E_NDS32_HAS_L2C_INST
)
3165 r
+= snprintf (buf
+ r
, size
-r
, ", L2C");
3169 get_machine_flags (Filedata
* filedata
, unsigned e_flags
, unsigned e_machine
)
3171 static char buf
[1024];
3182 case EM_ARC_COMPACT2
:
3183 case EM_ARC_COMPACT
:
3184 decode_ARC_machine_flags (e_flags
, e_machine
, buf
);
3188 decode_ARM_machine_flags (e_flags
, buf
);
3192 decode_AVR_machine_flags (e_flags
, buf
, sizeof buf
);
3196 if (e_flags
& EF_BFIN_PIC
)
3197 strcat (buf
, ", PIC");
3199 if (e_flags
& EF_BFIN_FDPIC
)
3200 strcat (buf
, ", FDPIC");
3202 if (e_flags
& EF_BFIN_CODE_IN_L1
)
3203 strcat (buf
, ", code in L1");
3205 if (e_flags
& EF_BFIN_DATA_IN_L1
)
3206 strcat (buf
, ", data in L1");
3211 switch (e_flags
& EF_FRV_CPU_MASK
)
3213 case EF_FRV_CPU_GENERIC
:
3217 strcat (buf
, ", fr???");
3220 case EF_FRV_CPU_FR300
:
3221 strcat (buf
, ", fr300");
3224 case EF_FRV_CPU_FR400
:
3225 strcat (buf
, ", fr400");
3227 case EF_FRV_CPU_FR405
:
3228 strcat (buf
, ", fr405");
3231 case EF_FRV_CPU_FR450
:
3232 strcat (buf
, ", fr450");
3235 case EF_FRV_CPU_FR500
:
3236 strcat (buf
, ", fr500");
3238 case EF_FRV_CPU_FR550
:
3239 strcat (buf
, ", fr550");
3242 case EF_FRV_CPU_SIMPLE
:
3243 strcat (buf
, ", simple");
3245 case EF_FRV_CPU_TOMCAT
:
3246 strcat (buf
, ", tomcat");
3252 if ((e_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_M68000
)
3253 strcat (buf
, ", m68000");
3254 else if ((e_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_CPU32
)
3255 strcat (buf
, ", cpu32");
3256 else if ((e_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_FIDO
)
3257 strcat (buf
, ", fido_a");
3260 char const * isa
= _("unknown");
3261 char const * mac
= _("unknown mac");
3262 char const * additional
= NULL
;
3264 switch (e_flags
& EF_M68K_CF_ISA_MASK
)
3266 case EF_M68K_CF_ISA_A_NODIV
:
3268 additional
= ", nodiv";
3270 case EF_M68K_CF_ISA_A
:
3273 case EF_M68K_CF_ISA_A_PLUS
:
3276 case EF_M68K_CF_ISA_B_NOUSP
:
3278 additional
= ", nousp";
3280 case EF_M68K_CF_ISA_B
:
3283 case EF_M68K_CF_ISA_C
:
3286 case EF_M68K_CF_ISA_C_NODIV
:
3288 additional
= ", nodiv";
3291 strcat (buf
, ", cf, isa ");
3294 strcat (buf
, additional
);
3295 if (e_flags
& EF_M68K_CF_FLOAT
)
3296 strcat (buf
, ", float");
3297 switch (e_flags
& EF_M68K_CF_MAC_MASK
)
3302 case EF_M68K_CF_MAC
:
3305 case EF_M68K_CF_EMAC
:
3308 case EF_M68K_CF_EMAC_B
:
3321 switch (e_flags
& EF_MEP_CPU_MASK
)
3323 case EF_MEP_CPU_MEP
: strcat (buf
, ", generic MeP"); break;
3324 case EF_MEP_CPU_C2
: strcat (buf
, ", MeP C2"); break;
3325 case EF_MEP_CPU_C3
: strcat (buf
, ", MeP C3"); break;
3326 case EF_MEP_CPU_C4
: strcat (buf
, ", MeP C4"); break;
3327 case EF_MEP_CPU_C5
: strcat (buf
, ", MeP C5"); break;
3328 case EF_MEP_CPU_H1
: strcat (buf
, ", MeP H1"); break;
3329 default: strcat (buf
, _(", <unknown MeP cpu type>")); break;
3332 switch (e_flags
& EF_MEP_COP_MASK
)
3334 case EF_MEP_COP_NONE
: break;
3335 case EF_MEP_COP_AVC
: strcat (buf
, ", AVC coprocessor"); break;
3336 case EF_MEP_COP_AVC2
: strcat (buf
, ", AVC2 coprocessor"); break;
3337 case EF_MEP_COP_FMAX
: strcat (buf
, ", FMAX coprocessor"); break;
3338 case EF_MEP_COP_IVC2
: strcat (buf
, ", IVC2 coprocessor"); break;
3339 default: strcat (buf
, _("<unknown MeP copro type>")); break;
3342 if (e_flags
& EF_MEP_LIBRARY
)
3343 strcat (buf
, ", Built for Library");
3345 if (e_flags
& EF_MEP_INDEX_MASK
)
3346 sprintf (buf
+ strlen (buf
), ", Configuration Index: %#x",
3347 e_flags
& EF_MEP_INDEX_MASK
);
3349 if (e_flags
& ~ EF_MEP_ALL_FLAGS
)
3350 sprintf (buf
+ strlen (buf
), _(", unknown flags bits: %#x"),
3351 e_flags
& ~ EF_MEP_ALL_FLAGS
);
3355 if (e_flags
& EF_PPC_EMB
)
3356 strcat (buf
, ", emb");
3358 if (e_flags
& EF_PPC_RELOCATABLE
)
3359 strcat (buf
, _(", relocatable"));
3361 if (e_flags
& EF_PPC_RELOCATABLE_LIB
)
3362 strcat (buf
, _(", relocatable-lib"));
3366 if (e_flags
& EF_PPC64_ABI
)
3368 char abi
[] = ", abiv0";
3370 abi
[6] += e_flags
& EF_PPC64_ABI
;
3376 if ((e_flags
& EF_RH850_ABI
) == EF_RH850_ABI
)
3377 strcat (buf
, ", RH850 ABI");
3379 if (e_flags
& EF_V800_850E3
)
3380 strcat (buf
, ", V3 architecture");
3382 if ((e_flags
& (EF_RH850_FPU_DOUBLE
| EF_RH850_FPU_SINGLE
)) == 0)
3383 strcat (buf
, ", FPU not used");
3385 if ((e_flags
& (EF_RH850_REGMODE22
| EF_RH850_REGMODE32
)) == 0)
3386 strcat (buf
, ", regmode: COMMON");
3388 if ((e_flags
& (EF_RH850_GP_FIX
| EF_RH850_GP_NOFIX
)) == 0)
3389 strcat (buf
, ", r4 not used");
3391 if ((e_flags
& (EF_RH850_EP_FIX
| EF_RH850_EP_NOFIX
)) == 0)
3392 strcat (buf
, ", r30 not used");
3394 if ((e_flags
& (EF_RH850_TP_FIX
| EF_RH850_TP_NOFIX
)) == 0)
3395 strcat (buf
, ", r5 not used");
3397 if ((e_flags
& (EF_RH850_REG2_RESERVE
| EF_RH850_REG2_NORESERVE
)) == 0)
3398 strcat (buf
, ", r2 not used");
3400 for (e_flags
&= 0xFFFF; e_flags
; e_flags
&= ~ (e_flags
& - e_flags
))
3402 switch (e_flags
& - e_flags
)
3404 case EF_RH850_FPU_DOUBLE
: strcat (buf
, ", double precision FPU"); break;
3405 case EF_RH850_FPU_SINGLE
: strcat (buf
, ", single precision FPU"); break;
3406 case EF_RH850_REGMODE22
: strcat (buf
, ", regmode:22"); break;
3407 case EF_RH850_REGMODE32
: strcat (buf
, ", regmode:23"); break;
3408 case EF_RH850_GP_FIX
: strcat (buf
, ", r4 fixed"); break;
3409 case EF_RH850_GP_NOFIX
: strcat (buf
, ", r4 free"); break;
3410 case EF_RH850_EP_FIX
: strcat (buf
, ", r30 fixed"); break;
3411 case EF_RH850_EP_NOFIX
: strcat (buf
, ", r30 free"); break;
3412 case EF_RH850_TP_FIX
: strcat (buf
, ", r5 fixed"); break;
3413 case EF_RH850_TP_NOFIX
: strcat (buf
, ", r5 free"); break;
3414 case EF_RH850_REG2_RESERVE
: strcat (buf
, ", r2 fixed"); break;
3415 case EF_RH850_REG2_NORESERVE
: strcat (buf
, ", r2 free"); break;
3422 case EM_CYGNUS_V850
:
3423 switch (e_flags
& EF_V850_ARCH
)
3425 case E_V850E3V5_ARCH
:
3426 strcat (buf
, ", v850e3v5");
3428 case E_V850E2V3_ARCH
:
3429 strcat (buf
, ", v850e2v3");
3432 strcat (buf
, ", v850e2");
3435 strcat (buf
, ", v850e1");
3438 strcat (buf
, ", v850e");
3441 strcat (buf
, ", v850");
3444 strcat (buf
, _(", unknown v850 architecture variant"));
3450 case EM_CYGNUS_M32R
:
3451 if ((e_flags
& EF_M32R_ARCH
) == E_M32R_ARCH
)
3452 strcat (buf
, ", m32r");
3456 case EM_MIPS_RS3_LE
:
3457 if (e_flags
& EF_MIPS_NOREORDER
)
3458 strcat (buf
, ", noreorder");
3460 if (e_flags
& EF_MIPS_PIC
)
3461 strcat (buf
, ", pic");
3463 if (e_flags
& EF_MIPS_CPIC
)
3464 strcat (buf
, ", cpic");
3466 if (e_flags
& EF_MIPS_UCODE
)
3467 strcat (buf
, ", ugen_reserved");
3469 if (e_flags
& EF_MIPS_ABI2
)
3470 strcat (buf
, ", abi2");
3472 if (e_flags
& EF_MIPS_OPTIONS_FIRST
)
3473 strcat (buf
, ", odk first");
3475 if (e_flags
& EF_MIPS_32BITMODE
)
3476 strcat (buf
, ", 32bitmode");
3478 if (e_flags
& EF_MIPS_NAN2008
)
3479 strcat (buf
, ", nan2008");
3481 if (e_flags
& EF_MIPS_FP64
)
3482 strcat (buf
, ", fp64");
3484 switch ((e_flags
& EF_MIPS_MACH
))
3486 case E_MIPS_MACH_3900
: strcat (buf
, ", 3900"); break;
3487 case E_MIPS_MACH_4010
: strcat (buf
, ", 4010"); break;
3488 case E_MIPS_MACH_4100
: strcat (buf
, ", 4100"); break;
3489 case E_MIPS_MACH_4111
: strcat (buf
, ", 4111"); break;
3490 case E_MIPS_MACH_4120
: strcat (buf
, ", 4120"); break;
3491 case E_MIPS_MACH_4650
: strcat (buf
, ", 4650"); break;
3492 case E_MIPS_MACH_5400
: strcat (buf
, ", 5400"); break;
3493 case E_MIPS_MACH_5500
: strcat (buf
, ", 5500"); break;
3494 case E_MIPS_MACH_5900
: strcat (buf
, ", 5900"); break;
3495 case E_MIPS_MACH_SB1
: strcat (buf
, ", sb1"); break;
3496 case E_MIPS_MACH_9000
: strcat (buf
, ", 9000"); break;
3497 case E_MIPS_MACH_LS2E
: strcat (buf
, ", loongson-2e"); break;
3498 case E_MIPS_MACH_LS2F
: strcat (buf
, ", loongson-2f"); break;
3499 case E_MIPS_MACH_GS464
: strcat (buf
, ", gs464"); break;
3500 case E_MIPS_MACH_GS464E
: strcat (buf
, ", gs464e"); break;
3501 case E_MIPS_MACH_GS264E
: strcat (buf
, ", gs264e"); break;
3502 case E_MIPS_MACH_OCTEON
: strcat (buf
, ", octeon"); break;
3503 case E_MIPS_MACH_OCTEON2
: strcat (buf
, ", octeon2"); break;
3504 case E_MIPS_MACH_OCTEON3
: strcat (buf
, ", octeon3"); break;
3505 case E_MIPS_MACH_XLR
: strcat (buf
, ", xlr"); break;
3506 case E_MIPS_MACH_IAMR2
: strcat (buf
, ", interaptiv-mr2"); break;
3508 /* We simply ignore the field in this case to avoid confusion:
3509 MIPS ELF does not specify EF_MIPS_MACH, it is a GNU
3512 default: strcat (buf
, _(", unknown CPU")); break;
3515 switch ((e_flags
& EF_MIPS_ABI
))
3517 case E_MIPS_ABI_O32
: strcat (buf
, ", o32"); break;
3518 case E_MIPS_ABI_O64
: strcat (buf
, ", o64"); break;
3519 case E_MIPS_ABI_EABI32
: strcat (buf
, ", eabi32"); break;
3520 case E_MIPS_ABI_EABI64
: strcat (buf
, ", eabi64"); break;
3522 /* We simply ignore the field in this case to avoid confusion:
3523 MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension.
3524 This means it is likely to be an o32 file, but not for
3527 default: strcat (buf
, _(", unknown ABI")); break;
3530 if (e_flags
& EF_MIPS_ARCH_ASE_MDMX
)
3531 strcat (buf
, ", mdmx");
3533 if (e_flags
& EF_MIPS_ARCH_ASE_M16
)
3534 strcat (buf
, ", mips16");
3536 if (e_flags
& EF_MIPS_ARCH_ASE_MICROMIPS
)
3537 strcat (buf
, ", micromips");
3539 switch ((e_flags
& EF_MIPS_ARCH
))
3541 case E_MIPS_ARCH_1
: strcat (buf
, ", mips1"); break;
3542 case E_MIPS_ARCH_2
: strcat (buf
, ", mips2"); break;
3543 case E_MIPS_ARCH_3
: strcat (buf
, ", mips3"); break;
3544 case E_MIPS_ARCH_4
: strcat (buf
, ", mips4"); break;
3545 case E_MIPS_ARCH_5
: strcat (buf
, ", mips5"); break;
3546 case E_MIPS_ARCH_32
: strcat (buf
, ", mips32"); break;
3547 case E_MIPS_ARCH_32R2
: strcat (buf
, ", mips32r2"); break;
3548 case E_MIPS_ARCH_32R6
: strcat (buf
, ", mips32r6"); break;
3549 case E_MIPS_ARCH_64
: strcat (buf
, ", mips64"); break;
3550 case E_MIPS_ARCH_64R2
: strcat (buf
, ", mips64r2"); break;
3551 case E_MIPS_ARCH_64R6
: strcat (buf
, ", mips64r6"); break;
3552 default: strcat (buf
, _(", unknown ISA")); break;
3557 decode_NDS32_machine_flags (e_flags
, buf
, sizeof buf
);
3561 switch (EF_NFP_MACH (e_flags
))
3563 case E_NFP_MACH_3200
:
3564 strcat (buf
, ", NFP-32xx");
3566 case E_NFP_MACH_6000
:
3567 strcat (buf
, ", NFP-6xxx");
3573 if (e_flags
& EF_RISCV_RVC
)
3574 strcat (buf
, ", RVC");
3576 if (e_flags
& EF_RISCV_RVE
)
3577 strcat (buf
, ", RVE");
3579 switch (e_flags
& EF_RISCV_FLOAT_ABI
)
3581 case EF_RISCV_FLOAT_ABI_SOFT
:
3582 strcat (buf
, ", soft-float ABI");
3585 case EF_RISCV_FLOAT_ABI_SINGLE
:
3586 strcat (buf
, ", single-float ABI");
3589 case EF_RISCV_FLOAT_ABI_DOUBLE
:
3590 strcat (buf
, ", double-float ABI");
3593 case EF_RISCV_FLOAT_ABI_QUAD
:
3594 strcat (buf
, ", quad-float ABI");
3600 switch ((e_flags
& EF_SH_MACH_MASK
))
3602 case EF_SH1
: strcat (buf
, ", sh1"); break;
3603 case EF_SH2
: strcat (buf
, ", sh2"); break;
3604 case EF_SH3
: strcat (buf
, ", sh3"); break;
3605 case EF_SH_DSP
: strcat (buf
, ", sh-dsp"); break;
3606 case EF_SH3_DSP
: strcat (buf
, ", sh3-dsp"); break;
3607 case EF_SH4AL_DSP
: strcat (buf
, ", sh4al-dsp"); break;
3608 case EF_SH3E
: strcat (buf
, ", sh3e"); break;
3609 case EF_SH4
: strcat (buf
, ", sh4"); break;
3610 case EF_SH5
: strcat (buf
, ", sh5"); break;
3611 case EF_SH2E
: strcat (buf
, ", sh2e"); break;
3612 case EF_SH4A
: strcat (buf
, ", sh4a"); break;
3613 case EF_SH2A
: strcat (buf
, ", sh2a"); break;
3614 case EF_SH4_NOFPU
: strcat (buf
, ", sh4-nofpu"); break;
3615 case EF_SH4A_NOFPU
: strcat (buf
, ", sh4a-nofpu"); break;
3616 case EF_SH2A_NOFPU
: strcat (buf
, ", sh2a-nofpu"); break;
3617 case EF_SH3_NOMMU
: strcat (buf
, ", sh3-nommu"); break;
3618 case EF_SH4_NOMMU_NOFPU
: strcat (buf
, ", sh4-nommu-nofpu"); break;
3619 case EF_SH2A_SH4_NOFPU
: strcat (buf
, ", sh2a-nofpu-or-sh4-nommu-nofpu"); break;
3620 case EF_SH2A_SH3_NOFPU
: strcat (buf
, ", sh2a-nofpu-or-sh3-nommu"); break;
3621 case EF_SH2A_SH4
: strcat (buf
, ", sh2a-or-sh4"); break;
3622 case EF_SH2A_SH3E
: strcat (buf
, ", sh2a-or-sh3e"); break;
3623 default: strcat (buf
, _(", unknown ISA")); break;
3626 if (e_flags
& EF_SH_PIC
)
3627 strcat (buf
, ", pic");
3629 if (e_flags
& EF_SH_FDPIC
)
3630 strcat (buf
, ", fdpic");
3634 if (e_flags
& EF_OR1K_NODELAY
)
3635 strcat (buf
, ", no delay");
3639 if (e_flags
& EF_SPARC_32PLUS
)
3640 strcat (buf
, ", v8+");
3642 if (e_flags
& EF_SPARC_SUN_US1
)
3643 strcat (buf
, ", ultrasparcI");
3645 if (e_flags
& EF_SPARC_SUN_US3
)
3646 strcat (buf
, ", ultrasparcIII");
3648 if (e_flags
& EF_SPARC_HAL_R1
)
3649 strcat (buf
, ", halr1");
3651 if (e_flags
& EF_SPARC_LEDATA
)
3652 strcat (buf
, ", ledata");
3654 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_TSO
)
3655 strcat (buf
, ", tso");
3657 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_PSO
)
3658 strcat (buf
, ", pso");
3660 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_RMO
)
3661 strcat (buf
, ", rmo");
3665 switch (e_flags
& EF_PARISC_ARCH
)
3667 case EFA_PARISC_1_0
:
3668 strcpy (buf
, ", PA-RISC 1.0");
3670 case EFA_PARISC_1_1
:
3671 strcpy (buf
, ", PA-RISC 1.1");
3673 case EFA_PARISC_2_0
:
3674 strcpy (buf
, ", PA-RISC 2.0");
3679 if (e_flags
& EF_PARISC_TRAPNIL
)
3680 strcat (buf
, ", trapnil");
3681 if (e_flags
& EF_PARISC_EXT
)
3682 strcat (buf
, ", ext");
3683 if (e_flags
& EF_PARISC_LSB
)
3684 strcat (buf
, ", lsb");
3685 if (e_flags
& EF_PARISC_WIDE
)
3686 strcat (buf
, ", wide");
3687 if (e_flags
& EF_PARISC_NO_KABP
)
3688 strcat (buf
, ", no kabp");
3689 if (e_flags
& EF_PARISC_LAZYSWAP
)
3690 strcat (buf
, ", lazyswap");
3695 if ((e_flags
& EF_PICOJAVA_NEWCALLS
) == EF_PICOJAVA_NEWCALLS
)
3696 strcat (buf
, ", new calling convention");
3698 if ((e_flags
& EF_PICOJAVA_GNUCALLS
) == EF_PICOJAVA_GNUCALLS
)
3699 strcat (buf
, ", gnu calling convention");
3703 if ((e_flags
& EF_IA_64_ABI64
))
3704 strcat (buf
, ", 64-bit");
3706 strcat (buf
, ", 32-bit");
3707 if ((e_flags
& EF_IA_64_REDUCEDFP
))
3708 strcat (buf
, ", reduced fp model");
3709 if ((e_flags
& EF_IA_64_NOFUNCDESC_CONS_GP
))
3710 strcat (buf
, ", no function descriptors, constant gp");
3711 else if ((e_flags
& EF_IA_64_CONS_GP
))
3712 strcat (buf
, ", constant gp");
3713 if ((e_flags
& EF_IA_64_ABSOLUTE
))
3714 strcat (buf
, ", absolute");
3715 if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_OPENVMS
)
3717 if ((e_flags
& EF_IA_64_VMS_LINKAGES
))
3718 strcat (buf
, ", vms_linkages");
3719 switch ((e_flags
& EF_IA_64_VMS_COMCOD
))
3721 case EF_IA_64_VMS_COMCOD_SUCCESS
:
3723 case EF_IA_64_VMS_COMCOD_WARNING
:
3724 strcat (buf
, ", warning");
3726 case EF_IA_64_VMS_COMCOD_ERROR
:
3727 strcat (buf
, ", error");
3729 case EF_IA_64_VMS_COMCOD_ABORT
:
3730 strcat (buf
, ", abort");
3733 warn (_("Unrecognised IA64 VMS Command Code: %x\n"),
3734 e_flags
& EF_IA_64_VMS_COMCOD
);
3735 strcat (buf
, ", <unknown>");
3741 if ((e_flags
& EF_VAX_NONPIC
))
3742 strcat (buf
, ", non-PIC");
3743 if ((e_flags
& EF_VAX_DFLOAT
))
3744 strcat (buf
, ", D-Float");
3745 if ((e_flags
& EF_VAX_GFLOAT
))
3746 strcat (buf
, ", G-Float");
3750 if (e_flags
& EF_VISIUM_ARCH_MCM
)
3751 strcat (buf
, ", mcm");
3752 else if (e_flags
& EF_VISIUM_ARCH_MCM24
)
3753 strcat (buf
, ", mcm24");
3754 if (e_flags
& EF_VISIUM_ARCH_GR6
)
3755 strcat (buf
, ", gr6");
3759 switch (e_flags
& E_FLAG_RL78_CPU_MASK
)
3761 case E_FLAG_RL78_ANY_CPU
: break;
3762 case E_FLAG_RL78_G10
: strcat (buf
, ", G10"); break;
3763 case E_FLAG_RL78_G13
: strcat (buf
, ", G13"); break;
3764 case E_FLAG_RL78_G14
: strcat (buf
, ", G14"); break;
3766 if (e_flags
& E_FLAG_RL78_64BIT_DOUBLES
)
3767 strcat (buf
, ", 64-bit doubles");
3771 if (e_flags
& E_FLAG_RX_64BIT_DOUBLES
)
3772 strcat (buf
, ", 64-bit doubles");
3773 if (e_flags
& E_FLAG_RX_DSP
)
3774 strcat (buf
, ", dsp");
3775 if (e_flags
& E_FLAG_RX_PID
)
3776 strcat (buf
, ", pid");
3777 if (e_flags
& E_FLAG_RX_ABI
)
3778 strcat (buf
, ", RX ABI");
3779 if (e_flags
& E_FLAG_RX_SINSNS_SET
)
3780 strcat (buf
, e_flags
& E_FLAG_RX_SINSNS_YES
3781 ? ", uses String instructions" : ", bans String instructions");
3782 if (e_flags
& E_FLAG_RX_V2
)
3783 strcat (buf
, ", V2");
3784 if (e_flags
& E_FLAG_RX_V3
)
3785 strcat (buf
, ", V3");
3789 if (e_flags
& EF_S390_HIGH_GPRS
)
3790 strcat (buf
, ", highgprs");
3794 if ((e_flags
& EF_C6000_REL
))
3795 strcat (buf
, ", relocatable module");
3799 strcat (buf
, _(": architecture variant: "));
3800 switch (e_flags
& EF_MSP430_MACH
)
3802 case E_MSP430_MACH_MSP430x11
: strcat (buf
, "MSP430x11"); break;
3803 case E_MSP430_MACH_MSP430x11x1
: strcat (buf
, "MSP430x11x1 "); break;
3804 case E_MSP430_MACH_MSP430x12
: strcat (buf
, "MSP430x12"); break;
3805 case E_MSP430_MACH_MSP430x13
: strcat (buf
, "MSP430x13"); break;
3806 case E_MSP430_MACH_MSP430x14
: strcat (buf
, "MSP430x14"); break;
3807 case E_MSP430_MACH_MSP430x15
: strcat (buf
, "MSP430x15"); break;
3808 case E_MSP430_MACH_MSP430x16
: strcat (buf
, "MSP430x16"); break;
3809 case E_MSP430_MACH_MSP430x31
: strcat (buf
, "MSP430x31"); break;
3810 case E_MSP430_MACH_MSP430x32
: strcat (buf
, "MSP430x32"); break;
3811 case E_MSP430_MACH_MSP430x33
: strcat (buf
, "MSP430x33"); break;
3812 case E_MSP430_MACH_MSP430x41
: strcat (buf
, "MSP430x41"); break;
3813 case E_MSP430_MACH_MSP430x42
: strcat (buf
, "MSP430x42"); break;
3814 case E_MSP430_MACH_MSP430x43
: strcat (buf
, "MSP430x43"); break;
3815 case E_MSP430_MACH_MSP430x44
: strcat (buf
, "MSP430x44"); break;
3816 case E_MSP430_MACH_MSP430X
: strcat (buf
, "MSP430X"); break;
3818 strcat (buf
, _(": unknown")); break;
3821 if (e_flags
& ~ EF_MSP430_MACH
)
3822 strcat (buf
, _(": unknown extra flag bits also present"));
3826 switch (e_flags
& EF_Z80_MACH_MSK
)
3828 case EF_Z80_MACH_Z80
: strcat (buf
, ", Z80"); break;
3829 case EF_Z80_MACH_Z180
: strcat (buf
, ", Z180"); break;
3830 case EF_Z80_MACH_R800
: strcat (buf
, ", R800"); break;
3831 case EF_Z80_MACH_EZ80_Z80
: strcat (buf
, ", EZ80"); break;
3832 case EF_Z80_MACH_EZ80_ADL
: strcat (buf
, ", EZ80, ADL"); break;
3833 case EF_Z80_MACH_GBZ80
: strcat (buf
, ", GBZ80"); break;
3834 case EF_Z80_MACH_Z80N
: strcat (buf
, ", Z80N"); break;
3836 strcat (buf
, _(", unknown")); break;
3846 get_osabi_name (Filedata
* filedata
, unsigned int osabi
)
3848 static char buff
[32];
3852 case ELFOSABI_NONE
: return "UNIX - System V";
3853 case ELFOSABI_HPUX
: return "UNIX - HP-UX";
3854 case ELFOSABI_NETBSD
: return "UNIX - NetBSD";
3855 case ELFOSABI_GNU
: return "UNIX - GNU";
3856 case ELFOSABI_SOLARIS
: return "UNIX - Solaris";
3857 case ELFOSABI_AIX
: return "UNIX - AIX";
3858 case ELFOSABI_IRIX
: return "UNIX - IRIX";
3859 case ELFOSABI_FREEBSD
: return "UNIX - FreeBSD";
3860 case ELFOSABI_TRU64
: return "UNIX - TRU64";
3861 case ELFOSABI_MODESTO
: return "Novell - Modesto";
3862 case ELFOSABI_OPENBSD
: return "UNIX - OpenBSD";
3863 case ELFOSABI_OPENVMS
: return "VMS - OpenVMS";
3864 case ELFOSABI_NSK
: return "HP - Non-Stop Kernel";
3865 case ELFOSABI_AROS
: return "AROS";
3866 case ELFOSABI_FENIXOS
: return "FenixOS";
3867 case ELFOSABI_CLOUDABI
: return "Nuxi CloudABI";
3868 case ELFOSABI_OPENVOS
: return "Stratus Technologies OpenVOS";
3871 switch (filedata
->file_header
.e_machine
)
3876 case ELFOSABI_ARM
: return "ARM";
3877 case ELFOSABI_ARM_FDPIC
: return "ARM FDPIC";
3888 case ELFOSABI_STANDALONE
: return _("Standalone App");
3897 case ELFOSABI_C6000_ELFABI
: return _("Bare-metal C6000");
3898 case ELFOSABI_C6000_LINUX
: return "Linux C6000";
3907 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), osabi
);
3913 get_aarch64_segment_type (unsigned long type
)
3917 case PT_AARCH64_ARCHEXT
: return "AARCH64_ARCHEXT";
3918 default: return NULL
;
3923 get_arm_segment_type (unsigned long type
)
3927 case PT_ARM_EXIDX
: return "EXIDX";
3928 default: return NULL
;
3933 get_s390_segment_type (unsigned long type
)
3937 case PT_S390_PGSTE
: return "S390_PGSTE";
3938 default: return NULL
;
3943 get_mips_segment_type (unsigned long type
)
3947 case PT_MIPS_REGINFO
: return "REGINFO";
3948 case PT_MIPS_RTPROC
: return "RTPROC";
3949 case PT_MIPS_OPTIONS
: return "OPTIONS";
3950 case PT_MIPS_ABIFLAGS
: return "ABIFLAGS";
3951 default: return NULL
;
3956 get_parisc_segment_type (unsigned long type
)
3960 case PT_PARISC_ARCHEXT
: return "PARISC_ARCHEXT";
3961 case PT_PARISC_UNWIND
: return "PARISC_UNWIND";
3962 case PT_PARISC_WEAKORDER
: return "PARISC_WEAKORDER";
3963 default: return NULL
;
3968 get_ia64_segment_type (unsigned long type
)
3972 case PT_IA_64_ARCHEXT
: return "IA_64_ARCHEXT";
3973 case PT_IA_64_UNWIND
: return "IA_64_UNWIND";
3974 default: return NULL
;
3979 get_tic6x_segment_type (unsigned long type
)
3983 case PT_C6000_PHATTR
: return "C6000_PHATTR";
3984 default: return NULL
;
3989 get_hpux_segment_type (unsigned long type
, unsigned e_machine
)
3991 if (e_machine
== EM_PARISC
)
3994 case PT_HP_TLS
: return "HP_TLS";
3995 case PT_HP_CORE_NONE
: return "HP_CORE_NONE";
3996 case PT_HP_CORE_VERSION
: return "HP_CORE_VERSION";
3997 case PT_HP_CORE_KERNEL
: return "HP_CORE_KERNEL";
3998 case PT_HP_CORE_COMM
: return "HP_CORE_COMM";
3999 case PT_HP_CORE_PROC
: return "HP_CORE_PROC";
4000 case PT_HP_CORE_LOADABLE
: return "HP_CORE_LOADABLE";
4001 case PT_HP_CORE_STACK
: return "HP_CORE_STACK";
4002 case PT_HP_CORE_SHM
: return "HP_CORE_SHM";
4003 case PT_HP_CORE_MMF
: return "HP_CORE_MMF";
4004 case PT_HP_PARALLEL
: return "HP_PARALLEL";
4005 case PT_HP_FASTBIND
: return "HP_FASTBIND";
4006 case PT_HP_OPT_ANNOT
: return "HP_OPT_ANNOT";
4007 case PT_HP_HSL_ANNOT
: return "HP_HSL_ANNOT";
4008 case PT_HP_STACK
: return "HP_STACK";
4009 case PT_HP_CORE_UTSNAME
: return "HP_CORE_UTSNAME";
4010 default: return NULL
;
4013 if (e_machine
== EM_IA_64
)
4016 case PT_HP_TLS
: return "HP_TLS";
4017 case PT_IA_64_HP_OPT_ANOT
: return "HP_OPT_ANNOT";
4018 case PT_IA_64_HP_HSL_ANOT
: return "HP_HSL_ANNOT";
4019 case PT_IA_64_HP_STACK
: return "HP_STACK";
4020 default: return NULL
;
4027 get_solaris_segment_type (unsigned long type
)
4031 case 0x6464e550: return "PT_SUNW_UNWIND";
4032 case 0x6474e550: return "PT_SUNW_EH_FRAME";
4033 case 0x6ffffff7: return "PT_LOSUNW";
4034 case 0x6ffffffa: return "PT_SUNWBSS";
4035 case 0x6ffffffb: return "PT_SUNWSTACK";
4036 case 0x6ffffffc: return "PT_SUNWDTRACE";
4037 case 0x6ffffffd: return "PT_SUNWCAP";
4038 case 0x6fffffff: return "PT_HISUNW";
4039 default: return NULL
;
4044 get_segment_type (Filedata
* filedata
, unsigned long p_type
)
4046 static char buff
[32];
4050 case PT_NULL
: return "NULL";
4051 case PT_LOAD
: return "LOAD";
4052 case PT_DYNAMIC
: return "DYNAMIC";
4053 case PT_INTERP
: return "INTERP";
4054 case PT_NOTE
: return "NOTE";
4055 case PT_SHLIB
: return "SHLIB";
4056 case PT_PHDR
: return "PHDR";
4057 case PT_TLS
: return "TLS";
4058 case PT_GNU_EH_FRAME
: return "GNU_EH_FRAME";
4059 case PT_GNU_STACK
: return "GNU_STACK";
4060 case PT_GNU_RELRO
: return "GNU_RELRO";
4061 case PT_GNU_PROPERTY
: return "GNU_PROPERTY";
4063 case PT_OPENBSD_RANDOMIZE
: return "OPENBSD_RANDOMIZE";
4064 case PT_OPENBSD_WXNEEDED
: return "OPENBSD_WXNEEDED";
4065 case PT_OPENBSD_BOOTDATA
: return "OPENBSD_BOOTDATA";
4068 if ((p_type
>= PT_LOPROC
) && (p_type
<= PT_HIPROC
))
4070 const char * result
;
4072 switch (filedata
->file_header
.e_machine
)
4075 result
= get_aarch64_segment_type (p_type
);
4078 result
= get_arm_segment_type (p_type
);
4081 case EM_MIPS_RS3_LE
:
4082 result
= get_mips_segment_type (p_type
);
4085 result
= get_parisc_segment_type (p_type
);
4088 result
= get_ia64_segment_type (p_type
);
4091 result
= get_tic6x_segment_type (p_type
);
4095 result
= get_s390_segment_type (p_type
);
4105 sprintf (buff
, "LOPROC+%#lx", p_type
- PT_LOPROC
);
4107 else if ((p_type
>= PT_LOOS
) && (p_type
<= PT_HIOS
))
4109 const char * result
= NULL
;
4111 switch (filedata
->file_header
.e_ident
[EI_OSABI
])
4114 case ELFOSABI_FREEBSD
:
4115 if (p_type
>= PT_GNU_MBIND_LO
&& p_type
<= PT_GNU_MBIND_HI
)
4117 sprintf (buff
, "GNU_MBIND+%#lx", p_type
- PT_GNU_MBIND_LO
);
4122 result
= get_hpux_segment_type (p_type
,
4123 filedata
->file_header
.e_machine
);
4125 case ELFOSABI_SOLARIS
:
4126 result
= get_solaris_segment_type (p_type
);
4134 sprintf (buff
, "LOOS+%#lx", p_type
- PT_LOOS
);
4137 snprintf (buff
, sizeof (buff
), _("<unknown>: %lx"), p_type
);
4144 get_arc_section_type_name (unsigned int sh_type
)
4148 case SHT_ARC_ATTRIBUTES
: return "ARC_ATTRIBUTES";
4156 get_mips_section_type_name (unsigned int sh_type
)
4160 case SHT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
4161 case SHT_MIPS_MSYM
: return "MIPS_MSYM";
4162 case SHT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
4163 case SHT_MIPS_GPTAB
: return "MIPS_GPTAB";
4164 case SHT_MIPS_UCODE
: return "MIPS_UCODE";
4165 case SHT_MIPS_DEBUG
: return "MIPS_DEBUG";
4166 case SHT_MIPS_REGINFO
: return "MIPS_REGINFO";
4167 case SHT_MIPS_PACKAGE
: return "MIPS_PACKAGE";
4168 case SHT_MIPS_PACKSYM
: return "MIPS_PACKSYM";
4169 case SHT_MIPS_RELD
: return "MIPS_RELD";
4170 case SHT_MIPS_IFACE
: return "MIPS_IFACE";
4171 case SHT_MIPS_CONTENT
: return "MIPS_CONTENT";
4172 case SHT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
4173 case SHT_MIPS_SHDR
: return "MIPS_SHDR";
4174 case SHT_MIPS_FDESC
: return "MIPS_FDESC";
4175 case SHT_MIPS_EXTSYM
: return "MIPS_EXTSYM";
4176 case SHT_MIPS_DENSE
: return "MIPS_DENSE";
4177 case SHT_MIPS_PDESC
: return "MIPS_PDESC";
4178 case SHT_MIPS_LOCSYM
: return "MIPS_LOCSYM";
4179 case SHT_MIPS_AUXSYM
: return "MIPS_AUXSYM";
4180 case SHT_MIPS_OPTSYM
: return "MIPS_OPTSYM";
4181 case SHT_MIPS_LOCSTR
: return "MIPS_LOCSTR";
4182 case SHT_MIPS_LINE
: return "MIPS_LINE";
4183 case SHT_MIPS_RFDESC
: return "MIPS_RFDESC";
4184 case SHT_MIPS_DELTASYM
: return "MIPS_DELTASYM";
4185 case SHT_MIPS_DELTAINST
: return "MIPS_DELTAINST";
4186 case SHT_MIPS_DELTACLASS
: return "MIPS_DELTACLASS";
4187 case SHT_MIPS_DWARF
: return "MIPS_DWARF";
4188 case SHT_MIPS_DELTADECL
: return "MIPS_DELTADECL";
4189 case SHT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
4190 case SHT_MIPS_EVENTS
: return "MIPS_EVENTS";
4191 case SHT_MIPS_TRANSLATE
: return "MIPS_TRANSLATE";
4192 case SHT_MIPS_PIXIE
: return "MIPS_PIXIE";
4193 case SHT_MIPS_XLATE
: return "MIPS_XLATE";
4194 case SHT_MIPS_XLATE_DEBUG
: return "MIPS_XLATE_DEBUG";
4195 case SHT_MIPS_WHIRL
: return "MIPS_WHIRL";
4196 case SHT_MIPS_EH_REGION
: return "MIPS_EH_REGION";
4197 case SHT_MIPS_XLATE_OLD
: return "MIPS_XLATE_OLD";
4198 case SHT_MIPS_PDR_EXCEPTION
: return "MIPS_PDR_EXCEPTION";
4199 case SHT_MIPS_ABIFLAGS
: return "MIPS_ABIFLAGS";
4200 case SHT_MIPS_XHASH
: return "MIPS_XHASH";
4208 get_parisc_section_type_name (unsigned int sh_type
)
4212 case SHT_PARISC_EXT
: return "PARISC_EXT";
4213 case SHT_PARISC_UNWIND
: return "PARISC_UNWIND";
4214 case SHT_PARISC_DOC
: return "PARISC_DOC";
4215 case SHT_PARISC_ANNOT
: return "PARISC_ANNOT";
4216 case SHT_PARISC_SYMEXTN
: return "PARISC_SYMEXTN";
4217 case SHT_PARISC_STUBS
: return "PARISC_STUBS";
4218 case SHT_PARISC_DLKM
: return "PARISC_DLKM";
4219 default: return NULL
;
4224 get_ia64_section_type_name (Filedata
* filedata
, unsigned int sh_type
)
4226 /* If the top 8 bits are 0x78 the next 8 are the os/abi ID. */
4227 if ((sh_type
& 0xFF000000) == SHT_IA_64_LOPSREG
)
4228 return get_osabi_name (filedata
, (sh_type
& 0x00FF0000) >> 16);
4232 case SHT_IA_64_EXT
: return "IA_64_EXT";
4233 case SHT_IA_64_UNWIND
: return "IA_64_UNWIND";
4234 case SHT_IA_64_PRIORITY_INIT
: return "IA_64_PRIORITY_INIT";
4235 case SHT_IA_64_VMS_TRACE
: return "VMS_TRACE";
4236 case SHT_IA_64_VMS_TIE_SIGNATURES
: return "VMS_TIE_SIGNATURES";
4237 case SHT_IA_64_VMS_DEBUG
: return "VMS_DEBUG";
4238 case SHT_IA_64_VMS_DEBUG_STR
: return "VMS_DEBUG_STR";
4239 case SHT_IA_64_VMS_LINKAGES
: return "VMS_LINKAGES";
4240 case SHT_IA_64_VMS_SYMBOL_VECTOR
: return "VMS_SYMBOL_VECTOR";
4241 case SHT_IA_64_VMS_FIXUP
: return "VMS_FIXUP";
4249 get_x86_64_section_type_name (unsigned int sh_type
)
4253 case SHT_X86_64_UNWIND
: return "X86_64_UNWIND";
4254 default: return NULL
;
4259 get_aarch64_section_type_name (unsigned int sh_type
)
4263 case SHT_AARCH64_ATTRIBUTES
: return "AARCH64_ATTRIBUTES";
4264 default: return NULL
;
4269 get_arm_section_type_name (unsigned int sh_type
)
4273 case SHT_ARM_EXIDX
: return "ARM_EXIDX";
4274 case SHT_ARM_PREEMPTMAP
: return "ARM_PREEMPTMAP";
4275 case SHT_ARM_ATTRIBUTES
: return "ARM_ATTRIBUTES";
4276 case SHT_ARM_DEBUGOVERLAY
: return "ARM_DEBUGOVERLAY";
4277 case SHT_ARM_OVERLAYSECTION
: return "ARM_OVERLAYSECTION";
4278 default: return NULL
;
4283 get_tic6x_section_type_name (unsigned int sh_type
)
4287 case SHT_C6000_UNWIND
: return "C6000_UNWIND";
4288 case SHT_C6000_PREEMPTMAP
: return "C6000_PREEMPTMAP";
4289 case SHT_C6000_ATTRIBUTES
: return "C6000_ATTRIBUTES";
4290 case SHT_TI_ICODE
: return "TI_ICODE";
4291 case SHT_TI_XREF
: return "TI_XREF";
4292 case SHT_TI_HANDLER
: return "TI_HANDLER";
4293 case SHT_TI_INITINFO
: return "TI_INITINFO";
4294 case SHT_TI_PHATTRS
: return "TI_PHATTRS";
4295 default: return NULL
;
4300 get_msp430_section_type_name (unsigned int sh_type
)
4304 case SHT_MSP430_SEC_FLAGS
: return "MSP430_SEC_FLAGS";
4305 case SHT_MSP430_SYM_ALIASES
: return "MSP430_SYM_ALIASES";
4306 case SHT_MSP430_ATTRIBUTES
: return "MSP430_ATTRIBUTES";
4307 default: return NULL
;
4312 get_nfp_section_type_name (unsigned int sh_type
)
4316 case SHT_NFP_MECONFIG
: return "NFP_MECONFIG";
4317 case SHT_NFP_INITREG
: return "NFP_INITREG";
4318 case SHT_NFP_UDEBUG
: return "NFP_UDEBUG";
4319 default: return NULL
;
4324 get_v850_section_type_name (unsigned int sh_type
)
4328 case SHT_V850_SCOMMON
: return "V850 Small Common";
4329 case SHT_V850_TCOMMON
: return "V850 Tiny Common";
4330 case SHT_V850_ZCOMMON
: return "V850 Zero Common";
4331 case SHT_RENESAS_IOP
: return "RENESAS IOP";
4332 case SHT_RENESAS_INFO
: return "RENESAS INFO";
4333 default: return NULL
;
4338 get_riscv_section_type_name (unsigned int sh_type
)
4342 case SHT_RISCV_ATTRIBUTES
: return "RISCV_ATTRIBUTES";
4343 default: return NULL
;
4348 get_csky_section_type_name (unsigned int sh_type
)
4352 case SHT_CSKY_ATTRIBUTES
: return "CSKY_ATTRIBUTES";
4353 default: return NULL
;
4358 get_section_type_name (Filedata
* filedata
, unsigned int sh_type
)
4360 static char buff
[32];
4361 const char * result
;
4365 case SHT_NULL
: return "NULL";
4366 case SHT_PROGBITS
: return "PROGBITS";
4367 case SHT_SYMTAB
: return "SYMTAB";
4368 case SHT_STRTAB
: return "STRTAB";
4369 case SHT_RELA
: return "RELA";
4370 case SHT_HASH
: return "HASH";
4371 case SHT_DYNAMIC
: return "DYNAMIC";
4372 case SHT_NOTE
: return "NOTE";
4373 case SHT_NOBITS
: return "NOBITS";
4374 case SHT_REL
: return "REL";
4375 case SHT_SHLIB
: return "SHLIB";
4376 case SHT_DYNSYM
: return "DYNSYM";
4377 case SHT_INIT_ARRAY
: return "INIT_ARRAY";
4378 case SHT_FINI_ARRAY
: return "FINI_ARRAY";
4379 case SHT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
4380 case SHT_GNU_HASH
: return "GNU_HASH";
4381 case SHT_GROUP
: return "GROUP";
4382 case SHT_SYMTAB_SHNDX
: return "SYMTAB SECTION INDICES";
4383 case SHT_GNU_verdef
: return "VERDEF";
4384 case SHT_GNU_verneed
: return "VERNEED";
4385 case SHT_GNU_versym
: return "VERSYM";
4386 case 0x6ffffff0: return "VERSYM";
4387 case 0x6ffffffc: return "VERDEF";
4388 case 0x7ffffffd: return "AUXILIARY";
4389 case 0x7fffffff: return "FILTER";
4390 case SHT_GNU_LIBLIST
: return "GNU_LIBLIST";
4393 if ((sh_type
>= SHT_LOPROC
) && (sh_type
<= SHT_HIPROC
))
4395 switch (filedata
->file_header
.e_machine
)
4398 case EM_ARC_COMPACT
:
4399 case EM_ARC_COMPACT2
:
4400 result
= get_arc_section_type_name (sh_type
);
4403 case EM_MIPS_RS3_LE
:
4404 result
= get_mips_section_type_name (sh_type
);
4407 result
= get_parisc_section_type_name (sh_type
);
4410 result
= get_ia64_section_type_name (filedata
, sh_type
);
4415 result
= get_x86_64_section_type_name (sh_type
);
4418 result
= get_aarch64_section_type_name (sh_type
);
4421 result
= get_arm_section_type_name (sh_type
);
4424 result
= get_tic6x_section_type_name (sh_type
);
4427 result
= get_msp430_section_type_name (sh_type
);
4430 result
= get_nfp_section_type_name (sh_type
);
4434 case EM_CYGNUS_V850
:
4435 result
= get_v850_section_type_name (sh_type
);
4438 result
= get_riscv_section_type_name (sh_type
);
4441 result
= get_csky_section_type_name (sh_type
);
4451 sprintf (buff
, "LOPROC+%#x", sh_type
- SHT_LOPROC
);
4453 else if ((sh_type
>= SHT_LOOS
) && (sh_type
<= SHT_HIOS
))
4455 switch (filedata
->file_header
.e_machine
)
4458 result
= get_ia64_section_type_name (filedata
, sh_type
);
4461 if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_SOLARIS
)
4462 result
= get_solaris_section_type (sh_type
);
4467 case SHT_GNU_INCREMENTAL_INPUTS
: result
= "GNU_INCREMENTAL_INPUTS"; break;
4468 case SHT_GNU_ATTRIBUTES
: result
= "GNU_ATTRIBUTES"; break;
4469 case SHT_GNU_HASH
: result
= "GNU_HASH"; break;
4470 case SHT_GNU_LIBLIST
: result
= "GNU_LIBLIST"; break;
4482 sprintf (buff
, "LOOS+%#x", sh_type
- SHT_LOOS
);
4484 else if ((sh_type
>= SHT_LOUSER
) && (sh_type
<= SHT_HIUSER
))
4486 switch (filedata
->file_header
.e_machine
)
4490 case EM_CYGNUS_V850
:
4491 result
= get_v850_section_type_name (sh_type
);
4501 sprintf (buff
, "LOUSER+%#x", sh_type
- SHT_LOUSER
);
4504 /* This message is probably going to be displayed in a 15
4505 character wide field, so put the hex value first. */
4506 snprintf (buff
, sizeof (buff
), _("%08x: <unknown>"), sh_type
);
4512 enum long_option_values
4514 OPTION_DEBUG_DUMP
= 512,
4524 OPTION_WITH_SYMBOL_VERSIONS
,
4525 OPTION_RECURSE_LIMIT
,
4526 OPTION_NO_RECURSE_LIMIT
,
4527 OPTION_NO_DEMANGLING
4530 static struct option options
[] =
4532 /* Note - This table is alpha-sorted on the 'val'
4533 field in order to make adding new options easier. */
4534 {"arch-specific", no_argument
, 0, 'A'},
4535 {"all", no_argument
, 0, 'a'},
4536 {"demangle", optional_argument
, 0, 'C'},
4537 {"archive-index", no_argument
, 0, 'c'},
4538 {"use-dynamic", no_argument
, 0, 'D'},
4539 {"dynamic", no_argument
, 0, 'd'},
4540 {"headers", no_argument
, 0, 'e'},
4541 {"section-groups", no_argument
, 0, 'g'},
4542 {"help", no_argument
, 0, 'H'},
4543 {"file-header", no_argument
, 0, 'h'},
4544 {"histogram", no_argument
, 0, 'I'},
4545 {"lint", no_argument
, 0, 'L'},
4546 {"enable-checks", no_argument
, 0, 'L'},
4547 {"program-headers", no_argument
, 0, 'l'},
4548 {"segments", no_argument
, 0, 'l'},
4549 {"full-section-name",no_argument
, 0, 'N'},
4550 {"notes", no_argument
, 0, 'n'},
4551 {"process-links", no_argument
, 0, 'P'},
4552 {"string-dump", required_argument
, 0, 'p'},
4553 {"relocated-dump", required_argument
, 0, 'R'},
4554 {"relocs", no_argument
, 0, 'r'},
4555 {"section-headers", no_argument
, 0, 'S'},
4556 {"sections", no_argument
, 0, 'S'},
4557 {"symbols", no_argument
, 0, 's'},
4558 {"syms", no_argument
, 0, 's'},
4559 {"silent-truncation",no_argument
, 0, 'T'},
4560 {"section-details", no_argument
, 0, 't'},
4561 {"unwind", no_argument
, 0, 'u'},
4562 {"version-info", no_argument
, 0, 'V'},
4563 {"version", no_argument
, 0, 'v'},
4564 {"wide", no_argument
, 0, 'W'},
4565 {"hex-dump", required_argument
, 0, 'x'},
4566 {"decompress", no_argument
, 0, 'z'},
4568 {"no-demangle", no_argument
, 0, OPTION_NO_DEMANGLING
},
4569 {"recurse-limit", no_argument
, NULL
, OPTION_RECURSE_LIMIT
},
4570 {"no-recurse-limit", no_argument
, NULL
, OPTION_NO_RECURSE_LIMIT
},
4571 {"no-recursion-limit", no_argument
, NULL
, OPTION_NO_RECURSE_LIMIT
},
4572 {"dyn-syms", no_argument
, 0, OPTION_DYN_SYMS
},
4573 {"lto-syms", no_argument
, 0, OPTION_LTO_SYMS
},
4574 {"debug-dump", optional_argument
, 0, OPTION_DEBUG_DUMP
},
4575 {"dwarf-depth", required_argument
, 0, OPTION_DWARF_DEPTH
},
4576 {"dwarf-start", required_argument
, 0, OPTION_DWARF_START
},
4577 {"dwarf-check", no_argument
, 0, OPTION_DWARF_CHECK
},
4578 #ifdef ENABLE_LIBCTF
4579 {"ctf", required_argument
, 0, OPTION_CTF_DUMP
},
4580 {"ctf-symbols", required_argument
, 0, OPTION_CTF_SYMBOLS
},
4581 {"ctf-strings", required_argument
, 0, OPTION_CTF_STRINGS
},
4582 {"ctf-parent", required_argument
, 0, OPTION_CTF_PARENT
},
4585 {0, no_argument
, 0, 0}
4589 usage (FILE * stream
)
4591 fprintf (stream
, _("Usage: readelf <option(s)> elf-file(s)\n"));
4592 fprintf (stream
, _(" Display information about the contents of ELF format files\n"));
4593 fprintf (stream
, _(" Options are:\n\
4594 -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n\
4595 -h --file-header Display the ELF file header\n\
4596 -l --program-headers Display the program headers\n\
4597 --segments An alias for --program-headers\n\
4598 -S --section-headers Display the sections' header\n\
4599 --sections An alias for --section-headers\n\
4600 -g --section-groups Display the section groups\n\
4601 -t --section-details Display the section details\n\
4602 -e --headers Equivalent to: -h -l -S\n\
4603 -s --syms Display the symbol table\n\
4604 --symbols An alias for --syms\n\
4605 --dyn-syms Display the dynamic symbol table\n\
4606 --lto-syms Display LTO symbol tables\n\
4607 -C --demangle[=STYLE] Decode low-level symbol names into user-level names\n\
4608 The STYLE, if specified, can be `auto' (the default),\n\
4609 `gnu', `lucid', `arm', `hp', `edg', `gnu-v3', `java'\n\
4611 --no-demangle Do not demangle low-level symbol names. (This is the default)\n\
4612 --recurse-limit Enable a demangling recursion limit. (This is the default)\n\
4613 --no-recurse-limit Disable a demangling recursion limit\n\
4614 -n --notes Display the core notes (if present)\n\
4615 -r --relocs Display the relocations (if present)\n\
4616 -u --unwind Display the unwind info (if present)\n\
4617 -d --dynamic Display the dynamic section (if present)\n\
4618 -V --version-info Display the version sections (if present)\n\
4619 -A --arch-specific Display architecture specific information (if any)\n\
4620 -c --archive-index Display the symbol/file index in an archive\n\
4621 -D --use-dynamic Use the dynamic section info when displaying symbols\n\
4622 -L --lint|--enable-checks Display warning messages for possible problems\n\
4623 -x --hex-dump=<number|name>\n\
4624 Dump the contents of section <number|name> as bytes\n\
4625 -p --string-dump=<number|name>\n\
4626 Dump the contents of section <number|name> as strings\n\
4627 -R --relocated-dump=<number|name>\n\
4628 Dump the contents of section <number|name> as relocated bytes\n\
4629 -z --decompress Decompress section before dumping it\n\
4630 -w[lLiaprmfFsoORtUuTgAc] or\n\
4631 --debug-dump[=rawline,=decodedline,=info,=abbrev,=pubnames,=aranges,=macro,=frames,\n\
4632 =frames-interp,=str,=str-offsets,=loc,=Ranges,=pubtypes,\n\
4633 =gdb_index,=trace_info,=trace_abbrev,=trace_aranges,\n\
4635 Display the contents of DWARF debug sections\n\
4636 -wk,--debug-dump=links Display the contents of sections that link to separate debuginfo files\n\
4637 -P,--process-links Display the contents of non-debug sections in separate debuginfo files. (Implies -wK)\n"));
4638 #if DEFAULT_FOR_FOLLOW_LINKS
4639 fprintf (stream
, _("\
4640 -wK,--debug-dump=follow-links Follow links to separate debug info files (default)\n\
4641 -wN,--debug-dump=no-follow-links Do not follow links to separate debug info files\n\
4644 fprintf (stream
, _("\
4645 -wK,--debug-dump=follow-links Follow links to separate debug info files\n\
4646 -wN,--debug-dump=no-follow-links Do not follow links to separate debug info files (default)\n\
4649 fprintf (stream
, _("\
4650 --dwarf-depth=N Do not display DIEs at depth N or greater\n\
4651 --dwarf-start=N Display DIEs starting with N, at the same depth\n\
4653 #ifdef ENABLE_LIBCTF
4654 fprintf (stream
, _("\
4655 --ctf=<number|name> Display CTF info from section <number|name>\n\
4656 --ctf-parent=<number|name>\n\
4657 Use section <number|name> as the CTF parent\n\n\
4658 --ctf-symbols=<number|name>\n\
4659 Use section <number|name> as the CTF external symtab\n\n\
4660 --ctf-strings=<number|name>\n\
4661 Use section <number|name> as the CTF external strtab\n\n"));
4664 #ifdef SUPPORT_DISASSEMBLY
4665 fprintf (stream
, _("\
4666 -i --instruction-dump=<number|name>\n\
4667 Disassemble the contents of section <number|name>\n"));
4669 fprintf (stream
, _("\
4670 -I --histogram Display histogram of bucket list lengths\n\
4671 -W --wide Allow output width to exceed 80 characters\n\
4672 -T --silent-truncation If a symbol name is truncated, do not add a suffix [...]\n\
4673 @<file> Read options from <file>\n\
4674 -H --help Display this information\n\
4675 -v --version Display the version number of readelf\n"));
4677 if (REPORT_BUGS_TO
[0] && stream
== stdout
)
4678 fprintf (stdout
, _("Report bugs to %s\n"), REPORT_BUGS_TO
);
4680 exit (stream
== stdout
? 0 : 1);
4683 /* Record the fact that the user wants the contents of section number
4684 SECTION to be displayed using the method(s) encoded as flags bits
4685 in TYPE. Note, TYPE can be zero if we are creating the array for
4689 request_dump_bynumber (struct dump_data
*dumpdata
,
4690 unsigned int section
, dump_type type
)
4692 if (section
>= dumpdata
->num_dump_sects
)
4694 dump_type
* new_dump_sects
;
4696 new_dump_sects
= (dump_type
*) calloc (section
+ 1,
4697 sizeof (* new_dump_sects
));
4699 if (new_dump_sects
== NULL
)
4700 error (_("Out of memory allocating dump request table.\n"));
4703 if (dumpdata
->dump_sects
)
4705 /* Copy current flag settings. */
4706 memcpy (new_dump_sects
, dumpdata
->dump_sects
,
4707 dumpdata
->num_dump_sects
* sizeof (* new_dump_sects
));
4709 free (dumpdata
->dump_sects
);
4712 dumpdata
->dump_sects
= new_dump_sects
;
4713 dumpdata
->num_dump_sects
= section
+ 1;
4717 if (dumpdata
->dump_sects
)
4718 dumpdata
->dump_sects
[section
] |= type
;
4721 /* Request a dump by section name. */
4724 request_dump_byname (const char * section
, dump_type type
)
4726 struct dump_list_entry
* new_request
;
4728 new_request
= (struct dump_list_entry
*)
4729 malloc (sizeof (struct dump_list_entry
));
4731 error (_("Out of memory allocating dump request table.\n"));
4733 new_request
->name
= strdup (section
);
4734 if (!new_request
->name
)
4735 error (_("Out of memory allocating dump request table.\n"));
4737 new_request
->type
= type
;
4739 new_request
->next
= dump_sects_byname
;
4740 dump_sects_byname
= new_request
;
4744 request_dump (struct dump_data
*dumpdata
, dump_type type
)
4750 section
= strtoul (optarg
, & cp
, 0);
4752 if (! *cp
&& section
>= 0)
4753 request_dump_bynumber (dumpdata
, section
, type
);
4755 request_dump_byname (optarg
, type
);
4759 parse_args (struct dump_data
*dumpdata
, int argc
, char ** argv
)
4766 while ((c
= getopt_long
4767 (argc
, argv
, "ACDHILNPR:STVWacdeghi:lnp:rstuvw::x:z", options
, NULL
)) != EOF
)
4785 do_section_groups
= TRUE
;
4788 do_histogram
= TRUE
;
4794 do_section_groups
= TRUE
;
4799 do_section_details
= TRUE
;
4810 do_using_dynamic
= TRUE
;
4834 do_histogram
= TRUE
;
4840 do_archive_index
= TRUE
;
4846 process_links
= TRUE
;
4847 do_follow_links
= TRUE
;
4850 request_dump (dumpdata
, HEX_DUMP
);
4853 request_dump (dumpdata
, STRING_DUMP
);
4856 request_dump (dumpdata
, RELOC_DUMP
);
4859 decompress_dumps
= TRUE
;
4865 do_debugging
= TRUE
;
4866 dwarf_select_sections_all ();
4870 do_debugging
= FALSE
;
4871 dwarf_select_sections_by_letters (optarg
);
4874 case OPTION_DEBUG_DUMP
:
4877 do_debugging
= TRUE
;
4880 do_debugging
= FALSE
;
4881 dwarf_select_sections_by_names (optarg
);
4884 case OPTION_DWARF_DEPTH
:
4888 dwarf_cutoff_level
= strtoul (optarg
, & cp
, 0);
4891 case OPTION_DWARF_START
:
4895 dwarf_start_die
= strtoul (optarg
, & cp
, 0);
4898 case OPTION_DWARF_CHECK
:
4901 case OPTION_CTF_DUMP
:
4903 request_dump (dumpdata
, CTF_DUMP
);
4905 case OPTION_CTF_SYMBOLS
:
4906 free (dump_ctf_symtab_name
);
4907 dump_ctf_symtab_name
= strdup (optarg
);
4909 case OPTION_CTF_STRINGS
:
4910 free (dump_ctf_strtab_name
);
4911 dump_ctf_strtab_name
= strdup (optarg
);
4913 case OPTION_CTF_PARENT
:
4914 free (dump_ctf_parent_name
);
4915 dump_ctf_parent_name
= strdup (optarg
);
4917 case OPTION_DYN_SYMS
:
4920 case OPTION_LTO_SYMS
:
4923 #ifdef SUPPORT_DISASSEMBLY
4925 request_dump (dumpdata
, DISASS_DUMP
);
4929 print_version (program_name
);
4938 do_not_show_symbol_truncation
= TRUE
;
4944 enum demangling_styles style
;
4946 style
= cplus_demangle_name_to_style (optarg
);
4947 if (style
== unknown_demangling
)
4948 error (_("unknown demangling style `%s'"), optarg
);
4950 cplus_demangle_set_style (style
);
4953 case OPTION_NO_DEMANGLING
:
4954 do_demangle
= FALSE
;
4956 case OPTION_RECURSE_LIMIT
:
4957 demangle_flags
&= ~ DMGL_NO_RECURSE_LIMIT
;
4959 case OPTION_NO_RECURSE_LIMIT
:
4960 demangle_flags
|= DMGL_NO_RECURSE_LIMIT
;
4962 case OPTION_WITH_SYMBOL_VERSIONS
:
4963 /* Ignored for backward compatibility. */
4967 /* xgettext:c-format */
4968 error (_("Invalid option '-%c'\n"), c
);
4975 if (!do_dynamic
&& !do_syms
&& !do_reloc
&& !do_unwind
&& !do_sections
4976 && !do_segments
&& !do_header
&& !do_dump
&& !do_version
4977 && !do_histogram
&& !do_debugging
&& !do_arch
&& !do_notes
4978 && !do_section_groups
&& !do_archive_index
4979 && !do_dyn_syms
&& !do_lto_syms
)
4984 do_dynamic
= do_syms
= do_reloc
= do_unwind
= do_sections
= TRUE
;
4985 do_segments
= do_header
= do_dump
= do_version
= TRUE
;
4986 do_histogram
= do_debugging
= do_arch
= do_notes
= TRUE
;
4987 do_section_groups
= do_archive_index
= do_dyn_syms
= TRUE
;
4996 get_elf_class (unsigned int elf_class
)
4998 static char buff
[32];
5002 case ELFCLASSNONE
: return _("none");
5003 case ELFCLASS32
: return "ELF32";
5004 case ELFCLASS64
: return "ELF64";
5006 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), elf_class
);
5012 get_data_encoding (unsigned int encoding
)
5014 static char buff
[32];
5018 case ELFDATANONE
: return _("none");
5019 case ELFDATA2LSB
: return _("2's complement, little endian");
5020 case ELFDATA2MSB
: return _("2's complement, big endian");
5022 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), encoding
);
5027 /* Decode the data held in 'filedata->file_header'. */
5030 process_file_header (Filedata
* filedata
)
5032 Elf_Internal_Ehdr
* header
= & filedata
->file_header
;
5034 if ( header
->e_ident
[EI_MAG0
] != ELFMAG0
5035 || header
->e_ident
[EI_MAG1
] != ELFMAG1
5036 || header
->e_ident
[EI_MAG2
] != ELFMAG2
5037 || header
->e_ident
[EI_MAG3
] != ELFMAG3
)
5040 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
5044 if (! filedata
->is_separate
)
5045 init_dwarf_regnames_by_elf_machine_code (header
->e_machine
);
5051 if (filedata
->is_separate
)
5052 printf (_("ELF Header in linked file '%s':\n"), filedata
->file_name
);
5054 printf (_("ELF Header:\n"));
5055 printf (_(" Magic: "));
5056 for (i
= 0; i
< EI_NIDENT
; i
++)
5057 printf ("%2.2x ", header
->e_ident
[i
]);
5059 printf (_(" Class: %s\n"),
5060 get_elf_class (header
->e_ident
[EI_CLASS
]));
5061 printf (_(" Data: %s\n"),
5062 get_data_encoding (header
->e_ident
[EI_DATA
]));
5063 printf (_(" Version: %d%s\n"),
5064 header
->e_ident
[EI_VERSION
],
5065 (header
->e_ident
[EI_VERSION
] == EV_CURRENT
5067 : (header
->e_ident
[EI_VERSION
] != EV_NONE
5070 printf (_(" OS/ABI: %s\n"),
5071 get_osabi_name (filedata
, header
->e_ident
[EI_OSABI
]));
5072 printf (_(" ABI Version: %d\n"),
5073 header
->e_ident
[EI_ABIVERSION
]);
5074 printf (_(" Type: %s\n"),
5075 get_file_type (header
->e_type
));
5076 printf (_(" Machine: %s\n"),
5077 get_machine_name (header
->e_machine
));
5078 printf (_(" Version: 0x%lx\n"),
5081 printf (_(" Entry point address: "));
5082 print_vma (header
->e_entry
, PREFIX_HEX
);
5083 printf (_("\n Start of program headers: "));
5084 print_vma (header
->e_phoff
, DEC
);
5085 printf (_(" (bytes into file)\n Start of section headers: "));
5086 print_vma (header
->e_shoff
, DEC
);
5087 printf (_(" (bytes into file)\n"));
5089 printf (_(" Flags: 0x%lx%s\n"),
5091 get_machine_flags (filedata
, header
->e_flags
, header
->e_machine
));
5092 printf (_(" Size of this header: %u (bytes)\n"),
5094 printf (_(" Size of program headers: %u (bytes)\n"),
5095 header
->e_phentsize
);
5096 printf (_(" Number of program headers: %u"),
5098 if (filedata
->section_headers
!= NULL
5099 && header
->e_phnum
== PN_XNUM
5100 && filedata
->section_headers
[0].sh_info
!= 0)
5102 header
->e_phnum
= filedata
->section_headers
[0].sh_info
;
5103 printf (" (%u)", header
->e_phnum
);
5105 putc ('\n', stdout
);
5106 printf (_(" Size of section headers: %u (bytes)\n"),
5107 header
->e_shentsize
);
5108 printf (_(" Number of section headers: %u"),
5110 if (filedata
->section_headers
!= NULL
&& header
->e_shnum
== SHN_UNDEF
)
5112 header
->e_shnum
= filedata
->section_headers
[0].sh_size
;
5113 printf (" (%u)", header
->e_shnum
);
5115 putc ('\n', stdout
);
5116 printf (_(" Section header string table index: %u"),
5117 header
->e_shstrndx
);
5118 if (filedata
->section_headers
!= NULL
5119 && header
->e_shstrndx
== (SHN_XINDEX
& 0xffff))
5121 header
->e_shstrndx
= filedata
->section_headers
[0].sh_link
;
5122 printf (" (%u)", header
->e_shstrndx
);
5124 if (header
->e_shstrndx
!= SHN_UNDEF
5125 && header
->e_shstrndx
>= header
->e_shnum
)
5127 header
->e_shstrndx
= SHN_UNDEF
;
5128 printf (_(" <corrupt: out of range>"));
5130 putc ('\n', stdout
);
5133 if (filedata
->section_headers
!= NULL
)
5135 if (header
->e_phnum
== PN_XNUM
5136 && filedata
->section_headers
[0].sh_info
!= 0)
5137 header
->e_phnum
= filedata
->section_headers
[0].sh_info
;
5138 if (header
->e_shnum
== SHN_UNDEF
)
5139 header
->e_shnum
= filedata
->section_headers
[0].sh_size
;
5140 if (header
->e_shstrndx
== (SHN_XINDEX
& 0xffff))
5141 header
->e_shstrndx
= filedata
->section_headers
[0].sh_link
;
5142 if (header
->e_shstrndx
>= header
->e_shnum
)
5143 header
->e_shstrndx
= SHN_UNDEF
;
5144 free (filedata
->section_headers
);
5145 filedata
->section_headers
= NULL
;
5151 /* Read in the program headers from FILEDATA and store them in PHEADERS.
5152 Returns TRUE upon success, FALSE otherwise. Loads 32-bit headers. */
5155 get_32bit_program_headers (Filedata
* filedata
, Elf_Internal_Phdr
* pheaders
)
5157 Elf32_External_Phdr
* phdrs
;
5158 Elf32_External_Phdr
* external
;
5159 Elf_Internal_Phdr
* internal
;
5161 unsigned int size
= filedata
->file_header
.e_phentsize
;
5162 unsigned int num
= filedata
->file_header
.e_phnum
;
5164 /* PR binutils/17531: Cope with unexpected section header sizes. */
5165 if (size
== 0 || num
== 0)
5167 if (size
< sizeof * phdrs
)
5169 error (_("The e_phentsize field in the ELF header is less than the size of an ELF program header\n"));
5172 if (size
> sizeof * phdrs
)
5173 warn (_("The e_phentsize field in the ELF header is larger than the size of an ELF program header\n"));
5175 phdrs
= (Elf32_External_Phdr
*) get_data (NULL
, filedata
, filedata
->file_header
.e_phoff
,
5176 size
, num
, _("program headers"));
5180 for (i
= 0, internal
= pheaders
, external
= phdrs
;
5181 i
< filedata
->file_header
.e_phnum
;
5182 i
++, internal
++, external
++)
5184 internal
->p_type
= BYTE_GET (external
->p_type
);
5185 internal
->p_offset
= BYTE_GET (external
->p_offset
);
5186 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
5187 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
5188 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
5189 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
5190 internal
->p_flags
= BYTE_GET (external
->p_flags
);
5191 internal
->p_align
= BYTE_GET (external
->p_align
);
5198 /* Read in the program headers from FILEDATA and store them in PHEADERS.
5199 Returns TRUE upon success, FALSE otherwise. Loads 64-bit headers. */
5202 get_64bit_program_headers (Filedata
* filedata
, Elf_Internal_Phdr
* pheaders
)
5204 Elf64_External_Phdr
* phdrs
;
5205 Elf64_External_Phdr
* external
;
5206 Elf_Internal_Phdr
* internal
;
5208 unsigned int size
= filedata
->file_header
.e_phentsize
;
5209 unsigned int num
= filedata
->file_header
.e_phnum
;
5211 /* PR binutils/17531: Cope with unexpected section header sizes. */
5212 if (size
== 0 || num
== 0)
5214 if (size
< sizeof * phdrs
)
5216 error (_("The e_phentsize field in the ELF header is less than the size of an ELF program header\n"));
5219 if (size
> sizeof * phdrs
)
5220 warn (_("The e_phentsize field in the ELF header is larger than the size of an ELF program header\n"));
5222 phdrs
= (Elf64_External_Phdr
*) get_data (NULL
, filedata
, filedata
->file_header
.e_phoff
,
5223 size
, num
, _("program headers"));
5227 for (i
= 0, internal
= pheaders
, external
= phdrs
;
5228 i
< filedata
->file_header
.e_phnum
;
5229 i
++, internal
++, external
++)
5231 internal
->p_type
= BYTE_GET (external
->p_type
);
5232 internal
->p_flags
= BYTE_GET (external
->p_flags
);
5233 internal
->p_offset
= BYTE_GET (external
->p_offset
);
5234 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
5235 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
5236 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
5237 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
5238 internal
->p_align
= BYTE_GET (external
->p_align
);
5245 /* Returns TRUE if the program headers were read into `program_headers'. */
5248 get_program_headers (Filedata
* filedata
)
5250 Elf_Internal_Phdr
* phdrs
;
5252 /* Check cache of prior read. */
5253 if (filedata
->program_headers
!= NULL
)
5256 /* Be kind to memory checkers by looking for
5257 e_phnum values which we know must be invalid. */
5258 if (filedata
->file_header
.e_phnum
5259 * (is_32bit_elf
? sizeof (Elf32_External_Phdr
) : sizeof (Elf64_External_Phdr
))
5260 >= filedata
->file_size
)
5262 error (_("Too many program headers - %#x - the file is not that big\n"),
5263 filedata
->file_header
.e_phnum
);
5267 phdrs
= (Elf_Internal_Phdr
*) cmalloc (filedata
->file_header
.e_phnum
,
5268 sizeof (Elf_Internal_Phdr
));
5271 error (_("Out of memory reading %u program headers\n"),
5272 filedata
->file_header
.e_phnum
);
5277 ? get_32bit_program_headers (filedata
, phdrs
)
5278 : get_64bit_program_headers (filedata
, phdrs
))
5280 filedata
->program_headers
= phdrs
;
5288 /* Returns TRUE if the program headers were loaded. */
5291 process_program_headers (Filedata
* filedata
)
5293 Elf_Internal_Phdr
* segment
;
5295 Elf_Internal_Phdr
* previous_load
= NULL
;
5297 filedata
->dynamic_addr
= 0;
5298 filedata
->dynamic_size
= 0;
5300 if (filedata
->file_header
.e_phnum
== 0)
5302 /* PR binutils/12467. */
5303 if (filedata
->file_header
.e_phoff
!= 0)
5305 warn (_("possibly corrupt ELF header - it has a non-zero program"
5306 " header offset, but no program headers\n"));
5309 else if (do_segments
)
5311 if (filedata
->is_separate
)
5312 printf (_("\nThere are no program headers in linked file '%s'.\n"),
5313 filedata
->file_name
);
5315 printf (_("\nThere are no program headers in this file.\n"));
5320 if (do_segments
&& !do_header
)
5322 if (filedata
->is_separate
)
5323 printf ("\nIn linked file '%s' the ELF file type is %s\n",
5324 filedata
->file_name
,
5325 get_file_type (filedata
->file_header
.e_type
));
5327 printf (_("\nElf file type is %s\n"), get_file_type (filedata
->file_header
.e_type
));
5328 printf (_("Entry point 0x%s\n"), bfd_vmatoa ("x", filedata
->file_header
.e_entry
));
5329 printf (ngettext ("There is %d program header, starting at offset %s\n",
5330 "There are %d program headers, starting at offset %s\n",
5331 filedata
->file_header
.e_phnum
),
5332 filedata
->file_header
.e_phnum
,
5333 bfd_vmatoa ("u", filedata
->file_header
.e_phoff
));
5336 if (! get_program_headers (filedata
))
5341 if (filedata
->file_header
.e_phnum
> 1)
5342 printf (_("\nProgram Headers:\n"));
5344 printf (_("\nProgram Headers:\n"));
5348 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
5351 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
5355 (_(" Type Offset VirtAddr PhysAddr\n"));
5357 (_(" FileSiz MemSiz Flags Align\n"));
5361 for (i
= 0, segment
= filedata
->program_headers
;
5362 i
< filedata
->file_header
.e_phnum
;
5367 printf (" %-14.14s ", get_segment_type (filedata
, segment
->p_type
));
5371 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
5372 printf ("0x%8.8lx ", (unsigned long) segment
->p_vaddr
);
5373 printf ("0x%8.8lx ", (unsigned long) segment
->p_paddr
);
5374 printf ("0x%5.5lx ", (unsigned long) segment
->p_filesz
);
5375 printf ("0x%5.5lx ", (unsigned long) segment
->p_memsz
);
5377 (segment
->p_flags
& PF_R
? 'R' : ' '),
5378 (segment
->p_flags
& PF_W
? 'W' : ' '),
5379 (segment
->p_flags
& PF_X
? 'E' : ' '));
5380 printf ("%#lx", (unsigned long) segment
->p_align
);
5384 if ((unsigned long) segment
->p_offset
== segment
->p_offset
)
5385 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
5388 print_vma (segment
->p_offset
, FULL_HEX
);
5392 print_vma (segment
->p_vaddr
, FULL_HEX
);
5394 print_vma (segment
->p_paddr
, FULL_HEX
);
5397 if ((unsigned long) segment
->p_filesz
== segment
->p_filesz
)
5398 printf ("0x%6.6lx ", (unsigned long) segment
->p_filesz
);
5401 print_vma (segment
->p_filesz
, FULL_HEX
);
5405 if ((unsigned long) segment
->p_memsz
== segment
->p_memsz
)
5406 printf ("0x%6.6lx", (unsigned long) segment
->p_memsz
);
5409 print_vma (segment
->p_memsz
, FULL_HEX
);
5413 (segment
->p_flags
& PF_R
? 'R' : ' '),
5414 (segment
->p_flags
& PF_W
? 'W' : ' '),
5415 (segment
->p_flags
& PF_X
? 'E' : ' '));
5417 if ((unsigned long) segment
->p_align
== segment
->p_align
)
5418 printf ("%#lx", (unsigned long) segment
->p_align
);
5421 print_vma (segment
->p_align
, PREFIX_HEX
);
5426 print_vma (segment
->p_offset
, FULL_HEX
);
5428 print_vma (segment
->p_vaddr
, FULL_HEX
);
5430 print_vma (segment
->p_paddr
, FULL_HEX
);
5432 print_vma (segment
->p_filesz
, FULL_HEX
);
5434 print_vma (segment
->p_memsz
, FULL_HEX
);
5436 (segment
->p_flags
& PF_R
? 'R' : ' '),
5437 (segment
->p_flags
& PF_W
? 'W' : ' '),
5438 (segment
->p_flags
& PF_X
? 'E' : ' '));
5439 print_vma (segment
->p_align
, PREFIX_HEX
);
5442 putc ('\n', stdout
);
5445 switch (segment
->p_type
)
5448 #if 0 /* Do not warn about out of order PT_LOAD segments. Although officially
5449 required by the ELF standard, several programs, including the Linux
5450 kernel, make use of non-ordered segments. */
5452 && previous_load
->p_vaddr
> segment
->p_vaddr
)
5453 error (_("LOAD segments must be sorted in order of increasing VirtAddr\n"));
5455 if (segment
->p_memsz
< segment
->p_filesz
)
5456 error (_("the segment's file size is larger than its memory size\n"));
5457 previous_load
= segment
;
5461 /* PR 20815 - Verify that the program header is loaded into memory. */
5462 if (i
> 0 && previous_load
!= NULL
)
5463 error (_("the PHDR segment must occur before any LOAD segment\n"));
5464 if (filedata
->file_header
.e_machine
!= EM_PARISC
)
5468 for (j
= 1; j
< filedata
->file_header
.e_phnum
; j
++)
5470 Elf_Internal_Phdr
*load
= filedata
->program_headers
+ j
;
5471 if (load
->p_type
== PT_LOAD
5472 && load
->p_offset
<= segment
->p_offset
5473 && (load
->p_offset
+ load
->p_filesz
5474 >= segment
->p_offset
+ segment
->p_filesz
)
5475 && load
->p_vaddr
<= segment
->p_vaddr
5476 && (load
->p_vaddr
+ load
->p_filesz
5477 >= segment
->p_vaddr
+ segment
->p_filesz
))
5480 if (j
== filedata
->file_header
.e_phnum
)
5481 error (_("the PHDR segment is not covered by a LOAD segment\n"));
5486 if (filedata
->dynamic_addr
)
5487 error (_("more than one dynamic segment\n"));
5489 /* By default, assume that the .dynamic section is the first
5490 section in the DYNAMIC segment. */
5491 filedata
->dynamic_addr
= segment
->p_offset
;
5492 filedata
->dynamic_size
= segment
->p_filesz
;
5494 /* Try to locate the .dynamic section. If there is
5495 a section header table, we can easily locate it. */
5496 if (filedata
->section_headers
!= NULL
)
5498 Elf_Internal_Shdr
* sec
;
5500 sec
= find_section (filedata
, ".dynamic");
5501 if (sec
== NULL
|| sec
->sh_size
== 0)
5503 /* A corresponding .dynamic section is expected, but on
5504 IA-64/OpenVMS it is OK for it to be missing. */
5505 if (!is_ia64_vms (filedata
))
5506 error (_("no .dynamic section in the dynamic segment\n"));
5510 if (sec
->sh_type
== SHT_NOBITS
)
5512 filedata
->dynamic_size
= 0;
5516 filedata
->dynamic_addr
= sec
->sh_offset
;
5517 filedata
->dynamic_size
= sec
->sh_size
;
5519 /* The PT_DYNAMIC segment, which is used by the run-time
5520 loader, should exactly match the .dynamic section. */
5522 && (filedata
->dynamic_addr
!= segment
->p_offset
5523 || filedata
->dynamic_size
!= segment
->p_filesz
))
5525 the .dynamic section is not the same as the dynamic segment\n"));
5528 /* PR binutils/17512: Avoid corrupt dynamic section info in the
5529 segment. Check this after matching against the section headers
5530 so we don't warn on debuginfo file (which have NOBITS .dynamic
5532 if (filedata
->dynamic_addr
> filedata
->file_size
5533 || (filedata
->dynamic_size
5534 > filedata
->file_size
- filedata
->dynamic_addr
))
5536 error (_("the dynamic segment offset + size exceeds the size of the file\n"));
5537 filedata
->dynamic_addr
= filedata
->dynamic_size
= 0;
5542 if (fseek (filedata
->handle
,
5543 filedata
->archive_file_offset
+ (long) segment
->p_offset
,
5545 error (_("Unable to find program interpreter name\n"));
5549 int ret
= snprintf (fmt
, sizeof (fmt
), "%%%ds", PATH_MAX
- 1);
5551 if (ret
>= (int) sizeof (fmt
) || ret
< 0)
5552 error (_("Internal error: failed to create format string to display program interpreter\n"));
5554 filedata
->program_interpreter
[0] = 0;
5555 if (fscanf (filedata
->handle
, fmt
,
5556 filedata
->program_interpreter
) <= 0)
5557 error (_("Unable to read program interpreter name\n"));
5560 printf (_(" [Requesting program interpreter: %s]\n"),
5561 filedata
->program_interpreter
);
5568 && filedata
->section_headers
!= NULL
5569 && filedata
->string_table
!= NULL
)
5571 printf (_("\n Section to Segment mapping:\n"));
5572 printf (_(" Segment Sections...\n"));
5574 for (i
= 0; i
< filedata
->file_header
.e_phnum
; i
++)
5577 Elf_Internal_Shdr
* section
;
5579 segment
= filedata
->program_headers
+ i
;
5580 section
= filedata
->section_headers
+ 1;
5582 printf (" %2.2d ", i
);
5584 for (j
= 1; j
< filedata
->file_header
.e_shnum
; j
++, section
++)
5586 if (!ELF_TBSS_SPECIAL (section
, segment
)
5587 && ELF_SECTION_IN_SEGMENT_STRICT (section
, segment
))
5588 printf ("%s ", printable_section_name (filedata
, section
));
5599 /* Find the file offset corresponding to VMA by using the program headers. */
5602 offset_from_vma (Filedata
* filedata
, bfd_vma vma
, bfd_size_type size
)
5604 Elf_Internal_Phdr
* seg
;
5606 if (! get_program_headers (filedata
))
5608 warn (_("Cannot interpret virtual addresses without program headers.\n"));
5612 for (seg
= filedata
->program_headers
;
5613 seg
< filedata
->program_headers
+ filedata
->file_header
.e_phnum
;
5616 if (seg
->p_type
!= PT_LOAD
)
5619 if (vma
>= (seg
->p_vaddr
& -seg
->p_align
)
5620 && vma
+ size
<= seg
->p_vaddr
+ seg
->p_filesz
)
5621 return vma
- seg
->p_vaddr
+ seg
->p_offset
;
5624 warn (_("Virtual address 0x%lx not located in any PT_LOAD segment.\n"),
5625 (unsigned long) vma
);
5630 /* Allocate memory and load the sections headers into FILEDATA->filedata->section_headers.
5631 If PROBE is true, this is just a probe and we do not generate any error
5632 messages if the load fails. */
5635 get_32bit_section_headers (Filedata
* filedata
, bfd_boolean probe
)
5637 Elf32_External_Shdr
* shdrs
;
5638 Elf_Internal_Shdr
* internal
;
5640 unsigned int size
= filedata
->file_header
.e_shentsize
;
5641 unsigned int num
= probe
? 1 : filedata
->file_header
.e_shnum
;
5643 /* PR binutils/17531: Cope with unexpected section header sizes. */
5644 if (size
== 0 || num
== 0)
5646 if (size
< sizeof * shdrs
)
5649 error (_("The e_shentsize field in the ELF header is less than the size of an ELF section header\n"));
5652 if (!probe
&& size
> sizeof * shdrs
)
5653 warn (_("The e_shentsize field in the ELF header is larger than the size of an ELF section header\n"));
5655 shdrs
= (Elf32_External_Shdr
*) get_data (NULL
, filedata
, filedata
->file_header
.e_shoff
,
5657 probe
? NULL
: _("section headers"));
5661 free (filedata
->section_headers
);
5662 filedata
->section_headers
= (Elf_Internal_Shdr
*)
5663 cmalloc (num
, sizeof (Elf_Internal_Shdr
));
5664 if (filedata
->section_headers
== NULL
)
5667 error (_("Out of memory reading %u section headers\n"), num
);
5672 for (i
= 0, internal
= filedata
->section_headers
;
5676 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
5677 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
5678 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
5679 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
5680 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
5681 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
5682 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
5683 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
5684 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
5685 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
5686 if (!probe
&& internal
->sh_link
> num
)
5687 warn (_("Section %u has an out of range sh_link value of %u\n"), i
, internal
->sh_link
);
5688 if (!probe
&& internal
->sh_flags
& SHF_INFO_LINK
&& internal
->sh_info
> num
)
5689 warn (_("Section %u has an out of range sh_info value of %u\n"), i
, internal
->sh_info
);
5696 /* Like get_32bit_section_headers, except that it fetches 64-bit headers. */
5699 get_64bit_section_headers (Filedata
* filedata
, bfd_boolean probe
)
5701 Elf64_External_Shdr
* shdrs
;
5702 Elf_Internal_Shdr
* internal
;
5704 unsigned int size
= filedata
->file_header
.e_shentsize
;
5705 unsigned int num
= probe
? 1 : filedata
->file_header
.e_shnum
;
5707 /* PR binutils/17531: Cope with unexpected section header sizes. */
5708 if (size
== 0 || num
== 0)
5711 if (size
< sizeof * shdrs
)
5714 error (_("The e_shentsize field in the ELF header is less than the size of an ELF section header\n"));
5718 if (! probe
&& size
> sizeof * shdrs
)
5719 warn (_("The e_shentsize field in the ELF header is larger than the size of an ELF section header\n"));
5721 shdrs
= (Elf64_External_Shdr
*) get_data (NULL
, filedata
,
5722 filedata
->file_header
.e_shoff
,
5724 probe
? NULL
: _("section headers"));
5728 free (filedata
->section_headers
);
5729 filedata
->section_headers
= (Elf_Internal_Shdr
*)
5730 cmalloc (num
, sizeof (Elf_Internal_Shdr
));
5731 if (filedata
->section_headers
== NULL
)
5734 error (_("Out of memory reading %u section headers\n"), num
);
5739 for (i
= 0, internal
= filedata
->section_headers
;
5743 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
5744 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
5745 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
5746 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
5747 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
5748 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
5749 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
5750 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
5751 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
5752 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
5753 if (!probe
&& internal
->sh_link
> num
)
5754 warn (_("Section %u has an out of range sh_link value of %u\n"), i
, internal
->sh_link
);
5755 if (!probe
&& internal
->sh_flags
& SHF_INFO_LINK
&& internal
->sh_info
> num
)
5756 warn (_("Section %u has an out of range sh_info value of %u\n"), i
, internal
->sh_info
);
5763 static Elf_Internal_Sym
*
5764 get_32bit_elf_symbols (Filedata
* filedata
,
5765 Elf_Internal_Shdr
* section
,
5766 unsigned long * num_syms_return
)
5768 unsigned long number
= 0;
5769 Elf32_External_Sym
* esyms
= NULL
;
5770 Elf_External_Sym_Shndx
* shndx
= NULL
;
5771 Elf_Internal_Sym
* isyms
= NULL
;
5772 Elf_Internal_Sym
* psym
;
5774 elf_section_list
* entry
;
5776 if (section
->sh_size
== 0)
5778 if (num_syms_return
!= NULL
)
5779 * num_syms_return
= 0;
5783 /* Run some sanity checks first. */
5784 if (section
->sh_entsize
== 0 || section
->sh_entsize
> section
->sh_size
)
5786 error (_("Section %s has an invalid sh_entsize of 0x%lx\n"),
5787 printable_section_name (filedata
, section
),
5788 (unsigned long) section
->sh_entsize
);
5792 if (section
->sh_size
> filedata
->file_size
)
5794 error (_("Section %s has an invalid sh_size of 0x%lx\n"),
5795 printable_section_name (filedata
, section
),
5796 (unsigned long) section
->sh_size
);
5800 number
= section
->sh_size
/ section
->sh_entsize
;
5802 if (number
* sizeof (Elf32_External_Sym
) > section
->sh_size
+ 1)
5804 error (_("Size (0x%lx) of section %s is not a multiple of its sh_entsize (0x%lx)\n"),
5805 (unsigned long) section
->sh_size
,
5806 printable_section_name (filedata
, section
),
5807 (unsigned long) section
->sh_entsize
);
5811 esyms
= (Elf32_External_Sym
*) get_data (NULL
, filedata
, section
->sh_offset
, 1,
5812 section
->sh_size
, _("symbols"));
5817 for (entry
= filedata
->symtab_shndx_list
; entry
!= NULL
; entry
= entry
->next
)
5819 if (entry
->hdr
->sh_link
!= (unsigned long) (section
- filedata
->section_headers
))
5824 error (_("Multiple symbol table index sections associated with the same symbol section\n"));
5828 shndx
= (Elf_External_Sym_Shndx
*) get_data (NULL
, filedata
,
5829 entry
->hdr
->sh_offset
,
5830 1, entry
->hdr
->sh_size
,
5831 _("symbol table section indices"));
5835 /* PR17531: file: heap-buffer-overflow */
5836 if (entry
->hdr
->sh_size
/ sizeof (Elf_External_Sym_Shndx
) < number
)
5838 error (_("Index section %s has an sh_size of 0x%lx - expected 0x%lx\n"),
5839 printable_section_name (filedata
, entry
->hdr
),
5840 (unsigned long) entry
->hdr
->sh_size
,
5841 (unsigned long) section
->sh_size
);
5846 isyms
= (Elf_Internal_Sym
*) cmalloc (number
, sizeof (Elf_Internal_Sym
));
5850 error (_("Out of memory reading %lu symbols\n"),
5851 (unsigned long) number
);
5855 for (j
= 0, psym
= isyms
; j
< number
; j
++, psym
++)
5857 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
5858 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
5859 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
5860 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
5861 if (psym
->st_shndx
== (SHN_XINDEX
& 0xffff) && shndx
!= NULL
)
5863 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
5864 else if (psym
->st_shndx
>= (SHN_LORESERVE
& 0xffff))
5865 psym
->st_shndx
+= SHN_LORESERVE
- (SHN_LORESERVE
& 0xffff);
5866 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
5867 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
5874 if (num_syms_return
!= NULL
)
5875 * num_syms_return
= isyms
== NULL
? 0 : number
;
5880 static Elf_Internal_Sym
*
5881 get_64bit_elf_symbols (Filedata
* filedata
,
5882 Elf_Internal_Shdr
* section
,
5883 unsigned long * num_syms_return
)
5885 unsigned long number
= 0;
5886 Elf64_External_Sym
* esyms
= NULL
;
5887 Elf_External_Sym_Shndx
* shndx
= NULL
;
5888 Elf_Internal_Sym
* isyms
= NULL
;
5889 Elf_Internal_Sym
* psym
;
5891 elf_section_list
* entry
;
5893 if (section
->sh_size
== 0)
5895 if (num_syms_return
!= NULL
)
5896 * num_syms_return
= 0;
5900 /* Run some sanity checks first. */
5901 if (section
->sh_entsize
== 0 || section
->sh_entsize
> section
->sh_size
)
5903 error (_("Section %s has an invalid sh_entsize of 0x%lx\n"),
5904 printable_section_name (filedata
, section
),
5905 (unsigned long) section
->sh_entsize
);
5909 if (section
->sh_size
> filedata
->file_size
)
5911 error (_("Section %s has an invalid sh_size of 0x%lx\n"),
5912 printable_section_name (filedata
, section
),
5913 (unsigned long) section
->sh_size
);
5917 number
= section
->sh_size
/ section
->sh_entsize
;
5919 if (number
* sizeof (Elf64_External_Sym
) > section
->sh_size
+ 1)
5921 error (_("Size (0x%lx) of section %s is not a multiple of its sh_entsize (0x%lx)\n"),
5922 (unsigned long) section
->sh_size
,
5923 printable_section_name (filedata
, section
),
5924 (unsigned long) section
->sh_entsize
);
5928 esyms
= (Elf64_External_Sym
*) get_data (NULL
, filedata
, section
->sh_offset
, 1,
5929 section
->sh_size
, _("symbols"));
5934 for (entry
= filedata
->symtab_shndx_list
; entry
!= NULL
; entry
= entry
->next
)
5936 if (entry
->hdr
->sh_link
!= (unsigned long) (section
- filedata
->section_headers
))
5941 error (_("Multiple symbol table index sections associated with the same symbol section\n"));
5945 shndx
= (Elf_External_Sym_Shndx
*) get_data (NULL
, filedata
,
5946 entry
->hdr
->sh_offset
,
5947 1, entry
->hdr
->sh_size
,
5948 _("symbol table section indices"));
5952 /* PR17531: file: heap-buffer-overflow */
5953 if (entry
->hdr
->sh_size
/ sizeof (Elf_External_Sym_Shndx
) < number
)
5955 error (_("Index section %s has an sh_size of 0x%lx - expected 0x%lx\n"),
5956 printable_section_name (filedata
, entry
->hdr
),
5957 (unsigned long) entry
->hdr
->sh_size
,
5958 (unsigned long) section
->sh_size
);
5963 isyms
= (Elf_Internal_Sym
*) cmalloc (number
, sizeof (Elf_Internal_Sym
));
5967 error (_("Out of memory reading %lu symbols\n"),
5968 (unsigned long) number
);
5972 for (j
= 0, psym
= isyms
; j
< number
; j
++, psym
++)
5974 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
5975 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
5976 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
5977 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
5979 if (psym
->st_shndx
== (SHN_XINDEX
& 0xffff) && shndx
!= NULL
)
5981 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
5982 else if (psym
->st_shndx
>= (SHN_LORESERVE
& 0xffff))
5983 psym
->st_shndx
+= SHN_LORESERVE
- (SHN_LORESERVE
& 0xffff);
5985 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
5986 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
5993 if (num_syms_return
!= NULL
)
5994 * num_syms_return
= isyms
== NULL
? 0 : number
;
6000 get_elf_section_flags (Filedata
* filedata
, bfd_vma sh_flags
)
6002 static char buff
[1024];
6004 unsigned int field_size
= is_32bit_elf
? 8 : 16;
6006 unsigned int size
= sizeof (buff
) - (field_size
+ 4 + 1);
6007 bfd_vma os_flags
= 0;
6008 bfd_vma proc_flags
= 0;
6009 bfd_vma unknown_flags
= 0;
6017 /* 0 */ { STRING_COMMA_LEN ("WRITE") },
6018 /* 1 */ { STRING_COMMA_LEN ("ALLOC") },
6019 /* 2 */ { STRING_COMMA_LEN ("EXEC") },
6020 /* 3 */ { STRING_COMMA_LEN ("MERGE") },
6021 /* 4 */ { STRING_COMMA_LEN ("STRINGS") },
6022 /* 5 */ { STRING_COMMA_LEN ("INFO LINK") },
6023 /* 6 */ { STRING_COMMA_LEN ("LINK ORDER") },
6024 /* 7 */ { STRING_COMMA_LEN ("OS NONCONF") },
6025 /* 8 */ { STRING_COMMA_LEN ("GROUP") },
6026 /* 9 */ { STRING_COMMA_LEN ("TLS") },
6027 /* IA-64 specific. */
6028 /* 10 */ { STRING_COMMA_LEN ("SHORT") },
6029 /* 11 */ { STRING_COMMA_LEN ("NORECOV") },
6030 /* IA-64 OpenVMS specific. */
6031 /* 12 */ { STRING_COMMA_LEN ("VMS_GLOBAL") },
6032 /* 13 */ { STRING_COMMA_LEN ("VMS_OVERLAID") },
6033 /* 14 */ { STRING_COMMA_LEN ("VMS_SHARED") },
6034 /* 15 */ { STRING_COMMA_LEN ("VMS_VECTOR") },
6035 /* 16 */ { STRING_COMMA_LEN ("VMS_ALLOC_64BIT") },
6036 /* 17 */ { STRING_COMMA_LEN ("VMS_PROTECTED") },
6038 /* 18 */ { STRING_COMMA_LEN ("EXCLUDE") },
6039 /* SPARC specific. */
6040 /* 19 */ { STRING_COMMA_LEN ("ORDERED") },
6041 /* 20 */ { STRING_COMMA_LEN ("COMPRESSED") },
6043 /* 21 */ { STRING_COMMA_LEN ("ENTRYSECT") },
6044 /* 22 */ { STRING_COMMA_LEN ("ARM_PURECODE") },
6045 /* 23 */ { STRING_COMMA_LEN ("COMDEF") },
6047 /* 24 */ { STRING_COMMA_LEN ("GNU_MBIND") },
6049 /* 25 */ { STRING_COMMA_LEN ("VLE") },
6051 /* 26 */ { STRING_COMMA_LEN ("GNU_RETAIN") },
6054 if (do_section_details
)
6056 sprintf (buff
, "[%*.*lx]: ",
6057 field_size
, field_size
, (unsigned long) sh_flags
);
6058 p
+= field_size
+ 4;
6065 flag
= sh_flags
& - sh_flags
;
6068 if (do_section_details
)
6072 case SHF_WRITE
: sindex
= 0; break;
6073 case SHF_ALLOC
: sindex
= 1; break;
6074 case SHF_EXECINSTR
: sindex
= 2; break;
6075 case SHF_MERGE
: sindex
= 3; break;
6076 case SHF_STRINGS
: sindex
= 4; break;
6077 case SHF_INFO_LINK
: sindex
= 5; break;
6078 case SHF_LINK_ORDER
: sindex
= 6; break;
6079 case SHF_OS_NONCONFORMING
: sindex
= 7; break;
6080 case SHF_GROUP
: sindex
= 8; break;
6081 case SHF_TLS
: sindex
= 9; break;
6082 case SHF_EXCLUDE
: sindex
= 18; break;
6083 case SHF_COMPRESSED
: sindex
= 20; break;
6087 switch (filedata
->file_header
.e_machine
)
6090 if (flag
== SHF_IA_64_SHORT
)
6092 else if (flag
== SHF_IA_64_NORECOV
)
6095 else if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_OPENVMS
)
6098 case SHF_IA_64_VMS_GLOBAL
: sindex
= 12; break;
6099 case SHF_IA_64_VMS_OVERLAID
: sindex
= 13; break;
6100 case SHF_IA_64_VMS_SHARED
: sindex
= 14; break;
6101 case SHF_IA_64_VMS_VECTOR
: sindex
= 15; break;
6102 case SHF_IA_64_VMS_ALLOC_64BIT
: sindex
= 16; break;
6103 case SHF_IA_64_VMS_PROTECTED
: sindex
= 17; break;
6114 case EM_OLD_SPARCV9
:
6115 case EM_SPARC32PLUS
:
6118 if (flag
== SHF_ORDERED
)
6125 case SHF_ENTRYSECT
: sindex
= 21; break;
6126 case SHF_ARM_PURECODE
: sindex
= 22; break;
6127 case SHF_COMDEF
: sindex
= 23; break;
6132 if (flag
== SHF_PPC_VLE
)
6139 switch (filedata
->file_header
.e_ident
[EI_OSABI
])
6142 case ELFOSABI_FREEBSD
:
6143 if (flag
== SHF_GNU_RETAIN
)
6147 if (flag
== SHF_GNU_MBIND
)
6148 /* We should not recognize SHF_GNU_MBIND for
6149 ELFOSABI_NONE, but binutils as of 2019-07-23 did
6150 not set the EI_OSABI header byte. */
6161 if (p
!= buff
+ field_size
+ 4)
6163 if (size
< (10 + 2))
6165 warn (_("Internal error: not enough buffer room for section flag info"));
6166 return _("<unknown>");
6173 size
-= flags
[sindex
].len
;
6174 p
= stpcpy (p
, flags
[sindex
].str
);
6176 else if (flag
& SHF_MASKOS
)
6178 else if (flag
& SHF_MASKPROC
)
6181 unknown_flags
|= flag
;
6187 case SHF_WRITE
: *p
= 'W'; break;
6188 case SHF_ALLOC
: *p
= 'A'; break;
6189 case SHF_EXECINSTR
: *p
= 'X'; break;
6190 case SHF_MERGE
: *p
= 'M'; break;
6191 case SHF_STRINGS
: *p
= 'S'; break;
6192 case SHF_INFO_LINK
: *p
= 'I'; break;
6193 case SHF_LINK_ORDER
: *p
= 'L'; break;
6194 case SHF_OS_NONCONFORMING
: *p
= 'O'; break;
6195 case SHF_GROUP
: *p
= 'G'; break;
6196 case SHF_TLS
: *p
= 'T'; break;
6197 case SHF_EXCLUDE
: *p
= 'E'; break;
6198 case SHF_COMPRESSED
: *p
= 'C'; break;
6201 if ((filedata
->file_header
.e_machine
== EM_X86_64
6202 || filedata
->file_header
.e_machine
== EM_L1OM
6203 || filedata
->file_header
.e_machine
== EM_K1OM
)
6204 && flag
== SHF_X86_64_LARGE
)
6206 else if (filedata
->file_header
.e_machine
== EM_ARM
6207 && flag
== SHF_ARM_PURECODE
)
6209 else if (filedata
->file_header
.e_machine
== EM_PPC
6210 && flag
== SHF_PPC_VLE
)
6212 else if (flag
& SHF_MASKOS
)
6214 switch (filedata
->file_header
.e_ident
[EI_OSABI
])
6217 case ELFOSABI_FREEBSD
:
6218 if (flag
== SHF_GNU_RETAIN
)
6225 if (flag
== SHF_GNU_MBIND
)
6227 /* We should not recognize SHF_GNU_MBIND for
6228 ELFOSABI_NONE, but binutils as of 2019-07-23 did
6229 not set the EI_OSABI header byte. */
6236 sh_flags
&= ~SHF_MASKOS
;
6240 else if (flag
& SHF_MASKPROC
)
6243 sh_flags
&= ~ SHF_MASKPROC
;
6253 if (do_section_details
)
6257 size
-= 5 + field_size
;
6258 if (p
!= buff
+ field_size
+ 4)
6262 warn (_("Internal error: not enough buffer room for section flag info"));
6263 return _("<unknown>");
6269 sprintf (p
, "OS (%*.*lx)", field_size
, field_size
,
6270 (unsigned long) os_flags
);
6271 p
+= 5 + field_size
;
6275 size
-= 7 + field_size
;
6276 if (p
!= buff
+ field_size
+ 4)
6280 warn (_("Internal error: not enough buffer room for section flag info"));
6281 return _("<unknown>");
6287 sprintf (p
, "PROC (%*.*lx)", field_size
, field_size
,
6288 (unsigned long) proc_flags
);
6289 p
+= 7 + field_size
;
6293 size
-= 10 + field_size
;
6294 if (p
!= buff
+ field_size
+ 4)
6298 warn (_("Internal error: not enough buffer room for section flag info"));
6299 return _("<unknown>");
6305 sprintf (p
, _("UNKNOWN (%*.*lx)"), field_size
, field_size
,
6306 (unsigned long) unknown_flags
);
6307 p
+= 10 + field_size
;
6315 static unsigned int ATTRIBUTE_WARN_UNUSED_RESULT
6316 get_compression_header (Elf_Internal_Chdr
*chdr
, unsigned char *buf
, bfd_size_type size
)
6320 Elf32_External_Chdr
*echdr
= (Elf32_External_Chdr
*) buf
;
6322 if (size
< sizeof (* echdr
))
6324 error (_("Compressed section is too small even for a compression header\n"));
6328 chdr
->ch_type
= BYTE_GET (echdr
->ch_type
);
6329 chdr
->ch_size
= BYTE_GET (echdr
->ch_size
);
6330 chdr
->ch_addralign
= BYTE_GET (echdr
->ch_addralign
);
6331 return sizeof (*echdr
);
6335 Elf64_External_Chdr
*echdr
= (Elf64_External_Chdr
*) buf
;
6337 if (size
< sizeof (* echdr
))
6339 error (_("Compressed section is too small even for a compression header\n"));
6343 chdr
->ch_type
= BYTE_GET (echdr
->ch_type
);
6344 chdr
->ch_size
= BYTE_GET (echdr
->ch_size
);
6345 chdr
->ch_addralign
= BYTE_GET (echdr
->ch_addralign
);
6346 return sizeof (*echdr
);
6351 process_section_headers (Filedata
* filedata
)
6353 Elf_Internal_Shdr
* section
;
6356 free (filedata
->section_headers
);
6357 filedata
->section_headers
= NULL
;
6358 free (filedata
->dynamic_symbols
);
6359 filedata
->dynamic_symbols
= NULL
;
6360 filedata
->num_dynamic_syms
= 0;
6361 free (filedata
->dynamic_strings
);
6362 filedata
->dynamic_strings
= NULL
;
6363 filedata
->dynamic_strings_length
= 0;
6364 free (filedata
->dynamic_syminfo
);
6365 filedata
->dynamic_syminfo
= NULL
;
6366 while (filedata
->symtab_shndx_list
!= NULL
)
6368 elf_section_list
*next
= filedata
->symtab_shndx_list
->next
;
6369 free (filedata
->symtab_shndx_list
);
6370 filedata
->symtab_shndx_list
= next
;
6373 if (filedata
->file_header
.e_shnum
== 0)
6375 /* PR binutils/12467. */
6376 if (filedata
->file_header
.e_shoff
!= 0)
6378 warn (_("possibly corrupt ELF file header - it has a non-zero"
6379 " section header offset, but no section headers\n"));
6382 else if (do_sections
)
6383 printf (_("\nThere are no sections in this file.\n"));
6388 if (do_sections
&& !do_header
)
6390 if (filedata
->is_separate
&& process_links
)
6391 printf (_("In linked file '%s': "), filedata
->file_name
);
6392 if (! filedata
->is_separate
|| process_links
)
6393 printf (ngettext ("There is %d section header, "
6394 "starting at offset 0x%lx:\n",
6395 "There are %d section headers, "
6396 "starting at offset 0x%lx:\n",
6397 filedata
->file_header
.e_shnum
),
6398 filedata
->file_header
.e_shnum
,
6399 (unsigned long) filedata
->file_header
.e_shoff
);
6404 if (! get_32bit_section_headers (filedata
, FALSE
))
6409 if (! get_64bit_section_headers (filedata
, FALSE
))
6413 /* Read in the string table, so that we have names to display. */
6414 if (filedata
->file_header
.e_shstrndx
!= SHN_UNDEF
6415 && filedata
->file_header
.e_shstrndx
< filedata
->file_header
.e_shnum
)
6417 section
= filedata
->section_headers
+ filedata
->file_header
.e_shstrndx
;
6419 if (section
->sh_size
!= 0)
6421 filedata
->string_table
= (char *) get_data (NULL
, filedata
, section
->sh_offset
,
6422 1, section
->sh_size
,
6425 filedata
->string_table_length
= filedata
->string_table
!= NULL
? section
->sh_size
: 0;
6429 /* Scan the sections for the dynamic symbol table
6430 and dynamic string table and debug sections. */
6431 eh_addr_size
= is_32bit_elf
? 4 : 8;
6432 switch (filedata
->file_header
.e_machine
)
6435 case EM_MIPS_RS3_LE
:
6436 /* The 64-bit MIPS EABI uses a combination of 32-bit ELF and 64-bit
6437 FDE addresses. However, the ABI also has a semi-official ILP32
6438 variant for which the normal FDE address size rules apply.
6440 GCC 4.0 marks EABI64 objects with a dummy .gcc_compiled_longXX
6441 section, where XX is the size of longs in bits. Unfortunately,
6442 earlier compilers provided no way of distinguishing ILP32 objects
6443 from LP64 objects, so if there's any doubt, we should assume that
6444 the official LP64 form is being used. */
6445 if ((filedata
->file_header
.e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
6446 && find_section (filedata
, ".gcc_compiled_long32") == NULL
)
6452 switch (filedata
->file_header
.e_flags
& EF_H8_MACH
)
6454 case E_H8_MACH_H8300
:
6455 case E_H8_MACH_H8300HN
:
6456 case E_H8_MACH_H8300SN
:
6457 case E_H8_MACH_H8300SXN
:
6460 case E_H8_MACH_H8300H
:
6461 case E_H8_MACH_H8300S
:
6462 case E_H8_MACH_H8300SX
:
6470 switch (filedata
->file_header
.e_flags
& EF_M32C_CPU_MASK
)
6472 case EF_M32C_CPU_M16C
:
6479 #define CHECK_ENTSIZE_VALUES(section, i, size32, size64) \
6482 bfd_size_type expected_entsize = is_32bit_elf ? size32 : size64; \
6483 if (section->sh_entsize != expected_entsize) \
6486 sprintf_vma (buf, section->sh_entsize); \
6487 /* Note: coded this way so that there is a single string for \
6489 error (_("Section %d has invalid sh_entsize of %s\n"), i, buf); \
6490 error (_("(Using the expected size of %u for the rest of this dump)\n"), \
6491 (unsigned) expected_entsize); \
6492 section->sh_entsize = expected_entsize; \
6497 #define CHECK_ENTSIZE(section, i, type) \
6498 CHECK_ENTSIZE_VALUES (section, i, sizeof (Elf32_External_##type), \
6499 sizeof (Elf64_External_##type))
6501 for (i
= 0, section
= filedata
->section_headers
;
6502 i
< filedata
->file_header
.e_shnum
;
6505 char * name
= SECTION_NAME_PRINT (section
);
6507 /* Run some sanity checks on the headers and
6508 possibly fill in some file data as well. */
6509 switch (section
->sh_type
)
6512 if (filedata
->dynamic_symbols
!= NULL
)
6514 error (_("File contains multiple dynamic symbol tables\n"));
6518 CHECK_ENTSIZE (section
, i
, Sym
);
6519 filedata
->dynamic_symbols
6520 = GET_ELF_SYMBOLS (filedata
, section
, &filedata
->num_dynamic_syms
);
6521 filedata
->dynamic_symtab_section
= section
;
6525 if (streq (name
, ".dynstr"))
6527 if (filedata
->dynamic_strings
!= NULL
)
6529 error (_("File contains multiple dynamic string tables\n"));
6533 filedata
->dynamic_strings
6534 = (char *) get_data (NULL
, filedata
, section
->sh_offset
,
6535 1, section
->sh_size
, _("dynamic strings"));
6536 filedata
->dynamic_strings_length
6537 = filedata
->dynamic_strings
== NULL
? 0 : section
->sh_size
;
6538 filedata
->dynamic_strtab_section
= section
;
6542 case SHT_SYMTAB_SHNDX
:
6544 elf_section_list
* entry
= xmalloc (sizeof * entry
);
6546 entry
->hdr
= section
;
6547 entry
->next
= filedata
->symtab_shndx_list
;
6548 filedata
->symtab_shndx_list
= entry
;
6553 CHECK_ENTSIZE (section
, i
, Sym
);
6557 CHECK_ENTSIZE_VALUES (section
, i
, GRP_ENTRY_SIZE
, GRP_ENTRY_SIZE
);
6561 CHECK_ENTSIZE (section
, i
, Rel
);
6562 if (do_checks
&& section
->sh_size
== 0)
6563 warn (_("Section '%s': zero-sized relocation section\n"), name
);
6567 CHECK_ENTSIZE (section
, i
, Rela
);
6568 if (do_checks
&& section
->sh_size
== 0)
6569 warn (_("Section '%s': zero-sized relocation section\n"), name
);
6574 /* Having a zero sized section is not illegal according to the
6575 ELF standard, but it might be an indication that something
6576 is wrong. So issue a warning if we are running in lint mode. */
6577 if (do_checks
&& section
->sh_size
== 0)
6578 warn (_("Section '%s': has a size of zero - is this intended ?\n"), name
);
6585 if ((do_debugging
|| do_debug_info
|| do_debug_abbrevs
6586 || do_debug_lines
|| do_debug_pubnames
|| do_debug_pubtypes
6587 || do_debug_aranges
|| do_debug_frames
|| do_debug_macinfo
6588 || do_debug_str
|| do_debug_str_offsets
|| do_debug_loc
6590 || do_debug_addr
|| do_debug_cu_index
|| do_debug_links
)
6591 && (const_strneq (name
, ".debug_")
6592 || const_strneq (name
, ".zdebug_")))
6595 name
+= sizeof (".zdebug_") - 1;
6597 name
+= sizeof (".debug_") - 1;
6600 || (do_debug_info
&& const_strneq (name
, "info"))
6601 || (do_debug_info
&& const_strneq (name
, "types"))
6602 || (do_debug_abbrevs
&& const_strneq (name
, "abbrev"))
6603 || (do_debug_lines
&& strcmp (name
, "line") == 0)
6604 || (do_debug_lines
&& const_strneq (name
, "line."))
6605 || (do_debug_pubnames
&& const_strneq (name
, "pubnames"))
6606 || (do_debug_pubtypes
&& const_strneq (name
, "pubtypes"))
6607 || (do_debug_pubnames
&& const_strneq (name
, "gnu_pubnames"))
6608 || (do_debug_pubtypes
&& const_strneq (name
, "gnu_pubtypes"))
6609 || (do_debug_aranges
&& const_strneq (name
, "aranges"))
6610 || (do_debug_ranges
&& const_strneq (name
, "ranges"))
6611 || (do_debug_ranges
&& const_strneq (name
, "rnglists"))
6612 || (do_debug_frames
&& const_strneq (name
, "frame"))
6613 || (do_debug_macinfo
&& const_strneq (name
, "macinfo"))
6614 || (do_debug_macinfo
&& const_strneq (name
, "macro"))
6615 || (do_debug_str
&& const_strneq (name
, "str"))
6616 || (do_debug_links
&& const_strneq (name
, "sup"))
6617 || (do_debug_str_offsets
&& const_strneq (name
, "str_offsets"))
6618 || (do_debug_loc
&& const_strneq (name
, "loc"))
6619 || (do_debug_loc
&& const_strneq (name
, "loclists"))
6620 || (do_debug_addr
&& const_strneq (name
, "addr"))
6621 || (do_debug_cu_index
&& const_strneq (name
, "cu_index"))
6622 || (do_debug_cu_index
&& const_strneq (name
, "tu_index"))
6624 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
6626 /* Linkonce section to be combined with .debug_info at link time. */
6627 else if ((do_debugging
|| do_debug_info
)
6628 && const_strneq (name
, ".gnu.linkonce.wi."))
6629 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
6630 else if (do_debug_frames
&& streq (name
, ".eh_frame"))
6631 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
6632 else if (do_gdb_index
&& (streq (name
, ".gdb_index")
6633 || streq (name
, ".debug_names")))
6634 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
6635 /* Trace sections for Itanium VMS. */
6636 else if ((do_debugging
|| do_trace_info
|| do_trace_abbrevs
6637 || do_trace_aranges
)
6638 && const_strneq (name
, ".trace_"))
6640 name
+= sizeof (".trace_") - 1;
6643 || (do_trace_info
&& streq (name
, "info"))
6644 || (do_trace_abbrevs
&& streq (name
, "abbrev"))
6645 || (do_trace_aranges
&& streq (name
, "aranges"))
6647 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
6649 else if ((do_debugging
|| do_debug_links
)
6650 && (const_strneq (name
, ".gnu_debuglink")
6651 || const_strneq (name
, ".gnu_debugaltlink")))
6652 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
6658 if (filedata
->is_separate
&& ! process_links
)
6661 if (filedata
->is_separate
)
6662 printf (_("\nSection Headers in linked file '%s':\n"), filedata
->file_name
);
6663 else if (filedata
->file_header
.e_shnum
> 1)
6664 printf (_("\nSection Headers:\n"));
6666 printf (_("\nSection Header:\n"));
6670 if (do_section_details
)
6672 printf (_(" [Nr] Name\n"));
6673 printf (_(" Type Addr Off Size ES Lk Inf Al\n"));
6677 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
6681 if (do_section_details
)
6683 printf (_(" [Nr] Name\n"));
6684 printf (_(" Type Address Off Size ES Lk Inf Al\n"));
6688 (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n"));
6692 if (do_section_details
)
6694 printf (_(" [Nr] Name\n"));
6695 printf (_(" Type Address Offset Link\n"));
6696 printf (_(" Size EntSize Info Align\n"));
6700 printf (_(" [Nr] Name Type Address Offset\n"));
6701 printf (_(" Size EntSize Flags Link Info Align\n"));
6705 if (do_section_details
)
6706 printf (_(" Flags\n"));
6708 for (i
= 0, section
= filedata
->section_headers
;
6709 i
< filedata
->file_header
.e_shnum
;
6712 /* Run some sanity checks on the section header. */
6714 /* Check the sh_link field. */
6715 switch (section
->sh_type
)
6719 if (section
->sh_link
== 0
6720 && (filedata
->file_header
.e_type
== ET_EXEC
6721 || filedata
->file_header
.e_type
== ET_DYN
))
6722 /* A dynamic relocation section where all entries use a
6723 zero symbol index need not specify a symtab section. */
6726 case SHT_SYMTAB_SHNDX
:
6730 case SHT_GNU_versym
:
6731 if (section
->sh_link
== 0
6732 || section
->sh_link
>= filedata
->file_header
.e_shnum
6733 || (filedata
->section_headers
[section
->sh_link
].sh_type
!= SHT_SYMTAB
6734 && filedata
->section_headers
[section
->sh_link
].sh_type
!= SHT_DYNSYM
))
6735 warn (_("[%2u]: Link field (%u) should index a symtab section.\n"),
6736 i
, section
->sh_link
);
6742 case SHT_GNU_verneed
:
6743 case SHT_GNU_verdef
:
6744 case SHT_GNU_LIBLIST
:
6745 if (section
->sh_link
== 0
6746 || section
->sh_link
>= filedata
->file_header
.e_shnum
6747 || filedata
->section_headers
[section
->sh_link
].sh_type
!= SHT_STRTAB
)
6748 warn (_("[%2u]: Link field (%u) should index a string section.\n"),
6749 i
, section
->sh_link
);
6752 case SHT_INIT_ARRAY
:
6753 case SHT_FINI_ARRAY
:
6754 case SHT_PREINIT_ARRAY
:
6755 if (section
->sh_type
< SHT_LOOS
&& section
->sh_link
!= 0)
6756 warn (_("[%2u]: Unexpected value (%u) in link field.\n"),
6757 i
, section
->sh_link
);
6761 /* FIXME: Add support for target specific section types. */
6762 #if 0 /* Currently we do not check other section types as there are too
6763 many special cases. Stab sections for example have a type
6764 of SHT_PROGBITS but an sh_link field that links to the .stabstr
6766 if (section
->sh_type
< SHT_LOOS
&& section
->sh_link
!= 0)
6767 warn (_("[%2u]: Unexpected value (%u) in link field.\n"),
6768 i
, section
->sh_link
);
6773 /* Check the sh_info field. */
6774 switch (section
->sh_type
)
6778 if (section
->sh_info
== 0
6779 && (filedata
->file_header
.e_type
== ET_EXEC
6780 || filedata
->file_header
.e_type
== ET_DYN
))
6781 /* Dynamic relocations apply to segments, so they do not
6782 need to specify the section they relocate. */
6784 if (section
->sh_info
== 0
6785 || section
->sh_info
>= filedata
->file_header
.e_shnum
6786 || (filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_PROGBITS
6787 && filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_NOBITS
6788 && filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_NOTE
6789 && filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_INIT_ARRAY
6790 && filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_FINI_ARRAY
6791 && filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_PREINIT_ARRAY
6792 /* FIXME: Are other section types valid ? */
6793 && filedata
->section_headers
[section
->sh_info
].sh_type
< SHT_LOOS
))
6794 warn (_("[%2u]: Info field (%u) should index a relocatable section.\n"),
6795 i
, section
->sh_info
);
6800 case SHT_SYMTAB_SHNDX
:
6801 case SHT_INIT_ARRAY
:
6802 case SHT_FINI_ARRAY
:
6803 case SHT_PREINIT_ARRAY
:
6804 if (section
->sh_info
!= 0)
6805 warn (_("[%2u]: Unexpected value (%u) in info field.\n"),
6806 i
, section
->sh_info
);
6812 /* A symbol index - we assume that it is valid. */
6816 /* FIXME: Add support for target specific section types. */
6817 if (section
->sh_type
== SHT_NOBITS
)
6818 /* NOBITS section headers with non-zero sh_info fields can be
6819 created when a binary is stripped of everything but its debug
6820 information. The stripped sections have their headers
6821 preserved but their types set to SHT_NOBITS. So do not check
6822 this type of section. */
6824 else if (section
->sh_flags
& SHF_INFO_LINK
)
6826 if (section
->sh_info
< 1 || section
->sh_info
>= filedata
->file_header
.e_shnum
)
6827 warn (_("[%2u]: Expected link to another section in info field"), i
);
6829 else if (section
->sh_type
< SHT_LOOS
6830 && (section
->sh_flags
& SHF_GNU_MBIND
) == 0
6831 && section
->sh_info
!= 0)
6832 warn (_("[%2u]: Unexpected value (%u) in info field.\n"),
6833 i
, section
->sh_info
);
6837 /* Check the sh_size field. */
6838 if (section
->sh_size
> filedata
->file_size
6839 && section
->sh_type
!= SHT_NOBITS
6840 && section
->sh_type
!= SHT_NULL
6841 && section
->sh_type
< SHT_LOOS
)
6842 warn (_("Size of section %u is larger than the entire file!\n"), i
);
6844 printf (" [%2u] ", i
);
6845 if (do_section_details
)
6846 printf ("%s\n ", printable_section_name (filedata
, section
));
6848 print_symbol (-17, SECTION_NAME_PRINT (section
));
6850 printf (do_wide
? " %-15s " : " %-15.15s ",
6851 get_section_type_name (filedata
, section
->sh_type
));
6855 const char * link_too_big
= NULL
;
6857 print_vma (section
->sh_addr
, LONG_HEX
);
6859 printf ( " %6.6lx %6.6lx %2.2lx",
6860 (unsigned long) section
->sh_offset
,
6861 (unsigned long) section
->sh_size
,
6862 (unsigned long) section
->sh_entsize
);
6864 if (do_section_details
)
6865 fputs (" ", stdout
);
6867 printf (" %3s ", get_elf_section_flags (filedata
, section
->sh_flags
));
6869 if (section
->sh_link
>= filedata
->file_header
.e_shnum
)
6872 /* The sh_link value is out of range. Normally this indicates
6873 an error but it can have special values in Solaris binaries. */
6874 switch (filedata
->file_header
.e_machine
)
6881 case EM_OLD_SPARCV9
:
6882 case EM_SPARC32PLUS
:
6885 if (section
->sh_link
== (SHN_BEFORE
& 0xffff))
6886 link_too_big
= "BEFORE";
6887 else if (section
->sh_link
== (SHN_AFTER
& 0xffff))
6888 link_too_big
= "AFTER";
6895 if (do_section_details
)
6897 if (link_too_big
!= NULL
&& * link_too_big
)
6898 printf ("<%s> ", link_too_big
);
6900 printf ("%2u ", section
->sh_link
);
6901 printf ("%3u %2lu\n", section
->sh_info
,
6902 (unsigned long) section
->sh_addralign
);
6905 printf ("%2u %3u %2lu\n",
6908 (unsigned long) section
->sh_addralign
);
6910 if (link_too_big
&& ! * link_too_big
)
6911 warn (_("section %u: sh_link value of %u is larger than the number of sections\n"),
6912 i
, section
->sh_link
);
6916 print_vma (section
->sh_addr
, LONG_HEX
);
6918 if ((long) section
->sh_offset
== section
->sh_offset
)
6919 printf (" %6.6lx", (unsigned long) section
->sh_offset
);
6923 print_vma (section
->sh_offset
, LONG_HEX
);
6926 if ((unsigned long) section
->sh_size
== section
->sh_size
)
6927 printf (" %6.6lx", (unsigned long) section
->sh_size
);
6931 print_vma (section
->sh_size
, LONG_HEX
);
6934 if ((unsigned long) section
->sh_entsize
== section
->sh_entsize
)
6935 printf (" %2.2lx", (unsigned long) section
->sh_entsize
);
6939 print_vma (section
->sh_entsize
, LONG_HEX
);
6942 if (do_section_details
)
6943 fputs (" ", stdout
);
6945 printf (" %3s ", get_elf_section_flags (filedata
, section
->sh_flags
));
6947 printf ("%2u %3u ", section
->sh_link
, section
->sh_info
);
6949 if ((unsigned long) section
->sh_addralign
== section
->sh_addralign
)
6950 printf ("%2lu\n", (unsigned long) section
->sh_addralign
);
6953 print_vma (section
->sh_addralign
, DEC
);
6957 else if (do_section_details
)
6960 print_vma (section
->sh_addr
, LONG_HEX
);
6961 if ((long) section
->sh_offset
== section
->sh_offset
)
6962 printf (" %16.16lx", (unsigned long) section
->sh_offset
);
6966 print_vma (section
->sh_offset
, LONG_HEX
);
6968 printf (" %u\n ", section
->sh_link
);
6969 print_vma (section
->sh_size
, LONG_HEX
);
6971 print_vma (section
->sh_entsize
, LONG_HEX
);
6973 printf (" %-16u %lu\n",
6975 (unsigned long) section
->sh_addralign
);
6980 print_vma (section
->sh_addr
, LONG_HEX
);
6981 if ((long) section
->sh_offset
== section
->sh_offset
)
6982 printf (" %8.8lx", (unsigned long) section
->sh_offset
);
6986 print_vma (section
->sh_offset
, LONG_HEX
);
6989 print_vma (section
->sh_size
, LONG_HEX
);
6991 print_vma (section
->sh_entsize
, LONG_HEX
);
6993 printf (" %3s ", get_elf_section_flags (filedata
, section
->sh_flags
));
6995 printf (" %2u %3u %lu\n",
6998 (unsigned long) section
->sh_addralign
);
7001 if (do_section_details
)
7003 printf (" %s\n", get_elf_section_flags (filedata
, section
->sh_flags
));
7004 if ((section
->sh_flags
& SHF_COMPRESSED
) != 0)
7006 /* Minimum section size is 12 bytes for 32-bit compression
7007 header + 12 bytes for compressed data header. */
7008 unsigned char buf
[24];
7010 assert (sizeof (buf
) >= sizeof (Elf64_External_Chdr
));
7011 if (get_data (&buf
, filedata
, section
->sh_offset
, 1,
7012 sizeof (buf
), _("compression header")))
7014 Elf_Internal_Chdr chdr
;
7016 if (get_compression_header (&chdr
, buf
, sizeof (buf
)) == 0)
7017 printf (_(" [<corrupt>]\n"));
7020 if (chdr
.ch_type
== ELFCOMPRESS_ZLIB
)
7023 printf (_(" [<unknown>: 0x%x], "),
7025 print_vma (chdr
.ch_size
, LONG_HEX
);
7026 printf (", %lu\n", (unsigned long) chdr
.ch_addralign
);
7033 if (!do_section_details
)
7035 /* The ordering of the letters shown here matches the ordering of the
7036 corresponding SHF_xxx values, and hence the order in which these
7037 letters will be displayed to the user. */
7038 printf (_("Key to Flags:\n\
7039 W (write), A (alloc), X (execute), M (merge), S (strings), I (info),\n\
7040 L (link order), O (extra OS processing required), G (group), T (TLS),\n\
7041 C (compressed), x (unknown), o (OS specific), E (exclude),\n "));
7042 switch (filedata
->file_header
.e_ident
[EI_OSABI
])
7045 case ELFOSABI_FREEBSD
:
7046 printf (_("R (retain), "));
7049 printf (_("D (mbind), "));
7054 if (filedata
->file_header
.e_machine
== EM_X86_64
7055 || filedata
->file_header
.e_machine
== EM_L1OM
7056 || filedata
->file_header
.e_machine
== EM_K1OM
)
7057 printf (_("l (large), "));
7058 else if (filedata
->file_header
.e_machine
== EM_ARM
)
7059 printf (_("y (purecode), "));
7060 else if (filedata
->file_header
.e_machine
== EM_PPC
)
7061 printf (_("v (VLE), "));
7062 printf ("p (processor specific)\n");
7069 get_symtab (Filedata
*filedata
, Elf_Internal_Shdr
*symsec
,
7070 Elf_Internal_Sym
**symtab
, unsigned long *nsyms
,
7071 char **strtab
, unsigned long *strtablen
)
7075 *symtab
= GET_ELF_SYMBOLS (filedata
, symsec
, nsyms
);
7077 if (*symtab
== NULL
)
7080 if (symsec
->sh_link
!= 0)
7082 Elf_Internal_Shdr
*strsec
;
7084 if (symsec
->sh_link
>= filedata
->file_header
.e_shnum
)
7086 error (_("Bad sh_link in symbol table section\n"));
7093 strsec
= filedata
->section_headers
+ symsec
->sh_link
;
7095 *strtab
= (char *) get_data (NULL
, filedata
, strsec
->sh_offset
,
7096 1, strsec
->sh_size
, _("string table"));
7097 if (*strtab
== NULL
)
7104 *strtablen
= strsec
->sh_size
;
7110 get_group_flags (unsigned int flags
)
7112 static char buff
[128];
7116 else if (flags
== GRP_COMDAT
)
7119 snprintf (buff
, sizeof buff
, "[0x%x: %s%s%s]",
7121 flags
& GRP_MASKOS
? _("<OS specific>") : "",
7122 flags
& GRP_MASKPROC
? _("<PROC specific>") : "",
7123 (flags
& ~(GRP_COMDAT
| GRP_MASKOS
| GRP_MASKPROC
)
7124 ? _("<unknown>") : ""));
7130 process_section_groups (Filedata
* filedata
)
7132 Elf_Internal_Shdr
* section
;
7134 struct group
* group
;
7135 Elf_Internal_Shdr
* symtab_sec
;
7136 Elf_Internal_Shdr
* strtab_sec
;
7137 Elf_Internal_Sym
* symtab
;
7138 unsigned long num_syms
;
7142 /* Don't process section groups unless needed. */
7143 if (!do_unwind
&& !do_section_groups
)
7146 if (filedata
->file_header
.e_shnum
== 0)
7148 if (do_section_groups
)
7150 if (filedata
->is_separate
)
7151 printf (_("\nThere are no sections group in linked file '%s'.\n"),
7152 filedata
->file_name
);
7154 printf (_("\nThere are no section groups in this file.\n"));
7159 if (filedata
->section_headers
== NULL
)
7161 error (_("Section headers are not available!\n"));
7162 /* PR 13622: This can happen with a corrupt ELF header. */
7166 filedata
->section_headers_groups
7167 = (struct group
**) calloc (filedata
->file_header
.e_shnum
,
7168 sizeof (struct group
*));
7170 if (filedata
->section_headers_groups
== NULL
)
7172 error (_("Out of memory reading %u section group headers\n"),
7173 filedata
->file_header
.e_shnum
);
7177 /* Scan the sections for the group section. */
7178 filedata
->group_count
= 0;
7179 for (i
= 0, section
= filedata
->section_headers
;
7180 i
< filedata
->file_header
.e_shnum
;
7182 if (section
->sh_type
== SHT_GROUP
)
7183 filedata
->group_count
++;
7185 if (filedata
->group_count
== 0)
7187 if (do_section_groups
)
7189 if (filedata
->is_separate
)
7190 printf (_("\nThere are no section groups in linked file '%s'.\n"),
7191 filedata
->file_name
);
7193 printf (_("\nThere are no section groups in this file.\n"));
7199 filedata
->section_groups
= (struct group
*) calloc (filedata
->group_count
,
7200 sizeof (struct group
));
7202 if (filedata
->section_groups
== NULL
)
7204 error (_("Out of memory reading %lu groups\n"),
7205 (unsigned long) filedata
->group_count
);
7216 if (filedata
->is_separate
)
7217 printf (_("Section groups in linked file '%s'\n"), filedata
->file_name
);
7219 for (i
= 0, section
= filedata
->section_headers
, group
= filedata
->section_groups
;
7220 i
< filedata
->file_header
.e_shnum
;
7223 if (section
->sh_type
== SHT_GROUP
)
7225 const char * name
= printable_section_name (filedata
, section
);
7226 const char * group_name
;
7227 unsigned char * start
;
7228 unsigned char * indices
;
7229 unsigned int entry
, j
, size
;
7230 Elf_Internal_Shdr
* sec
;
7231 Elf_Internal_Sym
* sym
;
7233 /* Get the symbol table. */
7234 if (section
->sh_link
>= filedata
->file_header
.e_shnum
7235 || ((sec
= filedata
->section_headers
+ section
->sh_link
)->sh_type
7238 error (_("Bad sh_link in group section `%s'\n"), name
);
7242 if (symtab_sec
!= sec
)
7246 symtab
= GET_ELF_SYMBOLS (filedata
, symtab_sec
, & num_syms
);
7251 error (_("Corrupt header in group section `%s'\n"), name
);
7255 if (section
->sh_info
>= num_syms
)
7257 error (_("Bad sh_info in group section `%s'\n"), name
);
7261 sym
= symtab
+ section
->sh_info
;
7263 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
7265 if (sym
->st_shndx
== 0
7266 || sym
->st_shndx
>= filedata
->file_header
.e_shnum
)
7268 error (_("Bad sh_info in group section `%s'\n"), name
);
7272 group_name
= SECTION_NAME_PRINT (filedata
->section_headers
7281 /* Get the string table. */
7282 if (symtab_sec
->sh_link
>= filedata
->file_header
.e_shnum
)
7290 != (sec
= filedata
->section_headers
+ symtab_sec
->sh_link
))
7295 strtab
= (char *) get_data (NULL
, filedata
, strtab_sec
->sh_offset
,
7296 1, strtab_sec
->sh_size
,
7298 strtab_size
= strtab
!= NULL
? strtab_sec
->sh_size
: 0;
7300 group_name
= sym
->st_name
< strtab_size
7301 ? strtab
+ sym
->st_name
: _("<corrupt>");
7304 /* PR 17531: file: loop. */
7305 if (section
->sh_entsize
> section
->sh_size
)
7307 error (_("Section %s has sh_entsize (0x%lx) which is larger than its size (0x%lx)\n"),
7308 printable_section_name (filedata
, section
),
7309 (unsigned long) section
->sh_entsize
,
7310 (unsigned long) section
->sh_size
);
7314 start
= (unsigned char *) get_data (NULL
, filedata
, section
->sh_offset
,
7315 1, section
->sh_size
,
7321 size
= (section
->sh_size
/ section
->sh_entsize
) - 1;
7322 entry
= byte_get (indices
, 4);
7325 if (do_section_groups
)
7327 printf (_("\n%sgroup section [%5u] `%s' [%s] contains %u sections:\n"),
7328 get_group_flags (entry
), i
, name
, group_name
, size
);
7330 printf (_(" [Index] Name\n"));
7333 group
->group_index
= i
;
7335 for (j
= 0; j
< size
; j
++)
7337 struct group_list
* g
;
7339 entry
= byte_get (indices
, 4);
7342 if (entry
>= filedata
->file_header
.e_shnum
)
7344 static unsigned num_group_errors
= 0;
7346 if (num_group_errors
++ < 10)
7348 error (_("section [%5u] in group section [%5u] > maximum section [%5u]\n"),
7349 entry
, i
, filedata
->file_header
.e_shnum
- 1);
7350 if (num_group_errors
== 10)
7351 warn (_("Further error messages about overlarge group section indices suppressed\n"));
7356 if (filedata
->section_headers_groups
[entry
] != NULL
)
7360 static unsigned num_errs
= 0;
7362 if (num_errs
++ < 10)
7364 error (_("section [%5u] in group section [%5u] already in group section [%5u]\n"),
7366 filedata
->section_headers_groups
[entry
]->group_index
);
7368 warn (_("Further error messages about already contained group sections suppressed\n"));
7374 /* Intel C/C++ compiler may put section 0 in a
7375 section group. We just warn it the first time
7376 and ignore it afterwards. */
7377 static bfd_boolean warned
= FALSE
;
7380 error (_("section 0 in group section [%5u]\n"),
7381 filedata
->section_headers_groups
[entry
]->group_index
);
7387 filedata
->section_headers_groups
[entry
] = group
;
7389 if (do_section_groups
)
7391 sec
= filedata
->section_headers
+ entry
;
7392 printf (" [%5u] %s\n", entry
, printable_section_name (filedata
, sec
));
7395 g
= (struct group_list
*) xmalloc (sizeof (struct group_list
));
7396 g
->section_index
= entry
;
7397 g
->next
= group
->root
;
7412 /* Data used to display dynamic fixups. */
7414 struct ia64_vms_dynfixup
7416 bfd_vma needed_ident
; /* Library ident number. */
7417 bfd_vma needed
; /* Index in the dstrtab of the library name. */
7418 bfd_vma fixup_needed
; /* Index of the library. */
7419 bfd_vma fixup_rela_cnt
; /* Number of fixups. */
7420 bfd_vma fixup_rela_off
; /* Fixups offset in the dynamic segment. */
7423 /* Data used to display dynamic relocations. */
7425 struct ia64_vms_dynimgrela
7427 bfd_vma img_rela_cnt
; /* Number of relocations. */
7428 bfd_vma img_rela_off
; /* Reloc offset in the dynamic segment. */
7431 /* Display IA-64 OpenVMS dynamic fixups (used to dynamically link a shared
7435 dump_ia64_vms_dynamic_fixups (Filedata
* filedata
,
7436 struct ia64_vms_dynfixup
* fixup
,
7437 const char * strtab
,
7438 unsigned int strtab_sz
)
7440 Elf64_External_VMS_IMAGE_FIXUP
* imfs
;
7442 const char * lib_name
;
7444 imfs
= get_data (NULL
, filedata
,
7445 filedata
->dynamic_addr
+ fixup
->fixup_rela_off
,
7446 sizeof (*imfs
), fixup
->fixup_rela_cnt
,
7447 _("dynamic section image fixups"));
7451 if (fixup
->needed
< strtab_sz
)
7452 lib_name
= strtab
+ fixup
->needed
;
7455 warn (_("corrupt library name index of 0x%lx found in dynamic entry"),
7456 (unsigned long) fixup
->needed
);
7460 printf (_("\nImage fixups for needed library #%d: %s - ident: %lx\n"),
7461 (int) fixup
->fixup_needed
, lib_name
, (long) fixup
->needed_ident
);
7463 (_("Seg Offset Type SymVec DataType\n"));
7465 for (i
= 0; i
< (long) fixup
->fixup_rela_cnt
; i
++)
7470 printf ("%3u ", (unsigned) BYTE_GET (imfs
[i
].fixup_seg
));
7471 printf_vma ((bfd_vma
) BYTE_GET (imfs
[i
].fixup_offset
));
7472 type
= BYTE_GET (imfs
[i
].type
);
7473 rtype
= elf_ia64_reloc_type (type
);
7475 printf (" 0x%08x ", type
);
7477 printf (" %-32s ", rtype
);
7478 printf ("%6u ", (unsigned) BYTE_GET (imfs
[i
].symvec_index
));
7479 printf ("0x%08x\n", (unsigned) BYTE_GET (imfs
[i
].data_type
));
7486 /* Display IA-64 OpenVMS dynamic relocations (used to relocate an image). */
7489 dump_ia64_vms_dynamic_relocs (Filedata
* filedata
, struct ia64_vms_dynimgrela
*imgrela
)
7491 Elf64_External_VMS_IMAGE_RELA
*imrs
;
7494 imrs
= get_data (NULL
, filedata
,
7495 filedata
->dynamic_addr
+ imgrela
->img_rela_off
,
7496 sizeof (*imrs
), imgrela
->img_rela_cnt
,
7497 _("dynamic section image relocations"));
7501 printf (_("\nImage relocs\n"));
7503 (_("Seg Offset Type Addend Seg Sym Off\n"));
7505 for (i
= 0; i
< (long) imgrela
->img_rela_cnt
; i
++)
7510 printf ("%3u ", (unsigned) BYTE_GET (imrs
[i
].rela_seg
));
7511 printf ("%08" BFD_VMA_FMT
"x ",
7512 (bfd_vma
) BYTE_GET (imrs
[i
].rela_offset
));
7513 type
= BYTE_GET (imrs
[i
].type
);
7514 rtype
= elf_ia64_reloc_type (type
);
7516 printf ("0x%08x ", type
);
7518 printf ("%-31s ", rtype
);
7519 print_vma (BYTE_GET (imrs
[i
].addend
), FULL_HEX
);
7520 printf ("%3u ", (unsigned) BYTE_GET (imrs
[i
].sym_seg
));
7521 printf ("%08" BFD_VMA_FMT
"x\n",
7522 (bfd_vma
) BYTE_GET (imrs
[i
].sym_offset
));
7529 /* Display IA-64 OpenVMS dynamic relocations and fixups. */
7532 process_ia64_vms_dynamic_relocs (Filedata
* filedata
)
7534 struct ia64_vms_dynfixup fixup
;
7535 struct ia64_vms_dynimgrela imgrela
;
7536 Elf_Internal_Dyn
*entry
;
7537 bfd_vma strtab_off
= 0;
7538 bfd_vma strtab_sz
= 0;
7539 char *strtab
= NULL
;
7540 bfd_boolean res
= TRUE
;
7542 memset (&fixup
, 0, sizeof (fixup
));
7543 memset (&imgrela
, 0, sizeof (imgrela
));
7545 /* Note: the order of the entries is specified by the OpenVMS specs. */
7546 for (entry
= filedata
->dynamic_section
;
7547 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
7550 switch (entry
->d_tag
)
7552 case DT_IA_64_VMS_STRTAB_OFFSET
:
7553 strtab_off
= entry
->d_un
.d_val
;
7556 strtab_sz
= entry
->d_un
.d_val
;
7558 strtab
= get_data (NULL
, filedata
,
7559 filedata
->dynamic_addr
+ strtab_off
,
7560 1, strtab_sz
, _("dynamic string section"));
7565 case DT_IA_64_VMS_NEEDED_IDENT
:
7566 fixup
.needed_ident
= entry
->d_un
.d_val
;
7569 fixup
.needed
= entry
->d_un
.d_val
;
7571 case DT_IA_64_VMS_FIXUP_NEEDED
:
7572 fixup
.fixup_needed
= entry
->d_un
.d_val
;
7574 case DT_IA_64_VMS_FIXUP_RELA_CNT
:
7575 fixup
.fixup_rela_cnt
= entry
->d_un
.d_val
;
7577 case DT_IA_64_VMS_FIXUP_RELA_OFF
:
7578 fixup
.fixup_rela_off
= entry
->d_un
.d_val
;
7579 if (! dump_ia64_vms_dynamic_fixups (filedata
, &fixup
, strtab
, strtab_sz
))
7582 case DT_IA_64_VMS_IMG_RELA_CNT
:
7583 imgrela
.img_rela_cnt
= entry
->d_un
.d_val
;
7585 case DT_IA_64_VMS_IMG_RELA_OFF
:
7586 imgrela
.img_rela_off
= entry
->d_un
.d_val
;
7587 if (! dump_ia64_vms_dynamic_relocs (filedata
, &imgrela
))
7608 dynamic_relocations
[] =
7610 { "REL", DT_REL
, DT_RELSZ
, FALSE
},
7611 { "RELA", DT_RELA
, DT_RELASZ
, TRUE
},
7612 { "PLT", DT_JMPREL
, DT_PLTRELSZ
, UNKNOWN
}
7615 /* Process the reloc section. */
7618 process_relocs (Filedata
* filedata
)
7620 unsigned long rel_size
;
7621 unsigned long rel_offset
;
7626 if (do_using_dynamic
)
7630 bfd_boolean has_dynamic_reloc
;
7633 has_dynamic_reloc
= FALSE
;
7635 for (i
= 0; i
< ARRAY_SIZE (dynamic_relocations
); i
++)
7637 is_rela
= dynamic_relocations
[i
].rela
;
7638 name
= dynamic_relocations
[i
].name
;
7639 rel_size
= filedata
->dynamic_info
[dynamic_relocations
[i
].size
];
7640 rel_offset
= filedata
->dynamic_info
[dynamic_relocations
[i
].reloc
];
7643 has_dynamic_reloc
= TRUE
;
7645 if (is_rela
== UNKNOWN
)
7647 if (dynamic_relocations
[i
].reloc
== DT_JMPREL
)
7648 switch (filedata
->dynamic_info
[DT_PLTREL
])
7661 if (filedata
->is_separate
)
7663 (_("\nIn linked file '%s' section '%s' at offset 0x%lx contains %ld bytes:\n"),
7664 filedata
->file_name
, name
, rel_offset
, rel_size
);
7667 (_("\n'%s' relocation section at offset 0x%lx contains %ld bytes:\n"),
7668 name
, rel_offset
, rel_size
);
7671 dump_relocations (filedata
,
7672 offset_from_vma (filedata
, rel_offset
, rel_size
),
7674 filedata
->dynamic_symbols
,
7675 filedata
->num_dynamic_syms
,
7676 filedata
->dynamic_strings
,
7677 filedata
->dynamic_strings_length
,
7678 is_rela
, TRUE
/* is_dynamic */);
7682 if (is_ia64_vms (filedata
))
7683 if (process_ia64_vms_dynamic_relocs (filedata
))
7684 has_dynamic_reloc
= TRUE
;
7686 if (! has_dynamic_reloc
)
7688 if (filedata
->is_separate
)
7689 printf (_("\nThere are no dynamic relocations in linked file '%s'.\n"),
7690 filedata
->file_name
);
7692 printf (_("\nThere are no dynamic relocations in this file.\n"));
7697 Elf_Internal_Shdr
* section
;
7699 bfd_boolean found
= FALSE
;
7701 for (i
= 0, section
= filedata
->section_headers
;
7702 i
< filedata
->file_header
.e_shnum
;
7705 if ( section
->sh_type
!= SHT_RELA
7706 && section
->sh_type
!= SHT_REL
)
7709 rel_offset
= section
->sh_offset
;
7710 rel_size
= section
->sh_size
;
7715 unsigned long num_rela
;
7717 if (filedata
->is_separate
)
7718 printf (_("\nIn linked file '%s' relocation section "),
7719 filedata
->file_name
);
7721 printf (_("\nRelocation section "));
7723 if (filedata
->string_table
== NULL
)
7724 printf ("%d", section
->sh_name
);
7726 printf ("'%s'", printable_section_name (filedata
, section
));
7728 num_rela
= rel_size
/ section
->sh_entsize
;
7729 printf (ngettext (" at offset 0x%lx contains %lu entry:\n",
7730 " at offset 0x%lx contains %lu entries:\n",
7732 rel_offset
, num_rela
);
7734 is_rela
= section
->sh_type
== SHT_RELA
;
7736 if (section
->sh_link
!= 0
7737 && section
->sh_link
< filedata
->file_header
.e_shnum
)
7739 Elf_Internal_Shdr
* symsec
;
7740 Elf_Internal_Sym
* symtab
;
7741 unsigned long nsyms
;
7742 unsigned long strtablen
= 0;
7743 char * strtab
= NULL
;
7745 symsec
= filedata
->section_headers
+ section
->sh_link
;
7746 if (symsec
->sh_type
!= SHT_SYMTAB
7747 && symsec
->sh_type
!= SHT_DYNSYM
)
7750 if (!get_symtab (filedata
, symsec
,
7751 &symtab
, &nsyms
, &strtab
, &strtablen
))
7754 dump_relocations (filedata
, rel_offset
, rel_size
,
7755 symtab
, nsyms
, strtab
, strtablen
,
7757 symsec
->sh_type
== SHT_DYNSYM
);
7762 dump_relocations (filedata
, rel_offset
, rel_size
,
7763 NULL
, 0, NULL
, 0, is_rela
,
7764 FALSE
/* is_dynamic */);
7772 /* Users sometimes forget the -D option, so try to be helpful. */
7773 for (i
= 0; i
< ARRAY_SIZE (dynamic_relocations
); i
++)
7775 if (filedata
->dynamic_info
[dynamic_relocations
[i
].size
])
7777 if (filedata
->is_separate
)
7778 printf (_("\nThere are no static relocations in linked file '%s'."),
7779 filedata
->file_name
);
7781 printf (_("\nThere are no static relocations in this file."));
7782 printf (_("\nTo see the dynamic relocations add --use-dynamic to the command line.\n"));
7787 if (i
== ARRAY_SIZE (dynamic_relocations
))
7789 if (filedata
->is_separate
)
7790 printf (_("\nThere are no relocations in linked file '%s'.\n"),
7791 filedata
->file_name
);
7793 printf (_("\nThere are no relocations in this file.\n"));
7801 /* An absolute address consists of a section and an offset. If the
7802 section is NULL, the offset itself is the address, otherwise, the
7803 address equals to LOAD_ADDRESS(section) + offset. */
7807 unsigned short section
;
7811 /* Find the nearest symbol at or below ADDR. Returns the symbol
7812 name, if found, and the offset from the symbol to ADDR. */
7815 find_symbol_for_address (Filedata
* filedata
,
7816 Elf_Internal_Sym
* symtab
,
7817 unsigned long nsyms
,
7818 const char * strtab
,
7819 unsigned long strtab_size
,
7820 struct absaddr addr
,
7821 const char ** symname
,
7824 bfd_vma dist
= 0x100000;
7825 Elf_Internal_Sym
* sym
;
7826 Elf_Internal_Sym
* beg
;
7827 Elf_Internal_Sym
* end
;
7828 Elf_Internal_Sym
* best
= NULL
;
7830 REMOVE_ARCH_BITS (addr
.offset
);
7832 end
= symtab
+ nsyms
;
7838 sym
= beg
+ (end
- beg
) / 2;
7840 value
= sym
->st_value
;
7841 REMOVE_ARCH_BITS (value
);
7843 if (sym
->st_name
!= 0
7844 && (addr
.section
== SHN_UNDEF
|| addr
.section
== sym
->st_shndx
)
7845 && addr
.offset
>= value
7846 && addr
.offset
- value
< dist
)
7849 dist
= addr
.offset
- value
;
7854 if (addr
.offset
< value
)
7862 *symname
= (best
->st_name
>= strtab_size
7863 ? _("<corrupt>") : strtab
+ best
->st_name
);
7869 *offset
= addr
.offset
;
7872 static /* signed */ int
7873 symcmp (const void *p
, const void *q
)
7875 Elf_Internal_Sym
*sp
= (Elf_Internal_Sym
*) p
;
7876 Elf_Internal_Sym
*sq
= (Elf_Internal_Sym
*) q
;
7878 return sp
->st_value
> sq
->st_value
? 1 : (sp
->st_value
< sq
->st_value
? -1 : 0);
7881 /* Process the unwind section. */
7883 #include "unwind-ia64.h"
7885 struct ia64_unw_table_entry
7887 struct absaddr start
;
7889 struct absaddr info
;
7892 struct ia64_unw_aux_info
7894 struct ia64_unw_table_entry
* table
; /* Unwind table. */
7895 unsigned long table_len
; /* Length of unwind table. */
7896 unsigned char * info
; /* Unwind info. */
7897 unsigned long info_size
; /* Size of unwind info. */
7898 bfd_vma info_addr
; /* Starting address of unwind info. */
7899 bfd_vma seg_base
; /* Starting address of segment. */
7900 Elf_Internal_Sym
* symtab
; /* The symbol table. */
7901 unsigned long nsyms
; /* Number of symbols. */
7902 Elf_Internal_Sym
* funtab
; /* Sorted table of STT_FUNC symbols. */
7903 unsigned long nfuns
; /* Number of entries in funtab. */
7904 char * strtab
; /* The string table. */
7905 unsigned long strtab_size
; /* Size of string table. */
7909 dump_ia64_unwind (Filedata
* filedata
, struct ia64_unw_aux_info
* aux
)
7911 struct ia64_unw_table_entry
* tp
;
7912 unsigned long j
, nfuns
;
7914 bfd_boolean res
= TRUE
;
7916 aux
->funtab
= xmalloc (aux
->nsyms
* sizeof (Elf_Internal_Sym
));
7917 for (nfuns
= 0, j
= 0; j
< aux
->nsyms
; j
++)
7918 if (aux
->symtab
[j
].st_value
&& ELF_ST_TYPE (aux
->symtab
[j
].st_info
) == STT_FUNC
)
7919 aux
->funtab
[nfuns
++] = aux
->symtab
[j
];
7921 qsort (aux
->funtab
, aux
->nfuns
, sizeof (Elf_Internal_Sym
), symcmp
);
7923 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
7927 const unsigned char * dp
;
7928 const unsigned char * head
;
7929 const unsigned char * end
;
7930 const char * procname
;
7932 find_symbol_for_address (filedata
, aux
->funtab
, aux
->nfuns
, aux
->strtab
,
7933 aux
->strtab_size
, tp
->start
, &procname
, &offset
);
7935 fputs ("\n<", stdout
);
7939 fputs (procname
, stdout
);
7942 printf ("+%lx", (unsigned long) offset
);
7945 fputs (">: [", stdout
);
7946 print_vma (tp
->start
.offset
, PREFIX_HEX
);
7947 fputc ('-', stdout
);
7948 print_vma (tp
->end
.offset
, PREFIX_HEX
);
7949 printf ("], info at +0x%lx\n",
7950 (unsigned long) (tp
->info
.offset
- aux
->seg_base
));
7952 /* PR 17531: file: 86232b32. */
7953 if (aux
->info
== NULL
)
7956 offset
= tp
->info
.offset
;
7957 if (tp
->info
.section
)
7959 if (tp
->info
.section
>= filedata
->file_header
.e_shnum
)
7961 warn (_("Invalid section %u in table entry %ld\n"),
7962 tp
->info
.section
, (long) (tp
- aux
->table
));
7966 offset
+= filedata
->section_headers
[tp
->info
.section
].sh_addr
;
7968 offset
-= aux
->info_addr
;
7969 /* PR 17531: file: 0997b4d1. */
7970 if (offset
>= aux
->info_size
7971 || aux
->info_size
- offset
< 8)
7973 warn (_("Invalid offset %lx in table entry %ld\n"),
7974 (long) tp
->info
.offset
, (long) (tp
- aux
->table
));
7979 head
= aux
->info
+ offset
;
7980 stamp
= byte_get ((unsigned char *) head
, sizeof (stamp
));
7982 printf (" v%u, flags=0x%lx (%s%s), len=%lu bytes\n",
7983 (unsigned) UNW_VER (stamp
),
7984 (unsigned long) ((stamp
& UNW_FLAG_MASK
) >> 32),
7985 UNW_FLAG_EHANDLER (stamp
) ? " ehandler" : "",
7986 UNW_FLAG_UHANDLER (stamp
) ? " uhandler" : "",
7987 (unsigned long) (eh_addr_size
* UNW_LENGTH (stamp
)));
7989 if (UNW_VER (stamp
) != 1)
7991 printf (_("\tUnknown version.\n"));
7996 end
= head
+ 8 + eh_addr_size
* UNW_LENGTH (stamp
);
7997 /* PR 17531: file: 16ceda89. */
7998 if (end
> aux
->info
+ aux
->info_size
)
7999 end
= aux
->info
+ aux
->info_size
;
8000 for (dp
= head
+ 8; dp
< end
;)
8001 dp
= unw_decode (dp
, in_body
, & in_body
, end
);
8010 slurp_ia64_unwind_table (Filedata
* filedata
,
8011 struct ia64_unw_aux_info
* aux
,
8012 Elf_Internal_Shdr
* sec
)
8014 unsigned long size
, nrelas
, i
;
8015 Elf_Internal_Phdr
* seg
;
8016 struct ia64_unw_table_entry
* tep
;
8017 Elf_Internal_Shdr
* relsec
;
8018 Elf_Internal_Rela
* rela
;
8019 Elf_Internal_Rela
* rp
;
8020 unsigned char * table
;
8022 Elf_Internal_Sym
* sym
;
8023 const char * relname
;
8027 /* First, find the starting address of the segment that includes
8030 if (filedata
->file_header
.e_phnum
)
8032 if (! get_program_headers (filedata
))
8035 for (seg
= filedata
->program_headers
;
8036 seg
< filedata
->program_headers
+ filedata
->file_header
.e_phnum
;
8039 if (seg
->p_type
!= PT_LOAD
)
8042 if (sec
->sh_addr
>= seg
->p_vaddr
8043 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
8045 aux
->seg_base
= seg
->p_vaddr
;
8051 /* Second, build the unwind table from the contents of the unwind section: */
8052 size
= sec
->sh_size
;
8053 table
= (unsigned char *) get_data (NULL
, filedata
, sec
->sh_offset
, 1, size
,
8058 aux
->table_len
= size
/ (3 * eh_addr_size
);
8059 aux
->table
= (struct ia64_unw_table_entry
*)
8060 xcmalloc (aux
->table_len
, sizeof (aux
->table
[0]));
8063 for (tp
= table
; tp
<= table
+ size
- (3 * eh_addr_size
); ++tep
)
8065 tep
->start
.section
= SHN_UNDEF
;
8066 tep
->end
.section
= SHN_UNDEF
;
8067 tep
->info
.section
= SHN_UNDEF
;
8068 tep
->start
.offset
= byte_get (tp
, eh_addr_size
); tp
+= eh_addr_size
;
8069 tep
->end
.offset
= byte_get (tp
, eh_addr_size
); tp
+= eh_addr_size
;
8070 tep
->info
.offset
= byte_get (tp
, eh_addr_size
); tp
+= eh_addr_size
;
8071 tep
->start
.offset
+= aux
->seg_base
;
8072 tep
->end
.offset
+= aux
->seg_base
;
8073 tep
->info
.offset
+= aux
->seg_base
;
8077 /* Third, apply any relocations to the unwind table: */
8078 for (relsec
= filedata
->section_headers
;
8079 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
8082 if (relsec
->sh_type
!= SHT_RELA
8083 || relsec
->sh_info
>= filedata
->file_header
.e_shnum
8084 || filedata
->section_headers
+ relsec
->sh_info
!= sec
)
8087 if (!slurp_rela_relocs (filedata
, relsec
->sh_offset
, relsec
->sh_size
,
8096 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
8098 unsigned int sym_ndx
;
8099 unsigned int r_type
= get_reloc_type (filedata
, rp
->r_info
);
8100 relname
= elf_ia64_reloc_type (r_type
);
8102 /* PR 17531: file: 9fa67536. */
8103 if (relname
== NULL
)
8105 warn (_("Skipping unknown relocation type: %u\n"), r_type
);
8109 if (! const_strneq (relname
, "R_IA64_SEGREL"))
8111 warn (_("Skipping unexpected relocation type: %s\n"), relname
);
8115 i
= rp
->r_offset
/ (3 * eh_addr_size
);
8117 /* PR 17531: file: 5bc8d9bf. */
8118 if (i
>= aux
->table_len
)
8120 warn (_("Skipping reloc with overlarge offset: %lx\n"), i
);
8124 sym_ndx
= get_reloc_symindex (rp
->r_info
);
8125 if (sym_ndx
>= aux
->nsyms
)
8127 warn (_("Skipping reloc with invalid symbol index: %u\n"),
8131 sym
= aux
->symtab
+ sym_ndx
;
8133 switch (rp
->r_offset
/ eh_addr_size
% 3)
8136 aux
->table
[i
].start
.section
= sym
->st_shndx
;
8137 aux
->table
[i
].start
.offset
= rp
->r_addend
+ sym
->st_value
;
8140 aux
->table
[i
].end
.section
= sym
->st_shndx
;
8141 aux
->table
[i
].end
.offset
= rp
->r_addend
+ sym
->st_value
;
8144 aux
->table
[i
].info
.section
= sym
->st_shndx
;
8145 aux
->table
[i
].info
.offset
= rp
->r_addend
+ sym
->st_value
;
8159 ia64_process_unwind (Filedata
* filedata
)
8161 Elf_Internal_Shdr
* sec
;
8162 Elf_Internal_Shdr
* unwsec
= NULL
;
8163 unsigned long i
, unwcount
= 0, unwstart
= 0;
8164 struct ia64_unw_aux_info aux
;
8165 bfd_boolean res
= TRUE
;
8167 memset (& aux
, 0, sizeof (aux
));
8169 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
8171 if (sec
->sh_type
== SHT_SYMTAB
)
8175 error (_("Multiple symbol tables encountered\n"));
8181 if (!get_symtab (filedata
, sec
, &aux
.symtab
, &aux
.nsyms
,
8182 &aux
.strtab
, &aux
.strtab_size
))
8185 else if (sec
->sh_type
== SHT_IA_64_UNWIND
)
8190 printf (_("\nThere are no unwind sections in this file.\n"));
8192 while (unwcount
-- > 0)
8197 for (i
= unwstart
, sec
= filedata
->section_headers
+ unwstart
, unwsec
= NULL
;
8198 i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
8199 if (sec
->sh_type
== SHT_IA_64_UNWIND
)
8204 /* We have already counted the number of SHT_IA64_UNWIND
8205 sections so the loop above should never fail. */
8206 assert (unwsec
!= NULL
);
8209 len
= sizeof (ELF_STRING_ia64_unwind_once
) - 1;
8211 if ((unwsec
->sh_flags
& SHF_GROUP
) != 0)
8213 /* We need to find which section group it is in. */
8214 struct group_list
* g
;
8216 if (filedata
->section_headers_groups
== NULL
8217 || filedata
->section_headers_groups
[i
] == NULL
)
8218 i
= filedata
->file_header
.e_shnum
;
8221 g
= filedata
->section_headers_groups
[i
]->root
;
8223 for (; g
!= NULL
; g
= g
->next
)
8225 sec
= filedata
->section_headers
+ g
->section_index
;
8227 if (SECTION_NAME_VALID (sec
)
8228 && streq (SECTION_NAME (sec
), ELF_STRING_ia64_unwind_info
))
8233 i
= filedata
->file_header
.e_shnum
;
8236 else if (SECTION_NAME_VALID (unwsec
)
8237 && strneq (SECTION_NAME (unwsec
),
8238 ELF_STRING_ia64_unwind_once
, len
))
8240 /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO. */
8241 len2
= sizeof (ELF_STRING_ia64_unwind_info_once
) - 1;
8242 suffix
= SECTION_NAME (unwsec
) + len
;
8243 for (i
= 0, sec
= filedata
->section_headers
;
8244 i
< filedata
->file_header
.e_shnum
;
8246 if (SECTION_NAME_VALID (sec
)
8247 && strneq (SECTION_NAME (sec
),
8248 ELF_STRING_ia64_unwind_info_once
, len2
)
8249 && streq (SECTION_NAME (sec
) + len2
, suffix
))
8254 /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
8255 .IA_64.unwind or BAR -> .IA_64.unwind_info. */
8256 len
= sizeof (ELF_STRING_ia64_unwind
) - 1;
8257 len2
= sizeof (ELF_STRING_ia64_unwind_info
) - 1;
8259 if (SECTION_NAME_VALID (unwsec
)
8260 && strneq (SECTION_NAME (unwsec
), ELF_STRING_ia64_unwind
, len
))
8261 suffix
= SECTION_NAME (unwsec
) + len
;
8262 for (i
= 0, sec
= filedata
->section_headers
;
8263 i
< filedata
->file_header
.e_shnum
;
8265 if (SECTION_NAME_VALID (sec
)
8266 && strneq (SECTION_NAME (sec
), ELF_STRING_ia64_unwind_info
, len2
)
8267 && streq (SECTION_NAME (sec
) + len2
, suffix
))
8271 if (i
== filedata
->file_header
.e_shnum
)
8273 printf (_("\nCould not find unwind info section for "));
8275 if (filedata
->string_table
== NULL
)
8276 printf ("%d", unwsec
->sh_name
);
8278 printf ("'%s'", printable_section_name (filedata
, unwsec
));
8282 aux
.info_addr
= sec
->sh_addr
;
8283 aux
.info
= (unsigned char *) get_data (NULL
, filedata
, sec
->sh_offset
, 1,
8286 aux
.info_size
= aux
.info
== NULL
? 0 : sec
->sh_size
;
8288 printf (_("\nUnwind section "));
8290 if (filedata
->string_table
== NULL
)
8291 printf ("%d", unwsec
->sh_name
);
8293 printf ("'%s'", printable_section_name (filedata
, unwsec
));
8295 printf (_(" at offset 0x%lx contains %lu entries:\n"),
8296 (unsigned long) unwsec
->sh_offset
,
8297 (unsigned long) (unwsec
->sh_size
/ (3 * eh_addr_size
)));
8299 if (slurp_ia64_unwind_table (filedata
, & aux
, unwsec
)
8300 && aux
.table_len
> 0)
8301 dump_ia64_unwind (filedata
, & aux
);
8303 free ((char *) aux
.table
);
8304 free ((char *) aux
.info
);
8311 free ((char *) aux
.strtab
);
8316 struct hppa_unw_table_entry
8318 struct absaddr start
;
8320 unsigned int Cannot_unwind
:1; /* 0 */
8321 unsigned int Millicode
:1; /* 1 */
8322 unsigned int Millicode_save_sr0
:1; /* 2 */
8323 unsigned int Region_description
:2; /* 3..4 */
8324 unsigned int reserved1
:1; /* 5 */
8325 unsigned int Entry_SR
:1; /* 6 */
8326 unsigned int Entry_FR
:4; /* Number saved 7..10 */
8327 unsigned int Entry_GR
:5; /* Number saved 11..15 */
8328 unsigned int Args_stored
:1; /* 16 */
8329 unsigned int Variable_Frame
:1; /* 17 */
8330 unsigned int Separate_Package_Body
:1; /* 18 */
8331 unsigned int Frame_Extension_Millicode
:1; /* 19 */
8332 unsigned int Stack_Overflow_Check
:1; /* 20 */
8333 unsigned int Two_Instruction_SP_Increment
:1; /* 21 */
8334 unsigned int Ada_Region
:1; /* 22 */
8335 unsigned int cxx_info
:1; /* 23 */
8336 unsigned int cxx_try_catch
:1; /* 24 */
8337 unsigned int sched_entry_seq
:1; /* 25 */
8338 unsigned int reserved2
:1; /* 26 */
8339 unsigned int Save_SP
:1; /* 27 */
8340 unsigned int Save_RP
:1; /* 28 */
8341 unsigned int Save_MRP_in_frame
:1; /* 29 */
8342 unsigned int extn_ptr_defined
:1; /* 30 */
8343 unsigned int Cleanup_defined
:1; /* 31 */
8345 unsigned int MPE_XL_interrupt_marker
:1; /* 0 */
8346 unsigned int HP_UX_interrupt_marker
:1; /* 1 */
8347 unsigned int Large_frame
:1; /* 2 */
8348 unsigned int Pseudo_SP_Set
:1; /* 3 */
8349 unsigned int reserved4
:1; /* 4 */
8350 unsigned int Total_frame_size
:27; /* 5..31 */
8353 struct hppa_unw_aux_info
8355 struct hppa_unw_table_entry
* table
; /* Unwind table. */
8356 unsigned long table_len
; /* Length of unwind table. */
8357 bfd_vma seg_base
; /* Starting address of segment. */
8358 Elf_Internal_Sym
* symtab
; /* The symbol table. */
8359 unsigned long nsyms
; /* Number of symbols. */
8360 Elf_Internal_Sym
* funtab
; /* Sorted table of STT_FUNC symbols. */
8361 unsigned long nfuns
; /* Number of entries in funtab. */
8362 char * strtab
; /* The string table. */
8363 unsigned long strtab_size
; /* Size of string table. */
8367 dump_hppa_unwind (Filedata
* filedata
, struct hppa_unw_aux_info
* aux
)
8369 struct hppa_unw_table_entry
* tp
;
8370 unsigned long j
, nfuns
;
8371 bfd_boolean res
= TRUE
;
8373 aux
->funtab
= xmalloc (aux
->nsyms
* sizeof (Elf_Internal_Sym
));
8374 for (nfuns
= 0, j
= 0; j
< aux
->nsyms
; j
++)
8375 if (aux
->symtab
[j
].st_value
&& ELF_ST_TYPE (aux
->symtab
[j
].st_info
) == STT_FUNC
)
8376 aux
->funtab
[nfuns
++] = aux
->symtab
[j
];
8378 qsort (aux
->funtab
, aux
->nfuns
, sizeof (Elf_Internal_Sym
), symcmp
);
8380 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
8383 const char * procname
;
8385 find_symbol_for_address (filedata
, aux
->funtab
, aux
->nfuns
, aux
->strtab
,
8386 aux
->strtab_size
, tp
->start
, &procname
,
8389 fputs ("\n<", stdout
);
8393 fputs (procname
, stdout
);
8396 printf ("+%lx", (unsigned long) offset
);
8399 fputs (">: [", stdout
);
8400 print_vma (tp
->start
.offset
, PREFIX_HEX
);
8401 fputc ('-', stdout
);
8402 print_vma (tp
->end
.offset
, PREFIX_HEX
);
8405 #define PF(_m) if (tp->_m) printf (#_m " ");
8406 #define PV(_m) if (tp->_m) printf (#_m "=%d ", tp->_m);
8409 PF(Millicode_save_sr0
);
8410 /* PV(Region_description); */
8416 PF(Separate_Package_Body
);
8417 PF(Frame_Extension_Millicode
);
8418 PF(Stack_Overflow_Check
);
8419 PF(Two_Instruction_SP_Increment
);
8423 PF(sched_entry_seq
);
8426 PF(Save_MRP_in_frame
);
8427 PF(extn_ptr_defined
);
8428 PF(Cleanup_defined
);
8429 PF(MPE_XL_interrupt_marker
);
8430 PF(HP_UX_interrupt_marker
);
8433 PV(Total_frame_size
);
8446 slurp_hppa_unwind_table (Filedata
* filedata
,
8447 struct hppa_unw_aux_info
* aux
,
8448 Elf_Internal_Shdr
* sec
)
8450 unsigned long size
, unw_ent_size
, nentries
, nrelas
, i
;
8451 Elf_Internal_Phdr
* seg
;
8452 struct hppa_unw_table_entry
* tep
;
8453 Elf_Internal_Shdr
* relsec
;
8454 Elf_Internal_Rela
* rela
;
8455 Elf_Internal_Rela
* rp
;
8456 unsigned char * table
;
8458 Elf_Internal_Sym
* sym
;
8459 const char * relname
;
8461 /* First, find the starting address of the segment that includes
8463 if (filedata
->file_header
.e_phnum
)
8465 if (! get_program_headers (filedata
))
8468 for (seg
= filedata
->program_headers
;
8469 seg
< filedata
->program_headers
+ filedata
->file_header
.e_phnum
;
8472 if (seg
->p_type
!= PT_LOAD
)
8475 if (sec
->sh_addr
>= seg
->p_vaddr
8476 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
8478 aux
->seg_base
= seg
->p_vaddr
;
8484 /* Second, build the unwind table from the contents of the unwind
8486 size
= sec
->sh_size
;
8487 table
= (unsigned char *) get_data (NULL
, filedata
, sec
->sh_offset
, 1, size
,
8493 nentries
= size
/ unw_ent_size
;
8494 size
= unw_ent_size
* nentries
;
8496 aux
->table_len
= nentries
;
8497 tep
= aux
->table
= (struct hppa_unw_table_entry
*)
8498 xcmalloc (nentries
, sizeof (aux
->table
[0]));
8500 for (tp
= table
; tp
< table
+ size
; tp
+= unw_ent_size
, ++tep
)
8502 unsigned int tmp1
, tmp2
;
8504 tep
->start
.section
= SHN_UNDEF
;
8505 tep
->end
.section
= SHN_UNDEF
;
8507 tep
->start
.offset
= byte_get ((unsigned char *) tp
+ 0, 4);
8508 tep
->end
.offset
= byte_get ((unsigned char *) tp
+ 4, 4);
8509 tmp1
= byte_get ((unsigned char *) tp
+ 8, 4);
8510 tmp2
= byte_get ((unsigned char *) tp
+ 12, 4);
8512 tep
->start
.offset
+= aux
->seg_base
;
8513 tep
->end
.offset
+= aux
->seg_base
;
8515 tep
->Cannot_unwind
= (tmp1
>> 31) & 0x1;
8516 tep
->Millicode
= (tmp1
>> 30) & 0x1;
8517 tep
->Millicode_save_sr0
= (tmp1
>> 29) & 0x1;
8518 tep
->Region_description
= (tmp1
>> 27) & 0x3;
8519 tep
->reserved1
= (tmp1
>> 26) & 0x1;
8520 tep
->Entry_SR
= (tmp1
>> 25) & 0x1;
8521 tep
->Entry_FR
= (tmp1
>> 21) & 0xf;
8522 tep
->Entry_GR
= (tmp1
>> 16) & 0x1f;
8523 tep
->Args_stored
= (tmp1
>> 15) & 0x1;
8524 tep
->Variable_Frame
= (tmp1
>> 14) & 0x1;
8525 tep
->Separate_Package_Body
= (tmp1
>> 13) & 0x1;
8526 tep
->Frame_Extension_Millicode
= (tmp1
>> 12) & 0x1;
8527 tep
->Stack_Overflow_Check
= (tmp1
>> 11) & 0x1;
8528 tep
->Two_Instruction_SP_Increment
= (tmp1
>> 10) & 0x1;
8529 tep
->Ada_Region
= (tmp1
>> 9) & 0x1;
8530 tep
->cxx_info
= (tmp1
>> 8) & 0x1;
8531 tep
->cxx_try_catch
= (tmp1
>> 7) & 0x1;
8532 tep
->sched_entry_seq
= (tmp1
>> 6) & 0x1;
8533 tep
->reserved2
= (tmp1
>> 5) & 0x1;
8534 tep
->Save_SP
= (tmp1
>> 4) & 0x1;
8535 tep
->Save_RP
= (tmp1
>> 3) & 0x1;
8536 tep
->Save_MRP_in_frame
= (tmp1
>> 2) & 0x1;
8537 tep
->extn_ptr_defined
= (tmp1
>> 1) & 0x1;
8538 tep
->Cleanup_defined
= tmp1
& 0x1;
8540 tep
->MPE_XL_interrupt_marker
= (tmp2
>> 31) & 0x1;
8541 tep
->HP_UX_interrupt_marker
= (tmp2
>> 30) & 0x1;
8542 tep
->Large_frame
= (tmp2
>> 29) & 0x1;
8543 tep
->Pseudo_SP_Set
= (tmp2
>> 28) & 0x1;
8544 tep
->reserved4
= (tmp2
>> 27) & 0x1;
8545 tep
->Total_frame_size
= tmp2
& 0x7ffffff;
8549 /* Third, apply any relocations to the unwind table. */
8550 for (relsec
= filedata
->section_headers
;
8551 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
8554 if (relsec
->sh_type
!= SHT_RELA
8555 || relsec
->sh_info
>= filedata
->file_header
.e_shnum
8556 || filedata
->section_headers
+ relsec
->sh_info
!= sec
)
8559 if (!slurp_rela_relocs (filedata
, relsec
->sh_offset
, relsec
->sh_size
,
8563 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
8565 unsigned int sym_ndx
;
8566 unsigned int r_type
= get_reloc_type (filedata
, rp
->r_info
);
8567 relname
= elf_hppa_reloc_type (r_type
);
8569 if (relname
== NULL
)
8571 warn (_("Skipping unknown relocation type: %u\n"), r_type
);
8575 /* R_PARISC_SEGREL32 or R_PARISC_SEGREL64. */
8576 if (! const_strneq (relname
, "R_PARISC_SEGREL"))
8578 warn (_("Skipping unexpected relocation type: %s\n"), relname
);
8582 i
= rp
->r_offset
/ unw_ent_size
;
8583 if (i
>= aux
->table_len
)
8585 warn (_("Skipping reloc with overlarge offset: %lx\n"), i
);
8589 sym_ndx
= get_reloc_symindex (rp
->r_info
);
8590 if (sym_ndx
>= aux
->nsyms
)
8592 warn (_("Skipping reloc with invalid symbol index: %u\n"),
8596 sym
= aux
->symtab
+ sym_ndx
;
8598 switch ((rp
->r_offset
% unw_ent_size
) / 4)
8601 aux
->table
[i
].start
.section
= sym
->st_shndx
;
8602 aux
->table
[i
].start
.offset
= sym
->st_value
+ rp
->r_addend
;
8605 aux
->table
[i
].end
.section
= sym
->st_shndx
;
8606 aux
->table
[i
].end
.offset
= sym
->st_value
+ rp
->r_addend
;
8620 hppa_process_unwind (Filedata
* filedata
)
8622 struct hppa_unw_aux_info aux
;
8623 Elf_Internal_Shdr
* unwsec
= NULL
;
8624 Elf_Internal_Shdr
* sec
;
8626 bfd_boolean res
= TRUE
;
8628 if (filedata
->string_table
== NULL
)
8631 memset (& aux
, 0, sizeof (aux
));
8633 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
8635 if (sec
->sh_type
== SHT_SYMTAB
)
8639 error (_("Multiple symbol tables encountered\n"));
8645 if (!get_symtab (filedata
, sec
, &aux
.symtab
, &aux
.nsyms
,
8646 &aux
.strtab
, &aux
.strtab_size
))
8649 else if (SECTION_NAME_VALID (sec
)
8650 && streq (SECTION_NAME (sec
), ".PARISC.unwind"))
8655 printf (_("\nThere are no unwind sections in this file.\n"));
8657 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
8659 if (SECTION_NAME_VALID (sec
)
8660 && streq (SECTION_NAME (sec
), ".PARISC.unwind"))
8662 unsigned long num_unwind
= sec
->sh_size
/ 16;
8664 printf (ngettext ("\nUnwind section '%s' at offset 0x%lx "
8665 "contains %lu entry:\n",
8666 "\nUnwind section '%s' at offset 0x%lx "
8667 "contains %lu entries:\n",
8669 printable_section_name (filedata
, sec
),
8670 (unsigned long) sec
->sh_offset
,
8673 if (! slurp_hppa_unwind_table (filedata
, &aux
, sec
))
8676 if (res
&& aux
.table_len
> 0)
8678 if (! dump_hppa_unwind (filedata
, &aux
))
8682 free ((char *) aux
.table
);
8688 free ((char *) aux
.strtab
);
8695 unsigned char * data
; /* The unwind data. */
8696 Elf_Internal_Shdr
* sec
; /* The cached unwind section header. */
8697 Elf_Internal_Rela
* rela
; /* The cached relocations for this section. */
8698 unsigned long nrelas
; /* The number of relocations. */
8699 unsigned int rel_type
; /* REL or RELA ? */
8700 Elf_Internal_Rela
* next_rela
; /* Cyclic pointer to the next reloc to process. */
8703 struct arm_unw_aux_info
8705 Filedata
* filedata
; /* The file containing the unwind sections. */
8706 Elf_Internal_Sym
* symtab
; /* The file's symbol table. */
8707 unsigned long nsyms
; /* Number of symbols. */
8708 Elf_Internal_Sym
* funtab
; /* Sorted table of STT_FUNC symbols. */
8709 unsigned long nfuns
; /* Number of these symbols. */
8710 char * strtab
; /* The file's string table. */
8711 unsigned long strtab_size
; /* Size of string table. */
8715 arm_print_vma_and_name (Filedata
* filedata
,
8716 struct arm_unw_aux_info
* aux
,
8718 struct absaddr addr
)
8720 const char *procname
;
8723 if (addr
.section
== SHN_UNDEF
)
8726 find_symbol_for_address (filedata
, aux
->funtab
, aux
->nfuns
, aux
->strtab
,
8727 aux
->strtab_size
, addr
, &procname
,
8730 print_vma (fn
, PREFIX_HEX
);
8734 fputs (" <", stdout
);
8735 fputs (procname
, stdout
);
8738 printf ("+0x%lx", (unsigned long) sym_offset
);
8739 fputc ('>', stdout
);
8746 arm_free_section (struct arm_section
*arm_sec
)
8748 free (arm_sec
->data
);
8749 free (arm_sec
->rela
);
8752 /* 1) If SEC does not match the one cached in ARM_SEC, then free the current
8753 cached section and install SEC instead.
8754 2) Locate the 32-bit word at WORD_OFFSET in unwind section SEC
8755 and return its valued in * WORDP, relocating if necessary.
8756 3) Update the NEXT_RELA field in ARM_SEC and store the section index and
8757 relocation's offset in ADDR.
8758 4) If SYM_NAME is non-NULL and a relocation was applied, record the offset
8759 into the string table of the symbol associated with the reloc. If no
8760 reloc was applied store -1 there.
8761 5) Return TRUE upon success, FALSE otherwise. */
8764 get_unwind_section_word (Filedata
* filedata
,
8765 struct arm_unw_aux_info
* aux
,
8766 struct arm_section
* arm_sec
,
8767 Elf_Internal_Shdr
* sec
,
8768 bfd_vma word_offset
,
8769 unsigned int * wordp
,
8770 struct absaddr
* addr
,
8773 Elf_Internal_Rela
*rp
;
8774 Elf_Internal_Sym
*sym
;
8775 const char * relname
;
8777 bfd_boolean wrapped
;
8779 if (sec
== NULL
|| arm_sec
== NULL
)
8782 addr
->section
= SHN_UNDEF
;
8785 if (sym_name
!= NULL
)
8786 *sym_name
= (bfd_vma
) -1;
8788 /* If necessary, update the section cache. */
8789 if (sec
!= arm_sec
->sec
)
8791 Elf_Internal_Shdr
*relsec
;
8793 arm_free_section (arm_sec
);
8796 arm_sec
->data
= get_data (NULL
, aux
->filedata
, sec
->sh_offset
, 1,
8797 sec
->sh_size
, _("unwind data"));
8798 arm_sec
->rela
= NULL
;
8799 arm_sec
->nrelas
= 0;
8801 for (relsec
= filedata
->section_headers
;
8802 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
8805 if (relsec
->sh_info
>= filedata
->file_header
.e_shnum
8806 || filedata
->section_headers
+ relsec
->sh_info
!= sec
8807 /* PR 15745: Check the section type as well. */
8808 || (relsec
->sh_type
!= SHT_REL
8809 && relsec
->sh_type
!= SHT_RELA
))
8812 arm_sec
->rel_type
= relsec
->sh_type
;
8813 if (relsec
->sh_type
== SHT_REL
)
8815 if (!slurp_rel_relocs (aux
->filedata
, relsec
->sh_offset
,
8817 & arm_sec
->rela
, & arm_sec
->nrelas
))
8820 else /* relsec->sh_type == SHT_RELA */
8822 if (!slurp_rela_relocs (aux
->filedata
, relsec
->sh_offset
,
8824 & arm_sec
->rela
, & arm_sec
->nrelas
))
8830 arm_sec
->next_rela
= arm_sec
->rela
;
8833 /* If there is no unwind data we can do nothing. */
8834 if (arm_sec
->data
== NULL
)
8837 /* If the offset is invalid then fail. */
8838 if (/* PR 21343 *//* PR 18879 */
8840 || word_offset
> (sec
->sh_size
- 4)
8841 || ((bfd_signed_vma
) word_offset
) < 0)
8844 /* Get the word at the required offset. */
8845 word
= byte_get (arm_sec
->data
+ word_offset
, 4);
8847 /* PR 17531: file: id:000001,src:001266+003044,op:splice,rep:128. */
8848 if (arm_sec
->rela
== NULL
)
8854 /* Look through the relocs to find the one that applies to the provided offset. */
8856 for (rp
= arm_sec
->next_rela
; rp
!= arm_sec
->rela
+ arm_sec
->nrelas
; rp
++)
8858 bfd_vma prelval
, offset
;
8860 if (rp
->r_offset
> word_offset
&& !wrapped
)
8865 if (rp
->r_offset
> word_offset
)
8868 if (rp
->r_offset
& 3)
8870 warn (_("Skipping unexpected relocation at offset 0x%lx\n"),
8871 (unsigned long) rp
->r_offset
);
8875 if (rp
->r_offset
< word_offset
)
8878 /* PR 17531: file: 027-161405-0.004 */
8879 if (aux
->symtab
== NULL
)
8882 if (arm_sec
->rel_type
== SHT_REL
)
8884 offset
= word
& 0x7fffffff;
8885 if (offset
& 0x40000000)
8886 offset
|= ~ (bfd_vma
) 0x7fffffff;
8888 else if (arm_sec
->rel_type
== SHT_RELA
)
8889 offset
= rp
->r_addend
;
8892 error (_("Unknown section relocation type %d encountered\n"),
8897 /* PR 17531 file: 027-1241568-0.004. */
8898 if (ELF32_R_SYM (rp
->r_info
) >= aux
->nsyms
)
8900 error (_("Bad symbol index in unwind relocation (%lu > %lu)\n"),
8901 (unsigned long) ELF32_R_SYM (rp
->r_info
), aux
->nsyms
);
8905 sym
= aux
->symtab
+ ELF32_R_SYM (rp
->r_info
);
8906 offset
+= sym
->st_value
;
8907 prelval
= offset
- (arm_sec
->sec
->sh_addr
+ rp
->r_offset
);
8909 /* Check that we are processing the expected reloc type. */
8910 if (filedata
->file_header
.e_machine
== EM_ARM
)
8912 relname
= elf_arm_reloc_type (ELF32_R_TYPE (rp
->r_info
));
8913 if (relname
== NULL
)
8915 warn (_("Skipping unknown ARM relocation type: %d\n"),
8916 (int) ELF32_R_TYPE (rp
->r_info
));
8920 if (streq (relname
, "R_ARM_NONE"))
8923 if (! streq (relname
, "R_ARM_PREL31"))
8925 warn (_("Skipping unexpected ARM relocation type %s\n"), relname
);
8929 else if (filedata
->file_header
.e_machine
== EM_TI_C6000
)
8931 relname
= elf_tic6x_reloc_type (ELF32_R_TYPE (rp
->r_info
));
8932 if (relname
== NULL
)
8934 warn (_("Skipping unknown C6000 relocation type: %d\n"),
8935 (int) ELF32_R_TYPE (rp
->r_info
));
8939 if (streq (relname
, "R_C6000_NONE"))
8942 if (! streq (relname
, "R_C6000_PREL31"))
8944 warn (_("Skipping unexpected C6000 relocation type %s\n"), relname
);
8952 /* This function currently only supports ARM and TI unwinders. */
8953 warn (_("Only TI and ARM unwinders are currently supported\n"));
8957 word
= (word
& ~ (bfd_vma
) 0x7fffffff) | (prelval
& 0x7fffffff);
8958 addr
->section
= sym
->st_shndx
;
8959 addr
->offset
= offset
;
8962 * sym_name
= sym
->st_name
;
8967 arm_sec
->next_rela
= rp
;
8972 static const char *tic6x_unwind_regnames
[16] =
8974 "A15", "B15", "B14", "B13", "B12", "B11", "B10", "B3",
8975 "A14", "A13", "A12", "A11", "A10",
8976 "[invalid reg 13]", "[invalid reg 14]", "[invalid reg 15]"
8980 decode_tic6x_unwind_regmask (unsigned int mask
)
8984 for (i
= 12; mask
; mask
>>= 1, i
--)
8988 fputs (tic6x_unwind_regnames
[i
], stdout
);
8990 fputs (", ", stdout
);
8996 if (remaining == 0 && more_words) \
8999 if (! get_unwind_section_word (filedata, aux, data_arm_sec, data_sec, \
9000 data_offset, & word, & addr, NULL)) \
9006 #define GET_OP(OP) \
9011 (OP) = word >> 24; \
9016 printf (_("[Truncated opcode]\n")); \
9019 printf ("0x%02x ", OP)
9022 decode_arm_unwind_bytecode (Filedata
* filedata
,
9023 struct arm_unw_aux_info
* aux
,
9025 unsigned int remaining
,
9026 unsigned int more_words
,
9027 bfd_vma data_offset
,
9028 Elf_Internal_Shdr
* data_sec
,
9029 struct arm_section
* data_arm_sec
)
9031 struct absaddr addr
;
9032 bfd_boolean res
= TRUE
;
9034 /* Decode the unwinding instructions. */
9037 unsigned int op
, op2
;
9046 printf (" 0x%02x ", op
);
9048 if ((op
& 0xc0) == 0x00)
9050 int offset
= ((op
& 0x3f) << 2) + 4;
9052 printf (" vsp = vsp + %d", offset
);
9054 else if ((op
& 0xc0) == 0x40)
9056 int offset
= ((op
& 0x3f) << 2) + 4;
9058 printf (" vsp = vsp - %d", offset
);
9060 else if ((op
& 0xf0) == 0x80)
9063 if (op
== 0x80 && op2
== 0)
9064 printf (_("Refuse to unwind"));
9067 unsigned int mask
= ((op
& 0x0f) << 8) | op2
;
9068 bfd_boolean first
= TRUE
;
9072 for (i
= 0; i
< 12; i
++)
9073 if (mask
& (1 << i
))
9079 printf ("r%d", 4 + i
);
9084 else if ((op
& 0xf0) == 0x90)
9086 if (op
== 0x9d || op
== 0x9f)
9087 printf (_(" [Reserved]"));
9089 printf (" vsp = r%d", op
& 0x0f);
9091 else if ((op
& 0xf0) == 0xa0)
9093 int end
= 4 + (op
& 0x07);
9094 bfd_boolean first
= TRUE
;
9098 for (i
= 4; i
<= end
; i
++)
9114 else if (op
== 0xb0)
9115 printf (_(" finish"));
9116 else if (op
== 0xb1)
9119 if (op2
== 0 || (op2
& 0xf0) != 0)
9120 printf (_("[Spare]"));
9123 unsigned int mask
= op2
& 0x0f;
9124 bfd_boolean first
= TRUE
;
9128 for (i
= 0; i
< 12; i
++)
9129 if (mask
& (1 << i
))
9140 else if (op
== 0xb2)
9142 unsigned char buf
[9];
9143 unsigned int i
, len
;
9144 unsigned long offset
;
9146 for (i
= 0; i
< sizeof (buf
); i
++)
9149 if ((buf
[i
] & 0x80) == 0)
9152 if (i
== sizeof (buf
))
9154 error (_("corrupt change to vsp\n"));
9159 offset
= read_leb128 (buf
, buf
+ i
+ 1, FALSE
, &len
, NULL
);
9160 assert (len
== i
+ 1);
9161 offset
= offset
* 4 + 0x204;
9162 printf ("vsp = vsp + %ld", offset
);
9165 else if (op
== 0xb3 || op
== 0xc8 || op
== 0xc9)
9167 unsigned int first
, last
;
9174 printf ("pop {D%d", first
);
9176 printf ("-D%d", first
+ last
);
9179 else if ((op
& 0xf8) == 0xb8 || (op
& 0xf8) == 0xd0)
9181 unsigned int count
= op
& 0x07;
9185 printf ("-D%d", 8 + count
);
9188 else if (op
>= 0xc0 && op
<= 0xc5)
9190 unsigned int count
= op
& 0x07;
9192 printf (" pop {wR10");
9194 printf ("-wR%d", 10 + count
);
9197 else if (op
== 0xc6)
9199 unsigned int first
, last
;
9204 printf ("pop {wR%d", first
);
9206 printf ("-wR%d", first
+ last
);
9209 else if (op
== 0xc7)
9212 if (op2
== 0 || (op2
& 0xf0) != 0)
9213 printf (_("[Spare]"));
9216 unsigned int mask
= op2
& 0x0f;
9217 bfd_boolean first
= TRUE
;
9221 for (i
= 0; i
< 4; i
++)
9222 if (mask
& (1 << i
))
9228 printf ("wCGR%d", i
);
9235 printf (_(" [unsupported opcode]"));
9246 decode_tic6x_unwind_bytecode (Filedata
* filedata
,
9247 struct arm_unw_aux_info
* aux
,
9249 unsigned int remaining
,
9250 unsigned int more_words
,
9251 bfd_vma data_offset
,
9252 Elf_Internal_Shdr
* data_sec
,
9253 struct arm_section
* data_arm_sec
)
9255 struct absaddr addr
;
9257 /* Decode the unwinding instructions. */
9260 unsigned int op
, op2
;
9269 printf (" 0x%02x ", op
);
9271 if ((op
& 0xc0) == 0x00)
9273 int offset
= ((op
& 0x3f) << 3) + 8;
9274 printf (" sp = sp + %d", offset
);
9276 else if ((op
& 0xc0) == 0x80)
9279 if (op
== 0x80 && op2
== 0)
9280 printf (_("Refuse to unwind"));
9283 unsigned int mask
= ((op
& 0x1f) << 8) | op2
;
9285 printf ("pop compact {");
9289 decode_tic6x_unwind_regmask (mask
);
9293 else if ((op
& 0xf0) == 0xc0)
9301 unsigned int offset
;
9305 /* Scan entire instruction first so that GET_OP output is not
9306 interleaved with disassembly. */
9308 for (i
= 0; nregs
< (op
& 0xf); i
++)
9314 regpos
[nregs
].offset
= i
* 2;
9315 regpos
[nregs
].reg
= reg
;
9322 regpos
[nregs
].offset
= i
* 2 + 1;
9323 regpos
[nregs
].reg
= reg
;
9328 printf (_("pop frame {"));
9331 printf (_("*corrupt* - no registers specified"));
9336 for (i
= i
* 2; i
> 0; i
--)
9338 if (regpos
[reg
].offset
== i
- 1)
9340 name
= tic6x_unwind_regnames
[regpos
[reg
].reg
];
9347 fputs (name
, stdout
);
9355 else if (op
== 0xd0)
9356 printf (" MOV FP, SP");
9357 else if (op
== 0xd1)
9358 printf (" __c6xabi_pop_rts");
9359 else if (op
== 0xd2)
9361 unsigned char buf
[9];
9362 unsigned int i
, len
;
9363 unsigned long offset
;
9365 for (i
= 0; i
< sizeof (buf
); i
++)
9368 if ((buf
[i
] & 0x80) == 0)
9371 /* PR 17531: file: id:000001,src:001906+004739,op:splice,rep:2. */
9372 if (i
== sizeof (buf
))
9374 warn (_("Corrupt stack pointer adjustment detected\n"));
9378 offset
= read_leb128 (buf
, buf
+ i
+ 1, FALSE
, &len
, NULL
);
9379 assert (len
== i
+ 1);
9380 offset
= offset
* 8 + 0x408;
9381 printf (_("sp = sp + %ld"), offset
);
9383 else if ((op
& 0xf0) == 0xe0)
9385 if ((op
& 0x0f) == 7)
9388 printf (" MV %s, B3", tic6x_unwind_regnames
[op
& 0x0f]);
9392 printf (_(" [unsupported opcode]"));
9401 arm_expand_prel31 (Filedata
* filedata
, bfd_vma word
, bfd_vma where
)
9405 offset
= word
& 0x7fffffff;
9406 if (offset
& 0x40000000)
9407 offset
|= ~ (bfd_vma
) 0x7fffffff;
9409 if (filedata
->file_header
.e_machine
== EM_TI_C6000
)
9412 return offset
+ where
;
9416 decode_arm_unwind (Filedata
* filedata
,
9417 struct arm_unw_aux_info
* aux
,
9419 unsigned int remaining
,
9420 bfd_vma data_offset
,
9421 Elf_Internal_Shdr
* data_sec
,
9422 struct arm_section
* data_arm_sec
)
9425 unsigned int more_words
= 0;
9426 struct absaddr addr
;
9427 bfd_vma sym_name
= (bfd_vma
) -1;
9428 bfd_boolean res
= TRUE
;
9432 /* Fetch the first word.
9433 Note - when decoding an object file the address extracted
9434 here will always be 0. So we also pass in the sym_name
9435 parameter so that we can find the symbol associated with
9436 the personality routine. */
9437 if (! get_unwind_section_word (filedata
, aux
, data_arm_sec
, data_sec
, data_offset
,
9438 & word
, & addr
, & sym_name
))
9445 addr
.section
= SHN_UNDEF
;
9449 if ((word
& 0x80000000) == 0)
9451 /* Expand prel31 for personality routine. */
9453 const char *procname
;
9455 fn
= arm_expand_prel31 (filedata
, word
, data_sec
->sh_addr
+ data_offset
);
9456 printf (_(" Personality routine: "));
9458 && addr
.section
== SHN_UNDEF
&& addr
.offset
== 0
9459 && sym_name
!= (bfd_vma
) -1 && sym_name
< aux
->strtab_size
)
9461 procname
= aux
->strtab
+ sym_name
;
9462 print_vma (fn
, PREFIX_HEX
);
9465 fputs (" <", stdout
);
9466 fputs (procname
, stdout
);
9467 fputc ('>', stdout
);
9471 procname
= arm_print_vma_and_name (filedata
, aux
, fn
, addr
);
9472 fputc ('\n', stdout
);
9474 /* The GCC personality routines use the standard compact
9475 encoding, starting with one byte giving the number of
9477 if (procname
!= NULL
9478 && (const_strneq (procname
, "__gcc_personality_v0")
9479 || const_strneq (procname
, "__gxx_personality_v0")
9480 || const_strneq (procname
, "__gcj_personality_v0")
9481 || const_strneq (procname
, "__gnu_objc_personality_v0")))
9488 printf (_(" [Truncated data]\n"));
9491 more_words
= word
>> 24;
9501 /* ARM EHABI Section 6.3:
9503 An exception-handling table entry for the compact model looks like:
9507 1 0 index Data for personalityRoutine[index] */
9509 if (filedata
->file_header
.e_machine
== EM_ARM
9510 && (word
& 0x70000000))
9512 warn (_("Corrupt ARM compact model table entry: %x \n"), word
);
9516 per_index
= (word
>> 24) & 0x7f;
9517 printf (_(" Compact model index: %d\n"), per_index
);
9524 else if (per_index
< 3)
9526 more_words
= (word
>> 16) & 0xff;
9532 switch (filedata
->file_header
.e_machine
)
9537 if (! decode_arm_unwind_bytecode (filedata
, aux
, word
, remaining
, more_words
,
9538 data_offset
, data_sec
, data_arm_sec
))
9543 warn (_("Unknown ARM compact model index encountered\n"));
9544 printf (_(" [reserved]\n"));
9552 if (! decode_tic6x_unwind_bytecode (filedata
, aux
, word
, remaining
, more_words
,
9553 data_offset
, data_sec
, data_arm_sec
))
9556 else if (per_index
< 5)
9558 if (((word
>> 17) & 0x7f) == 0x7f)
9559 printf (_(" Restore stack from frame pointer\n"));
9561 printf (_(" Stack increment %d\n"), (word
>> 14) & 0x1fc);
9562 printf (_(" Registers restored: "));
9564 printf (" (compact) ");
9565 decode_tic6x_unwind_regmask ((word
>> 4) & 0x1fff);
9567 printf (_(" Return register: %s\n"),
9568 tic6x_unwind_regnames
[word
& 0xf]);
9571 printf (_(" [reserved (%d)]\n"), per_index
);
9575 error (_("Unsupported architecture type %d encountered when decoding unwind table\n"),
9576 filedata
->file_header
.e_machine
);
9580 /* Decode the descriptors. Not implemented. */
9586 dump_arm_unwind (Filedata
* filedata
,
9587 struct arm_unw_aux_info
* aux
,
9588 Elf_Internal_Shdr
* exidx_sec
)
9590 struct arm_section exidx_arm_sec
, extab_arm_sec
;
9591 unsigned int i
, exidx_len
;
9592 unsigned long j
, nfuns
;
9593 bfd_boolean res
= TRUE
;
9595 memset (&exidx_arm_sec
, 0, sizeof (exidx_arm_sec
));
9596 memset (&extab_arm_sec
, 0, sizeof (extab_arm_sec
));
9597 exidx_len
= exidx_sec
->sh_size
/ 8;
9599 aux
->funtab
= xmalloc (aux
->nsyms
* sizeof (Elf_Internal_Sym
));
9600 for (nfuns
= 0, j
= 0; j
< aux
->nsyms
; j
++)
9601 if (aux
->symtab
[j
].st_value
&& ELF_ST_TYPE (aux
->symtab
[j
].st_info
) == STT_FUNC
)
9602 aux
->funtab
[nfuns
++] = aux
->symtab
[j
];
9604 qsort (aux
->funtab
, aux
->nfuns
, sizeof (Elf_Internal_Sym
), symcmp
);
9606 for (i
= 0; i
< exidx_len
; i
++)
9608 unsigned int exidx_fn
, exidx_entry
;
9609 struct absaddr fn_addr
, entry_addr
;
9612 fputc ('\n', stdout
);
9614 if (! get_unwind_section_word (filedata
, aux
, & exidx_arm_sec
, exidx_sec
,
9615 8 * i
, & exidx_fn
, & fn_addr
, NULL
)
9616 || ! get_unwind_section_word (filedata
, aux
, & exidx_arm_sec
, exidx_sec
,
9617 8 * i
+ 4, & exidx_entry
, & entry_addr
, NULL
))
9620 arm_free_section (& exidx_arm_sec
);
9621 arm_free_section (& extab_arm_sec
);
9625 /* ARM EHABI, Section 5:
9626 An index table entry consists of 2 words.
9627 The first word contains a prel31 offset to the start of a function, with bit 31 clear. */
9628 if (exidx_fn
& 0x80000000)
9630 warn (_("corrupt index table entry: %x\n"), exidx_fn
);
9634 fn
= arm_expand_prel31 (filedata
, exidx_fn
, exidx_sec
->sh_addr
+ 8 * i
);
9636 arm_print_vma_and_name (filedata
, aux
, fn
, fn_addr
);
9637 fputs (": ", stdout
);
9639 if (exidx_entry
== 1)
9641 print_vma (exidx_entry
, PREFIX_HEX
);
9642 fputs (" [cantunwind]\n", stdout
);
9644 else if (exidx_entry
& 0x80000000)
9646 print_vma (exidx_entry
, PREFIX_HEX
);
9647 fputc ('\n', stdout
);
9648 decode_arm_unwind (filedata
, aux
, exidx_entry
, 4, 0, NULL
, NULL
);
9652 bfd_vma table
, table_offset
= 0;
9653 Elf_Internal_Shdr
*table_sec
;
9655 fputs ("@", stdout
);
9656 table
= arm_expand_prel31 (filedata
, exidx_entry
, exidx_sec
->sh_addr
+ 8 * i
+ 4);
9657 print_vma (table
, PREFIX_HEX
);
9660 /* Locate the matching .ARM.extab. */
9661 if (entry_addr
.section
!= SHN_UNDEF
9662 && entry_addr
.section
< filedata
->file_header
.e_shnum
)
9664 table_sec
= filedata
->section_headers
+ entry_addr
.section
;
9665 table_offset
= entry_addr
.offset
;
9667 if (table_offset
> table_sec
->sh_size
9668 || ((bfd_signed_vma
) table_offset
) < 0)
9670 warn (_("Unwind entry contains corrupt offset (0x%lx) into section %s\n"),
9671 (unsigned long) table_offset
,
9672 printable_section_name (filedata
, table_sec
));
9679 table_sec
= find_section_by_address (filedata
, table
);
9680 if (table_sec
!= NULL
)
9681 table_offset
= table
- table_sec
->sh_addr
;
9684 if (table_sec
== NULL
)
9686 warn (_("Could not locate .ARM.extab section containing 0x%lx.\n"),
9687 (unsigned long) table
);
9692 if (! decode_arm_unwind (filedata
, aux
, 0, 0, table_offset
, table_sec
,
9701 arm_free_section (&exidx_arm_sec
);
9702 arm_free_section (&extab_arm_sec
);
9707 /* Used for both ARM and C6X unwinding tables. */
9710 arm_process_unwind (Filedata
* filedata
)
9712 struct arm_unw_aux_info aux
;
9713 Elf_Internal_Shdr
*unwsec
= NULL
;
9714 Elf_Internal_Shdr
*sec
;
9716 unsigned int sec_type
;
9717 bfd_boolean res
= TRUE
;
9719 switch (filedata
->file_header
.e_machine
)
9722 sec_type
= SHT_ARM_EXIDX
;
9726 sec_type
= SHT_C6000_UNWIND
;
9730 error (_("Unsupported architecture type %d encountered when processing unwind table\n"),
9731 filedata
->file_header
.e_machine
);
9735 if (filedata
->string_table
== NULL
)
9738 memset (& aux
, 0, sizeof (aux
));
9739 aux
.filedata
= filedata
;
9741 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
9743 if (sec
->sh_type
== SHT_SYMTAB
)
9747 error (_("Multiple symbol tables encountered\n"));
9753 if (!get_symtab (filedata
, sec
, &aux
.symtab
, &aux
.nsyms
,
9754 &aux
.strtab
, &aux
.strtab_size
))
9757 else if (sec
->sh_type
== sec_type
)
9762 printf (_("\nThere are no unwind sections in this file.\n"));
9764 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
9766 if (sec
->sh_type
== sec_type
)
9768 unsigned long num_unwind
= sec
->sh_size
/ (2 * eh_addr_size
);
9769 printf (ngettext ("\nUnwind section '%s' at offset 0x%lx "
9770 "contains %lu entry:\n",
9771 "\nUnwind section '%s' at offset 0x%lx "
9772 "contains %lu entries:\n",
9774 printable_section_name (filedata
, sec
),
9775 (unsigned long) sec
->sh_offset
,
9778 if (! dump_arm_unwind (filedata
, &aux
, sec
))
9784 free ((char *) aux
.strtab
);
9790 process_unwind (Filedata
* filedata
)
9792 struct unwind_handler
9794 unsigned int machtype
;
9795 bfd_boolean (* handler
)(Filedata
*);
9798 { EM_ARM
, arm_process_unwind
},
9799 { EM_IA_64
, ia64_process_unwind
},
9800 { EM_PARISC
, hppa_process_unwind
},
9801 { EM_TI_C6000
, arm_process_unwind
},
9809 for (i
= 0; handlers
[i
].handler
!= NULL
; i
++)
9810 if (filedata
->file_header
.e_machine
== handlers
[i
].machtype
)
9811 return handlers
[i
].handler (filedata
);
9813 printf (_("\nThe decoding of unwind sections for machine type %s is not currently supported.\n"),
9814 get_machine_name (filedata
->file_header
.e_machine
));
9819 dynamic_section_aarch64_val (Elf_Internal_Dyn
* entry
)
9821 switch (entry
->d_tag
)
9823 case DT_AARCH64_BTI_PLT
:
9824 case DT_AARCH64_PAC_PLT
:
9827 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
9834 dynamic_section_mips_val (Filedata
* filedata
, Elf_Internal_Dyn
* entry
)
9836 switch (entry
->d_tag
)
9839 if (entry
->d_un
.d_val
== 0)
9843 static const char * opts
[] =
9845 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
9846 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
9847 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
9848 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
9852 bfd_boolean first
= TRUE
;
9854 for (cnt
= 0; cnt
< ARRAY_SIZE (opts
); ++cnt
)
9855 if (entry
->d_un
.d_val
& (1 << cnt
))
9857 printf ("%s%s", first
? "" : " ", opts
[cnt
]);
9863 case DT_MIPS_IVERSION
:
9864 if (VALID_DYNAMIC_NAME (filedata
, entry
->d_un
.d_val
))
9865 printf (_("Interface Version: %s"),
9866 GET_DYNAMIC_NAME (filedata
, entry
->d_un
.d_val
));
9870 sprintf_vma (buf
, entry
->d_un
.d_ptr
);
9871 /* Note: coded this way so that there is a single string for translation. */
9872 printf (_("<corrupt: %s>"), buf
);
9876 case DT_MIPS_TIME_STAMP
:
9880 time_t atime
= entry
->d_un
.d_val
;
9882 tmp
= gmtime (&atime
);
9883 /* PR 17531: file: 6accc532. */
9885 snprintf (timebuf
, sizeof (timebuf
), _("<corrupt>"));
9887 snprintf (timebuf
, sizeof (timebuf
), "%04u-%02u-%02uT%02u:%02u:%02u",
9888 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
9889 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
9890 printf (_("Time Stamp: %s"), timebuf
);
9894 case DT_MIPS_RLD_VERSION
:
9895 case DT_MIPS_LOCAL_GOTNO
:
9896 case DT_MIPS_CONFLICTNO
:
9897 case DT_MIPS_LIBLISTNO
:
9898 case DT_MIPS_SYMTABNO
:
9899 case DT_MIPS_UNREFEXTNO
:
9900 case DT_MIPS_HIPAGENO
:
9901 case DT_MIPS_DELTA_CLASS_NO
:
9902 case DT_MIPS_DELTA_INSTANCE_NO
:
9903 case DT_MIPS_DELTA_RELOC_NO
:
9904 case DT_MIPS_DELTA_SYM_NO
:
9905 case DT_MIPS_DELTA_CLASSSYM_NO
:
9906 case DT_MIPS_COMPACT_SIZE
:
9907 print_vma (entry
->d_un
.d_val
, DEC
);
9911 filedata
->dynamic_info_DT_MIPS_XHASH
= entry
->d_un
.d_val
;
9912 filedata
->dynamic_info_DT_GNU_HASH
= entry
->d_un
.d_val
;
9913 /* Falls through. */
9916 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
9922 dynamic_section_parisc_val (Elf_Internal_Dyn
* entry
)
9924 switch (entry
->d_tag
)
9926 case DT_HP_DLD_FLAGS
:
9935 { DT_HP_DEBUG_PRIVATE
, "HP_DEBUG_PRIVATE" },
9936 { DT_HP_DEBUG_CALLBACK
, "HP_DEBUG_CALLBACK" },
9937 { DT_HP_DEBUG_CALLBACK_BOR
, "HP_DEBUG_CALLBACK_BOR" },
9938 { DT_HP_NO_ENVVAR
, "HP_NO_ENVVAR" },
9939 { DT_HP_BIND_NOW
, "HP_BIND_NOW" },
9940 { DT_HP_BIND_NONFATAL
, "HP_BIND_NONFATAL" },
9941 { DT_HP_BIND_VERBOSE
, "HP_BIND_VERBOSE" },
9942 { DT_HP_BIND_RESTRICTED
, "HP_BIND_RESTRICTED" },
9943 { DT_HP_BIND_SYMBOLIC
, "HP_BIND_SYMBOLIC" },
9944 { DT_HP_RPATH_FIRST
, "HP_RPATH_FIRST" },
9945 { DT_HP_BIND_DEPTH_FIRST
, "HP_BIND_DEPTH_FIRST" },
9946 { DT_HP_GST
, "HP_GST" },
9947 { DT_HP_SHLIB_FIXED
, "HP_SHLIB_FIXED" },
9948 { DT_HP_MERGE_SHLIB_SEG
, "HP_MERGE_SHLIB_SEG" },
9949 { DT_HP_NODELETE
, "HP_NODELETE" },
9950 { DT_HP_GROUP
, "HP_GROUP" },
9951 { DT_HP_PROTECT_LINKAGE_TABLE
, "HP_PROTECT_LINKAGE_TABLE" }
9953 bfd_boolean first
= TRUE
;
9955 bfd_vma val
= entry
->d_un
.d_val
;
9957 for (cnt
= 0; cnt
< ARRAY_SIZE (flags
); ++cnt
)
9958 if (val
& flags
[cnt
].bit
)
9962 fputs (flags
[cnt
].str
, stdout
);
9964 val
^= flags
[cnt
].bit
;
9967 if (val
!= 0 || first
)
9971 print_vma (val
, HEX
);
9977 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
9985 /* VMS vs Unix time offset and factor. */
9987 #define VMS_EPOCH_OFFSET 35067168000000000LL
9988 #define VMS_GRANULARITY_FACTOR 10000000
9990 #define INT64_MIN (-9223372036854775807LL - 1)
9993 /* Display a VMS time in a human readable format. */
9996 print_vms_time (bfd_int64_t vmstime
)
9998 struct tm
*tm
= NULL
;
10001 if (vmstime
>= INT64_MIN
+ VMS_EPOCH_OFFSET
)
10003 vmstime
= (vmstime
- VMS_EPOCH_OFFSET
) / VMS_GRANULARITY_FACTOR
;
10005 if (unxtime
== vmstime
)
10006 tm
= gmtime (&unxtime
);
10009 printf ("%04u-%02u-%02uT%02u:%02u:%02u",
10010 tm
->tm_year
+ 1900, tm
->tm_mon
+ 1, tm
->tm_mday
,
10011 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
);
10016 dynamic_section_ia64_val (Elf_Internal_Dyn
* entry
)
10018 switch (entry
->d_tag
)
10020 case DT_IA_64_PLT_RESERVE
:
10021 /* First 3 slots reserved. */
10022 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
10024 print_vma (entry
->d_un
.d_ptr
+ (3 * 8), PREFIX_HEX
);
10027 case DT_IA_64_VMS_LINKTIME
:
10029 print_vms_time (entry
->d_un
.d_val
);
10033 case DT_IA_64_VMS_LNKFLAGS
:
10034 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
10035 if (entry
->d_un
.d_val
& VMS_LF_CALL_DEBUG
)
10036 printf (" CALL_DEBUG");
10037 if (entry
->d_un
.d_val
& VMS_LF_NOP0BUFS
)
10038 printf (" NOP0BUFS");
10039 if (entry
->d_un
.d_val
& VMS_LF_P0IMAGE
)
10040 printf (" P0IMAGE");
10041 if (entry
->d_un
.d_val
& VMS_LF_MKTHREADS
)
10042 printf (" MKTHREADS");
10043 if (entry
->d_un
.d_val
& VMS_LF_UPCALLS
)
10044 printf (" UPCALLS");
10045 if (entry
->d_un
.d_val
& VMS_LF_IMGSTA
)
10046 printf (" IMGSTA");
10047 if (entry
->d_un
.d_val
& VMS_LF_INITIALIZE
)
10048 printf (" INITIALIZE");
10049 if (entry
->d_un
.d_val
& VMS_LF_MAIN
)
10051 if (entry
->d_un
.d_val
& VMS_LF_EXE_INIT
)
10052 printf (" EXE_INIT");
10053 if (entry
->d_un
.d_val
& VMS_LF_TBK_IN_IMG
)
10054 printf (" TBK_IN_IMG");
10055 if (entry
->d_un
.d_val
& VMS_LF_DBG_IN_IMG
)
10056 printf (" DBG_IN_IMG");
10057 if (entry
->d_un
.d_val
& VMS_LF_TBK_IN_DSF
)
10058 printf (" TBK_IN_DSF");
10059 if (entry
->d_un
.d_val
& VMS_LF_DBG_IN_DSF
)
10060 printf (" DBG_IN_DSF");
10061 if (entry
->d_un
.d_val
& VMS_LF_SIGNATURES
)
10062 printf (" SIGNATURES");
10063 if (entry
->d_un
.d_val
& VMS_LF_REL_SEG_OFF
)
10064 printf (" REL_SEG_OFF");
10068 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
10075 get_32bit_dynamic_section (Filedata
* filedata
)
10077 Elf32_External_Dyn
* edyn
;
10078 Elf32_External_Dyn
* ext
;
10079 Elf_Internal_Dyn
* entry
;
10081 edyn
= (Elf32_External_Dyn
*) get_data (NULL
, filedata
,
10082 filedata
->dynamic_addr
, 1,
10083 filedata
->dynamic_size
,
10084 _("dynamic section"));
10088 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
10089 might not have the luxury of section headers. Look for the DT_NULL
10090 terminator to determine the number of entries. */
10091 for (ext
= edyn
, filedata
->dynamic_nent
= 0;
10092 (char *) (ext
+ 1) <= (char *) edyn
+ filedata
->dynamic_size
;
10095 filedata
->dynamic_nent
++;
10096 if (BYTE_GET (ext
->d_tag
) == DT_NULL
)
10100 filedata
->dynamic_section
10101 = (Elf_Internal_Dyn
*) cmalloc (filedata
->dynamic_nent
, sizeof (* entry
));
10102 if (filedata
->dynamic_section
== NULL
)
10104 error (_("Out of memory allocating space for %lu dynamic entries\n"),
10105 (unsigned long) filedata
->dynamic_nent
);
10110 for (ext
= edyn
, entry
= filedata
->dynamic_section
;
10111 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
10114 entry
->d_tag
= BYTE_GET (ext
->d_tag
);
10115 entry
->d_un
.d_val
= BYTE_GET (ext
->d_un
.d_val
);
10124 get_64bit_dynamic_section (Filedata
* filedata
)
10126 Elf64_External_Dyn
* edyn
;
10127 Elf64_External_Dyn
* ext
;
10128 Elf_Internal_Dyn
* entry
;
10130 /* Read in the data. */
10131 edyn
= (Elf64_External_Dyn
*) get_data (NULL
, filedata
,
10132 filedata
->dynamic_addr
, 1,
10133 filedata
->dynamic_size
,
10134 _("dynamic section"));
10138 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
10139 might not have the luxury of section headers. Look for the DT_NULL
10140 terminator to determine the number of entries. */
10141 for (ext
= edyn
, filedata
->dynamic_nent
= 0;
10142 /* PR 17533 file: 033-67080-0.004 - do not read past end of buffer. */
10143 (char *) (ext
+ 1) <= (char *) edyn
+ filedata
->dynamic_size
;
10146 filedata
->dynamic_nent
++;
10147 if (BYTE_GET (ext
->d_tag
) == DT_NULL
)
10151 filedata
->dynamic_section
10152 = (Elf_Internal_Dyn
*) cmalloc (filedata
->dynamic_nent
, sizeof (* entry
));
10153 if (filedata
->dynamic_section
== NULL
)
10155 error (_("Out of memory allocating space for %lu dynamic entries\n"),
10156 (unsigned long) filedata
->dynamic_nent
);
10161 /* Convert from external to internal formats. */
10162 for (ext
= edyn
, entry
= filedata
->dynamic_section
;
10163 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
10166 entry
->d_tag
= BYTE_GET (ext
->d_tag
);
10167 entry
->d_un
.d_val
= BYTE_GET (ext
->d_un
.d_val
);
10176 print_dynamic_flags (bfd_vma flags
)
10178 bfd_boolean first
= TRUE
;
10184 flag
= flags
& - flags
;
10190 putc (' ', stdout
);
10194 case DF_ORIGIN
: fputs ("ORIGIN", stdout
); break;
10195 case DF_SYMBOLIC
: fputs ("SYMBOLIC", stdout
); break;
10196 case DF_TEXTREL
: fputs ("TEXTREL", stdout
); break;
10197 case DF_BIND_NOW
: fputs ("BIND_NOW", stdout
); break;
10198 case DF_STATIC_TLS
: fputs ("STATIC_TLS", stdout
); break;
10199 default: fputs (_("unknown"), stdout
); break;
10206 get_dynamic_data (Filedata
* filedata
, bfd_size_type number
, unsigned int ent_size
)
10208 unsigned char * e_data
;
10211 /* If the size_t type is smaller than the bfd_size_type, eg because
10212 you are building a 32-bit tool on a 64-bit host, then make sure
10213 that when (number) is cast to (size_t) no information is lost. */
10214 if (sizeof (size_t) < sizeof (bfd_size_type
)
10215 && (bfd_size_type
) ((size_t) number
) != number
)
10217 error (_("Size truncation prevents reading %s elements of size %u\n"),
10218 bfd_vmatoa ("u", number
), ent_size
);
10222 /* Be kind to memory checkers (eg valgrind, address sanitizer) by not
10223 attempting to allocate memory when the read is bound to fail. */
10224 if (ent_size
* number
> filedata
->file_size
)
10226 error (_("Invalid number of dynamic entries: %s\n"),
10227 bfd_vmatoa ("u", number
));
10231 e_data
= (unsigned char *) cmalloc ((size_t) number
, ent_size
);
10232 if (e_data
== NULL
)
10234 error (_("Out of memory reading %s dynamic entries\n"),
10235 bfd_vmatoa ("u", number
));
10239 if (fread (e_data
, ent_size
, (size_t) number
, filedata
->handle
) != number
)
10241 error (_("Unable to read in %s bytes of dynamic data\n"),
10242 bfd_vmatoa ("u", number
* ent_size
));
10247 i_data
= (bfd_vma
*) cmalloc ((size_t) number
, sizeof (*i_data
));
10248 if (i_data
== NULL
)
10250 error (_("Out of memory allocating space for %s dynamic entries\n"),
10251 bfd_vmatoa ("u", number
));
10257 i_data
[number
] = byte_get (e_data
+ number
* ent_size
, ent_size
);
10264 static unsigned long
10265 get_num_dynamic_syms (Filedata
* filedata
)
10267 unsigned long num_of_syms
= 0;
10269 if (!do_histogram
&& (!do_using_dynamic
|| do_dyn_syms
))
10270 return num_of_syms
;
10272 if (filedata
->dynamic_info
[DT_HASH
])
10274 unsigned char nb
[8];
10275 unsigned char nc
[8];
10276 unsigned int hash_ent_size
= 4;
10278 if ((filedata
->file_header
.e_machine
== EM_ALPHA
10279 || filedata
->file_header
.e_machine
== EM_S390
10280 || filedata
->file_header
.e_machine
== EM_S390_OLD
)
10281 && filedata
->file_header
.e_ident
[EI_CLASS
] == ELFCLASS64
)
10284 if (fseek (filedata
->handle
,
10285 (filedata
->archive_file_offset
10286 + offset_from_vma (filedata
, filedata
->dynamic_info
[DT_HASH
],
10287 sizeof nb
+ sizeof nc
)),
10290 error (_("Unable to seek to start of dynamic information\n"));
10294 if (fread (nb
, hash_ent_size
, 1, filedata
->handle
) != 1)
10296 error (_("Failed to read in number of buckets\n"));
10300 if (fread (nc
, hash_ent_size
, 1, filedata
->handle
) != 1)
10302 error (_("Failed to read in number of chains\n"));
10306 filedata
->nbuckets
= byte_get (nb
, hash_ent_size
);
10307 filedata
->nchains
= byte_get (nc
, hash_ent_size
);
10309 if (filedata
->nbuckets
!= 0 && filedata
->nchains
!= 0)
10311 filedata
->buckets
= get_dynamic_data (filedata
, filedata
->nbuckets
,
10313 filedata
->chains
= get_dynamic_data (filedata
, filedata
->nchains
,
10316 if (filedata
->buckets
!= NULL
&& filedata
->chains
!= NULL
)
10317 num_of_syms
= filedata
->nchains
;
10320 if (num_of_syms
== 0)
10322 free (filedata
->buckets
);
10323 filedata
->buckets
= NULL
;
10324 free (filedata
->chains
);
10325 filedata
->chains
= NULL
;
10326 filedata
->nbuckets
= 0;
10330 if (filedata
->dynamic_info_DT_GNU_HASH
)
10332 unsigned char nb
[16];
10333 bfd_vma i
, maxchain
= 0xffffffff, bitmaskwords
;
10334 bfd_vma buckets_vma
;
10337 if (fseek (filedata
->handle
,
10338 (filedata
->archive_file_offset
10339 + offset_from_vma (filedata
,
10340 filedata
->dynamic_info_DT_GNU_HASH
,
10344 error (_("Unable to seek to start of dynamic information\n"));
10348 if (fread (nb
, 16, 1, filedata
->handle
) != 1)
10350 error (_("Failed to read in number of buckets\n"));
10354 filedata
->ngnubuckets
= byte_get (nb
, 4);
10355 filedata
->gnusymidx
= byte_get (nb
+ 4, 4);
10356 bitmaskwords
= byte_get (nb
+ 8, 4);
10357 buckets_vma
= filedata
->dynamic_info_DT_GNU_HASH
+ 16;
10359 buckets_vma
+= bitmaskwords
* 4;
10361 buckets_vma
+= bitmaskwords
* 8;
10363 if (fseek (filedata
->handle
,
10364 (filedata
->archive_file_offset
10365 + offset_from_vma (filedata
, buckets_vma
, 4)),
10368 error (_("Unable to seek to start of dynamic information\n"));
10372 filedata
->gnubuckets
10373 = get_dynamic_data (filedata
, filedata
->ngnubuckets
, 4);
10375 if (filedata
->gnubuckets
== NULL
)
10378 for (i
= 0; i
< filedata
->ngnubuckets
; i
++)
10379 if (filedata
->gnubuckets
[i
] != 0)
10381 if (filedata
->gnubuckets
[i
] < filedata
->gnusymidx
)
10384 if (maxchain
== 0xffffffff || filedata
->gnubuckets
[i
] > maxchain
)
10385 maxchain
= filedata
->gnubuckets
[i
];
10388 if (maxchain
== 0xffffffff)
10391 maxchain
-= filedata
->gnusymidx
;
10393 if (fseek (filedata
->handle
,
10394 (filedata
->archive_file_offset
10395 + offset_from_vma (filedata
,
10396 buckets_vma
+ 4 * (filedata
->ngnubuckets
10401 error (_("Unable to seek to start of dynamic information\n"));
10407 if (fread (nb
, 4, 1, filedata
->handle
) != 1)
10409 error (_("Failed to determine last chain length\n"));
10413 if (maxchain
+ 1 == 0)
10418 while ((byte_get (nb
, 4) & 1) == 0);
10420 if (fseek (filedata
->handle
,
10421 (filedata
->archive_file_offset
10422 + offset_from_vma (filedata
, (buckets_vma
10423 + 4 * filedata
->ngnubuckets
),
10427 error (_("Unable to seek to start of dynamic information\n"));
10431 filedata
->gnuchains
= get_dynamic_data (filedata
, maxchain
, 4);
10432 filedata
->ngnuchains
= maxchain
;
10434 if (filedata
->gnuchains
== NULL
)
10437 if (filedata
->dynamic_info_DT_MIPS_XHASH
)
10439 if (fseek (filedata
->handle
,
10440 (filedata
->archive_file_offset
10441 + offset_from_vma (filedata
, (buckets_vma
10442 + 4 * (filedata
->ngnubuckets
10446 error (_("Unable to seek to start of dynamic information\n"));
10450 filedata
->mipsxlat
= get_dynamic_data (filedata
, maxchain
, 4);
10451 if (filedata
->mipsxlat
== NULL
)
10455 for (hn
= 0; hn
< filedata
->ngnubuckets
; ++hn
)
10456 if (filedata
->gnubuckets
[hn
] != 0)
10458 bfd_vma si
= filedata
->gnubuckets
[hn
];
10459 bfd_vma off
= si
- filedata
->gnusymidx
;
10463 if (filedata
->dynamic_info_DT_MIPS_XHASH
)
10465 if (off
< filedata
->ngnuchains
10466 && filedata
->mipsxlat
[off
] >= num_of_syms
)
10467 num_of_syms
= filedata
->mipsxlat
[off
] + 1;
10471 if (si
>= num_of_syms
)
10472 num_of_syms
= si
+ 1;
10476 while (off
< filedata
->ngnuchains
10477 && (filedata
->gnuchains
[off
++] & 1) == 0);
10480 if (num_of_syms
== 0)
10483 free (filedata
->mipsxlat
);
10484 filedata
->mipsxlat
= NULL
;
10485 free (filedata
->gnuchains
);
10486 filedata
->gnuchains
= NULL
;
10487 free (filedata
->gnubuckets
);
10488 filedata
->gnubuckets
= NULL
;
10489 filedata
->ngnubuckets
= 0;
10490 filedata
->ngnuchains
= 0;
10494 return num_of_syms
;
10497 /* Parse and display the contents of the dynamic section. */
10500 process_dynamic_section (Filedata
* filedata
)
10502 Elf_Internal_Dyn
* entry
;
10504 if (filedata
->dynamic_size
== 0)
10508 if (filedata
->is_separate
)
10509 printf (_("\nThere is no dynamic section in linked file '%s'.\n"),
10510 filedata
->file_name
);
10512 printf (_("\nThere is no dynamic section in this file.\n"));
10520 if (! get_32bit_dynamic_section (filedata
))
10525 if (! get_64bit_dynamic_section (filedata
))
10529 /* Find the appropriate symbol table. */
10530 if (filedata
->dynamic_symbols
== NULL
|| do_histogram
)
10532 unsigned long num_of_syms
;
10534 for (entry
= filedata
->dynamic_section
;
10535 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
10537 if (entry
->d_tag
== DT_SYMTAB
)
10538 filedata
->dynamic_info
[DT_SYMTAB
] = entry
->d_un
.d_val
;
10539 else if (entry
->d_tag
== DT_SYMENT
)
10540 filedata
->dynamic_info
[DT_SYMENT
] = entry
->d_un
.d_val
;
10541 else if (entry
->d_tag
== DT_HASH
)
10542 filedata
->dynamic_info
[DT_HASH
] = entry
->d_un
.d_val
;
10543 else if (entry
->d_tag
== DT_GNU_HASH
)
10544 filedata
->dynamic_info_DT_GNU_HASH
= entry
->d_un
.d_val
;
10545 else if ((filedata
->file_header
.e_machine
== EM_MIPS
10546 || filedata
->file_header
.e_machine
== EM_MIPS_RS3_LE
)
10547 && entry
->d_tag
== DT_MIPS_XHASH
)
10549 filedata
->dynamic_info_DT_MIPS_XHASH
= entry
->d_un
.d_val
;
10550 filedata
->dynamic_info_DT_GNU_HASH
= entry
->d_un
.d_val
;
10553 num_of_syms
= get_num_dynamic_syms (filedata
);
10555 if (num_of_syms
!= 0
10556 && filedata
->dynamic_symbols
== NULL
10557 && filedata
->dynamic_info
[DT_SYMTAB
]
10558 && filedata
->dynamic_info
[DT_SYMENT
])
10560 Elf_Internal_Phdr
*seg
;
10561 bfd_vma vma
= filedata
->dynamic_info
[DT_SYMTAB
];
10563 if (! get_program_headers (filedata
))
10565 error (_("Cannot interpret virtual addresses "
10566 "without program headers.\n"));
10570 for (seg
= filedata
->program_headers
;
10571 seg
< filedata
->program_headers
+ filedata
->file_header
.e_phnum
;
10574 if (seg
->p_type
!= PT_LOAD
)
10577 if (seg
->p_offset
+ seg
->p_filesz
> filedata
->file_size
)
10579 /* See PR 21379 for a reproducer. */
10580 error (_("Invalid PT_LOAD entry\n"));
10584 if (vma
>= (seg
->p_vaddr
& -seg
->p_align
)
10585 && vma
< seg
->p_vaddr
+ seg
->p_filesz
)
10587 /* Since we do not know how big the symbol table is,
10588 we default to reading in up to the end of PT_LOAD
10589 segment and processing that. This is overkill, I
10590 know, but it should work. */
10591 Elf_Internal_Shdr section
;
10592 section
.sh_offset
= (vma
- seg
->p_vaddr
10594 section
.sh_size
= (num_of_syms
10595 * filedata
->dynamic_info
[DT_SYMENT
]);
10596 section
.sh_entsize
= filedata
->dynamic_info
[DT_SYMENT
];
10599 && filedata
->dynamic_symtab_section
!= NULL
10600 && ((filedata
->dynamic_symtab_section
->sh_offset
10601 != section
.sh_offset
)
10602 || (filedata
->dynamic_symtab_section
->sh_size
10603 != section
.sh_size
)
10604 || (filedata
->dynamic_symtab_section
->sh_entsize
10605 != section
.sh_entsize
)))
10607 the .dynsym section doesn't match the DT_SYMTAB and DT_SYMENT tags\n"));
10609 section
.sh_name
= filedata
->string_table_length
;
10610 filedata
->dynamic_symbols
10611 = GET_ELF_SYMBOLS (filedata
, §ion
,
10612 &filedata
->num_dynamic_syms
);
10613 if (filedata
->dynamic_symbols
== NULL
10614 || filedata
->num_dynamic_syms
!= num_of_syms
)
10616 error (_("Corrupt DT_SYMTAB dynamic entry\n"));
10625 /* Similarly find a string table. */
10626 if (filedata
->dynamic_strings
== NULL
)
10627 for (entry
= filedata
->dynamic_section
;
10628 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
10631 if (entry
->d_tag
== DT_STRTAB
)
10632 filedata
->dynamic_info
[DT_STRTAB
] = entry
->d_un
.d_val
;
10634 if (entry
->d_tag
== DT_STRSZ
)
10635 filedata
->dynamic_info
[DT_STRSZ
] = entry
->d_un
.d_val
;
10637 if (filedata
->dynamic_info
[DT_STRTAB
]
10638 && filedata
->dynamic_info
[DT_STRSZ
])
10640 unsigned long offset
;
10641 bfd_size_type str_tab_len
= filedata
->dynamic_info
[DT_STRSZ
];
10643 offset
= offset_from_vma (filedata
,
10644 filedata
->dynamic_info
[DT_STRTAB
],
10647 && filedata
->dynamic_strtab_section
10648 && ((filedata
->dynamic_strtab_section
->sh_offset
10649 != (file_ptr
) offset
)
10650 || (filedata
->dynamic_strtab_section
->sh_size
10653 the .dynstr section doesn't match the DT_STRTAB and DT_STRSZ tags\n"));
10655 filedata
->dynamic_strings
10656 = (char *) get_data (NULL
, filedata
, offset
, 1, str_tab_len
,
10657 _("dynamic string table"));
10658 if (filedata
->dynamic_strings
== NULL
)
10660 error (_("Corrupt DT_STRTAB dynamic entry\n"));
10664 filedata
->dynamic_strings_length
= str_tab_len
;
10669 /* And find the syminfo section if available. */
10670 if (filedata
->dynamic_syminfo
== NULL
)
10672 unsigned long syminsz
= 0;
10674 for (entry
= filedata
->dynamic_section
;
10675 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
10678 if (entry
->d_tag
== DT_SYMINENT
)
10680 /* Note: these braces are necessary to avoid a syntax
10681 error from the SunOS4 C compiler. */
10682 /* PR binutils/17531: A corrupt file can trigger this test.
10683 So do not use an assert, instead generate an error message. */
10684 if (sizeof (Elf_External_Syminfo
) != entry
->d_un
.d_val
)
10685 error (_("Bad value (%d) for SYMINENT entry\n"),
10686 (int) entry
->d_un
.d_val
);
10688 else if (entry
->d_tag
== DT_SYMINSZ
)
10689 syminsz
= entry
->d_un
.d_val
;
10690 else if (entry
->d_tag
== DT_SYMINFO
)
10691 filedata
->dynamic_syminfo_offset
10692 = offset_from_vma (filedata
, entry
->d_un
.d_val
, syminsz
);
10695 if (filedata
->dynamic_syminfo_offset
!= 0 && syminsz
!= 0)
10697 Elf_External_Syminfo
* extsyminfo
;
10698 Elf_External_Syminfo
* extsym
;
10699 Elf_Internal_Syminfo
* syminfo
;
10701 /* There is a syminfo section. Read the data. */
10702 extsyminfo
= (Elf_External_Syminfo
*)
10703 get_data (NULL
, filedata
, filedata
->dynamic_syminfo_offset
,
10704 1, syminsz
, _("symbol information"));
10708 if (filedata
->dynamic_syminfo
!= NULL
)
10710 error (_("Multiple dynamic symbol information sections found\n"));
10711 free (filedata
->dynamic_syminfo
);
10713 filedata
->dynamic_syminfo
= (Elf_Internal_Syminfo
*) malloc (syminsz
);
10714 if (filedata
->dynamic_syminfo
== NULL
)
10716 error (_("Out of memory allocating %lu bytes "
10717 "for dynamic symbol info\n"),
10718 (unsigned long) syminsz
);
10722 filedata
->dynamic_syminfo_nent
10723 = syminsz
/ sizeof (Elf_External_Syminfo
);
10724 for (syminfo
= filedata
->dynamic_syminfo
, extsym
= extsyminfo
;
10725 syminfo
< (filedata
->dynamic_syminfo
10726 + filedata
->dynamic_syminfo_nent
);
10727 ++syminfo
, ++extsym
)
10729 syminfo
->si_boundto
= BYTE_GET (extsym
->si_boundto
);
10730 syminfo
->si_flags
= BYTE_GET (extsym
->si_flags
);
10737 if (do_dynamic
&& filedata
->dynamic_addr
)
10739 if (filedata
->dynamic_nent
== 1)
10741 if (filedata
->is_separate
)
10742 printf (_("\nIn linked file '%s' the dynamic section at offset 0x%lx contains 1 entry:\n"),
10743 filedata
->file_name
,
10744 filedata
->dynamic_addr
);
10746 printf (_("\nDynamic section at offset 0x%lx contains 1 entry:\n"),
10747 filedata
->dynamic_addr
);
10751 if (filedata
->is_separate
)
10752 printf (_("\nIn linked file '%s' the dynamic section at offset 0x%lx contains %lu entries:\n"),
10753 filedata
->file_name
,
10754 filedata
->dynamic_addr
,
10755 (unsigned long) filedata
->dynamic_nent
);
10757 printf (_("\nDynamic section at offset 0x%lx contains %lu entries:\n"),
10758 filedata
->dynamic_addr
,
10759 (unsigned long) filedata
->dynamic_nent
);
10763 printf (_(" Tag Type Name/Value\n"));
10765 for (entry
= filedata
->dynamic_section
;
10766 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
10771 const char * dtype
;
10774 print_vma (entry
->d_tag
, FULL_HEX
);
10775 dtype
= get_dynamic_type (filedata
, entry
->d_tag
);
10776 printf (" (%s)%*s", dtype
,
10777 ((is_32bit_elf
? 27 : 19) - (int) strlen (dtype
)), " ");
10780 switch (entry
->d_tag
)
10784 print_dynamic_flags (entry
->d_un
.d_val
);
10794 switch (entry
->d_tag
)
10797 printf (_("Auxiliary library"));
10801 printf (_("Filter library"));
10805 printf (_("Configuration file"));
10809 printf (_("Dependency audit library"));
10813 printf (_("Audit library"));
10817 if (VALID_DYNAMIC_NAME (filedata
, entry
->d_un
.d_val
))
10818 printf (": [%s]\n",
10819 GET_DYNAMIC_NAME (filedata
, entry
->d_un
.d_val
));
10823 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
10832 printf (_("Flags:"));
10834 if (entry
->d_un
.d_val
== 0)
10835 printf (_(" None\n"));
10838 unsigned long int val
= entry
->d_un
.d_val
;
10840 if (val
& DTF_1_PARINIT
)
10842 printf (" PARINIT");
10843 val
^= DTF_1_PARINIT
;
10845 if (val
& DTF_1_CONFEXP
)
10847 printf (" CONFEXP");
10848 val
^= DTF_1_CONFEXP
;
10851 printf (" %lx", val
);
10860 printf (_("Flags:"));
10862 if (entry
->d_un
.d_val
== 0)
10863 printf (_(" None\n"));
10866 unsigned long int val
= entry
->d_un
.d_val
;
10868 if (val
& DF_P1_LAZYLOAD
)
10870 printf (" LAZYLOAD");
10871 val
^= DF_P1_LAZYLOAD
;
10873 if (val
& DF_P1_GROUPPERM
)
10875 printf (" GROUPPERM");
10876 val
^= DF_P1_GROUPPERM
;
10879 printf (" %lx", val
);
10888 printf (_("Flags:"));
10889 if (entry
->d_un
.d_val
== 0)
10890 printf (_(" None\n"));
10893 unsigned long int val
= entry
->d_un
.d_val
;
10895 if (val
& DF_1_NOW
)
10900 if (val
& DF_1_GLOBAL
)
10902 printf (" GLOBAL");
10903 val
^= DF_1_GLOBAL
;
10905 if (val
& DF_1_GROUP
)
10910 if (val
& DF_1_NODELETE
)
10912 printf (" NODELETE");
10913 val
^= DF_1_NODELETE
;
10915 if (val
& DF_1_LOADFLTR
)
10917 printf (" LOADFLTR");
10918 val
^= DF_1_LOADFLTR
;
10920 if (val
& DF_1_INITFIRST
)
10922 printf (" INITFIRST");
10923 val
^= DF_1_INITFIRST
;
10925 if (val
& DF_1_NOOPEN
)
10927 printf (" NOOPEN");
10928 val
^= DF_1_NOOPEN
;
10930 if (val
& DF_1_ORIGIN
)
10932 printf (" ORIGIN");
10933 val
^= DF_1_ORIGIN
;
10935 if (val
& DF_1_DIRECT
)
10937 printf (" DIRECT");
10938 val
^= DF_1_DIRECT
;
10940 if (val
& DF_1_TRANS
)
10945 if (val
& DF_1_INTERPOSE
)
10947 printf (" INTERPOSE");
10948 val
^= DF_1_INTERPOSE
;
10950 if (val
& DF_1_NODEFLIB
)
10952 printf (" NODEFLIB");
10953 val
^= DF_1_NODEFLIB
;
10955 if (val
& DF_1_NODUMP
)
10957 printf (" NODUMP");
10958 val
^= DF_1_NODUMP
;
10960 if (val
& DF_1_CONFALT
)
10962 printf (" CONFALT");
10963 val
^= DF_1_CONFALT
;
10965 if (val
& DF_1_ENDFILTEE
)
10967 printf (" ENDFILTEE");
10968 val
^= DF_1_ENDFILTEE
;
10970 if (val
& DF_1_DISPRELDNE
)
10972 printf (" DISPRELDNE");
10973 val
^= DF_1_DISPRELDNE
;
10975 if (val
& DF_1_DISPRELPND
)
10977 printf (" DISPRELPND");
10978 val
^= DF_1_DISPRELPND
;
10980 if (val
& DF_1_NODIRECT
)
10982 printf (" NODIRECT");
10983 val
^= DF_1_NODIRECT
;
10985 if (val
& DF_1_IGNMULDEF
)
10987 printf (" IGNMULDEF");
10988 val
^= DF_1_IGNMULDEF
;
10990 if (val
& DF_1_NOKSYMS
)
10992 printf (" NOKSYMS");
10993 val
^= DF_1_NOKSYMS
;
10995 if (val
& DF_1_NOHDR
)
11000 if (val
& DF_1_EDITED
)
11002 printf (" EDITED");
11003 val
^= DF_1_EDITED
;
11005 if (val
& DF_1_NORELOC
)
11007 printf (" NORELOC");
11008 val
^= DF_1_NORELOC
;
11010 if (val
& DF_1_SYMINTPOSE
)
11012 printf (" SYMINTPOSE");
11013 val
^= DF_1_SYMINTPOSE
;
11015 if (val
& DF_1_GLOBAUDIT
)
11017 printf (" GLOBAUDIT");
11018 val
^= DF_1_GLOBAUDIT
;
11020 if (val
& DF_1_SINGLETON
)
11022 printf (" SINGLETON");
11023 val
^= DF_1_SINGLETON
;
11025 if (val
& DF_1_STUB
)
11030 if (val
& DF_1_PIE
)
11035 if (val
& DF_1_KMOD
)
11040 if (val
& DF_1_WEAKFILTER
)
11042 printf (" WEAKFILTER");
11043 val
^= DF_1_WEAKFILTER
;
11045 if (val
& DF_1_NOCOMMON
)
11047 printf (" NOCOMMON");
11048 val
^= DF_1_NOCOMMON
;
11051 printf (" %lx", val
);
11058 filedata
->dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
11060 puts (get_dynamic_type (filedata
, entry
->d_un
.d_val
));
11080 filedata
->dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
11086 if (VALID_DYNAMIC_NAME (filedata
, entry
->d_un
.d_val
))
11087 name
= GET_DYNAMIC_NAME (filedata
, entry
->d_un
.d_val
);
11093 switch (entry
->d_tag
)
11096 printf (_("Shared library: [%s]"), name
);
11098 if (streq (name
, filedata
->program_interpreter
))
11099 printf (_(" program interpreter"));
11103 printf (_("Library soname: [%s]"), name
);
11107 printf (_("Library rpath: [%s]"), name
);
11111 printf (_("Library runpath: [%s]"), name
);
11115 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
11120 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
11133 filedata
->dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
11134 /* Fall through. */
11138 case DT_INIT_ARRAYSZ
:
11139 case DT_FINI_ARRAYSZ
:
11140 case DT_GNU_CONFLICTSZ
:
11141 case DT_GNU_LIBLISTSZ
:
11144 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
11145 printf (_(" (bytes)\n"));
11150 case DT_VERNEEDNUM
:
11155 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
11164 case DT_INIT_ARRAY
:
11165 case DT_FINI_ARRAY
:
11168 if (entry
->d_tag
== DT_USED
11169 && VALID_DYNAMIC_NAME (filedata
, entry
->d_un
.d_val
))
11171 char * name
= GET_DYNAMIC_NAME (filedata
, entry
->d_un
.d_val
);
11175 printf (_("Not needed object: [%s]\n"), name
);
11180 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
11186 /* The value of this entry is ignored. */
11191 case DT_GNU_PRELINKED
:
11195 time_t atime
= entry
->d_un
.d_val
;
11197 tmp
= gmtime (&atime
);
11198 /* PR 17533 file: 041-1244816-0.004. */
11200 printf (_("<corrupt time val: %lx"),
11201 (unsigned long) atime
);
11203 printf ("%04u-%02u-%02uT%02u:%02u:%02u\n",
11204 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
11205 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
11211 filedata
->dynamic_info_DT_GNU_HASH
= entry
->d_un
.d_val
;
11214 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
11219 case DT_GNU_FLAGS_1
:
11222 printf (_("Flags:"));
11223 if (entry
->d_un
.d_val
== 0)
11224 printf (_(" None\n"));
11227 unsigned long int val
= entry
->d_un
.d_val
;
11229 if (val
& DF_GNU_1_UNIQUE
)
11231 printf (" UNIQUE");
11232 val
^= DF_GNU_1_UNIQUE
;
11235 printf (" %lx", val
);
11242 if ((entry
->d_tag
>= DT_VERSYM
) && (entry
->d_tag
<= DT_VERNEEDNUM
))
11243 filedata
->version_info
[DT_VERSIONTAGIDX (entry
->d_tag
)]
11244 = entry
->d_un
.d_val
;
11248 switch (filedata
->file_header
.e_machine
)
11251 dynamic_section_aarch64_val (entry
);
11254 case EM_MIPS_RS3_LE
:
11255 dynamic_section_mips_val (filedata
, entry
);
11258 dynamic_section_parisc_val (entry
);
11261 dynamic_section_ia64_val (entry
);
11264 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
11276 get_ver_flags (unsigned int flags
)
11278 static char buff
[128];
11285 if (flags
& VER_FLG_BASE
)
11286 strcat (buff
, "BASE");
11288 if (flags
& VER_FLG_WEAK
)
11290 if (flags
& VER_FLG_BASE
)
11291 strcat (buff
, " | ");
11293 strcat (buff
, "WEAK");
11296 if (flags
& VER_FLG_INFO
)
11298 if (flags
& (VER_FLG_BASE
|VER_FLG_WEAK
))
11299 strcat (buff
, " | ");
11301 strcat (buff
, "INFO");
11304 if (flags
& ~(VER_FLG_BASE
| VER_FLG_WEAK
| VER_FLG_INFO
))
11306 if (flags
& (VER_FLG_BASE
| VER_FLG_WEAK
| VER_FLG_INFO
))
11307 strcat (buff
, " | ");
11309 strcat (buff
, _("<unknown>"));
11315 /* Display the contents of the version sections. */
11318 process_version_sections (Filedata
* filedata
)
11320 Elf_Internal_Shdr
* section
;
11322 bfd_boolean found
= FALSE
;
11327 for (i
= 0, section
= filedata
->section_headers
;
11328 i
< filedata
->file_header
.e_shnum
;
11331 switch (section
->sh_type
)
11333 case SHT_GNU_verdef
:
11335 Elf_External_Verdef
* edefs
;
11342 if (filedata
->is_separate
)
11343 printf (ngettext ("\nIn linked file '%s' the version definition section '%s' contains %u entry:\n",
11344 "\nIn linked file '%s' the version definition section '%s' contains %u entries:\n",
11346 filedata
->file_name
,
11347 printable_section_name (filedata
, section
),
11350 printf (ngettext ("\nVersion definition section '%s' "
11351 "contains %u entry:\n",
11352 "\nVersion definition section '%s' "
11353 "contains %u entries:\n",
11355 printable_section_name (filedata
, section
),
11358 printf (_(" Addr: 0x"));
11359 printf_vma (section
->sh_addr
);
11360 printf (_(" Offset: %#08lx Link: %u (%s)\n"),
11361 (unsigned long) section
->sh_offset
, section
->sh_link
,
11362 printable_section_name_from_index (filedata
, section
->sh_link
));
11364 edefs
= (Elf_External_Verdef
*)
11365 get_data (NULL
, filedata
, section
->sh_offset
, 1,section
->sh_size
,
11366 _("version definition section"));
11369 endbuf
= (char *) edefs
+ section
->sh_size
;
11371 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
11374 Elf_External_Verdef
* edef
;
11375 Elf_Internal_Verdef ent
;
11376 Elf_External_Verdaux
* eaux
;
11377 Elf_Internal_Verdaux aux
;
11378 unsigned long isum
;
11381 vstart
= ((char *) edefs
) + idx
;
11382 if (vstart
+ sizeof (*edef
) > endbuf
)
11385 edef
= (Elf_External_Verdef
*) vstart
;
11387 ent
.vd_version
= BYTE_GET (edef
->vd_version
);
11388 ent
.vd_flags
= BYTE_GET (edef
->vd_flags
);
11389 ent
.vd_ndx
= BYTE_GET (edef
->vd_ndx
);
11390 ent
.vd_cnt
= BYTE_GET (edef
->vd_cnt
);
11391 ent
.vd_hash
= BYTE_GET (edef
->vd_hash
);
11392 ent
.vd_aux
= BYTE_GET (edef
->vd_aux
);
11393 ent
.vd_next
= BYTE_GET (edef
->vd_next
);
11395 printf (_(" %#06lx: Rev: %d Flags: %s"),
11396 idx
, ent
.vd_version
, get_ver_flags (ent
.vd_flags
));
11398 printf (_(" Index: %d Cnt: %d "),
11399 ent
.vd_ndx
, ent
.vd_cnt
);
11401 /* Check for overflow. */
11402 if (ent
.vd_aux
> (size_t) (endbuf
- vstart
))
11405 vstart
+= ent
.vd_aux
;
11407 if (vstart
+ sizeof (*eaux
) > endbuf
)
11409 eaux
= (Elf_External_Verdaux
*) vstart
;
11411 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
11412 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
11414 if (VALID_DYNAMIC_NAME (filedata
, aux
.vda_name
))
11415 printf (_("Name: %s\n"),
11416 GET_DYNAMIC_NAME (filedata
, aux
.vda_name
));
11418 printf (_("Name index: %ld\n"), aux
.vda_name
);
11420 isum
= idx
+ ent
.vd_aux
;
11422 for (j
= 1; j
< ent
.vd_cnt
; j
++)
11424 if (aux
.vda_next
< sizeof (*eaux
)
11425 && !(j
== ent
.vd_cnt
- 1 && aux
.vda_next
== 0))
11427 warn (_("Invalid vda_next field of %lx\n"),
11432 /* Check for overflow. */
11433 if (aux
.vda_next
> (size_t) (endbuf
- vstart
))
11436 isum
+= aux
.vda_next
;
11437 vstart
+= aux
.vda_next
;
11439 if (vstart
+ sizeof (*eaux
) > endbuf
)
11441 eaux
= (Elf_External_Verdaux
*) vstart
;
11443 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
11444 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
11446 if (VALID_DYNAMIC_NAME (filedata
, aux
.vda_name
))
11447 printf (_(" %#06lx: Parent %d: %s\n"),
11449 GET_DYNAMIC_NAME (filedata
, aux
.vda_name
));
11451 printf (_(" %#06lx: Parent %d, name index: %ld\n"),
11452 isum
, j
, aux
.vda_name
);
11455 if (j
< ent
.vd_cnt
)
11456 printf (_(" Version def aux past end of section\n"));
11459 file: id:000001,src:000172+005151,op:splice,rep:2. */
11460 if (ent
.vd_next
< sizeof (*edef
)
11461 && !(cnt
== section
->sh_info
- 1 && ent
.vd_next
== 0))
11463 warn (_("Invalid vd_next field of %lx\n"), ent
.vd_next
);
11464 cnt
= section
->sh_info
;
11467 if (ent
.vd_next
> (size_t) (endbuf
- ((char *) edefs
+ idx
)))
11470 idx
+= ent
.vd_next
;
11473 if (cnt
< section
->sh_info
)
11474 printf (_(" Version definition past end of section\n"));
11480 case SHT_GNU_verneed
:
11482 Elf_External_Verneed
* eneed
;
11489 if (filedata
->is_separate
)
11490 printf (ngettext ("\nIn linked file '%s' the version needs section '%s' contains %u entry:\n",
11491 "\nIn linked file '%s' the version needs section '%s' contains %u entries:\n",
11493 filedata
->file_name
,
11494 printable_section_name (filedata
, section
),
11497 printf (ngettext ("\nVersion needs section '%s' "
11498 "contains %u entry:\n",
11499 "\nVersion needs section '%s' "
11500 "contains %u entries:\n",
11502 printable_section_name (filedata
, section
),
11505 printf (_(" Addr: 0x"));
11506 printf_vma (section
->sh_addr
);
11507 printf (_(" Offset: %#08lx Link: %u (%s)\n"),
11508 (unsigned long) section
->sh_offset
, section
->sh_link
,
11509 printable_section_name_from_index (filedata
, section
->sh_link
));
11511 eneed
= (Elf_External_Verneed
*) get_data (NULL
, filedata
,
11512 section
->sh_offset
, 1,
11514 _("Version Needs section"));
11517 endbuf
= (char *) eneed
+ section
->sh_size
;
11519 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
11521 Elf_External_Verneed
* entry
;
11522 Elf_Internal_Verneed ent
;
11523 unsigned long isum
;
11527 vstart
= ((char *) eneed
) + idx
;
11528 if (vstart
+ sizeof (*entry
) > endbuf
)
11531 entry
= (Elf_External_Verneed
*) vstart
;
11533 ent
.vn_version
= BYTE_GET (entry
->vn_version
);
11534 ent
.vn_cnt
= BYTE_GET (entry
->vn_cnt
);
11535 ent
.vn_file
= BYTE_GET (entry
->vn_file
);
11536 ent
.vn_aux
= BYTE_GET (entry
->vn_aux
);
11537 ent
.vn_next
= BYTE_GET (entry
->vn_next
);
11539 printf (_(" %#06lx: Version: %d"), idx
, ent
.vn_version
);
11541 if (VALID_DYNAMIC_NAME (filedata
, ent
.vn_file
))
11542 printf (_(" File: %s"),
11543 GET_DYNAMIC_NAME (filedata
, ent
.vn_file
));
11545 printf (_(" File: %lx"), ent
.vn_file
);
11547 printf (_(" Cnt: %d\n"), ent
.vn_cnt
);
11549 /* Check for overflow. */
11550 if (ent
.vn_aux
> (size_t) (endbuf
- vstart
))
11552 vstart
+= ent
.vn_aux
;
11554 for (j
= 0, isum
= idx
+ ent
.vn_aux
; j
< ent
.vn_cnt
; ++j
)
11556 Elf_External_Vernaux
* eaux
;
11557 Elf_Internal_Vernaux aux
;
11559 if (vstart
+ sizeof (*eaux
) > endbuf
)
11561 eaux
= (Elf_External_Vernaux
*) vstart
;
11563 aux
.vna_hash
= BYTE_GET (eaux
->vna_hash
);
11564 aux
.vna_flags
= BYTE_GET (eaux
->vna_flags
);
11565 aux
.vna_other
= BYTE_GET (eaux
->vna_other
);
11566 aux
.vna_name
= BYTE_GET (eaux
->vna_name
);
11567 aux
.vna_next
= BYTE_GET (eaux
->vna_next
);
11569 if (VALID_DYNAMIC_NAME (filedata
, aux
.vna_name
))
11570 printf (_(" %#06lx: Name: %s"),
11571 isum
, GET_DYNAMIC_NAME (filedata
, aux
.vna_name
));
11573 printf (_(" %#06lx: Name index: %lx"),
11574 isum
, aux
.vna_name
);
11576 printf (_(" Flags: %s Version: %d\n"),
11577 get_ver_flags (aux
.vna_flags
), aux
.vna_other
);
11579 if (aux
.vna_next
< sizeof (*eaux
)
11580 && !(j
== ent
.vn_cnt
- 1 && aux
.vna_next
== 0))
11582 warn (_("Invalid vna_next field of %lx\n"),
11587 /* Check for overflow. */
11588 if (aux
.vna_next
> (size_t) (endbuf
- vstart
))
11590 isum
+= aux
.vna_next
;
11591 vstart
+= aux
.vna_next
;
11594 if (j
< ent
.vn_cnt
)
11595 warn (_("Missing Version Needs auxiliary information\n"));
11597 if (ent
.vn_next
< sizeof (*entry
)
11598 && !(cnt
== section
->sh_info
- 1 && ent
.vn_next
== 0))
11600 warn (_("Invalid vn_next field of %lx\n"), ent
.vn_next
);
11601 cnt
= section
->sh_info
;
11604 if (ent
.vn_next
> (size_t) (endbuf
- ((char *) eneed
+ idx
)))
11606 idx
+= ent
.vn_next
;
11609 if (cnt
< section
->sh_info
)
11610 warn (_("Missing Version Needs information\n"));
11616 case SHT_GNU_versym
:
11618 Elf_Internal_Shdr
* link_section
;
11621 unsigned char * edata
;
11622 unsigned short * data
;
11624 Elf_Internal_Sym
* symbols
;
11625 Elf_Internal_Shdr
* string_sec
;
11626 unsigned long num_syms
;
11629 if (section
->sh_link
>= filedata
->file_header
.e_shnum
)
11632 link_section
= filedata
->section_headers
+ section
->sh_link
;
11633 total
= section
->sh_size
/ sizeof (Elf_External_Versym
);
11635 if (link_section
->sh_link
>= filedata
->file_header
.e_shnum
)
11640 symbols
= GET_ELF_SYMBOLS (filedata
, link_section
, & num_syms
);
11641 if (symbols
== NULL
)
11644 string_sec
= filedata
->section_headers
+ link_section
->sh_link
;
11646 strtab
= (char *) get_data (NULL
, filedata
, string_sec
->sh_offset
, 1,
11647 string_sec
->sh_size
,
11648 _("version string table"));
11655 if (filedata
->is_separate
)
11656 printf (ngettext ("\nIn linked file '%s' the version symbols section '%s' contains %lu entry:\n",
11657 "\nIn linked file '%s' the version symbols section '%s' contains %lu entries:\n",
11659 filedata
->file_name
,
11660 printable_section_name (filedata
, section
),
11661 (unsigned long) total
);
11663 printf (ngettext ("\nVersion symbols section '%s' "
11664 "contains %lu entry:\n",
11665 "\nVersion symbols section '%s' "
11666 "contains %lu entries:\n",
11668 printable_section_name (filedata
, section
),
11669 (unsigned long) total
);
11671 printf (_(" Addr: 0x"));
11672 printf_vma (section
->sh_addr
);
11673 printf (_(" Offset: %#08lx Link: %u (%s)\n"),
11674 (unsigned long) section
->sh_offset
, section
->sh_link
,
11675 printable_section_name (filedata
, link_section
));
11677 off
= offset_from_vma (filedata
,
11678 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)],
11679 total
* sizeof (short));
11680 edata
= (unsigned char *) get_data (NULL
, filedata
, off
,
11681 sizeof (short), total
,
11682 _("version symbol data"));
11690 data
= (short unsigned int *) cmalloc (total
, sizeof (short));
11692 for (cnt
= total
; cnt
--;)
11693 data
[cnt
] = byte_get (edata
+ cnt
* sizeof (short),
11698 for (cnt
= 0; cnt
< total
; cnt
+= 4)
11702 char *invalid
= _("*invalid*");
11704 printf (" %03x:", cnt
);
11706 for (j
= 0; (j
< 4) && (cnt
+ j
) < total
; ++j
)
11707 switch (data
[cnt
+ j
])
11710 fputs (_(" 0 (*local*) "), stdout
);
11714 fputs (_(" 1 (*global*) "), stdout
);
11718 nn
= printf ("%4x%c", data
[cnt
+ j
] & VERSYM_VERSION
,
11719 data
[cnt
+ j
] & VERSYM_HIDDEN
? 'h' : ' ');
11721 /* If this index value is greater than the size of the symbols
11722 array, break to avoid an out-of-bounds read. */
11723 if ((unsigned long)(cnt
+ j
) >= num_syms
)
11725 warn (_("invalid index into symbol array\n"));
11730 if (filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)])
11732 Elf_Internal_Verneed ivn
;
11733 unsigned long offset
;
11735 offset
= offset_from_vma
11737 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)],
11738 sizeof (Elf_External_Verneed
));
11742 Elf_Internal_Vernaux ivna
;
11743 Elf_External_Verneed evn
;
11744 Elf_External_Vernaux evna
;
11745 unsigned long a_off
;
11747 if (get_data (&evn
, filedata
, offset
, sizeof (evn
), 1,
11748 _("version need")) == NULL
)
11751 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
11752 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
11754 a_off
= offset
+ ivn
.vn_aux
;
11758 if (get_data (&evna
, filedata
, a_off
, sizeof (evna
),
11759 1, _("version need aux (2)")) == NULL
)
11762 ivna
.vna_other
= 0;
11766 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
11767 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
11770 a_off
+= ivna
.vna_next
;
11772 while (ivna
.vna_other
!= data
[cnt
+ j
]
11773 && ivna
.vna_next
!= 0);
11775 if (ivna
.vna_other
== data
[cnt
+ j
])
11777 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
11779 if (ivna
.vna_name
>= string_sec
->sh_size
)
11782 name
= strtab
+ ivna
.vna_name
;
11786 offset
+= ivn
.vn_next
;
11788 while (ivn
.vn_next
);
11791 if (data
[cnt
+ j
] != 0x8001
11792 && filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
11794 Elf_Internal_Verdef ivd
;
11795 Elf_External_Verdef evd
;
11796 unsigned long offset
;
11798 offset
= offset_from_vma
11800 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)],
11805 if (get_data (&evd
, filedata
, offset
, sizeof (evd
), 1,
11806 _("version def")) == NULL
)
11809 /* PR 17531: file: 046-1082287-0.004. */
11810 ivd
.vd_ndx
= (data
[cnt
+ j
] & VERSYM_VERSION
) + 1;
11815 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
11816 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
11819 offset
+= ivd
.vd_next
;
11821 while (ivd
.vd_ndx
!= (data
[cnt
+ j
] & VERSYM_VERSION
)
11822 && ivd
.vd_next
!= 0);
11824 if (ivd
.vd_ndx
== (data
[cnt
+ j
] & VERSYM_VERSION
))
11826 Elf_External_Verdaux evda
;
11827 Elf_Internal_Verdaux ivda
;
11829 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
11831 if (get_data (&evda
, filedata
,
11832 offset
- ivd
.vd_next
+ ivd
.vd_aux
,
11834 _("version def aux")) == NULL
)
11837 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
11839 if (ivda
.vda_name
>= string_sec
->sh_size
)
11841 else if (name
!= NULL
&& name
!= invalid
)
11842 name
= _("*both*");
11844 name
= strtab
+ ivda
.vda_name
;
11848 nn
+= printf ("(%s%-*s",
11850 12 - (int) strlen (name
),
11854 printf ("%*c", 18 - nn
, ' ');
11873 if (filedata
->is_separate
)
11874 printf (_("\nNo version information found in linked file '%s'.\n"),
11875 filedata
->file_name
);
11877 printf (_("\nNo version information found in this file.\n"));
11883 static const char *
11884 get_symbol_binding (Filedata
* filedata
, unsigned int binding
)
11886 static char buff
[64];
11890 case STB_LOCAL
: return "LOCAL";
11891 case STB_GLOBAL
: return "GLOBAL";
11892 case STB_WEAK
: return "WEAK";
11894 if (binding
>= STB_LOPROC
&& binding
<= STB_HIPROC
)
11895 snprintf (buff
, sizeof (buff
), _("<processor specific>: %d"),
11897 else if (binding
>= STB_LOOS
&& binding
<= STB_HIOS
)
11899 if (binding
== STB_GNU_UNIQUE
11900 && filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_GNU
)
11902 snprintf (buff
, sizeof (buff
), _("<OS specific>: %d"), binding
);
11905 snprintf (buff
, sizeof (buff
), _("<unknown>: %d"), binding
);
11910 static const char *
11911 get_symbol_type (Filedata
* filedata
, unsigned int type
)
11913 static char buff
[64];
11917 case STT_NOTYPE
: return "NOTYPE";
11918 case STT_OBJECT
: return "OBJECT";
11919 case STT_FUNC
: return "FUNC";
11920 case STT_SECTION
: return "SECTION";
11921 case STT_FILE
: return "FILE";
11922 case STT_COMMON
: return "COMMON";
11923 case STT_TLS
: return "TLS";
11924 case STT_RELC
: return "RELC";
11925 case STT_SRELC
: return "SRELC";
11927 if (type
>= STT_LOPROC
&& type
<= STT_HIPROC
)
11929 if (filedata
->file_header
.e_machine
== EM_ARM
&& type
== STT_ARM_TFUNC
)
11930 return "THUMB_FUNC";
11932 if (filedata
->file_header
.e_machine
== EM_SPARCV9
&& type
== STT_REGISTER
)
11935 if (filedata
->file_header
.e_machine
== EM_PARISC
&& type
== STT_PARISC_MILLI
)
11936 return "PARISC_MILLI";
11938 snprintf (buff
, sizeof (buff
), _("<processor specific>: %d"), type
);
11940 else if (type
>= STT_LOOS
&& type
<= STT_HIOS
)
11942 if (filedata
->file_header
.e_machine
== EM_PARISC
)
11944 if (type
== STT_HP_OPAQUE
)
11945 return "HP_OPAQUE";
11946 if (type
== STT_HP_STUB
)
11950 if (type
== STT_GNU_IFUNC
11951 && (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_GNU
11952 || filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_FREEBSD
))
11955 snprintf (buff
, sizeof (buff
), _("<OS specific>: %d"), type
);
11958 snprintf (buff
, sizeof (buff
), _("<unknown>: %d"), type
);
11963 static const char *
11964 get_symbol_visibility (unsigned int visibility
)
11966 switch (visibility
)
11968 case STV_DEFAULT
: return "DEFAULT";
11969 case STV_INTERNAL
: return "INTERNAL";
11970 case STV_HIDDEN
: return "HIDDEN";
11971 case STV_PROTECTED
: return "PROTECTED";
11973 error (_("Unrecognized visibility value: %u\n"), visibility
);
11974 return _("<unknown>");
11978 static const char *
11979 get_alpha_symbol_other (unsigned int other
)
11983 case STO_ALPHA_NOPV
: return "NOPV";
11984 case STO_ALPHA_STD_GPLOAD
: return "STD GPLOAD";
11986 error (_("Unrecognized alpha specific other value: %u\n"), other
);
11987 return _("<unknown>");
11991 static const char *
11992 get_solaris_symbol_visibility (unsigned int visibility
)
11994 switch (visibility
)
11996 case 4: return "EXPORTED";
11997 case 5: return "SINGLETON";
11998 case 6: return "ELIMINATE";
11999 default: return get_symbol_visibility (visibility
);
12003 static const char *
12004 get_aarch64_symbol_other (unsigned int other
)
12006 static char buf
[32];
12008 if (other
& STO_AARCH64_VARIANT_PCS
)
12010 other
&= ~STO_AARCH64_VARIANT_PCS
;
12012 return "VARIANT_PCS";
12013 snprintf (buf
, sizeof buf
, "VARIANT_PCS | %x", other
);
12019 static const char *
12020 get_mips_symbol_other (unsigned int other
)
12024 case STO_OPTIONAL
: return "OPTIONAL";
12025 case STO_MIPS_PLT
: return "MIPS PLT";
12026 case STO_MIPS_PIC
: return "MIPS PIC";
12027 case STO_MICROMIPS
: return "MICROMIPS";
12028 case STO_MICROMIPS
| STO_MIPS_PIC
: return "MICROMIPS, MIPS PIC";
12029 case STO_MIPS16
: return "MIPS16";
12030 default: return NULL
;
12034 static const char *
12035 get_ia64_symbol_other (Filedata
* filedata
, unsigned int other
)
12037 if (is_ia64_vms (filedata
))
12039 static char res
[32];
12043 /* Function types is for images and .STB files only. */
12044 switch (filedata
->file_header
.e_type
)
12048 switch (VMS_ST_FUNC_TYPE (other
))
12050 case VMS_SFT_CODE_ADDR
:
12051 strcat (res
, " CA");
12053 case VMS_SFT_SYMV_IDX
:
12054 strcat (res
, " VEC");
12057 strcat (res
, " FD");
12059 case VMS_SFT_RESERVE
:
12060 strcat (res
, " RSV");
12063 warn (_("Unrecognized IA64 VMS ST Function type: %d\n"),
12064 VMS_ST_FUNC_TYPE (other
));
12065 strcat (res
, " <unknown>");
12072 switch (VMS_ST_LINKAGE (other
))
12074 case VMS_STL_IGNORE
:
12075 strcat (res
, " IGN");
12077 case VMS_STL_RESERVE
:
12078 strcat (res
, " RSV");
12081 strcat (res
, " STD");
12084 strcat (res
, " LNK");
12087 warn (_("Unrecognized IA64 VMS ST Linkage: %d\n"),
12088 VMS_ST_LINKAGE (other
));
12089 strcat (res
, " <unknown>");
12101 static const char *
12102 get_ppc64_symbol_other (unsigned int other
)
12104 if ((other
& ~STO_PPC64_LOCAL_MASK
) != 0)
12107 other
>>= STO_PPC64_LOCAL_BIT
;
12110 static char buf
[64];
12112 other
= ppc64_decode_local_entry (other
);
12113 snprintf (buf
, sizeof buf
, _("<localentry>: %d"), other
);
12119 static const char *
12120 get_symbol_other (Filedata
* filedata
, unsigned int other
)
12122 const char * result
= NULL
;
12123 static char buff
[64];
12128 switch (filedata
->file_header
.e_machine
)
12131 result
= get_alpha_symbol_other (other
);
12134 result
= get_aarch64_symbol_other (other
);
12137 result
= get_mips_symbol_other (other
);
12140 result
= get_ia64_symbol_other (filedata
, other
);
12143 result
= get_ppc64_symbol_other (other
);
12153 snprintf (buff
, sizeof buff
, _("<other>: %x"), other
);
12157 static const char *
12158 get_symbol_index_type (Filedata
* filedata
, unsigned int type
)
12160 static char buff
[32];
12164 case SHN_UNDEF
: return "UND";
12165 case SHN_ABS
: return "ABS";
12166 case SHN_COMMON
: return "COM";
12168 if (type
== SHN_IA_64_ANSI_COMMON
12169 && filedata
->file_header
.e_machine
== EM_IA_64
12170 && filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_HPUX
)
12172 else if ((filedata
->file_header
.e_machine
== EM_X86_64
12173 || filedata
->file_header
.e_machine
== EM_L1OM
12174 || filedata
->file_header
.e_machine
== EM_K1OM
)
12175 && type
== SHN_X86_64_LCOMMON
)
12176 return "LARGE_COM";
12177 else if ((type
== SHN_MIPS_SCOMMON
12178 && filedata
->file_header
.e_machine
== EM_MIPS
)
12179 || (type
== SHN_TIC6X_SCOMMON
12180 && filedata
->file_header
.e_machine
== EM_TI_C6000
))
12182 else if (type
== SHN_MIPS_SUNDEFINED
12183 && filedata
->file_header
.e_machine
== EM_MIPS
)
12185 else if (type
>= SHN_LOPROC
&& type
<= SHN_HIPROC
)
12186 sprintf (buff
, "PRC[0x%04x]", type
& 0xffff);
12187 else if (type
>= SHN_LOOS
&& type
<= SHN_HIOS
)
12188 sprintf (buff
, "OS [0x%04x]", type
& 0xffff);
12189 else if (type
>= SHN_LORESERVE
)
12190 sprintf (buff
, "RSV[0x%04x]", type
& 0xffff);
12191 else if (filedata
->file_header
.e_shnum
!= 0
12192 && type
>= filedata
->file_header
.e_shnum
)
12193 sprintf (buff
, _("bad section index[%3d]"), type
);
12195 sprintf (buff
, "%3d", type
);
12202 static const char *
12203 get_symbol_version_string (Filedata
* filedata
,
12204 bfd_boolean is_dynsym
,
12205 const char * strtab
,
12206 unsigned long int strtab_size
,
12208 Elf_Internal_Sym
* psym
,
12209 enum versioned_symbol_info
* sym_info
,
12210 unsigned short * vna_other
)
12212 unsigned char data
[2];
12213 unsigned short vers_data
;
12214 unsigned long offset
;
12215 unsigned short max_vd_ndx
;
12218 || filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)] == 0)
12221 offset
= offset_from_vma (filedata
,
12222 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)],
12223 sizeof data
+ si
* sizeof (vers_data
));
12225 if (get_data (&data
, filedata
, offset
+ si
* sizeof (vers_data
),
12226 sizeof (data
), 1, _("version data")) == NULL
)
12229 vers_data
= byte_get (data
, 2);
12231 if ((vers_data
& VERSYM_HIDDEN
) == 0 && vers_data
== 0)
12234 *sym_info
= (vers_data
& VERSYM_HIDDEN
) != 0 ? symbol_hidden
: symbol_public
;
12237 /* Usually we'd only see verdef for defined symbols, and verneed for
12238 undefined symbols. However, symbols defined by the linker in
12239 .dynbss for variables copied from a shared library in order to
12240 avoid text relocations are defined yet have verneed. We could
12241 use a heuristic to detect the special case, for example, check
12242 for verneed first on symbols defined in SHT_NOBITS sections, but
12243 it is simpler and more reliable to just look for both verdef and
12244 verneed. .dynbss might not be mapped to a SHT_NOBITS section. */
12246 if (psym
->st_shndx
!= SHN_UNDEF
12247 && vers_data
!= 0x8001
12248 && filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
12250 Elf_Internal_Verdef ivd
;
12251 Elf_Internal_Verdaux ivda
;
12252 Elf_External_Verdaux evda
;
12255 off
= offset_from_vma (filedata
,
12256 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)],
12257 sizeof (Elf_External_Verdef
));
12261 Elf_External_Verdef evd
;
12263 if (get_data (&evd
, filedata
, off
, sizeof (evd
), 1,
12264 _("version def")) == NULL
)
12273 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
12274 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
12275 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
12276 ivd
.vd_flags
= BYTE_GET (evd
.vd_flags
);
12279 if ((ivd
.vd_ndx
& VERSYM_VERSION
) > max_vd_ndx
)
12280 max_vd_ndx
= ivd
.vd_ndx
& VERSYM_VERSION
;
12282 off
+= ivd
.vd_next
;
12284 while (ivd
.vd_ndx
!= (vers_data
& VERSYM_VERSION
) && ivd
.vd_next
!= 0);
12286 if (ivd
.vd_ndx
== (vers_data
& VERSYM_VERSION
))
12288 if (ivd
.vd_ndx
== 1 && ivd
.vd_flags
== VER_FLG_BASE
)
12291 off
-= ivd
.vd_next
;
12294 if (get_data (&evda
, filedata
, off
, sizeof (evda
), 1,
12295 _("version def aux")) != NULL
)
12297 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
12299 if (psym
->st_name
!= ivda
.vda_name
)
12300 return (ivda
.vda_name
< strtab_size
12301 ? strtab
+ ivda
.vda_name
: _("<corrupt>"));
12306 if (filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)])
12308 Elf_External_Verneed evn
;
12309 Elf_Internal_Verneed ivn
;
12310 Elf_Internal_Vernaux ivna
;
12312 offset
= offset_from_vma (filedata
,
12313 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)],
12317 unsigned long vna_off
;
12319 if (get_data (&evn
, filedata
, offset
, sizeof (evn
), 1,
12320 _("version need")) == NULL
)
12323 ivna
.vna_other
= 0;
12328 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
12329 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
12331 vna_off
= offset
+ ivn
.vn_aux
;
12335 Elf_External_Vernaux evna
;
12337 if (get_data (&evna
, filedata
, vna_off
, sizeof (evna
), 1,
12338 _("version need aux (3)")) == NULL
)
12341 ivna
.vna_other
= 0;
12346 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
12347 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
12348 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
12351 vna_off
+= ivna
.vna_next
;
12353 while (ivna
.vna_other
!= vers_data
&& ivna
.vna_next
!= 0);
12355 if (ivna
.vna_other
== vers_data
)
12358 offset
+= ivn
.vn_next
;
12360 while (ivn
.vn_next
!= 0);
12362 if (ivna
.vna_other
== vers_data
)
12364 *sym_info
= symbol_undefined
;
12365 *vna_other
= ivna
.vna_other
;
12366 return (ivna
.vna_name
< strtab_size
12367 ? strtab
+ ivna
.vna_name
: _("<corrupt>"));
12369 else if ((max_vd_ndx
|| (vers_data
& VERSYM_VERSION
) != 1)
12370 && (vers_data
& VERSYM_VERSION
) > max_vd_ndx
)
12371 return _("<corrupt>");
12377 print_dynamic_symbol (Filedata
*filedata
, unsigned long si
,
12378 Elf_Internal_Sym
*symtab
,
12379 Elf_Internal_Shdr
*section
,
12380 char *strtab
, size_t strtab_size
)
12382 const char *version_string
;
12383 enum versioned_symbol_info sym_info
;
12384 unsigned short vna_other
;
12385 Elf_Internal_Sym
*psym
= symtab
+ si
;
12387 printf ("%6ld: ", si
);
12388 print_vma (psym
->st_value
, LONG_HEX
);
12390 print_vma (psym
->st_size
, DEC_5
);
12391 printf (" %-7s", get_symbol_type (filedata
, ELF_ST_TYPE (psym
->st_info
)));
12392 printf (" %-6s", get_symbol_binding (filedata
, ELF_ST_BIND (psym
->st_info
)));
12393 if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_SOLARIS
)
12394 printf (" %-7s", get_solaris_symbol_visibility (psym
->st_other
));
12397 unsigned int vis
= ELF_ST_VISIBILITY (psym
->st_other
);
12399 printf (" %-7s", get_symbol_visibility (vis
));
12400 /* Check to see if any other bits in the st_other field are set.
12401 Note - displaying this information disrupts the layout of the
12402 table being generated, but for the moment this case is very rare. */
12403 if (psym
->st_other
^ vis
)
12404 printf (" [%s] ", get_symbol_other (filedata
, psym
->st_other
^ vis
));
12406 printf (" %4s ", get_symbol_index_type (filedata
, psym
->st_shndx
));
12408 bfd_boolean is_valid
= VALID_SYMBOL_NAME (strtab
, strtab_size
,
12410 const char * sstr
= is_valid
? strtab
+ psym
->st_name
: _("<corrupt>");
12413 = get_symbol_version_string (filedata
,
12415 || section
->sh_type
== SHT_DYNSYM
),
12416 strtab
, strtab_size
, si
,
12417 psym
, &sym_info
, &vna_other
);
12419 int len_avail
= 21;
12420 if (! do_wide
&& version_string
!= NULL
)
12424 len_avail
-= 1 + strlen (version_string
);
12426 if (sym_info
== symbol_undefined
)
12427 len_avail
-= sprintf (buffer
," (%d)", vna_other
);
12428 else if (sym_info
!= symbol_hidden
)
12432 print_symbol (len_avail
, sstr
);
12434 if (version_string
)
12436 if (sym_info
== symbol_undefined
)
12437 printf ("@%s (%d)", version_string
, vna_other
);
12439 printf (sym_info
== symbol_hidden
? "@%s" : "@@%s",
12445 if (ELF_ST_BIND (psym
->st_info
) == STB_LOCAL
12447 && si
>= section
->sh_info
12448 /* Irix 5 and 6 MIPS binaries are known to ignore this requirement. */
12449 && filedata
->file_header
.e_machine
!= EM_MIPS
12450 /* Solaris binaries have been found to violate this requirement as
12451 well. Not sure if this is a bug or an ABI requirement. */
12452 && filedata
->file_header
.e_ident
[EI_OSABI
] != ELFOSABI_SOLARIS
)
12453 warn (_("local symbol %lu found at index >= %s's sh_info value of %u\n"),
12454 si
, printable_section_name (filedata
, section
), section
->sh_info
);
12457 static const char *
12458 get_lto_kind (unsigned int kind
)
12462 case 0: return "DEF";
12463 case 1: return "WEAKDEF";
12464 case 2: return "UNDEF";
12465 case 3: return "WEAKUNDEF";
12466 case 4: return "COMMON";
12471 static char buffer
[30];
12472 error (_("Unknown LTO symbol definition encountered: %u\n"), kind
);
12473 sprintf (buffer
, "<unknown: %u>", kind
);
12477 static const char *
12478 get_lto_visibility (unsigned int visibility
)
12480 switch (visibility
)
12482 case 0: return "DEFAULT";
12483 case 1: return "PROTECTED";
12484 case 2: return "INTERNAL";
12485 case 3: return "HIDDEN";
12490 static char buffer
[30];
12491 error (_("Unknown LTO symbol visibility encountered: %u\n"), visibility
);
12492 sprintf (buffer
, "<unknown: %u>", visibility
);
12496 static const char *
12497 get_lto_sym_type (unsigned int sym_type
)
12501 case 0: return "UNKNOWN";
12502 case 1: return "FUNCTION";
12503 case 2: return "VARIABLE";
12508 static char buffer
[30];
12509 error (_("Unknown LTO symbol type encountered: %u\n"), sym_type
);
12510 sprintf (buffer
, "<unknown: %u>", sym_type
);
12514 /* Display an LTO format symbol table.
12515 FIXME: The format of LTO symbol tables is not formalized.
12516 So this code could need changing in the future. */
12519 display_lto_symtab (Filedata
* filedata
,
12520 Elf_Internal_Shdr
* section
)
12522 if (section
->sh_size
== 0)
12524 if (filedata
->is_separate
)
12525 printf (_("\nThe LTO Symbol table section '%s' in linked file '%s' is empty!\n"),
12526 printable_section_name (filedata
, section
),
12527 filedata
->file_name
);
12529 printf (_("\nLTO Symbol table '%s' is empty!\n"),
12530 printable_section_name (filedata
, section
));
12535 if (section
->sh_size
> filedata
->file_size
)
12537 error (_("Section %s has an invalid sh_size of 0x%lx\n"),
12538 printable_section_name (filedata
, section
),
12539 (unsigned long) section
->sh_size
);
12543 void * alloced_data
= get_data (NULL
, filedata
, section
->sh_offset
,
12544 section
->sh_size
, 1, _("LTO symbols"));
12545 if (alloced_data
== NULL
)
12548 /* Look for extended data for the symbol table. */
12549 Elf_Internal_Shdr
* ext
;
12550 void * ext_data_orig
= NULL
;
12551 char * ext_data
= NULL
;
12552 char * ext_data_end
= NULL
;
12553 char * ext_name
= NULL
;
12555 if (asprintf (& ext_name
, ".gnu.lto_.ext_symtab.%s",
12556 SECTION_NAME (section
) + sizeof (".gnu.lto_.symtab.") - 1) > 0
12557 && ext_name
!= NULL
/* Paranoia. */
12558 && (ext
= find_section (filedata
, ext_name
)) != NULL
)
12560 if (ext
->sh_size
< 3)
12561 error (_("LTO Symbol extension table '%s' is empty!\n"),
12562 printable_section_name (filedata
, ext
));
12565 ext_data_orig
= ext_data
= get_data (NULL
, filedata
, ext
->sh_offset
,
12567 _("LTO ext symbol data"));
12568 if (ext_data
!= NULL
)
12570 ext_data_end
= ext_data
+ ext
->sh_size
;
12571 if (* ext_data
++ != 1)
12572 error (_("Unexpected version number in symbol extension table\n"));
12577 const unsigned char * data
= (const unsigned char *) alloced_data
;
12578 const unsigned char * end
= data
+ section
->sh_size
;
12580 if (filedata
->is_separate
)
12581 printf (_("\nIn linked file '%s': "), filedata
->file_name
);
12585 if (ext_data_orig
!= NULL
)
12588 printf (_("LTO Symbol table '%s' and extension table '%s' contain:\n"),
12589 printable_section_name (filedata
, section
),
12590 printable_section_name (filedata
, ext
));
12593 printf (_("LTO Symbol table '%s'\n"),
12594 printable_section_name (filedata
, section
));
12595 printf (_(" and extension table '%s' contain:\n"),
12596 printable_section_name (filedata
, ext
));
12600 printf (_("LTO Symbol table '%s' contains:\n"),
12601 printable_section_name (filedata
, section
));
12603 /* FIXME: Add a wide version. */
12604 if (ext_data_orig
!= NULL
)
12605 printf (_(" Comdat_Key Kind Visibility Size Slot Type Section Name\n"));
12607 printf (_(" Comdat_Key Kind Visibility Size Slot Name\n"));
12609 /* FIXME: We do not handle style prefixes. */
12613 const unsigned char * sym_name
= data
;
12614 data
+= strnlen ((const char *) sym_name
, end
- data
) + 1;
12618 const unsigned char * comdat_key
= data
;
12619 data
+= strnlen ((const char *) comdat_key
, end
- data
) + 1;
12623 if (data
+ 2 + 8 + 4 > end
)
12626 unsigned int kind
= *data
++;
12627 unsigned int visibility
= *data
++;
12629 elf_vma size
= byte_get (data
, 8);
12632 elf_vma slot
= byte_get (data
, 4);
12635 if (ext_data
!= NULL
)
12637 if (ext_data
< (ext_data_end
- 1))
12639 unsigned int sym_type
= * ext_data
++;
12640 unsigned int sec_kind
= * ext_data
++;
12642 printf (" %10s %10s %11s %08lx %08lx %9s %08lx _",
12643 * comdat_key
== 0 ? "-" : (char *) comdat_key
,
12644 get_lto_kind (kind
),
12645 get_lto_visibility (visibility
),
12648 get_lto_sym_type (sym_type
),
12650 print_symbol (6, (const char *) sym_name
);
12654 error (_("Ran out of LTO symbol extension data\n"));
12656 /* FIXME: return FAIL result ? */
12661 printf (" %10s %10s %11s %08lx %08lx _",
12662 * comdat_key
== 0 ? "-" : (char *) comdat_key
,
12663 get_lto_kind (kind
),
12664 get_lto_visibility (visibility
),
12667 print_symbol (21, (const char *) sym_name
);
12672 if (ext_data
!= NULL
&& ext_data
< ext_data_end
)
12674 error (_("Data remains in the LTO symbol extension table\n"));
12678 free (alloced_data
);
12679 free (ext_data_orig
);
12684 error (_("Buffer overrun encountered whilst decoding LTO symbol table\n"));
12685 free (alloced_data
);
12686 free (ext_data_orig
);
12691 /* Display LTO symbol tables. */
12694 process_lto_symbol_tables (Filedata
* filedata
)
12696 Elf_Internal_Shdr
* section
;
12698 bfd_boolean res
= TRUE
;
12703 if (filedata
->section_headers
== NULL
)
12706 for (i
= 0, section
= filedata
->section_headers
;
12707 i
< filedata
->file_header
.e_shnum
;
12709 if (SECTION_NAME_VALID (section
)
12710 && CONST_STRNEQ (SECTION_NAME (section
), ".gnu.lto_.symtab."))
12711 res
&= display_lto_symtab (filedata
, section
);
12716 /* Dump the symbol table. */
12719 process_symbol_table (Filedata
* filedata
)
12721 Elf_Internal_Shdr
* section
;
12723 if (!do_syms
&& !do_dyn_syms
&& !do_histogram
)
12726 if ((filedata
->dynamic_info
[DT_HASH
] || filedata
->dynamic_info_DT_GNU_HASH
)
12728 && do_using_dynamic
12729 && filedata
->dynamic_strings
!= NULL
12730 && filedata
->dynamic_symbols
!= NULL
)
12734 if (filedata
->is_separate
)
12736 printf (ngettext ("\nIn linked file '%s' the dynamic symbol table contains %lu entry:\n",
12737 "\nIn linked file '%s' the dynamic symbol table contains %lu entries:\n",
12738 filedata
->num_dynamic_syms
),
12739 filedata
->file_name
,
12740 filedata
->num_dynamic_syms
);
12744 printf (ngettext ("\nSymbol table for image contains %lu entry:\n",
12745 "\nSymbol table for image contains %lu entries:\n",
12746 filedata
->num_dynamic_syms
),
12747 filedata
->num_dynamic_syms
);
12750 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
12752 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
12754 for (si
= 0; si
< filedata
->num_dynamic_syms
; si
++)
12755 print_dynamic_symbol (filedata
, si
, filedata
->dynamic_symbols
, NULL
,
12756 filedata
->dynamic_strings
,
12757 filedata
->dynamic_strings_length
);
12759 else if ((do_dyn_syms
|| (do_syms
&& !do_using_dynamic
))
12760 && filedata
->section_headers
!= NULL
)
12764 for (i
= 0, section
= filedata
->section_headers
;
12765 i
< filedata
->file_header
.e_shnum
;
12768 char * strtab
= NULL
;
12769 unsigned long int strtab_size
= 0;
12770 Elf_Internal_Sym
* symtab
;
12771 unsigned long si
, num_syms
;
12773 if ((section
->sh_type
!= SHT_SYMTAB
12774 && section
->sh_type
!= SHT_DYNSYM
)
12776 && section
->sh_type
== SHT_SYMTAB
))
12779 if (section
->sh_entsize
== 0)
12781 printf (_("\nSymbol table '%s' has a sh_entsize of zero!\n"),
12782 printable_section_name (filedata
, section
));
12786 num_syms
= section
->sh_size
/ section
->sh_entsize
;
12788 if (filedata
->is_separate
)
12789 printf (ngettext ("\nIn linked file '%s' symbol section '%s' contains %lu entry:\n",
12790 "\nIn linked file '%s' symbol section '%s' contains %lu entries:\n",
12792 filedata
->file_name
,
12793 printable_section_name (filedata
, section
),
12796 printf (ngettext ("\nSymbol table '%s' contains %lu entry:\n",
12797 "\nSymbol table '%s' contains %lu entries:\n",
12799 printable_section_name (filedata
, section
),
12803 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
12805 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
12807 symtab
= GET_ELF_SYMBOLS (filedata
, section
, & num_syms
);
12808 if (symtab
== NULL
)
12811 if (section
->sh_link
== filedata
->file_header
.e_shstrndx
)
12813 strtab
= filedata
->string_table
;
12814 strtab_size
= filedata
->string_table_length
;
12816 else if (section
->sh_link
< filedata
->file_header
.e_shnum
)
12818 Elf_Internal_Shdr
* string_sec
;
12820 string_sec
= filedata
->section_headers
+ section
->sh_link
;
12822 strtab
= (char *) get_data (NULL
, filedata
, string_sec
->sh_offset
,
12823 1, string_sec
->sh_size
,
12824 _("string table"));
12825 strtab_size
= strtab
!= NULL
? string_sec
->sh_size
: 0;
12828 for (si
= 0; si
< num_syms
; si
++)
12829 print_dynamic_symbol (filedata
, si
, symtab
, section
,
12830 strtab
, strtab_size
);
12833 if (strtab
!= filedata
->string_table
)
12839 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
12841 if (do_histogram
&& filedata
->buckets
!= NULL
)
12843 unsigned long * lengths
;
12844 unsigned long * counts
;
12847 unsigned long maxlength
= 0;
12848 unsigned long nzero_counts
= 0;
12849 unsigned long nsyms
= 0;
12852 printf (ngettext ("\nHistogram for bucket list length "
12853 "(total of %lu bucket):\n",
12854 "\nHistogram for bucket list length "
12855 "(total of %lu buckets):\n",
12856 (unsigned long) filedata
->nbuckets
),
12857 (unsigned long) filedata
->nbuckets
);
12859 lengths
= (unsigned long *) calloc (filedata
->nbuckets
,
12860 sizeof (*lengths
));
12861 if (lengths
== NULL
)
12863 error (_("Out of memory allocating space for histogram buckets\n"));
12866 visited
= xcmalloc (filedata
->nchains
, 1);
12867 memset (visited
, 0, filedata
->nchains
);
12869 printf (_(" Length Number %% of total Coverage\n"));
12870 for (hn
= 0; hn
< filedata
->nbuckets
; ++hn
)
12872 for (si
= filedata
->buckets
[hn
]; si
> 0; si
= filedata
->chains
[si
])
12875 if (maxlength
< ++lengths
[hn
])
12877 if (si
>= filedata
->nchains
|| visited
[si
])
12879 error (_("histogram chain is corrupt\n"));
12887 counts
= (unsigned long *) calloc (maxlength
+ 1, sizeof (*counts
));
12888 if (counts
== NULL
)
12891 error (_("Out of memory allocating space for histogram counts\n"));
12895 for (hn
= 0; hn
< filedata
->nbuckets
; ++hn
)
12896 ++counts
[lengths
[hn
]];
12898 if (filedata
->nbuckets
> 0)
12901 printf (" 0 %-10lu (%5.1f%%)\n",
12902 counts
[0], (counts
[0] * 100.0) / filedata
->nbuckets
);
12903 for (i
= 1; i
<= maxlength
; ++i
)
12905 nzero_counts
+= counts
[i
] * i
;
12906 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
12907 i
, counts
[i
], (counts
[i
] * 100.0) / filedata
->nbuckets
,
12908 (nzero_counts
* 100.0) / nsyms
);
12916 free (filedata
->buckets
);
12917 filedata
->buckets
= NULL
;
12918 filedata
->nbuckets
= 0;
12919 free (filedata
->chains
);
12920 filedata
->chains
= NULL
;
12922 if (do_histogram
&& filedata
->gnubuckets
!= NULL
)
12924 unsigned long * lengths
;
12925 unsigned long * counts
;
12927 unsigned long maxlength
= 0;
12928 unsigned long nzero_counts
= 0;
12929 unsigned long nsyms
= 0;
12931 printf (ngettext ("\nHistogram for `%s' bucket list length "
12932 "(total of %lu bucket):\n",
12933 "\nHistogram for `%s' bucket list length "
12934 "(total of %lu buckets):\n",
12935 (unsigned long) filedata
->ngnubuckets
),
12936 GNU_HASH_SECTION_NAME (filedata
),
12937 (unsigned long) filedata
->ngnubuckets
);
12939 lengths
= (unsigned long *) calloc (filedata
->ngnubuckets
,
12940 sizeof (*lengths
));
12941 if (lengths
== NULL
)
12943 error (_("Out of memory allocating space for gnu histogram buckets\n"));
12947 printf (_(" Length Number %% of total Coverage\n"));
12949 for (hn
= 0; hn
< filedata
->ngnubuckets
; ++hn
)
12950 if (filedata
->gnubuckets
[hn
] != 0)
12952 bfd_vma off
, length
= 1;
12954 for (off
= filedata
->gnubuckets
[hn
] - filedata
->gnusymidx
;
12955 /* PR 17531 file: 010-77222-0.004. */
12956 off
< filedata
->ngnuchains
12957 && (filedata
->gnuchains
[off
] & 1) == 0;
12960 lengths
[hn
] = length
;
12961 if (length
> maxlength
)
12962 maxlength
= length
;
12966 counts
= (unsigned long *) calloc (maxlength
+ 1, sizeof (*counts
));
12967 if (counts
== NULL
)
12970 error (_("Out of memory allocating space for gnu histogram counts\n"));
12974 for (hn
= 0; hn
< filedata
->ngnubuckets
; ++hn
)
12975 ++counts
[lengths
[hn
]];
12977 if (filedata
->ngnubuckets
> 0)
12980 printf (" 0 %-10lu (%5.1f%%)\n",
12981 counts
[0], (counts
[0] * 100.0) / filedata
->ngnubuckets
);
12982 for (j
= 1; j
<= maxlength
; ++j
)
12984 nzero_counts
+= counts
[j
] * j
;
12985 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
12986 j
, counts
[j
], (counts
[j
] * 100.0) / filedata
->ngnubuckets
,
12987 (nzero_counts
* 100.0) / nsyms
);
12994 free (filedata
->gnubuckets
);
12995 filedata
->gnubuckets
= NULL
;
12996 filedata
->ngnubuckets
= 0;
12997 free (filedata
->gnuchains
);
12998 filedata
->gnuchains
= NULL
;
12999 filedata
->ngnuchains
= 0;
13000 free (filedata
->mipsxlat
);
13001 filedata
->mipsxlat
= NULL
;
13005 free (filedata
->gnubuckets
);
13006 filedata
->gnubuckets
= NULL
;
13007 filedata
->ngnubuckets
= 0;
13008 free (filedata
->gnuchains
);
13009 filedata
->gnuchains
= NULL
;
13010 filedata
->ngnuchains
= 0;
13011 free (filedata
->mipsxlat
);
13012 filedata
->mipsxlat
= NULL
;
13013 free (filedata
->buckets
);
13014 filedata
->buckets
= NULL
;
13015 filedata
->nbuckets
= 0;
13016 free (filedata
->chains
);
13017 filedata
->chains
= NULL
;
13022 process_syminfo (Filedata
* filedata
)
13026 if (filedata
->dynamic_syminfo
== NULL
13028 /* No syminfo, this is ok. */
13031 /* There better should be a dynamic symbol section. */
13032 if (filedata
->dynamic_symbols
== NULL
|| filedata
->dynamic_strings
== NULL
)
13035 if (filedata
->is_separate
)
13036 printf (ngettext ("\nIn linked file '%s: the dynamic info segment at offset 0x%lx contains %d entry:\n",
13037 "\nIn linked file '%s: the dynamic info segment at offset 0x%lx contains %d entries:\n",
13038 filedata
->dynamic_syminfo_nent
),
13039 filedata
->file_name
,
13040 filedata
->dynamic_syminfo_offset
,
13041 filedata
->dynamic_syminfo_nent
);
13043 printf (ngettext ("\nDynamic info segment at offset 0x%lx "
13044 "contains %d entry:\n",
13045 "\nDynamic info segment at offset 0x%lx "
13046 "contains %d entries:\n",
13047 filedata
->dynamic_syminfo_nent
),
13048 filedata
->dynamic_syminfo_offset
,
13049 filedata
->dynamic_syminfo_nent
);
13051 printf (_(" Num: Name BoundTo Flags\n"));
13052 for (i
= 0; i
< filedata
->dynamic_syminfo_nent
; ++i
)
13054 unsigned short int flags
= filedata
->dynamic_syminfo
[i
].si_flags
;
13056 printf ("%4d: ", i
);
13057 if (i
>= filedata
->num_dynamic_syms
)
13058 printf (_("<corrupt index>"));
13059 else if (VALID_DYNAMIC_NAME (filedata
, filedata
->dynamic_symbols
[i
].st_name
))
13060 print_symbol (30, GET_DYNAMIC_NAME (filedata
,
13061 filedata
->dynamic_symbols
[i
].st_name
));
13063 printf (_("<corrupt: %19ld>"), filedata
->dynamic_symbols
[i
].st_name
);
13066 switch (filedata
->dynamic_syminfo
[i
].si_boundto
)
13068 case SYMINFO_BT_SELF
:
13069 fputs ("SELF ", stdout
);
13071 case SYMINFO_BT_PARENT
:
13072 fputs ("PARENT ", stdout
);
13075 if (filedata
->dynamic_syminfo
[i
].si_boundto
> 0
13076 && filedata
->dynamic_syminfo
[i
].si_boundto
< filedata
->dynamic_nent
13077 && VALID_DYNAMIC_NAME (filedata
,
13078 filedata
->dynamic_section
[filedata
->dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
))
13080 print_symbol (10, GET_DYNAMIC_NAME (filedata
,
13081 filedata
->dynamic_section
[filedata
->dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
));
13085 printf ("%-10d ", filedata
->dynamic_syminfo
[i
].si_boundto
);
13089 if (flags
& SYMINFO_FLG_DIRECT
)
13090 printf (" DIRECT");
13091 if (flags
& SYMINFO_FLG_PASSTHRU
)
13092 printf (" PASSTHRU");
13093 if (flags
& SYMINFO_FLG_COPY
)
13095 if (flags
& SYMINFO_FLG_LAZYLOAD
)
13096 printf (" LAZYLOAD");
13104 /* A macro which evaluates to TRUE if the region ADDR .. ADDR + NELEM
13105 is contained by the region START .. END. The types of ADDR, START
13106 and END should all be the same. Note both ADDR + NELEM and END
13107 point to just beyond the end of the regions that are being tested. */
13108 #define IN_RANGE(START,END,ADDR,NELEM) \
13109 (((ADDR) >= (START)) && ((ADDR) < (END)) && ((ADDR) + (NELEM) <= (END)))
13111 /* Check to see if the given reloc needs to be handled in a target specific
13112 manner. If so then process the reloc and return TRUE otherwise return
13115 If called with reloc == NULL, then this is a signal that reloc processing
13116 for the current section has finished, and any saved state should be
13120 target_specific_reloc_handling (Filedata
* filedata
,
13121 Elf_Internal_Rela
* reloc
,
13122 unsigned char * start
,
13123 unsigned char * end
,
13124 Elf_Internal_Sym
* symtab
,
13125 unsigned long num_syms
)
13127 unsigned int reloc_type
= 0;
13128 unsigned long sym_index
= 0;
13132 reloc_type
= get_reloc_type (filedata
, reloc
->r_info
);
13133 sym_index
= get_reloc_symindex (reloc
->r_info
);
13136 switch (filedata
->file_header
.e_machine
)
13139 case EM_MSP430_OLD
:
13141 static Elf_Internal_Sym
* saved_sym
= NULL
;
13149 switch (reloc_type
)
13151 case 10: /* R_MSP430_SYM_DIFF */
13152 case 12: /* R_MSP430_GNU_SUB_ULEB128 */
13153 if (uses_msp430x_relocs (filedata
))
13155 /* Fall through. */
13156 case 21: /* R_MSP430X_SYM_DIFF */
13157 case 23: /* R_MSP430X_GNU_SUB_ULEB128 */
13159 if (sym_index
>= num_syms
)
13160 error (_("MSP430 SYM_DIFF reloc contains invalid symbol index %lu\n"),
13163 saved_sym
= symtab
+ sym_index
;
13166 case 1: /* R_MSP430_32 or R_MSP430_ABS32 */
13167 case 3: /* R_MSP430_16 or R_MSP430_ABS8 */
13168 goto handle_sym_diff
;
13170 case 5: /* R_MSP430_16_BYTE */
13171 case 9: /* R_MSP430_8 */
13172 case 11: /* R_MSP430_GNU_SET_ULEB128 */
13173 if (uses_msp430x_relocs (filedata
))
13175 goto handle_sym_diff
;
13177 case 2: /* R_MSP430_ABS16 */
13178 case 15: /* R_MSP430X_ABS16 */
13179 case 22: /* R_MSP430X_GNU_SET_ULEB128 */
13180 if (! uses_msp430x_relocs (filedata
))
13182 goto handle_sym_diff
;
13185 if (saved_sym
!= NULL
)
13188 unsigned int reloc_size
= 0;
13190 switch (reloc_type
)
13192 case 1: /* R_MSP430_32 or R_MSP430_ABS32 */
13195 case 11: /* R_MSP430_GNU_SET_ULEB128 */
13196 case 22: /* R_MSP430X_GNU_SET_ULEB128 */
13197 if (reloc
->r_offset
< (size_t) (end
- start
))
13198 read_leb128 (start
+ reloc
->r_offset
, end
, FALSE
,
13199 &reloc_size
, &leb_ret
);
13206 if (leb_ret
!= 0 || reloc_size
== 0 || reloc_size
> 8)
13207 error (_("MSP430 ULEB128 field at 0x%lx contains invalid "
13208 "ULEB128 value\n"),
13209 (long) reloc
->r_offset
);
13210 else if (sym_index
>= num_syms
)
13211 error (_("MSP430 reloc contains invalid symbol index %lu\n"),
13215 value
= reloc
->r_addend
+ (symtab
[sym_index
].st_value
13216 - saved_sym
->st_value
);
13218 if (IN_RANGE (start
, end
, start
+ reloc
->r_offset
, reloc_size
))
13219 byte_put (start
+ reloc
->r_offset
, value
, reloc_size
);
13222 error (_("MSP430 sym diff reloc contains invalid offset: 0x%lx\n"),
13223 (long) reloc
->r_offset
);
13232 if (saved_sym
!= NULL
)
13233 error (_("Unhandled MSP430 reloc type found after SYM_DIFF reloc\n"));
13240 case EM_CYGNUS_MN10300
:
13242 static Elf_Internal_Sym
* saved_sym
= NULL
;
13250 switch (reloc_type
)
13252 case 34: /* R_MN10300_ALIGN */
13254 case 33: /* R_MN10300_SYM_DIFF */
13255 if (sym_index
>= num_syms
)
13256 error (_("MN10300_SYM_DIFF reloc contains invalid symbol index %lu\n"),
13259 saved_sym
= symtab
+ sym_index
;
13262 case 1: /* R_MN10300_32 */
13263 case 2: /* R_MN10300_16 */
13264 if (saved_sym
!= NULL
)
13266 int reloc_size
= reloc_type
== 1 ? 4 : 2;
13269 if (sym_index
>= num_syms
)
13270 error (_("MN10300 reloc contains invalid symbol index %lu\n"),
13274 value
= reloc
->r_addend
+ (symtab
[sym_index
].st_value
13275 - saved_sym
->st_value
);
13277 if (IN_RANGE (start
, end
, start
+ reloc
->r_offset
, reloc_size
))
13278 byte_put (start
+ reloc
->r_offset
, value
, reloc_size
);
13280 error (_("MN10300 sym diff reloc contains invalid offset: 0x%lx\n"),
13281 (long) reloc
->r_offset
);
13289 if (saved_sym
!= NULL
)
13290 error (_("Unhandled MN10300 reloc type found after SYM_DIFF reloc\n"));
13298 static bfd_vma saved_sym1
= 0;
13299 static bfd_vma saved_sym2
= 0;
13300 static bfd_vma value
;
13304 saved_sym1
= saved_sym2
= 0;
13308 switch (reloc_type
)
13310 case 0x80: /* R_RL78_SYM. */
13311 saved_sym1
= saved_sym2
;
13312 if (sym_index
>= num_syms
)
13313 error (_("RL78_SYM reloc contains invalid symbol index %lu\n"),
13317 saved_sym2
= symtab
[sym_index
].st_value
;
13318 saved_sym2
+= reloc
->r_addend
;
13322 case 0x83: /* R_RL78_OPsub. */
13323 value
= saved_sym1
- saved_sym2
;
13324 saved_sym2
= saved_sym1
= 0;
13328 case 0x41: /* R_RL78_ABS32. */
13329 if (IN_RANGE (start
, end
, start
+ reloc
->r_offset
, 4))
13330 byte_put (start
+ reloc
->r_offset
, value
, 4);
13332 error (_("RL78 sym diff reloc contains invalid offset: 0x%lx\n"),
13333 (long) reloc
->r_offset
);
13337 case 0x43: /* R_RL78_ABS16. */
13338 if (IN_RANGE (start
, end
, start
+ reloc
->r_offset
, 2))
13339 byte_put (start
+ reloc
->r_offset
, value
, 2);
13341 error (_("RL78 sym diff reloc contains invalid offset: 0x%lx\n"),
13342 (long) reloc
->r_offset
);
13356 /* Returns TRUE iff RELOC_TYPE is a 32-bit absolute RELA relocation used in
13357 DWARF debug sections. This is a target specific test. Note - we do not
13358 go through the whole including-target-headers-multiple-times route, (as
13359 we have already done with <elf/h8.h>) because this would become very
13360 messy and even then this function would have to contain target specific
13361 information (the names of the relocs instead of their numeric values).
13362 FIXME: This is not the correct way to solve this problem. The proper way
13363 is to have target specific reloc sizing and typing functions created by
13364 the reloc-macros.h header, in the same way that it already creates the
13365 reloc naming functions. */
13368 is_32bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
13370 /* Please keep this table alpha-sorted for ease of visual lookup. */
13371 switch (filedata
->file_header
.e_machine
)
13375 return reloc_type
== 1; /* R_386_32. */
13377 return reloc_type
== 1; /* R_68K_32. */
13379 return reloc_type
== 1; /* R_860_32. */
13381 return reloc_type
== 2; /* R_960_32. */
13383 return (reloc_type
== 258
13384 || reloc_type
== 1); /* R_AARCH64_ABS32 || R_AARCH64_P32_ABS32 */
13386 return reloc_type
== 11; /* R_BPF_DATA_32 */
13387 case EM_ADAPTEVA_EPIPHANY
:
13388 return reloc_type
== 3;
13390 return reloc_type
== 1; /* R_ALPHA_REFLONG. */
13392 return reloc_type
== 1; /* R_ARC_32. */
13393 case EM_ARC_COMPACT
:
13394 case EM_ARC_COMPACT2
:
13395 return reloc_type
== 4; /* R_ARC_32. */
13397 return reloc_type
== 2; /* R_ARM_ABS32 */
13400 return reloc_type
== 1;
13402 return reloc_type
== 0x12; /* R_byte4_data. */
13404 return reloc_type
== 3; /* R_CRIS_32. */
13406 return reloc_type
== 3; /* R_CR16_NUM32. */
13408 return reloc_type
== 15; /* R_CRX_NUM32. */
13410 return reloc_type
== 1; /* R_CKCORE_ADDR32. */
13411 case EM_CYGNUS_FRV
:
13412 return reloc_type
== 1;
13413 case EM_CYGNUS_D10V
:
13415 return reloc_type
== 6; /* R_D10V_32. */
13416 case EM_CYGNUS_D30V
:
13418 return reloc_type
== 12; /* R_D30V_32_NORMAL. */
13420 return reloc_type
== 3; /* R_DLX_RELOC_32. */
13421 case EM_CYGNUS_FR30
:
13423 return reloc_type
== 3; /* R_FR30_32. */
13425 return reloc_type
== 1; /* R_FT32_32. */
13429 return reloc_type
== 1; /* R_H8_DIR32. */
13431 return (reloc_type
== 0x64 /* R_IA64_SECREL32MSB. */
13432 || reloc_type
== 0x65 /* R_IA64_SECREL32LSB. */
13433 || reloc_type
== 0x24 /* R_IA64_DIR32MSB. */
13434 || reloc_type
== 0x25 /* R_IA64_DIR32LSB. */);
13437 return reloc_type
== 2; /* R_IP2K_32. */
13439 return reloc_type
== 2; /* R_IQ2000_32. */
13440 case EM_LATTICEMICO32
:
13441 return reloc_type
== 3; /* R_LM32_32. */
13444 return reloc_type
== 3; /* R_M32C_32. */
13446 return reloc_type
== 34; /* R_M32R_32_RELA. */
13449 return reloc_type
== 6; /* R_M68HC11_32. */
13451 return reloc_type
== 7 || /* R_S12Z_EXT32 */
13452 reloc_type
== 6; /* R_S12Z_CW32. */
13454 return reloc_type
== 1; /* R_MCORE_ADDR32. */
13455 case EM_CYGNUS_MEP
:
13456 return reloc_type
== 4; /* R_MEP_32. */
13458 return reloc_type
== 2; /* R_METAG_ADDR32. */
13459 case EM_MICROBLAZE
:
13460 return reloc_type
== 1; /* R_MICROBLAZE_32. */
13462 return reloc_type
== 2; /* R_MIPS_32. */
13464 return reloc_type
== 4; /* R_MMIX_32. */
13465 case EM_CYGNUS_MN10200
:
13467 return reloc_type
== 1; /* R_MN10200_32. */
13468 case EM_CYGNUS_MN10300
:
13470 return reloc_type
== 1; /* R_MN10300_32. */
13472 return reloc_type
== 1; /* R_MOXIE_32. */
13473 case EM_MSP430_OLD
:
13475 return reloc_type
== 1; /* R_MSP430_32 or R_MSP320_ABS32. */
13477 return reloc_type
== 2; /* R_MT_32. */
13479 return reloc_type
== 20; /* R_NDS32_RELA. */
13480 case EM_ALTERA_NIOS2
:
13481 return reloc_type
== 12; /* R_NIOS2_BFD_RELOC_32. */
13483 return reloc_type
== 1; /* R_NIOS_32. */
13485 return reloc_type
== 1; /* R_OR1K_32. */
13487 return (reloc_type
== 1 /* R_PARISC_DIR32. */
13488 || reloc_type
== 2 /* R_PARISC_DIR21L. */
13489 || reloc_type
== 41); /* R_PARISC_SECREL32. */
13492 return reloc_type
== 1; /* R_PJ_DATA_DIR32. */
13494 return reloc_type
== 1; /* R_PPC64_ADDR32. */
13496 return reloc_type
== 1; /* R_PPC_ADDR32. */
13498 return reloc_type
== 11; /* R_PRU_BFD_RELOC_32. */
13500 return reloc_type
== 1; /* R_RISCV_32. */
13502 return reloc_type
== 1; /* R_RL78_DIR32. */
13504 return reloc_type
== 1; /* R_RX_DIR32. */
13506 return reloc_type
== 1; /* R_I370_ADDR31. */
13509 return reloc_type
== 4; /* R_S390_32. */
13511 return reloc_type
== 8; /* R_SCORE_ABS32. */
13513 return reloc_type
== 1; /* R_SH_DIR32. */
13514 case EM_SPARC32PLUS
:
13517 return reloc_type
== 3 /* R_SPARC_32. */
13518 || reloc_type
== 23; /* R_SPARC_UA32. */
13520 return reloc_type
== 6; /* R_SPU_ADDR32 */
13522 return reloc_type
== 1; /* R_C6000_ABS32. */
13524 return reloc_type
== 2; /* R_TILEGX_32. */
13526 return reloc_type
== 1; /* R_TILEPRO_32. */
13527 case EM_CYGNUS_V850
:
13529 return reloc_type
== 6; /* R_V850_ABS32. */
13531 return reloc_type
== 0x33; /* R_V810_WORD. */
13533 return reloc_type
== 1; /* R_VAX_32. */
13535 return reloc_type
== 3; /* R_VISIUM_32. */
13536 case EM_WEBASSEMBLY
:
13537 return reloc_type
== 1; /* R_WASM32_32. */
13541 return reloc_type
== 10; /* R_X86_64_32. */
13544 return reloc_type
== 3; /* R_XC16C_ABS_32. */
13546 return reloc_type
== 4; /* R_XGATE_32. */
13548 return reloc_type
== 1; /* R_XSTROMY16_32. */
13549 case EM_XTENSA_OLD
:
13551 return reloc_type
== 1; /* R_XTENSA_32. */
13553 return reloc_type
== 6; /* R_Z80_32. */
13556 static unsigned int prev_warn
= 0;
13558 /* Avoid repeating the same warning multiple times. */
13559 if (prev_warn
!= filedata
->file_header
.e_machine
)
13560 error (_("Missing knowledge of 32-bit reloc types used in DWARF sections of machine number %d\n"),
13561 filedata
->file_header
.e_machine
);
13562 prev_warn
= filedata
->file_header
.e_machine
;
13568 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13569 a 32-bit pc-relative RELA relocation used in DWARF debug sections. */
13572 is_32bit_pcrel_reloc (Filedata
* filedata
, unsigned int reloc_type
)
13574 switch (filedata
->file_header
.e_machine
)
13575 /* Please keep this table alpha-sorted for ease of visual lookup. */
13579 return reloc_type
== 2; /* R_386_PC32. */
13581 return reloc_type
== 4; /* R_68K_PC32. */
13583 return reloc_type
== 261; /* R_AARCH64_PREL32 */
13584 case EM_ADAPTEVA_EPIPHANY
:
13585 return reloc_type
== 6;
13587 return reloc_type
== 10; /* R_ALPHA_SREL32. */
13588 case EM_ARC_COMPACT
:
13589 case EM_ARC_COMPACT2
:
13590 return reloc_type
== 49; /* R_ARC_32_PCREL. */
13592 return reloc_type
== 3; /* R_ARM_REL32 */
13595 return reloc_type
== 36; /* R_AVR_32_PCREL. */
13596 case EM_MICROBLAZE
:
13597 return reloc_type
== 2; /* R_MICROBLAZE_32_PCREL. */
13599 return reloc_type
== 9; /* R_OR1K_32_PCREL. */
13601 return reloc_type
== 9; /* R_PARISC_PCREL32. */
13603 return reloc_type
== 26; /* R_PPC_REL32. */
13605 return reloc_type
== 26; /* R_PPC64_REL32. */
13607 return reloc_type
== 57; /* R_RISCV_32_PCREL. */
13610 return reloc_type
== 5; /* R_390_PC32. */
13612 return reloc_type
== 2; /* R_SH_REL32. */
13613 case EM_SPARC32PLUS
:
13616 return reloc_type
== 6; /* R_SPARC_DISP32. */
13618 return reloc_type
== 13; /* R_SPU_REL32. */
13620 return reloc_type
== 6; /* R_TILEGX_32_PCREL. */
13622 return reloc_type
== 4; /* R_TILEPRO_32_PCREL. */
13624 return reloc_type
== 6; /* R_VISIUM_32_PCREL */
13628 return reloc_type
== 2; /* R_X86_64_PC32. */
13630 return reloc_type
== 4; /* R_VAX_PCREL32. */
13631 case EM_XTENSA_OLD
:
13633 return reloc_type
== 14; /* R_XTENSA_32_PCREL. */
13635 /* Do not abort or issue an error message here. Not all targets use
13636 pc-relative 32-bit relocs in their DWARF debug information and we
13637 have already tested for target coverage in is_32bit_abs_reloc. A
13638 more helpful warning message will be generated by apply_relocations
13639 anyway, so just return. */
13644 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13645 a 64-bit absolute RELA relocation used in DWARF debug sections. */
13648 is_64bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
13650 switch (filedata
->file_header
.e_machine
)
13653 return reloc_type
== 257; /* R_AARCH64_ABS64. */
13655 return reloc_type
== 2; /* R_ALPHA_REFQUAD. */
13657 return (reloc_type
== 0x26 /* R_IA64_DIR64MSB. */
13658 || reloc_type
== 0x27 /* R_IA64_DIR64LSB. */);
13660 return reloc_type
== 80; /* R_PARISC_DIR64. */
13662 return reloc_type
== 38; /* R_PPC64_ADDR64. */
13664 return reloc_type
== 2; /* R_RISCV_64. */
13665 case EM_SPARC32PLUS
:
13668 return reloc_type
== 32 /* R_SPARC_64. */
13669 || reloc_type
== 54; /* R_SPARC_UA64. */
13673 return reloc_type
== 1; /* R_X86_64_64. */
13676 return reloc_type
== 22; /* R_S390_64. */
13678 return reloc_type
== 1; /* R_TILEGX_64. */
13680 return reloc_type
== 18; /* R_MIPS_64. */
13686 /* Like is_32bit_pcrel_reloc except that it returns TRUE iff RELOC_TYPE is
13687 a 64-bit pc-relative RELA relocation used in DWARF debug sections. */
13690 is_64bit_pcrel_reloc (Filedata
* filedata
, unsigned int reloc_type
)
13692 switch (filedata
->file_header
.e_machine
)
13695 return reloc_type
== 260; /* R_AARCH64_PREL64. */
13697 return reloc_type
== 11; /* R_ALPHA_SREL64. */
13699 return (reloc_type
== 0x4e /* R_IA64_PCREL64MSB. */
13700 || reloc_type
== 0x4f /* R_IA64_PCREL64LSB. */);
13702 return reloc_type
== 72; /* R_PARISC_PCREL64. */
13704 return reloc_type
== 44; /* R_PPC64_REL64. */
13705 case EM_SPARC32PLUS
:
13708 return reloc_type
== 46; /* R_SPARC_DISP64. */
13712 return reloc_type
== 24; /* R_X86_64_PC64. */
13715 return reloc_type
== 23; /* R_S390_PC64. */
13717 return reloc_type
== 5; /* R_TILEGX_64_PCREL. */
13723 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13724 a 24-bit absolute RELA relocation used in DWARF debug sections. */
13727 is_24bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
13729 switch (filedata
->file_header
.e_machine
)
13731 case EM_CYGNUS_MN10200
:
13733 return reloc_type
== 4; /* R_MN10200_24. */
13735 return reloc_type
== 5; /* R_FT32_20. */
13737 return reloc_type
== 5; /* R_Z80_24. */
13743 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13744 a 16-bit absolute RELA relocation used in DWARF debug sections. */
13747 is_16bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
13749 /* Please keep this table alpha-sorted for ease of visual lookup. */
13750 switch (filedata
->file_header
.e_machine
)
13753 case EM_ARC_COMPACT
:
13754 case EM_ARC_COMPACT2
:
13755 return reloc_type
== 2; /* R_ARC_16. */
13756 case EM_ADAPTEVA_EPIPHANY
:
13757 return reloc_type
== 5;
13760 return reloc_type
== 4; /* R_AVR_16. */
13761 case EM_CYGNUS_D10V
:
13763 return reloc_type
== 3; /* R_D10V_16. */
13765 return reloc_type
== 2; /* R_FT32_16. */
13769 return reloc_type
== R_H8_DIR16
;
13772 return reloc_type
== 1; /* R_IP2K_16. */
13775 return reloc_type
== 1; /* R_M32C_16 */
13776 case EM_CYGNUS_MN10200
:
13778 return reloc_type
== 2; /* R_MN10200_16. */
13779 case EM_CYGNUS_MN10300
:
13781 return reloc_type
== 2; /* R_MN10300_16. */
13783 if (uses_msp430x_relocs (filedata
))
13784 return reloc_type
== 2; /* R_MSP430_ABS16. */
13785 /* Fall through. */
13786 case EM_MSP430_OLD
:
13787 return reloc_type
== 5; /* R_MSP430_16_BYTE. */
13789 return reloc_type
== 19; /* R_NDS32_RELA. */
13790 case EM_ALTERA_NIOS2
:
13791 return reloc_type
== 13; /* R_NIOS2_BFD_RELOC_16. */
13793 return reloc_type
== 9; /* R_NIOS_16. */
13795 return reloc_type
== 2; /* R_OR1K_16. */
13797 return reloc_type
== 55; /* R_RISCV_SET16. */
13799 return reloc_type
== 8; /* R_PRU_BFD_RELOC_16. */
13801 return reloc_type
== 2; /* R_C6000_ABS16. */
13803 return reloc_type
== 2; /* R_VISIUM_16. */
13806 return reloc_type
== 2; /* R_XC16C_ABS_16. */
13808 return reloc_type
== 3; /* R_XGATE_16. */
13810 return reloc_type
== 4; /* R_Z80_16. */
13816 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13817 a 8-bit absolute RELA relocation used in DWARF debug sections. */
13820 is_8bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
13822 switch (filedata
->file_header
.e_machine
)
13825 return reloc_type
== 54; /* R_RISCV_SET8. */
13827 return reloc_type
== 1; /* R_Z80_8. */
13833 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13834 a 6-bit absolute RELA relocation used in DWARF debug sections. */
13837 is_6bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
13839 switch (filedata
->file_header
.e_machine
)
13842 return reloc_type
== 53; /* R_RISCV_SET6. */
13848 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13849 a 32-bit inplace add RELA relocation used in DWARF debug sections. */
13852 is_32bit_inplace_add_reloc (Filedata
* filedata
, unsigned int reloc_type
)
13854 /* Please keep this table alpha-sorted for ease of visual lookup. */
13855 switch (filedata
->file_header
.e_machine
)
13858 return reloc_type
== 35; /* R_RISCV_ADD32. */
13864 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13865 a 32-bit inplace sub RELA relocation used in DWARF debug sections. */
13868 is_32bit_inplace_sub_reloc (Filedata
* filedata
, unsigned int reloc_type
)
13870 /* Please keep this table alpha-sorted for ease of visual lookup. */
13871 switch (filedata
->file_header
.e_machine
)
13874 return reloc_type
== 39; /* R_RISCV_SUB32. */
13880 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13881 a 64-bit inplace add RELA relocation used in DWARF debug sections. */
13884 is_64bit_inplace_add_reloc (Filedata
* filedata
, unsigned int reloc_type
)
13886 /* Please keep this table alpha-sorted for ease of visual lookup. */
13887 switch (filedata
->file_header
.e_machine
)
13890 return reloc_type
== 36; /* R_RISCV_ADD64. */
13896 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13897 a 64-bit inplace sub RELA relocation used in DWARF debug sections. */
13900 is_64bit_inplace_sub_reloc (Filedata
* filedata
, unsigned int reloc_type
)
13902 /* Please keep this table alpha-sorted for ease of visual lookup. */
13903 switch (filedata
->file_header
.e_machine
)
13906 return reloc_type
== 40; /* R_RISCV_SUB64. */
13912 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13913 a 16-bit inplace add RELA relocation used in DWARF debug sections. */
13916 is_16bit_inplace_add_reloc (Filedata
* filedata
, unsigned int reloc_type
)
13918 /* Please keep this table alpha-sorted for ease of visual lookup. */
13919 switch (filedata
->file_header
.e_machine
)
13922 return reloc_type
== 34; /* R_RISCV_ADD16. */
13928 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13929 a 16-bit inplace sub RELA relocation used in DWARF debug sections. */
13932 is_16bit_inplace_sub_reloc (Filedata
* filedata
, unsigned int reloc_type
)
13934 /* Please keep this table alpha-sorted for ease of visual lookup. */
13935 switch (filedata
->file_header
.e_machine
)
13938 return reloc_type
== 38; /* R_RISCV_SUB16. */
13944 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13945 a 8-bit inplace add RELA relocation used in DWARF debug sections. */
13948 is_8bit_inplace_add_reloc (Filedata
* filedata
, unsigned int reloc_type
)
13950 /* Please keep this table alpha-sorted for ease of visual lookup. */
13951 switch (filedata
->file_header
.e_machine
)
13954 return reloc_type
== 33; /* R_RISCV_ADD8. */
13960 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13961 a 8-bit inplace sub RELA relocation used in DWARF debug sections. */
13964 is_8bit_inplace_sub_reloc (Filedata
* filedata
, unsigned int reloc_type
)
13966 /* Please keep this table alpha-sorted for ease of visual lookup. */
13967 switch (filedata
->file_header
.e_machine
)
13970 return reloc_type
== 37; /* R_RISCV_SUB8. */
13976 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13977 a 6-bit inplace sub RELA relocation used in DWARF debug sections. */
13980 is_6bit_inplace_sub_reloc (Filedata
* filedata
, unsigned int reloc_type
)
13982 switch (filedata
->file_header
.e_machine
)
13985 return reloc_type
== 52; /* R_RISCV_SUB6. */
13991 /* Returns TRUE iff RELOC_TYPE is a NONE relocation used for discarded
13992 relocation entries (possibly formerly used for SHT_GROUP sections). */
13995 is_none_reloc (Filedata
* filedata
, unsigned int reloc_type
)
13997 switch (filedata
->file_header
.e_machine
)
13999 case EM_386
: /* R_386_NONE. */
14000 case EM_68K
: /* R_68K_NONE. */
14001 case EM_ADAPTEVA_EPIPHANY
:
14002 case EM_ALPHA
: /* R_ALPHA_NONE. */
14003 case EM_ALTERA_NIOS2
: /* R_NIOS2_NONE. */
14004 case EM_ARC
: /* R_ARC_NONE. */
14005 case EM_ARC_COMPACT2
: /* R_ARC_NONE. */
14006 case EM_ARC_COMPACT
: /* R_ARC_NONE. */
14007 case EM_ARM
: /* R_ARM_NONE. */
14008 case EM_C166
: /* R_XC16X_NONE. */
14009 case EM_CRIS
: /* R_CRIS_NONE. */
14010 case EM_FT32
: /* R_FT32_NONE. */
14011 case EM_IA_64
: /* R_IA64_NONE. */
14012 case EM_K1OM
: /* R_X86_64_NONE. */
14013 case EM_L1OM
: /* R_X86_64_NONE. */
14014 case EM_M32R
: /* R_M32R_NONE. */
14015 case EM_MIPS
: /* R_MIPS_NONE. */
14016 case EM_MN10300
: /* R_MN10300_NONE. */
14017 case EM_MOXIE
: /* R_MOXIE_NONE. */
14018 case EM_NIOS32
: /* R_NIOS_NONE. */
14019 case EM_OR1K
: /* R_OR1K_NONE. */
14020 case EM_PARISC
: /* R_PARISC_NONE. */
14021 case EM_PPC64
: /* R_PPC64_NONE. */
14022 case EM_PPC
: /* R_PPC_NONE. */
14023 case EM_RISCV
: /* R_RISCV_NONE. */
14024 case EM_S390
: /* R_390_NONE. */
14026 case EM_SH
: /* R_SH_NONE. */
14027 case EM_SPARC32PLUS
:
14028 case EM_SPARC
: /* R_SPARC_NONE. */
14030 case EM_TILEGX
: /* R_TILEGX_NONE. */
14031 case EM_TILEPRO
: /* R_TILEPRO_NONE. */
14032 case EM_TI_C6000
:/* R_C6000_NONE. */
14033 case EM_X86_64
: /* R_X86_64_NONE. */
14035 case EM_Z80
: /* R_Z80_NONE. */
14036 case EM_WEBASSEMBLY
: /* R_WASM32_NONE. */
14037 return reloc_type
== 0;
14040 return reloc_type
== 0 || reloc_type
== 256;
14043 return (reloc_type
== 0 /* R_AVR_NONE. */
14044 || reloc_type
== 30 /* R_AVR_DIFF8. */
14045 || reloc_type
== 31 /* R_AVR_DIFF16. */
14046 || reloc_type
== 32 /* R_AVR_DIFF32. */);
14048 return reloc_type
== 3; /* R_METAG_NONE. */
14050 return (reloc_type
== 0 /* R_XTENSA_NONE. */
14051 || reloc_type
== 204 /* R_NDS32_DIFF8. */
14052 || reloc_type
== 205 /* R_NDS32_DIFF16. */
14053 || reloc_type
== 206 /* R_NDS32_DIFF32. */
14054 || reloc_type
== 207 /* R_NDS32_ULEB128. */);
14056 return (reloc_type
== 0 /* R_PRU_NONE. */
14057 || reloc_type
== 65 /* R_PRU_DIFF8. */
14058 || reloc_type
== 66 /* R_PRU_DIFF16. */
14059 || reloc_type
== 67 /* R_PRU_DIFF32. */);
14060 case EM_XTENSA_OLD
:
14062 return (reloc_type
== 0 /* R_XTENSA_NONE. */
14063 || reloc_type
== 17 /* R_XTENSA_DIFF8. */
14064 || reloc_type
== 18 /* R_XTENSA_DIFF16. */
14065 || reloc_type
== 19 /* R_XTENSA_DIFF32. */
14066 || reloc_type
== 57 /* R_XTENSA_PDIFF8. */
14067 || reloc_type
== 58 /* R_XTENSA_PDIFF16. */
14068 || reloc_type
== 59 /* R_XTENSA_PDIFF32. */
14069 || reloc_type
== 60 /* R_XTENSA_NDIFF8. */
14070 || reloc_type
== 61 /* R_XTENSA_NDIFF16. */
14071 || reloc_type
== 62 /* R_XTENSA_NDIFF32. */);
14076 /* Returns TRUE if there is a relocation against
14077 section NAME at OFFSET bytes. */
14080 reloc_at (struct dwarf_section
* dsec
, dwarf_vma offset
)
14082 Elf_Internal_Rela
* relocs
;
14083 Elf_Internal_Rela
* rp
;
14085 if (dsec
== NULL
|| dsec
->reloc_info
== NULL
)
14088 relocs
= (Elf_Internal_Rela
*) dsec
->reloc_info
;
14090 for (rp
= relocs
; rp
< relocs
+ dsec
->num_relocs
; ++rp
)
14091 if (rp
->r_offset
== offset
)
14097 /* Apply relocations to a section.
14098 Returns TRUE upon success, FALSE otherwise.
14099 If RELOCS_RETURN is non-NULL then it is set to point to the loaded relocs.
14100 It is then the caller's responsibility to free them. NUM_RELOCS_RETURN
14101 will be set to the number of relocs loaded.
14103 Note: So far support has been added only for those relocations
14104 which can be found in debug sections. FIXME: Add support for
14105 more relocations ? */
14108 apply_relocations (Filedata
* filedata
,
14109 const Elf_Internal_Shdr
* section
,
14110 unsigned char * start
,
14111 bfd_size_type size
,
14112 void ** relocs_return
,
14113 unsigned long * num_relocs_return
)
14115 Elf_Internal_Shdr
* relsec
;
14116 unsigned char * end
= start
+ size
;
14118 if (relocs_return
!= NULL
)
14120 * (Elf_Internal_Rela
**) relocs_return
= NULL
;
14121 * num_relocs_return
= 0;
14124 if (filedata
->file_header
.e_type
!= ET_REL
)
14125 /* No relocs to apply. */
14128 /* Find the reloc section associated with the section. */
14129 for (relsec
= filedata
->section_headers
;
14130 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
14133 bfd_boolean is_rela
;
14134 unsigned long num_relocs
;
14135 Elf_Internal_Rela
* relocs
;
14136 Elf_Internal_Rela
* rp
;
14137 Elf_Internal_Shdr
* symsec
;
14138 Elf_Internal_Sym
* symtab
;
14139 unsigned long num_syms
;
14140 Elf_Internal_Sym
* sym
;
14142 if ((relsec
->sh_type
!= SHT_RELA
&& relsec
->sh_type
!= SHT_REL
)
14143 || relsec
->sh_info
>= filedata
->file_header
.e_shnum
14144 || filedata
->section_headers
+ relsec
->sh_info
!= section
14145 || relsec
->sh_size
== 0
14146 || relsec
->sh_link
>= filedata
->file_header
.e_shnum
)
14149 symsec
= filedata
->section_headers
+ relsec
->sh_link
;
14150 if (symsec
->sh_type
!= SHT_SYMTAB
14151 && symsec
->sh_type
!= SHT_DYNSYM
)
14154 is_rela
= relsec
->sh_type
== SHT_RELA
;
14158 if (!slurp_rela_relocs (filedata
, relsec
->sh_offset
,
14159 relsec
->sh_size
, & relocs
, & num_relocs
))
14164 if (!slurp_rel_relocs (filedata
, relsec
->sh_offset
,
14165 relsec
->sh_size
, & relocs
, & num_relocs
))
14169 /* SH uses RELA but uses in place value instead of the addend field. */
14170 if (filedata
->file_header
.e_machine
== EM_SH
)
14173 symtab
= GET_ELF_SYMBOLS (filedata
, symsec
, & num_syms
);
14175 for (rp
= relocs
; rp
< relocs
+ num_relocs
; ++rp
)
14178 unsigned int reloc_type
;
14179 unsigned int reloc_size
;
14180 bfd_boolean reloc_inplace
= FALSE
;
14181 bfd_boolean reloc_subtract
= FALSE
;
14182 unsigned char * rloc
;
14183 unsigned long sym_index
;
14185 reloc_type
= get_reloc_type (filedata
, rp
->r_info
);
14187 if (target_specific_reloc_handling (filedata
, rp
, start
, end
, symtab
, num_syms
))
14189 else if (is_none_reloc (filedata
, reloc_type
))
14191 else if (is_32bit_abs_reloc (filedata
, reloc_type
)
14192 || is_32bit_pcrel_reloc (filedata
, reloc_type
))
14194 else if (is_64bit_abs_reloc (filedata
, reloc_type
)
14195 || is_64bit_pcrel_reloc (filedata
, reloc_type
))
14197 else if (is_24bit_abs_reloc (filedata
, reloc_type
))
14199 else if (is_16bit_abs_reloc (filedata
, reloc_type
))
14201 else if (is_8bit_abs_reloc (filedata
, reloc_type
)
14202 || is_6bit_abs_reloc (filedata
, reloc_type
))
14204 else if ((reloc_subtract
= is_32bit_inplace_sub_reloc (filedata
,
14206 || is_32bit_inplace_add_reloc (filedata
, reloc_type
))
14209 reloc_inplace
= TRUE
;
14211 else if ((reloc_subtract
= is_64bit_inplace_sub_reloc (filedata
,
14213 || is_64bit_inplace_add_reloc (filedata
, reloc_type
))
14216 reloc_inplace
= TRUE
;
14218 else if ((reloc_subtract
= is_16bit_inplace_sub_reloc (filedata
,
14220 || is_16bit_inplace_add_reloc (filedata
, reloc_type
))
14223 reloc_inplace
= TRUE
;
14225 else if ((reloc_subtract
= is_8bit_inplace_sub_reloc (filedata
,
14227 || is_8bit_inplace_add_reloc (filedata
, reloc_type
))
14230 reloc_inplace
= TRUE
;
14232 else if ((reloc_subtract
= is_6bit_inplace_sub_reloc (filedata
,
14236 reloc_inplace
= TRUE
;
14240 static unsigned int prev_reloc
= 0;
14242 if (reloc_type
!= prev_reloc
)
14243 warn (_("unable to apply unsupported reloc type %d to section %s\n"),
14244 reloc_type
, printable_section_name (filedata
, section
));
14245 prev_reloc
= reloc_type
;
14249 rloc
= start
+ rp
->r_offset
;
14250 if (!IN_RANGE (start
, end
, rloc
, reloc_size
))
14252 warn (_("skipping invalid relocation offset 0x%lx in section %s\n"),
14253 (unsigned long) rp
->r_offset
,
14254 printable_section_name (filedata
, section
));
14258 sym_index
= (unsigned long) get_reloc_symindex (rp
->r_info
);
14259 if (sym_index
>= num_syms
)
14261 warn (_("skipping invalid relocation symbol index 0x%lx in section %s\n"),
14262 sym_index
, printable_section_name (filedata
, section
));
14265 sym
= symtab
+ sym_index
;
14267 /* If the reloc has a symbol associated with it,
14268 make sure that it is of an appropriate type.
14270 Relocations against symbols without type can happen.
14271 Gcc -feliminate-dwarf2-dups may generate symbols
14272 without type for debug info.
14274 Icc generates relocations against function symbols
14275 instead of local labels.
14277 Relocations against object symbols can happen, eg when
14278 referencing a global array. For an example of this see
14279 the _clz.o binary in libgcc.a. */
14281 && ELF_ST_TYPE (sym
->st_info
) != STT_COMMON
14282 && ELF_ST_TYPE (sym
->st_info
) > STT_SECTION
)
14284 warn (_("skipping unexpected symbol type %s in section %s relocation %ld\n"),
14285 get_symbol_type (filedata
, ELF_ST_TYPE (sym
->st_info
)),
14286 printable_section_name (filedata
, relsec
),
14287 (long int)(rp
- relocs
));
14293 addend
+= rp
->r_addend
;
14294 /* R_XTENSA_32, R_PJ_DATA_DIR32 and R_D30V_32_NORMAL are
14295 partial_inplace. */
14297 || (filedata
->file_header
.e_machine
== EM_XTENSA
14298 && reloc_type
== 1)
14299 || ((filedata
->file_header
.e_machine
== EM_PJ
14300 || filedata
->file_header
.e_machine
== EM_PJ_OLD
)
14301 && reloc_type
== 1)
14302 || ((filedata
->file_header
.e_machine
== EM_D30V
14303 || filedata
->file_header
.e_machine
== EM_CYGNUS_D30V
)
14304 && reloc_type
== 12)
14307 if (is_6bit_inplace_sub_reloc (filedata
, reloc_type
))
14308 addend
+= byte_get (rloc
, reloc_size
) & 0x3f;
14310 addend
+= byte_get (rloc
, reloc_size
);
14313 if (is_32bit_pcrel_reloc (filedata
, reloc_type
)
14314 || is_64bit_pcrel_reloc (filedata
, reloc_type
))
14316 /* On HPPA, all pc-relative relocations are biased by 8. */
14317 if (filedata
->file_header
.e_machine
== EM_PARISC
)
14319 byte_put (rloc
, (addend
+ sym
->st_value
) - rp
->r_offset
,
14322 else if (is_6bit_abs_reloc (filedata
, reloc_type
)
14323 || is_6bit_inplace_sub_reloc (filedata
, reloc_type
))
14325 if (reloc_subtract
)
14326 addend
-= sym
->st_value
;
14328 addend
+= sym
->st_value
;
14329 addend
= (addend
& 0x3f) | (byte_get (rloc
, reloc_size
) & 0xc0);
14330 byte_put (rloc
, addend
, reloc_size
);
14332 else if (reloc_subtract
)
14333 byte_put (rloc
, addend
- sym
->st_value
, reloc_size
);
14335 byte_put (rloc
, addend
+ sym
->st_value
, reloc_size
);
14339 /* Let the target specific reloc processing code know that
14340 we have finished with these relocs. */
14341 target_specific_reloc_handling (filedata
, NULL
, NULL
, NULL
, NULL
, 0);
14345 * (Elf_Internal_Rela
**) relocs_return
= relocs
;
14346 * num_relocs_return
= num_relocs
;
14357 #ifdef SUPPORT_DISASSEMBLY
14359 disassemble_section (Elf_Internal_Shdr
* section
, Filedata
* filedata
)
14361 printf (_("\nAssembly dump of section %s\n"), printable_section_name (filedata
, section
));
14363 /* FIXME: XXX -- to be done --- XXX */
14369 /* Reads in the contents of SECTION from FILE, returning a pointer
14370 to a malloc'ed buffer or NULL if something went wrong. */
14373 get_section_contents (Elf_Internal_Shdr
* section
, Filedata
* filedata
)
14375 bfd_size_type num_bytes
= section
->sh_size
;
14377 if (num_bytes
== 0 || section
->sh_type
== SHT_NOBITS
)
14379 printf (_("Section '%s' has no data to dump.\n"),
14380 printable_section_name (filedata
, section
));
14384 return (char *) get_data (NULL
, filedata
, section
->sh_offset
, 1, num_bytes
,
14385 _("section contents"));
14388 /* Uncompresses a section that was compressed using zlib, in place. */
14391 uncompress_section_contents (unsigned char ** buffer
,
14392 dwarf_size_type uncompressed_size
,
14393 dwarf_size_type
* size
)
14395 dwarf_size_type compressed_size
= *size
;
14396 unsigned char * compressed_buffer
= *buffer
;
14397 unsigned char * uncompressed_buffer
;
14401 /* It is possible the section consists of several compressed
14402 buffers concatenated together, so we uncompress in a loop. */
14403 /* PR 18313: The state field in the z_stream structure is supposed
14404 to be invisible to the user (ie us), but some compilers will
14405 still complain about it being used without initialisation. So
14406 we first zero the entire z_stream structure and then set the fields
14408 memset (& strm
, 0, sizeof strm
);
14409 strm
.avail_in
= compressed_size
;
14410 strm
.next_in
= (Bytef
*) compressed_buffer
;
14411 strm
.avail_out
= uncompressed_size
;
14412 uncompressed_buffer
= (unsigned char *) xmalloc (uncompressed_size
);
14414 rc
= inflateInit (& strm
);
14415 while (strm
.avail_in
> 0)
14419 strm
.next_out
= ((Bytef
*) uncompressed_buffer
14420 + (uncompressed_size
- strm
.avail_out
));
14421 rc
= inflate (&strm
, Z_FINISH
);
14422 if (rc
!= Z_STREAM_END
)
14424 rc
= inflateReset (& strm
);
14426 if (inflateEnd (& strm
) != Z_OK
14428 || strm
.avail_out
!= 0)
14431 *buffer
= uncompressed_buffer
;
14432 *size
= uncompressed_size
;
14436 free (uncompressed_buffer
);
14437 /* Indicate decompression failure. */
14443 dump_section_as_strings (Elf_Internal_Shdr
* section
, Filedata
* filedata
)
14445 Elf_Internal_Shdr
* relsec
;
14446 bfd_size_type num_bytes
;
14447 unsigned char * data
;
14448 unsigned char * end
;
14449 unsigned char * real_start
;
14450 unsigned char * start
;
14451 bfd_boolean some_strings_shown
;
14453 real_start
= start
= (unsigned char *) get_section_contents (section
, filedata
);
14455 /* PR 21820: Do not fail if the section was empty. */
14456 return (section
->sh_size
== 0 || section
->sh_type
== SHT_NOBITS
) ? TRUE
: FALSE
;
14458 num_bytes
= section
->sh_size
;
14460 printf (_("\nString dump of section '%s':\n"), printable_section_name (filedata
, section
));
14462 if (decompress_dumps
)
14464 dwarf_size_type new_size
= num_bytes
;
14465 dwarf_size_type uncompressed_size
= 0;
14467 if ((section
->sh_flags
& SHF_COMPRESSED
) != 0)
14469 Elf_Internal_Chdr chdr
;
14470 unsigned int compression_header_size
14471 = get_compression_header (& chdr
, (unsigned char *) start
,
14473 if (compression_header_size
== 0)
14474 /* An error message will have already been generated
14475 by get_compression_header. */
14478 if (chdr
.ch_type
!= ELFCOMPRESS_ZLIB
)
14480 warn (_("section '%s' has unsupported compress type: %d\n"),
14481 printable_section_name (filedata
, section
), chdr
.ch_type
);
14484 uncompressed_size
= chdr
.ch_size
;
14485 start
+= compression_header_size
;
14486 new_size
-= compression_header_size
;
14488 else if (new_size
> 12 && streq ((char *) start
, "ZLIB"))
14490 /* Read the zlib header. In this case, it should be "ZLIB"
14491 followed by the uncompressed section size, 8 bytes in
14492 big-endian order. */
14493 uncompressed_size
= start
[4]; uncompressed_size
<<= 8;
14494 uncompressed_size
+= start
[5]; uncompressed_size
<<= 8;
14495 uncompressed_size
+= start
[6]; uncompressed_size
<<= 8;
14496 uncompressed_size
+= start
[7]; uncompressed_size
<<= 8;
14497 uncompressed_size
+= start
[8]; uncompressed_size
<<= 8;
14498 uncompressed_size
+= start
[9]; uncompressed_size
<<= 8;
14499 uncompressed_size
+= start
[10]; uncompressed_size
<<= 8;
14500 uncompressed_size
+= start
[11];
14505 if (uncompressed_size
)
14507 if (uncompress_section_contents (& start
,
14508 uncompressed_size
, & new_size
))
14509 num_bytes
= new_size
;
14512 error (_("Unable to decompress section %s\n"),
14513 printable_section_name (filedata
, section
));
14518 start
= real_start
;
14521 /* If the section being dumped has relocations against it the user might
14522 be expecting these relocations to have been applied. Check for this
14523 case and issue a warning message in order to avoid confusion.
14524 FIXME: Maybe we ought to have an option that dumps a section with
14525 relocs applied ? */
14526 for (relsec
= filedata
->section_headers
;
14527 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
14530 if ((relsec
->sh_type
!= SHT_RELA
&& relsec
->sh_type
!= SHT_REL
)
14531 || relsec
->sh_info
>= filedata
->file_header
.e_shnum
14532 || filedata
->section_headers
+ relsec
->sh_info
!= section
14533 || relsec
->sh_size
== 0
14534 || relsec
->sh_link
>= filedata
->file_header
.e_shnum
)
14537 printf (_(" Note: This section has relocations against it, but these have NOT been applied to this dump.\n"));
14542 end
= start
+ num_bytes
;
14543 some_strings_shown
= FALSE
;
14545 #ifdef HAVE_MBSTATE_T
14547 /* Initialise the multibyte conversion state. */
14548 memset (& state
, 0, sizeof (state
));
14551 bfd_boolean continuing
= FALSE
;
14555 while (!ISPRINT (* data
))
14556 if (++ data
>= end
)
14561 size_t maxlen
= end
- data
;
14566 continuing
= FALSE
;
14570 printf (" [%6lx] ", (unsigned long) (data
- start
));
14584 /* PR 25543: Treat new-lines as string-ending characters. */
14593 /* Do not print control characters directly as they can affect terminal
14594 settings. Such characters usually appear in the names generated
14595 by the assembler for local labels. */
14598 printf ("^%c", c
+ 0x40);
14600 else if (ISPRINT (c
))
14607 #ifdef HAVE_MBSTATE_T
14610 /* Let printf do the hard work of displaying multibyte characters. */
14611 printf ("%.1s", data
- 1);
14612 #ifdef HAVE_MBSTATE_T
14613 /* Try to find out how many bytes made up the character that was
14614 just printed. Advance the symbol pointer past the bytes that
14616 n
= mbrtowc (& w
, (char *)(data
- 1), MB_CUR_MAX
, & state
);
14620 if (n
!= (size_t) -1 && n
!= (size_t) -2 && n
> 0)
14630 printf (_("<corrupt>\n"));
14633 some_strings_shown
= TRUE
;
14637 if (! some_strings_shown
)
14638 printf (_(" No strings found in this section."));
14651 dump_section_as_bytes (Elf_Internal_Shdr
* section
,
14652 Filedata
* filedata
,
14653 bfd_boolean relocate
)
14655 Elf_Internal_Shdr
* relsec
;
14656 bfd_size_type bytes
;
14657 bfd_size_type section_size
;
14659 unsigned char * data
;
14660 unsigned char * real_start
;
14661 unsigned char * start
;
14663 real_start
= start
= (unsigned char *) get_section_contents (section
, filedata
);
14665 /* PR 21820: Do not fail if the section was empty. */
14666 return (section
->sh_size
== 0 || section
->sh_type
== SHT_NOBITS
) ? TRUE
: FALSE
;
14668 section_size
= section
->sh_size
;
14670 printf (_("\nHex dump of section '%s':\n"), printable_section_name (filedata
, section
));
14672 if (decompress_dumps
)
14674 dwarf_size_type new_size
= section_size
;
14675 dwarf_size_type uncompressed_size
= 0;
14677 if ((section
->sh_flags
& SHF_COMPRESSED
) != 0)
14679 Elf_Internal_Chdr chdr
;
14680 unsigned int compression_header_size
14681 = get_compression_header (& chdr
, start
, section_size
);
14683 if (compression_header_size
== 0)
14684 /* An error message will have already been generated
14685 by get_compression_header. */
14688 if (chdr
.ch_type
!= ELFCOMPRESS_ZLIB
)
14690 warn (_("section '%s' has unsupported compress type: %d\n"),
14691 printable_section_name (filedata
, section
), chdr
.ch_type
);
14694 uncompressed_size
= chdr
.ch_size
;
14695 start
+= compression_header_size
;
14696 new_size
-= compression_header_size
;
14698 else if (new_size
> 12 && streq ((char *) start
, "ZLIB"))
14700 /* Read the zlib header. In this case, it should be "ZLIB"
14701 followed by the uncompressed section size, 8 bytes in
14702 big-endian order. */
14703 uncompressed_size
= start
[4]; uncompressed_size
<<= 8;
14704 uncompressed_size
+= start
[5]; uncompressed_size
<<= 8;
14705 uncompressed_size
+= start
[6]; uncompressed_size
<<= 8;
14706 uncompressed_size
+= start
[7]; uncompressed_size
<<= 8;
14707 uncompressed_size
+= start
[8]; uncompressed_size
<<= 8;
14708 uncompressed_size
+= start
[9]; uncompressed_size
<<= 8;
14709 uncompressed_size
+= start
[10]; uncompressed_size
<<= 8;
14710 uncompressed_size
+= start
[11];
14715 if (uncompressed_size
)
14717 if (uncompress_section_contents (& start
, uncompressed_size
,
14720 section_size
= new_size
;
14724 error (_("Unable to decompress section %s\n"),
14725 printable_section_name (filedata
, section
));
14726 /* FIXME: Print the section anyway ? */
14731 start
= real_start
;
14736 if (! apply_relocations (filedata
, section
, start
, section_size
, NULL
, NULL
))
14741 /* If the section being dumped has relocations against it the user might
14742 be expecting these relocations to have been applied. Check for this
14743 case and issue a warning message in order to avoid confusion.
14744 FIXME: Maybe we ought to have an option that dumps a section with
14745 relocs applied ? */
14746 for (relsec
= filedata
->section_headers
;
14747 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
14750 if ((relsec
->sh_type
!= SHT_RELA
&& relsec
->sh_type
!= SHT_REL
)
14751 || relsec
->sh_info
>= filedata
->file_header
.e_shnum
14752 || filedata
->section_headers
+ relsec
->sh_info
!= section
14753 || relsec
->sh_size
== 0
14754 || relsec
->sh_link
>= filedata
->file_header
.e_shnum
)
14757 printf (_(" NOTE: This section has relocations against it, but these have NOT been applied to this dump.\n"));
14762 addr
= section
->sh_addr
;
14763 bytes
= section_size
;
14772 lbytes
= (bytes
> 16 ? 16 : bytes
);
14774 printf (" 0x%8.8lx ", (unsigned long) addr
);
14776 for (j
= 0; j
< 16; j
++)
14779 printf ("%2.2x", data
[j
]);
14787 for (j
= 0; j
< lbytes
; j
++)
14790 if (k
>= ' ' && k
< 0x7f)
14813 #ifdef ENABLE_LIBCTF
14814 static ctf_sect_t
*
14815 shdr_to_ctf_sect (ctf_sect_t
*buf
, Elf_Internal_Shdr
*shdr
, Filedata
*filedata
)
14817 buf
->cts_name
= SECTION_NAME_PRINT (shdr
);
14818 buf
->cts_size
= shdr
->sh_size
;
14819 buf
->cts_entsize
= shdr
->sh_entsize
;
14824 /* Formatting callback function passed to ctf_dump. Returns either the pointer
14825 it is passed, or a pointer to newly-allocated storage, in which case
14826 dump_ctf() will free it when it no longer needs it. */
14829 dump_ctf_indent_lines (ctf_sect_names_t sect ATTRIBUTE_UNUSED
,
14830 char *s
, void *arg
)
14832 const char *blanks
= arg
;
14835 if (asprintf (&new_s
, "%s%s", blanks
, s
) < 0)
14840 /* Dump CTF errors/warnings. */
14842 dump_ctf_errs (ctf_dict_t
*fp
)
14844 ctf_next_t
*it
= NULL
;
14849 /* Dump accumulated errors and warnings. */
14850 while ((errtext
= ctf_errwarning_next (fp
, &it
, &is_warning
, &err
)) != NULL
)
14852 error (_("%s: %s"), is_warning
? _("warning"): _("error"),
14856 if (err
!= ECTF_NEXT_END
)
14857 error (_("CTF error: cannot get CTF errors: `%s'"), ctf_errmsg (err
));
14860 /* Dump one CTF archive member. */
14863 dump_ctf_archive_member (ctf_dict_t
*ctf
, const char *name
, void *arg
)
14865 ctf_dict_t
*parent
= (ctf_dict_t
*) arg
;
14866 const char *things
[] = {"Header", "Labels", "Data objects",
14867 "Function objects", "Variables", "Types", "Strings",
14869 const char **thing
;
14873 /* Only print out the name of non-default-named archive members.
14874 The name .ctf appears everywhere, even for things that aren't
14875 really archives, so printing it out is liable to be confusing.
14877 The parent, if there is one, is the default-owned archive member:
14878 avoid importing it into itself. (This does no harm, but looks
14881 if (strcmp (name
, ".ctf") != 0)
14883 printf (_("\nCTF archive member: %s:\n"), name
);
14884 ctf_import (ctf
, parent
);
14887 for (i
= 0, thing
= things
; *thing
[0]; thing
++, i
++)
14889 ctf_dump_state_t
*s
= NULL
;
14892 printf ("\n %s:\n", *thing
);
14893 while ((item
= ctf_dump (ctf
, &s
, i
, dump_ctf_indent_lines
,
14894 (void *) " ")) != NULL
)
14896 printf ("%s\n", item
);
14900 if (ctf_errno (ctf
))
14902 error (_("Iteration failed: %s, %s\n"), *thing
,
14903 ctf_errmsg (ctf_errno (ctf
)));
14910 dump_ctf_errs (ctf
);
14915 dump_section_as_ctf (Elf_Internal_Shdr
* section
, Filedata
* filedata
)
14917 Elf_Internal_Shdr
* parent_sec
= NULL
;
14918 Elf_Internal_Shdr
* symtab_sec
= NULL
;
14919 Elf_Internal_Shdr
* strtab_sec
= NULL
;
14920 void * data
= NULL
;
14921 void * symdata
= NULL
;
14922 void * strdata
= NULL
;
14923 void * parentdata
= NULL
;
14924 ctf_sect_t ctfsect
, symsect
, strsect
, parentsect
;
14925 ctf_sect_t
* symsectp
= NULL
;
14926 ctf_sect_t
* strsectp
= NULL
;
14927 ctf_archive_t
* ctfa
= NULL
;
14928 ctf_archive_t
* parenta
= NULL
, *lookparent
;
14929 ctf_dict_t
* parent
= NULL
;
14932 bfd_boolean ret
= FALSE
;
14934 shdr_to_ctf_sect (&ctfsect
, section
, filedata
);
14935 data
= get_section_contents (section
, filedata
);
14936 ctfsect
.cts_data
= data
;
14938 if (!dump_ctf_symtab_name
)
14939 dump_ctf_symtab_name
= strdup (".dynsym");
14941 if (!dump_ctf_strtab_name
)
14942 dump_ctf_strtab_name
= strdup (".dynstr");
14944 if (dump_ctf_symtab_name
&& dump_ctf_symtab_name
[0] != 0)
14946 if ((symtab_sec
= find_section (filedata
, dump_ctf_symtab_name
)) == NULL
)
14948 error (_("No symbol section named %s\n"), dump_ctf_symtab_name
);
14951 if ((symdata
= (void *) get_data (NULL
, filedata
,
14952 symtab_sec
->sh_offset
, 1,
14953 symtab_sec
->sh_size
,
14954 _("symbols"))) == NULL
)
14956 symsectp
= shdr_to_ctf_sect (&symsect
, symtab_sec
, filedata
);
14957 symsect
.cts_data
= symdata
;
14959 if (dump_ctf_strtab_name
&& dump_ctf_strtab_name
[0] != 0)
14961 if ((strtab_sec
= find_section (filedata
, dump_ctf_strtab_name
)) == NULL
)
14963 error (_("No string table section named %s\n"),
14964 dump_ctf_strtab_name
);
14967 if ((strdata
= (void *) get_data (NULL
, filedata
,
14968 strtab_sec
->sh_offset
, 1,
14969 strtab_sec
->sh_size
,
14970 _("strings"))) == NULL
)
14972 strsectp
= shdr_to_ctf_sect (&strsect
, strtab_sec
, filedata
);
14973 strsect
.cts_data
= strdata
;
14975 if (dump_ctf_parent_name
)
14977 if ((parent_sec
= find_section (filedata
, dump_ctf_parent_name
)) == NULL
)
14979 error (_("No CTF parent section named %s\n"), dump_ctf_parent_name
);
14982 if ((parentdata
= (void *) get_data (NULL
, filedata
,
14983 parent_sec
->sh_offset
, 1,
14984 parent_sec
->sh_size
,
14985 _("CTF parent"))) == NULL
)
14987 shdr_to_ctf_sect (&parentsect
, parent_sec
, filedata
);
14988 parentsect
.cts_data
= parentdata
;
14991 /* Load the CTF file and dump it. It may be a raw CTF section, or an archive:
14992 libctf papers over the difference, so we can pretend it is always an
14993 archive. Possibly open the parent as well, if one was specified. */
14995 if ((ctfa
= ctf_arc_bufopen (&ctfsect
, symsectp
, strsectp
, &err
)) == NULL
)
14997 dump_ctf_errs (NULL
);
14998 error (_("CTF open failure: %s\n"), ctf_errmsg (err
));
15002 ctf_arc_symsect_endianness (ctfa
, filedata
->file_header
.e_ident
[EI_DATA
]
15007 if ((parenta
= ctf_arc_bufopen (&parentsect
, symsectp
, strsectp
,
15010 dump_ctf_errs (NULL
);
15011 error (_("CTF open failure: %s\n"), ctf_errmsg (err
));
15014 lookparent
= parenta
;
15019 /* Assume that the applicable parent archive member is the default one.
15020 (This is what all known implementations are expected to do, if they
15021 put CTFs and their parents in archives together.) */
15022 if ((parent
= ctf_dict_open (lookparent
, NULL
, &err
)) == NULL
)
15024 dump_ctf_errs (NULL
);
15025 error (_("CTF open failure: %s\n"), ctf_errmsg (err
));
15031 printf (_("\nDump of CTF section '%s':\n"),
15032 printable_section_name (filedata
, section
));
15034 if ((err
= ctf_archive_iter (ctfa
, dump_ctf_archive_member
, parent
)) != 0)
15036 dump_ctf_errs (NULL
);
15037 error (_("CTF member open failure: %s\n"), ctf_errmsg (err
));
15042 ctf_dict_close (parent
);
15044 ctf_close (parenta
);
15054 load_specific_debug_section (enum dwarf_section_display_enum debug
,
15055 const Elf_Internal_Shdr
* sec
,
15058 struct dwarf_section
* section
= &debug_displays
[debug
].section
;
15060 Filedata
* filedata
= (Filedata
*) data
;
15062 if (section
->start
!= NULL
)
15064 /* If it is already loaded, do nothing. */
15065 if (streq (section
->filename
, filedata
->file_name
))
15067 free (section
->start
);
15070 snprintf (buf
, sizeof (buf
), _("%s section data"), section
->name
);
15071 section
->address
= sec
->sh_addr
;
15072 section
->filename
= filedata
->file_name
;
15073 section
->start
= (unsigned char *) get_data (NULL
, filedata
,
15075 sec
->sh_size
, buf
);
15076 if (section
->start
== NULL
)
15080 unsigned char *start
= section
->start
;
15081 dwarf_size_type size
= sec
->sh_size
;
15082 dwarf_size_type uncompressed_size
= 0;
15084 if ((sec
->sh_flags
& SHF_COMPRESSED
) != 0)
15086 Elf_Internal_Chdr chdr
;
15087 unsigned int compression_header_size
;
15089 if (size
< (is_32bit_elf
15090 ? sizeof (Elf32_External_Chdr
)
15091 : sizeof (Elf64_External_Chdr
)))
15093 warn (_("compressed section %s is too small to contain a compression header\n"),
15098 compression_header_size
= get_compression_header (&chdr
, start
, size
);
15099 if (compression_header_size
== 0)
15100 /* An error message will have already been generated
15101 by get_compression_header. */
15104 if (chdr
.ch_type
!= ELFCOMPRESS_ZLIB
)
15106 warn (_("section '%s' has unsupported compress type: %d\n"),
15107 section
->name
, chdr
.ch_type
);
15110 uncompressed_size
= chdr
.ch_size
;
15111 start
+= compression_header_size
;
15112 size
-= compression_header_size
;
15114 else if (size
> 12 && streq ((char *) start
, "ZLIB"))
15116 /* Read the zlib header. In this case, it should be "ZLIB"
15117 followed by the uncompressed section size, 8 bytes in
15118 big-endian order. */
15119 uncompressed_size
= start
[4]; uncompressed_size
<<= 8;
15120 uncompressed_size
+= start
[5]; uncompressed_size
<<= 8;
15121 uncompressed_size
+= start
[6]; uncompressed_size
<<= 8;
15122 uncompressed_size
+= start
[7]; uncompressed_size
<<= 8;
15123 uncompressed_size
+= start
[8]; uncompressed_size
<<= 8;
15124 uncompressed_size
+= start
[9]; uncompressed_size
<<= 8;
15125 uncompressed_size
+= start
[10]; uncompressed_size
<<= 8;
15126 uncompressed_size
+= start
[11];
15131 if (uncompressed_size
)
15133 if (uncompress_section_contents (&start
, uncompressed_size
,
15136 /* Free the compressed buffer, update the section buffer
15137 and the section size if uncompress is successful. */
15138 free (section
->start
);
15139 section
->start
= start
;
15143 error (_("Unable to decompress section %s\n"),
15144 printable_section_name (filedata
, sec
));
15149 section
->size
= size
;
15152 if (section
->start
== NULL
)
15155 if (debug_displays
[debug
].relocate
)
15157 if (! apply_relocations (filedata
, sec
, section
->start
, section
->size
,
15158 & section
->reloc_info
, & section
->num_relocs
))
15163 section
->reloc_info
= NULL
;
15164 section
->num_relocs
= 0;
15170 #if HAVE_LIBDEBUGINFOD
15171 /* Return a hex string representation of the build-id. */
15173 get_build_id (void * data
)
15175 Filedata
* filedata
= (Filedata
*) data
;
15176 Elf_Internal_Shdr
* shdr
;
15179 /* Iterate through notes to find note.gnu.build-id.
15180 FIXME: Only the first note in any note section is examined. */
15181 for (i
= 0, shdr
= filedata
->section_headers
;
15182 i
< filedata
->file_header
.e_shnum
&& shdr
!= NULL
;
15185 if (shdr
->sh_type
!= SHT_NOTE
)
15190 size_t data_remaining
;
15192 Elf_External_Note
* enote
;
15193 Elf_Internal_Note inote
;
15195 bfd_vma offset
= shdr
->sh_offset
;
15196 bfd_vma align
= shdr
->sh_addralign
;
15197 bfd_vma length
= shdr
->sh_size
;
15199 enote
= (Elf_External_Note
*) get_section_contents (shdr
, filedata
);
15205 else if (align
!= 4 && align
!= 8)
15211 end
= (char *) enote
+ length
;
15212 data_remaining
= end
- (char *) enote
;
15214 if (!is_ia64_vms (filedata
))
15216 min_notesz
= offsetof (Elf_External_Note
, name
);
15217 if (data_remaining
< min_notesz
)
15220 malformed note encountered in section %s whilst scanning for build-id note\n"),
15221 printable_section_name (filedata
, shdr
));
15225 data_remaining
-= min_notesz
;
15227 inote
.type
= BYTE_GET (enote
->type
);
15228 inote
.namesz
= BYTE_GET (enote
->namesz
);
15229 inote
.namedata
= enote
->name
;
15230 inote
.descsz
= BYTE_GET (enote
->descsz
);
15231 inote
.descdata
= ((char *) enote
15232 + ELF_NOTE_DESC_OFFSET (inote
.namesz
, align
));
15233 inote
.descpos
= offset
+ (inote
.descdata
- (char *) enote
);
15234 next
= ((char *) enote
15235 + ELF_NOTE_NEXT_OFFSET (inote
.namesz
, inote
.descsz
, align
));
15239 Elf64_External_VMS_Note
*vms_enote
;
15241 /* PR binutils/15191
15242 Make sure that there is enough data to read. */
15243 min_notesz
= offsetof (Elf64_External_VMS_Note
, name
);
15244 if (data_remaining
< min_notesz
)
15247 malformed note encountered in section %s whilst scanning for build-id note\n"),
15248 printable_section_name (filedata
, shdr
));
15252 data_remaining
-= min_notesz
;
15254 vms_enote
= (Elf64_External_VMS_Note
*) enote
;
15255 inote
.type
= BYTE_GET (vms_enote
->type
);
15256 inote
.namesz
= BYTE_GET (vms_enote
->namesz
);
15257 inote
.namedata
= vms_enote
->name
;
15258 inote
.descsz
= BYTE_GET (vms_enote
->descsz
);
15259 inote
.descdata
= inote
.namedata
+ align_power (inote
.namesz
, 3);
15260 inote
.descpos
= offset
+ (inote
.descdata
- (char *) enote
);
15261 next
= inote
.descdata
+ align_power (inote
.descsz
, 3);
15264 /* Skip malformed notes. */
15265 if ((size_t) (inote
.descdata
- inote
.namedata
) < inote
.namesz
15266 || (size_t) (inote
.descdata
- inote
.namedata
) > data_remaining
15267 || (size_t) (next
- inote
.descdata
) < inote
.descsz
15268 || ((size_t) (next
- inote
.descdata
)
15269 > data_remaining
- (size_t) (inote
.descdata
- inote
.namedata
)))
15272 malformed note encountered in section %s whilst scanning for build-id note\n"),
15273 printable_section_name (filedata
, shdr
));
15278 /* Check if this is the build-id note. If so then convert the build-id
15279 bytes to a hex string. */
15280 if (inote
.namesz
> 0
15281 && const_strneq (inote
.namedata
, "GNU")
15282 && inote
.type
== NT_GNU_BUILD_ID
)
15287 build_id
= malloc (inote
.descsz
* 2 + 1);
15288 if (build_id
== NULL
)
15294 for (j
= 0; j
< inote
.descsz
; ++j
)
15295 sprintf (build_id
+ (j
* 2), "%02x", inote
.descdata
[j
] & 0xff);
15296 build_id
[inote
.descsz
* 2] = '\0';
15299 return (unsigned char *) build_id
;
15306 #endif /* HAVE_LIBDEBUGINFOD */
15308 /* If this is not NULL, load_debug_section will only look for sections
15309 within the list of sections given here. */
15310 static unsigned int * section_subset
= NULL
;
15313 load_debug_section (enum dwarf_section_display_enum debug
, void * data
)
15315 struct dwarf_section
* section
= &debug_displays
[debug
].section
;
15316 Elf_Internal_Shdr
* sec
;
15317 Filedata
* filedata
= (Filedata
*) data
;
15319 /* Without section headers we cannot find any sections. */
15320 if (filedata
->section_headers
== NULL
)
15323 if (filedata
->string_table
== NULL
15324 && filedata
->file_header
.e_shstrndx
!= SHN_UNDEF
15325 && filedata
->file_header
.e_shstrndx
< filedata
->file_header
.e_shnum
)
15327 Elf_Internal_Shdr
* strs
;
15329 /* Read in the string table, so that we have section names to scan. */
15330 strs
= filedata
->section_headers
+ filedata
->file_header
.e_shstrndx
;
15332 if (strs
!= NULL
&& strs
->sh_size
!= 0)
15334 filedata
->string_table
15335 = (char *) get_data (NULL
, filedata
, strs
->sh_offset
,
15336 1, strs
->sh_size
, _("string table"));
15338 filedata
->string_table_length
15339 = filedata
->string_table
!= NULL
? strs
->sh_size
: 0;
15343 /* Locate the debug section. */
15344 sec
= find_section_in_set (filedata
, section
->uncompressed_name
, section_subset
);
15346 section
->name
= section
->uncompressed_name
;
15349 sec
= find_section_in_set (filedata
, section
->compressed_name
, section_subset
);
15351 section
->name
= section
->compressed_name
;
15356 /* If we're loading from a subset of sections, and we've loaded
15357 a section matching this name before, it's likely that it's a
15359 if (section_subset
!= NULL
)
15360 free_debug_section (debug
);
15362 return load_specific_debug_section (debug
, sec
, data
);
15366 free_debug_section (enum dwarf_section_display_enum debug
)
15368 struct dwarf_section
* section
= &debug_displays
[debug
].section
;
15370 if (section
->start
== NULL
)
15373 free ((char *) section
->start
);
15374 section
->start
= NULL
;
15375 section
->address
= 0;
15378 free (section
->reloc_info
);
15379 section
->reloc_info
= NULL
;
15380 section
->num_relocs
= 0;
15384 display_debug_section (int shndx
, Elf_Internal_Shdr
* section
, Filedata
* filedata
)
15386 char * name
= SECTION_NAME_VALID (section
) ? SECTION_NAME (section
) : "";
15387 const char * print_name
= printable_section_name (filedata
, section
);
15388 bfd_size_type length
;
15389 bfd_boolean result
= TRUE
;
15392 length
= section
->sh_size
;
15395 printf (_("\nSection '%s' has no debugging data.\n"), print_name
);
15398 if (section
->sh_type
== SHT_NOBITS
)
15400 /* There is no point in dumping the contents of a debugging section
15401 which has the NOBITS type - the bits in the file will be random.
15402 This can happen when a file containing a .eh_frame section is
15403 stripped with the --only-keep-debug command line option. */
15404 printf (_("section '%s' has the NOBITS type - its contents are unreliable.\n"),
15409 if (const_strneq (name
, ".gnu.linkonce.wi."))
15410 name
= ".debug_info";
15412 /* See if we know how to display the contents of this section. */
15413 for (i
= 0; i
< max
; i
++)
15415 enum dwarf_section_display_enum id
= (enum dwarf_section_display_enum
) i
;
15416 struct dwarf_section_display
* display
= debug_displays
+ i
;
15417 struct dwarf_section
* sec
= & display
->section
;
15419 if (streq (sec
->uncompressed_name
, name
)
15420 || (id
== line
&& const_strneq (name
, ".debug_line."))
15421 || streq (sec
->compressed_name
, name
))
15423 bfd_boolean secondary
= (section
!= find_section (filedata
, name
));
15426 free_debug_section (id
);
15428 if (i
== line
&& const_strneq (name
, ".debug_line."))
15430 else if (streq (sec
->uncompressed_name
, name
))
15431 sec
->name
= sec
->uncompressed_name
;
15433 sec
->name
= sec
->compressed_name
;
15435 if (load_specific_debug_section (id
, section
, filedata
))
15437 /* If this debug section is part of a CU/TU set in a .dwp file,
15438 restrict load_debug_section to the sections in that set. */
15439 section_subset
= find_cu_tu_set (filedata
, shndx
);
15441 result
&= display
->display (sec
, filedata
);
15443 section_subset
= NULL
;
15445 if (secondary
|| (id
!= info
&& id
!= abbrev
))
15446 free_debug_section (id
);
15454 printf (_("Unrecognized debug section: %s\n"), print_name
);
15461 /* Set DUMP_SECTS for all sections where dumps were requested
15462 based on section name. */
15465 initialise_dumps_byname (Filedata
* filedata
)
15467 struct dump_list_entry
* cur
;
15469 for (cur
= dump_sects_byname
; cur
; cur
= cur
->next
)
15472 bfd_boolean any
= FALSE
;
15474 for (i
= 0; i
< filedata
->file_header
.e_shnum
; i
++)
15475 if (SECTION_NAME_VALID (filedata
->section_headers
+ i
)
15476 && streq (SECTION_NAME (filedata
->section_headers
+ i
), cur
->name
))
15478 request_dump_bynumber (&filedata
->dump
, i
, cur
->type
);
15484 if (filedata
->is_separate
)
15485 warn (_("Section '%s' in linked file '%s' was not dumped because it does not exist\n"),
15486 cur
->name
, filedata
->file_name
);
15488 warn (_("Section '%s' was not dumped because it does not exist\n"),
15495 process_section_contents (Filedata
* filedata
)
15497 Elf_Internal_Shdr
* section
;
15499 bfd_boolean res
= TRUE
;
15504 initialise_dumps_byname (filedata
);
15506 for (i
= 0, section
= filedata
->section_headers
;
15507 i
< filedata
->file_header
.e_shnum
&& i
< filedata
->dump
.num_dump_sects
;
15510 dump_type dump
= filedata
->dump
.dump_sects
[i
];
15512 #ifdef SUPPORT_DISASSEMBLY
15513 if (dump
& DISASS_DUMP
)
15515 if (! disassemble_section (section
, filedata
))
15519 if (dump
& HEX_DUMP
)
15521 if (! dump_section_as_bytes (section
, filedata
, FALSE
))
15525 if (dump
& RELOC_DUMP
)
15527 if (! dump_section_as_bytes (section
, filedata
, TRUE
))
15531 if (dump
& STRING_DUMP
)
15533 if (! dump_section_as_strings (section
, filedata
))
15537 if (dump
& DEBUG_DUMP
)
15539 if (! display_debug_section (i
, section
, filedata
))
15543 #ifdef ENABLE_LIBCTF
15544 if (dump
& CTF_DUMP
)
15546 if (! dump_section_as_ctf (section
, filedata
))
15552 /* Check to see if the user requested a
15553 dump of a section that does not exist. */
15554 while (i
< filedata
->dump
.num_dump_sects
)
15556 if (filedata
->dump
.dump_sects
[i
])
15558 if (filedata
->is_separate
)
15559 warn (_("Section %d in linked file '%s' was not dumped because it does not exist!\n"),
15560 i
, filedata
->file_name
);
15562 warn (_("Section %d was not dumped because it does not exist!\n"), i
);
15572 process_mips_fpe_exception (int mask
)
15576 bfd_boolean first
= TRUE
;
15578 if (mask
& OEX_FPU_INEX
)
15579 fputs ("INEX", stdout
), first
= FALSE
;
15580 if (mask
& OEX_FPU_UFLO
)
15581 printf ("%sUFLO", first
? "" : "|"), first
= FALSE
;
15582 if (mask
& OEX_FPU_OFLO
)
15583 printf ("%sOFLO", first
? "" : "|"), first
= FALSE
;
15584 if (mask
& OEX_FPU_DIV0
)
15585 printf ("%sDIV0", first
? "" : "|"), first
= FALSE
;
15586 if (mask
& OEX_FPU_INVAL
)
15587 printf ("%sINVAL", first
? "" : "|");
15590 fputs ("0", stdout
);
15593 /* Display's the value of TAG at location P. If TAG is
15594 greater than 0 it is assumed to be an unknown tag, and
15595 a message is printed to this effect. Otherwise it is
15596 assumed that a message has already been printed.
15598 If the bottom bit of TAG is set it assumed to have a
15599 string value, otherwise it is assumed to have an integer
15602 Returns an updated P pointing to the first unread byte
15603 beyond the end of TAG's value.
15605 Reads at or beyond END will not be made. */
15607 static unsigned char *
15608 display_tag_value (signed int tag
,
15610 const unsigned char * const end
)
15615 printf (" Tag_unknown_%d: ", tag
);
15619 warn (_("<corrupt tag>\n"));
15623 /* PR 17531 file: 027-19978-0.004. */
15624 size_t maxlen
= (end
- p
) - 1;
15629 print_symbol ((int) maxlen
, (const char *) p
);
15630 p
+= strnlen ((char *) p
, maxlen
) + 1;
15634 printf (_("<corrupt string tag>"));
15635 p
= (unsigned char *) end
;
15641 READ_ULEB (val
, p
, end
);
15642 printf ("%ld (0x%lx)\n", val
, val
);
15649 /* ARC ABI attributes section. */
15651 static unsigned char *
15652 display_arc_attribute (unsigned char * p
,
15653 const unsigned char * const end
)
15658 READ_ULEB (tag
, p
, end
);
15662 case Tag_ARC_PCS_config
:
15663 READ_ULEB (val
, p
, end
);
15664 printf (" Tag_ARC_PCS_config: ");
15668 printf (_("Absent/Non standard\n"));
15671 printf (_("Bare metal/mwdt\n"));
15674 printf (_("Bare metal/newlib\n"));
15677 printf (_("Linux/uclibc\n"));
15680 printf (_("Linux/glibc\n"));
15683 printf (_("Unknown\n"));
15688 case Tag_ARC_CPU_base
:
15689 READ_ULEB (val
, p
, end
);
15690 printf (" Tag_ARC_CPU_base: ");
15695 printf (_("Absent\n"));
15697 case TAG_CPU_ARC6xx
:
15698 printf ("ARC6xx\n");
15700 case TAG_CPU_ARC7xx
:
15701 printf ("ARC7xx\n");
15703 case TAG_CPU_ARCEM
:
15704 printf ("ARCEM\n");
15706 case TAG_CPU_ARCHS
:
15707 printf ("ARCHS\n");
15712 case Tag_ARC_CPU_variation
:
15713 READ_ULEB (val
, p
, end
);
15714 printf (" Tag_ARC_CPU_variation: ");
15718 if (val
> 0 && val
< 16)
15719 printf ("Core%d\n", val
);
15721 printf ("Unknown\n");
15725 printf (_("Absent\n"));
15730 case Tag_ARC_CPU_name
:
15731 printf (" Tag_ARC_CPU_name: ");
15732 p
= display_tag_value (-1, p
, end
);
15735 case Tag_ARC_ABI_rf16
:
15736 READ_ULEB (val
, p
, end
);
15737 printf (" Tag_ARC_ABI_rf16: %s\n", val
? _("yes") : _("no"));
15740 case Tag_ARC_ABI_osver
:
15741 READ_ULEB (val
, p
, end
);
15742 printf (" Tag_ARC_ABI_osver: v%d\n", val
);
15745 case Tag_ARC_ABI_pic
:
15746 case Tag_ARC_ABI_sda
:
15747 READ_ULEB (val
, p
, end
);
15748 printf (tag
== Tag_ARC_ABI_sda
? " Tag_ARC_ABI_sda: "
15749 : " Tag_ARC_ABI_pic: ");
15753 printf (_("Absent\n"));
15762 printf (_("Unknown\n"));
15767 case Tag_ARC_ABI_tls
:
15768 READ_ULEB (val
, p
, end
);
15769 printf (" Tag_ARC_ABI_tls: %s\n", val
? "r25": "none");
15772 case Tag_ARC_ABI_enumsize
:
15773 READ_ULEB (val
, p
, end
);
15774 printf (" Tag_ARC_ABI_enumsize: %s\n", val
? _("default") :
15778 case Tag_ARC_ABI_exceptions
:
15779 READ_ULEB (val
, p
, end
);
15780 printf (" Tag_ARC_ABI_exceptions: %s\n", val
? _("OPTFP")
15784 case Tag_ARC_ABI_double_size
:
15785 READ_ULEB (val
, p
, end
);
15786 printf (" Tag_ARC_ABI_double_size: %d\n", val
);
15789 case Tag_ARC_ISA_config
:
15790 printf (" Tag_ARC_ISA_config: ");
15791 p
= display_tag_value (-1, p
, end
);
15794 case Tag_ARC_ISA_apex
:
15795 printf (" Tag_ARC_ISA_apex: ");
15796 p
= display_tag_value (-1, p
, end
);
15799 case Tag_ARC_ISA_mpy_option
:
15800 READ_ULEB (val
, p
, end
);
15801 printf (" Tag_ARC_ISA_mpy_option: %d\n", val
);
15804 case Tag_ARC_ATR_version
:
15805 READ_ULEB (val
, p
, end
);
15806 printf (" Tag_ARC_ATR_version: %d\n", val
);
15810 return display_tag_value (tag
& 1, p
, end
);
15816 /* ARM EABI attributes section. */
15821 /* 0 = special, 1 = string, 2 = uleb123, > 0x80 == table lookup. */
15823 const char *const *table
;
15824 } arm_attr_public_tag
;
15826 static const char *const arm_attr_tag_CPU_arch
[] =
15827 {"Pre-v4", "v4", "v4T", "v5T", "v5TE", "v5TEJ", "v6", "v6KZ", "v6T2",
15828 "v6K", "v7", "v6-M", "v6S-M", "v7E-M", "v8", "v8-R", "v8-M.baseline",
15829 "v8-M.mainline", "", "", "", "v8.1-M.mainline"};
15830 static const char *const arm_attr_tag_ARM_ISA_use
[] = {"No", "Yes"};
15831 static const char *const arm_attr_tag_THUMB_ISA_use
[] =
15832 {"No", "Thumb-1", "Thumb-2", "Yes"};
15833 static const char *const arm_attr_tag_FP_arch
[] =
15834 {"No", "VFPv1", "VFPv2", "VFPv3", "VFPv3-D16", "VFPv4", "VFPv4-D16",
15835 "FP for ARMv8", "FPv5/FP-D16 for ARMv8"};
15836 static const char *const arm_attr_tag_WMMX_arch
[] = {"No", "WMMXv1", "WMMXv2"};
15837 static const char *const arm_attr_tag_Advanced_SIMD_arch
[] =
15838 {"No", "NEONv1", "NEONv1 with Fused-MAC", "NEON for ARMv8",
15839 "NEON for ARMv8.1"};
15840 static const char *const arm_attr_tag_PCS_config
[] =
15841 {"None", "Bare platform", "Linux application", "Linux DSO", "PalmOS 2004",
15842 "PalmOS (reserved)", "SymbianOS 2004", "SymbianOS (reserved)"};
15843 static const char *const arm_attr_tag_ABI_PCS_R9_use
[] =
15844 {"V6", "SB", "TLS", "Unused"};
15845 static const char *const arm_attr_tag_ABI_PCS_RW_data
[] =
15846 {"Absolute", "PC-relative", "SB-relative", "None"};
15847 static const char *const arm_attr_tag_ABI_PCS_RO_data
[] =
15848 {"Absolute", "PC-relative", "None"};
15849 static const char *const arm_attr_tag_ABI_PCS_GOT_use
[] =
15850 {"None", "direct", "GOT-indirect"};
15851 static const char *const arm_attr_tag_ABI_PCS_wchar_t
[] =
15852 {"None", "??? 1", "2", "??? 3", "4"};
15853 static const char *const arm_attr_tag_ABI_FP_rounding
[] = {"Unused", "Needed"};
15854 static const char *const arm_attr_tag_ABI_FP_denormal
[] =
15855 {"Unused", "Needed", "Sign only"};
15856 static const char *const arm_attr_tag_ABI_FP_exceptions
[] = {"Unused", "Needed"};
15857 static const char *const arm_attr_tag_ABI_FP_user_exceptions
[] = {"Unused", "Needed"};
15858 static const char *const arm_attr_tag_ABI_FP_number_model
[] =
15859 {"Unused", "Finite", "RTABI", "IEEE 754"};
15860 static const char *const arm_attr_tag_ABI_enum_size
[] =
15861 {"Unused", "small", "int", "forced to int"};
15862 static const char *const arm_attr_tag_ABI_HardFP_use
[] =
15863 {"As Tag_FP_arch", "SP only", "Reserved", "Deprecated"};
15864 static const char *const arm_attr_tag_ABI_VFP_args
[] =
15865 {"AAPCS", "VFP registers", "custom", "compatible"};
15866 static const char *const arm_attr_tag_ABI_WMMX_args
[] =
15867 {"AAPCS", "WMMX registers", "custom"};
15868 static const char *const arm_attr_tag_ABI_optimization_goals
[] =
15869 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
15870 "Aggressive Size", "Prefer Debug", "Aggressive Debug"};
15871 static const char *const arm_attr_tag_ABI_FP_optimization_goals
[] =
15872 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
15873 "Aggressive Size", "Prefer Accuracy", "Aggressive Accuracy"};
15874 static const char *const arm_attr_tag_CPU_unaligned_access
[] = {"None", "v6"};
15875 static const char *const arm_attr_tag_FP_HP_extension
[] =
15876 {"Not Allowed", "Allowed"};
15877 static const char *const arm_attr_tag_ABI_FP_16bit_format
[] =
15878 {"None", "IEEE 754", "Alternative Format"};
15879 static const char *const arm_attr_tag_DSP_extension
[] =
15880 {"Follow architecture", "Allowed"};
15881 static const char *const arm_attr_tag_MPextension_use
[] =
15882 {"Not Allowed", "Allowed"};
15883 static const char *const arm_attr_tag_DIV_use
[] =
15884 {"Allowed in Thumb-ISA, v7-R or v7-M", "Not allowed",
15885 "Allowed in v7-A with integer division extension"};
15886 static const char *const arm_attr_tag_T2EE_use
[] = {"Not Allowed", "Allowed"};
15887 static const char *const arm_attr_tag_Virtualization_use
[] =
15888 {"Not Allowed", "TrustZone", "Virtualization Extensions",
15889 "TrustZone and Virtualization Extensions"};
15890 static const char *const arm_attr_tag_MPextension_use_legacy
[] =
15891 {"Not Allowed", "Allowed"};
15893 static const char *const arm_attr_tag_MVE_arch
[] =
15894 {"No MVE", "MVE Integer only", "MVE Integer and FP"};
15896 #define LOOKUP(id, name) \
15897 {id, #name, 0x80 | ARRAY_SIZE(arm_attr_tag_##name), arm_attr_tag_##name}
15898 static arm_attr_public_tag arm_attr_public_tags
[] =
15900 {4, "CPU_raw_name", 1, NULL
},
15901 {5, "CPU_name", 1, NULL
},
15902 LOOKUP(6, CPU_arch
),
15903 {7, "CPU_arch_profile", 0, NULL
},
15904 LOOKUP(8, ARM_ISA_use
),
15905 LOOKUP(9, THUMB_ISA_use
),
15906 LOOKUP(10, FP_arch
),
15907 LOOKUP(11, WMMX_arch
),
15908 LOOKUP(12, Advanced_SIMD_arch
),
15909 LOOKUP(13, PCS_config
),
15910 LOOKUP(14, ABI_PCS_R9_use
),
15911 LOOKUP(15, ABI_PCS_RW_data
),
15912 LOOKUP(16, ABI_PCS_RO_data
),
15913 LOOKUP(17, ABI_PCS_GOT_use
),
15914 LOOKUP(18, ABI_PCS_wchar_t
),
15915 LOOKUP(19, ABI_FP_rounding
),
15916 LOOKUP(20, ABI_FP_denormal
),
15917 LOOKUP(21, ABI_FP_exceptions
),
15918 LOOKUP(22, ABI_FP_user_exceptions
),
15919 LOOKUP(23, ABI_FP_number_model
),
15920 {24, "ABI_align_needed", 0, NULL
},
15921 {25, "ABI_align_preserved", 0, NULL
},
15922 LOOKUP(26, ABI_enum_size
),
15923 LOOKUP(27, ABI_HardFP_use
),
15924 LOOKUP(28, ABI_VFP_args
),
15925 LOOKUP(29, ABI_WMMX_args
),
15926 LOOKUP(30, ABI_optimization_goals
),
15927 LOOKUP(31, ABI_FP_optimization_goals
),
15928 {32, "compatibility", 0, NULL
},
15929 LOOKUP(34, CPU_unaligned_access
),
15930 LOOKUP(36, FP_HP_extension
),
15931 LOOKUP(38, ABI_FP_16bit_format
),
15932 LOOKUP(42, MPextension_use
),
15933 LOOKUP(44, DIV_use
),
15934 LOOKUP(46, DSP_extension
),
15935 LOOKUP(48, MVE_arch
),
15936 {64, "nodefaults", 0, NULL
},
15937 {65, "also_compatible_with", 0, NULL
},
15938 LOOKUP(66, T2EE_use
),
15939 {67, "conformance", 1, NULL
},
15940 LOOKUP(68, Virtualization_use
),
15941 LOOKUP(70, MPextension_use_legacy
)
15945 static unsigned char *
15946 display_arm_attribute (unsigned char * p
,
15947 const unsigned char * const end
)
15951 arm_attr_public_tag
* attr
;
15955 READ_ULEB (tag
, p
, end
);
15957 for (i
= 0; i
< ARRAY_SIZE (arm_attr_public_tags
); i
++)
15959 if (arm_attr_public_tags
[i
].tag
== tag
)
15961 attr
= &arm_attr_public_tags
[i
];
15968 printf (" Tag_%s: ", attr
->name
);
15969 switch (attr
->type
)
15974 case 7: /* Tag_CPU_arch_profile. */
15975 READ_ULEB (val
, p
, end
);
15978 case 0: printf (_("None\n")); break;
15979 case 'A': printf (_("Application\n")); break;
15980 case 'R': printf (_("Realtime\n")); break;
15981 case 'M': printf (_("Microcontroller\n")); break;
15982 case 'S': printf (_("Application or Realtime\n")); break;
15983 default: printf ("??? (%d)\n", val
); break;
15987 case 24: /* Tag_align_needed. */
15988 READ_ULEB (val
, p
, end
);
15991 case 0: printf (_("None\n")); break;
15992 case 1: printf (_("8-byte\n")); break;
15993 case 2: printf (_("4-byte\n")); break;
15994 case 3: printf ("??? 3\n"); break;
15997 printf (_("8-byte and up to %d-byte extended\n"),
16000 printf ("??? (%d)\n", val
);
16005 case 25: /* Tag_align_preserved. */
16006 READ_ULEB (val
, p
, end
);
16009 case 0: printf (_("None\n")); break;
16010 case 1: printf (_("8-byte, except leaf SP\n")); break;
16011 case 2: printf (_("8-byte\n")); break;
16012 case 3: printf ("??? 3\n"); break;
16015 printf (_("8-byte and up to %d-byte extended\n"),
16018 printf ("??? (%d)\n", val
);
16023 case 32: /* Tag_compatibility. */
16025 READ_ULEB (val
, p
, end
);
16026 printf (_("flag = %d, vendor = "), val
);
16029 size_t maxlen
= (end
- p
) - 1;
16031 print_symbol ((int) maxlen
, (const char *) p
);
16032 p
+= strnlen ((char *) p
, maxlen
) + 1;
16036 printf (_("<corrupt>"));
16037 p
= (unsigned char *) end
;
16043 case 64: /* Tag_nodefaults. */
16044 /* PR 17531: file: 001-505008-0.01. */
16047 printf (_("True\n"));
16050 case 65: /* Tag_also_compatible_with. */
16051 READ_ULEB (val
, p
, end
);
16052 if (val
== 6 /* Tag_CPU_arch. */)
16054 READ_ULEB (val
, p
, end
);
16055 if ((unsigned int) val
>= ARRAY_SIZE (arm_attr_tag_CPU_arch
))
16056 printf ("??? (%d)\n", val
);
16058 printf ("%s\n", arm_attr_tag_CPU_arch
[val
]);
16062 while (p
< end
&& *(p
++) != '\0' /* NUL terminator. */)
16067 printf (_("<unknown: %d>\n"), tag
);
16073 return display_tag_value (-1, p
, end
);
16075 return display_tag_value (0, p
, end
);
16078 assert (attr
->type
& 0x80);
16079 READ_ULEB (val
, p
, end
);
16080 type
= attr
->type
& 0x7f;
16082 printf ("??? (%d)\n", val
);
16084 printf ("%s\n", attr
->table
[val
]);
16089 return display_tag_value (tag
, p
, end
);
16092 static unsigned char *
16093 display_gnu_attribute (unsigned char * p
,
16094 unsigned char * (* display_proc_gnu_attribute
) (unsigned char *, unsigned int, const unsigned char * const),
16095 const unsigned char * const end
)
16100 READ_ULEB (tag
, p
, end
);
16102 /* Tag_compatibility is the only generic GNU attribute defined at
16106 READ_ULEB (val
, p
, end
);
16108 printf (_("flag = %d, vendor = "), val
);
16111 printf (_("<corrupt>\n"));
16112 warn (_("corrupt vendor attribute\n"));
16118 size_t maxlen
= (end
- p
) - 1;
16120 print_symbol ((int) maxlen
, (const char *) p
);
16121 p
+= strnlen ((char *) p
, maxlen
) + 1;
16125 printf (_("<corrupt>"));
16126 p
= (unsigned char *) end
;
16133 if ((tag
& 2) == 0 && display_proc_gnu_attribute
)
16134 return display_proc_gnu_attribute (p
, tag
, end
);
16136 return display_tag_value (tag
, p
, end
);
16139 static unsigned char *
16140 display_m68k_gnu_attribute (unsigned char * p
,
16142 const unsigned char * const end
)
16146 if (tag
== Tag_GNU_M68K_ABI_FP
)
16148 printf (" Tag_GNU_M68K_ABI_FP: ");
16151 printf (_("<corrupt>\n"));
16154 READ_ULEB (val
, p
, end
);
16157 printf ("(%#x), ", val
);
16162 printf (_("unspecified hard/soft float\n"));
16165 printf (_("hard float\n"));
16168 printf (_("soft float\n"));
16174 return display_tag_value (tag
& 1, p
, end
);
16177 static unsigned char *
16178 display_power_gnu_attribute (unsigned char * p
,
16180 const unsigned char * const end
)
16184 if (tag
== Tag_GNU_Power_ABI_FP
)
16186 printf (" Tag_GNU_Power_ABI_FP: ");
16189 printf (_("<corrupt>\n"));
16192 READ_ULEB (val
, p
, end
);
16195 printf ("(%#x), ", val
);
16200 printf (_("unspecified hard/soft float, "));
16203 printf (_("hard float, "));
16206 printf (_("soft float, "));
16209 printf (_("single-precision hard float, "));
16216 printf (_("unspecified long double\n"));
16219 printf (_("128-bit IBM long double\n"));
16222 printf (_("64-bit long double\n"));
16225 printf (_("128-bit IEEE long double\n"));
16231 if (tag
== Tag_GNU_Power_ABI_Vector
)
16233 printf (" Tag_GNU_Power_ABI_Vector: ");
16236 printf (_("<corrupt>\n"));
16239 READ_ULEB (val
, p
, end
);
16242 printf ("(%#x), ", val
);
16247 printf (_("unspecified\n"));
16250 printf (_("generic\n"));
16253 printf ("AltiVec\n");
16262 if (tag
== Tag_GNU_Power_ABI_Struct_Return
)
16264 printf (" Tag_GNU_Power_ABI_Struct_Return: ");
16267 printf (_("<corrupt>\n"));
16270 READ_ULEB (val
, p
, end
);
16273 printf ("(%#x), ", val
);
16278 printf (_("unspecified\n"));
16281 printf ("r3/r4\n");
16284 printf (_("memory\n"));
16293 return display_tag_value (tag
& 1, p
, end
);
16296 static unsigned char *
16297 display_s390_gnu_attribute (unsigned char * p
,
16299 const unsigned char * const end
)
16303 if (tag
== Tag_GNU_S390_ABI_Vector
)
16305 printf (" Tag_GNU_S390_ABI_Vector: ");
16306 READ_ULEB (val
, p
, end
);
16311 printf (_("any\n"));
16314 printf (_("software\n"));
16317 printf (_("hardware\n"));
16320 printf ("??? (%d)\n", val
);
16326 return display_tag_value (tag
& 1, p
, end
);
16330 display_sparc_hwcaps (unsigned int mask
)
16334 bfd_boolean first
= TRUE
;
16336 if (mask
& ELF_SPARC_HWCAP_MUL32
)
16337 fputs ("mul32", stdout
), first
= FALSE
;
16338 if (mask
& ELF_SPARC_HWCAP_DIV32
)
16339 printf ("%sdiv32", first
? "" : "|"), first
= FALSE
;
16340 if (mask
& ELF_SPARC_HWCAP_FSMULD
)
16341 printf ("%sfsmuld", first
? "" : "|"), first
= FALSE
;
16342 if (mask
& ELF_SPARC_HWCAP_V8PLUS
)
16343 printf ("%sv8plus", first
? "" : "|"), first
= FALSE
;
16344 if (mask
& ELF_SPARC_HWCAP_POPC
)
16345 printf ("%spopc", first
? "" : "|"), first
= FALSE
;
16346 if (mask
& ELF_SPARC_HWCAP_VIS
)
16347 printf ("%svis", first
? "" : "|"), first
= FALSE
;
16348 if (mask
& ELF_SPARC_HWCAP_VIS2
)
16349 printf ("%svis2", first
? "" : "|"), first
= FALSE
;
16350 if (mask
& ELF_SPARC_HWCAP_ASI_BLK_INIT
)
16351 printf ("%sASIBlkInit", first
? "" : "|"), first
= FALSE
;
16352 if (mask
& ELF_SPARC_HWCAP_FMAF
)
16353 printf ("%sfmaf", first
? "" : "|"), first
= FALSE
;
16354 if (mask
& ELF_SPARC_HWCAP_VIS3
)
16355 printf ("%svis3", first
? "" : "|"), first
= FALSE
;
16356 if (mask
& ELF_SPARC_HWCAP_HPC
)
16357 printf ("%shpc", first
? "" : "|"), first
= FALSE
;
16358 if (mask
& ELF_SPARC_HWCAP_RANDOM
)
16359 printf ("%srandom", first
? "" : "|"), first
= FALSE
;
16360 if (mask
& ELF_SPARC_HWCAP_TRANS
)
16361 printf ("%strans", first
? "" : "|"), first
= FALSE
;
16362 if (mask
& ELF_SPARC_HWCAP_FJFMAU
)
16363 printf ("%sfjfmau", first
? "" : "|"), first
= FALSE
;
16364 if (mask
& ELF_SPARC_HWCAP_IMA
)
16365 printf ("%sima", first
? "" : "|"), first
= FALSE
;
16366 if (mask
& ELF_SPARC_HWCAP_ASI_CACHE_SPARING
)
16367 printf ("%scspare", first
? "" : "|"), first
= FALSE
;
16370 fputc ('0', stdout
);
16371 fputc ('\n', stdout
);
16375 display_sparc_hwcaps2 (unsigned int mask
)
16379 bfd_boolean first
= TRUE
;
16381 if (mask
& ELF_SPARC_HWCAP2_FJATHPLUS
)
16382 fputs ("fjathplus", stdout
), first
= FALSE
;
16383 if (mask
& ELF_SPARC_HWCAP2_VIS3B
)
16384 printf ("%svis3b", first
? "" : "|"), first
= FALSE
;
16385 if (mask
& ELF_SPARC_HWCAP2_ADP
)
16386 printf ("%sadp", first
? "" : "|"), first
= FALSE
;
16387 if (mask
& ELF_SPARC_HWCAP2_SPARC5
)
16388 printf ("%ssparc5", first
? "" : "|"), first
= FALSE
;
16389 if (mask
& ELF_SPARC_HWCAP2_MWAIT
)
16390 printf ("%smwait", first
? "" : "|"), first
= FALSE
;
16391 if (mask
& ELF_SPARC_HWCAP2_XMPMUL
)
16392 printf ("%sxmpmul", first
? "" : "|"), first
= FALSE
;
16393 if (mask
& ELF_SPARC_HWCAP2_XMONT
)
16394 printf ("%sxmont2", first
? "" : "|"), first
= FALSE
;
16395 if (mask
& ELF_SPARC_HWCAP2_NSEC
)
16396 printf ("%snsec", first
? "" : "|"), first
= FALSE
;
16397 if (mask
& ELF_SPARC_HWCAP2_FJATHHPC
)
16398 printf ("%sfjathhpc", first
? "" : "|"), first
= FALSE
;
16399 if (mask
& ELF_SPARC_HWCAP2_FJDES
)
16400 printf ("%sfjdes", first
? "" : "|"), first
= FALSE
;
16401 if (mask
& ELF_SPARC_HWCAP2_FJAES
)
16402 printf ("%sfjaes", first
? "" : "|"), first
= FALSE
;
16405 fputc ('0', stdout
);
16406 fputc ('\n', stdout
);
16409 static unsigned char *
16410 display_sparc_gnu_attribute (unsigned char * p
,
16412 const unsigned char * const end
)
16416 if (tag
== Tag_GNU_Sparc_HWCAPS
)
16418 READ_ULEB (val
, p
, end
);
16419 printf (" Tag_GNU_Sparc_HWCAPS: ");
16420 display_sparc_hwcaps (val
);
16423 if (tag
== Tag_GNU_Sparc_HWCAPS2
)
16425 READ_ULEB (val
, p
, end
);
16426 printf (" Tag_GNU_Sparc_HWCAPS2: ");
16427 display_sparc_hwcaps2 (val
);
16431 return display_tag_value (tag
, p
, end
);
16435 print_mips_fp_abi_value (unsigned int val
)
16439 case Val_GNU_MIPS_ABI_FP_ANY
:
16440 printf (_("Hard or soft float\n"));
16442 case Val_GNU_MIPS_ABI_FP_DOUBLE
:
16443 printf (_("Hard float (double precision)\n"));
16445 case Val_GNU_MIPS_ABI_FP_SINGLE
:
16446 printf (_("Hard float (single precision)\n"));
16448 case Val_GNU_MIPS_ABI_FP_SOFT
:
16449 printf (_("Soft float\n"));
16451 case Val_GNU_MIPS_ABI_FP_OLD_64
:
16452 printf (_("Hard float (MIPS32r2 64-bit FPU 12 callee-saved)\n"));
16454 case Val_GNU_MIPS_ABI_FP_XX
:
16455 printf (_("Hard float (32-bit CPU, Any FPU)\n"));
16457 case Val_GNU_MIPS_ABI_FP_64
:
16458 printf (_("Hard float (32-bit CPU, 64-bit FPU)\n"));
16460 case Val_GNU_MIPS_ABI_FP_64A
:
16461 printf (_("Hard float compat (32-bit CPU, 64-bit FPU)\n"));
16463 case Val_GNU_MIPS_ABI_FP_NAN2008
:
16464 printf (_("NaN 2008 compatibility\n"));
16467 printf ("??? (%d)\n", val
);
16472 static unsigned char *
16473 display_mips_gnu_attribute (unsigned char * p
,
16475 const unsigned char * const end
)
16477 if (tag
== Tag_GNU_MIPS_ABI_FP
)
16481 printf (" Tag_GNU_MIPS_ABI_FP: ");
16482 READ_ULEB (val
, p
, end
);
16483 print_mips_fp_abi_value (val
);
16487 if (tag
== Tag_GNU_MIPS_ABI_MSA
)
16491 printf (" Tag_GNU_MIPS_ABI_MSA: ");
16492 READ_ULEB (val
, p
, end
);
16496 case Val_GNU_MIPS_ABI_MSA_ANY
:
16497 printf (_("Any MSA or not\n"));
16499 case Val_GNU_MIPS_ABI_MSA_128
:
16500 printf (_("128-bit MSA\n"));
16503 printf ("??? (%d)\n", val
);
16509 return display_tag_value (tag
& 1, p
, end
);
16512 static unsigned char *
16513 display_tic6x_attribute (unsigned char * p
,
16514 const unsigned char * const end
)
16519 READ_ULEB (tag
, p
, end
);
16524 printf (" Tag_ISA: ");
16525 READ_ULEB (val
, p
, end
);
16529 case C6XABI_Tag_ISA_none
:
16530 printf (_("None\n"));
16532 case C6XABI_Tag_ISA_C62X
:
16535 case C6XABI_Tag_ISA_C67X
:
16538 case C6XABI_Tag_ISA_C67XP
:
16539 printf ("C67x+\n");
16541 case C6XABI_Tag_ISA_C64X
:
16544 case C6XABI_Tag_ISA_C64XP
:
16545 printf ("C64x+\n");
16547 case C6XABI_Tag_ISA_C674X
:
16548 printf ("C674x\n");
16551 printf ("??? (%d)\n", val
);
16556 case Tag_ABI_wchar_t
:
16557 printf (" Tag_ABI_wchar_t: ");
16558 READ_ULEB (val
, p
, end
);
16562 printf (_("Not used\n"));
16565 printf (_("2 bytes\n"));
16568 printf (_("4 bytes\n"));
16571 printf ("??? (%d)\n", val
);
16576 case Tag_ABI_stack_align_needed
:
16577 printf (" Tag_ABI_stack_align_needed: ");
16578 READ_ULEB (val
, p
, end
);
16582 printf (_("8-byte\n"));
16585 printf (_("16-byte\n"));
16588 printf ("??? (%d)\n", val
);
16593 case Tag_ABI_stack_align_preserved
:
16594 READ_ULEB (val
, p
, end
);
16595 printf (" Tag_ABI_stack_align_preserved: ");
16599 printf (_("8-byte\n"));
16602 printf (_("16-byte\n"));
16605 printf ("??? (%d)\n", val
);
16611 READ_ULEB (val
, p
, end
);
16612 printf (" Tag_ABI_DSBT: ");
16616 printf (_("DSBT addressing not used\n"));
16619 printf (_("DSBT addressing used\n"));
16622 printf ("??? (%d)\n", val
);
16628 READ_ULEB (val
, p
, end
);
16629 printf (" Tag_ABI_PID: ");
16633 printf (_("Data addressing position-dependent\n"));
16636 printf (_("Data addressing position-independent, GOT near DP\n"));
16639 printf (_("Data addressing position-independent, GOT far from DP\n"));
16642 printf ("??? (%d)\n", val
);
16648 READ_ULEB (val
, p
, end
);
16649 printf (" Tag_ABI_PIC: ");
16653 printf (_("Code addressing position-dependent\n"));
16656 printf (_("Code addressing position-independent\n"));
16659 printf ("??? (%d)\n", val
);
16664 case Tag_ABI_array_object_alignment
:
16665 READ_ULEB (val
, p
, end
);
16666 printf (" Tag_ABI_array_object_alignment: ");
16670 printf (_("8-byte\n"));
16673 printf (_("4-byte\n"));
16676 printf (_("16-byte\n"));
16679 printf ("??? (%d)\n", val
);
16684 case Tag_ABI_array_object_align_expected
:
16685 READ_ULEB (val
, p
, end
);
16686 printf (" Tag_ABI_array_object_align_expected: ");
16690 printf (_("8-byte\n"));
16693 printf (_("4-byte\n"));
16696 printf (_("16-byte\n"));
16699 printf ("??? (%d)\n", val
);
16704 case Tag_ABI_compatibility
:
16706 READ_ULEB (val
, p
, end
);
16707 printf (" Tag_ABI_compatibility: ");
16708 printf (_("flag = %d, vendor = "), val
);
16711 size_t maxlen
= (end
- p
) - 1;
16713 print_symbol ((int) maxlen
, (const char *) p
);
16714 p
+= strnlen ((char *) p
, maxlen
) + 1;
16718 printf (_("<corrupt>"));
16719 p
= (unsigned char *) end
;
16725 case Tag_ABI_conformance
:
16727 printf (" Tag_ABI_conformance: \"");
16730 size_t maxlen
= (end
- p
) - 1;
16732 print_symbol ((int) maxlen
, (const char *) p
);
16733 p
+= strnlen ((char *) p
, maxlen
) + 1;
16737 printf (_("<corrupt>"));
16738 p
= (unsigned char *) end
;
16745 return display_tag_value (tag
, p
, end
);
16749 display_raw_attribute (unsigned char * p
, unsigned char const * const end
)
16751 unsigned long addr
= 0;
16752 size_t bytes
= end
- p
;
16759 int lbytes
= (bytes
> 16 ? 16 : bytes
);
16761 printf (" 0x%8.8lx ", addr
);
16763 for (j
= 0; j
< 16; j
++)
16766 printf ("%2.2x", p
[j
]);
16774 for (j
= 0; j
< lbytes
; j
++)
16777 if (k
>= ' ' && k
< 0x7f)
16793 static unsigned char *
16794 display_msp430_attribute (unsigned char * p
,
16795 const unsigned char * const end
)
16800 READ_ULEB (tag
, p
, end
);
16804 case OFBA_MSPABI_Tag_ISA
:
16805 printf (" Tag_ISA: ");
16806 READ_ULEB (val
, p
, end
);
16809 case 0: printf (_("None\n")); break;
16810 case 1: printf (_("MSP430\n")); break;
16811 case 2: printf (_("MSP430X\n")); break;
16812 default: printf ("??? (%d)\n", val
); break;
16816 case OFBA_MSPABI_Tag_Code_Model
:
16817 printf (" Tag_Code_Model: ");
16818 READ_ULEB (val
, p
, end
);
16821 case 0: printf (_("None\n")); break;
16822 case 1: printf (_("Small\n")); break;
16823 case 2: printf (_("Large\n")); break;
16824 default: printf ("??? (%d)\n", val
); break;
16828 case OFBA_MSPABI_Tag_Data_Model
:
16829 printf (" Tag_Data_Model: ");
16830 READ_ULEB (val
, p
, end
);
16833 case 0: printf (_("None\n")); break;
16834 case 1: printf (_("Small\n")); break;
16835 case 2: printf (_("Large\n")); break;
16836 case 3: printf (_("Restricted Large\n")); break;
16837 default: printf ("??? (%d)\n", val
); break;
16842 printf (_(" <unknown tag %d>: "), tag
);
16849 size_t maxlen
= (end
- p
) - 1;
16851 print_symbol ((int) maxlen
, (const char *) p
);
16852 p
+= strnlen ((char *) p
, maxlen
) + 1;
16856 printf (_("<corrupt>"));
16857 p
= (unsigned char *) end
;
16863 READ_ULEB (val
, p
, end
);
16864 printf ("%d (0x%x)\n", val
, val
);
16873 static unsigned char *
16874 display_msp430_gnu_attribute (unsigned char * p
,
16876 const unsigned char * const end
)
16878 if (tag
== Tag_GNU_MSP430_Data_Region
)
16882 printf (" Tag_GNU_MSP430_Data_Region: ");
16883 READ_ULEB (val
, p
, end
);
16887 case Val_GNU_MSP430_Data_Region_Any
:
16888 printf (_("Any Region\n"));
16890 case Val_GNU_MSP430_Data_Region_Lower
:
16891 printf (_("Lower Region Only\n"));
16894 printf ("??? (%u)\n", val
);
16898 return display_tag_value (tag
& 1, p
, end
);
16901 struct riscv_attr_tag_t
{
16906 static struct riscv_attr_tag_t riscv_attr_tag
[] =
16908 #define T(tag) {"Tag_RISCV_" #tag, Tag_RISCV_##tag}
16911 T(priv_spec_minor
),
16912 T(priv_spec_revision
),
16913 T(unaligned_access
),
16918 static unsigned char *
16919 display_riscv_attribute (unsigned char *p
,
16920 const unsigned char * const end
)
16924 struct riscv_attr_tag_t
*attr
= NULL
;
16927 READ_ULEB (tag
, p
, end
);
16929 /* Find the name of attribute. */
16930 for (i
= 0; i
< ARRAY_SIZE (riscv_attr_tag
); i
++)
16932 if (riscv_attr_tag
[i
].tag
== tag
)
16934 attr
= &riscv_attr_tag
[i
];
16940 printf (" %s: ", attr
->name
);
16942 return display_tag_value (tag
, p
, end
);
16946 case Tag_RISCV_priv_spec
:
16947 case Tag_RISCV_priv_spec_minor
:
16948 case Tag_RISCV_priv_spec_revision
:
16949 READ_ULEB (val
, p
, end
);
16950 printf (_("%u\n"), val
);
16952 case Tag_RISCV_unaligned_access
:
16953 READ_ULEB (val
, p
, end
);
16957 printf (_("No unaligned access\n"));
16960 printf (_("Unaligned access\n"));
16964 case Tag_RISCV_stack_align
:
16965 READ_ULEB (val
, p
, end
);
16966 printf (_("%u-bytes\n"), val
);
16968 case Tag_RISCV_arch
:
16969 p
= display_tag_value (-1, p
, end
);
16972 return display_tag_value (tag
, p
, end
);
16978 static unsigned char *
16979 display_csky_attribute (unsigned char * p
,
16980 const unsigned char * const end
)
16984 READ_ULEB (tag
, p
, end
);
16986 if (tag
>= Tag_CSKY_MAX
)
16988 return display_tag_value (-1, p
, end
);
16993 case Tag_CSKY_ARCH_NAME
:
16994 printf (" Tag_CSKY_ARCH_NAME:\t\t");
16995 return display_tag_value (-1, p
, end
);
16996 case Tag_CSKY_CPU_NAME
:
16997 printf (" Tag_CSKY_CPU_NAME:\t\t");
16998 return display_tag_value (-1, p
, end
);
17000 case Tag_CSKY_ISA_FLAGS
:
17001 printf (" Tag_CSKY_ISA_FLAGS:\t\t");
17002 return display_tag_value (0, p
, end
);
17003 case Tag_CSKY_ISA_EXT_FLAGS
:
17004 printf (" Tag_CSKY_ISA_EXT_FLAGS:\t");
17005 return display_tag_value (0, p
, end
);
17007 case Tag_CSKY_DSP_VERSION
:
17008 printf (" Tag_CSKY_DSP_VERSION:\t\t");
17009 READ_ULEB (val
, p
, end
);
17010 if (val
== VAL_CSKY_DSP_VERSION_EXTENSION
)
17011 printf ("DSP Extension\n");
17012 else if (val
== VAL_CSKY_DSP_VERSION_2
)
17013 printf ("DSP 2.0\n");
17016 case Tag_CSKY_VDSP_VERSION
:
17017 printf (" Tag_CSKY_VDSP_VERSION:\t");
17018 READ_ULEB (val
, p
, end
);
17019 printf ("VDSP Version %d\n", val
);
17022 case Tag_CSKY_FPU_VERSION
:
17023 printf (" Tag_CSKY_FPU_VERSION:\t\t");
17024 READ_ULEB (val
, p
, end
);
17025 if (val
== VAL_CSKY_FPU_VERSION_1
)
17026 printf ("ABIV1 FPU Version 1\n");
17027 else if (val
== VAL_CSKY_FPU_VERSION_2
)
17028 printf ("FPU Version 2\n");
17031 case Tag_CSKY_FPU_ABI
:
17032 printf (" Tag_CSKY_FPU_ABI:\t\t");
17033 READ_ULEB (val
, p
, end
);
17034 if (val
== VAL_CSKY_FPU_ABI_HARD
)
17036 else if (val
== VAL_CSKY_FPU_ABI_SOFTFP
)
17037 printf ("SoftFP\n");
17038 else if (val
== VAL_CSKY_FPU_ABI_SOFT
)
17041 case Tag_CSKY_FPU_ROUNDING
:
17042 READ_ULEB (val
, p
, end
);
17044 printf (" Tag_CSKY_FPU_ROUNDING:\t");
17045 printf ("Needed\n");
17048 case Tag_CSKY_FPU_DENORMAL
:
17049 READ_ULEB (val
, p
, end
);
17051 printf (" Tag_CSKY_FPU_DENORMAL:\t");
17052 printf ("Needed\n");
17055 case Tag_CSKY_FPU_Exception
:
17056 READ_ULEB (val
, p
, end
);
17058 printf (" Tag_CSKY_FPU_Exception:\t");
17059 printf ("Needed\n");
17062 case Tag_CSKY_FPU_NUMBER_MODULE
:
17063 printf (" Tag_CSKY_FPU_NUMBER_MODULE:\t");
17064 return display_tag_value (-1, p
, end
);
17065 case Tag_CSKY_FPU_HARDFP
:
17066 printf (" Tag_CSKY_FPU_HARDFP:\t\t");
17067 READ_ULEB (val
, p
, end
);
17068 if (val
& VAL_CSKY_FPU_HARDFP_HALF
)
17070 if (val
& VAL_CSKY_FPU_HARDFP_SINGLE
)
17071 printf (" Single");
17072 if (val
& VAL_CSKY_FPU_HARDFP_DOUBLE
)
17073 printf (" Double");
17077 return display_tag_value (tag
, p
, end
);
17083 process_attributes (Filedata
* filedata
,
17084 const char * public_name
,
17085 unsigned int proc_type
,
17086 unsigned char * (* display_pub_attribute
) (unsigned char *, const unsigned char * const),
17087 unsigned char * (* display_proc_gnu_attribute
) (unsigned char *, unsigned int, const unsigned char * const))
17089 Elf_Internal_Shdr
* sect
;
17091 bfd_boolean res
= TRUE
;
17093 /* Find the section header so that we get the size. */
17094 for (i
= 0, sect
= filedata
->section_headers
;
17095 i
< filedata
->file_header
.e_shnum
;
17098 unsigned char * contents
;
17101 if (sect
->sh_type
!= proc_type
&& sect
->sh_type
!= SHT_GNU_ATTRIBUTES
)
17104 contents
= (unsigned char *) get_data (NULL
, filedata
, sect
->sh_offset
, 1,
17105 sect
->sh_size
, _("attributes"));
17106 if (contents
== NULL
)
17113 /* The first character is the version of the attributes.
17114 Currently only version 1, (aka 'A') is recognised here. */
17117 printf (_("Unknown attributes version '%c'(%d) - expecting 'A'\n"), *p
, *p
);
17122 bfd_vma section_len
;
17124 section_len
= sect
->sh_size
- 1;
17127 while (section_len
> 0)
17130 unsigned int namelen
;
17131 bfd_boolean public_section
;
17132 bfd_boolean gnu_section
;
17134 if (section_len
<= 4)
17136 error (_("Tag section ends prematurely\n"));
17140 attr_len
= byte_get (p
, 4);
17143 if (attr_len
> section_len
)
17145 error (_("Bad attribute length (%u > %u)\n"),
17146 (unsigned) attr_len
, (unsigned) section_len
);
17147 attr_len
= section_len
;
17150 /* PR 17531: file: 001-101425-0.004 */
17151 else if (attr_len
< 5)
17153 error (_("Attribute length of %u is too small\n"), (unsigned) attr_len
);
17158 section_len
-= attr_len
;
17161 namelen
= strnlen ((char *) p
, attr_len
) + 1;
17162 if (namelen
== 0 || namelen
>= attr_len
)
17164 error (_("Corrupt attribute section name\n"));
17169 printf (_("Attribute Section: "));
17170 print_symbol (INT_MAX
, (const char *) p
);
17173 if (public_name
&& streq ((char *) p
, public_name
))
17174 public_section
= TRUE
;
17176 public_section
= FALSE
;
17178 if (streq ((char *) p
, "gnu"))
17179 gnu_section
= TRUE
;
17181 gnu_section
= FALSE
;
17184 attr_len
-= namelen
;
17186 while (attr_len
> 0 && p
< contents
+ sect
->sh_size
)
17191 unsigned char * end
;
17193 /* PR binutils/17531: Safe handling of corrupt files. */
17196 error (_("Unused bytes at end of section\n"));
17203 size
= byte_get (p
, 4);
17204 if (size
> attr_len
)
17206 error (_("Bad subsection length (%u > %u)\n"),
17207 (unsigned) size
, (unsigned) attr_len
);
17211 /* PR binutils/17531: Safe handling of corrupt files. */
17214 error (_("Bad subsection length (%u < 6)\n"),
17222 end
= p
+ size
- 1;
17223 assert (end
<= contents
+ sect
->sh_size
);
17229 printf (_("File Attributes\n"));
17232 printf (_("Section Attributes:"));
17235 printf (_("Symbol Attributes:"));
17236 /* Fall through. */
17240 READ_ULEB (val
, p
, end
);
17243 printf (" %d", val
);
17248 printf (_("Unknown tag: %d\n"), tag
);
17249 public_section
= FALSE
;
17253 if (public_section
&& display_pub_attribute
!= NULL
)
17256 p
= display_pub_attribute (p
, end
);
17259 else if (gnu_section
&& display_proc_gnu_attribute
!= NULL
)
17262 p
= display_gnu_attribute (p
,
17263 display_proc_gnu_attribute
,
17269 printf (_(" Unknown attribute:\n"));
17270 display_raw_attribute (p
, end
);
17285 /* DATA points to the contents of a MIPS GOT that starts at VMA PLTGOT.
17286 Print the Address, Access and Initial fields of an entry at VMA ADDR
17287 and return the VMA of the next entry, or -1 if there was a problem.
17288 Does not read from DATA_END or beyond. */
17291 print_mips_got_entry (unsigned char * data
, bfd_vma pltgot
, bfd_vma addr
,
17292 unsigned char * data_end
)
17295 print_vma (addr
, LONG_HEX
);
17297 if (addr
< pltgot
+ 0xfff0)
17298 printf ("%6d(gp)", (int) (addr
- pltgot
- 0x7ff0));
17300 printf ("%10s", "");
17303 printf ("%*s", is_32bit_elf
? 8 : 16, _("<unknown>"));
17307 unsigned char * from
= data
+ addr
- pltgot
;
17309 if (from
+ (is_32bit_elf
? 4 : 8) > data_end
)
17311 warn (_("MIPS GOT entry extends beyond the end of available data\n"));
17312 printf ("%*s", is_32bit_elf
? 8 : 16, _("<corrupt>"));
17313 return (bfd_vma
) -1;
17317 entry
= byte_get (data
+ addr
- pltgot
, is_32bit_elf
? 4 : 8);
17318 print_vma (entry
, LONG_HEX
);
17321 return addr
+ (is_32bit_elf
? 4 : 8);
17324 /* DATA points to the contents of a MIPS PLT GOT that starts at VMA
17325 PLTGOT. Print the Address and Initial fields of an entry at VMA
17326 ADDR and return the VMA of the next entry. */
17329 print_mips_pltgot_entry (unsigned char * data
, bfd_vma pltgot
, bfd_vma addr
)
17332 print_vma (addr
, LONG_HEX
);
17335 printf ("%*s", is_32bit_elf
? 8 : 16, _("<unknown>"));
17340 entry
= byte_get (data
+ addr
- pltgot
, is_32bit_elf
? 4 : 8);
17341 print_vma (entry
, LONG_HEX
);
17343 return addr
+ (is_32bit_elf
? 4 : 8);
17347 print_mips_ases (unsigned int mask
)
17349 if (mask
& AFL_ASE_DSP
)
17350 fputs ("\n\tDSP ASE", stdout
);
17351 if (mask
& AFL_ASE_DSPR2
)
17352 fputs ("\n\tDSP R2 ASE", stdout
);
17353 if (mask
& AFL_ASE_DSPR3
)
17354 fputs ("\n\tDSP R3 ASE", stdout
);
17355 if (mask
& AFL_ASE_EVA
)
17356 fputs ("\n\tEnhanced VA Scheme", stdout
);
17357 if (mask
& AFL_ASE_MCU
)
17358 fputs ("\n\tMCU (MicroController) ASE", stdout
);
17359 if (mask
& AFL_ASE_MDMX
)
17360 fputs ("\n\tMDMX ASE", stdout
);
17361 if (mask
& AFL_ASE_MIPS3D
)
17362 fputs ("\n\tMIPS-3D ASE", stdout
);
17363 if (mask
& AFL_ASE_MT
)
17364 fputs ("\n\tMT ASE", stdout
);
17365 if (mask
& AFL_ASE_SMARTMIPS
)
17366 fputs ("\n\tSmartMIPS ASE", stdout
);
17367 if (mask
& AFL_ASE_VIRT
)
17368 fputs ("\n\tVZ ASE", stdout
);
17369 if (mask
& AFL_ASE_MSA
)
17370 fputs ("\n\tMSA ASE", stdout
);
17371 if (mask
& AFL_ASE_MIPS16
)
17372 fputs ("\n\tMIPS16 ASE", stdout
);
17373 if (mask
& AFL_ASE_MICROMIPS
)
17374 fputs ("\n\tMICROMIPS ASE", stdout
);
17375 if (mask
& AFL_ASE_XPA
)
17376 fputs ("\n\tXPA ASE", stdout
);
17377 if (mask
& AFL_ASE_MIPS16E2
)
17378 fputs ("\n\tMIPS16e2 ASE", stdout
);
17379 if (mask
& AFL_ASE_CRC
)
17380 fputs ("\n\tCRC ASE", stdout
);
17381 if (mask
& AFL_ASE_GINV
)
17382 fputs ("\n\tGINV ASE", stdout
);
17383 if (mask
& AFL_ASE_LOONGSON_MMI
)
17384 fputs ("\n\tLoongson MMI ASE", stdout
);
17385 if (mask
& AFL_ASE_LOONGSON_CAM
)
17386 fputs ("\n\tLoongson CAM ASE", stdout
);
17387 if (mask
& AFL_ASE_LOONGSON_EXT
)
17388 fputs ("\n\tLoongson EXT ASE", stdout
);
17389 if (mask
& AFL_ASE_LOONGSON_EXT2
)
17390 fputs ("\n\tLoongson EXT2 ASE", stdout
);
17392 fprintf (stdout
, "\n\t%s", _("None"));
17393 else if ((mask
& ~AFL_ASE_MASK
) != 0)
17394 fprintf (stdout
, "\n\t%s (%x)", _("Unknown"), mask
& ~AFL_ASE_MASK
);
17398 print_mips_isa_ext (unsigned int isa_ext
)
17403 fputs (_("None"), stdout
);
17406 fputs ("RMI XLR", stdout
);
17408 case AFL_EXT_OCTEON3
:
17409 fputs ("Cavium Networks Octeon3", stdout
);
17411 case AFL_EXT_OCTEON2
:
17412 fputs ("Cavium Networks Octeon2", stdout
);
17414 case AFL_EXT_OCTEONP
:
17415 fputs ("Cavium Networks OcteonP", stdout
);
17417 case AFL_EXT_OCTEON
:
17418 fputs ("Cavium Networks Octeon", stdout
);
17421 fputs ("Toshiba R5900", stdout
);
17424 fputs ("MIPS R4650", stdout
);
17427 fputs ("LSI R4010", stdout
);
17430 fputs ("NEC VR4100", stdout
);
17433 fputs ("Toshiba R3900", stdout
);
17435 case AFL_EXT_10000
:
17436 fputs ("MIPS R10000", stdout
);
17439 fputs ("Broadcom SB-1", stdout
);
17442 fputs ("NEC VR4111/VR4181", stdout
);
17445 fputs ("NEC VR4120", stdout
);
17448 fputs ("NEC VR5400", stdout
);
17451 fputs ("NEC VR5500", stdout
);
17453 case AFL_EXT_LOONGSON_2E
:
17454 fputs ("ST Microelectronics Loongson 2E", stdout
);
17456 case AFL_EXT_LOONGSON_2F
:
17457 fputs ("ST Microelectronics Loongson 2F", stdout
);
17459 case AFL_EXT_INTERAPTIV_MR2
:
17460 fputs ("Imagination interAptiv MR2", stdout
);
17463 fprintf (stdout
, "%s (%d)", _("Unknown"), isa_ext
);
17468 get_mips_reg_size (int reg_size
)
17470 return (reg_size
== AFL_REG_NONE
) ? 0
17471 : (reg_size
== AFL_REG_32
) ? 32
17472 : (reg_size
== AFL_REG_64
) ? 64
17473 : (reg_size
== AFL_REG_128
) ? 128
17478 process_mips_specific (Filedata
* filedata
)
17480 Elf_Internal_Dyn
* entry
;
17481 Elf_Internal_Shdr
*sect
= NULL
;
17482 size_t liblist_offset
= 0;
17483 size_t liblistno
= 0;
17484 size_t conflictsno
= 0;
17485 size_t options_offset
= 0;
17486 size_t conflicts_offset
= 0;
17487 size_t pltrelsz
= 0;
17489 bfd_vma pltgot
= 0;
17490 bfd_vma mips_pltgot
= 0;
17491 bfd_vma jmprel
= 0;
17492 bfd_vma local_gotno
= 0;
17493 bfd_vma gotsym
= 0;
17494 bfd_vma symtabno
= 0;
17495 bfd_boolean res
= TRUE
;
17497 if (! process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
17498 display_mips_gnu_attribute
))
17501 sect
= find_section (filedata
, ".MIPS.abiflags");
17505 Elf_External_ABIFlags_v0
*abiflags_ext
;
17506 Elf_Internal_ABIFlags_v0 abiflags_in
;
17508 if (sizeof (Elf_External_ABIFlags_v0
) != sect
->sh_size
)
17510 error (_("Corrupt MIPS ABI Flags section.\n"));
17515 abiflags_ext
= get_data (NULL
, filedata
, sect
->sh_offset
, 1,
17516 sect
->sh_size
, _("MIPS ABI Flags section"));
17519 abiflags_in
.version
= BYTE_GET (abiflags_ext
->version
);
17520 abiflags_in
.isa_level
= BYTE_GET (abiflags_ext
->isa_level
);
17521 abiflags_in
.isa_rev
= BYTE_GET (abiflags_ext
->isa_rev
);
17522 abiflags_in
.gpr_size
= BYTE_GET (abiflags_ext
->gpr_size
);
17523 abiflags_in
.cpr1_size
= BYTE_GET (abiflags_ext
->cpr1_size
);
17524 abiflags_in
.cpr2_size
= BYTE_GET (abiflags_ext
->cpr2_size
);
17525 abiflags_in
.fp_abi
= BYTE_GET (abiflags_ext
->fp_abi
);
17526 abiflags_in
.isa_ext
= BYTE_GET (abiflags_ext
->isa_ext
);
17527 abiflags_in
.ases
= BYTE_GET (abiflags_ext
->ases
);
17528 abiflags_in
.flags1
= BYTE_GET (abiflags_ext
->flags1
);
17529 abiflags_in
.flags2
= BYTE_GET (abiflags_ext
->flags2
);
17531 printf ("\nMIPS ABI Flags Version: %d\n", abiflags_in
.version
);
17532 printf ("\nISA: MIPS%d", abiflags_in
.isa_level
);
17533 if (abiflags_in
.isa_rev
> 1)
17534 printf ("r%d", abiflags_in
.isa_rev
);
17535 printf ("\nGPR size: %d",
17536 get_mips_reg_size (abiflags_in
.gpr_size
));
17537 printf ("\nCPR1 size: %d",
17538 get_mips_reg_size (abiflags_in
.cpr1_size
));
17539 printf ("\nCPR2 size: %d",
17540 get_mips_reg_size (abiflags_in
.cpr2_size
));
17541 fputs ("\nFP ABI: ", stdout
);
17542 print_mips_fp_abi_value (abiflags_in
.fp_abi
);
17543 fputs ("ISA Extension: ", stdout
);
17544 print_mips_isa_ext (abiflags_in
.isa_ext
);
17545 fputs ("\nASEs:", stdout
);
17546 print_mips_ases (abiflags_in
.ases
);
17547 printf ("\nFLAGS 1: %8.8lx", abiflags_in
.flags1
);
17548 printf ("\nFLAGS 2: %8.8lx", abiflags_in
.flags2
);
17549 fputc ('\n', stdout
);
17550 free (abiflags_ext
);
17555 /* We have a lot of special sections. Thanks SGI! */
17556 if (filedata
->dynamic_section
== NULL
)
17558 /* No dynamic information available. See if there is static GOT. */
17559 sect
= find_section (filedata
, ".got");
17562 unsigned char *data_end
;
17563 unsigned char *data
;
17567 pltgot
= sect
->sh_addr
;
17570 addr_size
= (is_32bit_elf
? 4 : 8);
17571 end
= pltgot
+ sect
->sh_size
;
17573 data
= (unsigned char *) get_data (NULL
, filedata
, sect
->sh_offset
,
17575 _("Global Offset Table data"));
17576 /* PR 12855: Null data is handled gracefully throughout. */
17577 data_end
= data
+ (end
- pltgot
);
17579 printf (_("\nStatic GOT:\n"));
17580 printf (_(" Canonical gp value: "));
17581 print_vma (ent
+ 0x7ff0, LONG_HEX
);
17584 /* In a dynamic binary GOT[0] is reserved for the dynamic
17585 loader to store the lazy resolver pointer, however in
17586 a static binary it may well have been omitted and GOT
17587 reduced to a table of addresses.
17588 PR 21344: Check for the entry being fully available
17589 before fetching it. */
17591 && data
+ ent
- pltgot
+ addr_size
<= data_end
17592 && byte_get (data
+ ent
- pltgot
, addr_size
) == 0)
17594 printf (_(" Reserved entries:\n"));
17595 printf (_(" %*s %10s %*s\n"),
17596 addr_size
* 2, _("Address"), _("Access"),
17597 addr_size
* 2, _("Value"));
17598 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
17600 if (ent
== (bfd_vma
) -1)
17601 goto sgot_print_fail
;
17603 /* Check for the MSB of GOT[1] being set, identifying a
17604 GNU object. This entry will be used by some runtime
17605 loaders, to store the module pointer. Otherwise this
17606 is an ordinary local entry.
17607 PR 21344: Check for the entry being fully available
17608 before fetching it. */
17610 && data
+ ent
- pltgot
+ addr_size
<= data_end
17611 && (byte_get (data
+ ent
- pltgot
, addr_size
)
17612 >> (addr_size
* 8 - 1)) != 0)
17614 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
17616 if (ent
== (bfd_vma
) -1)
17617 goto sgot_print_fail
;
17622 if (data
!= NULL
&& ent
< end
)
17624 printf (_(" Local entries:\n"));
17625 printf (" %*s %10s %*s\n",
17626 addr_size
* 2, _("Address"), _("Access"),
17627 addr_size
* 2, _("Value"));
17630 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
17632 if (ent
== (bfd_vma
) -1)
17633 goto sgot_print_fail
;
17644 for (entry
= filedata
->dynamic_section
;
17645 /* PR 17531 file: 012-50589-0.004. */
17646 (entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
17647 && entry
->d_tag
!= DT_NULL
);
17649 switch (entry
->d_tag
)
17651 case DT_MIPS_LIBLIST
:
17653 = offset_from_vma (filedata
, entry
->d_un
.d_val
,
17654 liblistno
* sizeof (Elf32_External_Lib
));
17656 case DT_MIPS_LIBLISTNO
:
17657 liblistno
= entry
->d_un
.d_val
;
17659 case DT_MIPS_OPTIONS
:
17660 options_offset
= offset_from_vma (filedata
, entry
->d_un
.d_val
, 0);
17662 case DT_MIPS_CONFLICT
:
17664 = offset_from_vma (filedata
, entry
->d_un
.d_val
,
17665 conflictsno
* sizeof (Elf32_External_Conflict
));
17667 case DT_MIPS_CONFLICTNO
:
17668 conflictsno
= entry
->d_un
.d_val
;
17671 pltgot
= entry
->d_un
.d_ptr
;
17673 case DT_MIPS_LOCAL_GOTNO
:
17674 local_gotno
= entry
->d_un
.d_val
;
17676 case DT_MIPS_GOTSYM
:
17677 gotsym
= entry
->d_un
.d_val
;
17679 case DT_MIPS_SYMTABNO
:
17680 symtabno
= entry
->d_un
.d_val
;
17682 case DT_MIPS_PLTGOT
:
17683 mips_pltgot
= entry
->d_un
.d_ptr
;
17686 pltrel
= entry
->d_un
.d_val
;
17689 pltrelsz
= entry
->d_un
.d_val
;
17692 jmprel
= entry
->d_un
.d_ptr
;
17698 if (liblist_offset
!= 0 && liblistno
!= 0 && do_dynamic
)
17700 Elf32_External_Lib
* elib
;
17703 elib
= (Elf32_External_Lib
*) get_data (NULL
, filedata
, liblist_offset
,
17704 sizeof (Elf32_External_Lib
),
17706 _("liblist section data"));
17709 printf (ngettext ("\nSection '.liblist' contains %lu entry:\n",
17710 "\nSection '.liblist' contains %lu entries:\n",
17711 (unsigned long) liblistno
),
17712 (unsigned long) liblistno
);
17713 fputs (_(" Library Time Stamp Checksum Version Flags\n"),
17716 for (cnt
= 0; cnt
< liblistno
; ++cnt
)
17723 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
17724 atime
= BYTE_GET (elib
[cnt
].l_time_stamp
);
17725 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
17726 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
17727 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
17729 tmp
= gmtime (&atime
);
17730 snprintf (timebuf
, sizeof (timebuf
),
17731 "%04u-%02u-%02uT%02u:%02u:%02u",
17732 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
17733 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
17735 printf ("%3lu: ", (unsigned long) cnt
);
17736 if (VALID_DYNAMIC_NAME (filedata
, liblist
.l_name
))
17737 print_symbol (20, GET_DYNAMIC_NAME (filedata
, liblist
.l_name
));
17739 printf (_("<corrupt: %9ld>"), liblist
.l_name
);
17740 printf (" %s %#10lx %-7ld", timebuf
, liblist
.l_checksum
,
17741 liblist
.l_version
);
17743 if (liblist
.l_flags
== 0)
17747 static const struct
17754 { " EXACT_MATCH", LL_EXACT_MATCH
},
17755 { " IGNORE_INT_VER", LL_IGNORE_INT_VER
},
17756 { " REQUIRE_MINOR", LL_REQUIRE_MINOR
},
17757 { " EXPORTS", LL_EXPORTS
},
17758 { " DELAY_LOAD", LL_DELAY_LOAD
},
17759 { " DELTA", LL_DELTA
}
17761 int flags
= liblist
.l_flags
;
17764 for (fcnt
= 0; fcnt
< ARRAY_SIZE (l_flags_vals
); ++fcnt
)
17765 if ((flags
& l_flags_vals
[fcnt
].bit
) != 0)
17767 fputs (l_flags_vals
[fcnt
].name
, stdout
);
17768 flags
^= l_flags_vals
[fcnt
].bit
;
17771 printf (" %#x", (unsigned int) flags
);
17783 if (options_offset
!= 0)
17785 Elf_External_Options
* eopt
;
17788 sect
= filedata
->section_headers
;
17790 /* Find the section header so that we get the size. */
17791 sect
= find_section_by_type (filedata
, SHT_MIPS_OPTIONS
);
17792 /* PR 17533 file: 012-277276-0.004. */
17795 error (_("No MIPS_OPTIONS header found\n"));
17799 if (sect
->sh_size
< sizeof (* eopt
))
17801 error (_("The MIPS options section is too small.\n"));
17805 eopt
= (Elf_External_Options
*) get_data (NULL
, filedata
, options_offset
, 1,
17806 sect
->sh_size
, _("options"));
17809 Elf_Internal_Options option
;
17812 while (offset
<= sect
->sh_size
- sizeof (* eopt
))
17814 Elf_External_Options
* eoption
;
17815 unsigned int optsize
;
17817 eoption
= (Elf_External_Options
*) ((char *) eopt
+ offset
);
17819 optsize
= BYTE_GET (eoption
->size
);
17821 /* PR 17531: file: ffa0fa3b. */
17822 if (optsize
< sizeof (* eopt
)
17823 || optsize
> sect
->sh_size
- offset
)
17825 error (_("Invalid size (%u) for MIPS option\n"),
17834 printf (ngettext ("\nSection '%s' contains %d entry:\n",
17835 "\nSection '%s' contains %d entries:\n",
17837 printable_section_name (filedata
, sect
), cnt
);
17843 Elf_External_Options
* eoption
;
17845 eoption
= (Elf_External_Options
*) ((char *) eopt
+ offset
);
17847 option
.kind
= BYTE_GET (eoption
->kind
);
17848 option
.size
= BYTE_GET (eoption
->size
);
17849 option
.section
= BYTE_GET (eoption
->section
);
17850 option
.info
= BYTE_GET (eoption
->info
);
17852 switch (option
.kind
)
17855 /* This shouldn't happen. */
17856 printf (" NULL %" PRId16
" %" PRIx32
,
17857 option
.section
, option
.info
);
17861 printf (" REGINFO ");
17862 if (filedata
->file_header
.e_machine
== EM_MIPS
)
17864 Elf32_External_RegInfo
* ereg
;
17865 Elf32_RegInfo reginfo
;
17868 if (option
.size
< (sizeof (Elf_External_Options
)
17869 + sizeof (Elf32_External_RegInfo
)))
17871 printf (_("<corrupt>\n"));
17872 error (_("Truncated MIPS REGINFO option\n"));
17877 ereg
= (Elf32_External_RegInfo
*) (eoption
+ 1);
17879 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
17880 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
17881 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
17882 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
17883 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
17884 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
17886 printf ("GPR %08" PRIx32
" GP 0x%" PRIx32
"\n",
17887 reginfo
.ri_gprmask
, reginfo
.ri_gp_value
);
17889 " CPR0 %08" PRIx32
" CPR1 %08" PRIx32
17890 " CPR2 %08" PRIx32
" CPR3 %08" PRIx32
"\n",
17891 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
17892 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
17897 Elf64_External_RegInfo
* ereg
;
17898 Elf64_Internal_RegInfo reginfo
;
17900 if (option
.size
< (sizeof (Elf_External_Options
)
17901 + sizeof (Elf64_External_RegInfo
)))
17903 printf (_("<corrupt>\n"));
17904 error (_("Truncated MIPS REGINFO option\n"));
17909 ereg
= (Elf64_External_RegInfo
*) (eoption
+ 1);
17910 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
17911 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
17912 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
17913 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
17914 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
17915 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
17917 printf ("GPR %08" PRIx32
" GP 0x%" PRIx64
"\n",
17918 reginfo
.ri_gprmask
, reginfo
.ri_gp_value
);
17920 " CPR0 %08" PRIx32
" CPR1 %08" PRIx32
17921 " CPR2 %08" PRIx32
" CPR3 %08" PRIx32
"\n",
17922 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
17923 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
17925 offset
+= option
.size
;
17928 case ODK_EXCEPTIONS
:
17929 fputs (" EXCEPTIONS fpe_min(", stdout
);
17930 process_mips_fpe_exception (option
.info
& OEX_FPU_MIN
);
17931 fputs (") fpe_max(", stdout
);
17932 process_mips_fpe_exception ((option
.info
& OEX_FPU_MAX
) >> 8);
17933 fputs (")", stdout
);
17935 if (option
.info
& OEX_PAGE0
)
17936 fputs (" PAGE0", stdout
);
17937 if (option
.info
& OEX_SMM
)
17938 fputs (" SMM", stdout
);
17939 if (option
.info
& OEX_FPDBUG
)
17940 fputs (" FPDBUG", stdout
);
17941 if (option
.info
& OEX_DISMISS
)
17942 fputs (" DISMISS", stdout
);
17946 fputs (" PAD ", stdout
);
17947 if (option
.info
& OPAD_PREFIX
)
17948 fputs (" PREFIX", stdout
);
17949 if (option
.info
& OPAD_POSTFIX
)
17950 fputs (" POSTFIX", stdout
);
17951 if (option
.info
& OPAD_SYMBOL
)
17952 fputs (" SYMBOL", stdout
);
17956 fputs (" HWPATCH ", stdout
);
17957 if (option
.info
& OHW_R4KEOP
)
17958 fputs (" R4KEOP", stdout
);
17959 if (option
.info
& OHW_R8KPFETCH
)
17960 fputs (" R8KPFETCH", stdout
);
17961 if (option
.info
& OHW_R5KEOP
)
17962 fputs (" R5KEOP", stdout
);
17963 if (option
.info
& OHW_R5KCVTL
)
17964 fputs (" R5KCVTL", stdout
);
17968 fputs (" FILL ", stdout
);
17969 /* XXX Print content of info word? */
17973 fputs (" TAGS ", stdout
);
17974 /* XXX Print content of info word? */
17978 fputs (" HWAND ", stdout
);
17979 if (option
.info
& OHWA0_R4KEOP_CHECKED
)
17980 fputs (" R4KEOP_CHECKED", stdout
);
17981 if (option
.info
& OHWA0_R4KEOP_CLEAN
)
17982 fputs (" R4KEOP_CLEAN", stdout
);
17986 fputs (" HWOR ", stdout
);
17987 if (option
.info
& OHWA0_R4KEOP_CHECKED
)
17988 fputs (" R4KEOP_CHECKED", stdout
);
17989 if (option
.info
& OHWA0_R4KEOP_CLEAN
)
17990 fputs (" R4KEOP_CLEAN", stdout
);
17994 printf (" GP_GROUP %#06x self-contained %#06x",
17995 option
.info
& OGP_GROUP
,
17996 (option
.info
& OGP_SELF
) >> 16);
18000 printf (" IDENT %#06x self-contained %#06x",
18001 option
.info
& OGP_GROUP
,
18002 (option
.info
& OGP_SELF
) >> 16);
18006 /* This shouldn't happen. */
18007 printf (" %3d ??? %" PRId16
" %" PRIx32
,
18008 option
.kind
, option
.section
, option
.info
);
18012 len
= sizeof (* eopt
);
18013 while (len
< option
.size
)
18015 unsigned char datum
= *((unsigned char *) eoption
+ len
);
18017 if (ISPRINT (datum
))
18018 printf ("%c", datum
);
18020 printf ("\\%03o", datum
);
18023 fputs ("\n", stdout
);
18025 offset
+= option
.size
;
18033 if (conflicts_offset
!= 0 && conflictsno
!= 0)
18035 Elf32_Conflict
* iconf
;
18038 if (filedata
->dynamic_symbols
== NULL
)
18040 error (_("conflict list found without a dynamic symbol table\n"));
18044 /* PR 21345 - print a slightly more helpful error message
18045 if we are sure that the cmalloc will fail. */
18046 if (conflictsno
> filedata
->file_size
/ sizeof (* iconf
))
18048 error (_("Overlarge number of conflicts detected: %lx\n"),
18049 (long) conflictsno
);
18053 iconf
= (Elf32_Conflict
*) cmalloc (conflictsno
, sizeof (* iconf
));
18056 error (_("Out of memory allocating space for dynamic conflicts\n"));
18062 Elf32_External_Conflict
* econf32
;
18064 econf32
= (Elf32_External_Conflict
*)
18065 get_data (NULL
, filedata
, conflicts_offset
,
18066 sizeof (*econf32
), conflictsno
, _("conflict"));
18073 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
18074 iconf
[cnt
] = BYTE_GET (econf32
[cnt
]);
18080 Elf64_External_Conflict
* econf64
;
18082 econf64
= (Elf64_External_Conflict
*)
18083 get_data (NULL
, filedata
, conflicts_offset
,
18084 sizeof (*econf64
), conflictsno
, _("conflict"));
18091 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
18092 iconf
[cnt
] = BYTE_GET (econf64
[cnt
]);
18097 printf (ngettext ("\nSection '.conflict' contains %lu entry:\n",
18098 "\nSection '.conflict' contains %lu entries:\n",
18099 (unsigned long) conflictsno
),
18100 (unsigned long) conflictsno
);
18101 puts (_(" Num: Index Value Name"));
18103 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
18105 printf ("%5lu: %8lu ", (unsigned long) cnt
, iconf
[cnt
]);
18107 if (iconf
[cnt
] >= filedata
->num_dynamic_syms
)
18108 printf (_("<corrupt symbol index>"));
18111 Elf_Internal_Sym
* psym
;
18113 psym
= & filedata
->dynamic_symbols
[iconf
[cnt
]];
18114 print_vma (psym
->st_value
, FULL_HEX
);
18116 if (VALID_DYNAMIC_NAME (filedata
, psym
->st_name
))
18117 print_symbol (25, GET_DYNAMIC_NAME (filedata
, psym
->st_name
));
18119 printf (_("<corrupt: %14ld>"), psym
->st_name
);
18127 if (pltgot
!= 0 && local_gotno
!= 0)
18129 bfd_vma ent
, local_end
, global_end
;
18131 unsigned char * data
;
18132 unsigned char * data_end
;
18136 addr_size
= (is_32bit_elf
? 4 : 8);
18137 local_end
= pltgot
+ local_gotno
* addr_size
;
18139 /* PR binutils/17533 file: 012-111227-0.004 */
18140 if (symtabno
< gotsym
)
18142 error (_("The GOT symbol offset (%lu) is greater than the symbol table size (%lu)\n"),
18143 (unsigned long) gotsym
, (unsigned long) symtabno
);
18147 global_end
= local_end
+ (symtabno
- gotsym
) * addr_size
;
18148 /* PR 17531: file: 54c91a34. */
18149 if (global_end
< local_end
)
18151 error (_("Too many GOT symbols: %lu\n"), (unsigned long) symtabno
);
18155 offset
= offset_from_vma (filedata
, pltgot
, global_end
- pltgot
);
18156 data
= (unsigned char *) get_data (NULL
, filedata
, offset
,
18157 global_end
- pltgot
, 1,
18158 _("Global Offset Table data"));
18159 /* PR 12855: Null data is handled gracefully throughout. */
18160 data_end
= data
+ (global_end
- pltgot
);
18162 printf (_("\nPrimary GOT:\n"));
18163 printf (_(" Canonical gp value: "));
18164 print_vma (pltgot
+ 0x7ff0, LONG_HEX
);
18167 printf (_(" Reserved entries:\n"));
18168 printf (_(" %*s %10s %*s Purpose\n"),
18169 addr_size
* 2, _("Address"), _("Access"),
18170 addr_size
* 2, _("Initial"));
18171 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
18172 printf (_(" Lazy resolver\n"));
18173 if (ent
== (bfd_vma
) -1)
18174 goto got_print_fail
;
18176 /* Check for the MSB of GOT[1] being set, denoting a GNU object.
18177 This entry will be used by some runtime loaders, to store the
18178 module pointer. Otherwise this is an ordinary local entry.
18179 PR 21344: Check for the entry being fully available before
18182 && data
+ ent
- pltgot
+ addr_size
<= data_end
18183 && (byte_get (data
+ ent
- pltgot
, addr_size
)
18184 >> (addr_size
* 8 - 1)) != 0)
18186 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
18187 printf (_(" Module pointer (GNU extension)\n"));
18188 if (ent
== (bfd_vma
) -1)
18189 goto got_print_fail
;
18193 if (data
!= NULL
&& ent
< local_end
)
18195 printf (_(" Local entries:\n"));
18196 printf (" %*s %10s %*s\n",
18197 addr_size
* 2, _("Address"), _("Access"),
18198 addr_size
* 2, _("Initial"));
18199 while (ent
< local_end
)
18201 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
18203 if (ent
== (bfd_vma
) -1)
18204 goto got_print_fail
;
18209 if (data
!= NULL
&& gotsym
< symtabno
)
18213 printf (_(" Global entries:\n"));
18214 printf (" %*s %10s %*s %*s %-7s %3s %s\n",
18215 addr_size
* 2, _("Address"),
18217 addr_size
* 2, _("Initial"),
18218 addr_size
* 2, _("Sym.Val."),
18220 /* Note for translators: "Ndx" = abbreviated form of "Index". */
18221 _("Ndx"), _("Name"));
18223 sym_width
= (is_32bit_elf
? 80 : 160) - 28 - addr_size
* 6 - 1;
18225 for (i
= gotsym
; i
< symtabno
; i
++)
18227 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
18230 if (filedata
->dynamic_symbols
== NULL
)
18231 printf (_("<no dynamic symbols>"));
18232 else if (i
< filedata
->num_dynamic_syms
)
18234 Elf_Internal_Sym
* psym
= filedata
->dynamic_symbols
+ i
;
18236 print_vma (psym
->st_value
, LONG_HEX
);
18237 printf (" %-7s %3s ",
18238 get_symbol_type (filedata
, ELF_ST_TYPE (psym
->st_info
)),
18239 get_symbol_index_type (filedata
, psym
->st_shndx
));
18241 if (VALID_DYNAMIC_NAME (filedata
, psym
->st_name
))
18242 print_symbol (sym_width
,
18243 GET_DYNAMIC_NAME (filedata
, psym
->st_name
));
18245 printf (_("<corrupt: %14ld>"), psym
->st_name
);
18248 printf (_("<symbol index %lu exceeds number of dynamic symbols>"),
18249 (unsigned long) i
);
18252 if (ent
== (bfd_vma
) -1)
18262 if (mips_pltgot
!= 0 && jmprel
!= 0 && pltrel
!= 0 && pltrelsz
!= 0)
18265 size_t offset
, rel_offset
;
18266 unsigned long count
, i
;
18267 unsigned char * data
;
18268 int addr_size
, sym_width
;
18269 Elf_Internal_Rela
* rels
;
18271 rel_offset
= offset_from_vma (filedata
, jmprel
, pltrelsz
);
18272 if (pltrel
== DT_RELA
)
18274 if (!slurp_rela_relocs (filedata
, rel_offset
, pltrelsz
, &rels
, &count
))
18279 if (!slurp_rel_relocs (filedata
, rel_offset
, pltrelsz
, &rels
, &count
))
18284 addr_size
= (is_32bit_elf
? 4 : 8);
18285 end
= mips_pltgot
+ (2 + count
) * addr_size
;
18287 offset
= offset_from_vma (filedata
, mips_pltgot
, end
- mips_pltgot
);
18288 data
= (unsigned char *) get_data (NULL
, filedata
, offset
, end
- mips_pltgot
,
18289 1, _("Procedure Linkage Table data"));
18296 printf ("\nPLT GOT:\n\n");
18297 printf (_(" Reserved entries:\n"));
18298 printf (_(" %*s %*s Purpose\n"),
18299 addr_size
* 2, _("Address"), addr_size
* 2, _("Initial"));
18300 ent
= print_mips_pltgot_entry (data
, mips_pltgot
, ent
);
18301 printf (_(" PLT lazy resolver\n"));
18302 ent
= print_mips_pltgot_entry (data
, mips_pltgot
, ent
);
18303 printf (_(" Module pointer\n"));
18306 printf (_(" Entries:\n"));
18307 printf (" %*s %*s %*s %-7s %3s %s\n",
18308 addr_size
* 2, _("Address"),
18309 addr_size
* 2, _("Initial"),
18310 addr_size
* 2, _("Sym.Val."), _("Type"), _("Ndx"), _("Name"));
18311 sym_width
= (is_32bit_elf
? 80 : 160) - 17 - addr_size
* 6 - 1;
18312 for (i
= 0; i
< count
; i
++)
18314 unsigned long idx
= get_reloc_symindex (rels
[i
].r_info
);
18316 ent
= print_mips_pltgot_entry (data
, mips_pltgot
, ent
);
18319 if (idx
>= filedata
->num_dynamic_syms
)
18320 printf (_("<corrupt symbol index: %lu>"), idx
);
18323 Elf_Internal_Sym
* psym
= filedata
->dynamic_symbols
+ idx
;
18325 print_vma (psym
->st_value
, LONG_HEX
);
18326 printf (" %-7s %3s ",
18327 get_symbol_type (filedata
, ELF_ST_TYPE (psym
->st_info
)),
18328 get_symbol_index_type (filedata
, psym
->st_shndx
));
18329 if (VALID_DYNAMIC_NAME (filedata
, psym
->st_name
))
18330 print_symbol (sym_width
,
18331 GET_DYNAMIC_NAME (filedata
, psym
->st_name
));
18333 printf (_("<corrupt: %14ld>"), psym
->st_name
);
18347 process_nds32_specific (Filedata
* filedata
)
18349 Elf_Internal_Shdr
*sect
= NULL
;
18351 sect
= find_section (filedata
, ".nds32_e_flags");
18352 if (sect
!= NULL
&& sect
->sh_size
>= 4)
18354 unsigned char *buf
;
18357 printf ("\nNDS32 elf flags section:\n");
18358 buf
= get_data (NULL
, filedata
, sect
->sh_offset
, 1, 4,
18359 _("NDS32 elf flags section"));
18364 flag
= byte_get (buf
, 4);
18366 switch (flag
& 0x3)
18369 printf ("(VEC_SIZE):\tNo entry.\n");
18372 printf ("(VEC_SIZE):\t4 bytes\n");
18375 printf ("(VEC_SIZE):\t16 bytes\n");
18378 printf ("(VEC_SIZE):\treserved\n");
18387 process_gnu_liblist (Filedata
* filedata
)
18389 Elf_Internal_Shdr
* section
;
18390 Elf_Internal_Shdr
* string_sec
;
18391 Elf32_External_Lib
* elib
;
18393 size_t strtab_size
;
18395 unsigned long num_liblist
;
18397 bfd_boolean res
= TRUE
;
18402 for (i
= 0, section
= filedata
->section_headers
;
18403 i
< filedata
->file_header
.e_shnum
;
18406 switch (section
->sh_type
)
18408 case SHT_GNU_LIBLIST
:
18409 if (section
->sh_link
>= filedata
->file_header
.e_shnum
)
18412 elib
= (Elf32_External_Lib
*)
18413 get_data (NULL
, filedata
, section
->sh_offset
, 1, section
->sh_size
,
18414 _("liblist section data"));
18422 string_sec
= filedata
->section_headers
+ section
->sh_link
;
18423 strtab
= (char *) get_data (NULL
, filedata
, string_sec
->sh_offset
, 1,
18424 string_sec
->sh_size
,
18425 _("liblist string table"));
18427 || section
->sh_entsize
!= sizeof (Elf32_External_Lib
))
18434 strtab_size
= string_sec
->sh_size
;
18436 num_liblist
= section
->sh_size
/ sizeof (Elf32_External_Lib
);
18437 printf (ngettext ("\nLibrary list section '%s' contains %lu entries:\n",
18438 "\nLibrary list section '%s' contains %lu entries:\n",
18440 printable_section_name (filedata
, section
),
18443 puts (_(" Library Time Stamp Checksum Version Flags"));
18445 for (cnt
= 0; cnt
< section
->sh_size
/ sizeof (Elf32_External_Lib
);
18453 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
18454 atime
= BYTE_GET (elib
[cnt
].l_time_stamp
);
18455 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
18456 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
18457 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
18459 tmp
= gmtime (&atime
);
18460 snprintf (timebuf
, sizeof (timebuf
),
18461 "%04u-%02u-%02uT%02u:%02u:%02u",
18462 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
18463 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
18465 printf ("%3lu: ", (unsigned long) cnt
);
18467 printf ("%-20s", liblist
.l_name
< strtab_size
18468 ? strtab
+ liblist
.l_name
: _("<corrupt>"));
18470 printf ("%-20.20s", liblist
.l_name
< strtab_size
18471 ? strtab
+ liblist
.l_name
: _("<corrupt>"));
18472 printf (" %s %#010lx %-7ld %-7ld\n", timebuf
, liblist
.l_checksum
,
18473 liblist
.l_version
, liblist
.l_flags
);
18484 static const char *
18485 get_note_type (Filedata
* filedata
, unsigned e_type
)
18487 static char buff
[64];
18489 if (filedata
->file_header
.e_type
== ET_CORE
)
18493 return _("NT_AUXV (auxiliary vector)");
18495 return _("NT_PRSTATUS (prstatus structure)");
18497 return _("NT_FPREGSET (floating point registers)");
18499 return _("NT_PRPSINFO (prpsinfo structure)");
18500 case NT_TASKSTRUCT
:
18501 return _("NT_TASKSTRUCT (task structure)");
18503 return _("NT_PRXFPREG (user_xfpregs structure)");
18505 return _("NT_PPC_VMX (ppc Altivec registers)");
18507 return _("NT_PPC_VSX (ppc VSX registers)");
18509 return _("NT_PPC_TAR (ppc TAR register)");
18511 return _("NT_PPC_PPR (ppc PPR register)");
18513 return _("NT_PPC_DSCR (ppc DSCR register)");
18515 return _("NT_PPC_EBB (ppc EBB registers)");
18517 return _("NT_PPC_PMU (ppc PMU registers)");
18518 case NT_PPC_TM_CGPR
:
18519 return _("NT_PPC_TM_CGPR (ppc checkpointed GPR registers)");
18520 case NT_PPC_TM_CFPR
:
18521 return _("NT_PPC_TM_CFPR (ppc checkpointed floating point registers)");
18522 case NT_PPC_TM_CVMX
:
18523 return _("NT_PPC_TM_CVMX (ppc checkpointed Altivec registers)");
18524 case NT_PPC_TM_CVSX
:
18525 return _("NT_PPC_TM_CVSX (ppc checkpointed VSX registers)");
18526 case NT_PPC_TM_SPR
:
18527 return _("NT_PPC_TM_SPR (ppc TM special purpose registers)");
18528 case NT_PPC_TM_CTAR
:
18529 return _("NT_PPC_TM_CTAR (ppc checkpointed TAR register)");
18530 case NT_PPC_TM_CPPR
:
18531 return _("NT_PPC_TM_CPPR (ppc checkpointed PPR register)");
18532 case NT_PPC_TM_CDSCR
:
18533 return _("NT_PPC_TM_CDSCR (ppc checkpointed DSCR register)");
18535 return _("NT_386_TLS (x86 TLS information)");
18536 case NT_386_IOPERM
:
18537 return _("NT_386_IOPERM (x86 I/O permissions)");
18538 case NT_X86_XSTATE
:
18539 return _("NT_X86_XSTATE (x86 XSAVE extended state)");
18541 return _("NT_X86_CET (x86 CET state)");
18542 case NT_S390_HIGH_GPRS
:
18543 return _("NT_S390_HIGH_GPRS (s390 upper register halves)");
18544 case NT_S390_TIMER
:
18545 return _("NT_S390_TIMER (s390 timer register)");
18546 case NT_S390_TODCMP
:
18547 return _("NT_S390_TODCMP (s390 TOD comparator register)");
18548 case NT_S390_TODPREG
:
18549 return _("NT_S390_TODPREG (s390 TOD programmable register)");
18551 return _("NT_S390_CTRS (s390 control registers)");
18552 case NT_S390_PREFIX
:
18553 return _("NT_S390_PREFIX (s390 prefix register)");
18554 case NT_S390_LAST_BREAK
:
18555 return _("NT_S390_LAST_BREAK (s390 last breaking event address)");
18556 case NT_S390_SYSTEM_CALL
:
18557 return _("NT_S390_SYSTEM_CALL (s390 system call restart data)");
18559 return _("NT_S390_TDB (s390 transaction diagnostic block)");
18560 case NT_S390_VXRS_LOW
:
18561 return _("NT_S390_VXRS_LOW (s390 vector registers 0-15 upper half)");
18562 case NT_S390_VXRS_HIGH
:
18563 return _("NT_S390_VXRS_HIGH (s390 vector registers 16-31)");
18564 case NT_S390_GS_CB
:
18565 return _("NT_S390_GS_CB (s390 guarded-storage registers)");
18566 case NT_S390_GS_BC
:
18567 return _("NT_S390_GS_BC (s390 guarded-storage broadcast control)");
18569 return _("NT_ARM_VFP (arm VFP registers)");
18571 return _("NT_ARM_TLS (AArch TLS registers)");
18572 case NT_ARM_HW_BREAK
:
18573 return _("NT_ARM_HW_BREAK (AArch hardware breakpoint registers)");
18574 case NT_ARM_HW_WATCH
:
18575 return _("NT_ARM_HW_WATCH (AArch hardware watchpoint registers)");
18577 return _("NT_ARC_V2 (ARC HS accumulator/extra registers)");
18579 return _("NT_PSTATUS (pstatus structure)");
18581 return _("NT_FPREGS (floating point registers)");
18583 return _("NT_PSINFO (psinfo structure)");
18585 return _("NT_LWPSTATUS (lwpstatus_t structure)");
18587 return _("NT_LWPSINFO (lwpsinfo_t structure)");
18588 case NT_WIN32PSTATUS
:
18589 return _("NT_WIN32PSTATUS (win32_pstatus structure)");
18591 return _("NT_SIGINFO (siginfo_t data)");
18593 return _("NT_FILE (mapped files)");
18601 return _("NT_VERSION (version)");
18603 return _("NT_ARCH (architecture)");
18604 case NT_GNU_BUILD_ATTRIBUTE_OPEN
:
18606 case NT_GNU_BUILD_ATTRIBUTE_FUNC
:
18612 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
18617 print_core_note (Elf_Internal_Note
*pnote
)
18619 unsigned int addr_size
= is_32bit_elf
? 4 : 8;
18620 bfd_vma count
, page_size
;
18621 unsigned char *descdata
, *filenames
, *descend
;
18623 if (pnote
->type
!= NT_FILE
)
18633 printf (_(" Cannot decode 64-bit note in 32-bit build\n"));
18634 /* Still "successful". */
18639 if (pnote
->descsz
< 2 * addr_size
)
18641 error (_(" Malformed note - too short for header\n"));
18645 descdata
= (unsigned char *) pnote
->descdata
;
18646 descend
= descdata
+ pnote
->descsz
;
18648 if (descdata
[pnote
->descsz
- 1] != '\0')
18650 error (_(" Malformed note - does not end with \\0\n"));
18654 count
= byte_get (descdata
, addr_size
);
18655 descdata
+= addr_size
;
18657 page_size
= byte_get (descdata
, addr_size
);
18658 descdata
+= addr_size
;
18660 if (count
> ((bfd_vma
) -1 - 2 * addr_size
) / (3 * addr_size
)
18661 || pnote
->descsz
< 2 * addr_size
+ count
* 3 * addr_size
)
18663 error (_(" Malformed note - too short for supplied file count\n"));
18667 printf (_(" Page size: "));
18668 print_vma (page_size
, DEC
);
18671 printf (_(" %*s%*s%*s\n"),
18672 (int) (2 + 2 * addr_size
), _("Start"),
18673 (int) (4 + 2 * addr_size
), _("End"),
18674 (int) (4 + 2 * addr_size
), _("Page Offset"));
18675 filenames
= descdata
+ count
* 3 * addr_size
;
18676 while (count
-- > 0)
18678 bfd_vma start
, end
, file_ofs
;
18680 if (filenames
== descend
)
18682 error (_(" Malformed note - filenames end too early\n"));
18686 start
= byte_get (descdata
, addr_size
);
18687 descdata
+= addr_size
;
18688 end
= byte_get (descdata
, addr_size
);
18689 descdata
+= addr_size
;
18690 file_ofs
= byte_get (descdata
, addr_size
);
18691 descdata
+= addr_size
;
18694 print_vma (start
, FULL_HEX
);
18696 print_vma (end
, FULL_HEX
);
18698 print_vma (file_ofs
, FULL_HEX
);
18699 printf ("\n %s\n", filenames
);
18701 filenames
+= 1 + strlen ((char *) filenames
);
18707 static const char *
18708 get_gnu_elf_note_type (unsigned e_type
)
18710 /* NB/ Keep this switch statement in sync with print_gnu_note (). */
18713 case NT_GNU_ABI_TAG
:
18714 return _("NT_GNU_ABI_TAG (ABI version tag)");
18716 return _("NT_GNU_HWCAP (DSO-supplied software HWCAP info)");
18717 case NT_GNU_BUILD_ID
:
18718 return _("NT_GNU_BUILD_ID (unique build ID bitstring)");
18719 case NT_GNU_GOLD_VERSION
:
18720 return _("NT_GNU_GOLD_VERSION (gold version)");
18721 case NT_GNU_PROPERTY_TYPE_0
:
18722 return _("NT_GNU_PROPERTY_TYPE_0");
18723 case NT_GNU_BUILD_ATTRIBUTE_OPEN
:
18724 return _("NT_GNU_BUILD_ATTRIBUTE_OPEN");
18725 case NT_GNU_BUILD_ATTRIBUTE_FUNC
:
18726 return _("NT_GNU_BUILD_ATTRIBUTE_FUNC");
18729 static char buff
[64];
18731 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
18738 decode_x86_compat_isa (unsigned int bitmask
)
18742 unsigned int bit
= bitmask
& (- bitmask
);
18747 case GNU_PROPERTY_X86_COMPAT_ISA_1_486
:
18750 case GNU_PROPERTY_X86_COMPAT_ISA_1_586
:
18753 case GNU_PROPERTY_X86_COMPAT_ISA_1_686
:
18756 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE
:
18759 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE2
:
18762 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE3
:
18765 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSSE3
:
18768 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE4_1
:
18771 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE4_2
:
18774 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX
:
18777 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX2
:
18780 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512F
:
18781 printf ("AVX512F");
18783 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512CD
:
18784 printf ("AVX512CD");
18786 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512ER
:
18787 printf ("AVX512ER");
18789 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512PF
:
18790 printf ("AVX512PF");
18792 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512VL
:
18793 printf ("AVX512VL");
18795 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512DQ
:
18796 printf ("AVX512DQ");
18798 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512BW
:
18799 printf ("AVX512BW");
18802 printf (_("<unknown: %x>"), bit
);
18811 decode_x86_compat_2_isa (unsigned int bitmask
)
18815 printf (_("<None>"));
18821 unsigned int bit
= bitmask
& (- bitmask
);
18826 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_CMOV
:
18829 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE
:
18832 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE2
:
18835 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE3
:
18838 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSSE3
:
18841 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE4_1
:
18844 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE4_2
:
18847 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX
:
18850 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX2
:
18853 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_FMA
:
18856 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512F
:
18857 printf ("AVX512F");
18859 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512CD
:
18860 printf ("AVX512CD");
18862 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512ER
:
18863 printf ("AVX512ER");
18865 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512PF
:
18866 printf ("AVX512PF");
18868 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512VL
:
18869 printf ("AVX512VL");
18871 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512DQ
:
18872 printf ("AVX512DQ");
18874 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512BW
:
18875 printf ("AVX512BW");
18877 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_4FMAPS
:
18878 printf ("AVX512_4FMAPS");
18880 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_4VNNIW
:
18881 printf ("AVX512_4VNNIW");
18883 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_BITALG
:
18884 printf ("AVX512_BITALG");
18886 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_IFMA
:
18887 printf ("AVX512_IFMA");
18889 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_VBMI
:
18890 printf ("AVX512_VBMI");
18892 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_VBMI2
:
18893 printf ("AVX512_VBMI2");
18895 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_VNNI
:
18896 printf ("AVX512_VNNI");
18898 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_BF16
:
18899 printf ("AVX512_BF16");
18902 printf (_("<unknown: %x>"), bit
);
18911 decode_x86_isa (unsigned int bitmask
)
18915 unsigned int bit
= bitmask
& (- bitmask
);
18920 case GNU_PROPERTY_X86_ISA_1_BASELINE
:
18921 printf ("x86-64-baseline");
18923 case GNU_PROPERTY_X86_ISA_1_V2
:
18924 printf ("x86-64-v2");
18926 case GNU_PROPERTY_X86_ISA_1_V3
:
18927 printf ("x86-64-v3");
18929 case GNU_PROPERTY_X86_ISA_1_V4
:
18930 printf ("x86-64-v4");
18933 printf (_("<unknown: %x>"), bit
);
18942 decode_x86_feature_1 (unsigned int bitmask
)
18946 printf (_("<None>"));
18952 unsigned int bit
= bitmask
& (- bitmask
);
18957 case GNU_PROPERTY_X86_FEATURE_1_IBT
:
18960 case GNU_PROPERTY_X86_FEATURE_1_SHSTK
:
18963 case GNU_PROPERTY_X86_FEATURE_1_LAM_U48
:
18964 printf ("LAM_U48");
18966 case GNU_PROPERTY_X86_FEATURE_1_LAM_U57
:
18967 printf ("LAM_U57");
18970 printf (_("<unknown: %x>"), bit
);
18979 decode_x86_feature_2 (unsigned int bitmask
)
18983 printf (_("<None>"));
18989 unsigned int bit
= bitmask
& (- bitmask
);
18994 case GNU_PROPERTY_X86_FEATURE_2_X86
:
18997 case GNU_PROPERTY_X86_FEATURE_2_X87
:
19000 case GNU_PROPERTY_X86_FEATURE_2_MMX
:
19003 case GNU_PROPERTY_X86_FEATURE_2_XMM
:
19006 case GNU_PROPERTY_X86_FEATURE_2_YMM
:
19009 case GNU_PROPERTY_X86_FEATURE_2_ZMM
:
19012 case GNU_PROPERTY_X86_FEATURE_2_TMM
:
19015 case GNU_PROPERTY_X86_FEATURE_2_MASK
:
19018 case GNU_PROPERTY_X86_FEATURE_2_FXSR
:
19021 case GNU_PROPERTY_X86_FEATURE_2_XSAVE
:
19024 case GNU_PROPERTY_X86_FEATURE_2_XSAVEOPT
:
19025 printf ("XSAVEOPT");
19027 case GNU_PROPERTY_X86_FEATURE_2_XSAVEC
:
19031 printf (_("<unknown: %x>"), bit
);
19040 decode_aarch64_feature_1_and (unsigned int bitmask
)
19044 unsigned int bit
= bitmask
& (- bitmask
);
19049 case GNU_PROPERTY_AARCH64_FEATURE_1_BTI
:
19053 case GNU_PROPERTY_AARCH64_FEATURE_1_PAC
:
19058 printf (_("<unknown: %x>"), bit
);
19067 print_gnu_property_note (Filedata
* filedata
, Elf_Internal_Note
* pnote
)
19069 unsigned char * ptr
= (unsigned char *) pnote
->descdata
;
19070 unsigned char * ptr_end
= ptr
+ pnote
->descsz
;
19071 unsigned int size
= is_32bit_elf
? 4 : 8;
19073 printf (_(" Properties: "));
19075 if (pnote
->descsz
< 8 || (pnote
->descsz
% size
) != 0)
19077 printf (_("<corrupt GNU_PROPERTY_TYPE, size = %#lx>\n"), pnote
->descsz
);
19081 while (ptr
< ptr_end
)
19085 unsigned int datasz
;
19087 if ((size_t) (ptr_end
- ptr
) < 8)
19089 printf (_("<corrupt descsz: %#lx>\n"), pnote
->descsz
);
19093 type
= byte_get (ptr
, 4);
19094 datasz
= byte_get (ptr
+ 4, 4);
19098 if (datasz
> (size_t) (ptr_end
- ptr
))
19100 printf (_("<corrupt type (%#x) datasz: %#x>\n"),
19105 if (type
>= GNU_PROPERTY_LOPROC
&& type
<= GNU_PROPERTY_HIPROC
)
19107 if (filedata
->file_header
.e_machine
== EM_X86_64
19108 || filedata
->file_header
.e_machine
== EM_IAMCU
19109 || filedata
->file_header
.e_machine
== EM_386
)
19111 unsigned int bitmask
;
19114 bitmask
= byte_get (ptr
, 4);
19120 case GNU_PROPERTY_X86_ISA_1_USED
:
19122 printf (_("x86 ISA used: <corrupt length: %#x> "),
19126 printf ("x86 ISA used: ");
19127 decode_x86_isa (bitmask
);
19131 case GNU_PROPERTY_X86_ISA_1_NEEDED
:
19133 printf (_("x86 ISA needed: <corrupt length: %#x> "),
19137 printf ("x86 ISA needed: ");
19138 decode_x86_isa (bitmask
);
19142 case GNU_PROPERTY_X86_FEATURE_1_AND
:
19144 printf (_("x86 feature: <corrupt length: %#x> "),
19148 printf ("x86 feature: ");
19149 decode_x86_feature_1 (bitmask
);
19153 case GNU_PROPERTY_X86_FEATURE_2_USED
:
19155 printf (_("x86 feature used: <corrupt length: %#x> "),
19159 printf ("x86 feature used: ");
19160 decode_x86_feature_2 (bitmask
);
19164 case GNU_PROPERTY_X86_FEATURE_2_NEEDED
:
19166 printf (_("x86 feature needed: <corrupt length: %#x> "), datasz
);
19169 printf ("x86 feature needed: ");
19170 decode_x86_feature_2 (bitmask
);
19174 case GNU_PROPERTY_X86_COMPAT_ISA_1_USED
:
19176 printf (_("x86 ISA used: <corrupt length: %#x> "),
19180 printf ("x86 ISA used: ");
19181 decode_x86_compat_isa (bitmask
);
19185 case GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED
:
19187 printf (_("x86 ISA needed: <corrupt length: %#x> "),
19191 printf ("x86 ISA needed: ");
19192 decode_x86_compat_isa (bitmask
);
19196 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_USED
:
19198 printf (_("x86 ISA used: <corrupt length: %#x> "),
19202 printf ("x86 ISA used: ");
19203 decode_x86_compat_2_isa (bitmask
);
19207 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_NEEDED
:
19209 printf (_("x86 ISA needed: <corrupt length: %#x> "),
19213 printf ("x86 ISA needed: ");
19214 decode_x86_compat_2_isa (bitmask
);
19222 else if (filedata
->file_header
.e_machine
== EM_AARCH64
)
19224 if (type
== GNU_PROPERTY_AARCH64_FEATURE_1_AND
)
19226 printf ("AArch64 feature: ");
19228 printf (_("<corrupt length: %#x> "), datasz
);
19230 decode_aarch64_feature_1_and (byte_get (ptr
, 4));
19239 case GNU_PROPERTY_STACK_SIZE
:
19240 printf (_("stack size: "));
19241 if (datasz
!= size
)
19242 printf (_("<corrupt length: %#x> "), datasz
);
19244 printf ("%#lx", (unsigned long) byte_get (ptr
, size
));
19247 case GNU_PROPERTY_NO_COPY_ON_PROTECTED
:
19248 printf ("no copy on protected ");
19250 printf (_("<corrupt length: %#x> "), datasz
);
19258 if (type
< GNU_PROPERTY_LOPROC
)
19259 printf (_("<unknown type %#x data: "), type
);
19260 else if (type
< GNU_PROPERTY_LOUSER
)
19261 printf (_("<processor-specific type %#x data: "), type
);
19263 printf (_("<application-specific type %#x data: "), type
);
19264 for (j
= 0; j
< datasz
; ++j
)
19265 printf ("%02x ", ptr
[j
] & 0xff);
19269 ptr
+= ((datasz
+ (size
- 1)) & ~ (size
- 1));
19270 if (ptr
== ptr_end
)
19283 print_gnu_note (Filedata
* filedata
, Elf_Internal_Note
*pnote
)
19285 /* NB/ Keep this switch statement in sync with get_gnu_elf_note_type (). */
19286 switch (pnote
->type
)
19288 case NT_GNU_BUILD_ID
:
19292 printf (_(" Build ID: "));
19293 for (i
= 0; i
< pnote
->descsz
; ++i
)
19294 printf ("%02x", pnote
->descdata
[i
] & 0xff);
19299 case NT_GNU_ABI_TAG
:
19301 unsigned long os
, major
, minor
, subminor
;
19302 const char *osname
;
19304 /* PR 17531: file: 030-599401-0.004. */
19305 if (pnote
->descsz
< 16)
19307 printf (_(" <corrupt GNU_ABI_TAG>\n"));
19311 os
= byte_get ((unsigned char *) pnote
->descdata
, 4);
19312 major
= byte_get ((unsigned char *) pnote
->descdata
+ 4, 4);
19313 minor
= byte_get ((unsigned char *) pnote
->descdata
+ 8, 4);
19314 subminor
= byte_get ((unsigned char *) pnote
->descdata
+ 12, 4);
19318 case GNU_ABI_TAG_LINUX
:
19321 case GNU_ABI_TAG_HURD
:
19324 case GNU_ABI_TAG_SOLARIS
:
19325 osname
= "Solaris";
19327 case GNU_ABI_TAG_FREEBSD
:
19328 osname
= "FreeBSD";
19330 case GNU_ABI_TAG_NETBSD
:
19333 case GNU_ABI_TAG_SYLLABLE
:
19334 osname
= "Syllable";
19336 case GNU_ABI_TAG_NACL
:
19340 osname
= "Unknown";
19344 printf (_(" OS: %s, ABI: %ld.%ld.%ld\n"), osname
,
19345 major
, minor
, subminor
);
19349 case NT_GNU_GOLD_VERSION
:
19353 printf (_(" Version: "));
19354 for (i
= 0; i
< pnote
->descsz
&& pnote
->descdata
[i
] != '\0'; ++i
)
19355 printf ("%c", pnote
->descdata
[i
]);
19362 unsigned long num_entries
, mask
;
19364 /* Hardware capabilities information. Word 0 is the number of entries.
19365 Word 1 is a bitmask of enabled entries. The rest of the descriptor
19366 is a series of entries, where each entry is a single byte followed
19367 by a nul terminated string. The byte gives the bit number to test
19368 if enabled in the bitmask. */
19369 printf (_(" Hardware Capabilities: "));
19370 if (pnote
->descsz
< 8)
19372 error (_("<corrupt GNU_HWCAP>\n"));
19375 num_entries
= byte_get ((unsigned char *) pnote
->descdata
, 4);
19376 mask
= byte_get ((unsigned char *) pnote
->descdata
+ 4, 4);
19377 printf (_("num entries: %ld, enabled mask: %lx\n"), num_entries
, mask
);
19378 /* FIXME: Add code to display the entries... */
19382 case NT_GNU_PROPERTY_TYPE_0
:
19383 print_gnu_property_note (filedata
, pnote
);
19387 /* Handle unrecognised types. An error message should have already been
19388 created by get_gnu_elf_note_type(), so all that we need to do is to
19389 display the data. */
19393 printf (_(" Description data: "));
19394 for (i
= 0; i
< pnote
->descsz
; ++i
)
19395 printf ("%02x ", pnote
->descdata
[i
] & 0xff);
19404 static const char *
19405 get_v850_elf_note_type (enum v850_notes n_type
)
19407 static char buff
[64];
19411 case V850_NOTE_ALIGNMENT
: return _("Alignment of 8-byte objects");
19412 case V850_NOTE_DATA_SIZE
: return _("Sizeof double and long double");
19413 case V850_NOTE_FPU_INFO
: return _("Type of FPU support needed");
19414 case V850_NOTE_SIMD_INFO
: return _("Use of SIMD instructions");
19415 case V850_NOTE_CACHE_INFO
: return _("Use of cache");
19416 case V850_NOTE_MMU_INFO
: return _("Use of MMU");
19418 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), n_type
);
19424 print_v850_note (Elf_Internal_Note
* pnote
)
19428 if (pnote
->descsz
!= 4)
19431 val
= byte_get ((unsigned char *) pnote
->descdata
, pnote
->descsz
);
19435 printf (_("not set\n"));
19439 switch (pnote
->type
)
19441 case V850_NOTE_ALIGNMENT
:
19444 case EF_RH850_DATA_ALIGN4
: printf (_("4-byte\n")); return TRUE
;
19445 case EF_RH850_DATA_ALIGN8
: printf (_("8-byte\n")); return TRUE
;
19449 case V850_NOTE_DATA_SIZE
:
19452 case EF_RH850_DOUBLE32
: printf (_("4-bytes\n")); return TRUE
;
19453 case EF_RH850_DOUBLE64
: printf (_("8-bytes\n")); return TRUE
;
19457 case V850_NOTE_FPU_INFO
:
19460 case EF_RH850_FPU20
: printf (_("FPU-2.0\n")); return TRUE
;
19461 case EF_RH850_FPU30
: printf (_("FPU-3.0\n")); return TRUE
;
19465 case V850_NOTE_MMU_INFO
:
19466 case V850_NOTE_CACHE_INFO
:
19467 case V850_NOTE_SIMD_INFO
:
19468 if (val
== EF_RH850_SIMD
)
19470 printf (_("yes\n"));
19476 /* An 'unknown note type' message will already have been displayed. */
19480 printf (_("unknown value: %x\n"), val
);
19485 process_netbsd_elf_note (Elf_Internal_Note
* pnote
)
19487 unsigned int version
;
19489 switch (pnote
->type
)
19491 case NT_NETBSD_IDENT
:
19492 if (pnote
->descsz
< 1)
19494 version
= byte_get ((unsigned char *) pnote
->descdata
, sizeof (version
));
19495 if ((version
/ 10000) % 100)
19496 printf (" NetBSD\t\t0x%08lx\tIDENT %u (%u.%u%s%c)\n", pnote
->descsz
,
19497 version
, version
/ 100000000, (version
/ 1000000) % 100,
19498 (version
/ 10000) % 100 > 26 ? "Z" : "",
19499 'A' + (version
/ 10000) % 26);
19501 printf (" NetBSD\t\t0x%08lx\tIDENT %u (%u.%u.%u)\n", pnote
->descsz
,
19502 version
, version
/ 100000000, (version
/ 1000000) % 100,
19503 (version
/ 100) % 100);
19506 case NT_NETBSD_MARCH
:
19507 printf (" NetBSD\t\t0x%08lx\tMARCH <%s>\n", pnote
->descsz
,
19511 #ifdef NT_NETBSD_PAX
19512 case NT_NETBSD_PAX
:
19513 if (pnote
->descsz
< 1)
19515 version
= byte_get ((unsigned char *) pnote
->descdata
, sizeof (version
));
19516 printf (" NetBSD\t\t0x%08lx\tPaX <%s%s%s%s%s%s>\n", pnote
->descsz
,
19517 ((version
& NT_NETBSD_PAX_MPROTECT
) ? "+mprotect" : ""),
19518 ((version
& NT_NETBSD_PAX_NOMPROTECT
) ? "-mprotect" : ""),
19519 ((version
& NT_NETBSD_PAX_GUARD
) ? "+guard" : ""),
19520 ((version
& NT_NETBSD_PAX_NOGUARD
) ? "-guard" : ""),
19521 ((version
& NT_NETBSD_PAX_ASLR
) ? "+ASLR" : ""),
19522 ((version
& NT_NETBSD_PAX_NOASLR
) ? "-ASLR" : ""));
19527 printf (" NetBSD\t0x%08lx\tUnknown note type: (0x%08lx)\n",
19528 pnote
->descsz
, pnote
->type
);
19532 static const char *
19533 get_freebsd_elfcore_note_type (Filedata
* filedata
, unsigned e_type
)
19537 case NT_FREEBSD_THRMISC
:
19538 return _("NT_THRMISC (thrmisc structure)");
19539 case NT_FREEBSD_PROCSTAT_PROC
:
19540 return _("NT_PROCSTAT_PROC (proc data)");
19541 case NT_FREEBSD_PROCSTAT_FILES
:
19542 return _("NT_PROCSTAT_FILES (files data)");
19543 case NT_FREEBSD_PROCSTAT_VMMAP
:
19544 return _("NT_PROCSTAT_VMMAP (vmmap data)");
19545 case NT_FREEBSD_PROCSTAT_GROUPS
:
19546 return _("NT_PROCSTAT_GROUPS (groups data)");
19547 case NT_FREEBSD_PROCSTAT_UMASK
:
19548 return _("NT_PROCSTAT_UMASK (umask data)");
19549 case NT_FREEBSD_PROCSTAT_RLIMIT
:
19550 return _("NT_PROCSTAT_RLIMIT (rlimit data)");
19551 case NT_FREEBSD_PROCSTAT_OSREL
:
19552 return _("NT_PROCSTAT_OSREL (osreldate data)");
19553 case NT_FREEBSD_PROCSTAT_PSSTRINGS
:
19554 return _("NT_PROCSTAT_PSSTRINGS (ps_strings data)");
19555 case NT_FREEBSD_PROCSTAT_AUXV
:
19556 return _("NT_PROCSTAT_AUXV (auxv data)");
19557 case NT_FREEBSD_PTLWPINFO
:
19558 return _("NT_PTLWPINFO (ptrace_lwpinfo structure)");
19560 return get_note_type (filedata
, e_type
);
19563 static const char *
19564 get_netbsd_elfcore_note_type (Filedata
* filedata
, unsigned e_type
)
19566 static char buff
[64];
19570 case NT_NETBSDCORE_PROCINFO
:
19571 /* NetBSD core "procinfo" structure. */
19572 return _("NetBSD procinfo structure");
19574 #ifdef NT_NETBSDCORE_AUXV
19575 case NT_NETBSDCORE_AUXV
:
19576 return _("NetBSD ELF auxiliary vector data");
19579 #ifdef NT_NETBSDCORE_LWPSTATUS
19580 case NT_NETBSDCORE_LWPSTATUS
:
19581 return _("PT_LWPSTATUS (ptrace_lwpstatus structure)");
19585 /* As of Jan 2020 there are no other machine-independent notes
19586 defined for NetBSD core files. If the note type is less
19587 than the start of the machine-dependent note types, we don't
19590 if (e_type
< NT_NETBSDCORE_FIRSTMACH
)
19592 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
19598 switch (filedata
->file_header
.e_machine
)
19600 /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0
19601 and PT_GETFPREGS == mach+2. */
19606 case EM_SPARC32PLUS
:
19610 case NT_NETBSDCORE_FIRSTMACH
+ 0:
19611 return _("PT_GETREGS (reg structure)");
19612 case NT_NETBSDCORE_FIRSTMACH
+ 2:
19613 return _("PT_GETFPREGS (fpreg structure)");
19619 /* On SuperH, PT_GETREGS == mach+3 and PT_GETFPREGS == mach+5.
19620 There's also old PT___GETREGS40 == mach + 1 for old reg
19621 structure which lacks GBR. */
19625 case NT_NETBSDCORE_FIRSTMACH
+ 1:
19626 return _("PT___GETREGS40 (old reg structure)");
19627 case NT_NETBSDCORE_FIRSTMACH
+ 3:
19628 return _("PT_GETREGS (reg structure)");
19629 case NT_NETBSDCORE_FIRSTMACH
+ 5:
19630 return _("PT_GETFPREGS (fpreg structure)");
19636 /* On all other arch's, PT_GETREGS == mach+1 and
19637 PT_GETFPREGS == mach+3. */
19641 case NT_NETBSDCORE_FIRSTMACH
+ 1:
19642 return _("PT_GETREGS (reg structure)");
19643 case NT_NETBSDCORE_FIRSTMACH
+ 3:
19644 return _("PT_GETFPREGS (fpreg structure)");
19650 snprintf (buff
, sizeof (buff
), "PT_FIRSTMACH+%d",
19651 e_type
- NT_NETBSDCORE_FIRSTMACH
);
19655 static const char *
19656 get_stapsdt_note_type (unsigned e_type
)
19658 static char buff
[64];
19663 return _("NT_STAPSDT (SystemTap probe descriptors)");
19669 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
19674 print_stapsdt_note (Elf_Internal_Note
*pnote
)
19676 size_t len
, maxlen
;
19677 unsigned long addr_size
= is_32bit_elf
? 4 : 8;
19678 char *data
= pnote
->descdata
;
19679 char *data_end
= pnote
->descdata
+ pnote
->descsz
;
19680 bfd_vma pc
, base_addr
, semaphore
;
19681 char *provider
, *probe
, *arg_fmt
;
19683 if (pnote
->descsz
< (addr_size
* 3))
19684 goto stapdt_note_too_small
;
19686 pc
= byte_get ((unsigned char *) data
, addr_size
);
19689 base_addr
= byte_get ((unsigned char *) data
, addr_size
);
19692 semaphore
= byte_get ((unsigned char *) data
, addr_size
);
19695 if (data
>= data_end
)
19696 goto stapdt_note_too_small
;
19697 maxlen
= data_end
- data
;
19698 len
= strnlen (data
, maxlen
);
19705 goto stapdt_note_too_small
;
19707 if (data
>= data_end
)
19708 goto stapdt_note_too_small
;
19709 maxlen
= data_end
- data
;
19710 len
= strnlen (data
, maxlen
);
19717 goto stapdt_note_too_small
;
19719 if (data
>= data_end
)
19720 goto stapdt_note_too_small
;
19721 maxlen
= data_end
- data
;
19722 len
= strnlen (data
, maxlen
);
19729 goto stapdt_note_too_small
;
19731 printf (_(" Provider: %s\n"), provider
);
19732 printf (_(" Name: %s\n"), probe
);
19733 printf (_(" Location: "));
19734 print_vma (pc
, FULL_HEX
);
19735 printf (_(", Base: "));
19736 print_vma (base_addr
, FULL_HEX
);
19737 printf (_(", Semaphore: "));
19738 print_vma (semaphore
, FULL_HEX
);
19740 printf (_(" Arguments: %s\n"), arg_fmt
);
19742 return data
== data_end
;
19744 stapdt_note_too_small
:
19745 printf (_(" <corrupt - note is too small>\n"));
19746 error (_("corrupt stapdt note - the data size is too small\n"));
19750 static const char *
19751 get_ia64_vms_note_type (unsigned e_type
)
19753 static char buff
[64];
19758 return _("NT_VMS_MHD (module header)");
19760 return _("NT_VMS_LNM (language name)");
19762 return _("NT_VMS_SRC (source files)");
19764 return "NT_VMS_TITLE";
19766 return _("NT_VMS_EIDC (consistency check)");
19767 case NT_VMS_FPMODE
:
19768 return _("NT_VMS_FPMODE (FP mode)");
19769 case NT_VMS_LINKTIME
:
19770 return "NT_VMS_LINKTIME";
19771 case NT_VMS_IMGNAM
:
19772 return _("NT_VMS_IMGNAM (image name)");
19774 return _("NT_VMS_IMGID (image id)");
19775 case NT_VMS_LINKID
:
19776 return _("NT_VMS_LINKID (link id)");
19777 case NT_VMS_IMGBID
:
19778 return _("NT_VMS_IMGBID (build id)");
19779 case NT_VMS_GSTNAM
:
19780 return _("NT_VMS_GSTNAM (sym table name)");
19781 case NT_VMS_ORIG_DYN
:
19782 return "NT_VMS_ORIG_DYN";
19783 case NT_VMS_PATCHTIME
:
19784 return "NT_VMS_PATCHTIME";
19786 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
19792 print_ia64_vms_note (Elf_Internal_Note
* pnote
)
19794 int maxlen
= pnote
->descsz
;
19796 if (maxlen
< 2 || (unsigned long) maxlen
!= pnote
->descsz
)
19797 goto desc_size_fail
;
19799 switch (pnote
->type
)
19803 goto desc_size_fail
;
19805 int l
= (int) strnlen (pnote
->descdata
+ 34, maxlen
- 34);
19807 printf (_(" Creation date : %.17s\n"), pnote
->descdata
);
19808 printf (_(" Last patch date: %.17s\n"), pnote
->descdata
+ 17);
19809 if (l
+ 34 < maxlen
)
19811 printf (_(" Module name : %s\n"), pnote
->descdata
+ 34);
19812 if (l
+ 35 < maxlen
)
19813 printf (_(" Module version : %s\n"), pnote
->descdata
+ 34 + l
+ 1);
19815 printf (_(" Module version : <missing>\n"));
19819 printf (_(" Module name : <missing>\n"));
19820 printf (_(" Module version : <missing>\n"));
19825 printf (_(" Language: %.*s\n"), maxlen
, pnote
->descdata
);
19829 case NT_VMS_FPMODE
:
19830 printf (_(" Floating Point mode: "));
19832 goto desc_size_fail
;
19833 /* FIXME: Generate an error if descsz > 8 ? */
19835 printf ("0x%016" BFD_VMA_FMT
"x\n",
19836 (bfd_vma
) byte_get ((unsigned char *)pnote
->descdata
, 8));
19839 case NT_VMS_LINKTIME
:
19840 printf (_(" Link time: "));
19842 goto desc_size_fail
;
19843 /* FIXME: Generate an error if descsz > 8 ? */
19846 ((bfd_int64_t
) byte_get ((unsigned char *)pnote
->descdata
, 8));
19850 case NT_VMS_PATCHTIME
:
19851 printf (_(" Patch time: "));
19853 goto desc_size_fail
;
19854 /* FIXME: Generate an error if descsz > 8 ? */
19857 ((bfd_int64_t
) byte_get ((unsigned char *)pnote
->descdata
, 8));
19861 case NT_VMS_ORIG_DYN
:
19863 goto desc_size_fail
;
19865 printf (_(" Major id: %u, minor id: %u\n"),
19866 (unsigned) byte_get ((unsigned char *)pnote
->descdata
, 4),
19867 (unsigned) byte_get ((unsigned char *)pnote
->descdata
+ 4, 4));
19868 printf (_(" Last modified : "));
19870 ((bfd_int64_t
) byte_get ((unsigned char *)pnote
->descdata
+ 8, 8));
19871 printf (_("\n Link flags : "));
19872 printf ("0x%016" BFD_VMA_FMT
"x\n",
19873 (bfd_vma
) byte_get ((unsigned char *)pnote
->descdata
+ 16, 8));
19874 printf (_(" Header flags: 0x%08x\n"),
19875 (unsigned) byte_get ((unsigned char *)pnote
->descdata
+ 24, 4));
19876 printf (_(" Image id : %.*s\n"), maxlen
- 32, pnote
->descdata
+ 32);
19880 case NT_VMS_IMGNAM
:
19881 printf (_(" Image name: %.*s\n"), maxlen
, pnote
->descdata
);
19884 case NT_VMS_GSTNAM
:
19885 printf (_(" Global symbol table name: %.*s\n"), maxlen
, pnote
->descdata
);
19889 printf (_(" Image id: %.*s\n"), maxlen
, pnote
->descdata
);
19892 case NT_VMS_LINKID
:
19893 printf (_(" Linker id: %.*s\n"), maxlen
, pnote
->descdata
);
19903 printf (_(" <corrupt - data size is too small>\n"));
19904 error (_("corrupt IA64 note: data size is too small\n"));
19908 struct build_attr_cache
{
19909 Filedata
*filedata
;
19911 unsigned long strtablen
;
19912 Elf_Internal_Sym
*symtab
;
19913 unsigned long nsyms
;
19916 /* Find the symbol associated with a build attribute that is attached
19917 to address OFFSET. If PNAME is non-NULL then store the name of
19918 the symbol (if found) in the provided pointer, Returns NULL if a
19919 symbol could not be found. */
19921 static Elf_Internal_Sym
*
19922 get_symbol_for_build_attribute (Filedata
* filedata
,
19923 unsigned long offset
,
19924 bfd_boolean is_open_attr
,
19925 const char ** pname
)
19927 Elf_Internal_Sym
*saved_sym
= NULL
;
19928 Elf_Internal_Sym
*sym
;
19930 if (filedata
->section_headers
!= NULL
19931 && (ba_cache
.filedata
== NULL
|| filedata
!= ba_cache
.filedata
))
19933 Elf_Internal_Shdr
* symsec
;
19935 free (ba_cache
.strtab
);
19936 ba_cache
.strtab
= NULL
;
19937 free (ba_cache
.symtab
);
19938 ba_cache
.symtab
= NULL
;
19940 /* Load the symbol and string sections. */
19941 for (symsec
= filedata
->section_headers
;
19942 symsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
19945 if (symsec
->sh_type
== SHT_SYMTAB
19946 && get_symtab (filedata
, symsec
,
19947 &ba_cache
.symtab
, &ba_cache
.nsyms
,
19948 &ba_cache
.strtab
, &ba_cache
.strtablen
))
19951 ba_cache
.filedata
= filedata
;
19954 if (ba_cache
.symtab
== NULL
)
19957 /* Find a symbol whose value matches offset. */
19958 for (sym
= ba_cache
.symtab
; sym
< ba_cache
.symtab
+ ba_cache
.nsyms
; sym
++)
19959 if (sym
->st_value
== offset
)
19961 if (sym
->st_name
>= ba_cache
.strtablen
)
19962 /* Huh ? This should not happen. */
19965 if (ba_cache
.strtab
[sym
->st_name
] == 0)
19968 /* The AArch64 and ARM architectures define mapping symbols
19969 (eg $d, $x, $t) which we want to ignore. */
19970 if (ba_cache
.strtab
[sym
->st_name
] == '$'
19971 && ba_cache
.strtab
[sym
->st_name
+ 1] != 0
19972 && ba_cache
.strtab
[sym
->st_name
+ 2] == 0)
19977 /* For OPEN attributes we prefer GLOBAL over LOCAL symbols
19978 and FILE or OBJECT symbols over NOTYPE symbols. We skip
19979 FUNC symbols entirely. */
19980 switch (ELF_ST_TYPE (sym
->st_info
))
19987 /* If the symbol has a size associated
19988 with it then we can stop searching. */
19989 sym
= ba_cache
.symtab
+ ba_cache
.nsyms
;
19994 /* Ignore function symbols. */
20001 switch (ELF_ST_BIND (sym
->st_info
))
20004 if (saved_sym
== NULL
20005 || ELF_ST_TYPE (saved_sym
->st_info
) != STT_OBJECT
)
20010 if (saved_sym
== NULL
)
20020 if (ELF_ST_TYPE (sym
->st_info
) != STT_FUNC
)
20028 if (saved_sym
&& pname
)
20029 * pname
= ba_cache
.strtab
+ saved_sym
->st_name
;
20034 /* Returns true iff addr1 and addr2 are in the same section. */
20037 same_section (Filedata
* filedata
, unsigned long addr1
, unsigned long addr2
)
20039 Elf_Internal_Shdr
* a1
;
20040 Elf_Internal_Shdr
* a2
;
20042 a1
= find_section_by_address (filedata
, addr1
);
20043 a2
= find_section_by_address (filedata
, addr2
);
20045 return a1
== a2
&& a1
!= NULL
;
20049 print_gnu_build_attribute_description (Elf_Internal_Note
* pnote
,
20050 Filedata
* filedata
)
20052 static unsigned long global_offset
= 0;
20053 static unsigned long global_end
= 0;
20054 static unsigned long func_offset
= 0;
20055 static unsigned long func_end
= 0;
20057 Elf_Internal_Sym
* sym
;
20059 unsigned long start
;
20061 bfd_boolean is_open_attr
= pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_OPEN
;
20063 switch (pnote
->descsz
)
20066 /* A zero-length description means that the range of
20067 the previous note of the same type should be used. */
20070 if (global_end
> global_offset
)
20071 printf (_(" Applies to region from %#lx to %#lx\n"),
20072 global_offset
, global_end
);
20074 printf (_(" Applies to region from %#lx\n"), global_offset
);
20078 if (func_end
> func_offset
)
20079 printf (_(" Applies to region from %#lx to %#lx\n"), func_offset
, func_end
);
20081 printf (_(" Applies to region from %#lx\n"), func_offset
);
20086 start
= byte_get ((unsigned char *) pnote
->descdata
, 4);
20091 start
= byte_get ((unsigned char *) pnote
->descdata
, 4);
20092 end
= byte_get ((unsigned char *) pnote
->descdata
+ 4, 4);
20096 start
= byte_get ((unsigned char *) pnote
->descdata
, 8);
20097 end
= byte_get ((unsigned char *) pnote
->descdata
+ 8, 8);
20101 error (_(" <invalid description size: %lx>\n"), pnote
->descsz
);
20102 printf (_(" <invalid descsz>"));
20107 sym
= get_symbol_for_build_attribute (filedata
, start
, is_open_attr
, & name
);
20108 /* As of version 5 of the annobin plugin, filename symbols are biased by 2
20109 in order to avoid them being confused with the start address of the
20110 first function in the file... */
20111 if (sym
== NULL
&& is_open_attr
)
20112 sym
= get_symbol_for_build_attribute (filedata
, start
+ 2, is_open_attr
,
20115 if (end
== 0 && sym
!= NULL
&& sym
->st_size
> 0)
20116 end
= start
+ sym
->st_size
;
20120 /* FIXME: Need to properly allow for section alignment.
20121 16 is just the alignment used on x86_64. */
20123 && start
> BFD_ALIGN (global_end
, 16)
20124 /* Build notes are not guaranteed to be organised in order of
20125 increasing address, but we should find the all of the notes
20126 for one section in the same place. */
20127 && same_section (filedata
, start
, global_end
))
20128 warn (_("Gap in build notes detected from %#lx to %#lx\n"),
20129 global_end
+ 1, start
- 1);
20131 printf (_(" Applies to region from %#lx"), start
);
20132 global_offset
= start
;
20136 printf (_(" to %#lx"), end
);
20142 printf (_(" Applies to region from %#lx"), start
);
20143 func_offset
= start
;
20147 printf (_(" to %#lx"), end
);
20153 printf (_(" (%s)"), name
);
20160 print_gnu_build_attribute_name (Elf_Internal_Note
* pnote
)
20162 static const char string_expected
[2] = { GNU_BUILD_ATTRIBUTE_TYPE_STRING
, 0 };
20163 static const char number_expected
[2] = { GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC
, 0 };
20164 static const char bool_expected
[3] = { GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE
, GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE
, 0 };
20166 char name_attribute
;
20167 const char * expected_types
;
20168 const char * name
= pnote
->namedata
;
20172 if (name
== NULL
|| pnote
->namesz
< 2)
20174 error (_("corrupt name field in GNU build attribute note: size = %ld\n"), pnote
->namesz
);
20175 print_symbol (-20, _(" <corrupt name>"));
20184 /* Version 2 of the spec adds a "GA" prefix to the name field. */
20185 if (name
[0] == 'G' && name
[1] == 'A')
20187 if (pnote
->namesz
< 4)
20189 error (_("corrupt name field in GNU build attribute note: size = %ld\n"), pnote
->namesz
);
20190 print_symbol (-20, _(" <corrupt name>"));
20199 switch ((name_type
= * name
))
20201 case GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC
:
20202 case GNU_BUILD_ATTRIBUTE_TYPE_STRING
:
20203 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE
:
20204 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE
:
20205 printf ("%c", * name
);
20209 error (_("unrecognised attribute type in name field: %d\n"), name_type
);
20210 print_symbol (-20, _("<unknown name type>"));
20217 switch ((name_attribute
= * name
))
20219 case GNU_BUILD_ATTRIBUTE_VERSION
:
20220 text
= _("<version>");
20221 expected_types
= string_expected
;
20224 case GNU_BUILD_ATTRIBUTE_STACK_PROT
:
20225 text
= _("<stack prot>");
20226 expected_types
= "!+*";
20229 case GNU_BUILD_ATTRIBUTE_RELRO
:
20230 text
= _("<relro>");
20231 expected_types
= bool_expected
;
20234 case GNU_BUILD_ATTRIBUTE_STACK_SIZE
:
20235 text
= _("<stack size>");
20236 expected_types
= number_expected
;
20239 case GNU_BUILD_ATTRIBUTE_TOOL
:
20240 text
= _("<tool>");
20241 expected_types
= string_expected
;
20244 case GNU_BUILD_ATTRIBUTE_ABI
:
20246 expected_types
= "$*";
20249 case GNU_BUILD_ATTRIBUTE_PIC
:
20251 expected_types
= number_expected
;
20254 case GNU_BUILD_ATTRIBUTE_SHORT_ENUM
:
20255 text
= _("<short enum>");
20256 expected_types
= bool_expected
;
20260 if (ISPRINT (* name
))
20262 int len
= strnlen (name
, pnote
->namesz
- (name
- pnote
->namedata
)) + 1;
20264 if (len
> left
&& ! do_wide
)
20266 printf ("%.*s:", len
, name
);
20272 static char tmpbuf
[128];
20274 error (_("unrecognised byte in name field: %d\n"), * name
);
20275 sprintf (tmpbuf
, _("<unknown:_%d>"), * name
);
20279 expected_types
= "*$!+";
20284 left
-= printf ("%s", text
);
20286 if (strchr (expected_types
, name_type
) == NULL
)
20287 warn (_("attribute does not have an expected type (%c)\n"), name_type
);
20289 if ((unsigned long)(name
- pnote
->namedata
) > pnote
->namesz
)
20291 error (_("corrupt name field: namesz: %lu but parsing gets to %ld\n"),
20292 (unsigned long) pnote
->namesz
,
20293 (long) (name
- pnote
->namedata
));
20297 if (left
< 1 && ! do_wide
)
20302 case GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC
:
20304 unsigned int bytes
;
20305 unsigned long long val
= 0;
20306 unsigned int shift
= 0;
20307 char * decoded
= NULL
;
20309 bytes
= pnote
->namesz
- (name
- pnote
->namedata
);
20311 /* The -1 is because the name field is always 0 terminated, and we
20312 want to be able to ensure that the shift in the while loop below
20313 will not overflow. */
20316 if (bytes
> sizeof (val
))
20318 error (_("corrupt numeric name field: too many bytes in the value: %x\n"),
20320 bytes
= sizeof (val
);
20322 /* We do not bother to warn if bytes == 0 as this can
20323 happen with some early versions of the gcc plugin. */
20327 unsigned long long byte
= *name
++ & 0xff;
20329 val
|= byte
<< shift
;
20333 switch (name_attribute
)
20335 case GNU_BUILD_ATTRIBUTE_PIC
:
20338 case 0: decoded
= "static"; break;
20339 case 1: decoded
= "pic"; break;
20340 case 2: decoded
= "PIC"; break;
20341 case 3: decoded
= "pie"; break;
20342 case 4: decoded
= "PIE"; break;
20346 case GNU_BUILD_ATTRIBUTE_STACK_PROT
:
20349 /* Based upon the SPCT_FLAG_xxx enum values in gcc/cfgexpand.c. */
20350 case 0: decoded
= "off"; break;
20351 case 1: decoded
= "on"; break;
20352 case 2: decoded
= "all"; break;
20353 case 3: decoded
= "strong"; break;
20354 case 4: decoded
= "explicit"; break;
20362 if (decoded
!= NULL
)
20364 print_symbol (-left
, decoded
);
20375 left
-= printf ("0x%llx", val
);
20377 left
-= printf ("0x%-.*llx", left
, val
);
20381 case GNU_BUILD_ATTRIBUTE_TYPE_STRING
:
20382 left
-= print_symbol (- left
, name
);
20384 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE
:
20385 left
-= print_symbol (- left
, "true");
20387 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE
:
20388 left
-= print_symbol (- left
, "false");
20392 if (do_wide
&& left
> 0)
20393 printf ("%-*s", left
, " ");
20398 /* Note that by the ELF standard, the name field is already null byte
20399 terminated, and namesz includes the terminating null byte.
20400 I.E. the value of namesz for the name "FSF" is 4.
20402 If the value of namesz is zero, there is no name present. */
20405 process_note (Elf_Internal_Note
* pnote
,
20406 Filedata
* filedata
)
20408 const char * name
= pnote
->namesz
? pnote
->namedata
: "(NONE)";
20411 if (pnote
->namesz
== 0)
20412 /* If there is no note name, then use the default set of
20413 note type strings. */
20414 nt
= get_note_type (filedata
, pnote
->type
);
20416 else if (const_strneq (pnote
->namedata
, "GNU"))
20417 /* GNU-specific object file notes. */
20418 nt
= get_gnu_elf_note_type (pnote
->type
);
20420 else if (const_strneq (pnote
->namedata
, "FreeBSD"))
20421 /* FreeBSD-specific core file notes. */
20422 nt
= get_freebsd_elfcore_note_type (filedata
, pnote
->type
);
20424 else if (const_strneq (pnote
->namedata
, "NetBSD-CORE"))
20425 /* NetBSD-specific core file notes. */
20426 nt
= get_netbsd_elfcore_note_type (filedata
, pnote
->type
);
20428 else if (const_strneq (pnote
->namedata
, "NetBSD"))
20429 /* NetBSD-specific core file notes. */
20430 return process_netbsd_elf_note (pnote
);
20432 else if (const_strneq (pnote
->namedata
, "PaX"))
20433 /* NetBSD-specific core file notes. */
20434 return process_netbsd_elf_note (pnote
);
20436 else if (strneq (pnote
->namedata
, "SPU/", 4))
20438 /* SPU-specific core file notes. */
20439 nt
= pnote
->namedata
+ 4;
20443 else if (const_strneq (pnote
->namedata
, "IPF/VMS"))
20444 /* VMS/ia64-specific file notes. */
20445 nt
= get_ia64_vms_note_type (pnote
->type
);
20447 else if (const_strneq (pnote
->namedata
, "stapsdt"))
20448 nt
= get_stapsdt_note_type (pnote
->type
);
20451 /* Don't recognize this note name; just use the default set of
20452 note type strings. */
20453 nt
= get_note_type (filedata
, pnote
->type
);
20457 if (((const_strneq (pnote
->namedata
, "GA")
20458 && strchr ("*$!+", pnote
->namedata
[2]) != NULL
)
20459 || strchr ("*$!+", pnote
->namedata
[0]) != NULL
)
20460 && (pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_OPEN
20461 || pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_FUNC
))
20462 print_gnu_build_attribute_name (pnote
);
20464 print_symbol (-20, name
);
20467 printf (" 0x%08lx\t%s\t", pnote
->descsz
, nt
);
20469 printf (" 0x%08lx\t%s\n", pnote
->descsz
, nt
);
20471 if (const_strneq (pnote
->namedata
, "IPF/VMS"))
20472 return print_ia64_vms_note (pnote
);
20473 else if (const_strneq (pnote
->namedata
, "GNU"))
20474 return print_gnu_note (filedata
, pnote
);
20475 else if (const_strneq (pnote
->namedata
, "stapsdt"))
20476 return print_stapsdt_note (pnote
);
20477 else if (const_strneq (pnote
->namedata
, "CORE"))
20478 return print_core_note (pnote
);
20479 else if (((const_strneq (pnote
->namedata
, "GA")
20480 && strchr ("*$!+", pnote
->namedata
[2]) != NULL
)
20481 || strchr ("*$!+", pnote
->namedata
[0]) != NULL
)
20482 && (pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_OPEN
20483 || pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_FUNC
))
20484 return print_gnu_build_attribute_description (pnote
, filedata
);
20490 printf (_(" description data: "));
20491 for (i
= 0; i
< pnote
->descsz
; i
++)
20492 printf ("%02x ", pnote
->descdata
[i
] & 0xff);
20504 process_notes_at (Filedata
* filedata
,
20505 Elf_Internal_Shdr
* section
,
20510 Elf_External_Note
* pnotes
;
20511 Elf_External_Note
* external
;
20513 bfd_boolean res
= TRUE
;
20520 pnotes
= (Elf_External_Note
*) get_section_contents (section
, filedata
);
20523 if (! apply_relocations (filedata
, section
, (unsigned char *) pnotes
, length
, NULL
, NULL
))
20531 pnotes
= (Elf_External_Note
*) get_data (NULL
, filedata
, offset
, 1, length
,
20534 if (pnotes
== NULL
)
20539 if (filedata
->is_separate
)
20540 printf (_("In linked file '%s': "), filedata
->file_name
);
20544 printf (_("Displaying notes found in: %s\n"), printable_section_name (filedata
, section
));
20546 printf (_("Displaying notes found at file offset 0x%08lx with length 0x%08lx:\n"),
20547 (unsigned long) offset
, (unsigned long) length
);
20549 /* NB: Some note sections may have alignment value of 0 or 1. gABI
20550 specifies that notes should be aligned to 4 bytes in 32-bit
20551 objects and to 8 bytes in 64-bit objects. As a Linux extension,
20552 we also support 4 byte alignment in 64-bit objects. If section
20553 alignment is less than 4, we treate alignment as 4 bytes. */
20556 else if (align
!= 4 && align
!= 8)
20558 warn (_("Corrupt note: alignment %ld, expecting 4 or 8\n"),
20564 printf (_(" %-20s %-10s\tDescription\n"), _("Owner"), _("Data size"));
20566 end
= (char *) pnotes
+ length
;
20567 while ((char *) external
< end
)
20569 Elf_Internal_Note inote
;
20572 char * temp
= NULL
;
20573 size_t data_remaining
= end
- (char *) external
;
20575 if (!is_ia64_vms (filedata
))
20577 /* PR binutils/15191
20578 Make sure that there is enough data to read. */
20579 min_notesz
= offsetof (Elf_External_Note
, name
);
20580 if (data_remaining
< min_notesz
)
20582 warn (ngettext ("Corrupt note: only %ld byte remains, "
20583 "not enough for a full note\n",
20584 "Corrupt note: only %ld bytes remain, "
20585 "not enough for a full note\n",
20587 (long) data_remaining
);
20590 data_remaining
-= min_notesz
;
20592 inote
.type
= BYTE_GET (external
->type
);
20593 inote
.namesz
= BYTE_GET (external
->namesz
);
20594 inote
.namedata
= external
->name
;
20595 inote
.descsz
= BYTE_GET (external
->descsz
);
20596 inote
.descdata
= ((char *) external
20597 + ELF_NOTE_DESC_OFFSET (inote
.namesz
, align
));
20598 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
20599 next
= ((char *) external
20600 + ELF_NOTE_NEXT_OFFSET (inote
.namesz
, inote
.descsz
, align
));
20604 Elf64_External_VMS_Note
*vms_external
;
20606 /* PR binutils/15191
20607 Make sure that there is enough data to read. */
20608 min_notesz
= offsetof (Elf64_External_VMS_Note
, name
);
20609 if (data_remaining
< min_notesz
)
20611 warn (ngettext ("Corrupt note: only %ld byte remains, "
20612 "not enough for a full note\n",
20613 "Corrupt note: only %ld bytes remain, "
20614 "not enough for a full note\n",
20616 (long) data_remaining
);
20619 data_remaining
-= min_notesz
;
20621 vms_external
= (Elf64_External_VMS_Note
*) external
;
20622 inote
.type
= BYTE_GET (vms_external
->type
);
20623 inote
.namesz
= BYTE_GET (vms_external
->namesz
);
20624 inote
.namedata
= vms_external
->name
;
20625 inote
.descsz
= BYTE_GET (vms_external
->descsz
);
20626 inote
.descdata
= inote
.namedata
+ align_power (inote
.namesz
, 3);
20627 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
20628 next
= inote
.descdata
+ align_power (inote
.descsz
, 3);
20631 /* PR 17531: file: 3443835e. */
20632 /* PR 17531: file: id:000000,sig:11,src:006986,op:havoc,rep:4. */
20633 if ((size_t) (inote
.descdata
- inote
.namedata
) < inote
.namesz
20634 || (size_t) (inote
.descdata
- inote
.namedata
) > data_remaining
20635 || (size_t) (next
- inote
.descdata
) < inote
.descsz
20636 || ((size_t) (next
- inote
.descdata
)
20637 > data_remaining
- (size_t) (inote
.descdata
- inote
.namedata
)))
20639 warn (_("note with invalid namesz and/or descsz found at offset 0x%lx\n"),
20640 (unsigned long) ((char *) external
- (char *) pnotes
));
20641 warn (_(" type: 0x%lx, namesize: 0x%08lx, descsize: 0x%08lx, alignment: %u\n"),
20642 inote
.type
, inote
.namesz
, inote
.descsz
, (int) align
);
20646 external
= (Elf_External_Note
*) next
;
20648 /* Verify that name is null terminated. It appears that at least
20649 one version of Linux (RedHat 6.0) generates corefiles that don't
20650 comply with the ELF spec by failing to include the null byte in
20652 if (inote
.namesz
> 0 && inote
.namedata
[inote
.namesz
- 1] != '\0')
20654 if ((size_t) (inote
.descdata
- inote
.namedata
) == inote
.namesz
)
20656 temp
= (char *) malloc (inote
.namesz
+ 1);
20659 error (_("Out of memory allocating space for inote name\n"));
20664 memcpy (temp
, inote
.namedata
, inote
.namesz
);
20665 inote
.namedata
= temp
;
20667 inote
.namedata
[inote
.namesz
] = 0;
20670 if (! process_note (& inote
, filedata
))
20683 process_corefile_note_segments (Filedata
* filedata
)
20685 Elf_Internal_Phdr
* segment
;
20687 bfd_boolean res
= TRUE
;
20689 if (! get_program_headers (filedata
))
20692 for (i
= 0, segment
= filedata
->program_headers
;
20693 i
< filedata
->file_header
.e_phnum
;
20696 if (segment
->p_type
== PT_NOTE
)
20697 if (! process_notes_at (filedata
, NULL
,
20698 (bfd_vma
) segment
->p_offset
,
20699 (bfd_vma
) segment
->p_filesz
,
20700 (bfd_vma
) segment
->p_align
))
20708 process_v850_notes (Filedata
* filedata
, bfd_vma offset
, bfd_vma length
)
20710 Elf_External_Note
* pnotes
;
20711 Elf_External_Note
* external
;
20713 bfd_boolean res
= TRUE
;
20718 pnotes
= (Elf_External_Note
*) get_data (NULL
, filedata
, offset
, 1, length
,
20720 if (pnotes
== NULL
)
20724 end
= (char*) pnotes
+ length
;
20726 printf (_("\nDisplaying contents of Renesas V850 notes section at offset 0x%lx with length 0x%lx:\n"),
20727 (unsigned long) offset
, (unsigned long) length
);
20729 while ((char *) external
+ sizeof (Elf_External_Note
) < end
)
20731 Elf_External_Note
* next
;
20732 Elf_Internal_Note inote
;
20734 inote
.type
= BYTE_GET (external
->type
);
20735 inote
.namesz
= BYTE_GET (external
->namesz
);
20736 inote
.namedata
= external
->name
;
20737 inote
.descsz
= BYTE_GET (external
->descsz
);
20738 inote
.descdata
= inote
.namedata
+ align_power (inote
.namesz
, 2);
20739 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
20741 if (inote
.descdata
< (char *) pnotes
|| inote
.descdata
>= end
)
20743 warn (_("Corrupt note: name size is too big: %lx\n"), inote
.namesz
);
20744 inote
.descdata
= inote
.namedata
;
20748 next
= (Elf_External_Note
*) (inote
.descdata
+ align_power (inote
.descsz
, 2));
20750 if ( ((char *) next
> end
)
20751 || ((char *) next
< (char *) pnotes
))
20753 warn (_("corrupt descsz found in note at offset 0x%lx\n"),
20754 (unsigned long) ((char *) external
- (char *) pnotes
));
20755 warn (_(" type: 0x%lx, namesize: 0x%lx, descsize: 0x%lx\n"),
20756 inote
.type
, inote
.namesz
, inote
.descsz
);
20762 /* Prevent out-of-bounds indexing. */
20763 if ( inote
.namedata
+ inote
.namesz
> end
20764 || inote
.namedata
+ inote
.namesz
< inote
.namedata
)
20766 warn (_("corrupt namesz found in note at offset 0x%lx\n"),
20767 (unsigned long) ((char *) external
- (char *) pnotes
));
20768 warn (_(" type: 0x%lx, namesize: 0x%lx, descsize: 0x%lx\n"),
20769 inote
.type
, inote
.namesz
, inote
.descsz
);
20773 printf (" %s: ", get_v850_elf_note_type (inote
.type
));
20775 if (! print_v850_note (& inote
))
20778 printf ("<corrupt sizes: namesz: %lx, descsz: %lx>\n",
20779 inote
.namesz
, inote
.descsz
);
20789 process_note_sections (Filedata
* filedata
)
20791 Elf_Internal_Shdr
* section
;
20793 unsigned int n
= 0;
20794 bfd_boolean res
= TRUE
;
20796 for (i
= 0, section
= filedata
->section_headers
;
20797 i
< filedata
->file_header
.e_shnum
&& section
!= NULL
;
20800 if (section
->sh_type
== SHT_NOTE
)
20802 if (! process_notes_at (filedata
, section
,
20803 (bfd_vma
) section
->sh_offset
,
20804 (bfd_vma
) section
->sh_size
,
20805 (bfd_vma
) section
->sh_addralign
))
20810 if (( filedata
->file_header
.e_machine
== EM_V800
20811 || filedata
->file_header
.e_machine
== EM_V850
20812 || filedata
->file_header
.e_machine
== EM_CYGNUS_V850
)
20813 && section
->sh_type
== SHT_RENESAS_INFO
)
20815 if (! process_v850_notes (filedata
,
20816 (bfd_vma
) section
->sh_offset
,
20817 (bfd_vma
) section
->sh_size
))
20824 /* Try processing NOTE segments instead. */
20825 return process_corefile_note_segments (filedata
);
20831 process_notes (Filedata
* filedata
)
20833 /* If we have not been asked to display the notes then do nothing. */
20837 if (filedata
->file_header
.e_type
!= ET_CORE
)
20838 return process_note_sections (filedata
);
20840 /* No program headers means no NOTE segment. */
20841 if (filedata
->file_header
.e_phnum
> 0)
20842 return process_corefile_note_segments (filedata
);
20844 if (filedata
->is_separate
)
20845 printf (_("No notes found in linked file '%s'.\n"),
20846 filedata
->file_name
);
20848 printf (_("No notes found file.\n"));
20853 static unsigned char *
20854 display_public_gnu_attributes (unsigned char * start
,
20855 const unsigned char * const end
)
20857 printf (_(" Unknown GNU attribute: %s\n"), start
);
20859 start
+= strnlen ((char *) start
, end
- start
);
20860 display_raw_attribute (start
, end
);
20862 return (unsigned char *) end
;
20865 static unsigned char *
20866 display_generic_attribute (unsigned char * start
,
20868 const unsigned char * const end
)
20871 return (unsigned char *) end
;
20873 return display_tag_value (tag
, start
, end
);
20877 process_arch_specific (Filedata
* filedata
)
20882 switch (filedata
->file_header
.e_machine
)
20885 case EM_ARC_COMPACT
:
20886 case EM_ARC_COMPACT2
:
20887 return process_attributes (filedata
, "ARC", SHT_ARC_ATTRIBUTES
,
20888 display_arc_attribute
,
20889 display_generic_attribute
);
20891 return process_attributes (filedata
, "aeabi", SHT_ARM_ATTRIBUTES
,
20892 display_arm_attribute
,
20893 display_generic_attribute
);
20896 case EM_MIPS_RS3_LE
:
20897 return process_mips_specific (filedata
);
20900 return process_attributes (filedata
, "mspabi", SHT_MSP430_ATTRIBUTES
,
20901 display_msp430_attribute
,
20902 display_msp430_gnu_attribute
);
20905 return process_attributes (filedata
, "riscv", SHT_RISCV_ATTRIBUTES
,
20906 display_riscv_attribute
,
20907 display_generic_attribute
);
20910 return process_nds32_specific (filedata
);
20913 return process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
20914 display_m68k_gnu_attribute
);
20918 return process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
20919 display_power_gnu_attribute
);
20923 return process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
20924 display_s390_gnu_attribute
);
20927 case EM_SPARC32PLUS
:
20929 return process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
20930 display_sparc_gnu_attribute
);
20933 return process_attributes (filedata
, "c6xabi", SHT_C6000_ATTRIBUTES
,
20934 display_tic6x_attribute
,
20935 display_generic_attribute
);
20938 return process_attributes (filedata
, "csky", SHT_CSKY_ATTRIBUTES
,
20939 display_csky_attribute
, NULL
);
20942 return process_attributes (filedata
, "gnu", SHT_GNU_ATTRIBUTES
,
20943 display_public_gnu_attributes
,
20944 display_generic_attribute
);
20949 get_file_header (Filedata
* filedata
)
20951 /* Read in the identity array. */
20952 if (fread (filedata
->file_header
.e_ident
, EI_NIDENT
, 1, filedata
->handle
) != 1)
20955 /* Determine how to read the rest of the header. */
20956 switch (filedata
->file_header
.e_ident
[EI_DATA
])
20961 byte_get
= byte_get_little_endian
;
20962 byte_put
= byte_put_little_endian
;
20965 byte_get
= byte_get_big_endian
;
20966 byte_put
= byte_put_big_endian
;
20970 /* For now we only support 32 bit and 64 bit ELF files. */
20971 is_32bit_elf
= (filedata
->file_header
.e_ident
[EI_CLASS
] != ELFCLASS64
);
20973 /* Read in the rest of the header. */
20976 Elf32_External_Ehdr ehdr32
;
20978 if (fread (ehdr32
.e_type
, sizeof (ehdr32
) - EI_NIDENT
, 1, filedata
->handle
) != 1)
20981 filedata
->file_header
.e_type
= BYTE_GET (ehdr32
.e_type
);
20982 filedata
->file_header
.e_machine
= BYTE_GET (ehdr32
.e_machine
);
20983 filedata
->file_header
.e_version
= BYTE_GET (ehdr32
.e_version
);
20984 filedata
->file_header
.e_entry
= BYTE_GET (ehdr32
.e_entry
);
20985 filedata
->file_header
.e_phoff
= BYTE_GET (ehdr32
.e_phoff
);
20986 filedata
->file_header
.e_shoff
= BYTE_GET (ehdr32
.e_shoff
);
20987 filedata
->file_header
.e_flags
= BYTE_GET (ehdr32
.e_flags
);
20988 filedata
->file_header
.e_ehsize
= BYTE_GET (ehdr32
.e_ehsize
);
20989 filedata
->file_header
.e_phentsize
= BYTE_GET (ehdr32
.e_phentsize
);
20990 filedata
->file_header
.e_phnum
= BYTE_GET (ehdr32
.e_phnum
);
20991 filedata
->file_header
.e_shentsize
= BYTE_GET (ehdr32
.e_shentsize
);
20992 filedata
->file_header
.e_shnum
= BYTE_GET (ehdr32
.e_shnum
);
20993 filedata
->file_header
.e_shstrndx
= BYTE_GET (ehdr32
.e_shstrndx
);
20997 Elf64_External_Ehdr ehdr64
;
20999 /* If we have been compiled with sizeof (bfd_vma) == 4, then
21000 we will not be able to cope with the 64bit data found in
21001 64 ELF files. Detect this now and abort before we start
21002 overwriting things. */
21003 if (sizeof (bfd_vma
) < 8)
21005 error (_("This instance of readelf has been built without support for a\n\
21006 64 bit data type and so it cannot read 64 bit ELF files.\n"));
21010 if (fread (ehdr64
.e_type
, sizeof (ehdr64
) - EI_NIDENT
, 1, filedata
->handle
) != 1)
21013 filedata
->file_header
.e_type
= BYTE_GET (ehdr64
.e_type
);
21014 filedata
->file_header
.e_machine
= BYTE_GET (ehdr64
.e_machine
);
21015 filedata
->file_header
.e_version
= BYTE_GET (ehdr64
.e_version
);
21016 filedata
->file_header
.e_entry
= BYTE_GET (ehdr64
.e_entry
);
21017 filedata
->file_header
.e_phoff
= BYTE_GET (ehdr64
.e_phoff
);
21018 filedata
->file_header
.e_shoff
= BYTE_GET (ehdr64
.e_shoff
);
21019 filedata
->file_header
.e_flags
= BYTE_GET (ehdr64
.e_flags
);
21020 filedata
->file_header
.e_ehsize
= BYTE_GET (ehdr64
.e_ehsize
);
21021 filedata
->file_header
.e_phentsize
= BYTE_GET (ehdr64
.e_phentsize
);
21022 filedata
->file_header
.e_phnum
= BYTE_GET (ehdr64
.e_phnum
);
21023 filedata
->file_header
.e_shentsize
= BYTE_GET (ehdr64
.e_shentsize
);
21024 filedata
->file_header
.e_shnum
= BYTE_GET (ehdr64
.e_shnum
);
21025 filedata
->file_header
.e_shstrndx
= BYTE_GET (ehdr64
.e_shstrndx
);
21028 if (filedata
->file_header
.e_shoff
)
21030 /* There may be some extensions in the first section header. Don't
21031 bomb if we can't read it. */
21033 get_32bit_section_headers (filedata
, TRUE
);
21035 get_64bit_section_headers (filedata
, TRUE
);
21042 close_file (Filedata
* filedata
)
21046 if (filedata
->handle
)
21047 fclose (filedata
->handle
);
21053 close_debug_file (void * data
)
21055 close_file ((Filedata
*) data
);
21059 open_file (const char * pathname
, bfd_boolean is_separate
)
21061 struct stat statbuf
;
21062 Filedata
* filedata
= NULL
;
21064 if (stat (pathname
, & statbuf
) < 0
21065 || ! S_ISREG (statbuf
.st_mode
))
21068 filedata
= calloc (1, sizeof * filedata
);
21069 if (filedata
== NULL
)
21072 filedata
->handle
= fopen (pathname
, "rb");
21073 if (filedata
->handle
== NULL
)
21076 filedata
->file_size
= (bfd_size_type
) statbuf
.st_size
;
21077 filedata
->file_name
= pathname
;
21078 filedata
->is_separate
= is_separate
;
21080 if (! get_file_header (filedata
))
21083 if (filedata
->file_header
.e_shoff
)
21087 /* Read the section headers again, this time for real. */
21089 res
= get_32bit_section_headers (filedata
, FALSE
);
21091 res
= get_64bit_section_headers (filedata
, FALSE
);
21102 if (filedata
->handle
)
21103 fclose (filedata
->handle
);
21110 open_debug_file (const char * pathname
)
21112 return open_file (pathname
, TRUE
);
21115 /* Process one ELF object file according to the command line options.
21116 This file may actually be stored in an archive. The file is
21117 positioned at the start of the ELF object. Returns TRUE if no
21118 problems were encountered, FALSE otherwise. */
21121 process_object (Filedata
* filedata
)
21123 bfd_boolean have_separate_files
;
21127 if (! get_file_header (filedata
))
21129 error (_("%s: Failed to read file header\n"), filedata
->file_name
);
21133 /* Initialise per file variables. */
21134 for (i
= ARRAY_SIZE (filedata
->version_info
); i
--;)
21135 filedata
->version_info
[i
] = 0;
21137 for (i
= ARRAY_SIZE (filedata
->dynamic_info
); i
--;)
21138 filedata
->dynamic_info
[i
] = 0;
21139 filedata
->dynamic_info_DT_GNU_HASH
= 0;
21140 filedata
->dynamic_info_DT_MIPS_XHASH
= 0;
21142 /* Process the file. */
21144 printf (_("\nFile: %s\n"), filedata
->file_name
);
21146 /* Initialise the dump_sects array from the cmdline_dump_sects array.
21147 Note we do this even if cmdline_dump_sects is empty because we
21148 must make sure that the dump_sets array is zeroed out before each
21149 object file is processed. */
21150 if (filedata
->dump
.num_dump_sects
> cmdline
.num_dump_sects
)
21151 memset (filedata
->dump
.dump_sects
, 0,
21152 filedata
->dump
.num_dump_sects
* sizeof (*filedata
->dump
.dump_sects
));
21154 if (cmdline
.num_dump_sects
> 0)
21156 if (filedata
->dump
.num_dump_sects
== 0)
21157 /* A sneaky way of allocating the dump_sects array. */
21158 request_dump_bynumber (&filedata
->dump
, cmdline
.num_dump_sects
, 0);
21160 assert (filedata
->dump
.num_dump_sects
>= cmdline
.num_dump_sects
);
21161 memcpy (filedata
->dump
.dump_sects
, cmdline
.dump_sects
,
21162 cmdline
.num_dump_sects
* sizeof (*filedata
->dump
.dump_sects
));
21165 if (! process_file_header (filedata
))
21168 if (! process_section_headers (filedata
))
21170 /* Without loaded section headers we cannot process lots of things. */
21171 do_unwind
= do_version
= do_dump
= do_arch
= FALSE
;
21173 if (! do_using_dynamic
)
21174 do_syms
= do_dyn_syms
= do_reloc
= FALSE
;
21177 if (! process_section_groups (filedata
))
21178 /* Without loaded section groups we cannot process unwind. */
21181 res
= process_program_headers (filedata
);
21183 res
= process_dynamic_section (filedata
);
21185 if (! process_relocs (filedata
))
21188 if (! process_unwind (filedata
))
21191 if (! process_symbol_table (filedata
))
21194 if (! process_lto_symbol_tables (filedata
))
21197 if (! process_syminfo (filedata
))
21200 if (! process_version_sections (filedata
))
21203 if (filedata
->file_header
.e_shstrndx
!= SHN_UNDEF
)
21204 have_separate_files
= load_separate_debug_files (filedata
, filedata
->file_name
);
21206 have_separate_files
= FALSE
;
21208 if (! process_section_contents (filedata
))
21211 if (have_separate_files
)
21215 for (d
= first_separate_info
; d
!= NULL
; d
= d
->next
)
21217 if (process_links
&& ! process_file_header (d
->handle
))
21219 else if (! process_section_headers (d
->handle
))
21221 else if (process_links
)
21223 if (! process_section_contents (d
->handle
))
21225 if (! process_section_groups (d
->handle
))
21227 if (! process_program_headers (d
->handle
))
21229 if (! process_dynamic_section (d
->handle
))
21231 if (! process_relocs (d
->handle
))
21233 if (! process_unwind (d
->handle
))
21235 if (! process_symbol_table (d
->handle
))
21237 if (! process_lto_symbol_tables (d
->handle
))
21239 if (! process_syminfo (d
->handle
))
21241 if (! process_version_sections (d
->handle
))
21243 if (! process_notes (d
->handle
))
21248 /* The file handles are closed by the call to free_debug_memory() below. */
21251 if (! process_notes (filedata
))
21254 if (! process_gnu_liblist (filedata
))
21257 if (! process_arch_specific (filedata
))
21260 free (filedata
->program_headers
);
21261 filedata
->program_headers
= NULL
;
21263 free (filedata
->section_headers
);
21264 filedata
->section_headers
= NULL
;
21266 free (filedata
->string_table
);
21267 filedata
->string_table
= NULL
;
21268 filedata
->string_table_length
= 0;
21270 free (filedata
->dump
.dump_sects
);
21271 filedata
->dump
.dump_sects
= NULL
;
21272 filedata
->dump
.num_dump_sects
= 0;
21274 free (filedata
->dynamic_strings
);
21275 filedata
->dynamic_strings
= NULL
;
21276 filedata
->dynamic_strings_length
= 0;
21278 free (filedata
->dynamic_symbols
);
21279 filedata
->dynamic_symbols
= NULL
;
21280 filedata
->num_dynamic_syms
= 0;
21282 free (filedata
->dynamic_syminfo
);
21283 filedata
->dynamic_syminfo
= NULL
;
21285 free (filedata
->dynamic_section
);
21286 filedata
->dynamic_section
= NULL
;
21288 while (filedata
->symtab_shndx_list
!= NULL
)
21290 elf_section_list
*next
= filedata
->symtab_shndx_list
->next
;
21291 free (filedata
->symtab_shndx_list
);
21292 filedata
->symtab_shndx_list
= next
;
21295 free (filedata
->section_headers_groups
);
21296 filedata
->section_headers_groups
= NULL
;
21298 if (filedata
->section_groups
)
21300 struct group_list
* g
;
21301 struct group_list
* next
;
21303 for (i
= 0; i
< filedata
->group_count
; i
++)
21305 for (g
= filedata
->section_groups
[i
].root
; g
!= NULL
; g
= next
)
21312 free (filedata
->section_groups
);
21313 filedata
->section_groups
= NULL
;
21316 free_debug_memory ();
21321 /* Process an ELF archive.
21322 On entry the file is positioned just after the ARMAG string.
21323 Returns TRUE upon success, FALSE otherwise. */
21326 process_archive (Filedata
* filedata
, bfd_boolean is_thin_archive
)
21328 struct archive_info arch
;
21329 struct archive_info nested_arch
;
21331 bfd_boolean ret
= TRUE
;
21335 /* The ARCH structure is used to hold information about this archive. */
21336 arch
.file_name
= NULL
;
21338 arch
.index_array
= NULL
;
21339 arch
.sym_table
= NULL
;
21340 arch
.longnames
= NULL
;
21342 /* The NESTED_ARCH structure is used as a single-item cache of information
21343 about a nested archive (when members of a thin archive reside within
21344 another regular archive file). */
21345 nested_arch
.file_name
= NULL
;
21346 nested_arch
.file
= NULL
;
21347 nested_arch
.index_array
= NULL
;
21348 nested_arch
.sym_table
= NULL
;
21349 nested_arch
.longnames
= NULL
;
21351 if (setup_archive (&arch
, filedata
->file_name
, filedata
->handle
,
21352 filedata
->file_size
, is_thin_archive
,
21353 do_archive_index
) != 0)
21359 if (do_archive_index
)
21361 if (arch
.sym_table
== NULL
)
21362 error (_("%s: unable to dump the index as none was found\n"),
21363 filedata
->file_name
);
21366 unsigned long i
, l
;
21367 unsigned long current_pos
;
21369 printf (_("Index of archive %s: (%lu entries, 0x%lx bytes "
21370 "in the symbol table)\n"),
21371 filedata
->file_name
, (unsigned long) arch
.index_num
,
21374 current_pos
= ftell (filedata
->handle
);
21376 for (i
= l
= 0; i
< arch
.index_num
; i
++)
21379 || (i
> 0 && arch
.index_array
[i
] != arch
.index_array
[i
- 1]))
21382 = get_archive_member_name_at (&arch
, arch
.index_array
[i
],
21385 if (member_name
!= NULL
)
21387 char * qualified_name
21388 = make_qualified_name (&arch
, &nested_arch
,
21391 if (qualified_name
!= NULL
)
21393 printf (_("Contents of binary %s at offset "),
21395 (void) print_vma (arch
.index_array
[i
], PREFIX_HEX
);
21397 free (qualified_name
);
21399 free (member_name
);
21403 if (l
>= arch
.sym_size
)
21405 error (_("%s: end of the symbol table reached "
21406 "before the end of the index\n"),
21407 filedata
->file_name
);
21411 /* PR 17531: file: 0b6630b2. */
21412 printf ("\t%.*s\n",
21413 (int) (arch
.sym_size
- l
), arch
.sym_table
+ l
);
21414 l
+= strnlen (arch
.sym_table
+ l
, arch
.sym_size
- l
) + 1;
21417 if (arch
.uses_64bit_indices
)
21422 if (l
< arch
.sym_size
)
21424 error (ngettext ("%s: %ld byte remains in the symbol table, "
21425 "but without corresponding entries in "
21426 "the index table\n",
21427 "%s: %ld bytes remain in the symbol table, "
21428 "but without corresponding entries in "
21429 "the index table\n",
21430 arch
.sym_size
- l
),
21431 filedata
->file_name
, arch
.sym_size
- l
);
21435 if (fseek (filedata
->handle
, current_pos
, SEEK_SET
) != 0)
21437 error (_("%s: failed to seek back to start of object files "
21438 "in the archive\n"),
21439 filedata
->file_name
);
21445 if (!do_dynamic
&& !do_syms
&& !do_reloc
&& !do_unwind
&& !do_sections
21446 && !do_segments
&& !do_header
&& !do_dump
&& !do_version
21447 && !do_histogram
&& !do_debugging
&& !do_arch
&& !do_notes
21448 && !do_section_groups
&& !do_dyn_syms
)
21450 ret
= TRUE
; /* Archive index only. */
21459 char * qualified_name
;
21461 /* Read the next archive header. */
21462 if (fseek (filedata
->handle
, arch
.next_arhdr_offset
, SEEK_SET
) != 0)
21464 error (_("%s: failed to seek to next archive header\n"),
21469 got
= fread (&arch
.arhdr
, 1, sizeof arch
.arhdr
, filedata
->handle
);
21470 if (got
!= sizeof arch
.arhdr
)
21474 /* PR 24049 - we cannot use filedata->file_name as this will
21475 have already been freed. */
21476 error (_("%s: failed to read archive header\n"), arch
.file_name
);
21481 if (memcmp (arch
.arhdr
.ar_fmag
, ARFMAG
, 2) != 0)
21483 error (_("%s: did not find a valid archive header\n"),
21489 arch
.next_arhdr_offset
+= sizeof arch
.arhdr
;
21491 filedata
->archive_file_size
= strtoul (arch
.arhdr
.ar_size
, NULL
, 10);
21492 if (filedata
->archive_file_size
& 01)
21493 ++filedata
->archive_file_size
;
21495 name
= get_archive_member_name (&arch
, &nested_arch
);
21498 error (_("%s: bad archive file name\n"), arch
.file_name
);
21502 namelen
= strlen (name
);
21504 qualified_name
= make_qualified_name (&arch
, &nested_arch
, name
);
21505 if (qualified_name
== NULL
)
21507 error (_("%s: bad archive file name\n"), arch
.file_name
);
21513 if (is_thin_archive
&& arch
.nested_member_origin
== 0)
21515 /* This is a proxy for an external member of a thin archive. */
21516 Filedata
* member_filedata
;
21517 char * member_file_name
= adjust_relative_path
21518 (filedata
->file_name
, name
, namelen
);
21521 if (member_file_name
== NULL
)
21523 free (qualified_name
);
21528 member_filedata
= open_file (member_file_name
, FALSE
);
21529 if (member_filedata
== NULL
)
21531 error (_("Input file '%s' is not readable.\n"), member_file_name
);
21532 free (member_file_name
);
21533 free (qualified_name
);
21538 filedata
->archive_file_offset
= arch
.nested_member_origin
;
21539 member_filedata
->file_name
= qualified_name
;
21541 if (! process_object (member_filedata
))
21544 close_file (member_filedata
);
21545 free (member_file_name
);
21547 else if (is_thin_archive
)
21549 Filedata thin_filedata
;
21551 memset (&thin_filedata
, 0, sizeof (thin_filedata
));
21553 /* PR 15140: Allow for corrupt thin archives. */
21554 if (nested_arch
.file
== NULL
)
21556 error (_("%s: contains corrupt thin archive: %s\n"),
21557 qualified_name
, name
);
21558 free (qualified_name
);
21565 /* This is a proxy for a member of a nested archive. */
21566 filedata
->archive_file_offset
21567 = arch
.nested_member_origin
+ sizeof arch
.arhdr
;
21569 /* The nested archive file will have been opened and setup by
21570 get_archive_member_name. */
21571 if (fseek (nested_arch
.file
, filedata
->archive_file_offset
,
21574 error (_("%s: failed to seek to archive member.\n"),
21575 nested_arch
.file_name
);
21576 free (qualified_name
);
21581 thin_filedata
.handle
= nested_arch
.file
;
21582 thin_filedata
.file_name
= qualified_name
;
21584 if (! process_object (& thin_filedata
))
21590 filedata
->archive_file_offset
= arch
.next_arhdr_offset
;
21591 filedata
->file_name
= qualified_name
;
21592 if (! process_object (filedata
))
21594 arch
.next_arhdr_offset
+= filedata
->archive_file_size
;
21595 /* Stop looping with "negative" archive_file_size. */
21596 if (arch
.next_arhdr_offset
< filedata
->archive_file_size
)
21597 arch
.next_arhdr_offset
= -1ul;
21600 free (qualified_name
);
21604 if (nested_arch
.file
!= NULL
)
21605 fclose (nested_arch
.file
);
21606 release_archive (&nested_arch
);
21607 release_archive (&arch
);
21613 process_file (char * file_name
)
21615 Filedata
* filedata
= NULL
;
21616 struct stat statbuf
;
21617 char armag
[SARMAG
];
21618 bfd_boolean ret
= TRUE
;
21620 if (stat (file_name
, &statbuf
) < 0)
21622 if (errno
== ENOENT
)
21623 error (_("'%s': No such file\n"), file_name
);
21625 error (_("Could not locate '%s'. System error message: %s\n"),
21626 file_name
, strerror (errno
));
21630 if (! S_ISREG (statbuf
.st_mode
))
21632 error (_("'%s' is not an ordinary file\n"), file_name
);
21636 filedata
= calloc (1, sizeof * filedata
);
21637 if (filedata
== NULL
)
21639 error (_("Out of memory allocating file data structure\n"));
21643 filedata
->file_name
= file_name
;
21644 filedata
->handle
= fopen (file_name
, "rb");
21645 if (filedata
->handle
== NULL
)
21647 error (_("Input file '%s' is not readable.\n"), file_name
);
21652 if (fread (armag
, SARMAG
, 1, filedata
->handle
) != 1)
21654 error (_("%s: Failed to read file's magic number\n"), file_name
);
21655 fclose (filedata
->handle
);
21660 filedata
->file_size
= (bfd_size_type
) statbuf
.st_size
;
21661 filedata
->is_separate
= FALSE
;
21663 if (memcmp (armag
, ARMAG
, SARMAG
) == 0)
21665 if (! process_archive (filedata
, FALSE
))
21668 else if (memcmp (armag
, ARMAGT
, SARMAG
) == 0)
21670 if ( ! process_archive (filedata
, TRUE
))
21675 if (do_archive_index
&& !check_all
)
21676 error (_("File %s is not an archive so its index cannot be displayed.\n"),
21679 rewind (filedata
->handle
);
21680 filedata
->archive_file_size
= filedata
->archive_file_offset
= 0;
21682 if (! process_object (filedata
))
21686 fclose (filedata
->handle
);
21687 free (filedata
->section_headers
);
21688 free (filedata
->program_headers
);
21689 free (filedata
->string_table
);
21690 free (filedata
->dump
.dump_sects
);
21693 free (ba_cache
.strtab
);
21694 ba_cache
.strtab
= NULL
;
21695 free (ba_cache
.symtab
);
21696 ba_cache
.symtab
= NULL
;
21697 ba_cache
.filedata
= NULL
;
21702 #ifdef SUPPORT_DISASSEMBLY
21703 /* Needed by the i386 disassembler. For extra credit, someone could
21704 fix this so that we insert symbolic addresses here, esp for GOT/PLT
21708 print_address (unsigned int addr
, FILE * outfile
)
21710 fprintf (outfile
,"0x%8.8x", addr
);
21713 /* Needed by the i386 disassembler. */
21716 db_task_printsym (unsigned int addr
)
21718 print_address (addr
, stderr
);
21723 main (int argc
, char ** argv
)
21727 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
21728 setlocale (LC_MESSAGES
, "");
21730 #if defined (HAVE_SETLOCALE)
21731 setlocale (LC_CTYPE
, "");
21733 bindtextdomain (PACKAGE
, LOCALEDIR
);
21734 textdomain (PACKAGE
);
21736 expandargv (&argc
, &argv
);
21738 parse_args (& cmdline
, argc
, argv
);
21740 if (optind
< (argc
- 1))
21741 /* When displaying information for more than one file,
21742 prefix the information with the file name. */
21744 else if (optind
>= argc
)
21746 /* Ensure that the warning is always displayed. */
21749 warn (_("Nothing to do.\n"));
21754 while (optind
< argc
)
21755 if (! process_file (argv
[optind
++]))
21758 free (cmdline
.dump_sects
);
21760 free (dump_ctf_symtab_name
);
21761 free (dump_ctf_strtab_name
);
21762 free (dump_ctf_parent_name
);
21764 return err
? EXIT_FAILURE
: EXIT_SUCCESS
;