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 bool show_name
= false;
216 static bool do_dynamic
= false;
217 static bool do_syms
= false;
218 static bool do_dyn_syms
= false;
219 static bool do_lto_syms
= false;
220 static bool do_reloc
= false;
221 static bool do_sections
= false;
222 static bool do_section_groups
= false;
223 static bool do_section_details
= false;
224 static bool do_segments
= false;
225 static bool do_unwind
= false;
226 static bool do_using_dynamic
= false;
227 static bool do_header
= false;
228 static bool do_dump
= false;
229 static bool do_version
= false;
230 static bool do_histogram
= false;
231 static bool do_debugging
= false;
232 static bool do_ctf
= false;
233 static bool do_arch
= false;
234 static bool do_notes
= false;
235 static bool do_archive_index
= false;
236 static bool check_all
= false;
237 static bool is_32bit_elf
= false;
238 static bool decompress_dumps
= false;
239 static bool do_not_show_symbol_truncation
= false;
240 static bool do_demangle
= false; /* Pretty print C++ symbol names. */
241 static bool 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
;
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
*, bool, 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 bool extra_padding
= false;
563 bool 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
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
);
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
,
1223 Elf_Internal_Rela
* rels
;
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";
2552 case EM_INTELGT
: return "Intel Graphics Technology";
2554 case EM_KM32
: return "KM211 KM32 32-bit processor";
2555 case EM_KMX32
: return "KM211 KMX32 32-bit processor";
2556 case EM_KMX16
: return "KM211 KMX16 16-bit processor";
2557 case EM_KMX8
: return "KM211 KMX8 8-bit processor";
2558 case EM_KVARC
: return "KM211 KVARC processor";
2559 case EM_CDP
: return "Paneve CDP architecture family";
2560 case EM_COGE
: return "Cognitive Smart Memory Processor";
2561 case EM_COOL
: return "Bluechip Systems CoolEngine";
2562 case EM_NORC
: return "Nanoradio Optimized RISC";
2563 case EM_CSR_KALIMBA
: return "CSR Kalimba architecture family";
2565 case EM_Z80
: return "Zilog Z80";
2566 case EM_VISIUM
: return "CDS VISIUMcore processor";
2567 case EM_FT32
: return "FTDI Chip FT32";
2568 case EM_MOXIE
: return "Moxie";
2569 case EM_AMDGPU
: return "AMD GPU";
2570 /* 230 (all reserved) */
2572 case EM_RISCV
: return "RISC-V";
2573 case EM_LANAI
: return "Lanai 32-bit processor";
2574 case EM_CEVA
: return "CEVA Processor Architecture Family";
2575 case EM_CEVA_X2
: return "CEVA X2 Processor Family";
2576 case EM_BPF
: return "Linux BPF";
2577 case EM_GRAPHCORE_IPU
: return "Graphcore Intelligent Processing Unit";
2578 case EM_IMG1
: return "Imagination Technologies";
2580 case EM_NFP
: return "Netronome Flow Processor";
2581 case EM_VE
: return "NEC Vector Engine";
2582 case EM_CSKY
: return "C-SKY";
2583 case EM_ARC_COMPACT3_64
: return "Synopsys ARCv2.3 64-bit";
2584 case EM_MCS6502
: return "MOS Technology MCS 6502 processor";
2585 case EM_ARC_COMPACT3
: return "Synopsys ARCv2.3 32-bit";
2586 case EM_KVX
: return "Kalray VLIW core of the MPPA processor family";
2587 case EM_65816
: return "WDC 65816/65C816";
2588 case EM_LOONGARCH
: return "Loongson Loongarch";
2589 case EM_KF32
: return "ChipON KungFu32";
2591 /* Large numbers... */
2592 case EM_MT
: return "Morpho Techologies MT processor";
2593 case EM_ALPHA
: return "Alpha";
2594 case EM_WEBASSEMBLY
: return "Web Assembly";
2595 case EM_DLX
: return "OpenDLX";
2596 case EM_XSTORMY16
: return "Sanyo XStormy16 CPU core";
2597 case EM_IQ2000
: return "Vitesse IQ2000";
2599 case EM_NIOS32
: return "Altera Nios";
2600 case EM_CYGNUS_MEP
: return "Toshiba MeP Media Engine";
2601 case EM_ADAPTEVA_EPIPHANY
: return "Adapteva EPIPHANY";
2602 case EM_CYGNUS_FRV
: return "Fujitsu FR-V";
2603 case EM_S12Z
: return "Freescale S12Z";
2606 snprintf (buff
, sizeof (buff
), _("<unknown>: 0x%x"), e_machine
);
2612 decode_ARC_machine_flags (unsigned e_flags
, unsigned e_machine
, char buf
[])
2614 /* ARC has two machine types EM_ARC_COMPACT and EM_ARC_COMPACT2. Some
2615 other compilers don't specify an architecture type in the e_flags, and
2616 instead use EM_ARC_COMPACT for old ARC600, ARC601, and ARC700
2617 architectures, and switch to EM_ARC_COMPACT2 for newer ARCEM and ARCHS
2620 Th GNU tools follows this use of EM_ARC_COMPACT and EM_ARC_COMPACT2,
2621 but also sets a specific architecture type in the e_flags field.
2623 However, when decoding the flags we don't worry if we see an
2624 unexpected pairing, for example EM_ARC_COMPACT machine type, with
2625 ARCEM architecture type. */
2627 switch (e_flags
& EF_ARC_MACH_MSK
)
2629 /* We only expect these to occur for EM_ARC_COMPACT2. */
2630 case EF_ARC_CPU_ARCV2EM
:
2631 strcat (buf
, ", ARC EM");
2633 case EF_ARC_CPU_ARCV2HS
:
2634 strcat (buf
, ", ARC HS");
2637 /* We only expect these to occur for EM_ARC_COMPACT. */
2638 case E_ARC_MACH_ARC600
:
2639 strcat (buf
, ", ARC600");
2641 case E_ARC_MACH_ARC601
:
2642 strcat (buf
, ", ARC601");
2644 case E_ARC_MACH_ARC700
:
2645 strcat (buf
, ", ARC700");
2648 /* The only times we should end up here are (a) A corrupt ELF, (b) A
2649 new ELF with new architecture being read by an old version of
2650 readelf, or (c) An ELF built with non-GNU compiler that does not
2651 set the architecture in the e_flags. */
2653 if (e_machine
== EM_ARC_COMPACT
)
2654 strcat (buf
, ", Unknown ARCompact");
2656 strcat (buf
, ", Unknown ARC");
2660 switch (e_flags
& EF_ARC_OSABI_MSK
)
2662 case E_ARC_OSABI_ORIG
:
2663 strcat (buf
, ", (ABI:legacy)");
2665 case E_ARC_OSABI_V2
:
2666 strcat (buf
, ", (ABI:v2)");
2668 /* Only upstream 3.9+ kernels will support ARCv2 ISA. */
2669 case E_ARC_OSABI_V3
:
2670 strcat (buf
, ", v3 no-legacy-syscalls ABI");
2672 case E_ARC_OSABI_V4
:
2673 strcat (buf
, ", v4 ABI");
2676 strcat (buf
, ", unrecognised ARC OSABI flag");
2682 decode_ARM_machine_flags (unsigned e_flags
, char buf
[])
2685 bool unknown
= false;
2687 eabi
= EF_ARM_EABI_VERSION (e_flags
);
2688 e_flags
&= ~ EF_ARM_EABIMASK
;
2690 /* Handle "generic" ARM flags. */
2691 if (e_flags
& EF_ARM_RELEXEC
)
2693 strcat (buf
, ", relocatable executable");
2694 e_flags
&= ~ EF_ARM_RELEXEC
;
2697 if (e_flags
& EF_ARM_PIC
)
2699 strcat (buf
, ", position independent");
2700 e_flags
&= ~ EF_ARM_PIC
;
2703 /* Now handle EABI specific flags. */
2707 strcat (buf
, ", <unrecognized EABI>");
2712 case EF_ARM_EABI_VER1
:
2713 strcat (buf
, ", Version1 EABI");
2718 /* Process flags one bit at a time. */
2719 flag
= e_flags
& - e_flags
;
2724 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
2725 strcat (buf
, ", sorted symbol tables");
2735 case EF_ARM_EABI_VER2
:
2736 strcat (buf
, ", Version2 EABI");
2741 /* Process flags one bit at a time. */
2742 flag
= e_flags
& - e_flags
;
2747 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
2748 strcat (buf
, ", sorted symbol tables");
2751 case EF_ARM_DYNSYMSUSESEGIDX
:
2752 strcat (buf
, ", dynamic symbols use segment index");
2755 case EF_ARM_MAPSYMSFIRST
:
2756 strcat (buf
, ", mapping symbols precede others");
2766 case EF_ARM_EABI_VER3
:
2767 strcat (buf
, ", Version3 EABI");
2770 case EF_ARM_EABI_VER4
:
2771 strcat (buf
, ", Version4 EABI");
2776 /* Process flags one bit at a time. */
2777 flag
= e_flags
& - e_flags
;
2783 strcat (buf
, ", BE8");
2787 strcat (buf
, ", LE8");
2797 case EF_ARM_EABI_VER5
:
2798 strcat (buf
, ", Version5 EABI");
2803 /* Process flags one bit at a time. */
2804 flag
= e_flags
& - e_flags
;
2810 strcat (buf
, ", BE8");
2814 strcat (buf
, ", LE8");
2817 case EF_ARM_ABI_FLOAT_SOFT
: /* Conflicts with EF_ARM_SOFT_FLOAT. */
2818 strcat (buf
, ", soft-float ABI");
2821 case EF_ARM_ABI_FLOAT_HARD
: /* Conflicts with EF_ARM_VFP_FLOAT. */
2822 strcat (buf
, ", hard-float ABI");
2832 case EF_ARM_EABI_UNKNOWN
:
2833 strcat (buf
, ", GNU EABI");
2838 /* Process flags one bit at a time. */
2839 flag
= e_flags
& - e_flags
;
2844 case EF_ARM_INTERWORK
:
2845 strcat (buf
, ", interworking enabled");
2848 case EF_ARM_APCS_26
:
2849 strcat (buf
, ", uses APCS/26");
2852 case EF_ARM_APCS_FLOAT
:
2853 strcat (buf
, ", uses APCS/float");
2857 strcat (buf
, ", position independent");
2861 strcat (buf
, ", 8 bit structure alignment");
2864 case EF_ARM_NEW_ABI
:
2865 strcat (buf
, ", uses new ABI");
2868 case EF_ARM_OLD_ABI
:
2869 strcat (buf
, ", uses old ABI");
2872 case EF_ARM_SOFT_FLOAT
:
2873 strcat (buf
, ", software FP");
2876 case EF_ARM_VFP_FLOAT
:
2877 strcat (buf
, ", VFP");
2880 case EF_ARM_MAVERICK_FLOAT
:
2881 strcat (buf
, ", Maverick FP");
2892 strcat (buf
,_(", <unknown>"));
2896 decode_AVR_machine_flags (unsigned e_flags
, char buf
[], size_t size
)
2898 --size
; /* Leave space for null terminator. */
2900 switch (e_flags
& EF_AVR_MACH
)
2902 case E_AVR_MACH_AVR1
:
2903 strncat (buf
, ", avr:1", size
);
2905 case E_AVR_MACH_AVR2
:
2906 strncat (buf
, ", avr:2", size
);
2908 case E_AVR_MACH_AVR25
:
2909 strncat (buf
, ", avr:25", size
);
2911 case E_AVR_MACH_AVR3
:
2912 strncat (buf
, ", avr:3", size
);
2914 case E_AVR_MACH_AVR31
:
2915 strncat (buf
, ", avr:31", size
);
2917 case E_AVR_MACH_AVR35
:
2918 strncat (buf
, ", avr:35", size
);
2920 case E_AVR_MACH_AVR4
:
2921 strncat (buf
, ", avr:4", size
);
2923 case E_AVR_MACH_AVR5
:
2924 strncat (buf
, ", avr:5", size
);
2926 case E_AVR_MACH_AVR51
:
2927 strncat (buf
, ", avr:51", size
);
2929 case E_AVR_MACH_AVR6
:
2930 strncat (buf
, ", avr:6", size
);
2932 case E_AVR_MACH_AVRTINY
:
2933 strncat (buf
, ", avr:100", size
);
2935 case E_AVR_MACH_XMEGA1
:
2936 strncat (buf
, ", avr:101", size
);
2938 case E_AVR_MACH_XMEGA2
:
2939 strncat (buf
, ", avr:102", size
);
2941 case E_AVR_MACH_XMEGA3
:
2942 strncat (buf
, ", avr:103", size
);
2944 case E_AVR_MACH_XMEGA4
:
2945 strncat (buf
, ", avr:104", size
);
2947 case E_AVR_MACH_XMEGA5
:
2948 strncat (buf
, ", avr:105", size
);
2950 case E_AVR_MACH_XMEGA6
:
2951 strncat (buf
, ", avr:106", size
);
2953 case E_AVR_MACH_XMEGA7
:
2954 strncat (buf
, ", avr:107", size
);
2957 strncat (buf
, ", avr:<unknown>", size
);
2961 size
-= strlen (buf
);
2962 if (e_flags
& EF_AVR_LINKRELAX_PREPARED
)
2963 strncat (buf
, ", link-relax", size
);
2967 decode_NDS32_machine_flags (unsigned e_flags
, char buf
[], size_t size
)
2973 bool has_fpu
= false;
2976 static const char *ABI_STRINGS
[] =
2978 "ABI v0", /* use r5 as return register; only used in N1213HC */
2979 "ABI v1", /* use r0 as return register */
2980 "ABI v2", /* use r0 as return register and don't reserve 24 bytes for arguments */
2981 "ABI v2fp", /* for FPU */
2985 static const char *VER_STRINGS
[] =
2987 "Andes ELF V1.3 or older",
2991 static const char *ARCH_STRINGS
[] =
3000 abi
= EF_NDS_ABI
& e_flags
;
3001 arch
= EF_NDS_ARCH
& e_flags
;
3002 config
= EF_NDS_INST
& e_flags
;
3003 version
= EF_NDS32_ELF_VERSION
& e_flags
;
3005 memset (buf
, 0, size
);
3012 case E_NDS_ABI_V2FP
:
3013 case E_NDS_ABI_AABI
:
3014 case E_NDS_ABI_V2FP_PLUS
:
3015 /* In case there are holes in the array. */
3016 r
+= snprintf (buf
+ r
, size
- r
, ", %s", ABI_STRINGS
[abi
>> EF_NDS_ABI_SHIFT
]);
3020 r
+= snprintf (buf
+ r
, size
- r
, ", <unrecognized ABI>");
3026 case E_NDS32_ELF_VER_1_2
:
3027 case E_NDS32_ELF_VER_1_3
:
3028 case E_NDS32_ELF_VER_1_4
:
3029 r
+= snprintf (buf
+ r
, size
- r
, ", %s", VER_STRINGS
[version
>> EF_NDS32_ELF_VERSION_SHIFT
]);
3033 r
+= snprintf (buf
+ r
, size
- r
, ", <unrecognized ELF version number>");
3037 if (E_NDS_ABI_V0
== abi
)
3039 /* OLD ABI; only used in N1213HC, has performance extension 1. */
3040 r
+= snprintf (buf
+ r
, size
- r
, ", Andes Star v1.0, N1213HC, MAC, PERF1");
3041 if (arch
== E_NDS_ARCH_STAR_V1_0
)
3042 r
+= snprintf (buf
+ r
, size
-r
, ", 16b"); /* has 16-bit instructions */
3048 case E_NDS_ARCH_STAR_V1_0
:
3049 case E_NDS_ARCH_STAR_V2_0
:
3050 case E_NDS_ARCH_STAR_V3_0
:
3051 case E_NDS_ARCH_STAR_V3_M
:
3052 r
+= snprintf (buf
+ r
, size
- r
, ", %s", ARCH_STRINGS
[arch
>> EF_NDS_ARCH_SHIFT
]);
3056 r
+= snprintf (buf
+ r
, size
- r
, ", <unrecognized architecture>");
3057 /* ARCH version determines how the e_flags are interpreted.
3058 If it is unknown, we cannot proceed. */
3062 /* Newer ABI; Now handle architecture specific flags. */
3063 if (arch
== E_NDS_ARCH_STAR_V1_0
)
3065 if (config
& E_NDS32_HAS_MFUSR_PC_INST
)
3066 r
+= snprintf (buf
+ r
, size
-r
, ", MFUSR_PC");
3068 if (!(config
& E_NDS32_HAS_NO_MAC_INST
))
3069 r
+= snprintf (buf
+ r
, size
-r
, ", MAC");
3071 if (config
& E_NDS32_HAS_DIV_INST
)
3072 r
+= snprintf (buf
+ r
, size
-r
, ", DIV");
3074 if (config
& E_NDS32_HAS_16BIT_INST
)
3075 r
+= snprintf (buf
+ r
, size
-r
, ", 16b");
3079 if (config
& E_NDS32_HAS_MFUSR_PC_INST
)
3081 if (version
<= E_NDS32_ELF_VER_1_3
)
3082 r
+= snprintf (buf
+ r
, size
-r
, ", [B8]");
3084 r
+= snprintf (buf
+ r
, size
-r
, ", EX9");
3087 if (config
& E_NDS32_HAS_MAC_DX_INST
)
3088 r
+= snprintf (buf
+ r
, size
-r
, ", MAC_DX");
3090 if (config
& E_NDS32_HAS_DIV_DX_INST
)
3091 r
+= snprintf (buf
+ r
, size
-r
, ", DIV_DX");
3093 if (config
& E_NDS32_HAS_16BIT_INST
)
3095 if (version
<= E_NDS32_ELF_VER_1_3
)
3096 r
+= snprintf (buf
+ r
, size
-r
, ", 16b");
3098 r
+= snprintf (buf
+ r
, size
-r
, ", IFC");
3102 if (config
& E_NDS32_HAS_EXT_INST
)
3103 r
+= snprintf (buf
+ r
, size
-r
, ", PERF1");
3105 if (config
& E_NDS32_HAS_EXT2_INST
)
3106 r
+= snprintf (buf
+ r
, size
-r
, ", PERF2");
3108 if (config
& E_NDS32_HAS_FPU_INST
)
3111 r
+= snprintf (buf
+ r
, size
-r
, ", FPU_SP");
3114 if (config
& E_NDS32_HAS_FPU_DP_INST
)
3117 r
+= snprintf (buf
+ r
, size
-r
, ", FPU_DP");
3120 if (config
& E_NDS32_HAS_FPU_MAC_INST
)
3123 r
+= snprintf (buf
+ r
, size
-r
, ", FPU_MAC");
3128 switch ((config
& E_NDS32_FPU_REG_CONF
) >> E_NDS32_FPU_REG_CONF_SHIFT
)
3130 case E_NDS32_FPU_REG_8SP_4DP
:
3131 r
+= snprintf (buf
+ r
, size
-r
, ", FPU_REG:8/4");
3133 case E_NDS32_FPU_REG_16SP_8DP
:
3134 r
+= snprintf (buf
+ r
, size
-r
, ", FPU_REG:16/8");
3136 case E_NDS32_FPU_REG_32SP_16DP
:
3137 r
+= snprintf (buf
+ r
, size
-r
, ", FPU_REG:32/16");
3139 case E_NDS32_FPU_REG_32SP_32DP
:
3140 r
+= snprintf (buf
+ r
, size
-r
, ", FPU_REG:32/32");
3145 if (config
& E_NDS32_HAS_AUDIO_INST
)
3146 r
+= snprintf (buf
+ r
, size
-r
, ", AUDIO");
3148 if (config
& E_NDS32_HAS_STRING_INST
)
3149 r
+= snprintf (buf
+ r
, size
-r
, ", STR");
3151 if (config
& E_NDS32_HAS_REDUCED_REGS
)
3152 r
+= snprintf (buf
+ r
, size
-r
, ", 16REG");
3154 if (config
& E_NDS32_HAS_VIDEO_INST
)
3156 if (version
<= E_NDS32_ELF_VER_1_3
)
3157 r
+= snprintf (buf
+ r
, size
-r
, ", VIDEO");
3159 r
+= snprintf (buf
+ r
, size
-r
, ", SATURATION");
3162 if (config
& E_NDS32_HAS_ENCRIPT_INST
)
3163 r
+= snprintf (buf
+ r
, size
-r
, ", ENCRP");
3165 if (config
& E_NDS32_HAS_L2C_INST
)
3166 r
+= snprintf (buf
+ r
, size
-r
, ", L2C");
3170 get_machine_flags (Filedata
* filedata
, unsigned e_flags
, unsigned e_machine
)
3172 static char buf
[1024];
3183 case EM_ARC_COMPACT2
:
3184 case EM_ARC_COMPACT
:
3185 decode_ARC_machine_flags (e_flags
, e_machine
, buf
);
3189 decode_ARM_machine_flags (e_flags
, buf
);
3193 decode_AVR_machine_flags (e_flags
, buf
, sizeof buf
);
3197 if (e_flags
& EF_BFIN_PIC
)
3198 strcat (buf
, ", PIC");
3200 if (e_flags
& EF_BFIN_FDPIC
)
3201 strcat (buf
, ", FDPIC");
3203 if (e_flags
& EF_BFIN_CODE_IN_L1
)
3204 strcat (buf
, ", code in L1");
3206 if (e_flags
& EF_BFIN_DATA_IN_L1
)
3207 strcat (buf
, ", data in L1");
3212 switch (e_flags
& EF_FRV_CPU_MASK
)
3214 case EF_FRV_CPU_GENERIC
:
3218 strcat (buf
, ", fr???");
3221 case EF_FRV_CPU_FR300
:
3222 strcat (buf
, ", fr300");
3225 case EF_FRV_CPU_FR400
:
3226 strcat (buf
, ", fr400");
3228 case EF_FRV_CPU_FR405
:
3229 strcat (buf
, ", fr405");
3232 case EF_FRV_CPU_FR450
:
3233 strcat (buf
, ", fr450");
3236 case EF_FRV_CPU_FR500
:
3237 strcat (buf
, ", fr500");
3239 case EF_FRV_CPU_FR550
:
3240 strcat (buf
, ", fr550");
3243 case EF_FRV_CPU_SIMPLE
:
3244 strcat (buf
, ", simple");
3246 case EF_FRV_CPU_TOMCAT
:
3247 strcat (buf
, ", tomcat");
3253 if ((e_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_M68000
)
3254 strcat (buf
, ", m68000");
3255 else if ((e_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_CPU32
)
3256 strcat (buf
, ", cpu32");
3257 else if ((e_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_FIDO
)
3258 strcat (buf
, ", fido_a");
3261 char const * isa
= _("unknown");
3262 char const * mac
= _("unknown mac");
3263 char const * additional
= NULL
;
3265 switch (e_flags
& EF_M68K_CF_ISA_MASK
)
3267 case EF_M68K_CF_ISA_A_NODIV
:
3269 additional
= ", nodiv";
3271 case EF_M68K_CF_ISA_A
:
3274 case EF_M68K_CF_ISA_A_PLUS
:
3277 case EF_M68K_CF_ISA_B_NOUSP
:
3279 additional
= ", nousp";
3281 case EF_M68K_CF_ISA_B
:
3284 case EF_M68K_CF_ISA_C
:
3287 case EF_M68K_CF_ISA_C_NODIV
:
3289 additional
= ", nodiv";
3292 strcat (buf
, ", cf, isa ");
3295 strcat (buf
, additional
);
3296 if (e_flags
& EF_M68K_CF_FLOAT
)
3297 strcat (buf
, ", float");
3298 switch (e_flags
& EF_M68K_CF_MAC_MASK
)
3303 case EF_M68K_CF_MAC
:
3306 case EF_M68K_CF_EMAC
:
3309 case EF_M68K_CF_EMAC_B
:
3322 switch (e_flags
& EF_MEP_CPU_MASK
)
3324 case EF_MEP_CPU_MEP
: strcat (buf
, ", generic MeP"); break;
3325 case EF_MEP_CPU_C2
: strcat (buf
, ", MeP C2"); break;
3326 case EF_MEP_CPU_C3
: strcat (buf
, ", MeP C3"); break;
3327 case EF_MEP_CPU_C4
: strcat (buf
, ", MeP C4"); break;
3328 case EF_MEP_CPU_C5
: strcat (buf
, ", MeP C5"); break;
3329 case EF_MEP_CPU_H1
: strcat (buf
, ", MeP H1"); break;
3330 default: strcat (buf
, _(", <unknown MeP cpu type>")); break;
3333 switch (e_flags
& EF_MEP_COP_MASK
)
3335 case EF_MEP_COP_NONE
: break;
3336 case EF_MEP_COP_AVC
: strcat (buf
, ", AVC coprocessor"); break;
3337 case EF_MEP_COP_AVC2
: strcat (buf
, ", AVC2 coprocessor"); break;
3338 case EF_MEP_COP_FMAX
: strcat (buf
, ", FMAX coprocessor"); break;
3339 case EF_MEP_COP_IVC2
: strcat (buf
, ", IVC2 coprocessor"); break;
3340 default: strcat (buf
, _("<unknown MeP copro type>")); break;
3343 if (e_flags
& EF_MEP_LIBRARY
)
3344 strcat (buf
, ", Built for Library");
3346 if (e_flags
& EF_MEP_INDEX_MASK
)
3347 sprintf (buf
+ strlen (buf
), ", Configuration Index: %#x",
3348 e_flags
& EF_MEP_INDEX_MASK
);
3350 if (e_flags
& ~ EF_MEP_ALL_FLAGS
)
3351 sprintf (buf
+ strlen (buf
), _(", unknown flags bits: %#x"),
3352 e_flags
& ~ EF_MEP_ALL_FLAGS
);
3356 if (e_flags
& EF_PPC_EMB
)
3357 strcat (buf
, ", emb");
3359 if (e_flags
& EF_PPC_RELOCATABLE
)
3360 strcat (buf
, _(", relocatable"));
3362 if (e_flags
& EF_PPC_RELOCATABLE_LIB
)
3363 strcat (buf
, _(", relocatable-lib"));
3367 if (e_flags
& EF_PPC64_ABI
)
3369 char abi
[] = ", abiv0";
3371 abi
[6] += e_flags
& EF_PPC64_ABI
;
3377 if ((e_flags
& EF_RH850_ABI
) == EF_RH850_ABI
)
3378 strcat (buf
, ", RH850 ABI");
3380 if (e_flags
& EF_V800_850E3
)
3381 strcat (buf
, ", V3 architecture");
3383 if ((e_flags
& (EF_RH850_FPU_DOUBLE
| EF_RH850_FPU_SINGLE
)) == 0)
3384 strcat (buf
, ", FPU not used");
3386 if ((e_flags
& (EF_RH850_REGMODE22
| EF_RH850_REGMODE32
)) == 0)
3387 strcat (buf
, ", regmode: COMMON");
3389 if ((e_flags
& (EF_RH850_GP_FIX
| EF_RH850_GP_NOFIX
)) == 0)
3390 strcat (buf
, ", r4 not used");
3392 if ((e_flags
& (EF_RH850_EP_FIX
| EF_RH850_EP_NOFIX
)) == 0)
3393 strcat (buf
, ", r30 not used");
3395 if ((e_flags
& (EF_RH850_TP_FIX
| EF_RH850_TP_NOFIX
)) == 0)
3396 strcat (buf
, ", r5 not used");
3398 if ((e_flags
& (EF_RH850_REG2_RESERVE
| EF_RH850_REG2_NORESERVE
)) == 0)
3399 strcat (buf
, ", r2 not used");
3401 for (e_flags
&= 0xFFFF; e_flags
; e_flags
&= ~ (e_flags
& - e_flags
))
3403 switch (e_flags
& - e_flags
)
3405 case EF_RH850_FPU_DOUBLE
: strcat (buf
, ", double precision FPU"); break;
3406 case EF_RH850_FPU_SINGLE
: strcat (buf
, ", single precision FPU"); break;
3407 case EF_RH850_REGMODE22
: strcat (buf
, ", regmode:22"); break;
3408 case EF_RH850_REGMODE32
: strcat (buf
, ", regmode:23"); break;
3409 case EF_RH850_GP_FIX
: strcat (buf
, ", r4 fixed"); break;
3410 case EF_RH850_GP_NOFIX
: strcat (buf
, ", r4 free"); break;
3411 case EF_RH850_EP_FIX
: strcat (buf
, ", r30 fixed"); break;
3412 case EF_RH850_EP_NOFIX
: strcat (buf
, ", r30 free"); break;
3413 case EF_RH850_TP_FIX
: strcat (buf
, ", r5 fixed"); break;
3414 case EF_RH850_TP_NOFIX
: strcat (buf
, ", r5 free"); break;
3415 case EF_RH850_REG2_RESERVE
: strcat (buf
, ", r2 fixed"); break;
3416 case EF_RH850_REG2_NORESERVE
: strcat (buf
, ", r2 free"); break;
3423 case EM_CYGNUS_V850
:
3424 switch (e_flags
& EF_V850_ARCH
)
3426 case E_V850E3V5_ARCH
:
3427 strcat (buf
, ", v850e3v5");
3429 case E_V850E2V3_ARCH
:
3430 strcat (buf
, ", v850e2v3");
3433 strcat (buf
, ", v850e2");
3436 strcat (buf
, ", v850e1");
3439 strcat (buf
, ", v850e");
3442 strcat (buf
, ", v850");
3445 strcat (buf
, _(", unknown v850 architecture variant"));
3451 case EM_CYGNUS_M32R
:
3452 if ((e_flags
& EF_M32R_ARCH
) == E_M32R_ARCH
)
3453 strcat (buf
, ", m32r");
3457 case EM_MIPS_RS3_LE
:
3458 if (e_flags
& EF_MIPS_NOREORDER
)
3459 strcat (buf
, ", noreorder");
3461 if (e_flags
& EF_MIPS_PIC
)
3462 strcat (buf
, ", pic");
3464 if (e_flags
& EF_MIPS_CPIC
)
3465 strcat (buf
, ", cpic");
3467 if (e_flags
& EF_MIPS_UCODE
)
3468 strcat (buf
, ", ugen_reserved");
3470 if (e_flags
& EF_MIPS_ABI2
)
3471 strcat (buf
, ", abi2");
3473 if (e_flags
& EF_MIPS_OPTIONS_FIRST
)
3474 strcat (buf
, ", odk first");
3476 if (e_flags
& EF_MIPS_32BITMODE
)
3477 strcat (buf
, ", 32bitmode");
3479 if (e_flags
& EF_MIPS_NAN2008
)
3480 strcat (buf
, ", nan2008");
3482 if (e_flags
& EF_MIPS_FP64
)
3483 strcat (buf
, ", fp64");
3485 switch ((e_flags
& EF_MIPS_MACH
))
3487 case E_MIPS_MACH_3900
: strcat (buf
, ", 3900"); break;
3488 case E_MIPS_MACH_4010
: strcat (buf
, ", 4010"); break;
3489 case E_MIPS_MACH_4100
: strcat (buf
, ", 4100"); break;
3490 case E_MIPS_MACH_4111
: strcat (buf
, ", 4111"); break;
3491 case E_MIPS_MACH_4120
: strcat (buf
, ", 4120"); break;
3492 case E_MIPS_MACH_4650
: strcat (buf
, ", 4650"); break;
3493 case E_MIPS_MACH_5400
: strcat (buf
, ", 5400"); break;
3494 case E_MIPS_MACH_5500
: strcat (buf
, ", 5500"); break;
3495 case E_MIPS_MACH_5900
: strcat (buf
, ", 5900"); break;
3496 case E_MIPS_MACH_SB1
: strcat (buf
, ", sb1"); break;
3497 case E_MIPS_MACH_9000
: strcat (buf
, ", 9000"); break;
3498 case E_MIPS_MACH_LS2E
: strcat (buf
, ", loongson-2e"); break;
3499 case E_MIPS_MACH_LS2F
: strcat (buf
, ", loongson-2f"); break;
3500 case E_MIPS_MACH_GS464
: strcat (buf
, ", gs464"); break;
3501 case E_MIPS_MACH_GS464E
: strcat (buf
, ", gs464e"); break;
3502 case E_MIPS_MACH_GS264E
: strcat (buf
, ", gs264e"); break;
3503 case E_MIPS_MACH_OCTEON
: strcat (buf
, ", octeon"); break;
3504 case E_MIPS_MACH_OCTEON2
: strcat (buf
, ", octeon2"); break;
3505 case E_MIPS_MACH_OCTEON3
: strcat (buf
, ", octeon3"); break;
3506 case E_MIPS_MACH_XLR
: strcat (buf
, ", xlr"); break;
3507 case E_MIPS_MACH_IAMR2
: strcat (buf
, ", interaptiv-mr2"); break;
3509 /* We simply ignore the field in this case to avoid confusion:
3510 MIPS ELF does not specify EF_MIPS_MACH, it is a GNU
3513 default: strcat (buf
, _(", unknown CPU")); break;
3516 switch ((e_flags
& EF_MIPS_ABI
))
3518 case E_MIPS_ABI_O32
: strcat (buf
, ", o32"); break;
3519 case E_MIPS_ABI_O64
: strcat (buf
, ", o64"); break;
3520 case E_MIPS_ABI_EABI32
: strcat (buf
, ", eabi32"); break;
3521 case E_MIPS_ABI_EABI64
: strcat (buf
, ", eabi64"); break;
3523 /* We simply ignore the field in this case to avoid confusion:
3524 MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension.
3525 This means it is likely to be an o32 file, but not for
3528 default: strcat (buf
, _(", unknown ABI")); break;
3531 if (e_flags
& EF_MIPS_ARCH_ASE_MDMX
)
3532 strcat (buf
, ", mdmx");
3534 if (e_flags
& EF_MIPS_ARCH_ASE_M16
)
3535 strcat (buf
, ", mips16");
3537 if (e_flags
& EF_MIPS_ARCH_ASE_MICROMIPS
)
3538 strcat (buf
, ", micromips");
3540 switch ((e_flags
& EF_MIPS_ARCH
))
3542 case E_MIPS_ARCH_1
: strcat (buf
, ", mips1"); break;
3543 case E_MIPS_ARCH_2
: strcat (buf
, ", mips2"); break;
3544 case E_MIPS_ARCH_3
: strcat (buf
, ", mips3"); break;
3545 case E_MIPS_ARCH_4
: strcat (buf
, ", mips4"); break;
3546 case E_MIPS_ARCH_5
: strcat (buf
, ", mips5"); break;
3547 case E_MIPS_ARCH_32
: strcat (buf
, ", mips32"); break;
3548 case E_MIPS_ARCH_32R2
: strcat (buf
, ", mips32r2"); break;
3549 case E_MIPS_ARCH_32R6
: strcat (buf
, ", mips32r6"); break;
3550 case E_MIPS_ARCH_64
: strcat (buf
, ", mips64"); break;
3551 case E_MIPS_ARCH_64R2
: strcat (buf
, ", mips64r2"); break;
3552 case E_MIPS_ARCH_64R6
: strcat (buf
, ", mips64r6"); break;
3553 default: strcat (buf
, _(", unknown ISA")); break;
3558 decode_NDS32_machine_flags (e_flags
, buf
, sizeof buf
);
3562 switch (EF_NFP_MACH (e_flags
))
3564 case E_NFP_MACH_3200
:
3565 strcat (buf
, ", NFP-32xx");
3567 case E_NFP_MACH_6000
:
3568 strcat (buf
, ", NFP-6xxx");
3574 if (e_flags
& EF_RISCV_RVC
)
3575 strcat (buf
, ", RVC");
3577 if (e_flags
& EF_RISCV_RVE
)
3578 strcat (buf
, ", RVE");
3580 switch (e_flags
& EF_RISCV_FLOAT_ABI
)
3582 case EF_RISCV_FLOAT_ABI_SOFT
:
3583 strcat (buf
, ", soft-float ABI");
3586 case EF_RISCV_FLOAT_ABI_SINGLE
:
3587 strcat (buf
, ", single-float ABI");
3590 case EF_RISCV_FLOAT_ABI_DOUBLE
:
3591 strcat (buf
, ", double-float ABI");
3594 case EF_RISCV_FLOAT_ABI_QUAD
:
3595 strcat (buf
, ", quad-float ABI");
3601 switch ((e_flags
& EF_SH_MACH_MASK
))
3603 case EF_SH1
: strcat (buf
, ", sh1"); break;
3604 case EF_SH2
: strcat (buf
, ", sh2"); break;
3605 case EF_SH3
: strcat (buf
, ", sh3"); break;
3606 case EF_SH_DSP
: strcat (buf
, ", sh-dsp"); break;
3607 case EF_SH3_DSP
: strcat (buf
, ", sh3-dsp"); break;
3608 case EF_SH4AL_DSP
: strcat (buf
, ", sh4al-dsp"); break;
3609 case EF_SH3E
: strcat (buf
, ", sh3e"); break;
3610 case EF_SH4
: strcat (buf
, ", sh4"); break;
3611 case EF_SH5
: strcat (buf
, ", sh5"); break;
3612 case EF_SH2E
: strcat (buf
, ", sh2e"); break;
3613 case EF_SH4A
: strcat (buf
, ", sh4a"); break;
3614 case EF_SH2A
: strcat (buf
, ", sh2a"); break;
3615 case EF_SH4_NOFPU
: strcat (buf
, ", sh4-nofpu"); break;
3616 case EF_SH4A_NOFPU
: strcat (buf
, ", sh4a-nofpu"); break;
3617 case EF_SH2A_NOFPU
: strcat (buf
, ", sh2a-nofpu"); break;
3618 case EF_SH3_NOMMU
: strcat (buf
, ", sh3-nommu"); break;
3619 case EF_SH4_NOMMU_NOFPU
: strcat (buf
, ", sh4-nommu-nofpu"); break;
3620 case EF_SH2A_SH4_NOFPU
: strcat (buf
, ", sh2a-nofpu-or-sh4-nommu-nofpu"); break;
3621 case EF_SH2A_SH3_NOFPU
: strcat (buf
, ", sh2a-nofpu-or-sh3-nommu"); break;
3622 case EF_SH2A_SH4
: strcat (buf
, ", sh2a-or-sh4"); break;
3623 case EF_SH2A_SH3E
: strcat (buf
, ", sh2a-or-sh3e"); break;
3624 default: strcat (buf
, _(", unknown ISA")); break;
3627 if (e_flags
& EF_SH_PIC
)
3628 strcat (buf
, ", pic");
3630 if (e_flags
& EF_SH_FDPIC
)
3631 strcat (buf
, ", fdpic");
3635 if (e_flags
& EF_OR1K_NODELAY
)
3636 strcat (buf
, ", no delay");
3640 if (e_flags
& EF_SPARC_32PLUS
)
3641 strcat (buf
, ", v8+");
3643 if (e_flags
& EF_SPARC_SUN_US1
)
3644 strcat (buf
, ", ultrasparcI");
3646 if (e_flags
& EF_SPARC_SUN_US3
)
3647 strcat (buf
, ", ultrasparcIII");
3649 if (e_flags
& EF_SPARC_HAL_R1
)
3650 strcat (buf
, ", halr1");
3652 if (e_flags
& EF_SPARC_LEDATA
)
3653 strcat (buf
, ", ledata");
3655 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_TSO
)
3656 strcat (buf
, ", tso");
3658 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_PSO
)
3659 strcat (buf
, ", pso");
3661 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_RMO
)
3662 strcat (buf
, ", rmo");
3666 switch (e_flags
& EF_PARISC_ARCH
)
3668 case EFA_PARISC_1_0
:
3669 strcpy (buf
, ", PA-RISC 1.0");
3671 case EFA_PARISC_1_1
:
3672 strcpy (buf
, ", PA-RISC 1.1");
3674 case EFA_PARISC_2_0
:
3675 strcpy (buf
, ", PA-RISC 2.0");
3680 if (e_flags
& EF_PARISC_TRAPNIL
)
3681 strcat (buf
, ", trapnil");
3682 if (e_flags
& EF_PARISC_EXT
)
3683 strcat (buf
, ", ext");
3684 if (e_flags
& EF_PARISC_LSB
)
3685 strcat (buf
, ", lsb");
3686 if (e_flags
& EF_PARISC_WIDE
)
3687 strcat (buf
, ", wide");
3688 if (e_flags
& EF_PARISC_NO_KABP
)
3689 strcat (buf
, ", no kabp");
3690 if (e_flags
& EF_PARISC_LAZYSWAP
)
3691 strcat (buf
, ", lazyswap");
3696 if ((e_flags
& EF_PICOJAVA_NEWCALLS
) == EF_PICOJAVA_NEWCALLS
)
3697 strcat (buf
, ", new calling convention");
3699 if ((e_flags
& EF_PICOJAVA_GNUCALLS
) == EF_PICOJAVA_GNUCALLS
)
3700 strcat (buf
, ", gnu calling convention");
3704 if ((e_flags
& EF_IA_64_ABI64
))
3705 strcat (buf
, ", 64-bit");
3707 strcat (buf
, ", 32-bit");
3708 if ((e_flags
& EF_IA_64_REDUCEDFP
))
3709 strcat (buf
, ", reduced fp model");
3710 if ((e_flags
& EF_IA_64_NOFUNCDESC_CONS_GP
))
3711 strcat (buf
, ", no function descriptors, constant gp");
3712 else if ((e_flags
& EF_IA_64_CONS_GP
))
3713 strcat (buf
, ", constant gp");
3714 if ((e_flags
& EF_IA_64_ABSOLUTE
))
3715 strcat (buf
, ", absolute");
3716 if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_OPENVMS
)
3718 if ((e_flags
& EF_IA_64_VMS_LINKAGES
))
3719 strcat (buf
, ", vms_linkages");
3720 switch ((e_flags
& EF_IA_64_VMS_COMCOD
))
3722 case EF_IA_64_VMS_COMCOD_SUCCESS
:
3724 case EF_IA_64_VMS_COMCOD_WARNING
:
3725 strcat (buf
, ", warning");
3727 case EF_IA_64_VMS_COMCOD_ERROR
:
3728 strcat (buf
, ", error");
3730 case EF_IA_64_VMS_COMCOD_ABORT
:
3731 strcat (buf
, ", abort");
3734 warn (_("Unrecognised IA64 VMS Command Code: %x\n"),
3735 e_flags
& EF_IA_64_VMS_COMCOD
);
3736 strcat (buf
, ", <unknown>");
3742 if ((e_flags
& EF_VAX_NONPIC
))
3743 strcat (buf
, ", non-PIC");
3744 if ((e_flags
& EF_VAX_DFLOAT
))
3745 strcat (buf
, ", D-Float");
3746 if ((e_flags
& EF_VAX_GFLOAT
))
3747 strcat (buf
, ", G-Float");
3751 if (e_flags
& EF_VISIUM_ARCH_MCM
)
3752 strcat (buf
, ", mcm");
3753 else if (e_flags
& EF_VISIUM_ARCH_MCM24
)
3754 strcat (buf
, ", mcm24");
3755 if (e_flags
& EF_VISIUM_ARCH_GR6
)
3756 strcat (buf
, ", gr6");
3760 switch (e_flags
& E_FLAG_RL78_CPU_MASK
)
3762 case E_FLAG_RL78_ANY_CPU
: break;
3763 case E_FLAG_RL78_G10
: strcat (buf
, ", G10"); break;
3764 case E_FLAG_RL78_G13
: strcat (buf
, ", G13"); break;
3765 case E_FLAG_RL78_G14
: strcat (buf
, ", G14"); break;
3767 if (e_flags
& E_FLAG_RL78_64BIT_DOUBLES
)
3768 strcat (buf
, ", 64-bit doubles");
3772 if (e_flags
& E_FLAG_RX_64BIT_DOUBLES
)
3773 strcat (buf
, ", 64-bit doubles");
3774 if (e_flags
& E_FLAG_RX_DSP
)
3775 strcat (buf
, ", dsp");
3776 if (e_flags
& E_FLAG_RX_PID
)
3777 strcat (buf
, ", pid");
3778 if (e_flags
& E_FLAG_RX_ABI
)
3779 strcat (buf
, ", RX ABI");
3780 if (e_flags
& E_FLAG_RX_SINSNS_SET
)
3781 strcat (buf
, e_flags
& E_FLAG_RX_SINSNS_YES
3782 ? ", uses String instructions" : ", bans String instructions");
3783 if (e_flags
& E_FLAG_RX_V2
)
3784 strcat (buf
, ", V2");
3785 if (e_flags
& E_FLAG_RX_V3
)
3786 strcat (buf
, ", V3");
3790 if (e_flags
& EF_S390_HIGH_GPRS
)
3791 strcat (buf
, ", highgprs");
3795 if ((e_flags
& EF_C6000_REL
))
3796 strcat (buf
, ", relocatable module");
3800 strcat (buf
, _(": architecture variant: "));
3801 switch (e_flags
& EF_MSP430_MACH
)
3803 case E_MSP430_MACH_MSP430x11
: strcat (buf
, "MSP430x11"); break;
3804 case E_MSP430_MACH_MSP430x11x1
: strcat (buf
, "MSP430x11x1 "); break;
3805 case E_MSP430_MACH_MSP430x12
: strcat (buf
, "MSP430x12"); break;
3806 case E_MSP430_MACH_MSP430x13
: strcat (buf
, "MSP430x13"); break;
3807 case E_MSP430_MACH_MSP430x14
: strcat (buf
, "MSP430x14"); break;
3808 case E_MSP430_MACH_MSP430x15
: strcat (buf
, "MSP430x15"); break;
3809 case E_MSP430_MACH_MSP430x16
: strcat (buf
, "MSP430x16"); break;
3810 case E_MSP430_MACH_MSP430x31
: strcat (buf
, "MSP430x31"); break;
3811 case E_MSP430_MACH_MSP430x32
: strcat (buf
, "MSP430x32"); break;
3812 case E_MSP430_MACH_MSP430x33
: strcat (buf
, "MSP430x33"); break;
3813 case E_MSP430_MACH_MSP430x41
: strcat (buf
, "MSP430x41"); break;
3814 case E_MSP430_MACH_MSP430x42
: strcat (buf
, "MSP430x42"); break;
3815 case E_MSP430_MACH_MSP430x43
: strcat (buf
, "MSP430x43"); break;
3816 case E_MSP430_MACH_MSP430x44
: strcat (buf
, "MSP430x44"); break;
3817 case E_MSP430_MACH_MSP430X
: strcat (buf
, "MSP430X"); break;
3819 strcat (buf
, _(": unknown")); break;
3822 if (e_flags
& ~ EF_MSP430_MACH
)
3823 strcat (buf
, _(": unknown extra flag bits also present"));
3827 switch (e_flags
& EF_Z80_MACH_MSK
)
3829 case EF_Z80_MACH_Z80
: strcat (buf
, ", Z80"); break;
3830 case EF_Z80_MACH_Z180
: strcat (buf
, ", Z180"); break;
3831 case EF_Z80_MACH_R800
: strcat (buf
, ", R800"); break;
3832 case EF_Z80_MACH_EZ80_Z80
: strcat (buf
, ", EZ80"); break;
3833 case EF_Z80_MACH_EZ80_ADL
: strcat (buf
, ", EZ80, ADL"); break;
3834 case EF_Z80_MACH_GBZ80
: strcat (buf
, ", GBZ80"); break;
3835 case EF_Z80_MACH_Z80N
: strcat (buf
, ", Z80N"); break;
3837 strcat (buf
, _(", unknown")); break;
3847 get_osabi_name (Filedata
* filedata
, unsigned int osabi
)
3849 static char buff
[32];
3853 case ELFOSABI_NONE
: return "UNIX - System V";
3854 case ELFOSABI_HPUX
: return "UNIX - HP-UX";
3855 case ELFOSABI_NETBSD
: return "UNIX - NetBSD";
3856 case ELFOSABI_GNU
: return "UNIX - GNU";
3857 case ELFOSABI_SOLARIS
: return "UNIX - Solaris";
3858 case ELFOSABI_AIX
: return "UNIX - AIX";
3859 case ELFOSABI_IRIX
: return "UNIX - IRIX";
3860 case ELFOSABI_FREEBSD
: return "UNIX - FreeBSD";
3861 case ELFOSABI_TRU64
: return "UNIX - TRU64";
3862 case ELFOSABI_MODESTO
: return "Novell - Modesto";
3863 case ELFOSABI_OPENBSD
: return "UNIX - OpenBSD";
3864 case ELFOSABI_OPENVMS
: return "VMS - OpenVMS";
3865 case ELFOSABI_NSK
: return "HP - Non-Stop Kernel";
3866 case ELFOSABI_AROS
: return "AROS";
3867 case ELFOSABI_FENIXOS
: return "FenixOS";
3868 case ELFOSABI_CLOUDABI
: return "Nuxi CloudABI";
3869 case ELFOSABI_OPENVOS
: return "Stratus Technologies OpenVOS";
3872 switch (filedata
->file_header
.e_machine
)
3877 case ELFOSABI_ARM
: return "ARM";
3878 case ELFOSABI_ARM_FDPIC
: return "ARM FDPIC";
3889 case ELFOSABI_STANDALONE
: return _("Standalone App");
3898 case ELFOSABI_C6000_ELFABI
: return _("Bare-metal C6000");
3899 case ELFOSABI_C6000_LINUX
: return "Linux C6000";
3908 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), osabi
);
3914 get_aarch64_segment_type (unsigned long type
)
3918 case PT_AARCH64_ARCHEXT
: return "AARCH64_ARCHEXT";
3919 default: return NULL
;
3924 get_arm_segment_type (unsigned long type
)
3928 case PT_ARM_EXIDX
: return "EXIDX";
3929 default: return NULL
;
3934 get_s390_segment_type (unsigned long type
)
3938 case PT_S390_PGSTE
: return "S390_PGSTE";
3939 default: return NULL
;
3944 get_mips_segment_type (unsigned long type
)
3948 case PT_MIPS_REGINFO
: return "REGINFO";
3949 case PT_MIPS_RTPROC
: return "RTPROC";
3950 case PT_MIPS_OPTIONS
: return "OPTIONS";
3951 case PT_MIPS_ABIFLAGS
: return "ABIFLAGS";
3952 default: return NULL
;
3957 get_parisc_segment_type (unsigned long type
)
3961 case PT_PARISC_ARCHEXT
: return "PARISC_ARCHEXT";
3962 case PT_PARISC_UNWIND
: return "PARISC_UNWIND";
3963 case PT_PARISC_WEAKORDER
: return "PARISC_WEAKORDER";
3964 default: return NULL
;
3969 get_ia64_segment_type (unsigned long type
)
3973 case PT_IA_64_ARCHEXT
: return "IA_64_ARCHEXT";
3974 case PT_IA_64_UNWIND
: return "IA_64_UNWIND";
3975 default: return NULL
;
3980 get_tic6x_segment_type (unsigned long type
)
3984 case PT_C6000_PHATTR
: return "C6000_PHATTR";
3985 default: return NULL
;
3990 get_hpux_segment_type (unsigned long type
, unsigned e_machine
)
3992 if (e_machine
== EM_PARISC
)
3995 case PT_HP_TLS
: return "HP_TLS";
3996 case PT_HP_CORE_NONE
: return "HP_CORE_NONE";
3997 case PT_HP_CORE_VERSION
: return "HP_CORE_VERSION";
3998 case PT_HP_CORE_KERNEL
: return "HP_CORE_KERNEL";
3999 case PT_HP_CORE_COMM
: return "HP_CORE_COMM";
4000 case PT_HP_CORE_PROC
: return "HP_CORE_PROC";
4001 case PT_HP_CORE_LOADABLE
: return "HP_CORE_LOADABLE";
4002 case PT_HP_CORE_STACK
: return "HP_CORE_STACK";
4003 case PT_HP_CORE_SHM
: return "HP_CORE_SHM";
4004 case PT_HP_CORE_MMF
: return "HP_CORE_MMF";
4005 case PT_HP_PARALLEL
: return "HP_PARALLEL";
4006 case PT_HP_FASTBIND
: return "HP_FASTBIND";
4007 case PT_HP_OPT_ANNOT
: return "HP_OPT_ANNOT";
4008 case PT_HP_HSL_ANNOT
: return "HP_HSL_ANNOT";
4009 case PT_HP_STACK
: return "HP_STACK";
4010 case PT_HP_CORE_UTSNAME
: return "HP_CORE_UTSNAME";
4011 default: return NULL
;
4014 if (e_machine
== EM_IA_64
)
4017 case PT_HP_TLS
: return "HP_TLS";
4018 case PT_IA_64_HP_OPT_ANOT
: return "HP_OPT_ANNOT";
4019 case PT_IA_64_HP_HSL_ANOT
: return "HP_HSL_ANNOT";
4020 case PT_IA_64_HP_STACK
: return "HP_STACK";
4021 default: return NULL
;
4028 get_solaris_segment_type (unsigned long type
)
4032 case 0x6464e550: return "PT_SUNW_UNWIND";
4033 case 0x6474e550: return "PT_SUNW_EH_FRAME";
4034 case 0x6ffffff7: return "PT_LOSUNW";
4035 case 0x6ffffffa: return "PT_SUNWBSS";
4036 case 0x6ffffffb: return "PT_SUNWSTACK";
4037 case 0x6ffffffc: return "PT_SUNWDTRACE";
4038 case 0x6ffffffd: return "PT_SUNWCAP";
4039 case 0x6fffffff: return "PT_HISUNW";
4040 default: return NULL
;
4045 get_segment_type (Filedata
* filedata
, unsigned long p_type
)
4047 static char buff
[32];
4051 case PT_NULL
: return "NULL";
4052 case PT_LOAD
: return "LOAD";
4053 case PT_DYNAMIC
: return "DYNAMIC";
4054 case PT_INTERP
: return "INTERP";
4055 case PT_NOTE
: return "NOTE";
4056 case PT_SHLIB
: return "SHLIB";
4057 case PT_PHDR
: return "PHDR";
4058 case PT_TLS
: return "TLS";
4059 case PT_GNU_EH_FRAME
: return "GNU_EH_FRAME";
4060 case PT_GNU_STACK
: return "GNU_STACK";
4061 case PT_GNU_RELRO
: return "GNU_RELRO";
4062 case PT_GNU_PROPERTY
: return "GNU_PROPERTY";
4064 case PT_OPENBSD_RANDOMIZE
: return "OPENBSD_RANDOMIZE";
4065 case PT_OPENBSD_WXNEEDED
: return "OPENBSD_WXNEEDED";
4066 case PT_OPENBSD_BOOTDATA
: return "OPENBSD_BOOTDATA";
4069 if ((p_type
>= PT_LOPROC
) && (p_type
<= PT_HIPROC
))
4071 const char * result
;
4073 switch (filedata
->file_header
.e_machine
)
4076 result
= get_aarch64_segment_type (p_type
);
4079 result
= get_arm_segment_type (p_type
);
4082 case EM_MIPS_RS3_LE
:
4083 result
= get_mips_segment_type (p_type
);
4086 result
= get_parisc_segment_type (p_type
);
4089 result
= get_ia64_segment_type (p_type
);
4092 result
= get_tic6x_segment_type (p_type
);
4096 result
= get_s390_segment_type (p_type
);
4106 sprintf (buff
, "LOPROC+%#lx", p_type
- PT_LOPROC
);
4108 else if ((p_type
>= PT_LOOS
) && (p_type
<= PT_HIOS
))
4110 const char * result
= NULL
;
4112 switch (filedata
->file_header
.e_ident
[EI_OSABI
])
4115 case ELFOSABI_FREEBSD
:
4116 if (p_type
>= PT_GNU_MBIND_LO
&& p_type
<= PT_GNU_MBIND_HI
)
4118 sprintf (buff
, "GNU_MBIND+%#lx", p_type
- PT_GNU_MBIND_LO
);
4123 result
= get_hpux_segment_type (p_type
,
4124 filedata
->file_header
.e_machine
);
4126 case ELFOSABI_SOLARIS
:
4127 result
= get_solaris_segment_type (p_type
);
4135 sprintf (buff
, "LOOS+%#lx", p_type
- PT_LOOS
);
4138 snprintf (buff
, sizeof (buff
), _("<unknown>: %lx"), p_type
);
4145 get_arc_section_type_name (unsigned int sh_type
)
4149 case SHT_ARC_ATTRIBUTES
: return "ARC_ATTRIBUTES";
4157 get_mips_section_type_name (unsigned int sh_type
)
4161 case SHT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
4162 case SHT_MIPS_MSYM
: return "MIPS_MSYM";
4163 case SHT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
4164 case SHT_MIPS_GPTAB
: return "MIPS_GPTAB";
4165 case SHT_MIPS_UCODE
: return "MIPS_UCODE";
4166 case SHT_MIPS_DEBUG
: return "MIPS_DEBUG";
4167 case SHT_MIPS_REGINFO
: return "MIPS_REGINFO";
4168 case SHT_MIPS_PACKAGE
: return "MIPS_PACKAGE";
4169 case SHT_MIPS_PACKSYM
: return "MIPS_PACKSYM";
4170 case SHT_MIPS_RELD
: return "MIPS_RELD";
4171 case SHT_MIPS_IFACE
: return "MIPS_IFACE";
4172 case SHT_MIPS_CONTENT
: return "MIPS_CONTENT";
4173 case SHT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
4174 case SHT_MIPS_SHDR
: return "MIPS_SHDR";
4175 case SHT_MIPS_FDESC
: return "MIPS_FDESC";
4176 case SHT_MIPS_EXTSYM
: return "MIPS_EXTSYM";
4177 case SHT_MIPS_DENSE
: return "MIPS_DENSE";
4178 case SHT_MIPS_PDESC
: return "MIPS_PDESC";
4179 case SHT_MIPS_LOCSYM
: return "MIPS_LOCSYM";
4180 case SHT_MIPS_AUXSYM
: return "MIPS_AUXSYM";
4181 case SHT_MIPS_OPTSYM
: return "MIPS_OPTSYM";
4182 case SHT_MIPS_LOCSTR
: return "MIPS_LOCSTR";
4183 case SHT_MIPS_LINE
: return "MIPS_LINE";
4184 case SHT_MIPS_RFDESC
: return "MIPS_RFDESC";
4185 case SHT_MIPS_DELTASYM
: return "MIPS_DELTASYM";
4186 case SHT_MIPS_DELTAINST
: return "MIPS_DELTAINST";
4187 case SHT_MIPS_DELTACLASS
: return "MIPS_DELTACLASS";
4188 case SHT_MIPS_DWARF
: return "MIPS_DWARF";
4189 case SHT_MIPS_DELTADECL
: return "MIPS_DELTADECL";
4190 case SHT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
4191 case SHT_MIPS_EVENTS
: return "MIPS_EVENTS";
4192 case SHT_MIPS_TRANSLATE
: return "MIPS_TRANSLATE";
4193 case SHT_MIPS_PIXIE
: return "MIPS_PIXIE";
4194 case SHT_MIPS_XLATE
: return "MIPS_XLATE";
4195 case SHT_MIPS_XLATE_DEBUG
: return "MIPS_XLATE_DEBUG";
4196 case SHT_MIPS_WHIRL
: return "MIPS_WHIRL";
4197 case SHT_MIPS_EH_REGION
: return "MIPS_EH_REGION";
4198 case SHT_MIPS_XLATE_OLD
: return "MIPS_XLATE_OLD";
4199 case SHT_MIPS_PDR_EXCEPTION
: return "MIPS_PDR_EXCEPTION";
4200 case SHT_MIPS_ABIFLAGS
: return "MIPS_ABIFLAGS";
4201 case SHT_MIPS_XHASH
: return "MIPS_XHASH";
4209 get_parisc_section_type_name (unsigned int sh_type
)
4213 case SHT_PARISC_EXT
: return "PARISC_EXT";
4214 case SHT_PARISC_UNWIND
: return "PARISC_UNWIND";
4215 case SHT_PARISC_DOC
: return "PARISC_DOC";
4216 case SHT_PARISC_ANNOT
: return "PARISC_ANNOT";
4217 case SHT_PARISC_SYMEXTN
: return "PARISC_SYMEXTN";
4218 case SHT_PARISC_STUBS
: return "PARISC_STUBS";
4219 case SHT_PARISC_DLKM
: return "PARISC_DLKM";
4220 default: return NULL
;
4225 get_ia64_section_type_name (Filedata
* filedata
, unsigned int sh_type
)
4227 /* If the top 8 bits are 0x78 the next 8 are the os/abi ID. */
4228 if ((sh_type
& 0xFF000000) == SHT_IA_64_LOPSREG
)
4229 return get_osabi_name (filedata
, (sh_type
& 0x00FF0000) >> 16);
4233 case SHT_IA_64_EXT
: return "IA_64_EXT";
4234 case SHT_IA_64_UNWIND
: return "IA_64_UNWIND";
4235 case SHT_IA_64_PRIORITY_INIT
: return "IA_64_PRIORITY_INIT";
4236 case SHT_IA_64_VMS_TRACE
: return "VMS_TRACE";
4237 case SHT_IA_64_VMS_TIE_SIGNATURES
: return "VMS_TIE_SIGNATURES";
4238 case SHT_IA_64_VMS_DEBUG
: return "VMS_DEBUG";
4239 case SHT_IA_64_VMS_DEBUG_STR
: return "VMS_DEBUG_STR";
4240 case SHT_IA_64_VMS_LINKAGES
: return "VMS_LINKAGES";
4241 case SHT_IA_64_VMS_SYMBOL_VECTOR
: return "VMS_SYMBOL_VECTOR";
4242 case SHT_IA_64_VMS_FIXUP
: return "VMS_FIXUP";
4250 get_x86_64_section_type_name (unsigned int sh_type
)
4254 case SHT_X86_64_UNWIND
: return "X86_64_UNWIND";
4255 default: return NULL
;
4260 get_aarch64_section_type_name (unsigned int sh_type
)
4264 case SHT_AARCH64_ATTRIBUTES
: return "AARCH64_ATTRIBUTES";
4265 default: return NULL
;
4270 get_arm_section_type_name (unsigned int sh_type
)
4274 case SHT_ARM_EXIDX
: return "ARM_EXIDX";
4275 case SHT_ARM_PREEMPTMAP
: return "ARM_PREEMPTMAP";
4276 case SHT_ARM_ATTRIBUTES
: return "ARM_ATTRIBUTES";
4277 case SHT_ARM_DEBUGOVERLAY
: return "ARM_DEBUGOVERLAY";
4278 case SHT_ARM_OVERLAYSECTION
: return "ARM_OVERLAYSECTION";
4279 default: return NULL
;
4284 get_tic6x_section_type_name (unsigned int sh_type
)
4288 case SHT_C6000_UNWIND
: return "C6000_UNWIND";
4289 case SHT_C6000_PREEMPTMAP
: return "C6000_PREEMPTMAP";
4290 case SHT_C6000_ATTRIBUTES
: return "C6000_ATTRIBUTES";
4291 case SHT_TI_ICODE
: return "TI_ICODE";
4292 case SHT_TI_XREF
: return "TI_XREF";
4293 case SHT_TI_HANDLER
: return "TI_HANDLER";
4294 case SHT_TI_INITINFO
: return "TI_INITINFO";
4295 case SHT_TI_PHATTRS
: return "TI_PHATTRS";
4296 default: return NULL
;
4301 get_msp430_section_type_name (unsigned int sh_type
)
4305 case SHT_MSP430_SEC_FLAGS
: return "MSP430_SEC_FLAGS";
4306 case SHT_MSP430_SYM_ALIASES
: return "MSP430_SYM_ALIASES";
4307 case SHT_MSP430_ATTRIBUTES
: return "MSP430_ATTRIBUTES";
4308 default: return NULL
;
4313 get_nfp_section_type_name (unsigned int sh_type
)
4317 case SHT_NFP_MECONFIG
: return "NFP_MECONFIG";
4318 case SHT_NFP_INITREG
: return "NFP_INITREG";
4319 case SHT_NFP_UDEBUG
: return "NFP_UDEBUG";
4320 default: return NULL
;
4325 get_v850_section_type_name (unsigned int sh_type
)
4329 case SHT_V850_SCOMMON
: return "V850 Small Common";
4330 case SHT_V850_TCOMMON
: return "V850 Tiny Common";
4331 case SHT_V850_ZCOMMON
: return "V850 Zero Common";
4332 case SHT_RENESAS_IOP
: return "RENESAS IOP";
4333 case SHT_RENESAS_INFO
: return "RENESAS INFO";
4334 default: return NULL
;
4339 get_riscv_section_type_name (unsigned int sh_type
)
4343 case SHT_RISCV_ATTRIBUTES
: return "RISCV_ATTRIBUTES";
4344 default: return NULL
;
4349 get_csky_section_type_name (unsigned int sh_type
)
4353 case SHT_CSKY_ATTRIBUTES
: return "CSKY_ATTRIBUTES";
4354 default: return NULL
;
4359 get_section_type_name (Filedata
* filedata
, unsigned int sh_type
)
4361 static char buff
[32];
4362 const char * result
;
4366 case SHT_NULL
: return "NULL";
4367 case SHT_PROGBITS
: return "PROGBITS";
4368 case SHT_SYMTAB
: return "SYMTAB";
4369 case SHT_STRTAB
: return "STRTAB";
4370 case SHT_RELA
: return "RELA";
4371 case SHT_HASH
: return "HASH";
4372 case SHT_DYNAMIC
: return "DYNAMIC";
4373 case SHT_NOTE
: return "NOTE";
4374 case SHT_NOBITS
: return "NOBITS";
4375 case SHT_REL
: return "REL";
4376 case SHT_SHLIB
: return "SHLIB";
4377 case SHT_DYNSYM
: return "DYNSYM";
4378 case SHT_INIT_ARRAY
: return "INIT_ARRAY";
4379 case SHT_FINI_ARRAY
: return "FINI_ARRAY";
4380 case SHT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
4381 case SHT_GNU_HASH
: return "GNU_HASH";
4382 case SHT_GROUP
: return "GROUP";
4383 case SHT_SYMTAB_SHNDX
: return "SYMTAB SECTION INDICES";
4384 case SHT_GNU_verdef
: return "VERDEF";
4385 case SHT_GNU_verneed
: return "VERNEED";
4386 case SHT_GNU_versym
: return "VERSYM";
4387 case 0x6ffffff0: return "VERSYM";
4388 case 0x6ffffffc: return "VERDEF";
4389 case 0x7ffffffd: return "AUXILIARY";
4390 case 0x7fffffff: return "FILTER";
4391 case SHT_GNU_LIBLIST
: return "GNU_LIBLIST";
4394 if ((sh_type
>= SHT_LOPROC
) && (sh_type
<= SHT_HIPROC
))
4396 switch (filedata
->file_header
.e_machine
)
4399 case EM_ARC_COMPACT
:
4400 case EM_ARC_COMPACT2
:
4401 result
= get_arc_section_type_name (sh_type
);
4404 case EM_MIPS_RS3_LE
:
4405 result
= get_mips_section_type_name (sh_type
);
4408 result
= get_parisc_section_type_name (sh_type
);
4411 result
= get_ia64_section_type_name (filedata
, sh_type
);
4416 result
= get_x86_64_section_type_name (sh_type
);
4419 result
= get_aarch64_section_type_name (sh_type
);
4422 result
= get_arm_section_type_name (sh_type
);
4425 result
= get_tic6x_section_type_name (sh_type
);
4428 result
= get_msp430_section_type_name (sh_type
);
4431 result
= get_nfp_section_type_name (sh_type
);
4435 case EM_CYGNUS_V850
:
4436 result
= get_v850_section_type_name (sh_type
);
4439 result
= get_riscv_section_type_name (sh_type
);
4442 result
= get_csky_section_type_name (sh_type
);
4452 sprintf (buff
, "LOPROC+%#x", sh_type
- SHT_LOPROC
);
4454 else if ((sh_type
>= SHT_LOOS
) && (sh_type
<= SHT_HIOS
))
4456 switch (filedata
->file_header
.e_machine
)
4459 result
= get_ia64_section_type_name (filedata
, sh_type
);
4462 if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_SOLARIS
)
4463 result
= get_solaris_section_type (sh_type
);
4468 case SHT_GNU_INCREMENTAL_INPUTS
: result
= "GNU_INCREMENTAL_INPUTS"; break;
4469 case SHT_GNU_ATTRIBUTES
: result
= "GNU_ATTRIBUTES"; break;
4470 case SHT_GNU_HASH
: result
= "GNU_HASH"; break;
4471 case SHT_GNU_LIBLIST
: result
= "GNU_LIBLIST"; break;
4483 sprintf (buff
, "LOOS+%#x", sh_type
- SHT_LOOS
);
4485 else if ((sh_type
>= SHT_LOUSER
) && (sh_type
<= SHT_HIUSER
))
4487 switch (filedata
->file_header
.e_machine
)
4491 case EM_CYGNUS_V850
:
4492 result
= get_v850_section_type_name (sh_type
);
4502 sprintf (buff
, "LOUSER+%#x", sh_type
- SHT_LOUSER
);
4505 /* This message is probably going to be displayed in a 15
4506 character wide field, so put the hex value first. */
4507 snprintf (buff
, sizeof (buff
), _("%08x: <unknown>"), sh_type
);
4513 enum long_option_values
4515 OPTION_DEBUG_DUMP
= 512,
4525 OPTION_WITH_SYMBOL_VERSIONS
,
4526 OPTION_RECURSE_LIMIT
,
4527 OPTION_NO_RECURSE_LIMIT
,
4528 OPTION_NO_DEMANGLING
4531 static struct option options
[] =
4533 /* Note - This table is alpha-sorted on the 'val'
4534 field in order to make adding new options easier. */
4535 {"arch-specific", no_argument
, 0, 'A'},
4536 {"all", no_argument
, 0, 'a'},
4537 {"demangle", optional_argument
, 0, 'C'},
4538 {"archive-index", no_argument
, 0, 'c'},
4539 {"use-dynamic", no_argument
, 0, 'D'},
4540 {"dynamic", no_argument
, 0, 'd'},
4541 {"headers", no_argument
, 0, 'e'},
4542 {"section-groups", no_argument
, 0, 'g'},
4543 {"help", no_argument
, 0, 'H'},
4544 {"file-header", no_argument
, 0, 'h'},
4545 {"histogram", no_argument
, 0, 'I'},
4546 {"lint", no_argument
, 0, 'L'},
4547 {"enable-checks", no_argument
, 0, 'L'},
4548 {"program-headers", no_argument
, 0, 'l'},
4549 {"segments", no_argument
, 0, 'l'},
4550 {"full-section-name",no_argument
, 0, 'N'},
4551 {"notes", no_argument
, 0, 'n'},
4552 {"process-links", no_argument
, 0, 'P'},
4553 {"string-dump", required_argument
, 0, 'p'},
4554 {"relocated-dump", required_argument
, 0, 'R'},
4555 {"relocs", no_argument
, 0, 'r'},
4556 {"section-headers", no_argument
, 0, 'S'},
4557 {"sections", no_argument
, 0, 'S'},
4558 {"symbols", no_argument
, 0, 's'},
4559 {"syms", no_argument
, 0, 's'},
4560 {"silent-truncation",no_argument
, 0, 'T'},
4561 {"section-details", no_argument
, 0, 't'},
4562 {"unwind", no_argument
, 0, 'u'},
4563 {"version-info", no_argument
, 0, 'V'},
4564 {"version", no_argument
, 0, 'v'},
4565 {"wide", no_argument
, 0, 'W'},
4566 {"hex-dump", required_argument
, 0, 'x'},
4567 {"decompress", no_argument
, 0, 'z'},
4569 {"no-demangle", no_argument
, 0, OPTION_NO_DEMANGLING
},
4570 {"recurse-limit", no_argument
, NULL
, OPTION_RECURSE_LIMIT
},
4571 {"no-recurse-limit", no_argument
, NULL
, OPTION_NO_RECURSE_LIMIT
},
4572 {"no-recursion-limit", no_argument
, NULL
, OPTION_NO_RECURSE_LIMIT
},
4573 {"dyn-syms", no_argument
, 0, OPTION_DYN_SYMS
},
4574 {"lto-syms", no_argument
, 0, OPTION_LTO_SYMS
},
4575 {"debug-dump", optional_argument
, 0, OPTION_DEBUG_DUMP
},
4576 {"dwarf-depth", required_argument
, 0, OPTION_DWARF_DEPTH
},
4577 {"dwarf-start", required_argument
, 0, OPTION_DWARF_START
},
4578 {"dwarf-check", no_argument
, 0, OPTION_DWARF_CHECK
},
4579 #ifdef ENABLE_LIBCTF
4580 {"ctf", required_argument
, 0, OPTION_CTF_DUMP
},
4581 {"ctf-symbols", required_argument
, 0, OPTION_CTF_SYMBOLS
},
4582 {"ctf-strings", required_argument
, 0, OPTION_CTF_STRINGS
},
4583 {"ctf-parent", required_argument
, 0, OPTION_CTF_PARENT
},
4586 {0, no_argument
, 0, 0}
4590 usage (FILE * stream
)
4592 fprintf (stream
, _("Usage: readelf <option(s)> elf-file(s)\n"));
4593 fprintf (stream
, _(" Display information about the contents of ELF format files\n"));
4594 fprintf (stream
, _(" Options are:\n\
4595 -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n\
4596 -h --file-header Display the ELF file header\n\
4597 -l --program-headers Display the program headers\n\
4598 --segments An alias for --program-headers\n\
4599 -S --section-headers Display the sections' header\n\
4600 --sections An alias for --section-headers\n\
4601 -g --section-groups Display the section groups\n\
4602 -t --section-details Display the section details\n\
4603 -e --headers Equivalent to: -h -l -S\n\
4604 -s --syms Display the symbol table\n\
4605 --symbols An alias for --syms\n\
4606 --dyn-syms Display the dynamic symbol table\n\
4607 --lto-syms Display LTO symbol tables\n\
4608 -C --demangle[=STYLE] Decode low-level symbol names into user-level names\n\
4609 The STYLE, if specified, can be `auto' (the default),\n\
4610 `gnu', `lucid', `arm', `hp', `edg', `gnu-v3', `java'\n\
4612 --no-demangle Do not demangle low-level symbol names. (This is the default)\n\
4613 --recurse-limit Enable a demangling recursion limit. (This is the default)\n\
4614 --no-recurse-limit Disable a demangling recursion limit\n\
4615 -n --notes Display the core notes (if present)\n\
4616 -r --relocs Display the relocations (if present)\n\
4617 -u --unwind Display the unwind info (if present)\n\
4618 -d --dynamic Display the dynamic section (if present)\n\
4619 -V --version-info Display the version sections (if present)\n\
4620 -A --arch-specific Display architecture specific information (if any)\n\
4621 -c --archive-index Display the symbol/file index in an archive\n\
4622 -D --use-dynamic Use the dynamic section info when displaying symbols\n\
4623 -L --lint|--enable-checks Display warning messages for possible problems\n\
4624 -x --hex-dump=<number|name>\n\
4625 Dump the contents of section <number|name> as bytes\n\
4626 -p --string-dump=<number|name>\n\
4627 Dump the contents of section <number|name> as strings\n\
4628 -R --relocated-dump=<number|name>\n\
4629 Dump the contents of section <number|name> as relocated bytes\n\
4630 -z --decompress Decompress section before dumping it\n\
4631 -w[lLiaprmfFsoORtUuTgAc] or\n\
4632 --debug-dump[=rawline,=decodedline,=info,=abbrev,=pubnames,=aranges,=macro,=frames,\n\
4633 =frames-interp,=str,=str-offsets,=loc,=Ranges,=pubtypes,\n\
4634 =gdb_index,=trace_info,=trace_abbrev,=trace_aranges,\n\
4636 Display the contents of DWARF debug sections\n\
4637 -wk,--debug-dump=links Display the contents of sections that link to separate debuginfo files\n\
4638 -P,--process-links Display the contents of non-debug sections in separate debuginfo files. (Implies -wK)\n"));
4639 #if DEFAULT_FOR_FOLLOW_LINKS
4640 fprintf (stream
, _("\
4641 -wK,--debug-dump=follow-links Follow links to separate debug info files (default)\n\
4642 -wN,--debug-dump=no-follow-links Do not follow links to separate debug info files\n\
4645 fprintf (stream
, _("\
4646 -wK,--debug-dump=follow-links Follow links to separate debug info files\n\
4647 -wN,--debug-dump=no-follow-links Do not follow links to separate debug info files (default)\n\
4650 fprintf (stream
, _("\
4651 --dwarf-depth=N Do not display DIEs at depth N or greater\n\
4652 --dwarf-start=N Display DIEs starting with N, at the same depth\n\
4654 #ifdef ENABLE_LIBCTF
4655 fprintf (stream
, _("\
4656 --ctf=<number|name> Display CTF info from section <number|name>\n\
4657 --ctf-parent=<number|name>\n\
4658 Use section <number|name> as the CTF parent\n\n\
4659 --ctf-symbols=<number|name>\n\
4660 Use section <number|name> as the CTF external symtab\n\n\
4661 --ctf-strings=<number|name>\n\
4662 Use section <number|name> as the CTF external strtab\n\n"));
4665 #ifdef SUPPORT_DISASSEMBLY
4666 fprintf (stream
, _("\
4667 -i --instruction-dump=<number|name>\n\
4668 Disassemble the contents of section <number|name>\n"));
4670 fprintf (stream
, _("\
4671 -I --histogram Display histogram of bucket list lengths\n\
4672 -W --wide Allow output width to exceed 80 characters\n\
4673 -T --silent-truncation If a symbol name is truncated, do not add a suffix [...]\n\
4674 @<file> Read options from <file>\n\
4675 -H --help Display this information\n\
4676 -v --version Display the version number of readelf\n"));
4678 if (REPORT_BUGS_TO
[0] && stream
== stdout
)
4679 fprintf (stdout
, _("Report bugs to %s\n"), REPORT_BUGS_TO
);
4681 exit (stream
== stdout
? 0 : 1);
4684 /* Record the fact that the user wants the contents of section number
4685 SECTION to be displayed using the method(s) encoded as flags bits
4686 in TYPE. Note, TYPE can be zero if we are creating the array for
4690 request_dump_bynumber (struct dump_data
*dumpdata
,
4691 unsigned int section
, dump_type type
)
4693 if (section
>= dumpdata
->num_dump_sects
)
4695 dump_type
* new_dump_sects
;
4697 new_dump_sects
= (dump_type
*) calloc (section
+ 1,
4698 sizeof (* new_dump_sects
));
4700 if (new_dump_sects
== NULL
)
4701 error (_("Out of memory allocating dump request table.\n"));
4704 if (dumpdata
->dump_sects
)
4706 /* Copy current flag settings. */
4707 memcpy (new_dump_sects
, dumpdata
->dump_sects
,
4708 dumpdata
->num_dump_sects
* sizeof (* new_dump_sects
));
4710 free (dumpdata
->dump_sects
);
4713 dumpdata
->dump_sects
= new_dump_sects
;
4714 dumpdata
->num_dump_sects
= section
+ 1;
4718 if (dumpdata
->dump_sects
)
4719 dumpdata
->dump_sects
[section
] |= type
;
4722 /* Request a dump by section name. */
4725 request_dump_byname (const char * section
, dump_type type
)
4727 struct dump_list_entry
* new_request
;
4729 new_request
= (struct dump_list_entry
*)
4730 malloc (sizeof (struct dump_list_entry
));
4732 error (_("Out of memory allocating dump request table.\n"));
4734 new_request
->name
= strdup (section
);
4735 if (!new_request
->name
)
4736 error (_("Out of memory allocating dump request table.\n"));
4738 new_request
->type
= type
;
4740 new_request
->next
= dump_sects_byname
;
4741 dump_sects_byname
= new_request
;
4745 request_dump (struct dump_data
*dumpdata
, dump_type type
)
4751 section
= strtoul (optarg
, & cp
, 0);
4753 if (! *cp
&& section
>= 0)
4754 request_dump_bynumber (dumpdata
, section
, type
);
4756 request_dump_byname (optarg
, type
);
4760 parse_args (struct dump_data
*dumpdata
, int argc
, char ** argv
)
4767 while ((c
= getopt_long
4768 (argc
, argv
, "ACDHILNPR:STVWacdeghi:lnp:rstuvw::x:z", options
, NULL
)) != EOF
)
4786 do_section_groups
= true;
4789 do_histogram
= true;
4795 do_section_groups
= true;
4800 do_section_details
= true;
4811 do_using_dynamic
= true;
4835 do_histogram
= true;
4841 do_archive_index
= true;
4847 process_links
= true;
4848 do_follow_links
= true;
4851 request_dump (dumpdata
, HEX_DUMP
);
4854 request_dump (dumpdata
, STRING_DUMP
);
4857 request_dump (dumpdata
, RELOC_DUMP
);
4860 decompress_dumps
= true;
4866 do_debugging
= true;
4867 dwarf_select_sections_all ();
4871 do_debugging
= false;
4872 dwarf_select_sections_by_letters (optarg
);
4875 case OPTION_DEBUG_DUMP
:
4878 do_debugging
= true;
4881 do_debugging
= false;
4882 dwarf_select_sections_by_names (optarg
);
4885 case OPTION_DWARF_DEPTH
:
4889 dwarf_cutoff_level
= strtoul (optarg
, & cp
, 0);
4892 case OPTION_DWARF_START
:
4896 dwarf_start_die
= strtoul (optarg
, & cp
, 0);
4899 case OPTION_DWARF_CHECK
:
4902 case OPTION_CTF_DUMP
:
4904 request_dump (dumpdata
, CTF_DUMP
);
4906 case OPTION_CTF_SYMBOLS
:
4907 free (dump_ctf_symtab_name
);
4908 dump_ctf_symtab_name
= strdup (optarg
);
4910 case OPTION_CTF_STRINGS
:
4911 free (dump_ctf_strtab_name
);
4912 dump_ctf_strtab_name
= strdup (optarg
);
4914 case OPTION_CTF_PARENT
:
4915 free (dump_ctf_parent_name
);
4916 dump_ctf_parent_name
= strdup (optarg
);
4918 case OPTION_DYN_SYMS
:
4921 case OPTION_LTO_SYMS
:
4924 #ifdef SUPPORT_DISASSEMBLY
4926 request_dump (dumpdata
, DISASS_DUMP
);
4930 print_version (program_name
);
4939 do_not_show_symbol_truncation
= true;
4945 enum demangling_styles style
;
4947 style
= cplus_demangle_name_to_style (optarg
);
4948 if (style
== unknown_demangling
)
4949 error (_("unknown demangling style `%s'"), optarg
);
4951 cplus_demangle_set_style (style
);
4954 case OPTION_NO_DEMANGLING
:
4955 do_demangle
= false;
4957 case OPTION_RECURSE_LIMIT
:
4958 demangle_flags
&= ~ DMGL_NO_RECURSE_LIMIT
;
4960 case OPTION_NO_RECURSE_LIMIT
:
4961 demangle_flags
|= DMGL_NO_RECURSE_LIMIT
;
4963 case OPTION_WITH_SYMBOL_VERSIONS
:
4964 /* Ignored for backward compatibility. */
4968 /* xgettext:c-format */
4969 error (_("Invalid option '-%c'\n"), c
);
4976 if (!do_dynamic
&& !do_syms
&& !do_reloc
&& !do_unwind
&& !do_sections
4977 && !do_segments
&& !do_header
&& !do_dump
&& !do_version
4978 && !do_histogram
&& !do_debugging
&& !do_arch
&& !do_notes
4979 && !do_section_groups
&& !do_archive_index
4980 && !do_dyn_syms
&& !do_lto_syms
)
4985 do_dynamic
= do_syms
= do_reloc
= do_unwind
= do_sections
= true;
4986 do_segments
= do_header
= do_dump
= do_version
= true;
4987 do_histogram
= do_debugging
= do_arch
= do_notes
= true;
4988 do_section_groups
= do_archive_index
= do_dyn_syms
= true;
4997 get_elf_class (unsigned int elf_class
)
4999 static char buff
[32];
5003 case ELFCLASSNONE
: return _("none");
5004 case ELFCLASS32
: return "ELF32";
5005 case ELFCLASS64
: return "ELF64";
5007 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), elf_class
);
5013 get_data_encoding (unsigned int encoding
)
5015 static char buff
[32];
5019 case ELFDATANONE
: return _("none");
5020 case ELFDATA2LSB
: return _("2's complement, little endian");
5021 case ELFDATA2MSB
: return _("2's complement, big endian");
5023 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), encoding
);
5028 /* Decode the data held in 'filedata->file_header'. */
5031 process_file_header (Filedata
* filedata
)
5033 Elf_Internal_Ehdr
* header
= & filedata
->file_header
;
5035 if ( header
->e_ident
[EI_MAG0
] != ELFMAG0
5036 || header
->e_ident
[EI_MAG1
] != ELFMAG1
5037 || header
->e_ident
[EI_MAG2
] != ELFMAG2
5038 || header
->e_ident
[EI_MAG3
] != ELFMAG3
)
5041 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
5045 if (! filedata
->is_separate
)
5046 init_dwarf_regnames_by_elf_machine_code (header
->e_machine
);
5052 if (filedata
->is_separate
)
5053 printf (_("ELF Header in linked file '%s':\n"), filedata
->file_name
);
5055 printf (_("ELF Header:\n"));
5056 printf (_(" Magic: "));
5057 for (i
= 0; i
< EI_NIDENT
; i
++)
5058 printf ("%2.2x ", header
->e_ident
[i
]);
5060 printf (_(" Class: %s\n"),
5061 get_elf_class (header
->e_ident
[EI_CLASS
]));
5062 printf (_(" Data: %s\n"),
5063 get_data_encoding (header
->e_ident
[EI_DATA
]));
5064 printf (_(" Version: %d%s\n"),
5065 header
->e_ident
[EI_VERSION
],
5066 (header
->e_ident
[EI_VERSION
] == EV_CURRENT
5068 : (header
->e_ident
[EI_VERSION
] != EV_NONE
5071 printf (_(" OS/ABI: %s\n"),
5072 get_osabi_name (filedata
, header
->e_ident
[EI_OSABI
]));
5073 printf (_(" ABI Version: %d\n"),
5074 header
->e_ident
[EI_ABIVERSION
]);
5075 printf (_(" Type: %s\n"),
5076 get_file_type (header
->e_type
));
5077 printf (_(" Machine: %s\n"),
5078 get_machine_name (header
->e_machine
));
5079 printf (_(" Version: 0x%lx\n"),
5082 printf (_(" Entry point address: "));
5083 print_vma (header
->e_entry
, PREFIX_HEX
);
5084 printf (_("\n Start of program headers: "));
5085 print_vma (header
->e_phoff
, DEC
);
5086 printf (_(" (bytes into file)\n Start of section headers: "));
5087 print_vma (header
->e_shoff
, DEC
);
5088 printf (_(" (bytes into file)\n"));
5090 printf (_(" Flags: 0x%lx%s\n"),
5092 get_machine_flags (filedata
, header
->e_flags
, header
->e_machine
));
5093 printf (_(" Size of this header: %u (bytes)\n"),
5095 printf (_(" Size of program headers: %u (bytes)\n"),
5096 header
->e_phentsize
);
5097 printf (_(" Number of program headers: %u"),
5099 if (filedata
->section_headers
!= NULL
5100 && header
->e_phnum
== PN_XNUM
5101 && filedata
->section_headers
[0].sh_info
!= 0)
5103 header
->e_phnum
= filedata
->section_headers
[0].sh_info
;
5104 printf (" (%u)", header
->e_phnum
);
5106 putc ('\n', stdout
);
5107 printf (_(" Size of section headers: %u (bytes)\n"),
5108 header
->e_shentsize
);
5109 printf (_(" Number of section headers: %u"),
5111 if (filedata
->section_headers
!= NULL
&& header
->e_shnum
== SHN_UNDEF
)
5113 header
->e_shnum
= filedata
->section_headers
[0].sh_size
;
5114 printf (" (%u)", header
->e_shnum
);
5116 putc ('\n', stdout
);
5117 printf (_(" Section header string table index: %u"),
5118 header
->e_shstrndx
);
5119 if (filedata
->section_headers
!= NULL
5120 && header
->e_shstrndx
== (SHN_XINDEX
& 0xffff))
5122 header
->e_shstrndx
= filedata
->section_headers
[0].sh_link
;
5123 printf (" (%u)", header
->e_shstrndx
);
5125 if (header
->e_shstrndx
!= SHN_UNDEF
5126 && header
->e_shstrndx
>= header
->e_shnum
)
5128 header
->e_shstrndx
= SHN_UNDEF
;
5129 printf (_(" <corrupt: out of range>"));
5131 putc ('\n', stdout
);
5134 if (filedata
->section_headers
!= NULL
)
5136 if (header
->e_phnum
== PN_XNUM
5137 && filedata
->section_headers
[0].sh_info
!= 0)
5138 header
->e_phnum
= filedata
->section_headers
[0].sh_info
;
5139 if (header
->e_shnum
== SHN_UNDEF
)
5140 header
->e_shnum
= filedata
->section_headers
[0].sh_size
;
5141 if (header
->e_shstrndx
== (SHN_XINDEX
& 0xffff))
5142 header
->e_shstrndx
= filedata
->section_headers
[0].sh_link
;
5143 if (header
->e_shstrndx
>= header
->e_shnum
)
5144 header
->e_shstrndx
= SHN_UNDEF
;
5145 free (filedata
->section_headers
);
5146 filedata
->section_headers
= NULL
;
5152 /* Read in the program headers from FILEDATA and store them in PHEADERS.
5153 Returns TRUE upon success, FALSE otherwise. Loads 32-bit headers. */
5156 get_32bit_program_headers (Filedata
* filedata
, Elf_Internal_Phdr
* pheaders
)
5158 Elf32_External_Phdr
* phdrs
;
5159 Elf32_External_Phdr
* external
;
5160 Elf_Internal_Phdr
* internal
;
5162 unsigned int size
= filedata
->file_header
.e_phentsize
;
5163 unsigned int num
= filedata
->file_header
.e_phnum
;
5165 /* PR binutils/17531: Cope with unexpected section header sizes. */
5166 if (size
== 0 || num
== 0)
5168 if (size
< sizeof * phdrs
)
5170 error (_("The e_phentsize field in the ELF header is less than the size of an ELF program header\n"));
5173 if (size
> sizeof * phdrs
)
5174 warn (_("The e_phentsize field in the ELF header is larger than the size of an ELF program header\n"));
5176 phdrs
= (Elf32_External_Phdr
*) get_data (NULL
, filedata
, filedata
->file_header
.e_phoff
,
5177 size
, num
, _("program headers"));
5181 for (i
= 0, internal
= pheaders
, external
= phdrs
;
5182 i
< filedata
->file_header
.e_phnum
;
5183 i
++, internal
++, external
++)
5185 internal
->p_type
= BYTE_GET (external
->p_type
);
5186 internal
->p_offset
= BYTE_GET (external
->p_offset
);
5187 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
5188 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
5189 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
5190 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
5191 internal
->p_flags
= BYTE_GET (external
->p_flags
);
5192 internal
->p_align
= BYTE_GET (external
->p_align
);
5199 /* Read in the program headers from FILEDATA and store them in PHEADERS.
5200 Returns TRUE upon success, FALSE otherwise. Loads 64-bit headers. */
5203 get_64bit_program_headers (Filedata
* filedata
, Elf_Internal_Phdr
* pheaders
)
5205 Elf64_External_Phdr
* phdrs
;
5206 Elf64_External_Phdr
* external
;
5207 Elf_Internal_Phdr
* internal
;
5209 unsigned int size
= filedata
->file_header
.e_phentsize
;
5210 unsigned int num
= filedata
->file_header
.e_phnum
;
5212 /* PR binutils/17531: Cope with unexpected section header sizes. */
5213 if (size
== 0 || num
== 0)
5215 if (size
< sizeof * phdrs
)
5217 error (_("The e_phentsize field in the ELF header is less than the size of an ELF program header\n"));
5220 if (size
> sizeof * phdrs
)
5221 warn (_("The e_phentsize field in the ELF header is larger than the size of an ELF program header\n"));
5223 phdrs
= (Elf64_External_Phdr
*) get_data (NULL
, filedata
, filedata
->file_header
.e_phoff
,
5224 size
, num
, _("program headers"));
5228 for (i
= 0, internal
= pheaders
, external
= phdrs
;
5229 i
< filedata
->file_header
.e_phnum
;
5230 i
++, internal
++, external
++)
5232 internal
->p_type
= BYTE_GET (external
->p_type
);
5233 internal
->p_flags
= BYTE_GET (external
->p_flags
);
5234 internal
->p_offset
= BYTE_GET (external
->p_offset
);
5235 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
5236 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
5237 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
5238 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
5239 internal
->p_align
= BYTE_GET (external
->p_align
);
5246 /* Returns TRUE if the program headers were read into `program_headers'. */
5249 get_program_headers (Filedata
* filedata
)
5251 Elf_Internal_Phdr
* phdrs
;
5253 /* Check cache of prior read. */
5254 if (filedata
->program_headers
!= NULL
)
5257 /* Be kind to memory checkers by looking for
5258 e_phnum values which we know must be invalid. */
5259 if (filedata
->file_header
.e_phnum
5260 * (is_32bit_elf
? sizeof (Elf32_External_Phdr
) : sizeof (Elf64_External_Phdr
))
5261 >= filedata
->file_size
)
5263 error (_("Too many program headers - %#x - the file is not that big\n"),
5264 filedata
->file_header
.e_phnum
);
5268 phdrs
= (Elf_Internal_Phdr
*) cmalloc (filedata
->file_header
.e_phnum
,
5269 sizeof (Elf_Internal_Phdr
));
5272 error (_("Out of memory reading %u program headers\n"),
5273 filedata
->file_header
.e_phnum
);
5278 ? get_32bit_program_headers (filedata
, phdrs
)
5279 : get_64bit_program_headers (filedata
, phdrs
))
5281 filedata
->program_headers
= phdrs
;
5289 /* Returns TRUE if the program headers were loaded. */
5292 process_program_headers (Filedata
* filedata
)
5294 Elf_Internal_Phdr
* segment
;
5296 Elf_Internal_Phdr
* previous_load
= NULL
;
5298 filedata
->dynamic_addr
= 0;
5299 filedata
->dynamic_size
= 0;
5301 if (filedata
->file_header
.e_phnum
== 0)
5303 /* PR binutils/12467. */
5304 if (filedata
->file_header
.e_phoff
!= 0)
5306 warn (_("possibly corrupt ELF header - it has a non-zero program"
5307 " header offset, but no program headers\n"));
5310 else if (do_segments
)
5312 if (filedata
->is_separate
)
5313 printf (_("\nThere are no program headers in linked file '%s'.\n"),
5314 filedata
->file_name
);
5316 printf (_("\nThere are no program headers in this file.\n"));
5321 if (do_segments
&& !do_header
)
5323 if (filedata
->is_separate
)
5324 printf ("\nIn linked file '%s' the ELF file type is %s\n",
5325 filedata
->file_name
,
5326 get_file_type (filedata
->file_header
.e_type
));
5328 printf (_("\nElf file type is %s\n"), get_file_type (filedata
->file_header
.e_type
));
5329 printf (_("Entry point 0x%s\n"), bfd_vmatoa ("x", filedata
->file_header
.e_entry
));
5330 printf (ngettext ("There is %d program header, starting at offset %s\n",
5331 "There are %d program headers, starting at offset %s\n",
5332 filedata
->file_header
.e_phnum
),
5333 filedata
->file_header
.e_phnum
,
5334 bfd_vmatoa ("u", filedata
->file_header
.e_phoff
));
5337 if (! get_program_headers (filedata
))
5342 if (filedata
->file_header
.e_phnum
> 1)
5343 printf (_("\nProgram Headers:\n"));
5345 printf (_("\nProgram Headers:\n"));
5349 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
5352 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
5356 (_(" Type Offset VirtAddr PhysAddr\n"));
5358 (_(" FileSiz MemSiz Flags Align\n"));
5362 for (i
= 0, segment
= filedata
->program_headers
;
5363 i
< filedata
->file_header
.e_phnum
;
5368 printf (" %-14.14s ", get_segment_type (filedata
, segment
->p_type
));
5372 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
5373 printf ("0x%8.8lx ", (unsigned long) segment
->p_vaddr
);
5374 printf ("0x%8.8lx ", (unsigned long) segment
->p_paddr
);
5375 printf ("0x%5.5lx ", (unsigned long) segment
->p_filesz
);
5376 printf ("0x%5.5lx ", (unsigned long) segment
->p_memsz
);
5378 (segment
->p_flags
& PF_R
? 'R' : ' '),
5379 (segment
->p_flags
& PF_W
? 'W' : ' '),
5380 (segment
->p_flags
& PF_X
? 'E' : ' '));
5381 printf ("%#lx", (unsigned long) segment
->p_align
);
5385 if ((unsigned long) segment
->p_offset
== segment
->p_offset
)
5386 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
5389 print_vma (segment
->p_offset
, FULL_HEX
);
5393 print_vma (segment
->p_vaddr
, FULL_HEX
);
5395 print_vma (segment
->p_paddr
, FULL_HEX
);
5398 if ((unsigned long) segment
->p_filesz
== segment
->p_filesz
)
5399 printf ("0x%6.6lx ", (unsigned long) segment
->p_filesz
);
5402 print_vma (segment
->p_filesz
, FULL_HEX
);
5406 if ((unsigned long) segment
->p_memsz
== segment
->p_memsz
)
5407 printf ("0x%6.6lx", (unsigned long) segment
->p_memsz
);
5410 print_vma (segment
->p_memsz
, FULL_HEX
);
5414 (segment
->p_flags
& PF_R
? 'R' : ' '),
5415 (segment
->p_flags
& PF_W
? 'W' : ' '),
5416 (segment
->p_flags
& PF_X
? 'E' : ' '));
5418 if ((unsigned long) segment
->p_align
== segment
->p_align
)
5419 printf ("%#lx", (unsigned long) segment
->p_align
);
5422 print_vma (segment
->p_align
, PREFIX_HEX
);
5427 print_vma (segment
->p_offset
, FULL_HEX
);
5429 print_vma (segment
->p_vaddr
, FULL_HEX
);
5431 print_vma (segment
->p_paddr
, FULL_HEX
);
5433 print_vma (segment
->p_filesz
, FULL_HEX
);
5435 print_vma (segment
->p_memsz
, FULL_HEX
);
5437 (segment
->p_flags
& PF_R
? 'R' : ' '),
5438 (segment
->p_flags
& PF_W
? 'W' : ' '),
5439 (segment
->p_flags
& PF_X
? 'E' : ' '));
5440 print_vma (segment
->p_align
, PREFIX_HEX
);
5443 putc ('\n', stdout
);
5446 switch (segment
->p_type
)
5449 #if 0 /* Do not warn about out of order PT_LOAD segments. Although officially
5450 required by the ELF standard, several programs, including the Linux
5451 kernel, make use of non-ordered segments. */
5453 && previous_load
->p_vaddr
> segment
->p_vaddr
)
5454 error (_("LOAD segments must be sorted in order of increasing VirtAddr\n"));
5456 if (segment
->p_memsz
< segment
->p_filesz
)
5457 error (_("the segment's file size is larger than its memory size\n"));
5458 previous_load
= segment
;
5462 /* PR 20815 - Verify that the program header is loaded into memory. */
5463 if (i
> 0 && previous_load
!= NULL
)
5464 error (_("the PHDR segment must occur before any LOAD segment\n"));
5465 if (filedata
->file_header
.e_machine
!= EM_PARISC
)
5469 for (j
= 1; j
< filedata
->file_header
.e_phnum
; j
++)
5471 Elf_Internal_Phdr
*load
= filedata
->program_headers
+ j
;
5472 if (load
->p_type
== PT_LOAD
5473 && load
->p_offset
<= segment
->p_offset
5474 && (load
->p_offset
+ load
->p_filesz
5475 >= segment
->p_offset
+ segment
->p_filesz
)
5476 && load
->p_vaddr
<= segment
->p_vaddr
5477 && (load
->p_vaddr
+ load
->p_filesz
5478 >= segment
->p_vaddr
+ segment
->p_filesz
))
5481 if (j
== filedata
->file_header
.e_phnum
)
5482 error (_("the PHDR segment is not covered by a LOAD segment\n"));
5487 if (filedata
->dynamic_addr
)
5488 error (_("more than one dynamic segment\n"));
5490 /* By default, assume that the .dynamic section is the first
5491 section in the DYNAMIC segment. */
5492 filedata
->dynamic_addr
= segment
->p_offset
;
5493 filedata
->dynamic_size
= segment
->p_filesz
;
5495 /* Try to locate the .dynamic section. If there is
5496 a section header table, we can easily locate it. */
5497 if (filedata
->section_headers
!= NULL
)
5499 Elf_Internal_Shdr
* sec
;
5501 sec
= find_section (filedata
, ".dynamic");
5502 if (sec
== NULL
|| sec
->sh_size
== 0)
5504 /* A corresponding .dynamic section is expected, but on
5505 IA-64/OpenVMS it is OK for it to be missing. */
5506 if (!is_ia64_vms (filedata
))
5507 error (_("no .dynamic section in the dynamic segment\n"));
5511 if (sec
->sh_type
== SHT_NOBITS
)
5513 filedata
->dynamic_size
= 0;
5517 filedata
->dynamic_addr
= sec
->sh_offset
;
5518 filedata
->dynamic_size
= sec
->sh_size
;
5520 /* The PT_DYNAMIC segment, which is used by the run-time
5521 loader, should exactly match the .dynamic section. */
5523 && (filedata
->dynamic_addr
!= segment
->p_offset
5524 || filedata
->dynamic_size
!= segment
->p_filesz
))
5526 the .dynamic section is not the same as the dynamic segment\n"));
5529 /* PR binutils/17512: Avoid corrupt dynamic section info in the
5530 segment. Check this after matching against the section headers
5531 so we don't warn on debuginfo file (which have NOBITS .dynamic
5533 if (filedata
->dynamic_addr
> filedata
->file_size
5534 || (filedata
->dynamic_size
5535 > filedata
->file_size
- filedata
->dynamic_addr
))
5537 error (_("the dynamic segment offset + size exceeds the size of the file\n"));
5538 filedata
->dynamic_addr
= filedata
->dynamic_size
= 0;
5543 if (fseek (filedata
->handle
,
5544 filedata
->archive_file_offset
+ (long) segment
->p_offset
,
5546 error (_("Unable to find program interpreter name\n"));
5550 int ret
= snprintf (fmt
, sizeof (fmt
), "%%%ds", PATH_MAX
- 1);
5552 if (ret
>= (int) sizeof (fmt
) || ret
< 0)
5553 error (_("Internal error: failed to create format string to display program interpreter\n"));
5555 filedata
->program_interpreter
[0] = 0;
5556 if (fscanf (filedata
->handle
, fmt
,
5557 filedata
->program_interpreter
) <= 0)
5558 error (_("Unable to read program interpreter name\n"));
5561 printf (_(" [Requesting program interpreter: %s]\n"),
5562 filedata
->program_interpreter
);
5569 && filedata
->section_headers
!= NULL
5570 && filedata
->string_table
!= NULL
)
5572 printf (_("\n Section to Segment mapping:\n"));
5573 printf (_(" Segment Sections...\n"));
5575 for (i
= 0; i
< filedata
->file_header
.e_phnum
; i
++)
5578 Elf_Internal_Shdr
* section
;
5580 segment
= filedata
->program_headers
+ i
;
5581 section
= filedata
->section_headers
+ 1;
5583 printf (" %2.2d ", i
);
5585 for (j
= 1; j
< filedata
->file_header
.e_shnum
; j
++, section
++)
5587 if (!ELF_TBSS_SPECIAL (section
, segment
)
5588 && ELF_SECTION_IN_SEGMENT_STRICT (section
, segment
))
5589 printf ("%s ", printable_section_name (filedata
, section
));
5600 /* Find the file offset corresponding to VMA by using the program headers. */
5603 offset_from_vma (Filedata
* filedata
, bfd_vma vma
, bfd_size_type size
)
5605 Elf_Internal_Phdr
* seg
;
5607 if (! get_program_headers (filedata
))
5609 warn (_("Cannot interpret virtual addresses without program headers.\n"));
5613 for (seg
= filedata
->program_headers
;
5614 seg
< filedata
->program_headers
+ filedata
->file_header
.e_phnum
;
5617 if (seg
->p_type
!= PT_LOAD
)
5620 if (vma
>= (seg
->p_vaddr
& -seg
->p_align
)
5621 && vma
+ size
<= seg
->p_vaddr
+ seg
->p_filesz
)
5622 return vma
- seg
->p_vaddr
+ seg
->p_offset
;
5625 warn (_("Virtual address 0x%lx not located in any PT_LOAD segment.\n"),
5626 (unsigned long) vma
);
5631 /* Allocate memory and load the sections headers into FILEDATA->filedata->section_headers.
5632 If PROBE is true, this is just a probe and we do not generate any error
5633 messages if the load fails. */
5636 get_32bit_section_headers (Filedata
* filedata
, bool probe
)
5638 Elf32_External_Shdr
* shdrs
;
5639 Elf_Internal_Shdr
* internal
;
5641 unsigned int size
= filedata
->file_header
.e_shentsize
;
5642 unsigned int num
= probe
? 1 : filedata
->file_header
.e_shnum
;
5644 /* PR binutils/17531: Cope with unexpected section header sizes. */
5645 if (size
== 0 || num
== 0)
5647 if (size
< sizeof * shdrs
)
5650 error (_("The e_shentsize field in the ELF header is less than the size of an ELF section header\n"));
5653 if (!probe
&& size
> sizeof * shdrs
)
5654 warn (_("The e_shentsize field in the ELF header is larger than the size of an ELF section header\n"));
5656 shdrs
= (Elf32_External_Shdr
*) get_data (NULL
, filedata
, filedata
->file_header
.e_shoff
,
5658 probe
? NULL
: _("section headers"));
5662 free (filedata
->section_headers
);
5663 filedata
->section_headers
= (Elf_Internal_Shdr
*)
5664 cmalloc (num
, sizeof (Elf_Internal_Shdr
));
5665 if (filedata
->section_headers
== NULL
)
5668 error (_("Out of memory reading %u section headers\n"), num
);
5673 for (i
= 0, internal
= filedata
->section_headers
;
5677 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
5678 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
5679 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
5680 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
5681 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
5682 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
5683 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
5684 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
5685 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
5686 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
5687 if (!probe
&& internal
->sh_link
> num
)
5688 warn (_("Section %u has an out of range sh_link value of %u\n"), i
, internal
->sh_link
);
5689 if (!probe
&& internal
->sh_flags
& SHF_INFO_LINK
&& internal
->sh_info
> num
)
5690 warn (_("Section %u has an out of range sh_info value of %u\n"), i
, internal
->sh_info
);
5697 /* Like get_32bit_section_headers, except that it fetches 64-bit headers. */
5700 get_64bit_section_headers (Filedata
* filedata
, bool probe
)
5702 Elf64_External_Shdr
* shdrs
;
5703 Elf_Internal_Shdr
* internal
;
5705 unsigned int size
= filedata
->file_header
.e_shentsize
;
5706 unsigned int num
= probe
? 1 : filedata
->file_header
.e_shnum
;
5708 /* PR binutils/17531: Cope with unexpected section header sizes. */
5709 if (size
== 0 || num
== 0)
5712 if (size
< sizeof * shdrs
)
5715 error (_("The e_shentsize field in the ELF header is less than the size of an ELF section header\n"));
5719 if (! probe
&& size
> sizeof * shdrs
)
5720 warn (_("The e_shentsize field in the ELF header is larger than the size of an ELF section header\n"));
5722 shdrs
= (Elf64_External_Shdr
*) get_data (NULL
, filedata
,
5723 filedata
->file_header
.e_shoff
,
5725 probe
? NULL
: _("section headers"));
5729 free (filedata
->section_headers
);
5730 filedata
->section_headers
= (Elf_Internal_Shdr
*)
5731 cmalloc (num
, sizeof (Elf_Internal_Shdr
));
5732 if (filedata
->section_headers
== NULL
)
5735 error (_("Out of memory reading %u section headers\n"), num
);
5740 for (i
= 0, internal
= filedata
->section_headers
;
5744 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
5745 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
5746 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
5747 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
5748 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
5749 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
5750 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
5751 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
5752 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
5753 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
5754 if (!probe
&& internal
->sh_link
> num
)
5755 warn (_("Section %u has an out of range sh_link value of %u\n"), i
, internal
->sh_link
);
5756 if (!probe
&& internal
->sh_flags
& SHF_INFO_LINK
&& internal
->sh_info
> num
)
5757 warn (_("Section %u has an out of range sh_info value of %u\n"), i
, internal
->sh_info
);
5764 static Elf_Internal_Sym
*
5765 get_32bit_elf_symbols (Filedata
* filedata
,
5766 Elf_Internal_Shdr
* section
,
5767 unsigned long * num_syms_return
)
5769 unsigned long number
= 0;
5770 Elf32_External_Sym
* esyms
= NULL
;
5771 Elf_External_Sym_Shndx
* shndx
= NULL
;
5772 Elf_Internal_Sym
* isyms
= NULL
;
5773 Elf_Internal_Sym
* psym
;
5775 elf_section_list
* entry
;
5777 if (section
->sh_size
== 0)
5779 if (num_syms_return
!= NULL
)
5780 * num_syms_return
= 0;
5784 /* Run some sanity checks first. */
5785 if (section
->sh_entsize
== 0 || section
->sh_entsize
> section
->sh_size
)
5787 error (_("Section %s has an invalid sh_entsize of 0x%lx\n"),
5788 printable_section_name (filedata
, section
),
5789 (unsigned long) section
->sh_entsize
);
5793 if (section
->sh_size
> filedata
->file_size
)
5795 error (_("Section %s has an invalid sh_size of 0x%lx\n"),
5796 printable_section_name (filedata
, section
),
5797 (unsigned long) section
->sh_size
);
5801 number
= section
->sh_size
/ section
->sh_entsize
;
5803 if (number
* sizeof (Elf32_External_Sym
) > section
->sh_size
+ 1)
5805 error (_("Size (0x%lx) of section %s is not a multiple of its sh_entsize (0x%lx)\n"),
5806 (unsigned long) section
->sh_size
,
5807 printable_section_name (filedata
, section
),
5808 (unsigned long) section
->sh_entsize
);
5812 esyms
= (Elf32_External_Sym
*) get_data (NULL
, filedata
, section
->sh_offset
, 1,
5813 section
->sh_size
, _("symbols"));
5818 for (entry
= filedata
->symtab_shndx_list
; entry
!= NULL
; entry
= entry
->next
)
5820 if (entry
->hdr
->sh_link
!= (unsigned long) (section
- filedata
->section_headers
))
5825 error (_("Multiple symbol table index sections associated with the same symbol section\n"));
5829 shndx
= (Elf_External_Sym_Shndx
*) get_data (NULL
, filedata
,
5830 entry
->hdr
->sh_offset
,
5831 1, entry
->hdr
->sh_size
,
5832 _("symbol table section indices"));
5836 /* PR17531: file: heap-buffer-overflow */
5837 if (entry
->hdr
->sh_size
/ sizeof (Elf_External_Sym_Shndx
) < number
)
5839 error (_("Index section %s has an sh_size of 0x%lx - expected 0x%lx\n"),
5840 printable_section_name (filedata
, entry
->hdr
),
5841 (unsigned long) entry
->hdr
->sh_size
,
5842 (unsigned long) section
->sh_size
);
5847 isyms
= (Elf_Internal_Sym
*) cmalloc (number
, sizeof (Elf_Internal_Sym
));
5851 error (_("Out of memory reading %lu symbols\n"),
5852 (unsigned long) number
);
5856 for (j
= 0, psym
= isyms
; j
< number
; j
++, psym
++)
5858 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
5859 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
5860 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
5861 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
5862 if (psym
->st_shndx
== (SHN_XINDEX
& 0xffff) && shndx
!= NULL
)
5864 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
5865 else if (psym
->st_shndx
>= (SHN_LORESERVE
& 0xffff))
5866 psym
->st_shndx
+= SHN_LORESERVE
- (SHN_LORESERVE
& 0xffff);
5867 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
5868 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
5875 if (num_syms_return
!= NULL
)
5876 * num_syms_return
= isyms
== NULL
? 0 : number
;
5881 static Elf_Internal_Sym
*
5882 get_64bit_elf_symbols (Filedata
* filedata
,
5883 Elf_Internal_Shdr
* section
,
5884 unsigned long * num_syms_return
)
5886 unsigned long number
= 0;
5887 Elf64_External_Sym
* esyms
= NULL
;
5888 Elf_External_Sym_Shndx
* shndx
= NULL
;
5889 Elf_Internal_Sym
* isyms
= NULL
;
5890 Elf_Internal_Sym
* psym
;
5892 elf_section_list
* entry
;
5894 if (section
->sh_size
== 0)
5896 if (num_syms_return
!= NULL
)
5897 * num_syms_return
= 0;
5901 /* Run some sanity checks first. */
5902 if (section
->sh_entsize
== 0 || section
->sh_entsize
> section
->sh_size
)
5904 error (_("Section %s has an invalid sh_entsize of 0x%lx\n"),
5905 printable_section_name (filedata
, section
),
5906 (unsigned long) section
->sh_entsize
);
5910 if (section
->sh_size
> filedata
->file_size
)
5912 error (_("Section %s has an invalid sh_size of 0x%lx\n"),
5913 printable_section_name (filedata
, section
),
5914 (unsigned long) section
->sh_size
);
5918 number
= section
->sh_size
/ section
->sh_entsize
;
5920 if (number
* sizeof (Elf64_External_Sym
) > section
->sh_size
+ 1)
5922 error (_("Size (0x%lx) of section %s is not a multiple of its sh_entsize (0x%lx)\n"),
5923 (unsigned long) section
->sh_size
,
5924 printable_section_name (filedata
, section
),
5925 (unsigned long) section
->sh_entsize
);
5929 esyms
= (Elf64_External_Sym
*) get_data (NULL
, filedata
, section
->sh_offset
, 1,
5930 section
->sh_size
, _("symbols"));
5935 for (entry
= filedata
->symtab_shndx_list
; entry
!= NULL
; entry
= entry
->next
)
5937 if (entry
->hdr
->sh_link
!= (unsigned long) (section
- filedata
->section_headers
))
5942 error (_("Multiple symbol table index sections associated with the same symbol section\n"));
5946 shndx
= (Elf_External_Sym_Shndx
*) get_data (NULL
, filedata
,
5947 entry
->hdr
->sh_offset
,
5948 1, entry
->hdr
->sh_size
,
5949 _("symbol table section indices"));
5953 /* PR17531: file: heap-buffer-overflow */
5954 if (entry
->hdr
->sh_size
/ sizeof (Elf_External_Sym_Shndx
) < number
)
5956 error (_("Index section %s has an sh_size of 0x%lx - expected 0x%lx\n"),
5957 printable_section_name (filedata
, entry
->hdr
),
5958 (unsigned long) entry
->hdr
->sh_size
,
5959 (unsigned long) section
->sh_size
);
5964 isyms
= (Elf_Internal_Sym
*) cmalloc (number
, sizeof (Elf_Internal_Sym
));
5968 error (_("Out of memory reading %lu symbols\n"),
5969 (unsigned long) number
);
5973 for (j
= 0, psym
= isyms
; j
< number
; j
++, psym
++)
5975 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
5976 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
5977 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
5978 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
5980 if (psym
->st_shndx
== (SHN_XINDEX
& 0xffff) && shndx
!= NULL
)
5982 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
5983 else if (psym
->st_shndx
>= (SHN_LORESERVE
& 0xffff))
5984 psym
->st_shndx
+= SHN_LORESERVE
- (SHN_LORESERVE
& 0xffff);
5986 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
5987 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
5994 if (num_syms_return
!= NULL
)
5995 * num_syms_return
= isyms
== NULL
? 0 : number
;
6001 get_elf_section_flags (Filedata
* filedata
, bfd_vma sh_flags
)
6003 static char buff
[1024];
6005 unsigned int field_size
= is_32bit_elf
? 8 : 16;
6007 unsigned int size
= sizeof (buff
) - (field_size
+ 4 + 1);
6008 bfd_vma os_flags
= 0;
6009 bfd_vma proc_flags
= 0;
6010 bfd_vma unknown_flags
= 0;
6018 /* 0 */ { STRING_COMMA_LEN ("WRITE") },
6019 /* 1 */ { STRING_COMMA_LEN ("ALLOC") },
6020 /* 2 */ { STRING_COMMA_LEN ("EXEC") },
6021 /* 3 */ { STRING_COMMA_LEN ("MERGE") },
6022 /* 4 */ { STRING_COMMA_LEN ("STRINGS") },
6023 /* 5 */ { STRING_COMMA_LEN ("INFO LINK") },
6024 /* 6 */ { STRING_COMMA_LEN ("LINK ORDER") },
6025 /* 7 */ { STRING_COMMA_LEN ("OS NONCONF") },
6026 /* 8 */ { STRING_COMMA_LEN ("GROUP") },
6027 /* 9 */ { STRING_COMMA_LEN ("TLS") },
6028 /* IA-64 specific. */
6029 /* 10 */ { STRING_COMMA_LEN ("SHORT") },
6030 /* 11 */ { STRING_COMMA_LEN ("NORECOV") },
6031 /* IA-64 OpenVMS specific. */
6032 /* 12 */ { STRING_COMMA_LEN ("VMS_GLOBAL") },
6033 /* 13 */ { STRING_COMMA_LEN ("VMS_OVERLAID") },
6034 /* 14 */ { STRING_COMMA_LEN ("VMS_SHARED") },
6035 /* 15 */ { STRING_COMMA_LEN ("VMS_VECTOR") },
6036 /* 16 */ { STRING_COMMA_LEN ("VMS_ALLOC_64BIT") },
6037 /* 17 */ { STRING_COMMA_LEN ("VMS_PROTECTED") },
6039 /* 18 */ { STRING_COMMA_LEN ("EXCLUDE") },
6040 /* SPARC specific. */
6041 /* 19 */ { STRING_COMMA_LEN ("ORDERED") },
6042 /* 20 */ { STRING_COMMA_LEN ("COMPRESSED") },
6044 /* 21 */ { STRING_COMMA_LEN ("ENTRYSECT") },
6045 /* 22 */ { STRING_COMMA_LEN ("ARM_PURECODE") },
6046 /* 23 */ { STRING_COMMA_LEN ("COMDEF") },
6048 /* 24 */ { STRING_COMMA_LEN ("GNU_MBIND") },
6050 /* 25 */ { STRING_COMMA_LEN ("VLE") },
6052 /* 26 */ { STRING_COMMA_LEN ("GNU_RETAIN") },
6055 if (do_section_details
)
6057 sprintf (buff
, "[%*.*lx]: ",
6058 field_size
, field_size
, (unsigned long) sh_flags
);
6059 p
+= field_size
+ 4;
6066 flag
= sh_flags
& - sh_flags
;
6069 if (do_section_details
)
6073 case SHF_WRITE
: sindex
= 0; break;
6074 case SHF_ALLOC
: sindex
= 1; break;
6075 case SHF_EXECINSTR
: sindex
= 2; break;
6076 case SHF_MERGE
: sindex
= 3; break;
6077 case SHF_STRINGS
: sindex
= 4; break;
6078 case SHF_INFO_LINK
: sindex
= 5; break;
6079 case SHF_LINK_ORDER
: sindex
= 6; break;
6080 case SHF_OS_NONCONFORMING
: sindex
= 7; break;
6081 case SHF_GROUP
: sindex
= 8; break;
6082 case SHF_TLS
: sindex
= 9; break;
6083 case SHF_EXCLUDE
: sindex
= 18; break;
6084 case SHF_COMPRESSED
: sindex
= 20; break;
6088 switch (filedata
->file_header
.e_machine
)
6091 if (flag
== SHF_IA_64_SHORT
)
6093 else if (flag
== SHF_IA_64_NORECOV
)
6096 else if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_OPENVMS
)
6099 case SHF_IA_64_VMS_GLOBAL
: sindex
= 12; break;
6100 case SHF_IA_64_VMS_OVERLAID
: sindex
= 13; break;
6101 case SHF_IA_64_VMS_SHARED
: sindex
= 14; break;
6102 case SHF_IA_64_VMS_VECTOR
: sindex
= 15; break;
6103 case SHF_IA_64_VMS_ALLOC_64BIT
: sindex
= 16; break;
6104 case SHF_IA_64_VMS_PROTECTED
: sindex
= 17; break;
6115 case EM_OLD_SPARCV9
:
6116 case EM_SPARC32PLUS
:
6119 if (flag
== SHF_ORDERED
)
6126 case SHF_ENTRYSECT
: sindex
= 21; break;
6127 case SHF_ARM_PURECODE
: sindex
= 22; break;
6128 case SHF_COMDEF
: sindex
= 23; break;
6133 if (flag
== SHF_PPC_VLE
)
6140 switch (filedata
->file_header
.e_ident
[EI_OSABI
])
6143 case ELFOSABI_FREEBSD
:
6144 if (flag
== SHF_GNU_RETAIN
)
6148 if (flag
== SHF_GNU_MBIND
)
6149 /* We should not recognize SHF_GNU_MBIND for
6150 ELFOSABI_NONE, but binutils as of 2019-07-23 did
6151 not set the EI_OSABI header byte. */
6162 if (p
!= buff
+ field_size
+ 4)
6164 if (size
< (10 + 2))
6166 warn (_("Internal error: not enough buffer room for section flag info"));
6167 return _("<unknown>");
6174 size
-= flags
[sindex
].len
;
6175 p
= stpcpy (p
, flags
[sindex
].str
);
6177 else if (flag
& SHF_MASKOS
)
6179 else if (flag
& SHF_MASKPROC
)
6182 unknown_flags
|= flag
;
6188 case SHF_WRITE
: *p
= 'W'; break;
6189 case SHF_ALLOC
: *p
= 'A'; break;
6190 case SHF_EXECINSTR
: *p
= 'X'; break;
6191 case SHF_MERGE
: *p
= 'M'; break;
6192 case SHF_STRINGS
: *p
= 'S'; break;
6193 case SHF_INFO_LINK
: *p
= 'I'; break;
6194 case SHF_LINK_ORDER
: *p
= 'L'; break;
6195 case SHF_OS_NONCONFORMING
: *p
= 'O'; break;
6196 case SHF_GROUP
: *p
= 'G'; break;
6197 case SHF_TLS
: *p
= 'T'; break;
6198 case SHF_EXCLUDE
: *p
= 'E'; break;
6199 case SHF_COMPRESSED
: *p
= 'C'; break;
6202 if ((filedata
->file_header
.e_machine
== EM_X86_64
6203 || filedata
->file_header
.e_machine
== EM_L1OM
6204 || filedata
->file_header
.e_machine
== EM_K1OM
)
6205 && flag
== SHF_X86_64_LARGE
)
6207 else if (filedata
->file_header
.e_machine
== EM_ARM
6208 && flag
== SHF_ARM_PURECODE
)
6210 else if (filedata
->file_header
.e_machine
== EM_PPC
6211 && flag
== SHF_PPC_VLE
)
6213 else if (flag
& SHF_MASKOS
)
6215 switch (filedata
->file_header
.e_ident
[EI_OSABI
])
6218 case ELFOSABI_FREEBSD
:
6219 if (flag
== SHF_GNU_RETAIN
)
6226 if (flag
== SHF_GNU_MBIND
)
6228 /* We should not recognize SHF_GNU_MBIND for
6229 ELFOSABI_NONE, but binutils as of 2019-07-23 did
6230 not set the EI_OSABI header byte. */
6237 sh_flags
&= ~SHF_MASKOS
;
6241 else if (flag
& SHF_MASKPROC
)
6244 sh_flags
&= ~ SHF_MASKPROC
;
6254 if (do_section_details
)
6258 size
-= 5 + field_size
;
6259 if (p
!= buff
+ field_size
+ 4)
6263 warn (_("Internal error: not enough buffer room for section flag info"));
6264 return _("<unknown>");
6270 sprintf (p
, "OS (%*.*lx)", field_size
, field_size
,
6271 (unsigned long) os_flags
);
6272 p
+= 5 + field_size
;
6276 size
-= 7 + field_size
;
6277 if (p
!= buff
+ field_size
+ 4)
6281 warn (_("Internal error: not enough buffer room for section flag info"));
6282 return _("<unknown>");
6288 sprintf (p
, "PROC (%*.*lx)", field_size
, field_size
,
6289 (unsigned long) proc_flags
);
6290 p
+= 7 + field_size
;
6294 size
-= 10 + field_size
;
6295 if (p
!= buff
+ field_size
+ 4)
6299 warn (_("Internal error: not enough buffer room for section flag info"));
6300 return _("<unknown>");
6306 sprintf (p
, _("UNKNOWN (%*.*lx)"), field_size
, field_size
,
6307 (unsigned long) unknown_flags
);
6308 p
+= 10 + field_size
;
6316 static unsigned int ATTRIBUTE_WARN_UNUSED_RESULT
6317 get_compression_header (Elf_Internal_Chdr
*chdr
, unsigned char *buf
, bfd_size_type size
)
6321 Elf32_External_Chdr
*echdr
= (Elf32_External_Chdr
*) buf
;
6323 if (size
< sizeof (* echdr
))
6325 error (_("Compressed section is too small even for a compression header\n"));
6329 chdr
->ch_type
= BYTE_GET (echdr
->ch_type
);
6330 chdr
->ch_size
= BYTE_GET (echdr
->ch_size
);
6331 chdr
->ch_addralign
= BYTE_GET (echdr
->ch_addralign
);
6332 return sizeof (*echdr
);
6336 Elf64_External_Chdr
*echdr
= (Elf64_External_Chdr
*) buf
;
6338 if (size
< sizeof (* echdr
))
6340 error (_("Compressed section is too small even for a compression header\n"));
6344 chdr
->ch_type
= BYTE_GET (echdr
->ch_type
);
6345 chdr
->ch_size
= BYTE_GET (echdr
->ch_size
);
6346 chdr
->ch_addralign
= BYTE_GET (echdr
->ch_addralign
);
6347 return sizeof (*echdr
);
6352 process_section_headers (Filedata
* filedata
)
6354 Elf_Internal_Shdr
* section
;
6357 free (filedata
->section_headers
);
6358 filedata
->section_headers
= NULL
;
6359 free (filedata
->dynamic_symbols
);
6360 filedata
->dynamic_symbols
= NULL
;
6361 filedata
->num_dynamic_syms
= 0;
6362 free (filedata
->dynamic_strings
);
6363 filedata
->dynamic_strings
= NULL
;
6364 filedata
->dynamic_strings_length
= 0;
6365 free (filedata
->dynamic_syminfo
);
6366 filedata
->dynamic_syminfo
= NULL
;
6367 while (filedata
->symtab_shndx_list
!= NULL
)
6369 elf_section_list
*next
= filedata
->symtab_shndx_list
->next
;
6370 free (filedata
->symtab_shndx_list
);
6371 filedata
->symtab_shndx_list
= next
;
6374 if (filedata
->file_header
.e_shnum
== 0)
6376 /* PR binutils/12467. */
6377 if (filedata
->file_header
.e_shoff
!= 0)
6379 warn (_("possibly corrupt ELF file header - it has a non-zero"
6380 " section header offset, but no section headers\n"));
6383 else if (do_sections
)
6384 printf (_("\nThere are no sections in this file.\n"));
6389 if (do_sections
&& !do_header
)
6391 if (filedata
->is_separate
&& process_links
)
6392 printf (_("In linked file '%s': "), filedata
->file_name
);
6393 if (! filedata
->is_separate
|| process_links
)
6394 printf (ngettext ("There is %d section header, "
6395 "starting at offset 0x%lx:\n",
6396 "There are %d section headers, "
6397 "starting at offset 0x%lx:\n",
6398 filedata
->file_header
.e_shnum
),
6399 filedata
->file_header
.e_shnum
,
6400 (unsigned long) filedata
->file_header
.e_shoff
);
6405 if (! get_32bit_section_headers (filedata
, false))
6410 if (! get_64bit_section_headers (filedata
, false))
6414 /* Read in the string table, so that we have names to display. */
6415 if (filedata
->file_header
.e_shstrndx
!= SHN_UNDEF
6416 && filedata
->file_header
.e_shstrndx
< filedata
->file_header
.e_shnum
)
6418 section
= filedata
->section_headers
+ filedata
->file_header
.e_shstrndx
;
6420 if (section
->sh_size
!= 0)
6422 filedata
->string_table
= (char *) get_data (NULL
, filedata
, section
->sh_offset
,
6423 1, section
->sh_size
,
6426 filedata
->string_table_length
= filedata
->string_table
!= NULL
? section
->sh_size
: 0;
6430 /* Scan the sections for the dynamic symbol table
6431 and dynamic string table and debug sections. */
6432 eh_addr_size
= is_32bit_elf
? 4 : 8;
6433 switch (filedata
->file_header
.e_machine
)
6436 case EM_MIPS_RS3_LE
:
6437 /* The 64-bit MIPS EABI uses a combination of 32-bit ELF and 64-bit
6438 FDE addresses. However, the ABI also has a semi-official ILP32
6439 variant for which the normal FDE address size rules apply.
6441 GCC 4.0 marks EABI64 objects with a dummy .gcc_compiled_longXX
6442 section, where XX is the size of longs in bits. Unfortunately,
6443 earlier compilers provided no way of distinguishing ILP32 objects
6444 from LP64 objects, so if there's any doubt, we should assume that
6445 the official LP64 form is being used. */
6446 if ((filedata
->file_header
.e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
6447 && find_section (filedata
, ".gcc_compiled_long32") == NULL
)
6453 switch (filedata
->file_header
.e_flags
& EF_H8_MACH
)
6455 case E_H8_MACH_H8300
:
6456 case E_H8_MACH_H8300HN
:
6457 case E_H8_MACH_H8300SN
:
6458 case E_H8_MACH_H8300SXN
:
6461 case E_H8_MACH_H8300H
:
6462 case E_H8_MACH_H8300S
:
6463 case E_H8_MACH_H8300SX
:
6471 switch (filedata
->file_header
.e_flags
& EF_M32C_CPU_MASK
)
6473 case EF_M32C_CPU_M16C
:
6480 #define CHECK_ENTSIZE_VALUES(section, i, size32, size64) \
6483 bfd_size_type expected_entsize = is_32bit_elf ? size32 : size64; \
6484 if (section->sh_entsize != expected_entsize) \
6487 sprintf_vma (buf, section->sh_entsize); \
6488 /* Note: coded this way so that there is a single string for \
6490 error (_("Section %d has invalid sh_entsize of %s\n"), i, buf); \
6491 error (_("(Using the expected size of %u for the rest of this dump)\n"), \
6492 (unsigned) expected_entsize); \
6493 section->sh_entsize = expected_entsize; \
6498 #define CHECK_ENTSIZE(section, i, type) \
6499 CHECK_ENTSIZE_VALUES (section, i, sizeof (Elf32_External_##type), \
6500 sizeof (Elf64_External_##type))
6502 for (i
= 0, section
= filedata
->section_headers
;
6503 i
< filedata
->file_header
.e_shnum
;
6506 char * name
= SECTION_NAME_PRINT (section
);
6508 /* Run some sanity checks on the headers and
6509 possibly fill in some file data as well. */
6510 switch (section
->sh_type
)
6513 if (filedata
->dynamic_symbols
!= NULL
)
6515 error (_("File contains multiple dynamic symbol tables\n"));
6519 CHECK_ENTSIZE (section
, i
, Sym
);
6520 filedata
->dynamic_symbols
6521 = GET_ELF_SYMBOLS (filedata
, section
, &filedata
->num_dynamic_syms
);
6522 filedata
->dynamic_symtab_section
= section
;
6526 if (streq (name
, ".dynstr"))
6528 if (filedata
->dynamic_strings
!= NULL
)
6530 error (_("File contains multiple dynamic string tables\n"));
6534 filedata
->dynamic_strings
6535 = (char *) get_data (NULL
, filedata
, section
->sh_offset
,
6536 1, section
->sh_size
, _("dynamic strings"));
6537 filedata
->dynamic_strings_length
6538 = filedata
->dynamic_strings
== NULL
? 0 : section
->sh_size
;
6539 filedata
->dynamic_strtab_section
= section
;
6543 case SHT_SYMTAB_SHNDX
:
6545 elf_section_list
* entry
= xmalloc (sizeof * entry
);
6547 entry
->hdr
= section
;
6548 entry
->next
= filedata
->symtab_shndx_list
;
6549 filedata
->symtab_shndx_list
= entry
;
6554 CHECK_ENTSIZE (section
, i
, Sym
);
6558 CHECK_ENTSIZE_VALUES (section
, i
, GRP_ENTRY_SIZE
, GRP_ENTRY_SIZE
);
6562 CHECK_ENTSIZE (section
, i
, Rel
);
6563 if (do_checks
&& section
->sh_size
== 0)
6564 warn (_("Section '%s': zero-sized relocation section\n"), name
);
6568 CHECK_ENTSIZE (section
, i
, Rela
);
6569 if (do_checks
&& section
->sh_size
== 0)
6570 warn (_("Section '%s': zero-sized relocation section\n"), name
);
6575 /* Having a zero sized section is not illegal according to the
6576 ELF standard, but it might be an indication that something
6577 is wrong. So issue a warning if we are running in lint mode. */
6578 if (do_checks
&& section
->sh_size
== 0)
6579 warn (_("Section '%s': has a size of zero - is this intended ?\n"), name
);
6586 if ((do_debugging
|| do_debug_info
|| do_debug_abbrevs
6587 || do_debug_lines
|| do_debug_pubnames
|| do_debug_pubtypes
6588 || do_debug_aranges
|| do_debug_frames
|| do_debug_macinfo
6589 || do_debug_str
|| do_debug_str_offsets
|| do_debug_loc
6591 || do_debug_addr
|| do_debug_cu_index
|| do_debug_links
)
6592 && (const_strneq (name
, ".debug_")
6593 || const_strneq (name
, ".zdebug_")))
6596 name
+= sizeof (".zdebug_") - 1;
6598 name
+= sizeof (".debug_") - 1;
6601 || (do_debug_info
&& const_strneq (name
, "info"))
6602 || (do_debug_info
&& const_strneq (name
, "types"))
6603 || (do_debug_abbrevs
&& const_strneq (name
, "abbrev"))
6604 || (do_debug_lines
&& strcmp (name
, "line") == 0)
6605 || (do_debug_lines
&& const_strneq (name
, "line."))
6606 || (do_debug_pubnames
&& const_strneq (name
, "pubnames"))
6607 || (do_debug_pubtypes
&& const_strneq (name
, "pubtypes"))
6608 || (do_debug_pubnames
&& const_strneq (name
, "gnu_pubnames"))
6609 || (do_debug_pubtypes
&& const_strneq (name
, "gnu_pubtypes"))
6610 || (do_debug_aranges
&& const_strneq (name
, "aranges"))
6611 || (do_debug_ranges
&& const_strneq (name
, "ranges"))
6612 || (do_debug_ranges
&& const_strneq (name
, "rnglists"))
6613 || (do_debug_frames
&& const_strneq (name
, "frame"))
6614 || (do_debug_macinfo
&& const_strneq (name
, "macinfo"))
6615 || (do_debug_macinfo
&& const_strneq (name
, "macro"))
6616 || (do_debug_str
&& const_strneq (name
, "str"))
6617 || (do_debug_links
&& const_strneq (name
, "sup"))
6618 || (do_debug_str_offsets
&& const_strneq (name
, "str_offsets"))
6619 || (do_debug_loc
&& const_strneq (name
, "loc"))
6620 || (do_debug_loc
&& const_strneq (name
, "loclists"))
6621 || (do_debug_addr
&& const_strneq (name
, "addr"))
6622 || (do_debug_cu_index
&& const_strneq (name
, "cu_index"))
6623 || (do_debug_cu_index
&& const_strneq (name
, "tu_index"))
6625 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
6627 /* Linkonce section to be combined with .debug_info at link time. */
6628 else if ((do_debugging
|| do_debug_info
)
6629 && const_strneq (name
, ".gnu.linkonce.wi."))
6630 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
6631 else if (do_debug_frames
&& streq (name
, ".eh_frame"))
6632 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
6633 else if (do_gdb_index
&& (streq (name
, ".gdb_index")
6634 || streq (name
, ".debug_names")))
6635 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
6636 /* Trace sections for Itanium VMS. */
6637 else if ((do_debugging
|| do_trace_info
|| do_trace_abbrevs
6638 || do_trace_aranges
)
6639 && const_strneq (name
, ".trace_"))
6641 name
+= sizeof (".trace_") - 1;
6644 || (do_trace_info
&& streq (name
, "info"))
6645 || (do_trace_abbrevs
&& streq (name
, "abbrev"))
6646 || (do_trace_aranges
&& streq (name
, "aranges"))
6648 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
6650 else if ((do_debugging
|| do_debug_links
)
6651 && (const_strneq (name
, ".gnu_debuglink")
6652 || const_strneq (name
, ".gnu_debugaltlink")))
6653 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
6659 if (filedata
->is_separate
&& ! process_links
)
6662 if (filedata
->is_separate
)
6663 printf (_("\nSection Headers in linked file '%s':\n"), filedata
->file_name
);
6664 else if (filedata
->file_header
.e_shnum
> 1)
6665 printf (_("\nSection Headers:\n"));
6667 printf (_("\nSection Header:\n"));
6671 if (do_section_details
)
6673 printf (_(" [Nr] Name\n"));
6674 printf (_(" Type Addr Off Size ES Lk Inf Al\n"));
6678 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
6682 if (do_section_details
)
6684 printf (_(" [Nr] Name\n"));
6685 printf (_(" Type Address Off Size ES Lk Inf Al\n"));
6689 (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n"));
6693 if (do_section_details
)
6695 printf (_(" [Nr] Name\n"));
6696 printf (_(" Type Address Offset Link\n"));
6697 printf (_(" Size EntSize Info Align\n"));
6701 printf (_(" [Nr] Name Type Address Offset\n"));
6702 printf (_(" Size EntSize Flags Link Info Align\n"));
6706 if (do_section_details
)
6707 printf (_(" Flags\n"));
6709 for (i
= 0, section
= filedata
->section_headers
;
6710 i
< filedata
->file_header
.e_shnum
;
6713 /* Run some sanity checks on the section header. */
6715 /* Check the sh_link field. */
6716 switch (section
->sh_type
)
6720 if (section
->sh_link
== 0
6721 && (filedata
->file_header
.e_type
== ET_EXEC
6722 || filedata
->file_header
.e_type
== ET_DYN
))
6723 /* A dynamic relocation section where all entries use a
6724 zero symbol index need not specify a symtab section. */
6727 case SHT_SYMTAB_SHNDX
:
6731 case SHT_GNU_versym
:
6732 if (section
->sh_link
== 0
6733 || section
->sh_link
>= filedata
->file_header
.e_shnum
6734 || (filedata
->section_headers
[section
->sh_link
].sh_type
!= SHT_SYMTAB
6735 && filedata
->section_headers
[section
->sh_link
].sh_type
!= SHT_DYNSYM
))
6736 warn (_("[%2u]: Link field (%u) should index a symtab section.\n"),
6737 i
, section
->sh_link
);
6743 case SHT_GNU_verneed
:
6744 case SHT_GNU_verdef
:
6745 case SHT_GNU_LIBLIST
:
6746 if (section
->sh_link
== 0
6747 || section
->sh_link
>= filedata
->file_header
.e_shnum
6748 || filedata
->section_headers
[section
->sh_link
].sh_type
!= SHT_STRTAB
)
6749 warn (_("[%2u]: Link field (%u) should index a string section.\n"),
6750 i
, section
->sh_link
);
6753 case SHT_INIT_ARRAY
:
6754 case SHT_FINI_ARRAY
:
6755 case SHT_PREINIT_ARRAY
:
6756 if (section
->sh_type
< SHT_LOOS
&& section
->sh_link
!= 0)
6757 warn (_("[%2u]: Unexpected value (%u) in link field.\n"),
6758 i
, section
->sh_link
);
6762 /* FIXME: Add support for target specific section types. */
6763 #if 0 /* Currently we do not check other section types as there are too
6764 many special cases. Stab sections for example have a type
6765 of SHT_PROGBITS but an sh_link field that links to the .stabstr
6767 if (section
->sh_type
< SHT_LOOS
&& section
->sh_link
!= 0)
6768 warn (_("[%2u]: Unexpected value (%u) in link field.\n"),
6769 i
, section
->sh_link
);
6774 /* Check the sh_info field. */
6775 switch (section
->sh_type
)
6779 if (section
->sh_info
== 0
6780 && (filedata
->file_header
.e_type
== ET_EXEC
6781 || filedata
->file_header
.e_type
== ET_DYN
))
6782 /* Dynamic relocations apply to segments, so they do not
6783 need to specify the section they relocate. */
6785 if (section
->sh_info
== 0
6786 || section
->sh_info
>= filedata
->file_header
.e_shnum
6787 || (filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_PROGBITS
6788 && filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_NOBITS
6789 && filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_NOTE
6790 && filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_INIT_ARRAY
6791 && filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_FINI_ARRAY
6792 && filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_PREINIT_ARRAY
6793 /* FIXME: Are other section types valid ? */
6794 && filedata
->section_headers
[section
->sh_info
].sh_type
< SHT_LOOS
))
6795 warn (_("[%2u]: Info field (%u) should index a relocatable section.\n"),
6796 i
, section
->sh_info
);
6801 case SHT_SYMTAB_SHNDX
:
6802 case SHT_INIT_ARRAY
:
6803 case SHT_FINI_ARRAY
:
6804 case SHT_PREINIT_ARRAY
:
6805 if (section
->sh_info
!= 0)
6806 warn (_("[%2u]: Unexpected value (%u) in info field.\n"),
6807 i
, section
->sh_info
);
6813 /* A symbol index - we assume that it is valid. */
6817 /* FIXME: Add support for target specific section types. */
6818 if (section
->sh_type
== SHT_NOBITS
)
6819 /* NOBITS section headers with non-zero sh_info fields can be
6820 created when a binary is stripped of everything but its debug
6821 information. The stripped sections have their headers
6822 preserved but their types set to SHT_NOBITS. So do not check
6823 this type of section. */
6825 else if (section
->sh_flags
& SHF_INFO_LINK
)
6827 if (section
->sh_info
< 1 || section
->sh_info
>= filedata
->file_header
.e_shnum
)
6828 warn (_("[%2u]: Expected link to another section in info field"), i
);
6830 else if (section
->sh_type
< SHT_LOOS
6831 && (section
->sh_flags
& SHF_GNU_MBIND
) == 0
6832 && section
->sh_info
!= 0)
6833 warn (_("[%2u]: Unexpected value (%u) in info field.\n"),
6834 i
, section
->sh_info
);
6838 /* Check the sh_size field. */
6839 if (section
->sh_size
> filedata
->file_size
6840 && section
->sh_type
!= SHT_NOBITS
6841 && section
->sh_type
!= SHT_NULL
6842 && section
->sh_type
< SHT_LOOS
)
6843 warn (_("Size of section %u is larger than the entire file!\n"), i
);
6845 printf (" [%2u] ", i
);
6846 if (do_section_details
)
6847 printf ("%s\n ", printable_section_name (filedata
, section
));
6849 print_symbol (-17, SECTION_NAME_PRINT (section
));
6851 printf (do_wide
? " %-15s " : " %-15.15s ",
6852 get_section_type_name (filedata
, section
->sh_type
));
6856 const char * link_too_big
= NULL
;
6858 print_vma (section
->sh_addr
, LONG_HEX
);
6860 printf ( " %6.6lx %6.6lx %2.2lx",
6861 (unsigned long) section
->sh_offset
,
6862 (unsigned long) section
->sh_size
,
6863 (unsigned long) section
->sh_entsize
);
6865 if (do_section_details
)
6866 fputs (" ", stdout
);
6868 printf (" %3s ", get_elf_section_flags (filedata
, section
->sh_flags
));
6870 if (section
->sh_link
>= filedata
->file_header
.e_shnum
)
6873 /* The sh_link value is out of range. Normally this indicates
6874 an error but it can have special values in Solaris binaries. */
6875 switch (filedata
->file_header
.e_machine
)
6882 case EM_OLD_SPARCV9
:
6883 case EM_SPARC32PLUS
:
6886 if (section
->sh_link
== (SHN_BEFORE
& 0xffff))
6887 link_too_big
= "BEFORE";
6888 else if (section
->sh_link
== (SHN_AFTER
& 0xffff))
6889 link_too_big
= "AFTER";
6896 if (do_section_details
)
6898 if (link_too_big
!= NULL
&& * link_too_big
)
6899 printf ("<%s> ", link_too_big
);
6901 printf ("%2u ", section
->sh_link
);
6902 printf ("%3u %2lu\n", section
->sh_info
,
6903 (unsigned long) section
->sh_addralign
);
6906 printf ("%2u %3u %2lu\n",
6909 (unsigned long) section
->sh_addralign
);
6911 if (link_too_big
&& ! * link_too_big
)
6912 warn (_("section %u: sh_link value of %u is larger than the number of sections\n"),
6913 i
, section
->sh_link
);
6917 print_vma (section
->sh_addr
, LONG_HEX
);
6919 if ((long) section
->sh_offset
== section
->sh_offset
)
6920 printf (" %6.6lx", (unsigned long) section
->sh_offset
);
6924 print_vma (section
->sh_offset
, LONG_HEX
);
6927 if ((unsigned long) section
->sh_size
== section
->sh_size
)
6928 printf (" %6.6lx", (unsigned long) section
->sh_size
);
6932 print_vma (section
->sh_size
, LONG_HEX
);
6935 if ((unsigned long) section
->sh_entsize
== section
->sh_entsize
)
6936 printf (" %2.2lx", (unsigned long) section
->sh_entsize
);
6940 print_vma (section
->sh_entsize
, LONG_HEX
);
6943 if (do_section_details
)
6944 fputs (" ", stdout
);
6946 printf (" %3s ", get_elf_section_flags (filedata
, section
->sh_flags
));
6948 printf ("%2u %3u ", section
->sh_link
, section
->sh_info
);
6950 if ((unsigned long) section
->sh_addralign
== section
->sh_addralign
)
6951 printf ("%2lu\n", (unsigned long) section
->sh_addralign
);
6954 print_vma (section
->sh_addralign
, DEC
);
6958 else if (do_section_details
)
6961 print_vma (section
->sh_addr
, LONG_HEX
);
6962 if ((long) section
->sh_offset
== section
->sh_offset
)
6963 printf (" %16.16lx", (unsigned long) section
->sh_offset
);
6967 print_vma (section
->sh_offset
, LONG_HEX
);
6969 printf (" %u\n ", section
->sh_link
);
6970 print_vma (section
->sh_size
, LONG_HEX
);
6972 print_vma (section
->sh_entsize
, LONG_HEX
);
6974 printf (" %-16u %lu\n",
6976 (unsigned long) section
->sh_addralign
);
6981 print_vma (section
->sh_addr
, LONG_HEX
);
6982 if ((long) section
->sh_offset
== section
->sh_offset
)
6983 printf (" %8.8lx", (unsigned long) section
->sh_offset
);
6987 print_vma (section
->sh_offset
, LONG_HEX
);
6990 print_vma (section
->sh_size
, LONG_HEX
);
6992 print_vma (section
->sh_entsize
, LONG_HEX
);
6994 printf (" %3s ", get_elf_section_flags (filedata
, section
->sh_flags
));
6996 printf (" %2u %3u %lu\n",
6999 (unsigned long) section
->sh_addralign
);
7002 if (do_section_details
)
7004 printf (" %s\n", get_elf_section_flags (filedata
, section
->sh_flags
));
7005 if ((section
->sh_flags
& SHF_COMPRESSED
) != 0)
7007 /* Minimum section size is 12 bytes for 32-bit compression
7008 header + 12 bytes for compressed data header. */
7009 unsigned char buf
[24];
7011 assert (sizeof (buf
) >= sizeof (Elf64_External_Chdr
));
7012 if (get_data (&buf
, filedata
, section
->sh_offset
, 1,
7013 sizeof (buf
), _("compression header")))
7015 Elf_Internal_Chdr chdr
;
7017 if (get_compression_header (&chdr
, buf
, sizeof (buf
)) == 0)
7018 printf (_(" [<corrupt>]\n"));
7021 if (chdr
.ch_type
== ELFCOMPRESS_ZLIB
)
7024 printf (_(" [<unknown>: 0x%x], "),
7026 print_vma (chdr
.ch_size
, LONG_HEX
);
7027 printf (", %lu\n", (unsigned long) chdr
.ch_addralign
);
7034 if (!do_section_details
)
7036 /* The ordering of the letters shown here matches the ordering of the
7037 corresponding SHF_xxx values, and hence the order in which these
7038 letters will be displayed to the user. */
7039 printf (_("Key to Flags:\n\
7040 W (write), A (alloc), X (execute), M (merge), S (strings), I (info),\n\
7041 L (link order), O (extra OS processing required), G (group), T (TLS),\n\
7042 C (compressed), x (unknown), o (OS specific), E (exclude),\n "));
7043 switch (filedata
->file_header
.e_ident
[EI_OSABI
])
7046 case ELFOSABI_FREEBSD
:
7047 printf (_("R (retain), "));
7050 printf (_("D (mbind), "));
7055 if (filedata
->file_header
.e_machine
== EM_X86_64
7056 || filedata
->file_header
.e_machine
== EM_L1OM
7057 || filedata
->file_header
.e_machine
== EM_K1OM
)
7058 printf (_("l (large), "));
7059 else if (filedata
->file_header
.e_machine
== EM_ARM
)
7060 printf (_("y (purecode), "));
7061 else if (filedata
->file_header
.e_machine
== EM_PPC
)
7062 printf (_("v (VLE), "));
7063 printf ("p (processor specific)\n");
7070 get_symtab (Filedata
*filedata
, Elf_Internal_Shdr
*symsec
,
7071 Elf_Internal_Sym
**symtab
, unsigned long *nsyms
,
7072 char **strtab
, unsigned long *strtablen
)
7076 *symtab
= GET_ELF_SYMBOLS (filedata
, symsec
, nsyms
);
7078 if (*symtab
== NULL
)
7081 if (symsec
->sh_link
!= 0)
7083 Elf_Internal_Shdr
*strsec
;
7085 if (symsec
->sh_link
>= filedata
->file_header
.e_shnum
)
7087 error (_("Bad sh_link in symbol table section\n"));
7094 strsec
= filedata
->section_headers
+ symsec
->sh_link
;
7096 *strtab
= (char *) get_data (NULL
, filedata
, strsec
->sh_offset
,
7097 1, strsec
->sh_size
, _("string table"));
7098 if (*strtab
== NULL
)
7105 *strtablen
= strsec
->sh_size
;
7111 get_group_flags (unsigned int flags
)
7113 static char buff
[128];
7117 else if (flags
== GRP_COMDAT
)
7120 snprintf (buff
, sizeof buff
, "[0x%x: %s%s%s]",
7122 flags
& GRP_MASKOS
? _("<OS specific>") : "",
7123 flags
& GRP_MASKPROC
? _("<PROC specific>") : "",
7124 (flags
& ~(GRP_COMDAT
| GRP_MASKOS
| GRP_MASKPROC
)
7125 ? _("<unknown>") : ""));
7131 process_section_groups (Filedata
* filedata
)
7133 Elf_Internal_Shdr
* section
;
7135 struct group
* group
;
7136 Elf_Internal_Shdr
* symtab_sec
;
7137 Elf_Internal_Shdr
* strtab_sec
;
7138 Elf_Internal_Sym
* symtab
;
7139 unsigned long num_syms
;
7143 /* Don't process section groups unless needed. */
7144 if (!do_unwind
&& !do_section_groups
)
7147 if (filedata
->file_header
.e_shnum
== 0)
7149 if (do_section_groups
)
7151 if (filedata
->is_separate
)
7152 printf (_("\nThere are no sections group in linked file '%s'.\n"),
7153 filedata
->file_name
);
7155 printf (_("\nThere are no section groups in this file.\n"));
7160 if (filedata
->section_headers
== NULL
)
7162 error (_("Section headers are not available!\n"));
7163 /* PR 13622: This can happen with a corrupt ELF header. */
7167 filedata
->section_headers_groups
7168 = (struct group
**) calloc (filedata
->file_header
.e_shnum
,
7169 sizeof (struct group
*));
7171 if (filedata
->section_headers_groups
== NULL
)
7173 error (_("Out of memory reading %u section group headers\n"),
7174 filedata
->file_header
.e_shnum
);
7178 /* Scan the sections for the group section. */
7179 filedata
->group_count
= 0;
7180 for (i
= 0, section
= filedata
->section_headers
;
7181 i
< filedata
->file_header
.e_shnum
;
7183 if (section
->sh_type
== SHT_GROUP
)
7184 filedata
->group_count
++;
7186 if (filedata
->group_count
== 0)
7188 if (do_section_groups
)
7190 if (filedata
->is_separate
)
7191 printf (_("\nThere are no section groups in linked file '%s'.\n"),
7192 filedata
->file_name
);
7194 printf (_("\nThere are no section groups in this file.\n"));
7200 filedata
->section_groups
= (struct group
*) calloc (filedata
->group_count
,
7201 sizeof (struct group
));
7203 if (filedata
->section_groups
== NULL
)
7205 error (_("Out of memory reading %lu groups\n"),
7206 (unsigned long) filedata
->group_count
);
7217 if (filedata
->is_separate
)
7218 printf (_("Section groups in linked file '%s'\n"), filedata
->file_name
);
7220 for (i
= 0, section
= filedata
->section_headers
, group
= filedata
->section_groups
;
7221 i
< filedata
->file_header
.e_shnum
;
7224 if (section
->sh_type
== SHT_GROUP
)
7226 const char * name
= printable_section_name (filedata
, section
);
7227 const char * group_name
;
7228 unsigned char * start
;
7229 unsigned char * indices
;
7230 unsigned int entry
, j
, size
;
7231 Elf_Internal_Shdr
* sec
;
7232 Elf_Internal_Sym
* sym
;
7234 /* Get the symbol table. */
7235 if (section
->sh_link
>= filedata
->file_header
.e_shnum
7236 || ((sec
= filedata
->section_headers
+ section
->sh_link
)->sh_type
7239 error (_("Bad sh_link in group section `%s'\n"), name
);
7243 if (symtab_sec
!= sec
)
7247 symtab
= GET_ELF_SYMBOLS (filedata
, symtab_sec
, & num_syms
);
7252 error (_("Corrupt header in group section `%s'\n"), name
);
7256 if (section
->sh_info
>= num_syms
)
7258 error (_("Bad sh_info in group section `%s'\n"), name
);
7262 sym
= symtab
+ section
->sh_info
;
7264 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
7266 if (sym
->st_shndx
== 0
7267 || sym
->st_shndx
>= filedata
->file_header
.e_shnum
)
7269 error (_("Bad sh_info in group section `%s'\n"), name
);
7273 group_name
= SECTION_NAME_PRINT (filedata
->section_headers
7282 /* Get the string table. */
7283 if (symtab_sec
->sh_link
>= filedata
->file_header
.e_shnum
)
7291 != (sec
= filedata
->section_headers
+ symtab_sec
->sh_link
))
7296 strtab
= (char *) get_data (NULL
, filedata
, strtab_sec
->sh_offset
,
7297 1, strtab_sec
->sh_size
,
7299 strtab_size
= strtab
!= NULL
? strtab_sec
->sh_size
: 0;
7301 group_name
= sym
->st_name
< strtab_size
7302 ? strtab
+ sym
->st_name
: _("<corrupt>");
7305 /* PR 17531: file: loop. */
7306 if (section
->sh_entsize
> section
->sh_size
)
7308 error (_("Section %s has sh_entsize (0x%lx) which is larger than its size (0x%lx)\n"),
7309 printable_section_name (filedata
, section
),
7310 (unsigned long) section
->sh_entsize
,
7311 (unsigned long) section
->sh_size
);
7315 start
= (unsigned char *) get_data (NULL
, filedata
, section
->sh_offset
,
7316 1, section
->sh_size
,
7322 size
= (section
->sh_size
/ section
->sh_entsize
) - 1;
7323 entry
= byte_get (indices
, 4);
7326 if (do_section_groups
)
7328 printf (_("\n%sgroup section [%5u] `%s' [%s] contains %u sections:\n"),
7329 get_group_flags (entry
), i
, name
, group_name
, size
);
7331 printf (_(" [Index] Name\n"));
7334 group
->group_index
= i
;
7336 for (j
= 0; j
< size
; j
++)
7338 struct group_list
* g
;
7340 entry
= byte_get (indices
, 4);
7343 if (entry
>= filedata
->file_header
.e_shnum
)
7345 static unsigned num_group_errors
= 0;
7347 if (num_group_errors
++ < 10)
7349 error (_("section [%5u] in group section [%5u] > maximum section [%5u]\n"),
7350 entry
, i
, filedata
->file_header
.e_shnum
- 1);
7351 if (num_group_errors
== 10)
7352 warn (_("Further error messages about overlarge group section indices suppressed\n"));
7357 if (filedata
->section_headers_groups
[entry
] != NULL
)
7361 static unsigned num_errs
= 0;
7363 if (num_errs
++ < 10)
7365 error (_("section [%5u] in group section [%5u] already in group section [%5u]\n"),
7367 filedata
->section_headers_groups
[entry
]->group_index
);
7369 warn (_("Further error messages about already contained group sections suppressed\n"));
7375 /* Intel C/C++ compiler may put section 0 in a
7376 section group. We just warn it the first time
7377 and ignore it afterwards. */
7378 static bool warned
= false;
7381 error (_("section 0 in group section [%5u]\n"),
7382 filedata
->section_headers_groups
[entry
]->group_index
);
7388 filedata
->section_headers_groups
[entry
] = group
;
7390 if (do_section_groups
)
7392 sec
= filedata
->section_headers
+ entry
;
7393 printf (" [%5u] %s\n", entry
, printable_section_name (filedata
, sec
));
7396 g
= (struct group_list
*) xmalloc (sizeof (struct group_list
));
7397 g
->section_index
= entry
;
7398 g
->next
= group
->root
;
7413 /* Data used to display dynamic fixups. */
7415 struct ia64_vms_dynfixup
7417 bfd_vma needed_ident
; /* Library ident number. */
7418 bfd_vma needed
; /* Index in the dstrtab of the library name. */
7419 bfd_vma fixup_needed
; /* Index of the library. */
7420 bfd_vma fixup_rela_cnt
; /* Number of fixups. */
7421 bfd_vma fixup_rela_off
; /* Fixups offset in the dynamic segment. */
7424 /* Data used to display dynamic relocations. */
7426 struct ia64_vms_dynimgrela
7428 bfd_vma img_rela_cnt
; /* Number of relocations. */
7429 bfd_vma img_rela_off
; /* Reloc offset in the dynamic segment. */
7432 /* Display IA-64 OpenVMS dynamic fixups (used to dynamically link a shared
7436 dump_ia64_vms_dynamic_fixups (Filedata
* filedata
,
7437 struct ia64_vms_dynfixup
* fixup
,
7438 const char * strtab
,
7439 unsigned int strtab_sz
)
7441 Elf64_External_VMS_IMAGE_FIXUP
* imfs
;
7443 const char * lib_name
;
7445 imfs
= get_data (NULL
, filedata
,
7446 filedata
->dynamic_addr
+ fixup
->fixup_rela_off
,
7447 sizeof (*imfs
), fixup
->fixup_rela_cnt
,
7448 _("dynamic section image fixups"));
7452 if (fixup
->needed
< strtab_sz
)
7453 lib_name
= strtab
+ fixup
->needed
;
7456 warn (_("corrupt library name index of 0x%lx found in dynamic entry"),
7457 (unsigned long) fixup
->needed
);
7461 printf (_("\nImage fixups for needed library #%d: %s - ident: %lx\n"),
7462 (int) fixup
->fixup_needed
, lib_name
, (long) fixup
->needed_ident
);
7464 (_("Seg Offset Type SymVec DataType\n"));
7466 for (i
= 0; i
< (long) fixup
->fixup_rela_cnt
; i
++)
7471 printf ("%3u ", (unsigned) BYTE_GET (imfs
[i
].fixup_seg
));
7472 printf_vma ((bfd_vma
) BYTE_GET (imfs
[i
].fixup_offset
));
7473 type
= BYTE_GET (imfs
[i
].type
);
7474 rtype
= elf_ia64_reloc_type (type
);
7476 printf (" 0x%08x ", type
);
7478 printf (" %-32s ", rtype
);
7479 printf ("%6u ", (unsigned) BYTE_GET (imfs
[i
].symvec_index
));
7480 printf ("0x%08x\n", (unsigned) BYTE_GET (imfs
[i
].data_type
));
7487 /* Display IA-64 OpenVMS dynamic relocations (used to relocate an image). */
7490 dump_ia64_vms_dynamic_relocs (Filedata
* filedata
, struct ia64_vms_dynimgrela
*imgrela
)
7492 Elf64_External_VMS_IMAGE_RELA
*imrs
;
7495 imrs
= get_data (NULL
, filedata
,
7496 filedata
->dynamic_addr
+ imgrela
->img_rela_off
,
7497 sizeof (*imrs
), imgrela
->img_rela_cnt
,
7498 _("dynamic section image relocations"));
7502 printf (_("\nImage relocs\n"));
7504 (_("Seg Offset Type Addend Seg Sym Off\n"));
7506 for (i
= 0; i
< (long) imgrela
->img_rela_cnt
; i
++)
7511 printf ("%3u ", (unsigned) BYTE_GET (imrs
[i
].rela_seg
));
7512 printf ("%08" BFD_VMA_FMT
"x ",
7513 (bfd_vma
) BYTE_GET (imrs
[i
].rela_offset
));
7514 type
= BYTE_GET (imrs
[i
].type
);
7515 rtype
= elf_ia64_reloc_type (type
);
7517 printf ("0x%08x ", type
);
7519 printf ("%-31s ", rtype
);
7520 print_vma (BYTE_GET (imrs
[i
].addend
), FULL_HEX
);
7521 printf ("%3u ", (unsigned) BYTE_GET (imrs
[i
].sym_seg
));
7522 printf ("%08" BFD_VMA_FMT
"x\n",
7523 (bfd_vma
) BYTE_GET (imrs
[i
].sym_offset
));
7530 /* Display IA-64 OpenVMS dynamic relocations and fixups. */
7533 process_ia64_vms_dynamic_relocs (Filedata
* filedata
)
7535 struct ia64_vms_dynfixup fixup
;
7536 struct ia64_vms_dynimgrela imgrela
;
7537 Elf_Internal_Dyn
*entry
;
7538 bfd_vma strtab_off
= 0;
7539 bfd_vma strtab_sz
= 0;
7540 char *strtab
= NULL
;
7543 memset (&fixup
, 0, sizeof (fixup
));
7544 memset (&imgrela
, 0, sizeof (imgrela
));
7546 /* Note: the order of the entries is specified by the OpenVMS specs. */
7547 for (entry
= filedata
->dynamic_section
;
7548 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
7551 switch (entry
->d_tag
)
7553 case DT_IA_64_VMS_STRTAB_OFFSET
:
7554 strtab_off
= entry
->d_un
.d_val
;
7557 strtab_sz
= entry
->d_un
.d_val
;
7559 strtab
= get_data (NULL
, filedata
,
7560 filedata
->dynamic_addr
+ strtab_off
,
7561 1, strtab_sz
, _("dynamic string section"));
7566 case DT_IA_64_VMS_NEEDED_IDENT
:
7567 fixup
.needed_ident
= entry
->d_un
.d_val
;
7570 fixup
.needed
= entry
->d_un
.d_val
;
7572 case DT_IA_64_VMS_FIXUP_NEEDED
:
7573 fixup
.fixup_needed
= entry
->d_un
.d_val
;
7575 case DT_IA_64_VMS_FIXUP_RELA_CNT
:
7576 fixup
.fixup_rela_cnt
= entry
->d_un
.d_val
;
7578 case DT_IA_64_VMS_FIXUP_RELA_OFF
:
7579 fixup
.fixup_rela_off
= entry
->d_un
.d_val
;
7580 if (! dump_ia64_vms_dynamic_fixups (filedata
, &fixup
, strtab
, strtab_sz
))
7583 case DT_IA_64_VMS_IMG_RELA_CNT
:
7584 imgrela
.img_rela_cnt
= entry
->d_un
.d_val
;
7586 case DT_IA_64_VMS_IMG_RELA_OFF
:
7587 imgrela
.img_rela_off
= entry
->d_un
.d_val
;
7588 if (! dump_ia64_vms_dynamic_relocs (filedata
, &imgrela
))
7609 dynamic_relocations
[] =
7611 { "REL", DT_REL
, DT_RELSZ
, false },
7612 { "RELA", DT_RELA
, DT_RELASZ
, true },
7613 { "PLT", DT_JMPREL
, DT_PLTRELSZ
, UNKNOWN
}
7616 /* Process the reloc section. */
7619 process_relocs (Filedata
* filedata
)
7621 unsigned long rel_size
;
7622 unsigned long rel_offset
;
7627 if (do_using_dynamic
)
7631 bool has_dynamic_reloc
;
7634 has_dynamic_reloc
= false;
7636 for (i
= 0; i
< ARRAY_SIZE (dynamic_relocations
); i
++)
7638 is_rela
= dynamic_relocations
[i
].rela
;
7639 name
= dynamic_relocations
[i
].name
;
7640 rel_size
= filedata
->dynamic_info
[dynamic_relocations
[i
].size
];
7641 rel_offset
= filedata
->dynamic_info
[dynamic_relocations
[i
].reloc
];
7644 has_dynamic_reloc
= true;
7646 if (is_rela
== UNKNOWN
)
7648 if (dynamic_relocations
[i
].reloc
== DT_JMPREL
)
7649 switch (filedata
->dynamic_info
[DT_PLTREL
])
7662 if (filedata
->is_separate
)
7664 (_("\nIn linked file '%s' section '%s' at offset 0x%lx contains %ld bytes:\n"),
7665 filedata
->file_name
, name
, rel_offset
, rel_size
);
7668 (_("\n'%s' relocation section at offset 0x%lx contains %ld bytes:\n"),
7669 name
, rel_offset
, rel_size
);
7672 dump_relocations (filedata
,
7673 offset_from_vma (filedata
, rel_offset
, rel_size
),
7675 filedata
->dynamic_symbols
,
7676 filedata
->num_dynamic_syms
,
7677 filedata
->dynamic_strings
,
7678 filedata
->dynamic_strings_length
,
7679 is_rela
, true /* is_dynamic */);
7683 if (is_ia64_vms (filedata
))
7684 if (process_ia64_vms_dynamic_relocs (filedata
))
7685 has_dynamic_reloc
= true;
7687 if (! has_dynamic_reloc
)
7689 if (filedata
->is_separate
)
7690 printf (_("\nThere are no dynamic relocations in linked file '%s'.\n"),
7691 filedata
->file_name
);
7693 printf (_("\nThere are no dynamic relocations in this file.\n"));
7698 Elf_Internal_Shdr
* section
;
7702 for (i
= 0, section
= filedata
->section_headers
;
7703 i
< filedata
->file_header
.e_shnum
;
7706 if ( section
->sh_type
!= SHT_RELA
7707 && section
->sh_type
!= SHT_REL
)
7710 rel_offset
= section
->sh_offset
;
7711 rel_size
= section
->sh_size
;
7716 unsigned long num_rela
;
7718 if (filedata
->is_separate
)
7719 printf (_("\nIn linked file '%s' relocation section "),
7720 filedata
->file_name
);
7722 printf (_("\nRelocation section "));
7724 if (filedata
->string_table
== NULL
)
7725 printf ("%d", section
->sh_name
);
7727 printf ("'%s'", printable_section_name (filedata
, section
));
7729 num_rela
= rel_size
/ section
->sh_entsize
;
7730 printf (ngettext (" at offset 0x%lx contains %lu entry:\n",
7731 " at offset 0x%lx contains %lu entries:\n",
7733 rel_offset
, num_rela
);
7735 is_rela
= section
->sh_type
== SHT_RELA
;
7737 if (section
->sh_link
!= 0
7738 && section
->sh_link
< filedata
->file_header
.e_shnum
)
7740 Elf_Internal_Shdr
* symsec
;
7741 Elf_Internal_Sym
* symtab
;
7742 unsigned long nsyms
;
7743 unsigned long strtablen
= 0;
7744 char * strtab
= NULL
;
7746 symsec
= filedata
->section_headers
+ section
->sh_link
;
7747 if (symsec
->sh_type
!= SHT_SYMTAB
7748 && symsec
->sh_type
!= SHT_DYNSYM
)
7751 if (!get_symtab (filedata
, symsec
,
7752 &symtab
, &nsyms
, &strtab
, &strtablen
))
7755 dump_relocations (filedata
, rel_offset
, rel_size
,
7756 symtab
, nsyms
, strtab
, strtablen
,
7758 symsec
->sh_type
== SHT_DYNSYM
);
7763 dump_relocations (filedata
, rel_offset
, rel_size
,
7764 NULL
, 0, NULL
, 0, is_rela
,
7765 false /* is_dynamic */);
7773 /* Users sometimes forget the -D option, so try to be helpful. */
7774 for (i
= 0; i
< ARRAY_SIZE (dynamic_relocations
); i
++)
7776 if (filedata
->dynamic_info
[dynamic_relocations
[i
].size
])
7778 if (filedata
->is_separate
)
7779 printf (_("\nThere are no static relocations in linked file '%s'."),
7780 filedata
->file_name
);
7782 printf (_("\nThere are no static relocations in this file."));
7783 printf (_("\nTo see the dynamic relocations add --use-dynamic to the command line.\n"));
7788 if (i
== ARRAY_SIZE (dynamic_relocations
))
7790 if (filedata
->is_separate
)
7791 printf (_("\nThere are no relocations in linked file '%s'.\n"),
7792 filedata
->file_name
);
7794 printf (_("\nThere are no relocations in this file.\n"));
7802 /* An absolute address consists of a section and an offset. If the
7803 section is NULL, the offset itself is the address, otherwise, the
7804 address equals to LOAD_ADDRESS(section) + offset. */
7808 unsigned short section
;
7812 /* Find the nearest symbol at or below ADDR. Returns the symbol
7813 name, if found, and the offset from the symbol to ADDR. */
7816 find_symbol_for_address (Filedata
* filedata
,
7817 Elf_Internal_Sym
* symtab
,
7818 unsigned long nsyms
,
7819 const char * strtab
,
7820 unsigned long strtab_size
,
7821 struct absaddr addr
,
7822 const char ** symname
,
7825 bfd_vma dist
= 0x100000;
7826 Elf_Internal_Sym
* sym
;
7827 Elf_Internal_Sym
* beg
;
7828 Elf_Internal_Sym
* end
;
7829 Elf_Internal_Sym
* best
= NULL
;
7831 REMOVE_ARCH_BITS (addr
.offset
);
7833 end
= symtab
+ nsyms
;
7839 sym
= beg
+ (end
- beg
) / 2;
7841 value
= sym
->st_value
;
7842 REMOVE_ARCH_BITS (value
);
7844 if (sym
->st_name
!= 0
7845 && (addr
.section
== SHN_UNDEF
|| addr
.section
== sym
->st_shndx
)
7846 && addr
.offset
>= value
7847 && addr
.offset
- value
< dist
)
7850 dist
= addr
.offset
- value
;
7855 if (addr
.offset
< value
)
7863 *symname
= (best
->st_name
>= strtab_size
7864 ? _("<corrupt>") : strtab
+ best
->st_name
);
7870 *offset
= addr
.offset
;
7873 static /* signed */ int
7874 symcmp (const void *p
, const void *q
)
7876 Elf_Internal_Sym
*sp
= (Elf_Internal_Sym
*) p
;
7877 Elf_Internal_Sym
*sq
= (Elf_Internal_Sym
*) q
;
7879 return sp
->st_value
> sq
->st_value
? 1 : (sp
->st_value
< sq
->st_value
? -1 : 0);
7882 /* Process the unwind section. */
7884 #include "unwind-ia64.h"
7886 struct ia64_unw_table_entry
7888 struct absaddr start
;
7890 struct absaddr info
;
7893 struct ia64_unw_aux_info
7895 struct ia64_unw_table_entry
* table
; /* Unwind table. */
7896 unsigned long table_len
; /* Length of unwind table. */
7897 unsigned char * info
; /* Unwind info. */
7898 unsigned long info_size
; /* Size of unwind info. */
7899 bfd_vma info_addr
; /* Starting address of unwind info. */
7900 bfd_vma seg_base
; /* Starting address of segment. */
7901 Elf_Internal_Sym
* symtab
; /* The symbol table. */
7902 unsigned long nsyms
; /* Number of symbols. */
7903 Elf_Internal_Sym
* funtab
; /* Sorted table of STT_FUNC symbols. */
7904 unsigned long nfuns
; /* Number of entries in funtab. */
7905 char * strtab
; /* The string table. */
7906 unsigned long strtab_size
; /* Size of string table. */
7910 dump_ia64_unwind (Filedata
* filedata
, struct ia64_unw_aux_info
* aux
)
7912 struct ia64_unw_table_entry
* tp
;
7913 unsigned long j
, nfuns
;
7917 aux
->funtab
= xmalloc (aux
->nsyms
* sizeof (Elf_Internal_Sym
));
7918 for (nfuns
= 0, j
= 0; j
< aux
->nsyms
; j
++)
7919 if (aux
->symtab
[j
].st_value
&& ELF_ST_TYPE (aux
->symtab
[j
].st_info
) == STT_FUNC
)
7920 aux
->funtab
[nfuns
++] = aux
->symtab
[j
];
7922 qsort (aux
->funtab
, aux
->nfuns
, sizeof (Elf_Internal_Sym
), symcmp
);
7924 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
7928 const unsigned char * dp
;
7929 const unsigned char * head
;
7930 const unsigned char * end
;
7931 const char * procname
;
7933 find_symbol_for_address (filedata
, aux
->funtab
, aux
->nfuns
, aux
->strtab
,
7934 aux
->strtab_size
, tp
->start
, &procname
, &offset
);
7936 fputs ("\n<", stdout
);
7940 fputs (procname
, stdout
);
7943 printf ("+%lx", (unsigned long) offset
);
7946 fputs (">: [", stdout
);
7947 print_vma (tp
->start
.offset
, PREFIX_HEX
);
7948 fputc ('-', stdout
);
7949 print_vma (tp
->end
.offset
, PREFIX_HEX
);
7950 printf ("], info at +0x%lx\n",
7951 (unsigned long) (tp
->info
.offset
- aux
->seg_base
));
7953 /* PR 17531: file: 86232b32. */
7954 if (aux
->info
== NULL
)
7957 offset
= tp
->info
.offset
;
7958 if (tp
->info
.section
)
7960 if (tp
->info
.section
>= filedata
->file_header
.e_shnum
)
7962 warn (_("Invalid section %u in table entry %ld\n"),
7963 tp
->info
.section
, (long) (tp
- aux
->table
));
7967 offset
+= filedata
->section_headers
[tp
->info
.section
].sh_addr
;
7969 offset
-= aux
->info_addr
;
7970 /* PR 17531: file: 0997b4d1. */
7971 if (offset
>= aux
->info_size
7972 || aux
->info_size
- offset
< 8)
7974 warn (_("Invalid offset %lx in table entry %ld\n"),
7975 (long) tp
->info
.offset
, (long) (tp
- aux
->table
));
7980 head
= aux
->info
+ offset
;
7981 stamp
= byte_get ((unsigned char *) head
, sizeof (stamp
));
7983 printf (" v%u, flags=0x%lx (%s%s), len=%lu bytes\n",
7984 (unsigned) UNW_VER (stamp
),
7985 (unsigned long) ((stamp
& UNW_FLAG_MASK
) >> 32),
7986 UNW_FLAG_EHANDLER (stamp
) ? " ehandler" : "",
7987 UNW_FLAG_UHANDLER (stamp
) ? " uhandler" : "",
7988 (unsigned long) (eh_addr_size
* UNW_LENGTH (stamp
)));
7990 if (UNW_VER (stamp
) != 1)
7992 printf (_("\tUnknown version.\n"));
7997 end
= head
+ 8 + eh_addr_size
* UNW_LENGTH (stamp
);
7998 /* PR 17531: file: 16ceda89. */
7999 if (end
> aux
->info
+ aux
->info_size
)
8000 end
= aux
->info
+ aux
->info_size
;
8001 for (dp
= head
+ 8; dp
< end
;)
8002 dp
= unw_decode (dp
, in_body
, & in_body
, end
);
8011 slurp_ia64_unwind_table (Filedata
* filedata
,
8012 struct ia64_unw_aux_info
* aux
,
8013 Elf_Internal_Shdr
* sec
)
8015 unsigned long size
, nrelas
, i
;
8016 Elf_Internal_Phdr
* seg
;
8017 struct ia64_unw_table_entry
* tep
;
8018 Elf_Internal_Shdr
* relsec
;
8019 Elf_Internal_Rela
* rela
;
8020 Elf_Internal_Rela
* rp
;
8021 unsigned char * table
;
8023 Elf_Internal_Sym
* sym
;
8024 const char * relname
;
8028 /* First, find the starting address of the segment that includes
8031 if (filedata
->file_header
.e_phnum
)
8033 if (! get_program_headers (filedata
))
8036 for (seg
= filedata
->program_headers
;
8037 seg
< filedata
->program_headers
+ filedata
->file_header
.e_phnum
;
8040 if (seg
->p_type
!= PT_LOAD
)
8043 if (sec
->sh_addr
>= seg
->p_vaddr
8044 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
8046 aux
->seg_base
= seg
->p_vaddr
;
8052 /* Second, build the unwind table from the contents of the unwind section: */
8053 size
= sec
->sh_size
;
8054 table
= (unsigned char *) get_data (NULL
, filedata
, sec
->sh_offset
, 1, size
,
8059 aux
->table_len
= size
/ (3 * eh_addr_size
);
8060 aux
->table
= (struct ia64_unw_table_entry
*)
8061 xcmalloc (aux
->table_len
, sizeof (aux
->table
[0]));
8064 for (tp
= table
; tp
<= table
+ size
- (3 * eh_addr_size
); ++tep
)
8066 tep
->start
.section
= SHN_UNDEF
;
8067 tep
->end
.section
= SHN_UNDEF
;
8068 tep
->info
.section
= SHN_UNDEF
;
8069 tep
->start
.offset
= byte_get (tp
, eh_addr_size
); tp
+= eh_addr_size
;
8070 tep
->end
.offset
= byte_get (tp
, eh_addr_size
); tp
+= eh_addr_size
;
8071 tep
->info
.offset
= byte_get (tp
, eh_addr_size
); tp
+= eh_addr_size
;
8072 tep
->start
.offset
+= aux
->seg_base
;
8073 tep
->end
.offset
+= aux
->seg_base
;
8074 tep
->info
.offset
+= aux
->seg_base
;
8078 /* Third, apply any relocations to the unwind table: */
8079 for (relsec
= filedata
->section_headers
;
8080 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
8083 if (relsec
->sh_type
!= SHT_RELA
8084 || relsec
->sh_info
>= filedata
->file_header
.e_shnum
8085 || filedata
->section_headers
+ relsec
->sh_info
!= sec
)
8088 if (!slurp_rela_relocs (filedata
, relsec
->sh_offset
, relsec
->sh_size
,
8097 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
8099 unsigned int sym_ndx
;
8100 unsigned int r_type
= get_reloc_type (filedata
, rp
->r_info
);
8101 relname
= elf_ia64_reloc_type (r_type
);
8103 /* PR 17531: file: 9fa67536. */
8104 if (relname
== NULL
)
8106 warn (_("Skipping unknown relocation type: %u\n"), r_type
);
8110 if (! const_strneq (relname
, "R_IA64_SEGREL"))
8112 warn (_("Skipping unexpected relocation type: %s\n"), relname
);
8116 i
= rp
->r_offset
/ (3 * eh_addr_size
);
8118 /* PR 17531: file: 5bc8d9bf. */
8119 if (i
>= aux
->table_len
)
8121 warn (_("Skipping reloc with overlarge offset: %lx\n"), i
);
8125 sym_ndx
= get_reloc_symindex (rp
->r_info
);
8126 if (sym_ndx
>= aux
->nsyms
)
8128 warn (_("Skipping reloc with invalid symbol index: %u\n"),
8132 sym
= aux
->symtab
+ sym_ndx
;
8134 switch (rp
->r_offset
/ eh_addr_size
% 3)
8137 aux
->table
[i
].start
.section
= sym
->st_shndx
;
8138 aux
->table
[i
].start
.offset
= rp
->r_addend
+ sym
->st_value
;
8141 aux
->table
[i
].end
.section
= sym
->st_shndx
;
8142 aux
->table
[i
].end
.offset
= rp
->r_addend
+ sym
->st_value
;
8145 aux
->table
[i
].info
.section
= sym
->st_shndx
;
8146 aux
->table
[i
].info
.offset
= rp
->r_addend
+ sym
->st_value
;
8160 ia64_process_unwind (Filedata
* filedata
)
8162 Elf_Internal_Shdr
* sec
;
8163 Elf_Internal_Shdr
* unwsec
= NULL
;
8164 unsigned long i
, unwcount
= 0, unwstart
= 0;
8165 struct ia64_unw_aux_info aux
;
8168 memset (& aux
, 0, sizeof (aux
));
8170 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
8172 if (sec
->sh_type
== SHT_SYMTAB
)
8176 error (_("Multiple symbol tables encountered\n"));
8182 if (!get_symtab (filedata
, sec
, &aux
.symtab
, &aux
.nsyms
,
8183 &aux
.strtab
, &aux
.strtab_size
))
8186 else if (sec
->sh_type
== SHT_IA_64_UNWIND
)
8191 printf (_("\nThere are no unwind sections in this file.\n"));
8193 while (unwcount
-- > 0)
8198 for (i
= unwstart
, sec
= filedata
->section_headers
+ unwstart
, unwsec
= NULL
;
8199 i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
8200 if (sec
->sh_type
== SHT_IA_64_UNWIND
)
8205 /* We have already counted the number of SHT_IA64_UNWIND
8206 sections so the loop above should never fail. */
8207 assert (unwsec
!= NULL
);
8210 len
= sizeof (ELF_STRING_ia64_unwind_once
) - 1;
8212 if ((unwsec
->sh_flags
& SHF_GROUP
) != 0)
8214 /* We need to find which section group it is in. */
8215 struct group_list
* g
;
8217 if (filedata
->section_headers_groups
== NULL
8218 || filedata
->section_headers_groups
[i
] == NULL
)
8219 i
= filedata
->file_header
.e_shnum
;
8222 g
= filedata
->section_headers_groups
[i
]->root
;
8224 for (; g
!= NULL
; g
= g
->next
)
8226 sec
= filedata
->section_headers
+ g
->section_index
;
8228 if (SECTION_NAME_VALID (sec
)
8229 && streq (SECTION_NAME (sec
), ELF_STRING_ia64_unwind_info
))
8234 i
= filedata
->file_header
.e_shnum
;
8237 else if (SECTION_NAME_VALID (unwsec
)
8238 && strneq (SECTION_NAME (unwsec
),
8239 ELF_STRING_ia64_unwind_once
, len
))
8241 /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO. */
8242 len2
= sizeof (ELF_STRING_ia64_unwind_info_once
) - 1;
8243 suffix
= SECTION_NAME (unwsec
) + len
;
8244 for (i
= 0, sec
= filedata
->section_headers
;
8245 i
< filedata
->file_header
.e_shnum
;
8247 if (SECTION_NAME_VALID (sec
)
8248 && strneq (SECTION_NAME (sec
),
8249 ELF_STRING_ia64_unwind_info_once
, len2
)
8250 && streq (SECTION_NAME (sec
) + len2
, suffix
))
8255 /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
8256 .IA_64.unwind or BAR -> .IA_64.unwind_info. */
8257 len
= sizeof (ELF_STRING_ia64_unwind
) - 1;
8258 len2
= sizeof (ELF_STRING_ia64_unwind_info
) - 1;
8260 if (SECTION_NAME_VALID (unwsec
)
8261 && strneq (SECTION_NAME (unwsec
), ELF_STRING_ia64_unwind
, len
))
8262 suffix
= SECTION_NAME (unwsec
) + len
;
8263 for (i
= 0, sec
= filedata
->section_headers
;
8264 i
< filedata
->file_header
.e_shnum
;
8266 if (SECTION_NAME_VALID (sec
)
8267 && strneq (SECTION_NAME (sec
), ELF_STRING_ia64_unwind_info
, len2
)
8268 && streq (SECTION_NAME (sec
) + len2
, suffix
))
8272 if (i
== filedata
->file_header
.e_shnum
)
8274 printf (_("\nCould not find unwind info section for "));
8276 if (filedata
->string_table
== NULL
)
8277 printf ("%d", unwsec
->sh_name
);
8279 printf ("'%s'", printable_section_name (filedata
, unwsec
));
8283 aux
.info_addr
= sec
->sh_addr
;
8284 aux
.info
= (unsigned char *) get_data (NULL
, filedata
, sec
->sh_offset
, 1,
8287 aux
.info_size
= aux
.info
== NULL
? 0 : sec
->sh_size
;
8289 printf (_("\nUnwind section "));
8291 if (filedata
->string_table
== NULL
)
8292 printf ("%d", unwsec
->sh_name
);
8294 printf ("'%s'", printable_section_name (filedata
, unwsec
));
8296 printf (_(" at offset 0x%lx contains %lu entries:\n"),
8297 (unsigned long) unwsec
->sh_offset
,
8298 (unsigned long) (unwsec
->sh_size
/ (3 * eh_addr_size
)));
8300 if (slurp_ia64_unwind_table (filedata
, & aux
, unwsec
)
8301 && aux
.table_len
> 0)
8302 dump_ia64_unwind (filedata
, & aux
);
8304 free ((char *) aux
.table
);
8305 free ((char *) aux
.info
);
8312 free ((char *) aux
.strtab
);
8317 struct hppa_unw_table_entry
8319 struct absaddr start
;
8321 unsigned int Cannot_unwind
:1; /* 0 */
8322 unsigned int Millicode
:1; /* 1 */
8323 unsigned int Millicode_save_sr0
:1; /* 2 */
8324 unsigned int Region_description
:2; /* 3..4 */
8325 unsigned int reserved1
:1; /* 5 */
8326 unsigned int Entry_SR
:1; /* 6 */
8327 unsigned int Entry_FR
:4; /* Number saved 7..10 */
8328 unsigned int Entry_GR
:5; /* Number saved 11..15 */
8329 unsigned int Args_stored
:1; /* 16 */
8330 unsigned int Variable_Frame
:1; /* 17 */
8331 unsigned int Separate_Package_Body
:1; /* 18 */
8332 unsigned int Frame_Extension_Millicode
:1; /* 19 */
8333 unsigned int Stack_Overflow_Check
:1; /* 20 */
8334 unsigned int Two_Instruction_SP_Increment
:1; /* 21 */
8335 unsigned int Ada_Region
:1; /* 22 */
8336 unsigned int cxx_info
:1; /* 23 */
8337 unsigned int cxx_try_catch
:1; /* 24 */
8338 unsigned int sched_entry_seq
:1; /* 25 */
8339 unsigned int reserved2
:1; /* 26 */
8340 unsigned int Save_SP
:1; /* 27 */
8341 unsigned int Save_RP
:1; /* 28 */
8342 unsigned int Save_MRP_in_frame
:1; /* 29 */
8343 unsigned int extn_ptr_defined
:1; /* 30 */
8344 unsigned int Cleanup_defined
:1; /* 31 */
8346 unsigned int MPE_XL_interrupt_marker
:1; /* 0 */
8347 unsigned int HP_UX_interrupt_marker
:1; /* 1 */
8348 unsigned int Large_frame
:1; /* 2 */
8349 unsigned int Pseudo_SP_Set
:1; /* 3 */
8350 unsigned int reserved4
:1; /* 4 */
8351 unsigned int Total_frame_size
:27; /* 5..31 */
8354 struct hppa_unw_aux_info
8356 struct hppa_unw_table_entry
* table
; /* Unwind table. */
8357 unsigned long table_len
; /* Length of unwind table. */
8358 bfd_vma seg_base
; /* Starting address of segment. */
8359 Elf_Internal_Sym
* symtab
; /* The symbol table. */
8360 unsigned long nsyms
; /* Number of symbols. */
8361 Elf_Internal_Sym
* funtab
; /* Sorted table of STT_FUNC symbols. */
8362 unsigned long nfuns
; /* Number of entries in funtab. */
8363 char * strtab
; /* The string table. */
8364 unsigned long strtab_size
; /* Size of string table. */
8368 dump_hppa_unwind (Filedata
* filedata
, struct hppa_unw_aux_info
* aux
)
8370 struct hppa_unw_table_entry
* tp
;
8371 unsigned long j
, nfuns
;
8374 aux
->funtab
= xmalloc (aux
->nsyms
* sizeof (Elf_Internal_Sym
));
8375 for (nfuns
= 0, j
= 0; j
< aux
->nsyms
; j
++)
8376 if (aux
->symtab
[j
].st_value
&& ELF_ST_TYPE (aux
->symtab
[j
].st_info
) == STT_FUNC
)
8377 aux
->funtab
[nfuns
++] = aux
->symtab
[j
];
8379 qsort (aux
->funtab
, aux
->nfuns
, sizeof (Elf_Internal_Sym
), symcmp
);
8381 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
8384 const char * procname
;
8386 find_symbol_for_address (filedata
, aux
->funtab
, aux
->nfuns
, aux
->strtab
,
8387 aux
->strtab_size
, tp
->start
, &procname
,
8390 fputs ("\n<", stdout
);
8394 fputs (procname
, stdout
);
8397 printf ("+%lx", (unsigned long) offset
);
8400 fputs (">: [", stdout
);
8401 print_vma (tp
->start
.offset
, PREFIX_HEX
);
8402 fputc ('-', stdout
);
8403 print_vma (tp
->end
.offset
, PREFIX_HEX
);
8406 #define PF(_m) if (tp->_m) printf (#_m " ");
8407 #define PV(_m) if (tp->_m) printf (#_m "=%d ", tp->_m);
8410 PF(Millicode_save_sr0
);
8411 /* PV(Region_description); */
8417 PF(Separate_Package_Body
);
8418 PF(Frame_Extension_Millicode
);
8419 PF(Stack_Overflow_Check
);
8420 PF(Two_Instruction_SP_Increment
);
8424 PF(sched_entry_seq
);
8427 PF(Save_MRP_in_frame
);
8428 PF(extn_ptr_defined
);
8429 PF(Cleanup_defined
);
8430 PF(MPE_XL_interrupt_marker
);
8431 PF(HP_UX_interrupt_marker
);
8434 PV(Total_frame_size
);
8447 slurp_hppa_unwind_table (Filedata
* filedata
,
8448 struct hppa_unw_aux_info
* aux
,
8449 Elf_Internal_Shdr
* sec
)
8451 unsigned long size
, unw_ent_size
, nentries
, nrelas
, i
;
8452 Elf_Internal_Phdr
* seg
;
8453 struct hppa_unw_table_entry
* tep
;
8454 Elf_Internal_Shdr
* relsec
;
8455 Elf_Internal_Rela
* rela
;
8456 Elf_Internal_Rela
* rp
;
8457 unsigned char * table
;
8459 Elf_Internal_Sym
* sym
;
8460 const char * relname
;
8462 /* First, find the starting address of the segment that includes
8464 if (filedata
->file_header
.e_phnum
)
8466 if (! get_program_headers (filedata
))
8469 for (seg
= filedata
->program_headers
;
8470 seg
< filedata
->program_headers
+ filedata
->file_header
.e_phnum
;
8473 if (seg
->p_type
!= PT_LOAD
)
8476 if (sec
->sh_addr
>= seg
->p_vaddr
8477 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
8479 aux
->seg_base
= seg
->p_vaddr
;
8485 /* Second, build the unwind table from the contents of the unwind
8487 size
= sec
->sh_size
;
8488 table
= (unsigned char *) get_data (NULL
, filedata
, sec
->sh_offset
, 1, size
,
8494 nentries
= size
/ unw_ent_size
;
8495 size
= unw_ent_size
* nentries
;
8497 aux
->table_len
= nentries
;
8498 tep
= aux
->table
= (struct hppa_unw_table_entry
*)
8499 xcmalloc (nentries
, sizeof (aux
->table
[0]));
8501 for (tp
= table
; tp
< table
+ size
; tp
+= unw_ent_size
, ++tep
)
8503 unsigned int tmp1
, tmp2
;
8505 tep
->start
.section
= SHN_UNDEF
;
8506 tep
->end
.section
= SHN_UNDEF
;
8508 tep
->start
.offset
= byte_get ((unsigned char *) tp
+ 0, 4);
8509 tep
->end
.offset
= byte_get ((unsigned char *) tp
+ 4, 4);
8510 tmp1
= byte_get ((unsigned char *) tp
+ 8, 4);
8511 tmp2
= byte_get ((unsigned char *) tp
+ 12, 4);
8513 tep
->start
.offset
+= aux
->seg_base
;
8514 tep
->end
.offset
+= aux
->seg_base
;
8516 tep
->Cannot_unwind
= (tmp1
>> 31) & 0x1;
8517 tep
->Millicode
= (tmp1
>> 30) & 0x1;
8518 tep
->Millicode_save_sr0
= (tmp1
>> 29) & 0x1;
8519 tep
->Region_description
= (tmp1
>> 27) & 0x3;
8520 tep
->reserved1
= (tmp1
>> 26) & 0x1;
8521 tep
->Entry_SR
= (tmp1
>> 25) & 0x1;
8522 tep
->Entry_FR
= (tmp1
>> 21) & 0xf;
8523 tep
->Entry_GR
= (tmp1
>> 16) & 0x1f;
8524 tep
->Args_stored
= (tmp1
>> 15) & 0x1;
8525 tep
->Variable_Frame
= (tmp1
>> 14) & 0x1;
8526 tep
->Separate_Package_Body
= (tmp1
>> 13) & 0x1;
8527 tep
->Frame_Extension_Millicode
= (tmp1
>> 12) & 0x1;
8528 tep
->Stack_Overflow_Check
= (tmp1
>> 11) & 0x1;
8529 tep
->Two_Instruction_SP_Increment
= (tmp1
>> 10) & 0x1;
8530 tep
->Ada_Region
= (tmp1
>> 9) & 0x1;
8531 tep
->cxx_info
= (tmp1
>> 8) & 0x1;
8532 tep
->cxx_try_catch
= (tmp1
>> 7) & 0x1;
8533 tep
->sched_entry_seq
= (tmp1
>> 6) & 0x1;
8534 tep
->reserved2
= (tmp1
>> 5) & 0x1;
8535 tep
->Save_SP
= (tmp1
>> 4) & 0x1;
8536 tep
->Save_RP
= (tmp1
>> 3) & 0x1;
8537 tep
->Save_MRP_in_frame
= (tmp1
>> 2) & 0x1;
8538 tep
->extn_ptr_defined
= (tmp1
>> 1) & 0x1;
8539 tep
->Cleanup_defined
= tmp1
& 0x1;
8541 tep
->MPE_XL_interrupt_marker
= (tmp2
>> 31) & 0x1;
8542 tep
->HP_UX_interrupt_marker
= (tmp2
>> 30) & 0x1;
8543 tep
->Large_frame
= (tmp2
>> 29) & 0x1;
8544 tep
->Pseudo_SP_Set
= (tmp2
>> 28) & 0x1;
8545 tep
->reserved4
= (tmp2
>> 27) & 0x1;
8546 tep
->Total_frame_size
= tmp2
& 0x7ffffff;
8550 /* Third, apply any relocations to the unwind table. */
8551 for (relsec
= filedata
->section_headers
;
8552 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
8555 if (relsec
->sh_type
!= SHT_RELA
8556 || relsec
->sh_info
>= filedata
->file_header
.e_shnum
8557 || filedata
->section_headers
+ relsec
->sh_info
!= sec
)
8560 if (!slurp_rela_relocs (filedata
, relsec
->sh_offset
, relsec
->sh_size
,
8564 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
8566 unsigned int sym_ndx
;
8567 unsigned int r_type
= get_reloc_type (filedata
, rp
->r_info
);
8568 relname
= elf_hppa_reloc_type (r_type
);
8570 if (relname
== NULL
)
8572 warn (_("Skipping unknown relocation type: %u\n"), r_type
);
8576 /* R_PARISC_SEGREL32 or R_PARISC_SEGREL64. */
8577 if (! const_strneq (relname
, "R_PARISC_SEGREL"))
8579 warn (_("Skipping unexpected relocation type: %s\n"), relname
);
8583 i
= rp
->r_offset
/ unw_ent_size
;
8584 if (i
>= aux
->table_len
)
8586 warn (_("Skipping reloc with overlarge offset: %lx\n"), i
);
8590 sym_ndx
= get_reloc_symindex (rp
->r_info
);
8591 if (sym_ndx
>= aux
->nsyms
)
8593 warn (_("Skipping reloc with invalid symbol index: %u\n"),
8597 sym
= aux
->symtab
+ sym_ndx
;
8599 switch ((rp
->r_offset
% unw_ent_size
) / 4)
8602 aux
->table
[i
].start
.section
= sym
->st_shndx
;
8603 aux
->table
[i
].start
.offset
= sym
->st_value
+ rp
->r_addend
;
8606 aux
->table
[i
].end
.section
= sym
->st_shndx
;
8607 aux
->table
[i
].end
.offset
= sym
->st_value
+ rp
->r_addend
;
8621 hppa_process_unwind (Filedata
* filedata
)
8623 struct hppa_unw_aux_info aux
;
8624 Elf_Internal_Shdr
* unwsec
= NULL
;
8625 Elf_Internal_Shdr
* sec
;
8629 if (filedata
->string_table
== NULL
)
8632 memset (& aux
, 0, sizeof (aux
));
8634 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
8636 if (sec
->sh_type
== SHT_SYMTAB
)
8640 error (_("Multiple symbol tables encountered\n"));
8646 if (!get_symtab (filedata
, sec
, &aux
.symtab
, &aux
.nsyms
,
8647 &aux
.strtab
, &aux
.strtab_size
))
8650 else if (SECTION_NAME_VALID (sec
)
8651 && streq (SECTION_NAME (sec
), ".PARISC.unwind"))
8656 printf (_("\nThere are no unwind sections in this file.\n"));
8658 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
8660 if (SECTION_NAME_VALID (sec
)
8661 && streq (SECTION_NAME (sec
), ".PARISC.unwind"))
8663 unsigned long num_unwind
= sec
->sh_size
/ 16;
8665 printf (ngettext ("\nUnwind section '%s' at offset 0x%lx "
8666 "contains %lu entry:\n",
8667 "\nUnwind section '%s' at offset 0x%lx "
8668 "contains %lu entries:\n",
8670 printable_section_name (filedata
, sec
),
8671 (unsigned long) sec
->sh_offset
,
8674 if (! slurp_hppa_unwind_table (filedata
, &aux
, sec
))
8677 if (res
&& aux
.table_len
> 0)
8679 if (! dump_hppa_unwind (filedata
, &aux
))
8683 free ((char *) aux
.table
);
8689 free ((char *) aux
.strtab
);
8696 unsigned char * data
; /* The unwind data. */
8697 Elf_Internal_Shdr
* sec
; /* The cached unwind section header. */
8698 Elf_Internal_Rela
* rela
; /* The cached relocations for this section. */
8699 unsigned long nrelas
; /* The number of relocations. */
8700 unsigned int rel_type
; /* REL or RELA ? */
8701 Elf_Internal_Rela
* next_rela
; /* Cyclic pointer to the next reloc to process. */
8704 struct arm_unw_aux_info
8706 Filedata
* filedata
; /* The file containing the unwind sections. */
8707 Elf_Internal_Sym
* symtab
; /* The file's symbol table. */
8708 unsigned long nsyms
; /* Number of symbols. */
8709 Elf_Internal_Sym
* funtab
; /* Sorted table of STT_FUNC symbols. */
8710 unsigned long nfuns
; /* Number of these symbols. */
8711 char * strtab
; /* The file's string table. */
8712 unsigned long strtab_size
; /* Size of string table. */
8716 arm_print_vma_and_name (Filedata
* filedata
,
8717 struct arm_unw_aux_info
* aux
,
8719 struct absaddr addr
)
8721 const char *procname
;
8724 if (addr
.section
== SHN_UNDEF
)
8727 find_symbol_for_address (filedata
, aux
->funtab
, aux
->nfuns
, aux
->strtab
,
8728 aux
->strtab_size
, addr
, &procname
,
8731 print_vma (fn
, PREFIX_HEX
);
8735 fputs (" <", stdout
);
8736 fputs (procname
, stdout
);
8739 printf ("+0x%lx", (unsigned long) sym_offset
);
8740 fputc ('>', stdout
);
8747 arm_free_section (struct arm_section
*arm_sec
)
8749 free (arm_sec
->data
);
8750 free (arm_sec
->rela
);
8753 /* 1) If SEC does not match the one cached in ARM_SEC, then free the current
8754 cached section and install SEC instead.
8755 2) Locate the 32-bit word at WORD_OFFSET in unwind section SEC
8756 and return its valued in * WORDP, relocating if necessary.
8757 3) Update the NEXT_RELA field in ARM_SEC and store the section index and
8758 relocation's offset in ADDR.
8759 4) If SYM_NAME is non-NULL and a relocation was applied, record the offset
8760 into the string table of the symbol associated with the reloc. If no
8761 reloc was applied store -1 there.
8762 5) Return TRUE upon success, FALSE otherwise. */
8765 get_unwind_section_word (Filedata
* filedata
,
8766 struct arm_unw_aux_info
* aux
,
8767 struct arm_section
* arm_sec
,
8768 Elf_Internal_Shdr
* sec
,
8769 bfd_vma word_offset
,
8770 unsigned int * wordp
,
8771 struct absaddr
* addr
,
8774 Elf_Internal_Rela
*rp
;
8775 Elf_Internal_Sym
*sym
;
8776 const char * relname
;
8780 if (sec
== NULL
|| arm_sec
== NULL
)
8783 addr
->section
= SHN_UNDEF
;
8786 if (sym_name
!= NULL
)
8787 *sym_name
= (bfd_vma
) -1;
8789 /* If necessary, update the section cache. */
8790 if (sec
!= arm_sec
->sec
)
8792 Elf_Internal_Shdr
*relsec
;
8794 arm_free_section (arm_sec
);
8797 arm_sec
->data
= get_data (NULL
, aux
->filedata
, sec
->sh_offset
, 1,
8798 sec
->sh_size
, _("unwind data"));
8799 arm_sec
->rela
= NULL
;
8800 arm_sec
->nrelas
= 0;
8802 for (relsec
= filedata
->section_headers
;
8803 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
8806 if (relsec
->sh_info
>= filedata
->file_header
.e_shnum
8807 || filedata
->section_headers
+ relsec
->sh_info
!= sec
8808 /* PR 15745: Check the section type as well. */
8809 || (relsec
->sh_type
!= SHT_REL
8810 && relsec
->sh_type
!= SHT_RELA
))
8813 arm_sec
->rel_type
= relsec
->sh_type
;
8814 if (relsec
->sh_type
== SHT_REL
)
8816 if (!slurp_rel_relocs (aux
->filedata
, relsec
->sh_offset
,
8818 & arm_sec
->rela
, & arm_sec
->nrelas
))
8821 else /* relsec->sh_type == SHT_RELA */
8823 if (!slurp_rela_relocs (aux
->filedata
, relsec
->sh_offset
,
8825 & arm_sec
->rela
, & arm_sec
->nrelas
))
8831 arm_sec
->next_rela
= arm_sec
->rela
;
8834 /* If there is no unwind data we can do nothing. */
8835 if (arm_sec
->data
== NULL
)
8838 /* If the offset is invalid then fail. */
8839 if (/* PR 21343 *//* PR 18879 */
8841 || word_offset
> (sec
->sh_size
- 4)
8842 || ((bfd_signed_vma
) word_offset
) < 0)
8845 /* Get the word at the required offset. */
8846 word
= byte_get (arm_sec
->data
+ word_offset
, 4);
8848 /* PR 17531: file: id:000001,src:001266+003044,op:splice,rep:128. */
8849 if (arm_sec
->rela
== NULL
)
8855 /* Look through the relocs to find the one that applies to the provided offset. */
8857 for (rp
= arm_sec
->next_rela
; rp
!= arm_sec
->rela
+ arm_sec
->nrelas
; rp
++)
8859 bfd_vma prelval
, offset
;
8861 if (rp
->r_offset
> word_offset
&& !wrapped
)
8866 if (rp
->r_offset
> word_offset
)
8869 if (rp
->r_offset
& 3)
8871 warn (_("Skipping unexpected relocation at offset 0x%lx\n"),
8872 (unsigned long) rp
->r_offset
);
8876 if (rp
->r_offset
< word_offset
)
8879 /* PR 17531: file: 027-161405-0.004 */
8880 if (aux
->symtab
== NULL
)
8883 if (arm_sec
->rel_type
== SHT_REL
)
8885 offset
= word
& 0x7fffffff;
8886 if (offset
& 0x40000000)
8887 offset
|= ~ (bfd_vma
) 0x7fffffff;
8889 else if (arm_sec
->rel_type
== SHT_RELA
)
8890 offset
= rp
->r_addend
;
8893 error (_("Unknown section relocation type %d encountered\n"),
8898 /* PR 17531 file: 027-1241568-0.004. */
8899 if (ELF32_R_SYM (rp
->r_info
) >= aux
->nsyms
)
8901 error (_("Bad symbol index in unwind relocation (%lu > %lu)\n"),
8902 (unsigned long) ELF32_R_SYM (rp
->r_info
), aux
->nsyms
);
8906 sym
= aux
->symtab
+ ELF32_R_SYM (rp
->r_info
);
8907 offset
+= sym
->st_value
;
8908 prelval
= offset
- (arm_sec
->sec
->sh_addr
+ rp
->r_offset
);
8910 /* Check that we are processing the expected reloc type. */
8911 if (filedata
->file_header
.e_machine
== EM_ARM
)
8913 relname
= elf_arm_reloc_type (ELF32_R_TYPE (rp
->r_info
));
8914 if (relname
== NULL
)
8916 warn (_("Skipping unknown ARM relocation type: %d\n"),
8917 (int) ELF32_R_TYPE (rp
->r_info
));
8921 if (streq (relname
, "R_ARM_NONE"))
8924 if (! streq (relname
, "R_ARM_PREL31"))
8926 warn (_("Skipping unexpected ARM relocation type %s\n"), relname
);
8930 else if (filedata
->file_header
.e_machine
== EM_TI_C6000
)
8932 relname
= elf_tic6x_reloc_type (ELF32_R_TYPE (rp
->r_info
));
8933 if (relname
== NULL
)
8935 warn (_("Skipping unknown C6000 relocation type: %d\n"),
8936 (int) ELF32_R_TYPE (rp
->r_info
));
8940 if (streq (relname
, "R_C6000_NONE"))
8943 if (! streq (relname
, "R_C6000_PREL31"))
8945 warn (_("Skipping unexpected C6000 relocation type %s\n"), relname
);
8953 /* This function currently only supports ARM and TI unwinders. */
8954 warn (_("Only TI and ARM unwinders are currently supported\n"));
8958 word
= (word
& ~ (bfd_vma
) 0x7fffffff) | (prelval
& 0x7fffffff);
8959 addr
->section
= sym
->st_shndx
;
8960 addr
->offset
= offset
;
8963 * sym_name
= sym
->st_name
;
8968 arm_sec
->next_rela
= rp
;
8973 static const char *tic6x_unwind_regnames
[16] =
8975 "A15", "B15", "B14", "B13", "B12", "B11", "B10", "B3",
8976 "A14", "A13", "A12", "A11", "A10",
8977 "[invalid reg 13]", "[invalid reg 14]", "[invalid reg 15]"
8981 decode_tic6x_unwind_regmask (unsigned int mask
)
8985 for (i
= 12; mask
; mask
>>= 1, i
--)
8989 fputs (tic6x_unwind_regnames
[i
], stdout
);
8991 fputs (", ", stdout
);
8997 if (remaining == 0 && more_words) \
9000 if (! get_unwind_section_word (filedata, aux, data_arm_sec, data_sec, \
9001 data_offset, & word, & addr, NULL)) \
9007 #define GET_OP(OP) \
9012 (OP) = word >> 24; \
9017 printf (_("[Truncated opcode]\n")); \
9020 printf ("0x%02x ", OP)
9023 decode_arm_unwind_bytecode (Filedata
* filedata
,
9024 struct arm_unw_aux_info
* aux
,
9026 unsigned int remaining
,
9027 unsigned int more_words
,
9028 bfd_vma data_offset
,
9029 Elf_Internal_Shdr
* data_sec
,
9030 struct arm_section
* data_arm_sec
)
9032 struct absaddr addr
;
9035 /* Decode the unwinding instructions. */
9038 unsigned int op
, op2
;
9047 printf (" 0x%02x ", op
);
9049 if ((op
& 0xc0) == 0x00)
9051 int offset
= ((op
& 0x3f) << 2) + 4;
9053 printf (" vsp = vsp + %d", offset
);
9055 else if ((op
& 0xc0) == 0x40)
9057 int offset
= ((op
& 0x3f) << 2) + 4;
9059 printf (" vsp = vsp - %d", offset
);
9061 else if ((op
& 0xf0) == 0x80)
9064 if (op
== 0x80 && op2
== 0)
9065 printf (_("Refuse to unwind"));
9068 unsigned int mask
= ((op
& 0x0f) << 8) | op2
;
9073 for (i
= 0; i
< 12; i
++)
9074 if (mask
& (1 << i
))
9080 printf ("r%d", 4 + i
);
9085 else if ((op
& 0xf0) == 0x90)
9087 if (op
== 0x9d || op
== 0x9f)
9088 printf (_(" [Reserved]"));
9090 printf (" vsp = r%d", op
& 0x0f);
9092 else if ((op
& 0xf0) == 0xa0)
9094 int end
= 4 + (op
& 0x07);
9099 for (i
= 4; i
<= end
; i
++)
9115 else if (op
== 0xb0)
9116 printf (_(" finish"));
9117 else if (op
== 0xb1)
9120 if (op2
== 0 || (op2
& 0xf0) != 0)
9121 printf (_("[Spare]"));
9124 unsigned int mask
= op2
& 0x0f;
9129 for (i
= 0; i
< 12; i
++)
9130 if (mask
& (1 << i
))
9141 else if (op
== 0xb2)
9143 unsigned char buf
[9];
9144 unsigned int i
, len
;
9145 unsigned long offset
;
9147 for (i
= 0; i
< sizeof (buf
); i
++)
9150 if ((buf
[i
] & 0x80) == 0)
9153 if (i
== sizeof (buf
))
9155 error (_("corrupt change to vsp\n"));
9160 offset
= read_leb128 (buf
, buf
+ i
+ 1, false, &len
, NULL
);
9161 assert (len
== i
+ 1);
9162 offset
= offset
* 4 + 0x204;
9163 printf ("vsp = vsp + %ld", offset
);
9166 else if (op
== 0xb3 || op
== 0xc8 || op
== 0xc9)
9168 unsigned int first
, last
;
9175 printf ("pop {D%d", first
);
9177 printf ("-D%d", first
+ last
);
9180 else if ((op
& 0xf8) == 0xb8 || (op
& 0xf8) == 0xd0)
9182 unsigned int count
= op
& 0x07;
9186 printf ("-D%d", 8 + count
);
9189 else if (op
>= 0xc0 && op
<= 0xc5)
9191 unsigned int count
= op
& 0x07;
9193 printf (" pop {wR10");
9195 printf ("-wR%d", 10 + count
);
9198 else if (op
== 0xc6)
9200 unsigned int first
, last
;
9205 printf ("pop {wR%d", first
);
9207 printf ("-wR%d", first
+ last
);
9210 else if (op
== 0xc7)
9213 if (op2
== 0 || (op2
& 0xf0) != 0)
9214 printf (_("[Spare]"));
9217 unsigned int mask
= op2
& 0x0f;
9222 for (i
= 0; i
< 4; i
++)
9223 if (mask
& (1 << i
))
9229 printf ("wCGR%d", i
);
9236 printf (_(" [unsupported opcode]"));
9247 decode_tic6x_unwind_bytecode (Filedata
* filedata
,
9248 struct arm_unw_aux_info
* aux
,
9250 unsigned int remaining
,
9251 unsigned int more_words
,
9252 bfd_vma data_offset
,
9253 Elf_Internal_Shdr
* data_sec
,
9254 struct arm_section
* data_arm_sec
)
9256 struct absaddr addr
;
9258 /* Decode the unwinding instructions. */
9261 unsigned int op
, op2
;
9270 printf (" 0x%02x ", op
);
9272 if ((op
& 0xc0) == 0x00)
9274 int offset
= ((op
& 0x3f) << 3) + 8;
9275 printf (" sp = sp + %d", offset
);
9277 else if ((op
& 0xc0) == 0x80)
9280 if (op
== 0x80 && op2
== 0)
9281 printf (_("Refuse to unwind"));
9284 unsigned int mask
= ((op
& 0x1f) << 8) | op2
;
9286 printf ("pop compact {");
9290 decode_tic6x_unwind_regmask (mask
);
9294 else if ((op
& 0xf0) == 0xc0)
9302 unsigned int offset
;
9306 /* Scan entire instruction first so that GET_OP output is not
9307 interleaved with disassembly. */
9309 for (i
= 0; nregs
< (op
& 0xf); i
++)
9315 regpos
[nregs
].offset
= i
* 2;
9316 regpos
[nregs
].reg
= reg
;
9323 regpos
[nregs
].offset
= i
* 2 + 1;
9324 regpos
[nregs
].reg
= reg
;
9329 printf (_("pop frame {"));
9332 printf (_("*corrupt* - no registers specified"));
9337 for (i
= i
* 2; i
> 0; i
--)
9339 if (regpos
[reg
].offset
== i
- 1)
9341 name
= tic6x_unwind_regnames
[regpos
[reg
].reg
];
9348 fputs (name
, stdout
);
9356 else if (op
== 0xd0)
9357 printf (" MOV FP, SP");
9358 else if (op
== 0xd1)
9359 printf (" __c6xabi_pop_rts");
9360 else if (op
== 0xd2)
9362 unsigned char buf
[9];
9363 unsigned int i
, len
;
9364 unsigned long offset
;
9366 for (i
= 0; i
< sizeof (buf
); i
++)
9369 if ((buf
[i
] & 0x80) == 0)
9372 /* PR 17531: file: id:000001,src:001906+004739,op:splice,rep:2. */
9373 if (i
== sizeof (buf
))
9375 warn (_("Corrupt stack pointer adjustment detected\n"));
9379 offset
= read_leb128 (buf
, buf
+ i
+ 1, false, &len
, NULL
);
9380 assert (len
== i
+ 1);
9381 offset
= offset
* 8 + 0x408;
9382 printf (_("sp = sp + %ld"), offset
);
9384 else if ((op
& 0xf0) == 0xe0)
9386 if ((op
& 0x0f) == 7)
9389 printf (" MV %s, B3", tic6x_unwind_regnames
[op
& 0x0f]);
9393 printf (_(" [unsupported opcode]"));
9402 arm_expand_prel31 (Filedata
* filedata
, bfd_vma word
, bfd_vma where
)
9406 offset
= word
& 0x7fffffff;
9407 if (offset
& 0x40000000)
9408 offset
|= ~ (bfd_vma
) 0x7fffffff;
9410 if (filedata
->file_header
.e_machine
== EM_TI_C6000
)
9413 return offset
+ where
;
9417 decode_arm_unwind (Filedata
* filedata
,
9418 struct arm_unw_aux_info
* aux
,
9420 unsigned int remaining
,
9421 bfd_vma data_offset
,
9422 Elf_Internal_Shdr
* data_sec
,
9423 struct arm_section
* data_arm_sec
)
9426 unsigned int more_words
= 0;
9427 struct absaddr addr
;
9428 bfd_vma sym_name
= (bfd_vma
) -1;
9433 /* Fetch the first word.
9434 Note - when decoding an object file the address extracted
9435 here will always be 0. So we also pass in the sym_name
9436 parameter so that we can find the symbol associated with
9437 the personality routine. */
9438 if (! get_unwind_section_word (filedata
, aux
, data_arm_sec
, data_sec
, data_offset
,
9439 & word
, & addr
, & sym_name
))
9446 addr
.section
= SHN_UNDEF
;
9450 if ((word
& 0x80000000) == 0)
9452 /* Expand prel31 for personality routine. */
9454 const char *procname
;
9456 fn
= arm_expand_prel31 (filedata
, word
, data_sec
->sh_addr
+ data_offset
);
9457 printf (_(" Personality routine: "));
9459 && addr
.section
== SHN_UNDEF
&& addr
.offset
== 0
9460 && sym_name
!= (bfd_vma
) -1 && sym_name
< aux
->strtab_size
)
9462 procname
= aux
->strtab
+ sym_name
;
9463 print_vma (fn
, PREFIX_HEX
);
9466 fputs (" <", stdout
);
9467 fputs (procname
, stdout
);
9468 fputc ('>', stdout
);
9472 procname
= arm_print_vma_and_name (filedata
, aux
, fn
, addr
);
9473 fputc ('\n', stdout
);
9475 /* The GCC personality routines use the standard compact
9476 encoding, starting with one byte giving the number of
9478 if (procname
!= NULL
9479 && (const_strneq (procname
, "__gcc_personality_v0")
9480 || const_strneq (procname
, "__gxx_personality_v0")
9481 || const_strneq (procname
, "__gcj_personality_v0")
9482 || const_strneq (procname
, "__gnu_objc_personality_v0")))
9489 printf (_(" [Truncated data]\n"));
9492 more_words
= word
>> 24;
9502 /* ARM EHABI Section 6.3:
9504 An exception-handling table entry for the compact model looks like:
9508 1 0 index Data for personalityRoutine[index] */
9510 if (filedata
->file_header
.e_machine
== EM_ARM
9511 && (word
& 0x70000000))
9513 warn (_("Corrupt ARM compact model table entry: %x \n"), word
);
9517 per_index
= (word
>> 24) & 0x7f;
9518 printf (_(" Compact model index: %d\n"), per_index
);
9525 else if (per_index
< 3)
9527 more_words
= (word
>> 16) & 0xff;
9533 switch (filedata
->file_header
.e_machine
)
9538 if (! decode_arm_unwind_bytecode (filedata
, aux
, word
, remaining
, more_words
,
9539 data_offset
, data_sec
, data_arm_sec
))
9544 warn (_("Unknown ARM compact model index encountered\n"));
9545 printf (_(" [reserved]\n"));
9553 if (! decode_tic6x_unwind_bytecode (filedata
, aux
, word
, remaining
, more_words
,
9554 data_offset
, data_sec
, data_arm_sec
))
9557 else if (per_index
< 5)
9559 if (((word
>> 17) & 0x7f) == 0x7f)
9560 printf (_(" Restore stack from frame pointer\n"));
9562 printf (_(" Stack increment %d\n"), (word
>> 14) & 0x1fc);
9563 printf (_(" Registers restored: "));
9565 printf (" (compact) ");
9566 decode_tic6x_unwind_regmask ((word
>> 4) & 0x1fff);
9568 printf (_(" Return register: %s\n"),
9569 tic6x_unwind_regnames
[word
& 0xf]);
9572 printf (_(" [reserved (%d)]\n"), per_index
);
9576 error (_("Unsupported architecture type %d encountered when decoding unwind table\n"),
9577 filedata
->file_header
.e_machine
);
9581 /* Decode the descriptors. Not implemented. */
9587 dump_arm_unwind (Filedata
* filedata
,
9588 struct arm_unw_aux_info
* aux
,
9589 Elf_Internal_Shdr
* exidx_sec
)
9591 struct arm_section exidx_arm_sec
, extab_arm_sec
;
9592 unsigned int i
, exidx_len
;
9593 unsigned long j
, nfuns
;
9596 memset (&exidx_arm_sec
, 0, sizeof (exidx_arm_sec
));
9597 memset (&extab_arm_sec
, 0, sizeof (extab_arm_sec
));
9598 exidx_len
= exidx_sec
->sh_size
/ 8;
9600 aux
->funtab
= xmalloc (aux
->nsyms
* sizeof (Elf_Internal_Sym
));
9601 for (nfuns
= 0, j
= 0; j
< aux
->nsyms
; j
++)
9602 if (aux
->symtab
[j
].st_value
&& ELF_ST_TYPE (aux
->symtab
[j
].st_info
) == STT_FUNC
)
9603 aux
->funtab
[nfuns
++] = aux
->symtab
[j
];
9605 qsort (aux
->funtab
, aux
->nfuns
, sizeof (Elf_Internal_Sym
), symcmp
);
9607 for (i
= 0; i
< exidx_len
; i
++)
9609 unsigned int exidx_fn
, exidx_entry
;
9610 struct absaddr fn_addr
, entry_addr
;
9613 fputc ('\n', stdout
);
9615 if (! get_unwind_section_word (filedata
, aux
, & exidx_arm_sec
, exidx_sec
,
9616 8 * i
, & exidx_fn
, & fn_addr
, NULL
)
9617 || ! get_unwind_section_word (filedata
, aux
, & exidx_arm_sec
, exidx_sec
,
9618 8 * i
+ 4, & exidx_entry
, & entry_addr
, NULL
))
9621 arm_free_section (& exidx_arm_sec
);
9622 arm_free_section (& extab_arm_sec
);
9626 /* ARM EHABI, Section 5:
9627 An index table entry consists of 2 words.
9628 The first word contains a prel31 offset to the start of a function, with bit 31 clear. */
9629 if (exidx_fn
& 0x80000000)
9631 warn (_("corrupt index table entry: %x\n"), exidx_fn
);
9635 fn
= arm_expand_prel31 (filedata
, exidx_fn
, exidx_sec
->sh_addr
+ 8 * i
);
9637 arm_print_vma_and_name (filedata
, aux
, fn
, fn_addr
);
9638 fputs (": ", stdout
);
9640 if (exidx_entry
== 1)
9642 print_vma (exidx_entry
, PREFIX_HEX
);
9643 fputs (" [cantunwind]\n", stdout
);
9645 else if (exidx_entry
& 0x80000000)
9647 print_vma (exidx_entry
, PREFIX_HEX
);
9648 fputc ('\n', stdout
);
9649 decode_arm_unwind (filedata
, aux
, exidx_entry
, 4, 0, NULL
, NULL
);
9653 bfd_vma table
, table_offset
= 0;
9654 Elf_Internal_Shdr
*table_sec
;
9656 fputs ("@", stdout
);
9657 table
= arm_expand_prel31 (filedata
, exidx_entry
, exidx_sec
->sh_addr
+ 8 * i
+ 4);
9658 print_vma (table
, PREFIX_HEX
);
9661 /* Locate the matching .ARM.extab. */
9662 if (entry_addr
.section
!= SHN_UNDEF
9663 && entry_addr
.section
< filedata
->file_header
.e_shnum
)
9665 table_sec
= filedata
->section_headers
+ entry_addr
.section
;
9666 table_offset
= entry_addr
.offset
;
9668 if (table_offset
> table_sec
->sh_size
9669 || ((bfd_signed_vma
) table_offset
) < 0)
9671 warn (_("Unwind entry contains corrupt offset (0x%lx) into section %s\n"),
9672 (unsigned long) table_offset
,
9673 printable_section_name (filedata
, table_sec
));
9680 table_sec
= find_section_by_address (filedata
, table
);
9681 if (table_sec
!= NULL
)
9682 table_offset
= table
- table_sec
->sh_addr
;
9685 if (table_sec
== NULL
)
9687 warn (_("Could not locate .ARM.extab section containing 0x%lx.\n"),
9688 (unsigned long) table
);
9693 if (! decode_arm_unwind (filedata
, aux
, 0, 0, table_offset
, table_sec
,
9702 arm_free_section (&exidx_arm_sec
);
9703 arm_free_section (&extab_arm_sec
);
9708 /* Used for both ARM and C6X unwinding tables. */
9711 arm_process_unwind (Filedata
* filedata
)
9713 struct arm_unw_aux_info aux
;
9714 Elf_Internal_Shdr
*unwsec
= NULL
;
9715 Elf_Internal_Shdr
*sec
;
9717 unsigned int sec_type
;
9720 switch (filedata
->file_header
.e_machine
)
9723 sec_type
= SHT_ARM_EXIDX
;
9727 sec_type
= SHT_C6000_UNWIND
;
9731 error (_("Unsupported architecture type %d encountered when processing unwind table\n"),
9732 filedata
->file_header
.e_machine
);
9736 if (filedata
->string_table
== NULL
)
9739 memset (& aux
, 0, sizeof (aux
));
9740 aux
.filedata
= filedata
;
9742 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
9744 if (sec
->sh_type
== SHT_SYMTAB
)
9748 error (_("Multiple symbol tables encountered\n"));
9754 if (!get_symtab (filedata
, sec
, &aux
.symtab
, &aux
.nsyms
,
9755 &aux
.strtab
, &aux
.strtab_size
))
9758 else if (sec
->sh_type
== sec_type
)
9763 printf (_("\nThere are no unwind sections in this file.\n"));
9765 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
9767 if (sec
->sh_type
== sec_type
)
9769 unsigned long num_unwind
= sec
->sh_size
/ (2 * eh_addr_size
);
9770 printf (ngettext ("\nUnwind section '%s' at offset 0x%lx "
9771 "contains %lu entry:\n",
9772 "\nUnwind section '%s' at offset 0x%lx "
9773 "contains %lu entries:\n",
9775 printable_section_name (filedata
, sec
),
9776 (unsigned long) sec
->sh_offset
,
9779 if (! dump_arm_unwind (filedata
, &aux
, sec
))
9785 free ((char *) aux
.strtab
);
9791 process_unwind (Filedata
* filedata
)
9793 struct unwind_handler
9795 unsigned int machtype
;
9796 bool (* handler
)(Filedata
*);
9799 { EM_ARM
, arm_process_unwind
},
9800 { EM_IA_64
, ia64_process_unwind
},
9801 { EM_PARISC
, hppa_process_unwind
},
9802 { EM_TI_C6000
, arm_process_unwind
},
9810 for (i
= 0; handlers
[i
].handler
!= NULL
; i
++)
9811 if (filedata
->file_header
.e_machine
== handlers
[i
].machtype
)
9812 return handlers
[i
].handler (filedata
);
9814 printf (_("\nThe decoding of unwind sections for machine type %s is not currently supported.\n"),
9815 get_machine_name (filedata
->file_header
.e_machine
));
9820 dynamic_section_aarch64_val (Elf_Internal_Dyn
* entry
)
9822 switch (entry
->d_tag
)
9824 case DT_AARCH64_BTI_PLT
:
9825 case DT_AARCH64_PAC_PLT
:
9828 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
9835 dynamic_section_mips_val (Filedata
* filedata
, Elf_Internal_Dyn
* entry
)
9837 switch (entry
->d_tag
)
9840 if (entry
->d_un
.d_val
== 0)
9844 static const char * opts
[] =
9846 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
9847 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
9848 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
9849 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
9855 for (cnt
= 0; cnt
< ARRAY_SIZE (opts
); ++cnt
)
9856 if (entry
->d_un
.d_val
& (1 << cnt
))
9858 printf ("%s%s", first
? "" : " ", opts
[cnt
]);
9864 case DT_MIPS_IVERSION
:
9865 if (VALID_DYNAMIC_NAME (filedata
, entry
->d_un
.d_val
))
9866 printf (_("Interface Version: %s"),
9867 GET_DYNAMIC_NAME (filedata
, entry
->d_un
.d_val
));
9871 sprintf_vma (buf
, entry
->d_un
.d_ptr
);
9872 /* Note: coded this way so that there is a single string for translation. */
9873 printf (_("<corrupt: %s>"), buf
);
9877 case DT_MIPS_TIME_STAMP
:
9881 time_t atime
= entry
->d_un
.d_val
;
9883 tmp
= gmtime (&atime
);
9884 /* PR 17531: file: 6accc532. */
9886 snprintf (timebuf
, sizeof (timebuf
), _("<corrupt>"));
9888 snprintf (timebuf
, sizeof (timebuf
), "%04u-%02u-%02uT%02u:%02u:%02u",
9889 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
9890 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
9891 printf (_("Time Stamp: %s"), timebuf
);
9895 case DT_MIPS_RLD_VERSION
:
9896 case DT_MIPS_LOCAL_GOTNO
:
9897 case DT_MIPS_CONFLICTNO
:
9898 case DT_MIPS_LIBLISTNO
:
9899 case DT_MIPS_SYMTABNO
:
9900 case DT_MIPS_UNREFEXTNO
:
9901 case DT_MIPS_HIPAGENO
:
9902 case DT_MIPS_DELTA_CLASS_NO
:
9903 case DT_MIPS_DELTA_INSTANCE_NO
:
9904 case DT_MIPS_DELTA_RELOC_NO
:
9905 case DT_MIPS_DELTA_SYM_NO
:
9906 case DT_MIPS_DELTA_CLASSSYM_NO
:
9907 case DT_MIPS_COMPACT_SIZE
:
9908 print_vma (entry
->d_un
.d_val
, DEC
);
9912 filedata
->dynamic_info_DT_MIPS_XHASH
= entry
->d_un
.d_val
;
9913 filedata
->dynamic_info_DT_GNU_HASH
= entry
->d_un
.d_val
;
9914 /* Falls through. */
9917 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
9923 dynamic_section_parisc_val (Elf_Internal_Dyn
* entry
)
9925 switch (entry
->d_tag
)
9927 case DT_HP_DLD_FLAGS
:
9936 { DT_HP_DEBUG_PRIVATE
, "HP_DEBUG_PRIVATE" },
9937 { DT_HP_DEBUG_CALLBACK
, "HP_DEBUG_CALLBACK" },
9938 { DT_HP_DEBUG_CALLBACK_BOR
, "HP_DEBUG_CALLBACK_BOR" },
9939 { DT_HP_NO_ENVVAR
, "HP_NO_ENVVAR" },
9940 { DT_HP_BIND_NOW
, "HP_BIND_NOW" },
9941 { DT_HP_BIND_NONFATAL
, "HP_BIND_NONFATAL" },
9942 { DT_HP_BIND_VERBOSE
, "HP_BIND_VERBOSE" },
9943 { DT_HP_BIND_RESTRICTED
, "HP_BIND_RESTRICTED" },
9944 { DT_HP_BIND_SYMBOLIC
, "HP_BIND_SYMBOLIC" },
9945 { DT_HP_RPATH_FIRST
, "HP_RPATH_FIRST" },
9946 { DT_HP_BIND_DEPTH_FIRST
, "HP_BIND_DEPTH_FIRST" },
9947 { DT_HP_GST
, "HP_GST" },
9948 { DT_HP_SHLIB_FIXED
, "HP_SHLIB_FIXED" },
9949 { DT_HP_MERGE_SHLIB_SEG
, "HP_MERGE_SHLIB_SEG" },
9950 { DT_HP_NODELETE
, "HP_NODELETE" },
9951 { DT_HP_GROUP
, "HP_GROUP" },
9952 { DT_HP_PROTECT_LINKAGE_TABLE
, "HP_PROTECT_LINKAGE_TABLE" }
9956 bfd_vma val
= entry
->d_un
.d_val
;
9958 for (cnt
= 0; cnt
< ARRAY_SIZE (flags
); ++cnt
)
9959 if (val
& flags
[cnt
].bit
)
9963 fputs (flags
[cnt
].str
, stdout
);
9965 val
^= flags
[cnt
].bit
;
9968 if (val
!= 0 || first
)
9972 print_vma (val
, HEX
);
9978 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
9986 /* VMS vs Unix time offset and factor. */
9988 #define VMS_EPOCH_OFFSET 35067168000000000LL
9989 #define VMS_GRANULARITY_FACTOR 10000000
9991 #define INT64_MIN (-9223372036854775807LL - 1)
9994 /* Display a VMS time in a human readable format. */
9997 print_vms_time (bfd_int64_t vmstime
)
9999 struct tm
*tm
= NULL
;
10002 if (vmstime
>= INT64_MIN
+ VMS_EPOCH_OFFSET
)
10004 vmstime
= (vmstime
- VMS_EPOCH_OFFSET
) / VMS_GRANULARITY_FACTOR
;
10006 if (unxtime
== vmstime
)
10007 tm
= gmtime (&unxtime
);
10010 printf ("%04u-%02u-%02uT%02u:%02u:%02u",
10011 tm
->tm_year
+ 1900, tm
->tm_mon
+ 1, tm
->tm_mday
,
10012 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
);
10017 dynamic_section_ia64_val (Elf_Internal_Dyn
* entry
)
10019 switch (entry
->d_tag
)
10021 case DT_IA_64_PLT_RESERVE
:
10022 /* First 3 slots reserved. */
10023 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
10025 print_vma (entry
->d_un
.d_ptr
+ (3 * 8), PREFIX_HEX
);
10028 case DT_IA_64_VMS_LINKTIME
:
10030 print_vms_time (entry
->d_un
.d_val
);
10034 case DT_IA_64_VMS_LNKFLAGS
:
10035 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
10036 if (entry
->d_un
.d_val
& VMS_LF_CALL_DEBUG
)
10037 printf (" CALL_DEBUG");
10038 if (entry
->d_un
.d_val
& VMS_LF_NOP0BUFS
)
10039 printf (" NOP0BUFS");
10040 if (entry
->d_un
.d_val
& VMS_LF_P0IMAGE
)
10041 printf (" P0IMAGE");
10042 if (entry
->d_un
.d_val
& VMS_LF_MKTHREADS
)
10043 printf (" MKTHREADS");
10044 if (entry
->d_un
.d_val
& VMS_LF_UPCALLS
)
10045 printf (" UPCALLS");
10046 if (entry
->d_un
.d_val
& VMS_LF_IMGSTA
)
10047 printf (" IMGSTA");
10048 if (entry
->d_un
.d_val
& VMS_LF_INITIALIZE
)
10049 printf (" INITIALIZE");
10050 if (entry
->d_un
.d_val
& VMS_LF_MAIN
)
10052 if (entry
->d_un
.d_val
& VMS_LF_EXE_INIT
)
10053 printf (" EXE_INIT");
10054 if (entry
->d_un
.d_val
& VMS_LF_TBK_IN_IMG
)
10055 printf (" TBK_IN_IMG");
10056 if (entry
->d_un
.d_val
& VMS_LF_DBG_IN_IMG
)
10057 printf (" DBG_IN_IMG");
10058 if (entry
->d_un
.d_val
& VMS_LF_TBK_IN_DSF
)
10059 printf (" TBK_IN_DSF");
10060 if (entry
->d_un
.d_val
& VMS_LF_DBG_IN_DSF
)
10061 printf (" DBG_IN_DSF");
10062 if (entry
->d_un
.d_val
& VMS_LF_SIGNATURES
)
10063 printf (" SIGNATURES");
10064 if (entry
->d_un
.d_val
& VMS_LF_REL_SEG_OFF
)
10065 printf (" REL_SEG_OFF");
10069 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
10076 get_32bit_dynamic_section (Filedata
* filedata
)
10078 Elf32_External_Dyn
* edyn
;
10079 Elf32_External_Dyn
* ext
;
10080 Elf_Internal_Dyn
* entry
;
10082 edyn
= (Elf32_External_Dyn
*) get_data (NULL
, filedata
,
10083 filedata
->dynamic_addr
, 1,
10084 filedata
->dynamic_size
,
10085 _("dynamic section"));
10089 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
10090 might not have the luxury of section headers. Look for the DT_NULL
10091 terminator to determine the number of entries. */
10092 for (ext
= edyn
, filedata
->dynamic_nent
= 0;
10093 (char *) (ext
+ 1) <= (char *) edyn
+ filedata
->dynamic_size
;
10096 filedata
->dynamic_nent
++;
10097 if (BYTE_GET (ext
->d_tag
) == DT_NULL
)
10101 filedata
->dynamic_section
10102 = (Elf_Internal_Dyn
*) cmalloc (filedata
->dynamic_nent
, sizeof (* entry
));
10103 if (filedata
->dynamic_section
== NULL
)
10105 error (_("Out of memory allocating space for %lu dynamic entries\n"),
10106 (unsigned long) filedata
->dynamic_nent
);
10111 for (ext
= edyn
, entry
= filedata
->dynamic_section
;
10112 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
10115 entry
->d_tag
= BYTE_GET (ext
->d_tag
);
10116 entry
->d_un
.d_val
= BYTE_GET (ext
->d_un
.d_val
);
10125 get_64bit_dynamic_section (Filedata
* filedata
)
10127 Elf64_External_Dyn
* edyn
;
10128 Elf64_External_Dyn
* ext
;
10129 Elf_Internal_Dyn
* entry
;
10131 /* Read in the data. */
10132 edyn
= (Elf64_External_Dyn
*) get_data (NULL
, filedata
,
10133 filedata
->dynamic_addr
, 1,
10134 filedata
->dynamic_size
,
10135 _("dynamic section"));
10139 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
10140 might not have the luxury of section headers. Look for the DT_NULL
10141 terminator to determine the number of entries. */
10142 for (ext
= edyn
, filedata
->dynamic_nent
= 0;
10143 /* PR 17533 file: 033-67080-0.004 - do not read past end of buffer. */
10144 (char *) (ext
+ 1) <= (char *) edyn
+ filedata
->dynamic_size
;
10147 filedata
->dynamic_nent
++;
10148 if (BYTE_GET (ext
->d_tag
) == DT_NULL
)
10152 filedata
->dynamic_section
10153 = (Elf_Internal_Dyn
*) cmalloc (filedata
->dynamic_nent
, sizeof (* entry
));
10154 if (filedata
->dynamic_section
== NULL
)
10156 error (_("Out of memory allocating space for %lu dynamic entries\n"),
10157 (unsigned long) filedata
->dynamic_nent
);
10162 /* Convert from external to internal formats. */
10163 for (ext
= edyn
, entry
= filedata
->dynamic_section
;
10164 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
10167 entry
->d_tag
= BYTE_GET (ext
->d_tag
);
10168 entry
->d_un
.d_val
= BYTE_GET (ext
->d_un
.d_val
);
10177 print_dynamic_flags (bfd_vma flags
)
10185 flag
= flags
& - flags
;
10191 putc (' ', stdout
);
10195 case DF_ORIGIN
: fputs ("ORIGIN", stdout
); break;
10196 case DF_SYMBOLIC
: fputs ("SYMBOLIC", stdout
); break;
10197 case DF_TEXTREL
: fputs ("TEXTREL", stdout
); break;
10198 case DF_BIND_NOW
: fputs ("BIND_NOW", stdout
); break;
10199 case DF_STATIC_TLS
: fputs ("STATIC_TLS", stdout
); break;
10200 default: fputs (_("unknown"), stdout
); break;
10207 get_dynamic_data (Filedata
* filedata
, bfd_size_type number
, unsigned int ent_size
)
10209 unsigned char * e_data
;
10212 /* If the size_t type is smaller than the bfd_size_type, eg because
10213 you are building a 32-bit tool on a 64-bit host, then make sure
10214 that when (number) is cast to (size_t) no information is lost. */
10215 if (sizeof (size_t) < sizeof (bfd_size_type
)
10216 && (bfd_size_type
) ((size_t) number
) != number
)
10218 error (_("Size truncation prevents reading %s elements of size %u\n"),
10219 bfd_vmatoa ("u", number
), ent_size
);
10223 /* Be kind to memory checkers (eg valgrind, address sanitizer) by not
10224 attempting to allocate memory when the read is bound to fail. */
10225 if (ent_size
* number
> filedata
->file_size
)
10227 error (_("Invalid number of dynamic entries: %s\n"),
10228 bfd_vmatoa ("u", number
));
10232 e_data
= (unsigned char *) cmalloc ((size_t) number
, ent_size
);
10233 if (e_data
== NULL
)
10235 error (_("Out of memory reading %s dynamic entries\n"),
10236 bfd_vmatoa ("u", number
));
10240 if (fread (e_data
, ent_size
, (size_t) number
, filedata
->handle
) != number
)
10242 error (_("Unable to read in %s bytes of dynamic data\n"),
10243 bfd_vmatoa ("u", number
* ent_size
));
10248 i_data
= (bfd_vma
*) cmalloc ((size_t) number
, sizeof (*i_data
));
10249 if (i_data
== NULL
)
10251 error (_("Out of memory allocating space for %s dynamic entries\n"),
10252 bfd_vmatoa ("u", number
));
10258 i_data
[number
] = byte_get (e_data
+ number
* ent_size
, ent_size
);
10265 static unsigned long
10266 get_num_dynamic_syms (Filedata
* filedata
)
10268 unsigned long num_of_syms
= 0;
10270 if (!do_histogram
&& (!do_using_dynamic
|| do_dyn_syms
))
10271 return num_of_syms
;
10273 if (filedata
->dynamic_info
[DT_HASH
])
10275 unsigned char nb
[8];
10276 unsigned char nc
[8];
10277 unsigned int hash_ent_size
= 4;
10279 if ((filedata
->file_header
.e_machine
== EM_ALPHA
10280 || filedata
->file_header
.e_machine
== EM_S390
10281 || filedata
->file_header
.e_machine
== EM_S390_OLD
)
10282 && filedata
->file_header
.e_ident
[EI_CLASS
] == ELFCLASS64
)
10285 if (fseek (filedata
->handle
,
10286 (filedata
->archive_file_offset
10287 + offset_from_vma (filedata
, filedata
->dynamic_info
[DT_HASH
],
10288 sizeof nb
+ sizeof nc
)),
10291 error (_("Unable to seek to start of dynamic information\n"));
10295 if (fread (nb
, hash_ent_size
, 1, filedata
->handle
) != 1)
10297 error (_("Failed to read in number of buckets\n"));
10301 if (fread (nc
, hash_ent_size
, 1, filedata
->handle
) != 1)
10303 error (_("Failed to read in number of chains\n"));
10307 filedata
->nbuckets
= byte_get (nb
, hash_ent_size
);
10308 filedata
->nchains
= byte_get (nc
, hash_ent_size
);
10310 if (filedata
->nbuckets
!= 0 && filedata
->nchains
!= 0)
10312 filedata
->buckets
= get_dynamic_data (filedata
, filedata
->nbuckets
,
10314 filedata
->chains
= get_dynamic_data (filedata
, filedata
->nchains
,
10317 if (filedata
->buckets
!= NULL
&& filedata
->chains
!= NULL
)
10318 num_of_syms
= filedata
->nchains
;
10321 if (num_of_syms
== 0)
10323 free (filedata
->buckets
);
10324 filedata
->buckets
= NULL
;
10325 free (filedata
->chains
);
10326 filedata
->chains
= NULL
;
10327 filedata
->nbuckets
= 0;
10331 if (filedata
->dynamic_info_DT_GNU_HASH
)
10333 unsigned char nb
[16];
10334 bfd_vma i
, maxchain
= 0xffffffff, bitmaskwords
;
10335 bfd_vma buckets_vma
;
10338 if (fseek (filedata
->handle
,
10339 (filedata
->archive_file_offset
10340 + offset_from_vma (filedata
,
10341 filedata
->dynamic_info_DT_GNU_HASH
,
10345 error (_("Unable to seek to start of dynamic information\n"));
10349 if (fread (nb
, 16, 1, filedata
->handle
) != 1)
10351 error (_("Failed to read in number of buckets\n"));
10355 filedata
->ngnubuckets
= byte_get (nb
, 4);
10356 filedata
->gnusymidx
= byte_get (nb
+ 4, 4);
10357 bitmaskwords
= byte_get (nb
+ 8, 4);
10358 buckets_vma
= filedata
->dynamic_info_DT_GNU_HASH
+ 16;
10360 buckets_vma
+= bitmaskwords
* 4;
10362 buckets_vma
+= bitmaskwords
* 8;
10364 if (fseek (filedata
->handle
,
10365 (filedata
->archive_file_offset
10366 + offset_from_vma (filedata
, buckets_vma
, 4)),
10369 error (_("Unable to seek to start of dynamic information\n"));
10373 filedata
->gnubuckets
10374 = get_dynamic_data (filedata
, filedata
->ngnubuckets
, 4);
10376 if (filedata
->gnubuckets
== NULL
)
10379 for (i
= 0; i
< filedata
->ngnubuckets
; i
++)
10380 if (filedata
->gnubuckets
[i
] != 0)
10382 if (filedata
->gnubuckets
[i
] < filedata
->gnusymidx
)
10385 if (maxchain
== 0xffffffff || filedata
->gnubuckets
[i
] > maxchain
)
10386 maxchain
= filedata
->gnubuckets
[i
];
10389 if (maxchain
== 0xffffffff)
10392 maxchain
-= filedata
->gnusymidx
;
10394 if (fseek (filedata
->handle
,
10395 (filedata
->archive_file_offset
10396 + offset_from_vma (filedata
,
10397 buckets_vma
+ 4 * (filedata
->ngnubuckets
10402 error (_("Unable to seek to start of dynamic information\n"));
10408 if (fread (nb
, 4, 1, filedata
->handle
) != 1)
10410 error (_("Failed to determine last chain length\n"));
10414 if (maxchain
+ 1 == 0)
10419 while ((byte_get (nb
, 4) & 1) == 0);
10421 if (fseek (filedata
->handle
,
10422 (filedata
->archive_file_offset
10423 + offset_from_vma (filedata
, (buckets_vma
10424 + 4 * filedata
->ngnubuckets
),
10428 error (_("Unable to seek to start of dynamic information\n"));
10432 filedata
->gnuchains
= get_dynamic_data (filedata
, maxchain
, 4);
10433 filedata
->ngnuchains
= maxchain
;
10435 if (filedata
->gnuchains
== NULL
)
10438 if (filedata
->dynamic_info_DT_MIPS_XHASH
)
10440 if (fseek (filedata
->handle
,
10441 (filedata
->archive_file_offset
10442 + offset_from_vma (filedata
, (buckets_vma
10443 + 4 * (filedata
->ngnubuckets
10447 error (_("Unable to seek to start of dynamic information\n"));
10451 filedata
->mipsxlat
= get_dynamic_data (filedata
, maxchain
, 4);
10452 if (filedata
->mipsxlat
== NULL
)
10456 for (hn
= 0; hn
< filedata
->ngnubuckets
; ++hn
)
10457 if (filedata
->gnubuckets
[hn
] != 0)
10459 bfd_vma si
= filedata
->gnubuckets
[hn
];
10460 bfd_vma off
= si
- filedata
->gnusymidx
;
10464 if (filedata
->dynamic_info_DT_MIPS_XHASH
)
10466 if (off
< filedata
->ngnuchains
10467 && filedata
->mipsxlat
[off
] >= num_of_syms
)
10468 num_of_syms
= filedata
->mipsxlat
[off
] + 1;
10472 if (si
>= num_of_syms
)
10473 num_of_syms
= si
+ 1;
10477 while (off
< filedata
->ngnuchains
10478 && (filedata
->gnuchains
[off
++] & 1) == 0);
10481 if (num_of_syms
== 0)
10484 free (filedata
->mipsxlat
);
10485 filedata
->mipsxlat
= NULL
;
10486 free (filedata
->gnuchains
);
10487 filedata
->gnuchains
= NULL
;
10488 free (filedata
->gnubuckets
);
10489 filedata
->gnubuckets
= NULL
;
10490 filedata
->ngnubuckets
= 0;
10491 filedata
->ngnuchains
= 0;
10495 return num_of_syms
;
10498 /* Parse and display the contents of the dynamic section. */
10501 process_dynamic_section (Filedata
* filedata
)
10503 Elf_Internal_Dyn
* entry
;
10505 if (filedata
->dynamic_size
== 0)
10509 if (filedata
->is_separate
)
10510 printf (_("\nThere is no dynamic section in linked file '%s'.\n"),
10511 filedata
->file_name
);
10513 printf (_("\nThere is no dynamic section in this file.\n"));
10521 if (! get_32bit_dynamic_section (filedata
))
10526 if (! get_64bit_dynamic_section (filedata
))
10530 /* Find the appropriate symbol table. */
10531 if (filedata
->dynamic_symbols
== NULL
|| do_histogram
)
10533 unsigned long num_of_syms
;
10535 for (entry
= filedata
->dynamic_section
;
10536 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
10538 if (entry
->d_tag
== DT_SYMTAB
)
10539 filedata
->dynamic_info
[DT_SYMTAB
] = entry
->d_un
.d_val
;
10540 else if (entry
->d_tag
== DT_SYMENT
)
10541 filedata
->dynamic_info
[DT_SYMENT
] = entry
->d_un
.d_val
;
10542 else if (entry
->d_tag
== DT_HASH
)
10543 filedata
->dynamic_info
[DT_HASH
] = entry
->d_un
.d_val
;
10544 else if (entry
->d_tag
== DT_GNU_HASH
)
10545 filedata
->dynamic_info_DT_GNU_HASH
= entry
->d_un
.d_val
;
10546 else if ((filedata
->file_header
.e_machine
== EM_MIPS
10547 || filedata
->file_header
.e_machine
== EM_MIPS_RS3_LE
)
10548 && entry
->d_tag
== DT_MIPS_XHASH
)
10550 filedata
->dynamic_info_DT_MIPS_XHASH
= entry
->d_un
.d_val
;
10551 filedata
->dynamic_info_DT_GNU_HASH
= entry
->d_un
.d_val
;
10554 num_of_syms
= get_num_dynamic_syms (filedata
);
10556 if (num_of_syms
!= 0
10557 && filedata
->dynamic_symbols
== NULL
10558 && filedata
->dynamic_info
[DT_SYMTAB
]
10559 && filedata
->dynamic_info
[DT_SYMENT
])
10561 Elf_Internal_Phdr
*seg
;
10562 bfd_vma vma
= filedata
->dynamic_info
[DT_SYMTAB
];
10564 if (! get_program_headers (filedata
))
10566 error (_("Cannot interpret virtual addresses "
10567 "without program headers.\n"));
10571 for (seg
= filedata
->program_headers
;
10572 seg
< filedata
->program_headers
+ filedata
->file_header
.e_phnum
;
10575 if (seg
->p_type
!= PT_LOAD
)
10578 if (seg
->p_offset
+ seg
->p_filesz
> filedata
->file_size
)
10580 /* See PR 21379 for a reproducer. */
10581 error (_("Invalid PT_LOAD entry\n"));
10585 if (vma
>= (seg
->p_vaddr
& -seg
->p_align
)
10586 && vma
< seg
->p_vaddr
+ seg
->p_filesz
)
10588 /* Since we do not know how big the symbol table is,
10589 we default to reading in up to the end of PT_LOAD
10590 segment and processing that. This is overkill, I
10591 know, but it should work. */
10592 Elf_Internal_Shdr section
;
10593 section
.sh_offset
= (vma
- seg
->p_vaddr
10595 section
.sh_size
= (num_of_syms
10596 * filedata
->dynamic_info
[DT_SYMENT
]);
10597 section
.sh_entsize
= filedata
->dynamic_info
[DT_SYMENT
];
10600 && filedata
->dynamic_symtab_section
!= NULL
10601 && ((filedata
->dynamic_symtab_section
->sh_offset
10602 != section
.sh_offset
)
10603 || (filedata
->dynamic_symtab_section
->sh_size
10604 != section
.sh_size
)
10605 || (filedata
->dynamic_symtab_section
->sh_entsize
10606 != section
.sh_entsize
)))
10608 the .dynsym section doesn't match the DT_SYMTAB and DT_SYMENT tags\n"));
10610 section
.sh_name
= filedata
->string_table_length
;
10611 filedata
->dynamic_symbols
10612 = GET_ELF_SYMBOLS (filedata
, §ion
,
10613 &filedata
->num_dynamic_syms
);
10614 if (filedata
->dynamic_symbols
== NULL
10615 || filedata
->num_dynamic_syms
!= num_of_syms
)
10617 error (_("Corrupt DT_SYMTAB dynamic entry\n"));
10626 /* Similarly find a string table. */
10627 if (filedata
->dynamic_strings
== NULL
)
10628 for (entry
= filedata
->dynamic_section
;
10629 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
10632 if (entry
->d_tag
== DT_STRTAB
)
10633 filedata
->dynamic_info
[DT_STRTAB
] = entry
->d_un
.d_val
;
10635 if (entry
->d_tag
== DT_STRSZ
)
10636 filedata
->dynamic_info
[DT_STRSZ
] = entry
->d_un
.d_val
;
10638 if (filedata
->dynamic_info
[DT_STRTAB
]
10639 && filedata
->dynamic_info
[DT_STRSZ
])
10641 unsigned long offset
;
10642 bfd_size_type str_tab_len
= filedata
->dynamic_info
[DT_STRSZ
];
10644 offset
= offset_from_vma (filedata
,
10645 filedata
->dynamic_info
[DT_STRTAB
],
10648 && filedata
->dynamic_strtab_section
10649 && ((filedata
->dynamic_strtab_section
->sh_offset
10650 != (file_ptr
) offset
)
10651 || (filedata
->dynamic_strtab_section
->sh_size
10654 the .dynstr section doesn't match the DT_STRTAB and DT_STRSZ tags\n"));
10656 filedata
->dynamic_strings
10657 = (char *) get_data (NULL
, filedata
, offset
, 1, str_tab_len
,
10658 _("dynamic string table"));
10659 if (filedata
->dynamic_strings
== NULL
)
10661 error (_("Corrupt DT_STRTAB dynamic entry\n"));
10665 filedata
->dynamic_strings_length
= str_tab_len
;
10670 /* And find the syminfo section if available. */
10671 if (filedata
->dynamic_syminfo
== NULL
)
10673 unsigned long syminsz
= 0;
10675 for (entry
= filedata
->dynamic_section
;
10676 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
10679 if (entry
->d_tag
== DT_SYMINENT
)
10681 /* Note: these braces are necessary to avoid a syntax
10682 error from the SunOS4 C compiler. */
10683 /* PR binutils/17531: A corrupt file can trigger this test.
10684 So do not use an assert, instead generate an error message. */
10685 if (sizeof (Elf_External_Syminfo
) != entry
->d_un
.d_val
)
10686 error (_("Bad value (%d) for SYMINENT entry\n"),
10687 (int) entry
->d_un
.d_val
);
10689 else if (entry
->d_tag
== DT_SYMINSZ
)
10690 syminsz
= entry
->d_un
.d_val
;
10691 else if (entry
->d_tag
== DT_SYMINFO
)
10692 filedata
->dynamic_syminfo_offset
10693 = offset_from_vma (filedata
, entry
->d_un
.d_val
, syminsz
);
10696 if (filedata
->dynamic_syminfo_offset
!= 0 && syminsz
!= 0)
10698 Elf_External_Syminfo
* extsyminfo
;
10699 Elf_External_Syminfo
* extsym
;
10700 Elf_Internal_Syminfo
* syminfo
;
10702 /* There is a syminfo section. Read the data. */
10703 extsyminfo
= (Elf_External_Syminfo
*)
10704 get_data (NULL
, filedata
, filedata
->dynamic_syminfo_offset
,
10705 1, syminsz
, _("symbol information"));
10709 if (filedata
->dynamic_syminfo
!= NULL
)
10711 error (_("Multiple dynamic symbol information sections found\n"));
10712 free (filedata
->dynamic_syminfo
);
10714 filedata
->dynamic_syminfo
= (Elf_Internal_Syminfo
*) malloc (syminsz
);
10715 if (filedata
->dynamic_syminfo
== NULL
)
10717 error (_("Out of memory allocating %lu bytes "
10718 "for dynamic symbol info\n"),
10719 (unsigned long) syminsz
);
10723 filedata
->dynamic_syminfo_nent
10724 = syminsz
/ sizeof (Elf_External_Syminfo
);
10725 for (syminfo
= filedata
->dynamic_syminfo
, extsym
= extsyminfo
;
10726 syminfo
< (filedata
->dynamic_syminfo
10727 + filedata
->dynamic_syminfo_nent
);
10728 ++syminfo
, ++extsym
)
10730 syminfo
->si_boundto
= BYTE_GET (extsym
->si_boundto
);
10731 syminfo
->si_flags
= BYTE_GET (extsym
->si_flags
);
10738 if (do_dynamic
&& filedata
->dynamic_addr
)
10740 if (filedata
->dynamic_nent
== 1)
10742 if (filedata
->is_separate
)
10743 printf (_("\nIn linked file '%s' the dynamic section at offset 0x%lx contains 1 entry:\n"),
10744 filedata
->file_name
,
10745 filedata
->dynamic_addr
);
10747 printf (_("\nDynamic section at offset 0x%lx contains 1 entry:\n"),
10748 filedata
->dynamic_addr
);
10752 if (filedata
->is_separate
)
10753 printf (_("\nIn linked file '%s' the dynamic section at offset 0x%lx contains %lu entries:\n"),
10754 filedata
->file_name
,
10755 filedata
->dynamic_addr
,
10756 (unsigned long) filedata
->dynamic_nent
);
10758 printf (_("\nDynamic section at offset 0x%lx contains %lu entries:\n"),
10759 filedata
->dynamic_addr
,
10760 (unsigned long) filedata
->dynamic_nent
);
10764 printf (_(" Tag Type Name/Value\n"));
10766 for (entry
= filedata
->dynamic_section
;
10767 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
10772 const char * dtype
;
10775 print_vma (entry
->d_tag
, FULL_HEX
);
10776 dtype
= get_dynamic_type (filedata
, entry
->d_tag
);
10777 printf (" (%s)%*s", dtype
,
10778 ((is_32bit_elf
? 27 : 19) - (int) strlen (dtype
)), " ");
10781 switch (entry
->d_tag
)
10785 print_dynamic_flags (entry
->d_un
.d_val
);
10795 switch (entry
->d_tag
)
10798 printf (_("Auxiliary library"));
10802 printf (_("Filter library"));
10806 printf (_("Configuration file"));
10810 printf (_("Dependency audit library"));
10814 printf (_("Audit library"));
10818 if (VALID_DYNAMIC_NAME (filedata
, entry
->d_un
.d_val
))
10819 printf (": [%s]\n",
10820 GET_DYNAMIC_NAME (filedata
, entry
->d_un
.d_val
));
10824 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
10833 printf (_("Flags:"));
10835 if (entry
->d_un
.d_val
== 0)
10836 printf (_(" None\n"));
10839 unsigned long int val
= entry
->d_un
.d_val
;
10841 if (val
& DTF_1_PARINIT
)
10843 printf (" PARINIT");
10844 val
^= DTF_1_PARINIT
;
10846 if (val
& DTF_1_CONFEXP
)
10848 printf (" CONFEXP");
10849 val
^= DTF_1_CONFEXP
;
10852 printf (" %lx", val
);
10861 printf (_("Flags:"));
10863 if (entry
->d_un
.d_val
== 0)
10864 printf (_(" None\n"));
10867 unsigned long int val
= entry
->d_un
.d_val
;
10869 if (val
& DF_P1_LAZYLOAD
)
10871 printf (" LAZYLOAD");
10872 val
^= DF_P1_LAZYLOAD
;
10874 if (val
& DF_P1_GROUPPERM
)
10876 printf (" GROUPPERM");
10877 val
^= DF_P1_GROUPPERM
;
10880 printf (" %lx", val
);
10889 printf (_("Flags:"));
10890 if (entry
->d_un
.d_val
== 0)
10891 printf (_(" None\n"));
10894 unsigned long int val
= entry
->d_un
.d_val
;
10896 if (val
& DF_1_NOW
)
10901 if (val
& DF_1_GLOBAL
)
10903 printf (" GLOBAL");
10904 val
^= DF_1_GLOBAL
;
10906 if (val
& DF_1_GROUP
)
10911 if (val
& DF_1_NODELETE
)
10913 printf (" NODELETE");
10914 val
^= DF_1_NODELETE
;
10916 if (val
& DF_1_LOADFLTR
)
10918 printf (" LOADFLTR");
10919 val
^= DF_1_LOADFLTR
;
10921 if (val
& DF_1_INITFIRST
)
10923 printf (" INITFIRST");
10924 val
^= DF_1_INITFIRST
;
10926 if (val
& DF_1_NOOPEN
)
10928 printf (" NOOPEN");
10929 val
^= DF_1_NOOPEN
;
10931 if (val
& DF_1_ORIGIN
)
10933 printf (" ORIGIN");
10934 val
^= DF_1_ORIGIN
;
10936 if (val
& DF_1_DIRECT
)
10938 printf (" DIRECT");
10939 val
^= DF_1_DIRECT
;
10941 if (val
& DF_1_TRANS
)
10946 if (val
& DF_1_INTERPOSE
)
10948 printf (" INTERPOSE");
10949 val
^= DF_1_INTERPOSE
;
10951 if (val
& DF_1_NODEFLIB
)
10953 printf (" NODEFLIB");
10954 val
^= DF_1_NODEFLIB
;
10956 if (val
& DF_1_NODUMP
)
10958 printf (" NODUMP");
10959 val
^= DF_1_NODUMP
;
10961 if (val
& DF_1_CONFALT
)
10963 printf (" CONFALT");
10964 val
^= DF_1_CONFALT
;
10966 if (val
& DF_1_ENDFILTEE
)
10968 printf (" ENDFILTEE");
10969 val
^= DF_1_ENDFILTEE
;
10971 if (val
& DF_1_DISPRELDNE
)
10973 printf (" DISPRELDNE");
10974 val
^= DF_1_DISPRELDNE
;
10976 if (val
& DF_1_DISPRELPND
)
10978 printf (" DISPRELPND");
10979 val
^= DF_1_DISPRELPND
;
10981 if (val
& DF_1_NODIRECT
)
10983 printf (" NODIRECT");
10984 val
^= DF_1_NODIRECT
;
10986 if (val
& DF_1_IGNMULDEF
)
10988 printf (" IGNMULDEF");
10989 val
^= DF_1_IGNMULDEF
;
10991 if (val
& DF_1_NOKSYMS
)
10993 printf (" NOKSYMS");
10994 val
^= DF_1_NOKSYMS
;
10996 if (val
& DF_1_NOHDR
)
11001 if (val
& DF_1_EDITED
)
11003 printf (" EDITED");
11004 val
^= DF_1_EDITED
;
11006 if (val
& DF_1_NORELOC
)
11008 printf (" NORELOC");
11009 val
^= DF_1_NORELOC
;
11011 if (val
& DF_1_SYMINTPOSE
)
11013 printf (" SYMINTPOSE");
11014 val
^= DF_1_SYMINTPOSE
;
11016 if (val
& DF_1_GLOBAUDIT
)
11018 printf (" GLOBAUDIT");
11019 val
^= DF_1_GLOBAUDIT
;
11021 if (val
& DF_1_SINGLETON
)
11023 printf (" SINGLETON");
11024 val
^= DF_1_SINGLETON
;
11026 if (val
& DF_1_STUB
)
11031 if (val
& DF_1_PIE
)
11036 if (val
& DF_1_KMOD
)
11041 if (val
& DF_1_WEAKFILTER
)
11043 printf (" WEAKFILTER");
11044 val
^= DF_1_WEAKFILTER
;
11046 if (val
& DF_1_NOCOMMON
)
11048 printf (" NOCOMMON");
11049 val
^= DF_1_NOCOMMON
;
11052 printf (" %lx", val
);
11059 filedata
->dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
11061 puts (get_dynamic_type (filedata
, entry
->d_un
.d_val
));
11081 filedata
->dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
11087 if (VALID_DYNAMIC_NAME (filedata
, entry
->d_un
.d_val
))
11088 name
= GET_DYNAMIC_NAME (filedata
, entry
->d_un
.d_val
);
11094 switch (entry
->d_tag
)
11097 printf (_("Shared library: [%s]"), name
);
11099 if (streq (name
, filedata
->program_interpreter
))
11100 printf (_(" program interpreter"));
11104 printf (_("Library soname: [%s]"), name
);
11108 printf (_("Library rpath: [%s]"), name
);
11112 printf (_("Library runpath: [%s]"), name
);
11116 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
11121 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
11134 filedata
->dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
11135 /* Fall through. */
11139 case DT_INIT_ARRAYSZ
:
11140 case DT_FINI_ARRAYSZ
:
11141 case DT_GNU_CONFLICTSZ
:
11142 case DT_GNU_LIBLISTSZ
:
11145 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
11146 printf (_(" (bytes)\n"));
11151 case DT_VERNEEDNUM
:
11156 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
11165 case DT_INIT_ARRAY
:
11166 case DT_FINI_ARRAY
:
11169 if (entry
->d_tag
== DT_USED
11170 && VALID_DYNAMIC_NAME (filedata
, entry
->d_un
.d_val
))
11172 char * name
= GET_DYNAMIC_NAME (filedata
, entry
->d_un
.d_val
);
11176 printf (_("Not needed object: [%s]\n"), name
);
11181 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
11187 /* The value of this entry is ignored. */
11192 case DT_GNU_PRELINKED
:
11196 time_t atime
= entry
->d_un
.d_val
;
11198 tmp
= gmtime (&atime
);
11199 /* PR 17533 file: 041-1244816-0.004. */
11201 printf (_("<corrupt time val: %lx"),
11202 (unsigned long) atime
);
11204 printf ("%04u-%02u-%02uT%02u:%02u:%02u\n",
11205 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
11206 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
11212 filedata
->dynamic_info_DT_GNU_HASH
= entry
->d_un
.d_val
;
11215 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
11220 case DT_GNU_FLAGS_1
:
11223 printf (_("Flags:"));
11224 if (entry
->d_un
.d_val
== 0)
11225 printf (_(" None\n"));
11228 unsigned long int val
= entry
->d_un
.d_val
;
11230 if (val
& DF_GNU_1_UNIQUE
)
11232 printf (" UNIQUE");
11233 val
^= DF_GNU_1_UNIQUE
;
11236 printf (" %lx", val
);
11243 if ((entry
->d_tag
>= DT_VERSYM
) && (entry
->d_tag
<= DT_VERNEEDNUM
))
11244 filedata
->version_info
[DT_VERSIONTAGIDX (entry
->d_tag
)]
11245 = entry
->d_un
.d_val
;
11249 switch (filedata
->file_header
.e_machine
)
11252 dynamic_section_aarch64_val (entry
);
11255 case EM_MIPS_RS3_LE
:
11256 dynamic_section_mips_val (filedata
, entry
);
11259 dynamic_section_parisc_val (entry
);
11262 dynamic_section_ia64_val (entry
);
11265 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
11277 get_ver_flags (unsigned int flags
)
11279 static char buff
[128];
11286 if (flags
& VER_FLG_BASE
)
11287 strcat (buff
, "BASE");
11289 if (flags
& VER_FLG_WEAK
)
11291 if (flags
& VER_FLG_BASE
)
11292 strcat (buff
, " | ");
11294 strcat (buff
, "WEAK");
11297 if (flags
& VER_FLG_INFO
)
11299 if (flags
& (VER_FLG_BASE
|VER_FLG_WEAK
))
11300 strcat (buff
, " | ");
11302 strcat (buff
, "INFO");
11305 if (flags
& ~(VER_FLG_BASE
| VER_FLG_WEAK
| VER_FLG_INFO
))
11307 if (flags
& (VER_FLG_BASE
| VER_FLG_WEAK
| VER_FLG_INFO
))
11308 strcat (buff
, " | ");
11310 strcat (buff
, _("<unknown>"));
11316 /* Display the contents of the version sections. */
11319 process_version_sections (Filedata
* filedata
)
11321 Elf_Internal_Shdr
* section
;
11323 bool found
= false;
11328 for (i
= 0, section
= filedata
->section_headers
;
11329 i
< filedata
->file_header
.e_shnum
;
11332 switch (section
->sh_type
)
11334 case SHT_GNU_verdef
:
11336 Elf_External_Verdef
* edefs
;
11343 if (filedata
->is_separate
)
11344 printf (ngettext ("\nIn linked file '%s' the version definition section '%s' contains %u entry:\n",
11345 "\nIn linked file '%s' the version definition section '%s' contains %u entries:\n",
11347 filedata
->file_name
,
11348 printable_section_name (filedata
, section
),
11351 printf (ngettext ("\nVersion definition section '%s' "
11352 "contains %u entry:\n",
11353 "\nVersion definition section '%s' "
11354 "contains %u entries:\n",
11356 printable_section_name (filedata
, section
),
11359 printf (_(" Addr: 0x"));
11360 printf_vma (section
->sh_addr
);
11361 printf (_(" Offset: %#08lx Link: %u (%s)\n"),
11362 (unsigned long) section
->sh_offset
, section
->sh_link
,
11363 printable_section_name_from_index (filedata
, section
->sh_link
));
11365 edefs
= (Elf_External_Verdef
*)
11366 get_data (NULL
, filedata
, section
->sh_offset
, 1,section
->sh_size
,
11367 _("version definition section"));
11370 endbuf
= (char *) edefs
+ section
->sh_size
;
11372 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
11375 Elf_External_Verdef
* edef
;
11376 Elf_Internal_Verdef ent
;
11377 Elf_External_Verdaux
* eaux
;
11378 Elf_Internal_Verdaux aux
;
11379 unsigned long isum
;
11382 vstart
= ((char *) edefs
) + idx
;
11383 if (vstart
+ sizeof (*edef
) > endbuf
)
11386 edef
= (Elf_External_Verdef
*) vstart
;
11388 ent
.vd_version
= BYTE_GET (edef
->vd_version
);
11389 ent
.vd_flags
= BYTE_GET (edef
->vd_flags
);
11390 ent
.vd_ndx
= BYTE_GET (edef
->vd_ndx
);
11391 ent
.vd_cnt
= BYTE_GET (edef
->vd_cnt
);
11392 ent
.vd_hash
= BYTE_GET (edef
->vd_hash
);
11393 ent
.vd_aux
= BYTE_GET (edef
->vd_aux
);
11394 ent
.vd_next
= BYTE_GET (edef
->vd_next
);
11396 printf (_(" %#06lx: Rev: %d Flags: %s"),
11397 idx
, ent
.vd_version
, get_ver_flags (ent
.vd_flags
));
11399 printf (_(" Index: %d Cnt: %d "),
11400 ent
.vd_ndx
, ent
.vd_cnt
);
11402 /* Check for overflow. */
11403 if (ent
.vd_aux
> (size_t) (endbuf
- vstart
))
11406 vstart
+= ent
.vd_aux
;
11408 if (vstart
+ sizeof (*eaux
) > endbuf
)
11410 eaux
= (Elf_External_Verdaux
*) vstart
;
11412 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
11413 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
11415 if (VALID_DYNAMIC_NAME (filedata
, aux
.vda_name
))
11416 printf (_("Name: %s\n"),
11417 GET_DYNAMIC_NAME (filedata
, aux
.vda_name
));
11419 printf (_("Name index: %ld\n"), aux
.vda_name
);
11421 isum
= idx
+ ent
.vd_aux
;
11423 for (j
= 1; j
< ent
.vd_cnt
; j
++)
11425 if (aux
.vda_next
< sizeof (*eaux
)
11426 && !(j
== ent
.vd_cnt
- 1 && aux
.vda_next
== 0))
11428 warn (_("Invalid vda_next field of %lx\n"),
11433 /* Check for overflow. */
11434 if (aux
.vda_next
> (size_t) (endbuf
- vstart
))
11437 isum
+= aux
.vda_next
;
11438 vstart
+= aux
.vda_next
;
11440 if (vstart
+ sizeof (*eaux
) > endbuf
)
11442 eaux
= (Elf_External_Verdaux
*) vstart
;
11444 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
11445 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
11447 if (VALID_DYNAMIC_NAME (filedata
, aux
.vda_name
))
11448 printf (_(" %#06lx: Parent %d: %s\n"),
11450 GET_DYNAMIC_NAME (filedata
, aux
.vda_name
));
11452 printf (_(" %#06lx: Parent %d, name index: %ld\n"),
11453 isum
, j
, aux
.vda_name
);
11456 if (j
< ent
.vd_cnt
)
11457 printf (_(" Version def aux past end of section\n"));
11460 file: id:000001,src:000172+005151,op:splice,rep:2. */
11461 if (ent
.vd_next
< sizeof (*edef
)
11462 && !(cnt
== section
->sh_info
- 1 && ent
.vd_next
== 0))
11464 warn (_("Invalid vd_next field of %lx\n"), ent
.vd_next
);
11465 cnt
= section
->sh_info
;
11468 if (ent
.vd_next
> (size_t) (endbuf
- ((char *) edefs
+ idx
)))
11471 idx
+= ent
.vd_next
;
11474 if (cnt
< section
->sh_info
)
11475 printf (_(" Version definition past end of section\n"));
11481 case SHT_GNU_verneed
:
11483 Elf_External_Verneed
* eneed
;
11490 if (filedata
->is_separate
)
11491 printf (ngettext ("\nIn linked file '%s' the version needs section '%s' contains %u entry:\n",
11492 "\nIn linked file '%s' the version needs section '%s' contains %u entries:\n",
11494 filedata
->file_name
,
11495 printable_section_name (filedata
, section
),
11498 printf (ngettext ("\nVersion needs section '%s' "
11499 "contains %u entry:\n",
11500 "\nVersion needs section '%s' "
11501 "contains %u entries:\n",
11503 printable_section_name (filedata
, section
),
11506 printf (_(" Addr: 0x"));
11507 printf_vma (section
->sh_addr
);
11508 printf (_(" Offset: %#08lx Link: %u (%s)\n"),
11509 (unsigned long) section
->sh_offset
, section
->sh_link
,
11510 printable_section_name_from_index (filedata
, section
->sh_link
));
11512 eneed
= (Elf_External_Verneed
*) get_data (NULL
, filedata
,
11513 section
->sh_offset
, 1,
11515 _("Version Needs section"));
11518 endbuf
= (char *) eneed
+ section
->sh_size
;
11520 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
11522 Elf_External_Verneed
* entry
;
11523 Elf_Internal_Verneed ent
;
11524 unsigned long isum
;
11528 vstart
= ((char *) eneed
) + idx
;
11529 if (vstart
+ sizeof (*entry
) > endbuf
)
11532 entry
= (Elf_External_Verneed
*) vstart
;
11534 ent
.vn_version
= BYTE_GET (entry
->vn_version
);
11535 ent
.vn_cnt
= BYTE_GET (entry
->vn_cnt
);
11536 ent
.vn_file
= BYTE_GET (entry
->vn_file
);
11537 ent
.vn_aux
= BYTE_GET (entry
->vn_aux
);
11538 ent
.vn_next
= BYTE_GET (entry
->vn_next
);
11540 printf (_(" %#06lx: Version: %d"), idx
, ent
.vn_version
);
11542 if (VALID_DYNAMIC_NAME (filedata
, ent
.vn_file
))
11543 printf (_(" File: %s"),
11544 GET_DYNAMIC_NAME (filedata
, ent
.vn_file
));
11546 printf (_(" File: %lx"), ent
.vn_file
);
11548 printf (_(" Cnt: %d\n"), ent
.vn_cnt
);
11550 /* Check for overflow. */
11551 if (ent
.vn_aux
> (size_t) (endbuf
- vstart
))
11553 vstart
+= ent
.vn_aux
;
11555 for (j
= 0, isum
= idx
+ ent
.vn_aux
; j
< ent
.vn_cnt
; ++j
)
11557 Elf_External_Vernaux
* eaux
;
11558 Elf_Internal_Vernaux aux
;
11560 if (vstart
+ sizeof (*eaux
) > endbuf
)
11562 eaux
= (Elf_External_Vernaux
*) vstart
;
11564 aux
.vna_hash
= BYTE_GET (eaux
->vna_hash
);
11565 aux
.vna_flags
= BYTE_GET (eaux
->vna_flags
);
11566 aux
.vna_other
= BYTE_GET (eaux
->vna_other
);
11567 aux
.vna_name
= BYTE_GET (eaux
->vna_name
);
11568 aux
.vna_next
= BYTE_GET (eaux
->vna_next
);
11570 if (VALID_DYNAMIC_NAME (filedata
, aux
.vna_name
))
11571 printf (_(" %#06lx: Name: %s"),
11572 isum
, GET_DYNAMIC_NAME (filedata
, aux
.vna_name
));
11574 printf (_(" %#06lx: Name index: %lx"),
11575 isum
, aux
.vna_name
);
11577 printf (_(" Flags: %s Version: %d\n"),
11578 get_ver_flags (aux
.vna_flags
), aux
.vna_other
);
11580 if (aux
.vna_next
< sizeof (*eaux
)
11581 && !(j
== ent
.vn_cnt
- 1 && aux
.vna_next
== 0))
11583 warn (_("Invalid vna_next field of %lx\n"),
11588 /* Check for overflow. */
11589 if (aux
.vna_next
> (size_t) (endbuf
- vstart
))
11591 isum
+= aux
.vna_next
;
11592 vstart
+= aux
.vna_next
;
11595 if (j
< ent
.vn_cnt
)
11596 warn (_("Missing Version Needs auxiliary information\n"));
11598 if (ent
.vn_next
< sizeof (*entry
)
11599 && !(cnt
== section
->sh_info
- 1 && ent
.vn_next
== 0))
11601 warn (_("Invalid vn_next field of %lx\n"), ent
.vn_next
);
11602 cnt
= section
->sh_info
;
11605 if (ent
.vn_next
> (size_t) (endbuf
- ((char *) eneed
+ idx
)))
11607 idx
+= ent
.vn_next
;
11610 if (cnt
< section
->sh_info
)
11611 warn (_("Missing Version Needs information\n"));
11617 case SHT_GNU_versym
:
11619 Elf_Internal_Shdr
* link_section
;
11622 unsigned char * edata
;
11623 unsigned short * data
;
11625 Elf_Internal_Sym
* symbols
;
11626 Elf_Internal_Shdr
* string_sec
;
11627 unsigned long num_syms
;
11630 if (section
->sh_link
>= filedata
->file_header
.e_shnum
)
11633 link_section
= filedata
->section_headers
+ section
->sh_link
;
11634 total
= section
->sh_size
/ sizeof (Elf_External_Versym
);
11636 if (link_section
->sh_link
>= filedata
->file_header
.e_shnum
)
11641 symbols
= GET_ELF_SYMBOLS (filedata
, link_section
, & num_syms
);
11642 if (symbols
== NULL
)
11645 string_sec
= filedata
->section_headers
+ link_section
->sh_link
;
11647 strtab
= (char *) get_data (NULL
, filedata
, string_sec
->sh_offset
, 1,
11648 string_sec
->sh_size
,
11649 _("version string table"));
11656 if (filedata
->is_separate
)
11657 printf (ngettext ("\nIn linked file '%s' the version symbols section '%s' contains %lu entry:\n",
11658 "\nIn linked file '%s' the version symbols section '%s' contains %lu entries:\n",
11660 filedata
->file_name
,
11661 printable_section_name (filedata
, section
),
11662 (unsigned long) total
);
11664 printf (ngettext ("\nVersion symbols section '%s' "
11665 "contains %lu entry:\n",
11666 "\nVersion symbols section '%s' "
11667 "contains %lu entries:\n",
11669 printable_section_name (filedata
, section
),
11670 (unsigned long) total
);
11672 printf (_(" Addr: 0x"));
11673 printf_vma (section
->sh_addr
);
11674 printf (_(" Offset: %#08lx Link: %u (%s)\n"),
11675 (unsigned long) section
->sh_offset
, section
->sh_link
,
11676 printable_section_name (filedata
, link_section
));
11678 off
= offset_from_vma (filedata
,
11679 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)],
11680 total
* sizeof (short));
11681 edata
= (unsigned char *) get_data (NULL
, filedata
, off
,
11682 sizeof (short), total
,
11683 _("version symbol data"));
11691 data
= (short unsigned int *) cmalloc (total
, sizeof (short));
11693 for (cnt
= total
; cnt
--;)
11694 data
[cnt
] = byte_get (edata
+ cnt
* sizeof (short),
11699 for (cnt
= 0; cnt
< total
; cnt
+= 4)
11703 char *invalid
= _("*invalid*");
11705 printf (" %03x:", cnt
);
11707 for (j
= 0; (j
< 4) && (cnt
+ j
) < total
; ++j
)
11708 switch (data
[cnt
+ j
])
11711 fputs (_(" 0 (*local*) "), stdout
);
11715 fputs (_(" 1 (*global*) "), stdout
);
11719 nn
= printf ("%4x%c", data
[cnt
+ j
] & VERSYM_VERSION
,
11720 data
[cnt
+ j
] & VERSYM_HIDDEN
? 'h' : ' ');
11722 /* If this index value is greater than the size of the symbols
11723 array, break to avoid an out-of-bounds read. */
11724 if ((unsigned long)(cnt
+ j
) >= num_syms
)
11726 warn (_("invalid index into symbol array\n"));
11731 if (filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)])
11733 Elf_Internal_Verneed ivn
;
11734 unsigned long offset
;
11736 offset
= offset_from_vma
11738 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)],
11739 sizeof (Elf_External_Verneed
));
11743 Elf_Internal_Vernaux ivna
;
11744 Elf_External_Verneed evn
;
11745 Elf_External_Vernaux evna
;
11746 unsigned long a_off
;
11748 if (get_data (&evn
, filedata
, offset
, sizeof (evn
), 1,
11749 _("version need")) == NULL
)
11752 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
11753 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
11755 a_off
= offset
+ ivn
.vn_aux
;
11759 if (get_data (&evna
, filedata
, a_off
, sizeof (evna
),
11760 1, _("version need aux (2)")) == NULL
)
11763 ivna
.vna_other
= 0;
11767 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
11768 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
11771 a_off
+= ivna
.vna_next
;
11773 while (ivna
.vna_other
!= data
[cnt
+ j
]
11774 && ivna
.vna_next
!= 0);
11776 if (ivna
.vna_other
== data
[cnt
+ j
])
11778 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
11780 if (ivna
.vna_name
>= string_sec
->sh_size
)
11783 name
= strtab
+ ivna
.vna_name
;
11787 offset
+= ivn
.vn_next
;
11789 while (ivn
.vn_next
);
11792 if (data
[cnt
+ j
] != 0x8001
11793 && filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
11795 Elf_Internal_Verdef ivd
;
11796 Elf_External_Verdef evd
;
11797 unsigned long offset
;
11799 offset
= offset_from_vma
11801 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)],
11806 if (get_data (&evd
, filedata
, offset
, sizeof (evd
), 1,
11807 _("version def")) == NULL
)
11810 /* PR 17531: file: 046-1082287-0.004. */
11811 ivd
.vd_ndx
= (data
[cnt
+ j
] & VERSYM_VERSION
) + 1;
11816 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
11817 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
11820 offset
+= ivd
.vd_next
;
11822 while (ivd
.vd_ndx
!= (data
[cnt
+ j
] & VERSYM_VERSION
)
11823 && ivd
.vd_next
!= 0);
11825 if (ivd
.vd_ndx
== (data
[cnt
+ j
] & VERSYM_VERSION
))
11827 Elf_External_Verdaux evda
;
11828 Elf_Internal_Verdaux ivda
;
11830 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
11832 if (get_data (&evda
, filedata
,
11833 offset
- ivd
.vd_next
+ ivd
.vd_aux
,
11835 _("version def aux")) == NULL
)
11838 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
11840 if (ivda
.vda_name
>= string_sec
->sh_size
)
11842 else if (name
!= NULL
&& name
!= invalid
)
11843 name
= _("*both*");
11845 name
= strtab
+ ivda
.vda_name
;
11849 nn
+= printf ("(%s%-*s",
11851 12 - (int) strlen (name
),
11855 printf ("%*c", 18 - nn
, ' ');
11874 if (filedata
->is_separate
)
11875 printf (_("\nNo version information found in linked file '%s'.\n"),
11876 filedata
->file_name
);
11878 printf (_("\nNo version information found in this file.\n"));
11884 static const char *
11885 get_symbol_binding (Filedata
* filedata
, unsigned int binding
)
11887 static char buff
[64];
11891 case STB_LOCAL
: return "LOCAL";
11892 case STB_GLOBAL
: return "GLOBAL";
11893 case STB_WEAK
: return "WEAK";
11895 if (binding
>= STB_LOPROC
&& binding
<= STB_HIPROC
)
11896 snprintf (buff
, sizeof (buff
), _("<processor specific>: %d"),
11898 else if (binding
>= STB_LOOS
&& binding
<= STB_HIOS
)
11900 if (binding
== STB_GNU_UNIQUE
11901 && filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_GNU
)
11903 snprintf (buff
, sizeof (buff
), _("<OS specific>: %d"), binding
);
11906 snprintf (buff
, sizeof (buff
), _("<unknown>: %d"), binding
);
11911 static const char *
11912 get_symbol_type (Filedata
* filedata
, unsigned int type
)
11914 static char buff
[64];
11918 case STT_NOTYPE
: return "NOTYPE";
11919 case STT_OBJECT
: return "OBJECT";
11920 case STT_FUNC
: return "FUNC";
11921 case STT_SECTION
: return "SECTION";
11922 case STT_FILE
: return "FILE";
11923 case STT_COMMON
: return "COMMON";
11924 case STT_TLS
: return "TLS";
11925 case STT_RELC
: return "RELC";
11926 case STT_SRELC
: return "SRELC";
11928 if (type
>= STT_LOPROC
&& type
<= STT_HIPROC
)
11930 if (filedata
->file_header
.e_machine
== EM_ARM
&& type
== STT_ARM_TFUNC
)
11931 return "THUMB_FUNC";
11933 if (filedata
->file_header
.e_machine
== EM_SPARCV9
&& type
== STT_REGISTER
)
11936 if (filedata
->file_header
.e_machine
== EM_PARISC
&& type
== STT_PARISC_MILLI
)
11937 return "PARISC_MILLI";
11939 snprintf (buff
, sizeof (buff
), _("<processor specific>: %d"), type
);
11941 else if (type
>= STT_LOOS
&& type
<= STT_HIOS
)
11943 if (filedata
->file_header
.e_machine
== EM_PARISC
)
11945 if (type
== STT_HP_OPAQUE
)
11946 return "HP_OPAQUE";
11947 if (type
== STT_HP_STUB
)
11951 if (type
== STT_GNU_IFUNC
11952 && (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_GNU
11953 || filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_FREEBSD
))
11956 snprintf (buff
, sizeof (buff
), _("<OS specific>: %d"), type
);
11959 snprintf (buff
, sizeof (buff
), _("<unknown>: %d"), type
);
11964 static const char *
11965 get_symbol_visibility (unsigned int visibility
)
11967 switch (visibility
)
11969 case STV_DEFAULT
: return "DEFAULT";
11970 case STV_INTERNAL
: return "INTERNAL";
11971 case STV_HIDDEN
: return "HIDDEN";
11972 case STV_PROTECTED
: return "PROTECTED";
11974 error (_("Unrecognized visibility value: %u\n"), visibility
);
11975 return _("<unknown>");
11979 static const char *
11980 get_alpha_symbol_other (unsigned int other
)
11984 case STO_ALPHA_NOPV
: return "NOPV";
11985 case STO_ALPHA_STD_GPLOAD
: return "STD GPLOAD";
11987 error (_("Unrecognized alpha specific other value: %u\n"), other
);
11988 return _("<unknown>");
11992 static const char *
11993 get_solaris_symbol_visibility (unsigned int visibility
)
11995 switch (visibility
)
11997 case 4: return "EXPORTED";
11998 case 5: return "SINGLETON";
11999 case 6: return "ELIMINATE";
12000 default: return get_symbol_visibility (visibility
);
12004 static const char *
12005 get_aarch64_symbol_other (unsigned int other
)
12007 static char buf
[32];
12009 if (other
& STO_AARCH64_VARIANT_PCS
)
12011 other
&= ~STO_AARCH64_VARIANT_PCS
;
12013 return "VARIANT_PCS";
12014 snprintf (buf
, sizeof buf
, "VARIANT_PCS | %x", other
);
12020 static const char *
12021 get_mips_symbol_other (unsigned int other
)
12025 case STO_OPTIONAL
: return "OPTIONAL";
12026 case STO_MIPS_PLT
: return "MIPS PLT";
12027 case STO_MIPS_PIC
: return "MIPS PIC";
12028 case STO_MICROMIPS
: return "MICROMIPS";
12029 case STO_MICROMIPS
| STO_MIPS_PIC
: return "MICROMIPS, MIPS PIC";
12030 case STO_MIPS16
: return "MIPS16";
12031 default: return NULL
;
12035 static const char *
12036 get_ia64_symbol_other (Filedata
* filedata
, unsigned int other
)
12038 if (is_ia64_vms (filedata
))
12040 static char res
[32];
12044 /* Function types is for images and .STB files only. */
12045 switch (filedata
->file_header
.e_type
)
12049 switch (VMS_ST_FUNC_TYPE (other
))
12051 case VMS_SFT_CODE_ADDR
:
12052 strcat (res
, " CA");
12054 case VMS_SFT_SYMV_IDX
:
12055 strcat (res
, " VEC");
12058 strcat (res
, " FD");
12060 case VMS_SFT_RESERVE
:
12061 strcat (res
, " RSV");
12064 warn (_("Unrecognized IA64 VMS ST Function type: %d\n"),
12065 VMS_ST_FUNC_TYPE (other
));
12066 strcat (res
, " <unknown>");
12073 switch (VMS_ST_LINKAGE (other
))
12075 case VMS_STL_IGNORE
:
12076 strcat (res
, " IGN");
12078 case VMS_STL_RESERVE
:
12079 strcat (res
, " RSV");
12082 strcat (res
, " STD");
12085 strcat (res
, " LNK");
12088 warn (_("Unrecognized IA64 VMS ST Linkage: %d\n"),
12089 VMS_ST_LINKAGE (other
));
12090 strcat (res
, " <unknown>");
12102 static const char *
12103 get_ppc64_symbol_other (unsigned int other
)
12105 if ((other
& ~STO_PPC64_LOCAL_MASK
) != 0)
12108 other
>>= STO_PPC64_LOCAL_BIT
;
12111 static char buf
[64];
12113 other
= ppc64_decode_local_entry (other
);
12114 snprintf (buf
, sizeof buf
, _("<localentry>: %d"), other
);
12120 static const char *
12121 get_symbol_other (Filedata
* filedata
, unsigned int other
)
12123 const char * result
= NULL
;
12124 static char buff
[64];
12129 switch (filedata
->file_header
.e_machine
)
12132 result
= get_alpha_symbol_other (other
);
12135 result
= get_aarch64_symbol_other (other
);
12138 result
= get_mips_symbol_other (other
);
12141 result
= get_ia64_symbol_other (filedata
, other
);
12144 result
= get_ppc64_symbol_other (other
);
12154 snprintf (buff
, sizeof buff
, _("<other>: %x"), other
);
12158 static const char *
12159 get_symbol_index_type (Filedata
* filedata
, unsigned int type
)
12161 static char buff
[32];
12165 case SHN_UNDEF
: return "UND";
12166 case SHN_ABS
: return "ABS";
12167 case SHN_COMMON
: return "COM";
12169 if (type
== SHN_IA_64_ANSI_COMMON
12170 && filedata
->file_header
.e_machine
== EM_IA_64
12171 && filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_HPUX
)
12173 else if ((filedata
->file_header
.e_machine
== EM_X86_64
12174 || filedata
->file_header
.e_machine
== EM_L1OM
12175 || filedata
->file_header
.e_machine
== EM_K1OM
)
12176 && type
== SHN_X86_64_LCOMMON
)
12177 return "LARGE_COM";
12178 else if ((type
== SHN_MIPS_SCOMMON
12179 && filedata
->file_header
.e_machine
== EM_MIPS
)
12180 || (type
== SHN_TIC6X_SCOMMON
12181 && filedata
->file_header
.e_machine
== EM_TI_C6000
))
12183 else if (type
== SHN_MIPS_SUNDEFINED
12184 && filedata
->file_header
.e_machine
== EM_MIPS
)
12186 else if (type
>= SHN_LOPROC
&& type
<= SHN_HIPROC
)
12187 sprintf (buff
, "PRC[0x%04x]", type
& 0xffff);
12188 else if (type
>= SHN_LOOS
&& type
<= SHN_HIOS
)
12189 sprintf (buff
, "OS [0x%04x]", type
& 0xffff);
12190 else if (type
>= SHN_LORESERVE
)
12191 sprintf (buff
, "RSV[0x%04x]", type
& 0xffff);
12192 else if (filedata
->file_header
.e_shnum
!= 0
12193 && type
>= filedata
->file_header
.e_shnum
)
12194 sprintf (buff
, _("bad section index[%3d]"), type
);
12196 sprintf (buff
, "%3d", type
);
12203 static const char *
12204 get_symbol_version_string (Filedata
* filedata
,
12206 const char * strtab
,
12207 unsigned long int strtab_size
,
12209 Elf_Internal_Sym
* psym
,
12210 enum versioned_symbol_info
* sym_info
,
12211 unsigned short * vna_other
)
12213 unsigned char data
[2];
12214 unsigned short vers_data
;
12215 unsigned long offset
;
12216 unsigned short max_vd_ndx
;
12219 || filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)] == 0)
12222 offset
= offset_from_vma (filedata
,
12223 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)],
12224 sizeof data
+ si
* sizeof (vers_data
));
12226 if (get_data (&data
, filedata
, offset
+ si
* sizeof (vers_data
),
12227 sizeof (data
), 1, _("version data")) == NULL
)
12230 vers_data
= byte_get (data
, 2);
12232 if ((vers_data
& VERSYM_HIDDEN
) == 0 && vers_data
== 0)
12235 *sym_info
= (vers_data
& VERSYM_HIDDEN
) != 0 ? symbol_hidden
: symbol_public
;
12238 /* Usually we'd only see verdef for defined symbols, and verneed for
12239 undefined symbols. However, symbols defined by the linker in
12240 .dynbss for variables copied from a shared library in order to
12241 avoid text relocations are defined yet have verneed. We could
12242 use a heuristic to detect the special case, for example, check
12243 for verneed first on symbols defined in SHT_NOBITS sections, but
12244 it is simpler and more reliable to just look for both verdef and
12245 verneed. .dynbss might not be mapped to a SHT_NOBITS section. */
12247 if (psym
->st_shndx
!= SHN_UNDEF
12248 && vers_data
!= 0x8001
12249 && filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
12251 Elf_Internal_Verdef ivd
;
12252 Elf_Internal_Verdaux ivda
;
12253 Elf_External_Verdaux evda
;
12256 off
= offset_from_vma (filedata
,
12257 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)],
12258 sizeof (Elf_External_Verdef
));
12262 Elf_External_Verdef evd
;
12264 if (get_data (&evd
, filedata
, off
, sizeof (evd
), 1,
12265 _("version def")) == NULL
)
12274 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
12275 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
12276 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
12277 ivd
.vd_flags
= BYTE_GET (evd
.vd_flags
);
12280 if ((ivd
.vd_ndx
& VERSYM_VERSION
) > max_vd_ndx
)
12281 max_vd_ndx
= ivd
.vd_ndx
& VERSYM_VERSION
;
12283 off
+= ivd
.vd_next
;
12285 while (ivd
.vd_ndx
!= (vers_data
& VERSYM_VERSION
) && ivd
.vd_next
!= 0);
12287 if (ivd
.vd_ndx
== (vers_data
& VERSYM_VERSION
))
12289 if (ivd
.vd_ndx
== 1 && ivd
.vd_flags
== VER_FLG_BASE
)
12292 off
-= ivd
.vd_next
;
12295 if (get_data (&evda
, filedata
, off
, sizeof (evda
), 1,
12296 _("version def aux")) != NULL
)
12298 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
12300 if (psym
->st_name
!= ivda
.vda_name
)
12301 return (ivda
.vda_name
< strtab_size
12302 ? strtab
+ ivda
.vda_name
: _("<corrupt>"));
12307 if (filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)])
12309 Elf_External_Verneed evn
;
12310 Elf_Internal_Verneed ivn
;
12311 Elf_Internal_Vernaux ivna
;
12313 offset
= offset_from_vma (filedata
,
12314 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)],
12318 unsigned long vna_off
;
12320 if (get_data (&evn
, filedata
, offset
, sizeof (evn
), 1,
12321 _("version need")) == NULL
)
12324 ivna
.vna_other
= 0;
12329 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
12330 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
12332 vna_off
= offset
+ ivn
.vn_aux
;
12336 Elf_External_Vernaux evna
;
12338 if (get_data (&evna
, filedata
, vna_off
, sizeof (evna
), 1,
12339 _("version need aux (3)")) == NULL
)
12342 ivna
.vna_other
= 0;
12347 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
12348 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
12349 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
12352 vna_off
+= ivna
.vna_next
;
12354 while (ivna
.vna_other
!= vers_data
&& ivna
.vna_next
!= 0);
12356 if (ivna
.vna_other
== vers_data
)
12359 offset
+= ivn
.vn_next
;
12361 while (ivn
.vn_next
!= 0);
12363 if (ivna
.vna_other
== vers_data
)
12365 *sym_info
= symbol_undefined
;
12366 *vna_other
= ivna
.vna_other
;
12367 return (ivna
.vna_name
< strtab_size
12368 ? strtab
+ ivna
.vna_name
: _("<corrupt>"));
12370 else if ((max_vd_ndx
|| (vers_data
& VERSYM_VERSION
) != 1)
12371 && (vers_data
& VERSYM_VERSION
) > max_vd_ndx
)
12372 return _("<corrupt>");
12378 print_dynamic_symbol (Filedata
*filedata
, unsigned long si
,
12379 Elf_Internal_Sym
*symtab
,
12380 Elf_Internal_Shdr
*section
,
12381 char *strtab
, size_t strtab_size
)
12383 const char *version_string
;
12384 enum versioned_symbol_info sym_info
;
12385 unsigned short vna_other
;
12386 Elf_Internal_Sym
*psym
= symtab
+ si
;
12388 printf ("%6ld: ", si
);
12389 print_vma (psym
->st_value
, LONG_HEX
);
12391 print_vma (psym
->st_size
, DEC_5
);
12392 printf (" %-7s", get_symbol_type (filedata
, ELF_ST_TYPE (psym
->st_info
)));
12393 printf (" %-6s", get_symbol_binding (filedata
, ELF_ST_BIND (psym
->st_info
)));
12394 if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_SOLARIS
)
12395 printf (" %-7s", get_solaris_symbol_visibility (psym
->st_other
));
12398 unsigned int vis
= ELF_ST_VISIBILITY (psym
->st_other
);
12400 printf (" %-7s", get_symbol_visibility (vis
));
12401 /* Check to see if any other bits in the st_other field are set.
12402 Note - displaying this information disrupts the layout of the
12403 table being generated, but for the moment this case is very rare. */
12404 if (psym
->st_other
^ vis
)
12405 printf (" [%s] ", get_symbol_other (filedata
, psym
->st_other
^ vis
));
12407 printf (" %4s ", get_symbol_index_type (filedata
, psym
->st_shndx
));
12409 bool is_valid
= VALID_SYMBOL_NAME (strtab
, strtab_size
, psym
->st_name
);
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
;
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 && startswith (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
;
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 bool reloc_inplace
= false;
14181 bool 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 bool 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
;
14458 num_bytes
= section
->sh_size
;
14460 if (filedata
->is_separate
)
14461 printf (_("\nString dump of section '%s' in linked file %s:\n"),
14462 printable_section_name (filedata
, section
),
14463 filedata
->file_name
);
14465 printf (_("\nString dump of section '%s':\n"),
14466 printable_section_name (filedata
, section
));
14468 if (decompress_dumps
)
14470 dwarf_size_type new_size
= num_bytes
;
14471 dwarf_size_type uncompressed_size
= 0;
14473 if ((section
->sh_flags
& SHF_COMPRESSED
) != 0)
14475 Elf_Internal_Chdr chdr
;
14476 unsigned int compression_header_size
14477 = get_compression_header (& chdr
, (unsigned char *) start
,
14479 if (compression_header_size
== 0)
14480 /* An error message will have already been generated
14481 by get_compression_header. */
14484 if (chdr
.ch_type
!= ELFCOMPRESS_ZLIB
)
14486 warn (_("section '%s' has unsupported compress type: %d\n"),
14487 printable_section_name (filedata
, section
), chdr
.ch_type
);
14490 uncompressed_size
= chdr
.ch_size
;
14491 start
+= compression_header_size
;
14492 new_size
-= compression_header_size
;
14494 else if (new_size
> 12 && streq ((char *) start
, "ZLIB"))
14496 /* Read the zlib header. In this case, it should be "ZLIB"
14497 followed by the uncompressed section size, 8 bytes in
14498 big-endian order. */
14499 uncompressed_size
= start
[4]; uncompressed_size
<<= 8;
14500 uncompressed_size
+= start
[5]; uncompressed_size
<<= 8;
14501 uncompressed_size
+= start
[6]; uncompressed_size
<<= 8;
14502 uncompressed_size
+= start
[7]; uncompressed_size
<<= 8;
14503 uncompressed_size
+= start
[8]; uncompressed_size
<<= 8;
14504 uncompressed_size
+= start
[9]; uncompressed_size
<<= 8;
14505 uncompressed_size
+= start
[10]; uncompressed_size
<<= 8;
14506 uncompressed_size
+= start
[11];
14511 if (uncompressed_size
)
14513 if (uncompress_section_contents (& start
,
14514 uncompressed_size
, & new_size
))
14515 num_bytes
= new_size
;
14518 error (_("Unable to decompress section %s\n"),
14519 printable_section_name (filedata
, section
));
14524 start
= real_start
;
14527 /* If the section being dumped has relocations against it the user might
14528 be expecting these relocations to have been applied. Check for this
14529 case and issue a warning message in order to avoid confusion.
14530 FIXME: Maybe we ought to have an option that dumps a section with
14531 relocs applied ? */
14532 for (relsec
= filedata
->section_headers
;
14533 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
14536 if ((relsec
->sh_type
!= SHT_RELA
&& relsec
->sh_type
!= SHT_REL
)
14537 || relsec
->sh_info
>= filedata
->file_header
.e_shnum
14538 || filedata
->section_headers
+ relsec
->sh_info
!= section
14539 || relsec
->sh_size
== 0
14540 || relsec
->sh_link
>= filedata
->file_header
.e_shnum
)
14543 printf (_(" Note: This section has relocations against it, but these have NOT been applied to this dump.\n"));
14548 end
= start
+ num_bytes
;
14549 some_strings_shown
= false;
14551 #ifdef HAVE_MBSTATE_T
14553 /* Initialise the multibyte conversion state. */
14554 memset (& state
, 0, sizeof (state
));
14557 bool continuing
= false;
14561 while (!ISPRINT (* data
))
14562 if (++ data
>= end
)
14567 size_t maxlen
= end
- data
;
14572 continuing
= false;
14576 printf (" [%6lx] ", (unsigned long) (data
- start
));
14590 /* PR 25543: Treat new-lines as string-ending characters. */
14599 /* Do not print control characters directly as they can affect terminal
14600 settings. Such characters usually appear in the names generated
14601 by the assembler for local labels. */
14604 printf ("^%c", c
+ 0x40);
14606 else if (ISPRINT (c
))
14613 #ifdef HAVE_MBSTATE_T
14616 /* Let printf do the hard work of displaying multibyte characters. */
14617 printf ("%.1s", data
- 1);
14618 #ifdef HAVE_MBSTATE_T
14619 /* Try to find out how many bytes made up the character that was
14620 just printed. Advance the symbol pointer past the bytes that
14622 n
= mbrtowc (& w
, (char *)(data
- 1), MB_CUR_MAX
, & state
);
14626 if (n
!= (size_t) -1 && n
!= (size_t) -2 && n
> 0)
14636 printf (_("<corrupt>\n"));
14639 some_strings_shown
= true;
14643 if (! some_strings_shown
)
14644 printf (_(" No strings found in this section."));
14657 dump_section_as_bytes (Elf_Internal_Shdr
*section
,
14658 Filedata
*filedata
,
14661 Elf_Internal_Shdr
* relsec
;
14662 bfd_size_type bytes
;
14663 bfd_size_type section_size
;
14665 unsigned char * data
;
14666 unsigned char * real_start
;
14667 unsigned char * start
;
14669 real_start
= start
= (unsigned char *) get_section_contents (section
, filedata
);
14671 /* PR 21820: Do not fail if the section was empty. */
14672 return section
->sh_size
== 0 || section
->sh_type
== SHT_NOBITS
;
14674 section_size
= section
->sh_size
;
14676 if (filedata
->is_separate
)
14677 printf (_("\nHex dump of section '%s' in linked file %s:\n"),
14678 printable_section_name (filedata
, section
),
14679 filedata
->file_name
);
14681 printf (_("\nHex dump of section '%s':\n"),
14682 printable_section_name (filedata
, section
));
14684 if (decompress_dumps
)
14686 dwarf_size_type new_size
= section_size
;
14687 dwarf_size_type uncompressed_size
= 0;
14689 if ((section
->sh_flags
& SHF_COMPRESSED
) != 0)
14691 Elf_Internal_Chdr chdr
;
14692 unsigned int compression_header_size
14693 = get_compression_header (& chdr
, start
, section_size
);
14695 if (compression_header_size
== 0)
14696 /* An error message will have already been generated
14697 by get_compression_header. */
14700 if (chdr
.ch_type
!= ELFCOMPRESS_ZLIB
)
14702 warn (_("section '%s' has unsupported compress type: %d\n"),
14703 printable_section_name (filedata
, section
), chdr
.ch_type
);
14706 uncompressed_size
= chdr
.ch_size
;
14707 start
+= compression_header_size
;
14708 new_size
-= compression_header_size
;
14710 else if (new_size
> 12 && streq ((char *) start
, "ZLIB"))
14712 /* Read the zlib header. In this case, it should be "ZLIB"
14713 followed by the uncompressed section size, 8 bytes in
14714 big-endian order. */
14715 uncompressed_size
= start
[4]; uncompressed_size
<<= 8;
14716 uncompressed_size
+= start
[5]; uncompressed_size
<<= 8;
14717 uncompressed_size
+= start
[6]; uncompressed_size
<<= 8;
14718 uncompressed_size
+= start
[7]; uncompressed_size
<<= 8;
14719 uncompressed_size
+= start
[8]; uncompressed_size
<<= 8;
14720 uncompressed_size
+= start
[9]; uncompressed_size
<<= 8;
14721 uncompressed_size
+= start
[10]; uncompressed_size
<<= 8;
14722 uncompressed_size
+= start
[11];
14727 if (uncompressed_size
)
14729 if (uncompress_section_contents (& start
, uncompressed_size
,
14732 section_size
= new_size
;
14736 error (_("Unable to decompress section %s\n"),
14737 printable_section_name (filedata
, section
));
14738 /* FIXME: Print the section anyway ? */
14743 start
= real_start
;
14748 if (! apply_relocations (filedata
, section
, start
, section_size
, NULL
, NULL
))
14753 /* If the section being dumped has relocations against it the user might
14754 be expecting these relocations to have been applied. Check for this
14755 case and issue a warning message in order to avoid confusion.
14756 FIXME: Maybe we ought to have an option that dumps a section with
14757 relocs applied ? */
14758 for (relsec
= filedata
->section_headers
;
14759 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
14762 if ((relsec
->sh_type
!= SHT_RELA
&& relsec
->sh_type
!= SHT_REL
)
14763 || relsec
->sh_info
>= filedata
->file_header
.e_shnum
14764 || filedata
->section_headers
+ relsec
->sh_info
!= section
14765 || relsec
->sh_size
== 0
14766 || relsec
->sh_link
>= filedata
->file_header
.e_shnum
)
14769 printf (_(" NOTE: This section has relocations against it, but these have NOT been applied to this dump.\n"));
14774 addr
= section
->sh_addr
;
14775 bytes
= section_size
;
14784 lbytes
= (bytes
> 16 ? 16 : bytes
);
14786 printf (" 0x%8.8lx ", (unsigned long) addr
);
14788 for (j
= 0; j
< 16; j
++)
14791 printf ("%2.2x", data
[j
]);
14799 for (j
= 0; j
< lbytes
; j
++)
14802 if (k
>= ' ' && k
< 0x7f)
14825 #ifdef ENABLE_LIBCTF
14826 static ctf_sect_t
*
14827 shdr_to_ctf_sect (ctf_sect_t
*buf
, Elf_Internal_Shdr
*shdr
, Filedata
*filedata
)
14829 buf
->cts_name
= SECTION_NAME_PRINT (shdr
);
14830 buf
->cts_size
= shdr
->sh_size
;
14831 buf
->cts_entsize
= shdr
->sh_entsize
;
14836 /* Formatting callback function passed to ctf_dump. Returns either the pointer
14837 it is passed, or a pointer to newly-allocated storage, in which case
14838 dump_ctf() will free it when it no longer needs it. */
14841 dump_ctf_indent_lines (ctf_sect_names_t sect ATTRIBUTE_UNUSED
,
14842 char *s
, void *arg
)
14844 const char *blanks
= arg
;
14847 if (asprintf (&new_s
, "%s%s", blanks
, s
) < 0)
14852 /* Dump CTF errors/warnings. */
14854 dump_ctf_errs (ctf_dict_t
*fp
)
14856 ctf_next_t
*it
= NULL
;
14861 /* Dump accumulated errors and warnings. */
14862 while ((errtext
= ctf_errwarning_next (fp
, &it
, &is_warning
, &err
)) != NULL
)
14864 error (_("%s: %s"), is_warning
? _("warning"): _("error"),
14868 if (err
!= ECTF_NEXT_END
)
14869 error (_("CTF error: cannot get CTF errors: `%s'"), ctf_errmsg (err
));
14872 /* Dump one CTF archive member. */
14875 dump_ctf_archive_member (ctf_dict_t
*ctf
, const char *name
, void *arg
)
14877 ctf_dict_t
*parent
= (ctf_dict_t
*) arg
;
14878 const char *things
[] = {"Header", "Labels", "Data objects",
14879 "Function objects", "Variables", "Types", "Strings",
14881 const char **thing
;
14885 /* Only print out the name of non-default-named archive members.
14886 The name .ctf appears everywhere, even for things that aren't
14887 really archives, so printing it out is liable to be confusing.
14889 The parent, if there is one, is the default-owned archive member:
14890 avoid importing it into itself. (This does no harm, but looks
14893 if (strcmp (name
, ".ctf") != 0)
14895 printf (_("\nCTF archive member: %s:\n"), name
);
14896 ctf_import (ctf
, parent
);
14899 for (i
= 0, thing
= things
; *thing
[0]; thing
++, i
++)
14901 ctf_dump_state_t
*s
= NULL
;
14904 printf ("\n %s:\n", *thing
);
14905 while ((item
= ctf_dump (ctf
, &s
, i
, dump_ctf_indent_lines
,
14906 (void *) " ")) != NULL
)
14908 printf ("%s\n", item
);
14912 if (ctf_errno (ctf
))
14914 error (_("Iteration failed: %s, %s\n"), *thing
,
14915 ctf_errmsg (ctf_errno (ctf
)));
14922 dump_ctf_errs (ctf
);
14927 dump_section_as_ctf (Elf_Internal_Shdr
* section
, Filedata
* filedata
)
14929 Elf_Internal_Shdr
* parent_sec
= NULL
;
14930 Elf_Internal_Shdr
* symtab_sec
= NULL
;
14931 Elf_Internal_Shdr
* strtab_sec
= NULL
;
14932 void * data
= NULL
;
14933 void * symdata
= NULL
;
14934 void * strdata
= NULL
;
14935 void * parentdata
= NULL
;
14936 ctf_sect_t ctfsect
, symsect
, strsect
, parentsect
;
14937 ctf_sect_t
* symsectp
= NULL
;
14938 ctf_sect_t
* strsectp
= NULL
;
14939 ctf_archive_t
* ctfa
= NULL
;
14940 ctf_archive_t
* parenta
= NULL
, *lookparent
;
14941 ctf_dict_t
* parent
= NULL
;
14946 shdr_to_ctf_sect (&ctfsect
, section
, filedata
);
14947 data
= get_section_contents (section
, filedata
);
14948 ctfsect
.cts_data
= data
;
14950 if (!dump_ctf_symtab_name
)
14951 dump_ctf_symtab_name
= strdup (".dynsym");
14953 if (!dump_ctf_strtab_name
)
14954 dump_ctf_strtab_name
= strdup (".dynstr");
14956 if (dump_ctf_symtab_name
&& dump_ctf_symtab_name
[0] != 0)
14958 if ((symtab_sec
= find_section (filedata
, dump_ctf_symtab_name
)) == NULL
)
14960 error (_("No symbol section named %s\n"), dump_ctf_symtab_name
);
14963 if ((symdata
= (void *) get_data (NULL
, filedata
,
14964 symtab_sec
->sh_offset
, 1,
14965 symtab_sec
->sh_size
,
14966 _("symbols"))) == NULL
)
14968 symsectp
= shdr_to_ctf_sect (&symsect
, symtab_sec
, filedata
);
14969 symsect
.cts_data
= symdata
;
14972 if (dump_ctf_strtab_name
&& dump_ctf_strtab_name
[0] != 0)
14974 if ((strtab_sec
= find_section (filedata
, dump_ctf_strtab_name
)) == NULL
)
14976 error (_("No string table section named %s\n"),
14977 dump_ctf_strtab_name
);
14980 if ((strdata
= (void *) get_data (NULL
, filedata
,
14981 strtab_sec
->sh_offset
, 1,
14982 strtab_sec
->sh_size
,
14983 _("strings"))) == NULL
)
14985 strsectp
= shdr_to_ctf_sect (&strsect
, strtab_sec
, filedata
);
14986 strsect
.cts_data
= strdata
;
14989 if (dump_ctf_parent_name
)
14991 if ((parent_sec
= find_section (filedata
, dump_ctf_parent_name
)) == NULL
)
14993 error (_("No CTF parent section named %s\n"), dump_ctf_parent_name
);
14996 if ((parentdata
= (void *) get_data (NULL
, filedata
,
14997 parent_sec
->sh_offset
, 1,
14998 parent_sec
->sh_size
,
14999 _("CTF parent"))) == NULL
)
15001 shdr_to_ctf_sect (&parentsect
, parent_sec
, filedata
);
15002 parentsect
.cts_data
= parentdata
;
15005 /* Load the CTF file and dump it. It may be a raw CTF section, or an archive:
15006 libctf papers over the difference, so we can pretend it is always an
15007 archive. Possibly open the parent as well, if one was specified. */
15009 if ((ctfa
= ctf_arc_bufopen (&ctfsect
, symsectp
, strsectp
, &err
)) == NULL
)
15011 dump_ctf_errs (NULL
);
15012 error (_("CTF open failure: %s\n"), ctf_errmsg (err
));
15016 ctf_arc_symsect_endianness (ctfa
, filedata
->file_header
.e_ident
[EI_DATA
]
15021 if ((parenta
= ctf_arc_bufopen (&parentsect
, symsectp
, strsectp
,
15024 dump_ctf_errs (NULL
);
15025 error (_("CTF open failure: %s\n"), ctf_errmsg (err
));
15028 lookparent
= parenta
;
15033 /* Assume that the applicable parent archive member is the default one.
15034 (This is what all known implementations are expected to do, if they
15035 put CTFs and their parents in archives together.) */
15036 if ((parent
= ctf_dict_open (lookparent
, NULL
, &err
)) == NULL
)
15038 dump_ctf_errs (NULL
);
15039 error (_("CTF open failure: %s\n"), ctf_errmsg (err
));
15045 if (filedata
->is_separate
)
15046 printf (_("\nDump of CTF section '%s' in linked file %s:\n"),
15047 printable_section_name (filedata
, section
),
15048 filedata
->file_name
);
15050 printf (_("\nDump of CTF section '%s':\n"),
15051 printable_section_name (filedata
, section
));
15053 if ((err
= ctf_archive_iter (ctfa
, dump_ctf_archive_member
, parent
)) != 0)
15055 dump_ctf_errs (NULL
);
15056 error (_("CTF member open failure: %s\n"), ctf_errmsg (err
));
15061 ctf_dict_close (parent
);
15063 ctf_close (parenta
);
15073 load_specific_debug_section (enum dwarf_section_display_enum debug
,
15074 const Elf_Internal_Shdr
* sec
,
15077 struct dwarf_section
* section
= &debug_displays
[debug
].section
;
15079 Filedata
* filedata
= (Filedata
*) data
;
15081 if (section
->start
!= NULL
)
15083 /* If it is already loaded, do nothing. */
15084 if (streq (section
->filename
, filedata
->file_name
))
15086 free (section
->start
);
15089 snprintf (buf
, sizeof (buf
), _("%s section data"), section
->name
);
15090 section
->address
= sec
->sh_addr
;
15091 section
->filename
= filedata
->file_name
;
15092 section
->start
= (unsigned char *) get_data (NULL
, filedata
,
15094 sec
->sh_size
, buf
);
15095 if (section
->start
== NULL
)
15099 unsigned char *start
= section
->start
;
15100 dwarf_size_type size
= sec
->sh_size
;
15101 dwarf_size_type uncompressed_size
= 0;
15103 if ((sec
->sh_flags
& SHF_COMPRESSED
) != 0)
15105 Elf_Internal_Chdr chdr
;
15106 unsigned int compression_header_size
;
15108 if (size
< (is_32bit_elf
15109 ? sizeof (Elf32_External_Chdr
)
15110 : sizeof (Elf64_External_Chdr
)))
15112 warn (_("compressed section %s is too small to contain a compression header\n"),
15117 compression_header_size
= get_compression_header (&chdr
, start
, size
);
15118 if (compression_header_size
== 0)
15119 /* An error message will have already been generated
15120 by get_compression_header. */
15123 if (chdr
.ch_type
!= ELFCOMPRESS_ZLIB
)
15125 warn (_("section '%s' has unsupported compress type: %d\n"),
15126 section
->name
, chdr
.ch_type
);
15129 uncompressed_size
= chdr
.ch_size
;
15130 start
+= compression_header_size
;
15131 size
-= compression_header_size
;
15133 else if (size
> 12 && streq ((char *) start
, "ZLIB"))
15135 /* Read the zlib header. In this case, it should be "ZLIB"
15136 followed by the uncompressed section size, 8 bytes in
15137 big-endian order. */
15138 uncompressed_size
= start
[4]; uncompressed_size
<<= 8;
15139 uncompressed_size
+= start
[5]; uncompressed_size
<<= 8;
15140 uncompressed_size
+= start
[6]; uncompressed_size
<<= 8;
15141 uncompressed_size
+= start
[7]; uncompressed_size
<<= 8;
15142 uncompressed_size
+= start
[8]; uncompressed_size
<<= 8;
15143 uncompressed_size
+= start
[9]; uncompressed_size
<<= 8;
15144 uncompressed_size
+= start
[10]; uncompressed_size
<<= 8;
15145 uncompressed_size
+= start
[11];
15150 if (uncompressed_size
)
15152 if (uncompress_section_contents (&start
, uncompressed_size
,
15155 /* Free the compressed buffer, update the section buffer
15156 and the section size if uncompress is successful. */
15157 free (section
->start
);
15158 section
->start
= start
;
15162 error (_("Unable to decompress section %s\n"),
15163 printable_section_name (filedata
, sec
));
15168 section
->size
= size
;
15171 if (section
->start
== NULL
)
15174 if (debug_displays
[debug
].relocate
)
15176 if (! apply_relocations (filedata
, sec
, section
->start
, section
->size
,
15177 & section
->reloc_info
, & section
->num_relocs
))
15182 section
->reloc_info
= NULL
;
15183 section
->num_relocs
= 0;
15189 #if HAVE_LIBDEBUGINFOD
15190 /* Return a hex string representation of the build-id. */
15192 get_build_id (void * data
)
15194 Filedata
* filedata
= (Filedata
*) data
;
15195 Elf_Internal_Shdr
* shdr
;
15198 /* Iterate through notes to find note.gnu.build-id.
15199 FIXME: Only the first note in any note section is examined. */
15200 for (i
= 0, shdr
= filedata
->section_headers
;
15201 i
< filedata
->file_header
.e_shnum
&& shdr
!= NULL
;
15204 if (shdr
->sh_type
!= SHT_NOTE
)
15209 size_t data_remaining
;
15211 Elf_External_Note
* enote
;
15212 Elf_Internal_Note inote
;
15214 bfd_vma offset
= shdr
->sh_offset
;
15215 bfd_vma align
= shdr
->sh_addralign
;
15216 bfd_vma length
= shdr
->sh_size
;
15218 enote
= (Elf_External_Note
*) get_section_contents (shdr
, filedata
);
15224 else if (align
!= 4 && align
!= 8)
15230 end
= (char *) enote
+ length
;
15231 data_remaining
= end
- (char *) enote
;
15233 if (!is_ia64_vms (filedata
))
15235 min_notesz
= offsetof (Elf_External_Note
, name
);
15236 if (data_remaining
< min_notesz
)
15239 malformed note encountered in section %s whilst scanning for build-id note\n"),
15240 printable_section_name (filedata
, shdr
));
15244 data_remaining
-= min_notesz
;
15246 inote
.type
= BYTE_GET (enote
->type
);
15247 inote
.namesz
= BYTE_GET (enote
->namesz
);
15248 inote
.namedata
= enote
->name
;
15249 inote
.descsz
= BYTE_GET (enote
->descsz
);
15250 inote
.descdata
= ((char *) enote
15251 + ELF_NOTE_DESC_OFFSET (inote
.namesz
, align
));
15252 inote
.descpos
= offset
+ (inote
.descdata
- (char *) enote
);
15253 next
= ((char *) enote
15254 + ELF_NOTE_NEXT_OFFSET (inote
.namesz
, inote
.descsz
, align
));
15258 Elf64_External_VMS_Note
*vms_enote
;
15260 /* PR binutils/15191
15261 Make sure that there is enough data to read. */
15262 min_notesz
= offsetof (Elf64_External_VMS_Note
, name
);
15263 if (data_remaining
< min_notesz
)
15266 malformed note encountered in section %s whilst scanning for build-id note\n"),
15267 printable_section_name (filedata
, shdr
));
15271 data_remaining
-= min_notesz
;
15273 vms_enote
= (Elf64_External_VMS_Note
*) enote
;
15274 inote
.type
= BYTE_GET (vms_enote
->type
);
15275 inote
.namesz
= BYTE_GET (vms_enote
->namesz
);
15276 inote
.namedata
= vms_enote
->name
;
15277 inote
.descsz
= BYTE_GET (vms_enote
->descsz
);
15278 inote
.descdata
= inote
.namedata
+ align_power (inote
.namesz
, 3);
15279 inote
.descpos
= offset
+ (inote
.descdata
- (char *) enote
);
15280 next
= inote
.descdata
+ align_power (inote
.descsz
, 3);
15283 /* Skip malformed notes. */
15284 if ((size_t) (inote
.descdata
- inote
.namedata
) < inote
.namesz
15285 || (size_t) (inote
.descdata
- inote
.namedata
) > data_remaining
15286 || (size_t) (next
- inote
.descdata
) < inote
.descsz
15287 || ((size_t) (next
- inote
.descdata
)
15288 > data_remaining
- (size_t) (inote
.descdata
- inote
.namedata
)))
15291 malformed note encountered in section %s whilst scanning for build-id note\n"),
15292 printable_section_name (filedata
, shdr
));
15297 /* Check if this is the build-id note. If so then convert the build-id
15298 bytes to a hex string. */
15299 if (inote
.namesz
> 0
15300 && const_strneq (inote
.namedata
, "GNU")
15301 && inote
.type
== NT_GNU_BUILD_ID
)
15306 build_id
= malloc (inote
.descsz
* 2 + 1);
15307 if (build_id
== NULL
)
15313 for (j
= 0; j
< inote
.descsz
; ++j
)
15314 sprintf (build_id
+ (j
* 2), "%02x", inote
.descdata
[j
] & 0xff);
15315 build_id
[inote
.descsz
* 2] = '\0';
15318 return (unsigned char *) build_id
;
15325 #endif /* HAVE_LIBDEBUGINFOD */
15327 /* If this is not NULL, load_debug_section will only look for sections
15328 within the list of sections given here. */
15329 static unsigned int * section_subset
= NULL
;
15332 load_debug_section (enum dwarf_section_display_enum debug
, void * data
)
15334 struct dwarf_section
* section
= &debug_displays
[debug
].section
;
15335 Elf_Internal_Shdr
* sec
;
15336 Filedata
* filedata
= (Filedata
*) data
;
15338 /* Without section headers we cannot find any sections. */
15339 if (filedata
->section_headers
== NULL
)
15342 if (filedata
->string_table
== NULL
15343 && filedata
->file_header
.e_shstrndx
!= SHN_UNDEF
15344 && filedata
->file_header
.e_shstrndx
< filedata
->file_header
.e_shnum
)
15346 Elf_Internal_Shdr
* strs
;
15348 /* Read in the string table, so that we have section names to scan. */
15349 strs
= filedata
->section_headers
+ filedata
->file_header
.e_shstrndx
;
15351 if (strs
!= NULL
&& strs
->sh_size
!= 0)
15353 filedata
->string_table
15354 = (char *) get_data (NULL
, filedata
, strs
->sh_offset
,
15355 1, strs
->sh_size
, _("string table"));
15357 filedata
->string_table_length
15358 = filedata
->string_table
!= NULL
? strs
->sh_size
: 0;
15362 /* Locate the debug section. */
15363 sec
= find_section_in_set (filedata
, section
->uncompressed_name
, section_subset
);
15365 section
->name
= section
->uncompressed_name
;
15368 sec
= find_section_in_set (filedata
, section
->compressed_name
, section_subset
);
15370 section
->name
= section
->compressed_name
;
15375 /* If we're loading from a subset of sections, and we've loaded
15376 a section matching this name before, it's likely that it's a
15378 if (section_subset
!= NULL
)
15379 free_debug_section (debug
);
15381 return load_specific_debug_section (debug
, sec
, data
);
15385 free_debug_section (enum dwarf_section_display_enum debug
)
15387 struct dwarf_section
* section
= &debug_displays
[debug
].section
;
15389 if (section
->start
== NULL
)
15392 free ((char *) section
->start
);
15393 section
->start
= NULL
;
15394 section
->address
= 0;
15397 free (section
->reloc_info
);
15398 section
->reloc_info
= NULL
;
15399 section
->num_relocs
= 0;
15403 display_debug_section (int shndx
, Elf_Internal_Shdr
* section
, Filedata
* filedata
)
15405 char * name
= SECTION_NAME_VALID (section
) ? SECTION_NAME (section
) : "";
15406 const char * print_name
= printable_section_name (filedata
, section
);
15407 bfd_size_type length
;
15408 bool result
= true;
15411 length
= section
->sh_size
;
15414 printf (_("\nSection '%s' has no debugging data.\n"), print_name
);
15417 if (section
->sh_type
== SHT_NOBITS
)
15419 /* There is no point in dumping the contents of a debugging section
15420 which has the NOBITS type - the bits in the file will be random.
15421 This can happen when a file containing a .eh_frame section is
15422 stripped with the --only-keep-debug command line option. */
15423 printf (_("section '%s' has the NOBITS type - its contents are unreliable.\n"),
15428 if (const_strneq (name
, ".gnu.linkonce.wi."))
15429 name
= ".debug_info";
15431 /* See if we know how to display the contents of this section. */
15432 for (i
= 0; i
< max
; i
++)
15434 enum dwarf_section_display_enum id
= (enum dwarf_section_display_enum
) i
;
15435 struct dwarf_section_display
* display
= debug_displays
+ i
;
15436 struct dwarf_section
* sec
= & display
->section
;
15438 if (streq (sec
->uncompressed_name
, name
)
15439 || (id
== line
&& const_strneq (name
, ".debug_line."))
15440 || streq (sec
->compressed_name
, name
))
15442 bool secondary
= (section
!= find_section (filedata
, name
));
15445 free_debug_section (id
);
15447 if (i
== line
&& const_strneq (name
, ".debug_line."))
15449 else if (streq (sec
->uncompressed_name
, name
))
15450 sec
->name
= sec
->uncompressed_name
;
15452 sec
->name
= sec
->compressed_name
;
15454 if (load_specific_debug_section (id
, section
, filedata
))
15456 /* If this debug section is part of a CU/TU set in a .dwp file,
15457 restrict load_debug_section to the sections in that set. */
15458 section_subset
= find_cu_tu_set (filedata
, shndx
);
15460 result
&= display
->display (sec
, filedata
);
15462 section_subset
= NULL
;
15464 if (secondary
|| (id
!= info
&& id
!= abbrev
&& id
!= debug_addr
))
15465 free_debug_section (id
);
15473 printf (_("Unrecognized debug section: %s\n"), print_name
);
15480 /* Set DUMP_SECTS for all sections where dumps were requested
15481 based on section name. */
15484 initialise_dumps_byname (Filedata
* filedata
)
15486 struct dump_list_entry
* cur
;
15488 for (cur
= dump_sects_byname
; cur
; cur
= cur
->next
)
15493 for (i
= 0; i
< filedata
->file_header
.e_shnum
; i
++)
15494 if (SECTION_NAME_VALID (filedata
->section_headers
+ i
)
15495 && streq (SECTION_NAME (filedata
->section_headers
+ i
), cur
->name
))
15497 request_dump_bynumber (&filedata
->dump
, i
, cur
->type
);
15501 if (!any
&& !filedata
->is_separate
)
15502 warn (_("Section '%s' was not dumped because it does not exist\n"),
15508 process_section_contents (Filedata
* filedata
)
15510 Elf_Internal_Shdr
* section
;
15517 initialise_dumps_byname (filedata
);
15519 for (i
= 0, section
= filedata
->section_headers
;
15520 i
< filedata
->file_header
.e_shnum
&& i
< filedata
->dump
.num_dump_sects
;
15523 dump_type dump
= filedata
->dump
.dump_sects
[i
];
15525 if (filedata
->is_separate
&& ! process_links
)
15526 dump
&= DEBUG_DUMP
;
15528 #ifdef SUPPORT_DISASSEMBLY
15529 if (dump
& DISASS_DUMP
)
15531 if (! disassemble_section (section
, filedata
))
15535 if (dump
& HEX_DUMP
)
15537 if (! dump_section_as_bytes (section
, filedata
, false))
15541 if (dump
& RELOC_DUMP
)
15543 if (! dump_section_as_bytes (section
, filedata
, true))
15547 if (dump
& STRING_DUMP
)
15549 if (! dump_section_as_strings (section
, filedata
))
15553 if (dump
& DEBUG_DUMP
)
15555 if (! display_debug_section (i
, section
, filedata
))
15559 #ifdef ENABLE_LIBCTF
15560 if (dump
& CTF_DUMP
)
15562 if (! dump_section_as_ctf (section
, filedata
))
15568 if (! filedata
->is_separate
)
15570 /* Check to see if the user requested a
15571 dump of a section that does not exist. */
15572 for (; i
< filedata
->dump
.num_dump_sects
; i
++)
15573 if (filedata
->dump
.dump_sects
[i
])
15575 warn (_("Section %d was not dumped because it does not exist!\n"), i
);
15584 process_mips_fpe_exception (int mask
)
15590 if (mask
& OEX_FPU_INEX
)
15591 fputs ("INEX", stdout
), first
= false;
15592 if (mask
& OEX_FPU_UFLO
)
15593 printf ("%sUFLO", first
? "" : "|"), first
= false;
15594 if (mask
& OEX_FPU_OFLO
)
15595 printf ("%sOFLO", first
? "" : "|"), first
= false;
15596 if (mask
& OEX_FPU_DIV0
)
15597 printf ("%sDIV0", first
? "" : "|"), first
= false;
15598 if (mask
& OEX_FPU_INVAL
)
15599 printf ("%sINVAL", first
? "" : "|");
15602 fputs ("0", stdout
);
15605 /* Display's the value of TAG at location P. If TAG is
15606 greater than 0 it is assumed to be an unknown tag, and
15607 a message is printed to this effect. Otherwise it is
15608 assumed that a message has already been printed.
15610 If the bottom bit of TAG is set it assumed to have a
15611 string value, otherwise it is assumed to have an integer
15614 Returns an updated P pointing to the first unread byte
15615 beyond the end of TAG's value.
15617 Reads at or beyond END will not be made. */
15619 static unsigned char *
15620 display_tag_value (signed int tag
,
15622 const unsigned char * const end
)
15627 printf (" Tag_unknown_%d: ", tag
);
15631 warn (_("<corrupt tag>\n"));
15635 /* PR 17531 file: 027-19978-0.004. */
15636 size_t maxlen
= (end
- p
) - 1;
15641 print_symbol ((int) maxlen
, (const char *) p
);
15642 p
+= strnlen ((char *) p
, maxlen
) + 1;
15646 printf (_("<corrupt string tag>"));
15647 p
= (unsigned char *) end
;
15653 READ_ULEB (val
, p
, end
);
15654 printf ("%ld (0x%lx)\n", val
, val
);
15661 /* ARC ABI attributes section. */
15663 static unsigned char *
15664 display_arc_attribute (unsigned char * p
,
15665 const unsigned char * const end
)
15670 READ_ULEB (tag
, p
, end
);
15674 case Tag_ARC_PCS_config
:
15675 READ_ULEB (val
, p
, end
);
15676 printf (" Tag_ARC_PCS_config: ");
15680 printf (_("Absent/Non standard\n"));
15683 printf (_("Bare metal/mwdt\n"));
15686 printf (_("Bare metal/newlib\n"));
15689 printf (_("Linux/uclibc\n"));
15692 printf (_("Linux/glibc\n"));
15695 printf (_("Unknown\n"));
15700 case Tag_ARC_CPU_base
:
15701 READ_ULEB (val
, p
, end
);
15702 printf (" Tag_ARC_CPU_base: ");
15707 printf (_("Absent\n"));
15709 case TAG_CPU_ARC6xx
:
15710 printf ("ARC6xx\n");
15712 case TAG_CPU_ARC7xx
:
15713 printf ("ARC7xx\n");
15715 case TAG_CPU_ARCEM
:
15716 printf ("ARCEM\n");
15718 case TAG_CPU_ARCHS
:
15719 printf ("ARCHS\n");
15724 case Tag_ARC_CPU_variation
:
15725 READ_ULEB (val
, p
, end
);
15726 printf (" Tag_ARC_CPU_variation: ");
15730 if (val
> 0 && val
< 16)
15731 printf ("Core%d\n", val
);
15733 printf ("Unknown\n");
15737 printf (_("Absent\n"));
15742 case Tag_ARC_CPU_name
:
15743 printf (" Tag_ARC_CPU_name: ");
15744 p
= display_tag_value (-1, p
, end
);
15747 case Tag_ARC_ABI_rf16
:
15748 READ_ULEB (val
, p
, end
);
15749 printf (" Tag_ARC_ABI_rf16: %s\n", val
? _("yes") : _("no"));
15752 case Tag_ARC_ABI_osver
:
15753 READ_ULEB (val
, p
, end
);
15754 printf (" Tag_ARC_ABI_osver: v%d\n", val
);
15757 case Tag_ARC_ABI_pic
:
15758 case Tag_ARC_ABI_sda
:
15759 READ_ULEB (val
, p
, end
);
15760 printf (tag
== Tag_ARC_ABI_sda
? " Tag_ARC_ABI_sda: "
15761 : " Tag_ARC_ABI_pic: ");
15765 printf (_("Absent\n"));
15774 printf (_("Unknown\n"));
15779 case Tag_ARC_ABI_tls
:
15780 READ_ULEB (val
, p
, end
);
15781 printf (" Tag_ARC_ABI_tls: %s\n", val
? "r25": "none");
15784 case Tag_ARC_ABI_enumsize
:
15785 READ_ULEB (val
, p
, end
);
15786 printf (" Tag_ARC_ABI_enumsize: %s\n", val
? _("default") :
15790 case Tag_ARC_ABI_exceptions
:
15791 READ_ULEB (val
, p
, end
);
15792 printf (" Tag_ARC_ABI_exceptions: %s\n", val
? _("OPTFP")
15796 case Tag_ARC_ABI_double_size
:
15797 READ_ULEB (val
, p
, end
);
15798 printf (" Tag_ARC_ABI_double_size: %d\n", val
);
15801 case Tag_ARC_ISA_config
:
15802 printf (" Tag_ARC_ISA_config: ");
15803 p
= display_tag_value (-1, p
, end
);
15806 case Tag_ARC_ISA_apex
:
15807 printf (" Tag_ARC_ISA_apex: ");
15808 p
= display_tag_value (-1, p
, end
);
15811 case Tag_ARC_ISA_mpy_option
:
15812 READ_ULEB (val
, p
, end
);
15813 printf (" Tag_ARC_ISA_mpy_option: %d\n", val
);
15816 case Tag_ARC_ATR_version
:
15817 READ_ULEB (val
, p
, end
);
15818 printf (" Tag_ARC_ATR_version: %d\n", val
);
15822 return display_tag_value (tag
& 1, p
, end
);
15828 /* ARM EABI attributes section. */
15833 /* 0 = special, 1 = string, 2 = uleb123, > 0x80 == table lookup. */
15835 const char *const *table
;
15836 } arm_attr_public_tag
;
15838 static const char *const arm_attr_tag_CPU_arch
[] =
15839 {"Pre-v4", "v4", "v4T", "v5T", "v5TE", "v5TEJ", "v6", "v6KZ", "v6T2",
15840 "v6K", "v7", "v6-M", "v6S-M", "v7E-M", "v8", "v8-R", "v8-M.baseline",
15841 "v8-M.mainline", "", "", "", "v8.1-M.mainline"};
15842 static const char *const arm_attr_tag_ARM_ISA_use
[] = {"No", "Yes"};
15843 static const char *const arm_attr_tag_THUMB_ISA_use
[] =
15844 {"No", "Thumb-1", "Thumb-2", "Yes"};
15845 static const char *const arm_attr_tag_FP_arch
[] =
15846 {"No", "VFPv1", "VFPv2", "VFPv3", "VFPv3-D16", "VFPv4", "VFPv4-D16",
15847 "FP for ARMv8", "FPv5/FP-D16 for ARMv8"};
15848 static const char *const arm_attr_tag_WMMX_arch
[] = {"No", "WMMXv1", "WMMXv2"};
15849 static const char *const arm_attr_tag_Advanced_SIMD_arch
[] =
15850 {"No", "NEONv1", "NEONv1 with Fused-MAC", "NEON for ARMv8",
15851 "NEON for ARMv8.1"};
15852 static const char *const arm_attr_tag_PCS_config
[] =
15853 {"None", "Bare platform", "Linux application", "Linux DSO", "PalmOS 2004",
15854 "PalmOS (reserved)", "SymbianOS 2004", "SymbianOS (reserved)"};
15855 static const char *const arm_attr_tag_ABI_PCS_R9_use
[] =
15856 {"V6", "SB", "TLS", "Unused"};
15857 static const char *const arm_attr_tag_ABI_PCS_RW_data
[] =
15858 {"Absolute", "PC-relative", "SB-relative", "None"};
15859 static const char *const arm_attr_tag_ABI_PCS_RO_data
[] =
15860 {"Absolute", "PC-relative", "None"};
15861 static const char *const arm_attr_tag_ABI_PCS_GOT_use
[] =
15862 {"None", "direct", "GOT-indirect"};
15863 static const char *const arm_attr_tag_ABI_PCS_wchar_t
[] =
15864 {"None", "??? 1", "2", "??? 3", "4"};
15865 static const char *const arm_attr_tag_ABI_FP_rounding
[] = {"Unused", "Needed"};
15866 static const char *const arm_attr_tag_ABI_FP_denormal
[] =
15867 {"Unused", "Needed", "Sign only"};
15868 static const char *const arm_attr_tag_ABI_FP_exceptions
[] = {"Unused", "Needed"};
15869 static const char *const arm_attr_tag_ABI_FP_user_exceptions
[] = {"Unused", "Needed"};
15870 static const char *const arm_attr_tag_ABI_FP_number_model
[] =
15871 {"Unused", "Finite", "RTABI", "IEEE 754"};
15872 static const char *const arm_attr_tag_ABI_enum_size
[] =
15873 {"Unused", "small", "int", "forced to int"};
15874 static const char *const arm_attr_tag_ABI_HardFP_use
[] =
15875 {"As Tag_FP_arch", "SP only", "Reserved", "Deprecated"};
15876 static const char *const arm_attr_tag_ABI_VFP_args
[] =
15877 {"AAPCS", "VFP registers", "custom", "compatible"};
15878 static const char *const arm_attr_tag_ABI_WMMX_args
[] =
15879 {"AAPCS", "WMMX registers", "custom"};
15880 static const char *const arm_attr_tag_ABI_optimization_goals
[] =
15881 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
15882 "Aggressive Size", "Prefer Debug", "Aggressive Debug"};
15883 static const char *const arm_attr_tag_ABI_FP_optimization_goals
[] =
15884 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
15885 "Aggressive Size", "Prefer Accuracy", "Aggressive Accuracy"};
15886 static const char *const arm_attr_tag_CPU_unaligned_access
[] = {"None", "v6"};
15887 static const char *const arm_attr_tag_FP_HP_extension
[] =
15888 {"Not Allowed", "Allowed"};
15889 static const char *const arm_attr_tag_ABI_FP_16bit_format
[] =
15890 {"None", "IEEE 754", "Alternative Format"};
15891 static const char *const arm_attr_tag_DSP_extension
[] =
15892 {"Follow architecture", "Allowed"};
15893 static const char *const arm_attr_tag_MPextension_use
[] =
15894 {"Not Allowed", "Allowed"};
15895 static const char *const arm_attr_tag_DIV_use
[] =
15896 {"Allowed in Thumb-ISA, v7-R or v7-M", "Not allowed",
15897 "Allowed in v7-A with integer division extension"};
15898 static const char *const arm_attr_tag_T2EE_use
[] = {"Not Allowed", "Allowed"};
15899 static const char *const arm_attr_tag_Virtualization_use
[] =
15900 {"Not Allowed", "TrustZone", "Virtualization Extensions",
15901 "TrustZone and Virtualization Extensions"};
15902 static const char *const arm_attr_tag_MPextension_use_legacy
[] =
15903 {"Not Allowed", "Allowed"};
15905 static const char *const arm_attr_tag_MVE_arch
[] =
15906 {"No MVE", "MVE Integer only", "MVE Integer and FP"};
15908 #define LOOKUP(id, name) \
15909 {id, #name, 0x80 | ARRAY_SIZE(arm_attr_tag_##name), arm_attr_tag_##name}
15910 static arm_attr_public_tag arm_attr_public_tags
[] =
15912 {4, "CPU_raw_name", 1, NULL
},
15913 {5, "CPU_name", 1, NULL
},
15914 LOOKUP(6, CPU_arch
),
15915 {7, "CPU_arch_profile", 0, NULL
},
15916 LOOKUP(8, ARM_ISA_use
),
15917 LOOKUP(9, THUMB_ISA_use
),
15918 LOOKUP(10, FP_arch
),
15919 LOOKUP(11, WMMX_arch
),
15920 LOOKUP(12, Advanced_SIMD_arch
),
15921 LOOKUP(13, PCS_config
),
15922 LOOKUP(14, ABI_PCS_R9_use
),
15923 LOOKUP(15, ABI_PCS_RW_data
),
15924 LOOKUP(16, ABI_PCS_RO_data
),
15925 LOOKUP(17, ABI_PCS_GOT_use
),
15926 LOOKUP(18, ABI_PCS_wchar_t
),
15927 LOOKUP(19, ABI_FP_rounding
),
15928 LOOKUP(20, ABI_FP_denormal
),
15929 LOOKUP(21, ABI_FP_exceptions
),
15930 LOOKUP(22, ABI_FP_user_exceptions
),
15931 LOOKUP(23, ABI_FP_number_model
),
15932 {24, "ABI_align_needed", 0, NULL
},
15933 {25, "ABI_align_preserved", 0, NULL
},
15934 LOOKUP(26, ABI_enum_size
),
15935 LOOKUP(27, ABI_HardFP_use
),
15936 LOOKUP(28, ABI_VFP_args
),
15937 LOOKUP(29, ABI_WMMX_args
),
15938 LOOKUP(30, ABI_optimization_goals
),
15939 LOOKUP(31, ABI_FP_optimization_goals
),
15940 {32, "compatibility", 0, NULL
},
15941 LOOKUP(34, CPU_unaligned_access
),
15942 LOOKUP(36, FP_HP_extension
),
15943 LOOKUP(38, ABI_FP_16bit_format
),
15944 LOOKUP(42, MPextension_use
),
15945 LOOKUP(44, DIV_use
),
15946 LOOKUP(46, DSP_extension
),
15947 LOOKUP(48, MVE_arch
),
15948 {64, "nodefaults", 0, NULL
},
15949 {65, "also_compatible_with", 0, NULL
},
15950 LOOKUP(66, T2EE_use
),
15951 {67, "conformance", 1, NULL
},
15952 LOOKUP(68, Virtualization_use
),
15953 LOOKUP(70, MPextension_use_legacy
)
15957 static unsigned char *
15958 display_arm_attribute (unsigned char * p
,
15959 const unsigned char * const end
)
15963 arm_attr_public_tag
* attr
;
15967 READ_ULEB (tag
, p
, end
);
15969 for (i
= 0; i
< ARRAY_SIZE (arm_attr_public_tags
); i
++)
15971 if (arm_attr_public_tags
[i
].tag
== tag
)
15973 attr
= &arm_attr_public_tags
[i
];
15980 printf (" Tag_%s: ", attr
->name
);
15981 switch (attr
->type
)
15986 case 7: /* Tag_CPU_arch_profile. */
15987 READ_ULEB (val
, p
, end
);
15990 case 0: printf (_("None\n")); break;
15991 case 'A': printf (_("Application\n")); break;
15992 case 'R': printf (_("Realtime\n")); break;
15993 case 'M': printf (_("Microcontroller\n")); break;
15994 case 'S': printf (_("Application or Realtime\n")); break;
15995 default: printf ("??? (%d)\n", val
); break;
15999 case 24: /* Tag_align_needed. */
16000 READ_ULEB (val
, p
, end
);
16003 case 0: printf (_("None\n")); break;
16004 case 1: printf (_("8-byte\n")); break;
16005 case 2: printf (_("4-byte\n")); break;
16006 case 3: printf ("??? 3\n"); break;
16009 printf (_("8-byte and up to %d-byte extended\n"),
16012 printf ("??? (%d)\n", val
);
16017 case 25: /* Tag_align_preserved. */
16018 READ_ULEB (val
, p
, end
);
16021 case 0: printf (_("None\n")); break;
16022 case 1: printf (_("8-byte, except leaf SP\n")); break;
16023 case 2: printf (_("8-byte\n")); break;
16024 case 3: printf ("??? 3\n"); break;
16027 printf (_("8-byte and up to %d-byte extended\n"),
16030 printf ("??? (%d)\n", val
);
16035 case 32: /* Tag_compatibility. */
16037 READ_ULEB (val
, p
, end
);
16038 printf (_("flag = %d, vendor = "), val
);
16041 size_t maxlen
= (end
- p
) - 1;
16043 print_symbol ((int) maxlen
, (const char *) p
);
16044 p
+= strnlen ((char *) p
, maxlen
) + 1;
16048 printf (_("<corrupt>"));
16049 p
= (unsigned char *) end
;
16055 case 64: /* Tag_nodefaults. */
16056 /* PR 17531: file: 001-505008-0.01. */
16059 printf (_("True\n"));
16062 case 65: /* Tag_also_compatible_with. */
16063 READ_ULEB (val
, p
, end
);
16064 if (val
== 6 /* Tag_CPU_arch. */)
16066 READ_ULEB (val
, p
, end
);
16067 if ((unsigned int) val
>= ARRAY_SIZE (arm_attr_tag_CPU_arch
))
16068 printf ("??? (%d)\n", val
);
16070 printf ("%s\n", arm_attr_tag_CPU_arch
[val
]);
16074 while (p
< end
&& *(p
++) != '\0' /* NUL terminator. */)
16079 printf (_("<unknown: %d>\n"), tag
);
16085 return display_tag_value (-1, p
, end
);
16087 return display_tag_value (0, p
, end
);
16090 assert (attr
->type
& 0x80);
16091 READ_ULEB (val
, p
, end
);
16092 type
= attr
->type
& 0x7f;
16094 printf ("??? (%d)\n", val
);
16096 printf ("%s\n", attr
->table
[val
]);
16101 return display_tag_value (tag
, p
, end
);
16104 static unsigned char *
16105 display_gnu_attribute (unsigned char * p
,
16106 unsigned char * (* display_proc_gnu_attribute
) (unsigned char *, unsigned int, const unsigned char * const),
16107 const unsigned char * const end
)
16112 READ_ULEB (tag
, p
, end
);
16114 /* Tag_compatibility is the only generic GNU attribute defined at
16118 READ_ULEB (val
, p
, end
);
16120 printf (_("flag = %d, vendor = "), val
);
16123 printf (_("<corrupt>\n"));
16124 warn (_("corrupt vendor attribute\n"));
16130 size_t maxlen
= (end
- p
) - 1;
16132 print_symbol ((int) maxlen
, (const char *) p
);
16133 p
+= strnlen ((char *) p
, maxlen
) + 1;
16137 printf (_("<corrupt>"));
16138 p
= (unsigned char *) end
;
16145 if ((tag
& 2) == 0 && display_proc_gnu_attribute
)
16146 return display_proc_gnu_attribute (p
, tag
, end
);
16148 return display_tag_value (tag
, p
, end
);
16151 static unsigned char *
16152 display_m68k_gnu_attribute (unsigned char * p
,
16154 const unsigned char * const end
)
16158 if (tag
== Tag_GNU_M68K_ABI_FP
)
16160 printf (" Tag_GNU_M68K_ABI_FP: ");
16163 printf (_("<corrupt>\n"));
16166 READ_ULEB (val
, p
, end
);
16169 printf ("(%#x), ", val
);
16174 printf (_("unspecified hard/soft float\n"));
16177 printf (_("hard float\n"));
16180 printf (_("soft float\n"));
16186 return display_tag_value (tag
& 1, p
, end
);
16189 static unsigned char *
16190 display_power_gnu_attribute (unsigned char * p
,
16192 const unsigned char * const end
)
16196 if (tag
== Tag_GNU_Power_ABI_FP
)
16198 printf (" Tag_GNU_Power_ABI_FP: ");
16201 printf (_("<corrupt>\n"));
16204 READ_ULEB (val
, p
, end
);
16207 printf ("(%#x), ", val
);
16212 printf (_("unspecified hard/soft float, "));
16215 printf (_("hard float, "));
16218 printf (_("soft float, "));
16221 printf (_("single-precision hard float, "));
16228 printf (_("unspecified long double\n"));
16231 printf (_("128-bit IBM long double\n"));
16234 printf (_("64-bit long double\n"));
16237 printf (_("128-bit IEEE long double\n"));
16243 if (tag
== Tag_GNU_Power_ABI_Vector
)
16245 printf (" Tag_GNU_Power_ABI_Vector: ");
16248 printf (_("<corrupt>\n"));
16251 READ_ULEB (val
, p
, end
);
16254 printf ("(%#x), ", val
);
16259 printf (_("unspecified\n"));
16262 printf (_("generic\n"));
16265 printf ("AltiVec\n");
16274 if (tag
== Tag_GNU_Power_ABI_Struct_Return
)
16276 printf (" Tag_GNU_Power_ABI_Struct_Return: ");
16279 printf (_("<corrupt>\n"));
16282 READ_ULEB (val
, p
, end
);
16285 printf ("(%#x), ", val
);
16290 printf (_("unspecified\n"));
16293 printf ("r3/r4\n");
16296 printf (_("memory\n"));
16305 return display_tag_value (tag
& 1, p
, end
);
16308 static unsigned char *
16309 display_s390_gnu_attribute (unsigned char * p
,
16311 const unsigned char * const end
)
16315 if (tag
== Tag_GNU_S390_ABI_Vector
)
16317 printf (" Tag_GNU_S390_ABI_Vector: ");
16318 READ_ULEB (val
, p
, end
);
16323 printf (_("any\n"));
16326 printf (_("software\n"));
16329 printf (_("hardware\n"));
16332 printf ("??? (%d)\n", val
);
16338 return display_tag_value (tag
& 1, p
, end
);
16342 display_sparc_hwcaps (unsigned int mask
)
16348 if (mask
& ELF_SPARC_HWCAP_MUL32
)
16349 fputs ("mul32", stdout
), first
= false;
16350 if (mask
& ELF_SPARC_HWCAP_DIV32
)
16351 printf ("%sdiv32", first
? "" : "|"), first
= false;
16352 if (mask
& ELF_SPARC_HWCAP_FSMULD
)
16353 printf ("%sfsmuld", first
? "" : "|"), first
= false;
16354 if (mask
& ELF_SPARC_HWCAP_V8PLUS
)
16355 printf ("%sv8plus", first
? "" : "|"), first
= false;
16356 if (mask
& ELF_SPARC_HWCAP_POPC
)
16357 printf ("%spopc", first
? "" : "|"), first
= false;
16358 if (mask
& ELF_SPARC_HWCAP_VIS
)
16359 printf ("%svis", first
? "" : "|"), first
= false;
16360 if (mask
& ELF_SPARC_HWCAP_VIS2
)
16361 printf ("%svis2", first
? "" : "|"), first
= false;
16362 if (mask
& ELF_SPARC_HWCAP_ASI_BLK_INIT
)
16363 printf ("%sASIBlkInit", first
? "" : "|"), first
= false;
16364 if (mask
& ELF_SPARC_HWCAP_FMAF
)
16365 printf ("%sfmaf", first
? "" : "|"), first
= false;
16366 if (mask
& ELF_SPARC_HWCAP_VIS3
)
16367 printf ("%svis3", first
? "" : "|"), first
= false;
16368 if (mask
& ELF_SPARC_HWCAP_HPC
)
16369 printf ("%shpc", first
? "" : "|"), first
= false;
16370 if (mask
& ELF_SPARC_HWCAP_RANDOM
)
16371 printf ("%srandom", first
? "" : "|"), first
= false;
16372 if (mask
& ELF_SPARC_HWCAP_TRANS
)
16373 printf ("%strans", first
? "" : "|"), first
= false;
16374 if (mask
& ELF_SPARC_HWCAP_FJFMAU
)
16375 printf ("%sfjfmau", first
? "" : "|"), first
= false;
16376 if (mask
& ELF_SPARC_HWCAP_IMA
)
16377 printf ("%sima", first
? "" : "|"), first
= false;
16378 if (mask
& ELF_SPARC_HWCAP_ASI_CACHE_SPARING
)
16379 printf ("%scspare", first
? "" : "|"), first
= false;
16382 fputc ('0', stdout
);
16383 fputc ('\n', stdout
);
16387 display_sparc_hwcaps2 (unsigned int mask
)
16393 if (mask
& ELF_SPARC_HWCAP2_FJATHPLUS
)
16394 fputs ("fjathplus", stdout
), first
= false;
16395 if (mask
& ELF_SPARC_HWCAP2_VIS3B
)
16396 printf ("%svis3b", first
? "" : "|"), first
= false;
16397 if (mask
& ELF_SPARC_HWCAP2_ADP
)
16398 printf ("%sadp", first
? "" : "|"), first
= false;
16399 if (mask
& ELF_SPARC_HWCAP2_SPARC5
)
16400 printf ("%ssparc5", first
? "" : "|"), first
= false;
16401 if (mask
& ELF_SPARC_HWCAP2_MWAIT
)
16402 printf ("%smwait", first
? "" : "|"), first
= false;
16403 if (mask
& ELF_SPARC_HWCAP2_XMPMUL
)
16404 printf ("%sxmpmul", first
? "" : "|"), first
= false;
16405 if (mask
& ELF_SPARC_HWCAP2_XMONT
)
16406 printf ("%sxmont2", first
? "" : "|"), first
= false;
16407 if (mask
& ELF_SPARC_HWCAP2_NSEC
)
16408 printf ("%snsec", first
? "" : "|"), first
= false;
16409 if (mask
& ELF_SPARC_HWCAP2_FJATHHPC
)
16410 printf ("%sfjathhpc", first
? "" : "|"), first
= false;
16411 if (mask
& ELF_SPARC_HWCAP2_FJDES
)
16412 printf ("%sfjdes", first
? "" : "|"), first
= false;
16413 if (mask
& ELF_SPARC_HWCAP2_FJAES
)
16414 printf ("%sfjaes", first
? "" : "|"), first
= false;
16417 fputc ('0', stdout
);
16418 fputc ('\n', stdout
);
16421 static unsigned char *
16422 display_sparc_gnu_attribute (unsigned char * p
,
16424 const unsigned char * const end
)
16428 if (tag
== Tag_GNU_Sparc_HWCAPS
)
16430 READ_ULEB (val
, p
, end
);
16431 printf (" Tag_GNU_Sparc_HWCAPS: ");
16432 display_sparc_hwcaps (val
);
16435 if (tag
== Tag_GNU_Sparc_HWCAPS2
)
16437 READ_ULEB (val
, p
, end
);
16438 printf (" Tag_GNU_Sparc_HWCAPS2: ");
16439 display_sparc_hwcaps2 (val
);
16443 return display_tag_value (tag
, p
, end
);
16447 print_mips_fp_abi_value (unsigned int val
)
16451 case Val_GNU_MIPS_ABI_FP_ANY
:
16452 printf (_("Hard or soft float\n"));
16454 case Val_GNU_MIPS_ABI_FP_DOUBLE
:
16455 printf (_("Hard float (double precision)\n"));
16457 case Val_GNU_MIPS_ABI_FP_SINGLE
:
16458 printf (_("Hard float (single precision)\n"));
16460 case Val_GNU_MIPS_ABI_FP_SOFT
:
16461 printf (_("Soft float\n"));
16463 case Val_GNU_MIPS_ABI_FP_OLD_64
:
16464 printf (_("Hard float (MIPS32r2 64-bit FPU 12 callee-saved)\n"));
16466 case Val_GNU_MIPS_ABI_FP_XX
:
16467 printf (_("Hard float (32-bit CPU, Any FPU)\n"));
16469 case Val_GNU_MIPS_ABI_FP_64
:
16470 printf (_("Hard float (32-bit CPU, 64-bit FPU)\n"));
16472 case Val_GNU_MIPS_ABI_FP_64A
:
16473 printf (_("Hard float compat (32-bit CPU, 64-bit FPU)\n"));
16475 case Val_GNU_MIPS_ABI_FP_NAN2008
:
16476 printf (_("NaN 2008 compatibility\n"));
16479 printf ("??? (%d)\n", val
);
16484 static unsigned char *
16485 display_mips_gnu_attribute (unsigned char * p
,
16487 const unsigned char * const end
)
16489 if (tag
== Tag_GNU_MIPS_ABI_FP
)
16493 printf (" Tag_GNU_MIPS_ABI_FP: ");
16494 READ_ULEB (val
, p
, end
);
16495 print_mips_fp_abi_value (val
);
16499 if (tag
== Tag_GNU_MIPS_ABI_MSA
)
16503 printf (" Tag_GNU_MIPS_ABI_MSA: ");
16504 READ_ULEB (val
, p
, end
);
16508 case Val_GNU_MIPS_ABI_MSA_ANY
:
16509 printf (_("Any MSA or not\n"));
16511 case Val_GNU_MIPS_ABI_MSA_128
:
16512 printf (_("128-bit MSA\n"));
16515 printf ("??? (%d)\n", val
);
16521 return display_tag_value (tag
& 1, p
, end
);
16524 static unsigned char *
16525 display_tic6x_attribute (unsigned char * p
,
16526 const unsigned char * const end
)
16531 READ_ULEB (tag
, p
, end
);
16536 printf (" Tag_ISA: ");
16537 READ_ULEB (val
, p
, end
);
16541 case C6XABI_Tag_ISA_none
:
16542 printf (_("None\n"));
16544 case C6XABI_Tag_ISA_C62X
:
16547 case C6XABI_Tag_ISA_C67X
:
16550 case C6XABI_Tag_ISA_C67XP
:
16551 printf ("C67x+\n");
16553 case C6XABI_Tag_ISA_C64X
:
16556 case C6XABI_Tag_ISA_C64XP
:
16557 printf ("C64x+\n");
16559 case C6XABI_Tag_ISA_C674X
:
16560 printf ("C674x\n");
16563 printf ("??? (%d)\n", val
);
16568 case Tag_ABI_wchar_t
:
16569 printf (" Tag_ABI_wchar_t: ");
16570 READ_ULEB (val
, p
, end
);
16574 printf (_("Not used\n"));
16577 printf (_("2 bytes\n"));
16580 printf (_("4 bytes\n"));
16583 printf ("??? (%d)\n", val
);
16588 case Tag_ABI_stack_align_needed
:
16589 printf (" Tag_ABI_stack_align_needed: ");
16590 READ_ULEB (val
, p
, end
);
16594 printf (_("8-byte\n"));
16597 printf (_("16-byte\n"));
16600 printf ("??? (%d)\n", val
);
16605 case Tag_ABI_stack_align_preserved
:
16606 READ_ULEB (val
, p
, end
);
16607 printf (" Tag_ABI_stack_align_preserved: ");
16611 printf (_("8-byte\n"));
16614 printf (_("16-byte\n"));
16617 printf ("??? (%d)\n", val
);
16623 READ_ULEB (val
, p
, end
);
16624 printf (" Tag_ABI_DSBT: ");
16628 printf (_("DSBT addressing not used\n"));
16631 printf (_("DSBT addressing used\n"));
16634 printf ("??? (%d)\n", val
);
16640 READ_ULEB (val
, p
, end
);
16641 printf (" Tag_ABI_PID: ");
16645 printf (_("Data addressing position-dependent\n"));
16648 printf (_("Data addressing position-independent, GOT near DP\n"));
16651 printf (_("Data addressing position-independent, GOT far from DP\n"));
16654 printf ("??? (%d)\n", val
);
16660 READ_ULEB (val
, p
, end
);
16661 printf (" Tag_ABI_PIC: ");
16665 printf (_("Code addressing position-dependent\n"));
16668 printf (_("Code addressing position-independent\n"));
16671 printf ("??? (%d)\n", val
);
16676 case Tag_ABI_array_object_alignment
:
16677 READ_ULEB (val
, p
, end
);
16678 printf (" Tag_ABI_array_object_alignment: ");
16682 printf (_("8-byte\n"));
16685 printf (_("4-byte\n"));
16688 printf (_("16-byte\n"));
16691 printf ("??? (%d)\n", val
);
16696 case Tag_ABI_array_object_align_expected
:
16697 READ_ULEB (val
, p
, end
);
16698 printf (" Tag_ABI_array_object_align_expected: ");
16702 printf (_("8-byte\n"));
16705 printf (_("4-byte\n"));
16708 printf (_("16-byte\n"));
16711 printf ("??? (%d)\n", val
);
16716 case Tag_ABI_compatibility
:
16718 READ_ULEB (val
, p
, end
);
16719 printf (" Tag_ABI_compatibility: ");
16720 printf (_("flag = %d, vendor = "), val
);
16723 size_t maxlen
= (end
- p
) - 1;
16725 print_symbol ((int) maxlen
, (const char *) p
);
16726 p
+= strnlen ((char *) p
, maxlen
) + 1;
16730 printf (_("<corrupt>"));
16731 p
= (unsigned char *) end
;
16737 case Tag_ABI_conformance
:
16739 printf (" Tag_ABI_conformance: \"");
16742 size_t maxlen
= (end
- p
) - 1;
16744 print_symbol ((int) maxlen
, (const char *) p
);
16745 p
+= strnlen ((char *) p
, maxlen
) + 1;
16749 printf (_("<corrupt>"));
16750 p
= (unsigned char *) end
;
16757 return display_tag_value (tag
, p
, end
);
16761 display_raw_attribute (unsigned char * p
, unsigned char const * const end
)
16763 unsigned long addr
= 0;
16764 size_t bytes
= end
- p
;
16771 int lbytes
= (bytes
> 16 ? 16 : bytes
);
16773 printf (" 0x%8.8lx ", addr
);
16775 for (j
= 0; j
< 16; j
++)
16778 printf ("%2.2x", p
[j
]);
16786 for (j
= 0; j
< lbytes
; j
++)
16789 if (k
>= ' ' && k
< 0x7f)
16805 static unsigned char *
16806 display_msp430_attribute (unsigned char * p
,
16807 const unsigned char * const end
)
16812 READ_ULEB (tag
, p
, end
);
16816 case OFBA_MSPABI_Tag_ISA
:
16817 printf (" Tag_ISA: ");
16818 READ_ULEB (val
, p
, end
);
16821 case 0: printf (_("None\n")); break;
16822 case 1: printf (_("MSP430\n")); break;
16823 case 2: printf (_("MSP430X\n")); break;
16824 default: printf ("??? (%d)\n", val
); break;
16828 case OFBA_MSPABI_Tag_Code_Model
:
16829 printf (" Tag_Code_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 default: printf ("??? (%d)\n", val
); break;
16840 case OFBA_MSPABI_Tag_Data_Model
:
16841 printf (" Tag_Data_Model: ");
16842 READ_ULEB (val
, p
, end
);
16845 case 0: printf (_("None\n")); break;
16846 case 1: printf (_("Small\n")); break;
16847 case 2: printf (_("Large\n")); break;
16848 case 3: printf (_("Restricted Large\n")); break;
16849 default: printf ("??? (%d)\n", val
); break;
16854 printf (_(" <unknown tag %d>: "), tag
);
16861 size_t maxlen
= (end
- p
) - 1;
16863 print_symbol ((int) maxlen
, (const char *) p
);
16864 p
+= strnlen ((char *) p
, maxlen
) + 1;
16868 printf (_("<corrupt>"));
16869 p
= (unsigned char *) end
;
16875 READ_ULEB (val
, p
, end
);
16876 printf ("%d (0x%x)\n", val
, val
);
16885 static unsigned char *
16886 display_msp430_gnu_attribute (unsigned char * p
,
16888 const unsigned char * const end
)
16890 if (tag
== Tag_GNU_MSP430_Data_Region
)
16894 printf (" Tag_GNU_MSP430_Data_Region: ");
16895 READ_ULEB (val
, p
, end
);
16899 case Val_GNU_MSP430_Data_Region_Any
:
16900 printf (_("Any Region\n"));
16902 case Val_GNU_MSP430_Data_Region_Lower
:
16903 printf (_("Lower Region Only\n"));
16906 printf ("??? (%u)\n", val
);
16910 return display_tag_value (tag
& 1, p
, end
);
16913 struct riscv_attr_tag_t
{
16918 static struct riscv_attr_tag_t riscv_attr_tag
[] =
16920 #define T(tag) {"Tag_RISCV_" #tag, Tag_RISCV_##tag}
16923 T(priv_spec_minor
),
16924 T(priv_spec_revision
),
16925 T(unaligned_access
),
16930 static unsigned char *
16931 display_riscv_attribute (unsigned char *p
,
16932 const unsigned char * const end
)
16936 struct riscv_attr_tag_t
*attr
= NULL
;
16939 READ_ULEB (tag
, p
, end
);
16941 /* Find the name of attribute. */
16942 for (i
= 0; i
< ARRAY_SIZE (riscv_attr_tag
); i
++)
16944 if (riscv_attr_tag
[i
].tag
== tag
)
16946 attr
= &riscv_attr_tag
[i
];
16952 printf (" %s: ", attr
->name
);
16954 return display_tag_value (tag
, p
, end
);
16958 case Tag_RISCV_priv_spec
:
16959 case Tag_RISCV_priv_spec_minor
:
16960 case Tag_RISCV_priv_spec_revision
:
16961 READ_ULEB (val
, p
, end
);
16962 printf (_("%u\n"), val
);
16964 case Tag_RISCV_unaligned_access
:
16965 READ_ULEB (val
, p
, end
);
16969 printf (_("No unaligned access\n"));
16972 printf (_("Unaligned access\n"));
16976 case Tag_RISCV_stack_align
:
16977 READ_ULEB (val
, p
, end
);
16978 printf (_("%u-bytes\n"), val
);
16980 case Tag_RISCV_arch
:
16981 p
= display_tag_value (-1, p
, end
);
16984 return display_tag_value (tag
, p
, end
);
16990 static unsigned char *
16991 display_csky_attribute (unsigned char * p
,
16992 const unsigned char * const end
)
16996 READ_ULEB (tag
, p
, end
);
16998 if (tag
>= Tag_CSKY_MAX
)
17000 return display_tag_value (-1, p
, end
);
17005 case Tag_CSKY_ARCH_NAME
:
17006 printf (" Tag_CSKY_ARCH_NAME:\t\t");
17007 return display_tag_value (-1, p
, end
);
17008 case Tag_CSKY_CPU_NAME
:
17009 printf (" Tag_CSKY_CPU_NAME:\t\t");
17010 return display_tag_value (-1, p
, end
);
17012 case Tag_CSKY_ISA_FLAGS
:
17013 printf (" Tag_CSKY_ISA_FLAGS:\t\t");
17014 return display_tag_value (0, p
, end
);
17015 case Tag_CSKY_ISA_EXT_FLAGS
:
17016 printf (" Tag_CSKY_ISA_EXT_FLAGS:\t");
17017 return display_tag_value (0, p
, end
);
17019 case Tag_CSKY_DSP_VERSION
:
17020 printf (" Tag_CSKY_DSP_VERSION:\t\t");
17021 READ_ULEB (val
, p
, end
);
17022 if (val
== VAL_CSKY_DSP_VERSION_EXTENSION
)
17023 printf ("DSP Extension\n");
17024 else if (val
== VAL_CSKY_DSP_VERSION_2
)
17025 printf ("DSP 2.0\n");
17028 case Tag_CSKY_VDSP_VERSION
:
17029 printf (" Tag_CSKY_VDSP_VERSION:\t");
17030 READ_ULEB (val
, p
, end
);
17031 printf ("VDSP Version %d\n", val
);
17034 case Tag_CSKY_FPU_VERSION
:
17035 printf (" Tag_CSKY_FPU_VERSION:\t\t");
17036 READ_ULEB (val
, p
, end
);
17037 if (val
== VAL_CSKY_FPU_VERSION_1
)
17038 printf ("ABIV1 FPU Version 1\n");
17039 else if (val
== VAL_CSKY_FPU_VERSION_2
)
17040 printf ("FPU Version 2\n");
17043 case Tag_CSKY_FPU_ABI
:
17044 printf (" Tag_CSKY_FPU_ABI:\t\t");
17045 READ_ULEB (val
, p
, end
);
17046 if (val
== VAL_CSKY_FPU_ABI_HARD
)
17048 else if (val
== VAL_CSKY_FPU_ABI_SOFTFP
)
17049 printf ("SoftFP\n");
17050 else if (val
== VAL_CSKY_FPU_ABI_SOFT
)
17053 case Tag_CSKY_FPU_ROUNDING
:
17054 READ_ULEB (val
, p
, end
);
17056 printf (" Tag_CSKY_FPU_ROUNDING:\t");
17057 printf ("Needed\n");
17060 case Tag_CSKY_FPU_DENORMAL
:
17061 READ_ULEB (val
, p
, end
);
17063 printf (" Tag_CSKY_FPU_DENORMAL:\t");
17064 printf ("Needed\n");
17067 case Tag_CSKY_FPU_Exception
:
17068 READ_ULEB (val
, p
, end
);
17070 printf (" Tag_CSKY_FPU_Exception:\t");
17071 printf ("Needed\n");
17074 case Tag_CSKY_FPU_NUMBER_MODULE
:
17075 printf (" Tag_CSKY_FPU_NUMBER_MODULE:\t");
17076 return display_tag_value (-1, p
, end
);
17077 case Tag_CSKY_FPU_HARDFP
:
17078 printf (" Tag_CSKY_FPU_HARDFP:\t\t");
17079 READ_ULEB (val
, p
, end
);
17080 if (val
& VAL_CSKY_FPU_HARDFP_HALF
)
17082 if (val
& VAL_CSKY_FPU_HARDFP_SINGLE
)
17083 printf (" Single");
17084 if (val
& VAL_CSKY_FPU_HARDFP_DOUBLE
)
17085 printf (" Double");
17089 return display_tag_value (tag
, p
, end
);
17095 process_attributes (Filedata
* filedata
,
17096 const char * public_name
,
17097 unsigned int proc_type
,
17098 unsigned char * (* display_pub_attribute
) (unsigned char *, const unsigned char * const),
17099 unsigned char * (* display_proc_gnu_attribute
) (unsigned char *, unsigned int, const unsigned char * const))
17101 Elf_Internal_Shdr
* sect
;
17105 /* Find the section header so that we get the size. */
17106 for (i
= 0, sect
= filedata
->section_headers
;
17107 i
< filedata
->file_header
.e_shnum
;
17110 unsigned char * contents
;
17113 if (sect
->sh_type
!= proc_type
&& sect
->sh_type
!= SHT_GNU_ATTRIBUTES
)
17116 contents
= (unsigned char *) get_data (NULL
, filedata
, sect
->sh_offset
, 1,
17117 sect
->sh_size
, _("attributes"));
17118 if (contents
== NULL
)
17125 /* The first character is the version of the attributes.
17126 Currently only version 1, (aka 'A') is recognised here. */
17129 printf (_("Unknown attributes version '%c'(%d) - expecting 'A'\n"), *p
, *p
);
17134 bfd_vma section_len
;
17136 section_len
= sect
->sh_size
- 1;
17139 while (section_len
> 0)
17142 unsigned int namelen
;
17143 bool public_section
;
17146 if (section_len
<= 4)
17148 error (_("Tag section ends prematurely\n"));
17152 attr_len
= byte_get (p
, 4);
17155 if (attr_len
> section_len
)
17157 error (_("Bad attribute length (%u > %u)\n"),
17158 (unsigned) attr_len
, (unsigned) section_len
);
17159 attr_len
= section_len
;
17162 /* PR 17531: file: 001-101425-0.004 */
17163 else if (attr_len
< 5)
17165 error (_("Attribute length of %u is too small\n"), (unsigned) attr_len
);
17170 section_len
-= attr_len
;
17173 namelen
= strnlen ((char *) p
, attr_len
) + 1;
17174 if (namelen
== 0 || namelen
>= attr_len
)
17176 error (_("Corrupt attribute section name\n"));
17181 printf (_("Attribute Section: "));
17182 print_symbol (INT_MAX
, (const char *) p
);
17185 if (public_name
&& streq ((char *) p
, public_name
))
17186 public_section
= true;
17188 public_section
= false;
17190 if (streq ((char *) p
, "gnu"))
17191 gnu_section
= true;
17193 gnu_section
= false;
17196 attr_len
-= namelen
;
17198 while (attr_len
> 0 && p
< contents
+ sect
->sh_size
)
17203 unsigned char * end
;
17205 /* PR binutils/17531: Safe handling of corrupt files. */
17208 error (_("Unused bytes at end of section\n"));
17215 size
= byte_get (p
, 4);
17216 if (size
> attr_len
)
17218 error (_("Bad subsection length (%u > %u)\n"),
17219 (unsigned) size
, (unsigned) attr_len
);
17223 /* PR binutils/17531: Safe handling of corrupt files. */
17226 error (_("Bad subsection length (%u < 6)\n"),
17234 end
= p
+ size
- 1;
17235 assert (end
<= contents
+ sect
->sh_size
);
17241 printf (_("File Attributes\n"));
17244 printf (_("Section Attributes:"));
17247 printf (_("Symbol Attributes:"));
17248 /* Fall through. */
17252 READ_ULEB (val
, p
, end
);
17255 printf (" %d", val
);
17260 printf (_("Unknown tag: %d\n"), tag
);
17261 public_section
= false;
17265 if (public_section
&& display_pub_attribute
!= NULL
)
17268 p
= display_pub_attribute (p
, end
);
17271 else if (gnu_section
&& display_proc_gnu_attribute
!= NULL
)
17274 p
= display_gnu_attribute (p
,
17275 display_proc_gnu_attribute
,
17281 printf (_(" Unknown attribute:\n"));
17282 display_raw_attribute (p
, end
);
17297 /* DATA points to the contents of a MIPS GOT that starts at VMA PLTGOT.
17298 Print the Address, Access and Initial fields of an entry at VMA ADDR
17299 and return the VMA of the next entry, or -1 if there was a problem.
17300 Does not read from DATA_END or beyond. */
17303 print_mips_got_entry (unsigned char * data
, bfd_vma pltgot
, bfd_vma addr
,
17304 unsigned char * data_end
)
17307 print_vma (addr
, LONG_HEX
);
17309 if (addr
< pltgot
+ 0xfff0)
17310 printf ("%6d(gp)", (int) (addr
- pltgot
- 0x7ff0));
17312 printf ("%10s", "");
17315 printf ("%*s", is_32bit_elf
? 8 : 16, _("<unknown>"));
17319 unsigned char * from
= data
+ addr
- pltgot
;
17321 if (from
+ (is_32bit_elf
? 4 : 8) > data_end
)
17323 warn (_("MIPS GOT entry extends beyond the end of available data\n"));
17324 printf ("%*s", is_32bit_elf
? 8 : 16, _("<corrupt>"));
17325 return (bfd_vma
) -1;
17329 entry
= byte_get (data
+ addr
- pltgot
, is_32bit_elf
? 4 : 8);
17330 print_vma (entry
, LONG_HEX
);
17333 return addr
+ (is_32bit_elf
? 4 : 8);
17336 /* DATA points to the contents of a MIPS PLT GOT that starts at VMA
17337 PLTGOT. Print the Address and Initial fields of an entry at VMA
17338 ADDR and return the VMA of the next entry. */
17341 print_mips_pltgot_entry (unsigned char * data
, bfd_vma pltgot
, bfd_vma addr
)
17344 print_vma (addr
, LONG_HEX
);
17347 printf ("%*s", is_32bit_elf
? 8 : 16, _("<unknown>"));
17352 entry
= byte_get (data
+ addr
- pltgot
, is_32bit_elf
? 4 : 8);
17353 print_vma (entry
, LONG_HEX
);
17355 return addr
+ (is_32bit_elf
? 4 : 8);
17359 print_mips_ases (unsigned int mask
)
17361 if (mask
& AFL_ASE_DSP
)
17362 fputs ("\n\tDSP ASE", stdout
);
17363 if (mask
& AFL_ASE_DSPR2
)
17364 fputs ("\n\tDSP R2 ASE", stdout
);
17365 if (mask
& AFL_ASE_DSPR3
)
17366 fputs ("\n\tDSP R3 ASE", stdout
);
17367 if (mask
& AFL_ASE_EVA
)
17368 fputs ("\n\tEnhanced VA Scheme", stdout
);
17369 if (mask
& AFL_ASE_MCU
)
17370 fputs ("\n\tMCU (MicroController) ASE", stdout
);
17371 if (mask
& AFL_ASE_MDMX
)
17372 fputs ("\n\tMDMX ASE", stdout
);
17373 if (mask
& AFL_ASE_MIPS3D
)
17374 fputs ("\n\tMIPS-3D ASE", stdout
);
17375 if (mask
& AFL_ASE_MT
)
17376 fputs ("\n\tMT ASE", stdout
);
17377 if (mask
& AFL_ASE_SMARTMIPS
)
17378 fputs ("\n\tSmartMIPS ASE", stdout
);
17379 if (mask
& AFL_ASE_VIRT
)
17380 fputs ("\n\tVZ ASE", stdout
);
17381 if (mask
& AFL_ASE_MSA
)
17382 fputs ("\n\tMSA ASE", stdout
);
17383 if (mask
& AFL_ASE_MIPS16
)
17384 fputs ("\n\tMIPS16 ASE", stdout
);
17385 if (mask
& AFL_ASE_MICROMIPS
)
17386 fputs ("\n\tMICROMIPS ASE", stdout
);
17387 if (mask
& AFL_ASE_XPA
)
17388 fputs ("\n\tXPA ASE", stdout
);
17389 if (mask
& AFL_ASE_MIPS16E2
)
17390 fputs ("\n\tMIPS16e2 ASE", stdout
);
17391 if (mask
& AFL_ASE_CRC
)
17392 fputs ("\n\tCRC ASE", stdout
);
17393 if (mask
& AFL_ASE_GINV
)
17394 fputs ("\n\tGINV ASE", stdout
);
17395 if (mask
& AFL_ASE_LOONGSON_MMI
)
17396 fputs ("\n\tLoongson MMI ASE", stdout
);
17397 if (mask
& AFL_ASE_LOONGSON_CAM
)
17398 fputs ("\n\tLoongson CAM ASE", stdout
);
17399 if (mask
& AFL_ASE_LOONGSON_EXT
)
17400 fputs ("\n\tLoongson EXT ASE", stdout
);
17401 if (mask
& AFL_ASE_LOONGSON_EXT2
)
17402 fputs ("\n\tLoongson EXT2 ASE", stdout
);
17404 fprintf (stdout
, "\n\t%s", _("None"));
17405 else if ((mask
& ~AFL_ASE_MASK
) != 0)
17406 fprintf (stdout
, "\n\t%s (%x)", _("Unknown"), mask
& ~AFL_ASE_MASK
);
17410 print_mips_isa_ext (unsigned int isa_ext
)
17415 fputs (_("None"), stdout
);
17418 fputs ("RMI XLR", stdout
);
17420 case AFL_EXT_OCTEON3
:
17421 fputs ("Cavium Networks Octeon3", stdout
);
17423 case AFL_EXT_OCTEON2
:
17424 fputs ("Cavium Networks Octeon2", stdout
);
17426 case AFL_EXT_OCTEONP
:
17427 fputs ("Cavium Networks OcteonP", stdout
);
17429 case AFL_EXT_OCTEON
:
17430 fputs ("Cavium Networks Octeon", stdout
);
17433 fputs ("Toshiba R5900", stdout
);
17436 fputs ("MIPS R4650", stdout
);
17439 fputs ("LSI R4010", stdout
);
17442 fputs ("NEC VR4100", stdout
);
17445 fputs ("Toshiba R3900", stdout
);
17447 case AFL_EXT_10000
:
17448 fputs ("MIPS R10000", stdout
);
17451 fputs ("Broadcom SB-1", stdout
);
17454 fputs ("NEC VR4111/VR4181", stdout
);
17457 fputs ("NEC VR4120", stdout
);
17460 fputs ("NEC VR5400", stdout
);
17463 fputs ("NEC VR5500", stdout
);
17465 case AFL_EXT_LOONGSON_2E
:
17466 fputs ("ST Microelectronics Loongson 2E", stdout
);
17468 case AFL_EXT_LOONGSON_2F
:
17469 fputs ("ST Microelectronics Loongson 2F", stdout
);
17471 case AFL_EXT_INTERAPTIV_MR2
:
17472 fputs ("Imagination interAptiv MR2", stdout
);
17475 fprintf (stdout
, "%s (%d)", _("Unknown"), isa_ext
);
17480 get_mips_reg_size (int reg_size
)
17482 return (reg_size
== AFL_REG_NONE
) ? 0
17483 : (reg_size
== AFL_REG_32
) ? 32
17484 : (reg_size
== AFL_REG_64
) ? 64
17485 : (reg_size
== AFL_REG_128
) ? 128
17490 process_mips_specific (Filedata
* filedata
)
17492 Elf_Internal_Dyn
* entry
;
17493 Elf_Internal_Shdr
*sect
= NULL
;
17494 size_t liblist_offset
= 0;
17495 size_t liblistno
= 0;
17496 size_t conflictsno
= 0;
17497 size_t options_offset
= 0;
17498 size_t conflicts_offset
= 0;
17499 size_t pltrelsz
= 0;
17501 bfd_vma pltgot
= 0;
17502 bfd_vma mips_pltgot
= 0;
17503 bfd_vma jmprel
= 0;
17504 bfd_vma local_gotno
= 0;
17505 bfd_vma gotsym
= 0;
17506 bfd_vma symtabno
= 0;
17509 if (! process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
17510 display_mips_gnu_attribute
))
17513 sect
= find_section (filedata
, ".MIPS.abiflags");
17517 Elf_External_ABIFlags_v0
*abiflags_ext
;
17518 Elf_Internal_ABIFlags_v0 abiflags_in
;
17520 if (sizeof (Elf_External_ABIFlags_v0
) != sect
->sh_size
)
17522 error (_("Corrupt MIPS ABI Flags section.\n"));
17527 abiflags_ext
= get_data (NULL
, filedata
, sect
->sh_offset
, 1,
17528 sect
->sh_size
, _("MIPS ABI Flags section"));
17531 abiflags_in
.version
= BYTE_GET (abiflags_ext
->version
);
17532 abiflags_in
.isa_level
= BYTE_GET (abiflags_ext
->isa_level
);
17533 abiflags_in
.isa_rev
= BYTE_GET (abiflags_ext
->isa_rev
);
17534 abiflags_in
.gpr_size
= BYTE_GET (abiflags_ext
->gpr_size
);
17535 abiflags_in
.cpr1_size
= BYTE_GET (abiflags_ext
->cpr1_size
);
17536 abiflags_in
.cpr2_size
= BYTE_GET (abiflags_ext
->cpr2_size
);
17537 abiflags_in
.fp_abi
= BYTE_GET (abiflags_ext
->fp_abi
);
17538 abiflags_in
.isa_ext
= BYTE_GET (abiflags_ext
->isa_ext
);
17539 abiflags_in
.ases
= BYTE_GET (abiflags_ext
->ases
);
17540 abiflags_in
.flags1
= BYTE_GET (abiflags_ext
->flags1
);
17541 abiflags_in
.flags2
= BYTE_GET (abiflags_ext
->flags2
);
17543 printf ("\nMIPS ABI Flags Version: %d\n", abiflags_in
.version
);
17544 printf ("\nISA: MIPS%d", abiflags_in
.isa_level
);
17545 if (abiflags_in
.isa_rev
> 1)
17546 printf ("r%d", abiflags_in
.isa_rev
);
17547 printf ("\nGPR size: %d",
17548 get_mips_reg_size (abiflags_in
.gpr_size
));
17549 printf ("\nCPR1 size: %d",
17550 get_mips_reg_size (abiflags_in
.cpr1_size
));
17551 printf ("\nCPR2 size: %d",
17552 get_mips_reg_size (abiflags_in
.cpr2_size
));
17553 fputs ("\nFP ABI: ", stdout
);
17554 print_mips_fp_abi_value (abiflags_in
.fp_abi
);
17555 fputs ("ISA Extension: ", stdout
);
17556 print_mips_isa_ext (abiflags_in
.isa_ext
);
17557 fputs ("\nASEs:", stdout
);
17558 print_mips_ases (abiflags_in
.ases
);
17559 printf ("\nFLAGS 1: %8.8lx", abiflags_in
.flags1
);
17560 printf ("\nFLAGS 2: %8.8lx", abiflags_in
.flags2
);
17561 fputc ('\n', stdout
);
17562 free (abiflags_ext
);
17567 /* We have a lot of special sections. Thanks SGI! */
17568 if (filedata
->dynamic_section
== NULL
)
17570 /* No dynamic information available. See if there is static GOT. */
17571 sect
= find_section (filedata
, ".got");
17574 unsigned char *data_end
;
17575 unsigned char *data
;
17579 pltgot
= sect
->sh_addr
;
17582 addr_size
= (is_32bit_elf
? 4 : 8);
17583 end
= pltgot
+ sect
->sh_size
;
17585 data
= (unsigned char *) get_data (NULL
, filedata
, sect
->sh_offset
,
17587 _("Global Offset Table data"));
17588 /* PR 12855: Null data is handled gracefully throughout. */
17589 data_end
= data
+ (end
- pltgot
);
17591 printf (_("\nStatic GOT:\n"));
17592 printf (_(" Canonical gp value: "));
17593 print_vma (ent
+ 0x7ff0, LONG_HEX
);
17596 /* In a dynamic binary GOT[0] is reserved for the dynamic
17597 loader to store the lazy resolver pointer, however in
17598 a static binary it may well have been omitted and GOT
17599 reduced to a table of addresses.
17600 PR 21344: Check for the entry being fully available
17601 before fetching it. */
17603 && data
+ ent
- pltgot
+ addr_size
<= data_end
17604 && byte_get (data
+ ent
- pltgot
, addr_size
) == 0)
17606 printf (_(" Reserved entries:\n"));
17607 printf (_(" %*s %10s %*s\n"),
17608 addr_size
* 2, _("Address"), _("Access"),
17609 addr_size
* 2, _("Value"));
17610 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
17612 if (ent
== (bfd_vma
) -1)
17613 goto sgot_print_fail
;
17615 /* Check for the MSB of GOT[1] being set, identifying a
17616 GNU object. This entry will be used by some runtime
17617 loaders, to store the module pointer. Otherwise this
17618 is an ordinary local entry.
17619 PR 21344: Check for the entry being fully available
17620 before fetching it. */
17622 && data
+ ent
- pltgot
+ addr_size
<= data_end
17623 && (byte_get (data
+ ent
- pltgot
, addr_size
)
17624 >> (addr_size
* 8 - 1)) != 0)
17626 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
17628 if (ent
== (bfd_vma
) -1)
17629 goto sgot_print_fail
;
17634 if (data
!= NULL
&& ent
< end
)
17636 printf (_(" Local entries:\n"));
17637 printf (" %*s %10s %*s\n",
17638 addr_size
* 2, _("Address"), _("Access"),
17639 addr_size
* 2, _("Value"));
17642 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
17644 if (ent
== (bfd_vma
) -1)
17645 goto sgot_print_fail
;
17656 for (entry
= filedata
->dynamic_section
;
17657 /* PR 17531 file: 012-50589-0.004. */
17658 (entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
17659 && entry
->d_tag
!= DT_NULL
);
17661 switch (entry
->d_tag
)
17663 case DT_MIPS_LIBLIST
:
17665 = offset_from_vma (filedata
, entry
->d_un
.d_val
,
17666 liblistno
* sizeof (Elf32_External_Lib
));
17668 case DT_MIPS_LIBLISTNO
:
17669 liblistno
= entry
->d_un
.d_val
;
17671 case DT_MIPS_OPTIONS
:
17672 options_offset
= offset_from_vma (filedata
, entry
->d_un
.d_val
, 0);
17674 case DT_MIPS_CONFLICT
:
17676 = offset_from_vma (filedata
, entry
->d_un
.d_val
,
17677 conflictsno
* sizeof (Elf32_External_Conflict
));
17679 case DT_MIPS_CONFLICTNO
:
17680 conflictsno
= entry
->d_un
.d_val
;
17683 pltgot
= entry
->d_un
.d_ptr
;
17685 case DT_MIPS_LOCAL_GOTNO
:
17686 local_gotno
= entry
->d_un
.d_val
;
17688 case DT_MIPS_GOTSYM
:
17689 gotsym
= entry
->d_un
.d_val
;
17691 case DT_MIPS_SYMTABNO
:
17692 symtabno
= entry
->d_un
.d_val
;
17694 case DT_MIPS_PLTGOT
:
17695 mips_pltgot
= entry
->d_un
.d_ptr
;
17698 pltrel
= entry
->d_un
.d_val
;
17701 pltrelsz
= entry
->d_un
.d_val
;
17704 jmprel
= entry
->d_un
.d_ptr
;
17710 if (liblist_offset
!= 0 && liblistno
!= 0 && do_dynamic
)
17712 Elf32_External_Lib
* elib
;
17715 elib
= (Elf32_External_Lib
*) get_data (NULL
, filedata
, liblist_offset
,
17716 sizeof (Elf32_External_Lib
),
17718 _("liblist section data"));
17721 printf (ngettext ("\nSection '.liblist' contains %lu entry:\n",
17722 "\nSection '.liblist' contains %lu entries:\n",
17723 (unsigned long) liblistno
),
17724 (unsigned long) liblistno
);
17725 fputs (_(" Library Time Stamp Checksum Version Flags\n"),
17728 for (cnt
= 0; cnt
< liblistno
; ++cnt
)
17735 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
17736 atime
= BYTE_GET (elib
[cnt
].l_time_stamp
);
17737 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
17738 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
17739 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
17741 tmp
= gmtime (&atime
);
17742 snprintf (timebuf
, sizeof (timebuf
),
17743 "%04u-%02u-%02uT%02u:%02u:%02u",
17744 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
17745 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
17747 printf ("%3lu: ", (unsigned long) cnt
);
17748 if (VALID_DYNAMIC_NAME (filedata
, liblist
.l_name
))
17749 print_symbol (20, GET_DYNAMIC_NAME (filedata
, liblist
.l_name
));
17751 printf (_("<corrupt: %9ld>"), liblist
.l_name
);
17752 printf (" %s %#10lx %-7ld", timebuf
, liblist
.l_checksum
,
17753 liblist
.l_version
);
17755 if (liblist
.l_flags
== 0)
17759 static const struct
17766 { " EXACT_MATCH", LL_EXACT_MATCH
},
17767 { " IGNORE_INT_VER", LL_IGNORE_INT_VER
},
17768 { " REQUIRE_MINOR", LL_REQUIRE_MINOR
},
17769 { " EXPORTS", LL_EXPORTS
},
17770 { " DELAY_LOAD", LL_DELAY_LOAD
},
17771 { " DELTA", LL_DELTA
}
17773 int flags
= liblist
.l_flags
;
17776 for (fcnt
= 0; fcnt
< ARRAY_SIZE (l_flags_vals
); ++fcnt
)
17777 if ((flags
& l_flags_vals
[fcnt
].bit
) != 0)
17779 fputs (l_flags_vals
[fcnt
].name
, stdout
);
17780 flags
^= l_flags_vals
[fcnt
].bit
;
17783 printf (" %#x", (unsigned int) flags
);
17795 if (options_offset
!= 0)
17797 Elf_External_Options
* eopt
;
17800 sect
= filedata
->section_headers
;
17802 /* Find the section header so that we get the size. */
17803 sect
= find_section_by_type (filedata
, SHT_MIPS_OPTIONS
);
17804 /* PR 17533 file: 012-277276-0.004. */
17807 error (_("No MIPS_OPTIONS header found\n"));
17811 if (sect
->sh_size
< sizeof (* eopt
))
17813 error (_("The MIPS options section is too small.\n"));
17817 eopt
= (Elf_External_Options
*) get_data (NULL
, filedata
, options_offset
, 1,
17818 sect
->sh_size
, _("options"));
17821 Elf_Internal_Options option
;
17824 while (offset
<= sect
->sh_size
- sizeof (* eopt
))
17826 Elf_External_Options
* eoption
;
17827 unsigned int optsize
;
17829 eoption
= (Elf_External_Options
*) ((char *) eopt
+ offset
);
17831 optsize
= BYTE_GET (eoption
->size
);
17833 /* PR 17531: file: ffa0fa3b. */
17834 if (optsize
< sizeof (* eopt
)
17835 || optsize
> sect
->sh_size
- offset
)
17837 error (_("Invalid size (%u) for MIPS option\n"),
17846 printf (ngettext ("\nSection '%s' contains %d entry:\n",
17847 "\nSection '%s' contains %d entries:\n",
17849 printable_section_name (filedata
, sect
), cnt
);
17855 Elf_External_Options
* eoption
;
17857 eoption
= (Elf_External_Options
*) ((char *) eopt
+ offset
);
17859 option
.kind
= BYTE_GET (eoption
->kind
);
17860 option
.size
= BYTE_GET (eoption
->size
);
17861 option
.section
= BYTE_GET (eoption
->section
);
17862 option
.info
= BYTE_GET (eoption
->info
);
17864 switch (option
.kind
)
17867 /* This shouldn't happen. */
17868 printf (" NULL %" PRId16
" %" PRIx32
,
17869 option
.section
, option
.info
);
17873 printf (" REGINFO ");
17874 if (filedata
->file_header
.e_machine
== EM_MIPS
)
17876 Elf32_External_RegInfo
* ereg
;
17877 Elf32_RegInfo reginfo
;
17880 if (option
.size
< (sizeof (Elf_External_Options
)
17881 + sizeof (Elf32_External_RegInfo
)))
17883 printf (_("<corrupt>\n"));
17884 error (_("Truncated MIPS REGINFO option\n"));
17889 ereg
= (Elf32_External_RegInfo
*) (eoption
+ 1);
17891 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
17892 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
17893 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
17894 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
17895 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
17896 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
17898 printf ("GPR %08" PRIx32
" GP 0x%" PRIx32
"\n",
17899 reginfo
.ri_gprmask
, reginfo
.ri_gp_value
);
17901 " CPR0 %08" PRIx32
" CPR1 %08" PRIx32
17902 " CPR2 %08" PRIx32
" CPR3 %08" PRIx32
"\n",
17903 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
17904 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
17909 Elf64_External_RegInfo
* ereg
;
17910 Elf64_Internal_RegInfo reginfo
;
17912 if (option
.size
< (sizeof (Elf_External_Options
)
17913 + sizeof (Elf64_External_RegInfo
)))
17915 printf (_("<corrupt>\n"));
17916 error (_("Truncated MIPS REGINFO option\n"));
17921 ereg
= (Elf64_External_RegInfo
*) (eoption
+ 1);
17922 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
17923 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
17924 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
17925 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
17926 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
17927 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
17929 printf ("GPR %08" PRIx32
" GP 0x%" PRIx64
"\n",
17930 reginfo
.ri_gprmask
, reginfo
.ri_gp_value
);
17932 " CPR0 %08" PRIx32
" CPR1 %08" PRIx32
17933 " CPR2 %08" PRIx32
" CPR3 %08" PRIx32
"\n",
17934 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
17935 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
17937 offset
+= option
.size
;
17940 case ODK_EXCEPTIONS
:
17941 fputs (" EXCEPTIONS fpe_min(", stdout
);
17942 process_mips_fpe_exception (option
.info
& OEX_FPU_MIN
);
17943 fputs (") fpe_max(", stdout
);
17944 process_mips_fpe_exception ((option
.info
& OEX_FPU_MAX
) >> 8);
17945 fputs (")", stdout
);
17947 if (option
.info
& OEX_PAGE0
)
17948 fputs (" PAGE0", stdout
);
17949 if (option
.info
& OEX_SMM
)
17950 fputs (" SMM", stdout
);
17951 if (option
.info
& OEX_FPDBUG
)
17952 fputs (" FPDBUG", stdout
);
17953 if (option
.info
& OEX_DISMISS
)
17954 fputs (" DISMISS", stdout
);
17958 fputs (" PAD ", stdout
);
17959 if (option
.info
& OPAD_PREFIX
)
17960 fputs (" PREFIX", stdout
);
17961 if (option
.info
& OPAD_POSTFIX
)
17962 fputs (" POSTFIX", stdout
);
17963 if (option
.info
& OPAD_SYMBOL
)
17964 fputs (" SYMBOL", stdout
);
17968 fputs (" HWPATCH ", stdout
);
17969 if (option
.info
& OHW_R4KEOP
)
17970 fputs (" R4KEOP", stdout
);
17971 if (option
.info
& OHW_R8KPFETCH
)
17972 fputs (" R8KPFETCH", stdout
);
17973 if (option
.info
& OHW_R5KEOP
)
17974 fputs (" R5KEOP", stdout
);
17975 if (option
.info
& OHW_R5KCVTL
)
17976 fputs (" R5KCVTL", stdout
);
17980 fputs (" FILL ", stdout
);
17981 /* XXX Print content of info word? */
17985 fputs (" TAGS ", stdout
);
17986 /* XXX Print content of info word? */
17990 fputs (" HWAND ", stdout
);
17991 if (option
.info
& OHWA0_R4KEOP_CHECKED
)
17992 fputs (" R4KEOP_CHECKED", stdout
);
17993 if (option
.info
& OHWA0_R4KEOP_CLEAN
)
17994 fputs (" R4KEOP_CLEAN", stdout
);
17998 fputs (" HWOR ", stdout
);
17999 if (option
.info
& OHWA0_R4KEOP_CHECKED
)
18000 fputs (" R4KEOP_CHECKED", stdout
);
18001 if (option
.info
& OHWA0_R4KEOP_CLEAN
)
18002 fputs (" R4KEOP_CLEAN", stdout
);
18006 printf (" GP_GROUP %#06x self-contained %#06x",
18007 option
.info
& OGP_GROUP
,
18008 (option
.info
& OGP_SELF
) >> 16);
18012 printf (" IDENT %#06x self-contained %#06x",
18013 option
.info
& OGP_GROUP
,
18014 (option
.info
& OGP_SELF
) >> 16);
18018 /* This shouldn't happen. */
18019 printf (" %3d ??? %" PRId16
" %" PRIx32
,
18020 option
.kind
, option
.section
, option
.info
);
18024 len
= sizeof (* eopt
);
18025 while (len
< option
.size
)
18027 unsigned char datum
= *((unsigned char *) eoption
+ len
);
18029 if (ISPRINT (datum
))
18030 printf ("%c", datum
);
18032 printf ("\\%03o", datum
);
18035 fputs ("\n", stdout
);
18037 offset
+= option
.size
;
18045 if (conflicts_offset
!= 0 && conflictsno
!= 0)
18047 Elf32_Conflict
* iconf
;
18050 if (filedata
->dynamic_symbols
== NULL
)
18052 error (_("conflict list found without a dynamic symbol table\n"));
18056 /* PR 21345 - print a slightly more helpful error message
18057 if we are sure that the cmalloc will fail. */
18058 if (conflictsno
> filedata
->file_size
/ sizeof (* iconf
))
18060 error (_("Overlarge number of conflicts detected: %lx\n"),
18061 (long) conflictsno
);
18065 iconf
= (Elf32_Conflict
*) cmalloc (conflictsno
, sizeof (* iconf
));
18068 error (_("Out of memory allocating space for dynamic conflicts\n"));
18074 Elf32_External_Conflict
* econf32
;
18076 econf32
= (Elf32_External_Conflict
*)
18077 get_data (NULL
, filedata
, conflicts_offset
,
18078 sizeof (*econf32
), conflictsno
, _("conflict"));
18085 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
18086 iconf
[cnt
] = BYTE_GET (econf32
[cnt
]);
18092 Elf64_External_Conflict
* econf64
;
18094 econf64
= (Elf64_External_Conflict
*)
18095 get_data (NULL
, filedata
, conflicts_offset
,
18096 sizeof (*econf64
), conflictsno
, _("conflict"));
18103 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
18104 iconf
[cnt
] = BYTE_GET (econf64
[cnt
]);
18109 printf (ngettext ("\nSection '.conflict' contains %lu entry:\n",
18110 "\nSection '.conflict' contains %lu entries:\n",
18111 (unsigned long) conflictsno
),
18112 (unsigned long) conflictsno
);
18113 puts (_(" Num: Index Value Name"));
18115 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
18117 printf ("%5lu: %8lu ", (unsigned long) cnt
, iconf
[cnt
]);
18119 if (iconf
[cnt
] >= filedata
->num_dynamic_syms
)
18120 printf (_("<corrupt symbol index>"));
18123 Elf_Internal_Sym
* psym
;
18125 psym
= & filedata
->dynamic_symbols
[iconf
[cnt
]];
18126 print_vma (psym
->st_value
, FULL_HEX
);
18128 if (VALID_DYNAMIC_NAME (filedata
, psym
->st_name
))
18129 print_symbol (25, GET_DYNAMIC_NAME (filedata
, psym
->st_name
));
18131 printf (_("<corrupt: %14ld>"), psym
->st_name
);
18139 if (pltgot
!= 0 && local_gotno
!= 0)
18141 bfd_vma ent
, local_end
, global_end
;
18143 unsigned char * data
;
18144 unsigned char * data_end
;
18148 addr_size
= (is_32bit_elf
? 4 : 8);
18149 local_end
= pltgot
+ local_gotno
* addr_size
;
18151 /* PR binutils/17533 file: 012-111227-0.004 */
18152 if (symtabno
< gotsym
)
18154 error (_("The GOT symbol offset (%lu) is greater than the symbol table size (%lu)\n"),
18155 (unsigned long) gotsym
, (unsigned long) symtabno
);
18159 global_end
= local_end
+ (symtabno
- gotsym
) * addr_size
;
18160 /* PR 17531: file: 54c91a34. */
18161 if (global_end
< local_end
)
18163 error (_("Too many GOT symbols: %lu\n"), (unsigned long) symtabno
);
18167 offset
= offset_from_vma (filedata
, pltgot
, global_end
- pltgot
);
18168 data
= (unsigned char *) get_data (NULL
, filedata
, offset
,
18169 global_end
- pltgot
, 1,
18170 _("Global Offset Table data"));
18171 /* PR 12855: Null data is handled gracefully throughout. */
18172 data_end
= data
+ (global_end
- pltgot
);
18174 printf (_("\nPrimary GOT:\n"));
18175 printf (_(" Canonical gp value: "));
18176 print_vma (pltgot
+ 0x7ff0, LONG_HEX
);
18179 printf (_(" Reserved entries:\n"));
18180 printf (_(" %*s %10s %*s Purpose\n"),
18181 addr_size
* 2, _("Address"), _("Access"),
18182 addr_size
* 2, _("Initial"));
18183 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
18184 printf (_(" Lazy resolver\n"));
18185 if (ent
== (bfd_vma
) -1)
18186 goto got_print_fail
;
18188 /* Check for the MSB of GOT[1] being set, denoting a GNU object.
18189 This entry will be used by some runtime loaders, to store the
18190 module pointer. Otherwise this is an ordinary local entry.
18191 PR 21344: Check for the entry being fully available before
18194 && data
+ ent
- pltgot
+ addr_size
<= data_end
18195 && (byte_get (data
+ ent
- pltgot
, addr_size
)
18196 >> (addr_size
* 8 - 1)) != 0)
18198 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
18199 printf (_(" Module pointer (GNU extension)\n"));
18200 if (ent
== (bfd_vma
) -1)
18201 goto got_print_fail
;
18205 if (data
!= NULL
&& ent
< local_end
)
18207 printf (_(" Local entries:\n"));
18208 printf (" %*s %10s %*s\n",
18209 addr_size
* 2, _("Address"), _("Access"),
18210 addr_size
* 2, _("Initial"));
18211 while (ent
< local_end
)
18213 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
18215 if (ent
== (bfd_vma
) -1)
18216 goto got_print_fail
;
18221 if (data
!= NULL
&& gotsym
< symtabno
)
18225 printf (_(" Global entries:\n"));
18226 printf (" %*s %10s %*s %*s %-7s %3s %s\n",
18227 addr_size
* 2, _("Address"),
18229 addr_size
* 2, _("Initial"),
18230 addr_size
* 2, _("Sym.Val."),
18232 /* Note for translators: "Ndx" = abbreviated form of "Index". */
18233 _("Ndx"), _("Name"));
18235 sym_width
= (is_32bit_elf
? 80 : 160) - 28 - addr_size
* 6 - 1;
18237 for (i
= gotsym
; i
< symtabno
; i
++)
18239 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
18242 if (filedata
->dynamic_symbols
== NULL
)
18243 printf (_("<no dynamic symbols>"));
18244 else if (i
< filedata
->num_dynamic_syms
)
18246 Elf_Internal_Sym
* psym
= filedata
->dynamic_symbols
+ i
;
18248 print_vma (psym
->st_value
, LONG_HEX
);
18249 printf (" %-7s %3s ",
18250 get_symbol_type (filedata
, ELF_ST_TYPE (psym
->st_info
)),
18251 get_symbol_index_type (filedata
, psym
->st_shndx
));
18253 if (VALID_DYNAMIC_NAME (filedata
, psym
->st_name
))
18254 print_symbol (sym_width
,
18255 GET_DYNAMIC_NAME (filedata
, psym
->st_name
));
18257 printf (_("<corrupt: %14ld>"), psym
->st_name
);
18260 printf (_("<symbol index %lu exceeds number of dynamic symbols>"),
18261 (unsigned long) i
);
18264 if (ent
== (bfd_vma
) -1)
18274 if (mips_pltgot
!= 0 && jmprel
!= 0 && pltrel
!= 0 && pltrelsz
!= 0)
18277 size_t offset
, rel_offset
;
18278 unsigned long count
, i
;
18279 unsigned char * data
;
18280 int addr_size
, sym_width
;
18281 Elf_Internal_Rela
* rels
;
18283 rel_offset
= offset_from_vma (filedata
, jmprel
, pltrelsz
);
18284 if (pltrel
== DT_RELA
)
18286 if (!slurp_rela_relocs (filedata
, rel_offset
, pltrelsz
, &rels
, &count
))
18291 if (!slurp_rel_relocs (filedata
, rel_offset
, pltrelsz
, &rels
, &count
))
18296 addr_size
= (is_32bit_elf
? 4 : 8);
18297 end
= mips_pltgot
+ (2 + count
) * addr_size
;
18299 offset
= offset_from_vma (filedata
, mips_pltgot
, end
- mips_pltgot
);
18300 data
= (unsigned char *) get_data (NULL
, filedata
, offset
, end
- mips_pltgot
,
18301 1, _("Procedure Linkage Table data"));
18308 printf ("\nPLT GOT:\n\n");
18309 printf (_(" Reserved entries:\n"));
18310 printf (_(" %*s %*s Purpose\n"),
18311 addr_size
* 2, _("Address"), addr_size
* 2, _("Initial"));
18312 ent
= print_mips_pltgot_entry (data
, mips_pltgot
, ent
);
18313 printf (_(" PLT lazy resolver\n"));
18314 ent
= print_mips_pltgot_entry (data
, mips_pltgot
, ent
);
18315 printf (_(" Module pointer\n"));
18318 printf (_(" Entries:\n"));
18319 printf (" %*s %*s %*s %-7s %3s %s\n",
18320 addr_size
* 2, _("Address"),
18321 addr_size
* 2, _("Initial"),
18322 addr_size
* 2, _("Sym.Val."), _("Type"), _("Ndx"), _("Name"));
18323 sym_width
= (is_32bit_elf
? 80 : 160) - 17 - addr_size
* 6 - 1;
18324 for (i
= 0; i
< count
; i
++)
18326 unsigned long idx
= get_reloc_symindex (rels
[i
].r_info
);
18328 ent
= print_mips_pltgot_entry (data
, mips_pltgot
, ent
);
18331 if (idx
>= filedata
->num_dynamic_syms
)
18332 printf (_("<corrupt symbol index: %lu>"), idx
);
18335 Elf_Internal_Sym
* psym
= filedata
->dynamic_symbols
+ idx
;
18337 print_vma (psym
->st_value
, LONG_HEX
);
18338 printf (" %-7s %3s ",
18339 get_symbol_type (filedata
, ELF_ST_TYPE (psym
->st_info
)),
18340 get_symbol_index_type (filedata
, psym
->st_shndx
));
18341 if (VALID_DYNAMIC_NAME (filedata
, psym
->st_name
))
18342 print_symbol (sym_width
,
18343 GET_DYNAMIC_NAME (filedata
, psym
->st_name
));
18345 printf (_("<corrupt: %14ld>"), psym
->st_name
);
18359 process_nds32_specific (Filedata
* filedata
)
18361 Elf_Internal_Shdr
*sect
= NULL
;
18363 sect
= find_section (filedata
, ".nds32_e_flags");
18364 if (sect
!= NULL
&& sect
->sh_size
>= 4)
18366 unsigned char *buf
;
18369 printf ("\nNDS32 elf flags section:\n");
18370 buf
= get_data (NULL
, filedata
, sect
->sh_offset
, 1, 4,
18371 _("NDS32 elf flags section"));
18376 flag
= byte_get (buf
, 4);
18378 switch (flag
& 0x3)
18381 printf ("(VEC_SIZE):\tNo entry.\n");
18384 printf ("(VEC_SIZE):\t4 bytes\n");
18387 printf ("(VEC_SIZE):\t16 bytes\n");
18390 printf ("(VEC_SIZE):\treserved\n");
18399 process_gnu_liblist (Filedata
* filedata
)
18401 Elf_Internal_Shdr
* section
;
18402 Elf_Internal_Shdr
* string_sec
;
18403 Elf32_External_Lib
* elib
;
18405 size_t strtab_size
;
18407 unsigned long num_liblist
;
18414 for (i
= 0, section
= filedata
->section_headers
;
18415 i
< filedata
->file_header
.e_shnum
;
18418 switch (section
->sh_type
)
18420 case SHT_GNU_LIBLIST
:
18421 if (section
->sh_link
>= filedata
->file_header
.e_shnum
)
18424 elib
= (Elf32_External_Lib
*)
18425 get_data (NULL
, filedata
, section
->sh_offset
, 1, section
->sh_size
,
18426 _("liblist section data"));
18434 string_sec
= filedata
->section_headers
+ section
->sh_link
;
18435 strtab
= (char *) get_data (NULL
, filedata
, string_sec
->sh_offset
, 1,
18436 string_sec
->sh_size
,
18437 _("liblist string table"));
18439 || section
->sh_entsize
!= sizeof (Elf32_External_Lib
))
18446 strtab_size
= string_sec
->sh_size
;
18448 num_liblist
= section
->sh_size
/ sizeof (Elf32_External_Lib
);
18449 printf (ngettext ("\nLibrary list section '%s' contains %lu entries:\n",
18450 "\nLibrary list section '%s' contains %lu entries:\n",
18452 printable_section_name (filedata
, section
),
18455 puts (_(" Library Time Stamp Checksum Version Flags"));
18457 for (cnt
= 0; cnt
< section
->sh_size
/ sizeof (Elf32_External_Lib
);
18465 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
18466 atime
= BYTE_GET (elib
[cnt
].l_time_stamp
);
18467 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
18468 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
18469 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
18471 tmp
= gmtime (&atime
);
18472 snprintf (timebuf
, sizeof (timebuf
),
18473 "%04u-%02u-%02uT%02u:%02u:%02u",
18474 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
18475 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
18477 printf ("%3lu: ", (unsigned long) cnt
);
18479 printf ("%-20s", liblist
.l_name
< strtab_size
18480 ? strtab
+ liblist
.l_name
: _("<corrupt>"));
18482 printf ("%-20.20s", liblist
.l_name
< strtab_size
18483 ? strtab
+ liblist
.l_name
: _("<corrupt>"));
18484 printf (" %s %#010lx %-7ld %-7ld\n", timebuf
, liblist
.l_checksum
,
18485 liblist
.l_version
, liblist
.l_flags
);
18496 static const char *
18497 get_note_type (Filedata
* filedata
, unsigned e_type
)
18499 static char buff
[64];
18501 if (filedata
->file_header
.e_type
== ET_CORE
)
18505 return _("NT_AUXV (auxiliary vector)");
18507 return _("NT_PRSTATUS (prstatus structure)");
18509 return _("NT_FPREGSET (floating point registers)");
18511 return _("NT_PRPSINFO (prpsinfo structure)");
18512 case NT_TASKSTRUCT
:
18513 return _("NT_TASKSTRUCT (task structure)");
18515 return _("NT_GDB_TDESC (GDB XML target description)");
18517 return _("NT_PRXFPREG (user_xfpregs structure)");
18519 return _("NT_PPC_VMX (ppc Altivec registers)");
18521 return _("NT_PPC_VSX (ppc VSX registers)");
18523 return _("NT_PPC_TAR (ppc TAR register)");
18525 return _("NT_PPC_PPR (ppc PPR register)");
18527 return _("NT_PPC_DSCR (ppc DSCR register)");
18529 return _("NT_PPC_EBB (ppc EBB registers)");
18531 return _("NT_PPC_PMU (ppc PMU registers)");
18532 case NT_PPC_TM_CGPR
:
18533 return _("NT_PPC_TM_CGPR (ppc checkpointed GPR registers)");
18534 case NT_PPC_TM_CFPR
:
18535 return _("NT_PPC_TM_CFPR (ppc checkpointed floating point registers)");
18536 case NT_PPC_TM_CVMX
:
18537 return _("NT_PPC_TM_CVMX (ppc checkpointed Altivec registers)");
18538 case NT_PPC_TM_CVSX
:
18539 return _("NT_PPC_TM_CVSX (ppc checkpointed VSX registers)");
18540 case NT_PPC_TM_SPR
:
18541 return _("NT_PPC_TM_SPR (ppc TM special purpose registers)");
18542 case NT_PPC_TM_CTAR
:
18543 return _("NT_PPC_TM_CTAR (ppc checkpointed TAR register)");
18544 case NT_PPC_TM_CPPR
:
18545 return _("NT_PPC_TM_CPPR (ppc checkpointed PPR register)");
18546 case NT_PPC_TM_CDSCR
:
18547 return _("NT_PPC_TM_CDSCR (ppc checkpointed DSCR register)");
18549 return _("NT_386_TLS (x86 TLS information)");
18550 case NT_386_IOPERM
:
18551 return _("NT_386_IOPERM (x86 I/O permissions)");
18552 case NT_X86_XSTATE
:
18553 return _("NT_X86_XSTATE (x86 XSAVE extended state)");
18555 return _("NT_X86_CET (x86 CET state)");
18556 case NT_S390_HIGH_GPRS
:
18557 return _("NT_S390_HIGH_GPRS (s390 upper register halves)");
18558 case NT_S390_TIMER
:
18559 return _("NT_S390_TIMER (s390 timer register)");
18560 case NT_S390_TODCMP
:
18561 return _("NT_S390_TODCMP (s390 TOD comparator register)");
18562 case NT_S390_TODPREG
:
18563 return _("NT_S390_TODPREG (s390 TOD programmable register)");
18565 return _("NT_S390_CTRS (s390 control registers)");
18566 case NT_S390_PREFIX
:
18567 return _("NT_S390_PREFIX (s390 prefix register)");
18568 case NT_S390_LAST_BREAK
:
18569 return _("NT_S390_LAST_BREAK (s390 last breaking event address)");
18570 case NT_S390_SYSTEM_CALL
:
18571 return _("NT_S390_SYSTEM_CALL (s390 system call restart data)");
18573 return _("NT_S390_TDB (s390 transaction diagnostic block)");
18574 case NT_S390_VXRS_LOW
:
18575 return _("NT_S390_VXRS_LOW (s390 vector registers 0-15 upper half)");
18576 case NT_S390_VXRS_HIGH
:
18577 return _("NT_S390_VXRS_HIGH (s390 vector registers 16-31)");
18578 case NT_S390_GS_CB
:
18579 return _("NT_S390_GS_CB (s390 guarded-storage registers)");
18580 case NT_S390_GS_BC
:
18581 return _("NT_S390_GS_BC (s390 guarded-storage broadcast control)");
18583 return _("NT_ARM_VFP (arm VFP registers)");
18585 return _("NT_ARM_TLS (AArch TLS registers)");
18586 case NT_ARM_HW_BREAK
:
18587 return _("NT_ARM_HW_BREAK (AArch hardware breakpoint registers)");
18588 case NT_ARM_HW_WATCH
:
18589 return _("NT_ARM_HW_WATCH (AArch hardware watchpoint registers)");
18591 return _("NT_ARC_V2 (ARC HS accumulator/extra registers)");
18593 return _("NT_RISCV_CSR (RISC-V control and status registers)");
18595 return _("NT_PSTATUS (pstatus structure)");
18597 return _("NT_FPREGS (floating point registers)");
18599 return _("NT_PSINFO (psinfo structure)");
18601 return _("NT_LWPSTATUS (lwpstatus_t structure)");
18603 return _("NT_LWPSINFO (lwpsinfo_t structure)");
18604 case NT_WIN32PSTATUS
:
18605 return _("NT_WIN32PSTATUS (win32_pstatus structure)");
18607 return _("NT_SIGINFO (siginfo_t data)");
18609 return _("NT_FILE (mapped files)");
18617 return _("NT_VERSION (version)");
18619 return _("NT_ARCH (architecture)");
18620 case NT_GNU_BUILD_ATTRIBUTE_OPEN
:
18622 case NT_GNU_BUILD_ATTRIBUTE_FUNC
:
18628 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
18633 print_core_note (Elf_Internal_Note
*pnote
)
18635 unsigned int addr_size
= is_32bit_elf
? 4 : 8;
18636 bfd_vma count
, page_size
;
18637 unsigned char *descdata
, *filenames
, *descend
;
18639 if (pnote
->type
!= NT_FILE
)
18649 printf (_(" Cannot decode 64-bit note in 32-bit build\n"));
18650 /* Still "successful". */
18655 if (pnote
->descsz
< 2 * addr_size
)
18657 error (_(" Malformed note - too short for header\n"));
18661 descdata
= (unsigned char *) pnote
->descdata
;
18662 descend
= descdata
+ pnote
->descsz
;
18664 if (descdata
[pnote
->descsz
- 1] != '\0')
18666 error (_(" Malformed note - does not end with \\0\n"));
18670 count
= byte_get (descdata
, addr_size
);
18671 descdata
+= addr_size
;
18673 page_size
= byte_get (descdata
, addr_size
);
18674 descdata
+= addr_size
;
18676 if (count
> ((bfd_vma
) -1 - 2 * addr_size
) / (3 * addr_size
)
18677 || pnote
->descsz
< 2 * addr_size
+ count
* 3 * addr_size
)
18679 error (_(" Malformed note - too short for supplied file count\n"));
18683 printf (_(" Page size: "));
18684 print_vma (page_size
, DEC
);
18687 printf (_(" %*s%*s%*s\n"),
18688 (int) (2 + 2 * addr_size
), _("Start"),
18689 (int) (4 + 2 * addr_size
), _("End"),
18690 (int) (4 + 2 * addr_size
), _("Page Offset"));
18691 filenames
= descdata
+ count
* 3 * addr_size
;
18692 while (count
-- > 0)
18694 bfd_vma start
, end
, file_ofs
;
18696 if (filenames
== descend
)
18698 error (_(" Malformed note - filenames end too early\n"));
18702 start
= byte_get (descdata
, addr_size
);
18703 descdata
+= addr_size
;
18704 end
= byte_get (descdata
, addr_size
);
18705 descdata
+= addr_size
;
18706 file_ofs
= byte_get (descdata
, addr_size
);
18707 descdata
+= addr_size
;
18710 print_vma (start
, FULL_HEX
);
18712 print_vma (end
, FULL_HEX
);
18714 print_vma (file_ofs
, FULL_HEX
);
18715 printf ("\n %s\n", filenames
);
18717 filenames
+= 1 + strlen ((char *) filenames
);
18723 static const char *
18724 get_gnu_elf_note_type (unsigned e_type
)
18726 /* NB/ Keep this switch statement in sync with print_gnu_note (). */
18729 case NT_GNU_ABI_TAG
:
18730 return _("NT_GNU_ABI_TAG (ABI version tag)");
18732 return _("NT_GNU_HWCAP (DSO-supplied software HWCAP info)");
18733 case NT_GNU_BUILD_ID
:
18734 return _("NT_GNU_BUILD_ID (unique build ID bitstring)");
18735 case NT_GNU_GOLD_VERSION
:
18736 return _("NT_GNU_GOLD_VERSION (gold version)");
18737 case NT_GNU_PROPERTY_TYPE_0
:
18738 return _("NT_GNU_PROPERTY_TYPE_0");
18739 case NT_GNU_BUILD_ATTRIBUTE_OPEN
:
18740 return _("NT_GNU_BUILD_ATTRIBUTE_OPEN");
18741 case NT_GNU_BUILD_ATTRIBUTE_FUNC
:
18742 return _("NT_GNU_BUILD_ATTRIBUTE_FUNC");
18745 static char buff
[64];
18747 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
18754 decode_x86_compat_isa (unsigned int bitmask
)
18758 unsigned int bit
= bitmask
& (- bitmask
);
18763 case GNU_PROPERTY_X86_COMPAT_ISA_1_486
:
18766 case GNU_PROPERTY_X86_COMPAT_ISA_1_586
:
18769 case GNU_PROPERTY_X86_COMPAT_ISA_1_686
:
18772 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE
:
18775 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE2
:
18778 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE3
:
18781 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSSE3
:
18784 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE4_1
:
18787 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE4_2
:
18790 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX
:
18793 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX2
:
18796 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512F
:
18797 printf ("AVX512F");
18799 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512CD
:
18800 printf ("AVX512CD");
18802 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512ER
:
18803 printf ("AVX512ER");
18805 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512PF
:
18806 printf ("AVX512PF");
18808 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512VL
:
18809 printf ("AVX512VL");
18811 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512DQ
:
18812 printf ("AVX512DQ");
18814 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512BW
:
18815 printf ("AVX512BW");
18818 printf (_("<unknown: %x>"), bit
);
18827 decode_x86_compat_2_isa (unsigned int bitmask
)
18831 printf (_("<None>"));
18837 unsigned int bit
= bitmask
& (- bitmask
);
18842 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_CMOV
:
18845 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE
:
18848 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE2
:
18851 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE3
:
18854 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSSE3
:
18857 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE4_1
:
18860 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE4_2
:
18863 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX
:
18866 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX2
:
18869 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_FMA
:
18872 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512F
:
18873 printf ("AVX512F");
18875 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512CD
:
18876 printf ("AVX512CD");
18878 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512ER
:
18879 printf ("AVX512ER");
18881 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512PF
:
18882 printf ("AVX512PF");
18884 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512VL
:
18885 printf ("AVX512VL");
18887 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512DQ
:
18888 printf ("AVX512DQ");
18890 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512BW
:
18891 printf ("AVX512BW");
18893 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_4FMAPS
:
18894 printf ("AVX512_4FMAPS");
18896 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_4VNNIW
:
18897 printf ("AVX512_4VNNIW");
18899 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_BITALG
:
18900 printf ("AVX512_BITALG");
18902 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_IFMA
:
18903 printf ("AVX512_IFMA");
18905 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_VBMI
:
18906 printf ("AVX512_VBMI");
18908 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_VBMI2
:
18909 printf ("AVX512_VBMI2");
18911 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_VNNI
:
18912 printf ("AVX512_VNNI");
18914 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_BF16
:
18915 printf ("AVX512_BF16");
18918 printf (_("<unknown: %x>"), bit
);
18927 decode_x86_isa (unsigned int bitmask
)
18931 unsigned int bit
= bitmask
& (- bitmask
);
18936 case GNU_PROPERTY_X86_ISA_1_BASELINE
:
18937 printf ("x86-64-baseline");
18939 case GNU_PROPERTY_X86_ISA_1_V2
:
18940 printf ("x86-64-v2");
18942 case GNU_PROPERTY_X86_ISA_1_V3
:
18943 printf ("x86-64-v3");
18945 case GNU_PROPERTY_X86_ISA_1_V4
:
18946 printf ("x86-64-v4");
18949 printf (_("<unknown: %x>"), bit
);
18958 decode_x86_feature_1 (unsigned int bitmask
)
18962 printf (_("<None>"));
18968 unsigned int bit
= bitmask
& (- bitmask
);
18973 case GNU_PROPERTY_X86_FEATURE_1_IBT
:
18976 case GNU_PROPERTY_X86_FEATURE_1_SHSTK
:
18979 case GNU_PROPERTY_X86_FEATURE_1_LAM_U48
:
18980 printf ("LAM_U48");
18982 case GNU_PROPERTY_X86_FEATURE_1_LAM_U57
:
18983 printf ("LAM_U57");
18986 printf (_("<unknown: %x>"), bit
);
18995 decode_x86_feature_2 (unsigned int bitmask
)
18999 printf (_("<None>"));
19005 unsigned int bit
= bitmask
& (- bitmask
);
19010 case GNU_PROPERTY_X86_FEATURE_2_X86
:
19013 case GNU_PROPERTY_X86_FEATURE_2_X87
:
19016 case GNU_PROPERTY_X86_FEATURE_2_MMX
:
19019 case GNU_PROPERTY_X86_FEATURE_2_XMM
:
19022 case GNU_PROPERTY_X86_FEATURE_2_YMM
:
19025 case GNU_PROPERTY_X86_FEATURE_2_ZMM
:
19028 case GNU_PROPERTY_X86_FEATURE_2_TMM
:
19031 case GNU_PROPERTY_X86_FEATURE_2_MASK
:
19034 case GNU_PROPERTY_X86_FEATURE_2_FXSR
:
19037 case GNU_PROPERTY_X86_FEATURE_2_XSAVE
:
19040 case GNU_PROPERTY_X86_FEATURE_2_XSAVEOPT
:
19041 printf ("XSAVEOPT");
19043 case GNU_PROPERTY_X86_FEATURE_2_XSAVEC
:
19047 printf (_("<unknown: %x>"), bit
);
19056 decode_aarch64_feature_1_and (unsigned int bitmask
)
19060 unsigned int bit
= bitmask
& (- bitmask
);
19065 case GNU_PROPERTY_AARCH64_FEATURE_1_BTI
:
19069 case GNU_PROPERTY_AARCH64_FEATURE_1_PAC
:
19074 printf (_("<unknown: %x>"), bit
);
19083 print_gnu_property_note (Filedata
* filedata
, Elf_Internal_Note
* pnote
)
19085 unsigned char * ptr
= (unsigned char *) pnote
->descdata
;
19086 unsigned char * ptr_end
= ptr
+ pnote
->descsz
;
19087 unsigned int size
= is_32bit_elf
? 4 : 8;
19089 printf (_(" Properties: "));
19091 if (pnote
->descsz
< 8 || (pnote
->descsz
% size
) != 0)
19093 printf (_("<corrupt GNU_PROPERTY_TYPE, size = %#lx>\n"), pnote
->descsz
);
19097 while (ptr
< ptr_end
)
19101 unsigned int datasz
;
19103 if ((size_t) (ptr_end
- ptr
) < 8)
19105 printf (_("<corrupt descsz: %#lx>\n"), pnote
->descsz
);
19109 type
= byte_get (ptr
, 4);
19110 datasz
= byte_get (ptr
+ 4, 4);
19114 if (datasz
> (size_t) (ptr_end
- ptr
))
19116 printf (_("<corrupt type (%#x) datasz: %#x>\n"),
19121 if (type
>= GNU_PROPERTY_LOPROC
&& type
<= GNU_PROPERTY_HIPROC
)
19123 if (filedata
->file_header
.e_machine
== EM_X86_64
19124 || filedata
->file_header
.e_machine
== EM_IAMCU
19125 || filedata
->file_header
.e_machine
== EM_386
)
19127 unsigned int bitmask
;
19130 bitmask
= byte_get (ptr
, 4);
19136 case GNU_PROPERTY_X86_ISA_1_USED
:
19138 printf (_("x86 ISA used: <corrupt length: %#x> "),
19142 printf ("x86 ISA used: ");
19143 decode_x86_isa (bitmask
);
19147 case GNU_PROPERTY_X86_ISA_1_NEEDED
:
19149 printf (_("x86 ISA needed: <corrupt length: %#x> "),
19153 printf ("x86 ISA needed: ");
19154 decode_x86_isa (bitmask
);
19158 case GNU_PROPERTY_X86_FEATURE_1_AND
:
19160 printf (_("x86 feature: <corrupt length: %#x> "),
19164 printf ("x86 feature: ");
19165 decode_x86_feature_1 (bitmask
);
19169 case GNU_PROPERTY_X86_FEATURE_2_USED
:
19171 printf (_("x86 feature used: <corrupt length: %#x> "),
19175 printf ("x86 feature used: ");
19176 decode_x86_feature_2 (bitmask
);
19180 case GNU_PROPERTY_X86_FEATURE_2_NEEDED
:
19182 printf (_("x86 feature needed: <corrupt length: %#x> "), datasz
);
19185 printf ("x86 feature needed: ");
19186 decode_x86_feature_2 (bitmask
);
19190 case GNU_PROPERTY_X86_COMPAT_ISA_1_USED
:
19192 printf (_("x86 ISA used: <corrupt length: %#x> "),
19196 printf ("x86 ISA used: ");
19197 decode_x86_compat_isa (bitmask
);
19201 case GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED
:
19203 printf (_("x86 ISA needed: <corrupt length: %#x> "),
19207 printf ("x86 ISA needed: ");
19208 decode_x86_compat_isa (bitmask
);
19212 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_USED
:
19214 printf (_("x86 ISA used: <corrupt length: %#x> "),
19218 printf ("x86 ISA used: ");
19219 decode_x86_compat_2_isa (bitmask
);
19223 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_NEEDED
:
19225 printf (_("x86 ISA needed: <corrupt length: %#x> "),
19229 printf ("x86 ISA needed: ");
19230 decode_x86_compat_2_isa (bitmask
);
19238 else if (filedata
->file_header
.e_machine
== EM_AARCH64
)
19240 if (type
== GNU_PROPERTY_AARCH64_FEATURE_1_AND
)
19242 printf ("AArch64 feature: ");
19244 printf (_("<corrupt length: %#x> "), datasz
);
19246 decode_aarch64_feature_1_and (byte_get (ptr
, 4));
19255 case GNU_PROPERTY_STACK_SIZE
:
19256 printf (_("stack size: "));
19257 if (datasz
!= size
)
19258 printf (_("<corrupt length: %#x> "), datasz
);
19260 printf ("%#lx", (unsigned long) byte_get (ptr
, size
));
19263 case GNU_PROPERTY_NO_COPY_ON_PROTECTED
:
19264 printf ("no copy on protected ");
19266 printf (_("<corrupt length: %#x> "), datasz
);
19274 if (type
< GNU_PROPERTY_LOPROC
)
19275 printf (_("<unknown type %#x data: "), type
);
19276 else if (type
< GNU_PROPERTY_LOUSER
)
19277 printf (_("<processor-specific type %#x data: "), type
);
19279 printf (_("<application-specific type %#x data: "), type
);
19280 for (j
= 0; j
< datasz
; ++j
)
19281 printf ("%02x ", ptr
[j
] & 0xff);
19285 ptr
+= ((datasz
+ (size
- 1)) & ~ (size
- 1));
19286 if (ptr
== ptr_end
)
19299 print_gnu_note (Filedata
* filedata
, Elf_Internal_Note
*pnote
)
19301 /* NB/ Keep this switch statement in sync with get_gnu_elf_note_type (). */
19302 switch (pnote
->type
)
19304 case NT_GNU_BUILD_ID
:
19308 printf (_(" Build ID: "));
19309 for (i
= 0; i
< pnote
->descsz
; ++i
)
19310 printf ("%02x", pnote
->descdata
[i
] & 0xff);
19315 case NT_GNU_ABI_TAG
:
19317 unsigned long os
, major
, minor
, subminor
;
19318 const char *osname
;
19320 /* PR 17531: file: 030-599401-0.004. */
19321 if (pnote
->descsz
< 16)
19323 printf (_(" <corrupt GNU_ABI_TAG>\n"));
19327 os
= byte_get ((unsigned char *) pnote
->descdata
, 4);
19328 major
= byte_get ((unsigned char *) pnote
->descdata
+ 4, 4);
19329 minor
= byte_get ((unsigned char *) pnote
->descdata
+ 8, 4);
19330 subminor
= byte_get ((unsigned char *) pnote
->descdata
+ 12, 4);
19334 case GNU_ABI_TAG_LINUX
:
19337 case GNU_ABI_TAG_HURD
:
19340 case GNU_ABI_TAG_SOLARIS
:
19341 osname
= "Solaris";
19343 case GNU_ABI_TAG_FREEBSD
:
19344 osname
= "FreeBSD";
19346 case GNU_ABI_TAG_NETBSD
:
19349 case GNU_ABI_TAG_SYLLABLE
:
19350 osname
= "Syllable";
19352 case GNU_ABI_TAG_NACL
:
19356 osname
= "Unknown";
19360 printf (_(" OS: %s, ABI: %ld.%ld.%ld\n"), osname
,
19361 major
, minor
, subminor
);
19365 case NT_GNU_GOLD_VERSION
:
19369 printf (_(" Version: "));
19370 for (i
= 0; i
< pnote
->descsz
&& pnote
->descdata
[i
] != '\0'; ++i
)
19371 printf ("%c", pnote
->descdata
[i
]);
19378 unsigned long num_entries
, mask
;
19380 /* Hardware capabilities information. Word 0 is the number of entries.
19381 Word 1 is a bitmask of enabled entries. The rest of the descriptor
19382 is a series of entries, where each entry is a single byte followed
19383 by a nul terminated string. The byte gives the bit number to test
19384 if enabled in the bitmask. */
19385 printf (_(" Hardware Capabilities: "));
19386 if (pnote
->descsz
< 8)
19388 error (_("<corrupt GNU_HWCAP>\n"));
19391 num_entries
= byte_get ((unsigned char *) pnote
->descdata
, 4);
19392 mask
= byte_get ((unsigned char *) pnote
->descdata
+ 4, 4);
19393 printf (_("num entries: %ld, enabled mask: %lx\n"), num_entries
, mask
);
19394 /* FIXME: Add code to display the entries... */
19398 case NT_GNU_PROPERTY_TYPE_0
:
19399 print_gnu_property_note (filedata
, pnote
);
19403 /* Handle unrecognised types. An error message should have already been
19404 created by get_gnu_elf_note_type(), so all that we need to do is to
19405 display the data. */
19409 printf (_(" Description data: "));
19410 for (i
= 0; i
< pnote
->descsz
; ++i
)
19411 printf ("%02x ", pnote
->descdata
[i
] & 0xff);
19420 static const char *
19421 get_v850_elf_note_type (enum v850_notes n_type
)
19423 static char buff
[64];
19427 case V850_NOTE_ALIGNMENT
: return _("Alignment of 8-byte objects");
19428 case V850_NOTE_DATA_SIZE
: return _("Sizeof double and long double");
19429 case V850_NOTE_FPU_INFO
: return _("Type of FPU support needed");
19430 case V850_NOTE_SIMD_INFO
: return _("Use of SIMD instructions");
19431 case V850_NOTE_CACHE_INFO
: return _("Use of cache");
19432 case V850_NOTE_MMU_INFO
: return _("Use of MMU");
19434 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), n_type
);
19440 print_v850_note (Elf_Internal_Note
* pnote
)
19444 if (pnote
->descsz
!= 4)
19447 val
= byte_get ((unsigned char *) pnote
->descdata
, pnote
->descsz
);
19451 printf (_("not set\n"));
19455 switch (pnote
->type
)
19457 case V850_NOTE_ALIGNMENT
:
19460 case EF_RH850_DATA_ALIGN4
: printf (_("4-byte\n")); return true;
19461 case EF_RH850_DATA_ALIGN8
: printf (_("8-byte\n")); return true;
19465 case V850_NOTE_DATA_SIZE
:
19468 case EF_RH850_DOUBLE32
: printf (_("4-bytes\n")); return true;
19469 case EF_RH850_DOUBLE64
: printf (_("8-bytes\n")); return true;
19473 case V850_NOTE_FPU_INFO
:
19476 case EF_RH850_FPU20
: printf (_("FPU-2.0\n")); return true;
19477 case EF_RH850_FPU30
: printf (_("FPU-3.0\n")); return true;
19481 case V850_NOTE_MMU_INFO
:
19482 case V850_NOTE_CACHE_INFO
:
19483 case V850_NOTE_SIMD_INFO
:
19484 if (val
== EF_RH850_SIMD
)
19486 printf (_("yes\n"));
19492 /* An 'unknown note type' message will already have been displayed. */
19496 printf (_("unknown value: %x\n"), val
);
19501 process_netbsd_elf_note (Elf_Internal_Note
* pnote
)
19503 unsigned int version
;
19505 switch (pnote
->type
)
19507 case NT_NETBSD_IDENT
:
19508 if (pnote
->descsz
< 1)
19510 version
= byte_get ((unsigned char *) pnote
->descdata
, sizeof (version
));
19511 if ((version
/ 10000) % 100)
19512 printf (" NetBSD\t\t0x%08lx\tIDENT %u (%u.%u%s%c)\n", pnote
->descsz
,
19513 version
, version
/ 100000000, (version
/ 1000000) % 100,
19514 (version
/ 10000) % 100 > 26 ? "Z" : "",
19515 'A' + (version
/ 10000) % 26);
19517 printf (" NetBSD\t\t0x%08lx\tIDENT %u (%u.%u.%u)\n", pnote
->descsz
,
19518 version
, version
/ 100000000, (version
/ 1000000) % 100,
19519 (version
/ 100) % 100);
19522 case NT_NETBSD_MARCH
:
19523 printf (" NetBSD\t\t0x%08lx\tMARCH <%s>\n", pnote
->descsz
,
19527 #ifdef NT_NETBSD_PAX
19528 case NT_NETBSD_PAX
:
19529 if (pnote
->descsz
< 1)
19531 version
= byte_get ((unsigned char *) pnote
->descdata
, sizeof (version
));
19532 printf (" NetBSD\t\t0x%08lx\tPaX <%s%s%s%s%s%s>\n", pnote
->descsz
,
19533 ((version
& NT_NETBSD_PAX_MPROTECT
) ? "+mprotect" : ""),
19534 ((version
& NT_NETBSD_PAX_NOMPROTECT
) ? "-mprotect" : ""),
19535 ((version
& NT_NETBSD_PAX_GUARD
) ? "+guard" : ""),
19536 ((version
& NT_NETBSD_PAX_NOGUARD
) ? "-guard" : ""),
19537 ((version
& NT_NETBSD_PAX_ASLR
) ? "+ASLR" : ""),
19538 ((version
& NT_NETBSD_PAX_NOASLR
) ? "-ASLR" : ""));
19543 printf (" NetBSD\t0x%08lx\tUnknown note type: (0x%08lx)\n",
19544 pnote
->descsz
, pnote
->type
);
19548 static const char *
19549 get_freebsd_elfcore_note_type (Filedata
* filedata
, unsigned e_type
)
19553 case NT_FREEBSD_THRMISC
:
19554 return _("NT_THRMISC (thrmisc structure)");
19555 case NT_FREEBSD_PROCSTAT_PROC
:
19556 return _("NT_PROCSTAT_PROC (proc data)");
19557 case NT_FREEBSD_PROCSTAT_FILES
:
19558 return _("NT_PROCSTAT_FILES (files data)");
19559 case NT_FREEBSD_PROCSTAT_VMMAP
:
19560 return _("NT_PROCSTAT_VMMAP (vmmap data)");
19561 case NT_FREEBSD_PROCSTAT_GROUPS
:
19562 return _("NT_PROCSTAT_GROUPS (groups data)");
19563 case NT_FREEBSD_PROCSTAT_UMASK
:
19564 return _("NT_PROCSTAT_UMASK (umask data)");
19565 case NT_FREEBSD_PROCSTAT_RLIMIT
:
19566 return _("NT_PROCSTAT_RLIMIT (rlimit data)");
19567 case NT_FREEBSD_PROCSTAT_OSREL
:
19568 return _("NT_PROCSTAT_OSREL (osreldate data)");
19569 case NT_FREEBSD_PROCSTAT_PSSTRINGS
:
19570 return _("NT_PROCSTAT_PSSTRINGS (ps_strings data)");
19571 case NT_FREEBSD_PROCSTAT_AUXV
:
19572 return _("NT_PROCSTAT_AUXV (auxv data)");
19573 case NT_FREEBSD_PTLWPINFO
:
19574 return _("NT_PTLWPINFO (ptrace_lwpinfo structure)");
19576 return get_note_type (filedata
, e_type
);
19579 static const char *
19580 get_netbsd_elfcore_note_type (Filedata
* filedata
, unsigned e_type
)
19582 static char buff
[64];
19586 case NT_NETBSDCORE_PROCINFO
:
19587 /* NetBSD core "procinfo" structure. */
19588 return _("NetBSD procinfo structure");
19590 #ifdef NT_NETBSDCORE_AUXV
19591 case NT_NETBSDCORE_AUXV
:
19592 return _("NetBSD ELF auxiliary vector data");
19595 #ifdef NT_NETBSDCORE_LWPSTATUS
19596 case NT_NETBSDCORE_LWPSTATUS
:
19597 return _("PT_LWPSTATUS (ptrace_lwpstatus structure)");
19601 /* As of Jan 2020 there are no other machine-independent notes
19602 defined for NetBSD core files. If the note type is less
19603 than the start of the machine-dependent note types, we don't
19606 if (e_type
< NT_NETBSDCORE_FIRSTMACH
)
19608 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
19614 switch (filedata
->file_header
.e_machine
)
19616 /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0
19617 and PT_GETFPREGS == mach+2. */
19622 case EM_SPARC32PLUS
:
19626 case NT_NETBSDCORE_FIRSTMACH
+ 0:
19627 return _("PT_GETREGS (reg structure)");
19628 case NT_NETBSDCORE_FIRSTMACH
+ 2:
19629 return _("PT_GETFPREGS (fpreg structure)");
19635 /* On SuperH, PT_GETREGS == mach+3 and PT_GETFPREGS == mach+5.
19636 There's also old PT___GETREGS40 == mach + 1 for old reg
19637 structure which lacks GBR. */
19641 case NT_NETBSDCORE_FIRSTMACH
+ 1:
19642 return _("PT___GETREGS40 (old reg structure)");
19643 case NT_NETBSDCORE_FIRSTMACH
+ 3:
19644 return _("PT_GETREGS (reg structure)");
19645 case NT_NETBSDCORE_FIRSTMACH
+ 5:
19646 return _("PT_GETFPREGS (fpreg structure)");
19652 /* On all other arch's, PT_GETREGS == mach+1 and
19653 PT_GETFPREGS == mach+3. */
19657 case NT_NETBSDCORE_FIRSTMACH
+ 1:
19658 return _("PT_GETREGS (reg structure)");
19659 case NT_NETBSDCORE_FIRSTMACH
+ 3:
19660 return _("PT_GETFPREGS (fpreg structure)");
19666 snprintf (buff
, sizeof (buff
), "PT_FIRSTMACH+%d",
19667 e_type
- NT_NETBSDCORE_FIRSTMACH
);
19671 static const char *
19672 get_stapsdt_note_type (unsigned e_type
)
19674 static char buff
[64];
19679 return _("NT_STAPSDT (SystemTap probe descriptors)");
19685 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
19690 print_stapsdt_note (Elf_Internal_Note
*pnote
)
19692 size_t len
, maxlen
;
19693 unsigned long addr_size
= is_32bit_elf
? 4 : 8;
19694 char *data
= pnote
->descdata
;
19695 char *data_end
= pnote
->descdata
+ pnote
->descsz
;
19696 bfd_vma pc
, base_addr
, semaphore
;
19697 char *provider
, *probe
, *arg_fmt
;
19699 if (pnote
->descsz
< (addr_size
* 3))
19700 goto stapdt_note_too_small
;
19702 pc
= byte_get ((unsigned char *) data
, addr_size
);
19705 base_addr
= byte_get ((unsigned char *) data
, addr_size
);
19708 semaphore
= byte_get ((unsigned char *) data
, addr_size
);
19711 if (data
>= data_end
)
19712 goto stapdt_note_too_small
;
19713 maxlen
= data_end
- data
;
19714 len
= strnlen (data
, maxlen
);
19721 goto stapdt_note_too_small
;
19723 if (data
>= data_end
)
19724 goto stapdt_note_too_small
;
19725 maxlen
= data_end
- data
;
19726 len
= strnlen (data
, maxlen
);
19733 goto stapdt_note_too_small
;
19735 if (data
>= data_end
)
19736 goto stapdt_note_too_small
;
19737 maxlen
= data_end
- data
;
19738 len
= strnlen (data
, maxlen
);
19745 goto stapdt_note_too_small
;
19747 printf (_(" Provider: %s\n"), provider
);
19748 printf (_(" Name: %s\n"), probe
);
19749 printf (_(" Location: "));
19750 print_vma (pc
, FULL_HEX
);
19751 printf (_(", Base: "));
19752 print_vma (base_addr
, FULL_HEX
);
19753 printf (_(", Semaphore: "));
19754 print_vma (semaphore
, FULL_HEX
);
19756 printf (_(" Arguments: %s\n"), arg_fmt
);
19758 return data
== data_end
;
19760 stapdt_note_too_small
:
19761 printf (_(" <corrupt - note is too small>\n"));
19762 error (_("corrupt stapdt note - the data size is too small\n"));
19766 static const char *
19767 get_ia64_vms_note_type (unsigned e_type
)
19769 static char buff
[64];
19774 return _("NT_VMS_MHD (module header)");
19776 return _("NT_VMS_LNM (language name)");
19778 return _("NT_VMS_SRC (source files)");
19780 return "NT_VMS_TITLE";
19782 return _("NT_VMS_EIDC (consistency check)");
19783 case NT_VMS_FPMODE
:
19784 return _("NT_VMS_FPMODE (FP mode)");
19785 case NT_VMS_LINKTIME
:
19786 return "NT_VMS_LINKTIME";
19787 case NT_VMS_IMGNAM
:
19788 return _("NT_VMS_IMGNAM (image name)");
19790 return _("NT_VMS_IMGID (image id)");
19791 case NT_VMS_LINKID
:
19792 return _("NT_VMS_LINKID (link id)");
19793 case NT_VMS_IMGBID
:
19794 return _("NT_VMS_IMGBID (build id)");
19795 case NT_VMS_GSTNAM
:
19796 return _("NT_VMS_GSTNAM (sym table name)");
19797 case NT_VMS_ORIG_DYN
:
19798 return "NT_VMS_ORIG_DYN";
19799 case NT_VMS_PATCHTIME
:
19800 return "NT_VMS_PATCHTIME";
19802 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
19808 print_ia64_vms_note (Elf_Internal_Note
* pnote
)
19810 int maxlen
= pnote
->descsz
;
19812 if (maxlen
< 2 || (unsigned long) maxlen
!= pnote
->descsz
)
19813 goto desc_size_fail
;
19815 switch (pnote
->type
)
19819 goto desc_size_fail
;
19821 int l
= (int) strnlen (pnote
->descdata
+ 34, maxlen
- 34);
19823 printf (_(" Creation date : %.17s\n"), pnote
->descdata
);
19824 printf (_(" Last patch date: %.17s\n"), pnote
->descdata
+ 17);
19825 if (l
+ 34 < maxlen
)
19827 printf (_(" Module name : %s\n"), pnote
->descdata
+ 34);
19828 if (l
+ 35 < maxlen
)
19829 printf (_(" Module version : %s\n"), pnote
->descdata
+ 34 + l
+ 1);
19831 printf (_(" Module version : <missing>\n"));
19835 printf (_(" Module name : <missing>\n"));
19836 printf (_(" Module version : <missing>\n"));
19841 printf (_(" Language: %.*s\n"), maxlen
, pnote
->descdata
);
19845 case NT_VMS_FPMODE
:
19846 printf (_(" Floating Point mode: "));
19848 goto desc_size_fail
;
19849 /* FIXME: Generate an error if descsz > 8 ? */
19851 printf ("0x%016" BFD_VMA_FMT
"x\n",
19852 (bfd_vma
) byte_get ((unsigned char *)pnote
->descdata
, 8));
19855 case NT_VMS_LINKTIME
:
19856 printf (_(" Link time: "));
19858 goto desc_size_fail
;
19859 /* FIXME: Generate an error if descsz > 8 ? */
19862 ((bfd_int64_t
) byte_get ((unsigned char *)pnote
->descdata
, 8));
19866 case NT_VMS_PATCHTIME
:
19867 printf (_(" Patch time: "));
19869 goto desc_size_fail
;
19870 /* FIXME: Generate an error if descsz > 8 ? */
19873 ((bfd_int64_t
) byte_get ((unsigned char *)pnote
->descdata
, 8));
19877 case NT_VMS_ORIG_DYN
:
19879 goto desc_size_fail
;
19881 printf (_(" Major id: %u, minor id: %u\n"),
19882 (unsigned) byte_get ((unsigned char *)pnote
->descdata
, 4),
19883 (unsigned) byte_get ((unsigned char *)pnote
->descdata
+ 4, 4));
19884 printf (_(" Last modified : "));
19886 ((bfd_int64_t
) byte_get ((unsigned char *)pnote
->descdata
+ 8, 8));
19887 printf (_("\n Link flags : "));
19888 printf ("0x%016" BFD_VMA_FMT
"x\n",
19889 (bfd_vma
) byte_get ((unsigned char *)pnote
->descdata
+ 16, 8));
19890 printf (_(" Header flags: 0x%08x\n"),
19891 (unsigned) byte_get ((unsigned char *)pnote
->descdata
+ 24, 4));
19892 printf (_(" Image id : %.*s\n"), maxlen
- 32, pnote
->descdata
+ 32);
19896 case NT_VMS_IMGNAM
:
19897 printf (_(" Image name: %.*s\n"), maxlen
, pnote
->descdata
);
19900 case NT_VMS_GSTNAM
:
19901 printf (_(" Global symbol table name: %.*s\n"), maxlen
, pnote
->descdata
);
19905 printf (_(" Image id: %.*s\n"), maxlen
, pnote
->descdata
);
19908 case NT_VMS_LINKID
:
19909 printf (_(" Linker id: %.*s\n"), maxlen
, pnote
->descdata
);
19919 printf (_(" <corrupt - data size is too small>\n"));
19920 error (_("corrupt IA64 note: data size is too small\n"));
19924 struct build_attr_cache
{
19925 Filedata
*filedata
;
19927 unsigned long strtablen
;
19928 Elf_Internal_Sym
*symtab
;
19929 unsigned long nsyms
;
19932 /* Find the symbol associated with a build attribute that is attached
19933 to address OFFSET. If PNAME is non-NULL then store the name of
19934 the symbol (if found) in the provided pointer, Returns NULL if a
19935 symbol could not be found. */
19937 static Elf_Internal_Sym
*
19938 get_symbol_for_build_attribute (Filedata
*filedata
,
19939 unsigned long offset
,
19941 const char **pname
)
19943 Elf_Internal_Sym
*saved_sym
= NULL
;
19944 Elf_Internal_Sym
*sym
;
19946 if (filedata
->section_headers
!= NULL
19947 && (ba_cache
.filedata
== NULL
|| filedata
!= ba_cache
.filedata
))
19949 Elf_Internal_Shdr
* symsec
;
19951 free (ba_cache
.strtab
);
19952 ba_cache
.strtab
= NULL
;
19953 free (ba_cache
.symtab
);
19954 ba_cache
.symtab
= NULL
;
19956 /* Load the symbol and string sections. */
19957 for (symsec
= filedata
->section_headers
;
19958 symsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
19961 if (symsec
->sh_type
== SHT_SYMTAB
19962 && get_symtab (filedata
, symsec
,
19963 &ba_cache
.symtab
, &ba_cache
.nsyms
,
19964 &ba_cache
.strtab
, &ba_cache
.strtablen
))
19967 ba_cache
.filedata
= filedata
;
19970 if (ba_cache
.symtab
== NULL
)
19973 /* Find a symbol whose value matches offset. */
19974 for (sym
= ba_cache
.symtab
; sym
< ba_cache
.symtab
+ ba_cache
.nsyms
; sym
++)
19975 if (sym
->st_value
== offset
)
19977 if (sym
->st_name
>= ba_cache
.strtablen
)
19978 /* Huh ? This should not happen. */
19981 if (ba_cache
.strtab
[sym
->st_name
] == 0)
19984 /* The AArch64 and ARM architectures define mapping symbols
19985 (eg $d, $x, $t) which we want to ignore. */
19986 if (ba_cache
.strtab
[sym
->st_name
] == '$'
19987 && ba_cache
.strtab
[sym
->st_name
+ 1] != 0
19988 && ba_cache
.strtab
[sym
->st_name
+ 2] == 0)
19993 /* For OPEN attributes we prefer GLOBAL over LOCAL symbols
19994 and FILE or OBJECT symbols over NOTYPE symbols. We skip
19995 FUNC symbols entirely. */
19996 switch (ELF_ST_TYPE (sym
->st_info
))
20003 /* If the symbol has a size associated
20004 with it then we can stop searching. */
20005 sym
= ba_cache
.symtab
+ ba_cache
.nsyms
;
20010 /* Ignore function symbols. */
20017 switch (ELF_ST_BIND (sym
->st_info
))
20020 if (saved_sym
== NULL
20021 || ELF_ST_TYPE (saved_sym
->st_info
) != STT_OBJECT
)
20026 if (saved_sym
== NULL
)
20036 if (ELF_ST_TYPE (sym
->st_info
) != STT_FUNC
)
20044 if (saved_sym
&& pname
)
20045 * pname
= ba_cache
.strtab
+ saved_sym
->st_name
;
20050 /* Returns true iff addr1 and addr2 are in the same section. */
20053 same_section (Filedata
* filedata
, unsigned long addr1
, unsigned long addr2
)
20055 Elf_Internal_Shdr
* a1
;
20056 Elf_Internal_Shdr
* a2
;
20058 a1
= find_section_by_address (filedata
, addr1
);
20059 a2
= find_section_by_address (filedata
, addr2
);
20061 return a1
== a2
&& a1
!= NULL
;
20065 print_gnu_build_attribute_description (Elf_Internal_Note
* pnote
,
20066 Filedata
* filedata
)
20068 static unsigned long global_offset
= 0;
20069 static unsigned long global_end
= 0;
20070 static unsigned long func_offset
= 0;
20071 static unsigned long func_end
= 0;
20073 Elf_Internal_Sym
*sym
;
20075 unsigned long start
;
20077 bool is_open_attr
= pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_OPEN
;
20079 switch (pnote
->descsz
)
20082 /* A zero-length description means that the range of
20083 the previous note of the same type should be used. */
20086 if (global_end
> global_offset
)
20087 printf (_(" Applies to region from %#lx to %#lx\n"),
20088 global_offset
, global_end
);
20090 printf (_(" Applies to region from %#lx\n"), global_offset
);
20094 if (func_end
> func_offset
)
20095 printf (_(" Applies to region from %#lx to %#lx\n"), func_offset
, func_end
);
20097 printf (_(" Applies to region from %#lx\n"), func_offset
);
20102 start
= byte_get ((unsigned char *) pnote
->descdata
, 4);
20107 start
= byte_get ((unsigned char *) pnote
->descdata
, 4);
20108 end
= byte_get ((unsigned char *) pnote
->descdata
+ 4, 4);
20112 start
= byte_get ((unsigned char *) pnote
->descdata
, 8);
20113 end
= byte_get ((unsigned char *) pnote
->descdata
+ 8, 8);
20117 error (_(" <invalid description size: %lx>\n"), pnote
->descsz
);
20118 printf (_(" <invalid descsz>"));
20123 sym
= get_symbol_for_build_attribute (filedata
, start
, is_open_attr
, & name
);
20124 /* As of version 5 of the annobin plugin, filename symbols are biased by 2
20125 in order to avoid them being confused with the start address of the
20126 first function in the file... */
20127 if (sym
== NULL
&& is_open_attr
)
20128 sym
= get_symbol_for_build_attribute (filedata
, start
+ 2, is_open_attr
,
20131 if (end
== 0 && sym
!= NULL
&& sym
->st_size
> 0)
20132 end
= start
+ sym
->st_size
;
20136 /* FIXME: Need to properly allow for section alignment.
20137 16 is just the alignment used on x86_64. */
20139 && start
> BFD_ALIGN (global_end
, 16)
20140 /* Build notes are not guaranteed to be organised in order of
20141 increasing address, but we should find the all of the notes
20142 for one section in the same place. */
20143 && same_section (filedata
, start
, global_end
))
20144 warn (_("Gap in build notes detected from %#lx to %#lx\n"),
20145 global_end
+ 1, start
- 1);
20147 printf (_(" Applies to region from %#lx"), start
);
20148 global_offset
= start
;
20152 printf (_(" to %#lx"), end
);
20158 printf (_(" Applies to region from %#lx"), start
);
20159 func_offset
= start
;
20163 printf (_(" to %#lx"), end
);
20169 printf (_(" (%s)"), name
);
20176 print_gnu_build_attribute_name (Elf_Internal_Note
* pnote
)
20178 static const char string_expected
[2] = { GNU_BUILD_ATTRIBUTE_TYPE_STRING
, 0 };
20179 static const char number_expected
[2] = { GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC
, 0 };
20180 static const char bool_expected
[3] = { GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE
, GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE
, 0 };
20182 char name_attribute
;
20183 const char * expected_types
;
20184 const char * name
= pnote
->namedata
;
20188 if (name
== NULL
|| pnote
->namesz
< 2)
20190 error (_("corrupt name field in GNU build attribute note: size = %ld\n"), pnote
->namesz
);
20191 print_symbol (-20, _(" <corrupt name>"));
20200 /* Version 2 of the spec adds a "GA" prefix to the name field. */
20201 if (name
[0] == 'G' && name
[1] == 'A')
20203 if (pnote
->namesz
< 4)
20205 error (_("corrupt name field in GNU build attribute note: size = %ld\n"), pnote
->namesz
);
20206 print_symbol (-20, _(" <corrupt name>"));
20215 switch ((name_type
= * name
))
20217 case GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC
:
20218 case GNU_BUILD_ATTRIBUTE_TYPE_STRING
:
20219 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE
:
20220 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE
:
20221 printf ("%c", * name
);
20225 error (_("unrecognised attribute type in name field: %d\n"), name_type
);
20226 print_symbol (-20, _("<unknown name type>"));
20233 switch ((name_attribute
= * name
))
20235 case GNU_BUILD_ATTRIBUTE_VERSION
:
20236 text
= _("<version>");
20237 expected_types
= string_expected
;
20240 case GNU_BUILD_ATTRIBUTE_STACK_PROT
:
20241 text
= _("<stack prot>");
20242 expected_types
= "!+*";
20245 case GNU_BUILD_ATTRIBUTE_RELRO
:
20246 text
= _("<relro>");
20247 expected_types
= bool_expected
;
20250 case GNU_BUILD_ATTRIBUTE_STACK_SIZE
:
20251 text
= _("<stack size>");
20252 expected_types
= number_expected
;
20255 case GNU_BUILD_ATTRIBUTE_TOOL
:
20256 text
= _("<tool>");
20257 expected_types
= string_expected
;
20260 case GNU_BUILD_ATTRIBUTE_ABI
:
20262 expected_types
= "$*";
20265 case GNU_BUILD_ATTRIBUTE_PIC
:
20267 expected_types
= number_expected
;
20270 case GNU_BUILD_ATTRIBUTE_SHORT_ENUM
:
20271 text
= _("<short enum>");
20272 expected_types
= bool_expected
;
20276 if (ISPRINT (* name
))
20278 int len
= strnlen (name
, pnote
->namesz
- (name
- pnote
->namedata
)) + 1;
20280 if (len
> left
&& ! do_wide
)
20282 printf ("%.*s:", len
, name
);
20288 static char tmpbuf
[128];
20290 error (_("unrecognised byte in name field: %d\n"), * name
);
20291 sprintf (tmpbuf
, _("<unknown:_%d>"), * name
);
20295 expected_types
= "*$!+";
20300 left
-= printf ("%s", text
);
20302 if (strchr (expected_types
, name_type
) == NULL
)
20303 warn (_("attribute does not have an expected type (%c)\n"), name_type
);
20305 if ((unsigned long)(name
- pnote
->namedata
) > pnote
->namesz
)
20307 error (_("corrupt name field: namesz: %lu but parsing gets to %ld\n"),
20308 (unsigned long) pnote
->namesz
,
20309 (long) (name
- pnote
->namedata
));
20313 if (left
< 1 && ! do_wide
)
20318 case GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC
:
20320 unsigned int bytes
;
20321 unsigned long long val
= 0;
20322 unsigned int shift
= 0;
20323 char * decoded
= NULL
;
20325 bytes
= pnote
->namesz
- (name
- pnote
->namedata
);
20327 /* The -1 is because the name field is always 0 terminated, and we
20328 want to be able to ensure that the shift in the while loop below
20329 will not overflow. */
20332 if (bytes
> sizeof (val
))
20334 error (_("corrupt numeric name field: too many bytes in the value: %x\n"),
20336 bytes
= sizeof (val
);
20338 /* We do not bother to warn if bytes == 0 as this can
20339 happen with some early versions of the gcc plugin. */
20343 unsigned long long byte
= *name
++ & 0xff;
20345 val
|= byte
<< shift
;
20349 switch (name_attribute
)
20351 case GNU_BUILD_ATTRIBUTE_PIC
:
20354 case 0: decoded
= "static"; break;
20355 case 1: decoded
= "pic"; break;
20356 case 2: decoded
= "PIC"; break;
20357 case 3: decoded
= "pie"; break;
20358 case 4: decoded
= "PIE"; break;
20362 case GNU_BUILD_ATTRIBUTE_STACK_PROT
:
20365 /* Based upon the SPCT_FLAG_xxx enum values in gcc/cfgexpand.c. */
20366 case 0: decoded
= "off"; break;
20367 case 1: decoded
= "on"; break;
20368 case 2: decoded
= "all"; break;
20369 case 3: decoded
= "strong"; break;
20370 case 4: decoded
= "explicit"; break;
20378 if (decoded
!= NULL
)
20380 print_symbol (-left
, decoded
);
20391 left
-= printf ("0x%llx", val
);
20393 left
-= printf ("0x%-.*llx", left
, val
);
20397 case GNU_BUILD_ATTRIBUTE_TYPE_STRING
:
20398 left
-= print_symbol (- left
, name
);
20400 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE
:
20401 left
-= print_symbol (- left
, "true");
20403 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE
:
20404 left
-= print_symbol (- left
, "false");
20408 if (do_wide
&& left
> 0)
20409 printf ("%-*s", left
, " ");
20414 /* Note that by the ELF standard, the name field is already null byte
20415 terminated, and namesz includes the terminating null byte.
20416 I.E. the value of namesz for the name "FSF" is 4.
20418 If the value of namesz is zero, there is no name present. */
20421 process_note (Elf_Internal_Note
* pnote
,
20422 Filedata
* filedata
)
20424 const char * name
= pnote
->namesz
? pnote
->namedata
: "(NONE)";
20427 if (pnote
->namesz
== 0)
20428 /* If there is no note name, then use the default set of
20429 note type strings. */
20430 nt
= get_note_type (filedata
, pnote
->type
);
20432 else if (const_strneq (pnote
->namedata
, "GNU"))
20433 /* GNU-specific object file notes. */
20434 nt
= get_gnu_elf_note_type (pnote
->type
);
20436 else if (const_strneq (pnote
->namedata
, "FreeBSD"))
20437 /* FreeBSD-specific core file notes. */
20438 nt
= get_freebsd_elfcore_note_type (filedata
, pnote
->type
);
20440 else if (const_strneq (pnote
->namedata
, "NetBSD-CORE"))
20441 /* NetBSD-specific core file notes. */
20442 nt
= get_netbsd_elfcore_note_type (filedata
, pnote
->type
);
20444 else if (const_strneq (pnote
->namedata
, "NetBSD"))
20445 /* NetBSD-specific core file notes. */
20446 return process_netbsd_elf_note (pnote
);
20448 else if (const_strneq (pnote
->namedata
, "PaX"))
20449 /* NetBSD-specific core file notes. */
20450 return process_netbsd_elf_note (pnote
);
20452 else if (strneq (pnote
->namedata
, "SPU/", 4))
20454 /* SPU-specific core file notes. */
20455 nt
= pnote
->namedata
+ 4;
20459 else if (const_strneq (pnote
->namedata
, "IPF/VMS"))
20460 /* VMS/ia64-specific file notes. */
20461 nt
= get_ia64_vms_note_type (pnote
->type
);
20463 else if (const_strneq (pnote
->namedata
, "stapsdt"))
20464 nt
= get_stapsdt_note_type (pnote
->type
);
20467 /* Don't recognize this note name; just use the default set of
20468 note type strings. */
20469 nt
= get_note_type (filedata
, pnote
->type
);
20473 if (((const_strneq (pnote
->namedata
, "GA")
20474 && strchr ("*$!+", pnote
->namedata
[2]) != NULL
)
20475 || strchr ("*$!+", pnote
->namedata
[0]) != NULL
)
20476 && (pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_OPEN
20477 || pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_FUNC
))
20478 print_gnu_build_attribute_name (pnote
);
20480 print_symbol (-20, name
);
20483 printf (" 0x%08lx\t%s\t", pnote
->descsz
, nt
);
20485 printf (" 0x%08lx\t%s\n", pnote
->descsz
, nt
);
20487 if (const_strneq (pnote
->namedata
, "IPF/VMS"))
20488 return print_ia64_vms_note (pnote
);
20489 else if (const_strneq (pnote
->namedata
, "GNU"))
20490 return print_gnu_note (filedata
, pnote
);
20491 else if (const_strneq (pnote
->namedata
, "stapsdt"))
20492 return print_stapsdt_note (pnote
);
20493 else if (const_strneq (pnote
->namedata
, "CORE"))
20494 return print_core_note (pnote
);
20495 else if (((const_strneq (pnote
->namedata
, "GA")
20496 && strchr ("*$!+", pnote
->namedata
[2]) != NULL
)
20497 || strchr ("*$!+", pnote
->namedata
[0]) != NULL
)
20498 && (pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_OPEN
20499 || pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_FUNC
))
20500 return print_gnu_build_attribute_description (pnote
, filedata
);
20506 printf (_(" description data: "));
20507 for (i
= 0; i
< pnote
->descsz
; i
++)
20508 printf ("%02x ", pnote
->descdata
[i
] & 0xff);
20520 process_notes_at (Filedata
* filedata
,
20521 Elf_Internal_Shdr
* section
,
20526 Elf_External_Note
*pnotes
;
20527 Elf_External_Note
*external
;
20536 pnotes
= (Elf_External_Note
*) get_section_contents (section
, filedata
);
20539 if (! apply_relocations (filedata
, section
, (unsigned char *) pnotes
, length
, NULL
, NULL
))
20547 pnotes
= (Elf_External_Note
*) get_data (NULL
, filedata
, offset
, 1, length
,
20550 if (pnotes
== NULL
)
20555 if (filedata
->is_separate
)
20556 printf (_("In linked file '%s': "), filedata
->file_name
);
20560 printf (_("Displaying notes found in: %s\n"), printable_section_name (filedata
, section
));
20562 printf (_("Displaying notes found at file offset 0x%08lx with length 0x%08lx:\n"),
20563 (unsigned long) offset
, (unsigned long) length
);
20565 /* NB: Some note sections may have alignment value of 0 or 1. gABI
20566 specifies that notes should be aligned to 4 bytes in 32-bit
20567 objects and to 8 bytes in 64-bit objects. As a Linux extension,
20568 we also support 4 byte alignment in 64-bit objects. If section
20569 alignment is less than 4, we treate alignment as 4 bytes. */
20572 else if (align
!= 4 && align
!= 8)
20574 warn (_("Corrupt note: alignment %ld, expecting 4 or 8\n"),
20580 printf (_(" %-20s %-10s\tDescription\n"), _("Owner"), _("Data size"));
20582 end
= (char *) pnotes
+ length
;
20583 while ((char *) external
< end
)
20585 Elf_Internal_Note inote
;
20588 char * temp
= NULL
;
20589 size_t data_remaining
= end
- (char *) external
;
20591 if (!is_ia64_vms (filedata
))
20593 /* PR binutils/15191
20594 Make sure that there is enough data to read. */
20595 min_notesz
= offsetof (Elf_External_Note
, name
);
20596 if (data_remaining
< min_notesz
)
20598 warn (ngettext ("Corrupt note: only %ld byte remains, "
20599 "not enough for a full note\n",
20600 "Corrupt note: only %ld bytes remain, "
20601 "not enough for a full note\n",
20603 (long) data_remaining
);
20606 data_remaining
-= min_notesz
;
20608 inote
.type
= BYTE_GET (external
->type
);
20609 inote
.namesz
= BYTE_GET (external
->namesz
);
20610 inote
.namedata
= external
->name
;
20611 inote
.descsz
= BYTE_GET (external
->descsz
);
20612 inote
.descdata
= ((char *) external
20613 + ELF_NOTE_DESC_OFFSET (inote
.namesz
, align
));
20614 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
20615 next
= ((char *) external
20616 + ELF_NOTE_NEXT_OFFSET (inote
.namesz
, inote
.descsz
, align
));
20620 Elf64_External_VMS_Note
*vms_external
;
20622 /* PR binutils/15191
20623 Make sure that there is enough data to read. */
20624 min_notesz
= offsetof (Elf64_External_VMS_Note
, name
);
20625 if (data_remaining
< min_notesz
)
20627 warn (ngettext ("Corrupt note: only %ld byte remains, "
20628 "not enough for a full note\n",
20629 "Corrupt note: only %ld bytes remain, "
20630 "not enough for a full note\n",
20632 (long) data_remaining
);
20635 data_remaining
-= min_notesz
;
20637 vms_external
= (Elf64_External_VMS_Note
*) external
;
20638 inote
.type
= BYTE_GET (vms_external
->type
);
20639 inote
.namesz
= BYTE_GET (vms_external
->namesz
);
20640 inote
.namedata
= vms_external
->name
;
20641 inote
.descsz
= BYTE_GET (vms_external
->descsz
);
20642 inote
.descdata
= inote
.namedata
+ align_power (inote
.namesz
, 3);
20643 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
20644 next
= inote
.descdata
+ align_power (inote
.descsz
, 3);
20647 /* PR 17531: file: 3443835e. */
20648 /* PR 17531: file: id:000000,sig:11,src:006986,op:havoc,rep:4. */
20649 if ((size_t) (inote
.descdata
- inote
.namedata
) < inote
.namesz
20650 || (size_t) (inote
.descdata
- inote
.namedata
) > data_remaining
20651 || (size_t) (next
- inote
.descdata
) < inote
.descsz
20652 || ((size_t) (next
- inote
.descdata
)
20653 > data_remaining
- (size_t) (inote
.descdata
- inote
.namedata
)))
20655 warn (_("note with invalid namesz and/or descsz found at offset 0x%lx\n"),
20656 (unsigned long) ((char *) external
- (char *) pnotes
));
20657 warn (_(" type: 0x%lx, namesize: 0x%08lx, descsize: 0x%08lx, alignment: %u\n"),
20658 inote
.type
, inote
.namesz
, inote
.descsz
, (int) align
);
20662 external
= (Elf_External_Note
*) next
;
20664 /* Verify that name is null terminated. It appears that at least
20665 one version of Linux (RedHat 6.0) generates corefiles that don't
20666 comply with the ELF spec by failing to include the null byte in
20668 if (inote
.namesz
> 0 && inote
.namedata
[inote
.namesz
- 1] != '\0')
20670 if ((size_t) (inote
.descdata
- inote
.namedata
) == inote
.namesz
)
20672 temp
= (char *) malloc (inote
.namesz
+ 1);
20675 error (_("Out of memory allocating space for inote name\n"));
20680 memcpy (temp
, inote
.namedata
, inote
.namesz
);
20681 inote
.namedata
= temp
;
20683 inote
.namedata
[inote
.namesz
] = 0;
20686 if (! process_note (& inote
, filedata
))
20699 process_corefile_note_segments (Filedata
* filedata
)
20701 Elf_Internal_Phdr
*segment
;
20705 if (! get_program_headers (filedata
))
20708 for (i
= 0, segment
= filedata
->program_headers
;
20709 i
< filedata
->file_header
.e_phnum
;
20712 if (segment
->p_type
== PT_NOTE
)
20713 if (! process_notes_at (filedata
, NULL
,
20714 (bfd_vma
) segment
->p_offset
,
20715 (bfd_vma
) segment
->p_filesz
,
20716 (bfd_vma
) segment
->p_align
))
20724 process_v850_notes (Filedata
* filedata
, bfd_vma offset
, bfd_vma length
)
20726 Elf_External_Note
* pnotes
;
20727 Elf_External_Note
* external
;
20734 pnotes
= (Elf_External_Note
*) get_data (NULL
, filedata
, offset
, 1, length
,
20736 if (pnotes
== NULL
)
20740 end
= (char*) pnotes
+ length
;
20742 printf (_("\nDisplaying contents of Renesas V850 notes section at offset 0x%lx with length 0x%lx:\n"),
20743 (unsigned long) offset
, (unsigned long) length
);
20745 while ((char *) external
+ sizeof (Elf_External_Note
) < end
)
20747 Elf_External_Note
* next
;
20748 Elf_Internal_Note inote
;
20750 inote
.type
= BYTE_GET (external
->type
);
20751 inote
.namesz
= BYTE_GET (external
->namesz
);
20752 inote
.namedata
= external
->name
;
20753 inote
.descsz
= BYTE_GET (external
->descsz
);
20754 inote
.descdata
= inote
.namedata
+ align_power (inote
.namesz
, 2);
20755 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
20757 if (inote
.descdata
< (char *) pnotes
|| inote
.descdata
>= end
)
20759 warn (_("Corrupt note: name size is too big: %lx\n"), inote
.namesz
);
20760 inote
.descdata
= inote
.namedata
;
20764 next
= (Elf_External_Note
*) (inote
.descdata
+ align_power (inote
.descsz
, 2));
20766 if ( ((char *) next
> end
)
20767 || ((char *) next
< (char *) pnotes
))
20769 warn (_("corrupt descsz found in note at offset 0x%lx\n"),
20770 (unsigned long) ((char *) external
- (char *) pnotes
));
20771 warn (_(" type: 0x%lx, namesize: 0x%lx, descsize: 0x%lx\n"),
20772 inote
.type
, inote
.namesz
, inote
.descsz
);
20778 /* Prevent out-of-bounds indexing. */
20779 if ( inote
.namedata
+ inote
.namesz
> end
20780 || inote
.namedata
+ inote
.namesz
< inote
.namedata
)
20782 warn (_("corrupt namesz found in note at offset 0x%lx\n"),
20783 (unsigned long) ((char *) external
- (char *) pnotes
));
20784 warn (_(" type: 0x%lx, namesize: 0x%lx, descsize: 0x%lx\n"),
20785 inote
.type
, inote
.namesz
, inote
.descsz
);
20789 printf (" %s: ", get_v850_elf_note_type (inote
.type
));
20791 if (! print_v850_note (& inote
))
20794 printf ("<corrupt sizes: namesz: %lx, descsz: %lx>\n",
20795 inote
.namesz
, inote
.descsz
);
20805 process_note_sections (Filedata
* filedata
)
20807 Elf_Internal_Shdr
*section
;
20809 unsigned int n
= 0;
20812 for (i
= 0, section
= filedata
->section_headers
;
20813 i
< filedata
->file_header
.e_shnum
&& section
!= NULL
;
20816 if (section
->sh_type
== SHT_NOTE
)
20818 if (! process_notes_at (filedata
, section
,
20819 (bfd_vma
) section
->sh_offset
,
20820 (bfd_vma
) section
->sh_size
,
20821 (bfd_vma
) section
->sh_addralign
))
20826 if (( filedata
->file_header
.e_machine
== EM_V800
20827 || filedata
->file_header
.e_machine
== EM_V850
20828 || filedata
->file_header
.e_machine
== EM_CYGNUS_V850
)
20829 && section
->sh_type
== SHT_RENESAS_INFO
)
20831 if (! process_v850_notes (filedata
,
20832 (bfd_vma
) section
->sh_offset
,
20833 (bfd_vma
) section
->sh_size
))
20840 /* Try processing NOTE segments instead. */
20841 return process_corefile_note_segments (filedata
);
20847 process_notes (Filedata
* filedata
)
20849 /* If we have not been asked to display the notes then do nothing. */
20853 if (filedata
->file_header
.e_type
!= ET_CORE
)
20854 return process_note_sections (filedata
);
20856 /* No program headers means no NOTE segment. */
20857 if (filedata
->file_header
.e_phnum
> 0)
20858 return process_corefile_note_segments (filedata
);
20860 if (filedata
->is_separate
)
20861 printf (_("No notes found in linked file '%s'.\n"),
20862 filedata
->file_name
);
20864 printf (_("No notes found file.\n"));
20869 static unsigned char *
20870 display_public_gnu_attributes (unsigned char * start
,
20871 const unsigned char * const end
)
20873 printf (_(" Unknown GNU attribute: %s\n"), start
);
20875 start
+= strnlen ((char *) start
, end
- start
);
20876 display_raw_attribute (start
, end
);
20878 return (unsigned char *) end
;
20881 static unsigned char *
20882 display_generic_attribute (unsigned char * start
,
20884 const unsigned char * const end
)
20887 return (unsigned char *) end
;
20889 return display_tag_value (tag
, start
, end
);
20893 process_arch_specific (Filedata
* filedata
)
20898 switch (filedata
->file_header
.e_machine
)
20901 case EM_ARC_COMPACT
:
20902 case EM_ARC_COMPACT2
:
20903 return process_attributes (filedata
, "ARC", SHT_ARC_ATTRIBUTES
,
20904 display_arc_attribute
,
20905 display_generic_attribute
);
20907 return process_attributes (filedata
, "aeabi", SHT_ARM_ATTRIBUTES
,
20908 display_arm_attribute
,
20909 display_generic_attribute
);
20912 case EM_MIPS_RS3_LE
:
20913 return process_mips_specific (filedata
);
20916 return process_attributes (filedata
, "mspabi", SHT_MSP430_ATTRIBUTES
,
20917 display_msp430_attribute
,
20918 display_msp430_gnu_attribute
);
20921 return process_attributes (filedata
, "riscv", SHT_RISCV_ATTRIBUTES
,
20922 display_riscv_attribute
,
20923 display_generic_attribute
);
20926 return process_nds32_specific (filedata
);
20929 return process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
20930 display_m68k_gnu_attribute
);
20934 return process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
20935 display_power_gnu_attribute
);
20939 return process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
20940 display_s390_gnu_attribute
);
20943 case EM_SPARC32PLUS
:
20945 return process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
20946 display_sparc_gnu_attribute
);
20949 return process_attributes (filedata
, "c6xabi", SHT_C6000_ATTRIBUTES
,
20950 display_tic6x_attribute
,
20951 display_generic_attribute
);
20954 return process_attributes (filedata
, "csky", SHT_CSKY_ATTRIBUTES
,
20955 display_csky_attribute
, NULL
);
20958 return process_attributes (filedata
, "gnu", SHT_GNU_ATTRIBUTES
,
20959 display_public_gnu_attributes
,
20960 display_generic_attribute
);
20965 get_file_header (Filedata
* filedata
)
20967 /* Read in the identity array. */
20968 if (fread (filedata
->file_header
.e_ident
, EI_NIDENT
, 1, filedata
->handle
) != 1)
20971 /* Determine how to read the rest of the header. */
20972 switch (filedata
->file_header
.e_ident
[EI_DATA
])
20977 byte_get
= byte_get_little_endian
;
20978 byte_put
= byte_put_little_endian
;
20981 byte_get
= byte_get_big_endian
;
20982 byte_put
= byte_put_big_endian
;
20986 /* For now we only support 32 bit and 64 bit ELF files. */
20987 is_32bit_elf
= (filedata
->file_header
.e_ident
[EI_CLASS
] != ELFCLASS64
);
20989 /* Read in the rest of the header. */
20992 Elf32_External_Ehdr ehdr32
;
20994 if (fread (ehdr32
.e_type
, sizeof (ehdr32
) - EI_NIDENT
, 1, filedata
->handle
) != 1)
20997 filedata
->file_header
.e_type
= BYTE_GET (ehdr32
.e_type
);
20998 filedata
->file_header
.e_machine
= BYTE_GET (ehdr32
.e_machine
);
20999 filedata
->file_header
.e_version
= BYTE_GET (ehdr32
.e_version
);
21000 filedata
->file_header
.e_entry
= BYTE_GET (ehdr32
.e_entry
);
21001 filedata
->file_header
.e_phoff
= BYTE_GET (ehdr32
.e_phoff
);
21002 filedata
->file_header
.e_shoff
= BYTE_GET (ehdr32
.e_shoff
);
21003 filedata
->file_header
.e_flags
= BYTE_GET (ehdr32
.e_flags
);
21004 filedata
->file_header
.e_ehsize
= BYTE_GET (ehdr32
.e_ehsize
);
21005 filedata
->file_header
.e_phentsize
= BYTE_GET (ehdr32
.e_phentsize
);
21006 filedata
->file_header
.e_phnum
= BYTE_GET (ehdr32
.e_phnum
);
21007 filedata
->file_header
.e_shentsize
= BYTE_GET (ehdr32
.e_shentsize
);
21008 filedata
->file_header
.e_shnum
= BYTE_GET (ehdr32
.e_shnum
);
21009 filedata
->file_header
.e_shstrndx
= BYTE_GET (ehdr32
.e_shstrndx
);
21013 Elf64_External_Ehdr ehdr64
;
21015 /* If we have been compiled with sizeof (bfd_vma) == 4, then
21016 we will not be able to cope with the 64bit data found in
21017 64 ELF files. Detect this now and abort before we start
21018 overwriting things. */
21019 if (sizeof (bfd_vma
) < 8)
21021 error (_("This instance of readelf has been built without support for a\n\
21022 64 bit data type and so it cannot read 64 bit ELF files.\n"));
21026 if (fread (ehdr64
.e_type
, sizeof (ehdr64
) - EI_NIDENT
, 1, filedata
->handle
) != 1)
21029 filedata
->file_header
.e_type
= BYTE_GET (ehdr64
.e_type
);
21030 filedata
->file_header
.e_machine
= BYTE_GET (ehdr64
.e_machine
);
21031 filedata
->file_header
.e_version
= BYTE_GET (ehdr64
.e_version
);
21032 filedata
->file_header
.e_entry
= BYTE_GET (ehdr64
.e_entry
);
21033 filedata
->file_header
.e_phoff
= BYTE_GET (ehdr64
.e_phoff
);
21034 filedata
->file_header
.e_shoff
= BYTE_GET (ehdr64
.e_shoff
);
21035 filedata
->file_header
.e_flags
= BYTE_GET (ehdr64
.e_flags
);
21036 filedata
->file_header
.e_ehsize
= BYTE_GET (ehdr64
.e_ehsize
);
21037 filedata
->file_header
.e_phentsize
= BYTE_GET (ehdr64
.e_phentsize
);
21038 filedata
->file_header
.e_phnum
= BYTE_GET (ehdr64
.e_phnum
);
21039 filedata
->file_header
.e_shentsize
= BYTE_GET (ehdr64
.e_shentsize
);
21040 filedata
->file_header
.e_shnum
= BYTE_GET (ehdr64
.e_shnum
);
21041 filedata
->file_header
.e_shstrndx
= BYTE_GET (ehdr64
.e_shstrndx
);
21044 if (filedata
->file_header
.e_shoff
)
21046 /* There may be some extensions in the first section header. Don't
21047 bomb if we can't read it. */
21049 get_32bit_section_headers (filedata
, true);
21051 get_64bit_section_headers (filedata
, true);
21058 close_file (Filedata
* filedata
)
21062 if (filedata
->handle
)
21063 fclose (filedata
->handle
);
21069 close_debug_file (void * data
)
21071 close_file ((Filedata
*) data
);
21075 open_file (const char * pathname
, bool is_separate
)
21077 struct stat statbuf
;
21078 Filedata
* filedata
= NULL
;
21080 if (stat (pathname
, & statbuf
) < 0
21081 || ! S_ISREG (statbuf
.st_mode
))
21084 filedata
= calloc (1, sizeof * filedata
);
21085 if (filedata
== NULL
)
21088 filedata
->handle
= fopen (pathname
, "rb");
21089 if (filedata
->handle
== NULL
)
21092 filedata
->file_size
= (bfd_size_type
) statbuf
.st_size
;
21093 filedata
->file_name
= pathname
;
21094 filedata
->is_separate
= is_separate
;
21096 if (! get_file_header (filedata
))
21099 if (filedata
->file_header
.e_shoff
)
21103 /* Read the section headers again, this time for real. */
21105 res
= get_32bit_section_headers (filedata
, false);
21107 res
= get_64bit_section_headers (filedata
, false);
21118 if (filedata
->handle
)
21119 fclose (filedata
->handle
);
21126 open_debug_file (const char * pathname
)
21128 return open_file (pathname
, true);
21132 initialise_dump_sects (Filedata
* filedata
)
21134 /* Initialise the dump_sects array from the cmdline_dump_sects array.
21135 Note we do this even if cmdline_dump_sects is empty because we
21136 must make sure that the dump_sets array is zeroed out before each
21137 object file is processed. */
21138 if (filedata
->dump
.num_dump_sects
> cmdline
.num_dump_sects
)
21139 memset (filedata
->dump
.dump_sects
, 0,
21140 filedata
->dump
.num_dump_sects
* sizeof (*filedata
->dump
.dump_sects
));
21142 if (cmdline
.num_dump_sects
> 0)
21144 if (filedata
->dump
.num_dump_sects
== 0)
21145 /* A sneaky way of allocating the dump_sects array. */
21146 request_dump_bynumber (&filedata
->dump
, cmdline
.num_dump_sects
, 0);
21148 assert (filedata
->dump
.num_dump_sects
>= cmdline
.num_dump_sects
);
21149 memcpy (filedata
->dump
.dump_sects
, cmdline
.dump_sects
,
21150 cmdline
.num_dump_sects
* sizeof (*filedata
->dump
.dump_sects
));
21154 /* Process one ELF object file according to the command line options.
21155 This file may actually be stored in an archive. The file is
21156 positioned at the start of the ELF object. Returns TRUE if no
21157 problems were encountered, FALSE otherwise. */
21160 process_object (Filedata
* filedata
)
21162 bool have_separate_files
;
21166 if (! get_file_header (filedata
))
21168 error (_("%s: Failed to read file header\n"), filedata
->file_name
);
21172 /* Initialise per file variables. */
21173 for (i
= ARRAY_SIZE (filedata
->version_info
); i
--;)
21174 filedata
->version_info
[i
] = 0;
21176 for (i
= ARRAY_SIZE (filedata
->dynamic_info
); i
--;)
21177 filedata
->dynamic_info
[i
] = 0;
21178 filedata
->dynamic_info_DT_GNU_HASH
= 0;
21179 filedata
->dynamic_info_DT_MIPS_XHASH
= 0;
21181 /* Process the file. */
21183 printf (_("\nFile: %s\n"), filedata
->file_name
);
21185 initialise_dump_sects (filedata
);
21187 if (! process_file_header (filedata
))
21190 if (! process_section_headers (filedata
))
21192 /* Without loaded section headers we cannot process lots of things. */
21193 do_unwind
= do_version
= do_dump
= do_arch
= false;
21195 if (! do_using_dynamic
)
21196 do_syms
= do_dyn_syms
= do_reloc
= false;
21199 if (! process_section_groups (filedata
))
21200 /* Without loaded section groups we cannot process unwind. */
21203 res
= process_program_headers (filedata
);
21205 res
= process_dynamic_section (filedata
);
21207 if (! process_relocs (filedata
))
21210 if (! process_unwind (filedata
))
21213 if (! process_symbol_table (filedata
))
21216 if (! process_lto_symbol_tables (filedata
))
21219 if (! process_syminfo (filedata
))
21222 if (! process_version_sections (filedata
))
21225 if (filedata
->file_header
.e_shstrndx
!= SHN_UNDEF
)
21226 have_separate_files
= load_separate_debug_files (filedata
, filedata
->file_name
);
21228 have_separate_files
= false;
21230 if (! process_section_contents (filedata
))
21233 if (have_separate_files
)
21237 for (d
= first_separate_info
; d
!= NULL
; d
= d
->next
)
21239 initialise_dump_sects (d
->handle
);
21241 if (process_links
&& ! process_file_header (d
->handle
))
21243 else if (! process_section_headers (d
->handle
))
21245 else if (! process_section_contents (d
->handle
))
21247 else if (process_links
)
21249 if (! process_section_groups (d
->handle
))
21251 if (! process_program_headers (d
->handle
))
21253 if (! process_dynamic_section (d
->handle
))
21255 if (! process_relocs (d
->handle
))
21257 if (! process_unwind (d
->handle
))
21259 if (! process_symbol_table (d
->handle
))
21261 if (! process_lto_symbol_tables (d
->handle
))
21263 if (! process_syminfo (d
->handle
))
21265 if (! process_version_sections (d
->handle
))
21267 if (! process_notes (d
->handle
))
21272 /* The file handles are closed by the call to free_debug_memory() below. */
21275 if (! process_notes (filedata
))
21278 if (! process_gnu_liblist (filedata
))
21281 if (! process_arch_specific (filedata
))
21284 free (filedata
->program_headers
);
21285 filedata
->program_headers
= NULL
;
21287 free (filedata
->section_headers
);
21288 filedata
->section_headers
= NULL
;
21290 free (filedata
->string_table
);
21291 filedata
->string_table
= NULL
;
21292 filedata
->string_table_length
= 0;
21294 free (filedata
->dump
.dump_sects
);
21295 filedata
->dump
.dump_sects
= NULL
;
21296 filedata
->dump
.num_dump_sects
= 0;
21298 free (filedata
->dynamic_strings
);
21299 filedata
->dynamic_strings
= NULL
;
21300 filedata
->dynamic_strings_length
= 0;
21302 free (filedata
->dynamic_symbols
);
21303 filedata
->dynamic_symbols
= NULL
;
21304 filedata
->num_dynamic_syms
= 0;
21306 free (filedata
->dynamic_syminfo
);
21307 filedata
->dynamic_syminfo
= NULL
;
21309 free (filedata
->dynamic_section
);
21310 filedata
->dynamic_section
= NULL
;
21312 while (filedata
->symtab_shndx_list
!= NULL
)
21314 elf_section_list
*next
= filedata
->symtab_shndx_list
->next
;
21315 free (filedata
->symtab_shndx_list
);
21316 filedata
->symtab_shndx_list
= next
;
21319 free (filedata
->section_headers_groups
);
21320 filedata
->section_headers_groups
= NULL
;
21322 if (filedata
->section_groups
)
21324 struct group_list
* g
;
21325 struct group_list
* next
;
21327 for (i
= 0; i
< filedata
->group_count
; i
++)
21329 for (g
= filedata
->section_groups
[i
].root
; g
!= NULL
; g
= next
)
21336 free (filedata
->section_groups
);
21337 filedata
->section_groups
= NULL
;
21340 free_debug_memory ();
21345 /* Process an ELF archive.
21346 On entry the file is positioned just after the ARMAG string.
21347 Returns TRUE upon success, FALSE otherwise. */
21350 process_archive (Filedata
* filedata
, bool is_thin_archive
)
21352 struct archive_info arch
;
21353 struct archive_info nested_arch
;
21359 /* The ARCH structure is used to hold information about this archive. */
21360 arch
.file_name
= NULL
;
21362 arch
.index_array
= NULL
;
21363 arch
.sym_table
= NULL
;
21364 arch
.longnames
= NULL
;
21366 /* The NESTED_ARCH structure is used as a single-item cache of information
21367 about a nested archive (when members of a thin archive reside within
21368 another regular archive file). */
21369 nested_arch
.file_name
= NULL
;
21370 nested_arch
.file
= NULL
;
21371 nested_arch
.index_array
= NULL
;
21372 nested_arch
.sym_table
= NULL
;
21373 nested_arch
.longnames
= NULL
;
21375 if (setup_archive (&arch
, filedata
->file_name
, filedata
->handle
,
21376 filedata
->file_size
, is_thin_archive
,
21377 do_archive_index
) != 0)
21383 if (do_archive_index
)
21385 if (arch
.sym_table
== NULL
)
21386 error (_("%s: unable to dump the index as none was found\n"),
21387 filedata
->file_name
);
21390 unsigned long i
, l
;
21391 unsigned long current_pos
;
21393 printf (_("Index of archive %s: (%lu entries, 0x%lx bytes "
21394 "in the symbol table)\n"),
21395 filedata
->file_name
, (unsigned long) arch
.index_num
,
21398 current_pos
= ftell (filedata
->handle
);
21400 for (i
= l
= 0; i
< arch
.index_num
; i
++)
21403 || (i
> 0 && arch
.index_array
[i
] != arch
.index_array
[i
- 1]))
21406 = get_archive_member_name_at (&arch
, arch
.index_array
[i
],
21409 if (member_name
!= NULL
)
21411 char * qualified_name
21412 = make_qualified_name (&arch
, &nested_arch
,
21415 if (qualified_name
!= NULL
)
21417 printf (_("Contents of binary %s at offset "),
21419 (void) print_vma (arch
.index_array
[i
], PREFIX_HEX
);
21421 free (qualified_name
);
21423 free (member_name
);
21427 if (l
>= arch
.sym_size
)
21429 error (_("%s: end of the symbol table reached "
21430 "before the end of the index\n"),
21431 filedata
->file_name
);
21435 /* PR 17531: file: 0b6630b2. */
21436 printf ("\t%.*s\n",
21437 (int) (arch
.sym_size
- l
), arch
.sym_table
+ l
);
21438 l
+= strnlen (arch
.sym_table
+ l
, arch
.sym_size
- l
) + 1;
21441 if (arch
.uses_64bit_indices
)
21446 if (l
< arch
.sym_size
)
21448 error (ngettext ("%s: %ld byte remains in the symbol table, "
21449 "but without corresponding entries in "
21450 "the index table\n",
21451 "%s: %ld bytes remain in the symbol table, "
21452 "but without corresponding entries in "
21453 "the index table\n",
21454 arch
.sym_size
- l
),
21455 filedata
->file_name
, arch
.sym_size
- l
);
21459 if (fseek (filedata
->handle
, current_pos
, SEEK_SET
) != 0)
21461 error (_("%s: failed to seek back to start of object files "
21462 "in the archive\n"),
21463 filedata
->file_name
);
21469 if (!do_dynamic
&& !do_syms
&& !do_reloc
&& !do_unwind
&& !do_sections
21470 && !do_segments
&& !do_header
&& !do_dump
&& !do_version
21471 && !do_histogram
&& !do_debugging
&& !do_arch
&& !do_notes
21472 && !do_section_groups
&& !do_dyn_syms
)
21474 ret
= true; /* Archive index only. */
21483 char * qualified_name
;
21485 /* Read the next archive header. */
21486 if (fseek (filedata
->handle
, arch
.next_arhdr_offset
, SEEK_SET
) != 0)
21488 error (_("%s: failed to seek to next archive header\n"),
21493 got
= fread (&arch
.arhdr
, 1, sizeof arch
.arhdr
, filedata
->handle
);
21494 if (got
!= sizeof arch
.arhdr
)
21498 /* PR 24049 - we cannot use filedata->file_name as this will
21499 have already been freed. */
21500 error (_("%s: failed to read archive header\n"), arch
.file_name
);
21505 if (memcmp (arch
.arhdr
.ar_fmag
, ARFMAG
, 2) != 0)
21507 error (_("%s: did not find a valid archive header\n"),
21513 arch
.next_arhdr_offset
+= sizeof arch
.arhdr
;
21515 filedata
->archive_file_size
= strtoul (arch
.arhdr
.ar_size
, NULL
, 10);
21516 if (filedata
->archive_file_size
& 01)
21517 ++filedata
->archive_file_size
;
21519 name
= get_archive_member_name (&arch
, &nested_arch
);
21522 error (_("%s: bad archive file name\n"), arch
.file_name
);
21526 namelen
= strlen (name
);
21528 qualified_name
= make_qualified_name (&arch
, &nested_arch
, name
);
21529 if (qualified_name
== NULL
)
21531 error (_("%s: bad archive file name\n"), arch
.file_name
);
21537 if (is_thin_archive
&& arch
.nested_member_origin
== 0)
21539 /* This is a proxy for an external member of a thin archive. */
21540 Filedata
* member_filedata
;
21541 char * member_file_name
= adjust_relative_path
21542 (filedata
->file_name
, name
, namelen
);
21545 if (member_file_name
== NULL
)
21547 free (qualified_name
);
21552 member_filedata
= open_file (member_file_name
, false);
21553 if (member_filedata
== NULL
)
21555 error (_("Input file '%s' is not readable.\n"), member_file_name
);
21556 free (member_file_name
);
21557 free (qualified_name
);
21562 filedata
->archive_file_offset
= arch
.nested_member_origin
;
21563 member_filedata
->file_name
= qualified_name
;
21565 if (! process_object (member_filedata
))
21568 close_file (member_filedata
);
21569 free (member_file_name
);
21571 else if (is_thin_archive
)
21573 Filedata thin_filedata
;
21575 memset (&thin_filedata
, 0, sizeof (thin_filedata
));
21577 /* PR 15140: Allow for corrupt thin archives. */
21578 if (nested_arch
.file
== NULL
)
21580 error (_("%s: contains corrupt thin archive: %s\n"),
21581 qualified_name
, name
);
21582 free (qualified_name
);
21589 /* This is a proxy for a member of a nested archive. */
21590 filedata
->archive_file_offset
21591 = arch
.nested_member_origin
+ sizeof arch
.arhdr
;
21593 /* The nested archive file will have been opened and setup by
21594 get_archive_member_name. */
21595 if (fseek (nested_arch
.file
, filedata
->archive_file_offset
,
21598 error (_("%s: failed to seek to archive member.\n"),
21599 nested_arch
.file_name
);
21600 free (qualified_name
);
21605 thin_filedata
.handle
= nested_arch
.file
;
21606 thin_filedata
.file_name
= qualified_name
;
21608 if (! process_object (& thin_filedata
))
21614 filedata
->archive_file_offset
= arch
.next_arhdr_offset
;
21615 filedata
->file_name
= qualified_name
;
21616 if (! process_object (filedata
))
21618 arch
.next_arhdr_offset
+= filedata
->archive_file_size
;
21619 /* Stop looping with "negative" archive_file_size. */
21620 if (arch
.next_arhdr_offset
< filedata
->archive_file_size
)
21621 arch
.next_arhdr_offset
= -1ul;
21624 free (qualified_name
);
21628 if (nested_arch
.file
!= NULL
)
21629 fclose (nested_arch
.file
);
21630 release_archive (&nested_arch
);
21631 release_archive (&arch
);
21637 process_file (char * file_name
)
21639 Filedata
* filedata
= NULL
;
21640 struct stat statbuf
;
21641 char armag
[SARMAG
];
21644 if (stat (file_name
, &statbuf
) < 0)
21646 if (errno
== ENOENT
)
21647 error (_("'%s': No such file\n"), file_name
);
21649 error (_("Could not locate '%s'. System error message: %s\n"),
21650 file_name
, strerror (errno
));
21654 if (! S_ISREG (statbuf
.st_mode
))
21656 error (_("'%s' is not an ordinary file\n"), file_name
);
21660 filedata
= calloc (1, sizeof * filedata
);
21661 if (filedata
== NULL
)
21663 error (_("Out of memory allocating file data structure\n"));
21667 filedata
->file_name
= file_name
;
21668 filedata
->handle
= fopen (file_name
, "rb");
21669 if (filedata
->handle
== NULL
)
21671 error (_("Input file '%s' is not readable.\n"), file_name
);
21676 if (fread (armag
, SARMAG
, 1, filedata
->handle
) != 1)
21678 error (_("%s: Failed to read file's magic number\n"), file_name
);
21679 fclose (filedata
->handle
);
21684 filedata
->file_size
= (bfd_size_type
) statbuf
.st_size
;
21685 filedata
->is_separate
= false;
21687 if (memcmp (armag
, ARMAG
, SARMAG
) == 0)
21689 if (! process_archive (filedata
, false))
21692 else if (memcmp (armag
, ARMAGT
, SARMAG
) == 0)
21694 if ( ! process_archive (filedata
, true))
21699 if (do_archive_index
&& !check_all
)
21700 error (_("File %s is not an archive so its index cannot be displayed.\n"),
21703 rewind (filedata
->handle
);
21704 filedata
->archive_file_size
= filedata
->archive_file_offset
= 0;
21706 if (! process_object (filedata
))
21710 fclose (filedata
->handle
);
21711 free (filedata
->section_headers
);
21712 free (filedata
->program_headers
);
21713 free (filedata
->string_table
);
21714 free (filedata
->dump
.dump_sects
);
21717 free (ba_cache
.strtab
);
21718 ba_cache
.strtab
= NULL
;
21719 free (ba_cache
.symtab
);
21720 ba_cache
.symtab
= NULL
;
21721 ba_cache
.filedata
= NULL
;
21726 #ifdef SUPPORT_DISASSEMBLY
21727 /* Needed by the i386 disassembler. For extra credit, someone could
21728 fix this so that we insert symbolic addresses here, esp for GOT/PLT
21732 print_address (unsigned int addr
, FILE * outfile
)
21734 fprintf (outfile
,"0x%8.8x", addr
);
21737 /* Needed by the i386 disassembler. */
21740 db_task_printsym (unsigned int addr
)
21742 print_address (addr
, stderr
);
21747 main (int argc
, char ** argv
)
21751 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
21752 setlocale (LC_MESSAGES
, "");
21754 #if defined (HAVE_SETLOCALE)
21755 setlocale (LC_CTYPE
, "");
21757 bindtextdomain (PACKAGE
, LOCALEDIR
);
21758 textdomain (PACKAGE
);
21760 expandargv (&argc
, &argv
);
21762 parse_args (& cmdline
, argc
, argv
);
21764 if (optind
< (argc
- 1))
21765 /* When displaying information for more than one file,
21766 prefix the information with the file name. */
21768 else if (optind
>= argc
)
21770 /* Ensure that the warning is always displayed. */
21773 warn (_("Nothing to do.\n"));
21778 while (optind
< argc
)
21779 if (! process_file (argv
[optind
++]))
21782 free (cmdline
.dump_sects
);
21784 free (dump_ctf_symtab_name
);
21785 free (dump_ctf_strtab_name
);
21786 free (dump_ctf_parent_name
);
21788 return err
? EXIT_FAILURE
: EXIT_SUCCESS
;