1 /* readelf.c -- display contents of an ELF format file
2 Copyright (C) 1998-2020 Free Software Foundation, Inc.
4 Originally developed by Eric Youngdale <eric@andante.jic.com>
5 Modifications by Nick Clifton <nickc@redhat.com>
7 This file is part of GNU Binutils.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
24 /* The difference between readelf and objdump:
26 Both programs are capable of displaying the contents of ELF format files,
27 so why does the binutils project have two file dumpers ?
29 The reason is that objdump sees an ELF file through a BFD filter of the
30 world; if BFD has a bug where, say, it disagrees about a machine constant
31 in e_flags, then the odds are good that it will remain internally
32 consistent. The linker sees it the BFD way, objdump sees it the BFD way,
33 GAS sees it the BFD way. There was need for a tool to go find out what
34 the file actually says.
36 This is why the readelf program does not link against the BFD library - it
37 exists as an independent program to help verify the correct working of BFD.
39 There is also the case that readelf can provide more information about an
40 ELF file than is provided by objdump. In particular it can display DWARF
41 debugging information which (at the moment) objdump cannot. */
52 /* Define BFD64 here, even if our default architecture is 32 bit ELF
53 as this will allow us to read in and parse 64bit and 32bit ELF files.
54 Only do this if we believe that the compiler can support a 64 bit
55 data type. For now we only rely on GCC being able to do this. */
66 #include "elf/common.h"
67 #include "elf/external.h"
68 #include "elf/internal.h"
71 /* Included here, before RELOC_MACROS_GEN_FUNC is defined, so that
72 we can obtain the H8 reloc numbers. We need these for the
73 get_reloc_size() function. We include h8.h again after defining
74 RELOC_MACROS_GEN_FUNC so that we get the naming function as well. */
79 /* Undo the effects of #including reloc-macros.h. */
81 #undef START_RELOC_NUMBERS
85 #undef END_RELOC_NUMBERS
86 #undef _RELOC_MACROS_H
88 /* The following headers use the elf/reloc-macros.h file to
89 automatically generate relocation recognition functions
90 such as elf_mips_reloc_type() */
92 #define RELOC_MACROS_GEN_FUNC
94 #include "elf/aarch64.h"
95 #include "elf/alpha.h"
100 #include "elf/cr16.h"
101 #include "elf/cris.h"
103 #include "elf/csky.h"
104 #include "elf/d10v.h"
105 #include "elf/d30v.h"
108 #include "elf/epiphany.h"
109 #include "elf/fr30.h"
111 #include "elf/ft32.h"
113 #include "elf/hppa.h"
114 #include "elf/i386.h"
115 #include "elf/i370.h"
116 #include "elf/i860.h"
117 #include "elf/i960.h"
118 #include "elf/ia64.h"
119 #include "elf/ip2k.h"
120 #include "elf/lm32.h"
121 #include "elf/iq2000.h"
122 #include "elf/m32c.h"
123 #include "elf/m32r.h"
124 #include "elf/m68k.h"
125 #include "elf/m68hc11.h"
126 #include "elf/s12z.h"
127 #include "elf/mcore.h"
129 #include "elf/metag.h"
130 #include "elf/microblaze.h"
131 #include "elf/mips.h"
132 #include "elf/mmix.h"
133 #include "elf/mn10200.h"
134 #include "elf/mn10300.h"
135 #include "elf/moxie.h"
137 #include "elf/msp430.h"
138 #include "elf/nds32.h"
140 #include "elf/nios2.h"
141 #include "elf/or1k.h"
144 #include "elf/ppc64.h"
146 #include "elf/riscv.h"
147 #include "elf/rl78.h"
149 #include "elf/s390.h"
150 #include "elf/score.h"
152 #include "elf/sparc.h"
154 #include "elf/tic6x.h"
155 #include "elf/tilegx.h"
156 #include "elf/tilepro.h"
157 #include "elf/v850.h"
159 #include "elf/visium.h"
160 #include "elf/wasm32.h"
161 #include "elf/x86-64.h"
162 #include "elf/xc16x.h"
163 #include "elf/xgate.h"
164 #include "elf/xstormy16.h"
165 #include "elf/xtensa.h"
169 #include "libiberty.h"
170 #include "safe-ctype.h"
171 #include "filenames.h"
174 #define offsetof(TYPE, MEMBER) ((size_t) &(((TYPE *) 0)->MEMBER))
177 typedef struct elf_section_list
179 Elf_Internal_Shdr
* hdr
;
180 struct elf_section_list
* next
;
183 /* Flag bits indicating particular types of dump. */
184 #define HEX_DUMP (1 << 0) /* The -x command line switch. */
185 #define DISASS_DUMP (1 << 1) /* The -i command line switch. */
186 #define DEBUG_DUMP (1 << 2) /* The -w command line switch. */
187 #define STRING_DUMP (1 << 3) /* The -p command line switch. */
188 #define RELOC_DUMP (1 << 4) /* The -R command line switch. */
189 #define CTF_DUMP (1 << 5) /* The --ctf command line switch. */
191 typedef unsigned char dump_type
;
193 /* A linked list of the section names for which dumps were requested. */
194 struct dump_list_entry
198 struct dump_list_entry
* next
;
201 /* A dynamic array of flags indicating for which sections a dump
202 has been requested via command line switches. */
205 dump_type
* dump_sects
;
206 unsigned int num_dump_sects
;
209 static struct dump_data cmdline
;
211 static struct dump_list_entry
* dump_sects_byname
;
213 char * program_name
= "readelf";
215 static bfd_boolean show_name
= FALSE
;
216 static bfd_boolean do_dynamic
= FALSE
;
217 static bfd_boolean do_syms
= FALSE
;
218 static bfd_boolean do_dyn_syms
= FALSE
;
219 static bfd_boolean do_lto_syms
= FALSE
;
220 static bfd_boolean do_reloc
= FALSE
;
221 static bfd_boolean do_sections
= FALSE
;
222 static bfd_boolean do_section_groups
= FALSE
;
223 static bfd_boolean do_section_details
= FALSE
;
224 static bfd_boolean do_segments
= FALSE
;
225 static bfd_boolean do_unwind
= FALSE
;
226 static bfd_boolean do_using_dynamic
= FALSE
;
227 static bfd_boolean do_header
= FALSE
;
228 static bfd_boolean do_dump
= FALSE
;
229 static bfd_boolean do_version
= FALSE
;
230 static bfd_boolean do_histogram
= FALSE
;
231 static bfd_boolean do_debugging
= FALSE
;
232 static bfd_boolean do_ctf
= FALSE
;
233 static bfd_boolean do_arch
= FALSE
;
234 static bfd_boolean do_notes
= FALSE
;
235 static bfd_boolean do_archive_index
= FALSE
;
236 static bfd_boolean check_all
= FALSE
;
237 static bfd_boolean is_32bit_elf
= FALSE
;
238 static bfd_boolean decompress_dumps
= FALSE
;
239 static bfd_boolean do_not_show_symbol_truncation
= FALSE
;
240 static bfd_boolean do_demangle
= FALSE
; /* Pretty print C++ symbol names. */
241 static int demangle_flags
= DMGL_ANSI
| DMGL_PARAMS
;
243 static char *dump_ctf_parent_name
;
244 static char *dump_ctf_symtab_name
;
245 static char *dump_ctf_strtab_name
;
249 struct group_list
* next
;
250 unsigned int section_index
;
255 struct group_list
* root
;
256 unsigned int group_index
;
259 typedef struct filedata
261 const char * file_name
;
263 bfd_size_type file_size
;
264 Elf_Internal_Ehdr file_header
;
265 Elf_Internal_Shdr
* section_headers
;
266 Elf_Internal_Phdr
* program_headers
;
268 unsigned long string_table_length
;
269 unsigned long archive_file_offset
;
270 unsigned long archive_file_size
;
271 unsigned long dynamic_addr
;
272 bfd_size_type dynamic_size
;
274 Elf_Internal_Dyn
* dynamic_section
;
275 Elf_Internal_Shdr
* dynamic_strtab_section
;
276 char * dynamic_strings
;
277 unsigned long dynamic_strings_length
;
278 Elf_Internal_Shdr
* dynamic_symtab_section
;
279 unsigned long num_dynamic_syms
;
280 Elf_Internal_Sym
* dynamic_symbols
;
281 bfd_vma version_info
[16];
282 unsigned int dynamic_syminfo_nent
;
283 Elf_Internal_Syminfo
* dynamic_syminfo
;
284 unsigned long dynamic_syminfo_offset
;
285 bfd_size_type nbuckets
;
286 bfd_size_type nchains
;
289 bfd_size_type ngnubuckets
;
290 bfd_size_type ngnuchains
;
291 bfd_vma
* gnubuckets
;
295 char program_interpreter
[PATH_MAX
];
296 bfd_vma dynamic_info
[DT_ENCODING
];
297 bfd_vma dynamic_info_DT_GNU_HASH
;
298 bfd_vma dynamic_info_DT_MIPS_XHASH
;
299 elf_section_list
* symtab_shndx_list
;
301 struct group
* section_groups
;
302 struct group
** section_headers_groups
;
303 /* A dynamic array of flags indicating for which sections a dump of
304 some kind has been requested. It is reset on a per-object file
305 basis and then initialised from the cmdline_dump_sects array,
306 the results of interpreting the -w switch, and the
307 dump_sects_byname list. */
308 struct dump_data dump
;
311 /* How to print a vma value. */
312 typedef enum print_mode
324 /* Versioned symbol info. */
325 enum versioned_symbol_info
332 static const char * get_symbol_version_string
333 (Filedata
*, bfd_boolean
, const char *, unsigned long, unsigned,
334 Elf_Internal_Sym
*, enum versioned_symbol_info
*, unsigned short *);
338 #define SECTION_NAME(X) \
339 ((X) == NULL ? _("<none>") \
340 : filedata->string_table == NULL ? _("<no-strings>") \
341 : ((X)->sh_name >= filedata->string_table_length ? _("<corrupt>") \
342 : filedata->string_table + (X)->sh_name))
344 #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
346 #define GET_ELF_SYMBOLS(file, section, sym_count) \
347 (is_32bit_elf ? get_32bit_elf_symbols (file, section, sym_count) \
348 : get_64bit_elf_symbols (file, section, sym_count))
350 #define VALID_SYMBOL_NAME(strtab, strtab_size, offset) \
351 (strtab != NULL && offset < strtab_size)
352 #define VALID_DYNAMIC_NAME(filedata, offset) \
353 VALID_SYMBOL_NAME (filedata->dynamic_strings, \
354 filedata->dynamic_strings_length, offset)
355 /* GET_DYNAMIC_NAME asssumes that VALID_DYNAMIC_NAME has
356 already been called and verified that the string exists. */
357 #define GET_DYNAMIC_NAME(filedata, offset) \
358 (filedata->dynamic_strings + offset)
360 #define REMOVE_ARCH_BITS(ADDR) \
363 if (filedata->file_header.e_machine == EM_ARM) \
368 /* Get the correct GNU hash section name. */
369 #define GNU_HASH_SECTION_NAME(filedata) \
370 filedata->dynamic_info_DT_MIPS_XHASH ? ".MIPS.xhash" : ".gnu.hash"
372 /* Print a BFD_VMA to an internal buffer, for use in error messages.
373 BFD_FMA_FMT can't be used in translated strings. */
376 bfd_vmatoa (char *fmtch
, bfd_vma value
)
378 /* bfd_vmatoa is used more then once in a printf call for output.
379 Cycle through an array of buffers. */
380 static int buf_pos
= 0;
381 static struct bfd_vmatoa_buf
388 ret
= buf
[buf_pos
++].place
;
389 buf_pos
%= ARRAY_SIZE (buf
);
391 sprintf (fmt
, "%%%s%s", BFD_VMA_FMT
, fmtch
);
392 snprintf (ret
, sizeof (buf
[0].place
), fmt
, value
);
396 /* Retrieve NMEMB structures, each SIZE bytes long from FILEDATA starting at
397 OFFSET + the offset of the current archive member, if we are examining an
398 archive. Put the retrieved data into VAR, if it is not NULL. Otherwise
399 allocate a buffer using malloc and fill that. In either case return the
400 pointer to the start of the retrieved data or NULL if something went wrong.
401 If something does go wrong and REASON is not NULL then emit an error
402 message using REASON as part of the context. */
405 get_data (void * var
,
407 unsigned long offset
,
413 bfd_size_type amt
= size
* nmemb
;
415 if (size
== 0 || nmemb
== 0)
418 /* If the size_t type is smaller than the bfd_size_type, eg because
419 you are building a 32-bit tool on a 64-bit host, then make sure
420 that when the sizes are cast to (size_t) no information is lost. */
421 if ((size_t) size
!= size
422 || (size_t) nmemb
!= nmemb
423 || (size_t) amt
!= amt
)
426 error (_("Size truncation prevents reading %s"
427 " elements of size %s for %s\n"),
428 bfd_vmatoa ("u", nmemb
), bfd_vmatoa ("u", size
), reason
);
432 /* Check for size overflow. */
433 if (amt
/ size
!= nmemb
|| (size_t) amt
+ 1 == 0)
436 error (_("Size overflow prevents reading %s"
437 " elements of size %s for %s\n"),
438 bfd_vmatoa ("u", nmemb
), bfd_vmatoa ("u", size
), reason
);
442 /* Be kind to memory checkers (eg valgrind, address sanitizer) by not
443 attempting to allocate memory when the read is bound to fail. */
444 if (filedata
->archive_file_offset
> filedata
->file_size
445 || offset
> filedata
->file_size
- filedata
->archive_file_offset
446 || amt
> filedata
->file_size
- filedata
->archive_file_offset
- offset
)
449 error (_("Reading %s bytes extends past end of file for %s\n"),
450 bfd_vmatoa ("u", amt
), reason
);
454 if (fseek (filedata
->handle
, filedata
->archive_file_offset
+ offset
,
458 error (_("Unable to seek to 0x%lx for %s\n"),
459 filedata
->archive_file_offset
+ offset
, reason
);
466 /* + 1 so that we can '\0' terminate invalid string table sections. */
467 mvar
= malloc ((size_t) amt
+ 1);
472 error (_("Out of memory allocating %s bytes for %s\n"),
473 bfd_vmatoa ("u", amt
), reason
);
477 ((char *) mvar
)[amt
] = '\0';
480 if (fread (mvar
, (size_t) size
, (size_t) nmemb
, filedata
->handle
) != nmemb
)
483 error (_("Unable to read in %s bytes of %s\n"),
484 bfd_vmatoa ("u", amt
), reason
);
493 /* Print a VMA value in the MODE specified.
494 Returns the number of characters displayed. */
497 print_vma (bfd_vma vma
, print_mode mode
)
509 return nc
+ printf ("%8.8" BFD_VMA_FMT
"x", vma
);
516 return printf ("%5" BFD_VMA_FMT
"d", vma
);
522 return nc
+ printf ("%" BFD_VMA_FMT
"x", vma
);
525 return printf ("%" BFD_VMA_FMT
"d", vma
);
528 return printf ("%" BFD_VMA_FMT
"u", vma
);
531 /* FIXME: Report unrecognised mode ? */
536 /* Display a symbol on stdout. Handles the display of control characters and
537 multibye characters (assuming the host environment supports them).
539 Display at most abs(WIDTH) characters, truncating as necessary, unless do_wide is true.
541 If truncation will happen and do_not_show_symbol_truncation is FALSE then display
542 abs(WIDTH) - 5 characters followed by "[...]".
544 If WIDTH is negative then ensure that the output is at least (- WIDTH) characters,
545 padding as necessary.
547 Returns the number of emitted characters. */
550 print_symbol (signed int width
, const char * symbol
)
552 bfd_boolean extra_padding
= FALSE
;
553 bfd_boolean do_dots
= FALSE
;
554 signed int num_printed
= 0;
555 #ifdef HAVE_MBSTATE_T
558 unsigned int width_remaining
;
559 const void * alloced_symbol
= NULL
;
563 /* Keep the width positive. This helps the code below. */
565 extra_padding
= TRUE
;
571 /* Set the remaining width to a very large value.
572 This simplifies the code below. */
573 width_remaining
= INT_MAX
;
576 width_remaining
= width
;
577 if (! do_not_show_symbol_truncation
578 && (int) strlen (symbol
) > width
)
580 width_remaining
-= 5;
581 if ((int) width_remaining
< 0)
587 #ifdef HAVE_MBSTATE_T
588 /* Initialise the multibyte conversion state. */
589 memset (& state
, 0, sizeof (state
));
592 if (do_demangle
&& *symbol
)
594 const char * res
= cplus_demangle (symbol
, demangle_flags
);
597 alloced_symbol
= symbol
= res
;
600 while (width_remaining
)
603 const char c
= *symbol
++;
608 /* Do not print control characters directly as they can affect terminal
609 settings. Such characters usually appear in the names generated
610 by the assembler for local labels. */
613 if (width_remaining
< 2)
616 printf ("^%c", c
+ 0x40);
617 width_remaining
-= 2;
620 else if (ISPRINT (c
))
628 #ifdef HAVE_MBSTATE_T
631 /* Let printf do the hard work of displaying multibyte characters. */
632 printf ("%.1s", symbol
- 1);
636 #ifdef HAVE_MBSTATE_T
637 /* Try to find out how many bytes made up the character that was
638 just printed. Advance the symbol pointer past the bytes that
640 n
= mbrtowc (& w
, symbol
- 1, MB_CUR_MAX
, & state
);
644 if (n
!= (size_t) -1 && n
!= (size_t) -2 && n
> 0)
650 num_printed
+= printf ("[...]");
652 if (extra_padding
&& num_printed
< width
)
654 /* Fill in the remaining spaces. */
655 printf ("%-*s", width
- num_printed
, " ");
659 free ((void *) alloced_symbol
);
663 /* Returns a pointer to a static buffer containing a printable version of
664 the given section's name. Like print_symbol, except that it does not try
665 to print multibyte characters, it just interprets them as hex values. */
668 printable_section_name (Filedata
* filedata
, const Elf_Internal_Shdr
* sec
)
670 #define MAX_PRINT_SEC_NAME_LEN 128
671 static char sec_name_buf
[MAX_PRINT_SEC_NAME_LEN
+ 1];
672 const char * name
= SECTION_NAME (sec
);
673 char * buf
= sec_name_buf
;
675 unsigned int remaining
= MAX_PRINT_SEC_NAME_LEN
;
677 while ((c
= * name
++) != 0)
688 else if (ISPRINT (c
))
695 static char hex
[17] = "0123456789ABCDEF";
700 * buf
++ = hex
[(c
& 0xf0) >> 4];
701 * buf
++ = hex
[c
& 0x0f];
715 printable_section_name_from_index (Filedata
* filedata
, unsigned long ndx
)
717 if (ndx
>= filedata
->file_header
.e_shnum
)
718 return _("<corrupt>");
720 return printable_section_name (filedata
, filedata
->section_headers
+ ndx
);
723 /* Return a pointer to section NAME, or NULL if no such section exists. */
725 static Elf_Internal_Shdr
*
726 find_section (Filedata
* filedata
, const char * name
)
730 if (filedata
->section_headers
== NULL
)
733 for (i
= 0; i
< filedata
->file_header
.e_shnum
; i
++)
734 if (streq (SECTION_NAME (filedata
->section_headers
+ i
), name
))
735 return filedata
->section_headers
+ i
;
740 /* Return a pointer to a section containing ADDR, or NULL if no such
743 static Elf_Internal_Shdr
*
744 find_section_by_address (Filedata
* filedata
, bfd_vma addr
)
748 if (filedata
->section_headers
== NULL
)
751 for (i
= 0; i
< filedata
->file_header
.e_shnum
; i
++)
753 Elf_Internal_Shdr
*sec
= filedata
->section_headers
+ i
;
755 if (addr
>= sec
->sh_addr
&& addr
< sec
->sh_addr
+ sec
->sh_size
)
762 static Elf_Internal_Shdr
*
763 find_section_by_type (Filedata
* filedata
, unsigned int type
)
767 if (filedata
->section_headers
== NULL
)
770 for (i
= 0; i
< filedata
->file_header
.e_shnum
; i
++)
772 Elf_Internal_Shdr
*sec
= filedata
->section_headers
+ i
;
774 if (sec
->sh_type
== type
)
781 /* Return a pointer to section NAME, or NULL if no such section exists,
782 restricted to the list of sections given in SET. */
784 static Elf_Internal_Shdr
*
785 find_section_in_set (Filedata
* filedata
, const char * name
, unsigned int * set
)
789 if (filedata
->section_headers
== NULL
)
794 while ((i
= *set
++) > 0)
796 /* See PR 21156 for a reproducer. */
797 if (i
>= filedata
->file_header
.e_shnum
)
798 continue; /* FIXME: Should we issue an error message ? */
800 if (streq (SECTION_NAME (filedata
->section_headers
+ i
), name
))
801 return filedata
->section_headers
+ i
;
805 return find_section (filedata
, name
);
808 /* Return TRUE if the current file is for IA-64 machine and OpenVMS ABI.
809 This OS has so many departures from the ELF standard that we test it at
812 static inline bfd_boolean
813 is_ia64_vms (Filedata
* filedata
)
815 return filedata
->file_header
.e_machine
== EM_IA_64
816 && filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_OPENVMS
;
819 /* Guess the relocation size commonly used by the specific machines. */
822 guess_is_rela (unsigned int e_machine
)
826 /* Targets that use REL relocations. */
843 /* Targets that use RELA relocations. */
847 case EM_ADAPTEVA_EPIPHANY
:
849 case EM_ALTERA_NIOS2
:
852 case EM_ARC_COMPACT2
:
873 case EM_LATTICEMICO32
:
882 case EM_CYGNUS_MN10200
:
884 case EM_CYGNUS_MN10300
:
920 case EM_MICROBLAZE_OLD
:
942 warn (_("Don't know about relocations on this machine architecture\n"));
947 /* Load RELA type relocations from FILEDATA at REL_OFFSET extending for REL_SIZE bytes.
948 Returns TRUE upon success, FALSE otherwise. If successful then a
949 pointer to a malloc'ed buffer containing the relocs is placed in *RELASP,
950 and the number of relocs loaded is placed in *NRELASP. It is the caller's
951 responsibility to free the allocated buffer. */
954 slurp_rela_relocs (Filedata
* filedata
,
955 unsigned long rel_offset
,
956 unsigned long rel_size
,
957 Elf_Internal_Rela
** relasp
,
958 unsigned long * nrelasp
)
960 Elf_Internal_Rela
* relas
;
966 Elf32_External_Rela
* erelas
;
968 erelas
= (Elf32_External_Rela
*) get_data (NULL
, filedata
, rel_offset
, 1,
969 rel_size
, _("32-bit relocation data"));
973 nrelas
= rel_size
/ sizeof (Elf32_External_Rela
);
975 relas
= (Elf_Internal_Rela
*) cmalloc (nrelas
,
976 sizeof (Elf_Internal_Rela
));
981 error (_("out of memory parsing relocs\n"));
985 for (i
= 0; i
< nrelas
; i
++)
987 relas
[i
].r_offset
= BYTE_GET (erelas
[i
].r_offset
);
988 relas
[i
].r_info
= BYTE_GET (erelas
[i
].r_info
);
989 relas
[i
].r_addend
= BYTE_GET_SIGNED (erelas
[i
].r_addend
);
996 Elf64_External_Rela
* erelas
;
998 erelas
= (Elf64_External_Rela
*) get_data (NULL
, filedata
, rel_offset
, 1,
999 rel_size
, _("64-bit relocation data"));
1003 nrelas
= rel_size
/ sizeof (Elf64_External_Rela
);
1005 relas
= (Elf_Internal_Rela
*) cmalloc (nrelas
,
1006 sizeof (Elf_Internal_Rela
));
1011 error (_("out of memory parsing relocs\n"));
1015 for (i
= 0; i
< nrelas
; i
++)
1017 relas
[i
].r_offset
= BYTE_GET (erelas
[i
].r_offset
);
1018 relas
[i
].r_info
= BYTE_GET (erelas
[i
].r_info
);
1019 relas
[i
].r_addend
= BYTE_GET_SIGNED (erelas
[i
].r_addend
);
1021 /* The #ifdef BFD64 below is to prevent a compile time
1022 warning. We know that if we do not have a 64 bit data
1023 type that we will never execute this code anyway. */
1025 if (filedata
->file_header
.e_machine
== EM_MIPS
1026 && filedata
->file_header
.e_ident
[EI_DATA
] != ELFDATA2MSB
)
1028 /* In little-endian objects, r_info isn't really a
1029 64-bit little-endian value: it has a 32-bit
1030 little-endian symbol index followed by four
1031 individual byte fields. Reorder INFO
1033 bfd_vma inf
= relas
[i
].r_info
;
1034 inf
= (((inf
& 0xffffffff) << 32)
1035 | ((inf
>> 56) & 0xff)
1036 | ((inf
>> 40) & 0xff00)
1037 | ((inf
>> 24) & 0xff0000)
1038 | ((inf
>> 8) & 0xff000000));
1039 relas
[i
].r_info
= inf
;
1052 /* Load REL type relocations from FILEDATA at REL_OFFSET extending for REL_SIZE bytes.
1053 Returns TRUE upon success, FALSE otherwise. If successful then a
1054 pointer to a malloc'ed buffer containing the relocs is placed in *RELSP,
1055 and the number of relocs loaded is placed in *NRELSP. It is the caller's
1056 responsibility to free the allocated buffer. */
1059 slurp_rel_relocs (Filedata
* filedata
,
1060 unsigned long rel_offset
,
1061 unsigned long rel_size
,
1062 Elf_Internal_Rela
** relsp
,
1063 unsigned long * nrelsp
)
1065 Elf_Internal_Rela
* rels
;
1071 Elf32_External_Rel
* erels
;
1073 erels
= (Elf32_External_Rel
*) get_data (NULL
, filedata
, rel_offset
, 1,
1074 rel_size
, _("32-bit relocation data"));
1078 nrels
= rel_size
/ sizeof (Elf32_External_Rel
);
1080 rels
= (Elf_Internal_Rela
*) cmalloc (nrels
, sizeof (Elf_Internal_Rela
));
1085 error (_("out of memory parsing relocs\n"));
1089 for (i
= 0; i
< nrels
; i
++)
1091 rels
[i
].r_offset
= BYTE_GET (erels
[i
].r_offset
);
1092 rels
[i
].r_info
= BYTE_GET (erels
[i
].r_info
);
1093 rels
[i
].r_addend
= 0;
1100 Elf64_External_Rel
* erels
;
1102 erels
= (Elf64_External_Rel
*) get_data (NULL
, filedata
, rel_offset
, 1,
1103 rel_size
, _("64-bit relocation data"));
1107 nrels
= rel_size
/ sizeof (Elf64_External_Rel
);
1109 rels
= (Elf_Internal_Rela
*) cmalloc (nrels
, sizeof (Elf_Internal_Rela
));
1114 error (_("out of memory parsing relocs\n"));
1118 for (i
= 0; i
< nrels
; i
++)
1120 rels
[i
].r_offset
= BYTE_GET (erels
[i
].r_offset
);
1121 rels
[i
].r_info
= BYTE_GET (erels
[i
].r_info
);
1122 rels
[i
].r_addend
= 0;
1124 /* The #ifdef BFD64 below is to prevent a compile time
1125 warning. We know that if we do not have a 64 bit data
1126 type that we will never execute this code anyway. */
1128 if (filedata
->file_header
.e_machine
== EM_MIPS
1129 && filedata
->file_header
.e_ident
[EI_DATA
] != ELFDATA2MSB
)
1131 /* In little-endian objects, r_info isn't really a
1132 64-bit little-endian value: it has a 32-bit
1133 little-endian symbol index followed by four
1134 individual byte fields. Reorder INFO
1136 bfd_vma inf
= rels
[i
].r_info
;
1137 inf
= (((inf
& 0xffffffff) << 32)
1138 | ((inf
>> 56) & 0xff)
1139 | ((inf
>> 40) & 0xff00)
1140 | ((inf
>> 24) & 0xff0000)
1141 | ((inf
>> 8) & 0xff000000));
1142 rels
[i
].r_info
= inf
;
1155 /* Returns the reloc type extracted from the reloc info field. */
1158 get_reloc_type (Filedata
* filedata
, bfd_vma reloc_info
)
1161 return ELF32_R_TYPE (reloc_info
);
1163 switch (filedata
->file_header
.e_machine
)
1166 /* Note: We assume that reloc_info has already been adjusted for us. */
1167 return ELF64_MIPS_R_TYPE (reloc_info
);
1170 return ELF64_R_TYPE_ID (reloc_info
);
1173 return ELF64_R_TYPE (reloc_info
);
1177 /* Return the symbol index extracted from the reloc info field. */
1180 get_reloc_symindex (bfd_vma reloc_info
)
1182 return is_32bit_elf
? ELF32_R_SYM (reloc_info
) : ELF64_R_SYM (reloc_info
);
1185 static inline bfd_boolean
1186 uses_msp430x_relocs (Filedata
* filedata
)
1189 filedata
->file_header
.e_machine
== EM_MSP430
/* Paranoia. */
1190 /* GCC uses osabi == ELFOSBI_STANDALONE. */
1191 && (((filedata
->file_header
.e_flags
& EF_MSP430_MACH
) == E_MSP430_MACH_MSP430X
)
1192 /* TI compiler uses ELFOSABI_NONE. */
1193 || (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_NONE
));
1196 /* Display the contents of the relocation data found at the specified
1200 dump_relocations (Filedata
* filedata
,
1201 unsigned long rel_offset
,
1202 unsigned long rel_size
,
1203 Elf_Internal_Sym
* symtab
,
1204 unsigned long nsyms
,
1206 unsigned long strtablen
,
1208 bfd_boolean is_dynsym
)
1211 Elf_Internal_Rela
* rels
;
1212 bfd_boolean res
= TRUE
;
1214 if (is_rela
== UNKNOWN
)
1215 is_rela
= guess_is_rela (filedata
->file_header
.e_machine
);
1219 if (!slurp_rela_relocs (filedata
, rel_offset
, rel_size
, &rels
, &rel_size
))
1224 if (!slurp_rel_relocs (filedata
, rel_offset
, rel_size
, &rels
, &rel_size
))
1233 printf (_(" Offset Info Type Sym. Value Symbol's Name + Addend\n"));
1235 printf (_(" Offset Info Type Sym.Value Sym. Name + Addend\n"));
1240 printf (_(" Offset Info Type Sym. Value Symbol's Name\n"));
1242 printf (_(" Offset Info Type Sym.Value Sym. Name\n"));
1250 printf (_(" Offset Info Type Symbol's Value Symbol's Name + Addend\n"));
1252 printf (_(" Offset Info Type Sym. Value Sym. Name + Addend\n"));
1257 printf (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
1259 printf (_(" Offset Info Type Sym. Value Sym. Name\n"));
1263 for (i
= 0; i
< rel_size
; i
++)
1268 bfd_vma symtab_index
;
1271 offset
= rels
[i
].r_offset
;
1272 inf
= rels
[i
].r_info
;
1274 type
= get_reloc_type (filedata
, inf
);
1275 symtab_index
= get_reloc_symindex (inf
);
1279 printf ("%8.8lx %8.8lx ",
1280 (unsigned long) offset
& 0xffffffff,
1281 (unsigned long) inf
& 0xffffffff);
1286 ? "%16.16" BFD_VMA_FMT
"x %16.16" BFD_VMA_FMT
"x "
1287 : "%12.12" BFD_VMA_FMT
"x %12.12" BFD_VMA_FMT
"x ",
1291 switch (filedata
->file_header
.e_machine
)
1298 rtype
= elf_aarch64_reloc_type (type
);
1302 case EM_CYGNUS_M32R
:
1303 rtype
= elf_m32r_reloc_type (type
);
1308 rtype
= elf_i386_reloc_type (type
);
1313 rtype
= elf_m68hc11_reloc_type (type
);
1317 rtype
= elf_s12z_reloc_type (type
);
1321 rtype
= elf_m68k_reloc_type (type
);
1325 rtype
= elf_i960_reloc_type (type
);
1330 rtype
= elf_avr_reloc_type (type
);
1333 case EM_OLD_SPARCV9
:
1334 case EM_SPARC32PLUS
:
1337 rtype
= elf_sparc_reloc_type (type
);
1341 rtype
= elf_spu_reloc_type (type
);
1345 rtype
= v800_reloc_type (type
);
1348 case EM_CYGNUS_V850
:
1349 rtype
= v850_reloc_type (type
);
1353 case EM_CYGNUS_D10V
:
1354 rtype
= elf_d10v_reloc_type (type
);
1358 case EM_CYGNUS_D30V
:
1359 rtype
= elf_d30v_reloc_type (type
);
1363 rtype
= elf_dlx_reloc_type (type
);
1367 rtype
= elf_sh_reloc_type (type
);
1371 case EM_CYGNUS_MN10300
:
1372 rtype
= elf_mn10300_reloc_type (type
);
1376 case EM_CYGNUS_MN10200
:
1377 rtype
= elf_mn10200_reloc_type (type
);
1381 case EM_CYGNUS_FR30
:
1382 rtype
= elf_fr30_reloc_type (type
);
1386 rtype
= elf_frv_reloc_type (type
);
1390 rtype
= elf_csky_reloc_type (type
);
1394 rtype
= elf_ft32_reloc_type (type
);
1398 rtype
= elf_mcore_reloc_type (type
);
1402 rtype
= elf_mmix_reloc_type (type
);
1406 rtype
= elf_moxie_reloc_type (type
);
1410 if (uses_msp430x_relocs (filedata
))
1412 rtype
= elf_msp430x_reloc_type (type
);
1417 rtype
= elf_msp430_reloc_type (type
);
1421 rtype
= elf_nds32_reloc_type (type
);
1425 rtype
= elf_ppc_reloc_type (type
);
1429 rtype
= elf_ppc64_reloc_type (type
);
1433 case EM_MIPS_RS3_LE
:
1434 rtype
= elf_mips_reloc_type (type
);
1438 rtype
= elf_riscv_reloc_type (type
);
1442 rtype
= elf_alpha_reloc_type (type
);
1446 rtype
= elf_arm_reloc_type (type
);
1450 case EM_ARC_COMPACT
:
1451 case EM_ARC_COMPACT2
:
1452 rtype
= elf_arc_reloc_type (type
);
1456 rtype
= elf_hppa_reloc_type (type
);
1462 rtype
= elf_h8_reloc_type (type
);
1466 rtype
= elf_or1k_reloc_type (type
);
1471 rtype
= elf_pj_reloc_type (type
);
1474 rtype
= elf_ia64_reloc_type (type
);
1478 rtype
= elf_cris_reloc_type (type
);
1482 rtype
= elf_i860_reloc_type (type
);
1488 rtype
= elf_x86_64_reloc_type (type
);
1492 rtype
= i370_reloc_type (type
);
1497 rtype
= elf_s390_reloc_type (type
);
1501 rtype
= elf_score_reloc_type (type
);
1505 rtype
= elf_xstormy16_reloc_type (type
);
1509 rtype
= elf_crx_reloc_type (type
);
1513 rtype
= elf_vax_reloc_type (type
);
1517 rtype
= elf_visium_reloc_type (type
);
1521 rtype
= elf_bpf_reloc_type (type
);
1524 case EM_ADAPTEVA_EPIPHANY
:
1525 rtype
= elf_epiphany_reloc_type (type
);
1530 rtype
= elf_ip2k_reloc_type (type
);
1534 rtype
= elf_iq2000_reloc_type (type
);
1539 rtype
= elf_xtensa_reloc_type (type
);
1542 case EM_LATTICEMICO32
:
1543 rtype
= elf_lm32_reloc_type (type
);
1548 rtype
= elf_m32c_reloc_type (type
);
1552 rtype
= elf_mt_reloc_type (type
);
1556 rtype
= elf_bfin_reloc_type (type
);
1560 rtype
= elf_mep_reloc_type (type
);
1564 rtype
= elf_cr16_reloc_type (type
);
1568 case EM_MICROBLAZE_OLD
:
1569 rtype
= elf_microblaze_reloc_type (type
);
1573 rtype
= elf_rl78_reloc_type (type
);
1577 rtype
= elf_rx_reloc_type (type
);
1581 rtype
= elf_metag_reloc_type (type
);
1586 rtype
= elf_xc16x_reloc_type (type
);
1590 rtype
= elf_tic6x_reloc_type (type
);
1594 rtype
= elf_tilegx_reloc_type (type
);
1598 rtype
= elf_tilepro_reloc_type (type
);
1601 case EM_WEBASSEMBLY
:
1602 rtype
= elf_wasm32_reloc_type (type
);
1606 rtype
= elf_xgate_reloc_type (type
);
1609 case EM_ALTERA_NIOS2
:
1610 rtype
= elf_nios2_reloc_type (type
);
1614 rtype
= elf_pru_reloc_type (type
);
1618 if (EF_NFP_MACH (filedata
->file_header
.e_flags
) == E_NFP_MACH_3200
)
1619 rtype
= elf_nfp3200_reloc_type (type
);
1621 rtype
= elf_nfp_reloc_type (type
);
1625 rtype
= elf_z80_reloc_type (type
);
1630 printf (_("unrecognized: %-7lx"), (unsigned long) type
& 0xffffffff);
1632 printf (do_wide
? "%-22s" : "%-17.17s", rtype
);
1634 if (filedata
->file_header
.e_machine
== EM_ALPHA
1636 && streq (rtype
, "R_ALPHA_LITUSE")
1639 switch (rels
[i
].r_addend
)
1641 case LITUSE_ALPHA_ADDR
: rtype
= "ADDR"; break;
1642 case LITUSE_ALPHA_BASE
: rtype
= "BASE"; break;
1643 case LITUSE_ALPHA_BYTOFF
: rtype
= "BYTOFF"; break;
1644 case LITUSE_ALPHA_JSR
: rtype
= "JSR"; break;
1645 case LITUSE_ALPHA_TLSGD
: rtype
= "TLSGD"; break;
1646 case LITUSE_ALPHA_TLSLDM
: rtype
= "TLSLDM"; break;
1647 case LITUSE_ALPHA_JSRDIRECT
: rtype
= "JSRDIRECT"; break;
1648 default: rtype
= NULL
;
1652 printf (" (%s)", rtype
);
1656 printf (_("<unknown addend: %lx>"),
1657 (unsigned long) rels
[i
].r_addend
);
1661 else if (symtab_index
)
1663 if (symtab
== NULL
|| symtab_index
>= nsyms
)
1665 error (_(" bad symbol index: %08lx in reloc\n"),
1666 (unsigned long) symtab_index
);
1671 Elf_Internal_Sym
* psym
;
1672 const char * version_string
;
1673 enum versioned_symbol_info sym_info
;
1674 unsigned short vna_other
;
1676 psym
= symtab
+ symtab_index
;
1679 = get_symbol_version_string (filedata
, is_dynsym
,
1688 if (ELF_ST_TYPE (psym
->st_info
) == STT_GNU_IFUNC
)
1692 unsigned int width
= is_32bit_elf
? 8 : 14;
1694 /* Relocations against GNU_IFUNC symbols do not use the value
1695 of the symbol as the address to relocate against. Instead
1696 they invoke the function named by the symbol and use its
1697 result as the address for relocation.
1699 To indicate this to the user, do not display the value of
1700 the symbol in the "Symbols's Value" field. Instead show
1701 its name followed by () as a hint that the symbol is
1705 || psym
->st_name
== 0
1706 || psym
->st_name
>= strtablen
)
1709 name
= strtab
+ psym
->st_name
;
1711 len
= print_symbol (width
, name
);
1713 printf (sym_info
== symbol_public
? "@@%s" : "@%s",
1715 printf ("()%-*s", len
<= width
? (width
+ 1) - len
: 1, " ");
1719 print_vma (psym
->st_value
, LONG_HEX
);
1721 printf (is_32bit_elf
? " " : " ");
1724 if (psym
->st_name
== 0)
1726 const char * sec_name
= "<null>";
1729 if (ELF_ST_TYPE (psym
->st_info
) == STT_SECTION
)
1731 if (psym
->st_shndx
< filedata
->file_header
.e_shnum
)
1732 sec_name
= SECTION_NAME (filedata
->section_headers
+ psym
->st_shndx
);
1733 else if (psym
->st_shndx
== SHN_ABS
)
1735 else if (psym
->st_shndx
== SHN_COMMON
)
1736 sec_name
= "COMMON";
1737 else if ((filedata
->file_header
.e_machine
== EM_MIPS
1738 && psym
->st_shndx
== SHN_MIPS_SCOMMON
)
1739 || (filedata
->file_header
.e_machine
== EM_TI_C6000
1740 && psym
->st_shndx
== SHN_TIC6X_SCOMMON
))
1741 sec_name
= "SCOMMON";
1742 else if (filedata
->file_header
.e_machine
== EM_MIPS
1743 && psym
->st_shndx
== SHN_MIPS_SUNDEFINED
)
1744 sec_name
= "SUNDEF";
1745 else if ((filedata
->file_header
.e_machine
== EM_X86_64
1746 || filedata
->file_header
.e_machine
== EM_L1OM
1747 || filedata
->file_header
.e_machine
== EM_K1OM
)
1748 && psym
->st_shndx
== SHN_X86_64_LCOMMON
)
1749 sec_name
= "LARGE_COMMON";
1750 else if (filedata
->file_header
.e_machine
== EM_IA_64
1751 && filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_HPUX
1752 && psym
->st_shndx
== SHN_IA_64_ANSI_COMMON
)
1753 sec_name
= "ANSI_COM";
1754 else if (is_ia64_vms (filedata
)
1755 && psym
->st_shndx
== SHN_IA_64_VMS_SYMVEC
)
1756 sec_name
= "VMS_SYMVEC";
1759 sprintf (name_buf
, "<section 0x%x>",
1760 (unsigned int) psym
->st_shndx
);
1761 sec_name
= name_buf
;
1764 print_symbol (22, sec_name
);
1766 else if (strtab
== NULL
)
1767 printf (_("<string table index: %3ld>"), psym
->st_name
);
1768 else if (psym
->st_name
>= strtablen
)
1770 error (_("<corrupt string table index: %3ld>\n"),
1776 print_symbol (22, strtab
+ psym
->st_name
);
1778 printf (sym_info
== symbol_public
? "@@%s" : "@%s",
1784 bfd_vma off
= rels
[i
].r_addend
;
1786 if ((bfd_signed_vma
) off
< 0)
1787 printf (" - %" BFD_VMA_FMT
"x", - off
);
1789 printf (" + %" BFD_VMA_FMT
"x", off
);
1795 bfd_vma off
= rels
[i
].r_addend
;
1797 printf ("%*c", is_32bit_elf
? 12 : 20, ' ');
1798 if ((bfd_signed_vma
) off
< 0)
1799 printf ("-%" BFD_VMA_FMT
"x", - off
);
1801 printf ("%" BFD_VMA_FMT
"x", off
);
1804 if (filedata
->file_header
.e_machine
== EM_SPARCV9
1806 && streq (rtype
, "R_SPARC_OLO10"))
1807 printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (inf
));
1812 if (! is_32bit_elf
&& filedata
->file_header
.e_machine
== EM_MIPS
)
1814 bfd_vma type2
= ELF64_MIPS_R_TYPE2 (inf
);
1815 bfd_vma type3
= ELF64_MIPS_R_TYPE3 (inf
);
1816 const char * rtype2
= elf_mips_reloc_type (type2
);
1817 const char * rtype3
= elf_mips_reloc_type (type3
);
1819 printf (" Type2: ");
1822 printf (_("unrecognized: %-7lx"),
1823 (unsigned long) type2
& 0xffffffff);
1825 printf ("%-17.17s", rtype2
);
1827 printf ("\n Type3: ");
1830 printf (_("unrecognized: %-7lx"),
1831 (unsigned long) type3
& 0xffffffff);
1833 printf ("%-17.17s", rtype3
);
1846 get_aarch64_dynamic_type (unsigned long type
)
1850 case DT_AARCH64_BTI_PLT
: return "AARCH64_BTI_PLT";
1851 case DT_AARCH64_PAC_PLT
: return "AARCH64_PAC_PLT";
1852 case DT_AARCH64_VARIANT_PCS
: return "AARCH64_VARIANT_PCS";
1859 get_mips_dynamic_type (unsigned long type
)
1863 case DT_MIPS_RLD_VERSION
: return "MIPS_RLD_VERSION";
1864 case DT_MIPS_TIME_STAMP
: return "MIPS_TIME_STAMP";
1865 case DT_MIPS_ICHECKSUM
: return "MIPS_ICHECKSUM";
1866 case DT_MIPS_IVERSION
: return "MIPS_IVERSION";
1867 case DT_MIPS_FLAGS
: return "MIPS_FLAGS";
1868 case DT_MIPS_BASE_ADDRESS
: return "MIPS_BASE_ADDRESS";
1869 case DT_MIPS_MSYM
: return "MIPS_MSYM";
1870 case DT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
1871 case DT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
1872 case DT_MIPS_LOCAL_GOTNO
: return "MIPS_LOCAL_GOTNO";
1873 case DT_MIPS_CONFLICTNO
: return "MIPS_CONFLICTNO";
1874 case DT_MIPS_LIBLISTNO
: return "MIPS_LIBLISTNO";
1875 case DT_MIPS_SYMTABNO
: return "MIPS_SYMTABNO";
1876 case DT_MIPS_UNREFEXTNO
: return "MIPS_UNREFEXTNO";
1877 case DT_MIPS_GOTSYM
: return "MIPS_GOTSYM";
1878 case DT_MIPS_HIPAGENO
: return "MIPS_HIPAGENO";
1879 case DT_MIPS_RLD_MAP
: return "MIPS_RLD_MAP";
1880 case DT_MIPS_RLD_MAP_REL
: return "MIPS_RLD_MAP_REL";
1881 case DT_MIPS_DELTA_CLASS
: return "MIPS_DELTA_CLASS";
1882 case DT_MIPS_DELTA_CLASS_NO
: return "MIPS_DELTA_CLASS_NO";
1883 case DT_MIPS_DELTA_INSTANCE
: return "MIPS_DELTA_INSTANCE";
1884 case DT_MIPS_DELTA_INSTANCE_NO
: return "MIPS_DELTA_INSTANCE_NO";
1885 case DT_MIPS_DELTA_RELOC
: return "MIPS_DELTA_RELOC";
1886 case DT_MIPS_DELTA_RELOC_NO
: return "MIPS_DELTA_RELOC_NO";
1887 case DT_MIPS_DELTA_SYM
: return "MIPS_DELTA_SYM";
1888 case DT_MIPS_DELTA_SYM_NO
: return "MIPS_DELTA_SYM_NO";
1889 case DT_MIPS_DELTA_CLASSSYM
: return "MIPS_DELTA_CLASSSYM";
1890 case DT_MIPS_DELTA_CLASSSYM_NO
: return "MIPS_DELTA_CLASSSYM_NO";
1891 case DT_MIPS_CXX_FLAGS
: return "MIPS_CXX_FLAGS";
1892 case DT_MIPS_PIXIE_INIT
: return "MIPS_PIXIE_INIT";
1893 case DT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
1894 case DT_MIPS_LOCALPAGE_GOTIDX
: return "MIPS_LOCALPAGE_GOTIDX";
1895 case DT_MIPS_LOCAL_GOTIDX
: return "MIPS_LOCAL_GOTIDX";
1896 case DT_MIPS_HIDDEN_GOTIDX
: return "MIPS_HIDDEN_GOTIDX";
1897 case DT_MIPS_PROTECTED_GOTIDX
: return "MIPS_PROTECTED_GOTIDX";
1898 case DT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
1899 case DT_MIPS_INTERFACE
: return "MIPS_INTERFACE";
1900 case DT_MIPS_DYNSTR_ALIGN
: return "MIPS_DYNSTR_ALIGN";
1901 case DT_MIPS_INTERFACE_SIZE
: return "MIPS_INTERFACE_SIZE";
1902 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR
: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
1903 case DT_MIPS_PERF_SUFFIX
: return "MIPS_PERF_SUFFIX";
1904 case DT_MIPS_COMPACT_SIZE
: return "MIPS_COMPACT_SIZE";
1905 case DT_MIPS_GP_VALUE
: return "MIPS_GP_VALUE";
1906 case DT_MIPS_AUX_DYNAMIC
: return "MIPS_AUX_DYNAMIC";
1907 case DT_MIPS_PLTGOT
: return "MIPS_PLTGOT";
1908 case DT_MIPS_RWPLT
: return "MIPS_RWPLT";
1909 case DT_MIPS_XHASH
: return "MIPS_XHASH";
1916 get_sparc64_dynamic_type (unsigned long type
)
1920 case DT_SPARC_REGISTER
: return "SPARC_REGISTER";
1927 get_ppc_dynamic_type (unsigned long type
)
1931 case DT_PPC_GOT
: return "PPC_GOT";
1932 case DT_PPC_OPT
: return "PPC_OPT";
1939 get_ppc64_dynamic_type (unsigned long type
)
1943 case DT_PPC64_GLINK
: return "PPC64_GLINK";
1944 case DT_PPC64_OPD
: return "PPC64_OPD";
1945 case DT_PPC64_OPDSZ
: return "PPC64_OPDSZ";
1946 case DT_PPC64_OPT
: return "PPC64_OPT";
1953 get_parisc_dynamic_type (unsigned long type
)
1957 case DT_HP_LOAD_MAP
: return "HP_LOAD_MAP";
1958 case DT_HP_DLD_FLAGS
: return "HP_DLD_FLAGS";
1959 case DT_HP_DLD_HOOK
: return "HP_DLD_HOOK";
1960 case DT_HP_UX10_INIT
: return "HP_UX10_INIT";
1961 case DT_HP_UX10_INITSZ
: return "HP_UX10_INITSZ";
1962 case DT_HP_PREINIT
: return "HP_PREINIT";
1963 case DT_HP_PREINITSZ
: return "HP_PREINITSZ";
1964 case DT_HP_NEEDED
: return "HP_NEEDED";
1965 case DT_HP_TIME_STAMP
: return "HP_TIME_STAMP";
1966 case DT_HP_CHECKSUM
: return "HP_CHECKSUM";
1967 case DT_HP_GST_SIZE
: return "HP_GST_SIZE";
1968 case DT_HP_GST_VERSION
: return "HP_GST_VERSION";
1969 case DT_HP_GST_HASHVAL
: return "HP_GST_HASHVAL";
1970 case DT_HP_EPLTREL
: return "HP_GST_EPLTREL";
1971 case DT_HP_EPLTRELSZ
: return "HP_GST_EPLTRELSZ";
1972 case DT_HP_FILTERED
: return "HP_FILTERED";
1973 case DT_HP_FILTER_TLS
: return "HP_FILTER_TLS";
1974 case DT_HP_COMPAT_FILTERED
: return "HP_COMPAT_FILTERED";
1975 case DT_HP_LAZYLOAD
: return "HP_LAZYLOAD";
1976 case DT_HP_BIND_NOW_COUNT
: return "HP_BIND_NOW_COUNT";
1977 case DT_PLT
: return "PLT";
1978 case DT_PLT_SIZE
: return "PLT_SIZE";
1979 case DT_DLT
: return "DLT";
1980 case DT_DLT_SIZE
: return "DLT_SIZE";
1987 get_ia64_dynamic_type (unsigned long type
)
1991 case DT_IA_64_PLT_RESERVE
: return "IA_64_PLT_RESERVE";
1992 case DT_IA_64_VMS_SUBTYPE
: return "VMS_SUBTYPE";
1993 case DT_IA_64_VMS_IMGIOCNT
: return "VMS_IMGIOCNT";
1994 case DT_IA_64_VMS_LNKFLAGS
: return "VMS_LNKFLAGS";
1995 case DT_IA_64_VMS_VIR_MEM_BLK_SIZ
: return "VMS_VIR_MEM_BLK_SIZ";
1996 case DT_IA_64_VMS_IDENT
: return "VMS_IDENT";
1997 case DT_IA_64_VMS_NEEDED_IDENT
: return "VMS_NEEDED_IDENT";
1998 case DT_IA_64_VMS_IMG_RELA_CNT
: return "VMS_IMG_RELA_CNT";
1999 case DT_IA_64_VMS_SEG_RELA_CNT
: return "VMS_SEG_RELA_CNT";
2000 case DT_IA_64_VMS_FIXUP_RELA_CNT
: return "VMS_FIXUP_RELA_CNT";
2001 case DT_IA_64_VMS_FIXUP_NEEDED
: return "VMS_FIXUP_NEEDED";
2002 case DT_IA_64_VMS_SYMVEC_CNT
: return "VMS_SYMVEC_CNT";
2003 case DT_IA_64_VMS_XLATED
: return "VMS_XLATED";
2004 case DT_IA_64_VMS_STACKSIZE
: return "VMS_STACKSIZE";
2005 case DT_IA_64_VMS_UNWINDSZ
: return "VMS_UNWINDSZ";
2006 case DT_IA_64_VMS_UNWIND_CODSEG
: return "VMS_UNWIND_CODSEG";
2007 case DT_IA_64_VMS_UNWIND_INFOSEG
: return "VMS_UNWIND_INFOSEG";
2008 case DT_IA_64_VMS_LINKTIME
: return "VMS_LINKTIME";
2009 case DT_IA_64_VMS_SEG_NO
: return "VMS_SEG_NO";
2010 case DT_IA_64_VMS_SYMVEC_OFFSET
: return "VMS_SYMVEC_OFFSET";
2011 case DT_IA_64_VMS_SYMVEC_SEG
: return "VMS_SYMVEC_SEG";
2012 case DT_IA_64_VMS_UNWIND_OFFSET
: return "VMS_UNWIND_OFFSET";
2013 case DT_IA_64_VMS_UNWIND_SEG
: return "VMS_UNWIND_SEG";
2014 case DT_IA_64_VMS_STRTAB_OFFSET
: return "VMS_STRTAB_OFFSET";
2015 case DT_IA_64_VMS_SYSVER_OFFSET
: return "VMS_SYSVER_OFFSET";
2016 case DT_IA_64_VMS_IMG_RELA_OFF
: return "VMS_IMG_RELA_OFF";
2017 case DT_IA_64_VMS_SEG_RELA_OFF
: return "VMS_SEG_RELA_OFF";
2018 case DT_IA_64_VMS_FIXUP_RELA_OFF
: return "VMS_FIXUP_RELA_OFF";
2019 case DT_IA_64_VMS_PLTGOT_OFFSET
: return "VMS_PLTGOT_OFFSET";
2020 case DT_IA_64_VMS_PLTGOT_SEG
: return "VMS_PLTGOT_SEG";
2021 case DT_IA_64_VMS_FPMODE
: return "VMS_FPMODE";
2028 get_solaris_section_type (unsigned long type
)
2032 case 0x6fffffee: return "SUNW_ancillary";
2033 case 0x6fffffef: return "SUNW_capchain";
2034 case 0x6ffffff0: return "SUNW_capinfo";
2035 case 0x6ffffff1: return "SUNW_symsort";
2036 case 0x6ffffff2: return "SUNW_tlssort";
2037 case 0x6ffffff3: return "SUNW_LDYNSYM";
2038 case 0x6ffffff4: return "SUNW_dof";
2039 case 0x6ffffff5: return "SUNW_cap";
2040 case 0x6ffffff6: return "SUNW_SIGNATURE";
2041 case 0x6ffffff7: return "SUNW_ANNOTATE";
2042 case 0x6ffffff8: return "SUNW_DEBUGSTR";
2043 case 0x6ffffff9: return "SUNW_DEBUG";
2044 case 0x6ffffffa: return "SUNW_move";
2045 case 0x6ffffffb: return "SUNW_COMDAT";
2046 case 0x6ffffffc: return "SUNW_syminfo";
2047 case 0x6ffffffd: return "SUNW_verdef";
2048 case 0x6ffffffe: return "SUNW_verneed";
2049 case 0x6fffffff: return "SUNW_versym";
2050 case 0x70000000: return "SPARC_GOTDATA";
2051 default: return NULL
;
2056 get_alpha_dynamic_type (unsigned long type
)
2060 case DT_ALPHA_PLTRO
: return "ALPHA_PLTRO";
2061 default: return NULL
;
2066 get_score_dynamic_type (unsigned long type
)
2070 case DT_SCORE_BASE_ADDRESS
: return "SCORE_BASE_ADDRESS";
2071 case DT_SCORE_LOCAL_GOTNO
: return "SCORE_LOCAL_GOTNO";
2072 case DT_SCORE_SYMTABNO
: return "SCORE_SYMTABNO";
2073 case DT_SCORE_GOTSYM
: return "SCORE_GOTSYM";
2074 case DT_SCORE_UNREFEXTNO
: return "SCORE_UNREFEXTNO";
2075 case DT_SCORE_HIPAGENO
: return "SCORE_HIPAGENO";
2076 default: return NULL
;
2081 get_tic6x_dynamic_type (unsigned long type
)
2085 case DT_C6000_GSYM_OFFSET
: return "C6000_GSYM_OFFSET";
2086 case DT_C6000_GSTR_OFFSET
: return "C6000_GSTR_OFFSET";
2087 case DT_C6000_DSBT_BASE
: return "C6000_DSBT_BASE";
2088 case DT_C6000_DSBT_SIZE
: return "C6000_DSBT_SIZE";
2089 case DT_C6000_PREEMPTMAP
: return "C6000_PREEMPTMAP";
2090 case DT_C6000_DSBT_INDEX
: return "C6000_DSBT_INDEX";
2091 default: return NULL
;
2096 get_nios2_dynamic_type (unsigned long type
)
2100 case DT_NIOS2_GP
: return "NIOS2_GP";
2101 default: return NULL
;
2106 get_solaris_dynamic_type (unsigned long type
)
2110 case 0x6000000d: return "SUNW_AUXILIARY";
2111 case 0x6000000e: return "SUNW_RTLDINF";
2112 case 0x6000000f: return "SUNW_FILTER";
2113 case 0x60000010: return "SUNW_CAP";
2114 case 0x60000011: return "SUNW_SYMTAB";
2115 case 0x60000012: return "SUNW_SYMSZ";
2116 case 0x60000013: return "SUNW_SORTENT";
2117 case 0x60000014: return "SUNW_SYMSORT";
2118 case 0x60000015: return "SUNW_SYMSORTSZ";
2119 case 0x60000016: return "SUNW_TLSSORT";
2120 case 0x60000017: return "SUNW_TLSSORTSZ";
2121 case 0x60000018: return "SUNW_CAPINFO";
2122 case 0x60000019: return "SUNW_STRPAD";
2123 case 0x6000001a: return "SUNW_CAPCHAIN";
2124 case 0x6000001b: return "SUNW_LDMACH";
2125 case 0x6000001d: return "SUNW_CAPCHAINENT";
2126 case 0x6000001f: return "SUNW_CAPCHAINSZ";
2127 case 0x60000021: return "SUNW_PARENT";
2128 case 0x60000023: return "SUNW_ASLR";
2129 case 0x60000025: return "SUNW_RELAX";
2130 case 0x60000029: return "SUNW_NXHEAP";
2131 case 0x6000002b: return "SUNW_NXSTACK";
2133 case 0x70000001: return "SPARC_REGISTER";
2134 case 0x7ffffffd: return "AUXILIARY";
2135 case 0x7ffffffe: return "USED";
2136 case 0x7fffffff: return "FILTER";
2138 default: return NULL
;
2143 get_dynamic_type (Filedata
* filedata
, unsigned long type
)
2145 static char buff
[64];
2149 case DT_NULL
: return "NULL";
2150 case DT_NEEDED
: return "NEEDED";
2151 case DT_PLTRELSZ
: return "PLTRELSZ";
2152 case DT_PLTGOT
: return "PLTGOT";
2153 case DT_HASH
: return "HASH";
2154 case DT_STRTAB
: return "STRTAB";
2155 case DT_SYMTAB
: return "SYMTAB";
2156 case DT_RELA
: return "RELA";
2157 case DT_RELASZ
: return "RELASZ";
2158 case DT_RELAENT
: return "RELAENT";
2159 case DT_STRSZ
: return "STRSZ";
2160 case DT_SYMENT
: return "SYMENT";
2161 case DT_INIT
: return "INIT";
2162 case DT_FINI
: return "FINI";
2163 case DT_SONAME
: return "SONAME";
2164 case DT_RPATH
: return "RPATH";
2165 case DT_SYMBOLIC
: return "SYMBOLIC";
2166 case DT_REL
: return "REL";
2167 case DT_RELSZ
: return "RELSZ";
2168 case DT_RELENT
: return "RELENT";
2169 case DT_PLTREL
: return "PLTREL";
2170 case DT_DEBUG
: return "DEBUG";
2171 case DT_TEXTREL
: return "TEXTREL";
2172 case DT_JMPREL
: return "JMPREL";
2173 case DT_BIND_NOW
: return "BIND_NOW";
2174 case DT_INIT_ARRAY
: return "INIT_ARRAY";
2175 case DT_FINI_ARRAY
: return "FINI_ARRAY";
2176 case DT_INIT_ARRAYSZ
: return "INIT_ARRAYSZ";
2177 case DT_FINI_ARRAYSZ
: return "FINI_ARRAYSZ";
2178 case DT_RUNPATH
: return "RUNPATH";
2179 case DT_FLAGS
: return "FLAGS";
2181 case DT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
2182 case DT_PREINIT_ARRAYSZ
: return "PREINIT_ARRAYSZ";
2183 case DT_SYMTAB_SHNDX
: return "SYMTAB_SHNDX";
2185 case DT_CHECKSUM
: return "CHECKSUM";
2186 case DT_PLTPADSZ
: return "PLTPADSZ";
2187 case DT_MOVEENT
: return "MOVEENT";
2188 case DT_MOVESZ
: return "MOVESZ";
2189 case DT_FEATURE
: return "FEATURE";
2190 case DT_POSFLAG_1
: return "POSFLAG_1";
2191 case DT_SYMINSZ
: return "SYMINSZ";
2192 case DT_SYMINENT
: return "SYMINENT"; /* aka VALRNGHI */
2194 case DT_ADDRRNGLO
: return "ADDRRNGLO";
2195 case DT_CONFIG
: return "CONFIG";
2196 case DT_DEPAUDIT
: return "DEPAUDIT";
2197 case DT_AUDIT
: return "AUDIT";
2198 case DT_PLTPAD
: return "PLTPAD";
2199 case DT_MOVETAB
: return "MOVETAB";
2200 case DT_SYMINFO
: return "SYMINFO"; /* aka ADDRRNGHI */
2202 case DT_VERSYM
: return "VERSYM";
2204 case DT_TLSDESC_GOT
: return "TLSDESC_GOT";
2205 case DT_TLSDESC_PLT
: return "TLSDESC_PLT";
2206 case DT_RELACOUNT
: return "RELACOUNT";
2207 case DT_RELCOUNT
: return "RELCOUNT";
2208 case DT_FLAGS_1
: return "FLAGS_1";
2209 case DT_VERDEF
: return "VERDEF";
2210 case DT_VERDEFNUM
: return "VERDEFNUM";
2211 case DT_VERNEED
: return "VERNEED";
2212 case DT_VERNEEDNUM
: return "VERNEEDNUM";
2214 case DT_AUXILIARY
: return "AUXILIARY";
2215 case DT_USED
: return "USED";
2216 case DT_FILTER
: return "FILTER";
2218 case DT_GNU_PRELINKED
: return "GNU_PRELINKED";
2219 case DT_GNU_CONFLICT
: return "GNU_CONFLICT";
2220 case DT_GNU_CONFLICTSZ
: return "GNU_CONFLICTSZ";
2221 case DT_GNU_LIBLIST
: return "GNU_LIBLIST";
2222 case DT_GNU_LIBLISTSZ
: return "GNU_LIBLISTSZ";
2223 case DT_GNU_HASH
: return "GNU_HASH";
2226 if ((type
>= DT_LOPROC
) && (type
<= DT_HIPROC
))
2228 const char * result
;
2230 switch (filedata
->file_header
.e_machine
)
2233 result
= get_aarch64_dynamic_type (type
);
2236 case EM_MIPS_RS3_LE
:
2237 result
= get_mips_dynamic_type (type
);
2240 result
= get_sparc64_dynamic_type (type
);
2243 result
= get_ppc_dynamic_type (type
);
2246 result
= get_ppc64_dynamic_type (type
);
2249 result
= get_ia64_dynamic_type (type
);
2252 result
= get_alpha_dynamic_type (type
);
2255 result
= get_score_dynamic_type (type
);
2258 result
= get_tic6x_dynamic_type (type
);
2260 case EM_ALTERA_NIOS2
:
2261 result
= get_nios2_dynamic_type (type
);
2264 if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_SOLARIS
)
2265 result
= get_solaris_dynamic_type (type
);
2274 snprintf (buff
, sizeof (buff
), _("Processor Specific: %lx"), type
);
2276 else if (((type
>= DT_LOOS
) && (type
<= DT_HIOS
))
2277 || (filedata
->file_header
.e_machine
== EM_PARISC
2278 && (type
>= OLD_DT_LOOS
) && (type
<= OLD_DT_HIOS
)))
2280 const char * result
;
2282 switch (filedata
->file_header
.e_machine
)
2285 result
= get_parisc_dynamic_type (type
);
2288 result
= get_ia64_dynamic_type (type
);
2291 if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_SOLARIS
)
2292 result
= get_solaris_dynamic_type (type
);
2301 snprintf (buff
, sizeof (buff
), _("Operating System specific: %lx"),
2305 snprintf (buff
, sizeof (buff
), _("<unknown>: %lx"), type
);
2312 get_file_type (unsigned e_type
)
2314 static char buff
[64];
2318 case ET_NONE
: return _("NONE (None)");
2319 case ET_REL
: return _("REL (Relocatable file)");
2320 case ET_EXEC
: return _("EXEC (Executable file)");
2321 case ET_DYN
: return _("DYN (Shared object file)");
2322 case ET_CORE
: return _("CORE (Core file)");
2325 if ((e_type
>= ET_LOPROC
) && (e_type
<= ET_HIPROC
))
2326 snprintf (buff
, sizeof (buff
), _("Processor Specific: (%x)"), e_type
);
2327 else if ((e_type
>= ET_LOOS
) && (e_type
<= ET_HIOS
))
2328 snprintf (buff
, sizeof (buff
), _("OS Specific: (%x)"), e_type
);
2330 snprintf (buff
, sizeof (buff
), _("<unknown>: %x"), e_type
);
2336 get_machine_name (unsigned e_machine
)
2338 static char buff
[64]; /* XXX */
2342 /* Please keep this switch table sorted by increasing EM_ value. */
2344 case EM_NONE
: return _("None");
2345 case EM_M32
: return "WE32100";
2346 case EM_SPARC
: return "Sparc";
2347 case EM_386
: return "Intel 80386";
2348 case EM_68K
: return "MC68000";
2349 case EM_88K
: return "MC88000";
2350 case EM_IAMCU
: return "Intel MCU";
2351 case EM_860
: return "Intel 80860";
2352 case EM_MIPS
: return "MIPS R3000";
2353 case EM_S370
: return "IBM System/370";
2355 case EM_MIPS_RS3_LE
: return "MIPS R4000 big-endian";
2356 case EM_OLD_SPARCV9
: return "Sparc v9 (old)";
2357 case EM_PARISC
: return "HPPA";
2358 case EM_VPP550
: return "Fujitsu VPP500";
2359 case EM_SPARC32PLUS
: return "Sparc v8+" ;
2360 case EM_960
: return "Intel 80960";
2361 case EM_PPC
: return "PowerPC";
2363 case EM_PPC64
: return "PowerPC64";
2365 case EM_S390
: return "IBM S/390";
2366 case EM_SPU
: return "SPU";
2368 case EM_V800
: return "Renesas V850 (using RH850 ABI)";
2369 case EM_FR20
: return "Fujitsu FR20";
2370 case EM_RH32
: return "TRW RH32";
2371 case EM_MCORE
: return "MCORE";
2373 case EM_ARM
: return "ARM";
2374 case EM_OLD_ALPHA
: return "Digital Alpha (old)";
2375 case EM_SH
: return "Renesas / SuperH SH";
2376 case EM_SPARCV9
: return "Sparc v9";
2377 case EM_TRICORE
: return "Siemens Tricore";
2378 case EM_ARC
: return "ARC";
2379 case EM_H8_300
: return "Renesas H8/300";
2380 case EM_H8_300H
: return "Renesas H8/300H";
2381 case EM_H8S
: return "Renesas H8S";
2382 case EM_H8_500
: return "Renesas H8/500";
2384 case EM_IA_64
: return "Intel IA-64";
2385 case EM_MIPS_X
: return "Stanford MIPS-X";
2386 case EM_COLDFIRE
: return "Motorola Coldfire";
2387 case EM_68HC12
: return "Motorola MC68HC12 Microcontroller";
2388 case EM_MMA
: return "Fujitsu Multimedia Accelerator";
2389 case EM_PCP
: return "Siemens PCP";
2390 case EM_NCPU
: return "Sony nCPU embedded RISC processor";
2391 case EM_NDR1
: return "Denso NDR1 microprocesspr";
2392 case EM_STARCORE
: return "Motorola Star*Core processor";
2393 case EM_ME16
: return "Toyota ME16 processor";
2395 case EM_ST100
: return "STMicroelectronics ST100 processor";
2396 case EM_TINYJ
: return "Advanced Logic Corp. TinyJ embedded processor";
2397 case EM_X86_64
: return "Advanced Micro Devices X86-64";
2398 case EM_PDSP
: return "Sony DSP processor";
2399 case EM_PDP10
: return "Digital Equipment Corp. PDP-10";
2400 case EM_PDP11
: return "Digital Equipment Corp. PDP-11";
2401 case EM_FX66
: return "Siemens FX66 microcontroller";
2402 case EM_ST9PLUS
: return "STMicroelectronics ST9+ 8/16 bit microcontroller";
2403 case EM_ST7
: return "STMicroelectronics ST7 8-bit microcontroller";
2404 case EM_68HC16
: return "Motorola MC68HC16 Microcontroller";
2406 case EM_68HC11
: return "Motorola MC68HC11 Microcontroller";
2407 case EM_68HC08
: return "Motorola MC68HC08 Microcontroller";
2408 case EM_68HC05
: return "Motorola MC68HC05 Microcontroller";
2409 case EM_SVX
: return "Silicon Graphics SVx";
2410 case EM_ST19
: return "STMicroelectronics ST19 8-bit microcontroller";
2411 case EM_VAX
: return "Digital VAX";
2412 case EM_CRIS
: return "Axis Communications 32-bit embedded processor";
2413 case EM_JAVELIN
: return "Infineon Technologies 32-bit embedded cpu";
2414 case EM_FIREPATH
: return "Element 14 64-bit DSP processor";
2415 case EM_ZSP
: return "LSI Logic's 16-bit DSP processor";
2417 case EM_MMIX
: return "Donald Knuth's educational 64-bit processor";
2418 case EM_HUANY
: return "Harvard Universitys's machine-independent object format";
2419 case EM_PRISM
: return "Vitesse Prism";
2421 case EM_AVR
: return "Atmel AVR 8-bit microcontroller";
2422 case EM_CYGNUS_FR30
:
2423 case EM_FR30
: return "Fujitsu FR30";
2424 case EM_CYGNUS_D10V
:
2425 case EM_D10V
: return "d10v";
2426 case EM_CYGNUS_D30V
:
2427 case EM_D30V
: return "d30v";
2428 case EM_CYGNUS_V850
:
2429 case EM_V850
: return "Renesas V850";
2430 case EM_CYGNUS_M32R
:
2431 case EM_M32R
: return "Renesas M32R (formerly Mitsubishi M32r)";
2432 case EM_CYGNUS_MN10300
:
2433 case EM_MN10300
: return "mn10300";
2435 case EM_CYGNUS_MN10200
:
2436 case EM_MN10200
: return "mn10200";
2437 case EM_PJ
: return "picoJava";
2438 case EM_OR1K
: return "OpenRISC 1000";
2439 case EM_ARC_COMPACT
: return "ARCompact";
2441 case EM_XTENSA
: return "Tensilica Xtensa Processor";
2442 case EM_VIDEOCORE
: return "Alphamosaic VideoCore processor";
2443 case EM_TMM_GPP
: return "Thompson Multimedia General Purpose Processor";
2444 case EM_NS32K
: return "National Semiconductor 32000 series";
2445 case EM_TPC
: return "Tenor Network TPC processor";
2446 case EM_SNP1K
: return "Trebia SNP 1000 processor";
2448 case EM_ST200
: return "STMicroelectronics ST200 microcontroller";
2450 case EM_IP2K
: return "Ubicom IP2xxx 8-bit microcontrollers";
2451 case EM_MAX
: return "MAX Processor";
2452 case EM_CR
: return "National Semiconductor CompactRISC";
2453 case EM_F2MC16
: return "Fujitsu F2MC16";
2454 case EM_MSP430
: return "Texas Instruments msp430 microcontroller";
2455 case EM_BLACKFIN
: return "Analog Devices Blackfin";
2456 case EM_SE_C33
: return "S1C33 Family of Seiko Epson processors";
2457 case EM_SEP
: return "Sharp embedded microprocessor";
2458 case EM_ARCA
: return "Arca RISC microprocessor";
2460 case EM_UNICORE
: return "Unicore";
2461 case EM_EXCESS
: return "eXcess 16/32/64-bit configurable embedded CPU";
2462 case EM_DXP
: return "Icera Semiconductor Inc. Deep Execution Processor";
2463 case EM_ALTERA_NIOS2
: return "Altera Nios II";
2464 case EM_CRX
: return "National Semiconductor CRX microprocessor";
2465 case EM_XGATE
: return "Motorola XGATE embedded processor";
2467 case EM_XC16X
: return "Infineon Technologies xc16x";
2468 case EM_M16C
: return "Renesas M16C series microprocessors";
2469 case EM_DSPIC30F
: return "Microchip Technology dsPIC30F Digital Signal Controller";
2470 case EM_CE
: return "Freescale Communication Engine RISC core";
2472 case EM_M32C
: return "Renesas M32c";
2474 case EM_TSK3000
: return "Altium TSK3000 core";
2475 case EM_RS08
: return "Freescale RS08 embedded processor";
2476 case EM_ECOG2
: return "Cyan Technology eCOG2 microprocessor";
2477 case EM_SCORE
: return "SUNPLUS S+Core";
2478 case EM_DSP24
: return "New Japan Radio (NJR) 24-bit DSP Processor";
2479 case EM_VIDEOCORE3
: return "Broadcom VideoCore III processor";
2480 case EM_LATTICEMICO32
: return "Lattice Mico32";
2481 case EM_SE_C17
: return "Seiko Epson C17 family";
2483 case EM_TI_C6000
: return "Texas Instruments TMS320C6000 DSP family";
2484 case EM_TI_C2000
: return "Texas Instruments TMS320C2000 DSP family";
2485 case EM_TI_C5500
: return "Texas Instruments TMS320C55x DSP family";
2486 case EM_TI_PRU
: return "TI PRU I/O processor";
2488 case EM_MMDSP_PLUS
: return "STMicroelectronics 64bit VLIW Data Signal Processor";
2489 case EM_CYPRESS_M8C
: return "Cypress M8C microprocessor";
2490 case EM_R32C
: return "Renesas R32C series microprocessors";
2491 case EM_TRIMEDIA
: return "NXP Semiconductors TriMedia architecture family";
2492 case EM_QDSP6
: return "QUALCOMM DSP6 Processor";
2493 case EM_8051
: return "Intel 8051 and variants";
2494 case EM_STXP7X
: return "STMicroelectronics STxP7x family";
2495 case EM_NDS32
: return "Andes Technology compact code size embedded RISC processor family";
2496 case EM_ECOG1X
: return "Cyan Technology eCOG1X family";
2497 case EM_MAXQ30
: return "Dallas Semiconductor MAXQ30 Core microcontrollers";
2499 case EM_XIMO16
: return "New Japan Radio (NJR) 16-bit DSP Processor";
2500 case EM_MANIK
: return "M2000 Reconfigurable RISC Microprocessor";
2501 case EM_CRAYNV2
: return "Cray Inc. NV2 vector architecture";
2502 case EM_RX
: return "Renesas RX";
2503 case EM_METAG
: return "Imagination Technologies Meta processor architecture";
2504 case EM_MCST_ELBRUS
: return "MCST Elbrus general purpose hardware architecture";
2505 case EM_ECOG16
: return "Cyan Technology eCOG16 family";
2508 case EM_MICROBLAZE_OLD
: return "Xilinx MicroBlaze";
2509 case EM_ETPU
: return "Freescale Extended Time Processing Unit";
2510 case EM_SLE9X
: return "Infineon Technologies SLE9X core";
2512 case EM_L1OM
: return "Intel L1OM";
2513 case EM_K1OM
: return "Intel K1OM";
2514 case EM_INTEL182
: return "Intel (reserved)";
2515 case EM_AARCH64
: return "AArch64";
2516 case EM_ARM184
: return "ARM (reserved)";
2517 case EM_AVR32
: return "Atmel Corporation 32-bit microprocessor";
2518 case EM_STM8
: return "STMicroeletronics STM8 8-bit microcontroller";
2519 case EM_TILE64
: return "Tilera TILE64 multicore architecture family";
2520 case EM_TILEPRO
: return "Tilera TILEPro multicore architecture family";
2522 case EM_CUDA
: return "NVIDIA CUDA architecture";
2523 case EM_TILEGX
: return "Tilera TILE-Gx multicore architecture family";
2524 case EM_CLOUDSHIELD
: return "CloudShield architecture family";
2525 case EM_COREA_1ST
: return "KIPO-KAIST Core-A 1st generation processor family";
2526 case EM_COREA_2ND
: return "KIPO-KAIST Core-A 2nd generation processor family";
2527 case EM_ARC_COMPACT2
: return "ARCv2";
2528 case EM_OPEN8
: return "Open8 8-bit RISC soft processor core";
2529 case EM_RL78
: return "Renesas RL78";
2530 case EM_VIDEOCORE5
: return "Broadcom VideoCore V processor";
2531 case EM_78K0R
: return "Renesas 78K0R";
2533 case EM_56800EX
: return "Freescale 56800EX Digital Signal Controller (DSC)";
2534 case EM_BA1
: return "Beyond BA1 CPU architecture";
2535 case EM_BA2
: return "Beyond BA2 CPU architecture";
2536 case EM_XCORE
: return "XMOS xCORE processor family";
2537 case EM_MCHP_PIC
: return "Microchip 8-bit PIC(r) family";
2539 case EM_KM32
: return "KM211 KM32 32-bit processor";
2540 case EM_KMX32
: return "KM211 KMX32 32-bit processor";
2541 case EM_KMX16
: return "KM211 KMX16 16-bit processor";
2542 case EM_KMX8
: return "KM211 KMX8 8-bit processor";
2543 case EM_KVARC
: return "KM211 KVARC processor";
2544 case EM_CDP
: return "Paneve CDP architecture family";
2545 case EM_COGE
: return "Cognitive Smart Memory Processor";
2546 case EM_COOL
: return "Bluechip Systems CoolEngine";
2547 case EM_NORC
: return "Nanoradio Optimized RISC";
2548 case EM_CSR_KALIMBA
: return "CSR Kalimba architecture family";
2550 case EM_Z80
: return "Zilog Z80";
2551 case EM_VISIUM
: return "CDS VISIUMcore processor";
2552 case EM_FT32
: return "FTDI Chip FT32";
2553 case EM_MOXIE
: return "Moxie";
2554 case EM_AMDGPU
: return "AMD GPU";
2555 case EM_RISCV
: return "RISC-V";
2556 case EM_LANAI
: return "Lanai 32-bit processor";
2557 case EM_BPF
: return "Linux BPF";
2558 case EM_NFP
: return "Netronome Flow Processor";
2560 /* Large numbers... */
2561 case EM_MT
: return "Morpho Techologies MT processor";
2562 case EM_ALPHA
: return "Alpha";
2563 case EM_WEBASSEMBLY
: return "Web Assembly";
2564 case EM_DLX
: return "OpenDLX";
2565 case EM_XSTORMY16
: return "Sanyo XStormy16 CPU core";
2566 case EM_IQ2000
: return "Vitesse IQ2000";
2568 case EM_NIOS32
: return "Altera Nios";
2569 case EM_CYGNUS_MEP
: return "Toshiba MeP Media Engine";
2570 case EM_ADAPTEVA_EPIPHANY
: return "Adapteva EPIPHANY";
2571 case EM_CYGNUS_FRV
: return "Fujitsu FR-V";
2572 case EM_S12Z
: return "Freescale S12Z";
2573 case EM_CSKY
: return "C-SKY";
2576 snprintf (buff
, sizeof (buff
), _("<unknown>: 0x%x"), e_machine
);
2582 decode_ARC_machine_flags (unsigned e_flags
, unsigned e_machine
, char buf
[])
2584 /* ARC has two machine types EM_ARC_COMPACT and EM_ARC_COMPACT2. Some
2585 other compilers don't a specific architecture type in the e_flags, and
2586 instead use EM_ARC_COMPACT for old ARC600, ARC601, and ARC700
2587 architectures, and switch to EM_ARC_COMPACT2 for newer ARCEM and ARCHS
2590 Th GNU tools follows this use of EM_ARC_COMPACT and EM_ARC_COMPACT2,
2591 but also sets a specific architecture type in the e_flags field.
2593 However, when decoding the flags we don't worry if we see an
2594 unexpected pairing, for example EM_ARC_COMPACT machine type, with
2595 ARCEM architecture type. */
2597 switch (e_flags
& EF_ARC_MACH_MSK
)
2599 /* We only expect these to occur for EM_ARC_COMPACT2. */
2600 case EF_ARC_CPU_ARCV2EM
:
2601 strcat (buf
, ", ARC EM");
2603 case EF_ARC_CPU_ARCV2HS
:
2604 strcat (buf
, ", ARC HS");
2607 /* We only expect these to occur for EM_ARC_COMPACT. */
2608 case E_ARC_MACH_ARC600
:
2609 strcat (buf
, ", ARC600");
2611 case E_ARC_MACH_ARC601
:
2612 strcat (buf
, ", ARC601");
2614 case E_ARC_MACH_ARC700
:
2615 strcat (buf
, ", ARC700");
2618 /* The only times we should end up here are (a) A corrupt ELF, (b) A
2619 new ELF with new architecture being read by an old version of
2620 readelf, or (c) An ELF built with non-GNU compiler that does not
2621 set the architecture in the e_flags. */
2623 if (e_machine
== EM_ARC_COMPACT
)
2624 strcat (buf
, ", Unknown ARCompact");
2626 strcat (buf
, ", Unknown ARC");
2630 switch (e_flags
& EF_ARC_OSABI_MSK
)
2632 case E_ARC_OSABI_ORIG
:
2633 strcat (buf
, ", (ABI:legacy)");
2635 case E_ARC_OSABI_V2
:
2636 strcat (buf
, ", (ABI:v2)");
2638 /* Only upstream 3.9+ kernels will support ARCv2 ISA. */
2639 case E_ARC_OSABI_V3
:
2640 strcat (buf
, ", v3 no-legacy-syscalls ABI");
2642 case E_ARC_OSABI_V4
:
2643 strcat (buf
, ", v4 ABI");
2646 strcat (buf
, ", unrecognised ARC OSABI flag");
2652 decode_ARM_machine_flags (unsigned e_flags
, char buf
[])
2655 bfd_boolean unknown
= FALSE
;
2657 eabi
= EF_ARM_EABI_VERSION (e_flags
);
2658 e_flags
&= ~ EF_ARM_EABIMASK
;
2660 /* Handle "generic" ARM flags. */
2661 if (e_flags
& EF_ARM_RELEXEC
)
2663 strcat (buf
, ", relocatable executable");
2664 e_flags
&= ~ EF_ARM_RELEXEC
;
2667 if (e_flags
& EF_ARM_PIC
)
2669 strcat (buf
, ", position independent");
2670 e_flags
&= ~ EF_ARM_PIC
;
2673 /* Now handle EABI specific flags. */
2677 strcat (buf
, ", <unrecognized EABI>");
2682 case EF_ARM_EABI_VER1
:
2683 strcat (buf
, ", Version1 EABI");
2688 /* Process flags one bit at a time. */
2689 flag
= e_flags
& - e_flags
;
2694 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
2695 strcat (buf
, ", sorted symbol tables");
2705 case EF_ARM_EABI_VER2
:
2706 strcat (buf
, ", Version2 EABI");
2711 /* Process flags one bit at a time. */
2712 flag
= e_flags
& - e_flags
;
2717 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
2718 strcat (buf
, ", sorted symbol tables");
2721 case EF_ARM_DYNSYMSUSESEGIDX
:
2722 strcat (buf
, ", dynamic symbols use segment index");
2725 case EF_ARM_MAPSYMSFIRST
:
2726 strcat (buf
, ", mapping symbols precede others");
2736 case EF_ARM_EABI_VER3
:
2737 strcat (buf
, ", Version3 EABI");
2740 case EF_ARM_EABI_VER4
:
2741 strcat (buf
, ", Version4 EABI");
2746 /* Process flags one bit at a time. */
2747 flag
= e_flags
& - e_flags
;
2753 strcat (buf
, ", BE8");
2757 strcat (buf
, ", LE8");
2767 case EF_ARM_EABI_VER5
:
2768 strcat (buf
, ", Version5 EABI");
2773 /* Process flags one bit at a time. */
2774 flag
= e_flags
& - e_flags
;
2780 strcat (buf
, ", BE8");
2784 strcat (buf
, ", LE8");
2787 case EF_ARM_ABI_FLOAT_SOFT
: /* Conflicts with EF_ARM_SOFT_FLOAT. */
2788 strcat (buf
, ", soft-float ABI");
2791 case EF_ARM_ABI_FLOAT_HARD
: /* Conflicts with EF_ARM_VFP_FLOAT. */
2792 strcat (buf
, ", hard-float ABI");
2802 case EF_ARM_EABI_UNKNOWN
:
2803 strcat (buf
, ", GNU EABI");
2808 /* Process flags one bit at a time. */
2809 flag
= e_flags
& - e_flags
;
2814 case EF_ARM_INTERWORK
:
2815 strcat (buf
, ", interworking enabled");
2818 case EF_ARM_APCS_26
:
2819 strcat (buf
, ", uses APCS/26");
2822 case EF_ARM_APCS_FLOAT
:
2823 strcat (buf
, ", uses APCS/float");
2827 strcat (buf
, ", position independent");
2831 strcat (buf
, ", 8 bit structure alignment");
2834 case EF_ARM_NEW_ABI
:
2835 strcat (buf
, ", uses new ABI");
2838 case EF_ARM_OLD_ABI
:
2839 strcat (buf
, ", uses old ABI");
2842 case EF_ARM_SOFT_FLOAT
:
2843 strcat (buf
, ", software FP");
2846 case EF_ARM_VFP_FLOAT
:
2847 strcat (buf
, ", VFP");
2850 case EF_ARM_MAVERICK_FLOAT
:
2851 strcat (buf
, ", Maverick FP");
2862 strcat (buf
,_(", <unknown>"));
2866 decode_AVR_machine_flags (unsigned e_flags
, char buf
[], size_t size
)
2868 --size
; /* Leave space for null terminator. */
2870 switch (e_flags
& EF_AVR_MACH
)
2872 case E_AVR_MACH_AVR1
:
2873 strncat (buf
, ", avr:1", size
);
2875 case E_AVR_MACH_AVR2
:
2876 strncat (buf
, ", avr:2", size
);
2878 case E_AVR_MACH_AVR25
:
2879 strncat (buf
, ", avr:25", size
);
2881 case E_AVR_MACH_AVR3
:
2882 strncat (buf
, ", avr:3", size
);
2884 case E_AVR_MACH_AVR31
:
2885 strncat (buf
, ", avr:31", size
);
2887 case E_AVR_MACH_AVR35
:
2888 strncat (buf
, ", avr:35", size
);
2890 case E_AVR_MACH_AVR4
:
2891 strncat (buf
, ", avr:4", size
);
2893 case E_AVR_MACH_AVR5
:
2894 strncat (buf
, ", avr:5", size
);
2896 case E_AVR_MACH_AVR51
:
2897 strncat (buf
, ", avr:51", size
);
2899 case E_AVR_MACH_AVR6
:
2900 strncat (buf
, ", avr:6", size
);
2902 case E_AVR_MACH_AVRTINY
:
2903 strncat (buf
, ", avr:100", size
);
2905 case E_AVR_MACH_XMEGA1
:
2906 strncat (buf
, ", avr:101", size
);
2908 case E_AVR_MACH_XMEGA2
:
2909 strncat (buf
, ", avr:102", size
);
2911 case E_AVR_MACH_XMEGA3
:
2912 strncat (buf
, ", avr:103", size
);
2914 case E_AVR_MACH_XMEGA4
:
2915 strncat (buf
, ", avr:104", size
);
2917 case E_AVR_MACH_XMEGA5
:
2918 strncat (buf
, ", avr:105", size
);
2920 case E_AVR_MACH_XMEGA6
:
2921 strncat (buf
, ", avr:106", size
);
2923 case E_AVR_MACH_XMEGA7
:
2924 strncat (buf
, ", avr:107", size
);
2927 strncat (buf
, ", avr:<unknown>", size
);
2931 size
-= strlen (buf
);
2932 if (e_flags
& EF_AVR_LINKRELAX_PREPARED
)
2933 strncat (buf
, ", link-relax", size
);
2937 decode_NDS32_machine_flags (unsigned e_flags
, char buf
[], size_t size
)
2943 bfd_boolean has_fpu
= FALSE
;
2946 static const char *ABI_STRINGS
[] =
2948 "ABI v0", /* use r5 as return register; only used in N1213HC */
2949 "ABI v1", /* use r0 as return register */
2950 "ABI v2", /* use r0 as return register and don't reserve 24 bytes for arguments */
2951 "ABI v2fp", /* for FPU */
2955 static const char *VER_STRINGS
[] =
2957 "Andes ELF V1.3 or older",
2961 static const char *ARCH_STRINGS
[] =
2970 abi
= EF_NDS_ABI
& e_flags
;
2971 arch
= EF_NDS_ARCH
& e_flags
;
2972 config
= EF_NDS_INST
& e_flags
;
2973 version
= EF_NDS32_ELF_VERSION
& e_flags
;
2975 memset (buf
, 0, size
);
2982 case E_NDS_ABI_V2FP
:
2983 case E_NDS_ABI_AABI
:
2984 case E_NDS_ABI_V2FP_PLUS
:
2985 /* In case there are holes in the array. */
2986 r
+= snprintf (buf
+ r
, size
- r
, ", %s", ABI_STRINGS
[abi
>> EF_NDS_ABI_SHIFT
]);
2990 r
+= snprintf (buf
+ r
, size
- r
, ", <unrecognized ABI>");
2996 case E_NDS32_ELF_VER_1_2
:
2997 case E_NDS32_ELF_VER_1_3
:
2998 case E_NDS32_ELF_VER_1_4
:
2999 r
+= snprintf (buf
+ r
, size
- r
, ", %s", VER_STRINGS
[version
>> EF_NDS32_ELF_VERSION_SHIFT
]);
3003 r
+= snprintf (buf
+ r
, size
- r
, ", <unrecognized ELF version number>");
3007 if (E_NDS_ABI_V0
== abi
)
3009 /* OLD ABI; only used in N1213HC, has performance extension 1. */
3010 r
+= snprintf (buf
+ r
, size
- r
, ", Andes Star v1.0, N1213HC, MAC, PERF1");
3011 if (arch
== E_NDS_ARCH_STAR_V1_0
)
3012 r
+= snprintf (buf
+ r
, size
-r
, ", 16b"); /* has 16-bit instructions */
3018 case E_NDS_ARCH_STAR_V1_0
:
3019 case E_NDS_ARCH_STAR_V2_0
:
3020 case E_NDS_ARCH_STAR_V3_0
:
3021 case E_NDS_ARCH_STAR_V3_M
:
3022 r
+= snprintf (buf
+ r
, size
- r
, ", %s", ARCH_STRINGS
[arch
>> EF_NDS_ARCH_SHIFT
]);
3026 r
+= snprintf (buf
+ r
, size
- r
, ", <unrecognized architecture>");
3027 /* ARCH version determines how the e_flags are interpreted.
3028 If it is unknown, we cannot proceed. */
3032 /* Newer ABI; Now handle architecture specific flags. */
3033 if (arch
== E_NDS_ARCH_STAR_V1_0
)
3035 if (config
& E_NDS32_HAS_MFUSR_PC_INST
)
3036 r
+= snprintf (buf
+ r
, size
-r
, ", MFUSR_PC");
3038 if (!(config
& E_NDS32_HAS_NO_MAC_INST
))
3039 r
+= snprintf (buf
+ r
, size
-r
, ", MAC");
3041 if (config
& E_NDS32_HAS_DIV_INST
)
3042 r
+= snprintf (buf
+ r
, size
-r
, ", DIV");
3044 if (config
& E_NDS32_HAS_16BIT_INST
)
3045 r
+= snprintf (buf
+ r
, size
-r
, ", 16b");
3049 if (config
& E_NDS32_HAS_MFUSR_PC_INST
)
3051 if (version
<= E_NDS32_ELF_VER_1_3
)
3052 r
+= snprintf (buf
+ r
, size
-r
, ", [B8]");
3054 r
+= snprintf (buf
+ r
, size
-r
, ", EX9");
3057 if (config
& E_NDS32_HAS_MAC_DX_INST
)
3058 r
+= snprintf (buf
+ r
, size
-r
, ", MAC_DX");
3060 if (config
& E_NDS32_HAS_DIV_DX_INST
)
3061 r
+= snprintf (buf
+ r
, size
-r
, ", DIV_DX");
3063 if (config
& E_NDS32_HAS_16BIT_INST
)
3065 if (version
<= E_NDS32_ELF_VER_1_3
)
3066 r
+= snprintf (buf
+ r
, size
-r
, ", 16b");
3068 r
+= snprintf (buf
+ r
, size
-r
, ", IFC");
3072 if (config
& E_NDS32_HAS_EXT_INST
)
3073 r
+= snprintf (buf
+ r
, size
-r
, ", PERF1");
3075 if (config
& E_NDS32_HAS_EXT2_INST
)
3076 r
+= snprintf (buf
+ r
, size
-r
, ", PERF2");
3078 if (config
& E_NDS32_HAS_FPU_INST
)
3081 r
+= snprintf (buf
+ r
, size
-r
, ", FPU_SP");
3084 if (config
& E_NDS32_HAS_FPU_DP_INST
)
3087 r
+= snprintf (buf
+ r
, size
-r
, ", FPU_DP");
3090 if (config
& E_NDS32_HAS_FPU_MAC_INST
)
3093 r
+= snprintf (buf
+ r
, size
-r
, ", FPU_MAC");
3098 switch ((config
& E_NDS32_FPU_REG_CONF
) >> E_NDS32_FPU_REG_CONF_SHIFT
)
3100 case E_NDS32_FPU_REG_8SP_4DP
:
3101 r
+= snprintf (buf
+ r
, size
-r
, ", FPU_REG:8/4");
3103 case E_NDS32_FPU_REG_16SP_8DP
:
3104 r
+= snprintf (buf
+ r
, size
-r
, ", FPU_REG:16/8");
3106 case E_NDS32_FPU_REG_32SP_16DP
:
3107 r
+= snprintf (buf
+ r
, size
-r
, ", FPU_REG:32/16");
3109 case E_NDS32_FPU_REG_32SP_32DP
:
3110 r
+= snprintf (buf
+ r
, size
-r
, ", FPU_REG:32/32");
3115 if (config
& E_NDS32_HAS_AUDIO_INST
)
3116 r
+= snprintf (buf
+ r
, size
-r
, ", AUDIO");
3118 if (config
& E_NDS32_HAS_STRING_INST
)
3119 r
+= snprintf (buf
+ r
, size
-r
, ", STR");
3121 if (config
& E_NDS32_HAS_REDUCED_REGS
)
3122 r
+= snprintf (buf
+ r
, size
-r
, ", 16REG");
3124 if (config
& E_NDS32_HAS_VIDEO_INST
)
3126 if (version
<= E_NDS32_ELF_VER_1_3
)
3127 r
+= snprintf (buf
+ r
, size
-r
, ", VIDEO");
3129 r
+= snprintf (buf
+ r
, size
-r
, ", SATURATION");
3132 if (config
& E_NDS32_HAS_ENCRIPT_INST
)
3133 r
+= snprintf (buf
+ r
, size
-r
, ", ENCRP");
3135 if (config
& E_NDS32_HAS_L2C_INST
)
3136 r
+= snprintf (buf
+ r
, size
-r
, ", L2C");
3140 get_machine_flags (Filedata
* filedata
, unsigned e_flags
, unsigned e_machine
)
3142 static char buf
[1024];
3153 case EM_ARC_COMPACT2
:
3154 case EM_ARC_COMPACT
:
3155 decode_ARC_machine_flags (e_flags
, e_machine
, buf
);
3159 decode_ARM_machine_flags (e_flags
, buf
);
3163 decode_AVR_machine_flags (e_flags
, buf
, sizeof buf
);
3167 if (e_flags
& EF_BFIN_PIC
)
3168 strcat (buf
, ", PIC");
3170 if (e_flags
& EF_BFIN_FDPIC
)
3171 strcat (buf
, ", FDPIC");
3173 if (e_flags
& EF_BFIN_CODE_IN_L1
)
3174 strcat (buf
, ", code in L1");
3176 if (e_flags
& EF_BFIN_DATA_IN_L1
)
3177 strcat (buf
, ", data in L1");
3182 switch (e_flags
& EF_FRV_CPU_MASK
)
3184 case EF_FRV_CPU_GENERIC
:
3188 strcat (buf
, ", fr???");
3191 case EF_FRV_CPU_FR300
:
3192 strcat (buf
, ", fr300");
3195 case EF_FRV_CPU_FR400
:
3196 strcat (buf
, ", fr400");
3198 case EF_FRV_CPU_FR405
:
3199 strcat (buf
, ", fr405");
3202 case EF_FRV_CPU_FR450
:
3203 strcat (buf
, ", fr450");
3206 case EF_FRV_CPU_FR500
:
3207 strcat (buf
, ", fr500");
3209 case EF_FRV_CPU_FR550
:
3210 strcat (buf
, ", fr550");
3213 case EF_FRV_CPU_SIMPLE
:
3214 strcat (buf
, ", simple");
3216 case EF_FRV_CPU_TOMCAT
:
3217 strcat (buf
, ", tomcat");
3223 if ((e_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_M68000
)
3224 strcat (buf
, ", m68000");
3225 else if ((e_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_CPU32
)
3226 strcat (buf
, ", cpu32");
3227 else if ((e_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_FIDO
)
3228 strcat (buf
, ", fido_a");
3231 char const * isa
= _("unknown");
3232 char const * mac
= _("unknown mac");
3233 char const * additional
= NULL
;
3235 switch (e_flags
& EF_M68K_CF_ISA_MASK
)
3237 case EF_M68K_CF_ISA_A_NODIV
:
3239 additional
= ", nodiv";
3241 case EF_M68K_CF_ISA_A
:
3244 case EF_M68K_CF_ISA_A_PLUS
:
3247 case EF_M68K_CF_ISA_B_NOUSP
:
3249 additional
= ", nousp";
3251 case EF_M68K_CF_ISA_B
:
3254 case EF_M68K_CF_ISA_C
:
3257 case EF_M68K_CF_ISA_C_NODIV
:
3259 additional
= ", nodiv";
3262 strcat (buf
, ", cf, isa ");
3265 strcat (buf
, additional
);
3266 if (e_flags
& EF_M68K_CF_FLOAT
)
3267 strcat (buf
, ", float");
3268 switch (e_flags
& EF_M68K_CF_MAC_MASK
)
3273 case EF_M68K_CF_MAC
:
3276 case EF_M68K_CF_EMAC
:
3279 case EF_M68K_CF_EMAC_B
:
3292 switch (e_flags
& EF_MEP_CPU_MASK
)
3294 case EF_MEP_CPU_MEP
: strcat (buf
, ", generic MeP"); break;
3295 case EF_MEP_CPU_C2
: strcat (buf
, ", MeP C2"); break;
3296 case EF_MEP_CPU_C3
: strcat (buf
, ", MeP C3"); break;
3297 case EF_MEP_CPU_C4
: strcat (buf
, ", MeP C4"); break;
3298 case EF_MEP_CPU_C5
: strcat (buf
, ", MeP C5"); break;
3299 case EF_MEP_CPU_H1
: strcat (buf
, ", MeP H1"); break;
3300 default: strcat (buf
, _(", <unknown MeP cpu type>")); break;
3303 switch (e_flags
& EF_MEP_COP_MASK
)
3305 case EF_MEP_COP_NONE
: break;
3306 case EF_MEP_COP_AVC
: strcat (buf
, ", AVC coprocessor"); break;
3307 case EF_MEP_COP_AVC2
: strcat (buf
, ", AVC2 coprocessor"); break;
3308 case EF_MEP_COP_FMAX
: strcat (buf
, ", FMAX coprocessor"); break;
3309 case EF_MEP_COP_IVC2
: strcat (buf
, ", IVC2 coprocessor"); break;
3310 default: strcat (buf
, _("<unknown MeP copro type>")); break;
3313 if (e_flags
& EF_MEP_LIBRARY
)
3314 strcat (buf
, ", Built for Library");
3316 if (e_flags
& EF_MEP_INDEX_MASK
)
3317 sprintf (buf
+ strlen (buf
), ", Configuration Index: %#x",
3318 e_flags
& EF_MEP_INDEX_MASK
);
3320 if (e_flags
& ~ EF_MEP_ALL_FLAGS
)
3321 sprintf (buf
+ strlen (buf
), _(", unknown flags bits: %#x"),
3322 e_flags
& ~ EF_MEP_ALL_FLAGS
);
3326 if (e_flags
& EF_PPC_EMB
)
3327 strcat (buf
, ", emb");
3329 if (e_flags
& EF_PPC_RELOCATABLE
)
3330 strcat (buf
, _(", relocatable"));
3332 if (e_flags
& EF_PPC_RELOCATABLE_LIB
)
3333 strcat (buf
, _(", relocatable-lib"));
3337 if (e_flags
& EF_PPC64_ABI
)
3339 char abi
[] = ", abiv0";
3341 abi
[6] += e_flags
& EF_PPC64_ABI
;
3347 if ((e_flags
& EF_RH850_ABI
) == EF_RH850_ABI
)
3348 strcat (buf
, ", RH850 ABI");
3350 if (e_flags
& EF_V800_850E3
)
3351 strcat (buf
, ", V3 architecture");
3353 if ((e_flags
& (EF_RH850_FPU_DOUBLE
| EF_RH850_FPU_SINGLE
)) == 0)
3354 strcat (buf
, ", FPU not used");
3356 if ((e_flags
& (EF_RH850_REGMODE22
| EF_RH850_REGMODE32
)) == 0)
3357 strcat (buf
, ", regmode: COMMON");
3359 if ((e_flags
& (EF_RH850_GP_FIX
| EF_RH850_GP_NOFIX
)) == 0)
3360 strcat (buf
, ", r4 not used");
3362 if ((e_flags
& (EF_RH850_EP_FIX
| EF_RH850_EP_NOFIX
)) == 0)
3363 strcat (buf
, ", r30 not used");
3365 if ((e_flags
& (EF_RH850_TP_FIX
| EF_RH850_TP_NOFIX
)) == 0)
3366 strcat (buf
, ", r5 not used");
3368 if ((e_flags
& (EF_RH850_REG2_RESERVE
| EF_RH850_REG2_NORESERVE
)) == 0)
3369 strcat (buf
, ", r2 not used");
3371 for (e_flags
&= 0xFFFF; e_flags
; e_flags
&= ~ (e_flags
& - e_flags
))
3373 switch (e_flags
& - e_flags
)
3375 case EF_RH850_FPU_DOUBLE
: strcat (buf
, ", double precision FPU"); break;
3376 case EF_RH850_FPU_SINGLE
: strcat (buf
, ", single precision FPU"); break;
3377 case EF_RH850_REGMODE22
: strcat (buf
, ", regmode:22"); break;
3378 case EF_RH850_REGMODE32
: strcat (buf
, ", regmode:23"); break;
3379 case EF_RH850_GP_FIX
: strcat (buf
, ", r4 fixed"); break;
3380 case EF_RH850_GP_NOFIX
: strcat (buf
, ", r4 free"); break;
3381 case EF_RH850_EP_FIX
: strcat (buf
, ", r30 fixed"); break;
3382 case EF_RH850_EP_NOFIX
: strcat (buf
, ", r30 free"); break;
3383 case EF_RH850_TP_FIX
: strcat (buf
, ", r5 fixed"); break;
3384 case EF_RH850_TP_NOFIX
: strcat (buf
, ", r5 free"); break;
3385 case EF_RH850_REG2_RESERVE
: strcat (buf
, ", r2 fixed"); break;
3386 case EF_RH850_REG2_NORESERVE
: strcat (buf
, ", r2 free"); break;
3393 case EM_CYGNUS_V850
:
3394 switch (e_flags
& EF_V850_ARCH
)
3396 case E_V850E3V5_ARCH
:
3397 strcat (buf
, ", v850e3v5");
3399 case E_V850E2V3_ARCH
:
3400 strcat (buf
, ", v850e2v3");
3403 strcat (buf
, ", v850e2");
3406 strcat (buf
, ", v850e1");
3409 strcat (buf
, ", v850e");
3412 strcat (buf
, ", v850");
3415 strcat (buf
, _(", unknown v850 architecture variant"));
3421 case EM_CYGNUS_M32R
:
3422 if ((e_flags
& EF_M32R_ARCH
) == E_M32R_ARCH
)
3423 strcat (buf
, ", m32r");
3427 case EM_MIPS_RS3_LE
:
3428 if (e_flags
& EF_MIPS_NOREORDER
)
3429 strcat (buf
, ", noreorder");
3431 if (e_flags
& EF_MIPS_PIC
)
3432 strcat (buf
, ", pic");
3434 if (e_flags
& EF_MIPS_CPIC
)
3435 strcat (buf
, ", cpic");
3437 if (e_flags
& EF_MIPS_UCODE
)
3438 strcat (buf
, ", ugen_reserved");
3440 if (e_flags
& EF_MIPS_ABI2
)
3441 strcat (buf
, ", abi2");
3443 if (e_flags
& EF_MIPS_OPTIONS_FIRST
)
3444 strcat (buf
, ", odk first");
3446 if (e_flags
& EF_MIPS_32BITMODE
)
3447 strcat (buf
, ", 32bitmode");
3449 if (e_flags
& EF_MIPS_NAN2008
)
3450 strcat (buf
, ", nan2008");
3452 if (e_flags
& EF_MIPS_FP64
)
3453 strcat (buf
, ", fp64");
3455 switch ((e_flags
& EF_MIPS_MACH
))
3457 case E_MIPS_MACH_3900
: strcat (buf
, ", 3900"); break;
3458 case E_MIPS_MACH_4010
: strcat (buf
, ", 4010"); break;
3459 case E_MIPS_MACH_4100
: strcat (buf
, ", 4100"); break;
3460 case E_MIPS_MACH_4111
: strcat (buf
, ", 4111"); break;
3461 case E_MIPS_MACH_4120
: strcat (buf
, ", 4120"); break;
3462 case E_MIPS_MACH_4650
: strcat (buf
, ", 4650"); break;
3463 case E_MIPS_MACH_5400
: strcat (buf
, ", 5400"); break;
3464 case E_MIPS_MACH_5500
: strcat (buf
, ", 5500"); break;
3465 case E_MIPS_MACH_5900
: strcat (buf
, ", 5900"); break;
3466 case E_MIPS_MACH_SB1
: strcat (buf
, ", sb1"); break;
3467 case E_MIPS_MACH_9000
: strcat (buf
, ", 9000"); break;
3468 case E_MIPS_MACH_LS2E
: strcat (buf
, ", loongson-2e"); break;
3469 case E_MIPS_MACH_LS2F
: strcat (buf
, ", loongson-2f"); break;
3470 case E_MIPS_MACH_GS464
: strcat (buf
, ", gs464"); break;
3471 case E_MIPS_MACH_GS464E
: strcat (buf
, ", gs464e"); break;
3472 case E_MIPS_MACH_GS264E
: strcat (buf
, ", gs264e"); break;
3473 case E_MIPS_MACH_OCTEON
: strcat (buf
, ", octeon"); break;
3474 case E_MIPS_MACH_OCTEON2
: strcat (buf
, ", octeon2"); break;
3475 case E_MIPS_MACH_OCTEON3
: strcat (buf
, ", octeon3"); break;
3476 case E_MIPS_MACH_XLR
: strcat (buf
, ", xlr"); break;
3477 case E_MIPS_MACH_IAMR2
: strcat (buf
, ", interaptiv-mr2"); break;
3479 /* We simply ignore the field in this case to avoid confusion:
3480 MIPS ELF does not specify EF_MIPS_MACH, it is a GNU
3483 default: strcat (buf
, _(", unknown CPU")); break;
3486 switch ((e_flags
& EF_MIPS_ABI
))
3488 case E_MIPS_ABI_O32
: strcat (buf
, ", o32"); break;
3489 case E_MIPS_ABI_O64
: strcat (buf
, ", o64"); break;
3490 case E_MIPS_ABI_EABI32
: strcat (buf
, ", eabi32"); break;
3491 case E_MIPS_ABI_EABI64
: strcat (buf
, ", eabi64"); break;
3493 /* We simply ignore the field in this case to avoid confusion:
3494 MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension.
3495 This means it is likely to be an o32 file, but not for
3498 default: strcat (buf
, _(", unknown ABI")); break;
3501 if (e_flags
& EF_MIPS_ARCH_ASE_MDMX
)
3502 strcat (buf
, ", mdmx");
3504 if (e_flags
& EF_MIPS_ARCH_ASE_M16
)
3505 strcat (buf
, ", mips16");
3507 if (e_flags
& EF_MIPS_ARCH_ASE_MICROMIPS
)
3508 strcat (buf
, ", micromips");
3510 switch ((e_flags
& EF_MIPS_ARCH
))
3512 case E_MIPS_ARCH_1
: strcat (buf
, ", mips1"); break;
3513 case E_MIPS_ARCH_2
: strcat (buf
, ", mips2"); break;
3514 case E_MIPS_ARCH_3
: strcat (buf
, ", mips3"); break;
3515 case E_MIPS_ARCH_4
: strcat (buf
, ", mips4"); break;
3516 case E_MIPS_ARCH_5
: strcat (buf
, ", mips5"); break;
3517 case E_MIPS_ARCH_32
: strcat (buf
, ", mips32"); break;
3518 case E_MIPS_ARCH_32R2
: strcat (buf
, ", mips32r2"); break;
3519 case E_MIPS_ARCH_32R6
: strcat (buf
, ", mips32r6"); break;
3520 case E_MIPS_ARCH_64
: strcat (buf
, ", mips64"); break;
3521 case E_MIPS_ARCH_64R2
: strcat (buf
, ", mips64r2"); break;
3522 case E_MIPS_ARCH_64R6
: strcat (buf
, ", mips64r6"); break;
3523 default: strcat (buf
, _(", unknown ISA")); break;
3528 decode_NDS32_machine_flags (e_flags
, buf
, sizeof buf
);
3532 switch (EF_NFP_MACH (e_flags
))
3534 case E_NFP_MACH_3200
:
3535 strcat (buf
, ", NFP-32xx");
3537 case E_NFP_MACH_6000
:
3538 strcat (buf
, ", NFP-6xxx");
3544 if (e_flags
& EF_RISCV_RVC
)
3545 strcat (buf
, ", RVC");
3547 if (e_flags
& EF_RISCV_RVE
)
3548 strcat (buf
, ", RVE");
3550 switch (e_flags
& EF_RISCV_FLOAT_ABI
)
3552 case EF_RISCV_FLOAT_ABI_SOFT
:
3553 strcat (buf
, ", soft-float ABI");
3556 case EF_RISCV_FLOAT_ABI_SINGLE
:
3557 strcat (buf
, ", single-float ABI");
3560 case EF_RISCV_FLOAT_ABI_DOUBLE
:
3561 strcat (buf
, ", double-float ABI");
3564 case EF_RISCV_FLOAT_ABI_QUAD
:
3565 strcat (buf
, ", quad-float ABI");
3571 switch ((e_flags
& EF_SH_MACH_MASK
))
3573 case EF_SH1
: strcat (buf
, ", sh1"); break;
3574 case EF_SH2
: strcat (buf
, ", sh2"); break;
3575 case EF_SH3
: strcat (buf
, ", sh3"); break;
3576 case EF_SH_DSP
: strcat (buf
, ", sh-dsp"); break;
3577 case EF_SH3_DSP
: strcat (buf
, ", sh3-dsp"); break;
3578 case EF_SH4AL_DSP
: strcat (buf
, ", sh4al-dsp"); break;
3579 case EF_SH3E
: strcat (buf
, ", sh3e"); break;
3580 case EF_SH4
: strcat (buf
, ", sh4"); break;
3581 case EF_SH5
: strcat (buf
, ", sh5"); break;
3582 case EF_SH2E
: strcat (buf
, ", sh2e"); break;
3583 case EF_SH4A
: strcat (buf
, ", sh4a"); break;
3584 case EF_SH2A
: strcat (buf
, ", sh2a"); break;
3585 case EF_SH4_NOFPU
: strcat (buf
, ", sh4-nofpu"); break;
3586 case EF_SH4A_NOFPU
: strcat (buf
, ", sh4a-nofpu"); break;
3587 case EF_SH2A_NOFPU
: strcat (buf
, ", sh2a-nofpu"); break;
3588 case EF_SH3_NOMMU
: strcat (buf
, ", sh3-nommu"); break;
3589 case EF_SH4_NOMMU_NOFPU
: strcat (buf
, ", sh4-nommu-nofpu"); break;
3590 case EF_SH2A_SH4_NOFPU
: strcat (buf
, ", sh2a-nofpu-or-sh4-nommu-nofpu"); break;
3591 case EF_SH2A_SH3_NOFPU
: strcat (buf
, ", sh2a-nofpu-or-sh3-nommu"); break;
3592 case EF_SH2A_SH4
: strcat (buf
, ", sh2a-or-sh4"); break;
3593 case EF_SH2A_SH3E
: strcat (buf
, ", sh2a-or-sh3e"); break;
3594 default: strcat (buf
, _(", unknown ISA")); break;
3597 if (e_flags
& EF_SH_PIC
)
3598 strcat (buf
, ", pic");
3600 if (e_flags
& EF_SH_FDPIC
)
3601 strcat (buf
, ", fdpic");
3605 if (e_flags
& EF_OR1K_NODELAY
)
3606 strcat (buf
, ", no delay");
3610 if (e_flags
& EF_SPARC_32PLUS
)
3611 strcat (buf
, ", v8+");
3613 if (e_flags
& EF_SPARC_SUN_US1
)
3614 strcat (buf
, ", ultrasparcI");
3616 if (e_flags
& EF_SPARC_SUN_US3
)
3617 strcat (buf
, ", ultrasparcIII");
3619 if (e_flags
& EF_SPARC_HAL_R1
)
3620 strcat (buf
, ", halr1");
3622 if (e_flags
& EF_SPARC_LEDATA
)
3623 strcat (buf
, ", ledata");
3625 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_TSO
)
3626 strcat (buf
, ", tso");
3628 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_PSO
)
3629 strcat (buf
, ", pso");
3631 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_RMO
)
3632 strcat (buf
, ", rmo");
3636 switch (e_flags
& EF_PARISC_ARCH
)
3638 case EFA_PARISC_1_0
:
3639 strcpy (buf
, ", PA-RISC 1.0");
3641 case EFA_PARISC_1_1
:
3642 strcpy (buf
, ", PA-RISC 1.1");
3644 case EFA_PARISC_2_0
:
3645 strcpy (buf
, ", PA-RISC 2.0");
3650 if (e_flags
& EF_PARISC_TRAPNIL
)
3651 strcat (buf
, ", trapnil");
3652 if (e_flags
& EF_PARISC_EXT
)
3653 strcat (buf
, ", ext");
3654 if (e_flags
& EF_PARISC_LSB
)
3655 strcat (buf
, ", lsb");
3656 if (e_flags
& EF_PARISC_WIDE
)
3657 strcat (buf
, ", wide");
3658 if (e_flags
& EF_PARISC_NO_KABP
)
3659 strcat (buf
, ", no kabp");
3660 if (e_flags
& EF_PARISC_LAZYSWAP
)
3661 strcat (buf
, ", lazyswap");
3666 if ((e_flags
& EF_PICOJAVA_NEWCALLS
) == EF_PICOJAVA_NEWCALLS
)
3667 strcat (buf
, ", new calling convention");
3669 if ((e_flags
& EF_PICOJAVA_GNUCALLS
) == EF_PICOJAVA_GNUCALLS
)
3670 strcat (buf
, ", gnu calling convention");
3674 if ((e_flags
& EF_IA_64_ABI64
))
3675 strcat (buf
, ", 64-bit");
3677 strcat (buf
, ", 32-bit");
3678 if ((e_flags
& EF_IA_64_REDUCEDFP
))
3679 strcat (buf
, ", reduced fp model");
3680 if ((e_flags
& EF_IA_64_NOFUNCDESC_CONS_GP
))
3681 strcat (buf
, ", no function descriptors, constant gp");
3682 else if ((e_flags
& EF_IA_64_CONS_GP
))
3683 strcat (buf
, ", constant gp");
3684 if ((e_flags
& EF_IA_64_ABSOLUTE
))
3685 strcat (buf
, ", absolute");
3686 if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_OPENVMS
)
3688 if ((e_flags
& EF_IA_64_VMS_LINKAGES
))
3689 strcat (buf
, ", vms_linkages");
3690 switch ((e_flags
& EF_IA_64_VMS_COMCOD
))
3692 case EF_IA_64_VMS_COMCOD_SUCCESS
:
3694 case EF_IA_64_VMS_COMCOD_WARNING
:
3695 strcat (buf
, ", warning");
3697 case EF_IA_64_VMS_COMCOD_ERROR
:
3698 strcat (buf
, ", error");
3700 case EF_IA_64_VMS_COMCOD_ABORT
:
3701 strcat (buf
, ", abort");
3704 warn (_("Unrecognised IA64 VMS Command Code: %x\n"),
3705 e_flags
& EF_IA_64_VMS_COMCOD
);
3706 strcat (buf
, ", <unknown>");
3712 if ((e_flags
& EF_VAX_NONPIC
))
3713 strcat (buf
, ", non-PIC");
3714 if ((e_flags
& EF_VAX_DFLOAT
))
3715 strcat (buf
, ", D-Float");
3716 if ((e_flags
& EF_VAX_GFLOAT
))
3717 strcat (buf
, ", G-Float");
3721 if (e_flags
& EF_VISIUM_ARCH_MCM
)
3722 strcat (buf
, ", mcm");
3723 else if (e_flags
& EF_VISIUM_ARCH_MCM24
)
3724 strcat (buf
, ", mcm24");
3725 if (e_flags
& EF_VISIUM_ARCH_GR6
)
3726 strcat (buf
, ", gr6");
3730 switch (e_flags
& E_FLAG_RL78_CPU_MASK
)
3732 case E_FLAG_RL78_ANY_CPU
: break;
3733 case E_FLAG_RL78_G10
: strcat (buf
, ", G10"); break;
3734 case E_FLAG_RL78_G13
: strcat (buf
, ", G13"); break;
3735 case E_FLAG_RL78_G14
: strcat (buf
, ", G14"); break;
3737 if (e_flags
& E_FLAG_RL78_64BIT_DOUBLES
)
3738 strcat (buf
, ", 64-bit doubles");
3742 if (e_flags
& E_FLAG_RX_64BIT_DOUBLES
)
3743 strcat (buf
, ", 64-bit doubles");
3744 if (e_flags
& E_FLAG_RX_DSP
)
3745 strcat (buf
, ", dsp");
3746 if (e_flags
& E_FLAG_RX_PID
)
3747 strcat (buf
, ", pid");
3748 if (e_flags
& E_FLAG_RX_ABI
)
3749 strcat (buf
, ", RX ABI");
3750 if (e_flags
& E_FLAG_RX_SINSNS_SET
)
3751 strcat (buf
, e_flags
& E_FLAG_RX_SINSNS_YES
3752 ? ", uses String instructions" : ", bans String instructions");
3753 if (e_flags
& E_FLAG_RX_V2
)
3754 strcat (buf
, ", V2");
3755 if (e_flags
& E_FLAG_RX_V3
)
3756 strcat (buf
, ", V3");
3760 if (e_flags
& EF_S390_HIGH_GPRS
)
3761 strcat (buf
, ", highgprs");
3765 if ((e_flags
& EF_C6000_REL
))
3766 strcat (buf
, ", relocatable module");
3770 strcat (buf
, _(": architecture variant: "));
3771 switch (e_flags
& EF_MSP430_MACH
)
3773 case E_MSP430_MACH_MSP430x11
: strcat (buf
, "MSP430x11"); break;
3774 case E_MSP430_MACH_MSP430x11x1
: strcat (buf
, "MSP430x11x1 "); break;
3775 case E_MSP430_MACH_MSP430x12
: strcat (buf
, "MSP430x12"); break;
3776 case E_MSP430_MACH_MSP430x13
: strcat (buf
, "MSP430x13"); break;
3777 case E_MSP430_MACH_MSP430x14
: strcat (buf
, "MSP430x14"); break;
3778 case E_MSP430_MACH_MSP430x15
: strcat (buf
, "MSP430x15"); break;
3779 case E_MSP430_MACH_MSP430x16
: strcat (buf
, "MSP430x16"); break;
3780 case E_MSP430_MACH_MSP430x31
: strcat (buf
, "MSP430x31"); break;
3781 case E_MSP430_MACH_MSP430x32
: strcat (buf
, "MSP430x32"); break;
3782 case E_MSP430_MACH_MSP430x33
: strcat (buf
, "MSP430x33"); break;
3783 case E_MSP430_MACH_MSP430x41
: strcat (buf
, "MSP430x41"); break;
3784 case E_MSP430_MACH_MSP430x42
: strcat (buf
, "MSP430x42"); break;
3785 case E_MSP430_MACH_MSP430x43
: strcat (buf
, "MSP430x43"); break;
3786 case E_MSP430_MACH_MSP430x44
: strcat (buf
, "MSP430x44"); break;
3787 case E_MSP430_MACH_MSP430X
: strcat (buf
, "MSP430X"); break;
3789 strcat (buf
, _(": unknown")); break;
3792 if (e_flags
& ~ EF_MSP430_MACH
)
3793 strcat (buf
, _(": unknown extra flag bits also present"));
3797 switch (e_flags
& EF_Z80_MACH_MSK
)
3799 case EF_Z80_MACH_Z80
: strcat (buf
, ", Z80"); break;
3800 case EF_Z80_MACH_Z180
: strcat (buf
, ", Z180"); break;
3801 case EF_Z80_MACH_R800
: strcat (buf
, ", R800"); break;
3802 case EF_Z80_MACH_EZ80_Z80
: strcat (buf
, ", EZ80"); break;
3803 case EF_Z80_MACH_EZ80_ADL
: strcat (buf
, ", EZ80, ADL"); break;
3804 case EF_Z80_MACH_GBZ80
: strcat (buf
, ", GBZ80"); break;
3805 case EF_Z80_MACH_Z80N
: strcat (buf
, ", Z80N"); break;
3807 strcat (buf
, _(", unknown")); break;
3817 get_osabi_name (Filedata
* filedata
, unsigned int osabi
)
3819 static char buff
[32];
3823 case ELFOSABI_NONE
: return "UNIX - System V";
3824 case ELFOSABI_HPUX
: return "UNIX - HP-UX";
3825 case ELFOSABI_NETBSD
: return "UNIX - NetBSD";
3826 case ELFOSABI_GNU
: return "UNIX - GNU";
3827 case ELFOSABI_SOLARIS
: return "UNIX - Solaris";
3828 case ELFOSABI_AIX
: return "UNIX - AIX";
3829 case ELFOSABI_IRIX
: return "UNIX - IRIX";
3830 case ELFOSABI_FREEBSD
: return "UNIX - FreeBSD";
3831 case ELFOSABI_TRU64
: return "UNIX - TRU64";
3832 case ELFOSABI_MODESTO
: return "Novell - Modesto";
3833 case ELFOSABI_OPENBSD
: return "UNIX - OpenBSD";
3834 case ELFOSABI_OPENVMS
: return "VMS - OpenVMS";
3835 case ELFOSABI_NSK
: return "HP - Non-Stop Kernel";
3836 case ELFOSABI_AROS
: return "AROS";
3837 case ELFOSABI_FENIXOS
: return "FenixOS";
3838 case ELFOSABI_CLOUDABI
: return "Nuxi CloudABI";
3839 case ELFOSABI_OPENVOS
: return "Stratus Technologies OpenVOS";
3842 switch (filedata
->file_header
.e_machine
)
3847 case ELFOSABI_ARM
: return "ARM";
3848 case ELFOSABI_ARM_FDPIC
: return "ARM FDPIC";
3859 case ELFOSABI_STANDALONE
: return _("Standalone App");
3868 case ELFOSABI_C6000_ELFABI
: return _("Bare-metal C6000");
3869 case ELFOSABI_C6000_LINUX
: return "Linux C6000";
3878 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), osabi
);
3884 get_aarch64_segment_type (unsigned long type
)
3888 case PT_AARCH64_ARCHEXT
: return "AARCH64_ARCHEXT";
3889 default: return NULL
;
3894 get_arm_segment_type (unsigned long type
)
3898 case PT_ARM_EXIDX
: return "EXIDX";
3899 default: return NULL
;
3904 get_s390_segment_type (unsigned long type
)
3908 case PT_S390_PGSTE
: return "S390_PGSTE";
3909 default: return NULL
;
3914 get_mips_segment_type (unsigned long type
)
3918 case PT_MIPS_REGINFO
: return "REGINFO";
3919 case PT_MIPS_RTPROC
: return "RTPROC";
3920 case PT_MIPS_OPTIONS
: return "OPTIONS";
3921 case PT_MIPS_ABIFLAGS
: return "ABIFLAGS";
3922 default: return NULL
;
3927 get_parisc_segment_type (unsigned long type
)
3931 case PT_PARISC_ARCHEXT
: return "PARISC_ARCHEXT";
3932 case PT_PARISC_UNWIND
: return "PARISC_UNWIND";
3933 case PT_PARISC_WEAKORDER
: return "PARISC_WEAKORDER";
3934 default: return NULL
;
3939 get_ia64_segment_type (unsigned long type
)
3943 case PT_IA_64_ARCHEXT
: return "IA_64_ARCHEXT";
3944 case PT_IA_64_UNWIND
: return "IA_64_UNWIND";
3945 default: return NULL
;
3950 get_tic6x_segment_type (unsigned long type
)
3954 case PT_C6000_PHATTR
: return "C6000_PHATTR";
3955 default: return NULL
;
3960 get_hpux_segment_type (unsigned long type
, unsigned e_machine
)
3962 if (e_machine
== EM_PARISC
)
3965 case PT_HP_TLS
: return "HP_TLS";
3966 case PT_HP_CORE_NONE
: return "HP_CORE_NONE";
3967 case PT_HP_CORE_VERSION
: return "HP_CORE_VERSION";
3968 case PT_HP_CORE_KERNEL
: return "HP_CORE_KERNEL";
3969 case PT_HP_CORE_COMM
: return "HP_CORE_COMM";
3970 case PT_HP_CORE_PROC
: return "HP_CORE_PROC";
3971 case PT_HP_CORE_LOADABLE
: return "HP_CORE_LOADABLE";
3972 case PT_HP_CORE_STACK
: return "HP_CORE_STACK";
3973 case PT_HP_CORE_SHM
: return "HP_CORE_SHM";
3974 case PT_HP_CORE_MMF
: return "HP_CORE_MMF";
3975 case PT_HP_PARALLEL
: return "HP_PARALLEL";
3976 case PT_HP_FASTBIND
: return "HP_FASTBIND";
3977 case PT_HP_OPT_ANNOT
: return "HP_OPT_ANNOT";
3978 case PT_HP_HSL_ANNOT
: return "HP_HSL_ANNOT";
3979 case PT_HP_STACK
: return "HP_STACK";
3980 case PT_HP_CORE_UTSNAME
: return "HP_CORE_UTSNAME";
3981 default: return NULL
;
3984 if (e_machine
== EM_IA_64
)
3987 case PT_HP_TLS
: return "HP_TLS";
3988 case PT_IA_64_HP_OPT_ANOT
: return "HP_OPT_ANNOT";
3989 case PT_IA_64_HP_HSL_ANOT
: return "HP_HSL_ANNOT";
3990 case PT_IA_64_HP_STACK
: return "HP_STACK";
3991 default: return NULL
;
3998 get_solaris_segment_type (unsigned long type
)
4002 case 0x6464e550: return "PT_SUNW_UNWIND";
4003 case 0x6474e550: return "PT_SUNW_EH_FRAME";
4004 case 0x6ffffff7: return "PT_LOSUNW";
4005 case 0x6ffffffa: return "PT_SUNWBSS";
4006 case 0x6ffffffb: return "PT_SUNWSTACK";
4007 case 0x6ffffffc: return "PT_SUNWDTRACE";
4008 case 0x6ffffffd: return "PT_SUNWCAP";
4009 case 0x6fffffff: return "PT_HISUNW";
4010 default: return NULL
;
4015 get_segment_type (Filedata
* filedata
, unsigned long p_type
)
4017 static char buff
[32];
4021 case PT_NULL
: return "NULL";
4022 case PT_LOAD
: return "LOAD";
4023 case PT_DYNAMIC
: return "DYNAMIC";
4024 case PT_INTERP
: return "INTERP";
4025 case PT_NOTE
: return "NOTE";
4026 case PT_SHLIB
: return "SHLIB";
4027 case PT_PHDR
: return "PHDR";
4028 case PT_TLS
: return "TLS";
4029 case PT_GNU_EH_FRAME
: return "GNU_EH_FRAME";
4030 case PT_GNU_STACK
: return "GNU_STACK";
4031 case PT_GNU_RELRO
: return "GNU_RELRO";
4032 case PT_GNU_PROPERTY
: return "GNU_PROPERTY";
4034 case PT_OPENBSD_RANDOMIZE
: return "OPENBSD_RANDOMIZE";
4035 case PT_OPENBSD_WXNEEDED
: return "OPENBSD_WXNEEDED";
4036 case PT_OPENBSD_BOOTDATA
: return "OPENBSD_BOOTDATA";
4039 if ((p_type
>= PT_LOPROC
) && (p_type
<= PT_HIPROC
))
4041 const char * result
;
4043 switch (filedata
->file_header
.e_machine
)
4046 result
= get_aarch64_segment_type (p_type
);
4049 result
= get_arm_segment_type (p_type
);
4052 case EM_MIPS_RS3_LE
:
4053 result
= get_mips_segment_type (p_type
);
4056 result
= get_parisc_segment_type (p_type
);
4059 result
= get_ia64_segment_type (p_type
);
4062 result
= get_tic6x_segment_type (p_type
);
4066 result
= get_s390_segment_type (p_type
);
4076 sprintf (buff
, "LOPROC+%#lx", p_type
- PT_LOPROC
);
4078 else if ((p_type
>= PT_LOOS
) && (p_type
<= PT_HIOS
))
4080 const char * result
= NULL
;
4082 switch (filedata
->file_header
.e_ident
[EI_OSABI
])
4085 case ELFOSABI_FREEBSD
:
4086 if (p_type
>= PT_GNU_MBIND_LO
&& p_type
<= PT_GNU_MBIND_HI
)
4088 sprintf (buff
, "GNU_MBIND+%#lx", p_type
- PT_GNU_MBIND_LO
);
4093 result
= get_hpux_segment_type (p_type
,
4094 filedata
->file_header
.e_machine
);
4096 case ELFOSABI_SOLARIS
:
4097 result
= get_solaris_segment_type (p_type
);
4105 sprintf (buff
, "LOOS+%#lx", p_type
- PT_LOOS
);
4108 snprintf (buff
, sizeof (buff
), _("<unknown>: %lx"), p_type
);
4115 get_arc_section_type_name (unsigned int sh_type
)
4119 case SHT_ARC_ATTRIBUTES
: return "ARC_ATTRIBUTES";
4127 get_mips_section_type_name (unsigned int sh_type
)
4131 case SHT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
4132 case SHT_MIPS_MSYM
: return "MIPS_MSYM";
4133 case SHT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
4134 case SHT_MIPS_GPTAB
: return "MIPS_GPTAB";
4135 case SHT_MIPS_UCODE
: return "MIPS_UCODE";
4136 case SHT_MIPS_DEBUG
: return "MIPS_DEBUG";
4137 case SHT_MIPS_REGINFO
: return "MIPS_REGINFO";
4138 case SHT_MIPS_PACKAGE
: return "MIPS_PACKAGE";
4139 case SHT_MIPS_PACKSYM
: return "MIPS_PACKSYM";
4140 case SHT_MIPS_RELD
: return "MIPS_RELD";
4141 case SHT_MIPS_IFACE
: return "MIPS_IFACE";
4142 case SHT_MIPS_CONTENT
: return "MIPS_CONTENT";
4143 case SHT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
4144 case SHT_MIPS_SHDR
: return "MIPS_SHDR";
4145 case SHT_MIPS_FDESC
: return "MIPS_FDESC";
4146 case SHT_MIPS_EXTSYM
: return "MIPS_EXTSYM";
4147 case SHT_MIPS_DENSE
: return "MIPS_DENSE";
4148 case SHT_MIPS_PDESC
: return "MIPS_PDESC";
4149 case SHT_MIPS_LOCSYM
: return "MIPS_LOCSYM";
4150 case SHT_MIPS_AUXSYM
: return "MIPS_AUXSYM";
4151 case SHT_MIPS_OPTSYM
: return "MIPS_OPTSYM";
4152 case SHT_MIPS_LOCSTR
: return "MIPS_LOCSTR";
4153 case SHT_MIPS_LINE
: return "MIPS_LINE";
4154 case SHT_MIPS_RFDESC
: return "MIPS_RFDESC";
4155 case SHT_MIPS_DELTASYM
: return "MIPS_DELTASYM";
4156 case SHT_MIPS_DELTAINST
: return "MIPS_DELTAINST";
4157 case SHT_MIPS_DELTACLASS
: return "MIPS_DELTACLASS";
4158 case SHT_MIPS_DWARF
: return "MIPS_DWARF";
4159 case SHT_MIPS_DELTADECL
: return "MIPS_DELTADECL";
4160 case SHT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
4161 case SHT_MIPS_EVENTS
: return "MIPS_EVENTS";
4162 case SHT_MIPS_TRANSLATE
: return "MIPS_TRANSLATE";
4163 case SHT_MIPS_PIXIE
: return "MIPS_PIXIE";
4164 case SHT_MIPS_XLATE
: return "MIPS_XLATE";
4165 case SHT_MIPS_XLATE_DEBUG
: return "MIPS_XLATE_DEBUG";
4166 case SHT_MIPS_WHIRL
: return "MIPS_WHIRL";
4167 case SHT_MIPS_EH_REGION
: return "MIPS_EH_REGION";
4168 case SHT_MIPS_XLATE_OLD
: return "MIPS_XLATE_OLD";
4169 case SHT_MIPS_PDR_EXCEPTION
: return "MIPS_PDR_EXCEPTION";
4170 case SHT_MIPS_ABIFLAGS
: return "MIPS_ABIFLAGS";
4171 case SHT_MIPS_XHASH
: return "MIPS_XHASH";
4179 get_parisc_section_type_name (unsigned int sh_type
)
4183 case SHT_PARISC_EXT
: return "PARISC_EXT";
4184 case SHT_PARISC_UNWIND
: return "PARISC_UNWIND";
4185 case SHT_PARISC_DOC
: return "PARISC_DOC";
4186 case SHT_PARISC_ANNOT
: return "PARISC_ANNOT";
4187 case SHT_PARISC_SYMEXTN
: return "PARISC_SYMEXTN";
4188 case SHT_PARISC_STUBS
: return "PARISC_STUBS";
4189 case SHT_PARISC_DLKM
: return "PARISC_DLKM";
4190 default: return NULL
;
4195 get_ia64_section_type_name (Filedata
* filedata
, unsigned int sh_type
)
4197 /* If the top 8 bits are 0x78 the next 8 are the os/abi ID. */
4198 if ((sh_type
& 0xFF000000) == SHT_IA_64_LOPSREG
)
4199 return get_osabi_name (filedata
, (sh_type
& 0x00FF0000) >> 16);
4203 case SHT_IA_64_EXT
: return "IA_64_EXT";
4204 case SHT_IA_64_UNWIND
: return "IA_64_UNWIND";
4205 case SHT_IA_64_PRIORITY_INIT
: return "IA_64_PRIORITY_INIT";
4206 case SHT_IA_64_VMS_TRACE
: return "VMS_TRACE";
4207 case SHT_IA_64_VMS_TIE_SIGNATURES
: return "VMS_TIE_SIGNATURES";
4208 case SHT_IA_64_VMS_DEBUG
: return "VMS_DEBUG";
4209 case SHT_IA_64_VMS_DEBUG_STR
: return "VMS_DEBUG_STR";
4210 case SHT_IA_64_VMS_LINKAGES
: return "VMS_LINKAGES";
4211 case SHT_IA_64_VMS_SYMBOL_VECTOR
: return "VMS_SYMBOL_VECTOR";
4212 case SHT_IA_64_VMS_FIXUP
: return "VMS_FIXUP";
4220 get_x86_64_section_type_name (unsigned int sh_type
)
4224 case SHT_X86_64_UNWIND
: return "X86_64_UNWIND";
4225 default: return NULL
;
4230 get_aarch64_section_type_name (unsigned int sh_type
)
4234 case SHT_AARCH64_ATTRIBUTES
: return "AARCH64_ATTRIBUTES";
4235 default: return NULL
;
4240 get_arm_section_type_name (unsigned int sh_type
)
4244 case SHT_ARM_EXIDX
: return "ARM_EXIDX";
4245 case SHT_ARM_PREEMPTMAP
: return "ARM_PREEMPTMAP";
4246 case SHT_ARM_ATTRIBUTES
: return "ARM_ATTRIBUTES";
4247 case SHT_ARM_DEBUGOVERLAY
: return "ARM_DEBUGOVERLAY";
4248 case SHT_ARM_OVERLAYSECTION
: return "ARM_OVERLAYSECTION";
4249 default: return NULL
;
4254 get_tic6x_section_type_name (unsigned int sh_type
)
4258 case SHT_C6000_UNWIND
: return "C6000_UNWIND";
4259 case SHT_C6000_PREEMPTMAP
: return "C6000_PREEMPTMAP";
4260 case SHT_C6000_ATTRIBUTES
: return "C6000_ATTRIBUTES";
4261 case SHT_TI_ICODE
: return "TI_ICODE";
4262 case SHT_TI_XREF
: return "TI_XREF";
4263 case SHT_TI_HANDLER
: return "TI_HANDLER";
4264 case SHT_TI_INITINFO
: return "TI_INITINFO";
4265 case SHT_TI_PHATTRS
: return "TI_PHATTRS";
4266 default: return NULL
;
4271 get_msp430_section_type_name (unsigned int sh_type
)
4275 case SHT_MSP430_SEC_FLAGS
: return "MSP430_SEC_FLAGS";
4276 case SHT_MSP430_SYM_ALIASES
: return "MSP430_SYM_ALIASES";
4277 case SHT_MSP430_ATTRIBUTES
: return "MSP430_ATTRIBUTES";
4278 default: return NULL
;
4283 get_nfp_section_type_name (unsigned int sh_type
)
4287 case SHT_NFP_MECONFIG
: return "NFP_MECONFIG";
4288 case SHT_NFP_INITREG
: return "NFP_INITREG";
4289 case SHT_NFP_UDEBUG
: return "NFP_UDEBUG";
4290 default: return NULL
;
4295 get_v850_section_type_name (unsigned int sh_type
)
4299 case SHT_V850_SCOMMON
: return "V850 Small Common";
4300 case SHT_V850_TCOMMON
: return "V850 Tiny Common";
4301 case SHT_V850_ZCOMMON
: return "V850 Zero Common";
4302 case SHT_RENESAS_IOP
: return "RENESAS IOP";
4303 case SHT_RENESAS_INFO
: return "RENESAS INFO";
4304 default: return NULL
;
4309 get_riscv_section_type_name (unsigned int sh_type
)
4313 case SHT_RISCV_ATTRIBUTES
: return "RISCV_ATTRIBUTES";
4314 default: return NULL
;
4319 get_csky_section_type_name (unsigned int sh_type
)
4323 case SHT_CSKY_ATTRIBUTES
: return "CSKY_ATTRIBUTES";
4324 default: return NULL
;
4329 get_section_type_name (Filedata
* filedata
, unsigned int sh_type
)
4331 static char buff
[32];
4332 const char * result
;
4336 case SHT_NULL
: return "NULL";
4337 case SHT_PROGBITS
: return "PROGBITS";
4338 case SHT_SYMTAB
: return "SYMTAB";
4339 case SHT_STRTAB
: return "STRTAB";
4340 case SHT_RELA
: return "RELA";
4341 case SHT_HASH
: return "HASH";
4342 case SHT_DYNAMIC
: return "DYNAMIC";
4343 case SHT_NOTE
: return "NOTE";
4344 case SHT_NOBITS
: return "NOBITS";
4345 case SHT_REL
: return "REL";
4346 case SHT_SHLIB
: return "SHLIB";
4347 case SHT_DYNSYM
: return "DYNSYM";
4348 case SHT_INIT_ARRAY
: return "INIT_ARRAY";
4349 case SHT_FINI_ARRAY
: return "FINI_ARRAY";
4350 case SHT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
4351 case SHT_GNU_HASH
: return "GNU_HASH";
4352 case SHT_GROUP
: return "GROUP";
4353 case SHT_SYMTAB_SHNDX
: return "SYMTAB SECTION INDICES";
4354 case SHT_GNU_verdef
: return "VERDEF";
4355 case SHT_GNU_verneed
: return "VERNEED";
4356 case SHT_GNU_versym
: return "VERSYM";
4357 case 0x6ffffff0: return "VERSYM";
4358 case 0x6ffffffc: return "VERDEF";
4359 case 0x7ffffffd: return "AUXILIARY";
4360 case 0x7fffffff: return "FILTER";
4361 case SHT_GNU_LIBLIST
: return "GNU_LIBLIST";
4364 if ((sh_type
>= SHT_LOPROC
) && (sh_type
<= SHT_HIPROC
))
4366 switch (filedata
->file_header
.e_machine
)
4369 case EM_ARC_COMPACT
:
4370 case EM_ARC_COMPACT2
:
4371 result
= get_arc_section_type_name (sh_type
);
4374 case EM_MIPS_RS3_LE
:
4375 result
= get_mips_section_type_name (sh_type
);
4378 result
= get_parisc_section_type_name (sh_type
);
4381 result
= get_ia64_section_type_name (filedata
, sh_type
);
4386 result
= get_x86_64_section_type_name (sh_type
);
4389 result
= get_aarch64_section_type_name (sh_type
);
4392 result
= get_arm_section_type_name (sh_type
);
4395 result
= get_tic6x_section_type_name (sh_type
);
4398 result
= get_msp430_section_type_name (sh_type
);
4401 result
= get_nfp_section_type_name (sh_type
);
4405 case EM_CYGNUS_V850
:
4406 result
= get_v850_section_type_name (sh_type
);
4409 result
= get_riscv_section_type_name (sh_type
);
4412 result
= get_csky_section_type_name (sh_type
);
4422 sprintf (buff
, "LOPROC+%#x", sh_type
- SHT_LOPROC
);
4424 else if ((sh_type
>= SHT_LOOS
) && (sh_type
<= SHT_HIOS
))
4426 switch (filedata
->file_header
.e_machine
)
4429 result
= get_ia64_section_type_name (filedata
, sh_type
);
4432 if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_SOLARIS
)
4433 result
= get_solaris_section_type (sh_type
);
4438 case SHT_GNU_INCREMENTAL_INPUTS
: result
= "GNU_INCREMENTAL_INPUTS"; break;
4439 case SHT_GNU_ATTRIBUTES
: result
= "GNU_ATTRIBUTES"; break;
4440 case SHT_GNU_HASH
: result
= "GNU_HASH"; break;
4441 case SHT_GNU_LIBLIST
: result
= "GNU_LIBLIST"; break;
4453 sprintf (buff
, "LOOS+%#x", sh_type
- SHT_LOOS
);
4455 else if ((sh_type
>= SHT_LOUSER
) && (sh_type
<= SHT_HIUSER
))
4457 switch (filedata
->file_header
.e_machine
)
4461 case EM_CYGNUS_V850
:
4462 result
= get_v850_section_type_name (sh_type
);
4472 sprintf (buff
, "LOUSER+%#x", sh_type
- SHT_LOUSER
);
4475 /* This message is probably going to be displayed in a 15
4476 character wide field, so put the hex value first. */
4477 snprintf (buff
, sizeof (buff
), _("%08x: <unknown>"), sh_type
);
4483 enum long_option_values
4485 OPTION_DEBUG_DUMP
= 512,
4495 OPTION_WITH_SYMBOL_VERSIONS
,
4496 OPTION_RECURSE_LIMIT
,
4497 OPTION_NO_RECURSE_LIMIT
,
4498 OPTION_NO_DEMANGLING
4501 static struct option options
[] =
4503 /* Note - This table is alpha-sorted on the 'val'
4504 field in order to make adding new options easier. */
4505 {"arch-specific", no_argument
, 0, 'A'},
4506 {"all", no_argument
, 0, 'a'},
4507 {"demangle", optional_argument
, 0, 'C'},
4508 {"archive-index", no_argument
, 0, 'c'},
4509 {"use-dynamic", no_argument
, 0, 'D'},
4510 {"dynamic", no_argument
, 0, 'd'},
4511 {"headers", no_argument
, 0, 'e'},
4512 {"section-groups", no_argument
, 0, 'g'},
4513 {"help", no_argument
, 0, 'H'},
4514 {"file-header", no_argument
, 0, 'h'},
4515 {"histogram", no_argument
, 0, 'I'},
4516 {"lint", no_argument
, 0, 'L'},
4517 {"enable-checks", no_argument
, 0, 'L'},
4518 {"program-headers", no_argument
, 0, 'l'},
4519 {"segments", no_argument
, 0, 'l'},
4520 {"full-section-name",no_argument
, 0, 'N'},
4521 {"notes", no_argument
, 0, 'n'},
4522 {"string-dump", required_argument
, 0, 'p'},
4523 {"relocated-dump", required_argument
, 0, 'R'},
4524 {"relocs", no_argument
, 0, 'r'},
4525 {"section-headers", no_argument
, 0, 'S'},
4526 {"sections", no_argument
, 0, 'S'},
4527 {"symbols", no_argument
, 0, 's'},
4528 {"syms", no_argument
, 0, 's'},
4529 {"silent-truncation",no_argument
, 0, 'T'},
4530 {"section-details", no_argument
, 0, 't'},
4531 {"unwind", no_argument
, 0, 'u'},
4532 {"version-info", no_argument
, 0, 'V'},
4533 {"version", no_argument
, 0, 'v'},
4534 {"wide", no_argument
, 0, 'W'},
4535 {"hex-dump", required_argument
, 0, 'x'},
4536 {"decompress", no_argument
, 0, 'z'},
4538 {"no-demangle", no_argument
, 0, OPTION_NO_DEMANGLING
},
4539 {"recurse-limit", no_argument
, NULL
, OPTION_RECURSE_LIMIT
},
4540 {"no-recurse-limit", no_argument
, NULL
, OPTION_NO_RECURSE_LIMIT
},
4541 {"no-recursion-limit", no_argument
, NULL
, OPTION_NO_RECURSE_LIMIT
},
4542 {"dyn-syms", no_argument
, 0, OPTION_DYN_SYMS
},
4543 {"lto-syms", no_argument
, 0, OPTION_LTO_SYMS
},
4544 {"debug-dump", optional_argument
, 0, OPTION_DEBUG_DUMP
},
4545 {"dwarf-depth", required_argument
, 0, OPTION_DWARF_DEPTH
},
4546 {"dwarf-start", required_argument
, 0, OPTION_DWARF_START
},
4547 {"dwarf-check", no_argument
, 0, OPTION_DWARF_CHECK
},
4548 #ifdef ENABLE_LIBCTF
4549 {"ctf", required_argument
, 0, OPTION_CTF_DUMP
},
4550 {"ctf-symbols", required_argument
, 0, OPTION_CTF_SYMBOLS
},
4551 {"ctf-strings", required_argument
, 0, OPTION_CTF_STRINGS
},
4552 {"ctf-parent", required_argument
, 0, OPTION_CTF_PARENT
},
4555 {0, no_argument
, 0, 0}
4559 usage (FILE * stream
)
4561 fprintf (stream
, _("Usage: readelf <option(s)> elf-file(s)\n"));
4562 fprintf (stream
, _(" Display information about the contents of ELF format files\n"));
4563 fprintf (stream
, _(" Options are:\n\
4564 -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n\
4565 -h --file-header Display the ELF file header\n\
4566 -l --program-headers Display the program headers\n\
4567 --segments An alias for --program-headers\n\
4568 -S --section-headers Display the sections' header\n\
4569 --sections An alias for --section-headers\n\
4570 -g --section-groups Display the section groups\n\
4571 -t --section-details Display the section details\n\
4572 -e --headers Equivalent to: -h -l -S\n\
4573 -s --syms Display the symbol table\n\
4574 --symbols An alias for --syms\n\
4575 --dyn-syms Display the dynamic symbol table\n\
4576 --lto-syms Display LTO symbol tables\n\
4577 -C --demangle[=STYLE] Decode low-level symbol names into user-level names\n\
4578 The STYLE, if specified, can be `auto' (the default),\n\
4579 `gnu', `lucid', `arm', `hp', `edg', `gnu-v3', `java'\n\
4581 --no-demangle Do not demangle low-level symbol names. (This is the default)\n\
4582 --recurse-limit Enable a demangling recursion limit. (This is the default)\n\
4583 --no-recurse-limit Disable a demangling recursion limit\n\
4584 -n --notes Display the core notes (if present)\n\
4585 -r --relocs Display the relocations (if present)\n\
4586 -u --unwind Display the unwind info (if present)\n\
4587 -d --dynamic Display the dynamic section (if present)\n\
4588 -V --version-info Display the version sections (if present)\n\
4589 -A --arch-specific Display architecture specific information (if any)\n\
4590 -c --archive-index Display the symbol/file index in an archive\n\
4591 -D --use-dynamic Use the dynamic section info when displaying symbols\n\
4592 -L --lint|--enable-checks Display warning messages for possible problems\n\
4593 -x --hex-dump=<number|name>\n\
4594 Dump the contents of section <number|name> as bytes\n\
4595 -p --string-dump=<number|name>\n\
4596 Dump the contents of section <number|name> as strings\n\
4597 -R --relocated-dump=<number|name>\n\
4598 Dump the contents of section <number|name> as relocated bytes\n\
4599 -z --decompress Decompress section before dumping it\n\
4600 -w[lLiaprmfFsoORtUuTgAckK] or\n\
4601 --debug-dump[=rawline,=decodedline,=info,=abbrev,=pubnames,=aranges,=macro,=frames,\n\
4602 =frames-interp,=str,=str-offsets,=loc,=Ranges,=pubtypes,\n\
4603 =gdb_index,=trace_info,=trace_abbrev,=trace_aranges,\n\
4604 =addr,=cu_index,=links,=follow-links]\n\
4605 Display the contents of DWARF debug sections\n"));
4606 fprintf (stream
, _("\
4607 --dwarf-depth=N Do not display DIEs at depth N or greater\n\
4608 --dwarf-start=N Display DIEs starting with N, at the same depth\n\
4610 #ifdef ENABLE_LIBCTF
4611 fprintf (stream
, _("\
4612 --ctf=<number|name> Display CTF info from section <number|name>\n\
4613 --ctf-parent=<number|name>\n\
4614 Use section <number|name> as the CTF parent\n\n\
4615 --ctf-symbols=<number|name>\n\
4616 Use section <number|name> as the CTF external symtab\n\n\
4617 --ctf-strings=<number|name>\n\
4618 Use section <number|name> as the CTF external strtab\n\n"));
4621 #ifdef SUPPORT_DISASSEMBLY
4622 fprintf (stream
, _("\
4623 -i --instruction-dump=<number|name>\n\
4624 Disassemble the contents of section <number|name>\n"));
4626 fprintf (stream
, _("\
4627 -I --histogram Display histogram of bucket list lengths\n\
4628 -W --wide Allow output width to exceed 80 characters\n\
4629 -T --silent-truncation If a symbol name is truncated, do not add a suffix [...]\n\
4630 @<file> Read options from <file>\n\
4631 -H --help Display this information\n\
4632 -v --version Display the version number of readelf\n"));
4634 if (REPORT_BUGS_TO
[0] && stream
== stdout
)
4635 fprintf (stdout
, _("Report bugs to %s\n"), REPORT_BUGS_TO
);
4637 exit (stream
== stdout
? 0 : 1);
4640 /* Record the fact that the user wants the contents of section number
4641 SECTION to be displayed using the method(s) encoded as flags bits
4642 in TYPE. Note, TYPE can be zero if we are creating the array for
4646 request_dump_bynumber (struct dump_data
*dumpdata
,
4647 unsigned int section
, dump_type type
)
4649 if (section
>= dumpdata
->num_dump_sects
)
4651 dump_type
* new_dump_sects
;
4653 new_dump_sects
= (dump_type
*) calloc (section
+ 1,
4654 sizeof (* new_dump_sects
));
4656 if (new_dump_sects
== NULL
)
4657 error (_("Out of memory allocating dump request table.\n"));
4660 if (dumpdata
->dump_sects
)
4662 /* Copy current flag settings. */
4663 memcpy (new_dump_sects
, dumpdata
->dump_sects
,
4664 dumpdata
->num_dump_sects
* sizeof (* new_dump_sects
));
4666 free (dumpdata
->dump_sects
);
4669 dumpdata
->dump_sects
= new_dump_sects
;
4670 dumpdata
->num_dump_sects
= section
+ 1;
4674 if (dumpdata
->dump_sects
)
4675 dumpdata
->dump_sects
[section
] |= type
;
4678 /* Request a dump by section name. */
4681 request_dump_byname (const char * section
, dump_type type
)
4683 struct dump_list_entry
* new_request
;
4685 new_request
= (struct dump_list_entry
*)
4686 malloc (sizeof (struct dump_list_entry
));
4688 error (_("Out of memory allocating dump request table.\n"));
4690 new_request
->name
= strdup (section
);
4691 if (!new_request
->name
)
4692 error (_("Out of memory allocating dump request table.\n"));
4694 new_request
->type
= type
;
4696 new_request
->next
= dump_sects_byname
;
4697 dump_sects_byname
= new_request
;
4701 request_dump (struct dump_data
*dumpdata
, dump_type type
)
4707 section
= strtoul (optarg
, & cp
, 0);
4709 if (! *cp
&& section
>= 0)
4710 request_dump_bynumber (dumpdata
, section
, type
);
4712 request_dump_byname (optarg
, type
);
4716 parse_args (struct dump_data
*dumpdata
, int argc
, char ** argv
)
4723 while ((c
= getopt_long
4724 (argc
, argv
, "ACDHILNR:STVWacdeghi:lnp:rstuvw::x:z", options
, NULL
)) != EOF
)
4742 do_section_groups
= TRUE
;
4745 do_histogram
= TRUE
;
4751 do_section_groups
= TRUE
;
4756 do_section_details
= TRUE
;
4767 do_using_dynamic
= TRUE
;
4791 do_histogram
= TRUE
;
4797 do_archive_index
= TRUE
;
4803 request_dump (dumpdata
, HEX_DUMP
);
4806 request_dump (dumpdata
, STRING_DUMP
);
4809 request_dump (dumpdata
, RELOC_DUMP
);
4812 decompress_dumps
= TRUE
;
4818 do_debugging
= TRUE
;
4819 dwarf_select_sections_all ();
4823 do_debugging
= FALSE
;
4824 dwarf_select_sections_by_letters (optarg
);
4827 case OPTION_DEBUG_DUMP
:
4830 do_debugging
= TRUE
;
4833 do_debugging
= FALSE
;
4834 dwarf_select_sections_by_names (optarg
);
4837 case OPTION_DWARF_DEPTH
:
4841 dwarf_cutoff_level
= strtoul (optarg
, & cp
, 0);
4844 case OPTION_DWARF_START
:
4848 dwarf_start_die
= strtoul (optarg
, & cp
, 0);
4851 case OPTION_DWARF_CHECK
:
4854 case OPTION_CTF_DUMP
:
4856 request_dump (dumpdata
, CTF_DUMP
);
4858 case OPTION_CTF_SYMBOLS
:
4859 free (dump_ctf_symtab_name
);
4860 dump_ctf_symtab_name
= strdup (optarg
);
4862 case OPTION_CTF_STRINGS
:
4863 free (dump_ctf_strtab_name
);
4864 dump_ctf_strtab_name
= strdup (optarg
);
4866 case OPTION_CTF_PARENT
:
4867 free (dump_ctf_parent_name
);
4868 dump_ctf_parent_name
= strdup (optarg
);
4870 case OPTION_DYN_SYMS
:
4873 case OPTION_LTO_SYMS
:
4876 #ifdef SUPPORT_DISASSEMBLY
4878 request_dump (dumpdata
, DISASS_DUMP
);
4882 print_version (program_name
);
4891 do_not_show_symbol_truncation
= TRUE
;
4897 enum demangling_styles style
;
4899 style
= cplus_demangle_name_to_style (optarg
);
4900 if (style
== unknown_demangling
)
4901 error (_("unknown demangling style `%s'"), optarg
);
4903 cplus_demangle_set_style (style
);
4906 case OPTION_NO_DEMANGLING
:
4907 do_demangle
= FALSE
;
4909 case OPTION_RECURSE_LIMIT
:
4910 demangle_flags
&= ~ DMGL_NO_RECURSE_LIMIT
;
4912 case OPTION_NO_RECURSE_LIMIT
:
4913 demangle_flags
|= DMGL_NO_RECURSE_LIMIT
;
4915 case OPTION_WITH_SYMBOL_VERSIONS
:
4916 /* Ignored for backward compatibility. */
4920 /* xgettext:c-format */
4921 error (_("Invalid option '-%c'\n"), c
);
4928 if (!do_dynamic
&& !do_syms
&& !do_reloc
&& !do_unwind
&& !do_sections
4929 && !do_segments
&& !do_header
&& !do_dump
&& !do_version
4930 && !do_histogram
&& !do_debugging
&& !do_arch
&& !do_notes
4931 && !do_section_groups
&& !do_archive_index
4932 && !do_dyn_syms
&& !do_lto_syms
)
4937 do_dynamic
= do_syms
= do_reloc
= do_unwind
= do_sections
= TRUE
;
4938 do_segments
= do_header
= do_dump
= do_version
= TRUE
;
4939 do_histogram
= do_debugging
= do_arch
= do_notes
= TRUE
;
4940 do_section_groups
= do_archive_index
= do_dyn_syms
= TRUE
;
4949 get_elf_class (unsigned int elf_class
)
4951 static char buff
[32];
4955 case ELFCLASSNONE
: return _("none");
4956 case ELFCLASS32
: return "ELF32";
4957 case ELFCLASS64
: return "ELF64";
4959 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), elf_class
);
4965 get_data_encoding (unsigned int encoding
)
4967 static char buff
[32];
4971 case ELFDATANONE
: return _("none");
4972 case ELFDATA2LSB
: return _("2's complement, little endian");
4973 case ELFDATA2MSB
: return _("2's complement, big endian");
4975 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), encoding
);
4980 /* Decode the data held in 'filedata->file_header'. */
4983 process_file_header (Filedata
* filedata
)
4985 Elf_Internal_Ehdr
* header
= & filedata
->file_header
;
4987 if ( header
->e_ident
[EI_MAG0
] != ELFMAG0
4988 || header
->e_ident
[EI_MAG1
] != ELFMAG1
4989 || header
->e_ident
[EI_MAG2
] != ELFMAG2
4990 || header
->e_ident
[EI_MAG3
] != ELFMAG3
)
4993 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
4997 init_dwarf_regnames_by_elf_machine_code (header
->e_machine
);
5003 printf (_("ELF Header:\n"));
5004 printf (_(" Magic: "));
5005 for (i
= 0; i
< EI_NIDENT
; i
++)
5006 printf ("%2.2x ", header
->e_ident
[i
]);
5008 printf (_(" Class: %s\n"),
5009 get_elf_class (header
->e_ident
[EI_CLASS
]));
5010 printf (_(" Data: %s\n"),
5011 get_data_encoding (header
->e_ident
[EI_DATA
]));
5012 printf (_(" Version: %d%s\n"),
5013 header
->e_ident
[EI_VERSION
],
5014 (header
->e_ident
[EI_VERSION
] == EV_CURRENT
5016 : (header
->e_ident
[EI_VERSION
] != EV_NONE
5019 printf (_(" OS/ABI: %s\n"),
5020 get_osabi_name (filedata
, header
->e_ident
[EI_OSABI
]));
5021 printf (_(" ABI Version: %d\n"),
5022 header
->e_ident
[EI_ABIVERSION
]);
5023 printf (_(" Type: %s\n"),
5024 get_file_type (header
->e_type
));
5025 printf (_(" Machine: %s\n"),
5026 get_machine_name (header
->e_machine
));
5027 printf (_(" Version: 0x%lx\n"),
5030 printf (_(" Entry point address: "));
5031 print_vma (header
->e_entry
, PREFIX_HEX
);
5032 printf (_("\n Start of program headers: "));
5033 print_vma (header
->e_phoff
, DEC
);
5034 printf (_(" (bytes into file)\n Start of section headers: "));
5035 print_vma (header
->e_shoff
, DEC
);
5036 printf (_(" (bytes into file)\n"));
5038 printf (_(" Flags: 0x%lx%s\n"),
5040 get_machine_flags (filedata
, header
->e_flags
, header
->e_machine
));
5041 printf (_(" Size of this header: %u (bytes)\n"),
5043 printf (_(" Size of program headers: %u (bytes)\n"),
5044 header
->e_phentsize
);
5045 printf (_(" Number of program headers: %u"),
5047 if (filedata
->section_headers
!= NULL
5048 && header
->e_phnum
== PN_XNUM
5049 && filedata
->section_headers
[0].sh_info
!= 0)
5051 header
->e_phnum
= filedata
->section_headers
[0].sh_info
;
5052 printf (" (%u)", header
->e_phnum
);
5054 putc ('\n', stdout
);
5055 printf (_(" Size of section headers: %u (bytes)\n"),
5056 header
->e_shentsize
);
5057 printf (_(" Number of section headers: %u"),
5059 if (filedata
->section_headers
!= NULL
&& header
->e_shnum
== SHN_UNDEF
)
5061 header
->e_shnum
= filedata
->section_headers
[0].sh_size
;
5062 printf (" (%u)", header
->e_shnum
);
5064 putc ('\n', stdout
);
5065 printf (_(" Section header string table index: %u"),
5066 header
->e_shstrndx
);
5067 if (filedata
->section_headers
!= NULL
5068 && header
->e_shstrndx
== (SHN_XINDEX
& 0xffff))
5070 header
->e_shstrndx
= filedata
->section_headers
[0].sh_link
;
5071 printf (" (%u)", header
->e_shstrndx
);
5073 if (header
->e_shstrndx
!= SHN_UNDEF
5074 && header
->e_shstrndx
>= header
->e_shnum
)
5076 header
->e_shstrndx
= SHN_UNDEF
;
5077 printf (_(" <corrupt: out of range>"));
5079 putc ('\n', stdout
);
5082 if (filedata
->section_headers
!= NULL
)
5084 if (header
->e_phnum
== PN_XNUM
5085 && filedata
->section_headers
[0].sh_info
!= 0)
5086 header
->e_phnum
= filedata
->section_headers
[0].sh_info
;
5087 if (header
->e_shnum
== SHN_UNDEF
)
5088 header
->e_shnum
= filedata
->section_headers
[0].sh_size
;
5089 if (header
->e_shstrndx
== (SHN_XINDEX
& 0xffff))
5090 header
->e_shstrndx
= filedata
->section_headers
[0].sh_link
;
5091 if (header
->e_shstrndx
>= header
->e_shnum
)
5092 header
->e_shstrndx
= SHN_UNDEF
;
5093 free (filedata
->section_headers
);
5094 filedata
->section_headers
= NULL
;
5100 /* Read in the program headers from FILEDATA and store them in PHEADERS.
5101 Returns TRUE upon success, FALSE otherwise. Loads 32-bit headers. */
5104 get_32bit_program_headers (Filedata
* filedata
, Elf_Internal_Phdr
* pheaders
)
5106 Elf32_External_Phdr
* phdrs
;
5107 Elf32_External_Phdr
* external
;
5108 Elf_Internal_Phdr
* internal
;
5110 unsigned int size
= filedata
->file_header
.e_phentsize
;
5111 unsigned int num
= filedata
->file_header
.e_phnum
;
5113 /* PR binutils/17531: Cope with unexpected section header sizes. */
5114 if (size
== 0 || num
== 0)
5116 if (size
< sizeof * phdrs
)
5118 error (_("The e_phentsize field in the ELF header is less than the size of an ELF program header\n"));
5121 if (size
> sizeof * phdrs
)
5122 warn (_("The e_phentsize field in the ELF header is larger than the size of an ELF program header\n"));
5124 phdrs
= (Elf32_External_Phdr
*) get_data (NULL
, filedata
, filedata
->file_header
.e_phoff
,
5125 size
, num
, _("program headers"));
5129 for (i
= 0, internal
= pheaders
, external
= phdrs
;
5130 i
< filedata
->file_header
.e_phnum
;
5131 i
++, internal
++, external
++)
5133 internal
->p_type
= BYTE_GET (external
->p_type
);
5134 internal
->p_offset
= BYTE_GET (external
->p_offset
);
5135 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
5136 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
5137 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
5138 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
5139 internal
->p_flags
= BYTE_GET (external
->p_flags
);
5140 internal
->p_align
= BYTE_GET (external
->p_align
);
5147 /* Read in the program headers from FILEDATA and store them in PHEADERS.
5148 Returns TRUE upon success, FALSE otherwise. Loads 64-bit headers. */
5151 get_64bit_program_headers (Filedata
* filedata
, Elf_Internal_Phdr
* pheaders
)
5153 Elf64_External_Phdr
* phdrs
;
5154 Elf64_External_Phdr
* external
;
5155 Elf_Internal_Phdr
* internal
;
5157 unsigned int size
= filedata
->file_header
.e_phentsize
;
5158 unsigned int num
= filedata
->file_header
.e_phnum
;
5160 /* PR binutils/17531: Cope with unexpected section header sizes. */
5161 if (size
== 0 || num
== 0)
5163 if (size
< sizeof * phdrs
)
5165 error (_("The e_phentsize field in the ELF header is less than the size of an ELF program header\n"));
5168 if (size
> sizeof * phdrs
)
5169 warn (_("The e_phentsize field in the ELF header is larger than the size of an ELF program header\n"));
5171 phdrs
= (Elf64_External_Phdr
*) get_data (NULL
, filedata
, filedata
->file_header
.e_phoff
,
5172 size
, num
, _("program headers"));
5176 for (i
= 0, internal
= pheaders
, external
= phdrs
;
5177 i
< filedata
->file_header
.e_phnum
;
5178 i
++, internal
++, external
++)
5180 internal
->p_type
= BYTE_GET (external
->p_type
);
5181 internal
->p_flags
= BYTE_GET (external
->p_flags
);
5182 internal
->p_offset
= BYTE_GET (external
->p_offset
);
5183 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
5184 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
5185 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
5186 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
5187 internal
->p_align
= BYTE_GET (external
->p_align
);
5194 /* Returns TRUE if the program headers were read into `program_headers'. */
5197 get_program_headers (Filedata
* filedata
)
5199 Elf_Internal_Phdr
* phdrs
;
5201 /* Check cache of prior read. */
5202 if (filedata
->program_headers
!= NULL
)
5205 /* Be kind to memory checkers by looking for
5206 e_phnum values which we know must be invalid. */
5207 if (filedata
->file_header
.e_phnum
5208 * (is_32bit_elf
? sizeof (Elf32_External_Phdr
) : sizeof (Elf64_External_Phdr
))
5209 >= filedata
->file_size
)
5211 error (_("Too many program headers - %#x - the file is not that big\n"),
5212 filedata
->file_header
.e_phnum
);
5216 phdrs
= (Elf_Internal_Phdr
*) cmalloc (filedata
->file_header
.e_phnum
,
5217 sizeof (Elf_Internal_Phdr
));
5220 error (_("Out of memory reading %u program headers\n"),
5221 filedata
->file_header
.e_phnum
);
5226 ? get_32bit_program_headers (filedata
, phdrs
)
5227 : get_64bit_program_headers (filedata
, phdrs
))
5229 filedata
->program_headers
= phdrs
;
5237 /* Returns TRUE if the program headers were loaded. */
5240 process_program_headers (Filedata
* filedata
)
5242 Elf_Internal_Phdr
* segment
;
5244 Elf_Internal_Phdr
* previous_load
= NULL
;
5246 filedata
->dynamic_addr
= 0;
5247 filedata
->dynamic_size
= 0;
5249 if (filedata
->file_header
.e_phnum
== 0)
5251 /* PR binutils/12467. */
5252 if (filedata
->file_header
.e_phoff
!= 0)
5254 warn (_("possibly corrupt ELF header - it has a non-zero program"
5255 " header offset, but no program headers\n"));
5258 else if (do_segments
)
5259 printf (_("\nThere are no program headers in this file.\n"));
5263 if (do_segments
&& !do_header
)
5265 printf (_("\nElf file type is %s\n"), get_file_type (filedata
->file_header
.e_type
));
5266 printf (_("Entry point 0x%s\n"), bfd_vmatoa ("x", filedata
->file_header
.e_entry
));
5267 printf (ngettext ("There is %d program header, starting at offset %s\n",
5268 "There are %d program headers, starting at offset %s\n",
5269 filedata
->file_header
.e_phnum
),
5270 filedata
->file_header
.e_phnum
,
5271 bfd_vmatoa ("u", filedata
->file_header
.e_phoff
));
5274 if (! get_program_headers (filedata
))
5279 if (filedata
->file_header
.e_phnum
> 1)
5280 printf (_("\nProgram Headers:\n"));
5282 printf (_("\nProgram Headers:\n"));
5286 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
5289 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
5293 (_(" Type Offset VirtAddr PhysAddr\n"));
5295 (_(" FileSiz MemSiz Flags Align\n"));
5299 for (i
= 0, segment
= filedata
->program_headers
;
5300 i
< filedata
->file_header
.e_phnum
;
5305 printf (" %-14.14s ", get_segment_type (filedata
, segment
->p_type
));
5309 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
5310 printf ("0x%8.8lx ", (unsigned long) segment
->p_vaddr
);
5311 printf ("0x%8.8lx ", (unsigned long) segment
->p_paddr
);
5312 printf ("0x%5.5lx ", (unsigned long) segment
->p_filesz
);
5313 printf ("0x%5.5lx ", (unsigned long) segment
->p_memsz
);
5315 (segment
->p_flags
& PF_R
? 'R' : ' '),
5316 (segment
->p_flags
& PF_W
? 'W' : ' '),
5317 (segment
->p_flags
& PF_X
? 'E' : ' '));
5318 printf ("%#lx", (unsigned long) segment
->p_align
);
5322 if ((unsigned long) segment
->p_offset
== segment
->p_offset
)
5323 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
5326 print_vma (segment
->p_offset
, FULL_HEX
);
5330 print_vma (segment
->p_vaddr
, FULL_HEX
);
5332 print_vma (segment
->p_paddr
, FULL_HEX
);
5335 if ((unsigned long) segment
->p_filesz
== segment
->p_filesz
)
5336 printf ("0x%6.6lx ", (unsigned long) segment
->p_filesz
);
5339 print_vma (segment
->p_filesz
, FULL_HEX
);
5343 if ((unsigned long) segment
->p_memsz
== segment
->p_memsz
)
5344 printf ("0x%6.6lx", (unsigned long) segment
->p_memsz
);
5347 print_vma (segment
->p_memsz
, FULL_HEX
);
5351 (segment
->p_flags
& PF_R
? 'R' : ' '),
5352 (segment
->p_flags
& PF_W
? 'W' : ' '),
5353 (segment
->p_flags
& PF_X
? 'E' : ' '));
5355 if ((unsigned long) segment
->p_align
== segment
->p_align
)
5356 printf ("%#lx", (unsigned long) segment
->p_align
);
5359 print_vma (segment
->p_align
, PREFIX_HEX
);
5364 print_vma (segment
->p_offset
, FULL_HEX
);
5366 print_vma (segment
->p_vaddr
, FULL_HEX
);
5368 print_vma (segment
->p_paddr
, FULL_HEX
);
5370 print_vma (segment
->p_filesz
, FULL_HEX
);
5372 print_vma (segment
->p_memsz
, FULL_HEX
);
5374 (segment
->p_flags
& PF_R
? 'R' : ' '),
5375 (segment
->p_flags
& PF_W
? 'W' : ' '),
5376 (segment
->p_flags
& PF_X
? 'E' : ' '));
5377 print_vma (segment
->p_align
, PREFIX_HEX
);
5380 putc ('\n', stdout
);
5383 switch (segment
->p_type
)
5386 #if 0 /* Do not warn about out of order PT_LOAD segments. Although officially
5387 required by the ELF standard, several programs, including the Linux
5388 kernel, make use of non-ordered segments. */
5390 && previous_load
->p_vaddr
> segment
->p_vaddr
)
5391 error (_("LOAD segments must be sorted in order of increasing VirtAddr\n"));
5393 if (segment
->p_memsz
< segment
->p_filesz
)
5394 error (_("the segment's file size is larger than its memory size\n"));
5395 previous_load
= segment
;
5399 /* PR 20815 - Verify that the program header is loaded into memory. */
5400 if (i
> 0 && previous_load
!= NULL
)
5401 error (_("the PHDR segment must occur before any LOAD segment\n"));
5402 if (filedata
->file_header
.e_machine
!= EM_PARISC
)
5406 for (j
= 1; j
< filedata
->file_header
.e_phnum
; j
++)
5408 Elf_Internal_Phdr
*load
= filedata
->program_headers
+ j
;
5409 if (load
->p_type
== PT_LOAD
5410 && load
->p_offset
<= segment
->p_offset
5411 && (load
->p_offset
+ load
->p_filesz
5412 >= segment
->p_offset
+ segment
->p_filesz
)
5413 && load
->p_vaddr
<= segment
->p_vaddr
5414 && (load
->p_vaddr
+ load
->p_filesz
5415 >= segment
->p_vaddr
+ segment
->p_filesz
))
5418 if (j
== filedata
->file_header
.e_phnum
)
5419 error (_("the PHDR segment is not covered by a LOAD segment\n"));
5424 if (filedata
->dynamic_addr
)
5425 error (_("more than one dynamic segment\n"));
5427 /* By default, assume that the .dynamic section is the first
5428 section in the DYNAMIC segment. */
5429 filedata
->dynamic_addr
= segment
->p_offset
;
5430 filedata
->dynamic_size
= segment
->p_filesz
;
5432 /* Try to locate the .dynamic section. If there is
5433 a section header table, we can easily locate it. */
5434 if (filedata
->section_headers
!= NULL
)
5436 Elf_Internal_Shdr
* sec
;
5438 sec
= find_section (filedata
, ".dynamic");
5439 if (sec
== NULL
|| sec
->sh_size
== 0)
5441 /* A corresponding .dynamic section is expected, but on
5442 IA-64/OpenVMS it is OK for it to be missing. */
5443 if (!is_ia64_vms (filedata
))
5444 error (_("no .dynamic section in the dynamic segment\n"));
5448 if (sec
->sh_type
== SHT_NOBITS
)
5450 filedata
->dynamic_size
= 0;
5454 filedata
->dynamic_addr
= sec
->sh_offset
;
5455 filedata
->dynamic_size
= sec
->sh_size
;
5457 /* The PT_DYNAMIC segment, which is used by the run-time
5458 loader, should exactly match the .dynamic section. */
5460 && (filedata
->dynamic_addr
!= segment
->p_offset
5461 || filedata
->dynamic_size
!= segment
->p_filesz
))
5463 the .dynamic section is not the same as the dynamic segment\n"));
5466 /* PR binutils/17512: Avoid corrupt dynamic section info in the
5467 segment. Check this after matching against the section headers
5468 so we don't warn on debuginfo file (which have NOBITS .dynamic
5470 if (filedata
->dynamic_addr
> filedata
->file_size
5471 || (filedata
->dynamic_size
5472 > filedata
->file_size
- filedata
->dynamic_addr
))
5474 error (_("the dynamic segment offset + size exceeds the size of the file\n"));
5475 filedata
->dynamic_addr
= filedata
->dynamic_size
= 0;
5480 if (fseek (filedata
->handle
,
5481 filedata
->archive_file_offset
+ (long) segment
->p_offset
,
5483 error (_("Unable to find program interpreter name\n"));
5487 int ret
= snprintf (fmt
, sizeof (fmt
), "%%%ds", PATH_MAX
- 1);
5489 if (ret
>= (int) sizeof (fmt
) || ret
< 0)
5490 error (_("Internal error: failed to create format string to display program interpreter\n"));
5492 filedata
->program_interpreter
[0] = 0;
5493 if (fscanf (filedata
->handle
, fmt
,
5494 filedata
->program_interpreter
) <= 0)
5495 error (_("Unable to read program interpreter name\n"));
5498 printf (_(" [Requesting program interpreter: %s]\n"),
5499 filedata
->program_interpreter
);
5506 && filedata
->section_headers
!= NULL
5507 && filedata
->string_table
!= NULL
)
5509 printf (_("\n Section to Segment mapping:\n"));
5510 printf (_(" Segment Sections...\n"));
5512 for (i
= 0; i
< filedata
->file_header
.e_phnum
; i
++)
5515 Elf_Internal_Shdr
* section
;
5517 segment
= filedata
->program_headers
+ i
;
5518 section
= filedata
->section_headers
+ 1;
5520 printf (" %2.2d ", i
);
5522 for (j
= 1; j
< filedata
->file_header
.e_shnum
; j
++, section
++)
5524 if (!ELF_TBSS_SPECIAL (section
, segment
)
5525 && ELF_SECTION_IN_SEGMENT_STRICT (section
, segment
))
5526 printf ("%s ", printable_section_name (filedata
, section
));
5537 /* Find the file offset corresponding to VMA by using the program headers. */
5540 offset_from_vma (Filedata
* filedata
, bfd_vma vma
, bfd_size_type size
)
5542 Elf_Internal_Phdr
* seg
;
5544 if (! get_program_headers (filedata
))
5546 warn (_("Cannot interpret virtual addresses without program headers.\n"));
5550 for (seg
= filedata
->program_headers
;
5551 seg
< filedata
->program_headers
+ filedata
->file_header
.e_phnum
;
5554 if (seg
->p_type
!= PT_LOAD
)
5557 if (vma
>= (seg
->p_vaddr
& -seg
->p_align
)
5558 && vma
+ size
<= seg
->p_vaddr
+ seg
->p_filesz
)
5559 return vma
- seg
->p_vaddr
+ seg
->p_offset
;
5562 warn (_("Virtual address 0x%lx not located in any PT_LOAD segment.\n"),
5563 (unsigned long) vma
);
5568 /* Allocate memory and load the sections headers into FILEDATA->filedata->section_headers.
5569 If PROBE is true, this is just a probe and we do not generate any error
5570 messages if the load fails. */
5573 get_32bit_section_headers (Filedata
* filedata
, bfd_boolean probe
)
5575 Elf32_External_Shdr
* shdrs
;
5576 Elf_Internal_Shdr
* internal
;
5578 unsigned int size
= filedata
->file_header
.e_shentsize
;
5579 unsigned int num
= probe
? 1 : filedata
->file_header
.e_shnum
;
5581 /* PR binutils/17531: Cope with unexpected section header sizes. */
5582 if (size
== 0 || num
== 0)
5584 if (size
< sizeof * shdrs
)
5587 error (_("The e_shentsize field in the ELF header is less than the size of an ELF section header\n"));
5590 if (!probe
&& size
> sizeof * shdrs
)
5591 warn (_("The e_shentsize field in the ELF header is larger than the size of an ELF section header\n"));
5593 shdrs
= (Elf32_External_Shdr
*) get_data (NULL
, filedata
, filedata
->file_header
.e_shoff
,
5595 probe
? NULL
: _("section headers"));
5599 free (filedata
->section_headers
);
5600 filedata
->section_headers
= (Elf_Internal_Shdr
*)
5601 cmalloc (num
, sizeof (Elf_Internal_Shdr
));
5602 if (filedata
->section_headers
== NULL
)
5605 error (_("Out of memory reading %u section headers\n"), num
);
5610 for (i
= 0, internal
= filedata
->section_headers
;
5614 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
5615 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
5616 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
5617 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
5618 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
5619 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
5620 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
5621 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
5622 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
5623 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
5624 if (!probe
&& internal
->sh_link
> num
)
5625 warn (_("Section %u has an out of range sh_link value of %u\n"), i
, internal
->sh_link
);
5626 if (!probe
&& internal
->sh_flags
& SHF_INFO_LINK
&& internal
->sh_info
> num
)
5627 warn (_("Section %u has an out of range sh_info value of %u\n"), i
, internal
->sh_info
);
5634 /* Like get_32bit_section_headers, except that it fetches 64-bit headers. */
5637 get_64bit_section_headers (Filedata
* filedata
, bfd_boolean probe
)
5639 Elf64_External_Shdr
* shdrs
;
5640 Elf_Internal_Shdr
* internal
;
5642 unsigned int size
= filedata
->file_header
.e_shentsize
;
5643 unsigned int num
= probe
? 1 : filedata
->file_header
.e_shnum
;
5645 /* PR binutils/17531: Cope with unexpected section header sizes. */
5646 if (size
== 0 || num
== 0)
5649 if (size
< sizeof * shdrs
)
5652 error (_("The e_shentsize field in the ELF header is less than the size of an ELF section header\n"));
5656 if (! probe
&& size
> sizeof * shdrs
)
5657 warn (_("The e_shentsize field in the ELF header is larger than the size of an ELF section header\n"));
5659 shdrs
= (Elf64_External_Shdr
*) get_data (NULL
, filedata
,
5660 filedata
->file_header
.e_shoff
,
5662 probe
? NULL
: _("section headers"));
5666 free (filedata
->section_headers
);
5667 filedata
->section_headers
= (Elf_Internal_Shdr
*)
5668 cmalloc (num
, sizeof (Elf_Internal_Shdr
));
5669 if (filedata
->section_headers
== NULL
)
5672 error (_("Out of memory reading %u section headers\n"), num
);
5677 for (i
= 0, internal
= filedata
->section_headers
;
5681 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
5682 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
5683 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
5684 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
5685 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
5686 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
5687 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
5688 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
5689 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
5690 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
5691 if (!probe
&& internal
->sh_link
> num
)
5692 warn (_("Section %u has an out of range sh_link value of %u\n"), i
, internal
->sh_link
);
5693 if (!probe
&& internal
->sh_flags
& SHF_INFO_LINK
&& internal
->sh_info
> num
)
5694 warn (_("Section %u has an out of range sh_info value of %u\n"), i
, internal
->sh_info
);
5701 static Elf_Internal_Sym
*
5702 get_32bit_elf_symbols (Filedata
* filedata
,
5703 Elf_Internal_Shdr
* section
,
5704 unsigned long * num_syms_return
)
5706 unsigned long number
= 0;
5707 Elf32_External_Sym
* esyms
= NULL
;
5708 Elf_External_Sym_Shndx
* shndx
= NULL
;
5709 Elf_Internal_Sym
* isyms
= NULL
;
5710 Elf_Internal_Sym
* psym
;
5712 elf_section_list
* entry
;
5714 if (section
->sh_size
== 0)
5716 if (num_syms_return
!= NULL
)
5717 * num_syms_return
= 0;
5721 /* Run some sanity checks first. */
5722 if (section
->sh_entsize
== 0 || section
->sh_entsize
> section
->sh_size
)
5724 error (_("Section %s has an invalid sh_entsize of 0x%lx\n"),
5725 printable_section_name (filedata
, section
),
5726 (unsigned long) section
->sh_entsize
);
5730 if (section
->sh_size
> filedata
->file_size
)
5732 error (_("Section %s has an invalid sh_size of 0x%lx\n"),
5733 printable_section_name (filedata
, section
),
5734 (unsigned long) section
->sh_size
);
5738 number
= section
->sh_size
/ section
->sh_entsize
;
5740 if (number
* sizeof (Elf32_External_Sym
) > section
->sh_size
+ 1)
5742 error (_("Size (0x%lx) of section %s is not a multiple of its sh_entsize (0x%lx)\n"),
5743 (unsigned long) section
->sh_size
,
5744 printable_section_name (filedata
, section
),
5745 (unsigned long) section
->sh_entsize
);
5749 esyms
= (Elf32_External_Sym
*) get_data (NULL
, filedata
, section
->sh_offset
, 1,
5750 section
->sh_size
, _("symbols"));
5755 for (entry
= filedata
->symtab_shndx_list
; entry
!= NULL
; entry
= entry
->next
)
5757 if (entry
->hdr
->sh_link
!= (unsigned long) (section
- filedata
->section_headers
))
5762 error (_("Multiple symbol table index sections associated with the same symbol section\n"));
5766 shndx
= (Elf_External_Sym_Shndx
*) get_data (NULL
, filedata
,
5767 entry
->hdr
->sh_offset
,
5768 1, entry
->hdr
->sh_size
,
5769 _("symbol table section indices"));
5773 /* PR17531: file: heap-buffer-overflow */
5774 if (entry
->hdr
->sh_size
/ sizeof (Elf_External_Sym_Shndx
) < number
)
5776 error (_("Index section %s has an sh_size of 0x%lx - expected 0x%lx\n"),
5777 printable_section_name (filedata
, entry
->hdr
),
5778 (unsigned long) entry
->hdr
->sh_size
,
5779 (unsigned long) section
->sh_size
);
5784 isyms
= (Elf_Internal_Sym
*) cmalloc (number
, sizeof (Elf_Internal_Sym
));
5788 error (_("Out of memory reading %lu symbols\n"),
5789 (unsigned long) number
);
5793 for (j
= 0, psym
= isyms
; j
< number
; j
++, psym
++)
5795 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
5796 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
5797 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
5798 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
5799 if (psym
->st_shndx
== (SHN_XINDEX
& 0xffff) && shndx
!= NULL
)
5801 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
5802 else if (psym
->st_shndx
>= (SHN_LORESERVE
& 0xffff))
5803 psym
->st_shndx
+= SHN_LORESERVE
- (SHN_LORESERVE
& 0xffff);
5804 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
5805 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
5812 if (num_syms_return
!= NULL
)
5813 * num_syms_return
= isyms
== NULL
? 0 : number
;
5818 static Elf_Internal_Sym
*
5819 get_64bit_elf_symbols (Filedata
* filedata
,
5820 Elf_Internal_Shdr
* section
,
5821 unsigned long * num_syms_return
)
5823 unsigned long number
= 0;
5824 Elf64_External_Sym
* esyms
= NULL
;
5825 Elf_External_Sym_Shndx
* shndx
= NULL
;
5826 Elf_Internal_Sym
* isyms
= NULL
;
5827 Elf_Internal_Sym
* psym
;
5829 elf_section_list
* entry
;
5831 if (section
->sh_size
== 0)
5833 if (num_syms_return
!= NULL
)
5834 * num_syms_return
= 0;
5838 /* Run some sanity checks first. */
5839 if (section
->sh_entsize
== 0 || section
->sh_entsize
> section
->sh_size
)
5841 error (_("Section %s has an invalid sh_entsize of 0x%lx\n"),
5842 printable_section_name (filedata
, section
),
5843 (unsigned long) section
->sh_entsize
);
5847 if (section
->sh_size
> filedata
->file_size
)
5849 error (_("Section %s has an invalid sh_size of 0x%lx\n"),
5850 printable_section_name (filedata
, section
),
5851 (unsigned long) section
->sh_size
);
5855 number
= section
->sh_size
/ section
->sh_entsize
;
5857 if (number
* sizeof (Elf64_External_Sym
) > section
->sh_size
+ 1)
5859 error (_("Size (0x%lx) of section %s is not a multiple of its sh_entsize (0x%lx)\n"),
5860 (unsigned long) section
->sh_size
,
5861 printable_section_name (filedata
, section
),
5862 (unsigned long) section
->sh_entsize
);
5866 esyms
= (Elf64_External_Sym
*) get_data (NULL
, filedata
, section
->sh_offset
, 1,
5867 section
->sh_size
, _("symbols"));
5872 for (entry
= filedata
->symtab_shndx_list
; entry
!= NULL
; entry
= entry
->next
)
5874 if (entry
->hdr
->sh_link
!= (unsigned long) (section
- filedata
->section_headers
))
5879 error (_("Multiple symbol table index sections associated with the same symbol section\n"));
5883 shndx
= (Elf_External_Sym_Shndx
*) get_data (NULL
, filedata
,
5884 entry
->hdr
->sh_offset
,
5885 1, entry
->hdr
->sh_size
,
5886 _("symbol table section indices"));
5890 /* PR17531: file: heap-buffer-overflow */
5891 if (entry
->hdr
->sh_size
/ sizeof (Elf_External_Sym_Shndx
) < number
)
5893 error (_("Index section %s has an sh_size of 0x%lx - expected 0x%lx\n"),
5894 printable_section_name (filedata
, entry
->hdr
),
5895 (unsigned long) entry
->hdr
->sh_size
,
5896 (unsigned long) section
->sh_size
);
5901 isyms
= (Elf_Internal_Sym
*) cmalloc (number
, sizeof (Elf_Internal_Sym
));
5905 error (_("Out of memory reading %lu symbols\n"),
5906 (unsigned long) number
);
5910 for (j
= 0, psym
= isyms
; j
< number
; j
++, psym
++)
5912 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
5913 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
5914 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
5915 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
5917 if (psym
->st_shndx
== (SHN_XINDEX
& 0xffff) && shndx
!= NULL
)
5919 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
5920 else if (psym
->st_shndx
>= (SHN_LORESERVE
& 0xffff))
5921 psym
->st_shndx
+= SHN_LORESERVE
- (SHN_LORESERVE
& 0xffff);
5923 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
5924 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
5931 if (num_syms_return
!= NULL
)
5932 * num_syms_return
= isyms
== NULL
? 0 : number
;
5938 get_elf_section_flags (Filedata
* filedata
, bfd_vma sh_flags
)
5940 static char buff
[1024];
5942 unsigned int field_size
= is_32bit_elf
? 8 : 16;
5944 unsigned int size
= sizeof (buff
) - (field_size
+ 4 + 1);
5945 bfd_vma os_flags
= 0;
5946 bfd_vma proc_flags
= 0;
5947 bfd_vma unknown_flags
= 0;
5955 /* 0 */ { STRING_COMMA_LEN ("WRITE") },
5956 /* 1 */ { STRING_COMMA_LEN ("ALLOC") },
5957 /* 2 */ { STRING_COMMA_LEN ("EXEC") },
5958 /* 3 */ { STRING_COMMA_LEN ("MERGE") },
5959 /* 4 */ { STRING_COMMA_LEN ("STRINGS") },
5960 /* 5 */ { STRING_COMMA_LEN ("INFO LINK") },
5961 /* 6 */ { STRING_COMMA_LEN ("LINK ORDER") },
5962 /* 7 */ { STRING_COMMA_LEN ("OS NONCONF") },
5963 /* 8 */ { STRING_COMMA_LEN ("GROUP") },
5964 /* 9 */ { STRING_COMMA_LEN ("TLS") },
5965 /* IA-64 specific. */
5966 /* 10 */ { STRING_COMMA_LEN ("SHORT") },
5967 /* 11 */ { STRING_COMMA_LEN ("NORECOV") },
5968 /* IA-64 OpenVMS specific. */
5969 /* 12 */ { STRING_COMMA_LEN ("VMS_GLOBAL") },
5970 /* 13 */ { STRING_COMMA_LEN ("VMS_OVERLAID") },
5971 /* 14 */ { STRING_COMMA_LEN ("VMS_SHARED") },
5972 /* 15 */ { STRING_COMMA_LEN ("VMS_VECTOR") },
5973 /* 16 */ { STRING_COMMA_LEN ("VMS_ALLOC_64BIT") },
5974 /* 17 */ { STRING_COMMA_LEN ("VMS_PROTECTED") },
5976 /* 18 */ { STRING_COMMA_LEN ("EXCLUDE") },
5977 /* SPARC specific. */
5978 /* 19 */ { STRING_COMMA_LEN ("ORDERED") },
5979 /* 20 */ { STRING_COMMA_LEN ("COMPRESSED") },
5981 /* 21 */ { STRING_COMMA_LEN ("ENTRYSECT") },
5982 /* 22 */ { STRING_COMMA_LEN ("ARM_PURECODE") },
5983 /* 23 */ { STRING_COMMA_LEN ("COMDEF") },
5985 /* 24 */ { STRING_COMMA_LEN ("GNU_MBIND") },
5987 /* 25 */ { STRING_COMMA_LEN ("VLE") },
5990 if (do_section_details
)
5992 sprintf (buff
, "[%*.*lx]: ",
5993 field_size
, field_size
, (unsigned long) sh_flags
);
5994 p
+= field_size
+ 4;
6001 flag
= sh_flags
& - sh_flags
;
6004 if (do_section_details
)
6008 case SHF_WRITE
: sindex
= 0; break;
6009 case SHF_ALLOC
: sindex
= 1; break;
6010 case SHF_EXECINSTR
: sindex
= 2; break;
6011 case SHF_MERGE
: sindex
= 3; break;
6012 case SHF_STRINGS
: sindex
= 4; break;
6013 case SHF_INFO_LINK
: sindex
= 5; break;
6014 case SHF_LINK_ORDER
: sindex
= 6; break;
6015 case SHF_OS_NONCONFORMING
: sindex
= 7; break;
6016 case SHF_GROUP
: sindex
= 8; break;
6017 case SHF_TLS
: sindex
= 9; break;
6018 case SHF_EXCLUDE
: sindex
= 18; break;
6019 case SHF_COMPRESSED
: sindex
= 20; break;
6020 case SHF_GNU_MBIND
: sindex
= 24; break;
6024 switch (filedata
->file_header
.e_machine
)
6027 if (flag
== SHF_IA_64_SHORT
)
6029 else if (flag
== SHF_IA_64_NORECOV
)
6032 else if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_OPENVMS
)
6035 case SHF_IA_64_VMS_GLOBAL
: sindex
= 12; break;
6036 case SHF_IA_64_VMS_OVERLAID
: sindex
= 13; break;
6037 case SHF_IA_64_VMS_SHARED
: sindex
= 14; break;
6038 case SHF_IA_64_VMS_VECTOR
: sindex
= 15; break;
6039 case SHF_IA_64_VMS_ALLOC_64BIT
: sindex
= 16; break;
6040 case SHF_IA_64_VMS_PROTECTED
: sindex
= 17; break;
6051 case EM_OLD_SPARCV9
:
6052 case EM_SPARC32PLUS
:
6055 if (flag
== SHF_ORDERED
)
6062 case SHF_ENTRYSECT
: sindex
= 21; break;
6063 case SHF_ARM_PURECODE
: sindex
= 22; break;
6064 case SHF_COMDEF
: sindex
= 23; break;
6069 if (flag
== SHF_PPC_VLE
)
6080 if (p
!= buff
+ field_size
+ 4)
6082 if (size
< (10 + 2))
6084 warn (_("Internal error: not enough buffer room for section flag info"));
6085 return _("<unknown>");
6092 size
-= flags
[sindex
].len
;
6093 p
= stpcpy (p
, flags
[sindex
].str
);
6095 else if (flag
& SHF_MASKOS
)
6097 else if (flag
& SHF_MASKPROC
)
6100 unknown_flags
|= flag
;
6106 case SHF_WRITE
: *p
= 'W'; break;
6107 case SHF_ALLOC
: *p
= 'A'; break;
6108 case SHF_EXECINSTR
: *p
= 'X'; break;
6109 case SHF_MERGE
: *p
= 'M'; break;
6110 case SHF_STRINGS
: *p
= 'S'; break;
6111 case SHF_INFO_LINK
: *p
= 'I'; break;
6112 case SHF_LINK_ORDER
: *p
= 'L'; break;
6113 case SHF_OS_NONCONFORMING
: *p
= 'O'; break;
6114 case SHF_GROUP
: *p
= 'G'; break;
6115 case SHF_TLS
: *p
= 'T'; break;
6116 case SHF_EXCLUDE
: *p
= 'E'; break;
6117 case SHF_COMPRESSED
: *p
= 'C'; break;
6118 case SHF_GNU_MBIND
: *p
= 'D'; break;
6121 if ((filedata
->file_header
.e_machine
== EM_X86_64
6122 || filedata
->file_header
.e_machine
== EM_L1OM
6123 || filedata
->file_header
.e_machine
== EM_K1OM
)
6124 && flag
== SHF_X86_64_LARGE
)
6126 else if (filedata
->file_header
.e_machine
== EM_ARM
6127 && flag
== SHF_ARM_PURECODE
)
6129 else if (filedata
->file_header
.e_machine
== EM_PPC
6130 && flag
== SHF_PPC_VLE
)
6132 else if (flag
& SHF_MASKOS
)
6135 sh_flags
&= ~ SHF_MASKOS
;
6137 else if (flag
& SHF_MASKPROC
)
6140 sh_flags
&= ~ SHF_MASKPROC
;
6150 if (do_section_details
)
6154 size
-= 5 + field_size
;
6155 if (p
!= buff
+ field_size
+ 4)
6159 warn (_("Internal error: not enough buffer room for section flag info"));
6160 return _("<unknown>");
6166 sprintf (p
, "OS (%*.*lx)", field_size
, field_size
,
6167 (unsigned long) os_flags
);
6168 p
+= 5 + field_size
;
6172 size
-= 7 + field_size
;
6173 if (p
!= buff
+ field_size
+ 4)
6177 warn (_("Internal error: not enough buffer room for section flag info"));
6178 return _("<unknown>");
6184 sprintf (p
, "PROC (%*.*lx)", field_size
, field_size
,
6185 (unsigned long) proc_flags
);
6186 p
+= 7 + field_size
;
6190 size
-= 10 + field_size
;
6191 if (p
!= buff
+ field_size
+ 4)
6195 warn (_("Internal error: not enough buffer room for section flag info"));
6196 return _("<unknown>");
6202 sprintf (p
, _("UNKNOWN (%*.*lx)"), field_size
, field_size
,
6203 (unsigned long) unknown_flags
);
6204 p
+= 10 + field_size
;
6212 static unsigned int ATTRIBUTE_WARN_UNUSED_RESULT
6213 get_compression_header (Elf_Internal_Chdr
*chdr
, unsigned char *buf
, bfd_size_type size
)
6217 Elf32_External_Chdr
*echdr
= (Elf32_External_Chdr
*) buf
;
6219 if (size
< sizeof (* echdr
))
6221 error (_("Compressed section is too small even for a compression header\n"));
6225 chdr
->ch_type
= BYTE_GET (echdr
->ch_type
);
6226 chdr
->ch_size
= BYTE_GET (echdr
->ch_size
);
6227 chdr
->ch_addralign
= BYTE_GET (echdr
->ch_addralign
);
6228 return sizeof (*echdr
);
6232 Elf64_External_Chdr
*echdr
= (Elf64_External_Chdr
*) buf
;
6234 if (size
< sizeof (* echdr
))
6236 error (_("Compressed section is too small even for a compression header\n"));
6240 chdr
->ch_type
= BYTE_GET (echdr
->ch_type
);
6241 chdr
->ch_size
= BYTE_GET (echdr
->ch_size
);
6242 chdr
->ch_addralign
= BYTE_GET (echdr
->ch_addralign
);
6243 return sizeof (*echdr
);
6248 process_section_headers (Filedata
* filedata
)
6250 Elf_Internal_Shdr
* section
;
6253 free (filedata
->section_headers
);
6254 filedata
->section_headers
= NULL
;
6255 free (filedata
->dynamic_symbols
);
6256 filedata
->dynamic_symbols
= NULL
;
6257 filedata
->num_dynamic_syms
= 0;
6258 free (filedata
->dynamic_strings
);
6259 filedata
->dynamic_strings
= NULL
;
6260 filedata
->dynamic_strings_length
= 0;
6261 free (filedata
->dynamic_syminfo
);
6262 filedata
->dynamic_syminfo
= NULL
;
6263 while (filedata
->symtab_shndx_list
!= NULL
)
6265 elf_section_list
*next
= filedata
->symtab_shndx_list
->next
;
6266 free (filedata
->symtab_shndx_list
);
6267 filedata
->symtab_shndx_list
= next
;
6270 if (filedata
->file_header
.e_shnum
== 0)
6272 /* PR binutils/12467. */
6273 if (filedata
->file_header
.e_shoff
!= 0)
6275 warn (_("possibly corrupt ELF file header - it has a non-zero"
6276 " section header offset, but no section headers\n"));
6279 else if (do_sections
)
6280 printf (_("\nThere are no sections in this file.\n"));
6285 if (do_sections
&& !do_header
)
6286 printf (ngettext ("There is %d section header, "
6287 "starting at offset 0x%lx:\n",
6288 "There are %d section headers, "
6289 "starting at offset 0x%lx:\n",
6290 filedata
->file_header
.e_shnum
),
6291 filedata
->file_header
.e_shnum
,
6292 (unsigned long) filedata
->file_header
.e_shoff
);
6296 if (! get_32bit_section_headers (filedata
, FALSE
))
6301 if (! get_64bit_section_headers (filedata
, FALSE
))
6305 /* Read in the string table, so that we have names to display. */
6306 if (filedata
->file_header
.e_shstrndx
!= SHN_UNDEF
6307 && filedata
->file_header
.e_shstrndx
< filedata
->file_header
.e_shnum
)
6309 section
= filedata
->section_headers
+ filedata
->file_header
.e_shstrndx
;
6311 if (section
->sh_size
!= 0)
6313 filedata
->string_table
= (char *) get_data (NULL
, filedata
, section
->sh_offset
,
6314 1, section
->sh_size
,
6317 filedata
->string_table_length
= filedata
->string_table
!= NULL
? section
->sh_size
: 0;
6321 /* Scan the sections for the dynamic symbol table
6322 and dynamic string table and debug sections. */
6323 eh_addr_size
= is_32bit_elf
? 4 : 8;
6324 switch (filedata
->file_header
.e_machine
)
6327 case EM_MIPS_RS3_LE
:
6328 /* The 64-bit MIPS EABI uses a combination of 32-bit ELF and 64-bit
6329 FDE addresses. However, the ABI also has a semi-official ILP32
6330 variant for which the normal FDE address size rules apply.
6332 GCC 4.0 marks EABI64 objects with a dummy .gcc_compiled_longXX
6333 section, where XX is the size of longs in bits. Unfortunately,
6334 earlier compilers provided no way of distinguishing ILP32 objects
6335 from LP64 objects, so if there's any doubt, we should assume that
6336 the official LP64 form is being used. */
6337 if ((filedata
->file_header
.e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
6338 && find_section (filedata
, ".gcc_compiled_long32") == NULL
)
6344 switch (filedata
->file_header
.e_flags
& EF_H8_MACH
)
6346 case E_H8_MACH_H8300
:
6347 case E_H8_MACH_H8300HN
:
6348 case E_H8_MACH_H8300SN
:
6349 case E_H8_MACH_H8300SXN
:
6352 case E_H8_MACH_H8300H
:
6353 case E_H8_MACH_H8300S
:
6354 case E_H8_MACH_H8300SX
:
6362 switch (filedata
->file_header
.e_flags
& EF_M32C_CPU_MASK
)
6364 case EF_M32C_CPU_M16C
:
6371 #define CHECK_ENTSIZE_VALUES(section, i, size32, size64) \
6374 bfd_size_type expected_entsize = is_32bit_elf ? size32 : size64; \
6375 if (section->sh_entsize != expected_entsize) \
6378 sprintf_vma (buf, section->sh_entsize); \
6379 /* Note: coded this way so that there is a single string for \
6381 error (_("Section %d has invalid sh_entsize of %s\n"), i, buf); \
6382 error (_("(Using the expected size of %u for the rest of this dump)\n"), \
6383 (unsigned) expected_entsize); \
6384 section->sh_entsize = expected_entsize; \
6389 #define CHECK_ENTSIZE(section, i, type) \
6390 CHECK_ENTSIZE_VALUES (section, i, sizeof (Elf32_External_##type), \
6391 sizeof (Elf64_External_##type))
6393 for (i
= 0, section
= filedata
->section_headers
;
6394 i
< filedata
->file_header
.e_shnum
;
6397 char * name
= SECTION_NAME (section
);
6399 /* Run some sanity checks on the headers and
6400 possibly fill in some file data as well. */
6401 switch (section
->sh_type
)
6404 if (filedata
->dynamic_symbols
!= NULL
)
6406 error (_("File contains multiple dynamic symbol tables\n"));
6410 CHECK_ENTSIZE (section
, i
, Sym
);
6411 filedata
->dynamic_symbols
6412 = GET_ELF_SYMBOLS (filedata
, section
, &filedata
->num_dynamic_syms
);
6413 filedata
->dynamic_symtab_section
= section
;
6417 if (streq (name
, ".dynstr"))
6419 if (filedata
->dynamic_strings
!= NULL
)
6421 error (_("File contains multiple dynamic string tables\n"));
6425 filedata
->dynamic_strings
6426 = (char *) get_data (NULL
, filedata
, section
->sh_offset
,
6427 1, section
->sh_size
, _("dynamic strings"));
6428 filedata
->dynamic_strings_length
6429 = filedata
->dynamic_strings
== NULL
? 0 : section
->sh_size
;
6430 filedata
->dynamic_strtab_section
= section
;
6434 case SHT_SYMTAB_SHNDX
:
6436 elf_section_list
* entry
= xmalloc (sizeof * entry
);
6438 entry
->hdr
= section
;
6439 entry
->next
= filedata
->symtab_shndx_list
;
6440 filedata
->symtab_shndx_list
= entry
;
6445 CHECK_ENTSIZE (section
, i
, Sym
);
6449 CHECK_ENTSIZE_VALUES (section
, i
, GRP_ENTRY_SIZE
, GRP_ENTRY_SIZE
);
6453 CHECK_ENTSIZE (section
, i
, Rel
);
6454 if (do_checks
&& section
->sh_size
== 0)
6455 warn (_("Section '%s': zero-sized relocation section\n"), name
);
6459 CHECK_ENTSIZE (section
, i
, Rela
);
6460 if (do_checks
&& section
->sh_size
== 0)
6461 warn (_("Section '%s': zero-sized relocation section\n"), name
);
6466 /* Having a zero sized section is not illegal according to the
6467 ELF standard, but it might be an indication that something
6468 is wrong. So issue a warning if we are running in lint mode. */
6469 if (do_checks
&& section
->sh_size
== 0)
6470 warn (_("Section '%s': has a size of zero - is this intended ?\n"), name
);
6477 if ((do_debugging
|| do_debug_info
|| do_debug_abbrevs
6478 || do_debug_lines
|| do_debug_pubnames
|| do_debug_pubtypes
6479 || do_debug_aranges
|| do_debug_frames
|| do_debug_macinfo
6480 || do_debug_str
|| do_debug_str_offsets
|| do_debug_loc
|| do_debug_ranges
6481 || do_debug_addr
|| do_debug_cu_index
|| do_debug_links
)
6482 && (const_strneq (name
, ".debug_")
6483 || const_strneq (name
, ".zdebug_")))
6486 name
+= sizeof (".zdebug_") - 1;
6488 name
+= sizeof (".debug_") - 1;
6491 || (do_debug_info
&& const_strneq (name
, "info"))
6492 || (do_debug_info
&& const_strneq (name
, "types"))
6493 || (do_debug_abbrevs
&& const_strneq (name
, "abbrev"))
6494 || (do_debug_lines
&& strcmp (name
, "line") == 0)
6495 || (do_debug_lines
&& const_strneq (name
, "line."))
6496 || (do_debug_pubnames
&& const_strneq (name
, "pubnames"))
6497 || (do_debug_pubtypes
&& const_strneq (name
, "pubtypes"))
6498 || (do_debug_pubnames
&& const_strneq (name
, "gnu_pubnames"))
6499 || (do_debug_pubtypes
&& const_strneq (name
, "gnu_pubtypes"))
6500 || (do_debug_aranges
&& const_strneq (name
, "aranges"))
6501 || (do_debug_ranges
&& const_strneq (name
, "ranges"))
6502 || (do_debug_ranges
&& const_strneq (name
, "rnglists"))
6503 || (do_debug_frames
&& const_strneq (name
, "frame"))
6504 || (do_debug_macinfo
&& const_strneq (name
, "macinfo"))
6505 || (do_debug_macinfo
&& const_strneq (name
, "macro"))
6506 || (do_debug_str
&& const_strneq (name
, "str"))
6507 || (do_debug_str_offsets
&& const_strneq (name
, "str_offsets"))
6508 || (do_debug_loc
&& const_strneq (name
, "loc"))
6509 || (do_debug_loc
&& const_strneq (name
, "loclists"))
6510 || (do_debug_addr
&& const_strneq (name
, "addr"))
6511 || (do_debug_cu_index
&& const_strneq (name
, "cu_index"))
6512 || (do_debug_cu_index
&& const_strneq (name
, "tu_index"))
6514 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
6516 /* Linkonce section to be combined with .debug_info at link time. */
6517 else if ((do_debugging
|| do_debug_info
)
6518 && const_strneq (name
, ".gnu.linkonce.wi."))
6519 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
6520 else if (do_debug_frames
&& streq (name
, ".eh_frame"))
6521 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
6522 else if (do_gdb_index
&& (streq (name
, ".gdb_index")
6523 || streq (name
, ".debug_names")))
6524 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
6525 /* Trace sections for Itanium VMS. */
6526 else if ((do_debugging
|| do_trace_info
|| do_trace_abbrevs
6527 || do_trace_aranges
)
6528 && const_strneq (name
, ".trace_"))
6530 name
+= sizeof (".trace_") - 1;
6533 || (do_trace_info
&& streq (name
, "info"))
6534 || (do_trace_abbrevs
&& streq (name
, "abbrev"))
6535 || (do_trace_aranges
&& streq (name
, "aranges"))
6537 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
6539 else if ((do_debugging
|| do_debug_links
)
6540 && (const_strneq (name
, ".gnu_debuglink")
6541 || const_strneq (name
, ".gnu_debugaltlink")))
6542 request_dump_bynumber (&filedata
->dump
, i
, DEBUG_DUMP
);
6548 if (filedata
->file_header
.e_shnum
> 1)
6549 printf (_("\nSection Headers:\n"));
6551 printf (_("\nSection Header:\n"));
6555 if (do_section_details
)
6557 printf (_(" [Nr] Name\n"));
6558 printf (_(" Type Addr Off Size ES Lk Inf Al\n"));
6562 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
6566 if (do_section_details
)
6568 printf (_(" [Nr] Name\n"));
6569 printf (_(" Type Address Off Size ES Lk Inf Al\n"));
6573 (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n"));
6577 if (do_section_details
)
6579 printf (_(" [Nr] Name\n"));
6580 printf (_(" Type Address Offset Link\n"));
6581 printf (_(" Size EntSize Info Align\n"));
6585 printf (_(" [Nr] Name Type Address Offset\n"));
6586 printf (_(" Size EntSize Flags Link Info Align\n"));
6590 if (do_section_details
)
6591 printf (_(" Flags\n"));
6593 for (i
= 0, section
= filedata
->section_headers
;
6594 i
< filedata
->file_header
.e_shnum
;
6597 /* Run some sanity checks on the section header. */
6599 /* Check the sh_link field. */
6600 switch (section
->sh_type
)
6604 if (section
->sh_link
== 0
6605 && (filedata
->file_header
.e_type
== ET_EXEC
6606 || filedata
->file_header
.e_type
== ET_DYN
))
6607 /* A dynamic relocation section where all entries use a
6608 zero symbol index need not specify a symtab section. */
6611 case SHT_SYMTAB_SHNDX
:
6615 case SHT_GNU_versym
:
6616 if (section
->sh_link
== 0
6617 || section
->sh_link
>= filedata
->file_header
.e_shnum
6618 || (filedata
->section_headers
[section
->sh_link
].sh_type
!= SHT_SYMTAB
6619 && filedata
->section_headers
[section
->sh_link
].sh_type
!= SHT_DYNSYM
))
6620 warn (_("[%2u]: Link field (%u) should index a symtab section.\n"),
6621 i
, section
->sh_link
);
6627 case SHT_GNU_verneed
:
6628 case SHT_GNU_verdef
:
6629 case SHT_GNU_LIBLIST
:
6630 if (section
->sh_link
== 0
6631 || section
->sh_link
>= filedata
->file_header
.e_shnum
6632 || filedata
->section_headers
[section
->sh_link
].sh_type
!= SHT_STRTAB
)
6633 warn (_("[%2u]: Link field (%u) should index a string section.\n"),
6634 i
, section
->sh_link
);
6637 case SHT_INIT_ARRAY
:
6638 case SHT_FINI_ARRAY
:
6639 case SHT_PREINIT_ARRAY
:
6640 if (section
->sh_type
< SHT_LOOS
&& section
->sh_link
!= 0)
6641 warn (_("[%2u]: Unexpected value (%u) in link field.\n"),
6642 i
, section
->sh_link
);
6646 /* FIXME: Add support for target specific section types. */
6647 #if 0 /* Currently we do not check other section types as there are too
6648 many special cases. Stab sections for example have a type
6649 of SHT_PROGBITS but an sh_link field that links to the .stabstr
6651 if (section
->sh_type
< SHT_LOOS
&& section
->sh_link
!= 0)
6652 warn (_("[%2u]: Unexpected value (%u) in link field.\n"),
6653 i
, section
->sh_link
);
6658 /* Check the sh_info field. */
6659 switch (section
->sh_type
)
6663 if (section
->sh_info
== 0
6664 && (filedata
->file_header
.e_type
== ET_EXEC
6665 || filedata
->file_header
.e_type
== ET_DYN
))
6666 /* Dynamic relocations apply to segments, so they do not
6667 need to specify the section they relocate. */
6669 if (section
->sh_info
== 0
6670 || section
->sh_info
>= filedata
->file_header
.e_shnum
6671 || (filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_PROGBITS
6672 && filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_NOBITS
6673 && filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_NOTE
6674 && filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_INIT_ARRAY
6675 && filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_FINI_ARRAY
6676 && filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_PREINIT_ARRAY
6677 /* FIXME: Are other section types valid ? */
6678 && filedata
->section_headers
[section
->sh_info
].sh_type
< SHT_LOOS
))
6679 warn (_("[%2u]: Info field (%u) should index a relocatable section.\n"),
6680 i
, section
->sh_info
);
6685 case SHT_SYMTAB_SHNDX
:
6686 case SHT_INIT_ARRAY
:
6687 case SHT_FINI_ARRAY
:
6688 case SHT_PREINIT_ARRAY
:
6689 if (section
->sh_info
!= 0)
6690 warn (_("[%2u]: Unexpected value (%u) in info field.\n"),
6691 i
, section
->sh_info
);
6697 /* A symbol index - we assume that it is valid. */
6701 /* FIXME: Add support for target specific section types. */
6702 if (section
->sh_type
== SHT_NOBITS
)
6703 /* NOBITS section headers with non-zero sh_info fields can be
6704 created when a binary is stripped of everything but its debug
6705 information. The stripped sections have their headers
6706 preserved but their types set to SHT_NOBITS. So do not check
6707 this type of section. */
6709 else if (section
->sh_flags
& SHF_INFO_LINK
)
6711 if (section
->sh_info
< 1 || section
->sh_info
>= filedata
->file_header
.e_shnum
)
6712 warn (_("[%2u]: Expected link to another section in info field"), i
);
6714 else if (section
->sh_type
< SHT_LOOS
6715 && (section
->sh_flags
& SHF_GNU_MBIND
) == 0
6716 && section
->sh_info
!= 0)
6717 warn (_("[%2u]: Unexpected value (%u) in info field.\n"),
6718 i
, section
->sh_info
);
6722 /* Check the sh_size field. */
6723 if (section
->sh_size
> filedata
->file_size
6724 && section
->sh_type
!= SHT_NOBITS
6725 && section
->sh_type
!= SHT_NULL
6726 && section
->sh_type
< SHT_LOOS
)
6727 warn (_("Size of section %u is larger than the entire file!\n"), i
);
6729 printf (" [%2u] ", i
);
6730 if (do_section_details
)
6731 printf ("%s\n ", printable_section_name (filedata
, section
));
6733 print_symbol (-17, SECTION_NAME (section
));
6735 printf (do_wide
? " %-15s " : " %-15.15s ",
6736 get_section_type_name (filedata
, section
->sh_type
));
6740 const char * link_too_big
= NULL
;
6742 print_vma (section
->sh_addr
, LONG_HEX
);
6744 printf ( " %6.6lx %6.6lx %2.2lx",
6745 (unsigned long) section
->sh_offset
,
6746 (unsigned long) section
->sh_size
,
6747 (unsigned long) section
->sh_entsize
);
6749 if (do_section_details
)
6750 fputs (" ", stdout
);
6752 printf (" %3s ", get_elf_section_flags (filedata
, section
->sh_flags
));
6754 if (section
->sh_link
>= filedata
->file_header
.e_shnum
)
6757 /* The sh_link value is out of range. Normally this indicates
6758 an error but it can have special values in Solaris binaries. */
6759 switch (filedata
->file_header
.e_machine
)
6766 case EM_OLD_SPARCV9
:
6767 case EM_SPARC32PLUS
:
6770 if (section
->sh_link
== (SHN_BEFORE
& 0xffff))
6771 link_too_big
= "BEFORE";
6772 else if (section
->sh_link
== (SHN_AFTER
& 0xffff))
6773 link_too_big
= "AFTER";
6780 if (do_section_details
)
6782 if (link_too_big
!= NULL
&& * link_too_big
)
6783 printf ("<%s> ", link_too_big
);
6785 printf ("%2u ", section
->sh_link
);
6786 printf ("%3u %2lu\n", section
->sh_info
,
6787 (unsigned long) section
->sh_addralign
);
6790 printf ("%2u %3u %2lu\n",
6793 (unsigned long) section
->sh_addralign
);
6795 if (link_too_big
&& ! * link_too_big
)
6796 warn (_("section %u: sh_link value of %u is larger than the number of sections\n"),
6797 i
, section
->sh_link
);
6801 print_vma (section
->sh_addr
, LONG_HEX
);
6803 if ((long) section
->sh_offset
== section
->sh_offset
)
6804 printf (" %6.6lx", (unsigned long) section
->sh_offset
);
6808 print_vma (section
->sh_offset
, LONG_HEX
);
6811 if ((unsigned long) section
->sh_size
== section
->sh_size
)
6812 printf (" %6.6lx", (unsigned long) section
->sh_size
);
6816 print_vma (section
->sh_size
, LONG_HEX
);
6819 if ((unsigned long) section
->sh_entsize
== section
->sh_entsize
)
6820 printf (" %2.2lx", (unsigned long) section
->sh_entsize
);
6824 print_vma (section
->sh_entsize
, LONG_HEX
);
6827 if (do_section_details
)
6828 fputs (" ", stdout
);
6830 printf (" %3s ", get_elf_section_flags (filedata
, section
->sh_flags
));
6832 printf ("%2u %3u ", section
->sh_link
, section
->sh_info
);
6834 if ((unsigned long) section
->sh_addralign
== section
->sh_addralign
)
6835 printf ("%2lu\n", (unsigned long) section
->sh_addralign
);
6838 print_vma (section
->sh_addralign
, DEC
);
6842 else if (do_section_details
)
6845 print_vma (section
->sh_addr
, LONG_HEX
);
6846 if ((long) section
->sh_offset
== section
->sh_offset
)
6847 printf (" %16.16lx", (unsigned long) section
->sh_offset
);
6851 print_vma (section
->sh_offset
, LONG_HEX
);
6853 printf (" %u\n ", section
->sh_link
);
6854 print_vma (section
->sh_size
, LONG_HEX
);
6856 print_vma (section
->sh_entsize
, LONG_HEX
);
6858 printf (" %-16u %lu\n",
6860 (unsigned long) section
->sh_addralign
);
6865 print_vma (section
->sh_addr
, LONG_HEX
);
6866 if ((long) section
->sh_offset
== section
->sh_offset
)
6867 printf (" %8.8lx", (unsigned long) section
->sh_offset
);
6871 print_vma (section
->sh_offset
, LONG_HEX
);
6874 print_vma (section
->sh_size
, LONG_HEX
);
6876 print_vma (section
->sh_entsize
, LONG_HEX
);
6878 printf (" %3s ", get_elf_section_flags (filedata
, section
->sh_flags
));
6880 printf (" %2u %3u %lu\n",
6883 (unsigned long) section
->sh_addralign
);
6886 if (do_section_details
)
6888 printf (" %s\n", get_elf_section_flags (filedata
, section
->sh_flags
));
6889 if ((section
->sh_flags
& SHF_COMPRESSED
) != 0)
6891 /* Minimum section size is 12 bytes for 32-bit compression
6892 header + 12 bytes for compressed data header. */
6893 unsigned char buf
[24];
6895 assert (sizeof (buf
) >= sizeof (Elf64_External_Chdr
));
6896 if (get_data (&buf
, filedata
, section
->sh_offset
, 1,
6897 sizeof (buf
), _("compression header")))
6899 Elf_Internal_Chdr chdr
;
6901 if (get_compression_header (&chdr
, buf
, sizeof (buf
)) == 0)
6902 printf (_(" [<corrupt>]\n"));
6905 if (chdr
.ch_type
== ELFCOMPRESS_ZLIB
)
6908 printf (_(" [<unknown>: 0x%x], "),
6910 print_vma (chdr
.ch_size
, LONG_HEX
);
6911 printf (", %lu\n", (unsigned long) chdr
.ch_addralign
);
6918 if (!do_section_details
)
6920 /* The ordering of the letters shown here matches the ordering of the
6921 corresponding SHF_xxx values, and hence the order in which these
6922 letters will be displayed to the user. */
6923 printf (_("Key to Flags:\n\
6924 W (write), A (alloc), X (execute), M (merge), S (strings), I (info),\n\
6925 L (link order), O (extra OS processing required), G (group), T (TLS),\n\
6926 C (compressed), x (unknown), o (OS specific), E (exclude),\n "));
6927 if (filedata
->file_header
.e_machine
== EM_X86_64
6928 || filedata
->file_header
.e_machine
== EM_L1OM
6929 || filedata
->file_header
.e_machine
== EM_K1OM
)
6930 printf (_("l (large), "));
6931 else if (filedata
->file_header
.e_machine
== EM_ARM
)
6932 printf (_("y (purecode), "));
6933 else if (filedata
->file_header
.e_machine
== EM_PPC
)
6934 printf (_("v (VLE), "));
6935 printf ("p (processor specific)\n");
6942 get_symtab (Filedata
*filedata
, Elf_Internal_Shdr
*symsec
,
6943 Elf_Internal_Sym
**symtab
, unsigned long *nsyms
,
6944 char **strtab
, unsigned long *strtablen
)
6948 *symtab
= GET_ELF_SYMBOLS (filedata
, symsec
, nsyms
);
6950 if (*symtab
== NULL
)
6953 if (symsec
->sh_link
!= 0)
6955 Elf_Internal_Shdr
*strsec
;
6957 if (symsec
->sh_link
>= filedata
->file_header
.e_shnum
)
6959 error (_("Bad sh_link in symbol table section\n"));
6966 strsec
= filedata
->section_headers
+ symsec
->sh_link
;
6968 *strtab
= (char *) get_data (NULL
, filedata
, strsec
->sh_offset
,
6969 1, strsec
->sh_size
, _("string table"));
6970 if (*strtab
== NULL
)
6977 *strtablen
= strsec
->sh_size
;
6983 get_group_flags (unsigned int flags
)
6985 static char buff
[128];
6989 else if (flags
== GRP_COMDAT
)
6992 snprintf (buff
, sizeof buff
, "[0x%x: %s%s%s]",
6994 flags
& GRP_MASKOS
? _("<OS specific>") : "",
6995 flags
& GRP_MASKPROC
? _("<PROC specific>") : "",
6996 (flags
& ~(GRP_COMDAT
| GRP_MASKOS
| GRP_MASKPROC
)
6997 ? _("<unknown>") : ""));
7003 process_section_groups (Filedata
* filedata
)
7005 Elf_Internal_Shdr
* section
;
7007 struct group
* group
;
7008 Elf_Internal_Shdr
* symtab_sec
;
7009 Elf_Internal_Shdr
* strtab_sec
;
7010 Elf_Internal_Sym
* symtab
;
7011 unsigned long num_syms
;
7015 /* Don't process section groups unless needed. */
7016 if (!do_unwind
&& !do_section_groups
)
7019 if (filedata
->file_header
.e_shnum
== 0)
7021 if (do_section_groups
)
7022 printf (_("\nThere are no sections to group in this file.\n"));
7027 if (filedata
->section_headers
== NULL
)
7029 error (_("Section headers are not available!\n"));
7030 /* PR 13622: This can happen with a corrupt ELF header. */
7034 filedata
->section_headers_groups
7035 = (struct group
**) calloc (filedata
->file_header
.e_shnum
,
7036 sizeof (struct group
*));
7038 if (filedata
->section_headers_groups
== NULL
)
7040 error (_("Out of memory reading %u section group headers\n"),
7041 filedata
->file_header
.e_shnum
);
7045 /* Scan the sections for the group section. */
7046 filedata
->group_count
= 0;
7047 for (i
= 0, section
= filedata
->section_headers
;
7048 i
< filedata
->file_header
.e_shnum
;
7050 if (section
->sh_type
== SHT_GROUP
)
7051 filedata
->group_count
++;
7053 if (filedata
->group_count
== 0)
7055 if (do_section_groups
)
7056 printf (_("\nThere are no section groups in this file.\n"));
7061 filedata
->section_groups
= (struct group
*) calloc (filedata
->group_count
,
7062 sizeof (struct group
));
7064 if (filedata
->section_groups
== NULL
)
7066 error (_("Out of memory reading %lu groups\n"),
7067 (unsigned long) filedata
->group_count
);
7077 for (i
= 0, section
= filedata
->section_headers
, group
= filedata
->section_groups
;
7078 i
< filedata
->file_header
.e_shnum
;
7081 if (section
->sh_type
== SHT_GROUP
)
7083 const char * name
= printable_section_name (filedata
, section
);
7084 const char * group_name
;
7085 unsigned char * start
;
7086 unsigned char * indices
;
7087 unsigned int entry
, j
, size
;
7088 Elf_Internal_Shdr
* sec
;
7089 Elf_Internal_Sym
* sym
;
7091 /* Get the symbol table. */
7092 if (section
->sh_link
>= filedata
->file_header
.e_shnum
7093 || ((sec
= filedata
->section_headers
+ section
->sh_link
)->sh_type
7096 error (_("Bad sh_link in group section `%s'\n"), name
);
7100 if (symtab_sec
!= sec
)
7104 symtab
= GET_ELF_SYMBOLS (filedata
, symtab_sec
, & num_syms
);
7109 error (_("Corrupt header in group section `%s'\n"), name
);
7113 if (section
->sh_info
>= num_syms
)
7115 error (_("Bad sh_info in group section `%s'\n"), name
);
7119 sym
= symtab
+ section
->sh_info
;
7121 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
7123 if (sym
->st_shndx
== 0
7124 || sym
->st_shndx
>= filedata
->file_header
.e_shnum
)
7126 error (_("Bad sh_info in group section `%s'\n"), name
);
7130 group_name
= SECTION_NAME (filedata
->section_headers
+ sym
->st_shndx
);
7138 /* Get the string table. */
7139 if (symtab_sec
->sh_link
>= filedata
->file_header
.e_shnum
)
7147 != (sec
= filedata
->section_headers
+ symtab_sec
->sh_link
))
7152 strtab
= (char *) get_data (NULL
, filedata
, strtab_sec
->sh_offset
,
7153 1, strtab_sec
->sh_size
,
7155 strtab_size
= strtab
!= NULL
? strtab_sec
->sh_size
: 0;
7157 group_name
= sym
->st_name
< strtab_size
7158 ? strtab
+ sym
->st_name
: _("<corrupt>");
7161 /* PR 17531: file: loop. */
7162 if (section
->sh_entsize
> section
->sh_size
)
7164 error (_("Section %s has sh_entsize (0x%lx) which is larger than its size (0x%lx)\n"),
7165 printable_section_name (filedata
, section
),
7166 (unsigned long) section
->sh_entsize
,
7167 (unsigned long) section
->sh_size
);
7171 start
= (unsigned char *) get_data (NULL
, filedata
, section
->sh_offset
,
7172 1, section
->sh_size
,
7178 size
= (section
->sh_size
/ section
->sh_entsize
) - 1;
7179 entry
= byte_get (indices
, 4);
7182 if (do_section_groups
)
7184 printf (_("\n%sgroup section [%5u] `%s' [%s] contains %u sections:\n"),
7185 get_group_flags (entry
), i
, name
, group_name
, size
);
7187 printf (_(" [Index] Name\n"));
7190 group
->group_index
= i
;
7192 for (j
= 0; j
< size
; j
++)
7194 struct group_list
* g
;
7196 entry
= byte_get (indices
, 4);
7199 if (entry
>= filedata
->file_header
.e_shnum
)
7201 static unsigned num_group_errors
= 0;
7203 if (num_group_errors
++ < 10)
7205 error (_("section [%5u] in group section [%5u] > maximum section [%5u]\n"),
7206 entry
, i
, filedata
->file_header
.e_shnum
- 1);
7207 if (num_group_errors
== 10)
7208 warn (_("Further error messages about overlarge group section indices suppressed\n"));
7213 if (filedata
->section_headers_groups
[entry
] != NULL
)
7217 static unsigned num_errs
= 0;
7219 if (num_errs
++ < 10)
7221 error (_("section [%5u] in group section [%5u] already in group section [%5u]\n"),
7223 filedata
->section_headers_groups
[entry
]->group_index
);
7225 warn (_("Further error messages about already contained group sections suppressed\n"));
7231 /* Intel C/C++ compiler may put section 0 in a
7232 section group. We just warn it the first time
7233 and ignore it afterwards. */
7234 static bfd_boolean warned
= FALSE
;
7237 error (_("section 0 in group section [%5u]\n"),
7238 filedata
->section_headers_groups
[entry
]->group_index
);
7244 filedata
->section_headers_groups
[entry
] = group
;
7246 if (do_section_groups
)
7248 sec
= filedata
->section_headers
+ entry
;
7249 printf (" [%5u] %s\n", entry
, printable_section_name (filedata
, sec
));
7252 g
= (struct group_list
*) xmalloc (sizeof (struct group_list
));
7253 g
->section_index
= entry
;
7254 g
->next
= group
->root
;
7269 /* Data used to display dynamic fixups. */
7271 struct ia64_vms_dynfixup
7273 bfd_vma needed_ident
; /* Library ident number. */
7274 bfd_vma needed
; /* Index in the dstrtab of the library name. */
7275 bfd_vma fixup_needed
; /* Index of the library. */
7276 bfd_vma fixup_rela_cnt
; /* Number of fixups. */
7277 bfd_vma fixup_rela_off
; /* Fixups offset in the dynamic segment. */
7280 /* Data used to display dynamic relocations. */
7282 struct ia64_vms_dynimgrela
7284 bfd_vma img_rela_cnt
; /* Number of relocations. */
7285 bfd_vma img_rela_off
; /* Reloc offset in the dynamic segment. */
7288 /* Display IA-64 OpenVMS dynamic fixups (used to dynamically link a shared
7292 dump_ia64_vms_dynamic_fixups (Filedata
* filedata
,
7293 struct ia64_vms_dynfixup
* fixup
,
7294 const char * strtab
,
7295 unsigned int strtab_sz
)
7297 Elf64_External_VMS_IMAGE_FIXUP
* imfs
;
7299 const char * lib_name
;
7301 imfs
= get_data (NULL
, filedata
,
7302 filedata
->dynamic_addr
+ fixup
->fixup_rela_off
,
7303 sizeof (*imfs
), fixup
->fixup_rela_cnt
,
7304 _("dynamic section image fixups"));
7308 if (fixup
->needed
< strtab_sz
)
7309 lib_name
= strtab
+ fixup
->needed
;
7312 warn (_("corrupt library name index of 0x%lx found in dynamic entry"),
7313 (unsigned long) fixup
->needed
);
7317 printf (_("\nImage fixups for needed library #%d: %s - ident: %lx\n"),
7318 (int) fixup
->fixup_needed
, lib_name
, (long) fixup
->needed_ident
);
7320 (_("Seg Offset Type SymVec DataType\n"));
7322 for (i
= 0; i
< (long) fixup
->fixup_rela_cnt
; i
++)
7327 printf ("%3u ", (unsigned) BYTE_GET (imfs
[i
].fixup_seg
));
7328 printf_vma ((bfd_vma
) BYTE_GET (imfs
[i
].fixup_offset
));
7329 type
= BYTE_GET (imfs
[i
].type
);
7330 rtype
= elf_ia64_reloc_type (type
);
7332 printf (" 0x%08x ", type
);
7334 printf (" %-32s ", rtype
);
7335 printf ("%6u ", (unsigned) BYTE_GET (imfs
[i
].symvec_index
));
7336 printf ("0x%08x\n", (unsigned) BYTE_GET (imfs
[i
].data_type
));
7343 /* Display IA-64 OpenVMS dynamic relocations (used to relocate an image). */
7346 dump_ia64_vms_dynamic_relocs (Filedata
* filedata
, struct ia64_vms_dynimgrela
*imgrela
)
7348 Elf64_External_VMS_IMAGE_RELA
*imrs
;
7351 imrs
= get_data (NULL
, filedata
,
7352 filedata
->dynamic_addr
+ imgrela
->img_rela_off
,
7353 sizeof (*imrs
), imgrela
->img_rela_cnt
,
7354 _("dynamic section image relocations"));
7358 printf (_("\nImage relocs\n"));
7360 (_("Seg Offset Type Addend Seg Sym Off\n"));
7362 for (i
= 0; i
< (long) imgrela
->img_rela_cnt
; i
++)
7367 printf ("%3u ", (unsigned) BYTE_GET (imrs
[i
].rela_seg
));
7368 printf ("%08" BFD_VMA_FMT
"x ",
7369 (bfd_vma
) BYTE_GET (imrs
[i
].rela_offset
));
7370 type
= BYTE_GET (imrs
[i
].type
);
7371 rtype
= elf_ia64_reloc_type (type
);
7373 printf ("0x%08x ", type
);
7375 printf ("%-31s ", rtype
);
7376 print_vma (BYTE_GET (imrs
[i
].addend
), FULL_HEX
);
7377 printf ("%3u ", (unsigned) BYTE_GET (imrs
[i
].sym_seg
));
7378 printf ("%08" BFD_VMA_FMT
"x\n",
7379 (bfd_vma
) BYTE_GET (imrs
[i
].sym_offset
));
7386 /* Display IA-64 OpenVMS dynamic relocations and fixups. */
7389 process_ia64_vms_dynamic_relocs (Filedata
* filedata
)
7391 struct ia64_vms_dynfixup fixup
;
7392 struct ia64_vms_dynimgrela imgrela
;
7393 Elf_Internal_Dyn
*entry
;
7394 bfd_vma strtab_off
= 0;
7395 bfd_vma strtab_sz
= 0;
7396 char *strtab
= NULL
;
7397 bfd_boolean res
= TRUE
;
7399 memset (&fixup
, 0, sizeof (fixup
));
7400 memset (&imgrela
, 0, sizeof (imgrela
));
7402 /* Note: the order of the entries is specified by the OpenVMS specs. */
7403 for (entry
= filedata
->dynamic_section
;
7404 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
7407 switch (entry
->d_tag
)
7409 case DT_IA_64_VMS_STRTAB_OFFSET
:
7410 strtab_off
= entry
->d_un
.d_val
;
7413 strtab_sz
= entry
->d_un
.d_val
;
7415 strtab
= get_data (NULL
, filedata
,
7416 filedata
->dynamic_addr
+ strtab_off
,
7417 1, strtab_sz
, _("dynamic string section"));
7422 case DT_IA_64_VMS_NEEDED_IDENT
:
7423 fixup
.needed_ident
= entry
->d_un
.d_val
;
7426 fixup
.needed
= entry
->d_un
.d_val
;
7428 case DT_IA_64_VMS_FIXUP_NEEDED
:
7429 fixup
.fixup_needed
= entry
->d_un
.d_val
;
7431 case DT_IA_64_VMS_FIXUP_RELA_CNT
:
7432 fixup
.fixup_rela_cnt
= entry
->d_un
.d_val
;
7434 case DT_IA_64_VMS_FIXUP_RELA_OFF
:
7435 fixup
.fixup_rela_off
= entry
->d_un
.d_val
;
7436 if (! dump_ia64_vms_dynamic_fixups (filedata
, &fixup
, strtab
, strtab_sz
))
7439 case DT_IA_64_VMS_IMG_RELA_CNT
:
7440 imgrela
.img_rela_cnt
= entry
->d_un
.d_val
;
7442 case DT_IA_64_VMS_IMG_RELA_OFF
:
7443 imgrela
.img_rela_off
= entry
->d_un
.d_val
;
7444 if (! dump_ia64_vms_dynamic_relocs (filedata
, &imgrela
))
7465 dynamic_relocations
[] =
7467 { "REL", DT_REL
, DT_RELSZ
, FALSE
},
7468 { "RELA", DT_RELA
, DT_RELASZ
, TRUE
},
7469 { "PLT", DT_JMPREL
, DT_PLTRELSZ
, UNKNOWN
}
7472 /* Process the reloc section. */
7475 process_relocs (Filedata
* filedata
)
7477 unsigned long rel_size
;
7478 unsigned long rel_offset
;
7483 if (do_using_dynamic
)
7487 bfd_boolean has_dynamic_reloc
;
7490 has_dynamic_reloc
= FALSE
;
7492 for (i
= 0; i
< ARRAY_SIZE (dynamic_relocations
); i
++)
7494 is_rela
= dynamic_relocations
[i
].rela
;
7495 name
= dynamic_relocations
[i
].name
;
7496 rel_size
= filedata
->dynamic_info
[dynamic_relocations
[i
].size
];
7497 rel_offset
= filedata
->dynamic_info
[dynamic_relocations
[i
].reloc
];
7500 has_dynamic_reloc
= TRUE
;
7502 if (is_rela
== UNKNOWN
)
7504 if (dynamic_relocations
[i
].reloc
== DT_JMPREL
)
7505 switch (filedata
->dynamic_info
[DT_PLTREL
])
7519 (_("\n'%s' relocation section at offset 0x%lx contains %ld bytes:\n"),
7520 name
, rel_offset
, rel_size
);
7522 dump_relocations (filedata
,
7523 offset_from_vma (filedata
, rel_offset
, rel_size
),
7525 filedata
->dynamic_symbols
,
7526 filedata
->num_dynamic_syms
,
7527 filedata
->dynamic_strings
,
7528 filedata
->dynamic_strings_length
,
7529 is_rela
, TRUE
/* is_dynamic */);
7533 if (is_ia64_vms (filedata
))
7534 if (process_ia64_vms_dynamic_relocs (filedata
))
7535 has_dynamic_reloc
= TRUE
;
7537 if (! has_dynamic_reloc
)
7538 printf (_("\nThere are no dynamic relocations in this file.\n"));
7542 Elf_Internal_Shdr
* section
;
7544 bfd_boolean found
= FALSE
;
7546 for (i
= 0, section
= filedata
->section_headers
;
7547 i
< filedata
->file_header
.e_shnum
;
7550 if ( section
->sh_type
!= SHT_RELA
7551 && section
->sh_type
!= SHT_REL
)
7554 rel_offset
= section
->sh_offset
;
7555 rel_size
= section
->sh_size
;
7560 unsigned long num_rela
;
7562 printf (_("\nRelocation section "));
7564 if (filedata
->string_table
== NULL
)
7565 printf ("%d", section
->sh_name
);
7567 printf ("'%s'", printable_section_name (filedata
, section
));
7569 num_rela
= rel_size
/ section
->sh_entsize
;
7570 printf (ngettext (" at offset 0x%lx contains %lu entry:\n",
7571 " at offset 0x%lx contains %lu entries:\n",
7573 rel_offset
, num_rela
);
7575 is_rela
= section
->sh_type
== SHT_RELA
;
7577 if (section
->sh_link
!= 0
7578 && section
->sh_link
< filedata
->file_header
.e_shnum
)
7580 Elf_Internal_Shdr
* symsec
;
7581 Elf_Internal_Sym
* symtab
;
7582 unsigned long nsyms
;
7583 unsigned long strtablen
= 0;
7584 char * strtab
= NULL
;
7586 symsec
= filedata
->section_headers
+ section
->sh_link
;
7587 if (symsec
->sh_type
!= SHT_SYMTAB
7588 && symsec
->sh_type
!= SHT_DYNSYM
)
7591 if (!get_symtab (filedata
, symsec
,
7592 &symtab
, &nsyms
, &strtab
, &strtablen
))
7595 dump_relocations (filedata
, rel_offset
, rel_size
,
7596 symtab
, nsyms
, strtab
, strtablen
,
7598 symsec
->sh_type
== SHT_DYNSYM
);
7603 dump_relocations (filedata
, rel_offset
, rel_size
,
7604 NULL
, 0, NULL
, 0, is_rela
,
7605 FALSE
/* is_dynamic */);
7613 /* Users sometimes forget the -D option, so try to be helpful. */
7614 for (i
= 0; i
< ARRAY_SIZE (dynamic_relocations
); i
++)
7616 if (filedata
->dynamic_info
[dynamic_relocations
[i
].size
])
7618 printf (_("\nThere are no static relocations in this file."));
7619 printf (_("\nTo see the dynamic relocations add --use-dynamic to the command line.\n"));
7624 if (i
== ARRAY_SIZE (dynamic_relocations
))
7625 printf (_("\nThere are no relocations in this file.\n"));
7632 /* An absolute address consists of a section and an offset. If the
7633 section is NULL, the offset itself is the address, otherwise, the
7634 address equals to LOAD_ADDRESS(section) + offset. */
7638 unsigned short section
;
7642 /* Find the nearest symbol at or below ADDR. Returns the symbol
7643 name, if found, and the offset from the symbol to ADDR. */
7646 find_symbol_for_address (Filedata
* filedata
,
7647 Elf_Internal_Sym
* symtab
,
7648 unsigned long nsyms
,
7649 const char * strtab
,
7650 unsigned long strtab_size
,
7651 struct absaddr addr
,
7652 const char ** symname
,
7655 bfd_vma dist
= 0x100000;
7656 Elf_Internal_Sym
* sym
;
7657 Elf_Internal_Sym
* beg
;
7658 Elf_Internal_Sym
* end
;
7659 Elf_Internal_Sym
* best
= NULL
;
7661 REMOVE_ARCH_BITS (addr
.offset
);
7663 end
= symtab
+ nsyms
;
7669 sym
= beg
+ (end
- beg
) / 2;
7671 value
= sym
->st_value
;
7672 REMOVE_ARCH_BITS (value
);
7674 if (sym
->st_name
!= 0
7675 && (addr
.section
== SHN_UNDEF
|| addr
.section
== sym
->st_shndx
)
7676 && addr
.offset
>= value
7677 && addr
.offset
- value
< dist
)
7680 dist
= addr
.offset
- value
;
7685 if (addr
.offset
< value
)
7693 *symname
= (best
->st_name
>= strtab_size
7694 ? _("<corrupt>") : strtab
+ best
->st_name
);
7700 *offset
= addr
.offset
;
7703 static /* signed */ int
7704 symcmp (const void *p
, const void *q
)
7706 Elf_Internal_Sym
*sp
= (Elf_Internal_Sym
*) p
;
7707 Elf_Internal_Sym
*sq
= (Elf_Internal_Sym
*) q
;
7709 return sp
->st_value
> sq
->st_value
? 1 : (sp
->st_value
< sq
->st_value
? -1 : 0);
7712 /* Process the unwind section. */
7714 #include "unwind-ia64.h"
7716 struct ia64_unw_table_entry
7718 struct absaddr start
;
7720 struct absaddr info
;
7723 struct ia64_unw_aux_info
7725 struct ia64_unw_table_entry
* table
; /* Unwind table. */
7726 unsigned long table_len
; /* Length of unwind table. */
7727 unsigned char * info
; /* Unwind info. */
7728 unsigned long info_size
; /* Size of unwind info. */
7729 bfd_vma info_addr
; /* Starting address of unwind info. */
7730 bfd_vma seg_base
; /* Starting address of segment. */
7731 Elf_Internal_Sym
* symtab
; /* The symbol table. */
7732 unsigned long nsyms
; /* Number of symbols. */
7733 Elf_Internal_Sym
* funtab
; /* Sorted table of STT_FUNC symbols. */
7734 unsigned long nfuns
; /* Number of entries in funtab. */
7735 char * strtab
; /* The string table. */
7736 unsigned long strtab_size
; /* Size of string table. */
7740 dump_ia64_unwind (Filedata
* filedata
, struct ia64_unw_aux_info
* aux
)
7742 struct ia64_unw_table_entry
* tp
;
7743 unsigned long j
, nfuns
;
7745 bfd_boolean res
= TRUE
;
7747 aux
->funtab
= xmalloc (aux
->nsyms
* sizeof (Elf_Internal_Sym
));
7748 for (nfuns
= 0, j
= 0; j
< aux
->nsyms
; j
++)
7749 if (aux
->symtab
[j
].st_value
&& ELF_ST_TYPE (aux
->symtab
[j
].st_info
) == STT_FUNC
)
7750 aux
->funtab
[nfuns
++] = aux
->symtab
[j
];
7752 qsort (aux
->funtab
, aux
->nfuns
, sizeof (Elf_Internal_Sym
), symcmp
);
7754 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
7758 const unsigned char * dp
;
7759 const unsigned char * head
;
7760 const unsigned char * end
;
7761 const char * procname
;
7763 find_symbol_for_address (filedata
, aux
->funtab
, aux
->nfuns
, aux
->strtab
,
7764 aux
->strtab_size
, tp
->start
, &procname
, &offset
);
7766 fputs ("\n<", stdout
);
7770 fputs (procname
, stdout
);
7773 printf ("+%lx", (unsigned long) offset
);
7776 fputs (">: [", stdout
);
7777 print_vma (tp
->start
.offset
, PREFIX_HEX
);
7778 fputc ('-', stdout
);
7779 print_vma (tp
->end
.offset
, PREFIX_HEX
);
7780 printf ("], info at +0x%lx\n",
7781 (unsigned long) (tp
->info
.offset
- aux
->seg_base
));
7783 /* PR 17531: file: 86232b32. */
7784 if (aux
->info
== NULL
)
7787 offset
= tp
->info
.offset
;
7788 if (tp
->info
.section
)
7790 if (tp
->info
.section
>= filedata
->file_header
.e_shnum
)
7792 warn (_("Invalid section %u in table entry %ld\n"),
7793 tp
->info
.section
, (long) (tp
- aux
->table
));
7797 offset
+= filedata
->section_headers
[tp
->info
.section
].sh_addr
;
7799 offset
-= aux
->info_addr
;
7800 /* PR 17531: file: 0997b4d1. */
7801 if (offset
>= aux
->info_size
7802 || aux
->info_size
- offset
< 8)
7804 warn (_("Invalid offset %lx in table entry %ld\n"),
7805 (long) tp
->info
.offset
, (long) (tp
- aux
->table
));
7810 head
= aux
->info
+ offset
;
7811 stamp
= byte_get ((unsigned char *) head
, sizeof (stamp
));
7813 printf (" v%u, flags=0x%lx (%s%s), len=%lu bytes\n",
7814 (unsigned) UNW_VER (stamp
),
7815 (unsigned long) ((stamp
& UNW_FLAG_MASK
) >> 32),
7816 UNW_FLAG_EHANDLER (stamp
) ? " ehandler" : "",
7817 UNW_FLAG_UHANDLER (stamp
) ? " uhandler" : "",
7818 (unsigned long) (eh_addr_size
* UNW_LENGTH (stamp
)));
7820 if (UNW_VER (stamp
) != 1)
7822 printf (_("\tUnknown version.\n"));
7827 end
= head
+ 8 + eh_addr_size
* UNW_LENGTH (stamp
);
7828 /* PR 17531: file: 16ceda89. */
7829 if (end
> aux
->info
+ aux
->info_size
)
7830 end
= aux
->info
+ aux
->info_size
;
7831 for (dp
= head
+ 8; dp
< end
;)
7832 dp
= unw_decode (dp
, in_body
, & in_body
, end
);
7841 slurp_ia64_unwind_table (Filedata
* filedata
,
7842 struct ia64_unw_aux_info
* aux
,
7843 Elf_Internal_Shdr
* sec
)
7845 unsigned long size
, nrelas
, i
;
7846 Elf_Internal_Phdr
* seg
;
7847 struct ia64_unw_table_entry
* tep
;
7848 Elf_Internal_Shdr
* relsec
;
7849 Elf_Internal_Rela
* rela
;
7850 Elf_Internal_Rela
* rp
;
7851 unsigned char * table
;
7853 Elf_Internal_Sym
* sym
;
7854 const char * relname
;
7858 /* First, find the starting address of the segment that includes
7861 if (filedata
->file_header
.e_phnum
)
7863 if (! get_program_headers (filedata
))
7866 for (seg
= filedata
->program_headers
;
7867 seg
< filedata
->program_headers
+ filedata
->file_header
.e_phnum
;
7870 if (seg
->p_type
!= PT_LOAD
)
7873 if (sec
->sh_addr
>= seg
->p_vaddr
7874 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
7876 aux
->seg_base
= seg
->p_vaddr
;
7882 /* Second, build the unwind table from the contents of the unwind section: */
7883 size
= sec
->sh_size
;
7884 table
= (unsigned char *) get_data (NULL
, filedata
, sec
->sh_offset
, 1, size
,
7889 aux
->table_len
= size
/ (3 * eh_addr_size
);
7890 aux
->table
= (struct ia64_unw_table_entry
*)
7891 xcmalloc (aux
->table_len
, sizeof (aux
->table
[0]));
7894 for (tp
= table
; tp
<= table
+ size
- (3 * eh_addr_size
); ++tep
)
7896 tep
->start
.section
= SHN_UNDEF
;
7897 tep
->end
.section
= SHN_UNDEF
;
7898 tep
->info
.section
= SHN_UNDEF
;
7899 tep
->start
.offset
= byte_get (tp
, eh_addr_size
); tp
+= eh_addr_size
;
7900 tep
->end
.offset
= byte_get (tp
, eh_addr_size
); tp
+= eh_addr_size
;
7901 tep
->info
.offset
= byte_get (tp
, eh_addr_size
); tp
+= eh_addr_size
;
7902 tep
->start
.offset
+= aux
->seg_base
;
7903 tep
->end
.offset
+= aux
->seg_base
;
7904 tep
->info
.offset
+= aux
->seg_base
;
7908 /* Third, apply any relocations to the unwind table: */
7909 for (relsec
= filedata
->section_headers
;
7910 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
7913 if (relsec
->sh_type
!= SHT_RELA
7914 || relsec
->sh_info
>= filedata
->file_header
.e_shnum
7915 || filedata
->section_headers
+ relsec
->sh_info
!= sec
)
7918 if (!slurp_rela_relocs (filedata
, relsec
->sh_offset
, relsec
->sh_size
,
7927 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
7929 unsigned int sym_ndx
;
7930 unsigned int r_type
= get_reloc_type (filedata
, rp
->r_info
);
7931 relname
= elf_ia64_reloc_type (r_type
);
7933 /* PR 17531: file: 9fa67536. */
7934 if (relname
== NULL
)
7936 warn (_("Skipping unknown relocation type: %u\n"), r_type
);
7940 if (! const_strneq (relname
, "R_IA64_SEGREL"))
7942 warn (_("Skipping unexpected relocation type: %s\n"), relname
);
7946 i
= rp
->r_offset
/ (3 * eh_addr_size
);
7948 /* PR 17531: file: 5bc8d9bf. */
7949 if (i
>= aux
->table_len
)
7951 warn (_("Skipping reloc with overlarge offset: %lx\n"), i
);
7955 sym_ndx
= get_reloc_symindex (rp
->r_info
);
7956 if (sym_ndx
>= aux
->nsyms
)
7958 warn (_("Skipping reloc with invalid symbol index: %u\n"),
7962 sym
= aux
->symtab
+ sym_ndx
;
7964 switch (rp
->r_offset
/ eh_addr_size
% 3)
7967 aux
->table
[i
].start
.section
= sym
->st_shndx
;
7968 aux
->table
[i
].start
.offset
= rp
->r_addend
+ sym
->st_value
;
7971 aux
->table
[i
].end
.section
= sym
->st_shndx
;
7972 aux
->table
[i
].end
.offset
= rp
->r_addend
+ sym
->st_value
;
7975 aux
->table
[i
].info
.section
= sym
->st_shndx
;
7976 aux
->table
[i
].info
.offset
= rp
->r_addend
+ sym
->st_value
;
7990 ia64_process_unwind (Filedata
* filedata
)
7992 Elf_Internal_Shdr
* sec
;
7993 Elf_Internal_Shdr
* unwsec
= NULL
;
7994 unsigned long i
, unwcount
= 0, unwstart
= 0;
7995 struct ia64_unw_aux_info aux
;
7996 bfd_boolean res
= TRUE
;
7998 memset (& aux
, 0, sizeof (aux
));
8000 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
8002 if (sec
->sh_type
== SHT_SYMTAB
)
8006 error (_("Multiple symbol tables encountered\n"));
8012 if (!get_symtab (filedata
, sec
, &aux
.symtab
, &aux
.nsyms
,
8013 &aux
.strtab
, &aux
.strtab_size
))
8016 else if (sec
->sh_type
== SHT_IA_64_UNWIND
)
8021 printf (_("\nThere are no unwind sections in this file.\n"));
8023 while (unwcount
-- > 0)
8028 for (i
= unwstart
, sec
= filedata
->section_headers
+ unwstart
, unwsec
= NULL
;
8029 i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
8030 if (sec
->sh_type
== SHT_IA_64_UNWIND
)
8035 /* We have already counted the number of SHT_IA64_UNWIND
8036 sections so the loop above should never fail. */
8037 assert (unwsec
!= NULL
);
8040 len
= sizeof (ELF_STRING_ia64_unwind_once
) - 1;
8042 if ((unwsec
->sh_flags
& SHF_GROUP
) != 0)
8044 /* We need to find which section group it is in. */
8045 struct group_list
* g
;
8047 if (filedata
->section_headers_groups
== NULL
8048 || filedata
->section_headers_groups
[i
] == NULL
)
8049 i
= filedata
->file_header
.e_shnum
;
8052 g
= filedata
->section_headers_groups
[i
]->root
;
8054 for (; g
!= NULL
; g
= g
->next
)
8056 sec
= filedata
->section_headers
+ g
->section_index
;
8058 if (streq (SECTION_NAME (sec
), ELF_STRING_ia64_unwind_info
))
8063 i
= filedata
->file_header
.e_shnum
;
8066 else if (strneq (SECTION_NAME (unwsec
), ELF_STRING_ia64_unwind_once
, len
))
8068 /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO. */
8069 len2
= sizeof (ELF_STRING_ia64_unwind_info_once
) - 1;
8070 suffix
= SECTION_NAME (unwsec
) + len
;
8071 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
;
8073 if (strneq (SECTION_NAME (sec
), ELF_STRING_ia64_unwind_info_once
, len2
)
8074 && streq (SECTION_NAME (sec
) + len2
, suffix
))
8079 /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
8080 .IA_64.unwind or BAR -> .IA_64.unwind_info. */
8081 len
= sizeof (ELF_STRING_ia64_unwind
) - 1;
8082 len2
= sizeof (ELF_STRING_ia64_unwind_info
) - 1;
8084 if (strneq (SECTION_NAME (unwsec
), ELF_STRING_ia64_unwind
, len
))
8085 suffix
= SECTION_NAME (unwsec
) + len
;
8086 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
;
8088 if (strneq (SECTION_NAME (sec
), ELF_STRING_ia64_unwind_info
, len2
)
8089 && streq (SECTION_NAME (sec
) + len2
, suffix
))
8093 if (i
== filedata
->file_header
.e_shnum
)
8095 printf (_("\nCould not find unwind info section for "));
8097 if (filedata
->string_table
== NULL
)
8098 printf ("%d", unwsec
->sh_name
);
8100 printf ("'%s'", printable_section_name (filedata
, unwsec
));
8104 aux
.info_addr
= sec
->sh_addr
;
8105 aux
.info
= (unsigned char *) get_data (NULL
, filedata
, sec
->sh_offset
, 1,
8108 aux
.info_size
= aux
.info
== NULL
? 0 : sec
->sh_size
;
8110 printf (_("\nUnwind section "));
8112 if (filedata
->string_table
== NULL
)
8113 printf ("%d", unwsec
->sh_name
);
8115 printf ("'%s'", printable_section_name (filedata
, unwsec
));
8117 printf (_(" at offset 0x%lx contains %lu entries:\n"),
8118 (unsigned long) unwsec
->sh_offset
,
8119 (unsigned long) (unwsec
->sh_size
/ (3 * eh_addr_size
)));
8121 if (slurp_ia64_unwind_table (filedata
, & aux
, unwsec
)
8122 && aux
.table_len
> 0)
8123 dump_ia64_unwind (filedata
, & aux
);
8125 free ((char *) aux
.table
);
8126 free ((char *) aux
.info
);
8133 free ((char *) aux
.strtab
);
8138 struct hppa_unw_table_entry
8140 struct absaddr start
;
8142 unsigned int Cannot_unwind
:1; /* 0 */
8143 unsigned int Millicode
:1; /* 1 */
8144 unsigned int Millicode_save_sr0
:1; /* 2 */
8145 unsigned int Region_description
:2; /* 3..4 */
8146 unsigned int reserved1
:1; /* 5 */
8147 unsigned int Entry_SR
:1; /* 6 */
8148 unsigned int Entry_FR
:4; /* Number saved 7..10 */
8149 unsigned int Entry_GR
:5; /* Number saved 11..15 */
8150 unsigned int Args_stored
:1; /* 16 */
8151 unsigned int Variable_Frame
:1; /* 17 */
8152 unsigned int Separate_Package_Body
:1; /* 18 */
8153 unsigned int Frame_Extension_Millicode
:1; /* 19 */
8154 unsigned int Stack_Overflow_Check
:1; /* 20 */
8155 unsigned int Two_Instruction_SP_Increment
:1; /* 21 */
8156 unsigned int Ada_Region
:1; /* 22 */
8157 unsigned int cxx_info
:1; /* 23 */
8158 unsigned int cxx_try_catch
:1; /* 24 */
8159 unsigned int sched_entry_seq
:1; /* 25 */
8160 unsigned int reserved2
:1; /* 26 */
8161 unsigned int Save_SP
:1; /* 27 */
8162 unsigned int Save_RP
:1; /* 28 */
8163 unsigned int Save_MRP_in_frame
:1; /* 29 */
8164 unsigned int extn_ptr_defined
:1; /* 30 */
8165 unsigned int Cleanup_defined
:1; /* 31 */
8167 unsigned int MPE_XL_interrupt_marker
:1; /* 0 */
8168 unsigned int HP_UX_interrupt_marker
:1; /* 1 */
8169 unsigned int Large_frame
:1; /* 2 */
8170 unsigned int Pseudo_SP_Set
:1; /* 3 */
8171 unsigned int reserved4
:1; /* 4 */
8172 unsigned int Total_frame_size
:27; /* 5..31 */
8175 struct hppa_unw_aux_info
8177 struct hppa_unw_table_entry
* table
; /* Unwind table. */
8178 unsigned long table_len
; /* Length of unwind table. */
8179 bfd_vma seg_base
; /* Starting address of segment. */
8180 Elf_Internal_Sym
* symtab
; /* The symbol table. */
8181 unsigned long nsyms
; /* Number of symbols. */
8182 Elf_Internal_Sym
* funtab
; /* Sorted table of STT_FUNC symbols. */
8183 unsigned long nfuns
; /* Number of entries in funtab. */
8184 char * strtab
; /* The string table. */
8185 unsigned long strtab_size
; /* Size of string table. */
8189 dump_hppa_unwind (Filedata
* filedata
, struct hppa_unw_aux_info
* aux
)
8191 struct hppa_unw_table_entry
* tp
;
8192 unsigned long j
, nfuns
;
8193 bfd_boolean res
= TRUE
;
8195 aux
->funtab
= xmalloc (aux
->nsyms
* sizeof (Elf_Internal_Sym
));
8196 for (nfuns
= 0, j
= 0; j
< aux
->nsyms
; j
++)
8197 if (aux
->symtab
[j
].st_value
&& ELF_ST_TYPE (aux
->symtab
[j
].st_info
) == STT_FUNC
)
8198 aux
->funtab
[nfuns
++] = aux
->symtab
[j
];
8200 qsort (aux
->funtab
, aux
->nfuns
, sizeof (Elf_Internal_Sym
), symcmp
);
8202 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
8205 const char * procname
;
8207 find_symbol_for_address (filedata
, aux
->funtab
, aux
->nfuns
, aux
->strtab
,
8208 aux
->strtab_size
, tp
->start
, &procname
,
8211 fputs ("\n<", stdout
);
8215 fputs (procname
, stdout
);
8218 printf ("+%lx", (unsigned long) offset
);
8221 fputs (">: [", stdout
);
8222 print_vma (tp
->start
.offset
, PREFIX_HEX
);
8223 fputc ('-', stdout
);
8224 print_vma (tp
->end
.offset
, PREFIX_HEX
);
8227 #define PF(_m) if (tp->_m) printf (#_m " ");
8228 #define PV(_m) if (tp->_m) printf (#_m "=%d ", tp->_m);
8231 PF(Millicode_save_sr0
);
8232 /* PV(Region_description); */
8238 PF(Separate_Package_Body
);
8239 PF(Frame_Extension_Millicode
);
8240 PF(Stack_Overflow_Check
);
8241 PF(Two_Instruction_SP_Increment
);
8245 PF(sched_entry_seq
);
8248 PF(Save_MRP_in_frame
);
8249 PF(extn_ptr_defined
);
8250 PF(Cleanup_defined
);
8251 PF(MPE_XL_interrupt_marker
);
8252 PF(HP_UX_interrupt_marker
);
8255 PV(Total_frame_size
);
8268 slurp_hppa_unwind_table (Filedata
* filedata
,
8269 struct hppa_unw_aux_info
* aux
,
8270 Elf_Internal_Shdr
* sec
)
8272 unsigned long size
, unw_ent_size
, nentries
, nrelas
, i
;
8273 Elf_Internal_Phdr
* seg
;
8274 struct hppa_unw_table_entry
* tep
;
8275 Elf_Internal_Shdr
* relsec
;
8276 Elf_Internal_Rela
* rela
;
8277 Elf_Internal_Rela
* rp
;
8278 unsigned char * table
;
8280 Elf_Internal_Sym
* sym
;
8281 const char * relname
;
8283 /* First, find the starting address of the segment that includes
8285 if (filedata
->file_header
.e_phnum
)
8287 if (! get_program_headers (filedata
))
8290 for (seg
= filedata
->program_headers
;
8291 seg
< filedata
->program_headers
+ filedata
->file_header
.e_phnum
;
8294 if (seg
->p_type
!= PT_LOAD
)
8297 if (sec
->sh_addr
>= seg
->p_vaddr
8298 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
8300 aux
->seg_base
= seg
->p_vaddr
;
8306 /* Second, build the unwind table from the contents of the unwind
8308 size
= sec
->sh_size
;
8309 table
= (unsigned char *) get_data (NULL
, filedata
, sec
->sh_offset
, 1, size
,
8315 nentries
= size
/ unw_ent_size
;
8316 size
= unw_ent_size
* nentries
;
8318 aux
->table_len
= nentries
;
8319 tep
= aux
->table
= (struct hppa_unw_table_entry
*)
8320 xcmalloc (nentries
, sizeof (aux
->table
[0]));
8322 for (tp
= table
; tp
< table
+ size
; tp
+= unw_ent_size
, ++tep
)
8324 unsigned int tmp1
, tmp2
;
8326 tep
->start
.section
= SHN_UNDEF
;
8327 tep
->end
.section
= SHN_UNDEF
;
8329 tep
->start
.offset
= byte_get ((unsigned char *) tp
+ 0, 4);
8330 tep
->end
.offset
= byte_get ((unsigned char *) tp
+ 4, 4);
8331 tmp1
= byte_get ((unsigned char *) tp
+ 8, 4);
8332 tmp2
= byte_get ((unsigned char *) tp
+ 12, 4);
8334 tep
->start
.offset
+= aux
->seg_base
;
8335 tep
->end
.offset
+= aux
->seg_base
;
8337 tep
->Cannot_unwind
= (tmp1
>> 31) & 0x1;
8338 tep
->Millicode
= (tmp1
>> 30) & 0x1;
8339 tep
->Millicode_save_sr0
= (tmp1
>> 29) & 0x1;
8340 tep
->Region_description
= (tmp1
>> 27) & 0x3;
8341 tep
->reserved1
= (tmp1
>> 26) & 0x1;
8342 tep
->Entry_SR
= (tmp1
>> 25) & 0x1;
8343 tep
->Entry_FR
= (tmp1
>> 21) & 0xf;
8344 tep
->Entry_GR
= (tmp1
>> 16) & 0x1f;
8345 tep
->Args_stored
= (tmp1
>> 15) & 0x1;
8346 tep
->Variable_Frame
= (tmp1
>> 14) & 0x1;
8347 tep
->Separate_Package_Body
= (tmp1
>> 13) & 0x1;
8348 tep
->Frame_Extension_Millicode
= (tmp1
>> 12) & 0x1;
8349 tep
->Stack_Overflow_Check
= (tmp1
>> 11) & 0x1;
8350 tep
->Two_Instruction_SP_Increment
= (tmp1
>> 10) & 0x1;
8351 tep
->Ada_Region
= (tmp1
>> 9) & 0x1;
8352 tep
->cxx_info
= (tmp1
>> 8) & 0x1;
8353 tep
->cxx_try_catch
= (tmp1
>> 7) & 0x1;
8354 tep
->sched_entry_seq
= (tmp1
>> 6) & 0x1;
8355 tep
->reserved2
= (tmp1
>> 5) & 0x1;
8356 tep
->Save_SP
= (tmp1
>> 4) & 0x1;
8357 tep
->Save_RP
= (tmp1
>> 3) & 0x1;
8358 tep
->Save_MRP_in_frame
= (tmp1
>> 2) & 0x1;
8359 tep
->extn_ptr_defined
= (tmp1
>> 1) & 0x1;
8360 tep
->Cleanup_defined
= tmp1
& 0x1;
8362 tep
->MPE_XL_interrupt_marker
= (tmp2
>> 31) & 0x1;
8363 tep
->HP_UX_interrupt_marker
= (tmp2
>> 30) & 0x1;
8364 tep
->Large_frame
= (tmp2
>> 29) & 0x1;
8365 tep
->Pseudo_SP_Set
= (tmp2
>> 28) & 0x1;
8366 tep
->reserved4
= (tmp2
>> 27) & 0x1;
8367 tep
->Total_frame_size
= tmp2
& 0x7ffffff;
8371 /* Third, apply any relocations to the unwind table. */
8372 for (relsec
= filedata
->section_headers
;
8373 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
8376 if (relsec
->sh_type
!= SHT_RELA
8377 || relsec
->sh_info
>= filedata
->file_header
.e_shnum
8378 || filedata
->section_headers
+ relsec
->sh_info
!= sec
)
8381 if (!slurp_rela_relocs (filedata
, relsec
->sh_offset
, relsec
->sh_size
,
8385 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
8387 unsigned int sym_ndx
;
8388 unsigned int r_type
= get_reloc_type (filedata
, rp
->r_info
);
8389 relname
= elf_hppa_reloc_type (r_type
);
8391 if (relname
== NULL
)
8393 warn (_("Skipping unknown relocation type: %u\n"), r_type
);
8397 /* R_PARISC_SEGREL32 or R_PARISC_SEGREL64. */
8398 if (! const_strneq (relname
, "R_PARISC_SEGREL"))
8400 warn (_("Skipping unexpected relocation type: %s\n"), relname
);
8404 i
= rp
->r_offset
/ unw_ent_size
;
8405 if (i
>= aux
->table_len
)
8407 warn (_("Skipping reloc with overlarge offset: %lx\n"), i
);
8411 sym_ndx
= get_reloc_symindex (rp
->r_info
);
8412 if (sym_ndx
>= aux
->nsyms
)
8414 warn (_("Skipping reloc with invalid symbol index: %u\n"),
8418 sym
= aux
->symtab
+ sym_ndx
;
8420 switch ((rp
->r_offset
% unw_ent_size
) / 4)
8423 aux
->table
[i
].start
.section
= sym
->st_shndx
;
8424 aux
->table
[i
].start
.offset
= sym
->st_value
+ rp
->r_addend
;
8427 aux
->table
[i
].end
.section
= sym
->st_shndx
;
8428 aux
->table
[i
].end
.offset
= sym
->st_value
+ rp
->r_addend
;
8442 hppa_process_unwind (Filedata
* filedata
)
8444 struct hppa_unw_aux_info aux
;
8445 Elf_Internal_Shdr
* unwsec
= NULL
;
8446 Elf_Internal_Shdr
* sec
;
8448 bfd_boolean res
= TRUE
;
8450 if (filedata
->string_table
== NULL
)
8453 memset (& aux
, 0, sizeof (aux
));
8455 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
8457 if (sec
->sh_type
== SHT_SYMTAB
)
8461 error (_("Multiple symbol tables encountered\n"));
8467 if (!get_symtab (filedata
, sec
, &aux
.symtab
, &aux
.nsyms
,
8468 &aux
.strtab
, &aux
.strtab_size
))
8471 else if (streq (SECTION_NAME (sec
), ".PARISC.unwind"))
8476 printf (_("\nThere are no unwind sections in this file.\n"));
8478 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
8480 if (streq (SECTION_NAME (sec
), ".PARISC.unwind"))
8482 unsigned long num_unwind
= sec
->sh_size
/ 16;
8484 printf (ngettext ("\nUnwind section '%s' at offset 0x%lx "
8485 "contains %lu entry:\n",
8486 "\nUnwind section '%s' at offset 0x%lx "
8487 "contains %lu entries:\n",
8489 printable_section_name (filedata
, sec
),
8490 (unsigned long) sec
->sh_offset
,
8493 if (! slurp_hppa_unwind_table (filedata
, &aux
, sec
))
8496 if (res
&& aux
.table_len
> 0)
8498 if (! dump_hppa_unwind (filedata
, &aux
))
8502 free ((char *) aux
.table
);
8508 free ((char *) aux
.strtab
);
8515 unsigned char * data
; /* The unwind data. */
8516 Elf_Internal_Shdr
* sec
; /* The cached unwind section header. */
8517 Elf_Internal_Rela
* rela
; /* The cached relocations for this section. */
8518 unsigned long nrelas
; /* The number of relocations. */
8519 unsigned int rel_type
; /* REL or RELA ? */
8520 Elf_Internal_Rela
* next_rela
; /* Cyclic pointer to the next reloc to process. */
8523 struct arm_unw_aux_info
8525 Filedata
* filedata
; /* The file containing the unwind sections. */
8526 Elf_Internal_Sym
* symtab
; /* The file's symbol table. */
8527 unsigned long nsyms
; /* Number of symbols. */
8528 Elf_Internal_Sym
* funtab
; /* Sorted table of STT_FUNC symbols. */
8529 unsigned long nfuns
; /* Number of these symbols. */
8530 char * strtab
; /* The file's string table. */
8531 unsigned long strtab_size
; /* Size of string table. */
8535 arm_print_vma_and_name (Filedata
* filedata
,
8536 struct arm_unw_aux_info
* aux
,
8538 struct absaddr addr
)
8540 const char *procname
;
8543 if (addr
.section
== SHN_UNDEF
)
8546 find_symbol_for_address (filedata
, aux
->funtab
, aux
->nfuns
, aux
->strtab
,
8547 aux
->strtab_size
, addr
, &procname
,
8550 print_vma (fn
, PREFIX_HEX
);
8554 fputs (" <", stdout
);
8555 fputs (procname
, stdout
);
8558 printf ("+0x%lx", (unsigned long) sym_offset
);
8559 fputc ('>', stdout
);
8566 arm_free_section (struct arm_section
*arm_sec
)
8568 free (arm_sec
->data
);
8569 free (arm_sec
->rela
);
8572 /* 1) If SEC does not match the one cached in ARM_SEC, then free the current
8573 cached section and install SEC instead.
8574 2) Locate the 32-bit word at WORD_OFFSET in unwind section SEC
8575 and return its valued in * WORDP, relocating if necessary.
8576 3) Update the NEXT_RELA field in ARM_SEC and store the section index and
8577 relocation's offset in ADDR.
8578 4) If SYM_NAME is non-NULL and a relocation was applied, record the offset
8579 into the string table of the symbol associated with the reloc. If no
8580 reloc was applied store -1 there.
8581 5) Return TRUE upon success, FALSE otherwise. */
8584 get_unwind_section_word (Filedata
* filedata
,
8585 struct arm_unw_aux_info
* aux
,
8586 struct arm_section
* arm_sec
,
8587 Elf_Internal_Shdr
* sec
,
8588 bfd_vma word_offset
,
8589 unsigned int * wordp
,
8590 struct absaddr
* addr
,
8593 Elf_Internal_Rela
*rp
;
8594 Elf_Internal_Sym
*sym
;
8595 const char * relname
;
8597 bfd_boolean wrapped
;
8599 if (sec
== NULL
|| arm_sec
== NULL
)
8602 addr
->section
= SHN_UNDEF
;
8605 if (sym_name
!= NULL
)
8606 *sym_name
= (bfd_vma
) -1;
8608 /* If necessary, update the section cache. */
8609 if (sec
!= arm_sec
->sec
)
8611 Elf_Internal_Shdr
*relsec
;
8613 arm_free_section (arm_sec
);
8616 arm_sec
->data
= get_data (NULL
, aux
->filedata
, sec
->sh_offset
, 1,
8617 sec
->sh_size
, _("unwind data"));
8618 arm_sec
->rela
= NULL
;
8619 arm_sec
->nrelas
= 0;
8621 for (relsec
= filedata
->section_headers
;
8622 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
8625 if (relsec
->sh_info
>= filedata
->file_header
.e_shnum
8626 || filedata
->section_headers
+ relsec
->sh_info
!= sec
8627 /* PR 15745: Check the section type as well. */
8628 || (relsec
->sh_type
!= SHT_REL
8629 && relsec
->sh_type
!= SHT_RELA
))
8632 arm_sec
->rel_type
= relsec
->sh_type
;
8633 if (relsec
->sh_type
== SHT_REL
)
8635 if (!slurp_rel_relocs (aux
->filedata
, relsec
->sh_offset
,
8637 & arm_sec
->rela
, & arm_sec
->nrelas
))
8640 else /* relsec->sh_type == SHT_RELA */
8642 if (!slurp_rela_relocs (aux
->filedata
, relsec
->sh_offset
,
8644 & arm_sec
->rela
, & arm_sec
->nrelas
))
8650 arm_sec
->next_rela
= arm_sec
->rela
;
8653 /* If there is no unwind data we can do nothing. */
8654 if (arm_sec
->data
== NULL
)
8657 /* If the offset is invalid then fail. */
8658 if (/* PR 21343 *//* PR 18879 */
8660 || word_offset
> (sec
->sh_size
- 4)
8661 || ((bfd_signed_vma
) word_offset
) < 0)
8664 /* Get the word at the required offset. */
8665 word
= byte_get (arm_sec
->data
+ word_offset
, 4);
8667 /* PR 17531: file: id:000001,src:001266+003044,op:splice,rep:128. */
8668 if (arm_sec
->rela
== NULL
)
8674 /* Look through the relocs to find the one that applies to the provided offset. */
8676 for (rp
= arm_sec
->next_rela
; rp
!= arm_sec
->rela
+ arm_sec
->nrelas
; rp
++)
8678 bfd_vma prelval
, offset
;
8680 if (rp
->r_offset
> word_offset
&& !wrapped
)
8685 if (rp
->r_offset
> word_offset
)
8688 if (rp
->r_offset
& 3)
8690 warn (_("Skipping unexpected relocation at offset 0x%lx\n"),
8691 (unsigned long) rp
->r_offset
);
8695 if (rp
->r_offset
< word_offset
)
8698 /* PR 17531: file: 027-161405-0.004 */
8699 if (aux
->symtab
== NULL
)
8702 if (arm_sec
->rel_type
== SHT_REL
)
8704 offset
= word
& 0x7fffffff;
8705 if (offset
& 0x40000000)
8706 offset
|= ~ (bfd_vma
) 0x7fffffff;
8708 else if (arm_sec
->rel_type
== SHT_RELA
)
8709 offset
= rp
->r_addend
;
8712 error (_("Unknown section relocation type %d encountered\n"),
8717 /* PR 17531 file: 027-1241568-0.004. */
8718 if (ELF32_R_SYM (rp
->r_info
) >= aux
->nsyms
)
8720 error (_("Bad symbol index in unwind relocation (%lu > %lu)\n"),
8721 (unsigned long) ELF32_R_SYM (rp
->r_info
), aux
->nsyms
);
8725 sym
= aux
->symtab
+ ELF32_R_SYM (rp
->r_info
);
8726 offset
+= sym
->st_value
;
8727 prelval
= offset
- (arm_sec
->sec
->sh_addr
+ rp
->r_offset
);
8729 /* Check that we are processing the expected reloc type. */
8730 if (filedata
->file_header
.e_machine
== EM_ARM
)
8732 relname
= elf_arm_reloc_type (ELF32_R_TYPE (rp
->r_info
));
8733 if (relname
== NULL
)
8735 warn (_("Skipping unknown ARM relocation type: %d\n"),
8736 (int) ELF32_R_TYPE (rp
->r_info
));
8740 if (streq (relname
, "R_ARM_NONE"))
8743 if (! streq (relname
, "R_ARM_PREL31"))
8745 warn (_("Skipping unexpected ARM relocation type %s\n"), relname
);
8749 else if (filedata
->file_header
.e_machine
== EM_TI_C6000
)
8751 relname
= elf_tic6x_reloc_type (ELF32_R_TYPE (rp
->r_info
));
8752 if (relname
== NULL
)
8754 warn (_("Skipping unknown C6000 relocation type: %d\n"),
8755 (int) ELF32_R_TYPE (rp
->r_info
));
8759 if (streq (relname
, "R_C6000_NONE"))
8762 if (! streq (relname
, "R_C6000_PREL31"))
8764 warn (_("Skipping unexpected C6000 relocation type %s\n"), relname
);
8772 /* This function currently only supports ARM and TI unwinders. */
8773 warn (_("Only TI and ARM unwinders are currently supported\n"));
8777 word
= (word
& ~ (bfd_vma
) 0x7fffffff) | (prelval
& 0x7fffffff);
8778 addr
->section
= sym
->st_shndx
;
8779 addr
->offset
= offset
;
8782 * sym_name
= sym
->st_name
;
8787 arm_sec
->next_rela
= rp
;
8792 static const char *tic6x_unwind_regnames
[16] =
8794 "A15", "B15", "B14", "B13", "B12", "B11", "B10", "B3",
8795 "A14", "A13", "A12", "A11", "A10",
8796 "[invalid reg 13]", "[invalid reg 14]", "[invalid reg 15]"
8800 decode_tic6x_unwind_regmask (unsigned int mask
)
8804 for (i
= 12; mask
; mask
>>= 1, i
--)
8808 fputs (tic6x_unwind_regnames
[i
], stdout
);
8810 fputs (", ", stdout
);
8816 if (remaining == 0 && more_words) \
8819 if (! get_unwind_section_word (filedata, aux, data_arm_sec, data_sec, \
8820 data_offset, & word, & addr, NULL)) \
8826 #define GET_OP(OP) \
8831 (OP) = word >> 24; \
8836 printf (_("[Truncated opcode]\n")); \
8839 printf ("0x%02x ", OP)
8842 decode_arm_unwind_bytecode (Filedata
* filedata
,
8843 struct arm_unw_aux_info
* aux
,
8845 unsigned int remaining
,
8846 unsigned int more_words
,
8847 bfd_vma data_offset
,
8848 Elf_Internal_Shdr
* data_sec
,
8849 struct arm_section
* data_arm_sec
)
8851 struct absaddr addr
;
8852 bfd_boolean res
= TRUE
;
8854 /* Decode the unwinding instructions. */
8857 unsigned int op
, op2
;
8866 printf (" 0x%02x ", op
);
8868 if ((op
& 0xc0) == 0x00)
8870 int offset
= ((op
& 0x3f) << 2) + 4;
8872 printf (" vsp = vsp + %d", offset
);
8874 else if ((op
& 0xc0) == 0x40)
8876 int offset
= ((op
& 0x3f) << 2) + 4;
8878 printf (" vsp = vsp - %d", offset
);
8880 else if ((op
& 0xf0) == 0x80)
8883 if (op
== 0x80 && op2
== 0)
8884 printf (_("Refuse to unwind"));
8887 unsigned int mask
= ((op
& 0x0f) << 8) | op2
;
8888 bfd_boolean first
= TRUE
;
8892 for (i
= 0; i
< 12; i
++)
8893 if (mask
& (1 << i
))
8899 printf ("r%d", 4 + i
);
8904 else if ((op
& 0xf0) == 0x90)
8906 if (op
== 0x9d || op
== 0x9f)
8907 printf (_(" [Reserved]"));
8909 printf (" vsp = r%d", op
& 0x0f);
8911 else if ((op
& 0xf0) == 0xa0)
8913 int end
= 4 + (op
& 0x07);
8914 bfd_boolean first
= TRUE
;
8918 for (i
= 4; i
<= end
; i
++)
8934 else if (op
== 0xb0)
8935 printf (_(" finish"));
8936 else if (op
== 0xb1)
8939 if (op2
== 0 || (op2
& 0xf0) != 0)
8940 printf (_("[Spare]"));
8943 unsigned int mask
= op2
& 0x0f;
8944 bfd_boolean first
= TRUE
;
8948 for (i
= 0; i
< 12; i
++)
8949 if (mask
& (1 << i
))
8960 else if (op
== 0xb2)
8962 unsigned char buf
[9];
8963 unsigned int i
, len
;
8964 unsigned long offset
;
8966 for (i
= 0; i
< sizeof (buf
); i
++)
8969 if ((buf
[i
] & 0x80) == 0)
8972 if (i
== sizeof (buf
))
8974 error (_("corrupt change to vsp\n"));
8979 offset
= read_leb128 (buf
, buf
+ i
+ 1, FALSE
, &len
, NULL
);
8980 assert (len
== i
+ 1);
8981 offset
= offset
* 4 + 0x204;
8982 printf ("vsp = vsp + %ld", offset
);
8985 else if (op
== 0xb3 || op
== 0xc8 || op
== 0xc9)
8987 unsigned int first
, last
;
8994 printf ("pop {D%d", first
);
8996 printf ("-D%d", first
+ last
);
8999 else if ((op
& 0xf8) == 0xb8 || (op
& 0xf8) == 0xd0)
9001 unsigned int count
= op
& 0x07;
9005 printf ("-D%d", 8 + count
);
9008 else if (op
>= 0xc0 && op
<= 0xc5)
9010 unsigned int count
= op
& 0x07;
9012 printf (" pop {wR10");
9014 printf ("-wR%d", 10 + count
);
9017 else if (op
== 0xc6)
9019 unsigned int first
, last
;
9024 printf ("pop {wR%d", first
);
9026 printf ("-wR%d", first
+ last
);
9029 else if (op
== 0xc7)
9032 if (op2
== 0 || (op2
& 0xf0) != 0)
9033 printf (_("[Spare]"));
9036 unsigned int mask
= op2
& 0x0f;
9037 bfd_boolean first
= TRUE
;
9041 for (i
= 0; i
< 4; i
++)
9042 if (mask
& (1 << i
))
9048 printf ("wCGR%d", i
);
9055 printf (_(" [unsupported opcode]"));
9066 decode_tic6x_unwind_bytecode (Filedata
* filedata
,
9067 struct arm_unw_aux_info
* aux
,
9069 unsigned int remaining
,
9070 unsigned int more_words
,
9071 bfd_vma data_offset
,
9072 Elf_Internal_Shdr
* data_sec
,
9073 struct arm_section
* data_arm_sec
)
9075 struct absaddr addr
;
9077 /* Decode the unwinding instructions. */
9080 unsigned int op
, op2
;
9089 printf (" 0x%02x ", op
);
9091 if ((op
& 0xc0) == 0x00)
9093 int offset
= ((op
& 0x3f) << 3) + 8;
9094 printf (" sp = sp + %d", offset
);
9096 else if ((op
& 0xc0) == 0x80)
9099 if (op
== 0x80 && op2
== 0)
9100 printf (_("Refuse to unwind"));
9103 unsigned int mask
= ((op
& 0x1f) << 8) | op2
;
9105 printf ("pop compact {");
9109 decode_tic6x_unwind_regmask (mask
);
9113 else if ((op
& 0xf0) == 0xc0)
9121 unsigned int offset
;
9125 /* Scan entire instruction first so that GET_OP output is not
9126 interleaved with disassembly. */
9128 for (i
= 0; nregs
< (op
& 0xf); i
++)
9134 regpos
[nregs
].offset
= i
* 2;
9135 regpos
[nregs
].reg
= reg
;
9142 regpos
[nregs
].offset
= i
* 2 + 1;
9143 regpos
[nregs
].reg
= reg
;
9148 printf (_("pop frame {"));
9151 printf (_("*corrupt* - no registers specified"));
9156 for (i
= i
* 2; i
> 0; i
--)
9158 if (regpos
[reg
].offset
== i
- 1)
9160 name
= tic6x_unwind_regnames
[regpos
[reg
].reg
];
9167 fputs (name
, stdout
);
9175 else if (op
== 0xd0)
9176 printf (" MOV FP, SP");
9177 else if (op
== 0xd1)
9178 printf (" __c6xabi_pop_rts");
9179 else if (op
== 0xd2)
9181 unsigned char buf
[9];
9182 unsigned int i
, len
;
9183 unsigned long offset
;
9185 for (i
= 0; i
< sizeof (buf
); i
++)
9188 if ((buf
[i
] & 0x80) == 0)
9191 /* PR 17531: file: id:000001,src:001906+004739,op:splice,rep:2. */
9192 if (i
== sizeof (buf
))
9194 warn (_("Corrupt stack pointer adjustment detected\n"));
9198 offset
= read_leb128 (buf
, buf
+ i
+ 1, FALSE
, &len
, NULL
);
9199 assert (len
== i
+ 1);
9200 offset
= offset
* 8 + 0x408;
9201 printf (_("sp = sp + %ld"), offset
);
9203 else if ((op
& 0xf0) == 0xe0)
9205 if ((op
& 0x0f) == 7)
9208 printf (" MV %s, B3", tic6x_unwind_regnames
[op
& 0x0f]);
9212 printf (_(" [unsupported opcode]"));
9221 arm_expand_prel31 (Filedata
* filedata
, bfd_vma word
, bfd_vma where
)
9225 offset
= word
& 0x7fffffff;
9226 if (offset
& 0x40000000)
9227 offset
|= ~ (bfd_vma
) 0x7fffffff;
9229 if (filedata
->file_header
.e_machine
== EM_TI_C6000
)
9232 return offset
+ where
;
9236 decode_arm_unwind (Filedata
* filedata
,
9237 struct arm_unw_aux_info
* aux
,
9239 unsigned int remaining
,
9240 bfd_vma data_offset
,
9241 Elf_Internal_Shdr
* data_sec
,
9242 struct arm_section
* data_arm_sec
)
9245 unsigned int more_words
= 0;
9246 struct absaddr addr
;
9247 bfd_vma sym_name
= (bfd_vma
) -1;
9248 bfd_boolean res
= TRUE
;
9252 /* Fetch the first word.
9253 Note - when decoding an object file the address extracted
9254 here will always be 0. So we also pass in the sym_name
9255 parameter so that we can find the symbol associated with
9256 the personality routine. */
9257 if (! get_unwind_section_word (filedata
, aux
, data_arm_sec
, data_sec
, data_offset
,
9258 & word
, & addr
, & sym_name
))
9265 addr
.section
= SHN_UNDEF
;
9269 if ((word
& 0x80000000) == 0)
9271 /* Expand prel31 for personality routine. */
9273 const char *procname
;
9275 fn
= arm_expand_prel31 (filedata
, word
, data_sec
->sh_addr
+ data_offset
);
9276 printf (_(" Personality routine: "));
9278 && addr
.section
== SHN_UNDEF
&& addr
.offset
== 0
9279 && sym_name
!= (bfd_vma
) -1 && sym_name
< aux
->strtab_size
)
9281 procname
= aux
->strtab
+ sym_name
;
9282 print_vma (fn
, PREFIX_HEX
);
9285 fputs (" <", stdout
);
9286 fputs (procname
, stdout
);
9287 fputc ('>', stdout
);
9291 procname
= arm_print_vma_and_name (filedata
, aux
, fn
, addr
);
9292 fputc ('\n', stdout
);
9294 /* The GCC personality routines use the standard compact
9295 encoding, starting with one byte giving the number of
9297 if (procname
!= NULL
9298 && (const_strneq (procname
, "__gcc_personality_v0")
9299 || const_strneq (procname
, "__gxx_personality_v0")
9300 || const_strneq (procname
, "__gcj_personality_v0")
9301 || const_strneq (procname
, "__gnu_objc_personality_v0")))
9308 printf (_(" [Truncated data]\n"));
9311 more_words
= word
>> 24;
9321 /* ARM EHABI Section 6.3:
9323 An exception-handling table entry for the compact model looks like:
9327 1 0 index Data for personalityRoutine[index] */
9329 if (filedata
->file_header
.e_machine
== EM_ARM
9330 && (word
& 0x70000000))
9332 warn (_("Corrupt ARM compact model table entry: %x \n"), word
);
9336 per_index
= (word
>> 24) & 0x7f;
9337 printf (_(" Compact model index: %d\n"), per_index
);
9344 else if (per_index
< 3)
9346 more_words
= (word
>> 16) & 0xff;
9352 switch (filedata
->file_header
.e_machine
)
9357 if (! decode_arm_unwind_bytecode (filedata
, aux
, word
, remaining
, more_words
,
9358 data_offset
, data_sec
, data_arm_sec
))
9363 warn (_("Unknown ARM compact model index encountered\n"));
9364 printf (_(" [reserved]\n"));
9372 if (! decode_tic6x_unwind_bytecode (filedata
, aux
, word
, remaining
, more_words
,
9373 data_offset
, data_sec
, data_arm_sec
))
9376 else if (per_index
< 5)
9378 if (((word
>> 17) & 0x7f) == 0x7f)
9379 printf (_(" Restore stack from frame pointer\n"));
9381 printf (_(" Stack increment %d\n"), (word
>> 14) & 0x1fc);
9382 printf (_(" Registers restored: "));
9384 printf (" (compact) ");
9385 decode_tic6x_unwind_regmask ((word
>> 4) & 0x1fff);
9387 printf (_(" Return register: %s\n"),
9388 tic6x_unwind_regnames
[word
& 0xf]);
9391 printf (_(" [reserved (%d)]\n"), per_index
);
9395 error (_("Unsupported architecture type %d encountered when decoding unwind table\n"),
9396 filedata
->file_header
.e_machine
);
9400 /* Decode the descriptors. Not implemented. */
9406 dump_arm_unwind (Filedata
* filedata
,
9407 struct arm_unw_aux_info
* aux
,
9408 Elf_Internal_Shdr
* exidx_sec
)
9410 struct arm_section exidx_arm_sec
, extab_arm_sec
;
9411 unsigned int i
, exidx_len
;
9412 unsigned long j
, nfuns
;
9413 bfd_boolean res
= TRUE
;
9415 memset (&exidx_arm_sec
, 0, sizeof (exidx_arm_sec
));
9416 memset (&extab_arm_sec
, 0, sizeof (extab_arm_sec
));
9417 exidx_len
= exidx_sec
->sh_size
/ 8;
9419 aux
->funtab
= xmalloc (aux
->nsyms
* sizeof (Elf_Internal_Sym
));
9420 for (nfuns
= 0, j
= 0; j
< aux
->nsyms
; j
++)
9421 if (aux
->symtab
[j
].st_value
&& ELF_ST_TYPE (aux
->symtab
[j
].st_info
) == STT_FUNC
)
9422 aux
->funtab
[nfuns
++] = aux
->symtab
[j
];
9424 qsort (aux
->funtab
, aux
->nfuns
, sizeof (Elf_Internal_Sym
), symcmp
);
9426 for (i
= 0; i
< exidx_len
; i
++)
9428 unsigned int exidx_fn
, exidx_entry
;
9429 struct absaddr fn_addr
, entry_addr
;
9432 fputc ('\n', stdout
);
9434 if (! get_unwind_section_word (filedata
, aux
, & exidx_arm_sec
, exidx_sec
,
9435 8 * i
, & exidx_fn
, & fn_addr
, NULL
)
9436 || ! get_unwind_section_word (filedata
, aux
, & exidx_arm_sec
, exidx_sec
,
9437 8 * i
+ 4, & exidx_entry
, & entry_addr
, NULL
))
9440 arm_free_section (& exidx_arm_sec
);
9441 arm_free_section (& extab_arm_sec
);
9445 /* ARM EHABI, Section 5:
9446 An index table entry consists of 2 words.
9447 The first word contains a prel31 offset to the start of a function, with bit 31 clear. */
9448 if (exidx_fn
& 0x80000000)
9450 warn (_("corrupt index table entry: %x\n"), exidx_fn
);
9454 fn
= arm_expand_prel31 (filedata
, exidx_fn
, exidx_sec
->sh_addr
+ 8 * i
);
9456 arm_print_vma_and_name (filedata
, aux
, fn
, fn_addr
);
9457 fputs (": ", stdout
);
9459 if (exidx_entry
== 1)
9461 print_vma (exidx_entry
, PREFIX_HEX
);
9462 fputs (" [cantunwind]\n", stdout
);
9464 else if (exidx_entry
& 0x80000000)
9466 print_vma (exidx_entry
, PREFIX_HEX
);
9467 fputc ('\n', stdout
);
9468 decode_arm_unwind (filedata
, aux
, exidx_entry
, 4, 0, NULL
, NULL
);
9472 bfd_vma table
, table_offset
= 0;
9473 Elf_Internal_Shdr
*table_sec
;
9475 fputs ("@", stdout
);
9476 table
= arm_expand_prel31 (filedata
, exidx_entry
, exidx_sec
->sh_addr
+ 8 * i
+ 4);
9477 print_vma (table
, PREFIX_HEX
);
9480 /* Locate the matching .ARM.extab. */
9481 if (entry_addr
.section
!= SHN_UNDEF
9482 && entry_addr
.section
< filedata
->file_header
.e_shnum
)
9484 table_sec
= filedata
->section_headers
+ entry_addr
.section
;
9485 table_offset
= entry_addr
.offset
;
9487 if (table_offset
> table_sec
->sh_size
9488 || ((bfd_signed_vma
) table_offset
) < 0)
9490 warn (_("Unwind entry contains corrupt offset (0x%lx) into section %s\n"),
9491 (unsigned long) table_offset
,
9492 printable_section_name (filedata
, table_sec
));
9499 table_sec
= find_section_by_address (filedata
, table
);
9500 if (table_sec
!= NULL
)
9501 table_offset
= table
- table_sec
->sh_addr
;
9504 if (table_sec
== NULL
)
9506 warn (_("Could not locate .ARM.extab section containing 0x%lx.\n"),
9507 (unsigned long) table
);
9512 if (! decode_arm_unwind (filedata
, aux
, 0, 0, table_offset
, table_sec
,
9521 arm_free_section (&exidx_arm_sec
);
9522 arm_free_section (&extab_arm_sec
);
9527 /* Used for both ARM and C6X unwinding tables. */
9530 arm_process_unwind (Filedata
* filedata
)
9532 struct arm_unw_aux_info aux
;
9533 Elf_Internal_Shdr
*unwsec
= NULL
;
9534 Elf_Internal_Shdr
*sec
;
9536 unsigned int sec_type
;
9537 bfd_boolean res
= TRUE
;
9539 switch (filedata
->file_header
.e_machine
)
9542 sec_type
= SHT_ARM_EXIDX
;
9546 sec_type
= SHT_C6000_UNWIND
;
9550 error (_("Unsupported architecture type %d encountered when processing unwind table\n"),
9551 filedata
->file_header
.e_machine
);
9555 if (filedata
->string_table
== NULL
)
9558 memset (& aux
, 0, sizeof (aux
));
9559 aux
.filedata
= filedata
;
9561 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
9563 if (sec
->sh_type
== SHT_SYMTAB
)
9567 error (_("Multiple symbol tables encountered\n"));
9573 if (!get_symtab (filedata
, sec
, &aux
.symtab
, &aux
.nsyms
,
9574 &aux
.strtab
, &aux
.strtab_size
))
9577 else if (sec
->sh_type
== sec_type
)
9582 printf (_("\nThere are no unwind sections in this file.\n"));
9584 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
9586 if (sec
->sh_type
== sec_type
)
9588 unsigned long num_unwind
= sec
->sh_size
/ (2 * eh_addr_size
);
9589 printf (ngettext ("\nUnwind section '%s' at offset 0x%lx "
9590 "contains %lu entry:\n",
9591 "\nUnwind section '%s' at offset 0x%lx "
9592 "contains %lu entries:\n",
9594 printable_section_name (filedata
, sec
),
9595 (unsigned long) sec
->sh_offset
,
9598 if (! dump_arm_unwind (filedata
, &aux
, sec
))
9604 free ((char *) aux
.strtab
);
9610 process_unwind (Filedata
* filedata
)
9612 struct unwind_handler
9614 unsigned int machtype
;
9615 bfd_boolean (* handler
)(Filedata
*);
9618 { EM_ARM
, arm_process_unwind
},
9619 { EM_IA_64
, ia64_process_unwind
},
9620 { EM_PARISC
, hppa_process_unwind
},
9621 { EM_TI_C6000
, arm_process_unwind
},
9629 for (i
= 0; handlers
[i
].handler
!= NULL
; i
++)
9630 if (filedata
->file_header
.e_machine
== handlers
[i
].machtype
)
9631 return handlers
[i
].handler (filedata
);
9633 printf (_("\nThe decoding of unwind sections for machine type %s is not currently supported.\n"),
9634 get_machine_name (filedata
->file_header
.e_machine
));
9639 dynamic_section_aarch64_val (Elf_Internal_Dyn
* entry
)
9641 switch (entry
->d_tag
)
9643 case DT_AARCH64_BTI_PLT
:
9644 case DT_AARCH64_PAC_PLT
:
9647 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
9654 dynamic_section_mips_val (Filedata
* filedata
, Elf_Internal_Dyn
* entry
)
9656 switch (entry
->d_tag
)
9659 if (entry
->d_un
.d_val
== 0)
9663 static const char * opts
[] =
9665 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
9666 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
9667 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
9668 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
9672 bfd_boolean first
= TRUE
;
9674 for (cnt
= 0; cnt
< ARRAY_SIZE (opts
); ++cnt
)
9675 if (entry
->d_un
.d_val
& (1 << cnt
))
9677 printf ("%s%s", first
? "" : " ", opts
[cnt
]);
9683 case DT_MIPS_IVERSION
:
9684 if (VALID_DYNAMIC_NAME (filedata
, entry
->d_un
.d_val
))
9685 printf (_("Interface Version: %s"),
9686 GET_DYNAMIC_NAME (filedata
, entry
->d_un
.d_val
));
9690 sprintf_vma (buf
, entry
->d_un
.d_ptr
);
9691 /* Note: coded this way so that there is a single string for translation. */
9692 printf (_("<corrupt: %s>"), buf
);
9696 case DT_MIPS_TIME_STAMP
:
9700 time_t atime
= entry
->d_un
.d_val
;
9702 tmp
= gmtime (&atime
);
9703 /* PR 17531: file: 6accc532. */
9705 snprintf (timebuf
, sizeof (timebuf
), _("<corrupt>"));
9707 snprintf (timebuf
, sizeof (timebuf
), "%04u-%02u-%02uT%02u:%02u:%02u",
9708 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
9709 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
9710 printf (_("Time Stamp: %s"), timebuf
);
9714 case DT_MIPS_RLD_VERSION
:
9715 case DT_MIPS_LOCAL_GOTNO
:
9716 case DT_MIPS_CONFLICTNO
:
9717 case DT_MIPS_LIBLISTNO
:
9718 case DT_MIPS_SYMTABNO
:
9719 case DT_MIPS_UNREFEXTNO
:
9720 case DT_MIPS_HIPAGENO
:
9721 case DT_MIPS_DELTA_CLASS_NO
:
9722 case DT_MIPS_DELTA_INSTANCE_NO
:
9723 case DT_MIPS_DELTA_RELOC_NO
:
9724 case DT_MIPS_DELTA_SYM_NO
:
9725 case DT_MIPS_DELTA_CLASSSYM_NO
:
9726 case DT_MIPS_COMPACT_SIZE
:
9727 print_vma (entry
->d_un
.d_val
, DEC
);
9731 filedata
->dynamic_info_DT_MIPS_XHASH
= entry
->d_un
.d_val
;
9732 filedata
->dynamic_info_DT_GNU_HASH
= entry
->d_un
.d_val
;
9733 /* Falls through. */
9736 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
9742 dynamic_section_parisc_val (Elf_Internal_Dyn
* entry
)
9744 switch (entry
->d_tag
)
9746 case DT_HP_DLD_FLAGS
:
9755 { DT_HP_DEBUG_PRIVATE
, "HP_DEBUG_PRIVATE" },
9756 { DT_HP_DEBUG_CALLBACK
, "HP_DEBUG_CALLBACK" },
9757 { DT_HP_DEBUG_CALLBACK_BOR
, "HP_DEBUG_CALLBACK_BOR" },
9758 { DT_HP_NO_ENVVAR
, "HP_NO_ENVVAR" },
9759 { DT_HP_BIND_NOW
, "HP_BIND_NOW" },
9760 { DT_HP_BIND_NONFATAL
, "HP_BIND_NONFATAL" },
9761 { DT_HP_BIND_VERBOSE
, "HP_BIND_VERBOSE" },
9762 { DT_HP_BIND_RESTRICTED
, "HP_BIND_RESTRICTED" },
9763 { DT_HP_BIND_SYMBOLIC
, "HP_BIND_SYMBOLIC" },
9764 { DT_HP_RPATH_FIRST
, "HP_RPATH_FIRST" },
9765 { DT_HP_BIND_DEPTH_FIRST
, "HP_BIND_DEPTH_FIRST" },
9766 { DT_HP_GST
, "HP_GST" },
9767 { DT_HP_SHLIB_FIXED
, "HP_SHLIB_FIXED" },
9768 { DT_HP_MERGE_SHLIB_SEG
, "HP_MERGE_SHLIB_SEG" },
9769 { DT_HP_NODELETE
, "HP_NODELETE" },
9770 { DT_HP_GROUP
, "HP_GROUP" },
9771 { DT_HP_PROTECT_LINKAGE_TABLE
, "HP_PROTECT_LINKAGE_TABLE" }
9773 bfd_boolean first
= TRUE
;
9775 bfd_vma val
= entry
->d_un
.d_val
;
9777 for (cnt
= 0; cnt
< ARRAY_SIZE (flags
); ++cnt
)
9778 if (val
& flags
[cnt
].bit
)
9782 fputs (flags
[cnt
].str
, stdout
);
9784 val
^= flags
[cnt
].bit
;
9787 if (val
!= 0 || first
)
9791 print_vma (val
, HEX
);
9797 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
9805 /* VMS vs Unix time offset and factor. */
9807 #define VMS_EPOCH_OFFSET 35067168000000000LL
9808 #define VMS_GRANULARITY_FACTOR 10000000
9810 /* Display a VMS time in a human readable format. */
9813 print_vms_time (bfd_int64_t vmstime
)
9818 unxtime
= (vmstime
- VMS_EPOCH_OFFSET
) / VMS_GRANULARITY_FACTOR
;
9819 tm
= gmtime (&unxtime
);
9820 printf ("%04u-%02u-%02uT%02u:%02u:%02u",
9821 tm
->tm_year
+ 1900, tm
->tm_mon
+ 1, tm
->tm_mday
,
9822 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
);
9827 dynamic_section_ia64_val (Elf_Internal_Dyn
* entry
)
9829 switch (entry
->d_tag
)
9831 case DT_IA_64_PLT_RESERVE
:
9832 /* First 3 slots reserved. */
9833 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
9835 print_vma (entry
->d_un
.d_ptr
+ (3 * 8), PREFIX_HEX
);
9838 case DT_IA_64_VMS_LINKTIME
:
9840 print_vms_time (entry
->d_un
.d_val
);
9844 case DT_IA_64_VMS_LNKFLAGS
:
9845 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
9846 if (entry
->d_un
.d_val
& VMS_LF_CALL_DEBUG
)
9847 printf (" CALL_DEBUG");
9848 if (entry
->d_un
.d_val
& VMS_LF_NOP0BUFS
)
9849 printf (" NOP0BUFS");
9850 if (entry
->d_un
.d_val
& VMS_LF_P0IMAGE
)
9851 printf (" P0IMAGE");
9852 if (entry
->d_un
.d_val
& VMS_LF_MKTHREADS
)
9853 printf (" MKTHREADS");
9854 if (entry
->d_un
.d_val
& VMS_LF_UPCALLS
)
9855 printf (" UPCALLS");
9856 if (entry
->d_un
.d_val
& VMS_LF_IMGSTA
)
9858 if (entry
->d_un
.d_val
& VMS_LF_INITIALIZE
)
9859 printf (" INITIALIZE");
9860 if (entry
->d_un
.d_val
& VMS_LF_MAIN
)
9862 if (entry
->d_un
.d_val
& VMS_LF_EXE_INIT
)
9863 printf (" EXE_INIT");
9864 if (entry
->d_un
.d_val
& VMS_LF_TBK_IN_IMG
)
9865 printf (" TBK_IN_IMG");
9866 if (entry
->d_un
.d_val
& VMS_LF_DBG_IN_IMG
)
9867 printf (" DBG_IN_IMG");
9868 if (entry
->d_un
.d_val
& VMS_LF_TBK_IN_DSF
)
9869 printf (" TBK_IN_DSF");
9870 if (entry
->d_un
.d_val
& VMS_LF_DBG_IN_DSF
)
9871 printf (" DBG_IN_DSF");
9872 if (entry
->d_un
.d_val
& VMS_LF_SIGNATURES
)
9873 printf (" SIGNATURES");
9874 if (entry
->d_un
.d_val
& VMS_LF_REL_SEG_OFF
)
9875 printf (" REL_SEG_OFF");
9879 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
9886 get_32bit_dynamic_section (Filedata
* filedata
)
9888 Elf32_External_Dyn
* edyn
;
9889 Elf32_External_Dyn
* ext
;
9890 Elf_Internal_Dyn
* entry
;
9892 edyn
= (Elf32_External_Dyn
*) get_data (NULL
, filedata
,
9893 filedata
->dynamic_addr
, 1,
9894 filedata
->dynamic_size
,
9895 _("dynamic section"));
9899 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
9900 might not have the luxury of section headers. Look for the DT_NULL
9901 terminator to determine the number of entries. */
9902 for (ext
= edyn
, filedata
->dynamic_nent
= 0;
9903 (char *) (ext
+ 1) <= (char *) edyn
+ filedata
->dynamic_size
;
9906 filedata
->dynamic_nent
++;
9907 if (BYTE_GET (ext
->d_tag
) == DT_NULL
)
9911 filedata
->dynamic_section
9912 = (Elf_Internal_Dyn
*) cmalloc (filedata
->dynamic_nent
, sizeof (* entry
));
9913 if (filedata
->dynamic_section
== NULL
)
9915 error (_("Out of memory allocating space for %lu dynamic entries\n"),
9916 (unsigned long) filedata
->dynamic_nent
);
9921 for (ext
= edyn
, entry
= filedata
->dynamic_section
;
9922 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
9925 entry
->d_tag
= BYTE_GET (ext
->d_tag
);
9926 entry
->d_un
.d_val
= BYTE_GET (ext
->d_un
.d_val
);
9935 get_64bit_dynamic_section (Filedata
* filedata
)
9937 Elf64_External_Dyn
* edyn
;
9938 Elf64_External_Dyn
* ext
;
9939 Elf_Internal_Dyn
* entry
;
9941 /* Read in the data. */
9942 edyn
= (Elf64_External_Dyn
*) get_data (NULL
, filedata
,
9943 filedata
->dynamic_addr
, 1,
9944 filedata
->dynamic_size
,
9945 _("dynamic section"));
9949 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
9950 might not have the luxury of section headers. Look for the DT_NULL
9951 terminator to determine the number of entries. */
9952 for (ext
= edyn
, filedata
->dynamic_nent
= 0;
9953 /* PR 17533 file: 033-67080-0.004 - do not read past end of buffer. */
9954 (char *) (ext
+ 1) <= (char *) edyn
+ filedata
->dynamic_size
;
9957 filedata
->dynamic_nent
++;
9958 if (BYTE_GET (ext
->d_tag
) == DT_NULL
)
9962 filedata
->dynamic_section
9963 = (Elf_Internal_Dyn
*) cmalloc (filedata
->dynamic_nent
, sizeof (* entry
));
9964 if (filedata
->dynamic_section
== NULL
)
9966 error (_("Out of memory allocating space for %lu dynamic entries\n"),
9967 (unsigned long) filedata
->dynamic_nent
);
9972 /* Convert from external to internal formats. */
9973 for (ext
= edyn
, entry
= filedata
->dynamic_section
;
9974 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
9977 entry
->d_tag
= BYTE_GET (ext
->d_tag
);
9978 entry
->d_un
.d_val
= BYTE_GET (ext
->d_un
.d_val
);
9987 print_dynamic_flags (bfd_vma flags
)
9989 bfd_boolean first
= TRUE
;
9995 flag
= flags
& - flags
;
10001 putc (' ', stdout
);
10005 case DF_ORIGIN
: fputs ("ORIGIN", stdout
); break;
10006 case DF_SYMBOLIC
: fputs ("SYMBOLIC", stdout
); break;
10007 case DF_TEXTREL
: fputs ("TEXTREL", stdout
); break;
10008 case DF_BIND_NOW
: fputs ("BIND_NOW", stdout
); break;
10009 case DF_STATIC_TLS
: fputs ("STATIC_TLS", stdout
); break;
10010 default: fputs (_("unknown"), stdout
); break;
10017 get_dynamic_data (Filedata
* filedata
, bfd_size_type number
, unsigned int ent_size
)
10019 unsigned char * e_data
;
10022 /* If the size_t type is smaller than the bfd_size_type, eg because
10023 you are building a 32-bit tool on a 64-bit host, then make sure
10024 that when (number) is cast to (size_t) no information is lost. */
10025 if (sizeof (size_t) < sizeof (bfd_size_type
)
10026 && (bfd_size_type
) ((size_t) number
) != number
)
10028 error (_("Size truncation prevents reading %s elements of size %u\n"),
10029 bfd_vmatoa ("u", number
), ent_size
);
10033 /* Be kind to memory checkers (eg valgrind, address sanitizer) by not
10034 attempting to allocate memory when the read is bound to fail. */
10035 if (ent_size
* number
> filedata
->file_size
)
10037 error (_("Invalid number of dynamic entries: %s\n"),
10038 bfd_vmatoa ("u", number
));
10042 e_data
= (unsigned char *) cmalloc ((size_t) number
, ent_size
);
10043 if (e_data
== NULL
)
10045 error (_("Out of memory reading %s dynamic entries\n"),
10046 bfd_vmatoa ("u", number
));
10050 if (fread (e_data
, ent_size
, (size_t) number
, filedata
->handle
) != number
)
10052 error (_("Unable to read in %s bytes of dynamic data\n"),
10053 bfd_vmatoa ("u", number
* ent_size
));
10058 i_data
= (bfd_vma
*) cmalloc ((size_t) number
, sizeof (*i_data
));
10059 if (i_data
== NULL
)
10061 error (_("Out of memory allocating space for %s dynamic entries\n"),
10062 bfd_vmatoa ("u", number
));
10068 i_data
[number
] = byte_get (e_data
+ number
* ent_size
, ent_size
);
10075 static unsigned long
10076 get_num_dynamic_syms (Filedata
* filedata
)
10078 unsigned long num_of_syms
= 0;
10080 if (!do_histogram
&& (!do_using_dynamic
|| do_dyn_syms
))
10081 return num_of_syms
;
10083 if (filedata
->dynamic_info
[DT_HASH
])
10085 unsigned char nb
[8];
10086 unsigned char nc
[8];
10087 unsigned int hash_ent_size
= 4;
10089 if ((filedata
->file_header
.e_machine
== EM_ALPHA
10090 || filedata
->file_header
.e_machine
== EM_S390
10091 || filedata
->file_header
.e_machine
== EM_S390_OLD
)
10092 && filedata
->file_header
.e_ident
[EI_CLASS
] == ELFCLASS64
)
10095 if (fseek (filedata
->handle
,
10096 (filedata
->archive_file_offset
10097 + offset_from_vma (filedata
, filedata
->dynamic_info
[DT_HASH
],
10098 sizeof nb
+ sizeof nc
)),
10101 error (_("Unable to seek to start of dynamic information\n"));
10105 if (fread (nb
, hash_ent_size
, 1, filedata
->handle
) != 1)
10107 error (_("Failed to read in number of buckets\n"));
10111 if (fread (nc
, hash_ent_size
, 1, filedata
->handle
) != 1)
10113 error (_("Failed to read in number of chains\n"));
10117 filedata
->nbuckets
= byte_get (nb
, hash_ent_size
);
10118 filedata
->nchains
= byte_get (nc
, hash_ent_size
);
10120 if (filedata
->nbuckets
!= 0 && filedata
->nchains
!= 0)
10122 filedata
->buckets
= get_dynamic_data (filedata
, filedata
->nbuckets
,
10124 filedata
->chains
= get_dynamic_data (filedata
, filedata
->nchains
,
10127 if (filedata
->buckets
!= NULL
&& filedata
->chains
!= NULL
)
10128 num_of_syms
= filedata
->nchains
;
10131 if (num_of_syms
== 0)
10133 free (filedata
->buckets
);
10134 filedata
->buckets
= NULL
;
10135 free (filedata
->chains
);
10136 filedata
->chains
= NULL
;
10137 filedata
->nbuckets
= 0;
10141 if (filedata
->dynamic_info_DT_GNU_HASH
)
10143 unsigned char nb
[16];
10144 bfd_vma i
, maxchain
= 0xffffffff, bitmaskwords
;
10145 bfd_vma buckets_vma
;
10148 if (fseek (filedata
->handle
,
10149 (filedata
->archive_file_offset
10150 + offset_from_vma (filedata
,
10151 filedata
->dynamic_info_DT_GNU_HASH
,
10155 error (_("Unable to seek to start of dynamic information\n"));
10159 if (fread (nb
, 16, 1, filedata
->handle
) != 1)
10161 error (_("Failed to read in number of buckets\n"));
10165 filedata
->ngnubuckets
= byte_get (nb
, 4);
10166 filedata
->gnusymidx
= byte_get (nb
+ 4, 4);
10167 bitmaskwords
= byte_get (nb
+ 8, 4);
10168 buckets_vma
= filedata
->dynamic_info_DT_GNU_HASH
+ 16;
10170 buckets_vma
+= bitmaskwords
* 4;
10172 buckets_vma
+= bitmaskwords
* 8;
10174 if (fseek (filedata
->handle
,
10175 (filedata
->archive_file_offset
10176 + offset_from_vma (filedata
, buckets_vma
, 4)),
10179 error (_("Unable to seek to start of dynamic information\n"));
10183 filedata
->gnubuckets
10184 = get_dynamic_data (filedata
, filedata
->ngnubuckets
, 4);
10186 if (filedata
->gnubuckets
== NULL
)
10189 for (i
= 0; i
< filedata
->ngnubuckets
; i
++)
10190 if (filedata
->gnubuckets
[i
] != 0)
10192 if (filedata
->gnubuckets
[i
] < filedata
->gnusymidx
)
10195 if (maxchain
== 0xffffffff || filedata
->gnubuckets
[i
] > maxchain
)
10196 maxchain
= filedata
->gnubuckets
[i
];
10199 if (maxchain
== 0xffffffff)
10202 maxchain
-= filedata
->gnusymidx
;
10204 if (fseek (filedata
->handle
,
10205 (filedata
->archive_file_offset
10206 + offset_from_vma (filedata
,
10207 buckets_vma
+ 4 * (filedata
->ngnubuckets
10212 error (_("Unable to seek to start of dynamic information\n"));
10218 if (fread (nb
, 4, 1, filedata
->handle
) != 1)
10220 error (_("Failed to determine last chain length\n"));
10224 if (maxchain
+ 1 == 0)
10229 while ((byte_get (nb
, 4) & 1) == 0);
10231 if (fseek (filedata
->handle
,
10232 (filedata
->archive_file_offset
10233 + offset_from_vma (filedata
, (buckets_vma
10234 + 4 * filedata
->ngnubuckets
),
10238 error (_("Unable to seek to start of dynamic information\n"));
10242 filedata
->gnuchains
= get_dynamic_data (filedata
, maxchain
, 4);
10243 filedata
->ngnuchains
= maxchain
;
10245 if (filedata
->gnuchains
== NULL
)
10248 if (filedata
->dynamic_info_DT_MIPS_XHASH
)
10250 if (fseek (filedata
->handle
,
10251 (filedata
->archive_file_offset
10252 + offset_from_vma (filedata
, (buckets_vma
10253 + 4 * (filedata
->ngnubuckets
10257 error (_("Unable to seek to start of dynamic information\n"));
10261 filedata
->mipsxlat
= get_dynamic_data (filedata
, maxchain
, 4);
10262 if (filedata
->mipsxlat
== NULL
)
10266 for (hn
= 0; hn
< filedata
->ngnubuckets
; ++hn
)
10267 if (filedata
->gnubuckets
[hn
] != 0)
10269 bfd_vma si
= filedata
->gnubuckets
[hn
];
10270 bfd_vma off
= si
- filedata
->gnusymidx
;
10274 if (filedata
->dynamic_info_DT_MIPS_XHASH
)
10276 if (off
< filedata
->ngnuchains
10277 && filedata
->mipsxlat
[off
] >= num_of_syms
)
10278 num_of_syms
= filedata
->mipsxlat
[off
] + 1;
10282 if (si
>= num_of_syms
)
10283 num_of_syms
= si
+ 1;
10287 while (off
< filedata
->ngnuchains
10288 && (filedata
->gnuchains
[off
++] & 1) == 0);
10291 if (num_of_syms
== 0)
10294 free (filedata
->mipsxlat
);
10295 filedata
->mipsxlat
= NULL
;
10296 free (filedata
->gnuchains
);
10297 filedata
->gnuchains
= NULL
;
10298 free (filedata
->gnubuckets
);
10299 filedata
->gnubuckets
= NULL
;
10300 filedata
->ngnubuckets
= 0;
10301 filedata
->ngnuchains
= 0;
10305 return num_of_syms
;
10308 /* Parse and display the contents of the dynamic section. */
10311 process_dynamic_section (Filedata
* filedata
)
10313 Elf_Internal_Dyn
* entry
;
10315 if (filedata
->dynamic_size
== 0)
10318 printf (_("\nThere is no dynamic section in this file.\n"));
10325 if (! get_32bit_dynamic_section (filedata
))
10330 if (! get_64bit_dynamic_section (filedata
))
10334 /* Find the appropriate symbol table. */
10335 if (filedata
->dynamic_symbols
== NULL
|| do_histogram
)
10337 unsigned long num_of_syms
;
10339 for (entry
= filedata
->dynamic_section
;
10340 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
10342 if (entry
->d_tag
== DT_SYMTAB
)
10343 filedata
->dynamic_info
[DT_SYMTAB
] = entry
->d_un
.d_val
;
10344 else if (entry
->d_tag
== DT_SYMENT
)
10345 filedata
->dynamic_info
[DT_SYMENT
] = entry
->d_un
.d_val
;
10346 else if (entry
->d_tag
== DT_HASH
)
10347 filedata
->dynamic_info
[DT_HASH
] = entry
->d_un
.d_val
;
10348 else if (entry
->d_tag
== DT_GNU_HASH
)
10349 filedata
->dynamic_info_DT_GNU_HASH
= entry
->d_un
.d_val
;
10350 else if ((filedata
->file_header
.e_machine
== EM_MIPS
10351 || filedata
->file_header
.e_machine
== EM_MIPS_RS3_LE
)
10352 && entry
->d_tag
== DT_MIPS_XHASH
)
10354 filedata
->dynamic_info_DT_MIPS_XHASH
= entry
->d_un
.d_val
;
10355 filedata
->dynamic_info_DT_GNU_HASH
= entry
->d_un
.d_val
;
10358 num_of_syms
= get_num_dynamic_syms (filedata
);
10360 if (num_of_syms
!= 0
10361 && filedata
->dynamic_symbols
== NULL
10362 && filedata
->dynamic_info
[DT_SYMTAB
]
10363 && filedata
->dynamic_info
[DT_SYMENT
])
10365 Elf_Internal_Phdr
*seg
;
10366 bfd_vma vma
= filedata
->dynamic_info
[DT_SYMTAB
];
10368 if (! get_program_headers (filedata
))
10370 error (_("Cannot interpret virtual addresses "
10371 "without program headers.\n"));
10375 for (seg
= filedata
->program_headers
;
10376 seg
< filedata
->program_headers
+ filedata
->file_header
.e_phnum
;
10379 if (seg
->p_type
!= PT_LOAD
)
10382 if (seg
->p_offset
+ seg
->p_filesz
> filedata
->file_size
)
10384 /* See PR 21379 for a reproducer. */
10385 error (_("Invalid PT_LOAD entry\n"));
10389 if (vma
>= (seg
->p_vaddr
& -seg
->p_align
)
10390 && vma
< seg
->p_vaddr
+ seg
->p_filesz
)
10392 /* Since we do not know how big the symbol table is,
10393 we default to reading in up to the end of PT_LOAD
10394 segment and processing that. This is overkill, I
10395 know, but it should work. */
10396 Elf_Internal_Shdr section
;
10397 section
.sh_offset
= (vma
- seg
->p_vaddr
10399 section
.sh_size
= (num_of_syms
10400 * filedata
->dynamic_info
[DT_SYMENT
]);
10401 section
.sh_entsize
= filedata
->dynamic_info
[DT_SYMENT
];
10404 && filedata
->dynamic_symtab_section
!= NULL
10405 && ((filedata
->dynamic_symtab_section
->sh_offset
10406 != section
.sh_offset
)
10407 || (filedata
->dynamic_symtab_section
->sh_size
10408 != section
.sh_size
)
10409 || (filedata
->dynamic_symtab_section
->sh_entsize
10410 != section
.sh_entsize
)))
10412 the .dynsym section doesn't match the DT_SYMTAB and DT_SYMENT tags\n"));
10414 section
.sh_name
= filedata
->string_table_length
;
10415 filedata
->dynamic_symbols
10416 = GET_ELF_SYMBOLS (filedata
, §ion
,
10417 &filedata
->num_dynamic_syms
);
10418 if (filedata
->dynamic_symbols
== NULL
10419 || filedata
->num_dynamic_syms
!= num_of_syms
)
10421 error (_("Corrupt DT_SYMTAB dynamic entry\n"));
10430 /* Similarly find a string table. */
10431 if (filedata
->dynamic_strings
== NULL
)
10432 for (entry
= filedata
->dynamic_section
;
10433 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
10436 if (entry
->d_tag
== DT_STRTAB
)
10437 filedata
->dynamic_info
[DT_STRTAB
] = entry
->d_un
.d_val
;
10439 if (entry
->d_tag
== DT_STRSZ
)
10440 filedata
->dynamic_info
[DT_STRSZ
] = entry
->d_un
.d_val
;
10442 if (filedata
->dynamic_info
[DT_STRTAB
]
10443 && filedata
->dynamic_info
[DT_STRSZ
])
10445 unsigned long offset
;
10446 bfd_size_type str_tab_len
= filedata
->dynamic_info
[DT_STRSZ
];
10448 offset
= offset_from_vma (filedata
,
10449 filedata
->dynamic_info
[DT_STRTAB
],
10452 && filedata
->dynamic_strtab_section
10453 && ((filedata
->dynamic_strtab_section
->sh_offset
10454 != (file_ptr
) offset
)
10455 || (filedata
->dynamic_strtab_section
->sh_size
10458 the .dynstr section doesn't match the DT_STRTAB and DT_STRSZ tags\n"));
10460 filedata
->dynamic_strings
10461 = (char *) get_data (NULL
, filedata
, offset
, 1, str_tab_len
,
10462 _("dynamic string table"));
10463 if (filedata
->dynamic_strings
== NULL
)
10465 error (_("Corrupt DT_STRTAB dynamic entry\n"));
10469 filedata
->dynamic_strings_length
= str_tab_len
;
10474 /* And find the syminfo section if available. */
10475 if (filedata
->dynamic_syminfo
== NULL
)
10477 unsigned long syminsz
= 0;
10479 for (entry
= filedata
->dynamic_section
;
10480 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
10483 if (entry
->d_tag
== DT_SYMINENT
)
10485 /* Note: these braces are necessary to avoid a syntax
10486 error from the SunOS4 C compiler. */
10487 /* PR binutils/17531: A corrupt file can trigger this test.
10488 So do not use an assert, instead generate an error message. */
10489 if (sizeof (Elf_External_Syminfo
) != entry
->d_un
.d_val
)
10490 error (_("Bad value (%d) for SYMINENT entry\n"),
10491 (int) entry
->d_un
.d_val
);
10493 else if (entry
->d_tag
== DT_SYMINSZ
)
10494 syminsz
= entry
->d_un
.d_val
;
10495 else if (entry
->d_tag
== DT_SYMINFO
)
10496 filedata
->dynamic_syminfo_offset
10497 = offset_from_vma (filedata
, entry
->d_un
.d_val
, syminsz
);
10500 if (filedata
->dynamic_syminfo_offset
!= 0 && syminsz
!= 0)
10502 Elf_External_Syminfo
* extsyminfo
;
10503 Elf_External_Syminfo
* extsym
;
10504 Elf_Internal_Syminfo
* syminfo
;
10506 /* There is a syminfo section. Read the data. */
10507 extsyminfo
= (Elf_External_Syminfo
*)
10508 get_data (NULL
, filedata
, filedata
->dynamic_syminfo_offset
,
10509 1, syminsz
, _("symbol information"));
10513 if (filedata
->dynamic_syminfo
!= NULL
)
10515 error (_("Multiple dynamic symbol information sections found\n"));
10516 free (filedata
->dynamic_syminfo
);
10518 filedata
->dynamic_syminfo
= (Elf_Internal_Syminfo
*) malloc (syminsz
);
10519 if (filedata
->dynamic_syminfo
== NULL
)
10521 error (_("Out of memory allocating %lu bytes "
10522 "for dynamic symbol info\n"),
10523 (unsigned long) syminsz
);
10527 filedata
->dynamic_syminfo_nent
10528 = syminsz
/ sizeof (Elf_External_Syminfo
);
10529 for (syminfo
= filedata
->dynamic_syminfo
, extsym
= extsyminfo
;
10530 syminfo
< (filedata
->dynamic_syminfo
10531 + filedata
->dynamic_syminfo_nent
);
10532 ++syminfo
, ++extsym
)
10534 syminfo
->si_boundto
= BYTE_GET (extsym
->si_boundto
);
10535 syminfo
->si_flags
= BYTE_GET (extsym
->si_flags
);
10542 if (do_dynamic
&& filedata
->dynamic_addr
)
10543 printf (ngettext ("\nDynamic section at offset 0x%lx "
10544 "contains %lu entry:\n",
10545 "\nDynamic section at offset 0x%lx "
10546 "contains %lu entries:\n",
10547 filedata
->dynamic_nent
),
10548 filedata
->dynamic_addr
, (unsigned long) filedata
->dynamic_nent
);
10550 printf (_(" Tag Type Name/Value\n"));
10552 for (entry
= filedata
->dynamic_section
;
10553 entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
;
10558 const char * dtype
;
10561 print_vma (entry
->d_tag
, FULL_HEX
);
10562 dtype
= get_dynamic_type (filedata
, entry
->d_tag
);
10563 printf (" (%s)%*s", dtype
,
10564 ((is_32bit_elf
? 27 : 19) - (int) strlen (dtype
)), " ");
10567 switch (entry
->d_tag
)
10571 print_dynamic_flags (entry
->d_un
.d_val
);
10581 switch (entry
->d_tag
)
10584 printf (_("Auxiliary library"));
10588 printf (_("Filter library"));
10592 printf (_("Configuration file"));
10596 printf (_("Dependency audit library"));
10600 printf (_("Audit library"));
10604 if (VALID_DYNAMIC_NAME (filedata
, entry
->d_un
.d_val
))
10605 printf (": [%s]\n",
10606 GET_DYNAMIC_NAME (filedata
, entry
->d_un
.d_val
));
10610 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
10619 printf (_("Flags:"));
10621 if (entry
->d_un
.d_val
== 0)
10622 printf (_(" None\n"));
10625 unsigned long int val
= entry
->d_un
.d_val
;
10627 if (val
& DTF_1_PARINIT
)
10629 printf (" PARINIT");
10630 val
^= DTF_1_PARINIT
;
10632 if (val
& DTF_1_CONFEXP
)
10634 printf (" CONFEXP");
10635 val
^= DTF_1_CONFEXP
;
10638 printf (" %lx", val
);
10647 printf (_("Flags:"));
10649 if (entry
->d_un
.d_val
== 0)
10650 printf (_(" None\n"));
10653 unsigned long int val
= entry
->d_un
.d_val
;
10655 if (val
& DF_P1_LAZYLOAD
)
10657 printf (" LAZYLOAD");
10658 val
^= DF_P1_LAZYLOAD
;
10660 if (val
& DF_P1_GROUPPERM
)
10662 printf (" GROUPPERM");
10663 val
^= DF_P1_GROUPPERM
;
10666 printf (" %lx", val
);
10675 printf (_("Flags:"));
10676 if (entry
->d_un
.d_val
== 0)
10677 printf (_(" None\n"));
10680 unsigned long int val
= entry
->d_un
.d_val
;
10682 if (val
& DF_1_NOW
)
10687 if (val
& DF_1_GLOBAL
)
10689 printf (" GLOBAL");
10690 val
^= DF_1_GLOBAL
;
10692 if (val
& DF_1_GROUP
)
10697 if (val
& DF_1_NODELETE
)
10699 printf (" NODELETE");
10700 val
^= DF_1_NODELETE
;
10702 if (val
& DF_1_LOADFLTR
)
10704 printf (" LOADFLTR");
10705 val
^= DF_1_LOADFLTR
;
10707 if (val
& DF_1_INITFIRST
)
10709 printf (" INITFIRST");
10710 val
^= DF_1_INITFIRST
;
10712 if (val
& DF_1_NOOPEN
)
10714 printf (" NOOPEN");
10715 val
^= DF_1_NOOPEN
;
10717 if (val
& DF_1_ORIGIN
)
10719 printf (" ORIGIN");
10720 val
^= DF_1_ORIGIN
;
10722 if (val
& DF_1_DIRECT
)
10724 printf (" DIRECT");
10725 val
^= DF_1_DIRECT
;
10727 if (val
& DF_1_TRANS
)
10732 if (val
& DF_1_INTERPOSE
)
10734 printf (" INTERPOSE");
10735 val
^= DF_1_INTERPOSE
;
10737 if (val
& DF_1_NODEFLIB
)
10739 printf (" NODEFLIB");
10740 val
^= DF_1_NODEFLIB
;
10742 if (val
& DF_1_NODUMP
)
10744 printf (" NODUMP");
10745 val
^= DF_1_NODUMP
;
10747 if (val
& DF_1_CONFALT
)
10749 printf (" CONFALT");
10750 val
^= DF_1_CONFALT
;
10752 if (val
& DF_1_ENDFILTEE
)
10754 printf (" ENDFILTEE");
10755 val
^= DF_1_ENDFILTEE
;
10757 if (val
& DF_1_DISPRELDNE
)
10759 printf (" DISPRELDNE");
10760 val
^= DF_1_DISPRELDNE
;
10762 if (val
& DF_1_DISPRELPND
)
10764 printf (" DISPRELPND");
10765 val
^= DF_1_DISPRELPND
;
10767 if (val
& DF_1_NODIRECT
)
10769 printf (" NODIRECT");
10770 val
^= DF_1_NODIRECT
;
10772 if (val
& DF_1_IGNMULDEF
)
10774 printf (" IGNMULDEF");
10775 val
^= DF_1_IGNMULDEF
;
10777 if (val
& DF_1_NOKSYMS
)
10779 printf (" NOKSYMS");
10780 val
^= DF_1_NOKSYMS
;
10782 if (val
& DF_1_NOHDR
)
10787 if (val
& DF_1_EDITED
)
10789 printf (" EDITED");
10790 val
^= DF_1_EDITED
;
10792 if (val
& DF_1_NORELOC
)
10794 printf (" NORELOC");
10795 val
^= DF_1_NORELOC
;
10797 if (val
& DF_1_SYMINTPOSE
)
10799 printf (" SYMINTPOSE");
10800 val
^= DF_1_SYMINTPOSE
;
10802 if (val
& DF_1_GLOBAUDIT
)
10804 printf (" GLOBAUDIT");
10805 val
^= DF_1_GLOBAUDIT
;
10807 if (val
& DF_1_SINGLETON
)
10809 printf (" SINGLETON");
10810 val
^= DF_1_SINGLETON
;
10812 if (val
& DF_1_STUB
)
10817 if (val
& DF_1_PIE
)
10822 if (val
& DF_1_KMOD
)
10827 if (val
& DF_1_WEAKFILTER
)
10829 printf (" WEAKFILTER");
10830 val
^= DF_1_WEAKFILTER
;
10832 if (val
& DF_1_NOCOMMON
)
10834 printf (" NOCOMMON");
10835 val
^= DF_1_NOCOMMON
;
10838 printf (" %lx", val
);
10845 filedata
->dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
10847 puts (get_dynamic_type (filedata
, entry
->d_un
.d_val
));
10867 filedata
->dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
10873 if (VALID_DYNAMIC_NAME (filedata
, entry
->d_un
.d_val
))
10874 name
= GET_DYNAMIC_NAME (filedata
, entry
->d_un
.d_val
);
10880 switch (entry
->d_tag
)
10883 printf (_("Shared library: [%s]"), name
);
10885 if (streq (name
, filedata
->program_interpreter
))
10886 printf (_(" program interpreter"));
10890 printf (_("Library soname: [%s]"), name
);
10894 printf (_("Library rpath: [%s]"), name
);
10898 printf (_("Library runpath: [%s]"), name
);
10902 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
10907 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
10920 filedata
->dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
10921 /* Fall through. */
10925 case DT_INIT_ARRAYSZ
:
10926 case DT_FINI_ARRAYSZ
:
10927 case DT_GNU_CONFLICTSZ
:
10928 case DT_GNU_LIBLISTSZ
:
10931 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
10932 printf (_(" (bytes)\n"));
10937 case DT_VERNEEDNUM
:
10942 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
10951 case DT_INIT_ARRAY
:
10952 case DT_FINI_ARRAY
:
10955 if (entry
->d_tag
== DT_USED
10956 && VALID_DYNAMIC_NAME (filedata
, entry
->d_un
.d_val
))
10958 char * name
= GET_DYNAMIC_NAME (filedata
, entry
->d_un
.d_val
);
10962 printf (_("Not needed object: [%s]\n"), name
);
10967 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
10973 /* The value of this entry is ignored. */
10978 case DT_GNU_PRELINKED
:
10982 time_t atime
= entry
->d_un
.d_val
;
10984 tmp
= gmtime (&atime
);
10985 /* PR 17533 file: 041-1244816-0.004. */
10987 printf (_("<corrupt time val: %lx"),
10988 (unsigned long) atime
);
10990 printf ("%04u-%02u-%02uT%02u:%02u:%02u\n",
10991 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
10992 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
10998 filedata
->dynamic_info_DT_GNU_HASH
= entry
->d_un
.d_val
;
11001 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
11007 if ((entry
->d_tag
>= DT_VERSYM
) && (entry
->d_tag
<= DT_VERNEEDNUM
))
11008 filedata
->version_info
[DT_VERSIONTAGIDX (entry
->d_tag
)]
11009 = entry
->d_un
.d_val
;
11013 switch (filedata
->file_header
.e_machine
)
11016 dynamic_section_aarch64_val (entry
);
11019 case EM_MIPS_RS3_LE
:
11020 dynamic_section_mips_val (filedata
, entry
);
11023 dynamic_section_parisc_val (entry
);
11026 dynamic_section_ia64_val (entry
);
11029 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
11041 get_ver_flags (unsigned int flags
)
11043 static char buff
[128];
11050 if (flags
& VER_FLG_BASE
)
11051 strcat (buff
, "BASE");
11053 if (flags
& VER_FLG_WEAK
)
11055 if (flags
& VER_FLG_BASE
)
11056 strcat (buff
, " | ");
11058 strcat (buff
, "WEAK");
11061 if (flags
& VER_FLG_INFO
)
11063 if (flags
& (VER_FLG_BASE
|VER_FLG_WEAK
))
11064 strcat (buff
, " | ");
11066 strcat (buff
, "INFO");
11069 if (flags
& ~(VER_FLG_BASE
| VER_FLG_WEAK
| VER_FLG_INFO
))
11071 if (flags
& (VER_FLG_BASE
| VER_FLG_WEAK
| VER_FLG_INFO
))
11072 strcat (buff
, " | ");
11074 strcat (buff
, _("<unknown>"));
11080 /* Display the contents of the version sections. */
11083 process_version_sections (Filedata
* filedata
)
11085 Elf_Internal_Shdr
* section
;
11087 bfd_boolean found
= FALSE
;
11092 for (i
= 0, section
= filedata
->section_headers
;
11093 i
< filedata
->file_header
.e_shnum
;
11096 switch (section
->sh_type
)
11098 case SHT_GNU_verdef
:
11100 Elf_External_Verdef
* edefs
;
11107 printf (ngettext ("\nVersion definition section '%s' "
11108 "contains %u entry:\n",
11109 "\nVersion definition section '%s' "
11110 "contains %u entries:\n",
11112 printable_section_name (filedata
, section
),
11115 printf (_(" Addr: 0x"));
11116 printf_vma (section
->sh_addr
);
11117 printf (_(" Offset: %#08lx Link: %u (%s)\n"),
11118 (unsigned long) section
->sh_offset
, section
->sh_link
,
11119 printable_section_name_from_index (filedata
, section
->sh_link
));
11121 edefs
= (Elf_External_Verdef
*)
11122 get_data (NULL
, filedata
, section
->sh_offset
, 1,section
->sh_size
,
11123 _("version definition section"));
11126 endbuf
= (char *) edefs
+ section
->sh_size
;
11128 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
11131 Elf_External_Verdef
* edef
;
11132 Elf_Internal_Verdef ent
;
11133 Elf_External_Verdaux
* eaux
;
11134 Elf_Internal_Verdaux aux
;
11135 unsigned long isum
;
11138 vstart
= ((char *) edefs
) + idx
;
11139 if (vstart
+ sizeof (*edef
) > endbuf
)
11142 edef
= (Elf_External_Verdef
*) vstart
;
11144 ent
.vd_version
= BYTE_GET (edef
->vd_version
);
11145 ent
.vd_flags
= BYTE_GET (edef
->vd_flags
);
11146 ent
.vd_ndx
= BYTE_GET (edef
->vd_ndx
);
11147 ent
.vd_cnt
= BYTE_GET (edef
->vd_cnt
);
11148 ent
.vd_hash
= BYTE_GET (edef
->vd_hash
);
11149 ent
.vd_aux
= BYTE_GET (edef
->vd_aux
);
11150 ent
.vd_next
= BYTE_GET (edef
->vd_next
);
11152 printf (_(" %#06lx: Rev: %d Flags: %s"),
11153 idx
, ent
.vd_version
, get_ver_flags (ent
.vd_flags
));
11155 printf (_(" Index: %d Cnt: %d "),
11156 ent
.vd_ndx
, ent
.vd_cnt
);
11158 /* Check for overflow. */
11159 if (ent
.vd_aux
> (size_t) (endbuf
- vstart
))
11162 vstart
+= ent
.vd_aux
;
11164 if (vstart
+ sizeof (*eaux
) > endbuf
)
11166 eaux
= (Elf_External_Verdaux
*) vstart
;
11168 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
11169 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
11171 if (VALID_DYNAMIC_NAME (filedata
, aux
.vda_name
))
11172 printf (_("Name: %s\n"),
11173 GET_DYNAMIC_NAME (filedata
, aux
.vda_name
));
11175 printf (_("Name index: %ld\n"), aux
.vda_name
);
11177 isum
= idx
+ ent
.vd_aux
;
11179 for (j
= 1; j
< ent
.vd_cnt
; j
++)
11181 if (aux
.vda_next
< sizeof (*eaux
)
11182 && !(j
== ent
.vd_cnt
- 1 && aux
.vda_next
== 0))
11184 warn (_("Invalid vda_next field of %lx\n"),
11189 /* Check for overflow. */
11190 if (aux
.vda_next
> (size_t) (endbuf
- vstart
))
11193 isum
+= aux
.vda_next
;
11194 vstart
+= aux
.vda_next
;
11196 if (vstart
+ sizeof (*eaux
) > endbuf
)
11198 eaux
= (Elf_External_Verdaux
*) vstart
;
11200 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
11201 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
11203 if (VALID_DYNAMIC_NAME (filedata
, aux
.vda_name
))
11204 printf (_(" %#06lx: Parent %d: %s\n"),
11206 GET_DYNAMIC_NAME (filedata
, aux
.vda_name
));
11208 printf (_(" %#06lx: Parent %d, name index: %ld\n"),
11209 isum
, j
, aux
.vda_name
);
11212 if (j
< ent
.vd_cnt
)
11213 printf (_(" Version def aux past end of section\n"));
11216 file: id:000001,src:000172+005151,op:splice,rep:2. */
11217 if (ent
.vd_next
< sizeof (*edef
)
11218 && !(cnt
== section
->sh_info
- 1 && ent
.vd_next
== 0))
11220 warn (_("Invalid vd_next field of %lx\n"), ent
.vd_next
);
11221 cnt
= section
->sh_info
;
11224 if (ent
.vd_next
> (size_t) (endbuf
- ((char *) edefs
+ idx
)))
11227 idx
+= ent
.vd_next
;
11230 if (cnt
< section
->sh_info
)
11231 printf (_(" Version definition past end of section\n"));
11237 case SHT_GNU_verneed
:
11239 Elf_External_Verneed
* eneed
;
11246 printf (ngettext ("\nVersion needs section '%s' "
11247 "contains %u entry:\n",
11248 "\nVersion needs section '%s' "
11249 "contains %u entries:\n",
11251 printable_section_name (filedata
, section
), section
->sh_info
);
11253 printf (_(" Addr: 0x"));
11254 printf_vma (section
->sh_addr
);
11255 printf (_(" Offset: %#08lx Link: %u (%s)\n"),
11256 (unsigned long) section
->sh_offset
, section
->sh_link
,
11257 printable_section_name_from_index (filedata
, section
->sh_link
));
11259 eneed
= (Elf_External_Verneed
*) get_data (NULL
, filedata
,
11260 section
->sh_offset
, 1,
11262 _("Version Needs section"));
11265 endbuf
= (char *) eneed
+ section
->sh_size
;
11267 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
11269 Elf_External_Verneed
* entry
;
11270 Elf_Internal_Verneed ent
;
11271 unsigned long isum
;
11275 vstart
= ((char *) eneed
) + idx
;
11276 if (vstart
+ sizeof (*entry
) > endbuf
)
11279 entry
= (Elf_External_Verneed
*) vstart
;
11281 ent
.vn_version
= BYTE_GET (entry
->vn_version
);
11282 ent
.vn_cnt
= BYTE_GET (entry
->vn_cnt
);
11283 ent
.vn_file
= BYTE_GET (entry
->vn_file
);
11284 ent
.vn_aux
= BYTE_GET (entry
->vn_aux
);
11285 ent
.vn_next
= BYTE_GET (entry
->vn_next
);
11287 printf (_(" %#06lx: Version: %d"), idx
, ent
.vn_version
);
11289 if (VALID_DYNAMIC_NAME (filedata
, ent
.vn_file
))
11290 printf (_(" File: %s"),
11291 GET_DYNAMIC_NAME (filedata
, ent
.vn_file
));
11293 printf (_(" File: %lx"), ent
.vn_file
);
11295 printf (_(" Cnt: %d\n"), ent
.vn_cnt
);
11297 /* Check for overflow. */
11298 if (ent
.vn_aux
> (size_t) (endbuf
- vstart
))
11300 vstart
+= ent
.vn_aux
;
11302 for (j
= 0, isum
= idx
+ ent
.vn_aux
; j
< ent
.vn_cnt
; ++j
)
11304 Elf_External_Vernaux
* eaux
;
11305 Elf_Internal_Vernaux aux
;
11307 if (vstart
+ sizeof (*eaux
) > endbuf
)
11309 eaux
= (Elf_External_Vernaux
*) vstart
;
11311 aux
.vna_hash
= BYTE_GET (eaux
->vna_hash
);
11312 aux
.vna_flags
= BYTE_GET (eaux
->vna_flags
);
11313 aux
.vna_other
= BYTE_GET (eaux
->vna_other
);
11314 aux
.vna_name
= BYTE_GET (eaux
->vna_name
);
11315 aux
.vna_next
= BYTE_GET (eaux
->vna_next
);
11317 if (VALID_DYNAMIC_NAME (filedata
, aux
.vna_name
))
11318 printf (_(" %#06lx: Name: %s"),
11319 isum
, GET_DYNAMIC_NAME (filedata
, aux
.vna_name
));
11321 printf (_(" %#06lx: Name index: %lx"),
11322 isum
, aux
.vna_name
);
11324 printf (_(" Flags: %s Version: %d\n"),
11325 get_ver_flags (aux
.vna_flags
), aux
.vna_other
);
11327 if (aux
.vna_next
< sizeof (*eaux
)
11328 && !(j
== ent
.vn_cnt
- 1 && aux
.vna_next
== 0))
11330 warn (_("Invalid vna_next field of %lx\n"),
11335 /* Check for overflow. */
11336 if (aux
.vna_next
> (size_t) (endbuf
- vstart
))
11338 isum
+= aux
.vna_next
;
11339 vstart
+= aux
.vna_next
;
11342 if (j
< ent
.vn_cnt
)
11343 warn (_("Missing Version Needs auxillary information\n"));
11345 if (ent
.vn_next
< sizeof (*entry
)
11346 && !(cnt
== section
->sh_info
- 1 && ent
.vn_next
== 0))
11348 warn (_("Invalid vn_next field of %lx\n"), ent
.vn_next
);
11349 cnt
= section
->sh_info
;
11352 if (ent
.vn_next
> (size_t) (endbuf
- ((char *) eneed
+ idx
)))
11354 idx
+= ent
.vn_next
;
11357 if (cnt
< section
->sh_info
)
11358 warn (_("Missing Version Needs information\n"));
11364 case SHT_GNU_versym
:
11366 Elf_Internal_Shdr
* link_section
;
11369 unsigned char * edata
;
11370 unsigned short * data
;
11372 Elf_Internal_Sym
* symbols
;
11373 Elf_Internal_Shdr
* string_sec
;
11374 unsigned long num_syms
;
11377 if (section
->sh_link
>= filedata
->file_header
.e_shnum
)
11380 link_section
= filedata
->section_headers
+ section
->sh_link
;
11381 total
= section
->sh_size
/ sizeof (Elf_External_Versym
);
11383 if (link_section
->sh_link
>= filedata
->file_header
.e_shnum
)
11388 symbols
= GET_ELF_SYMBOLS (filedata
, link_section
, & num_syms
);
11389 if (symbols
== NULL
)
11392 string_sec
= filedata
->section_headers
+ link_section
->sh_link
;
11394 strtab
= (char *) get_data (NULL
, filedata
, string_sec
->sh_offset
, 1,
11395 string_sec
->sh_size
,
11396 _("version string table"));
11403 printf (ngettext ("\nVersion symbols section '%s' "
11404 "contains %lu entry:\n",
11405 "\nVersion symbols section '%s' "
11406 "contains %lu entries:\n",
11408 printable_section_name (filedata
, section
), (unsigned long) total
);
11410 printf (_(" Addr: 0x"));
11411 printf_vma (section
->sh_addr
);
11412 printf (_(" Offset: %#08lx Link: %u (%s)\n"),
11413 (unsigned long) section
->sh_offset
, section
->sh_link
,
11414 printable_section_name (filedata
, link_section
));
11416 off
= offset_from_vma (filedata
,
11417 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)],
11418 total
* sizeof (short));
11419 edata
= (unsigned char *) get_data (NULL
, filedata
, off
,
11420 sizeof (short), total
,
11421 _("version symbol data"));
11429 data
= (short unsigned int *) cmalloc (total
, sizeof (short));
11431 for (cnt
= total
; cnt
--;)
11432 data
[cnt
] = byte_get (edata
+ cnt
* sizeof (short),
11437 for (cnt
= 0; cnt
< total
; cnt
+= 4)
11441 char *invalid
= _("*invalid*");
11443 printf (" %03x:", cnt
);
11445 for (j
= 0; (j
< 4) && (cnt
+ j
) < total
; ++j
)
11446 switch (data
[cnt
+ j
])
11449 fputs (_(" 0 (*local*) "), stdout
);
11453 fputs (_(" 1 (*global*) "), stdout
);
11457 nn
= printf ("%4x%c", data
[cnt
+ j
] & VERSYM_VERSION
,
11458 data
[cnt
+ j
] & VERSYM_HIDDEN
? 'h' : ' ');
11460 /* If this index value is greater than the size of the symbols
11461 array, break to avoid an out-of-bounds read. */
11462 if ((unsigned long)(cnt
+ j
) >= num_syms
)
11464 warn (_("invalid index into symbol array\n"));
11469 if (filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)])
11471 Elf_Internal_Verneed ivn
;
11472 unsigned long offset
;
11474 offset
= offset_from_vma
11476 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)],
11477 sizeof (Elf_External_Verneed
));
11481 Elf_Internal_Vernaux ivna
;
11482 Elf_External_Verneed evn
;
11483 Elf_External_Vernaux evna
;
11484 unsigned long a_off
;
11486 if (get_data (&evn
, filedata
, offset
, sizeof (evn
), 1,
11487 _("version need")) == NULL
)
11490 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
11491 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
11493 a_off
= offset
+ ivn
.vn_aux
;
11497 if (get_data (&evna
, filedata
, a_off
, sizeof (evna
),
11498 1, _("version need aux (2)")) == NULL
)
11501 ivna
.vna_other
= 0;
11505 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
11506 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
11509 a_off
+= ivna
.vna_next
;
11511 while (ivna
.vna_other
!= data
[cnt
+ j
]
11512 && ivna
.vna_next
!= 0);
11514 if (ivna
.vna_other
== data
[cnt
+ j
])
11516 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
11518 if (ivna
.vna_name
>= string_sec
->sh_size
)
11521 name
= strtab
+ ivna
.vna_name
;
11525 offset
+= ivn
.vn_next
;
11527 while (ivn
.vn_next
);
11530 if (data
[cnt
+ j
] != 0x8001
11531 && filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
11533 Elf_Internal_Verdef ivd
;
11534 Elf_External_Verdef evd
;
11535 unsigned long offset
;
11537 offset
= offset_from_vma
11539 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)],
11544 if (get_data (&evd
, filedata
, offset
, sizeof (evd
), 1,
11545 _("version def")) == NULL
)
11548 /* PR 17531: file: 046-1082287-0.004. */
11549 ivd
.vd_ndx
= (data
[cnt
+ j
] & VERSYM_VERSION
) + 1;
11554 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
11555 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
11558 offset
+= ivd
.vd_next
;
11560 while (ivd
.vd_ndx
!= (data
[cnt
+ j
] & VERSYM_VERSION
)
11561 && ivd
.vd_next
!= 0);
11563 if (ivd
.vd_ndx
== (data
[cnt
+ j
] & VERSYM_VERSION
))
11565 Elf_External_Verdaux evda
;
11566 Elf_Internal_Verdaux ivda
;
11568 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
11570 if (get_data (&evda
, filedata
,
11571 offset
- ivd
.vd_next
+ ivd
.vd_aux
,
11573 _("version def aux")) == NULL
)
11576 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
11578 if (ivda
.vda_name
>= string_sec
->sh_size
)
11580 else if (name
!= NULL
&& name
!= invalid
)
11581 name
= _("*both*");
11583 name
= strtab
+ ivda
.vda_name
;
11587 nn
+= printf ("(%s%-*s",
11589 12 - (int) strlen (name
),
11593 printf ("%*c", 18 - nn
, ' ');
11611 printf (_("\nNo version information found in this file.\n"));
11616 static const char *
11617 get_symbol_binding (Filedata
* filedata
, unsigned int binding
)
11619 static char buff
[64];
11623 case STB_LOCAL
: return "LOCAL";
11624 case STB_GLOBAL
: return "GLOBAL";
11625 case STB_WEAK
: return "WEAK";
11627 if (binding
>= STB_LOPROC
&& binding
<= STB_HIPROC
)
11628 snprintf (buff
, sizeof (buff
), _("<processor specific>: %d"),
11630 else if (binding
>= STB_LOOS
&& binding
<= STB_HIOS
)
11632 if (binding
== STB_GNU_UNIQUE
11633 && filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_GNU
)
11635 snprintf (buff
, sizeof (buff
), _("<OS specific>: %d"), binding
);
11638 snprintf (buff
, sizeof (buff
), _("<unknown>: %d"), binding
);
11643 static const char *
11644 get_symbol_type (Filedata
* filedata
, unsigned int type
)
11646 static char buff
[64];
11650 case STT_NOTYPE
: return "NOTYPE";
11651 case STT_OBJECT
: return "OBJECT";
11652 case STT_FUNC
: return "FUNC";
11653 case STT_SECTION
: return "SECTION";
11654 case STT_FILE
: return "FILE";
11655 case STT_COMMON
: return "COMMON";
11656 case STT_TLS
: return "TLS";
11657 case STT_RELC
: return "RELC";
11658 case STT_SRELC
: return "SRELC";
11660 if (type
>= STT_LOPROC
&& type
<= STT_HIPROC
)
11662 if (filedata
->file_header
.e_machine
== EM_ARM
&& type
== STT_ARM_TFUNC
)
11663 return "THUMB_FUNC";
11665 if (filedata
->file_header
.e_machine
== EM_SPARCV9
&& type
== STT_REGISTER
)
11668 if (filedata
->file_header
.e_machine
== EM_PARISC
&& type
== STT_PARISC_MILLI
)
11669 return "PARISC_MILLI";
11671 snprintf (buff
, sizeof (buff
), _("<processor specific>: %d"), type
);
11673 else if (type
>= STT_LOOS
&& type
<= STT_HIOS
)
11675 if (filedata
->file_header
.e_machine
== EM_PARISC
)
11677 if (type
== STT_HP_OPAQUE
)
11678 return "HP_OPAQUE";
11679 if (type
== STT_HP_STUB
)
11683 if (type
== STT_GNU_IFUNC
11684 && (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_GNU
11685 || filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_FREEBSD
))
11688 snprintf (buff
, sizeof (buff
), _("<OS specific>: %d"), type
);
11691 snprintf (buff
, sizeof (buff
), _("<unknown>: %d"), type
);
11696 static const char *
11697 get_symbol_visibility (unsigned int visibility
)
11699 switch (visibility
)
11701 case STV_DEFAULT
: return "DEFAULT";
11702 case STV_INTERNAL
: return "INTERNAL";
11703 case STV_HIDDEN
: return "HIDDEN";
11704 case STV_PROTECTED
: return "PROTECTED";
11706 error (_("Unrecognized visibility value: %u\n"), visibility
);
11707 return _("<unknown>");
11711 static const char *
11712 get_alpha_symbol_other (unsigned int other
)
11716 case STO_ALPHA_NOPV
: return "NOPV";
11717 case STO_ALPHA_STD_GPLOAD
: return "STD GPLOAD";
11719 error (_("Unrecognized alpha specific other value: %u\n"), other
);
11720 return _("<unknown>");
11724 static const char *
11725 get_solaris_symbol_visibility (unsigned int visibility
)
11727 switch (visibility
)
11729 case 4: return "EXPORTED";
11730 case 5: return "SINGLETON";
11731 case 6: return "ELIMINATE";
11732 default: return get_symbol_visibility (visibility
);
11736 static const char *
11737 get_aarch64_symbol_other (unsigned int other
)
11739 static char buf
[32];
11741 if (other
& STO_AARCH64_VARIANT_PCS
)
11743 other
&= ~STO_AARCH64_VARIANT_PCS
;
11745 return "VARIANT_PCS";
11746 snprintf (buf
, sizeof buf
, "VARIANT_PCS | %x", other
);
11752 static const char *
11753 get_mips_symbol_other (unsigned int other
)
11757 case STO_OPTIONAL
: return "OPTIONAL";
11758 case STO_MIPS_PLT
: return "MIPS PLT";
11759 case STO_MIPS_PIC
: return "MIPS PIC";
11760 case STO_MICROMIPS
: return "MICROMIPS";
11761 case STO_MICROMIPS
| STO_MIPS_PIC
: return "MICROMIPS, MIPS PIC";
11762 case STO_MIPS16
: return "MIPS16";
11763 default: return NULL
;
11767 static const char *
11768 get_ia64_symbol_other (Filedata
* filedata
, unsigned int other
)
11770 if (is_ia64_vms (filedata
))
11772 static char res
[32];
11776 /* Function types is for images and .STB files only. */
11777 switch (filedata
->file_header
.e_type
)
11781 switch (VMS_ST_FUNC_TYPE (other
))
11783 case VMS_SFT_CODE_ADDR
:
11784 strcat (res
, " CA");
11786 case VMS_SFT_SYMV_IDX
:
11787 strcat (res
, " VEC");
11790 strcat (res
, " FD");
11792 case VMS_SFT_RESERVE
:
11793 strcat (res
, " RSV");
11796 warn (_("Unrecognized IA64 VMS ST Function type: %d\n"),
11797 VMS_ST_FUNC_TYPE (other
));
11798 strcat (res
, " <unknown>");
11805 switch (VMS_ST_LINKAGE (other
))
11807 case VMS_STL_IGNORE
:
11808 strcat (res
, " IGN");
11810 case VMS_STL_RESERVE
:
11811 strcat (res
, " RSV");
11814 strcat (res
, " STD");
11817 strcat (res
, " LNK");
11820 warn (_("Unrecognized IA64 VMS ST Linkage: %d\n"),
11821 VMS_ST_LINKAGE (other
));
11822 strcat (res
, " <unknown>");
11834 static const char *
11835 get_ppc64_symbol_other (unsigned int other
)
11837 if ((other
& ~STO_PPC64_LOCAL_MASK
) != 0)
11840 other
>>= STO_PPC64_LOCAL_BIT
;
11843 static char buf
[64];
11845 other
= ppc64_decode_local_entry (other
);
11846 snprintf (buf
, sizeof buf
, _("<localentry>: %d"), other
);
11852 static const char *
11853 get_symbol_other (Filedata
* filedata
, unsigned int other
)
11855 const char * result
= NULL
;
11856 static char buff
[64];
11861 switch (filedata
->file_header
.e_machine
)
11864 result
= get_alpha_symbol_other (other
);
11867 result
= get_aarch64_symbol_other (other
);
11870 result
= get_mips_symbol_other (other
);
11873 result
= get_ia64_symbol_other (filedata
, other
);
11876 result
= get_ppc64_symbol_other (other
);
11886 snprintf (buff
, sizeof buff
, _("<other>: %x"), other
);
11890 static const char *
11891 get_symbol_index_type (Filedata
* filedata
, unsigned int type
)
11893 static char buff
[32];
11897 case SHN_UNDEF
: return "UND";
11898 case SHN_ABS
: return "ABS";
11899 case SHN_COMMON
: return "COM";
11901 if (type
== SHN_IA_64_ANSI_COMMON
11902 && filedata
->file_header
.e_machine
== EM_IA_64
11903 && filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_HPUX
)
11905 else if ((filedata
->file_header
.e_machine
== EM_X86_64
11906 || filedata
->file_header
.e_machine
== EM_L1OM
11907 || filedata
->file_header
.e_machine
== EM_K1OM
)
11908 && type
== SHN_X86_64_LCOMMON
)
11909 return "LARGE_COM";
11910 else if ((type
== SHN_MIPS_SCOMMON
11911 && filedata
->file_header
.e_machine
== EM_MIPS
)
11912 || (type
== SHN_TIC6X_SCOMMON
11913 && filedata
->file_header
.e_machine
== EM_TI_C6000
))
11915 else if (type
== SHN_MIPS_SUNDEFINED
11916 && filedata
->file_header
.e_machine
== EM_MIPS
)
11918 else if (type
>= SHN_LOPROC
&& type
<= SHN_HIPROC
)
11919 sprintf (buff
, "PRC[0x%04x]", type
& 0xffff);
11920 else if (type
>= SHN_LOOS
&& type
<= SHN_HIOS
)
11921 sprintf (buff
, "OS [0x%04x]", type
& 0xffff);
11922 else if (type
>= SHN_LORESERVE
)
11923 sprintf (buff
, "RSV[0x%04x]", type
& 0xffff);
11924 else if (filedata
->file_header
.e_shnum
!= 0
11925 && type
>= filedata
->file_header
.e_shnum
)
11926 sprintf (buff
, _("bad section index[%3d]"), type
);
11928 sprintf (buff
, "%3d", type
);
11935 static const char *
11936 get_symbol_version_string (Filedata
* filedata
,
11937 bfd_boolean is_dynsym
,
11938 const char * strtab
,
11939 unsigned long int strtab_size
,
11941 Elf_Internal_Sym
* psym
,
11942 enum versioned_symbol_info
* sym_info
,
11943 unsigned short * vna_other
)
11945 unsigned char data
[2];
11946 unsigned short vers_data
;
11947 unsigned long offset
;
11948 unsigned short max_vd_ndx
;
11951 || filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)] == 0)
11954 offset
= offset_from_vma (filedata
,
11955 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)],
11956 sizeof data
+ si
* sizeof (vers_data
));
11958 if (get_data (&data
, filedata
, offset
+ si
* sizeof (vers_data
),
11959 sizeof (data
), 1, _("version data")) == NULL
)
11962 vers_data
= byte_get (data
, 2);
11964 if ((vers_data
& VERSYM_HIDDEN
) == 0 && vers_data
== 0)
11967 *sym_info
= (vers_data
& VERSYM_HIDDEN
) != 0 ? symbol_hidden
: symbol_public
;
11970 /* Usually we'd only see verdef for defined symbols, and verneed for
11971 undefined symbols. However, symbols defined by the linker in
11972 .dynbss for variables copied from a shared library in order to
11973 avoid text relocations are defined yet have verneed. We could
11974 use a heuristic to detect the special case, for example, check
11975 for verneed first on symbols defined in SHT_NOBITS sections, but
11976 it is simpler and more reliable to just look for both verdef and
11977 verneed. .dynbss might not be mapped to a SHT_NOBITS section. */
11979 if (psym
->st_shndx
!= SHN_UNDEF
11980 && vers_data
!= 0x8001
11981 && filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
11983 Elf_Internal_Verdef ivd
;
11984 Elf_Internal_Verdaux ivda
;
11985 Elf_External_Verdaux evda
;
11988 off
= offset_from_vma (filedata
,
11989 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)],
11990 sizeof (Elf_External_Verdef
));
11994 Elf_External_Verdef evd
;
11996 if (get_data (&evd
, filedata
, off
, sizeof (evd
), 1,
11997 _("version def")) == NULL
)
12006 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
12007 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
12008 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
12009 ivd
.vd_flags
= BYTE_GET (evd
.vd_flags
);
12012 if ((ivd
.vd_ndx
& VERSYM_VERSION
) > max_vd_ndx
)
12013 max_vd_ndx
= ivd
.vd_ndx
& VERSYM_VERSION
;
12015 off
+= ivd
.vd_next
;
12017 while (ivd
.vd_ndx
!= (vers_data
& VERSYM_VERSION
) && ivd
.vd_next
!= 0);
12019 if (ivd
.vd_ndx
== (vers_data
& VERSYM_VERSION
))
12021 if (ivd
.vd_ndx
== 1 && ivd
.vd_flags
== VER_FLG_BASE
)
12024 off
-= ivd
.vd_next
;
12027 if (get_data (&evda
, filedata
, off
, sizeof (evda
), 1,
12028 _("version def aux")) != NULL
)
12030 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
12032 if (psym
->st_name
!= ivda
.vda_name
)
12033 return (ivda
.vda_name
< strtab_size
12034 ? strtab
+ ivda
.vda_name
: _("<corrupt>"));
12039 if (filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)])
12041 Elf_External_Verneed evn
;
12042 Elf_Internal_Verneed ivn
;
12043 Elf_Internal_Vernaux ivna
;
12045 offset
= offset_from_vma (filedata
,
12046 filedata
->version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)],
12050 unsigned long vna_off
;
12052 if (get_data (&evn
, filedata
, offset
, sizeof (evn
), 1,
12053 _("version need")) == NULL
)
12056 ivna
.vna_other
= 0;
12061 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
12062 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
12064 vna_off
= offset
+ ivn
.vn_aux
;
12068 Elf_External_Vernaux evna
;
12070 if (get_data (&evna
, filedata
, vna_off
, sizeof (evna
), 1,
12071 _("version need aux (3)")) == NULL
)
12074 ivna
.vna_other
= 0;
12079 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
12080 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
12081 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
12084 vna_off
+= ivna
.vna_next
;
12086 while (ivna
.vna_other
!= vers_data
&& ivna
.vna_next
!= 0);
12088 if (ivna
.vna_other
== vers_data
)
12091 offset
+= ivn
.vn_next
;
12093 while (ivn
.vn_next
!= 0);
12095 if (ivna
.vna_other
== vers_data
)
12097 *sym_info
= symbol_undefined
;
12098 *vna_other
= ivna
.vna_other
;
12099 return (ivna
.vna_name
< strtab_size
12100 ? strtab
+ ivna
.vna_name
: _("<corrupt>"));
12102 else if ((max_vd_ndx
|| (vers_data
& VERSYM_VERSION
) != 1)
12103 && (vers_data
& VERSYM_VERSION
) > max_vd_ndx
)
12104 return _("<corrupt>");
12110 print_dynamic_symbol (Filedata
*filedata
, unsigned long si
,
12111 Elf_Internal_Sym
*symtab
,
12112 Elf_Internal_Shdr
*section
,
12113 char *strtab
, size_t strtab_size
)
12115 const char *version_string
;
12116 enum versioned_symbol_info sym_info
;
12117 unsigned short vna_other
;
12118 Elf_Internal_Sym
*psym
= symtab
+ si
;
12120 printf ("%6ld: ", si
);
12121 print_vma (psym
->st_value
, LONG_HEX
);
12123 print_vma (psym
->st_size
, DEC_5
);
12124 printf (" %-7s", get_symbol_type (filedata
, ELF_ST_TYPE (psym
->st_info
)));
12125 printf (" %-6s", get_symbol_binding (filedata
, ELF_ST_BIND (psym
->st_info
)));
12126 if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_SOLARIS
)
12127 printf (" %-7s", get_solaris_symbol_visibility (psym
->st_other
));
12130 unsigned int vis
= ELF_ST_VISIBILITY (psym
->st_other
);
12132 printf (" %-7s", get_symbol_visibility (vis
));
12133 /* Check to see if any other bits in the st_other field are set.
12134 Note - displaying this information disrupts the layout of the
12135 table being generated, but for the moment this case is very rare. */
12136 if (psym
->st_other
^ vis
)
12137 printf (" [%s] ", get_symbol_other (filedata
, psym
->st_other
^ vis
));
12139 printf (" %4s ", get_symbol_index_type (filedata
, psym
->st_shndx
));
12141 bfd_boolean is_valid
= VALID_SYMBOL_NAME (strtab
, strtab_size
,
12143 const char * sstr
= is_valid
? strtab
+ psym
->st_name
: _("<corrupt>");
12146 = get_symbol_version_string (filedata
,
12148 || section
->sh_type
== SHT_DYNSYM
),
12149 strtab
, strtab_size
, si
,
12150 psym
, &sym_info
, &vna_other
);
12152 int len_avail
= 21;
12153 if (! do_wide
&& version_string
!= NULL
)
12157 len_avail
-= 1 + strlen (version_string
);
12159 if (sym_info
== symbol_undefined
)
12160 len_avail
-= sprintf (buffer
," (%d)", vna_other
);
12161 else if (sym_info
!= symbol_hidden
)
12165 print_symbol (len_avail
, sstr
);
12167 if (version_string
)
12169 if (sym_info
== symbol_undefined
)
12170 printf ("@%s (%d)", version_string
, vna_other
);
12172 printf (sym_info
== symbol_hidden
? "@%s" : "@@%s",
12178 if (ELF_ST_BIND (psym
->st_info
) == STB_LOCAL
12180 && si
>= section
->sh_info
12181 /* Irix 5 and 6 MIPS binaries are known to ignore this requirement. */
12182 && filedata
->file_header
.e_machine
!= EM_MIPS
12183 /* Solaris binaries have been found to violate this requirement as
12184 well. Not sure if this is a bug or an ABI requirement. */
12185 && filedata
->file_header
.e_ident
[EI_OSABI
] != ELFOSABI_SOLARIS
)
12186 warn (_("local symbol %lu found at index >= %s's sh_info value of %u\n"),
12187 si
, printable_section_name (filedata
, section
), section
->sh_info
);
12190 static const char *
12191 get_lto_kind (unsigned int kind
)
12195 case 0: return "DEF";
12196 case 1: return "WEAKDEF";
12197 case 2: return "UNDEF";
12198 case 3: return "WEAKUNDEF";
12199 case 4: return "COMMON";
12204 static char buffer
[30];
12205 error (_("Unknown LTO symbol definition encountered: %u\n"), kind
);
12206 sprintf (buffer
, "<unknown: %u>", kind
);
12210 static const char *
12211 get_lto_visibility (unsigned int visibility
)
12213 switch (visibility
)
12215 case 0: return "DEFAULT";
12216 case 1: return "PROTECTED";
12217 case 2: return "INTERNAL";
12218 case 3: return "HIDDEN";
12223 static char buffer
[30];
12224 error (_("Unknown LTO symbol visibility encountered: %u\n"), visibility
);
12225 sprintf (buffer
, "<unknown: %u>", visibility
);
12229 static const char *
12230 get_lto_sym_type (unsigned int sym_type
)
12234 case 0: return "UNKNOWN";
12235 case 1: return "FUNCTION";
12236 case 2: return "VARIABLE";
12241 static char buffer
[30];
12242 error (_("Unknown LTO symbol type encountered: %u\n"), sym_type
);
12243 sprintf (buffer
, "<unknown: %u>", sym_type
);
12247 /* Display an LTO format symbol table.
12248 FIXME: The format of LTO symbol tables is not formalized.
12249 So this code could need changing in the future. */
12252 display_lto_symtab (Filedata
* filedata
,
12253 Elf_Internal_Shdr
* section
)
12255 if (section
->sh_size
== 0)
12257 printf (_("\nLTO Symbol table '%s' is empty!\n"),
12258 printable_section_name (filedata
, section
));
12262 if (section
->sh_size
> filedata
->file_size
)
12264 error (_("Section %s has an invalid sh_size of 0x%lx\n"),
12265 printable_section_name (filedata
, section
),
12266 (unsigned long) section
->sh_size
);
12270 void * alloced_data
= get_data (NULL
, filedata
, section
->sh_offset
,
12271 section
->sh_size
, 1, _("LTO symbols"));
12272 if (alloced_data
== NULL
)
12275 /* Look for extended data for the symbol table. */
12276 Elf_Internal_Shdr
* ext
;
12277 void * ext_data_orig
= NULL
;
12278 char * ext_data
= NULL
;
12279 char * ext_data_end
= NULL
;
12280 char * ext_name
= NULL
;
12282 if (asprintf (& ext_name
, ".gnu.lto_.ext_symtab.%s",
12283 SECTION_NAME (section
) + strlen (".gnu.lto_.symtab.")) > 0
12284 && ext_name
!= NULL
/* Paranoia. */
12285 && (ext
= find_section (filedata
, ext_name
)) != NULL
)
12287 if (ext
->sh_size
< 3)
12288 error (_("LTO Symbol extension table '%s' is empty!\n"),
12289 printable_section_name (filedata
, ext
));
12292 ext_data_orig
= ext_data
= get_data (NULL
, filedata
, ext
->sh_offset
,
12294 _("LTO ext symbol data"));
12295 if (ext_data
!= NULL
)
12297 ext_data_end
= ext_data
+ ext
->sh_size
;
12298 if (* ext_data
++ != 1)
12299 error (_("Unexpected version number in symbol extension table\n"));
12304 const unsigned char * data
= (const unsigned char *) alloced_data
;
12305 const unsigned char * end
= data
+ section
->sh_size
;
12307 if (ext_data_orig
!= NULL
)
12310 printf (_("\nLTO Symbol table '%s' and extension table '%s' contain:\n"),
12311 printable_section_name (filedata
, section
),
12312 printable_section_name (filedata
, ext
));
12315 printf (_("\nLTO Symbol table '%s'\n"),
12316 printable_section_name (filedata
, section
));
12317 printf (_(" and extension table '%s' contain:\n"),
12318 printable_section_name (filedata
, ext
));
12322 printf (_("\nLTO Symbol table '%s' contains:\n"),
12323 printable_section_name (filedata
, section
));
12326 /* FIXME: Add a wide version. */
12327 if (ext_data_orig
!= NULL
)
12328 printf (_(" Comdat_Key Kind Visibility Size Slot Type Section Name\n"));
12330 printf (_(" Comdat_Key Kind Visibility Size Slot Name\n"));
12332 /* FIXME: We do not handle style prefixes. */
12336 const unsigned char * sym_name
= data
;
12337 data
+= strnlen ((const char *) sym_name
, end
- data
) + 1;
12341 const unsigned char * comdat_key
= data
;
12342 data
+= strnlen ((const char *) comdat_key
, end
- data
) + 1;
12346 if (data
+ 2 + 8 + 4 > end
)
12349 unsigned int kind
= *data
++;
12350 unsigned int visibility
= *data
++;
12352 elf_vma size
= byte_get (data
, 8);
12355 elf_vma slot
= byte_get (data
, 4);
12358 if (ext_data
!= NULL
)
12360 if (ext_data
< (ext_data_end
- 1))
12362 unsigned int sym_type
= * ext_data
++;
12363 unsigned int sec_kind
= * ext_data
++;
12365 printf (" %10s %10s %11s %08lx %08lx %9s %08lx _",
12366 * comdat_key
== 0 ? "-" : (char *) comdat_key
,
12367 get_lto_kind (kind
),
12368 get_lto_visibility (visibility
),
12371 get_lto_sym_type (sym_type
),
12373 print_symbol (6, (const char *) sym_name
);
12377 error (_("Ran out of LTO symbol extension data\n"));
12379 /* FIXME: return FAIL result ? */
12384 printf (" %10s %10s %11s %08lx %08lx _",
12385 * comdat_key
== 0 ? "-" : (char *) comdat_key
,
12386 get_lto_kind (kind
),
12387 get_lto_visibility (visibility
),
12390 print_symbol (21, (const char *) sym_name
);
12395 if (ext_data
!= NULL
&& ext_data
< ext_data_end
)
12397 error (_("Data remains in the LTO symbol extension table\n"));
12401 free (alloced_data
);
12402 free (ext_data_orig
);
12407 error (_("Buffer overrun encountered whilst decoding LTO symbol table\n"));
12408 free (alloced_data
);
12409 free (ext_data_orig
);
12414 /* Display LTO symbol tables. */
12417 process_lto_symbol_tables (Filedata
* filedata
)
12419 Elf_Internal_Shdr
* section
;
12421 bfd_boolean res
= TRUE
;
12426 if (filedata
->section_headers
== NULL
)
12429 for (i
= 0, section
= filedata
->section_headers
;
12430 i
< filedata
->file_header
.e_shnum
;
12432 if (CONST_STRNEQ (SECTION_NAME (section
), ".gnu.lto_.symtab"))
12433 res
&= display_lto_symtab (filedata
, section
);
12438 /* Dump the symbol table. */
12441 process_symbol_table (Filedata
* filedata
)
12443 Elf_Internal_Shdr
* section
;
12445 if (!do_syms
&& !do_dyn_syms
&& !do_histogram
)
12448 if ((filedata
->dynamic_info
[DT_HASH
] || filedata
->dynamic_info_DT_GNU_HASH
)
12450 && do_using_dynamic
12451 && filedata
->dynamic_strings
!= NULL
12452 && filedata
->dynamic_symbols
!= NULL
)
12456 printf (ngettext ("\nSymbol table for image contains %lu entry:\n",
12457 "\nSymbol table for image contains %lu entries:\n",
12458 filedata
->num_dynamic_syms
),
12459 filedata
->num_dynamic_syms
);
12461 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
12463 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
12465 for (si
= 0; si
< filedata
->num_dynamic_syms
; si
++)
12466 print_dynamic_symbol (filedata
, si
, filedata
->dynamic_symbols
, NULL
,
12467 filedata
->dynamic_strings
,
12468 filedata
->dynamic_strings_length
);
12470 else if ((do_dyn_syms
|| (do_syms
&& !do_using_dynamic
))
12471 && filedata
->section_headers
!= NULL
)
12475 for (i
= 0, section
= filedata
->section_headers
;
12476 i
< filedata
->file_header
.e_shnum
;
12479 char * strtab
= NULL
;
12480 unsigned long int strtab_size
= 0;
12481 Elf_Internal_Sym
* symtab
;
12482 unsigned long si
, num_syms
;
12484 if ((section
->sh_type
!= SHT_SYMTAB
12485 && section
->sh_type
!= SHT_DYNSYM
)
12487 && section
->sh_type
== SHT_SYMTAB
))
12490 if (section
->sh_entsize
== 0)
12492 printf (_("\nSymbol table '%s' has a sh_entsize of zero!\n"),
12493 printable_section_name (filedata
, section
));
12497 num_syms
= section
->sh_size
/ section
->sh_entsize
;
12498 printf (ngettext ("\nSymbol table '%s' contains %lu entry:\n",
12499 "\nSymbol table '%s' contains %lu entries:\n",
12501 printable_section_name (filedata
, section
),
12505 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
12507 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
12509 symtab
= GET_ELF_SYMBOLS (filedata
, section
, & num_syms
);
12510 if (symtab
== NULL
)
12513 if (section
->sh_link
== filedata
->file_header
.e_shstrndx
)
12515 strtab
= filedata
->string_table
;
12516 strtab_size
= filedata
->string_table_length
;
12518 else if (section
->sh_link
< filedata
->file_header
.e_shnum
)
12520 Elf_Internal_Shdr
* string_sec
;
12522 string_sec
= filedata
->section_headers
+ section
->sh_link
;
12524 strtab
= (char *) get_data (NULL
, filedata
, string_sec
->sh_offset
,
12525 1, string_sec
->sh_size
,
12526 _("string table"));
12527 strtab_size
= strtab
!= NULL
? string_sec
->sh_size
: 0;
12530 for (si
= 0; si
< num_syms
; si
++)
12531 print_dynamic_symbol (filedata
, si
, symtab
, section
,
12532 strtab
, strtab_size
);
12535 if (strtab
!= filedata
->string_table
)
12541 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
12543 if (do_histogram
&& filedata
->buckets
!= NULL
)
12545 unsigned long * lengths
;
12546 unsigned long * counts
;
12549 unsigned long maxlength
= 0;
12550 unsigned long nzero_counts
= 0;
12551 unsigned long nsyms
= 0;
12554 printf (ngettext ("\nHistogram for bucket list length "
12555 "(total of %lu bucket):\n",
12556 "\nHistogram for bucket list length "
12557 "(total of %lu buckets):\n",
12558 (unsigned long) filedata
->nbuckets
),
12559 (unsigned long) filedata
->nbuckets
);
12561 lengths
= (unsigned long *) calloc (filedata
->nbuckets
,
12562 sizeof (*lengths
));
12563 if (lengths
== NULL
)
12565 error (_("Out of memory allocating space for histogram buckets\n"));
12568 visited
= xcmalloc (filedata
->nchains
, 1);
12569 memset (visited
, 0, filedata
->nchains
);
12571 printf (_(" Length Number %% of total Coverage\n"));
12572 for (hn
= 0; hn
< filedata
->nbuckets
; ++hn
)
12574 for (si
= filedata
->buckets
[hn
]; si
> 0; si
= filedata
->chains
[si
])
12577 if (maxlength
< ++lengths
[hn
])
12579 if (si
>= filedata
->nchains
|| visited
[si
])
12581 error (_("histogram chain is corrupt\n"));
12589 counts
= (unsigned long *) calloc (maxlength
+ 1, sizeof (*counts
));
12590 if (counts
== NULL
)
12593 error (_("Out of memory allocating space for histogram counts\n"));
12597 for (hn
= 0; hn
< filedata
->nbuckets
; ++hn
)
12598 ++counts
[lengths
[hn
]];
12600 if (filedata
->nbuckets
> 0)
12603 printf (" 0 %-10lu (%5.1f%%)\n",
12604 counts
[0], (counts
[0] * 100.0) / filedata
->nbuckets
);
12605 for (i
= 1; i
<= maxlength
; ++i
)
12607 nzero_counts
+= counts
[i
] * i
;
12608 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
12609 i
, counts
[i
], (counts
[i
] * 100.0) / filedata
->nbuckets
,
12610 (nzero_counts
* 100.0) / nsyms
);
12618 free (filedata
->buckets
);
12619 filedata
->buckets
= NULL
;
12620 filedata
->nbuckets
= 0;
12621 free (filedata
->chains
);
12622 filedata
->chains
= NULL
;
12624 if (do_histogram
&& filedata
->gnubuckets
!= NULL
)
12626 unsigned long * lengths
;
12627 unsigned long * counts
;
12629 unsigned long maxlength
= 0;
12630 unsigned long nzero_counts
= 0;
12631 unsigned long nsyms
= 0;
12633 printf (ngettext ("\nHistogram for `%s' bucket list length "
12634 "(total of %lu bucket):\n",
12635 "\nHistogram for `%s' bucket list length "
12636 "(total of %lu buckets):\n",
12637 (unsigned long) filedata
->ngnubuckets
),
12638 GNU_HASH_SECTION_NAME (filedata
),
12639 (unsigned long) filedata
->ngnubuckets
);
12641 lengths
= (unsigned long *) calloc (filedata
->ngnubuckets
,
12642 sizeof (*lengths
));
12643 if (lengths
== NULL
)
12645 error (_("Out of memory allocating space for gnu histogram buckets\n"));
12649 printf (_(" Length Number %% of total Coverage\n"));
12651 for (hn
= 0; hn
< filedata
->ngnubuckets
; ++hn
)
12652 if (filedata
->gnubuckets
[hn
] != 0)
12654 bfd_vma off
, length
= 1;
12656 for (off
= filedata
->gnubuckets
[hn
] - filedata
->gnusymidx
;
12657 /* PR 17531 file: 010-77222-0.004. */
12658 off
< filedata
->ngnuchains
12659 && (filedata
->gnuchains
[off
] & 1) == 0;
12662 lengths
[hn
] = length
;
12663 if (length
> maxlength
)
12664 maxlength
= length
;
12668 counts
= (unsigned long *) calloc (maxlength
+ 1, sizeof (*counts
));
12669 if (counts
== NULL
)
12672 error (_("Out of memory allocating space for gnu histogram counts\n"));
12676 for (hn
= 0; hn
< filedata
->ngnubuckets
; ++hn
)
12677 ++counts
[lengths
[hn
]];
12679 if (filedata
->ngnubuckets
> 0)
12682 printf (" 0 %-10lu (%5.1f%%)\n",
12683 counts
[0], (counts
[0] * 100.0) / filedata
->ngnubuckets
);
12684 for (j
= 1; j
<= maxlength
; ++j
)
12686 nzero_counts
+= counts
[j
] * j
;
12687 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
12688 j
, counts
[j
], (counts
[j
] * 100.0) / filedata
->ngnubuckets
,
12689 (nzero_counts
* 100.0) / nsyms
);
12696 free (filedata
->gnubuckets
);
12697 filedata
->gnubuckets
= NULL
;
12698 filedata
->ngnubuckets
= 0;
12699 free (filedata
->gnuchains
);
12700 filedata
->gnuchains
= NULL
;
12701 filedata
->ngnuchains
= 0;
12702 free (filedata
->mipsxlat
);
12703 filedata
->mipsxlat
= NULL
;
12707 free (filedata
->gnubuckets
);
12708 filedata
->gnubuckets
= NULL
;
12709 filedata
->ngnubuckets
= 0;
12710 free (filedata
->gnuchains
);
12711 filedata
->gnuchains
= NULL
;
12712 filedata
->ngnuchains
= 0;
12713 free (filedata
->mipsxlat
);
12714 filedata
->mipsxlat
= NULL
;
12715 free (filedata
->buckets
);
12716 filedata
->buckets
= NULL
;
12717 filedata
->nbuckets
= 0;
12718 free (filedata
->chains
);
12719 filedata
->chains
= NULL
;
12724 process_syminfo (Filedata
* filedata ATTRIBUTE_UNUSED
)
12728 if (filedata
->dynamic_syminfo
== NULL
12730 /* No syminfo, this is ok. */
12733 /* There better should be a dynamic symbol section. */
12734 if (filedata
->dynamic_symbols
== NULL
|| filedata
->dynamic_strings
== NULL
)
12737 if (filedata
->dynamic_addr
)
12738 printf (ngettext ("\nDynamic info segment at offset 0x%lx "
12739 "contains %d entry:\n",
12740 "\nDynamic info segment at offset 0x%lx "
12741 "contains %d entries:\n",
12742 filedata
->dynamic_syminfo_nent
),
12743 filedata
->dynamic_syminfo_offset
, filedata
->dynamic_syminfo_nent
);
12745 printf (_(" Num: Name BoundTo Flags\n"));
12746 for (i
= 0; i
< filedata
->dynamic_syminfo_nent
; ++i
)
12748 unsigned short int flags
= filedata
->dynamic_syminfo
[i
].si_flags
;
12750 printf ("%4d: ", i
);
12751 if (i
>= filedata
->num_dynamic_syms
)
12752 printf (_("<corrupt index>"));
12753 else if (VALID_DYNAMIC_NAME (filedata
, filedata
->dynamic_symbols
[i
].st_name
))
12754 print_symbol (30, GET_DYNAMIC_NAME (filedata
,
12755 filedata
->dynamic_symbols
[i
].st_name
));
12757 printf (_("<corrupt: %19ld>"), filedata
->dynamic_symbols
[i
].st_name
);
12760 switch (filedata
->dynamic_syminfo
[i
].si_boundto
)
12762 case SYMINFO_BT_SELF
:
12763 fputs ("SELF ", stdout
);
12765 case SYMINFO_BT_PARENT
:
12766 fputs ("PARENT ", stdout
);
12769 if (filedata
->dynamic_syminfo
[i
].si_boundto
> 0
12770 && filedata
->dynamic_syminfo
[i
].si_boundto
< filedata
->dynamic_nent
12771 && VALID_DYNAMIC_NAME (filedata
,
12772 filedata
->dynamic_section
[filedata
->dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
))
12774 print_symbol (10, GET_DYNAMIC_NAME (filedata
,
12775 filedata
->dynamic_section
[filedata
->dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
));
12779 printf ("%-10d ", filedata
->dynamic_syminfo
[i
].si_boundto
);
12783 if (flags
& SYMINFO_FLG_DIRECT
)
12784 printf (" DIRECT");
12785 if (flags
& SYMINFO_FLG_PASSTHRU
)
12786 printf (" PASSTHRU");
12787 if (flags
& SYMINFO_FLG_COPY
)
12789 if (flags
& SYMINFO_FLG_LAZYLOAD
)
12790 printf (" LAZYLOAD");
12798 /* A macro which evaluates to TRUE if the region ADDR .. ADDR + NELEM
12799 is contained by the region START .. END. The types of ADDR, START
12800 and END should all be the same. Note both ADDR + NELEM and END
12801 point to just beyond the end of the regions that are being tested. */
12802 #define IN_RANGE(START,END,ADDR,NELEM) \
12803 (((ADDR) >= (START)) && ((ADDR) < (END)) && ((ADDR) + (NELEM) <= (END)))
12805 /* Check to see if the given reloc needs to be handled in a target specific
12806 manner. If so then process the reloc and return TRUE otherwise return
12809 If called with reloc == NULL, then this is a signal that reloc processing
12810 for the current section has finished, and any saved state should be
12814 target_specific_reloc_handling (Filedata
* filedata
,
12815 Elf_Internal_Rela
* reloc
,
12816 unsigned char * start
,
12817 unsigned char * end
,
12818 Elf_Internal_Sym
* symtab
,
12819 unsigned long num_syms
)
12821 unsigned int reloc_type
= 0;
12822 unsigned long sym_index
= 0;
12826 reloc_type
= get_reloc_type (filedata
, reloc
->r_info
);
12827 sym_index
= get_reloc_symindex (reloc
->r_info
);
12830 switch (filedata
->file_header
.e_machine
)
12833 case EM_MSP430_OLD
:
12835 static Elf_Internal_Sym
* saved_sym
= NULL
;
12843 switch (reloc_type
)
12845 case 10: /* R_MSP430_SYM_DIFF */
12846 case 12: /* R_MSP430_GNU_SUB_ULEB128 */
12847 if (uses_msp430x_relocs (filedata
))
12849 /* Fall through. */
12850 case 21: /* R_MSP430X_SYM_DIFF */
12851 case 23: /* R_MSP430X_GNU_SUB_ULEB128 */
12853 if (sym_index
>= num_syms
)
12854 error (_("MSP430 SYM_DIFF reloc contains invalid symbol index %lu\n"),
12857 saved_sym
= symtab
+ sym_index
;
12860 case 1: /* R_MSP430_32 or R_MSP430_ABS32 */
12861 case 3: /* R_MSP430_16 or R_MSP430_ABS8 */
12862 goto handle_sym_diff
;
12864 case 5: /* R_MSP430_16_BYTE */
12865 case 9: /* R_MSP430_8 */
12866 case 11: /* R_MSP430_GNU_SET_ULEB128 */
12867 if (uses_msp430x_relocs (filedata
))
12869 goto handle_sym_diff
;
12871 case 2: /* R_MSP430_ABS16 */
12872 case 15: /* R_MSP430X_ABS16 */
12873 case 22: /* R_MSP430X_GNU_SET_ULEB128 */
12874 if (! uses_msp430x_relocs (filedata
))
12876 goto handle_sym_diff
;
12879 if (saved_sym
!= NULL
)
12882 unsigned int reloc_size
= 0;
12884 switch (reloc_type
)
12886 case 1: /* R_MSP430_32 or R_MSP430_ABS32 */
12889 case 11: /* R_MSP430_GNU_SET_ULEB128 */
12890 case 22: /* R_MSP430X_GNU_SET_ULEB128 */
12891 if (reloc
->r_offset
< (size_t) (end
- start
))
12892 read_leb128 (start
+ reloc
->r_offset
, end
, FALSE
,
12893 &reloc_size
, &leb_ret
);
12900 if (leb_ret
!= 0 || reloc_size
== 0 || reloc_size
> 8)
12901 error (_("MSP430 ULEB128 field at 0x%lx contains invalid "
12902 "ULEB128 value\n"),
12903 (long) reloc
->r_offset
);
12904 else if (sym_index
>= num_syms
)
12905 error (_("MSP430 reloc contains invalid symbol index %lu\n"),
12909 value
= reloc
->r_addend
+ (symtab
[sym_index
].st_value
12910 - saved_sym
->st_value
);
12912 if (IN_RANGE (start
, end
, start
+ reloc
->r_offset
, reloc_size
))
12913 byte_put (start
+ reloc
->r_offset
, value
, reloc_size
);
12916 error (_("MSP430 sym diff reloc contains invalid offset: 0x%lx\n"),
12917 (long) reloc
->r_offset
);
12926 if (saved_sym
!= NULL
)
12927 error (_("Unhandled MSP430 reloc type found after SYM_DIFF reloc\n"));
12934 case EM_CYGNUS_MN10300
:
12936 static Elf_Internal_Sym
* saved_sym
= NULL
;
12944 switch (reloc_type
)
12946 case 34: /* R_MN10300_ALIGN */
12948 case 33: /* R_MN10300_SYM_DIFF */
12949 if (sym_index
>= num_syms
)
12950 error (_("MN10300_SYM_DIFF reloc contains invalid symbol index %lu\n"),
12953 saved_sym
= symtab
+ sym_index
;
12956 case 1: /* R_MN10300_32 */
12957 case 2: /* R_MN10300_16 */
12958 if (saved_sym
!= NULL
)
12960 int reloc_size
= reloc_type
== 1 ? 4 : 2;
12963 if (sym_index
>= num_syms
)
12964 error (_("MN10300 reloc contains invalid symbol index %lu\n"),
12968 value
= reloc
->r_addend
+ (symtab
[sym_index
].st_value
12969 - saved_sym
->st_value
);
12971 if (IN_RANGE (start
, end
, start
+ reloc
->r_offset
, reloc_size
))
12972 byte_put (start
+ reloc
->r_offset
, value
, reloc_size
);
12974 error (_("MN10300 sym diff reloc contains invalid offset: 0x%lx\n"),
12975 (long) reloc
->r_offset
);
12983 if (saved_sym
!= NULL
)
12984 error (_("Unhandled MN10300 reloc type found after SYM_DIFF reloc\n"));
12992 static bfd_vma saved_sym1
= 0;
12993 static bfd_vma saved_sym2
= 0;
12994 static bfd_vma value
;
12998 saved_sym1
= saved_sym2
= 0;
13002 switch (reloc_type
)
13004 case 0x80: /* R_RL78_SYM. */
13005 saved_sym1
= saved_sym2
;
13006 if (sym_index
>= num_syms
)
13007 error (_("RL78_SYM reloc contains invalid symbol index %lu\n"),
13011 saved_sym2
= symtab
[sym_index
].st_value
;
13012 saved_sym2
+= reloc
->r_addend
;
13016 case 0x83: /* R_RL78_OPsub. */
13017 value
= saved_sym1
- saved_sym2
;
13018 saved_sym2
= saved_sym1
= 0;
13022 case 0x41: /* R_RL78_ABS32. */
13023 if (IN_RANGE (start
, end
, start
+ reloc
->r_offset
, 4))
13024 byte_put (start
+ reloc
->r_offset
, value
, 4);
13026 error (_("RL78 sym diff reloc contains invalid offset: 0x%lx\n"),
13027 (long) reloc
->r_offset
);
13031 case 0x43: /* R_RL78_ABS16. */
13032 if (IN_RANGE (start
, end
, start
+ reloc
->r_offset
, 2))
13033 byte_put (start
+ reloc
->r_offset
, value
, 2);
13035 error (_("RL78 sym diff reloc contains invalid offset: 0x%lx\n"),
13036 (long) reloc
->r_offset
);
13050 /* Returns TRUE iff RELOC_TYPE is a 32-bit absolute RELA relocation used in
13051 DWARF debug sections. This is a target specific test. Note - we do not
13052 go through the whole including-target-headers-multiple-times route, (as
13053 we have already done with <elf/h8.h>) because this would become very
13054 messy and even then this function would have to contain target specific
13055 information (the names of the relocs instead of their numeric values).
13056 FIXME: This is not the correct way to solve this problem. The proper way
13057 is to have target specific reloc sizing and typing functions created by
13058 the reloc-macros.h header, in the same way that it already creates the
13059 reloc naming functions. */
13062 is_32bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
13064 /* Please keep this table alpha-sorted for ease of visual lookup. */
13065 switch (filedata
->file_header
.e_machine
)
13069 return reloc_type
== 1; /* R_386_32. */
13071 return reloc_type
== 1; /* R_68K_32. */
13073 return reloc_type
== 1; /* R_860_32. */
13075 return reloc_type
== 2; /* R_960_32. */
13077 return (reloc_type
== 258
13078 || reloc_type
== 1); /* R_AARCH64_ABS32 || R_AARCH64_P32_ABS32 */
13080 return reloc_type
== 11; /* R_BPF_DATA_32 */
13081 case EM_ADAPTEVA_EPIPHANY
:
13082 return reloc_type
== 3;
13084 return reloc_type
== 1; /* R_ALPHA_REFLONG. */
13086 return reloc_type
== 1; /* R_ARC_32. */
13087 case EM_ARC_COMPACT
:
13088 case EM_ARC_COMPACT2
:
13089 return reloc_type
== 4; /* R_ARC_32. */
13091 return reloc_type
== 2; /* R_ARM_ABS32 */
13094 return reloc_type
== 1;
13096 return reloc_type
== 0x12; /* R_byte4_data. */
13098 return reloc_type
== 3; /* R_CRIS_32. */
13100 return reloc_type
== 3; /* R_CR16_NUM32. */
13102 return reloc_type
== 15; /* R_CRX_NUM32. */
13104 return reloc_type
== 1; /* R_CKCORE_ADDR32. */
13105 case EM_CYGNUS_FRV
:
13106 return reloc_type
== 1;
13107 case EM_CYGNUS_D10V
:
13109 return reloc_type
== 6; /* R_D10V_32. */
13110 case EM_CYGNUS_D30V
:
13112 return reloc_type
== 12; /* R_D30V_32_NORMAL. */
13114 return reloc_type
== 3; /* R_DLX_RELOC_32. */
13115 case EM_CYGNUS_FR30
:
13117 return reloc_type
== 3; /* R_FR30_32. */
13119 return reloc_type
== 1; /* R_FT32_32. */
13123 return reloc_type
== 1; /* R_H8_DIR32. */
13125 return (reloc_type
== 0x64 /* R_IA64_SECREL32MSB. */
13126 || reloc_type
== 0x65 /* R_IA64_SECREL32LSB. */
13127 || reloc_type
== 0x24 /* R_IA64_DIR32MSB. */
13128 || reloc_type
== 0x25 /* R_IA64_DIR32LSB. */);
13131 return reloc_type
== 2; /* R_IP2K_32. */
13133 return reloc_type
== 2; /* R_IQ2000_32. */
13134 case EM_LATTICEMICO32
:
13135 return reloc_type
== 3; /* R_LM32_32. */
13138 return reloc_type
== 3; /* R_M32C_32. */
13140 return reloc_type
== 34; /* R_M32R_32_RELA. */
13143 return reloc_type
== 6; /* R_M68HC11_32. */
13145 return reloc_type
== 7 || /* R_S12Z_EXT32 */
13146 reloc_type
== 6; /* R_S12Z_CW32. */
13148 return reloc_type
== 1; /* R_MCORE_ADDR32. */
13149 case EM_CYGNUS_MEP
:
13150 return reloc_type
== 4; /* R_MEP_32. */
13152 return reloc_type
== 2; /* R_METAG_ADDR32. */
13153 case EM_MICROBLAZE
:
13154 return reloc_type
== 1; /* R_MICROBLAZE_32. */
13156 return reloc_type
== 2; /* R_MIPS_32. */
13158 return reloc_type
== 4; /* R_MMIX_32. */
13159 case EM_CYGNUS_MN10200
:
13161 return reloc_type
== 1; /* R_MN10200_32. */
13162 case EM_CYGNUS_MN10300
:
13164 return reloc_type
== 1; /* R_MN10300_32. */
13166 return reloc_type
== 1; /* R_MOXIE_32. */
13167 case EM_MSP430_OLD
:
13169 return reloc_type
== 1; /* R_MSP430_32 or R_MSP320_ABS32. */
13171 return reloc_type
== 2; /* R_MT_32. */
13173 return reloc_type
== 20; /* R_NDS32_RELA. */
13174 case EM_ALTERA_NIOS2
:
13175 return reloc_type
== 12; /* R_NIOS2_BFD_RELOC_32. */
13177 return reloc_type
== 1; /* R_NIOS_32. */
13179 return reloc_type
== 1; /* R_OR1K_32. */
13181 return (reloc_type
== 1 /* R_PARISC_DIR32. */
13182 || reloc_type
== 2 /* R_PARISC_DIR21L. */
13183 || reloc_type
== 41); /* R_PARISC_SECREL32. */
13186 return reloc_type
== 1; /* R_PJ_DATA_DIR32. */
13188 return reloc_type
== 1; /* R_PPC64_ADDR32. */
13190 return reloc_type
== 1; /* R_PPC_ADDR32. */
13192 return reloc_type
== 11; /* R_PRU_BFD_RELOC_32. */
13194 return reloc_type
== 1; /* R_RISCV_32. */
13196 return reloc_type
== 1; /* R_RL78_DIR32. */
13198 return reloc_type
== 1; /* R_RX_DIR32. */
13200 return reloc_type
== 1; /* R_I370_ADDR31. */
13203 return reloc_type
== 4; /* R_S390_32. */
13205 return reloc_type
== 8; /* R_SCORE_ABS32. */
13207 return reloc_type
== 1; /* R_SH_DIR32. */
13208 case EM_SPARC32PLUS
:
13211 return reloc_type
== 3 /* R_SPARC_32. */
13212 || reloc_type
== 23; /* R_SPARC_UA32. */
13214 return reloc_type
== 6; /* R_SPU_ADDR32 */
13216 return reloc_type
== 1; /* R_C6000_ABS32. */
13218 return reloc_type
== 2; /* R_TILEGX_32. */
13220 return reloc_type
== 1; /* R_TILEPRO_32. */
13221 case EM_CYGNUS_V850
:
13223 return reloc_type
== 6; /* R_V850_ABS32. */
13225 return reloc_type
== 0x33; /* R_V810_WORD. */
13227 return reloc_type
== 1; /* R_VAX_32. */
13229 return reloc_type
== 3; /* R_VISIUM_32. */
13230 case EM_WEBASSEMBLY
:
13231 return reloc_type
== 1; /* R_WASM32_32. */
13235 return reloc_type
== 10; /* R_X86_64_32. */
13238 return reloc_type
== 3; /* R_XC16C_ABS_32. */
13240 return reloc_type
== 4; /* R_XGATE_32. */
13242 return reloc_type
== 1; /* R_XSTROMY16_32. */
13243 case EM_XTENSA_OLD
:
13245 return reloc_type
== 1; /* R_XTENSA_32. */
13247 return reloc_type
== 6; /* R_Z80_32. */
13250 static unsigned int prev_warn
= 0;
13252 /* Avoid repeating the same warning multiple times. */
13253 if (prev_warn
!= filedata
->file_header
.e_machine
)
13254 error (_("Missing knowledge of 32-bit reloc types used in DWARF sections of machine number %d\n"),
13255 filedata
->file_header
.e_machine
);
13256 prev_warn
= filedata
->file_header
.e_machine
;
13262 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13263 a 32-bit pc-relative RELA relocation used in DWARF debug sections. */
13266 is_32bit_pcrel_reloc (Filedata
* filedata
, unsigned int reloc_type
)
13268 switch (filedata
->file_header
.e_machine
)
13269 /* Please keep this table alpha-sorted for ease of visual lookup. */
13273 return reloc_type
== 2; /* R_386_PC32. */
13275 return reloc_type
== 4; /* R_68K_PC32. */
13277 return reloc_type
== 261; /* R_AARCH64_PREL32 */
13278 case EM_ADAPTEVA_EPIPHANY
:
13279 return reloc_type
== 6;
13281 return reloc_type
== 10; /* R_ALPHA_SREL32. */
13282 case EM_ARC_COMPACT
:
13283 case EM_ARC_COMPACT2
:
13284 return reloc_type
== 49; /* R_ARC_32_PCREL. */
13286 return reloc_type
== 3; /* R_ARM_REL32 */
13289 return reloc_type
== 36; /* R_AVR_32_PCREL. */
13290 case EM_MICROBLAZE
:
13291 return reloc_type
== 2; /* R_MICROBLAZE_32_PCREL. */
13293 return reloc_type
== 9; /* R_OR1K_32_PCREL. */
13295 return reloc_type
== 9; /* R_PARISC_PCREL32. */
13297 return reloc_type
== 26; /* R_PPC_REL32. */
13299 return reloc_type
== 26; /* R_PPC64_REL32. */
13301 return reloc_type
== 57; /* R_RISCV_32_PCREL. */
13304 return reloc_type
== 5; /* R_390_PC32. */
13306 return reloc_type
== 2; /* R_SH_REL32. */
13307 case EM_SPARC32PLUS
:
13310 return reloc_type
== 6; /* R_SPARC_DISP32. */
13312 return reloc_type
== 13; /* R_SPU_REL32. */
13314 return reloc_type
== 6; /* R_TILEGX_32_PCREL. */
13316 return reloc_type
== 4; /* R_TILEPRO_32_PCREL. */
13318 return reloc_type
== 6; /* R_VISIUM_32_PCREL */
13322 return reloc_type
== 2; /* R_X86_64_PC32. */
13324 return reloc_type
== 4; /* R_VAX_PCREL32. */
13325 case EM_XTENSA_OLD
:
13327 return reloc_type
== 14; /* R_XTENSA_32_PCREL. */
13329 /* Do not abort or issue an error message here. Not all targets use
13330 pc-relative 32-bit relocs in their DWARF debug information and we
13331 have already tested for target coverage in is_32bit_abs_reloc. A
13332 more helpful warning message will be generated by apply_relocations
13333 anyway, so just return. */
13338 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13339 a 64-bit absolute RELA relocation used in DWARF debug sections. */
13342 is_64bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
13344 switch (filedata
->file_header
.e_machine
)
13347 return reloc_type
== 257; /* R_AARCH64_ABS64. */
13349 return reloc_type
== 2; /* R_ALPHA_REFQUAD. */
13351 return (reloc_type
== 0x26 /* R_IA64_DIR64MSB. */
13352 || reloc_type
== 0x27 /* R_IA64_DIR64LSB. */);
13354 return reloc_type
== 80; /* R_PARISC_DIR64. */
13356 return reloc_type
== 38; /* R_PPC64_ADDR64. */
13358 return reloc_type
== 2; /* R_RISCV_64. */
13359 case EM_SPARC32PLUS
:
13362 return reloc_type
== 32 /* R_SPARC_64. */
13363 || reloc_type
== 54; /* R_SPARC_UA64. */
13367 return reloc_type
== 1; /* R_X86_64_64. */
13370 return reloc_type
== 22; /* R_S390_64. */
13372 return reloc_type
== 1; /* R_TILEGX_64. */
13374 return reloc_type
== 18; /* R_MIPS_64. */
13380 /* Like is_32bit_pcrel_reloc except that it returns TRUE iff RELOC_TYPE is
13381 a 64-bit pc-relative RELA relocation used in DWARF debug sections. */
13384 is_64bit_pcrel_reloc (Filedata
* filedata
, unsigned int reloc_type
)
13386 switch (filedata
->file_header
.e_machine
)
13389 return reloc_type
== 260; /* R_AARCH64_PREL64. */
13391 return reloc_type
== 11; /* R_ALPHA_SREL64. */
13393 return (reloc_type
== 0x4e /* R_IA64_PCREL64MSB. */
13394 || reloc_type
== 0x4f /* R_IA64_PCREL64LSB. */);
13396 return reloc_type
== 72; /* R_PARISC_PCREL64. */
13398 return reloc_type
== 44; /* R_PPC64_REL64. */
13399 case EM_SPARC32PLUS
:
13402 return reloc_type
== 46; /* R_SPARC_DISP64. */
13406 return reloc_type
== 24; /* R_X86_64_PC64. */
13409 return reloc_type
== 23; /* R_S390_PC64. */
13411 return reloc_type
== 5; /* R_TILEGX_64_PCREL. */
13417 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13418 a 24-bit absolute RELA relocation used in DWARF debug sections. */
13421 is_24bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
13423 switch (filedata
->file_header
.e_machine
)
13425 case EM_CYGNUS_MN10200
:
13427 return reloc_type
== 4; /* R_MN10200_24. */
13429 return reloc_type
== 5; /* R_FT32_20. */
13431 return reloc_type
== 5; /* R_Z80_24. */
13437 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13438 a 16-bit absolute RELA relocation used in DWARF debug sections. */
13441 is_16bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
13443 /* Please keep this table alpha-sorted for ease of visual lookup. */
13444 switch (filedata
->file_header
.e_machine
)
13447 case EM_ARC_COMPACT
:
13448 case EM_ARC_COMPACT2
:
13449 return reloc_type
== 2; /* R_ARC_16. */
13450 case EM_ADAPTEVA_EPIPHANY
:
13451 return reloc_type
== 5;
13454 return reloc_type
== 4; /* R_AVR_16. */
13455 case EM_CYGNUS_D10V
:
13457 return reloc_type
== 3; /* R_D10V_16. */
13459 return reloc_type
== 2; /* R_FT32_16. */
13463 return reloc_type
== R_H8_DIR16
;
13466 return reloc_type
== 1; /* R_IP2K_16. */
13469 return reloc_type
== 1; /* R_M32C_16 */
13470 case EM_CYGNUS_MN10200
:
13472 return reloc_type
== 2; /* R_MN10200_16. */
13473 case EM_CYGNUS_MN10300
:
13475 return reloc_type
== 2; /* R_MN10300_16. */
13477 if (uses_msp430x_relocs (filedata
))
13478 return reloc_type
== 2; /* R_MSP430_ABS16. */
13479 /* Fall through. */
13480 case EM_MSP430_OLD
:
13481 return reloc_type
== 5; /* R_MSP430_16_BYTE. */
13483 return reloc_type
== 19; /* R_NDS32_RELA. */
13484 case EM_ALTERA_NIOS2
:
13485 return reloc_type
== 13; /* R_NIOS2_BFD_RELOC_16. */
13487 return reloc_type
== 9; /* R_NIOS_16. */
13489 return reloc_type
== 2; /* R_OR1K_16. */
13491 return reloc_type
== 55; /* R_RISCV_SET16. */
13493 return reloc_type
== 8; /* R_PRU_BFD_RELOC_16. */
13495 return reloc_type
== 2; /* R_C6000_ABS16. */
13497 return reloc_type
== 2; /* R_VISIUM_16. */
13500 return reloc_type
== 2; /* R_XC16C_ABS_16. */
13502 return reloc_type
== 3; /* R_XGATE_16. */
13504 return reloc_type
== 4; /* R_Z80_16. */
13510 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13511 a 8-bit absolute RELA relocation used in DWARF debug sections. */
13514 is_8bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
13516 switch (filedata
->file_header
.e_machine
)
13519 return reloc_type
== 54; /* R_RISCV_SET8. */
13521 return reloc_type
== 1; /* R_Z80_8. */
13527 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13528 a 6-bit absolute RELA relocation used in DWARF debug sections. */
13531 is_6bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
13533 switch (filedata
->file_header
.e_machine
)
13536 return reloc_type
== 53; /* R_RISCV_SET6. */
13542 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13543 a 32-bit inplace add RELA relocation used in DWARF debug sections. */
13546 is_32bit_inplace_add_reloc (Filedata
* filedata
, unsigned int reloc_type
)
13548 /* Please keep this table alpha-sorted for ease of visual lookup. */
13549 switch (filedata
->file_header
.e_machine
)
13552 return reloc_type
== 35; /* R_RISCV_ADD32. */
13558 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13559 a 32-bit inplace sub RELA relocation used in DWARF debug sections. */
13562 is_32bit_inplace_sub_reloc (Filedata
* filedata
, unsigned int reloc_type
)
13564 /* Please keep this table alpha-sorted for ease of visual lookup. */
13565 switch (filedata
->file_header
.e_machine
)
13568 return reloc_type
== 39; /* R_RISCV_SUB32. */
13574 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13575 a 64-bit inplace add RELA relocation used in DWARF debug sections. */
13578 is_64bit_inplace_add_reloc (Filedata
* filedata
, unsigned int reloc_type
)
13580 /* Please keep this table alpha-sorted for ease of visual lookup. */
13581 switch (filedata
->file_header
.e_machine
)
13584 return reloc_type
== 36; /* R_RISCV_ADD64. */
13590 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13591 a 64-bit inplace sub RELA relocation used in DWARF debug sections. */
13594 is_64bit_inplace_sub_reloc (Filedata
* filedata
, unsigned int reloc_type
)
13596 /* Please keep this table alpha-sorted for ease of visual lookup. */
13597 switch (filedata
->file_header
.e_machine
)
13600 return reloc_type
== 40; /* R_RISCV_SUB64. */
13606 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13607 a 16-bit inplace add RELA relocation used in DWARF debug sections. */
13610 is_16bit_inplace_add_reloc (Filedata
* filedata
, unsigned int reloc_type
)
13612 /* Please keep this table alpha-sorted for ease of visual lookup. */
13613 switch (filedata
->file_header
.e_machine
)
13616 return reloc_type
== 34; /* R_RISCV_ADD16. */
13622 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13623 a 16-bit inplace sub RELA relocation used in DWARF debug sections. */
13626 is_16bit_inplace_sub_reloc (Filedata
* filedata
, unsigned int reloc_type
)
13628 /* Please keep this table alpha-sorted for ease of visual lookup. */
13629 switch (filedata
->file_header
.e_machine
)
13632 return reloc_type
== 38; /* R_RISCV_SUB16. */
13638 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13639 a 8-bit inplace add RELA relocation used in DWARF debug sections. */
13642 is_8bit_inplace_add_reloc (Filedata
* filedata
, unsigned int reloc_type
)
13644 /* Please keep this table alpha-sorted for ease of visual lookup. */
13645 switch (filedata
->file_header
.e_machine
)
13648 return reloc_type
== 33; /* R_RISCV_ADD8. */
13654 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13655 a 8-bit inplace sub RELA relocation used in DWARF debug sections. */
13658 is_8bit_inplace_sub_reloc (Filedata
* filedata
, unsigned int reloc_type
)
13660 /* Please keep this table alpha-sorted for ease of visual lookup. */
13661 switch (filedata
->file_header
.e_machine
)
13664 return reloc_type
== 37; /* R_RISCV_SUB8. */
13670 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13671 a 6-bit inplace sub RELA relocation used in DWARF debug sections. */
13674 is_6bit_inplace_sub_reloc (Filedata
* filedata
, unsigned int reloc_type
)
13676 switch (filedata
->file_header
.e_machine
)
13679 return reloc_type
== 52; /* R_RISCV_SUB6. */
13685 /* Returns TRUE iff RELOC_TYPE is a NONE relocation used for discarded
13686 relocation entries (possibly formerly used for SHT_GROUP sections). */
13689 is_none_reloc (Filedata
* filedata
, unsigned int reloc_type
)
13691 switch (filedata
->file_header
.e_machine
)
13693 case EM_386
: /* R_386_NONE. */
13694 case EM_68K
: /* R_68K_NONE. */
13695 case EM_ADAPTEVA_EPIPHANY
:
13696 case EM_ALPHA
: /* R_ALPHA_NONE. */
13697 case EM_ALTERA_NIOS2
: /* R_NIOS2_NONE. */
13698 case EM_ARC
: /* R_ARC_NONE. */
13699 case EM_ARC_COMPACT2
: /* R_ARC_NONE. */
13700 case EM_ARC_COMPACT
: /* R_ARC_NONE. */
13701 case EM_ARM
: /* R_ARM_NONE. */
13702 case EM_C166
: /* R_XC16X_NONE. */
13703 case EM_CRIS
: /* R_CRIS_NONE. */
13704 case EM_FT32
: /* R_FT32_NONE. */
13705 case EM_IA_64
: /* R_IA64_NONE. */
13706 case EM_K1OM
: /* R_X86_64_NONE. */
13707 case EM_L1OM
: /* R_X86_64_NONE. */
13708 case EM_M32R
: /* R_M32R_NONE. */
13709 case EM_MIPS
: /* R_MIPS_NONE. */
13710 case EM_MN10300
: /* R_MN10300_NONE. */
13711 case EM_MOXIE
: /* R_MOXIE_NONE. */
13712 case EM_NIOS32
: /* R_NIOS_NONE. */
13713 case EM_OR1K
: /* R_OR1K_NONE. */
13714 case EM_PARISC
: /* R_PARISC_NONE. */
13715 case EM_PPC64
: /* R_PPC64_NONE. */
13716 case EM_PPC
: /* R_PPC_NONE. */
13717 case EM_RISCV
: /* R_RISCV_NONE. */
13718 case EM_S390
: /* R_390_NONE. */
13720 case EM_SH
: /* R_SH_NONE. */
13721 case EM_SPARC32PLUS
:
13722 case EM_SPARC
: /* R_SPARC_NONE. */
13724 case EM_TILEGX
: /* R_TILEGX_NONE. */
13725 case EM_TILEPRO
: /* R_TILEPRO_NONE. */
13726 case EM_TI_C6000
:/* R_C6000_NONE. */
13727 case EM_X86_64
: /* R_X86_64_NONE. */
13729 case EM_Z80
: /* R_Z80_NONE. */
13730 case EM_WEBASSEMBLY
: /* R_WASM32_NONE. */
13731 return reloc_type
== 0;
13734 return reloc_type
== 0 || reloc_type
== 256;
13737 return (reloc_type
== 0 /* R_AVR_NONE. */
13738 || reloc_type
== 30 /* R_AVR_DIFF8. */
13739 || reloc_type
== 31 /* R_AVR_DIFF16. */
13740 || reloc_type
== 32 /* R_AVR_DIFF32. */);
13742 return reloc_type
== 3; /* R_METAG_NONE. */
13744 return (reloc_type
== 0 /* R_XTENSA_NONE. */
13745 || reloc_type
== 204 /* R_NDS32_DIFF8. */
13746 || reloc_type
== 205 /* R_NDS32_DIFF16. */
13747 || reloc_type
== 206 /* R_NDS32_DIFF32. */
13748 || reloc_type
== 207 /* R_NDS32_ULEB128. */);
13750 return (reloc_type
== 0 /* R_PRU_NONE. */
13751 || reloc_type
== 65 /* R_PRU_DIFF8. */
13752 || reloc_type
== 66 /* R_PRU_DIFF16. */
13753 || reloc_type
== 67 /* R_PRU_DIFF32. */);
13754 case EM_XTENSA_OLD
:
13756 return (reloc_type
== 0 /* R_XTENSA_NONE. */
13757 || reloc_type
== 17 /* R_XTENSA_DIFF8. */
13758 || reloc_type
== 18 /* R_XTENSA_DIFF16. */
13759 || reloc_type
== 19 /* R_XTENSA_DIFF32. */
13760 || reloc_type
== 57 /* R_XTENSA_PDIFF8. */
13761 || reloc_type
== 58 /* R_XTENSA_PDIFF16. */
13762 || reloc_type
== 59 /* R_XTENSA_PDIFF32. */
13763 || reloc_type
== 60 /* R_XTENSA_NDIFF8. */
13764 || reloc_type
== 61 /* R_XTENSA_NDIFF16. */
13765 || reloc_type
== 62 /* R_XTENSA_NDIFF32. */);
13770 /* Returns TRUE if there is a relocation against
13771 section NAME at OFFSET bytes. */
13774 reloc_at (struct dwarf_section
* dsec
, dwarf_vma offset
)
13776 Elf_Internal_Rela
* relocs
;
13777 Elf_Internal_Rela
* rp
;
13779 if (dsec
== NULL
|| dsec
->reloc_info
== NULL
)
13782 relocs
= (Elf_Internal_Rela
*) dsec
->reloc_info
;
13784 for (rp
= relocs
; rp
< relocs
+ dsec
->num_relocs
; ++rp
)
13785 if (rp
->r_offset
== offset
)
13791 /* Apply relocations to a section.
13792 Returns TRUE upon success, FALSE otherwise.
13793 If RELOCS_RETURN is non-NULL then it is set to point to the loaded relocs.
13794 It is then the caller's responsibility to free them. NUM_RELOCS_RETURN
13795 will be set to the number of relocs loaded.
13797 Note: So far support has been added only for those relocations
13798 which can be found in debug sections. FIXME: Add support for
13799 more relocations ? */
13802 apply_relocations (Filedata
* filedata
,
13803 const Elf_Internal_Shdr
* section
,
13804 unsigned char * start
,
13805 bfd_size_type size
,
13806 void ** relocs_return
,
13807 unsigned long * num_relocs_return
)
13809 Elf_Internal_Shdr
* relsec
;
13810 unsigned char * end
= start
+ size
;
13812 if (relocs_return
!= NULL
)
13814 * (Elf_Internal_Rela
**) relocs_return
= NULL
;
13815 * num_relocs_return
= 0;
13818 if (filedata
->file_header
.e_type
!= ET_REL
)
13819 /* No relocs to apply. */
13822 /* Find the reloc section associated with the section. */
13823 for (relsec
= filedata
->section_headers
;
13824 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
13827 bfd_boolean is_rela
;
13828 unsigned long num_relocs
;
13829 Elf_Internal_Rela
* relocs
;
13830 Elf_Internal_Rela
* rp
;
13831 Elf_Internal_Shdr
* symsec
;
13832 Elf_Internal_Sym
* symtab
;
13833 unsigned long num_syms
;
13834 Elf_Internal_Sym
* sym
;
13836 if ((relsec
->sh_type
!= SHT_RELA
&& relsec
->sh_type
!= SHT_REL
)
13837 || relsec
->sh_info
>= filedata
->file_header
.e_shnum
13838 || filedata
->section_headers
+ relsec
->sh_info
!= section
13839 || relsec
->sh_size
== 0
13840 || relsec
->sh_link
>= filedata
->file_header
.e_shnum
)
13843 symsec
= filedata
->section_headers
+ relsec
->sh_link
;
13844 if (symsec
->sh_type
!= SHT_SYMTAB
13845 && symsec
->sh_type
!= SHT_DYNSYM
)
13848 is_rela
= relsec
->sh_type
== SHT_RELA
;
13852 if (!slurp_rela_relocs (filedata
, relsec
->sh_offset
,
13853 relsec
->sh_size
, & relocs
, & num_relocs
))
13858 if (!slurp_rel_relocs (filedata
, relsec
->sh_offset
,
13859 relsec
->sh_size
, & relocs
, & num_relocs
))
13863 /* SH uses RELA but uses in place value instead of the addend field. */
13864 if (filedata
->file_header
.e_machine
== EM_SH
)
13867 symtab
= GET_ELF_SYMBOLS (filedata
, symsec
, & num_syms
);
13869 for (rp
= relocs
; rp
< relocs
+ num_relocs
; ++rp
)
13872 unsigned int reloc_type
;
13873 unsigned int reloc_size
;
13874 bfd_boolean reloc_inplace
= FALSE
;
13875 bfd_boolean reloc_subtract
= FALSE
;
13876 unsigned char * rloc
;
13877 unsigned long sym_index
;
13879 reloc_type
= get_reloc_type (filedata
, rp
->r_info
);
13881 if (target_specific_reloc_handling (filedata
, rp
, start
, end
, symtab
, num_syms
))
13883 else if (is_none_reloc (filedata
, reloc_type
))
13885 else if (is_32bit_abs_reloc (filedata
, reloc_type
)
13886 || is_32bit_pcrel_reloc (filedata
, reloc_type
))
13888 else if (is_64bit_abs_reloc (filedata
, reloc_type
)
13889 || is_64bit_pcrel_reloc (filedata
, reloc_type
))
13891 else if (is_24bit_abs_reloc (filedata
, reloc_type
))
13893 else if (is_16bit_abs_reloc (filedata
, reloc_type
))
13895 else if (is_8bit_abs_reloc (filedata
, reloc_type
)
13896 || is_6bit_abs_reloc (filedata
, reloc_type
))
13898 else if ((reloc_subtract
= is_32bit_inplace_sub_reloc (filedata
,
13900 || is_32bit_inplace_add_reloc (filedata
, reloc_type
))
13903 reloc_inplace
= TRUE
;
13905 else if ((reloc_subtract
= is_64bit_inplace_sub_reloc (filedata
,
13907 || is_64bit_inplace_add_reloc (filedata
, reloc_type
))
13910 reloc_inplace
= TRUE
;
13912 else if ((reloc_subtract
= is_16bit_inplace_sub_reloc (filedata
,
13914 || is_16bit_inplace_add_reloc (filedata
, reloc_type
))
13917 reloc_inplace
= TRUE
;
13919 else if ((reloc_subtract
= is_8bit_inplace_sub_reloc (filedata
,
13921 || is_8bit_inplace_add_reloc (filedata
, reloc_type
))
13924 reloc_inplace
= TRUE
;
13926 else if ((reloc_subtract
= is_6bit_inplace_sub_reloc (filedata
,
13930 reloc_inplace
= TRUE
;
13934 static unsigned int prev_reloc
= 0;
13936 if (reloc_type
!= prev_reloc
)
13937 warn (_("unable to apply unsupported reloc type %d to section %s\n"),
13938 reloc_type
, printable_section_name (filedata
, section
));
13939 prev_reloc
= reloc_type
;
13943 rloc
= start
+ rp
->r_offset
;
13944 if (!IN_RANGE (start
, end
, rloc
, reloc_size
))
13946 warn (_("skipping invalid relocation offset 0x%lx in section %s\n"),
13947 (unsigned long) rp
->r_offset
,
13948 printable_section_name (filedata
, section
));
13952 sym_index
= (unsigned long) get_reloc_symindex (rp
->r_info
);
13953 if (sym_index
>= num_syms
)
13955 warn (_("skipping invalid relocation symbol index 0x%lx in section %s\n"),
13956 sym_index
, printable_section_name (filedata
, section
));
13959 sym
= symtab
+ sym_index
;
13961 /* If the reloc has a symbol associated with it,
13962 make sure that it is of an appropriate type.
13964 Relocations against symbols without type can happen.
13965 Gcc -feliminate-dwarf2-dups may generate symbols
13966 without type for debug info.
13968 Icc generates relocations against function symbols
13969 instead of local labels.
13971 Relocations against object symbols can happen, eg when
13972 referencing a global array. For an example of this see
13973 the _clz.o binary in libgcc.a. */
13975 && ELF_ST_TYPE (sym
->st_info
) != STT_COMMON
13976 && ELF_ST_TYPE (sym
->st_info
) > STT_SECTION
)
13978 warn (_("skipping unexpected symbol type %s in section %s relocation %ld\n"),
13979 get_symbol_type (filedata
, ELF_ST_TYPE (sym
->st_info
)),
13980 printable_section_name (filedata
, relsec
),
13981 (long int)(rp
- relocs
));
13987 addend
+= rp
->r_addend
;
13988 /* R_XTENSA_32, R_PJ_DATA_DIR32 and R_D30V_32_NORMAL are
13989 partial_inplace. */
13991 || (filedata
->file_header
.e_machine
== EM_XTENSA
13992 && reloc_type
== 1)
13993 || ((filedata
->file_header
.e_machine
== EM_PJ
13994 || filedata
->file_header
.e_machine
== EM_PJ_OLD
)
13995 && reloc_type
== 1)
13996 || ((filedata
->file_header
.e_machine
== EM_D30V
13997 || filedata
->file_header
.e_machine
== EM_CYGNUS_D30V
)
13998 && reloc_type
== 12)
14001 if (is_6bit_inplace_sub_reloc (filedata
, reloc_type
))
14002 addend
+= byte_get (rloc
, reloc_size
) & 0x3f;
14004 addend
+= byte_get (rloc
, reloc_size
);
14007 if (is_32bit_pcrel_reloc (filedata
, reloc_type
)
14008 || is_64bit_pcrel_reloc (filedata
, reloc_type
))
14010 /* On HPPA, all pc-relative relocations are biased by 8. */
14011 if (filedata
->file_header
.e_machine
== EM_PARISC
)
14013 byte_put (rloc
, (addend
+ sym
->st_value
) - rp
->r_offset
,
14016 else if (is_6bit_abs_reloc (filedata
, reloc_type
)
14017 || is_6bit_inplace_sub_reloc (filedata
, reloc_type
))
14019 if (reloc_subtract
)
14020 addend
-= sym
->st_value
;
14022 addend
+= sym
->st_value
;
14023 addend
= (addend
& 0x3f) | (byte_get (rloc
, reloc_size
) & 0xc0);
14024 byte_put (rloc
, addend
, reloc_size
);
14026 else if (reloc_subtract
)
14027 byte_put (rloc
, addend
- sym
->st_value
, reloc_size
);
14029 byte_put (rloc
, addend
+ sym
->st_value
, reloc_size
);
14033 /* Let the target specific reloc processing code know that
14034 we have finished with these relocs. */
14035 target_specific_reloc_handling (filedata
, NULL
, NULL
, NULL
, NULL
, 0);
14039 * (Elf_Internal_Rela
**) relocs_return
= relocs
;
14040 * num_relocs_return
= num_relocs
;
14051 #ifdef SUPPORT_DISASSEMBLY
14053 disassemble_section (Elf_Internal_Shdr
* section
, Filedata
* filedata
)
14055 printf (_("\nAssembly dump of section %s\n"), printable_section_name (filedata
, section
));
14057 /* FIXME: XXX -- to be done --- XXX */
14063 /* Reads in the contents of SECTION from FILE, returning a pointer
14064 to a malloc'ed buffer or NULL if something went wrong. */
14067 get_section_contents (Elf_Internal_Shdr
* section
, Filedata
* filedata
)
14069 bfd_size_type num_bytes
= section
->sh_size
;
14071 if (num_bytes
== 0 || section
->sh_type
== SHT_NOBITS
)
14073 printf (_("Section '%s' has no data to dump.\n"),
14074 printable_section_name (filedata
, section
));
14078 return (char *) get_data (NULL
, filedata
, section
->sh_offset
, 1, num_bytes
,
14079 _("section contents"));
14082 /* Uncompresses a section that was compressed using zlib, in place. */
14085 uncompress_section_contents (unsigned char ** buffer
,
14086 dwarf_size_type uncompressed_size
,
14087 dwarf_size_type
* size
)
14089 dwarf_size_type compressed_size
= *size
;
14090 unsigned char * compressed_buffer
= *buffer
;
14091 unsigned char * uncompressed_buffer
;
14095 /* It is possible the section consists of several compressed
14096 buffers concatenated together, so we uncompress in a loop. */
14097 /* PR 18313: The state field in the z_stream structure is supposed
14098 to be invisible to the user (ie us), but some compilers will
14099 still complain about it being used without initialisation. So
14100 we first zero the entire z_stream structure and then set the fields
14102 memset (& strm
, 0, sizeof strm
);
14103 strm
.avail_in
= compressed_size
;
14104 strm
.next_in
= (Bytef
*) compressed_buffer
;
14105 strm
.avail_out
= uncompressed_size
;
14106 uncompressed_buffer
= (unsigned char *) xmalloc (uncompressed_size
);
14108 rc
= inflateInit (& strm
);
14109 while (strm
.avail_in
> 0)
14113 strm
.next_out
= ((Bytef
*) uncompressed_buffer
14114 + (uncompressed_size
- strm
.avail_out
));
14115 rc
= inflate (&strm
, Z_FINISH
);
14116 if (rc
!= Z_STREAM_END
)
14118 rc
= inflateReset (& strm
);
14120 rc
= inflateEnd (& strm
);
14122 || strm
.avail_out
!= 0)
14125 *buffer
= uncompressed_buffer
;
14126 *size
= uncompressed_size
;
14130 free (uncompressed_buffer
);
14131 /* Indicate decompression failure. */
14137 dump_section_as_strings (Elf_Internal_Shdr
* section
, Filedata
* filedata
)
14139 Elf_Internal_Shdr
* relsec
;
14140 bfd_size_type num_bytes
;
14141 unsigned char * data
;
14142 unsigned char * end
;
14143 unsigned char * real_start
;
14144 unsigned char * start
;
14145 bfd_boolean some_strings_shown
;
14147 real_start
= start
= (unsigned char *) get_section_contents (section
, filedata
);
14149 /* PR 21820: Do not fail if the section was empty. */
14150 return (section
->sh_size
== 0 || section
->sh_type
== SHT_NOBITS
) ? TRUE
: FALSE
;
14152 num_bytes
= section
->sh_size
;
14154 printf (_("\nString dump of section '%s':\n"), printable_section_name (filedata
, section
));
14156 if (decompress_dumps
)
14158 dwarf_size_type new_size
= num_bytes
;
14159 dwarf_size_type uncompressed_size
= 0;
14161 if ((section
->sh_flags
& SHF_COMPRESSED
) != 0)
14163 Elf_Internal_Chdr chdr
;
14164 unsigned int compression_header_size
14165 = get_compression_header (& chdr
, (unsigned char *) start
,
14167 if (compression_header_size
== 0)
14168 /* An error message will have already been generated
14169 by get_compression_header. */
14172 if (chdr
.ch_type
!= ELFCOMPRESS_ZLIB
)
14174 warn (_("section '%s' has unsupported compress type: %d\n"),
14175 printable_section_name (filedata
, section
), chdr
.ch_type
);
14178 uncompressed_size
= chdr
.ch_size
;
14179 start
+= compression_header_size
;
14180 new_size
-= compression_header_size
;
14182 else if (new_size
> 12 && streq ((char *) start
, "ZLIB"))
14184 /* Read the zlib header. In this case, it should be "ZLIB"
14185 followed by the uncompressed section size, 8 bytes in
14186 big-endian order. */
14187 uncompressed_size
= start
[4]; uncompressed_size
<<= 8;
14188 uncompressed_size
+= start
[5]; uncompressed_size
<<= 8;
14189 uncompressed_size
+= start
[6]; uncompressed_size
<<= 8;
14190 uncompressed_size
+= start
[7]; uncompressed_size
<<= 8;
14191 uncompressed_size
+= start
[8]; uncompressed_size
<<= 8;
14192 uncompressed_size
+= start
[9]; uncompressed_size
<<= 8;
14193 uncompressed_size
+= start
[10]; uncompressed_size
<<= 8;
14194 uncompressed_size
+= start
[11];
14199 if (uncompressed_size
)
14201 if (uncompress_section_contents (& start
,
14202 uncompressed_size
, & new_size
))
14203 num_bytes
= new_size
;
14206 error (_("Unable to decompress section %s\n"),
14207 printable_section_name (filedata
, section
));
14212 start
= real_start
;
14215 /* If the section being dumped has relocations against it the user might
14216 be expecting these relocations to have been applied. Check for this
14217 case and issue a warning message in order to avoid confusion.
14218 FIXME: Maybe we ought to have an option that dumps a section with
14219 relocs applied ? */
14220 for (relsec
= filedata
->section_headers
;
14221 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
14224 if ((relsec
->sh_type
!= SHT_RELA
&& relsec
->sh_type
!= SHT_REL
)
14225 || relsec
->sh_info
>= filedata
->file_header
.e_shnum
14226 || filedata
->section_headers
+ relsec
->sh_info
!= section
14227 || relsec
->sh_size
== 0
14228 || relsec
->sh_link
>= filedata
->file_header
.e_shnum
)
14231 printf (_(" Note: This section has relocations against it, but these have NOT been applied to this dump.\n"));
14236 end
= start
+ num_bytes
;
14237 some_strings_shown
= FALSE
;
14239 #ifdef HAVE_MBSTATE_T
14241 /* Initialise the multibyte conversion state. */
14242 memset (& state
, 0, sizeof (state
));
14245 bfd_boolean continuing
= FALSE
;
14249 while (!ISPRINT (* data
))
14250 if (++ data
>= end
)
14255 size_t maxlen
= end
- data
;
14260 continuing
= FALSE
;
14264 printf (" [%6lx] ", (unsigned long) (data
- start
));
14278 /* PR 25543: Treat new-lines as string-ending characters. */
14287 /* Do not print control characters directly as they can affect terminal
14288 settings. Such characters usually appear in the names generated
14289 by the assembler for local labels. */
14292 printf ("^%c", c
+ 0x40);
14294 else if (ISPRINT (c
))
14301 #ifdef HAVE_MBSTATE_T
14304 /* Let printf do the hard work of displaying multibyte characters. */
14305 printf ("%.1s", data
- 1);
14306 #ifdef HAVE_MBSTATE_T
14307 /* Try to find out how many bytes made up the character that was
14308 just printed. Advance the symbol pointer past the bytes that
14310 n
= mbrtowc (& w
, (char *)(data
- 1), MB_CUR_MAX
, & state
);
14314 if (n
!= (size_t) -1 && n
!= (size_t) -2 && n
> 0)
14324 printf (_("<corrupt>\n"));
14327 some_strings_shown
= TRUE
;
14331 if (! some_strings_shown
)
14332 printf (_(" No strings found in this section."));
14345 dump_section_as_bytes (Elf_Internal_Shdr
* section
,
14346 Filedata
* filedata
,
14347 bfd_boolean relocate
)
14349 Elf_Internal_Shdr
* relsec
;
14350 bfd_size_type bytes
;
14351 bfd_size_type section_size
;
14353 unsigned char * data
;
14354 unsigned char * real_start
;
14355 unsigned char * start
;
14357 real_start
= start
= (unsigned char *) get_section_contents (section
, filedata
);
14359 /* PR 21820: Do not fail if the section was empty. */
14360 return (section
->sh_size
== 0 || section
->sh_type
== SHT_NOBITS
) ? TRUE
: FALSE
;
14362 section_size
= section
->sh_size
;
14364 printf (_("\nHex dump of section '%s':\n"), printable_section_name (filedata
, section
));
14366 if (decompress_dumps
)
14368 dwarf_size_type new_size
= section_size
;
14369 dwarf_size_type uncompressed_size
= 0;
14371 if ((section
->sh_flags
& SHF_COMPRESSED
) != 0)
14373 Elf_Internal_Chdr chdr
;
14374 unsigned int compression_header_size
14375 = get_compression_header (& chdr
, start
, section_size
);
14377 if (compression_header_size
== 0)
14378 /* An error message will have already been generated
14379 by get_compression_header. */
14382 if (chdr
.ch_type
!= ELFCOMPRESS_ZLIB
)
14384 warn (_("section '%s' has unsupported compress type: %d\n"),
14385 printable_section_name (filedata
, section
), chdr
.ch_type
);
14388 uncompressed_size
= chdr
.ch_size
;
14389 start
+= compression_header_size
;
14390 new_size
-= compression_header_size
;
14392 else if (new_size
> 12 && streq ((char *) start
, "ZLIB"))
14394 /* Read the zlib header. In this case, it should be "ZLIB"
14395 followed by the uncompressed section size, 8 bytes in
14396 big-endian order. */
14397 uncompressed_size
= start
[4]; uncompressed_size
<<= 8;
14398 uncompressed_size
+= start
[5]; uncompressed_size
<<= 8;
14399 uncompressed_size
+= start
[6]; uncompressed_size
<<= 8;
14400 uncompressed_size
+= start
[7]; uncompressed_size
<<= 8;
14401 uncompressed_size
+= start
[8]; uncompressed_size
<<= 8;
14402 uncompressed_size
+= start
[9]; uncompressed_size
<<= 8;
14403 uncompressed_size
+= start
[10]; uncompressed_size
<<= 8;
14404 uncompressed_size
+= start
[11];
14409 if (uncompressed_size
)
14411 if (uncompress_section_contents (& start
, uncompressed_size
,
14414 section_size
= new_size
;
14418 error (_("Unable to decompress section %s\n"),
14419 printable_section_name (filedata
, section
));
14420 /* FIXME: Print the section anyway ? */
14425 start
= real_start
;
14430 if (! apply_relocations (filedata
, section
, start
, section_size
, NULL
, NULL
))
14435 /* If the section being dumped has relocations against it the user might
14436 be expecting these relocations to have been applied. Check for this
14437 case and issue a warning message in order to avoid confusion.
14438 FIXME: Maybe we ought to have an option that dumps a section with
14439 relocs applied ? */
14440 for (relsec
= filedata
->section_headers
;
14441 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
14444 if ((relsec
->sh_type
!= SHT_RELA
&& relsec
->sh_type
!= SHT_REL
)
14445 || relsec
->sh_info
>= filedata
->file_header
.e_shnum
14446 || filedata
->section_headers
+ relsec
->sh_info
!= section
14447 || relsec
->sh_size
== 0
14448 || relsec
->sh_link
>= filedata
->file_header
.e_shnum
)
14451 printf (_(" NOTE: This section has relocations against it, but these have NOT been applied to this dump.\n"));
14456 addr
= section
->sh_addr
;
14457 bytes
= section_size
;
14466 lbytes
= (bytes
> 16 ? 16 : bytes
);
14468 printf (" 0x%8.8lx ", (unsigned long) addr
);
14470 for (j
= 0; j
< 16; j
++)
14473 printf ("%2.2x", data
[j
]);
14481 for (j
= 0; j
< lbytes
; j
++)
14484 if (k
>= ' ' && k
< 0x7f)
14507 #ifdef ENABLE_LIBCTF
14508 static ctf_sect_t
*
14509 shdr_to_ctf_sect (ctf_sect_t
*buf
, Elf_Internal_Shdr
*shdr
, Filedata
*filedata
)
14511 buf
->cts_name
= SECTION_NAME (shdr
);
14512 buf
->cts_size
= shdr
->sh_size
;
14513 buf
->cts_entsize
= shdr
->sh_entsize
;
14518 /* Formatting callback function passed to ctf_dump. Returns either the pointer
14519 it is passed, or a pointer to newly-allocated storage, in which case
14520 dump_ctf() will free it when it no longer needs it. */
14523 dump_ctf_indent_lines (ctf_sect_names_t sect ATTRIBUTE_UNUSED
,
14524 char *s
, void *arg
)
14526 const char *blanks
= arg
;
14529 if (asprintf (&new_s
, "%s%s", blanks
, s
) < 0)
14534 /* Dump CTF errors/warnings. */
14536 dump_ctf_errs (ctf_file_t
*fp
)
14538 ctf_next_t
*it
= NULL
;
14543 /* Dump accumulated errors and warnings. */
14544 while ((errtext
= ctf_errwarning_next (fp
, &it
, &is_warning
, &err
)) != NULL
)
14546 error (_("%s: %s"), is_warning
? _("warning"): _("error"),
14550 if (err
!= ECTF_NEXT_END
)
14551 error (_("CTF error: cannot get CTF errors: `%s'"), ctf_errmsg (err
));
14554 /* Dump one CTF archive member. */
14557 dump_ctf_archive_member (ctf_file_t
*ctf
, const char *name
, void *arg
)
14559 ctf_file_t
*parent
= (ctf_file_t
*) arg
;
14560 const char *things
[] = {"Header", "Labels", "Data objects",
14561 "Function objects", "Variables", "Types", "Strings",
14563 const char **thing
;
14567 /* Only print out the name of non-default-named archive members.
14568 The name .ctf appears everywhere, even for things that aren't
14569 really archives, so printing it out is liable to be confusing.
14571 The parent, if there is one, is the default-owned archive member:
14572 avoid importing it into itself. (This does no harm, but looks
14575 if (strcmp (name
, ".ctf") != 0)
14577 printf (_("\nCTF archive member: %s:\n"), name
);
14578 ctf_import (ctf
, parent
);
14581 for (i
= 0, thing
= things
; *thing
[0]; thing
++, i
++)
14583 ctf_dump_state_t
*s
= NULL
;
14586 printf ("\n %s:\n", *thing
);
14587 while ((item
= ctf_dump (ctf
, &s
, i
, dump_ctf_indent_lines
,
14588 (void *) " ")) != NULL
)
14590 printf ("%s\n", item
);
14594 if (ctf_errno (ctf
))
14596 error (_("Iteration failed: %s, %s\n"), *thing
,
14597 ctf_errmsg (ctf_errno (ctf
)));
14604 dump_ctf_errs (ctf
);
14609 dump_section_as_ctf (Elf_Internal_Shdr
* section
, Filedata
* filedata
)
14611 Elf_Internal_Shdr
* parent_sec
= NULL
;
14612 Elf_Internal_Shdr
* symtab_sec
= NULL
;
14613 Elf_Internal_Shdr
* strtab_sec
= NULL
;
14614 void * data
= NULL
;
14615 void * symdata
= NULL
;
14616 void * strdata
= NULL
;
14617 void * parentdata
= NULL
;
14618 ctf_sect_t ctfsect
, symsect
, strsect
, parentsect
;
14619 ctf_sect_t
* symsectp
= NULL
;
14620 ctf_sect_t
* strsectp
= NULL
;
14621 ctf_archive_t
* ctfa
= NULL
;
14622 ctf_archive_t
* parenta
= NULL
, *lookparent
;
14623 ctf_file_t
* parent
= NULL
;
14626 bfd_boolean ret
= FALSE
;
14628 shdr_to_ctf_sect (&ctfsect
, section
, filedata
);
14629 data
= get_section_contents (section
, filedata
);
14630 ctfsect
.cts_data
= data
;
14632 if (!dump_ctf_symtab_name
)
14633 dump_ctf_symtab_name
= strdup (".symtab");
14635 if (!dump_ctf_strtab_name
)
14636 dump_ctf_strtab_name
= strdup (".strtab");
14638 if (dump_ctf_symtab_name
&& dump_ctf_symtab_name
[0] != 0)
14640 if ((symtab_sec
= find_section (filedata
, dump_ctf_symtab_name
)) == NULL
)
14642 error (_("No symbol section named %s\n"), dump_ctf_symtab_name
);
14645 if ((symdata
= (void *) get_data (NULL
, filedata
,
14646 symtab_sec
->sh_offset
, 1,
14647 symtab_sec
->sh_size
,
14648 _("symbols"))) == NULL
)
14650 symsectp
= shdr_to_ctf_sect (&symsect
, symtab_sec
, filedata
);
14651 symsect
.cts_data
= symdata
;
14653 if (dump_ctf_strtab_name
&& dump_ctf_strtab_name
[0] != 0)
14655 if ((strtab_sec
= find_section (filedata
, dump_ctf_strtab_name
)) == NULL
)
14657 error (_("No string table section named %s\n"),
14658 dump_ctf_strtab_name
);
14661 if ((strdata
= (void *) get_data (NULL
, filedata
,
14662 strtab_sec
->sh_offset
, 1,
14663 strtab_sec
->sh_size
,
14664 _("strings"))) == NULL
)
14666 strsectp
= shdr_to_ctf_sect (&strsect
, strtab_sec
, filedata
);
14667 strsect
.cts_data
= strdata
;
14669 if (dump_ctf_parent_name
)
14671 if ((parent_sec
= find_section (filedata
, dump_ctf_parent_name
)) == NULL
)
14673 error (_("No CTF parent section named %s\n"), dump_ctf_parent_name
);
14676 if ((parentdata
= (void *) get_data (NULL
, filedata
,
14677 parent_sec
->sh_offset
, 1,
14678 parent_sec
->sh_size
,
14679 _("CTF parent"))) == NULL
)
14681 shdr_to_ctf_sect (&parentsect
, parent_sec
, filedata
);
14682 parentsect
.cts_data
= parentdata
;
14685 /* Load the CTF file and dump it. It may be a raw CTF section, or an archive:
14686 libctf papers over the difference, so we can pretend it is always an
14687 archive. Possibly open the parent as well, if one was specified. */
14689 if ((ctfa
= ctf_arc_bufopen (&ctfsect
, symsectp
, strsectp
, &err
)) == NULL
)
14691 dump_ctf_errs (NULL
);
14692 error (_("CTF open failure: %s\n"), ctf_errmsg (err
));
14698 if ((parenta
= ctf_arc_bufopen (&parentsect
, symsectp
, strsectp
,
14701 dump_ctf_errs (NULL
);
14702 error (_("CTF open failure: %s\n"), ctf_errmsg (err
));
14705 lookparent
= parenta
;
14710 /* Assume that the applicable parent archive member is the default one.
14711 (This is what all known implementations are expected to do, if they
14712 put CTFs and their parents in archives together.) */
14713 if ((parent
= ctf_arc_open_by_name (lookparent
, NULL
, &err
)) == NULL
)
14715 dump_ctf_errs (NULL
);
14716 error (_("CTF open failure: %s\n"), ctf_errmsg (err
));
14722 printf (_("\nDump of CTF section '%s':\n"),
14723 printable_section_name (filedata
, section
));
14725 if (ctf_archive_iter (ctfa
, dump_ctf_archive_member
, parent
) != 0)
14729 ctf_file_close (parent
);
14731 ctf_close (parenta
);
14741 load_specific_debug_section (enum dwarf_section_display_enum debug
,
14742 const Elf_Internal_Shdr
* sec
,
14745 struct dwarf_section
* section
= &debug_displays
[debug
].section
;
14747 Filedata
* filedata
= (Filedata
*) data
;
14749 if (section
->start
!= NULL
)
14751 /* If it is already loaded, do nothing. */
14752 if (streq (section
->filename
, filedata
->file_name
))
14754 free (section
->start
);
14757 snprintf (buf
, sizeof (buf
), _("%s section data"), section
->name
);
14758 section
->address
= sec
->sh_addr
;
14759 section
->user_data
= NULL
;
14760 section
->filename
= filedata
->file_name
;
14761 section
->start
= (unsigned char *) get_data (NULL
, filedata
,
14763 sec
->sh_size
, buf
);
14764 if (section
->start
== NULL
)
14768 unsigned char *start
= section
->start
;
14769 dwarf_size_type size
= sec
->sh_size
;
14770 dwarf_size_type uncompressed_size
= 0;
14772 if ((sec
->sh_flags
& SHF_COMPRESSED
) != 0)
14774 Elf_Internal_Chdr chdr
;
14775 unsigned int compression_header_size
;
14777 if (size
< (is_32bit_elf
14778 ? sizeof (Elf32_External_Chdr
)
14779 : sizeof (Elf64_External_Chdr
)))
14781 warn (_("compressed section %s is too small to contain a compression header\n"),
14786 compression_header_size
= get_compression_header (&chdr
, start
, size
);
14787 if (compression_header_size
== 0)
14788 /* An error message will have already been generated
14789 by get_compression_header. */
14792 if (chdr
.ch_type
!= ELFCOMPRESS_ZLIB
)
14794 warn (_("section '%s' has unsupported compress type: %d\n"),
14795 section
->name
, chdr
.ch_type
);
14798 uncompressed_size
= chdr
.ch_size
;
14799 start
+= compression_header_size
;
14800 size
-= compression_header_size
;
14802 else if (size
> 12 && streq ((char *) start
, "ZLIB"))
14804 /* Read the zlib header. In this case, it should be "ZLIB"
14805 followed by the uncompressed section size, 8 bytes in
14806 big-endian order. */
14807 uncompressed_size
= start
[4]; uncompressed_size
<<= 8;
14808 uncompressed_size
+= start
[5]; uncompressed_size
<<= 8;
14809 uncompressed_size
+= start
[6]; uncompressed_size
<<= 8;
14810 uncompressed_size
+= start
[7]; uncompressed_size
<<= 8;
14811 uncompressed_size
+= start
[8]; uncompressed_size
<<= 8;
14812 uncompressed_size
+= start
[9]; uncompressed_size
<<= 8;
14813 uncompressed_size
+= start
[10]; uncompressed_size
<<= 8;
14814 uncompressed_size
+= start
[11];
14819 if (uncompressed_size
)
14821 if (uncompress_section_contents (&start
, uncompressed_size
,
14824 /* Free the compressed buffer, update the section buffer
14825 and the section size if uncompress is successful. */
14826 free (section
->start
);
14827 section
->start
= start
;
14831 error (_("Unable to decompress section %s\n"),
14832 printable_section_name (filedata
, sec
));
14837 section
->size
= size
;
14840 if (section
->start
== NULL
)
14843 if (debug_displays
[debug
].relocate
)
14845 if (! apply_relocations (filedata
, sec
, section
->start
, section
->size
,
14846 & section
->reloc_info
, & section
->num_relocs
))
14851 section
->reloc_info
= NULL
;
14852 section
->num_relocs
= 0;
14858 #if HAVE_LIBDEBUGINFOD
14859 /* Return a hex string representation of the build-id. */
14861 get_build_id (void * data
)
14863 Filedata
* filedata
= (Filedata
*)data
;
14864 Elf_Internal_Shdr
* shdr
;
14867 /* Iterate through notes to find note.gnu.build-id.
14868 FIXME: Only the first note in any note section is examined. */
14869 for (i
= 0, shdr
= filedata
->section_headers
;
14870 i
< filedata
->file_header
.e_shnum
&& shdr
!= NULL
;
14873 if (shdr
->sh_type
!= SHT_NOTE
)
14878 size_t data_remaining
;
14880 Elf_External_Note
* enote
;
14881 Elf_Internal_Note inote
;
14883 bfd_vma offset
= shdr
->sh_offset
;
14884 bfd_vma align
= shdr
->sh_addralign
;
14885 bfd_vma length
= shdr
->sh_size
;
14887 enote
= (Elf_External_Note
*) get_section_contents (shdr
, filedata
);
14893 else if (align
!= 4 && align
!= 8)
14899 end
= (char *) enote
+ length
;
14900 data_remaining
= end
- (char *) enote
;
14902 if (!is_ia64_vms (filedata
))
14904 min_notesz
= offsetof (Elf_External_Note
, name
);
14905 if (data_remaining
< min_notesz
)
14908 malformed note encountered in section %s whilst scanning for build-id note\n"),
14909 printable_section_name (filedata
, shdr
));
14913 data_remaining
-= min_notesz
;
14915 inote
.type
= BYTE_GET (enote
->type
);
14916 inote
.namesz
= BYTE_GET (enote
->namesz
);
14917 inote
.namedata
= enote
->name
;
14918 inote
.descsz
= BYTE_GET (enote
->descsz
);
14919 inote
.descdata
= ((char *) enote
14920 + ELF_NOTE_DESC_OFFSET (inote
.namesz
, align
));
14921 inote
.descpos
= offset
+ (inote
.descdata
- (char *) enote
);
14922 next
= ((char *) enote
14923 + ELF_NOTE_NEXT_OFFSET (inote
.namesz
, inote
.descsz
, align
));
14927 Elf64_External_VMS_Note
*vms_enote
;
14929 /* PR binutils/15191
14930 Make sure that there is enough data to read. */
14931 min_notesz
= offsetof (Elf64_External_VMS_Note
, name
);
14932 if (data_remaining
< min_notesz
)
14935 malformed note encountered in section %s whilst scanning for build-id note\n"),
14936 printable_section_name (filedata
, shdr
));
14940 data_remaining
-= min_notesz
;
14942 vms_enote
= (Elf64_External_VMS_Note
*) enote
;
14943 inote
.type
= BYTE_GET (vms_enote
->type
);
14944 inote
.namesz
= BYTE_GET (vms_enote
->namesz
);
14945 inote
.namedata
= vms_enote
->name
;
14946 inote
.descsz
= BYTE_GET (vms_enote
->descsz
);
14947 inote
.descdata
= inote
.namedata
+ align_power (inote
.namesz
, 3);
14948 inote
.descpos
= offset
+ (inote
.descdata
- (char *) enote
);
14949 next
= inote
.descdata
+ align_power (inote
.descsz
, 3);
14952 /* Skip malformed notes. */
14953 if ((size_t) (inote
.descdata
- inote
.namedata
) < inote
.namesz
14954 || (size_t) (inote
.descdata
- inote
.namedata
) > data_remaining
14955 || (size_t) (next
- inote
.descdata
) < inote
.descsz
14956 || ((size_t) (next
- inote
.descdata
)
14957 > data_remaining
- (size_t) (inote
.descdata
- inote
.namedata
)))
14960 malformed note encountered in section %s whilst scanning for build-id note\n"),
14961 printable_section_name (filedata
, shdr
));
14966 /* Check if this is the build-id note. If so then convert the build-id
14967 bytes to a hex string. */
14968 if (inote
.namesz
> 0
14969 && const_strneq (inote
.namedata
, "GNU")
14970 && inote
.type
== NT_GNU_BUILD_ID
)
14975 build_id
= malloc (inote
.descsz
* 2 + 1);
14976 if (build_id
== NULL
)
14982 for (j
= 0; j
< inote
.descsz
; ++j
)
14983 sprintf (build_id
+ (j
* 2), "%02x", inote
.descdata
[j
] & 0xff);
14984 build_id
[inote
.descsz
* 2] = '\0';
14987 return (unsigned char *) build_id
;
14994 #endif /* HAVE_LIBDEBUGINFOD */
14996 /* If this is not NULL, load_debug_section will only look for sections
14997 within the list of sections given here. */
14998 static unsigned int * section_subset
= NULL
;
15001 load_debug_section (enum dwarf_section_display_enum debug
, void * data
)
15003 struct dwarf_section
* section
= &debug_displays
[debug
].section
;
15004 Elf_Internal_Shdr
* sec
;
15005 Filedata
* filedata
= (Filedata
*) data
;
15007 /* Without section headers we cannot find any sections. */
15008 if (filedata
->section_headers
== NULL
)
15011 if (filedata
->string_table
== NULL
15012 && filedata
->file_header
.e_shstrndx
!= SHN_UNDEF
15013 && filedata
->file_header
.e_shstrndx
< filedata
->file_header
.e_shnum
)
15015 Elf_Internal_Shdr
* strs
;
15017 /* Read in the string table, so that we have section names to scan. */
15018 strs
= filedata
->section_headers
+ filedata
->file_header
.e_shstrndx
;
15020 if (strs
!= NULL
&& strs
->sh_size
!= 0)
15022 filedata
->string_table
15023 = (char *) get_data (NULL
, filedata
, strs
->sh_offset
,
15024 1, strs
->sh_size
, _("string table"));
15026 filedata
->string_table_length
15027 = filedata
->string_table
!= NULL
? strs
->sh_size
: 0;
15031 /* Locate the debug section. */
15032 sec
= find_section_in_set (filedata
, section
->uncompressed_name
, section_subset
);
15034 section
->name
= section
->uncompressed_name
;
15037 sec
= find_section_in_set (filedata
, section
->compressed_name
, section_subset
);
15039 section
->name
= section
->compressed_name
;
15044 /* If we're loading from a subset of sections, and we've loaded
15045 a section matching this name before, it's likely that it's a
15047 if (section_subset
!= NULL
)
15048 free_debug_section (debug
);
15050 return load_specific_debug_section (debug
, sec
, data
);
15054 free_debug_section (enum dwarf_section_display_enum debug
)
15056 struct dwarf_section
* section
= &debug_displays
[debug
].section
;
15058 if (section
->start
== NULL
)
15061 free ((char *) section
->start
);
15062 section
->start
= NULL
;
15063 section
->address
= 0;
15066 free (section
->reloc_info
);
15067 section
->reloc_info
= NULL
;
15068 section
->num_relocs
= 0;
15072 display_debug_section (int shndx
, Elf_Internal_Shdr
* section
, Filedata
* filedata
)
15074 char * name
= SECTION_NAME (section
);
15075 const char * print_name
= printable_section_name (filedata
, section
);
15076 bfd_size_type length
;
15077 bfd_boolean result
= TRUE
;
15080 length
= section
->sh_size
;
15083 printf (_("\nSection '%s' has no debugging data.\n"), print_name
);
15086 if (section
->sh_type
== SHT_NOBITS
)
15088 /* There is no point in dumping the contents of a debugging section
15089 which has the NOBITS type - the bits in the file will be random.
15090 This can happen when a file containing a .eh_frame section is
15091 stripped with the --only-keep-debug command line option. */
15092 printf (_("section '%s' has the NOBITS type - its contents are unreliable.\n"),
15097 if (const_strneq (name
, ".gnu.linkonce.wi."))
15098 name
= ".debug_info";
15100 /* See if we know how to display the contents of this section. */
15101 for (i
= 0; i
< max
; i
++)
15103 enum dwarf_section_display_enum id
= (enum dwarf_section_display_enum
) i
;
15104 struct dwarf_section_display
* display
= debug_displays
+ i
;
15105 struct dwarf_section
* sec
= & display
->section
;
15107 if (streq (sec
->uncompressed_name
, name
)
15108 || (id
== line
&& const_strneq (name
, ".debug_line."))
15109 || streq (sec
->compressed_name
, name
))
15111 bfd_boolean secondary
= (section
!= find_section (filedata
, name
));
15114 free_debug_section (id
);
15116 if (i
== line
&& const_strneq (name
, ".debug_line."))
15118 else if (streq (sec
->uncompressed_name
, name
))
15119 sec
->name
= sec
->uncompressed_name
;
15121 sec
->name
= sec
->compressed_name
;
15123 if (load_specific_debug_section (id
, section
, filedata
))
15125 /* If this debug section is part of a CU/TU set in a .dwp file,
15126 restrict load_debug_section to the sections in that set. */
15127 section_subset
= find_cu_tu_set (filedata
, shndx
);
15129 result
&= display
->display (sec
, filedata
);
15131 section_subset
= NULL
;
15133 if (secondary
|| (id
!= info
&& id
!= abbrev
))
15134 free_debug_section (id
);
15142 printf (_("Unrecognized debug section: %s\n"), print_name
);
15149 /* Set DUMP_SECTS for all sections where dumps were requested
15150 based on section name. */
15153 initialise_dumps_byname (Filedata
* filedata
)
15155 struct dump_list_entry
* cur
;
15157 for (cur
= dump_sects_byname
; cur
; cur
= cur
->next
)
15160 bfd_boolean any
= FALSE
;
15162 for (i
= 0; i
< filedata
->file_header
.e_shnum
; i
++)
15163 if (streq (SECTION_NAME (filedata
->section_headers
+ i
), cur
->name
))
15165 request_dump_bynumber (&filedata
->dump
, i
, cur
->type
);
15170 warn (_("Section '%s' was not dumped because it does not exist!\n"),
15176 process_section_contents (Filedata
* filedata
)
15178 Elf_Internal_Shdr
* section
;
15180 bfd_boolean res
= TRUE
;
15185 initialise_dumps_byname (filedata
);
15187 for (i
= 0, section
= filedata
->section_headers
;
15188 i
< filedata
->file_header
.e_shnum
&& i
< filedata
->dump
.num_dump_sects
;
15191 dump_type dump
= filedata
->dump
.dump_sects
[i
];
15193 #ifdef SUPPORT_DISASSEMBLY
15194 if (dump
& DISASS_DUMP
)
15196 if (! disassemble_section (section
, filedata
))
15200 if (dump
& HEX_DUMP
)
15202 if (! dump_section_as_bytes (section
, filedata
, FALSE
))
15206 if (dump
& RELOC_DUMP
)
15208 if (! dump_section_as_bytes (section
, filedata
, TRUE
))
15212 if (dump
& STRING_DUMP
)
15214 if (! dump_section_as_strings (section
, filedata
))
15218 if (dump
& DEBUG_DUMP
)
15220 if (! display_debug_section (i
, section
, filedata
))
15224 #ifdef ENABLE_LIBCTF
15225 if (dump
& CTF_DUMP
)
15227 if (! dump_section_as_ctf (section
, filedata
))
15233 /* Check to see if the user requested a
15234 dump of a section that does not exist. */
15235 while (i
< filedata
->dump
.num_dump_sects
)
15237 if (filedata
->dump
.dump_sects
[i
])
15239 warn (_("Section %d was not dumped because it does not exist!\n"), i
);
15249 process_mips_fpe_exception (int mask
)
15253 bfd_boolean first
= TRUE
;
15255 if (mask
& OEX_FPU_INEX
)
15256 fputs ("INEX", stdout
), first
= FALSE
;
15257 if (mask
& OEX_FPU_UFLO
)
15258 printf ("%sUFLO", first
? "" : "|"), first
= FALSE
;
15259 if (mask
& OEX_FPU_OFLO
)
15260 printf ("%sOFLO", first
? "" : "|"), first
= FALSE
;
15261 if (mask
& OEX_FPU_DIV0
)
15262 printf ("%sDIV0", first
? "" : "|"), first
= FALSE
;
15263 if (mask
& OEX_FPU_INVAL
)
15264 printf ("%sINVAL", first
? "" : "|");
15267 fputs ("0", stdout
);
15270 /* Display's the value of TAG at location P. If TAG is
15271 greater than 0 it is assumed to be an unknown tag, and
15272 a message is printed to this effect. Otherwise it is
15273 assumed that a message has already been printed.
15275 If the bottom bit of TAG is set it assumed to have a
15276 string value, otherwise it is assumed to have an integer
15279 Returns an updated P pointing to the first unread byte
15280 beyond the end of TAG's value.
15282 Reads at or beyond END will not be made. */
15284 static unsigned char *
15285 display_tag_value (signed int tag
,
15287 const unsigned char * const end
)
15292 printf (" Tag_unknown_%d: ", tag
);
15296 warn (_("<corrupt tag>\n"));
15300 /* PR 17531 file: 027-19978-0.004. */
15301 size_t maxlen
= (end
- p
) - 1;
15306 print_symbol ((int) maxlen
, (const char *) p
);
15307 p
+= strnlen ((char *) p
, maxlen
) + 1;
15311 printf (_("<corrupt string tag>"));
15312 p
= (unsigned char *) end
;
15318 READ_ULEB (val
, p
, end
);
15319 printf ("%ld (0x%lx)\n", val
, val
);
15326 /* ARC ABI attributes section. */
15328 static unsigned char *
15329 display_arc_attribute (unsigned char * p
,
15330 const unsigned char * const end
)
15335 READ_ULEB (tag
, p
, end
);
15339 case Tag_ARC_PCS_config
:
15340 READ_ULEB (val
, p
, end
);
15341 printf (" Tag_ARC_PCS_config: ");
15345 printf (_("Absent/Non standard\n"));
15348 printf (_("Bare metal/mwdt\n"));
15351 printf (_("Bare metal/newlib\n"));
15354 printf (_("Linux/uclibc\n"));
15357 printf (_("Linux/glibc\n"));
15360 printf (_("Unknown\n"));
15365 case Tag_ARC_CPU_base
:
15366 READ_ULEB (val
, p
, end
);
15367 printf (" Tag_ARC_CPU_base: ");
15372 printf (_("Absent\n"));
15374 case TAG_CPU_ARC6xx
:
15375 printf ("ARC6xx\n");
15377 case TAG_CPU_ARC7xx
:
15378 printf ("ARC7xx\n");
15380 case TAG_CPU_ARCEM
:
15381 printf ("ARCEM\n");
15383 case TAG_CPU_ARCHS
:
15384 printf ("ARCHS\n");
15389 case Tag_ARC_CPU_variation
:
15390 READ_ULEB (val
, p
, end
);
15391 printf (" Tag_ARC_CPU_variation: ");
15395 if (val
> 0 && val
< 16)
15396 printf ("Core%d\n", val
);
15398 printf ("Unknown\n");
15402 printf (_("Absent\n"));
15407 case Tag_ARC_CPU_name
:
15408 printf (" Tag_ARC_CPU_name: ");
15409 p
= display_tag_value (-1, p
, end
);
15412 case Tag_ARC_ABI_rf16
:
15413 READ_ULEB (val
, p
, end
);
15414 printf (" Tag_ARC_ABI_rf16: %s\n", val
? _("yes") : _("no"));
15417 case Tag_ARC_ABI_osver
:
15418 READ_ULEB (val
, p
, end
);
15419 printf (" Tag_ARC_ABI_osver: v%d\n", val
);
15422 case Tag_ARC_ABI_pic
:
15423 case Tag_ARC_ABI_sda
:
15424 READ_ULEB (val
, p
, end
);
15425 printf (tag
== Tag_ARC_ABI_sda
? " Tag_ARC_ABI_sda: "
15426 : " Tag_ARC_ABI_pic: ");
15430 printf (_("Absent\n"));
15439 printf (_("Unknown\n"));
15444 case Tag_ARC_ABI_tls
:
15445 READ_ULEB (val
, p
, end
);
15446 printf (" Tag_ARC_ABI_tls: %s\n", val
? "r25": "none");
15449 case Tag_ARC_ABI_enumsize
:
15450 READ_ULEB (val
, p
, end
);
15451 printf (" Tag_ARC_ABI_enumsize: %s\n", val
? _("default") :
15455 case Tag_ARC_ABI_exceptions
:
15456 READ_ULEB (val
, p
, end
);
15457 printf (" Tag_ARC_ABI_exceptions: %s\n", val
? _("OPTFP")
15461 case Tag_ARC_ABI_double_size
:
15462 READ_ULEB (val
, p
, end
);
15463 printf (" Tag_ARC_ABI_double_size: %d\n", val
);
15466 case Tag_ARC_ISA_config
:
15467 printf (" Tag_ARC_ISA_config: ");
15468 p
= display_tag_value (-1, p
, end
);
15471 case Tag_ARC_ISA_apex
:
15472 printf (" Tag_ARC_ISA_apex: ");
15473 p
= display_tag_value (-1, p
, end
);
15476 case Tag_ARC_ISA_mpy_option
:
15477 READ_ULEB (val
, p
, end
);
15478 printf (" Tag_ARC_ISA_mpy_option: %d\n", val
);
15481 case Tag_ARC_ATR_version
:
15482 READ_ULEB (val
, p
, end
);
15483 printf (" Tag_ARC_ATR_version: %d\n", val
);
15487 return display_tag_value (tag
& 1, p
, end
);
15493 /* ARM EABI attributes section. */
15498 /* 0 = special, 1 = string, 2 = uleb123, > 0x80 == table lookup. */
15500 const char ** table
;
15501 } arm_attr_public_tag
;
15503 static const char * arm_attr_tag_CPU_arch
[] =
15504 {"Pre-v4", "v4", "v4T", "v5T", "v5TE", "v5TEJ", "v6", "v6KZ", "v6T2",
15505 "v6K", "v7", "v6-M", "v6S-M", "v7E-M", "v8", "v8-R", "v8-M.baseline",
15506 "v8-M.mainline", "", "", "", "v8.1-M.mainline"};
15507 static const char * arm_attr_tag_ARM_ISA_use
[] = {"No", "Yes"};
15508 static const char * arm_attr_tag_THUMB_ISA_use
[] =
15509 {"No", "Thumb-1", "Thumb-2", "Yes"};
15510 static const char * arm_attr_tag_FP_arch
[] =
15511 {"No", "VFPv1", "VFPv2", "VFPv3", "VFPv3-D16", "VFPv4", "VFPv4-D16",
15512 "FP for ARMv8", "FPv5/FP-D16 for ARMv8"};
15513 static const char * arm_attr_tag_WMMX_arch
[] = {"No", "WMMXv1", "WMMXv2"};
15514 static const char * arm_attr_tag_Advanced_SIMD_arch
[] =
15515 {"No", "NEONv1", "NEONv1 with Fused-MAC", "NEON for ARMv8",
15516 "NEON for ARMv8.1"};
15517 static const char * arm_attr_tag_PCS_config
[] =
15518 {"None", "Bare platform", "Linux application", "Linux DSO", "PalmOS 2004",
15519 "PalmOS (reserved)", "SymbianOS 2004", "SymbianOS (reserved)"};
15520 static const char * arm_attr_tag_ABI_PCS_R9_use
[] =
15521 {"V6", "SB", "TLS", "Unused"};
15522 static const char * arm_attr_tag_ABI_PCS_RW_data
[] =
15523 {"Absolute", "PC-relative", "SB-relative", "None"};
15524 static const char * arm_attr_tag_ABI_PCS_RO_data
[] =
15525 {"Absolute", "PC-relative", "None"};
15526 static const char * arm_attr_tag_ABI_PCS_GOT_use
[] =
15527 {"None", "direct", "GOT-indirect"};
15528 static const char * arm_attr_tag_ABI_PCS_wchar_t
[] =
15529 {"None", "??? 1", "2", "??? 3", "4"};
15530 static const char * arm_attr_tag_ABI_FP_rounding
[] = {"Unused", "Needed"};
15531 static const char * arm_attr_tag_ABI_FP_denormal
[] =
15532 {"Unused", "Needed", "Sign only"};
15533 static const char * arm_attr_tag_ABI_FP_exceptions
[] = {"Unused", "Needed"};
15534 static const char * arm_attr_tag_ABI_FP_user_exceptions
[] = {"Unused", "Needed"};
15535 static const char * arm_attr_tag_ABI_FP_number_model
[] =
15536 {"Unused", "Finite", "RTABI", "IEEE 754"};
15537 static const char * arm_attr_tag_ABI_enum_size
[] =
15538 {"Unused", "small", "int", "forced to int"};
15539 static const char * arm_attr_tag_ABI_HardFP_use
[] =
15540 {"As Tag_FP_arch", "SP only", "Reserved", "Deprecated"};
15541 static const char * arm_attr_tag_ABI_VFP_args
[] =
15542 {"AAPCS", "VFP registers", "custom", "compatible"};
15543 static const char * arm_attr_tag_ABI_WMMX_args
[] =
15544 {"AAPCS", "WMMX registers", "custom"};
15545 static const char * arm_attr_tag_ABI_optimization_goals
[] =
15546 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
15547 "Aggressive Size", "Prefer Debug", "Aggressive Debug"};
15548 static const char * arm_attr_tag_ABI_FP_optimization_goals
[] =
15549 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
15550 "Aggressive Size", "Prefer Accuracy", "Aggressive Accuracy"};
15551 static const char * arm_attr_tag_CPU_unaligned_access
[] = {"None", "v6"};
15552 static const char * arm_attr_tag_FP_HP_extension
[] =
15553 {"Not Allowed", "Allowed"};
15554 static const char * arm_attr_tag_ABI_FP_16bit_format
[] =
15555 {"None", "IEEE 754", "Alternative Format"};
15556 static const char * arm_attr_tag_DSP_extension
[] =
15557 {"Follow architecture", "Allowed"};
15558 static const char * arm_attr_tag_MPextension_use
[] =
15559 {"Not Allowed", "Allowed"};
15560 static const char * arm_attr_tag_DIV_use
[] =
15561 {"Allowed in Thumb-ISA, v7-R or v7-M", "Not allowed",
15562 "Allowed in v7-A with integer division extension"};
15563 static const char * arm_attr_tag_T2EE_use
[] = {"Not Allowed", "Allowed"};
15564 static const char * arm_attr_tag_Virtualization_use
[] =
15565 {"Not Allowed", "TrustZone", "Virtualization Extensions",
15566 "TrustZone and Virtualization Extensions"};
15567 static const char * arm_attr_tag_MPextension_use_legacy
[] =
15568 {"Not Allowed", "Allowed"};
15570 static const char * arm_attr_tag_MVE_arch
[] =
15571 {"No MVE", "MVE Integer only", "MVE Integer and FP"};
15573 #define LOOKUP(id, name) \
15574 {id, #name, 0x80 | ARRAY_SIZE(arm_attr_tag_##name), arm_attr_tag_##name}
15575 static arm_attr_public_tag arm_attr_public_tags
[] =
15577 {4, "CPU_raw_name", 1, NULL
},
15578 {5, "CPU_name", 1, NULL
},
15579 LOOKUP(6, CPU_arch
),
15580 {7, "CPU_arch_profile", 0, NULL
},
15581 LOOKUP(8, ARM_ISA_use
),
15582 LOOKUP(9, THUMB_ISA_use
),
15583 LOOKUP(10, FP_arch
),
15584 LOOKUP(11, WMMX_arch
),
15585 LOOKUP(12, Advanced_SIMD_arch
),
15586 LOOKUP(13, PCS_config
),
15587 LOOKUP(14, ABI_PCS_R9_use
),
15588 LOOKUP(15, ABI_PCS_RW_data
),
15589 LOOKUP(16, ABI_PCS_RO_data
),
15590 LOOKUP(17, ABI_PCS_GOT_use
),
15591 LOOKUP(18, ABI_PCS_wchar_t
),
15592 LOOKUP(19, ABI_FP_rounding
),
15593 LOOKUP(20, ABI_FP_denormal
),
15594 LOOKUP(21, ABI_FP_exceptions
),
15595 LOOKUP(22, ABI_FP_user_exceptions
),
15596 LOOKUP(23, ABI_FP_number_model
),
15597 {24, "ABI_align_needed", 0, NULL
},
15598 {25, "ABI_align_preserved", 0, NULL
},
15599 LOOKUP(26, ABI_enum_size
),
15600 LOOKUP(27, ABI_HardFP_use
),
15601 LOOKUP(28, ABI_VFP_args
),
15602 LOOKUP(29, ABI_WMMX_args
),
15603 LOOKUP(30, ABI_optimization_goals
),
15604 LOOKUP(31, ABI_FP_optimization_goals
),
15605 {32, "compatibility", 0, NULL
},
15606 LOOKUP(34, CPU_unaligned_access
),
15607 LOOKUP(36, FP_HP_extension
),
15608 LOOKUP(38, ABI_FP_16bit_format
),
15609 LOOKUP(42, MPextension_use
),
15610 LOOKUP(44, DIV_use
),
15611 LOOKUP(46, DSP_extension
),
15612 LOOKUP(48, MVE_arch
),
15613 {64, "nodefaults", 0, NULL
},
15614 {65, "also_compatible_with", 0, NULL
},
15615 LOOKUP(66, T2EE_use
),
15616 {67, "conformance", 1, NULL
},
15617 LOOKUP(68, Virtualization_use
),
15618 LOOKUP(70, MPextension_use_legacy
)
15622 static unsigned char *
15623 display_arm_attribute (unsigned char * p
,
15624 const unsigned char * const end
)
15628 arm_attr_public_tag
* attr
;
15632 READ_ULEB (tag
, p
, end
);
15634 for (i
= 0; i
< ARRAY_SIZE (arm_attr_public_tags
); i
++)
15636 if (arm_attr_public_tags
[i
].tag
== tag
)
15638 attr
= &arm_attr_public_tags
[i
];
15645 printf (" Tag_%s: ", attr
->name
);
15646 switch (attr
->type
)
15651 case 7: /* Tag_CPU_arch_profile. */
15652 READ_ULEB (val
, p
, end
);
15655 case 0: printf (_("None\n")); break;
15656 case 'A': printf (_("Application\n")); break;
15657 case 'R': printf (_("Realtime\n")); break;
15658 case 'M': printf (_("Microcontroller\n")); break;
15659 case 'S': printf (_("Application or Realtime\n")); break;
15660 default: printf ("??? (%d)\n", val
); break;
15664 case 24: /* Tag_align_needed. */
15665 READ_ULEB (val
, p
, end
);
15668 case 0: printf (_("None\n")); break;
15669 case 1: printf (_("8-byte\n")); break;
15670 case 2: printf (_("4-byte\n")); break;
15671 case 3: printf ("??? 3\n"); break;
15674 printf (_("8-byte and up to %d-byte extended\n"),
15677 printf ("??? (%d)\n", val
);
15682 case 25: /* Tag_align_preserved. */
15683 READ_ULEB (val
, p
, end
);
15686 case 0: printf (_("None\n")); break;
15687 case 1: printf (_("8-byte, except leaf SP\n")); break;
15688 case 2: printf (_("8-byte\n")); break;
15689 case 3: printf ("??? 3\n"); break;
15692 printf (_("8-byte and up to %d-byte extended\n"),
15695 printf ("??? (%d)\n", val
);
15700 case 32: /* Tag_compatibility. */
15702 READ_ULEB (val
, p
, end
);
15703 printf (_("flag = %d, vendor = "), val
);
15706 size_t maxlen
= (end
- p
) - 1;
15708 print_symbol ((int) maxlen
, (const char *) p
);
15709 p
+= strnlen ((char *) p
, maxlen
) + 1;
15713 printf (_("<corrupt>"));
15714 p
= (unsigned char *) end
;
15720 case 64: /* Tag_nodefaults. */
15721 /* PR 17531: file: 001-505008-0.01. */
15724 printf (_("True\n"));
15727 case 65: /* Tag_also_compatible_with. */
15728 READ_ULEB (val
, p
, end
);
15729 if (val
== 6 /* Tag_CPU_arch. */)
15731 READ_ULEB (val
, p
, end
);
15732 if ((unsigned int) val
>= ARRAY_SIZE (arm_attr_tag_CPU_arch
))
15733 printf ("??? (%d)\n", val
);
15735 printf ("%s\n", arm_attr_tag_CPU_arch
[val
]);
15739 while (p
< end
&& *(p
++) != '\0' /* NUL terminator. */)
15744 printf (_("<unknown: %d>\n"), tag
);
15750 return display_tag_value (-1, p
, end
);
15752 return display_tag_value (0, p
, end
);
15755 assert (attr
->type
& 0x80);
15756 READ_ULEB (val
, p
, end
);
15757 type
= attr
->type
& 0x7f;
15759 printf ("??? (%d)\n", val
);
15761 printf ("%s\n", attr
->table
[val
]);
15766 return display_tag_value (tag
, p
, end
);
15769 static unsigned char *
15770 display_gnu_attribute (unsigned char * p
,
15771 unsigned char * (* display_proc_gnu_attribute
) (unsigned char *, unsigned int, const unsigned char * const),
15772 const unsigned char * const end
)
15777 READ_ULEB (tag
, p
, end
);
15779 /* Tag_compatibility is the only generic GNU attribute defined at
15783 READ_ULEB (val
, p
, end
);
15785 printf (_("flag = %d, vendor = "), val
);
15788 printf (_("<corrupt>\n"));
15789 warn (_("corrupt vendor attribute\n"));
15795 size_t maxlen
= (end
- p
) - 1;
15797 print_symbol ((int) maxlen
, (const char *) p
);
15798 p
+= strnlen ((char *) p
, maxlen
) + 1;
15802 printf (_("<corrupt>"));
15803 p
= (unsigned char *) end
;
15810 if ((tag
& 2) == 0 && display_proc_gnu_attribute
)
15811 return display_proc_gnu_attribute (p
, tag
, end
);
15813 return display_tag_value (tag
, p
, end
);
15816 static unsigned char *
15817 display_m68k_gnu_attribute (unsigned char * p
,
15819 const unsigned char * const end
)
15823 if (tag
== Tag_GNU_M68K_ABI_FP
)
15825 printf (" Tag_GNU_M68K_ABI_FP: ");
15828 printf (_("<corrupt>\n"));
15831 READ_ULEB (val
, p
, end
);
15834 printf ("(%#x), ", val
);
15839 printf (_("unspecified hard/soft float\n"));
15842 printf (_("hard float\n"));
15845 printf (_("soft float\n"));
15851 return display_tag_value (tag
& 1, p
, end
);
15854 static unsigned char *
15855 display_power_gnu_attribute (unsigned char * p
,
15857 const unsigned char * const end
)
15861 if (tag
== Tag_GNU_Power_ABI_FP
)
15863 printf (" Tag_GNU_Power_ABI_FP: ");
15866 printf (_("<corrupt>\n"));
15869 READ_ULEB (val
, p
, end
);
15872 printf ("(%#x), ", val
);
15877 printf (_("unspecified hard/soft float, "));
15880 printf (_("hard float, "));
15883 printf (_("soft float, "));
15886 printf (_("single-precision hard float, "));
15893 printf (_("unspecified long double\n"));
15896 printf (_("128-bit IBM long double\n"));
15899 printf (_("64-bit long double\n"));
15902 printf (_("128-bit IEEE long double\n"));
15908 if (tag
== Tag_GNU_Power_ABI_Vector
)
15910 printf (" Tag_GNU_Power_ABI_Vector: ");
15913 printf (_("<corrupt>\n"));
15916 READ_ULEB (val
, p
, end
);
15919 printf ("(%#x), ", val
);
15924 printf (_("unspecified\n"));
15927 printf (_("generic\n"));
15930 printf ("AltiVec\n");
15939 if (tag
== Tag_GNU_Power_ABI_Struct_Return
)
15941 printf (" Tag_GNU_Power_ABI_Struct_Return: ");
15944 printf (_("<corrupt>\n"));
15947 READ_ULEB (val
, p
, end
);
15950 printf ("(%#x), ", val
);
15955 printf (_("unspecified\n"));
15958 printf ("r3/r4\n");
15961 printf (_("memory\n"));
15970 return display_tag_value (tag
& 1, p
, end
);
15973 static unsigned char *
15974 display_s390_gnu_attribute (unsigned char * p
,
15976 const unsigned char * const end
)
15980 if (tag
== Tag_GNU_S390_ABI_Vector
)
15982 printf (" Tag_GNU_S390_ABI_Vector: ");
15983 READ_ULEB (val
, p
, end
);
15988 printf (_("any\n"));
15991 printf (_("software\n"));
15994 printf (_("hardware\n"));
15997 printf ("??? (%d)\n", val
);
16003 return display_tag_value (tag
& 1, p
, end
);
16007 display_sparc_hwcaps (unsigned int mask
)
16011 bfd_boolean first
= TRUE
;
16013 if (mask
& ELF_SPARC_HWCAP_MUL32
)
16014 fputs ("mul32", stdout
), first
= FALSE
;
16015 if (mask
& ELF_SPARC_HWCAP_DIV32
)
16016 printf ("%sdiv32", first
? "" : "|"), first
= FALSE
;
16017 if (mask
& ELF_SPARC_HWCAP_FSMULD
)
16018 printf ("%sfsmuld", first
? "" : "|"), first
= FALSE
;
16019 if (mask
& ELF_SPARC_HWCAP_V8PLUS
)
16020 printf ("%sv8plus", first
? "" : "|"), first
= FALSE
;
16021 if (mask
& ELF_SPARC_HWCAP_POPC
)
16022 printf ("%spopc", first
? "" : "|"), first
= FALSE
;
16023 if (mask
& ELF_SPARC_HWCAP_VIS
)
16024 printf ("%svis", first
? "" : "|"), first
= FALSE
;
16025 if (mask
& ELF_SPARC_HWCAP_VIS2
)
16026 printf ("%svis2", first
? "" : "|"), first
= FALSE
;
16027 if (mask
& ELF_SPARC_HWCAP_ASI_BLK_INIT
)
16028 printf ("%sASIBlkInit", first
? "" : "|"), first
= FALSE
;
16029 if (mask
& ELF_SPARC_HWCAP_FMAF
)
16030 printf ("%sfmaf", first
? "" : "|"), first
= FALSE
;
16031 if (mask
& ELF_SPARC_HWCAP_VIS3
)
16032 printf ("%svis3", first
? "" : "|"), first
= FALSE
;
16033 if (mask
& ELF_SPARC_HWCAP_HPC
)
16034 printf ("%shpc", first
? "" : "|"), first
= FALSE
;
16035 if (mask
& ELF_SPARC_HWCAP_RANDOM
)
16036 printf ("%srandom", first
? "" : "|"), first
= FALSE
;
16037 if (mask
& ELF_SPARC_HWCAP_TRANS
)
16038 printf ("%strans", first
? "" : "|"), first
= FALSE
;
16039 if (mask
& ELF_SPARC_HWCAP_FJFMAU
)
16040 printf ("%sfjfmau", first
? "" : "|"), first
= FALSE
;
16041 if (mask
& ELF_SPARC_HWCAP_IMA
)
16042 printf ("%sima", first
? "" : "|"), first
= FALSE
;
16043 if (mask
& ELF_SPARC_HWCAP_ASI_CACHE_SPARING
)
16044 printf ("%scspare", first
? "" : "|"), first
= FALSE
;
16047 fputc ('0', stdout
);
16048 fputc ('\n', stdout
);
16052 display_sparc_hwcaps2 (unsigned int mask
)
16056 bfd_boolean first
= TRUE
;
16058 if (mask
& ELF_SPARC_HWCAP2_FJATHPLUS
)
16059 fputs ("fjathplus", stdout
), first
= FALSE
;
16060 if (mask
& ELF_SPARC_HWCAP2_VIS3B
)
16061 printf ("%svis3b", first
? "" : "|"), first
= FALSE
;
16062 if (mask
& ELF_SPARC_HWCAP2_ADP
)
16063 printf ("%sadp", first
? "" : "|"), first
= FALSE
;
16064 if (mask
& ELF_SPARC_HWCAP2_SPARC5
)
16065 printf ("%ssparc5", first
? "" : "|"), first
= FALSE
;
16066 if (mask
& ELF_SPARC_HWCAP2_MWAIT
)
16067 printf ("%smwait", first
? "" : "|"), first
= FALSE
;
16068 if (mask
& ELF_SPARC_HWCAP2_XMPMUL
)
16069 printf ("%sxmpmul", first
? "" : "|"), first
= FALSE
;
16070 if (mask
& ELF_SPARC_HWCAP2_XMONT
)
16071 printf ("%sxmont2", first
? "" : "|"), first
= FALSE
;
16072 if (mask
& ELF_SPARC_HWCAP2_NSEC
)
16073 printf ("%snsec", first
? "" : "|"), first
= FALSE
;
16074 if (mask
& ELF_SPARC_HWCAP2_FJATHHPC
)
16075 printf ("%sfjathhpc", first
? "" : "|"), first
= FALSE
;
16076 if (mask
& ELF_SPARC_HWCAP2_FJDES
)
16077 printf ("%sfjdes", first
? "" : "|"), first
= FALSE
;
16078 if (mask
& ELF_SPARC_HWCAP2_FJAES
)
16079 printf ("%sfjaes", first
? "" : "|"), first
= FALSE
;
16082 fputc ('0', stdout
);
16083 fputc ('\n', stdout
);
16086 static unsigned char *
16087 display_sparc_gnu_attribute (unsigned char * p
,
16089 const unsigned char * const end
)
16093 if (tag
== Tag_GNU_Sparc_HWCAPS
)
16095 READ_ULEB (val
, p
, end
);
16096 printf (" Tag_GNU_Sparc_HWCAPS: ");
16097 display_sparc_hwcaps (val
);
16100 if (tag
== Tag_GNU_Sparc_HWCAPS2
)
16102 READ_ULEB (val
, p
, end
);
16103 printf (" Tag_GNU_Sparc_HWCAPS2: ");
16104 display_sparc_hwcaps2 (val
);
16108 return display_tag_value (tag
, p
, end
);
16112 print_mips_fp_abi_value (unsigned int val
)
16116 case Val_GNU_MIPS_ABI_FP_ANY
:
16117 printf (_("Hard or soft float\n"));
16119 case Val_GNU_MIPS_ABI_FP_DOUBLE
:
16120 printf (_("Hard float (double precision)\n"));
16122 case Val_GNU_MIPS_ABI_FP_SINGLE
:
16123 printf (_("Hard float (single precision)\n"));
16125 case Val_GNU_MIPS_ABI_FP_SOFT
:
16126 printf (_("Soft float\n"));
16128 case Val_GNU_MIPS_ABI_FP_OLD_64
:
16129 printf (_("Hard float (MIPS32r2 64-bit FPU 12 callee-saved)\n"));
16131 case Val_GNU_MIPS_ABI_FP_XX
:
16132 printf (_("Hard float (32-bit CPU, Any FPU)\n"));
16134 case Val_GNU_MIPS_ABI_FP_64
:
16135 printf (_("Hard float (32-bit CPU, 64-bit FPU)\n"));
16137 case Val_GNU_MIPS_ABI_FP_64A
:
16138 printf (_("Hard float compat (32-bit CPU, 64-bit FPU)\n"));
16140 case Val_GNU_MIPS_ABI_FP_NAN2008
:
16141 printf (_("NaN 2008 compatibility\n"));
16144 printf ("??? (%d)\n", val
);
16149 static unsigned char *
16150 display_mips_gnu_attribute (unsigned char * p
,
16152 const unsigned char * const end
)
16154 if (tag
== Tag_GNU_MIPS_ABI_FP
)
16158 printf (" Tag_GNU_MIPS_ABI_FP: ");
16159 READ_ULEB (val
, p
, end
);
16160 print_mips_fp_abi_value (val
);
16164 if (tag
== Tag_GNU_MIPS_ABI_MSA
)
16168 printf (" Tag_GNU_MIPS_ABI_MSA: ");
16169 READ_ULEB (val
, p
, end
);
16173 case Val_GNU_MIPS_ABI_MSA_ANY
:
16174 printf (_("Any MSA or not\n"));
16176 case Val_GNU_MIPS_ABI_MSA_128
:
16177 printf (_("128-bit MSA\n"));
16180 printf ("??? (%d)\n", val
);
16186 return display_tag_value (tag
& 1, p
, end
);
16189 static unsigned char *
16190 display_tic6x_attribute (unsigned char * p
,
16191 const unsigned char * const end
)
16196 READ_ULEB (tag
, p
, end
);
16201 printf (" Tag_ISA: ");
16202 READ_ULEB (val
, p
, end
);
16206 case C6XABI_Tag_ISA_none
:
16207 printf (_("None\n"));
16209 case C6XABI_Tag_ISA_C62X
:
16212 case C6XABI_Tag_ISA_C67X
:
16215 case C6XABI_Tag_ISA_C67XP
:
16216 printf ("C67x+\n");
16218 case C6XABI_Tag_ISA_C64X
:
16221 case C6XABI_Tag_ISA_C64XP
:
16222 printf ("C64x+\n");
16224 case C6XABI_Tag_ISA_C674X
:
16225 printf ("C674x\n");
16228 printf ("??? (%d)\n", val
);
16233 case Tag_ABI_wchar_t
:
16234 printf (" Tag_ABI_wchar_t: ");
16235 READ_ULEB (val
, p
, end
);
16239 printf (_("Not used\n"));
16242 printf (_("2 bytes\n"));
16245 printf (_("4 bytes\n"));
16248 printf ("??? (%d)\n", val
);
16253 case Tag_ABI_stack_align_needed
:
16254 printf (" Tag_ABI_stack_align_needed: ");
16255 READ_ULEB (val
, p
, end
);
16259 printf (_("8-byte\n"));
16262 printf (_("16-byte\n"));
16265 printf ("??? (%d)\n", val
);
16270 case Tag_ABI_stack_align_preserved
:
16271 READ_ULEB (val
, p
, end
);
16272 printf (" Tag_ABI_stack_align_preserved: ");
16276 printf (_("8-byte\n"));
16279 printf (_("16-byte\n"));
16282 printf ("??? (%d)\n", val
);
16288 READ_ULEB (val
, p
, end
);
16289 printf (" Tag_ABI_DSBT: ");
16293 printf (_("DSBT addressing not used\n"));
16296 printf (_("DSBT addressing used\n"));
16299 printf ("??? (%d)\n", val
);
16305 READ_ULEB (val
, p
, end
);
16306 printf (" Tag_ABI_PID: ");
16310 printf (_("Data addressing position-dependent\n"));
16313 printf (_("Data addressing position-independent, GOT near DP\n"));
16316 printf (_("Data addressing position-independent, GOT far from DP\n"));
16319 printf ("??? (%d)\n", val
);
16325 READ_ULEB (val
, p
, end
);
16326 printf (" Tag_ABI_PIC: ");
16330 printf (_("Code addressing position-dependent\n"));
16333 printf (_("Code addressing position-independent\n"));
16336 printf ("??? (%d)\n", val
);
16341 case Tag_ABI_array_object_alignment
:
16342 READ_ULEB (val
, p
, end
);
16343 printf (" Tag_ABI_array_object_alignment: ");
16347 printf (_("8-byte\n"));
16350 printf (_("4-byte\n"));
16353 printf (_("16-byte\n"));
16356 printf ("??? (%d)\n", val
);
16361 case Tag_ABI_array_object_align_expected
:
16362 READ_ULEB (val
, p
, end
);
16363 printf (" Tag_ABI_array_object_align_expected: ");
16367 printf (_("8-byte\n"));
16370 printf (_("4-byte\n"));
16373 printf (_("16-byte\n"));
16376 printf ("??? (%d)\n", val
);
16381 case Tag_ABI_compatibility
:
16383 READ_ULEB (val
, p
, end
);
16384 printf (" Tag_ABI_compatibility: ");
16385 printf (_("flag = %d, vendor = "), val
);
16388 size_t maxlen
= (end
- p
) - 1;
16390 print_symbol ((int) maxlen
, (const char *) p
);
16391 p
+= strnlen ((char *) p
, maxlen
) + 1;
16395 printf (_("<corrupt>"));
16396 p
= (unsigned char *) end
;
16402 case Tag_ABI_conformance
:
16404 printf (" Tag_ABI_conformance: \"");
16407 size_t maxlen
= (end
- p
) - 1;
16409 print_symbol ((int) maxlen
, (const char *) p
);
16410 p
+= strnlen ((char *) p
, maxlen
) + 1;
16414 printf (_("<corrupt>"));
16415 p
= (unsigned char *) end
;
16422 return display_tag_value (tag
, p
, end
);
16426 display_raw_attribute (unsigned char * p
, unsigned char const * const end
)
16428 unsigned long addr
= 0;
16429 size_t bytes
= end
- p
;
16436 int lbytes
= (bytes
> 16 ? 16 : bytes
);
16438 printf (" 0x%8.8lx ", addr
);
16440 for (j
= 0; j
< 16; j
++)
16443 printf ("%2.2x", p
[j
]);
16451 for (j
= 0; j
< lbytes
; j
++)
16454 if (k
>= ' ' && k
< 0x7f)
16470 static unsigned char *
16471 display_msp430_attribute (unsigned char * p
,
16472 const unsigned char * const end
)
16477 READ_ULEB (tag
, p
, end
);
16481 case OFBA_MSPABI_Tag_ISA
:
16482 printf (" Tag_ISA: ");
16483 READ_ULEB (val
, p
, end
);
16486 case 0: printf (_("None\n")); break;
16487 case 1: printf (_("MSP430\n")); break;
16488 case 2: printf (_("MSP430X\n")); break;
16489 default: printf ("??? (%d)\n", val
); break;
16493 case OFBA_MSPABI_Tag_Code_Model
:
16494 printf (" Tag_Code_Model: ");
16495 READ_ULEB (val
, p
, end
);
16498 case 0: printf (_("None\n")); break;
16499 case 1: printf (_("Small\n")); break;
16500 case 2: printf (_("Large\n")); break;
16501 default: printf ("??? (%d)\n", val
); break;
16505 case OFBA_MSPABI_Tag_Data_Model
:
16506 printf (" Tag_Data_Model: ");
16507 READ_ULEB (val
, p
, end
);
16510 case 0: printf (_("None\n")); break;
16511 case 1: printf (_("Small\n")); break;
16512 case 2: printf (_("Large\n")); break;
16513 case 3: printf (_("Restricted Large\n")); break;
16514 default: printf ("??? (%d)\n", val
); break;
16519 printf (_(" <unknown tag %d>: "), tag
);
16526 size_t maxlen
= (end
- p
) - 1;
16528 print_symbol ((int) maxlen
, (const char *) p
);
16529 p
+= strnlen ((char *) p
, maxlen
) + 1;
16533 printf (_("<corrupt>"));
16534 p
= (unsigned char *) end
;
16540 READ_ULEB (val
, p
, end
);
16541 printf ("%d (0x%x)\n", val
, val
);
16550 static unsigned char *
16551 display_msp430_gnu_attribute (unsigned char * p
,
16553 const unsigned char * const end
)
16555 if (tag
== Tag_GNU_MSP430_Data_Region
)
16559 printf (" Tag_GNU_MSP430_Data_Region: ");
16560 READ_ULEB (val
, p
, end
);
16564 case Val_GNU_MSP430_Data_Region_Any
:
16565 printf (_("Any Region\n"));
16567 case Val_GNU_MSP430_Data_Region_Lower
:
16568 printf (_("Lower Region Only\n"));
16571 printf ("??? (%u)\n", val
);
16575 return display_tag_value (tag
& 1, p
, end
);
16578 struct riscv_attr_tag_t
{
16583 static struct riscv_attr_tag_t riscv_attr_tag
[] =
16585 #define T(tag) {"Tag_RISCV_" #tag, Tag_RISCV_##tag}
16588 T(priv_spec_minor
),
16589 T(priv_spec_revision
),
16590 T(unaligned_access
),
16595 static unsigned char *
16596 display_riscv_attribute (unsigned char *p
,
16597 const unsigned char * const end
)
16601 struct riscv_attr_tag_t
*attr
= NULL
;
16604 READ_ULEB (tag
, p
, end
);
16606 /* Find the name of attribute. */
16607 for (i
= 0; i
< ARRAY_SIZE (riscv_attr_tag
); i
++)
16609 if (riscv_attr_tag
[i
].tag
== tag
)
16611 attr
= &riscv_attr_tag
[i
];
16617 printf (" %s: ", attr
->name
);
16619 return display_tag_value (tag
, p
, end
);
16623 case Tag_RISCV_priv_spec
:
16624 case Tag_RISCV_priv_spec_minor
:
16625 case Tag_RISCV_priv_spec_revision
:
16626 READ_ULEB (val
, p
, end
);
16627 printf (_("%u\n"), val
);
16629 case Tag_RISCV_unaligned_access
:
16630 READ_ULEB (val
, p
, end
);
16634 printf (_("No unaligned access\n"));
16637 printf (_("Unaligned access\n"));
16641 case Tag_RISCV_stack_align
:
16642 READ_ULEB (val
, p
, end
);
16643 printf (_("%u-bytes\n"), val
);
16645 case Tag_RISCV_arch
:
16646 p
= display_tag_value (-1, p
, end
);
16649 return display_tag_value (tag
, p
, end
);
16655 static unsigned char *
16656 display_csky_attribute (unsigned char * p
,
16657 const unsigned char * const end
)
16661 READ_ULEB (tag
, p
, end
);
16663 if (tag
>= Tag_CSKY_MAX
)
16665 return display_tag_value (-1, p
, end
);
16670 case Tag_CSKY_ARCH_NAME
:
16671 printf (" Tag_CSKY_ARCH_NAME:\t\t");
16672 return display_tag_value (-1, p
, end
);
16673 case Tag_CSKY_CPU_NAME
:
16674 printf (" Tag_CSKY_CPU_NAME:\t\t");
16675 return display_tag_value (-1, p
, end
);
16677 case Tag_CSKY_ISA_FLAGS
:
16678 printf (" Tag_CSKY_ISA_FLAGS:\t\t");
16679 return display_tag_value (0, p
, end
);
16680 case Tag_CSKY_ISA_EXT_FLAGS
:
16681 printf (" Tag_CSKY_ISA_EXT_FLAGS:\t");
16682 return display_tag_value (0, p
, end
);
16684 case Tag_CSKY_DSP_VERSION
:
16685 printf (" Tag_CSKY_DSP_VERSION:\t\t");
16686 READ_ULEB (val
, p
, end
);
16687 if (val
== VAL_CSKY_DSP_VERSION_EXTENSION
)
16688 printf ("DSP Extension\n");
16689 else if (val
== VAL_CSKY_DSP_VERSION_2
)
16690 printf ("DSP 2.0\n");
16693 case Tag_CSKY_VDSP_VERSION
:
16694 printf (" Tag_CSKY_VDSP_VERSION:\t");
16695 READ_ULEB (val
, p
, end
);
16696 printf ("VDSP Version %d\n", val
);
16699 case Tag_CSKY_FPU_VERSION
:
16700 printf (" Tag_CSKY_FPU_VERSION:\t\t");
16701 READ_ULEB (val
, p
, end
);
16702 if (val
== VAL_CSKY_FPU_VERSION_1
)
16703 printf ("ABIV1 FPU Version 1\n");
16704 else if (val
== VAL_CSKY_FPU_VERSION_2
)
16705 printf ("FPU Version 2\n");
16708 case Tag_CSKY_FPU_ABI
:
16709 printf (" Tag_CSKY_FPU_ABI:\t\t");
16710 READ_ULEB (val
, p
, end
);
16711 if (val
== VAL_CSKY_FPU_ABI_HARD
)
16713 else if (val
== VAL_CSKY_FPU_ABI_SOFTFP
)
16714 printf ("SoftFP\n");
16715 else if (val
== VAL_CSKY_FPU_ABI_SOFT
)
16718 case Tag_CSKY_FPU_ROUNDING
:
16719 READ_ULEB (val
, p
, end
);
16721 printf (" Tag_CSKY_FPU_ROUNDING:\t");
16722 printf ("Needed\n");
16725 case Tag_CSKY_FPU_DENORMAL
:
16726 READ_ULEB (val
, p
, end
);
16728 printf (" Tag_CSKY_FPU_DENORMAL:\t");
16729 printf ("Needed\n");
16732 case Tag_CSKY_FPU_Exception
:
16733 READ_ULEB (val
, p
, end
);
16735 printf (" Tag_CSKY_FPU_Exception:\t");
16736 printf ("Needed\n");
16739 case Tag_CSKY_FPU_NUMBER_MODULE
:
16740 printf (" Tag_CSKY_FPU_NUMBER_MODULE:\t");
16741 return display_tag_value (-1, p
, end
);
16742 case Tag_CSKY_FPU_HARDFP
:
16743 printf (" Tag_CSKY_FPU_HARDFP:\t\t");
16744 READ_ULEB (val
, p
, end
);
16745 if (val
& VAL_CSKY_FPU_HARDFP_HALF
)
16747 if (val
& VAL_CSKY_FPU_HARDFP_SINGLE
)
16748 printf (" Single");
16749 if (val
& VAL_CSKY_FPU_HARDFP_DOUBLE
)
16750 printf (" Double");
16754 return display_tag_value (tag
, p
, end
);
16760 process_attributes (Filedata
* filedata
,
16761 const char * public_name
,
16762 unsigned int proc_type
,
16763 unsigned char * (* display_pub_attribute
) (unsigned char *, const unsigned char * const),
16764 unsigned char * (* display_proc_gnu_attribute
) (unsigned char *, unsigned int, const unsigned char * const))
16766 Elf_Internal_Shdr
* sect
;
16768 bfd_boolean res
= TRUE
;
16770 /* Find the section header so that we get the size. */
16771 for (i
= 0, sect
= filedata
->section_headers
;
16772 i
< filedata
->file_header
.e_shnum
;
16775 unsigned char * contents
;
16778 if (sect
->sh_type
!= proc_type
&& sect
->sh_type
!= SHT_GNU_ATTRIBUTES
)
16781 contents
= (unsigned char *) get_data (NULL
, filedata
, sect
->sh_offset
, 1,
16782 sect
->sh_size
, _("attributes"));
16783 if (contents
== NULL
)
16790 /* The first character is the version of the attributes.
16791 Currently only version 1, (aka 'A') is recognised here. */
16794 printf (_("Unknown attributes version '%c'(%d) - expecting 'A'\n"), *p
, *p
);
16799 bfd_vma section_len
;
16801 section_len
= sect
->sh_size
- 1;
16804 while (section_len
> 0)
16807 unsigned int namelen
;
16808 bfd_boolean public_section
;
16809 bfd_boolean gnu_section
;
16811 if (section_len
<= 4)
16813 error (_("Tag section ends prematurely\n"));
16817 attr_len
= byte_get (p
, 4);
16820 if (attr_len
> section_len
)
16822 error (_("Bad attribute length (%u > %u)\n"),
16823 (unsigned) attr_len
, (unsigned) section_len
);
16824 attr_len
= section_len
;
16827 /* PR 17531: file: 001-101425-0.004 */
16828 else if (attr_len
< 5)
16830 error (_("Attribute length of %u is too small\n"), (unsigned) attr_len
);
16835 section_len
-= attr_len
;
16838 namelen
= strnlen ((char *) p
, attr_len
) + 1;
16839 if (namelen
== 0 || namelen
>= attr_len
)
16841 error (_("Corrupt attribute section name\n"));
16846 printf (_("Attribute Section: "));
16847 print_symbol (INT_MAX
, (const char *) p
);
16850 if (public_name
&& streq ((char *) p
, public_name
))
16851 public_section
= TRUE
;
16853 public_section
= FALSE
;
16855 if (streq ((char *) p
, "gnu"))
16856 gnu_section
= TRUE
;
16858 gnu_section
= FALSE
;
16861 attr_len
-= namelen
;
16863 while (attr_len
> 0 && p
< contents
+ sect
->sh_size
)
16868 unsigned char * end
;
16870 /* PR binutils/17531: Safe handling of corrupt files. */
16873 error (_("Unused bytes at end of section\n"));
16880 size
= byte_get (p
, 4);
16881 if (size
> attr_len
)
16883 error (_("Bad subsection length (%u > %u)\n"),
16884 (unsigned) size
, (unsigned) attr_len
);
16888 /* PR binutils/17531: Safe handling of corrupt files. */
16891 error (_("Bad subsection length (%u < 6)\n"),
16899 end
= p
+ size
- 1;
16900 assert (end
<= contents
+ sect
->sh_size
);
16906 printf (_("File Attributes\n"));
16909 printf (_("Section Attributes:"));
16912 printf (_("Symbol Attributes:"));
16913 /* Fall through. */
16917 READ_ULEB (val
, p
, end
);
16920 printf (" %d", val
);
16925 printf (_("Unknown tag: %d\n"), tag
);
16926 public_section
= FALSE
;
16930 if (public_section
&& display_pub_attribute
!= NULL
)
16933 p
= display_pub_attribute (p
, end
);
16936 else if (gnu_section
&& display_proc_gnu_attribute
!= NULL
)
16939 p
= display_gnu_attribute (p
,
16940 display_proc_gnu_attribute
,
16946 printf (_(" Unknown attribute:\n"));
16947 display_raw_attribute (p
, end
);
16962 /* DATA points to the contents of a MIPS GOT that starts at VMA PLTGOT.
16963 Print the Address, Access and Initial fields of an entry at VMA ADDR
16964 and return the VMA of the next entry, or -1 if there was a problem.
16965 Does not read from DATA_END or beyond. */
16968 print_mips_got_entry (unsigned char * data
, bfd_vma pltgot
, bfd_vma addr
,
16969 unsigned char * data_end
)
16972 print_vma (addr
, LONG_HEX
);
16974 if (addr
< pltgot
+ 0xfff0)
16975 printf ("%6d(gp)", (int) (addr
- pltgot
- 0x7ff0));
16977 printf ("%10s", "");
16980 printf ("%*s", is_32bit_elf
? 8 : 16, _("<unknown>"));
16984 unsigned char * from
= data
+ addr
- pltgot
;
16986 if (from
+ (is_32bit_elf
? 4 : 8) > data_end
)
16988 warn (_("MIPS GOT entry extends beyond the end of available data\n"));
16989 printf ("%*s", is_32bit_elf
? 8 : 16, _("<corrupt>"));
16990 return (bfd_vma
) -1;
16994 entry
= byte_get (data
+ addr
- pltgot
, is_32bit_elf
? 4 : 8);
16995 print_vma (entry
, LONG_HEX
);
16998 return addr
+ (is_32bit_elf
? 4 : 8);
17001 /* DATA points to the contents of a MIPS PLT GOT that starts at VMA
17002 PLTGOT. Print the Address and Initial fields of an entry at VMA
17003 ADDR and return the VMA of the next entry. */
17006 print_mips_pltgot_entry (unsigned char * data
, bfd_vma pltgot
, bfd_vma addr
)
17009 print_vma (addr
, LONG_HEX
);
17012 printf ("%*s", is_32bit_elf
? 8 : 16, _("<unknown>"));
17017 entry
= byte_get (data
+ addr
- pltgot
, is_32bit_elf
? 4 : 8);
17018 print_vma (entry
, LONG_HEX
);
17020 return addr
+ (is_32bit_elf
? 4 : 8);
17024 print_mips_ases (unsigned int mask
)
17026 if (mask
& AFL_ASE_DSP
)
17027 fputs ("\n\tDSP ASE", stdout
);
17028 if (mask
& AFL_ASE_DSPR2
)
17029 fputs ("\n\tDSP R2 ASE", stdout
);
17030 if (mask
& AFL_ASE_DSPR3
)
17031 fputs ("\n\tDSP R3 ASE", stdout
);
17032 if (mask
& AFL_ASE_EVA
)
17033 fputs ("\n\tEnhanced VA Scheme", stdout
);
17034 if (mask
& AFL_ASE_MCU
)
17035 fputs ("\n\tMCU (MicroController) ASE", stdout
);
17036 if (mask
& AFL_ASE_MDMX
)
17037 fputs ("\n\tMDMX ASE", stdout
);
17038 if (mask
& AFL_ASE_MIPS3D
)
17039 fputs ("\n\tMIPS-3D ASE", stdout
);
17040 if (mask
& AFL_ASE_MT
)
17041 fputs ("\n\tMT ASE", stdout
);
17042 if (mask
& AFL_ASE_SMARTMIPS
)
17043 fputs ("\n\tSmartMIPS ASE", stdout
);
17044 if (mask
& AFL_ASE_VIRT
)
17045 fputs ("\n\tVZ ASE", stdout
);
17046 if (mask
& AFL_ASE_MSA
)
17047 fputs ("\n\tMSA ASE", stdout
);
17048 if (mask
& AFL_ASE_MIPS16
)
17049 fputs ("\n\tMIPS16 ASE", stdout
);
17050 if (mask
& AFL_ASE_MICROMIPS
)
17051 fputs ("\n\tMICROMIPS ASE", stdout
);
17052 if (mask
& AFL_ASE_XPA
)
17053 fputs ("\n\tXPA ASE", stdout
);
17054 if (mask
& AFL_ASE_MIPS16E2
)
17055 fputs ("\n\tMIPS16e2 ASE", stdout
);
17056 if (mask
& AFL_ASE_CRC
)
17057 fputs ("\n\tCRC ASE", stdout
);
17058 if (mask
& AFL_ASE_GINV
)
17059 fputs ("\n\tGINV ASE", stdout
);
17060 if (mask
& AFL_ASE_LOONGSON_MMI
)
17061 fputs ("\n\tLoongson MMI ASE", stdout
);
17062 if (mask
& AFL_ASE_LOONGSON_CAM
)
17063 fputs ("\n\tLoongson CAM ASE", stdout
);
17064 if (mask
& AFL_ASE_LOONGSON_EXT
)
17065 fputs ("\n\tLoongson EXT ASE", stdout
);
17066 if (mask
& AFL_ASE_LOONGSON_EXT2
)
17067 fputs ("\n\tLoongson EXT2 ASE", stdout
);
17069 fprintf (stdout
, "\n\t%s", _("None"));
17070 else if ((mask
& ~AFL_ASE_MASK
) != 0)
17071 fprintf (stdout
, "\n\t%s (%x)", _("Unknown"), mask
& ~AFL_ASE_MASK
);
17075 print_mips_isa_ext (unsigned int isa_ext
)
17080 fputs (_("None"), stdout
);
17083 fputs ("RMI XLR", stdout
);
17085 case AFL_EXT_OCTEON3
:
17086 fputs ("Cavium Networks Octeon3", stdout
);
17088 case AFL_EXT_OCTEON2
:
17089 fputs ("Cavium Networks Octeon2", stdout
);
17091 case AFL_EXT_OCTEONP
:
17092 fputs ("Cavium Networks OcteonP", stdout
);
17094 case AFL_EXT_OCTEON
:
17095 fputs ("Cavium Networks Octeon", stdout
);
17098 fputs ("Toshiba R5900", stdout
);
17101 fputs ("MIPS R4650", stdout
);
17104 fputs ("LSI R4010", stdout
);
17107 fputs ("NEC VR4100", stdout
);
17110 fputs ("Toshiba R3900", stdout
);
17112 case AFL_EXT_10000
:
17113 fputs ("MIPS R10000", stdout
);
17116 fputs ("Broadcom SB-1", stdout
);
17119 fputs ("NEC VR4111/VR4181", stdout
);
17122 fputs ("NEC VR4120", stdout
);
17125 fputs ("NEC VR5400", stdout
);
17128 fputs ("NEC VR5500", stdout
);
17130 case AFL_EXT_LOONGSON_2E
:
17131 fputs ("ST Microelectronics Loongson 2E", stdout
);
17133 case AFL_EXT_LOONGSON_2F
:
17134 fputs ("ST Microelectronics Loongson 2F", stdout
);
17136 case AFL_EXT_INTERAPTIV_MR2
:
17137 fputs ("Imagination interAptiv MR2", stdout
);
17140 fprintf (stdout
, "%s (%d)", _("Unknown"), isa_ext
);
17145 get_mips_reg_size (int reg_size
)
17147 return (reg_size
== AFL_REG_NONE
) ? 0
17148 : (reg_size
== AFL_REG_32
) ? 32
17149 : (reg_size
== AFL_REG_64
) ? 64
17150 : (reg_size
== AFL_REG_128
) ? 128
17155 process_mips_specific (Filedata
* filedata
)
17157 Elf_Internal_Dyn
* entry
;
17158 Elf_Internal_Shdr
*sect
= NULL
;
17159 size_t liblist_offset
= 0;
17160 size_t liblistno
= 0;
17161 size_t conflictsno
= 0;
17162 size_t options_offset
= 0;
17163 size_t conflicts_offset
= 0;
17164 size_t pltrelsz
= 0;
17166 bfd_vma pltgot
= 0;
17167 bfd_vma mips_pltgot
= 0;
17168 bfd_vma jmprel
= 0;
17169 bfd_vma local_gotno
= 0;
17170 bfd_vma gotsym
= 0;
17171 bfd_vma symtabno
= 0;
17172 bfd_boolean res
= TRUE
;
17174 if (! process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
17175 display_mips_gnu_attribute
))
17178 sect
= find_section (filedata
, ".MIPS.abiflags");
17182 Elf_External_ABIFlags_v0
*abiflags_ext
;
17183 Elf_Internal_ABIFlags_v0 abiflags_in
;
17185 if (sizeof (Elf_External_ABIFlags_v0
) != sect
->sh_size
)
17187 error (_("Corrupt MIPS ABI Flags section.\n"));
17192 abiflags_ext
= get_data (NULL
, filedata
, sect
->sh_offset
, 1,
17193 sect
->sh_size
, _("MIPS ABI Flags section"));
17196 abiflags_in
.version
= BYTE_GET (abiflags_ext
->version
);
17197 abiflags_in
.isa_level
= BYTE_GET (abiflags_ext
->isa_level
);
17198 abiflags_in
.isa_rev
= BYTE_GET (abiflags_ext
->isa_rev
);
17199 abiflags_in
.gpr_size
= BYTE_GET (abiflags_ext
->gpr_size
);
17200 abiflags_in
.cpr1_size
= BYTE_GET (abiflags_ext
->cpr1_size
);
17201 abiflags_in
.cpr2_size
= BYTE_GET (abiflags_ext
->cpr2_size
);
17202 abiflags_in
.fp_abi
= BYTE_GET (abiflags_ext
->fp_abi
);
17203 abiflags_in
.isa_ext
= BYTE_GET (abiflags_ext
->isa_ext
);
17204 abiflags_in
.ases
= BYTE_GET (abiflags_ext
->ases
);
17205 abiflags_in
.flags1
= BYTE_GET (abiflags_ext
->flags1
);
17206 abiflags_in
.flags2
= BYTE_GET (abiflags_ext
->flags2
);
17208 printf ("\nMIPS ABI Flags Version: %d\n", abiflags_in
.version
);
17209 printf ("\nISA: MIPS%d", abiflags_in
.isa_level
);
17210 if (abiflags_in
.isa_rev
> 1)
17211 printf ("r%d", abiflags_in
.isa_rev
);
17212 printf ("\nGPR size: %d",
17213 get_mips_reg_size (abiflags_in
.gpr_size
));
17214 printf ("\nCPR1 size: %d",
17215 get_mips_reg_size (abiflags_in
.cpr1_size
));
17216 printf ("\nCPR2 size: %d",
17217 get_mips_reg_size (abiflags_in
.cpr2_size
));
17218 fputs ("\nFP ABI: ", stdout
);
17219 print_mips_fp_abi_value (abiflags_in
.fp_abi
);
17220 fputs ("ISA Extension: ", stdout
);
17221 print_mips_isa_ext (abiflags_in
.isa_ext
);
17222 fputs ("\nASEs:", stdout
);
17223 print_mips_ases (abiflags_in
.ases
);
17224 printf ("\nFLAGS 1: %8.8lx", abiflags_in
.flags1
);
17225 printf ("\nFLAGS 2: %8.8lx", abiflags_in
.flags2
);
17226 fputc ('\n', stdout
);
17227 free (abiflags_ext
);
17232 /* We have a lot of special sections. Thanks SGI! */
17233 if (filedata
->dynamic_section
== NULL
)
17235 /* No dynamic information available. See if there is static GOT. */
17236 sect
= find_section (filedata
, ".got");
17239 unsigned char *data_end
;
17240 unsigned char *data
;
17244 pltgot
= sect
->sh_addr
;
17247 addr_size
= (is_32bit_elf
? 4 : 8);
17248 end
= pltgot
+ sect
->sh_size
;
17250 data
= (unsigned char *) get_data (NULL
, filedata
, sect
->sh_offset
,
17252 _("Global Offset Table data"));
17253 /* PR 12855: Null data is handled gracefully throughout. */
17254 data_end
= data
+ (end
- pltgot
);
17256 printf (_("\nStatic GOT:\n"));
17257 printf (_(" Canonical gp value: "));
17258 print_vma (ent
+ 0x7ff0, LONG_HEX
);
17261 /* In a dynamic binary GOT[0] is reserved for the dynamic
17262 loader to store the lazy resolver pointer, however in
17263 a static binary it may well have been omitted and GOT
17264 reduced to a table of addresses.
17265 PR 21344: Check for the entry being fully available
17266 before fetching it. */
17268 && data
+ ent
- pltgot
+ addr_size
<= data_end
17269 && byte_get (data
+ ent
- pltgot
, addr_size
) == 0)
17271 printf (_(" Reserved entries:\n"));
17272 printf (_(" %*s %10s %*s\n"),
17273 addr_size
* 2, _("Address"), _("Access"),
17274 addr_size
* 2, _("Value"));
17275 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
17277 if (ent
== (bfd_vma
) -1)
17278 goto sgot_print_fail
;
17280 /* Check for the MSB of GOT[1] being set, identifying a
17281 GNU object. This entry will be used by some runtime
17282 loaders, to store the module pointer. Otherwise this
17283 is an ordinary local entry.
17284 PR 21344: Check for the entry being fully available
17285 before fetching it. */
17287 && data
+ ent
- pltgot
+ addr_size
<= data_end
17288 && (byte_get (data
+ ent
- pltgot
, addr_size
)
17289 >> (addr_size
* 8 - 1)) != 0)
17291 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
17293 if (ent
== (bfd_vma
) -1)
17294 goto sgot_print_fail
;
17299 if (data
!= NULL
&& ent
< end
)
17301 printf (_(" Local entries:\n"));
17302 printf (" %*s %10s %*s\n",
17303 addr_size
* 2, _("Address"), _("Access"),
17304 addr_size
* 2, _("Value"));
17307 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
17309 if (ent
== (bfd_vma
) -1)
17310 goto sgot_print_fail
;
17321 for (entry
= filedata
->dynamic_section
;
17322 /* PR 17531 file: 012-50589-0.004. */
17323 (entry
< filedata
->dynamic_section
+ filedata
->dynamic_nent
17324 && entry
->d_tag
!= DT_NULL
);
17326 switch (entry
->d_tag
)
17328 case DT_MIPS_LIBLIST
:
17330 = offset_from_vma (filedata
, entry
->d_un
.d_val
,
17331 liblistno
* sizeof (Elf32_External_Lib
));
17333 case DT_MIPS_LIBLISTNO
:
17334 liblistno
= entry
->d_un
.d_val
;
17336 case DT_MIPS_OPTIONS
:
17337 options_offset
= offset_from_vma (filedata
, entry
->d_un
.d_val
, 0);
17339 case DT_MIPS_CONFLICT
:
17341 = offset_from_vma (filedata
, entry
->d_un
.d_val
,
17342 conflictsno
* sizeof (Elf32_External_Conflict
));
17344 case DT_MIPS_CONFLICTNO
:
17345 conflictsno
= entry
->d_un
.d_val
;
17348 pltgot
= entry
->d_un
.d_ptr
;
17350 case DT_MIPS_LOCAL_GOTNO
:
17351 local_gotno
= entry
->d_un
.d_val
;
17353 case DT_MIPS_GOTSYM
:
17354 gotsym
= entry
->d_un
.d_val
;
17356 case DT_MIPS_SYMTABNO
:
17357 symtabno
= entry
->d_un
.d_val
;
17359 case DT_MIPS_PLTGOT
:
17360 mips_pltgot
= entry
->d_un
.d_ptr
;
17363 pltrel
= entry
->d_un
.d_val
;
17366 pltrelsz
= entry
->d_un
.d_val
;
17369 jmprel
= entry
->d_un
.d_ptr
;
17375 if (liblist_offset
!= 0 && liblistno
!= 0 && do_dynamic
)
17377 Elf32_External_Lib
* elib
;
17380 elib
= (Elf32_External_Lib
*) get_data (NULL
, filedata
, liblist_offset
,
17381 sizeof (Elf32_External_Lib
),
17383 _("liblist section data"));
17386 printf (ngettext ("\nSection '.liblist' contains %lu entry:\n",
17387 "\nSection '.liblist' contains %lu entries:\n",
17388 (unsigned long) liblistno
),
17389 (unsigned long) liblistno
);
17390 fputs (_(" Library Time Stamp Checksum Version Flags\n"),
17393 for (cnt
= 0; cnt
< liblistno
; ++cnt
)
17400 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
17401 atime
= BYTE_GET (elib
[cnt
].l_time_stamp
);
17402 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
17403 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
17404 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
17406 tmp
= gmtime (&atime
);
17407 snprintf (timebuf
, sizeof (timebuf
),
17408 "%04u-%02u-%02uT%02u:%02u:%02u",
17409 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
17410 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
17412 printf ("%3lu: ", (unsigned long) cnt
);
17413 if (VALID_DYNAMIC_NAME (filedata
, liblist
.l_name
))
17414 print_symbol (20, GET_DYNAMIC_NAME (filedata
, liblist
.l_name
));
17416 printf (_("<corrupt: %9ld>"), liblist
.l_name
);
17417 printf (" %s %#10lx %-7ld", timebuf
, liblist
.l_checksum
,
17418 liblist
.l_version
);
17420 if (liblist
.l_flags
== 0)
17424 static const struct
17431 { " EXACT_MATCH", LL_EXACT_MATCH
},
17432 { " IGNORE_INT_VER", LL_IGNORE_INT_VER
},
17433 { " REQUIRE_MINOR", LL_REQUIRE_MINOR
},
17434 { " EXPORTS", LL_EXPORTS
},
17435 { " DELAY_LOAD", LL_DELAY_LOAD
},
17436 { " DELTA", LL_DELTA
}
17438 int flags
= liblist
.l_flags
;
17441 for (fcnt
= 0; fcnt
< ARRAY_SIZE (l_flags_vals
); ++fcnt
)
17442 if ((flags
& l_flags_vals
[fcnt
].bit
) != 0)
17444 fputs (l_flags_vals
[fcnt
].name
, stdout
);
17445 flags
^= l_flags_vals
[fcnt
].bit
;
17448 printf (" %#x", (unsigned int) flags
);
17460 if (options_offset
!= 0)
17462 Elf_External_Options
* eopt
;
17465 sect
= filedata
->section_headers
;
17467 /* Find the section header so that we get the size. */
17468 sect
= find_section_by_type (filedata
, SHT_MIPS_OPTIONS
);
17469 /* PR 17533 file: 012-277276-0.004. */
17472 error (_("No MIPS_OPTIONS header found\n"));
17476 if (sect
->sh_size
< sizeof (* eopt
))
17478 error (_("The MIPS options section is too small.\n"));
17482 eopt
= (Elf_External_Options
*) get_data (NULL
, filedata
, options_offset
, 1,
17483 sect
->sh_size
, _("options"));
17486 Elf_Internal_Options option
;
17489 while (offset
<= sect
->sh_size
- sizeof (* eopt
))
17491 Elf_External_Options
* eoption
;
17492 unsigned int optsize
;
17494 eoption
= (Elf_External_Options
*) ((char *) eopt
+ offset
);
17496 optsize
= BYTE_GET (eoption
->size
);
17498 /* PR 17531: file: ffa0fa3b. */
17499 if (optsize
< sizeof (* eopt
)
17500 || optsize
> sect
->sh_size
- offset
)
17502 error (_("Invalid size (%u) for MIPS option\n"),
17511 printf (ngettext ("\nSection '%s' contains %d entry:\n",
17512 "\nSection '%s' contains %d entries:\n",
17514 printable_section_name (filedata
, sect
), cnt
);
17520 Elf_External_Options
* eoption
;
17522 eoption
= (Elf_External_Options
*) ((char *) eopt
+ offset
);
17524 option
.kind
= BYTE_GET (eoption
->kind
);
17525 option
.size
= BYTE_GET (eoption
->size
);
17526 option
.section
= BYTE_GET (eoption
->section
);
17527 option
.info
= BYTE_GET (eoption
->info
);
17529 switch (option
.kind
)
17532 /* This shouldn't happen. */
17533 printf (" NULL %" PRId16
" %" PRIx32
,
17534 option
.section
, option
.info
);
17538 printf (" REGINFO ");
17539 if (filedata
->file_header
.e_machine
== EM_MIPS
)
17541 Elf32_External_RegInfo
* ereg
;
17542 Elf32_RegInfo reginfo
;
17545 if (option
.size
< (sizeof (Elf_External_Options
)
17546 + sizeof (Elf32_External_RegInfo
)))
17548 printf (_("<corrupt>\n"));
17549 error (_("Truncated MIPS REGINFO option\n"));
17554 ereg
= (Elf32_External_RegInfo
*) (eoption
+ 1);
17556 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
17557 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
17558 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
17559 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
17560 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
17561 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
17563 printf ("GPR %08" PRIx32
" GP 0x%" PRIx32
"\n",
17564 reginfo
.ri_gprmask
, reginfo
.ri_gp_value
);
17566 " CPR0 %08" PRIx32
" CPR1 %08" PRIx32
17567 " CPR2 %08" PRIx32
" CPR3 %08" PRIx32
"\n",
17568 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
17569 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
17574 Elf64_External_RegInfo
* ereg
;
17575 Elf64_Internal_RegInfo reginfo
;
17577 if (option
.size
< (sizeof (Elf_External_Options
)
17578 + sizeof (Elf64_External_RegInfo
)))
17580 printf (_("<corrupt>\n"));
17581 error (_("Truncated MIPS REGINFO option\n"));
17586 ereg
= (Elf64_External_RegInfo
*) (eoption
+ 1);
17587 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
17588 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
17589 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
17590 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
17591 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
17592 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
17594 printf ("GPR %08" PRIx32
" GP 0x%" PRIx64
"\n",
17595 reginfo
.ri_gprmask
, reginfo
.ri_gp_value
);
17597 " CPR0 %08" PRIx32
" CPR1 %08" PRIx32
17598 " CPR2 %08" PRIx32
" CPR3 %08" PRIx32
"\n",
17599 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
17600 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
17602 offset
+= option
.size
;
17605 case ODK_EXCEPTIONS
:
17606 fputs (" EXCEPTIONS fpe_min(", stdout
);
17607 process_mips_fpe_exception (option
.info
& OEX_FPU_MIN
);
17608 fputs (") fpe_max(", stdout
);
17609 process_mips_fpe_exception ((option
.info
& OEX_FPU_MAX
) >> 8);
17610 fputs (")", stdout
);
17612 if (option
.info
& OEX_PAGE0
)
17613 fputs (" PAGE0", stdout
);
17614 if (option
.info
& OEX_SMM
)
17615 fputs (" SMM", stdout
);
17616 if (option
.info
& OEX_FPDBUG
)
17617 fputs (" FPDBUG", stdout
);
17618 if (option
.info
& OEX_DISMISS
)
17619 fputs (" DISMISS", stdout
);
17623 fputs (" PAD ", stdout
);
17624 if (option
.info
& OPAD_PREFIX
)
17625 fputs (" PREFIX", stdout
);
17626 if (option
.info
& OPAD_POSTFIX
)
17627 fputs (" POSTFIX", stdout
);
17628 if (option
.info
& OPAD_SYMBOL
)
17629 fputs (" SYMBOL", stdout
);
17633 fputs (" HWPATCH ", stdout
);
17634 if (option
.info
& OHW_R4KEOP
)
17635 fputs (" R4KEOP", stdout
);
17636 if (option
.info
& OHW_R8KPFETCH
)
17637 fputs (" R8KPFETCH", stdout
);
17638 if (option
.info
& OHW_R5KEOP
)
17639 fputs (" R5KEOP", stdout
);
17640 if (option
.info
& OHW_R5KCVTL
)
17641 fputs (" R5KCVTL", stdout
);
17645 fputs (" FILL ", stdout
);
17646 /* XXX Print content of info word? */
17650 fputs (" TAGS ", stdout
);
17651 /* XXX Print content of info word? */
17655 fputs (" HWAND ", stdout
);
17656 if (option
.info
& OHWA0_R4KEOP_CHECKED
)
17657 fputs (" R4KEOP_CHECKED", stdout
);
17658 if (option
.info
& OHWA0_R4KEOP_CLEAN
)
17659 fputs (" R4KEOP_CLEAN", stdout
);
17663 fputs (" HWOR ", stdout
);
17664 if (option
.info
& OHWA0_R4KEOP_CHECKED
)
17665 fputs (" R4KEOP_CHECKED", stdout
);
17666 if (option
.info
& OHWA0_R4KEOP_CLEAN
)
17667 fputs (" R4KEOP_CLEAN", stdout
);
17671 printf (" GP_GROUP %#06x self-contained %#06x",
17672 option
.info
& OGP_GROUP
,
17673 (option
.info
& OGP_SELF
) >> 16);
17677 printf (" IDENT %#06x self-contained %#06x",
17678 option
.info
& OGP_GROUP
,
17679 (option
.info
& OGP_SELF
) >> 16);
17683 /* This shouldn't happen. */
17684 printf (" %3d ??? %" PRId16
" %" PRIx32
,
17685 option
.kind
, option
.section
, option
.info
);
17689 len
= sizeof (* eopt
);
17690 while (len
< option
.size
)
17692 unsigned char datum
= *((unsigned char *) eoption
+ len
);
17694 if (ISPRINT (datum
))
17695 printf ("%c", datum
);
17697 printf ("\\%03o", datum
);
17700 fputs ("\n", stdout
);
17702 offset
+= option
.size
;
17710 if (conflicts_offset
!= 0 && conflictsno
!= 0)
17712 Elf32_Conflict
* iconf
;
17715 if (filedata
->dynamic_symbols
== NULL
)
17717 error (_("conflict list found without a dynamic symbol table\n"));
17721 /* PR 21345 - print a slightly more helpful error message
17722 if we are sure that the cmalloc will fail. */
17723 if (conflictsno
> filedata
->file_size
/ sizeof (* iconf
))
17725 error (_("Overlarge number of conflicts detected: %lx\n"),
17726 (long) conflictsno
);
17730 iconf
= (Elf32_Conflict
*) cmalloc (conflictsno
, sizeof (* iconf
));
17733 error (_("Out of memory allocating space for dynamic conflicts\n"));
17739 Elf32_External_Conflict
* econf32
;
17741 econf32
= (Elf32_External_Conflict
*)
17742 get_data (NULL
, filedata
, conflicts_offset
,
17743 sizeof (*econf32
), conflictsno
, _("conflict"));
17750 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
17751 iconf
[cnt
] = BYTE_GET (econf32
[cnt
]);
17757 Elf64_External_Conflict
* econf64
;
17759 econf64
= (Elf64_External_Conflict
*)
17760 get_data (NULL
, filedata
, conflicts_offset
,
17761 sizeof (*econf64
), conflictsno
, _("conflict"));
17768 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
17769 iconf
[cnt
] = BYTE_GET (econf64
[cnt
]);
17774 printf (ngettext ("\nSection '.conflict' contains %lu entry:\n",
17775 "\nSection '.conflict' contains %lu entries:\n",
17776 (unsigned long) conflictsno
),
17777 (unsigned long) conflictsno
);
17778 puts (_(" Num: Index Value Name"));
17780 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
17782 printf ("%5lu: %8lu ", (unsigned long) cnt
, iconf
[cnt
]);
17784 if (iconf
[cnt
] >= filedata
->num_dynamic_syms
)
17785 printf (_("<corrupt symbol index>"));
17788 Elf_Internal_Sym
* psym
;
17790 psym
= & filedata
->dynamic_symbols
[iconf
[cnt
]];
17791 print_vma (psym
->st_value
, FULL_HEX
);
17793 if (VALID_DYNAMIC_NAME (filedata
, psym
->st_name
))
17794 print_symbol (25, GET_DYNAMIC_NAME (filedata
, psym
->st_name
));
17796 printf (_("<corrupt: %14ld>"), psym
->st_name
);
17804 if (pltgot
!= 0 && local_gotno
!= 0)
17806 bfd_vma ent
, local_end
, global_end
;
17808 unsigned char * data
;
17809 unsigned char * data_end
;
17813 addr_size
= (is_32bit_elf
? 4 : 8);
17814 local_end
= pltgot
+ local_gotno
* addr_size
;
17816 /* PR binutils/17533 file: 012-111227-0.004 */
17817 if (symtabno
< gotsym
)
17819 error (_("The GOT symbol offset (%lu) is greater than the symbol table size (%lu)\n"),
17820 (unsigned long) gotsym
, (unsigned long) symtabno
);
17824 global_end
= local_end
+ (symtabno
- gotsym
) * addr_size
;
17825 /* PR 17531: file: 54c91a34. */
17826 if (global_end
< local_end
)
17828 error (_("Too many GOT symbols: %lu\n"), (unsigned long) symtabno
);
17832 offset
= offset_from_vma (filedata
, pltgot
, global_end
- pltgot
);
17833 data
= (unsigned char *) get_data (NULL
, filedata
, offset
,
17834 global_end
- pltgot
, 1,
17835 _("Global Offset Table data"));
17836 /* PR 12855: Null data is handled gracefully throughout. */
17837 data_end
= data
+ (global_end
- pltgot
);
17839 printf (_("\nPrimary GOT:\n"));
17840 printf (_(" Canonical gp value: "));
17841 print_vma (pltgot
+ 0x7ff0, LONG_HEX
);
17844 printf (_(" Reserved entries:\n"));
17845 printf (_(" %*s %10s %*s Purpose\n"),
17846 addr_size
* 2, _("Address"), _("Access"),
17847 addr_size
* 2, _("Initial"));
17848 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
17849 printf (_(" Lazy resolver\n"));
17850 if (ent
== (bfd_vma
) -1)
17851 goto got_print_fail
;
17853 /* Check for the MSB of GOT[1] being set, denoting a GNU object.
17854 This entry will be used by some runtime loaders, to store the
17855 module pointer. Otherwise this is an ordinary local entry.
17856 PR 21344: Check for the entry being fully available before
17859 && data
+ ent
- pltgot
+ addr_size
<= data_end
17860 && (byte_get (data
+ ent
- pltgot
, addr_size
)
17861 >> (addr_size
* 8 - 1)) != 0)
17863 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
17864 printf (_(" Module pointer (GNU extension)\n"));
17865 if (ent
== (bfd_vma
) -1)
17866 goto got_print_fail
;
17870 if (data
!= NULL
&& ent
< local_end
)
17872 printf (_(" Local entries:\n"));
17873 printf (" %*s %10s %*s\n",
17874 addr_size
* 2, _("Address"), _("Access"),
17875 addr_size
* 2, _("Initial"));
17876 while (ent
< local_end
)
17878 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
17880 if (ent
== (bfd_vma
) -1)
17881 goto got_print_fail
;
17886 if (data
!= NULL
&& gotsym
< symtabno
)
17890 printf (_(" Global entries:\n"));
17891 printf (" %*s %10s %*s %*s %-7s %3s %s\n",
17892 addr_size
* 2, _("Address"),
17894 addr_size
* 2, _("Initial"),
17895 addr_size
* 2, _("Sym.Val."),
17897 /* Note for translators: "Ndx" = abbreviated form of "Index". */
17898 _("Ndx"), _("Name"));
17900 sym_width
= (is_32bit_elf
? 80 : 160) - 28 - addr_size
* 6 - 1;
17902 for (i
= gotsym
; i
< symtabno
; i
++)
17904 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
17907 if (filedata
->dynamic_symbols
== NULL
)
17908 printf (_("<no dynamic symbols>"));
17909 else if (i
< filedata
->num_dynamic_syms
)
17911 Elf_Internal_Sym
* psym
= filedata
->dynamic_symbols
+ i
;
17913 print_vma (psym
->st_value
, LONG_HEX
);
17914 printf (" %-7s %3s ",
17915 get_symbol_type (filedata
, ELF_ST_TYPE (psym
->st_info
)),
17916 get_symbol_index_type (filedata
, psym
->st_shndx
));
17918 if (VALID_DYNAMIC_NAME (filedata
, psym
->st_name
))
17919 print_symbol (sym_width
,
17920 GET_DYNAMIC_NAME (filedata
, psym
->st_name
));
17922 printf (_("<corrupt: %14ld>"), psym
->st_name
);
17925 printf (_("<symbol index %lu exceeds number of dynamic symbols>"),
17926 (unsigned long) i
);
17929 if (ent
== (bfd_vma
) -1)
17939 if (mips_pltgot
!= 0 && jmprel
!= 0 && pltrel
!= 0 && pltrelsz
!= 0)
17942 size_t offset
, rel_offset
;
17943 unsigned long count
, i
;
17944 unsigned char * data
;
17945 int addr_size
, sym_width
;
17946 Elf_Internal_Rela
* rels
;
17948 rel_offset
= offset_from_vma (filedata
, jmprel
, pltrelsz
);
17949 if (pltrel
== DT_RELA
)
17951 if (!slurp_rela_relocs (filedata
, rel_offset
, pltrelsz
, &rels
, &count
))
17956 if (!slurp_rel_relocs (filedata
, rel_offset
, pltrelsz
, &rels
, &count
))
17961 addr_size
= (is_32bit_elf
? 4 : 8);
17962 end
= mips_pltgot
+ (2 + count
) * addr_size
;
17964 offset
= offset_from_vma (filedata
, mips_pltgot
, end
- mips_pltgot
);
17965 data
= (unsigned char *) get_data (NULL
, filedata
, offset
, end
- mips_pltgot
,
17966 1, _("Procedure Linkage Table data"));
17970 printf ("\nPLT GOT:\n\n");
17971 printf (_(" Reserved entries:\n"));
17972 printf (_(" %*s %*s Purpose\n"),
17973 addr_size
* 2, _("Address"), addr_size
* 2, _("Initial"));
17974 ent
= print_mips_pltgot_entry (data
, mips_pltgot
, ent
);
17975 printf (_(" PLT lazy resolver\n"));
17976 ent
= print_mips_pltgot_entry (data
, mips_pltgot
, ent
);
17977 printf (_(" Module pointer\n"));
17980 printf (_(" Entries:\n"));
17981 printf (" %*s %*s %*s %-7s %3s %s\n",
17982 addr_size
* 2, _("Address"),
17983 addr_size
* 2, _("Initial"),
17984 addr_size
* 2, _("Sym.Val."), _("Type"), _("Ndx"), _("Name"));
17985 sym_width
= (is_32bit_elf
? 80 : 160) - 17 - addr_size
* 6 - 1;
17986 for (i
= 0; i
< count
; i
++)
17988 unsigned long idx
= get_reloc_symindex (rels
[i
].r_info
);
17990 ent
= print_mips_pltgot_entry (data
, mips_pltgot
, ent
);
17993 if (idx
>= filedata
->num_dynamic_syms
)
17994 printf (_("<corrupt symbol index: %lu>"), idx
);
17997 Elf_Internal_Sym
* psym
= filedata
->dynamic_symbols
+ idx
;
17999 print_vma (psym
->st_value
, LONG_HEX
);
18000 printf (" %-7s %3s ",
18001 get_symbol_type (filedata
, ELF_ST_TYPE (psym
->st_info
)),
18002 get_symbol_index_type (filedata
, psym
->st_shndx
));
18003 if (VALID_DYNAMIC_NAME (filedata
, psym
->st_name
))
18004 print_symbol (sym_width
,
18005 GET_DYNAMIC_NAME (filedata
, psym
->st_name
));
18007 printf (_("<corrupt: %14ld>"), psym
->st_name
);
18021 process_nds32_specific (Filedata
* filedata
)
18023 Elf_Internal_Shdr
*sect
= NULL
;
18025 sect
= find_section (filedata
, ".nds32_e_flags");
18026 if (sect
!= NULL
&& sect
->sh_size
>= 4)
18028 unsigned char *buf
;
18031 printf ("\nNDS32 elf flags section:\n");
18032 buf
= get_data (NULL
, filedata
, sect
->sh_offset
, 1, 4,
18033 _("NDS32 elf flags section"));
18038 flag
= byte_get (buf
, 4);
18040 switch (flag
& 0x3)
18043 printf ("(VEC_SIZE):\tNo entry.\n");
18046 printf ("(VEC_SIZE):\t4 bytes\n");
18049 printf ("(VEC_SIZE):\t16 bytes\n");
18052 printf ("(VEC_SIZE):\treserved\n");
18061 process_gnu_liblist (Filedata
* filedata
)
18063 Elf_Internal_Shdr
* section
;
18064 Elf_Internal_Shdr
* string_sec
;
18065 Elf32_External_Lib
* elib
;
18067 size_t strtab_size
;
18069 unsigned long num_liblist
;
18071 bfd_boolean res
= TRUE
;
18076 for (i
= 0, section
= filedata
->section_headers
;
18077 i
< filedata
->file_header
.e_shnum
;
18080 switch (section
->sh_type
)
18082 case SHT_GNU_LIBLIST
:
18083 if (section
->sh_link
>= filedata
->file_header
.e_shnum
)
18086 elib
= (Elf32_External_Lib
*)
18087 get_data (NULL
, filedata
, section
->sh_offset
, 1, section
->sh_size
,
18088 _("liblist section data"));
18096 string_sec
= filedata
->section_headers
+ section
->sh_link
;
18097 strtab
= (char *) get_data (NULL
, filedata
, string_sec
->sh_offset
, 1,
18098 string_sec
->sh_size
,
18099 _("liblist string table"));
18101 || section
->sh_entsize
!= sizeof (Elf32_External_Lib
))
18108 strtab_size
= string_sec
->sh_size
;
18110 num_liblist
= section
->sh_size
/ sizeof (Elf32_External_Lib
);
18111 printf (ngettext ("\nLibrary list section '%s' contains %lu entries:\n",
18112 "\nLibrary list section '%s' contains %lu entries:\n",
18114 printable_section_name (filedata
, section
),
18117 puts (_(" Library Time Stamp Checksum Version Flags"));
18119 for (cnt
= 0; cnt
< section
->sh_size
/ sizeof (Elf32_External_Lib
);
18127 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
18128 atime
= BYTE_GET (elib
[cnt
].l_time_stamp
);
18129 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
18130 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
18131 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
18133 tmp
= gmtime (&atime
);
18134 snprintf (timebuf
, sizeof (timebuf
),
18135 "%04u-%02u-%02uT%02u:%02u:%02u",
18136 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
18137 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
18139 printf ("%3lu: ", (unsigned long) cnt
);
18141 printf ("%-20s", liblist
.l_name
< strtab_size
18142 ? strtab
+ liblist
.l_name
: _("<corrupt>"));
18144 printf ("%-20.20s", liblist
.l_name
< strtab_size
18145 ? strtab
+ liblist
.l_name
: _("<corrupt>"));
18146 printf (" %s %#010lx %-7ld %-7ld\n", timebuf
, liblist
.l_checksum
,
18147 liblist
.l_version
, liblist
.l_flags
);
18158 static const char *
18159 get_note_type (Filedata
* filedata
, unsigned e_type
)
18161 static char buff
[64];
18163 if (filedata
->file_header
.e_type
== ET_CORE
)
18167 return _("NT_AUXV (auxiliary vector)");
18169 return _("NT_PRSTATUS (prstatus structure)");
18171 return _("NT_FPREGSET (floating point registers)");
18173 return _("NT_PRPSINFO (prpsinfo structure)");
18174 case NT_TASKSTRUCT
:
18175 return _("NT_TASKSTRUCT (task structure)");
18177 return _("NT_PRXFPREG (user_xfpregs structure)");
18179 return _("NT_PPC_VMX (ppc Altivec registers)");
18181 return _("NT_PPC_VSX (ppc VSX registers)");
18183 return _("NT_PPC_TAR (ppc TAR register)");
18185 return _("NT_PPC_PPR (ppc PPR register)");
18187 return _("NT_PPC_DSCR (ppc DSCR register)");
18189 return _("NT_PPC_EBB (ppc EBB registers)");
18191 return _("NT_PPC_PMU (ppc PMU registers)");
18192 case NT_PPC_TM_CGPR
:
18193 return _("NT_PPC_TM_CGPR (ppc checkpointed GPR registers)");
18194 case NT_PPC_TM_CFPR
:
18195 return _("NT_PPC_TM_CFPR (ppc checkpointed floating point registers)");
18196 case NT_PPC_TM_CVMX
:
18197 return _("NT_PPC_TM_CVMX (ppc checkpointed Altivec registers)");
18198 case NT_PPC_TM_CVSX
:
18199 return _("NT_PPC_TM_CVSX (ppc checkpointed VSX registers)");
18200 case NT_PPC_TM_SPR
:
18201 return _("NT_PPC_TM_SPR (ppc TM special purpose registers)");
18202 case NT_PPC_TM_CTAR
:
18203 return _("NT_PPC_TM_CTAR (ppc checkpointed TAR register)");
18204 case NT_PPC_TM_CPPR
:
18205 return _("NT_PPC_TM_CPPR (ppc checkpointed PPR register)");
18206 case NT_PPC_TM_CDSCR
:
18207 return _("NT_PPC_TM_CDSCR (ppc checkpointed DSCR register)");
18209 return _("NT_386_TLS (x86 TLS information)");
18210 case NT_386_IOPERM
:
18211 return _("NT_386_IOPERM (x86 I/O permissions)");
18212 case NT_X86_XSTATE
:
18213 return _("NT_X86_XSTATE (x86 XSAVE extended state)");
18215 return _("NT_X86_CET (x86 CET state)");
18216 case NT_S390_HIGH_GPRS
:
18217 return _("NT_S390_HIGH_GPRS (s390 upper register halves)");
18218 case NT_S390_TIMER
:
18219 return _("NT_S390_TIMER (s390 timer register)");
18220 case NT_S390_TODCMP
:
18221 return _("NT_S390_TODCMP (s390 TOD comparator register)");
18222 case NT_S390_TODPREG
:
18223 return _("NT_S390_TODPREG (s390 TOD programmable register)");
18225 return _("NT_S390_CTRS (s390 control registers)");
18226 case NT_S390_PREFIX
:
18227 return _("NT_S390_PREFIX (s390 prefix register)");
18228 case NT_S390_LAST_BREAK
:
18229 return _("NT_S390_LAST_BREAK (s390 last breaking event address)");
18230 case NT_S390_SYSTEM_CALL
:
18231 return _("NT_S390_SYSTEM_CALL (s390 system call restart data)");
18233 return _("NT_S390_TDB (s390 transaction diagnostic block)");
18234 case NT_S390_VXRS_LOW
:
18235 return _("NT_S390_VXRS_LOW (s390 vector registers 0-15 upper half)");
18236 case NT_S390_VXRS_HIGH
:
18237 return _("NT_S390_VXRS_HIGH (s390 vector registers 16-31)");
18238 case NT_S390_GS_CB
:
18239 return _("NT_S390_GS_CB (s390 guarded-storage registers)");
18240 case NT_S390_GS_BC
:
18241 return _("NT_S390_GS_BC (s390 guarded-storage broadcast control)");
18243 return _("NT_ARM_VFP (arm VFP registers)");
18245 return _("NT_ARM_TLS (AArch TLS registers)");
18246 case NT_ARM_HW_BREAK
:
18247 return _("NT_ARM_HW_BREAK (AArch hardware breakpoint registers)");
18248 case NT_ARM_HW_WATCH
:
18249 return _("NT_ARM_HW_WATCH (AArch hardware watchpoint registers)");
18251 return _("NT_ARC_V2 (ARC HS accumulator/extra registers)");
18253 return _("NT_PSTATUS (pstatus structure)");
18255 return _("NT_FPREGS (floating point registers)");
18257 return _("NT_PSINFO (psinfo structure)");
18259 return _("NT_LWPSTATUS (lwpstatus_t structure)");
18261 return _("NT_LWPSINFO (lwpsinfo_t structure)");
18262 case NT_WIN32PSTATUS
:
18263 return _("NT_WIN32PSTATUS (win32_pstatus structure)");
18265 return _("NT_SIGINFO (siginfo_t data)");
18267 return _("NT_FILE (mapped files)");
18275 return _("NT_VERSION (version)");
18277 return _("NT_ARCH (architecture)");
18278 case NT_GNU_BUILD_ATTRIBUTE_OPEN
:
18280 case NT_GNU_BUILD_ATTRIBUTE_FUNC
:
18286 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
18291 print_core_note (Elf_Internal_Note
*pnote
)
18293 unsigned int addr_size
= is_32bit_elf
? 4 : 8;
18294 bfd_vma count
, page_size
;
18295 unsigned char *descdata
, *filenames
, *descend
;
18297 if (pnote
->type
!= NT_FILE
)
18307 printf (_(" Cannot decode 64-bit note in 32-bit build\n"));
18308 /* Still "successful". */
18313 if (pnote
->descsz
< 2 * addr_size
)
18315 error (_(" Malformed note - too short for header\n"));
18319 descdata
= (unsigned char *) pnote
->descdata
;
18320 descend
= descdata
+ pnote
->descsz
;
18322 if (descdata
[pnote
->descsz
- 1] != '\0')
18324 error (_(" Malformed note - does not end with \\0\n"));
18328 count
= byte_get (descdata
, addr_size
);
18329 descdata
+= addr_size
;
18331 page_size
= byte_get (descdata
, addr_size
);
18332 descdata
+= addr_size
;
18334 if (count
> ((bfd_vma
) -1 - 2 * addr_size
) / (3 * addr_size
)
18335 || pnote
->descsz
< 2 * addr_size
+ count
* 3 * addr_size
)
18337 error (_(" Malformed note - too short for supplied file count\n"));
18341 printf (_(" Page size: "));
18342 print_vma (page_size
, DEC
);
18345 printf (_(" %*s%*s%*s\n"),
18346 (int) (2 + 2 * addr_size
), _("Start"),
18347 (int) (4 + 2 * addr_size
), _("End"),
18348 (int) (4 + 2 * addr_size
), _("Page Offset"));
18349 filenames
= descdata
+ count
* 3 * addr_size
;
18350 while (count
-- > 0)
18352 bfd_vma start
, end
, file_ofs
;
18354 if (filenames
== descend
)
18356 error (_(" Malformed note - filenames end too early\n"));
18360 start
= byte_get (descdata
, addr_size
);
18361 descdata
+= addr_size
;
18362 end
= byte_get (descdata
, addr_size
);
18363 descdata
+= addr_size
;
18364 file_ofs
= byte_get (descdata
, addr_size
);
18365 descdata
+= addr_size
;
18368 print_vma (start
, FULL_HEX
);
18370 print_vma (end
, FULL_HEX
);
18372 print_vma (file_ofs
, FULL_HEX
);
18373 printf ("\n %s\n", filenames
);
18375 filenames
+= 1 + strlen ((char *) filenames
);
18381 static const char *
18382 get_gnu_elf_note_type (unsigned e_type
)
18384 /* NB/ Keep this switch statement in sync with print_gnu_note (). */
18387 case NT_GNU_ABI_TAG
:
18388 return _("NT_GNU_ABI_TAG (ABI version tag)");
18390 return _("NT_GNU_HWCAP (DSO-supplied software HWCAP info)");
18391 case NT_GNU_BUILD_ID
:
18392 return _("NT_GNU_BUILD_ID (unique build ID bitstring)");
18393 case NT_GNU_GOLD_VERSION
:
18394 return _("NT_GNU_GOLD_VERSION (gold version)");
18395 case NT_GNU_PROPERTY_TYPE_0
:
18396 return _("NT_GNU_PROPERTY_TYPE_0");
18397 case NT_GNU_BUILD_ATTRIBUTE_OPEN
:
18398 return _("NT_GNU_BUILD_ATTRIBUTE_OPEN");
18399 case NT_GNU_BUILD_ATTRIBUTE_FUNC
:
18400 return _("NT_GNU_BUILD_ATTRIBUTE_FUNC");
18403 static char buff
[64];
18405 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
18412 decode_x86_compat_isa (unsigned int bitmask
)
18416 unsigned int bit
= bitmask
& (- bitmask
);
18421 case GNU_PROPERTY_X86_COMPAT_ISA_1_486
:
18424 case GNU_PROPERTY_X86_COMPAT_ISA_1_586
:
18427 case GNU_PROPERTY_X86_COMPAT_ISA_1_686
:
18430 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE
:
18433 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE2
:
18436 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE3
:
18439 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSSE3
:
18442 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE4_1
:
18445 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE4_2
:
18448 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX
:
18451 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX2
:
18454 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512F
:
18455 printf ("AVX512F");
18457 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512CD
:
18458 printf ("AVX512CD");
18460 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512ER
:
18461 printf ("AVX512ER");
18463 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512PF
:
18464 printf ("AVX512PF");
18466 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512VL
:
18467 printf ("AVX512VL");
18469 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512DQ
:
18470 printf ("AVX512DQ");
18472 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512BW
:
18473 printf ("AVX512BW");
18476 printf (_("<unknown: %x>"), bit
);
18485 decode_x86_compat_2_isa (unsigned int bitmask
)
18489 printf (_("<None>"));
18495 unsigned int bit
= bitmask
& (- bitmask
);
18500 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_CMOV
:
18503 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE
:
18506 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE2
:
18509 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE3
:
18512 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSSE3
:
18515 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE4_1
:
18518 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE4_2
:
18521 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX
:
18524 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX2
:
18527 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_FMA
:
18530 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512F
:
18531 printf ("AVX512F");
18533 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512CD
:
18534 printf ("AVX512CD");
18536 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512ER
:
18537 printf ("AVX512ER");
18539 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512PF
:
18540 printf ("AVX512PF");
18542 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512VL
:
18543 printf ("AVX512VL");
18545 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512DQ
:
18546 printf ("AVX512DQ");
18548 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512BW
:
18549 printf ("AVX512BW");
18551 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_4FMAPS
:
18552 printf ("AVX512_4FMAPS");
18554 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_4VNNIW
:
18555 printf ("AVX512_4VNNIW");
18557 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_BITALG
:
18558 printf ("AVX512_BITALG");
18560 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_IFMA
:
18561 printf ("AVX512_IFMA");
18563 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_VBMI
:
18564 printf ("AVX512_VBMI");
18566 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_VBMI2
:
18567 printf ("AVX512_VBMI2");
18569 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_VNNI
:
18570 printf ("AVX512_VNNI");
18572 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_BF16
:
18573 printf ("AVX512_BF16");
18576 printf (_("<unknown: %x>"), bit
);
18585 decode_x86_isa (unsigned int bitmask
)
18589 printf (_("x86-64-baseline"));
18595 unsigned int bit
= bitmask
& (- bitmask
);
18600 case GNU_PROPERTY_X86_ISA_1_V2
:
18601 printf ("x86-64-v2");
18603 case GNU_PROPERTY_X86_ISA_1_V3
:
18604 printf ("x86-64-v3");
18606 case GNU_PROPERTY_X86_ISA_1_V4
:
18607 printf ("x86-64-v4");
18610 printf (_("<unknown: %x>"), bit
);
18619 decode_x86_feature_1 (unsigned int bitmask
)
18623 printf (_("<None>"));
18629 unsigned int bit
= bitmask
& (- bitmask
);
18634 case GNU_PROPERTY_X86_FEATURE_1_IBT
:
18637 case GNU_PROPERTY_X86_FEATURE_1_SHSTK
:
18641 printf (_("<unknown: %x>"), bit
);
18650 decode_x86_feature_2 (unsigned int bitmask
)
18654 printf (_("<None>"));
18660 unsigned int bit
= bitmask
& (- bitmask
);
18665 case GNU_PROPERTY_X86_FEATURE_2_X86
:
18668 case GNU_PROPERTY_X86_FEATURE_2_X87
:
18671 case GNU_PROPERTY_X86_FEATURE_2_MMX
:
18674 case GNU_PROPERTY_X86_FEATURE_2_XMM
:
18677 case GNU_PROPERTY_X86_FEATURE_2_YMM
:
18680 case GNU_PROPERTY_X86_FEATURE_2_ZMM
:
18683 case GNU_PROPERTY_X86_FEATURE_2_TMM
:
18686 case GNU_PROPERTY_X86_FEATURE_2_MASK
:
18689 case GNU_PROPERTY_X86_FEATURE_2_FXSR
:
18692 case GNU_PROPERTY_X86_FEATURE_2_XSAVE
:
18695 case GNU_PROPERTY_X86_FEATURE_2_XSAVEOPT
:
18696 printf ("XSAVEOPT");
18698 case GNU_PROPERTY_X86_FEATURE_2_XSAVEC
:
18702 printf (_("<unknown: %x>"), bit
);
18711 decode_aarch64_feature_1_and (unsigned int bitmask
)
18715 unsigned int bit
= bitmask
& (- bitmask
);
18720 case GNU_PROPERTY_AARCH64_FEATURE_1_BTI
:
18724 case GNU_PROPERTY_AARCH64_FEATURE_1_PAC
:
18729 printf (_("<unknown: %x>"), bit
);
18738 print_gnu_property_note (Filedata
* filedata
, Elf_Internal_Note
* pnote
)
18740 unsigned char * ptr
= (unsigned char *) pnote
->descdata
;
18741 unsigned char * ptr_end
= ptr
+ pnote
->descsz
;
18742 unsigned int size
= is_32bit_elf
? 4 : 8;
18744 printf (_(" Properties: "));
18746 if (pnote
->descsz
< 8 || (pnote
->descsz
% size
) != 0)
18748 printf (_("<corrupt GNU_PROPERTY_TYPE, size = %#lx>\n"), pnote
->descsz
);
18752 while (ptr
< ptr_end
)
18756 unsigned int datasz
;
18758 if ((size_t) (ptr_end
- ptr
) < 8)
18760 printf (_("<corrupt descsz: %#lx>\n"), pnote
->descsz
);
18764 type
= byte_get (ptr
, 4);
18765 datasz
= byte_get (ptr
+ 4, 4);
18769 if (datasz
> (size_t) (ptr_end
- ptr
))
18771 printf (_("<corrupt type (%#x) datasz: %#x>\n"),
18776 if (type
>= GNU_PROPERTY_LOPROC
&& type
<= GNU_PROPERTY_HIPROC
)
18778 if (filedata
->file_header
.e_machine
== EM_X86_64
18779 || filedata
->file_header
.e_machine
== EM_IAMCU
18780 || filedata
->file_header
.e_machine
== EM_386
)
18782 unsigned int bitmask
;
18785 bitmask
= byte_get (ptr
, 4);
18791 case GNU_PROPERTY_X86_ISA_1_USED
:
18793 printf (_("x86 ISA used: <corrupt length: %#x> "),
18797 printf ("x86 ISA used: ");
18798 decode_x86_isa (bitmask
);
18802 case GNU_PROPERTY_X86_ISA_1_NEEDED
:
18804 printf (_("x86 ISA needed: <corrupt length: %#x> "),
18808 printf ("x86 ISA needed: ");
18809 decode_x86_isa (bitmask
);
18813 case GNU_PROPERTY_X86_FEATURE_1_AND
:
18815 printf (_("x86 feature: <corrupt length: %#x> "),
18819 printf ("x86 feature: ");
18820 decode_x86_feature_1 (bitmask
);
18824 case GNU_PROPERTY_X86_FEATURE_2_USED
:
18826 printf (_("x86 feature used: <corrupt length: %#x> "),
18830 printf ("x86 feature used: ");
18831 decode_x86_feature_2 (bitmask
);
18835 case GNU_PROPERTY_X86_FEATURE_2_NEEDED
:
18837 printf (_("x86 feature needed: <corrupt length: %#x> "), datasz
);
18840 printf ("x86 feature needed: ");
18841 decode_x86_feature_2 (bitmask
);
18845 case GNU_PROPERTY_X86_COMPAT_ISA_1_USED
:
18847 printf (_("x86 ISA used: <corrupt length: %#x> "),
18851 printf ("x86 ISA used: ");
18852 decode_x86_compat_isa (bitmask
);
18856 case GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED
:
18858 printf (_("x86 ISA needed: <corrupt length: %#x> "),
18862 printf ("x86 ISA needed: ");
18863 decode_x86_compat_isa (bitmask
);
18867 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_USED
:
18869 printf (_("x86 ISA used: <corrupt length: %#x> "),
18873 printf ("x86 ISA used: ");
18874 decode_x86_compat_2_isa (bitmask
);
18878 case GNU_PROPERTY_X86_COMPAT_2_ISA_1_NEEDED
:
18880 printf (_("x86 ISA needed: <corrupt length: %#x> "),
18884 printf ("x86 ISA needed: ");
18885 decode_x86_compat_2_isa (bitmask
);
18893 else if (filedata
->file_header
.e_machine
== EM_AARCH64
)
18895 if (type
== GNU_PROPERTY_AARCH64_FEATURE_1_AND
)
18897 printf ("AArch64 feature: ");
18899 printf (_("<corrupt length: %#x> "), datasz
);
18901 decode_aarch64_feature_1_and (byte_get (ptr
, 4));
18910 case GNU_PROPERTY_STACK_SIZE
:
18911 printf (_("stack size: "));
18912 if (datasz
!= size
)
18913 printf (_("<corrupt length: %#x> "), datasz
);
18915 printf ("%#lx", (unsigned long) byte_get (ptr
, size
));
18918 case GNU_PROPERTY_NO_COPY_ON_PROTECTED
:
18919 printf ("no copy on protected ");
18921 printf (_("<corrupt length: %#x> "), datasz
);
18929 if (type
< GNU_PROPERTY_LOPROC
)
18930 printf (_("<unknown type %#x data: "), type
);
18931 else if (type
< GNU_PROPERTY_LOUSER
)
18932 printf (_("<procesor-specific type %#x data: "), type
);
18934 printf (_("<application-specific type %#x data: "), type
);
18935 for (j
= 0; j
< datasz
; ++j
)
18936 printf ("%02x ", ptr
[j
] & 0xff);
18940 ptr
+= ((datasz
+ (size
- 1)) & ~ (size
- 1));
18941 if (ptr
== ptr_end
)
18954 print_gnu_note (Filedata
* filedata
, Elf_Internal_Note
*pnote
)
18956 /* NB/ Keep this switch statement in sync with get_gnu_elf_note_type (). */
18957 switch (pnote
->type
)
18959 case NT_GNU_BUILD_ID
:
18963 printf (_(" Build ID: "));
18964 for (i
= 0; i
< pnote
->descsz
; ++i
)
18965 printf ("%02x", pnote
->descdata
[i
] & 0xff);
18970 case NT_GNU_ABI_TAG
:
18972 unsigned long os
, major
, minor
, subminor
;
18973 const char *osname
;
18975 /* PR 17531: file: 030-599401-0.004. */
18976 if (pnote
->descsz
< 16)
18978 printf (_(" <corrupt GNU_ABI_TAG>\n"));
18982 os
= byte_get ((unsigned char *) pnote
->descdata
, 4);
18983 major
= byte_get ((unsigned char *) pnote
->descdata
+ 4, 4);
18984 minor
= byte_get ((unsigned char *) pnote
->descdata
+ 8, 4);
18985 subminor
= byte_get ((unsigned char *) pnote
->descdata
+ 12, 4);
18989 case GNU_ABI_TAG_LINUX
:
18992 case GNU_ABI_TAG_HURD
:
18995 case GNU_ABI_TAG_SOLARIS
:
18996 osname
= "Solaris";
18998 case GNU_ABI_TAG_FREEBSD
:
18999 osname
= "FreeBSD";
19001 case GNU_ABI_TAG_NETBSD
:
19004 case GNU_ABI_TAG_SYLLABLE
:
19005 osname
= "Syllable";
19007 case GNU_ABI_TAG_NACL
:
19011 osname
= "Unknown";
19015 printf (_(" OS: %s, ABI: %ld.%ld.%ld\n"), osname
,
19016 major
, minor
, subminor
);
19020 case NT_GNU_GOLD_VERSION
:
19024 printf (_(" Version: "));
19025 for (i
= 0; i
< pnote
->descsz
&& pnote
->descdata
[i
] != '\0'; ++i
)
19026 printf ("%c", pnote
->descdata
[i
]);
19033 unsigned long num_entries
, mask
;
19035 /* Hardware capabilities information. Word 0 is the number of entries.
19036 Word 1 is a bitmask of enabled entries. The rest of the descriptor
19037 is a series of entries, where each entry is a single byte followed
19038 by a nul terminated string. The byte gives the bit number to test
19039 if enabled in the bitmask. */
19040 printf (_(" Hardware Capabilities: "));
19041 if (pnote
->descsz
< 8)
19043 error (_("<corrupt GNU_HWCAP>\n"));
19046 num_entries
= byte_get ((unsigned char *) pnote
->descdata
, 4);
19047 mask
= byte_get ((unsigned char *) pnote
->descdata
+ 4, 4);
19048 printf (_("num entries: %ld, enabled mask: %lx\n"), num_entries
, mask
);
19049 /* FIXME: Add code to display the entries... */
19053 case NT_GNU_PROPERTY_TYPE_0
:
19054 print_gnu_property_note (filedata
, pnote
);
19058 /* Handle unrecognised types. An error message should have already been
19059 created by get_gnu_elf_note_type(), so all that we need to do is to
19060 display the data. */
19064 printf (_(" Description data: "));
19065 for (i
= 0; i
< pnote
->descsz
; ++i
)
19066 printf ("%02x ", pnote
->descdata
[i
] & 0xff);
19075 static const char *
19076 get_v850_elf_note_type (enum v850_notes n_type
)
19078 static char buff
[64];
19082 case V850_NOTE_ALIGNMENT
: return _("Alignment of 8-byte objects");
19083 case V850_NOTE_DATA_SIZE
: return _("Sizeof double and long double");
19084 case V850_NOTE_FPU_INFO
: return _("Type of FPU support needed");
19085 case V850_NOTE_SIMD_INFO
: return _("Use of SIMD instructions");
19086 case V850_NOTE_CACHE_INFO
: return _("Use of cache");
19087 case V850_NOTE_MMU_INFO
: return _("Use of MMU");
19089 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), n_type
);
19095 print_v850_note (Elf_Internal_Note
* pnote
)
19099 if (pnote
->descsz
!= 4)
19102 val
= byte_get ((unsigned char *) pnote
->descdata
, pnote
->descsz
);
19106 printf (_("not set\n"));
19110 switch (pnote
->type
)
19112 case V850_NOTE_ALIGNMENT
:
19115 case EF_RH850_DATA_ALIGN4
: printf (_("4-byte\n")); return TRUE
;
19116 case EF_RH850_DATA_ALIGN8
: printf (_("8-byte\n")); return TRUE
;
19120 case V850_NOTE_DATA_SIZE
:
19123 case EF_RH850_DOUBLE32
: printf (_("4-bytes\n")); return TRUE
;
19124 case EF_RH850_DOUBLE64
: printf (_("8-bytes\n")); return TRUE
;
19128 case V850_NOTE_FPU_INFO
:
19131 case EF_RH850_FPU20
: printf (_("FPU-2.0\n")); return TRUE
;
19132 case EF_RH850_FPU30
: printf (_("FPU-3.0\n")); return TRUE
;
19136 case V850_NOTE_MMU_INFO
:
19137 case V850_NOTE_CACHE_INFO
:
19138 case V850_NOTE_SIMD_INFO
:
19139 if (val
== EF_RH850_SIMD
)
19141 printf (_("yes\n"));
19147 /* An 'unknown note type' message will already have been displayed. */
19151 printf (_("unknown value: %x\n"), val
);
19156 process_netbsd_elf_note (Elf_Internal_Note
* pnote
)
19158 unsigned int version
;
19160 switch (pnote
->type
)
19162 case NT_NETBSD_IDENT
:
19163 if (pnote
->descsz
< 1)
19165 version
= byte_get ((unsigned char *) pnote
->descdata
, sizeof (version
));
19166 if ((version
/ 10000) % 100)
19167 printf (" NetBSD\t\t0x%08lx\tIDENT %u (%u.%u%s%c)\n", pnote
->descsz
,
19168 version
, version
/ 100000000, (version
/ 1000000) % 100,
19169 (version
/ 10000) % 100 > 26 ? "Z" : "",
19170 'A' + (version
/ 10000) % 26);
19172 printf (" NetBSD\t\t0x%08lx\tIDENT %u (%u.%u.%u)\n", pnote
->descsz
,
19173 version
, version
/ 100000000, (version
/ 1000000) % 100,
19174 (version
/ 100) % 100);
19177 case NT_NETBSD_MARCH
:
19178 printf (" NetBSD\t\t0x%08lx\tMARCH <%s>\n", pnote
->descsz
,
19182 #ifdef NT_NETBSD_PAX
19183 case NT_NETBSD_PAX
:
19184 if (pnote
->descsz
< 1)
19186 version
= byte_get ((unsigned char *) pnote
->descdata
, sizeof (version
));
19187 printf (" NetBSD\t\t0x%08lx\tPaX <%s%s%s%s%s%s>\n", pnote
->descsz
,
19188 ((version
& NT_NETBSD_PAX_MPROTECT
) ? "+mprotect" : ""),
19189 ((version
& NT_NETBSD_PAX_NOMPROTECT
) ? "-mprotect" : ""),
19190 ((version
& NT_NETBSD_PAX_GUARD
) ? "+guard" : ""),
19191 ((version
& NT_NETBSD_PAX_NOGUARD
) ? "-guard" : ""),
19192 ((version
& NT_NETBSD_PAX_ASLR
) ? "+ASLR" : ""),
19193 ((version
& NT_NETBSD_PAX_NOASLR
) ? "-ASLR" : ""));
19198 printf (" NetBSD\t0x%08lx\tUnknown note type: (0x%08lx)\n",
19199 pnote
->descsz
, pnote
->type
);
19203 static const char *
19204 get_freebsd_elfcore_note_type (Filedata
* filedata
, unsigned e_type
)
19208 case NT_FREEBSD_THRMISC
:
19209 return _("NT_THRMISC (thrmisc structure)");
19210 case NT_FREEBSD_PROCSTAT_PROC
:
19211 return _("NT_PROCSTAT_PROC (proc data)");
19212 case NT_FREEBSD_PROCSTAT_FILES
:
19213 return _("NT_PROCSTAT_FILES (files data)");
19214 case NT_FREEBSD_PROCSTAT_VMMAP
:
19215 return _("NT_PROCSTAT_VMMAP (vmmap data)");
19216 case NT_FREEBSD_PROCSTAT_GROUPS
:
19217 return _("NT_PROCSTAT_GROUPS (groups data)");
19218 case NT_FREEBSD_PROCSTAT_UMASK
:
19219 return _("NT_PROCSTAT_UMASK (umask data)");
19220 case NT_FREEBSD_PROCSTAT_RLIMIT
:
19221 return _("NT_PROCSTAT_RLIMIT (rlimit data)");
19222 case NT_FREEBSD_PROCSTAT_OSREL
:
19223 return _("NT_PROCSTAT_OSREL (osreldate data)");
19224 case NT_FREEBSD_PROCSTAT_PSSTRINGS
:
19225 return _("NT_PROCSTAT_PSSTRINGS (ps_strings data)");
19226 case NT_FREEBSD_PROCSTAT_AUXV
:
19227 return _("NT_PROCSTAT_AUXV (auxv data)");
19228 case NT_FREEBSD_PTLWPINFO
:
19229 return _("NT_PTLWPINFO (ptrace_lwpinfo structure)");
19231 return get_note_type (filedata
, e_type
);
19234 static const char *
19235 get_netbsd_elfcore_note_type (Filedata
* filedata
, unsigned e_type
)
19237 static char buff
[64];
19241 case NT_NETBSDCORE_PROCINFO
:
19242 /* NetBSD core "procinfo" structure. */
19243 return _("NetBSD procinfo structure");
19245 #ifdef NT_NETBSDCORE_AUXV
19246 case NT_NETBSDCORE_AUXV
:
19247 return _("NetBSD ELF auxiliary vector data");
19250 #ifdef NT_NETBSDCORE_LWPSTATUS
19251 case NT_NETBSDCORE_LWPSTATUS
:
19252 return _("PT_LWPSTATUS (ptrace_lwpstatus structure)");
19256 /* As of Jan 2020 there are no other machine-independent notes
19257 defined for NetBSD core files. If the note type is less
19258 than the start of the machine-dependent note types, we don't
19261 if (e_type
< NT_NETBSDCORE_FIRSTMACH
)
19263 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
19269 switch (filedata
->file_header
.e_machine
)
19271 /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0
19272 and PT_GETFPREGS == mach+2. */
19277 case EM_SPARC32PLUS
:
19281 case NT_NETBSDCORE_FIRSTMACH
+ 0:
19282 return _("PT_GETREGS (reg structure)");
19283 case NT_NETBSDCORE_FIRSTMACH
+ 2:
19284 return _("PT_GETFPREGS (fpreg structure)");
19290 /* On SuperH, PT_GETREGS == mach+3 and PT_GETFPREGS == mach+5.
19291 There's also old PT___GETREGS40 == mach + 1 for old reg
19292 structure which lacks GBR. */
19296 case NT_NETBSDCORE_FIRSTMACH
+ 1:
19297 return _("PT___GETREGS40 (old reg structure)");
19298 case NT_NETBSDCORE_FIRSTMACH
+ 3:
19299 return _("PT_GETREGS (reg structure)");
19300 case NT_NETBSDCORE_FIRSTMACH
+ 5:
19301 return _("PT_GETFPREGS (fpreg structure)");
19307 /* On all other arch's, PT_GETREGS == mach+1 and
19308 PT_GETFPREGS == mach+3. */
19312 case NT_NETBSDCORE_FIRSTMACH
+ 1:
19313 return _("PT_GETREGS (reg structure)");
19314 case NT_NETBSDCORE_FIRSTMACH
+ 3:
19315 return _("PT_GETFPREGS (fpreg structure)");
19321 snprintf (buff
, sizeof (buff
), "PT_FIRSTMACH+%d",
19322 e_type
- NT_NETBSDCORE_FIRSTMACH
);
19326 static const char *
19327 get_stapsdt_note_type (unsigned e_type
)
19329 static char buff
[64];
19334 return _("NT_STAPSDT (SystemTap probe descriptors)");
19340 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
19345 print_stapsdt_note (Elf_Internal_Note
*pnote
)
19347 size_t len
, maxlen
;
19348 unsigned long addr_size
= is_32bit_elf
? 4 : 8;
19349 char *data
= pnote
->descdata
;
19350 char *data_end
= pnote
->descdata
+ pnote
->descsz
;
19351 bfd_vma pc
, base_addr
, semaphore
;
19352 char *provider
, *probe
, *arg_fmt
;
19354 if (pnote
->descsz
< (addr_size
* 3))
19355 goto stapdt_note_too_small
;
19357 pc
= byte_get ((unsigned char *) data
, addr_size
);
19360 base_addr
= byte_get ((unsigned char *) data
, addr_size
);
19363 semaphore
= byte_get ((unsigned char *) data
, addr_size
);
19366 if (data
>= data_end
)
19367 goto stapdt_note_too_small
;
19368 maxlen
= data_end
- data
;
19369 len
= strnlen (data
, maxlen
);
19376 goto stapdt_note_too_small
;
19378 if (data
>= data_end
)
19379 goto stapdt_note_too_small
;
19380 maxlen
= data_end
- data
;
19381 len
= strnlen (data
, maxlen
);
19388 goto stapdt_note_too_small
;
19390 if (data
>= data_end
)
19391 goto stapdt_note_too_small
;
19392 maxlen
= data_end
- data
;
19393 len
= strnlen (data
, maxlen
);
19400 goto stapdt_note_too_small
;
19402 printf (_(" Provider: %s\n"), provider
);
19403 printf (_(" Name: %s\n"), probe
);
19404 printf (_(" Location: "));
19405 print_vma (pc
, FULL_HEX
);
19406 printf (_(", Base: "));
19407 print_vma (base_addr
, FULL_HEX
);
19408 printf (_(", Semaphore: "));
19409 print_vma (semaphore
, FULL_HEX
);
19411 printf (_(" Arguments: %s\n"), arg_fmt
);
19413 return data
== data_end
;
19415 stapdt_note_too_small
:
19416 printf (_(" <corrupt - note is too small>\n"));
19417 error (_("corrupt stapdt note - the data size is too small\n"));
19421 static const char *
19422 get_ia64_vms_note_type (unsigned e_type
)
19424 static char buff
[64];
19429 return _("NT_VMS_MHD (module header)");
19431 return _("NT_VMS_LNM (language name)");
19433 return _("NT_VMS_SRC (source files)");
19435 return "NT_VMS_TITLE";
19437 return _("NT_VMS_EIDC (consistency check)");
19438 case NT_VMS_FPMODE
:
19439 return _("NT_VMS_FPMODE (FP mode)");
19440 case NT_VMS_LINKTIME
:
19441 return "NT_VMS_LINKTIME";
19442 case NT_VMS_IMGNAM
:
19443 return _("NT_VMS_IMGNAM (image name)");
19445 return _("NT_VMS_IMGID (image id)");
19446 case NT_VMS_LINKID
:
19447 return _("NT_VMS_LINKID (link id)");
19448 case NT_VMS_IMGBID
:
19449 return _("NT_VMS_IMGBID (build id)");
19450 case NT_VMS_GSTNAM
:
19451 return _("NT_VMS_GSTNAM (sym table name)");
19452 case NT_VMS_ORIG_DYN
:
19453 return "NT_VMS_ORIG_DYN";
19454 case NT_VMS_PATCHTIME
:
19455 return "NT_VMS_PATCHTIME";
19457 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
19463 print_ia64_vms_note (Elf_Internal_Note
* pnote
)
19465 int maxlen
= pnote
->descsz
;
19467 if (maxlen
< 2 || (unsigned long) maxlen
!= pnote
->descsz
)
19468 goto desc_size_fail
;
19470 switch (pnote
->type
)
19474 goto desc_size_fail
;
19476 int l
= (int) strnlen (pnote
->descdata
+ 34, maxlen
- 34);
19478 printf (_(" Creation date : %.17s\n"), pnote
->descdata
);
19479 printf (_(" Last patch date: %.17s\n"), pnote
->descdata
+ 17);
19480 if (l
+ 34 < maxlen
)
19482 printf (_(" Module name : %s\n"), pnote
->descdata
+ 34);
19483 if (l
+ 35 < maxlen
)
19484 printf (_(" Module version : %s\n"), pnote
->descdata
+ 34 + l
+ 1);
19486 printf (_(" Module version : <missing>\n"));
19490 printf (_(" Module name : <missing>\n"));
19491 printf (_(" Module version : <missing>\n"));
19496 printf (_(" Language: %.*s\n"), maxlen
, pnote
->descdata
);
19500 case NT_VMS_FPMODE
:
19501 printf (_(" Floating Point mode: "));
19503 goto desc_size_fail
;
19504 /* FIXME: Generate an error if descsz > 8 ? */
19506 printf ("0x%016" BFD_VMA_FMT
"x\n",
19507 (bfd_vma
) byte_get ((unsigned char *)pnote
->descdata
, 8));
19510 case NT_VMS_LINKTIME
:
19511 printf (_(" Link time: "));
19513 goto desc_size_fail
;
19514 /* FIXME: Generate an error if descsz > 8 ? */
19517 ((bfd_int64_t
) byte_get ((unsigned char *)pnote
->descdata
, 8));
19521 case NT_VMS_PATCHTIME
:
19522 printf (_(" Patch time: "));
19524 goto desc_size_fail
;
19525 /* FIXME: Generate an error if descsz > 8 ? */
19528 ((bfd_int64_t
) byte_get ((unsigned char *)pnote
->descdata
, 8));
19532 case NT_VMS_ORIG_DYN
:
19534 goto desc_size_fail
;
19536 printf (_(" Major id: %u, minor id: %u\n"),
19537 (unsigned) byte_get ((unsigned char *)pnote
->descdata
, 4),
19538 (unsigned) byte_get ((unsigned char *)pnote
->descdata
+ 4, 4));
19539 printf (_(" Last modified : "));
19541 ((bfd_int64_t
) byte_get ((unsigned char *)pnote
->descdata
+ 8, 8));
19542 printf (_("\n Link flags : "));
19543 printf ("0x%016" BFD_VMA_FMT
"x\n",
19544 (bfd_vma
) byte_get ((unsigned char *)pnote
->descdata
+ 16, 8));
19545 printf (_(" Header flags: 0x%08x\n"),
19546 (unsigned) byte_get ((unsigned char *)pnote
->descdata
+ 24, 4));
19547 printf (_(" Image id : %.*s\n"), maxlen
- 32, pnote
->descdata
+ 32);
19551 case NT_VMS_IMGNAM
:
19552 printf (_(" Image name: %.*s\n"), maxlen
, pnote
->descdata
);
19555 case NT_VMS_GSTNAM
:
19556 printf (_(" Global symbol table name: %.*s\n"), maxlen
, pnote
->descdata
);
19560 printf (_(" Image id: %.*s\n"), maxlen
, pnote
->descdata
);
19563 case NT_VMS_LINKID
:
19564 printf (_(" Linker id: %.*s\n"), maxlen
, pnote
->descdata
);
19574 printf (_(" <corrupt - data size is too small>\n"));
19575 error (_("corrupt IA64 note: data size is too small\n"));
19579 struct build_attr_cache
{
19580 Filedata
*filedata
;
19582 unsigned long strtablen
;
19583 Elf_Internal_Sym
*symtab
;
19584 unsigned long nsyms
;
19587 /* Find the symbol associated with a build attribute that is attached
19588 to address OFFSET. If PNAME is non-NULL then store the name of
19589 the symbol (if found) in the provided pointer, Returns NULL if a
19590 symbol could not be found. */
19592 static Elf_Internal_Sym
*
19593 get_symbol_for_build_attribute (Filedata
* filedata
,
19594 unsigned long offset
,
19595 bfd_boolean is_open_attr
,
19596 const char ** pname
)
19598 Elf_Internal_Sym
*saved_sym
= NULL
;
19599 Elf_Internal_Sym
*sym
;
19601 if (filedata
->section_headers
!= NULL
19602 && (ba_cache
.filedata
== NULL
|| filedata
!= ba_cache
.filedata
))
19604 Elf_Internal_Shdr
* symsec
;
19606 free (ba_cache
.strtab
);
19607 ba_cache
.strtab
= NULL
;
19608 free (ba_cache
.symtab
);
19609 ba_cache
.symtab
= NULL
;
19611 /* Load the symbol and string sections. */
19612 for (symsec
= filedata
->section_headers
;
19613 symsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
19616 if (symsec
->sh_type
== SHT_SYMTAB
19617 && get_symtab (filedata
, symsec
,
19618 &ba_cache
.symtab
, &ba_cache
.nsyms
,
19619 &ba_cache
.strtab
, &ba_cache
.strtablen
))
19622 ba_cache
.filedata
= filedata
;
19625 if (ba_cache
.symtab
== NULL
)
19628 /* Find a symbol whose value matches offset. */
19629 for (sym
= ba_cache
.symtab
; sym
< ba_cache
.symtab
+ ba_cache
.nsyms
; sym
++)
19630 if (sym
->st_value
== offset
)
19632 if (sym
->st_name
>= ba_cache
.strtablen
)
19633 /* Huh ? This should not happen. */
19636 if (ba_cache
.strtab
[sym
->st_name
] == 0)
19639 /* The AArch64 and ARM architectures define mapping symbols
19640 (eg $d, $x, $t) which we want to ignore. */
19641 if (ba_cache
.strtab
[sym
->st_name
] == '$'
19642 && ba_cache
.strtab
[sym
->st_name
+ 1] != 0
19643 && ba_cache
.strtab
[sym
->st_name
+ 2] == 0)
19648 /* For OPEN attributes we prefer GLOBAL over LOCAL symbols
19649 and FILE or OBJECT symbols over NOTYPE symbols. We skip
19650 FUNC symbols entirely. */
19651 switch (ELF_ST_TYPE (sym
->st_info
))
19658 /* If the symbol has a size associated
19659 with it then we can stop searching. */
19660 sym
= ba_cache
.symtab
+ ba_cache
.nsyms
;
19665 /* Ignore function symbols. */
19672 switch (ELF_ST_BIND (sym
->st_info
))
19675 if (saved_sym
== NULL
19676 || ELF_ST_TYPE (saved_sym
->st_info
) != STT_OBJECT
)
19681 if (saved_sym
== NULL
)
19691 if (ELF_ST_TYPE (sym
->st_info
) != STT_FUNC
)
19699 if (saved_sym
&& pname
)
19700 * pname
= ba_cache
.strtab
+ saved_sym
->st_name
;
19705 /* Returns true iff addr1 and addr2 are in the same section. */
19708 same_section (Filedata
* filedata
, unsigned long addr1
, unsigned long addr2
)
19710 Elf_Internal_Shdr
* a1
;
19711 Elf_Internal_Shdr
* a2
;
19713 a1
= find_section_by_address (filedata
, addr1
);
19714 a2
= find_section_by_address (filedata
, addr2
);
19716 return a1
== a2
&& a1
!= NULL
;
19720 print_gnu_build_attribute_description (Elf_Internal_Note
* pnote
,
19721 Filedata
* filedata
)
19723 static unsigned long global_offset
= 0;
19724 static unsigned long global_end
= 0;
19725 static unsigned long func_offset
= 0;
19726 static unsigned long func_end
= 0;
19728 Elf_Internal_Sym
* sym
;
19730 unsigned long start
;
19732 bfd_boolean is_open_attr
= pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_OPEN
;
19734 switch (pnote
->descsz
)
19737 /* A zero-length description means that the range of
19738 the previous note of the same type should be used. */
19741 if (global_end
> global_offset
)
19742 printf (_(" Applies to region from %#lx to %#lx\n"),
19743 global_offset
, global_end
);
19745 printf (_(" Applies to region from %#lx\n"), global_offset
);
19749 if (func_end
> func_offset
)
19750 printf (_(" Applies to region from %#lx to %#lx\n"), func_offset
, func_end
);
19752 printf (_(" Applies to region from %#lx\n"), func_offset
);
19757 start
= byte_get ((unsigned char *) pnote
->descdata
, 4);
19764 /* FIXME: We should check that version 3+ notes are being used here... */
19765 start
= byte_get ((unsigned char *) pnote
->descdata
, 4);
19766 end
= byte_get ((unsigned char *) pnote
->descdata
+ 4, 4);
19770 start
= byte_get ((unsigned char *) pnote
->descdata
, 8);
19776 start
= byte_get ((unsigned char *) pnote
->descdata
, 8);
19777 end
= byte_get ((unsigned char *) pnote
->descdata
+ 8, 8);
19781 error (_(" <invalid description size: %lx>\n"), pnote
->descsz
);
19782 printf (_(" <invalid descsz>"));
19787 sym
= get_symbol_for_build_attribute (filedata
, start
, is_open_attr
, & name
);
19788 /* As of version 5 of the annobin plugin, filename symbols are biased by 2
19789 in order to avoid them being confused with the start address of the
19790 first function in the file... */
19791 if (sym
== NULL
&& is_open_attr
)
19792 sym
= get_symbol_for_build_attribute (filedata
, start
+ 2, is_open_attr
,
19795 if (end
== 0 && sym
!= NULL
&& sym
->st_size
> 0)
19796 end
= start
+ sym
->st_size
;
19800 /* FIXME: Need to properly allow for section alignment.
19801 16 is just the alignment used on x86_64. */
19803 && start
> BFD_ALIGN (global_end
, 16)
19804 /* Build notes are not guaranteed to be organised in order of
19805 increasing address, but we should find the all of the notes
19806 for one section in the same place. */
19807 && same_section (filedata
, start
, global_end
))
19808 warn (_("Gap in build notes detected from %#lx to %#lx\n"),
19809 global_end
+ 1, start
- 1);
19811 printf (_(" Applies to region from %#lx"), start
);
19812 global_offset
= start
;
19816 printf (_(" to %#lx"), end
);
19822 printf (_(" Applies to region from %#lx"), start
);
19823 func_offset
= start
;
19827 printf (_(" to %#lx"), end
);
19833 printf (_(" (%s)"), name
);
19840 print_gnu_build_attribute_name (Elf_Internal_Note
* pnote
)
19842 static const char string_expected
[2] = { GNU_BUILD_ATTRIBUTE_TYPE_STRING
, 0 };
19843 static const char number_expected
[2] = { GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC
, 0 };
19844 static const char bool_expected
[3] = { GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE
, GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE
, 0 };
19846 char name_attribute
;
19847 const char * expected_types
;
19848 const char * name
= pnote
->namedata
;
19852 if (name
== NULL
|| pnote
->namesz
< 2)
19854 error (_("corrupt name field in GNU build attribute note: size = %ld\n"), pnote
->namesz
);
19855 print_symbol (-20, _(" <corrupt name>"));
19864 /* Version 2 of the spec adds a "GA" prefix to the name field. */
19865 if (name
[0] == 'G' && name
[1] == 'A')
19867 if (pnote
->namesz
< 4)
19869 error (_("corrupt name field in GNU build attribute note: size = %ld\n"), pnote
->namesz
);
19870 print_symbol (-20, _(" <corrupt name>"));
19879 switch ((name_type
= * name
))
19881 case GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC
:
19882 case GNU_BUILD_ATTRIBUTE_TYPE_STRING
:
19883 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE
:
19884 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE
:
19885 printf ("%c", * name
);
19889 error (_("unrecognised attribute type in name field: %d\n"), name_type
);
19890 print_symbol (-20, _("<unknown name type>"));
19897 switch ((name_attribute
= * name
))
19899 case GNU_BUILD_ATTRIBUTE_VERSION
:
19900 text
= _("<version>");
19901 expected_types
= string_expected
;
19904 case GNU_BUILD_ATTRIBUTE_STACK_PROT
:
19905 text
= _("<stack prot>");
19906 expected_types
= "!+*";
19909 case GNU_BUILD_ATTRIBUTE_RELRO
:
19910 text
= _("<relro>");
19911 expected_types
= bool_expected
;
19914 case GNU_BUILD_ATTRIBUTE_STACK_SIZE
:
19915 text
= _("<stack size>");
19916 expected_types
= number_expected
;
19919 case GNU_BUILD_ATTRIBUTE_TOOL
:
19920 text
= _("<tool>");
19921 expected_types
= string_expected
;
19924 case GNU_BUILD_ATTRIBUTE_ABI
:
19926 expected_types
= "$*";
19929 case GNU_BUILD_ATTRIBUTE_PIC
:
19931 expected_types
= number_expected
;
19934 case GNU_BUILD_ATTRIBUTE_SHORT_ENUM
:
19935 text
= _("<short enum>");
19936 expected_types
= bool_expected
;
19940 if (ISPRINT (* name
))
19942 int len
= strnlen (name
, pnote
->namesz
- (name
- pnote
->namedata
)) + 1;
19944 if (len
> left
&& ! do_wide
)
19946 printf ("%.*s:", len
, name
);
19952 static char tmpbuf
[128];
19954 error (_("unrecognised byte in name field: %d\n"), * name
);
19955 sprintf (tmpbuf
, _("<unknown:_%d>"), * name
);
19959 expected_types
= "*$!+";
19964 left
-= printf ("%s", text
);
19966 if (strchr (expected_types
, name_type
) == NULL
)
19967 warn (_("attribute does not have an expected type (%c)\n"), name_type
);
19969 if ((unsigned long)(name
- pnote
->namedata
) > pnote
->namesz
)
19971 error (_("corrupt name field: namesz: %lu but parsing gets to %ld\n"),
19972 (unsigned long) pnote
->namesz
,
19973 (long) (name
- pnote
->namedata
));
19977 if (left
< 1 && ! do_wide
)
19982 case GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC
:
19984 unsigned int bytes
;
19985 unsigned long long val
= 0;
19986 unsigned int shift
= 0;
19987 char * decoded
= NULL
;
19989 bytes
= pnote
->namesz
- (name
- pnote
->namedata
);
19991 /* The -1 is because the name field is always 0 terminated, and we
19992 want to be able to ensure that the shift in the while loop below
19993 will not overflow. */
19996 if (bytes
> sizeof (val
))
19998 error (_("corrupt numeric name field: too many bytes in the value: %x\n"),
20000 bytes
= sizeof (val
);
20002 /* We do not bother to warn if bytes == 0 as this can
20003 happen with some early versions of the gcc plugin. */
20007 unsigned long long byte
= *name
++ & 0xff;
20009 val
|= byte
<< shift
;
20013 switch (name_attribute
)
20015 case GNU_BUILD_ATTRIBUTE_PIC
:
20018 case 0: decoded
= "static"; break;
20019 case 1: decoded
= "pic"; break;
20020 case 2: decoded
= "PIC"; break;
20021 case 3: decoded
= "pie"; break;
20022 case 4: decoded
= "PIE"; break;
20026 case GNU_BUILD_ATTRIBUTE_STACK_PROT
:
20029 /* Based upon the SPCT_FLAG_xxx enum values in gcc/cfgexpand.c. */
20030 case 0: decoded
= "off"; break;
20031 case 1: decoded
= "on"; break;
20032 case 2: decoded
= "all"; break;
20033 case 3: decoded
= "strong"; break;
20034 case 4: decoded
= "explicit"; break;
20042 if (decoded
!= NULL
)
20044 print_symbol (-left
, decoded
);
20055 left
-= printf ("0x%llx", val
);
20057 left
-= printf ("0x%-.*llx", left
, val
);
20061 case GNU_BUILD_ATTRIBUTE_TYPE_STRING
:
20062 left
-= print_symbol (- left
, name
);
20064 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE
:
20065 left
-= print_symbol (- left
, "true");
20067 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE
:
20068 left
-= print_symbol (- left
, "false");
20072 if (do_wide
&& left
> 0)
20073 printf ("%-*s", left
, " ");
20078 /* Note that by the ELF standard, the name field is already null byte
20079 terminated, and namesz includes the terminating null byte.
20080 I.E. the value of namesz for the name "FSF" is 4.
20082 If the value of namesz is zero, there is no name present. */
20085 process_note (Elf_Internal_Note
* pnote
,
20086 Filedata
* filedata
)
20088 const char * name
= pnote
->namesz
? pnote
->namedata
: "(NONE)";
20091 if (pnote
->namesz
== 0)
20092 /* If there is no note name, then use the default set of
20093 note type strings. */
20094 nt
= get_note_type (filedata
, pnote
->type
);
20096 else if (const_strneq (pnote
->namedata
, "GNU"))
20097 /* GNU-specific object file notes. */
20098 nt
= get_gnu_elf_note_type (pnote
->type
);
20100 else if (const_strneq (pnote
->namedata
, "FreeBSD"))
20101 /* FreeBSD-specific core file notes. */
20102 nt
= get_freebsd_elfcore_note_type (filedata
, pnote
->type
);
20104 else if (const_strneq (pnote
->namedata
, "NetBSD-CORE"))
20105 /* NetBSD-specific core file notes. */
20106 nt
= get_netbsd_elfcore_note_type (filedata
, pnote
->type
);
20108 else if (const_strneq (pnote
->namedata
, "NetBSD"))
20109 /* NetBSD-specific core file notes. */
20110 return process_netbsd_elf_note (pnote
);
20112 else if (const_strneq (pnote
->namedata
, "PaX"))
20113 /* NetBSD-specific core file notes. */
20114 return process_netbsd_elf_note (pnote
);
20116 else if (strneq (pnote
->namedata
, "SPU/", 4))
20118 /* SPU-specific core file notes. */
20119 nt
= pnote
->namedata
+ 4;
20123 else if (const_strneq (pnote
->namedata
, "IPF/VMS"))
20124 /* VMS/ia64-specific file notes. */
20125 nt
= get_ia64_vms_note_type (pnote
->type
);
20127 else if (const_strneq (pnote
->namedata
, "stapsdt"))
20128 nt
= get_stapsdt_note_type (pnote
->type
);
20131 /* Don't recognize this note name; just use the default set of
20132 note type strings. */
20133 nt
= get_note_type (filedata
, pnote
->type
);
20137 if (((const_strneq (pnote
->namedata
, "GA")
20138 && strchr ("*$!+", pnote
->namedata
[2]) != NULL
)
20139 || strchr ("*$!+", pnote
->namedata
[0]) != NULL
)
20140 && (pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_OPEN
20141 || pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_FUNC
))
20142 print_gnu_build_attribute_name (pnote
);
20144 print_symbol (-20, name
);
20147 printf (" 0x%08lx\t%s\t", pnote
->descsz
, nt
);
20149 printf (" 0x%08lx\t%s\n", pnote
->descsz
, nt
);
20151 if (const_strneq (pnote
->namedata
, "IPF/VMS"))
20152 return print_ia64_vms_note (pnote
);
20153 else if (const_strneq (pnote
->namedata
, "GNU"))
20154 return print_gnu_note (filedata
, pnote
);
20155 else if (const_strneq (pnote
->namedata
, "stapsdt"))
20156 return print_stapsdt_note (pnote
);
20157 else if (const_strneq (pnote
->namedata
, "CORE"))
20158 return print_core_note (pnote
);
20159 else if (((const_strneq (pnote
->namedata
, "GA")
20160 && strchr ("*$!+", pnote
->namedata
[2]) != NULL
)
20161 || strchr ("*$!+", pnote
->namedata
[0]) != NULL
)
20162 && (pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_OPEN
20163 || pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_FUNC
))
20164 return print_gnu_build_attribute_description (pnote
, filedata
);
20170 printf (_(" description data: "));
20171 for (i
= 0; i
< pnote
->descsz
; i
++)
20172 printf ("%02x ", pnote
->descdata
[i
] & 0xff);
20184 process_notes_at (Filedata
* filedata
,
20185 Elf_Internal_Shdr
* section
,
20190 Elf_External_Note
* pnotes
;
20191 Elf_External_Note
* external
;
20193 bfd_boolean res
= TRUE
;
20200 pnotes
= (Elf_External_Note
*) get_section_contents (section
, filedata
);
20203 if (! apply_relocations (filedata
, section
, (unsigned char *) pnotes
, length
, NULL
, NULL
))
20211 pnotes
= (Elf_External_Note
*) get_data (NULL
, filedata
, offset
, 1, length
,
20214 if (pnotes
== NULL
)
20220 printf (_("\nDisplaying notes found in: %s\n"), printable_section_name (filedata
, section
));
20222 printf (_("\nDisplaying notes found at file offset 0x%08lx with length 0x%08lx:\n"),
20223 (unsigned long) offset
, (unsigned long) length
);
20225 /* NB: Some note sections may have alignment value of 0 or 1. gABI
20226 specifies that notes should be aligned to 4 bytes in 32-bit
20227 objects and to 8 bytes in 64-bit objects. As a Linux extension,
20228 we also support 4 byte alignment in 64-bit objects. If section
20229 alignment is less than 4, we treate alignment as 4 bytes. */
20232 else if (align
!= 4 && align
!= 8)
20234 warn (_("Corrupt note: alignment %ld, expecting 4 or 8\n"),
20240 printf (_(" %-20s %-10s\tDescription\n"), _("Owner"), _("Data size"));
20242 end
= (char *) pnotes
+ length
;
20243 while ((char *) external
< end
)
20245 Elf_Internal_Note inote
;
20248 char * temp
= NULL
;
20249 size_t data_remaining
= end
- (char *) external
;
20251 if (!is_ia64_vms (filedata
))
20253 /* PR binutils/15191
20254 Make sure that there is enough data to read. */
20255 min_notesz
= offsetof (Elf_External_Note
, name
);
20256 if (data_remaining
< min_notesz
)
20258 warn (ngettext ("Corrupt note: only %ld byte remains, "
20259 "not enough for a full note\n",
20260 "Corrupt note: only %ld bytes remain, "
20261 "not enough for a full note\n",
20263 (long) data_remaining
);
20266 data_remaining
-= min_notesz
;
20268 inote
.type
= BYTE_GET (external
->type
);
20269 inote
.namesz
= BYTE_GET (external
->namesz
);
20270 inote
.namedata
= external
->name
;
20271 inote
.descsz
= BYTE_GET (external
->descsz
);
20272 inote
.descdata
= ((char *) external
20273 + ELF_NOTE_DESC_OFFSET (inote
.namesz
, align
));
20274 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
20275 next
= ((char *) external
20276 + ELF_NOTE_NEXT_OFFSET (inote
.namesz
, inote
.descsz
, align
));
20280 Elf64_External_VMS_Note
*vms_external
;
20282 /* PR binutils/15191
20283 Make sure that there is enough data to read. */
20284 min_notesz
= offsetof (Elf64_External_VMS_Note
, name
);
20285 if (data_remaining
< min_notesz
)
20287 warn (ngettext ("Corrupt note: only %ld byte remains, "
20288 "not enough for a full note\n",
20289 "Corrupt note: only %ld bytes remain, "
20290 "not enough for a full note\n",
20292 (long) data_remaining
);
20295 data_remaining
-= min_notesz
;
20297 vms_external
= (Elf64_External_VMS_Note
*) external
;
20298 inote
.type
= BYTE_GET (vms_external
->type
);
20299 inote
.namesz
= BYTE_GET (vms_external
->namesz
);
20300 inote
.namedata
= vms_external
->name
;
20301 inote
.descsz
= BYTE_GET (vms_external
->descsz
);
20302 inote
.descdata
= inote
.namedata
+ align_power (inote
.namesz
, 3);
20303 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
20304 next
= inote
.descdata
+ align_power (inote
.descsz
, 3);
20307 /* PR 17531: file: 3443835e. */
20308 /* PR 17531: file: id:000000,sig:11,src:006986,op:havoc,rep:4. */
20309 if ((size_t) (inote
.descdata
- inote
.namedata
) < inote
.namesz
20310 || (size_t) (inote
.descdata
- inote
.namedata
) > data_remaining
20311 || (size_t) (next
- inote
.descdata
) < inote
.descsz
20312 || ((size_t) (next
- inote
.descdata
)
20313 > data_remaining
- (size_t) (inote
.descdata
- inote
.namedata
)))
20315 warn (_("note with invalid namesz and/or descsz found at offset 0x%lx\n"),
20316 (unsigned long) ((char *) external
- (char *) pnotes
));
20317 warn (_(" type: 0x%lx, namesize: 0x%08lx, descsize: 0x%08lx, alignment: %u\n"),
20318 inote
.type
, inote
.namesz
, inote
.descsz
, (int) align
);
20322 external
= (Elf_External_Note
*) next
;
20324 /* Verify that name is null terminated. It appears that at least
20325 one version of Linux (RedHat 6.0) generates corefiles that don't
20326 comply with the ELF spec by failing to include the null byte in
20328 if (inote
.namesz
> 0 && inote
.namedata
[inote
.namesz
- 1] != '\0')
20330 if ((size_t) (inote
.descdata
- inote
.namedata
) == inote
.namesz
)
20332 temp
= (char *) malloc (inote
.namesz
+ 1);
20335 error (_("Out of memory allocating space for inote name\n"));
20340 memcpy (temp
, inote
.namedata
, inote
.namesz
);
20341 inote
.namedata
= temp
;
20343 inote
.namedata
[inote
.namesz
] = 0;
20346 if (! process_note (& inote
, filedata
))
20359 process_corefile_note_segments (Filedata
* filedata
)
20361 Elf_Internal_Phdr
* segment
;
20363 bfd_boolean res
= TRUE
;
20365 if (! get_program_headers (filedata
))
20368 for (i
= 0, segment
= filedata
->program_headers
;
20369 i
< filedata
->file_header
.e_phnum
;
20372 if (segment
->p_type
== PT_NOTE
)
20373 if (! process_notes_at (filedata
, NULL
,
20374 (bfd_vma
) segment
->p_offset
,
20375 (bfd_vma
) segment
->p_filesz
,
20376 (bfd_vma
) segment
->p_align
))
20384 process_v850_notes (Filedata
* filedata
, bfd_vma offset
, bfd_vma length
)
20386 Elf_External_Note
* pnotes
;
20387 Elf_External_Note
* external
;
20389 bfd_boolean res
= TRUE
;
20394 pnotes
= (Elf_External_Note
*) get_data (NULL
, filedata
, offset
, 1, length
,
20396 if (pnotes
== NULL
)
20400 end
= (char*) pnotes
+ length
;
20402 printf (_("\nDisplaying contents of Renesas V850 notes section at offset 0x%lx with length 0x%lx:\n"),
20403 (unsigned long) offset
, (unsigned long) length
);
20405 while ((char *) external
+ sizeof (Elf_External_Note
) < end
)
20407 Elf_External_Note
* next
;
20408 Elf_Internal_Note inote
;
20410 inote
.type
= BYTE_GET (external
->type
);
20411 inote
.namesz
= BYTE_GET (external
->namesz
);
20412 inote
.namedata
= external
->name
;
20413 inote
.descsz
= BYTE_GET (external
->descsz
);
20414 inote
.descdata
= inote
.namedata
+ align_power (inote
.namesz
, 2);
20415 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
20417 if (inote
.descdata
< (char *) pnotes
|| inote
.descdata
>= end
)
20419 warn (_("Corrupt note: name size is too big: %lx\n"), inote
.namesz
);
20420 inote
.descdata
= inote
.namedata
;
20424 next
= (Elf_External_Note
*) (inote
.descdata
+ align_power (inote
.descsz
, 2));
20426 if ( ((char *) next
> end
)
20427 || ((char *) next
< (char *) pnotes
))
20429 warn (_("corrupt descsz found in note at offset 0x%lx\n"),
20430 (unsigned long) ((char *) external
- (char *) pnotes
));
20431 warn (_(" type: 0x%lx, namesize: 0x%lx, descsize: 0x%lx\n"),
20432 inote
.type
, inote
.namesz
, inote
.descsz
);
20438 /* Prevent out-of-bounds indexing. */
20439 if ( inote
.namedata
+ inote
.namesz
> end
20440 || inote
.namedata
+ inote
.namesz
< inote
.namedata
)
20442 warn (_("corrupt namesz found in note at offset 0x%lx\n"),
20443 (unsigned long) ((char *) external
- (char *) pnotes
));
20444 warn (_(" type: 0x%lx, namesize: 0x%lx, descsize: 0x%lx\n"),
20445 inote
.type
, inote
.namesz
, inote
.descsz
);
20449 printf (" %s: ", get_v850_elf_note_type (inote
.type
));
20451 if (! print_v850_note (& inote
))
20454 printf ("<corrupt sizes: namesz: %lx, descsz: %lx>\n",
20455 inote
.namesz
, inote
.descsz
);
20465 process_note_sections (Filedata
* filedata
)
20467 Elf_Internal_Shdr
* section
;
20469 unsigned int n
= 0;
20470 bfd_boolean res
= TRUE
;
20472 for (i
= 0, section
= filedata
->section_headers
;
20473 i
< filedata
->file_header
.e_shnum
&& section
!= NULL
;
20476 if (section
->sh_type
== SHT_NOTE
)
20478 if (! process_notes_at (filedata
, section
,
20479 (bfd_vma
) section
->sh_offset
,
20480 (bfd_vma
) section
->sh_size
,
20481 (bfd_vma
) section
->sh_addralign
))
20486 if (( filedata
->file_header
.e_machine
== EM_V800
20487 || filedata
->file_header
.e_machine
== EM_V850
20488 || filedata
->file_header
.e_machine
== EM_CYGNUS_V850
)
20489 && section
->sh_type
== SHT_RENESAS_INFO
)
20491 if (! process_v850_notes (filedata
,
20492 (bfd_vma
) section
->sh_offset
,
20493 (bfd_vma
) section
->sh_size
))
20500 /* Try processing NOTE segments instead. */
20501 return process_corefile_note_segments (filedata
);
20507 process_notes (Filedata
* filedata
)
20509 /* If we have not been asked to display the notes then do nothing. */
20513 if (filedata
->file_header
.e_type
!= ET_CORE
)
20514 return process_note_sections (filedata
);
20516 /* No program headers means no NOTE segment. */
20517 if (filedata
->file_header
.e_phnum
> 0)
20518 return process_corefile_note_segments (filedata
);
20520 printf (_("No note segments present in the core file.\n"));
20524 static unsigned char *
20525 display_public_gnu_attributes (unsigned char * start
,
20526 const unsigned char * const end
)
20528 printf (_(" Unknown GNU attribute: %s\n"), start
);
20530 start
+= strnlen ((char *) start
, end
- start
);
20531 display_raw_attribute (start
, end
);
20533 return (unsigned char *) end
;
20536 static unsigned char *
20537 display_generic_attribute (unsigned char * start
,
20539 const unsigned char * const end
)
20542 return (unsigned char *) end
;
20544 return display_tag_value (tag
, start
, end
);
20548 process_arch_specific (Filedata
* filedata
)
20553 switch (filedata
->file_header
.e_machine
)
20556 case EM_ARC_COMPACT
:
20557 case EM_ARC_COMPACT2
:
20558 return process_attributes (filedata
, "ARC", SHT_ARC_ATTRIBUTES
,
20559 display_arc_attribute
,
20560 display_generic_attribute
);
20562 return process_attributes (filedata
, "aeabi", SHT_ARM_ATTRIBUTES
,
20563 display_arm_attribute
,
20564 display_generic_attribute
);
20567 case EM_MIPS_RS3_LE
:
20568 return process_mips_specific (filedata
);
20571 return process_attributes (filedata
, "mspabi", SHT_MSP430_ATTRIBUTES
,
20572 display_msp430_attribute
,
20573 display_msp430_gnu_attribute
);
20576 return process_attributes (filedata
, "riscv", SHT_RISCV_ATTRIBUTES
,
20577 display_riscv_attribute
,
20578 display_generic_attribute
);
20581 return process_nds32_specific (filedata
);
20584 return process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
20585 display_m68k_gnu_attribute
);
20589 return process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
20590 display_power_gnu_attribute
);
20594 return process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
20595 display_s390_gnu_attribute
);
20598 case EM_SPARC32PLUS
:
20600 return process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
20601 display_sparc_gnu_attribute
);
20604 return process_attributes (filedata
, "c6xabi", SHT_C6000_ATTRIBUTES
,
20605 display_tic6x_attribute
,
20606 display_generic_attribute
);
20609 return process_attributes (filedata
, "csky", SHT_CSKY_ATTRIBUTES
,
20610 display_csky_attribute
, NULL
);
20613 return process_attributes (filedata
, "gnu", SHT_GNU_ATTRIBUTES
,
20614 display_public_gnu_attributes
,
20615 display_generic_attribute
);
20620 get_file_header (Filedata
* filedata
)
20622 /* Read in the identity array. */
20623 if (fread (filedata
->file_header
.e_ident
, EI_NIDENT
, 1, filedata
->handle
) != 1)
20626 /* Determine how to read the rest of the header. */
20627 switch (filedata
->file_header
.e_ident
[EI_DATA
])
20632 byte_get
= byte_get_little_endian
;
20633 byte_put
= byte_put_little_endian
;
20636 byte_get
= byte_get_big_endian
;
20637 byte_put
= byte_put_big_endian
;
20641 /* For now we only support 32 bit and 64 bit ELF files. */
20642 is_32bit_elf
= (filedata
->file_header
.e_ident
[EI_CLASS
] != ELFCLASS64
);
20644 /* Read in the rest of the header. */
20647 Elf32_External_Ehdr ehdr32
;
20649 if (fread (ehdr32
.e_type
, sizeof (ehdr32
) - EI_NIDENT
, 1, filedata
->handle
) != 1)
20652 filedata
->file_header
.e_type
= BYTE_GET (ehdr32
.e_type
);
20653 filedata
->file_header
.e_machine
= BYTE_GET (ehdr32
.e_machine
);
20654 filedata
->file_header
.e_version
= BYTE_GET (ehdr32
.e_version
);
20655 filedata
->file_header
.e_entry
= BYTE_GET (ehdr32
.e_entry
);
20656 filedata
->file_header
.e_phoff
= BYTE_GET (ehdr32
.e_phoff
);
20657 filedata
->file_header
.e_shoff
= BYTE_GET (ehdr32
.e_shoff
);
20658 filedata
->file_header
.e_flags
= BYTE_GET (ehdr32
.e_flags
);
20659 filedata
->file_header
.e_ehsize
= BYTE_GET (ehdr32
.e_ehsize
);
20660 filedata
->file_header
.e_phentsize
= BYTE_GET (ehdr32
.e_phentsize
);
20661 filedata
->file_header
.e_phnum
= BYTE_GET (ehdr32
.e_phnum
);
20662 filedata
->file_header
.e_shentsize
= BYTE_GET (ehdr32
.e_shentsize
);
20663 filedata
->file_header
.e_shnum
= BYTE_GET (ehdr32
.e_shnum
);
20664 filedata
->file_header
.e_shstrndx
= BYTE_GET (ehdr32
.e_shstrndx
);
20668 Elf64_External_Ehdr ehdr64
;
20670 /* If we have been compiled with sizeof (bfd_vma) == 4, then
20671 we will not be able to cope with the 64bit data found in
20672 64 ELF files. Detect this now and abort before we start
20673 overwriting things. */
20674 if (sizeof (bfd_vma
) < 8)
20676 error (_("This instance of readelf has been built without support for a\n\
20677 64 bit data type and so it cannot read 64 bit ELF files.\n"));
20681 if (fread (ehdr64
.e_type
, sizeof (ehdr64
) - EI_NIDENT
, 1, filedata
->handle
) != 1)
20684 filedata
->file_header
.e_type
= BYTE_GET (ehdr64
.e_type
);
20685 filedata
->file_header
.e_machine
= BYTE_GET (ehdr64
.e_machine
);
20686 filedata
->file_header
.e_version
= BYTE_GET (ehdr64
.e_version
);
20687 filedata
->file_header
.e_entry
= BYTE_GET (ehdr64
.e_entry
);
20688 filedata
->file_header
.e_phoff
= BYTE_GET (ehdr64
.e_phoff
);
20689 filedata
->file_header
.e_shoff
= BYTE_GET (ehdr64
.e_shoff
);
20690 filedata
->file_header
.e_flags
= BYTE_GET (ehdr64
.e_flags
);
20691 filedata
->file_header
.e_ehsize
= BYTE_GET (ehdr64
.e_ehsize
);
20692 filedata
->file_header
.e_phentsize
= BYTE_GET (ehdr64
.e_phentsize
);
20693 filedata
->file_header
.e_phnum
= BYTE_GET (ehdr64
.e_phnum
);
20694 filedata
->file_header
.e_shentsize
= BYTE_GET (ehdr64
.e_shentsize
);
20695 filedata
->file_header
.e_shnum
= BYTE_GET (ehdr64
.e_shnum
);
20696 filedata
->file_header
.e_shstrndx
= BYTE_GET (ehdr64
.e_shstrndx
);
20699 if (filedata
->file_header
.e_shoff
)
20701 /* There may be some extensions in the first section header. Don't
20702 bomb if we can't read it. */
20704 get_32bit_section_headers (filedata
, TRUE
);
20706 get_64bit_section_headers (filedata
, TRUE
);
20713 close_file (Filedata
* filedata
)
20717 if (filedata
->handle
)
20718 fclose (filedata
->handle
);
20724 close_debug_file (void * data
)
20726 close_file ((Filedata
*) data
);
20730 open_file (const char * pathname
)
20732 struct stat statbuf
;
20733 Filedata
* filedata
= NULL
;
20735 if (stat (pathname
, & statbuf
) < 0
20736 || ! S_ISREG (statbuf
.st_mode
))
20739 filedata
= calloc (1, sizeof * filedata
);
20740 if (filedata
== NULL
)
20743 filedata
->handle
= fopen (pathname
, "rb");
20744 if (filedata
->handle
== NULL
)
20747 filedata
->file_size
= (bfd_size_type
) statbuf
.st_size
;
20748 filedata
->file_name
= pathname
;
20750 if (! get_file_header (filedata
))
20753 if (filedata
->file_header
.e_shoff
)
20757 /* Read the section headers again, this time for real. */
20759 res
= get_32bit_section_headers (filedata
, FALSE
);
20761 res
= get_64bit_section_headers (filedata
, FALSE
);
20772 if (filedata
->handle
)
20773 fclose (filedata
->handle
);
20780 open_debug_file (const char * pathname
)
20782 return open_file (pathname
);
20785 /* Process one ELF object file according to the command line options.
20786 This file may actually be stored in an archive. The file is
20787 positioned at the start of the ELF object. Returns TRUE if no
20788 problems were encountered, FALSE otherwise. */
20791 process_object (Filedata
* filedata
)
20793 bfd_boolean have_separate_files
;
20797 if (! get_file_header (filedata
))
20799 error (_("%s: Failed to read file header\n"), filedata
->file_name
);
20803 /* Initialise per file variables. */
20804 for (i
= ARRAY_SIZE (filedata
->version_info
); i
--;)
20805 filedata
->version_info
[i
] = 0;
20807 for (i
= ARRAY_SIZE (filedata
->dynamic_info
); i
--;)
20808 filedata
->dynamic_info
[i
] = 0;
20809 filedata
->dynamic_info_DT_GNU_HASH
= 0;
20810 filedata
->dynamic_info_DT_MIPS_XHASH
= 0;
20812 /* Process the file. */
20814 printf (_("\nFile: %s\n"), filedata
->file_name
);
20816 /* Initialise the dump_sects array from the cmdline_dump_sects array.
20817 Note we do this even if cmdline_dump_sects is empty because we
20818 must make sure that the dump_sets array is zeroed out before each
20819 object file is processed. */
20820 if (filedata
->dump
.num_dump_sects
> cmdline
.num_dump_sects
)
20821 memset (filedata
->dump
.dump_sects
, 0,
20822 filedata
->dump
.num_dump_sects
* sizeof (*filedata
->dump
.dump_sects
));
20824 if (cmdline
.num_dump_sects
> 0)
20826 if (filedata
->dump
.num_dump_sects
== 0)
20827 /* A sneaky way of allocating the dump_sects array. */
20828 request_dump_bynumber (&filedata
->dump
, cmdline
.num_dump_sects
, 0);
20830 assert (filedata
->dump
.num_dump_sects
>= cmdline
.num_dump_sects
);
20831 memcpy (filedata
->dump
.dump_sects
, cmdline
.dump_sects
,
20832 cmdline
.num_dump_sects
* sizeof (*filedata
->dump
.dump_sects
));
20835 if (! process_file_header (filedata
))
20838 if (! process_section_headers (filedata
))
20840 /* Without loaded section headers we cannot process lots of things. */
20841 do_unwind
= do_version
= do_dump
= do_arch
= FALSE
;
20843 if (! do_using_dynamic
)
20844 do_syms
= do_dyn_syms
= do_reloc
= FALSE
;
20847 if (! process_section_groups (filedata
))
20848 /* Without loaded section groups we cannot process unwind. */
20851 res
= process_program_headers (filedata
);
20853 res
= process_dynamic_section (filedata
);
20855 if (! process_relocs (filedata
))
20858 if (! process_unwind (filedata
))
20861 if (! process_symbol_table (filedata
))
20864 if (! process_lto_symbol_tables (filedata
))
20867 if (! process_syminfo (filedata
))
20870 if (! process_version_sections (filedata
))
20873 if (filedata
->file_header
.e_shstrndx
!= SHN_UNDEF
)
20874 have_separate_files
= load_separate_debug_files (filedata
, filedata
->file_name
);
20876 have_separate_files
= FALSE
;
20878 if (! process_section_contents (filedata
))
20881 if (have_separate_files
)
20885 for (d
= first_separate_info
; d
!= NULL
; d
= d
->next
)
20887 if (! process_section_headers (d
->handle
))
20889 else if (! process_section_contents (d
->handle
))
20893 /* The file handles are closed by the call to free_debug_memory() below. */
20896 if (! process_notes (filedata
))
20899 if (! process_gnu_liblist (filedata
))
20902 if (! process_arch_specific (filedata
))
20905 free (filedata
->program_headers
);
20906 filedata
->program_headers
= NULL
;
20908 free (filedata
->section_headers
);
20909 filedata
->section_headers
= NULL
;
20911 free (filedata
->string_table
);
20912 filedata
->string_table
= NULL
;
20913 filedata
->string_table_length
= 0;
20915 free (filedata
->dump
.dump_sects
);
20916 filedata
->dump
.dump_sects
= NULL
;
20917 filedata
->dump
.num_dump_sects
= 0;
20919 free (filedata
->dynamic_strings
);
20920 filedata
->dynamic_strings
= NULL
;
20921 filedata
->dynamic_strings_length
= 0;
20923 free (filedata
->dynamic_symbols
);
20924 filedata
->dynamic_symbols
= NULL
;
20925 filedata
->num_dynamic_syms
= 0;
20927 free (filedata
->dynamic_syminfo
);
20928 filedata
->dynamic_syminfo
= NULL
;
20930 free (filedata
->dynamic_section
);
20931 filedata
->dynamic_section
= NULL
;
20933 while (filedata
->symtab_shndx_list
!= NULL
)
20935 elf_section_list
*next
= filedata
->symtab_shndx_list
->next
;
20936 free (filedata
->symtab_shndx_list
);
20937 filedata
->symtab_shndx_list
= next
;
20940 free (filedata
->section_headers_groups
);
20941 filedata
->section_headers_groups
= NULL
;
20943 if (filedata
->section_groups
)
20945 struct group_list
* g
;
20946 struct group_list
* next
;
20948 for (i
= 0; i
< filedata
->group_count
; i
++)
20950 for (g
= filedata
->section_groups
[i
].root
; g
!= NULL
; g
= next
)
20957 free (filedata
->section_groups
);
20958 filedata
->section_groups
= NULL
;
20961 free_debug_memory ();
20966 /* Process an ELF archive.
20967 On entry the file is positioned just after the ARMAG string.
20968 Returns TRUE upon success, FALSE otherwise. */
20971 process_archive (Filedata
* filedata
, bfd_boolean is_thin_archive
)
20973 struct archive_info arch
;
20974 struct archive_info nested_arch
;
20976 bfd_boolean ret
= TRUE
;
20980 /* The ARCH structure is used to hold information about this archive. */
20981 arch
.file_name
= NULL
;
20983 arch
.index_array
= NULL
;
20984 arch
.sym_table
= NULL
;
20985 arch
.longnames
= NULL
;
20987 /* The NESTED_ARCH structure is used as a single-item cache of information
20988 about a nested archive (when members of a thin archive reside within
20989 another regular archive file). */
20990 nested_arch
.file_name
= NULL
;
20991 nested_arch
.file
= NULL
;
20992 nested_arch
.index_array
= NULL
;
20993 nested_arch
.sym_table
= NULL
;
20994 nested_arch
.longnames
= NULL
;
20996 if (setup_archive (&arch
, filedata
->file_name
, filedata
->handle
,
20997 filedata
->file_size
, is_thin_archive
,
20998 do_archive_index
) != 0)
21004 if (do_archive_index
)
21006 if (arch
.sym_table
== NULL
)
21007 error (_("%s: unable to dump the index as none was found\n"),
21008 filedata
->file_name
);
21011 unsigned long i
, l
;
21012 unsigned long current_pos
;
21014 printf (_("Index of archive %s: (%lu entries, 0x%lx bytes "
21015 "in the symbol table)\n"),
21016 filedata
->file_name
, (unsigned long) arch
.index_num
,
21019 current_pos
= ftell (filedata
->handle
);
21021 for (i
= l
= 0; i
< arch
.index_num
; i
++)
21024 || (i
> 0 && arch
.index_array
[i
] != arch
.index_array
[i
- 1]))
21027 = get_archive_member_name_at (&arch
, arch
.index_array
[i
],
21030 if (member_name
!= NULL
)
21032 char * qualified_name
21033 = make_qualified_name (&arch
, &nested_arch
,
21036 if (qualified_name
!= NULL
)
21038 printf (_("Contents of binary %s at offset "),
21040 (void) print_vma (arch
.index_array
[i
], PREFIX_HEX
);
21042 free (qualified_name
);
21044 free (member_name
);
21048 if (l
>= arch
.sym_size
)
21050 error (_("%s: end of the symbol table reached "
21051 "before the end of the index\n"),
21052 filedata
->file_name
);
21056 /* PR 17531: file: 0b6630b2. */
21057 printf ("\t%.*s\n",
21058 (int) (arch
.sym_size
- l
), arch
.sym_table
+ l
);
21059 l
+= strnlen (arch
.sym_table
+ l
, arch
.sym_size
- l
) + 1;
21062 if (arch
.uses_64bit_indices
)
21067 if (l
< arch
.sym_size
)
21069 error (ngettext ("%s: %ld byte remains in the symbol table, "
21070 "but without corresponding entries in "
21071 "the index table\n",
21072 "%s: %ld bytes remain in the symbol table, "
21073 "but without corresponding entries in "
21074 "the index table\n",
21075 arch
.sym_size
- l
),
21076 filedata
->file_name
, arch
.sym_size
- l
);
21080 if (fseek (filedata
->handle
, current_pos
, SEEK_SET
) != 0)
21082 error (_("%s: failed to seek back to start of object files "
21083 "in the archive\n"),
21084 filedata
->file_name
);
21090 if (!do_dynamic
&& !do_syms
&& !do_reloc
&& !do_unwind
&& !do_sections
21091 && !do_segments
&& !do_header
&& !do_dump
&& !do_version
21092 && !do_histogram
&& !do_debugging
&& !do_arch
&& !do_notes
21093 && !do_section_groups
&& !do_dyn_syms
)
21095 ret
= TRUE
; /* Archive index only. */
21104 char * qualified_name
;
21106 /* Read the next archive header. */
21107 if (fseek (filedata
->handle
, arch
.next_arhdr_offset
, SEEK_SET
) != 0)
21109 error (_("%s: failed to seek to next archive header\n"),
21114 got
= fread (&arch
.arhdr
, 1, sizeof arch
.arhdr
, filedata
->handle
);
21115 if (got
!= sizeof arch
.arhdr
)
21119 /* PR 24049 - we cannot use filedata->file_name as this will
21120 have already been freed. */
21121 error (_("%s: failed to read archive header\n"), arch
.file_name
);
21126 if (memcmp (arch
.arhdr
.ar_fmag
, ARFMAG
, 2) != 0)
21128 error (_("%s: did not find a valid archive header\n"),
21134 arch
.next_arhdr_offset
+= sizeof arch
.arhdr
;
21136 filedata
->archive_file_size
= strtoul (arch
.arhdr
.ar_size
, NULL
, 10);
21137 if (filedata
->archive_file_size
& 01)
21138 ++filedata
->archive_file_size
;
21140 name
= get_archive_member_name (&arch
, &nested_arch
);
21143 error (_("%s: bad archive file name\n"), arch
.file_name
);
21147 namelen
= strlen (name
);
21149 qualified_name
= make_qualified_name (&arch
, &nested_arch
, name
);
21150 if (qualified_name
== NULL
)
21152 error (_("%s: bad archive file name\n"), arch
.file_name
);
21158 if (is_thin_archive
&& arch
.nested_member_origin
== 0)
21160 /* This is a proxy for an external member of a thin archive. */
21161 Filedata
* member_filedata
;
21162 char * member_file_name
= adjust_relative_path
21163 (filedata
->file_name
, name
, namelen
);
21166 if (member_file_name
== NULL
)
21168 free (qualified_name
);
21173 member_filedata
= open_file (member_file_name
);
21174 if (member_filedata
== NULL
)
21176 error (_("Input file '%s' is not readable.\n"), member_file_name
);
21177 free (member_file_name
);
21178 free (qualified_name
);
21183 filedata
->archive_file_offset
= arch
.nested_member_origin
;
21184 member_filedata
->file_name
= qualified_name
;
21186 if (! process_object (member_filedata
))
21189 close_file (member_filedata
);
21190 free (member_file_name
);
21192 else if (is_thin_archive
)
21194 Filedata thin_filedata
;
21196 memset (&thin_filedata
, 0, sizeof (thin_filedata
));
21198 /* PR 15140: Allow for corrupt thin archives. */
21199 if (nested_arch
.file
== NULL
)
21201 error (_("%s: contains corrupt thin archive: %s\n"),
21202 qualified_name
, name
);
21203 free (qualified_name
);
21210 /* This is a proxy for a member of a nested archive. */
21211 filedata
->archive_file_offset
21212 = arch
.nested_member_origin
+ sizeof arch
.arhdr
;
21214 /* The nested archive file will have been opened and setup by
21215 get_archive_member_name. */
21216 if (fseek (nested_arch
.file
, filedata
->archive_file_offset
,
21219 error (_("%s: failed to seek to archive member.\n"),
21220 nested_arch
.file_name
);
21221 free (qualified_name
);
21226 thin_filedata
.handle
= nested_arch
.file
;
21227 thin_filedata
.file_name
= qualified_name
;
21229 if (! process_object (& thin_filedata
))
21235 filedata
->archive_file_offset
= arch
.next_arhdr_offset
;
21236 filedata
->file_name
= qualified_name
;
21237 if (! process_object (filedata
))
21239 arch
.next_arhdr_offset
+= filedata
->archive_file_size
;
21240 /* Stop looping with "negative" archive_file_size. */
21241 if (arch
.next_arhdr_offset
< filedata
->archive_file_size
)
21242 arch
.next_arhdr_offset
= -1ul;
21245 free (qualified_name
);
21249 if (nested_arch
.file
!= NULL
)
21250 fclose (nested_arch
.file
);
21251 release_archive (&nested_arch
);
21252 release_archive (&arch
);
21258 process_file (char * file_name
)
21260 Filedata
* filedata
= NULL
;
21261 struct stat statbuf
;
21262 char armag
[SARMAG
];
21263 bfd_boolean ret
= TRUE
;
21265 if (stat (file_name
, &statbuf
) < 0)
21267 if (errno
== ENOENT
)
21268 error (_("'%s': No such file\n"), file_name
);
21270 error (_("Could not locate '%s'. System error message: %s\n"),
21271 file_name
, strerror (errno
));
21275 if (! S_ISREG (statbuf
.st_mode
))
21277 error (_("'%s' is not an ordinary file\n"), file_name
);
21281 filedata
= calloc (1, sizeof * filedata
);
21282 if (filedata
== NULL
)
21284 error (_("Out of memory allocating file data structure\n"));
21288 filedata
->file_name
= file_name
;
21289 filedata
->handle
= fopen (file_name
, "rb");
21290 if (filedata
->handle
== NULL
)
21292 error (_("Input file '%s' is not readable.\n"), file_name
);
21297 if (fread (armag
, SARMAG
, 1, filedata
->handle
) != 1)
21299 error (_("%s: Failed to read file's magic number\n"), file_name
);
21300 fclose (filedata
->handle
);
21305 filedata
->file_size
= (bfd_size_type
) statbuf
.st_size
;
21307 if (memcmp (armag
, ARMAG
, SARMAG
) == 0)
21309 if (! process_archive (filedata
, FALSE
))
21312 else if (memcmp (armag
, ARMAGT
, SARMAG
) == 0)
21314 if ( ! process_archive (filedata
, TRUE
))
21319 if (do_archive_index
&& !check_all
)
21320 error (_("File %s is not an archive so its index cannot be displayed.\n"),
21323 rewind (filedata
->handle
);
21324 filedata
->archive_file_size
= filedata
->archive_file_offset
= 0;
21326 if (! process_object (filedata
))
21330 fclose (filedata
->handle
);
21331 free (filedata
->section_headers
);
21332 free (filedata
->program_headers
);
21333 free (filedata
->string_table
);
21334 free (filedata
->dump
.dump_sects
);
21337 free (ba_cache
.strtab
);
21338 ba_cache
.strtab
= NULL
;
21339 free (ba_cache
.symtab
);
21340 ba_cache
.symtab
= NULL
;
21341 ba_cache
.filedata
= NULL
;
21346 #ifdef SUPPORT_DISASSEMBLY
21347 /* Needed by the i386 disassembler. For extra credit, someone could
21348 fix this so that we insert symbolic addresses here, esp for GOT/PLT
21352 print_address (unsigned int addr
, FILE * outfile
)
21354 fprintf (outfile
,"0x%8.8x", addr
);
21357 /* Needed by the i386 disassembler. */
21360 db_task_printsym (unsigned int addr
)
21362 print_address (addr
, stderr
);
21367 main (int argc
, char ** argv
)
21371 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
21372 setlocale (LC_MESSAGES
, "");
21374 #if defined (HAVE_SETLOCALE)
21375 setlocale (LC_CTYPE
, "");
21377 bindtextdomain (PACKAGE
, LOCALEDIR
);
21378 textdomain (PACKAGE
);
21380 expandargv (&argc
, &argv
);
21382 parse_args (& cmdline
, argc
, argv
);
21384 if (optind
< (argc
- 1))
21385 /* When displaying information for more than one file,
21386 prefix the information with the file name. */
21388 else if (optind
>= argc
)
21390 /* Ensure that the warning is always displayed. */
21393 warn (_("Nothing to do.\n"));
21398 while (optind
< argc
)
21399 if (! process_file (argv
[optind
++]))
21402 free (cmdline
.dump_sects
);
21404 free (dump_ctf_symtab_name
);
21405 free (dump_ctf_strtab_name
);
21406 free (dump_ctf_parent_name
);
21408 return err
? EXIT_FAILURE
: EXIT_SUCCESS
;