1 /* readelf.c -- display contents of an ELF format file
2 Copyright (C) 1998-2019 Free Software Foundation, Inc.
3 Copyright (C) 2019 Advanced Micro Devices, Inc. All rights reserved.
5 Originally developed by Eric Youngdale <eric@andante.jic.com>
6 Modifications by Nick Clifton <nickc@redhat.com>
8 This file is part of GNU Binutils.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
25 /* The difference between readelf and objdump:
27 Both programs are capable of displaying the contents of ELF format files,
28 so why does the binutils project have two file dumpers ?
30 The reason is that objdump sees an ELF file through a BFD filter of the
31 world; if BFD has a bug where, say, it disagrees about a machine constant
32 in e_flags, then the odds are good that it will remain internally
33 consistent. The linker sees it the BFD way, objdump sees it the BFD way,
34 GAS sees it the BFD way. There was need for a tool to go find out what
35 the file actually says.
37 This is why the readelf program does not link against the BFD library - it
38 exists as an independent program to help verify the correct working of BFD.
40 There is also the case that readelf can provide more information about an
41 ELF file than is provided by objdump. In particular it can display DWARF
42 debugging information which (at the moment) objdump cannot. */
53 /* Define BFD64 here, even if our default architecture is 32 bit ELF
54 as this will allow us to read in and parse 64bit and 32bit ELF files.
55 Only do this if we believe that the compiler can support a 64 bit
56 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"
96 #include "elf/amdgcn.h"
100 #include "elf/bfin.h"
101 #include "elf/cr16.h"
102 #include "elf/cris.h"
104 #include "elf/csky.h"
105 #include "elf/d10v.h"
106 #include "elf/d30v.h"
109 #include "elf/epiphany.h"
110 #include "elf/fr30.h"
112 #include "elf/ft32.h"
114 #include "elf/hppa.h"
115 #include "elf/i386.h"
116 #include "elf/i370.h"
117 #include "elf/i860.h"
118 #include "elf/i960.h"
119 #include "elf/ia64.h"
120 #include "elf/ip2k.h"
121 #include "elf/lm32.h"
122 #include "elf/iq2000.h"
123 #include "elf/m32c.h"
124 #include "elf/m32r.h"
125 #include "elf/m68k.h"
126 #include "elf/m68hc11.h"
127 #include "elf/s12z.h"
128 #include "elf/mcore.h"
130 #include "elf/metag.h"
131 #include "elf/microblaze.h"
132 #include "elf/mips.h"
133 #include "elf/mmix.h"
134 #include "elf/mn10200.h"
135 #include "elf/mn10300.h"
136 #include "elf/moxie.h"
138 #include "elf/msp430.h"
139 #include "elf/nds32.h"
141 #include "elf/nios2.h"
142 #include "elf/or1k.h"
145 #include "elf/ppc64.h"
147 #include "elf/riscv.h"
148 #include "elf/rl78.h"
150 #include "elf/s390.h"
151 #include "elf/score.h"
153 #include "elf/sparc.h"
155 #include "elf/tic6x.h"
156 #include "elf/tilegx.h"
157 #include "elf/tilepro.h"
158 #include "elf/v850.h"
160 #include "elf/visium.h"
161 #include "elf/wasm32.h"
162 #include "elf/x86-64.h"
163 #include "elf/xc16x.h"
164 #include "elf/xgate.h"
165 #include "elf/xstormy16.h"
166 #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 typedef struct filedata
203 const char * file_name
;
205 bfd_size_type file_size
;
206 Elf_Internal_Ehdr file_header
;
207 Elf_Internal_Shdr
* section_headers
;
208 Elf_Internal_Phdr
* program_headers
;
210 unsigned long string_table_length
;
211 /* A dynamic array of flags indicating for which sections a dump of
212 some kind has been requested. It is reset on a per-object file
213 basis and then initialised from the cmdline_dump_sects array,
214 the results of interpreting the -w switch, and the
215 dump_sects_byname list. */
216 dump_type
* dump_sects
;
217 unsigned int num_dump_sects
;
220 char * program_name
= "readelf";
222 static unsigned long archive_file_offset
;
223 static unsigned long archive_file_size
;
224 static unsigned long dynamic_addr
;
225 static bfd_size_type dynamic_size
;
226 static size_t dynamic_nent
;
227 static char * dynamic_strings
;
228 static unsigned long dynamic_strings_length
;
229 static unsigned long num_dynamic_syms
;
230 static Elf_Internal_Sym
* dynamic_symbols
;
231 static Elf_Internal_Syminfo
* dynamic_syminfo
;
232 static unsigned long dynamic_syminfo_offset
;
233 static unsigned int dynamic_syminfo_nent
;
234 static char program_interpreter
[PATH_MAX
];
235 static bfd_vma dynamic_info
[DT_ENCODING
];
236 static bfd_vma dynamic_info_DT_GNU_HASH
;
237 static bfd_vma dynamic_info_DT_MIPS_XHASH
;
238 static bfd_vma version_info
[16];
239 static Elf_Internal_Dyn
* dynamic_section
;
240 static elf_section_list
* symtab_shndx_list
;
241 static bfd_boolean show_name
= FALSE
;
242 static bfd_boolean do_dynamic
= FALSE
;
243 static bfd_boolean do_syms
= FALSE
;
244 static bfd_boolean do_dyn_syms
= FALSE
;
245 static bfd_boolean do_reloc
= FALSE
;
246 static bfd_boolean do_sections
= FALSE
;
247 static bfd_boolean do_section_groups
= FALSE
;
248 static bfd_boolean do_section_details
= FALSE
;
249 static bfd_boolean do_segments
= FALSE
;
250 static bfd_boolean do_unwind
= FALSE
;
251 static bfd_boolean do_using_dynamic
= FALSE
;
252 static bfd_boolean do_header
= FALSE
;
253 static bfd_boolean do_dump
= FALSE
;
254 static bfd_boolean do_version
= FALSE
;
255 static bfd_boolean do_histogram
= FALSE
;
256 static bfd_boolean do_debugging
= FALSE
;
257 static bfd_boolean do_ctf
= FALSE
;
258 static bfd_boolean do_arch
= FALSE
;
259 static bfd_boolean do_notes
= FALSE
;
260 static bfd_boolean do_archive_index
= FALSE
;
261 static bfd_boolean is_32bit_elf
= FALSE
;
262 static bfd_boolean decompress_dumps
= FALSE
;
264 static char *dump_ctf_parent_name
;
265 static char *dump_ctf_symtab_name
;
266 static char *dump_ctf_strtab_name
;
270 struct group_list
* next
;
271 unsigned int section_index
;
276 struct group_list
* root
;
277 unsigned int group_index
;
280 static size_t group_count
;
281 static struct group
* section_groups
;
282 static struct group
** section_headers_groups
;
284 /* A dynamic array of flags indicating for which sections a dump
285 has been requested via command line switches. */
286 static Filedata cmdline
;
288 static struct dump_list_entry
* dump_sects_byname
;
290 /* How to print a vma value. */
291 typedef enum print_mode
303 /* Versioned symbol info. */
304 enum versioned_symbol_info
311 static const char * get_symbol_version_string
312 (Filedata
*, bfd_boolean
, const char *, unsigned long, unsigned,
313 Elf_Internal_Sym
*, enum versioned_symbol_info
*, unsigned short *);
317 #define SECTION_NAME(X) \
318 ((X) == NULL ? _("<none>") \
319 : filedata->string_table == NULL ? _("<no-strings>") \
320 : ((X)->sh_name >= filedata->string_table_length ? _("<corrupt>") \
321 : filedata->string_table + (X)->sh_name))
323 #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
325 #define GET_ELF_SYMBOLS(file, section, sym_count) \
326 (is_32bit_elf ? get_32bit_elf_symbols (file, section, sym_count) \
327 : get_64bit_elf_symbols (file, section, sym_count))
329 #define VALID_DYNAMIC_NAME(offset) ((dynamic_strings != NULL) && (offset < dynamic_strings_length))
330 /* GET_DYNAMIC_NAME asssumes that VALID_DYNAMIC_NAME has
331 already been called and verified that the string exists. */
332 #define GET_DYNAMIC_NAME(offset) (dynamic_strings + offset)
334 #define REMOVE_ARCH_BITS(ADDR) \
337 if (filedata->file_header.e_machine == EM_ARM) \
342 /* Get the correct GNU hash section name. */
343 #define GNU_HASH_SECTION_NAME \
344 dynamic_info_DT_MIPS_XHASH ? ".MIPS.xhash" : ".gnu.hash"
346 /* Print a BFD_VMA to an internal buffer, for use in error messages.
347 BFD_FMA_FMT can't be used in translated strings. */
350 bfd_vmatoa (char *fmtch
, bfd_vma value
)
352 /* bfd_vmatoa is used more then once in a printf call for output.
353 Cycle through an array of buffers. */
354 static int buf_pos
= 0;
355 static struct bfd_vmatoa_buf
362 ret
= buf
[buf_pos
++].place
;
363 buf_pos
%= ARRAY_SIZE (buf
);
365 sprintf (fmt
, "%%%s%s", BFD_VMA_FMT
, fmtch
);
366 snprintf (ret
, sizeof (buf
[0].place
), fmt
, value
);
370 /* Retrieve NMEMB structures, each SIZE bytes long from FILEDATA starting at
371 OFFSET + the offset of the current archive member, if we are examining an
372 archive. Put the retrieved data into VAR, if it is not NULL. Otherwise
373 allocate a buffer using malloc and fill that. In either case return the
374 pointer to the start of the retrieved data or NULL if something went wrong.
375 If something does go wrong and REASON is not NULL then emit an error
376 message using REASON as part of the context. */
379 get_data (void * var
,
381 unsigned long offset
,
387 bfd_size_type amt
= size
* nmemb
;
389 if (size
== 0 || nmemb
== 0)
392 /* If the size_t type is smaller than the bfd_size_type, eg because
393 you are building a 32-bit tool on a 64-bit host, then make sure
394 that when the sizes are cast to (size_t) no information is lost. */
395 if ((size_t) size
!= size
396 || (size_t) nmemb
!= nmemb
397 || (size_t) amt
!= amt
)
400 error (_("Size truncation prevents reading %s"
401 " elements of size %s for %s\n"),
402 bfd_vmatoa ("u", nmemb
), bfd_vmatoa ("u", size
), reason
);
406 /* Check for size overflow. */
407 if (amt
/ size
!= nmemb
|| (size_t) amt
+ 1 == 0)
410 error (_("Size overflow prevents reading %s"
411 " elements of size %s for %s\n"),
412 bfd_vmatoa ("u", nmemb
), bfd_vmatoa ("u", size
), reason
);
416 /* Be kind to memory checkers (eg valgrind, address sanitizer) by not
417 attempting to allocate memory when the read is bound to fail. */
418 if (archive_file_offset
> filedata
->file_size
419 || offset
> filedata
->file_size
- archive_file_offset
420 || amt
> filedata
->file_size
- archive_file_offset
- offset
)
423 error (_("Reading %s bytes extends past end of file for %s\n"),
424 bfd_vmatoa ("u", amt
), reason
);
428 if (fseek (filedata
->handle
, archive_file_offset
+ offset
, SEEK_SET
))
431 error (_("Unable to seek to 0x%lx for %s\n"),
432 archive_file_offset
+ offset
, reason
);
439 /* + 1 so that we can '\0' terminate invalid string table sections. */
440 mvar
= malloc ((size_t) amt
+ 1);
445 error (_("Out of memory allocating %s bytes for %s\n"),
446 bfd_vmatoa ("u", amt
), reason
);
450 ((char *) mvar
)[amt
] = '\0';
453 if (fread (mvar
, (size_t) size
, (size_t) nmemb
, filedata
->handle
) != nmemb
)
456 error (_("Unable to read in %s bytes of %s\n"),
457 bfd_vmatoa ("u", amt
), reason
);
466 /* Print a VMA value in the MODE specified.
467 Returns the number of characters displayed. */
470 print_vma (bfd_vma vma
, print_mode mode
)
482 return nc
+ printf ("%8.8" BFD_VMA_FMT
"x", vma
);
489 return printf ("%5" BFD_VMA_FMT
"d", vma
);
495 return nc
+ printf ("%" BFD_VMA_FMT
"x", vma
);
498 return printf ("%" BFD_VMA_FMT
"d", vma
);
501 return printf ("%" BFD_VMA_FMT
"u", vma
);
504 /* FIXME: Report unrecognised mode ? */
509 /* Display a symbol on stdout. Handles the display of control characters and
510 multibye characters (assuming the host environment supports them).
512 Display at most abs(WIDTH) characters, truncating as necessary, unless do_wide is true.
514 If WIDTH is negative then ensure that the output is at least (- WIDTH) characters,
515 padding as necessary.
517 Returns the number of emitted characters. */
520 print_symbol (signed int width
, const char *symbol
)
522 bfd_boolean extra_padding
= FALSE
;
523 signed int num_printed
= 0;
524 #ifdef HAVE_MBSTATE_T
527 unsigned int width_remaining
;
531 /* Keep the width positive. This helps the code below. */
533 extra_padding
= TRUE
;
539 /* Set the remaining width to a very large value.
540 This simplifies the code below. */
541 width_remaining
= INT_MAX
;
543 width_remaining
= width
;
545 #ifdef HAVE_MBSTATE_T
546 /* Initialise the multibyte conversion state. */
547 memset (& state
, 0, sizeof (state
));
550 while (width_remaining
)
553 const char c
= *symbol
++;
558 /* Do not print control characters directly as they can affect terminal
559 settings. Such characters usually appear in the names generated
560 by the assembler for local labels. */
563 if (width_remaining
< 2)
566 printf ("^%c", c
+ 0x40);
567 width_remaining
-= 2;
570 else if (ISPRINT (c
))
578 #ifdef HAVE_MBSTATE_T
581 /* Let printf do the hard work of displaying multibyte characters. */
582 printf ("%.1s", symbol
- 1);
586 #ifdef HAVE_MBSTATE_T
587 /* Try to find out how many bytes made up the character that was
588 just printed. Advance the symbol pointer past the bytes that
590 n
= mbrtowc (& w
, symbol
- 1, MB_CUR_MAX
, & state
);
594 if (n
!= (size_t) -1 && n
!= (size_t) -2 && n
> 0)
599 if (extra_padding
&& num_printed
< width
)
601 /* Fill in the remaining spaces. */
602 printf ("%-*s", width
- num_printed
, " ");
609 /* Returns a pointer to a static buffer containing a printable version of
610 the given section's name. Like print_symbol, except that it does not try
611 to print multibyte characters, it just interprets them as hex values. */
614 printable_section_name (Filedata
* filedata
, const Elf_Internal_Shdr
* sec
)
616 #define MAX_PRINT_SEC_NAME_LEN 128
617 static char sec_name_buf
[MAX_PRINT_SEC_NAME_LEN
+ 1];
618 const char * name
= SECTION_NAME (sec
);
619 char * buf
= sec_name_buf
;
621 unsigned int remaining
= MAX_PRINT_SEC_NAME_LEN
;
623 while ((c
= * name
++) != 0)
634 else if (ISPRINT (c
))
641 static char hex
[17] = "0123456789ABCDEF";
646 * buf
++ = hex
[(c
& 0xf0) >> 4];
647 * buf
++ = hex
[c
& 0x0f];
661 printable_section_name_from_index (Filedata
* filedata
, unsigned long ndx
)
663 if (ndx
>= filedata
->file_header
.e_shnum
)
664 return _("<corrupt>");
666 return printable_section_name (filedata
, filedata
->section_headers
+ ndx
);
669 /* Return a pointer to section NAME, or NULL if no such section exists. */
671 static Elf_Internal_Shdr
*
672 find_section (Filedata
* filedata
, const char * name
)
676 if (filedata
->section_headers
== NULL
)
679 for (i
= 0; i
< filedata
->file_header
.e_shnum
; i
++)
680 if (streq (SECTION_NAME (filedata
->section_headers
+ i
), name
))
681 return filedata
->section_headers
+ i
;
686 /* Return a pointer to a section containing ADDR, or NULL if no such
689 static Elf_Internal_Shdr
*
690 find_section_by_address (Filedata
* filedata
, bfd_vma addr
)
694 if (filedata
->section_headers
== NULL
)
697 for (i
= 0; i
< filedata
->file_header
.e_shnum
; i
++)
699 Elf_Internal_Shdr
*sec
= filedata
->section_headers
+ i
;
701 if (addr
>= sec
->sh_addr
&& addr
< sec
->sh_addr
+ sec
->sh_size
)
708 static Elf_Internal_Shdr
*
709 find_section_by_type (Filedata
* filedata
, unsigned int type
)
713 if (filedata
->section_headers
== NULL
)
716 for (i
= 0; i
< filedata
->file_header
.e_shnum
; i
++)
718 Elf_Internal_Shdr
*sec
= filedata
->section_headers
+ i
;
720 if (sec
->sh_type
== type
)
727 /* Return a pointer to section NAME, or NULL if no such section exists,
728 restricted to the list of sections given in SET. */
730 static Elf_Internal_Shdr
*
731 find_section_in_set (Filedata
* filedata
, const char * name
, unsigned int * set
)
735 if (filedata
->section_headers
== NULL
)
740 while ((i
= *set
++) > 0)
742 /* See PR 21156 for a reproducer. */
743 if (i
>= filedata
->file_header
.e_shnum
)
744 continue; /* FIXME: Should we issue an error message ? */
746 if (streq (SECTION_NAME (filedata
->section_headers
+ i
), name
))
747 return filedata
->section_headers
+ i
;
751 return find_section (filedata
, name
);
754 /* Read an unsigned LEB128 encoded value from DATA.
755 Set *LENGTH_RETURN to the number of bytes read. */
757 static inline unsigned long
758 read_uleb128 (unsigned char * data
,
759 unsigned int * length_return
,
760 const unsigned char * const end
)
762 return read_leb128 (data
, length_return
, FALSE
, end
);
765 /* Return TRUE if the current file is for IA-64 machine and OpenVMS ABI.
766 This OS has so many departures from the ELF standard that we test it at
769 static inline bfd_boolean
770 is_ia64_vms (Filedata
* filedata
)
772 return filedata
->file_header
.e_machine
== EM_IA_64
773 && filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_OPENVMS
;
776 /* Guess the relocation size commonly used by the specific machines. */
779 guess_is_rela (unsigned int e_machine
)
783 /* Targets that use REL relocations. */
800 /* Targets that use RELA relocations. */
804 case EM_ADAPTEVA_EPIPHANY
:
806 case EM_ALTERA_NIOS2
:
809 case EM_ARC_COMPACT2
:
830 case EM_LATTICEMICO32
:
839 case EM_CYGNUS_MN10200
:
841 case EM_CYGNUS_MN10300
:
877 case EM_MICROBLAZE_OLD
:
899 warn (_("Don't know about relocations on this machine architecture\n"));
904 /* Load RELA type relocations from FILEDATA at REL_OFFSET extending for REL_SIZE bytes.
905 Returns TRUE upon success, FALSE otherwise. If successful then a
906 pointer to a malloc'ed buffer containing the relocs is placed in *RELASP,
907 and the number of relocs loaded is placed in *NRELASP. It is the caller's
908 responsibility to free the allocated buffer. */
911 slurp_rela_relocs (Filedata
* filedata
,
912 unsigned long rel_offset
,
913 unsigned long rel_size
,
914 Elf_Internal_Rela
** relasp
,
915 unsigned long * nrelasp
)
917 Elf_Internal_Rela
* relas
;
923 Elf32_External_Rela
* erelas
;
925 erelas
= (Elf32_External_Rela
*) get_data (NULL
, filedata
, rel_offset
, 1,
926 rel_size
, _("32-bit relocation data"));
930 nrelas
= rel_size
/ sizeof (Elf32_External_Rela
);
932 relas
= (Elf_Internal_Rela
*) cmalloc (nrelas
,
933 sizeof (Elf_Internal_Rela
));
938 error (_("out of memory parsing relocs\n"));
942 for (i
= 0; i
< nrelas
; i
++)
944 relas
[i
].r_offset
= BYTE_GET (erelas
[i
].r_offset
);
945 relas
[i
].r_info
= BYTE_GET (erelas
[i
].r_info
);
946 relas
[i
].r_addend
= BYTE_GET_SIGNED (erelas
[i
].r_addend
);
953 Elf64_External_Rela
* erelas
;
955 erelas
= (Elf64_External_Rela
*) get_data (NULL
, filedata
, rel_offset
, 1,
956 rel_size
, _("64-bit relocation data"));
960 nrelas
= rel_size
/ sizeof (Elf64_External_Rela
);
962 relas
= (Elf_Internal_Rela
*) cmalloc (nrelas
,
963 sizeof (Elf_Internal_Rela
));
968 error (_("out of memory parsing relocs\n"));
972 for (i
= 0; i
< nrelas
; i
++)
974 relas
[i
].r_offset
= BYTE_GET (erelas
[i
].r_offset
);
975 relas
[i
].r_info
= BYTE_GET (erelas
[i
].r_info
);
976 relas
[i
].r_addend
= BYTE_GET_SIGNED (erelas
[i
].r_addend
);
978 /* The #ifdef BFD64 below is to prevent a compile time
979 warning. We know that if we do not have a 64 bit data
980 type that we will never execute this code anyway. */
982 if (filedata
->file_header
.e_machine
== EM_MIPS
983 && filedata
->file_header
.e_ident
[EI_DATA
] != ELFDATA2MSB
)
985 /* In little-endian objects, r_info isn't really a
986 64-bit little-endian value: it has a 32-bit
987 little-endian symbol index followed by four
988 individual byte fields. Reorder INFO
990 bfd_vma inf
= relas
[i
].r_info
;
991 inf
= (((inf
& 0xffffffff) << 32)
992 | ((inf
>> 56) & 0xff)
993 | ((inf
>> 40) & 0xff00)
994 | ((inf
>> 24) & 0xff0000)
995 | ((inf
>> 8) & 0xff000000));
996 relas
[i
].r_info
= inf
;
1009 /* Load REL type relocations from FILEDATA at REL_OFFSET extending for REL_SIZE bytes.
1010 Returns TRUE upon success, FALSE otherwise. If successful then a
1011 pointer to a malloc'ed buffer containing the relocs is placed in *RELSP,
1012 and the number of relocs loaded is placed in *NRELSP. It is the caller's
1013 responsibility to free the allocated buffer. */
1016 slurp_rel_relocs (Filedata
* filedata
,
1017 unsigned long rel_offset
,
1018 unsigned long rel_size
,
1019 Elf_Internal_Rela
** relsp
,
1020 unsigned long * nrelsp
)
1022 Elf_Internal_Rela
* rels
;
1028 Elf32_External_Rel
* erels
;
1030 erels
= (Elf32_External_Rel
*) get_data (NULL
, filedata
, rel_offset
, 1,
1031 rel_size
, _("32-bit relocation data"));
1035 nrels
= rel_size
/ sizeof (Elf32_External_Rel
);
1037 rels
= (Elf_Internal_Rela
*) cmalloc (nrels
, sizeof (Elf_Internal_Rela
));
1042 error (_("out of memory parsing relocs\n"));
1046 for (i
= 0; i
< nrels
; i
++)
1048 rels
[i
].r_offset
= BYTE_GET (erels
[i
].r_offset
);
1049 rels
[i
].r_info
= BYTE_GET (erels
[i
].r_info
);
1050 rels
[i
].r_addend
= 0;
1057 Elf64_External_Rel
* erels
;
1059 erels
= (Elf64_External_Rel
*) get_data (NULL
, filedata
, rel_offset
, 1,
1060 rel_size
, _("64-bit relocation data"));
1064 nrels
= rel_size
/ sizeof (Elf64_External_Rel
);
1066 rels
= (Elf_Internal_Rela
*) cmalloc (nrels
, sizeof (Elf_Internal_Rela
));
1071 error (_("out of memory parsing relocs\n"));
1075 for (i
= 0; i
< nrels
; i
++)
1077 rels
[i
].r_offset
= BYTE_GET (erels
[i
].r_offset
);
1078 rels
[i
].r_info
= BYTE_GET (erels
[i
].r_info
);
1079 rels
[i
].r_addend
= 0;
1081 /* The #ifdef BFD64 below is to prevent a compile time
1082 warning. We know that if we do not have a 64 bit data
1083 type that we will never execute this code anyway. */
1085 if (filedata
->file_header
.e_machine
== EM_MIPS
1086 && filedata
->file_header
.e_ident
[EI_DATA
] != ELFDATA2MSB
)
1088 /* In little-endian objects, r_info isn't really a
1089 64-bit little-endian value: it has a 32-bit
1090 little-endian symbol index followed by four
1091 individual byte fields. Reorder INFO
1093 bfd_vma inf
= rels
[i
].r_info
;
1094 inf
= (((inf
& 0xffffffff) << 32)
1095 | ((inf
>> 56) & 0xff)
1096 | ((inf
>> 40) & 0xff00)
1097 | ((inf
>> 24) & 0xff0000)
1098 | ((inf
>> 8) & 0xff000000));
1099 rels
[i
].r_info
= inf
;
1112 /* Returns the reloc type extracted from the reloc info field. */
1115 get_reloc_type (Filedata
* filedata
, bfd_vma reloc_info
)
1118 return ELF32_R_TYPE (reloc_info
);
1120 switch (filedata
->file_header
.e_machine
)
1123 /* Note: We assume that reloc_info has already been adjusted for us. */
1124 return ELF64_MIPS_R_TYPE (reloc_info
);
1127 return ELF64_R_TYPE_ID (reloc_info
);
1130 return ELF64_R_TYPE (reloc_info
);
1134 /* Return the symbol index extracted from the reloc info field. */
1137 get_reloc_symindex (bfd_vma reloc_info
)
1139 return is_32bit_elf
? ELF32_R_SYM (reloc_info
) : ELF64_R_SYM (reloc_info
);
1142 static inline bfd_boolean
1143 uses_msp430x_relocs (Filedata
* filedata
)
1146 filedata
->file_header
.e_machine
== EM_MSP430
/* Paranoia. */
1147 /* GCC uses osabi == ELFOSBI_STANDALONE. */
1148 && (((filedata
->file_header
.e_flags
& EF_MSP430_MACH
) == E_MSP430_MACH_MSP430X
)
1149 /* TI compiler uses ELFOSABI_NONE. */
1150 || (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_NONE
));
1153 /* Display the contents of the relocation data found at the specified
1157 dump_relocations (Filedata
* filedata
,
1158 unsigned long rel_offset
,
1159 unsigned long rel_size
,
1160 Elf_Internal_Sym
* symtab
,
1161 unsigned long nsyms
,
1163 unsigned long strtablen
,
1165 bfd_boolean is_dynsym
)
1168 Elf_Internal_Rela
* rels
;
1169 bfd_boolean res
= TRUE
;
1171 if (is_rela
== UNKNOWN
)
1172 is_rela
= guess_is_rela (filedata
->file_header
.e_machine
);
1176 if (!slurp_rela_relocs (filedata
, rel_offset
, rel_size
, &rels
, &rel_size
))
1181 if (!slurp_rel_relocs (filedata
, rel_offset
, rel_size
, &rels
, &rel_size
))
1190 printf (_(" Offset Info Type Sym. Value Symbol's Name + Addend\n"));
1192 printf (_(" Offset Info Type Sym.Value Sym. Name + Addend\n"));
1197 printf (_(" Offset Info Type Sym. Value Symbol's Name\n"));
1199 printf (_(" Offset Info Type Sym.Value Sym. Name\n"));
1207 printf (_(" Offset Info Type Symbol's Value Symbol's Name + Addend\n"));
1209 printf (_(" Offset Info Type Sym. Value Sym. Name + Addend\n"));
1214 printf (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
1216 printf (_(" Offset Info Type Sym. Value Sym. Name\n"));
1220 for (i
= 0; i
< rel_size
; i
++)
1225 bfd_vma symtab_index
;
1228 offset
= rels
[i
].r_offset
;
1229 inf
= rels
[i
].r_info
;
1231 type
= get_reloc_type (filedata
, inf
);
1232 symtab_index
= get_reloc_symindex (inf
);
1236 printf ("%8.8lx %8.8lx ",
1237 (unsigned long) offset
& 0xffffffff,
1238 (unsigned long) inf
& 0xffffffff);
1242 #if BFD_HOST_64BIT_LONG
1244 ? "%16.16lx %16.16lx "
1245 : "%12.12lx %12.12lx ",
1247 #elif BFD_HOST_64BIT_LONG_LONG
1250 ? "%16.16llx %16.16llx "
1251 : "%12.12llx %12.12llx ",
1255 ? "%16.16I64x %16.16I64x "
1256 : "%12.12I64x %12.12I64x ",
1261 ? "%8.8lx%8.8lx %8.8lx%8.8lx "
1262 : "%4.4lx%8.8lx %4.4lx%8.8lx ",
1263 _bfd_int64_high (offset
),
1264 _bfd_int64_low (offset
),
1265 _bfd_int64_high (inf
),
1266 _bfd_int64_low (inf
));
1270 switch (filedata
->file_header
.e_machine
)
1277 rtype
= elf_aarch64_reloc_type (type
);
1281 case EM_CYGNUS_M32R
:
1282 rtype
= elf_m32r_reloc_type (type
);
1287 rtype
= elf_i386_reloc_type (type
);
1292 rtype
= elf_m68hc11_reloc_type (type
);
1296 rtype
= elf_s12z_reloc_type (type
);
1300 rtype
= elf_m68k_reloc_type (type
);
1304 rtype
= elf_i960_reloc_type (type
);
1309 rtype
= elf_avr_reloc_type (type
);
1312 case EM_OLD_SPARCV9
:
1313 case EM_SPARC32PLUS
:
1316 rtype
= elf_sparc_reloc_type (type
);
1320 rtype
= elf_spu_reloc_type (type
);
1324 rtype
= v800_reloc_type (type
);
1327 case EM_CYGNUS_V850
:
1328 rtype
= v850_reloc_type (type
);
1332 case EM_CYGNUS_D10V
:
1333 rtype
= elf_d10v_reloc_type (type
);
1337 case EM_CYGNUS_D30V
:
1338 rtype
= elf_d30v_reloc_type (type
);
1342 rtype
= elf_dlx_reloc_type (type
);
1346 rtype
= elf_sh_reloc_type (type
);
1350 case EM_CYGNUS_MN10300
:
1351 rtype
= elf_mn10300_reloc_type (type
);
1355 case EM_CYGNUS_MN10200
:
1356 rtype
= elf_mn10200_reloc_type (type
);
1360 case EM_CYGNUS_FR30
:
1361 rtype
= elf_fr30_reloc_type (type
);
1365 rtype
= elf_frv_reloc_type (type
);
1369 rtype
= elf_csky_reloc_type (type
);
1373 rtype
= elf_ft32_reloc_type (type
);
1377 rtype
= elf_mcore_reloc_type (type
);
1381 rtype
= elf_mmix_reloc_type (type
);
1385 rtype
= elf_moxie_reloc_type (type
);
1389 if (uses_msp430x_relocs (filedata
))
1391 rtype
= elf_msp430x_reloc_type (type
);
1396 rtype
= elf_msp430_reloc_type (type
);
1400 rtype
= elf_nds32_reloc_type (type
);
1404 rtype
= elf_ppc_reloc_type (type
);
1408 rtype
= elf_ppc64_reloc_type (type
);
1412 case EM_MIPS_RS3_LE
:
1413 rtype
= elf_mips_reloc_type (type
);
1417 rtype
= elf_riscv_reloc_type (type
);
1421 rtype
= elf_alpha_reloc_type (type
);
1425 rtype
= elf_arm_reloc_type (type
);
1429 case EM_ARC_COMPACT
:
1430 case EM_ARC_COMPACT2
:
1431 rtype
= elf_arc_reloc_type (type
);
1435 rtype
= elf_hppa_reloc_type (type
);
1441 rtype
= elf_h8_reloc_type (type
);
1445 rtype
= elf_or1k_reloc_type (type
);
1450 rtype
= elf_pj_reloc_type (type
);
1453 rtype
= elf_ia64_reloc_type (type
);
1457 rtype
= elf_cris_reloc_type (type
);
1461 rtype
= elf_i860_reloc_type (type
);
1467 rtype
= elf_x86_64_reloc_type (type
);
1471 rtype
= i370_reloc_type (type
);
1476 rtype
= elf_s390_reloc_type (type
);
1480 rtype
= elf_score_reloc_type (type
);
1484 rtype
= elf_xstormy16_reloc_type (type
);
1488 rtype
= elf_crx_reloc_type (type
);
1492 rtype
= elf_vax_reloc_type (type
);
1496 rtype
= elf_visium_reloc_type (type
);
1500 rtype
= elf_bpf_reloc_type (type
);
1503 case EM_ADAPTEVA_EPIPHANY
:
1504 rtype
= elf_epiphany_reloc_type (type
);
1509 rtype
= elf_ip2k_reloc_type (type
);
1513 rtype
= elf_iq2000_reloc_type (type
);
1518 rtype
= elf_xtensa_reloc_type (type
);
1521 case EM_LATTICEMICO32
:
1522 rtype
= elf_lm32_reloc_type (type
);
1527 rtype
= elf_m32c_reloc_type (type
);
1531 rtype
= elf_mt_reloc_type (type
);
1535 rtype
= elf_bfin_reloc_type (type
);
1539 rtype
= elf_mep_reloc_type (type
);
1543 rtype
= elf_cr16_reloc_type (type
);
1547 case EM_MICROBLAZE_OLD
:
1548 rtype
= elf_microblaze_reloc_type (type
);
1552 rtype
= elf_rl78_reloc_type (type
);
1556 rtype
= elf_rx_reloc_type (type
);
1560 rtype
= elf_metag_reloc_type (type
);
1565 rtype
= elf_xc16x_reloc_type (type
);
1569 rtype
= elf_tic6x_reloc_type (type
);
1573 rtype
= elf_tilegx_reloc_type (type
);
1577 rtype
= elf_tilepro_reloc_type (type
);
1580 case EM_WEBASSEMBLY
:
1581 rtype
= elf_wasm32_reloc_type (type
);
1585 rtype
= elf_xgate_reloc_type (type
);
1588 case EM_ALTERA_NIOS2
:
1589 rtype
= elf_nios2_reloc_type (type
);
1593 rtype
= elf_pru_reloc_type (type
);
1597 if (EF_NFP_MACH (filedata
->file_header
.e_flags
) == E_NFP_MACH_3200
)
1598 rtype
= elf_nfp3200_reloc_type (type
);
1600 rtype
= elf_nfp_reloc_type (type
);
1604 rtype
= elf_amdgcn_reloc_type (type
);
1609 printf (_("unrecognized: %-7lx"), (unsigned long) type
& 0xffffffff);
1611 printf (do_wide
? "%-22s" : "%-17.17s", rtype
);
1613 if (filedata
->file_header
.e_machine
== EM_ALPHA
1615 && streq (rtype
, "R_ALPHA_LITUSE")
1618 switch (rels
[i
].r_addend
)
1620 case LITUSE_ALPHA_ADDR
: rtype
= "ADDR"; break;
1621 case LITUSE_ALPHA_BASE
: rtype
= "BASE"; break;
1622 case LITUSE_ALPHA_BYTOFF
: rtype
= "BYTOFF"; break;
1623 case LITUSE_ALPHA_JSR
: rtype
= "JSR"; break;
1624 case LITUSE_ALPHA_TLSGD
: rtype
= "TLSGD"; break;
1625 case LITUSE_ALPHA_TLSLDM
: rtype
= "TLSLDM"; break;
1626 case LITUSE_ALPHA_JSRDIRECT
: rtype
= "JSRDIRECT"; break;
1627 default: rtype
= NULL
;
1631 printf (" (%s)", rtype
);
1635 printf (_("<unknown addend: %lx>"),
1636 (unsigned long) rels
[i
].r_addend
);
1640 else if (symtab_index
)
1642 if (symtab
== NULL
|| symtab_index
>= nsyms
)
1644 error (_(" bad symbol index: %08lx in reloc"), (unsigned long) symtab_index
);
1649 Elf_Internal_Sym
* psym
;
1650 const char * version_string
;
1651 enum versioned_symbol_info sym_info
;
1652 unsigned short vna_other
;
1654 psym
= symtab
+ symtab_index
;
1657 = get_symbol_version_string (filedata
, is_dynsym
,
1666 if (ELF_ST_TYPE (psym
->st_info
) == STT_GNU_IFUNC
)
1670 unsigned int width
= is_32bit_elf
? 8 : 14;
1672 /* Relocations against GNU_IFUNC symbols do not use the value
1673 of the symbol as the address to relocate against. Instead
1674 they invoke the function named by the symbol and use its
1675 result as the address for relocation.
1677 To indicate this to the user, do not display the value of
1678 the symbol in the "Symbols's Value" field. Instead show
1679 its name followed by () as a hint that the symbol is
1683 || psym
->st_name
== 0
1684 || psym
->st_name
>= strtablen
)
1687 name
= strtab
+ psym
->st_name
;
1689 len
= print_symbol (width
, name
);
1691 printf (sym_info
== symbol_public
? "@@%s" : "@%s",
1693 printf ("()%-*s", len
<= width
? (width
+ 1) - len
: 1, " ");
1697 print_vma (psym
->st_value
, LONG_HEX
);
1699 printf (is_32bit_elf
? " " : " ");
1702 if (psym
->st_name
== 0)
1704 const char * sec_name
= "<null>";
1707 if (ELF_ST_TYPE (psym
->st_info
) == STT_SECTION
)
1709 if (psym
->st_shndx
< filedata
->file_header
.e_shnum
)
1710 sec_name
= SECTION_NAME (filedata
->section_headers
+ psym
->st_shndx
);
1711 else if (psym
->st_shndx
== SHN_ABS
)
1713 else if (psym
->st_shndx
== SHN_COMMON
)
1714 sec_name
= "COMMON";
1715 else if ((filedata
->file_header
.e_machine
== EM_MIPS
1716 && psym
->st_shndx
== SHN_MIPS_SCOMMON
)
1717 || (filedata
->file_header
.e_machine
== EM_TI_C6000
1718 && psym
->st_shndx
== SHN_TIC6X_SCOMMON
))
1719 sec_name
= "SCOMMON";
1720 else if (filedata
->file_header
.e_machine
== EM_MIPS
1721 && psym
->st_shndx
== SHN_MIPS_SUNDEFINED
)
1722 sec_name
= "SUNDEF";
1723 else if ((filedata
->file_header
.e_machine
== EM_X86_64
1724 || filedata
->file_header
.e_machine
== EM_L1OM
1725 || filedata
->file_header
.e_machine
== EM_K1OM
)
1726 && psym
->st_shndx
== SHN_X86_64_LCOMMON
)
1727 sec_name
= "LARGE_COMMON";
1728 else if (filedata
->file_header
.e_machine
== EM_IA_64
1729 && filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_HPUX
1730 && psym
->st_shndx
== SHN_IA_64_ANSI_COMMON
)
1731 sec_name
= "ANSI_COM";
1732 else if (is_ia64_vms (filedata
)
1733 && psym
->st_shndx
== SHN_IA_64_VMS_SYMVEC
)
1734 sec_name
= "VMS_SYMVEC";
1737 sprintf (name_buf
, "<section 0x%x>",
1738 (unsigned int) psym
->st_shndx
);
1739 sec_name
= name_buf
;
1742 print_symbol (22, sec_name
);
1744 else if (strtab
== NULL
)
1745 printf (_("<string table index: %3ld>"), psym
->st_name
);
1746 else if (psym
->st_name
>= strtablen
)
1748 error (_("<corrupt string table index: %3ld>"), psym
->st_name
);
1753 print_symbol (22, strtab
+ psym
->st_name
);
1755 printf (sym_info
== symbol_public
? "@@%s" : "@%s",
1761 bfd_vma off
= rels
[i
].r_addend
;
1763 if ((bfd_signed_vma
) off
< 0)
1764 printf (" - %" BFD_VMA_FMT
"x", - off
);
1766 printf (" + %" BFD_VMA_FMT
"x", off
);
1772 bfd_vma off
= rels
[i
].r_addend
;
1774 printf ("%*c", is_32bit_elf
? 12 : 20, ' ');
1775 if ((bfd_signed_vma
) off
< 0)
1776 printf ("-%" BFD_VMA_FMT
"x", - off
);
1778 printf ("%" BFD_VMA_FMT
"x", off
);
1781 if (filedata
->file_header
.e_machine
== EM_SPARCV9
1783 && streq (rtype
, "R_SPARC_OLO10"))
1784 printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (inf
));
1789 if (! is_32bit_elf
&& filedata
->file_header
.e_machine
== EM_MIPS
)
1791 bfd_vma type2
= ELF64_MIPS_R_TYPE2 (inf
);
1792 bfd_vma type3
= ELF64_MIPS_R_TYPE3 (inf
);
1793 const char * rtype2
= elf_mips_reloc_type (type2
);
1794 const char * rtype3
= elf_mips_reloc_type (type3
);
1796 printf (" Type2: ");
1799 printf (_("unrecognized: %-7lx"),
1800 (unsigned long) type2
& 0xffffffff);
1802 printf ("%-17.17s", rtype2
);
1804 printf ("\n Type3: ");
1807 printf (_("unrecognized: %-7lx"),
1808 (unsigned long) type3
& 0xffffffff);
1810 printf ("%-17.17s", rtype3
);
1823 get_aarch64_dynamic_type (unsigned long type
)
1827 case DT_AARCH64_BTI_PLT
: return "AARCH64_BTI_PLT";
1828 case DT_AARCH64_PAC_PLT
: return "AARCH64_PAC_PLT";
1829 case DT_AARCH64_VARIANT_PCS
: return "AARCH64_VARIANT_PCS";
1836 get_mips_dynamic_type (unsigned long type
)
1840 case DT_MIPS_RLD_VERSION
: return "MIPS_RLD_VERSION";
1841 case DT_MIPS_TIME_STAMP
: return "MIPS_TIME_STAMP";
1842 case DT_MIPS_ICHECKSUM
: return "MIPS_ICHECKSUM";
1843 case DT_MIPS_IVERSION
: return "MIPS_IVERSION";
1844 case DT_MIPS_FLAGS
: return "MIPS_FLAGS";
1845 case DT_MIPS_BASE_ADDRESS
: return "MIPS_BASE_ADDRESS";
1846 case DT_MIPS_MSYM
: return "MIPS_MSYM";
1847 case DT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
1848 case DT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
1849 case DT_MIPS_LOCAL_GOTNO
: return "MIPS_LOCAL_GOTNO";
1850 case DT_MIPS_CONFLICTNO
: return "MIPS_CONFLICTNO";
1851 case DT_MIPS_LIBLISTNO
: return "MIPS_LIBLISTNO";
1852 case DT_MIPS_SYMTABNO
: return "MIPS_SYMTABNO";
1853 case DT_MIPS_UNREFEXTNO
: return "MIPS_UNREFEXTNO";
1854 case DT_MIPS_GOTSYM
: return "MIPS_GOTSYM";
1855 case DT_MIPS_HIPAGENO
: return "MIPS_HIPAGENO";
1856 case DT_MIPS_RLD_MAP
: return "MIPS_RLD_MAP";
1857 case DT_MIPS_RLD_MAP_REL
: return "MIPS_RLD_MAP_REL";
1858 case DT_MIPS_DELTA_CLASS
: return "MIPS_DELTA_CLASS";
1859 case DT_MIPS_DELTA_CLASS_NO
: return "MIPS_DELTA_CLASS_NO";
1860 case DT_MIPS_DELTA_INSTANCE
: return "MIPS_DELTA_INSTANCE";
1861 case DT_MIPS_DELTA_INSTANCE_NO
: return "MIPS_DELTA_INSTANCE_NO";
1862 case DT_MIPS_DELTA_RELOC
: return "MIPS_DELTA_RELOC";
1863 case DT_MIPS_DELTA_RELOC_NO
: return "MIPS_DELTA_RELOC_NO";
1864 case DT_MIPS_DELTA_SYM
: return "MIPS_DELTA_SYM";
1865 case DT_MIPS_DELTA_SYM_NO
: return "MIPS_DELTA_SYM_NO";
1866 case DT_MIPS_DELTA_CLASSSYM
: return "MIPS_DELTA_CLASSSYM";
1867 case DT_MIPS_DELTA_CLASSSYM_NO
: return "MIPS_DELTA_CLASSSYM_NO";
1868 case DT_MIPS_CXX_FLAGS
: return "MIPS_CXX_FLAGS";
1869 case DT_MIPS_PIXIE_INIT
: return "MIPS_PIXIE_INIT";
1870 case DT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
1871 case DT_MIPS_LOCALPAGE_GOTIDX
: return "MIPS_LOCALPAGE_GOTIDX";
1872 case DT_MIPS_LOCAL_GOTIDX
: return "MIPS_LOCAL_GOTIDX";
1873 case DT_MIPS_HIDDEN_GOTIDX
: return "MIPS_HIDDEN_GOTIDX";
1874 case DT_MIPS_PROTECTED_GOTIDX
: return "MIPS_PROTECTED_GOTIDX";
1875 case DT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
1876 case DT_MIPS_INTERFACE
: return "MIPS_INTERFACE";
1877 case DT_MIPS_DYNSTR_ALIGN
: return "MIPS_DYNSTR_ALIGN";
1878 case DT_MIPS_INTERFACE_SIZE
: return "MIPS_INTERFACE_SIZE";
1879 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR
: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
1880 case DT_MIPS_PERF_SUFFIX
: return "MIPS_PERF_SUFFIX";
1881 case DT_MIPS_COMPACT_SIZE
: return "MIPS_COMPACT_SIZE";
1882 case DT_MIPS_GP_VALUE
: return "MIPS_GP_VALUE";
1883 case DT_MIPS_AUX_DYNAMIC
: return "MIPS_AUX_DYNAMIC";
1884 case DT_MIPS_PLTGOT
: return "MIPS_PLTGOT";
1885 case DT_MIPS_RWPLT
: return "MIPS_RWPLT";
1886 case DT_MIPS_XHASH
: return "MIPS_XHASH";
1893 get_sparc64_dynamic_type (unsigned long type
)
1897 case DT_SPARC_REGISTER
: return "SPARC_REGISTER";
1904 get_ppc_dynamic_type (unsigned long type
)
1908 case DT_PPC_GOT
: return "PPC_GOT";
1909 case DT_PPC_OPT
: return "PPC_OPT";
1916 get_ppc64_dynamic_type (unsigned long type
)
1920 case DT_PPC64_GLINK
: return "PPC64_GLINK";
1921 case DT_PPC64_OPD
: return "PPC64_OPD";
1922 case DT_PPC64_OPDSZ
: return "PPC64_OPDSZ";
1923 case DT_PPC64_OPT
: return "PPC64_OPT";
1930 get_parisc_dynamic_type (unsigned long type
)
1934 case DT_HP_LOAD_MAP
: return "HP_LOAD_MAP";
1935 case DT_HP_DLD_FLAGS
: return "HP_DLD_FLAGS";
1936 case DT_HP_DLD_HOOK
: return "HP_DLD_HOOK";
1937 case DT_HP_UX10_INIT
: return "HP_UX10_INIT";
1938 case DT_HP_UX10_INITSZ
: return "HP_UX10_INITSZ";
1939 case DT_HP_PREINIT
: return "HP_PREINIT";
1940 case DT_HP_PREINITSZ
: return "HP_PREINITSZ";
1941 case DT_HP_NEEDED
: return "HP_NEEDED";
1942 case DT_HP_TIME_STAMP
: return "HP_TIME_STAMP";
1943 case DT_HP_CHECKSUM
: return "HP_CHECKSUM";
1944 case DT_HP_GST_SIZE
: return "HP_GST_SIZE";
1945 case DT_HP_GST_VERSION
: return "HP_GST_VERSION";
1946 case DT_HP_GST_HASHVAL
: return "HP_GST_HASHVAL";
1947 case DT_HP_EPLTREL
: return "HP_GST_EPLTREL";
1948 case DT_HP_EPLTRELSZ
: return "HP_GST_EPLTRELSZ";
1949 case DT_HP_FILTERED
: return "HP_FILTERED";
1950 case DT_HP_FILTER_TLS
: return "HP_FILTER_TLS";
1951 case DT_HP_COMPAT_FILTERED
: return "HP_COMPAT_FILTERED";
1952 case DT_HP_LAZYLOAD
: return "HP_LAZYLOAD";
1953 case DT_HP_BIND_NOW_COUNT
: return "HP_BIND_NOW_COUNT";
1954 case DT_PLT
: return "PLT";
1955 case DT_PLT_SIZE
: return "PLT_SIZE";
1956 case DT_DLT
: return "DLT";
1957 case DT_DLT_SIZE
: return "DLT_SIZE";
1964 get_ia64_dynamic_type (unsigned long type
)
1968 case DT_IA_64_PLT_RESERVE
: return "IA_64_PLT_RESERVE";
1969 case DT_IA_64_VMS_SUBTYPE
: return "VMS_SUBTYPE";
1970 case DT_IA_64_VMS_IMGIOCNT
: return "VMS_IMGIOCNT";
1971 case DT_IA_64_VMS_LNKFLAGS
: return "VMS_LNKFLAGS";
1972 case DT_IA_64_VMS_VIR_MEM_BLK_SIZ
: return "VMS_VIR_MEM_BLK_SIZ";
1973 case DT_IA_64_VMS_IDENT
: return "VMS_IDENT";
1974 case DT_IA_64_VMS_NEEDED_IDENT
: return "VMS_NEEDED_IDENT";
1975 case DT_IA_64_VMS_IMG_RELA_CNT
: return "VMS_IMG_RELA_CNT";
1976 case DT_IA_64_VMS_SEG_RELA_CNT
: return "VMS_SEG_RELA_CNT";
1977 case DT_IA_64_VMS_FIXUP_RELA_CNT
: return "VMS_FIXUP_RELA_CNT";
1978 case DT_IA_64_VMS_FIXUP_NEEDED
: return "VMS_FIXUP_NEEDED";
1979 case DT_IA_64_VMS_SYMVEC_CNT
: return "VMS_SYMVEC_CNT";
1980 case DT_IA_64_VMS_XLATED
: return "VMS_XLATED";
1981 case DT_IA_64_VMS_STACKSIZE
: return "VMS_STACKSIZE";
1982 case DT_IA_64_VMS_UNWINDSZ
: return "VMS_UNWINDSZ";
1983 case DT_IA_64_VMS_UNWIND_CODSEG
: return "VMS_UNWIND_CODSEG";
1984 case DT_IA_64_VMS_UNWIND_INFOSEG
: return "VMS_UNWIND_INFOSEG";
1985 case DT_IA_64_VMS_LINKTIME
: return "VMS_LINKTIME";
1986 case DT_IA_64_VMS_SEG_NO
: return "VMS_SEG_NO";
1987 case DT_IA_64_VMS_SYMVEC_OFFSET
: return "VMS_SYMVEC_OFFSET";
1988 case DT_IA_64_VMS_SYMVEC_SEG
: return "VMS_SYMVEC_SEG";
1989 case DT_IA_64_VMS_UNWIND_OFFSET
: return "VMS_UNWIND_OFFSET";
1990 case DT_IA_64_VMS_UNWIND_SEG
: return "VMS_UNWIND_SEG";
1991 case DT_IA_64_VMS_STRTAB_OFFSET
: return "VMS_STRTAB_OFFSET";
1992 case DT_IA_64_VMS_SYSVER_OFFSET
: return "VMS_SYSVER_OFFSET";
1993 case DT_IA_64_VMS_IMG_RELA_OFF
: return "VMS_IMG_RELA_OFF";
1994 case DT_IA_64_VMS_SEG_RELA_OFF
: return "VMS_SEG_RELA_OFF";
1995 case DT_IA_64_VMS_FIXUP_RELA_OFF
: return "VMS_FIXUP_RELA_OFF";
1996 case DT_IA_64_VMS_PLTGOT_OFFSET
: return "VMS_PLTGOT_OFFSET";
1997 case DT_IA_64_VMS_PLTGOT_SEG
: return "VMS_PLTGOT_SEG";
1998 case DT_IA_64_VMS_FPMODE
: return "VMS_FPMODE";
2005 get_solaris_section_type (unsigned long type
)
2009 case 0x6fffffee: return "SUNW_ancillary";
2010 case 0x6fffffef: return "SUNW_capchain";
2011 case 0x6ffffff0: return "SUNW_capinfo";
2012 case 0x6ffffff1: return "SUNW_symsort";
2013 case 0x6ffffff2: return "SUNW_tlssort";
2014 case 0x6ffffff3: return "SUNW_LDYNSYM";
2015 case 0x6ffffff4: return "SUNW_dof";
2016 case 0x6ffffff5: return "SUNW_cap";
2017 case 0x6ffffff6: return "SUNW_SIGNATURE";
2018 case 0x6ffffff7: return "SUNW_ANNOTATE";
2019 case 0x6ffffff8: return "SUNW_DEBUGSTR";
2020 case 0x6ffffff9: return "SUNW_DEBUG";
2021 case 0x6ffffffa: return "SUNW_move";
2022 case 0x6ffffffb: return "SUNW_COMDAT";
2023 case 0x6ffffffc: return "SUNW_syminfo";
2024 case 0x6ffffffd: return "SUNW_verdef";
2025 case 0x6ffffffe: return "SUNW_verneed";
2026 case 0x6fffffff: return "SUNW_versym";
2027 case 0x70000000: return "SPARC_GOTDATA";
2028 default: return NULL
;
2033 get_alpha_dynamic_type (unsigned long type
)
2037 case DT_ALPHA_PLTRO
: return "ALPHA_PLTRO";
2038 default: return NULL
;
2043 get_score_dynamic_type (unsigned long type
)
2047 case DT_SCORE_BASE_ADDRESS
: return "SCORE_BASE_ADDRESS";
2048 case DT_SCORE_LOCAL_GOTNO
: return "SCORE_LOCAL_GOTNO";
2049 case DT_SCORE_SYMTABNO
: return "SCORE_SYMTABNO";
2050 case DT_SCORE_GOTSYM
: return "SCORE_GOTSYM";
2051 case DT_SCORE_UNREFEXTNO
: return "SCORE_UNREFEXTNO";
2052 case DT_SCORE_HIPAGENO
: return "SCORE_HIPAGENO";
2053 default: return NULL
;
2058 get_tic6x_dynamic_type (unsigned long type
)
2062 case DT_C6000_GSYM_OFFSET
: return "C6000_GSYM_OFFSET";
2063 case DT_C6000_GSTR_OFFSET
: return "C6000_GSTR_OFFSET";
2064 case DT_C6000_DSBT_BASE
: return "C6000_DSBT_BASE";
2065 case DT_C6000_DSBT_SIZE
: return "C6000_DSBT_SIZE";
2066 case DT_C6000_PREEMPTMAP
: return "C6000_PREEMPTMAP";
2067 case DT_C6000_DSBT_INDEX
: return "C6000_DSBT_INDEX";
2068 default: return NULL
;
2073 get_nios2_dynamic_type (unsigned long type
)
2077 case DT_NIOS2_GP
: return "NIOS2_GP";
2078 default: return NULL
;
2083 get_solaris_dynamic_type (unsigned long type
)
2087 case 0x6000000d: return "SUNW_AUXILIARY";
2088 case 0x6000000e: return "SUNW_RTLDINF";
2089 case 0x6000000f: return "SUNW_FILTER";
2090 case 0x60000010: return "SUNW_CAP";
2091 case 0x60000011: return "SUNW_SYMTAB";
2092 case 0x60000012: return "SUNW_SYMSZ";
2093 case 0x60000013: return "SUNW_SORTENT";
2094 case 0x60000014: return "SUNW_SYMSORT";
2095 case 0x60000015: return "SUNW_SYMSORTSZ";
2096 case 0x60000016: return "SUNW_TLSSORT";
2097 case 0x60000017: return "SUNW_TLSSORTSZ";
2098 case 0x60000018: return "SUNW_CAPINFO";
2099 case 0x60000019: return "SUNW_STRPAD";
2100 case 0x6000001a: return "SUNW_CAPCHAIN";
2101 case 0x6000001b: return "SUNW_LDMACH";
2102 case 0x6000001d: return "SUNW_CAPCHAINENT";
2103 case 0x6000001f: return "SUNW_CAPCHAINSZ";
2104 case 0x60000021: return "SUNW_PARENT";
2105 case 0x60000023: return "SUNW_ASLR";
2106 case 0x60000025: return "SUNW_RELAX";
2107 case 0x60000029: return "SUNW_NXHEAP";
2108 case 0x6000002b: return "SUNW_NXSTACK";
2110 case 0x70000001: return "SPARC_REGISTER";
2111 case 0x7ffffffd: return "AUXILIARY";
2112 case 0x7ffffffe: return "USED";
2113 case 0x7fffffff: return "FILTER";
2115 default: return NULL
;
2120 get_dynamic_type (Filedata
* filedata
, unsigned long type
)
2122 static char buff
[64];
2126 case DT_NULL
: return "NULL";
2127 case DT_NEEDED
: return "NEEDED";
2128 case DT_PLTRELSZ
: return "PLTRELSZ";
2129 case DT_PLTGOT
: return "PLTGOT";
2130 case DT_HASH
: return "HASH";
2131 case DT_STRTAB
: return "STRTAB";
2132 case DT_SYMTAB
: return "SYMTAB";
2133 case DT_RELA
: return "RELA";
2134 case DT_RELASZ
: return "RELASZ";
2135 case DT_RELAENT
: return "RELAENT";
2136 case DT_STRSZ
: return "STRSZ";
2137 case DT_SYMENT
: return "SYMENT";
2138 case DT_INIT
: return "INIT";
2139 case DT_FINI
: return "FINI";
2140 case DT_SONAME
: return "SONAME";
2141 case DT_RPATH
: return "RPATH";
2142 case DT_SYMBOLIC
: return "SYMBOLIC";
2143 case DT_REL
: return "REL";
2144 case DT_RELSZ
: return "RELSZ";
2145 case DT_RELENT
: return "RELENT";
2146 case DT_PLTREL
: return "PLTREL";
2147 case DT_DEBUG
: return "DEBUG";
2148 case DT_TEXTREL
: return "TEXTREL";
2149 case DT_JMPREL
: return "JMPREL";
2150 case DT_BIND_NOW
: return "BIND_NOW";
2151 case DT_INIT_ARRAY
: return "INIT_ARRAY";
2152 case DT_FINI_ARRAY
: return "FINI_ARRAY";
2153 case DT_INIT_ARRAYSZ
: return "INIT_ARRAYSZ";
2154 case DT_FINI_ARRAYSZ
: return "FINI_ARRAYSZ";
2155 case DT_RUNPATH
: return "RUNPATH";
2156 case DT_FLAGS
: return "FLAGS";
2158 case DT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
2159 case DT_PREINIT_ARRAYSZ
: return "PREINIT_ARRAYSZ";
2160 case DT_SYMTAB_SHNDX
: return "SYMTAB_SHNDX";
2162 case DT_CHECKSUM
: return "CHECKSUM";
2163 case DT_PLTPADSZ
: return "PLTPADSZ";
2164 case DT_MOVEENT
: return "MOVEENT";
2165 case DT_MOVESZ
: return "MOVESZ";
2166 case DT_FEATURE
: return "FEATURE";
2167 case DT_POSFLAG_1
: return "POSFLAG_1";
2168 case DT_SYMINSZ
: return "SYMINSZ";
2169 case DT_SYMINENT
: return "SYMINENT"; /* aka VALRNGHI */
2171 case DT_ADDRRNGLO
: return "ADDRRNGLO";
2172 case DT_CONFIG
: return "CONFIG";
2173 case DT_DEPAUDIT
: return "DEPAUDIT";
2174 case DT_AUDIT
: return "AUDIT";
2175 case DT_PLTPAD
: return "PLTPAD";
2176 case DT_MOVETAB
: return "MOVETAB";
2177 case DT_SYMINFO
: return "SYMINFO"; /* aka ADDRRNGHI */
2179 case DT_VERSYM
: return "VERSYM";
2181 case DT_TLSDESC_GOT
: return "TLSDESC_GOT";
2182 case DT_TLSDESC_PLT
: return "TLSDESC_PLT";
2183 case DT_RELACOUNT
: return "RELACOUNT";
2184 case DT_RELCOUNT
: return "RELCOUNT";
2185 case DT_FLAGS_1
: return "FLAGS_1";
2186 case DT_VERDEF
: return "VERDEF";
2187 case DT_VERDEFNUM
: return "VERDEFNUM";
2188 case DT_VERNEED
: return "VERNEED";
2189 case DT_VERNEEDNUM
: return "VERNEEDNUM";
2191 case DT_AUXILIARY
: return "AUXILIARY";
2192 case DT_USED
: return "USED";
2193 case DT_FILTER
: return "FILTER";
2195 case DT_GNU_PRELINKED
: return "GNU_PRELINKED";
2196 case DT_GNU_CONFLICT
: return "GNU_CONFLICT";
2197 case DT_GNU_CONFLICTSZ
: return "GNU_CONFLICTSZ";
2198 case DT_GNU_LIBLIST
: return "GNU_LIBLIST";
2199 case DT_GNU_LIBLISTSZ
: return "GNU_LIBLISTSZ";
2200 case DT_GNU_HASH
: return "GNU_HASH";
2203 if ((type
>= DT_LOPROC
) && (type
<= DT_HIPROC
))
2205 const char * result
;
2207 switch (filedata
->file_header
.e_machine
)
2210 result
= get_aarch64_dynamic_type (type
);
2213 case EM_MIPS_RS3_LE
:
2214 result
= get_mips_dynamic_type (type
);
2217 result
= get_sparc64_dynamic_type (type
);
2220 result
= get_ppc_dynamic_type (type
);
2223 result
= get_ppc64_dynamic_type (type
);
2226 result
= get_ia64_dynamic_type (type
);
2229 result
= get_alpha_dynamic_type (type
);
2232 result
= get_score_dynamic_type (type
);
2235 result
= get_tic6x_dynamic_type (type
);
2237 case EM_ALTERA_NIOS2
:
2238 result
= get_nios2_dynamic_type (type
);
2241 if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_SOLARIS
)
2242 result
= get_solaris_dynamic_type (type
);
2251 snprintf (buff
, sizeof (buff
), _("Processor Specific: %lx"), type
);
2253 else if (((type
>= DT_LOOS
) && (type
<= DT_HIOS
))
2254 || (filedata
->file_header
.e_machine
== EM_PARISC
2255 && (type
>= OLD_DT_LOOS
) && (type
<= OLD_DT_HIOS
)))
2257 const char * result
;
2259 switch (filedata
->file_header
.e_machine
)
2262 result
= get_parisc_dynamic_type (type
);
2265 result
= get_ia64_dynamic_type (type
);
2268 if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_SOLARIS
)
2269 result
= get_solaris_dynamic_type (type
);
2278 snprintf (buff
, sizeof (buff
), _("Operating System specific: %lx"),
2282 snprintf (buff
, sizeof (buff
), _("<unknown>: %lx"), type
);
2289 get_file_type (unsigned e_type
)
2291 static char buff
[32];
2295 case ET_NONE
: return _("NONE (None)");
2296 case ET_REL
: return _("REL (Relocatable file)");
2297 case ET_EXEC
: return _("EXEC (Executable file)");
2298 case ET_DYN
: return _("DYN (Shared object file)");
2299 case ET_CORE
: return _("CORE (Core file)");
2302 if ((e_type
>= ET_LOPROC
) && (e_type
<= ET_HIPROC
))
2303 snprintf (buff
, sizeof (buff
), _("Processor Specific: (%x)"), e_type
);
2304 else if ((e_type
>= ET_LOOS
) && (e_type
<= ET_HIOS
))
2305 snprintf (buff
, sizeof (buff
), _("OS Specific: (%x)"), e_type
);
2307 snprintf (buff
, sizeof (buff
), _("<unknown>: %x"), e_type
);
2313 get_machine_name (unsigned e_machine
)
2315 static char buff
[64]; /* XXX */
2319 /* Please keep this switch table sorted by increasing EM_ value. */
2321 case EM_NONE
: return _("None");
2322 case EM_M32
: return "WE32100";
2323 case EM_SPARC
: return "Sparc";
2324 case EM_386
: return "Intel 80386";
2325 case EM_68K
: return "MC68000";
2326 case EM_88K
: return "MC88000";
2327 case EM_IAMCU
: return "Intel MCU";
2328 case EM_860
: return "Intel 80860";
2329 case EM_MIPS
: return "MIPS R3000";
2330 case EM_S370
: return "IBM System/370";
2332 case EM_MIPS_RS3_LE
: return "MIPS R4000 big-endian";
2333 case EM_OLD_SPARCV9
: return "Sparc v9 (old)";
2334 case EM_PARISC
: return "HPPA";
2335 case EM_VPP550
: return "Fujitsu VPP500";
2336 case EM_SPARC32PLUS
: return "Sparc v8+" ;
2337 case EM_960
: return "Intel 80960";
2338 case EM_PPC
: return "PowerPC";
2340 case EM_PPC64
: return "PowerPC64";
2342 case EM_S390
: return "IBM S/390";
2343 case EM_SPU
: return "SPU";
2345 case EM_V800
: return "Renesas V850 (using RH850 ABI)";
2346 case EM_FR20
: return "Fujitsu FR20";
2347 case EM_RH32
: return "TRW RH32";
2348 case EM_MCORE
: return "MCORE";
2350 case EM_ARM
: return "ARM";
2351 case EM_OLD_ALPHA
: return "Digital Alpha (old)";
2352 case EM_SH
: return "Renesas / SuperH SH";
2353 case EM_SPARCV9
: return "Sparc v9";
2354 case EM_TRICORE
: return "Siemens Tricore";
2355 case EM_ARC
: return "ARC";
2356 case EM_H8_300
: return "Renesas H8/300";
2357 case EM_H8_300H
: return "Renesas H8/300H";
2358 case EM_H8S
: return "Renesas H8S";
2359 case EM_H8_500
: return "Renesas H8/500";
2361 case EM_IA_64
: return "Intel IA-64";
2362 case EM_MIPS_X
: return "Stanford MIPS-X";
2363 case EM_COLDFIRE
: return "Motorola Coldfire";
2364 case EM_68HC12
: return "Motorola MC68HC12 Microcontroller";
2365 case EM_MMA
: return "Fujitsu Multimedia Accelerator";
2366 case EM_PCP
: return "Siemens PCP";
2367 case EM_NCPU
: return "Sony nCPU embedded RISC processor";
2368 case EM_NDR1
: return "Denso NDR1 microprocesspr";
2369 case EM_STARCORE
: return "Motorola Star*Core processor";
2370 case EM_ME16
: return "Toyota ME16 processor";
2372 case EM_ST100
: return "STMicroelectronics ST100 processor";
2373 case EM_TINYJ
: return "Advanced Logic Corp. TinyJ embedded processor";
2374 case EM_X86_64
: return "Advanced Micro Devices X86-64";
2375 case EM_PDSP
: return "Sony DSP processor";
2376 case EM_PDP10
: return "Digital Equipment Corp. PDP-10";
2377 case EM_PDP11
: return "Digital Equipment Corp. PDP-11";
2378 case EM_FX66
: return "Siemens FX66 microcontroller";
2379 case EM_ST9PLUS
: return "STMicroelectronics ST9+ 8/16 bit microcontroller";
2380 case EM_ST7
: return "STMicroelectronics ST7 8-bit microcontroller";
2381 case EM_68HC16
: return "Motorola MC68HC16 Microcontroller";
2383 case EM_68HC11
: return "Motorola MC68HC11 Microcontroller";
2384 case EM_68HC08
: return "Motorola MC68HC08 Microcontroller";
2385 case EM_68HC05
: return "Motorola MC68HC05 Microcontroller";
2386 case EM_SVX
: return "Silicon Graphics SVx";
2387 case EM_ST19
: return "STMicroelectronics ST19 8-bit microcontroller";
2388 case EM_VAX
: return "Digital VAX";
2389 case EM_CRIS
: return "Axis Communications 32-bit embedded processor";
2390 case EM_JAVELIN
: return "Infineon Technologies 32-bit embedded cpu";
2391 case EM_FIREPATH
: return "Element 14 64-bit DSP processor";
2392 case EM_ZSP
: return "LSI Logic's 16-bit DSP processor";
2394 case EM_MMIX
: return "Donald Knuth's educational 64-bit processor";
2395 case EM_HUANY
: return "Harvard Universitys's machine-independent object format";
2396 case EM_PRISM
: return "Vitesse Prism";
2398 case EM_AVR
: return "Atmel AVR 8-bit microcontroller";
2399 case EM_CYGNUS_FR30
:
2400 case EM_FR30
: return "Fujitsu FR30";
2401 case EM_CYGNUS_D10V
:
2402 case EM_D10V
: return "d10v";
2403 case EM_CYGNUS_D30V
:
2404 case EM_D30V
: return "d30v";
2405 case EM_CYGNUS_V850
:
2406 case EM_V850
: return "Renesas V850";
2407 case EM_CYGNUS_M32R
:
2408 case EM_M32R
: return "Renesas M32R (formerly Mitsubishi M32r)";
2409 case EM_CYGNUS_MN10300
:
2410 case EM_MN10300
: return "mn10300";
2412 case EM_CYGNUS_MN10200
:
2413 case EM_MN10200
: return "mn10200";
2414 case EM_PJ
: return "picoJava";
2415 case EM_OR1K
: return "OpenRISC 1000";
2416 case EM_ARC_COMPACT
: return "ARCompact";
2418 case EM_XTENSA
: return "Tensilica Xtensa Processor";
2419 case EM_VIDEOCORE
: return "Alphamosaic VideoCore processor";
2420 case EM_TMM_GPP
: return "Thompson Multimedia General Purpose Processor";
2421 case EM_NS32K
: return "National Semiconductor 32000 series";
2422 case EM_TPC
: return "Tenor Network TPC processor";
2423 case EM_SNP1K
: return "Trebia SNP 1000 processor";
2425 case EM_ST200
: return "STMicroelectronics ST200 microcontroller";
2427 case EM_IP2K
: return "Ubicom IP2xxx 8-bit microcontrollers";
2428 case EM_MAX
: return "MAX Processor";
2429 case EM_CR
: return "National Semiconductor CompactRISC";
2430 case EM_F2MC16
: return "Fujitsu F2MC16";
2431 case EM_MSP430
: return "Texas Instruments msp430 microcontroller";
2432 case EM_BLACKFIN
: return "Analog Devices Blackfin";
2433 case EM_SE_C33
: return "S1C33 Family of Seiko Epson processors";
2434 case EM_SEP
: return "Sharp embedded microprocessor";
2435 case EM_ARCA
: return "Arca RISC microprocessor";
2437 case EM_UNICORE
: return "Unicore";
2438 case EM_EXCESS
: return "eXcess 16/32/64-bit configurable embedded CPU";
2439 case EM_DXP
: return "Icera Semiconductor Inc. Deep Execution Processor";
2440 case EM_ALTERA_NIOS2
: return "Altera Nios II";
2441 case EM_CRX
: return "National Semiconductor CRX microprocessor";
2442 case EM_XGATE
: return "Motorola XGATE embedded processor";
2444 case EM_XC16X
: return "Infineon Technologies xc16x";
2445 case EM_M16C
: return "Renesas M16C series microprocessors";
2446 case EM_DSPIC30F
: return "Microchip Technology dsPIC30F Digital Signal Controller";
2447 case EM_CE
: return "Freescale Communication Engine RISC core";
2449 case EM_M32C
: return "Renesas M32c";
2451 case EM_TSK3000
: return "Altium TSK3000 core";
2452 case EM_RS08
: return "Freescale RS08 embedded processor";
2453 case EM_ECOG2
: return "Cyan Technology eCOG2 microprocessor";
2454 case EM_SCORE
: return "SUNPLUS S+Core";
2455 case EM_DSP24
: return "New Japan Radio (NJR) 24-bit DSP Processor";
2456 case EM_VIDEOCORE3
: return "Broadcom VideoCore III processor";
2457 case EM_LATTICEMICO32
: return "Lattice Mico32";
2458 case EM_SE_C17
: return "Seiko Epson C17 family";
2460 case EM_TI_C6000
: return "Texas Instruments TMS320C6000 DSP family";
2461 case EM_TI_C2000
: return "Texas Instruments TMS320C2000 DSP family";
2462 case EM_TI_C5500
: return "Texas Instruments TMS320C55x DSP family";
2463 case EM_TI_PRU
: return "TI PRU I/O processor";
2465 case EM_MMDSP_PLUS
: return "STMicroelectronics 64bit VLIW Data Signal Processor";
2466 case EM_CYPRESS_M8C
: return "Cypress M8C microprocessor";
2467 case EM_R32C
: return "Renesas R32C series microprocessors";
2468 case EM_TRIMEDIA
: return "NXP Semiconductors TriMedia architecture family";
2469 case EM_QDSP6
: return "QUALCOMM DSP6 Processor";
2470 case EM_8051
: return "Intel 8051 and variants";
2471 case EM_STXP7X
: return "STMicroelectronics STxP7x family";
2472 case EM_NDS32
: return "Andes Technology compact code size embedded RISC processor family";
2473 case EM_ECOG1X
: return "Cyan Technology eCOG1X family";
2474 case EM_MAXQ30
: return "Dallas Semiconductor MAXQ30 Core microcontrollers";
2476 case EM_XIMO16
: return "New Japan Radio (NJR) 16-bit DSP Processor";
2477 case EM_MANIK
: return "M2000 Reconfigurable RISC Microprocessor";
2478 case EM_CRAYNV2
: return "Cray Inc. NV2 vector architecture";
2479 case EM_RX
: return "Renesas RX";
2480 case EM_METAG
: return "Imagination Technologies Meta processor architecture";
2481 case EM_MCST_ELBRUS
: return "MCST Elbrus general purpose hardware architecture";
2482 case EM_ECOG16
: return "Cyan Technology eCOG16 family";
2485 case EM_MICROBLAZE_OLD
: return "Xilinx MicroBlaze";
2486 case EM_ETPU
: return "Freescale Extended Time Processing Unit";
2487 case EM_SLE9X
: return "Infineon Technologies SLE9X core";
2489 case EM_L1OM
: return "Intel L1OM";
2490 case EM_K1OM
: return "Intel K1OM";
2491 case EM_INTEL182
: return "Intel (reserved)";
2492 case EM_AARCH64
: return "AArch64";
2493 case EM_ARM184
: return "ARM (reserved)";
2494 case EM_AVR32
: return "Atmel Corporation 32-bit microprocessor";
2495 case EM_STM8
: return "STMicroeletronics STM8 8-bit microcontroller";
2496 case EM_TILE64
: return "Tilera TILE64 multicore architecture family";
2497 case EM_TILEPRO
: return "Tilera TILEPro multicore architecture family";
2499 case EM_CUDA
: return "NVIDIA CUDA architecture";
2500 case EM_TILEGX
: return "Tilera TILE-Gx multicore architecture family";
2501 case EM_CLOUDSHIELD
: return "CloudShield architecture family";
2502 case EM_COREA_1ST
: return "KIPO-KAIST Core-A 1st generation processor family";
2503 case EM_COREA_2ND
: return "KIPO-KAIST Core-A 2nd generation processor family";
2504 case EM_ARC_COMPACT2
: return "ARCv2";
2505 case EM_OPEN8
: return "Open8 8-bit RISC soft processor core";
2506 case EM_RL78
: return "Renesas RL78";
2507 case EM_VIDEOCORE5
: return "Broadcom VideoCore V processor";
2508 case EM_78K0R
: return "Renesas 78K0R";
2510 case EM_56800EX
: return "Freescale 56800EX Digital Signal Controller (DSC)";
2511 case EM_BA1
: return "Beyond BA1 CPU architecture";
2512 case EM_BA2
: return "Beyond BA2 CPU architecture";
2513 case EM_XCORE
: return "XMOS xCORE processor family";
2514 case EM_MCHP_PIC
: return "Microchip 8-bit PIC(r) family";
2516 case EM_KM32
: return "KM211 KM32 32-bit processor";
2517 case EM_KMX32
: return "KM211 KMX32 32-bit processor";
2518 case EM_KMX16
: return "KM211 KMX16 16-bit processor";
2519 case EM_KMX8
: return "KM211 KMX8 8-bit processor";
2520 case EM_KVARC
: return "KM211 KVARC processor";
2521 case EM_CDP
: return "Paneve CDP architecture family";
2522 case EM_COGE
: return "Cognitive Smart Memory Processor";
2523 case EM_COOL
: return "Bluechip Systems CoolEngine";
2524 case EM_NORC
: return "Nanoradio Optimized RISC";
2525 case EM_CSR_KALIMBA
: return "CSR Kalimba architecture family";
2527 case EM_Z80
: return "Zilog Z80";
2528 case EM_VISIUM
: return "CDS VISIUMcore processor";
2529 case EM_FT32
: return "FTDI Chip FT32";
2530 case EM_MOXIE
: return "Moxie";
2531 case EM_AMDGPU
: return "AMD GPU";
2532 case EM_RISCV
: return "RISC-V";
2533 case EM_LANAI
: return "Lanai 32-bit processor";
2534 case EM_BPF
: return "Linux BPF";
2535 case EM_NFP
: return "Netronome Flow Processor";
2537 /* Large numbers... */
2538 case EM_MT
: return "Morpho Techologies MT processor";
2539 case EM_ALPHA
: return "Alpha";
2540 case EM_WEBASSEMBLY
: return "Web Assembly";
2541 case EM_DLX
: return "OpenDLX";
2542 case EM_XSTORMY16
: return "Sanyo XStormy16 CPU core";
2543 case EM_IQ2000
: return "Vitesse IQ2000";
2545 case EM_NIOS32
: return "Altera Nios";
2546 case EM_CYGNUS_MEP
: return "Toshiba MeP Media Engine";
2547 case EM_ADAPTEVA_EPIPHANY
: return "Adapteva EPIPHANY";
2548 case EM_CYGNUS_FRV
: return "Fujitsu FR-V";
2549 case EM_S12Z
: return "Freescale S12Z";
2550 case EM_CSKY
: return "C-SKY";
2553 snprintf (buff
, sizeof (buff
), _("<unknown>: 0x%x"), e_machine
);
2559 decode_ARC_machine_flags (unsigned e_flags
, unsigned e_machine
, char buf
[])
2561 /* ARC has two machine types EM_ARC_COMPACT and EM_ARC_COMPACT2. Some
2562 other compilers don't a specific architecture type in the e_flags, and
2563 instead use EM_ARC_COMPACT for old ARC600, ARC601, and ARC700
2564 architectures, and switch to EM_ARC_COMPACT2 for newer ARCEM and ARCHS
2567 Th GNU tools follows this use of EM_ARC_COMPACT and EM_ARC_COMPACT2,
2568 but also sets a specific architecture type in the e_flags field.
2570 However, when decoding the flags we don't worry if we see an
2571 unexpected pairing, for example EM_ARC_COMPACT machine type, with
2572 ARCEM architecture type. */
2574 switch (e_flags
& EF_ARC_MACH_MSK
)
2576 /* We only expect these to occur for EM_ARC_COMPACT2. */
2577 case EF_ARC_CPU_ARCV2EM
:
2578 strcat (buf
, ", ARC EM");
2580 case EF_ARC_CPU_ARCV2HS
:
2581 strcat (buf
, ", ARC HS");
2584 /* We only expect these to occur for EM_ARC_COMPACT. */
2585 case E_ARC_MACH_ARC600
:
2586 strcat (buf
, ", ARC600");
2588 case E_ARC_MACH_ARC601
:
2589 strcat (buf
, ", ARC601");
2591 case E_ARC_MACH_ARC700
:
2592 strcat (buf
, ", ARC700");
2595 /* The only times we should end up here are (a) A corrupt ELF, (b) A
2596 new ELF with new architecture being read by an old version of
2597 readelf, or (c) An ELF built with non-GNU compiler that does not
2598 set the architecture in the e_flags. */
2600 if (e_machine
== EM_ARC_COMPACT
)
2601 strcat (buf
, ", Unknown ARCompact");
2603 strcat (buf
, ", Unknown ARC");
2607 switch (e_flags
& EF_ARC_OSABI_MSK
)
2609 case E_ARC_OSABI_ORIG
:
2610 strcat (buf
, ", (ABI:legacy)");
2612 case E_ARC_OSABI_V2
:
2613 strcat (buf
, ", (ABI:v2)");
2615 /* Only upstream 3.9+ kernels will support ARCv2 ISA. */
2616 case E_ARC_OSABI_V3
:
2617 strcat (buf
, ", v3 no-legacy-syscalls ABI");
2619 case E_ARC_OSABI_V4
:
2620 strcat (buf
, ", v4 ABI");
2623 strcat (buf
, ", unrecognised ARC OSABI flag");
2629 decode_ARM_machine_flags (unsigned e_flags
, char buf
[])
2632 bfd_boolean unknown
= FALSE
;
2634 eabi
= EF_ARM_EABI_VERSION (e_flags
);
2635 e_flags
&= ~ EF_ARM_EABIMASK
;
2637 /* Handle "generic" ARM flags. */
2638 if (e_flags
& EF_ARM_RELEXEC
)
2640 strcat (buf
, ", relocatable executable");
2641 e_flags
&= ~ EF_ARM_RELEXEC
;
2644 if (e_flags
& EF_ARM_PIC
)
2646 strcat (buf
, ", position independent");
2647 e_flags
&= ~ EF_ARM_PIC
;
2650 /* Now handle EABI specific flags. */
2654 strcat (buf
, ", <unrecognized EABI>");
2659 case EF_ARM_EABI_VER1
:
2660 strcat (buf
, ", Version1 EABI");
2665 /* Process flags one bit at a time. */
2666 flag
= e_flags
& - e_flags
;
2671 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
2672 strcat (buf
, ", sorted symbol tables");
2682 case EF_ARM_EABI_VER2
:
2683 strcat (buf
, ", Version2 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");
2698 case EF_ARM_DYNSYMSUSESEGIDX
:
2699 strcat (buf
, ", dynamic symbols use segment index");
2702 case EF_ARM_MAPSYMSFIRST
:
2703 strcat (buf
, ", mapping symbols precede others");
2713 case EF_ARM_EABI_VER3
:
2714 strcat (buf
, ", Version3 EABI");
2717 case EF_ARM_EABI_VER4
:
2718 strcat (buf
, ", Version4 EABI");
2723 /* Process flags one bit at a time. */
2724 flag
= e_flags
& - e_flags
;
2730 strcat (buf
, ", BE8");
2734 strcat (buf
, ", LE8");
2744 case EF_ARM_EABI_VER5
:
2745 strcat (buf
, ", Version5 EABI");
2750 /* Process flags one bit at a time. */
2751 flag
= e_flags
& - e_flags
;
2757 strcat (buf
, ", BE8");
2761 strcat (buf
, ", LE8");
2764 case EF_ARM_ABI_FLOAT_SOFT
: /* Conflicts with EF_ARM_SOFT_FLOAT. */
2765 strcat (buf
, ", soft-float ABI");
2768 case EF_ARM_ABI_FLOAT_HARD
: /* Conflicts with EF_ARM_VFP_FLOAT. */
2769 strcat (buf
, ", hard-float ABI");
2779 case EF_ARM_EABI_UNKNOWN
:
2780 strcat (buf
, ", GNU EABI");
2785 /* Process flags one bit at a time. */
2786 flag
= e_flags
& - e_flags
;
2791 case EF_ARM_INTERWORK
:
2792 strcat (buf
, ", interworking enabled");
2795 case EF_ARM_APCS_26
:
2796 strcat (buf
, ", uses APCS/26");
2799 case EF_ARM_APCS_FLOAT
:
2800 strcat (buf
, ", uses APCS/float");
2804 strcat (buf
, ", position independent");
2808 strcat (buf
, ", 8 bit structure alignment");
2811 case EF_ARM_NEW_ABI
:
2812 strcat (buf
, ", uses new ABI");
2815 case EF_ARM_OLD_ABI
:
2816 strcat (buf
, ", uses old ABI");
2819 case EF_ARM_SOFT_FLOAT
:
2820 strcat (buf
, ", software FP");
2823 case EF_ARM_VFP_FLOAT
:
2824 strcat (buf
, ", VFP");
2827 case EF_ARM_MAVERICK_FLOAT
:
2828 strcat (buf
, ", Maverick FP");
2839 strcat (buf
,_(", <unknown>"));
2843 decode_AVR_machine_flags (unsigned e_flags
, char buf
[], size_t size
)
2845 --size
; /* Leave space for null terminator. */
2847 switch (e_flags
& EF_AVR_MACH
)
2849 case E_AVR_MACH_AVR1
:
2850 strncat (buf
, ", avr:1", size
);
2852 case E_AVR_MACH_AVR2
:
2853 strncat (buf
, ", avr:2", size
);
2855 case E_AVR_MACH_AVR25
:
2856 strncat (buf
, ", avr:25", size
);
2858 case E_AVR_MACH_AVR3
:
2859 strncat (buf
, ", avr:3", size
);
2861 case E_AVR_MACH_AVR31
:
2862 strncat (buf
, ", avr:31", size
);
2864 case E_AVR_MACH_AVR35
:
2865 strncat (buf
, ", avr:35", size
);
2867 case E_AVR_MACH_AVR4
:
2868 strncat (buf
, ", avr:4", size
);
2870 case E_AVR_MACH_AVR5
:
2871 strncat (buf
, ", avr:5", size
);
2873 case E_AVR_MACH_AVR51
:
2874 strncat (buf
, ", avr:51", size
);
2876 case E_AVR_MACH_AVR6
:
2877 strncat (buf
, ", avr:6", size
);
2879 case E_AVR_MACH_AVRTINY
:
2880 strncat (buf
, ", avr:100", size
);
2882 case E_AVR_MACH_XMEGA1
:
2883 strncat (buf
, ", avr:101", size
);
2885 case E_AVR_MACH_XMEGA2
:
2886 strncat (buf
, ", avr:102", size
);
2888 case E_AVR_MACH_XMEGA3
:
2889 strncat (buf
, ", avr:103", size
);
2891 case E_AVR_MACH_XMEGA4
:
2892 strncat (buf
, ", avr:104", size
);
2894 case E_AVR_MACH_XMEGA5
:
2895 strncat (buf
, ", avr:105", size
);
2897 case E_AVR_MACH_XMEGA6
:
2898 strncat (buf
, ", avr:106", size
);
2900 case E_AVR_MACH_XMEGA7
:
2901 strncat (buf
, ", avr:107", size
);
2904 strncat (buf
, ", avr:<unknown>", size
);
2908 size
-= strlen (buf
);
2909 if (e_flags
& EF_AVR_LINKRELAX_PREPARED
)
2910 strncat (buf
, ", link-relax", size
);
2914 decode_NDS32_machine_flags (unsigned e_flags
, char buf
[], size_t size
)
2920 bfd_boolean has_fpu
= FALSE
;
2923 static const char *ABI_STRINGS
[] =
2925 "ABI v0", /* use r5 as return register; only used in N1213HC */
2926 "ABI v1", /* use r0 as return register */
2927 "ABI v2", /* use r0 as return register and don't reserve 24 bytes for arguments */
2928 "ABI v2fp", /* for FPU */
2932 static const char *VER_STRINGS
[] =
2934 "Andes ELF V1.3 or older",
2938 static const char *ARCH_STRINGS
[] =
2947 abi
= EF_NDS_ABI
& e_flags
;
2948 arch
= EF_NDS_ARCH
& e_flags
;
2949 config
= EF_NDS_INST
& e_flags
;
2950 version
= EF_NDS32_ELF_VERSION
& e_flags
;
2952 memset (buf
, 0, size
);
2959 case E_NDS_ABI_V2FP
:
2960 case E_NDS_ABI_AABI
:
2961 case E_NDS_ABI_V2FP_PLUS
:
2962 /* In case there are holes in the array. */
2963 r
+= snprintf (buf
+ r
, size
- r
, ", %s", ABI_STRINGS
[abi
>> EF_NDS_ABI_SHIFT
]);
2967 r
+= snprintf (buf
+ r
, size
- r
, ", <unrecognized ABI>");
2973 case E_NDS32_ELF_VER_1_2
:
2974 case E_NDS32_ELF_VER_1_3
:
2975 case E_NDS32_ELF_VER_1_4
:
2976 r
+= snprintf (buf
+ r
, size
- r
, ", %s", VER_STRINGS
[version
>> EF_NDS32_ELF_VERSION_SHIFT
]);
2980 r
+= snprintf (buf
+ r
, size
- r
, ", <unrecognized ELF version number>");
2984 if (E_NDS_ABI_V0
== abi
)
2986 /* OLD ABI; only used in N1213HC, has performance extension 1. */
2987 r
+= snprintf (buf
+ r
, size
- r
, ", Andes Star v1.0, N1213HC, MAC, PERF1");
2988 if (arch
== E_NDS_ARCH_STAR_V1_0
)
2989 r
+= snprintf (buf
+ r
, size
-r
, ", 16b"); /* has 16-bit instructions */
2995 case E_NDS_ARCH_STAR_V1_0
:
2996 case E_NDS_ARCH_STAR_V2_0
:
2997 case E_NDS_ARCH_STAR_V3_0
:
2998 case E_NDS_ARCH_STAR_V3_M
:
2999 r
+= snprintf (buf
+ r
, size
- r
, ", %s", ARCH_STRINGS
[arch
>> EF_NDS_ARCH_SHIFT
]);
3003 r
+= snprintf (buf
+ r
, size
- r
, ", <unrecognized architecture>");
3004 /* ARCH version determines how the e_flags are interpreted.
3005 If it is unknown, we cannot proceed. */
3009 /* Newer ABI; Now handle architecture specific flags. */
3010 if (arch
== E_NDS_ARCH_STAR_V1_0
)
3012 if (config
& E_NDS32_HAS_MFUSR_PC_INST
)
3013 r
+= snprintf (buf
+ r
, size
-r
, ", MFUSR_PC");
3015 if (!(config
& E_NDS32_HAS_NO_MAC_INST
))
3016 r
+= snprintf (buf
+ r
, size
-r
, ", MAC");
3018 if (config
& E_NDS32_HAS_DIV_INST
)
3019 r
+= snprintf (buf
+ r
, size
-r
, ", DIV");
3021 if (config
& E_NDS32_HAS_16BIT_INST
)
3022 r
+= snprintf (buf
+ r
, size
-r
, ", 16b");
3026 if (config
& E_NDS32_HAS_MFUSR_PC_INST
)
3028 if (version
<= E_NDS32_ELF_VER_1_3
)
3029 r
+= snprintf (buf
+ r
, size
-r
, ", [B8]");
3031 r
+= snprintf (buf
+ r
, size
-r
, ", EX9");
3034 if (config
& E_NDS32_HAS_MAC_DX_INST
)
3035 r
+= snprintf (buf
+ r
, size
-r
, ", MAC_DX");
3037 if (config
& E_NDS32_HAS_DIV_DX_INST
)
3038 r
+= snprintf (buf
+ r
, size
-r
, ", DIV_DX");
3040 if (config
& E_NDS32_HAS_16BIT_INST
)
3042 if (version
<= E_NDS32_ELF_VER_1_3
)
3043 r
+= snprintf (buf
+ r
, size
-r
, ", 16b");
3045 r
+= snprintf (buf
+ r
, size
-r
, ", IFC");
3049 if (config
& E_NDS32_HAS_EXT_INST
)
3050 r
+= snprintf (buf
+ r
, size
-r
, ", PERF1");
3052 if (config
& E_NDS32_HAS_EXT2_INST
)
3053 r
+= snprintf (buf
+ r
, size
-r
, ", PERF2");
3055 if (config
& E_NDS32_HAS_FPU_INST
)
3058 r
+= snprintf (buf
+ r
, size
-r
, ", FPU_SP");
3061 if (config
& E_NDS32_HAS_FPU_DP_INST
)
3064 r
+= snprintf (buf
+ r
, size
-r
, ", FPU_DP");
3067 if (config
& E_NDS32_HAS_FPU_MAC_INST
)
3070 r
+= snprintf (buf
+ r
, size
-r
, ", FPU_MAC");
3075 switch ((config
& E_NDS32_FPU_REG_CONF
) >> E_NDS32_FPU_REG_CONF_SHIFT
)
3077 case E_NDS32_FPU_REG_8SP_4DP
:
3078 r
+= snprintf (buf
+ r
, size
-r
, ", FPU_REG:8/4");
3080 case E_NDS32_FPU_REG_16SP_8DP
:
3081 r
+= snprintf (buf
+ r
, size
-r
, ", FPU_REG:16/8");
3083 case E_NDS32_FPU_REG_32SP_16DP
:
3084 r
+= snprintf (buf
+ r
, size
-r
, ", FPU_REG:32/16");
3086 case E_NDS32_FPU_REG_32SP_32DP
:
3087 r
+= snprintf (buf
+ r
, size
-r
, ", FPU_REG:32/32");
3092 if (config
& E_NDS32_HAS_AUDIO_INST
)
3093 r
+= snprintf (buf
+ r
, size
-r
, ", AUDIO");
3095 if (config
& E_NDS32_HAS_STRING_INST
)
3096 r
+= snprintf (buf
+ r
, size
-r
, ", STR");
3098 if (config
& E_NDS32_HAS_REDUCED_REGS
)
3099 r
+= snprintf (buf
+ r
, size
-r
, ", 16REG");
3101 if (config
& E_NDS32_HAS_VIDEO_INST
)
3103 if (version
<= E_NDS32_ELF_VER_1_3
)
3104 r
+= snprintf (buf
+ r
, size
-r
, ", VIDEO");
3106 r
+= snprintf (buf
+ r
, size
-r
, ", SATURATION");
3109 if (config
& E_NDS32_HAS_ENCRIPT_INST
)
3110 r
+= snprintf (buf
+ r
, size
-r
, ", ENCRP");
3112 if (config
& E_NDS32_HAS_L2C_INST
)
3113 r
+= snprintf (buf
+ r
, size
-r
, ", L2C");
3117 get_machine_flags (Filedata
* filedata
, unsigned e_flags
, unsigned e_machine
)
3119 static char buf
[1024];
3130 case EM_ARC_COMPACT2
:
3131 case EM_ARC_COMPACT
:
3132 decode_ARC_machine_flags (e_flags
, e_machine
, buf
);
3136 decode_ARM_machine_flags (e_flags
, buf
);
3140 decode_AVR_machine_flags (e_flags
, buf
, sizeof buf
);
3144 if (e_flags
& EF_BFIN_PIC
)
3145 strcat (buf
, ", PIC");
3147 if (e_flags
& EF_BFIN_FDPIC
)
3148 strcat (buf
, ", FDPIC");
3150 if (e_flags
& EF_BFIN_CODE_IN_L1
)
3151 strcat (buf
, ", code in L1");
3153 if (e_flags
& EF_BFIN_DATA_IN_L1
)
3154 strcat (buf
, ", data in L1");
3159 switch (e_flags
& EF_FRV_CPU_MASK
)
3161 case EF_FRV_CPU_GENERIC
:
3165 strcat (buf
, ", fr???");
3168 case EF_FRV_CPU_FR300
:
3169 strcat (buf
, ", fr300");
3172 case EF_FRV_CPU_FR400
:
3173 strcat (buf
, ", fr400");
3175 case EF_FRV_CPU_FR405
:
3176 strcat (buf
, ", fr405");
3179 case EF_FRV_CPU_FR450
:
3180 strcat (buf
, ", fr450");
3183 case EF_FRV_CPU_FR500
:
3184 strcat (buf
, ", fr500");
3186 case EF_FRV_CPU_FR550
:
3187 strcat (buf
, ", fr550");
3190 case EF_FRV_CPU_SIMPLE
:
3191 strcat (buf
, ", simple");
3193 case EF_FRV_CPU_TOMCAT
:
3194 strcat (buf
, ", tomcat");
3200 if ((e_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_M68000
)
3201 strcat (buf
, ", m68000");
3202 else if ((e_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_CPU32
)
3203 strcat (buf
, ", cpu32");
3204 else if ((e_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_FIDO
)
3205 strcat (buf
, ", fido_a");
3208 char const * isa
= _("unknown");
3209 char const * mac
= _("unknown mac");
3210 char const * additional
= NULL
;
3212 switch (e_flags
& EF_M68K_CF_ISA_MASK
)
3214 case EF_M68K_CF_ISA_A_NODIV
:
3216 additional
= ", nodiv";
3218 case EF_M68K_CF_ISA_A
:
3221 case EF_M68K_CF_ISA_A_PLUS
:
3224 case EF_M68K_CF_ISA_B_NOUSP
:
3226 additional
= ", nousp";
3228 case EF_M68K_CF_ISA_B
:
3231 case EF_M68K_CF_ISA_C
:
3234 case EF_M68K_CF_ISA_C_NODIV
:
3236 additional
= ", nodiv";
3239 strcat (buf
, ", cf, isa ");
3242 strcat (buf
, additional
);
3243 if (e_flags
& EF_M68K_CF_FLOAT
)
3244 strcat (buf
, ", float");
3245 switch (e_flags
& EF_M68K_CF_MAC_MASK
)
3250 case EF_M68K_CF_MAC
:
3253 case EF_M68K_CF_EMAC
:
3256 case EF_M68K_CF_EMAC_B
:
3269 switch (e_flags
& EF_AMDGPU_MACH
)
3271 case EF_AMDGPU_MACH_AMDGCN_GFX801
: strcat (buf
, ", gfx801"); break;
3272 case EF_AMDGPU_MACH_AMDGCN_GFX802
: strcat (buf
, ", gfx802"); break;
3273 case EF_AMDGPU_MACH_AMDGCN_GFX803
: strcat (buf
, ", gfx803"); break;
3274 case EF_AMDGPU_MACH_AMDGCN_GFX810
: strcat (buf
, ", gfx810"); break;
3275 case EF_AMDGPU_MACH_AMDGCN_GFX900
: strcat (buf
, ", gfx900"); break;
3276 case EF_AMDGPU_MACH_AMDGCN_GFX902
: strcat (buf
, ", gfx902"); break;
3277 case EF_AMDGPU_MACH_AMDGCN_GFX904
: strcat (buf
, ", gfx904"); break;
3278 case EF_AMDGPU_MACH_AMDGCN_GFX906
: strcat (buf
, ", gfx906"); break;
3279 case EF_AMDGPU_MACH_AMDGCN_GFX908
: strcat (buf
, ", gfx908"); break;
3280 case EF_AMDGPU_MACH_AMDGCN_GFX909
: strcat (buf
, ", gfx909"); break;
3281 default: strcat (buf
, _(", <unknown AMDGPU gpu type>")); break;
3284 if (e_flags
& ~ EF_AMDGPU_MACH
)
3285 sprintf (buf
+ strlen (buf
), _(", unknown flags bits: %#x"),
3286 e_flags
& ~ EF_AMDGPU_MACH
);
3290 switch (e_flags
& EF_MEP_CPU_MASK
)
3292 case EF_MEP_CPU_MEP
: strcat (buf
, ", generic MeP"); break;
3293 case EF_MEP_CPU_C2
: strcat (buf
, ", MeP C2"); break;
3294 case EF_MEP_CPU_C3
: strcat (buf
, ", MeP C3"); break;
3295 case EF_MEP_CPU_C4
: strcat (buf
, ", MeP C4"); break;
3296 case EF_MEP_CPU_C5
: strcat (buf
, ", MeP C5"); break;
3297 case EF_MEP_CPU_H1
: strcat (buf
, ", MeP H1"); break;
3298 default: strcat (buf
, _(", <unknown MeP cpu type>")); break;
3301 switch (e_flags
& EF_MEP_COP_MASK
)
3303 case EF_MEP_COP_NONE
: break;
3304 case EF_MEP_COP_AVC
: strcat (buf
, ", AVC coprocessor"); break;
3305 case EF_MEP_COP_AVC2
: strcat (buf
, ", AVC2 coprocessor"); break;
3306 case EF_MEP_COP_FMAX
: strcat (buf
, ", FMAX coprocessor"); break;
3307 case EF_MEP_COP_IVC2
: strcat (buf
, ", IVC2 coprocessor"); break;
3308 default: strcat (buf
, _("<unknown MeP copro type>")); break;
3311 if (e_flags
& EF_MEP_LIBRARY
)
3312 strcat (buf
, ", Built for Library");
3314 if (e_flags
& EF_MEP_INDEX_MASK
)
3315 sprintf (buf
+ strlen (buf
), ", Configuration Index: %#x",
3316 e_flags
& EF_MEP_INDEX_MASK
);
3318 if (e_flags
& ~ EF_MEP_ALL_FLAGS
)
3319 sprintf (buf
+ strlen (buf
), _(", unknown flags bits: %#x"),
3320 e_flags
& ~ EF_MEP_ALL_FLAGS
);
3324 if (e_flags
& EF_PPC_EMB
)
3325 strcat (buf
, ", emb");
3327 if (e_flags
& EF_PPC_RELOCATABLE
)
3328 strcat (buf
, _(", relocatable"));
3330 if (e_flags
& EF_PPC_RELOCATABLE_LIB
)
3331 strcat (buf
, _(", relocatable-lib"));
3335 if (e_flags
& EF_PPC64_ABI
)
3337 char abi
[] = ", abiv0";
3339 abi
[6] += e_flags
& EF_PPC64_ABI
;
3345 if ((e_flags
& EF_RH850_ABI
) == EF_RH850_ABI
)
3346 strcat (buf
, ", RH850 ABI");
3348 if (e_flags
& EF_V800_850E3
)
3349 strcat (buf
, ", V3 architecture");
3351 if ((e_flags
& (EF_RH850_FPU_DOUBLE
| EF_RH850_FPU_SINGLE
)) == 0)
3352 strcat (buf
, ", FPU not used");
3354 if ((e_flags
& (EF_RH850_REGMODE22
| EF_RH850_REGMODE32
)) == 0)
3355 strcat (buf
, ", regmode: COMMON");
3357 if ((e_flags
& (EF_RH850_GP_FIX
| EF_RH850_GP_NOFIX
)) == 0)
3358 strcat (buf
, ", r4 not used");
3360 if ((e_flags
& (EF_RH850_EP_FIX
| EF_RH850_EP_NOFIX
)) == 0)
3361 strcat (buf
, ", r30 not used");
3363 if ((e_flags
& (EF_RH850_TP_FIX
| EF_RH850_TP_NOFIX
)) == 0)
3364 strcat (buf
, ", r5 not used");
3366 if ((e_flags
& (EF_RH850_REG2_RESERVE
| EF_RH850_REG2_NORESERVE
)) == 0)
3367 strcat (buf
, ", r2 not used");
3369 for (e_flags
&= 0xFFFF; e_flags
; e_flags
&= ~ (e_flags
& - e_flags
))
3371 switch (e_flags
& - e_flags
)
3373 case EF_RH850_FPU_DOUBLE
: strcat (buf
, ", double precision FPU"); break;
3374 case EF_RH850_FPU_SINGLE
: strcat (buf
, ", single precision FPU"); break;
3375 case EF_RH850_REGMODE22
: strcat (buf
, ", regmode:22"); break;
3376 case EF_RH850_REGMODE32
: strcat (buf
, ", regmode:23"); break;
3377 case EF_RH850_GP_FIX
: strcat (buf
, ", r4 fixed"); break;
3378 case EF_RH850_GP_NOFIX
: strcat (buf
, ", r4 free"); break;
3379 case EF_RH850_EP_FIX
: strcat (buf
, ", r30 fixed"); break;
3380 case EF_RH850_EP_NOFIX
: strcat (buf
, ", r30 free"); break;
3381 case EF_RH850_TP_FIX
: strcat (buf
, ", r5 fixed"); break;
3382 case EF_RH850_TP_NOFIX
: strcat (buf
, ", r5 free"); break;
3383 case EF_RH850_REG2_RESERVE
: strcat (buf
, ", r2 fixed"); break;
3384 case EF_RH850_REG2_NORESERVE
: strcat (buf
, ", r2 free"); break;
3391 case EM_CYGNUS_V850
:
3392 switch (e_flags
& EF_V850_ARCH
)
3394 case E_V850E3V5_ARCH
:
3395 strcat (buf
, ", v850e3v5");
3397 case E_V850E2V3_ARCH
:
3398 strcat (buf
, ", v850e2v3");
3401 strcat (buf
, ", v850e2");
3404 strcat (buf
, ", v850e1");
3407 strcat (buf
, ", v850e");
3410 strcat (buf
, ", v850");
3413 strcat (buf
, _(", unknown v850 architecture variant"));
3419 case EM_CYGNUS_M32R
:
3420 if ((e_flags
& EF_M32R_ARCH
) == E_M32R_ARCH
)
3421 strcat (buf
, ", m32r");
3425 case EM_MIPS_RS3_LE
:
3426 if (e_flags
& EF_MIPS_NOREORDER
)
3427 strcat (buf
, ", noreorder");
3429 if (e_flags
& EF_MIPS_PIC
)
3430 strcat (buf
, ", pic");
3432 if (e_flags
& EF_MIPS_CPIC
)
3433 strcat (buf
, ", cpic");
3435 if (e_flags
& EF_MIPS_UCODE
)
3436 strcat (buf
, ", ugen_reserved");
3438 if (e_flags
& EF_MIPS_ABI2
)
3439 strcat (buf
, ", abi2");
3441 if (e_flags
& EF_MIPS_OPTIONS_FIRST
)
3442 strcat (buf
, ", odk first");
3444 if (e_flags
& EF_MIPS_32BITMODE
)
3445 strcat (buf
, ", 32bitmode");
3447 if (e_flags
& EF_MIPS_NAN2008
)
3448 strcat (buf
, ", nan2008");
3450 if (e_flags
& EF_MIPS_FP64
)
3451 strcat (buf
, ", fp64");
3453 switch ((e_flags
& EF_MIPS_MACH
))
3455 case E_MIPS_MACH_3900
: strcat (buf
, ", 3900"); break;
3456 case E_MIPS_MACH_4010
: strcat (buf
, ", 4010"); break;
3457 case E_MIPS_MACH_4100
: strcat (buf
, ", 4100"); break;
3458 case E_MIPS_MACH_4111
: strcat (buf
, ", 4111"); break;
3459 case E_MIPS_MACH_4120
: strcat (buf
, ", 4120"); break;
3460 case E_MIPS_MACH_4650
: strcat (buf
, ", 4650"); break;
3461 case E_MIPS_MACH_5400
: strcat (buf
, ", 5400"); break;
3462 case E_MIPS_MACH_5500
: strcat (buf
, ", 5500"); break;
3463 case E_MIPS_MACH_5900
: strcat (buf
, ", 5900"); break;
3464 case E_MIPS_MACH_SB1
: strcat (buf
, ", sb1"); break;
3465 case E_MIPS_MACH_9000
: strcat (buf
, ", 9000"); break;
3466 case E_MIPS_MACH_LS2E
: strcat (buf
, ", loongson-2e"); break;
3467 case E_MIPS_MACH_LS2F
: strcat (buf
, ", loongson-2f"); break;
3468 case E_MIPS_MACH_GS464
: strcat (buf
, ", gs464"); break;
3469 case E_MIPS_MACH_GS464E
: strcat (buf
, ", gs464e"); break;
3470 case E_MIPS_MACH_GS264E
: strcat (buf
, ", gs264e"); break;
3471 case E_MIPS_MACH_OCTEON
: strcat (buf
, ", octeon"); break;
3472 case E_MIPS_MACH_OCTEON2
: strcat (buf
, ", octeon2"); break;
3473 case E_MIPS_MACH_OCTEON3
: strcat (buf
, ", octeon3"); break;
3474 case E_MIPS_MACH_XLR
: strcat (buf
, ", xlr"); break;
3475 case E_MIPS_MACH_IAMR2
: strcat (buf
, ", interaptiv-mr2"); break;
3477 /* We simply ignore the field in this case to avoid confusion:
3478 MIPS ELF does not specify EF_MIPS_MACH, it is a GNU
3481 default: strcat (buf
, _(", unknown CPU")); break;
3484 switch ((e_flags
& EF_MIPS_ABI
))
3486 case E_MIPS_ABI_O32
: strcat (buf
, ", o32"); break;
3487 case E_MIPS_ABI_O64
: strcat (buf
, ", o64"); break;
3488 case E_MIPS_ABI_EABI32
: strcat (buf
, ", eabi32"); break;
3489 case E_MIPS_ABI_EABI64
: strcat (buf
, ", eabi64"); break;
3491 /* We simply ignore the field in this case to avoid confusion:
3492 MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension.
3493 This means it is likely to be an o32 file, but not for
3496 default: strcat (buf
, _(", unknown ABI")); break;
3499 if (e_flags
& EF_MIPS_ARCH_ASE_MDMX
)
3500 strcat (buf
, ", mdmx");
3502 if (e_flags
& EF_MIPS_ARCH_ASE_M16
)
3503 strcat (buf
, ", mips16");
3505 if (e_flags
& EF_MIPS_ARCH_ASE_MICROMIPS
)
3506 strcat (buf
, ", micromips");
3508 switch ((e_flags
& EF_MIPS_ARCH
))
3510 case E_MIPS_ARCH_1
: strcat (buf
, ", mips1"); break;
3511 case E_MIPS_ARCH_2
: strcat (buf
, ", mips2"); break;
3512 case E_MIPS_ARCH_3
: strcat (buf
, ", mips3"); break;
3513 case E_MIPS_ARCH_4
: strcat (buf
, ", mips4"); break;
3514 case E_MIPS_ARCH_5
: strcat (buf
, ", mips5"); break;
3515 case E_MIPS_ARCH_32
: strcat (buf
, ", mips32"); break;
3516 case E_MIPS_ARCH_32R2
: strcat (buf
, ", mips32r2"); break;
3517 case E_MIPS_ARCH_32R6
: strcat (buf
, ", mips32r6"); break;
3518 case E_MIPS_ARCH_64
: strcat (buf
, ", mips64"); break;
3519 case E_MIPS_ARCH_64R2
: strcat (buf
, ", mips64r2"); break;
3520 case E_MIPS_ARCH_64R6
: strcat (buf
, ", mips64r6"); break;
3521 default: strcat (buf
, _(", unknown ISA")); break;
3526 decode_NDS32_machine_flags (e_flags
, buf
, sizeof buf
);
3530 switch (EF_NFP_MACH (e_flags
))
3532 case E_NFP_MACH_3200
:
3533 strcat (buf
, ", NFP-32xx");
3535 case E_NFP_MACH_6000
:
3536 strcat (buf
, ", NFP-6xxx");
3542 if (e_flags
& EF_RISCV_RVC
)
3543 strcat (buf
, ", RVC");
3545 if (e_flags
& EF_RISCV_RVE
)
3546 strcat (buf
, ", RVE");
3548 switch (e_flags
& EF_RISCV_FLOAT_ABI
)
3550 case EF_RISCV_FLOAT_ABI_SOFT
:
3551 strcat (buf
, ", soft-float ABI");
3554 case EF_RISCV_FLOAT_ABI_SINGLE
:
3555 strcat (buf
, ", single-float ABI");
3558 case EF_RISCV_FLOAT_ABI_DOUBLE
:
3559 strcat (buf
, ", double-float ABI");
3562 case EF_RISCV_FLOAT_ABI_QUAD
:
3563 strcat (buf
, ", quad-float ABI");
3569 switch ((e_flags
& EF_SH_MACH_MASK
))
3571 case EF_SH1
: strcat (buf
, ", sh1"); break;
3572 case EF_SH2
: strcat (buf
, ", sh2"); break;
3573 case EF_SH3
: strcat (buf
, ", sh3"); break;
3574 case EF_SH_DSP
: strcat (buf
, ", sh-dsp"); break;
3575 case EF_SH3_DSP
: strcat (buf
, ", sh3-dsp"); break;
3576 case EF_SH4AL_DSP
: strcat (buf
, ", sh4al-dsp"); break;
3577 case EF_SH3E
: strcat (buf
, ", sh3e"); break;
3578 case EF_SH4
: strcat (buf
, ", sh4"); break;
3579 case EF_SH5
: strcat (buf
, ", sh5"); break;
3580 case EF_SH2E
: strcat (buf
, ", sh2e"); break;
3581 case EF_SH4A
: strcat (buf
, ", sh4a"); break;
3582 case EF_SH2A
: strcat (buf
, ", sh2a"); break;
3583 case EF_SH4_NOFPU
: strcat (buf
, ", sh4-nofpu"); break;
3584 case EF_SH4A_NOFPU
: strcat (buf
, ", sh4a-nofpu"); break;
3585 case EF_SH2A_NOFPU
: strcat (buf
, ", sh2a-nofpu"); break;
3586 case EF_SH3_NOMMU
: strcat (buf
, ", sh3-nommu"); break;
3587 case EF_SH4_NOMMU_NOFPU
: strcat (buf
, ", sh4-nommu-nofpu"); break;
3588 case EF_SH2A_SH4_NOFPU
: strcat (buf
, ", sh2a-nofpu-or-sh4-nommu-nofpu"); break;
3589 case EF_SH2A_SH3_NOFPU
: strcat (buf
, ", sh2a-nofpu-or-sh3-nommu"); break;
3590 case EF_SH2A_SH4
: strcat (buf
, ", sh2a-or-sh4"); break;
3591 case EF_SH2A_SH3E
: strcat (buf
, ", sh2a-or-sh3e"); break;
3592 default: strcat (buf
, _(", unknown ISA")); break;
3595 if (e_flags
& EF_SH_PIC
)
3596 strcat (buf
, ", pic");
3598 if (e_flags
& EF_SH_FDPIC
)
3599 strcat (buf
, ", fdpic");
3603 if (e_flags
& EF_OR1K_NODELAY
)
3604 strcat (buf
, ", no delay");
3608 if (e_flags
& EF_SPARC_32PLUS
)
3609 strcat (buf
, ", v8+");
3611 if (e_flags
& EF_SPARC_SUN_US1
)
3612 strcat (buf
, ", ultrasparcI");
3614 if (e_flags
& EF_SPARC_SUN_US3
)
3615 strcat (buf
, ", ultrasparcIII");
3617 if (e_flags
& EF_SPARC_HAL_R1
)
3618 strcat (buf
, ", halr1");
3620 if (e_flags
& EF_SPARC_LEDATA
)
3621 strcat (buf
, ", ledata");
3623 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_TSO
)
3624 strcat (buf
, ", tso");
3626 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_PSO
)
3627 strcat (buf
, ", pso");
3629 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_RMO
)
3630 strcat (buf
, ", rmo");
3634 switch (e_flags
& EF_PARISC_ARCH
)
3636 case EFA_PARISC_1_0
:
3637 strcpy (buf
, ", PA-RISC 1.0");
3639 case EFA_PARISC_1_1
:
3640 strcpy (buf
, ", PA-RISC 1.1");
3642 case EFA_PARISC_2_0
:
3643 strcpy (buf
, ", PA-RISC 2.0");
3648 if (e_flags
& EF_PARISC_TRAPNIL
)
3649 strcat (buf
, ", trapnil");
3650 if (e_flags
& EF_PARISC_EXT
)
3651 strcat (buf
, ", ext");
3652 if (e_flags
& EF_PARISC_LSB
)
3653 strcat (buf
, ", lsb");
3654 if (e_flags
& EF_PARISC_WIDE
)
3655 strcat (buf
, ", wide");
3656 if (e_flags
& EF_PARISC_NO_KABP
)
3657 strcat (buf
, ", no kabp");
3658 if (e_flags
& EF_PARISC_LAZYSWAP
)
3659 strcat (buf
, ", lazyswap");
3664 if ((e_flags
& EF_PICOJAVA_NEWCALLS
) == EF_PICOJAVA_NEWCALLS
)
3665 strcat (buf
, ", new calling convention");
3667 if ((e_flags
& EF_PICOJAVA_GNUCALLS
) == EF_PICOJAVA_GNUCALLS
)
3668 strcat (buf
, ", gnu calling convention");
3672 if ((e_flags
& EF_IA_64_ABI64
))
3673 strcat (buf
, ", 64-bit");
3675 strcat (buf
, ", 32-bit");
3676 if ((e_flags
& EF_IA_64_REDUCEDFP
))
3677 strcat (buf
, ", reduced fp model");
3678 if ((e_flags
& EF_IA_64_NOFUNCDESC_CONS_GP
))
3679 strcat (buf
, ", no function descriptors, constant gp");
3680 else if ((e_flags
& EF_IA_64_CONS_GP
))
3681 strcat (buf
, ", constant gp");
3682 if ((e_flags
& EF_IA_64_ABSOLUTE
))
3683 strcat (buf
, ", absolute");
3684 if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_OPENVMS
)
3686 if ((e_flags
& EF_IA_64_VMS_LINKAGES
))
3687 strcat (buf
, ", vms_linkages");
3688 switch ((e_flags
& EF_IA_64_VMS_COMCOD
))
3690 case EF_IA_64_VMS_COMCOD_SUCCESS
:
3692 case EF_IA_64_VMS_COMCOD_WARNING
:
3693 strcat (buf
, ", warning");
3695 case EF_IA_64_VMS_COMCOD_ERROR
:
3696 strcat (buf
, ", error");
3698 case EF_IA_64_VMS_COMCOD_ABORT
:
3699 strcat (buf
, ", abort");
3702 warn (_("Unrecognised IA64 VMS Command Code: %x\n"),
3703 e_flags
& EF_IA_64_VMS_COMCOD
);
3704 strcat (buf
, ", <unknown>");
3710 if ((e_flags
& EF_VAX_NONPIC
))
3711 strcat (buf
, ", non-PIC");
3712 if ((e_flags
& EF_VAX_DFLOAT
))
3713 strcat (buf
, ", D-Float");
3714 if ((e_flags
& EF_VAX_GFLOAT
))
3715 strcat (buf
, ", G-Float");
3719 if (e_flags
& EF_VISIUM_ARCH_MCM
)
3720 strcat (buf
, ", mcm");
3721 else if (e_flags
& EF_VISIUM_ARCH_MCM24
)
3722 strcat (buf
, ", mcm24");
3723 if (e_flags
& EF_VISIUM_ARCH_GR6
)
3724 strcat (buf
, ", gr6");
3728 switch (e_flags
& E_FLAG_RL78_CPU_MASK
)
3730 case E_FLAG_RL78_ANY_CPU
: break;
3731 case E_FLAG_RL78_G10
: strcat (buf
, ", G10"); break;
3732 case E_FLAG_RL78_G13
: strcat (buf
, ", G13"); break;
3733 case E_FLAG_RL78_G14
: strcat (buf
, ", G14"); break;
3735 if (e_flags
& E_FLAG_RL78_64BIT_DOUBLES
)
3736 strcat (buf
, ", 64-bit doubles");
3740 if (e_flags
& E_FLAG_RX_64BIT_DOUBLES
)
3741 strcat (buf
, ", 64-bit doubles");
3742 if (e_flags
& E_FLAG_RX_DSP
)
3743 strcat (buf
, ", dsp");
3744 if (e_flags
& E_FLAG_RX_PID
)
3745 strcat (buf
, ", pid");
3746 if (e_flags
& E_FLAG_RX_ABI
)
3747 strcat (buf
, ", RX ABI");
3748 if (e_flags
& E_FLAG_RX_SINSNS_SET
)
3749 strcat (buf
, e_flags
& E_FLAG_RX_SINSNS_YES
3750 ? ", uses String instructions" : ", bans String instructions");
3751 if (e_flags
& E_FLAG_RX_V2
)
3752 strcat (buf
, ", V2");
3753 if (e_flags
& E_FLAG_RX_V3
)
3754 strcat (buf
, ", V3");
3758 if (e_flags
& EF_S390_HIGH_GPRS
)
3759 strcat (buf
, ", highgprs");
3763 if ((e_flags
& EF_C6000_REL
))
3764 strcat (buf
, ", relocatable module");
3768 strcat (buf
, _(": architecture variant: "));
3769 switch (e_flags
& EF_MSP430_MACH
)
3771 case E_MSP430_MACH_MSP430x11
: strcat (buf
, "MSP430x11"); break;
3772 case E_MSP430_MACH_MSP430x11x1
: strcat (buf
, "MSP430x11x1 "); break;
3773 case E_MSP430_MACH_MSP430x12
: strcat (buf
, "MSP430x12"); break;
3774 case E_MSP430_MACH_MSP430x13
: strcat (buf
, "MSP430x13"); break;
3775 case E_MSP430_MACH_MSP430x14
: strcat (buf
, "MSP430x14"); break;
3776 case E_MSP430_MACH_MSP430x15
: strcat (buf
, "MSP430x15"); break;
3777 case E_MSP430_MACH_MSP430x16
: strcat (buf
, "MSP430x16"); break;
3778 case E_MSP430_MACH_MSP430x31
: strcat (buf
, "MSP430x31"); break;
3779 case E_MSP430_MACH_MSP430x32
: strcat (buf
, "MSP430x32"); break;
3780 case E_MSP430_MACH_MSP430x33
: strcat (buf
, "MSP430x33"); break;
3781 case E_MSP430_MACH_MSP430x41
: strcat (buf
, "MSP430x41"); break;
3782 case E_MSP430_MACH_MSP430x42
: strcat (buf
, "MSP430x42"); break;
3783 case E_MSP430_MACH_MSP430x43
: strcat (buf
, "MSP430x43"); break;
3784 case E_MSP430_MACH_MSP430x44
: strcat (buf
, "MSP430x44"); break;
3785 case E_MSP430_MACH_MSP430X
: strcat (buf
, "MSP430X"); break;
3787 strcat (buf
, _(": unknown")); break;
3790 if (e_flags
& ~ EF_MSP430_MACH
)
3791 strcat (buf
, _(": unknown extra flag bits also present"));
3799 get_osabi_name (Filedata
* filedata
, unsigned int osabi
)
3801 static char buff
[32];
3805 case ELFOSABI_NONE
: return "UNIX - System V";
3806 case ELFOSABI_HPUX
: return "UNIX - HP-UX";
3807 case ELFOSABI_NETBSD
: return "UNIX - NetBSD";
3808 case ELFOSABI_GNU
: return "UNIX - GNU";
3809 case ELFOSABI_SOLARIS
: return "UNIX - Solaris";
3810 case ELFOSABI_AIX
: return "UNIX - AIX";
3811 case ELFOSABI_IRIX
: return "UNIX - IRIX";
3812 case ELFOSABI_FREEBSD
: return "UNIX - FreeBSD";
3813 case ELFOSABI_TRU64
: return "UNIX - TRU64";
3814 case ELFOSABI_MODESTO
: return "Novell - Modesto";
3815 case ELFOSABI_OPENBSD
: return "UNIX - OpenBSD";
3816 case ELFOSABI_OPENVMS
: return "VMS - OpenVMS";
3817 case ELFOSABI_NSK
: return "HP - Non-Stop Kernel";
3818 case ELFOSABI_AROS
: return "AROS";
3819 case ELFOSABI_FENIXOS
: return "FenixOS";
3820 case ELFOSABI_CLOUDABI
: return "Nuxi CloudABI";
3821 case ELFOSABI_OPENVOS
: return "Stratus Technologies OpenVOS";
3824 switch (filedata
->file_header
.e_machine
)
3829 case ELFOSABI_AMDGPU_HSA
: return "AMD HSA Runtime";
3838 case ELFOSABI_ARM
: return "ARM";
3839 case ELFOSABI_ARM_FDPIC
: return "ARM FDPIC";
3850 case ELFOSABI_STANDALONE
: return _("Standalone App");
3859 case ELFOSABI_C6000_ELFABI
: return _("Bare-metal C6000");
3860 case ELFOSABI_C6000_LINUX
: return "Linux C6000";
3869 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), osabi
);
3875 get_aarch64_segment_type (unsigned long type
)
3879 case PT_AARCH64_ARCHEXT
: return "AARCH64_ARCHEXT";
3880 default: return NULL
;
3885 get_arm_segment_type (unsigned long type
)
3889 case PT_ARM_EXIDX
: return "EXIDX";
3890 default: return NULL
;
3895 get_s390_segment_type (unsigned long type
)
3899 case PT_S390_PGSTE
: return "S390_PGSTE";
3900 default: return NULL
;
3905 get_mips_segment_type (unsigned long type
)
3909 case PT_MIPS_REGINFO
: return "REGINFO";
3910 case PT_MIPS_RTPROC
: return "RTPROC";
3911 case PT_MIPS_OPTIONS
: return "OPTIONS";
3912 case PT_MIPS_ABIFLAGS
: return "ABIFLAGS";
3913 default: return NULL
;
3918 get_parisc_segment_type (unsigned long type
)
3922 case PT_PARISC_ARCHEXT
: return "PARISC_ARCHEXT";
3923 case PT_PARISC_UNWIND
: return "PARISC_UNWIND";
3924 case PT_PARISC_WEAKORDER
: return "PARISC_WEAKORDER";
3925 default: return NULL
;
3930 get_ia64_segment_type (unsigned long type
)
3934 case PT_IA_64_ARCHEXT
: return "IA_64_ARCHEXT";
3935 case PT_IA_64_UNWIND
: return "IA_64_UNWIND";
3936 default: return NULL
;
3941 get_tic6x_segment_type (unsigned long type
)
3945 case PT_C6000_PHATTR
: return "C6000_PHATTR";
3946 default: return NULL
;
3951 get_hpux_segment_type (unsigned long type
, unsigned e_machine
)
3953 if (e_machine
== EM_PARISC
)
3956 case PT_HP_TLS
: return "HP_TLS";
3957 case PT_HP_CORE_NONE
: return "HP_CORE_NONE";
3958 case PT_HP_CORE_VERSION
: return "HP_CORE_VERSION";
3959 case PT_HP_CORE_KERNEL
: return "HP_CORE_KERNEL";
3960 case PT_HP_CORE_COMM
: return "HP_CORE_COMM";
3961 case PT_HP_CORE_PROC
: return "HP_CORE_PROC";
3962 case PT_HP_CORE_LOADABLE
: return "HP_CORE_LOADABLE";
3963 case PT_HP_CORE_STACK
: return "HP_CORE_STACK";
3964 case PT_HP_CORE_SHM
: return "HP_CORE_SHM";
3965 case PT_HP_CORE_MMF
: return "HP_CORE_MMF";
3966 case PT_HP_PARALLEL
: return "HP_PARALLEL";
3967 case PT_HP_FASTBIND
: return "HP_FASTBIND";
3968 case PT_HP_OPT_ANNOT
: return "HP_OPT_ANNOT";
3969 case PT_HP_HSL_ANNOT
: return "HP_HSL_ANNOT";
3970 case PT_HP_STACK
: return "HP_STACK";
3971 case PT_HP_CORE_UTSNAME
: return "HP_CORE_UTSNAME";
3972 default: return NULL
;
3975 if (e_machine
== EM_IA_64
)
3978 case PT_HP_TLS
: return "HP_TLS";
3979 case PT_IA_64_HP_OPT_ANOT
: return "HP_OPT_ANNOT";
3980 case PT_IA_64_HP_HSL_ANOT
: return "HP_HSL_ANNOT";
3981 case PT_IA_64_HP_STACK
: return "HP_STACK";
3982 default: return NULL
;
3989 get_solaris_segment_type (unsigned long type
)
3993 case 0x6464e550: return "PT_SUNW_UNWIND";
3994 case 0x6474e550: return "PT_SUNW_EH_FRAME";
3995 case 0x6ffffff7: return "PT_LOSUNW";
3996 case 0x6ffffffa: return "PT_SUNWBSS";
3997 case 0x6ffffffb: return "PT_SUNWSTACK";
3998 case 0x6ffffffc: return "PT_SUNWDTRACE";
3999 case 0x6ffffffd: return "PT_SUNWCAP";
4000 case 0x6fffffff: return "PT_HISUNW";
4001 default: return NULL
;
4006 get_segment_type (Filedata
* filedata
, unsigned long p_type
)
4008 static char buff
[32];
4012 case PT_NULL
: return "NULL";
4013 case PT_LOAD
: return "LOAD";
4014 case PT_DYNAMIC
: return "DYNAMIC";
4015 case PT_INTERP
: return "INTERP";
4016 case PT_NOTE
: return "NOTE";
4017 case PT_SHLIB
: return "SHLIB";
4018 case PT_PHDR
: return "PHDR";
4019 case PT_TLS
: return "TLS";
4020 case PT_GNU_EH_FRAME
: return "GNU_EH_FRAME";
4021 case PT_GNU_STACK
: return "GNU_STACK";
4022 case PT_GNU_RELRO
: return "GNU_RELRO";
4023 case PT_GNU_PROPERTY
: return "GNU_PROPERTY";
4026 if ((p_type
>= PT_LOPROC
) && (p_type
<= PT_HIPROC
))
4028 const char * result
;
4030 switch (filedata
->file_header
.e_machine
)
4033 result
= get_aarch64_segment_type (p_type
);
4036 result
= get_arm_segment_type (p_type
);
4039 case EM_MIPS_RS3_LE
:
4040 result
= get_mips_segment_type (p_type
);
4043 result
= get_parisc_segment_type (p_type
);
4046 result
= get_ia64_segment_type (p_type
);
4049 result
= get_tic6x_segment_type (p_type
);
4053 result
= get_s390_segment_type (p_type
);
4063 sprintf (buff
, "LOPROC+%#lx", p_type
- PT_LOPROC
);
4065 else if ((p_type
>= PT_LOOS
) && (p_type
<= PT_HIOS
))
4067 const char * result
= NULL
;
4069 switch (filedata
->file_header
.e_ident
[EI_OSABI
])
4072 case ELFOSABI_FREEBSD
:
4073 if (p_type
>= PT_GNU_MBIND_LO
&& p_type
<= PT_GNU_MBIND_HI
)
4075 sprintf (buff
, "GNU_MBIND+%#lx", p_type
- PT_GNU_MBIND_LO
);
4080 result
= get_hpux_segment_type (p_type
,
4081 filedata
->file_header
.e_machine
);
4083 case ELFOSABI_SOLARIS
:
4084 result
= get_solaris_segment_type (p_type
);
4092 sprintf (buff
, "LOOS+%#lx", p_type
- PT_LOOS
);
4095 snprintf (buff
, sizeof (buff
), _("<unknown>: %lx"), p_type
);
4102 get_arc_section_type_name (unsigned int sh_type
)
4106 case SHT_ARC_ATTRIBUTES
: return "ARC_ATTRIBUTES";
4114 get_mips_section_type_name (unsigned int sh_type
)
4118 case SHT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
4119 case SHT_MIPS_MSYM
: return "MIPS_MSYM";
4120 case SHT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
4121 case SHT_MIPS_GPTAB
: return "MIPS_GPTAB";
4122 case SHT_MIPS_UCODE
: return "MIPS_UCODE";
4123 case SHT_MIPS_DEBUG
: return "MIPS_DEBUG";
4124 case SHT_MIPS_REGINFO
: return "MIPS_REGINFO";
4125 case SHT_MIPS_PACKAGE
: return "MIPS_PACKAGE";
4126 case SHT_MIPS_PACKSYM
: return "MIPS_PACKSYM";
4127 case SHT_MIPS_RELD
: return "MIPS_RELD";
4128 case SHT_MIPS_IFACE
: return "MIPS_IFACE";
4129 case SHT_MIPS_CONTENT
: return "MIPS_CONTENT";
4130 case SHT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
4131 case SHT_MIPS_SHDR
: return "MIPS_SHDR";
4132 case SHT_MIPS_FDESC
: return "MIPS_FDESC";
4133 case SHT_MIPS_EXTSYM
: return "MIPS_EXTSYM";
4134 case SHT_MIPS_DENSE
: return "MIPS_DENSE";
4135 case SHT_MIPS_PDESC
: return "MIPS_PDESC";
4136 case SHT_MIPS_LOCSYM
: return "MIPS_LOCSYM";
4137 case SHT_MIPS_AUXSYM
: return "MIPS_AUXSYM";
4138 case SHT_MIPS_OPTSYM
: return "MIPS_OPTSYM";
4139 case SHT_MIPS_LOCSTR
: return "MIPS_LOCSTR";
4140 case SHT_MIPS_LINE
: return "MIPS_LINE";
4141 case SHT_MIPS_RFDESC
: return "MIPS_RFDESC";
4142 case SHT_MIPS_DELTASYM
: return "MIPS_DELTASYM";
4143 case SHT_MIPS_DELTAINST
: return "MIPS_DELTAINST";
4144 case SHT_MIPS_DELTACLASS
: return "MIPS_DELTACLASS";
4145 case SHT_MIPS_DWARF
: return "MIPS_DWARF";
4146 case SHT_MIPS_DELTADECL
: return "MIPS_DELTADECL";
4147 case SHT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
4148 case SHT_MIPS_EVENTS
: return "MIPS_EVENTS";
4149 case SHT_MIPS_TRANSLATE
: return "MIPS_TRANSLATE";
4150 case SHT_MIPS_PIXIE
: return "MIPS_PIXIE";
4151 case SHT_MIPS_XLATE
: return "MIPS_XLATE";
4152 case SHT_MIPS_XLATE_DEBUG
: return "MIPS_XLATE_DEBUG";
4153 case SHT_MIPS_WHIRL
: return "MIPS_WHIRL";
4154 case SHT_MIPS_EH_REGION
: return "MIPS_EH_REGION";
4155 case SHT_MIPS_XLATE_OLD
: return "MIPS_XLATE_OLD";
4156 case SHT_MIPS_PDR_EXCEPTION
: return "MIPS_PDR_EXCEPTION";
4157 case SHT_MIPS_ABIFLAGS
: return "MIPS_ABIFLAGS";
4158 case SHT_MIPS_XHASH
: return "MIPS_XHASH";
4166 get_parisc_section_type_name (unsigned int sh_type
)
4170 case SHT_PARISC_EXT
: return "PARISC_EXT";
4171 case SHT_PARISC_UNWIND
: return "PARISC_UNWIND";
4172 case SHT_PARISC_DOC
: return "PARISC_DOC";
4173 case SHT_PARISC_ANNOT
: return "PARISC_ANNOT";
4174 case SHT_PARISC_SYMEXTN
: return "PARISC_SYMEXTN";
4175 case SHT_PARISC_STUBS
: return "PARISC_STUBS";
4176 case SHT_PARISC_DLKM
: return "PARISC_DLKM";
4177 default: return NULL
;
4182 get_ia64_section_type_name (Filedata
* filedata
, unsigned int sh_type
)
4184 /* If the top 8 bits are 0x78 the next 8 are the os/abi ID. */
4185 if ((sh_type
& 0xFF000000) == SHT_IA_64_LOPSREG
)
4186 return get_osabi_name (filedata
, (sh_type
& 0x00FF0000) >> 16);
4190 case SHT_IA_64_EXT
: return "IA_64_EXT";
4191 case SHT_IA_64_UNWIND
: return "IA_64_UNWIND";
4192 case SHT_IA_64_PRIORITY_INIT
: return "IA_64_PRIORITY_INIT";
4193 case SHT_IA_64_VMS_TRACE
: return "VMS_TRACE";
4194 case SHT_IA_64_VMS_TIE_SIGNATURES
: return "VMS_TIE_SIGNATURES";
4195 case SHT_IA_64_VMS_DEBUG
: return "VMS_DEBUG";
4196 case SHT_IA_64_VMS_DEBUG_STR
: return "VMS_DEBUG_STR";
4197 case SHT_IA_64_VMS_LINKAGES
: return "VMS_LINKAGES";
4198 case SHT_IA_64_VMS_SYMBOL_VECTOR
: return "VMS_SYMBOL_VECTOR";
4199 case SHT_IA_64_VMS_FIXUP
: return "VMS_FIXUP";
4207 get_x86_64_section_type_name (unsigned int sh_type
)
4211 case SHT_X86_64_UNWIND
: return "X86_64_UNWIND";
4212 default: return NULL
;
4217 get_aarch64_section_type_name (unsigned int sh_type
)
4221 case SHT_AARCH64_ATTRIBUTES
: return "AARCH64_ATTRIBUTES";
4222 default: return NULL
;
4227 get_arm_section_type_name (unsigned int sh_type
)
4231 case SHT_ARM_EXIDX
: return "ARM_EXIDX";
4232 case SHT_ARM_PREEMPTMAP
: return "ARM_PREEMPTMAP";
4233 case SHT_ARM_ATTRIBUTES
: return "ARM_ATTRIBUTES";
4234 case SHT_ARM_DEBUGOVERLAY
: return "ARM_DEBUGOVERLAY";
4235 case SHT_ARM_OVERLAYSECTION
: return "ARM_OVERLAYSECTION";
4236 default: return NULL
;
4241 get_tic6x_section_type_name (unsigned int sh_type
)
4245 case SHT_C6000_UNWIND
: return "C6000_UNWIND";
4246 case SHT_C6000_PREEMPTMAP
: return "C6000_PREEMPTMAP";
4247 case SHT_C6000_ATTRIBUTES
: return "C6000_ATTRIBUTES";
4248 case SHT_TI_ICODE
: return "TI_ICODE";
4249 case SHT_TI_XREF
: return "TI_XREF";
4250 case SHT_TI_HANDLER
: return "TI_HANDLER";
4251 case SHT_TI_INITINFO
: return "TI_INITINFO";
4252 case SHT_TI_PHATTRS
: return "TI_PHATTRS";
4253 default: return NULL
;
4258 get_msp430x_section_type_name (unsigned int sh_type
)
4262 case SHT_MSP430_SEC_FLAGS
: return "MSP430_SEC_FLAGS";
4263 case SHT_MSP430_SYM_ALIASES
: return "MSP430_SYM_ALIASES";
4264 case SHT_MSP430_ATTRIBUTES
: return "MSP430_ATTRIBUTES";
4265 default: return NULL
;
4270 get_nfp_section_type_name (unsigned int sh_type
)
4274 case SHT_NFP_MECONFIG
: return "NFP_MECONFIG";
4275 case SHT_NFP_INITREG
: return "NFP_INITREG";
4276 case SHT_NFP_UDEBUG
: return "NFP_UDEBUG";
4277 default: return NULL
;
4282 get_v850_section_type_name (unsigned int sh_type
)
4286 case SHT_V850_SCOMMON
: return "V850 Small Common";
4287 case SHT_V850_TCOMMON
: return "V850 Tiny Common";
4288 case SHT_V850_ZCOMMON
: return "V850 Zero Common";
4289 case SHT_RENESAS_IOP
: return "RENESAS IOP";
4290 case SHT_RENESAS_INFO
: return "RENESAS INFO";
4291 default: return NULL
;
4296 get_riscv_section_type_name (unsigned int sh_type
)
4300 case SHT_RISCV_ATTRIBUTES
: return "RISCV_ATTRIBUTES";
4301 default: return NULL
;
4306 get_section_type_name (Filedata
* filedata
, unsigned int sh_type
)
4308 static char buff
[32];
4309 const char * result
;
4313 case SHT_NULL
: return "NULL";
4314 case SHT_PROGBITS
: return "PROGBITS";
4315 case SHT_SYMTAB
: return "SYMTAB";
4316 case SHT_STRTAB
: return "STRTAB";
4317 case SHT_RELA
: return "RELA";
4318 case SHT_HASH
: return "HASH";
4319 case SHT_DYNAMIC
: return "DYNAMIC";
4320 case SHT_NOTE
: return "NOTE";
4321 case SHT_NOBITS
: return "NOBITS";
4322 case SHT_REL
: return "REL";
4323 case SHT_SHLIB
: return "SHLIB";
4324 case SHT_DYNSYM
: return "DYNSYM";
4325 case SHT_INIT_ARRAY
: return "INIT_ARRAY";
4326 case SHT_FINI_ARRAY
: return "FINI_ARRAY";
4327 case SHT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
4328 case SHT_GNU_HASH
: return "GNU_HASH";
4329 case SHT_GROUP
: return "GROUP";
4330 case SHT_SYMTAB_SHNDX
: return "SYMTAB SECTION INDICES";
4331 case SHT_GNU_verdef
: return "VERDEF";
4332 case SHT_GNU_verneed
: return "VERNEED";
4333 case SHT_GNU_versym
: return "VERSYM";
4334 case 0x6ffffff0: return "VERSYM";
4335 case 0x6ffffffc: return "VERDEF";
4336 case 0x7ffffffd: return "AUXILIARY";
4337 case 0x7fffffff: return "FILTER";
4338 case SHT_GNU_LIBLIST
: return "GNU_LIBLIST";
4341 if ((sh_type
>= SHT_LOPROC
) && (sh_type
<= SHT_HIPROC
))
4343 switch (filedata
->file_header
.e_machine
)
4346 case EM_ARC_COMPACT
:
4347 case EM_ARC_COMPACT2
:
4348 result
= get_arc_section_type_name (sh_type
);
4351 case EM_MIPS_RS3_LE
:
4352 result
= get_mips_section_type_name (sh_type
);
4355 result
= get_parisc_section_type_name (sh_type
);
4358 result
= get_ia64_section_type_name (filedata
, sh_type
);
4363 result
= get_x86_64_section_type_name (sh_type
);
4366 result
= get_aarch64_section_type_name (sh_type
);
4369 result
= get_arm_section_type_name (sh_type
);
4372 result
= get_tic6x_section_type_name (sh_type
);
4375 result
= get_msp430x_section_type_name (sh_type
);
4378 result
= get_nfp_section_type_name (sh_type
);
4382 case EM_CYGNUS_V850
:
4383 result
= get_v850_section_type_name (sh_type
);
4386 result
= get_riscv_section_type_name (sh_type
);
4396 sprintf (buff
, "LOPROC+%#x", sh_type
- SHT_LOPROC
);
4398 else if ((sh_type
>= SHT_LOOS
) && (sh_type
<= SHT_HIOS
))
4400 switch (filedata
->file_header
.e_machine
)
4403 result
= get_ia64_section_type_name (filedata
, sh_type
);
4406 if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_SOLARIS
)
4407 result
= get_solaris_section_type (sh_type
);
4412 case SHT_GNU_INCREMENTAL_INPUTS
: result
= "GNU_INCREMENTAL_INPUTS"; break;
4413 case SHT_GNU_ATTRIBUTES
: result
= "GNU_ATTRIBUTES"; break;
4414 case SHT_GNU_HASH
: result
= "GNU_HASH"; break;
4415 case SHT_GNU_LIBLIST
: result
= "GNU_LIBLIST"; break;
4427 sprintf (buff
, "LOOS+%#x", sh_type
- SHT_LOOS
);
4429 else if ((sh_type
>= SHT_LOUSER
) && (sh_type
<= SHT_HIUSER
))
4431 switch (filedata
->file_header
.e_machine
)
4435 case EM_CYGNUS_V850
:
4436 result
= get_v850_section_type_name (sh_type
);
4446 sprintf (buff
, "LOUSER+%#x", sh_type
- SHT_LOUSER
);
4449 /* This message is probably going to be displayed in a 15
4450 character wide field, so put the hex value first. */
4451 snprintf (buff
, sizeof (buff
), _("%08x: <unknown>"), sh_type
);
4457 #define OPTION_DEBUG_DUMP 512
4458 #define OPTION_DYN_SYMS 513
4459 #define OPTION_DWARF_DEPTH 514
4460 #define OPTION_DWARF_START 515
4461 #define OPTION_DWARF_CHECK 516
4462 #define OPTION_CTF_DUMP 517
4463 #define OPTION_CTF_PARENT 518
4464 #define OPTION_CTF_SYMBOLS 519
4465 #define OPTION_CTF_STRINGS 520
4467 static struct option options
[] =
4469 {"all", no_argument
, 0, 'a'},
4470 {"file-header", no_argument
, 0, 'h'},
4471 {"program-headers", no_argument
, 0, 'l'},
4472 {"headers", no_argument
, 0, 'e'},
4473 {"histogram", no_argument
, 0, 'I'},
4474 {"segments", no_argument
, 0, 'l'},
4475 {"sections", no_argument
, 0, 'S'},
4476 {"section-headers", no_argument
, 0, 'S'},
4477 {"section-groups", no_argument
, 0, 'g'},
4478 {"section-details", no_argument
, 0, 't'},
4479 {"full-section-name",no_argument
, 0, 'N'},
4480 {"symbols", no_argument
, 0, 's'},
4481 {"syms", no_argument
, 0, 's'},
4482 {"dyn-syms", no_argument
, 0, OPTION_DYN_SYMS
},
4483 {"relocs", no_argument
, 0, 'r'},
4484 {"notes", no_argument
, 0, 'n'},
4485 {"dynamic", no_argument
, 0, 'd'},
4486 {"arch-specific", no_argument
, 0, 'A'},
4487 {"version-info", no_argument
, 0, 'V'},
4488 {"use-dynamic", no_argument
, 0, 'D'},
4489 {"unwind", no_argument
, 0, 'u'},
4490 {"archive-index", no_argument
, 0, 'c'},
4491 {"hex-dump", required_argument
, 0, 'x'},
4492 {"relocated-dump", required_argument
, 0, 'R'},
4493 {"string-dump", required_argument
, 0, 'p'},
4494 {"decompress", no_argument
, 0, 'z'},
4495 #ifdef SUPPORT_DISASSEMBLY
4496 {"instruction-dump", required_argument
, 0, 'i'},
4498 {"debug-dump", optional_argument
, 0, OPTION_DEBUG_DUMP
},
4500 {"dwarf-depth", required_argument
, 0, OPTION_DWARF_DEPTH
},
4501 {"dwarf-start", required_argument
, 0, OPTION_DWARF_START
},
4502 {"dwarf-check", no_argument
, 0, OPTION_DWARF_CHECK
},
4504 {"ctf", required_argument
, 0, OPTION_CTF_DUMP
},
4506 {"ctf-symbols", required_argument
, 0, OPTION_CTF_SYMBOLS
},
4507 {"ctf-strings", required_argument
, 0, OPTION_CTF_STRINGS
},
4508 {"ctf-parent", required_argument
, 0, OPTION_CTF_PARENT
},
4510 {"version", no_argument
, 0, 'v'},
4511 {"wide", no_argument
, 0, 'W'},
4512 {"help", no_argument
, 0, 'H'},
4513 {0, no_argument
, 0, 0}
4517 usage (FILE * stream
)
4519 fprintf (stream
, _("Usage: readelf <option(s)> elf-file(s)\n"));
4520 fprintf (stream
, _(" Display information about the contents of ELF format files\n"));
4521 fprintf (stream
, _(" Options are:\n\
4522 -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n\
4523 -h --file-header Display the ELF file header\n\
4524 -l --program-headers Display the program headers\n\
4525 --segments An alias for --program-headers\n\
4526 -S --section-headers Display the sections' header\n\
4527 --sections An alias for --section-headers\n\
4528 -g --section-groups Display the section groups\n\
4529 -t --section-details Display the section details\n\
4530 -e --headers Equivalent to: -h -l -S\n\
4531 -s --syms Display the symbol table\n\
4532 --symbols An alias for --syms\n\
4533 --dyn-syms Display the dynamic symbol table\n\
4534 -n --notes Display the core notes (if present)\n\
4535 -r --relocs Display the relocations (if present)\n\
4536 -u --unwind Display the unwind info (if present)\n\
4537 -d --dynamic Display the dynamic section (if present)\n\
4538 -V --version-info Display the version sections (if present)\n\
4539 -A --arch-specific Display architecture specific information (if any)\n\
4540 -c --archive-index Display the symbol/file index in an archive\n\
4541 -D --use-dynamic Use the dynamic section info when displaying symbols\n\
4542 -x --hex-dump=<number|name>\n\
4543 Dump the contents of section <number|name> as bytes\n\
4544 -p --string-dump=<number|name>\n\
4545 Dump the contents of section <number|name> as strings\n\
4546 -R --relocated-dump=<number|name>\n\
4547 Dump the contents of section <number|name> as relocated bytes\n\
4548 -z --decompress Decompress section before dumping it\n\
4549 -w[lLiaprmfFsoRtUuTgAckK] or\n\
4550 --debug-dump[=rawline,=decodedline,=info,=abbrev,=pubnames,=aranges,=macro,=frames,\n\
4551 =frames-interp,=str,=loc,=Ranges,=pubtypes,\n\
4552 =gdb_index,=trace_info,=trace_abbrev,=trace_aranges,\n\
4553 =addr,=cu_index,=links,=follow-links]\n\
4554 Display the contents of DWARF debug sections\n"));
4555 fprintf (stream
, _("\
4556 --dwarf-depth=N Do not display DIEs at depth N or greater\n\
4557 --dwarf-start=N Display DIEs starting with N, at the same depth\n\
4559 fprintf (stream
, _("\
4560 --ctf=<number|name> Display CTF info from section <number|name>\n\
4561 --ctf-parent=<number|name>\n\
4562 Use section <number|name> as the CTF parent\n\n\
4563 --ctf-symbols=<number|name>\n\
4564 Use section <number|name> as the CTF external symtab\n\n\
4565 --ctf-strings=<number|name>\n\
4566 Use section <number|name> as the CTF external strtab\n\n"));
4568 #ifdef SUPPORT_DISASSEMBLY
4569 fprintf (stream
, _("\
4570 -i --instruction-dump=<number|name>\n\
4571 Disassemble the contents of section <number|name>\n"));
4573 fprintf (stream
, _("\
4574 -I --histogram Display histogram of bucket list lengths\n\
4575 -W --wide Allow output width to exceed 80 characters\n\
4576 @<file> Read options from <file>\n\
4577 -H --help Display this information\n\
4578 -v --version Display the version number of readelf\n"));
4580 if (REPORT_BUGS_TO
[0] && stream
== stdout
)
4581 fprintf (stdout
, _("Report bugs to %s\n"), REPORT_BUGS_TO
);
4583 exit (stream
== stdout
? 0 : 1);
4586 /* Record the fact that the user wants the contents of section number
4587 SECTION to be displayed using the method(s) encoded as flags bits
4588 in TYPE. Note, TYPE can be zero if we are creating the array for
4592 request_dump_bynumber (Filedata
* filedata
, unsigned int section
, dump_type type
)
4594 if (section
>= filedata
->num_dump_sects
)
4596 dump_type
* new_dump_sects
;
4598 new_dump_sects
= (dump_type
*) calloc (section
+ 1,
4599 sizeof (* new_dump_sects
));
4601 if (new_dump_sects
== NULL
)
4602 error (_("Out of memory allocating dump request table.\n"));
4605 if (filedata
->dump_sects
)
4607 /* Copy current flag settings. */
4608 memcpy (new_dump_sects
, filedata
->dump_sects
,
4609 filedata
->num_dump_sects
* sizeof (* new_dump_sects
));
4611 free (filedata
->dump_sects
);
4614 filedata
->dump_sects
= new_dump_sects
;
4615 filedata
->num_dump_sects
= section
+ 1;
4619 if (filedata
->dump_sects
)
4620 filedata
->dump_sects
[section
] |= type
;
4623 /* Request a dump by section name. */
4626 request_dump_byname (const char * section
, dump_type type
)
4628 struct dump_list_entry
* new_request
;
4630 new_request
= (struct dump_list_entry
*)
4631 malloc (sizeof (struct dump_list_entry
));
4633 error (_("Out of memory allocating dump request table.\n"));
4635 new_request
->name
= strdup (section
);
4636 if (!new_request
->name
)
4637 error (_("Out of memory allocating dump request table.\n"));
4639 new_request
->type
= type
;
4641 new_request
->next
= dump_sects_byname
;
4642 dump_sects_byname
= new_request
;
4646 request_dump (Filedata
* filedata
, dump_type type
)
4652 section
= strtoul (optarg
, & cp
, 0);
4654 if (! *cp
&& section
>= 0)
4655 request_dump_bynumber (filedata
, section
, type
);
4657 request_dump_byname (optarg
, type
);
4661 parse_args (Filedata
* filedata
, int argc
, char ** argv
)
4668 while ((c
= getopt_long
4669 (argc
, argv
, "ADHINR:SVWacdeghi:lnp:rstuvw::x:z", options
, NULL
)) != EOF
)
4687 do_section_groups
= TRUE
;
4690 do_histogram
= TRUE
;
4695 do_section_groups
= TRUE
;
4700 do_section_details
= TRUE
;
4711 do_using_dynamic
= TRUE
;
4735 do_histogram
= TRUE
;
4741 do_archive_index
= TRUE
;
4744 request_dump (filedata
, HEX_DUMP
);
4747 request_dump (filedata
, STRING_DUMP
);
4750 request_dump (filedata
, RELOC_DUMP
);
4753 decompress_dumps
= TRUE
;
4759 do_debugging
= TRUE
;
4760 dwarf_select_sections_all ();
4764 do_debugging
= FALSE
;
4765 dwarf_select_sections_by_letters (optarg
);
4768 case OPTION_DEBUG_DUMP
:
4771 do_debugging
= TRUE
;
4774 do_debugging
= FALSE
;
4775 dwarf_select_sections_by_names (optarg
);
4778 case OPTION_DWARF_DEPTH
:
4782 dwarf_cutoff_level
= strtoul (optarg
, & cp
, 0);
4785 case OPTION_DWARF_START
:
4789 dwarf_start_die
= strtoul (optarg
, & cp
, 0);
4792 case OPTION_DWARF_CHECK
:
4795 case OPTION_CTF_DUMP
:
4797 request_dump (filedata
, CTF_DUMP
);
4799 case OPTION_CTF_SYMBOLS
:
4800 dump_ctf_symtab_name
= strdup (optarg
);
4802 case OPTION_CTF_STRINGS
:
4803 dump_ctf_strtab_name
= strdup (optarg
);
4805 case OPTION_CTF_PARENT
:
4806 dump_ctf_parent_name
= strdup (optarg
);
4808 case OPTION_DYN_SYMS
:
4811 #ifdef SUPPORT_DISASSEMBLY
4813 request_dump (filedata
, DISASS_DUMP
);
4817 print_version (program_name
);
4826 /* xgettext:c-format */
4827 error (_("Invalid option '-%c'\n"), c
);
4834 if (!do_dynamic
&& !do_syms
&& !do_reloc
&& !do_unwind
&& !do_sections
4835 && !do_segments
&& !do_header
&& !do_dump
&& !do_version
4836 && !do_histogram
&& !do_debugging
&& !do_arch
&& !do_notes
4837 && !do_section_groups
&& !do_archive_index
4843 get_elf_class (unsigned int elf_class
)
4845 static char buff
[32];
4849 case ELFCLASSNONE
: return _("none");
4850 case ELFCLASS32
: return "ELF32";
4851 case ELFCLASS64
: return "ELF64";
4853 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), elf_class
);
4859 get_data_encoding (unsigned int encoding
)
4861 static char buff
[32];
4865 case ELFDATANONE
: return _("none");
4866 case ELFDATA2LSB
: return _("2's complement, little endian");
4867 case ELFDATA2MSB
: return _("2's complement, big endian");
4869 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), encoding
);
4874 /* Decode the data held in 'filedata->file_header'. */
4877 process_file_header (Filedata
* filedata
)
4879 Elf_Internal_Ehdr
* header
= & filedata
->file_header
;
4881 if ( header
->e_ident
[EI_MAG0
] != ELFMAG0
4882 || header
->e_ident
[EI_MAG1
] != ELFMAG1
4883 || header
->e_ident
[EI_MAG2
] != ELFMAG2
4884 || header
->e_ident
[EI_MAG3
] != ELFMAG3
)
4887 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
4891 init_dwarf_regnames_by_elf_machine_code (header
->e_machine
);
4897 printf (_("ELF Header:\n"));
4898 printf (_(" Magic: "));
4899 for (i
= 0; i
< EI_NIDENT
; i
++)
4900 printf ("%2.2x ", header
->e_ident
[i
]);
4902 printf (_(" Class: %s\n"),
4903 get_elf_class (header
->e_ident
[EI_CLASS
]));
4904 printf (_(" Data: %s\n"),
4905 get_data_encoding (header
->e_ident
[EI_DATA
]));
4906 printf (_(" Version: %d%s\n"),
4907 header
->e_ident
[EI_VERSION
],
4908 (header
->e_ident
[EI_VERSION
] == EV_CURRENT
4910 : (header
->e_ident
[EI_VERSION
] != EV_NONE
4913 printf (_(" OS/ABI: %s\n"),
4914 get_osabi_name (filedata
, header
->e_ident
[EI_OSABI
]));
4915 printf (_(" ABI Version: %d\n"),
4916 header
->e_ident
[EI_ABIVERSION
]);
4917 printf (_(" Type: %s\n"),
4918 get_file_type (header
->e_type
));
4919 printf (_(" Machine: %s\n"),
4920 get_machine_name (header
->e_machine
));
4921 printf (_(" Version: 0x%lx\n"),
4924 printf (_(" Entry point address: "));
4925 print_vma (header
->e_entry
, PREFIX_HEX
);
4926 printf (_("\n Start of program headers: "));
4927 print_vma (header
->e_phoff
, DEC
);
4928 printf (_(" (bytes into file)\n Start of section headers: "));
4929 print_vma (header
->e_shoff
, DEC
);
4930 printf (_(" (bytes into file)\n"));
4932 printf (_(" Flags: 0x%lx%s\n"),
4934 get_machine_flags (filedata
, header
->e_flags
, header
->e_machine
));
4935 printf (_(" Size of this header: %u (bytes)\n"),
4937 printf (_(" Size of program headers: %u (bytes)\n"),
4938 header
->e_phentsize
);
4939 printf (_(" Number of program headers: %u"),
4941 if (filedata
->section_headers
!= NULL
4942 && header
->e_phnum
== PN_XNUM
4943 && filedata
->section_headers
[0].sh_info
!= 0)
4945 header
->e_phnum
= filedata
->section_headers
[0].sh_info
;
4946 printf (" (%u)", header
->e_phnum
);
4948 putc ('\n', stdout
);
4949 printf (_(" Size of section headers: %u (bytes)\n"),
4950 header
->e_shentsize
);
4951 printf (_(" Number of section headers: %u"),
4953 if (filedata
->section_headers
!= NULL
&& header
->e_shnum
== SHN_UNDEF
)
4955 header
->e_shnum
= filedata
->section_headers
[0].sh_size
;
4956 printf (" (%u)", header
->e_shnum
);
4958 putc ('\n', stdout
);
4959 printf (_(" Section header string table index: %u"),
4960 header
->e_shstrndx
);
4961 if (filedata
->section_headers
!= NULL
4962 && header
->e_shstrndx
== (SHN_XINDEX
& 0xffff))
4964 header
->e_shstrndx
= filedata
->section_headers
[0].sh_link
;
4965 printf (" (%u)", header
->e_shstrndx
);
4967 if (header
->e_shstrndx
!= SHN_UNDEF
4968 && header
->e_shstrndx
>= header
->e_shnum
)
4970 header
->e_shstrndx
= SHN_UNDEF
;
4971 printf (_(" <corrupt: out of range>"));
4973 putc ('\n', stdout
);
4976 if (filedata
->section_headers
!= NULL
)
4978 if (header
->e_phnum
== PN_XNUM
4979 && filedata
->section_headers
[0].sh_info
!= 0)
4980 header
->e_phnum
= filedata
->section_headers
[0].sh_info
;
4981 if (header
->e_shnum
== SHN_UNDEF
)
4982 header
->e_shnum
= filedata
->section_headers
[0].sh_size
;
4983 if (header
->e_shstrndx
== (SHN_XINDEX
& 0xffff))
4984 header
->e_shstrndx
= filedata
->section_headers
[0].sh_link
;
4985 if (header
->e_shstrndx
>= header
->e_shnum
)
4986 header
->e_shstrndx
= SHN_UNDEF
;
4987 free (filedata
->section_headers
);
4988 filedata
->section_headers
= NULL
;
4994 /* Read in the program headers from FILEDATA and store them in PHEADERS.
4995 Returns TRUE upon success, FALSE otherwise. Loads 32-bit headers. */
4998 get_32bit_program_headers (Filedata
* filedata
, Elf_Internal_Phdr
* pheaders
)
5000 Elf32_External_Phdr
* phdrs
;
5001 Elf32_External_Phdr
* external
;
5002 Elf_Internal_Phdr
* internal
;
5004 unsigned int size
= filedata
->file_header
.e_phentsize
;
5005 unsigned int num
= filedata
->file_header
.e_phnum
;
5007 /* PR binutils/17531: Cope with unexpected section header sizes. */
5008 if (size
== 0 || num
== 0)
5010 if (size
< sizeof * phdrs
)
5012 error (_("The e_phentsize field in the ELF header is less than the size of an ELF program header\n"));
5015 if (size
> sizeof * phdrs
)
5016 warn (_("The e_phentsize field in the ELF header is larger than the size of an ELF program header\n"));
5018 phdrs
= (Elf32_External_Phdr
*) get_data (NULL
, filedata
, filedata
->file_header
.e_phoff
,
5019 size
, num
, _("program headers"));
5023 for (i
= 0, internal
= pheaders
, external
= phdrs
;
5024 i
< filedata
->file_header
.e_phnum
;
5025 i
++, internal
++, external
++)
5027 internal
->p_type
= BYTE_GET (external
->p_type
);
5028 internal
->p_offset
= BYTE_GET (external
->p_offset
);
5029 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
5030 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
5031 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
5032 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
5033 internal
->p_flags
= BYTE_GET (external
->p_flags
);
5034 internal
->p_align
= BYTE_GET (external
->p_align
);
5041 /* Read in the program headers from FILEDATA and store them in PHEADERS.
5042 Returns TRUE upon success, FALSE otherwise. Loads 64-bit headers. */
5045 get_64bit_program_headers (Filedata
* filedata
, Elf_Internal_Phdr
* pheaders
)
5047 Elf64_External_Phdr
* phdrs
;
5048 Elf64_External_Phdr
* external
;
5049 Elf_Internal_Phdr
* internal
;
5051 unsigned int size
= filedata
->file_header
.e_phentsize
;
5052 unsigned int num
= filedata
->file_header
.e_phnum
;
5054 /* PR binutils/17531: Cope with unexpected section header sizes. */
5055 if (size
== 0 || num
== 0)
5057 if (size
< sizeof * phdrs
)
5059 error (_("The e_phentsize field in the ELF header is less than the size of an ELF program header\n"));
5062 if (size
> sizeof * phdrs
)
5063 warn (_("The e_phentsize field in the ELF header is larger than the size of an ELF program header\n"));
5065 phdrs
= (Elf64_External_Phdr
*) get_data (NULL
, filedata
, filedata
->file_header
.e_phoff
,
5066 size
, num
, _("program headers"));
5070 for (i
= 0, internal
= pheaders
, external
= phdrs
;
5071 i
< filedata
->file_header
.e_phnum
;
5072 i
++, internal
++, external
++)
5074 internal
->p_type
= BYTE_GET (external
->p_type
);
5075 internal
->p_flags
= BYTE_GET (external
->p_flags
);
5076 internal
->p_offset
= BYTE_GET (external
->p_offset
);
5077 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
5078 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
5079 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
5080 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
5081 internal
->p_align
= BYTE_GET (external
->p_align
);
5088 /* Returns TRUE if the program headers were read into `program_headers'. */
5091 get_program_headers (Filedata
* filedata
)
5093 Elf_Internal_Phdr
* phdrs
;
5095 /* Check cache of prior read. */
5096 if (filedata
->program_headers
!= NULL
)
5099 /* Be kind to memory checkers by looking for
5100 e_phnum values which we know must be invalid. */
5101 if (filedata
->file_header
.e_phnum
5102 * (is_32bit_elf
? sizeof (Elf32_External_Phdr
) : sizeof (Elf64_External_Phdr
))
5103 >= filedata
->file_size
)
5105 error (_("Too many program headers - %#x - the file is not that big\n"),
5106 filedata
->file_header
.e_phnum
);
5110 phdrs
= (Elf_Internal_Phdr
*) cmalloc (filedata
->file_header
.e_phnum
,
5111 sizeof (Elf_Internal_Phdr
));
5114 error (_("Out of memory reading %u program headers\n"),
5115 filedata
->file_header
.e_phnum
);
5120 ? get_32bit_program_headers (filedata
, phdrs
)
5121 : get_64bit_program_headers (filedata
, phdrs
))
5123 filedata
->program_headers
= phdrs
;
5131 /* Returns TRUE if the program headers were loaded. */
5134 process_program_headers (Filedata
* filedata
)
5136 Elf_Internal_Phdr
* segment
;
5138 Elf_Internal_Phdr
* previous_load
= NULL
;
5143 if (filedata
->file_header
.e_phnum
== 0)
5145 /* PR binutils/12467. */
5146 if (filedata
->file_header
.e_phoff
!= 0)
5148 warn (_("possibly corrupt ELF header - it has a non-zero program"
5149 " header offset, but no program headers\n"));
5152 else if (do_segments
)
5153 printf (_("\nThere are no program headers in this file.\n"));
5157 if (do_segments
&& !do_header
)
5159 printf (_("\nElf file type is %s\n"), get_file_type (filedata
->file_header
.e_type
));
5160 printf (_("Entry point 0x%s\n"), bfd_vmatoa ("x", filedata
->file_header
.e_entry
));
5161 printf (ngettext ("There is %d program header, starting at offset %s\n",
5162 "There are %d program headers, starting at offset %s\n",
5163 filedata
->file_header
.e_phnum
),
5164 filedata
->file_header
.e_phnum
,
5165 bfd_vmatoa ("u", filedata
->file_header
.e_phoff
));
5168 if (! get_program_headers (filedata
))
5173 if (filedata
->file_header
.e_phnum
> 1)
5174 printf (_("\nProgram Headers:\n"));
5176 printf (_("\nProgram Headers:\n"));
5180 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
5183 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
5187 (_(" Type Offset VirtAddr PhysAddr\n"));
5189 (_(" FileSiz MemSiz Flags Align\n"));
5193 for (i
= 0, segment
= filedata
->program_headers
;
5194 i
< filedata
->file_header
.e_phnum
;
5199 printf (" %-14.14s ", get_segment_type (filedata
, segment
->p_type
));
5203 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
5204 printf ("0x%8.8lx ", (unsigned long) segment
->p_vaddr
);
5205 printf ("0x%8.8lx ", (unsigned long) segment
->p_paddr
);
5206 printf ("0x%5.5lx ", (unsigned long) segment
->p_filesz
);
5207 printf ("0x%5.5lx ", (unsigned long) segment
->p_memsz
);
5209 (segment
->p_flags
& PF_R
? 'R' : ' '),
5210 (segment
->p_flags
& PF_W
? 'W' : ' '),
5211 (segment
->p_flags
& PF_X
? 'E' : ' '));
5212 printf ("%#lx", (unsigned long) segment
->p_align
);
5216 if ((unsigned long) segment
->p_offset
== segment
->p_offset
)
5217 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
5220 print_vma (segment
->p_offset
, FULL_HEX
);
5224 print_vma (segment
->p_vaddr
, FULL_HEX
);
5226 print_vma (segment
->p_paddr
, FULL_HEX
);
5229 if ((unsigned long) segment
->p_filesz
== segment
->p_filesz
)
5230 printf ("0x%6.6lx ", (unsigned long) segment
->p_filesz
);
5233 print_vma (segment
->p_filesz
, FULL_HEX
);
5237 if ((unsigned long) segment
->p_memsz
== segment
->p_memsz
)
5238 printf ("0x%6.6lx", (unsigned long) segment
->p_memsz
);
5241 print_vma (segment
->p_memsz
, FULL_HEX
);
5245 (segment
->p_flags
& PF_R
? 'R' : ' '),
5246 (segment
->p_flags
& PF_W
? 'W' : ' '),
5247 (segment
->p_flags
& PF_X
? 'E' : ' '));
5249 if ((unsigned long) segment
->p_align
== segment
->p_align
)
5250 printf ("%#lx", (unsigned long) segment
->p_align
);
5253 print_vma (segment
->p_align
, PREFIX_HEX
);
5258 print_vma (segment
->p_offset
, FULL_HEX
);
5260 print_vma (segment
->p_vaddr
, FULL_HEX
);
5262 print_vma (segment
->p_paddr
, FULL_HEX
);
5264 print_vma (segment
->p_filesz
, FULL_HEX
);
5266 print_vma (segment
->p_memsz
, FULL_HEX
);
5268 (segment
->p_flags
& PF_R
? 'R' : ' '),
5269 (segment
->p_flags
& PF_W
? 'W' : ' '),
5270 (segment
->p_flags
& PF_X
? 'E' : ' '));
5271 print_vma (segment
->p_align
, PREFIX_HEX
);
5274 putc ('\n', stdout
);
5277 switch (segment
->p_type
)
5280 #if 0 /* Do not warn about out of order PT_LOAD segments. Although officially
5281 required by the ELF standard, several programs, including the Linux
5282 kernel, make use of non-ordered segments. */
5284 && previous_load
->p_vaddr
> segment
->p_vaddr
)
5285 error (_("LOAD segments must be sorted in order of increasing VirtAddr\n"));
5287 if (segment
->p_memsz
< segment
->p_filesz
)
5288 error (_("the segment's file size is larger than its memory size\n"));
5289 previous_load
= segment
;
5293 /* PR 20815 - Verify that the program header is loaded into memory. */
5294 if (i
> 0 && previous_load
!= NULL
)
5295 error (_("the PHDR segment must occur before any LOAD segment\n"));
5296 if (filedata
->file_header
.e_machine
!= EM_PARISC
)
5300 for (j
= 1; j
< filedata
->file_header
.e_phnum
; j
++)
5302 Elf_Internal_Phdr
*load
= filedata
->program_headers
+ j
;
5303 if (load
->p_type
== PT_LOAD
5304 && load
->p_offset
<= segment
->p_offset
5305 && (load
->p_offset
+ load
->p_filesz
5306 >= segment
->p_offset
+ segment
->p_filesz
)
5307 && load
->p_vaddr
<= segment
->p_vaddr
5308 && (load
->p_vaddr
+ load
->p_filesz
5309 >= segment
->p_vaddr
+ segment
->p_filesz
))
5312 if (j
== filedata
->file_header
.e_phnum
)
5313 error (_("the PHDR segment is not covered by a LOAD segment\n"));
5319 error (_("more than one dynamic segment\n"));
5321 /* By default, assume that the .dynamic section is the first
5322 section in the DYNAMIC segment. */
5323 dynamic_addr
= segment
->p_offset
;
5324 dynamic_size
= segment
->p_filesz
;
5326 /* Try to locate the .dynamic section. If there is
5327 a section header table, we can easily locate it. */
5328 if (filedata
->section_headers
!= NULL
)
5330 Elf_Internal_Shdr
* sec
;
5332 sec
= find_section (filedata
, ".dynamic");
5333 if (sec
== NULL
|| sec
->sh_size
== 0)
5335 /* A corresponding .dynamic section is expected, but on
5336 IA-64/OpenVMS it is OK for it to be missing. */
5337 if (!is_ia64_vms (filedata
))
5338 error (_("no .dynamic section in the dynamic segment\n"));
5342 if (sec
->sh_type
== SHT_NOBITS
)
5348 dynamic_addr
= sec
->sh_offset
;
5349 dynamic_size
= sec
->sh_size
;
5351 if (dynamic_addr
< segment
->p_offset
5352 || dynamic_addr
> segment
->p_offset
+ segment
->p_filesz
)
5353 warn (_("the .dynamic section is not contained"
5354 " within the dynamic segment\n"));
5355 else if (dynamic_addr
> segment
->p_offset
)
5356 warn (_("the .dynamic section is not the first section"
5357 " in the dynamic segment.\n"));
5360 /* PR binutils/17512: Avoid corrupt dynamic section info in the
5361 segment. Check this after matching against the section headers
5362 so we don't warn on debuginfo file (which have NOBITS .dynamic
5364 if (dynamic_addr
> filedata
->file_size
5365 || dynamic_size
> filedata
->file_size
- dynamic_addr
)
5367 error (_("the dynamic segment offset + size exceeds the size of the file\n"));
5368 dynamic_addr
= dynamic_size
= 0;
5373 if (fseek (filedata
->handle
, archive_file_offset
+ (long) segment
->p_offset
,
5375 error (_("Unable to find program interpreter name\n"));
5379 int ret
= snprintf (fmt
, sizeof (fmt
), "%%%ds", PATH_MAX
- 1);
5381 if (ret
>= (int) sizeof (fmt
) || ret
< 0)
5382 error (_("Internal error: failed to create format string to display program interpreter\n"));
5384 program_interpreter
[0] = 0;
5385 if (fscanf (filedata
->handle
, fmt
, program_interpreter
) <= 0)
5386 error (_("Unable to read program interpreter name\n"));
5389 printf (_(" [Requesting program interpreter: %s]\n"),
5390 program_interpreter
);
5397 && filedata
->section_headers
!= NULL
5398 && filedata
->string_table
!= NULL
)
5400 printf (_("\n Section to Segment mapping:\n"));
5401 printf (_(" Segment Sections...\n"));
5403 for (i
= 0; i
< filedata
->file_header
.e_phnum
; i
++)
5406 Elf_Internal_Shdr
* section
;
5408 segment
= filedata
->program_headers
+ i
;
5409 section
= filedata
->section_headers
+ 1;
5411 printf (" %2.2d ", i
);
5413 for (j
= 1; j
< filedata
->file_header
.e_shnum
; j
++, section
++)
5415 if (!ELF_TBSS_SPECIAL (section
, segment
)
5416 && ELF_SECTION_IN_SEGMENT_STRICT (section
, segment
))
5417 printf ("%s ", printable_section_name (filedata
, section
));
5428 /* Find the file offset corresponding to VMA by using the program headers. */
5431 offset_from_vma (Filedata
* filedata
, bfd_vma vma
, bfd_size_type size
)
5433 Elf_Internal_Phdr
* seg
;
5435 if (! get_program_headers (filedata
))
5437 warn (_("Cannot interpret virtual addresses without program headers.\n"));
5441 for (seg
= filedata
->program_headers
;
5442 seg
< filedata
->program_headers
+ filedata
->file_header
.e_phnum
;
5445 if (seg
->p_type
!= PT_LOAD
)
5448 if (vma
>= (seg
->p_vaddr
& -seg
->p_align
)
5449 && vma
+ size
<= seg
->p_vaddr
+ seg
->p_filesz
)
5450 return vma
- seg
->p_vaddr
+ seg
->p_offset
;
5453 warn (_("Virtual address 0x%lx not located in any PT_LOAD segment.\n"),
5454 (unsigned long) vma
);
5459 /* Allocate memory and load the sections headers into FILEDATA->filedata->section_headers.
5460 If PROBE is true, this is just a probe and we do not generate any error
5461 messages if the load fails. */
5464 get_32bit_section_headers (Filedata
* filedata
, bfd_boolean probe
)
5466 Elf32_External_Shdr
* shdrs
;
5467 Elf_Internal_Shdr
* internal
;
5469 unsigned int size
= filedata
->file_header
.e_shentsize
;
5470 unsigned int num
= probe
? 1 : filedata
->file_header
.e_shnum
;
5472 /* PR binutils/17531: Cope with unexpected section header sizes. */
5473 if (size
== 0 || num
== 0)
5475 if (size
< sizeof * shdrs
)
5478 error (_("The e_shentsize field in the ELF header is less than the size of an ELF section header\n"));
5481 if (!probe
&& size
> sizeof * shdrs
)
5482 warn (_("The e_shentsize field in the ELF header is larger than the size of an ELF section header\n"));
5484 shdrs
= (Elf32_External_Shdr
*) get_data (NULL
, filedata
, filedata
->file_header
.e_shoff
,
5486 probe
? NULL
: _("section headers"));
5490 free (filedata
->section_headers
);
5491 filedata
->section_headers
= (Elf_Internal_Shdr
*)
5492 cmalloc (num
, sizeof (Elf_Internal_Shdr
));
5493 if (filedata
->section_headers
== NULL
)
5496 error (_("Out of memory reading %u section headers\n"), num
);
5501 for (i
= 0, internal
= filedata
->section_headers
;
5505 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
5506 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
5507 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
5508 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
5509 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
5510 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
5511 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
5512 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
5513 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
5514 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
5515 if (!probe
&& internal
->sh_link
> num
)
5516 warn (_("Section %u has an out of range sh_link value of %u\n"), i
, internal
->sh_link
);
5517 if (!probe
&& internal
->sh_flags
& SHF_INFO_LINK
&& internal
->sh_info
> num
)
5518 warn (_("Section %u has an out of range sh_info value of %u\n"), i
, internal
->sh_info
);
5525 /* Like get_32bit_section_headers, except that it fetches 64-bit headers. */
5528 get_64bit_section_headers (Filedata
* filedata
, bfd_boolean probe
)
5530 Elf64_External_Shdr
* shdrs
;
5531 Elf_Internal_Shdr
* internal
;
5533 unsigned int size
= filedata
->file_header
.e_shentsize
;
5534 unsigned int num
= probe
? 1 : filedata
->file_header
.e_shnum
;
5536 /* PR binutils/17531: Cope with unexpected section header sizes. */
5537 if (size
== 0 || num
== 0)
5540 if (size
< sizeof * shdrs
)
5543 error (_("The e_shentsize field in the ELF header is less than the size of an ELF section header\n"));
5547 if (! probe
&& size
> sizeof * shdrs
)
5548 warn (_("The e_shentsize field in the ELF header is larger than the size of an ELF section header\n"));
5550 shdrs
= (Elf64_External_Shdr
*) get_data (NULL
, filedata
,
5551 filedata
->file_header
.e_shoff
,
5553 probe
? NULL
: _("section headers"));
5557 free (filedata
->section_headers
);
5558 filedata
->section_headers
= (Elf_Internal_Shdr
*)
5559 cmalloc (num
, sizeof (Elf_Internal_Shdr
));
5560 if (filedata
->section_headers
== NULL
)
5563 error (_("Out of memory reading %u section headers\n"), num
);
5568 for (i
= 0, internal
= filedata
->section_headers
;
5572 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
5573 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
5574 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
5575 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
5576 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
5577 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
5578 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
5579 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
5580 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
5581 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
5582 if (!probe
&& internal
->sh_link
> num
)
5583 warn (_("Section %u has an out of range sh_link value of %u\n"), i
, internal
->sh_link
);
5584 if (!probe
&& internal
->sh_flags
& SHF_INFO_LINK
&& internal
->sh_info
> num
)
5585 warn (_("Section %u has an out of range sh_info value of %u\n"), i
, internal
->sh_info
);
5592 static Elf_Internal_Sym
*
5593 get_32bit_elf_symbols (Filedata
* filedata
,
5594 Elf_Internal_Shdr
* section
,
5595 unsigned long * num_syms_return
)
5597 unsigned long number
= 0;
5598 Elf32_External_Sym
* esyms
= NULL
;
5599 Elf_External_Sym_Shndx
* shndx
= NULL
;
5600 Elf_Internal_Sym
* isyms
= NULL
;
5601 Elf_Internal_Sym
* psym
;
5603 elf_section_list
* entry
;
5605 if (section
->sh_size
== 0)
5607 if (num_syms_return
!= NULL
)
5608 * num_syms_return
= 0;
5612 /* Run some sanity checks first. */
5613 if (section
->sh_entsize
== 0 || section
->sh_entsize
> section
->sh_size
)
5615 error (_("Section %s has an invalid sh_entsize of 0x%lx\n"),
5616 printable_section_name (filedata
, section
),
5617 (unsigned long) section
->sh_entsize
);
5621 if (section
->sh_size
> filedata
->file_size
)
5623 error (_("Section %s has an invalid sh_size of 0x%lx\n"),
5624 printable_section_name (filedata
, section
),
5625 (unsigned long) section
->sh_size
);
5629 number
= section
->sh_size
/ section
->sh_entsize
;
5631 if (number
* sizeof (Elf32_External_Sym
) > section
->sh_size
+ 1)
5633 error (_("Size (0x%lx) of section %s is not a multiple of its sh_entsize (0x%lx)\n"),
5634 (unsigned long) section
->sh_size
,
5635 printable_section_name (filedata
, section
),
5636 (unsigned long) section
->sh_entsize
);
5640 esyms
= (Elf32_External_Sym
*) get_data (NULL
, filedata
, section
->sh_offset
, 1,
5641 section
->sh_size
, _("symbols"));
5646 for (entry
= symtab_shndx_list
; entry
!= NULL
; entry
= entry
->next
)
5648 if (entry
->hdr
->sh_link
!= (unsigned long) (section
- filedata
->section_headers
))
5653 error (_("Multiple symbol table index sections associated with the same symbol section\n"));
5657 shndx
= (Elf_External_Sym_Shndx
*) get_data (NULL
, filedata
,
5658 entry
->hdr
->sh_offset
,
5659 1, entry
->hdr
->sh_size
,
5660 _("symbol table section indices"));
5664 /* PR17531: file: heap-buffer-overflow */
5665 if (entry
->hdr
->sh_size
/ sizeof (Elf_External_Sym_Shndx
) < number
)
5667 error (_("Index section %s has an sh_size of 0x%lx - expected 0x%lx\n"),
5668 printable_section_name (filedata
, entry
->hdr
),
5669 (unsigned long) entry
->hdr
->sh_size
,
5670 (unsigned long) section
->sh_size
);
5675 isyms
= (Elf_Internal_Sym
*) cmalloc (number
, sizeof (Elf_Internal_Sym
));
5679 error (_("Out of memory reading %lu symbols\n"),
5680 (unsigned long) number
);
5684 for (j
= 0, psym
= isyms
; j
< number
; j
++, psym
++)
5686 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
5687 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
5688 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
5689 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
5690 if (psym
->st_shndx
== (SHN_XINDEX
& 0xffff) && shndx
!= NULL
)
5692 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
5693 else if (psym
->st_shndx
>= (SHN_LORESERVE
& 0xffff))
5694 psym
->st_shndx
+= SHN_LORESERVE
- (SHN_LORESERVE
& 0xffff);
5695 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
5696 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
5703 if (num_syms_return
!= NULL
)
5704 * num_syms_return
= isyms
== NULL
? 0 : number
;
5709 static Elf_Internal_Sym
*
5710 get_64bit_elf_symbols (Filedata
* filedata
,
5711 Elf_Internal_Shdr
* section
,
5712 unsigned long * num_syms_return
)
5714 unsigned long number
= 0;
5715 Elf64_External_Sym
* esyms
= NULL
;
5716 Elf_External_Sym_Shndx
* shndx
= NULL
;
5717 Elf_Internal_Sym
* isyms
= NULL
;
5718 Elf_Internal_Sym
* psym
;
5720 elf_section_list
* entry
;
5722 if (section
->sh_size
== 0)
5724 if (num_syms_return
!= NULL
)
5725 * num_syms_return
= 0;
5729 /* Run some sanity checks first. */
5730 if (section
->sh_entsize
== 0 || section
->sh_entsize
> section
->sh_size
)
5732 error (_("Section %s has an invalid sh_entsize of 0x%lx\n"),
5733 printable_section_name (filedata
, section
),
5734 (unsigned long) section
->sh_entsize
);
5738 if (section
->sh_size
> filedata
->file_size
)
5740 error (_("Section %s has an invalid sh_size of 0x%lx\n"),
5741 printable_section_name (filedata
, section
),
5742 (unsigned long) section
->sh_size
);
5746 number
= section
->sh_size
/ section
->sh_entsize
;
5748 if (number
* sizeof (Elf64_External_Sym
) > section
->sh_size
+ 1)
5750 error (_("Size (0x%lx) of section %s is not a multiple of its sh_entsize (0x%lx)\n"),
5751 (unsigned long) section
->sh_size
,
5752 printable_section_name (filedata
, section
),
5753 (unsigned long) section
->sh_entsize
);
5757 esyms
= (Elf64_External_Sym
*) get_data (NULL
, filedata
, section
->sh_offset
, 1,
5758 section
->sh_size
, _("symbols"));
5763 for (entry
= symtab_shndx_list
; entry
!= NULL
; entry
= entry
->next
)
5765 if (entry
->hdr
->sh_link
!= (unsigned long) (section
- filedata
->section_headers
))
5770 error (_("Multiple symbol table index sections associated with the same symbol section\n"));
5774 shndx
= (Elf_External_Sym_Shndx
*) get_data (NULL
, filedata
,
5775 entry
->hdr
->sh_offset
,
5776 1, entry
->hdr
->sh_size
,
5777 _("symbol table section indices"));
5781 /* PR17531: file: heap-buffer-overflow */
5782 if (entry
->hdr
->sh_size
/ sizeof (Elf_External_Sym_Shndx
) < number
)
5784 error (_("Index section %s has an sh_size of 0x%lx - expected 0x%lx\n"),
5785 printable_section_name (filedata
, entry
->hdr
),
5786 (unsigned long) entry
->hdr
->sh_size
,
5787 (unsigned long) section
->sh_size
);
5792 isyms
= (Elf_Internal_Sym
*) cmalloc (number
, sizeof (Elf_Internal_Sym
));
5796 error (_("Out of memory reading %lu symbols\n"),
5797 (unsigned long) number
);
5801 for (j
= 0, psym
= isyms
; j
< number
; j
++, psym
++)
5803 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
5804 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
5805 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
5806 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
5808 if (psym
->st_shndx
== (SHN_XINDEX
& 0xffff) && shndx
!= NULL
)
5810 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
5811 else if (psym
->st_shndx
>= (SHN_LORESERVE
& 0xffff))
5812 psym
->st_shndx
+= SHN_LORESERVE
- (SHN_LORESERVE
& 0xffff);
5814 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
5815 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
5822 if (num_syms_return
!= NULL
)
5823 * num_syms_return
= isyms
== NULL
? 0 : number
;
5829 get_elf_section_flags (Filedata
* filedata
, bfd_vma sh_flags
)
5831 static char buff
[1024];
5833 unsigned int field_size
= is_32bit_elf
? 8 : 16;
5835 unsigned int size
= sizeof (buff
) - (field_size
+ 4 + 1);
5836 bfd_vma os_flags
= 0;
5837 bfd_vma proc_flags
= 0;
5838 bfd_vma unknown_flags
= 0;
5846 /* 0 */ { STRING_COMMA_LEN ("WRITE") },
5847 /* 1 */ { STRING_COMMA_LEN ("ALLOC") },
5848 /* 2 */ { STRING_COMMA_LEN ("EXEC") },
5849 /* 3 */ { STRING_COMMA_LEN ("MERGE") },
5850 /* 4 */ { STRING_COMMA_LEN ("STRINGS") },
5851 /* 5 */ { STRING_COMMA_LEN ("INFO LINK") },
5852 /* 6 */ { STRING_COMMA_LEN ("LINK ORDER") },
5853 /* 7 */ { STRING_COMMA_LEN ("OS NONCONF") },
5854 /* 8 */ { STRING_COMMA_LEN ("GROUP") },
5855 /* 9 */ { STRING_COMMA_LEN ("TLS") },
5856 /* IA-64 specific. */
5857 /* 10 */ { STRING_COMMA_LEN ("SHORT") },
5858 /* 11 */ { STRING_COMMA_LEN ("NORECOV") },
5859 /* IA-64 OpenVMS specific. */
5860 /* 12 */ { STRING_COMMA_LEN ("VMS_GLOBAL") },
5861 /* 13 */ { STRING_COMMA_LEN ("VMS_OVERLAID") },
5862 /* 14 */ { STRING_COMMA_LEN ("VMS_SHARED") },
5863 /* 15 */ { STRING_COMMA_LEN ("VMS_VECTOR") },
5864 /* 16 */ { STRING_COMMA_LEN ("VMS_ALLOC_64BIT") },
5865 /* 17 */ { STRING_COMMA_LEN ("VMS_PROTECTED") },
5867 /* 18 */ { STRING_COMMA_LEN ("EXCLUDE") },
5868 /* SPARC specific. */
5869 /* 19 */ { STRING_COMMA_LEN ("ORDERED") },
5870 /* 20 */ { STRING_COMMA_LEN ("COMPRESSED") },
5872 /* 21 */ { STRING_COMMA_LEN ("ENTRYSECT") },
5873 /* 22 */ { STRING_COMMA_LEN ("ARM_PURECODE") },
5874 /* 23 */ { STRING_COMMA_LEN ("COMDEF") },
5876 /* 24 */ { STRING_COMMA_LEN ("GNU_MBIND") },
5878 /* 25 */ { STRING_COMMA_LEN ("VLE") },
5881 if (do_section_details
)
5883 sprintf (buff
, "[%*.*lx]: ",
5884 field_size
, field_size
, (unsigned long) sh_flags
);
5885 p
+= field_size
+ 4;
5892 flag
= sh_flags
& - sh_flags
;
5895 if (do_section_details
)
5899 case SHF_WRITE
: sindex
= 0; break;
5900 case SHF_ALLOC
: sindex
= 1; break;
5901 case SHF_EXECINSTR
: sindex
= 2; break;
5902 case SHF_MERGE
: sindex
= 3; break;
5903 case SHF_STRINGS
: sindex
= 4; break;
5904 case SHF_INFO_LINK
: sindex
= 5; break;
5905 case SHF_LINK_ORDER
: sindex
= 6; break;
5906 case SHF_OS_NONCONFORMING
: sindex
= 7; break;
5907 case SHF_GROUP
: sindex
= 8; break;
5908 case SHF_TLS
: sindex
= 9; break;
5909 case SHF_EXCLUDE
: sindex
= 18; break;
5910 case SHF_COMPRESSED
: sindex
= 20; break;
5911 case SHF_GNU_MBIND
: sindex
= 24; break;
5915 switch (filedata
->file_header
.e_machine
)
5918 if (flag
== SHF_IA_64_SHORT
)
5920 else if (flag
== SHF_IA_64_NORECOV
)
5923 else if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_OPENVMS
)
5926 case SHF_IA_64_VMS_GLOBAL
: sindex
= 12; break;
5927 case SHF_IA_64_VMS_OVERLAID
: sindex
= 13; break;
5928 case SHF_IA_64_VMS_SHARED
: sindex
= 14; break;
5929 case SHF_IA_64_VMS_VECTOR
: sindex
= 15; break;
5930 case SHF_IA_64_VMS_ALLOC_64BIT
: sindex
= 16; break;
5931 case SHF_IA_64_VMS_PROTECTED
: sindex
= 17; break;
5942 case EM_OLD_SPARCV9
:
5943 case EM_SPARC32PLUS
:
5946 if (flag
== SHF_ORDERED
)
5953 case SHF_ENTRYSECT
: sindex
= 21; break;
5954 case SHF_ARM_PURECODE
: sindex
= 22; break;
5955 case SHF_COMDEF
: sindex
= 23; break;
5960 if (flag
== SHF_PPC_VLE
)
5971 if (p
!= buff
+ field_size
+ 4)
5973 if (size
< (10 + 2))
5975 warn (_("Internal error: not enough buffer room for section flag info"));
5976 return _("<unknown>");
5983 size
-= flags
[sindex
].len
;
5984 p
= stpcpy (p
, flags
[sindex
].str
);
5986 else if (flag
& SHF_MASKOS
)
5988 else if (flag
& SHF_MASKPROC
)
5991 unknown_flags
|= flag
;
5997 case SHF_WRITE
: *p
= 'W'; break;
5998 case SHF_ALLOC
: *p
= 'A'; break;
5999 case SHF_EXECINSTR
: *p
= 'X'; break;
6000 case SHF_MERGE
: *p
= 'M'; break;
6001 case SHF_STRINGS
: *p
= 'S'; break;
6002 case SHF_INFO_LINK
: *p
= 'I'; break;
6003 case SHF_LINK_ORDER
: *p
= 'L'; break;
6004 case SHF_OS_NONCONFORMING
: *p
= 'O'; break;
6005 case SHF_GROUP
: *p
= 'G'; break;
6006 case SHF_TLS
: *p
= 'T'; break;
6007 case SHF_EXCLUDE
: *p
= 'E'; break;
6008 case SHF_COMPRESSED
: *p
= 'C'; break;
6009 case SHF_GNU_MBIND
: *p
= 'D'; break;
6012 if ((filedata
->file_header
.e_machine
== EM_X86_64
6013 || filedata
->file_header
.e_machine
== EM_L1OM
6014 || filedata
->file_header
.e_machine
== EM_K1OM
)
6015 && flag
== SHF_X86_64_LARGE
)
6017 else if (filedata
->file_header
.e_machine
== EM_ARM
6018 && flag
== SHF_ARM_PURECODE
)
6020 else if (filedata
->file_header
.e_machine
== EM_PPC
6021 && flag
== SHF_PPC_VLE
)
6023 else if (flag
& SHF_MASKOS
)
6026 sh_flags
&= ~ SHF_MASKOS
;
6028 else if (flag
& SHF_MASKPROC
)
6031 sh_flags
&= ~ SHF_MASKPROC
;
6041 if (do_section_details
)
6045 size
-= 5 + field_size
;
6046 if (p
!= buff
+ field_size
+ 4)
6050 warn (_("Internal error: not enough buffer room for section flag info"));
6051 return _("<unknown>");
6057 sprintf (p
, "OS (%*.*lx)", field_size
, field_size
,
6058 (unsigned long) os_flags
);
6059 p
+= 5 + field_size
;
6063 size
-= 7 + field_size
;
6064 if (p
!= buff
+ field_size
+ 4)
6068 warn (_("Internal error: not enough buffer room for section flag info"));
6069 return _("<unknown>");
6075 sprintf (p
, "PROC (%*.*lx)", field_size
, field_size
,
6076 (unsigned long) proc_flags
);
6077 p
+= 7 + field_size
;
6081 size
-= 10 + field_size
;
6082 if (p
!= buff
+ field_size
+ 4)
6086 warn (_("Internal error: not enough buffer room for section flag info"));
6087 return _("<unknown>");
6093 sprintf (p
, _("UNKNOWN (%*.*lx)"), field_size
, field_size
,
6094 (unsigned long) unknown_flags
);
6095 p
+= 10 + field_size
;
6104 get_compression_header (Elf_Internal_Chdr
*chdr
, unsigned char *buf
, bfd_size_type size
)
6108 Elf32_External_Chdr
*echdr
= (Elf32_External_Chdr
*) buf
;
6110 if (size
< sizeof (* echdr
))
6112 error (_("Compressed section is too small even for a compression header\n"));
6116 chdr
->ch_type
= BYTE_GET (echdr
->ch_type
);
6117 chdr
->ch_size
= BYTE_GET (echdr
->ch_size
);
6118 chdr
->ch_addralign
= BYTE_GET (echdr
->ch_addralign
);
6119 return sizeof (*echdr
);
6123 Elf64_External_Chdr
*echdr
= (Elf64_External_Chdr
*) buf
;
6125 if (size
< sizeof (* echdr
))
6127 error (_("Compressed section is too small even for a compression header\n"));
6131 chdr
->ch_type
= BYTE_GET (echdr
->ch_type
);
6132 chdr
->ch_size
= BYTE_GET (echdr
->ch_size
);
6133 chdr
->ch_addralign
= BYTE_GET (echdr
->ch_addralign
);
6134 return sizeof (*echdr
);
6139 process_section_headers (Filedata
* filedata
)
6141 Elf_Internal_Shdr
* section
;
6144 filedata
->section_headers
= NULL
;
6146 if (filedata
->file_header
.e_shnum
== 0)
6148 /* PR binutils/12467. */
6149 if (filedata
->file_header
.e_shoff
!= 0)
6151 warn (_("possibly corrupt ELF file header - it has a non-zero"
6152 " section header offset, but no section headers\n"));
6155 else if (do_sections
)
6156 printf (_("\nThere are no sections in this file.\n"));
6161 if (do_sections
&& !do_header
)
6162 printf (ngettext ("There is %d section header, "
6163 "starting at offset 0x%lx:\n",
6164 "There are %d section headers, "
6165 "starting at offset 0x%lx:\n",
6166 filedata
->file_header
.e_shnum
),
6167 filedata
->file_header
.e_shnum
,
6168 (unsigned long) filedata
->file_header
.e_shoff
);
6172 if (! get_32bit_section_headers (filedata
, FALSE
))
6177 if (! get_64bit_section_headers (filedata
, FALSE
))
6181 /* Read in the string table, so that we have names to display. */
6182 if (filedata
->file_header
.e_shstrndx
!= SHN_UNDEF
6183 && filedata
->file_header
.e_shstrndx
< filedata
->file_header
.e_shnum
)
6185 section
= filedata
->section_headers
+ filedata
->file_header
.e_shstrndx
;
6187 if (section
->sh_size
!= 0)
6189 filedata
->string_table
= (char *) get_data (NULL
, filedata
, section
->sh_offset
,
6190 1, section
->sh_size
,
6193 filedata
->string_table_length
= filedata
->string_table
!= NULL
? section
->sh_size
: 0;
6197 /* Scan the sections for the dynamic symbol table
6198 and dynamic string table and debug sections. */
6199 dynamic_symbols
= NULL
;
6200 dynamic_strings
= NULL
;
6201 dynamic_syminfo
= NULL
;
6202 symtab_shndx_list
= NULL
;
6204 eh_addr_size
= is_32bit_elf
? 4 : 8;
6205 switch (filedata
->file_header
.e_machine
)
6208 case EM_MIPS_RS3_LE
:
6209 /* The 64-bit MIPS EABI uses a combination of 32-bit ELF and 64-bit
6210 FDE addresses. However, the ABI also has a semi-official ILP32
6211 variant for which the normal FDE address size rules apply.
6213 GCC 4.0 marks EABI64 objects with a dummy .gcc_compiled_longXX
6214 section, where XX is the size of longs in bits. Unfortunately,
6215 earlier compilers provided no way of distinguishing ILP32 objects
6216 from LP64 objects, so if there's any doubt, we should assume that
6217 the official LP64 form is being used. */
6218 if ((filedata
->file_header
.e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
6219 && find_section (filedata
, ".gcc_compiled_long32") == NULL
)
6225 switch (filedata
->file_header
.e_flags
& EF_H8_MACH
)
6227 case E_H8_MACH_H8300
:
6228 case E_H8_MACH_H8300HN
:
6229 case E_H8_MACH_H8300SN
:
6230 case E_H8_MACH_H8300SXN
:
6233 case E_H8_MACH_H8300H
:
6234 case E_H8_MACH_H8300S
:
6235 case E_H8_MACH_H8300SX
:
6243 switch (filedata
->file_header
.e_flags
& EF_M32C_CPU_MASK
)
6245 case EF_M32C_CPU_M16C
:
6252 #define CHECK_ENTSIZE_VALUES(section, i, size32, size64) \
6255 bfd_size_type expected_entsize = is_32bit_elf ? size32 : size64; \
6256 if (section->sh_entsize != expected_entsize) \
6259 sprintf_vma (buf, section->sh_entsize); \
6260 /* Note: coded this way so that there is a single string for \
6262 error (_("Section %d has invalid sh_entsize of %s\n"), i, buf); \
6263 error (_("(Using the expected size of %u for the rest of this dump)\n"), \
6264 (unsigned) expected_entsize); \
6265 section->sh_entsize = expected_entsize; \
6270 #define CHECK_ENTSIZE(section, i, type) \
6271 CHECK_ENTSIZE_VALUES (section, i, sizeof (Elf32_External_##type), \
6272 sizeof (Elf64_External_##type))
6274 for (i
= 0, section
= filedata
->section_headers
;
6275 i
< filedata
->file_header
.e_shnum
;
6278 char * name
= SECTION_NAME (section
);
6280 if (section
->sh_type
== SHT_DYNSYM
)
6282 if (dynamic_symbols
!= NULL
)
6284 error (_("File contains multiple dynamic symbol tables\n"));
6288 CHECK_ENTSIZE (section
, i
, Sym
);
6289 dynamic_symbols
= GET_ELF_SYMBOLS (filedata
, section
, & num_dynamic_syms
);
6291 else if (section
->sh_type
== SHT_STRTAB
6292 && streq (name
, ".dynstr"))
6294 if (dynamic_strings
!= NULL
)
6296 error (_("File contains multiple dynamic string tables\n"));
6300 dynamic_strings
= (char *) get_data (NULL
, filedata
, section
->sh_offset
,
6301 1, section
->sh_size
,
6302 _("dynamic strings"));
6303 dynamic_strings_length
= dynamic_strings
== NULL
? 0 : section
->sh_size
;
6305 else if (section
->sh_type
== SHT_SYMTAB_SHNDX
)
6307 elf_section_list
* entry
= xmalloc (sizeof * entry
);
6309 entry
->hdr
= section
;
6310 entry
->next
= symtab_shndx_list
;
6311 symtab_shndx_list
= entry
;
6313 else if (section
->sh_type
== SHT_SYMTAB
)
6314 CHECK_ENTSIZE (section
, i
, Sym
);
6315 else if (section
->sh_type
== SHT_GROUP
)
6316 CHECK_ENTSIZE_VALUES (section
, i
, GRP_ENTRY_SIZE
, GRP_ENTRY_SIZE
);
6317 else if (section
->sh_type
== SHT_REL
)
6318 CHECK_ENTSIZE (section
, i
, Rel
);
6319 else if (section
->sh_type
== SHT_RELA
)
6320 CHECK_ENTSIZE (section
, i
, Rela
);
6321 else if ((do_debugging
|| do_debug_info
|| do_debug_abbrevs
6322 || do_debug_lines
|| do_debug_pubnames
|| do_debug_pubtypes
6323 || do_debug_aranges
|| do_debug_frames
|| do_debug_macinfo
6324 || do_debug_str
|| do_debug_loc
|| do_debug_ranges
6325 || do_debug_addr
|| do_debug_cu_index
|| do_debug_links
)
6326 && (const_strneq (name
, ".debug_")
6327 || const_strneq (name
, ".zdebug_")))
6330 name
+= sizeof (".zdebug_") - 1;
6332 name
+= sizeof (".debug_") - 1;
6335 || (do_debug_info
&& const_strneq (name
, "info"))
6336 || (do_debug_info
&& const_strneq (name
, "types"))
6337 || (do_debug_abbrevs
&& const_strneq (name
, "abbrev"))
6338 || (do_debug_lines
&& strcmp (name
, "line") == 0)
6339 || (do_debug_lines
&& const_strneq (name
, "line."))
6340 || (do_debug_pubnames
&& const_strneq (name
, "pubnames"))
6341 || (do_debug_pubtypes
&& const_strneq (name
, "pubtypes"))
6342 || (do_debug_pubnames
&& const_strneq (name
, "gnu_pubnames"))
6343 || (do_debug_pubtypes
&& const_strneq (name
, "gnu_pubtypes"))
6344 || (do_debug_aranges
&& const_strneq (name
, "aranges"))
6345 || (do_debug_ranges
&& const_strneq (name
, "ranges"))
6346 || (do_debug_ranges
&& const_strneq (name
, "rnglists"))
6347 || (do_debug_frames
&& const_strneq (name
, "frame"))
6348 || (do_debug_macinfo
&& const_strneq (name
, "macinfo"))
6349 || (do_debug_macinfo
&& const_strneq (name
, "macro"))
6350 || (do_debug_str
&& const_strneq (name
, "str"))
6351 || (do_debug_loc
&& const_strneq (name
, "loc"))
6352 || (do_debug_loc
&& const_strneq (name
, "loclists"))
6353 || (do_debug_addr
&& const_strneq (name
, "addr"))
6354 || (do_debug_cu_index
&& const_strneq (name
, "cu_index"))
6355 || (do_debug_cu_index
&& const_strneq (name
, "tu_index"))
6357 request_dump_bynumber (filedata
, i
, DEBUG_DUMP
);
6359 /* Linkonce section to be combined with .debug_info at link time. */
6360 else if ((do_debugging
|| do_debug_info
)
6361 && const_strneq (name
, ".gnu.linkonce.wi."))
6362 request_dump_bynumber (filedata
, i
, DEBUG_DUMP
);
6363 else if (do_debug_frames
&& streq (name
, ".eh_frame"))
6364 request_dump_bynumber (filedata
, i
, DEBUG_DUMP
);
6365 else if (do_gdb_index
&& (streq (name
, ".gdb_index")
6366 || streq (name
, ".debug_names")))
6367 request_dump_bynumber (filedata
, i
, DEBUG_DUMP
);
6368 /* Trace sections for Itanium VMS. */
6369 else if ((do_debugging
|| do_trace_info
|| do_trace_abbrevs
6370 || do_trace_aranges
)
6371 && const_strneq (name
, ".trace_"))
6373 name
+= sizeof (".trace_") - 1;
6376 || (do_trace_info
&& streq (name
, "info"))
6377 || (do_trace_abbrevs
&& streq (name
, "abbrev"))
6378 || (do_trace_aranges
&& streq (name
, "aranges"))
6380 request_dump_bynumber (filedata
, i
, DEBUG_DUMP
);
6382 else if ((do_debugging
|| do_debug_links
)
6383 && (const_strneq (name
, ".gnu_debuglink")
6384 || const_strneq (name
, ".gnu_debugaltlink")))
6385 request_dump_bynumber (filedata
, i
, DEBUG_DUMP
);
6391 if (filedata
->file_header
.e_shnum
> 1)
6392 printf (_("\nSection Headers:\n"));
6394 printf (_("\nSection Header:\n"));
6398 if (do_section_details
)
6400 printf (_(" [Nr] Name\n"));
6401 printf (_(" Type Addr Off Size ES Lk Inf Al\n"));
6405 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
6409 if (do_section_details
)
6411 printf (_(" [Nr] Name\n"));
6412 printf (_(" Type Address Off Size ES Lk Inf Al\n"));
6416 (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n"));
6420 if (do_section_details
)
6422 printf (_(" [Nr] Name\n"));
6423 printf (_(" Type Address Offset Link\n"));
6424 printf (_(" Size EntSize Info Align\n"));
6428 printf (_(" [Nr] Name Type Address Offset\n"));
6429 printf (_(" Size EntSize Flags Link Info Align\n"));
6433 if (do_section_details
)
6434 printf (_(" Flags\n"));
6436 for (i
= 0, section
= filedata
->section_headers
;
6437 i
< filedata
->file_header
.e_shnum
;
6440 /* Run some sanity checks on the section header. */
6442 /* Check the sh_link field. */
6443 switch (section
->sh_type
)
6447 if (section
->sh_link
== 0
6448 && (filedata
->file_header
.e_type
== ET_EXEC
6449 || filedata
->file_header
.e_type
== ET_DYN
))
6450 /* A dynamic relocation section where all entries use a
6451 zero symbol index need not specify a symtab section. */
6454 case SHT_SYMTAB_SHNDX
:
6458 case SHT_GNU_versym
:
6459 if (section
->sh_link
== 0
6460 || section
->sh_link
>= filedata
->file_header
.e_shnum
6461 || (filedata
->section_headers
[section
->sh_link
].sh_type
!= SHT_SYMTAB
6462 && filedata
->section_headers
[section
->sh_link
].sh_type
!= SHT_DYNSYM
))
6463 warn (_("[%2u]: Link field (%u) should index a symtab section.\n"),
6464 i
, section
->sh_link
);
6470 case SHT_GNU_verneed
:
6471 case SHT_GNU_verdef
:
6472 case SHT_GNU_LIBLIST
:
6473 if (section
->sh_link
== 0
6474 || section
->sh_link
>= filedata
->file_header
.e_shnum
6475 || filedata
->section_headers
[section
->sh_link
].sh_type
!= SHT_STRTAB
)
6476 warn (_("[%2u]: Link field (%u) should index a string section.\n"),
6477 i
, section
->sh_link
);
6480 case SHT_INIT_ARRAY
:
6481 case SHT_FINI_ARRAY
:
6482 case SHT_PREINIT_ARRAY
:
6483 if (section
->sh_type
< SHT_LOOS
&& section
->sh_link
!= 0)
6484 warn (_("[%2u]: Unexpected value (%u) in link field.\n"),
6485 i
, section
->sh_link
);
6489 /* FIXME: Add support for target specific section types. */
6490 #if 0 /* Currently we do not check other section types as there are too
6491 many special cases. Stab sections for example have a type
6492 of SHT_PROGBITS but an sh_link field that links to the .stabstr
6494 if (section
->sh_type
< SHT_LOOS
&& section
->sh_link
!= 0)
6495 warn (_("[%2u]: Unexpected value (%u) in link field.\n"),
6496 i
, section
->sh_link
);
6501 /* Check the sh_info field. */
6502 switch (section
->sh_type
)
6506 if (section
->sh_info
== 0
6507 && (filedata
->file_header
.e_type
== ET_EXEC
6508 || filedata
->file_header
.e_type
== ET_DYN
))
6509 /* Dynamic relocations apply to segments, so they do not
6510 need to specify the section they relocate. */
6512 if (section
->sh_info
== 0
6513 || section
->sh_info
>= filedata
->file_header
.e_shnum
6514 || (filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_PROGBITS
6515 && filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_NOBITS
6516 && filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_NOTE
6517 && filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_INIT_ARRAY
6518 && filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_FINI_ARRAY
6519 && filedata
->section_headers
[section
->sh_info
].sh_type
!= SHT_PREINIT_ARRAY
6520 /* FIXME: Are other section types valid ? */
6521 && filedata
->section_headers
[section
->sh_info
].sh_type
< SHT_LOOS
))
6522 warn (_("[%2u]: Info field (%u) should index a relocatable section.\n"),
6523 i
, section
->sh_info
);
6528 case SHT_SYMTAB_SHNDX
:
6529 case SHT_INIT_ARRAY
:
6530 case SHT_FINI_ARRAY
:
6531 case SHT_PREINIT_ARRAY
:
6532 if (section
->sh_info
!= 0)
6533 warn (_("[%2u]: Unexpected value (%u) in info field.\n"),
6534 i
, section
->sh_info
);
6540 /* A symbol index - we assume that it is valid. */
6544 /* FIXME: Add support for target specific section types. */
6545 if (section
->sh_type
== SHT_NOBITS
)
6546 /* NOBITS section headers with non-zero sh_info fields can be
6547 created when a binary is stripped of everything but its debug
6548 information. The stripped sections have their headers
6549 preserved but their types set to SHT_NOBITS. So do not check
6550 this type of section. */
6552 else if (section
->sh_flags
& SHF_INFO_LINK
)
6554 if (section
->sh_info
< 1 || section
->sh_info
>= filedata
->file_header
.e_shnum
)
6555 warn (_("[%2u]: Expected link to another section in info field"), i
);
6557 else if (section
->sh_type
< SHT_LOOS
6558 && (section
->sh_flags
& SHF_GNU_MBIND
) == 0
6559 && section
->sh_info
!= 0)
6560 warn (_("[%2u]: Unexpected value (%u) in info field.\n"),
6561 i
, section
->sh_info
);
6565 /* Check the sh_size field. */
6566 if (section
->sh_size
> filedata
->file_size
6567 && section
->sh_type
!= SHT_NOBITS
6568 && section
->sh_type
!= SHT_NULL
6569 && section
->sh_type
< SHT_LOOS
)
6570 warn (_("Size of section %u is larger than the entire file!\n"), i
);
6572 printf (" [%2u] ", i
);
6573 if (do_section_details
)
6574 printf ("%s\n ", printable_section_name (filedata
, section
));
6576 print_symbol (-17, SECTION_NAME (section
));
6578 printf (do_wide
? " %-15s " : " %-15.15s ",
6579 get_section_type_name (filedata
, section
->sh_type
));
6583 const char * link_too_big
= NULL
;
6585 print_vma (section
->sh_addr
, LONG_HEX
);
6587 printf ( " %6.6lx %6.6lx %2.2lx",
6588 (unsigned long) section
->sh_offset
,
6589 (unsigned long) section
->sh_size
,
6590 (unsigned long) section
->sh_entsize
);
6592 if (do_section_details
)
6593 fputs (" ", stdout
);
6595 printf (" %3s ", get_elf_section_flags (filedata
, section
->sh_flags
));
6597 if (section
->sh_link
>= filedata
->file_header
.e_shnum
)
6600 /* The sh_link value is out of range. Normally this indicates
6601 an error but it can have special values in Solaris binaries. */
6602 switch (filedata
->file_header
.e_machine
)
6609 case EM_OLD_SPARCV9
:
6610 case EM_SPARC32PLUS
:
6613 if (section
->sh_link
== (SHN_BEFORE
& 0xffff))
6614 link_too_big
= "BEFORE";
6615 else if (section
->sh_link
== (SHN_AFTER
& 0xffff))
6616 link_too_big
= "AFTER";
6623 if (do_section_details
)
6625 if (link_too_big
!= NULL
&& * link_too_big
)
6626 printf ("<%s> ", link_too_big
);
6628 printf ("%2u ", section
->sh_link
);
6629 printf ("%3u %2lu\n", section
->sh_info
,
6630 (unsigned long) section
->sh_addralign
);
6633 printf ("%2u %3u %2lu\n",
6636 (unsigned long) section
->sh_addralign
);
6638 if (link_too_big
&& ! * link_too_big
)
6639 warn (_("section %u: sh_link value of %u is larger than the number of sections\n"),
6640 i
, section
->sh_link
);
6644 print_vma (section
->sh_addr
, LONG_HEX
);
6646 if ((long) section
->sh_offset
== section
->sh_offset
)
6647 printf (" %6.6lx", (unsigned long) section
->sh_offset
);
6651 print_vma (section
->sh_offset
, LONG_HEX
);
6654 if ((unsigned long) section
->sh_size
== section
->sh_size
)
6655 printf (" %6.6lx", (unsigned long) section
->sh_size
);
6659 print_vma (section
->sh_size
, LONG_HEX
);
6662 if ((unsigned long) section
->sh_entsize
== section
->sh_entsize
)
6663 printf (" %2.2lx", (unsigned long) section
->sh_entsize
);
6667 print_vma (section
->sh_entsize
, LONG_HEX
);
6670 if (do_section_details
)
6671 fputs (" ", stdout
);
6673 printf (" %3s ", get_elf_section_flags (filedata
, section
->sh_flags
));
6675 printf ("%2u %3u ", section
->sh_link
, section
->sh_info
);
6677 if ((unsigned long) section
->sh_addralign
== section
->sh_addralign
)
6678 printf ("%2lu\n", (unsigned long) section
->sh_addralign
);
6681 print_vma (section
->sh_addralign
, DEC
);
6685 else if (do_section_details
)
6688 print_vma (section
->sh_addr
, LONG_HEX
);
6689 if ((long) section
->sh_offset
== section
->sh_offset
)
6690 printf (" %16.16lx", (unsigned long) section
->sh_offset
);
6694 print_vma (section
->sh_offset
, LONG_HEX
);
6696 printf (" %u\n ", section
->sh_link
);
6697 print_vma (section
->sh_size
, LONG_HEX
);
6699 print_vma (section
->sh_entsize
, LONG_HEX
);
6701 printf (" %-16u %lu\n",
6703 (unsigned long) section
->sh_addralign
);
6708 print_vma (section
->sh_addr
, LONG_HEX
);
6709 if ((long) section
->sh_offset
== section
->sh_offset
)
6710 printf (" %8.8lx", (unsigned long) section
->sh_offset
);
6714 print_vma (section
->sh_offset
, LONG_HEX
);
6717 print_vma (section
->sh_size
, LONG_HEX
);
6719 print_vma (section
->sh_entsize
, LONG_HEX
);
6721 printf (" %3s ", get_elf_section_flags (filedata
, section
->sh_flags
));
6723 printf (" %2u %3u %lu\n",
6726 (unsigned long) section
->sh_addralign
);
6729 if (do_section_details
)
6731 printf (" %s\n", get_elf_section_flags (filedata
, section
->sh_flags
));
6732 if ((section
->sh_flags
& SHF_COMPRESSED
) != 0)
6734 /* Minimum section size is 12 bytes for 32-bit compression
6735 header + 12 bytes for compressed data header. */
6736 unsigned char buf
[24];
6738 assert (sizeof (buf
) >= sizeof (Elf64_External_Chdr
));
6739 if (get_data (&buf
, filedata
, section
->sh_offset
, 1,
6740 sizeof (buf
), _("compression header")))
6742 Elf_Internal_Chdr chdr
;
6744 (void) get_compression_header (&chdr
, buf
, sizeof (buf
));
6746 if (chdr
.ch_type
== ELFCOMPRESS_ZLIB
)
6749 printf (_(" [<unknown>: 0x%x], "),
6751 print_vma (chdr
.ch_size
, LONG_HEX
);
6752 printf (", %lu\n", (unsigned long) chdr
.ch_addralign
);
6758 if (!do_section_details
)
6760 /* The ordering of the letters shown here matches the ordering of the
6761 corresponding SHF_xxx values, and hence the order in which these
6762 letters will be displayed to the user. */
6763 printf (_("Key to Flags:\n\
6764 W (write), A (alloc), X (execute), M (merge), S (strings), I (info),\n\
6765 L (link order), O (extra OS processing required), G (group), T (TLS),\n\
6766 C (compressed), x (unknown), o (OS specific), E (exclude),\n "));
6767 if (filedata
->file_header
.e_machine
== EM_X86_64
6768 || filedata
->file_header
.e_machine
== EM_L1OM
6769 || filedata
->file_header
.e_machine
== EM_K1OM
)
6770 printf (_("l (large), "));
6771 else if (filedata
->file_header
.e_machine
== EM_ARM
)
6772 printf (_("y (purecode), "));
6773 else if (filedata
->file_header
.e_machine
== EM_PPC
)
6774 printf (_("v (VLE), "));
6775 printf ("p (processor specific)\n");
6782 get_group_flags (unsigned int flags
)
6784 static char buff
[128];
6788 else if (flags
== GRP_COMDAT
)
6791 snprintf (buff
, 14, _("[0x%x: "), flags
);
6793 flags
&= ~ GRP_COMDAT
;
6794 if (flags
& GRP_MASKOS
)
6796 strcat (buff
, "<OS specific>");
6797 flags
&= ~ GRP_MASKOS
;
6800 if (flags
& GRP_MASKPROC
)
6802 strcat (buff
, "<PROC specific>");
6803 flags
&= ~ GRP_MASKPROC
;
6807 strcat (buff
, "<unknown>");
6814 process_section_groups (Filedata
* filedata
)
6816 Elf_Internal_Shdr
* section
;
6818 struct group
* group
;
6819 Elf_Internal_Shdr
* symtab_sec
;
6820 Elf_Internal_Shdr
* strtab_sec
;
6821 Elf_Internal_Sym
* symtab
;
6822 unsigned long num_syms
;
6826 /* Don't process section groups unless needed. */
6827 if (!do_unwind
&& !do_section_groups
)
6830 if (filedata
->file_header
.e_shnum
== 0)
6832 if (do_section_groups
)
6833 printf (_("\nThere are no sections to group in this file.\n"));
6838 if (filedata
->section_headers
== NULL
)
6840 error (_("Section headers are not available!\n"));
6841 /* PR 13622: This can happen with a corrupt ELF header. */
6845 section_headers_groups
= (struct group
**) calloc (filedata
->file_header
.e_shnum
,
6846 sizeof (struct group
*));
6848 if (section_headers_groups
== NULL
)
6850 error (_("Out of memory reading %u section group headers\n"),
6851 filedata
->file_header
.e_shnum
);
6855 /* Scan the sections for the group section. */
6857 for (i
= 0, section
= filedata
->section_headers
;
6858 i
< filedata
->file_header
.e_shnum
;
6860 if (section
->sh_type
== SHT_GROUP
)
6863 if (group_count
== 0)
6865 if (do_section_groups
)
6866 printf (_("\nThere are no section groups in this file.\n"));
6871 section_groups
= (struct group
*) calloc (group_count
, sizeof (struct group
));
6873 if (section_groups
== NULL
)
6875 error (_("Out of memory reading %lu groups\n"),
6876 (unsigned long) group_count
);
6886 for (i
= 0, section
= filedata
->section_headers
, group
= section_groups
;
6887 i
< filedata
->file_header
.e_shnum
;
6890 if (section
->sh_type
== SHT_GROUP
)
6892 const char * name
= printable_section_name (filedata
, section
);
6893 const char * group_name
;
6894 unsigned char * start
;
6895 unsigned char * indices
;
6896 unsigned int entry
, j
, size
;
6897 Elf_Internal_Shdr
* sec
;
6898 Elf_Internal_Sym
* sym
;
6900 /* Get the symbol table. */
6901 if (section
->sh_link
>= filedata
->file_header
.e_shnum
6902 || ((sec
= filedata
->section_headers
+ section
->sh_link
)->sh_type
6905 error (_("Bad sh_link in group section `%s'\n"), name
);
6909 if (symtab_sec
!= sec
)
6914 symtab
= GET_ELF_SYMBOLS (filedata
, symtab_sec
, & num_syms
);
6919 error (_("Corrupt header in group section `%s'\n"), name
);
6923 if (section
->sh_info
>= num_syms
)
6925 error (_("Bad sh_info in group section `%s'\n"), name
);
6929 sym
= symtab
+ section
->sh_info
;
6931 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
6933 if (sym
->st_shndx
== 0
6934 || sym
->st_shndx
>= filedata
->file_header
.e_shnum
)
6936 error (_("Bad sh_info in group section `%s'\n"), name
);
6940 group_name
= SECTION_NAME (filedata
->section_headers
+ sym
->st_shndx
);
6949 /* Get the string table. */
6950 if (symtab_sec
->sh_link
>= filedata
->file_header
.e_shnum
)
6959 != (sec
= filedata
->section_headers
+ symtab_sec
->sh_link
))
6965 strtab
= (char *) get_data (NULL
, filedata
, strtab_sec
->sh_offset
,
6966 1, strtab_sec
->sh_size
,
6968 strtab_size
= strtab
!= NULL
? strtab_sec
->sh_size
: 0;
6970 group_name
= sym
->st_name
< strtab_size
6971 ? strtab
+ sym
->st_name
: _("<corrupt>");
6974 /* PR 17531: file: loop. */
6975 if (section
->sh_entsize
> section
->sh_size
)
6977 error (_("Section %s has sh_entsize (0x%lx) which is larger than its size (0x%lx)\n"),
6978 printable_section_name (filedata
, section
),
6979 (unsigned long) section
->sh_entsize
,
6980 (unsigned long) section
->sh_size
);
6984 start
= (unsigned char *) get_data (NULL
, filedata
, section
->sh_offset
,
6985 1, section
->sh_size
,
6991 size
= (section
->sh_size
/ section
->sh_entsize
) - 1;
6992 entry
= byte_get (indices
, 4);
6995 if (do_section_groups
)
6997 printf (_("\n%sgroup section [%5u] `%s' [%s] contains %u sections:\n"),
6998 get_group_flags (entry
), i
, name
, group_name
, size
);
7000 printf (_(" [Index] Name\n"));
7003 group
->group_index
= i
;
7005 for (j
= 0; j
< size
; j
++)
7007 struct group_list
* g
;
7009 entry
= byte_get (indices
, 4);
7012 if (entry
>= filedata
->file_header
.e_shnum
)
7014 static unsigned num_group_errors
= 0;
7016 if (num_group_errors
++ < 10)
7018 error (_("section [%5u] in group section [%5u] > maximum section [%5u]\n"),
7019 entry
, i
, filedata
->file_header
.e_shnum
- 1);
7020 if (num_group_errors
== 10)
7021 warn (_("Further error messages about overlarge group section indices suppressed\n"));
7026 if (section_headers_groups
[entry
] != NULL
)
7030 static unsigned num_errs
= 0;
7032 if (num_errs
++ < 10)
7034 error (_("section [%5u] in group section [%5u] already in group section [%5u]\n"),
7036 section_headers_groups
[entry
]->group_index
);
7038 warn (_("Further error messages about already contained group sections suppressed\n"));
7044 /* Intel C/C++ compiler may put section 0 in a
7045 section group. We just warn it the first time
7046 and ignore it afterwards. */
7047 static bfd_boolean warned
= FALSE
;
7050 error (_("section 0 in group section [%5u]\n"),
7051 section_headers_groups
[entry
]->group_index
);
7057 section_headers_groups
[entry
] = group
;
7059 if (do_section_groups
)
7061 sec
= filedata
->section_headers
+ entry
;
7062 printf (" [%5u] %s\n", entry
, printable_section_name (filedata
, sec
));
7065 g
= (struct group_list
*) xmalloc (sizeof (struct group_list
));
7066 g
->section_index
= entry
;
7067 g
->next
= group
->root
;
7085 /* Data used to display dynamic fixups. */
7087 struct ia64_vms_dynfixup
7089 bfd_vma needed_ident
; /* Library ident number. */
7090 bfd_vma needed
; /* Index in the dstrtab of the library name. */
7091 bfd_vma fixup_needed
; /* Index of the library. */
7092 bfd_vma fixup_rela_cnt
; /* Number of fixups. */
7093 bfd_vma fixup_rela_off
; /* Fixups offset in the dynamic segment. */
7096 /* Data used to display dynamic relocations. */
7098 struct ia64_vms_dynimgrela
7100 bfd_vma img_rela_cnt
; /* Number of relocations. */
7101 bfd_vma img_rela_off
; /* Reloc offset in the dynamic segment. */
7104 /* Display IA-64 OpenVMS dynamic fixups (used to dynamically link a shared
7108 dump_ia64_vms_dynamic_fixups (Filedata
* filedata
,
7109 struct ia64_vms_dynfixup
* fixup
,
7110 const char * strtab
,
7111 unsigned int strtab_sz
)
7113 Elf64_External_VMS_IMAGE_FIXUP
* imfs
;
7115 const char * lib_name
;
7117 imfs
= get_data (NULL
, filedata
, dynamic_addr
+ fixup
->fixup_rela_off
,
7118 1, fixup
->fixup_rela_cnt
* sizeof (*imfs
),
7119 _("dynamic section image fixups"));
7123 if (fixup
->needed
< strtab_sz
)
7124 lib_name
= strtab
+ fixup
->needed
;
7127 warn (_("corrupt library name index of 0x%lx found in dynamic entry"),
7128 (unsigned long) fixup
->needed
);
7131 printf (_("\nImage fixups for needed library #%d: %s - ident: %lx\n"),
7132 (int) fixup
->fixup_needed
, lib_name
, (long) fixup
->needed_ident
);
7134 (_("Seg Offset Type SymVec DataType\n"));
7136 for (i
= 0; i
< (long) fixup
->fixup_rela_cnt
; i
++)
7141 printf ("%3u ", (unsigned) BYTE_GET (imfs
[i
].fixup_seg
));
7142 printf_vma ((bfd_vma
) BYTE_GET (imfs
[i
].fixup_offset
));
7143 type
= BYTE_GET (imfs
[i
].type
);
7144 rtype
= elf_ia64_reloc_type (type
);
7146 printf (" 0x%08x ", type
);
7148 printf (" %-32s ", rtype
);
7149 printf ("%6u ", (unsigned) BYTE_GET (imfs
[i
].symvec_index
));
7150 printf ("0x%08x\n", (unsigned) BYTE_GET (imfs
[i
].data_type
));
7157 /* Display IA-64 OpenVMS dynamic relocations (used to relocate an image). */
7160 dump_ia64_vms_dynamic_relocs (Filedata
* filedata
, struct ia64_vms_dynimgrela
*imgrela
)
7162 Elf64_External_VMS_IMAGE_RELA
*imrs
;
7165 imrs
= get_data (NULL
, filedata
, dynamic_addr
+ imgrela
->img_rela_off
,
7166 1, imgrela
->img_rela_cnt
* sizeof (*imrs
),
7167 _("dynamic section image relocations"));
7171 printf (_("\nImage relocs\n"));
7173 (_("Seg Offset Type Addend Seg Sym Off\n"));
7175 for (i
= 0; i
< (long) imgrela
->img_rela_cnt
; i
++)
7180 printf ("%3u ", (unsigned) BYTE_GET (imrs
[i
].rela_seg
));
7181 printf ("%08" BFD_VMA_FMT
"x ",
7182 (bfd_vma
) BYTE_GET (imrs
[i
].rela_offset
));
7183 type
= BYTE_GET (imrs
[i
].type
);
7184 rtype
= elf_ia64_reloc_type (type
);
7186 printf ("0x%08x ", type
);
7188 printf ("%-31s ", rtype
);
7189 print_vma (BYTE_GET (imrs
[i
].addend
), FULL_HEX
);
7190 printf ("%3u ", (unsigned) BYTE_GET (imrs
[i
].sym_seg
));
7191 printf ("%08" BFD_VMA_FMT
"x\n",
7192 (bfd_vma
) BYTE_GET (imrs
[i
].sym_offset
));
7199 /* Display IA-64 OpenVMS dynamic relocations and fixups. */
7202 process_ia64_vms_dynamic_relocs (Filedata
* filedata
)
7204 struct ia64_vms_dynfixup fixup
;
7205 struct ia64_vms_dynimgrela imgrela
;
7206 Elf_Internal_Dyn
*entry
;
7207 bfd_vma strtab_off
= 0;
7208 bfd_vma strtab_sz
= 0;
7209 char *strtab
= NULL
;
7210 bfd_boolean res
= TRUE
;
7212 memset (&fixup
, 0, sizeof (fixup
));
7213 memset (&imgrela
, 0, sizeof (imgrela
));
7215 /* Note: the order of the entries is specified by the OpenVMS specs. */
7216 for (entry
= dynamic_section
;
7217 entry
< dynamic_section
+ dynamic_nent
;
7220 switch (entry
->d_tag
)
7222 case DT_IA_64_VMS_STRTAB_OFFSET
:
7223 strtab_off
= entry
->d_un
.d_val
;
7226 strtab_sz
= entry
->d_un
.d_val
;
7228 strtab
= get_data (NULL
, filedata
, dynamic_addr
+ strtab_off
,
7229 1, strtab_sz
, _("dynamic string section"));
7232 case DT_IA_64_VMS_NEEDED_IDENT
:
7233 fixup
.needed_ident
= entry
->d_un
.d_val
;
7236 fixup
.needed
= entry
->d_un
.d_val
;
7238 case DT_IA_64_VMS_FIXUP_NEEDED
:
7239 fixup
.fixup_needed
= entry
->d_un
.d_val
;
7241 case DT_IA_64_VMS_FIXUP_RELA_CNT
:
7242 fixup
.fixup_rela_cnt
= entry
->d_un
.d_val
;
7244 case DT_IA_64_VMS_FIXUP_RELA_OFF
:
7245 fixup
.fixup_rela_off
= entry
->d_un
.d_val
;
7246 if (! dump_ia64_vms_dynamic_fixups (filedata
, &fixup
, strtab
, strtab_sz
))
7249 case DT_IA_64_VMS_IMG_RELA_CNT
:
7250 imgrela
.img_rela_cnt
= entry
->d_un
.d_val
;
7252 case DT_IA_64_VMS_IMG_RELA_OFF
:
7253 imgrela
.img_rela_off
= entry
->d_un
.d_val
;
7254 if (! dump_ia64_vms_dynamic_relocs (filedata
, &imgrela
))
7276 dynamic_relocations
[] =
7278 { "REL", DT_REL
, DT_RELSZ
, FALSE
},
7279 { "RELA", DT_RELA
, DT_RELASZ
, TRUE
},
7280 { "PLT", DT_JMPREL
, DT_PLTRELSZ
, UNKNOWN
}
7283 /* Process the reloc section. */
7286 process_relocs (Filedata
* filedata
)
7288 unsigned long rel_size
;
7289 unsigned long rel_offset
;
7294 if (do_using_dynamic
)
7298 bfd_boolean has_dynamic_reloc
;
7301 has_dynamic_reloc
= FALSE
;
7303 for (i
= 0; i
< ARRAY_SIZE (dynamic_relocations
); i
++)
7305 is_rela
= dynamic_relocations
[i
].rela
;
7306 name
= dynamic_relocations
[i
].name
;
7307 rel_size
= dynamic_info
[dynamic_relocations
[i
].size
];
7308 rel_offset
= dynamic_info
[dynamic_relocations
[i
].reloc
];
7311 has_dynamic_reloc
= TRUE
;
7313 if (is_rela
== UNKNOWN
)
7315 if (dynamic_relocations
[i
].reloc
== DT_JMPREL
)
7316 switch (dynamic_info
[DT_PLTREL
])
7330 (_("\n'%s' relocation section at offset 0x%lx contains %ld bytes:\n"),
7331 name
, rel_offset
, rel_size
);
7333 dump_relocations (filedata
,
7334 offset_from_vma (filedata
, rel_offset
, rel_size
),
7336 dynamic_symbols
, num_dynamic_syms
,
7337 dynamic_strings
, dynamic_strings_length
,
7338 is_rela
, TRUE
/* is_dynamic */);
7342 if (is_ia64_vms (filedata
))
7343 if (process_ia64_vms_dynamic_relocs (filedata
))
7344 has_dynamic_reloc
= TRUE
;
7346 if (! has_dynamic_reloc
)
7347 printf (_("\nThere are no dynamic relocations in this file.\n"));
7351 Elf_Internal_Shdr
* section
;
7353 bfd_boolean found
= FALSE
;
7355 for (i
= 0, section
= filedata
->section_headers
;
7356 i
< filedata
->file_header
.e_shnum
;
7359 if ( section
->sh_type
!= SHT_RELA
7360 && section
->sh_type
!= SHT_REL
)
7363 rel_offset
= section
->sh_offset
;
7364 rel_size
= section
->sh_size
;
7368 Elf_Internal_Shdr
* strsec
;
7370 unsigned long num_rela
;
7372 printf (_("\nRelocation section "));
7374 if (filedata
->string_table
== NULL
)
7375 printf ("%d", section
->sh_name
);
7377 printf ("'%s'", printable_section_name (filedata
, section
));
7379 num_rela
= rel_size
/ section
->sh_entsize
;
7380 printf (ngettext (" at offset 0x%lx contains %lu entry:\n",
7381 " at offset 0x%lx contains %lu entries:\n",
7383 rel_offset
, num_rela
);
7385 is_rela
= section
->sh_type
== SHT_RELA
;
7387 if (section
->sh_link
!= 0
7388 && section
->sh_link
< filedata
->file_header
.e_shnum
)
7390 Elf_Internal_Shdr
* symsec
;
7391 Elf_Internal_Sym
* symtab
;
7392 unsigned long nsyms
;
7393 unsigned long strtablen
= 0;
7394 char * strtab
= NULL
;
7396 symsec
= filedata
->section_headers
+ section
->sh_link
;
7397 if (symsec
->sh_type
!= SHT_SYMTAB
7398 && symsec
->sh_type
!= SHT_DYNSYM
)
7401 symtab
= GET_ELF_SYMBOLS (filedata
, symsec
, & nsyms
);
7406 if (symsec
->sh_link
!= 0
7407 && symsec
->sh_link
< filedata
->file_header
.e_shnum
)
7409 strsec
= filedata
->section_headers
+ symsec
->sh_link
;
7411 strtab
= (char *) get_data (NULL
, filedata
, strsec
->sh_offset
,
7414 strtablen
= strtab
== NULL
? 0 : strsec
->sh_size
;
7417 dump_relocations (filedata
, rel_offset
, rel_size
,
7418 symtab
, nsyms
, strtab
, strtablen
,
7420 symsec
->sh_type
== SHT_DYNSYM
);
7426 dump_relocations (filedata
, rel_offset
, rel_size
,
7427 NULL
, 0, NULL
, 0, is_rela
,
7428 FALSE
/* is_dynamic */);
7436 /* Users sometimes forget the -D option, so try to be helpful. */
7437 for (i
= 0; i
< ARRAY_SIZE (dynamic_relocations
); i
++)
7439 if (dynamic_info
[dynamic_relocations
[i
].size
])
7441 printf (_("\nThere are no static relocations in this file."));
7442 printf (_("\nTo see the dynamic relocations add --use-dynamic to the command line.\n"));
7447 if (i
== ARRAY_SIZE (dynamic_relocations
))
7448 printf (_("\nThere are no relocations in this file.\n"));
7455 /* An absolute address consists of a section and an offset. If the
7456 section is NULL, the offset itself is the address, otherwise, the
7457 address equals to LOAD_ADDRESS(section) + offset. */
7461 unsigned short section
;
7465 /* Find the nearest symbol at or below ADDR. Returns the symbol
7466 name, if found, and the offset from the symbol to ADDR. */
7469 find_symbol_for_address (Filedata
* filedata
,
7470 Elf_Internal_Sym
* symtab
,
7471 unsigned long nsyms
,
7472 const char * strtab
,
7473 unsigned long strtab_size
,
7474 struct absaddr addr
,
7475 const char ** symname
,
7478 bfd_vma dist
= 0x100000;
7479 Elf_Internal_Sym
* sym
;
7480 Elf_Internal_Sym
* beg
;
7481 Elf_Internal_Sym
* end
;
7482 Elf_Internal_Sym
* best
= NULL
;
7484 REMOVE_ARCH_BITS (addr
.offset
);
7486 end
= symtab
+ nsyms
;
7492 sym
= beg
+ (end
- beg
) / 2;
7494 value
= sym
->st_value
;
7495 REMOVE_ARCH_BITS (value
);
7497 if (sym
->st_name
!= 0
7498 && (addr
.section
== SHN_UNDEF
|| addr
.section
== sym
->st_shndx
)
7499 && addr
.offset
>= value
7500 && addr
.offset
- value
< dist
)
7503 dist
= addr
.offset
- value
;
7508 if (addr
.offset
< value
)
7516 *symname
= (best
->st_name
>= strtab_size
7517 ? _("<corrupt>") : strtab
+ best
->st_name
);
7523 *offset
= addr
.offset
;
7526 static /* signed */ int
7527 symcmp (const void *p
, const void *q
)
7529 Elf_Internal_Sym
*sp
= (Elf_Internal_Sym
*) p
;
7530 Elf_Internal_Sym
*sq
= (Elf_Internal_Sym
*) q
;
7532 return sp
->st_value
> sq
->st_value
? 1 : (sp
->st_value
< sq
->st_value
? -1 : 0);
7535 /* Process the unwind section. */
7537 #include "unwind-ia64.h"
7539 struct ia64_unw_table_entry
7541 struct absaddr start
;
7543 struct absaddr info
;
7546 struct ia64_unw_aux_info
7548 struct ia64_unw_table_entry
* table
; /* Unwind table. */
7549 unsigned long table_len
; /* Length of unwind table. */
7550 unsigned char * info
; /* Unwind info. */
7551 unsigned long info_size
; /* Size of unwind info. */
7552 bfd_vma info_addr
; /* Starting address of unwind info. */
7553 bfd_vma seg_base
; /* Starting address of segment. */
7554 Elf_Internal_Sym
* symtab
; /* The symbol table. */
7555 unsigned long nsyms
; /* Number of symbols. */
7556 Elf_Internal_Sym
* funtab
; /* Sorted table of STT_FUNC symbols. */
7557 unsigned long nfuns
; /* Number of entries in funtab. */
7558 char * strtab
; /* The string table. */
7559 unsigned long strtab_size
; /* Size of string table. */
7563 dump_ia64_unwind (Filedata
* filedata
, struct ia64_unw_aux_info
* aux
)
7565 struct ia64_unw_table_entry
* tp
;
7566 unsigned long j
, nfuns
;
7568 bfd_boolean res
= TRUE
;
7570 aux
->funtab
= xmalloc (aux
->nsyms
* sizeof (Elf_Internal_Sym
));
7571 for (nfuns
= 0, j
= 0; j
< aux
->nsyms
; j
++)
7572 if (aux
->symtab
[j
].st_value
&& ELF_ST_TYPE (aux
->symtab
[j
].st_info
) == STT_FUNC
)
7573 aux
->funtab
[nfuns
++] = aux
->symtab
[j
];
7575 qsort (aux
->funtab
, aux
->nfuns
, sizeof (Elf_Internal_Sym
), symcmp
);
7577 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
7581 const unsigned char * dp
;
7582 const unsigned char * head
;
7583 const unsigned char * end
;
7584 const char * procname
;
7586 find_symbol_for_address (filedata
, aux
->funtab
, aux
->nfuns
, aux
->strtab
,
7587 aux
->strtab_size
, tp
->start
, &procname
, &offset
);
7589 fputs ("\n<", stdout
);
7593 fputs (procname
, stdout
);
7596 printf ("+%lx", (unsigned long) offset
);
7599 fputs (">: [", stdout
);
7600 print_vma (tp
->start
.offset
, PREFIX_HEX
);
7601 fputc ('-', stdout
);
7602 print_vma (tp
->end
.offset
, PREFIX_HEX
);
7603 printf ("], info at +0x%lx\n",
7604 (unsigned long) (tp
->info
.offset
- aux
->seg_base
));
7606 /* PR 17531: file: 86232b32. */
7607 if (aux
->info
== NULL
)
7610 offset
= tp
->info
.offset
;
7611 if (tp
->info
.section
)
7613 if (tp
->info
.section
>= filedata
->file_header
.e_shnum
)
7615 warn (_("Invalid section %u in table entry %ld\n"),
7616 tp
->info
.section
, (long) (tp
- aux
->table
));
7620 offset
+= filedata
->section_headers
[tp
->info
.section
].sh_addr
;
7622 offset
-= aux
->info_addr
;
7623 /* PR 17531: file: 0997b4d1. */
7624 if (offset
>= aux
->info_size
7625 || aux
->info_size
- offset
< 8)
7627 warn (_("Invalid offset %lx in table entry %ld\n"),
7628 (long) tp
->info
.offset
, (long) (tp
- aux
->table
));
7633 head
= aux
->info
+ offset
;
7634 stamp
= byte_get ((unsigned char *) head
, sizeof (stamp
));
7636 printf (" v%u, flags=0x%lx (%s%s), len=%lu bytes\n",
7637 (unsigned) UNW_VER (stamp
),
7638 (unsigned long) ((stamp
& UNW_FLAG_MASK
) >> 32),
7639 UNW_FLAG_EHANDLER (stamp
) ? " ehandler" : "",
7640 UNW_FLAG_UHANDLER (stamp
) ? " uhandler" : "",
7641 (unsigned long) (eh_addr_size
* UNW_LENGTH (stamp
)));
7643 if (UNW_VER (stamp
) != 1)
7645 printf (_("\tUnknown version.\n"));
7650 end
= head
+ 8 + eh_addr_size
* UNW_LENGTH (stamp
);
7651 /* PR 17531: file: 16ceda89. */
7652 if (end
> aux
->info
+ aux
->info_size
)
7653 end
= aux
->info
+ aux
->info_size
;
7654 for (dp
= head
+ 8; dp
< end
;)
7655 dp
= unw_decode (dp
, in_body
, & in_body
, end
);
7664 slurp_ia64_unwind_table (Filedata
* filedata
,
7665 struct ia64_unw_aux_info
* aux
,
7666 Elf_Internal_Shdr
* sec
)
7668 unsigned long size
, nrelas
, i
;
7669 Elf_Internal_Phdr
* seg
;
7670 struct ia64_unw_table_entry
* tep
;
7671 Elf_Internal_Shdr
* relsec
;
7672 Elf_Internal_Rela
* rela
;
7673 Elf_Internal_Rela
* rp
;
7674 unsigned char * table
;
7676 Elf_Internal_Sym
* sym
;
7677 const char * relname
;
7681 /* First, find the starting address of the segment that includes
7684 if (filedata
->file_header
.e_phnum
)
7686 if (! get_program_headers (filedata
))
7689 for (seg
= filedata
->program_headers
;
7690 seg
< filedata
->program_headers
+ filedata
->file_header
.e_phnum
;
7693 if (seg
->p_type
!= PT_LOAD
)
7696 if (sec
->sh_addr
>= seg
->p_vaddr
7697 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
7699 aux
->seg_base
= seg
->p_vaddr
;
7705 /* Second, build the unwind table from the contents of the unwind section: */
7706 size
= sec
->sh_size
;
7707 table
= (unsigned char *) get_data (NULL
, filedata
, sec
->sh_offset
, 1, size
,
7712 aux
->table_len
= size
/ (3 * eh_addr_size
);
7713 aux
->table
= (struct ia64_unw_table_entry
*)
7714 xcmalloc (aux
->table_len
, sizeof (aux
->table
[0]));
7717 for (tp
= table
; tp
<= table
+ size
- (3 * eh_addr_size
); ++tep
)
7719 tep
->start
.section
= SHN_UNDEF
;
7720 tep
->end
.section
= SHN_UNDEF
;
7721 tep
->info
.section
= SHN_UNDEF
;
7722 tep
->start
.offset
= byte_get (tp
, eh_addr_size
); tp
+= eh_addr_size
;
7723 tep
->end
.offset
= byte_get (tp
, eh_addr_size
); tp
+= eh_addr_size
;
7724 tep
->info
.offset
= byte_get (tp
, eh_addr_size
); tp
+= eh_addr_size
;
7725 tep
->start
.offset
+= aux
->seg_base
;
7726 tep
->end
.offset
+= aux
->seg_base
;
7727 tep
->info
.offset
+= aux
->seg_base
;
7731 /* Third, apply any relocations to the unwind table: */
7732 for (relsec
= filedata
->section_headers
;
7733 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
7736 if (relsec
->sh_type
!= SHT_RELA
7737 || relsec
->sh_info
>= filedata
->file_header
.e_shnum
7738 || filedata
->section_headers
+ relsec
->sh_info
!= sec
)
7741 if (!slurp_rela_relocs (filedata
, relsec
->sh_offset
, relsec
->sh_size
,
7750 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
7752 unsigned int sym_ndx
;
7753 unsigned int r_type
= get_reloc_type (filedata
, rp
->r_info
);
7754 relname
= elf_ia64_reloc_type (r_type
);
7756 /* PR 17531: file: 9fa67536. */
7757 if (relname
== NULL
)
7759 warn (_("Skipping unknown relocation type: %u\n"), r_type
);
7763 if (! const_strneq (relname
, "R_IA64_SEGREL"))
7765 warn (_("Skipping unexpected relocation type: %s\n"), relname
);
7769 i
= rp
->r_offset
/ (3 * eh_addr_size
);
7771 /* PR 17531: file: 5bc8d9bf. */
7772 if (i
>= aux
->table_len
)
7774 warn (_("Skipping reloc with overlarge offset: %lx\n"), i
);
7778 sym_ndx
= get_reloc_symindex (rp
->r_info
);
7779 if (sym_ndx
>= aux
->nsyms
)
7781 warn (_("Skipping reloc with invalid symbol index: %u\n"),
7785 sym
= aux
->symtab
+ sym_ndx
;
7787 switch (rp
->r_offset
/ eh_addr_size
% 3)
7790 aux
->table
[i
].start
.section
= sym
->st_shndx
;
7791 aux
->table
[i
].start
.offset
= rp
->r_addend
+ sym
->st_value
;
7794 aux
->table
[i
].end
.section
= sym
->st_shndx
;
7795 aux
->table
[i
].end
.offset
= rp
->r_addend
+ sym
->st_value
;
7798 aux
->table
[i
].info
.section
= sym
->st_shndx
;
7799 aux
->table
[i
].info
.offset
= rp
->r_addend
+ sym
->st_value
;
7813 ia64_process_unwind (Filedata
* filedata
)
7815 Elf_Internal_Shdr
* sec
;
7816 Elf_Internal_Shdr
* unwsec
= NULL
;
7817 Elf_Internal_Shdr
* strsec
;
7818 unsigned long i
, unwcount
= 0, unwstart
= 0;
7819 struct ia64_unw_aux_info aux
;
7820 bfd_boolean res
= TRUE
;
7822 memset (& aux
, 0, sizeof (aux
));
7824 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
7826 if (sec
->sh_type
== SHT_SYMTAB
7827 && sec
->sh_link
< filedata
->file_header
.e_shnum
)
7829 aux
.symtab
= GET_ELF_SYMBOLS (filedata
, sec
, & aux
.nsyms
);
7831 strsec
= filedata
->section_headers
+ sec
->sh_link
;
7832 if (aux
.strtab
!= NULL
)
7834 error (_("Multiple auxillary string tables encountered\n"));
7838 aux
.strtab
= (char *) get_data (NULL
, filedata
, strsec
->sh_offset
,
7841 aux
.strtab_size
= aux
.strtab
!= NULL
? strsec
->sh_size
: 0;
7843 else if (sec
->sh_type
== SHT_IA_64_UNWIND
)
7848 printf (_("\nThere are no unwind sections in this file.\n"));
7850 while (unwcount
-- > 0)
7855 for (i
= unwstart
, sec
= filedata
->section_headers
+ unwstart
, unwsec
= NULL
;
7856 i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
7857 if (sec
->sh_type
== SHT_IA_64_UNWIND
)
7862 /* We have already counted the number of SHT_IA64_UNWIND
7863 sections so the loop above should never fail. */
7864 assert (unwsec
!= NULL
);
7867 len
= sizeof (ELF_STRING_ia64_unwind_once
) - 1;
7869 if ((unwsec
->sh_flags
& SHF_GROUP
) != 0)
7871 /* We need to find which section group it is in. */
7872 struct group_list
* g
;
7874 if (section_headers_groups
== NULL
7875 || section_headers_groups
[i
] == NULL
)
7876 i
= filedata
->file_header
.e_shnum
;
7879 g
= section_headers_groups
[i
]->root
;
7881 for (; g
!= NULL
; g
= g
->next
)
7883 sec
= filedata
->section_headers
+ g
->section_index
;
7885 if (streq (SECTION_NAME (sec
), ELF_STRING_ia64_unwind_info
))
7890 i
= filedata
->file_header
.e_shnum
;
7893 else if (strneq (SECTION_NAME (unwsec
), ELF_STRING_ia64_unwind_once
, len
))
7895 /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO. */
7896 len2
= sizeof (ELF_STRING_ia64_unwind_info_once
) - 1;
7897 suffix
= SECTION_NAME (unwsec
) + len
;
7898 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
;
7900 if (strneq (SECTION_NAME (sec
), ELF_STRING_ia64_unwind_info_once
, len2
)
7901 && streq (SECTION_NAME (sec
) + len2
, suffix
))
7906 /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
7907 .IA_64.unwind or BAR -> .IA_64.unwind_info. */
7908 len
= sizeof (ELF_STRING_ia64_unwind
) - 1;
7909 len2
= sizeof (ELF_STRING_ia64_unwind_info
) - 1;
7911 if (strneq (SECTION_NAME (unwsec
), ELF_STRING_ia64_unwind
, len
))
7912 suffix
= SECTION_NAME (unwsec
) + len
;
7913 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
;
7915 if (strneq (SECTION_NAME (sec
), ELF_STRING_ia64_unwind_info
, len2
)
7916 && streq (SECTION_NAME (sec
) + len2
, suffix
))
7920 if (i
== filedata
->file_header
.e_shnum
)
7922 printf (_("\nCould not find unwind info section for "));
7924 if (filedata
->string_table
== NULL
)
7925 printf ("%d", unwsec
->sh_name
);
7927 printf ("'%s'", printable_section_name (filedata
, unwsec
));
7931 aux
.info_addr
= sec
->sh_addr
;
7932 aux
.info
= (unsigned char *) get_data (NULL
, filedata
, sec
->sh_offset
, 1,
7935 aux
.info_size
= aux
.info
== NULL
? 0 : sec
->sh_size
;
7937 printf (_("\nUnwind section "));
7939 if (filedata
->string_table
== NULL
)
7940 printf ("%d", unwsec
->sh_name
);
7942 printf ("'%s'", printable_section_name (filedata
, unwsec
));
7944 printf (_(" at offset 0x%lx contains %lu entries:\n"),
7945 (unsigned long) unwsec
->sh_offset
,
7946 (unsigned long) (unwsec
->sh_size
/ (3 * eh_addr_size
)));
7948 if (slurp_ia64_unwind_table (filedata
, & aux
, unwsec
)
7949 && aux
.table_len
> 0)
7950 dump_ia64_unwind (filedata
, & aux
);
7953 free ((char *) aux
.table
);
7955 free ((char *) aux
.info
);
7964 free ((char *) aux
.strtab
);
7969 struct hppa_unw_table_entry
7971 struct absaddr start
;
7973 unsigned int Cannot_unwind
:1; /* 0 */
7974 unsigned int Millicode
:1; /* 1 */
7975 unsigned int Millicode_save_sr0
:1; /* 2 */
7976 unsigned int Region_description
:2; /* 3..4 */
7977 unsigned int reserved1
:1; /* 5 */
7978 unsigned int Entry_SR
:1; /* 6 */
7979 unsigned int Entry_FR
:4; /* Number saved 7..10 */
7980 unsigned int Entry_GR
:5; /* Number saved 11..15 */
7981 unsigned int Args_stored
:1; /* 16 */
7982 unsigned int Variable_Frame
:1; /* 17 */
7983 unsigned int Separate_Package_Body
:1; /* 18 */
7984 unsigned int Frame_Extension_Millicode
:1; /* 19 */
7985 unsigned int Stack_Overflow_Check
:1; /* 20 */
7986 unsigned int Two_Instruction_SP_Increment
:1; /* 21 */
7987 unsigned int Ada_Region
:1; /* 22 */
7988 unsigned int cxx_info
:1; /* 23 */
7989 unsigned int cxx_try_catch
:1; /* 24 */
7990 unsigned int sched_entry_seq
:1; /* 25 */
7991 unsigned int reserved2
:1; /* 26 */
7992 unsigned int Save_SP
:1; /* 27 */
7993 unsigned int Save_RP
:1; /* 28 */
7994 unsigned int Save_MRP_in_frame
:1; /* 29 */
7995 unsigned int extn_ptr_defined
:1; /* 30 */
7996 unsigned int Cleanup_defined
:1; /* 31 */
7998 unsigned int MPE_XL_interrupt_marker
:1; /* 0 */
7999 unsigned int HP_UX_interrupt_marker
:1; /* 1 */
8000 unsigned int Large_frame
:1; /* 2 */
8001 unsigned int Pseudo_SP_Set
:1; /* 3 */
8002 unsigned int reserved4
:1; /* 4 */
8003 unsigned int Total_frame_size
:27; /* 5..31 */
8006 struct hppa_unw_aux_info
8008 struct hppa_unw_table_entry
* table
; /* Unwind table. */
8009 unsigned long table_len
; /* Length of unwind table. */
8010 bfd_vma seg_base
; /* Starting address of segment. */
8011 Elf_Internal_Sym
* symtab
; /* The symbol table. */
8012 unsigned long nsyms
; /* Number of symbols. */
8013 Elf_Internal_Sym
* funtab
; /* Sorted table of STT_FUNC symbols. */
8014 unsigned long nfuns
; /* Number of entries in funtab. */
8015 char * strtab
; /* The string table. */
8016 unsigned long strtab_size
; /* Size of string table. */
8020 dump_hppa_unwind (Filedata
* filedata
, struct hppa_unw_aux_info
* aux
)
8022 struct hppa_unw_table_entry
* tp
;
8023 unsigned long j
, nfuns
;
8024 bfd_boolean res
= TRUE
;
8026 aux
->funtab
= xmalloc (aux
->nsyms
* sizeof (Elf_Internal_Sym
));
8027 for (nfuns
= 0, j
= 0; j
< aux
->nsyms
; j
++)
8028 if (aux
->symtab
[j
].st_value
&& ELF_ST_TYPE (aux
->symtab
[j
].st_info
) == STT_FUNC
)
8029 aux
->funtab
[nfuns
++] = aux
->symtab
[j
];
8031 qsort (aux
->funtab
, aux
->nfuns
, sizeof (Elf_Internal_Sym
), symcmp
);
8033 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
8036 const char * procname
;
8038 find_symbol_for_address (filedata
, aux
->funtab
, aux
->nfuns
, aux
->strtab
,
8039 aux
->strtab_size
, tp
->start
, &procname
,
8042 fputs ("\n<", stdout
);
8046 fputs (procname
, stdout
);
8049 printf ("+%lx", (unsigned long) offset
);
8052 fputs (">: [", stdout
);
8053 print_vma (tp
->start
.offset
, PREFIX_HEX
);
8054 fputc ('-', stdout
);
8055 print_vma (tp
->end
.offset
, PREFIX_HEX
);
8058 #define PF(_m) if (tp->_m) printf (#_m " ");
8059 #define PV(_m) if (tp->_m) printf (#_m "=%d ", tp->_m);
8062 PF(Millicode_save_sr0
);
8063 /* PV(Region_description); */
8069 PF(Separate_Package_Body
);
8070 PF(Frame_Extension_Millicode
);
8071 PF(Stack_Overflow_Check
);
8072 PF(Two_Instruction_SP_Increment
);
8076 PF(sched_entry_seq
);
8079 PF(Save_MRP_in_frame
);
8080 PF(extn_ptr_defined
);
8081 PF(Cleanup_defined
);
8082 PF(MPE_XL_interrupt_marker
);
8083 PF(HP_UX_interrupt_marker
);
8086 PV(Total_frame_size
);
8099 slurp_hppa_unwind_table (Filedata
* filedata
,
8100 struct hppa_unw_aux_info
* aux
,
8101 Elf_Internal_Shdr
* sec
)
8103 unsigned long size
, unw_ent_size
, nentries
, nrelas
, i
;
8104 Elf_Internal_Phdr
* seg
;
8105 struct hppa_unw_table_entry
* tep
;
8106 Elf_Internal_Shdr
* relsec
;
8107 Elf_Internal_Rela
* rela
;
8108 Elf_Internal_Rela
* rp
;
8109 unsigned char * table
;
8111 Elf_Internal_Sym
* sym
;
8112 const char * relname
;
8114 /* First, find the starting address of the segment that includes
8116 if (filedata
->file_header
.e_phnum
)
8118 if (! get_program_headers (filedata
))
8121 for (seg
= filedata
->program_headers
;
8122 seg
< filedata
->program_headers
+ filedata
->file_header
.e_phnum
;
8125 if (seg
->p_type
!= PT_LOAD
)
8128 if (sec
->sh_addr
>= seg
->p_vaddr
8129 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
8131 aux
->seg_base
= seg
->p_vaddr
;
8137 /* Second, build the unwind table from the contents of the unwind
8139 size
= sec
->sh_size
;
8140 table
= (unsigned char *) get_data (NULL
, filedata
, sec
->sh_offset
, 1, size
,
8146 nentries
= size
/ unw_ent_size
;
8147 size
= unw_ent_size
* nentries
;
8149 tep
= aux
->table
= (struct hppa_unw_table_entry
*)
8150 xcmalloc (nentries
, sizeof (aux
->table
[0]));
8152 for (tp
= table
; tp
< table
+ size
; tp
+= unw_ent_size
, ++tep
)
8154 unsigned int tmp1
, tmp2
;
8156 tep
->start
.section
= SHN_UNDEF
;
8157 tep
->end
.section
= SHN_UNDEF
;
8159 tep
->start
.offset
= byte_get ((unsigned char *) tp
+ 0, 4);
8160 tep
->end
.offset
= byte_get ((unsigned char *) tp
+ 4, 4);
8161 tmp1
= byte_get ((unsigned char *) tp
+ 8, 4);
8162 tmp2
= byte_get ((unsigned char *) tp
+ 12, 4);
8164 tep
->start
.offset
+= aux
->seg_base
;
8165 tep
->end
.offset
+= aux
->seg_base
;
8167 tep
->Cannot_unwind
= (tmp1
>> 31) & 0x1;
8168 tep
->Millicode
= (tmp1
>> 30) & 0x1;
8169 tep
->Millicode_save_sr0
= (tmp1
>> 29) & 0x1;
8170 tep
->Region_description
= (tmp1
>> 27) & 0x3;
8171 tep
->reserved1
= (tmp1
>> 26) & 0x1;
8172 tep
->Entry_SR
= (tmp1
>> 25) & 0x1;
8173 tep
->Entry_FR
= (tmp1
>> 21) & 0xf;
8174 tep
->Entry_GR
= (tmp1
>> 16) & 0x1f;
8175 tep
->Args_stored
= (tmp1
>> 15) & 0x1;
8176 tep
->Variable_Frame
= (tmp1
>> 14) & 0x1;
8177 tep
->Separate_Package_Body
= (tmp1
>> 13) & 0x1;
8178 tep
->Frame_Extension_Millicode
= (tmp1
>> 12) & 0x1;
8179 tep
->Stack_Overflow_Check
= (tmp1
>> 11) & 0x1;
8180 tep
->Two_Instruction_SP_Increment
= (tmp1
>> 10) & 0x1;
8181 tep
->Ada_Region
= (tmp1
>> 9) & 0x1;
8182 tep
->cxx_info
= (tmp1
>> 8) & 0x1;
8183 tep
->cxx_try_catch
= (tmp1
>> 7) & 0x1;
8184 tep
->sched_entry_seq
= (tmp1
>> 6) & 0x1;
8185 tep
->reserved2
= (tmp1
>> 5) & 0x1;
8186 tep
->Save_SP
= (tmp1
>> 4) & 0x1;
8187 tep
->Save_RP
= (tmp1
>> 3) & 0x1;
8188 tep
->Save_MRP_in_frame
= (tmp1
>> 2) & 0x1;
8189 tep
->extn_ptr_defined
= (tmp1
>> 1) & 0x1;
8190 tep
->Cleanup_defined
= tmp1
& 0x1;
8192 tep
->MPE_XL_interrupt_marker
= (tmp2
>> 31) & 0x1;
8193 tep
->HP_UX_interrupt_marker
= (tmp2
>> 30) & 0x1;
8194 tep
->Large_frame
= (tmp2
>> 29) & 0x1;
8195 tep
->Pseudo_SP_Set
= (tmp2
>> 28) & 0x1;
8196 tep
->reserved4
= (tmp2
>> 27) & 0x1;
8197 tep
->Total_frame_size
= tmp2
& 0x7ffffff;
8201 /* Third, apply any relocations to the unwind table. */
8202 for (relsec
= filedata
->section_headers
;
8203 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
8206 if (relsec
->sh_type
!= SHT_RELA
8207 || relsec
->sh_info
>= filedata
->file_header
.e_shnum
8208 || filedata
->section_headers
+ relsec
->sh_info
!= sec
)
8211 if (!slurp_rela_relocs (filedata
, relsec
->sh_offset
, relsec
->sh_size
,
8215 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
8217 unsigned int sym_ndx
;
8218 unsigned int r_type
= get_reloc_type (filedata
, rp
->r_info
);
8219 relname
= elf_hppa_reloc_type (r_type
);
8221 if (relname
== NULL
)
8223 warn (_("Skipping unknown relocation type: %u\n"), r_type
);
8227 /* R_PARISC_SEGREL32 or R_PARISC_SEGREL64. */
8228 if (! const_strneq (relname
, "R_PARISC_SEGREL"))
8230 warn (_("Skipping unexpected relocation type: %s\n"), relname
);
8234 i
= rp
->r_offset
/ unw_ent_size
;
8235 if (i
>= aux
->table_len
)
8237 warn (_("Skipping reloc with overlarge offset: %lx\n"), i
);
8241 sym_ndx
= get_reloc_symindex (rp
->r_info
);
8242 if (sym_ndx
>= aux
->nsyms
)
8244 warn (_("Skipping reloc with invalid symbol index: %u\n"),
8248 sym
= aux
->symtab
+ sym_ndx
;
8250 switch ((rp
->r_offset
% unw_ent_size
) / 4)
8253 aux
->table
[i
].start
.section
= sym
->st_shndx
;
8254 aux
->table
[i
].start
.offset
= sym
->st_value
+ rp
->r_addend
;
8257 aux
->table
[i
].end
.section
= sym
->st_shndx
;
8258 aux
->table
[i
].end
.offset
= sym
->st_value
+ rp
->r_addend
;
8268 aux
->table_len
= nentries
;
8274 hppa_process_unwind (Filedata
* filedata
)
8276 struct hppa_unw_aux_info aux
;
8277 Elf_Internal_Shdr
* unwsec
= NULL
;
8278 Elf_Internal_Shdr
* strsec
;
8279 Elf_Internal_Shdr
* sec
;
8281 bfd_boolean res
= TRUE
;
8283 if (filedata
->string_table
== NULL
)
8286 memset (& aux
, 0, sizeof (aux
));
8288 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
8290 if (sec
->sh_type
== SHT_SYMTAB
8291 && sec
->sh_link
< filedata
->file_header
.e_shnum
)
8293 aux
.symtab
= GET_ELF_SYMBOLS (filedata
, sec
, & aux
.nsyms
);
8295 strsec
= filedata
->section_headers
+ sec
->sh_link
;
8296 if (aux
.strtab
!= NULL
)
8298 error (_("Multiple auxillary string tables encountered\n"));
8302 aux
.strtab
= (char *) get_data (NULL
, filedata
, strsec
->sh_offset
,
8305 aux
.strtab_size
= aux
.strtab
!= NULL
? strsec
->sh_size
: 0;
8307 else if (streq (SECTION_NAME (sec
), ".PARISC.unwind"))
8312 printf (_("\nThere are no unwind sections in this file.\n"));
8314 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
8316 if (streq (SECTION_NAME (sec
), ".PARISC.unwind"))
8318 unsigned long num_unwind
= sec
->sh_size
/ 16;
8320 printf (ngettext ("\nUnwind section '%s' at offset 0x%lx "
8321 "contains %lu entry:\n",
8322 "\nUnwind section '%s' at offset 0x%lx "
8323 "contains %lu entries:\n",
8325 printable_section_name (filedata
, sec
),
8326 (unsigned long) sec
->sh_offset
,
8329 if (! slurp_hppa_unwind_table (filedata
, &aux
, sec
))
8332 if (res
&& aux
.table_len
> 0)
8334 if (! dump_hppa_unwind (filedata
, &aux
))
8339 free ((char *) aux
.table
);
8347 free ((char *) aux
.strtab
);
8354 unsigned char * data
; /* The unwind data. */
8355 Elf_Internal_Shdr
* sec
; /* The cached unwind section header. */
8356 Elf_Internal_Rela
* rela
; /* The cached relocations for this section. */
8357 unsigned long nrelas
; /* The number of relocations. */
8358 unsigned int rel_type
; /* REL or RELA ? */
8359 Elf_Internal_Rela
* next_rela
; /* Cyclic pointer to the next reloc to process. */
8362 struct arm_unw_aux_info
8364 Filedata
* filedata
; /* The file containing the unwind sections. */
8365 Elf_Internal_Sym
* symtab
; /* The file's symbol table. */
8366 unsigned long nsyms
; /* Number of symbols. */
8367 Elf_Internal_Sym
* funtab
; /* Sorted table of STT_FUNC symbols. */
8368 unsigned long nfuns
; /* Number of these symbols. */
8369 char * strtab
; /* The file's string table. */
8370 unsigned long strtab_size
; /* Size of string table. */
8374 arm_print_vma_and_name (Filedata
* filedata
,
8375 struct arm_unw_aux_info
* aux
,
8377 struct absaddr addr
)
8379 const char *procname
;
8382 if (addr
.section
== SHN_UNDEF
)
8385 find_symbol_for_address (filedata
, aux
->funtab
, aux
->nfuns
, aux
->strtab
,
8386 aux
->strtab_size
, addr
, &procname
,
8389 print_vma (fn
, PREFIX_HEX
);
8393 fputs (" <", stdout
);
8394 fputs (procname
, stdout
);
8397 printf ("+0x%lx", (unsigned long) sym_offset
);
8398 fputc ('>', stdout
);
8405 arm_free_section (struct arm_section
*arm_sec
)
8407 if (arm_sec
->data
!= NULL
)
8408 free (arm_sec
->data
);
8410 if (arm_sec
->rela
!= NULL
)
8411 free (arm_sec
->rela
);
8414 /* 1) If SEC does not match the one cached in ARM_SEC, then free the current
8415 cached section and install SEC instead.
8416 2) Locate the 32-bit word at WORD_OFFSET in unwind section SEC
8417 and return its valued in * WORDP, relocating if necessary.
8418 3) Update the NEXT_RELA field in ARM_SEC and store the section index and
8419 relocation's offset in ADDR.
8420 4) If SYM_NAME is non-NULL and a relocation was applied, record the offset
8421 into the string table of the symbol associated with the reloc. If no
8422 reloc was applied store -1 there.
8423 5) Return TRUE upon success, FALSE otherwise. */
8426 get_unwind_section_word (Filedata
* filedata
,
8427 struct arm_unw_aux_info
* aux
,
8428 struct arm_section
* arm_sec
,
8429 Elf_Internal_Shdr
* sec
,
8430 bfd_vma word_offset
,
8431 unsigned int * wordp
,
8432 struct absaddr
* addr
,
8435 Elf_Internal_Rela
*rp
;
8436 Elf_Internal_Sym
*sym
;
8437 const char * relname
;
8439 bfd_boolean wrapped
;
8441 if (sec
== NULL
|| arm_sec
== NULL
)
8444 addr
->section
= SHN_UNDEF
;
8447 if (sym_name
!= NULL
)
8448 *sym_name
= (bfd_vma
) -1;
8450 /* If necessary, update the section cache. */
8451 if (sec
!= arm_sec
->sec
)
8453 Elf_Internal_Shdr
*relsec
;
8455 arm_free_section (arm_sec
);
8458 arm_sec
->data
= get_data (NULL
, aux
->filedata
, sec
->sh_offset
, 1,
8459 sec
->sh_size
, _("unwind data"));
8460 arm_sec
->rela
= NULL
;
8461 arm_sec
->nrelas
= 0;
8463 for (relsec
= filedata
->section_headers
;
8464 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
8467 if (relsec
->sh_info
>= filedata
->file_header
.e_shnum
8468 || filedata
->section_headers
+ relsec
->sh_info
!= sec
8469 /* PR 15745: Check the section type as well. */
8470 || (relsec
->sh_type
!= SHT_REL
8471 && relsec
->sh_type
!= SHT_RELA
))
8474 arm_sec
->rel_type
= relsec
->sh_type
;
8475 if (relsec
->sh_type
== SHT_REL
)
8477 if (!slurp_rel_relocs (aux
->filedata
, relsec
->sh_offset
,
8479 & arm_sec
->rela
, & arm_sec
->nrelas
))
8482 else /* relsec->sh_type == SHT_RELA */
8484 if (!slurp_rela_relocs (aux
->filedata
, relsec
->sh_offset
,
8486 & arm_sec
->rela
, & arm_sec
->nrelas
))
8492 arm_sec
->next_rela
= arm_sec
->rela
;
8495 /* If there is no unwind data we can do nothing. */
8496 if (arm_sec
->data
== NULL
)
8499 /* If the offset is invalid then fail. */
8500 if (/* PR 21343 *//* PR 18879 */
8502 || word_offset
> (sec
->sh_size
- 4)
8503 || ((bfd_signed_vma
) word_offset
) < 0)
8506 /* Get the word at the required offset. */
8507 word
= byte_get (arm_sec
->data
+ word_offset
, 4);
8509 /* PR 17531: file: id:000001,src:001266+003044,op:splice,rep:128. */
8510 if (arm_sec
->rela
== NULL
)
8516 /* Look through the relocs to find the one that applies to the provided offset. */
8518 for (rp
= arm_sec
->next_rela
; rp
!= arm_sec
->rela
+ arm_sec
->nrelas
; rp
++)
8520 bfd_vma prelval
, offset
;
8522 if (rp
->r_offset
> word_offset
&& !wrapped
)
8527 if (rp
->r_offset
> word_offset
)
8530 if (rp
->r_offset
& 3)
8532 warn (_("Skipping unexpected relocation at offset 0x%lx\n"),
8533 (unsigned long) rp
->r_offset
);
8537 if (rp
->r_offset
< word_offset
)
8540 /* PR 17531: file: 027-161405-0.004 */
8541 if (aux
->symtab
== NULL
)
8544 if (arm_sec
->rel_type
== SHT_REL
)
8546 offset
= word
& 0x7fffffff;
8547 if (offset
& 0x40000000)
8548 offset
|= ~ (bfd_vma
) 0x7fffffff;
8550 else if (arm_sec
->rel_type
== SHT_RELA
)
8551 offset
= rp
->r_addend
;
8554 error (_("Unknown section relocation type %d encountered\n"),
8559 /* PR 17531 file: 027-1241568-0.004. */
8560 if (ELF32_R_SYM (rp
->r_info
) >= aux
->nsyms
)
8562 error (_("Bad symbol index in unwind relocation (%lu > %lu)\n"),
8563 (unsigned long) ELF32_R_SYM (rp
->r_info
), aux
->nsyms
);
8567 sym
= aux
->symtab
+ ELF32_R_SYM (rp
->r_info
);
8568 offset
+= sym
->st_value
;
8569 prelval
= offset
- (arm_sec
->sec
->sh_addr
+ rp
->r_offset
);
8571 /* Check that we are processing the expected reloc type. */
8572 if (filedata
->file_header
.e_machine
== EM_ARM
)
8574 relname
= elf_arm_reloc_type (ELF32_R_TYPE (rp
->r_info
));
8575 if (relname
== NULL
)
8577 warn (_("Skipping unknown ARM relocation type: %d\n"),
8578 (int) ELF32_R_TYPE (rp
->r_info
));
8582 if (streq (relname
, "R_ARM_NONE"))
8585 if (! streq (relname
, "R_ARM_PREL31"))
8587 warn (_("Skipping unexpected ARM relocation type %s\n"), relname
);
8591 else if (filedata
->file_header
.e_machine
== EM_TI_C6000
)
8593 relname
= elf_tic6x_reloc_type (ELF32_R_TYPE (rp
->r_info
));
8594 if (relname
== NULL
)
8596 warn (_("Skipping unknown C6000 relocation type: %d\n"),
8597 (int) ELF32_R_TYPE (rp
->r_info
));
8601 if (streq (relname
, "R_C6000_NONE"))
8604 if (! streq (relname
, "R_C6000_PREL31"))
8606 warn (_("Skipping unexpected C6000 relocation type %s\n"), relname
);
8614 /* This function currently only supports ARM and TI unwinders. */
8615 warn (_("Only TI and ARM unwinders are currently supported\n"));
8619 word
= (word
& ~ (bfd_vma
) 0x7fffffff) | (prelval
& 0x7fffffff);
8620 addr
->section
= sym
->st_shndx
;
8621 addr
->offset
= offset
;
8624 * sym_name
= sym
->st_name
;
8629 arm_sec
->next_rela
= rp
;
8634 static const char *tic6x_unwind_regnames
[16] =
8636 "A15", "B15", "B14", "B13", "B12", "B11", "B10", "B3",
8637 "A14", "A13", "A12", "A11", "A10",
8638 "[invalid reg 13]", "[invalid reg 14]", "[invalid reg 15]"
8642 decode_tic6x_unwind_regmask (unsigned int mask
)
8646 for (i
= 12; mask
; mask
>>= 1, i
--)
8650 fputs (tic6x_unwind_regnames
[i
], stdout
);
8652 fputs (", ", stdout
);
8658 if (remaining == 0 && more_words) \
8661 if (! get_unwind_section_word (filedata, aux, data_arm_sec, data_sec, \
8662 data_offset, & word, & addr, NULL)) \
8668 #define GET_OP(OP) \
8673 (OP) = word >> 24; \
8678 printf (_("[Truncated opcode]\n")); \
8681 printf ("0x%02x ", OP)
8684 decode_arm_unwind_bytecode (Filedata
* filedata
,
8685 struct arm_unw_aux_info
* aux
,
8687 unsigned int remaining
,
8688 unsigned int more_words
,
8689 bfd_vma data_offset
,
8690 Elf_Internal_Shdr
* data_sec
,
8691 struct arm_section
* data_arm_sec
)
8693 struct absaddr addr
;
8694 bfd_boolean res
= TRUE
;
8696 /* Decode the unwinding instructions. */
8699 unsigned int op
, op2
;
8708 printf (" 0x%02x ", op
);
8710 if ((op
& 0xc0) == 0x00)
8712 int offset
= ((op
& 0x3f) << 2) + 4;
8714 printf (" vsp = vsp + %d", offset
);
8716 else if ((op
& 0xc0) == 0x40)
8718 int offset
= ((op
& 0x3f) << 2) + 4;
8720 printf (" vsp = vsp - %d", offset
);
8722 else if ((op
& 0xf0) == 0x80)
8725 if (op
== 0x80 && op2
== 0)
8726 printf (_("Refuse to unwind"));
8729 unsigned int mask
= ((op
& 0x0f) << 8) | op2
;
8730 bfd_boolean first
= TRUE
;
8734 for (i
= 0; i
< 12; i
++)
8735 if (mask
& (1 << i
))
8741 printf ("r%d", 4 + i
);
8746 else if ((op
& 0xf0) == 0x90)
8748 if (op
== 0x9d || op
== 0x9f)
8749 printf (_(" [Reserved]"));
8751 printf (" vsp = r%d", op
& 0x0f);
8753 else if ((op
& 0xf0) == 0xa0)
8755 int end
= 4 + (op
& 0x07);
8756 bfd_boolean first
= TRUE
;
8760 for (i
= 4; i
<= end
; i
++)
8776 else if (op
== 0xb0)
8777 printf (_(" finish"));
8778 else if (op
== 0xb1)
8781 if (op2
== 0 || (op2
& 0xf0) != 0)
8782 printf (_("[Spare]"));
8785 unsigned int mask
= op2
& 0x0f;
8786 bfd_boolean first
= TRUE
;
8790 for (i
= 0; i
< 12; i
++)
8791 if (mask
& (1 << i
))
8802 else if (op
== 0xb2)
8804 unsigned char buf
[9];
8805 unsigned int i
, len
;
8806 unsigned long offset
;
8808 for (i
= 0; i
< sizeof (buf
); i
++)
8811 if ((buf
[i
] & 0x80) == 0)
8814 if (i
== sizeof (buf
))
8816 error (_("corrupt change to vsp"));
8821 offset
= read_uleb128 (buf
, &len
, buf
+ i
+ 1);
8822 assert (len
== i
+ 1);
8823 offset
= offset
* 4 + 0x204;
8824 printf ("vsp = vsp + %ld", offset
);
8827 else if (op
== 0xb3 || op
== 0xc8 || op
== 0xc9)
8829 unsigned int first
, last
;
8836 printf ("pop {D%d", first
);
8838 printf ("-D%d", first
+ last
);
8841 else if ((op
& 0xf8) == 0xb8 || (op
& 0xf8) == 0xd0)
8843 unsigned int count
= op
& 0x07;
8847 printf ("-D%d", 8 + count
);
8850 else if (op
>= 0xc0 && op
<= 0xc5)
8852 unsigned int count
= op
& 0x07;
8854 printf (" pop {wR10");
8856 printf ("-wR%d", 10 + count
);
8859 else if (op
== 0xc6)
8861 unsigned int first
, last
;
8866 printf ("pop {wR%d", first
);
8868 printf ("-wR%d", first
+ last
);
8871 else if (op
== 0xc7)
8874 if (op2
== 0 || (op2
& 0xf0) != 0)
8875 printf (_("[Spare]"));
8878 unsigned int mask
= op2
& 0x0f;
8879 bfd_boolean first
= TRUE
;
8883 for (i
= 0; i
< 4; i
++)
8884 if (mask
& (1 << i
))
8890 printf ("wCGR%d", i
);
8897 printf (_(" [unsupported opcode]"));
8908 decode_tic6x_unwind_bytecode (Filedata
* filedata
,
8909 struct arm_unw_aux_info
* aux
,
8911 unsigned int remaining
,
8912 unsigned int more_words
,
8913 bfd_vma data_offset
,
8914 Elf_Internal_Shdr
* data_sec
,
8915 struct arm_section
* data_arm_sec
)
8917 struct absaddr addr
;
8919 /* Decode the unwinding instructions. */
8922 unsigned int op
, op2
;
8931 printf (" 0x%02x ", op
);
8933 if ((op
& 0xc0) == 0x00)
8935 int offset
= ((op
& 0x3f) << 3) + 8;
8936 printf (" sp = sp + %d", offset
);
8938 else if ((op
& 0xc0) == 0x80)
8941 if (op
== 0x80 && op2
== 0)
8942 printf (_("Refuse to unwind"));
8945 unsigned int mask
= ((op
& 0x1f) << 8) | op2
;
8947 printf ("pop compact {");
8951 decode_tic6x_unwind_regmask (mask
);
8955 else if ((op
& 0xf0) == 0xc0)
8963 unsigned int offset
;
8967 /* Scan entire instruction first so that GET_OP output is not
8968 interleaved with disassembly. */
8970 for (i
= 0; nregs
< (op
& 0xf); i
++)
8976 regpos
[nregs
].offset
= i
* 2;
8977 regpos
[nregs
].reg
= reg
;
8984 regpos
[nregs
].offset
= i
* 2 + 1;
8985 regpos
[nregs
].reg
= reg
;
8990 printf (_("pop frame {"));
8993 printf (_("*corrupt* - no registers specified"));
8998 for (i
= i
* 2; i
> 0; i
--)
9000 if (regpos
[reg
].offset
== i
- 1)
9002 name
= tic6x_unwind_regnames
[regpos
[reg
].reg
];
9009 fputs (name
, stdout
);
9017 else if (op
== 0xd0)
9018 printf (" MOV FP, SP");
9019 else if (op
== 0xd1)
9020 printf (" __c6xabi_pop_rts");
9021 else if (op
== 0xd2)
9023 unsigned char buf
[9];
9024 unsigned int i
, len
;
9025 unsigned long offset
;
9027 for (i
= 0; i
< sizeof (buf
); i
++)
9030 if ((buf
[i
] & 0x80) == 0)
9033 /* PR 17531: file: id:000001,src:001906+004739,op:splice,rep:2. */
9034 if (i
== sizeof (buf
))
9036 warn (_("Corrupt stack pointer adjustment detected\n"));
9040 offset
= read_uleb128 (buf
, &len
, buf
+ i
+ 1);
9041 assert (len
== i
+ 1);
9042 offset
= offset
* 8 + 0x408;
9043 printf (_("sp = sp + %ld"), offset
);
9045 else if ((op
& 0xf0) == 0xe0)
9047 if ((op
& 0x0f) == 7)
9050 printf (" MV %s, B3", tic6x_unwind_regnames
[op
& 0x0f]);
9054 printf (_(" [unsupported opcode]"));
9063 arm_expand_prel31 (Filedata
* filedata
, bfd_vma word
, bfd_vma where
)
9067 offset
= word
& 0x7fffffff;
9068 if (offset
& 0x40000000)
9069 offset
|= ~ (bfd_vma
) 0x7fffffff;
9071 if (filedata
->file_header
.e_machine
== EM_TI_C6000
)
9074 return offset
+ where
;
9078 decode_arm_unwind (Filedata
* filedata
,
9079 struct arm_unw_aux_info
* aux
,
9081 unsigned int remaining
,
9082 bfd_vma data_offset
,
9083 Elf_Internal_Shdr
* data_sec
,
9084 struct arm_section
* data_arm_sec
)
9087 unsigned int more_words
= 0;
9088 struct absaddr addr
;
9089 bfd_vma sym_name
= (bfd_vma
) -1;
9090 bfd_boolean res
= TRUE
;
9094 /* Fetch the first word.
9095 Note - when decoding an object file the address extracted
9096 here will always be 0. So we also pass in the sym_name
9097 parameter so that we can find the symbol associated with
9098 the personality routine. */
9099 if (! get_unwind_section_word (filedata
, aux
, data_arm_sec
, data_sec
, data_offset
,
9100 & word
, & addr
, & sym_name
))
9107 addr
.section
= SHN_UNDEF
;
9111 if ((word
& 0x80000000) == 0)
9113 /* Expand prel31 for personality routine. */
9115 const char *procname
;
9117 fn
= arm_expand_prel31 (filedata
, word
, data_sec
->sh_addr
+ data_offset
);
9118 printf (_(" Personality routine: "));
9120 && addr
.section
== SHN_UNDEF
&& addr
.offset
== 0
9121 && sym_name
!= (bfd_vma
) -1 && sym_name
< aux
->strtab_size
)
9123 procname
= aux
->strtab
+ sym_name
;
9124 print_vma (fn
, PREFIX_HEX
);
9127 fputs (" <", stdout
);
9128 fputs (procname
, stdout
);
9129 fputc ('>', stdout
);
9133 procname
= arm_print_vma_and_name (filedata
, aux
, fn
, addr
);
9134 fputc ('\n', stdout
);
9136 /* The GCC personality routines use the standard compact
9137 encoding, starting with one byte giving the number of
9139 if (procname
!= NULL
9140 && (const_strneq (procname
, "__gcc_personality_v0")
9141 || const_strneq (procname
, "__gxx_personality_v0")
9142 || const_strneq (procname
, "__gcj_personality_v0")
9143 || const_strneq (procname
, "__gnu_objc_personality_v0")))
9150 printf (_(" [Truncated data]\n"));
9153 more_words
= word
>> 24;
9163 /* ARM EHABI Section 6.3:
9165 An exception-handling table entry for the compact model looks like:
9169 1 0 index Data for personalityRoutine[index] */
9171 if (filedata
->file_header
.e_machine
== EM_ARM
9172 && (word
& 0x70000000))
9174 warn (_("Corrupt ARM compact model table entry: %x \n"), word
);
9178 per_index
= (word
>> 24) & 0x7f;
9179 printf (_(" Compact model index: %d\n"), per_index
);
9186 else if (per_index
< 3)
9188 more_words
= (word
>> 16) & 0xff;
9194 switch (filedata
->file_header
.e_machine
)
9199 if (! decode_arm_unwind_bytecode (filedata
, aux
, word
, remaining
, more_words
,
9200 data_offset
, data_sec
, data_arm_sec
))
9205 warn (_("Unknown ARM compact model index encountered\n"));
9206 printf (_(" [reserved]\n"));
9214 if (! decode_tic6x_unwind_bytecode (filedata
, aux
, word
, remaining
, more_words
,
9215 data_offset
, data_sec
, data_arm_sec
))
9218 else if (per_index
< 5)
9220 if (((word
>> 17) & 0x7f) == 0x7f)
9221 printf (_(" Restore stack from frame pointer\n"));
9223 printf (_(" Stack increment %d\n"), (word
>> 14) & 0x1fc);
9224 printf (_(" Registers restored: "));
9226 printf (" (compact) ");
9227 decode_tic6x_unwind_regmask ((word
>> 4) & 0x1fff);
9229 printf (_(" Return register: %s\n"),
9230 tic6x_unwind_regnames
[word
& 0xf]);
9233 printf (_(" [reserved (%d)]\n"), per_index
);
9237 error (_("Unsupported architecture type %d encountered when decoding unwind table\n"),
9238 filedata
->file_header
.e_machine
);
9242 /* Decode the descriptors. Not implemented. */
9248 dump_arm_unwind (Filedata
* filedata
,
9249 struct arm_unw_aux_info
* aux
,
9250 Elf_Internal_Shdr
* exidx_sec
)
9252 struct arm_section exidx_arm_sec
, extab_arm_sec
;
9253 unsigned int i
, exidx_len
;
9254 unsigned long j
, nfuns
;
9255 bfd_boolean res
= TRUE
;
9257 memset (&exidx_arm_sec
, 0, sizeof (exidx_arm_sec
));
9258 memset (&extab_arm_sec
, 0, sizeof (extab_arm_sec
));
9259 exidx_len
= exidx_sec
->sh_size
/ 8;
9261 aux
->funtab
= xmalloc (aux
->nsyms
* sizeof (Elf_Internal_Sym
));
9262 for (nfuns
= 0, j
= 0; j
< aux
->nsyms
; j
++)
9263 if (aux
->symtab
[j
].st_value
&& ELF_ST_TYPE (aux
->symtab
[j
].st_info
) == STT_FUNC
)
9264 aux
->funtab
[nfuns
++] = aux
->symtab
[j
];
9266 qsort (aux
->funtab
, aux
->nfuns
, sizeof (Elf_Internal_Sym
), symcmp
);
9268 for (i
= 0; i
< exidx_len
; i
++)
9270 unsigned int exidx_fn
, exidx_entry
;
9271 struct absaddr fn_addr
, entry_addr
;
9274 fputc ('\n', stdout
);
9276 if (! get_unwind_section_word (filedata
, aux
, & exidx_arm_sec
, exidx_sec
,
9277 8 * i
, & exidx_fn
, & fn_addr
, NULL
)
9278 || ! get_unwind_section_word (filedata
, aux
, & exidx_arm_sec
, exidx_sec
,
9279 8 * i
+ 4, & exidx_entry
, & entry_addr
, NULL
))
9282 arm_free_section (& exidx_arm_sec
);
9283 arm_free_section (& extab_arm_sec
);
9287 /* ARM EHABI, Section 5:
9288 An index table entry consists of 2 words.
9289 The first word contains a prel31 offset to the start of a function, with bit 31 clear. */
9290 if (exidx_fn
& 0x80000000)
9292 warn (_("corrupt index table entry: %x\n"), exidx_fn
);
9296 fn
= arm_expand_prel31 (filedata
, exidx_fn
, exidx_sec
->sh_addr
+ 8 * i
);
9298 arm_print_vma_and_name (filedata
, aux
, fn
, fn_addr
);
9299 fputs (": ", stdout
);
9301 if (exidx_entry
== 1)
9303 print_vma (exidx_entry
, PREFIX_HEX
);
9304 fputs (" [cantunwind]\n", stdout
);
9306 else if (exidx_entry
& 0x80000000)
9308 print_vma (exidx_entry
, PREFIX_HEX
);
9309 fputc ('\n', stdout
);
9310 decode_arm_unwind (filedata
, aux
, exidx_entry
, 4, 0, NULL
, NULL
);
9314 bfd_vma table
, table_offset
= 0;
9315 Elf_Internal_Shdr
*table_sec
;
9317 fputs ("@", stdout
);
9318 table
= arm_expand_prel31 (filedata
, exidx_entry
, exidx_sec
->sh_addr
+ 8 * i
+ 4);
9319 print_vma (table
, PREFIX_HEX
);
9322 /* Locate the matching .ARM.extab. */
9323 if (entry_addr
.section
!= SHN_UNDEF
9324 && entry_addr
.section
< filedata
->file_header
.e_shnum
)
9326 table_sec
= filedata
->section_headers
+ entry_addr
.section
;
9327 table_offset
= entry_addr
.offset
;
9329 if (table_offset
> table_sec
->sh_size
9330 || ((bfd_signed_vma
) table_offset
) < 0)
9332 warn (_("Unwind entry contains corrupt offset (0x%lx) into section %s\n"),
9333 (unsigned long) table_offset
,
9334 printable_section_name (filedata
, table_sec
));
9341 table_sec
= find_section_by_address (filedata
, table
);
9342 if (table_sec
!= NULL
)
9343 table_offset
= table
- table_sec
->sh_addr
;
9346 if (table_sec
== NULL
)
9348 warn (_("Could not locate .ARM.extab section containing 0x%lx.\n"),
9349 (unsigned long) table
);
9354 if (! decode_arm_unwind (filedata
, aux
, 0, 0, table_offset
, table_sec
,
9363 arm_free_section (&exidx_arm_sec
);
9364 arm_free_section (&extab_arm_sec
);
9369 /* Used for both ARM and C6X unwinding tables. */
9372 arm_process_unwind (Filedata
* filedata
)
9374 struct arm_unw_aux_info aux
;
9375 Elf_Internal_Shdr
*unwsec
= NULL
;
9376 Elf_Internal_Shdr
*strsec
;
9377 Elf_Internal_Shdr
*sec
;
9379 unsigned int sec_type
;
9380 bfd_boolean res
= TRUE
;
9382 switch (filedata
->file_header
.e_machine
)
9385 sec_type
= SHT_ARM_EXIDX
;
9389 sec_type
= SHT_C6000_UNWIND
;
9393 error (_("Unsupported architecture type %d encountered when processing unwind table\n"),
9394 filedata
->file_header
.e_machine
);
9398 if (filedata
->string_table
== NULL
)
9401 memset (& aux
, 0, sizeof (aux
));
9402 aux
.filedata
= filedata
;
9404 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
9406 if (sec
->sh_type
== SHT_SYMTAB
&& sec
->sh_link
< filedata
->file_header
.e_shnum
)
9408 aux
.symtab
= GET_ELF_SYMBOLS (filedata
, sec
, & aux
.nsyms
);
9410 strsec
= filedata
->section_headers
+ sec
->sh_link
;
9412 /* PR binutils/17531 file: 011-12666-0.004. */
9413 if (aux
.strtab
!= NULL
)
9415 error (_("Multiple string tables found in file.\n"));
9419 aux
.strtab
= get_data (NULL
, filedata
, strsec
->sh_offset
,
9420 1, strsec
->sh_size
, _("string table"));
9421 aux
.strtab_size
= aux
.strtab
!= NULL
? strsec
->sh_size
: 0;
9423 else if (sec
->sh_type
== sec_type
)
9428 printf (_("\nThere are no unwind sections in this file.\n"));
9430 for (i
= 0, sec
= filedata
->section_headers
; i
< filedata
->file_header
.e_shnum
; ++i
, ++sec
)
9432 if (sec
->sh_type
== sec_type
)
9434 unsigned long num_unwind
= sec
->sh_size
/ (2 * eh_addr_size
);
9435 printf (ngettext ("\nUnwind section '%s' at offset 0x%lx "
9436 "contains %lu entry:\n",
9437 "\nUnwind section '%s' at offset 0x%lx "
9438 "contains %lu entries:\n",
9440 printable_section_name (filedata
, sec
),
9441 (unsigned long) sec
->sh_offset
,
9444 if (! dump_arm_unwind (filedata
, &aux
, sec
))
9452 free ((char *) aux
.strtab
);
9458 process_unwind (Filedata
* filedata
)
9460 struct unwind_handler
9462 unsigned int machtype
;
9463 bfd_boolean (* handler
)(Filedata
*);
9466 { EM_ARM
, arm_process_unwind
},
9467 { EM_IA_64
, ia64_process_unwind
},
9468 { EM_PARISC
, hppa_process_unwind
},
9469 { EM_TI_C6000
, arm_process_unwind
},
9477 for (i
= 0; handlers
[i
].handler
!= NULL
; i
++)
9478 if (filedata
->file_header
.e_machine
== handlers
[i
].machtype
)
9479 return handlers
[i
].handler (filedata
);
9481 printf (_("\nThe decoding of unwind sections for machine type %s is not currently supported.\n"),
9482 get_machine_name (filedata
->file_header
.e_machine
));
9487 dynamic_section_aarch64_val (Elf_Internal_Dyn
* entry
)
9489 switch (entry
->d_tag
)
9491 case DT_AARCH64_BTI_PLT
:
9492 case DT_AARCH64_PAC_PLT
:
9495 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
9502 dynamic_section_mips_val (Elf_Internal_Dyn
* entry
)
9504 switch (entry
->d_tag
)
9507 if (entry
->d_un
.d_val
== 0)
9511 static const char * opts
[] =
9513 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
9514 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
9515 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
9516 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
9520 bfd_boolean first
= TRUE
;
9522 for (cnt
= 0; cnt
< ARRAY_SIZE (opts
); ++cnt
)
9523 if (entry
->d_un
.d_val
& (1 << cnt
))
9525 printf ("%s%s", first
? "" : " ", opts
[cnt
]);
9531 case DT_MIPS_IVERSION
:
9532 if (VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
9533 printf (_("Interface Version: %s"), GET_DYNAMIC_NAME (entry
->d_un
.d_val
));
9537 sprintf_vma (buf
, entry
->d_un
.d_ptr
);
9538 /* Note: coded this way so that there is a single string for translation. */
9539 printf (_("<corrupt: %s>"), buf
);
9543 case DT_MIPS_TIME_STAMP
:
9547 time_t atime
= entry
->d_un
.d_val
;
9549 tmp
= gmtime (&atime
);
9550 /* PR 17531: file: 6accc532. */
9552 snprintf (timebuf
, sizeof (timebuf
), _("<corrupt>"));
9554 snprintf (timebuf
, sizeof (timebuf
), "%04u-%02u-%02uT%02u:%02u:%02u",
9555 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
9556 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
9557 printf (_("Time Stamp: %s"), timebuf
);
9561 case DT_MIPS_RLD_VERSION
:
9562 case DT_MIPS_LOCAL_GOTNO
:
9563 case DT_MIPS_CONFLICTNO
:
9564 case DT_MIPS_LIBLISTNO
:
9565 case DT_MIPS_SYMTABNO
:
9566 case DT_MIPS_UNREFEXTNO
:
9567 case DT_MIPS_HIPAGENO
:
9568 case DT_MIPS_DELTA_CLASS_NO
:
9569 case DT_MIPS_DELTA_INSTANCE_NO
:
9570 case DT_MIPS_DELTA_RELOC_NO
:
9571 case DT_MIPS_DELTA_SYM_NO
:
9572 case DT_MIPS_DELTA_CLASSSYM_NO
:
9573 case DT_MIPS_COMPACT_SIZE
:
9574 print_vma (entry
->d_un
.d_val
, DEC
);
9578 dynamic_info_DT_MIPS_XHASH
= entry
->d_un
.d_val
;
9579 dynamic_info_DT_GNU_HASH
= entry
->d_un
.d_val
;
9580 /* Falls through. */
9583 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
9589 dynamic_section_parisc_val (Elf_Internal_Dyn
* entry
)
9591 switch (entry
->d_tag
)
9593 case DT_HP_DLD_FLAGS
:
9602 { DT_HP_DEBUG_PRIVATE
, "HP_DEBUG_PRIVATE" },
9603 { DT_HP_DEBUG_CALLBACK
, "HP_DEBUG_CALLBACK" },
9604 { DT_HP_DEBUG_CALLBACK_BOR
, "HP_DEBUG_CALLBACK_BOR" },
9605 { DT_HP_NO_ENVVAR
, "HP_NO_ENVVAR" },
9606 { DT_HP_BIND_NOW
, "HP_BIND_NOW" },
9607 { DT_HP_BIND_NONFATAL
, "HP_BIND_NONFATAL" },
9608 { DT_HP_BIND_VERBOSE
, "HP_BIND_VERBOSE" },
9609 { DT_HP_BIND_RESTRICTED
, "HP_BIND_RESTRICTED" },
9610 { DT_HP_BIND_SYMBOLIC
, "HP_BIND_SYMBOLIC" },
9611 { DT_HP_RPATH_FIRST
, "HP_RPATH_FIRST" },
9612 { DT_HP_BIND_DEPTH_FIRST
, "HP_BIND_DEPTH_FIRST" },
9613 { DT_HP_GST
, "HP_GST" },
9614 { DT_HP_SHLIB_FIXED
, "HP_SHLIB_FIXED" },
9615 { DT_HP_MERGE_SHLIB_SEG
, "HP_MERGE_SHLIB_SEG" },
9616 { DT_HP_NODELETE
, "HP_NODELETE" },
9617 { DT_HP_GROUP
, "HP_GROUP" },
9618 { DT_HP_PROTECT_LINKAGE_TABLE
, "HP_PROTECT_LINKAGE_TABLE" }
9620 bfd_boolean first
= TRUE
;
9622 bfd_vma val
= entry
->d_un
.d_val
;
9624 for (cnt
= 0; cnt
< ARRAY_SIZE (flags
); ++cnt
)
9625 if (val
& flags
[cnt
].bit
)
9629 fputs (flags
[cnt
].str
, stdout
);
9631 val
^= flags
[cnt
].bit
;
9634 if (val
!= 0 || first
)
9638 print_vma (val
, HEX
);
9644 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
9652 /* VMS vs Unix time offset and factor. */
9654 #define VMS_EPOCH_OFFSET 35067168000000000LL
9655 #define VMS_GRANULARITY_FACTOR 10000000
9657 /* Display a VMS time in a human readable format. */
9660 print_vms_time (bfd_int64_t vmstime
)
9665 unxtime
= (vmstime
- VMS_EPOCH_OFFSET
) / VMS_GRANULARITY_FACTOR
;
9666 tm
= gmtime (&unxtime
);
9667 printf ("%04u-%02u-%02uT%02u:%02u:%02u",
9668 tm
->tm_year
+ 1900, tm
->tm_mon
+ 1, tm
->tm_mday
,
9669 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
);
9674 dynamic_section_ia64_val (Elf_Internal_Dyn
* entry
)
9676 switch (entry
->d_tag
)
9678 case DT_IA_64_PLT_RESERVE
:
9679 /* First 3 slots reserved. */
9680 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
9682 print_vma (entry
->d_un
.d_ptr
+ (3 * 8), PREFIX_HEX
);
9685 case DT_IA_64_VMS_LINKTIME
:
9687 print_vms_time (entry
->d_un
.d_val
);
9691 case DT_IA_64_VMS_LNKFLAGS
:
9692 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
9693 if (entry
->d_un
.d_val
& VMS_LF_CALL_DEBUG
)
9694 printf (" CALL_DEBUG");
9695 if (entry
->d_un
.d_val
& VMS_LF_NOP0BUFS
)
9696 printf (" NOP0BUFS");
9697 if (entry
->d_un
.d_val
& VMS_LF_P0IMAGE
)
9698 printf (" P0IMAGE");
9699 if (entry
->d_un
.d_val
& VMS_LF_MKTHREADS
)
9700 printf (" MKTHREADS");
9701 if (entry
->d_un
.d_val
& VMS_LF_UPCALLS
)
9702 printf (" UPCALLS");
9703 if (entry
->d_un
.d_val
& VMS_LF_IMGSTA
)
9705 if (entry
->d_un
.d_val
& VMS_LF_INITIALIZE
)
9706 printf (" INITIALIZE");
9707 if (entry
->d_un
.d_val
& VMS_LF_MAIN
)
9709 if (entry
->d_un
.d_val
& VMS_LF_EXE_INIT
)
9710 printf (" EXE_INIT");
9711 if (entry
->d_un
.d_val
& VMS_LF_TBK_IN_IMG
)
9712 printf (" TBK_IN_IMG");
9713 if (entry
->d_un
.d_val
& VMS_LF_DBG_IN_IMG
)
9714 printf (" DBG_IN_IMG");
9715 if (entry
->d_un
.d_val
& VMS_LF_TBK_IN_DSF
)
9716 printf (" TBK_IN_DSF");
9717 if (entry
->d_un
.d_val
& VMS_LF_DBG_IN_DSF
)
9718 printf (" DBG_IN_DSF");
9719 if (entry
->d_un
.d_val
& VMS_LF_SIGNATURES
)
9720 printf (" SIGNATURES");
9721 if (entry
->d_un
.d_val
& VMS_LF_REL_SEG_OFF
)
9722 printf (" REL_SEG_OFF");
9726 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
9733 get_32bit_dynamic_section (Filedata
* filedata
)
9735 Elf32_External_Dyn
* edyn
;
9736 Elf32_External_Dyn
* ext
;
9737 Elf_Internal_Dyn
* entry
;
9739 edyn
= (Elf32_External_Dyn
*) get_data (NULL
, filedata
, dynamic_addr
, 1,
9740 dynamic_size
, _("dynamic section"));
9744 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
9745 might not have the luxury of section headers. Look for the DT_NULL
9746 terminator to determine the number of entries. */
9747 for (ext
= edyn
, dynamic_nent
= 0;
9748 (char *) (ext
+ 1) <= (char *) edyn
+ dynamic_size
;
9752 if (BYTE_GET (ext
->d_tag
) == DT_NULL
)
9756 dynamic_section
= (Elf_Internal_Dyn
*) cmalloc (dynamic_nent
,
9758 if (dynamic_section
== NULL
)
9760 error (_("Out of memory allocating space for %lu dynamic entries\n"),
9761 (unsigned long) dynamic_nent
);
9766 for (ext
= edyn
, entry
= dynamic_section
;
9767 entry
< dynamic_section
+ dynamic_nent
;
9770 entry
->d_tag
= BYTE_GET (ext
->d_tag
);
9771 entry
->d_un
.d_val
= BYTE_GET (ext
->d_un
.d_val
);
9780 get_64bit_dynamic_section (Filedata
* filedata
)
9782 Elf64_External_Dyn
* edyn
;
9783 Elf64_External_Dyn
* ext
;
9784 Elf_Internal_Dyn
* entry
;
9786 /* Read in the data. */
9787 edyn
= (Elf64_External_Dyn
*) get_data (NULL
, filedata
, dynamic_addr
, 1,
9788 dynamic_size
, _("dynamic section"));
9792 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
9793 might not have the luxury of section headers. Look for the DT_NULL
9794 terminator to determine the number of entries. */
9795 for (ext
= edyn
, dynamic_nent
= 0;
9796 /* PR 17533 file: 033-67080-0.004 - do not read past end of buffer. */
9797 (char *) (ext
+ 1) <= (char *) edyn
+ dynamic_size
;
9801 if (BYTE_GET (ext
->d_tag
) == DT_NULL
)
9805 dynamic_section
= (Elf_Internal_Dyn
*) cmalloc (dynamic_nent
,
9807 if (dynamic_section
== NULL
)
9809 error (_("Out of memory allocating space for %lu dynamic entries\n"),
9810 (unsigned long) dynamic_nent
);
9815 /* Convert from external to internal formats. */
9816 for (ext
= edyn
, entry
= dynamic_section
;
9817 entry
< dynamic_section
+ dynamic_nent
;
9820 entry
->d_tag
= BYTE_GET (ext
->d_tag
);
9821 entry
->d_un
.d_val
= BYTE_GET (ext
->d_un
.d_val
);
9830 print_dynamic_flags (bfd_vma flags
)
9832 bfd_boolean first
= TRUE
;
9838 flag
= flags
& - flags
;
9848 case DF_ORIGIN
: fputs ("ORIGIN", stdout
); break;
9849 case DF_SYMBOLIC
: fputs ("SYMBOLIC", stdout
); break;
9850 case DF_TEXTREL
: fputs ("TEXTREL", stdout
); break;
9851 case DF_BIND_NOW
: fputs ("BIND_NOW", stdout
); break;
9852 case DF_STATIC_TLS
: fputs ("STATIC_TLS", stdout
); break;
9853 default: fputs (_("unknown"), stdout
); break;
9859 /* Parse and display the contents of the dynamic section. */
9862 process_dynamic_section (Filedata
* filedata
)
9864 Elf_Internal_Dyn
* entry
;
9866 if (dynamic_size
== 0)
9869 printf (_("\nThere is no dynamic section in this file.\n"));
9876 if (! get_32bit_dynamic_section (filedata
))
9881 if (! get_64bit_dynamic_section (filedata
))
9885 /* Find the appropriate symbol table. */
9886 if (dynamic_symbols
== NULL
)
9888 for (entry
= dynamic_section
;
9889 entry
< dynamic_section
+ dynamic_nent
;
9892 Elf_Internal_Shdr section
;
9894 if (entry
->d_tag
!= DT_SYMTAB
)
9897 dynamic_info
[DT_SYMTAB
] = entry
->d_un
.d_val
;
9899 /* Since we do not know how big the symbol table is,
9900 we default to reading in the entire file (!) and
9901 processing that. This is overkill, I know, but it
9903 section
.sh_offset
= offset_from_vma (filedata
, entry
->d_un
.d_val
, 0);
9904 if ((bfd_size_type
) section
.sh_offset
> filedata
->file_size
)
9906 /* See PR 21379 for a reproducer. */
9907 error (_("Invalid DT_SYMTAB entry: %lx"), (long) section
.sh_offset
);
9911 if (archive_file_offset
!= 0)
9912 section
.sh_size
= archive_file_size
- section
.sh_offset
;
9914 section
.sh_size
= filedata
->file_size
- section
.sh_offset
;
9917 section
.sh_entsize
= sizeof (Elf32_External_Sym
);
9919 section
.sh_entsize
= sizeof (Elf64_External_Sym
);
9920 section
.sh_name
= filedata
->string_table_length
;
9922 if (dynamic_symbols
!= NULL
)
9924 error (_("Multiple dynamic symbol table sections found\n"));
9925 free (dynamic_symbols
);
9927 dynamic_symbols
= GET_ELF_SYMBOLS (filedata
, §ion
, & num_dynamic_syms
);
9928 if (num_dynamic_syms
< 1)
9930 error (_("Unable to determine the number of symbols to load\n"));
9936 /* Similarly find a string table. */
9937 if (dynamic_strings
== NULL
)
9939 for (entry
= dynamic_section
;
9940 entry
< dynamic_section
+ dynamic_nent
;
9943 unsigned long offset
;
9946 if (entry
->d_tag
!= DT_STRTAB
)
9949 dynamic_info
[DT_STRTAB
] = entry
->d_un
.d_val
;
9951 /* Since we do not know how big the string table is,
9952 we default to reading in the entire file (!) and
9953 processing that. This is overkill, I know, but it
9956 offset
= offset_from_vma (filedata
, entry
->d_un
.d_val
, 0);
9958 if (archive_file_offset
!= 0)
9959 str_tab_len
= archive_file_size
- offset
;
9961 str_tab_len
= filedata
->file_size
- offset
;
9963 if (str_tab_len
< 1)
9966 (_("Unable to determine the length of the dynamic string table\n"));
9970 if (dynamic_strings
!= NULL
)
9972 error (_("Multiple dynamic string tables found\n"));
9973 free (dynamic_strings
);
9976 dynamic_strings
= (char *) get_data (NULL
, filedata
, offset
, 1,
9978 _("dynamic string table"));
9979 dynamic_strings_length
= dynamic_strings
== NULL
? 0 : str_tab_len
;
9983 /* And find the syminfo section if available. */
9984 if (dynamic_syminfo
== NULL
)
9986 unsigned long syminsz
= 0;
9988 for (entry
= dynamic_section
;
9989 entry
< dynamic_section
+ dynamic_nent
;
9992 if (entry
->d_tag
== DT_SYMINENT
)
9994 /* Note: these braces are necessary to avoid a syntax
9995 error from the SunOS4 C compiler. */
9996 /* PR binutils/17531: A corrupt file can trigger this test.
9997 So do not use an assert, instead generate an error message. */
9998 if (sizeof (Elf_External_Syminfo
) != entry
->d_un
.d_val
)
9999 error (_("Bad value (%d) for SYMINENT entry\n"),
10000 (int) entry
->d_un
.d_val
);
10002 else if (entry
->d_tag
== DT_SYMINSZ
)
10003 syminsz
= entry
->d_un
.d_val
;
10004 else if (entry
->d_tag
== DT_SYMINFO
)
10005 dynamic_syminfo_offset
= offset_from_vma (filedata
, entry
->d_un
.d_val
,
10009 if (dynamic_syminfo_offset
!= 0 && syminsz
!= 0)
10011 Elf_External_Syminfo
* extsyminfo
;
10012 Elf_External_Syminfo
* extsym
;
10013 Elf_Internal_Syminfo
* syminfo
;
10015 /* There is a syminfo section. Read the data. */
10016 extsyminfo
= (Elf_External_Syminfo
*)
10017 get_data (NULL
, filedata
, dynamic_syminfo_offset
, 1, syminsz
,
10018 _("symbol information"));
10022 if (dynamic_syminfo
!= NULL
)
10024 error (_("Multiple dynamic symbol information sections found\n"));
10025 free (dynamic_syminfo
);
10027 dynamic_syminfo
= (Elf_Internal_Syminfo
*) malloc (syminsz
);
10028 if (dynamic_syminfo
== NULL
)
10030 error (_("Out of memory allocating %lu byte for dynamic symbol info\n"),
10031 (unsigned long) syminsz
);
10035 dynamic_syminfo_nent
= syminsz
/ sizeof (Elf_External_Syminfo
);
10036 for (syminfo
= dynamic_syminfo
, extsym
= extsyminfo
;
10037 syminfo
< dynamic_syminfo
+ dynamic_syminfo_nent
;
10038 ++syminfo
, ++extsym
)
10040 syminfo
->si_boundto
= BYTE_GET (extsym
->si_boundto
);
10041 syminfo
->si_flags
= BYTE_GET (extsym
->si_flags
);
10048 if (do_dynamic
&& dynamic_addr
)
10049 printf (ngettext ("\nDynamic section at offset 0x%lx "
10050 "contains %lu entry:\n",
10051 "\nDynamic section at offset 0x%lx "
10052 "contains %lu entries:\n",
10054 dynamic_addr
, (unsigned long) dynamic_nent
);
10056 printf (_(" Tag Type Name/Value\n"));
10058 for (entry
= dynamic_section
;
10059 entry
< dynamic_section
+ dynamic_nent
;
10064 const char * dtype
;
10067 print_vma (entry
->d_tag
, FULL_HEX
);
10068 dtype
= get_dynamic_type (filedata
, entry
->d_tag
);
10069 printf (" (%s)%*s", dtype
,
10070 ((is_32bit_elf
? 27 : 19) - (int) strlen (dtype
)), " ");
10073 switch (entry
->d_tag
)
10077 print_dynamic_flags (entry
->d_un
.d_val
);
10087 switch (entry
->d_tag
)
10090 printf (_("Auxiliary library"));
10094 printf (_("Filter library"));
10098 printf (_("Configuration file"));
10102 printf (_("Dependency audit library"));
10106 printf (_("Audit library"));
10110 if (VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
10111 printf (": [%s]\n", GET_DYNAMIC_NAME (entry
->d_un
.d_val
));
10115 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
10124 printf (_("Flags:"));
10126 if (entry
->d_un
.d_val
== 0)
10127 printf (_(" None\n"));
10130 unsigned long int val
= entry
->d_un
.d_val
;
10132 if (val
& DTF_1_PARINIT
)
10134 printf (" PARINIT");
10135 val
^= DTF_1_PARINIT
;
10137 if (val
& DTF_1_CONFEXP
)
10139 printf (" CONFEXP");
10140 val
^= DTF_1_CONFEXP
;
10143 printf (" %lx", val
);
10152 printf (_("Flags:"));
10154 if (entry
->d_un
.d_val
== 0)
10155 printf (_(" None\n"));
10158 unsigned long int val
= entry
->d_un
.d_val
;
10160 if (val
& DF_P1_LAZYLOAD
)
10162 printf (" LAZYLOAD");
10163 val
^= DF_P1_LAZYLOAD
;
10165 if (val
& DF_P1_GROUPPERM
)
10167 printf (" GROUPPERM");
10168 val
^= DF_P1_GROUPPERM
;
10171 printf (" %lx", val
);
10180 printf (_("Flags:"));
10181 if (entry
->d_un
.d_val
== 0)
10182 printf (_(" None\n"));
10185 unsigned long int val
= entry
->d_un
.d_val
;
10187 if (val
& DF_1_NOW
)
10192 if (val
& DF_1_GLOBAL
)
10194 printf (" GLOBAL");
10195 val
^= DF_1_GLOBAL
;
10197 if (val
& DF_1_GROUP
)
10202 if (val
& DF_1_NODELETE
)
10204 printf (" NODELETE");
10205 val
^= DF_1_NODELETE
;
10207 if (val
& DF_1_LOADFLTR
)
10209 printf (" LOADFLTR");
10210 val
^= DF_1_LOADFLTR
;
10212 if (val
& DF_1_INITFIRST
)
10214 printf (" INITFIRST");
10215 val
^= DF_1_INITFIRST
;
10217 if (val
& DF_1_NOOPEN
)
10219 printf (" NOOPEN");
10220 val
^= DF_1_NOOPEN
;
10222 if (val
& DF_1_ORIGIN
)
10224 printf (" ORIGIN");
10225 val
^= DF_1_ORIGIN
;
10227 if (val
& DF_1_DIRECT
)
10229 printf (" DIRECT");
10230 val
^= DF_1_DIRECT
;
10232 if (val
& DF_1_TRANS
)
10237 if (val
& DF_1_INTERPOSE
)
10239 printf (" INTERPOSE");
10240 val
^= DF_1_INTERPOSE
;
10242 if (val
& DF_1_NODEFLIB
)
10244 printf (" NODEFLIB");
10245 val
^= DF_1_NODEFLIB
;
10247 if (val
& DF_1_NODUMP
)
10249 printf (" NODUMP");
10250 val
^= DF_1_NODUMP
;
10252 if (val
& DF_1_CONFALT
)
10254 printf (" CONFALT");
10255 val
^= DF_1_CONFALT
;
10257 if (val
& DF_1_ENDFILTEE
)
10259 printf (" ENDFILTEE");
10260 val
^= DF_1_ENDFILTEE
;
10262 if (val
& DF_1_DISPRELDNE
)
10264 printf (" DISPRELDNE");
10265 val
^= DF_1_DISPRELDNE
;
10267 if (val
& DF_1_DISPRELPND
)
10269 printf (" DISPRELPND");
10270 val
^= DF_1_DISPRELPND
;
10272 if (val
& DF_1_NODIRECT
)
10274 printf (" NODIRECT");
10275 val
^= DF_1_NODIRECT
;
10277 if (val
& DF_1_IGNMULDEF
)
10279 printf (" IGNMULDEF");
10280 val
^= DF_1_IGNMULDEF
;
10282 if (val
& DF_1_NOKSYMS
)
10284 printf (" NOKSYMS");
10285 val
^= DF_1_NOKSYMS
;
10287 if (val
& DF_1_NOHDR
)
10292 if (val
& DF_1_EDITED
)
10294 printf (" EDITED");
10295 val
^= DF_1_EDITED
;
10297 if (val
& DF_1_NORELOC
)
10299 printf (" NORELOC");
10300 val
^= DF_1_NORELOC
;
10302 if (val
& DF_1_SYMINTPOSE
)
10304 printf (" SYMINTPOSE");
10305 val
^= DF_1_SYMINTPOSE
;
10307 if (val
& DF_1_GLOBAUDIT
)
10309 printf (" GLOBAUDIT");
10310 val
^= DF_1_GLOBAUDIT
;
10312 if (val
& DF_1_SINGLETON
)
10314 printf (" SINGLETON");
10315 val
^= DF_1_SINGLETON
;
10317 if (val
& DF_1_STUB
)
10322 if (val
& DF_1_PIE
)
10327 if (val
& DF_1_KMOD
)
10332 if (val
& DF_1_WEAKFILTER
)
10334 printf (" WEAKFILTER");
10335 val
^= DF_1_WEAKFILTER
;
10337 if (val
& DF_1_NOCOMMON
)
10339 printf (" NOCOMMON");
10340 val
^= DF_1_NOCOMMON
;
10343 printf (" %lx", val
);
10350 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
10352 puts (get_dynamic_type (filedata
, entry
->d_un
.d_val
));
10372 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
10378 if (VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
10379 name
= GET_DYNAMIC_NAME (entry
->d_un
.d_val
);
10385 switch (entry
->d_tag
)
10388 printf (_("Shared library: [%s]"), name
);
10390 if (streq (name
, program_interpreter
))
10391 printf (_(" program interpreter"));
10395 printf (_("Library soname: [%s]"), name
);
10399 printf (_("Library rpath: [%s]"), name
);
10403 printf (_("Library runpath: [%s]"), name
);
10407 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
10412 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
10425 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
10426 /* Fall through. */
10430 case DT_INIT_ARRAYSZ
:
10431 case DT_FINI_ARRAYSZ
:
10432 case DT_GNU_CONFLICTSZ
:
10433 case DT_GNU_LIBLISTSZ
:
10436 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
10437 printf (_(" (bytes)\n"));
10442 case DT_VERNEEDNUM
:
10447 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
10456 case DT_INIT_ARRAY
:
10457 case DT_FINI_ARRAY
:
10460 if (entry
->d_tag
== DT_USED
10461 && VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
10463 char * name
= GET_DYNAMIC_NAME (entry
->d_un
.d_val
);
10467 printf (_("Not needed object: [%s]\n"), name
);
10472 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
10478 /* The value of this entry is ignored. */
10483 case DT_GNU_PRELINKED
:
10487 time_t atime
= entry
->d_un
.d_val
;
10489 tmp
= gmtime (&atime
);
10490 /* PR 17533 file: 041-1244816-0.004. */
10492 printf (_("<corrupt time val: %lx"),
10493 (unsigned long) atime
);
10495 printf ("%04u-%02u-%02uT%02u:%02u:%02u\n",
10496 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
10497 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
10503 dynamic_info_DT_GNU_HASH
= entry
->d_un
.d_val
;
10506 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
10512 if ((entry
->d_tag
>= DT_VERSYM
) && (entry
->d_tag
<= DT_VERNEEDNUM
))
10513 version_info
[DT_VERSIONTAGIDX (entry
->d_tag
)] =
10518 switch (filedata
->file_header
.e_machine
)
10521 dynamic_section_aarch64_val (entry
);
10524 case EM_MIPS_RS3_LE
:
10525 dynamic_section_mips_val (entry
);
10528 dynamic_section_parisc_val (entry
);
10531 dynamic_section_ia64_val (entry
);
10534 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
10546 get_ver_flags (unsigned int flags
)
10548 static char buff
[128];
10555 if (flags
& VER_FLG_BASE
)
10556 strcat (buff
, "BASE");
10558 if (flags
& VER_FLG_WEAK
)
10560 if (flags
& VER_FLG_BASE
)
10561 strcat (buff
, " | ");
10563 strcat (buff
, "WEAK");
10566 if (flags
& VER_FLG_INFO
)
10568 if (flags
& (VER_FLG_BASE
|VER_FLG_WEAK
))
10569 strcat (buff
, " | ");
10571 strcat (buff
, "INFO");
10574 if (flags
& ~(VER_FLG_BASE
| VER_FLG_WEAK
| VER_FLG_INFO
))
10576 if (flags
& (VER_FLG_BASE
| VER_FLG_WEAK
| VER_FLG_INFO
))
10577 strcat (buff
, " | ");
10579 strcat (buff
, _("<unknown>"));
10585 /* Display the contents of the version sections. */
10588 process_version_sections (Filedata
* filedata
)
10590 Elf_Internal_Shdr
* section
;
10592 bfd_boolean found
= FALSE
;
10597 for (i
= 0, section
= filedata
->section_headers
;
10598 i
< filedata
->file_header
.e_shnum
;
10601 switch (section
->sh_type
)
10603 case SHT_GNU_verdef
:
10605 Elf_External_Verdef
* edefs
;
10612 printf (ngettext ("\nVersion definition section '%s' "
10613 "contains %u entry:\n",
10614 "\nVersion definition section '%s' "
10615 "contains %u entries:\n",
10617 printable_section_name (filedata
, section
),
10620 printf (_(" Addr: 0x"));
10621 printf_vma (section
->sh_addr
);
10622 printf (_(" Offset: %#08lx Link: %u (%s)\n"),
10623 (unsigned long) section
->sh_offset
, section
->sh_link
,
10624 printable_section_name_from_index (filedata
, section
->sh_link
));
10626 edefs
= (Elf_External_Verdef
*)
10627 get_data (NULL
, filedata
, section
->sh_offset
, 1,section
->sh_size
,
10628 _("version definition section"));
10631 endbuf
= (char *) edefs
+ section
->sh_size
;
10633 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
10636 Elf_External_Verdef
* edef
;
10637 Elf_Internal_Verdef ent
;
10638 Elf_External_Verdaux
* eaux
;
10639 Elf_Internal_Verdaux aux
;
10640 unsigned long isum
;
10643 vstart
= ((char *) edefs
) + idx
;
10644 if (vstart
+ sizeof (*edef
) > endbuf
)
10647 edef
= (Elf_External_Verdef
*) vstart
;
10649 ent
.vd_version
= BYTE_GET (edef
->vd_version
);
10650 ent
.vd_flags
= BYTE_GET (edef
->vd_flags
);
10651 ent
.vd_ndx
= BYTE_GET (edef
->vd_ndx
);
10652 ent
.vd_cnt
= BYTE_GET (edef
->vd_cnt
);
10653 ent
.vd_hash
= BYTE_GET (edef
->vd_hash
);
10654 ent
.vd_aux
= BYTE_GET (edef
->vd_aux
);
10655 ent
.vd_next
= BYTE_GET (edef
->vd_next
);
10657 printf (_(" %#06lx: Rev: %d Flags: %s"),
10658 idx
, ent
.vd_version
, get_ver_flags (ent
.vd_flags
));
10660 printf (_(" Index: %d Cnt: %d "),
10661 ent
.vd_ndx
, ent
.vd_cnt
);
10663 /* Check for overflow. */
10664 if (ent
.vd_aux
> (size_t) (endbuf
- vstart
))
10667 vstart
+= ent
.vd_aux
;
10669 if (vstart
+ sizeof (*eaux
) > endbuf
)
10671 eaux
= (Elf_External_Verdaux
*) vstart
;
10673 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
10674 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
10676 if (VALID_DYNAMIC_NAME (aux
.vda_name
))
10677 printf (_("Name: %s\n"), GET_DYNAMIC_NAME (aux
.vda_name
));
10679 printf (_("Name index: %ld\n"), aux
.vda_name
);
10681 isum
= idx
+ ent
.vd_aux
;
10683 for (j
= 1; j
< ent
.vd_cnt
; j
++)
10685 if (aux
.vda_next
< sizeof (*eaux
)
10686 && !(j
== ent
.vd_cnt
- 1 && aux
.vda_next
== 0))
10688 warn (_("Invalid vda_next field of %lx\n"),
10693 /* Check for overflow. */
10694 if (aux
.vda_next
> (size_t) (endbuf
- vstart
))
10697 isum
+= aux
.vda_next
;
10698 vstart
+= aux
.vda_next
;
10700 if (vstart
+ sizeof (*eaux
) > endbuf
)
10702 eaux
= (Elf_External_Verdaux
*) vstart
;
10704 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
10705 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
10707 if (VALID_DYNAMIC_NAME (aux
.vda_name
))
10708 printf (_(" %#06lx: Parent %d: %s\n"),
10709 isum
, j
, GET_DYNAMIC_NAME (aux
.vda_name
));
10711 printf (_(" %#06lx: Parent %d, name index: %ld\n"),
10712 isum
, j
, aux
.vda_name
);
10715 if (j
< ent
.vd_cnt
)
10716 printf (_(" Version def aux past end of section\n"));
10719 file: id:000001,src:000172+005151,op:splice,rep:2. */
10720 if (ent
.vd_next
< sizeof (*edef
)
10721 && !(cnt
== section
->sh_info
- 1 && ent
.vd_next
== 0))
10723 warn (_("Invalid vd_next field of %lx\n"), ent
.vd_next
);
10724 cnt
= section
->sh_info
;
10727 if (ent
.vd_next
> (size_t) (endbuf
- ((char *) edefs
+ idx
)))
10730 idx
+= ent
.vd_next
;
10733 if (cnt
< section
->sh_info
)
10734 printf (_(" Version definition past end of section\n"));
10740 case SHT_GNU_verneed
:
10742 Elf_External_Verneed
* eneed
;
10749 printf (ngettext ("\nVersion needs section '%s' "
10750 "contains %u entry:\n",
10751 "\nVersion needs section '%s' "
10752 "contains %u entries:\n",
10754 printable_section_name (filedata
, section
), section
->sh_info
);
10756 printf (_(" Addr: 0x"));
10757 printf_vma (section
->sh_addr
);
10758 printf (_(" Offset: %#08lx Link: %u (%s)\n"),
10759 (unsigned long) section
->sh_offset
, section
->sh_link
,
10760 printable_section_name_from_index (filedata
, section
->sh_link
));
10762 eneed
= (Elf_External_Verneed
*) get_data (NULL
, filedata
,
10763 section
->sh_offset
, 1,
10765 _("Version Needs section"));
10768 endbuf
= (char *) eneed
+ section
->sh_size
;
10770 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
10772 Elf_External_Verneed
* entry
;
10773 Elf_Internal_Verneed ent
;
10774 unsigned long isum
;
10778 vstart
= ((char *) eneed
) + idx
;
10779 if (vstart
+ sizeof (*entry
) > endbuf
)
10782 entry
= (Elf_External_Verneed
*) vstart
;
10784 ent
.vn_version
= BYTE_GET (entry
->vn_version
);
10785 ent
.vn_cnt
= BYTE_GET (entry
->vn_cnt
);
10786 ent
.vn_file
= BYTE_GET (entry
->vn_file
);
10787 ent
.vn_aux
= BYTE_GET (entry
->vn_aux
);
10788 ent
.vn_next
= BYTE_GET (entry
->vn_next
);
10790 printf (_(" %#06lx: Version: %d"), idx
, ent
.vn_version
);
10792 if (VALID_DYNAMIC_NAME (ent
.vn_file
))
10793 printf (_(" File: %s"), GET_DYNAMIC_NAME (ent
.vn_file
));
10795 printf (_(" File: %lx"), ent
.vn_file
);
10797 printf (_(" Cnt: %d\n"), ent
.vn_cnt
);
10799 /* Check for overflow. */
10800 if (ent
.vn_aux
> (size_t) (endbuf
- vstart
))
10802 vstart
+= ent
.vn_aux
;
10804 for (j
= 0, isum
= idx
+ ent
.vn_aux
; j
< ent
.vn_cnt
; ++j
)
10806 Elf_External_Vernaux
* eaux
;
10807 Elf_Internal_Vernaux aux
;
10809 if (vstart
+ sizeof (*eaux
) > endbuf
)
10811 eaux
= (Elf_External_Vernaux
*) vstart
;
10813 aux
.vna_hash
= BYTE_GET (eaux
->vna_hash
);
10814 aux
.vna_flags
= BYTE_GET (eaux
->vna_flags
);
10815 aux
.vna_other
= BYTE_GET (eaux
->vna_other
);
10816 aux
.vna_name
= BYTE_GET (eaux
->vna_name
);
10817 aux
.vna_next
= BYTE_GET (eaux
->vna_next
);
10819 if (VALID_DYNAMIC_NAME (aux
.vna_name
))
10820 printf (_(" %#06lx: Name: %s"),
10821 isum
, GET_DYNAMIC_NAME (aux
.vna_name
));
10823 printf (_(" %#06lx: Name index: %lx"),
10824 isum
, aux
.vna_name
);
10826 printf (_(" Flags: %s Version: %d\n"),
10827 get_ver_flags (aux
.vna_flags
), aux
.vna_other
);
10829 if (aux
.vna_next
< sizeof (*eaux
)
10830 && !(j
== ent
.vn_cnt
- 1 && aux
.vna_next
== 0))
10832 warn (_("Invalid vna_next field of %lx\n"),
10837 /* Check for overflow. */
10838 if (aux
.vna_next
> (size_t) (endbuf
- vstart
))
10840 isum
+= aux
.vna_next
;
10841 vstart
+= aux
.vna_next
;
10844 if (j
< ent
.vn_cnt
)
10845 warn (_("Missing Version Needs auxillary information\n"));
10847 if (ent
.vn_next
< sizeof (*entry
)
10848 && !(cnt
== section
->sh_info
- 1 && ent
.vn_next
== 0))
10850 warn (_("Invalid vn_next field of %lx\n"), ent
.vn_next
);
10851 cnt
= section
->sh_info
;
10854 if (ent
.vn_next
> (size_t) (endbuf
- ((char *) eneed
+ idx
)))
10856 idx
+= ent
.vn_next
;
10859 if (cnt
< section
->sh_info
)
10860 warn (_("Missing Version Needs information\n"));
10866 case SHT_GNU_versym
:
10868 Elf_Internal_Shdr
* link_section
;
10871 unsigned char * edata
;
10872 unsigned short * data
;
10874 Elf_Internal_Sym
* symbols
;
10875 Elf_Internal_Shdr
* string_sec
;
10876 unsigned long num_syms
;
10879 if (section
->sh_link
>= filedata
->file_header
.e_shnum
)
10882 link_section
= filedata
->section_headers
+ section
->sh_link
;
10883 total
= section
->sh_size
/ sizeof (Elf_External_Versym
);
10885 if (link_section
->sh_link
>= filedata
->file_header
.e_shnum
)
10890 symbols
= GET_ELF_SYMBOLS (filedata
, link_section
, & num_syms
);
10891 if (symbols
== NULL
)
10894 string_sec
= filedata
->section_headers
+ link_section
->sh_link
;
10896 strtab
= (char *) get_data (NULL
, filedata
, string_sec
->sh_offset
, 1,
10897 string_sec
->sh_size
,
10898 _("version string table"));
10905 printf (ngettext ("\nVersion symbols section '%s' "
10906 "contains %lu entry:\n",
10907 "\nVersion symbols section '%s' "
10908 "contains %lu entries:\n",
10910 printable_section_name (filedata
, section
), (unsigned long) total
);
10912 printf (_(" Addr: 0x"));
10913 printf_vma (section
->sh_addr
);
10914 printf (_(" Offset: %#08lx Link: %u (%s)\n"),
10915 (unsigned long) section
->sh_offset
, section
->sh_link
,
10916 printable_section_name (filedata
, link_section
));
10918 off
= offset_from_vma (filedata
,
10919 version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)],
10920 total
* sizeof (short));
10921 edata
= (unsigned char *) get_data (NULL
, filedata
, off
, total
,
10923 _("version symbol data"));
10931 data
= (short unsigned int *) cmalloc (total
, sizeof (short));
10933 for (cnt
= total
; cnt
--;)
10934 data
[cnt
] = byte_get (edata
+ cnt
* sizeof (short),
10939 for (cnt
= 0; cnt
< total
; cnt
+= 4)
10943 char *invalid
= _("*invalid*");
10945 printf (" %03x:", cnt
);
10947 for (j
= 0; (j
< 4) && (cnt
+ j
) < total
; ++j
)
10948 switch (data
[cnt
+ j
])
10951 fputs (_(" 0 (*local*) "), stdout
);
10955 fputs (_(" 1 (*global*) "), stdout
);
10959 nn
= printf ("%4x%c", data
[cnt
+ j
] & VERSYM_VERSION
,
10960 data
[cnt
+ j
] & VERSYM_HIDDEN
? 'h' : ' ');
10962 /* If this index value is greater than the size of the symbols
10963 array, break to avoid an out-of-bounds read. */
10964 if ((unsigned long)(cnt
+ j
) >= num_syms
)
10966 warn (_("invalid index into symbol array\n"));
10971 if (version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)])
10973 Elf_Internal_Verneed ivn
;
10974 unsigned long offset
;
10976 offset
= offset_from_vma
10977 (filedata
, version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)],
10978 sizeof (Elf_External_Verneed
));
10982 Elf_Internal_Vernaux ivna
;
10983 Elf_External_Verneed evn
;
10984 Elf_External_Vernaux evna
;
10985 unsigned long a_off
;
10987 if (get_data (&evn
, filedata
, offset
, sizeof (evn
), 1,
10988 _("version need")) == NULL
)
10991 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
10992 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
10994 a_off
= offset
+ ivn
.vn_aux
;
10998 if (get_data (&evna
, filedata
, a_off
, sizeof (evna
),
10999 1, _("version need aux (2)")) == NULL
)
11002 ivna
.vna_other
= 0;
11006 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
11007 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
11010 a_off
+= ivna
.vna_next
;
11012 while (ivna
.vna_other
!= data
[cnt
+ j
]
11013 && ivna
.vna_next
!= 0);
11015 if (ivna
.vna_other
== data
[cnt
+ j
])
11017 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
11019 if (ivna
.vna_name
>= string_sec
->sh_size
)
11022 name
= strtab
+ ivna
.vna_name
;
11026 offset
+= ivn
.vn_next
;
11028 while (ivn
.vn_next
);
11031 if (data
[cnt
+ j
] != 0x8001
11032 && version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
11034 Elf_Internal_Verdef ivd
;
11035 Elf_External_Verdef evd
;
11036 unsigned long offset
;
11038 offset
= offset_from_vma
11039 (filedata
, version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)],
11044 if (get_data (&evd
, filedata
, offset
, sizeof (evd
), 1,
11045 _("version def")) == NULL
)
11048 /* PR 17531: file: 046-1082287-0.004. */
11049 ivd
.vd_ndx
= (data
[cnt
+ j
] & VERSYM_VERSION
) + 1;
11054 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
11055 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
11058 offset
+= ivd
.vd_next
;
11060 while (ivd
.vd_ndx
!= (data
[cnt
+ j
] & VERSYM_VERSION
)
11061 && ivd
.vd_next
!= 0);
11063 if (ivd
.vd_ndx
== (data
[cnt
+ j
] & VERSYM_VERSION
))
11065 Elf_External_Verdaux evda
;
11066 Elf_Internal_Verdaux ivda
;
11068 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
11070 if (get_data (&evda
, filedata
,
11071 offset
- ivd
.vd_next
+ ivd
.vd_aux
,
11073 _("version def aux")) == NULL
)
11076 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
11078 if (ivda
.vda_name
>= string_sec
->sh_size
)
11080 else if (name
!= NULL
&& name
!= invalid
)
11081 name
= _("*both*");
11083 name
= strtab
+ ivda
.vda_name
;
11087 nn
+= printf ("(%s%-*s",
11089 12 - (int) strlen (name
),
11093 printf ("%*c", 18 - nn
, ' ');
11111 printf (_("\nNo version information found in this file.\n"));
11116 static const char *
11117 get_symbol_binding (Filedata
* filedata
, unsigned int binding
)
11119 static char buff
[32];
11123 case STB_LOCAL
: return "LOCAL";
11124 case STB_GLOBAL
: return "GLOBAL";
11125 case STB_WEAK
: return "WEAK";
11127 if (binding
>= STB_LOPROC
&& binding
<= STB_HIPROC
)
11128 snprintf (buff
, sizeof (buff
), _("<processor specific>: %d"),
11130 else if (binding
>= STB_LOOS
&& binding
<= STB_HIOS
)
11132 if (binding
== STB_GNU_UNIQUE
11133 && filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_GNU
)
11135 snprintf (buff
, sizeof (buff
), _("<OS specific>: %d"), binding
);
11138 snprintf (buff
, sizeof (buff
), _("<unknown>: %d"), binding
);
11143 static const char *
11144 get_symbol_type (Filedata
* filedata
, unsigned int type
)
11146 static char buff
[32];
11150 case STT_NOTYPE
: return "NOTYPE";
11151 case STT_OBJECT
: return "OBJECT";
11152 case STT_FUNC
: return "FUNC";
11153 case STT_SECTION
: return "SECTION";
11154 case STT_FILE
: return "FILE";
11155 case STT_COMMON
: return "COMMON";
11156 case STT_TLS
: return "TLS";
11157 case STT_RELC
: return "RELC";
11158 case STT_SRELC
: return "SRELC";
11160 if (type
>= STT_LOPROC
&& type
<= STT_HIPROC
)
11162 if (filedata
->file_header
.e_machine
== EM_ARM
&& type
== STT_ARM_TFUNC
)
11163 return "THUMB_FUNC";
11165 if (filedata
->file_header
.e_machine
== EM_SPARCV9
&& type
== STT_REGISTER
)
11168 if (filedata
->file_header
.e_machine
== EM_PARISC
&& type
== STT_PARISC_MILLI
)
11169 return "PARISC_MILLI";
11171 snprintf (buff
, sizeof (buff
), _("<processor specific>: %d"), type
);
11173 else if (type
>= STT_LOOS
&& type
<= STT_HIOS
)
11175 if (filedata
->file_header
.e_machine
== EM_PARISC
)
11177 if (type
== STT_HP_OPAQUE
)
11178 return "HP_OPAQUE";
11179 if (type
== STT_HP_STUB
)
11183 if (type
== STT_GNU_IFUNC
11184 && (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_GNU
11185 || filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_FREEBSD
))
11188 snprintf (buff
, sizeof (buff
), _("<OS specific>: %d"), type
);
11191 snprintf (buff
, sizeof (buff
), _("<unknown>: %d"), type
);
11196 static const char *
11197 get_symbol_visibility (unsigned int visibility
)
11199 switch (visibility
)
11201 case STV_DEFAULT
: return "DEFAULT";
11202 case STV_INTERNAL
: return "INTERNAL";
11203 case STV_HIDDEN
: return "HIDDEN";
11204 case STV_PROTECTED
: return "PROTECTED";
11206 error (_("Unrecognized visibility value: %u"), visibility
);
11207 return _("<unknown>");
11211 static const char *
11212 get_alpha_symbol_other (unsigned int other
)
11216 case STO_ALPHA_NOPV
: return "NOPV";
11217 case STO_ALPHA_STD_GPLOAD
: return "STD GPLOAD";
11219 error (_("Unrecognized alpah specific other value: %u"), other
);
11220 return _("<unknown>");
11224 static const char *
11225 get_solaris_symbol_visibility (unsigned int visibility
)
11227 switch (visibility
)
11229 case 4: return "EXPORTED";
11230 case 5: return "SINGLETON";
11231 case 6: return "ELIMINATE";
11232 default: return get_symbol_visibility (visibility
);
11236 static const char *
11237 get_aarch64_symbol_other (unsigned int other
)
11239 static char buf
[32];
11241 if (other
& STO_AARCH64_VARIANT_PCS
)
11243 other
&= ~STO_AARCH64_VARIANT_PCS
;
11245 return "VARIANT_PCS";
11246 snprintf (buf
, sizeof buf
, "VARIANT_PCS | %x", other
);
11252 static const char *
11253 get_mips_symbol_other (unsigned int other
)
11257 case STO_OPTIONAL
: return "OPTIONAL";
11258 case STO_MIPS_PLT
: return "MIPS PLT";
11259 case STO_MIPS_PIC
: return "MIPS PIC";
11260 case STO_MICROMIPS
: return "MICROMIPS";
11261 case STO_MICROMIPS
| STO_MIPS_PIC
: return "MICROMIPS, MIPS PIC";
11262 case STO_MIPS16
: return "MIPS16";
11263 default: return NULL
;
11267 static const char *
11268 get_ia64_symbol_other (Filedata
* filedata
, unsigned int other
)
11270 if (is_ia64_vms (filedata
))
11272 static char res
[32];
11276 /* Function types is for images and .STB files only. */
11277 switch (filedata
->file_header
.e_type
)
11281 switch (VMS_ST_FUNC_TYPE (other
))
11283 case VMS_SFT_CODE_ADDR
:
11284 strcat (res
, " CA");
11286 case VMS_SFT_SYMV_IDX
:
11287 strcat (res
, " VEC");
11290 strcat (res
, " FD");
11292 case VMS_SFT_RESERVE
:
11293 strcat (res
, " RSV");
11296 warn (_("Unrecognized IA64 VMS ST Function type: %d\n"),
11297 VMS_ST_FUNC_TYPE (other
));
11298 strcat (res
, " <unknown>");
11305 switch (VMS_ST_LINKAGE (other
))
11307 case VMS_STL_IGNORE
:
11308 strcat (res
, " IGN");
11310 case VMS_STL_RESERVE
:
11311 strcat (res
, " RSV");
11314 strcat (res
, " STD");
11317 strcat (res
, " LNK");
11320 warn (_("Unrecognized IA64 VMS ST Linkage: %d\n"),
11321 VMS_ST_LINKAGE (other
));
11322 strcat (res
, " <unknown>");
11334 static const char *
11335 get_ppc64_symbol_other (unsigned int other
)
11337 if ((other
& ~STO_PPC64_LOCAL_MASK
) != 0)
11340 other
>>= STO_PPC64_LOCAL_BIT
;
11343 static char buf
[32];
11345 other
= ppc64_decode_local_entry (other
);
11346 snprintf (buf
, sizeof buf
, _("<localentry>: %d"), other
);
11352 static const char *
11353 get_symbol_other (Filedata
* filedata
, unsigned int other
)
11355 const char * result
= NULL
;
11356 static char buff
[32];
11361 switch (filedata
->file_header
.e_machine
)
11364 result
= get_alpha_symbol_other (other
);
11367 result
= get_aarch64_symbol_other (other
);
11370 result
= get_mips_symbol_other (other
);
11373 result
= get_ia64_symbol_other (filedata
, other
);
11376 result
= get_ppc64_symbol_other (other
);
11386 snprintf (buff
, sizeof buff
, _("<other>: %x"), other
);
11390 static const char *
11391 get_symbol_index_type (Filedata
* filedata
, unsigned int type
)
11393 static char buff
[32];
11397 case SHN_UNDEF
: return "UND";
11398 case SHN_ABS
: return "ABS";
11399 case SHN_COMMON
: return "COM";
11401 if (type
== SHN_IA_64_ANSI_COMMON
11402 && filedata
->file_header
.e_machine
== EM_IA_64
11403 && filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_HPUX
)
11405 else if ((filedata
->file_header
.e_machine
== EM_X86_64
11406 || filedata
->file_header
.e_machine
== EM_L1OM
11407 || filedata
->file_header
.e_machine
== EM_K1OM
)
11408 && type
== SHN_X86_64_LCOMMON
)
11409 return "LARGE_COM";
11410 else if ((type
== SHN_MIPS_SCOMMON
11411 && filedata
->file_header
.e_machine
== EM_MIPS
)
11412 || (type
== SHN_TIC6X_SCOMMON
11413 && filedata
->file_header
.e_machine
== EM_TI_C6000
))
11415 else if (type
== SHN_MIPS_SUNDEFINED
11416 && filedata
->file_header
.e_machine
== EM_MIPS
)
11418 else if (type
>= SHN_LOPROC
&& type
<= SHN_HIPROC
)
11419 sprintf (buff
, "PRC[0x%04x]", type
& 0xffff);
11420 else if (type
>= SHN_LOOS
&& type
<= SHN_HIOS
)
11421 sprintf (buff
, "OS [0x%04x]", type
& 0xffff);
11422 else if (type
>= SHN_LORESERVE
)
11423 sprintf (buff
, "RSV[0x%04x]", type
& 0xffff);
11424 else if (type
>= filedata
->file_header
.e_shnum
)
11425 sprintf (buff
, _("bad section index[%3d]"), type
);
11427 sprintf (buff
, "%3d", type
);
11435 get_dynamic_data (Filedata
* filedata
, bfd_size_type number
, unsigned int ent_size
)
11437 unsigned char * e_data
;
11440 /* If the size_t type is smaller than the bfd_size_type, eg because
11441 you are building a 32-bit tool on a 64-bit host, then make sure
11442 that when (number) is cast to (size_t) no information is lost. */
11443 if (sizeof (size_t) < sizeof (bfd_size_type
)
11444 && (bfd_size_type
) ((size_t) number
) != number
)
11446 error (_("Size truncation prevents reading %s elements of size %u\n"),
11447 bfd_vmatoa ("u", number
), ent_size
);
11451 /* Be kind to memory chekers (eg valgrind, address sanitizer) by not
11452 attempting to allocate memory when the read is bound to fail. */
11453 if (ent_size
* number
> filedata
->file_size
)
11455 error (_("Invalid number of dynamic entries: %s\n"),
11456 bfd_vmatoa ("u", number
));
11460 e_data
= (unsigned char *) cmalloc ((size_t) number
, ent_size
);
11461 if (e_data
== NULL
)
11463 error (_("Out of memory reading %s dynamic entries\n"),
11464 bfd_vmatoa ("u", number
));
11468 if (fread (e_data
, ent_size
, (size_t) number
, filedata
->handle
) != number
)
11470 error (_("Unable to read in %s bytes of dynamic data\n"),
11471 bfd_vmatoa ("u", number
* ent_size
));
11476 i_data
= (bfd_vma
*) cmalloc ((size_t) number
, sizeof (*i_data
));
11477 if (i_data
== NULL
)
11479 error (_("Out of memory allocating space for %s dynamic entries\n"),
11480 bfd_vmatoa ("u", number
));
11486 i_data
[number
] = byte_get (e_data
+ number
* ent_size
, ent_size
);
11494 print_dynamic_symbol (Filedata
* filedata
, bfd_vma si
, unsigned long hn
)
11496 Elf_Internal_Sym
* psym
;
11499 n
= print_vma (si
, DEC_5
);
11501 fputs (&" "[n
], stdout
);
11502 printf (" %3lu: ", hn
);
11504 if (dynamic_symbols
== NULL
|| si
>= num_dynamic_syms
)
11506 printf (_("<No info available for dynamic symbol number %lu>\n"),
11507 (unsigned long) si
);
11511 psym
= dynamic_symbols
+ si
;
11512 print_vma (psym
->st_value
, LONG_HEX
);
11514 print_vma (psym
->st_size
, DEC_5
);
11516 printf (" %-7s", get_symbol_type (filedata
, ELF_ST_TYPE (psym
->st_info
)));
11517 printf (" %-6s", get_symbol_binding (filedata
, ELF_ST_BIND (psym
->st_info
)));
11519 if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_SOLARIS
)
11520 printf (" %-7s", get_solaris_symbol_visibility (psym
->st_other
));
11523 unsigned int vis
= ELF_ST_VISIBILITY (psym
->st_other
);
11525 printf (" %-7s", get_symbol_visibility (vis
));
11526 /* Check to see if any other bits in the st_other field are set.
11527 Note - displaying this information disrupts the layout of the
11528 table being generated, but for the moment this case is very
11530 if (psym
->st_other
^ vis
)
11531 printf (" [%s] ", get_symbol_other (filedata
, psym
->st_other
^ vis
));
11534 printf (" %3.3s ", get_symbol_index_type (filedata
, psym
->st_shndx
));
11535 if (VALID_DYNAMIC_NAME (psym
->st_name
))
11536 print_symbol (25, GET_DYNAMIC_NAME (psym
->st_name
));
11538 printf (_(" <corrupt: %14ld>"), psym
->st_name
);
11542 static const char *
11543 get_symbol_version_string (Filedata
* filedata
,
11544 bfd_boolean is_dynsym
,
11545 const char * strtab
,
11546 unsigned long int strtab_size
,
11548 Elf_Internal_Sym
* psym
,
11549 enum versioned_symbol_info
* sym_info
,
11550 unsigned short * vna_other
)
11552 unsigned char data
[2];
11553 unsigned short vers_data
;
11554 unsigned long offset
;
11555 unsigned short max_vd_ndx
;
11558 || version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)] == 0)
11561 offset
= offset_from_vma (filedata
, version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)],
11562 sizeof data
+ si
* sizeof (vers_data
));
11564 if (get_data (&data
, filedata
, offset
+ si
* sizeof (vers_data
),
11565 sizeof (data
), 1, _("version data")) == NULL
)
11568 vers_data
= byte_get (data
, 2);
11570 if ((vers_data
& VERSYM_HIDDEN
) == 0 && vers_data
== 0)
11573 *sym_info
= (vers_data
& VERSYM_HIDDEN
) != 0 ? symbol_hidden
: symbol_public
;
11576 /* Usually we'd only see verdef for defined symbols, and verneed for
11577 undefined symbols. However, symbols defined by the linker in
11578 .dynbss for variables copied from a shared library in order to
11579 avoid text relocations are defined yet have verneed. We could
11580 use a heuristic to detect the special case, for example, check
11581 for verneed first on symbols defined in SHT_NOBITS sections, but
11582 it is simpler and more reliable to just look for both verdef and
11583 verneed. .dynbss might not be mapped to a SHT_NOBITS section. */
11585 if (psym
->st_shndx
!= SHN_UNDEF
11586 && vers_data
!= 0x8001
11587 && version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
11589 Elf_Internal_Verdef ivd
;
11590 Elf_Internal_Verdaux ivda
;
11591 Elf_External_Verdaux evda
;
11594 off
= offset_from_vma (filedata
,
11595 version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)],
11596 sizeof (Elf_External_Verdef
));
11600 Elf_External_Verdef evd
;
11602 if (get_data (&evd
, filedata
, off
, sizeof (evd
), 1,
11603 _("version def")) == NULL
)
11612 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
11613 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
11614 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
11615 ivd
.vd_flags
= BYTE_GET (evd
.vd_flags
);
11618 if ((ivd
.vd_ndx
& VERSYM_VERSION
) > max_vd_ndx
)
11619 max_vd_ndx
= ivd
.vd_ndx
& VERSYM_VERSION
;
11621 off
+= ivd
.vd_next
;
11623 while (ivd
.vd_ndx
!= (vers_data
& VERSYM_VERSION
) && ivd
.vd_next
!= 0);
11625 if (ivd
.vd_ndx
== (vers_data
& VERSYM_VERSION
))
11627 if (ivd
.vd_ndx
== 1 && ivd
.vd_flags
== VER_FLG_BASE
)
11630 off
-= ivd
.vd_next
;
11633 if (get_data (&evda
, filedata
, off
, sizeof (evda
), 1,
11634 _("version def aux")) != NULL
)
11636 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
11638 if (psym
->st_name
!= ivda
.vda_name
)
11639 return (ivda
.vda_name
< strtab_size
11640 ? strtab
+ ivda
.vda_name
: _("<corrupt>"));
11645 if (version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)])
11647 Elf_External_Verneed evn
;
11648 Elf_Internal_Verneed ivn
;
11649 Elf_Internal_Vernaux ivna
;
11651 offset
= offset_from_vma (filedata
,
11652 version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)],
11656 unsigned long vna_off
;
11658 if (get_data (&evn
, filedata
, offset
, sizeof (evn
), 1,
11659 _("version need")) == NULL
)
11662 ivna
.vna_other
= 0;
11667 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
11668 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
11670 vna_off
= offset
+ ivn
.vn_aux
;
11674 Elf_External_Vernaux evna
;
11676 if (get_data (&evna
, filedata
, vna_off
, sizeof (evna
), 1,
11677 _("version need aux (3)")) == NULL
)
11680 ivna
.vna_other
= 0;
11685 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
11686 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
11687 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
11690 vna_off
+= ivna
.vna_next
;
11692 while (ivna
.vna_other
!= vers_data
&& ivna
.vna_next
!= 0);
11694 if (ivna
.vna_other
== vers_data
)
11697 offset
+= ivn
.vn_next
;
11699 while (ivn
.vn_next
!= 0);
11701 if (ivna
.vna_other
== vers_data
)
11703 *sym_info
= symbol_undefined
;
11704 *vna_other
= ivna
.vna_other
;
11705 return (ivna
.vna_name
< strtab_size
11706 ? strtab
+ ivna
.vna_name
: _("<corrupt>"));
11708 else if ((max_vd_ndx
|| (vers_data
& VERSYM_VERSION
) != 1)
11709 && (vers_data
& VERSYM_VERSION
) > max_vd_ndx
)
11710 return _("<corrupt>");
11715 /* Dump the symbol table. */
11717 process_symbol_table (Filedata
* filedata
)
11719 Elf_Internal_Shdr
* section
;
11720 bfd_size_type nbuckets
= 0;
11721 bfd_size_type nchains
= 0;
11722 bfd_vma
* buckets
= NULL
;
11723 bfd_vma
* chains
= NULL
;
11724 bfd_vma ngnubuckets
= 0;
11725 bfd_vma
* gnubuckets
= NULL
;
11726 bfd_vma
* gnuchains
= NULL
;
11727 bfd_vma
* mipsxlat
= NULL
;
11728 bfd_vma gnusymidx
= 0;
11729 bfd_size_type ngnuchains
= 0;
11731 if (!do_syms
&& !do_dyn_syms
&& !do_histogram
)
11734 if (dynamic_info
[DT_HASH
]
11736 || (do_using_dynamic
11738 && dynamic_strings
!= NULL
)))
11740 unsigned char nb
[8];
11741 unsigned char nc
[8];
11742 unsigned int hash_ent_size
= 4;
11744 if ((filedata
->file_header
.e_machine
== EM_ALPHA
11745 || filedata
->file_header
.e_machine
== EM_S390
11746 || filedata
->file_header
.e_machine
== EM_S390_OLD
)
11747 && filedata
->file_header
.e_ident
[EI_CLASS
] == ELFCLASS64
)
11750 if (fseek (filedata
->handle
,
11751 (archive_file_offset
11752 + offset_from_vma (filedata
, dynamic_info
[DT_HASH
],
11753 sizeof nb
+ sizeof nc
)),
11756 error (_("Unable to seek to start of dynamic information\n"));
11760 if (fread (nb
, hash_ent_size
, 1, filedata
->handle
) != 1)
11762 error (_("Failed to read in number of buckets\n"));
11766 if (fread (nc
, hash_ent_size
, 1, filedata
->handle
) != 1)
11768 error (_("Failed to read in number of chains\n"));
11772 nbuckets
= byte_get (nb
, hash_ent_size
);
11773 nchains
= byte_get (nc
, hash_ent_size
);
11775 buckets
= get_dynamic_data (filedata
, nbuckets
, hash_ent_size
);
11776 chains
= get_dynamic_data (filedata
, nchains
, hash_ent_size
);
11779 if (buckets
== NULL
|| chains
== NULL
)
11781 if (do_using_dynamic
)
11792 if (dynamic_info_DT_GNU_HASH
11794 || (do_using_dynamic
11796 && dynamic_strings
!= NULL
)))
11798 unsigned char nb
[16];
11799 bfd_vma i
, maxchain
= 0xffffffff, bitmaskwords
;
11800 bfd_vma buckets_vma
;
11802 if (fseek (filedata
->handle
,
11803 (archive_file_offset
11804 + offset_from_vma (filedata
, dynamic_info_DT_GNU_HASH
,
11808 error (_("Unable to seek to start of dynamic information\n"));
11812 if (fread (nb
, 16, 1, filedata
->handle
) != 1)
11814 error (_("Failed to read in number of buckets\n"));
11818 ngnubuckets
= byte_get (nb
, 4);
11819 gnusymidx
= byte_get (nb
+ 4, 4);
11820 bitmaskwords
= byte_get (nb
+ 8, 4);
11821 buckets_vma
= dynamic_info_DT_GNU_HASH
+ 16;
11823 buckets_vma
+= bitmaskwords
* 4;
11825 buckets_vma
+= bitmaskwords
* 8;
11827 if (fseek (filedata
->handle
,
11828 (archive_file_offset
11829 + offset_from_vma (filedata
, buckets_vma
, 4)),
11832 error (_("Unable to seek to start of dynamic information\n"));
11836 gnubuckets
= get_dynamic_data (filedata
, ngnubuckets
, 4);
11838 if (gnubuckets
== NULL
)
11841 for (i
= 0; i
< ngnubuckets
; i
++)
11842 if (gnubuckets
[i
] != 0)
11844 if (gnubuckets
[i
] < gnusymidx
)
11847 if (maxchain
== 0xffffffff || gnubuckets
[i
] > maxchain
)
11848 maxchain
= gnubuckets
[i
];
11851 if (maxchain
== 0xffffffff)
11854 maxchain
-= gnusymidx
;
11856 if (fseek (filedata
->handle
,
11857 (archive_file_offset
11858 + offset_from_vma (filedata
, buckets_vma
11859 + 4 * (ngnubuckets
+ maxchain
), 4)),
11862 error (_("Unable to seek to start of dynamic information\n"));
11868 if (fread (nb
, 4, 1, filedata
->handle
) != 1)
11870 error (_("Failed to determine last chain length\n"));
11874 if (maxchain
+ 1 == 0)
11879 while ((byte_get (nb
, 4) & 1) == 0);
11881 if (fseek (filedata
->handle
,
11882 (archive_file_offset
11883 + offset_from_vma (filedata
, buckets_vma
+ 4 * ngnubuckets
, 4)),
11886 error (_("Unable to seek to start of dynamic information\n"));
11890 gnuchains
= get_dynamic_data (filedata
, maxchain
, 4);
11891 ngnuchains
= maxchain
;
11893 if (gnuchains
== NULL
)
11896 if (dynamic_info_DT_MIPS_XHASH
)
11898 if (fseek (filedata
->handle
,
11899 (archive_file_offset
11900 + offset_from_vma (filedata
, (buckets_vma
11905 error (_("Unable to seek to start of dynamic information\n"));
11909 mipsxlat
= get_dynamic_data (filedata
, maxchain
, 4);
11913 if (dynamic_info_DT_MIPS_XHASH
&& mipsxlat
== NULL
)
11918 if (gnuchains
== NULL
)
11923 if (do_using_dynamic
)
11928 if ((dynamic_info
[DT_HASH
] || dynamic_info_DT_GNU_HASH
)
11930 && do_using_dynamic
11931 && dynamic_strings
!= NULL
11932 && dynamic_symbols
!= NULL
)
11936 if (dynamic_info
[DT_HASH
])
11941 printf (_("\nSymbol table for image:\n"));
11943 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
11945 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
11947 visited
= xcmalloc (nchains
, 1);
11948 memset (visited
, 0, nchains
);
11949 for (hn
= 0; hn
< nbuckets
; hn
++)
11951 for (si
= buckets
[hn
]; si
> 0; si
= chains
[si
])
11953 print_dynamic_symbol (filedata
, si
, hn
);
11954 if (si
>= nchains
|| visited
[si
])
11956 error (_("histogram chain is corrupt\n"));
11965 if (dynamic_info_DT_GNU_HASH
)
11967 printf (_("\nSymbol table of `%s' for image:\n"),
11968 GNU_HASH_SECTION_NAME
);
11970 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
11972 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
11974 for (hn
= 0; hn
< ngnubuckets
; ++hn
)
11975 if (gnubuckets
[hn
] != 0)
11977 bfd_vma si
= gnubuckets
[hn
];
11978 bfd_vma off
= si
- gnusymidx
;
11982 if (dynamic_info_DT_MIPS_XHASH
)
11983 print_dynamic_symbol (filedata
, mipsxlat
[off
], hn
);
11985 print_dynamic_symbol (filedata
, si
, hn
);
11988 while (off
< ngnuchains
&& (gnuchains
[off
++] & 1) == 0);
11992 else if ((do_dyn_syms
|| (do_syms
&& !do_using_dynamic
))
11993 && filedata
->section_headers
!= NULL
)
11997 for (i
= 0, section
= filedata
->section_headers
;
11998 i
< filedata
->file_header
.e_shnum
;
12002 char * strtab
= NULL
;
12003 unsigned long int strtab_size
= 0;
12004 Elf_Internal_Sym
* symtab
;
12005 Elf_Internal_Sym
* psym
;
12006 unsigned long num_syms
;
12008 if ((section
->sh_type
!= SHT_SYMTAB
12009 && section
->sh_type
!= SHT_DYNSYM
)
12011 && section
->sh_type
== SHT_SYMTAB
))
12014 if (section
->sh_entsize
== 0)
12016 printf (_("\nSymbol table '%s' has a sh_entsize of zero!\n"),
12017 printable_section_name (filedata
, section
));
12021 num_syms
= section
->sh_size
/ section
->sh_entsize
;
12022 printf (ngettext ("\nSymbol table '%s' contains %lu entry:\n",
12023 "\nSymbol table '%s' contains %lu entries:\n",
12025 printable_section_name (filedata
, section
),
12029 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
12031 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
12033 symtab
= GET_ELF_SYMBOLS (filedata
, section
, & num_syms
);
12034 if (symtab
== NULL
)
12037 if (section
->sh_link
== filedata
->file_header
.e_shstrndx
)
12039 strtab
= filedata
->string_table
;
12040 strtab_size
= filedata
->string_table_length
;
12042 else if (section
->sh_link
< filedata
->file_header
.e_shnum
)
12044 Elf_Internal_Shdr
* string_sec
;
12046 string_sec
= filedata
->section_headers
+ section
->sh_link
;
12048 strtab
= (char *) get_data (NULL
, filedata
, string_sec
->sh_offset
,
12049 1, string_sec
->sh_size
,
12050 _("string table"));
12051 strtab_size
= strtab
!= NULL
? string_sec
->sh_size
: 0;
12054 for (si
= 0, psym
= symtab
; si
< num_syms
; si
++, psym
++)
12056 const char *version_string
;
12057 enum versioned_symbol_info sym_info
;
12058 unsigned short vna_other
;
12060 printf ("%6d: ", si
);
12061 print_vma (psym
->st_value
, LONG_HEX
);
12063 print_vma (psym
->st_size
, DEC_5
);
12064 printf (" %-7s", get_symbol_type (filedata
, ELF_ST_TYPE (psym
->st_info
)));
12065 printf (" %-6s", get_symbol_binding (filedata
, ELF_ST_BIND (psym
->st_info
)));
12066 if (filedata
->file_header
.e_ident
[EI_OSABI
] == ELFOSABI_SOLARIS
)
12067 printf (" %-7s", get_solaris_symbol_visibility (psym
->st_other
));
12070 unsigned int vis
= ELF_ST_VISIBILITY (psym
->st_other
);
12072 printf (" %-7s", get_symbol_visibility (vis
));
12073 /* Check to see if any other bits in the st_other field are set.
12074 Note - displaying this information disrupts the layout of the
12075 table being generated, but for the moment this case is very rare. */
12076 if (psym
->st_other
^ vis
)
12077 printf (" [%s] ", get_symbol_other (filedata
, psym
->st_other
^ vis
));
12079 printf (" %4s ", get_symbol_index_type (filedata
, psym
->st_shndx
));
12080 print_symbol (25, psym
->st_name
< strtab_size
12081 ? strtab
+ psym
->st_name
: _("<corrupt>"));
12084 = get_symbol_version_string (filedata
,
12085 section
->sh_type
== SHT_DYNSYM
,
12086 strtab
, strtab_size
, si
,
12087 psym
, &sym_info
, &vna_other
);
12088 if (version_string
)
12090 if (sym_info
== symbol_undefined
)
12091 printf ("@%s (%d)", version_string
, vna_other
);
12093 printf (sym_info
== symbol_hidden
? "@%s" : "@@%s",
12099 if (ELF_ST_BIND (psym
->st_info
) == STB_LOCAL
12100 && si
>= section
->sh_info
12101 /* Irix 5 and 6 MIPS binaries are known to ignore this requirement. */
12102 && filedata
->file_header
.e_machine
!= EM_MIPS
12103 /* Solaris binaries have been found to violate this requirement as
12104 well. Not sure if this is a bug or an ABI requirement. */
12105 && filedata
->file_header
.e_ident
[EI_OSABI
] != ELFOSABI_SOLARIS
)
12106 warn (_("local symbol %u found at index >= %s's sh_info value of %u\n"),
12107 si
, printable_section_name (filedata
, section
), section
->sh_info
);
12111 if (strtab
!= filedata
->string_table
)
12117 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
12119 if (do_histogram
&& buckets
!= NULL
)
12121 unsigned long * lengths
;
12122 unsigned long * counts
;
12125 unsigned long maxlength
= 0;
12126 unsigned long nzero_counts
= 0;
12127 unsigned long nsyms
= 0;
12130 printf (ngettext ("\nHistogram for bucket list length "
12131 "(total of %lu bucket):\n",
12132 "\nHistogram for bucket list length "
12133 "(total of %lu buckets):\n",
12134 (unsigned long) nbuckets
),
12135 (unsigned long) nbuckets
);
12137 lengths
= (unsigned long *) calloc (nbuckets
, sizeof (*lengths
));
12138 if (lengths
== NULL
)
12140 error (_("Out of memory allocating space for histogram buckets\n"));
12143 visited
= xcmalloc (nchains
, 1);
12144 memset (visited
, 0, nchains
);
12146 printf (_(" Length Number %% of total Coverage\n"));
12147 for (hn
= 0; hn
< nbuckets
; ++hn
)
12149 for (si
= buckets
[hn
]; si
> 0; si
= chains
[si
])
12152 if (maxlength
< ++lengths
[hn
])
12154 if (si
>= nchains
|| visited
[si
])
12156 error (_("histogram chain is corrupt\n"));
12164 counts
= (unsigned long *) calloc (maxlength
+ 1, sizeof (*counts
));
12165 if (counts
== NULL
)
12168 error (_("Out of memory allocating space for histogram counts\n"));
12172 for (hn
= 0; hn
< nbuckets
; ++hn
)
12173 ++counts
[lengths
[hn
]];
12178 printf (" 0 %-10lu (%5.1f%%)\n",
12179 counts
[0], (counts
[0] * 100.0) / nbuckets
);
12180 for (i
= 1; i
<= maxlength
; ++i
)
12182 nzero_counts
+= counts
[i
] * i
;
12183 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
12184 i
, counts
[i
], (counts
[i
] * 100.0) / nbuckets
,
12185 (nzero_counts
* 100.0) / nsyms
);
12193 if (buckets
!= NULL
)
12199 if (do_histogram
&& gnubuckets
!= NULL
)
12201 unsigned long * lengths
;
12202 unsigned long * counts
;
12204 unsigned long maxlength
= 0;
12205 unsigned long nzero_counts
= 0;
12206 unsigned long nsyms
= 0;
12208 printf (ngettext ("\nHistogram for `%s' bucket list length "
12209 "(total of %lu bucket):\n",
12210 "\nHistogram for `%s' bucket list length "
12211 "(total of %lu buckets):\n",
12212 (unsigned long) ngnubuckets
),
12213 GNU_HASH_SECTION_NAME
,
12214 (unsigned long) ngnubuckets
);
12216 lengths
= (unsigned long *) calloc (ngnubuckets
, sizeof (*lengths
));
12217 if (lengths
== NULL
)
12219 error (_("Out of memory allocating space for gnu histogram buckets\n"));
12223 printf (_(" Length Number %% of total Coverage\n"));
12225 for (hn
= 0; hn
< ngnubuckets
; ++hn
)
12226 if (gnubuckets
[hn
] != 0)
12228 bfd_vma off
, length
= 1;
12230 for (off
= gnubuckets
[hn
] - gnusymidx
;
12231 /* PR 17531 file: 010-77222-0.004. */
12232 off
< ngnuchains
&& (gnuchains
[off
] & 1) == 0;
12235 lengths
[hn
] = length
;
12236 if (length
> maxlength
)
12237 maxlength
= length
;
12241 counts
= (unsigned long *) calloc (maxlength
+ 1, sizeof (*counts
));
12242 if (counts
== NULL
)
12245 error (_("Out of memory allocating space for gnu histogram counts\n"));
12249 for (hn
= 0; hn
< ngnubuckets
; ++hn
)
12250 ++counts
[lengths
[hn
]];
12252 if (ngnubuckets
> 0)
12255 printf (" 0 %-10lu (%5.1f%%)\n",
12256 counts
[0], (counts
[0] * 100.0) / ngnubuckets
);
12257 for (j
= 1; j
<= maxlength
; ++j
)
12259 nzero_counts
+= counts
[j
] * j
;
12260 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
12261 j
, counts
[j
], (counts
[j
] * 100.0) / ngnubuckets
,
12262 (nzero_counts
* 100.0) / nsyms
);
12277 process_syminfo (Filedata
* filedata ATTRIBUTE_UNUSED
)
12281 if (dynamic_syminfo
== NULL
12283 /* No syminfo, this is ok. */
12286 /* There better should be a dynamic symbol section. */
12287 if (dynamic_symbols
== NULL
|| dynamic_strings
== NULL
)
12291 printf (ngettext ("\nDynamic info segment at offset 0x%lx "
12292 "contains %d entry:\n",
12293 "\nDynamic info segment at offset 0x%lx "
12294 "contains %d entries:\n",
12295 dynamic_syminfo_nent
),
12296 dynamic_syminfo_offset
, dynamic_syminfo_nent
);
12298 printf (_(" Num: Name BoundTo Flags\n"));
12299 for (i
= 0; i
< dynamic_syminfo_nent
; ++i
)
12301 unsigned short int flags
= dynamic_syminfo
[i
].si_flags
;
12303 printf ("%4d: ", i
);
12304 if (i
>= num_dynamic_syms
)
12305 printf (_("<corrupt index>"));
12306 else if (VALID_DYNAMIC_NAME (dynamic_symbols
[i
].st_name
))
12307 print_symbol (30, GET_DYNAMIC_NAME (dynamic_symbols
[i
].st_name
));
12309 printf (_("<corrupt: %19ld>"), dynamic_symbols
[i
].st_name
);
12312 switch (dynamic_syminfo
[i
].si_boundto
)
12314 case SYMINFO_BT_SELF
:
12315 fputs ("SELF ", stdout
);
12317 case SYMINFO_BT_PARENT
:
12318 fputs ("PARENT ", stdout
);
12321 if (dynamic_syminfo
[i
].si_boundto
> 0
12322 && dynamic_syminfo
[i
].si_boundto
< dynamic_nent
12323 && VALID_DYNAMIC_NAME (dynamic_section
[dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
))
12325 print_symbol (10, GET_DYNAMIC_NAME (dynamic_section
[dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
));
12329 printf ("%-10d ", dynamic_syminfo
[i
].si_boundto
);
12333 if (flags
& SYMINFO_FLG_DIRECT
)
12334 printf (" DIRECT");
12335 if (flags
& SYMINFO_FLG_PASSTHRU
)
12336 printf (" PASSTHRU");
12337 if (flags
& SYMINFO_FLG_COPY
)
12339 if (flags
& SYMINFO_FLG_LAZYLOAD
)
12340 printf (" LAZYLOAD");
12348 /* A macro which evaluates to TRUE if the region ADDR .. ADDR + NELEM
12349 is contained by the region START .. END. The types of ADDR, START
12350 and END should all be the same. Note both ADDR + NELEM and END
12351 point to just beyond the end of the regions that are being tested. */
12352 #define IN_RANGE(START,END,ADDR,NELEM) \
12353 (((ADDR) >= (START)) && ((ADDR) < (END)) && ((ADDR) + (NELEM) <= (END)))
12355 /* Check to see if the given reloc needs to be handled in a target specific
12356 manner. If so then process the reloc and return TRUE otherwise return
12359 If called with reloc == NULL, then this is a signal that reloc processing
12360 for the current section has finished, and any saved state should be
12364 target_specific_reloc_handling (Filedata
* filedata
,
12365 Elf_Internal_Rela
* reloc
,
12366 unsigned char * start
,
12367 unsigned char * end
,
12368 Elf_Internal_Sym
* symtab
,
12369 unsigned long num_syms
)
12371 unsigned int reloc_type
= 0;
12372 unsigned long sym_index
= 0;
12376 reloc_type
= get_reloc_type (filedata
, reloc
->r_info
);
12377 sym_index
= get_reloc_symindex (reloc
->r_info
);
12380 switch (filedata
->file_header
.e_machine
)
12383 case EM_MSP430_OLD
:
12385 static Elf_Internal_Sym
* saved_sym
= NULL
;
12393 switch (reloc_type
)
12395 case 10: /* R_MSP430_SYM_DIFF */
12396 if (uses_msp430x_relocs (filedata
))
12398 /* Fall through. */
12399 case 21: /* R_MSP430X_SYM_DIFF */
12401 if (sym_index
>= num_syms
)
12402 error (_("MSP430 SYM_DIFF reloc contains invalid symbol index %lu\n"),
12405 saved_sym
= symtab
+ sym_index
;
12408 case 1: /* R_MSP430_32 or R_MSP430_ABS32 */
12409 case 3: /* R_MSP430_16 or R_MSP430_ABS8 */
12410 goto handle_sym_diff
;
12412 case 5: /* R_MSP430_16_BYTE */
12413 case 9: /* R_MSP430_8 */
12414 if (uses_msp430x_relocs (filedata
))
12416 goto handle_sym_diff
;
12418 case 2: /* R_MSP430_ABS16 */
12419 case 15: /* R_MSP430X_ABS16 */
12420 if (! uses_msp430x_relocs (filedata
))
12422 goto handle_sym_diff
;
12425 if (saved_sym
!= NULL
)
12427 int reloc_size
= reloc_type
== 1 ? 4 : 2;
12430 if (sym_index
>= num_syms
)
12431 error (_("MSP430 reloc contains invalid symbol index %lu\n"),
12435 value
= reloc
->r_addend
+ (symtab
[sym_index
].st_value
12436 - saved_sym
->st_value
);
12438 if (IN_RANGE (start
, end
, start
+ reloc
->r_offset
, reloc_size
))
12439 byte_put (start
+ reloc
->r_offset
, value
, reloc_size
);
12442 error (_("MSP430 sym diff reloc contains invalid offset: 0x%lx\n"),
12443 (long) reloc
->r_offset
);
12452 if (saved_sym
!= NULL
)
12453 error (_("Unhandled MSP430 reloc type found after SYM_DIFF reloc\n"));
12460 case EM_CYGNUS_MN10300
:
12462 static Elf_Internal_Sym
* saved_sym
= NULL
;
12470 switch (reloc_type
)
12472 case 34: /* R_MN10300_ALIGN */
12474 case 33: /* R_MN10300_SYM_DIFF */
12475 if (sym_index
>= num_syms
)
12476 error (_("MN10300_SYM_DIFF reloc contains invalid symbol index %lu\n"),
12479 saved_sym
= symtab
+ sym_index
;
12482 case 1: /* R_MN10300_32 */
12483 case 2: /* R_MN10300_16 */
12484 if (saved_sym
!= NULL
)
12486 int reloc_size
= reloc_type
== 1 ? 4 : 2;
12489 if (sym_index
>= num_syms
)
12490 error (_("MN10300 reloc contains invalid symbol index %lu\n"),
12494 value
= reloc
->r_addend
+ (symtab
[sym_index
].st_value
12495 - saved_sym
->st_value
);
12497 if (IN_RANGE (start
, end
, start
+ reloc
->r_offset
, reloc_size
))
12498 byte_put (start
+ reloc
->r_offset
, value
, reloc_size
);
12500 error (_("MN10300 sym diff reloc contains invalid offset: 0x%lx\n"),
12501 (long) reloc
->r_offset
);
12509 if (saved_sym
!= NULL
)
12510 error (_("Unhandled MN10300 reloc type found after SYM_DIFF reloc\n"));
12518 static bfd_vma saved_sym1
= 0;
12519 static bfd_vma saved_sym2
= 0;
12520 static bfd_vma value
;
12524 saved_sym1
= saved_sym2
= 0;
12528 switch (reloc_type
)
12530 case 0x80: /* R_RL78_SYM. */
12531 saved_sym1
= saved_sym2
;
12532 if (sym_index
>= num_syms
)
12533 error (_("RL78_SYM reloc contains invalid symbol index %lu\n"),
12537 saved_sym2
= symtab
[sym_index
].st_value
;
12538 saved_sym2
+= reloc
->r_addend
;
12542 case 0x83: /* R_RL78_OPsub. */
12543 value
= saved_sym1
- saved_sym2
;
12544 saved_sym2
= saved_sym1
= 0;
12548 case 0x41: /* R_RL78_ABS32. */
12549 if (IN_RANGE (start
, end
, start
+ reloc
->r_offset
, 4))
12550 byte_put (start
+ reloc
->r_offset
, value
, 4);
12552 error (_("RL78 sym diff reloc contains invalid offset: 0x%lx\n"),
12553 (long) reloc
->r_offset
);
12557 case 0x43: /* R_RL78_ABS16. */
12558 if (IN_RANGE (start
, end
, start
+ reloc
->r_offset
, 2))
12559 byte_put (start
+ reloc
->r_offset
, value
, 2);
12561 error (_("RL78 sym diff reloc contains invalid offset: 0x%lx\n"),
12562 (long) reloc
->r_offset
);
12576 /* Returns TRUE iff RELOC_TYPE is a 32-bit absolute RELA relocation used in
12577 DWARF debug sections. This is a target specific test. Note - we do not
12578 go through the whole including-target-headers-multiple-times route, (as
12579 we have already done with <elf/h8.h>) because this would become very
12580 messy and even then this function would have to contain target specific
12581 information (the names of the relocs instead of their numeric values).
12582 FIXME: This is not the correct way to solve this problem. The proper way
12583 is to have target specific reloc sizing and typing functions created by
12584 the reloc-macros.h header, in the same way that it already creates the
12585 reloc naming functions. */
12588 is_32bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
12590 /* Please keep this table alpha-sorted for ease of visual lookup. */
12591 switch (filedata
->file_header
.e_machine
)
12595 return reloc_type
== 1; /* R_386_32. */
12597 return reloc_type
== 1; /* R_68K_32. */
12599 return reloc_type
== 1; /* R_860_32. */
12601 return reloc_type
== 2; /* R_960_32. */
12603 return (reloc_type
== 258
12604 || reloc_type
== 1); /* R_AARCH64_ABS32 || R_AARCH64_P32_ABS32 */
12606 return reloc_type
== 11; /* R_BPF_DATA_32 */
12607 case EM_ADAPTEVA_EPIPHANY
:
12608 return reloc_type
== 3;
12610 return reloc_type
== 1; /* R_ALPHA_REFLONG. */
12612 return reloc_type
== 1; /* R_ARC_32. */
12613 case EM_ARC_COMPACT
:
12614 case EM_ARC_COMPACT2
:
12615 return reloc_type
== 4; /* R_ARC_32. */
12617 return reloc_type
== 2; /* R_ARM_ABS32 */
12620 return reloc_type
== 1;
12622 return reloc_type
== 0x12; /* R_byte4_data. */
12624 return reloc_type
== 3; /* R_CRIS_32. */
12626 return reloc_type
== 3; /* R_CR16_NUM32. */
12628 return reloc_type
== 15; /* R_CRX_NUM32. */
12630 return reloc_type
== 1; /* R_CKCORE_ADDR32. */
12631 case EM_CYGNUS_FRV
:
12632 return reloc_type
== 1;
12633 case EM_CYGNUS_D10V
:
12635 return reloc_type
== 6; /* R_D10V_32. */
12636 case EM_CYGNUS_D30V
:
12638 return reloc_type
== 12; /* R_D30V_32_NORMAL. */
12640 return reloc_type
== 3; /* R_DLX_RELOC_32. */
12641 case EM_CYGNUS_FR30
:
12643 return reloc_type
== 3; /* R_FR30_32. */
12645 return reloc_type
== 1; /* R_FT32_32. */
12649 return reloc_type
== 1; /* R_H8_DIR32. */
12651 return (reloc_type
== 0x64 /* R_IA64_SECREL32MSB. */
12652 || reloc_type
== 0x65 /* R_IA64_SECREL32LSB. */
12653 || reloc_type
== 0x24 /* R_IA64_DIR32MSB. */
12654 || reloc_type
== 0x25 /* R_IA64_DIR32LSB. */);
12657 return reloc_type
== 2; /* R_IP2K_32. */
12659 return reloc_type
== 2; /* R_IQ2000_32. */
12660 case EM_LATTICEMICO32
:
12661 return reloc_type
== 3; /* R_LM32_32. */
12664 return reloc_type
== 3; /* R_M32C_32. */
12666 return reloc_type
== 34; /* R_M32R_32_RELA. */
12669 return reloc_type
== 6; /* R_M68HC11_32. */
12671 return reloc_type
== 7 || /* R_S12Z_EXT32 */
12672 reloc_type
== 6; /* R_S12Z_CW32. */
12674 return reloc_type
== 1; /* R_MCORE_ADDR32. */
12675 case EM_CYGNUS_MEP
:
12676 return reloc_type
== 4; /* R_MEP_32. */
12678 return reloc_type
== 2; /* R_METAG_ADDR32. */
12679 case EM_MICROBLAZE
:
12680 return reloc_type
== 1; /* R_MICROBLAZE_32. */
12682 return reloc_type
== 2; /* R_MIPS_32. */
12684 return reloc_type
== 4; /* R_MMIX_32. */
12685 case EM_CYGNUS_MN10200
:
12687 return reloc_type
== 1; /* R_MN10200_32. */
12688 case EM_CYGNUS_MN10300
:
12690 return reloc_type
== 1; /* R_MN10300_32. */
12692 return reloc_type
== 1; /* R_MOXIE_32. */
12693 case EM_MSP430_OLD
:
12695 return reloc_type
== 1; /* R_MSP430_32 or R_MSP320_ABS32. */
12697 return reloc_type
== 2; /* R_MT_32. */
12699 return reloc_type
== 20; /* R_NDS32_RELA. */
12700 case EM_ALTERA_NIOS2
:
12701 return reloc_type
== 12; /* R_NIOS2_BFD_RELOC_32. */
12703 return reloc_type
== 1; /* R_NIOS_32. */
12705 return reloc_type
== 1; /* R_OR1K_32. */
12707 return (reloc_type
== 1 /* R_PARISC_DIR32. */
12708 || reloc_type
== 2 /* R_PARISC_DIR21L. */
12709 || reloc_type
== 41); /* R_PARISC_SECREL32. */
12712 return reloc_type
== 1; /* R_PJ_DATA_DIR32. */
12714 return reloc_type
== 1; /* R_PPC64_ADDR32. */
12716 return reloc_type
== 1; /* R_PPC_ADDR32. */
12718 return reloc_type
== 11; /* R_PRU_BFD_RELOC_32. */
12720 return reloc_type
== 1; /* R_RISCV_32. */
12722 return reloc_type
== 1; /* R_RL78_DIR32. */
12724 return reloc_type
== 1; /* R_RX_DIR32. */
12726 return reloc_type
== 1; /* R_I370_ADDR31. */
12729 return reloc_type
== 4; /* R_S390_32. */
12731 return reloc_type
== 8; /* R_SCORE_ABS32. */
12733 return reloc_type
== 1; /* R_SH_DIR32. */
12734 case EM_SPARC32PLUS
:
12737 return reloc_type
== 3 /* R_SPARC_32. */
12738 || reloc_type
== 23; /* R_SPARC_UA32. */
12740 return reloc_type
== 6; /* R_SPU_ADDR32 */
12742 return reloc_type
== 1; /* R_C6000_ABS32. */
12744 return reloc_type
== 2; /* R_TILEGX_32. */
12746 return reloc_type
== 1; /* R_TILEPRO_32. */
12747 case EM_CYGNUS_V850
:
12749 return reloc_type
== 6; /* R_V850_ABS32. */
12751 return reloc_type
== 0x33; /* R_V810_WORD. */
12753 return reloc_type
== 1; /* R_VAX_32. */
12755 return reloc_type
== 3; /* R_VISIUM_32. */
12756 case EM_WEBASSEMBLY
:
12757 return reloc_type
== 1; /* R_WASM32_32. */
12761 return reloc_type
== 10; /* R_X86_64_32. */
12764 return reloc_type
== 3; /* R_XC16C_ABS_32. */
12766 return reloc_type
== 4; /* R_XGATE_32. */
12768 return reloc_type
== 1; /* R_XSTROMY16_32. */
12769 case EM_XTENSA_OLD
:
12771 return reloc_type
== 1; /* R_XTENSA_32. */
12774 static unsigned int prev_warn
= 0;
12776 /* Avoid repeating the same warning multiple times. */
12777 if (prev_warn
!= filedata
->file_header
.e_machine
)
12778 error (_("Missing knowledge of 32-bit reloc types used in DWARF sections of machine number %d\n"),
12779 filedata
->file_header
.e_machine
);
12780 prev_warn
= filedata
->file_header
.e_machine
;
12786 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
12787 a 32-bit pc-relative RELA relocation used in DWARF debug sections. */
12790 is_32bit_pcrel_reloc (Filedata
* filedata
, unsigned int reloc_type
)
12792 switch (filedata
->file_header
.e_machine
)
12793 /* Please keep this table alpha-sorted for ease of visual lookup. */
12797 return reloc_type
== 2; /* R_386_PC32. */
12799 return reloc_type
== 4; /* R_68K_PC32. */
12801 return reloc_type
== 261; /* R_AARCH64_PREL32 */
12802 case EM_ADAPTEVA_EPIPHANY
:
12803 return reloc_type
== 6;
12805 return reloc_type
== 10; /* R_ALPHA_SREL32. */
12806 case EM_ARC_COMPACT
:
12807 case EM_ARC_COMPACT2
:
12808 return reloc_type
== 49; /* R_ARC_32_PCREL. */
12810 return reloc_type
== 3; /* R_ARM_REL32 */
12813 return reloc_type
== 36; /* R_AVR_32_PCREL. */
12814 case EM_MICROBLAZE
:
12815 return reloc_type
== 2; /* R_MICROBLAZE_32_PCREL. */
12817 return reloc_type
== 9; /* R_OR1K_32_PCREL. */
12819 return reloc_type
== 9; /* R_PARISC_PCREL32. */
12821 return reloc_type
== 26; /* R_PPC_REL32. */
12823 return reloc_type
== 26; /* R_PPC64_REL32. */
12825 return reloc_type
== 57; /* R_RISCV_32_PCREL. */
12828 return reloc_type
== 5; /* R_390_PC32. */
12830 return reloc_type
== 2; /* R_SH_REL32. */
12831 case EM_SPARC32PLUS
:
12834 return reloc_type
== 6; /* R_SPARC_DISP32. */
12836 return reloc_type
== 13; /* R_SPU_REL32. */
12838 return reloc_type
== 6; /* R_TILEGX_32_PCREL. */
12840 return reloc_type
== 4; /* R_TILEPRO_32_PCREL. */
12842 return reloc_type
== 6; /* R_VISIUM_32_PCREL */
12846 return reloc_type
== 2; /* R_X86_64_PC32. */
12848 return reloc_type
== 4; /* R_VAX_PCREL32. */
12849 case EM_XTENSA_OLD
:
12851 return reloc_type
== 14; /* R_XTENSA_32_PCREL. */
12853 /* Do not abort or issue an error message here. Not all targets use
12854 pc-relative 32-bit relocs in their DWARF debug information and we
12855 have already tested for target coverage in is_32bit_abs_reloc. A
12856 more helpful warning message will be generated by apply_relocations
12857 anyway, so just return. */
12862 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
12863 a 64-bit absolute RELA relocation used in DWARF debug sections. */
12866 is_64bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
12868 switch (filedata
->file_header
.e_machine
)
12871 return reloc_type
== 257; /* R_AARCH64_ABS64. */
12873 return reloc_type
== 2; /* R_ALPHA_REFQUAD. */
12875 return (reloc_type
== 0x26 /* R_IA64_DIR64MSB. */
12876 || reloc_type
== 0x27 /* R_IA64_DIR64LSB. */);
12878 return reloc_type
== 80; /* R_PARISC_DIR64. */
12880 return reloc_type
== 38; /* R_PPC64_ADDR64. */
12882 return reloc_type
== 2; /* R_RISCV_64. */
12883 case EM_SPARC32PLUS
:
12886 return reloc_type
== 32 /* R_SPARC_64. */
12887 || reloc_type
== 54; /* R_SPARC_UA64. */
12891 return reloc_type
== 1; /* R_X86_64_64. */
12894 return reloc_type
== 22; /* R_S390_64. */
12896 return reloc_type
== 1; /* R_TILEGX_64. */
12898 return reloc_type
== 18; /* R_MIPS_64. */
12904 /* Like is_32bit_pcrel_reloc except that it returns TRUE iff RELOC_TYPE is
12905 a 64-bit pc-relative RELA relocation used in DWARF debug sections. */
12908 is_64bit_pcrel_reloc (Filedata
* filedata
, unsigned int reloc_type
)
12910 switch (filedata
->file_header
.e_machine
)
12913 return reloc_type
== 260; /* R_AARCH64_PREL64. */
12915 return reloc_type
== 11; /* R_ALPHA_SREL64. */
12917 return (reloc_type
== 0x4e /* R_IA64_PCREL64MSB. */
12918 || reloc_type
== 0x4f /* R_IA64_PCREL64LSB. */);
12920 return reloc_type
== 72; /* R_PARISC_PCREL64. */
12922 return reloc_type
== 44; /* R_PPC64_REL64. */
12923 case EM_SPARC32PLUS
:
12926 return reloc_type
== 46; /* R_SPARC_DISP64. */
12930 return reloc_type
== 24; /* R_X86_64_PC64. */
12933 return reloc_type
== 23; /* R_S390_PC64. */
12935 return reloc_type
== 5; /* R_TILEGX_64_PCREL. */
12941 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
12942 a 24-bit absolute RELA relocation used in DWARF debug sections. */
12945 is_24bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
12947 switch (filedata
->file_header
.e_machine
)
12949 case EM_CYGNUS_MN10200
:
12951 return reloc_type
== 4; /* R_MN10200_24. */
12953 return reloc_type
== 5; /* R_FT32_20. */
12959 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
12960 a 16-bit absolute RELA relocation used in DWARF debug sections. */
12963 is_16bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
12965 /* Please keep this table alpha-sorted for ease of visual lookup. */
12966 switch (filedata
->file_header
.e_machine
)
12969 case EM_ARC_COMPACT
:
12970 case EM_ARC_COMPACT2
:
12971 return reloc_type
== 2; /* R_ARC_16. */
12972 case EM_ADAPTEVA_EPIPHANY
:
12973 return reloc_type
== 5;
12976 return reloc_type
== 4; /* R_AVR_16. */
12977 case EM_CYGNUS_D10V
:
12979 return reloc_type
== 3; /* R_D10V_16. */
12981 return reloc_type
== 2; /* R_FT32_16. */
12985 return reloc_type
== R_H8_DIR16
;
12988 return reloc_type
== 1; /* R_IP2K_16. */
12991 return reloc_type
== 1; /* R_M32C_16 */
12992 case EM_CYGNUS_MN10200
:
12994 return reloc_type
== 2; /* R_MN10200_16. */
12995 case EM_CYGNUS_MN10300
:
12997 return reloc_type
== 2; /* R_MN10300_16. */
12999 if (uses_msp430x_relocs (filedata
))
13000 return reloc_type
== 2; /* R_MSP430_ABS16. */
13001 /* Fall through. */
13002 case EM_MSP430_OLD
:
13003 return reloc_type
== 5; /* R_MSP430_16_BYTE. */
13005 return reloc_type
== 19; /* R_NDS32_RELA. */
13006 case EM_ALTERA_NIOS2
:
13007 return reloc_type
== 13; /* R_NIOS2_BFD_RELOC_16. */
13009 return reloc_type
== 9; /* R_NIOS_16. */
13011 return reloc_type
== 2; /* R_OR1K_16. */
13013 return reloc_type
== 55; /* R_RISCV_SET16. */
13015 return reloc_type
== 8; /* R_PRU_BFD_RELOC_16. */
13017 return reloc_type
== 2; /* R_C6000_ABS16. */
13019 return reloc_type
== 2; /* R_VISIUM_16. */
13022 return reloc_type
== 2; /* R_XC16C_ABS_16. */
13024 return reloc_type
== 3; /* R_XGATE_16. */
13030 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13031 a 8-bit absolute RELA relocation used in DWARF debug sections. */
13034 is_8bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
13036 switch (filedata
->file_header
.e_machine
)
13039 return reloc_type
== 54; /* R_RISCV_SET8. */
13045 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13046 a 6-bit absolute RELA relocation used in DWARF debug sections. */
13049 is_6bit_abs_reloc (Filedata
* filedata
, unsigned int reloc_type
)
13051 switch (filedata
->file_header
.e_machine
)
13054 return reloc_type
== 53; /* R_RISCV_SET6. */
13060 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13061 a 32-bit inplace add RELA relocation used in DWARF debug sections. */
13064 is_32bit_inplace_add_reloc (Filedata
* filedata
, unsigned int reloc_type
)
13066 /* Please keep this table alpha-sorted for ease of visual lookup. */
13067 switch (filedata
->file_header
.e_machine
)
13070 return reloc_type
== 35; /* R_RISCV_ADD32. */
13076 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13077 a 32-bit inplace sub RELA relocation used in DWARF debug sections. */
13080 is_32bit_inplace_sub_reloc (Filedata
* filedata
, unsigned int reloc_type
)
13082 /* Please keep this table alpha-sorted for ease of visual lookup. */
13083 switch (filedata
->file_header
.e_machine
)
13086 return reloc_type
== 39; /* R_RISCV_SUB32. */
13092 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13093 a 64-bit inplace add RELA relocation used in DWARF debug sections. */
13096 is_64bit_inplace_add_reloc (Filedata
* filedata
, unsigned int reloc_type
)
13098 /* Please keep this table alpha-sorted for ease of visual lookup. */
13099 switch (filedata
->file_header
.e_machine
)
13102 return reloc_type
== 36; /* R_RISCV_ADD64. */
13108 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13109 a 64-bit inplace sub RELA relocation used in DWARF debug sections. */
13112 is_64bit_inplace_sub_reloc (Filedata
* filedata
, unsigned int reloc_type
)
13114 /* Please keep this table alpha-sorted for ease of visual lookup. */
13115 switch (filedata
->file_header
.e_machine
)
13118 return reloc_type
== 40; /* R_RISCV_SUB64. */
13124 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13125 a 16-bit inplace add RELA relocation used in DWARF debug sections. */
13128 is_16bit_inplace_add_reloc (Filedata
* filedata
, unsigned int reloc_type
)
13130 /* Please keep this table alpha-sorted for ease of visual lookup. */
13131 switch (filedata
->file_header
.e_machine
)
13134 return reloc_type
== 34; /* R_RISCV_ADD16. */
13140 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13141 a 16-bit inplace sub RELA relocation used in DWARF debug sections. */
13144 is_16bit_inplace_sub_reloc (Filedata
* filedata
, unsigned int reloc_type
)
13146 /* Please keep this table alpha-sorted for ease of visual lookup. */
13147 switch (filedata
->file_header
.e_machine
)
13150 return reloc_type
== 38; /* R_RISCV_SUB16. */
13156 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13157 a 8-bit inplace add RELA relocation used in DWARF debug sections. */
13160 is_8bit_inplace_add_reloc (Filedata
* filedata
, unsigned int reloc_type
)
13162 /* Please keep this table alpha-sorted for ease of visual lookup. */
13163 switch (filedata
->file_header
.e_machine
)
13166 return reloc_type
== 33; /* R_RISCV_ADD8. */
13172 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13173 a 8-bit inplace sub RELA relocation used in DWARF debug sections. */
13176 is_8bit_inplace_sub_reloc (Filedata
* filedata
, unsigned int reloc_type
)
13178 /* Please keep this table alpha-sorted for ease of visual lookup. */
13179 switch (filedata
->file_header
.e_machine
)
13182 return reloc_type
== 37; /* R_RISCV_SUB8. */
13188 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
13189 a 6-bit inplace sub RELA relocation used in DWARF debug sections. */
13192 is_6bit_inplace_sub_reloc (Filedata
* filedata
, unsigned int reloc_type
)
13194 switch (filedata
->file_header
.e_machine
)
13197 return reloc_type
== 52; /* R_RISCV_SUB6. */
13203 /* Returns TRUE iff RELOC_TYPE is a NONE relocation used for discarded
13204 relocation entries (possibly formerly used for SHT_GROUP sections). */
13207 is_none_reloc (Filedata
* filedata
, unsigned int reloc_type
)
13209 switch (filedata
->file_header
.e_machine
)
13211 case EM_386
: /* R_386_NONE. */
13212 case EM_68K
: /* R_68K_NONE. */
13213 case EM_ADAPTEVA_EPIPHANY
:
13214 case EM_ALPHA
: /* R_ALPHA_NONE. */
13215 case EM_ALTERA_NIOS2
: /* R_NIOS2_NONE. */
13216 case EM_ARC
: /* R_ARC_NONE. */
13217 case EM_ARC_COMPACT2
: /* R_ARC_NONE. */
13218 case EM_ARC_COMPACT
: /* R_ARC_NONE. */
13219 case EM_ARM
: /* R_ARM_NONE. */
13220 case EM_C166
: /* R_XC16X_NONE. */
13221 case EM_CRIS
: /* R_CRIS_NONE. */
13222 case EM_FT32
: /* R_FT32_NONE. */
13223 case EM_IA_64
: /* R_IA64_NONE. */
13224 case EM_K1OM
: /* R_X86_64_NONE. */
13225 case EM_L1OM
: /* R_X86_64_NONE. */
13226 case EM_M32R
: /* R_M32R_NONE. */
13227 case EM_MIPS
: /* R_MIPS_NONE. */
13228 case EM_MN10300
: /* R_MN10300_NONE. */
13229 case EM_MOXIE
: /* R_MOXIE_NONE. */
13230 case EM_NIOS32
: /* R_NIOS_NONE. */
13231 case EM_OR1K
: /* R_OR1K_NONE. */
13232 case EM_PARISC
: /* R_PARISC_NONE. */
13233 case EM_PPC64
: /* R_PPC64_NONE. */
13234 case EM_PPC
: /* R_PPC_NONE. */
13235 case EM_RISCV
: /* R_RISCV_NONE. */
13236 case EM_S390
: /* R_390_NONE. */
13238 case EM_SH
: /* R_SH_NONE. */
13239 case EM_SPARC32PLUS
:
13240 case EM_SPARC
: /* R_SPARC_NONE. */
13242 case EM_TILEGX
: /* R_TILEGX_NONE. */
13243 case EM_TILEPRO
: /* R_TILEPRO_NONE. */
13244 case EM_TI_C6000
:/* R_C6000_NONE. */
13245 case EM_X86_64
: /* R_X86_64_NONE. */
13247 case EM_WEBASSEMBLY
: /* R_WASM32_NONE. */
13248 return reloc_type
== 0;
13251 return reloc_type
== 0 || reloc_type
== 256;
13254 return (reloc_type
== 0 /* R_AVR_NONE. */
13255 || reloc_type
== 30 /* R_AVR_DIFF8. */
13256 || reloc_type
== 31 /* R_AVR_DIFF16. */
13257 || reloc_type
== 32 /* R_AVR_DIFF32. */);
13259 return reloc_type
== 3; /* R_METAG_NONE. */
13261 return (reloc_type
== 0 /* R_XTENSA_NONE. */
13262 || reloc_type
== 204 /* R_NDS32_DIFF8. */
13263 || reloc_type
== 205 /* R_NDS32_DIFF16. */
13264 || reloc_type
== 206 /* R_NDS32_DIFF32. */
13265 || reloc_type
== 207 /* R_NDS32_ULEB128. */);
13267 return (reloc_type
== 0 /* R_PRU_NONE. */
13268 || reloc_type
== 65 /* R_PRU_DIFF8. */
13269 || reloc_type
== 66 /* R_PRU_DIFF16. */
13270 || reloc_type
== 67 /* R_PRU_DIFF32. */);
13271 case EM_XTENSA_OLD
:
13273 return (reloc_type
== 0 /* R_XTENSA_NONE. */
13274 || reloc_type
== 17 /* R_XTENSA_DIFF8. */
13275 || reloc_type
== 18 /* R_XTENSA_DIFF16. */
13276 || reloc_type
== 19 /* R_XTENSA_DIFF32. */);
13281 /* Returns TRUE if there is a relocation against
13282 section NAME at OFFSET bytes. */
13285 reloc_at (struct dwarf_section
* dsec
, dwarf_vma offset
)
13287 Elf_Internal_Rela
* relocs
;
13288 Elf_Internal_Rela
* rp
;
13290 if (dsec
== NULL
|| dsec
->reloc_info
== NULL
)
13293 relocs
= (Elf_Internal_Rela
*) dsec
->reloc_info
;
13295 for (rp
= relocs
; rp
< relocs
+ dsec
->num_relocs
; ++rp
)
13296 if (rp
->r_offset
== offset
)
13302 /* Apply relocations to a section.
13303 Returns TRUE upon success, FALSE otherwise.
13304 If RELOCS_RETURN is non-NULL then it is set to point to the loaded relocs.
13305 It is then the caller's responsibility to free them. NUM_RELOCS_RETURN
13306 will be set to the number of relocs loaded.
13308 Note: So far support has been added only for those relocations
13309 which can be found in debug sections. FIXME: Add support for
13310 more relocations ? */
13313 apply_relocations (Filedata
* filedata
,
13314 const Elf_Internal_Shdr
* section
,
13315 unsigned char * start
,
13316 bfd_size_type size
,
13317 void ** relocs_return
,
13318 unsigned long * num_relocs_return
)
13320 Elf_Internal_Shdr
* relsec
;
13321 unsigned char * end
= start
+ size
;
13323 if (relocs_return
!= NULL
)
13325 * (Elf_Internal_Rela
**) relocs_return
= NULL
;
13326 * num_relocs_return
= 0;
13329 if (filedata
->file_header
.e_type
!= ET_REL
)
13330 /* No relocs to apply. */
13333 /* Find the reloc section associated with the section. */
13334 for (relsec
= filedata
->section_headers
;
13335 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
13338 bfd_boolean is_rela
;
13339 unsigned long num_relocs
;
13340 Elf_Internal_Rela
* relocs
;
13341 Elf_Internal_Rela
* rp
;
13342 Elf_Internal_Shdr
* symsec
;
13343 Elf_Internal_Sym
* symtab
;
13344 unsigned long num_syms
;
13345 Elf_Internal_Sym
* sym
;
13347 if ((relsec
->sh_type
!= SHT_RELA
&& relsec
->sh_type
!= SHT_REL
)
13348 || relsec
->sh_info
>= filedata
->file_header
.e_shnum
13349 || filedata
->section_headers
+ relsec
->sh_info
!= section
13350 || relsec
->sh_size
== 0
13351 || relsec
->sh_link
>= filedata
->file_header
.e_shnum
)
13354 is_rela
= relsec
->sh_type
== SHT_RELA
;
13358 if (!slurp_rela_relocs (filedata
, relsec
->sh_offset
,
13359 relsec
->sh_size
, & relocs
, & num_relocs
))
13364 if (!slurp_rel_relocs (filedata
, relsec
->sh_offset
,
13365 relsec
->sh_size
, & relocs
, & num_relocs
))
13369 /* SH uses RELA but uses in place value instead of the addend field. */
13370 if (filedata
->file_header
.e_machine
== EM_SH
)
13373 symsec
= filedata
->section_headers
+ relsec
->sh_link
;
13374 if (symsec
->sh_type
!= SHT_SYMTAB
13375 && symsec
->sh_type
!= SHT_DYNSYM
)
13377 symtab
= GET_ELF_SYMBOLS (filedata
, symsec
, & num_syms
);
13379 for (rp
= relocs
; rp
< relocs
+ num_relocs
; ++rp
)
13382 unsigned int reloc_type
;
13383 unsigned int reloc_size
;
13384 bfd_boolean reloc_inplace
= FALSE
;
13385 bfd_boolean reloc_subtract
= FALSE
;
13386 unsigned char * rloc
;
13387 unsigned long sym_index
;
13389 reloc_type
= get_reloc_type (filedata
, rp
->r_info
);
13391 if (target_specific_reloc_handling (filedata
, rp
, start
, end
, symtab
, num_syms
))
13393 else if (is_none_reloc (filedata
, reloc_type
))
13395 else if (is_32bit_abs_reloc (filedata
, reloc_type
)
13396 || is_32bit_pcrel_reloc (filedata
, reloc_type
))
13398 else if (is_64bit_abs_reloc (filedata
, reloc_type
)
13399 || is_64bit_pcrel_reloc (filedata
, reloc_type
))
13401 else if (is_24bit_abs_reloc (filedata
, reloc_type
))
13403 else if (is_16bit_abs_reloc (filedata
, reloc_type
))
13405 else if (is_8bit_abs_reloc (filedata
, reloc_type
)
13406 || is_6bit_abs_reloc (filedata
, reloc_type
))
13408 else if ((reloc_subtract
= is_32bit_inplace_sub_reloc (filedata
,
13410 || is_32bit_inplace_add_reloc (filedata
, reloc_type
))
13413 reloc_inplace
= TRUE
;
13415 else if ((reloc_subtract
= is_64bit_inplace_sub_reloc (filedata
,
13417 || is_64bit_inplace_add_reloc (filedata
, reloc_type
))
13420 reloc_inplace
= TRUE
;
13422 else if ((reloc_subtract
= is_16bit_inplace_sub_reloc (filedata
,
13424 || is_16bit_inplace_add_reloc (filedata
, reloc_type
))
13427 reloc_inplace
= TRUE
;
13429 else if ((reloc_subtract
= is_8bit_inplace_sub_reloc (filedata
,
13431 || is_8bit_inplace_add_reloc (filedata
, reloc_type
))
13434 reloc_inplace
= TRUE
;
13436 else if ((reloc_subtract
= is_6bit_inplace_sub_reloc (filedata
,
13440 reloc_inplace
= TRUE
;
13444 static unsigned int prev_reloc
= 0;
13446 if (reloc_type
!= prev_reloc
)
13447 warn (_("unable to apply unsupported reloc type %d to section %s\n"),
13448 reloc_type
, printable_section_name (filedata
, section
));
13449 prev_reloc
= reloc_type
;
13453 rloc
= start
+ rp
->r_offset
;
13454 if (!IN_RANGE (start
, end
, rloc
, reloc_size
))
13456 warn (_("skipping invalid relocation offset 0x%lx in section %s\n"),
13457 (unsigned long) rp
->r_offset
,
13458 printable_section_name (filedata
, section
));
13462 sym_index
= (unsigned long) get_reloc_symindex (rp
->r_info
);
13463 if (sym_index
>= num_syms
)
13465 warn (_("skipping invalid relocation symbol index 0x%lx in section %s\n"),
13466 sym_index
, printable_section_name (filedata
, section
));
13469 sym
= symtab
+ sym_index
;
13471 /* If the reloc has a symbol associated with it,
13472 make sure that it is of an appropriate type.
13474 Relocations against symbols without type can happen.
13475 Gcc -feliminate-dwarf2-dups may generate symbols
13476 without type for debug info.
13478 Icc generates relocations against function symbols
13479 instead of local labels.
13481 Relocations against object symbols can happen, eg when
13482 referencing a global array. For an example of this see
13483 the _clz.o binary in libgcc.a. */
13485 && ELF_ST_TYPE (sym
->st_info
) != STT_COMMON
13486 && ELF_ST_TYPE (sym
->st_info
) > STT_SECTION
)
13488 warn (_("skipping unexpected symbol type %s in section %s relocation %ld\n"),
13489 get_symbol_type (filedata
, ELF_ST_TYPE (sym
->st_info
)),
13490 printable_section_name (filedata
, relsec
),
13491 (long int)(rp
- relocs
));
13497 addend
+= rp
->r_addend
;
13498 /* R_XTENSA_32, R_PJ_DATA_DIR32 and R_D30V_32_NORMAL are
13499 partial_inplace. */
13501 || (filedata
->file_header
.e_machine
== EM_XTENSA
13502 && reloc_type
== 1)
13503 || ((filedata
->file_header
.e_machine
== EM_PJ
13504 || filedata
->file_header
.e_machine
== EM_PJ_OLD
)
13505 && reloc_type
== 1)
13506 || ((filedata
->file_header
.e_machine
== EM_D30V
13507 || filedata
->file_header
.e_machine
== EM_CYGNUS_D30V
)
13508 && reloc_type
== 12)
13511 if (is_6bit_inplace_sub_reloc (filedata
, reloc_type
))
13512 addend
+= byte_get (rloc
, reloc_size
) & 0x3f;
13514 addend
+= byte_get (rloc
, reloc_size
);
13517 if (is_32bit_pcrel_reloc (filedata
, reloc_type
)
13518 || is_64bit_pcrel_reloc (filedata
, reloc_type
))
13520 /* On HPPA, all pc-relative relocations are biased by 8. */
13521 if (filedata
->file_header
.e_machine
== EM_PARISC
)
13523 byte_put (rloc
, (addend
+ sym
->st_value
) - rp
->r_offset
,
13526 else if (is_6bit_abs_reloc (filedata
, reloc_type
)
13527 || is_6bit_inplace_sub_reloc (filedata
, reloc_type
))
13529 if (reloc_subtract
)
13530 addend
-= sym
->st_value
;
13532 addend
+= sym
->st_value
;
13533 addend
= (addend
& 0x3f) | (byte_get (rloc
, reloc_size
) & 0xc0);
13534 byte_put (rloc
, addend
, reloc_size
);
13536 else if (reloc_subtract
)
13537 byte_put (rloc
, addend
- sym
->st_value
, reloc_size
);
13539 byte_put (rloc
, addend
+ sym
->st_value
, reloc_size
);
13543 /* Let the target specific reloc processing code know that
13544 we have finished with these relocs. */
13545 target_specific_reloc_handling (filedata
, NULL
, NULL
, NULL
, NULL
, 0);
13549 * (Elf_Internal_Rela
**) relocs_return
= relocs
;
13550 * num_relocs_return
= num_relocs
;
13561 #ifdef SUPPORT_DISASSEMBLY
13563 disassemble_section (Elf_Internal_Shdr
* section
, Filedata
* filedata
)
13565 printf (_("\nAssembly dump of section %s\n"), printable_section_name (filedata
, section
));
13567 /* FIXME: XXX -- to be done --- XXX */
13573 /* Reads in the contents of SECTION from FILE, returning a pointer
13574 to a malloc'ed buffer or NULL if something went wrong. */
13577 get_section_contents (Elf_Internal_Shdr
* section
, Filedata
* filedata
)
13579 bfd_size_type num_bytes
= section
->sh_size
;
13581 if (num_bytes
== 0 || section
->sh_type
== SHT_NOBITS
)
13583 printf (_("Section '%s' has no data to dump.\n"),
13584 printable_section_name (filedata
, section
));
13588 return (char *) get_data (NULL
, filedata
, section
->sh_offset
, 1, num_bytes
,
13589 _("section contents"));
13592 /* Uncompresses a section that was compressed using zlib, in place. */
13595 uncompress_section_contents (unsigned char ** buffer
,
13596 dwarf_size_type uncompressed_size
,
13597 dwarf_size_type
* size
)
13599 dwarf_size_type compressed_size
= *size
;
13600 unsigned char * compressed_buffer
= *buffer
;
13601 unsigned char * uncompressed_buffer
;
13605 /* It is possible the section consists of several compressed
13606 buffers concatenated together, so we uncompress in a loop. */
13607 /* PR 18313: The state field in the z_stream structure is supposed
13608 to be invisible to the user (ie us), but some compilers will
13609 still complain about it being used without initialisation. So
13610 we first zero the entire z_stream structure and then set the fields
13612 memset (& strm
, 0, sizeof strm
);
13613 strm
.avail_in
= compressed_size
;
13614 strm
.next_in
= (Bytef
*) compressed_buffer
;
13615 strm
.avail_out
= uncompressed_size
;
13616 uncompressed_buffer
= (unsigned char *) xmalloc (uncompressed_size
);
13618 rc
= inflateInit (& strm
);
13619 while (strm
.avail_in
> 0)
13623 strm
.next_out
= ((Bytef
*) uncompressed_buffer
13624 + (uncompressed_size
- strm
.avail_out
));
13625 rc
= inflate (&strm
, Z_FINISH
);
13626 if (rc
!= Z_STREAM_END
)
13628 rc
= inflateReset (& strm
);
13630 rc
= inflateEnd (& strm
);
13632 || strm
.avail_out
!= 0)
13635 *buffer
= uncompressed_buffer
;
13636 *size
= uncompressed_size
;
13640 free (uncompressed_buffer
);
13641 /* Indicate decompression failure. */
13647 dump_section_as_strings (Elf_Internal_Shdr
* section
, Filedata
* filedata
)
13649 Elf_Internal_Shdr
* relsec
;
13650 bfd_size_type num_bytes
;
13651 unsigned char * data
;
13652 unsigned char * end
;
13653 unsigned char * real_start
;
13654 unsigned char * start
;
13655 bfd_boolean some_strings_shown
;
13657 real_start
= start
= (unsigned char *) get_section_contents (section
, filedata
);
13659 /* PR 21820: Do not fail if the section was empty. */
13660 return (section
->sh_size
== 0 || section
->sh_type
== SHT_NOBITS
) ? TRUE
: FALSE
;
13662 num_bytes
= section
->sh_size
;
13664 printf (_("\nString dump of section '%s':\n"), printable_section_name (filedata
, section
));
13666 if (decompress_dumps
)
13668 dwarf_size_type new_size
= num_bytes
;
13669 dwarf_size_type uncompressed_size
= 0;
13671 if ((section
->sh_flags
& SHF_COMPRESSED
) != 0)
13673 Elf_Internal_Chdr chdr
;
13674 unsigned int compression_header_size
13675 = get_compression_header (& chdr
, (unsigned char *) start
,
13678 if (chdr
.ch_type
!= ELFCOMPRESS_ZLIB
)
13680 warn (_("section '%s' has unsupported compress type: %d\n"),
13681 printable_section_name (filedata
, section
), chdr
.ch_type
);
13684 uncompressed_size
= chdr
.ch_size
;
13685 start
+= compression_header_size
;
13686 new_size
-= compression_header_size
;
13688 else if (new_size
> 12 && streq ((char *) start
, "ZLIB"))
13690 /* Read the zlib header. In this case, it should be "ZLIB"
13691 followed by the uncompressed section size, 8 bytes in
13692 big-endian order. */
13693 uncompressed_size
= start
[4]; uncompressed_size
<<= 8;
13694 uncompressed_size
+= start
[5]; uncompressed_size
<<= 8;
13695 uncompressed_size
+= start
[6]; uncompressed_size
<<= 8;
13696 uncompressed_size
+= start
[7]; uncompressed_size
<<= 8;
13697 uncompressed_size
+= start
[8]; uncompressed_size
<<= 8;
13698 uncompressed_size
+= start
[9]; uncompressed_size
<<= 8;
13699 uncompressed_size
+= start
[10]; uncompressed_size
<<= 8;
13700 uncompressed_size
+= start
[11];
13705 if (uncompressed_size
)
13707 if (uncompress_section_contents (& start
,
13708 uncompressed_size
, & new_size
))
13709 num_bytes
= new_size
;
13712 error (_("Unable to decompress section %s\n"),
13713 printable_section_name (filedata
, section
));
13718 start
= real_start
;
13721 /* If the section being dumped has relocations against it the user might
13722 be expecting these relocations to have been applied. Check for this
13723 case and issue a warning message in order to avoid confusion.
13724 FIXME: Maybe we ought to have an option that dumps a section with
13725 relocs applied ? */
13726 for (relsec
= filedata
->section_headers
;
13727 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
13730 if ((relsec
->sh_type
!= SHT_RELA
&& relsec
->sh_type
!= SHT_REL
)
13731 || relsec
->sh_info
>= filedata
->file_header
.e_shnum
13732 || filedata
->section_headers
+ relsec
->sh_info
!= section
13733 || relsec
->sh_size
== 0
13734 || relsec
->sh_link
>= filedata
->file_header
.e_shnum
)
13737 printf (_(" Note: This section has relocations against it, but these have NOT been applied to this dump.\n"));
13742 end
= start
+ num_bytes
;
13743 some_strings_shown
= FALSE
;
13747 while (!ISPRINT (* data
))
13748 if (++ data
>= end
)
13753 size_t maxlen
= end
- data
;
13756 /* PR 11128: Use two separate invocations in order to work
13757 around bugs in the Solaris 8 implementation of printf. */
13758 printf (" [%6tx] ", data
- start
);
13760 printf (" [%6Ix] ", (size_t) (data
- start
));
13764 print_symbol ((int) maxlen
, (const char *) data
);
13766 data
+= strnlen ((const char *) data
, maxlen
);
13770 printf (_("<corrupt>\n"));
13773 some_strings_shown
= TRUE
;
13777 if (! some_strings_shown
)
13778 printf (_(" No strings found in this section."));
13787 dump_section_as_bytes (Elf_Internal_Shdr
* section
,
13788 Filedata
* filedata
,
13789 bfd_boolean relocate
)
13791 Elf_Internal_Shdr
* relsec
;
13792 bfd_size_type bytes
;
13793 bfd_size_type section_size
;
13795 unsigned char * data
;
13796 unsigned char * real_start
;
13797 unsigned char * start
;
13799 real_start
= start
= (unsigned char *) get_section_contents (section
, filedata
);
13801 /* PR 21820: Do not fail if the section was empty. */
13802 return (section
->sh_size
== 0 || section
->sh_type
== SHT_NOBITS
) ? TRUE
: FALSE
;
13804 section_size
= section
->sh_size
;
13806 printf (_("\nHex dump of section '%s':\n"), printable_section_name (filedata
, section
));
13808 if (decompress_dumps
)
13810 dwarf_size_type new_size
= section_size
;
13811 dwarf_size_type uncompressed_size
= 0;
13813 if ((section
->sh_flags
& SHF_COMPRESSED
) != 0)
13815 Elf_Internal_Chdr chdr
;
13816 unsigned int compression_header_size
13817 = get_compression_header (& chdr
, start
, section_size
);
13819 if (chdr
.ch_type
!= ELFCOMPRESS_ZLIB
)
13821 warn (_("section '%s' has unsupported compress type: %d\n"),
13822 printable_section_name (filedata
, section
), chdr
.ch_type
);
13825 uncompressed_size
= chdr
.ch_size
;
13826 start
+= compression_header_size
;
13827 new_size
-= compression_header_size
;
13829 else if (new_size
> 12 && streq ((char *) start
, "ZLIB"))
13831 /* Read the zlib header. In this case, it should be "ZLIB"
13832 followed by the uncompressed section size, 8 bytes in
13833 big-endian order. */
13834 uncompressed_size
= start
[4]; uncompressed_size
<<= 8;
13835 uncompressed_size
+= start
[5]; uncompressed_size
<<= 8;
13836 uncompressed_size
+= start
[6]; uncompressed_size
<<= 8;
13837 uncompressed_size
+= start
[7]; uncompressed_size
<<= 8;
13838 uncompressed_size
+= start
[8]; uncompressed_size
<<= 8;
13839 uncompressed_size
+= start
[9]; uncompressed_size
<<= 8;
13840 uncompressed_size
+= start
[10]; uncompressed_size
<<= 8;
13841 uncompressed_size
+= start
[11];
13846 if (uncompressed_size
)
13848 if (uncompress_section_contents (& start
, uncompressed_size
,
13851 section_size
= new_size
;
13855 error (_("Unable to decompress section %s\n"),
13856 printable_section_name (filedata
, section
));
13857 /* FIXME: Print the section anyway ? */
13862 start
= real_start
;
13867 if (! apply_relocations (filedata
, section
, start
, section_size
, NULL
, NULL
))
13872 /* If the section being dumped has relocations against it the user might
13873 be expecting these relocations to have been applied. Check for this
13874 case and issue a warning message in order to avoid confusion.
13875 FIXME: Maybe we ought to have an option that dumps a section with
13876 relocs applied ? */
13877 for (relsec
= filedata
->section_headers
;
13878 relsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
13881 if ((relsec
->sh_type
!= SHT_RELA
&& relsec
->sh_type
!= SHT_REL
)
13882 || relsec
->sh_info
>= filedata
->file_header
.e_shnum
13883 || filedata
->section_headers
+ relsec
->sh_info
!= section
13884 || relsec
->sh_size
== 0
13885 || relsec
->sh_link
>= filedata
->file_header
.e_shnum
)
13888 printf (_(" NOTE: This section has relocations against it, but these have NOT been applied to this dump.\n"));
13893 addr
= section
->sh_addr
;
13894 bytes
= section_size
;
13903 lbytes
= (bytes
> 16 ? 16 : bytes
);
13905 printf (" 0x%8.8lx ", (unsigned long) addr
);
13907 for (j
= 0; j
< 16; j
++)
13910 printf ("%2.2x", data
[j
]);
13918 for (j
= 0; j
< lbytes
; j
++)
13921 if (k
>= ' ' && k
< 0x7f)
13940 static ctf_sect_t
*
13941 shdr_to_ctf_sect (ctf_sect_t
*buf
, Elf_Internal_Shdr
*shdr
, Filedata
*filedata
)
13943 buf
->cts_name
= SECTION_NAME (shdr
);
13944 buf
->cts_size
= shdr
->sh_size
;
13945 buf
->cts_entsize
= shdr
->sh_entsize
;
13950 /* Formatting callback function passed to ctf_dump. Returns either the pointer
13951 it is passed, or a pointer to newly-allocated storage, in which case
13952 dump_ctf() will free it when it no longer needs it. */
13954 static char *dump_ctf_indent_lines (ctf_sect_names_t sect ATTRIBUTE_UNUSED
,
13955 char *s
, void *arg
)
13957 const char *blanks
= arg
;
13960 if (asprintf (&new_s
, "%s%s", blanks
, s
) < 0)
13966 dump_section_as_ctf (Elf_Internal_Shdr
* section
, Filedata
* filedata
)
13968 Elf_Internal_Shdr
* parent_sec
= NULL
;
13969 Elf_Internal_Shdr
* symtab_sec
= NULL
;
13970 Elf_Internal_Shdr
* strtab_sec
= NULL
;
13971 void * data
= NULL
;
13972 void * symdata
= NULL
;
13973 void * strdata
= NULL
;
13974 void * parentdata
= NULL
;
13975 ctf_sect_t ctfsect
, symsect
, strsect
, parentsect
;
13976 ctf_sect_t
* symsectp
= NULL
;
13977 ctf_sect_t
* strsectp
= NULL
;
13978 ctf_file_t
* ctf
= NULL
;
13979 ctf_file_t
* parent
= NULL
;
13981 const char *things
[] = {"Header", "Labels", "Data objects",
13982 "Function objects", "Variables", "Types", "Strings",
13984 const char **thing
;
13986 bfd_boolean ret
= FALSE
;
13989 shdr_to_ctf_sect (&ctfsect
, section
, filedata
);
13990 data
= get_section_contents (section
, filedata
);
13991 ctfsect
.cts_data
= data
;
13993 if (!dump_ctf_symtab_name
)
13994 dump_ctf_symtab_name
= strdup (".symtab");
13996 if (!dump_ctf_strtab_name
)
13997 dump_ctf_strtab_name
= strdup (".strtab");
13999 if (dump_ctf_symtab_name
&& dump_ctf_symtab_name
[0] != 0)
14001 if ((symtab_sec
= find_section (filedata
, dump_ctf_symtab_name
)) == NULL
)
14003 error (_("No symbol section named %s\n"), dump_ctf_symtab_name
);
14006 if ((symdata
= (void *) get_data (NULL
, filedata
,
14007 symtab_sec
->sh_offset
, 1,
14008 symtab_sec
->sh_size
,
14009 _("symbols"))) == NULL
)
14011 symsectp
= shdr_to_ctf_sect (&symsect
, symtab_sec
, filedata
);
14012 symsect
.cts_data
= symdata
;
14014 if (dump_ctf_strtab_name
&& dump_ctf_symtab_name
[0] != 0)
14016 if ((strtab_sec
= find_section (filedata
, dump_ctf_strtab_name
)) == NULL
)
14018 error (_("No string table section named %s\n"),
14019 dump_ctf_strtab_name
);
14022 if ((strdata
= (void *) get_data (NULL
, filedata
,
14023 strtab_sec
->sh_offset
, 1,
14024 strtab_sec
->sh_size
,
14025 _("strings"))) == NULL
)
14027 strsectp
= shdr_to_ctf_sect (&strsect
, strtab_sec
, filedata
);
14028 strsect
.cts_data
= strdata
;
14030 if (dump_ctf_parent_name
)
14032 if ((parent_sec
= find_section (filedata
, dump_ctf_parent_name
)) == NULL
)
14034 error (_("No CTF parent section named %s\n"), dump_ctf_parent_name
);
14037 if ((parentdata
= (void *) get_data (NULL
, filedata
,
14038 parent_sec
->sh_offset
, 1,
14039 parent_sec
->sh_size
,
14040 _("CTF parent"))) == NULL
)
14042 shdr_to_ctf_sect (&parentsect
, parent_sec
, filedata
);
14043 parentsect
.cts_data
= parentdata
;
14046 /* Load the CTF file and dump it. */
14048 if ((ctf
= ctf_bufopen (&ctfsect
, symsectp
, strsectp
, &err
)) == NULL
)
14050 error (_("CTF open failure: %s\n"), ctf_errmsg (err
));
14056 if ((parent
= ctf_bufopen (&parentsect
, symsectp
, strsectp
, &err
)) == NULL
)
14058 error (_("CTF open failure: %s\n"), ctf_errmsg (err
));
14062 ctf_import (ctf
, parent
);
14067 printf (_("\nDump of CTF section '%s':\n"),
14068 printable_section_name (filedata
, section
));
14070 for (i
= 0, thing
= things
; *thing
[0]; thing
++, i
++)
14072 ctf_dump_state_t
*s
= NULL
;
14075 printf ("\n %s:\n", *thing
);
14076 while ((item
= ctf_dump (ctf
, &s
, i
, dump_ctf_indent_lines
,
14077 (void *) " ")) != NULL
)
14079 printf ("%s\n", item
);
14083 if (ctf_errno (ctf
))
14085 error (_("Iteration failed: %s, %s\n"), *thing
,
14086 ctf_errmsg (ctf_errno (ctf
)));
14092 ctf_file_close (ctf
);
14093 ctf_file_close (parent
);
14102 load_specific_debug_section (enum dwarf_section_display_enum debug
,
14103 const Elf_Internal_Shdr
* sec
,
14106 struct dwarf_section
* section
= &debug_displays
[debug
].section
;
14108 Filedata
* filedata
= (Filedata
*) data
;
14110 if (section
->start
!= NULL
)
14112 /* If it is already loaded, do nothing. */
14113 if (streq (section
->filename
, filedata
->file_name
))
14115 free (section
->start
);
14118 snprintf (buf
, sizeof (buf
), _("%s section data"), section
->name
);
14119 section
->address
= sec
->sh_addr
;
14120 section
->user_data
= NULL
;
14121 section
->filename
= filedata
->file_name
;
14122 section
->start
= (unsigned char *) get_data (NULL
, filedata
,
14124 sec
->sh_size
, buf
);
14125 if (section
->start
== NULL
)
14129 unsigned char *start
= section
->start
;
14130 dwarf_size_type size
= sec
->sh_size
;
14131 dwarf_size_type uncompressed_size
= 0;
14133 if ((sec
->sh_flags
& SHF_COMPRESSED
) != 0)
14135 Elf_Internal_Chdr chdr
;
14136 unsigned int compression_header_size
;
14138 if (size
< (is_32bit_elf
14139 ? sizeof (Elf32_External_Chdr
)
14140 : sizeof (Elf64_External_Chdr
)))
14142 warn (_("compressed section %s is too small to contain a compression header"),
14147 compression_header_size
= get_compression_header (&chdr
, start
, size
);
14149 if (chdr
.ch_type
!= ELFCOMPRESS_ZLIB
)
14151 warn (_("section '%s' has unsupported compress type: %d\n"),
14152 section
->name
, chdr
.ch_type
);
14155 uncompressed_size
= chdr
.ch_size
;
14156 start
+= compression_header_size
;
14157 size
-= compression_header_size
;
14159 else if (size
> 12 && streq ((char *) start
, "ZLIB"))
14161 /* Read the zlib header. In this case, it should be "ZLIB"
14162 followed by the uncompressed section size, 8 bytes in
14163 big-endian order. */
14164 uncompressed_size
= start
[4]; uncompressed_size
<<= 8;
14165 uncompressed_size
+= start
[5]; uncompressed_size
<<= 8;
14166 uncompressed_size
+= start
[6]; uncompressed_size
<<= 8;
14167 uncompressed_size
+= start
[7]; uncompressed_size
<<= 8;
14168 uncompressed_size
+= start
[8]; uncompressed_size
<<= 8;
14169 uncompressed_size
+= start
[9]; uncompressed_size
<<= 8;
14170 uncompressed_size
+= start
[10]; uncompressed_size
<<= 8;
14171 uncompressed_size
+= start
[11];
14176 if (uncompressed_size
)
14178 if (uncompress_section_contents (&start
, uncompressed_size
,
14181 /* Free the compressed buffer, update the section buffer
14182 and the section size if uncompress is successful. */
14183 free (section
->start
);
14184 section
->start
= start
;
14188 error (_("Unable to decompress section %s\n"),
14189 printable_section_name (filedata
, sec
));
14194 section
->size
= size
;
14197 if (section
->start
== NULL
)
14200 if (debug_displays
[debug
].relocate
)
14202 if (! apply_relocations (filedata
, sec
, section
->start
, section
->size
,
14203 & section
->reloc_info
, & section
->num_relocs
))
14208 section
->reloc_info
= NULL
;
14209 section
->num_relocs
= 0;
14215 /* If this is not NULL, load_debug_section will only look for sections
14216 within the list of sections given here. */
14217 static unsigned int * section_subset
= NULL
;
14220 load_debug_section (enum dwarf_section_display_enum debug
, void * data
)
14222 struct dwarf_section
* section
= &debug_displays
[debug
].section
;
14223 Elf_Internal_Shdr
* sec
;
14224 Filedata
* filedata
= (Filedata
*) data
;
14226 /* Without section headers we cannot find any sections. */
14227 if (filedata
->section_headers
== NULL
)
14230 if (filedata
->string_table
== NULL
14231 && filedata
->file_header
.e_shstrndx
!= SHN_UNDEF
14232 && filedata
->file_header
.e_shstrndx
< filedata
->file_header
.e_shnum
)
14234 Elf_Internal_Shdr
* strs
;
14236 /* Read in the string table, so that we have section names to scan. */
14237 strs
= filedata
->section_headers
+ filedata
->file_header
.e_shstrndx
;
14239 if (strs
!= NULL
&& strs
->sh_size
!= 0)
14241 filedata
->string_table
14242 = (char *) get_data (NULL
, filedata
, strs
->sh_offset
,
14243 1, strs
->sh_size
, _("string table"));
14245 filedata
->string_table_length
14246 = filedata
->string_table
!= NULL
? strs
->sh_size
: 0;
14250 /* Locate the debug section. */
14251 sec
= find_section_in_set (filedata
, section
->uncompressed_name
, section_subset
);
14253 section
->name
= section
->uncompressed_name
;
14256 sec
= find_section_in_set (filedata
, section
->compressed_name
, section_subset
);
14258 section
->name
= section
->compressed_name
;
14263 /* If we're loading from a subset of sections, and we've loaded
14264 a section matching this name before, it's likely that it's a
14266 if (section_subset
!= NULL
)
14267 free_debug_section (debug
);
14269 return load_specific_debug_section (debug
, sec
, data
);
14273 free_debug_section (enum dwarf_section_display_enum debug
)
14275 struct dwarf_section
* section
= &debug_displays
[debug
].section
;
14277 if (section
->start
== NULL
)
14280 free ((char *) section
->start
);
14281 section
->start
= NULL
;
14282 section
->address
= 0;
14287 display_debug_section (int shndx
, Elf_Internal_Shdr
* section
, Filedata
* filedata
)
14289 char * name
= SECTION_NAME (section
);
14290 const char * print_name
= printable_section_name (filedata
, section
);
14291 bfd_size_type length
;
14292 bfd_boolean result
= TRUE
;
14295 length
= section
->sh_size
;
14298 printf (_("\nSection '%s' has no debugging data.\n"), print_name
);
14301 if (section
->sh_type
== SHT_NOBITS
)
14303 /* There is no point in dumping the contents of a debugging section
14304 which has the NOBITS type - the bits in the file will be random.
14305 This can happen when a file containing a .eh_frame section is
14306 stripped with the --only-keep-debug command line option. */
14307 printf (_("section '%s' has the NOBITS type - its contents are unreliable.\n"),
14312 if (const_strneq (name
, ".gnu.linkonce.wi."))
14313 name
= ".debug_info";
14315 /* See if we know how to display the contents of this section. */
14316 for (i
= 0; i
< max
; i
++)
14318 enum dwarf_section_display_enum id
= (enum dwarf_section_display_enum
) i
;
14319 struct dwarf_section_display
* display
= debug_displays
+ i
;
14320 struct dwarf_section
* sec
= & display
->section
;
14322 if (streq (sec
->uncompressed_name
, name
)
14323 || (id
== line
&& const_strneq (name
, ".debug_line."))
14324 || streq (sec
->compressed_name
, name
))
14326 bfd_boolean secondary
= (section
!= find_section (filedata
, name
));
14329 free_debug_section (id
);
14331 if (i
== line
&& const_strneq (name
, ".debug_line."))
14333 else if (streq (sec
->uncompressed_name
, name
))
14334 sec
->name
= sec
->uncompressed_name
;
14336 sec
->name
= sec
->compressed_name
;
14338 if (load_specific_debug_section (id
, section
, filedata
))
14340 /* If this debug section is part of a CU/TU set in a .dwp file,
14341 restrict load_debug_section to the sections in that set. */
14342 section_subset
= find_cu_tu_set (filedata
, shndx
);
14344 result
&= display
->display (sec
, filedata
);
14346 section_subset
= NULL
;
14348 if (secondary
|| (id
!= info
&& id
!= abbrev
))
14349 free_debug_section (id
);
14357 printf (_("Unrecognized debug section: %s\n"), print_name
);
14364 /* Set DUMP_SECTS for all sections where dumps were requested
14365 based on section name. */
14368 initialise_dumps_byname (Filedata
* filedata
)
14370 struct dump_list_entry
* cur
;
14372 for (cur
= dump_sects_byname
; cur
; cur
= cur
->next
)
14375 bfd_boolean any
= FALSE
;
14377 for (i
= 0; i
< filedata
->file_header
.e_shnum
; i
++)
14378 if (streq (SECTION_NAME (filedata
->section_headers
+ i
), cur
->name
))
14380 request_dump_bynumber (filedata
, i
, cur
->type
);
14385 warn (_("Section '%s' was not dumped because it does not exist!\n"),
14391 process_section_contents (Filedata
* filedata
)
14393 Elf_Internal_Shdr
* section
;
14395 bfd_boolean res
= TRUE
;
14400 initialise_dumps_byname (filedata
);
14402 for (i
= 0, section
= filedata
->section_headers
;
14403 i
< filedata
->file_header
.e_shnum
&& i
< filedata
->num_dump_sects
;
14406 dump_type dump
= filedata
->dump_sects
[i
];
14408 #ifdef SUPPORT_DISASSEMBLY
14409 if (dump
& DISASS_DUMP
)
14411 if (! disassemble_section (section
, filedata
))
14415 if (dump
& HEX_DUMP
)
14417 if (! dump_section_as_bytes (section
, filedata
, FALSE
))
14421 if (dump
& RELOC_DUMP
)
14423 if (! dump_section_as_bytes (section
, filedata
, TRUE
))
14427 if (dump
& STRING_DUMP
)
14429 if (! dump_section_as_strings (section
, filedata
))
14433 if (dump
& DEBUG_DUMP
)
14435 if (! display_debug_section (i
, section
, filedata
))
14439 if (dump
& CTF_DUMP
)
14441 if (! dump_section_as_ctf (section
, filedata
))
14446 /* Check to see if the user requested a
14447 dump of a section that does not exist. */
14448 while (i
< filedata
->num_dump_sects
)
14450 if (filedata
->dump_sects
[i
])
14452 warn (_("Section %d was not dumped because it does not exist!\n"), i
);
14462 process_mips_fpe_exception (int mask
)
14466 bfd_boolean first
= TRUE
;
14468 if (mask
& OEX_FPU_INEX
)
14469 fputs ("INEX", stdout
), first
= FALSE
;
14470 if (mask
& OEX_FPU_UFLO
)
14471 printf ("%sUFLO", first
? "" : "|"), first
= FALSE
;
14472 if (mask
& OEX_FPU_OFLO
)
14473 printf ("%sOFLO", first
? "" : "|"), first
= FALSE
;
14474 if (mask
& OEX_FPU_DIV0
)
14475 printf ("%sDIV0", first
? "" : "|"), first
= FALSE
;
14476 if (mask
& OEX_FPU_INVAL
)
14477 printf ("%sINVAL", first
? "" : "|");
14480 fputs ("0", stdout
);
14483 /* Display's the value of TAG at location P. If TAG is
14484 greater than 0 it is assumed to be an unknown tag, and
14485 a message is printed to this effect. Otherwise it is
14486 assumed that a message has already been printed.
14488 If the bottom bit of TAG is set it assumed to have a
14489 string value, otherwise it is assumed to have an integer
14492 Returns an updated P pointing to the first unread byte
14493 beyond the end of TAG's value.
14495 Reads at or beyond END will not be made. */
14497 static unsigned char *
14498 display_tag_value (signed int tag
,
14500 const unsigned char * const end
)
14505 printf (" Tag_unknown_%d: ", tag
);
14509 warn (_("<corrupt tag>\n"));
14513 /* PR 17531 file: 027-19978-0.004. */
14514 size_t maxlen
= (end
- p
) - 1;
14519 print_symbol ((int) maxlen
, (const char *) p
);
14520 p
+= strnlen ((char *) p
, maxlen
) + 1;
14524 printf (_("<corrupt string tag>"));
14525 p
= (unsigned char *) end
;
14533 val
= read_uleb128 (p
, &len
, end
);
14535 printf ("%ld (0x%lx)\n", val
, val
);
14542 /* ARC ABI attributes section. */
14544 static unsigned char *
14545 display_arc_attribute (unsigned char * p
,
14546 const unsigned char * const end
)
14552 tag
= read_uleb128 (p
, &len
, end
);
14557 case Tag_ARC_PCS_config
:
14558 val
= read_uleb128 (p
, &len
, end
);
14560 printf (" Tag_ARC_PCS_config: ");
14564 printf (_("Absent/Non standard\n"));
14567 printf (_("Bare metal/mwdt\n"));
14570 printf (_("Bare metal/newlib\n"));
14573 printf (_("Linux/uclibc\n"));
14576 printf (_("Linux/glibc\n"));
14579 printf (_("Unknown\n"));
14584 case Tag_ARC_CPU_base
:
14585 val
= read_uleb128 (p
, &len
, end
);
14587 printf (" Tag_ARC_CPU_base: ");
14592 printf (_("Absent\n"));
14594 case TAG_CPU_ARC6xx
:
14595 printf ("ARC6xx\n");
14597 case TAG_CPU_ARC7xx
:
14598 printf ("ARC7xx\n");
14600 case TAG_CPU_ARCEM
:
14601 printf ("ARCEM\n");
14603 case TAG_CPU_ARCHS
:
14604 printf ("ARCHS\n");
14609 case Tag_ARC_CPU_variation
:
14610 val
= read_uleb128 (p
, &len
, end
);
14612 printf (" Tag_ARC_CPU_variation: ");
14616 if (val
> 0 && val
< 16)
14617 printf ("Core%d\n", val
);
14619 printf ("Unknown\n");
14623 printf (_("Absent\n"));
14628 case Tag_ARC_CPU_name
:
14629 printf (" Tag_ARC_CPU_name: ");
14630 p
= display_tag_value (-1, p
, end
);
14633 case Tag_ARC_ABI_rf16
:
14634 val
= read_uleb128 (p
, &len
, end
);
14636 printf (" Tag_ARC_ABI_rf16: %s\n", val
? _("yes") : _("no"));
14639 case Tag_ARC_ABI_osver
:
14640 val
= read_uleb128 (p
, &len
, end
);
14642 printf (" Tag_ARC_ABI_osver: v%d\n", val
);
14645 case Tag_ARC_ABI_pic
:
14646 case Tag_ARC_ABI_sda
:
14647 val
= read_uleb128 (p
, &len
, end
);
14649 printf (tag
== Tag_ARC_ABI_sda
? " Tag_ARC_ABI_sda: "
14650 : " Tag_ARC_ABI_pic: ");
14654 printf (_("Absent\n"));
14663 printf (_("Unknown\n"));
14668 case Tag_ARC_ABI_tls
:
14669 val
= read_uleb128 (p
, &len
, end
);
14671 printf (" Tag_ARC_ABI_tls: %s\n", val
? "r25": "none");
14674 case Tag_ARC_ABI_enumsize
:
14675 val
= read_uleb128 (p
, &len
, end
);
14677 printf (" Tag_ARC_ABI_enumsize: %s\n", val
? _("default") :
14681 case Tag_ARC_ABI_exceptions
:
14682 val
= read_uleb128 (p
, &len
, end
);
14684 printf (" Tag_ARC_ABI_exceptions: %s\n", val
? _("OPTFP")
14688 case Tag_ARC_ABI_double_size
:
14689 val
= read_uleb128 (p
, &len
, end
);
14691 printf (" Tag_ARC_ABI_double_size: %d\n", val
);
14694 case Tag_ARC_ISA_config
:
14695 printf (" Tag_ARC_ISA_config: ");
14696 p
= display_tag_value (-1, p
, end
);
14699 case Tag_ARC_ISA_apex
:
14700 printf (" Tag_ARC_ISA_apex: ");
14701 p
= display_tag_value (-1, p
, end
);
14704 case Tag_ARC_ISA_mpy_option
:
14705 val
= read_uleb128 (p
, &len
, end
);
14707 printf (" Tag_ARC_ISA_mpy_option: %d\n", val
);
14710 case Tag_ARC_ATR_version
:
14711 val
= read_uleb128 (p
, &len
, end
);
14713 printf (" Tag_ARC_ATR_version: %d\n", val
);
14717 return display_tag_value (tag
& 1, p
, end
);
14723 /* ARM EABI attributes section. */
14728 /* 0 = special, 1 = string, 2 = uleb123, > 0x80 == table lookup. */
14730 const char ** table
;
14731 } arm_attr_public_tag
;
14733 static const char * arm_attr_tag_CPU_arch
[] =
14734 {"Pre-v4", "v4", "v4T", "v5T", "v5TE", "v5TEJ", "v6", "v6KZ", "v6T2",
14735 "v6K", "v7", "v6-M", "v6S-M", "v7E-M", "v8", "v8-R", "v8-M.baseline",
14736 "v8-M.mainline", "", "", "", "v8.1-M.mainline"};
14737 static const char * arm_attr_tag_ARM_ISA_use
[] = {"No", "Yes"};
14738 static const char * arm_attr_tag_THUMB_ISA_use
[] =
14739 {"No", "Thumb-1", "Thumb-2", "Yes"};
14740 static const char * arm_attr_tag_FP_arch
[] =
14741 {"No", "VFPv1", "VFPv2", "VFPv3", "VFPv3-D16", "VFPv4", "VFPv4-D16",
14742 "FP for ARMv8", "FPv5/FP-D16 for ARMv8"};
14743 static const char * arm_attr_tag_WMMX_arch
[] = {"No", "WMMXv1", "WMMXv2"};
14744 static const char * arm_attr_tag_Advanced_SIMD_arch
[] =
14745 {"No", "NEONv1", "NEONv1 with Fused-MAC", "NEON for ARMv8",
14746 "NEON for ARMv8.1"};
14747 static const char * arm_attr_tag_PCS_config
[] =
14748 {"None", "Bare platform", "Linux application", "Linux DSO", "PalmOS 2004",
14749 "PalmOS (reserved)", "SymbianOS 2004", "SymbianOS (reserved)"};
14750 static const char * arm_attr_tag_ABI_PCS_R9_use
[] =
14751 {"V6", "SB", "TLS", "Unused"};
14752 static const char * arm_attr_tag_ABI_PCS_RW_data
[] =
14753 {"Absolute", "PC-relative", "SB-relative", "None"};
14754 static const char * arm_attr_tag_ABI_PCS_RO_data
[] =
14755 {"Absolute", "PC-relative", "None"};
14756 static const char * arm_attr_tag_ABI_PCS_GOT_use
[] =
14757 {"None", "direct", "GOT-indirect"};
14758 static const char * arm_attr_tag_ABI_PCS_wchar_t
[] =
14759 {"None", "??? 1", "2", "??? 3", "4"};
14760 static const char * arm_attr_tag_ABI_FP_rounding
[] = {"Unused", "Needed"};
14761 static const char * arm_attr_tag_ABI_FP_denormal
[] =
14762 {"Unused", "Needed", "Sign only"};
14763 static const char * arm_attr_tag_ABI_FP_exceptions
[] = {"Unused", "Needed"};
14764 static const char * arm_attr_tag_ABI_FP_user_exceptions
[] = {"Unused", "Needed"};
14765 static const char * arm_attr_tag_ABI_FP_number_model
[] =
14766 {"Unused", "Finite", "RTABI", "IEEE 754"};
14767 static const char * arm_attr_tag_ABI_enum_size
[] =
14768 {"Unused", "small", "int", "forced to int"};
14769 static const char * arm_attr_tag_ABI_HardFP_use
[] =
14770 {"As Tag_FP_arch", "SP only", "Reserved", "Deprecated"};
14771 static const char * arm_attr_tag_ABI_VFP_args
[] =
14772 {"AAPCS", "VFP registers", "custom", "compatible"};
14773 static const char * arm_attr_tag_ABI_WMMX_args
[] =
14774 {"AAPCS", "WMMX registers", "custom"};
14775 static const char * arm_attr_tag_ABI_optimization_goals
[] =
14776 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
14777 "Aggressive Size", "Prefer Debug", "Aggressive Debug"};
14778 static const char * arm_attr_tag_ABI_FP_optimization_goals
[] =
14779 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
14780 "Aggressive Size", "Prefer Accuracy", "Aggressive Accuracy"};
14781 static const char * arm_attr_tag_CPU_unaligned_access
[] = {"None", "v6"};
14782 static const char * arm_attr_tag_FP_HP_extension
[] =
14783 {"Not Allowed", "Allowed"};
14784 static const char * arm_attr_tag_ABI_FP_16bit_format
[] =
14785 {"None", "IEEE 754", "Alternative Format"};
14786 static const char * arm_attr_tag_DSP_extension
[] =
14787 {"Follow architecture", "Allowed"};
14788 static const char * arm_attr_tag_MPextension_use
[] =
14789 {"Not Allowed", "Allowed"};
14790 static const char * arm_attr_tag_DIV_use
[] =
14791 {"Allowed in Thumb-ISA, v7-R or v7-M", "Not allowed",
14792 "Allowed in v7-A with integer division extension"};
14793 static const char * arm_attr_tag_T2EE_use
[] = {"Not Allowed", "Allowed"};
14794 static const char * arm_attr_tag_Virtualization_use
[] =
14795 {"Not Allowed", "TrustZone", "Virtualization Extensions",
14796 "TrustZone and Virtualization Extensions"};
14797 static const char * arm_attr_tag_MPextension_use_legacy
[] =
14798 {"Not Allowed", "Allowed"};
14800 static const char * arm_attr_tag_MVE_arch
[] =
14801 {"No MVE", "MVE Integer only", "MVE Integer and FP"};
14803 #define LOOKUP(id, name) \
14804 {id, #name, 0x80 | ARRAY_SIZE(arm_attr_tag_##name), arm_attr_tag_##name}
14805 static arm_attr_public_tag arm_attr_public_tags
[] =
14807 {4, "CPU_raw_name", 1, NULL
},
14808 {5, "CPU_name", 1, NULL
},
14809 LOOKUP(6, CPU_arch
),
14810 {7, "CPU_arch_profile", 0, NULL
},
14811 LOOKUP(8, ARM_ISA_use
),
14812 LOOKUP(9, THUMB_ISA_use
),
14813 LOOKUP(10, FP_arch
),
14814 LOOKUP(11, WMMX_arch
),
14815 LOOKUP(12, Advanced_SIMD_arch
),
14816 LOOKUP(13, PCS_config
),
14817 LOOKUP(14, ABI_PCS_R9_use
),
14818 LOOKUP(15, ABI_PCS_RW_data
),
14819 LOOKUP(16, ABI_PCS_RO_data
),
14820 LOOKUP(17, ABI_PCS_GOT_use
),
14821 LOOKUP(18, ABI_PCS_wchar_t
),
14822 LOOKUP(19, ABI_FP_rounding
),
14823 LOOKUP(20, ABI_FP_denormal
),
14824 LOOKUP(21, ABI_FP_exceptions
),
14825 LOOKUP(22, ABI_FP_user_exceptions
),
14826 LOOKUP(23, ABI_FP_number_model
),
14827 {24, "ABI_align_needed", 0, NULL
},
14828 {25, "ABI_align_preserved", 0, NULL
},
14829 LOOKUP(26, ABI_enum_size
),
14830 LOOKUP(27, ABI_HardFP_use
),
14831 LOOKUP(28, ABI_VFP_args
),
14832 LOOKUP(29, ABI_WMMX_args
),
14833 LOOKUP(30, ABI_optimization_goals
),
14834 LOOKUP(31, ABI_FP_optimization_goals
),
14835 {32, "compatibility", 0, NULL
},
14836 LOOKUP(34, CPU_unaligned_access
),
14837 LOOKUP(36, FP_HP_extension
),
14838 LOOKUP(38, ABI_FP_16bit_format
),
14839 LOOKUP(42, MPextension_use
),
14840 LOOKUP(44, DIV_use
),
14841 LOOKUP(46, DSP_extension
),
14842 LOOKUP(48, MVE_arch
),
14843 {64, "nodefaults", 0, NULL
},
14844 {65, "also_compatible_with", 0, NULL
},
14845 LOOKUP(66, T2EE_use
),
14846 {67, "conformance", 1, NULL
},
14847 LOOKUP(68, Virtualization_use
),
14848 LOOKUP(70, MPextension_use_legacy
)
14852 static unsigned char *
14853 display_arm_attribute (unsigned char * p
,
14854 const unsigned char * const end
)
14859 arm_attr_public_tag
* attr
;
14863 tag
= read_uleb128 (p
, &len
, end
);
14866 for (i
= 0; i
< ARRAY_SIZE (arm_attr_public_tags
); i
++)
14868 if (arm_attr_public_tags
[i
].tag
== tag
)
14870 attr
= &arm_attr_public_tags
[i
];
14877 printf (" Tag_%s: ", attr
->name
);
14878 switch (attr
->type
)
14883 case 7: /* Tag_CPU_arch_profile. */
14884 val
= read_uleb128 (p
, &len
, end
);
14888 case 0: printf (_("None\n")); break;
14889 case 'A': printf (_("Application\n")); break;
14890 case 'R': printf (_("Realtime\n")); break;
14891 case 'M': printf (_("Microcontroller\n")); break;
14892 case 'S': printf (_("Application or Realtime\n")); break;
14893 default: printf ("??? (%d)\n", val
); break;
14897 case 24: /* Tag_align_needed. */
14898 val
= read_uleb128 (p
, &len
, end
);
14902 case 0: printf (_("None\n")); break;
14903 case 1: printf (_("8-byte\n")); break;
14904 case 2: printf (_("4-byte\n")); break;
14905 case 3: printf ("??? 3\n"); break;
14908 printf (_("8-byte and up to %d-byte extended\n"),
14911 printf ("??? (%d)\n", val
);
14916 case 25: /* Tag_align_preserved. */
14917 val
= read_uleb128 (p
, &len
, end
);
14921 case 0: printf (_("None\n")); break;
14922 case 1: printf (_("8-byte, except leaf SP\n")); break;
14923 case 2: printf (_("8-byte\n")); break;
14924 case 3: printf ("??? 3\n"); break;
14927 printf (_("8-byte and up to %d-byte extended\n"),
14930 printf ("??? (%d)\n", val
);
14935 case 32: /* Tag_compatibility. */
14937 val
= read_uleb128 (p
, &len
, end
);
14939 printf (_("flag = %d, vendor = "), val
);
14942 size_t maxlen
= (end
- p
) - 1;
14944 print_symbol ((int) maxlen
, (const char *) p
);
14945 p
+= strnlen ((char *) p
, maxlen
) + 1;
14949 printf (_("<corrupt>"));
14950 p
= (unsigned char *) end
;
14956 case 64: /* Tag_nodefaults. */
14957 /* PR 17531: file: 001-505008-0.01. */
14960 printf (_("True\n"));
14963 case 65: /* Tag_also_compatible_with. */
14964 val
= read_uleb128 (p
, &len
, end
);
14966 if (val
== 6 /* Tag_CPU_arch. */)
14968 val
= read_uleb128 (p
, &len
, end
);
14970 if ((unsigned int) val
>= ARRAY_SIZE (arm_attr_tag_CPU_arch
))
14971 printf ("??? (%d)\n", val
);
14973 printf ("%s\n", arm_attr_tag_CPU_arch
[val
]);
14977 while (p
< end
&& *(p
++) != '\0' /* NUL terminator. */)
14982 printf (_("<unknown: %d>\n"), tag
);
14988 return display_tag_value (-1, p
, end
);
14990 return display_tag_value (0, p
, end
);
14993 assert (attr
->type
& 0x80);
14994 val
= read_uleb128 (p
, &len
, end
);
14996 type
= attr
->type
& 0x7f;
14998 printf ("??? (%d)\n", val
);
15000 printf ("%s\n", attr
->table
[val
]);
15005 return display_tag_value (tag
, p
, end
);
15008 static unsigned char *
15009 display_gnu_attribute (unsigned char * p
,
15010 unsigned char * (* display_proc_gnu_attribute
) (unsigned char *, unsigned int, const unsigned char * const),
15011 const unsigned char * const end
)
15017 tag
= read_uleb128 (p
, &len
, end
);
15020 /* Tag_compatibility is the only generic GNU attribute defined at
15024 val
= read_uleb128 (p
, &len
, end
);
15027 printf (_("flag = %d, vendor = "), val
);
15030 printf (_("<corrupt>\n"));
15031 warn (_("corrupt vendor attribute\n"));
15037 size_t maxlen
= (end
- p
) - 1;
15039 print_symbol ((int) maxlen
, (const char *) p
);
15040 p
+= strnlen ((char *) p
, maxlen
) + 1;
15044 printf (_("<corrupt>"));
15045 p
= (unsigned char *) end
;
15052 if ((tag
& 2) == 0 && display_proc_gnu_attribute
)
15053 return display_proc_gnu_attribute (p
, tag
, end
);
15055 return display_tag_value (tag
, p
, end
);
15058 static unsigned char *
15059 display_power_gnu_attribute (unsigned char * p
,
15061 const unsigned char * const end
)
15066 if (tag
== Tag_GNU_Power_ABI_FP
)
15068 val
= read_uleb128 (p
, &len
, end
);
15070 printf (" Tag_GNU_Power_ABI_FP: ");
15073 printf (_("<corrupt>\n"));
15078 printf ("(%#x), ", val
);
15083 printf (_("unspecified hard/soft float, "));
15086 printf (_("hard float, "));
15089 printf (_("soft float, "));
15092 printf (_("single-precision hard float, "));
15099 printf (_("unspecified long double\n"));
15102 printf (_("128-bit IBM long double\n"));
15105 printf (_("64-bit long double\n"));
15108 printf (_("128-bit IEEE long double\n"));
15114 if (tag
== Tag_GNU_Power_ABI_Vector
)
15116 val
= read_uleb128 (p
, &len
, end
);
15118 printf (" Tag_GNU_Power_ABI_Vector: ");
15121 printf (_("<corrupt>\n"));
15126 printf ("(%#x), ", val
);
15131 printf (_("unspecified\n"));
15134 printf (_("generic\n"));
15137 printf ("AltiVec\n");
15146 if (tag
== Tag_GNU_Power_ABI_Struct_Return
)
15148 val
= read_uleb128 (p
, &len
, end
);
15150 printf (" Tag_GNU_Power_ABI_Struct_Return: ");
15153 printf (_("<corrupt>\n"));
15158 printf ("(%#x), ", val
);
15163 printf (_("unspecified\n"));
15166 printf ("r3/r4\n");
15169 printf (_("memory\n"));
15178 return display_tag_value (tag
& 1, p
, end
);
15181 static unsigned char *
15182 display_s390_gnu_attribute (unsigned char * p
,
15184 const unsigned char * const end
)
15189 if (tag
== Tag_GNU_S390_ABI_Vector
)
15191 val
= read_uleb128 (p
, &len
, end
);
15193 printf (" Tag_GNU_S390_ABI_Vector: ");
15198 printf (_("any\n"));
15201 printf (_("software\n"));
15204 printf (_("hardware\n"));
15207 printf ("??? (%d)\n", val
);
15213 return display_tag_value (tag
& 1, p
, end
);
15217 display_sparc_hwcaps (unsigned int mask
)
15221 bfd_boolean first
= TRUE
;
15223 if (mask
& ELF_SPARC_HWCAP_MUL32
)
15224 fputs ("mul32", stdout
), first
= FALSE
;
15225 if (mask
& ELF_SPARC_HWCAP_DIV32
)
15226 printf ("%sdiv32", first
? "" : "|"), first
= FALSE
;
15227 if (mask
& ELF_SPARC_HWCAP_FSMULD
)
15228 printf ("%sfsmuld", first
? "" : "|"), first
= FALSE
;
15229 if (mask
& ELF_SPARC_HWCAP_V8PLUS
)
15230 printf ("%sv8plus", first
? "" : "|"), first
= FALSE
;
15231 if (mask
& ELF_SPARC_HWCAP_POPC
)
15232 printf ("%spopc", first
? "" : "|"), first
= FALSE
;
15233 if (mask
& ELF_SPARC_HWCAP_VIS
)
15234 printf ("%svis", first
? "" : "|"), first
= FALSE
;
15235 if (mask
& ELF_SPARC_HWCAP_VIS2
)
15236 printf ("%svis2", first
? "" : "|"), first
= FALSE
;
15237 if (mask
& ELF_SPARC_HWCAP_ASI_BLK_INIT
)
15238 printf ("%sASIBlkInit", first
? "" : "|"), first
= FALSE
;
15239 if (mask
& ELF_SPARC_HWCAP_FMAF
)
15240 printf ("%sfmaf", first
? "" : "|"), first
= FALSE
;
15241 if (mask
& ELF_SPARC_HWCAP_VIS3
)
15242 printf ("%svis3", first
? "" : "|"), first
= FALSE
;
15243 if (mask
& ELF_SPARC_HWCAP_HPC
)
15244 printf ("%shpc", first
? "" : "|"), first
= FALSE
;
15245 if (mask
& ELF_SPARC_HWCAP_RANDOM
)
15246 printf ("%srandom", first
? "" : "|"), first
= FALSE
;
15247 if (mask
& ELF_SPARC_HWCAP_TRANS
)
15248 printf ("%strans", first
? "" : "|"), first
= FALSE
;
15249 if (mask
& ELF_SPARC_HWCAP_FJFMAU
)
15250 printf ("%sfjfmau", first
? "" : "|"), first
= FALSE
;
15251 if (mask
& ELF_SPARC_HWCAP_IMA
)
15252 printf ("%sima", first
? "" : "|"), first
= FALSE
;
15253 if (mask
& ELF_SPARC_HWCAP_ASI_CACHE_SPARING
)
15254 printf ("%scspare", first
? "" : "|"), first
= FALSE
;
15257 fputc ('0', stdout
);
15258 fputc ('\n', stdout
);
15262 display_sparc_hwcaps2 (unsigned int mask
)
15266 bfd_boolean first
= TRUE
;
15268 if (mask
& ELF_SPARC_HWCAP2_FJATHPLUS
)
15269 fputs ("fjathplus", stdout
), first
= FALSE
;
15270 if (mask
& ELF_SPARC_HWCAP2_VIS3B
)
15271 printf ("%svis3b", first
? "" : "|"), first
= FALSE
;
15272 if (mask
& ELF_SPARC_HWCAP2_ADP
)
15273 printf ("%sadp", first
? "" : "|"), first
= FALSE
;
15274 if (mask
& ELF_SPARC_HWCAP2_SPARC5
)
15275 printf ("%ssparc5", first
? "" : "|"), first
= FALSE
;
15276 if (mask
& ELF_SPARC_HWCAP2_MWAIT
)
15277 printf ("%smwait", first
? "" : "|"), first
= FALSE
;
15278 if (mask
& ELF_SPARC_HWCAP2_XMPMUL
)
15279 printf ("%sxmpmul", first
? "" : "|"), first
= FALSE
;
15280 if (mask
& ELF_SPARC_HWCAP2_XMONT
)
15281 printf ("%sxmont2", first
? "" : "|"), first
= FALSE
;
15282 if (mask
& ELF_SPARC_HWCAP2_NSEC
)
15283 printf ("%snsec", first
? "" : "|"), first
= FALSE
;
15284 if (mask
& ELF_SPARC_HWCAP2_FJATHHPC
)
15285 printf ("%sfjathhpc", first
? "" : "|"), first
= FALSE
;
15286 if (mask
& ELF_SPARC_HWCAP2_FJDES
)
15287 printf ("%sfjdes", first
? "" : "|"), first
= FALSE
;
15288 if (mask
& ELF_SPARC_HWCAP2_FJAES
)
15289 printf ("%sfjaes", first
? "" : "|"), first
= FALSE
;
15292 fputc ('0', stdout
);
15293 fputc ('\n', stdout
);
15296 static unsigned char *
15297 display_sparc_gnu_attribute (unsigned char * p
,
15299 const unsigned char * const end
)
15304 if (tag
== Tag_GNU_Sparc_HWCAPS
)
15306 val
= read_uleb128 (p
, &len
, end
);
15308 printf (" Tag_GNU_Sparc_HWCAPS: ");
15309 display_sparc_hwcaps (val
);
15312 if (tag
== Tag_GNU_Sparc_HWCAPS2
)
15314 val
= read_uleb128 (p
, &len
, end
);
15316 printf (" Tag_GNU_Sparc_HWCAPS2: ");
15317 display_sparc_hwcaps2 (val
);
15321 return display_tag_value (tag
, p
, end
);
15325 print_mips_fp_abi_value (unsigned int val
)
15329 case Val_GNU_MIPS_ABI_FP_ANY
:
15330 printf (_("Hard or soft float\n"));
15332 case Val_GNU_MIPS_ABI_FP_DOUBLE
:
15333 printf (_("Hard float (double precision)\n"));
15335 case Val_GNU_MIPS_ABI_FP_SINGLE
:
15336 printf (_("Hard float (single precision)\n"));
15338 case Val_GNU_MIPS_ABI_FP_SOFT
:
15339 printf (_("Soft float\n"));
15341 case Val_GNU_MIPS_ABI_FP_OLD_64
:
15342 printf (_("Hard float (MIPS32r2 64-bit FPU 12 callee-saved)\n"));
15344 case Val_GNU_MIPS_ABI_FP_XX
:
15345 printf (_("Hard float (32-bit CPU, Any FPU)\n"));
15347 case Val_GNU_MIPS_ABI_FP_64
:
15348 printf (_("Hard float (32-bit CPU, 64-bit FPU)\n"));
15350 case Val_GNU_MIPS_ABI_FP_64A
:
15351 printf (_("Hard float compat (32-bit CPU, 64-bit FPU)\n"));
15353 case Val_GNU_MIPS_ABI_FP_NAN2008
:
15354 printf (_("NaN 2008 compatibility\n"));
15357 printf ("??? (%d)\n", val
);
15362 static unsigned char *
15363 display_mips_gnu_attribute (unsigned char * p
,
15365 const unsigned char * const end
)
15367 if (tag
== Tag_GNU_MIPS_ABI_FP
)
15372 val
= read_uleb128 (p
, &len
, end
);
15374 printf (" Tag_GNU_MIPS_ABI_FP: ");
15376 print_mips_fp_abi_value (val
);
15381 if (tag
== Tag_GNU_MIPS_ABI_MSA
)
15386 val
= read_uleb128 (p
, &len
, end
);
15388 printf (" Tag_GNU_MIPS_ABI_MSA: ");
15392 case Val_GNU_MIPS_ABI_MSA_ANY
:
15393 printf (_("Any MSA or not\n"));
15395 case Val_GNU_MIPS_ABI_MSA_128
:
15396 printf (_("128-bit MSA\n"));
15399 printf ("??? (%d)\n", val
);
15405 return display_tag_value (tag
& 1, p
, end
);
15408 static unsigned char *
15409 display_tic6x_attribute (unsigned char * p
,
15410 const unsigned char * const end
)
15416 tag
= read_uleb128 (p
, &len
, end
);
15422 val
= read_uleb128 (p
, &len
, end
);
15424 printf (" Tag_ISA: ");
15428 case C6XABI_Tag_ISA_none
:
15429 printf (_("None\n"));
15431 case C6XABI_Tag_ISA_C62X
:
15434 case C6XABI_Tag_ISA_C67X
:
15437 case C6XABI_Tag_ISA_C67XP
:
15438 printf ("C67x+\n");
15440 case C6XABI_Tag_ISA_C64X
:
15443 case C6XABI_Tag_ISA_C64XP
:
15444 printf ("C64x+\n");
15446 case C6XABI_Tag_ISA_C674X
:
15447 printf ("C674x\n");
15450 printf ("??? (%d)\n", val
);
15455 case Tag_ABI_wchar_t
:
15456 val
= read_uleb128 (p
, &len
, end
);
15458 printf (" Tag_ABI_wchar_t: ");
15462 printf (_("Not used\n"));
15465 printf (_("2 bytes\n"));
15468 printf (_("4 bytes\n"));
15471 printf ("??? (%d)\n", val
);
15476 case Tag_ABI_stack_align_needed
:
15477 val
= read_uleb128 (p
, &len
, end
);
15479 printf (" Tag_ABI_stack_align_needed: ");
15483 printf (_("8-byte\n"));
15486 printf (_("16-byte\n"));
15489 printf ("??? (%d)\n", val
);
15494 case Tag_ABI_stack_align_preserved
:
15495 val
= read_uleb128 (p
, &len
, end
);
15497 printf (" Tag_ABI_stack_align_preserved: ");
15501 printf (_("8-byte\n"));
15504 printf (_("16-byte\n"));
15507 printf ("??? (%d)\n", val
);
15513 val
= read_uleb128 (p
, &len
, end
);
15515 printf (" Tag_ABI_DSBT: ");
15519 printf (_("DSBT addressing not used\n"));
15522 printf (_("DSBT addressing used\n"));
15525 printf ("??? (%d)\n", val
);
15531 val
= read_uleb128 (p
, &len
, end
);
15533 printf (" Tag_ABI_PID: ");
15537 printf (_("Data addressing position-dependent\n"));
15540 printf (_("Data addressing position-independent, GOT near DP\n"));
15543 printf (_("Data addressing position-independent, GOT far from DP\n"));
15546 printf ("??? (%d)\n", val
);
15552 val
= read_uleb128 (p
, &len
, end
);
15554 printf (" Tag_ABI_PIC: ");
15558 printf (_("Code addressing position-dependent\n"));
15561 printf (_("Code addressing position-independent\n"));
15564 printf ("??? (%d)\n", val
);
15569 case Tag_ABI_array_object_alignment
:
15570 val
= read_uleb128 (p
, &len
, end
);
15572 printf (" Tag_ABI_array_object_alignment: ");
15576 printf (_("8-byte\n"));
15579 printf (_("4-byte\n"));
15582 printf (_("16-byte\n"));
15585 printf ("??? (%d)\n", val
);
15590 case Tag_ABI_array_object_align_expected
:
15591 val
= read_uleb128 (p
, &len
, end
);
15593 printf (" Tag_ABI_array_object_align_expected: ");
15597 printf (_("8-byte\n"));
15600 printf (_("4-byte\n"));
15603 printf (_("16-byte\n"));
15606 printf ("??? (%d)\n", val
);
15611 case Tag_ABI_compatibility
:
15613 val
= read_uleb128 (p
, &len
, end
);
15615 printf (" Tag_ABI_compatibility: ");
15616 printf (_("flag = %d, vendor = "), val
);
15619 size_t maxlen
= (end
- p
) - 1;
15621 print_symbol ((int) maxlen
, (const char *) p
);
15622 p
+= strnlen ((char *) p
, maxlen
) + 1;
15626 printf (_("<corrupt>"));
15627 p
= (unsigned char *) end
;
15633 case Tag_ABI_conformance
:
15635 printf (" Tag_ABI_conformance: \"");
15638 size_t maxlen
= (end
- p
) - 1;
15640 print_symbol ((int) maxlen
, (const char *) p
);
15641 p
+= strnlen ((char *) p
, maxlen
) + 1;
15645 printf (_("<corrupt>"));
15646 p
= (unsigned char *) end
;
15653 return display_tag_value (tag
, p
, end
);
15657 display_raw_attribute (unsigned char * p
, unsigned char const * const end
)
15659 unsigned long addr
= 0;
15660 size_t bytes
= end
- p
;
15667 int lbytes
= (bytes
> 16 ? 16 : bytes
);
15669 printf (" 0x%8.8lx ", addr
);
15671 for (j
= 0; j
< 16; j
++)
15674 printf ("%2.2x", p
[j
]);
15682 for (j
= 0; j
< lbytes
; j
++)
15685 if (k
>= ' ' && k
< 0x7f)
15701 static unsigned char *
15702 display_msp430x_attribute (unsigned char * p
,
15703 const unsigned char * const end
)
15709 tag
= read_uleb128 (p
, & len
, end
);
15714 case OFBA_MSPABI_Tag_ISA
:
15715 val
= read_uleb128 (p
, &len
, end
);
15717 printf (" Tag_ISA: ");
15720 case 0: printf (_("None\n")); break;
15721 case 1: printf (_("MSP430\n")); break;
15722 case 2: printf (_("MSP430X\n")); break;
15723 default: printf ("??? (%d)\n", val
); break;
15727 case OFBA_MSPABI_Tag_Code_Model
:
15728 val
= read_uleb128 (p
, &len
, end
);
15730 printf (" Tag_Code_Model: ");
15733 case 0: printf (_("None\n")); break;
15734 case 1: printf (_("Small\n")); break;
15735 case 2: printf (_("Large\n")); break;
15736 default: printf ("??? (%d)\n", val
); break;
15740 case OFBA_MSPABI_Tag_Data_Model
:
15741 val
= read_uleb128 (p
, &len
, end
);
15743 printf (" Tag_Data_Model: ");
15746 case 0: printf (_("None\n")); break;
15747 case 1: printf (_("Small\n")); break;
15748 case 2: printf (_("Large\n")); break;
15749 case 3: printf (_("Restricted Large\n")); break;
15750 default: printf ("??? (%d)\n", val
); break;
15755 printf (_(" <unknown tag %d>: "), tag
);
15762 size_t maxlen
= (end
- p
) - 1;
15764 print_symbol ((int) maxlen
, (const char *) p
);
15765 p
+= strnlen ((char *) p
, maxlen
) + 1;
15769 printf (_("<corrupt>"));
15770 p
= (unsigned char *) end
;
15776 val
= read_uleb128 (p
, &len
, end
);
15778 printf ("%d (0x%x)\n", val
, val
);
15787 static unsigned char *
15788 display_msp430_gnu_attribute (unsigned char * p
,
15790 const unsigned char * const end
)
15792 if (tag
== Tag_GNU_MSP430_Data_Region
)
15797 val
= read_uleb128 (p
, &len
, end
);
15799 printf (" Tag_GNU_MSP430_Data_Region: ");
15803 case Val_GNU_MSP430_Data_Region_Any
:
15804 printf (_("Any Region\n"));
15806 case Val_GNU_MSP430_Data_Region_Lower
:
15807 printf (_("Lower Region Only\n"));
15810 printf ("??? (%d)\n", val
);
15814 return display_tag_value (tag
& 1, p
, end
);
15817 struct riscv_attr_tag_t
{
15822 static struct riscv_attr_tag_t riscv_attr_tag
[] =
15824 #define T(tag) {"Tag_RISCV_" #tag, Tag_RISCV_##tag}
15827 T(priv_spec_minor
),
15828 T(priv_spec_revision
),
15829 T(unaligned_access
),
15834 static unsigned char *
15835 display_riscv_attribute (unsigned char *p
,
15836 const unsigned char * const end
)
15841 struct riscv_attr_tag_t
*attr
= NULL
;
15844 tag
= read_uleb128 (p
, &len
, end
);
15847 /* Find the name of attribute. */
15848 for (i
= 0; i
< ARRAY_SIZE (riscv_attr_tag
); i
++)
15850 if (riscv_attr_tag
[i
].tag
== tag
)
15852 attr
= &riscv_attr_tag
[i
];
15858 printf (" %s: ", attr
->name
);
15860 return display_tag_value (tag
, p
, end
);
15864 case Tag_RISCV_priv_spec
:
15865 case Tag_RISCV_priv_spec_minor
:
15866 case Tag_RISCV_priv_spec_revision
:
15867 val
= read_uleb128 (p
, &len
, end
);
15869 printf (_("%d\n"), val
);
15871 case Tag_RISCV_unaligned_access
:
15872 val
= read_uleb128 (p
, &len
, end
);
15877 printf (_("No unaligned access\n"));
15880 printf (_("Unaligned access\n"));
15884 case Tag_RISCV_stack_align
:
15885 val
= read_uleb128 (p
, &len
, end
);
15887 printf (_("%d-bytes\n"), val
);
15889 case Tag_RISCV_arch
:
15890 p
= display_tag_value (-1, p
, end
);
15893 return display_tag_value (tag
, p
, end
);
15900 process_attributes (Filedata
* filedata
,
15901 const char * public_name
,
15902 unsigned int proc_type
,
15903 unsigned char * (* display_pub_attribute
) (unsigned char *, const unsigned char * const),
15904 unsigned char * (* display_proc_gnu_attribute
) (unsigned char *, unsigned int, const unsigned char * const))
15906 Elf_Internal_Shdr
* sect
;
15908 bfd_boolean res
= TRUE
;
15910 /* Find the section header so that we get the size. */
15911 for (i
= 0, sect
= filedata
->section_headers
;
15912 i
< filedata
->file_header
.e_shnum
;
15915 unsigned char * contents
;
15918 if (sect
->sh_type
!= proc_type
&& sect
->sh_type
!= SHT_GNU_ATTRIBUTES
)
15921 contents
= (unsigned char *) get_data (NULL
, filedata
, sect
->sh_offset
, 1,
15922 sect
->sh_size
, _("attributes"));
15923 if (contents
== NULL
)
15930 /* The first character is the version of the attributes.
15931 Currently only version 1, (aka 'A') is recognised here. */
15934 printf (_("Unknown attributes version '%c'(%d) - expecting 'A'\n"), *p
, *p
);
15939 bfd_vma section_len
;
15941 section_len
= sect
->sh_size
- 1;
15944 while (section_len
> 0)
15947 unsigned int namelen
;
15948 bfd_boolean public_section
;
15949 bfd_boolean gnu_section
;
15951 if (section_len
<= 4)
15953 error (_("Tag section ends prematurely\n"));
15957 attr_len
= byte_get (p
, 4);
15960 if (attr_len
> section_len
)
15962 error (_("Bad attribute length (%u > %u)\n"),
15963 (unsigned) attr_len
, (unsigned) section_len
);
15964 attr_len
= section_len
;
15967 /* PR 17531: file: 001-101425-0.004 */
15968 else if (attr_len
< 5)
15970 error (_("Attribute length of %u is too small\n"), (unsigned) attr_len
);
15975 section_len
-= attr_len
;
15978 namelen
= strnlen ((char *) p
, attr_len
) + 1;
15979 if (namelen
== 0 || namelen
>= attr_len
)
15981 error (_("Corrupt attribute section name\n"));
15986 printf (_("Attribute Section: "));
15987 print_symbol (INT_MAX
, (const char *) p
);
15990 if (public_name
&& streq ((char *) p
, public_name
))
15991 public_section
= TRUE
;
15993 public_section
= FALSE
;
15995 if (streq ((char *) p
, "gnu"))
15996 gnu_section
= TRUE
;
15998 gnu_section
= FALSE
;
16001 attr_len
-= namelen
;
16003 while (attr_len
> 0 && p
< contents
+ sect
->sh_size
)
16008 unsigned char * end
;
16010 /* PR binutils/17531: Safe handling of corrupt files. */
16013 error (_("Unused bytes at end of section\n"));
16020 size
= byte_get (p
, 4);
16021 if (size
> attr_len
)
16023 error (_("Bad subsection length (%u > %u)\n"),
16024 (unsigned) size
, (unsigned) attr_len
);
16028 /* PR binutils/17531: Safe handling of corrupt files. */
16031 error (_("Bad subsection length (%u < 6)\n"),
16039 end
= p
+ size
- 1;
16040 assert (end
<= contents
+ sect
->sh_size
);
16046 printf (_("File Attributes\n"));
16049 printf (_("Section Attributes:"));
16052 printf (_("Symbol Attributes:"));
16053 /* Fall through. */
16059 val
= read_uleb128 (p
, &j
, end
);
16063 printf (" %d", val
);
16068 printf (_("Unknown tag: %d\n"), tag
);
16069 public_section
= FALSE
;
16073 if (public_section
&& display_pub_attribute
!= NULL
)
16076 p
= display_pub_attribute (p
, end
);
16079 else if (gnu_section
&& display_proc_gnu_attribute
!= NULL
)
16082 p
= display_gnu_attribute (p
,
16083 display_proc_gnu_attribute
,
16089 printf (_(" Unknown attribute:\n"));
16090 display_raw_attribute (p
, end
);
16105 /* DATA points to the contents of a MIPS GOT that starts at VMA PLTGOT.
16106 Print the Address, Access and Initial fields of an entry at VMA ADDR
16107 and return the VMA of the next entry, or -1 if there was a problem.
16108 Does not read from DATA_END or beyond. */
16111 print_mips_got_entry (unsigned char * data
, bfd_vma pltgot
, bfd_vma addr
,
16112 unsigned char * data_end
)
16115 print_vma (addr
, LONG_HEX
);
16117 if (addr
< pltgot
+ 0xfff0)
16118 printf ("%6d(gp)", (int) (addr
- pltgot
- 0x7ff0));
16120 printf ("%10s", "");
16123 printf ("%*s", is_32bit_elf
? 8 : 16, _("<unknown>"));
16127 unsigned char * from
= data
+ addr
- pltgot
;
16129 if (from
+ (is_32bit_elf
? 4 : 8) > data_end
)
16131 warn (_("MIPS GOT entry extends beyond the end of available data\n"));
16132 printf ("%*s", is_32bit_elf
? 8 : 16, _("<corrupt>"));
16133 return (bfd_vma
) -1;
16137 entry
= byte_get (data
+ addr
- pltgot
, is_32bit_elf
? 4 : 8);
16138 print_vma (entry
, LONG_HEX
);
16141 return addr
+ (is_32bit_elf
? 4 : 8);
16144 /* DATA points to the contents of a MIPS PLT GOT that starts at VMA
16145 PLTGOT. Print the Address and Initial fields of an entry at VMA
16146 ADDR and return the VMA of the next entry. */
16149 print_mips_pltgot_entry (unsigned char * data
, bfd_vma pltgot
, bfd_vma addr
)
16152 print_vma (addr
, LONG_HEX
);
16155 printf ("%*s", is_32bit_elf
? 8 : 16, _("<unknown>"));
16160 entry
= byte_get (data
+ addr
- pltgot
, is_32bit_elf
? 4 : 8);
16161 print_vma (entry
, LONG_HEX
);
16163 return addr
+ (is_32bit_elf
? 4 : 8);
16167 print_mips_ases (unsigned int mask
)
16169 if (mask
& AFL_ASE_DSP
)
16170 fputs ("\n\tDSP ASE", stdout
);
16171 if (mask
& AFL_ASE_DSPR2
)
16172 fputs ("\n\tDSP R2 ASE", stdout
);
16173 if (mask
& AFL_ASE_DSPR3
)
16174 fputs ("\n\tDSP R3 ASE", stdout
);
16175 if (mask
& AFL_ASE_EVA
)
16176 fputs ("\n\tEnhanced VA Scheme", stdout
);
16177 if (mask
& AFL_ASE_MCU
)
16178 fputs ("\n\tMCU (MicroController) ASE", stdout
);
16179 if (mask
& AFL_ASE_MDMX
)
16180 fputs ("\n\tMDMX ASE", stdout
);
16181 if (mask
& AFL_ASE_MIPS3D
)
16182 fputs ("\n\tMIPS-3D ASE", stdout
);
16183 if (mask
& AFL_ASE_MT
)
16184 fputs ("\n\tMT ASE", stdout
);
16185 if (mask
& AFL_ASE_SMARTMIPS
)
16186 fputs ("\n\tSmartMIPS ASE", stdout
);
16187 if (mask
& AFL_ASE_VIRT
)
16188 fputs ("\n\tVZ ASE", stdout
);
16189 if (mask
& AFL_ASE_MSA
)
16190 fputs ("\n\tMSA ASE", stdout
);
16191 if (mask
& AFL_ASE_MIPS16
)
16192 fputs ("\n\tMIPS16 ASE", stdout
);
16193 if (mask
& AFL_ASE_MICROMIPS
)
16194 fputs ("\n\tMICROMIPS ASE", stdout
);
16195 if (mask
& AFL_ASE_XPA
)
16196 fputs ("\n\tXPA ASE", stdout
);
16197 if (mask
& AFL_ASE_MIPS16E2
)
16198 fputs ("\n\tMIPS16e2 ASE", stdout
);
16199 if (mask
& AFL_ASE_CRC
)
16200 fputs ("\n\tCRC ASE", stdout
);
16201 if (mask
& AFL_ASE_GINV
)
16202 fputs ("\n\tGINV ASE", stdout
);
16203 if (mask
& AFL_ASE_LOONGSON_MMI
)
16204 fputs ("\n\tLoongson MMI ASE", stdout
);
16205 if (mask
& AFL_ASE_LOONGSON_CAM
)
16206 fputs ("\n\tLoongson CAM ASE", stdout
);
16207 if (mask
& AFL_ASE_LOONGSON_EXT
)
16208 fputs ("\n\tLoongson EXT ASE", stdout
);
16209 if (mask
& AFL_ASE_LOONGSON_EXT2
)
16210 fputs ("\n\tLoongson EXT2 ASE", stdout
);
16212 fprintf (stdout
, "\n\t%s", _("None"));
16213 else if ((mask
& ~AFL_ASE_MASK
) != 0)
16214 fprintf (stdout
, "\n\t%s (%x)", _("Unknown"), mask
& ~AFL_ASE_MASK
);
16218 print_mips_isa_ext (unsigned int isa_ext
)
16223 fputs (_("None"), stdout
);
16226 fputs ("RMI XLR", stdout
);
16228 case AFL_EXT_OCTEON3
:
16229 fputs ("Cavium Networks Octeon3", stdout
);
16231 case AFL_EXT_OCTEON2
:
16232 fputs ("Cavium Networks Octeon2", stdout
);
16234 case AFL_EXT_OCTEONP
:
16235 fputs ("Cavium Networks OcteonP", stdout
);
16237 case AFL_EXT_OCTEON
:
16238 fputs ("Cavium Networks Octeon", stdout
);
16241 fputs ("Toshiba R5900", stdout
);
16244 fputs ("MIPS R4650", stdout
);
16247 fputs ("LSI R4010", stdout
);
16250 fputs ("NEC VR4100", stdout
);
16253 fputs ("Toshiba R3900", stdout
);
16255 case AFL_EXT_10000
:
16256 fputs ("MIPS R10000", stdout
);
16259 fputs ("Broadcom SB-1", stdout
);
16262 fputs ("NEC VR4111/VR4181", stdout
);
16265 fputs ("NEC VR4120", stdout
);
16268 fputs ("NEC VR5400", stdout
);
16271 fputs ("NEC VR5500", stdout
);
16273 case AFL_EXT_LOONGSON_2E
:
16274 fputs ("ST Microelectronics Loongson 2E", stdout
);
16276 case AFL_EXT_LOONGSON_2F
:
16277 fputs ("ST Microelectronics Loongson 2F", stdout
);
16279 case AFL_EXT_INTERAPTIV_MR2
:
16280 fputs ("Imagination interAptiv MR2", stdout
);
16283 fprintf (stdout
, "%s (%d)", _("Unknown"), isa_ext
);
16288 get_mips_reg_size (int reg_size
)
16290 return (reg_size
== AFL_REG_NONE
) ? 0
16291 : (reg_size
== AFL_REG_32
) ? 32
16292 : (reg_size
== AFL_REG_64
) ? 64
16293 : (reg_size
== AFL_REG_128
) ? 128
16298 process_mips_specific (Filedata
* filedata
)
16300 Elf_Internal_Dyn
* entry
;
16301 Elf_Internal_Shdr
*sect
= NULL
;
16302 size_t liblist_offset
= 0;
16303 size_t liblistno
= 0;
16304 size_t conflictsno
= 0;
16305 size_t options_offset
= 0;
16306 size_t conflicts_offset
= 0;
16307 size_t pltrelsz
= 0;
16309 bfd_vma pltgot
= 0;
16310 bfd_vma mips_pltgot
= 0;
16311 bfd_vma jmprel
= 0;
16312 bfd_vma local_gotno
= 0;
16313 bfd_vma gotsym
= 0;
16314 bfd_vma symtabno
= 0;
16315 bfd_boolean res
= TRUE
;
16317 if (! process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
16318 display_mips_gnu_attribute
))
16321 sect
= find_section (filedata
, ".MIPS.abiflags");
16325 Elf_External_ABIFlags_v0
*abiflags_ext
;
16326 Elf_Internal_ABIFlags_v0 abiflags_in
;
16328 if (sizeof (Elf_External_ABIFlags_v0
) != sect
->sh_size
)
16330 error (_("Corrupt MIPS ABI Flags section.\n"));
16335 abiflags_ext
= get_data (NULL
, filedata
, sect
->sh_offset
, 1,
16336 sect
->sh_size
, _("MIPS ABI Flags section"));
16339 abiflags_in
.version
= BYTE_GET (abiflags_ext
->version
);
16340 abiflags_in
.isa_level
= BYTE_GET (abiflags_ext
->isa_level
);
16341 abiflags_in
.isa_rev
= BYTE_GET (abiflags_ext
->isa_rev
);
16342 abiflags_in
.gpr_size
= BYTE_GET (abiflags_ext
->gpr_size
);
16343 abiflags_in
.cpr1_size
= BYTE_GET (abiflags_ext
->cpr1_size
);
16344 abiflags_in
.cpr2_size
= BYTE_GET (abiflags_ext
->cpr2_size
);
16345 abiflags_in
.fp_abi
= BYTE_GET (abiflags_ext
->fp_abi
);
16346 abiflags_in
.isa_ext
= BYTE_GET (abiflags_ext
->isa_ext
);
16347 abiflags_in
.ases
= BYTE_GET (abiflags_ext
->ases
);
16348 abiflags_in
.flags1
= BYTE_GET (abiflags_ext
->flags1
);
16349 abiflags_in
.flags2
= BYTE_GET (abiflags_ext
->flags2
);
16351 printf ("\nMIPS ABI Flags Version: %d\n", abiflags_in
.version
);
16352 printf ("\nISA: MIPS%d", abiflags_in
.isa_level
);
16353 if (abiflags_in
.isa_rev
> 1)
16354 printf ("r%d", abiflags_in
.isa_rev
);
16355 printf ("\nGPR size: %d",
16356 get_mips_reg_size (abiflags_in
.gpr_size
));
16357 printf ("\nCPR1 size: %d",
16358 get_mips_reg_size (abiflags_in
.cpr1_size
));
16359 printf ("\nCPR2 size: %d",
16360 get_mips_reg_size (abiflags_in
.cpr2_size
));
16361 fputs ("\nFP ABI: ", stdout
);
16362 print_mips_fp_abi_value (abiflags_in
.fp_abi
);
16363 fputs ("ISA Extension: ", stdout
);
16364 print_mips_isa_ext (abiflags_in
.isa_ext
);
16365 fputs ("\nASEs:", stdout
);
16366 print_mips_ases (abiflags_in
.ases
);
16367 printf ("\nFLAGS 1: %8.8lx", abiflags_in
.flags1
);
16368 printf ("\nFLAGS 2: %8.8lx", abiflags_in
.flags2
);
16369 fputc ('\n', stdout
);
16370 free (abiflags_ext
);
16375 /* We have a lot of special sections. Thanks SGI! */
16376 if (dynamic_section
== NULL
)
16378 /* No dynamic information available. See if there is static GOT. */
16379 sect
= find_section (filedata
, ".got");
16382 unsigned char *data_end
;
16383 unsigned char *data
;
16387 pltgot
= sect
->sh_addr
;
16390 addr_size
= (is_32bit_elf
? 4 : 8);
16391 end
= pltgot
+ sect
->sh_size
;
16393 data
= (unsigned char *) get_data (NULL
, filedata
, sect
->sh_offset
,
16395 _("Global Offset Table data"));
16396 /* PR 12855: Null data is handled gracefully throughout. */
16397 data_end
= data
+ (end
- pltgot
);
16399 printf (_("\nStatic GOT:\n"));
16400 printf (_(" Canonical gp value: "));
16401 print_vma (ent
+ 0x7ff0, LONG_HEX
);
16404 /* In a dynamic binary GOT[0] is reserved for the dynamic
16405 loader to store the lazy resolver pointer, however in
16406 a static binary it may well have been omitted and GOT
16407 reduced to a table of addresses.
16408 PR 21344: Check for the entry being fully available
16409 before fetching it. */
16411 && data
+ ent
- pltgot
+ addr_size
<= data_end
16412 && byte_get (data
+ ent
- pltgot
, addr_size
) == 0)
16414 printf (_(" Reserved entries:\n"));
16415 printf (_(" %*s %10s %*s\n"),
16416 addr_size
* 2, _("Address"), _("Access"),
16417 addr_size
* 2, _("Value"));
16418 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
16420 if (ent
== (bfd_vma
) -1)
16421 goto sgot_print_fail
;
16423 /* Check for the MSB of GOT[1] being set, identifying a
16424 GNU object. This entry will be used by some runtime
16425 loaders, to store the module pointer. Otherwise this
16426 is an ordinary local entry.
16427 PR 21344: Check for the entry being fully available
16428 before fetching it. */
16430 && data
+ ent
- pltgot
+ addr_size
<= data_end
16431 && (byte_get (data
+ ent
- pltgot
, addr_size
)
16432 >> (addr_size
* 8 - 1)) != 0)
16434 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
16436 if (ent
== (bfd_vma
) -1)
16437 goto sgot_print_fail
;
16442 if (data
!= NULL
&& ent
< end
)
16444 printf (_(" Local entries:\n"));
16445 printf (" %*s %10s %*s\n",
16446 addr_size
* 2, _("Address"), _("Access"),
16447 addr_size
* 2, _("Value"));
16450 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
16452 if (ent
== (bfd_vma
) -1)
16453 goto sgot_print_fail
;
16465 for (entry
= dynamic_section
;
16466 /* PR 17531 file: 012-50589-0.004. */
16467 entry
< dynamic_section
+ dynamic_nent
&& entry
->d_tag
!= DT_NULL
;
16469 switch (entry
->d_tag
)
16471 case DT_MIPS_LIBLIST
:
16473 = offset_from_vma (filedata
, entry
->d_un
.d_val
,
16474 liblistno
* sizeof (Elf32_External_Lib
));
16476 case DT_MIPS_LIBLISTNO
:
16477 liblistno
= entry
->d_un
.d_val
;
16479 case DT_MIPS_OPTIONS
:
16480 options_offset
= offset_from_vma (filedata
, entry
->d_un
.d_val
, 0);
16482 case DT_MIPS_CONFLICT
:
16484 = offset_from_vma (filedata
, entry
->d_un
.d_val
,
16485 conflictsno
* sizeof (Elf32_External_Conflict
));
16487 case DT_MIPS_CONFLICTNO
:
16488 conflictsno
= entry
->d_un
.d_val
;
16491 pltgot
= entry
->d_un
.d_ptr
;
16493 case DT_MIPS_LOCAL_GOTNO
:
16494 local_gotno
= entry
->d_un
.d_val
;
16496 case DT_MIPS_GOTSYM
:
16497 gotsym
= entry
->d_un
.d_val
;
16499 case DT_MIPS_SYMTABNO
:
16500 symtabno
= entry
->d_un
.d_val
;
16502 case DT_MIPS_PLTGOT
:
16503 mips_pltgot
= entry
->d_un
.d_ptr
;
16506 pltrel
= entry
->d_un
.d_val
;
16509 pltrelsz
= entry
->d_un
.d_val
;
16512 jmprel
= entry
->d_un
.d_ptr
;
16518 if (liblist_offset
!= 0 && liblistno
!= 0 && do_dynamic
)
16520 Elf32_External_Lib
* elib
;
16523 elib
= (Elf32_External_Lib
*) get_data (NULL
, filedata
, liblist_offset
,
16525 sizeof (Elf32_External_Lib
),
16526 _("liblist section data"));
16529 printf (ngettext ("\nSection '.liblist' contains %lu entry:\n",
16530 "\nSection '.liblist' contains %lu entries:\n",
16531 (unsigned long) liblistno
),
16532 (unsigned long) liblistno
);
16533 fputs (_(" Library Time Stamp Checksum Version Flags\n"),
16536 for (cnt
= 0; cnt
< liblistno
; ++cnt
)
16543 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
16544 atime
= BYTE_GET (elib
[cnt
].l_time_stamp
);
16545 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
16546 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
16547 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
16549 tmp
= gmtime (&atime
);
16550 snprintf (timebuf
, sizeof (timebuf
),
16551 "%04u-%02u-%02uT%02u:%02u:%02u",
16552 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
16553 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
16555 printf ("%3lu: ", (unsigned long) cnt
);
16556 if (VALID_DYNAMIC_NAME (liblist
.l_name
))
16557 print_symbol (20, GET_DYNAMIC_NAME (liblist
.l_name
));
16559 printf (_("<corrupt: %9ld>"), liblist
.l_name
);
16560 printf (" %s %#10lx %-7ld", timebuf
, liblist
.l_checksum
,
16561 liblist
.l_version
);
16563 if (liblist
.l_flags
== 0)
16567 static const struct
16574 { " EXACT_MATCH", LL_EXACT_MATCH
},
16575 { " IGNORE_INT_VER", LL_IGNORE_INT_VER
},
16576 { " REQUIRE_MINOR", LL_REQUIRE_MINOR
},
16577 { " EXPORTS", LL_EXPORTS
},
16578 { " DELAY_LOAD", LL_DELAY_LOAD
},
16579 { " DELTA", LL_DELTA
}
16581 int flags
= liblist
.l_flags
;
16584 for (fcnt
= 0; fcnt
< ARRAY_SIZE (l_flags_vals
); ++fcnt
)
16585 if ((flags
& l_flags_vals
[fcnt
].bit
) != 0)
16587 fputs (l_flags_vals
[fcnt
].name
, stdout
);
16588 flags
^= l_flags_vals
[fcnt
].bit
;
16591 printf (" %#x", (unsigned int) flags
);
16603 if (options_offset
!= 0)
16605 Elf_External_Options
* eopt
;
16608 sect
= filedata
->section_headers
;
16610 /* Find the section header so that we get the size. */
16611 sect
= find_section_by_type (filedata
, SHT_MIPS_OPTIONS
);
16612 /* PR 17533 file: 012-277276-0.004. */
16615 error (_("No MIPS_OPTIONS header found\n"));
16619 if (sect
->sh_size
< sizeof (* eopt
))
16621 error (_("The MIPS options section is too small.\n"));
16625 eopt
= (Elf_External_Options
*) get_data (NULL
, filedata
, options_offset
, 1,
16626 sect
->sh_size
, _("options"));
16629 Elf_Internal_Options
* iopt
;
16630 Elf_Internal_Options
* option
;
16631 Elf_Internal_Options
* iopt_end
;
16633 iopt
= (Elf_Internal_Options
*)
16634 cmalloc ((sect
->sh_size
/ sizeof (eopt
)), sizeof (* iopt
));
16637 error (_("Out of memory allocating space for MIPS options\n"));
16643 iopt_end
= iopt
+ (sect
->sh_size
/ sizeof (eopt
));
16645 while (offset
<= sect
->sh_size
- sizeof (* eopt
))
16647 Elf_External_Options
* eoption
;
16649 eoption
= (Elf_External_Options
*) ((char *) eopt
+ offset
);
16651 option
->kind
= BYTE_GET (eoption
->kind
);
16652 option
->size
= BYTE_GET (eoption
->size
);
16653 option
->section
= BYTE_GET (eoption
->section
);
16654 option
->info
= BYTE_GET (eoption
->info
);
16656 /* PR 17531: file: ffa0fa3b. */
16657 if (option
->size
< sizeof (* eopt
)
16658 || offset
+ option
->size
> sect
->sh_size
)
16660 error (_("Invalid size (%u) for MIPS option\n"), option
->size
);
16663 offset
+= option
->size
;
16669 printf (ngettext ("\nSection '%s' contains %d entry:\n",
16670 "\nSection '%s' contains %d entries:\n",
16672 printable_section_name (filedata
, sect
), cnt
);
16681 switch (option
->kind
)
16684 /* This shouldn't happen. */
16685 printf (" NULL %d %lx", option
->section
, option
->info
);
16689 printf (" REGINFO ");
16690 if (filedata
->file_header
.e_machine
== EM_MIPS
)
16692 Elf32_External_RegInfo
* ereg
;
16693 Elf32_RegInfo reginfo
;
16696 if (option
+ 2 > iopt_end
)
16698 printf (_("<corrupt>\n"));
16699 error (_("Truncated MIPS REGINFO option\n"));
16704 ereg
= (Elf32_External_RegInfo
*) (option
+ 1);
16706 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
16707 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
16708 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
16709 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
16710 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
16711 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
16713 printf ("GPR %08lx GP 0x%lx\n",
16714 reginfo
.ri_gprmask
,
16715 (unsigned long) reginfo
.ri_gp_value
);
16716 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
16717 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
16718 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
16723 Elf64_External_RegInfo
* ereg
;
16724 Elf64_Internal_RegInfo reginfo
;
16726 if (option
+ 2 > iopt_end
)
16728 printf (_("<corrupt>\n"));
16729 error (_("Truncated MIPS REGINFO option\n"));
16734 ereg
= (Elf64_External_RegInfo
*) (option
+ 1);
16735 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
16736 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
16737 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
16738 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
16739 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
16740 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
16742 printf ("GPR %08lx GP 0x",
16743 reginfo
.ri_gprmask
);
16744 printf_vma (reginfo
.ri_gp_value
);
16747 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
16748 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
16749 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
16754 case ODK_EXCEPTIONS
:
16755 fputs (" EXCEPTIONS fpe_min(", stdout
);
16756 process_mips_fpe_exception (option
->info
& OEX_FPU_MIN
);
16757 fputs (") fpe_max(", stdout
);
16758 process_mips_fpe_exception ((option
->info
& OEX_FPU_MAX
) >> 8);
16759 fputs (")", stdout
);
16761 if (option
->info
& OEX_PAGE0
)
16762 fputs (" PAGE0", stdout
);
16763 if (option
->info
& OEX_SMM
)
16764 fputs (" SMM", stdout
);
16765 if (option
->info
& OEX_FPDBUG
)
16766 fputs (" FPDBUG", stdout
);
16767 if (option
->info
& OEX_DISMISS
)
16768 fputs (" DISMISS", stdout
);
16772 fputs (" PAD ", stdout
);
16773 if (option
->info
& OPAD_PREFIX
)
16774 fputs (" PREFIX", stdout
);
16775 if (option
->info
& OPAD_POSTFIX
)
16776 fputs (" POSTFIX", stdout
);
16777 if (option
->info
& OPAD_SYMBOL
)
16778 fputs (" SYMBOL", stdout
);
16782 fputs (" HWPATCH ", stdout
);
16783 if (option
->info
& OHW_R4KEOP
)
16784 fputs (" R4KEOP", stdout
);
16785 if (option
->info
& OHW_R8KPFETCH
)
16786 fputs (" R8KPFETCH", stdout
);
16787 if (option
->info
& OHW_R5KEOP
)
16788 fputs (" R5KEOP", stdout
);
16789 if (option
->info
& OHW_R5KCVTL
)
16790 fputs (" R5KCVTL", stdout
);
16794 fputs (" FILL ", stdout
);
16795 /* XXX Print content of info word? */
16799 fputs (" TAGS ", stdout
);
16800 /* XXX Print content of info word? */
16804 fputs (" HWAND ", stdout
);
16805 if (option
->info
& OHWA0_R4KEOP_CHECKED
)
16806 fputs (" R4KEOP_CHECKED", stdout
);
16807 if (option
->info
& OHWA0_R4KEOP_CLEAN
)
16808 fputs (" R4KEOP_CLEAN", stdout
);
16812 fputs (" HWOR ", stdout
);
16813 if (option
->info
& OHWA0_R4KEOP_CHECKED
)
16814 fputs (" R4KEOP_CHECKED", stdout
);
16815 if (option
->info
& OHWA0_R4KEOP_CLEAN
)
16816 fputs (" R4KEOP_CLEAN", stdout
);
16820 printf (" GP_GROUP %#06lx self-contained %#06lx",
16821 option
->info
& OGP_GROUP
,
16822 (option
->info
& OGP_SELF
) >> 16);
16826 printf (" IDENT %#06lx self-contained %#06lx",
16827 option
->info
& OGP_GROUP
,
16828 (option
->info
& OGP_SELF
) >> 16);
16832 /* This shouldn't happen. */
16833 printf (" %3d ??? %d %lx",
16834 option
->kind
, option
->section
, option
->info
);
16838 len
= sizeof (* eopt
);
16839 while (len
< option
->size
)
16841 unsigned char datum
= * ((unsigned char *) eopt
+ offset
+ len
);
16843 if (ISPRINT (datum
))
16844 printf ("%c", datum
);
16846 printf ("\\%03o", datum
);
16849 fputs ("\n", stdout
);
16851 offset
+= option
->size
;
16861 if (conflicts_offset
!= 0 && conflictsno
!= 0)
16863 Elf32_Conflict
* iconf
;
16866 if (dynamic_symbols
== NULL
)
16868 error (_("conflict list found without a dynamic symbol table\n"));
16872 /* PR 21345 - print a slightly more helpful error message
16873 if we are sure that the cmalloc will fail. */
16874 if (conflictsno
* sizeof (* iconf
) > filedata
->file_size
)
16876 error (_("Overlarge number of conflicts detected: %lx\n"),
16877 (long) conflictsno
);
16881 iconf
= (Elf32_Conflict
*) cmalloc (conflictsno
, sizeof (* iconf
));
16884 error (_("Out of memory allocating space for dynamic conflicts\n"));
16890 Elf32_External_Conflict
* econf32
;
16892 econf32
= (Elf32_External_Conflict
*)
16893 get_data (NULL
, filedata
, conflicts_offset
, conflictsno
,
16894 sizeof (* econf32
), _("conflict"));
16898 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
16899 iconf
[cnt
] = BYTE_GET (econf32
[cnt
]);
16905 Elf64_External_Conflict
* econf64
;
16907 econf64
= (Elf64_External_Conflict
*)
16908 get_data (NULL
, filedata
, conflicts_offset
, conflictsno
,
16909 sizeof (* econf64
), _("conflict"));
16913 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
16914 iconf
[cnt
] = BYTE_GET (econf64
[cnt
]);
16919 printf (ngettext ("\nSection '.conflict' contains %lu entry:\n",
16920 "\nSection '.conflict' contains %lu entries:\n",
16921 (unsigned long) conflictsno
),
16922 (unsigned long) conflictsno
);
16923 puts (_(" Num: Index Value Name"));
16925 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
16927 printf ("%5lu: %8lu ", (unsigned long) cnt
, iconf
[cnt
]);
16929 if (iconf
[cnt
] >= num_dynamic_syms
)
16930 printf (_("<corrupt symbol index>"));
16933 Elf_Internal_Sym
* psym
;
16935 psym
= & dynamic_symbols
[iconf
[cnt
]];
16936 print_vma (psym
->st_value
, FULL_HEX
);
16938 if (VALID_DYNAMIC_NAME (psym
->st_name
))
16939 print_symbol (25, GET_DYNAMIC_NAME (psym
->st_name
));
16941 printf (_("<corrupt: %14ld>"), psym
->st_name
);
16949 if (pltgot
!= 0 && local_gotno
!= 0)
16951 bfd_vma ent
, local_end
, global_end
;
16953 unsigned char * data
;
16954 unsigned char * data_end
;
16958 addr_size
= (is_32bit_elf
? 4 : 8);
16959 local_end
= pltgot
+ local_gotno
* addr_size
;
16961 /* PR binutils/17533 file: 012-111227-0.004 */
16962 if (symtabno
< gotsym
)
16964 error (_("The GOT symbol offset (%lu) is greater than the symbol table size (%lu)\n"),
16965 (unsigned long) gotsym
, (unsigned long) symtabno
);
16969 global_end
= local_end
+ (symtabno
- gotsym
) * addr_size
;
16970 /* PR 17531: file: 54c91a34. */
16971 if (global_end
< local_end
)
16973 error (_("Too many GOT symbols: %lu\n"), (unsigned long) symtabno
);
16977 offset
= offset_from_vma (filedata
, pltgot
, global_end
- pltgot
);
16978 data
= (unsigned char *) get_data (NULL
, filedata
, offset
,
16979 global_end
- pltgot
, 1,
16980 _("Global Offset Table data"));
16981 /* PR 12855: Null data is handled gracefully throughout. */
16982 data_end
= data
+ (global_end
- pltgot
);
16984 printf (_("\nPrimary GOT:\n"));
16985 printf (_(" Canonical gp value: "));
16986 print_vma (pltgot
+ 0x7ff0, LONG_HEX
);
16989 printf (_(" Reserved entries:\n"));
16990 printf (_(" %*s %10s %*s Purpose\n"),
16991 addr_size
* 2, _("Address"), _("Access"),
16992 addr_size
* 2, _("Initial"));
16993 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
16994 printf (_(" Lazy resolver\n"));
16995 if (ent
== (bfd_vma
) -1)
16996 goto got_print_fail
;
16998 /* Check for the MSB of GOT[1] being set, denoting a GNU object.
16999 This entry will be used by some runtime loaders, to store the
17000 module pointer. Otherwise this is an ordinary local entry.
17001 PR 21344: Check for the entry being fully available before
17004 && data
+ ent
- pltgot
+ addr_size
<= data_end
17005 && (byte_get (data
+ ent
- pltgot
, addr_size
)
17006 >> (addr_size
* 8 - 1)) != 0)
17008 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
17009 printf (_(" Module pointer (GNU extension)\n"));
17010 if (ent
== (bfd_vma
) -1)
17011 goto got_print_fail
;
17015 if (data
!= NULL
&& ent
< local_end
)
17017 printf (_(" Local entries:\n"));
17018 printf (" %*s %10s %*s\n",
17019 addr_size
* 2, _("Address"), _("Access"),
17020 addr_size
* 2, _("Initial"));
17021 while (ent
< local_end
)
17023 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
17025 if (ent
== (bfd_vma
) -1)
17026 goto got_print_fail
;
17031 if (data
!= NULL
&& gotsym
< symtabno
)
17035 printf (_(" Global entries:\n"));
17036 printf (" %*s %10s %*s %*s %-7s %3s %s\n",
17037 addr_size
* 2, _("Address"),
17039 addr_size
* 2, _("Initial"),
17040 addr_size
* 2, _("Sym.Val."),
17042 /* Note for translators: "Ndx" = abbreviated form of "Index". */
17043 _("Ndx"), _("Name"));
17045 sym_width
= (is_32bit_elf
? 80 : 160) - 28 - addr_size
* 6 - 1;
17047 for (i
= gotsym
; i
< symtabno
; i
++)
17049 ent
= print_mips_got_entry (data
, pltgot
, ent
, data_end
);
17052 if (dynamic_symbols
== NULL
)
17053 printf (_("<no dynamic symbols>"));
17054 else if (i
< num_dynamic_syms
)
17056 Elf_Internal_Sym
* psym
= dynamic_symbols
+ i
;
17058 print_vma (psym
->st_value
, LONG_HEX
);
17059 printf (" %-7s %3s ",
17060 get_symbol_type (filedata
, ELF_ST_TYPE (psym
->st_info
)),
17061 get_symbol_index_type (filedata
, psym
->st_shndx
));
17063 if (VALID_DYNAMIC_NAME (psym
->st_name
))
17064 print_symbol (sym_width
, GET_DYNAMIC_NAME (psym
->st_name
));
17066 printf (_("<corrupt: %14ld>"), psym
->st_name
);
17069 printf (_("<symbol index %lu exceeds number of dynamic symbols>"),
17070 (unsigned long) i
);
17073 if (ent
== (bfd_vma
) -1)
17084 if (mips_pltgot
!= 0 && jmprel
!= 0 && pltrel
!= 0 && pltrelsz
!= 0)
17087 size_t offset
, rel_offset
;
17088 unsigned long count
, i
;
17089 unsigned char * data
;
17090 int addr_size
, sym_width
;
17091 Elf_Internal_Rela
* rels
;
17093 rel_offset
= offset_from_vma (filedata
, jmprel
, pltrelsz
);
17094 if (pltrel
== DT_RELA
)
17096 if (!slurp_rela_relocs (filedata
, rel_offset
, pltrelsz
, &rels
, &count
))
17101 if (!slurp_rel_relocs (filedata
, rel_offset
, pltrelsz
, &rels
, &count
))
17106 addr_size
= (is_32bit_elf
? 4 : 8);
17107 end
= mips_pltgot
+ (2 + count
) * addr_size
;
17109 offset
= offset_from_vma (filedata
, mips_pltgot
, end
- mips_pltgot
);
17110 data
= (unsigned char *) get_data (NULL
, filedata
, offset
, end
- mips_pltgot
,
17111 1, _("Procedure Linkage Table data"));
17115 printf ("\nPLT GOT:\n\n");
17116 printf (_(" Reserved entries:\n"));
17117 printf (_(" %*s %*s Purpose\n"),
17118 addr_size
* 2, _("Address"), addr_size
* 2, _("Initial"));
17119 ent
= print_mips_pltgot_entry (data
, mips_pltgot
, ent
);
17120 printf (_(" PLT lazy resolver\n"));
17121 ent
= print_mips_pltgot_entry (data
, mips_pltgot
, ent
);
17122 printf (_(" Module pointer\n"));
17125 printf (_(" Entries:\n"));
17126 printf (" %*s %*s %*s %-7s %3s %s\n",
17127 addr_size
* 2, _("Address"),
17128 addr_size
* 2, _("Initial"),
17129 addr_size
* 2, _("Sym.Val."), _("Type"), _("Ndx"), _("Name"));
17130 sym_width
= (is_32bit_elf
? 80 : 160) - 17 - addr_size
* 6 - 1;
17131 for (i
= 0; i
< count
; i
++)
17133 unsigned long idx
= get_reloc_symindex (rels
[i
].r_info
);
17135 ent
= print_mips_pltgot_entry (data
, mips_pltgot
, ent
);
17138 if (idx
>= num_dynamic_syms
)
17139 printf (_("<corrupt symbol index: %lu>"), idx
);
17142 Elf_Internal_Sym
* psym
= dynamic_symbols
+ idx
;
17144 print_vma (psym
->st_value
, LONG_HEX
);
17145 printf (" %-7s %3s ",
17146 get_symbol_type (filedata
, ELF_ST_TYPE (psym
->st_info
)),
17147 get_symbol_index_type (filedata
, psym
->st_shndx
));
17148 if (VALID_DYNAMIC_NAME (psym
->st_name
))
17149 print_symbol (sym_width
, GET_DYNAMIC_NAME (psym
->st_name
));
17151 printf (_("<corrupt: %14ld>"), psym
->st_name
);
17166 process_nds32_specific (Filedata
* filedata
)
17168 Elf_Internal_Shdr
*sect
= NULL
;
17170 sect
= find_section (filedata
, ".nds32_e_flags");
17173 unsigned int *flag
;
17175 printf ("\nNDS32 elf flags section:\n");
17176 flag
= get_data (NULL
, filedata
, sect
->sh_offset
, 1,
17177 sect
->sh_size
, _("NDS32 elf flags section"));
17182 switch ((*flag
) & 0x3)
17185 printf ("(VEC_SIZE):\tNo entry.\n");
17188 printf ("(VEC_SIZE):\t4 bytes\n");
17191 printf ("(VEC_SIZE):\t16 bytes\n");
17194 printf ("(VEC_SIZE):\treserved\n");
17203 process_gnu_liblist (Filedata
* filedata
)
17205 Elf_Internal_Shdr
* section
;
17206 Elf_Internal_Shdr
* string_sec
;
17207 Elf32_External_Lib
* elib
;
17209 size_t strtab_size
;
17211 unsigned long num_liblist
;
17213 bfd_boolean res
= TRUE
;
17218 for (i
= 0, section
= filedata
->section_headers
;
17219 i
< filedata
->file_header
.e_shnum
;
17222 switch (section
->sh_type
)
17224 case SHT_GNU_LIBLIST
:
17225 if (section
->sh_link
>= filedata
->file_header
.e_shnum
)
17228 elib
= (Elf32_External_Lib
*)
17229 get_data (NULL
, filedata
, section
->sh_offset
, 1, section
->sh_size
,
17230 _("liblist section data"));
17238 string_sec
= filedata
->section_headers
+ section
->sh_link
;
17239 strtab
= (char *) get_data (NULL
, filedata
, string_sec
->sh_offset
, 1,
17240 string_sec
->sh_size
,
17241 _("liblist string table"));
17243 || section
->sh_entsize
!= sizeof (Elf32_External_Lib
))
17250 strtab_size
= string_sec
->sh_size
;
17252 num_liblist
= section
->sh_size
/ sizeof (Elf32_External_Lib
);
17253 printf (ngettext ("\nLibrary list section '%s' contains %lu entries:\n",
17254 "\nLibrary list section '%s' contains %lu entries:\n",
17256 printable_section_name (filedata
, section
),
17259 puts (_(" Library Time Stamp Checksum Version Flags"));
17261 for (cnt
= 0; cnt
< section
->sh_size
/ sizeof (Elf32_External_Lib
);
17269 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
17270 atime
= BYTE_GET (elib
[cnt
].l_time_stamp
);
17271 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
17272 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
17273 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
17275 tmp
= gmtime (&atime
);
17276 snprintf (timebuf
, sizeof (timebuf
),
17277 "%04u-%02u-%02uT%02u:%02u:%02u",
17278 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
17279 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
17281 printf ("%3lu: ", (unsigned long) cnt
);
17283 printf ("%-20s", liblist
.l_name
< strtab_size
17284 ? strtab
+ liblist
.l_name
: _("<corrupt>"));
17286 printf ("%-20.20s", liblist
.l_name
< strtab_size
17287 ? strtab
+ liblist
.l_name
: _("<corrupt>"));
17288 printf (" %s %#010lx %-7ld %-7ld\n", timebuf
, liblist
.l_checksum
,
17289 liblist
.l_version
, liblist
.l_flags
);
17300 static const char *
17301 get_note_type (Filedata
* filedata
, unsigned e_type
)
17303 static char buff
[64];
17305 if (filedata
->file_header
.e_type
== ET_CORE
)
17309 return _("NT_AUXV (auxiliary vector)");
17311 return _("NT_PRSTATUS (prstatus structure)");
17313 return _("NT_FPREGSET (floating point registers)");
17315 return _("NT_PRPSINFO (prpsinfo structure)");
17316 case NT_TASKSTRUCT
:
17317 return _("NT_TASKSTRUCT (task structure)");
17319 return _("NT_PRXFPREG (user_xfpregs structure)");
17321 return _("NT_PPC_VMX (ppc Altivec registers)");
17323 return _("NT_PPC_VSX (ppc VSX registers)");
17325 return _("NT_PPC_TAR (ppc TAR register)");
17327 return _("NT_PPC_PPR (ppc PPR register)");
17329 return _("NT_PPC_DSCR (ppc DSCR register)");
17331 return _("NT_PPC_EBB (ppc EBB registers)");
17333 return _("NT_PPC_PMU (ppc PMU registers)");
17334 case NT_PPC_TM_CGPR
:
17335 return _("NT_PPC_TM_CGPR (ppc checkpointed GPR registers)");
17336 case NT_PPC_TM_CFPR
:
17337 return _("NT_PPC_TM_CFPR (ppc checkpointed floating point registers)");
17338 case NT_PPC_TM_CVMX
:
17339 return _("NT_PPC_TM_CVMX (ppc checkpointed Altivec registers)");
17340 case NT_PPC_TM_CVSX
:
17341 return _("NT_PPC_TM_CVSX (ppc checkpointed VSX registers)");
17342 case NT_PPC_TM_SPR
:
17343 return _("NT_PPC_TM_SPR (ppc TM special purpose registers)");
17344 case NT_PPC_TM_CTAR
:
17345 return _("NT_PPC_TM_CTAR (ppc checkpointed TAR register)");
17346 case NT_PPC_TM_CPPR
:
17347 return _("NT_PPC_TM_CPPR (ppc checkpointed PPR register)");
17348 case NT_PPC_TM_CDSCR
:
17349 return _("NT_PPC_TM_CDSCR (ppc checkpointed DSCR register)");
17351 return _("NT_386_TLS (x86 TLS information)");
17352 case NT_386_IOPERM
:
17353 return _("NT_386_IOPERM (x86 I/O permissions)");
17354 case NT_X86_XSTATE
:
17355 return _("NT_X86_XSTATE (x86 XSAVE extended state)");
17356 case NT_S390_HIGH_GPRS
:
17357 return _("NT_S390_HIGH_GPRS (s390 upper register halves)");
17358 case NT_S390_TIMER
:
17359 return _("NT_S390_TIMER (s390 timer register)");
17360 case NT_S390_TODCMP
:
17361 return _("NT_S390_TODCMP (s390 TOD comparator register)");
17362 case NT_S390_TODPREG
:
17363 return _("NT_S390_TODPREG (s390 TOD programmable register)");
17365 return _("NT_S390_CTRS (s390 control registers)");
17366 case NT_S390_PREFIX
:
17367 return _("NT_S390_PREFIX (s390 prefix register)");
17368 case NT_S390_LAST_BREAK
:
17369 return _("NT_S390_LAST_BREAK (s390 last breaking event address)");
17370 case NT_S390_SYSTEM_CALL
:
17371 return _("NT_S390_SYSTEM_CALL (s390 system call restart data)");
17373 return _("NT_S390_TDB (s390 transaction diagnostic block)");
17374 case NT_S390_VXRS_LOW
:
17375 return _("NT_S390_VXRS_LOW (s390 vector registers 0-15 upper half)");
17376 case NT_S390_VXRS_HIGH
:
17377 return _("NT_S390_VXRS_HIGH (s390 vector registers 16-31)");
17378 case NT_S390_GS_CB
:
17379 return _("NT_S390_GS_CB (s390 guarded-storage registers)");
17380 case NT_S390_GS_BC
:
17381 return _("NT_S390_GS_BC (s390 guarded-storage broadcast control)");
17383 return _("NT_ARM_VFP (arm VFP registers)");
17385 return _("NT_ARM_TLS (AArch TLS registers)");
17386 case NT_ARM_HW_BREAK
:
17387 return _("NT_ARM_HW_BREAK (AArch hardware breakpoint registers)");
17388 case NT_ARM_HW_WATCH
:
17389 return _("NT_ARM_HW_WATCH (AArch hardware watchpoint registers)");
17391 return _("NT_PSTATUS (pstatus structure)");
17393 return _("NT_FPREGS (floating point registers)");
17395 return _("NT_PSINFO (psinfo structure)");
17397 return _("NT_LWPSTATUS (lwpstatus_t structure)");
17399 return _("NT_LWPSINFO (lwpsinfo_t structure)");
17400 case NT_WIN32PSTATUS
:
17401 return _("NT_WIN32PSTATUS (win32_pstatus structure)");
17403 return _("NT_SIGINFO (siginfo_t data)");
17405 return _("NT_FILE (mapped files)");
17413 return _("NT_VERSION (version)");
17415 return _("NT_ARCH (architecture)");
17416 case NT_GNU_BUILD_ATTRIBUTE_OPEN
:
17418 case NT_GNU_BUILD_ATTRIBUTE_FUNC
:
17424 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
17429 print_core_note (Elf_Internal_Note
*pnote
)
17431 unsigned int addr_size
= is_32bit_elf
? 4 : 8;
17432 bfd_vma count
, page_size
;
17433 unsigned char *descdata
, *filenames
, *descend
;
17435 if (pnote
->type
!= NT_FILE
)
17445 printf (_(" Cannot decode 64-bit note in 32-bit build\n"));
17446 /* Still "successful". */
17451 if (pnote
->descsz
< 2 * addr_size
)
17453 error (_(" Malformed note - too short for header\n"));
17457 descdata
= (unsigned char *) pnote
->descdata
;
17458 descend
= descdata
+ pnote
->descsz
;
17460 if (descdata
[pnote
->descsz
- 1] != '\0')
17462 error (_(" Malformed note - does not end with \\0\n"));
17466 count
= byte_get (descdata
, addr_size
);
17467 descdata
+= addr_size
;
17469 page_size
= byte_get (descdata
, addr_size
);
17470 descdata
+= addr_size
;
17472 if (count
> ((bfd_vma
) -1 - 2 * addr_size
) / (3 * addr_size
)
17473 || pnote
->descsz
< 2 * addr_size
+ count
* 3 * addr_size
)
17475 error (_(" Malformed note - too short for supplied file count\n"));
17479 printf (_(" Page size: "));
17480 print_vma (page_size
, DEC
);
17483 printf (_(" %*s%*s%*s\n"),
17484 (int) (2 + 2 * addr_size
), _("Start"),
17485 (int) (4 + 2 * addr_size
), _("End"),
17486 (int) (4 + 2 * addr_size
), _("Page Offset"));
17487 filenames
= descdata
+ count
* 3 * addr_size
;
17488 while (count
-- > 0)
17490 bfd_vma start
, end
, file_ofs
;
17492 if (filenames
== descend
)
17494 error (_(" Malformed note - filenames end too early\n"));
17498 start
= byte_get (descdata
, addr_size
);
17499 descdata
+= addr_size
;
17500 end
= byte_get (descdata
, addr_size
);
17501 descdata
+= addr_size
;
17502 file_ofs
= byte_get (descdata
, addr_size
);
17503 descdata
+= addr_size
;
17506 print_vma (start
, FULL_HEX
);
17508 print_vma (end
, FULL_HEX
);
17510 print_vma (file_ofs
, FULL_HEX
);
17511 printf ("\n %s\n", filenames
);
17513 filenames
+= 1 + strlen ((char *) filenames
);
17519 static const char *
17520 get_gnu_elf_note_type (unsigned e_type
)
17522 /* NB/ Keep this switch statement in sync with print_gnu_note (). */
17525 case NT_GNU_ABI_TAG
:
17526 return _("NT_GNU_ABI_TAG (ABI version tag)");
17528 return _("NT_GNU_HWCAP (DSO-supplied software HWCAP info)");
17529 case NT_GNU_BUILD_ID
:
17530 return _("NT_GNU_BUILD_ID (unique build ID bitstring)");
17531 case NT_GNU_GOLD_VERSION
:
17532 return _("NT_GNU_GOLD_VERSION (gold version)");
17533 case NT_GNU_PROPERTY_TYPE_0
:
17534 return _("NT_GNU_PROPERTY_TYPE_0");
17535 case NT_GNU_BUILD_ATTRIBUTE_OPEN
:
17536 return _("NT_GNU_BUILD_ATTRIBUTE_OPEN");
17537 case NT_GNU_BUILD_ATTRIBUTE_FUNC
:
17538 return _("NT_GNU_BUILD_ATTRIBUTE_FUNC");
17541 static char buff
[64];
17543 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
17550 decode_x86_compat_isa (unsigned int bitmask
)
17554 unsigned int bit
= bitmask
& (- bitmask
);
17559 case GNU_PROPERTY_X86_COMPAT_ISA_1_486
:
17562 case GNU_PROPERTY_X86_COMPAT_ISA_1_586
:
17565 case GNU_PROPERTY_X86_COMPAT_ISA_1_686
:
17568 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE
:
17571 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE2
:
17574 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE3
:
17577 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSSE3
:
17580 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE4_1
:
17583 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE4_2
:
17586 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX
:
17589 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX2
:
17592 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512F
:
17593 printf ("AVX512F");
17595 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512CD
:
17596 printf ("AVX512CD");
17598 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512ER
:
17599 printf ("AVX512ER");
17601 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512PF
:
17602 printf ("AVX512PF");
17604 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512VL
:
17605 printf ("AVX512VL");
17607 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512DQ
:
17608 printf ("AVX512DQ");
17610 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512BW
:
17611 printf ("AVX512BW");
17614 printf (_("<unknown: %x>"), bit
);
17623 decode_x86_isa (unsigned int bitmask
)
17627 printf (_("<None>"));
17633 unsigned int bit
= bitmask
& (- bitmask
);
17638 case GNU_PROPERTY_X86_ISA_1_CMOV
:
17641 case GNU_PROPERTY_X86_ISA_1_SSE
:
17644 case GNU_PROPERTY_X86_ISA_1_SSE2
:
17647 case GNU_PROPERTY_X86_ISA_1_SSE3
:
17650 case GNU_PROPERTY_X86_ISA_1_SSSE3
:
17653 case GNU_PROPERTY_X86_ISA_1_SSE4_1
:
17656 case GNU_PROPERTY_X86_ISA_1_SSE4_2
:
17659 case GNU_PROPERTY_X86_ISA_1_AVX
:
17662 case GNU_PROPERTY_X86_ISA_1_AVX2
:
17665 case GNU_PROPERTY_X86_ISA_1_FMA
:
17668 case GNU_PROPERTY_X86_ISA_1_AVX512F
:
17669 printf ("AVX512F");
17671 case GNU_PROPERTY_X86_ISA_1_AVX512CD
:
17672 printf ("AVX512CD");
17674 case GNU_PROPERTY_X86_ISA_1_AVX512ER
:
17675 printf ("AVX512ER");
17677 case GNU_PROPERTY_X86_ISA_1_AVX512PF
:
17678 printf ("AVX512PF");
17680 case GNU_PROPERTY_X86_ISA_1_AVX512VL
:
17681 printf ("AVX512VL");
17683 case GNU_PROPERTY_X86_ISA_1_AVX512DQ
:
17684 printf ("AVX512DQ");
17686 case GNU_PROPERTY_X86_ISA_1_AVX512BW
:
17687 printf ("AVX512BW");
17689 case GNU_PROPERTY_X86_ISA_1_AVX512_4FMAPS
:
17690 printf ("AVX512_4FMAPS");
17692 case GNU_PROPERTY_X86_ISA_1_AVX512_4VNNIW
:
17693 printf ("AVX512_4VNNIW");
17695 case GNU_PROPERTY_X86_ISA_1_AVX512_BITALG
:
17696 printf ("AVX512_BITALG");
17698 case GNU_PROPERTY_X86_ISA_1_AVX512_IFMA
:
17699 printf ("AVX512_IFMA");
17701 case GNU_PROPERTY_X86_ISA_1_AVX512_VBMI
:
17702 printf ("AVX512_VBMI");
17704 case GNU_PROPERTY_X86_ISA_1_AVX512_VBMI2
:
17705 printf ("AVX512_VBMI2");
17707 case GNU_PROPERTY_X86_ISA_1_AVX512_VNNI
:
17708 printf ("AVX512_VNNI");
17710 case GNU_PROPERTY_X86_ISA_1_AVX512_BF16
:
17711 printf ("AVX512_BF16");
17714 printf (_("<unknown: %x>"), bit
);
17722 static const char *
17723 get_amd_elf_note_type (unsigned e_type
)
17725 static char buff
[64];
17729 case NT_AMDGPU_HSA_CODE_OBJECT_VERSION
:
17730 return _("NT_AMDGPU_HSA_CODE_OBJECT_VERSION (code object version)");
17731 case NT_AMDGPU_HSA_HSAIL
:
17732 return _("NT_AMDGPU_HSA_HSAIL (hsail)");
17733 case NT_AMDGPU_HSA_ISA
:
17734 return _("NT_AMDGPU_HSA_ISA (ISA name)");
17735 case NT_AMDGPU_HSA_PRODUCER
:
17736 return _("NT_AMDGPU_HSA_PRODUCER (producer name)");
17737 case NT_AMDGPU_HSA_PRODUCER_OPTIONS
:
17738 return _("NT_AMDGPU_HSA_PRODUCER_OPTIONS (producer options");
17739 case NT_AMDGPU_HSA_EXTENSION
:
17740 return _("NT_AMDGPU_HSA_EXTENSION (extension)");
17741 case NT_AMDGPU_HSA_METADATA
:
17742 return _("NT_AMDGPU_HSA_METADATA (code object metadata)");
17743 case NT_AMDGPU_ISA
:
17744 return _("NT_AMDGPU_ISA");
17745 case NT_AMDGPU_PAL_METADATA
:
17746 return _("NT_AMDGPU_PAL_METADATA (code object metadata)");
17747 case NT_AMDGPU_METADATA
:
17748 return _("NT_AMDGPU_METADATA (code object metadata)");
17753 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
17758 print_amd_note (Elf_Internal_Note
*pnote
)
17760 switch (pnote
->type
)
17762 case NT_AMDGPU_HSA_CODE_OBJECT_VERSION
:
17764 unsigned int major
, minor
;
17766 major
= byte_get ((unsigned char*) pnote
->descdata
, 4);
17767 minor
= byte_get ((unsigned char*) pnote
->descdata
+ 4, 4);
17769 printf (_(" Version: %d.%d\n"), major
, minor
);
17773 case NT_AMDGPU_HSA_ISA
:
17775 unsigned long i
, vendorsz
;
17776 unsigned int major
, minor
, stepping
;
17778 vendorsz
= byte_get ((unsigned char*) pnote
->descdata
, 2);
17779 major
= byte_get ((unsigned char*) pnote
->descdata
+ 4, 4);
17780 minor
= byte_get ((unsigned char*) pnote
->descdata
+ 8, 4);
17781 stepping
= byte_get ((unsigned char*) pnote
->descdata
+ 12, 4);
17783 printf (_(" Vendor: "));
17784 for (i
= 16; i
< pnote
->descsz
&& pnote
->descdata
[i
] != '\0'; ++i
)
17785 printf ("%c", pnote
->descdata
[i
]);
17786 printf (_(", Architecture: "));
17787 for (i
= 16 + vendorsz
; i
< pnote
->descsz
&& pnote
->descdata
[i
] != '\0'; ++i
)
17788 printf ("%c", pnote
->descdata
[i
]);
17790 printf (_(", Version: %d.%d.%d"), major
, minor
, stepping
);
17799 decode_x86_feature_1 (unsigned int bitmask
)
17803 printf (_("<None>"));
17809 unsigned int bit
= bitmask
& (- bitmask
);
17814 case GNU_PROPERTY_X86_FEATURE_1_IBT
:
17817 case GNU_PROPERTY_X86_FEATURE_1_SHSTK
:
17821 printf (_("<unknown: %x>"), bit
);
17830 decode_x86_feature_2 (unsigned int bitmask
)
17834 printf (_("<None>"));
17840 unsigned int bit
= bitmask
& (- bitmask
);
17845 case GNU_PROPERTY_X86_FEATURE_2_X86
:
17848 case GNU_PROPERTY_X86_FEATURE_2_X87
:
17851 case GNU_PROPERTY_X86_FEATURE_2_MMX
:
17854 case GNU_PROPERTY_X86_FEATURE_2_XMM
:
17857 case GNU_PROPERTY_X86_FEATURE_2_YMM
:
17860 case GNU_PROPERTY_X86_FEATURE_2_ZMM
:
17863 case GNU_PROPERTY_X86_FEATURE_2_FXSR
:
17866 case GNU_PROPERTY_X86_FEATURE_2_XSAVE
:
17869 case GNU_PROPERTY_X86_FEATURE_2_XSAVEOPT
:
17870 printf ("XSAVEOPT");
17872 case GNU_PROPERTY_X86_FEATURE_2_XSAVEC
:
17876 printf (_("<unknown: %x>"), bit
);
17885 decode_aarch64_feature_1_and (unsigned int bitmask
)
17889 unsigned int bit
= bitmask
& (- bitmask
);
17894 case GNU_PROPERTY_AARCH64_FEATURE_1_BTI
:
17898 case GNU_PROPERTY_AARCH64_FEATURE_1_PAC
:
17903 printf (_("<unknown: %x>"), bit
);
17912 print_gnu_property_note (Filedata
* filedata
, Elf_Internal_Note
* pnote
)
17914 unsigned char * ptr
= (unsigned char *) pnote
->descdata
;
17915 unsigned char * ptr_end
= ptr
+ pnote
->descsz
;
17916 unsigned int size
= is_32bit_elf
? 4 : 8;
17918 printf (_(" Properties: "));
17920 if (pnote
->descsz
< 8 || (pnote
->descsz
% size
) != 0)
17922 printf (_("<corrupt GNU_PROPERTY_TYPE, size = %#lx>\n"), pnote
->descsz
);
17926 while (ptr
< ptr_end
)
17930 unsigned int datasz
;
17932 if ((size_t) (ptr_end
- ptr
) < 8)
17934 printf (_("<corrupt descsz: %#lx>\n"), pnote
->descsz
);
17938 type
= byte_get (ptr
, 4);
17939 datasz
= byte_get (ptr
+ 4, 4);
17943 if (datasz
> (size_t) (ptr_end
- ptr
))
17945 printf (_("<corrupt type (%#x) datasz: %#x>\n"),
17950 if (type
>= GNU_PROPERTY_LOPROC
&& type
<= GNU_PROPERTY_HIPROC
)
17952 if (filedata
->file_header
.e_machine
== EM_X86_64
17953 || filedata
->file_header
.e_machine
== EM_IAMCU
17954 || filedata
->file_header
.e_machine
== EM_386
)
17956 unsigned int bitmask
;
17959 bitmask
= byte_get (ptr
, 4);
17965 case GNU_PROPERTY_X86_ISA_1_USED
:
17967 printf (_("x86 ISA used: <corrupt length: %#x> "),
17971 printf ("x86 ISA used: ");
17972 decode_x86_isa (bitmask
);
17976 case GNU_PROPERTY_X86_ISA_1_NEEDED
:
17978 printf (_("x86 ISA needed: <corrupt length: %#x> "),
17982 printf ("x86 ISA needed: ");
17983 decode_x86_isa (bitmask
);
17987 case GNU_PROPERTY_X86_FEATURE_1_AND
:
17989 printf (_("x86 feature: <corrupt length: %#x> "),
17993 printf ("x86 feature: ");
17994 decode_x86_feature_1 (bitmask
);
17998 case GNU_PROPERTY_X86_FEATURE_2_USED
:
18000 printf (_("x86 feature used: <corrupt length: %#x> "),
18004 printf ("x86 feature used: ");
18005 decode_x86_feature_2 (bitmask
);
18009 case GNU_PROPERTY_X86_FEATURE_2_NEEDED
:
18011 printf (_("x86 feature needed: <corrupt length: %#x> "), datasz
);
18014 printf ("x86 feature needed: ");
18015 decode_x86_feature_2 (bitmask
);
18019 case GNU_PROPERTY_X86_COMPAT_ISA_1_USED
:
18021 printf (_("x86 ISA used: <corrupt length: %#x> "),
18025 printf ("x86 ISA used: ");
18026 decode_x86_compat_isa (bitmask
);
18030 case GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED
:
18032 printf (_("x86 ISA needed: <corrupt length: %#x> "),
18036 printf ("x86 ISA needed: ");
18037 decode_x86_compat_isa (bitmask
);
18045 else if (filedata
->file_header
.e_machine
== EM_AARCH64
)
18047 if (type
== GNU_PROPERTY_AARCH64_FEATURE_1_AND
)
18049 printf ("AArch64 feature: ");
18051 printf (_("<corrupt length: %#x> "), datasz
);
18053 decode_aarch64_feature_1_and (byte_get (ptr
, 4));
18062 case GNU_PROPERTY_STACK_SIZE
:
18063 printf (_("stack size: "));
18064 if (datasz
!= size
)
18065 printf (_("<corrupt length: %#x> "), datasz
);
18067 printf ("%#lx", (unsigned long) byte_get (ptr
, size
));
18070 case GNU_PROPERTY_NO_COPY_ON_PROTECTED
:
18071 printf ("no copy on protected ");
18073 printf (_("<corrupt length: %#x> "), datasz
);
18081 if (type
< GNU_PROPERTY_LOPROC
)
18082 printf (_("<unknown type %#x data: "), type
);
18083 else if (type
< GNU_PROPERTY_LOUSER
)
18084 printf (_("<procesor-specific type %#x data: "), type
);
18086 printf (_("<application-specific type %#x data: "), type
);
18087 for (j
= 0; j
< datasz
; ++j
)
18088 printf ("%02x ", ptr
[j
] & 0xff);
18092 ptr
+= ((datasz
+ (size
- 1)) & ~ (size
- 1));
18093 if (ptr
== ptr_end
)
18106 print_gnu_note (Filedata
* filedata
, Elf_Internal_Note
*pnote
)
18108 /* NB/ Keep this switch statement in sync with get_gnu_elf_note_type (). */
18109 switch (pnote
->type
)
18111 case NT_GNU_BUILD_ID
:
18115 printf (_(" Build ID: "));
18116 for (i
= 0; i
< pnote
->descsz
; ++i
)
18117 printf ("%02x", pnote
->descdata
[i
] & 0xff);
18122 case NT_GNU_ABI_TAG
:
18124 unsigned long os
, major
, minor
, subminor
;
18125 const char *osname
;
18127 /* PR 17531: file: 030-599401-0.004. */
18128 if (pnote
->descsz
< 16)
18130 printf (_(" <corrupt GNU_ABI_TAG>\n"));
18134 os
= byte_get ((unsigned char *) pnote
->descdata
, 4);
18135 major
= byte_get ((unsigned char *) pnote
->descdata
+ 4, 4);
18136 minor
= byte_get ((unsigned char *) pnote
->descdata
+ 8, 4);
18137 subminor
= byte_get ((unsigned char *) pnote
->descdata
+ 12, 4);
18141 case GNU_ABI_TAG_LINUX
:
18144 case GNU_ABI_TAG_HURD
:
18147 case GNU_ABI_TAG_SOLARIS
:
18148 osname
= "Solaris";
18150 case GNU_ABI_TAG_FREEBSD
:
18151 osname
= "FreeBSD";
18153 case GNU_ABI_TAG_NETBSD
:
18156 case GNU_ABI_TAG_SYLLABLE
:
18157 osname
= "Syllable";
18159 case GNU_ABI_TAG_NACL
:
18163 osname
= "Unknown";
18167 printf (_(" OS: %s, ABI: %ld.%ld.%ld\n"), osname
,
18168 major
, minor
, subminor
);
18172 case NT_GNU_GOLD_VERSION
:
18176 printf (_(" Version: "));
18177 for (i
= 0; i
< pnote
->descsz
&& pnote
->descdata
[i
] != '\0'; ++i
)
18178 printf ("%c", pnote
->descdata
[i
]);
18185 unsigned long num_entries
, mask
;
18187 /* Hardware capabilities information. Word 0 is the number of entries.
18188 Word 1 is a bitmask of enabled entries. The rest of the descriptor
18189 is a series of entries, where each entry is a single byte followed
18190 by a nul terminated string. The byte gives the bit number to test
18191 if enabled in the bitmask. */
18192 printf (_(" Hardware Capabilities: "));
18193 if (pnote
->descsz
< 8)
18195 error (_("<corrupt GNU_HWCAP>\n"));
18198 num_entries
= byte_get ((unsigned char *) pnote
->descdata
, 4);
18199 mask
= byte_get ((unsigned char *) pnote
->descdata
+ 4, 4);
18200 printf (_("num entries: %ld, enabled mask: %lx\n"), num_entries
, mask
);
18201 /* FIXME: Add code to display the entries... */
18205 case NT_GNU_PROPERTY_TYPE_0
:
18206 print_gnu_property_note (filedata
, pnote
);
18210 /* Handle unrecognised types. An error message should have already been
18211 created by get_gnu_elf_note_type(), so all that we need to do is to
18212 display the data. */
18216 printf (_(" Description data: "));
18217 for (i
= 0; i
< pnote
->descsz
; ++i
)
18218 printf ("%02x ", pnote
->descdata
[i
] & 0xff);
18227 static const char *
18228 get_v850_elf_note_type (enum v850_notes n_type
)
18230 static char buff
[64];
18234 case V850_NOTE_ALIGNMENT
: return _("Alignment of 8-byte objects");
18235 case V850_NOTE_DATA_SIZE
: return _("Sizeof double and long double");
18236 case V850_NOTE_FPU_INFO
: return _("Type of FPU support needed");
18237 case V850_NOTE_SIMD_INFO
: return _("Use of SIMD instructions");
18238 case V850_NOTE_CACHE_INFO
: return _("Use of cache");
18239 case V850_NOTE_MMU_INFO
: return _("Use of MMU");
18241 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), n_type
);
18247 print_v850_note (Elf_Internal_Note
* pnote
)
18251 if (pnote
->descsz
!= 4)
18254 val
= byte_get ((unsigned char *) pnote
->descdata
, pnote
->descsz
);
18258 printf (_("not set\n"));
18262 switch (pnote
->type
)
18264 case V850_NOTE_ALIGNMENT
:
18267 case EF_RH850_DATA_ALIGN4
: printf (_("4-byte\n")); return TRUE
;
18268 case EF_RH850_DATA_ALIGN8
: printf (_("8-byte\n")); return TRUE
;
18272 case V850_NOTE_DATA_SIZE
:
18275 case EF_RH850_DOUBLE32
: printf (_("4-bytes\n")); return TRUE
;
18276 case EF_RH850_DOUBLE64
: printf (_("8-bytes\n")); return TRUE
;
18280 case V850_NOTE_FPU_INFO
:
18283 case EF_RH850_FPU20
: printf (_("FPU-2.0\n")); return TRUE
;
18284 case EF_RH850_FPU30
: printf (_("FPU-3.0\n")); return TRUE
;
18288 case V850_NOTE_MMU_INFO
:
18289 case V850_NOTE_CACHE_INFO
:
18290 case V850_NOTE_SIMD_INFO
:
18291 if (val
== EF_RH850_SIMD
)
18293 printf (_("yes\n"));
18299 /* An 'unknown note type' message will already have been displayed. */
18303 printf (_("unknown value: %x\n"), val
);
18308 process_netbsd_elf_note (Elf_Internal_Note
* pnote
)
18310 unsigned int version
;
18312 switch (pnote
->type
)
18314 case NT_NETBSD_IDENT
:
18315 version
= byte_get ((unsigned char *) pnote
->descdata
, sizeof (version
));
18316 if ((version
/ 10000) % 100)
18317 printf (" NetBSD\t\t0x%08lx\tIDENT %u (%u.%u%s%c)\n", pnote
->descsz
,
18318 version
, version
/ 100000000, (version
/ 1000000) % 100,
18319 (version
/ 10000) % 100 > 26 ? "Z" : "",
18320 'A' + (version
/ 10000) % 26);
18322 printf (" NetBSD\t\t0x%08lx\tIDENT %u (%u.%u.%u)\n", pnote
->descsz
,
18323 version
, version
/ 100000000, (version
/ 1000000) % 100,
18324 (version
/ 100) % 100);
18327 case NT_NETBSD_MARCH
:
18328 printf (" NetBSD\t\t0x%08lx\tMARCH <%s>\n", pnote
->descsz
,
18332 #ifdef NT_NETBSD_PAX
18333 case NT_NETBSD_PAX
:
18334 version
= byte_get ((unsigned char *) pnote
->descdata
, sizeof (version
));
18335 printf (" NetBSD\t\t0x%08lx\tPaX <%s%s%s%s%s%s>\n", pnote
->descsz
,
18336 ((version
& NT_NETBSD_PAX_MPROTECT
) ? "+mprotect" : ""),
18337 ((version
& NT_NETBSD_PAX_NOMPROTECT
) ? "-mprotect" : ""),
18338 ((version
& NT_NETBSD_PAX_GUARD
) ? "+guard" : ""),
18339 ((version
& NT_NETBSD_PAX_NOGUARD
) ? "-guard" : ""),
18340 ((version
& NT_NETBSD_PAX_ASLR
) ? "+ASLR" : ""),
18341 ((version
& NT_NETBSD_PAX_NOASLR
) ? "-ASLR" : ""));
18346 printf (" NetBSD\t0x%08lx\tUnknown note type: (0x%08lx)\n", pnote
->descsz
,
18352 static const char *
18353 get_freebsd_elfcore_note_type (Filedata
* filedata
, unsigned e_type
)
18357 case NT_FREEBSD_THRMISC
:
18358 return _("NT_THRMISC (thrmisc structure)");
18359 case NT_FREEBSD_PROCSTAT_PROC
:
18360 return _("NT_PROCSTAT_PROC (proc data)");
18361 case NT_FREEBSD_PROCSTAT_FILES
:
18362 return _("NT_PROCSTAT_FILES (files data)");
18363 case NT_FREEBSD_PROCSTAT_VMMAP
:
18364 return _("NT_PROCSTAT_VMMAP (vmmap data)");
18365 case NT_FREEBSD_PROCSTAT_GROUPS
:
18366 return _("NT_PROCSTAT_GROUPS (groups data)");
18367 case NT_FREEBSD_PROCSTAT_UMASK
:
18368 return _("NT_PROCSTAT_UMASK (umask data)");
18369 case NT_FREEBSD_PROCSTAT_RLIMIT
:
18370 return _("NT_PROCSTAT_RLIMIT (rlimit data)");
18371 case NT_FREEBSD_PROCSTAT_OSREL
:
18372 return _("NT_PROCSTAT_OSREL (osreldate data)");
18373 case NT_FREEBSD_PROCSTAT_PSSTRINGS
:
18374 return _("NT_PROCSTAT_PSSTRINGS (ps_strings data)");
18375 case NT_FREEBSD_PROCSTAT_AUXV
:
18376 return _("NT_PROCSTAT_AUXV (auxv data)");
18377 case NT_FREEBSD_PTLWPINFO
:
18378 return _("NT_PTLWPINFO (ptrace_lwpinfo structure)");
18380 return get_note_type (filedata
, e_type
);
18383 static const char *
18384 get_netbsd_elfcore_note_type (Filedata
* filedata
, unsigned e_type
)
18386 static char buff
[64];
18390 case NT_NETBSDCORE_PROCINFO
:
18391 /* NetBSD core "procinfo" structure. */
18392 return _("NetBSD procinfo structure");
18394 #ifdef NT_NETBSDCORE_AUXV
18395 case NT_NETBSDCORE_AUXV
:
18396 return _("NetBSD ELF auxiliary vector data");
18400 /* As of Jan 2002 there are no other machine-independent notes
18401 defined for NetBSD core files. If the note type is less
18402 than the start of the machine-dependent note types, we don't
18405 if (e_type
< NT_NETBSDCORE_FIRSTMACH
)
18407 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
18413 switch (filedata
->file_header
.e_machine
)
18415 /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0
18416 and PT_GETFPREGS == mach+2. */
18421 case EM_SPARC32PLUS
:
18425 case NT_NETBSDCORE_FIRSTMACH
+ 0:
18426 return _("PT_GETREGS (reg structure)");
18427 case NT_NETBSDCORE_FIRSTMACH
+ 2:
18428 return _("PT_GETFPREGS (fpreg structure)");
18434 /* On SuperH, PT_GETREGS == mach+3 and PT_GETFPREGS == mach+5.
18435 There's also old PT___GETREGS40 == mach + 1 for old reg
18436 structure which lacks GBR. */
18440 case NT_NETBSDCORE_FIRSTMACH
+ 1:
18441 return _("PT___GETREGS40 (old reg structure)");
18442 case NT_NETBSDCORE_FIRSTMACH
+ 3:
18443 return _("PT_GETREGS (reg structure)");
18444 case NT_NETBSDCORE_FIRSTMACH
+ 5:
18445 return _("PT_GETFPREGS (fpreg structure)");
18451 /* On all other arch's, PT_GETREGS == mach+1 and
18452 PT_GETFPREGS == mach+3. */
18456 case NT_NETBSDCORE_FIRSTMACH
+ 1:
18457 return _("PT_GETREGS (reg structure)");
18458 case NT_NETBSDCORE_FIRSTMACH
+ 3:
18459 return _("PT_GETFPREGS (fpreg structure)");
18465 snprintf (buff
, sizeof (buff
), "PT_FIRSTMACH+%d",
18466 e_type
- NT_NETBSDCORE_FIRSTMACH
);
18470 static const char *
18471 get_stapsdt_note_type (unsigned e_type
)
18473 static char buff
[64];
18478 return _("NT_STAPSDT (SystemTap probe descriptors)");
18484 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
18489 print_stapsdt_note (Elf_Internal_Note
*pnote
)
18491 size_t len
, maxlen
;
18492 unsigned long addr_size
= is_32bit_elf
? 4 : 8;
18493 char *data
= pnote
->descdata
;
18494 char *data_end
= pnote
->descdata
+ pnote
->descsz
;
18495 bfd_vma pc
, base_addr
, semaphore
;
18496 char *provider
, *probe
, *arg_fmt
;
18498 if (pnote
->descsz
< (addr_size
* 3))
18499 goto stapdt_note_too_small
;
18501 pc
= byte_get ((unsigned char *) data
, addr_size
);
18504 base_addr
= byte_get ((unsigned char *) data
, addr_size
);
18507 semaphore
= byte_get ((unsigned char *) data
, addr_size
);
18510 if (data
>= data_end
)
18511 goto stapdt_note_too_small
;
18512 maxlen
= data_end
- data
;
18513 len
= strnlen (data
, maxlen
);
18520 goto stapdt_note_too_small
;
18522 if (data
>= data_end
)
18523 goto stapdt_note_too_small
;
18524 maxlen
= data_end
- data
;
18525 len
= strnlen (data
, maxlen
);
18532 goto stapdt_note_too_small
;
18534 if (data
>= data_end
)
18535 goto stapdt_note_too_small
;
18536 maxlen
= data_end
- data
;
18537 len
= strnlen (data
, maxlen
);
18544 goto stapdt_note_too_small
;
18546 printf (_(" Provider: %s\n"), provider
);
18547 printf (_(" Name: %s\n"), probe
);
18548 printf (_(" Location: "));
18549 print_vma (pc
, FULL_HEX
);
18550 printf (_(", Base: "));
18551 print_vma (base_addr
, FULL_HEX
);
18552 printf (_(", Semaphore: "));
18553 print_vma (semaphore
, FULL_HEX
);
18555 printf (_(" Arguments: %s\n"), arg_fmt
);
18557 return data
== data_end
;
18559 stapdt_note_too_small
:
18560 printf (_(" <corrupt - note is too small>\n"));
18561 error (_("corrupt stapdt note - the data size is too small\n"));
18565 static const char *
18566 get_ia64_vms_note_type (unsigned e_type
)
18568 static char buff
[64];
18573 return _("NT_VMS_MHD (module header)");
18575 return _("NT_VMS_LNM (language name)");
18577 return _("NT_VMS_SRC (source files)");
18579 return "NT_VMS_TITLE";
18581 return _("NT_VMS_EIDC (consistency check)");
18582 case NT_VMS_FPMODE
:
18583 return _("NT_VMS_FPMODE (FP mode)");
18584 case NT_VMS_LINKTIME
:
18585 return "NT_VMS_LINKTIME";
18586 case NT_VMS_IMGNAM
:
18587 return _("NT_VMS_IMGNAM (image name)");
18589 return _("NT_VMS_IMGID (image id)");
18590 case NT_VMS_LINKID
:
18591 return _("NT_VMS_LINKID (link id)");
18592 case NT_VMS_IMGBID
:
18593 return _("NT_VMS_IMGBID (build id)");
18594 case NT_VMS_GSTNAM
:
18595 return _("NT_VMS_GSTNAM (sym table name)");
18596 case NT_VMS_ORIG_DYN
:
18597 return "NT_VMS_ORIG_DYN";
18598 case NT_VMS_PATCHTIME
:
18599 return "NT_VMS_PATCHTIME";
18601 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
18607 print_ia64_vms_note (Elf_Internal_Note
* pnote
)
18609 int maxlen
= pnote
->descsz
;
18611 if (maxlen
< 2 || (unsigned long) maxlen
!= pnote
->descsz
)
18612 goto desc_size_fail
;
18614 switch (pnote
->type
)
18618 goto desc_size_fail
;
18620 int l
= (int) strnlen (pnote
->descdata
+ 34, maxlen
- 34);
18622 printf (_(" Creation date : %.17s\n"), pnote
->descdata
);
18623 printf (_(" Last patch date: %.17s\n"), pnote
->descdata
+ 17);
18624 if (l
+ 34 < maxlen
)
18626 printf (_(" Module name : %s\n"), pnote
->descdata
+ 34);
18627 if (l
+ 35 < maxlen
)
18628 printf (_(" Module version : %s\n"), pnote
->descdata
+ 34 + l
+ 1);
18630 printf (_(" Module version : <missing>\n"));
18634 printf (_(" Module name : <missing>\n"));
18635 printf (_(" Module version : <missing>\n"));
18640 printf (_(" Language: %.*s\n"), maxlen
, pnote
->descdata
);
18644 case NT_VMS_FPMODE
:
18645 printf (_(" Floating Point mode: "));
18647 goto desc_size_fail
;
18648 /* FIXME: Generate an error if descsz > 8 ? */
18650 printf ("0x%016" BFD_VMA_FMT
"x\n",
18651 (bfd_vma
) byte_get ((unsigned char *)pnote
->descdata
, 8));
18654 case NT_VMS_LINKTIME
:
18655 printf (_(" Link time: "));
18657 goto desc_size_fail
;
18658 /* FIXME: Generate an error if descsz > 8 ? */
18661 ((bfd_int64_t
) byte_get ((unsigned char *)pnote
->descdata
, 8));
18665 case NT_VMS_PATCHTIME
:
18666 printf (_(" Patch time: "));
18668 goto desc_size_fail
;
18669 /* FIXME: Generate an error if descsz > 8 ? */
18672 ((bfd_int64_t
) byte_get ((unsigned char *)pnote
->descdata
, 8));
18676 case NT_VMS_ORIG_DYN
:
18678 goto desc_size_fail
;
18680 printf (_(" Major id: %u, minor id: %u\n"),
18681 (unsigned) byte_get ((unsigned char *)pnote
->descdata
, 4),
18682 (unsigned) byte_get ((unsigned char *)pnote
->descdata
+ 4, 4));
18683 printf (_(" Last modified : "));
18685 ((bfd_int64_t
) byte_get ((unsigned char *)pnote
->descdata
+ 8, 8));
18686 printf (_("\n Link flags : "));
18687 printf ("0x%016" BFD_VMA_FMT
"x\n",
18688 (bfd_vma
) byte_get ((unsigned char *)pnote
->descdata
+ 16, 8));
18689 printf (_(" Header flags: 0x%08x\n"),
18690 (unsigned) byte_get ((unsigned char *)pnote
->descdata
+ 24, 4));
18691 printf (_(" Image id : %.*s\n"), maxlen
- 32, pnote
->descdata
+ 32);
18695 case NT_VMS_IMGNAM
:
18696 printf (_(" Image name: %.*s\n"), maxlen
, pnote
->descdata
);
18699 case NT_VMS_GSTNAM
:
18700 printf (_(" Global symbol table name: %.*s\n"), maxlen
, pnote
->descdata
);
18704 printf (_(" Image id: %.*s\n"), maxlen
, pnote
->descdata
);
18707 case NT_VMS_LINKID
:
18708 printf (_(" Linker id: %.*s\n"), maxlen
, pnote
->descdata
);
18718 printf (_(" <corrupt - data size is too small>\n"));
18719 error (_("corrupt IA64 note: data size is too small\n"));
18723 /* Find the symbol associated with a build attribute that is attached
18724 to address OFFSET. If PNAME is non-NULL then store the name of
18725 the symbol (if found) in the provided pointer, Returns NULL if a
18726 symbol could not be found. */
18728 static Elf_Internal_Sym
*
18729 get_symbol_for_build_attribute (Filedata
* filedata
,
18730 unsigned long offset
,
18731 bfd_boolean is_open_attr
,
18732 const char ** pname
)
18734 static Filedata
* saved_filedata
= NULL
;
18735 static char * strtab
;
18736 static unsigned long strtablen
;
18737 static Elf_Internal_Sym
* symtab
;
18738 static unsigned long nsyms
;
18739 Elf_Internal_Sym
* saved_sym
= NULL
;
18740 Elf_Internal_Sym
* sym
;
18742 if (filedata
->section_headers
!= NULL
18743 && (saved_filedata
== NULL
|| filedata
!= saved_filedata
))
18745 Elf_Internal_Shdr
* symsec
;
18747 /* Load the symbol and string sections. */
18748 for (symsec
= filedata
->section_headers
;
18749 symsec
< filedata
->section_headers
+ filedata
->file_header
.e_shnum
;
18752 if (symsec
->sh_type
== SHT_SYMTAB
)
18754 symtab
= GET_ELF_SYMBOLS (filedata
, symsec
, & nsyms
);
18756 if (symsec
->sh_link
< filedata
->file_header
.e_shnum
)
18758 Elf_Internal_Shdr
* strtab_sec
= filedata
->section_headers
+ symsec
->sh_link
;
18760 strtab
= (char *) get_data (NULL
, filedata
, strtab_sec
->sh_offset
,
18761 1, strtab_sec
->sh_size
,
18762 _("string table"));
18763 strtablen
= strtab
!= NULL
? strtab_sec
->sh_size
: 0;
18767 saved_filedata
= filedata
;
18770 if (symtab
== NULL
|| strtab
== NULL
)
18773 /* Find a symbol whose value matches offset. */
18774 for (sym
= symtab
; sym
< symtab
+ nsyms
; sym
++)
18775 if (sym
->st_value
== offset
)
18777 if (sym
->st_name
>= strtablen
)
18778 /* Huh ? This should not happen. */
18781 if (strtab
[sym
->st_name
] == 0)
18784 /* The AArch64 and ARM architectures define mapping symbols
18785 (eg $d, $x, $t) which we want to ignore. */
18786 if (strtab
[sym
->st_name
] == '$'
18787 && strtab
[sym
->st_name
+ 1] != 0
18788 && strtab
[sym
->st_name
+ 2] == 0)
18793 /* For OPEN attributes we prefer GLOBAL over LOCAL symbols
18794 and FILE or OBJECT symbols over NOTYPE symbols. We skip
18795 FUNC symbols entirely. */
18796 switch (ELF_ST_TYPE (sym
->st_info
))
18803 /* If the symbol has a size associated
18804 with it then we can stop searching. */
18805 sym
= symtab
+ nsyms
;
18810 /* Ignore function symbols. */
18817 switch (ELF_ST_BIND (sym
->st_info
))
18820 if (saved_sym
== NULL
18821 || ELF_ST_TYPE (saved_sym
->st_info
) != STT_OBJECT
)
18826 if (saved_sym
== NULL
)
18836 if (ELF_ST_TYPE (sym
->st_info
) != STT_FUNC
)
18844 if (saved_sym
&& pname
)
18845 * pname
= strtab
+ saved_sym
->st_name
;
18850 /* Returns true iff addr1 and addr2 are in the same section. */
18853 same_section (Filedata
* filedata
, unsigned long addr1
, unsigned long addr2
)
18855 Elf_Internal_Shdr
* a1
;
18856 Elf_Internal_Shdr
* a2
;
18858 a1
= find_section_by_address (filedata
, addr1
);
18859 a2
= find_section_by_address (filedata
, addr2
);
18861 return a1
== a2
&& a1
!= NULL
;
18865 print_gnu_build_attribute_description (Elf_Internal_Note
* pnote
,
18866 Filedata
* filedata
)
18868 static unsigned long global_offset
= 0;
18869 static unsigned long global_end
= 0;
18870 static unsigned long func_offset
= 0;
18871 static unsigned long func_end
= 0;
18873 Elf_Internal_Sym
* sym
;
18875 unsigned long start
;
18877 bfd_boolean is_open_attr
= pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_OPEN
;
18879 switch (pnote
->descsz
)
18882 /* A zero-length description means that the range of
18883 the previous note of the same type should be used. */
18886 if (global_end
> global_offset
)
18887 printf (_(" Applies to region from %#lx to %#lx\n"),
18888 global_offset
, global_end
);
18890 printf (_(" Applies to region from %#lx\n"), global_offset
);
18894 if (func_end
> func_offset
)
18895 printf (_(" Applies to region from %#lx to %#lx\n"), func_offset
, func_end
);
18897 printf (_(" Applies to region from %#lx\n"), func_offset
);
18902 start
= byte_get ((unsigned char *) pnote
->descdata
, 4);
18909 /* FIXME: We should check that version 3+ notes are being used here... */
18910 start
= byte_get ((unsigned char *) pnote
->descdata
, 4);
18911 end
= byte_get ((unsigned char *) pnote
->descdata
+ 4, 4);
18915 start
= byte_get ((unsigned char *) pnote
->descdata
, 8);
18921 start
= byte_get ((unsigned char *) pnote
->descdata
, 8);
18922 end
= byte_get ((unsigned char *) pnote
->descdata
+ 8, 8);
18926 error (_(" <invalid description size: %lx>\n"), pnote
->descsz
);
18927 printf (_(" <invalid descsz>"));
18932 sym
= get_symbol_for_build_attribute (filedata
, start
, is_open_attr
, & name
);
18933 /* As of version 5 of the annobin plugin, filename symbols are biased by 2
18934 in order to avoid them being confused with the start address of the
18935 first function in the file... */
18936 if (sym
== NULL
&& is_open_attr
)
18937 sym
= get_symbol_for_build_attribute (filedata
, start
+ 2, is_open_attr
,
18940 if (end
== 0 && sym
!= NULL
&& sym
->st_size
> 0)
18941 end
= start
+ sym
->st_size
;
18945 /* FIXME: Need to properly allow for section alignment.
18946 16 is just the alignment used on x86_64. */
18948 && start
> BFD_ALIGN (global_end
, 16)
18949 /* Build notes are not guaranteed to be organised in order of
18950 increasing address, but we should find the all of the notes
18951 for one section in the same place. */
18952 && same_section (filedata
, start
, global_end
))
18953 warn (_("Gap in build notes detected from %#lx to %#lx\n"),
18954 global_end
+ 1, start
- 1);
18956 printf (_(" Applies to region from %#lx"), start
);
18957 global_offset
= start
;
18961 printf (_(" to %#lx"), end
);
18967 printf (_(" Applies to region from %#lx"), start
);
18968 func_offset
= start
;
18972 printf (_(" to %#lx"), end
);
18978 printf (_(" (%s)"), name
);
18985 print_gnu_build_attribute_name (Elf_Internal_Note
* pnote
)
18987 static const char string_expected
[2] = { GNU_BUILD_ATTRIBUTE_TYPE_STRING
, 0 };
18988 static const char number_expected
[2] = { GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC
, 0 };
18989 static const char bool_expected
[3] = { GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE
, GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE
, 0 };
18991 char name_attribute
;
18992 const char * expected_types
;
18993 const char * name
= pnote
->namedata
;
18997 if (name
== NULL
|| pnote
->namesz
< 2)
18999 error (_("corrupt name field in GNU build attribute note: size = %ld\n"), pnote
->namesz
);
19000 print_symbol (-20, _(" <corrupt name>"));
19009 /* Version 2 of the spec adds a "GA" prefix to the name field. */
19010 if (name
[0] == 'G' && name
[1] == 'A')
19012 if (pnote
->namesz
< 4)
19014 error (_("corrupt name field in GNU build attribute note: size = %ld\n"), pnote
->namesz
);
19015 print_symbol (-20, _(" <corrupt name>"));
19024 switch ((name_type
= * name
))
19026 case GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC
:
19027 case GNU_BUILD_ATTRIBUTE_TYPE_STRING
:
19028 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE
:
19029 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE
:
19030 printf ("%c", * name
);
19034 error (_("unrecognised attribute type in name field: %d\n"), name_type
);
19035 print_symbol (-20, _("<unknown name type>"));
19042 switch ((name_attribute
= * name
))
19044 case GNU_BUILD_ATTRIBUTE_VERSION
:
19045 text
= _("<version>");
19046 expected_types
= string_expected
;
19049 case GNU_BUILD_ATTRIBUTE_STACK_PROT
:
19050 text
= _("<stack prot>");
19051 expected_types
= "!+*";
19054 case GNU_BUILD_ATTRIBUTE_RELRO
:
19055 text
= _("<relro>");
19056 expected_types
= bool_expected
;
19059 case GNU_BUILD_ATTRIBUTE_STACK_SIZE
:
19060 text
= _("<stack size>");
19061 expected_types
= number_expected
;
19064 case GNU_BUILD_ATTRIBUTE_TOOL
:
19065 text
= _("<tool>");
19066 expected_types
= string_expected
;
19069 case GNU_BUILD_ATTRIBUTE_ABI
:
19071 expected_types
= "$*";
19074 case GNU_BUILD_ATTRIBUTE_PIC
:
19076 expected_types
= number_expected
;
19079 case GNU_BUILD_ATTRIBUTE_SHORT_ENUM
:
19080 text
= _("<short enum>");
19081 expected_types
= bool_expected
;
19085 if (ISPRINT (* name
))
19087 int len
= strnlen (name
, pnote
->namesz
- (name
- pnote
->namedata
)) + 1;
19089 if (len
> left
&& ! do_wide
)
19091 printf ("%.*s:", len
, name
);
19097 static char tmpbuf
[128];
19099 error (_("unrecognised byte in name field: %d\n"), * name
);
19100 sprintf (tmpbuf
, _("<unknown:_%d>"), * name
);
19104 expected_types
= "*$!+";
19109 left
-= printf ("%s", text
);
19111 if (strchr (expected_types
, name_type
) == NULL
)
19112 warn (_("attribute does not have an expected type (%c)\n"), name_type
);
19114 if ((unsigned long)(name
- pnote
->namedata
) > pnote
->namesz
)
19116 error (_("corrupt name field: namesz: %lu but parsing gets to %ld\n"),
19117 (unsigned long) pnote
->namesz
,
19118 (long) (name
- pnote
->namedata
));
19122 if (left
< 1 && ! do_wide
)
19127 case GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC
:
19129 unsigned int bytes
;
19130 unsigned long long val
= 0;
19131 unsigned int shift
= 0;
19132 char * decoded
= NULL
;
19134 bytes
= pnote
->namesz
- (name
- pnote
->namedata
);
19136 /* The -1 is because the name field is always 0 terminated, and we
19137 want to be able to ensure that the shift in the while loop below
19138 will not overflow. */
19141 if (bytes
> sizeof (val
))
19143 error (_("corrupt numeric name field: too many bytes in the value: %x\n"),
19145 bytes
= sizeof (val
);
19147 /* We do not bother to warn if bytes == 0 as this can
19148 happen with some early versions of the gcc plugin. */
19152 unsigned long byte
= (* name
++) & 0xff;
19154 val
|= byte
<< shift
;
19158 switch (name_attribute
)
19160 case GNU_BUILD_ATTRIBUTE_PIC
:
19163 case 0: decoded
= "static"; break;
19164 case 1: decoded
= "pic"; break;
19165 case 2: decoded
= "PIC"; break;
19166 case 3: decoded
= "pie"; break;
19167 case 4: decoded
= "PIE"; break;
19171 case GNU_BUILD_ATTRIBUTE_STACK_PROT
:
19174 /* Based upon the SPCT_FLAG_xxx enum values in gcc/cfgexpand.c. */
19175 case 0: decoded
= "off"; break;
19176 case 1: decoded
= "on"; break;
19177 case 2: decoded
= "all"; break;
19178 case 3: decoded
= "strong"; break;
19179 case 4: decoded
= "explicit"; break;
19187 if (decoded
!= NULL
)
19189 print_symbol (-left
, decoded
);
19200 left
-= printf ("0x%llx", val
);
19202 left
-= printf ("0x%-.*llx", left
, val
);
19206 case GNU_BUILD_ATTRIBUTE_TYPE_STRING
:
19207 left
-= print_symbol (- left
, name
);
19209 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE
:
19210 left
-= print_symbol (- left
, "true");
19212 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE
:
19213 left
-= print_symbol (- left
, "false");
19217 if (do_wide
&& left
> 0)
19218 printf ("%-*s", left
, " ");
19223 /* Note that by the ELF standard, the name field is already null byte
19224 terminated, and namesz includes the terminating null byte.
19225 I.E. the value of namesz for the name "FSF" is 4.
19227 If the value of namesz is zero, there is no name present. */
19230 process_note (Elf_Internal_Note
* pnote
,
19231 Filedata
* filedata
)
19233 const char * name
= pnote
->namesz
? pnote
->namedata
: "(NONE)";
19236 if (pnote
->namesz
== 0)
19237 /* If there is no note name, then use the default set of
19238 note type strings. */
19239 nt
= get_note_type (filedata
, pnote
->type
);
19241 else if (const_strneq (pnote
->namedata
, "GNU"))
19242 /* GNU-specific object file notes. */
19243 nt
= get_gnu_elf_note_type (pnote
->type
);
19245 else if (const_strneq (pnote
->namedata
, "AMD")
19246 || const_strneq (pnote
->namedata
, "AMDGPU"))
19247 /* AMD-specific object file notes. */
19248 nt
= get_amd_elf_note_type (pnote
->type
);
19250 else if (const_strneq (pnote
->namedata
, "FreeBSD"))
19251 /* FreeBSD-specific core file notes. */
19252 nt
= get_freebsd_elfcore_note_type (filedata
, pnote
->type
);
19254 else if (const_strneq (pnote
->namedata
, "NetBSD-CORE"))
19255 /* NetBSD-specific core file notes. */
19256 nt
= get_netbsd_elfcore_note_type (filedata
, pnote
->type
);
19258 else if (const_strneq (pnote
->namedata
, "NetBSD"))
19259 /* NetBSD-specific core file notes. */
19260 return process_netbsd_elf_note (pnote
);
19262 else if (const_strneq (pnote
->namedata
, "PaX"))
19263 /* NetBSD-specific core file notes. */
19264 return process_netbsd_elf_note (pnote
);
19266 else if (strneq (pnote
->namedata
, "SPU/", 4))
19268 /* SPU-specific core file notes. */
19269 nt
= pnote
->namedata
+ 4;
19273 else if (const_strneq (pnote
->namedata
, "IPF/VMS"))
19274 /* VMS/ia64-specific file notes. */
19275 nt
= get_ia64_vms_note_type (pnote
->type
);
19277 else if (const_strneq (pnote
->namedata
, "stapsdt"))
19278 nt
= get_stapsdt_note_type (pnote
->type
);
19281 /* Don't recognize this note name; just use the default set of
19282 note type strings. */
19283 nt
= get_note_type (filedata
, pnote
->type
);
19287 if (((const_strneq (pnote
->namedata
, "GA")
19288 && strchr ("*$!+", pnote
->namedata
[2]) != NULL
)
19289 || strchr ("*$!+", pnote
->namedata
[0]) != NULL
)
19290 && (pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_OPEN
19291 || pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_FUNC
))
19292 print_gnu_build_attribute_name (pnote
);
19294 print_symbol (-20, name
);
19297 printf (" 0x%08lx\t%s\t", pnote
->descsz
, nt
);
19299 printf (" 0x%08lx\t%s\n", pnote
->descsz
, nt
);
19301 if (const_strneq (pnote
->namedata
, "IPF/VMS"))
19302 return print_ia64_vms_note (pnote
);
19303 else if (const_strneq (pnote
->namedata
, "GNU"))
19304 return print_gnu_note (filedata
, pnote
);
19305 else if (const_strneq (pnote
->namedata
, "AMD")
19306 || const_strneq (pnote
->namedata
, "AMDGPU"))
19307 return print_amd_note (pnote
);
19308 else if (const_strneq (pnote
->namedata
, "stapsdt"))
19309 return print_stapsdt_note (pnote
);
19310 else if (const_strneq (pnote
->namedata
, "CORE"))
19311 return print_core_note (pnote
);
19312 else if (((const_strneq (pnote
->namedata
, "GA")
19313 && strchr ("*$!+", pnote
->namedata
[2]) != NULL
)
19314 || strchr ("*$!+", pnote
->namedata
[0]) != NULL
)
19315 && (pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_OPEN
19316 || pnote
->type
== NT_GNU_BUILD_ATTRIBUTE_FUNC
))
19317 return print_gnu_build_attribute_description (pnote
, filedata
);
19323 printf (_(" description data: "));
19324 for (i
= 0; i
< pnote
->descsz
; i
++)
19325 printf ("%02x ", pnote
->descdata
[i
] & 0xff);
19337 process_notes_at (Filedata
* filedata
,
19338 Elf_Internal_Shdr
* section
,
19343 Elf_External_Note
* pnotes
;
19344 Elf_External_Note
* external
;
19346 bfd_boolean res
= TRUE
;
19353 pnotes
= (Elf_External_Note
*) get_section_contents (section
, filedata
);
19356 if (! apply_relocations (filedata
, section
, (unsigned char *) pnotes
, length
, NULL
, NULL
))
19361 pnotes
= (Elf_External_Note
*) get_data (NULL
, filedata
, offset
, 1, length
,
19364 if (pnotes
== NULL
)
19370 printf (_("\nDisplaying notes found in: %s\n"), printable_section_name (filedata
, section
));
19372 printf (_("\nDisplaying notes found at file offset 0x%08lx with length 0x%08lx:\n"),
19373 (unsigned long) offset
, (unsigned long) length
);
19375 /* NB: Some note sections may have alignment value of 0 or 1. gABI
19376 specifies that notes should be aligned to 4 bytes in 32-bit
19377 objects and to 8 bytes in 64-bit objects. As a Linux extension,
19378 we also support 4 byte alignment in 64-bit objects. If section
19379 alignment is less than 4, we treate alignment as 4 bytes. */
19382 else if (align
!= 4 && align
!= 8)
19384 warn (_("Corrupt note: alignment %ld, expecting 4 or 8\n"),
19389 printf (_(" %-20s %-10s\tDescription\n"), _("Owner"), _("Data size"));
19391 end
= (char *) pnotes
+ length
;
19392 while ((char *) external
< end
)
19394 Elf_Internal_Note inote
;
19397 char * temp
= NULL
;
19398 size_t data_remaining
= end
- (char *) external
;
19400 if (!is_ia64_vms (filedata
))
19402 /* PR binutils/15191
19403 Make sure that there is enough data to read. */
19404 min_notesz
= offsetof (Elf_External_Note
, name
);
19405 if (data_remaining
< min_notesz
)
19407 warn (ngettext ("Corrupt note: only %ld byte remains, "
19408 "not enough for a full note\n",
19409 "Corrupt note: only %ld bytes remain, "
19410 "not enough for a full note\n",
19412 (long) data_remaining
);
19415 data_remaining
-= min_notesz
;
19417 inote
.type
= BYTE_GET (external
->type
);
19418 inote
.namesz
= BYTE_GET (external
->namesz
);
19419 inote
.namedata
= external
->name
;
19420 inote
.descsz
= BYTE_GET (external
->descsz
);
19421 inote
.descdata
= ((char *) external
19422 + ELF_NOTE_DESC_OFFSET (inote
.namesz
, align
));
19423 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
19424 next
= ((char *) external
19425 + ELF_NOTE_NEXT_OFFSET (inote
.namesz
, inote
.descsz
, align
));
19429 Elf64_External_VMS_Note
*vms_external
;
19431 /* PR binutils/15191
19432 Make sure that there is enough data to read. */
19433 min_notesz
= offsetof (Elf64_External_VMS_Note
, name
);
19434 if (data_remaining
< min_notesz
)
19436 warn (ngettext ("Corrupt note: only %ld byte remains, "
19437 "not enough for a full note\n",
19438 "Corrupt note: only %ld bytes remain, "
19439 "not enough for a full note\n",
19441 (long) data_remaining
);
19444 data_remaining
-= min_notesz
;
19446 vms_external
= (Elf64_External_VMS_Note
*) external
;
19447 inote
.type
= BYTE_GET (vms_external
->type
);
19448 inote
.namesz
= BYTE_GET (vms_external
->namesz
);
19449 inote
.namedata
= vms_external
->name
;
19450 inote
.descsz
= BYTE_GET (vms_external
->descsz
);
19451 inote
.descdata
= inote
.namedata
+ align_power (inote
.namesz
, 3);
19452 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
19453 next
= inote
.descdata
+ align_power (inote
.descsz
, 3);
19456 /* PR 17531: file: 3443835e. */
19457 /* PR 17531: file: id:000000,sig:11,src:006986,op:havoc,rep:4. */
19458 if ((size_t) (inote
.descdata
- inote
.namedata
) < inote
.namesz
19459 || (size_t) (inote
.descdata
- inote
.namedata
) > data_remaining
19460 || (size_t) (next
- inote
.descdata
) < inote
.descsz
19461 || ((size_t) (next
- inote
.descdata
)
19462 > data_remaining
- (size_t) (inote
.descdata
- inote
.namedata
)))
19464 warn (_("note with invalid namesz and/or descsz found at offset 0x%lx\n"),
19465 (unsigned long) ((char *) external
- (char *) pnotes
));
19466 warn (_(" type: 0x%lx, namesize: 0x%08lx, descsize: 0x%08lx, alignment: %u\n"),
19467 inote
.type
, inote
.namesz
, inote
.descsz
, (int) align
);
19471 external
= (Elf_External_Note
*) next
;
19473 /* Verify that name is null terminated. It appears that at least
19474 one version of Linux (RedHat 6.0) generates corefiles that don't
19475 comply with the ELF spec by failing to include the null byte in
19477 if (inote
.namesz
> 0 && inote
.namedata
[inote
.namesz
- 1] != '\0')
19479 if ((size_t) (inote
.descdata
- inote
.namedata
) == inote
.namesz
)
19481 temp
= (char *) malloc (inote
.namesz
+ 1);
19484 error (_("Out of memory allocating space for inote name\n"));
19489 memcpy (temp
, inote
.namedata
, inote
.namesz
);
19490 inote
.namedata
= temp
;
19492 inote
.namedata
[inote
.namesz
] = 0;
19495 if (! process_note (& inote
, filedata
))
19511 process_corefile_note_segments (Filedata
* filedata
)
19513 Elf_Internal_Phdr
* segment
;
19515 bfd_boolean res
= TRUE
;
19517 if (! get_program_headers (filedata
))
19520 for (i
= 0, segment
= filedata
->program_headers
;
19521 i
< filedata
->file_header
.e_phnum
;
19524 if (segment
->p_type
== PT_NOTE
)
19525 if (! process_notes_at (filedata
, NULL
,
19526 (bfd_vma
) segment
->p_offset
,
19527 (bfd_vma
) segment
->p_filesz
,
19528 (bfd_vma
) segment
->p_align
))
19536 process_v850_notes (Filedata
* filedata
, bfd_vma offset
, bfd_vma length
)
19538 Elf_External_Note
* pnotes
;
19539 Elf_External_Note
* external
;
19541 bfd_boolean res
= TRUE
;
19546 pnotes
= (Elf_External_Note
*) get_data (NULL
, filedata
, offset
, 1, length
,
19548 if (pnotes
== NULL
)
19552 end
= (char*) pnotes
+ length
;
19554 printf (_("\nDisplaying contents of Renesas V850 notes section at offset 0x%lx with length 0x%lx:\n"),
19555 (unsigned long) offset
, (unsigned long) length
);
19557 while ((char *) external
+ sizeof (Elf_External_Note
) < end
)
19559 Elf_External_Note
* next
;
19560 Elf_Internal_Note inote
;
19562 inote
.type
= BYTE_GET (external
->type
);
19563 inote
.namesz
= BYTE_GET (external
->namesz
);
19564 inote
.namedata
= external
->name
;
19565 inote
.descsz
= BYTE_GET (external
->descsz
);
19566 inote
.descdata
= inote
.namedata
+ align_power (inote
.namesz
, 2);
19567 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
19569 if (inote
.descdata
< (char *) pnotes
|| inote
.descdata
>= end
)
19571 warn (_("Corrupt note: name size is too big: %lx\n"), inote
.namesz
);
19572 inote
.descdata
= inote
.namedata
;
19576 next
= (Elf_External_Note
*) (inote
.descdata
+ align_power (inote
.descsz
, 2));
19578 if ( ((char *) next
> end
)
19579 || ((char *) next
< (char *) pnotes
))
19581 warn (_("corrupt descsz found in note at offset 0x%lx\n"),
19582 (unsigned long) ((char *) external
- (char *) pnotes
));
19583 warn (_(" type: 0x%lx, namesize: 0x%lx, descsize: 0x%lx\n"),
19584 inote
.type
, inote
.namesz
, inote
.descsz
);
19590 /* Prevent out-of-bounds indexing. */
19591 if ( inote
.namedata
+ inote
.namesz
> end
19592 || inote
.namedata
+ inote
.namesz
< inote
.namedata
)
19594 warn (_("corrupt namesz found in note at offset 0x%lx\n"),
19595 (unsigned long) ((char *) external
- (char *) pnotes
));
19596 warn (_(" type: 0x%lx, namesize: 0x%lx, descsize: 0x%lx\n"),
19597 inote
.type
, inote
.namesz
, inote
.descsz
);
19601 printf (" %s: ", get_v850_elf_note_type (inote
.type
));
19603 if (! print_v850_note (& inote
))
19606 printf ("<corrupt sizes: namesz: %lx, descsz: %lx>\n",
19607 inote
.namesz
, inote
.descsz
);
19617 process_note_sections (Filedata
* filedata
)
19619 Elf_Internal_Shdr
* section
;
19621 unsigned int n
= 0;
19622 bfd_boolean res
= TRUE
;
19624 for (i
= 0, section
= filedata
->section_headers
;
19625 i
< filedata
->file_header
.e_shnum
&& section
!= NULL
;
19628 if (section
->sh_type
== SHT_NOTE
)
19630 if (! process_notes_at (filedata
, section
,
19631 (bfd_vma
) section
->sh_offset
,
19632 (bfd_vma
) section
->sh_size
,
19633 (bfd_vma
) section
->sh_addralign
))
19638 if (( filedata
->file_header
.e_machine
== EM_V800
19639 || filedata
->file_header
.e_machine
== EM_V850
19640 || filedata
->file_header
.e_machine
== EM_CYGNUS_V850
)
19641 && section
->sh_type
== SHT_RENESAS_INFO
)
19643 if (! process_v850_notes (filedata
,
19644 (bfd_vma
) section
->sh_offset
,
19645 (bfd_vma
) section
->sh_size
))
19652 /* Try processing NOTE segments instead. */
19653 return process_corefile_note_segments (filedata
);
19659 process_notes (Filedata
* filedata
)
19661 /* If we have not been asked to display the notes then do nothing. */
19665 if (filedata
->file_header
.e_type
!= ET_CORE
)
19666 return process_note_sections (filedata
);
19668 /* No program headers means no NOTE segment. */
19669 if (filedata
->file_header
.e_phnum
> 0)
19670 return process_corefile_note_segments (filedata
);
19672 printf (_("No note segments present in the core file.\n"));
19676 static unsigned char *
19677 display_public_gnu_attributes (unsigned char * start
,
19678 const unsigned char * const end
)
19680 printf (_(" Unknown GNU attribute: %s\n"), start
);
19682 start
+= strnlen ((char *) start
, end
- start
);
19683 display_raw_attribute (start
, end
);
19685 return (unsigned char *) end
;
19688 static unsigned char *
19689 display_generic_attribute (unsigned char * start
,
19691 const unsigned char * const end
)
19694 return (unsigned char *) end
;
19696 return display_tag_value (tag
, start
, end
);
19700 process_arch_specific (Filedata
* filedata
)
19705 switch (filedata
->file_header
.e_machine
)
19708 case EM_ARC_COMPACT
:
19709 case EM_ARC_COMPACT2
:
19710 return process_attributes (filedata
, "ARC", SHT_ARC_ATTRIBUTES
,
19711 display_arc_attribute
,
19712 display_generic_attribute
);
19714 return process_attributes (filedata
, "aeabi", SHT_ARM_ATTRIBUTES
,
19715 display_arm_attribute
,
19716 display_generic_attribute
);
19719 case EM_MIPS_RS3_LE
:
19720 return process_mips_specific (filedata
);
19723 return process_attributes (filedata
, "mspabi", SHT_MSP430_ATTRIBUTES
,
19724 display_msp430x_attribute
,
19725 display_msp430_gnu_attribute
);
19728 return process_attributes (filedata
, "riscv", SHT_RISCV_ATTRIBUTES
,
19729 display_riscv_attribute
,
19730 display_generic_attribute
);
19733 return process_nds32_specific (filedata
);
19737 return process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
19738 display_power_gnu_attribute
);
19742 return process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
19743 display_s390_gnu_attribute
);
19746 case EM_SPARC32PLUS
:
19748 return process_attributes (filedata
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
19749 display_sparc_gnu_attribute
);
19752 return process_attributes (filedata
, "c6xabi", SHT_C6000_ATTRIBUTES
,
19753 display_tic6x_attribute
,
19754 display_generic_attribute
);
19757 return process_attributes (filedata
, "gnu", SHT_GNU_ATTRIBUTES
,
19758 display_public_gnu_attributes
,
19759 display_generic_attribute
);
19764 get_file_header (Filedata
* filedata
)
19766 /* Read in the identity array. */
19767 if (fread (filedata
->file_header
.e_ident
, EI_NIDENT
, 1, filedata
->handle
) != 1)
19770 /* Determine how to read the rest of the header. */
19771 switch (filedata
->file_header
.e_ident
[EI_DATA
])
19776 byte_get
= byte_get_little_endian
;
19777 byte_put
= byte_put_little_endian
;
19780 byte_get
= byte_get_big_endian
;
19781 byte_put
= byte_put_big_endian
;
19785 /* For now we only support 32 bit and 64 bit ELF files. */
19786 is_32bit_elf
= (filedata
->file_header
.e_ident
[EI_CLASS
] != ELFCLASS64
);
19788 /* Read in the rest of the header. */
19791 Elf32_External_Ehdr ehdr32
;
19793 if (fread (ehdr32
.e_type
, sizeof (ehdr32
) - EI_NIDENT
, 1, filedata
->handle
) != 1)
19796 filedata
->file_header
.e_type
= BYTE_GET (ehdr32
.e_type
);
19797 filedata
->file_header
.e_machine
= BYTE_GET (ehdr32
.e_machine
);
19798 filedata
->file_header
.e_version
= BYTE_GET (ehdr32
.e_version
);
19799 filedata
->file_header
.e_entry
= BYTE_GET (ehdr32
.e_entry
);
19800 filedata
->file_header
.e_phoff
= BYTE_GET (ehdr32
.e_phoff
);
19801 filedata
->file_header
.e_shoff
= BYTE_GET (ehdr32
.e_shoff
);
19802 filedata
->file_header
.e_flags
= BYTE_GET (ehdr32
.e_flags
);
19803 filedata
->file_header
.e_ehsize
= BYTE_GET (ehdr32
.e_ehsize
);
19804 filedata
->file_header
.e_phentsize
= BYTE_GET (ehdr32
.e_phentsize
);
19805 filedata
->file_header
.e_phnum
= BYTE_GET (ehdr32
.e_phnum
);
19806 filedata
->file_header
.e_shentsize
= BYTE_GET (ehdr32
.e_shentsize
);
19807 filedata
->file_header
.e_shnum
= BYTE_GET (ehdr32
.e_shnum
);
19808 filedata
->file_header
.e_shstrndx
= BYTE_GET (ehdr32
.e_shstrndx
);
19812 Elf64_External_Ehdr ehdr64
;
19814 /* If we have been compiled with sizeof (bfd_vma) == 4, then
19815 we will not be able to cope with the 64bit data found in
19816 64 ELF files. Detect this now and abort before we start
19817 overwriting things. */
19818 if (sizeof (bfd_vma
) < 8)
19820 error (_("This instance of readelf has been built without support for a\n\
19821 64 bit data type and so it cannot read 64 bit ELF files.\n"));
19825 if (fread (ehdr64
.e_type
, sizeof (ehdr64
) - EI_NIDENT
, 1, filedata
->handle
) != 1)
19828 filedata
->file_header
.e_type
= BYTE_GET (ehdr64
.e_type
);
19829 filedata
->file_header
.e_machine
= BYTE_GET (ehdr64
.e_machine
);
19830 filedata
->file_header
.e_version
= BYTE_GET (ehdr64
.e_version
);
19831 filedata
->file_header
.e_entry
= BYTE_GET (ehdr64
.e_entry
);
19832 filedata
->file_header
.e_phoff
= BYTE_GET (ehdr64
.e_phoff
);
19833 filedata
->file_header
.e_shoff
= BYTE_GET (ehdr64
.e_shoff
);
19834 filedata
->file_header
.e_flags
= BYTE_GET (ehdr64
.e_flags
);
19835 filedata
->file_header
.e_ehsize
= BYTE_GET (ehdr64
.e_ehsize
);
19836 filedata
->file_header
.e_phentsize
= BYTE_GET (ehdr64
.e_phentsize
);
19837 filedata
->file_header
.e_phnum
= BYTE_GET (ehdr64
.e_phnum
);
19838 filedata
->file_header
.e_shentsize
= BYTE_GET (ehdr64
.e_shentsize
);
19839 filedata
->file_header
.e_shnum
= BYTE_GET (ehdr64
.e_shnum
);
19840 filedata
->file_header
.e_shstrndx
= BYTE_GET (ehdr64
.e_shstrndx
);
19843 if (filedata
->file_header
.e_shoff
)
19845 /* There may be some extensions in the first section header. Don't
19846 bomb if we can't read it. */
19848 get_32bit_section_headers (filedata
, TRUE
);
19850 get_64bit_section_headers (filedata
, TRUE
);
19857 close_file (Filedata
* filedata
)
19861 if (filedata
->handle
)
19862 fclose (filedata
->handle
);
19868 close_debug_file (void * data
)
19870 close_file ((Filedata
*) data
);
19874 open_file (const char * pathname
)
19876 struct stat statbuf
;
19877 Filedata
* filedata
= NULL
;
19879 if (stat (pathname
, & statbuf
) < 0
19880 || ! S_ISREG (statbuf
.st_mode
))
19883 filedata
= calloc (1, sizeof * filedata
);
19884 if (filedata
== NULL
)
19887 filedata
->handle
= fopen (pathname
, "rb");
19888 if (filedata
->handle
== NULL
)
19891 filedata
->file_size
= (bfd_size_type
) statbuf
.st_size
;
19892 filedata
->file_name
= pathname
;
19894 if (! get_file_header (filedata
))
19897 if (filedata
->file_header
.e_shoff
)
19901 /* Read the section headers again, this time for real. */
19903 res
= get_32bit_section_headers (filedata
, FALSE
);
19905 res
= get_64bit_section_headers (filedata
, FALSE
);
19916 if (filedata
->handle
)
19917 fclose (filedata
->handle
);
19924 open_debug_file (const char * pathname
)
19926 return open_file (pathname
);
19929 /* Process one ELF object file according to the command line options.
19930 This file may actually be stored in an archive. The file is
19931 positioned at the start of the ELF object. Returns TRUE if no
19932 problems were encountered, FALSE otherwise. */
19935 process_object (Filedata
* filedata
)
19937 bfd_boolean have_separate_files
;
19939 bfd_boolean res
= TRUE
;
19941 if (! get_file_header (filedata
))
19943 error (_("%s: Failed to read file header\n"), filedata
->file_name
);
19947 /* Initialise per file variables. */
19948 for (i
= ARRAY_SIZE (version_info
); i
--;)
19949 version_info
[i
] = 0;
19951 for (i
= ARRAY_SIZE (dynamic_info
); i
--;)
19952 dynamic_info
[i
] = 0;
19953 dynamic_info_DT_GNU_HASH
= 0;
19954 dynamic_info_DT_MIPS_XHASH
= 0;
19956 /* Process the file. */
19958 printf (_("\nFile: %s\n"), filedata
->file_name
);
19960 /* Initialise the dump_sects array from the cmdline_dump_sects array.
19961 Note we do this even if cmdline_dump_sects is empty because we
19962 must make sure that the dump_sets array is zeroed out before each
19963 object file is processed. */
19964 if (filedata
->num_dump_sects
> cmdline
.num_dump_sects
)
19965 memset (filedata
->dump_sects
, 0, filedata
->num_dump_sects
* sizeof (* filedata
->dump_sects
));
19967 if (cmdline
.num_dump_sects
> 0)
19969 if (filedata
->num_dump_sects
== 0)
19970 /* A sneaky way of allocating the dump_sects array. */
19971 request_dump_bynumber (filedata
, cmdline
.num_dump_sects
, 0);
19973 assert (filedata
->num_dump_sects
>= cmdline
.num_dump_sects
);
19974 memcpy (filedata
->dump_sects
, cmdline
.dump_sects
,
19975 cmdline
.num_dump_sects
* sizeof (* filedata
->dump_sects
));
19978 if (! process_file_header (filedata
))
19981 if (! process_section_headers (filedata
))
19983 /* Without loaded section headers we cannot process lots of things. */
19984 do_unwind
= do_version
= do_dump
= do_arch
= FALSE
;
19986 if (! do_using_dynamic
)
19987 do_syms
= do_dyn_syms
= do_reloc
= FALSE
;
19990 if (! process_section_groups (filedata
))
19991 /* Without loaded section groups we cannot process unwind. */
19994 if (process_program_headers (filedata
))
19995 process_dynamic_section (filedata
);
19999 if (! process_relocs (filedata
))
20002 if (! process_unwind (filedata
))
20005 if (! process_symbol_table (filedata
))
20008 if (! process_syminfo (filedata
))
20011 if (! process_version_sections (filedata
))
20014 if (filedata
->file_header
.e_shstrndx
!= SHN_UNDEF
)
20015 have_separate_files
= load_separate_debug_files (filedata
, filedata
->file_name
);
20017 have_separate_files
= FALSE
;
20019 if (! process_section_contents (filedata
))
20022 if (have_separate_files
)
20026 for (d
= first_separate_info
; d
!= NULL
; d
= d
->next
)
20028 if (! process_section_headers (d
->handle
))
20030 else if (! process_section_contents (d
->handle
))
20034 /* The file handles are closed by the call to free_debug_memory() below. */
20037 if (! process_notes (filedata
))
20040 if (! process_gnu_liblist (filedata
))
20043 if (! process_arch_specific (filedata
))
20046 free (filedata
->program_headers
);
20047 filedata
->program_headers
= NULL
;
20049 free (filedata
->section_headers
);
20050 filedata
->section_headers
= NULL
;
20052 free (filedata
->string_table
);
20053 filedata
->string_table
= NULL
;
20054 filedata
->string_table_length
= 0;
20056 if (dynamic_strings
)
20058 free (dynamic_strings
);
20059 dynamic_strings
= NULL
;
20060 dynamic_strings_length
= 0;
20063 if (dynamic_symbols
)
20065 free (dynamic_symbols
);
20066 dynamic_symbols
= NULL
;
20067 num_dynamic_syms
= 0;
20070 if (dynamic_syminfo
)
20072 free (dynamic_syminfo
);
20073 dynamic_syminfo
= NULL
;
20076 if (dynamic_section
)
20078 free (dynamic_section
);
20079 dynamic_section
= NULL
;
20082 if (section_headers_groups
)
20084 free (section_headers_groups
);
20085 section_headers_groups
= NULL
;
20088 if (section_groups
)
20090 struct group_list
* g
;
20091 struct group_list
* next
;
20093 for (i
= 0; i
< group_count
; i
++)
20095 for (g
= section_groups
[i
].root
; g
!= NULL
; g
= next
)
20102 free (section_groups
);
20103 section_groups
= NULL
;
20106 free_debug_memory ();
20111 /* Process an ELF archive.
20112 On entry the file is positioned just after the ARMAG string.
20113 Returns TRUE upon success, FALSE otherwise. */
20116 process_archive (Filedata
* filedata
, bfd_boolean is_thin_archive
)
20118 struct archive_info arch
;
20119 struct archive_info nested_arch
;
20121 bfd_boolean ret
= TRUE
;
20125 /* The ARCH structure is used to hold information about this archive. */
20126 arch
.file_name
= NULL
;
20128 arch
.index_array
= NULL
;
20129 arch
.sym_table
= NULL
;
20130 arch
.longnames
= NULL
;
20132 /* The NESTED_ARCH structure is used as a single-item cache of information
20133 about a nested archive (when members of a thin archive reside within
20134 another regular archive file). */
20135 nested_arch
.file_name
= NULL
;
20136 nested_arch
.file
= NULL
;
20137 nested_arch
.index_array
= NULL
;
20138 nested_arch
.sym_table
= NULL
;
20139 nested_arch
.longnames
= NULL
;
20141 if (setup_archive (&arch
, filedata
->file_name
, filedata
->handle
,
20142 is_thin_archive
, do_archive_index
) != 0)
20148 if (do_archive_index
)
20150 if (arch
.sym_table
== NULL
)
20151 error (_("%s: unable to dump the index as none was found\n"), filedata
->file_name
);
20154 unsigned long i
, l
;
20155 unsigned long current_pos
;
20157 printf (_("Index of archive %s: (%lu entries, 0x%lx bytes in the symbol table)\n"),
20158 filedata
->file_name
, (unsigned long) arch
.index_num
, arch
.sym_size
);
20160 current_pos
= ftell (filedata
->handle
);
20162 for (i
= l
= 0; i
< arch
.index_num
; i
++)
20164 if ((i
== 0) || ((i
> 0) && (arch
.index_array
[i
] != arch
.index_array
[i
- 1])))
20166 char * member_name
;
20168 member_name
= get_archive_member_name_at (&arch
, arch
.index_array
[i
], &nested_arch
);
20170 if (member_name
!= NULL
)
20172 char * qualified_name
= make_qualified_name (&arch
, &nested_arch
, member_name
);
20174 if (qualified_name
!= NULL
)
20176 printf (_("Contents of binary %s at offset "), qualified_name
);
20177 (void) print_vma (arch
.index_array
[i
], PREFIX_HEX
);
20179 free (qualified_name
);
20184 if (l
>= arch
.sym_size
)
20186 error (_("%s: end of the symbol table reached before the end of the index\n"),
20187 filedata
->file_name
);
20191 /* PR 17531: file: 0b6630b2. */
20192 printf ("\t%.*s\n", (int) (arch
.sym_size
- l
), arch
.sym_table
+ l
);
20193 l
+= strnlen (arch
.sym_table
+ l
, arch
.sym_size
- l
) + 1;
20196 if (arch
.uses_64bit_indices
)
20201 if (l
< arch
.sym_size
)
20203 error (ngettext ("%s: %ld byte remains in the symbol table, "
20204 "but without corresponding entries in "
20205 "the index table\n",
20206 "%s: %ld bytes remain in the symbol table, "
20207 "but without corresponding entries in "
20208 "the index table\n",
20209 arch
.sym_size
- l
),
20210 filedata
->file_name
, arch
.sym_size
- l
);
20214 if (fseek (filedata
->handle
, current_pos
, SEEK_SET
) != 0)
20216 error (_("%s: failed to seek back to start of object files in the archive\n"),
20217 filedata
->file_name
);
20223 if (!do_dynamic
&& !do_syms
&& !do_reloc
&& !do_unwind
&& !do_sections
20224 && !do_segments
&& !do_header
&& !do_dump
&& !do_version
20225 && !do_histogram
&& !do_debugging
&& !do_arch
&& !do_notes
20226 && !do_section_groups
&& !do_dyn_syms
)
20228 ret
= TRUE
; /* Archive index only. */
20237 char * qualified_name
;
20239 /* Read the next archive header. */
20240 if (fseek (filedata
->handle
, arch
.next_arhdr_offset
, SEEK_SET
) != 0)
20242 error (_("%s: failed to seek to next archive header\n"), arch
.file_name
);
20245 got
= fread (&arch
.arhdr
, 1, sizeof arch
.arhdr
, filedata
->handle
);
20246 if (got
!= sizeof arch
.arhdr
)
20250 /* PR 24049 - we cannot use filedata->file_name as this will
20251 have already been freed. */
20252 error (_("%s: failed to read archive header\n"), arch
.file_name
);
20257 if (memcmp (arch
.arhdr
.ar_fmag
, ARFMAG
, 2) != 0)
20259 error (_("%s: did not find a valid archive header\n"), arch
.file_name
);
20264 arch
.next_arhdr_offset
+= sizeof arch
.arhdr
;
20266 archive_file_size
= strtoul (arch
.arhdr
.ar_size
, NULL
, 10);
20267 if (archive_file_size
& 01)
20268 ++archive_file_size
;
20270 name
= get_archive_member_name (&arch
, &nested_arch
);
20273 error (_("%s: bad archive file name\n"), arch
.file_name
);
20277 namelen
= strlen (name
);
20279 qualified_name
= make_qualified_name (&arch
, &nested_arch
, name
);
20280 if (qualified_name
== NULL
)
20282 error (_("%s: bad archive file name\n"), arch
.file_name
);
20287 if (is_thin_archive
&& arch
.nested_member_origin
== 0)
20289 /* This is a proxy for an external member of a thin archive. */
20290 Filedata
* member_filedata
;
20291 char * member_file_name
= adjust_relative_path
20292 (filedata
->file_name
, name
, namelen
);
20294 if (member_file_name
== NULL
)
20300 member_filedata
= open_file (member_file_name
);
20301 if (member_filedata
== NULL
)
20303 error (_("Input file '%s' is not readable.\n"), member_file_name
);
20304 free (member_file_name
);
20309 archive_file_offset
= arch
.nested_member_origin
;
20310 member_filedata
->file_name
= qualified_name
;
20312 if (! process_object (member_filedata
))
20315 close_file (member_filedata
);
20316 free (member_file_name
);
20318 else if (is_thin_archive
)
20320 Filedata thin_filedata
;
20322 memset (&thin_filedata
, 0, sizeof (thin_filedata
));
20324 /* PR 15140: Allow for corrupt thin archives. */
20325 if (nested_arch
.file
== NULL
)
20327 error (_("%s: contains corrupt thin archive: %s\n"),
20328 qualified_name
, name
);
20333 /* This is a proxy for a member of a nested archive. */
20334 archive_file_offset
= arch
.nested_member_origin
+ sizeof arch
.arhdr
;
20336 /* The nested archive file will have been opened and setup by
20337 get_archive_member_name. */
20338 if (fseek (nested_arch
.file
, archive_file_offset
, SEEK_SET
) != 0)
20340 error (_("%s: failed to seek to archive member.\n"), nested_arch
.file_name
);
20345 thin_filedata
.handle
= nested_arch
.file
;
20346 thin_filedata
.file_name
= qualified_name
;
20348 if (! process_object (& thin_filedata
))
20353 archive_file_offset
= arch
.next_arhdr_offset
;
20354 arch
.next_arhdr_offset
+= archive_file_size
;
20356 filedata
->file_name
= qualified_name
;
20357 if (! process_object (filedata
))
20361 if (filedata
->dump_sects
!= NULL
)
20363 free (filedata
->dump_sects
);
20364 filedata
->dump_sects
= NULL
;
20365 filedata
->num_dump_sects
= 0;
20368 free (qualified_name
);
20372 if (nested_arch
.file
!= NULL
)
20373 fclose (nested_arch
.file
);
20374 release_archive (&nested_arch
);
20375 release_archive (&arch
);
20381 process_file (char * file_name
)
20383 Filedata
* filedata
= NULL
;
20384 struct stat statbuf
;
20385 char armag
[SARMAG
];
20386 bfd_boolean ret
= TRUE
;
20388 if (stat (file_name
, &statbuf
) < 0)
20390 if (errno
== ENOENT
)
20391 error (_("'%s': No such file\n"), file_name
);
20393 error (_("Could not locate '%s'. System error message: %s\n"),
20394 file_name
, strerror (errno
));
20398 if (! S_ISREG (statbuf
.st_mode
))
20400 error (_("'%s' is not an ordinary file\n"), file_name
);
20404 filedata
= calloc (1, sizeof * filedata
);
20405 if (filedata
== NULL
)
20407 error (_("Out of memory allocating file data structure\n"));
20411 filedata
->file_name
= file_name
;
20412 filedata
->handle
= fopen (file_name
, "rb");
20413 if (filedata
->handle
== NULL
)
20415 error (_("Input file '%s' is not readable.\n"), file_name
);
20420 if (fread (armag
, SARMAG
, 1, filedata
->handle
) != 1)
20422 error (_("%s: Failed to read file's magic number\n"), file_name
);
20423 fclose (filedata
->handle
);
20428 filedata
->file_size
= (bfd_size_type
) statbuf
.st_size
;
20430 if (memcmp (armag
, ARMAG
, SARMAG
) == 0)
20432 if (! process_archive (filedata
, FALSE
))
20435 else if (memcmp (armag
, ARMAGT
, SARMAG
) == 0)
20437 if ( ! process_archive (filedata
, TRUE
))
20442 if (do_archive_index
)
20443 error (_("File %s is not an archive so its index cannot be displayed.\n"),
20446 rewind (filedata
->handle
);
20447 archive_file_size
= archive_file_offset
= 0;
20449 if (! process_object (filedata
))
20453 fclose (filedata
->handle
);
20459 #ifdef SUPPORT_DISASSEMBLY
20460 /* Needed by the i386 disassembler. For extra credit, someone could
20461 fix this so that we insert symbolic addresses here, esp for GOT/PLT
20465 print_address (unsigned int addr
, FILE * outfile
)
20467 fprintf (outfile
,"0x%8.8x", addr
);
20470 /* Needed by the i386 disassembler. */
20473 db_task_printsym (unsigned int addr
)
20475 print_address (addr
, stderr
);
20480 main (int argc
, char ** argv
)
20484 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
20485 setlocale (LC_MESSAGES
, "");
20487 #if defined (HAVE_SETLOCALE)
20488 setlocale (LC_CTYPE
, "");
20490 bindtextdomain (PACKAGE
, LOCALEDIR
);
20491 textdomain (PACKAGE
);
20493 expandargv (&argc
, &argv
);
20495 cmdline
.file_name
= "<cmdline>";
20496 parse_args (& cmdline
, argc
, argv
);
20498 if (optind
< (argc
- 1))
20500 else if (optind
>= argc
)
20502 warn (_("Nothing to do.\n"));
20507 while (optind
< argc
)
20508 if (! process_file (argv
[optind
++]))
20511 if (cmdline
.dump_sects
!= NULL
)
20512 free (cmdline
.dump_sects
);
20514 free (dump_ctf_symtab_name
);
20515 free (dump_ctf_strtab_name
);
20516 free (dump_ctf_parent_name
);
20518 return err
? EXIT_FAILURE
: EXIT_SUCCESS
;