]>
Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* readelf.c -- display contents of an ELF format file |
250d07de | 2 | Copyright (C) 1998-2021 Free Software Foundation, Inc. |
252b5132 RH |
3 | |
4 | Originally developed by Eric Youngdale <eric@andante.jic.com> | |
12ab83a9 | 5 | Modifications by Nick Clifton <nickc@redhat.com> |
252b5132 RH |
6 | |
7 | This file is part of GNU Binutils. | |
8 | ||
9 | This program is free software; you can redistribute it and/or modify | |
10 | it under the terms of the GNU General Public License as published by | |
32866df7 | 11 | the Free Software Foundation; either version 3 of the License, or |
252b5132 RH |
12 | (at your option) any later version. |
13 | ||
14 | This program is distributed in the hope that it will be useful, | |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
18 | ||
19 | You should have received a copy of the GNU General Public License | |
20 | along with this program; if not, write to the Free Software | |
b43b5d5f NC |
21 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA |
22 | 02110-1301, USA. */ | |
252b5132 | 23 | \f |
9eb20dd8 | 24 | /* The difference between readelf and objdump: |
252b5132 | 25 | |
74013231 | 26 | Both programs are capable of displaying the contents of ELF format files, |
9eb20dd8 | 27 | so why does the binutils project have two file dumpers ? |
0de14b54 | 28 | |
9eb20dd8 NC |
29 | The reason is that objdump sees an ELF file through a BFD filter of the |
30 | world; if BFD has a bug where, say, it disagrees about a machine constant | |
31 | in e_flags, then the odds are good that it will remain internally | |
32 | consistent. The linker sees it the BFD way, objdump sees it the BFD way, | |
33 | GAS sees it the BFD way. There was need for a tool to go find out what | |
34 | the file actually says. | |
35 | ||
36 | This is why the readelf program does not link against the BFD library - it | |
37 | exists as an independent program to help verify the correct working of BFD. | |
38 | ||
39 | There is also the case that readelf can provide more information about an | |
40 | ELF file than is provided by objdump. In particular it can display DWARF | |
41 | debugging information which (at the moment) objdump cannot. */ | |
42 | \f | |
3db64b00 | 43 | #include "sysdep.h" |
252b5132 | 44 | #include <assert.h> |
252b5132 | 45 | #include <time.h> |
1b315056 | 46 | #include <zlib.h> |
7bfd842d | 47 | #include <wchar.h> |
252b5132 | 48 | |
a952a375 | 49 | #if __GNUC__ >= 2 |
19936277 | 50 | /* Define BFD64 here, even if our default architecture is 32 bit ELF |
a952a375 | 51 | as this will allow us to read in and parse 64bit and 32bit ELF files. |
b34976b6 | 52 | Only do this if we believe that the compiler can support a 64 bit |
a952a375 | 53 | data type. For now we only rely on GCC being able to do this. */ |
19936277 | 54 | #define BFD64 |
a952a375 NC |
55 | #endif |
56 | ||
3db64b00 AM |
57 | #include "bfd.h" |
58 | #include "bucomm.h" | |
3284fe0c | 59 | #include "elfcomm.h" |
19e6b90e | 60 | #include "dwarf.h" |
7d9813f1 | 61 | #include "ctf-api.h" |
79bc120c | 62 | #include "demangle.h" |
252b5132 RH |
63 | |
64 | #include "elf/common.h" | |
65 | #include "elf/external.h" | |
66 | #include "elf/internal.h" | |
252b5132 | 67 | |
4b78141a NC |
68 | |
69 | /* Included here, before RELOC_MACROS_GEN_FUNC is defined, so that | |
70 | we can obtain the H8 reloc numbers. We need these for the | |
71 | get_reloc_size() function. We include h8.h again after defining | |
72 | RELOC_MACROS_GEN_FUNC so that we get the naming function as well. */ | |
73 | ||
74 | #include "elf/h8.h" | |
75 | #undef _ELF_H8_H | |
76 | ||
77 | /* Undo the effects of #including reloc-macros.h. */ | |
78 | ||
79 | #undef START_RELOC_NUMBERS | |
80 | #undef RELOC_NUMBER | |
81 | #undef FAKE_RELOC | |
82 | #undef EMPTY_RELOC | |
83 | #undef END_RELOC_NUMBERS | |
84 | #undef _RELOC_MACROS_H | |
85 | ||
252b5132 RH |
86 | /* The following headers use the elf/reloc-macros.h file to |
87 | automatically generate relocation recognition functions | |
88 | such as elf_mips_reloc_type() */ | |
89 | ||
90 | #define RELOC_MACROS_GEN_FUNC | |
91 | ||
a06ea964 | 92 | #include "elf/aarch64.h" |
252b5132 | 93 | #include "elf/alpha.h" |
3b16e843 | 94 | #include "elf/arc.h" |
252b5132 | 95 | #include "elf/arm.h" |
3b16e843 | 96 | #include "elf/avr.h" |
1d65ded4 | 97 | #include "elf/bfin.h" |
60bca95a | 98 | #include "elf/cr16.h" |
3b16e843 | 99 | #include "elf/cris.h" |
1c0d3aa6 | 100 | #include "elf/crx.h" |
b8891f8d | 101 | #include "elf/csky.h" |
252b5132 RH |
102 | #include "elf/d10v.h" |
103 | #include "elf/d30v.h" | |
d172d4ba | 104 | #include "elf/dlx.h" |
aca4efc7 | 105 | #include "elf/bpf.h" |
cfb8c092 | 106 | #include "elf/epiphany.h" |
252b5132 | 107 | #include "elf/fr30.h" |
5c70f934 | 108 | #include "elf/frv.h" |
3f8107ab | 109 | #include "elf/ft32.h" |
3b16e843 NC |
110 | #include "elf/h8.h" |
111 | #include "elf/hppa.h" | |
112 | #include "elf/i386.h" | |
f954747f AM |
113 | #include "elf/i370.h" |
114 | #include "elf/i860.h" | |
115 | #include "elf/i960.h" | |
3b16e843 | 116 | #include "elf/ia64.h" |
1e4cf259 | 117 | #include "elf/ip2k.h" |
84e94c90 | 118 | #include "elf/lm32.h" |
1c0d3aa6 | 119 | #include "elf/iq2000.h" |
49f58d10 | 120 | #include "elf/m32c.h" |
3b16e843 NC |
121 | #include "elf/m32r.h" |
122 | #include "elf/m68k.h" | |
75751cd9 | 123 | #include "elf/m68hc11.h" |
7b4ae824 | 124 | #include "elf/s12z.h" |
252b5132 | 125 | #include "elf/mcore.h" |
15ab5209 | 126 | #include "elf/mep.h" |
a3c62988 | 127 | #include "elf/metag.h" |
7ba29e2a | 128 | #include "elf/microblaze.h" |
3b16e843 | 129 | #include "elf/mips.h" |
3c3bdf30 | 130 | #include "elf/mmix.h" |
3b16e843 NC |
131 | #include "elf/mn10200.h" |
132 | #include "elf/mn10300.h" | |
5506d11a | 133 | #include "elf/moxie.h" |
4970f871 | 134 | #include "elf/mt.h" |
2469cfa2 | 135 | #include "elf/msp430.h" |
35c08157 | 136 | #include "elf/nds32.h" |
fe944acf | 137 | #include "elf/nfp.h" |
13761a11 | 138 | #include "elf/nios2.h" |
73589c9d | 139 | #include "elf/or1k.h" |
7d466069 | 140 | #include "elf/pj.h" |
3b16e843 | 141 | #include "elf/ppc.h" |
c833c019 | 142 | #include "elf/ppc64.h" |
2b100bb5 | 143 | #include "elf/pru.h" |
03336641 | 144 | #include "elf/riscv.h" |
99c513f6 | 145 | #include "elf/rl78.h" |
c7927a3c | 146 | #include "elf/rx.h" |
a85d7ed0 | 147 | #include "elf/s390.h" |
1c0d3aa6 | 148 | #include "elf/score.h" |
3b16e843 NC |
149 | #include "elf/sh.h" |
150 | #include "elf/sparc.h" | |
e9f53129 | 151 | #include "elf/spu.h" |
40b36596 | 152 | #include "elf/tic6x.h" |
aa137e4d NC |
153 | #include "elf/tilegx.h" |
154 | #include "elf/tilepro.h" | |
3b16e843 | 155 | #include "elf/v850.h" |
179d3252 | 156 | #include "elf/vax.h" |
619ed720 | 157 | #include "elf/visium.h" |
f96bd6c2 | 158 | #include "elf/wasm32.h" |
3b16e843 | 159 | #include "elf/x86-64.h" |
c29aca4a | 160 | #include "elf/xc16x.h" |
f6c1a2d5 | 161 | #include "elf/xgate.h" |
93fbbb04 | 162 | #include "elf/xstormy16.h" |
88da6820 | 163 | #include "elf/xtensa.h" |
6655dba2 | 164 | #include "elf/z80.h" |
e9a0721f | 165 | #include "elf/loongarch.h" |
252b5132 | 166 | |
252b5132 | 167 | #include "getopt.h" |
566b0d53 | 168 | #include "libiberty.h" |
09c11c86 | 169 | #include "safe-ctype.h" |
2cf0635d | 170 | #include "filenames.h" |
252b5132 | 171 | |
15b42fb0 AM |
172 | #ifndef offsetof |
173 | #define offsetof(TYPE, MEMBER) ((size_t) &(((TYPE *) 0)->MEMBER)) | |
174 | #endif | |
175 | ||
6a40cf0c NC |
176 | typedef struct elf_section_list |
177 | { | |
dda8d76d NC |
178 | Elf_Internal_Shdr * hdr; |
179 | struct elf_section_list * next; | |
6a40cf0c NC |
180 | } elf_section_list; |
181 | ||
dda8d76d NC |
182 | /* Flag bits indicating particular types of dump. */ |
183 | #define HEX_DUMP (1 << 0) /* The -x command line switch. */ | |
184 | #define DISASS_DUMP (1 << 1) /* The -i command line switch. */ | |
185 | #define DEBUG_DUMP (1 << 2) /* The -w command line switch. */ | |
186 | #define STRING_DUMP (1 << 3) /* The -p command line switch. */ | |
187 | #define RELOC_DUMP (1 << 4) /* The -R command line switch. */ | |
d344b407 | 188 | #define CTF_DUMP (1 << 5) /* The --ctf command line switch. */ |
dda8d76d NC |
189 | |
190 | typedef unsigned char dump_type; | |
191 | ||
192 | /* A linked list of the section names for which dumps were requested. */ | |
193 | struct dump_list_entry | |
194 | { | |
195 | char * name; | |
196 | dump_type type; | |
197 | struct dump_list_entry * next; | |
198 | }; | |
199 | ||
6431e409 AM |
200 | /* A dynamic array of flags indicating for which sections a dump |
201 | has been requested via command line switches. */ | |
1b513401 NC |
202 | struct dump_data |
203 | { | |
6431e409 AM |
204 | dump_type * dump_sects; |
205 | unsigned int num_dump_sects; | |
206 | }; | |
207 | ||
208 | static struct dump_data cmdline; | |
209 | ||
210 | static struct dump_list_entry * dump_sects_byname; | |
211 | ||
2cf0635d | 212 | char * program_name = "readelf"; |
dda8d76d | 213 | |
015dc7e1 AM |
214 | static bool show_name = false; |
215 | static bool do_dynamic = false; | |
216 | static bool do_syms = false; | |
217 | static bool do_dyn_syms = false; | |
218 | static bool do_lto_syms = false; | |
219 | static bool do_reloc = false; | |
220 | static bool do_sections = false; | |
221 | static bool do_section_groups = false; | |
222 | static bool do_section_details = false; | |
223 | static bool do_segments = false; | |
224 | static bool do_unwind = false; | |
225 | static bool do_using_dynamic = false; | |
226 | static bool do_header = false; | |
227 | static bool do_dump = false; | |
228 | static bool do_version = false; | |
229 | static bool do_histogram = false; | |
230 | static bool do_debugging = false; | |
231 | static bool do_ctf = false; | |
232 | static bool do_arch = false; | |
233 | static bool do_notes = false; | |
234 | static bool do_archive_index = false; | |
235 | static bool check_all = false; | |
236 | static bool is_32bit_elf = false; | |
237 | static bool decompress_dumps = false; | |
238 | static bool do_not_show_symbol_truncation = false; | |
239 | static bool do_demangle = false; /* Pretty print C++ symbol names. */ | |
240 | static bool process_links = false; | |
79bc120c | 241 | static int demangle_flags = DMGL_ANSI | DMGL_PARAMS; |
047c3dbf | 242 | static int sym_base = 0; |
252b5132 | 243 | |
7d9813f1 NA |
244 | static char *dump_ctf_parent_name; |
245 | static char *dump_ctf_symtab_name; | |
246 | static char *dump_ctf_strtab_name; | |
247 | ||
e4b17d5c L |
248 | struct group_list |
249 | { | |
dda8d76d NC |
250 | struct group_list * next; |
251 | unsigned int section_index; | |
e4b17d5c L |
252 | }; |
253 | ||
254 | struct group | |
255 | { | |
dda8d76d NC |
256 | struct group_list * root; |
257 | unsigned int group_index; | |
e4b17d5c L |
258 | }; |
259 | ||
978c4450 AM |
260 | typedef struct filedata |
261 | { | |
262 | const char * file_name; | |
015dc7e1 | 263 | bool is_separate; |
978c4450 AM |
264 | FILE * handle; |
265 | bfd_size_type file_size; | |
266 | Elf_Internal_Ehdr file_header; | |
066f8fbe AM |
267 | unsigned long archive_file_offset; |
268 | unsigned long archive_file_size; | |
269 | /* Everything below this point is cleared out by free_filedata. */ | |
978c4450 AM |
270 | Elf_Internal_Shdr * section_headers; |
271 | Elf_Internal_Phdr * program_headers; | |
272 | char * string_table; | |
273 | unsigned long string_table_length; | |
978c4450 AM |
274 | unsigned long dynamic_addr; |
275 | bfd_size_type dynamic_size; | |
276 | size_t dynamic_nent; | |
277 | Elf_Internal_Dyn * dynamic_section; | |
8ac10c5b | 278 | Elf_Internal_Shdr * dynamic_strtab_section; |
978c4450 AM |
279 | char * dynamic_strings; |
280 | unsigned long dynamic_strings_length; | |
8ac10c5b | 281 | Elf_Internal_Shdr * dynamic_symtab_section; |
978c4450 AM |
282 | unsigned long num_dynamic_syms; |
283 | Elf_Internal_Sym * dynamic_symbols; | |
284 | bfd_vma version_info[16]; | |
285 | unsigned int dynamic_syminfo_nent; | |
286 | Elf_Internal_Syminfo * dynamic_syminfo; | |
287 | unsigned long dynamic_syminfo_offset; | |
288 | bfd_size_type nbuckets; | |
289 | bfd_size_type nchains; | |
290 | bfd_vma * buckets; | |
291 | bfd_vma * chains; | |
292 | bfd_size_type ngnubuckets; | |
293 | bfd_size_type ngnuchains; | |
294 | bfd_vma * gnubuckets; | |
295 | bfd_vma * gnuchains; | |
296 | bfd_vma * mipsxlat; | |
297 | bfd_vma gnusymidx; | |
13acb58d | 298 | char * program_interpreter; |
978c4450 AM |
299 | bfd_vma dynamic_info[DT_ENCODING]; |
300 | bfd_vma dynamic_info_DT_GNU_HASH; | |
301 | bfd_vma dynamic_info_DT_MIPS_XHASH; | |
302 | elf_section_list * symtab_shndx_list; | |
303 | size_t group_count; | |
304 | struct group * section_groups; | |
305 | struct group ** section_headers_groups; | |
306 | /* A dynamic array of flags indicating for which sections a dump of | |
307 | some kind has been requested. It is reset on a per-object file | |
308 | basis and then initialised from the cmdline_dump_sects array, | |
309 | the results of interpreting the -w switch, and the | |
310 | dump_sects_byname list. */ | |
311 | struct dump_data dump; | |
312 | } Filedata; | |
aef1f6d0 | 313 | |
c256ffe7 | 314 | /* How to print a vma value. */ |
843dd992 NC |
315 | typedef enum print_mode |
316 | { | |
317 | HEX, | |
047c3dbf | 318 | HEX_5, |
843dd992 NC |
319 | DEC, |
320 | DEC_5, | |
321 | UNSIGNED, | |
047c3dbf | 322 | UNSIGNED_5, |
843dd992 | 323 | PREFIX_HEX, |
047c3dbf | 324 | PREFIX_HEX_5, |
843dd992 | 325 | FULL_HEX, |
047c3dbf NL |
326 | LONG_HEX, |
327 | OCTAL, | |
328 | OCTAL_5 | |
843dd992 NC |
329 | } |
330 | print_mode; | |
331 | ||
bb4d2ac2 L |
332 | /* Versioned symbol info. */ |
333 | enum versioned_symbol_info | |
334 | { | |
335 | symbol_undefined, | |
336 | symbol_hidden, | |
337 | symbol_public | |
338 | }; | |
339 | ||
32ec8896 | 340 | static const char * get_symbol_version_string |
015dc7e1 | 341 | (Filedata *, bool, const char *, unsigned long, unsigned, |
32ec8896 | 342 | Elf_Internal_Sym *, enum versioned_symbol_info *, unsigned short *); |
bb4d2ac2 | 343 | |
9c19a809 NC |
344 | #define UNKNOWN -1 |
345 | ||
84714f86 AM |
346 | static inline const char * |
347 | section_name (const Filedata *filedata, const Elf_Internal_Shdr *hdr) | |
348 | { | |
349 | return filedata->string_table + hdr->sh_name; | |
350 | } | |
b9e920ec | 351 | |
84714f86 AM |
352 | static inline bool |
353 | section_name_valid (const Filedata *filedata, const Elf_Internal_Shdr *hdr) | |
354 | { | |
355 | return (hdr != NULL | |
356 | && filedata->string_table != NULL | |
357 | && hdr->sh_name < filedata->string_table_length); | |
358 | } | |
b9e920ec | 359 | |
84714f86 AM |
360 | static inline const char * |
361 | section_name_print (const Filedata *filedata, const Elf_Internal_Shdr *hdr) | |
362 | { | |
363 | if (hdr == NULL) | |
364 | return _("<none>"); | |
365 | if (filedata->string_table == NULL) | |
366 | return _("<no-strings>"); | |
367 | if (hdr->sh_name >= filedata->string_table_length) | |
368 | return _("<corrupt>"); | |
369 | return section_name (filedata, hdr); | |
370 | } | |
252b5132 | 371 | |
ee42cf8c | 372 | #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */ |
252b5132 | 373 | |
84714f86 AM |
374 | static inline bool |
375 | valid_symbol_name (const char *strtab, size_t strtab_size, uint64_t offset) | |
376 | { | |
377 | return strtab != NULL && offset < strtab_size; | |
378 | } | |
379 | ||
380 | static inline bool | |
381 | valid_dynamic_name (const Filedata *filedata, uint64_t offset) | |
382 | { | |
383 | return valid_symbol_name (filedata->dynamic_strings, | |
384 | filedata->dynamic_strings_length, offset); | |
385 | } | |
386 | ||
d79b3d50 NC |
387 | /* GET_DYNAMIC_NAME asssumes that VALID_DYNAMIC_NAME has |
388 | already been called and verified that the string exists. */ | |
84714f86 AM |
389 | static inline const char * |
390 | get_dynamic_name (const Filedata *filedata, size_t offset) | |
391 | { | |
392 | return filedata->dynamic_strings + offset; | |
393 | } | |
18bd398b | 394 | |
61865e30 NC |
395 | #define REMOVE_ARCH_BITS(ADDR) \ |
396 | do \ | |
397 | { \ | |
dda8d76d | 398 | if (filedata->file_header.e_machine == EM_ARM) \ |
61865e30 NC |
399 | (ADDR) &= ~1; \ |
400 | } \ | |
401 | while (0) | |
f16a9783 MS |
402 | |
403 | /* Get the correct GNU hash section name. */ | |
978c4450 AM |
404 | #define GNU_HASH_SECTION_NAME(filedata) \ |
405 | filedata->dynamic_info_DT_MIPS_XHASH ? ".MIPS.xhash" : ".gnu.hash" | |
d79b3d50 | 406 | \f |
66cfc0fd AM |
407 | /* Print a BFD_VMA to an internal buffer, for use in error messages. |
408 | BFD_FMA_FMT can't be used in translated strings. */ | |
409 | ||
410 | static const char * | |
411 | bfd_vmatoa (char *fmtch, bfd_vma value) | |
412 | { | |
413 | /* bfd_vmatoa is used more then once in a printf call for output. | |
414 | Cycle through an array of buffers. */ | |
415 | static int buf_pos = 0; | |
416 | static struct bfd_vmatoa_buf | |
417 | { | |
418 | char place[64]; | |
419 | } buf[4]; | |
420 | char *ret; | |
421 | char fmt[32]; | |
422 | ||
423 | ret = buf[buf_pos++].place; | |
424 | buf_pos %= ARRAY_SIZE (buf); | |
425 | ||
426 | sprintf (fmt, "%%%s%s", BFD_VMA_FMT, fmtch); | |
427 | snprintf (ret, sizeof (buf[0].place), fmt, value); | |
428 | return ret; | |
429 | } | |
430 | ||
dda8d76d NC |
431 | /* Retrieve NMEMB structures, each SIZE bytes long from FILEDATA starting at |
432 | OFFSET + the offset of the current archive member, if we are examining an | |
433 | archive. Put the retrieved data into VAR, if it is not NULL. Otherwise | |
434 | allocate a buffer using malloc and fill that. In either case return the | |
435 | pointer to the start of the retrieved data or NULL if something went wrong. | |
436 | If something does go wrong and REASON is not NULL then emit an error | |
437 | message using REASON as part of the context. */ | |
59245841 | 438 | |
c256ffe7 | 439 | static void * |
dda8d76d NC |
440 | get_data (void * var, |
441 | Filedata * filedata, | |
442 | unsigned long offset, | |
443 | bfd_size_type size, | |
444 | bfd_size_type nmemb, | |
445 | const char * reason) | |
a6e9f9df | 446 | { |
2cf0635d | 447 | void * mvar; |
57028622 | 448 | bfd_size_type amt = size * nmemb; |
a6e9f9df | 449 | |
c256ffe7 | 450 | if (size == 0 || nmemb == 0) |
a6e9f9df AM |
451 | return NULL; |
452 | ||
57028622 NC |
453 | /* If the size_t type is smaller than the bfd_size_type, eg because |
454 | you are building a 32-bit tool on a 64-bit host, then make sure | |
455 | that when the sizes are cast to (size_t) no information is lost. */ | |
7c1c1904 AM |
456 | if ((size_t) size != size |
457 | || (size_t) nmemb != nmemb | |
458 | || (size_t) amt != amt) | |
57028622 NC |
459 | { |
460 | if (reason) | |
66cfc0fd AM |
461 | error (_("Size truncation prevents reading %s" |
462 | " elements of size %s for %s\n"), | |
463 | bfd_vmatoa ("u", nmemb), bfd_vmatoa ("u", size), reason); | |
57028622 NC |
464 | return NULL; |
465 | } | |
466 | ||
467 | /* Check for size overflow. */ | |
7c1c1904 | 468 | if (amt / size != nmemb || (size_t) amt + 1 == 0) |
57028622 NC |
469 | { |
470 | if (reason) | |
66cfc0fd AM |
471 | error (_("Size overflow prevents reading %s" |
472 | " elements of size %s for %s\n"), | |
473 | bfd_vmatoa ("u", nmemb), bfd_vmatoa ("u", size), reason); | |
57028622 NC |
474 | return NULL; |
475 | } | |
476 | ||
c22b42ce | 477 | /* Be kind to memory checkers (eg valgrind, address sanitizer) by not |
c9c1d674 | 478 | attempting to allocate memory when the read is bound to fail. */ |
978c4450 AM |
479 | if (filedata->archive_file_offset > filedata->file_size |
480 | || offset > filedata->file_size - filedata->archive_file_offset | |
481 | || amt > filedata->file_size - filedata->archive_file_offset - offset) | |
a6e9f9df | 482 | { |
049b0c3a | 483 | if (reason) |
66cfc0fd AM |
484 | error (_("Reading %s bytes extends past end of file for %s\n"), |
485 | bfd_vmatoa ("u", amt), reason); | |
a6e9f9df AM |
486 | return NULL; |
487 | } | |
488 | ||
978c4450 AM |
489 | if (fseek (filedata->handle, filedata->archive_file_offset + offset, |
490 | SEEK_SET)) | |
071436c6 NC |
491 | { |
492 | if (reason) | |
c9c1d674 | 493 | error (_("Unable to seek to 0x%lx for %s\n"), |
978c4450 | 494 | filedata->archive_file_offset + offset, reason); |
071436c6 NC |
495 | return NULL; |
496 | } | |
497 | ||
a6e9f9df AM |
498 | mvar = var; |
499 | if (mvar == NULL) | |
500 | { | |
7c1c1904 AM |
501 | /* + 1 so that we can '\0' terminate invalid string table sections. */ |
502 | mvar = malloc ((size_t) amt + 1); | |
a6e9f9df AM |
503 | |
504 | if (mvar == NULL) | |
505 | { | |
049b0c3a | 506 | if (reason) |
66cfc0fd AM |
507 | error (_("Out of memory allocating %s bytes for %s\n"), |
508 | bfd_vmatoa ("u", amt), reason); | |
a6e9f9df AM |
509 | return NULL; |
510 | } | |
c256ffe7 | 511 | |
c9c1d674 | 512 | ((char *) mvar)[amt] = '\0'; |
a6e9f9df AM |
513 | } |
514 | ||
dda8d76d | 515 | if (fread (mvar, (size_t) size, (size_t) nmemb, filedata->handle) != nmemb) |
a6e9f9df | 516 | { |
049b0c3a | 517 | if (reason) |
66cfc0fd AM |
518 | error (_("Unable to read in %s bytes of %s\n"), |
519 | bfd_vmatoa ("u", amt), reason); | |
a6e9f9df AM |
520 | if (mvar != var) |
521 | free (mvar); | |
522 | return NULL; | |
523 | } | |
524 | ||
525 | return mvar; | |
526 | } | |
527 | ||
32ec8896 NC |
528 | /* Print a VMA value in the MODE specified. |
529 | Returns the number of characters displayed. */ | |
cb8f3167 | 530 | |
32ec8896 | 531 | static unsigned int |
14a91970 | 532 | print_vma (bfd_vma vma, print_mode mode) |
66543521 | 533 | { |
32ec8896 | 534 | unsigned int nc = 0; |
66543521 | 535 | |
14a91970 | 536 | switch (mode) |
66543521 | 537 | { |
14a91970 AM |
538 | case FULL_HEX: |
539 | nc = printf ("0x"); | |
1a0670f3 | 540 | /* Fall through. */ |
14a91970 | 541 | case LONG_HEX: |
f7a99963 | 542 | #ifdef BFD64 |
14a91970 | 543 | if (is_32bit_elf) |
437c2fb7 | 544 | return nc + printf ("%8.8" BFD_VMA_FMT "x", vma); |
f7a99963 | 545 | #endif |
14a91970 AM |
546 | printf_vma (vma); |
547 | return nc + 16; | |
b19aac67 | 548 | |
14a91970 AM |
549 | case DEC_5: |
550 | if (vma <= 99999) | |
551 | return printf ("%5" BFD_VMA_FMT "d", vma); | |
1a0670f3 | 552 | /* Fall through. */ |
14a91970 AM |
553 | case PREFIX_HEX: |
554 | nc = printf ("0x"); | |
1a0670f3 | 555 | /* Fall through. */ |
14a91970 AM |
556 | case HEX: |
557 | return nc + printf ("%" BFD_VMA_FMT "x", vma); | |
b19aac67 | 558 | |
047c3dbf NL |
559 | case PREFIX_HEX_5: |
560 | nc = printf ("0x"); | |
561 | /* Fall through. */ | |
562 | case HEX_5: | |
563 | return nc + printf ("%05" BFD_VMA_FMT "x", vma); | |
564 | ||
14a91970 AM |
565 | case DEC: |
566 | return printf ("%" BFD_VMA_FMT "d", vma); | |
b19aac67 | 567 | |
14a91970 AM |
568 | case UNSIGNED: |
569 | return printf ("%" BFD_VMA_FMT "u", vma); | |
32ec8896 | 570 | |
047c3dbf NL |
571 | case UNSIGNED_5: |
572 | return printf ("%5" BFD_VMA_FMT "u", vma); | |
573 | ||
574 | case OCTAL: | |
575 | return printf ("%" BFD_VMA_FMT "o", vma); | |
576 | ||
577 | case OCTAL_5: | |
578 | return printf ("%5" BFD_VMA_FMT "o", vma); | |
579 | ||
32ec8896 NC |
580 | default: |
581 | /* FIXME: Report unrecognised mode ? */ | |
582 | return 0; | |
f7a99963 | 583 | } |
f7a99963 NC |
584 | } |
585 | ||
047c3dbf | 586 | |
7bfd842d | 587 | /* Display a symbol on stdout. Handles the display of control characters and |
3bfcb652 | 588 | multibye characters (assuming the host environment supports them). |
31104126 | 589 | |
7bfd842d NC |
590 | Display at most abs(WIDTH) characters, truncating as necessary, unless do_wide is true. |
591 | ||
0942c7ab NC |
592 | If truncation will happen and do_not_show_symbol_truncation is FALSE then display |
593 | abs(WIDTH) - 5 characters followed by "[...]". | |
594 | ||
7bfd842d NC |
595 | If WIDTH is negative then ensure that the output is at least (- WIDTH) characters, |
596 | padding as necessary. | |
171191ba NC |
597 | |
598 | Returns the number of emitted characters. */ | |
599 | ||
600 | static unsigned int | |
0942c7ab | 601 | print_symbol (signed int width, const char * symbol) |
31104126 | 602 | { |
015dc7e1 AM |
603 | bool extra_padding = false; |
604 | bool do_dots = false; | |
32ec8896 | 605 | signed int num_printed = 0; |
3bfcb652 | 606 | #ifdef HAVE_MBSTATE_T |
7bfd842d | 607 | mbstate_t state; |
3bfcb652 | 608 | #endif |
32ec8896 | 609 | unsigned int width_remaining; |
79bc120c | 610 | const void * alloced_symbol = NULL; |
961c521f | 611 | |
7bfd842d | 612 | if (width < 0) |
961c521f | 613 | { |
88305e1b | 614 | /* Keep the width positive. This helps the code below. */ |
961c521f | 615 | width = - width; |
015dc7e1 | 616 | extra_padding = true; |
0b4362b0 | 617 | } |
56d8f8a9 NC |
618 | else if (width == 0) |
619 | return 0; | |
961c521f | 620 | |
7bfd842d NC |
621 | if (do_wide) |
622 | /* Set the remaining width to a very large value. | |
623 | This simplifies the code below. */ | |
624 | width_remaining = INT_MAX; | |
625 | else | |
0942c7ab NC |
626 | { |
627 | width_remaining = width; | |
628 | if (! do_not_show_symbol_truncation | |
629 | && (int) strlen (symbol) > width) | |
630 | { | |
631 | width_remaining -= 5; | |
632 | if ((int) width_remaining < 0) | |
633 | width_remaining = 0; | |
015dc7e1 | 634 | do_dots = true; |
0942c7ab NC |
635 | } |
636 | } | |
cb8f3167 | 637 | |
3bfcb652 | 638 | #ifdef HAVE_MBSTATE_T |
7bfd842d NC |
639 | /* Initialise the multibyte conversion state. */ |
640 | memset (& state, 0, sizeof (state)); | |
3bfcb652 | 641 | #endif |
961c521f | 642 | |
79bc120c NC |
643 | if (do_demangle && *symbol) |
644 | { | |
645 | const char * res = cplus_demangle (symbol, demangle_flags); | |
646 | ||
647 | if (res != NULL) | |
648 | alloced_symbol = symbol = res; | |
649 | } | |
650 | ||
7bfd842d NC |
651 | while (width_remaining) |
652 | { | |
653 | size_t n; | |
7bfd842d | 654 | const char c = *symbol++; |
961c521f | 655 | |
7bfd842d | 656 | if (c == 0) |
961c521f NC |
657 | break; |
658 | ||
7bfd842d NC |
659 | /* Do not print control characters directly as they can affect terminal |
660 | settings. Such characters usually appear in the names generated | |
661 | by the assembler for local labels. */ | |
662 | if (ISCNTRL (c)) | |
961c521f | 663 | { |
7bfd842d | 664 | if (width_remaining < 2) |
961c521f NC |
665 | break; |
666 | ||
7bfd842d NC |
667 | printf ("^%c", c + 0x40); |
668 | width_remaining -= 2; | |
171191ba | 669 | num_printed += 2; |
961c521f | 670 | } |
7bfd842d NC |
671 | else if (ISPRINT (c)) |
672 | { | |
673 | putchar (c); | |
674 | width_remaining --; | |
675 | num_printed ++; | |
676 | } | |
961c521f NC |
677 | else |
678 | { | |
3bfcb652 NC |
679 | #ifdef HAVE_MBSTATE_T |
680 | wchar_t w; | |
681 | #endif | |
7bfd842d NC |
682 | /* Let printf do the hard work of displaying multibyte characters. */ |
683 | printf ("%.1s", symbol - 1); | |
684 | width_remaining --; | |
685 | num_printed ++; | |
686 | ||
3bfcb652 | 687 | #ifdef HAVE_MBSTATE_T |
7bfd842d NC |
688 | /* Try to find out how many bytes made up the character that was |
689 | just printed. Advance the symbol pointer past the bytes that | |
690 | were displayed. */ | |
691 | n = mbrtowc (& w, symbol - 1, MB_CUR_MAX, & state); | |
3bfcb652 NC |
692 | #else |
693 | n = 1; | |
694 | #endif | |
7bfd842d NC |
695 | if (n != (size_t) -1 && n != (size_t) -2 && n > 0) |
696 | symbol += (n - 1); | |
961c521f | 697 | } |
961c521f | 698 | } |
171191ba | 699 | |
0942c7ab NC |
700 | if (do_dots) |
701 | num_printed += printf ("[...]"); | |
702 | ||
7bfd842d | 703 | if (extra_padding && num_printed < width) |
171191ba NC |
704 | { |
705 | /* Fill in the remaining spaces. */ | |
7bfd842d NC |
706 | printf ("%-*s", width - num_printed, " "); |
707 | num_printed = width; | |
171191ba NC |
708 | } |
709 | ||
79bc120c | 710 | free ((void *) alloced_symbol); |
171191ba | 711 | return num_printed; |
31104126 NC |
712 | } |
713 | ||
1449284b | 714 | /* Returns a pointer to a static buffer containing a printable version of |
74e1a04b NC |
715 | the given section's name. Like print_symbol, except that it does not try |
716 | to print multibyte characters, it just interprets them as hex values. */ | |
717 | ||
718 | static const char * | |
dda8d76d | 719 | printable_section_name (Filedata * filedata, const Elf_Internal_Shdr * sec) |
74e1a04b | 720 | { |
ca0e11aa | 721 | #define MAX_PRINT_SEC_NAME_LEN 256 |
74e1a04b | 722 | static char sec_name_buf [MAX_PRINT_SEC_NAME_LEN + 1]; |
84714f86 | 723 | const char * name = section_name_print (filedata, sec); |
74e1a04b NC |
724 | char * buf = sec_name_buf; |
725 | char c; | |
726 | unsigned int remaining = MAX_PRINT_SEC_NAME_LEN; | |
727 | ||
728 | while ((c = * name ++) != 0) | |
729 | { | |
730 | if (ISCNTRL (c)) | |
731 | { | |
732 | if (remaining < 2) | |
733 | break; | |
948f632f | 734 | |
74e1a04b NC |
735 | * buf ++ = '^'; |
736 | * buf ++ = c + 0x40; | |
737 | remaining -= 2; | |
738 | } | |
739 | else if (ISPRINT (c)) | |
740 | { | |
741 | * buf ++ = c; | |
742 | remaining -= 1; | |
743 | } | |
744 | else | |
745 | { | |
746 | static char hex[17] = "0123456789ABCDEF"; | |
747 | ||
748 | if (remaining < 4) | |
749 | break; | |
750 | * buf ++ = '<'; | |
751 | * buf ++ = hex[(c & 0xf0) >> 4]; | |
752 | * buf ++ = hex[c & 0x0f]; | |
753 | * buf ++ = '>'; | |
754 | remaining -= 4; | |
755 | } | |
756 | ||
757 | if (remaining == 0) | |
758 | break; | |
759 | } | |
760 | ||
761 | * buf = 0; | |
762 | return sec_name_buf; | |
763 | } | |
764 | ||
765 | static const char * | |
dda8d76d | 766 | printable_section_name_from_index (Filedata * filedata, unsigned long ndx) |
74e1a04b | 767 | { |
dda8d76d | 768 | if (ndx >= filedata->file_header.e_shnum) |
74e1a04b NC |
769 | return _("<corrupt>"); |
770 | ||
dda8d76d | 771 | return printable_section_name (filedata, filedata->section_headers + ndx); |
74e1a04b NC |
772 | } |
773 | ||
89fac5e3 RS |
774 | /* Return a pointer to section NAME, or NULL if no such section exists. */ |
775 | ||
776 | static Elf_Internal_Shdr * | |
dda8d76d | 777 | find_section (Filedata * filedata, const char * name) |
89fac5e3 RS |
778 | { |
779 | unsigned int i; | |
780 | ||
68807c3c NC |
781 | if (filedata->section_headers == NULL) |
782 | return NULL; | |
dda8d76d NC |
783 | |
784 | for (i = 0; i < filedata->file_header.e_shnum; i++) | |
84714f86 AM |
785 | if (section_name_valid (filedata, filedata->section_headers + i) |
786 | && streq (section_name (filedata, filedata->section_headers + i), | |
787 | name)) | |
dda8d76d | 788 | return filedata->section_headers + i; |
89fac5e3 RS |
789 | |
790 | return NULL; | |
791 | } | |
792 | ||
0b6ae522 DJ |
793 | /* Return a pointer to a section containing ADDR, or NULL if no such |
794 | section exists. */ | |
795 | ||
796 | static Elf_Internal_Shdr * | |
dda8d76d | 797 | find_section_by_address (Filedata * filedata, bfd_vma addr) |
0b6ae522 DJ |
798 | { |
799 | unsigned int i; | |
800 | ||
68807c3c NC |
801 | if (filedata->section_headers == NULL) |
802 | return NULL; | |
803 | ||
dda8d76d | 804 | for (i = 0; i < filedata->file_header.e_shnum; i++) |
0b6ae522 | 805 | { |
dda8d76d NC |
806 | Elf_Internal_Shdr *sec = filedata->section_headers + i; |
807 | ||
0b6ae522 DJ |
808 | if (addr >= sec->sh_addr && addr < sec->sh_addr + sec->sh_size) |
809 | return sec; | |
810 | } | |
811 | ||
812 | return NULL; | |
813 | } | |
814 | ||
071436c6 | 815 | static Elf_Internal_Shdr * |
dda8d76d | 816 | find_section_by_type (Filedata * filedata, unsigned int type) |
071436c6 NC |
817 | { |
818 | unsigned int i; | |
819 | ||
68807c3c NC |
820 | if (filedata->section_headers == NULL) |
821 | return NULL; | |
822 | ||
dda8d76d | 823 | for (i = 0; i < filedata->file_header.e_shnum; i++) |
071436c6 | 824 | { |
dda8d76d NC |
825 | Elf_Internal_Shdr *sec = filedata->section_headers + i; |
826 | ||
071436c6 NC |
827 | if (sec->sh_type == type) |
828 | return sec; | |
829 | } | |
830 | ||
831 | return NULL; | |
832 | } | |
833 | ||
657d0d47 CC |
834 | /* Return a pointer to section NAME, or NULL if no such section exists, |
835 | restricted to the list of sections given in SET. */ | |
836 | ||
837 | static Elf_Internal_Shdr * | |
dda8d76d | 838 | find_section_in_set (Filedata * filedata, const char * name, unsigned int * set) |
657d0d47 CC |
839 | { |
840 | unsigned int i; | |
841 | ||
68807c3c NC |
842 | if (filedata->section_headers == NULL) |
843 | return NULL; | |
844 | ||
657d0d47 CC |
845 | if (set != NULL) |
846 | { | |
847 | while ((i = *set++) > 0) | |
b814a36d NC |
848 | { |
849 | /* See PR 21156 for a reproducer. */ | |
dda8d76d | 850 | if (i >= filedata->file_header.e_shnum) |
b814a36d NC |
851 | continue; /* FIXME: Should we issue an error message ? */ |
852 | ||
84714f86 AM |
853 | if (section_name_valid (filedata, filedata->section_headers + i) |
854 | && streq (section_name (filedata, filedata->section_headers + i), | |
855 | name)) | |
dda8d76d | 856 | return filedata->section_headers + i; |
b814a36d | 857 | } |
657d0d47 CC |
858 | } |
859 | ||
dda8d76d | 860 | return find_section (filedata, name); |
657d0d47 CC |
861 | } |
862 | ||
32ec8896 | 863 | /* Return TRUE if the current file is for IA-64 machine and OpenVMS ABI. |
28f997cf TG |
864 | This OS has so many departures from the ELF standard that we test it at |
865 | many places. */ | |
866 | ||
015dc7e1 | 867 | static inline bool |
dda8d76d | 868 | is_ia64_vms (Filedata * filedata) |
28f997cf | 869 | { |
dda8d76d NC |
870 | return filedata->file_header.e_machine == EM_IA_64 |
871 | && filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_OPENVMS; | |
28f997cf TG |
872 | } |
873 | ||
bcedfee6 | 874 | /* Guess the relocation size commonly used by the specific machines. */ |
252b5132 | 875 | |
015dc7e1 | 876 | static bool |
2dc4cec1 | 877 | guess_is_rela (unsigned int e_machine) |
252b5132 | 878 | { |
9c19a809 | 879 | switch (e_machine) |
252b5132 RH |
880 | { |
881 | /* Targets that use REL relocations. */ | |
252b5132 | 882 | case EM_386: |
22abe556 | 883 | case EM_IAMCU: |
f954747f | 884 | case EM_960: |
e9f53129 | 885 | case EM_ARM: |
2b0337b0 | 886 | case EM_D10V: |
252b5132 | 887 | case EM_CYGNUS_D10V: |
e9f53129 | 888 | case EM_DLX: |
252b5132 | 889 | case EM_MIPS: |
4fe85591 | 890 | case EM_MIPS_RS3_LE: |
e9f53129 | 891 | case EM_CYGNUS_M32R: |
1c0d3aa6 | 892 | case EM_SCORE: |
f6c1a2d5 | 893 | case EM_XGATE: |
fe944acf | 894 | case EM_NFP: |
aca4efc7 | 895 | case EM_BPF: |
015dc7e1 | 896 | return false; |
103f02d3 | 897 | |
252b5132 RH |
898 | /* Targets that use RELA relocations. */ |
899 | case EM_68K: | |
f954747f | 900 | case EM_860: |
a06ea964 | 901 | case EM_AARCH64: |
cfb8c092 | 902 | case EM_ADAPTEVA_EPIPHANY: |
e9f53129 AM |
903 | case EM_ALPHA: |
904 | case EM_ALTERA_NIOS2: | |
886a2506 NC |
905 | case EM_ARC: |
906 | case EM_ARC_COMPACT: | |
907 | case EM_ARC_COMPACT2: | |
e9f53129 AM |
908 | case EM_AVR: |
909 | case EM_AVR_OLD: | |
910 | case EM_BLACKFIN: | |
60bca95a | 911 | case EM_CR16: |
e9f53129 AM |
912 | case EM_CRIS: |
913 | case EM_CRX: | |
b8891f8d | 914 | case EM_CSKY: |
2b0337b0 | 915 | case EM_D30V: |
252b5132 | 916 | case EM_CYGNUS_D30V: |
2b0337b0 | 917 | case EM_FR30: |
3f8107ab | 918 | case EM_FT32: |
252b5132 | 919 | case EM_CYGNUS_FR30: |
5c70f934 | 920 | case EM_CYGNUS_FRV: |
e9f53129 AM |
921 | case EM_H8S: |
922 | case EM_H8_300: | |
923 | case EM_H8_300H: | |
800eeca4 | 924 | case EM_IA_64: |
1e4cf259 NC |
925 | case EM_IP2K: |
926 | case EM_IP2K_OLD: | |
3b36097d | 927 | case EM_IQ2000: |
84e94c90 | 928 | case EM_LATTICEMICO32: |
ff7eeb89 | 929 | case EM_M32C_OLD: |
49f58d10 | 930 | case EM_M32C: |
e9f53129 AM |
931 | case EM_M32R: |
932 | case EM_MCORE: | |
15ab5209 | 933 | case EM_CYGNUS_MEP: |
a3c62988 | 934 | case EM_METAG: |
e9f53129 AM |
935 | case EM_MMIX: |
936 | case EM_MN10200: | |
937 | case EM_CYGNUS_MN10200: | |
938 | case EM_MN10300: | |
939 | case EM_CYGNUS_MN10300: | |
5506d11a | 940 | case EM_MOXIE: |
e9f53129 AM |
941 | case EM_MSP430: |
942 | case EM_MSP430_OLD: | |
d031aafb | 943 | case EM_MT: |
35c08157 | 944 | case EM_NDS32: |
64fd6348 | 945 | case EM_NIOS32: |
73589c9d | 946 | case EM_OR1K: |
e9f53129 AM |
947 | case EM_PPC64: |
948 | case EM_PPC: | |
2b100bb5 | 949 | case EM_TI_PRU: |
e23eba97 | 950 | case EM_RISCV: |
99c513f6 | 951 | case EM_RL78: |
c7927a3c | 952 | case EM_RX: |
e9f53129 AM |
953 | case EM_S390: |
954 | case EM_S390_OLD: | |
955 | case EM_SH: | |
956 | case EM_SPARC: | |
957 | case EM_SPARC32PLUS: | |
958 | case EM_SPARCV9: | |
959 | case EM_SPU: | |
40b36596 | 960 | case EM_TI_C6000: |
aa137e4d NC |
961 | case EM_TILEGX: |
962 | case EM_TILEPRO: | |
708e2187 | 963 | case EM_V800: |
e9f53129 AM |
964 | case EM_V850: |
965 | case EM_CYGNUS_V850: | |
966 | case EM_VAX: | |
619ed720 | 967 | case EM_VISIUM: |
e9f53129 | 968 | case EM_X86_64: |
8a9036a4 | 969 | case EM_L1OM: |
7a9068fe | 970 | case EM_K1OM: |
e9f53129 AM |
971 | case EM_XSTORMY16: |
972 | case EM_XTENSA: | |
973 | case EM_XTENSA_OLD: | |
7ba29e2a NC |
974 | case EM_MICROBLAZE: |
975 | case EM_MICROBLAZE_OLD: | |
f96bd6c2 | 976 | case EM_WEBASSEMBLY: |
015dc7e1 | 977 | return true; |
103f02d3 | 978 | |
e9f53129 AM |
979 | case EM_68HC05: |
980 | case EM_68HC08: | |
981 | case EM_68HC11: | |
982 | case EM_68HC16: | |
983 | case EM_FX66: | |
984 | case EM_ME16: | |
d1133906 | 985 | case EM_MMA: |
d1133906 NC |
986 | case EM_NCPU: |
987 | case EM_NDR1: | |
e9f53129 | 988 | case EM_PCP: |
d1133906 | 989 | case EM_ST100: |
e9f53129 | 990 | case EM_ST19: |
d1133906 | 991 | case EM_ST7: |
e9f53129 AM |
992 | case EM_ST9PLUS: |
993 | case EM_STARCORE: | |
d1133906 | 994 | case EM_SVX: |
e9f53129 | 995 | case EM_TINYJ: |
9c19a809 NC |
996 | default: |
997 | warn (_("Don't know about relocations on this machine architecture\n")); | |
015dc7e1 | 998 | return false; |
9c19a809 NC |
999 | } |
1000 | } | |
252b5132 | 1001 | |
dda8d76d | 1002 | /* Load RELA type relocations from FILEDATA at REL_OFFSET extending for REL_SIZE bytes. |
32ec8896 NC |
1003 | Returns TRUE upon success, FALSE otherwise. If successful then a |
1004 | pointer to a malloc'ed buffer containing the relocs is placed in *RELASP, | |
1005 | and the number of relocs loaded is placed in *NRELASP. It is the caller's | |
1006 | responsibility to free the allocated buffer. */ | |
1007 | ||
015dc7e1 | 1008 | static bool |
dda8d76d NC |
1009 | slurp_rela_relocs (Filedata * filedata, |
1010 | unsigned long rel_offset, | |
1011 | unsigned long rel_size, | |
1012 | Elf_Internal_Rela ** relasp, | |
1013 | unsigned long * nrelasp) | |
9c19a809 | 1014 | { |
2cf0635d | 1015 | Elf_Internal_Rela * relas; |
8b73c356 | 1016 | size_t nrelas; |
4d6ed7c8 | 1017 | unsigned int i; |
252b5132 | 1018 | |
4d6ed7c8 NC |
1019 | if (is_32bit_elf) |
1020 | { | |
2cf0635d | 1021 | Elf32_External_Rela * erelas; |
103f02d3 | 1022 | |
dda8d76d | 1023 | erelas = (Elf32_External_Rela *) get_data (NULL, filedata, rel_offset, 1, |
9cf03b7e | 1024 | rel_size, _("32-bit relocation data")); |
a6e9f9df | 1025 | if (!erelas) |
015dc7e1 | 1026 | return false; |
252b5132 | 1027 | |
4d6ed7c8 | 1028 | nrelas = rel_size / sizeof (Elf32_External_Rela); |
103f02d3 | 1029 | |
3f5e193b NC |
1030 | relas = (Elf_Internal_Rela *) cmalloc (nrelas, |
1031 | sizeof (Elf_Internal_Rela)); | |
103f02d3 | 1032 | |
4d6ed7c8 NC |
1033 | if (relas == NULL) |
1034 | { | |
c256ffe7 | 1035 | free (erelas); |
591a748a | 1036 | error (_("out of memory parsing relocs\n")); |
015dc7e1 | 1037 | return false; |
4d6ed7c8 | 1038 | } |
103f02d3 | 1039 | |
4d6ed7c8 NC |
1040 | for (i = 0; i < nrelas; i++) |
1041 | { | |
1042 | relas[i].r_offset = BYTE_GET (erelas[i].r_offset); | |
1043 | relas[i].r_info = BYTE_GET (erelas[i].r_info); | |
598aaa76 | 1044 | relas[i].r_addend = BYTE_GET_SIGNED (erelas[i].r_addend); |
4d6ed7c8 | 1045 | } |
103f02d3 | 1046 | |
4d6ed7c8 NC |
1047 | free (erelas); |
1048 | } | |
1049 | else | |
1050 | { | |
2cf0635d | 1051 | Elf64_External_Rela * erelas; |
103f02d3 | 1052 | |
dda8d76d | 1053 | erelas = (Elf64_External_Rela *) get_data (NULL, filedata, rel_offset, 1, |
9cf03b7e | 1054 | rel_size, _("64-bit relocation data")); |
a6e9f9df | 1055 | if (!erelas) |
015dc7e1 | 1056 | return false; |
4d6ed7c8 NC |
1057 | |
1058 | nrelas = rel_size / sizeof (Elf64_External_Rela); | |
103f02d3 | 1059 | |
3f5e193b NC |
1060 | relas = (Elf_Internal_Rela *) cmalloc (nrelas, |
1061 | sizeof (Elf_Internal_Rela)); | |
103f02d3 | 1062 | |
4d6ed7c8 NC |
1063 | if (relas == NULL) |
1064 | { | |
c256ffe7 | 1065 | free (erelas); |
591a748a | 1066 | error (_("out of memory parsing relocs\n")); |
015dc7e1 | 1067 | return false; |
9c19a809 | 1068 | } |
4d6ed7c8 NC |
1069 | |
1070 | for (i = 0; i < nrelas; i++) | |
9c19a809 | 1071 | { |
66543521 AM |
1072 | relas[i].r_offset = BYTE_GET (erelas[i].r_offset); |
1073 | relas[i].r_info = BYTE_GET (erelas[i].r_info); | |
598aaa76 | 1074 | relas[i].r_addend = BYTE_GET_SIGNED (erelas[i].r_addend); |
861fb55a DJ |
1075 | |
1076 | /* The #ifdef BFD64 below is to prevent a compile time | |
1077 | warning. We know that if we do not have a 64 bit data | |
1078 | type that we will never execute this code anyway. */ | |
1079 | #ifdef BFD64 | |
dda8d76d NC |
1080 | if (filedata->file_header.e_machine == EM_MIPS |
1081 | && filedata->file_header.e_ident[EI_DATA] != ELFDATA2MSB) | |
861fb55a DJ |
1082 | { |
1083 | /* In little-endian objects, r_info isn't really a | |
1084 | 64-bit little-endian value: it has a 32-bit | |
1085 | little-endian symbol index followed by four | |
1086 | individual byte fields. Reorder INFO | |
1087 | accordingly. */ | |
91d6fa6a NC |
1088 | bfd_vma inf = relas[i].r_info; |
1089 | inf = (((inf & 0xffffffff) << 32) | |
1090 | | ((inf >> 56) & 0xff) | |
1091 | | ((inf >> 40) & 0xff00) | |
1092 | | ((inf >> 24) & 0xff0000) | |
1093 | | ((inf >> 8) & 0xff000000)); | |
1094 | relas[i].r_info = inf; | |
861fb55a DJ |
1095 | } |
1096 | #endif /* BFD64 */ | |
4d6ed7c8 | 1097 | } |
103f02d3 | 1098 | |
4d6ed7c8 NC |
1099 | free (erelas); |
1100 | } | |
32ec8896 | 1101 | |
4d6ed7c8 NC |
1102 | *relasp = relas; |
1103 | *nrelasp = nrelas; | |
015dc7e1 | 1104 | return true; |
4d6ed7c8 | 1105 | } |
103f02d3 | 1106 | |
dda8d76d | 1107 | /* Load REL type relocations from FILEDATA at REL_OFFSET extending for REL_SIZE bytes. |
32ec8896 NC |
1108 | Returns TRUE upon success, FALSE otherwise. If successful then a |
1109 | pointer to a malloc'ed buffer containing the relocs is placed in *RELSP, | |
1110 | and the number of relocs loaded is placed in *NRELSP. It is the caller's | |
1111 | responsibility to free the allocated buffer. */ | |
1112 | ||
015dc7e1 | 1113 | static bool |
dda8d76d NC |
1114 | slurp_rel_relocs (Filedata * filedata, |
1115 | unsigned long rel_offset, | |
1116 | unsigned long rel_size, | |
1117 | Elf_Internal_Rela ** relsp, | |
1118 | unsigned long * nrelsp) | |
4d6ed7c8 | 1119 | { |
2cf0635d | 1120 | Elf_Internal_Rela * rels; |
8b73c356 | 1121 | size_t nrels; |
4d6ed7c8 | 1122 | unsigned int i; |
103f02d3 | 1123 | |
4d6ed7c8 NC |
1124 | if (is_32bit_elf) |
1125 | { | |
2cf0635d | 1126 | Elf32_External_Rel * erels; |
103f02d3 | 1127 | |
dda8d76d | 1128 | erels = (Elf32_External_Rel *) get_data (NULL, filedata, rel_offset, 1, |
9cf03b7e | 1129 | rel_size, _("32-bit relocation data")); |
a6e9f9df | 1130 | if (!erels) |
015dc7e1 | 1131 | return false; |
103f02d3 | 1132 | |
4d6ed7c8 | 1133 | nrels = rel_size / sizeof (Elf32_External_Rel); |
103f02d3 | 1134 | |
3f5e193b | 1135 | rels = (Elf_Internal_Rela *) cmalloc (nrels, sizeof (Elf_Internal_Rela)); |
103f02d3 | 1136 | |
4d6ed7c8 NC |
1137 | if (rels == NULL) |
1138 | { | |
c256ffe7 | 1139 | free (erels); |
591a748a | 1140 | error (_("out of memory parsing relocs\n")); |
015dc7e1 | 1141 | return false; |
4d6ed7c8 NC |
1142 | } |
1143 | ||
1144 | for (i = 0; i < nrels; i++) | |
1145 | { | |
1146 | rels[i].r_offset = BYTE_GET (erels[i].r_offset); | |
1147 | rels[i].r_info = BYTE_GET (erels[i].r_info); | |
c8286bd1 | 1148 | rels[i].r_addend = 0; |
9ea033b2 | 1149 | } |
4d6ed7c8 NC |
1150 | |
1151 | free (erels); | |
9c19a809 NC |
1152 | } |
1153 | else | |
1154 | { | |
2cf0635d | 1155 | Elf64_External_Rel * erels; |
9ea033b2 | 1156 | |
dda8d76d | 1157 | erels = (Elf64_External_Rel *) get_data (NULL, filedata, rel_offset, 1, |
9cf03b7e | 1158 | rel_size, _("64-bit relocation data")); |
a6e9f9df | 1159 | if (!erels) |
015dc7e1 | 1160 | return false; |
103f02d3 | 1161 | |
4d6ed7c8 | 1162 | nrels = rel_size / sizeof (Elf64_External_Rel); |
103f02d3 | 1163 | |
3f5e193b | 1164 | rels = (Elf_Internal_Rela *) cmalloc (nrels, sizeof (Elf_Internal_Rela)); |
103f02d3 | 1165 | |
4d6ed7c8 | 1166 | if (rels == NULL) |
9c19a809 | 1167 | { |
c256ffe7 | 1168 | free (erels); |
591a748a | 1169 | error (_("out of memory parsing relocs\n")); |
015dc7e1 | 1170 | return false; |
4d6ed7c8 | 1171 | } |
103f02d3 | 1172 | |
4d6ed7c8 NC |
1173 | for (i = 0; i < nrels; i++) |
1174 | { | |
66543521 AM |
1175 | rels[i].r_offset = BYTE_GET (erels[i].r_offset); |
1176 | rels[i].r_info = BYTE_GET (erels[i].r_info); | |
c8286bd1 | 1177 | rels[i].r_addend = 0; |
861fb55a DJ |
1178 | |
1179 | /* The #ifdef BFD64 below is to prevent a compile time | |
1180 | warning. We know that if we do not have a 64 bit data | |
1181 | type that we will never execute this code anyway. */ | |
1182 | #ifdef BFD64 | |
dda8d76d NC |
1183 | if (filedata->file_header.e_machine == EM_MIPS |
1184 | && filedata->file_header.e_ident[EI_DATA] != ELFDATA2MSB) | |
861fb55a DJ |
1185 | { |
1186 | /* In little-endian objects, r_info isn't really a | |
1187 | 64-bit little-endian value: it has a 32-bit | |
1188 | little-endian symbol index followed by four | |
1189 | individual byte fields. Reorder INFO | |
1190 | accordingly. */ | |
91d6fa6a NC |
1191 | bfd_vma inf = rels[i].r_info; |
1192 | inf = (((inf & 0xffffffff) << 32) | |
1193 | | ((inf >> 56) & 0xff) | |
1194 | | ((inf >> 40) & 0xff00) | |
1195 | | ((inf >> 24) & 0xff0000) | |
1196 | | ((inf >> 8) & 0xff000000)); | |
1197 | rels[i].r_info = inf; | |
861fb55a DJ |
1198 | } |
1199 | #endif /* BFD64 */ | |
4d6ed7c8 | 1200 | } |
103f02d3 | 1201 | |
4d6ed7c8 NC |
1202 | free (erels); |
1203 | } | |
32ec8896 | 1204 | |
4d6ed7c8 NC |
1205 | *relsp = rels; |
1206 | *nrelsp = nrels; | |
015dc7e1 | 1207 | return true; |
4d6ed7c8 | 1208 | } |
103f02d3 | 1209 | |
aca88567 NC |
1210 | /* Returns the reloc type extracted from the reloc info field. */ |
1211 | ||
1212 | static unsigned int | |
dda8d76d | 1213 | get_reloc_type (Filedata * filedata, bfd_vma reloc_info) |
aca88567 NC |
1214 | { |
1215 | if (is_32bit_elf) | |
1216 | return ELF32_R_TYPE (reloc_info); | |
1217 | ||
dda8d76d | 1218 | switch (filedata->file_header.e_machine) |
aca88567 NC |
1219 | { |
1220 | case EM_MIPS: | |
1221 | /* Note: We assume that reloc_info has already been adjusted for us. */ | |
1222 | return ELF64_MIPS_R_TYPE (reloc_info); | |
1223 | ||
1224 | case EM_SPARCV9: | |
1225 | return ELF64_R_TYPE_ID (reloc_info); | |
1226 | ||
1227 | default: | |
1228 | return ELF64_R_TYPE (reloc_info); | |
1229 | } | |
1230 | } | |
1231 | ||
1232 | /* Return the symbol index extracted from the reloc info field. */ | |
1233 | ||
1234 | static bfd_vma | |
1235 | get_reloc_symindex (bfd_vma reloc_info) | |
1236 | { | |
1237 | return is_32bit_elf ? ELF32_R_SYM (reloc_info) : ELF64_R_SYM (reloc_info); | |
1238 | } | |
1239 | ||
015dc7e1 | 1240 | static inline bool |
dda8d76d | 1241 | uses_msp430x_relocs (Filedata * filedata) |
13761a11 NC |
1242 | { |
1243 | return | |
dda8d76d | 1244 | filedata->file_header.e_machine == EM_MSP430 /* Paranoia. */ |
13761a11 | 1245 | /* GCC uses osabi == ELFOSBI_STANDALONE. */ |
dda8d76d | 1246 | && (((filedata->file_header.e_flags & EF_MSP430_MACH) == E_MSP430_MACH_MSP430X) |
13761a11 | 1247 | /* TI compiler uses ELFOSABI_NONE. */ |
dda8d76d | 1248 | || (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_NONE)); |
13761a11 NC |
1249 | } |
1250 | ||
d3ba0551 AM |
1251 | /* Display the contents of the relocation data found at the specified |
1252 | offset. */ | |
ee42cf8c | 1253 | |
015dc7e1 | 1254 | static bool |
dda8d76d NC |
1255 | dump_relocations (Filedata * filedata, |
1256 | unsigned long rel_offset, | |
1257 | unsigned long rel_size, | |
1258 | Elf_Internal_Sym * symtab, | |
1259 | unsigned long nsyms, | |
1260 | char * strtab, | |
1261 | unsigned long strtablen, | |
1262 | int is_rela, | |
015dc7e1 | 1263 | bool is_dynsym) |
4d6ed7c8 | 1264 | { |
32ec8896 | 1265 | unsigned long i; |
2cf0635d | 1266 | Elf_Internal_Rela * rels; |
015dc7e1 | 1267 | bool res = true; |
103f02d3 | 1268 | |
4d6ed7c8 | 1269 | if (is_rela == UNKNOWN) |
dda8d76d | 1270 | is_rela = guess_is_rela (filedata->file_header.e_machine); |
103f02d3 | 1271 | |
4d6ed7c8 NC |
1272 | if (is_rela) |
1273 | { | |
dda8d76d | 1274 | if (!slurp_rela_relocs (filedata, rel_offset, rel_size, &rels, &rel_size)) |
015dc7e1 | 1275 | return false; |
4d6ed7c8 NC |
1276 | } |
1277 | else | |
1278 | { | |
dda8d76d | 1279 | if (!slurp_rel_relocs (filedata, rel_offset, rel_size, &rels, &rel_size)) |
015dc7e1 | 1280 | return false; |
252b5132 RH |
1281 | } |
1282 | ||
410f7a12 L |
1283 | if (is_32bit_elf) |
1284 | { | |
1285 | if (is_rela) | |
2c71103e NC |
1286 | { |
1287 | if (do_wide) | |
1288 | printf (_(" Offset Info Type Sym. Value Symbol's Name + Addend\n")); | |
1289 | else | |
1290 | printf (_(" Offset Info Type Sym.Value Sym. Name + Addend\n")); | |
1291 | } | |
410f7a12 | 1292 | else |
2c71103e NC |
1293 | { |
1294 | if (do_wide) | |
1295 | printf (_(" Offset Info Type Sym. Value Symbol's Name\n")); | |
1296 | else | |
1297 | printf (_(" Offset Info Type Sym.Value Sym. Name\n")); | |
1298 | } | |
410f7a12 | 1299 | } |
252b5132 | 1300 | else |
410f7a12 L |
1301 | { |
1302 | if (is_rela) | |
2c71103e NC |
1303 | { |
1304 | if (do_wide) | |
8beeaeb7 | 1305 | printf (_(" Offset Info Type Symbol's Value Symbol's Name + Addend\n")); |
2c71103e NC |
1306 | else |
1307 | printf (_(" Offset Info Type Sym. Value Sym. Name + Addend\n")); | |
1308 | } | |
410f7a12 | 1309 | else |
2c71103e NC |
1310 | { |
1311 | if (do_wide) | |
8beeaeb7 | 1312 | printf (_(" Offset Info Type Symbol's Value Symbol's Name\n")); |
2c71103e NC |
1313 | else |
1314 | printf (_(" Offset Info Type Sym. Value Sym. Name\n")); | |
1315 | } | |
410f7a12 | 1316 | } |
252b5132 RH |
1317 | |
1318 | for (i = 0; i < rel_size; i++) | |
1319 | { | |
2cf0635d | 1320 | const char * rtype; |
b34976b6 | 1321 | bfd_vma offset; |
91d6fa6a | 1322 | bfd_vma inf; |
b34976b6 AM |
1323 | bfd_vma symtab_index; |
1324 | bfd_vma type; | |
103f02d3 | 1325 | |
b34976b6 | 1326 | offset = rels[i].r_offset; |
91d6fa6a | 1327 | inf = rels[i].r_info; |
103f02d3 | 1328 | |
dda8d76d | 1329 | type = get_reloc_type (filedata, inf); |
91d6fa6a | 1330 | symtab_index = get_reloc_symindex (inf); |
252b5132 | 1331 | |
410f7a12 L |
1332 | if (is_32bit_elf) |
1333 | { | |
39dbeff8 AM |
1334 | printf ("%8.8lx %8.8lx ", |
1335 | (unsigned long) offset & 0xffffffff, | |
91d6fa6a | 1336 | (unsigned long) inf & 0xffffffff); |
410f7a12 L |
1337 | } |
1338 | else | |
1339 | { | |
39dbeff8 | 1340 | printf (do_wide |
d1ce973e AM |
1341 | ? "%16.16" BFD_VMA_FMT "x %16.16" BFD_VMA_FMT "x " |
1342 | : "%12.12" BFD_VMA_FMT "x %12.12" BFD_VMA_FMT "x ", | |
91d6fa6a | 1343 | offset, inf); |
410f7a12 | 1344 | } |
103f02d3 | 1345 | |
dda8d76d | 1346 | switch (filedata->file_header.e_machine) |
252b5132 RH |
1347 | { |
1348 | default: | |
1349 | rtype = NULL; | |
1350 | break; | |
1351 | ||
a06ea964 NC |
1352 | case EM_AARCH64: |
1353 | rtype = elf_aarch64_reloc_type (type); | |
1354 | break; | |
1355 | ||
2b0337b0 | 1356 | case EM_M32R: |
252b5132 | 1357 | case EM_CYGNUS_M32R: |
9ea033b2 | 1358 | rtype = elf_m32r_reloc_type (type); |
252b5132 RH |
1359 | break; |
1360 | ||
1361 | case EM_386: | |
22abe556 | 1362 | case EM_IAMCU: |
9ea033b2 | 1363 | rtype = elf_i386_reloc_type (type); |
252b5132 RH |
1364 | break; |
1365 | ||
ba2685cc AM |
1366 | case EM_68HC11: |
1367 | case EM_68HC12: | |
1368 | rtype = elf_m68hc11_reloc_type (type); | |
1369 | break; | |
75751cd9 | 1370 | |
7b4ae824 JD |
1371 | case EM_S12Z: |
1372 | rtype = elf_s12z_reloc_type (type); | |
1373 | break; | |
1374 | ||
252b5132 | 1375 | case EM_68K: |
9ea033b2 | 1376 | rtype = elf_m68k_reloc_type (type); |
252b5132 RH |
1377 | break; |
1378 | ||
f954747f AM |
1379 | case EM_960: |
1380 | rtype = elf_i960_reloc_type (type); | |
1381 | break; | |
1382 | ||
adde6300 | 1383 | case EM_AVR: |
2b0337b0 | 1384 | case EM_AVR_OLD: |
adde6300 AM |
1385 | rtype = elf_avr_reloc_type (type); |
1386 | break; | |
1387 | ||
9ea033b2 NC |
1388 | case EM_OLD_SPARCV9: |
1389 | case EM_SPARC32PLUS: | |
1390 | case EM_SPARCV9: | |
252b5132 | 1391 | case EM_SPARC: |
9ea033b2 | 1392 | rtype = elf_sparc_reloc_type (type); |
252b5132 RH |
1393 | break; |
1394 | ||
e9f53129 AM |
1395 | case EM_SPU: |
1396 | rtype = elf_spu_reloc_type (type); | |
1397 | break; | |
1398 | ||
708e2187 NC |
1399 | case EM_V800: |
1400 | rtype = v800_reloc_type (type); | |
1401 | break; | |
2b0337b0 | 1402 | case EM_V850: |
252b5132 | 1403 | case EM_CYGNUS_V850: |
9ea033b2 | 1404 | rtype = v850_reloc_type (type); |
252b5132 RH |
1405 | break; |
1406 | ||
2b0337b0 | 1407 | case EM_D10V: |
252b5132 | 1408 | case EM_CYGNUS_D10V: |
9ea033b2 | 1409 | rtype = elf_d10v_reloc_type (type); |
252b5132 RH |
1410 | break; |
1411 | ||
2b0337b0 | 1412 | case EM_D30V: |
252b5132 | 1413 | case EM_CYGNUS_D30V: |
9ea033b2 | 1414 | rtype = elf_d30v_reloc_type (type); |
252b5132 RH |
1415 | break; |
1416 | ||
d172d4ba NC |
1417 | case EM_DLX: |
1418 | rtype = elf_dlx_reloc_type (type); | |
1419 | break; | |
1420 | ||
252b5132 | 1421 | case EM_SH: |
9ea033b2 | 1422 | rtype = elf_sh_reloc_type (type); |
252b5132 RH |
1423 | break; |
1424 | ||
2b0337b0 | 1425 | case EM_MN10300: |
252b5132 | 1426 | case EM_CYGNUS_MN10300: |
9ea033b2 | 1427 | rtype = elf_mn10300_reloc_type (type); |
252b5132 RH |
1428 | break; |
1429 | ||
2b0337b0 | 1430 | case EM_MN10200: |
252b5132 | 1431 | case EM_CYGNUS_MN10200: |
9ea033b2 | 1432 | rtype = elf_mn10200_reloc_type (type); |
252b5132 RH |
1433 | break; |
1434 | ||
2b0337b0 | 1435 | case EM_FR30: |
252b5132 | 1436 | case EM_CYGNUS_FR30: |
9ea033b2 | 1437 | rtype = elf_fr30_reloc_type (type); |
252b5132 RH |
1438 | break; |
1439 | ||
ba2685cc AM |
1440 | case EM_CYGNUS_FRV: |
1441 | rtype = elf_frv_reloc_type (type); | |
1442 | break; | |
5c70f934 | 1443 | |
b8891f8d AJ |
1444 | case EM_CSKY: |
1445 | rtype = elf_csky_reloc_type (type); | |
1446 | break; | |
1447 | ||
3f8107ab AM |
1448 | case EM_FT32: |
1449 | rtype = elf_ft32_reloc_type (type); | |
1450 | break; | |
1451 | ||
252b5132 | 1452 | case EM_MCORE: |
9ea033b2 | 1453 | rtype = elf_mcore_reloc_type (type); |
252b5132 RH |
1454 | break; |
1455 | ||
3c3bdf30 NC |
1456 | case EM_MMIX: |
1457 | rtype = elf_mmix_reloc_type (type); | |
1458 | break; | |
1459 | ||
5506d11a AM |
1460 | case EM_MOXIE: |
1461 | rtype = elf_moxie_reloc_type (type); | |
1462 | break; | |
1463 | ||
2469cfa2 | 1464 | case EM_MSP430: |
dda8d76d | 1465 | if (uses_msp430x_relocs (filedata)) |
13761a11 NC |
1466 | { |
1467 | rtype = elf_msp430x_reloc_type (type); | |
1468 | break; | |
1469 | } | |
1a0670f3 | 1470 | /* Fall through. */ |
2469cfa2 NC |
1471 | case EM_MSP430_OLD: |
1472 | rtype = elf_msp430_reloc_type (type); | |
1473 | break; | |
1474 | ||
35c08157 KLC |
1475 | case EM_NDS32: |
1476 | rtype = elf_nds32_reloc_type (type); | |
1477 | break; | |
1478 | ||
252b5132 | 1479 | case EM_PPC: |
9ea033b2 | 1480 | rtype = elf_ppc_reloc_type (type); |
252b5132 RH |
1481 | break; |
1482 | ||
c833c019 AM |
1483 | case EM_PPC64: |
1484 | rtype = elf_ppc64_reloc_type (type); | |
1485 | break; | |
1486 | ||
252b5132 | 1487 | case EM_MIPS: |
4fe85591 | 1488 | case EM_MIPS_RS3_LE: |
9ea033b2 | 1489 | rtype = elf_mips_reloc_type (type); |
252b5132 RH |
1490 | break; |
1491 | ||
e23eba97 NC |
1492 | case EM_RISCV: |
1493 | rtype = elf_riscv_reloc_type (type); | |
1494 | break; | |
1495 | ||
252b5132 | 1496 | case EM_ALPHA: |
9ea033b2 | 1497 | rtype = elf_alpha_reloc_type (type); |
252b5132 RH |
1498 | break; |
1499 | ||
1500 | case EM_ARM: | |
9ea033b2 | 1501 | rtype = elf_arm_reloc_type (type); |
252b5132 RH |
1502 | break; |
1503 | ||
584da044 | 1504 | case EM_ARC: |
886a2506 NC |
1505 | case EM_ARC_COMPACT: |
1506 | case EM_ARC_COMPACT2: | |
9ea033b2 | 1507 | rtype = elf_arc_reloc_type (type); |
252b5132 RH |
1508 | break; |
1509 | ||
1510 | case EM_PARISC: | |
69e617ca | 1511 | rtype = elf_hppa_reloc_type (type); |
252b5132 | 1512 | break; |
7d466069 | 1513 | |
b8720f9d JL |
1514 | case EM_H8_300: |
1515 | case EM_H8_300H: | |
1516 | case EM_H8S: | |
1517 | rtype = elf_h8_reloc_type (type); | |
1518 | break; | |
1519 | ||
73589c9d CS |
1520 | case EM_OR1K: |
1521 | rtype = elf_or1k_reloc_type (type); | |
3b16e843 NC |
1522 | break; |
1523 | ||
7d466069 | 1524 | case EM_PJ: |
2b0337b0 | 1525 | case EM_PJ_OLD: |
7d466069 ILT |
1526 | rtype = elf_pj_reloc_type (type); |
1527 | break; | |
800eeca4 JW |
1528 | case EM_IA_64: |
1529 | rtype = elf_ia64_reloc_type (type); | |
1530 | break; | |
1b61cf92 HPN |
1531 | |
1532 | case EM_CRIS: | |
1533 | rtype = elf_cris_reloc_type (type); | |
1534 | break; | |
535c37ff | 1535 | |
f954747f AM |
1536 | case EM_860: |
1537 | rtype = elf_i860_reloc_type (type); | |
1538 | break; | |
1539 | ||
bcedfee6 | 1540 | case EM_X86_64: |
8a9036a4 | 1541 | case EM_L1OM: |
7a9068fe | 1542 | case EM_K1OM: |
bcedfee6 NC |
1543 | rtype = elf_x86_64_reloc_type (type); |
1544 | break; | |
a85d7ed0 | 1545 | |
f954747f AM |
1546 | case EM_S370: |
1547 | rtype = i370_reloc_type (type); | |
1548 | break; | |
1549 | ||
53c7db4b KH |
1550 | case EM_S390_OLD: |
1551 | case EM_S390: | |
1552 | rtype = elf_s390_reloc_type (type); | |
1553 | break; | |
93fbbb04 | 1554 | |
1c0d3aa6 NC |
1555 | case EM_SCORE: |
1556 | rtype = elf_score_reloc_type (type); | |
1557 | break; | |
1558 | ||
93fbbb04 GK |
1559 | case EM_XSTORMY16: |
1560 | rtype = elf_xstormy16_reloc_type (type); | |
1561 | break; | |
179d3252 | 1562 | |
1fe1f39c NC |
1563 | case EM_CRX: |
1564 | rtype = elf_crx_reloc_type (type); | |
1565 | break; | |
1566 | ||
179d3252 JT |
1567 | case EM_VAX: |
1568 | rtype = elf_vax_reloc_type (type); | |
1569 | break; | |
1e4cf259 | 1570 | |
619ed720 EB |
1571 | case EM_VISIUM: |
1572 | rtype = elf_visium_reloc_type (type); | |
1573 | break; | |
1574 | ||
aca4efc7 JM |
1575 | case EM_BPF: |
1576 | rtype = elf_bpf_reloc_type (type); | |
1577 | break; | |
1578 | ||
cfb8c092 NC |
1579 | case EM_ADAPTEVA_EPIPHANY: |
1580 | rtype = elf_epiphany_reloc_type (type); | |
1581 | break; | |
1582 | ||
1e4cf259 NC |
1583 | case EM_IP2K: |
1584 | case EM_IP2K_OLD: | |
1585 | rtype = elf_ip2k_reloc_type (type); | |
1586 | break; | |
3b36097d SC |
1587 | |
1588 | case EM_IQ2000: | |
1589 | rtype = elf_iq2000_reloc_type (type); | |
1590 | break; | |
88da6820 NC |
1591 | |
1592 | case EM_XTENSA_OLD: | |
1593 | case EM_XTENSA: | |
1594 | rtype = elf_xtensa_reloc_type (type); | |
1595 | break; | |
a34e3ecb | 1596 | |
84e94c90 NC |
1597 | case EM_LATTICEMICO32: |
1598 | rtype = elf_lm32_reloc_type (type); | |
1599 | break; | |
1600 | ||
ff7eeb89 | 1601 | case EM_M32C_OLD: |
49f58d10 JB |
1602 | case EM_M32C: |
1603 | rtype = elf_m32c_reloc_type (type); | |
1604 | break; | |
1605 | ||
d031aafb NS |
1606 | case EM_MT: |
1607 | rtype = elf_mt_reloc_type (type); | |
a34e3ecb | 1608 | break; |
1d65ded4 CM |
1609 | |
1610 | case EM_BLACKFIN: | |
1611 | rtype = elf_bfin_reloc_type (type); | |
1612 | break; | |
15ab5209 DB |
1613 | |
1614 | case EM_CYGNUS_MEP: | |
1615 | rtype = elf_mep_reloc_type (type); | |
1616 | break; | |
60bca95a NC |
1617 | |
1618 | case EM_CR16: | |
1619 | rtype = elf_cr16_reloc_type (type); | |
1620 | break; | |
dd24e3da | 1621 | |
7ba29e2a NC |
1622 | case EM_MICROBLAZE: |
1623 | case EM_MICROBLAZE_OLD: | |
1624 | rtype = elf_microblaze_reloc_type (type); | |
1625 | break; | |
c7927a3c | 1626 | |
99c513f6 DD |
1627 | case EM_RL78: |
1628 | rtype = elf_rl78_reloc_type (type); | |
1629 | break; | |
1630 | ||
c7927a3c NC |
1631 | case EM_RX: |
1632 | rtype = elf_rx_reloc_type (type); | |
1633 | break; | |
c29aca4a | 1634 | |
a3c62988 NC |
1635 | case EM_METAG: |
1636 | rtype = elf_metag_reloc_type (type); | |
1637 | break; | |
1638 | ||
c29aca4a NC |
1639 | case EM_XC16X: |
1640 | case EM_C166: | |
1641 | rtype = elf_xc16x_reloc_type (type); | |
1642 | break; | |
40b36596 JM |
1643 | |
1644 | case EM_TI_C6000: | |
1645 | rtype = elf_tic6x_reloc_type (type); | |
1646 | break; | |
aa137e4d NC |
1647 | |
1648 | case EM_TILEGX: | |
1649 | rtype = elf_tilegx_reloc_type (type); | |
1650 | break; | |
1651 | ||
1652 | case EM_TILEPRO: | |
1653 | rtype = elf_tilepro_reloc_type (type); | |
1654 | break; | |
f6c1a2d5 | 1655 | |
f96bd6c2 PC |
1656 | case EM_WEBASSEMBLY: |
1657 | rtype = elf_wasm32_reloc_type (type); | |
1658 | break; | |
1659 | ||
f6c1a2d5 NC |
1660 | case EM_XGATE: |
1661 | rtype = elf_xgate_reloc_type (type); | |
1662 | break; | |
36591ba1 SL |
1663 | |
1664 | case EM_ALTERA_NIOS2: | |
1665 | rtype = elf_nios2_reloc_type (type); | |
1666 | break; | |
2b100bb5 DD |
1667 | |
1668 | case EM_TI_PRU: | |
1669 | rtype = elf_pru_reloc_type (type); | |
1670 | break; | |
fe944acf FT |
1671 | |
1672 | case EM_NFP: | |
1673 | if (EF_NFP_MACH (filedata->file_header.e_flags) == E_NFP_MACH_3200) | |
1674 | rtype = elf_nfp3200_reloc_type (type); | |
1675 | else | |
1676 | rtype = elf_nfp_reloc_type (type); | |
1677 | break; | |
6655dba2 SB |
1678 | |
1679 | case EM_Z80: | |
1680 | rtype = elf_z80_reloc_type (type); | |
1681 | break; | |
e9a0721f | 1682 | |
1683 | case EM_LOONGARCH: | |
1684 | rtype = elf_loongarch_reloc_type (type); | |
1685 | break; | |
1686 | ||
252b5132 RH |
1687 | } |
1688 | ||
1689 | if (rtype == NULL) | |
39dbeff8 | 1690 | printf (_("unrecognized: %-7lx"), (unsigned long) type & 0xffffffff); |
252b5132 | 1691 | else |
5c144731 | 1692 | printf (do_wide ? "%-22s" : "%-17.17s", rtype); |
252b5132 | 1693 | |
dda8d76d | 1694 | if (filedata->file_header.e_machine == EM_ALPHA |
157c2599 | 1695 | && rtype != NULL |
7ace3541 RH |
1696 | && streq (rtype, "R_ALPHA_LITUSE") |
1697 | && is_rela) | |
1698 | { | |
1699 | switch (rels[i].r_addend) | |
1700 | { | |
1701 | case LITUSE_ALPHA_ADDR: rtype = "ADDR"; break; | |
1702 | case LITUSE_ALPHA_BASE: rtype = "BASE"; break; | |
1703 | case LITUSE_ALPHA_BYTOFF: rtype = "BYTOFF"; break; | |
1704 | case LITUSE_ALPHA_JSR: rtype = "JSR"; break; | |
1705 | case LITUSE_ALPHA_TLSGD: rtype = "TLSGD"; break; | |
1706 | case LITUSE_ALPHA_TLSLDM: rtype = "TLSLDM"; break; | |
1707 | case LITUSE_ALPHA_JSRDIRECT: rtype = "JSRDIRECT"; break; | |
1708 | default: rtype = NULL; | |
1709 | } | |
32ec8896 | 1710 | |
7ace3541 RH |
1711 | if (rtype) |
1712 | printf (" (%s)", rtype); | |
1713 | else | |
1714 | { | |
1715 | putchar (' '); | |
1716 | printf (_("<unknown addend: %lx>"), | |
1717 | (unsigned long) rels[i].r_addend); | |
015dc7e1 | 1718 | res = false; |
7ace3541 RH |
1719 | } |
1720 | } | |
1721 | else if (symtab_index) | |
252b5132 | 1722 | { |
af3fc3bc | 1723 | if (symtab == NULL || symtab_index >= nsyms) |
32ec8896 | 1724 | { |
27a45f42 AS |
1725 | error (_(" bad symbol index: %08lx in reloc\n"), |
1726 | (unsigned long) symtab_index); | |
015dc7e1 | 1727 | res = false; |
32ec8896 | 1728 | } |
af3fc3bc | 1729 | else |
19936277 | 1730 | { |
2cf0635d | 1731 | Elf_Internal_Sym * psym; |
bb4d2ac2 L |
1732 | const char * version_string; |
1733 | enum versioned_symbol_info sym_info; | |
1734 | unsigned short vna_other; | |
19936277 | 1735 | |
af3fc3bc | 1736 | psym = symtab + symtab_index; |
103f02d3 | 1737 | |
bb4d2ac2 | 1738 | version_string |
dda8d76d | 1739 | = get_symbol_version_string (filedata, is_dynsym, |
bb4d2ac2 L |
1740 | strtab, strtablen, |
1741 | symtab_index, | |
1742 | psym, | |
1743 | &sym_info, | |
1744 | &vna_other); | |
1745 | ||
af3fc3bc | 1746 | printf (" "); |
171191ba | 1747 | |
d8045f23 NC |
1748 | if (ELF_ST_TYPE (psym->st_info) == STT_GNU_IFUNC) |
1749 | { | |
1750 | const char * name; | |
1751 | unsigned int len; | |
1752 | unsigned int width = is_32bit_elf ? 8 : 14; | |
1753 | ||
1754 | /* Relocations against GNU_IFUNC symbols do not use the value | |
1755 | of the symbol as the address to relocate against. Instead | |
1756 | they invoke the function named by the symbol and use its | |
1757 | result as the address for relocation. | |
1758 | ||
1759 | To indicate this to the user, do not display the value of | |
1760 | the symbol in the "Symbols's Value" field. Instead show | |
1761 | its name followed by () as a hint that the symbol is | |
1762 | invoked. */ | |
1763 | ||
1764 | if (strtab == NULL | |
1765 | || psym->st_name == 0 | |
1766 | || psym->st_name >= strtablen) | |
1767 | name = "??"; | |
1768 | else | |
1769 | name = strtab + psym->st_name; | |
1770 | ||
1771 | len = print_symbol (width, name); | |
bb4d2ac2 L |
1772 | if (version_string) |
1773 | printf (sym_info == symbol_public ? "@@%s" : "@%s", | |
1774 | version_string); | |
d8045f23 NC |
1775 | printf ("()%-*s", len <= width ? (width + 1) - len : 1, " "); |
1776 | } | |
1777 | else | |
1778 | { | |
1779 | print_vma (psym->st_value, LONG_HEX); | |
171191ba | 1780 | |
d8045f23 NC |
1781 | printf (is_32bit_elf ? " " : " "); |
1782 | } | |
103f02d3 | 1783 | |
af3fc3bc | 1784 | if (psym->st_name == 0) |
f1ef08cb | 1785 | { |
2cf0635d | 1786 | const char * sec_name = "<null>"; |
f1ef08cb AM |
1787 | char name_buf[40]; |
1788 | ||
1789 | if (ELF_ST_TYPE (psym->st_info) == STT_SECTION) | |
1790 | { | |
dda8d76d | 1791 | if (psym->st_shndx < filedata->file_header.e_shnum) |
84714f86 AM |
1792 | sec_name = section_name_print (filedata, |
1793 | filedata->section_headers | |
b9e920ec | 1794 | + psym->st_shndx); |
f1ef08cb AM |
1795 | else if (psym->st_shndx == SHN_ABS) |
1796 | sec_name = "ABS"; | |
1797 | else if (psym->st_shndx == SHN_COMMON) | |
1798 | sec_name = "COMMON"; | |
dda8d76d | 1799 | else if ((filedata->file_header.e_machine == EM_MIPS |
ac145307 | 1800 | && psym->st_shndx == SHN_MIPS_SCOMMON) |
dda8d76d | 1801 | || (filedata->file_header.e_machine == EM_TI_C6000 |
ac145307 | 1802 | && psym->st_shndx == SHN_TIC6X_SCOMMON)) |
172553c7 | 1803 | sec_name = "SCOMMON"; |
dda8d76d | 1804 | else if (filedata->file_header.e_machine == EM_MIPS |
172553c7 TS |
1805 | && psym->st_shndx == SHN_MIPS_SUNDEFINED) |
1806 | sec_name = "SUNDEF"; | |
dda8d76d NC |
1807 | else if ((filedata->file_header.e_machine == EM_X86_64 |
1808 | || filedata->file_header.e_machine == EM_L1OM | |
1809 | || filedata->file_header.e_machine == EM_K1OM) | |
3b22753a L |
1810 | && psym->st_shndx == SHN_X86_64_LCOMMON) |
1811 | sec_name = "LARGE_COMMON"; | |
dda8d76d NC |
1812 | else if (filedata->file_header.e_machine == EM_IA_64 |
1813 | && filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_HPUX | |
9ce701e2 L |
1814 | && psym->st_shndx == SHN_IA_64_ANSI_COMMON) |
1815 | sec_name = "ANSI_COM"; | |
dda8d76d | 1816 | else if (is_ia64_vms (filedata) |
148b93f2 NC |
1817 | && psym->st_shndx == SHN_IA_64_VMS_SYMVEC) |
1818 | sec_name = "VMS_SYMVEC"; | |
f1ef08cb AM |
1819 | else |
1820 | { | |
1821 | sprintf (name_buf, "<section 0x%x>", | |
1822 | (unsigned int) psym->st_shndx); | |
1823 | sec_name = name_buf; | |
1824 | } | |
1825 | } | |
1826 | print_symbol (22, sec_name); | |
1827 | } | |
af3fc3bc | 1828 | else if (strtab == NULL) |
d79b3d50 | 1829 | printf (_("<string table index: %3ld>"), psym->st_name); |
c256ffe7 | 1830 | else if (psym->st_name >= strtablen) |
32ec8896 | 1831 | { |
27a45f42 AS |
1832 | error (_("<corrupt string table index: %3ld>\n"), |
1833 | psym->st_name); | |
015dc7e1 | 1834 | res = false; |
32ec8896 | 1835 | } |
af3fc3bc | 1836 | else |
bb4d2ac2 L |
1837 | { |
1838 | print_symbol (22, strtab + psym->st_name); | |
1839 | if (version_string) | |
1840 | printf (sym_info == symbol_public ? "@@%s" : "@%s", | |
1841 | version_string); | |
1842 | } | |
103f02d3 | 1843 | |
af3fc3bc | 1844 | if (is_rela) |
171191ba | 1845 | { |
7360e63f | 1846 | bfd_vma off = rels[i].r_addend; |
171191ba | 1847 | |
7360e63f | 1848 | if ((bfd_signed_vma) off < 0) |
598aaa76 | 1849 | printf (" - %" BFD_VMA_FMT "x", - off); |
171191ba | 1850 | else |
598aaa76 | 1851 | printf (" + %" BFD_VMA_FMT "x", off); |
171191ba | 1852 | } |
19936277 | 1853 | } |
252b5132 | 1854 | } |
1b228002 | 1855 | else if (is_rela) |
f7a99963 | 1856 | { |
7360e63f | 1857 | bfd_vma off = rels[i].r_addend; |
e04d7088 L |
1858 | |
1859 | printf ("%*c", is_32bit_elf ? 12 : 20, ' '); | |
7360e63f | 1860 | if ((bfd_signed_vma) off < 0) |
e04d7088 L |
1861 | printf ("-%" BFD_VMA_FMT "x", - off); |
1862 | else | |
1863 | printf ("%" BFD_VMA_FMT "x", off); | |
f7a99963 | 1864 | } |
252b5132 | 1865 | |
dda8d76d | 1866 | if (filedata->file_header.e_machine == EM_SPARCV9 |
157c2599 NC |
1867 | && rtype != NULL |
1868 | && streq (rtype, "R_SPARC_OLO10")) | |
91d6fa6a | 1869 | printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (inf)); |
351b4b40 | 1870 | |
252b5132 | 1871 | putchar ('\n'); |
2c71103e | 1872 | |
aca88567 | 1873 | #ifdef BFD64 |
dda8d76d | 1874 | if (! is_32bit_elf && filedata->file_header.e_machine == EM_MIPS) |
2c71103e | 1875 | { |
91d6fa6a NC |
1876 | bfd_vma type2 = ELF64_MIPS_R_TYPE2 (inf); |
1877 | bfd_vma type3 = ELF64_MIPS_R_TYPE3 (inf); | |
2cf0635d NC |
1878 | const char * rtype2 = elf_mips_reloc_type (type2); |
1879 | const char * rtype3 = elf_mips_reloc_type (type3); | |
aca88567 | 1880 | |
2c71103e NC |
1881 | printf (" Type2: "); |
1882 | ||
1883 | if (rtype2 == NULL) | |
39dbeff8 AM |
1884 | printf (_("unrecognized: %-7lx"), |
1885 | (unsigned long) type2 & 0xffffffff); | |
2c71103e NC |
1886 | else |
1887 | printf ("%-17.17s", rtype2); | |
1888 | ||
18bd398b | 1889 | printf ("\n Type3: "); |
2c71103e NC |
1890 | |
1891 | if (rtype3 == NULL) | |
39dbeff8 AM |
1892 | printf (_("unrecognized: %-7lx"), |
1893 | (unsigned long) type3 & 0xffffffff); | |
2c71103e NC |
1894 | else |
1895 | printf ("%-17.17s", rtype3); | |
1896 | ||
53c7db4b | 1897 | putchar ('\n'); |
2c71103e | 1898 | } |
aca88567 | 1899 | #endif /* BFD64 */ |
252b5132 RH |
1900 | } |
1901 | ||
c8286bd1 | 1902 | free (rels); |
32ec8896 NC |
1903 | |
1904 | return res; | |
252b5132 RH |
1905 | } |
1906 | ||
37c18eed SD |
1907 | static const char * |
1908 | get_aarch64_dynamic_type (unsigned long type) | |
1909 | { | |
1910 | switch (type) | |
1911 | { | |
1912 | case DT_AARCH64_BTI_PLT: return "AARCH64_BTI_PLT"; | |
1dbade74 | 1913 | case DT_AARCH64_PAC_PLT: return "AARCH64_PAC_PLT"; |
2301ed1c | 1914 | case DT_AARCH64_VARIANT_PCS: return "AARCH64_VARIANT_PCS"; |
37c18eed SD |
1915 | default: |
1916 | return NULL; | |
1917 | } | |
1918 | } | |
1919 | ||
252b5132 | 1920 | static const char * |
d3ba0551 | 1921 | get_mips_dynamic_type (unsigned long type) |
252b5132 RH |
1922 | { |
1923 | switch (type) | |
1924 | { | |
1925 | case DT_MIPS_RLD_VERSION: return "MIPS_RLD_VERSION"; | |
1926 | case DT_MIPS_TIME_STAMP: return "MIPS_TIME_STAMP"; | |
1927 | case DT_MIPS_ICHECKSUM: return "MIPS_ICHECKSUM"; | |
1928 | case DT_MIPS_IVERSION: return "MIPS_IVERSION"; | |
1929 | case DT_MIPS_FLAGS: return "MIPS_FLAGS"; | |
1930 | case DT_MIPS_BASE_ADDRESS: return "MIPS_BASE_ADDRESS"; | |
1931 | case DT_MIPS_MSYM: return "MIPS_MSYM"; | |
1932 | case DT_MIPS_CONFLICT: return "MIPS_CONFLICT"; | |
1933 | case DT_MIPS_LIBLIST: return "MIPS_LIBLIST"; | |
1934 | case DT_MIPS_LOCAL_GOTNO: return "MIPS_LOCAL_GOTNO"; | |
1935 | case DT_MIPS_CONFLICTNO: return "MIPS_CONFLICTNO"; | |
1936 | case DT_MIPS_LIBLISTNO: return "MIPS_LIBLISTNO"; | |
1937 | case DT_MIPS_SYMTABNO: return "MIPS_SYMTABNO"; | |
1938 | case DT_MIPS_UNREFEXTNO: return "MIPS_UNREFEXTNO"; | |
1939 | case DT_MIPS_GOTSYM: return "MIPS_GOTSYM"; | |
1940 | case DT_MIPS_HIPAGENO: return "MIPS_HIPAGENO"; | |
1941 | case DT_MIPS_RLD_MAP: return "MIPS_RLD_MAP"; | |
a5499fa4 | 1942 | case DT_MIPS_RLD_MAP_REL: return "MIPS_RLD_MAP_REL"; |
252b5132 RH |
1943 | case DT_MIPS_DELTA_CLASS: return "MIPS_DELTA_CLASS"; |
1944 | case DT_MIPS_DELTA_CLASS_NO: return "MIPS_DELTA_CLASS_NO"; | |
1945 | case DT_MIPS_DELTA_INSTANCE: return "MIPS_DELTA_INSTANCE"; | |
1946 | case DT_MIPS_DELTA_INSTANCE_NO: return "MIPS_DELTA_INSTANCE_NO"; | |
1947 | case DT_MIPS_DELTA_RELOC: return "MIPS_DELTA_RELOC"; | |
1948 | case DT_MIPS_DELTA_RELOC_NO: return "MIPS_DELTA_RELOC_NO"; | |
1949 | case DT_MIPS_DELTA_SYM: return "MIPS_DELTA_SYM"; | |
1950 | case DT_MIPS_DELTA_SYM_NO: return "MIPS_DELTA_SYM_NO"; | |
1951 | case DT_MIPS_DELTA_CLASSSYM: return "MIPS_DELTA_CLASSSYM"; | |
1952 | case DT_MIPS_DELTA_CLASSSYM_NO: return "MIPS_DELTA_CLASSSYM_NO"; | |
1953 | case DT_MIPS_CXX_FLAGS: return "MIPS_CXX_FLAGS"; | |
1954 | case DT_MIPS_PIXIE_INIT: return "MIPS_PIXIE_INIT"; | |
1955 | case DT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB"; | |
1956 | case DT_MIPS_LOCALPAGE_GOTIDX: return "MIPS_LOCALPAGE_GOTIDX"; | |
1957 | case DT_MIPS_LOCAL_GOTIDX: return "MIPS_LOCAL_GOTIDX"; | |
1958 | case DT_MIPS_HIDDEN_GOTIDX: return "MIPS_HIDDEN_GOTIDX"; | |
1959 | case DT_MIPS_PROTECTED_GOTIDX: return "MIPS_PROTECTED_GOTIDX"; | |
1960 | case DT_MIPS_OPTIONS: return "MIPS_OPTIONS"; | |
1961 | case DT_MIPS_INTERFACE: return "MIPS_INTERFACE"; | |
1962 | case DT_MIPS_DYNSTR_ALIGN: return "MIPS_DYNSTR_ALIGN"; | |
1963 | case DT_MIPS_INTERFACE_SIZE: return "MIPS_INTERFACE_SIZE"; | |
1964 | case DT_MIPS_RLD_TEXT_RESOLVE_ADDR: return "MIPS_RLD_TEXT_RESOLVE_ADDR"; | |
1965 | case DT_MIPS_PERF_SUFFIX: return "MIPS_PERF_SUFFIX"; | |
1966 | case DT_MIPS_COMPACT_SIZE: return "MIPS_COMPACT_SIZE"; | |
1967 | case DT_MIPS_GP_VALUE: return "MIPS_GP_VALUE"; | |
1968 | case DT_MIPS_AUX_DYNAMIC: return "MIPS_AUX_DYNAMIC"; | |
861fb55a DJ |
1969 | case DT_MIPS_PLTGOT: return "MIPS_PLTGOT"; |
1970 | case DT_MIPS_RWPLT: return "MIPS_RWPLT"; | |
f16a9783 | 1971 | case DT_MIPS_XHASH: return "MIPS_XHASH"; |
252b5132 RH |
1972 | default: |
1973 | return NULL; | |
1974 | } | |
1975 | } | |
1976 | ||
9a097730 | 1977 | static const char * |
d3ba0551 | 1978 | get_sparc64_dynamic_type (unsigned long type) |
9a097730 RH |
1979 | { |
1980 | switch (type) | |
1981 | { | |
1982 | case DT_SPARC_REGISTER: return "SPARC_REGISTER"; | |
1983 | default: | |
1984 | return NULL; | |
1985 | } | |
103f02d3 UD |
1986 | } |
1987 | ||
7490d522 AM |
1988 | static const char * |
1989 | get_ppc_dynamic_type (unsigned long type) | |
1990 | { | |
1991 | switch (type) | |
1992 | { | |
a7f2871e | 1993 | case DT_PPC_GOT: return "PPC_GOT"; |
e8910a83 | 1994 | case DT_PPC_OPT: return "PPC_OPT"; |
7490d522 AM |
1995 | default: |
1996 | return NULL; | |
1997 | } | |
1998 | } | |
1999 | ||
f1cb7e17 | 2000 | static const char * |
d3ba0551 | 2001 | get_ppc64_dynamic_type (unsigned long type) |
f1cb7e17 AM |
2002 | { |
2003 | switch (type) | |
2004 | { | |
a7f2871e AM |
2005 | case DT_PPC64_GLINK: return "PPC64_GLINK"; |
2006 | case DT_PPC64_OPD: return "PPC64_OPD"; | |
2007 | case DT_PPC64_OPDSZ: return "PPC64_OPDSZ"; | |
e8910a83 | 2008 | case DT_PPC64_OPT: return "PPC64_OPT"; |
f1cb7e17 AM |
2009 | default: |
2010 | return NULL; | |
2011 | } | |
2012 | } | |
2013 | ||
103f02d3 | 2014 | static const char * |
d3ba0551 | 2015 | get_parisc_dynamic_type (unsigned long type) |
103f02d3 UD |
2016 | { |
2017 | switch (type) | |
2018 | { | |
2019 | case DT_HP_LOAD_MAP: return "HP_LOAD_MAP"; | |
2020 | case DT_HP_DLD_FLAGS: return "HP_DLD_FLAGS"; | |
2021 | case DT_HP_DLD_HOOK: return "HP_DLD_HOOK"; | |
2022 | case DT_HP_UX10_INIT: return "HP_UX10_INIT"; | |
2023 | case DT_HP_UX10_INITSZ: return "HP_UX10_INITSZ"; | |
2024 | case DT_HP_PREINIT: return "HP_PREINIT"; | |
2025 | case DT_HP_PREINITSZ: return "HP_PREINITSZ"; | |
2026 | case DT_HP_NEEDED: return "HP_NEEDED"; | |
2027 | case DT_HP_TIME_STAMP: return "HP_TIME_STAMP"; | |
2028 | case DT_HP_CHECKSUM: return "HP_CHECKSUM"; | |
2029 | case DT_HP_GST_SIZE: return "HP_GST_SIZE"; | |
2030 | case DT_HP_GST_VERSION: return "HP_GST_VERSION"; | |
2031 | case DT_HP_GST_HASHVAL: return "HP_GST_HASHVAL"; | |
eec8f817 DA |
2032 | case DT_HP_EPLTREL: return "HP_GST_EPLTREL"; |
2033 | case DT_HP_EPLTRELSZ: return "HP_GST_EPLTRELSZ"; | |
2034 | case DT_HP_FILTERED: return "HP_FILTERED"; | |
2035 | case DT_HP_FILTER_TLS: return "HP_FILTER_TLS"; | |
2036 | case DT_HP_COMPAT_FILTERED: return "HP_COMPAT_FILTERED"; | |
2037 | case DT_HP_LAZYLOAD: return "HP_LAZYLOAD"; | |
2038 | case DT_HP_BIND_NOW_COUNT: return "HP_BIND_NOW_COUNT"; | |
2039 | case DT_PLT: return "PLT"; | |
2040 | case DT_PLT_SIZE: return "PLT_SIZE"; | |
2041 | case DT_DLT: return "DLT"; | |
2042 | case DT_DLT_SIZE: return "DLT_SIZE"; | |
103f02d3 UD |
2043 | default: |
2044 | return NULL; | |
2045 | } | |
2046 | } | |
9a097730 | 2047 | |
ecc51f48 | 2048 | static const char * |
d3ba0551 | 2049 | get_ia64_dynamic_type (unsigned long type) |
ecc51f48 NC |
2050 | { |
2051 | switch (type) | |
2052 | { | |
148b93f2 NC |
2053 | case DT_IA_64_PLT_RESERVE: return "IA_64_PLT_RESERVE"; |
2054 | case DT_IA_64_VMS_SUBTYPE: return "VMS_SUBTYPE"; | |
2055 | case DT_IA_64_VMS_IMGIOCNT: return "VMS_IMGIOCNT"; | |
2056 | case DT_IA_64_VMS_LNKFLAGS: return "VMS_LNKFLAGS"; | |
2057 | case DT_IA_64_VMS_VIR_MEM_BLK_SIZ: return "VMS_VIR_MEM_BLK_SIZ"; | |
2058 | case DT_IA_64_VMS_IDENT: return "VMS_IDENT"; | |
2059 | case DT_IA_64_VMS_NEEDED_IDENT: return "VMS_NEEDED_IDENT"; | |
2060 | case DT_IA_64_VMS_IMG_RELA_CNT: return "VMS_IMG_RELA_CNT"; | |
2061 | case DT_IA_64_VMS_SEG_RELA_CNT: return "VMS_SEG_RELA_CNT"; | |
2062 | case DT_IA_64_VMS_FIXUP_RELA_CNT: return "VMS_FIXUP_RELA_CNT"; | |
2063 | case DT_IA_64_VMS_FIXUP_NEEDED: return "VMS_FIXUP_NEEDED"; | |
2064 | case DT_IA_64_VMS_SYMVEC_CNT: return "VMS_SYMVEC_CNT"; | |
2065 | case DT_IA_64_VMS_XLATED: return "VMS_XLATED"; | |
2066 | case DT_IA_64_VMS_STACKSIZE: return "VMS_STACKSIZE"; | |
2067 | case DT_IA_64_VMS_UNWINDSZ: return "VMS_UNWINDSZ"; | |
2068 | case DT_IA_64_VMS_UNWIND_CODSEG: return "VMS_UNWIND_CODSEG"; | |
2069 | case DT_IA_64_VMS_UNWIND_INFOSEG: return "VMS_UNWIND_INFOSEG"; | |
2070 | case DT_IA_64_VMS_LINKTIME: return "VMS_LINKTIME"; | |
2071 | case DT_IA_64_VMS_SEG_NO: return "VMS_SEG_NO"; | |
2072 | case DT_IA_64_VMS_SYMVEC_OFFSET: return "VMS_SYMVEC_OFFSET"; | |
2073 | case DT_IA_64_VMS_SYMVEC_SEG: return "VMS_SYMVEC_SEG"; | |
2074 | case DT_IA_64_VMS_UNWIND_OFFSET: return "VMS_UNWIND_OFFSET"; | |
2075 | case DT_IA_64_VMS_UNWIND_SEG: return "VMS_UNWIND_SEG"; | |
2076 | case DT_IA_64_VMS_STRTAB_OFFSET: return "VMS_STRTAB_OFFSET"; | |
2077 | case DT_IA_64_VMS_SYSVER_OFFSET: return "VMS_SYSVER_OFFSET"; | |
2078 | case DT_IA_64_VMS_IMG_RELA_OFF: return "VMS_IMG_RELA_OFF"; | |
2079 | case DT_IA_64_VMS_SEG_RELA_OFF: return "VMS_SEG_RELA_OFF"; | |
2080 | case DT_IA_64_VMS_FIXUP_RELA_OFF: return "VMS_FIXUP_RELA_OFF"; | |
2081 | case DT_IA_64_VMS_PLTGOT_OFFSET: return "VMS_PLTGOT_OFFSET"; | |
2082 | case DT_IA_64_VMS_PLTGOT_SEG: return "VMS_PLTGOT_SEG"; | |
2083 | case DT_IA_64_VMS_FPMODE: return "VMS_FPMODE"; | |
ecc51f48 NC |
2084 | default: |
2085 | return NULL; | |
2086 | } | |
2087 | } | |
2088 | ||
fd85a6a1 NC |
2089 | static const char * |
2090 | get_solaris_section_type (unsigned long type) | |
2091 | { | |
2092 | switch (type) | |
2093 | { | |
2094 | case 0x6fffffee: return "SUNW_ancillary"; | |
2095 | case 0x6fffffef: return "SUNW_capchain"; | |
2096 | case 0x6ffffff0: return "SUNW_capinfo"; | |
2097 | case 0x6ffffff1: return "SUNW_symsort"; | |
2098 | case 0x6ffffff2: return "SUNW_tlssort"; | |
2099 | case 0x6ffffff3: return "SUNW_LDYNSYM"; | |
2100 | case 0x6ffffff4: return "SUNW_dof"; | |
2101 | case 0x6ffffff5: return "SUNW_cap"; | |
2102 | case 0x6ffffff6: return "SUNW_SIGNATURE"; | |
2103 | case 0x6ffffff7: return "SUNW_ANNOTATE"; | |
2104 | case 0x6ffffff8: return "SUNW_DEBUGSTR"; | |
2105 | case 0x6ffffff9: return "SUNW_DEBUG"; | |
2106 | case 0x6ffffffa: return "SUNW_move"; | |
2107 | case 0x6ffffffb: return "SUNW_COMDAT"; | |
2108 | case 0x6ffffffc: return "SUNW_syminfo"; | |
2109 | case 0x6ffffffd: return "SUNW_verdef"; | |
2110 | case 0x6ffffffe: return "SUNW_verneed"; | |
2111 | case 0x6fffffff: return "SUNW_versym"; | |
2112 | case 0x70000000: return "SPARC_GOTDATA"; | |
2113 | default: return NULL; | |
2114 | } | |
2115 | } | |
2116 | ||
fabcb361 RH |
2117 | static const char * |
2118 | get_alpha_dynamic_type (unsigned long type) | |
2119 | { | |
2120 | switch (type) | |
2121 | { | |
2122 | case DT_ALPHA_PLTRO: return "ALPHA_PLTRO"; | |
32ec8896 | 2123 | default: return NULL; |
fabcb361 RH |
2124 | } |
2125 | } | |
2126 | ||
1c0d3aa6 NC |
2127 | static const char * |
2128 | get_score_dynamic_type (unsigned long type) | |
2129 | { | |
2130 | switch (type) | |
2131 | { | |
2132 | case DT_SCORE_BASE_ADDRESS: return "SCORE_BASE_ADDRESS"; | |
2133 | case DT_SCORE_LOCAL_GOTNO: return "SCORE_LOCAL_GOTNO"; | |
2134 | case DT_SCORE_SYMTABNO: return "SCORE_SYMTABNO"; | |
2135 | case DT_SCORE_GOTSYM: return "SCORE_GOTSYM"; | |
2136 | case DT_SCORE_UNREFEXTNO: return "SCORE_UNREFEXTNO"; | |
2137 | case DT_SCORE_HIPAGENO: return "SCORE_HIPAGENO"; | |
32ec8896 | 2138 | default: return NULL; |
1c0d3aa6 NC |
2139 | } |
2140 | } | |
2141 | ||
40b36596 JM |
2142 | static const char * |
2143 | get_tic6x_dynamic_type (unsigned long type) | |
2144 | { | |
2145 | switch (type) | |
2146 | { | |
2147 | case DT_C6000_GSYM_OFFSET: return "C6000_GSYM_OFFSET"; | |
2148 | case DT_C6000_GSTR_OFFSET: return "C6000_GSTR_OFFSET"; | |
2149 | case DT_C6000_DSBT_BASE: return "C6000_DSBT_BASE"; | |
2150 | case DT_C6000_DSBT_SIZE: return "C6000_DSBT_SIZE"; | |
2151 | case DT_C6000_PREEMPTMAP: return "C6000_PREEMPTMAP"; | |
2152 | case DT_C6000_DSBT_INDEX: return "C6000_DSBT_INDEX"; | |
32ec8896 | 2153 | default: return NULL; |
40b36596 JM |
2154 | } |
2155 | } | |
1c0d3aa6 | 2156 | |
36591ba1 SL |
2157 | static const char * |
2158 | get_nios2_dynamic_type (unsigned long type) | |
2159 | { | |
2160 | switch (type) | |
2161 | { | |
2162 | case DT_NIOS2_GP: return "NIOS2_GP"; | |
32ec8896 | 2163 | default: return NULL; |
36591ba1 SL |
2164 | } |
2165 | } | |
2166 | ||
fd85a6a1 NC |
2167 | static const char * |
2168 | get_solaris_dynamic_type (unsigned long type) | |
2169 | { | |
2170 | switch (type) | |
2171 | { | |
2172 | case 0x6000000d: return "SUNW_AUXILIARY"; | |
2173 | case 0x6000000e: return "SUNW_RTLDINF"; | |
2174 | case 0x6000000f: return "SUNW_FILTER"; | |
2175 | case 0x60000010: return "SUNW_CAP"; | |
2176 | case 0x60000011: return "SUNW_SYMTAB"; | |
2177 | case 0x60000012: return "SUNW_SYMSZ"; | |
2178 | case 0x60000013: return "SUNW_SORTENT"; | |
2179 | case 0x60000014: return "SUNW_SYMSORT"; | |
2180 | case 0x60000015: return "SUNW_SYMSORTSZ"; | |
2181 | case 0x60000016: return "SUNW_TLSSORT"; | |
2182 | case 0x60000017: return "SUNW_TLSSORTSZ"; | |
2183 | case 0x60000018: return "SUNW_CAPINFO"; | |
2184 | case 0x60000019: return "SUNW_STRPAD"; | |
2185 | case 0x6000001a: return "SUNW_CAPCHAIN"; | |
2186 | case 0x6000001b: return "SUNW_LDMACH"; | |
2187 | case 0x6000001d: return "SUNW_CAPCHAINENT"; | |
2188 | case 0x6000001f: return "SUNW_CAPCHAINSZ"; | |
2189 | case 0x60000021: return "SUNW_PARENT"; | |
2190 | case 0x60000023: return "SUNW_ASLR"; | |
2191 | case 0x60000025: return "SUNW_RELAX"; | |
2192 | case 0x60000029: return "SUNW_NXHEAP"; | |
2193 | case 0x6000002b: return "SUNW_NXSTACK"; | |
2194 | ||
2195 | case 0x70000001: return "SPARC_REGISTER"; | |
2196 | case 0x7ffffffd: return "AUXILIARY"; | |
2197 | case 0x7ffffffe: return "USED"; | |
2198 | case 0x7fffffff: return "FILTER"; | |
2199 | ||
15f205b1 | 2200 | default: return NULL; |
fd85a6a1 NC |
2201 | } |
2202 | } | |
2203 | ||
252b5132 | 2204 | static const char * |
dda8d76d | 2205 | get_dynamic_type (Filedata * filedata, unsigned long type) |
252b5132 | 2206 | { |
e9e44622 | 2207 | static char buff[64]; |
252b5132 RH |
2208 | |
2209 | switch (type) | |
2210 | { | |
2211 | case DT_NULL: return "NULL"; | |
2212 | case DT_NEEDED: return "NEEDED"; | |
2213 | case DT_PLTRELSZ: return "PLTRELSZ"; | |
2214 | case DT_PLTGOT: return "PLTGOT"; | |
2215 | case DT_HASH: return "HASH"; | |
2216 | case DT_STRTAB: return "STRTAB"; | |
2217 | case DT_SYMTAB: return "SYMTAB"; | |
2218 | case DT_RELA: return "RELA"; | |
2219 | case DT_RELASZ: return "RELASZ"; | |
2220 | case DT_RELAENT: return "RELAENT"; | |
2221 | case DT_STRSZ: return "STRSZ"; | |
2222 | case DT_SYMENT: return "SYMENT"; | |
2223 | case DT_INIT: return "INIT"; | |
2224 | case DT_FINI: return "FINI"; | |
2225 | case DT_SONAME: return "SONAME"; | |
2226 | case DT_RPATH: return "RPATH"; | |
2227 | case DT_SYMBOLIC: return "SYMBOLIC"; | |
2228 | case DT_REL: return "REL"; | |
2229 | case DT_RELSZ: return "RELSZ"; | |
2230 | case DT_RELENT: return "RELENT"; | |
dd207c13 FS |
2231 | case DT_RELR: return "RELR"; |
2232 | case DT_RELRSZ: return "RELRSZ"; | |
2233 | case DT_RELRENT: return "RELRENT"; | |
252b5132 RH |
2234 | case DT_PLTREL: return "PLTREL"; |
2235 | case DT_DEBUG: return "DEBUG"; | |
2236 | case DT_TEXTREL: return "TEXTREL"; | |
2237 | case DT_JMPREL: return "JMPREL"; | |
2238 | case DT_BIND_NOW: return "BIND_NOW"; | |
2239 | case DT_INIT_ARRAY: return "INIT_ARRAY"; | |
2240 | case DT_FINI_ARRAY: return "FINI_ARRAY"; | |
2241 | case DT_INIT_ARRAYSZ: return "INIT_ARRAYSZ"; | |
2242 | case DT_FINI_ARRAYSZ: return "FINI_ARRAYSZ"; | |
d1133906 NC |
2243 | case DT_RUNPATH: return "RUNPATH"; |
2244 | case DT_FLAGS: return "FLAGS"; | |
2d0e6f43 | 2245 | |
d1133906 NC |
2246 | case DT_PREINIT_ARRAY: return "PREINIT_ARRAY"; |
2247 | case DT_PREINIT_ARRAYSZ: return "PREINIT_ARRAYSZ"; | |
6d913794 | 2248 | case DT_SYMTAB_SHNDX: return "SYMTAB_SHNDX"; |
103f02d3 | 2249 | |
05107a46 | 2250 | case DT_CHECKSUM: return "CHECKSUM"; |
252b5132 RH |
2251 | case DT_PLTPADSZ: return "PLTPADSZ"; |
2252 | case DT_MOVEENT: return "MOVEENT"; | |
2253 | case DT_MOVESZ: return "MOVESZ"; | |
dcefbbbd | 2254 | case DT_FEATURE: return "FEATURE"; |
252b5132 RH |
2255 | case DT_POSFLAG_1: return "POSFLAG_1"; |
2256 | case DT_SYMINSZ: return "SYMINSZ"; | |
2257 | case DT_SYMINENT: return "SYMINENT"; /* aka VALRNGHI */ | |
103f02d3 | 2258 | |
252b5132 | 2259 | case DT_ADDRRNGLO: return "ADDRRNGLO"; |
dcefbbbd L |
2260 | case DT_CONFIG: return "CONFIG"; |
2261 | case DT_DEPAUDIT: return "DEPAUDIT"; | |
2262 | case DT_AUDIT: return "AUDIT"; | |
2263 | case DT_PLTPAD: return "PLTPAD"; | |
2264 | case DT_MOVETAB: return "MOVETAB"; | |
252b5132 | 2265 | case DT_SYMINFO: return "SYMINFO"; /* aka ADDRRNGHI */ |
103f02d3 | 2266 | |
252b5132 | 2267 | case DT_VERSYM: return "VERSYM"; |
103f02d3 | 2268 | |
67a4f2b7 AO |
2269 | case DT_TLSDESC_GOT: return "TLSDESC_GOT"; |
2270 | case DT_TLSDESC_PLT: return "TLSDESC_PLT"; | |
252b5132 RH |
2271 | case DT_RELACOUNT: return "RELACOUNT"; |
2272 | case DT_RELCOUNT: return "RELCOUNT"; | |
2273 | case DT_FLAGS_1: return "FLAGS_1"; | |
2274 | case DT_VERDEF: return "VERDEF"; | |
2275 | case DT_VERDEFNUM: return "VERDEFNUM"; | |
2276 | case DT_VERNEED: return "VERNEED"; | |
2277 | case DT_VERNEEDNUM: return "VERNEEDNUM"; | |
103f02d3 | 2278 | |
019148e4 | 2279 | case DT_AUXILIARY: return "AUXILIARY"; |
252b5132 RH |
2280 | case DT_USED: return "USED"; |
2281 | case DT_FILTER: return "FILTER"; | |
103f02d3 | 2282 | |
047b2264 JJ |
2283 | case DT_GNU_PRELINKED: return "GNU_PRELINKED"; |
2284 | case DT_GNU_CONFLICT: return "GNU_CONFLICT"; | |
2285 | case DT_GNU_CONFLICTSZ: return "GNU_CONFLICTSZ"; | |
2286 | case DT_GNU_LIBLIST: return "GNU_LIBLIST"; | |
2287 | case DT_GNU_LIBLISTSZ: return "GNU_LIBLISTSZ"; | |
fdc90cb4 | 2288 | case DT_GNU_HASH: return "GNU_HASH"; |
a5da3dee | 2289 | case DT_GNU_FLAGS_1: return "GNU_FLAGS_1"; |
047b2264 | 2290 | |
252b5132 RH |
2291 | default: |
2292 | if ((type >= DT_LOPROC) && (type <= DT_HIPROC)) | |
2293 | { | |
2cf0635d | 2294 | const char * result; |
103f02d3 | 2295 | |
dda8d76d | 2296 | switch (filedata->file_header.e_machine) |
252b5132 | 2297 | { |
37c18eed SD |
2298 | case EM_AARCH64: |
2299 | result = get_aarch64_dynamic_type (type); | |
2300 | break; | |
252b5132 | 2301 | case EM_MIPS: |
4fe85591 | 2302 | case EM_MIPS_RS3_LE: |
252b5132 RH |
2303 | result = get_mips_dynamic_type (type); |
2304 | break; | |
9a097730 RH |
2305 | case EM_SPARCV9: |
2306 | result = get_sparc64_dynamic_type (type); | |
2307 | break; | |
7490d522 AM |
2308 | case EM_PPC: |
2309 | result = get_ppc_dynamic_type (type); | |
2310 | break; | |
f1cb7e17 AM |
2311 | case EM_PPC64: |
2312 | result = get_ppc64_dynamic_type (type); | |
2313 | break; | |
ecc51f48 NC |
2314 | case EM_IA_64: |
2315 | result = get_ia64_dynamic_type (type); | |
2316 | break; | |
fabcb361 RH |
2317 | case EM_ALPHA: |
2318 | result = get_alpha_dynamic_type (type); | |
2319 | break; | |
1c0d3aa6 NC |
2320 | case EM_SCORE: |
2321 | result = get_score_dynamic_type (type); | |
2322 | break; | |
40b36596 JM |
2323 | case EM_TI_C6000: |
2324 | result = get_tic6x_dynamic_type (type); | |
2325 | break; | |
36591ba1 SL |
2326 | case EM_ALTERA_NIOS2: |
2327 | result = get_nios2_dynamic_type (type); | |
2328 | break; | |
252b5132 | 2329 | default: |
dda8d76d | 2330 | if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS) |
fd85a6a1 NC |
2331 | result = get_solaris_dynamic_type (type); |
2332 | else | |
2333 | result = NULL; | |
252b5132 RH |
2334 | break; |
2335 | } | |
2336 | ||
2337 | if (result != NULL) | |
2338 | return result; | |
2339 | ||
e9e44622 | 2340 | snprintf (buff, sizeof (buff), _("Processor Specific: %lx"), type); |
252b5132 | 2341 | } |
eec8f817 | 2342 | else if (((type >= DT_LOOS) && (type <= DT_HIOS)) |
dda8d76d | 2343 | || (filedata->file_header.e_machine == EM_PARISC |
eec8f817 | 2344 | && (type >= OLD_DT_LOOS) && (type <= OLD_DT_HIOS))) |
103f02d3 | 2345 | { |
2cf0635d | 2346 | const char * result; |
103f02d3 | 2347 | |
dda8d76d | 2348 | switch (filedata->file_header.e_machine) |
103f02d3 UD |
2349 | { |
2350 | case EM_PARISC: | |
2351 | result = get_parisc_dynamic_type (type); | |
2352 | break; | |
148b93f2 NC |
2353 | case EM_IA_64: |
2354 | result = get_ia64_dynamic_type (type); | |
2355 | break; | |
103f02d3 | 2356 | default: |
dda8d76d | 2357 | if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS) |
fd85a6a1 NC |
2358 | result = get_solaris_dynamic_type (type); |
2359 | else | |
2360 | result = NULL; | |
103f02d3 UD |
2361 | break; |
2362 | } | |
2363 | ||
2364 | if (result != NULL) | |
2365 | return result; | |
2366 | ||
e9e44622 JJ |
2367 | snprintf (buff, sizeof (buff), _("Operating System specific: %lx"), |
2368 | type); | |
103f02d3 | 2369 | } |
252b5132 | 2370 | else |
e9e44622 | 2371 | snprintf (buff, sizeof (buff), _("<unknown>: %lx"), type); |
103f02d3 | 2372 | |
252b5132 RH |
2373 | return buff; |
2374 | } | |
2375 | } | |
2376 | ||
93df3340 AM |
2377 | static bool get_program_headers (Filedata *); |
2378 | static bool get_dynamic_section (Filedata *); | |
2379 | ||
2380 | static void | |
2381 | locate_dynamic_section (Filedata *filedata) | |
2382 | { | |
2383 | unsigned long dynamic_addr = 0; | |
2384 | bfd_size_type dynamic_size = 0; | |
2385 | ||
2386 | if (filedata->file_header.e_phnum != 0 | |
2387 | && get_program_headers (filedata)) | |
2388 | { | |
2389 | Elf_Internal_Phdr *segment; | |
2390 | unsigned int i; | |
2391 | ||
2392 | for (i = 0, segment = filedata->program_headers; | |
2393 | i < filedata->file_header.e_phnum; | |
2394 | i++, segment++) | |
2395 | { | |
2396 | if (segment->p_type == PT_DYNAMIC) | |
2397 | { | |
2398 | dynamic_addr = segment->p_offset; | |
2399 | dynamic_size = segment->p_filesz; | |
2400 | ||
2401 | if (filedata->section_headers != NULL) | |
2402 | { | |
2403 | Elf_Internal_Shdr *sec; | |
2404 | ||
2405 | sec = find_section (filedata, ".dynamic"); | |
2406 | if (sec != NULL) | |
2407 | { | |
2408 | if (sec->sh_size == 0 | |
2409 | || sec->sh_type == SHT_NOBITS) | |
2410 | { | |
2411 | dynamic_addr = 0; | |
2412 | dynamic_size = 0; | |
2413 | } | |
2414 | else | |
2415 | { | |
2416 | dynamic_addr = sec->sh_offset; | |
2417 | dynamic_size = sec->sh_size; | |
2418 | } | |
2419 | } | |
2420 | } | |
2421 | ||
2422 | if (dynamic_addr > filedata->file_size | |
2423 | || (dynamic_size > filedata->file_size - dynamic_addr)) | |
2424 | { | |
2425 | dynamic_addr = 0; | |
2426 | dynamic_size = 0; | |
2427 | } | |
2428 | break; | |
2429 | } | |
2430 | } | |
2431 | } | |
2432 | filedata->dynamic_addr = dynamic_addr; | |
2433 | filedata->dynamic_size = dynamic_size ? dynamic_size : 1; | |
2434 | } | |
2435 | ||
2436 | static bool | |
2437 | is_pie (Filedata *filedata) | |
2438 | { | |
2439 | Elf_Internal_Dyn *entry; | |
2440 | ||
2441 | if (filedata->dynamic_size == 0) | |
2442 | locate_dynamic_section (filedata); | |
2443 | if (filedata->dynamic_size <= 1) | |
2444 | return false; | |
2445 | ||
2446 | if (!get_dynamic_section (filedata)) | |
2447 | return false; | |
2448 | ||
2449 | for (entry = filedata->dynamic_section; | |
2450 | entry < filedata->dynamic_section + filedata->dynamic_nent; | |
2451 | entry++) | |
2452 | { | |
2453 | if (entry->d_tag == DT_FLAGS_1) | |
2454 | { | |
2455 | if ((entry->d_un.d_val & DF_1_PIE) != 0) | |
2456 | return true; | |
2457 | break; | |
2458 | } | |
2459 | } | |
2460 | return false; | |
2461 | } | |
2462 | ||
252b5132 | 2463 | static char * |
93df3340 | 2464 | get_file_type (Filedata *filedata) |
252b5132 | 2465 | { |
93df3340 | 2466 | unsigned e_type = filedata->file_header.e_type; |
89246a0e | 2467 | static char buff[64]; |
252b5132 RH |
2468 | |
2469 | switch (e_type) | |
2470 | { | |
32ec8896 NC |
2471 | case ET_NONE: return _("NONE (None)"); |
2472 | case ET_REL: return _("REL (Relocatable file)"); | |
2473 | case ET_EXEC: return _("EXEC (Executable file)"); | |
93df3340 AM |
2474 | case ET_DYN: |
2475 | if (is_pie (filedata)) | |
2476 | return _("DYN (Position-Independent Executable file)"); | |
2477 | else | |
2478 | return _("DYN (Shared object file)"); | |
32ec8896 | 2479 | case ET_CORE: return _("CORE (Core file)"); |
252b5132 RH |
2480 | |
2481 | default: | |
2482 | if ((e_type >= ET_LOPROC) && (e_type <= ET_HIPROC)) | |
e9e44622 | 2483 | snprintf (buff, sizeof (buff), _("Processor Specific: (%x)"), e_type); |
252b5132 | 2484 | else if ((e_type >= ET_LOOS) && (e_type <= ET_HIOS)) |
e9e44622 | 2485 | snprintf (buff, sizeof (buff), _("OS Specific: (%x)"), e_type); |
252b5132 | 2486 | else |
e9e44622 | 2487 | snprintf (buff, sizeof (buff), _("<unknown>: %x"), e_type); |
252b5132 RH |
2488 | return buff; |
2489 | } | |
2490 | } | |
2491 | ||
2492 | static char * | |
d3ba0551 | 2493 | get_machine_name (unsigned e_machine) |
252b5132 | 2494 | { |
b34976b6 | 2495 | static char buff[64]; /* XXX */ |
252b5132 RH |
2496 | |
2497 | switch (e_machine) | |
2498 | { | |
55e22ca8 NC |
2499 | /* Please keep this switch table sorted by increasing EM_ value. */ |
2500 | /* 0 */ | |
c45021f2 NC |
2501 | case EM_NONE: return _("None"); |
2502 | case EM_M32: return "WE32100"; | |
2503 | case EM_SPARC: return "Sparc"; | |
2504 | case EM_386: return "Intel 80386"; | |
2505 | case EM_68K: return "MC68000"; | |
2506 | case EM_88K: return "MC88000"; | |
22abe556 | 2507 | case EM_IAMCU: return "Intel MCU"; |
fb70ec17 | 2508 | case EM_860: return "Intel 80860"; |
c45021f2 NC |
2509 | case EM_MIPS: return "MIPS R3000"; |
2510 | case EM_S370: return "IBM System/370"; | |
55e22ca8 | 2511 | /* 10 */ |
7036c0e1 | 2512 | case EM_MIPS_RS3_LE: return "MIPS R4000 big-endian"; |
252b5132 | 2513 | case EM_OLD_SPARCV9: return "Sparc v9 (old)"; |
c45021f2 | 2514 | case EM_PARISC: return "HPPA"; |
55e22ca8 | 2515 | case EM_VPP550: return "Fujitsu VPP500"; |
7036c0e1 | 2516 | case EM_SPARC32PLUS: return "Sparc v8+" ; |
d7867d17 | 2517 | case EM_960: return "Intel 80960"; |
c45021f2 | 2518 | case EM_PPC: return "PowerPC"; |
55e22ca8 | 2519 | /* 20 */ |
285d1771 | 2520 | case EM_PPC64: return "PowerPC64"; |
55e22ca8 NC |
2521 | case EM_S390_OLD: |
2522 | case EM_S390: return "IBM S/390"; | |
2523 | case EM_SPU: return "SPU"; | |
2524 | /* 30 */ | |
2525 | case EM_V800: return "Renesas V850 (using RH850 ABI)"; | |
c45021f2 NC |
2526 | case EM_FR20: return "Fujitsu FR20"; |
2527 | case EM_RH32: return "TRW RH32"; | |
b34976b6 | 2528 | case EM_MCORE: return "MCORE"; |
55e22ca8 | 2529 | /* 40 */ |
7036c0e1 AJ |
2530 | case EM_ARM: return "ARM"; |
2531 | case EM_OLD_ALPHA: return "Digital Alpha (old)"; | |
ef230218 | 2532 | case EM_SH: return "Renesas / SuperH SH"; |
c45021f2 NC |
2533 | case EM_SPARCV9: return "Sparc v9"; |
2534 | case EM_TRICORE: return "Siemens Tricore"; | |
584da044 | 2535 | case EM_ARC: return "ARC"; |
c2dcd04e NC |
2536 | case EM_H8_300: return "Renesas H8/300"; |
2537 | case EM_H8_300H: return "Renesas H8/300H"; | |
2538 | case EM_H8S: return "Renesas H8S"; | |
2539 | case EM_H8_500: return "Renesas H8/500"; | |
55e22ca8 | 2540 | /* 50 */ |
30800947 | 2541 | case EM_IA_64: return "Intel IA-64"; |
252b5132 RH |
2542 | case EM_MIPS_X: return "Stanford MIPS-X"; |
2543 | case EM_COLDFIRE: return "Motorola Coldfire"; | |
55e22ca8 | 2544 | case EM_68HC12: return "Motorola MC68HC12 Microcontroller"; |
7036c0e1 AJ |
2545 | case EM_MMA: return "Fujitsu Multimedia Accelerator"; |
2546 | case EM_PCP: return "Siemens PCP"; | |
2547 | case EM_NCPU: return "Sony nCPU embedded RISC processor"; | |
2548 | case EM_NDR1: return "Denso NDR1 microprocesspr"; | |
2549 | case EM_STARCORE: return "Motorola Star*Core processor"; | |
2550 | case EM_ME16: return "Toyota ME16 processor"; | |
55e22ca8 | 2551 | /* 60 */ |
7036c0e1 AJ |
2552 | case EM_ST100: return "STMicroelectronics ST100 processor"; |
2553 | case EM_TINYJ: return "Advanced Logic Corp. TinyJ embedded processor"; | |
55e22ca8 | 2554 | case EM_X86_64: return "Advanced Micro Devices X86-64"; |
11636f9e JM |
2555 | case EM_PDSP: return "Sony DSP processor"; |
2556 | case EM_PDP10: return "Digital Equipment Corp. PDP-10"; | |
2557 | case EM_PDP11: return "Digital Equipment Corp. PDP-11"; | |
7036c0e1 AJ |
2558 | case EM_FX66: return "Siemens FX66 microcontroller"; |
2559 | case EM_ST9PLUS: return "STMicroelectronics ST9+ 8/16 bit microcontroller"; | |
2560 | case EM_ST7: return "STMicroelectronics ST7 8-bit microcontroller"; | |
2561 | case EM_68HC16: return "Motorola MC68HC16 Microcontroller"; | |
55e22ca8 | 2562 | /* 70 */ |
7036c0e1 AJ |
2563 | case EM_68HC11: return "Motorola MC68HC11 Microcontroller"; |
2564 | case EM_68HC08: return "Motorola MC68HC08 Microcontroller"; | |
2565 | case EM_68HC05: return "Motorola MC68HC05 Microcontroller"; | |
2566 | case EM_SVX: return "Silicon Graphics SVx"; | |
2567 | case EM_ST19: return "STMicroelectronics ST19 8-bit microcontroller"; | |
2568 | case EM_VAX: return "Digital VAX"; | |
1b61cf92 | 2569 | case EM_CRIS: return "Axis Communications 32-bit embedded processor"; |
c45021f2 NC |
2570 | case EM_JAVELIN: return "Infineon Technologies 32-bit embedded cpu"; |
2571 | case EM_FIREPATH: return "Element 14 64-bit DSP processor"; | |
2572 | case EM_ZSP: return "LSI Logic's 16-bit DSP processor"; | |
55e22ca8 | 2573 | /* 80 */ |
b34976b6 | 2574 | case EM_MMIX: return "Donald Knuth's educational 64-bit processor"; |
c45021f2 | 2575 | case EM_HUANY: return "Harvard Universitys's machine-independent object format"; |
3b36097d | 2576 | case EM_PRISM: return "Vitesse Prism"; |
55e22ca8 NC |
2577 | case EM_AVR_OLD: |
2578 | case EM_AVR: return "Atmel AVR 8-bit microcontroller"; | |
2579 | case EM_CYGNUS_FR30: | |
2580 | case EM_FR30: return "Fujitsu FR30"; | |
2581 | case EM_CYGNUS_D10V: | |
2582 | case EM_D10V: return "d10v"; | |
2583 | case EM_CYGNUS_D30V: | |
2584 | case EM_D30V: return "d30v"; | |
2585 | case EM_CYGNUS_V850: | |
2586 | case EM_V850: return "Renesas V850"; | |
2587 | case EM_CYGNUS_M32R: | |
2588 | case EM_M32R: return "Renesas M32R (formerly Mitsubishi M32r)"; | |
2589 | case EM_CYGNUS_MN10300: | |
2590 | case EM_MN10300: return "mn10300"; | |
2591 | /* 90 */ | |
2592 | case EM_CYGNUS_MN10200: | |
2593 | case EM_MN10200: return "mn10200"; | |
2594 | case EM_PJ: return "picoJava"; | |
73589c9d | 2595 | case EM_OR1K: return "OpenRISC 1000"; |
55e22ca8 | 2596 | case EM_ARC_COMPACT: return "ARCompact"; |
88da6820 NC |
2597 | case EM_XTENSA_OLD: |
2598 | case EM_XTENSA: return "Tensilica Xtensa Processor"; | |
11636f9e JM |
2599 | case EM_VIDEOCORE: return "Alphamosaic VideoCore processor"; |
2600 | case EM_TMM_GPP: return "Thompson Multimedia General Purpose Processor"; | |
2601 | case EM_NS32K: return "National Semiconductor 32000 series"; | |
2602 | case EM_TPC: return "Tenor Network TPC processor"; | |
55e22ca8 NC |
2603 | case EM_SNP1K: return "Trebia SNP 1000 processor"; |
2604 | /* 100 */ | |
9abca702 | 2605 | case EM_ST200: return "STMicroelectronics ST200 microcontroller"; |
55e22ca8 NC |
2606 | case EM_IP2K_OLD: |
2607 | case EM_IP2K: return "Ubicom IP2xxx 8-bit microcontrollers"; | |
11636f9e JM |
2608 | case EM_MAX: return "MAX Processor"; |
2609 | case EM_CR: return "National Semiconductor CompactRISC"; | |
2610 | case EM_F2MC16: return "Fujitsu F2MC16"; | |
2611 | case EM_MSP430: return "Texas Instruments msp430 microcontroller"; | |
7bbe5bc5 | 2612 | case EM_BLACKFIN: return "Analog Devices Blackfin"; |
11636f9e JM |
2613 | case EM_SE_C33: return "S1C33 Family of Seiko Epson processors"; |
2614 | case EM_SEP: return "Sharp embedded microprocessor"; | |
2615 | case EM_ARCA: return "Arca RISC microprocessor"; | |
55e22ca8 | 2616 | /* 110 */ |
11636f9e JM |
2617 | case EM_UNICORE: return "Unicore"; |
2618 | case EM_EXCESS: return "eXcess 16/32/64-bit configurable embedded CPU"; | |
2619 | case EM_DXP: return "Icera Semiconductor Inc. Deep Execution Processor"; | |
64fd6348 | 2620 | case EM_ALTERA_NIOS2: return "Altera Nios II"; |
55e22ca8 NC |
2621 | case EM_CRX: return "National Semiconductor CRX microprocessor"; |
2622 | case EM_XGATE: return "Motorola XGATE embedded processor"; | |
c29aca4a | 2623 | case EM_C166: |
d70c5fc7 | 2624 | case EM_XC16X: return "Infineon Technologies xc16x"; |
11636f9e JM |
2625 | case EM_M16C: return "Renesas M16C series microprocessors"; |
2626 | case EM_DSPIC30F: return "Microchip Technology dsPIC30F Digital Signal Controller"; | |
2627 | case EM_CE: return "Freescale Communication Engine RISC core"; | |
55e22ca8 NC |
2628 | /* 120 */ |
2629 | case EM_M32C: return "Renesas M32c"; | |
2630 | /* 130 */ | |
11636f9e JM |
2631 | case EM_TSK3000: return "Altium TSK3000 core"; |
2632 | case EM_RS08: return "Freescale RS08 embedded processor"; | |
2633 | case EM_ECOG2: return "Cyan Technology eCOG2 microprocessor"; | |
55e22ca8 | 2634 | case EM_SCORE: return "SUNPLUS S+Core"; |
11636f9e JM |
2635 | case EM_DSP24: return "New Japan Radio (NJR) 24-bit DSP Processor"; |
2636 | case EM_VIDEOCORE3: return "Broadcom VideoCore III processor"; | |
55e22ca8 | 2637 | case EM_LATTICEMICO32: return "Lattice Mico32"; |
11636f9e | 2638 | case EM_SE_C17: return "Seiko Epson C17 family"; |
55e22ca8 | 2639 | /* 140 */ |
11636f9e JM |
2640 | case EM_TI_C6000: return "Texas Instruments TMS320C6000 DSP family"; |
2641 | case EM_TI_C2000: return "Texas Instruments TMS320C2000 DSP family"; | |
2642 | case EM_TI_C5500: return "Texas Instruments TMS320C55x DSP family"; | |
55e22ca8 NC |
2643 | case EM_TI_PRU: return "TI PRU I/O processor"; |
2644 | /* 160 */ | |
11636f9e JM |
2645 | case EM_MMDSP_PLUS: return "STMicroelectronics 64bit VLIW Data Signal Processor"; |
2646 | case EM_CYPRESS_M8C: return "Cypress M8C microprocessor"; | |
2647 | case EM_R32C: return "Renesas R32C series microprocessors"; | |
2648 | case EM_TRIMEDIA: return "NXP Semiconductors TriMedia architecture family"; | |
2649 | case EM_QDSP6: return "QUALCOMM DSP6 Processor"; | |
2650 | case EM_8051: return "Intel 8051 and variants"; | |
2651 | case EM_STXP7X: return "STMicroelectronics STxP7x family"; | |
2652 | case EM_NDS32: return "Andes Technology compact code size embedded RISC processor family"; | |
2653 | case EM_ECOG1X: return "Cyan Technology eCOG1X family"; | |
2654 | case EM_MAXQ30: return "Dallas Semiconductor MAXQ30 Core microcontrollers"; | |
55e22ca8 | 2655 | /* 170 */ |
11636f9e JM |
2656 | case EM_XIMO16: return "New Japan Radio (NJR) 16-bit DSP Processor"; |
2657 | case EM_MANIK: return "M2000 Reconfigurable RISC Microprocessor"; | |
2658 | case EM_CRAYNV2: return "Cray Inc. NV2 vector architecture"; | |
c7927a3c | 2659 | case EM_RX: return "Renesas RX"; |
a3c62988 | 2660 | case EM_METAG: return "Imagination Technologies Meta processor architecture"; |
11636f9e JM |
2661 | case EM_MCST_ELBRUS: return "MCST Elbrus general purpose hardware architecture"; |
2662 | case EM_ECOG16: return "Cyan Technology eCOG16 family"; | |
55e22ca8 NC |
2663 | case EM_CR16: |
2664 | case EM_MICROBLAZE: | |
2665 | case EM_MICROBLAZE_OLD: return "Xilinx MicroBlaze"; | |
11636f9e JM |
2666 | case EM_ETPU: return "Freescale Extended Time Processing Unit"; |
2667 | case EM_SLE9X: return "Infineon Technologies SLE9X core"; | |
55e22ca8 NC |
2668 | /* 180 */ |
2669 | case EM_L1OM: return "Intel L1OM"; | |
2670 | case EM_K1OM: return "Intel K1OM"; | |
2671 | case EM_INTEL182: return "Intel (reserved)"; | |
2672 | case EM_AARCH64: return "AArch64"; | |
2673 | case EM_ARM184: return "ARM (reserved)"; | |
2674 | case EM_AVR32: return "Atmel Corporation 32-bit microprocessor"; | |
11636f9e JM |
2675 | case EM_STM8: return "STMicroeletronics STM8 8-bit microcontroller"; |
2676 | case EM_TILE64: return "Tilera TILE64 multicore architecture family"; | |
2677 | case EM_TILEPRO: return "Tilera TILEPro multicore architecture family"; | |
55e22ca8 | 2678 | /* 190 */ |
11636f9e | 2679 | case EM_CUDA: return "NVIDIA CUDA architecture"; |
55e22ca8 | 2680 | case EM_TILEGX: return "Tilera TILE-Gx multicore architecture family"; |
6d913794 NC |
2681 | case EM_CLOUDSHIELD: return "CloudShield architecture family"; |
2682 | case EM_COREA_1ST: return "KIPO-KAIST Core-A 1st generation processor family"; | |
2683 | case EM_COREA_2ND: return "KIPO-KAIST Core-A 2nd generation processor family"; | |
55e22ca8 | 2684 | case EM_ARC_COMPACT2: return "ARCv2"; |
6d913794 | 2685 | case EM_OPEN8: return "Open8 8-bit RISC soft processor core"; |
55e22ca8 | 2686 | case EM_RL78: return "Renesas RL78"; |
6d913794 | 2687 | case EM_VIDEOCORE5: return "Broadcom VideoCore V processor"; |
55e22ca8 NC |
2688 | case EM_78K0R: return "Renesas 78K0R"; |
2689 | /* 200 */ | |
6d913794 | 2690 | case EM_56800EX: return "Freescale 56800EX Digital Signal Controller (DSC)"; |
15f205b1 NC |
2691 | case EM_BA1: return "Beyond BA1 CPU architecture"; |
2692 | case EM_BA2: return "Beyond BA2 CPU architecture"; | |
6d913794 NC |
2693 | case EM_XCORE: return "XMOS xCORE processor family"; |
2694 | case EM_MCHP_PIC: return "Microchip 8-bit PIC(r) family"; | |
7b9f9859 | 2695 | case EM_INTELGT: return "Intel Graphics Technology"; |
55e22ca8 | 2696 | /* 210 */ |
6d913794 NC |
2697 | case EM_KM32: return "KM211 KM32 32-bit processor"; |
2698 | case EM_KMX32: return "KM211 KMX32 32-bit processor"; | |
2699 | case EM_KMX16: return "KM211 KMX16 16-bit processor"; | |
2700 | case EM_KMX8: return "KM211 KMX8 8-bit processor"; | |
2701 | case EM_KVARC: return "KM211 KVARC processor"; | |
15f205b1 | 2702 | case EM_CDP: return "Paneve CDP architecture family"; |
6d913794 NC |
2703 | case EM_COGE: return "Cognitive Smart Memory Processor"; |
2704 | case EM_COOL: return "Bluechip Systems CoolEngine"; | |
2705 | case EM_NORC: return "Nanoradio Optimized RISC"; | |
2706 | case EM_CSR_KALIMBA: return "CSR Kalimba architecture family"; | |
55e22ca8 | 2707 | /* 220 */ |
15f205b1 | 2708 | case EM_Z80: return "Zilog Z80"; |
55e22ca8 NC |
2709 | case EM_VISIUM: return "CDS VISIUMcore processor"; |
2710 | case EM_FT32: return "FTDI Chip FT32"; | |
2711 | case EM_MOXIE: return "Moxie"; | |
2712 | case EM_AMDGPU: return "AMD GPU"; | |
4cf2ad72 CC |
2713 | /* 230 (all reserved) */ |
2714 | /* 240 */ | |
55e22ca8 NC |
2715 | case EM_RISCV: return "RISC-V"; |
2716 | case EM_LANAI: return "Lanai 32-bit processor"; | |
4cf2ad72 CC |
2717 | case EM_CEVA: return "CEVA Processor Architecture Family"; |
2718 | case EM_CEVA_X2: return "CEVA X2 Processor Family"; | |
55e22ca8 | 2719 | case EM_BPF: return "Linux BPF"; |
4cf2ad72 CC |
2720 | case EM_GRAPHCORE_IPU: return "Graphcore Intelligent Processing Unit"; |
2721 | case EM_IMG1: return "Imagination Technologies"; | |
2722 | /* 250 */ | |
fe944acf | 2723 | case EM_NFP: return "Netronome Flow Processor"; |
4cf2ad72 CC |
2724 | case EM_VE: return "NEC Vector Engine"; |
2725 | case EM_CSKY: return "C-SKY"; | |
2726 | case EM_ARC_COMPACT3_64: return "Synopsys ARCv2.3 64-bit"; | |
2727 | case EM_MCS6502: return "MOS Technology MCS 6502 processor"; | |
2728 | case EM_ARC_COMPACT3: return "Synopsys ARCv2.3 32-bit"; | |
2729 | case EM_KVX: return "Kalray VLIW core of the MPPA processor family"; | |
2730 | case EM_65816: return "WDC 65816/65C816"; | |
01a8c731 | 2731 | case EM_LOONGARCH: return "LoongArch"; |
4cf2ad72 | 2732 | case EM_KF32: return "ChipON KungFu32"; |
55e22ca8 NC |
2733 | |
2734 | /* Large numbers... */ | |
2735 | case EM_MT: return "Morpho Techologies MT processor"; | |
2736 | case EM_ALPHA: return "Alpha"; | |
2737 | case EM_WEBASSEMBLY: return "Web Assembly"; | |
9abca702 | 2738 | case EM_DLX: return "OpenDLX"; |
55e22ca8 NC |
2739 | case EM_XSTORMY16: return "Sanyo XStormy16 CPU core"; |
2740 | case EM_IQ2000: return "Vitesse IQ2000"; | |
2741 | case EM_M32C_OLD: | |
2742 | case EM_NIOS32: return "Altera Nios"; | |
2743 | case EM_CYGNUS_MEP: return "Toshiba MeP Media Engine"; | |
2744 | case EM_ADAPTEVA_EPIPHANY: return "Adapteva EPIPHANY"; | |
2745 | case EM_CYGNUS_FRV: return "Fujitsu FR-V"; | |
637b1970 | 2746 | case EM_S12Z: return "Freescale S12Z"; |
55e22ca8 | 2747 | |
252b5132 | 2748 | default: |
35d9dd2f | 2749 | snprintf (buff, sizeof (buff), _("<unknown>: 0x%x"), e_machine); |
252b5132 RH |
2750 | return buff; |
2751 | } | |
2752 | } | |
2753 | ||
a9522a21 AB |
2754 | static void |
2755 | decode_ARC_machine_flags (unsigned e_flags, unsigned e_machine, char buf[]) | |
2756 | { | |
2757 | /* ARC has two machine types EM_ARC_COMPACT and EM_ARC_COMPACT2. Some | |
6987d5a1 | 2758 | other compilers don't specify an architecture type in the e_flags, and |
a9522a21 AB |
2759 | instead use EM_ARC_COMPACT for old ARC600, ARC601, and ARC700 |
2760 | architectures, and switch to EM_ARC_COMPACT2 for newer ARCEM and ARCHS | |
2761 | architectures. | |
2762 | ||
2763 | Th GNU tools follows this use of EM_ARC_COMPACT and EM_ARC_COMPACT2, | |
2764 | but also sets a specific architecture type in the e_flags field. | |
2765 | ||
2766 | However, when decoding the flags we don't worry if we see an | |
2767 | unexpected pairing, for example EM_ARC_COMPACT machine type, with | |
2768 | ARCEM architecture type. */ | |
2769 | ||
2770 | switch (e_flags & EF_ARC_MACH_MSK) | |
2771 | { | |
2772 | /* We only expect these to occur for EM_ARC_COMPACT2. */ | |
2773 | case EF_ARC_CPU_ARCV2EM: | |
2774 | strcat (buf, ", ARC EM"); | |
2775 | break; | |
2776 | case EF_ARC_CPU_ARCV2HS: | |
2777 | strcat (buf, ", ARC HS"); | |
2778 | break; | |
2779 | ||
2780 | /* We only expect these to occur for EM_ARC_COMPACT. */ | |
2781 | case E_ARC_MACH_ARC600: | |
2782 | strcat (buf, ", ARC600"); | |
2783 | break; | |
2784 | case E_ARC_MACH_ARC601: | |
2785 | strcat (buf, ", ARC601"); | |
2786 | break; | |
2787 | case E_ARC_MACH_ARC700: | |
2788 | strcat (buf, ", ARC700"); | |
2789 | break; | |
2790 | ||
2791 | /* The only times we should end up here are (a) A corrupt ELF, (b) A | |
2792 | new ELF with new architecture being read by an old version of | |
2793 | readelf, or (c) An ELF built with non-GNU compiler that does not | |
2794 | set the architecture in the e_flags. */ | |
2795 | default: | |
2796 | if (e_machine == EM_ARC_COMPACT) | |
2797 | strcat (buf, ", Unknown ARCompact"); | |
2798 | else | |
2799 | strcat (buf, ", Unknown ARC"); | |
2800 | break; | |
2801 | } | |
2802 | ||
2803 | switch (e_flags & EF_ARC_OSABI_MSK) | |
2804 | { | |
2805 | case E_ARC_OSABI_ORIG: | |
2806 | strcat (buf, ", (ABI:legacy)"); | |
2807 | break; | |
2808 | case E_ARC_OSABI_V2: | |
2809 | strcat (buf, ", (ABI:v2)"); | |
2810 | break; | |
2811 | /* Only upstream 3.9+ kernels will support ARCv2 ISA. */ | |
2812 | case E_ARC_OSABI_V3: | |
2813 | strcat (buf, ", v3 no-legacy-syscalls ABI"); | |
2814 | break; | |
53a346d8 CZ |
2815 | case E_ARC_OSABI_V4: |
2816 | strcat (buf, ", v4 ABI"); | |
2817 | break; | |
a9522a21 AB |
2818 | default: |
2819 | strcat (buf, ", unrecognised ARC OSABI flag"); | |
2820 | break; | |
2821 | } | |
2822 | } | |
2823 | ||
f3485b74 | 2824 | static void |
d3ba0551 | 2825 | decode_ARM_machine_flags (unsigned e_flags, char buf[]) |
f3485b74 NC |
2826 | { |
2827 | unsigned eabi; | |
015dc7e1 | 2828 | bool unknown = false; |
f3485b74 NC |
2829 | |
2830 | eabi = EF_ARM_EABI_VERSION (e_flags); | |
2831 | e_flags &= ~ EF_ARM_EABIMASK; | |
2832 | ||
2833 | /* Handle "generic" ARM flags. */ | |
2834 | if (e_flags & EF_ARM_RELEXEC) | |
2835 | { | |
2836 | strcat (buf, ", relocatable executable"); | |
2837 | e_flags &= ~ EF_ARM_RELEXEC; | |
2838 | } | |
76da6bbe | 2839 | |
18a20338 CL |
2840 | if (e_flags & EF_ARM_PIC) |
2841 | { | |
2842 | strcat (buf, ", position independent"); | |
2843 | e_flags &= ~ EF_ARM_PIC; | |
2844 | } | |
2845 | ||
f3485b74 NC |
2846 | /* Now handle EABI specific flags. */ |
2847 | switch (eabi) | |
2848 | { | |
2849 | default: | |
2c71103e | 2850 | strcat (buf, ", <unrecognized EABI>"); |
f3485b74 | 2851 | if (e_flags) |
015dc7e1 | 2852 | unknown = true; |
f3485b74 NC |
2853 | break; |
2854 | ||
2855 | case EF_ARM_EABI_VER1: | |
a5bcd848 | 2856 | strcat (buf, ", Version1 EABI"); |
f3485b74 NC |
2857 | while (e_flags) |
2858 | { | |
2859 | unsigned flag; | |
76da6bbe | 2860 | |
f3485b74 NC |
2861 | /* Process flags one bit at a time. */ |
2862 | flag = e_flags & - e_flags; | |
2863 | e_flags &= ~ flag; | |
76da6bbe | 2864 | |
f3485b74 NC |
2865 | switch (flag) |
2866 | { | |
a5bcd848 | 2867 | case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK. */ |
f3485b74 NC |
2868 | strcat (buf, ", sorted symbol tables"); |
2869 | break; | |
76da6bbe | 2870 | |
f3485b74 | 2871 | default: |
015dc7e1 | 2872 | unknown = true; |
f3485b74 NC |
2873 | break; |
2874 | } | |
2875 | } | |
2876 | break; | |
76da6bbe | 2877 | |
a5bcd848 PB |
2878 | case EF_ARM_EABI_VER2: |
2879 | strcat (buf, ", Version2 EABI"); | |
2880 | while (e_flags) | |
2881 | { | |
2882 | unsigned flag; | |
2883 | ||
2884 | /* Process flags one bit at a time. */ | |
2885 | flag = e_flags & - e_flags; | |
2886 | e_flags &= ~ flag; | |
2887 | ||
2888 | switch (flag) | |
2889 | { | |
2890 | case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK. */ | |
2891 | strcat (buf, ", sorted symbol tables"); | |
2892 | break; | |
2893 | ||
2894 | case EF_ARM_DYNSYMSUSESEGIDX: | |
2895 | strcat (buf, ", dynamic symbols use segment index"); | |
2896 | break; | |
2897 | ||
2898 | case EF_ARM_MAPSYMSFIRST: | |
2899 | strcat (buf, ", mapping symbols precede others"); | |
2900 | break; | |
2901 | ||
2902 | default: | |
015dc7e1 | 2903 | unknown = true; |
a5bcd848 PB |
2904 | break; |
2905 | } | |
2906 | } | |
2907 | break; | |
2908 | ||
d507cf36 PB |
2909 | case EF_ARM_EABI_VER3: |
2910 | strcat (buf, ", Version3 EABI"); | |
8cb51566 PB |
2911 | break; |
2912 | ||
2913 | case EF_ARM_EABI_VER4: | |
2914 | strcat (buf, ", Version4 EABI"); | |
3bfcb652 NC |
2915 | while (e_flags) |
2916 | { | |
2917 | unsigned flag; | |
2918 | ||
2919 | /* Process flags one bit at a time. */ | |
2920 | flag = e_flags & - e_flags; | |
2921 | e_flags &= ~ flag; | |
2922 | ||
2923 | switch (flag) | |
2924 | { | |
2925 | case EF_ARM_BE8: | |
2926 | strcat (buf, ", BE8"); | |
2927 | break; | |
2928 | ||
2929 | case EF_ARM_LE8: | |
2930 | strcat (buf, ", LE8"); | |
2931 | break; | |
2932 | ||
2933 | default: | |
015dc7e1 | 2934 | unknown = true; |
3bfcb652 NC |
2935 | break; |
2936 | } | |
3bfcb652 NC |
2937 | } |
2938 | break; | |
3a4a14e9 PB |
2939 | |
2940 | case EF_ARM_EABI_VER5: | |
2941 | strcat (buf, ", Version5 EABI"); | |
d507cf36 PB |
2942 | while (e_flags) |
2943 | { | |
2944 | unsigned flag; | |
2945 | ||
2946 | /* Process flags one bit at a time. */ | |
2947 | flag = e_flags & - e_flags; | |
2948 | e_flags &= ~ flag; | |
2949 | ||
2950 | switch (flag) | |
2951 | { | |
2952 | case EF_ARM_BE8: | |
2953 | strcat (buf, ", BE8"); | |
2954 | break; | |
2955 | ||
2956 | case EF_ARM_LE8: | |
2957 | strcat (buf, ", LE8"); | |
2958 | break; | |
2959 | ||
3bfcb652 NC |
2960 | case EF_ARM_ABI_FLOAT_SOFT: /* Conflicts with EF_ARM_SOFT_FLOAT. */ |
2961 | strcat (buf, ", soft-float ABI"); | |
2962 | break; | |
2963 | ||
2964 | case EF_ARM_ABI_FLOAT_HARD: /* Conflicts with EF_ARM_VFP_FLOAT. */ | |
2965 | strcat (buf, ", hard-float ABI"); | |
2966 | break; | |
2967 | ||
d507cf36 | 2968 | default: |
015dc7e1 | 2969 | unknown = true; |
d507cf36 PB |
2970 | break; |
2971 | } | |
2972 | } | |
2973 | break; | |
2974 | ||
f3485b74 | 2975 | case EF_ARM_EABI_UNKNOWN: |
a5bcd848 | 2976 | strcat (buf, ", GNU EABI"); |
f3485b74 NC |
2977 | while (e_flags) |
2978 | { | |
2979 | unsigned flag; | |
76da6bbe | 2980 | |
f3485b74 NC |
2981 | /* Process flags one bit at a time. */ |
2982 | flag = e_flags & - e_flags; | |
2983 | e_flags &= ~ flag; | |
76da6bbe | 2984 | |
f3485b74 NC |
2985 | switch (flag) |
2986 | { | |
a5bcd848 | 2987 | case EF_ARM_INTERWORK: |
f3485b74 NC |
2988 | strcat (buf, ", interworking enabled"); |
2989 | break; | |
76da6bbe | 2990 | |
a5bcd848 | 2991 | case EF_ARM_APCS_26: |
f3485b74 NC |
2992 | strcat (buf, ", uses APCS/26"); |
2993 | break; | |
76da6bbe | 2994 | |
a5bcd848 | 2995 | case EF_ARM_APCS_FLOAT: |
f3485b74 NC |
2996 | strcat (buf, ", uses APCS/float"); |
2997 | break; | |
76da6bbe | 2998 | |
a5bcd848 | 2999 | case EF_ARM_PIC: |
f3485b74 NC |
3000 | strcat (buf, ", position independent"); |
3001 | break; | |
76da6bbe | 3002 | |
a5bcd848 | 3003 | case EF_ARM_ALIGN8: |
f3485b74 NC |
3004 | strcat (buf, ", 8 bit structure alignment"); |
3005 | break; | |
76da6bbe | 3006 | |
a5bcd848 | 3007 | case EF_ARM_NEW_ABI: |
f3485b74 NC |
3008 | strcat (buf, ", uses new ABI"); |
3009 | break; | |
76da6bbe | 3010 | |
a5bcd848 | 3011 | case EF_ARM_OLD_ABI: |
f3485b74 NC |
3012 | strcat (buf, ", uses old ABI"); |
3013 | break; | |
76da6bbe | 3014 | |
a5bcd848 | 3015 | case EF_ARM_SOFT_FLOAT: |
f3485b74 NC |
3016 | strcat (buf, ", software FP"); |
3017 | break; | |
76da6bbe | 3018 | |
90e01f86 ILT |
3019 | case EF_ARM_VFP_FLOAT: |
3020 | strcat (buf, ", VFP"); | |
3021 | break; | |
3022 | ||
fde78edd NC |
3023 | case EF_ARM_MAVERICK_FLOAT: |
3024 | strcat (buf, ", Maverick FP"); | |
3025 | break; | |
3026 | ||
f3485b74 | 3027 | default: |
015dc7e1 | 3028 | unknown = true; |
f3485b74 NC |
3029 | break; |
3030 | } | |
3031 | } | |
3032 | } | |
f3485b74 NC |
3033 | |
3034 | if (unknown) | |
2b692964 | 3035 | strcat (buf,_(", <unknown>")); |
f3485b74 NC |
3036 | } |
3037 | ||
343433df AB |
3038 | static void |
3039 | decode_AVR_machine_flags (unsigned e_flags, char buf[], size_t size) | |
3040 | { | |
3041 | --size; /* Leave space for null terminator. */ | |
3042 | ||
3043 | switch (e_flags & EF_AVR_MACH) | |
3044 | { | |
3045 | case E_AVR_MACH_AVR1: | |
3046 | strncat (buf, ", avr:1", size); | |
3047 | break; | |
3048 | case E_AVR_MACH_AVR2: | |
3049 | strncat (buf, ", avr:2", size); | |
3050 | break; | |
3051 | case E_AVR_MACH_AVR25: | |
3052 | strncat (buf, ", avr:25", size); | |
3053 | break; | |
3054 | case E_AVR_MACH_AVR3: | |
3055 | strncat (buf, ", avr:3", size); | |
3056 | break; | |
3057 | case E_AVR_MACH_AVR31: | |
3058 | strncat (buf, ", avr:31", size); | |
3059 | break; | |
3060 | case E_AVR_MACH_AVR35: | |
3061 | strncat (buf, ", avr:35", size); | |
3062 | break; | |
3063 | case E_AVR_MACH_AVR4: | |
3064 | strncat (buf, ", avr:4", size); | |
3065 | break; | |
3066 | case E_AVR_MACH_AVR5: | |
3067 | strncat (buf, ", avr:5", size); | |
3068 | break; | |
3069 | case E_AVR_MACH_AVR51: | |
3070 | strncat (buf, ", avr:51", size); | |
3071 | break; | |
3072 | case E_AVR_MACH_AVR6: | |
3073 | strncat (buf, ", avr:6", size); | |
3074 | break; | |
3075 | case E_AVR_MACH_AVRTINY: | |
3076 | strncat (buf, ", avr:100", size); | |
3077 | break; | |
3078 | case E_AVR_MACH_XMEGA1: | |
3079 | strncat (buf, ", avr:101", size); | |
3080 | break; | |
3081 | case E_AVR_MACH_XMEGA2: | |
3082 | strncat (buf, ", avr:102", size); | |
3083 | break; | |
3084 | case E_AVR_MACH_XMEGA3: | |
3085 | strncat (buf, ", avr:103", size); | |
3086 | break; | |
3087 | case E_AVR_MACH_XMEGA4: | |
3088 | strncat (buf, ", avr:104", size); | |
3089 | break; | |
3090 | case E_AVR_MACH_XMEGA5: | |
3091 | strncat (buf, ", avr:105", size); | |
3092 | break; | |
3093 | case E_AVR_MACH_XMEGA6: | |
3094 | strncat (buf, ", avr:106", size); | |
3095 | break; | |
3096 | case E_AVR_MACH_XMEGA7: | |
3097 | strncat (buf, ", avr:107", size); | |
3098 | break; | |
3099 | default: | |
3100 | strncat (buf, ", avr:<unknown>", size); | |
3101 | break; | |
3102 | } | |
3103 | ||
3104 | size -= strlen (buf); | |
3105 | if (e_flags & EF_AVR_LINKRELAX_PREPARED) | |
3106 | strncat (buf, ", link-relax", size); | |
3107 | } | |
3108 | ||
35c08157 KLC |
3109 | static void |
3110 | decode_NDS32_machine_flags (unsigned e_flags, char buf[], size_t size) | |
3111 | { | |
3112 | unsigned abi; | |
3113 | unsigned arch; | |
3114 | unsigned config; | |
3115 | unsigned version; | |
015dc7e1 | 3116 | bool has_fpu = false; |
32ec8896 | 3117 | unsigned int r = 0; |
35c08157 KLC |
3118 | |
3119 | static const char *ABI_STRINGS[] = | |
3120 | { | |
3121 | "ABI v0", /* use r5 as return register; only used in N1213HC */ | |
3122 | "ABI v1", /* use r0 as return register */ | |
3123 | "ABI v2", /* use r0 as return register and don't reserve 24 bytes for arguments */ | |
3124 | "ABI v2fp", /* for FPU */ | |
40c7a7cb KLC |
3125 | "AABI", |
3126 | "ABI2 FP+" | |
35c08157 KLC |
3127 | }; |
3128 | static const char *VER_STRINGS[] = | |
3129 | { | |
3130 | "Andes ELF V1.3 or older", | |
3131 | "Andes ELF V1.3.1", | |
3132 | "Andes ELF V1.4" | |
3133 | }; | |
3134 | static const char *ARCH_STRINGS[] = | |
3135 | { | |
3136 | "", | |
3137 | "Andes Star v1.0", | |
3138 | "Andes Star v2.0", | |
3139 | "Andes Star v3.0", | |
3140 | "Andes Star v3.0m" | |
3141 | }; | |
3142 | ||
3143 | abi = EF_NDS_ABI & e_flags; | |
3144 | arch = EF_NDS_ARCH & e_flags; | |
3145 | config = EF_NDS_INST & e_flags; | |
3146 | version = EF_NDS32_ELF_VERSION & e_flags; | |
3147 | ||
3148 | memset (buf, 0, size); | |
3149 | ||
3150 | switch (abi) | |
3151 | { | |
3152 | case E_NDS_ABI_V0: | |
3153 | case E_NDS_ABI_V1: | |
3154 | case E_NDS_ABI_V2: | |
3155 | case E_NDS_ABI_V2FP: | |
3156 | case E_NDS_ABI_AABI: | |
40c7a7cb | 3157 | case E_NDS_ABI_V2FP_PLUS: |
35c08157 KLC |
3158 | /* In case there are holes in the array. */ |
3159 | r += snprintf (buf + r, size - r, ", %s", ABI_STRINGS[abi >> EF_NDS_ABI_SHIFT]); | |
3160 | break; | |
3161 | ||
3162 | default: | |
3163 | r += snprintf (buf + r, size - r, ", <unrecognized ABI>"); | |
3164 | break; | |
3165 | } | |
3166 | ||
3167 | switch (version) | |
3168 | { | |
3169 | case E_NDS32_ELF_VER_1_2: | |
3170 | case E_NDS32_ELF_VER_1_3: | |
3171 | case E_NDS32_ELF_VER_1_4: | |
3172 | r += snprintf (buf + r, size - r, ", %s", VER_STRINGS[version >> EF_NDS32_ELF_VERSION_SHIFT]); | |
3173 | break; | |
3174 | ||
3175 | default: | |
3176 | r += snprintf (buf + r, size - r, ", <unrecognized ELF version number>"); | |
3177 | break; | |
3178 | } | |
3179 | ||
3180 | if (E_NDS_ABI_V0 == abi) | |
3181 | { | |
3182 | /* OLD ABI; only used in N1213HC, has performance extension 1. */ | |
3183 | r += snprintf (buf + r, size - r, ", Andes Star v1.0, N1213HC, MAC, PERF1"); | |
3184 | if (arch == E_NDS_ARCH_STAR_V1_0) | |
3185 | r += snprintf (buf + r, size -r, ", 16b"); /* has 16-bit instructions */ | |
3186 | return; | |
3187 | } | |
3188 | ||
3189 | switch (arch) | |
3190 | { | |
3191 | case E_NDS_ARCH_STAR_V1_0: | |
3192 | case E_NDS_ARCH_STAR_V2_0: | |
3193 | case E_NDS_ARCH_STAR_V3_0: | |
3194 | case E_NDS_ARCH_STAR_V3_M: | |
3195 | r += snprintf (buf + r, size - r, ", %s", ARCH_STRINGS[arch >> EF_NDS_ARCH_SHIFT]); | |
3196 | break; | |
3197 | ||
3198 | default: | |
3199 | r += snprintf (buf + r, size - r, ", <unrecognized architecture>"); | |
3200 | /* ARCH version determines how the e_flags are interpreted. | |
3201 | If it is unknown, we cannot proceed. */ | |
3202 | return; | |
3203 | } | |
3204 | ||
3205 | /* Newer ABI; Now handle architecture specific flags. */ | |
3206 | if (arch == E_NDS_ARCH_STAR_V1_0) | |
3207 | { | |
3208 | if (config & E_NDS32_HAS_MFUSR_PC_INST) | |
3209 | r += snprintf (buf + r, size -r, ", MFUSR_PC"); | |
3210 | ||
3211 | if (!(config & E_NDS32_HAS_NO_MAC_INST)) | |
3212 | r += snprintf (buf + r, size -r, ", MAC"); | |
3213 | ||
3214 | if (config & E_NDS32_HAS_DIV_INST) | |
3215 | r += snprintf (buf + r, size -r, ", DIV"); | |
3216 | ||
3217 | if (config & E_NDS32_HAS_16BIT_INST) | |
3218 | r += snprintf (buf + r, size -r, ", 16b"); | |
3219 | } | |
3220 | else | |
3221 | { | |
3222 | if (config & E_NDS32_HAS_MFUSR_PC_INST) | |
3223 | { | |
3224 | if (version <= E_NDS32_ELF_VER_1_3) | |
3225 | r += snprintf (buf + r, size -r, ", [B8]"); | |
3226 | else | |
3227 | r += snprintf (buf + r, size -r, ", EX9"); | |
3228 | } | |
3229 | ||
3230 | if (config & E_NDS32_HAS_MAC_DX_INST) | |
3231 | r += snprintf (buf + r, size -r, ", MAC_DX"); | |
3232 | ||
3233 | if (config & E_NDS32_HAS_DIV_DX_INST) | |
3234 | r += snprintf (buf + r, size -r, ", DIV_DX"); | |
3235 | ||
3236 | if (config & E_NDS32_HAS_16BIT_INST) | |
3237 | { | |
3238 | if (version <= E_NDS32_ELF_VER_1_3) | |
3239 | r += snprintf (buf + r, size -r, ", 16b"); | |
3240 | else | |
3241 | r += snprintf (buf + r, size -r, ", IFC"); | |
3242 | } | |
3243 | } | |
3244 | ||
3245 | if (config & E_NDS32_HAS_EXT_INST) | |
3246 | r += snprintf (buf + r, size -r, ", PERF1"); | |
3247 | ||
3248 | if (config & E_NDS32_HAS_EXT2_INST) | |
3249 | r += snprintf (buf + r, size -r, ", PERF2"); | |
3250 | ||
3251 | if (config & E_NDS32_HAS_FPU_INST) | |
3252 | { | |
015dc7e1 | 3253 | has_fpu = true; |
35c08157 KLC |
3254 | r += snprintf (buf + r, size -r, ", FPU_SP"); |
3255 | } | |
3256 | ||
3257 | if (config & E_NDS32_HAS_FPU_DP_INST) | |
3258 | { | |
015dc7e1 | 3259 | has_fpu = true; |
35c08157 KLC |
3260 | r += snprintf (buf + r, size -r, ", FPU_DP"); |
3261 | } | |
3262 | ||
3263 | if (config & E_NDS32_HAS_FPU_MAC_INST) | |
3264 | { | |
015dc7e1 | 3265 | has_fpu = true; |
35c08157 KLC |
3266 | r += snprintf (buf + r, size -r, ", FPU_MAC"); |
3267 | } | |
3268 | ||
3269 | if (has_fpu) | |
3270 | { | |
3271 | switch ((config & E_NDS32_FPU_REG_CONF) >> E_NDS32_FPU_REG_CONF_SHIFT) | |
3272 | { | |
3273 | case E_NDS32_FPU_REG_8SP_4DP: | |
3274 | r += snprintf (buf + r, size -r, ", FPU_REG:8/4"); | |
3275 | break; | |
3276 | case E_NDS32_FPU_REG_16SP_8DP: | |
3277 | r += snprintf (buf + r, size -r, ", FPU_REG:16/8"); | |
3278 | break; | |
3279 | case E_NDS32_FPU_REG_32SP_16DP: | |
3280 | r += snprintf (buf + r, size -r, ", FPU_REG:32/16"); | |
3281 | break; | |
3282 | case E_NDS32_FPU_REG_32SP_32DP: | |
3283 | r += snprintf (buf + r, size -r, ", FPU_REG:32/32"); | |
3284 | break; | |
3285 | } | |
3286 | } | |
3287 | ||
3288 | if (config & E_NDS32_HAS_AUDIO_INST) | |
3289 | r += snprintf (buf + r, size -r, ", AUDIO"); | |
3290 | ||
3291 | if (config & E_NDS32_HAS_STRING_INST) | |
3292 | r += snprintf (buf + r, size -r, ", STR"); | |
3293 | ||
3294 | if (config & E_NDS32_HAS_REDUCED_REGS) | |
3295 | r += snprintf (buf + r, size -r, ", 16REG"); | |
3296 | ||
3297 | if (config & E_NDS32_HAS_VIDEO_INST) | |
3298 | { | |
3299 | if (version <= E_NDS32_ELF_VER_1_3) | |
3300 | r += snprintf (buf + r, size -r, ", VIDEO"); | |
3301 | else | |
3302 | r += snprintf (buf + r, size -r, ", SATURATION"); | |
3303 | } | |
3304 | ||
3305 | if (config & E_NDS32_HAS_ENCRIPT_INST) | |
3306 | r += snprintf (buf + r, size -r, ", ENCRP"); | |
3307 | ||
3308 | if (config & E_NDS32_HAS_L2C_INST) | |
3309 | r += snprintf (buf + r, size -r, ", L2C"); | |
3310 | } | |
3311 | ||
252b5132 | 3312 | static char * |
dda8d76d | 3313 | get_machine_flags (Filedata * filedata, unsigned e_flags, unsigned e_machine) |
252b5132 | 3314 | { |
b34976b6 | 3315 | static char buf[1024]; |
252b5132 RH |
3316 | |
3317 | buf[0] = '\0'; | |
76da6bbe | 3318 | |
252b5132 RH |
3319 | if (e_flags) |
3320 | { | |
3321 | switch (e_machine) | |
3322 | { | |
3323 | default: | |
3324 | break; | |
3325 | ||
886a2506 | 3326 | case EM_ARC_COMPACT2: |
886a2506 | 3327 | case EM_ARC_COMPACT: |
a9522a21 AB |
3328 | decode_ARC_machine_flags (e_flags, e_machine, buf); |
3329 | break; | |
886a2506 | 3330 | |
f3485b74 NC |
3331 | case EM_ARM: |
3332 | decode_ARM_machine_flags (e_flags, buf); | |
3333 | break; | |
76da6bbe | 3334 | |
343433df AB |
3335 | case EM_AVR: |
3336 | decode_AVR_machine_flags (e_flags, buf, sizeof buf); | |
3337 | break; | |
3338 | ||
781303ce MF |
3339 | case EM_BLACKFIN: |
3340 | if (e_flags & EF_BFIN_PIC) | |
3341 | strcat (buf, ", PIC"); | |
3342 | ||
3343 | if (e_flags & EF_BFIN_FDPIC) | |
3344 | strcat (buf, ", FDPIC"); | |
3345 | ||
3346 | if (e_flags & EF_BFIN_CODE_IN_L1) | |
3347 | strcat (buf, ", code in L1"); | |
3348 | ||
3349 | if (e_flags & EF_BFIN_DATA_IN_L1) | |
3350 | strcat (buf, ", data in L1"); | |
3351 | ||
3352 | break; | |
3353 | ||
ec2dfb42 AO |
3354 | case EM_CYGNUS_FRV: |
3355 | switch (e_flags & EF_FRV_CPU_MASK) | |
3356 | { | |
3357 | case EF_FRV_CPU_GENERIC: | |
3358 | break; | |
3359 | ||
3360 | default: | |
3361 | strcat (buf, ", fr???"); | |
3362 | break; | |
57346661 | 3363 | |
ec2dfb42 AO |
3364 | case EF_FRV_CPU_FR300: |
3365 | strcat (buf, ", fr300"); | |
3366 | break; | |
3367 | ||
3368 | case EF_FRV_CPU_FR400: | |
3369 | strcat (buf, ", fr400"); | |
3370 | break; | |
3371 | case EF_FRV_CPU_FR405: | |
3372 | strcat (buf, ", fr405"); | |
3373 | break; | |
3374 | ||
3375 | case EF_FRV_CPU_FR450: | |
3376 | strcat (buf, ", fr450"); | |
3377 | break; | |
3378 | ||
3379 | case EF_FRV_CPU_FR500: | |
3380 | strcat (buf, ", fr500"); | |
3381 | break; | |
3382 | case EF_FRV_CPU_FR550: | |
3383 | strcat (buf, ", fr550"); | |
3384 | break; | |
3385 | ||
3386 | case EF_FRV_CPU_SIMPLE: | |
3387 | strcat (buf, ", simple"); | |
3388 | break; | |
3389 | case EF_FRV_CPU_TOMCAT: | |
3390 | strcat (buf, ", tomcat"); | |
3391 | break; | |
3392 | } | |
1c877e87 | 3393 | break; |
ec2dfb42 | 3394 | |
53c7db4b | 3395 | case EM_68K: |
425c6cb0 | 3396 | if ((e_flags & EF_M68K_ARCH_MASK) == EF_M68K_M68000) |
76f57f3a | 3397 | strcat (buf, ", m68000"); |
425c6cb0 | 3398 | else if ((e_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32) |
3bdcfdf4 KH |
3399 | strcat (buf, ", cpu32"); |
3400 | else if ((e_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO) | |
3401 | strcat (buf, ", fido_a"); | |
425c6cb0 | 3402 | else |
266abb8f | 3403 | { |
2cf0635d NC |
3404 | char const * isa = _("unknown"); |
3405 | char const * mac = _("unknown mac"); | |
3406 | char const * additional = NULL; | |
0112cd26 | 3407 | |
c694fd50 | 3408 | switch (e_flags & EF_M68K_CF_ISA_MASK) |
266abb8f | 3409 | { |
c694fd50 | 3410 | case EF_M68K_CF_ISA_A_NODIV: |
0b2e31dc NS |
3411 | isa = "A"; |
3412 | additional = ", nodiv"; | |
3413 | break; | |
c694fd50 | 3414 | case EF_M68K_CF_ISA_A: |
266abb8f NS |
3415 | isa = "A"; |
3416 | break; | |
c694fd50 | 3417 | case EF_M68K_CF_ISA_A_PLUS: |
266abb8f NS |
3418 | isa = "A+"; |
3419 | break; | |
c694fd50 | 3420 | case EF_M68K_CF_ISA_B_NOUSP: |
0b2e31dc NS |
3421 | isa = "B"; |
3422 | additional = ", nousp"; | |
3423 | break; | |
c694fd50 | 3424 | case EF_M68K_CF_ISA_B: |
266abb8f NS |
3425 | isa = "B"; |
3426 | break; | |
f608cd77 NS |
3427 | case EF_M68K_CF_ISA_C: |
3428 | isa = "C"; | |
3429 | break; | |
3430 | case EF_M68K_CF_ISA_C_NODIV: | |
3431 | isa = "C"; | |
3432 | additional = ", nodiv"; | |
3433 | break; | |
266abb8f NS |
3434 | } |
3435 | strcat (buf, ", cf, isa "); | |
3436 | strcat (buf, isa); | |
0b2e31dc NS |
3437 | if (additional) |
3438 | strcat (buf, additional); | |
c694fd50 | 3439 | if (e_flags & EF_M68K_CF_FLOAT) |
0b2e31dc | 3440 | strcat (buf, ", float"); |
c694fd50 | 3441 | switch (e_flags & EF_M68K_CF_MAC_MASK) |
266abb8f NS |
3442 | { |
3443 | case 0: | |
3444 | mac = NULL; | |
3445 | break; | |
c694fd50 | 3446 | case EF_M68K_CF_MAC: |
266abb8f NS |
3447 | mac = "mac"; |
3448 | break; | |
c694fd50 | 3449 | case EF_M68K_CF_EMAC: |
266abb8f NS |
3450 | mac = "emac"; |
3451 | break; | |
f608cd77 NS |
3452 | case EF_M68K_CF_EMAC_B: |
3453 | mac = "emac_b"; | |
3454 | break; | |
266abb8f NS |
3455 | } |
3456 | if (mac) | |
3457 | { | |
3458 | strcat (buf, ", "); | |
3459 | strcat (buf, mac); | |
3460 | } | |
266abb8f | 3461 | } |
53c7db4b | 3462 | break; |
33c63f9d | 3463 | |
153a2776 NC |
3464 | case EM_CYGNUS_MEP: |
3465 | switch (e_flags & EF_MEP_CPU_MASK) | |
3466 | { | |
3467 | case EF_MEP_CPU_MEP: strcat (buf, ", generic MeP"); break; | |
3468 | case EF_MEP_CPU_C2: strcat (buf, ", MeP C2"); break; | |
3469 | case EF_MEP_CPU_C3: strcat (buf, ", MeP C3"); break; | |
3470 | case EF_MEP_CPU_C4: strcat (buf, ", MeP C4"); break; | |
3471 | case EF_MEP_CPU_C5: strcat (buf, ", MeP C5"); break; | |
3472 | case EF_MEP_CPU_H1: strcat (buf, ", MeP H1"); break; | |
3473 | default: strcat (buf, _(", <unknown MeP cpu type>")); break; | |
3474 | } | |
3475 | ||
3476 | switch (e_flags & EF_MEP_COP_MASK) | |
3477 | { | |
3478 | case EF_MEP_COP_NONE: break; | |
3479 | case EF_MEP_COP_AVC: strcat (buf, ", AVC coprocessor"); break; | |
3480 | case EF_MEP_COP_AVC2: strcat (buf, ", AVC2 coprocessor"); break; | |
3481 | case EF_MEP_COP_FMAX: strcat (buf, ", FMAX coprocessor"); break; | |
3482 | case EF_MEP_COP_IVC2: strcat (buf, ", IVC2 coprocessor"); break; | |
3483 | default: strcat (buf, _("<unknown MeP copro type>")); break; | |
3484 | } | |
3485 | ||
3486 | if (e_flags & EF_MEP_LIBRARY) | |
3487 | strcat (buf, ", Built for Library"); | |
3488 | ||
3489 | if (e_flags & EF_MEP_INDEX_MASK) | |
3490 | sprintf (buf + strlen (buf), ", Configuration Index: %#x", | |
3491 | e_flags & EF_MEP_INDEX_MASK); | |
3492 | ||
3493 | if (e_flags & ~ EF_MEP_ALL_FLAGS) | |
3494 | sprintf (buf + strlen (buf), _(", unknown flags bits: %#x"), | |
3495 | e_flags & ~ EF_MEP_ALL_FLAGS); | |
3496 | break; | |
3497 | ||
252b5132 RH |
3498 | case EM_PPC: |
3499 | if (e_flags & EF_PPC_EMB) | |
3500 | strcat (buf, ", emb"); | |
3501 | ||
3502 | if (e_flags & EF_PPC_RELOCATABLE) | |
2b692964 | 3503 | strcat (buf, _(", relocatable")); |
252b5132 RH |
3504 | |
3505 | if (e_flags & EF_PPC_RELOCATABLE_LIB) | |
2b692964 | 3506 | strcat (buf, _(", relocatable-lib")); |
252b5132 RH |
3507 | break; |
3508 | ||
ee67d69a AM |
3509 | case EM_PPC64: |
3510 | if (e_flags & EF_PPC64_ABI) | |
3511 | { | |
3512 | char abi[] = ", abiv0"; | |
3513 | ||
3514 | abi[6] += e_flags & EF_PPC64_ABI; | |
3515 | strcat (buf, abi); | |
3516 | } | |
3517 | break; | |
3518 | ||
708e2187 NC |
3519 | case EM_V800: |
3520 | if ((e_flags & EF_RH850_ABI) == EF_RH850_ABI) | |
3521 | strcat (buf, ", RH850 ABI"); | |
0b4362b0 | 3522 | |
708e2187 NC |
3523 | if (e_flags & EF_V800_850E3) |
3524 | strcat (buf, ", V3 architecture"); | |
3525 | ||
3526 | if ((e_flags & (EF_RH850_FPU_DOUBLE | EF_RH850_FPU_SINGLE)) == 0) | |
3527 | strcat (buf, ", FPU not used"); | |
3528 | ||
3529 | if ((e_flags & (EF_RH850_REGMODE22 | EF_RH850_REGMODE32)) == 0) | |
3530 | strcat (buf, ", regmode: COMMON"); | |
3531 | ||
3532 | if ((e_flags & (EF_RH850_GP_FIX | EF_RH850_GP_NOFIX)) == 0) | |
3533 | strcat (buf, ", r4 not used"); | |
3534 | ||
3535 | if ((e_flags & (EF_RH850_EP_FIX | EF_RH850_EP_NOFIX)) == 0) | |
3536 | strcat (buf, ", r30 not used"); | |
3537 | ||
3538 | if ((e_flags & (EF_RH850_TP_FIX | EF_RH850_TP_NOFIX)) == 0) | |
3539 | strcat (buf, ", r5 not used"); | |
3540 | ||
3541 | if ((e_flags & (EF_RH850_REG2_RESERVE | EF_RH850_REG2_NORESERVE)) == 0) | |
3542 | strcat (buf, ", r2 not used"); | |
3543 | ||
3544 | for (e_flags &= 0xFFFF; e_flags; e_flags &= ~ (e_flags & - e_flags)) | |
3545 | { | |
3546 | switch (e_flags & - e_flags) | |
3547 | { | |
3548 | case EF_RH850_FPU_DOUBLE: strcat (buf, ", double precision FPU"); break; | |
3549 | case EF_RH850_FPU_SINGLE: strcat (buf, ", single precision FPU"); break; | |
708e2187 NC |
3550 | case EF_RH850_REGMODE22: strcat (buf, ", regmode:22"); break; |
3551 | case EF_RH850_REGMODE32: strcat (buf, ", regmode:23"); break; | |
708e2187 NC |
3552 | case EF_RH850_GP_FIX: strcat (buf, ", r4 fixed"); break; |
3553 | case EF_RH850_GP_NOFIX: strcat (buf, ", r4 free"); break; | |
3554 | case EF_RH850_EP_FIX: strcat (buf, ", r30 fixed"); break; | |
3555 | case EF_RH850_EP_NOFIX: strcat (buf, ", r30 free"); break; | |
3556 | case EF_RH850_TP_FIX: strcat (buf, ", r5 fixed"); break; | |
3557 | case EF_RH850_TP_NOFIX: strcat (buf, ", r5 free"); break; | |
3558 | case EF_RH850_REG2_RESERVE: strcat (buf, ", r2 fixed"); break; | |
3559 | case EF_RH850_REG2_NORESERVE: strcat (buf, ", r2 free"); break; | |
3560 | default: break; | |
3561 | } | |
3562 | } | |
3563 | break; | |
3564 | ||
2b0337b0 | 3565 | case EM_V850: |
252b5132 RH |
3566 | case EM_CYGNUS_V850: |
3567 | switch (e_flags & EF_V850_ARCH) | |
3568 | { | |
78c8d46c NC |
3569 | case E_V850E3V5_ARCH: |
3570 | strcat (buf, ", v850e3v5"); | |
3571 | break; | |
1cd986c5 NC |
3572 | case E_V850E2V3_ARCH: |
3573 | strcat (buf, ", v850e2v3"); | |
3574 | break; | |
3575 | case E_V850E2_ARCH: | |
3576 | strcat (buf, ", v850e2"); | |
3577 | break; | |
3578 | case E_V850E1_ARCH: | |
3579 | strcat (buf, ", v850e1"); | |
8ad30312 | 3580 | break; |
252b5132 RH |
3581 | case E_V850E_ARCH: |
3582 | strcat (buf, ", v850e"); | |
3583 | break; | |
252b5132 RH |
3584 | case E_V850_ARCH: |
3585 | strcat (buf, ", v850"); | |
3586 | break; | |
3587 | default: | |
2b692964 | 3588 | strcat (buf, _(", unknown v850 architecture variant")); |
252b5132 RH |
3589 | break; |
3590 | } | |
3591 | break; | |
3592 | ||
2b0337b0 | 3593 | case EM_M32R: |
252b5132 RH |
3594 | case EM_CYGNUS_M32R: |
3595 | if ((e_flags & EF_M32R_ARCH) == E_M32R_ARCH) | |
3596 | strcat (buf, ", m32r"); | |
252b5132 RH |
3597 | break; |
3598 | ||
3599 | case EM_MIPS: | |
4fe85591 | 3600 | case EM_MIPS_RS3_LE: |
252b5132 RH |
3601 | if (e_flags & EF_MIPS_NOREORDER) |
3602 | strcat (buf, ", noreorder"); | |
3603 | ||
3604 | if (e_flags & EF_MIPS_PIC) | |
3605 | strcat (buf, ", pic"); | |
3606 | ||
3607 | if (e_flags & EF_MIPS_CPIC) | |
3608 | strcat (buf, ", cpic"); | |
3609 | ||
d1bdd336 TS |
3610 | if (e_flags & EF_MIPS_UCODE) |
3611 | strcat (buf, ", ugen_reserved"); | |
3612 | ||
252b5132 RH |
3613 | if (e_flags & EF_MIPS_ABI2) |
3614 | strcat (buf, ", abi2"); | |
3615 | ||
43521d43 TS |
3616 | if (e_flags & EF_MIPS_OPTIONS_FIRST) |
3617 | strcat (buf, ", odk first"); | |
3618 | ||
a5d22d2a TS |
3619 | if (e_flags & EF_MIPS_32BITMODE) |
3620 | strcat (buf, ", 32bitmode"); | |
3621 | ||
ba92f887 MR |
3622 | if (e_flags & EF_MIPS_NAN2008) |
3623 | strcat (buf, ", nan2008"); | |
3624 | ||
fef1b0b3 SE |
3625 | if (e_flags & EF_MIPS_FP64) |
3626 | strcat (buf, ", fp64"); | |
3627 | ||
156c2f8b NC |
3628 | switch ((e_flags & EF_MIPS_MACH)) |
3629 | { | |
3630 | case E_MIPS_MACH_3900: strcat (buf, ", 3900"); break; | |
3631 | case E_MIPS_MACH_4010: strcat (buf, ", 4010"); break; | |
3632 | case E_MIPS_MACH_4100: strcat (buf, ", 4100"); break; | |
156c2f8b | 3633 | case E_MIPS_MACH_4111: strcat (buf, ", 4111"); break; |
810dfa6e L |
3634 | case E_MIPS_MACH_4120: strcat (buf, ", 4120"); break; |
3635 | case E_MIPS_MACH_4650: strcat (buf, ", 4650"); break; | |
3636 | case E_MIPS_MACH_5400: strcat (buf, ", 5400"); break; | |
3637 | case E_MIPS_MACH_5500: strcat (buf, ", 5500"); break; | |
ef272caa | 3638 | case E_MIPS_MACH_5900: strcat (buf, ", 5900"); break; |
c6c98b38 | 3639 | case E_MIPS_MACH_SB1: strcat (buf, ", sb1"); break; |
ebcb91b7 | 3640 | case E_MIPS_MACH_9000: strcat (buf, ", 9000"); break; |
350cc38d MS |
3641 | case E_MIPS_MACH_LS2E: strcat (buf, ", loongson-2e"); break; |
3642 | case E_MIPS_MACH_LS2F: strcat (buf, ", loongson-2f"); break; | |
ac8cb70f | 3643 | case E_MIPS_MACH_GS464: strcat (buf, ", gs464"); break; |
bd782c07 | 3644 | case E_MIPS_MACH_GS464E: strcat (buf, ", gs464e"); break; |
9108bc33 | 3645 | case E_MIPS_MACH_GS264E: strcat (buf, ", gs264e"); break; |
05c6f050 | 3646 | case E_MIPS_MACH_OCTEON: strcat (buf, ", octeon"); break; |
67c2a3e8 | 3647 | case E_MIPS_MACH_OCTEON2: strcat (buf, ", octeon2"); break; |
d32e5c54 | 3648 | case E_MIPS_MACH_OCTEON3: strcat (buf, ", octeon3"); break; |
52b6b6b9 | 3649 | case E_MIPS_MACH_XLR: strcat (buf, ", xlr"); break; |
38bf472a | 3650 | case E_MIPS_MACH_IAMR2: strcat (buf, ", interaptiv-mr2"); break; |
43521d43 TS |
3651 | case 0: |
3652 | /* We simply ignore the field in this case to avoid confusion: | |
3653 | MIPS ELF does not specify EF_MIPS_MACH, it is a GNU | |
3654 | extension. */ | |
3655 | break; | |
2b692964 | 3656 | default: strcat (buf, _(", unknown CPU")); break; |
156c2f8b | 3657 | } |
43521d43 TS |
3658 | |
3659 | switch ((e_flags & EF_MIPS_ABI)) | |
3660 | { | |
3661 | case E_MIPS_ABI_O32: strcat (buf, ", o32"); break; | |
3662 | case E_MIPS_ABI_O64: strcat (buf, ", o64"); break; | |
3663 | case E_MIPS_ABI_EABI32: strcat (buf, ", eabi32"); break; | |
3664 | case E_MIPS_ABI_EABI64: strcat (buf, ", eabi64"); break; | |
3665 | case 0: | |
3666 | /* We simply ignore the field in this case to avoid confusion: | |
3667 | MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension. | |
3668 | This means it is likely to be an o32 file, but not for | |
3669 | sure. */ | |
3670 | break; | |
2b692964 | 3671 | default: strcat (buf, _(", unknown ABI")); break; |
43521d43 TS |
3672 | } |
3673 | ||
3674 | if (e_flags & EF_MIPS_ARCH_ASE_MDMX) | |
3675 | strcat (buf, ", mdmx"); | |
3676 | ||
3677 | if (e_flags & EF_MIPS_ARCH_ASE_M16) | |
3678 | strcat (buf, ", mips16"); | |
3679 | ||
df58fc94 RS |
3680 | if (e_flags & EF_MIPS_ARCH_ASE_MICROMIPS) |
3681 | strcat (buf, ", micromips"); | |
3682 | ||
43521d43 TS |
3683 | switch ((e_flags & EF_MIPS_ARCH)) |
3684 | { | |
3685 | case E_MIPS_ARCH_1: strcat (buf, ", mips1"); break; | |
3686 | case E_MIPS_ARCH_2: strcat (buf, ", mips2"); break; | |
3687 | case E_MIPS_ARCH_3: strcat (buf, ", mips3"); break; | |
3688 | case E_MIPS_ARCH_4: strcat (buf, ", mips4"); break; | |
3689 | case E_MIPS_ARCH_5: strcat (buf, ", mips5"); break; | |
3690 | case E_MIPS_ARCH_32: strcat (buf, ", mips32"); break; | |
cb44e358 | 3691 | case E_MIPS_ARCH_32R2: strcat (buf, ", mips32r2"); break; |
7361da2c | 3692 | case E_MIPS_ARCH_32R6: strcat (buf, ", mips32r6"); break; |
43521d43 | 3693 | case E_MIPS_ARCH_64: strcat (buf, ", mips64"); break; |
5f74bc13 | 3694 | case E_MIPS_ARCH_64R2: strcat (buf, ", mips64r2"); break; |
7361da2c | 3695 | case E_MIPS_ARCH_64R6: strcat (buf, ", mips64r6"); break; |
2b692964 | 3696 | default: strcat (buf, _(", unknown ISA")); break; |
43521d43 | 3697 | } |
252b5132 | 3698 | break; |
351b4b40 | 3699 | |
35c08157 KLC |
3700 | case EM_NDS32: |
3701 | decode_NDS32_machine_flags (e_flags, buf, sizeof buf); | |
3702 | break; | |
3703 | ||
fe944acf FT |
3704 | case EM_NFP: |
3705 | switch (EF_NFP_MACH (e_flags)) | |
3706 | { | |
3707 | case E_NFP_MACH_3200: | |
3708 | strcat (buf, ", NFP-32xx"); | |
3709 | break; | |
3710 | case E_NFP_MACH_6000: | |
3711 | strcat (buf, ", NFP-6xxx"); | |
3712 | break; | |
3713 | } | |
3714 | break; | |
3715 | ||
e23eba97 NC |
3716 | case EM_RISCV: |
3717 | if (e_flags & EF_RISCV_RVC) | |
3718 | strcat (buf, ", RVC"); | |
2922d21d | 3719 | |
7f999549 JW |
3720 | if (e_flags & EF_RISCV_RVE) |
3721 | strcat (buf, ", RVE"); | |
3722 | ||
2922d21d AW |
3723 | switch (e_flags & EF_RISCV_FLOAT_ABI) |
3724 | { | |
3725 | case EF_RISCV_FLOAT_ABI_SOFT: | |
3726 | strcat (buf, ", soft-float ABI"); | |
3727 | break; | |
3728 | ||
3729 | case EF_RISCV_FLOAT_ABI_SINGLE: | |
3730 | strcat (buf, ", single-float ABI"); | |
3731 | break; | |
3732 | ||
3733 | case EF_RISCV_FLOAT_ABI_DOUBLE: | |
3734 | strcat (buf, ", double-float ABI"); | |
3735 | break; | |
3736 | ||
3737 | case EF_RISCV_FLOAT_ABI_QUAD: | |
3738 | strcat (buf, ", quad-float ABI"); | |
3739 | break; | |
3740 | } | |
e23eba97 NC |
3741 | break; |
3742 | ||
ccde1100 AO |
3743 | case EM_SH: |
3744 | switch ((e_flags & EF_SH_MACH_MASK)) | |
3745 | { | |
3746 | case EF_SH1: strcat (buf, ", sh1"); break; | |
3747 | case EF_SH2: strcat (buf, ", sh2"); break; | |
3748 | case EF_SH3: strcat (buf, ", sh3"); break; | |
3749 | case EF_SH_DSP: strcat (buf, ", sh-dsp"); break; | |
3750 | case EF_SH3_DSP: strcat (buf, ", sh3-dsp"); break; | |
3751 | case EF_SH4AL_DSP: strcat (buf, ", sh4al-dsp"); break; | |
3752 | case EF_SH3E: strcat (buf, ", sh3e"); break; | |
3753 | case EF_SH4: strcat (buf, ", sh4"); break; | |
3754 | case EF_SH5: strcat (buf, ", sh5"); break; | |
3755 | case EF_SH2E: strcat (buf, ", sh2e"); break; | |
3756 | case EF_SH4A: strcat (buf, ", sh4a"); break; | |
1d70c7fb | 3757 | case EF_SH2A: strcat (buf, ", sh2a"); break; |
ccde1100 AO |
3758 | case EF_SH4_NOFPU: strcat (buf, ", sh4-nofpu"); break; |
3759 | case EF_SH4A_NOFPU: strcat (buf, ", sh4a-nofpu"); break; | |
1d70c7fb | 3760 | case EF_SH2A_NOFPU: strcat (buf, ", sh2a-nofpu"); break; |
0b92ab21 NH |
3761 | case EF_SH3_NOMMU: strcat (buf, ", sh3-nommu"); break; |
3762 | case EF_SH4_NOMMU_NOFPU: strcat (buf, ", sh4-nommu-nofpu"); break; | |
3763 | case EF_SH2A_SH4_NOFPU: strcat (buf, ", sh2a-nofpu-or-sh4-nommu-nofpu"); break; | |
3764 | case EF_SH2A_SH3_NOFPU: strcat (buf, ", sh2a-nofpu-or-sh3-nommu"); break; | |
3765 | case EF_SH2A_SH4: strcat (buf, ", sh2a-or-sh4"); break; | |
3766 | case EF_SH2A_SH3E: strcat (buf, ", sh2a-or-sh3e"); break; | |
2b692964 | 3767 | default: strcat (buf, _(", unknown ISA")); break; |
ccde1100 AO |
3768 | } |
3769 | ||
cec6a5b8 MR |
3770 | if (e_flags & EF_SH_PIC) |
3771 | strcat (buf, ", pic"); | |
3772 | ||
3773 | if (e_flags & EF_SH_FDPIC) | |
3774 | strcat (buf, ", fdpic"); | |
ccde1100 | 3775 | break; |
948f632f | 3776 | |
73589c9d CS |
3777 | case EM_OR1K: |
3778 | if (e_flags & EF_OR1K_NODELAY) | |
3779 | strcat (buf, ", no delay"); | |
3780 | break; | |
57346661 | 3781 | |
351b4b40 RH |
3782 | case EM_SPARCV9: |
3783 | if (e_flags & EF_SPARC_32PLUS) | |
3784 | strcat (buf, ", v8+"); | |
3785 | ||
3786 | if (e_flags & EF_SPARC_SUN_US1) | |
d07faca2 RH |
3787 | strcat (buf, ", ultrasparcI"); |
3788 | ||
3789 | if (e_flags & EF_SPARC_SUN_US3) | |
3790 | strcat (buf, ", ultrasparcIII"); | |
351b4b40 RH |
3791 | |
3792 | if (e_flags & EF_SPARC_HAL_R1) | |
3793 | strcat (buf, ", halr1"); | |
3794 | ||
3795 | if (e_flags & EF_SPARC_LEDATA) | |
3796 | strcat (buf, ", ledata"); | |
3797 | ||
3798 | if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_TSO) | |
3799 | strcat (buf, ", tso"); | |
3800 | ||
3801 | if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_PSO) | |
3802 | strcat (buf, ", pso"); | |
3803 | ||
3804 | if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_RMO) | |
3805 | strcat (buf, ", rmo"); | |
3806 | break; | |
7d466069 | 3807 | |
103f02d3 UD |
3808 | case EM_PARISC: |
3809 | switch (e_flags & EF_PARISC_ARCH) | |
3810 | { | |
3811 | case EFA_PARISC_1_0: | |
3812 | strcpy (buf, ", PA-RISC 1.0"); | |
3813 | break; | |
3814 | case EFA_PARISC_1_1: | |
3815 | strcpy (buf, ", PA-RISC 1.1"); | |
3816 | break; | |
3817 | case EFA_PARISC_2_0: | |
3818 | strcpy (buf, ", PA-RISC 2.0"); | |
3819 | break; | |
3820 | default: | |
3821 | break; | |
3822 | } | |
3823 | if (e_flags & EF_PARISC_TRAPNIL) | |
3824 | strcat (buf, ", trapnil"); | |
3825 | if (e_flags & EF_PARISC_EXT) | |
3826 | strcat (buf, ", ext"); | |
3827 | if (e_flags & EF_PARISC_LSB) | |
3828 | strcat (buf, ", lsb"); | |
3829 | if (e_flags & EF_PARISC_WIDE) | |
3830 | strcat (buf, ", wide"); | |
3831 | if (e_flags & EF_PARISC_NO_KABP) | |
3832 | strcat (buf, ", no kabp"); | |
3833 | if (e_flags & EF_PARISC_LAZYSWAP) | |
3834 | strcat (buf, ", lazyswap"); | |
30800947 | 3835 | break; |
76da6bbe | 3836 | |
7d466069 | 3837 | case EM_PJ: |
2b0337b0 | 3838 | case EM_PJ_OLD: |
7d466069 ILT |
3839 | if ((e_flags & EF_PICOJAVA_NEWCALLS) == EF_PICOJAVA_NEWCALLS) |
3840 | strcat (buf, ", new calling convention"); | |
3841 | ||
3842 | if ((e_flags & EF_PICOJAVA_GNUCALLS) == EF_PICOJAVA_GNUCALLS) | |
3843 | strcat (buf, ", gnu calling convention"); | |
3844 | break; | |
4d6ed7c8 NC |
3845 | |
3846 | case EM_IA_64: | |
3847 | if ((e_flags & EF_IA_64_ABI64)) | |
3848 | strcat (buf, ", 64-bit"); | |
3849 | else | |
3850 | strcat (buf, ", 32-bit"); | |
3851 | if ((e_flags & EF_IA_64_REDUCEDFP)) | |
3852 | strcat (buf, ", reduced fp model"); | |
3853 | if ((e_flags & EF_IA_64_NOFUNCDESC_CONS_GP)) | |
3854 | strcat (buf, ", no function descriptors, constant gp"); | |
3855 | else if ((e_flags & EF_IA_64_CONS_GP)) | |
3856 | strcat (buf, ", constant gp"); | |
3857 | if ((e_flags & EF_IA_64_ABSOLUTE)) | |
3858 | strcat (buf, ", absolute"); | |
dda8d76d | 3859 | if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_OPENVMS) |
28f997cf TG |
3860 | { |
3861 | if ((e_flags & EF_IA_64_VMS_LINKAGES)) | |
3862 | strcat (buf, ", vms_linkages"); | |
3863 | switch ((e_flags & EF_IA_64_VMS_COMCOD)) | |
3864 | { | |
3865 | case EF_IA_64_VMS_COMCOD_SUCCESS: | |
3866 | break; | |
3867 | case EF_IA_64_VMS_COMCOD_WARNING: | |
3868 | strcat (buf, ", warning"); | |
3869 | break; | |
3870 | case EF_IA_64_VMS_COMCOD_ERROR: | |
3871 | strcat (buf, ", error"); | |
3872 | break; | |
3873 | case EF_IA_64_VMS_COMCOD_ABORT: | |
3874 | strcat (buf, ", abort"); | |
3875 | break; | |
3876 | default: | |
bee0ee85 NC |
3877 | warn (_("Unrecognised IA64 VMS Command Code: %x\n"), |
3878 | e_flags & EF_IA_64_VMS_COMCOD); | |
3879 | strcat (buf, ", <unknown>"); | |
28f997cf TG |
3880 | } |
3881 | } | |
4d6ed7c8 | 3882 | break; |
179d3252 JT |
3883 | |
3884 | case EM_VAX: | |
3885 | if ((e_flags & EF_VAX_NONPIC)) | |
3886 | strcat (buf, ", non-PIC"); | |
3887 | if ((e_flags & EF_VAX_DFLOAT)) | |
3888 | strcat (buf, ", D-Float"); | |
3889 | if ((e_flags & EF_VAX_GFLOAT)) | |
3890 | strcat (buf, ", G-Float"); | |
3891 | break; | |
c7927a3c | 3892 | |
619ed720 EB |
3893 | case EM_VISIUM: |
3894 | if (e_flags & EF_VISIUM_ARCH_MCM) | |
3895 | strcat (buf, ", mcm"); | |
3896 | else if (e_flags & EF_VISIUM_ARCH_MCM24) | |
3897 | strcat (buf, ", mcm24"); | |
3898 | if (e_flags & EF_VISIUM_ARCH_GR6) | |
3899 | strcat (buf, ", gr6"); | |
3900 | break; | |
3901 | ||
4046d87a | 3902 | case EM_RL78: |
1740ba0c NC |
3903 | switch (e_flags & E_FLAG_RL78_CPU_MASK) |
3904 | { | |
3905 | case E_FLAG_RL78_ANY_CPU: break; | |
3906 | case E_FLAG_RL78_G10: strcat (buf, ", G10"); break; | |
3907 | case E_FLAG_RL78_G13: strcat (buf, ", G13"); break; | |
3908 | case E_FLAG_RL78_G14: strcat (buf, ", G14"); break; | |
3909 | } | |
856ea05c KP |
3910 | if (e_flags & E_FLAG_RL78_64BIT_DOUBLES) |
3911 | strcat (buf, ", 64-bit doubles"); | |
4046d87a | 3912 | break; |
0b4362b0 | 3913 | |
c7927a3c NC |
3914 | case EM_RX: |
3915 | if (e_flags & E_FLAG_RX_64BIT_DOUBLES) | |
3916 | strcat (buf, ", 64-bit doubles"); | |
3917 | if (e_flags & E_FLAG_RX_DSP) | |
dd24e3da | 3918 | strcat (buf, ", dsp"); |
d4cb0ea0 | 3919 | if (e_flags & E_FLAG_RX_PID) |
0b4362b0 | 3920 | strcat (buf, ", pid"); |
708e2187 NC |
3921 | if (e_flags & E_FLAG_RX_ABI) |
3922 | strcat (buf, ", RX ABI"); | |
3525236c NC |
3923 | if (e_flags & E_FLAG_RX_SINSNS_SET) |
3924 | strcat (buf, e_flags & E_FLAG_RX_SINSNS_YES | |
3925 | ? ", uses String instructions" : ", bans String instructions"); | |
a117b0a5 YS |
3926 | if (e_flags & E_FLAG_RX_V2) |
3927 | strcat (buf, ", V2"); | |
f87673e0 YS |
3928 | if (e_flags & E_FLAG_RX_V3) |
3929 | strcat (buf, ", V3"); | |
d4cb0ea0 | 3930 | break; |
55786da2 AK |
3931 | |
3932 | case EM_S390: | |
3933 | if (e_flags & EF_S390_HIGH_GPRS) | |
3934 | strcat (buf, ", highgprs"); | |
d4cb0ea0 | 3935 | break; |
40b36596 JM |
3936 | |
3937 | case EM_TI_C6000: | |
3938 | if ((e_flags & EF_C6000_REL)) | |
3939 | strcat (buf, ", relocatable module"); | |
d4cb0ea0 | 3940 | break; |
13761a11 NC |
3941 | |
3942 | case EM_MSP430: | |
3943 | strcat (buf, _(": architecture variant: ")); | |
3944 | switch (e_flags & EF_MSP430_MACH) | |
3945 | { | |
3946 | case E_MSP430_MACH_MSP430x11: strcat (buf, "MSP430x11"); break; | |
3947 | case E_MSP430_MACH_MSP430x11x1 : strcat (buf, "MSP430x11x1 "); break; | |
3948 | case E_MSP430_MACH_MSP430x12: strcat (buf, "MSP430x12"); break; | |
3949 | case E_MSP430_MACH_MSP430x13: strcat (buf, "MSP430x13"); break; | |
3950 | case E_MSP430_MACH_MSP430x14: strcat (buf, "MSP430x14"); break; | |
3951 | case E_MSP430_MACH_MSP430x15: strcat (buf, "MSP430x15"); break; | |
3952 | case E_MSP430_MACH_MSP430x16: strcat (buf, "MSP430x16"); break; | |
3953 | case E_MSP430_MACH_MSP430x31: strcat (buf, "MSP430x31"); break; | |
3954 | case E_MSP430_MACH_MSP430x32: strcat (buf, "MSP430x32"); break; | |
3955 | case E_MSP430_MACH_MSP430x33: strcat (buf, "MSP430x33"); break; | |
3956 | case E_MSP430_MACH_MSP430x41: strcat (buf, "MSP430x41"); break; | |
3957 | case E_MSP430_MACH_MSP430x42: strcat (buf, "MSP430x42"); break; | |
3958 | case E_MSP430_MACH_MSP430x43: strcat (buf, "MSP430x43"); break; | |
3959 | case E_MSP430_MACH_MSP430x44: strcat (buf, "MSP430x44"); break; | |
3960 | case E_MSP430_MACH_MSP430X : strcat (buf, "MSP430X"); break; | |
3961 | default: | |
3962 | strcat (buf, _(": unknown")); break; | |
3963 | } | |
3964 | ||
3965 | if (e_flags & ~ EF_MSP430_MACH) | |
3966 | strcat (buf, _(": unknown extra flag bits also present")); | |
6655dba2 SB |
3967 | break; |
3968 | ||
3969 | case EM_Z80: | |
3970 | switch (e_flags & EF_Z80_MACH_MSK) | |
3971 | { | |
3972 | case EF_Z80_MACH_Z80: strcat (buf, ", Z80"); break; | |
3973 | case EF_Z80_MACH_Z180: strcat (buf, ", Z180"); break; | |
3974 | case EF_Z80_MACH_R800: strcat (buf, ", R800"); break; | |
3975 | case EF_Z80_MACH_EZ80_Z80: strcat (buf, ", EZ80"); break; | |
3976 | case EF_Z80_MACH_EZ80_ADL: strcat (buf, ", EZ80, ADL"); break; | |
3977 | case EF_Z80_MACH_GBZ80: strcat (buf, ", GBZ80"); break; | |
9fc0b501 | 3978 | case EF_Z80_MACH_Z80N: strcat (buf, ", Z80N"); break; |
6655dba2 SB |
3979 | default: |
3980 | strcat (buf, _(", unknown")); break; | |
3981 | } | |
3982 | break; | |
e9a0721f | 3983 | case EM_LOONGARCH: |
3984 | if (EF_LOONGARCH_IS_LP64 (e_flags)) | |
3985 | strcat (buf, ", LP64"); | |
3986 | else if (EF_LOONGARCH_IS_ILP32 (e_flags)) | |
3987 | strcat (buf, ", ILP32"); | |
3988 | ||
3989 | if (EF_LOONGARCH_IS_SOFT_FLOAT (e_flags)) | |
3990 | strcat (buf, ", SOFT-FLOAT"); | |
3991 | else if (EF_LOONGARCH_IS_SINGLE_FLOAT (e_flags)) | |
3992 | strcat (buf, ", SINGLE-FLOAT"); | |
3993 | else if (EF_LOONGARCH_IS_DOUBLE_FLOAT (e_flags)) | |
3994 | strcat (buf, ", DOUBLE-FLOAT"); | |
3995 | ||
3996 | break; | |
252b5132 RH |
3997 | } |
3998 | } | |
3999 | ||
4000 | return buf; | |
4001 | } | |
4002 | ||
252b5132 | 4003 | static const char * |
dda8d76d | 4004 | get_osabi_name (Filedata * filedata, unsigned int osabi) |
d3ba0551 AM |
4005 | { |
4006 | static char buff[32]; | |
4007 | ||
4008 | switch (osabi) | |
4009 | { | |
4010 | case ELFOSABI_NONE: return "UNIX - System V"; | |
4011 | case ELFOSABI_HPUX: return "UNIX - HP-UX"; | |
4012 | case ELFOSABI_NETBSD: return "UNIX - NetBSD"; | |
9c55345c | 4013 | case ELFOSABI_GNU: return "UNIX - GNU"; |
d3ba0551 AM |
4014 | case ELFOSABI_SOLARIS: return "UNIX - Solaris"; |
4015 | case ELFOSABI_AIX: return "UNIX - AIX"; | |
4016 | case ELFOSABI_IRIX: return "UNIX - IRIX"; | |
4017 | case ELFOSABI_FREEBSD: return "UNIX - FreeBSD"; | |
4018 | case ELFOSABI_TRU64: return "UNIX - TRU64"; | |
4019 | case ELFOSABI_MODESTO: return "Novell - Modesto"; | |
4020 | case ELFOSABI_OPENBSD: return "UNIX - OpenBSD"; | |
4021 | case ELFOSABI_OPENVMS: return "VMS - OpenVMS"; | |
4022 | case ELFOSABI_NSK: return "HP - Non-Stop Kernel"; | |
3b26c801 | 4023 | case ELFOSABI_AROS: return "AROS"; |
11636f9e | 4024 | case ELFOSABI_FENIXOS: return "FenixOS"; |
6d913794 NC |
4025 | case ELFOSABI_CLOUDABI: return "Nuxi CloudABI"; |
4026 | case ELFOSABI_OPENVOS: return "Stratus Technologies OpenVOS"; | |
d3ba0551 | 4027 | default: |
40b36596 | 4028 | if (osabi >= 64) |
dda8d76d | 4029 | switch (filedata->file_header.e_machine) |
40b36596 JM |
4030 | { |
4031 | case EM_ARM: | |
4032 | switch (osabi) | |
4033 | { | |
4034 | case ELFOSABI_ARM: return "ARM"; | |
18a20338 | 4035 | case ELFOSABI_ARM_FDPIC: return "ARM FDPIC"; |
40b36596 JM |
4036 | default: |
4037 | break; | |
4038 | } | |
4039 | break; | |
4040 | ||
4041 | case EM_MSP430: | |
4042 | case EM_MSP430_OLD: | |
619ed720 | 4043 | case EM_VISIUM: |
40b36596 JM |
4044 | switch (osabi) |
4045 | { | |
4046 | case ELFOSABI_STANDALONE: return _("Standalone App"); | |
4047 | default: | |
4048 | break; | |
4049 | } | |
4050 | break; | |
4051 | ||
4052 | case EM_TI_C6000: | |
4053 | switch (osabi) | |
4054 | { | |
4055 | case ELFOSABI_C6000_ELFABI: return _("Bare-metal C6000"); | |
4056 | case ELFOSABI_C6000_LINUX: return "Linux C6000"; | |
4057 | default: | |
4058 | break; | |
4059 | } | |
4060 | break; | |
4061 | ||
4062 | default: | |
4063 | break; | |
4064 | } | |
e9e44622 | 4065 | snprintf (buff, sizeof (buff), _("<unknown: %x>"), osabi); |
d3ba0551 AM |
4066 | return buff; |
4067 | } | |
4068 | } | |
4069 | ||
a06ea964 NC |
4070 | static const char * |
4071 | get_aarch64_segment_type (unsigned long type) | |
4072 | { | |
4073 | switch (type) | |
4074 | { | |
32ec8896 NC |
4075 | case PT_AARCH64_ARCHEXT: return "AARCH64_ARCHEXT"; |
4076 | default: return NULL; | |
a06ea964 | 4077 | } |
a06ea964 NC |
4078 | } |
4079 | ||
b294bdf8 MM |
4080 | static const char * |
4081 | get_arm_segment_type (unsigned long type) | |
4082 | { | |
4083 | switch (type) | |
4084 | { | |
32ec8896 NC |
4085 | case PT_ARM_EXIDX: return "EXIDX"; |
4086 | default: return NULL; | |
b294bdf8 | 4087 | } |
b294bdf8 MM |
4088 | } |
4089 | ||
b4cbbe8f AK |
4090 | static const char * |
4091 | get_s390_segment_type (unsigned long type) | |
4092 | { | |
4093 | switch (type) | |
4094 | { | |
4095 | case PT_S390_PGSTE: return "S390_PGSTE"; | |
4096 | default: return NULL; | |
4097 | } | |
4098 | } | |
4099 | ||
d3ba0551 AM |
4100 | static const char * |
4101 | get_mips_segment_type (unsigned long type) | |
252b5132 RH |
4102 | { |
4103 | switch (type) | |
4104 | { | |
32ec8896 NC |
4105 | case PT_MIPS_REGINFO: return "REGINFO"; |
4106 | case PT_MIPS_RTPROC: return "RTPROC"; | |
4107 | case PT_MIPS_OPTIONS: return "OPTIONS"; | |
4108 | case PT_MIPS_ABIFLAGS: return "ABIFLAGS"; | |
4109 | default: return NULL; | |
252b5132 | 4110 | } |
252b5132 RH |
4111 | } |
4112 | ||
103f02d3 | 4113 | static const char * |
d3ba0551 | 4114 | get_parisc_segment_type (unsigned long type) |
103f02d3 UD |
4115 | { |
4116 | switch (type) | |
4117 | { | |
103f02d3 UD |
4118 | case PT_PARISC_ARCHEXT: return "PARISC_ARCHEXT"; |
4119 | case PT_PARISC_UNWIND: return "PARISC_UNWIND"; | |
61472819 | 4120 | case PT_PARISC_WEAKORDER: return "PARISC_WEAKORDER"; |
32ec8896 | 4121 | default: return NULL; |
103f02d3 | 4122 | } |
103f02d3 UD |
4123 | } |
4124 | ||
4d6ed7c8 | 4125 | static const char * |
d3ba0551 | 4126 | get_ia64_segment_type (unsigned long type) |
4d6ed7c8 NC |
4127 | { |
4128 | switch (type) | |
4129 | { | |
4130 | case PT_IA_64_ARCHEXT: return "IA_64_ARCHEXT"; | |
4131 | case PT_IA_64_UNWIND: return "IA_64_UNWIND"; | |
32ec8896 | 4132 | default: return NULL; |
4d6ed7c8 | 4133 | } |
4d6ed7c8 NC |
4134 | } |
4135 | ||
40b36596 JM |
4136 | static const char * |
4137 | get_tic6x_segment_type (unsigned long type) | |
4138 | { | |
4139 | switch (type) | |
4140 | { | |
32ec8896 NC |
4141 | case PT_C6000_PHATTR: return "C6000_PHATTR"; |
4142 | default: return NULL; | |
40b36596 | 4143 | } |
40b36596 JM |
4144 | } |
4145 | ||
fbc95f1e KC |
4146 | static const char * |
4147 | get_riscv_segment_type (unsigned long type) | |
4148 | { | |
4149 | switch (type) | |
4150 | { | |
4151 | case PT_RISCV_ATTRIBUTES: return "RISCV_ATTRIBUTES"; | |
4152 | default: return NULL; | |
4153 | } | |
4154 | } | |
4155 | ||
df3a023b AM |
4156 | static const char * |
4157 | get_hpux_segment_type (unsigned long type, unsigned e_machine) | |
4158 | { | |
4159 | if (e_machine == EM_PARISC) | |
4160 | switch (type) | |
4161 | { | |
4162 | case PT_HP_TLS: return "HP_TLS"; | |
4163 | case PT_HP_CORE_NONE: return "HP_CORE_NONE"; | |
4164 | case PT_HP_CORE_VERSION: return "HP_CORE_VERSION"; | |
4165 | case PT_HP_CORE_KERNEL: return "HP_CORE_KERNEL"; | |
4166 | case PT_HP_CORE_COMM: return "HP_CORE_COMM"; | |
4167 | case PT_HP_CORE_PROC: return "HP_CORE_PROC"; | |
4168 | case PT_HP_CORE_LOADABLE: return "HP_CORE_LOADABLE"; | |
4169 | case PT_HP_CORE_STACK: return "HP_CORE_STACK"; | |
4170 | case PT_HP_CORE_SHM: return "HP_CORE_SHM"; | |
4171 | case PT_HP_CORE_MMF: return "HP_CORE_MMF"; | |
4172 | case PT_HP_PARALLEL: return "HP_PARALLEL"; | |
4173 | case PT_HP_FASTBIND: return "HP_FASTBIND"; | |
4174 | case PT_HP_OPT_ANNOT: return "HP_OPT_ANNOT"; | |
4175 | case PT_HP_HSL_ANNOT: return "HP_HSL_ANNOT"; | |
4176 | case PT_HP_STACK: return "HP_STACK"; | |
4177 | case PT_HP_CORE_UTSNAME: return "HP_CORE_UTSNAME"; | |
4178 | default: return NULL; | |
4179 | } | |
4180 | ||
4181 | if (e_machine == EM_IA_64) | |
4182 | switch (type) | |
4183 | { | |
4184 | case PT_HP_TLS: return "HP_TLS"; | |
4185 | case PT_IA_64_HP_OPT_ANOT: return "HP_OPT_ANNOT"; | |
4186 | case PT_IA_64_HP_HSL_ANOT: return "HP_HSL_ANNOT"; | |
4187 | case PT_IA_64_HP_STACK: return "HP_STACK"; | |
4188 | default: return NULL; | |
4189 | } | |
4190 | ||
4191 | return NULL; | |
4192 | } | |
4193 | ||
5522f910 NC |
4194 | static const char * |
4195 | get_solaris_segment_type (unsigned long type) | |
4196 | { | |
4197 | switch (type) | |
4198 | { | |
4199 | case 0x6464e550: return "PT_SUNW_UNWIND"; | |
4200 | case 0x6474e550: return "PT_SUNW_EH_FRAME"; | |
4201 | case 0x6ffffff7: return "PT_LOSUNW"; | |
4202 | case 0x6ffffffa: return "PT_SUNWBSS"; | |
4203 | case 0x6ffffffb: return "PT_SUNWSTACK"; | |
4204 | case 0x6ffffffc: return "PT_SUNWDTRACE"; | |
4205 | case 0x6ffffffd: return "PT_SUNWCAP"; | |
4206 | case 0x6fffffff: return "PT_HISUNW"; | |
32ec8896 | 4207 | default: return NULL; |
5522f910 NC |
4208 | } |
4209 | } | |
4210 | ||
252b5132 | 4211 | static const char * |
dda8d76d | 4212 | get_segment_type (Filedata * filedata, unsigned long p_type) |
252b5132 | 4213 | { |
b34976b6 | 4214 | static char buff[32]; |
252b5132 RH |
4215 | |
4216 | switch (p_type) | |
4217 | { | |
b34976b6 AM |
4218 | case PT_NULL: return "NULL"; |
4219 | case PT_LOAD: return "LOAD"; | |
252b5132 | 4220 | case PT_DYNAMIC: return "DYNAMIC"; |
b34976b6 AM |
4221 | case PT_INTERP: return "INTERP"; |
4222 | case PT_NOTE: return "NOTE"; | |
4223 | case PT_SHLIB: return "SHLIB"; | |
4224 | case PT_PHDR: return "PHDR"; | |
13ae64f3 | 4225 | case PT_TLS: return "TLS"; |
32ec8896 | 4226 | case PT_GNU_EH_FRAME: return "GNU_EH_FRAME"; |
2b05f1b7 | 4227 | case PT_GNU_STACK: return "GNU_STACK"; |
8c37241b | 4228 | case PT_GNU_RELRO: return "GNU_RELRO"; |
0a59decb | 4229 | case PT_GNU_PROPERTY: return "GNU_PROPERTY"; |
65765700 | 4230 | |
3eba3ef3 NC |
4231 | case PT_OPENBSD_RANDOMIZE: return "OPENBSD_RANDOMIZE"; |
4232 | case PT_OPENBSD_WXNEEDED: return "OPENBSD_WXNEEDED"; | |
4233 | case PT_OPENBSD_BOOTDATA: return "OPENBSD_BOOTDATA"; | |
b9e920ec | 4234 | |
252b5132 | 4235 | default: |
df3a023b | 4236 | if ((p_type >= PT_LOPROC) && (p_type <= PT_HIPROC)) |
252b5132 | 4237 | { |
2cf0635d | 4238 | const char * result; |
103f02d3 | 4239 | |
dda8d76d | 4240 | switch (filedata->file_header.e_machine) |
252b5132 | 4241 | { |
a06ea964 NC |
4242 | case EM_AARCH64: |
4243 | result = get_aarch64_segment_type (p_type); | |
4244 | break; | |
b294bdf8 MM |
4245 | case EM_ARM: |
4246 | result = get_arm_segment_type (p_type); | |
4247 | break; | |
252b5132 | 4248 | case EM_MIPS: |
4fe85591 | 4249 | case EM_MIPS_RS3_LE: |
252b5132 RH |
4250 | result = get_mips_segment_type (p_type); |
4251 | break; | |
103f02d3 UD |
4252 | case EM_PARISC: |
4253 | result = get_parisc_segment_type (p_type); | |
4254 | break; | |
4d6ed7c8 NC |
4255 | case EM_IA_64: |
4256 | result = get_ia64_segment_type (p_type); | |
4257 | break; | |
40b36596 JM |
4258 | case EM_TI_C6000: |
4259 | result = get_tic6x_segment_type (p_type); | |
4260 | break; | |
b4cbbe8f AK |
4261 | case EM_S390: |
4262 | case EM_S390_OLD: | |
4263 | result = get_s390_segment_type (p_type); | |
4264 | break; | |
fbc95f1e KC |
4265 | case EM_RISCV: |
4266 | result = get_riscv_segment_type (p_type); | |
4267 | break; | |
252b5132 RH |
4268 | default: |
4269 | result = NULL; | |
4270 | break; | |
4271 | } | |
103f02d3 | 4272 | |
252b5132 RH |
4273 | if (result != NULL) |
4274 | return result; | |
103f02d3 | 4275 | |
1a9ccd70 | 4276 | sprintf (buff, "LOPROC+%#lx", p_type - PT_LOPROC); |
252b5132 RH |
4277 | } |
4278 | else if ((p_type >= PT_LOOS) && (p_type <= PT_HIOS)) | |
103f02d3 | 4279 | { |
df3a023b | 4280 | const char * result = NULL; |
103f02d3 | 4281 | |
df3a023b | 4282 | switch (filedata->file_header.e_ident[EI_OSABI]) |
103f02d3 | 4283 | { |
df3a023b AM |
4284 | case ELFOSABI_GNU: |
4285 | case ELFOSABI_FREEBSD: | |
4286 | if (p_type >= PT_GNU_MBIND_LO && p_type <= PT_GNU_MBIND_HI) | |
4287 | { | |
4288 | sprintf (buff, "GNU_MBIND+%#lx", p_type - PT_GNU_MBIND_LO); | |
4289 | result = buff; | |
4290 | } | |
103f02d3 | 4291 | break; |
df3a023b AM |
4292 | case ELFOSABI_HPUX: |
4293 | result = get_hpux_segment_type (p_type, | |
4294 | filedata->file_header.e_machine); | |
4295 | break; | |
4296 | case ELFOSABI_SOLARIS: | |
4297 | result = get_solaris_segment_type (p_type); | |
00428cca | 4298 | break; |
103f02d3 | 4299 | default: |
103f02d3 UD |
4300 | break; |
4301 | } | |
103f02d3 UD |
4302 | if (result != NULL) |
4303 | return result; | |
4304 | ||
1a9ccd70 | 4305 | sprintf (buff, "LOOS+%#lx", p_type - PT_LOOS); |
103f02d3 | 4306 | } |
252b5132 | 4307 | else |
e9e44622 | 4308 | snprintf (buff, sizeof (buff), _("<unknown>: %lx"), p_type); |
252b5132 RH |
4309 | |
4310 | return buff; | |
4311 | } | |
4312 | } | |
4313 | ||
53a346d8 CZ |
4314 | static const char * |
4315 | get_arc_section_type_name (unsigned int sh_type) | |
4316 | { | |
4317 | switch (sh_type) | |
4318 | { | |
4319 | case SHT_ARC_ATTRIBUTES: return "ARC_ATTRIBUTES"; | |
4320 | default: | |
4321 | break; | |
4322 | } | |
4323 | return NULL; | |
4324 | } | |
4325 | ||
252b5132 | 4326 | static const char * |
d3ba0551 | 4327 | get_mips_section_type_name (unsigned int sh_type) |
252b5132 RH |
4328 | { |
4329 | switch (sh_type) | |
4330 | { | |
b34976b6 AM |
4331 | case SHT_MIPS_LIBLIST: return "MIPS_LIBLIST"; |
4332 | case SHT_MIPS_MSYM: return "MIPS_MSYM"; | |
4333 | case SHT_MIPS_CONFLICT: return "MIPS_CONFLICT"; | |
4334 | case SHT_MIPS_GPTAB: return "MIPS_GPTAB"; | |
4335 | case SHT_MIPS_UCODE: return "MIPS_UCODE"; | |
4336 | case SHT_MIPS_DEBUG: return "MIPS_DEBUG"; | |
4337 | case SHT_MIPS_REGINFO: return "MIPS_REGINFO"; | |
4338 | case SHT_MIPS_PACKAGE: return "MIPS_PACKAGE"; | |
4339 | case SHT_MIPS_PACKSYM: return "MIPS_PACKSYM"; | |
4340 | case SHT_MIPS_RELD: return "MIPS_RELD"; | |
4341 | case SHT_MIPS_IFACE: return "MIPS_IFACE"; | |
4342 | case SHT_MIPS_CONTENT: return "MIPS_CONTENT"; | |
4343 | case SHT_MIPS_OPTIONS: return "MIPS_OPTIONS"; | |
4344 | case SHT_MIPS_SHDR: return "MIPS_SHDR"; | |
4345 | case SHT_MIPS_FDESC: return "MIPS_FDESC"; | |
4346 | case SHT_MIPS_EXTSYM: return "MIPS_EXTSYM"; | |
4347 | case SHT_MIPS_DENSE: return "MIPS_DENSE"; | |
4348 | case SHT_MIPS_PDESC: return "MIPS_PDESC"; | |
4349 | case SHT_MIPS_LOCSYM: return "MIPS_LOCSYM"; | |
4350 | case SHT_MIPS_AUXSYM: return "MIPS_AUXSYM"; | |
4351 | case SHT_MIPS_OPTSYM: return "MIPS_OPTSYM"; | |
4352 | case SHT_MIPS_LOCSTR: return "MIPS_LOCSTR"; | |
4353 | case SHT_MIPS_LINE: return "MIPS_LINE"; | |
4354 | case SHT_MIPS_RFDESC: return "MIPS_RFDESC"; | |
4355 | case SHT_MIPS_DELTASYM: return "MIPS_DELTASYM"; | |
4356 | case SHT_MIPS_DELTAINST: return "MIPS_DELTAINST"; | |
4357 | case SHT_MIPS_DELTACLASS: return "MIPS_DELTACLASS"; | |
4358 | case SHT_MIPS_DWARF: return "MIPS_DWARF"; | |
4359 | case SHT_MIPS_DELTADECL: return "MIPS_DELTADECL"; | |
4360 | case SHT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB"; | |
4361 | case SHT_MIPS_EVENTS: return "MIPS_EVENTS"; | |
4362 | case SHT_MIPS_TRANSLATE: return "MIPS_TRANSLATE"; | |
4363 | case SHT_MIPS_PIXIE: return "MIPS_PIXIE"; | |
4364 | case SHT_MIPS_XLATE: return "MIPS_XLATE"; | |
4365 | case SHT_MIPS_XLATE_DEBUG: return "MIPS_XLATE_DEBUG"; | |
4366 | case SHT_MIPS_WHIRL: return "MIPS_WHIRL"; | |
4367 | case SHT_MIPS_EH_REGION: return "MIPS_EH_REGION"; | |
4368 | case SHT_MIPS_XLATE_OLD: return "MIPS_XLATE_OLD"; | |
252b5132 | 4369 | case SHT_MIPS_PDR_EXCEPTION: return "MIPS_PDR_EXCEPTION"; |
351cdf24 | 4370 | case SHT_MIPS_ABIFLAGS: return "MIPS_ABIFLAGS"; |
f16a9783 | 4371 | case SHT_MIPS_XHASH: return "MIPS_XHASH"; |
252b5132 RH |
4372 | default: |
4373 | break; | |
4374 | } | |
4375 | return NULL; | |
4376 | } | |
4377 | ||
103f02d3 | 4378 | static const char * |
d3ba0551 | 4379 | get_parisc_section_type_name (unsigned int sh_type) |
103f02d3 UD |
4380 | { |
4381 | switch (sh_type) | |
4382 | { | |
4383 | case SHT_PARISC_EXT: return "PARISC_EXT"; | |
4384 | case SHT_PARISC_UNWIND: return "PARISC_UNWIND"; | |
4385 | case SHT_PARISC_DOC: return "PARISC_DOC"; | |
eec8f817 DA |
4386 | case SHT_PARISC_ANNOT: return "PARISC_ANNOT"; |
4387 | case SHT_PARISC_SYMEXTN: return "PARISC_SYMEXTN"; | |
4388 | case SHT_PARISC_STUBS: return "PARISC_STUBS"; | |
61472819 | 4389 | case SHT_PARISC_DLKM: return "PARISC_DLKM"; |
32ec8896 | 4390 | default: return NULL; |
103f02d3 | 4391 | } |
103f02d3 UD |
4392 | } |
4393 | ||
4d6ed7c8 | 4394 | static const char * |
dda8d76d | 4395 | get_ia64_section_type_name (Filedata * filedata, unsigned int sh_type) |
4d6ed7c8 | 4396 | { |
18bd398b | 4397 | /* If the top 8 bits are 0x78 the next 8 are the os/abi ID. */ |
ecc51f48 | 4398 | if ((sh_type & 0xFF000000) == SHT_IA_64_LOPSREG) |
dda8d76d | 4399 | return get_osabi_name (filedata, (sh_type & 0x00FF0000) >> 16); |
0de14b54 | 4400 | |
4d6ed7c8 NC |
4401 | switch (sh_type) |
4402 | { | |
148b93f2 NC |
4403 | case SHT_IA_64_EXT: return "IA_64_EXT"; |
4404 | case SHT_IA_64_UNWIND: return "IA_64_UNWIND"; | |
4405 | case SHT_IA_64_PRIORITY_INIT: return "IA_64_PRIORITY_INIT"; | |
4406 | case SHT_IA_64_VMS_TRACE: return "VMS_TRACE"; | |
4407 | case SHT_IA_64_VMS_TIE_SIGNATURES: return "VMS_TIE_SIGNATURES"; | |
4408 | case SHT_IA_64_VMS_DEBUG: return "VMS_DEBUG"; | |
4409 | case SHT_IA_64_VMS_DEBUG_STR: return "VMS_DEBUG_STR"; | |
4410 | case SHT_IA_64_VMS_LINKAGES: return "VMS_LINKAGES"; | |
4411 | case SHT_IA_64_VMS_SYMBOL_VECTOR: return "VMS_SYMBOL_VECTOR"; | |
4412 | case SHT_IA_64_VMS_FIXUP: return "VMS_FIXUP"; | |
4d6ed7c8 NC |
4413 | default: |
4414 | break; | |
4415 | } | |
4416 | return NULL; | |
4417 | } | |
4418 | ||
d2b2c203 DJ |
4419 | static const char * |
4420 | get_x86_64_section_type_name (unsigned int sh_type) | |
4421 | { | |
4422 | switch (sh_type) | |
4423 | { | |
4424 | case SHT_X86_64_UNWIND: return "X86_64_UNWIND"; | |
32ec8896 | 4425 | default: return NULL; |
d2b2c203 | 4426 | } |
d2b2c203 DJ |
4427 | } |
4428 | ||
a06ea964 NC |
4429 | static const char * |
4430 | get_aarch64_section_type_name (unsigned int sh_type) | |
4431 | { | |
4432 | switch (sh_type) | |
4433 | { | |
32ec8896 NC |
4434 | case SHT_AARCH64_ATTRIBUTES: return "AARCH64_ATTRIBUTES"; |
4435 | default: return NULL; | |
a06ea964 | 4436 | } |
a06ea964 NC |
4437 | } |
4438 | ||
40a18ebd NC |
4439 | static const char * |
4440 | get_arm_section_type_name (unsigned int sh_type) | |
4441 | { | |
4442 | switch (sh_type) | |
4443 | { | |
7f6fed87 NC |
4444 | case SHT_ARM_EXIDX: return "ARM_EXIDX"; |
4445 | case SHT_ARM_PREEMPTMAP: return "ARM_PREEMPTMAP"; | |
4446 | case SHT_ARM_ATTRIBUTES: return "ARM_ATTRIBUTES"; | |
4447 | case SHT_ARM_DEBUGOVERLAY: return "ARM_DEBUGOVERLAY"; | |
4448 | case SHT_ARM_OVERLAYSECTION: return "ARM_OVERLAYSECTION"; | |
32ec8896 | 4449 | default: return NULL; |
40a18ebd | 4450 | } |
40a18ebd NC |
4451 | } |
4452 | ||
40b36596 JM |
4453 | static const char * |
4454 | get_tic6x_section_type_name (unsigned int sh_type) | |
4455 | { | |
4456 | switch (sh_type) | |
4457 | { | |
32ec8896 NC |
4458 | case SHT_C6000_UNWIND: return "C6000_UNWIND"; |
4459 | case SHT_C6000_PREEMPTMAP: return "C6000_PREEMPTMAP"; | |
4460 | case SHT_C6000_ATTRIBUTES: return "C6000_ATTRIBUTES"; | |
4461 | case SHT_TI_ICODE: return "TI_ICODE"; | |
4462 | case SHT_TI_XREF: return "TI_XREF"; | |
4463 | case SHT_TI_HANDLER: return "TI_HANDLER"; | |
4464 | case SHT_TI_INITINFO: return "TI_INITINFO"; | |
4465 | case SHT_TI_PHATTRS: return "TI_PHATTRS"; | |
4466 | default: return NULL; | |
40b36596 | 4467 | } |
40b36596 JM |
4468 | } |
4469 | ||
13761a11 | 4470 | static const char * |
b0191216 | 4471 | get_msp430_section_type_name (unsigned int sh_type) |
13761a11 NC |
4472 | { |
4473 | switch (sh_type) | |
4474 | { | |
32ec8896 NC |
4475 | case SHT_MSP430_SEC_FLAGS: return "MSP430_SEC_FLAGS"; |
4476 | case SHT_MSP430_SYM_ALIASES: return "MSP430_SYM_ALIASES"; | |
4477 | case SHT_MSP430_ATTRIBUTES: return "MSP430_ATTRIBUTES"; | |
4478 | default: return NULL; | |
13761a11 NC |
4479 | } |
4480 | } | |
4481 | ||
fe944acf FT |
4482 | static const char * |
4483 | get_nfp_section_type_name (unsigned int sh_type) | |
4484 | { | |
4485 | switch (sh_type) | |
4486 | { | |
4487 | case SHT_NFP_MECONFIG: return "NFP_MECONFIG"; | |
4488 | case SHT_NFP_INITREG: return "NFP_INITREG"; | |
4489 | case SHT_NFP_UDEBUG: return "NFP_UDEBUG"; | |
4490 | default: return NULL; | |
4491 | } | |
4492 | } | |
4493 | ||
685080f2 NC |
4494 | static const char * |
4495 | get_v850_section_type_name (unsigned int sh_type) | |
4496 | { | |
4497 | switch (sh_type) | |
4498 | { | |
32ec8896 NC |
4499 | case SHT_V850_SCOMMON: return "V850 Small Common"; |
4500 | case SHT_V850_TCOMMON: return "V850 Tiny Common"; | |
4501 | case SHT_V850_ZCOMMON: return "V850 Zero Common"; | |
4502 | case SHT_RENESAS_IOP: return "RENESAS IOP"; | |
4503 | case SHT_RENESAS_INFO: return "RENESAS INFO"; | |
4504 | default: return NULL; | |
685080f2 NC |
4505 | } |
4506 | } | |
4507 | ||
2dc8dd17 JW |
4508 | static const char * |
4509 | get_riscv_section_type_name (unsigned int sh_type) | |
4510 | { | |
4511 | switch (sh_type) | |
4512 | { | |
4513 | case SHT_RISCV_ATTRIBUTES: return "RISCV_ATTRIBUTES"; | |
4514 | default: return NULL; | |
4515 | } | |
4516 | } | |
4517 | ||
0861f561 CQ |
4518 | static const char * |
4519 | get_csky_section_type_name (unsigned int sh_type) | |
4520 | { | |
4521 | switch (sh_type) | |
4522 | { | |
4523 | case SHT_CSKY_ATTRIBUTES: return "CSKY_ATTRIBUTES"; | |
4524 | default: return NULL; | |
4525 | } | |
4526 | } | |
4527 | ||
252b5132 | 4528 | static const char * |
dda8d76d | 4529 | get_section_type_name (Filedata * filedata, unsigned int sh_type) |
252b5132 | 4530 | { |
b34976b6 | 4531 | static char buff[32]; |
9fb71ee4 | 4532 | const char * result; |
252b5132 RH |
4533 | |
4534 | switch (sh_type) | |
4535 | { | |
4536 | case SHT_NULL: return "NULL"; | |
4537 | case SHT_PROGBITS: return "PROGBITS"; | |
4538 | case SHT_SYMTAB: return "SYMTAB"; | |
4539 | case SHT_STRTAB: return "STRTAB"; | |
4540 | case SHT_RELA: return "RELA"; | |
dd207c13 | 4541 | case SHT_RELR: return "RELR"; |
252b5132 RH |
4542 | case SHT_HASH: return "HASH"; |
4543 | case SHT_DYNAMIC: return "DYNAMIC"; | |
4544 | case SHT_NOTE: return "NOTE"; | |
4545 | case SHT_NOBITS: return "NOBITS"; | |
4546 | case SHT_REL: return "REL"; | |
4547 | case SHT_SHLIB: return "SHLIB"; | |
4548 | case SHT_DYNSYM: return "DYNSYM"; | |
d1133906 NC |
4549 | case SHT_INIT_ARRAY: return "INIT_ARRAY"; |
4550 | case SHT_FINI_ARRAY: return "FINI_ARRAY"; | |
4551 | case SHT_PREINIT_ARRAY: return "PREINIT_ARRAY"; | |
fdc90cb4 | 4552 | case SHT_GNU_HASH: return "GNU_HASH"; |
93ebe586 | 4553 | case SHT_GROUP: return "GROUP"; |
67ce483b | 4554 | case SHT_SYMTAB_SHNDX: return "SYMTAB SECTION INDICES"; |
252b5132 RH |
4555 | case SHT_GNU_verdef: return "VERDEF"; |
4556 | case SHT_GNU_verneed: return "VERNEED"; | |
4557 | case SHT_GNU_versym: return "VERSYM"; | |
b34976b6 AM |
4558 | case 0x6ffffff0: return "VERSYM"; |
4559 | case 0x6ffffffc: return "VERDEF"; | |
252b5132 RH |
4560 | case 0x7ffffffd: return "AUXILIARY"; |
4561 | case 0x7fffffff: return "FILTER"; | |
047b2264 | 4562 | case SHT_GNU_LIBLIST: return "GNU_LIBLIST"; |
252b5132 RH |
4563 | |
4564 | default: | |
4565 | if ((sh_type >= SHT_LOPROC) && (sh_type <= SHT_HIPROC)) | |
4566 | { | |
dda8d76d | 4567 | switch (filedata->file_header.e_machine) |
252b5132 | 4568 | { |
53a346d8 CZ |
4569 | case EM_ARC: |
4570 | case EM_ARC_COMPACT: | |
4571 | case EM_ARC_COMPACT2: | |
4572 | result = get_arc_section_type_name (sh_type); | |
4573 | break; | |
252b5132 | 4574 | case EM_MIPS: |
4fe85591 | 4575 | case EM_MIPS_RS3_LE: |
252b5132 RH |
4576 | result = get_mips_section_type_name (sh_type); |
4577 | break; | |
103f02d3 UD |
4578 | case EM_PARISC: |
4579 | result = get_parisc_section_type_name (sh_type); | |
4580 | break; | |
4d6ed7c8 | 4581 | case EM_IA_64: |
dda8d76d | 4582 | result = get_ia64_section_type_name (filedata, sh_type); |
4d6ed7c8 | 4583 | break; |
d2b2c203 | 4584 | case EM_X86_64: |
8a9036a4 | 4585 | case EM_L1OM: |
7a9068fe | 4586 | case EM_K1OM: |
d2b2c203 DJ |
4587 | result = get_x86_64_section_type_name (sh_type); |
4588 | break; | |
a06ea964 NC |
4589 | case EM_AARCH64: |
4590 | result = get_aarch64_section_type_name (sh_type); | |
4591 | break; | |
40a18ebd NC |
4592 | case EM_ARM: |
4593 | result = get_arm_section_type_name (sh_type); | |
4594 | break; | |
40b36596 JM |
4595 | case EM_TI_C6000: |
4596 | result = get_tic6x_section_type_name (sh_type); | |
4597 | break; | |
13761a11 | 4598 | case EM_MSP430: |
b0191216 | 4599 | result = get_msp430_section_type_name (sh_type); |
13761a11 | 4600 | break; |
fe944acf FT |
4601 | case EM_NFP: |
4602 | result = get_nfp_section_type_name (sh_type); | |
4603 | break; | |
685080f2 NC |
4604 | case EM_V800: |
4605 | case EM_V850: | |
4606 | case EM_CYGNUS_V850: | |
4607 | result = get_v850_section_type_name (sh_type); | |
4608 | break; | |
2dc8dd17 JW |
4609 | case EM_RISCV: |
4610 | result = get_riscv_section_type_name (sh_type); | |
4611 | break; | |
0861f561 CQ |
4612 | case EM_CSKY: |
4613 | result = get_csky_section_type_name (sh_type); | |
4614 | break; | |
252b5132 RH |
4615 | default: |
4616 | result = NULL; | |
4617 | break; | |
4618 | } | |
4619 | ||
4620 | if (result != NULL) | |
4621 | return result; | |
4622 | ||
9fb71ee4 | 4623 | sprintf (buff, "LOPROC+%#x", sh_type - SHT_LOPROC); |
252b5132 RH |
4624 | } |
4625 | else if ((sh_type >= SHT_LOOS) && (sh_type <= SHT_HIOS)) | |
148b93f2 | 4626 | { |
dda8d76d | 4627 | switch (filedata->file_header.e_machine) |
148b93f2 NC |
4628 | { |
4629 | case EM_IA_64: | |
dda8d76d | 4630 | result = get_ia64_section_type_name (filedata, sh_type); |
148b93f2 NC |
4631 | break; |
4632 | default: | |
dda8d76d | 4633 | if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS) |
fd85a6a1 NC |
4634 | result = get_solaris_section_type (sh_type); |
4635 | else | |
1b4b80bf NC |
4636 | { |
4637 | switch (sh_type) | |
4638 | { | |
4639 | case SHT_GNU_INCREMENTAL_INPUTS: result = "GNU_INCREMENTAL_INPUTS"; break; | |
4640 | case SHT_GNU_ATTRIBUTES: result = "GNU_ATTRIBUTES"; break; | |
4641 | case SHT_GNU_HASH: result = "GNU_HASH"; break; | |
4642 | case SHT_GNU_LIBLIST: result = "GNU_LIBLIST"; break; | |
4643 | default: | |
4644 | result = NULL; | |
4645 | break; | |
4646 | } | |
4647 | } | |
148b93f2 NC |
4648 | break; |
4649 | } | |
4650 | ||
4651 | if (result != NULL) | |
4652 | return result; | |
4653 | ||
9fb71ee4 | 4654 | sprintf (buff, "LOOS+%#x", sh_type - SHT_LOOS); |
148b93f2 | 4655 | } |
252b5132 | 4656 | else if ((sh_type >= SHT_LOUSER) && (sh_type <= SHT_HIUSER)) |
685080f2 | 4657 | { |
dda8d76d | 4658 | switch (filedata->file_header.e_machine) |
685080f2 NC |
4659 | { |
4660 | case EM_V800: | |
4661 | case EM_V850: | |
4662 | case EM_CYGNUS_V850: | |
9fb71ee4 | 4663 | result = get_v850_section_type_name (sh_type); |
a9fb83be | 4664 | break; |
685080f2 | 4665 | default: |
9fb71ee4 | 4666 | result = NULL; |
685080f2 NC |
4667 | break; |
4668 | } | |
4669 | ||
9fb71ee4 NC |
4670 | if (result != NULL) |
4671 | return result; | |
4672 | ||
4673 | sprintf (buff, "LOUSER+%#x", sh_type - SHT_LOUSER); | |
685080f2 | 4674 | } |
252b5132 | 4675 | else |
a7dbfd1c NC |
4676 | /* This message is probably going to be displayed in a 15 |
4677 | character wide field, so put the hex value first. */ | |
4678 | snprintf (buff, sizeof (buff), _("%08x: <unknown>"), sh_type); | |
103f02d3 | 4679 | |
252b5132 RH |
4680 | return buff; |
4681 | } | |
4682 | } | |
4683 | ||
79bc120c NC |
4684 | enum long_option_values |
4685 | { | |
4686 | OPTION_DEBUG_DUMP = 512, | |
4687 | OPTION_DYN_SYMS, | |
0f03783c | 4688 | OPTION_LTO_SYMS, |
79bc120c NC |
4689 | OPTION_DWARF_DEPTH, |
4690 | OPTION_DWARF_START, | |
4691 | OPTION_DWARF_CHECK, | |
4692 | OPTION_CTF_DUMP, | |
4693 | OPTION_CTF_PARENT, | |
4694 | OPTION_CTF_SYMBOLS, | |
4695 | OPTION_CTF_STRINGS, | |
4696 | OPTION_WITH_SYMBOL_VERSIONS, | |
4697 | OPTION_RECURSE_LIMIT, | |
4698 | OPTION_NO_RECURSE_LIMIT, | |
047c3dbf NL |
4699 | OPTION_NO_DEMANGLING, |
4700 | OPTION_SYM_BASE | |
79bc120c | 4701 | }; |
2979dc34 | 4702 | |
85b1c36d | 4703 | static struct option options[] = |
252b5132 | 4704 | { |
79bc120c NC |
4705 | /* Note - This table is alpha-sorted on the 'val' |
4706 | field in order to make adding new options easier. */ | |
4707 | {"arch-specific", no_argument, 0, 'A'}, | |
b34976b6 | 4708 | {"all", no_argument, 0, 'a'}, |
79bc120c NC |
4709 | {"demangle", optional_argument, 0, 'C'}, |
4710 | {"archive-index", no_argument, 0, 'c'}, | |
4711 | {"use-dynamic", no_argument, 0, 'D'}, | |
4712 | {"dynamic", no_argument, 0, 'd'}, | |
b34976b6 | 4713 | {"headers", no_argument, 0, 'e'}, |
79bc120c NC |
4714 | {"section-groups", no_argument, 0, 'g'}, |
4715 | {"help", no_argument, 0, 'H'}, | |
4716 | {"file-header", no_argument, 0, 'h'}, | |
b34976b6 | 4717 | {"histogram", no_argument, 0, 'I'}, |
79bc120c NC |
4718 | {"lint", no_argument, 0, 'L'}, |
4719 | {"enable-checks", no_argument, 0, 'L'}, | |
4720 | {"program-headers", no_argument, 0, 'l'}, | |
b34976b6 | 4721 | {"segments", no_argument, 0, 'l'}, |
595cf52e | 4722 | {"full-section-name",no_argument, 0, 'N'}, |
79bc120c | 4723 | {"notes", no_argument, 0, 'n'}, |
ca0e11aa | 4724 | {"process-links", no_argument, 0, 'P'}, |
79bc120c NC |
4725 | {"string-dump", required_argument, 0, 'p'}, |
4726 | {"relocated-dump", required_argument, 0, 'R'}, | |
4727 | {"relocs", no_argument, 0, 'r'}, | |
4728 | {"section-headers", no_argument, 0, 'S'}, | |
4729 | {"sections", no_argument, 0, 'S'}, | |
b34976b6 AM |
4730 | {"symbols", no_argument, 0, 's'}, |
4731 | {"syms", no_argument, 0, 's'}, | |
79bc120c NC |
4732 | {"silent-truncation",no_argument, 0, 'T'}, |
4733 | {"section-details", no_argument, 0, 't'}, | |
09c11c86 | 4734 | {"unwind", no_argument, 0, 'u'}, |
79bc120c NC |
4735 | {"version-info", no_argument, 0, 'V'}, |
4736 | {"version", no_argument, 0, 'v'}, | |
4737 | {"wide", no_argument, 0, 'W'}, | |
b34976b6 | 4738 | {"hex-dump", required_argument, 0, 'x'}, |
0e602686 | 4739 | {"decompress", no_argument, 0, 'z'}, |
252b5132 | 4740 | |
79bc120c NC |
4741 | {"no-demangle", no_argument, 0, OPTION_NO_DEMANGLING}, |
4742 | {"recurse-limit", no_argument, NULL, OPTION_RECURSE_LIMIT}, | |
4743 | {"no-recurse-limit", no_argument, NULL, OPTION_NO_RECURSE_LIMIT}, | |
4744 | {"no-recursion-limit", no_argument, NULL, OPTION_NO_RECURSE_LIMIT}, | |
4745 | {"dyn-syms", no_argument, 0, OPTION_DYN_SYMS}, | |
0f03783c | 4746 | {"lto-syms", no_argument, 0, OPTION_LTO_SYMS}, |
79bc120c | 4747 | {"debug-dump", optional_argument, 0, OPTION_DEBUG_DUMP}, |
fd2f0033 TT |
4748 | {"dwarf-depth", required_argument, 0, OPTION_DWARF_DEPTH}, |
4749 | {"dwarf-start", required_argument, 0, OPTION_DWARF_START}, | |
4723351a | 4750 | {"dwarf-check", no_argument, 0, OPTION_DWARF_CHECK}, |
094e34f2 | 4751 | #ifdef ENABLE_LIBCTF |
d344b407 | 4752 | {"ctf", required_argument, 0, OPTION_CTF_DUMP}, |
7d9813f1 NA |
4753 | {"ctf-symbols", required_argument, 0, OPTION_CTF_SYMBOLS}, |
4754 | {"ctf-strings", required_argument, 0, OPTION_CTF_STRINGS}, | |
4755 | {"ctf-parent", required_argument, 0, OPTION_CTF_PARENT}, | |
094e34f2 | 4756 | #endif |
047c3dbf | 4757 | {"sym-base", optional_argument, 0, OPTION_SYM_BASE}, |
7d9813f1 | 4758 | |
b34976b6 | 4759 | {0, no_argument, 0, 0} |
252b5132 RH |
4760 | }; |
4761 | ||
4762 | static void | |
2cf0635d | 4763 | usage (FILE * stream) |
252b5132 | 4764 | { |
92f01d61 JM |
4765 | fprintf (stream, _("Usage: readelf <option(s)> elf-file(s)\n")); |
4766 | fprintf (stream, _(" Display information about the contents of ELF format files\n")); | |
d6249f5f AM |
4767 | fprintf (stream, _(" Options are:\n")); |
4768 | fprintf (stream, _("\ | |
4769 | -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n")); | |
4770 | fprintf (stream, _("\ | |
4771 | -h --file-header Display the ELF file header\n")); | |
4772 | fprintf (stream, _("\ | |
4773 | -l --program-headers Display the program headers\n")); | |
4774 | fprintf (stream, _("\ | |
4775 | --segments An alias for --program-headers\n")); | |
4776 | fprintf (stream, _("\ | |
4777 | -S --section-headers Display the sections' header\n")); | |
4778 | fprintf (stream, _("\ | |
4779 | --sections An alias for --section-headers\n")); | |
4780 | fprintf (stream, _("\ | |
4781 | -g --section-groups Display the section groups\n")); | |
4782 | fprintf (stream, _("\ | |
4783 | -t --section-details Display the section details\n")); | |
4784 | fprintf (stream, _("\ | |
4785 | -e --headers Equivalent to: -h -l -S\n")); | |
4786 | fprintf (stream, _("\ | |
4787 | -s --syms Display the symbol table\n")); | |
4788 | fprintf (stream, _("\ | |
4789 | --symbols An alias for --syms\n")); | |
4790 | fprintf (stream, _("\ | |
4791 | --dyn-syms Display the dynamic symbol table\n")); | |
4792 | fprintf (stream, _("\ | |
4793 | --lto-syms Display LTO symbol tables\n")); | |
4794 | fprintf (stream, _("\ | |
047c3dbf NL |
4795 | --sym-base=[0|8|10|16] \n\ |
4796 | Force base for symbol sizes. The options are \n\ | |
d6249f5f AM |
4797 | mixed (the default), octal, decimal, hexadecimal.\n")); |
4798 | fprintf (stream, _("\ | |
79bc120c NC |
4799 | -C --demangle[=STYLE] Decode low-level symbol names into user-level names\n\ |
4800 | The STYLE, if specified, can be `auto' (the default),\n\ | |
4801 | `gnu', `lucid', `arm', `hp', `edg', `gnu-v3', `java'\n\ | |
d6249f5f AM |
4802 | or `gnat'\n")); |
4803 | fprintf (stream, _("\ | |
4804 | --no-demangle Do not demangle low-level symbol names. (default)\n")); | |
4805 | fprintf (stream, _("\ | |
4806 | --recurse-limit Enable a demangling recursion limit. (default)\n")); | |
4807 | fprintf (stream, _("\ | |
4808 | --no-recurse-limit Disable a demangling recursion limit\n")); | |
4809 | fprintf (stream, _("\ | |
4810 | -n --notes Display the core notes (if present)\n")); | |
4811 | fprintf (stream, _("\ | |
4812 | -r --relocs Display the relocations (if present)\n")); | |
4813 | fprintf (stream, _("\ | |
4814 | -u --unwind Display the unwind info (if present)\n")); | |
4815 | fprintf (stream, _("\ | |
4816 | -d --dynamic Display the dynamic section (if present)\n")); | |
4817 | fprintf (stream, _("\ | |
4818 | -V --version-info Display the version sections (if present)\n")); | |
4819 | fprintf (stream, _("\ | |
4820 | -A --arch-specific Display architecture specific information (if any)\n")); | |
4821 | fprintf (stream, _("\ | |
4822 | -c --archive-index Display the symbol/file index in an archive\n")); | |
4823 | fprintf (stream, _("\ | |
4824 | -D --use-dynamic Use the dynamic section info when displaying symbols\n")); | |
4825 | fprintf (stream, _("\ | |
4826 | -L --lint|--enable-checks\n\ | |
4827 | Display warning messages for possible problems\n")); | |
4828 | fprintf (stream, _("\ | |
09c11c86 | 4829 | -x --hex-dump=<number|name>\n\ |
d6249f5f AM |
4830 | Dump the contents of section <number|name> as bytes\n")); |
4831 | fprintf (stream, _("\ | |
09c11c86 | 4832 | -p --string-dump=<number|name>\n\ |
d6249f5f AM |
4833 | Dump the contents of section <number|name> as strings\n")); |
4834 | fprintf (stream, _("\ | |
cf13d699 | 4835 | -R --relocated-dump=<number|name>\n\ |
d6249f5f AM |
4836 | Dump the relocated contents of section <number|name>\n")); |
4837 | fprintf (stream, _("\ | |
4838 | -z --decompress Decompress section before dumping it\n")); | |
4839 | fprintf (stream, _("\ | |
4840 | -w --debug-dump[a/=abbrev, A/=addr, r/=aranges, c/=cu_index, L/=decodedline,\n\ | |
4841 | f/=frames, F/=frames-interp, g/=gdb_index, i/=info, o/=loc,\n\ | |
4842 | m/=macro, p/=pubnames, t/=pubtypes, R/=Ranges, l/=rawline,\n\ | |
4843 | s/=str, O/=str-offsets, u/=trace_abbrev, T/=trace_aranges,\n\ | |
4844 | U/=trace_info]\n\ | |
4845 | Display the contents of DWARF debug sections\n")); | |
4846 | fprintf (stream, _("\ | |
4847 | -wk --debug-dump=links Display the contents of sections that link to separate\n\ | |
4848 | debuginfo files\n")); | |
4849 | fprintf (stream, _("\ | |
4850 | -P --process-links Display the contents of non-debug sections in separate\n\ | |
4851 | debuginfo files. (Implies -wK)\n")); | |
c46b7066 NC |
4852 | #if DEFAULT_FOR_FOLLOW_LINKS |
4853 | fprintf (stream, _("\ | |
d6249f5f AM |
4854 | -wK --debug-dump=follow-links\n\ |
4855 | Follow links to separate debug info files (default)\n")); | |
4856 | fprintf (stream, _("\ | |
4857 | -wN --debug-dump=no-follow-links\n\ | |
4858 | Do not follow links to separate debug info files\n")); | |
c46b7066 NC |
4859 | #else |
4860 | fprintf (stream, _("\ | |
d6249f5f AM |
4861 | -wK --debug-dump=follow-links\n\ |
4862 | Follow links to separate debug info files\n")); | |
4863 | fprintf (stream, _("\ | |
4864 | -wN --debug-dump=no-follow-links\n\ | |
4865 | Do not follow links to separate debug info files\n\ | |
4866 | (default)\n")); | |
c46b7066 | 4867 | #endif |
fd2f0033 | 4868 | fprintf (stream, _("\ |
d6249f5f AM |
4869 | --dwarf-depth=N Do not display DIEs at depth N or greater\n")); |
4870 | fprintf (stream, _("\ | |
4871 | --dwarf-start=N Display DIEs starting at offset N\n")); | |
094e34f2 | 4872 | #ifdef ENABLE_LIBCTF |
7d9813f1 | 4873 | fprintf (stream, _("\ |
d6249f5f AM |
4874 | --ctf=<number|name> Display CTF info from section <number|name>\n")); |
4875 | fprintf (stream, _("\ | |
80b56fad | 4876 | --ctf-parent=<name> Use CTF archive member <name> as the CTF parent\n")); |
d6249f5f | 4877 | fprintf (stream, _("\ |
7d9813f1 | 4878 | --ctf-symbols=<number|name>\n\ |
d6249f5f AM |
4879 | Use section <number|name> as the CTF external symtab\n")); |
4880 | fprintf (stream, _("\ | |
7d9813f1 | 4881 | --ctf-strings=<number|name>\n\ |
d6249f5f | 4882 | Use section <number|name> as the CTF external strtab\n")); |
094e34f2 | 4883 | #endif |
7d9813f1 | 4884 | |
252b5132 | 4885 | #ifdef SUPPORT_DISASSEMBLY |
92f01d61 | 4886 | fprintf (stream, _("\ |
09c11c86 NC |
4887 | -i --instruction-dump=<number|name>\n\ |
4888 | Disassemble the contents of section <number|name>\n")); | |
252b5132 | 4889 | #endif |
92f01d61 | 4890 | fprintf (stream, _("\ |
d6249f5f AM |
4891 | -I --histogram Display histogram of bucket list lengths\n")); |
4892 | fprintf (stream, _("\ | |
4893 | -W --wide Allow output width to exceed 80 characters\n")); | |
4894 | fprintf (stream, _("\ | |
4895 | -T --silent-truncation If a symbol name is truncated, do not add [...] suffix\n")); | |
4896 | fprintf (stream, _("\ | |
4897 | @<file> Read options from <file>\n")); | |
4898 | fprintf (stream, _("\ | |
4899 | -H --help Display this information\n")); | |
4900 | fprintf (stream, _("\ | |
8b53311e | 4901 | -v --version Display the version number of readelf\n")); |
1118d252 | 4902 | |
92f01d61 JM |
4903 | if (REPORT_BUGS_TO[0] && stream == stdout) |
4904 | fprintf (stdout, _("Report bugs to %s\n"), REPORT_BUGS_TO); | |
252b5132 | 4905 | |
92f01d61 | 4906 | exit (stream == stdout ? 0 : 1); |
252b5132 RH |
4907 | } |
4908 | ||
18bd398b NC |
4909 | /* Record the fact that the user wants the contents of section number |
4910 | SECTION to be displayed using the method(s) encoded as flags bits | |
4911 | in TYPE. Note, TYPE can be zero if we are creating the array for | |
4912 | the first time. */ | |
4913 | ||
252b5132 | 4914 | static void |
6431e409 AM |
4915 | request_dump_bynumber (struct dump_data *dumpdata, |
4916 | unsigned int section, dump_type type) | |
252b5132 | 4917 | { |
6431e409 | 4918 | if (section >= dumpdata->num_dump_sects) |
252b5132 | 4919 | { |
2cf0635d | 4920 | dump_type * new_dump_sects; |
252b5132 | 4921 | |
3f5e193b | 4922 | new_dump_sects = (dump_type *) calloc (section + 1, |
dda8d76d | 4923 | sizeof (* new_dump_sects)); |
252b5132 RH |
4924 | |
4925 | if (new_dump_sects == NULL) | |
591a748a | 4926 | error (_("Out of memory allocating dump request table.\n")); |
252b5132 RH |
4927 | else |
4928 | { | |
6431e409 | 4929 | if (dumpdata->dump_sects) |
21b65bac NC |
4930 | { |
4931 | /* Copy current flag settings. */ | |
6431e409 AM |
4932 | memcpy (new_dump_sects, dumpdata->dump_sects, |
4933 | dumpdata->num_dump_sects * sizeof (* new_dump_sects)); | |
252b5132 | 4934 | |
6431e409 | 4935 | free (dumpdata->dump_sects); |
21b65bac | 4936 | } |
252b5132 | 4937 | |
6431e409 AM |
4938 | dumpdata->dump_sects = new_dump_sects; |
4939 | dumpdata->num_dump_sects = section + 1; | |
252b5132 RH |
4940 | } |
4941 | } | |
4942 | ||
6431e409 AM |
4943 | if (dumpdata->dump_sects) |
4944 | dumpdata->dump_sects[section] |= type; | |
252b5132 RH |
4945 | } |
4946 | ||
aef1f6d0 DJ |
4947 | /* Request a dump by section name. */ |
4948 | ||
4949 | static void | |
2cf0635d | 4950 | request_dump_byname (const char * section, dump_type type) |
aef1f6d0 | 4951 | { |
2cf0635d | 4952 | struct dump_list_entry * new_request; |
aef1f6d0 | 4953 | |
3f5e193b NC |
4954 | new_request = (struct dump_list_entry *) |
4955 | malloc (sizeof (struct dump_list_entry)); | |
aef1f6d0 | 4956 | if (!new_request) |
591a748a | 4957 | error (_("Out of memory allocating dump request table.\n")); |
aef1f6d0 DJ |
4958 | |
4959 | new_request->name = strdup (section); | |
4960 | if (!new_request->name) | |
591a748a | 4961 | error (_("Out of memory allocating dump request table.\n")); |
aef1f6d0 DJ |
4962 | |
4963 | new_request->type = type; | |
4964 | ||
4965 | new_request->next = dump_sects_byname; | |
4966 | dump_sects_byname = new_request; | |
4967 | } | |
4968 | ||
cf13d699 | 4969 | static inline void |
6431e409 | 4970 | request_dump (struct dump_data *dumpdata, dump_type type) |
cf13d699 NC |
4971 | { |
4972 | int section; | |
4973 | char * cp; | |
4974 | ||
015dc7e1 | 4975 | do_dump = true; |
cf13d699 NC |
4976 | section = strtoul (optarg, & cp, 0); |
4977 | ||
4978 | if (! *cp && section >= 0) | |
6431e409 | 4979 | request_dump_bynumber (dumpdata, section, type); |
cf13d699 NC |
4980 | else |
4981 | request_dump_byname (optarg, type); | |
4982 | } | |
4983 | ||
252b5132 | 4984 | static void |
6431e409 | 4985 | parse_args (struct dump_data *dumpdata, int argc, char ** argv) |
252b5132 RH |
4986 | { |
4987 | int c; | |
4988 | ||
4989 | if (argc < 2) | |
92f01d61 | 4990 | usage (stderr); |
252b5132 RH |
4991 | |
4992 | while ((c = getopt_long | |
ca0e11aa | 4993 | (argc, argv, "ACDHILNPR:STVWacdeghi:lnp:rstuvw::x:z", options, NULL)) != EOF) |
252b5132 | 4994 | { |
252b5132 RH |
4995 | switch (c) |
4996 | { | |
4997 | case 0: | |
4998 | /* Long options. */ | |
4999 | break; | |
5000 | case 'H': | |
92f01d61 | 5001 | usage (stdout); |
252b5132 RH |
5002 | break; |
5003 | ||
5004 | case 'a': | |
015dc7e1 AM |
5005 | do_syms = true; |
5006 | do_reloc = true; | |
5007 | do_unwind = true; | |
5008 | do_dynamic = true; | |
5009 | do_header = true; | |
5010 | do_sections = true; | |
5011 | do_section_groups = true; | |
5012 | do_segments = true; | |
5013 | do_version = true; | |
5014 | do_histogram = true; | |
5015 | do_arch = true; | |
5016 | do_notes = true; | |
252b5132 | 5017 | break; |
79bc120c | 5018 | |
f5842774 | 5019 | case 'g': |
015dc7e1 | 5020 | do_section_groups = true; |
f5842774 | 5021 | break; |
5477e8a0 | 5022 | case 't': |
595cf52e | 5023 | case 'N': |
015dc7e1 AM |
5024 | do_sections = true; |
5025 | do_section_details = true; | |
595cf52e | 5026 | break; |
252b5132 | 5027 | case 'e': |
015dc7e1 AM |
5028 | do_header = true; |
5029 | do_sections = true; | |
5030 | do_segments = true; | |
252b5132 | 5031 | break; |
a952a375 | 5032 | case 'A': |
015dc7e1 | 5033 | do_arch = true; |
a952a375 | 5034 | break; |
252b5132 | 5035 | case 'D': |
015dc7e1 | 5036 | do_using_dynamic = true; |
252b5132 RH |
5037 | break; |
5038 | case 'r': | |
015dc7e1 | 5039 | do_reloc = true; |
252b5132 | 5040 | break; |
4d6ed7c8 | 5041 | case 'u': |
015dc7e1 | 5042 | do_unwind = true; |
4d6ed7c8 | 5043 | break; |
252b5132 | 5044 | case 'h': |
015dc7e1 | 5045 | do_header = true; |
252b5132 RH |
5046 | break; |
5047 | case 'l': | |
015dc7e1 | 5048 | do_segments = true; |
252b5132 RH |
5049 | break; |
5050 | case 's': | |
015dc7e1 | 5051 | do_syms = true; |
252b5132 RH |
5052 | break; |
5053 | case 'S': | |
015dc7e1 | 5054 | do_sections = true; |
252b5132 RH |
5055 | break; |
5056 | case 'd': | |
015dc7e1 | 5057 | do_dynamic = true; |
252b5132 | 5058 | break; |
a952a375 | 5059 | case 'I': |
015dc7e1 | 5060 | do_histogram = true; |
a952a375 | 5061 | break; |
779fe533 | 5062 | case 'n': |
015dc7e1 | 5063 | do_notes = true; |
779fe533 | 5064 | break; |
4145f1d5 | 5065 | case 'c': |
015dc7e1 | 5066 | do_archive_index = true; |
4145f1d5 | 5067 | break; |
1b513401 | 5068 | case 'L': |
015dc7e1 | 5069 | do_checks = true; |
1b513401 | 5070 | break; |
ca0e11aa | 5071 | case 'P': |
015dc7e1 AM |
5072 | process_links = true; |
5073 | do_follow_links = true; | |
ca0e11aa | 5074 | break; |
252b5132 | 5075 | case 'x': |
6431e409 | 5076 | request_dump (dumpdata, HEX_DUMP); |
aef1f6d0 | 5077 | break; |
09c11c86 | 5078 | case 'p': |
6431e409 | 5079 | request_dump (dumpdata, STRING_DUMP); |
cf13d699 NC |
5080 | break; |
5081 | case 'R': | |
6431e409 | 5082 | request_dump (dumpdata, RELOC_DUMP); |
09c11c86 | 5083 | break; |
0e602686 | 5084 | case 'z': |
015dc7e1 | 5085 | decompress_dumps = true; |
0e602686 | 5086 | break; |
252b5132 | 5087 | case 'w': |
015dc7e1 | 5088 | do_dump = true; |
0f03783c | 5089 | if (optarg == NULL) |
613ff48b | 5090 | { |
015dc7e1 | 5091 | do_debugging = true; |
613ff48b CC |
5092 | dwarf_select_sections_all (); |
5093 | } | |
252b5132 RH |
5094 | else |
5095 | { | |
015dc7e1 | 5096 | do_debugging = false; |
4cb93e3b | 5097 | dwarf_select_sections_by_letters (optarg); |
252b5132 RH |
5098 | } |
5099 | break; | |
2979dc34 | 5100 | case OPTION_DEBUG_DUMP: |
015dc7e1 | 5101 | do_dump = true; |
0f03783c | 5102 | if (optarg == NULL) |
d6249f5f AM |
5103 | { |
5104 | do_debugging = true; | |
5105 | dwarf_select_sections_all (); | |
5106 | } | |
2979dc34 JJ |
5107 | else |
5108 | { | |
015dc7e1 | 5109 | do_debugging = false; |
4cb93e3b | 5110 | dwarf_select_sections_by_names (optarg); |
2979dc34 JJ |
5111 | } |
5112 | break; | |
fd2f0033 TT |
5113 | case OPTION_DWARF_DEPTH: |
5114 | { | |
5115 | char *cp; | |
5116 | ||
5117 | dwarf_cutoff_level = strtoul (optarg, & cp, 0); | |
5118 | } | |
5119 | break; | |
5120 | case OPTION_DWARF_START: | |
5121 | { | |
5122 | char *cp; | |
5123 | ||
5124 | dwarf_start_die = strtoul (optarg, & cp, 0); | |
5125 | } | |
5126 | break; | |
4723351a | 5127 | case OPTION_DWARF_CHECK: |
015dc7e1 | 5128 | dwarf_check = true; |
4723351a | 5129 | break; |
7d9813f1 | 5130 | case OPTION_CTF_DUMP: |
015dc7e1 | 5131 | do_ctf = true; |
6431e409 | 5132 | request_dump (dumpdata, CTF_DUMP); |
7d9813f1 NA |
5133 | break; |
5134 | case OPTION_CTF_SYMBOLS: | |
df16e041 | 5135 | free (dump_ctf_symtab_name); |
7d9813f1 NA |
5136 | dump_ctf_symtab_name = strdup (optarg); |
5137 | break; | |
5138 | case OPTION_CTF_STRINGS: | |
df16e041 | 5139 | free (dump_ctf_strtab_name); |
7d9813f1 NA |
5140 | dump_ctf_strtab_name = strdup (optarg); |
5141 | break; | |
5142 | case OPTION_CTF_PARENT: | |
df16e041 | 5143 | free (dump_ctf_parent_name); |
7d9813f1 NA |
5144 | dump_ctf_parent_name = strdup (optarg); |
5145 | break; | |
2c610e4b | 5146 | case OPTION_DYN_SYMS: |
015dc7e1 | 5147 | do_dyn_syms = true; |
2c610e4b | 5148 | break; |
0f03783c | 5149 | case OPTION_LTO_SYMS: |
015dc7e1 | 5150 | do_lto_syms = true; |
0f03783c | 5151 | break; |
252b5132 RH |
5152 | #ifdef SUPPORT_DISASSEMBLY |
5153 | case 'i': | |
6431e409 | 5154 | request_dump (dumpdata, DISASS_DUMP); |
cf13d699 | 5155 | break; |
252b5132 RH |
5156 | #endif |
5157 | case 'v': | |
5158 | print_version (program_name); | |
5159 | break; | |
5160 | case 'V': | |
015dc7e1 | 5161 | do_version = true; |
252b5132 | 5162 | break; |
d974e256 | 5163 | case 'W': |
015dc7e1 | 5164 | do_wide = true; |
d974e256 | 5165 | break; |
0942c7ab | 5166 | case 'T': |
015dc7e1 | 5167 | do_not_show_symbol_truncation = true; |
0942c7ab | 5168 | break; |
79bc120c | 5169 | case 'C': |
015dc7e1 | 5170 | do_demangle = true; |
79bc120c NC |
5171 | if (optarg != NULL) |
5172 | { | |
5173 | enum demangling_styles style; | |
5174 | ||
5175 | style = cplus_demangle_name_to_style (optarg); | |
5176 | if (style == unknown_demangling) | |
5177 | error (_("unknown demangling style `%s'"), optarg); | |
5178 | ||
5179 | cplus_demangle_set_style (style); | |
5180 | } | |
5181 | break; | |
5182 | case OPTION_NO_DEMANGLING: | |
015dc7e1 | 5183 | do_demangle = false; |
79bc120c NC |
5184 | break; |
5185 | case OPTION_RECURSE_LIMIT: | |
5186 | demangle_flags &= ~ DMGL_NO_RECURSE_LIMIT; | |
5187 | break; | |
5188 | case OPTION_NO_RECURSE_LIMIT: | |
5189 | demangle_flags |= DMGL_NO_RECURSE_LIMIT; | |
5190 | break; | |
5191 | case OPTION_WITH_SYMBOL_VERSIONS: | |
5192 | /* Ignored for backward compatibility. */ | |
5193 | break; | |
b9e920ec | 5194 | |
047c3dbf NL |
5195 | case OPTION_SYM_BASE: |
5196 | sym_base = 0; | |
5197 | if (optarg != NULL) | |
5198 | { | |
5199 | sym_base = strtoul (optarg, NULL, 0); | |
5200 | switch (sym_base) | |
5201 | { | |
5202 | case 0: | |
5203 | case 8: | |
5204 | case 10: | |
5205 | case 16: | |
5206 | break; | |
5207 | ||
5208 | default: | |
5209 | sym_base = 0; | |
5210 | break; | |
5211 | } | |
5212 | } | |
5213 | break; | |
5214 | ||
252b5132 | 5215 | default: |
252b5132 RH |
5216 | /* xgettext:c-format */ |
5217 | error (_("Invalid option '-%c'\n"), c); | |
1a0670f3 | 5218 | /* Fall through. */ |
252b5132 | 5219 | case '?': |
92f01d61 | 5220 | usage (stderr); |
252b5132 RH |
5221 | } |
5222 | } | |
5223 | ||
4d6ed7c8 | 5224 | if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections |
252b5132 | 5225 | && !do_segments && !do_header && !do_dump && !do_version |
f5842774 | 5226 | && !do_histogram && !do_debugging && !do_arch && !do_notes |
2c610e4b | 5227 | && !do_section_groups && !do_archive_index |
0f03783c | 5228 | && !do_dyn_syms && !do_lto_syms) |
1b513401 NC |
5229 | { |
5230 | if (do_checks) | |
5231 | { | |
015dc7e1 AM |
5232 | check_all = true; |
5233 | do_dynamic = do_syms = do_reloc = do_unwind = do_sections = true; | |
5234 | do_segments = do_header = do_dump = do_version = true; | |
5235 | do_histogram = do_debugging = do_arch = do_notes = true; | |
5236 | do_section_groups = do_archive_index = do_dyn_syms = true; | |
5237 | do_lto_syms = true; | |
1b513401 NC |
5238 | } |
5239 | else | |
5240 | usage (stderr); | |
5241 | } | |
252b5132 RH |
5242 | } |
5243 | ||
5244 | static const char * | |
d3ba0551 | 5245 | get_elf_class (unsigned int elf_class) |
252b5132 | 5246 | { |
b34976b6 | 5247 | static char buff[32]; |
103f02d3 | 5248 | |
252b5132 RH |
5249 | switch (elf_class) |
5250 | { | |
5251 | case ELFCLASSNONE: return _("none"); | |
e3c8793a NC |
5252 | case ELFCLASS32: return "ELF32"; |
5253 | case ELFCLASS64: return "ELF64"; | |
ab5e7794 | 5254 | default: |
e9e44622 | 5255 | snprintf (buff, sizeof (buff), _("<unknown: %x>"), elf_class); |
ab5e7794 | 5256 | return buff; |
252b5132 RH |
5257 | } |
5258 | } | |
5259 | ||
5260 | static const char * | |
d3ba0551 | 5261 | get_data_encoding (unsigned int encoding) |
252b5132 | 5262 | { |
b34976b6 | 5263 | static char buff[32]; |
103f02d3 | 5264 | |
252b5132 RH |
5265 | switch (encoding) |
5266 | { | |
5267 | case ELFDATANONE: return _("none"); | |
33c63f9d CM |
5268 | case ELFDATA2LSB: return _("2's complement, little endian"); |
5269 | case ELFDATA2MSB: return _("2's complement, big endian"); | |
103f02d3 | 5270 | default: |
e9e44622 | 5271 | snprintf (buff, sizeof (buff), _("<unknown: %x>"), encoding); |
ab5e7794 | 5272 | return buff; |
252b5132 RH |
5273 | } |
5274 | } | |
5275 | ||
dda8d76d | 5276 | /* Decode the data held in 'filedata->file_header'. */ |
ee42cf8c | 5277 | |
015dc7e1 | 5278 | static bool |
dda8d76d | 5279 | process_file_header (Filedata * filedata) |
252b5132 | 5280 | { |
dda8d76d NC |
5281 | Elf_Internal_Ehdr * header = & filedata->file_header; |
5282 | ||
5283 | if ( header->e_ident[EI_MAG0] != ELFMAG0 | |
5284 | || header->e_ident[EI_MAG1] != ELFMAG1 | |
5285 | || header->e_ident[EI_MAG2] != ELFMAG2 | |
5286 | || header->e_ident[EI_MAG3] != ELFMAG3) | |
252b5132 RH |
5287 | { |
5288 | error | |
5289 | (_("Not an ELF file - it has the wrong magic bytes at the start\n")); | |
015dc7e1 | 5290 | return false; |
252b5132 RH |
5291 | } |
5292 | ||
ca0e11aa NC |
5293 | if (! filedata->is_separate) |
5294 | init_dwarf_regnames_by_elf_machine_code (header->e_machine); | |
2dc4cec1 | 5295 | |
252b5132 RH |
5296 | if (do_header) |
5297 | { | |
32ec8896 | 5298 | unsigned i; |
252b5132 | 5299 | |
ca0e11aa NC |
5300 | if (filedata->is_separate) |
5301 | printf (_("ELF Header in linked file '%s':\n"), filedata->file_name); | |
5302 | else | |
5303 | printf (_("ELF Header:\n")); | |
252b5132 | 5304 | printf (_(" Magic: ")); |
b34976b6 | 5305 | for (i = 0; i < EI_NIDENT; i++) |
dda8d76d | 5306 | printf ("%2.2x ", header->e_ident[i]); |
252b5132 RH |
5307 | printf ("\n"); |
5308 | printf (_(" Class: %s\n"), | |
dda8d76d | 5309 | get_elf_class (header->e_ident[EI_CLASS])); |
252b5132 | 5310 | printf (_(" Data: %s\n"), |
dda8d76d | 5311 | get_data_encoding (header->e_ident[EI_DATA])); |
e8a64888 | 5312 | printf (_(" Version: %d%s\n"), |
dda8d76d NC |
5313 | header->e_ident[EI_VERSION], |
5314 | (header->e_ident[EI_VERSION] == EV_CURRENT | |
e8a64888 | 5315 | ? _(" (current)") |
dda8d76d | 5316 | : (header->e_ident[EI_VERSION] != EV_NONE |
e8a64888 | 5317 | ? _(" <unknown>") |
789be9f7 | 5318 | : ""))); |
252b5132 | 5319 | printf (_(" OS/ABI: %s\n"), |
dda8d76d | 5320 | get_osabi_name (filedata, header->e_ident[EI_OSABI])); |
252b5132 | 5321 | printf (_(" ABI Version: %d\n"), |
dda8d76d | 5322 | header->e_ident[EI_ABIVERSION]); |
252b5132 | 5323 | printf (_(" Type: %s\n"), |
93df3340 | 5324 | get_file_type (filedata)); |
252b5132 | 5325 | printf (_(" Machine: %s\n"), |
dda8d76d | 5326 | get_machine_name (header->e_machine)); |
252b5132 | 5327 | printf (_(" Version: 0x%lx\n"), |
e8a64888 | 5328 | header->e_version); |
76da6bbe | 5329 | |
f7a99963 | 5330 | printf (_(" Entry point address: ")); |
e8a64888 | 5331 | print_vma (header->e_entry, PREFIX_HEX); |
f7a99963 | 5332 | printf (_("\n Start of program headers: ")); |
e8a64888 | 5333 | print_vma (header->e_phoff, DEC); |
f7a99963 | 5334 | printf (_(" (bytes into file)\n Start of section headers: ")); |
e8a64888 | 5335 | print_vma (header->e_shoff, DEC); |
f7a99963 | 5336 | printf (_(" (bytes into file)\n")); |
76da6bbe | 5337 | |
252b5132 | 5338 | printf (_(" Flags: 0x%lx%s\n"), |
e8a64888 | 5339 | header->e_flags, |
dda8d76d | 5340 | get_machine_flags (filedata, header->e_flags, header->e_machine)); |
e8a64888 AM |
5341 | printf (_(" Size of this header: %u (bytes)\n"), |
5342 | header->e_ehsize); | |
5343 | printf (_(" Size of program headers: %u (bytes)\n"), | |
5344 | header->e_phentsize); | |
5345 | printf (_(" Number of program headers: %u"), | |
5346 | header->e_phnum); | |
dda8d76d NC |
5347 | if (filedata->section_headers != NULL |
5348 | && header->e_phnum == PN_XNUM | |
5349 | && filedata->section_headers[0].sh_info != 0) | |
e8a64888 AM |
5350 | { |
5351 | header->e_phnum = filedata->section_headers[0].sh_info; | |
5352 | printf (" (%u)", header->e_phnum); | |
5353 | } | |
2046a35d | 5354 | putc ('\n', stdout); |
e8a64888 AM |
5355 | printf (_(" Size of section headers: %u (bytes)\n"), |
5356 | header->e_shentsize); | |
5357 | printf (_(" Number of section headers: %u"), | |
5358 | header->e_shnum); | |
dda8d76d | 5359 | if (filedata->section_headers != NULL && header->e_shnum == SHN_UNDEF) |
e8a64888 AM |
5360 | { |
5361 | header->e_shnum = filedata->section_headers[0].sh_size; | |
5362 | printf (" (%u)", header->e_shnum); | |
5363 | } | |
560f3c1c | 5364 | putc ('\n', stdout); |
e8a64888 AM |
5365 | printf (_(" Section header string table index: %u"), |
5366 | header->e_shstrndx); | |
dda8d76d NC |
5367 | if (filedata->section_headers != NULL |
5368 | && header->e_shstrndx == (SHN_XINDEX & 0xffff)) | |
e8a64888 AM |
5369 | { |
5370 | header->e_shstrndx = filedata->section_headers[0].sh_link; | |
5371 | printf (" (%u)", header->e_shstrndx); | |
5372 | } | |
5373 | if (header->e_shstrndx != SHN_UNDEF | |
5374 | && header->e_shstrndx >= header->e_shnum) | |
5375 | { | |
5376 | header->e_shstrndx = SHN_UNDEF; | |
5377 | printf (_(" <corrupt: out of range>")); | |
5378 | } | |
560f3c1c AM |
5379 | putc ('\n', stdout); |
5380 | } | |
5381 | ||
dda8d76d | 5382 | if (filedata->section_headers != NULL) |
560f3c1c | 5383 | { |
dda8d76d NC |
5384 | if (header->e_phnum == PN_XNUM |
5385 | && filedata->section_headers[0].sh_info != 0) | |
5386 | header->e_phnum = filedata->section_headers[0].sh_info; | |
5387 | if (header->e_shnum == SHN_UNDEF) | |
5388 | header->e_shnum = filedata->section_headers[0].sh_size; | |
5389 | if (header->e_shstrndx == (SHN_XINDEX & 0xffff)) | |
5390 | header->e_shstrndx = filedata->section_headers[0].sh_link; | |
9c1ce108 | 5391 | if (header->e_shstrndx >= header->e_shnum) |
dda8d76d | 5392 | header->e_shstrndx = SHN_UNDEF; |
252b5132 | 5393 | } |
103f02d3 | 5394 | |
015dc7e1 | 5395 | return true; |
9ea033b2 NC |
5396 | } |
5397 | ||
dda8d76d NC |
5398 | /* Read in the program headers from FILEDATA and store them in PHEADERS. |
5399 | Returns TRUE upon success, FALSE otherwise. Loads 32-bit headers. */ | |
5400 | ||
015dc7e1 | 5401 | static bool |
dda8d76d | 5402 | get_32bit_program_headers (Filedata * filedata, Elf_Internal_Phdr * pheaders) |
9ea033b2 | 5403 | { |
2cf0635d NC |
5404 | Elf32_External_Phdr * phdrs; |
5405 | Elf32_External_Phdr * external; | |
5406 | Elf_Internal_Phdr * internal; | |
b34976b6 | 5407 | unsigned int i; |
dda8d76d NC |
5408 | unsigned int size = filedata->file_header.e_phentsize; |
5409 | unsigned int num = filedata->file_header.e_phnum; | |
e0a31db1 NC |
5410 | |
5411 | /* PR binutils/17531: Cope with unexpected section header sizes. */ | |
5412 | if (size == 0 || num == 0) | |
015dc7e1 | 5413 | return false; |
e0a31db1 NC |
5414 | if (size < sizeof * phdrs) |
5415 | { | |
5416 | error (_("The e_phentsize field in the ELF header is less than the size of an ELF program header\n")); | |
015dc7e1 | 5417 | return false; |
e0a31db1 NC |
5418 | } |
5419 | if (size > sizeof * phdrs) | |
5420 | warn (_("The e_phentsize field in the ELF header is larger than the size of an ELF program header\n")); | |
103f02d3 | 5421 | |
dda8d76d | 5422 | phdrs = (Elf32_External_Phdr *) get_data (NULL, filedata, filedata->file_header.e_phoff, |
e0a31db1 NC |
5423 | size, num, _("program headers")); |
5424 | if (phdrs == NULL) | |
015dc7e1 | 5425 | return false; |
9ea033b2 | 5426 | |
91d6fa6a | 5427 | for (i = 0, internal = pheaders, external = phdrs; |
dda8d76d | 5428 | i < filedata->file_header.e_phnum; |
b34976b6 | 5429 | i++, internal++, external++) |
252b5132 | 5430 | { |
9ea033b2 NC |
5431 | internal->p_type = BYTE_GET (external->p_type); |
5432 | internal->p_offset = BYTE_GET (external->p_offset); | |
5433 | internal->p_vaddr = BYTE_GET (external->p_vaddr); | |
5434 | internal->p_paddr = BYTE_GET (external->p_paddr); | |
5435 | internal->p_filesz = BYTE_GET (external->p_filesz); | |
5436 | internal->p_memsz = BYTE_GET (external->p_memsz); | |
5437 | internal->p_flags = BYTE_GET (external->p_flags); | |
5438 | internal->p_align = BYTE_GET (external->p_align); | |
252b5132 RH |
5439 | } |
5440 | ||
9ea033b2 | 5441 | free (phdrs); |
015dc7e1 | 5442 | return true; |
252b5132 RH |
5443 | } |
5444 | ||
dda8d76d NC |
5445 | /* Read in the program headers from FILEDATA and store them in PHEADERS. |
5446 | Returns TRUE upon success, FALSE otherwise. Loads 64-bit headers. */ | |
5447 | ||
015dc7e1 | 5448 | static bool |
dda8d76d | 5449 | get_64bit_program_headers (Filedata * filedata, Elf_Internal_Phdr * pheaders) |
9ea033b2 | 5450 | { |
2cf0635d NC |
5451 | Elf64_External_Phdr * phdrs; |
5452 | Elf64_External_Phdr * external; | |
5453 | Elf_Internal_Phdr * internal; | |
b34976b6 | 5454 | unsigned int i; |
dda8d76d NC |
5455 | unsigned int size = filedata->file_header.e_phentsize; |
5456 | unsigned int num = filedata->file_header.e_phnum; | |
e0a31db1 NC |
5457 | |
5458 | /* PR binutils/17531: Cope with unexpected section header sizes. */ | |
5459 | if (size == 0 || num == 0) | |
015dc7e1 | 5460 | return false; |
e0a31db1 NC |
5461 | if (size < sizeof * phdrs) |
5462 | { | |
5463 | error (_("The e_phentsize field in the ELF header is less than the size of an ELF program header\n")); | |
015dc7e1 | 5464 | return false; |
e0a31db1 NC |
5465 | } |
5466 | if (size > sizeof * phdrs) | |
5467 | warn (_("The e_phentsize field in the ELF header is larger than the size of an ELF program header\n")); | |
103f02d3 | 5468 | |
dda8d76d | 5469 | phdrs = (Elf64_External_Phdr *) get_data (NULL, filedata, filedata->file_header.e_phoff, |
e0a31db1 | 5470 | size, num, _("program headers")); |
a6e9f9df | 5471 | if (!phdrs) |
015dc7e1 | 5472 | return false; |
9ea033b2 | 5473 | |
91d6fa6a | 5474 | for (i = 0, internal = pheaders, external = phdrs; |
dda8d76d | 5475 | i < filedata->file_header.e_phnum; |
b34976b6 | 5476 | i++, internal++, external++) |
9ea033b2 NC |
5477 | { |
5478 | internal->p_type = BYTE_GET (external->p_type); | |
5479 | internal->p_flags = BYTE_GET (external->p_flags); | |
66543521 AM |
5480 | internal->p_offset = BYTE_GET (external->p_offset); |
5481 | internal->p_vaddr = BYTE_GET (external->p_vaddr); | |
5482 | internal->p_paddr = BYTE_GET (external->p_paddr); | |
5483 | internal->p_filesz = BYTE_GET (external->p_filesz); | |
5484 | internal->p_memsz = BYTE_GET (external->p_memsz); | |
5485 | internal->p_align = BYTE_GET (external->p_align); | |
9ea033b2 NC |
5486 | } |
5487 | ||
5488 | free (phdrs); | |
015dc7e1 | 5489 | return true; |
9ea033b2 | 5490 | } |
252b5132 | 5491 | |
32ec8896 | 5492 | /* Returns TRUE if the program headers were read into `program_headers'. */ |
d93f0186 | 5493 | |
015dc7e1 | 5494 | static bool |
dda8d76d | 5495 | get_program_headers (Filedata * filedata) |
d93f0186 | 5496 | { |
2cf0635d | 5497 | Elf_Internal_Phdr * phdrs; |
d93f0186 NC |
5498 | |
5499 | /* Check cache of prior read. */ | |
dda8d76d | 5500 | if (filedata->program_headers != NULL) |
015dc7e1 | 5501 | return true; |
d93f0186 | 5502 | |
82156ab7 NC |
5503 | /* Be kind to memory checkers by looking for |
5504 | e_phnum values which we know must be invalid. */ | |
dda8d76d | 5505 | if (filedata->file_header.e_phnum |
82156ab7 | 5506 | * (is_32bit_elf ? sizeof (Elf32_External_Phdr) : sizeof (Elf64_External_Phdr)) |
dda8d76d | 5507 | >= filedata->file_size) |
82156ab7 NC |
5508 | { |
5509 | error (_("Too many program headers - %#x - the file is not that big\n"), | |
dda8d76d | 5510 | filedata->file_header.e_phnum); |
015dc7e1 | 5511 | return false; |
82156ab7 | 5512 | } |
d93f0186 | 5513 | |
dda8d76d | 5514 | phdrs = (Elf_Internal_Phdr *) cmalloc (filedata->file_header.e_phnum, |
82156ab7 | 5515 | sizeof (Elf_Internal_Phdr)); |
d93f0186 NC |
5516 | if (phdrs == NULL) |
5517 | { | |
8b73c356 | 5518 | error (_("Out of memory reading %u program headers\n"), |
dda8d76d | 5519 | filedata->file_header.e_phnum); |
015dc7e1 | 5520 | return false; |
d93f0186 NC |
5521 | } |
5522 | ||
5523 | if (is_32bit_elf | |
dda8d76d NC |
5524 | ? get_32bit_program_headers (filedata, phdrs) |
5525 | : get_64bit_program_headers (filedata, phdrs)) | |
d93f0186 | 5526 | { |
dda8d76d | 5527 | filedata->program_headers = phdrs; |
015dc7e1 | 5528 | return true; |
d93f0186 NC |
5529 | } |
5530 | ||
5531 | free (phdrs); | |
015dc7e1 | 5532 | return false; |
d93f0186 NC |
5533 | } |
5534 | ||
93df3340 | 5535 | /* Print program header info and locate dynamic section. */ |
2f62977e | 5536 | |
93df3340 | 5537 | static void |
dda8d76d | 5538 | process_program_headers (Filedata * filedata) |
252b5132 | 5539 | { |
2cf0635d | 5540 | Elf_Internal_Phdr * segment; |
b34976b6 | 5541 | unsigned int i; |
1a9ccd70 | 5542 | Elf_Internal_Phdr * previous_load = NULL; |
252b5132 | 5543 | |
dda8d76d | 5544 | if (filedata->file_header.e_phnum == 0) |
252b5132 | 5545 | { |
82f2dbf7 | 5546 | /* PR binutils/12467. */ |
dda8d76d | 5547 | if (filedata->file_header.e_phoff != 0) |
93df3340 AM |
5548 | warn (_("possibly corrupt ELF header - it has a non-zero program" |
5549 | " header offset, but no program headers\n")); | |
82f2dbf7 | 5550 | else if (do_segments) |
ca0e11aa NC |
5551 | { |
5552 | if (filedata->is_separate) | |
5553 | printf (_("\nThere are no program headers in linked file '%s'.\n"), | |
5554 | filedata->file_name); | |
5555 | else | |
5556 | printf (_("\nThere are no program headers in this file.\n")); | |
5557 | } | |
93df3340 | 5558 | goto no_headers; |
252b5132 RH |
5559 | } |
5560 | ||
5561 | if (do_segments && !do_header) | |
5562 | { | |
ca0e11aa NC |
5563 | if (filedata->is_separate) |
5564 | printf ("\nIn linked file '%s' the ELF file type is %s\n", | |
93df3340 | 5565 | filedata->file_name, get_file_type (filedata)); |
ca0e11aa | 5566 | else |
93df3340 | 5567 | printf (_("\nElf file type is %s\n"), get_file_type (filedata)); |
dda8d76d | 5568 | printf (_("Entry point 0x%s\n"), bfd_vmatoa ("x", filedata->file_header.e_entry)); |
d3a49aa8 AM |
5569 | printf (ngettext ("There is %d program header, starting at offset %s\n", |
5570 | "There are %d program headers, starting at offset %s\n", | |
dda8d76d NC |
5571 | filedata->file_header.e_phnum), |
5572 | filedata->file_header.e_phnum, | |
5573 | bfd_vmatoa ("u", filedata->file_header.e_phoff)); | |
252b5132 RH |
5574 | } |
5575 | ||
dda8d76d | 5576 | if (! get_program_headers (filedata)) |
93df3340 | 5577 | goto no_headers; |
103f02d3 | 5578 | |
252b5132 RH |
5579 | if (do_segments) |
5580 | { | |
dda8d76d | 5581 | if (filedata->file_header.e_phnum > 1) |
3a1a2036 NC |
5582 | printf (_("\nProgram Headers:\n")); |
5583 | else | |
5584 | printf (_("\nProgram Headers:\n")); | |
76da6bbe | 5585 | |
f7a99963 NC |
5586 | if (is_32bit_elf) |
5587 | printf | |
5588 | (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n")); | |
d974e256 JJ |
5589 | else if (do_wide) |
5590 | printf | |
5591 | (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n")); | |
f7a99963 NC |
5592 | else |
5593 | { | |
5594 | printf | |
5595 | (_(" Type Offset VirtAddr PhysAddr\n")); | |
5596 | printf | |
5597 | (_(" FileSiz MemSiz Flags Align\n")); | |
5598 | } | |
252b5132 RH |
5599 | } |
5600 | ||
93df3340 AM |
5601 | unsigned long dynamic_addr = 0; |
5602 | bfd_size_type dynamic_size = 0; | |
dda8d76d NC |
5603 | for (i = 0, segment = filedata->program_headers; |
5604 | i < filedata->file_header.e_phnum; | |
b34976b6 | 5605 | i++, segment++) |
252b5132 RH |
5606 | { |
5607 | if (do_segments) | |
5608 | { | |
dda8d76d | 5609 | printf (" %-14.14s ", get_segment_type (filedata, segment->p_type)); |
f7a99963 NC |
5610 | |
5611 | if (is_32bit_elf) | |
5612 | { | |
5613 | printf ("0x%6.6lx ", (unsigned long) segment->p_offset); | |
5614 | printf ("0x%8.8lx ", (unsigned long) segment->p_vaddr); | |
5615 | printf ("0x%8.8lx ", (unsigned long) segment->p_paddr); | |
5616 | printf ("0x%5.5lx ", (unsigned long) segment->p_filesz); | |
5617 | printf ("0x%5.5lx ", (unsigned long) segment->p_memsz); | |
5618 | printf ("%c%c%c ", | |
5619 | (segment->p_flags & PF_R ? 'R' : ' '), | |
5620 | (segment->p_flags & PF_W ? 'W' : ' '), | |
5621 | (segment->p_flags & PF_X ? 'E' : ' ')); | |
5622 | printf ("%#lx", (unsigned long) segment->p_align); | |
5623 | } | |
d974e256 JJ |
5624 | else if (do_wide) |
5625 | { | |
5626 | if ((unsigned long) segment->p_offset == segment->p_offset) | |
5627 | printf ("0x%6.6lx ", (unsigned long) segment->p_offset); | |
5628 | else | |
5629 | { | |
5630 | print_vma (segment->p_offset, FULL_HEX); | |
5631 | putchar (' '); | |
5632 | } | |
5633 | ||
5634 | print_vma (segment->p_vaddr, FULL_HEX); | |
5635 | putchar (' '); | |
5636 | print_vma (segment->p_paddr, FULL_HEX); | |
5637 | putchar (' '); | |
5638 | ||
5639 | if ((unsigned long) segment->p_filesz == segment->p_filesz) | |
5640 | printf ("0x%6.6lx ", (unsigned long) segment->p_filesz); | |
5641 | else | |
5642 | { | |
5643 | print_vma (segment->p_filesz, FULL_HEX); | |
5644 | putchar (' '); | |
5645 | } | |
5646 | ||
5647 | if ((unsigned long) segment->p_memsz == segment->p_memsz) | |
5648 | printf ("0x%6.6lx", (unsigned long) segment->p_memsz); | |
5649 | else | |
5650 | { | |
f48e6c45 | 5651 | print_vma (segment->p_memsz, FULL_HEX); |
d974e256 JJ |
5652 | } |
5653 | ||
5654 | printf (" %c%c%c ", | |
5655 | (segment->p_flags & PF_R ? 'R' : ' '), | |
5656 | (segment->p_flags & PF_W ? 'W' : ' '), | |
5657 | (segment->p_flags & PF_X ? 'E' : ' ')); | |
5658 | ||
5659 | if ((unsigned long) segment->p_align == segment->p_align) | |
5660 | printf ("%#lx", (unsigned long) segment->p_align); | |
5661 | else | |
5662 | { | |
5663 | print_vma (segment->p_align, PREFIX_HEX); | |
5664 | } | |
5665 | } | |
f7a99963 NC |
5666 | else |
5667 | { | |
5668 | print_vma (segment->p_offset, FULL_HEX); | |
5669 | putchar (' '); | |
5670 | print_vma (segment->p_vaddr, FULL_HEX); | |
5671 | putchar (' '); | |
5672 | print_vma (segment->p_paddr, FULL_HEX); | |
5673 | printf ("\n "); | |
5674 | print_vma (segment->p_filesz, FULL_HEX); | |
5675 | putchar (' '); | |
5676 | print_vma (segment->p_memsz, FULL_HEX); | |
5677 | printf (" %c%c%c ", | |
5678 | (segment->p_flags & PF_R ? 'R' : ' '), | |
5679 | (segment->p_flags & PF_W ? 'W' : ' '), | |
5680 | (segment->p_flags & PF_X ? 'E' : ' ')); | |
1d262527 | 5681 | print_vma (segment->p_align, PREFIX_HEX); |
f7a99963 | 5682 | } |
252b5132 | 5683 | |
1a9ccd70 NC |
5684 | putc ('\n', stdout); |
5685 | } | |
f54498b4 | 5686 | |
252b5132 RH |
5687 | switch (segment->p_type) |
5688 | { | |
1a9ccd70 | 5689 | case PT_LOAD: |
502d895c NC |
5690 | #if 0 /* Do not warn about out of order PT_LOAD segments. Although officially |
5691 | required by the ELF standard, several programs, including the Linux | |
5692 | kernel, make use of non-ordered segments. */ | |
1a9ccd70 NC |
5693 | if (previous_load |
5694 | && previous_load->p_vaddr > segment->p_vaddr) | |
5695 | error (_("LOAD segments must be sorted in order of increasing VirtAddr\n")); | |
502d895c | 5696 | #endif |
1a9ccd70 NC |
5697 | if (segment->p_memsz < segment->p_filesz) |
5698 | error (_("the segment's file size is larger than its memory size\n")); | |
5699 | previous_load = segment; | |
5700 | break; | |
5701 | ||
5702 | case PT_PHDR: | |
5703 | /* PR 20815 - Verify that the program header is loaded into memory. */ | |
5704 | if (i > 0 && previous_load != NULL) | |
5705 | error (_("the PHDR segment must occur before any LOAD segment\n")); | |
dda8d76d | 5706 | if (filedata->file_header.e_machine != EM_PARISC) |
1a9ccd70 NC |
5707 | { |
5708 | unsigned int j; | |
5709 | ||
dda8d76d | 5710 | for (j = 1; j < filedata->file_header.e_phnum; j++) |
c0c121b0 AM |
5711 | { |
5712 | Elf_Internal_Phdr *load = filedata->program_headers + j; | |
5713 | if (load->p_type == PT_LOAD | |
5714 | && load->p_offset <= segment->p_offset | |
5715 | && (load->p_offset + load->p_filesz | |
5716 | >= segment->p_offset + segment->p_filesz) | |
5717 | && load->p_vaddr <= segment->p_vaddr | |
5718 | && (load->p_vaddr + load->p_filesz | |
5719 | >= segment->p_vaddr + segment->p_filesz)) | |
5720 | break; | |
5721 | } | |
dda8d76d | 5722 | if (j == filedata->file_header.e_phnum) |
1a9ccd70 NC |
5723 | error (_("the PHDR segment is not covered by a LOAD segment\n")); |
5724 | } | |
5725 | break; | |
5726 | ||
252b5132 | 5727 | case PT_DYNAMIC: |
93df3340 | 5728 | if (dynamic_addr) |
252b5132 RH |
5729 | error (_("more than one dynamic segment\n")); |
5730 | ||
20737c13 AM |
5731 | /* By default, assume that the .dynamic section is the first |
5732 | section in the DYNAMIC segment. */ | |
93df3340 AM |
5733 | dynamic_addr = segment->p_offset; |
5734 | dynamic_size = segment->p_filesz; | |
20737c13 | 5735 | |
b2d38a17 NC |
5736 | /* Try to locate the .dynamic section. If there is |
5737 | a section header table, we can easily locate it. */ | |
dda8d76d | 5738 | if (filedata->section_headers != NULL) |
b2d38a17 | 5739 | { |
2cf0635d | 5740 | Elf_Internal_Shdr * sec; |
b2d38a17 | 5741 | |
dda8d76d | 5742 | sec = find_section (filedata, ".dynamic"); |
89fac5e3 | 5743 | if (sec == NULL || sec->sh_size == 0) |
b2d38a17 | 5744 | { |
93df3340 AM |
5745 | /* A corresponding .dynamic section is expected, but on |
5746 | IA-64/OpenVMS it is OK for it to be missing. */ | |
5747 | if (!is_ia64_vms (filedata)) | |
5748 | error (_("no .dynamic section in the dynamic segment\n")); | |
b2d38a17 NC |
5749 | break; |
5750 | } | |
5751 | ||
42bb2e33 | 5752 | if (sec->sh_type == SHT_NOBITS) |
20737c13 | 5753 | { |
93df3340 AM |
5754 | dynamic_addr = 0; |
5755 | dynamic_size = 0; | |
20737c13 AM |
5756 | break; |
5757 | } | |
42bb2e33 | 5758 | |
93df3340 AM |
5759 | dynamic_addr = sec->sh_offset; |
5760 | dynamic_size = sec->sh_size; | |
b2d38a17 | 5761 | |
8ac10c5b L |
5762 | /* The PT_DYNAMIC segment, which is used by the run-time |
5763 | loader, should exactly match the .dynamic section. */ | |
5764 | if (do_checks | |
93df3340 AM |
5765 | && (dynamic_addr != segment->p_offset |
5766 | || dynamic_size != segment->p_filesz)) | |
8ac10c5b L |
5767 | warn (_("\ |
5768 | the .dynamic section is not the same as the dynamic segment\n")); | |
b2d38a17 | 5769 | } |
39e224f6 MW |
5770 | |
5771 | /* PR binutils/17512: Avoid corrupt dynamic section info in the | |
5772 | segment. Check this after matching against the section headers | |
5773 | so we don't warn on debuginfo file (which have NOBITS .dynamic | |
5774 | sections). */ | |
93df3340 AM |
5775 | if (dynamic_addr > filedata->file_size |
5776 | || (dynamic_size > filedata->file_size - dynamic_addr)) | |
39e224f6 MW |
5777 | { |
5778 | error (_("the dynamic segment offset + size exceeds the size of the file\n")); | |
93df3340 AM |
5779 | dynamic_addr = 0; |
5780 | dynamic_size = 0; | |
39e224f6 | 5781 | } |
252b5132 RH |
5782 | break; |
5783 | ||
5784 | case PT_INTERP: | |
13acb58d AM |
5785 | if (segment->p_offset >= filedata->file_size |
5786 | || segment->p_filesz > filedata->file_size - segment->p_offset | |
5787 | || segment->p_filesz - 1 >= (size_t) -2 | |
5788 | || fseek (filedata->handle, | |
5789 | filedata->archive_file_offset + (long) segment->p_offset, | |
5790 | SEEK_SET)) | |
252b5132 RH |
5791 | error (_("Unable to find program interpreter name\n")); |
5792 | else | |
5793 | { | |
13acb58d AM |
5794 | size_t len = segment->p_filesz; |
5795 | free (filedata->program_interpreter); | |
5796 | filedata->program_interpreter = xmalloc (len + 1); | |
5797 | len = fread (filedata->program_interpreter, 1, len, | |
5798 | filedata->handle); | |
5799 | filedata->program_interpreter[len] = 0; | |
252b5132 RH |
5800 | |
5801 | if (do_segments) | |
f54498b4 | 5802 | printf (_(" [Requesting program interpreter: %s]\n"), |
978c4450 | 5803 | filedata->program_interpreter); |
252b5132 RH |
5804 | } |
5805 | break; | |
5806 | } | |
252b5132 RH |
5807 | } |
5808 | ||
dda8d76d NC |
5809 | if (do_segments |
5810 | && filedata->section_headers != NULL | |
5811 | && filedata->string_table != NULL) | |
252b5132 RH |
5812 | { |
5813 | printf (_("\n Section to Segment mapping:\n")); | |
5814 | printf (_(" Segment Sections...\n")); | |
5815 | ||
dda8d76d | 5816 | for (i = 0; i < filedata->file_header.e_phnum; i++) |
252b5132 | 5817 | { |
9ad5cbcf | 5818 | unsigned int j; |
2cf0635d | 5819 | Elf_Internal_Shdr * section; |
252b5132 | 5820 | |
dda8d76d NC |
5821 | segment = filedata->program_headers + i; |
5822 | section = filedata->section_headers + 1; | |
252b5132 RH |
5823 | |
5824 | printf (" %2.2d ", i); | |
5825 | ||
dda8d76d | 5826 | for (j = 1; j < filedata->file_header.e_shnum; j++, section++) |
252b5132 | 5827 | { |
f4638467 AM |
5828 | if (!ELF_TBSS_SPECIAL (section, segment) |
5829 | && ELF_SECTION_IN_SEGMENT_STRICT (section, segment)) | |
dda8d76d | 5830 | printf ("%s ", printable_section_name (filedata, section)); |
252b5132 RH |
5831 | } |
5832 | ||
5833 | putc ('\n',stdout); | |
5834 | } | |
5835 | } | |
5836 | ||
93df3340 AM |
5837 | filedata->dynamic_addr = dynamic_addr; |
5838 | filedata->dynamic_size = dynamic_size ? dynamic_size : 1; | |
5839 | return; | |
5840 | ||
5841 | no_headers: | |
5842 | filedata->dynamic_addr = 0; | |
5843 | filedata->dynamic_size = 1; | |
252b5132 RH |
5844 | } |
5845 | ||
5846 | ||
d93f0186 NC |
5847 | /* Find the file offset corresponding to VMA by using the program headers. */ |
5848 | ||
5849 | static long | |
dda8d76d | 5850 | offset_from_vma (Filedata * filedata, bfd_vma vma, bfd_size_type size) |
d93f0186 | 5851 | { |
2cf0635d | 5852 | Elf_Internal_Phdr * seg; |
d93f0186 | 5853 | |
dda8d76d | 5854 | if (! get_program_headers (filedata)) |
d93f0186 NC |
5855 | { |
5856 | warn (_("Cannot interpret virtual addresses without program headers.\n")); | |
5857 | return (long) vma; | |
5858 | } | |
5859 | ||
dda8d76d NC |
5860 | for (seg = filedata->program_headers; |
5861 | seg < filedata->program_headers + filedata->file_header.e_phnum; | |
d93f0186 NC |
5862 | ++seg) |
5863 | { | |
5864 | if (seg->p_type != PT_LOAD) | |
5865 | continue; | |
5866 | ||
5867 | if (vma >= (seg->p_vaddr & -seg->p_align) | |
5868 | && vma + size <= seg->p_vaddr + seg->p_filesz) | |
5869 | return vma - seg->p_vaddr + seg->p_offset; | |
5870 | } | |
5871 | ||
5872 | warn (_("Virtual address 0x%lx not located in any PT_LOAD segment.\n"), | |
0af1713e | 5873 | (unsigned long) vma); |
d93f0186 NC |
5874 | return (long) vma; |
5875 | } | |
5876 | ||
5877 | ||
dda8d76d NC |
5878 | /* Allocate memory and load the sections headers into FILEDATA->filedata->section_headers. |
5879 | If PROBE is true, this is just a probe and we do not generate any error | |
5880 | messages if the load fails. */ | |
049b0c3a | 5881 | |
015dc7e1 AM |
5882 | static bool |
5883 | get_32bit_section_headers (Filedata * filedata, bool probe) | |
252b5132 | 5884 | { |
2cf0635d NC |
5885 | Elf32_External_Shdr * shdrs; |
5886 | Elf_Internal_Shdr * internal; | |
dda8d76d NC |
5887 | unsigned int i; |
5888 | unsigned int size = filedata->file_header.e_shentsize; | |
5889 | unsigned int num = probe ? 1 : filedata->file_header.e_shnum; | |
049b0c3a NC |
5890 | |
5891 | /* PR binutils/17531: Cope with unexpected section header sizes. */ | |
5892 | if (size == 0 || num == 0) | |
015dc7e1 | 5893 | return false; |
049b0c3a NC |
5894 | if (size < sizeof * shdrs) |
5895 | { | |
5896 | if (! probe) | |
5897 | error (_("The e_shentsize field in the ELF header is less than the size of an ELF section header\n")); | |
015dc7e1 | 5898 | return false; |
049b0c3a NC |
5899 | } |
5900 | if (!probe && size > sizeof * shdrs) | |
5901 | warn (_("The e_shentsize field in the ELF header is larger than the size of an ELF section header\n")); | |
252b5132 | 5902 | |
dda8d76d | 5903 | shdrs = (Elf32_External_Shdr *) get_data (NULL, filedata, filedata->file_header.e_shoff, |
049b0c3a NC |
5904 | size, num, |
5905 | probe ? NULL : _("section headers")); | |
5906 | if (shdrs == NULL) | |
015dc7e1 | 5907 | return false; |
252b5132 | 5908 | |
dda8d76d NC |
5909 | filedata->section_headers = (Elf_Internal_Shdr *) |
5910 | cmalloc (num, sizeof (Elf_Internal_Shdr)); | |
5911 | if (filedata->section_headers == NULL) | |
252b5132 | 5912 | { |
049b0c3a | 5913 | if (!probe) |
8b73c356 | 5914 | error (_("Out of memory reading %u section headers\n"), num); |
e3d39609 | 5915 | free (shdrs); |
015dc7e1 | 5916 | return false; |
252b5132 RH |
5917 | } |
5918 | ||
dda8d76d | 5919 | for (i = 0, internal = filedata->section_headers; |
560f3c1c | 5920 | i < num; |
b34976b6 | 5921 | i++, internal++) |
252b5132 RH |
5922 | { |
5923 | internal->sh_name = BYTE_GET (shdrs[i].sh_name); | |
5924 | internal->sh_type = BYTE_GET (shdrs[i].sh_type); | |
5925 | internal->sh_flags = BYTE_GET (shdrs[i].sh_flags); | |
5926 | internal->sh_addr = BYTE_GET (shdrs[i].sh_addr); | |
5927 | internal->sh_offset = BYTE_GET (shdrs[i].sh_offset); | |
5928 | internal->sh_size = BYTE_GET (shdrs[i].sh_size); | |
5929 | internal->sh_link = BYTE_GET (shdrs[i].sh_link); | |
5930 | internal->sh_info = BYTE_GET (shdrs[i].sh_info); | |
5931 | internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign); | |
5932 | internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize); | |
315350be NC |
5933 | if (!probe && internal->sh_link > num) |
5934 | warn (_("Section %u has an out of range sh_link value of %u\n"), i, internal->sh_link); | |
5935 | if (!probe && internal->sh_flags & SHF_INFO_LINK && internal->sh_info > num) | |
5936 | warn (_("Section %u has an out of range sh_info value of %u\n"), i, internal->sh_info); | |
252b5132 RH |
5937 | } |
5938 | ||
5939 | free (shdrs); | |
015dc7e1 | 5940 | return true; |
252b5132 RH |
5941 | } |
5942 | ||
dda8d76d NC |
5943 | /* Like get_32bit_section_headers, except that it fetches 64-bit headers. */ |
5944 | ||
015dc7e1 AM |
5945 | static bool |
5946 | get_64bit_section_headers (Filedata * filedata, bool probe) | |
9ea033b2 | 5947 | { |
dda8d76d NC |
5948 | Elf64_External_Shdr * shdrs; |
5949 | Elf_Internal_Shdr * internal; | |
5950 | unsigned int i; | |
5951 | unsigned int size = filedata->file_header.e_shentsize; | |
5952 | unsigned int num = probe ? 1 : filedata->file_header.e_shnum; | |
049b0c3a NC |
5953 | |
5954 | /* PR binutils/17531: Cope with unexpected section header sizes. */ | |
5955 | if (size == 0 || num == 0) | |
015dc7e1 | 5956 | return false; |
dda8d76d | 5957 | |
049b0c3a NC |
5958 | if (size < sizeof * shdrs) |
5959 | { | |
5960 | if (! probe) | |
5961 | error (_("The e_shentsize field in the ELF header is less than the size of an ELF section header\n")); | |
015dc7e1 | 5962 | return false; |
049b0c3a | 5963 | } |
dda8d76d | 5964 | |
049b0c3a NC |
5965 | if (! probe && size > sizeof * shdrs) |
5966 | warn (_("The e_shentsize field in the ELF header is larger than the size of an ELF section header\n")); | |
9ea033b2 | 5967 | |
dda8d76d NC |
5968 | shdrs = (Elf64_External_Shdr *) get_data (NULL, filedata, |
5969 | filedata->file_header.e_shoff, | |
049b0c3a NC |
5970 | size, num, |
5971 | probe ? NULL : _("section headers")); | |
5972 | if (shdrs == NULL) | |
015dc7e1 | 5973 | return false; |
9ea033b2 | 5974 | |
dda8d76d NC |
5975 | filedata->section_headers = (Elf_Internal_Shdr *) |
5976 | cmalloc (num, sizeof (Elf_Internal_Shdr)); | |
5977 | if (filedata->section_headers == NULL) | |
9ea033b2 | 5978 | { |
049b0c3a | 5979 | if (! probe) |
8b73c356 | 5980 | error (_("Out of memory reading %u section headers\n"), num); |
e3d39609 | 5981 | free (shdrs); |
015dc7e1 | 5982 | return false; |
9ea033b2 NC |
5983 | } |
5984 | ||
dda8d76d | 5985 | for (i = 0, internal = filedata->section_headers; |
560f3c1c | 5986 | i < num; |
b34976b6 | 5987 | i++, internal++) |
9ea033b2 NC |
5988 | { |
5989 | internal->sh_name = BYTE_GET (shdrs[i].sh_name); | |
5990 | internal->sh_type = BYTE_GET (shdrs[i].sh_type); | |
66543521 AM |
5991 | internal->sh_flags = BYTE_GET (shdrs[i].sh_flags); |
5992 | internal->sh_addr = BYTE_GET (shdrs[i].sh_addr); | |
5993 | internal->sh_size = BYTE_GET (shdrs[i].sh_size); | |
5994 | internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize); | |
9ea033b2 NC |
5995 | internal->sh_link = BYTE_GET (shdrs[i].sh_link); |
5996 | internal->sh_info = BYTE_GET (shdrs[i].sh_info); | |
5997 | internal->sh_offset = BYTE_GET (shdrs[i].sh_offset); | |
5998 | internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign); | |
315350be NC |
5999 | if (!probe && internal->sh_link > num) |
6000 | warn (_("Section %u has an out of range sh_link value of %u\n"), i, internal->sh_link); | |
6001 | if (!probe && internal->sh_flags & SHF_INFO_LINK && internal->sh_info > num) | |
6002 | warn (_("Section %u has an out of range sh_info value of %u\n"), i, internal->sh_info); | |
9ea033b2 NC |
6003 | } |
6004 | ||
6005 | free (shdrs); | |
015dc7e1 | 6006 | return true; |
9ea033b2 NC |
6007 | } |
6008 | ||
4de91c10 AM |
6009 | static bool |
6010 | get_section_headers (Filedata *filedata, bool probe) | |
6011 | { | |
6012 | if (filedata->section_headers != NULL) | |
6013 | return true; | |
6014 | ||
4de91c10 AM |
6015 | if (is_32bit_elf) |
6016 | return get_32bit_section_headers (filedata, probe); | |
6017 | else | |
6018 | return get_64bit_section_headers (filedata, probe); | |
6019 | } | |
6020 | ||
252b5132 | 6021 | static Elf_Internal_Sym * |
dda8d76d NC |
6022 | get_32bit_elf_symbols (Filedata * filedata, |
6023 | Elf_Internal_Shdr * section, | |
6024 | unsigned long * num_syms_return) | |
252b5132 | 6025 | { |
ba5cdace | 6026 | unsigned long number = 0; |
dd24e3da | 6027 | Elf32_External_Sym * esyms = NULL; |
ba5cdace | 6028 | Elf_External_Sym_Shndx * shndx = NULL; |
dd24e3da | 6029 | Elf_Internal_Sym * isyms = NULL; |
2cf0635d | 6030 | Elf_Internal_Sym * psym; |
b34976b6 | 6031 | unsigned int j; |
e3d39609 | 6032 | elf_section_list * entry; |
252b5132 | 6033 | |
c9c1d674 EG |
6034 | if (section->sh_size == 0) |
6035 | { | |
6036 | if (num_syms_return != NULL) | |
6037 | * num_syms_return = 0; | |
6038 | return NULL; | |
6039 | } | |
6040 | ||
dd24e3da | 6041 | /* Run some sanity checks first. */ |
c9c1d674 | 6042 | if (section->sh_entsize == 0 || section->sh_entsize > section->sh_size) |
dd24e3da | 6043 | { |
c9c1d674 | 6044 | error (_("Section %s has an invalid sh_entsize of 0x%lx\n"), |
dda8d76d NC |
6045 | printable_section_name (filedata, section), |
6046 | (unsigned long) section->sh_entsize); | |
ba5cdace | 6047 | goto exit_point; |
dd24e3da NC |
6048 | } |
6049 | ||
dda8d76d | 6050 | if (section->sh_size > filedata->file_size) |
f54498b4 NC |
6051 | { |
6052 | error (_("Section %s has an invalid sh_size of 0x%lx\n"), | |
dda8d76d NC |
6053 | printable_section_name (filedata, section), |
6054 | (unsigned long) section->sh_size); | |
f54498b4 NC |
6055 | goto exit_point; |
6056 | } | |
6057 | ||
dd24e3da NC |
6058 | number = section->sh_size / section->sh_entsize; |
6059 | ||
6060 | if (number * sizeof (Elf32_External_Sym) > section->sh_size + 1) | |
6061 | { | |
c9c1d674 | 6062 | error (_("Size (0x%lx) of section %s is not a multiple of its sh_entsize (0x%lx)\n"), |
8066deb1 | 6063 | (unsigned long) section->sh_size, |
dda8d76d | 6064 | printable_section_name (filedata, section), |
8066deb1 | 6065 | (unsigned long) section->sh_entsize); |
ba5cdace | 6066 | goto exit_point; |
dd24e3da NC |
6067 | } |
6068 | ||
dda8d76d | 6069 | esyms = (Elf32_External_Sym *) get_data (NULL, filedata, section->sh_offset, 1, |
3f5e193b | 6070 | section->sh_size, _("symbols")); |
dd24e3da | 6071 | if (esyms == NULL) |
ba5cdace | 6072 | goto exit_point; |
252b5132 | 6073 | |
e3d39609 | 6074 | shndx = NULL; |
978c4450 | 6075 | for (entry = filedata->symtab_shndx_list; entry != NULL; entry = entry->next) |
e3d39609 NC |
6076 | { |
6077 | if (entry->hdr->sh_link != (unsigned long) (section - filedata->section_headers)) | |
6078 | continue; | |
6079 | ||
6080 | if (shndx != NULL) | |
6081 | { | |
6082 | error (_("Multiple symbol table index sections associated with the same symbol section\n")); | |
6083 | free (shndx); | |
6084 | } | |
6085 | ||
6086 | shndx = (Elf_External_Sym_Shndx *) get_data (NULL, filedata, | |
6087 | entry->hdr->sh_offset, | |
6088 | 1, entry->hdr->sh_size, | |
6089 | _("symbol table section indices")); | |
6090 | if (shndx == NULL) | |
6091 | goto exit_point; | |
6092 | ||
6093 | /* PR17531: file: heap-buffer-overflow */ | |
6094 | if (entry->hdr->sh_size / sizeof (Elf_External_Sym_Shndx) < number) | |
6095 | { | |
6096 | error (_("Index section %s has an sh_size of 0x%lx - expected 0x%lx\n"), | |
6097 | printable_section_name (filedata, entry->hdr), | |
6098 | (unsigned long) entry->hdr->sh_size, | |
6099 | (unsigned long) section->sh_size); | |
6100 | goto exit_point; | |
c9c1d674 | 6101 | } |
e3d39609 | 6102 | } |
9ad5cbcf | 6103 | |
3f5e193b | 6104 | isyms = (Elf_Internal_Sym *) cmalloc (number, sizeof (Elf_Internal_Sym)); |
252b5132 RH |
6105 | |
6106 | if (isyms == NULL) | |
6107 | { | |
8b73c356 NC |
6108 | error (_("Out of memory reading %lu symbols\n"), |
6109 | (unsigned long) number); | |
dd24e3da | 6110 | goto exit_point; |
252b5132 RH |
6111 | } |
6112 | ||
dd24e3da | 6113 | for (j = 0, psym = isyms; j < number; j++, psym++) |
252b5132 RH |
6114 | { |
6115 | psym->st_name = BYTE_GET (esyms[j].st_name); | |
6116 | psym->st_value = BYTE_GET (esyms[j].st_value); | |
6117 | psym->st_size = BYTE_GET (esyms[j].st_size); | |
6118 | psym->st_shndx = BYTE_GET (esyms[j].st_shndx); | |
4fbb74a6 | 6119 | if (psym->st_shndx == (SHN_XINDEX & 0xffff) && shndx != NULL) |
9ad5cbcf AM |
6120 | psym->st_shndx |
6121 | = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j])); | |
4fbb74a6 AM |
6122 | else if (psym->st_shndx >= (SHN_LORESERVE & 0xffff)) |
6123 | psym->st_shndx += SHN_LORESERVE - (SHN_LORESERVE & 0xffff); | |
252b5132 RH |
6124 | psym->st_info = BYTE_GET (esyms[j].st_info); |
6125 | psym->st_other = BYTE_GET (esyms[j].st_other); | |
6126 | } | |
6127 | ||
dd24e3da | 6128 | exit_point: |
e3d39609 NC |
6129 | free (shndx); |
6130 | free (esyms); | |
252b5132 | 6131 | |
ba5cdace NC |
6132 | if (num_syms_return != NULL) |
6133 | * num_syms_return = isyms == NULL ? 0 : number; | |
6134 | ||
252b5132 RH |
6135 | return isyms; |
6136 | } | |
6137 | ||
9ea033b2 | 6138 | static Elf_Internal_Sym * |
dda8d76d NC |
6139 | get_64bit_elf_symbols (Filedata * filedata, |
6140 | Elf_Internal_Shdr * section, | |
6141 | unsigned long * num_syms_return) | |
9ea033b2 | 6142 | { |
ba5cdace NC |
6143 | unsigned long number = 0; |
6144 | Elf64_External_Sym * esyms = NULL; | |
6145 | Elf_External_Sym_Shndx * shndx = NULL; | |
6146 | Elf_Internal_Sym * isyms = NULL; | |
2cf0635d | 6147 | Elf_Internal_Sym * psym; |
b34976b6 | 6148 | unsigned int j; |
e3d39609 | 6149 | elf_section_list * entry; |
9ea033b2 | 6150 | |
c9c1d674 EG |
6151 | if (section->sh_size == 0) |
6152 | { | |
6153 | if (num_syms_return != NULL) | |
6154 | * num_syms_return = 0; | |
6155 | return NULL; | |
6156 | } | |
6157 | ||
dd24e3da | 6158 | /* Run some sanity checks first. */ |
c9c1d674 | 6159 | if (section->sh_entsize == 0 || section->sh_entsize > section->sh_size) |
dd24e3da | 6160 | { |
c9c1d674 | 6161 | error (_("Section %s has an invalid sh_entsize of 0x%lx\n"), |
dda8d76d | 6162 | printable_section_name (filedata, section), |
8066deb1 | 6163 | (unsigned long) section->sh_entsize); |
ba5cdace | 6164 | goto exit_point; |
dd24e3da NC |
6165 | } |
6166 | ||
dda8d76d | 6167 | if (section->sh_size > filedata->file_size) |
f54498b4 NC |
6168 | { |
6169 | error (_("Section %s has an invalid sh_size of 0x%lx\n"), | |
dda8d76d | 6170 | printable_section_name (filedata, section), |
8066deb1 | 6171 | (unsigned long) section->sh_size); |
f54498b4 NC |
6172 | goto exit_point; |
6173 | } | |
6174 | ||
dd24e3da NC |
6175 | number = section->sh_size / section->sh_entsize; |
6176 | ||
6177 | if (number * sizeof (Elf64_External_Sym) > section->sh_size + 1) | |
6178 | { | |
c9c1d674 | 6179 | error (_("Size (0x%lx) of section %s is not a multiple of its sh_entsize (0x%lx)\n"), |
8066deb1 | 6180 | (unsigned long) section->sh_size, |
dda8d76d | 6181 | printable_section_name (filedata, section), |
8066deb1 | 6182 | (unsigned long) section->sh_entsize); |
ba5cdace | 6183 | goto exit_point; |
dd24e3da NC |
6184 | } |
6185 | ||
dda8d76d | 6186 | esyms = (Elf64_External_Sym *) get_data (NULL, filedata, section->sh_offset, 1, |
3f5e193b | 6187 | section->sh_size, _("symbols")); |
a6e9f9df | 6188 | if (!esyms) |
ba5cdace | 6189 | goto exit_point; |
9ea033b2 | 6190 | |
e3d39609 | 6191 | shndx = NULL; |
978c4450 | 6192 | for (entry = filedata->symtab_shndx_list; entry != NULL; entry = entry->next) |
e3d39609 NC |
6193 | { |
6194 | if (entry->hdr->sh_link != (unsigned long) (section - filedata->section_headers)) | |
6195 | continue; | |
6196 | ||
6197 | if (shndx != NULL) | |
6198 | { | |
6199 | error (_("Multiple symbol table index sections associated with the same symbol section\n")); | |
6200 | free (shndx); | |
c9c1d674 | 6201 | } |
e3d39609 NC |
6202 | |
6203 | shndx = (Elf_External_Sym_Shndx *) get_data (NULL, filedata, | |
6204 | entry->hdr->sh_offset, | |
6205 | 1, entry->hdr->sh_size, | |
6206 | _("symbol table section indices")); | |
6207 | if (shndx == NULL) | |
6208 | goto exit_point; | |
6209 | ||
6210 | /* PR17531: file: heap-buffer-overflow */ | |
6211 | if (entry->hdr->sh_size / sizeof (Elf_External_Sym_Shndx) < number) | |
6212 | { | |
6213 | error (_("Index section %s has an sh_size of 0x%lx - expected 0x%lx\n"), | |
6214 | printable_section_name (filedata, entry->hdr), | |
6215 | (unsigned long) entry->hdr->sh_size, | |
6216 | (unsigned long) section->sh_size); | |
6217 | goto exit_point; | |
6218 | } | |
6219 | } | |
9ad5cbcf | 6220 | |
3f5e193b | 6221 | isyms = (Elf_Internal_Sym *) cmalloc (number, sizeof (Elf_Internal_Sym)); |
9ea033b2 NC |
6222 | |
6223 | if (isyms == NULL) | |
6224 | { | |
8b73c356 NC |
6225 | error (_("Out of memory reading %lu symbols\n"), |
6226 | (unsigned long) number); | |
ba5cdace | 6227 | goto exit_point; |
9ea033b2 NC |
6228 | } |
6229 | ||
ba5cdace | 6230 | for (j = 0, psym = isyms; j < number; j++, psym++) |
9ea033b2 NC |
6231 | { |
6232 | psym->st_name = BYTE_GET (esyms[j].st_name); | |
6233 | psym->st_info = BYTE_GET (esyms[j].st_info); | |
6234 | psym->st_other = BYTE_GET (esyms[j].st_other); | |
6235 | psym->st_shndx = BYTE_GET (esyms[j].st_shndx); | |
ba5cdace | 6236 | |
4fbb74a6 | 6237 | if (psym->st_shndx == (SHN_XINDEX & 0xffff) && shndx != NULL) |
9ad5cbcf AM |
6238 | psym->st_shndx |
6239 | = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j])); | |
4fbb74a6 AM |
6240 | else if (psym->st_shndx >= (SHN_LORESERVE & 0xffff)) |
6241 | psym->st_shndx += SHN_LORESERVE - (SHN_LORESERVE & 0xffff); | |
ba5cdace | 6242 | |
66543521 AM |
6243 | psym->st_value = BYTE_GET (esyms[j].st_value); |
6244 | psym->st_size = BYTE_GET (esyms[j].st_size); | |
9ea033b2 NC |
6245 | } |
6246 | ||
ba5cdace | 6247 | exit_point: |
e3d39609 NC |
6248 | free (shndx); |
6249 | free (esyms); | |
ba5cdace NC |
6250 | |
6251 | if (num_syms_return != NULL) | |
6252 | * num_syms_return = isyms == NULL ? 0 : number; | |
9ea033b2 NC |
6253 | |
6254 | return isyms; | |
6255 | } | |
6256 | ||
4de91c10 AM |
6257 | static Elf_Internal_Sym * |
6258 | get_elf_symbols (Filedata *filedata, | |
6259 | Elf_Internal_Shdr *section, | |
6260 | unsigned long *num_syms_return) | |
6261 | { | |
6262 | if (is_32bit_elf) | |
6263 | return get_32bit_elf_symbols (filedata, section, num_syms_return); | |
6264 | else | |
6265 | return get_64bit_elf_symbols (filedata, section, num_syms_return); | |
6266 | } | |
6267 | ||
d1133906 | 6268 | static const char * |
dda8d76d | 6269 | get_elf_section_flags (Filedata * filedata, bfd_vma sh_flags) |
d1133906 | 6270 | { |
5477e8a0 | 6271 | static char buff[1024]; |
2cf0635d | 6272 | char * p = buff; |
32ec8896 NC |
6273 | unsigned int field_size = is_32bit_elf ? 8 : 16; |
6274 | signed int sindex; | |
6275 | unsigned int size = sizeof (buff) - (field_size + 4 + 1); | |
8d5ff12c L |
6276 | bfd_vma os_flags = 0; |
6277 | bfd_vma proc_flags = 0; | |
6278 | bfd_vma unknown_flags = 0; | |
148b93f2 | 6279 | static const struct |
5477e8a0 | 6280 | { |
2cf0635d | 6281 | const char * str; |
32ec8896 | 6282 | unsigned int len; |
5477e8a0 L |
6283 | } |
6284 | flags [] = | |
6285 | { | |
cfcac11d NC |
6286 | /* 0 */ { STRING_COMMA_LEN ("WRITE") }, |
6287 | /* 1 */ { STRING_COMMA_LEN ("ALLOC") }, | |
6288 | /* 2 */ { STRING_COMMA_LEN ("EXEC") }, | |
6289 | /* 3 */ { STRING_COMMA_LEN ("MERGE") }, | |
6290 | /* 4 */ { STRING_COMMA_LEN ("STRINGS") }, | |
6291 | /* 5 */ { STRING_COMMA_LEN ("INFO LINK") }, | |
6292 | /* 6 */ { STRING_COMMA_LEN ("LINK ORDER") }, | |
6293 | /* 7 */ { STRING_COMMA_LEN ("OS NONCONF") }, | |
6294 | /* 8 */ { STRING_COMMA_LEN ("GROUP") }, | |
6295 | /* 9 */ { STRING_COMMA_LEN ("TLS") }, | |
6296 | /* IA-64 specific. */ | |
6297 | /* 10 */ { STRING_COMMA_LEN ("SHORT") }, | |
6298 | /* 11 */ { STRING_COMMA_LEN ("NORECOV") }, | |
6299 | /* IA-64 OpenVMS specific. */ | |
6300 | /* 12 */ { STRING_COMMA_LEN ("VMS_GLOBAL") }, | |
6301 | /* 13 */ { STRING_COMMA_LEN ("VMS_OVERLAID") }, | |
6302 | /* 14 */ { STRING_COMMA_LEN ("VMS_SHARED") }, | |
6303 | /* 15 */ { STRING_COMMA_LEN ("VMS_VECTOR") }, | |
6304 | /* 16 */ { STRING_COMMA_LEN ("VMS_ALLOC_64BIT") }, | |
6305 | /* 17 */ { STRING_COMMA_LEN ("VMS_PROTECTED") }, | |
18ae9cc1 | 6306 | /* Generic. */ |
cfcac11d | 6307 | /* 18 */ { STRING_COMMA_LEN ("EXCLUDE") }, |
18ae9cc1 | 6308 | /* SPARC specific. */ |
77115a4a | 6309 | /* 19 */ { STRING_COMMA_LEN ("ORDERED") }, |
ac4c9b04 MG |
6310 | /* 20 */ { STRING_COMMA_LEN ("COMPRESSED") }, |
6311 | /* ARM specific. */ | |
6312 | /* 21 */ { STRING_COMMA_LEN ("ENTRYSECT") }, | |
f0728ee3 | 6313 | /* 22 */ { STRING_COMMA_LEN ("ARM_PURECODE") }, |
a91e1603 L |
6314 | /* 23 */ { STRING_COMMA_LEN ("COMDEF") }, |
6315 | /* GNU specific. */ | |
6316 | /* 24 */ { STRING_COMMA_LEN ("GNU_MBIND") }, | |
83eef883 AFB |
6317 | /* VLE specific. */ |
6318 | /* 25 */ { STRING_COMMA_LEN ("VLE") }, | |
99fabbc9 JL |
6319 | /* GNU specific. */ |
6320 | /* 26 */ { STRING_COMMA_LEN ("GNU_RETAIN") }, | |
5477e8a0 L |
6321 | }; |
6322 | ||
6323 | if (do_section_details) | |
6324 | { | |
8d5ff12c L |
6325 | sprintf (buff, "[%*.*lx]: ", |
6326 | field_size, field_size, (unsigned long) sh_flags); | |
6327 | p += field_size + 4; | |
5477e8a0 | 6328 | } |
76da6bbe | 6329 | |
d1133906 NC |
6330 | while (sh_flags) |
6331 | { | |
6332 | bfd_vma flag; | |
6333 | ||
6334 | flag = sh_flags & - sh_flags; | |
6335 | sh_flags &= ~ flag; | |
76da6bbe | 6336 | |
5477e8a0 | 6337 | if (do_section_details) |
d1133906 | 6338 | { |
5477e8a0 L |
6339 | switch (flag) |
6340 | { | |
91d6fa6a NC |
6341 | case SHF_WRITE: sindex = 0; break; |
6342 | case SHF_ALLOC: sindex = 1; break; | |
6343 | case SHF_EXECINSTR: sindex = 2; break; | |
6344 | case SHF_MERGE: sindex = 3; break; | |
6345 | case SHF_STRINGS: sindex = 4; break; | |
6346 | case SHF_INFO_LINK: sindex = 5; break; | |
6347 | case SHF_LINK_ORDER: sindex = 6; break; | |
6348 | case SHF_OS_NONCONFORMING: sindex = 7; break; | |
6349 | case SHF_GROUP: sindex = 8; break; | |
6350 | case SHF_TLS: sindex = 9; break; | |
18ae9cc1 | 6351 | case SHF_EXCLUDE: sindex = 18; break; |
77115a4a | 6352 | case SHF_COMPRESSED: sindex = 20; break; |
76da6bbe | 6353 | |
5477e8a0 | 6354 | default: |
91d6fa6a | 6355 | sindex = -1; |
dda8d76d | 6356 | switch (filedata->file_header.e_machine) |
148b93f2 | 6357 | { |
cfcac11d | 6358 | case EM_IA_64: |
148b93f2 | 6359 | if (flag == SHF_IA_64_SHORT) |
91d6fa6a | 6360 | sindex = 10; |
148b93f2 | 6361 | else if (flag == SHF_IA_64_NORECOV) |
91d6fa6a | 6362 | sindex = 11; |
148b93f2 | 6363 | #ifdef BFD64 |
dda8d76d | 6364 | else if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_OPENVMS) |
148b93f2 NC |
6365 | switch (flag) |
6366 | { | |
91d6fa6a NC |
6367 | case SHF_IA_64_VMS_GLOBAL: sindex = 12; break; |
6368 | case SHF_IA_64_VMS_OVERLAID: sindex = 13; break; | |
6369 | case SHF_IA_64_VMS_SHARED: sindex = 14; break; | |
6370 | case SHF_IA_64_VMS_VECTOR: sindex = 15; break; | |
6371 | case SHF_IA_64_VMS_ALLOC_64BIT: sindex = 16; break; | |
6372 | case SHF_IA_64_VMS_PROTECTED: sindex = 17; break; | |
148b93f2 NC |
6373 | default: break; |
6374 | } | |
6375 | #endif | |
cfcac11d NC |
6376 | break; |
6377 | ||
caa83f8b | 6378 | case EM_386: |
22abe556 | 6379 | case EM_IAMCU: |
caa83f8b | 6380 | case EM_X86_64: |
7f502d6c | 6381 | case EM_L1OM: |
7a9068fe | 6382 | case EM_K1OM: |
cfcac11d NC |
6383 | case EM_OLD_SPARCV9: |
6384 | case EM_SPARC32PLUS: | |
6385 | case EM_SPARCV9: | |
6386 | case EM_SPARC: | |
18ae9cc1 | 6387 | if (flag == SHF_ORDERED) |
91d6fa6a | 6388 | sindex = 19; |
cfcac11d | 6389 | break; |
ac4c9b04 MG |
6390 | |
6391 | case EM_ARM: | |
6392 | switch (flag) | |
6393 | { | |
6394 | case SHF_ENTRYSECT: sindex = 21; break; | |
f0728ee3 | 6395 | case SHF_ARM_PURECODE: sindex = 22; break; |
ac4c9b04 MG |
6396 | case SHF_COMDEF: sindex = 23; break; |
6397 | default: break; | |
6398 | } | |
6399 | break; | |
83eef883 AFB |
6400 | case EM_PPC: |
6401 | if (flag == SHF_PPC_VLE) | |
6402 | sindex = 25; | |
6403 | break; | |
99fabbc9 JL |
6404 | default: |
6405 | break; | |
6406 | } | |
ac4c9b04 | 6407 | |
99fabbc9 JL |
6408 | switch (filedata->file_header.e_ident[EI_OSABI]) |
6409 | { | |
6410 | case ELFOSABI_GNU: | |
6411 | case ELFOSABI_FREEBSD: | |
6412 | if (flag == SHF_GNU_RETAIN) | |
6413 | sindex = 26; | |
6414 | /* Fall through */ | |
6415 | case ELFOSABI_NONE: | |
6416 | if (flag == SHF_GNU_MBIND) | |
6417 | /* We should not recognize SHF_GNU_MBIND for | |
6418 | ELFOSABI_NONE, but binutils as of 2019-07-23 did | |
6419 | not set the EI_OSABI header byte. */ | |
6420 | sindex = 24; | |
6421 | break; | |
cfcac11d NC |
6422 | default: |
6423 | break; | |
148b93f2 | 6424 | } |
99fabbc9 | 6425 | break; |
5477e8a0 L |
6426 | } |
6427 | ||
91d6fa6a | 6428 | if (sindex != -1) |
5477e8a0 | 6429 | { |
8d5ff12c L |
6430 | if (p != buff + field_size + 4) |
6431 | { | |
6432 | if (size < (10 + 2)) | |
bee0ee85 NC |
6433 | { |
6434 | warn (_("Internal error: not enough buffer room for section flag info")); | |
6435 | return _("<unknown>"); | |
6436 | } | |
8d5ff12c L |
6437 | size -= 2; |
6438 | *p++ = ','; | |
6439 | *p++ = ' '; | |
6440 | } | |
6441 | ||
91d6fa6a NC |
6442 | size -= flags [sindex].len; |
6443 | p = stpcpy (p, flags [sindex].str); | |
5477e8a0 | 6444 | } |
3b22753a | 6445 | else if (flag & SHF_MASKOS) |
8d5ff12c | 6446 | os_flags |= flag; |
d1133906 | 6447 | else if (flag & SHF_MASKPROC) |
8d5ff12c | 6448 | proc_flags |= flag; |
d1133906 | 6449 | else |
8d5ff12c | 6450 | unknown_flags |= flag; |
5477e8a0 L |
6451 | } |
6452 | else | |
6453 | { | |
6454 | switch (flag) | |
6455 | { | |
6456 | case SHF_WRITE: *p = 'W'; break; | |
6457 | case SHF_ALLOC: *p = 'A'; break; | |
6458 | case SHF_EXECINSTR: *p = 'X'; break; | |
6459 | case SHF_MERGE: *p = 'M'; break; | |
6460 | case SHF_STRINGS: *p = 'S'; break; | |
6461 | case SHF_INFO_LINK: *p = 'I'; break; | |
6462 | case SHF_LINK_ORDER: *p = 'L'; break; | |
6463 | case SHF_OS_NONCONFORMING: *p = 'O'; break; | |
6464 | case SHF_GROUP: *p = 'G'; break; | |
6465 | case SHF_TLS: *p = 'T'; break; | |
18ae9cc1 | 6466 | case SHF_EXCLUDE: *p = 'E'; break; |
77115a4a | 6467 | case SHF_COMPRESSED: *p = 'C'; break; |
5477e8a0 L |
6468 | |
6469 | default: | |
dda8d76d NC |
6470 | if ((filedata->file_header.e_machine == EM_X86_64 |
6471 | || filedata->file_header.e_machine == EM_L1OM | |
6472 | || filedata->file_header.e_machine == EM_K1OM) | |
5477e8a0 L |
6473 | && flag == SHF_X86_64_LARGE) |
6474 | *p = 'l'; | |
dda8d76d | 6475 | else if (filedata->file_header.e_machine == EM_ARM |
f0728ee3 | 6476 | && flag == SHF_ARM_PURECODE) |
99fabbc9 | 6477 | *p = 'y'; |
dda8d76d | 6478 | else if (filedata->file_header.e_machine == EM_PPC |
83eef883 | 6479 | && flag == SHF_PPC_VLE) |
99fabbc9 | 6480 | *p = 'v'; |
5477e8a0 L |
6481 | else if (flag & SHF_MASKOS) |
6482 | { | |
99fabbc9 JL |
6483 | switch (filedata->file_header.e_ident[EI_OSABI]) |
6484 | { | |
6485 | case ELFOSABI_GNU: | |
6486 | case ELFOSABI_FREEBSD: | |
6487 | if (flag == SHF_GNU_RETAIN) | |
6488 | { | |
6489 | *p = 'R'; | |
6490 | break; | |
6491 | } | |
6492 | /* Fall through */ | |
6493 | case ELFOSABI_NONE: | |
6494 | if (flag == SHF_GNU_MBIND) | |
6495 | { | |
6496 | /* We should not recognize SHF_GNU_MBIND for | |
6497 | ELFOSABI_NONE, but binutils as of 2019-07-23 did | |
6498 | not set the EI_OSABI header byte. */ | |
6499 | *p = 'D'; | |
6500 | break; | |
6501 | } | |
6502 | /* Fall through */ | |
6503 | default: | |
6504 | *p = 'o'; | |
6505 | sh_flags &= ~SHF_MASKOS; | |
6506 | break; | |
6507 | } | |
5477e8a0 L |
6508 | } |
6509 | else if (flag & SHF_MASKPROC) | |
6510 | { | |
6511 | *p = 'p'; | |
6512 | sh_flags &= ~ SHF_MASKPROC; | |
6513 | } | |
6514 | else | |
6515 | *p = 'x'; | |
6516 | break; | |
6517 | } | |
6518 | p++; | |
d1133906 NC |
6519 | } |
6520 | } | |
76da6bbe | 6521 | |
8d5ff12c L |
6522 | if (do_section_details) |
6523 | { | |
6524 | if (os_flags) | |
6525 | { | |
6526 | size -= 5 + field_size; | |
6527 | if (p != buff + field_size + 4) | |
6528 | { | |
6529 | if (size < (2 + 1)) | |
bee0ee85 NC |
6530 | { |
6531 | warn (_("Internal error: not enough buffer room for section flag info")); | |
6532 | return _("<unknown>"); | |
6533 | } | |
8d5ff12c L |
6534 | size -= 2; |
6535 | *p++ = ','; | |
6536 | *p++ = ' '; | |
6537 | } | |
6538 | sprintf (p, "OS (%*.*lx)", field_size, field_size, | |
6539 | (unsigned long) os_flags); | |
6540 | p += 5 + field_size; | |
6541 | } | |
6542 | if (proc_flags) | |
6543 | { | |
6544 | size -= 7 + field_size; | |
6545 | if (p != buff + field_size + 4) | |
6546 | { | |
6547 | if (size < (2 + 1)) | |
bee0ee85 NC |
6548 | { |
6549 | warn (_("Internal error: not enough buffer room for section flag info")); | |
6550 | return _("<unknown>"); | |
6551 | } | |
8d5ff12c L |
6552 | size -= 2; |
6553 | *p++ = ','; | |
6554 | *p++ = ' '; | |
6555 | } | |
6556 | sprintf (p, "PROC (%*.*lx)", field_size, field_size, | |
6557 | (unsigned long) proc_flags); | |
6558 | p += 7 + field_size; | |
6559 | } | |
6560 | if (unknown_flags) | |
6561 | { | |
6562 | size -= 10 + field_size; | |
6563 | if (p != buff + field_size + 4) | |
6564 | { | |
6565 | if (size < (2 + 1)) | |
bee0ee85 NC |
6566 | { |
6567 | warn (_("Internal error: not enough buffer room for section flag info")); | |
6568 | return _("<unknown>"); | |
6569 | } | |
8d5ff12c L |
6570 | size -= 2; |
6571 | *p++ = ','; | |
6572 | *p++ = ' '; | |
6573 | } | |
2b692964 | 6574 | sprintf (p, _("UNKNOWN (%*.*lx)"), field_size, field_size, |
8d5ff12c L |
6575 | (unsigned long) unknown_flags); |
6576 | p += 10 + field_size; | |
6577 | } | |
6578 | } | |
6579 | ||
e9e44622 | 6580 | *p = '\0'; |
d1133906 NC |
6581 | return buff; |
6582 | } | |
6583 | ||
5844b465 | 6584 | static unsigned int ATTRIBUTE_WARN_UNUSED_RESULT |
ebdf1ebf | 6585 | get_compression_header (Elf_Internal_Chdr *chdr, unsigned char *buf, bfd_size_type size) |
77115a4a L |
6586 | { |
6587 | if (is_32bit_elf) | |
6588 | { | |
6589 | Elf32_External_Chdr *echdr = (Elf32_External_Chdr *) buf; | |
d8024a91 | 6590 | |
ebdf1ebf NC |
6591 | if (size < sizeof (* echdr)) |
6592 | { | |
6593 | error (_("Compressed section is too small even for a compression header\n")); | |
6594 | return 0; | |
6595 | } | |
6596 | ||
77115a4a L |
6597 | chdr->ch_type = BYTE_GET (echdr->ch_type); |
6598 | chdr->ch_size = BYTE_GET (echdr->ch_size); | |
6599 | chdr->ch_addralign = BYTE_GET (echdr->ch_addralign); | |
6600 | return sizeof (*echdr); | |
6601 | } | |
6602 | else | |
6603 | { | |
6604 | Elf64_External_Chdr *echdr = (Elf64_External_Chdr *) buf; | |
d8024a91 | 6605 | |
ebdf1ebf NC |
6606 | if (size < sizeof (* echdr)) |
6607 | { | |
6608 | error (_("Compressed section is too small even for a compression header\n")); | |
6609 | return 0; | |
6610 | } | |
6611 | ||
77115a4a L |
6612 | chdr->ch_type = BYTE_GET (echdr->ch_type); |
6613 | chdr->ch_size = BYTE_GET (echdr->ch_size); | |
6614 | chdr->ch_addralign = BYTE_GET (echdr->ch_addralign); | |
6615 | return sizeof (*echdr); | |
6616 | } | |
6617 | } | |
6618 | ||
015dc7e1 | 6619 | static bool |
dda8d76d | 6620 | process_section_headers (Filedata * filedata) |
252b5132 | 6621 | { |
2cf0635d | 6622 | Elf_Internal_Shdr * section; |
b34976b6 | 6623 | unsigned int i; |
252b5132 | 6624 | |
dda8d76d | 6625 | if (filedata->file_header.e_shnum == 0) |
252b5132 | 6626 | { |
82f2dbf7 | 6627 | /* PR binutils/12467. */ |
dda8d76d | 6628 | if (filedata->file_header.e_shoff != 0) |
32ec8896 NC |
6629 | { |
6630 | warn (_("possibly corrupt ELF file header - it has a non-zero" | |
6631 | " section header offset, but no section headers\n")); | |
015dc7e1 | 6632 | return false; |
32ec8896 | 6633 | } |
82f2dbf7 | 6634 | else if (do_sections) |
252b5132 RH |
6635 | printf (_("\nThere are no sections in this file.\n")); |
6636 | ||
015dc7e1 | 6637 | return true; |
252b5132 RH |
6638 | } |
6639 | ||
6640 | if (do_sections && !do_header) | |
ca0e11aa NC |
6641 | { |
6642 | if (filedata->is_separate && process_links) | |
6643 | printf (_("In linked file '%s': "), filedata->file_name); | |
6644 | if (! filedata->is_separate || process_links) | |
6645 | printf (ngettext ("There is %d section header, " | |
6646 | "starting at offset 0x%lx:\n", | |
6647 | "There are %d section headers, " | |
6648 | "starting at offset 0x%lx:\n", | |
6649 | filedata->file_header.e_shnum), | |
6650 | filedata->file_header.e_shnum, | |
6651 | (unsigned long) filedata->file_header.e_shoff); | |
6652 | } | |
252b5132 | 6653 | |
4de91c10 AM |
6654 | if (!get_section_headers (filedata, false)) |
6655 | return false; | |
252b5132 RH |
6656 | |
6657 | /* Read in the string table, so that we have names to display. */ | |
dda8d76d NC |
6658 | if (filedata->file_header.e_shstrndx != SHN_UNDEF |
6659 | && filedata->file_header.e_shstrndx < filedata->file_header.e_shnum) | |
252b5132 | 6660 | { |
dda8d76d | 6661 | section = filedata->section_headers + filedata->file_header.e_shstrndx; |
d40ac9bd | 6662 | |
c256ffe7 JJ |
6663 | if (section->sh_size != 0) |
6664 | { | |
dda8d76d NC |
6665 | filedata->string_table = (char *) get_data (NULL, filedata, section->sh_offset, |
6666 | 1, section->sh_size, | |
6667 | _("string table")); | |
0de14b54 | 6668 | |
dda8d76d | 6669 | filedata->string_table_length = filedata->string_table != NULL ? section->sh_size : 0; |
c256ffe7 | 6670 | } |
252b5132 RH |
6671 | } |
6672 | ||
6673 | /* Scan the sections for the dynamic symbol table | |
e3c8793a | 6674 | and dynamic string table and debug sections. */ |
89fac5e3 | 6675 | eh_addr_size = is_32bit_elf ? 4 : 8; |
dda8d76d | 6676 | switch (filedata->file_header.e_machine) |
89fac5e3 RS |
6677 | { |
6678 | case EM_MIPS: | |
6679 | case EM_MIPS_RS3_LE: | |
6680 | /* The 64-bit MIPS EABI uses a combination of 32-bit ELF and 64-bit | |
6681 | FDE addresses. However, the ABI also has a semi-official ILP32 | |
6682 | variant for which the normal FDE address size rules apply. | |
6683 | ||
6684 | GCC 4.0 marks EABI64 objects with a dummy .gcc_compiled_longXX | |
6685 | section, where XX is the size of longs in bits. Unfortunately, | |
6686 | earlier compilers provided no way of distinguishing ILP32 objects | |
6687 | from LP64 objects, so if there's any doubt, we should assume that | |
6688 | the official LP64 form is being used. */ | |
dda8d76d NC |
6689 | if ((filedata->file_header.e_flags & EF_MIPS_ABI) == E_MIPS_ABI_EABI64 |
6690 | && find_section (filedata, ".gcc_compiled_long32") == NULL) | |
89fac5e3 RS |
6691 | eh_addr_size = 8; |
6692 | break; | |
0f56a26a DD |
6693 | |
6694 | case EM_H8_300: | |
6695 | case EM_H8_300H: | |
dda8d76d | 6696 | switch (filedata->file_header.e_flags & EF_H8_MACH) |
0f56a26a DD |
6697 | { |
6698 | case E_H8_MACH_H8300: | |
6699 | case E_H8_MACH_H8300HN: | |
6700 | case E_H8_MACH_H8300SN: | |
6701 | case E_H8_MACH_H8300SXN: | |
6702 | eh_addr_size = 2; | |
6703 | break; | |
6704 | case E_H8_MACH_H8300H: | |
6705 | case E_H8_MACH_H8300S: | |
6706 | case E_H8_MACH_H8300SX: | |
6707 | eh_addr_size = 4; | |
6708 | break; | |
6709 | } | |
f4236fe4 DD |
6710 | break; |
6711 | ||
ff7eeb89 | 6712 | case EM_M32C_OLD: |
f4236fe4 | 6713 | case EM_M32C: |
dda8d76d | 6714 | switch (filedata->file_header.e_flags & EF_M32C_CPU_MASK) |
f4236fe4 DD |
6715 | { |
6716 | case EF_M32C_CPU_M16C: | |
6717 | eh_addr_size = 2; | |
6718 | break; | |
6719 | } | |
6720 | break; | |
89fac5e3 RS |
6721 | } |
6722 | ||
76ca31c0 NC |
6723 | #define CHECK_ENTSIZE_VALUES(section, i, size32, size64) \ |
6724 | do \ | |
6725 | { \ | |
6726 | bfd_size_type expected_entsize = is_32bit_elf ? size32 : size64; \ | |
6727 | if (section->sh_entsize != expected_entsize) \ | |
9dd3a467 | 6728 | { \ |
76ca31c0 NC |
6729 | char buf[40]; \ |
6730 | sprintf_vma (buf, section->sh_entsize); \ | |
6731 | /* Note: coded this way so that there is a single string for \ | |
6732 | translation. */ \ | |
6733 | error (_("Section %d has invalid sh_entsize of %s\n"), i, buf); \ | |
6734 | error (_("(Using the expected size of %u for the rest of this dump)\n"), \ | |
6735 | (unsigned) expected_entsize); \ | |
9dd3a467 | 6736 | section->sh_entsize = expected_entsize; \ |
76ca31c0 NC |
6737 | } \ |
6738 | } \ | |
08d8fa11 | 6739 | while (0) |
9dd3a467 NC |
6740 | |
6741 | #define CHECK_ENTSIZE(section, i, type) \ | |
1b513401 | 6742 | CHECK_ENTSIZE_VALUES (section, i, sizeof (Elf32_External_##type), \ |
08d8fa11 JJ |
6743 | sizeof (Elf64_External_##type)) |
6744 | ||
dda8d76d NC |
6745 | for (i = 0, section = filedata->section_headers; |
6746 | i < filedata->file_header.e_shnum; | |
b34976b6 | 6747 | i++, section++) |
252b5132 | 6748 | { |
84714f86 | 6749 | const char *name = section_name_print (filedata, section); |
252b5132 | 6750 | |
1b513401 NC |
6751 | /* Run some sanity checks on the headers and |
6752 | possibly fill in some file data as well. */ | |
6753 | switch (section->sh_type) | |
252b5132 | 6754 | { |
1b513401 | 6755 | case SHT_DYNSYM: |
978c4450 | 6756 | if (filedata->dynamic_symbols != NULL) |
252b5132 RH |
6757 | { |
6758 | error (_("File contains multiple dynamic symbol tables\n")); | |
6759 | continue; | |
6760 | } | |
6761 | ||
08d8fa11 | 6762 | CHECK_ENTSIZE (section, i, Sym); |
978c4450 | 6763 | filedata->dynamic_symbols |
4de91c10 | 6764 | = get_elf_symbols (filedata, section, &filedata->num_dynamic_syms); |
8ac10c5b | 6765 | filedata->dynamic_symtab_section = section; |
1b513401 NC |
6766 | break; |
6767 | ||
6768 | case SHT_STRTAB: | |
6769 | if (streq (name, ".dynstr")) | |
252b5132 | 6770 | { |
1b513401 NC |
6771 | if (filedata->dynamic_strings != NULL) |
6772 | { | |
6773 | error (_("File contains multiple dynamic string tables\n")); | |
6774 | continue; | |
6775 | } | |
6776 | ||
6777 | filedata->dynamic_strings | |
6778 | = (char *) get_data (NULL, filedata, section->sh_offset, | |
6779 | 1, section->sh_size, _("dynamic strings")); | |
6780 | filedata->dynamic_strings_length | |
6781 | = filedata->dynamic_strings == NULL ? 0 : section->sh_size; | |
8ac10c5b | 6782 | filedata->dynamic_strtab_section = section; |
252b5132 | 6783 | } |
1b513401 NC |
6784 | break; |
6785 | ||
6786 | case SHT_SYMTAB_SHNDX: | |
6787 | { | |
6788 | elf_section_list * entry = xmalloc (sizeof * entry); | |
6789 | ||
6790 | entry->hdr = section; | |
6791 | entry->next = filedata->symtab_shndx_list; | |
6792 | filedata->symtab_shndx_list = entry; | |
6793 | } | |
6794 | break; | |
6795 | ||
6796 | case SHT_SYMTAB: | |
6797 | CHECK_ENTSIZE (section, i, Sym); | |
6798 | break; | |
6799 | ||
6800 | case SHT_GROUP: | |
6801 | CHECK_ENTSIZE_VALUES (section, i, GRP_ENTRY_SIZE, GRP_ENTRY_SIZE); | |
6802 | break; | |
252b5132 | 6803 | |
1b513401 NC |
6804 | case SHT_REL: |
6805 | CHECK_ENTSIZE (section, i, Rel); | |
546cb2d8 | 6806 | if (do_checks && section->sh_size == 0) |
1b513401 NC |
6807 | warn (_("Section '%s': zero-sized relocation section\n"), name); |
6808 | break; | |
6809 | ||
6810 | case SHT_RELA: | |
6811 | CHECK_ENTSIZE (section, i, Rela); | |
546cb2d8 | 6812 | if (do_checks && section->sh_size == 0) |
1b513401 NC |
6813 | warn (_("Section '%s': zero-sized relocation section\n"), name); |
6814 | break; | |
6815 | ||
6816 | case SHT_NOTE: | |
6817 | case SHT_PROGBITS: | |
546cb2d8 NC |
6818 | /* Having a zero sized section is not illegal according to the |
6819 | ELF standard, but it might be an indication that something | |
6820 | is wrong. So issue a warning if we are running in lint mode. */ | |
6821 | if (do_checks && section->sh_size == 0) | |
1b513401 NC |
6822 | warn (_("Section '%s': has a size of zero - is this intended ?\n"), name); |
6823 | break; | |
6824 | ||
6825 | default: | |
6826 | break; | |
6827 | } | |
6828 | ||
6829 | if ((do_debugging || do_debug_info || do_debug_abbrevs | |
6830 | || do_debug_lines || do_debug_pubnames || do_debug_pubtypes | |
6831 | || do_debug_aranges || do_debug_frames || do_debug_macinfo | |
e38332c2 NC |
6832 | || do_debug_str || do_debug_str_offsets || do_debug_loc |
6833 | || do_debug_ranges | |
1b513401 | 6834 | || do_debug_addr || do_debug_cu_index || do_debug_links) |
24d127aa ML |
6835 | && (startswith (name, ".debug_") |
6836 | || startswith (name, ".zdebug_"))) | |
252b5132 | 6837 | { |
1b315056 CS |
6838 | if (name[1] == 'z') |
6839 | name += sizeof (".zdebug_") - 1; | |
6840 | else | |
6841 | name += sizeof (".debug_") - 1; | |
252b5132 RH |
6842 | |
6843 | if (do_debugging | |
24d127aa ML |
6844 | || (do_debug_info && startswith (name, "info")) |
6845 | || (do_debug_info && startswith (name, "types")) | |
6846 | || (do_debug_abbrevs && startswith (name, "abbrev")) | |
b40bf0a2 | 6847 | || (do_debug_lines && strcmp (name, "line") == 0) |
24d127aa ML |
6848 | || (do_debug_lines && startswith (name, "line.")) |
6849 | || (do_debug_pubnames && startswith (name, "pubnames")) | |
6850 | || (do_debug_pubtypes && startswith (name, "pubtypes")) | |
6851 | || (do_debug_pubnames && startswith (name, "gnu_pubnames")) | |
6852 | || (do_debug_pubtypes && startswith (name, "gnu_pubtypes")) | |
6853 | || (do_debug_aranges && startswith (name, "aranges")) | |
6854 | || (do_debug_ranges && startswith (name, "ranges")) | |
6855 | || (do_debug_ranges && startswith (name, "rnglists")) | |
6856 | || (do_debug_frames && startswith (name, "frame")) | |
6857 | || (do_debug_macinfo && startswith (name, "macinfo")) | |
6858 | || (do_debug_macinfo && startswith (name, "macro")) | |
6859 | || (do_debug_str && startswith (name, "str")) | |
6860 | || (do_debug_links && startswith (name, "sup")) | |
6861 | || (do_debug_str_offsets && startswith (name, "str_offsets")) | |
6862 | || (do_debug_loc && startswith (name, "loc")) | |
6863 | || (do_debug_loc && startswith (name, "loclists")) | |
6864 | || (do_debug_addr && startswith (name, "addr")) | |
6865 | || (do_debug_cu_index && startswith (name, "cu_index")) | |
6866 | || (do_debug_cu_index && startswith (name, "tu_index")) | |
252b5132 | 6867 | ) |
6431e409 | 6868 | request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP); |
252b5132 | 6869 | } |
a262ae96 | 6870 | /* Linkonce section to be combined with .debug_info at link time. */ |
09fd7e38 | 6871 | else if ((do_debugging || do_debug_info) |
24d127aa | 6872 | && startswith (name, ".gnu.linkonce.wi.")) |
6431e409 | 6873 | request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP); |
18bd398b | 6874 | else if (do_debug_frames && streq (name, ".eh_frame")) |
6431e409 | 6875 | request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP); |
61364358 JK |
6876 | else if (do_gdb_index && (streq (name, ".gdb_index") |
6877 | || streq (name, ".debug_names"))) | |
6431e409 | 6878 | request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP); |
6f875884 TG |
6879 | /* Trace sections for Itanium VMS. */ |
6880 | else if ((do_debugging || do_trace_info || do_trace_abbrevs | |
6881 | || do_trace_aranges) | |
24d127aa | 6882 | && startswith (name, ".trace_")) |
6f875884 TG |
6883 | { |
6884 | name += sizeof (".trace_") - 1; | |
6885 | ||
6886 | if (do_debugging | |
6887 | || (do_trace_info && streq (name, "info")) | |
6888 | || (do_trace_abbrevs && streq (name, "abbrev")) | |
6889 | || (do_trace_aranges && streq (name, "aranges")) | |
6890 | ) | |
6431e409 | 6891 | request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP); |
6f875884 | 6892 | } |
dda8d76d | 6893 | else if ((do_debugging || do_debug_links) |
24d127aa ML |
6894 | && (startswith (name, ".gnu_debuglink") |
6895 | || startswith (name, ".gnu_debugaltlink"))) | |
6431e409 | 6896 | request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP); |
252b5132 RH |
6897 | } |
6898 | ||
6899 | if (! do_sections) | |
015dc7e1 | 6900 | return true; |
252b5132 | 6901 | |
ca0e11aa | 6902 | if (filedata->is_separate && ! process_links) |
015dc7e1 | 6903 | return true; |
ca0e11aa NC |
6904 | |
6905 | if (filedata->is_separate) | |
6906 | printf (_("\nSection Headers in linked file '%s':\n"), filedata->file_name); | |
6907 | else if (filedata->file_header.e_shnum > 1) | |
3a1a2036 NC |
6908 | printf (_("\nSection Headers:\n")); |
6909 | else | |
6910 | printf (_("\nSection Header:\n")); | |
76da6bbe | 6911 | |
f7a99963 | 6912 | if (is_32bit_elf) |
595cf52e | 6913 | { |
5477e8a0 | 6914 | if (do_section_details) |
595cf52e L |
6915 | { |
6916 | printf (_(" [Nr] Name\n")); | |
5477e8a0 | 6917 | printf (_(" Type Addr Off Size ES Lk Inf Al\n")); |
595cf52e L |
6918 | } |
6919 | else | |
6920 | printf | |
6921 | (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n")); | |
6922 | } | |
d974e256 | 6923 | else if (do_wide) |
595cf52e | 6924 | { |
5477e8a0 | 6925 | if (do_section_details) |
595cf52e L |
6926 | { |
6927 | printf (_(" [Nr] Name\n")); | |
5477e8a0 | 6928 | printf (_(" Type Address Off Size ES Lk Inf Al\n")); |
595cf52e L |
6929 | } |
6930 | else | |
6931 | printf | |
6932 | (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n")); | |
6933 | } | |
f7a99963 NC |
6934 | else |
6935 | { | |
5477e8a0 | 6936 | if (do_section_details) |
595cf52e L |
6937 | { |
6938 | printf (_(" [Nr] Name\n")); | |
5477e8a0 L |
6939 | printf (_(" Type Address Offset Link\n")); |
6940 | printf (_(" Size EntSize Info Align\n")); | |
595cf52e L |
6941 | } |
6942 | else | |
6943 | { | |
6944 | printf (_(" [Nr] Name Type Address Offset\n")); | |
6945 | printf (_(" Size EntSize Flags Link Info Align\n")); | |
6946 | } | |
f7a99963 | 6947 | } |
252b5132 | 6948 | |
5477e8a0 L |
6949 | if (do_section_details) |
6950 | printf (_(" Flags\n")); | |
6951 | ||
dda8d76d NC |
6952 | for (i = 0, section = filedata->section_headers; |
6953 | i < filedata->file_header.e_shnum; | |
b34976b6 | 6954 | i++, section++) |
252b5132 | 6955 | { |
dd905818 NC |
6956 | /* Run some sanity checks on the section header. */ |
6957 | ||
6958 | /* Check the sh_link field. */ | |
6959 | switch (section->sh_type) | |
6960 | { | |
285e3f99 AM |
6961 | case SHT_REL: |
6962 | case SHT_RELA: | |
6963 | if (section->sh_link == 0 | |
6964 | && (filedata->file_header.e_type == ET_EXEC | |
6965 | || filedata->file_header.e_type == ET_DYN)) | |
6966 | /* A dynamic relocation section where all entries use a | |
6967 | zero symbol index need not specify a symtab section. */ | |
6968 | break; | |
6969 | /* Fall through. */ | |
dd905818 NC |
6970 | case SHT_SYMTAB_SHNDX: |
6971 | case SHT_GROUP: | |
6972 | case SHT_HASH: | |
6973 | case SHT_GNU_HASH: | |
6974 | case SHT_GNU_versym: | |
285e3f99 | 6975 | if (section->sh_link == 0 |
dda8d76d NC |
6976 | || section->sh_link >= filedata->file_header.e_shnum |
6977 | || (filedata->section_headers[section->sh_link].sh_type != SHT_SYMTAB | |
6978 | && filedata->section_headers[section->sh_link].sh_type != SHT_DYNSYM)) | |
dd905818 NC |
6979 | warn (_("[%2u]: Link field (%u) should index a symtab section.\n"), |
6980 | i, section->sh_link); | |
6981 | break; | |
6982 | ||
6983 | case SHT_DYNAMIC: | |
6984 | case SHT_SYMTAB: | |
6985 | case SHT_DYNSYM: | |
6986 | case SHT_GNU_verneed: | |
6987 | case SHT_GNU_verdef: | |
6988 | case SHT_GNU_LIBLIST: | |
285e3f99 | 6989 | if (section->sh_link == 0 |
dda8d76d NC |
6990 | || section->sh_link >= filedata->file_header.e_shnum |
6991 | || filedata->section_headers[section->sh_link].sh_type != SHT_STRTAB) | |
dd905818 NC |
6992 | warn (_("[%2u]: Link field (%u) should index a string section.\n"), |
6993 | i, section->sh_link); | |
6994 | break; | |
6995 | ||
6996 | case SHT_INIT_ARRAY: | |
6997 | case SHT_FINI_ARRAY: | |
6998 | case SHT_PREINIT_ARRAY: | |
6999 | if (section->sh_type < SHT_LOOS && section->sh_link != 0) | |
7000 | warn (_("[%2u]: Unexpected value (%u) in link field.\n"), | |
7001 | i, section->sh_link); | |
7002 | break; | |
7003 | ||
7004 | default: | |
7005 | /* FIXME: Add support for target specific section types. */ | |
7006 | #if 0 /* Currently we do not check other section types as there are too | |
7007 | many special cases. Stab sections for example have a type | |
7008 | of SHT_PROGBITS but an sh_link field that links to the .stabstr | |
7009 | section. */ | |
7010 | if (section->sh_type < SHT_LOOS && section->sh_link != 0) | |
7011 | warn (_("[%2u]: Unexpected value (%u) in link field.\n"), | |
7012 | i, section->sh_link); | |
7013 | #endif | |
7014 | break; | |
7015 | } | |
7016 | ||
7017 | /* Check the sh_info field. */ | |
7018 | switch (section->sh_type) | |
7019 | { | |
7020 | case SHT_REL: | |
7021 | case SHT_RELA: | |
285e3f99 AM |
7022 | if (section->sh_info == 0 |
7023 | && (filedata->file_header.e_type == ET_EXEC | |
7024 | || filedata->file_header.e_type == ET_DYN)) | |
7025 | /* Dynamic relocations apply to segments, so they do not | |
7026 | need to specify the section they relocate. */ | |
7027 | break; | |
7028 | if (section->sh_info == 0 | |
dda8d76d NC |
7029 | || section->sh_info >= filedata->file_header.e_shnum |
7030 | || (filedata->section_headers[section->sh_info].sh_type != SHT_PROGBITS | |
7031 | && filedata->section_headers[section->sh_info].sh_type != SHT_NOBITS | |
7032 | && filedata->section_headers[section->sh_info].sh_type != SHT_NOTE | |
7033 | && filedata->section_headers[section->sh_info].sh_type != SHT_INIT_ARRAY | |
385e5b90 L |
7034 | && filedata->section_headers[section->sh_info].sh_type != SHT_FINI_ARRAY |
7035 | && filedata->section_headers[section->sh_info].sh_type != SHT_PREINIT_ARRAY | |
dd905818 | 7036 | /* FIXME: Are other section types valid ? */ |
dda8d76d | 7037 | && filedata->section_headers[section->sh_info].sh_type < SHT_LOOS)) |
285e3f99 AM |
7038 | warn (_("[%2u]: Info field (%u) should index a relocatable section.\n"), |
7039 | i, section->sh_info); | |
dd905818 NC |
7040 | break; |
7041 | ||
7042 | case SHT_DYNAMIC: | |
7043 | case SHT_HASH: | |
7044 | case SHT_SYMTAB_SHNDX: | |
7045 | case SHT_INIT_ARRAY: | |
7046 | case SHT_FINI_ARRAY: | |
7047 | case SHT_PREINIT_ARRAY: | |
7048 | if (section->sh_info != 0) | |
7049 | warn (_("[%2u]: Unexpected value (%u) in info field.\n"), | |
7050 | i, section->sh_info); | |
7051 | break; | |
7052 | ||
7053 | case SHT_GROUP: | |
7054 | case SHT_SYMTAB: | |
7055 | case SHT_DYNSYM: | |
7056 | /* A symbol index - we assume that it is valid. */ | |
7057 | break; | |
7058 | ||
7059 | default: | |
7060 | /* FIXME: Add support for target specific section types. */ | |
7061 | if (section->sh_type == SHT_NOBITS) | |
7062 | /* NOBITS section headers with non-zero sh_info fields can be | |
7063 | created when a binary is stripped of everything but its debug | |
1a9ccd70 NC |
7064 | information. The stripped sections have their headers |
7065 | preserved but their types set to SHT_NOBITS. So do not check | |
7066 | this type of section. */ | |
dd905818 NC |
7067 | ; |
7068 | else if (section->sh_flags & SHF_INFO_LINK) | |
7069 | { | |
dda8d76d | 7070 | if (section->sh_info < 1 || section->sh_info >= filedata->file_header.e_shnum) |
dd905818 NC |
7071 | warn (_("[%2u]: Expected link to another section in info field"), i); |
7072 | } | |
a91e1603 L |
7073 | else if (section->sh_type < SHT_LOOS |
7074 | && (section->sh_flags & SHF_GNU_MBIND) == 0 | |
7075 | && section->sh_info != 0) | |
dd905818 NC |
7076 | warn (_("[%2u]: Unexpected value (%u) in info field.\n"), |
7077 | i, section->sh_info); | |
7078 | break; | |
7079 | } | |
7080 | ||
3e6b6445 | 7081 | /* Check the sh_size field. */ |
dda8d76d | 7082 | if (section->sh_size > filedata->file_size |
3e6b6445 NC |
7083 | && section->sh_type != SHT_NOBITS |
7084 | && section->sh_type != SHT_NULL | |
7085 | && section->sh_type < SHT_LOOS) | |
7086 | warn (_("Size of section %u is larger than the entire file!\n"), i); | |
7087 | ||
7bfd842d | 7088 | printf (" [%2u] ", i); |
5477e8a0 | 7089 | if (do_section_details) |
dda8d76d | 7090 | printf ("%s\n ", printable_section_name (filedata, section)); |
595cf52e | 7091 | else |
84714f86 | 7092 | print_symbol (-17, section_name_print (filedata, section)); |
0b4362b0 | 7093 | |
ea52a088 | 7094 | printf (do_wide ? " %-15s " : " %-15.15s ", |
dda8d76d | 7095 | get_section_type_name (filedata, section->sh_type)); |
0b4362b0 | 7096 | |
f7a99963 NC |
7097 | if (is_32bit_elf) |
7098 | { | |
cfcac11d NC |
7099 | const char * link_too_big = NULL; |
7100 | ||
f7a99963 | 7101 | print_vma (section->sh_addr, LONG_HEX); |
76da6bbe | 7102 | |
f7a99963 NC |
7103 | printf ( " %6.6lx %6.6lx %2.2lx", |
7104 | (unsigned long) section->sh_offset, | |
7105 | (unsigned long) section->sh_size, | |
7106 | (unsigned long) section->sh_entsize); | |
d1133906 | 7107 | |
5477e8a0 L |
7108 | if (do_section_details) |
7109 | fputs (" ", stdout); | |
7110 | else | |
dda8d76d | 7111 | printf (" %3s ", get_elf_section_flags (filedata, section->sh_flags)); |
76da6bbe | 7112 | |
dda8d76d | 7113 | if (section->sh_link >= filedata->file_header.e_shnum) |
cfcac11d NC |
7114 | { |
7115 | link_too_big = ""; | |
7116 | /* The sh_link value is out of range. Normally this indicates | |
caa83f8b | 7117 | an error but it can have special values in Solaris binaries. */ |
dda8d76d | 7118 | switch (filedata->file_header.e_machine) |
cfcac11d | 7119 | { |
caa83f8b | 7120 | case EM_386: |
22abe556 | 7121 | case EM_IAMCU: |
caa83f8b | 7122 | case EM_X86_64: |
7f502d6c | 7123 | case EM_L1OM: |
7a9068fe | 7124 | case EM_K1OM: |
cfcac11d NC |
7125 | case EM_OLD_SPARCV9: |
7126 | case EM_SPARC32PLUS: | |
7127 | case EM_SPARCV9: | |
7128 | case EM_SPARC: | |
7129 | if (section->sh_link == (SHN_BEFORE & 0xffff)) | |
7130 | link_too_big = "BEFORE"; | |
7131 | else if (section->sh_link == (SHN_AFTER & 0xffff)) | |
7132 | link_too_big = "AFTER"; | |
7133 | break; | |
7134 | default: | |
7135 | break; | |
7136 | } | |
7137 | } | |
7138 | ||
7139 | if (do_section_details) | |
7140 | { | |
7141 | if (link_too_big != NULL && * link_too_big) | |
7142 | printf ("<%s> ", link_too_big); | |
7143 | else | |
7144 | printf ("%2u ", section->sh_link); | |
7145 | printf ("%3u %2lu\n", section->sh_info, | |
7146 | (unsigned long) section->sh_addralign); | |
7147 | } | |
7148 | else | |
7149 | printf ("%2u %3u %2lu\n", | |
7150 | section->sh_link, | |
7151 | section->sh_info, | |
7152 | (unsigned long) section->sh_addralign); | |
7153 | ||
7154 | if (link_too_big && ! * link_too_big) | |
7155 | warn (_("section %u: sh_link value of %u is larger than the number of sections\n"), | |
7156 | i, section->sh_link); | |
f7a99963 | 7157 | } |
d974e256 JJ |
7158 | else if (do_wide) |
7159 | { | |
7160 | print_vma (section->sh_addr, LONG_HEX); | |
7161 | ||
7162 | if ((long) section->sh_offset == section->sh_offset) | |
7163 | printf (" %6.6lx", (unsigned long) section->sh_offset); | |
7164 | else | |
7165 | { | |
7166 | putchar (' '); | |
7167 | print_vma (section->sh_offset, LONG_HEX); | |
7168 | } | |
7169 | ||
7170 | if ((unsigned long) section->sh_size == section->sh_size) | |
7171 | printf (" %6.6lx", (unsigned long) section->sh_size); | |
7172 | else | |
7173 | { | |
7174 | putchar (' '); | |
7175 | print_vma (section->sh_size, LONG_HEX); | |
7176 | } | |
7177 | ||
7178 | if ((unsigned long) section->sh_entsize == section->sh_entsize) | |
7179 | printf (" %2.2lx", (unsigned long) section->sh_entsize); | |
7180 | else | |
7181 | { | |
7182 | putchar (' '); | |
7183 | print_vma (section->sh_entsize, LONG_HEX); | |
7184 | } | |
7185 | ||
5477e8a0 L |
7186 | if (do_section_details) |
7187 | fputs (" ", stdout); | |
7188 | else | |
dda8d76d | 7189 | printf (" %3s ", get_elf_section_flags (filedata, section->sh_flags)); |
d974e256 | 7190 | |
72de5009 | 7191 | printf ("%2u %3u ", section->sh_link, section->sh_info); |
d974e256 JJ |
7192 | |
7193 | if ((unsigned long) section->sh_addralign == section->sh_addralign) | |
72de5009 | 7194 | printf ("%2lu\n", (unsigned long) section->sh_addralign); |
d974e256 JJ |
7195 | else |
7196 | { | |
7197 | print_vma (section->sh_addralign, DEC); | |
7198 | putchar ('\n'); | |
7199 | } | |
7200 | } | |
5477e8a0 | 7201 | else if (do_section_details) |
595cf52e | 7202 | { |
55cc53e9 | 7203 | putchar (' '); |
595cf52e L |
7204 | print_vma (section->sh_addr, LONG_HEX); |
7205 | if ((long) section->sh_offset == section->sh_offset) | |
5477e8a0 | 7206 | printf (" %16.16lx", (unsigned long) section->sh_offset); |
595cf52e L |
7207 | else |
7208 | { | |
7209 | printf (" "); | |
7210 | print_vma (section->sh_offset, LONG_HEX); | |
7211 | } | |
72de5009 | 7212 | printf (" %u\n ", section->sh_link); |
595cf52e | 7213 | print_vma (section->sh_size, LONG_HEX); |
5477e8a0 | 7214 | putchar (' '); |
595cf52e L |
7215 | print_vma (section->sh_entsize, LONG_HEX); |
7216 | ||
72de5009 AM |
7217 | printf (" %-16u %lu\n", |
7218 | section->sh_info, | |
595cf52e L |
7219 | (unsigned long) section->sh_addralign); |
7220 | } | |
f7a99963 NC |
7221 | else |
7222 | { | |
7223 | putchar (' '); | |
7224 | print_vma (section->sh_addr, LONG_HEX); | |
53c7db4b KH |
7225 | if ((long) section->sh_offset == section->sh_offset) |
7226 | printf (" %8.8lx", (unsigned long) section->sh_offset); | |
7227 | else | |
7228 | { | |
7229 | printf (" "); | |
7230 | print_vma (section->sh_offset, LONG_HEX); | |
7231 | } | |
f7a99963 NC |
7232 | printf ("\n "); |
7233 | print_vma (section->sh_size, LONG_HEX); | |
7234 | printf (" "); | |
7235 | print_vma (section->sh_entsize, LONG_HEX); | |
76da6bbe | 7236 | |
dda8d76d | 7237 | printf (" %3s ", get_elf_section_flags (filedata, section->sh_flags)); |
76da6bbe | 7238 | |
72de5009 AM |
7239 | printf (" %2u %3u %lu\n", |
7240 | section->sh_link, | |
7241 | section->sh_info, | |
f7a99963 NC |
7242 | (unsigned long) section->sh_addralign); |
7243 | } | |
5477e8a0 L |
7244 | |
7245 | if (do_section_details) | |
77115a4a | 7246 | { |
dda8d76d | 7247 | printf (" %s\n", get_elf_section_flags (filedata, section->sh_flags)); |
77115a4a L |
7248 | if ((section->sh_flags & SHF_COMPRESSED) != 0) |
7249 | { | |
7250 | /* Minimum section size is 12 bytes for 32-bit compression | |
7251 | header + 12 bytes for compressed data header. */ | |
7252 | unsigned char buf[24]; | |
d8024a91 | 7253 | |
77115a4a | 7254 | assert (sizeof (buf) >= sizeof (Elf64_External_Chdr)); |
dda8d76d | 7255 | if (get_data (&buf, filedata, section->sh_offset, 1, |
77115a4a L |
7256 | sizeof (buf), _("compression header"))) |
7257 | { | |
7258 | Elf_Internal_Chdr chdr; | |
d8024a91 | 7259 | |
5844b465 NC |
7260 | if (get_compression_header (&chdr, buf, sizeof (buf)) == 0) |
7261 | printf (_(" [<corrupt>]\n")); | |
77115a4a | 7262 | else |
5844b465 NC |
7263 | { |
7264 | if (chdr.ch_type == ELFCOMPRESS_ZLIB) | |
7265 | printf (" ZLIB, "); | |
7266 | else | |
7267 | printf (_(" [<unknown>: 0x%x], "), | |
7268 | chdr.ch_type); | |
7269 | print_vma (chdr.ch_size, LONG_HEX); | |
7270 | printf (", %lu\n", (unsigned long) chdr.ch_addralign); | |
7271 | } | |
77115a4a L |
7272 | } |
7273 | } | |
7274 | } | |
252b5132 RH |
7275 | } |
7276 | ||
5477e8a0 | 7277 | if (!do_section_details) |
3dbcc61d | 7278 | { |
9fb71ee4 NC |
7279 | /* The ordering of the letters shown here matches the ordering of the |
7280 | corresponding SHF_xxx values, and hence the order in which these | |
7281 | letters will be displayed to the user. */ | |
7282 | printf (_("Key to Flags:\n\ | |
7283 | W (write), A (alloc), X (execute), M (merge), S (strings), I (info),\n\ | |
7284 | L (link order), O (extra OS processing required), G (group), T (TLS),\n\ | |
fd85a6a1 | 7285 | C (compressed), x (unknown), o (OS specific), E (exclude),\n ")); |
5424d7ed L |
7286 | switch (filedata->file_header.e_ident[EI_OSABI]) |
7287 | { | |
7288 | case ELFOSABI_GNU: | |
7289 | case ELFOSABI_FREEBSD: | |
7290 | printf (_("R (retain), ")); | |
7291 | /* Fall through */ | |
7292 | case ELFOSABI_NONE: | |
7293 | printf (_("D (mbind), ")); | |
7294 | break; | |
7295 | default: | |
7296 | break; | |
7297 | } | |
dda8d76d NC |
7298 | if (filedata->file_header.e_machine == EM_X86_64 |
7299 | || filedata->file_header.e_machine == EM_L1OM | |
7300 | || filedata->file_header.e_machine == EM_K1OM) | |
9fb71ee4 | 7301 | printf (_("l (large), ")); |
dda8d76d | 7302 | else if (filedata->file_header.e_machine == EM_ARM) |
f0728ee3 | 7303 | printf (_("y (purecode), ")); |
dda8d76d | 7304 | else if (filedata->file_header.e_machine == EM_PPC) |
83eef883 | 7305 | printf (_("v (VLE), ")); |
9fb71ee4 | 7306 | printf ("p (processor specific)\n"); |
0b4362b0 | 7307 | } |
d1133906 | 7308 | |
015dc7e1 | 7309 | return true; |
252b5132 RH |
7310 | } |
7311 | ||
015dc7e1 | 7312 | static bool |
28d13567 AM |
7313 | get_symtab (Filedata *filedata, Elf_Internal_Shdr *symsec, |
7314 | Elf_Internal_Sym **symtab, unsigned long *nsyms, | |
7315 | char **strtab, unsigned long *strtablen) | |
7316 | { | |
7317 | *strtab = NULL; | |
7318 | *strtablen = 0; | |
4de91c10 | 7319 | *symtab = get_elf_symbols (filedata, symsec, nsyms); |
28d13567 AM |
7320 | |
7321 | if (*symtab == NULL) | |
015dc7e1 | 7322 | return false; |
28d13567 AM |
7323 | |
7324 | if (symsec->sh_link != 0) | |
7325 | { | |
7326 | Elf_Internal_Shdr *strsec; | |
7327 | ||
7328 | if (symsec->sh_link >= filedata->file_header.e_shnum) | |
7329 | { | |
7330 | error (_("Bad sh_link in symbol table section\n")); | |
7331 | free (*symtab); | |
7332 | *symtab = NULL; | |
7333 | *nsyms = 0; | |
015dc7e1 | 7334 | return false; |
28d13567 AM |
7335 | } |
7336 | ||
7337 | strsec = filedata->section_headers + symsec->sh_link; | |
7338 | ||
7339 | *strtab = (char *) get_data (NULL, filedata, strsec->sh_offset, | |
7340 | 1, strsec->sh_size, _("string table")); | |
7341 | if (*strtab == NULL) | |
7342 | { | |
7343 | free (*symtab); | |
7344 | *symtab = NULL; | |
7345 | *nsyms = 0; | |
015dc7e1 | 7346 | return false; |
28d13567 AM |
7347 | } |
7348 | *strtablen = strsec->sh_size; | |
7349 | } | |
015dc7e1 | 7350 | return true; |
28d13567 AM |
7351 | } |
7352 | ||
f5842774 L |
7353 | static const char * |
7354 | get_group_flags (unsigned int flags) | |
7355 | { | |
1449284b | 7356 | static char buff[128]; |
220453ec | 7357 | |
6d913794 NC |
7358 | if (flags == 0) |
7359 | return ""; | |
7360 | else if (flags == GRP_COMDAT) | |
7361 | return "COMDAT "; | |
f5842774 | 7362 | |
89246a0e AM |
7363 | snprintf (buff, sizeof buff, "[0x%x: %s%s%s]", |
7364 | flags, | |
7365 | flags & GRP_MASKOS ? _("<OS specific>") : "", | |
7366 | flags & GRP_MASKPROC ? _("<PROC specific>") : "", | |
7367 | (flags & ~(GRP_COMDAT | GRP_MASKOS | GRP_MASKPROC) | |
7368 | ? _("<unknown>") : "")); | |
6d913794 | 7369 | |
f5842774 L |
7370 | return buff; |
7371 | } | |
7372 | ||
015dc7e1 | 7373 | static bool |
dda8d76d | 7374 | process_section_groups (Filedata * filedata) |
f5842774 | 7375 | { |
2cf0635d | 7376 | Elf_Internal_Shdr * section; |
f5842774 | 7377 | unsigned int i; |
2cf0635d NC |
7378 | struct group * group; |
7379 | Elf_Internal_Shdr * symtab_sec; | |
7380 | Elf_Internal_Shdr * strtab_sec; | |
7381 | Elf_Internal_Sym * symtab; | |
ba5cdace | 7382 | unsigned long num_syms; |
2cf0635d | 7383 | char * strtab; |
c256ffe7 | 7384 | size_t strtab_size; |
d1f5c6e3 L |
7385 | |
7386 | /* Don't process section groups unless needed. */ | |
7387 | if (!do_unwind && !do_section_groups) | |
015dc7e1 | 7388 | return true; |
f5842774 | 7389 | |
dda8d76d | 7390 | if (filedata->file_header.e_shnum == 0) |
f5842774 L |
7391 | { |
7392 | if (do_section_groups) | |
ca0e11aa NC |
7393 | { |
7394 | if (filedata->is_separate) | |
7395 | printf (_("\nThere are no sections group in linked file '%s'.\n"), | |
7396 | filedata->file_name); | |
7397 | else | |
7398 | printf (_("\nThere are no section groups in this file.\n")); | |
7399 | } | |
015dc7e1 | 7400 | return true; |
f5842774 L |
7401 | } |
7402 | ||
dda8d76d | 7403 | if (filedata->section_headers == NULL) |
f5842774 L |
7404 | { |
7405 | error (_("Section headers are not available!\n")); | |
fa1908fd | 7406 | /* PR 13622: This can happen with a corrupt ELF header. */ |
015dc7e1 | 7407 | return false; |
f5842774 L |
7408 | } |
7409 | ||
978c4450 AM |
7410 | filedata->section_headers_groups |
7411 | = (struct group **) calloc (filedata->file_header.e_shnum, | |
7412 | sizeof (struct group *)); | |
e4b17d5c | 7413 | |
978c4450 | 7414 | if (filedata->section_headers_groups == NULL) |
e4b17d5c | 7415 | { |
8b73c356 | 7416 | error (_("Out of memory reading %u section group headers\n"), |
dda8d76d | 7417 | filedata->file_header.e_shnum); |
015dc7e1 | 7418 | return false; |
e4b17d5c L |
7419 | } |
7420 | ||
f5842774 | 7421 | /* Scan the sections for the group section. */ |
978c4450 | 7422 | filedata->group_count = 0; |
dda8d76d NC |
7423 | for (i = 0, section = filedata->section_headers; |
7424 | i < filedata->file_header.e_shnum; | |
f5842774 | 7425 | i++, section++) |
e4b17d5c | 7426 | if (section->sh_type == SHT_GROUP) |
978c4450 | 7427 | filedata->group_count++; |
e4b17d5c | 7428 | |
978c4450 | 7429 | if (filedata->group_count == 0) |
d1f5c6e3 L |
7430 | { |
7431 | if (do_section_groups) | |
ca0e11aa NC |
7432 | { |
7433 | if (filedata->is_separate) | |
7434 | printf (_("\nThere are no section groups in linked file '%s'.\n"), | |
7435 | filedata->file_name); | |
7436 | else | |
7437 | printf (_("\nThere are no section groups in this file.\n")); | |
7438 | } | |
d1f5c6e3 | 7439 | |
015dc7e1 | 7440 | return true; |
d1f5c6e3 L |
7441 | } |
7442 | ||
978c4450 AM |
7443 | filedata->section_groups = (struct group *) calloc (filedata->group_count, |
7444 | sizeof (struct group)); | |
e4b17d5c | 7445 | |
978c4450 | 7446 | if (filedata->section_groups == NULL) |
e4b17d5c | 7447 | { |
8b73c356 | 7448 | error (_("Out of memory reading %lu groups\n"), |
978c4450 | 7449 | (unsigned long) filedata->group_count); |
015dc7e1 | 7450 | return false; |
e4b17d5c L |
7451 | } |
7452 | ||
d1f5c6e3 L |
7453 | symtab_sec = NULL; |
7454 | strtab_sec = NULL; | |
7455 | symtab = NULL; | |
ba5cdace | 7456 | num_syms = 0; |
d1f5c6e3 | 7457 | strtab = NULL; |
c256ffe7 | 7458 | strtab_size = 0; |
ca0e11aa NC |
7459 | |
7460 | if (filedata->is_separate) | |
7461 | printf (_("Section groups in linked file '%s'\n"), filedata->file_name); | |
047c3dbf | 7462 | |
978c4450 | 7463 | for (i = 0, section = filedata->section_headers, group = filedata->section_groups; |
dda8d76d | 7464 | i < filedata->file_header.e_shnum; |
e4b17d5c | 7465 | i++, section++) |
f5842774 L |
7466 | { |
7467 | if (section->sh_type == SHT_GROUP) | |
7468 | { | |
dda8d76d | 7469 | const char * name = printable_section_name (filedata, section); |
74e1a04b | 7470 | const char * group_name; |
2cf0635d NC |
7471 | unsigned char * start; |
7472 | unsigned char * indices; | |
f5842774 | 7473 | unsigned int entry, j, size; |
2cf0635d NC |
7474 | Elf_Internal_Shdr * sec; |
7475 | Elf_Internal_Sym * sym; | |
f5842774 L |
7476 | |
7477 | /* Get the symbol table. */ | |
dda8d76d NC |
7478 | if (section->sh_link >= filedata->file_header.e_shnum |
7479 | || ((sec = filedata->section_headers + section->sh_link)->sh_type | |
c256ffe7 | 7480 | != SHT_SYMTAB)) |
f5842774 L |
7481 | { |
7482 | error (_("Bad sh_link in group section `%s'\n"), name); | |
7483 | continue; | |
7484 | } | |
d1f5c6e3 L |
7485 | |
7486 | if (symtab_sec != sec) | |
7487 | { | |
7488 | symtab_sec = sec; | |
9db70fc3 | 7489 | free (symtab); |
4de91c10 | 7490 | symtab = get_elf_symbols (filedata, symtab_sec, & num_syms); |
d1f5c6e3 | 7491 | } |
f5842774 | 7492 | |
dd24e3da NC |
7493 | if (symtab == NULL) |
7494 | { | |
7495 | error (_("Corrupt header in group section `%s'\n"), name); | |
7496 | continue; | |
7497 | } | |
7498 | ||
ba5cdace NC |
7499 | if (section->sh_info >= num_syms) |
7500 | { | |
7501 | error (_("Bad sh_info in group section `%s'\n"), name); | |
7502 | continue; | |
7503 | } | |
7504 | ||
f5842774 L |
7505 | sym = symtab + section->sh_info; |
7506 | ||
7507 | if (ELF_ST_TYPE (sym->st_info) == STT_SECTION) | |
7508 | { | |
4fbb74a6 | 7509 | if (sym->st_shndx == 0 |
dda8d76d | 7510 | || sym->st_shndx >= filedata->file_header.e_shnum) |
f5842774 L |
7511 | { |
7512 | error (_("Bad sh_info in group section `%s'\n"), name); | |
7513 | continue; | |
7514 | } | |
ba2685cc | 7515 | |
84714f86 AM |
7516 | group_name = section_name_print (filedata, |
7517 | filedata->section_headers | |
b9e920ec | 7518 | + sym->st_shndx); |
c256ffe7 | 7519 | strtab_sec = NULL; |
9db70fc3 | 7520 | free (strtab); |
f5842774 | 7521 | strtab = NULL; |
c256ffe7 | 7522 | strtab_size = 0; |
f5842774 L |
7523 | } |
7524 | else | |
7525 | { | |
7526 | /* Get the string table. */ | |
dda8d76d | 7527 | if (symtab_sec->sh_link >= filedata->file_header.e_shnum) |
c256ffe7 JJ |
7528 | { |
7529 | strtab_sec = NULL; | |
9db70fc3 | 7530 | free (strtab); |
c256ffe7 JJ |
7531 | strtab = NULL; |
7532 | strtab_size = 0; | |
7533 | } | |
7534 | else if (strtab_sec | |
dda8d76d | 7535 | != (sec = filedata->section_headers + symtab_sec->sh_link)) |
d1f5c6e3 L |
7536 | { |
7537 | strtab_sec = sec; | |
9db70fc3 | 7538 | free (strtab); |
071436c6 | 7539 | |
dda8d76d | 7540 | strtab = (char *) get_data (NULL, filedata, strtab_sec->sh_offset, |
071436c6 NC |
7541 | 1, strtab_sec->sh_size, |
7542 | _("string table")); | |
c256ffe7 | 7543 | strtab_size = strtab != NULL ? strtab_sec->sh_size : 0; |
d1f5c6e3 | 7544 | } |
c256ffe7 | 7545 | group_name = sym->st_name < strtab_size |
2b692964 | 7546 | ? strtab + sym->st_name : _("<corrupt>"); |
f5842774 L |
7547 | } |
7548 | ||
c9c1d674 EG |
7549 | /* PR 17531: file: loop. */ |
7550 | if (section->sh_entsize > section->sh_size) | |
7551 | { | |
7552 | error (_("Section %s has sh_entsize (0x%lx) which is larger than its size (0x%lx)\n"), | |
dda8d76d | 7553 | printable_section_name (filedata, section), |
8066deb1 AM |
7554 | (unsigned long) section->sh_entsize, |
7555 | (unsigned long) section->sh_size); | |
61dd8e19 | 7556 | continue; |
c9c1d674 EG |
7557 | } |
7558 | ||
dda8d76d | 7559 | start = (unsigned char *) get_data (NULL, filedata, section->sh_offset, |
3f5e193b NC |
7560 | 1, section->sh_size, |
7561 | _("section data")); | |
59245841 NC |
7562 | if (start == NULL) |
7563 | continue; | |
f5842774 L |
7564 | |
7565 | indices = start; | |
7566 | size = (section->sh_size / section->sh_entsize) - 1; | |
7567 | entry = byte_get (indices, 4); | |
7568 | indices += 4; | |
e4b17d5c L |
7569 | |
7570 | if (do_section_groups) | |
7571 | { | |
2b692964 | 7572 | printf (_("\n%sgroup section [%5u] `%s' [%s] contains %u sections:\n"), |
391cb864 | 7573 | get_group_flags (entry), i, name, group_name, size); |
ba2685cc | 7574 | |
e4b17d5c L |
7575 | printf (_(" [Index] Name\n")); |
7576 | } | |
7577 | ||
7578 | group->group_index = i; | |
7579 | ||
f5842774 L |
7580 | for (j = 0; j < size; j++) |
7581 | { | |
2cf0635d | 7582 | struct group_list * g; |
e4b17d5c | 7583 | |
f5842774 L |
7584 | entry = byte_get (indices, 4); |
7585 | indices += 4; | |
7586 | ||
dda8d76d | 7587 | if (entry >= filedata->file_header.e_shnum) |
391cb864 | 7588 | { |
57028622 NC |
7589 | static unsigned num_group_errors = 0; |
7590 | ||
7591 | if (num_group_errors ++ < 10) | |
7592 | { | |
7593 | error (_("section [%5u] in group section [%5u] > maximum section [%5u]\n"), | |
dda8d76d | 7594 | entry, i, filedata->file_header.e_shnum - 1); |
57028622 | 7595 | if (num_group_errors == 10) |
67ce483b | 7596 | warn (_("Further error messages about overlarge group section indices suppressed\n")); |
57028622 | 7597 | } |
391cb864 L |
7598 | continue; |
7599 | } | |
391cb864 | 7600 | |
978c4450 | 7601 | if (filedata->section_headers_groups [entry] != NULL) |
e4b17d5c | 7602 | { |
d1f5c6e3 L |
7603 | if (entry) |
7604 | { | |
57028622 NC |
7605 | static unsigned num_errs = 0; |
7606 | ||
7607 | if (num_errs ++ < 10) | |
7608 | { | |
7609 | error (_("section [%5u] in group section [%5u] already in group section [%5u]\n"), | |
7610 | entry, i, | |
978c4450 | 7611 | filedata->section_headers_groups [entry]->group_index); |
57028622 NC |
7612 | if (num_errs == 10) |
7613 | warn (_("Further error messages about already contained group sections suppressed\n")); | |
7614 | } | |
d1f5c6e3 L |
7615 | continue; |
7616 | } | |
7617 | else | |
7618 | { | |
7619 | /* Intel C/C++ compiler may put section 0 in a | |
32ec8896 | 7620 | section group. We just warn it the first time |
d1f5c6e3 | 7621 | and ignore it afterwards. */ |
015dc7e1 | 7622 | static bool warned = false; |
d1f5c6e3 L |
7623 | if (!warned) |
7624 | { | |
7625 | error (_("section 0 in group section [%5u]\n"), | |
978c4450 | 7626 | filedata->section_headers_groups [entry]->group_index); |
015dc7e1 | 7627 | warned = true; |
d1f5c6e3 L |
7628 | } |
7629 | } | |
e4b17d5c L |
7630 | } |
7631 | ||
978c4450 | 7632 | filedata->section_headers_groups [entry] = group; |
e4b17d5c L |
7633 | |
7634 | if (do_section_groups) | |
7635 | { | |
dda8d76d NC |
7636 | sec = filedata->section_headers + entry; |
7637 | printf (" [%5u] %s\n", entry, printable_section_name (filedata, sec)); | |
ba2685cc AM |
7638 | } |
7639 | ||
3f5e193b | 7640 | g = (struct group_list *) xmalloc (sizeof (struct group_list)); |
e4b17d5c L |
7641 | g->section_index = entry; |
7642 | g->next = group->root; | |
7643 | group->root = g; | |
f5842774 L |
7644 | } |
7645 | ||
9db70fc3 | 7646 | free (start); |
e4b17d5c L |
7647 | |
7648 | group++; | |
f5842774 L |
7649 | } |
7650 | } | |
7651 | ||
9db70fc3 AM |
7652 | free (symtab); |
7653 | free (strtab); | |
015dc7e1 | 7654 | return true; |
f5842774 L |
7655 | } |
7656 | ||
28f997cf TG |
7657 | /* Data used to display dynamic fixups. */ |
7658 | ||
7659 | struct ia64_vms_dynfixup | |
7660 | { | |
7661 | bfd_vma needed_ident; /* Library ident number. */ | |
7662 | bfd_vma needed; /* Index in the dstrtab of the library name. */ | |
7663 | bfd_vma fixup_needed; /* Index of the library. */ | |
7664 | bfd_vma fixup_rela_cnt; /* Number of fixups. */ | |
7665 | bfd_vma fixup_rela_off; /* Fixups offset in the dynamic segment. */ | |
7666 | }; | |
7667 | ||
7668 | /* Data used to display dynamic relocations. */ | |
7669 | ||
7670 | struct ia64_vms_dynimgrela | |
7671 | { | |
7672 | bfd_vma img_rela_cnt; /* Number of relocations. */ | |
7673 | bfd_vma img_rela_off; /* Reloc offset in the dynamic segment. */ | |
7674 | }; | |
7675 | ||
7676 | /* Display IA-64 OpenVMS dynamic fixups (used to dynamically link a shared | |
7677 | library). */ | |
7678 | ||
015dc7e1 | 7679 | static bool |
dda8d76d NC |
7680 | dump_ia64_vms_dynamic_fixups (Filedata * filedata, |
7681 | struct ia64_vms_dynfixup * fixup, | |
7682 | const char * strtab, | |
7683 | unsigned int strtab_sz) | |
28f997cf | 7684 | { |
32ec8896 | 7685 | Elf64_External_VMS_IMAGE_FIXUP * imfs; |
28f997cf | 7686 | long i; |
32ec8896 | 7687 | const char * lib_name; |
28f997cf | 7688 | |
978c4450 AM |
7689 | imfs = get_data (NULL, filedata, |
7690 | filedata->dynamic_addr + fixup->fixup_rela_off, | |
95099889 | 7691 | sizeof (*imfs), fixup->fixup_rela_cnt, |
28f997cf TG |
7692 | _("dynamic section image fixups")); |
7693 | if (!imfs) | |
015dc7e1 | 7694 | return false; |
28f997cf TG |
7695 | |
7696 | if (fixup->needed < strtab_sz) | |
7697 | lib_name = strtab + fixup->needed; | |
7698 | else | |
7699 | { | |
32ec8896 | 7700 | warn (_("corrupt library name index of 0x%lx found in dynamic entry"), |
7f01b0c6 | 7701 | (unsigned long) fixup->needed); |
28f997cf TG |
7702 | lib_name = "???"; |
7703 | } | |
736990c4 | 7704 | |
28f997cf TG |
7705 | printf (_("\nImage fixups for needed library #%d: %s - ident: %lx\n"), |
7706 | (int) fixup->fixup_needed, lib_name, (long) fixup->needed_ident); | |
7707 | printf | |
7708 | (_("Seg Offset Type SymVec DataType\n")); | |
7709 | ||
7710 | for (i = 0; i < (long) fixup->fixup_rela_cnt; i++) | |
7711 | { | |
7712 | unsigned int type; | |
7713 | const char *rtype; | |
7714 | ||
7715 | printf ("%3u ", (unsigned) BYTE_GET (imfs [i].fixup_seg)); | |
7716 | printf_vma ((bfd_vma) BYTE_GET (imfs [i].fixup_offset)); | |
7717 | type = BYTE_GET (imfs [i].type); | |
7718 | rtype = elf_ia64_reloc_type (type); | |
7719 | if (rtype == NULL) | |
7720 | printf (" 0x%08x ", type); | |
7721 | else | |
7722 | printf (" %-32s ", rtype); | |
7723 | printf ("%6u ", (unsigned) BYTE_GET (imfs [i].symvec_index)); | |
7724 | printf ("0x%08x\n", (unsigned) BYTE_GET (imfs [i].data_type)); | |
7725 | } | |
7726 | ||
7727 | free (imfs); | |
015dc7e1 | 7728 | return true; |
28f997cf TG |
7729 | } |
7730 | ||
7731 | /* Display IA-64 OpenVMS dynamic relocations (used to relocate an image). */ | |
7732 | ||
015dc7e1 | 7733 | static bool |
dda8d76d | 7734 | dump_ia64_vms_dynamic_relocs (Filedata * filedata, struct ia64_vms_dynimgrela *imgrela) |
28f997cf TG |
7735 | { |
7736 | Elf64_External_VMS_IMAGE_RELA *imrs; | |
7737 | long i; | |
7738 | ||
978c4450 AM |
7739 | imrs = get_data (NULL, filedata, |
7740 | filedata->dynamic_addr + imgrela->img_rela_off, | |
95099889 | 7741 | sizeof (*imrs), imgrela->img_rela_cnt, |
9cf03b7e | 7742 | _("dynamic section image relocations")); |
28f997cf | 7743 | if (!imrs) |
015dc7e1 | 7744 | return false; |
28f997cf TG |
7745 | |
7746 | printf (_("\nImage relocs\n")); | |
7747 | printf | |
7748 | (_("Seg Offset Type Addend Seg Sym Off\n")); | |
7749 | ||
7750 | for (i = 0; i < (long) imgrela->img_rela_cnt; i++) | |
7751 | { | |
7752 | unsigned int type; | |
7753 | const char *rtype; | |
7754 | ||
7755 | printf ("%3u ", (unsigned) BYTE_GET (imrs [i].rela_seg)); | |
7756 | printf ("%08" BFD_VMA_FMT "x ", | |
7757 | (bfd_vma) BYTE_GET (imrs [i].rela_offset)); | |
7758 | type = BYTE_GET (imrs [i].type); | |
7759 | rtype = elf_ia64_reloc_type (type); | |
7760 | if (rtype == NULL) | |
7761 | printf ("0x%08x ", type); | |
7762 | else | |
7763 | printf ("%-31s ", rtype); | |
7764 | print_vma (BYTE_GET (imrs [i].addend), FULL_HEX); | |
7765 | printf ("%3u ", (unsigned) BYTE_GET (imrs [i].sym_seg)); | |
7766 | printf ("%08" BFD_VMA_FMT "x\n", | |
7767 | (bfd_vma) BYTE_GET (imrs [i].sym_offset)); | |
7768 | } | |
7769 | ||
7770 | free (imrs); | |
015dc7e1 | 7771 | return true; |
28f997cf TG |
7772 | } |
7773 | ||
7774 | /* Display IA-64 OpenVMS dynamic relocations and fixups. */ | |
7775 | ||
015dc7e1 | 7776 | static bool |
dda8d76d | 7777 | process_ia64_vms_dynamic_relocs (Filedata * filedata) |
28f997cf TG |
7778 | { |
7779 | struct ia64_vms_dynfixup fixup; | |
7780 | struct ia64_vms_dynimgrela imgrela; | |
7781 | Elf_Internal_Dyn *entry; | |
28f997cf TG |
7782 | bfd_vma strtab_off = 0; |
7783 | bfd_vma strtab_sz = 0; | |
7784 | char *strtab = NULL; | |
015dc7e1 | 7785 | bool res = true; |
28f997cf TG |
7786 | |
7787 | memset (&fixup, 0, sizeof (fixup)); | |
7788 | memset (&imgrela, 0, sizeof (imgrela)); | |
7789 | ||
7790 | /* Note: the order of the entries is specified by the OpenVMS specs. */ | |
978c4450 AM |
7791 | for (entry = filedata->dynamic_section; |
7792 | entry < filedata->dynamic_section + filedata->dynamic_nent; | |
28f997cf TG |
7793 | entry++) |
7794 | { | |
7795 | switch (entry->d_tag) | |
7796 | { | |
7797 | case DT_IA_64_VMS_STRTAB_OFFSET: | |
7798 | strtab_off = entry->d_un.d_val; | |
7799 | break; | |
7800 | case DT_STRSZ: | |
7801 | strtab_sz = entry->d_un.d_val; | |
7802 | if (strtab == NULL) | |
978c4450 AM |
7803 | strtab = get_data (NULL, filedata, |
7804 | filedata->dynamic_addr + strtab_off, | |
28f997cf | 7805 | 1, strtab_sz, _("dynamic string section")); |
736990c4 NC |
7806 | if (strtab == NULL) |
7807 | strtab_sz = 0; | |
28f997cf TG |
7808 | break; |
7809 | ||
7810 | case DT_IA_64_VMS_NEEDED_IDENT: | |
7811 | fixup.needed_ident = entry->d_un.d_val; | |
7812 | break; | |
7813 | case DT_NEEDED: | |
7814 | fixup.needed = entry->d_un.d_val; | |
7815 | break; | |
7816 | case DT_IA_64_VMS_FIXUP_NEEDED: | |
7817 | fixup.fixup_needed = entry->d_un.d_val; | |
7818 | break; | |
7819 | case DT_IA_64_VMS_FIXUP_RELA_CNT: | |
7820 | fixup.fixup_rela_cnt = entry->d_un.d_val; | |
7821 | break; | |
7822 | case DT_IA_64_VMS_FIXUP_RELA_OFF: | |
7823 | fixup.fixup_rela_off = entry->d_un.d_val; | |
dda8d76d | 7824 | if (! dump_ia64_vms_dynamic_fixups (filedata, &fixup, strtab, strtab_sz)) |
015dc7e1 | 7825 | res = false; |
28f997cf | 7826 | break; |
28f997cf TG |
7827 | case DT_IA_64_VMS_IMG_RELA_CNT: |
7828 | imgrela.img_rela_cnt = entry->d_un.d_val; | |
7829 | break; | |
7830 | case DT_IA_64_VMS_IMG_RELA_OFF: | |
7831 | imgrela.img_rela_off = entry->d_un.d_val; | |
dda8d76d | 7832 | if (! dump_ia64_vms_dynamic_relocs (filedata, &imgrela)) |
015dc7e1 | 7833 | res = false; |
28f997cf TG |
7834 | break; |
7835 | ||
7836 | default: | |
7837 | break; | |
7838 | } | |
7839 | } | |
7840 | ||
9db70fc3 | 7841 | free (strtab); |
28f997cf TG |
7842 | |
7843 | return res; | |
7844 | } | |
7845 | ||
85b1c36d | 7846 | static struct |
566b0d53 | 7847 | { |
2cf0635d | 7848 | const char * name; |
566b0d53 L |
7849 | int reloc; |
7850 | int size; | |
7851 | int rela; | |
32ec8896 NC |
7852 | } |
7853 | dynamic_relocations [] = | |
566b0d53 | 7854 | { |
015dc7e1 AM |
7855 | { "REL", DT_REL, DT_RELSZ, false }, |
7856 | { "RELA", DT_RELA, DT_RELASZ, true }, | |
32ec8896 | 7857 | { "PLT", DT_JMPREL, DT_PLTRELSZ, UNKNOWN } |
566b0d53 L |
7858 | }; |
7859 | ||
252b5132 | 7860 | /* Process the reloc section. */ |
18bd398b | 7861 | |
015dc7e1 | 7862 | static bool |
dda8d76d | 7863 | process_relocs (Filedata * filedata) |
252b5132 | 7864 | { |
b34976b6 AM |
7865 | unsigned long rel_size; |
7866 | unsigned long rel_offset; | |
252b5132 | 7867 | |
252b5132 | 7868 | if (!do_reloc) |
015dc7e1 | 7869 | return true; |
252b5132 RH |
7870 | |
7871 | if (do_using_dynamic) | |
7872 | { | |
32ec8896 | 7873 | int is_rela; |
2cf0635d | 7874 | const char * name; |
015dc7e1 | 7875 | bool has_dynamic_reloc; |
566b0d53 | 7876 | unsigned int i; |
0de14b54 | 7877 | |
015dc7e1 | 7878 | has_dynamic_reloc = false; |
252b5132 | 7879 | |
566b0d53 | 7880 | for (i = 0; i < ARRAY_SIZE (dynamic_relocations); i++) |
252b5132 | 7881 | { |
566b0d53 L |
7882 | is_rela = dynamic_relocations [i].rela; |
7883 | name = dynamic_relocations [i].name; | |
978c4450 AM |
7884 | rel_size = filedata->dynamic_info[dynamic_relocations [i].size]; |
7885 | rel_offset = filedata->dynamic_info[dynamic_relocations [i].reloc]; | |
103f02d3 | 7886 | |
32ec8896 | 7887 | if (rel_size) |
015dc7e1 | 7888 | has_dynamic_reloc = true; |
566b0d53 L |
7889 | |
7890 | if (is_rela == UNKNOWN) | |
aa903cfb | 7891 | { |
566b0d53 | 7892 | if (dynamic_relocations [i].reloc == DT_JMPREL) |
978c4450 | 7893 | switch (filedata->dynamic_info[DT_PLTREL]) |
566b0d53 L |
7894 | { |
7895 | case DT_REL: | |
015dc7e1 | 7896 | is_rela = false; |
566b0d53 L |
7897 | break; |
7898 | case DT_RELA: | |
015dc7e1 | 7899 | is_rela = true; |
566b0d53 L |
7900 | break; |
7901 | } | |
aa903cfb | 7902 | } |
252b5132 | 7903 | |
566b0d53 L |
7904 | if (rel_size) |
7905 | { | |
ca0e11aa NC |
7906 | if (filedata->is_separate) |
7907 | printf | |
7908 | (_("\nIn linked file '%s' section '%s' at offset 0x%lx contains %ld bytes:\n"), | |
7909 | filedata->file_name, name, rel_offset, rel_size); | |
7910 | else | |
7911 | printf | |
7912 | (_("\n'%s' relocation section at offset 0x%lx contains %ld bytes:\n"), | |
7913 | name, rel_offset, rel_size); | |
252b5132 | 7914 | |
dda8d76d NC |
7915 | dump_relocations (filedata, |
7916 | offset_from_vma (filedata, rel_offset, rel_size), | |
d93f0186 | 7917 | rel_size, |
978c4450 AM |
7918 | filedata->dynamic_symbols, |
7919 | filedata->num_dynamic_syms, | |
7920 | filedata->dynamic_strings, | |
7921 | filedata->dynamic_strings_length, | |
015dc7e1 | 7922 | is_rela, true /* is_dynamic */); |
566b0d53 | 7923 | } |
252b5132 | 7924 | } |
566b0d53 | 7925 | |
dda8d76d NC |
7926 | if (is_ia64_vms (filedata)) |
7927 | if (process_ia64_vms_dynamic_relocs (filedata)) | |
015dc7e1 | 7928 | has_dynamic_reloc = true; |
28f997cf | 7929 | |
566b0d53 | 7930 | if (! has_dynamic_reloc) |
ca0e11aa NC |
7931 | { |
7932 | if (filedata->is_separate) | |
7933 | printf (_("\nThere are no dynamic relocations in linked file '%s'.\n"), | |
7934 | filedata->file_name); | |
7935 | else | |
7936 | printf (_("\nThere are no dynamic relocations in this file.\n")); | |
7937 | } | |
252b5132 RH |
7938 | } |
7939 | else | |
7940 | { | |
2cf0635d | 7941 | Elf_Internal_Shdr * section; |
b34976b6 | 7942 | unsigned long i; |
015dc7e1 | 7943 | bool found = false; |
252b5132 | 7944 | |
dda8d76d NC |
7945 | for (i = 0, section = filedata->section_headers; |
7946 | i < filedata->file_header.e_shnum; | |
b34976b6 | 7947 | i++, section++) |
252b5132 RH |
7948 | { |
7949 | if ( section->sh_type != SHT_RELA | |
7950 | && section->sh_type != SHT_REL) | |
7951 | continue; | |
7952 | ||
7953 | rel_offset = section->sh_offset; | |
7954 | rel_size = section->sh_size; | |
7955 | ||
7956 | if (rel_size) | |
7957 | { | |
b34976b6 | 7958 | int is_rela; |
d3a49aa8 | 7959 | unsigned long num_rela; |
103f02d3 | 7960 | |
ca0e11aa NC |
7961 | if (filedata->is_separate) |
7962 | printf (_("\nIn linked file '%s' relocation section "), | |
7963 | filedata->file_name); | |
7964 | else | |
7965 | printf (_("\nRelocation section ")); | |
252b5132 | 7966 | |
dda8d76d | 7967 | if (filedata->string_table == NULL) |
19936277 | 7968 | printf ("%d", section->sh_name); |
252b5132 | 7969 | else |
dda8d76d | 7970 | printf ("'%s'", printable_section_name (filedata, section)); |
252b5132 | 7971 | |
d3a49aa8 AM |
7972 | num_rela = rel_size / section->sh_entsize; |
7973 | printf (ngettext (" at offset 0x%lx contains %lu entry:\n", | |
7974 | " at offset 0x%lx contains %lu entries:\n", | |
7975 | num_rela), | |
7976 | rel_offset, num_rela); | |
252b5132 | 7977 | |
d79b3d50 NC |
7978 | is_rela = section->sh_type == SHT_RELA; |
7979 | ||
4fbb74a6 | 7980 | if (section->sh_link != 0 |
dda8d76d | 7981 | && section->sh_link < filedata->file_header.e_shnum) |
af3fc3bc | 7982 | { |
2cf0635d NC |
7983 | Elf_Internal_Shdr * symsec; |
7984 | Elf_Internal_Sym * symtab; | |
d79b3d50 | 7985 | unsigned long nsyms; |
c256ffe7 | 7986 | unsigned long strtablen = 0; |
2cf0635d | 7987 | char * strtab = NULL; |
57346661 | 7988 | |
dda8d76d | 7989 | symsec = filedata->section_headers + section->sh_link; |
08d8fa11 JJ |
7990 | if (symsec->sh_type != SHT_SYMTAB |
7991 | && symsec->sh_type != SHT_DYNSYM) | |
7992 | continue; | |
7993 | ||
28d13567 AM |
7994 | if (!get_symtab (filedata, symsec, |
7995 | &symtab, &nsyms, &strtab, &strtablen)) | |
af3fc3bc | 7996 | continue; |
252b5132 | 7997 | |
dda8d76d | 7998 | dump_relocations (filedata, rel_offset, rel_size, |
bb4d2ac2 L |
7999 | symtab, nsyms, strtab, strtablen, |
8000 | is_rela, | |
8001 | symsec->sh_type == SHT_DYNSYM); | |
9db70fc3 | 8002 | free (strtab); |
d79b3d50 NC |
8003 | free (symtab); |
8004 | } | |
8005 | else | |
dda8d76d | 8006 | dump_relocations (filedata, rel_offset, rel_size, |
32ec8896 | 8007 | NULL, 0, NULL, 0, is_rela, |
015dc7e1 | 8008 | false /* is_dynamic */); |
252b5132 | 8009 | |
015dc7e1 | 8010 | found = true; |
252b5132 RH |
8011 | } |
8012 | } | |
8013 | ||
8014 | if (! found) | |
45ac8f4f NC |
8015 | { |
8016 | /* Users sometimes forget the -D option, so try to be helpful. */ | |
8017 | for (i = 0; i < ARRAY_SIZE (dynamic_relocations); i++) | |
8018 | { | |
978c4450 | 8019 | if (filedata->dynamic_info[dynamic_relocations [i].size]) |
45ac8f4f | 8020 | { |
ca0e11aa NC |
8021 | if (filedata->is_separate) |
8022 | printf (_("\nThere are no static relocations in linked file '%s'."), | |
8023 | filedata->file_name); | |
8024 | else | |
8025 | printf (_("\nThere are no static relocations in this file.")); | |
45ac8f4f NC |
8026 | printf (_("\nTo see the dynamic relocations add --use-dynamic to the command line.\n")); |
8027 | ||
8028 | break; | |
8029 | } | |
8030 | } | |
8031 | if (i == ARRAY_SIZE (dynamic_relocations)) | |
ca0e11aa NC |
8032 | { |
8033 | if (filedata->is_separate) | |
8034 | printf (_("\nThere are no relocations in linked file '%s'.\n"), | |
8035 | filedata->file_name); | |
8036 | else | |
8037 | printf (_("\nThere are no relocations in this file.\n")); | |
8038 | } | |
45ac8f4f | 8039 | } |
252b5132 RH |
8040 | } |
8041 | ||
015dc7e1 | 8042 | return true; |
252b5132 RH |
8043 | } |
8044 | ||
4d6ed7c8 NC |
8045 | /* An absolute address consists of a section and an offset. If the |
8046 | section is NULL, the offset itself is the address, otherwise, the | |
8047 | address equals to LOAD_ADDRESS(section) + offset. */ | |
8048 | ||
8049 | struct absaddr | |
948f632f DA |
8050 | { |
8051 | unsigned short section; | |
8052 | bfd_vma offset; | |
8053 | }; | |
4d6ed7c8 | 8054 | |
948f632f DA |
8055 | /* Find the nearest symbol at or below ADDR. Returns the symbol |
8056 | name, if found, and the offset from the symbol to ADDR. */ | |
4d6ed7c8 | 8057 | |
4d6ed7c8 | 8058 | static void |
dda8d76d NC |
8059 | find_symbol_for_address (Filedata * filedata, |
8060 | Elf_Internal_Sym * symtab, | |
8061 | unsigned long nsyms, | |
8062 | const char * strtab, | |
8063 | unsigned long strtab_size, | |
8064 | struct absaddr addr, | |
8065 | const char ** symname, | |
8066 | bfd_vma * offset) | |
4d6ed7c8 | 8067 | { |
d3ba0551 | 8068 | bfd_vma dist = 0x100000; |
2cf0635d | 8069 | Elf_Internal_Sym * sym; |
948f632f DA |
8070 | Elf_Internal_Sym * beg; |
8071 | Elf_Internal_Sym * end; | |
2cf0635d | 8072 | Elf_Internal_Sym * best = NULL; |
4d6ed7c8 | 8073 | |
0b6ae522 | 8074 | REMOVE_ARCH_BITS (addr.offset); |
948f632f DA |
8075 | beg = symtab; |
8076 | end = symtab + nsyms; | |
0b6ae522 | 8077 | |
948f632f | 8078 | while (beg < end) |
4d6ed7c8 | 8079 | { |
948f632f DA |
8080 | bfd_vma value; |
8081 | ||
8082 | sym = beg + (end - beg) / 2; | |
0b6ae522 | 8083 | |
948f632f | 8084 | value = sym->st_value; |
0b6ae522 DJ |
8085 | REMOVE_ARCH_BITS (value); |
8086 | ||
948f632f | 8087 | if (sym->st_name != 0 |
4d6ed7c8 | 8088 | && (addr.section == SHN_UNDEF || addr.section == sym->st_shndx) |
0b6ae522 DJ |
8089 | && addr.offset >= value |
8090 | && addr.offset - value < dist) | |
4d6ed7c8 NC |
8091 | { |
8092 | best = sym; | |
0b6ae522 | 8093 | dist = addr.offset - value; |
4d6ed7c8 NC |
8094 | if (!dist) |
8095 | break; | |
8096 | } | |
948f632f DA |
8097 | |
8098 | if (addr.offset < value) | |
8099 | end = sym; | |
8100 | else | |
8101 | beg = sym + 1; | |
4d6ed7c8 | 8102 | } |
1b31d05e | 8103 | |
4d6ed7c8 NC |
8104 | if (best) |
8105 | { | |
57346661 | 8106 | *symname = (best->st_name >= strtab_size |
2b692964 | 8107 | ? _("<corrupt>") : strtab + best->st_name); |
4d6ed7c8 NC |
8108 | *offset = dist; |
8109 | return; | |
8110 | } | |
1b31d05e | 8111 | |
4d6ed7c8 NC |
8112 | *symname = NULL; |
8113 | *offset = addr.offset; | |
8114 | } | |
8115 | ||
32ec8896 | 8116 | static /* signed */ int |
948f632f DA |
8117 | symcmp (const void *p, const void *q) |
8118 | { | |
8119 | Elf_Internal_Sym *sp = (Elf_Internal_Sym *) p; | |
8120 | Elf_Internal_Sym *sq = (Elf_Internal_Sym *) q; | |
8121 | ||
8122 | return sp->st_value > sq->st_value ? 1 : (sp->st_value < sq->st_value ? -1 : 0); | |
8123 | } | |
8124 | ||
8125 | /* Process the unwind section. */ | |
8126 | ||
8127 | #include "unwind-ia64.h" | |
8128 | ||
8129 | struct ia64_unw_table_entry | |
8130 | { | |
8131 | struct absaddr start; | |
8132 | struct absaddr end; | |
8133 | struct absaddr info; | |
8134 | }; | |
8135 | ||
8136 | struct ia64_unw_aux_info | |
8137 | { | |
32ec8896 NC |
8138 | struct ia64_unw_table_entry * table; /* Unwind table. */ |
8139 | unsigned long table_len; /* Length of unwind table. */ | |
8140 | unsigned char * info; /* Unwind info. */ | |
8141 | unsigned long info_size; /* Size of unwind info. */ | |
8142 | bfd_vma info_addr; /* Starting address of unwind info. */ | |
8143 | bfd_vma seg_base; /* Starting address of segment. */ | |
8144 | Elf_Internal_Sym * symtab; /* The symbol table. */ | |
8145 | unsigned long nsyms; /* Number of symbols. */ | |
8146 | Elf_Internal_Sym * funtab; /* Sorted table of STT_FUNC symbols. */ | |
8147 | unsigned long nfuns; /* Number of entries in funtab. */ | |
8148 | char * strtab; /* The string table. */ | |
8149 | unsigned long strtab_size; /* Size of string table. */ | |
948f632f DA |
8150 | }; |
8151 | ||
015dc7e1 | 8152 | static bool |
dda8d76d | 8153 | dump_ia64_unwind (Filedata * filedata, struct ia64_unw_aux_info * aux) |
4d6ed7c8 | 8154 | { |
2cf0635d | 8155 | struct ia64_unw_table_entry * tp; |
948f632f | 8156 | unsigned long j, nfuns; |
4d6ed7c8 | 8157 | int in_body; |
015dc7e1 | 8158 | bool res = true; |
7036c0e1 | 8159 | |
948f632f DA |
8160 | aux->funtab = xmalloc (aux->nsyms * sizeof (Elf_Internal_Sym)); |
8161 | for (nfuns = 0, j = 0; j < aux->nsyms; j++) | |
8162 | if (aux->symtab[j].st_value && ELF_ST_TYPE (aux->symtab[j].st_info) == STT_FUNC) | |
8163 | aux->funtab[nfuns++] = aux->symtab[j]; | |
8164 | aux->nfuns = nfuns; | |
8165 | qsort (aux->funtab, aux->nfuns, sizeof (Elf_Internal_Sym), symcmp); | |
8166 | ||
4d6ed7c8 NC |
8167 | for (tp = aux->table; tp < aux->table + aux->table_len; ++tp) |
8168 | { | |
8169 | bfd_vma stamp; | |
8170 | bfd_vma offset; | |
2cf0635d NC |
8171 | const unsigned char * dp; |
8172 | const unsigned char * head; | |
53774b7e | 8173 | const unsigned char * end; |
2cf0635d | 8174 | const char * procname; |
4d6ed7c8 | 8175 | |
dda8d76d | 8176 | find_symbol_for_address (filedata, aux->funtab, aux->nfuns, aux->strtab, |
57346661 | 8177 | aux->strtab_size, tp->start, &procname, &offset); |
4d6ed7c8 NC |
8178 | |
8179 | fputs ("\n<", stdout); | |
8180 | ||
8181 | if (procname) | |
8182 | { | |
8183 | fputs (procname, stdout); | |
8184 | ||
8185 | if (offset) | |
8186 | printf ("+%lx", (unsigned long) offset); | |
8187 | } | |
8188 | ||
8189 | fputs (">: [", stdout); | |
8190 | print_vma (tp->start.offset, PREFIX_HEX); | |
8191 | fputc ('-', stdout); | |
8192 | print_vma (tp->end.offset, PREFIX_HEX); | |
86f55779 | 8193 | printf ("], info at +0x%lx\n", |
4d6ed7c8 NC |
8194 | (unsigned long) (tp->info.offset - aux->seg_base)); |
8195 | ||
53774b7e NC |
8196 | /* PR 17531: file: 86232b32. */ |
8197 | if (aux->info == NULL) | |
8198 | continue; | |
8199 | ||
97c0a079 AM |
8200 | offset = tp->info.offset; |
8201 | if (tp->info.section) | |
8202 | { | |
8203 | if (tp->info.section >= filedata->file_header.e_shnum) | |
8204 | { | |
8205 | warn (_("Invalid section %u in table entry %ld\n"), | |
8206 | tp->info.section, (long) (tp - aux->table)); | |
015dc7e1 | 8207 | res = false; |
97c0a079 AM |
8208 | continue; |
8209 | } | |
8210 | offset += filedata->section_headers[tp->info.section].sh_addr; | |
8211 | } | |
8212 | offset -= aux->info_addr; | |
53774b7e | 8213 | /* PR 17531: file: 0997b4d1. */ |
90679903 AM |
8214 | if (offset >= aux->info_size |
8215 | || aux->info_size - offset < 8) | |
53774b7e NC |
8216 | { |
8217 | warn (_("Invalid offset %lx in table entry %ld\n"), | |
8218 | (long) tp->info.offset, (long) (tp - aux->table)); | |
015dc7e1 | 8219 | res = false; |
53774b7e NC |
8220 | continue; |
8221 | } | |
8222 | ||
97c0a079 | 8223 | head = aux->info + offset; |
a4a00738 | 8224 | stamp = byte_get ((unsigned char *) head, sizeof (stamp)); |
4d6ed7c8 | 8225 | |
86f55779 | 8226 | printf (" v%u, flags=0x%lx (%s%s), len=%lu bytes\n", |
4d6ed7c8 NC |
8227 | (unsigned) UNW_VER (stamp), |
8228 | (unsigned long) ((stamp & UNW_FLAG_MASK) >> 32), | |
8229 | UNW_FLAG_EHANDLER (stamp) ? " ehandler" : "", | |
8230 | UNW_FLAG_UHANDLER (stamp) ? " uhandler" : "", | |
89fac5e3 | 8231 | (unsigned long) (eh_addr_size * UNW_LENGTH (stamp))); |
4d6ed7c8 NC |
8232 | |
8233 | if (UNW_VER (stamp) != 1) | |
8234 | { | |
2b692964 | 8235 | printf (_("\tUnknown version.\n")); |
4d6ed7c8 NC |
8236 | continue; |
8237 | } | |
8238 | ||
8239 | in_body = 0; | |
53774b7e NC |
8240 | end = head + 8 + eh_addr_size * UNW_LENGTH (stamp); |
8241 | /* PR 17531: file: 16ceda89. */ | |
8242 | if (end > aux->info + aux->info_size) | |
8243 | end = aux->info + aux->info_size; | |
8244 | for (dp = head + 8; dp < end;) | |
b4477bc8 | 8245 | dp = unw_decode (dp, in_body, & in_body, end); |
4d6ed7c8 | 8246 | } |
948f632f DA |
8247 | |
8248 | free (aux->funtab); | |
32ec8896 NC |
8249 | |
8250 | return res; | |
4d6ed7c8 NC |
8251 | } |
8252 | ||
015dc7e1 | 8253 | static bool |
dda8d76d NC |
8254 | slurp_ia64_unwind_table (Filedata * filedata, |
8255 | struct ia64_unw_aux_info * aux, | |
8256 | Elf_Internal_Shdr * sec) | |
4d6ed7c8 | 8257 | { |
89fac5e3 | 8258 | unsigned long size, nrelas, i; |
2cf0635d NC |
8259 | Elf_Internal_Phdr * seg; |
8260 | struct ia64_unw_table_entry * tep; | |
8261 | Elf_Internal_Shdr * relsec; | |
8262 | Elf_Internal_Rela * rela; | |
8263 | Elf_Internal_Rela * rp; | |
8264 | unsigned char * table; | |
8265 | unsigned char * tp; | |
8266 | Elf_Internal_Sym * sym; | |
8267 | const char * relname; | |
4d6ed7c8 | 8268 | |
53774b7e NC |
8269 | aux->table_len = 0; |
8270 | ||
4d6ed7c8 NC |
8271 | /* First, find the starting address of the segment that includes |
8272 | this section: */ | |
8273 | ||
dda8d76d | 8274 | if (filedata->file_header.e_phnum) |
4d6ed7c8 | 8275 | { |
dda8d76d | 8276 | if (! get_program_headers (filedata)) |
015dc7e1 | 8277 | return false; |
4d6ed7c8 | 8278 | |
dda8d76d NC |
8279 | for (seg = filedata->program_headers; |
8280 | seg < filedata->program_headers + filedata->file_header.e_phnum; | |
d93f0186 | 8281 | ++seg) |
4d6ed7c8 NC |
8282 | { |
8283 | if (seg->p_type != PT_LOAD) | |
8284 | continue; | |
8285 | ||
8286 | if (sec->sh_addr >= seg->p_vaddr | |
8287 | && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz)) | |
8288 | { | |
8289 | aux->seg_base = seg->p_vaddr; | |
8290 | break; | |
8291 | } | |
8292 | } | |
4d6ed7c8 NC |
8293 | } |
8294 | ||
8295 | /* Second, build the unwind table from the contents of the unwind section: */ | |
8296 | size = sec->sh_size; | |
dda8d76d | 8297 | table = (unsigned char *) get_data (NULL, filedata, sec->sh_offset, 1, size, |
3f5e193b | 8298 | _("unwind table")); |
a6e9f9df | 8299 | if (!table) |
015dc7e1 | 8300 | return false; |
4d6ed7c8 | 8301 | |
53774b7e | 8302 | aux->table_len = size / (3 * eh_addr_size); |
3f5e193b | 8303 | aux->table = (struct ia64_unw_table_entry *) |
53774b7e | 8304 | xcmalloc (aux->table_len, sizeof (aux->table[0])); |
89fac5e3 | 8305 | tep = aux->table; |
53774b7e NC |
8306 | |
8307 | for (tp = table; tp <= table + size - (3 * eh_addr_size); ++tep) | |
4d6ed7c8 NC |
8308 | { |
8309 | tep->start.section = SHN_UNDEF; | |
8310 | tep->end.section = SHN_UNDEF; | |
8311 | tep->info.section = SHN_UNDEF; | |
c6a0c689 AM |
8312 | tep->start.offset = byte_get (tp, eh_addr_size); tp += eh_addr_size; |
8313 | tep->end.offset = byte_get (tp, eh_addr_size); tp += eh_addr_size; | |
8314 | tep->info.offset = byte_get (tp, eh_addr_size); tp += eh_addr_size; | |
4d6ed7c8 NC |
8315 | tep->start.offset += aux->seg_base; |
8316 | tep->end.offset += aux->seg_base; | |
8317 | tep->info.offset += aux->seg_base; | |
8318 | } | |
8319 | free (table); | |
8320 | ||
41e92641 | 8321 | /* Third, apply any relocations to the unwind table: */ |
dda8d76d NC |
8322 | for (relsec = filedata->section_headers; |
8323 | relsec < filedata->section_headers + filedata->file_header.e_shnum; | |
4d6ed7c8 NC |
8324 | ++relsec) |
8325 | { | |
8326 | if (relsec->sh_type != SHT_RELA | |
dda8d76d NC |
8327 | || relsec->sh_info >= filedata->file_header.e_shnum |
8328 | || filedata->section_headers + relsec->sh_info != sec) | |
4d6ed7c8 NC |
8329 | continue; |
8330 | ||
dda8d76d | 8331 | if (!slurp_rela_relocs (filedata, relsec->sh_offset, relsec->sh_size, |
4d6ed7c8 | 8332 | & rela, & nrelas)) |
53774b7e NC |
8333 | { |
8334 | free (aux->table); | |
8335 | aux->table = NULL; | |
8336 | aux->table_len = 0; | |
015dc7e1 | 8337 | return false; |
53774b7e | 8338 | } |
4d6ed7c8 NC |
8339 | |
8340 | for (rp = rela; rp < rela + nrelas; ++rp) | |
8341 | { | |
4770fb94 | 8342 | unsigned int sym_ndx; |
726bd37d AM |
8343 | unsigned int r_type = get_reloc_type (filedata, rp->r_info); |
8344 | relname = elf_ia64_reloc_type (r_type); | |
4d6ed7c8 | 8345 | |
82b1b41b NC |
8346 | /* PR 17531: file: 9fa67536. */ |
8347 | if (relname == NULL) | |
8348 | { | |
726bd37d | 8349 | warn (_("Skipping unknown relocation type: %u\n"), r_type); |
82b1b41b NC |
8350 | continue; |
8351 | } | |
948f632f | 8352 | |
24d127aa | 8353 | if (! startswith (relname, "R_IA64_SEGREL")) |
4d6ed7c8 | 8354 | { |
82b1b41b | 8355 | warn (_("Skipping unexpected relocation type: %s\n"), relname); |
4d6ed7c8 NC |
8356 | continue; |
8357 | } | |
8358 | ||
89fac5e3 | 8359 | i = rp->r_offset / (3 * eh_addr_size); |
4d6ed7c8 | 8360 | |
53774b7e NC |
8361 | /* PR 17531: file: 5bc8d9bf. */ |
8362 | if (i >= aux->table_len) | |
8363 | { | |
8364 | warn (_("Skipping reloc with overlarge offset: %lx\n"), i); | |
8365 | continue; | |
8366 | } | |
8367 | ||
4770fb94 AM |
8368 | sym_ndx = get_reloc_symindex (rp->r_info); |
8369 | if (sym_ndx >= aux->nsyms) | |
8370 | { | |
8371 | warn (_("Skipping reloc with invalid symbol index: %u\n"), | |
8372 | sym_ndx); | |
8373 | continue; | |
8374 | } | |
8375 | sym = aux->symtab + sym_ndx; | |
8376 | ||
53774b7e | 8377 | switch (rp->r_offset / eh_addr_size % 3) |
4d6ed7c8 NC |
8378 | { |
8379 | case 0: | |
8380 | aux->table[i].start.section = sym->st_shndx; | |
e466bc6e | 8381 | aux->table[i].start.offset = rp->r_addend + sym->st_value; |
4d6ed7c8 NC |
8382 | break; |
8383 | case 1: | |
8384 | aux->table[i].end.section = sym->st_shndx; | |
e466bc6e | 8385 | aux->table[i].end.offset = rp->r_addend + sym->st_value; |
4d6ed7c8 NC |
8386 | break; |
8387 | case 2: | |
8388 | aux->table[i].info.section = sym->st_shndx; | |
e466bc6e | 8389 | aux->table[i].info.offset = rp->r_addend + sym->st_value; |
4d6ed7c8 NC |
8390 | break; |
8391 | default: | |
8392 | break; | |
8393 | } | |
8394 | } | |
8395 | ||
8396 | free (rela); | |
8397 | } | |
8398 | ||
015dc7e1 | 8399 | return true; |
4d6ed7c8 NC |
8400 | } |
8401 | ||
015dc7e1 | 8402 | static bool |
dda8d76d | 8403 | ia64_process_unwind (Filedata * filedata) |
4d6ed7c8 | 8404 | { |
2cf0635d NC |
8405 | Elf_Internal_Shdr * sec; |
8406 | Elf_Internal_Shdr * unwsec = NULL; | |
89fac5e3 | 8407 | unsigned long i, unwcount = 0, unwstart = 0; |
57346661 | 8408 | struct ia64_unw_aux_info aux; |
015dc7e1 | 8409 | bool res = true; |
f1467e33 | 8410 | |
4d6ed7c8 NC |
8411 | memset (& aux, 0, sizeof (aux)); |
8412 | ||
dda8d76d | 8413 | for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec) |
4d6ed7c8 | 8414 | { |
28d13567 | 8415 | if (sec->sh_type == SHT_SYMTAB) |
4d6ed7c8 | 8416 | { |
28d13567 | 8417 | if (aux.symtab) |
4082ef84 | 8418 | { |
28d13567 AM |
8419 | error (_("Multiple symbol tables encountered\n")); |
8420 | free (aux.symtab); | |
8421 | aux.symtab = NULL; | |
4082ef84 | 8422 | free (aux.strtab); |
28d13567 | 8423 | aux.strtab = NULL; |
4082ef84 | 8424 | } |
28d13567 AM |
8425 | if (!get_symtab (filedata, sec, &aux.symtab, &aux.nsyms, |
8426 | &aux.strtab, &aux.strtab_size)) | |
015dc7e1 | 8427 | return false; |
4d6ed7c8 NC |
8428 | } |
8429 | else if (sec->sh_type == SHT_IA_64_UNWIND) | |
579f31ac JJ |
8430 | unwcount++; |
8431 | } | |
8432 | ||
8433 | if (!unwcount) | |
8434 | printf (_("\nThere are no unwind sections in this file.\n")); | |
8435 | ||
8436 | while (unwcount-- > 0) | |
8437 | { | |
84714f86 | 8438 | const char *suffix; |
579f31ac JJ |
8439 | size_t len, len2; |
8440 | ||
dda8d76d NC |
8441 | for (i = unwstart, sec = filedata->section_headers + unwstart, unwsec = NULL; |
8442 | i < filedata->file_header.e_shnum; ++i, ++sec) | |
579f31ac JJ |
8443 | if (sec->sh_type == SHT_IA_64_UNWIND) |
8444 | { | |
8445 | unwsec = sec; | |
8446 | break; | |
8447 | } | |
4082ef84 NC |
8448 | /* We have already counted the number of SHT_IA64_UNWIND |
8449 | sections so the loop above should never fail. */ | |
8450 | assert (unwsec != NULL); | |
579f31ac JJ |
8451 | |
8452 | unwstart = i + 1; | |
8453 | len = sizeof (ELF_STRING_ia64_unwind_once) - 1; | |
8454 | ||
e4b17d5c L |
8455 | if ((unwsec->sh_flags & SHF_GROUP) != 0) |
8456 | { | |
8457 | /* We need to find which section group it is in. */ | |
4082ef84 | 8458 | struct group_list * g; |
e4b17d5c | 8459 | |
978c4450 AM |
8460 | if (filedata->section_headers_groups == NULL |
8461 | || filedata->section_headers_groups[i] == NULL) | |
dda8d76d | 8462 | i = filedata->file_header.e_shnum; |
4082ef84 | 8463 | else |
e4b17d5c | 8464 | { |
978c4450 | 8465 | g = filedata->section_headers_groups[i]->root; |
18bd398b | 8466 | |
4082ef84 NC |
8467 | for (; g != NULL; g = g->next) |
8468 | { | |
dda8d76d | 8469 | sec = filedata->section_headers + g->section_index; |
e4b17d5c | 8470 | |
84714f86 AM |
8471 | if (section_name_valid (filedata, sec) |
8472 | && streq (section_name (filedata, sec), | |
8473 | ELF_STRING_ia64_unwind_info)) | |
4082ef84 NC |
8474 | break; |
8475 | } | |
8476 | ||
8477 | if (g == NULL) | |
dda8d76d | 8478 | i = filedata->file_header.e_shnum; |
4082ef84 | 8479 | } |
e4b17d5c | 8480 | } |
84714f86 AM |
8481 | else if (section_name_valid (filedata, unwsec) |
8482 | && startswith (section_name (filedata, unwsec), | |
e9b095a5 | 8483 | ELF_STRING_ia64_unwind_once)) |
579f31ac | 8484 | { |
18bd398b | 8485 | /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO. */ |
579f31ac | 8486 | len2 = sizeof (ELF_STRING_ia64_unwind_info_once) - 1; |
84714f86 | 8487 | suffix = section_name (filedata, unwsec) + len; |
b9e920ec AM |
8488 | for (i = 0, sec = filedata->section_headers; |
8489 | i < filedata->file_header.e_shnum; | |
579f31ac | 8490 | ++i, ++sec) |
84714f86 AM |
8491 | if (section_name_valid (filedata, sec) |
8492 | && startswith (section_name (filedata, sec), | |
e9b095a5 | 8493 | ELF_STRING_ia64_unwind_info_once) |
84714f86 | 8494 | && streq (section_name (filedata, sec) + len2, suffix)) |
579f31ac JJ |
8495 | break; |
8496 | } | |
8497 | else | |
8498 | { | |
8499 | /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO | |
18bd398b | 8500 | .IA_64.unwind or BAR -> .IA_64.unwind_info. */ |
579f31ac JJ |
8501 | len = sizeof (ELF_STRING_ia64_unwind) - 1; |
8502 | len2 = sizeof (ELF_STRING_ia64_unwind_info) - 1; | |
8503 | suffix = ""; | |
84714f86 AM |
8504 | if (section_name_valid (filedata, unwsec) |
8505 | && startswith (section_name (filedata, unwsec), | |
8506 | ELF_STRING_ia64_unwind)) | |
8507 | suffix = section_name (filedata, unwsec) + len; | |
b9e920ec AM |
8508 | for (i = 0, sec = filedata->section_headers; |
8509 | i < filedata->file_header.e_shnum; | |
579f31ac | 8510 | ++i, ++sec) |
84714f86 AM |
8511 | if (section_name_valid (filedata, sec) |
8512 | && startswith (section_name (filedata, sec), | |
8513 | ELF_STRING_ia64_unwind_info) | |
8514 | && streq (section_name (filedata, sec) + len2, suffix)) | |
579f31ac JJ |
8515 | break; |
8516 | } | |
8517 | ||
dda8d76d | 8518 | if (i == filedata->file_header.e_shnum) |
579f31ac JJ |
8519 | { |
8520 | printf (_("\nCould not find unwind info section for ")); | |
8521 | ||
dda8d76d | 8522 | if (filedata->string_table == NULL) |
579f31ac JJ |
8523 | printf ("%d", unwsec->sh_name); |
8524 | else | |
dda8d76d | 8525 | printf ("'%s'", printable_section_name (filedata, unwsec)); |
579f31ac JJ |
8526 | } |
8527 | else | |
4d6ed7c8 | 8528 | { |
4d6ed7c8 | 8529 | aux.info_addr = sec->sh_addr; |
dda8d76d | 8530 | aux.info = (unsigned char *) get_data (NULL, filedata, sec->sh_offset, 1, |
4082ef84 NC |
8531 | sec->sh_size, |
8532 | _("unwind info")); | |
59245841 | 8533 | aux.info_size = aux.info == NULL ? 0 : sec->sh_size; |
4d6ed7c8 | 8534 | |
579f31ac | 8535 | printf (_("\nUnwind section ")); |
4d6ed7c8 | 8536 | |
dda8d76d | 8537 | if (filedata->string_table == NULL) |
579f31ac JJ |
8538 | printf ("%d", unwsec->sh_name); |
8539 | else | |
dda8d76d | 8540 | printf ("'%s'", printable_section_name (filedata, unwsec)); |
4d6ed7c8 | 8541 | |
579f31ac | 8542 | printf (_(" at offset 0x%lx contains %lu entries:\n"), |
e59b4dfb | 8543 | (unsigned long) unwsec->sh_offset, |
89fac5e3 | 8544 | (unsigned long) (unwsec->sh_size / (3 * eh_addr_size))); |
4d6ed7c8 | 8545 | |
dda8d76d | 8546 | if (slurp_ia64_unwind_table (filedata, & aux, unwsec) |
53774b7e | 8547 | && aux.table_len > 0) |
dda8d76d | 8548 | dump_ia64_unwind (filedata, & aux); |
579f31ac | 8549 | |
9db70fc3 AM |
8550 | free ((char *) aux.table); |
8551 | free ((char *) aux.info); | |
579f31ac JJ |
8552 | aux.table = NULL; |
8553 | aux.info = NULL; | |
8554 | } | |
4d6ed7c8 | 8555 | } |
4d6ed7c8 | 8556 | |
9db70fc3 AM |
8557 | free (aux.symtab); |
8558 | free ((char *) aux.strtab); | |
32ec8896 NC |
8559 | |
8560 | return res; | |
4d6ed7c8 NC |
8561 | } |
8562 | ||
3f5e193b | 8563 | struct hppa_unw_table_entry |
32ec8896 NC |
8564 | { |
8565 | struct absaddr start; | |
8566 | struct absaddr end; | |
8567 | unsigned int Cannot_unwind:1; /* 0 */ | |
8568 | unsigned int Millicode:1; /* 1 */ | |
8569 | unsigned int Millicode_save_sr0:1; /* 2 */ | |
8570 | unsigned int Region_description:2; /* 3..4 */ | |
8571 | unsigned int reserved1:1; /* 5 */ | |
8572 | unsigned int Entry_SR:1; /* 6 */ | |
8573 | unsigned int Entry_FR:4; /* Number saved 7..10 */ | |
8574 | unsigned int Entry_GR:5; /* Number saved 11..15 */ | |
8575 | unsigned int Args_stored:1; /* 16 */ | |
8576 | unsigned int Variable_Frame:1; /* 17 */ | |
8577 | unsigned int Separate_Package_Body:1; /* 18 */ | |
8578 | unsigned int Frame_Extension_Millicode:1; /* 19 */ | |
8579 | unsigned int Stack_Overflow_Check:1; /* 20 */ | |
8580 | unsigned int Two_Instruction_SP_Increment:1; /* 21 */ | |
8581 | unsigned int Ada_Region:1; /* 22 */ | |
8582 | unsigned int cxx_info:1; /* 23 */ | |
8583 | unsigned int cxx_try_catch:1; /* 24 */ | |
8584 | unsigned int sched_entry_seq:1; /* 25 */ | |
8585 | unsigned int reserved2:1; /* 26 */ | |
8586 | unsigned int Save_SP:1; /* 27 */ | |
8587 | unsigned int Save_RP:1; /* 28 */ | |
8588 | unsigned int Save_MRP_in_frame:1; /* 29 */ | |
8589 | unsigned int extn_ptr_defined:1; /* 30 */ | |
8590 | unsigned int Cleanup_defined:1; /* 31 */ | |
8591 | ||
8592 | unsigned int MPE_XL_interrupt_marker:1; /* 0 */ | |
8593 | unsigned int HP_UX_interrupt_marker:1; /* 1 */ | |
8594 | unsigned int Large_frame:1; /* 2 */ | |
8595 | unsigned int Pseudo_SP_Set:1; /* 3 */ | |
8596 | unsigned int reserved4:1; /* 4 */ | |
8597 | unsigned int Total_frame_size:27; /* 5..31 */ | |
8598 | }; | |
3f5e193b | 8599 | |
57346661 | 8600 | struct hppa_unw_aux_info |
948f632f | 8601 | { |
32ec8896 NC |
8602 | struct hppa_unw_table_entry * table; /* Unwind table. */ |
8603 | unsigned long table_len; /* Length of unwind table. */ | |
8604 | bfd_vma seg_base; /* Starting address of segment. */ | |
8605 | Elf_Internal_Sym * symtab; /* The symbol table. */ | |
8606 | unsigned long nsyms; /* Number of symbols. */ | |
8607 | Elf_Internal_Sym * funtab; /* Sorted table of STT_FUNC symbols. */ | |
8608 | unsigned long nfuns; /* Number of entries in funtab. */ | |
8609 | char * strtab; /* The string table. */ | |
8610 | unsigned long strtab_size; /* Size of string table. */ | |
948f632f | 8611 | }; |
57346661 | 8612 | |
015dc7e1 | 8613 | static bool |
dda8d76d | 8614 | dump_hppa_unwind (Filedata * filedata, struct hppa_unw_aux_info * aux) |
57346661 | 8615 | { |
2cf0635d | 8616 | struct hppa_unw_table_entry * tp; |
948f632f | 8617 | unsigned long j, nfuns; |
015dc7e1 | 8618 | bool res = true; |
948f632f DA |
8619 | |
8620 | aux->funtab = xmalloc (aux->nsyms * sizeof (Elf_Internal_Sym)); | |
8621 | for (nfuns = 0, j = 0; j < aux->nsyms; j++) | |
8622 | if (aux->symtab[j].st_value && ELF_ST_TYPE (aux->symtab[j].st_info) == STT_FUNC) | |
8623 | aux->funtab[nfuns++] = aux->symtab[j]; | |
8624 | aux->nfuns = nfuns; | |
8625 | qsort (aux->funtab, aux->nfuns, sizeof (Elf_Internal_Sym), symcmp); | |
57346661 | 8626 | |
57346661 AM |
8627 | for (tp = aux->table; tp < aux->table + aux->table_len; ++tp) |
8628 | { | |
8629 | bfd_vma offset; | |
2cf0635d | 8630 | const char * procname; |
57346661 | 8631 | |
dda8d76d | 8632 | find_symbol_for_address (filedata, aux->funtab, aux->nfuns, aux->strtab, |
57346661 AM |
8633 | aux->strtab_size, tp->start, &procname, |
8634 | &offset); | |
8635 | ||
8636 | fputs ("\n<", stdout); | |
8637 | ||
8638 | if (procname) | |
8639 | { | |
8640 | fputs (procname, stdout); | |
8641 | ||
8642 | if (offset) | |
8643 | printf ("+%lx", (unsigned long) offset); | |
8644 | } | |
8645 | ||
8646 | fputs (">: [", stdout); | |
8647 | print_vma (tp->start.offset, PREFIX_HEX); | |
8648 | fputc ('-', stdout); | |
8649 | print_vma (tp->end.offset, PREFIX_HEX); | |
8650 | printf ("]\n\t"); | |
8651 | ||
18bd398b NC |
8652 | #define PF(_m) if (tp->_m) printf (#_m " "); |
8653 | #define PV(_m) if (tp->_m) printf (#_m "=%d ", tp->_m); | |
57346661 AM |
8654 | PF(Cannot_unwind); |
8655 | PF(Millicode); | |
8656 | PF(Millicode_save_sr0); | |
18bd398b | 8657 | /* PV(Region_description); */ |
57346661 AM |
8658 | PF(Entry_SR); |
8659 | PV(Entry_FR); | |
8660 | PV(Entry_GR); | |
8661 | PF(Args_stored); | |
8662 | PF(Variable_Frame); | |
8663 | PF(Separate_Package_Body); | |
8664 | PF(Frame_Extension_Millicode); | |
8665 | PF(Stack_Overflow_Check); | |
8666 | PF(Two_Instruction_SP_Increment); | |
8667 | PF(Ada_Region); | |
8668 | PF(cxx_info); | |
8669 | PF(cxx_try_catch); | |
8670 | PF(sched_entry_seq); | |
8671 | PF(Save_SP); | |
8672 | PF(Save_RP); | |
8673 | PF(Save_MRP_in_frame); | |
8674 | PF(extn_ptr_defined); | |
8675 | PF(Cleanup_defined); | |
8676 | PF(MPE_XL_interrupt_marker); | |
8677 | PF(HP_UX_interrupt_marker); | |
8678 | PF(Large_frame); | |
8679 | PF(Pseudo_SP_Set); | |
8680 | PV(Total_frame_size); | |
8681 | #undef PF | |
8682 | #undef PV | |
8683 | } | |
8684 | ||
18bd398b | 8685 | printf ("\n"); |
948f632f DA |
8686 | |
8687 | free (aux->funtab); | |
32ec8896 NC |
8688 | |
8689 | return res; | |
57346661 AM |
8690 | } |
8691 | ||
015dc7e1 | 8692 | static bool |
dda8d76d NC |
8693 | slurp_hppa_unwind_table (Filedata * filedata, |
8694 | struct hppa_unw_aux_info * aux, | |
8695 | Elf_Internal_Shdr * sec) | |
57346661 | 8696 | { |
1c0751b2 | 8697 | unsigned long size, unw_ent_size, nentries, nrelas, i; |
2cf0635d NC |
8698 | Elf_Internal_Phdr * seg; |
8699 | struct hppa_unw_table_entry * tep; | |
8700 | Elf_Internal_Shdr * relsec; | |
8701 | Elf_Internal_Rela * rela; | |
8702 | Elf_Internal_Rela * rp; | |
8703 | unsigned char * table; | |
8704 | unsigned char * tp; | |
8705 | Elf_Internal_Sym * sym; | |
8706 | const char * relname; | |
57346661 | 8707 | |
57346661 AM |
8708 | /* First, find the starting address of the segment that includes |
8709 | this section. */ | |
dda8d76d | 8710 | if (filedata->file_header.e_phnum) |
57346661 | 8711 | { |
dda8d76d | 8712 | if (! get_program_headers (filedata)) |
015dc7e1 | 8713 | return false; |
57346661 | 8714 | |
dda8d76d NC |
8715 | for (seg = filedata->program_headers; |
8716 | seg < filedata->program_headers + filedata->file_header.e_phnum; | |
57346661 AM |
8717 | ++seg) |
8718 | { | |
8719 | if (seg->p_type != PT_LOAD) | |
8720 | continue; | |
8721 | ||
8722 | if (sec->sh_addr >= seg->p_vaddr | |
8723 | && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz)) | |
8724 | { | |
8725 | aux->seg_base = seg->p_vaddr; | |
8726 | break; | |
8727 | } | |
8728 | } | |
8729 | } | |
8730 | ||
8731 | /* Second, build the unwind table from the contents of the unwind | |
8732 | section. */ | |
8733 | size = sec->sh_size; | |
dda8d76d | 8734 | table = (unsigned char *) get_data (NULL, filedata, sec->sh_offset, 1, size, |
3f5e193b | 8735 | _("unwind table")); |
57346661 | 8736 | if (!table) |
015dc7e1 | 8737 | return false; |
57346661 | 8738 | |
1c0751b2 DA |
8739 | unw_ent_size = 16; |
8740 | nentries = size / unw_ent_size; | |
8741 | size = unw_ent_size * nentries; | |
57346661 | 8742 | |
e3fdc001 | 8743 | aux->table_len = nentries; |
3f5e193b NC |
8744 | tep = aux->table = (struct hppa_unw_table_entry *) |
8745 | xcmalloc (nentries, sizeof (aux->table[0])); | |
57346661 | 8746 | |
1c0751b2 | 8747 | for (tp = table; tp < table + size; tp += unw_ent_size, ++tep) |
57346661 AM |
8748 | { |
8749 | unsigned int tmp1, tmp2; | |
8750 | ||
8751 | tep->start.section = SHN_UNDEF; | |
8752 | tep->end.section = SHN_UNDEF; | |
8753 | ||
1c0751b2 DA |
8754 | tep->start.offset = byte_get ((unsigned char *) tp + 0, 4); |
8755 | tep->end.offset = byte_get ((unsigned char *) tp + 4, 4); | |
8756 | tmp1 = byte_get ((unsigned char *) tp + 8, 4); | |
8757 | tmp2 = byte_get ((unsigned char *) tp + 12, 4); | |
8758 | ||
8759 | tep->start.offset += aux->seg_base; | |
8760 | tep->end.offset += aux->seg_base; | |
57346661 AM |
8761 | |
8762 | tep->Cannot_unwind = (tmp1 >> 31) & 0x1; | |
8763 | tep->Millicode = (tmp1 >> 30) & 0x1; | |
8764 | tep->Millicode_save_sr0 = (tmp1 >> 29) & 0x1; | |
8765 | tep->Region_description = (tmp1 >> 27) & 0x3; | |
8766 | tep->reserved1 = (tmp1 >> 26) & 0x1; | |
8767 | tep->Entry_SR = (tmp1 >> 25) & 0x1; | |
8768 | tep->Entry_FR = (tmp1 >> 21) & 0xf; | |
8769 | tep->Entry_GR = (tmp1 >> 16) & 0x1f; | |
8770 | tep->Args_stored = (tmp1 >> 15) & 0x1; | |
8771 | tep->Variable_Frame = (tmp1 >> 14) & 0x1; | |
8772 | tep->Separate_Package_Body = (tmp1 >> 13) & 0x1; | |
8773 | tep->Frame_Extension_Millicode = (tmp1 >> 12) & 0x1; | |
8774 | tep->Stack_Overflow_Check = (tmp1 >> 11) & 0x1; | |
8775 | tep->Two_Instruction_SP_Increment = (tmp1 >> 10) & 0x1; | |
8776 | tep->Ada_Region = (tmp1 >> 9) & 0x1; | |
8777 | tep->cxx_info = (tmp1 >> 8) & 0x1; | |
8778 | tep->cxx_try_catch = (tmp1 >> 7) & 0x1; | |
8779 | tep->sched_entry_seq = (tmp1 >> 6) & 0x1; | |
8780 | tep->reserved2 = (tmp1 >> 5) & 0x1; | |
8781 | tep->Save_SP = (tmp1 >> 4) & 0x1; | |
8782 | tep->Save_RP = (tmp1 >> 3) & 0x1; | |
8783 | tep->Save_MRP_in_frame = (tmp1 >> 2) & 0x1; | |
8784 | tep->extn_ptr_defined = (tmp1 >> 1) & 0x1; | |
8785 | tep->Cleanup_defined = tmp1 & 0x1; | |
8786 | ||
8787 | tep->MPE_XL_interrupt_marker = (tmp2 >> 31) & 0x1; | |
8788 | tep->HP_UX_interrupt_marker = (tmp2 >> 30) & 0x1; | |
8789 | tep->Large_frame = (tmp2 >> 29) & 0x1; | |
8790 | tep->Pseudo_SP_Set = (tmp2 >> 28) & 0x1; | |
8791 | tep->reserved4 = (tmp2 >> 27) & 0x1; | |
8792 | tep->Total_frame_size = tmp2 & 0x7ffffff; | |
57346661 AM |
8793 | } |
8794 | free (table); | |
8795 | ||
8796 | /* Third, apply any relocations to the unwind table. */ | |
dda8d76d NC |
8797 | for (relsec = filedata->section_headers; |
8798 | relsec < filedata->section_headers + filedata->file_header.e_shnum; | |
57346661 AM |
8799 | ++relsec) |
8800 | { | |
8801 | if (relsec->sh_type != SHT_RELA | |
dda8d76d NC |
8802 | || relsec->sh_info >= filedata->file_header.e_shnum |
8803 | || filedata->section_headers + relsec->sh_info != sec) | |
57346661 AM |
8804 | continue; |
8805 | ||
dda8d76d | 8806 | if (!slurp_rela_relocs (filedata, relsec->sh_offset, relsec->sh_size, |
57346661 | 8807 | & rela, & nrelas)) |
015dc7e1 | 8808 | return false; |
57346661 AM |
8809 | |
8810 | for (rp = rela; rp < rela + nrelas; ++rp) | |
8811 | { | |
4770fb94 | 8812 | unsigned int sym_ndx; |
726bd37d AM |
8813 | unsigned int r_type = get_reloc_type (filedata, rp->r_info); |
8814 | relname = elf_hppa_reloc_type (r_type); | |
57346661 | 8815 | |
726bd37d AM |
8816 | if (relname == NULL) |
8817 | { | |
8818 | warn (_("Skipping unknown relocation type: %u\n"), r_type); | |
8819 | continue; | |
8820 | } | |
8821 | ||
57346661 | 8822 | /* R_PARISC_SEGREL32 or R_PARISC_SEGREL64. */ |
24d127aa | 8823 | if (! startswith (relname, "R_PARISC_SEGREL")) |
57346661 | 8824 | { |
726bd37d | 8825 | warn (_("Skipping unexpected relocation type: %s\n"), relname); |
57346661 AM |
8826 | continue; |
8827 | } | |
8828 | ||
8829 | i = rp->r_offset / unw_ent_size; | |
726bd37d AM |
8830 | if (i >= aux->table_len) |
8831 | { | |
8832 | warn (_("Skipping reloc with overlarge offset: %lx\n"), i); | |
8833 | continue; | |
8834 | } | |
57346661 | 8835 | |
4770fb94 AM |
8836 | sym_ndx = get_reloc_symindex (rp->r_info); |
8837 | if (sym_ndx >= aux->nsyms) | |
8838 | { | |
8839 | warn (_("Skipping reloc with invalid symbol index: %u\n"), | |
8840 | sym_ndx); | |
8841 | continue; | |
8842 | } | |
8843 | sym = aux->symtab + sym_ndx; | |
8844 | ||
43f6cd05 | 8845 | switch ((rp->r_offset % unw_ent_size) / 4) |
57346661 AM |
8846 | { |
8847 | case 0: | |
8848 | aux->table[i].start.section = sym->st_shndx; | |
1e456d54 | 8849 | aux->table[i].start.offset = sym->st_value + rp->r_addend; |
57346661 AM |
8850 | break; |
8851 | case 1: | |
8852 | aux->table[i].end.section = sym->st_shndx; | |
1e456d54 | 8853 | aux->table[i].end.offset = sym->st_value + rp->r_addend; |
57346661 AM |
8854 | break; |
8855 | default: | |
8856 | break; | |
8857 | } | |
8858 | } | |
8859 | ||
8860 | free (rela); | |
8861 | } | |
8862 | ||
015dc7e1 | 8863 | return true; |
57346661 AM |
8864 | } |
8865 | ||
015dc7e1 | 8866 | static bool |
dda8d76d | 8867 | hppa_process_unwind (Filedata * filedata) |
57346661 | 8868 | { |
57346661 | 8869 | struct hppa_unw_aux_info aux; |
2cf0635d | 8870 | Elf_Internal_Shdr * unwsec = NULL; |
2cf0635d | 8871 | Elf_Internal_Shdr * sec; |
18bd398b | 8872 | unsigned long i; |
015dc7e1 | 8873 | bool res = true; |
57346661 | 8874 | |
dda8d76d | 8875 | if (filedata->string_table == NULL) |
015dc7e1 | 8876 | return false; |
1b31d05e NC |
8877 | |
8878 | memset (& aux, 0, sizeof (aux)); | |
57346661 | 8879 | |
dda8d76d | 8880 | for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec) |
57346661 | 8881 | { |
28d13567 | 8882 | if (sec->sh_type == SHT_SYMTAB) |
57346661 | 8883 | { |
28d13567 | 8884 | if (aux.symtab) |
4082ef84 | 8885 | { |
28d13567 AM |
8886 | error (_("Multiple symbol tables encountered\n")); |
8887 | free (aux.symtab); | |
8888 | aux.symtab = NULL; | |
4082ef84 | 8889 | free (aux.strtab); |
28d13567 | 8890 | aux.strtab = NULL; |
4082ef84 | 8891 | } |
28d13567 AM |
8892 | if (!get_symtab (filedata, sec, &aux.symtab, &aux.nsyms, |
8893 | &aux.strtab, &aux.strtab_size)) | |
015dc7e1 | 8894 | return false; |
57346661 | 8895 | } |
84714f86 AM |
8896 | else if (section_name_valid (filedata, sec) |
8897 | && streq (section_name (filedata, sec), ".PARISC.unwind")) | |
57346661 AM |
8898 | unwsec = sec; |
8899 | } | |
8900 | ||
8901 | if (!unwsec) | |
8902 | printf (_("\nThere are no unwind sections in this file.\n")); | |
8903 | ||
dda8d76d | 8904 | for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec) |
57346661 | 8905 | { |
84714f86 AM |
8906 | if (section_name_valid (filedata, sec) |
8907 | && streq (section_name (filedata, sec), ".PARISC.unwind")) | |
57346661 | 8908 | { |
43f6cd05 | 8909 | unsigned long num_unwind = sec->sh_size / 16; |
dda8d76d | 8910 | |
d3a49aa8 AM |
8911 | printf (ngettext ("\nUnwind section '%s' at offset 0x%lx " |
8912 | "contains %lu entry:\n", | |
8913 | "\nUnwind section '%s' at offset 0x%lx " | |
8914 | "contains %lu entries:\n", | |
8915 | num_unwind), | |
dda8d76d | 8916 | printable_section_name (filedata, sec), |
57346661 | 8917 | (unsigned long) sec->sh_offset, |
d3a49aa8 | 8918 | num_unwind); |
57346661 | 8919 | |
dda8d76d | 8920 | if (! slurp_hppa_unwind_table (filedata, &aux, sec)) |
015dc7e1 | 8921 | res = false; |
66b09c7e S |
8922 | |
8923 | if (res && aux.table_len > 0) | |
32ec8896 | 8924 | { |
dda8d76d | 8925 | if (! dump_hppa_unwind (filedata, &aux)) |
015dc7e1 | 8926 | res = false; |
32ec8896 | 8927 | } |
57346661 | 8928 | |
9db70fc3 | 8929 | free ((char *) aux.table); |
57346661 AM |
8930 | aux.table = NULL; |
8931 | } | |
8932 | } | |
8933 | ||
9db70fc3 AM |
8934 | free (aux.symtab); |
8935 | free ((char *) aux.strtab); | |
32ec8896 NC |
8936 | |
8937 | return res; | |
57346661 AM |
8938 | } |
8939 | ||
0b6ae522 DJ |
8940 | struct arm_section |
8941 | { | |
a734115a NC |
8942 | unsigned char * data; /* The unwind data. */ |
8943 | Elf_Internal_Shdr * sec; /* The cached unwind section header. */ | |
8944 | Elf_Internal_Rela * rela; /* The cached relocations for this section. */ | |
8945 | unsigned long nrelas; /* The number of relocations. */ | |
8946 | unsigned int rel_type; /* REL or RELA ? */ | |
8947 | Elf_Internal_Rela * next_rela; /* Cyclic pointer to the next reloc to process. */ | |
0b6ae522 DJ |
8948 | }; |
8949 | ||
8950 | struct arm_unw_aux_info | |
8951 | { | |
dda8d76d | 8952 | Filedata * filedata; /* The file containing the unwind sections. */ |
a734115a NC |
8953 | Elf_Internal_Sym * symtab; /* The file's symbol table. */ |
8954 | unsigned long nsyms; /* Number of symbols. */ | |
948f632f DA |
8955 | Elf_Internal_Sym * funtab; /* Sorted table of STT_FUNC symbols. */ |
8956 | unsigned long nfuns; /* Number of these symbols. */ | |
a734115a NC |
8957 | char * strtab; /* The file's string table. */ |
8958 | unsigned long strtab_size; /* Size of string table. */ | |
0b6ae522 DJ |
8959 | }; |
8960 | ||
8961 | static const char * | |
dda8d76d NC |
8962 | arm_print_vma_and_name (Filedata * filedata, |
8963 | struct arm_unw_aux_info * aux, | |
8964 | bfd_vma fn, | |
8965 | struct absaddr addr) | |
0b6ae522 DJ |
8966 | { |
8967 | const char *procname; | |
8968 | bfd_vma sym_offset; | |
8969 | ||
8970 | if (addr.section == SHN_UNDEF) | |
8971 | addr.offset = fn; | |
8972 | ||
dda8d76d | 8973 | find_symbol_for_address (filedata, aux->funtab, aux->nfuns, aux->strtab, |
0b6ae522 DJ |
8974 | aux->strtab_size, addr, &procname, |
8975 | &sym_offset); | |
8976 | ||
8977 | print_vma (fn, PREFIX_HEX); | |
8978 | ||
8979 | if (procname) | |
8980 | { | |
8981 | fputs (" <", stdout); | |
8982 | fputs (procname, stdout); | |
8983 | ||
8984 | if (sym_offset) | |
8985 | printf ("+0x%lx", (unsigned long) sym_offset); | |
8986 | fputc ('>', stdout); | |
8987 | } | |
8988 | ||
8989 | return procname; | |
8990 | } | |
8991 | ||
8992 | static void | |
8993 | arm_free_section (struct arm_section *arm_sec) | |
8994 | { | |
9db70fc3 AM |
8995 | free (arm_sec->data); |
8996 | free (arm_sec->rela); | |
0b6ae522 DJ |
8997 | } |
8998 | ||
a734115a NC |
8999 | /* 1) If SEC does not match the one cached in ARM_SEC, then free the current |
9000 | cached section and install SEC instead. | |
9001 | 2) Locate the 32-bit word at WORD_OFFSET in unwind section SEC | |
9002 | and return its valued in * WORDP, relocating if necessary. | |
1b31d05e | 9003 | 3) Update the NEXT_RELA field in ARM_SEC and store the section index and |
a734115a | 9004 | relocation's offset in ADDR. |
1b31d05e NC |
9005 | 4) If SYM_NAME is non-NULL and a relocation was applied, record the offset |
9006 | into the string table of the symbol associated with the reloc. If no | |
9007 | reloc was applied store -1 there. | |
9008 | 5) Return TRUE upon success, FALSE otherwise. */ | |
a734115a | 9009 | |
015dc7e1 | 9010 | static bool |
dda8d76d NC |
9011 | get_unwind_section_word (Filedata * filedata, |
9012 | struct arm_unw_aux_info * aux, | |
1b31d05e NC |
9013 | struct arm_section * arm_sec, |
9014 | Elf_Internal_Shdr * sec, | |
9015 | bfd_vma word_offset, | |
9016 | unsigned int * wordp, | |
9017 | struct absaddr * addr, | |
9018 | bfd_vma * sym_name) | |
0b6ae522 DJ |
9019 | { |
9020 | Elf_Internal_Rela *rp; | |
9021 | Elf_Internal_Sym *sym; | |
9022 | const char * relname; | |
9023 | unsigned int word; | |
015dc7e1 | 9024 | bool wrapped; |
0b6ae522 | 9025 | |
e0a31db1 | 9026 | if (sec == NULL || arm_sec == NULL) |
015dc7e1 | 9027 | return false; |
e0a31db1 | 9028 | |
0b6ae522 DJ |
9029 | addr->section = SHN_UNDEF; |
9030 | addr->offset = 0; | |
9031 | ||
1b31d05e NC |
9032 | if (sym_name != NULL) |
9033 | *sym_name = (bfd_vma) -1; | |
9034 | ||
a734115a | 9035 | /* If necessary, update the section cache. */ |
0b6ae522 DJ |
9036 | if (sec != arm_sec->sec) |
9037 | { | |
9038 | Elf_Internal_Shdr *relsec; | |
9039 | ||
9040 | arm_free_section (arm_sec); | |
9041 | ||
9042 | arm_sec->sec = sec; | |
dda8d76d | 9043 | arm_sec->data = get_data (NULL, aux->filedata, sec->sh_offset, 1, |
0b6ae522 | 9044 | sec->sh_size, _("unwind data")); |
0b6ae522 DJ |
9045 | arm_sec->rela = NULL; |
9046 | arm_sec->nrelas = 0; | |
9047 | ||
dda8d76d NC |
9048 | for (relsec = filedata->section_headers; |
9049 | relsec < filedata->section_headers + filedata->file_header.e_shnum; | |
0b6ae522 DJ |
9050 | ++relsec) |
9051 | { | |
dda8d76d NC |
9052 | if (relsec->sh_info >= filedata->file_header.e_shnum |
9053 | || filedata->section_headers + relsec->sh_info != sec | |
1ae40aa4 NC |
9054 | /* PR 15745: Check the section type as well. */ |
9055 | || (relsec->sh_type != SHT_REL | |
9056 | && relsec->sh_type != SHT_RELA)) | |
0b6ae522 DJ |
9057 | continue; |
9058 | ||
a734115a | 9059 | arm_sec->rel_type = relsec->sh_type; |
0b6ae522 DJ |
9060 | if (relsec->sh_type == SHT_REL) |
9061 | { | |
dda8d76d | 9062 | if (!slurp_rel_relocs (aux->filedata, relsec->sh_offset, |
0b6ae522 DJ |
9063 | relsec->sh_size, |
9064 | & arm_sec->rela, & arm_sec->nrelas)) | |
015dc7e1 | 9065 | return false; |
0b6ae522 | 9066 | } |
1ae40aa4 | 9067 | else /* relsec->sh_type == SHT_RELA */ |
0b6ae522 | 9068 | { |
dda8d76d | 9069 | if (!slurp_rela_relocs (aux->filedata, relsec->sh_offset, |
0b6ae522 DJ |
9070 | relsec->sh_size, |
9071 | & arm_sec->rela, & arm_sec->nrelas)) | |
015dc7e1 | 9072 | return false; |
0b6ae522 | 9073 | } |
1ae40aa4 | 9074 | break; |
0b6ae522 DJ |
9075 | } |
9076 | ||
9077 | arm_sec->next_rela = arm_sec->rela; | |
9078 | } | |
9079 | ||
a734115a | 9080 | /* If there is no unwind data we can do nothing. */ |
0b6ae522 | 9081 | if (arm_sec->data == NULL) |
015dc7e1 | 9082 | return false; |
0b6ae522 | 9083 | |
e0a31db1 | 9084 | /* If the offset is invalid then fail. */ |
f32ba729 NC |
9085 | if (/* PR 21343 *//* PR 18879 */ |
9086 | sec->sh_size < 4 | |
9087 | || word_offset > (sec->sh_size - 4) | |
1a915552 | 9088 | || ((bfd_signed_vma) word_offset) < 0) |
015dc7e1 | 9089 | return false; |
e0a31db1 | 9090 | |
a734115a | 9091 | /* Get the word at the required offset. */ |
0b6ae522 DJ |
9092 | word = byte_get (arm_sec->data + word_offset, 4); |
9093 | ||
0eff7165 NC |
9094 | /* PR 17531: file: id:000001,src:001266+003044,op:splice,rep:128. */ |
9095 | if (arm_sec->rela == NULL) | |
9096 | { | |
9097 | * wordp = word; | |
015dc7e1 | 9098 | return true; |
0eff7165 NC |
9099 | } |
9100 | ||
a734115a | 9101 | /* Look through the relocs to find the one that applies to the provided offset. */ |
015dc7e1 | 9102 | wrapped = false; |
0b6ae522 DJ |
9103 | for (rp = arm_sec->next_rela; rp != arm_sec->rela + arm_sec->nrelas; rp++) |
9104 | { | |
9105 | bfd_vma prelval, offset; | |
9106 | ||
9107 | if (rp->r_offset > word_offset && !wrapped) | |
9108 | { | |
9109 | rp = arm_sec->rela; | |
015dc7e1 | 9110 | wrapped = true; |
0b6ae522 DJ |
9111 | } |
9112 | if (rp->r_offset > word_offset) | |
9113 | break; | |
9114 | ||
9115 | if (rp->r_offset & 3) | |
9116 | { | |
9117 | warn (_("Skipping unexpected relocation at offset 0x%lx\n"), | |
9118 | (unsigned long) rp->r_offset); | |
9119 | continue; | |
9120 | } | |
9121 | ||
9122 | if (rp->r_offset < word_offset) | |
9123 | continue; | |
9124 | ||
74e1a04b NC |
9125 | /* PR 17531: file: 027-161405-0.004 */ |
9126 | if (aux->symtab == NULL) | |
9127 | continue; | |
9128 | ||
0b6ae522 DJ |
9129 | if (arm_sec->rel_type == SHT_REL) |
9130 | { | |
9131 | offset = word & 0x7fffffff; | |
9132 | if (offset & 0x40000000) | |
9133 | offset |= ~ (bfd_vma) 0x7fffffff; | |
9134 | } | |
a734115a | 9135 | else if (arm_sec->rel_type == SHT_RELA) |
0b6ae522 | 9136 | offset = rp->r_addend; |
a734115a | 9137 | else |
74e1a04b NC |
9138 | { |
9139 | error (_("Unknown section relocation type %d encountered\n"), | |
9140 | arm_sec->rel_type); | |
9141 | break; | |
9142 | } | |
0b6ae522 | 9143 | |
071436c6 NC |
9144 | /* PR 17531 file: 027-1241568-0.004. */ |
9145 | if (ELF32_R_SYM (rp->r_info) >= aux->nsyms) | |
9146 | { | |
9147 | error (_("Bad symbol index in unwind relocation (%lu > %lu)\n"), | |
9148 | (unsigned long) ELF32_R_SYM (rp->r_info), aux->nsyms); | |
9149 | break; | |
9150 | } | |
9151 | ||
9152 | sym = aux->symtab + ELF32_R_SYM (rp->r_info); | |
0b6ae522 DJ |
9153 | offset += sym->st_value; |
9154 | prelval = offset - (arm_sec->sec->sh_addr + rp->r_offset); | |
9155 | ||
a734115a | 9156 | /* Check that we are processing the expected reloc type. */ |
dda8d76d | 9157 | if (filedata->file_header.e_machine == EM_ARM) |
a734115a NC |
9158 | { |
9159 | relname = elf_arm_reloc_type (ELF32_R_TYPE (rp->r_info)); | |
071436c6 NC |
9160 | if (relname == NULL) |
9161 | { | |
9162 | warn (_("Skipping unknown ARM relocation type: %d\n"), | |
9163 | (int) ELF32_R_TYPE (rp->r_info)); | |
9164 | continue; | |
9165 | } | |
a734115a NC |
9166 | |
9167 | if (streq (relname, "R_ARM_NONE")) | |
9168 | continue; | |
0b4362b0 | 9169 | |
a734115a NC |
9170 | if (! streq (relname, "R_ARM_PREL31")) |
9171 | { | |
071436c6 | 9172 | warn (_("Skipping unexpected ARM relocation type %s\n"), relname); |
a734115a NC |
9173 | continue; |
9174 | } | |
9175 | } | |
dda8d76d | 9176 | else if (filedata->file_header.e_machine == EM_TI_C6000) |
a734115a NC |
9177 | { |
9178 | relname = elf_tic6x_reloc_type (ELF32_R_TYPE (rp->r_info)); | |
071436c6 NC |
9179 | if (relname == NULL) |
9180 | { | |
9181 | warn (_("Skipping unknown C6000 relocation type: %d\n"), | |
9182 | (int) ELF32_R_TYPE (rp->r_info)); | |
9183 | continue; | |
9184 | } | |
0b4362b0 | 9185 | |
a734115a NC |
9186 | if (streq (relname, "R_C6000_NONE")) |
9187 | continue; | |
9188 | ||
9189 | if (! streq (relname, "R_C6000_PREL31")) | |
9190 | { | |
071436c6 | 9191 | warn (_("Skipping unexpected C6000 relocation type %s\n"), relname); |
a734115a NC |
9192 | continue; |
9193 | } | |
9194 | ||
9195 | prelval >>= 1; | |
9196 | } | |
9197 | else | |
74e1a04b NC |
9198 | { |
9199 | /* This function currently only supports ARM and TI unwinders. */ | |
9200 | warn (_("Only TI and ARM unwinders are currently supported\n")); | |
9201 | break; | |
9202 | } | |
fa197c1c | 9203 | |
0b6ae522 DJ |
9204 | word = (word & ~ (bfd_vma) 0x7fffffff) | (prelval & 0x7fffffff); |
9205 | addr->section = sym->st_shndx; | |
9206 | addr->offset = offset; | |
74e1a04b | 9207 | |
1b31d05e NC |
9208 | if (sym_name) |
9209 | * sym_name = sym->st_name; | |
0b6ae522 DJ |
9210 | break; |
9211 | } | |
9212 | ||
9213 | *wordp = word; | |
9214 | arm_sec->next_rela = rp; | |
9215 | ||
015dc7e1 | 9216 | return true; |
0b6ae522 DJ |
9217 | } |
9218 | ||
a734115a NC |
9219 | static const char *tic6x_unwind_regnames[16] = |
9220 | { | |
0b4362b0 RM |
9221 | "A15", "B15", "B14", "B13", "B12", "B11", "B10", "B3", |
9222 | "A14", "A13", "A12", "A11", "A10", | |
a734115a NC |
9223 | "[invalid reg 13]", "[invalid reg 14]", "[invalid reg 15]" |
9224 | }; | |
fa197c1c | 9225 | |
0b6ae522 | 9226 | static void |
fa197c1c | 9227 | decode_tic6x_unwind_regmask (unsigned int mask) |
0b6ae522 | 9228 | { |
fa197c1c PB |
9229 | int i; |
9230 | ||
9231 | for (i = 12; mask; mask >>= 1, i--) | |
9232 | { | |
9233 | if (mask & 1) | |
9234 | { | |
9235 | fputs (tic6x_unwind_regnames[i], stdout); | |
9236 | if (mask > 1) | |
9237 | fputs (", ", stdout); | |
9238 | } | |
9239 | } | |
9240 | } | |
0b6ae522 DJ |
9241 | |
9242 | #define ADVANCE \ | |
9243 | if (remaining == 0 && more_words) \ | |
9244 | { \ | |
9245 | data_offset += 4; \ | |
dda8d76d | 9246 | if (! get_unwind_section_word (filedata, aux, data_arm_sec, data_sec, \ |
1b31d05e | 9247 | data_offset, & word, & addr, NULL)) \ |
015dc7e1 | 9248 | return false; \ |
0b6ae522 DJ |
9249 | remaining = 4; \ |
9250 | more_words--; \ | |
9251 | } \ | |
9252 | ||
9253 | #define GET_OP(OP) \ | |
9254 | ADVANCE; \ | |
9255 | if (remaining) \ | |
9256 | { \ | |
9257 | remaining--; \ | |
9258 | (OP) = word >> 24; \ | |
9259 | word <<= 8; \ | |
9260 | } \ | |
9261 | else \ | |
9262 | { \ | |
2b692964 | 9263 | printf (_("[Truncated opcode]\n")); \ |
015dc7e1 | 9264 | return false; \ |
0b6ae522 | 9265 | } \ |
cc5914eb | 9266 | printf ("0x%02x ", OP) |
0b6ae522 | 9267 | |
015dc7e1 | 9268 | static bool |
dda8d76d NC |
9269 | decode_arm_unwind_bytecode (Filedata * filedata, |
9270 | struct arm_unw_aux_info * aux, | |
948f632f DA |
9271 | unsigned int word, |
9272 | unsigned int remaining, | |
9273 | unsigned int more_words, | |
9274 | bfd_vma data_offset, | |
9275 | Elf_Internal_Shdr * data_sec, | |
9276 | struct arm_section * data_arm_sec) | |
fa197c1c PB |
9277 | { |
9278 | struct absaddr addr; | |
015dc7e1 | 9279 | bool res = true; |
0b6ae522 DJ |
9280 | |
9281 | /* Decode the unwinding instructions. */ | |
9282 | while (1) | |
9283 | { | |
9284 | unsigned int op, op2; | |
9285 | ||
9286 | ADVANCE; | |
9287 | if (remaining == 0) | |
9288 | break; | |
9289 | remaining--; | |
9290 | op = word >> 24; | |
9291 | word <<= 8; | |
9292 | ||
cc5914eb | 9293 | printf (" 0x%02x ", op); |
0b6ae522 DJ |
9294 | |
9295 | if ((op & 0xc0) == 0x00) | |
9296 | { | |
9297 | int offset = ((op & 0x3f) << 2) + 4; | |
61865e30 | 9298 | |
cc5914eb | 9299 | printf (" vsp = vsp + %d", offset); |
0b6ae522 DJ |
9300 | } |
9301 | else if ((op & 0xc0) == 0x40) | |
9302 | { | |
9303 | int offset = ((op & 0x3f) << 2) + 4; | |
61865e30 | 9304 | |
cc5914eb | 9305 | printf (" vsp = vsp - %d", offset); |
0b6ae522 DJ |
9306 | } |
9307 | else if ((op & 0xf0) == 0x80) | |
9308 | { | |
9309 | GET_OP (op2); | |
9310 | if (op == 0x80 && op2 == 0) | |
9311 | printf (_("Refuse to unwind")); | |
9312 | else | |
9313 | { | |
9314 | unsigned int mask = ((op & 0x0f) << 8) | op2; | |
015dc7e1 | 9315 | bool first = true; |
0b6ae522 | 9316 | int i; |
2b692964 | 9317 | |
0b6ae522 DJ |
9318 | printf ("pop {"); |
9319 | for (i = 0; i < 12; i++) | |
9320 | if (mask & (1 << i)) | |
9321 | { | |
9322 | if (first) | |
015dc7e1 | 9323 | first = false; |
0b6ae522 DJ |
9324 | else |
9325 | printf (", "); | |
9326 | printf ("r%d", 4 + i); | |
9327 | } | |
9328 | printf ("}"); | |
9329 | } | |
9330 | } | |
9331 | else if ((op & 0xf0) == 0x90) | |
9332 | { | |
9333 | if (op == 0x9d || op == 0x9f) | |
9334 | printf (_(" [Reserved]")); | |
9335 | else | |
cc5914eb | 9336 | printf (" vsp = r%d", op & 0x0f); |
0b6ae522 DJ |
9337 | } |
9338 | else if ((op & 0xf0) == 0xa0) | |
9339 | { | |
9340 | int end = 4 + (op & 0x07); | |
015dc7e1 | 9341 | bool first = true; |
0b6ae522 | 9342 | int i; |
61865e30 | 9343 | |
0b6ae522 DJ |
9344 | printf (" pop {"); |
9345 | for (i = 4; i <= end; i++) | |
9346 | { | |
9347 | if (first) | |
015dc7e1 | 9348 | first = false; |
0b6ae522 DJ |
9349 | else |
9350 | printf (", "); | |
9351 | printf ("r%d", i); | |
9352 | } | |
9353 | if (op & 0x08) | |
9354 | { | |
1b31d05e | 9355 | if (!first) |
0b6ae522 DJ |
9356 | printf (", "); |
9357 | printf ("r14"); | |
9358 | } | |
9359 | printf ("}"); | |
9360 | } | |
9361 | else if (op == 0xb0) | |
9362 | printf (_(" finish")); | |
9363 | else if (op == 0xb1) | |
9364 | { | |
9365 | GET_OP (op2); | |
9366 | if (op2 == 0 || (op2 & 0xf0) != 0) | |
9367 | printf (_("[Spare]")); | |
9368 | else | |
9369 | { | |
9370 | unsigned int mask = op2 & 0x0f; | |
015dc7e1 | 9371 | bool first = true; |
0b6ae522 | 9372 | int i; |
61865e30 | 9373 | |
0b6ae522 DJ |
9374 | printf ("pop {"); |
9375 | for (i = 0; i < 12; i++) | |
9376 | if (mask & (1 << i)) | |
9377 | { | |
9378 | if (first) | |
015dc7e1 | 9379 | first = false; |
0b6ae522 DJ |
9380 | else |
9381 | printf (", "); | |
9382 | printf ("r%d", i); | |
9383 | } | |
9384 | printf ("}"); | |
9385 | } | |
9386 | } | |
9387 | else if (op == 0xb2) | |
9388 | { | |
b115cf96 | 9389 | unsigned char buf[9]; |
0b6ae522 DJ |
9390 | unsigned int i, len; |
9391 | unsigned long offset; | |
61865e30 | 9392 | |
b115cf96 | 9393 | for (i = 0; i < sizeof (buf); i++) |
0b6ae522 DJ |
9394 | { |
9395 | GET_OP (buf[i]); | |
9396 | if ((buf[i] & 0x80) == 0) | |
9397 | break; | |
9398 | } | |
4082ef84 | 9399 | if (i == sizeof (buf)) |
32ec8896 | 9400 | { |
27a45f42 | 9401 | error (_("corrupt change to vsp\n")); |
015dc7e1 | 9402 | res = false; |
32ec8896 | 9403 | } |
4082ef84 NC |
9404 | else |
9405 | { | |
015dc7e1 | 9406 | offset = read_leb128 (buf, buf + i + 1, false, &len, NULL); |
4082ef84 NC |
9407 | assert (len == i + 1); |
9408 | offset = offset * 4 + 0x204; | |
9409 | printf ("vsp = vsp + %ld", offset); | |
9410 | } | |
0b6ae522 | 9411 | } |
61865e30 | 9412 | else if (op == 0xb3 || op == 0xc8 || op == 0xc9) |
0b6ae522 | 9413 | { |
61865e30 NC |
9414 | unsigned int first, last; |
9415 | ||
9416 | GET_OP (op2); | |
9417 | first = op2 >> 4; | |
9418 | last = op2 & 0x0f; | |
9419 | if (op == 0xc8) | |
9420 | first = first + 16; | |
9421 | printf ("pop {D%d", first); | |
9422 | if (last) | |
9423 | printf ("-D%d", first + last); | |
9424 | printf ("}"); | |
9425 | } | |
09854a88 TB |
9426 | else if (op == 0xb4) |
9427 | printf (_(" pop {ra_auth_code}")); | |
61865e30 NC |
9428 | else if ((op & 0xf8) == 0xb8 || (op & 0xf8) == 0xd0) |
9429 | { | |
9430 | unsigned int count = op & 0x07; | |
9431 | ||
9432 | printf ("pop {D8"); | |
9433 | if (count) | |
9434 | printf ("-D%d", 8 + count); | |
9435 | printf ("}"); | |
9436 | } | |
9437 | else if (op >= 0xc0 && op <= 0xc5) | |
9438 | { | |
9439 | unsigned int count = op & 0x07; | |
9440 | ||
9441 | printf (" pop {wR10"); | |
9442 | if (count) | |
9443 | printf ("-wR%d", 10 + count); | |
9444 | printf ("}"); | |
9445 | } | |
9446 | else if (op == 0xc6) | |
9447 | { | |
9448 | unsigned int first, last; | |
9449 | ||
9450 | GET_OP (op2); | |
9451 | first = op2 >> 4; | |
9452 | last = op2 & 0x0f; | |
9453 | printf ("pop {wR%d", first); | |
9454 | if (last) | |
9455 | printf ("-wR%d", first + last); | |
9456 | printf ("}"); | |
9457 | } | |
9458 | else if (op == 0xc7) | |
9459 | { | |
9460 | GET_OP (op2); | |
9461 | if (op2 == 0 || (op2 & 0xf0) != 0) | |
9462 | printf (_("[Spare]")); | |
0b6ae522 DJ |
9463 | else |
9464 | { | |
61865e30 | 9465 | unsigned int mask = op2 & 0x0f; |
015dc7e1 | 9466 | bool first = true; |
61865e30 NC |
9467 | int i; |
9468 | ||
9469 | printf ("pop {"); | |
9470 | for (i = 0; i < 4; i++) | |
9471 | if (mask & (1 << i)) | |
9472 | { | |
9473 | if (first) | |
015dc7e1 | 9474 | first = false; |
61865e30 NC |
9475 | else |
9476 | printf (", "); | |
9477 | printf ("wCGR%d", i); | |
9478 | } | |
9479 | printf ("}"); | |
0b6ae522 DJ |
9480 | } |
9481 | } | |
61865e30 | 9482 | else |
32ec8896 NC |
9483 | { |
9484 | printf (_(" [unsupported opcode]")); | |
015dc7e1 | 9485 | res = false; |
32ec8896 NC |
9486 | } |
9487 | ||
0b6ae522 DJ |
9488 | printf ("\n"); |
9489 | } | |
32ec8896 NC |
9490 | |
9491 | return res; | |
fa197c1c PB |
9492 | } |
9493 | ||
015dc7e1 | 9494 | static bool |
dda8d76d NC |
9495 | decode_tic6x_unwind_bytecode (Filedata * filedata, |
9496 | struct arm_unw_aux_info * aux, | |
948f632f DA |
9497 | unsigned int word, |
9498 | unsigned int remaining, | |
9499 | unsigned int more_words, | |
9500 | bfd_vma data_offset, | |
9501 | Elf_Internal_Shdr * data_sec, | |
9502 | struct arm_section * data_arm_sec) | |
fa197c1c PB |
9503 | { |
9504 | struct absaddr addr; | |
9505 | ||
9506 | /* Decode the unwinding instructions. */ | |
9507 | while (1) | |
9508 | { | |
9509 | unsigned int op, op2; | |
9510 | ||
9511 | ADVANCE; | |
9512 | if (remaining == 0) | |
9513 | break; | |
9514 | remaining--; | |
9515 | op = word >> 24; | |
9516 | word <<= 8; | |
9517 | ||
9cf03b7e | 9518 | printf (" 0x%02x ", op); |
fa197c1c PB |
9519 | |
9520 | if ((op & 0xc0) == 0x00) | |
9521 | { | |
9522 | int offset = ((op & 0x3f) << 3) + 8; | |
9cf03b7e | 9523 | printf (" sp = sp + %d", offset); |
fa197c1c PB |
9524 | } |
9525 | else if ((op & 0xc0) == 0x80) | |
9526 | { | |
9527 | GET_OP (op2); | |
9528 | if (op == 0x80 && op2 == 0) | |
9529 | printf (_("Refuse to unwind")); | |
9530 | else | |
9531 | { | |
9532 | unsigned int mask = ((op & 0x1f) << 8) | op2; | |
9533 | if (op & 0x20) | |
9534 | printf ("pop compact {"); | |
9535 | else | |
9536 | printf ("pop {"); | |
9537 | ||
9538 | decode_tic6x_unwind_regmask (mask); | |
9539 | printf("}"); | |
9540 | } | |
9541 | } | |
9542 | else if ((op & 0xf0) == 0xc0) | |
9543 | { | |
9544 | unsigned int reg; | |
9545 | unsigned int nregs; | |
9546 | unsigned int i; | |
9547 | const char *name; | |
a734115a NC |
9548 | struct |
9549 | { | |
32ec8896 NC |
9550 | unsigned int offset; |
9551 | unsigned int reg; | |
fa197c1c PB |
9552 | } regpos[16]; |
9553 | ||
9554 | /* Scan entire instruction first so that GET_OP output is not | |
9555 | interleaved with disassembly. */ | |
9556 | nregs = 0; | |
9557 | for (i = 0; nregs < (op & 0xf); i++) | |
9558 | { | |
9559 | GET_OP (op2); | |
9560 | reg = op2 >> 4; | |
9561 | if (reg != 0xf) | |
9562 | { | |
9563 | regpos[nregs].offset = i * 2; | |
9564 | regpos[nregs].reg = reg; | |
9565 | nregs++; | |
9566 | } | |
9567 | ||
9568 | reg = op2 & 0xf; | |
9569 | if (reg != 0xf) | |
9570 | { | |
9571 | regpos[nregs].offset = i * 2 + 1; | |
9572 | regpos[nregs].reg = reg; | |
9573 | nregs++; | |
9574 | } | |
9575 | } | |
9576 | ||
9577 | printf (_("pop frame {")); | |
18344509 | 9578 | if (nregs == 0) |
fa197c1c | 9579 | { |
18344509 NC |
9580 | printf (_("*corrupt* - no registers specified")); |
9581 | } | |
9582 | else | |
9583 | { | |
9584 | reg = nregs - 1; | |
9585 | for (i = i * 2; i > 0; i--) | |
fa197c1c | 9586 | { |
18344509 NC |
9587 | if (regpos[reg].offset == i - 1) |
9588 | { | |
9589 | name = tic6x_unwind_regnames[regpos[reg].reg]; | |
9590 | if (reg > 0) | |
9591 | reg--; | |
9592 | } | |
9593 | else | |
9594 | name = _("[pad]"); | |
fa197c1c | 9595 | |
18344509 NC |
9596 | fputs (name, stdout); |
9597 | if (i > 1) | |
9598 | printf (", "); | |
9599 | } | |
fa197c1c PB |
9600 | } |
9601 | ||
9602 | printf ("}"); | |
9603 | } | |
9604 | else if (op == 0xd0) | |
9605 | printf (" MOV FP, SP"); | |
9606 | else if (op == 0xd1) | |
9607 | printf (" __c6xabi_pop_rts"); | |
9608 | else if (op == 0xd2) | |
9609 | { | |
9610 | unsigned char buf[9]; | |
9611 | unsigned int i, len; | |
9612 | unsigned long offset; | |
a734115a | 9613 | |
fa197c1c PB |
9614 | for (i = 0; i < sizeof (buf); i++) |
9615 | { | |
9616 | GET_OP (buf[i]); | |
9617 | if ((buf[i] & 0x80) == 0) | |
9618 | break; | |
9619 | } | |
0eff7165 NC |
9620 | /* PR 17531: file: id:000001,src:001906+004739,op:splice,rep:2. */ |
9621 | if (i == sizeof (buf)) | |
9622 | { | |
0eff7165 | 9623 | warn (_("Corrupt stack pointer adjustment detected\n")); |
015dc7e1 | 9624 | return false; |
0eff7165 | 9625 | } |
948f632f | 9626 | |
015dc7e1 | 9627 | offset = read_leb128 (buf, buf + i + 1, false, &len, NULL); |
fa197c1c PB |
9628 | assert (len == i + 1); |
9629 | offset = offset * 8 + 0x408; | |
9630 | printf (_("sp = sp + %ld"), offset); | |
9631 | } | |
9632 | else if ((op & 0xf0) == 0xe0) | |
9633 | { | |
9634 | if ((op & 0x0f) == 7) | |
9635 | printf (" RETURN"); | |
9636 | else | |
9637 | printf (" MV %s, B3", tic6x_unwind_regnames[op & 0x0f]); | |
9638 | } | |
9639 | else | |
9640 | { | |
9641 | printf (_(" [unsupported opcode]")); | |
9642 | } | |
9643 | putchar ('\n'); | |
9644 | } | |
32ec8896 | 9645 | |
015dc7e1 | 9646 | return true; |
fa197c1c PB |
9647 | } |
9648 | ||
9649 | static bfd_vma | |
dda8d76d | 9650 | arm_expand_prel31 (Filedata * filedata, bfd_vma word, bfd_vma where) |
fa197c1c PB |
9651 | { |
9652 | bfd_vma offset; | |
9653 | ||
9654 | offset = word & 0x7fffffff; | |
9655 | if (offset & 0x40000000) | |
9656 | offset |= ~ (bfd_vma) 0x7fffffff; | |
9657 | ||
dda8d76d | 9658 | if (filedata->file_header.e_machine == EM_TI_C6000) |
fa197c1c PB |
9659 | offset <<= 1; |
9660 | ||
9661 | return offset + where; | |
9662 | } | |
9663 | ||
015dc7e1 | 9664 | static bool |
dda8d76d NC |
9665 | decode_arm_unwind (Filedata * filedata, |
9666 | struct arm_unw_aux_info * aux, | |
1b31d05e NC |
9667 | unsigned int word, |
9668 | unsigned int remaining, | |
9669 | bfd_vma data_offset, | |
9670 | Elf_Internal_Shdr * data_sec, | |
9671 | struct arm_section * data_arm_sec) | |
fa197c1c PB |
9672 | { |
9673 | int per_index; | |
9674 | unsigned int more_words = 0; | |
37e14bc3 | 9675 | struct absaddr addr; |
1b31d05e | 9676 | bfd_vma sym_name = (bfd_vma) -1; |
015dc7e1 | 9677 | bool res = true; |
fa197c1c PB |
9678 | |
9679 | if (remaining == 0) | |
9680 | { | |
1b31d05e NC |
9681 | /* Fetch the first word. |
9682 | Note - when decoding an object file the address extracted | |
9683 | here will always be 0. So we also pass in the sym_name | |
9684 | parameter so that we can find the symbol associated with | |
9685 | the personality routine. */ | |
dda8d76d | 9686 | if (! get_unwind_section_word (filedata, aux, data_arm_sec, data_sec, data_offset, |
1b31d05e | 9687 | & word, & addr, & sym_name)) |
015dc7e1 | 9688 | return false; |
1b31d05e | 9689 | |
fa197c1c PB |
9690 | remaining = 4; |
9691 | } | |
c93dbb25 CZ |
9692 | else |
9693 | { | |
9694 | addr.section = SHN_UNDEF; | |
9695 | addr.offset = 0; | |
9696 | } | |
fa197c1c PB |
9697 | |
9698 | if ((word & 0x80000000) == 0) | |
9699 | { | |
9700 | /* Expand prel31 for personality routine. */ | |
9701 | bfd_vma fn; | |
9702 | const char *procname; | |
9703 | ||
dda8d76d | 9704 | fn = arm_expand_prel31 (filedata, word, data_sec->sh_addr + data_offset); |
fa197c1c | 9705 | printf (_(" Personality routine: ")); |
1b31d05e NC |
9706 | if (fn == 0 |
9707 | && addr.section == SHN_UNDEF && addr.offset == 0 | |
9708 | && sym_name != (bfd_vma) -1 && sym_name < aux->strtab_size) | |
9709 | { | |
9710 | procname = aux->strtab + sym_name; | |
9711 | print_vma (fn, PREFIX_HEX); | |
9712 | if (procname) | |
9713 | { | |
9714 | fputs (" <", stdout); | |
9715 | fputs (procname, stdout); | |
9716 | fputc ('>', stdout); | |
9717 | } | |
9718 | } | |
9719 | else | |
dda8d76d | 9720 | procname = arm_print_vma_and_name (filedata, aux, fn, addr); |
fa197c1c PB |
9721 | fputc ('\n', stdout); |
9722 | ||
9723 | /* The GCC personality routines use the standard compact | |
9724 | encoding, starting with one byte giving the number of | |
9725 | words. */ | |
9726 | if (procname != NULL | |
24d127aa ML |
9727 | && (startswith (procname, "__gcc_personality_v0") |
9728 | || startswith (procname, "__gxx_personality_v0") | |
9729 | || startswith (procname, "__gcj_personality_v0") | |
9730 | || startswith (procname, "__gnu_objc_personality_v0"))) | |
fa197c1c PB |
9731 | { |
9732 | remaining = 0; | |
9733 | more_words = 1; | |
9734 | ADVANCE; | |
9735 | if (!remaining) | |
9736 | { | |
9737 | printf (_(" [Truncated data]\n")); | |
015dc7e1 | 9738 | return false; |
fa197c1c PB |
9739 | } |
9740 | more_words = word >> 24; | |
9741 | word <<= 8; | |
9742 | remaining--; | |
9743 | per_index = -1; | |
9744 | } | |
9745 | else | |
015dc7e1 | 9746 | return true; |
fa197c1c PB |
9747 | } |
9748 | else | |
9749 | { | |
1b31d05e | 9750 | /* ARM EHABI Section 6.3: |
0b4362b0 | 9751 | |
1b31d05e | 9752 | An exception-handling table entry for the compact model looks like: |
0b4362b0 | 9753 | |
1b31d05e NC |
9754 | 31 30-28 27-24 23-0 |
9755 | -- ----- ----- ---- | |
9756 | 1 0 index Data for personalityRoutine[index] */ | |
9757 | ||
dda8d76d | 9758 | if (filedata->file_header.e_machine == EM_ARM |
1b31d05e | 9759 | && (word & 0x70000000)) |
32ec8896 NC |
9760 | { |
9761 | warn (_("Corrupt ARM compact model table entry: %x \n"), word); | |
015dc7e1 | 9762 | res = false; |
32ec8896 | 9763 | } |
1b31d05e | 9764 | |
fa197c1c | 9765 | per_index = (word >> 24) & 0x7f; |
1b31d05e | 9766 | printf (_(" Compact model index: %d\n"), per_index); |
fa197c1c PB |
9767 | if (per_index == 0) |
9768 | { | |
9769 | more_words = 0; | |
9770 | word <<= 8; | |
9771 | remaining--; | |
9772 | } | |
9773 | else if (per_index < 3) | |
9774 | { | |
9775 | more_words = (word >> 16) & 0xff; | |
9776 | word <<= 16; | |
9777 | remaining -= 2; | |
9778 | } | |
9779 | } | |
9780 | ||
dda8d76d | 9781 | switch (filedata->file_header.e_machine) |
fa197c1c PB |
9782 | { |
9783 | case EM_ARM: | |
9784 | if (per_index < 3) | |
9785 | { | |
dda8d76d | 9786 | if (! decode_arm_unwind_bytecode (filedata, aux, word, remaining, more_words, |
32ec8896 | 9787 | data_offset, data_sec, data_arm_sec)) |
015dc7e1 | 9788 | res = false; |
fa197c1c PB |
9789 | } |
9790 | else | |
1b31d05e NC |
9791 | { |
9792 | warn (_("Unknown ARM compact model index encountered\n")); | |
9793 | printf (_(" [reserved]\n")); | |
015dc7e1 | 9794 | res = false; |
1b31d05e | 9795 | } |
fa197c1c PB |
9796 | break; |
9797 | ||
9798 | case EM_TI_C6000: | |
9799 | if (per_index < 3) | |
9800 | { | |
dda8d76d | 9801 | if (! decode_tic6x_unwind_bytecode (filedata, aux, word, remaining, more_words, |
32ec8896 | 9802 | data_offset, data_sec, data_arm_sec)) |
015dc7e1 | 9803 | res = false; |
fa197c1c PB |
9804 | } |
9805 | else if (per_index < 5) | |
9806 | { | |
9807 | if (((word >> 17) & 0x7f) == 0x7f) | |
9808 | printf (_(" Restore stack from frame pointer\n")); | |
9809 | else | |
9810 | printf (_(" Stack increment %d\n"), (word >> 14) & 0x1fc); | |
9811 | printf (_(" Registers restored: ")); | |
9812 | if (per_index == 4) | |
9813 | printf (" (compact) "); | |
9814 | decode_tic6x_unwind_regmask ((word >> 4) & 0x1fff); | |
9815 | putchar ('\n'); | |
9816 | printf (_(" Return register: %s\n"), | |
9817 | tic6x_unwind_regnames[word & 0xf]); | |
9818 | } | |
9819 | else | |
1b31d05e | 9820 | printf (_(" [reserved (%d)]\n"), per_index); |
fa197c1c PB |
9821 | break; |
9822 | ||
9823 | default: | |
74e1a04b | 9824 | error (_("Unsupported architecture type %d encountered when decoding unwind table\n"), |
dda8d76d | 9825 | filedata->file_header.e_machine); |
015dc7e1 | 9826 | res = false; |
fa197c1c | 9827 | } |
0b6ae522 DJ |
9828 | |
9829 | /* Decode the descriptors. Not implemented. */ | |
32ec8896 NC |
9830 | |
9831 | return res; | |
0b6ae522 DJ |
9832 | } |
9833 | ||
015dc7e1 | 9834 | static bool |
dda8d76d NC |
9835 | dump_arm_unwind (Filedata * filedata, |
9836 | struct arm_unw_aux_info * aux, | |
9837 | Elf_Internal_Shdr * exidx_sec) | |
0b6ae522 DJ |
9838 | { |
9839 | struct arm_section exidx_arm_sec, extab_arm_sec; | |
9840 | unsigned int i, exidx_len; | |
948f632f | 9841 | unsigned long j, nfuns; |
015dc7e1 | 9842 | bool res = true; |
0b6ae522 DJ |
9843 | |
9844 | memset (&exidx_arm_sec, 0, sizeof (exidx_arm_sec)); | |
9845 | memset (&extab_arm_sec, 0, sizeof (extab_arm_sec)); | |
9846 | exidx_len = exidx_sec->sh_size / 8; | |
9847 | ||
948f632f DA |
9848 | aux->funtab = xmalloc (aux->nsyms * sizeof (Elf_Internal_Sym)); |
9849 | for (nfuns = 0, j = 0; j < aux->nsyms; j++) | |
9850 | if (aux->symtab[j].st_value && ELF_ST_TYPE (aux->symtab[j].st_info) == STT_FUNC) | |
9851 | aux->funtab[nfuns++] = aux->symtab[j]; | |
9852 | aux->nfuns = nfuns; | |
9853 | qsort (aux->funtab, aux->nfuns, sizeof (Elf_Internal_Sym), symcmp); | |
9854 | ||
0b6ae522 DJ |
9855 | for (i = 0; i < exidx_len; i++) |
9856 | { | |
9857 | unsigned int exidx_fn, exidx_entry; | |
9858 | struct absaddr fn_addr, entry_addr; | |
9859 | bfd_vma fn; | |
9860 | ||
9861 | fputc ('\n', stdout); | |
9862 | ||
dda8d76d | 9863 | if (! get_unwind_section_word (filedata, aux, & exidx_arm_sec, exidx_sec, |
1b31d05e | 9864 | 8 * i, & exidx_fn, & fn_addr, NULL) |
dda8d76d | 9865 | || ! get_unwind_section_word (filedata, aux, & exidx_arm_sec, exidx_sec, |
1b31d05e | 9866 | 8 * i + 4, & exidx_entry, & entry_addr, NULL)) |
0b6ae522 | 9867 | { |
948f632f | 9868 | free (aux->funtab); |
1b31d05e NC |
9869 | arm_free_section (& exidx_arm_sec); |
9870 | arm_free_section (& extab_arm_sec); | |
015dc7e1 | 9871 | return false; |
0b6ae522 DJ |
9872 | } |
9873 | ||
83c257ca NC |
9874 | /* ARM EHABI, Section 5: |
9875 | An index table entry consists of 2 words. | |
9876 | The first word contains a prel31 offset to the start of a function, with bit 31 clear. */ | |
9877 | if (exidx_fn & 0x80000000) | |
32ec8896 NC |
9878 | { |
9879 | warn (_("corrupt index table entry: %x\n"), exidx_fn); | |
015dc7e1 | 9880 | res = false; |
32ec8896 | 9881 | } |
83c257ca | 9882 | |
dda8d76d | 9883 | fn = arm_expand_prel31 (filedata, exidx_fn, exidx_sec->sh_addr + 8 * i); |
0b6ae522 | 9884 | |
dda8d76d | 9885 | arm_print_vma_and_name (filedata, aux, fn, fn_addr); |
0b6ae522 DJ |
9886 | fputs (": ", stdout); |
9887 | ||
9888 | if (exidx_entry == 1) | |
9889 | { | |
9890 | print_vma (exidx_entry, PREFIX_HEX); | |
9891 | fputs (" [cantunwind]\n", stdout); | |
9892 | } | |
9893 | else if (exidx_entry & 0x80000000) | |
9894 | { | |
9895 | print_vma (exidx_entry, PREFIX_HEX); | |
9896 | fputc ('\n', stdout); | |
dda8d76d | 9897 | decode_arm_unwind (filedata, aux, exidx_entry, 4, 0, NULL, NULL); |
0b6ae522 DJ |
9898 | } |
9899 | else | |
9900 | { | |
8f73510c | 9901 | bfd_vma table, table_offset = 0; |
0b6ae522 DJ |
9902 | Elf_Internal_Shdr *table_sec; |
9903 | ||
9904 | fputs ("@", stdout); | |
dda8d76d | 9905 | table = arm_expand_prel31 (filedata, exidx_entry, exidx_sec->sh_addr + 8 * i + 4); |
0b6ae522 DJ |
9906 | print_vma (table, PREFIX_HEX); |
9907 | printf ("\n"); | |
9908 | ||
9909 | /* Locate the matching .ARM.extab. */ | |
9910 | if (entry_addr.section != SHN_UNDEF | |
dda8d76d | 9911 | && entry_addr.section < filedata->file_header.e_shnum) |
0b6ae522 | 9912 | { |
dda8d76d | 9913 | table_sec = filedata->section_headers + entry_addr.section; |
0b6ae522 | 9914 | table_offset = entry_addr.offset; |
1a915552 NC |
9915 | /* PR 18879 */ |
9916 | if (table_offset > table_sec->sh_size | |
9917 | || ((bfd_signed_vma) table_offset) < 0) | |
9918 | { | |
9919 | warn (_("Unwind entry contains corrupt offset (0x%lx) into section %s\n"), | |
9920 | (unsigned long) table_offset, | |
dda8d76d | 9921 | printable_section_name (filedata, table_sec)); |
015dc7e1 | 9922 | res = false; |
1a915552 NC |
9923 | continue; |
9924 | } | |
0b6ae522 DJ |
9925 | } |
9926 | else | |
9927 | { | |
dda8d76d | 9928 | table_sec = find_section_by_address (filedata, table); |
0b6ae522 DJ |
9929 | if (table_sec != NULL) |
9930 | table_offset = table - table_sec->sh_addr; | |
9931 | } | |
32ec8896 | 9932 | |
0b6ae522 DJ |
9933 | if (table_sec == NULL) |
9934 | { | |
9935 | warn (_("Could not locate .ARM.extab section containing 0x%lx.\n"), | |
9936 | (unsigned long) table); | |
015dc7e1 | 9937 | res = false; |
0b6ae522 DJ |
9938 | continue; |
9939 | } | |
32ec8896 | 9940 | |
dda8d76d | 9941 | if (! decode_arm_unwind (filedata, aux, 0, 0, table_offset, table_sec, |
32ec8896 | 9942 | &extab_arm_sec)) |
015dc7e1 | 9943 | res = false; |
0b6ae522 DJ |
9944 | } |
9945 | } | |
9946 | ||
9947 | printf ("\n"); | |
9948 | ||
948f632f | 9949 | free (aux->funtab); |
0b6ae522 DJ |
9950 | arm_free_section (&exidx_arm_sec); |
9951 | arm_free_section (&extab_arm_sec); | |
32ec8896 NC |
9952 | |
9953 | return res; | |
0b6ae522 DJ |
9954 | } |
9955 | ||
fa197c1c | 9956 | /* Used for both ARM and C6X unwinding tables. */ |
1b31d05e | 9957 | |
015dc7e1 | 9958 | static bool |
dda8d76d | 9959 | arm_process_unwind (Filedata * filedata) |
0b6ae522 DJ |
9960 | { |
9961 | struct arm_unw_aux_info aux; | |
9962 | Elf_Internal_Shdr *unwsec = NULL; | |
0b6ae522 DJ |
9963 | Elf_Internal_Shdr *sec; |
9964 | unsigned long i; | |
fa197c1c | 9965 | unsigned int sec_type; |
015dc7e1 | 9966 | bool res = true; |
0b6ae522 | 9967 | |
dda8d76d | 9968 | switch (filedata->file_header.e_machine) |
fa197c1c PB |
9969 | { |
9970 | case EM_ARM: | |
9971 | sec_type = SHT_ARM_EXIDX; | |
9972 | break; | |
9973 | ||
9974 | case EM_TI_C6000: | |
9975 | sec_type = SHT_C6000_UNWIND; | |
9976 | break; | |
9977 | ||
0b4362b0 | 9978 | default: |
74e1a04b | 9979 | error (_("Unsupported architecture type %d encountered when processing unwind table\n"), |
dda8d76d | 9980 | filedata->file_header.e_machine); |
015dc7e1 | 9981 | return false; |
fa197c1c PB |
9982 | } |
9983 | ||
dda8d76d | 9984 | if (filedata->string_table == NULL) |
015dc7e1 | 9985 | return false; |
1b31d05e NC |
9986 | |
9987 | memset (& aux, 0, sizeof (aux)); | |
dda8d76d | 9988 | aux.filedata = filedata; |
0b6ae522 | 9989 | |
dda8d76d | 9990 | for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec) |
0b6ae522 | 9991 | { |
28d13567 | 9992 | if (sec->sh_type == SHT_SYMTAB) |
0b6ae522 | 9993 | { |
28d13567 | 9994 | if (aux.symtab) |
74e1a04b | 9995 | { |
28d13567 AM |
9996 | error (_("Multiple symbol tables encountered\n")); |
9997 | free (aux.symtab); | |
9998 | aux.symtab = NULL; | |
74e1a04b | 9999 | free (aux.strtab); |
28d13567 | 10000 | aux.strtab = NULL; |
74e1a04b | 10001 | } |
28d13567 AM |
10002 | if (!get_symtab (filedata, sec, &aux.symtab, &aux.nsyms, |
10003 | &aux.strtab, &aux.strtab_size)) | |
015dc7e1 | 10004 | return false; |
0b6ae522 | 10005 | } |
fa197c1c | 10006 | else if (sec->sh_type == sec_type) |
0b6ae522 DJ |
10007 | unwsec = sec; |
10008 | } | |
10009 | ||
1b31d05e | 10010 | if (unwsec == NULL) |
0b6ae522 | 10011 | printf (_("\nThere are no unwind sections in this file.\n")); |
1b31d05e | 10012 | else |
dda8d76d | 10013 | for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec) |
1b31d05e NC |
10014 | { |
10015 | if (sec->sh_type == sec_type) | |
10016 | { | |
d3a49aa8 AM |
10017 | unsigned long num_unwind = sec->sh_size / (2 * eh_addr_size); |
10018 | printf (ngettext ("\nUnwind section '%s' at offset 0x%lx " | |
10019 | "contains %lu entry:\n", | |
10020 | "\nUnwind section '%s' at offset 0x%lx " | |
10021 | "contains %lu entries:\n", | |
10022 | num_unwind), | |
dda8d76d | 10023 | printable_section_name (filedata, sec), |
1b31d05e | 10024 | (unsigned long) sec->sh_offset, |
d3a49aa8 | 10025 | num_unwind); |
0b6ae522 | 10026 | |
dda8d76d | 10027 | if (! dump_arm_unwind (filedata, &aux, sec)) |
015dc7e1 | 10028 | res = false; |
1b31d05e NC |
10029 | } |
10030 | } | |
0b6ae522 | 10031 | |
9db70fc3 AM |
10032 | free (aux.symtab); |
10033 | free ((char *) aux.strtab); | |
32ec8896 NC |
10034 | |
10035 | return res; | |
0b6ae522 DJ |
10036 | } |
10037 | ||
3ecc00ec NC |
10038 | static bool |
10039 | no_processor_specific_unwind (Filedata * filedata ATTRIBUTE_UNUSED) | |
10040 | { | |
10041 | printf (_("No processor specific unwind information to decode\n")); | |
10042 | return true; | |
10043 | } | |
10044 | ||
015dc7e1 | 10045 | static bool |
dda8d76d | 10046 | process_unwind (Filedata * filedata) |
57346661 | 10047 | { |
2cf0635d NC |
10048 | struct unwind_handler |
10049 | { | |
32ec8896 | 10050 | unsigned int machtype; |
015dc7e1 | 10051 | bool (* handler)(Filedata *); |
2cf0635d NC |
10052 | } handlers[] = |
10053 | { | |
0b6ae522 | 10054 | { EM_ARM, arm_process_unwind }, |
57346661 AM |
10055 | { EM_IA_64, ia64_process_unwind }, |
10056 | { EM_PARISC, hppa_process_unwind }, | |
fa197c1c | 10057 | { EM_TI_C6000, arm_process_unwind }, |
3ecc00ec NC |
10058 | { EM_386, no_processor_specific_unwind }, |
10059 | { EM_X86_64, no_processor_specific_unwind }, | |
32ec8896 | 10060 | { 0, NULL } |
57346661 AM |
10061 | }; |
10062 | int i; | |
10063 | ||
10064 | if (!do_unwind) | |
015dc7e1 | 10065 | return true; |
57346661 AM |
10066 | |
10067 | for (i = 0; handlers[i].handler != NULL; i++) | |
dda8d76d NC |
10068 | if (filedata->file_header.e_machine == handlers[i].machtype) |
10069 | return handlers[i].handler (filedata); | |
57346661 | 10070 | |
1b31d05e | 10071 | printf (_("\nThe decoding of unwind sections for machine type %s is not currently supported.\n"), |
dda8d76d | 10072 | get_machine_name (filedata->file_header.e_machine)); |
015dc7e1 | 10073 | return true; |
57346661 AM |
10074 | } |
10075 | ||
37c18eed SD |
10076 | static void |
10077 | dynamic_section_aarch64_val (Elf_Internal_Dyn * entry) | |
10078 | { | |
10079 | switch (entry->d_tag) | |
10080 | { | |
10081 | case DT_AARCH64_BTI_PLT: | |
1dbade74 | 10082 | case DT_AARCH64_PAC_PLT: |
37c18eed SD |
10083 | break; |
10084 | default: | |
10085 | print_vma (entry->d_un.d_ptr, PREFIX_HEX); | |
10086 | break; | |
10087 | } | |
10088 | putchar ('\n'); | |
10089 | } | |
10090 | ||
252b5132 | 10091 | static void |
978c4450 | 10092 | dynamic_section_mips_val (Filedata * filedata, Elf_Internal_Dyn * entry) |
252b5132 RH |
10093 | { |
10094 | switch (entry->d_tag) | |
10095 | { | |
10096 | case DT_MIPS_FLAGS: | |
10097 | if (entry->d_un.d_val == 0) | |
4b68bca3 | 10098 | printf (_("NONE")); |
252b5132 RH |
10099 | else |
10100 | { | |
10101 | static const char * opts[] = | |
10102 | { | |
10103 | "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT", | |
10104 | "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS", | |
10105 | "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD", | |
10106 | "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF", | |
10107 | "RLD_ORDER_SAFE" | |
10108 | }; | |
10109 | unsigned int cnt; | |
015dc7e1 | 10110 | bool first = true; |
2b692964 | 10111 | |
60bca95a | 10112 | for (cnt = 0; cnt < ARRAY_SIZE (opts); ++cnt) |
252b5132 RH |
10113 | if (entry->d_un.d_val & (1 << cnt)) |
10114 | { | |
10115 | printf ("%s%s", first ? "" : " ", opts[cnt]); | |
015dc7e1 | 10116 | first = false; |
252b5132 | 10117 | } |
252b5132 RH |
10118 | } |
10119 | break; | |
103f02d3 | 10120 | |
252b5132 | 10121 | case DT_MIPS_IVERSION: |
84714f86 | 10122 | if (valid_dynamic_name (filedata, entry->d_un.d_val)) |
978c4450 | 10123 | printf (_("Interface Version: %s"), |
84714f86 | 10124 | get_dynamic_name (filedata, entry->d_un.d_val)); |
252b5132 | 10125 | else |
76ca31c0 NC |
10126 | { |
10127 | char buf[40]; | |
10128 | sprintf_vma (buf, entry->d_un.d_ptr); | |
10129 | /* Note: coded this way so that there is a single string for translation. */ | |
10130 | printf (_("<corrupt: %s>"), buf); | |
10131 | } | |
252b5132 | 10132 | break; |
103f02d3 | 10133 | |
252b5132 RH |
10134 | case DT_MIPS_TIME_STAMP: |
10135 | { | |
d5b07ef4 | 10136 | char timebuf[128]; |
2cf0635d | 10137 | struct tm * tmp; |
91d6fa6a | 10138 | time_t atime = entry->d_un.d_val; |
82b1b41b | 10139 | |
91d6fa6a | 10140 | tmp = gmtime (&atime); |
82b1b41b NC |
10141 | /* PR 17531: file: 6accc532. */ |
10142 | if (tmp == NULL) | |
10143 | snprintf (timebuf, sizeof (timebuf), _("<corrupt>")); | |
10144 | else | |
10145 | snprintf (timebuf, sizeof (timebuf), "%04u-%02u-%02uT%02u:%02u:%02u", | |
10146 | tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday, | |
10147 | tmp->tm_hour, tmp->tm_min, tmp->tm_sec); | |
4b68bca3 | 10148 | printf (_("Time Stamp: %s"), timebuf); |
252b5132 RH |
10149 | } |
10150 | break; | |
103f02d3 | 10151 | |
252b5132 RH |
10152 | case DT_MIPS_RLD_VERSION: |
10153 | case DT_MIPS_LOCAL_GOTNO: | |
10154 | case DT_MIPS_CONFLICTNO: | |
10155 | case DT_MIPS_LIBLISTNO: | |
10156 | case DT_MIPS_SYMTABNO: | |
10157 | case DT_MIPS_UNREFEXTNO: | |
10158 | case DT_MIPS_HIPAGENO: | |
10159 | case DT_MIPS_DELTA_CLASS_NO: | |
10160 | case DT_MIPS_DELTA_INSTANCE_NO: | |
10161 | case DT_MIPS_DELTA_RELOC_NO: | |
10162 | case DT_MIPS_DELTA_SYM_NO: | |
10163 | case DT_MIPS_DELTA_CLASSSYM_NO: | |
10164 | case DT_MIPS_COMPACT_SIZE: | |
c69075ac | 10165 | print_vma (entry->d_un.d_val, DEC); |
252b5132 | 10166 | break; |
103f02d3 | 10167 | |
f16a9783 | 10168 | case DT_MIPS_XHASH: |
978c4450 AM |
10169 | filedata->dynamic_info_DT_MIPS_XHASH = entry->d_un.d_val; |
10170 | filedata->dynamic_info_DT_GNU_HASH = entry->d_un.d_val; | |
f16a9783 MS |
10171 | /* Falls through. */ |
10172 | ||
103f02d3 | 10173 | default: |
4b68bca3 | 10174 | print_vma (entry->d_un.d_ptr, PREFIX_HEX); |
103f02d3 | 10175 | } |
4b68bca3 | 10176 | putchar ('\n'); |
103f02d3 UD |
10177 | } |
10178 | ||
103f02d3 | 10179 | static void |
2cf0635d | 10180 | dynamic_section_parisc_val (Elf_Internal_Dyn * entry) |
103f02d3 UD |
10181 | { |
10182 | switch (entry->d_tag) | |
10183 | { | |
10184 | case DT_HP_DLD_FLAGS: | |
10185 | { | |
10186 | static struct | |
10187 | { | |
10188 | long int bit; | |
2cf0635d | 10189 | const char * str; |
5e220199 NC |
10190 | } |
10191 | flags[] = | |
10192 | { | |
10193 | { DT_HP_DEBUG_PRIVATE, "HP_DEBUG_PRIVATE" }, | |
10194 | { DT_HP_DEBUG_CALLBACK, "HP_DEBUG_CALLBACK" }, | |
10195 | { DT_HP_DEBUG_CALLBACK_BOR, "HP_DEBUG_CALLBACK_BOR" }, | |
10196 | { DT_HP_NO_ENVVAR, "HP_NO_ENVVAR" }, | |
10197 | { DT_HP_BIND_NOW, "HP_BIND_NOW" }, | |
10198 | { DT_HP_BIND_NONFATAL, "HP_BIND_NONFATAL" }, | |
10199 | { DT_HP_BIND_VERBOSE, "HP_BIND_VERBOSE" }, | |
10200 | { DT_HP_BIND_RESTRICTED, "HP_BIND_RESTRICTED" }, | |
10201 | { DT_HP_BIND_SYMBOLIC, "HP_BIND_SYMBOLIC" }, | |
10202 | { DT_HP_RPATH_FIRST, "HP_RPATH_FIRST" }, | |
eec8f817 DA |
10203 | { DT_HP_BIND_DEPTH_FIRST, "HP_BIND_DEPTH_FIRST" }, |
10204 | { DT_HP_GST, "HP_GST" }, | |
10205 | { DT_HP_SHLIB_FIXED, "HP_SHLIB_FIXED" }, | |
10206 | { DT_HP_MERGE_SHLIB_SEG, "HP_MERGE_SHLIB_SEG" }, | |
10207 | { DT_HP_NODELETE, "HP_NODELETE" }, | |
10208 | { DT_HP_GROUP, "HP_GROUP" }, | |
10209 | { DT_HP_PROTECT_LINKAGE_TABLE, "HP_PROTECT_LINKAGE_TABLE" } | |
5e220199 | 10210 | }; |
015dc7e1 | 10211 | bool first = true; |
5e220199 | 10212 | size_t cnt; |
f7a99963 | 10213 | bfd_vma val = entry->d_un.d_val; |
103f02d3 | 10214 | |
60bca95a | 10215 | for (cnt = 0; cnt < ARRAY_SIZE (flags); ++cnt) |
103f02d3 | 10216 | if (val & flags[cnt].bit) |
30800947 NC |
10217 | { |
10218 | if (! first) | |
10219 | putchar (' '); | |
10220 | fputs (flags[cnt].str, stdout); | |
015dc7e1 | 10221 | first = false; |
30800947 NC |
10222 | val ^= flags[cnt].bit; |
10223 | } | |
76da6bbe | 10224 | |
103f02d3 | 10225 | if (val != 0 || first) |
f7a99963 NC |
10226 | { |
10227 | if (! first) | |
10228 | putchar (' '); | |
10229 | print_vma (val, HEX); | |
10230 | } | |
103f02d3 UD |
10231 | } |
10232 | break; | |
76da6bbe | 10233 | |
252b5132 | 10234 | default: |
f7a99963 NC |
10235 | print_vma (entry->d_un.d_ptr, PREFIX_HEX); |
10236 | break; | |
252b5132 | 10237 | } |
35b1837e | 10238 | putchar ('\n'); |
252b5132 RH |
10239 | } |
10240 | ||
28f997cf TG |
10241 | #ifdef BFD64 |
10242 | ||
10243 | /* VMS vs Unix time offset and factor. */ | |
10244 | ||
10245 | #define VMS_EPOCH_OFFSET 35067168000000000LL | |
10246 | #define VMS_GRANULARITY_FACTOR 10000000 | |
dccc31de AM |
10247 | #ifndef INT64_MIN |
10248 | #define INT64_MIN (-9223372036854775807LL - 1) | |
10249 | #endif | |
28f997cf TG |
10250 | |
10251 | /* Display a VMS time in a human readable format. */ | |
10252 | ||
10253 | static void | |
10254 | print_vms_time (bfd_int64_t vmstime) | |
10255 | { | |
dccc31de | 10256 | struct tm *tm = NULL; |
28f997cf TG |
10257 | time_t unxtime; |
10258 | ||
dccc31de AM |
10259 | if (vmstime >= INT64_MIN + VMS_EPOCH_OFFSET) |
10260 | { | |
10261 | vmstime = (vmstime - VMS_EPOCH_OFFSET) / VMS_GRANULARITY_FACTOR; | |
10262 | unxtime = vmstime; | |
10263 | if (unxtime == vmstime) | |
10264 | tm = gmtime (&unxtime); | |
10265 | } | |
10266 | if (tm != NULL) | |
10267 | printf ("%04u-%02u-%02uT%02u:%02u:%02u", | |
10268 | tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, | |
10269 | tm->tm_hour, tm->tm_min, tm->tm_sec); | |
28f997cf TG |
10270 | } |
10271 | #endif /* BFD64 */ | |
10272 | ||
ecc51f48 | 10273 | static void |
2cf0635d | 10274 | dynamic_section_ia64_val (Elf_Internal_Dyn * entry) |
ecc51f48 NC |
10275 | { |
10276 | switch (entry->d_tag) | |
10277 | { | |
0de14b54 | 10278 | case DT_IA_64_PLT_RESERVE: |
bdf4d63a | 10279 | /* First 3 slots reserved. */ |
ecc51f48 NC |
10280 | print_vma (entry->d_un.d_ptr, PREFIX_HEX); |
10281 | printf (" -- "); | |
10282 | print_vma (entry->d_un.d_ptr + (3 * 8), PREFIX_HEX); | |
bdf4d63a JJ |
10283 | break; |
10284 | ||
28f997cf TG |
10285 | case DT_IA_64_VMS_LINKTIME: |
10286 | #ifdef BFD64 | |
10287 | print_vms_time (entry->d_un.d_val); | |
10288 | #endif | |
10289 | break; | |
10290 | ||
10291 | case DT_IA_64_VMS_LNKFLAGS: | |
10292 | print_vma (entry->d_un.d_ptr, PREFIX_HEX); | |
10293 | if (entry->d_un.d_val & VMS_LF_CALL_DEBUG) | |
10294 | printf (" CALL_DEBUG"); | |
10295 | if (entry->d_un.d_val & VMS_LF_NOP0BUFS) | |
10296 | printf (" NOP0BUFS"); | |
10297 | if (entry->d_un.d_val & VMS_LF_P0IMAGE) | |
10298 | printf (" P0IMAGE"); | |
10299 | if (entry->d_un.d_val & VMS_LF_MKTHREADS) | |
10300 | printf (" MKTHREADS"); | |
10301 | if (entry->d_un.d_val & VMS_LF_UPCALLS) | |
10302 | printf (" UPCALLS"); | |
10303 | if (entry->d_un.d_val & VMS_LF_IMGSTA) | |
10304 | printf (" IMGSTA"); | |
10305 | if (entry->d_un.d_val & VMS_LF_INITIALIZE) | |
10306 | printf (" INITIALIZE"); | |
10307 | if (entry->d_un.d_val & VMS_LF_MAIN) | |
10308 | printf (" MAIN"); | |
10309 | if (entry->d_un.d_val & VMS_LF_EXE_INIT) | |
10310 | printf (" EXE_INIT"); | |
10311 | if (entry->d_un.d_val & VMS_LF_TBK_IN_IMG) | |
10312 | printf (" TBK_IN_IMG"); | |
10313 | if (entry->d_un.d_val & VMS_LF_DBG_IN_IMG) | |
10314 | printf (" DBG_IN_IMG"); | |
10315 | if (entry->d_un.d_val & VMS_LF_TBK_IN_DSF) | |
10316 | printf (" TBK_IN_DSF"); | |
10317 | if (entry->d_un.d_val & VMS_LF_DBG_IN_DSF) | |
10318 | printf (" DBG_IN_DSF"); | |
10319 | if (entry->d_un.d_val & VMS_LF_SIGNATURES) | |
10320 | printf (" SIGNATURES"); | |
10321 | if (entry->d_un.d_val & VMS_LF_REL_SEG_OFF) | |
10322 | printf (" REL_SEG_OFF"); | |
10323 | break; | |
10324 | ||
bdf4d63a JJ |
10325 | default: |
10326 | print_vma (entry->d_un.d_ptr, PREFIX_HEX); | |
10327 | break; | |
ecc51f48 | 10328 | } |
bdf4d63a | 10329 | putchar ('\n'); |
ecc51f48 NC |
10330 | } |
10331 | ||
015dc7e1 | 10332 | static bool |
dda8d76d | 10333 | get_32bit_dynamic_section (Filedata * filedata) |
252b5132 | 10334 | { |
2cf0635d NC |
10335 | Elf32_External_Dyn * edyn; |
10336 | Elf32_External_Dyn * ext; | |
10337 | Elf_Internal_Dyn * entry; | |
103f02d3 | 10338 | |
978c4450 AM |
10339 | edyn = (Elf32_External_Dyn *) get_data (NULL, filedata, |
10340 | filedata->dynamic_addr, 1, | |
10341 | filedata->dynamic_size, | |
10342 | _("dynamic section")); | |
a6e9f9df | 10343 | if (!edyn) |
015dc7e1 | 10344 | return false; |
103f02d3 | 10345 | |
071436c6 NC |
10346 | /* SGI's ELF has more than one section in the DYNAMIC segment, and we |
10347 | might not have the luxury of section headers. Look for the DT_NULL | |
10348 | terminator to determine the number of entries. */ | |
978c4450 AM |
10349 | for (ext = edyn, filedata->dynamic_nent = 0; |
10350 | (char *) (ext + 1) <= (char *) edyn + filedata->dynamic_size; | |
ba2685cc AM |
10351 | ext++) |
10352 | { | |
978c4450 | 10353 | filedata->dynamic_nent++; |
ba2685cc AM |
10354 | if (BYTE_GET (ext->d_tag) == DT_NULL) |
10355 | break; | |
10356 | } | |
252b5132 | 10357 | |
978c4450 AM |
10358 | filedata->dynamic_section |
10359 | = (Elf_Internal_Dyn *) cmalloc (filedata->dynamic_nent, sizeof (* entry)); | |
10360 | if (filedata->dynamic_section == NULL) | |
252b5132 | 10361 | { |
8b73c356 | 10362 | error (_("Out of memory allocating space for %lu dynamic entries\n"), |
978c4450 | 10363 | (unsigned long) filedata->dynamic_nent); |
9ea033b2 | 10364 | free (edyn); |
015dc7e1 | 10365 | return false; |
9ea033b2 | 10366 | } |
252b5132 | 10367 | |
978c4450 AM |
10368 | for (ext = edyn, entry = filedata->dynamic_section; |
10369 | entry < filedata->dynamic_section + filedata->dynamic_nent; | |
fb514b26 | 10370 | ext++, entry++) |
9ea033b2 | 10371 | { |
fb514b26 AM |
10372 | entry->d_tag = BYTE_GET (ext->d_tag); |
10373 | entry->d_un.d_val = BYTE_GET (ext->d_un.d_val); | |
252b5132 RH |
10374 | } |
10375 | ||
9ea033b2 NC |
10376 | free (edyn); |
10377 | ||
015dc7e1 | 10378 | return true; |
9ea033b2 NC |
10379 | } |
10380 | ||
015dc7e1 | 10381 | static bool |
dda8d76d | 10382 | get_64bit_dynamic_section (Filedata * filedata) |
9ea033b2 | 10383 | { |
2cf0635d NC |
10384 | Elf64_External_Dyn * edyn; |
10385 | Elf64_External_Dyn * ext; | |
10386 | Elf_Internal_Dyn * entry; | |
103f02d3 | 10387 | |
071436c6 | 10388 | /* Read in the data. */ |
978c4450 AM |
10389 | edyn = (Elf64_External_Dyn *) get_data (NULL, filedata, |
10390 | filedata->dynamic_addr, 1, | |
10391 | filedata->dynamic_size, | |
10392 | _("dynamic section")); | |
a6e9f9df | 10393 | if (!edyn) |
015dc7e1 | 10394 | return false; |
103f02d3 | 10395 | |
071436c6 NC |
10396 | /* SGI's ELF has more than one section in the DYNAMIC segment, and we |
10397 | might not have the luxury of section headers. Look for the DT_NULL | |
10398 | terminator to determine the number of entries. */ | |
978c4450 | 10399 | for (ext = edyn, filedata->dynamic_nent = 0; |
53c3012c | 10400 | /* PR 17533 file: 033-67080-0.004 - do not read past end of buffer. */ |
978c4450 | 10401 | (char *) (ext + 1) <= (char *) edyn + filedata->dynamic_size; |
ba2685cc AM |
10402 | ext++) |
10403 | { | |
978c4450 | 10404 | filedata->dynamic_nent++; |
66543521 | 10405 | if (BYTE_GET (ext->d_tag) == DT_NULL) |
ba2685cc AM |
10406 | break; |
10407 | } | |
252b5132 | 10408 | |
978c4450 AM |
10409 | filedata->dynamic_section |
10410 | = (Elf_Internal_Dyn *) cmalloc (filedata->dynamic_nent, sizeof (* entry)); | |
10411 | if (filedata->dynamic_section == NULL) | |
252b5132 | 10412 | { |
8b73c356 | 10413 | error (_("Out of memory allocating space for %lu dynamic entries\n"), |
978c4450 | 10414 | (unsigned long) filedata->dynamic_nent); |
252b5132 | 10415 | free (edyn); |
015dc7e1 | 10416 | return false; |
252b5132 RH |
10417 | } |
10418 | ||
071436c6 | 10419 | /* Convert from external to internal formats. */ |
978c4450 AM |
10420 | for (ext = edyn, entry = filedata->dynamic_section; |
10421 | entry < filedata->dynamic_section + filedata->dynamic_nent; | |
fb514b26 | 10422 | ext++, entry++) |
252b5132 | 10423 | { |
66543521 AM |
10424 | entry->d_tag = BYTE_GET (ext->d_tag); |
10425 | entry->d_un.d_val = BYTE_GET (ext->d_un.d_val); | |
252b5132 RH |
10426 | } |
10427 | ||
10428 | free (edyn); | |
10429 | ||
015dc7e1 | 10430 | return true; |
9ea033b2 NC |
10431 | } |
10432 | ||
4de91c10 AM |
10433 | static bool |
10434 | get_dynamic_section (Filedata *filedata) | |
10435 | { | |
10436 | if (filedata->dynamic_section) | |
10437 | return true; | |
10438 | ||
10439 | if (is_32bit_elf) | |
10440 | return get_32bit_dynamic_section (filedata); | |
10441 | else | |
10442 | return get_64bit_dynamic_section (filedata); | |
10443 | } | |
10444 | ||
e9e44622 JJ |
10445 | static void |
10446 | print_dynamic_flags (bfd_vma flags) | |
d1133906 | 10447 | { |
015dc7e1 | 10448 | bool first = true; |
13ae64f3 | 10449 | |
d1133906 NC |
10450 | while (flags) |
10451 | { | |
10452 | bfd_vma flag; | |
10453 | ||
10454 | flag = flags & - flags; | |
10455 | flags &= ~ flag; | |
10456 | ||
e9e44622 | 10457 | if (first) |
015dc7e1 | 10458 | first = false; |
e9e44622 JJ |
10459 | else |
10460 | putc (' ', stdout); | |
13ae64f3 | 10461 | |
d1133906 NC |
10462 | switch (flag) |
10463 | { | |
e9e44622 JJ |
10464 | case DF_ORIGIN: fputs ("ORIGIN", stdout); break; |
10465 | case DF_SYMBOLIC: fputs ("SYMBOLIC", stdout); break; | |
10466 | case DF_TEXTREL: fputs ("TEXTREL", stdout); break; | |
10467 | case DF_BIND_NOW: fputs ("BIND_NOW", stdout); break; | |
10468 | case DF_STATIC_TLS: fputs ("STATIC_TLS", stdout); break; | |
2b692964 | 10469 | default: fputs (_("unknown"), stdout); break; |
d1133906 NC |
10470 | } |
10471 | } | |
e9e44622 | 10472 | puts (""); |
d1133906 NC |
10473 | } |
10474 | ||
10ca4b04 L |
10475 | static bfd_vma * |
10476 | get_dynamic_data (Filedata * filedata, bfd_size_type number, unsigned int ent_size) | |
10477 | { | |
10478 | unsigned char * e_data; | |
10479 | bfd_vma * i_data; | |
10480 | ||
10481 | /* If the size_t type is smaller than the bfd_size_type, eg because | |
10482 | you are building a 32-bit tool on a 64-bit host, then make sure | |
10483 | that when (number) is cast to (size_t) no information is lost. */ | |
10484 | if (sizeof (size_t) < sizeof (bfd_size_type) | |
10485 | && (bfd_size_type) ((size_t) number) != number) | |
10486 | { | |
10487 | error (_("Size truncation prevents reading %s elements of size %u\n"), | |
10488 | bfd_vmatoa ("u", number), ent_size); | |
10489 | return NULL; | |
10490 | } | |
10491 | ||
10492 | /* Be kind to memory checkers (eg valgrind, address sanitizer) by not | |
10493 | attempting to allocate memory when the read is bound to fail. */ | |
10494 | if (ent_size * number > filedata->file_size) | |
10495 | { | |
10496 | error (_("Invalid number of dynamic entries: %s\n"), | |
10497 | bfd_vmatoa ("u", number)); | |
10498 | return NULL; | |
10499 | } | |
10500 | ||
10501 | e_data = (unsigned char *) cmalloc ((size_t) number, ent_size); | |
10502 | if (e_data == NULL) | |
10503 | { | |
10504 | error (_("Out of memory reading %s dynamic entries\n"), | |
10505 | bfd_vmatoa ("u", number)); | |
10506 | return NULL; | |
10507 | } | |
10508 | ||
10509 | if (fread (e_data, ent_size, (size_t) number, filedata->handle) != number) | |
10510 | { | |
10511 | error (_("Unable to read in %s bytes of dynamic data\n"), | |
10512 | bfd_vmatoa ("u", number * ent_size)); | |
10513 | free (e_data); | |
10514 | return NULL; | |
10515 | } | |
10516 | ||
10517 | i_data = (bfd_vma *) cmalloc ((size_t) number, sizeof (*i_data)); | |
10518 | if (i_data == NULL) | |
10519 | { | |
10520 | error (_("Out of memory allocating space for %s dynamic entries\n"), | |
10521 | bfd_vmatoa ("u", number)); | |
10522 | free (e_data); | |
10523 | return NULL; | |
10524 | } | |
10525 | ||
10526 | while (number--) | |
10527 | i_data[number] = byte_get (e_data + number * ent_size, ent_size); | |
10528 | ||
10529 | free (e_data); | |
10530 | ||
10531 | return i_data; | |
10532 | } | |
10533 | ||
10534 | static unsigned long | |
10535 | get_num_dynamic_syms (Filedata * filedata) | |
10536 | { | |
10537 | unsigned long num_of_syms = 0; | |
10538 | ||
10539 | if (!do_histogram && (!do_using_dynamic || do_dyn_syms)) | |
10540 | return num_of_syms; | |
10541 | ||
978c4450 | 10542 | if (filedata->dynamic_info[DT_HASH]) |
10ca4b04 L |
10543 | { |
10544 | unsigned char nb[8]; | |
10545 | unsigned char nc[8]; | |
10546 | unsigned int hash_ent_size = 4; | |
10547 | ||
10548 | if ((filedata->file_header.e_machine == EM_ALPHA | |
10549 | || filedata->file_header.e_machine == EM_S390 | |
10550 | || filedata->file_header.e_machine == EM_S390_OLD) | |
10551 | && filedata->file_header.e_ident[EI_CLASS] == ELFCLASS64) | |
10552 | hash_ent_size = 8; | |
10553 | ||
10554 | if (fseek (filedata->handle, | |
978c4450 AM |
10555 | (filedata->archive_file_offset |
10556 | + offset_from_vma (filedata, filedata->dynamic_info[DT_HASH], | |
10ca4b04 L |
10557 | sizeof nb + sizeof nc)), |
10558 | SEEK_SET)) | |
10559 | { | |
10560 | error (_("Unable to seek to start of dynamic information\n")); | |
10561 | goto no_hash; | |
10562 | } | |
10563 | ||
10564 | if (fread (nb, hash_ent_size, 1, filedata->handle) != 1) | |
10565 | { | |
10566 | error (_("Failed to read in number of buckets\n")); | |
10567 | goto no_hash; | |
10568 | } | |
10569 | ||
10570 | if (fread (nc, hash_ent_size, 1, filedata->handle) != 1) | |
10571 | { | |
10572 | error (_("Failed to read in number of chains\n")); | |
10573 | goto no_hash; | |
10574 | } | |
10575 | ||
978c4450 AM |
10576 | filedata->nbuckets = byte_get (nb, hash_ent_size); |
10577 | filedata->nchains = byte_get (nc, hash_ent_size); | |
10ca4b04 | 10578 | |
2482f306 AM |
10579 | if (filedata->nbuckets != 0 && filedata->nchains != 0) |
10580 | { | |
10581 | filedata->buckets = get_dynamic_data (filedata, filedata->nbuckets, | |
10582 | hash_ent_size); | |
10583 | filedata->chains = get_dynamic_data (filedata, filedata->nchains, | |
10584 | hash_ent_size); | |
001890e1 | 10585 | |
2482f306 AM |
10586 | if (filedata->buckets != NULL && filedata->chains != NULL) |
10587 | num_of_syms = filedata->nchains; | |
10588 | } | |
ceb9bf11 | 10589 | no_hash: |
10ca4b04 L |
10590 | if (num_of_syms == 0) |
10591 | { | |
9db70fc3 AM |
10592 | free (filedata->buckets); |
10593 | filedata->buckets = NULL; | |
10594 | free (filedata->chains); | |
10595 | filedata->chains = NULL; | |
978c4450 | 10596 | filedata->nbuckets = 0; |
10ca4b04 L |
10597 | } |
10598 | } | |
10599 | ||
978c4450 | 10600 | if (filedata->dynamic_info_DT_GNU_HASH) |
10ca4b04 L |
10601 | { |
10602 | unsigned char nb[16]; | |
10603 | bfd_vma i, maxchain = 0xffffffff, bitmaskwords; | |
10604 | bfd_vma buckets_vma; | |
10605 | unsigned long hn; | |
10ca4b04 L |
10606 | |
10607 | if (fseek (filedata->handle, | |
978c4450 AM |
10608 | (filedata->archive_file_offset |
10609 | + offset_from_vma (filedata, | |
10610 | filedata->dynamic_info_DT_GNU_HASH, | |
10ca4b04 L |
10611 | sizeof nb)), |
10612 | SEEK_SET)) | |
10613 | { | |
10614 | error (_("Unable to seek to start of dynamic information\n")); | |
10ca4b04 L |
10615 | goto no_gnu_hash; |
10616 | } | |
10617 | ||
10618 | if (fread (nb, 16, 1, filedata->handle) != 1) | |
10619 | { | |
10620 | error (_("Failed to read in number of buckets\n")); | |
10ca4b04 L |
10621 | goto no_gnu_hash; |
10622 | } | |
10623 | ||
978c4450 AM |
10624 | filedata->ngnubuckets = byte_get (nb, 4); |
10625 | filedata->gnusymidx = byte_get (nb + 4, 4); | |
10ca4b04 | 10626 | bitmaskwords = byte_get (nb + 8, 4); |
978c4450 | 10627 | buckets_vma = filedata->dynamic_info_DT_GNU_HASH + 16; |
10ca4b04 L |
10628 | if (is_32bit_elf) |
10629 | buckets_vma += bitmaskwords * 4; | |
10630 | else | |
10631 | buckets_vma += bitmaskwords * 8; | |
10632 | ||
10633 | if (fseek (filedata->handle, | |
978c4450 | 10634 | (filedata->archive_file_offset |
10ca4b04 L |
10635 | + offset_from_vma (filedata, buckets_vma, 4)), |
10636 | SEEK_SET)) | |
10637 | { | |
10638 | error (_("Unable to seek to start of dynamic information\n")); | |
10ca4b04 L |
10639 | goto no_gnu_hash; |
10640 | } | |
10641 | ||
978c4450 AM |
10642 | filedata->gnubuckets |
10643 | = get_dynamic_data (filedata, filedata->ngnubuckets, 4); | |
10ca4b04 | 10644 | |
978c4450 | 10645 | if (filedata->gnubuckets == NULL) |
90837ea7 | 10646 | goto no_gnu_hash; |
10ca4b04 | 10647 | |
978c4450 AM |
10648 | for (i = 0; i < filedata->ngnubuckets; i++) |
10649 | if (filedata->gnubuckets[i] != 0) | |
10ca4b04 | 10650 | { |
978c4450 | 10651 | if (filedata->gnubuckets[i] < filedata->gnusymidx) |
90837ea7 | 10652 | goto no_gnu_hash; |
10ca4b04 | 10653 | |
978c4450 AM |
10654 | if (maxchain == 0xffffffff || filedata->gnubuckets[i] > maxchain) |
10655 | maxchain = filedata->gnubuckets[i]; | |
10ca4b04 L |
10656 | } |
10657 | ||
10658 | if (maxchain == 0xffffffff) | |
90837ea7 | 10659 | goto no_gnu_hash; |
10ca4b04 | 10660 | |
978c4450 | 10661 | maxchain -= filedata->gnusymidx; |
10ca4b04 L |
10662 | |
10663 | if (fseek (filedata->handle, | |
978c4450 AM |
10664 | (filedata->archive_file_offset |
10665 | + offset_from_vma (filedata, | |
10666 | buckets_vma + 4 * (filedata->ngnubuckets | |
10667 | + maxchain), | |
10668 | 4)), | |
10ca4b04 L |
10669 | SEEK_SET)) |
10670 | { | |
10671 | error (_("Unable to seek to start of dynamic information\n")); | |
10ca4b04 L |
10672 | goto no_gnu_hash; |
10673 | } | |
10674 | ||
10675 | do | |
10676 | { | |
10677 | if (fread (nb, 4, 1, filedata->handle) != 1) | |
10678 | { | |
10679 | error (_("Failed to determine last chain length\n")); | |
10ca4b04 L |
10680 | goto no_gnu_hash; |
10681 | } | |
10682 | ||
10683 | if (maxchain + 1 == 0) | |
90837ea7 | 10684 | goto no_gnu_hash; |
10ca4b04 L |
10685 | |
10686 | ++maxchain; | |
10687 | } | |
10688 | while ((byte_get (nb, 4) & 1) == 0); | |
10689 | ||
10690 | if (fseek (filedata->handle, | |
978c4450 AM |
10691 | (filedata->archive_file_offset |
10692 | + offset_from_vma (filedata, (buckets_vma | |
10693 | + 4 * filedata->ngnubuckets), | |
10694 | 4)), | |
10ca4b04 L |
10695 | SEEK_SET)) |
10696 | { | |
10697 | error (_("Unable to seek to start of dynamic information\n")); | |
10ca4b04 L |
10698 | goto no_gnu_hash; |
10699 | } | |
10700 | ||
978c4450 AM |
10701 | filedata->gnuchains = get_dynamic_data (filedata, maxchain, 4); |
10702 | filedata->ngnuchains = maxchain; | |
10ca4b04 | 10703 | |
978c4450 | 10704 | if (filedata->gnuchains == NULL) |
90837ea7 | 10705 | goto no_gnu_hash; |
10ca4b04 | 10706 | |
978c4450 | 10707 | if (filedata->dynamic_info_DT_MIPS_XHASH) |
10ca4b04 L |
10708 | { |
10709 | if (fseek (filedata->handle, | |
978c4450 | 10710 | (filedata->archive_file_offset |
10ca4b04 | 10711 | + offset_from_vma (filedata, (buckets_vma |
978c4450 | 10712 | + 4 * (filedata->ngnubuckets |
10ca4b04 L |
10713 | + maxchain)), 4)), |
10714 | SEEK_SET)) | |
10715 | { | |
10716 | error (_("Unable to seek to start of dynamic information\n")); | |
10ca4b04 L |
10717 | goto no_gnu_hash; |
10718 | } | |
10719 | ||
978c4450 | 10720 | filedata->mipsxlat = get_dynamic_data (filedata, maxchain, 4); |
90837ea7 AM |
10721 | if (filedata->mipsxlat == NULL) |
10722 | goto no_gnu_hash; | |
10ca4b04 L |
10723 | } |
10724 | ||
978c4450 AM |
10725 | for (hn = 0; hn < filedata->ngnubuckets; ++hn) |
10726 | if (filedata->gnubuckets[hn] != 0) | |
10ca4b04 | 10727 | { |
978c4450 AM |
10728 | bfd_vma si = filedata->gnubuckets[hn]; |
10729 | bfd_vma off = si - filedata->gnusymidx; | |
10ca4b04 L |
10730 | |
10731 | do | |
10732 | { | |
978c4450 | 10733 | if (filedata->dynamic_info_DT_MIPS_XHASH) |
10ca4b04 | 10734 | { |
c31ab5a0 AM |
10735 | if (off < filedata->ngnuchains |
10736 | && filedata->mipsxlat[off] >= num_of_syms) | |
978c4450 | 10737 | num_of_syms = filedata->mipsxlat[off] + 1; |
10ca4b04 L |
10738 | } |
10739 | else | |
10740 | { | |
10741 | if (si >= num_of_syms) | |
10742 | num_of_syms = si + 1; | |
10743 | } | |
10744 | si++; | |
10745 | } | |
978c4450 AM |
10746 | while (off < filedata->ngnuchains |
10747 | && (filedata->gnuchains[off++] & 1) == 0); | |
10ca4b04 L |
10748 | } |
10749 | ||
90837ea7 | 10750 | if (num_of_syms == 0) |
10ca4b04 | 10751 | { |
90837ea7 | 10752 | no_gnu_hash: |
9db70fc3 AM |
10753 | free (filedata->mipsxlat); |
10754 | filedata->mipsxlat = NULL; | |
10755 | free (filedata->gnuchains); | |
10756 | filedata->gnuchains = NULL; | |
10757 | free (filedata->gnubuckets); | |
10758 | filedata->gnubuckets = NULL; | |
978c4450 AM |
10759 | filedata->ngnubuckets = 0; |
10760 | filedata->ngnuchains = 0; | |
10ca4b04 L |
10761 | } |
10762 | } | |
10763 | ||
10764 | return num_of_syms; | |
10765 | } | |
10766 | ||
b2d38a17 NC |
10767 | /* Parse and display the contents of the dynamic section. */ |
10768 | ||
015dc7e1 | 10769 | static bool |
dda8d76d | 10770 | process_dynamic_section (Filedata * filedata) |
9ea033b2 | 10771 | { |
2cf0635d | 10772 | Elf_Internal_Dyn * entry; |
9ea033b2 | 10773 | |
93df3340 | 10774 | if (filedata->dynamic_size <= 1) |
9ea033b2 NC |
10775 | { |
10776 | if (do_dynamic) | |
ca0e11aa NC |
10777 | { |
10778 | if (filedata->is_separate) | |
10779 | printf (_("\nThere is no dynamic section in linked file '%s'.\n"), | |
10780 | filedata->file_name); | |
10781 | else | |
10782 | printf (_("\nThere is no dynamic section in this file.\n")); | |
10783 | } | |
9ea033b2 | 10784 | |
015dc7e1 | 10785 | return true; |
9ea033b2 NC |
10786 | } |
10787 | ||
4de91c10 AM |
10788 | if (!get_dynamic_section (filedata)) |
10789 | return false; | |
9ea033b2 | 10790 | |
252b5132 | 10791 | /* Find the appropriate symbol table. */ |
978c4450 | 10792 | if (filedata->dynamic_symbols == NULL || do_histogram) |
252b5132 | 10793 | { |
2482f306 AM |
10794 | unsigned long num_of_syms; |
10795 | ||
978c4450 AM |
10796 | for (entry = filedata->dynamic_section; |
10797 | entry < filedata->dynamic_section + filedata->dynamic_nent; | |
86dba8ee | 10798 | ++entry) |
10ca4b04 | 10799 | if (entry->d_tag == DT_SYMTAB) |
978c4450 | 10800 | filedata->dynamic_info[DT_SYMTAB] = entry->d_un.d_val; |
10ca4b04 | 10801 | else if (entry->d_tag == DT_SYMENT) |
978c4450 | 10802 | filedata->dynamic_info[DT_SYMENT] = entry->d_un.d_val; |
10ca4b04 | 10803 | else if (entry->d_tag == DT_HASH) |
978c4450 | 10804 | filedata->dynamic_info[DT_HASH] = entry->d_un.d_val; |
10ca4b04 | 10805 | else if (entry->d_tag == DT_GNU_HASH) |
978c4450 | 10806 | filedata->dynamic_info_DT_GNU_HASH = entry->d_un.d_val; |
10ca4b04 L |
10807 | else if ((filedata->file_header.e_machine == EM_MIPS |
10808 | || filedata->file_header.e_machine == EM_MIPS_RS3_LE) | |
10809 | && entry->d_tag == DT_MIPS_XHASH) | |
10810 | { | |
978c4450 AM |
10811 | filedata->dynamic_info_DT_MIPS_XHASH = entry->d_un.d_val; |
10812 | filedata->dynamic_info_DT_GNU_HASH = entry->d_un.d_val; | |
10ca4b04 | 10813 | } |
252b5132 | 10814 | |
2482f306 AM |
10815 | num_of_syms = get_num_dynamic_syms (filedata); |
10816 | ||
10817 | if (num_of_syms != 0 | |
10818 | && filedata->dynamic_symbols == NULL | |
10819 | && filedata->dynamic_info[DT_SYMTAB] | |
978c4450 | 10820 | && filedata->dynamic_info[DT_SYMENT]) |
10ca4b04 L |
10821 | { |
10822 | Elf_Internal_Phdr *seg; | |
2482f306 | 10823 | bfd_vma vma = filedata->dynamic_info[DT_SYMTAB]; |
252b5132 | 10824 | |
2482f306 AM |
10825 | if (! get_program_headers (filedata)) |
10826 | { | |
10827 | error (_("Cannot interpret virtual addresses " | |
10828 | "without program headers.\n")); | |
015dc7e1 | 10829 | return false; |
2482f306 | 10830 | } |
252b5132 | 10831 | |
2482f306 AM |
10832 | for (seg = filedata->program_headers; |
10833 | seg < filedata->program_headers + filedata->file_header.e_phnum; | |
10834 | ++seg) | |
10835 | { | |
10836 | if (seg->p_type != PT_LOAD) | |
10837 | continue; | |
252b5132 | 10838 | |
2482f306 AM |
10839 | if (seg->p_offset + seg->p_filesz > filedata->file_size) |
10840 | { | |
10841 | /* See PR 21379 for a reproducer. */ | |
10842 | error (_("Invalid PT_LOAD entry\n")); | |
015dc7e1 | 10843 | return false; |
2482f306 | 10844 | } |
252b5132 | 10845 | |
2482f306 AM |
10846 | if (vma >= (seg->p_vaddr & -seg->p_align) |
10847 | && vma < seg->p_vaddr + seg->p_filesz) | |
10848 | { | |
10849 | /* Since we do not know how big the symbol table is, | |
10850 | we default to reading in up to the end of PT_LOAD | |
10851 | segment and processing that. This is overkill, I | |
10852 | know, but it should work. */ | |
10853 | Elf_Internal_Shdr section; | |
10854 | section.sh_offset = (vma - seg->p_vaddr | |
10855 | + seg->p_offset); | |
10856 | section.sh_size = (num_of_syms | |
10857 | * filedata->dynamic_info[DT_SYMENT]); | |
10858 | section.sh_entsize = filedata->dynamic_info[DT_SYMENT]; | |
8ac10c5b L |
10859 | |
10860 | if (do_checks | |
10861 | && filedata->dynamic_symtab_section != NULL | |
10862 | && ((filedata->dynamic_symtab_section->sh_offset | |
10863 | != section.sh_offset) | |
10864 | || (filedata->dynamic_symtab_section->sh_size | |
10865 | != section.sh_size) | |
10866 | || (filedata->dynamic_symtab_section->sh_entsize | |
10867 | != section.sh_entsize))) | |
10868 | warn (_("\ | |
10869 | the .dynsym section doesn't match the DT_SYMTAB and DT_SYMENT tags\n")); | |
10870 | ||
2482f306 AM |
10871 | section.sh_name = filedata->string_table_length; |
10872 | filedata->dynamic_symbols | |
4de91c10 | 10873 | = get_elf_symbols (filedata, §ion, |
2482f306 AM |
10874 | &filedata->num_dynamic_syms); |
10875 | if (filedata->dynamic_symbols == NULL | |
10876 | || filedata->num_dynamic_syms != num_of_syms) | |
10877 | { | |
10878 | error (_("Corrupt DT_SYMTAB dynamic entry\n")); | |
015dc7e1 | 10879 | return false; |
2482f306 AM |
10880 | } |
10881 | break; | |
10882 | } | |
10883 | } | |
10884 | } | |
10885 | } | |
252b5132 RH |
10886 | |
10887 | /* Similarly find a string table. */ | |
978c4450 AM |
10888 | if (filedata->dynamic_strings == NULL) |
10889 | for (entry = filedata->dynamic_section; | |
10890 | entry < filedata->dynamic_section + filedata->dynamic_nent; | |
10ca4b04 L |
10891 | ++entry) |
10892 | { | |
10893 | if (entry->d_tag == DT_STRTAB) | |
978c4450 | 10894 | filedata->dynamic_info[DT_STRTAB] = entry->d_un.d_val; |
252b5132 | 10895 | |
10ca4b04 | 10896 | if (entry->d_tag == DT_STRSZ) |
978c4450 | 10897 | filedata->dynamic_info[DT_STRSZ] = entry->d_un.d_val; |
252b5132 | 10898 | |
978c4450 AM |
10899 | if (filedata->dynamic_info[DT_STRTAB] |
10900 | && filedata->dynamic_info[DT_STRSZ]) | |
10ca4b04 L |
10901 | { |
10902 | unsigned long offset; | |
978c4450 | 10903 | bfd_size_type str_tab_len = filedata->dynamic_info[DT_STRSZ]; |
10ca4b04 L |
10904 | |
10905 | offset = offset_from_vma (filedata, | |
978c4450 | 10906 | filedata->dynamic_info[DT_STRTAB], |
10ca4b04 | 10907 | str_tab_len); |
8ac10c5b L |
10908 | if (do_checks |
10909 | && filedata->dynamic_strtab_section | |
10910 | && ((filedata->dynamic_strtab_section->sh_offset | |
10911 | != (file_ptr) offset) | |
10912 | || (filedata->dynamic_strtab_section->sh_size | |
10913 | != str_tab_len))) | |
10914 | warn (_("\ | |
10915 | the .dynstr section doesn't match the DT_STRTAB and DT_STRSZ tags\n")); | |
10916 | ||
978c4450 AM |
10917 | filedata->dynamic_strings |
10918 | = (char *) get_data (NULL, filedata, offset, 1, str_tab_len, | |
10919 | _("dynamic string table")); | |
10920 | if (filedata->dynamic_strings == NULL) | |
10ca4b04 L |
10921 | { |
10922 | error (_("Corrupt DT_STRTAB dynamic entry\n")); | |
10923 | break; | |
10924 | } | |
e3d39609 | 10925 | |
978c4450 | 10926 | filedata->dynamic_strings_length = str_tab_len; |
10ca4b04 L |
10927 | break; |
10928 | } | |
10929 | } | |
252b5132 RH |
10930 | |
10931 | /* And find the syminfo section if available. */ | |
978c4450 | 10932 | if (filedata->dynamic_syminfo == NULL) |
252b5132 | 10933 | { |
3e8bba36 | 10934 | unsigned long syminsz = 0; |
252b5132 | 10935 | |
978c4450 AM |
10936 | for (entry = filedata->dynamic_section; |
10937 | entry < filedata->dynamic_section + filedata->dynamic_nent; | |
86dba8ee | 10938 | ++entry) |
252b5132 RH |
10939 | { |
10940 | if (entry->d_tag == DT_SYMINENT) | |
10941 | { | |
10942 | /* Note: these braces are necessary to avoid a syntax | |
10943 | error from the SunOS4 C compiler. */ | |
049b0c3a NC |
10944 | /* PR binutils/17531: A corrupt file can trigger this test. |
10945 | So do not use an assert, instead generate an error message. */ | |
10946 | if (sizeof (Elf_External_Syminfo) != entry->d_un.d_val) | |
071436c6 | 10947 | error (_("Bad value (%d) for SYMINENT entry\n"), |
049b0c3a | 10948 | (int) entry->d_un.d_val); |
252b5132 RH |
10949 | } |
10950 | else if (entry->d_tag == DT_SYMINSZ) | |
10951 | syminsz = entry->d_un.d_val; | |
10952 | else if (entry->d_tag == DT_SYMINFO) | |
978c4450 AM |
10953 | filedata->dynamic_syminfo_offset |
10954 | = offset_from_vma (filedata, entry->d_un.d_val, syminsz); | |
252b5132 RH |
10955 | } |
10956 | ||
978c4450 | 10957 | if (filedata->dynamic_syminfo_offset != 0 && syminsz != 0) |
252b5132 | 10958 | { |
2cf0635d NC |
10959 | Elf_External_Syminfo * extsyminfo; |
10960 | Elf_External_Syminfo * extsym; | |
10961 | Elf_Internal_Syminfo * syminfo; | |
252b5132 RH |
10962 | |
10963 | /* There is a syminfo section. Read the data. */ | |
3f5e193b | 10964 | extsyminfo = (Elf_External_Syminfo *) |
978c4450 AM |
10965 | get_data (NULL, filedata, filedata->dynamic_syminfo_offset, |
10966 | 1, syminsz, _("symbol information")); | |
a6e9f9df | 10967 | if (!extsyminfo) |
015dc7e1 | 10968 | return false; |
252b5132 | 10969 | |
978c4450 | 10970 | if (filedata->dynamic_syminfo != NULL) |
e3d39609 NC |
10971 | { |
10972 | error (_("Multiple dynamic symbol information sections found\n")); | |
978c4450 | 10973 | free (filedata->dynamic_syminfo); |
e3d39609 | 10974 | } |
978c4450 AM |
10975 | filedata->dynamic_syminfo = (Elf_Internal_Syminfo *) malloc (syminsz); |
10976 | if (filedata->dynamic_syminfo == NULL) | |
252b5132 | 10977 | { |
2482f306 AM |
10978 | error (_("Out of memory allocating %lu bytes " |
10979 | "for dynamic symbol info\n"), | |
8b73c356 | 10980 | (unsigned long) syminsz); |
015dc7e1 | 10981 | return false; |
252b5132 RH |
10982 | } |
10983 | ||
2482f306 AM |
10984 | filedata->dynamic_syminfo_nent |
10985 | = syminsz / sizeof (Elf_External_Syminfo); | |
978c4450 | 10986 | for (syminfo = filedata->dynamic_syminfo, extsym = extsyminfo; |
2482f306 AM |
10987 | syminfo < (filedata->dynamic_syminfo |
10988 | + filedata->dynamic_syminfo_nent); | |
86dba8ee | 10989 | ++syminfo, ++extsym) |
252b5132 | 10990 | { |
86dba8ee AM |
10991 | syminfo->si_boundto = BYTE_GET (extsym->si_boundto); |
10992 | syminfo->si_flags = BYTE_GET (extsym->si_flags); | |
252b5132 RH |
10993 | } |
10994 | ||
10995 | free (extsyminfo); | |
10996 | } | |
10997 | } | |
10998 | ||
978c4450 | 10999 | if (do_dynamic && filedata->dynamic_addr) |
ca0e11aa | 11000 | { |
f253158f NC |
11001 | if (filedata->is_separate) |
11002 | printf (ngettext ("\nIn linked file '%s' the dynamic section at offset 0x%lx contains %lu entry:\n", | |
11003 | "\nIn linked file '%s' the dynamic section at offset 0x%lx contains %lu entries:\n", | |
11004 | (unsigned long) filedata->dynamic_nent), | |
11005 | filedata->file_name, | |
11006 | filedata->dynamic_addr, | |
11007 | (unsigned long) filedata->dynamic_nent); | |
ca0e11aa | 11008 | else |
f253158f NC |
11009 | printf (ngettext ("\nDynamic section at offset 0x%lx contains %lu entry:\n", |
11010 | "\nDynamic section at offset 0x%lx contains %lu entries:\n", | |
11011 | (unsigned long) filedata->dynamic_nent), | |
ca0e11aa NC |
11012 | filedata->dynamic_addr, |
11013 | (unsigned long) filedata->dynamic_nent); | |
ca0e11aa | 11014 | } |
252b5132 RH |
11015 | if (do_dynamic) |
11016 | printf (_(" Tag Type Name/Value\n")); | |
11017 | ||
978c4450 AM |
11018 | for (entry = filedata->dynamic_section; |
11019 | entry < filedata->dynamic_section + filedata->dynamic_nent; | |
86dba8ee | 11020 | entry++) |
252b5132 RH |
11021 | { |
11022 | if (do_dynamic) | |
f7a99963 | 11023 | { |
2cf0635d | 11024 | const char * dtype; |
e699b9ff | 11025 | |
f7a99963 NC |
11026 | putchar (' '); |
11027 | print_vma (entry->d_tag, FULL_HEX); | |
dda8d76d | 11028 | dtype = get_dynamic_type (filedata, entry->d_tag); |
e699b9ff | 11029 | printf (" (%s)%*s", dtype, |
32ec8896 | 11030 | ((is_32bit_elf ? 27 : 19) - (int) strlen (dtype)), " "); |
f7a99963 | 11031 | } |
252b5132 RH |
11032 | |
11033 | switch (entry->d_tag) | |
11034 | { | |
d1133906 NC |
11035 | case DT_FLAGS: |
11036 | if (do_dynamic) | |
e9e44622 | 11037 | print_dynamic_flags (entry->d_un.d_val); |
d1133906 | 11038 | break; |
76da6bbe | 11039 | |
252b5132 RH |
11040 | case DT_AUXILIARY: |
11041 | case DT_FILTER: | |
019148e4 L |
11042 | case DT_CONFIG: |
11043 | case DT_DEPAUDIT: | |
11044 | case DT_AUDIT: | |
252b5132 RH |
11045 | if (do_dynamic) |
11046 | { | |
019148e4 | 11047 | switch (entry->d_tag) |
b34976b6 | 11048 | { |
019148e4 L |
11049 | case DT_AUXILIARY: |
11050 | printf (_("Auxiliary library")); | |
11051 | break; | |
11052 | ||
11053 | case DT_FILTER: | |
11054 | printf (_("Filter library")); | |
11055 | break; | |
11056 | ||
b34976b6 | 11057 | case DT_CONFIG: |
019148e4 L |
11058 | printf (_("Configuration file")); |
11059 | break; | |
11060 | ||
11061 | case DT_DEPAUDIT: | |
11062 | printf (_("Dependency audit library")); | |
11063 | break; | |
11064 | ||
11065 | case DT_AUDIT: | |
11066 | printf (_("Audit library")); | |
11067 | break; | |
11068 | } | |
252b5132 | 11069 | |
84714f86 | 11070 | if (valid_dynamic_name (filedata, entry->d_un.d_val)) |
978c4450 | 11071 | printf (": [%s]\n", |
84714f86 | 11072 | get_dynamic_name (filedata, entry->d_un.d_val)); |
252b5132 | 11073 | else |
f7a99963 NC |
11074 | { |
11075 | printf (": "); | |
11076 | print_vma (entry->d_un.d_val, PREFIX_HEX); | |
11077 | putchar ('\n'); | |
11078 | } | |
252b5132 RH |
11079 | } |
11080 | break; | |
11081 | ||
dcefbbbd | 11082 | case DT_FEATURE: |
252b5132 RH |
11083 | if (do_dynamic) |
11084 | { | |
11085 | printf (_("Flags:")); | |
86f55779 | 11086 | |
252b5132 RH |
11087 | if (entry->d_un.d_val == 0) |
11088 | printf (_(" None\n")); | |
11089 | else | |
11090 | { | |
11091 | unsigned long int val = entry->d_un.d_val; | |
86f55779 | 11092 | |
252b5132 RH |
11093 | if (val & DTF_1_PARINIT) |
11094 | { | |
11095 | printf (" PARINIT"); | |
11096 | val ^= DTF_1_PARINIT; | |
11097 | } | |
dcefbbbd L |
11098 | if (val & DTF_1_CONFEXP) |
11099 | { | |
11100 | printf (" CONFEXP"); | |
11101 | val ^= DTF_1_CONFEXP; | |
11102 | } | |
252b5132 RH |
11103 | if (val != 0) |
11104 | printf (" %lx", val); | |
11105 | puts (""); | |
11106 | } | |
11107 | } | |
11108 | break; | |
11109 | ||
11110 | case DT_POSFLAG_1: | |
11111 | if (do_dynamic) | |
11112 | { | |
11113 | printf (_("Flags:")); | |
86f55779 | 11114 | |
252b5132 RH |
11115 | if (entry->d_un.d_val == 0) |
11116 | printf (_(" None\n")); | |
11117 | else | |
11118 | { | |
11119 | unsigned long int val = entry->d_un.d_val; | |
86f55779 | 11120 | |
252b5132 RH |
11121 | if (val & DF_P1_LAZYLOAD) |
11122 | { | |
11123 | printf (" LAZYLOAD"); | |
11124 | val ^= DF_P1_LAZYLOAD; | |
11125 | } | |
11126 | if (val & DF_P1_GROUPPERM) | |
11127 | { | |
11128 | printf (" GROUPPERM"); | |
11129 | val ^= DF_P1_GROUPPERM; | |
11130 | } | |
11131 | if (val != 0) | |
11132 | printf (" %lx", val); | |
11133 | puts (""); | |
11134 | } | |
11135 | } | |
11136 | break; | |
11137 | ||
11138 | case DT_FLAGS_1: | |
11139 | if (do_dynamic) | |
11140 | { | |
11141 | printf (_("Flags:")); | |
11142 | if (entry->d_un.d_val == 0) | |
11143 | printf (_(" None\n")); | |
11144 | else | |
11145 | { | |
11146 | unsigned long int val = entry->d_un.d_val; | |
86f55779 | 11147 | |
252b5132 RH |
11148 | if (val & DF_1_NOW) |
11149 | { | |
11150 | printf (" NOW"); | |
11151 | val ^= DF_1_NOW; | |
11152 | } | |
11153 | if (val & DF_1_GLOBAL) | |
11154 | { | |
11155 | printf (" GLOBAL"); | |
11156 | val ^= DF_1_GLOBAL; | |
11157 | } | |
11158 | if (val & DF_1_GROUP) | |
11159 | { | |
11160 | printf (" GROUP"); | |
11161 | val ^= DF_1_GROUP; | |
11162 | } | |
11163 | if (val & DF_1_NODELETE) | |
11164 | { | |
11165 | printf (" NODELETE"); | |
11166 | val ^= DF_1_NODELETE; | |
11167 | } | |
11168 | if (val & DF_1_LOADFLTR) | |
11169 | { | |
11170 | printf (" LOADFLTR"); | |
11171 | val ^= DF_1_LOADFLTR; | |
11172 | } | |
11173 | if (val & DF_1_INITFIRST) | |
11174 | { | |
11175 | printf (" INITFIRST"); | |
11176 | val ^= DF_1_INITFIRST; | |
11177 | } | |
11178 | if (val & DF_1_NOOPEN) | |
11179 | { | |
11180 | printf (" NOOPEN"); | |
11181 | val ^= DF_1_NOOPEN; | |
11182 | } | |
11183 | if (val & DF_1_ORIGIN) | |
11184 | { | |
11185 | printf (" ORIGIN"); | |
11186 | val ^= DF_1_ORIGIN; | |
11187 | } | |
11188 | if (val & DF_1_DIRECT) | |
11189 | { | |
11190 | printf (" DIRECT"); | |
11191 | val ^= DF_1_DIRECT; | |
11192 | } | |
11193 | if (val & DF_1_TRANS) | |
11194 | { | |
11195 | printf (" TRANS"); | |
11196 | val ^= DF_1_TRANS; | |
11197 | } | |
11198 | if (val & DF_1_INTERPOSE) | |
11199 | { | |
11200 | printf (" INTERPOSE"); | |
11201 | val ^= DF_1_INTERPOSE; | |
11202 | } | |
f7db6139 | 11203 | if (val & DF_1_NODEFLIB) |
dcefbbbd | 11204 | { |
f7db6139 L |
11205 | printf (" NODEFLIB"); |
11206 | val ^= DF_1_NODEFLIB; | |
dcefbbbd L |
11207 | } |
11208 | if (val & DF_1_NODUMP) | |
11209 | { | |
11210 | printf (" NODUMP"); | |
11211 | val ^= DF_1_NODUMP; | |
11212 | } | |
34b60028 | 11213 | if (val & DF_1_CONFALT) |
dcefbbbd | 11214 | { |
34b60028 L |
11215 | printf (" CONFALT"); |
11216 | val ^= DF_1_CONFALT; | |
11217 | } | |
11218 | if (val & DF_1_ENDFILTEE) | |
11219 | { | |
11220 | printf (" ENDFILTEE"); | |
11221 | val ^= DF_1_ENDFILTEE; | |
11222 | } | |
11223 | if (val & DF_1_DISPRELDNE) | |
11224 | { | |
11225 | printf (" DISPRELDNE"); | |
11226 | val ^= DF_1_DISPRELDNE; | |
11227 | } | |
11228 | if (val & DF_1_DISPRELPND) | |
11229 | { | |
11230 | printf (" DISPRELPND"); | |
11231 | val ^= DF_1_DISPRELPND; | |
11232 | } | |
11233 | if (val & DF_1_NODIRECT) | |
11234 | { | |
11235 | printf (" NODIRECT"); | |
11236 | val ^= DF_1_NODIRECT; | |
11237 | } | |
11238 | if (val & DF_1_IGNMULDEF) | |
11239 | { | |
11240 | printf (" IGNMULDEF"); | |
11241 | val ^= DF_1_IGNMULDEF; | |
11242 | } | |
11243 | if (val & DF_1_NOKSYMS) | |
11244 | { | |
11245 | printf (" NOKSYMS"); | |
11246 | val ^= DF_1_NOKSYMS; | |
11247 | } | |
11248 | if (val & DF_1_NOHDR) | |
11249 | { | |
11250 | printf (" NOHDR"); | |
11251 | val ^= DF_1_NOHDR; | |
11252 | } | |
11253 | if (val & DF_1_EDITED) | |
11254 | { | |
11255 | printf (" EDITED"); | |
11256 | val ^= DF_1_EDITED; | |
11257 | } | |
11258 | if (val & DF_1_NORELOC) | |
11259 | { | |
11260 | printf (" NORELOC"); | |
11261 | val ^= DF_1_NORELOC; | |
11262 | } | |
11263 | if (val & DF_1_SYMINTPOSE) | |
11264 | { | |
11265 | printf (" SYMINTPOSE"); | |
11266 | val ^= DF_1_SYMINTPOSE; | |
11267 | } | |
11268 | if (val & DF_1_GLOBAUDIT) | |
11269 | { | |
11270 | printf (" GLOBAUDIT"); | |
11271 | val ^= DF_1_GLOBAUDIT; | |
11272 | } | |
11273 | if (val & DF_1_SINGLETON) | |
11274 | { | |
11275 | printf (" SINGLETON"); | |
11276 | val ^= DF_1_SINGLETON; | |
dcefbbbd | 11277 | } |
5c383f02 RO |
11278 | if (val & DF_1_STUB) |
11279 | { | |
11280 | printf (" STUB"); | |
11281 | val ^= DF_1_STUB; | |
11282 | } | |
11283 | if (val & DF_1_PIE) | |
11284 | { | |
11285 | printf (" PIE"); | |
11286 | val ^= DF_1_PIE; | |
11287 | } | |
b1202ffa L |
11288 | if (val & DF_1_KMOD) |
11289 | { | |
11290 | printf (" KMOD"); | |
11291 | val ^= DF_1_KMOD; | |
11292 | } | |
11293 | if (val & DF_1_WEAKFILTER) | |
11294 | { | |
11295 | printf (" WEAKFILTER"); | |
11296 | val ^= DF_1_WEAKFILTER; | |
11297 | } | |
11298 | if (val & DF_1_NOCOMMON) | |
11299 | { | |
11300 | printf (" NOCOMMON"); | |
11301 | val ^= DF_1_NOCOMMON; | |
11302 | } | |
252b5132 RH |
11303 | if (val != 0) |
11304 | printf (" %lx", val); | |
11305 | puts (""); | |
11306 | } | |
11307 | } | |
11308 | break; | |
11309 | ||
11310 | case DT_PLTREL: | |
978c4450 | 11311 | filedata->dynamic_info[entry->d_tag] = entry->d_un.d_val; |
252b5132 | 11312 | if (do_dynamic) |
dda8d76d | 11313 | puts (get_dynamic_type (filedata, entry->d_un.d_val)); |
252b5132 RH |
11314 | break; |
11315 | ||
11316 | case DT_NULL : | |
11317 | case DT_NEEDED : | |
11318 | case DT_PLTGOT : | |
11319 | case DT_HASH : | |
11320 | case DT_STRTAB : | |
11321 | case DT_SYMTAB : | |
11322 | case DT_RELA : | |
11323 | case DT_INIT : | |
11324 | case DT_FINI : | |
11325 | case DT_SONAME : | |
11326 | case DT_RPATH : | |
11327 | case DT_SYMBOLIC: | |
11328 | case DT_REL : | |
11329 | case DT_DEBUG : | |
11330 | case DT_TEXTREL : | |
11331 | case DT_JMPREL : | |
019148e4 | 11332 | case DT_RUNPATH : |
978c4450 | 11333 | filedata->dynamic_info[entry->d_tag] = entry->d_un.d_val; |
252b5132 RH |
11334 | |
11335 | if (do_dynamic) | |
11336 | { | |
84714f86 | 11337 | const char *name; |
252b5132 | 11338 | |
84714f86 AM |
11339 | if (valid_dynamic_name (filedata, entry->d_un.d_val)) |
11340 | name = get_dynamic_name (filedata, entry->d_un.d_val); | |
252b5132 | 11341 | else |
d79b3d50 | 11342 | name = NULL; |
252b5132 RH |
11343 | |
11344 | if (name) | |
11345 | { | |
11346 | switch (entry->d_tag) | |
11347 | { | |
11348 | case DT_NEEDED: | |
11349 | printf (_("Shared library: [%s]"), name); | |
11350 | ||
13acb58d AM |
11351 | if (filedata->program_interpreter |
11352 | && streq (name, filedata->program_interpreter)) | |
f7a99963 | 11353 | printf (_(" program interpreter")); |
252b5132 RH |
11354 | break; |
11355 | ||
11356 | case DT_SONAME: | |
f7a99963 | 11357 | printf (_("Library soname: [%s]"), name); |
252b5132 RH |
11358 | break; |
11359 | ||
11360 | case DT_RPATH: | |
f7a99963 | 11361 | printf (_("Library rpath: [%s]"), name); |
252b5132 RH |
11362 | break; |
11363 | ||
019148e4 L |
11364 | case DT_RUNPATH: |
11365 | printf (_("Library runpath: [%s]"), name); | |
11366 | break; | |
11367 | ||
252b5132 | 11368 | default: |
f7a99963 NC |
11369 | print_vma (entry->d_un.d_val, PREFIX_HEX); |
11370 | break; | |
252b5132 RH |
11371 | } |
11372 | } | |
11373 | else | |
f7a99963 NC |
11374 | print_vma (entry->d_un.d_val, PREFIX_HEX); |
11375 | ||
11376 | putchar ('\n'); | |
252b5132 RH |
11377 | } |
11378 | break; | |
11379 | ||
11380 | case DT_PLTRELSZ: | |
11381 | case DT_RELASZ : | |
11382 | case DT_STRSZ : | |
11383 | case DT_RELSZ : | |
11384 | case DT_RELAENT : | |
11385 | case DT_SYMENT : | |
11386 | case DT_RELENT : | |
978c4450 | 11387 | filedata->dynamic_info[entry->d_tag] = entry->d_un.d_val; |
1a0670f3 | 11388 | /* Fall through. */ |
252b5132 RH |
11389 | case DT_PLTPADSZ: |
11390 | case DT_MOVEENT : | |
11391 | case DT_MOVESZ : | |
dd207c13 FS |
11392 | case DT_RELRENT : |
11393 | case DT_RELRSZ : | |
04d8355a | 11394 | case DT_PREINIT_ARRAYSZ: |
252b5132 RH |
11395 | case DT_INIT_ARRAYSZ: |
11396 | case DT_FINI_ARRAYSZ: | |
047b2264 JJ |
11397 | case DT_GNU_CONFLICTSZ: |
11398 | case DT_GNU_LIBLISTSZ: | |
252b5132 | 11399 | if (do_dynamic) |
f7a99963 NC |
11400 | { |
11401 | print_vma (entry->d_un.d_val, UNSIGNED); | |
2b692964 | 11402 | printf (_(" (bytes)\n")); |
f7a99963 | 11403 | } |
252b5132 RH |
11404 | break; |
11405 | ||
11406 | case DT_VERDEFNUM: | |
11407 | case DT_VERNEEDNUM: | |
11408 | case DT_RELACOUNT: | |
11409 | case DT_RELCOUNT: | |
11410 | if (do_dynamic) | |
f7a99963 NC |
11411 | { |
11412 | print_vma (entry->d_un.d_val, UNSIGNED); | |
11413 | putchar ('\n'); | |
11414 | } | |
252b5132 RH |
11415 | break; |
11416 | ||
11417 | case DT_SYMINSZ: | |
11418 | case DT_SYMINENT: | |
11419 | case DT_SYMINFO: | |
11420 | case DT_USED: | |
11421 | case DT_INIT_ARRAY: | |
11422 | case DT_FINI_ARRAY: | |
11423 | if (do_dynamic) | |
11424 | { | |
d79b3d50 | 11425 | if (entry->d_tag == DT_USED |
84714f86 | 11426 | && valid_dynamic_name (filedata, entry->d_un.d_val)) |
252b5132 | 11427 | { |
84714f86 AM |
11428 | const char *name |
11429 | = get_dynamic_name (filedata, entry->d_un.d_val); | |
252b5132 | 11430 | |
b34976b6 | 11431 | if (*name) |
252b5132 RH |
11432 | { |
11433 | printf (_("Not needed object: [%s]\n"), name); | |
11434 | break; | |
11435 | } | |
11436 | } | |
103f02d3 | 11437 | |
f7a99963 NC |
11438 | print_vma (entry->d_un.d_val, PREFIX_HEX); |
11439 | putchar ('\n'); | |
252b5132 RH |
11440 | } |
11441 | break; | |
11442 | ||
11443 | case DT_BIND_NOW: | |
11444 | /* The value of this entry is ignored. */ | |
35b1837e AM |
11445 | if (do_dynamic) |
11446 | putchar ('\n'); | |
252b5132 | 11447 | break; |
103f02d3 | 11448 | |
047b2264 JJ |
11449 | case DT_GNU_PRELINKED: |
11450 | if (do_dynamic) | |
11451 | { | |
2cf0635d | 11452 | struct tm * tmp; |
91d6fa6a | 11453 | time_t atime = entry->d_un.d_val; |
047b2264 | 11454 | |
91d6fa6a | 11455 | tmp = gmtime (&atime); |
071436c6 NC |
11456 | /* PR 17533 file: 041-1244816-0.004. */ |
11457 | if (tmp == NULL) | |
5a2cbcf4 L |
11458 | printf (_("<corrupt time val: %lx"), |
11459 | (unsigned long) atime); | |
071436c6 NC |
11460 | else |
11461 | printf ("%04u-%02u-%02uT%02u:%02u:%02u\n", | |
11462 | tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday, | |
11463 | tmp->tm_hour, tmp->tm_min, tmp->tm_sec); | |
047b2264 JJ |
11464 | |
11465 | } | |
11466 | break; | |
11467 | ||
fdc90cb4 | 11468 | case DT_GNU_HASH: |
978c4450 | 11469 | filedata->dynamic_info_DT_GNU_HASH = entry->d_un.d_val; |
fdc90cb4 JJ |
11470 | if (do_dynamic) |
11471 | { | |
11472 | print_vma (entry->d_un.d_val, PREFIX_HEX); | |
11473 | putchar ('\n'); | |
11474 | } | |
11475 | break; | |
11476 | ||
a5da3dee VDM |
11477 | case DT_GNU_FLAGS_1: |
11478 | if (do_dynamic) | |
11479 | { | |
11480 | printf (_("Flags:")); | |
11481 | if (entry->d_un.d_val == 0) | |
11482 | printf (_(" None\n")); | |
11483 | else | |
11484 | { | |
11485 | unsigned long int val = entry->d_un.d_val; | |
11486 | ||
11487 | if (val & DF_GNU_1_UNIQUE) | |
11488 | { | |
11489 | printf (" UNIQUE"); | |
11490 | val ^= DF_GNU_1_UNIQUE; | |
11491 | } | |
11492 | if (val != 0) | |
11493 | printf (" %lx", val); | |
11494 | puts (""); | |
11495 | } | |
11496 | } | |
11497 | break; | |
11498 | ||
252b5132 RH |
11499 | default: |
11500 | if ((entry->d_tag >= DT_VERSYM) && (entry->d_tag <= DT_VERNEEDNUM)) | |
978c4450 AM |
11501 | filedata->version_info[DT_VERSIONTAGIDX (entry->d_tag)] |
11502 | = entry->d_un.d_val; | |
252b5132 RH |
11503 | |
11504 | if (do_dynamic) | |
11505 | { | |
dda8d76d | 11506 | switch (filedata->file_header.e_machine) |
252b5132 | 11507 | { |
37c18eed SD |
11508 | case EM_AARCH64: |
11509 | dynamic_section_aarch64_val (entry); | |
11510 | break; | |
252b5132 | 11511 | case EM_MIPS: |
4fe85591 | 11512 | case EM_MIPS_RS3_LE: |
978c4450 | 11513 | dynamic_section_mips_val (filedata, entry); |
252b5132 | 11514 | break; |
103f02d3 | 11515 | case EM_PARISC: |
b2d38a17 | 11516 | dynamic_section_parisc_val (entry); |
103f02d3 | 11517 | break; |
ecc51f48 | 11518 | case EM_IA_64: |
b2d38a17 | 11519 | dynamic_section_ia64_val (entry); |
ecc51f48 | 11520 | break; |
252b5132 | 11521 | default: |
f7a99963 NC |
11522 | print_vma (entry->d_un.d_val, PREFIX_HEX); |
11523 | putchar ('\n'); | |
252b5132 RH |
11524 | } |
11525 | } | |
11526 | break; | |
11527 | } | |
11528 | } | |
11529 | ||
015dc7e1 | 11530 | return true; |
252b5132 RH |
11531 | } |
11532 | ||
11533 | static char * | |
d3ba0551 | 11534 | get_ver_flags (unsigned int flags) |
252b5132 | 11535 | { |
6d4f21f6 | 11536 | static char buff[128]; |
252b5132 RH |
11537 | |
11538 | buff[0] = 0; | |
11539 | ||
11540 | if (flags == 0) | |
11541 | return _("none"); | |
11542 | ||
11543 | if (flags & VER_FLG_BASE) | |
7bb1ad17 | 11544 | strcat (buff, "BASE"); |
252b5132 RH |
11545 | |
11546 | if (flags & VER_FLG_WEAK) | |
11547 | { | |
11548 | if (flags & VER_FLG_BASE) | |
7bb1ad17 | 11549 | strcat (buff, " | "); |
252b5132 | 11550 | |
7bb1ad17 | 11551 | strcat (buff, "WEAK"); |
252b5132 RH |
11552 | } |
11553 | ||
44ec90b9 RO |
11554 | if (flags & VER_FLG_INFO) |
11555 | { | |
11556 | if (flags & (VER_FLG_BASE|VER_FLG_WEAK)) | |
7bb1ad17 | 11557 | strcat (buff, " | "); |
44ec90b9 | 11558 | |
7bb1ad17 | 11559 | strcat (buff, "INFO"); |
44ec90b9 RO |
11560 | } |
11561 | ||
11562 | if (flags & ~(VER_FLG_BASE | VER_FLG_WEAK | VER_FLG_INFO)) | |
7bb1ad17 MR |
11563 | { |
11564 | if (flags & (VER_FLG_BASE | VER_FLG_WEAK | VER_FLG_INFO)) | |
11565 | strcat (buff, " | "); | |
11566 | ||
11567 | strcat (buff, _("<unknown>")); | |
11568 | } | |
252b5132 RH |
11569 | |
11570 | return buff; | |
11571 | } | |
11572 | ||
11573 | /* Display the contents of the version sections. */ | |
98fb390a | 11574 | |
015dc7e1 | 11575 | static bool |
dda8d76d | 11576 | process_version_sections (Filedata * filedata) |
252b5132 | 11577 | { |
2cf0635d | 11578 | Elf_Internal_Shdr * section; |
b34976b6 | 11579 | unsigned i; |
015dc7e1 | 11580 | bool found = false; |
252b5132 RH |
11581 | |
11582 | if (! do_version) | |
015dc7e1 | 11583 | return true; |
252b5132 | 11584 | |
dda8d76d NC |
11585 | for (i = 0, section = filedata->section_headers; |
11586 | i < filedata->file_header.e_shnum; | |
b34976b6 | 11587 | i++, section++) |
252b5132 RH |
11588 | { |
11589 | switch (section->sh_type) | |
11590 | { | |
11591 | case SHT_GNU_verdef: | |
11592 | { | |
2cf0635d | 11593 | Elf_External_Verdef * edefs; |
452bf675 AM |
11594 | unsigned long idx; |
11595 | unsigned long cnt; | |
2cf0635d | 11596 | char * endbuf; |
252b5132 | 11597 | |
015dc7e1 | 11598 | found = true; |
252b5132 | 11599 | |
ca0e11aa NC |
11600 | if (filedata->is_separate) |
11601 | printf (ngettext ("\nIn linked file '%s' the version definition section '%s' contains %u entry:\n", | |
11602 | "\nIn linked file '%s' the version definition section '%s' contains %u entries:\n", | |
11603 | section->sh_info), | |
11604 | filedata->file_name, | |
11605 | printable_section_name (filedata, section), | |
11606 | section->sh_info); | |
11607 | else | |
11608 | printf (ngettext ("\nVersion definition section '%s' " | |
11609 | "contains %u entry:\n", | |
11610 | "\nVersion definition section '%s' " | |
11611 | "contains %u entries:\n", | |
11612 | section->sh_info), | |
11613 | printable_section_name (filedata, section), | |
11614 | section->sh_info); | |
047c3dbf | 11615 | |
ae9ac79e | 11616 | printf (_(" Addr: 0x")); |
252b5132 | 11617 | printf_vma (section->sh_addr); |
233f82cf | 11618 | printf (_(" Offset: %#08lx Link: %u (%s)\n"), |
1b228002 | 11619 | (unsigned long) section->sh_offset, section->sh_link, |
dda8d76d | 11620 | printable_section_name_from_index (filedata, section->sh_link)); |
252b5132 | 11621 | |
3f5e193b | 11622 | edefs = (Elf_External_Verdef *) |
dda8d76d | 11623 | get_data (NULL, filedata, section->sh_offset, 1,section->sh_size, |
3f5e193b | 11624 | _("version definition section")); |
a6e9f9df AM |
11625 | if (!edefs) |
11626 | break; | |
59245841 | 11627 | endbuf = (char *) edefs + section->sh_size; |
252b5132 | 11628 | |
1445030f | 11629 | for (idx = cnt = 0; cnt < section->sh_info; ++cnt) |
252b5132 | 11630 | { |
2cf0635d NC |
11631 | char * vstart; |
11632 | Elf_External_Verdef * edef; | |
b34976b6 | 11633 | Elf_Internal_Verdef ent; |
2cf0635d | 11634 | Elf_External_Verdaux * eaux; |
b34976b6 | 11635 | Elf_Internal_Verdaux aux; |
452bf675 | 11636 | unsigned long isum; |
b34976b6 | 11637 | int j; |
103f02d3 | 11638 | |
252b5132 | 11639 | vstart = ((char *) edefs) + idx; |
54806181 AM |
11640 | if (vstart + sizeof (*edef) > endbuf) |
11641 | break; | |
252b5132 RH |
11642 | |
11643 | edef = (Elf_External_Verdef *) vstart; | |
11644 | ||
11645 | ent.vd_version = BYTE_GET (edef->vd_version); | |
11646 | ent.vd_flags = BYTE_GET (edef->vd_flags); | |
11647 | ent.vd_ndx = BYTE_GET (edef->vd_ndx); | |
11648 | ent.vd_cnt = BYTE_GET (edef->vd_cnt); | |
11649 | ent.vd_hash = BYTE_GET (edef->vd_hash); | |
11650 | ent.vd_aux = BYTE_GET (edef->vd_aux); | |
11651 | ent.vd_next = BYTE_GET (edef->vd_next); | |
11652 | ||
452bf675 | 11653 | printf (_(" %#06lx: Rev: %d Flags: %s"), |
252b5132 RH |
11654 | idx, ent.vd_version, get_ver_flags (ent.vd_flags)); |
11655 | ||
11656 | printf (_(" Index: %d Cnt: %d "), | |
11657 | ent.vd_ndx, ent.vd_cnt); | |
11658 | ||
452bf675 | 11659 | /* Check for overflow. */ |
1445030f | 11660 | if (ent.vd_aux > (size_t) (endbuf - vstart)) |
dd24e3da NC |
11661 | break; |
11662 | ||
252b5132 RH |
11663 | vstart += ent.vd_aux; |
11664 | ||
1445030f AM |
11665 | if (vstart + sizeof (*eaux) > endbuf) |
11666 | break; | |
252b5132 RH |
11667 | eaux = (Elf_External_Verdaux *) vstart; |
11668 | ||
11669 | aux.vda_name = BYTE_GET (eaux->vda_name); | |
11670 | aux.vda_next = BYTE_GET (eaux->vda_next); | |
11671 | ||
84714f86 | 11672 | if (valid_dynamic_name (filedata, aux.vda_name)) |
978c4450 | 11673 | printf (_("Name: %s\n"), |
84714f86 | 11674 | get_dynamic_name (filedata, aux.vda_name)); |
252b5132 RH |
11675 | else |
11676 | printf (_("Name index: %ld\n"), aux.vda_name); | |
11677 | ||
11678 | isum = idx + ent.vd_aux; | |
11679 | ||
b34976b6 | 11680 | for (j = 1; j < ent.vd_cnt; j++) |
252b5132 | 11681 | { |
1445030f AM |
11682 | if (aux.vda_next < sizeof (*eaux) |
11683 | && !(j == ent.vd_cnt - 1 && aux.vda_next == 0)) | |
11684 | { | |
11685 | warn (_("Invalid vda_next field of %lx\n"), | |
11686 | aux.vda_next); | |
11687 | j = ent.vd_cnt; | |
11688 | break; | |
11689 | } | |
dd24e3da | 11690 | /* Check for overflow. */ |
7e26601c | 11691 | if (aux.vda_next > (size_t) (endbuf - vstart)) |
dd24e3da NC |
11692 | break; |
11693 | ||
252b5132 RH |
11694 | isum += aux.vda_next; |
11695 | vstart += aux.vda_next; | |
11696 | ||
54806181 AM |
11697 | if (vstart + sizeof (*eaux) > endbuf) |
11698 | break; | |
1445030f | 11699 | eaux = (Elf_External_Verdaux *) vstart; |
252b5132 RH |
11700 | |
11701 | aux.vda_name = BYTE_GET (eaux->vda_name); | |
11702 | aux.vda_next = BYTE_GET (eaux->vda_next); | |
11703 | ||
84714f86 | 11704 | if (valid_dynamic_name (filedata, aux.vda_name)) |
452bf675 | 11705 | printf (_(" %#06lx: Parent %d: %s\n"), |
978c4450 | 11706 | isum, j, |
84714f86 | 11707 | get_dynamic_name (filedata, aux.vda_name)); |
252b5132 | 11708 | else |
452bf675 | 11709 | printf (_(" %#06lx: Parent %d, name index: %ld\n"), |
252b5132 RH |
11710 | isum, j, aux.vda_name); |
11711 | } | |
dd24e3da | 11712 | |
54806181 AM |
11713 | if (j < ent.vd_cnt) |
11714 | printf (_(" Version def aux past end of section\n")); | |
252b5132 | 11715 | |
c9f02c3e MR |
11716 | /* PR 17531: |
11717 | file: id:000001,src:000172+005151,op:splice,rep:2. */ | |
1445030f AM |
11718 | if (ent.vd_next < sizeof (*edef) |
11719 | && !(cnt == section->sh_info - 1 && ent.vd_next == 0)) | |
11720 | { | |
11721 | warn (_("Invalid vd_next field of %lx\n"), ent.vd_next); | |
11722 | cnt = section->sh_info; | |
11723 | break; | |
11724 | } | |
452bf675 | 11725 | if (ent.vd_next > (size_t) (endbuf - ((char *) edefs + idx))) |
5d921cbd NC |
11726 | break; |
11727 | ||
252b5132 RH |
11728 | idx += ent.vd_next; |
11729 | } | |
dd24e3da | 11730 | |
54806181 AM |
11731 | if (cnt < section->sh_info) |
11732 | printf (_(" Version definition past end of section\n")); | |
252b5132 RH |
11733 | |
11734 | free (edefs); | |
11735 | } | |
11736 | break; | |
103f02d3 | 11737 | |
252b5132 RH |
11738 | case SHT_GNU_verneed: |
11739 | { | |
2cf0635d | 11740 | Elf_External_Verneed * eneed; |
452bf675 AM |
11741 | unsigned long idx; |
11742 | unsigned long cnt; | |
2cf0635d | 11743 | char * endbuf; |
252b5132 | 11744 | |
015dc7e1 | 11745 | found = true; |
252b5132 | 11746 | |
ca0e11aa NC |
11747 | if (filedata->is_separate) |
11748 | printf (ngettext ("\nIn linked file '%s' the version needs section '%s' contains %u entry:\n", | |
11749 | "\nIn linked file '%s' the version needs section '%s' contains %u entries:\n", | |
11750 | section->sh_info), | |
11751 | filedata->file_name, | |
11752 | printable_section_name (filedata, section), | |
11753 | section->sh_info); | |
11754 | else | |
11755 | printf (ngettext ("\nVersion needs section '%s' " | |
11756 | "contains %u entry:\n", | |
11757 | "\nVersion needs section '%s' " | |
11758 | "contains %u entries:\n", | |
11759 | section->sh_info), | |
11760 | printable_section_name (filedata, section), | |
11761 | section->sh_info); | |
047c3dbf | 11762 | |
252b5132 RH |
11763 | printf (_(" Addr: 0x")); |
11764 | printf_vma (section->sh_addr); | |
72de5009 | 11765 | printf (_(" Offset: %#08lx Link: %u (%s)\n"), |
1b228002 | 11766 | (unsigned long) section->sh_offset, section->sh_link, |
dda8d76d | 11767 | printable_section_name_from_index (filedata, section->sh_link)); |
252b5132 | 11768 | |
dda8d76d | 11769 | eneed = (Elf_External_Verneed *) get_data (NULL, filedata, |
3f5e193b NC |
11770 | section->sh_offset, 1, |
11771 | section->sh_size, | |
9cf03b7e | 11772 | _("Version Needs section")); |
a6e9f9df AM |
11773 | if (!eneed) |
11774 | break; | |
59245841 | 11775 | endbuf = (char *) eneed + section->sh_size; |
252b5132 RH |
11776 | |
11777 | for (idx = cnt = 0; cnt < section->sh_info; ++cnt) | |
11778 | { | |
2cf0635d | 11779 | Elf_External_Verneed * entry; |
b34976b6 | 11780 | Elf_Internal_Verneed ent; |
452bf675 | 11781 | unsigned long isum; |
b34976b6 | 11782 | int j; |
2cf0635d | 11783 | char * vstart; |
252b5132 RH |
11784 | |
11785 | vstart = ((char *) eneed) + idx; | |
54806181 AM |
11786 | if (vstart + sizeof (*entry) > endbuf) |
11787 | break; | |
252b5132 RH |
11788 | |
11789 | entry = (Elf_External_Verneed *) vstart; | |
11790 | ||
11791 | ent.vn_version = BYTE_GET (entry->vn_version); | |
11792 | ent.vn_cnt = BYTE_GET (entry->vn_cnt); | |
11793 | ent.vn_file = BYTE_GET (entry->vn_file); | |
11794 | ent.vn_aux = BYTE_GET (entry->vn_aux); | |
11795 | ent.vn_next = BYTE_GET (entry->vn_next); | |
11796 | ||
452bf675 | 11797 | printf (_(" %#06lx: Version: %d"), idx, ent.vn_version); |
252b5132 | 11798 | |
84714f86 | 11799 | if (valid_dynamic_name (filedata, ent.vn_file)) |
978c4450 | 11800 | printf (_(" File: %s"), |
84714f86 | 11801 | get_dynamic_name (filedata, ent.vn_file)); |
252b5132 RH |
11802 | else |
11803 | printf (_(" File: %lx"), ent.vn_file); | |
11804 | ||
11805 | printf (_(" Cnt: %d\n"), ent.vn_cnt); | |
11806 | ||
dd24e3da | 11807 | /* Check for overflow. */ |
7e26601c | 11808 | if (ent.vn_aux > (size_t) (endbuf - vstart)) |
dd24e3da | 11809 | break; |
252b5132 RH |
11810 | vstart += ent.vn_aux; |
11811 | ||
11812 | for (j = 0, isum = idx + ent.vn_aux; j < ent.vn_cnt; ++j) | |
11813 | { | |
2cf0635d | 11814 | Elf_External_Vernaux * eaux; |
b34976b6 | 11815 | Elf_Internal_Vernaux aux; |
252b5132 | 11816 | |
54806181 AM |
11817 | if (vstart + sizeof (*eaux) > endbuf) |
11818 | break; | |
252b5132 RH |
11819 | eaux = (Elf_External_Vernaux *) vstart; |
11820 | ||
11821 | aux.vna_hash = BYTE_GET (eaux->vna_hash); | |
11822 | aux.vna_flags = BYTE_GET (eaux->vna_flags); | |
11823 | aux.vna_other = BYTE_GET (eaux->vna_other); | |
11824 | aux.vna_name = BYTE_GET (eaux->vna_name); | |
11825 | aux.vna_next = BYTE_GET (eaux->vna_next); | |
11826 | ||
84714f86 | 11827 | if (valid_dynamic_name (filedata, aux.vna_name)) |
452bf675 | 11828 | printf (_(" %#06lx: Name: %s"), |
84714f86 | 11829 | isum, get_dynamic_name (filedata, aux.vna_name)); |
252b5132 | 11830 | else |
452bf675 | 11831 | printf (_(" %#06lx: Name index: %lx"), |
252b5132 RH |
11832 | isum, aux.vna_name); |
11833 | ||
11834 | printf (_(" Flags: %s Version: %d\n"), | |
11835 | get_ver_flags (aux.vna_flags), aux.vna_other); | |
11836 | ||
1445030f AM |
11837 | if (aux.vna_next < sizeof (*eaux) |
11838 | && !(j == ent.vn_cnt - 1 && aux.vna_next == 0)) | |
53774b7e NC |
11839 | { |
11840 | warn (_("Invalid vna_next field of %lx\n"), | |
11841 | aux.vna_next); | |
11842 | j = ent.vn_cnt; | |
11843 | break; | |
11844 | } | |
1445030f AM |
11845 | /* Check for overflow. */ |
11846 | if (aux.vna_next > (size_t) (endbuf - vstart)) | |
11847 | break; | |
252b5132 RH |
11848 | isum += aux.vna_next; |
11849 | vstart += aux.vna_next; | |
11850 | } | |
9cf03b7e | 11851 | |
54806181 | 11852 | if (j < ent.vn_cnt) |
f9a6a8f0 | 11853 | warn (_("Missing Version Needs auxiliary information\n")); |
252b5132 | 11854 | |
1445030f AM |
11855 | if (ent.vn_next < sizeof (*entry) |
11856 | && !(cnt == section->sh_info - 1 && ent.vn_next == 0)) | |
c24cf8b6 | 11857 | { |
452bf675 | 11858 | warn (_("Invalid vn_next field of %lx\n"), ent.vn_next); |
c24cf8b6 NC |
11859 | cnt = section->sh_info; |
11860 | break; | |
11861 | } | |
1445030f AM |
11862 | if (ent.vn_next > (size_t) (endbuf - ((char *) eneed + idx))) |
11863 | break; | |
252b5132 RH |
11864 | idx += ent.vn_next; |
11865 | } | |
9cf03b7e | 11866 | |
54806181 | 11867 | if (cnt < section->sh_info) |
9cf03b7e | 11868 | warn (_("Missing Version Needs information\n")); |
103f02d3 | 11869 | |
252b5132 RH |
11870 | free (eneed); |
11871 | } | |
11872 | break; | |
11873 | ||
11874 | case SHT_GNU_versym: | |
11875 | { | |
2cf0635d | 11876 | Elf_Internal_Shdr * link_section; |
8b73c356 NC |
11877 | size_t total; |
11878 | unsigned int cnt; | |
2cf0635d NC |
11879 | unsigned char * edata; |
11880 | unsigned short * data; | |
11881 | char * strtab; | |
11882 | Elf_Internal_Sym * symbols; | |
11883 | Elf_Internal_Shdr * string_sec; | |
ba5cdace | 11884 | unsigned long num_syms; |
d3ba0551 | 11885 | long off; |
252b5132 | 11886 | |
dda8d76d | 11887 | if (section->sh_link >= filedata->file_header.e_shnum) |
c256ffe7 JJ |
11888 | break; |
11889 | ||
dda8d76d | 11890 | link_section = filedata->section_headers + section->sh_link; |
08d8fa11 | 11891 | total = section->sh_size / sizeof (Elf_External_Versym); |
252b5132 | 11892 | |
dda8d76d | 11893 | if (link_section->sh_link >= filedata->file_header.e_shnum) |
c256ffe7 JJ |
11894 | break; |
11895 | ||
015dc7e1 | 11896 | found = true; |
252b5132 | 11897 | |
4de91c10 | 11898 | symbols = get_elf_symbols (filedata, link_section, & num_syms); |
dd24e3da NC |
11899 | if (symbols == NULL) |
11900 | break; | |
252b5132 | 11901 | |
dda8d76d | 11902 | string_sec = filedata->section_headers + link_section->sh_link; |
252b5132 | 11903 | |
dda8d76d | 11904 | strtab = (char *) get_data (NULL, filedata, string_sec->sh_offset, 1, |
3f5e193b NC |
11905 | string_sec->sh_size, |
11906 | _("version string table")); | |
a6e9f9df | 11907 | if (!strtab) |
0429c154 MS |
11908 | { |
11909 | free (symbols); | |
11910 | break; | |
11911 | } | |
252b5132 | 11912 | |
ca0e11aa NC |
11913 | if (filedata->is_separate) |
11914 | printf (ngettext ("\nIn linked file '%s' the version symbols section '%s' contains %lu entry:\n", | |
11915 | "\nIn linked file '%s' the version symbols section '%s' contains %lu entries:\n", | |
11916 | total), | |
11917 | filedata->file_name, | |
11918 | printable_section_name (filedata, section), | |
11919 | (unsigned long) total); | |
11920 | else | |
11921 | printf (ngettext ("\nVersion symbols section '%s' " | |
11922 | "contains %lu entry:\n", | |
11923 | "\nVersion symbols section '%s' " | |
11924 | "contains %lu entries:\n", | |
11925 | total), | |
11926 | printable_section_name (filedata, section), | |
11927 | (unsigned long) total); | |
252b5132 | 11928 | |
ae9ac79e | 11929 | printf (_(" Addr: 0x")); |
252b5132 | 11930 | printf_vma (section->sh_addr); |
72de5009 | 11931 | printf (_(" Offset: %#08lx Link: %u (%s)\n"), |
1b228002 | 11932 | (unsigned long) section->sh_offset, section->sh_link, |
dda8d76d | 11933 | printable_section_name (filedata, link_section)); |
252b5132 | 11934 | |
dda8d76d | 11935 | off = offset_from_vma (filedata, |
978c4450 | 11936 | filedata->version_info[DT_VERSIONTAGIDX (DT_VERSYM)], |
d3ba0551 | 11937 | total * sizeof (short)); |
95099889 AM |
11938 | edata = (unsigned char *) get_data (NULL, filedata, off, |
11939 | sizeof (short), total, | |
11940 | _("version symbol data")); | |
a6e9f9df AM |
11941 | if (!edata) |
11942 | { | |
11943 | free (strtab); | |
0429c154 | 11944 | free (symbols); |
a6e9f9df AM |
11945 | break; |
11946 | } | |
252b5132 | 11947 | |
3f5e193b | 11948 | data = (short unsigned int *) cmalloc (total, sizeof (short)); |
252b5132 RH |
11949 | |
11950 | for (cnt = total; cnt --;) | |
b34976b6 AM |
11951 | data[cnt] = byte_get (edata + cnt * sizeof (short), |
11952 | sizeof (short)); | |
252b5132 RH |
11953 | |
11954 | free (edata); | |
11955 | ||
11956 | for (cnt = 0; cnt < total; cnt += 4) | |
11957 | { | |
11958 | int j, nn; | |
ab273396 AM |
11959 | char *name; |
11960 | char *invalid = _("*invalid*"); | |
252b5132 RH |
11961 | |
11962 | printf (" %03x:", cnt); | |
11963 | ||
11964 | for (j = 0; (j < 4) && (cnt + j) < total; ++j) | |
b34976b6 | 11965 | switch (data[cnt + j]) |
252b5132 RH |
11966 | { |
11967 | case 0: | |
11968 | fputs (_(" 0 (*local*) "), stdout); | |
11969 | break; | |
11970 | ||
11971 | case 1: | |
11972 | fputs (_(" 1 (*global*) "), stdout); | |
11973 | break; | |
11974 | ||
11975 | default: | |
c244d050 NC |
11976 | nn = printf ("%4x%c", data[cnt + j] & VERSYM_VERSION, |
11977 | data[cnt + j] & VERSYM_HIDDEN ? 'h' : ' '); | |
252b5132 | 11978 | |
dd24e3da | 11979 | /* If this index value is greater than the size of the symbols |
ba5cdace NC |
11980 | array, break to avoid an out-of-bounds read. */ |
11981 | if ((unsigned long)(cnt + j) >= num_syms) | |
dd24e3da NC |
11982 | { |
11983 | warn (_("invalid index into symbol array\n")); | |
11984 | break; | |
11985 | } | |
11986 | ||
ab273396 | 11987 | name = NULL; |
978c4450 | 11988 | if (filedata->version_info[DT_VERSIONTAGIDX (DT_VERNEED)]) |
252b5132 | 11989 | { |
b34976b6 AM |
11990 | Elf_Internal_Verneed ivn; |
11991 | unsigned long offset; | |
252b5132 | 11992 | |
d93f0186 | 11993 | offset = offset_from_vma |
978c4450 AM |
11994 | (filedata, |
11995 | filedata->version_info[DT_VERSIONTAGIDX (DT_VERNEED)], | |
d93f0186 | 11996 | sizeof (Elf_External_Verneed)); |
252b5132 | 11997 | |
b34976b6 | 11998 | do |
252b5132 | 11999 | { |
b34976b6 AM |
12000 | Elf_Internal_Vernaux ivna; |
12001 | Elf_External_Verneed evn; | |
12002 | Elf_External_Vernaux evna; | |
12003 | unsigned long a_off; | |
252b5132 | 12004 | |
dda8d76d | 12005 | if (get_data (&evn, filedata, offset, sizeof (evn), 1, |
59245841 NC |
12006 | _("version need")) == NULL) |
12007 | break; | |
0b4362b0 | 12008 | |
252b5132 RH |
12009 | ivn.vn_aux = BYTE_GET (evn.vn_aux); |
12010 | ivn.vn_next = BYTE_GET (evn.vn_next); | |
12011 | ||
12012 | a_off = offset + ivn.vn_aux; | |
12013 | ||
12014 | do | |
12015 | { | |
dda8d76d | 12016 | if (get_data (&evna, filedata, a_off, sizeof (evna), |
59245841 NC |
12017 | 1, _("version need aux (2)")) == NULL) |
12018 | { | |
12019 | ivna.vna_next = 0; | |
12020 | ivna.vna_other = 0; | |
12021 | } | |
12022 | else | |
12023 | { | |
12024 | ivna.vna_next = BYTE_GET (evna.vna_next); | |
12025 | ivna.vna_other = BYTE_GET (evna.vna_other); | |
12026 | } | |
252b5132 RH |
12027 | |
12028 | a_off += ivna.vna_next; | |
12029 | } | |
b34976b6 | 12030 | while (ivna.vna_other != data[cnt + j] |
252b5132 RH |
12031 | && ivna.vna_next != 0); |
12032 | ||
b34976b6 | 12033 | if (ivna.vna_other == data[cnt + j]) |
252b5132 RH |
12034 | { |
12035 | ivna.vna_name = BYTE_GET (evna.vna_name); | |
12036 | ||
54806181 | 12037 | if (ivna.vna_name >= string_sec->sh_size) |
ab273396 | 12038 | name = invalid; |
54806181 AM |
12039 | else |
12040 | name = strtab + ivna.vna_name; | |
252b5132 RH |
12041 | break; |
12042 | } | |
12043 | ||
12044 | offset += ivn.vn_next; | |
12045 | } | |
12046 | while (ivn.vn_next); | |
12047 | } | |
00d93f34 | 12048 | |
ab273396 | 12049 | if (data[cnt + j] != 0x8001 |
978c4450 | 12050 | && filedata->version_info[DT_VERSIONTAGIDX (DT_VERDEF)]) |
252b5132 | 12051 | { |
b34976b6 AM |
12052 | Elf_Internal_Verdef ivd; |
12053 | Elf_External_Verdef evd; | |
12054 | unsigned long offset; | |
252b5132 | 12055 | |
d93f0186 | 12056 | offset = offset_from_vma |
978c4450 AM |
12057 | (filedata, |
12058 | filedata->version_info[DT_VERSIONTAGIDX (DT_VERDEF)], | |
d93f0186 | 12059 | sizeof evd); |
252b5132 RH |
12060 | |
12061 | do | |
12062 | { | |
dda8d76d | 12063 | if (get_data (&evd, filedata, offset, sizeof (evd), 1, |
59245841 NC |
12064 | _("version def")) == NULL) |
12065 | { | |
12066 | ivd.vd_next = 0; | |
948f632f | 12067 | /* PR 17531: file: 046-1082287-0.004. */ |
3102e897 NC |
12068 | ivd.vd_ndx = (data[cnt + j] & VERSYM_VERSION) + 1; |
12069 | break; | |
59245841 NC |
12070 | } |
12071 | else | |
12072 | { | |
12073 | ivd.vd_next = BYTE_GET (evd.vd_next); | |
12074 | ivd.vd_ndx = BYTE_GET (evd.vd_ndx); | |
12075 | } | |
252b5132 RH |
12076 | |
12077 | offset += ivd.vd_next; | |
12078 | } | |
c244d050 | 12079 | while (ivd.vd_ndx != (data[cnt + j] & VERSYM_VERSION) |
252b5132 RH |
12080 | && ivd.vd_next != 0); |
12081 | ||
c244d050 | 12082 | if (ivd.vd_ndx == (data[cnt + j] & VERSYM_VERSION)) |
252b5132 | 12083 | { |
b34976b6 AM |
12084 | Elf_External_Verdaux evda; |
12085 | Elf_Internal_Verdaux ivda; | |
252b5132 RH |
12086 | |
12087 | ivd.vd_aux = BYTE_GET (evd.vd_aux); | |
12088 | ||
dda8d76d | 12089 | if (get_data (&evda, filedata, |
59245841 NC |
12090 | offset - ivd.vd_next + ivd.vd_aux, |
12091 | sizeof (evda), 1, | |
12092 | _("version def aux")) == NULL) | |
12093 | break; | |
252b5132 RH |
12094 | |
12095 | ivda.vda_name = BYTE_GET (evda.vda_name); | |
12096 | ||
54806181 | 12097 | if (ivda.vda_name >= string_sec->sh_size) |
ab273396 AM |
12098 | name = invalid; |
12099 | else if (name != NULL && name != invalid) | |
12100 | name = _("*both*"); | |
54806181 AM |
12101 | else |
12102 | name = strtab + ivda.vda_name; | |
252b5132 RH |
12103 | } |
12104 | } | |
ab273396 AM |
12105 | if (name != NULL) |
12106 | nn += printf ("(%s%-*s", | |
12107 | name, | |
12108 | 12 - (int) strlen (name), | |
12109 | ")"); | |
252b5132 RH |
12110 | |
12111 | if (nn < 18) | |
12112 | printf ("%*c", 18 - nn, ' '); | |
12113 | } | |
12114 | ||
12115 | putchar ('\n'); | |
12116 | } | |
12117 | ||
12118 | free (data); | |
12119 | free (strtab); | |
12120 | free (symbols); | |
12121 | } | |
12122 | break; | |
103f02d3 | 12123 | |
252b5132 RH |
12124 | default: |
12125 | break; | |
12126 | } | |
12127 | } | |
12128 | ||
12129 | if (! found) | |
ca0e11aa NC |
12130 | { |
12131 | if (filedata->is_separate) | |
12132 | printf (_("\nNo version information found in linked file '%s'.\n"), | |
12133 | filedata->file_name); | |
12134 | else | |
12135 | printf (_("\nNo version information found in this file.\n")); | |
12136 | } | |
252b5132 | 12137 | |
015dc7e1 | 12138 | return true; |
252b5132 RH |
12139 | } |
12140 | ||
d1133906 | 12141 | static const char * |
dda8d76d | 12142 | get_symbol_binding (Filedata * filedata, unsigned int binding) |
252b5132 | 12143 | { |
89246a0e | 12144 | static char buff[64]; |
252b5132 RH |
12145 | |
12146 | switch (binding) | |
12147 | { | |
b34976b6 AM |
12148 | case STB_LOCAL: return "LOCAL"; |
12149 | case STB_GLOBAL: return "GLOBAL"; | |
12150 | case STB_WEAK: return "WEAK"; | |
252b5132 RH |
12151 | default: |
12152 | if (binding >= STB_LOPROC && binding <= STB_HIPROC) | |
e9e44622 JJ |
12153 | snprintf (buff, sizeof (buff), _("<processor specific>: %d"), |
12154 | binding); | |
252b5132 | 12155 | else if (binding >= STB_LOOS && binding <= STB_HIOS) |
3e7a7d11 NC |
12156 | { |
12157 | if (binding == STB_GNU_UNIQUE | |
df3a023b | 12158 | && filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_GNU) |
3e7a7d11 NC |
12159 | return "UNIQUE"; |
12160 | snprintf (buff, sizeof (buff), _("<OS specific>: %d"), binding); | |
12161 | } | |
252b5132 | 12162 | else |
e9e44622 | 12163 | snprintf (buff, sizeof (buff), _("<unknown>: %d"), binding); |
252b5132 RH |
12164 | return buff; |
12165 | } | |
12166 | } | |
12167 | ||
d1133906 | 12168 | static const char * |
dda8d76d | 12169 | get_symbol_type (Filedata * filedata, unsigned int type) |
252b5132 | 12170 | { |
89246a0e | 12171 | static char buff[64]; |
252b5132 RH |
12172 | |
12173 | switch (type) | |
12174 | { | |
b34976b6 AM |
12175 | case STT_NOTYPE: return "NOTYPE"; |
12176 | case STT_OBJECT: return "OBJECT"; | |
12177 | case STT_FUNC: return "FUNC"; | |
12178 | case STT_SECTION: return "SECTION"; | |
12179 | case STT_FILE: return "FILE"; | |
12180 | case STT_COMMON: return "COMMON"; | |
12181 | case STT_TLS: return "TLS"; | |
15ab5209 DB |
12182 | case STT_RELC: return "RELC"; |
12183 | case STT_SRELC: return "SRELC"; | |
252b5132 RH |
12184 | default: |
12185 | if (type >= STT_LOPROC && type <= STT_HIPROC) | |
df75f1af | 12186 | { |
dda8d76d | 12187 | if (filedata->file_header.e_machine == EM_ARM && type == STT_ARM_TFUNC) |
3510a7b8 | 12188 | return "THUMB_FUNC"; |
103f02d3 | 12189 | |
dda8d76d | 12190 | if (filedata->file_header.e_machine == EM_SPARCV9 && type == STT_REGISTER) |
103f02d3 UD |
12191 | return "REGISTER"; |
12192 | ||
dda8d76d | 12193 | if (filedata->file_header.e_machine == EM_PARISC && type == STT_PARISC_MILLI) |
103f02d3 UD |
12194 | return "PARISC_MILLI"; |
12195 | ||
e9e44622 | 12196 | snprintf (buff, sizeof (buff), _("<processor specific>: %d"), type); |
df75f1af | 12197 | } |
252b5132 | 12198 | else if (type >= STT_LOOS && type <= STT_HIOS) |
103f02d3 | 12199 | { |
dda8d76d | 12200 | if (filedata->file_header.e_machine == EM_PARISC) |
103f02d3 UD |
12201 | { |
12202 | if (type == STT_HP_OPAQUE) | |
12203 | return "HP_OPAQUE"; | |
12204 | if (type == STT_HP_STUB) | |
12205 | return "HP_STUB"; | |
12206 | } | |
12207 | ||
d8045f23 | 12208 | if (type == STT_GNU_IFUNC |
dda8d76d | 12209 | && (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_GNU |
df3a023b | 12210 | || filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_FREEBSD)) |
d8045f23 NC |
12211 | return "IFUNC"; |
12212 | ||
e9e44622 | 12213 | snprintf (buff, sizeof (buff), _("<OS specific>: %d"), type); |
103f02d3 | 12214 | } |
252b5132 | 12215 | else |
e9e44622 | 12216 | snprintf (buff, sizeof (buff), _("<unknown>: %d"), type); |
252b5132 RH |
12217 | return buff; |
12218 | } | |
12219 | } | |
12220 | ||
d1133906 | 12221 | static const char * |
d3ba0551 | 12222 | get_symbol_visibility (unsigned int visibility) |
d1133906 NC |
12223 | { |
12224 | switch (visibility) | |
12225 | { | |
b34976b6 AM |
12226 | case STV_DEFAULT: return "DEFAULT"; |
12227 | case STV_INTERNAL: return "INTERNAL"; | |
12228 | case STV_HIDDEN: return "HIDDEN"; | |
d1133906 | 12229 | case STV_PROTECTED: return "PROTECTED"; |
bee0ee85 | 12230 | default: |
27a45f42 | 12231 | error (_("Unrecognized visibility value: %u\n"), visibility); |
bee0ee85 | 12232 | return _("<unknown>"); |
d1133906 NC |
12233 | } |
12234 | } | |
12235 | ||
2057d69d CZ |
12236 | static const char * |
12237 | get_alpha_symbol_other (unsigned int other) | |
9abca702 | 12238 | { |
2057d69d CZ |
12239 | switch (other) |
12240 | { | |
12241 | case STO_ALPHA_NOPV: return "NOPV"; | |
12242 | case STO_ALPHA_STD_GPLOAD: return "STD GPLOAD"; | |
12243 | default: | |
27a45f42 | 12244 | error (_("Unrecognized alpha specific other value: %u\n"), other); |
2057d69d | 12245 | return _("<unknown>"); |
9abca702 | 12246 | } |
2057d69d CZ |
12247 | } |
12248 | ||
fd85a6a1 NC |
12249 | static const char * |
12250 | get_solaris_symbol_visibility (unsigned int visibility) | |
12251 | { | |
12252 | switch (visibility) | |
12253 | { | |
12254 | case 4: return "EXPORTED"; | |
12255 | case 5: return "SINGLETON"; | |
12256 | case 6: return "ELIMINATE"; | |
12257 | default: return get_symbol_visibility (visibility); | |
12258 | } | |
12259 | } | |
12260 | ||
2301ed1c SN |
12261 | static const char * |
12262 | get_aarch64_symbol_other (unsigned int other) | |
12263 | { | |
12264 | static char buf[32]; | |
12265 | ||
12266 | if (other & STO_AARCH64_VARIANT_PCS) | |
12267 | { | |
12268 | other &= ~STO_AARCH64_VARIANT_PCS; | |
12269 | if (other == 0) | |
12270 | return "VARIANT_PCS"; | |
12271 | snprintf (buf, sizeof buf, "VARIANT_PCS | %x", other); | |
12272 | return buf; | |
12273 | } | |
12274 | return NULL; | |
12275 | } | |
12276 | ||
5e2b0d47 NC |
12277 | static const char * |
12278 | get_mips_symbol_other (unsigned int other) | |
12279 | { | |
12280 | switch (other) | |
12281 | { | |
32ec8896 NC |
12282 | case STO_OPTIONAL: return "OPTIONAL"; |
12283 | case STO_MIPS_PLT: return "MIPS PLT"; | |
12284 | case STO_MIPS_PIC: return "MIPS PIC"; | |
12285 | case STO_MICROMIPS: return "MICROMIPS"; | |
12286 | case STO_MICROMIPS | STO_MIPS_PIC: return "MICROMIPS, MIPS PIC"; | |
12287 | case STO_MIPS16: return "MIPS16"; | |
12288 | default: return NULL; | |
5e2b0d47 NC |
12289 | } |
12290 | } | |
12291 | ||
28f997cf | 12292 | static const char * |
dda8d76d | 12293 | get_ia64_symbol_other (Filedata * filedata, unsigned int other) |
28f997cf | 12294 | { |
dda8d76d | 12295 | if (is_ia64_vms (filedata)) |
28f997cf TG |
12296 | { |
12297 | static char res[32]; | |
12298 | ||
12299 | res[0] = 0; | |
12300 | ||
12301 | /* Function types is for images and .STB files only. */ | |
dda8d76d | 12302 | switch (filedata->file_header.e_type) |
28f997cf TG |
12303 | { |
12304 | case ET_DYN: | |
12305 | case ET_EXEC: | |
12306 | switch (VMS_ST_FUNC_TYPE (other)) | |
12307 | { | |
12308 | case VMS_SFT_CODE_ADDR: | |
12309 | strcat (res, " CA"); | |
12310 | break; | |
12311 | case VMS_SFT_SYMV_IDX: | |
12312 | strcat (res, " VEC"); | |
12313 | break; | |
12314 | case VMS_SFT_FD: | |
12315 | strcat (res, " FD"); | |
12316 | break; | |
12317 | case VMS_SFT_RESERVE: | |
12318 | strcat (res, " RSV"); | |
12319 | break; | |
12320 | default: | |
bee0ee85 NC |
12321 | warn (_("Unrecognized IA64 VMS ST Function type: %d\n"), |
12322 | VMS_ST_FUNC_TYPE (other)); | |
12323 | strcat (res, " <unknown>"); | |
12324 | break; | |
28f997cf TG |
12325 | } |
12326 | break; | |
12327 | default: | |
12328 | break; | |
12329 | } | |
12330 | switch (VMS_ST_LINKAGE (other)) | |
12331 | { | |
12332 | case VMS_STL_IGNORE: | |
12333 | strcat (res, " IGN"); | |
12334 | break; | |
12335 | case VMS_STL_RESERVE: | |
12336 | strcat (res, " RSV"); | |
12337 | break; | |
12338 | case VMS_STL_STD: | |
12339 | strcat (res, " STD"); | |
12340 | break; | |
12341 | case VMS_STL_LNK: | |
12342 | strcat (res, " LNK"); | |
12343 | break; | |
12344 | default: | |
bee0ee85 NC |
12345 | warn (_("Unrecognized IA64 VMS ST Linkage: %d\n"), |
12346 | VMS_ST_LINKAGE (other)); | |
12347 | strcat (res, " <unknown>"); | |
12348 | break; | |
28f997cf TG |
12349 | } |
12350 | ||
12351 | if (res[0] != 0) | |
12352 | return res + 1; | |
12353 | else | |
12354 | return res; | |
12355 | } | |
12356 | return NULL; | |
12357 | } | |
12358 | ||
6911b7dc AM |
12359 | static const char * |
12360 | get_ppc64_symbol_other (unsigned int other) | |
12361 | { | |
14732552 AM |
12362 | if ((other & ~STO_PPC64_LOCAL_MASK) != 0) |
12363 | return NULL; | |
12364 | ||
12365 | other >>= STO_PPC64_LOCAL_BIT; | |
12366 | if (other <= 6) | |
6911b7dc | 12367 | { |
89246a0e | 12368 | static char buf[64]; |
14732552 AM |
12369 | if (other >= 2) |
12370 | other = ppc64_decode_local_entry (other); | |
12371 | snprintf (buf, sizeof buf, _("<localentry>: %d"), other); | |
6911b7dc AM |
12372 | return buf; |
12373 | } | |
12374 | return NULL; | |
12375 | } | |
12376 | ||
5e2b0d47 | 12377 | static const char * |
dda8d76d | 12378 | get_symbol_other (Filedata * filedata, unsigned int other) |
5e2b0d47 NC |
12379 | { |
12380 | const char * result = NULL; | |
89246a0e | 12381 | static char buff [64]; |
5e2b0d47 NC |
12382 | |
12383 | if (other == 0) | |
12384 | return ""; | |
12385 | ||
dda8d76d | 12386 | switch (filedata->file_header.e_machine) |
5e2b0d47 | 12387 | { |
2057d69d CZ |
12388 | case EM_ALPHA: |
12389 | result = get_alpha_symbol_other (other); | |
12390 | break; | |
2301ed1c SN |
12391 | case EM_AARCH64: |
12392 | result = get_aarch64_symbol_other (other); | |
12393 | break; | |
5e2b0d47 NC |
12394 | case EM_MIPS: |
12395 | result = get_mips_symbol_other (other); | |
28f997cf TG |
12396 | break; |
12397 | case EM_IA_64: | |
dda8d76d | 12398 | result = get_ia64_symbol_other (filedata, other); |
28f997cf | 12399 | break; |
6911b7dc AM |
12400 | case EM_PPC64: |
12401 | result = get_ppc64_symbol_other (other); | |
12402 | break; | |
5e2b0d47 | 12403 | default: |
fd85a6a1 | 12404 | result = NULL; |
5e2b0d47 NC |
12405 | break; |
12406 | } | |
12407 | ||
12408 | if (result) | |
12409 | return result; | |
12410 | ||
12411 | snprintf (buff, sizeof buff, _("<other>: %x"), other); | |
12412 | return buff; | |
12413 | } | |
12414 | ||
d1133906 | 12415 | static const char * |
dda8d76d | 12416 | get_symbol_index_type (Filedata * filedata, unsigned int type) |
252b5132 | 12417 | { |
b34976b6 | 12418 | static char buff[32]; |
5cf1065c | 12419 | |
252b5132 RH |
12420 | switch (type) |
12421 | { | |
b34976b6 AM |
12422 | case SHN_UNDEF: return "UND"; |
12423 | case SHN_ABS: return "ABS"; | |
12424 | case SHN_COMMON: return "COM"; | |
252b5132 | 12425 | default: |
9ce701e2 | 12426 | if (type == SHN_IA_64_ANSI_COMMON |
10ca4b04 L |
12427 | && filedata->file_header.e_machine == EM_IA_64 |
12428 | && filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_HPUX) | |
12429 | return "ANSI_COM"; | |
12430 | else if ((filedata->file_header.e_machine == EM_X86_64 | |
12431 | || filedata->file_header.e_machine == EM_L1OM | |
12432 | || filedata->file_header.e_machine == EM_K1OM) | |
12433 | && type == SHN_X86_64_LCOMMON) | |
12434 | return "LARGE_COM"; | |
12435 | else if ((type == SHN_MIPS_SCOMMON | |
12436 | && filedata->file_header.e_machine == EM_MIPS) | |
12437 | || (type == SHN_TIC6X_SCOMMON | |
12438 | && filedata->file_header.e_machine == EM_TI_C6000)) | |
12439 | return "SCOM"; | |
12440 | else if (type == SHN_MIPS_SUNDEFINED | |
12441 | && filedata->file_header.e_machine == EM_MIPS) | |
12442 | return "SUND"; | |
12443 | else if (type >= SHN_LOPROC && type <= SHN_HIPROC) | |
12444 | sprintf (buff, "PRC[0x%04x]", type & 0xffff); | |
12445 | else if (type >= SHN_LOOS && type <= SHN_HIOS) | |
12446 | sprintf (buff, "OS [0x%04x]", type & 0xffff); | |
12447 | else if (type >= SHN_LORESERVE) | |
12448 | sprintf (buff, "RSV[0x%04x]", type & 0xffff); | |
12449 | else if (filedata->file_header.e_shnum != 0 | |
12450 | && type >= filedata->file_header.e_shnum) | |
12451 | sprintf (buff, _("bad section index[%3d]"), type); | |
12452 | else | |
12453 | sprintf (buff, "%3d", type); | |
12454 | break; | |
fd85a6a1 NC |
12455 | } |
12456 | ||
10ca4b04 | 12457 | return buff; |
6bd1a22c L |
12458 | } |
12459 | ||
bb4d2ac2 | 12460 | static const char * |
dda8d76d | 12461 | get_symbol_version_string (Filedata * filedata, |
015dc7e1 | 12462 | bool is_dynsym, |
1449284b NC |
12463 | const char * strtab, |
12464 | unsigned long int strtab_size, | |
12465 | unsigned int si, | |
12466 | Elf_Internal_Sym * psym, | |
12467 | enum versioned_symbol_info * sym_info, | |
12468 | unsigned short * vna_other) | |
bb4d2ac2 | 12469 | { |
ab273396 AM |
12470 | unsigned char data[2]; |
12471 | unsigned short vers_data; | |
12472 | unsigned long offset; | |
7a815dd5 | 12473 | unsigned short max_vd_ndx; |
bb4d2ac2 | 12474 | |
ab273396 | 12475 | if (!is_dynsym |
978c4450 | 12476 | || filedata->version_info[DT_VERSIONTAGIDX (DT_VERSYM)] == 0) |
ab273396 | 12477 | return NULL; |
bb4d2ac2 | 12478 | |
978c4450 AM |
12479 | offset = offset_from_vma (filedata, |
12480 | filedata->version_info[DT_VERSIONTAGIDX (DT_VERSYM)], | |
ab273396 | 12481 | sizeof data + si * sizeof (vers_data)); |
bb4d2ac2 | 12482 | |
dda8d76d | 12483 | if (get_data (&data, filedata, offset + si * sizeof (vers_data), |
ab273396 AM |
12484 | sizeof (data), 1, _("version data")) == NULL) |
12485 | return NULL; | |
12486 | ||
12487 | vers_data = byte_get (data, 2); | |
bb4d2ac2 | 12488 | |
1f6f5dba | 12489 | if ((vers_data & VERSYM_HIDDEN) == 0 && vers_data == 0) |
ab273396 | 12490 | return NULL; |
bb4d2ac2 | 12491 | |
0b8b7609 | 12492 | *sym_info = (vers_data & VERSYM_HIDDEN) != 0 ? symbol_hidden : symbol_public; |
7a815dd5 L |
12493 | max_vd_ndx = 0; |
12494 | ||
ab273396 AM |
12495 | /* Usually we'd only see verdef for defined symbols, and verneed for |
12496 | undefined symbols. However, symbols defined by the linker in | |
12497 | .dynbss for variables copied from a shared library in order to | |
12498 | avoid text relocations are defined yet have verneed. We could | |
12499 | use a heuristic to detect the special case, for example, check | |
12500 | for verneed first on symbols defined in SHT_NOBITS sections, but | |
12501 | it is simpler and more reliable to just look for both verdef and | |
12502 | verneed. .dynbss might not be mapped to a SHT_NOBITS section. */ | |
bb4d2ac2 | 12503 | |
ab273396 AM |
12504 | if (psym->st_shndx != SHN_UNDEF |
12505 | && vers_data != 0x8001 | |
978c4450 | 12506 | && filedata->version_info[DT_VERSIONTAGIDX (DT_VERDEF)]) |
ab273396 AM |
12507 | { |
12508 | Elf_Internal_Verdef ivd; | |
12509 | Elf_Internal_Verdaux ivda; | |
12510 | Elf_External_Verdaux evda; | |
12511 | unsigned long off; | |
bb4d2ac2 | 12512 | |
dda8d76d | 12513 | off = offset_from_vma (filedata, |
978c4450 | 12514 | filedata->version_info[DT_VERSIONTAGIDX (DT_VERDEF)], |
ab273396 AM |
12515 | sizeof (Elf_External_Verdef)); |
12516 | ||
12517 | do | |
bb4d2ac2 | 12518 | { |
ab273396 AM |
12519 | Elf_External_Verdef evd; |
12520 | ||
dda8d76d | 12521 | if (get_data (&evd, filedata, off, sizeof (evd), 1, |
ab273396 AM |
12522 | _("version def")) == NULL) |
12523 | { | |
12524 | ivd.vd_ndx = 0; | |
12525 | ivd.vd_aux = 0; | |
12526 | ivd.vd_next = 0; | |
1f6f5dba | 12527 | ivd.vd_flags = 0; |
ab273396 AM |
12528 | } |
12529 | else | |
bb4d2ac2 | 12530 | { |
ab273396 AM |
12531 | ivd.vd_ndx = BYTE_GET (evd.vd_ndx); |
12532 | ivd.vd_aux = BYTE_GET (evd.vd_aux); | |
12533 | ivd.vd_next = BYTE_GET (evd.vd_next); | |
1f6f5dba | 12534 | ivd.vd_flags = BYTE_GET (evd.vd_flags); |
ab273396 | 12535 | } |
bb4d2ac2 | 12536 | |
7a815dd5 L |
12537 | if ((ivd.vd_ndx & VERSYM_VERSION) > max_vd_ndx) |
12538 | max_vd_ndx = ivd.vd_ndx & VERSYM_VERSION; | |
12539 | ||
ab273396 AM |
12540 | off += ivd.vd_next; |
12541 | } | |
12542 | while (ivd.vd_ndx != (vers_data & VERSYM_VERSION) && ivd.vd_next != 0); | |
bb4d2ac2 | 12543 | |
ab273396 AM |
12544 | if (ivd.vd_ndx == (vers_data & VERSYM_VERSION)) |
12545 | { | |
9abca702 | 12546 | if (ivd.vd_ndx == 1 && ivd.vd_flags == VER_FLG_BASE) |
1f6f5dba L |
12547 | return NULL; |
12548 | ||
ab273396 AM |
12549 | off -= ivd.vd_next; |
12550 | off += ivd.vd_aux; | |
bb4d2ac2 | 12551 | |
dda8d76d | 12552 | if (get_data (&evda, filedata, off, sizeof (evda), 1, |
ab273396 AM |
12553 | _("version def aux")) != NULL) |
12554 | { | |
12555 | ivda.vda_name = BYTE_GET (evda.vda_name); | |
bb4d2ac2 | 12556 | |
ab273396 | 12557 | if (psym->st_name != ivda.vda_name) |
0b8b7609 AM |
12558 | return (ivda.vda_name < strtab_size |
12559 | ? strtab + ivda.vda_name : _("<corrupt>")); | |
ab273396 AM |
12560 | } |
12561 | } | |
12562 | } | |
bb4d2ac2 | 12563 | |
978c4450 | 12564 | if (filedata->version_info[DT_VERSIONTAGIDX (DT_VERNEED)]) |
ab273396 AM |
12565 | { |
12566 | Elf_External_Verneed evn; | |
12567 | Elf_Internal_Verneed ivn; | |
12568 | Elf_Internal_Vernaux ivna; | |
bb4d2ac2 | 12569 | |
dda8d76d | 12570 | offset = offset_from_vma (filedata, |
978c4450 | 12571 | filedata->version_info[DT_VERSIONTAGIDX (DT_VERNEED)], |
ab273396 AM |
12572 | sizeof evn); |
12573 | do | |
12574 | { | |
12575 | unsigned long vna_off; | |
bb4d2ac2 | 12576 | |
dda8d76d | 12577 | if (get_data (&evn, filedata, offset, sizeof (evn), 1, |
ab273396 AM |
12578 | _("version need")) == NULL) |
12579 | { | |
12580 | ivna.vna_next = 0; | |
12581 | ivna.vna_other = 0; | |
12582 | ivna.vna_name = 0; | |
12583 | break; | |
12584 | } | |
bb4d2ac2 | 12585 | |
ab273396 AM |
12586 | ivn.vn_aux = BYTE_GET (evn.vn_aux); |
12587 | ivn.vn_next = BYTE_GET (evn.vn_next); | |
bb4d2ac2 | 12588 | |
ab273396 | 12589 | vna_off = offset + ivn.vn_aux; |
bb4d2ac2 | 12590 | |
ab273396 AM |
12591 | do |
12592 | { | |
12593 | Elf_External_Vernaux evna; | |
bb4d2ac2 | 12594 | |
dda8d76d | 12595 | if (get_data (&evna, filedata, vna_off, sizeof (evna), 1, |
ab273396 | 12596 | _("version need aux (3)")) == NULL) |
bb4d2ac2 | 12597 | { |
ab273396 AM |
12598 | ivna.vna_next = 0; |
12599 | ivna.vna_other = 0; | |
12600 | ivna.vna_name = 0; | |
bb4d2ac2 | 12601 | } |
bb4d2ac2 | 12602 | else |
bb4d2ac2 | 12603 | { |
ab273396 AM |
12604 | ivna.vna_other = BYTE_GET (evna.vna_other); |
12605 | ivna.vna_next = BYTE_GET (evna.vna_next); | |
12606 | ivna.vna_name = BYTE_GET (evna.vna_name); | |
12607 | } | |
bb4d2ac2 | 12608 | |
ab273396 AM |
12609 | vna_off += ivna.vna_next; |
12610 | } | |
12611 | while (ivna.vna_other != vers_data && ivna.vna_next != 0); | |
bb4d2ac2 | 12612 | |
ab273396 AM |
12613 | if (ivna.vna_other == vers_data) |
12614 | break; | |
bb4d2ac2 | 12615 | |
ab273396 AM |
12616 | offset += ivn.vn_next; |
12617 | } | |
12618 | while (ivn.vn_next != 0); | |
bb4d2ac2 | 12619 | |
ab273396 AM |
12620 | if (ivna.vna_other == vers_data) |
12621 | { | |
12622 | *sym_info = symbol_undefined; | |
12623 | *vna_other = ivna.vna_other; | |
12624 | return (ivna.vna_name < strtab_size | |
12625 | ? strtab + ivna.vna_name : _("<corrupt>")); | |
bb4d2ac2 | 12626 | } |
7a815dd5 L |
12627 | else if ((max_vd_ndx || (vers_data & VERSYM_VERSION) != 1) |
12628 | && (vers_data & VERSYM_VERSION) > max_vd_ndx) | |
12629 | return _("<corrupt>"); | |
bb4d2ac2 | 12630 | } |
ab273396 | 12631 | return NULL; |
bb4d2ac2 L |
12632 | } |
12633 | ||
047c3dbf NL |
12634 | /* Display a symbol size on stdout. Format is based on --sym-base setting. */ |
12635 | ||
12636 | static unsigned int | |
12637 | print_dynamic_symbol_size (bfd_vma vma, int base) | |
12638 | { | |
12639 | switch (base) | |
12640 | { | |
12641 | case 8: | |
12642 | return print_vma (vma, OCTAL_5); | |
12643 | ||
12644 | case 10: | |
12645 | return print_vma (vma, UNSIGNED_5); | |
12646 | ||
12647 | case 16: | |
12648 | return print_vma (vma, PREFIX_HEX_5); | |
12649 | ||
12650 | case 0: | |
12651 | default: | |
12652 | return print_vma (vma, DEC_5); | |
12653 | } | |
12654 | } | |
12655 | ||
10ca4b04 L |
12656 | static void |
12657 | print_dynamic_symbol (Filedata *filedata, unsigned long si, | |
12658 | Elf_Internal_Sym *symtab, | |
12659 | Elf_Internal_Shdr *section, | |
12660 | char *strtab, size_t strtab_size) | |
252b5132 | 12661 | { |
10ca4b04 L |
12662 | const char *version_string; |
12663 | enum versioned_symbol_info sym_info; | |
12664 | unsigned short vna_other; | |
23356397 NC |
12665 | bool is_valid; |
12666 | const char * sstr; | |
10ca4b04 | 12667 | Elf_Internal_Sym *psym = symtab + si; |
b9e920ec | 12668 | |
10ca4b04 L |
12669 | printf ("%6ld: ", si); |
12670 | print_vma (psym->st_value, LONG_HEX); | |
12671 | putchar (' '); | |
047c3dbf | 12672 | print_dynamic_symbol_size (psym->st_size, sym_base); |
10ca4b04 L |
12673 | printf (" %-7s", get_symbol_type (filedata, ELF_ST_TYPE (psym->st_info))); |
12674 | printf (" %-6s", get_symbol_binding (filedata, ELF_ST_BIND (psym->st_info))); | |
12675 | if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS) | |
12676 | printf (" %-7s", get_solaris_symbol_visibility (psym->st_other)); | |
12677 | else | |
252b5132 | 12678 | { |
10ca4b04 | 12679 | unsigned int vis = ELF_ST_VISIBILITY (psym->st_other); |
252b5132 | 12680 | |
10ca4b04 L |
12681 | printf (" %-7s", get_symbol_visibility (vis)); |
12682 | /* Check to see if any other bits in the st_other field are set. | |
12683 | Note - displaying this information disrupts the layout of the | |
12684 | table being generated, but for the moment this case is very rare. */ | |
12685 | if (psym->st_other ^ vis) | |
12686 | printf (" [%s] ", get_symbol_other (filedata, psym->st_other ^ vis)); | |
252b5132 | 12687 | } |
10ca4b04 | 12688 | printf (" %4s ", get_symbol_index_type (filedata, psym->st_shndx)); |
0942c7ab | 12689 | |
23356397 NC |
12690 | if (ELF_ST_TYPE (psym->st_info) == STT_SECTION |
12691 | && psym->st_shndx < filedata->file_header.e_shnum | |
12692 | && psym->st_name == 0) | |
12693 | { | |
84714f86 AM |
12694 | is_valid |
12695 | = section_name_valid (filedata, | |
12696 | filedata->section_headers + psym->st_shndx); | |
23356397 | 12697 | sstr = is_valid ? |
84714f86 AM |
12698 | section_name_print (filedata, |
12699 | filedata->section_headers + psym->st_shndx) | |
23356397 NC |
12700 | : _("<corrupt>"); |
12701 | } | |
12702 | else | |
12703 | { | |
84714f86 | 12704 | is_valid = valid_symbol_name (strtab, strtab_size, psym->st_name); |
23356397 NC |
12705 | sstr = is_valid ? strtab + psym->st_name : _("<corrupt>"); |
12706 | } | |
10ca4b04 L |
12707 | |
12708 | version_string | |
12709 | = get_symbol_version_string (filedata, | |
12710 | (section == NULL | |
12711 | || section->sh_type == SHT_DYNSYM), | |
12712 | strtab, strtab_size, si, | |
12713 | psym, &sym_info, &vna_other); | |
b9e920ec | 12714 | |
0942c7ab NC |
12715 | int len_avail = 21; |
12716 | if (! do_wide && version_string != NULL) | |
12717 | { | |
ddb43bab | 12718 | char buffer[16]; |
0942c7ab | 12719 | |
ddb43bab | 12720 | len_avail -= 1 + strlen (version_string); |
0942c7ab NC |
12721 | |
12722 | if (sym_info == symbol_undefined) | |
12723 | len_avail -= sprintf (buffer," (%d)", vna_other); | |
12724 | else if (sym_info != symbol_hidden) | |
12725 | len_avail -= 1; | |
12726 | } | |
12727 | ||
12728 | print_symbol (len_avail, sstr); | |
b9e920ec | 12729 | |
10ca4b04 L |
12730 | if (version_string) |
12731 | { | |
12732 | if (sym_info == symbol_undefined) | |
12733 | printf ("@%s (%d)", version_string, vna_other); | |
f7a99963 | 12734 | else |
10ca4b04 L |
12735 | printf (sym_info == symbol_hidden ? "@%s" : "@@%s", |
12736 | version_string); | |
12737 | } | |
6bd1a22c | 12738 | |
10ca4b04 | 12739 | putchar ('\n'); |
6bd1a22c | 12740 | |
10ca4b04 L |
12741 | if (ELF_ST_BIND (psym->st_info) == STB_LOCAL |
12742 | && section != NULL | |
12743 | && si >= section->sh_info | |
12744 | /* Irix 5 and 6 MIPS binaries are known to ignore this requirement. */ | |
12745 | && filedata->file_header.e_machine != EM_MIPS | |
12746 | /* Solaris binaries have been found to violate this requirement as | |
12747 | well. Not sure if this is a bug or an ABI requirement. */ | |
12748 | && filedata->file_header.e_ident[EI_OSABI] != ELFOSABI_SOLARIS) | |
12749 | warn (_("local symbol %lu found at index >= %s's sh_info value of %u\n"), | |
12750 | si, printable_section_name (filedata, section), section->sh_info); | |
12751 | } | |
f16a9783 | 12752 | |
0f03783c NC |
12753 | static const char * |
12754 | get_lto_kind (unsigned int kind) | |
12755 | { | |
12756 | switch (kind) | |
12757 | { | |
12758 | case 0: return "DEF"; | |
12759 | case 1: return "WEAKDEF"; | |
12760 | case 2: return "UNDEF"; | |
12761 | case 3: return "WEAKUNDEF"; | |
12762 | case 4: return "COMMON"; | |
12763 | default: | |
12764 | break; | |
12765 | } | |
12766 | ||
12767 | static char buffer[30]; | |
12768 | error (_("Unknown LTO symbol definition encountered: %u\n"), kind); | |
12769 | sprintf (buffer, "<unknown: %u>", kind); | |
12770 | return buffer; | |
12771 | } | |
12772 | ||
12773 | static const char * | |
12774 | get_lto_visibility (unsigned int visibility) | |
12775 | { | |
12776 | switch (visibility) | |
12777 | { | |
12778 | case 0: return "DEFAULT"; | |
12779 | case 1: return "PROTECTED"; | |
12780 | case 2: return "INTERNAL"; | |
12781 | case 3: return "HIDDEN"; | |
12782 | default: | |
12783 | break; | |
12784 | } | |
12785 | ||
12786 | static char buffer[30]; | |
12787 | error (_("Unknown LTO symbol visibility encountered: %u\n"), visibility); | |
12788 | sprintf (buffer, "<unknown: %u>", visibility); | |
12789 | return buffer; | |
12790 | } | |
12791 | ||
12792 | static const char * | |
12793 | get_lto_sym_type (unsigned int sym_type) | |
12794 | { | |
12795 | switch (sym_type) | |
12796 | { | |
12797 | case 0: return "UNKNOWN"; | |
12798 | case 1: return "FUNCTION"; | |
12799 | case 2: return "VARIABLE"; | |
12800 | default: | |
12801 | break; | |
12802 | } | |
12803 | ||
12804 | static char buffer[30]; | |
12805 | error (_("Unknown LTO symbol type encountered: %u\n"), sym_type); | |
12806 | sprintf (buffer, "<unknown: %u>", sym_type); | |
12807 | return buffer; | |
12808 | } | |
12809 | ||
12810 | /* Display an LTO format symbol table. | |
12811 | FIXME: The format of LTO symbol tables is not formalized. | |
12812 | So this code could need changing in the future. */ | |
12813 | ||
015dc7e1 | 12814 | static bool |
0f03783c NC |
12815 | display_lto_symtab (Filedata * filedata, |
12816 | Elf_Internal_Shdr * section) | |
12817 | { | |
12818 | if (section->sh_size == 0) | |
12819 | { | |
ca0e11aa NC |
12820 | if (filedata->is_separate) |
12821 | printf (_("\nThe LTO Symbol table section '%s' in linked file '%s' is empty!\n"), | |
12822 | printable_section_name (filedata, section), | |
12823 | filedata->file_name); | |
12824 | else | |
12825 | printf (_("\nLTO Symbol table '%s' is empty!\n"), | |
12826 | printable_section_name (filedata, section)); | |
047c3dbf | 12827 | |
015dc7e1 | 12828 | return true; |
0f03783c NC |
12829 | } |
12830 | ||
12831 | if (section->sh_size > filedata->file_size) | |
12832 | { | |
12833 | error (_("Section %s has an invalid sh_size of 0x%lx\n"), | |
12834 | printable_section_name (filedata, section), | |
12835 | (unsigned long) section->sh_size); | |
015dc7e1 | 12836 | return false; |
0f03783c NC |
12837 | } |
12838 | ||
12839 | void * alloced_data = get_data (NULL, filedata, section->sh_offset, | |
12840 | section->sh_size, 1, _("LTO symbols")); | |
12841 | if (alloced_data == NULL) | |
015dc7e1 | 12842 | return false; |
0f03783c NC |
12843 | |
12844 | /* Look for extended data for the symbol table. */ | |
12845 | Elf_Internal_Shdr * ext; | |
12846 | void * ext_data_orig = NULL; | |
12847 | char * ext_data = NULL; | |
12848 | char * ext_data_end = NULL; | |
12849 | char * ext_name = NULL; | |
12850 | ||
12851 | if (asprintf (& ext_name, ".gnu.lto_.ext_symtab.%s", | |
84714f86 AM |
12852 | (section_name (filedata, section) |
12853 | + sizeof (".gnu.lto_.symtab.") - 1)) > 0 | |
0f03783c NC |
12854 | && ext_name != NULL /* Paranoia. */ |
12855 | && (ext = find_section (filedata, ext_name)) != NULL) | |
12856 | { | |
12857 | if (ext->sh_size < 3) | |
12858 | error (_("LTO Symbol extension table '%s' is empty!\n"), | |
12859 | printable_section_name (filedata, ext)); | |
12860 | else | |
12861 | { | |
12862 | ext_data_orig = ext_data = get_data (NULL, filedata, ext->sh_offset, | |
12863 | ext->sh_size, 1, | |
12864 | _("LTO ext symbol data")); | |
12865 | if (ext_data != NULL) | |
12866 | { | |
12867 | ext_data_end = ext_data + ext->sh_size; | |
12868 | if (* ext_data++ != 1) | |
12869 | error (_("Unexpected version number in symbol extension table\n")); | |
12870 | } | |
12871 | } | |
12872 | } | |
b9e920ec | 12873 | |
0f03783c NC |
12874 | const unsigned char * data = (const unsigned char *) alloced_data; |
12875 | const unsigned char * end = data + section->sh_size; | |
12876 | ||
ca0e11aa NC |
12877 | if (filedata->is_separate) |
12878 | printf (_("\nIn linked file '%s': "), filedata->file_name); | |
12879 | else | |
12880 | printf ("\n"); | |
12881 | ||
0f03783c NC |
12882 | if (ext_data_orig != NULL) |
12883 | { | |
12884 | if (do_wide) | |
ca0e11aa | 12885 | printf (_("LTO Symbol table '%s' and extension table '%s' contain:\n"), |
0f03783c NC |
12886 | printable_section_name (filedata, section), |
12887 | printable_section_name (filedata, ext)); | |
12888 | else | |
12889 | { | |
ca0e11aa | 12890 | printf (_("LTO Symbol table '%s'\n"), |
0f03783c NC |
12891 | printable_section_name (filedata, section)); |
12892 | printf (_(" and extension table '%s' contain:\n"), | |
12893 | printable_section_name (filedata, ext)); | |
12894 | } | |
12895 | } | |
12896 | else | |
ca0e11aa | 12897 | printf (_("LTO Symbol table '%s' contains:\n"), |
0f03783c | 12898 | printable_section_name (filedata, section)); |
b9e920ec | 12899 | |
0f03783c | 12900 | /* FIXME: Add a wide version. */ |
b9e920ec | 12901 | if (ext_data_orig != NULL) |
0f03783c NC |
12902 | printf (_(" Comdat_Key Kind Visibility Size Slot Type Section Name\n")); |
12903 | else | |
12904 | printf (_(" Comdat_Key Kind Visibility Size Slot Name\n")); | |
12905 | ||
12906 | /* FIXME: We do not handle style prefixes. */ | |
12907 | ||
12908 | while (data < end) | |
12909 | { | |
12910 | const unsigned char * sym_name = data; | |
12911 | data += strnlen ((const char *) sym_name, end - data) + 1; | |
12912 | if (data >= end) | |
12913 | goto fail; | |
12914 | ||
12915 | const unsigned char * comdat_key = data; | |
12916 | data += strnlen ((const char *) comdat_key, end - data) + 1; | |
12917 | if (data >= end) | |
12918 | goto fail; | |
12919 | ||
12920 | if (data + 2 + 8 + 4 > end) | |
12921 | goto fail; | |
12922 | ||
12923 | unsigned int kind = *data++; | |
12924 | unsigned int visibility = *data++; | |
12925 | ||
12926 | elf_vma size = byte_get (data, 8); | |
12927 | data += 8; | |
12928 | ||
12929 | elf_vma slot = byte_get (data, 4); | |
12930 | data += 4; | |
12931 | ||
12932 | if (ext_data != NULL) | |
12933 | { | |
12934 | if (ext_data < (ext_data_end - 1)) | |
12935 | { | |
12936 | unsigned int sym_type = * ext_data ++; | |
12937 | unsigned int sec_kind = * ext_data ++; | |
12938 | ||
12939 | printf (" %10s %10s %11s %08lx %08lx %9s %08lx _", | |
12940 | * comdat_key == 0 ? "-" : (char *) comdat_key, | |
12941 | get_lto_kind (kind), | |
12942 | get_lto_visibility (visibility), | |
12943 | (long) size, | |
12944 | (long) slot, | |
12945 | get_lto_sym_type (sym_type), | |
12946 | (long) sec_kind); | |
12947 | print_symbol (6, (const char *) sym_name); | |
12948 | } | |
12949 | else | |
12950 | { | |
12951 | error (_("Ran out of LTO symbol extension data\n")); | |
12952 | ext_data = NULL; | |
12953 | /* FIXME: return FAIL result ? */ | |
12954 | } | |
12955 | } | |
12956 | else | |
12957 | { | |
12958 | printf (" %10s %10s %11s %08lx %08lx _", | |
12959 | * comdat_key == 0 ? "-" : (char *) comdat_key, | |
12960 | get_lto_kind (kind), | |
12961 | get_lto_visibility (visibility), | |
12962 | (long) size, | |
12963 | (long) slot); | |
12964 | print_symbol (21, (const char *) sym_name); | |
12965 | } | |
12966 | putchar ('\n'); | |
12967 | } | |
12968 | ||
12969 | if (ext_data != NULL && ext_data < ext_data_end) | |
12970 | { | |
12971 | error (_("Data remains in the LTO symbol extension table\n")); | |
12972 | goto fail; | |
12973 | } | |
12974 | ||
12975 | free (alloced_data); | |
12976 | free (ext_data_orig); | |
12977 | free (ext_name); | |
015dc7e1 | 12978 | return true; |
b9e920ec | 12979 | |
0f03783c NC |
12980 | fail: |
12981 | error (_("Buffer overrun encountered whilst decoding LTO symbol table\n")); | |
12982 | free (alloced_data); | |
12983 | free (ext_data_orig); | |
12984 | free (ext_name); | |
015dc7e1 | 12985 | return false; |
0f03783c NC |
12986 | } |
12987 | ||
12988 | /* Display LTO symbol tables. */ | |
12989 | ||
015dc7e1 | 12990 | static bool |
0f03783c NC |
12991 | process_lto_symbol_tables (Filedata * filedata) |
12992 | { | |
12993 | Elf_Internal_Shdr * section; | |
12994 | unsigned int i; | |
015dc7e1 | 12995 | bool res = true; |
0f03783c NC |
12996 | |
12997 | if (!do_lto_syms) | |
015dc7e1 | 12998 | return true; |
0f03783c NC |
12999 | |
13000 | if (filedata->section_headers == NULL) | |
015dc7e1 | 13001 | return true; |
0f03783c NC |
13002 | |
13003 | for (i = 0, section = filedata->section_headers; | |
13004 | i < filedata->file_header.e_shnum; | |
13005 | i++, section++) | |
84714f86 AM |
13006 | if (section_name_valid (filedata, section) |
13007 | && startswith (section_name (filedata, section), ".gnu.lto_.symtab.")) | |
0f03783c NC |
13008 | res &= display_lto_symtab (filedata, section); |
13009 | ||
b9e920ec | 13010 | return res; |
0f03783c NC |
13011 | } |
13012 | ||
10ca4b04 | 13013 | /* Dump the symbol table. */ |
0f03783c | 13014 | |
015dc7e1 | 13015 | static bool |
10ca4b04 L |
13016 | process_symbol_table (Filedata * filedata) |
13017 | { | |
13018 | Elf_Internal_Shdr * section; | |
f16a9783 | 13019 | |
10ca4b04 | 13020 | if (!do_syms && !do_dyn_syms && !do_histogram) |
015dc7e1 | 13021 | return true; |
6bd1a22c | 13022 | |
978c4450 | 13023 | if ((filedata->dynamic_info[DT_HASH] || filedata->dynamic_info_DT_GNU_HASH) |
6bd1a22c L |
13024 | && do_syms |
13025 | && do_using_dynamic | |
978c4450 AM |
13026 | && filedata->dynamic_strings != NULL |
13027 | && filedata->dynamic_symbols != NULL) | |
6bd1a22c | 13028 | { |
10ca4b04 | 13029 | unsigned long si; |
6bd1a22c | 13030 | |
ca0e11aa NC |
13031 | if (filedata->is_separate) |
13032 | { | |
13033 | printf (ngettext ("\nIn linked file '%s' the dynamic symbol table contains %lu entry:\n", | |
13034 | "\nIn linked file '%s' the dynamic symbol table contains %lu entries:\n", | |
13035 | filedata->num_dynamic_syms), | |
13036 | filedata->file_name, | |
13037 | filedata->num_dynamic_syms); | |
13038 | } | |
13039 | else | |
13040 | { | |
13041 | printf (ngettext ("\nSymbol table for image contains %lu entry:\n", | |
13042 | "\nSymbol table for image contains %lu entries:\n", | |
13043 | filedata->num_dynamic_syms), | |
13044 | filedata->num_dynamic_syms); | |
13045 | } | |
10ca4b04 L |
13046 | if (is_32bit_elf) |
13047 | printf (_(" Num: Value Size Type Bind Vis Ndx Name\n")); | |
13048 | else | |
13049 | printf (_(" Num: Value Size Type Bind Vis Ndx Name\n")); | |
6bd1a22c | 13050 | |
978c4450 AM |
13051 | for (si = 0; si < filedata->num_dynamic_syms; si++) |
13052 | print_dynamic_symbol (filedata, si, filedata->dynamic_symbols, NULL, | |
13053 | filedata->dynamic_strings, | |
13054 | filedata->dynamic_strings_length); | |
252b5132 | 13055 | } |
8b73c356 | 13056 | else if ((do_dyn_syms || (do_syms && !do_using_dynamic)) |
dda8d76d | 13057 | && filedata->section_headers != NULL) |
252b5132 | 13058 | { |
b34976b6 | 13059 | unsigned int i; |
252b5132 | 13060 | |
dda8d76d NC |
13061 | for (i = 0, section = filedata->section_headers; |
13062 | i < filedata->file_header.e_shnum; | |
252b5132 RH |
13063 | i++, section++) |
13064 | { | |
2cf0635d | 13065 | char * strtab = NULL; |
c256ffe7 | 13066 | unsigned long int strtab_size = 0; |
2cf0635d | 13067 | Elf_Internal_Sym * symtab; |
ef3df110 | 13068 | unsigned long si, num_syms; |
252b5132 | 13069 | |
2c610e4b L |
13070 | if ((section->sh_type != SHT_SYMTAB |
13071 | && section->sh_type != SHT_DYNSYM) | |
13072 | || (!do_syms | |
13073 | && section->sh_type == SHT_SYMTAB)) | |
252b5132 RH |
13074 | continue; |
13075 | ||
dd24e3da NC |
13076 | if (section->sh_entsize == 0) |
13077 | { | |
13078 | printf (_("\nSymbol table '%s' has a sh_entsize of zero!\n"), | |
dda8d76d | 13079 | printable_section_name (filedata, section)); |
dd24e3da NC |
13080 | continue; |
13081 | } | |
13082 | ||
d3a49aa8 | 13083 | num_syms = section->sh_size / section->sh_entsize; |
ca0e11aa NC |
13084 | |
13085 | if (filedata->is_separate) | |
13086 | printf (ngettext ("\nIn linked file '%s' symbol section '%s' contains %lu entry:\n", | |
13087 | "\nIn linked file '%s' symbol section '%s' contains %lu entries:\n", | |
13088 | num_syms), | |
13089 | filedata->file_name, | |
13090 | printable_section_name (filedata, section), | |
13091 | num_syms); | |
13092 | else | |
13093 | printf (ngettext ("\nSymbol table '%s' contains %lu entry:\n", | |
13094 | "\nSymbol table '%s' contains %lu entries:\n", | |
13095 | num_syms), | |
13096 | printable_section_name (filedata, section), | |
13097 | num_syms); | |
dd24e3da | 13098 | |
f7a99963 | 13099 | if (is_32bit_elf) |
ca47b30c | 13100 | printf (_(" Num: Value Size Type Bind Vis Ndx Name\n")); |
f7a99963 | 13101 | else |
ca47b30c | 13102 | printf (_(" Num: Value Size Type Bind Vis Ndx Name\n")); |
252b5132 | 13103 | |
4de91c10 | 13104 | symtab = get_elf_symbols (filedata, section, & num_syms); |
252b5132 RH |
13105 | if (symtab == NULL) |
13106 | continue; | |
13107 | ||
dda8d76d | 13108 | if (section->sh_link == filedata->file_header.e_shstrndx) |
c256ffe7 | 13109 | { |
dda8d76d NC |
13110 | strtab = filedata->string_table; |
13111 | strtab_size = filedata->string_table_length; | |
c256ffe7 | 13112 | } |
dda8d76d | 13113 | else if (section->sh_link < filedata->file_header.e_shnum) |
252b5132 | 13114 | { |
2cf0635d | 13115 | Elf_Internal_Shdr * string_sec; |
252b5132 | 13116 | |
dda8d76d | 13117 | string_sec = filedata->section_headers + section->sh_link; |
252b5132 | 13118 | |
dda8d76d | 13119 | strtab = (char *) get_data (NULL, filedata, string_sec->sh_offset, |
3f5e193b NC |
13120 | 1, string_sec->sh_size, |
13121 | _("string table")); | |
c256ffe7 | 13122 | strtab_size = strtab != NULL ? string_sec->sh_size : 0; |
252b5132 RH |
13123 | } |
13124 | ||
10ca4b04 L |
13125 | for (si = 0; si < num_syms; si++) |
13126 | print_dynamic_symbol (filedata, si, symtab, section, | |
13127 | strtab, strtab_size); | |
252b5132 RH |
13128 | |
13129 | free (symtab); | |
dda8d76d | 13130 | if (strtab != filedata->string_table) |
252b5132 RH |
13131 | free (strtab); |
13132 | } | |
13133 | } | |
13134 | else if (do_syms) | |
13135 | printf | |
13136 | (_("\nDynamic symbol information is not available for displaying symbols.\n")); | |
13137 | ||
978c4450 | 13138 | if (do_histogram && filedata->buckets != NULL) |
252b5132 | 13139 | { |
2cf0635d NC |
13140 | unsigned long * lengths; |
13141 | unsigned long * counts; | |
66543521 AM |
13142 | unsigned long hn; |
13143 | bfd_vma si; | |
13144 | unsigned long maxlength = 0; | |
13145 | unsigned long nzero_counts = 0; | |
13146 | unsigned long nsyms = 0; | |
6bd6a03d | 13147 | char *visited; |
252b5132 | 13148 | |
d3a49aa8 AM |
13149 | printf (ngettext ("\nHistogram for bucket list length " |
13150 | "(total of %lu bucket):\n", | |
13151 | "\nHistogram for bucket list length " | |
13152 | "(total of %lu buckets):\n", | |
978c4450 AM |
13153 | (unsigned long) filedata->nbuckets), |
13154 | (unsigned long) filedata->nbuckets); | |
252b5132 | 13155 | |
978c4450 AM |
13156 | lengths = (unsigned long *) calloc (filedata->nbuckets, |
13157 | sizeof (*lengths)); | |
252b5132 RH |
13158 | if (lengths == NULL) |
13159 | { | |
8b73c356 | 13160 | error (_("Out of memory allocating space for histogram buckets\n")); |
fd486f32 | 13161 | goto err_out; |
252b5132 | 13162 | } |
978c4450 AM |
13163 | visited = xcmalloc (filedata->nchains, 1); |
13164 | memset (visited, 0, filedata->nchains); | |
8b73c356 NC |
13165 | |
13166 | printf (_(" Length Number %% of total Coverage\n")); | |
978c4450 | 13167 | for (hn = 0; hn < filedata->nbuckets; ++hn) |
252b5132 | 13168 | { |
978c4450 | 13169 | for (si = filedata->buckets[hn]; si > 0; si = filedata->chains[si]) |
252b5132 | 13170 | { |
b34976b6 | 13171 | ++nsyms; |
252b5132 | 13172 | if (maxlength < ++lengths[hn]) |
b34976b6 | 13173 | ++maxlength; |
978c4450 | 13174 | if (si >= filedata->nchains || visited[si]) |
6bd6a03d AM |
13175 | { |
13176 | error (_("histogram chain is corrupt\n")); | |
13177 | break; | |
13178 | } | |
13179 | visited[si] = 1; | |
252b5132 RH |
13180 | } |
13181 | } | |
6bd6a03d | 13182 | free (visited); |
252b5132 | 13183 | |
3f5e193b | 13184 | counts = (unsigned long *) calloc (maxlength + 1, sizeof (*counts)); |
252b5132 RH |
13185 | if (counts == NULL) |
13186 | { | |
b2e951ec | 13187 | free (lengths); |
8b73c356 | 13188 | error (_("Out of memory allocating space for histogram counts\n")); |
fd486f32 | 13189 | goto err_out; |
252b5132 RH |
13190 | } |
13191 | ||
978c4450 | 13192 | for (hn = 0; hn < filedata->nbuckets; ++hn) |
b34976b6 | 13193 | ++counts[lengths[hn]]; |
252b5132 | 13194 | |
978c4450 | 13195 | if (filedata->nbuckets > 0) |
252b5132 | 13196 | { |
66543521 AM |
13197 | unsigned long i; |
13198 | printf (" 0 %-10lu (%5.1f%%)\n", | |
978c4450 | 13199 | counts[0], (counts[0] * 100.0) / filedata->nbuckets); |
66543521 | 13200 | for (i = 1; i <= maxlength; ++i) |
103f02d3 | 13201 | { |
66543521 AM |
13202 | nzero_counts += counts[i] * i; |
13203 | printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n", | |
978c4450 | 13204 | i, counts[i], (counts[i] * 100.0) / filedata->nbuckets, |
103f02d3 UD |
13205 | (nzero_counts * 100.0) / nsyms); |
13206 | } | |
252b5132 RH |
13207 | } |
13208 | ||
13209 | free (counts); | |
13210 | free (lengths); | |
13211 | } | |
13212 | ||
978c4450 AM |
13213 | free (filedata->buckets); |
13214 | filedata->buckets = NULL; | |
13215 | filedata->nbuckets = 0; | |
13216 | free (filedata->chains); | |
13217 | filedata->chains = NULL; | |
252b5132 | 13218 | |
978c4450 | 13219 | if (do_histogram && filedata->gnubuckets != NULL) |
fdc90cb4 | 13220 | { |
2cf0635d NC |
13221 | unsigned long * lengths; |
13222 | unsigned long * counts; | |
fdc90cb4 JJ |
13223 | unsigned long hn; |
13224 | unsigned long maxlength = 0; | |
13225 | unsigned long nzero_counts = 0; | |
13226 | unsigned long nsyms = 0; | |
fdc90cb4 | 13227 | |
f16a9783 | 13228 | printf (ngettext ("\nHistogram for `%s' bucket list length " |
d3a49aa8 | 13229 | "(total of %lu bucket):\n", |
f16a9783 | 13230 | "\nHistogram for `%s' bucket list length " |
d3a49aa8 | 13231 | "(total of %lu buckets):\n", |
978c4450 AM |
13232 | (unsigned long) filedata->ngnubuckets), |
13233 | GNU_HASH_SECTION_NAME (filedata), | |
13234 | (unsigned long) filedata->ngnubuckets); | |
8b73c356 | 13235 | |
978c4450 AM |
13236 | lengths = (unsigned long *) calloc (filedata->ngnubuckets, |
13237 | sizeof (*lengths)); | |
fdc90cb4 JJ |
13238 | if (lengths == NULL) |
13239 | { | |
8b73c356 | 13240 | error (_("Out of memory allocating space for gnu histogram buckets\n")); |
fd486f32 | 13241 | goto err_out; |
fdc90cb4 JJ |
13242 | } |
13243 | ||
fdc90cb4 JJ |
13244 | printf (_(" Length Number %% of total Coverage\n")); |
13245 | ||
978c4450 AM |
13246 | for (hn = 0; hn < filedata->ngnubuckets; ++hn) |
13247 | if (filedata->gnubuckets[hn] != 0) | |
fdc90cb4 JJ |
13248 | { |
13249 | bfd_vma off, length = 1; | |
13250 | ||
978c4450 | 13251 | for (off = filedata->gnubuckets[hn] - filedata->gnusymidx; |
071436c6 | 13252 | /* PR 17531 file: 010-77222-0.004. */ |
978c4450 AM |
13253 | off < filedata->ngnuchains |
13254 | && (filedata->gnuchains[off] & 1) == 0; | |
071436c6 | 13255 | ++off) |
fdc90cb4 JJ |
13256 | ++length; |
13257 | lengths[hn] = length; | |
13258 | if (length > maxlength) | |
13259 | maxlength = length; | |
13260 | nsyms += length; | |
13261 | } | |
13262 | ||
3f5e193b | 13263 | counts = (unsigned long *) calloc (maxlength + 1, sizeof (*counts)); |
fdc90cb4 JJ |
13264 | if (counts == NULL) |
13265 | { | |
b2e951ec | 13266 | free (lengths); |
8b73c356 | 13267 | error (_("Out of memory allocating space for gnu histogram counts\n")); |
fd486f32 | 13268 | goto err_out; |
fdc90cb4 JJ |
13269 | } |
13270 | ||
978c4450 | 13271 | for (hn = 0; hn < filedata->ngnubuckets; ++hn) |
fdc90cb4 JJ |
13272 | ++counts[lengths[hn]]; |
13273 | ||
978c4450 | 13274 | if (filedata->ngnubuckets > 0) |
fdc90cb4 JJ |
13275 | { |
13276 | unsigned long j; | |
13277 | printf (" 0 %-10lu (%5.1f%%)\n", | |
978c4450 | 13278 | counts[0], (counts[0] * 100.0) / filedata->ngnubuckets); |
fdc90cb4 JJ |
13279 | for (j = 1; j <= maxlength; ++j) |
13280 | { | |
13281 | nzero_counts += counts[j] * j; | |
13282 | printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n", | |
978c4450 | 13283 | j, counts[j], (counts[j] * 100.0) / filedata->ngnubuckets, |
fdc90cb4 JJ |
13284 | (nzero_counts * 100.0) / nsyms); |
13285 | } | |
13286 | } | |
13287 | ||
13288 | free (counts); | |
13289 | free (lengths); | |
fdc90cb4 | 13290 | } |
978c4450 AM |
13291 | free (filedata->gnubuckets); |
13292 | filedata->gnubuckets = NULL; | |
13293 | filedata->ngnubuckets = 0; | |
13294 | free (filedata->gnuchains); | |
13295 | filedata->gnuchains = NULL; | |
13296 | filedata->ngnuchains = 0; | |
13297 | free (filedata->mipsxlat); | |
13298 | filedata->mipsxlat = NULL; | |
015dc7e1 | 13299 | return true; |
fd486f32 AM |
13300 | |
13301 | err_out: | |
978c4450 AM |
13302 | free (filedata->gnubuckets); |
13303 | filedata->gnubuckets = NULL; | |
13304 | filedata->ngnubuckets = 0; | |
13305 | free (filedata->gnuchains); | |
13306 | filedata->gnuchains = NULL; | |
13307 | filedata->ngnuchains = 0; | |
13308 | free (filedata->mipsxlat); | |
13309 | filedata->mipsxlat = NULL; | |
13310 | free (filedata->buckets); | |
13311 | filedata->buckets = NULL; | |
13312 | filedata->nbuckets = 0; | |
13313 | free (filedata->chains); | |
13314 | filedata->chains = NULL; | |
015dc7e1 | 13315 | return false; |
252b5132 RH |
13316 | } |
13317 | ||
015dc7e1 | 13318 | static bool |
ca0e11aa | 13319 | process_syminfo (Filedata * filedata) |
252b5132 | 13320 | { |
b4c96d0d | 13321 | unsigned int i; |
252b5132 | 13322 | |
978c4450 | 13323 | if (filedata->dynamic_syminfo == NULL |
252b5132 RH |
13324 | || !do_dynamic) |
13325 | /* No syminfo, this is ok. */ | |
015dc7e1 | 13326 | return true; |
252b5132 RH |
13327 | |
13328 | /* There better should be a dynamic symbol section. */ | |
978c4450 | 13329 | if (filedata->dynamic_symbols == NULL || filedata->dynamic_strings == NULL) |
015dc7e1 | 13330 | return false; |
252b5132 | 13331 | |
ca0e11aa NC |
13332 | if (filedata->is_separate) |
13333 | printf (ngettext ("\nIn linked file '%s: the dynamic info segment at offset 0x%lx contains %d entry:\n", | |
13334 | "\nIn linked file '%s: the dynamic info segment at offset 0x%lx contains %d entries:\n", | |
13335 | filedata->dynamic_syminfo_nent), | |
13336 | filedata->file_name, | |
13337 | filedata->dynamic_syminfo_offset, | |
13338 | filedata->dynamic_syminfo_nent); | |
13339 | else | |
d3a49aa8 AM |
13340 | printf (ngettext ("\nDynamic info segment at offset 0x%lx " |
13341 | "contains %d entry:\n", | |
13342 | "\nDynamic info segment at offset 0x%lx " | |
13343 | "contains %d entries:\n", | |
978c4450 | 13344 | filedata->dynamic_syminfo_nent), |
ca0e11aa NC |
13345 | filedata->dynamic_syminfo_offset, |
13346 | filedata->dynamic_syminfo_nent); | |
252b5132 RH |
13347 | |
13348 | printf (_(" Num: Name BoundTo Flags\n")); | |
978c4450 | 13349 | for (i = 0; i < filedata->dynamic_syminfo_nent; ++i) |
252b5132 | 13350 | { |
978c4450 | 13351 | unsigned short int flags = filedata->dynamic_syminfo[i].si_flags; |
252b5132 | 13352 | |
31104126 | 13353 | printf ("%4d: ", i); |
978c4450 | 13354 | if (i >= filedata->num_dynamic_syms) |
4082ef84 | 13355 | printf (_("<corrupt index>")); |
84714f86 AM |
13356 | else if (valid_dynamic_name (filedata, filedata->dynamic_symbols[i].st_name)) |
13357 | print_symbol (30, get_dynamic_name (filedata, | |
978c4450 | 13358 | filedata->dynamic_symbols[i].st_name)); |
d79b3d50 | 13359 | else |
978c4450 | 13360 | printf (_("<corrupt: %19ld>"), filedata->dynamic_symbols[i].st_name); |
31104126 | 13361 | putchar (' '); |
252b5132 | 13362 | |
978c4450 | 13363 | switch (filedata->dynamic_syminfo[i].si_boundto) |
252b5132 RH |
13364 | { |
13365 | case SYMINFO_BT_SELF: | |
13366 | fputs ("SELF ", stdout); | |
13367 | break; | |
13368 | case SYMINFO_BT_PARENT: | |
13369 | fputs ("PARENT ", stdout); | |
13370 | break; | |
13371 | default: | |
978c4450 AM |
13372 | if (filedata->dynamic_syminfo[i].si_boundto > 0 |
13373 | && filedata->dynamic_syminfo[i].si_boundto < filedata->dynamic_nent | |
84714f86 | 13374 | && valid_dynamic_name (filedata, |
978c4450 | 13375 | filedata->dynamic_section[filedata->dynamic_syminfo[i].si_boundto].d_un.d_val)) |
31104126 | 13376 | { |
84714f86 | 13377 | print_symbol (10, get_dynamic_name (filedata, |
978c4450 | 13378 | filedata->dynamic_section[filedata->dynamic_syminfo[i].si_boundto].d_un.d_val)); |
31104126 NC |
13379 | putchar (' ' ); |
13380 | } | |
252b5132 | 13381 | else |
978c4450 | 13382 | printf ("%-10d ", filedata->dynamic_syminfo[i].si_boundto); |
252b5132 RH |
13383 | break; |
13384 | } | |
13385 | ||
13386 | if (flags & SYMINFO_FLG_DIRECT) | |
13387 | printf (" DIRECT"); | |
13388 | if (flags & SYMINFO_FLG_PASSTHRU) | |
13389 | printf (" PASSTHRU"); | |
13390 | if (flags & SYMINFO_FLG_COPY) | |
13391 | printf (" COPY"); | |
13392 | if (flags & SYMINFO_FLG_LAZYLOAD) | |
13393 | printf (" LAZYLOAD"); | |
13394 | ||
13395 | puts (""); | |
13396 | } | |
13397 | ||
015dc7e1 | 13398 | return true; |
252b5132 RH |
13399 | } |
13400 | ||
75802ccb CE |
13401 | /* A macro which evaluates to TRUE if the region ADDR .. ADDR + NELEM |
13402 | is contained by the region START .. END. The types of ADDR, START | |
13403 | and END should all be the same. Note both ADDR + NELEM and END | |
13404 | point to just beyond the end of the regions that are being tested. */ | |
13405 | #define IN_RANGE(START,END,ADDR,NELEM) \ | |
13406 | (((ADDR) >= (START)) && ((ADDR) < (END)) && ((ADDR) + (NELEM) <= (END))) | |
b32e566b | 13407 | |
cf13d699 NC |
13408 | /* Check to see if the given reloc needs to be handled in a target specific |
13409 | manner. If so then process the reloc and return TRUE otherwise return | |
f84ce13b NC |
13410 | FALSE. |
13411 | ||
13412 | If called with reloc == NULL, then this is a signal that reloc processing | |
13413 | for the current section has finished, and any saved state should be | |
13414 | discarded. */ | |
09c11c86 | 13415 | |
015dc7e1 | 13416 | static bool |
dda8d76d NC |
13417 | target_specific_reloc_handling (Filedata * filedata, |
13418 | Elf_Internal_Rela * reloc, | |
13419 | unsigned char * start, | |
13420 | unsigned char * end, | |
13421 | Elf_Internal_Sym * symtab, | |
13422 | unsigned long num_syms) | |
252b5132 | 13423 | { |
f84ce13b NC |
13424 | unsigned int reloc_type = 0; |
13425 | unsigned long sym_index = 0; | |
13426 | ||
13427 | if (reloc) | |
13428 | { | |
dda8d76d | 13429 | reloc_type = get_reloc_type (filedata, reloc->r_info); |
f84ce13b NC |
13430 | sym_index = get_reloc_symindex (reloc->r_info); |
13431 | } | |
252b5132 | 13432 | |
dda8d76d | 13433 | switch (filedata->file_header.e_machine) |
252b5132 | 13434 | { |
13761a11 NC |
13435 | case EM_MSP430: |
13436 | case EM_MSP430_OLD: | |
13437 | { | |
13438 | static Elf_Internal_Sym * saved_sym = NULL; | |
13439 | ||
f84ce13b NC |
13440 | if (reloc == NULL) |
13441 | { | |
13442 | saved_sym = NULL; | |
015dc7e1 | 13443 | return true; |
f84ce13b NC |
13444 | } |
13445 | ||
13761a11 NC |
13446 | switch (reloc_type) |
13447 | { | |
13448 | case 10: /* R_MSP430_SYM_DIFF */ | |
7d81bc93 | 13449 | case 12: /* R_MSP430_GNU_SUB_ULEB128 */ |
dda8d76d | 13450 | if (uses_msp430x_relocs (filedata)) |
13761a11 | 13451 | break; |
1a0670f3 | 13452 | /* Fall through. */ |
13761a11 | 13453 | case 21: /* R_MSP430X_SYM_DIFF */ |
7d81bc93 | 13454 | case 23: /* R_MSP430X_GNU_SUB_ULEB128 */ |
f84ce13b NC |
13455 | /* PR 21139. */ |
13456 | if (sym_index >= num_syms) | |
13457 | error (_("MSP430 SYM_DIFF reloc contains invalid symbol index %lu\n"), | |
13458 | sym_index); | |
13459 | else | |
13460 | saved_sym = symtab + sym_index; | |
015dc7e1 | 13461 | return true; |
13761a11 NC |
13462 | |
13463 | case 1: /* R_MSP430_32 or R_MSP430_ABS32 */ | |
13464 | case 3: /* R_MSP430_16 or R_MSP430_ABS8 */ | |
13465 | goto handle_sym_diff; | |
0b4362b0 | 13466 | |
13761a11 NC |
13467 | case 5: /* R_MSP430_16_BYTE */ |
13468 | case 9: /* R_MSP430_8 */ | |
7d81bc93 | 13469 | case 11: /* R_MSP430_GNU_SET_ULEB128 */ |
dda8d76d | 13470 | if (uses_msp430x_relocs (filedata)) |
13761a11 NC |
13471 | break; |
13472 | goto handle_sym_diff; | |
13473 | ||
13474 | case 2: /* R_MSP430_ABS16 */ | |
13475 | case 15: /* R_MSP430X_ABS16 */ | |
7d81bc93 | 13476 | case 22: /* R_MSP430X_GNU_SET_ULEB128 */ |
dda8d76d | 13477 | if (! uses_msp430x_relocs (filedata)) |
13761a11 NC |
13478 | break; |
13479 | goto handle_sym_diff; | |
0b4362b0 | 13480 | |
13761a11 NC |
13481 | handle_sym_diff: |
13482 | if (saved_sym != NULL) | |
13483 | { | |
13484 | bfd_vma value; | |
5a805384 | 13485 | unsigned int reloc_size = 0; |
7d81bc93 JL |
13486 | int leb_ret = 0; |
13487 | switch (reloc_type) | |
13488 | { | |
13489 | case 1: /* R_MSP430_32 or R_MSP430_ABS32 */ | |
13490 | reloc_size = 4; | |
13491 | break; | |
13492 | case 11: /* R_MSP430_GNU_SET_ULEB128 */ | |
13493 | case 22: /* R_MSP430X_GNU_SET_ULEB128 */ | |
5a805384 | 13494 | if (reloc->r_offset < (size_t) (end - start)) |
015dc7e1 | 13495 | read_leb128 (start + reloc->r_offset, end, false, |
5a805384 | 13496 | &reloc_size, &leb_ret); |
7d81bc93 JL |
13497 | break; |
13498 | default: | |
13499 | reloc_size = 2; | |
13500 | break; | |
13501 | } | |
13761a11 | 13502 | |
5a805384 | 13503 | if (leb_ret != 0 || reloc_size == 0 || reloc_size > 8) |
7d81bc93 JL |
13504 | error (_("MSP430 ULEB128 field at 0x%lx contains invalid " |
13505 | "ULEB128 value\n"), | |
13506 | (long) reloc->r_offset); | |
13507 | else if (sym_index >= num_syms) | |
f84ce13b NC |
13508 | error (_("MSP430 reloc contains invalid symbol index %lu\n"), |
13509 | sym_index); | |
03f7786e | 13510 | else |
f84ce13b NC |
13511 | { |
13512 | value = reloc->r_addend + (symtab[sym_index].st_value | |
13513 | - saved_sym->st_value); | |
13514 | ||
b32e566b | 13515 | if (IN_RANGE (start, end, start + reloc->r_offset, reloc_size)) |
f84ce13b | 13516 | byte_put (start + reloc->r_offset, value, reloc_size); |
b32e566b NC |
13517 | else |
13518 | /* PR 21137 */ | |
13519 | error (_("MSP430 sym diff reloc contains invalid offset: 0x%lx\n"), | |
13520 | (long) reloc->r_offset); | |
f84ce13b | 13521 | } |
13761a11 NC |
13522 | |
13523 | saved_sym = NULL; | |
015dc7e1 | 13524 | return true; |
13761a11 NC |
13525 | } |
13526 | break; | |
13527 | ||
13528 | default: | |
13529 | if (saved_sym != NULL) | |
071436c6 | 13530 | error (_("Unhandled MSP430 reloc type found after SYM_DIFF reloc\n")); |
13761a11 NC |
13531 | break; |
13532 | } | |
13533 | break; | |
13534 | } | |
13535 | ||
cf13d699 NC |
13536 | case EM_MN10300: |
13537 | case EM_CYGNUS_MN10300: | |
13538 | { | |
13539 | static Elf_Internal_Sym * saved_sym = NULL; | |
252b5132 | 13540 | |
f84ce13b NC |
13541 | if (reloc == NULL) |
13542 | { | |
13543 | saved_sym = NULL; | |
015dc7e1 | 13544 | return true; |
f84ce13b NC |
13545 | } |
13546 | ||
cf13d699 NC |
13547 | switch (reloc_type) |
13548 | { | |
13549 | case 34: /* R_MN10300_ALIGN */ | |
015dc7e1 | 13550 | return true; |
cf13d699 | 13551 | case 33: /* R_MN10300_SYM_DIFF */ |
f84ce13b NC |
13552 | if (sym_index >= num_syms) |
13553 | error (_("MN10300_SYM_DIFF reloc contains invalid symbol index %lu\n"), | |
13554 | sym_index); | |
13555 | else | |
13556 | saved_sym = symtab + sym_index; | |
015dc7e1 | 13557 | return true; |
f84ce13b | 13558 | |
cf13d699 NC |
13559 | case 1: /* R_MN10300_32 */ |
13560 | case 2: /* R_MN10300_16 */ | |
13561 | if (saved_sym != NULL) | |
13562 | { | |
03f7786e | 13563 | int reloc_size = reloc_type == 1 ? 4 : 2; |
cf13d699 | 13564 | bfd_vma value; |
252b5132 | 13565 | |
f84ce13b NC |
13566 | if (sym_index >= num_syms) |
13567 | error (_("MN10300 reloc contains invalid symbol index %lu\n"), | |
13568 | sym_index); | |
03f7786e | 13569 | else |
f84ce13b NC |
13570 | { |
13571 | value = reloc->r_addend + (symtab[sym_index].st_value | |
13572 | - saved_sym->st_value); | |
13573 | ||
b32e566b | 13574 | if (IN_RANGE (start, end, start + reloc->r_offset, reloc_size)) |
f84ce13b | 13575 | byte_put (start + reloc->r_offset, value, reloc_size); |
b32e566b NC |
13576 | else |
13577 | error (_("MN10300 sym diff reloc contains invalid offset: 0x%lx\n"), | |
13578 | (long) reloc->r_offset); | |
f84ce13b | 13579 | } |
252b5132 | 13580 | |
cf13d699 | 13581 | saved_sym = NULL; |
015dc7e1 | 13582 | return true; |
cf13d699 NC |
13583 | } |
13584 | break; | |
13585 | default: | |
13586 | if (saved_sym != NULL) | |
071436c6 | 13587 | error (_("Unhandled MN10300 reloc type found after SYM_DIFF reloc\n")); |
cf13d699 NC |
13588 | break; |
13589 | } | |
13590 | break; | |
13591 | } | |
6ff71e76 NC |
13592 | |
13593 | case EM_RL78: | |
13594 | { | |
13595 | static bfd_vma saved_sym1 = 0; | |
13596 | static bfd_vma saved_sym2 = 0; | |
13597 | static bfd_vma value; | |
13598 | ||
f84ce13b NC |
13599 | if (reloc == NULL) |
13600 | { | |
13601 | saved_sym1 = saved_sym2 = 0; | |
015dc7e1 | 13602 | return true; |
f84ce13b NC |
13603 | } |
13604 | ||
6ff71e76 NC |
13605 | switch (reloc_type) |
13606 | { | |
13607 | case 0x80: /* R_RL78_SYM. */ | |
13608 | saved_sym1 = saved_sym2; | |
f84ce13b NC |
13609 | if (sym_index >= num_syms) |
13610 | error (_("RL78_SYM reloc contains invalid symbol index %lu\n"), | |
13611 | sym_index); | |
13612 | else | |
13613 | { | |
13614 | saved_sym2 = symtab[sym_index].st_value; | |
13615 | saved_sym2 += reloc->r_addend; | |
13616 | } | |
015dc7e1 | 13617 | return true; |
6ff71e76 NC |
13618 | |
13619 | case 0x83: /* R_RL78_OPsub. */ | |
13620 | value = saved_sym1 - saved_sym2; | |
13621 | saved_sym2 = saved_sym1 = 0; | |
015dc7e1 | 13622 | return true; |
6ff71e76 NC |
13623 | break; |
13624 | ||
13625 | case 0x41: /* R_RL78_ABS32. */ | |
b32e566b | 13626 | if (IN_RANGE (start, end, start + reloc->r_offset, 4)) |
03f7786e | 13627 | byte_put (start + reloc->r_offset, value, 4); |
b32e566b NC |
13628 | else |
13629 | error (_("RL78 sym diff reloc contains invalid offset: 0x%lx\n"), | |
13630 | (long) reloc->r_offset); | |
6ff71e76 | 13631 | value = 0; |
015dc7e1 | 13632 | return true; |
6ff71e76 NC |
13633 | |
13634 | case 0x43: /* R_RL78_ABS16. */ | |
b32e566b | 13635 | if (IN_RANGE (start, end, start + reloc->r_offset, 2)) |
03f7786e | 13636 | byte_put (start + reloc->r_offset, value, 2); |
b32e566b NC |
13637 | else |
13638 | error (_("RL78 sym diff reloc contains invalid offset: 0x%lx\n"), | |
13639 | (long) reloc->r_offset); | |
6ff71e76 | 13640 | value = 0; |
015dc7e1 | 13641 | return true; |
6ff71e76 NC |
13642 | |
13643 | default: | |
13644 | break; | |
13645 | } | |
13646 | break; | |
13647 | } | |
252b5132 RH |
13648 | } |
13649 | ||
015dc7e1 | 13650 | return false; |
252b5132 RH |
13651 | } |
13652 | ||
aca88567 NC |
13653 | /* Returns TRUE iff RELOC_TYPE is a 32-bit absolute RELA relocation used in |
13654 | DWARF debug sections. This is a target specific test. Note - we do not | |
13655 | go through the whole including-target-headers-multiple-times route, (as | |
13656 | we have already done with <elf/h8.h>) because this would become very | |
13657 | messy and even then this function would have to contain target specific | |
13658 | information (the names of the relocs instead of their numeric values). | |
13659 | FIXME: This is not the correct way to solve this problem. The proper way | |
13660 | is to have target specific reloc sizing and typing functions created by | |
13661 | the reloc-macros.h header, in the same way that it already creates the | |
13662 | reloc naming functions. */ | |
13663 | ||
015dc7e1 | 13664 | static bool |
dda8d76d | 13665 | is_32bit_abs_reloc (Filedata * filedata, unsigned int reloc_type) |
aca88567 | 13666 | { |
d347c9df | 13667 | /* Please keep this table alpha-sorted for ease of visual lookup. */ |
dda8d76d | 13668 | switch (filedata->file_header.e_machine) |
aca88567 | 13669 | { |
41e92641 | 13670 | case EM_386: |
22abe556 | 13671 | case EM_IAMCU: |
41e92641 | 13672 | return reloc_type == 1; /* R_386_32. */ |
aca88567 NC |
13673 | case EM_68K: |
13674 | return reloc_type == 1; /* R_68K_32. */ | |
f954747f AM |
13675 | case EM_860: |
13676 | return reloc_type == 1; /* R_860_32. */ | |
13677 | case EM_960: | |
13678 | return reloc_type == 2; /* R_960_32. */ | |
a06ea964 | 13679 | case EM_AARCH64: |
9282b95a JW |
13680 | return (reloc_type == 258 |
13681 | || reloc_type == 1); /* R_AARCH64_ABS32 || R_AARCH64_P32_ABS32 */ | |
aca4efc7 JM |
13682 | case EM_BPF: |
13683 | return reloc_type == 11; /* R_BPF_DATA_32 */ | |
d347c9df PS |
13684 | case EM_ADAPTEVA_EPIPHANY: |
13685 | return reloc_type == 3; | |
aca88567 | 13686 | case EM_ALPHA: |
137b6b5f | 13687 | return reloc_type == 1; /* R_ALPHA_REFLONG. */ |
41e92641 NC |
13688 | case EM_ARC: |
13689 | return reloc_type == 1; /* R_ARC_32. */ | |
886a2506 NC |
13690 | case EM_ARC_COMPACT: |
13691 | case EM_ARC_COMPACT2: | |
13692 | return reloc_type == 4; /* R_ARC_32. */ | |
41e92641 NC |
13693 | case EM_ARM: |
13694 | return reloc_type == 2; /* R_ARM_ABS32 */ | |
cb8f3167 | 13695 | case EM_AVR_OLD: |
aca88567 NC |
13696 | case EM_AVR: |
13697 | return reloc_type == 1; | |
13698 | case EM_BLACKFIN: | |
13699 | return reloc_type == 0x12; /* R_byte4_data. */ | |
13700 | case EM_CRIS: | |
13701 | return reloc_type == 3; /* R_CRIS_32. */ | |
13702 | case EM_CR16: | |
13703 | return reloc_type == 3; /* R_CR16_NUM32. */ | |
13704 | case EM_CRX: | |
13705 | return reloc_type == 15; /* R_CRX_NUM32. */ | |
b8891f8d AJ |
13706 | case EM_CSKY: |
13707 | return reloc_type == 1; /* R_CKCORE_ADDR32. */ | |
aca88567 NC |
13708 | case EM_CYGNUS_FRV: |
13709 | return reloc_type == 1; | |
41e92641 NC |
13710 | case EM_CYGNUS_D10V: |
13711 | case EM_D10V: | |
13712 | return reloc_type == 6; /* R_D10V_32. */ | |
aca88567 NC |
13713 | case EM_CYGNUS_D30V: |
13714 | case EM_D30V: | |
13715 | return reloc_type == 12; /* R_D30V_32_NORMAL. */ | |
41e92641 NC |
13716 | case EM_DLX: |
13717 | return reloc_type == 3; /* R_DLX_RELOC_32. */ | |
aca88567 NC |
13718 | case EM_CYGNUS_FR30: |
13719 | case EM_FR30: | |
13720 | return reloc_type == 3; /* R_FR30_32. */ | |
3f8107ab AM |
13721 | case EM_FT32: |
13722 | return reloc_type == 1; /* R_FT32_32. */ | |
aca88567 NC |
13723 | case EM_H8S: |
13724 | case EM_H8_300: | |
13725 | case EM_H8_300H: | |
13726 | return reloc_type == 1; /* R_H8_DIR32. */ | |
3730236a | 13727 | case EM_IA_64: |
262cdac7 AM |
13728 | return (reloc_type == 0x64 /* R_IA64_SECREL32MSB. */ |
13729 | || reloc_type == 0x65 /* R_IA64_SECREL32LSB. */ | |
13730 | || reloc_type == 0x24 /* R_IA64_DIR32MSB. */ | |
13731 | || reloc_type == 0x25 /* R_IA64_DIR32LSB. */); | |
aca88567 NC |
13732 | case EM_IP2K_OLD: |
13733 | case EM_IP2K: | |
13734 | return reloc_type == 2; /* R_IP2K_32. */ | |
13735 | case EM_IQ2000: | |
13736 | return reloc_type == 2; /* R_IQ2000_32. */ | |
84e94c90 NC |
13737 | case EM_LATTICEMICO32: |
13738 | return reloc_type == 3; /* R_LM32_32. */ | |
e9a0721f | 13739 | case EM_LOONGARCH: |
13740 | return reloc_type == 1; /* R_LARCH_32. */ | |
ff7eeb89 | 13741 | case EM_M32C_OLD: |
aca88567 NC |
13742 | case EM_M32C: |
13743 | return reloc_type == 3; /* R_M32C_32. */ | |
13744 | case EM_M32R: | |
13745 | return reloc_type == 34; /* R_M32R_32_RELA. */ | |
adec12c1 AM |
13746 | case EM_68HC11: |
13747 | case EM_68HC12: | |
13748 | return reloc_type == 6; /* R_M68HC11_32. */ | |
7b4ae824 | 13749 | case EM_S12Z: |
2849d19f JD |
13750 | return reloc_type == 7 || /* R_S12Z_EXT32 */ |
13751 | reloc_type == 6; /* R_S12Z_CW32. */ | |
aca88567 NC |
13752 | case EM_MCORE: |
13753 | return reloc_type == 1; /* R_MCORE_ADDR32. */ | |
13754 | case EM_CYGNUS_MEP: | |
13755 | return reloc_type == 4; /* R_MEP_32. */ | |
a3c62988 NC |
13756 | case EM_METAG: |
13757 | return reloc_type == 2; /* R_METAG_ADDR32. */ | |
137b6b5f AM |
13758 | case EM_MICROBLAZE: |
13759 | return reloc_type == 1; /* R_MICROBLAZE_32. */ | |
aca88567 NC |
13760 | case EM_MIPS: |
13761 | return reloc_type == 2; /* R_MIPS_32. */ | |
13762 | case EM_MMIX: | |
13763 | return reloc_type == 4; /* R_MMIX_32. */ | |
13764 | case EM_CYGNUS_MN10200: | |
13765 | case EM_MN10200: | |
13766 | return reloc_type == 1; /* R_MN10200_32. */ | |
13767 | case EM_CYGNUS_MN10300: | |
13768 | case EM_MN10300: | |
13769 | return reloc_type == 1; /* R_MN10300_32. */ | |
5506d11a AM |
13770 | case EM_MOXIE: |
13771 | return reloc_type == 1; /* R_MOXIE_32. */ | |
aca88567 NC |
13772 | case EM_MSP430_OLD: |
13773 | case EM_MSP430: | |
13761a11 | 13774 | return reloc_type == 1; /* R_MSP430_32 or R_MSP320_ABS32. */ |
aca88567 NC |
13775 | case EM_MT: |
13776 | return reloc_type == 2; /* R_MT_32. */ | |
35c08157 KLC |
13777 | case EM_NDS32: |
13778 | return reloc_type == 20; /* R_NDS32_RELA. */ | |
3e0873ac | 13779 | case EM_ALTERA_NIOS2: |
36591ba1 | 13780 | return reloc_type == 12; /* R_NIOS2_BFD_RELOC_32. */ |
3e0873ac NC |
13781 | case EM_NIOS32: |
13782 | return reloc_type == 1; /* R_NIOS_32. */ | |
73589c9d CS |
13783 | case EM_OR1K: |
13784 | return reloc_type == 1; /* R_OR1K_32. */ | |
aca88567 | 13785 | case EM_PARISC: |
9abca702 | 13786 | return (reloc_type == 1 /* R_PARISC_DIR32. */ |
0df8ad28 | 13787 | || reloc_type == 2 /* R_PARISC_DIR21L. */ |
5fda8eca | 13788 | || reloc_type == 41); /* R_PARISC_SECREL32. */ |
aca88567 NC |
13789 | case EM_PJ: |
13790 | case EM_PJ_OLD: | |
13791 | return reloc_type == 1; /* R_PJ_DATA_DIR32. */ | |
13792 | case EM_PPC64: | |
13793 | return reloc_type == 1; /* R_PPC64_ADDR32. */ | |
13794 | case EM_PPC: | |
13795 | return reloc_type == 1; /* R_PPC_ADDR32. */ | |
2b100bb5 DD |
13796 | case EM_TI_PRU: |
13797 | return reloc_type == 11; /* R_PRU_BFD_RELOC_32. */ | |
e23eba97 NC |
13798 | case EM_RISCV: |
13799 | return reloc_type == 1; /* R_RISCV_32. */ | |
99c513f6 DD |
13800 | case EM_RL78: |
13801 | return reloc_type == 1; /* R_RL78_DIR32. */ | |
c7927a3c NC |
13802 | case EM_RX: |
13803 | return reloc_type == 1; /* R_RX_DIR32. */ | |
f954747f AM |
13804 | case EM_S370: |
13805 | return reloc_type == 1; /* R_I370_ADDR31. */ | |
aca88567 NC |
13806 | case EM_S390_OLD: |
13807 | case EM_S390: | |
13808 | return reloc_type == 4; /* R_S390_32. */ | |
41e92641 NC |
13809 | case EM_SCORE: |
13810 | return reloc_type == 8; /* R_SCORE_ABS32. */ | |
aca88567 NC |
13811 | case EM_SH: |
13812 | return reloc_type == 1; /* R_SH_DIR32. */ | |
13813 | case EM_SPARC32PLUS: | |
13814 | case EM_SPARCV9: | |
13815 | case EM_SPARC: | |
13816 | return reloc_type == 3 /* R_SPARC_32. */ | |
13817 | || reloc_type == 23; /* R_SPARC_UA32. */ | |
a7dd7d05 AM |
13818 | case EM_SPU: |
13819 | return reloc_type == 6; /* R_SPU_ADDR32 */ | |
40b36596 JM |
13820 | case EM_TI_C6000: |
13821 | return reloc_type == 1; /* R_C6000_ABS32. */ | |
aa137e4d NC |
13822 | case EM_TILEGX: |
13823 | return reloc_type == 2; /* R_TILEGX_32. */ | |
13824 | case EM_TILEPRO: | |
13825 | return reloc_type == 1; /* R_TILEPRO_32. */ | |
aca88567 NC |
13826 | case EM_CYGNUS_V850: |
13827 | case EM_V850: | |
13828 | return reloc_type == 6; /* R_V850_ABS32. */ | |
708e2187 NC |
13829 | case EM_V800: |
13830 | return reloc_type == 0x33; /* R_V810_WORD. */ | |
aca88567 NC |
13831 | case EM_VAX: |
13832 | return reloc_type == 1; /* R_VAX_32. */ | |
619ed720 EB |
13833 | case EM_VISIUM: |
13834 | return reloc_type == 3; /* R_VISIUM_32. */ | |
f96bd6c2 PC |
13835 | case EM_WEBASSEMBLY: |
13836 | return reloc_type == 1; /* R_WASM32_32. */ | |
aca88567 | 13837 | case EM_X86_64: |
8a9036a4 | 13838 | case EM_L1OM: |
7a9068fe | 13839 | case EM_K1OM: |
aca88567 | 13840 | return reloc_type == 10; /* R_X86_64_32. */ |
c29aca4a NC |
13841 | case EM_XC16X: |
13842 | case EM_C166: | |
13843 | return reloc_type == 3; /* R_XC16C_ABS_32. */ | |
f6c1a2d5 NC |
13844 | case EM_XGATE: |
13845 | return reloc_type == 4; /* R_XGATE_32. */ | |
aca88567 NC |
13846 | case EM_XSTORMY16: |
13847 | return reloc_type == 1; /* R_XSTROMY16_32. */ | |
13848 | case EM_XTENSA_OLD: | |
13849 | case EM_XTENSA: | |
13850 | return reloc_type == 1; /* R_XTENSA_32. */ | |
6655dba2 SB |
13851 | case EM_Z80: |
13852 | return reloc_type == 6; /* R_Z80_32. */ | |
aca88567 | 13853 | default: |
bee0ee85 NC |
13854 | { |
13855 | static unsigned int prev_warn = 0; | |
13856 | ||
13857 | /* Avoid repeating the same warning multiple times. */ | |
dda8d76d | 13858 | if (prev_warn != filedata->file_header.e_machine) |
bee0ee85 | 13859 | error (_("Missing knowledge of 32-bit reloc types used in DWARF sections of machine number %d\n"), |
dda8d76d NC |
13860 | filedata->file_header.e_machine); |
13861 | prev_warn = filedata->file_header.e_machine; | |
015dc7e1 | 13862 | return false; |
bee0ee85 | 13863 | } |
aca88567 NC |
13864 | } |
13865 | } | |
13866 | ||
13867 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
13868 | a 32-bit pc-relative RELA relocation used in DWARF debug sections. */ | |
13869 | ||
015dc7e1 | 13870 | static bool |
dda8d76d | 13871 | is_32bit_pcrel_reloc (Filedata * filedata, unsigned int reloc_type) |
aca88567 | 13872 | { |
dda8d76d | 13873 | switch (filedata->file_header.e_machine) |
d347c9df | 13874 | /* Please keep this table alpha-sorted for ease of visual lookup. */ |
aca88567 | 13875 | { |
41e92641 | 13876 | case EM_386: |
22abe556 | 13877 | case EM_IAMCU: |
3e0873ac | 13878 | return reloc_type == 2; /* R_386_PC32. */ |
aca88567 | 13879 | case EM_68K: |
3e0873ac | 13880 | return reloc_type == 4; /* R_68K_PC32. */ |
a06ea964 NC |
13881 | case EM_AARCH64: |
13882 | return reloc_type == 261; /* R_AARCH64_PREL32 */ | |
cfb8c092 NC |
13883 | case EM_ADAPTEVA_EPIPHANY: |
13884 | return reloc_type == 6; | |
aca88567 NC |
13885 | case EM_ALPHA: |
13886 | return reloc_type == 10; /* R_ALPHA_SREL32. */ | |
726c18e1 CZ |
13887 | case EM_ARC_COMPACT: |
13888 | case EM_ARC_COMPACT2: | |
13889 | return reloc_type == 49; /* R_ARC_32_PCREL. */ | |
41e92641 | 13890 | case EM_ARM: |
3e0873ac | 13891 | return reloc_type == 3; /* R_ARM_REL32 */ |
d347c9df PS |
13892 | case EM_AVR_OLD: |
13893 | case EM_AVR: | |
13894 | return reloc_type == 36; /* R_AVR_32_PCREL. */ | |
137b6b5f AM |
13895 | case EM_MICROBLAZE: |
13896 | return reloc_type == 2; /* R_MICROBLAZE_32_PCREL. */ | |
73589c9d CS |
13897 | case EM_OR1K: |
13898 | return reloc_type == 9; /* R_OR1K_32_PCREL. */ | |
aca88567 | 13899 | case EM_PARISC: |
85acf597 | 13900 | return reloc_type == 9; /* R_PARISC_PCREL32. */ |
aca88567 NC |
13901 | case EM_PPC: |
13902 | return reloc_type == 26; /* R_PPC_REL32. */ | |
13903 | case EM_PPC64: | |
3e0873ac | 13904 | return reloc_type == 26; /* R_PPC64_REL32. */ |
25cbdcbb AS |
13905 | case EM_RISCV: |
13906 | return reloc_type == 57; /* R_RISCV_32_PCREL. */ | |
aca88567 NC |
13907 | case EM_S390_OLD: |
13908 | case EM_S390: | |
3e0873ac | 13909 | return reloc_type == 5; /* R_390_PC32. */ |
aca88567 | 13910 | case EM_SH: |
3e0873ac | 13911 | return reloc_type == 2; /* R_SH_REL32. */ |
aca88567 NC |
13912 | case EM_SPARC32PLUS: |
13913 | case EM_SPARCV9: | |
13914 | case EM_SPARC: | |
3e0873ac | 13915 | return reloc_type == 6; /* R_SPARC_DISP32. */ |
a7dd7d05 AM |
13916 | case EM_SPU: |
13917 | return reloc_type == 13; /* R_SPU_REL32. */ | |
aa137e4d NC |
13918 | case EM_TILEGX: |
13919 | return reloc_type == 6; /* R_TILEGX_32_PCREL. */ | |
13920 | case EM_TILEPRO: | |
13921 | return reloc_type == 4; /* R_TILEPRO_32_PCREL. */ | |
619ed720 EB |
13922 | case EM_VISIUM: |
13923 | return reloc_type == 6; /* R_VISIUM_32_PCREL */ | |
aca88567 | 13924 | case EM_X86_64: |
8a9036a4 | 13925 | case EM_L1OM: |
7a9068fe | 13926 | case EM_K1OM: |
3e0873ac | 13927 | return reloc_type == 2; /* R_X86_64_PC32. */ |
2057d69d CZ |
13928 | case EM_VAX: |
13929 | return reloc_type == 4; /* R_VAX_PCREL32. */ | |
2fcb9706 BW |
13930 | case EM_XTENSA_OLD: |
13931 | case EM_XTENSA: | |
13932 | return reloc_type == 14; /* R_XTENSA_32_PCREL. */ | |
aca88567 NC |
13933 | default: |
13934 | /* Do not abort or issue an error message here. Not all targets use | |
13935 | pc-relative 32-bit relocs in their DWARF debug information and we | |
13936 | have already tested for target coverage in is_32bit_abs_reloc. A | |
cf13d699 NC |
13937 | more helpful warning message will be generated by apply_relocations |
13938 | anyway, so just return. */ | |
015dc7e1 | 13939 | return false; |
aca88567 NC |
13940 | } |
13941 | } | |
13942 | ||
13943 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
13944 | a 64-bit absolute RELA relocation used in DWARF debug sections. */ | |
13945 | ||
015dc7e1 | 13946 | static bool |
dda8d76d | 13947 | is_64bit_abs_reloc (Filedata * filedata, unsigned int reloc_type) |
aca88567 | 13948 | { |
dda8d76d | 13949 | switch (filedata->file_header.e_machine) |
aca88567 | 13950 | { |
a06ea964 NC |
13951 | case EM_AARCH64: |
13952 | return reloc_type == 257; /* R_AARCH64_ABS64. */ | |
aca88567 NC |
13953 | case EM_ALPHA: |
13954 | return reloc_type == 2; /* R_ALPHA_REFQUAD. */ | |
3730236a | 13955 | case EM_IA_64: |
262cdac7 AM |
13956 | return (reloc_type == 0x26 /* R_IA64_DIR64MSB. */ |
13957 | || reloc_type == 0x27 /* R_IA64_DIR64LSB. */); | |
e9a0721f | 13958 | case EM_LOONGARCH: |
13959 | return reloc_type == 2; /* R_LARCH_64 */ | |
3e0873ac NC |
13960 | case EM_PARISC: |
13961 | return reloc_type == 80; /* R_PARISC_DIR64. */ | |
aca88567 NC |
13962 | case EM_PPC64: |
13963 | return reloc_type == 38; /* R_PPC64_ADDR64. */ | |
e23eba97 NC |
13964 | case EM_RISCV: |
13965 | return reloc_type == 2; /* R_RISCV_64. */ | |
aca88567 NC |
13966 | case EM_SPARC32PLUS: |
13967 | case EM_SPARCV9: | |
13968 | case EM_SPARC: | |
714da62f NC |
13969 | return reloc_type == 32 /* R_SPARC_64. */ |
13970 | || reloc_type == 54; /* R_SPARC_UA64. */ | |
aca88567 | 13971 | case EM_X86_64: |
8a9036a4 | 13972 | case EM_L1OM: |
7a9068fe | 13973 | case EM_K1OM: |
aca88567 | 13974 | return reloc_type == 1; /* R_X86_64_64. */ |
e819ade1 AS |
13975 | case EM_S390_OLD: |
13976 | case EM_S390: | |
aa137e4d NC |
13977 | return reloc_type == 22; /* R_S390_64. */ |
13978 | case EM_TILEGX: | |
13979 | return reloc_type == 1; /* R_TILEGX_64. */ | |
85a82265 | 13980 | case EM_MIPS: |
aa137e4d | 13981 | return reloc_type == 18; /* R_MIPS_64. */ |
aca88567 | 13982 | default: |
015dc7e1 | 13983 | return false; |
aca88567 NC |
13984 | } |
13985 | } | |
13986 | ||
85acf597 RH |
13987 | /* Like is_32bit_pcrel_reloc except that it returns TRUE iff RELOC_TYPE is |
13988 | a 64-bit pc-relative RELA relocation used in DWARF debug sections. */ | |
13989 | ||
015dc7e1 | 13990 | static bool |
dda8d76d | 13991 | is_64bit_pcrel_reloc (Filedata * filedata, unsigned int reloc_type) |
85acf597 | 13992 | { |
dda8d76d | 13993 | switch (filedata->file_header.e_machine) |
85acf597 | 13994 | { |
a06ea964 NC |
13995 | case EM_AARCH64: |
13996 | return reloc_type == 260; /* R_AARCH64_PREL64. */ | |
85acf597 | 13997 | case EM_ALPHA: |
aa137e4d | 13998 | return reloc_type == 11; /* R_ALPHA_SREL64. */ |
85acf597 | 13999 | case EM_IA_64: |
262cdac7 AM |
14000 | return (reloc_type == 0x4e /* R_IA64_PCREL64MSB. */ |
14001 | || reloc_type == 0x4f /* R_IA64_PCREL64LSB. */); | |
85acf597 | 14002 | case EM_PARISC: |
aa137e4d | 14003 | return reloc_type == 72; /* R_PARISC_PCREL64. */ |
85acf597 | 14004 | case EM_PPC64: |
aa137e4d | 14005 | return reloc_type == 44; /* R_PPC64_REL64. */ |
85acf597 RH |
14006 | case EM_SPARC32PLUS: |
14007 | case EM_SPARCV9: | |
14008 | case EM_SPARC: | |
aa137e4d | 14009 | return reloc_type == 46; /* R_SPARC_DISP64. */ |
85acf597 | 14010 | case EM_X86_64: |
8a9036a4 | 14011 | case EM_L1OM: |
7a9068fe | 14012 | case EM_K1OM: |
aa137e4d | 14013 | return reloc_type == 24; /* R_X86_64_PC64. */ |
85acf597 RH |
14014 | case EM_S390_OLD: |
14015 | case EM_S390: | |
aa137e4d NC |
14016 | return reloc_type == 23; /* R_S390_PC64. */ |
14017 | case EM_TILEGX: | |
14018 | return reloc_type == 5; /* R_TILEGX_64_PCREL. */ | |
85acf597 | 14019 | default: |
015dc7e1 | 14020 | return false; |
85acf597 RH |
14021 | } |
14022 | } | |
14023 | ||
4dc3c23d AM |
14024 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is |
14025 | a 24-bit absolute RELA relocation used in DWARF debug sections. */ | |
14026 | ||
015dc7e1 | 14027 | static bool |
dda8d76d | 14028 | is_24bit_abs_reloc (Filedata * filedata, unsigned int reloc_type) |
4dc3c23d | 14029 | { |
dda8d76d | 14030 | switch (filedata->file_header.e_machine) |
4dc3c23d AM |
14031 | { |
14032 | case EM_CYGNUS_MN10200: | |
14033 | case EM_MN10200: | |
14034 | return reloc_type == 4; /* R_MN10200_24. */ | |
3ee6e4fb NC |
14035 | case EM_FT32: |
14036 | return reloc_type == 5; /* R_FT32_20. */ | |
6655dba2 SB |
14037 | case EM_Z80: |
14038 | return reloc_type == 5; /* R_Z80_24. */ | |
4dc3c23d | 14039 | default: |
015dc7e1 | 14040 | return false; |
4dc3c23d AM |
14041 | } |
14042 | } | |
14043 | ||
aca88567 NC |
14044 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is |
14045 | a 16-bit absolute RELA relocation used in DWARF debug sections. */ | |
14046 | ||
015dc7e1 | 14047 | static bool |
dda8d76d | 14048 | is_16bit_abs_reloc (Filedata * filedata, unsigned int reloc_type) |
4b78141a | 14049 | { |
d347c9df | 14050 | /* Please keep this table alpha-sorted for ease of visual lookup. */ |
dda8d76d | 14051 | switch (filedata->file_header.e_machine) |
4b78141a | 14052 | { |
886a2506 NC |
14053 | case EM_ARC: |
14054 | case EM_ARC_COMPACT: | |
14055 | case EM_ARC_COMPACT2: | |
14056 | return reloc_type == 2; /* R_ARC_16. */ | |
d347c9df PS |
14057 | case EM_ADAPTEVA_EPIPHANY: |
14058 | return reloc_type == 5; | |
aca88567 NC |
14059 | case EM_AVR_OLD: |
14060 | case EM_AVR: | |
14061 | return reloc_type == 4; /* R_AVR_16. */ | |
41e92641 NC |
14062 | case EM_CYGNUS_D10V: |
14063 | case EM_D10V: | |
14064 | return reloc_type == 3; /* R_D10V_16. */ | |
81b42bca JB |
14065 | case EM_FT32: |
14066 | return reloc_type == 2; /* R_FT32_16. */ | |
4b78141a NC |
14067 | case EM_H8S: |
14068 | case EM_H8_300: | |
14069 | case EM_H8_300H: | |
aca88567 NC |
14070 | return reloc_type == R_H8_DIR16; |
14071 | case EM_IP2K_OLD: | |
14072 | case EM_IP2K: | |
14073 | return reloc_type == 1; /* R_IP2K_16. */ | |
ff7eeb89 | 14074 | case EM_M32C_OLD: |
f4236fe4 DD |
14075 | case EM_M32C: |
14076 | return reloc_type == 1; /* R_M32C_16 */ | |
d347c9df PS |
14077 | case EM_CYGNUS_MN10200: |
14078 | case EM_MN10200: | |
14079 | return reloc_type == 2; /* R_MN10200_16. */ | |
14080 | case EM_CYGNUS_MN10300: | |
14081 | case EM_MN10300: | |
14082 | return reloc_type == 2; /* R_MN10300_16. */ | |
aca88567 | 14083 | case EM_MSP430: |
dda8d76d | 14084 | if (uses_msp430x_relocs (filedata)) |
13761a11 | 14085 | return reloc_type == 2; /* R_MSP430_ABS16. */ |
1a0670f3 | 14086 | /* Fall through. */ |
78c8d46c | 14087 | case EM_MSP430_OLD: |
aca88567 | 14088 | return reloc_type == 5; /* R_MSP430_16_BYTE. */ |
35c08157 KLC |
14089 | case EM_NDS32: |
14090 | return reloc_type == 19; /* R_NDS32_RELA. */ | |
3e0873ac | 14091 | case EM_ALTERA_NIOS2: |
36591ba1 | 14092 | return reloc_type == 13; /* R_NIOS2_BFD_RELOC_16. */ |
3e0873ac NC |
14093 | case EM_NIOS32: |
14094 | return reloc_type == 9; /* R_NIOS_16. */ | |
73589c9d CS |
14095 | case EM_OR1K: |
14096 | return reloc_type == 2; /* R_OR1K_16. */ | |
39e07931 AS |
14097 | case EM_RISCV: |
14098 | return reloc_type == 55; /* R_RISCV_SET16. */ | |
2b100bb5 DD |
14099 | case EM_TI_PRU: |
14100 | return reloc_type == 8; /* R_PRU_BFD_RELOC_16. */ | |
40b36596 JM |
14101 | case EM_TI_C6000: |
14102 | return reloc_type == 2; /* R_C6000_ABS16. */ | |
d347c9df PS |
14103 | case EM_VISIUM: |
14104 | return reloc_type == 2; /* R_VISIUM_16. */ | |
c29aca4a NC |
14105 | case EM_XC16X: |
14106 | case EM_C166: | |
14107 | return reloc_type == 2; /* R_XC16C_ABS_16. */ | |
f6c1a2d5 NC |
14108 | case EM_XGATE: |
14109 | return reloc_type == 3; /* R_XGATE_16. */ | |
6655dba2 SB |
14110 | case EM_Z80: |
14111 | return reloc_type == 4; /* R_Z80_16. */ | |
4b78141a | 14112 | default: |
015dc7e1 | 14113 | return false; |
4b78141a NC |
14114 | } |
14115 | } | |
14116 | ||
39e07931 AS |
14117 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is |
14118 | a 8-bit absolute RELA relocation used in DWARF debug sections. */ | |
14119 | ||
015dc7e1 | 14120 | static bool |
39e07931 AS |
14121 | is_8bit_abs_reloc (Filedata * filedata, unsigned int reloc_type) |
14122 | { | |
14123 | switch (filedata->file_header.e_machine) | |
14124 | { | |
14125 | case EM_RISCV: | |
14126 | return reloc_type == 54; /* R_RISCV_SET8. */ | |
6655dba2 SB |
14127 | case EM_Z80: |
14128 | return reloc_type == 1; /* R_Z80_8. */ | |
39e07931 | 14129 | default: |
015dc7e1 | 14130 | return false; |
39e07931 AS |
14131 | } |
14132 | } | |
14133 | ||
14134 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
14135 | a 6-bit absolute RELA relocation used in DWARF debug sections. */ | |
14136 | ||
015dc7e1 | 14137 | static bool |
39e07931 AS |
14138 | is_6bit_abs_reloc (Filedata * filedata, unsigned int reloc_type) |
14139 | { | |
14140 | switch (filedata->file_header.e_machine) | |
14141 | { | |
14142 | case EM_RISCV: | |
14143 | return reloc_type == 53; /* R_RISCV_SET6. */ | |
14144 | default: | |
015dc7e1 | 14145 | return false; |
39e07931 AS |
14146 | } |
14147 | } | |
14148 | ||
03336641 JW |
14149 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is |
14150 | a 32-bit inplace add RELA relocation used in DWARF debug sections. */ | |
14151 | ||
015dc7e1 | 14152 | static bool |
03336641 JW |
14153 | is_32bit_inplace_add_reloc (Filedata * filedata, unsigned int reloc_type) |
14154 | { | |
14155 | /* Please keep this table alpha-sorted for ease of visual lookup. */ | |
14156 | switch (filedata->file_header.e_machine) | |
14157 | { | |
14158 | case EM_RISCV: | |
14159 | return reloc_type == 35; /* R_RISCV_ADD32. */ | |
14160 | default: | |
015dc7e1 | 14161 | return false; |
03336641 JW |
14162 | } |
14163 | } | |
14164 | ||
14165 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
14166 | a 32-bit inplace sub RELA relocation used in DWARF debug sections. */ | |
14167 | ||
015dc7e1 | 14168 | static bool |
03336641 JW |
14169 | is_32bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type) |
14170 | { | |
14171 | /* Please keep this table alpha-sorted for ease of visual lookup. */ | |
14172 | switch (filedata->file_header.e_machine) | |
14173 | { | |
14174 | case EM_RISCV: | |
14175 | return reloc_type == 39; /* R_RISCV_SUB32. */ | |
14176 | default: | |
015dc7e1 | 14177 | return false; |
03336641 JW |
14178 | } |
14179 | } | |
14180 | ||
14181 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
14182 | a 64-bit inplace add RELA relocation used in DWARF debug sections. */ | |
14183 | ||
015dc7e1 | 14184 | static bool |
03336641 JW |
14185 | is_64bit_inplace_add_reloc (Filedata * filedata, unsigned int reloc_type) |
14186 | { | |
14187 | /* Please keep this table alpha-sorted for ease of visual lookup. */ | |
14188 | switch (filedata->file_header.e_machine) | |
14189 | { | |
14190 | case EM_RISCV: | |
14191 | return reloc_type == 36; /* R_RISCV_ADD64. */ | |
14192 | default: | |
015dc7e1 | 14193 | return false; |
03336641 JW |
14194 | } |
14195 | } | |
14196 | ||
14197 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
14198 | a 64-bit inplace sub RELA relocation used in DWARF debug sections. */ | |
14199 | ||
015dc7e1 | 14200 | static bool |
03336641 JW |
14201 | is_64bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type) |
14202 | { | |
14203 | /* Please keep this table alpha-sorted for ease of visual lookup. */ | |
14204 | switch (filedata->file_header.e_machine) | |
14205 | { | |
14206 | case EM_RISCV: | |
14207 | return reloc_type == 40; /* R_RISCV_SUB64. */ | |
14208 | default: | |
015dc7e1 | 14209 | return false; |
03336641 JW |
14210 | } |
14211 | } | |
14212 | ||
14213 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
14214 | a 16-bit inplace add RELA relocation used in DWARF debug sections. */ | |
14215 | ||
015dc7e1 | 14216 | static bool |
03336641 JW |
14217 | is_16bit_inplace_add_reloc (Filedata * filedata, unsigned int reloc_type) |
14218 | { | |
14219 | /* Please keep this table alpha-sorted for ease of visual lookup. */ | |
14220 | switch (filedata->file_header.e_machine) | |
14221 | { | |
14222 | case EM_RISCV: | |
14223 | return reloc_type == 34; /* R_RISCV_ADD16. */ | |
14224 | default: | |
015dc7e1 | 14225 | return false; |
03336641 JW |
14226 | } |
14227 | } | |
14228 | ||
14229 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
14230 | a 16-bit inplace sub RELA relocation used in DWARF debug sections. */ | |
14231 | ||
015dc7e1 | 14232 | static bool |
03336641 JW |
14233 | is_16bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type) |
14234 | { | |
14235 | /* Please keep this table alpha-sorted for ease of visual lookup. */ | |
14236 | switch (filedata->file_header.e_machine) | |
14237 | { | |
14238 | case EM_RISCV: | |
14239 | return reloc_type == 38; /* R_RISCV_SUB16. */ | |
14240 | default: | |
015dc7e1 | 14241 | return false; |
03336641 JW |
14242 | } |
14243 | } | |
14244 | ||
14245 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
14246 | a 8-bit inplace add RELA relocation used in DWARF debug sections. */ | |
14247 | ||
015dc7e1 | 14248 | static bool |
03336641 JW |
14249 | is_8bit_inplace_add_reloc (Filedata * filedata, unsigned int reloc_type) |
14250 | { | |
14251 | /* Please keep this table alpha-sorted for ease of visual lookup. */ | |
14252 | switch (filedata->file_header.e_machine) | |
14253 | { | |
14254 | case EM_RISCV: | |
14255 | return reloc_type == 33; /* R_RISCV_ADD8. */ | |
14256 | default: | |
015dc7e1 | 14257 | return false; |
03336641 JW |
14258 | } |
14259 | } | |
14260 | ||
14261 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
14262 | a 8-bit inplace sub RELA relocation used in DWARF debug sections. */ | |
14263 | ||
015dc7e1 | 14264 | static bool |
03336641 JW |
14265 | is_8bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type) |
14266 | { | |
14267 | /* Please keep this table alpha-sorted for ease of visual lookup. */ | |
14268 | switch (filedata->file_header.e_machine) | |
14269 | { | |
14270 | case EM_RISCV: | |
14271 | return reloc_type == 37; /* R_RISCV_SUB8. */ | |
14272 | default: | |
015dc7e1 | 14273 | return false; |
03336641 JW |
14274 | } |
14275 | } | |
14276 | ||
39e07931 AS |
14277 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is |
14278 | a 6-bit inplace sub RELA relocation used in DWARF debug sections. */ | |
14279 | ||
015dc7e1 | 14280 | static bool |
39e07931 AS |
14281 | is_6bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type) |
14282 | { | |
14283 | switch (filedata->file_header.e_machine) | |
14284 | { | |
14285 | case EM_RISCV: | |
14286 | return reloc_type == 52; /* R_RISCV_SUB6. */ | |
14287 | default: | |
015dc7e1 | 14288 | return false; |
39e07931 AS |
14289 | } |
14290 | } | |
14291 | ||
2a7b2e88 JK |
14292 | /* Returns TRUE iff RELOC_TYPE is a NONE relocation used for discarded |
14293 | relocation entries (possibly formerly used for SHT_GROUP sections). */ | |
14294 | ||
015dc7e1 | 14295 | static bool |
dda8d76d | 14296 | is_none_reloc (Filedata * filedata, unsigned int reloc_type) |
2a7b2e88 | 14297 | { |
dda8d76d | 14298 | switch (filedata->file_header.e_machine) |
2a7b2e88 | 14299 | { |
cb8f3167 | 14300 | case EM_386: /* R_386_NONE. */ |
d347c9df | 14301 | case EM_68K: /* R_68K_NONE. */ |
cfb8c092 | 14302 | case EM_ADAPTEVA_EPIPHANY: |
d347c9df PS |
14303 | case EM_ALPHA: /* R_ALPHA_NONE. */ |
14304 | case EM_ALTERA_NIOS2: /* R_NIOS2_NONE. */ | |
886a2506 | 14305 | case EM_ARC: /* R_ARC_NONE. */ |
886a2506 | 14306 | case EM_ARC_COMPACT2: /* R_ARC_NONE. */ |
d347c9df | 14307 | case EM_ARC_COMPACT: /* R_ARC_NONE. */ |
cb8f3167 | 14308 | case EM_ARM: /* R_ARM_NONE. */ |
d347c9df | 14309 | case EM_C166: /* R_XC16X_NONE. */ |
cb8f3167 | 14310 | case EM_CRIS: /* R_CRIS_NONE. */ |
d347c9df PS |
14311 | case EM_FT32: /* R_FT32_NONE. */ |
14312 | case EM_IA_64: /* R_IA64_NONE. */ | |
7a9068fe | 14313 | case EM_K1OM: /* R_X86_64_NONE. */ |
d347c9df PS |
14314 | case EM_L1OM: /* R_X86_64_NONE. */ |
14315 | case EM_M32R: /* R_M32R_NONE. */ | |
14316 | case EM_MIPS: /* R_MIPS_NONE. */ | |
cb8f3167 | 14317 | case EM_MN10300: /* R_MN10300_NONE. */ |
5506d11a | 14318 | case EM_MOXIE: /* R_MOXIE_NONE. */ |
d347c9df PS |
14319 | case EM_NIOS32: /* R_NIOS_NONE. */ |
14320 | case EM_OR1K: /* R_OR1K_NONE. */ | |
14321 | case EM_PARISC: /* R_PARISC_NONE. */ | |
14322 | case EM_PPC64: /* R_PPC64_NONE. */ | |
14323 | case EM_PPC: /* R_PPC_NONE. */ | |
e23eba97 | 14324 | case EM_RISCV: /* R_RISCV_NONE. */ |
d347c9df PS |
14325 | case EM_S390: /* R_390_NONE. */ |
14326 | case EM_S390_OLD: | |
14327 | case EM_SH: /* R_SH_NONE. */ | |
14328 | case EM_SPARC32PLUS: | |
14329 | case EM_SPARC: /* R_SPARC_NONE. */ | |
14330 | case EM_SPARCV9: | |
aa137e4d NC |
14331 | case EM_TILEGX: /* R_TILEGX_NONE. */ |
14332 | case EM_TILEPRO: /* R_TILEPRO_NONE. */ | |
d347c9df PS |
14333 | case EM_TI_C6000:/* R_C6000_NONE. */ |
14334 | case EM_X86_64: /* R_X86_64_NONE. */ | |
c29aca4a | 14335 | case EM_XC16X: |
6655dba2 | 14336 | case EM_Z80: /* R_Z80_NONE. */ |
f96bd6c2 | 14337 | case EM_WEBASSEMBLY: /* R_WASM32_NONE. */ |
cb8f3167 | 14338 | return reloc_type == 0; |
d347c9df | 14339 | |
a06ea964 NC |
14340 | case EM_AARCH64: |
14341 | return reloc_type == 0 || reloc_type == 256; | |
d347c9df PS |
14342 | case EM_AVR_OLD: |
14343 | case EM_AVR: | |
14344 | return (reloc_type == 0 /* R_AVR_NONE. */ | |
14345 | || reloc_type == 30 /* R_AVR_DIFF8. */ | |
14346 | || reloc_type == 31 /* R_AVR_DIFF16. */ | |
14347 | || reloc_type == 32 /* R_AVR_DIFF32. */); | |
14348 | case EM_METAG: | |
14349 | return reloc_type == 3; /* R_METAG_NONE. */ | |
35c08157 KLC |
14350 | case EM_NDS32: |
14351 | return (reloc_type == 0 /* R_XTENSA_NONE. */ | |
14352 | || reloc_type == 204 /* R_NDS32_DIFF8. */ | |
14353 | || reloc_type == 205 /* R_NDS32_DIFF16. */ | |
14354 | || reloc_type == 206 /* R_NDS32_DIFF32. */ | |
14355 | || reloc_type == 207 /* R_NDS32_ULEB128. */); | |
2b100bb5 DD |
14356 | case EM_TI_PRU: |
14357 | return (reloc_type == 0 /* R_PRU_NONE. */ | |
14358 | || reloc_type == 65 /* R_PRU_DIFF8. */ | |
14359 | || reloc_type == 66 /* R_PRU_DIFF16. */ | |
14360 | || reloc_type == 67 /* R_PRU_DIFF32. */); | |
58332dda JK |
14361 | case EM_XTENSA_OLD: |
14362 | case EM_XTENSA: | |
4dc3c23d AM |
14363 | return (reloc_type == 0 /* R_XTENSA_NONE. */ |
14364 | || reloc_type == 17 /* R_XTENSA_DIFF8. */ | |
14365 | || reloc_type == 18 /* R_XTENSA_DIFF16. */ | |
30ce8e47 MF |
14366 | || reloc_type == 19 /* R_XTENSA_DIFF32. */ |
14367 | || reloc_type == 57 /* R_XTENSA_PDIFF8. */ | |
14368 | || reloc_type == 58 /* R_XTENSA_PDIFF16. */ | |
14369 | || reloc_type == 59 /* R_XTENSA_PDIFF32. */ | |
14370 | || reloc_type == 60 /* R_XTENSA_NDIFF8. */ | |
14371 | || reloc_type == 61 /* R_XTENSA_NDIFF16. */ | |
14372 | || reloc_type == 62 /* R_XTENSA_NDIFF32. */); | |
2a7b2e88 | 14373 | } |
015dc7e1 | 14374 | return false; |
2a7b2e88 JK |
14375 | } |
14376 | ||
d1c4b12b NC |
14377 | /* Returns TRUE if there is a relocation against |
14378 | section NAME at OFFSET bytes. */ | |
14379 | ||
015dc7e1 | 14380 | bool |
d1c4b12b NC |
14381 | reloc_at (struct dwarf_section * dsec, dwarf_vma offset) |
14382 | { | |
14383 | Elf_Internal_Rela * relocs; | |
14384 | Elf_Internal_Rela * rp; | |
14385 | ||
14386 | if (dsec == NULL || dsec->reloc_info == NULL) | |
015dc7e1 | 14387 | return false; |
d1c4b12b NC |
14388 | |
14389 | relocs = (Elf_Internal_Rela *) dsec->reloc_info; | |
14390 | ||
14391 | for (rp = relocs; rp < relocs + dsec->num_relocs; ++rp) | |
14392 | if (rp->r_offset == offset) | |
015dc7e1 | 14393 | return true; |
d1c4b12b | 14394 | |
015dc7e1 | 14395 | return false; |
d1c4b12b NC |
14396 | } |
14397 | ||
cf13d699 | 14398 | /* Apply relocations to a section. |
32ec8896 NC |
14399 | Returns TRUE upon success, FALSE otherwise. |
14400 | If RELOCS_RETURN is non-NULL then it is set to point to the loaded relocs. | |
14401 | It is then the caller's responsibility to free them. NUM_RELOCS_RETURN | |
14402 | will be set to the number of relocs loaded. | |
14403 | ||
cf13d699 | 14404 | Note: So far support has been added only for those relocations |
32ec8896 NC |
14405 | which can be found in debug sections. FIXME: Add support for |
14406 | more relocations ? */ | |
1b315056 | 14407 | |
015dc7e1 | 14408 | static bool |
dda8d76d | 14409 | apply_relocations (Filedata * filedata, |
d1c4b12b NC |
14410 | const Elf_Internal_Shdr * section, |
14411 | unsigned char * start, | |
14412 | bfd_size_type size, | |
1449284b | 14413 | void ** relocs_return, |
d1c4b12b | 14414 | unsigned long * num_relocs_return) |
1b315056 | 14415 | { |
cf13d699 | 14416 | Elf_Internal_Shdr * relsec; |
0d2a7a93 | 14417 | unsigned char * end = start + size; |
cb8f3167 | 14418 | |
d1c4b12b NC |
14419 | if (relocs_return != NULL) |
14420 | { | |
14421 | * (Elf_Internal_Rela **) relocs_return = NULL; | |
14422 | * num_relocs_return = 0; | |
14423 | } | |
14424 | ||
dda8d76d | 14425 | if (filedata->file_header.e_type != ET_REL) |
32ec8896 | 14426 | /* No relocs to apply. */ |
015dc7e1 | 14427 | return true; |
1b315056 | 14428 | |
cf13d699 | 14429 | /* Find the reloc section associated with the section. */ |
dda8d76d NC |
14430 | for (relsec = filedata->section_headers; |
14431 | relsec < filedata->section_headers + filedata->file_header.e_shnum; | |
5b18a4bc | 14432 | ++relsec) |
252b5132 | 14433 | { |
015dc7e1 | 14434 | bool is_rela; |
41e92641 | 14435 | unsigned long num_relocs; |
2cf0635d NC |
14436 | Elf_Internal_Rela * relocs; |
14437 | Elf_Internal_Rela * rp; | |
14438 | Elf_Internal_Shdr * symsec; | |
14439 | Elf_Internal_Sym * symtab; | |
ba5cdace | 14440 | unsigned long num_syms; |
2cf0635d | 14441 | Elf_Internal_Sym * sym; |
252b5132 | 14442 | |
41e92641 | 14443 | if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL) |
dda8d76d NC |
14444 | || relsec->sh_info >= filedata->file_header.e_shnum |
14445 | || filedata->section_headers + relsec->sh_info != section | |
c256ffe7 | 14446 | || relsec->sh_size == 0 |
dda8d76d | 14447 | || relsec->sh_link >= filedata->file_header.e_shnum) |
5b18a4bc | 14448 | continue; |
428409d5 | 14449 | |
a788aedd AM |
14450 | symsec = filedata->section_headers + relsec->sh_link; |
14451 | if (symsec->sh_type != SHT_SYMTAB | |
14452 | && symsec->sh_type != SHT_DYNSYM) | |
015dc7e1 | 14453 | return false; |
a788aedd | 14454 | |
41e92641 NC |
14455 | is_rela = relsec->sh_type == SHT_RELA; |
14456 | ||
14457 | if (is_rela) | |
14458 | { | |
dda8d76d | 14459 | if (!slurp_rela_relocs (filedata, relsec->sh_offset, |
3f5e193b | 14460 | relsec->sh_size, & relocs, & num_relocs)) |
015dc7e1 | 14461 | return false; |
41e92641 NC |
14462 | } |
14463 | else | |
14464 | { | |
dda8d76d | 14465 | if (!slurp_rel_relocs (filedata, relsec->sh_offset, |
3f5e193b | 14466 | relsec->sh_size, & relocs, & num_relocs)) |
015dc7e1 | 14467 | return false; |
41e92641 NC |
14468 | } |
14469 | ||
14470 | /* SH uses RELA but uses in place value instead of the addend field. */ | |
dda8d76d | 14471 | if (filedata->file_header.e_machine == EM_SH) |
015dc7e1 | 14472 | is_rela = false; |
428409d5 | 14473 | |
4de91c10 | 14474 | symtab = get_elf_symbols (filedata, symsec, & num_syms); |
103f02d3 | 14475 | |
41e92641 | 14476 | for (rp = relocs; rp < relocs + num_relocs; ++rp) |
252b5132 | 14477 | { |
015dc7e1 AM |
14478 | bfd_vma addend; |
14479 | unsigned int reloc_type; | |
14480 | unsigned int reloc_size; | |
14481 | bool reloc_inplace = false; | |
14482 | bool reloc_subtract = false; | |
14483 | unsigned char *rloc; | |
14484 | unsigned long sym_index; | |
4b78141a | 14485 | |
dda8d76d | 14486 | reloc_type = get_reloc_type (filedata, rp->r_info); |
41e92641 | 14487 | |
dda8d76d | 14488 | if (target_specific_reloc_handling (filedata, rp, start, end, symtab, num_syms)) |
2a7b2e88 | 14489 | continue; |
dda8d76d | 14490 | else if (is_none_reloc (filedata, reloc_type)) |
98fb390a | 14491 | continue; |
dda8d76d NC |
14492 | else if (is_32bit_abs_reloc (filedata, reloc_type) |
14493 | || is_32bit_pcrel_reloc (filedata, reloc_type)) | |
aca88567 | 14494 | reloc_size = 4; |
dda8d76d NC |
14495 | else if (is_64bit_abs_reloc (filedata, reloc_type) |
14496 | || is_64bit_pcrel_reloc (filedata, reloc_type)) | |
aca88567 | 14497 | reloc_size = 8; |
dda8d76d | 14498 | else if (is_24bit_abs_reloc (filedata, reloc_type)) |
4dc3c23d | 14499 | reloc_size = 3; |
dda8d76d | 14500 | else if (is_16bit_abs_reloc (filedata, reloc_type)) |
aca88567 | 14501 | reloc_size = 2; |
39e07931 AS |
14502 | else if (is_8bit_abs_reloc (filedata, reloc_type) |
14503 | || is_6bit_abs_reloc (filedata, reloc_type)) | |
14504 | reloc_size = 1; | |
03336641 JW |
14505 | else if ((reloc_subtract = is_32bit_inplace_sub_reloc (filedata, |
14506 | reloc_type)) | |
14507 | || is_32bit_inplace_add_reloc (filedata, reloc_type)) | |
14508 | { | |
14509 | reloc_size = 4; | |
015dc7e1 | 14510 | reloc_inplace = true; |
03336641 JW |
14511 | } |
14512 | else if ((reloc_subtract = is_64bit_inplace_sub_reloc (filedata, | |
14513 | reloc_type)) | |
14514 | || is_64bit_inplace_add_reloc (filedata, reloc_type)) | |
14515 | { | |
14516 | reloc_size = 8; | |
015dc7e1 | 14517 | reloc_inplace = true; |
03336641 JW |
14518 | } |
14519 | else if ((reloc_subtract = is_16bit_inplace_sub_reloc (filedata, | |
14520 | reloc_type)) | |
14521 | || is_16bit_inplace_add_reloc (filedata, reloc_type)) | |
14522 | { | |
14523 | reloc_size = 2; | |
015dc7e1 | 14524 | reloc_inplace = true; |
03336641 JW |
14525 | } |
14526 | else if ((reloc_subtract = is_8bit_inplace_sub_reloc (filedata, | |
14527 | reloc_type)) | |
14528 | || is_8bit_inplace_add_reloc (filedata, reloc_type)) | |
14529 | { | |
14530 | reloc_size = 1; | |
015dc7e1 | 14531 | reloc_inplace = true; |
03336641 | 14532 | } |
39e07931 AS |
14533 | else if ((reloc_subtract = is_6bit_inplace_sub_reloc (filedata, |
14534 | reloc_type))) | |
14535 | { | |
14536 | reloc_size = 1; | |
015dc7e1 | 14537 | reloc_inplace = true; |
39e07931 | 14538 | } |
aca88567 | 14539 | else |
4b78141a | 14540 | { |
bee0ee85 | 14541 | static unsigned int prev_reloc = 0; |
dda8d76d | 14542 | |
bee0ee85 NC |
14543 | if (reloc_type != prev_reloc) |
14544 | warn (_("unable to apply unsupported reloc type %d to section %s\n"), | |
dda8d76d | 14545 | reloc_type, printable_section_name (filedata, section)); |
bee0ee85 | 14546 | prev_reloc = reloc_type; |
4b78141a NC |
14547 | continue; |
14548 | } | |
103f02d3 | 14549 | |
91d6fa6a | 14550 | rloc = start + rp->r_offset; |
75802ccb | 14551 | if (!IN_RANGE (start, end, rloc, reloc_size)) |
700dd8b7 L |
14552 | { |
14553 | warn (_("skipping invalid relocation offset 0x%lx in section %s\n"), | |
14554 | (unsigned long) rp->r_offset, | |
dda8d76d | 14555 | printable_section_name (filedata, section)); |
700dd8b7 L |
14556 | continue; |
14557 | } | |
103f02d3 | 14558 | |
ba5cdace NC |
14559 | sym_index = (unsigned long) get_reloc_symindex (rp->r_info); |
14560 | if (sym_index >= num_syms) | |
14561 | { | |
14562 | warn (_("skipping invalid relocation symbol index 0x%lx in section %s\n"), | |
dda8d76d | 14563 | sym_index, printable_section_name (filedata, section)); |
ba5cdace NC |
14564 | continue; |
14565 | } | |
14566 | sym = symtab + sym_index; | |
41e92641 NC |
14567 | |
14568 | /* If the reloc has a symbol associated with it, | |
55f25fc3 L |
14569 | make sure that it is of an appropriate type. |
14570 | ||
14571 | Relocations against symbols without type can happen. | |
14572 | Gcc -feliminate-dwarf2-dups may generate symbols | |
14573 | without type for debug info. | |
14574 | ||
14575 | Icc generates relocations against function symbols | |
14576 | instead of local labels. | |
14577 | ||
14578 | Relocations against object symbols can happen, eg when | |
14579 | referencing a global array. For an example of this see | |
14580 | the _clz.o binary in libgcc.a. */ | |
aca88567 | 14581 | if (sym != symtab |
b8871f35 | 14582 | && ELF_ST_TYPE (sym->st_info) != STT_COMMON |
55f25fc3 | 14583 | && ELF_ST_TYPE (sym->st_info) > STT_SECTION) |
5b18a4bc | 14584 | { |
d3a49aa8 | 14585 | warn (_("skipping unexpected symbol type %s in section %s relocation %ld\n"), |
dda8d76d NC |
14586 | get_symbol_type (filedata, ELF_ST_TYPE (sym->st_info)), |
14587 | printable_section_name (filedata, relsec), | |
d3a49aa8 | 14588 | (long int)(rp - relocs)); |
aca88567 | 14589 | continue; |
5b18a4bc | 14590 | } |
252b5132 | 14591 | |
4dc3c23d AM |
14592 | addend = 0; |
14593 | if (is_rela) | |
14594 | addend += rp->r_addend; | |
c47320c3 AM |
14595 | /* R_XTENSA_32, R_PJ_DATA_DIR32 and R_D30V_32_NORMAL are |
14596 | partial_inplace. */ | |
4dc3c23d | 14597 | if (!is_rela |
dda8d76d | 14598 | || (filedata->file_header.e_machine == EM_XTENSA |
4dc3c23d | 14599 | && reloc_type == 1) |
dda8d76d NC |
14600 | || ((filedata->file_header.e_machine == EM_PJ |
14601 | || filedata->file_header.e_machine == EM_PJ_OLD) | |
c47320c3 | 14602 | && reloc_type == 1) |
dda8d76d NC |
14603 | || ((filedata->file_header.e_machine == EM_D30V |
14604 | || filedata->file_header.e_machine == EM_CYGNUS_D30V) | |
03336641 JW |
14605 | && reloc_type == 12) |
14606 | || reloc_inplace) | |
39e07931 AS |
14607 | { |
14608 | if (is_6bit_inplace_sub_reloc (filedata, reloc_type)) | |
14609 | addend += byte_get (rloc, reloc_size) & 0x3f; | |
14610 | else | |
14611 | addend += byte_get (rloc, reloc_size); | |
14612 | } | |
cb8f3167 | 14613 | |
dda8d76d NC |
14614 | if (is_32bit_pcrel_reloc (filedata, reloc_type) |
14615 | || is_64bit_pcrel_reloc (filedata, reloc_type)) | |
85acf597 RH |
14616 | { |
14617 | /* On HPPA, all pc-relative relocations are biased by 8. */ | |
dda8d76d | 14618 | if (filedata->file_header.e_machine == EM_PARISC) |
85acf597 | 14619 | addend -= 8; |
91d6fa6a | 14620 | byte_put (rloc, (addend + sym->st_value) - rp->r_offset, |
85acf597 RH |
14621 | reloc_size); |
14622 | } | |
39e07931 AS |
14623 | else if (is_6bit_abs_reloc (filedata, reloc_type) |
14624 | || is_6bit_inplace_sub_reloc (filedata, reloc_type)) | |
14625 | { | |
14626 | if (reloc_subtract) | |
14627 | addend -= sym->st_value; | |
14628 | else | |
14629 | addend += sym->st_value; | |
14630 | addend = (addend & 0x3f) | (byte_get (rloc, reloc_size) & 0xc0); | |
14631 | byte_put (rloc, addend, reloc_size); | |
14632 | } | |
03336641 JW |
14633 | else if (reloc_subtract) |
14634 | byte_put (rloc, addend - sym->st_value, reloc_size); | |
41e92641 | 14635 | else |
91d6fa6a | 14636 | byte_put (rloc, addend + sym->st_value, reloc_size); |
5b18a4bc | 14637 | } |
252b5132 | 14638 | |
5b18a4bc | 14639 | free (symtab); |
f84ce13b NC |
14640 | /* Let the target specific reloc processing code know that |
14641 | we have finished with these relocs. */ | |
dda8d76d | 14642 | target_specific_reloc_handling (filedata, NULL, NULL, NULL, NULL, 0); |
d1c4b12b NC |
14643 | |
14644 | if (relocs_return) | |
14645 | { | |
14646 | * (Elf_Internal_Rela **) relocs_return = relocs; | |
14647 | * num_relocs_return = num_relocs; | |
14648 | } | |
14649 | else | |
14650 | free (relocs); | |
14651 | ||
5b18a4bc NC |
14652 | break; |
14653 | } | |
32ec8896 | 14654 | |
015dc7e1 | 14655 | return true; |
5b18a4bc | 14656 | } |
103f02d3 | 14657 | |
cf13d699 | 14658 | #ifdef SUPPORT_DISASSEMBLY |
015dc7e1 | 14659 | static bool |
dda8d76d | 14660 | disassemble_section (Elf_Internal_Shdr * section, Filedata * filedata) |
cf13d699 | 14661 | { |
dda8d76d | 14662 | printf (_("\nAssembly dump of section %s\n"), printable_section_name (filedata, section)); |
cf13d699 | 14663 | |
74e1a04b | 14664 | /* FIXME: XXX -- to be done --- XXX */ |
cf13d699 | 14665 | |
015dc7e1 | 14666 | return true; |
cf13d699 NC |
14667 | } |
14668 | #endif | |
14669 | ||
14670 | /* Reads in the contents of SECTION from FILE, returning a pointer | |
14671 | to a malloc'ed buffer or NULL if something went wrong. */ | |
14672 | ||
14673 | static char * | |
dda8d76d | 14674 | get_section_contents (Elf_Internal_Shdr * section, Filedata * filedata) |
cf13d699 | 14675 | { |
dda8d76d | 14676 | bfd_size_type num_bytes = section->sh_size; |
cf13d699 NC |
14677 | |
14678 | if (num_bytes == 0 || section->sh_type == SHT_NOBITS) | |
14679 | { | |
c6b78c96 | 14680 | printf (_("Section '%s' has no data to dump.\n"), |
dda8d76d | 14681 | printable_section_name (filedata, section)); |
cf13d699 NC |
14682 | return NULL; |
14683 | } | |
14684 | ||
dda8d76d | 14685 | return (char *) get_data (NULL, filedata, section->sh_offset, 1, num_bytes, |
3f5e193b | 14686 | _("section contents")); |
cf13d699 NC |
14687 | } |
14688 | ||
0e602686 NC |
14689 | /* Uncompresses a section that was compressed using zlib, in place. */ |
14690 | ||
015dc7e1 | 14691 | static bool |
dda8d76d NC |
14692 | uncompress_section_contents (unsigned char ** buffer, |
14693 | dwarf_size_type uncompressed_size, | |
14694 | dwarf_size_type * size) | |
0e602686 NC |
14695 | { |
14696 | dwarf_size_type compressed_size = *size; | |
14697 | unsigned char * compressed_buffer = *buffer; | |
14698 | unsigned char * uncompressed_buffer; | |
14699 | z_stream strm; | |
14700 | int rc; | |
14701 | ||
14702 | /* It is possible the section consists of several compressed | |
14703 | buffers concatenated together, so we uncompress in a loop. */ | |
14704 | /* PR 18313: The state field in the z_stream structure is supposed | |
14705 | to be invisible to the user (ie us), but some compilers will | |
14706 | still complain about it being used without initialisation. So | |
14707 | we first zero the entire z_stream structure and then set the fields | |
14708 | that we need. */ | |
14709 | memset (& strm, 0, sizeof strm); | |
14710 | strm.avail_in = compressed_size; | |
14711 | strm.next_in = (Bytef *) compressed_buffer; | |
14712 | strm.avail_out = uncompressed_size; | |
14713 | uncompressed_buffer = (unsigned char *) xmalloc (uncompressed_size); | |
14714 | ||
14715 | rc = inflateInit (& strm); | |
14716 | while (strm.avail_in > 0) | |
14717 | { | |
14718 | if (rc != Z_OK) | |
3624a6c1 | 14719 | break; |
0e602686 NC |
14720 | strm.next_out = ((Bytef *) uncompressed_buffer |
14721 | + (uncompressed_size - strm.avail_out)); | |
14722 | rc = inflate (&strm, Z_FINISH); | |
14723 | if (rc != Z_STREAM_END) | |
3624a6c1 | 14724 | break; |
0e602686 NC |
14725 | rc = inflateReset (& strm); |
14726 | } | |
ad92f33d AM |
14727 | if (inflateEnd (& strm) != Z_OK |
14728 | || rc != Z_OK | |
0e602686 NC |
14729 | || strm.avail_out != 0) |
14730 | goto fail; | |
14731 | ||
14732 | *buffer = uncompressed_buffer; | |
14733 | *size = uncompressed_size; | |
015dc7e1 | 14734 | return true; |
0e602686 NC |
14735 | |
14736 | fail: | |
14737 | free (uncompressed_buffer); | |
14738 | /* Indicate decompression failure. */ | |
14739 | *buffer = NULL; | |
015dc7e1 | 14740 | return false; |
0e602686 | 14741 | } |
dd24e3da | 14742 | |
015dc7e1 | 14743 | static bool |
dda8d76d | 14744 | dump_section_as_strings (Elf_Internal_Shdr * section, Filedata * filedata) |
cf13d699 | 14745 | { |
015dc7e1 AM |
14746 | Elf_Internal_Shdr *relsec; |
14747 | bfd_size_type num_bytes; | |
14748 | unsigned char *data; | |
14749 | unsigned char *end; | |
14750 | unsigned char *real_start; | |
14751 | unsigned char *start; | |
14752 | bool some_strings_shown; | |
cf13d699 | 14753 | |
dda8d76d | 14754 | real_start = start = (unsigned char *) get_section_contents (section, filedata); |
cf13d699 | 14755 | if (start == NULL) |
c6b78c96 | 14756 | /* PR 21820: Do not fail if the section was empty. */ |
63b4cc53 | 14757 | return section->sh_size == 0 || section->sh_type == SHT_NOBITS; |
c6b78c96 | 14758 | |
0e602686 | 14759 | num_bytes = section->sh_size; |
cf13d699 | 14760 | |
835f2fae NC |
14761 | if (filedata->is_separate) |
14762 | printf (_("\nString dump of section '%s' in linked file %s:\n"), | |
14763 | printable_section_name (filedata, section), | |
14764 | filedata->file_name); | |
14765 | else | |
14766 | printf (_("\nString dump of section '%s':\n"), | |
14767 | printable_section_name (filedata, section)); | |
cf13d699 | 14768 | |
0e602686 NC |
14769 | if (decompress_dumps) |
14770 | { | |
14771 | dwarf_size_type new_size = num_bytes; | |
14772 | dwarf_size_type uncompressed_size = 0; | |
14773 | ||
14774 | if ((section->sh_flags & SHF_COMPRESSED) != 0) | |
14775 | { | |
14776 | Elf_Internal_Chdr chdr; | |
14777 | unsigned int compression_header_size | |
ebdf1ebf NC |
14778 | = get_compression_header (& chdr, (unsigned char *) start, |
14779 | num_bytes); | |
5844b465 NC |
14780 | if (compression_header_size == 0) |
14781 | /* An error message will have already been generated | |
14782 | by get_compression_header. */ | |
14783 | goto error_out; | |
0e602686 | 14784 | |
813dabb9 | 14785 | if (chdr.ch_type != ELFCOMPRESS_ZLIB) |
0e602686 | 14786 | { |
813dabb9 | 14787 | warn (_("section '%s' has unsupported compress type: %d\n"), |
dda8d76d | 14788 | printable_section_name (filedata, section), chdr.ch_type); |
f761cb13 | 14789 | goto error_out; |
813dabb9 | 14790 | } |
813dabb9 L |
14791 | uncompressed_size = chdr.ch_size; |
14792 | start += compression_header_size; | |
14793 | new_size -= compression_header_size; | |
0e602686 NC |
14794 | } |
14795 | else if (new_size > 12 && streq ((char *) start, "ZLIB")) | |
14796 | { | |
14797 | /* Read the zlib header. In this case, it should be "ZLIB" | |
14798 | followed by the uncompressed section size, 8 bytes in | |
14799 | big-endian order. */ | |
14800 | uncompressed_size = start[4]; uncompressed_size <<= 8; | |
14801 | uncompressed_size += start[5]; uncompressed_size <<= 8; | |
14802 | uncompressed_size += start[6]; uncompressed_size <<= 8; | |
14803 | uncompressed_size += start[7]; uncompressed_size <<= 8; | |
14804 | uncompressed_size += start[8]; uncompressed_size <<= 8; | |
14805 | uncompressed_size += start[9]; uncompressed_size <<= 8; | |
14806 | uncompressed_size += start[10]; uncompressed_size <<= 8; | |
14807 | uncompressed_size += start[11]; | |
14808 | start += 12; | |
14809 | new_size -= 12; | |
14810 | } | |
14811 | ||
1835f746 NC |
14812 | if (uncompressed_size) |
14813 | { | |
14814 | if (uncompress_section_contents (& start, | |
14815 | uncompressed_size, & new_size)) | |
14816 | num_bytes = new_size; | |
14817 | else | |
14818 | { | |
14819 | error (_("Unable to decompress section %s\n"), | |
dda8d76d | 14820 | printable_section_name (filedata, section)); |
f761cb13 | 14821 | goto error_out; |
1835f746 NC |
14822 | } |
14823 | } | |
bc303e5d NC |
14824 | else |
14825 | start = real_start; | |
0e602686 | 14826 | } |
fd8008d8 | 14827 | |
cf13d699 NC |
14828 | /* If the section being dumped has relocations against it the user might |
14829 | be expecting these relocations to have been applied. Check for this | |
14830 | case and issue a warning message in order to avoid confusion. | |
14831 | FIXME: Maybe we ought to have an option that dumps a section with | |
14832 | relocs applied ? */ | |
dda8d76d NC |
14833 | for (relsec = filedata->section_headers; |
14834 | relsec < filedata->section_headers + filedata->file_header.e_shnum; | |
cf13d699 NC |
14835 | ++relsec) |
14836 | { | |
14837 | if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL) | |
dda8d76d NC |
14838 | || relsec->sh_info >= filedata->file_header.e_shnum |
14839 | || filedata->section_headers + relsec->sh_info != section | |
cf13d699 | 14840 | || relsec->sh_size == 0 |
dda8d76d | 14841 | || relsec->sh_link >= filedata->file_header.e_shnum) |
cf13d699 NC |
14842 | continue; |
14843 | ||
14844 | printf (_(" Note: This section has relocations against it, but these have NOT been applied to this dump.\n")); | |
14845 | break; | |
14846 | } | |
14847 | ||
cf13d699 NC |
14848 | data = start; |
14849 | end = start + num_bytes; | |
015dc7e1 | 14850 | some_strings_shown = false; |
cf13d699 | 14851 | |
ba3265d0 NC |
14852 | #ifdef HAVE_MBSTATE_T |
14853 | mbstate_t state; | |
14854 | /* Initialise the multibyte conversion state. */ | |
14855 | memset (& state, 0, sizeof (state)); | |
14856 | #endif | |
14857 | ||
015dc7e1 | 14858 | bool continuing = false; |
ba3265d0 | 14859 | |
cf13d699 NC |
14860 | while (data < end) |
14861 | { | |
14862 | while (!ISPRINT (* data)) | |
14863 | if (++ data >= end) | |
14864 | break; | |
14865 | ||
14866 | if (data < end) | |
14867 | { | |
071436c6 NC |
14868 | size_t maxlen = end - data; |
14869 | ||
ba3265d0 NC |
14870 | if (continuing) |
14871 | { | |
14872 | printf (" "); | |
015dc7e1 | 14873 | continuing = false; |
ba3265d0 NC |
14874 | } |
14875 | else | |
14876 | { | |
d1ce973e | 14877 | printf (" [%6lx] ", (unsigned long) (data - start)); |
ba3265d0 NC |
14878 | } |
14879 | ||
4082ef84 NC |
14880 | if (maxlen > 0) |
14881 | { | |
f3da8a96 | 14882 | char c = 0; |
ba3265d0 NC |
14883 | |
14884 | while (maxlen) | |
14885 | { | |
14886 | c = *data++; | |
14887 | ||
14888 | if (c == 0) | |
14889 | break; | |
14890 | ||
14891 | /* PR 25543: Treat new-lines as string-ending characters. */ | |
14892 | if (c == '\n') | |
14893 | { | |
14894 | printf ("\\n\n"); | |
14895 | if (*data != 0) | |
015dc7e1 | 14896 | continuing = true; |
ba3265d0 NC |
14897 | break; |
14898 | } | |
14899 | ||
14900 | /* Do not print control characters directly as they can affect terminal | |
14901 | settings. Such characters usually appear in the names generated | |
14902 | by the assembler for local labels. */ | |
14903 | if (ISCNTRL (c)) | |
14904 | { | |
14905 | printf ("^%c", c + 0x40); | |
14906 | } | |
14907 | else if (ISPRINT (c)) | |
14908 | { | |
14909 | putchar (c); | |
14910 | } | |
14911 | else | |
14912 | { | |
14913 | size_t n; | |
14914 | #ifdef HAVE_MBSTATE_T | |
14915 | wchar_t w; | |
14916 | #endif | |
14917 | /* Let printf do the hard work of displaying multibyte characters. */ | |
14918 | printf ("%.1s", data - 1); | |
14919 | #ifdef HAVE_MBSTATE_T | |
14920 | /* Try to find out how many bytes made up the character that was | |
14921 | just printed. Advance the symbol pointer past the bytes that | |
14922 | were displayed. */ | |
14923 | n = mbrtowc (& w, (char *)(data - 1), MB_CUR_MAX, & state); | |
14924 | #else | |
14925 | n = 1; | |
14926 | #endif | |
14927 | if (n != (size_t) -1 && n != (size_t) -2 && n > 0) | |
14928 | data += (n - 1); | |
14929 | } | |
14930 | } | |
14931 | ||
14932 | if (c != '\n') | |
14933 | putchar ('\n'); | |
4082ef84 NC |
14934 | } |
14935 | else | |
14936 | { | |
14937 | printf (_("<corrupt>\n")); | |
14938 | data = end; | |
14939 | } | |
015dc7e1 | 14940 | some_strings_shown = true; |
cf13d699 NC |
14941 | } |
14942 | } | |
14943 | ||
14944 | if (! some_strings_shown) | |
14945 | printf (_(" No strings found in this section.")); | |
14946 | ||
0e602686 | 14947 | free (real_start); |
cf13d699 NC |
14948 | |
14949 | putchar ('\n'); | |
015dc7e1 | 14950 | return true; |
f761cb13 AM |
14951 | |
14952 | error_out: | |
14953 | free (real_start); | |
015dc7e1 | 14954 | return false; |
cf13d699 NC |
14955 | } |
14956 | ||
015dc7e1 AM |
14957 | static bool |
14958 | dump_section_as_bytes (Elf_Internal_Shdr *section, | |
14959 | Filedata *filedata, | |
14960 | bool relocate) | |
cf13d699 NC |
14961 | { |
14962 | Elf_Internal_Shdr * relsec; | |
0e602686 NC |
14963 | bfd_size_type bytes; |
14964 | bfd_size_type section_size; | |
14965 | bfd_vma addr; | |
14966 | unsigned char * data; | |
14967 | unsigned char * real_start; | |
14968 | unsigned char * start; | |
14969 | ||
dda8d76d | 14970 | real_start = start = (unsigned char *) get_section_contents (section, filedata); |
cf13d699 | 14971 | if (start == NULL) |
c6b78c96 | 14972 | /* PR 21820: Do not fail if the section was empty. */ |
63b4cc53 | 14973 | return section->sh_size == 0 || section->sh_type == SHT_NOBITS; |
32ec8896 | 14974 | |
0e602686 | 14975 | section_size = section->sh_size; |
cf13d699 | 14976 | |
835f2fae NC |
14977 | if (filedata->is_separate) |
14978 | printf (_("\nHex dump of section '%s' in linked file %s:\n"), | |
14979 | printable_section_name (filedata, section), | |
14980 | filedata->file_name); | |
14981 | else | |
14982 | printf (_("\nHex dump of section '%s':\n"), | |
14983 | printable_section_name (filedata, section)); | |
cf13d699 | 14984 | |
0e602686 NC |
14985 | if (decompress_dumps) |
14986 | { | |
14987 | dwarf_size_type new_size = section_size; | |
14988 | dwarf_size_type uncompressed_size = 0; | |
14989 | ||
14990 | if ((section->sh_flags & SHF_COMPRESSED) != 0) | |
14991 | { | |
14992 | Elf_Internal_Chdr chdr; | |
14993 | unsigned int compression_header_size | |
ebdf1ebf | 14994 | = get_compression_header (& chdr, start, section_size); |
0e602686 | 14995 | |
5844b465 NC |
14996 | if (compression_header_size == 0) |
14997 | /* An error message will have already been generated | |
14998 | by get_compression_header. */ | |
14999 | goto error_out; | |
15000 | ||
813dabb9 | 15001 | if (chdr.ch_type != ELFCOMPRESS_ZLIB) |
0e602686 | 15002 | { |
813dabb9 | 15003 | warn (_("section '%s' has unsupported compress type: %d\n"), |
dda8d76d | 15004 | printable_section_name (filedata, section), chdr.ch_type); |
f761cb13 | 15005 | goto error_out; |
0e602686 | 15006 | } |
813dabb9 L |
15007 | uncompressed_size = chdr.ch_size; |
15008 | start += compression_header_size; | |
15009 | new_size -= compression_header_size; | |
0e602686 NC |
15010 | } |
15011 | else if (new_size > 12 && streq ((char *) start, "ZLIB")) | |
15012 | { | |
15013 | /* Read the zlib header. In this case, it should be "ZLIB" | |
15014 | followed by the uncompressed section size, 8 bytes in | |
15015 | big-endian order. */ | |
15016 | uncompressed_size = start[4]; uncompressed_size <<= 8; | |
15017 | uncompressed_size += start[5]; uncompressed_size <<= 8; | |
15018 | uncompressed_size += start[6]; uncompressed_size <<= 8; | |
15019 | uncompressed_size += start[7]; uncompressed_size <<= 8; | |
15020 | uncompressed_size += start[8]; uncompressed_size <<= 8; | |
15021 | uncompressed_size += start[9]; uncompressed_size <<= 8; | |
15022 | uncompressed_size += start[10]; uncompressed_size <<= 8; | |
15023 | uncompressed_size += start[11]; | |
15024 | start += 12; | |
15025 | new_size -= 12; | |
15026 | } | |
15027 | ||
f055032e NC |
15028 | if (uncompressed_size) |
15029 | { | |
15030 | if (uncompress_section_contents (& start, uncompressed_size, | |
15031 | & new_size)) | |
bc303e5d NC |
15032 | { |
15033 | section_size = new_size; | |
15034 | } | |
f055032e NC |
15035 | else |
15036 | { | |
15037 | error (_("Unable to decompress section %s\n"), | |
dda8d76d | 15038 | printable_section_name (filedata, section)); |
bc303e5d | 15039 | /* FIXME: Print the section anyway ? */ |
f761cb13 | 15040 | goto error_out; |
f055032e NC |
15041 | } |
15042 | } | |
bc303e5d NC |
15043 | else |
15044 | start = real_start; | |
0e602686 | 15045 | } |
14ae95f2 | 15046 | |
cf13d699 NC |
15047 | if (relocate) |
15048 | { | |
dda8d76d | 15049 | if (! apply_relocations (filedata, section, start, section_size, NULL, NULL)) |
f761cb13 | 15050 | goto error_out; |
cf13d699 NC |
15051 | } |
15052 | else | |
15053 | { | |
15054 | /* If the section being dumped has relocations against it the user might | |
15055 | be expecting these relocations to have been applied. Check for this | |
15056 | case and issue a warning message in order to avoid confusion. | |
15057 | FIXME: Maybe we ought to have an option that dumps a section with | |
15058 | relocs applied ? */ | |
dda8d76d NC |
15059 | for (relsec = filedata->section_headers; |
15060 | relsec < filedata->section_headers + filedata->file_header.e_shnum; | |
cf13d699 NC |
15061 | ++relsec) |
15062 | { | |
15063 | if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL) | |
dda8d76d NC |
15064 | || relsec->sh_info >= filedata->file_header.e_shnum |
15065 | || filedata->section_headers + relsec->sh_info != section | |
cf13d699 | 15066 | || relsec->sh_size == 0 |
dda8d76d | 15067 | || relsec->sh_link >= filedata->file_header.e_shnum) |
cf13d699 NC |
15068 | continue; |
15069 | ||
15070 | printf (_(" NOTE: This section has relocations against it, but these have NOT been applied to this dump.\n")); | |
15071 | break; | |
15072 | } | |
15073 | } | |
15074 | ||
15075 | addr = section->sh_addr; | |
0e602686 | 15076 | bytes = section_size; |
cf13d699 NC |
15077 | data = start; |
15078 | ||
15079 | while (bytes) | |
15080 | { | |
15081 | int j; | |
15082 | int k; | |
15083 | int lbytes; | |
15084 | ||
15085 | lbytes = (bytes > 16 ? 16 : bytes); | |
15086 | ||
15087 | printf (" 0x%8.8lx ", (unsigned long) addr); | |
15088 | ||
15089 | for (j = 0; j < 16; j++) | |
15090 | { | |
15091 | if (j < lbytes) | |
15092 | printf ("%2.2x", data[j]); | |
15093 | else | |
15094 | printf (" "); | |
15095 | ||
15096 | if ((j & 3) == 3) | |
15097 | printf (" "); | |
15098 | } | |
15099 | ||
15100 | for (j = 0; j < lbytes; j++) | |
15101 | { | |
15102 | k = data[j]; | |
15103 | if (k >= ' ' && k < 0x7f) | |
15104 | printf ("%c", k); | |
15105 | else | |
15106 | printf ("."); | |
15107 | } | |
15108 | ||
15109 | putchar ('\n'); | |
15110 | ||
15111 | data += lbytes; | |
15112 | addr += lbytes; | |
15113 | bytes -= lbytes; | |
15114 | } | |
15115 | ||
0e602686 | 15116 | free (real_start); |
cf13d699 NC |
15117 | |
15118 | putchar ('\n'); | |
015dc7e1 | 15119 | return true; |
f761cb13 AM |
15120 | |
15121 | error_out: | |
15122 | free (real_start); | |
015dc7e1 | 15123 | return false; |
cf13d699 NC |
15124 | } |
15125 | ||
094e34f2 | 15126 | #ifdef ENABLE_LIBCTF |
7d9813f1 NA |
15127 | static ctf_sect_t * |
15128 | shdr_to_ctf_sect (ctf_sect_t *buf, Elf_Internal_Shdr *shdr, Filedata *filedata) | |
15129 | { | |
84714f86 | 15130 | buf->cts_name = section_name_print (filedata, shdr); |
7d9813f1 NA |
15131 | buf->cts_size = shdr->sh_size; |
15132 | buf->cts_entsize = shdr->sh_entsize; | |
7d9813f1 NA |
15133 | |
15134 | return buf; | |
15135 | } | |
15136 | ||
15137 | /* Formatting callback function passed to ctf_dump. Returns either the pointer | |
15138 | it is passed, or a pointer to newly-allocated storage, in which case | |
15139 | dump_ctf() will free it when it no longer needs it. */ | |
15140 | ||
2f6ecaed NA |
15141 | static char * |
15142 | dump_ctf_indent_lines (ctf_sect_names_t sect ATTRIBUTE_UNUSED, | |
15143 | char *s, void *arg) | |
7d9813f1 | 15144 | { |
3e50a591 | 15145 | const char *blanks = arg; |
7d9813f1 NA |
15146 | char *new_s; |
15147 | ||
3e50a591 | 15148 | if (asprintf (&new_s, "%s%s", blanks, s) < 0) |
7d9813f1 NA |
15149 | return s; |
15150 | return new_s; | |
15151 | } | |
15152 | ||
926c9e76 NA |
15153 | /* Dump CTF errors/warnings. */ |
15154 | static void | |
139633c3 | 15155 | dump_ctf_errs (ctf_dict_t *fp) |
926c9e76 NA |
15156 | { |
15157 | ctf_next_t *it = NULL; | |
15158 | char *errtext; | |
15159 | int is_warning; | |
15160 | int err; | |
15161 | ||
15162 | /* Dump accumulated errors and warnings. */ | |
15163 | while ((errtext = ctf_errwarning_next (fp, &it, &is_warning, &err)) != NULL) | |
15164 | { | |
5e9b84f7 | 15165 | error (_("%s: %s"), is_warning ? _("warning"): _("error"), |
926c9e76 NA |
15166 | errtext); |
15167 | free (errtext); | |
15168 | } | |
15169 | if (err != ECTF_NEXT_END) | |
15170 | error (_("CTF error: cannot get CTF errors: `%s'"), ctf_errmsg (err)); | |
15171 | } | |
15172 | ||
2f6ecaed NA |
15173 | /* Dump one CTF archive member. */ |
15174 | ||
80b56fad NA |
15175 | static void |
15176 | dump_ctf_archive_member (ctf_dict_t *ctf, const char *name, ctf_dict_t *parent, | |
15177 | size_t member) | |
2f6ecaed | 15178 | { |
2f6ecaed NA |
15179 | const char *things[] = {"Header", "Labels", "Data objects", |
15180 | "Function objects", "Variables", "Types", "Strings", | |
15181 | ""}; | |
15182 | const char **thing; | |
15183 | size_t i; | |
15184 | ||
80b56fad NA |
15185 | /* Don't print out the name of the default-named archive member if it appears |
15186 | first in the list. The name .ctf appears everywhere, even for things that | |
15187 | aren't really archives, so printing it out is liable to be confusing; also, | |
15188 | the common case by far is for only one archive member to exist, and hiding | |
15189 | it in that case seems worthwhile. */ | |
2f6ecaed | 15190 | |
80b56fad NA |
15191 | if (strcmp (name, ".ctf") != 0 || member != 0) |
15192 | printf (_("\nCTF archive member: %s:\n"), name); | |
2f6ecaed | 15193 | |
80b56fad NA |
15194 | if (ctf_parent_name (ctf) != NULL) |
15195 | ctf_import (ctf, parent); | |
2f6ecaed NA |
15196 | |
15197 | for (i = 0, thing = things; *thing[0]; thing++, i++) | |
15198 | { | |
15199 | ctf_dump_state_t *s = NULL; | |
15200 | char *item; | |
15201 | ||
15202 | printf ("\n %s:\n", *thing); | |
15203 | while ((item = ctf_dump (ctf, &s, i, dump_ctf_indent_lines, | |
15204 | (void *) " ")) != NULL) | |
15205 | { | |
15206 | printf ("%s\n", item); | |
15207 | free (item); | |
15208 | } | |
15209 | ||
15210 | if (ctf_errno (ctf)) | |
15211 | { | |
15212 | error (_("Iteration failed: %s, %s\n"), *thing, | |
15213 | ctf_errmsg (ctf_errno (ctf))); | |
80b56fad | 15214 | break; |
2f6ecaed NA |
15215 | } |
15216 | } | |
8b37e7b6 | 15217 | |
926c9e76 | 15218 | dump_ctf_errs (ctf); |
2f6ecaed NA |
15219 | } |
15220 | ||
015dc7e1 | 15221 | static bool |
7d9813f1 NA |
15222 | dump_section_as_ctf (Elf_Internal_Shdr * section, Filedata * filedata) |
15223 | { | |
7d9813f1 NA |
15224 | Elf_Internal_Shdr * symtab_sec = NULL; |
15225 | Elf_Internal_Shdr * strtab_sec = NULL; | |
d344b407 NA |
15226 | void * data = NULL; |
15227 | void * symdata = NULL; | |
15228 | void * strdata = NULL; | |
80b56fad | 15229 | ctf_sect_t ctfsect, symsect, strsect; |
d344b407 NA |
15230 | ctf_sect_t * symsectp = NULL; |
15231 | ctf_sect_t * strsectp = NULL; | |
2f6ecaed | 15232 | ctf_archive_t * ctfa = NULL; |
139633c3 | 15233 | ctf_dict_t * parent = NULL; |
80b56fad | 15234 | ctf_dict_t * fp; |
7d9813f1 | 15235 | |
80b56fad NA |
15236 | ctf_next_t *i = NULL; |
15237 | const char *name; | |
15238 | size_t member = 0; | |
7d9813f1 | 15239 | int err; |
015dc7e1 | 15240 | bool ret = false; |
7d9813f1 NA |
15241 | |
15242 | shdr_to_ctf_sect (&ctfsect, section, filedata); | |
15243 | data = get_section_contents (section, filedata); | |
15244 | ctfsect.cts_data = data; | |
15245 | ||
616febde | 15246 | if (!dump_ctf_symtab_name) |
3d16b64e | 15247 | dump_ctf_symtab_name = strdup (".dynsym"); |
616febde NA |
15248 | |
15249 | if (!dump_ctf_strtab_name) | |
3d16b64e | 15250 | dump_ctf_strtab_name = strdup (".dynstr"); |
616febde NA |
15251 | |
15252 | if (dump_ctf_symtab_name && dump_ctf_symtab_name[0] != 0) | |
7d9813f1 NA |
15253 | { |
15254 | if ((symtab_sec = find_section (filedata, dump_ctf_symtab_name)) == NULL) | |
15255 | { | |
15256 | error (_("No symbol section named %s\n"), dump_ctf_symtab_name); | |
15257 | goto fail; | |
15258 | } | |
15259 | if ((symdata = (void *) get_data (NULL, filedata, | |
15260 | symtab_sec->sh_offset, 1, | |
15261 | symtab_sec->sh_size, | |
15262 | _("symbols"))) == NULL) | |
15263 | goto fail; | |
15264 | symsectp = shdr_to_ctf_sect (&symsect, symtab_sec, filedata); | |
15265 | symsect.cts_data = symdata; | |
15266 | } | |
835f2fae | 15267 | |
df16e041 | 15268 | if (dump_ctf_strtab_name && dump_ctf_strtab_name[0] != 0) |
7d9813f1 NA |
15269 | { |
15270 | if ((strtab_sec = find_section (filedata, dump_ctf_strtab_name)) == NULL) | |
15271 | { | |
15272 | error (_("No string table section named %s\n"), | |
15273 | dump_ctf_strtab_name); | |
15274 | goto fail; | |
15275 | } | |
15276 | if ((strdata = (void *) get_data (NULL, filedata, | |
15277 | strtab_sec->sh_offset, 1, | |
15278 | strtab_sec->sh_size, | |
15279 | _("strings"))) == NULL) | |
15280 | goto fail; | |
15281 | strsectp = shdr_to_ctf_sect (&strsect, strtab_sec, filedata); | |
15282 | strsect.cts_data = strdata; | |
15283 | } | |
835f2fae | 15284 | |
2f6ecaed NA |
15285 | /* Load the CTF file and dump it. It may be a raw CTF section, or an archive: |
15286 | libctf papers over the difference, so we can pretend it is always an | |
80b56fad | 15287 | archive. */ |
7d9813f1 | 15288 | |
2f6ecaed | 15289 | if ((ctfa = ctf_arc_bufopen (&ctfsect, symsectp, strsectp, &err)) == NULL) |
7d9813f1 | 15290 | { |
926c9e76 | 15291 | dump_ctf_errs (NULL); |
7d9813f1 NA |
15292 | error (_("CTF open failure: %s\n"), ctf_errmsg (err)); |
15293 | goto fail; | |
15294 | } | |
15295 | ||
96c61be5 NA |
15296 | ctf_arc_symsect_endianness (ctfa, filedata->file_header.e_ident[EI_DATA] |
15297 | != ELFDATA2MSB); | |
15298 | ||
80b56fad NA |
15299 | /* Preload the parent dict, since it will need to be imported into every |
15300 | child in turn. */ | |
15301 | if ((parent = ctf_dict_open (ctfa, dump_ctf_parent_name, &err)) == NULL) | |
2f6ecaed | 15302 | { |
926c9e76 | 15303 | dump_ctf_errs (NULL); |
2f6ecaed NA |
15304 | error (_("CTF open failure: %s\n"), ctf_errmsg (err)); |
15305 | goto fail; | |
7d9813f1 NA |
15306 | } |
15307 | ||
015dc7e1 | 15308 | ret = true; |
7d9813f1 | 15309 | |
835f2fae NC |
15310 | if (filedata->is_separate) |
15311 | printf (_("\nDump of CTF section '%s' in linked file %s:\n"), | |
15312 | printable_section_name (filedata, section), | |
15313 | filedata->file_name); | |
15314 | else | |
15315 | printf (_("\nDump of CTF section '%s':\n"), | |
15316 | printable_section_name (filedata, section)); | |
7d9813f1 | 15317 | |
80b56fad NA |
15318 | while ((fp = ctf_archive_next (ctfa, &i, &name, 0, &err)) != NULL) |
15319 | dump_ctf_archive_member (fp, name, parent, member++); | |
15320 | if (err != ECTF_NEXT_END) | |
15321 | { | |
15322 | dump_ctf_errs (NULL); | |
15323 | error (_("CTF member open failure: %s\n"), ctf_errmsg (err)); | |
15324 | ret = false; | |
15325 | } | |
7d9813f1 NA |
15326 | |
15327 | fail: | |
139633c3 | 15328 | ctf_dict_close (parent); |
2f6ecaed | 15329 | ctf_close (ctfa); |
7d9813f1 NA |
15330 | free (data); |
15331 | free (symdata); | |
15332 | free (strdata); | |
15333 | return ret; | |
15334 | } | |
094e34f2 | 15335 | #endif |
7d9813f1 | 15336 | |
015dc7e1 | 15337 | static bool |
dda8d76d NC |
15338 | load_specific_debug_section (enum dwarf_section_display_enum debug, |
15339 | const Elf_Internal_Shdr * sec, | |
15340 | void * data) | |
1007acb3 | 15341 | { |
2cf0635d | 15342 | struct dwarf_section * section = &debug_displays [debug].section; |
19e6b90e | 15343 | char buf [64]; |
dda8d76d | 15344 | Filedata * filedata = (Filedata *) data; |
9abca702 | 15345 | |
19e6b90e | 15346 | if (section->start != NULL) |
dda8d76d NC |
15347 | { |
15348 | /* If it is already loaded, do nothing. */ | |
15349 | if (streq (section->filename, filedata->file_name)) | |
015dc7e1 | 15350 | return true; |
dda8d76d NC |
15351 | free (section->start); |
15352 | } | |
1007acb3 | 15353 | |
19e6b90e L |
15354 | snprintf (buf, sizeof (buf), _("%s section data"), section->name); |
15355 | section->address = sec->sh_addr; | |
dda8d76d NC |
15356 | section->filename = filedata->file_name; |
15357 | section->start = (unsigned char *) get_data (NULL, filedata, | |
3f5e193b NC |
15358 | sec->sh_offset, 1, |
15359 | sec->sh_size, buf); | |
59245841 NC |
15360 | if (section->start == NULL) |
15361 | section->size = 0; | |
15362 | else | |
15363 | { | |
77115a4a L |
15364 | unsigned char *start = section->start; |
15365 | dwarf_size_type size = sec->sh_size; | |
dab394de | 15366 | dwarf_size_type uncompressed_size = 0; |
77115a4a L |
15367 | |
15368 | if ((sec->sh_flags & SHF_COMPRESSED) != 0) | |
15369 | { | |
15370 | Elf_Internal_Chdr chdr; | |
d8024a91 NC |
15371 | unsigned int compression_header_size; |
15372 | ||
f53be977 L |
15373 | if (size < (is_32bit_elf |
15374 | ? sizeof (Elf32_External_Chdr) | |
15375 | : sizeof (Elf64_External_Chdr))) | |
d8024a91 | 15376 | { |
55be8fd0 | 15377 | warn (_("compressed section %s is too small to contain a compression header\n"), |
d8024a91 | 15378 | section->name); |
015dc7e1 | 15379 | return false; |
d8024a91 NC |
15380 | } |
15381 | ||
ebdf1ebf | 15382 | compression_header_size = get_compression_header (&chdr, start, size); |
5844b465 NC |
15383 | if (compression_header_size == 0) |
15384 | /* An error message will have already been generated | |
15385 | by get_compression_header. */ | |
015dc7e1 | 15386 | return false; |
d8024a91 | 15387 | |
813dabb9 L |
15388 | if (chdr.ch_type != ELFCOMPRESS_ZLIB) |
15389 | { | |
15390 | warn (_("section '%s' has unsupported compress type: %d\n"), | |
15391 | section->name, chdr.ch_type); | |
015dc7e1 | 15392 | return false; |
813dabb9 | 15393 | } |
dab394de | 15394 | uncompressed_size = chdr.ch_size; |
77115a4a L |
15395 | start += compression_header_size; |
15396 | size -= compression_header_size; | |
15397 | } | |
dab394de L |
15398 | else if (size > 12 && streq ((char *) start, "ZLIB")) |
15399 | { | |
15400 | /* Read the zlib header. In this case, it should be "ZLIB" | |
15401 | followed by the uncompressed section size, 8 bytes in | |
15402 | big-endian order. */ | |
15403 | uncompressed_size = start[4]; uncompressed_size <<= 8; | |
15404 | uncompressed_size += start[5]; uncompressed_size <<= 8; | |
15405 | uncompressed_size += start[6]; uncompressed_size <<= 8; | |
15406 | uncompressed_size += start[7]; uncompressed_size <<= 8; | |
15407 | uncompressed_size += start[8]; uncompressed_size <<= 8; | |
15408 | uncompressed_size += start[9]; uncompressed_size <<= 8; | |
15409 | uncompressed_size += start[10]; uncompressed_size <<= 8; | |
15410 | uncompressed_size += start[11]; | |
15411 | start += 12; | |
15412 | size -= 12; | |
15413 | } | |
15414 | ||
1835f746 | 15415 | if (uncompressed_size) |
77115a4a | 15416 | { |
1835f746 NC |
15417 | if (uncompress_section_contents (&start, uncompressed_size, |
15418 | &size)) | |
15419 | { | |
15420 | /* Free the compressed buffer, update the section buffer | |
15421 | and the section size if uncompress is successful. */ | |
15422 | free (section->start); | |
15423 | section->start = start; | |
15424 | } | |
15425 | else | |
15426 | { | |
15427 | error (_("Unable to decompress section %s\n"), | |
dda8d76d | 15428 | printable_section_name (filedata, sec)); |
015dc7e1 | 15429 | return false; |
1835f746 | 15430 | } |
77115a4a | 15431 | } |
bc303e5d | 15432 | |
77115a4a | 15433 | section->size = size; |
59245841 | 15434 | } |
4a114e3e | 15435 | |
1b315056 | 15436 | if (section->start == NULL) |
015dc7e1 | 15437 | return false; |
1b315056 | 15438 | |
19e6b90e | 15439 | if (debug_displays [debug].relocate) |
32ec8896 | 15440 | { |
dda8d76d | 15441 | if (! apply_relocations (filedata, sec, section->start, section->size, |
32ec8896 | 15442 | & section->reloc_info, & section->num_relocs)) |
015dc7e1 | 15443 | return false; |
32ec8896 | 15444 | } |
d1c4b12b NC |
15445 | else |
15446 | { | |
15447 | section->reloc_info = NULL; | |
15448 | section->num_relocs = 0; | |
15449 | } | |
1007acb3 | 15450 | |
015dc7e1 | 15451 | return true; |
1007acb3 L |
15452 | } |
15453 | ||
301a9420 AM |
15454 | #if HAVE_LIBDEBUGINFOD |
15455 | /* Return a hex string representation of the build-id. */ | |
15456 | unsigned char * | |
15457 | get_build_id (void * data) | |
15458 | { | |
ca0e11aa | 15459 | Filedata * filedata = (Filedata *) data; |
301a9420 AM |
15460 | Elf_Internal_Shdr * shdr; |
15461 | unsigned long i; | |
15462 | ||
55be8fd0 NC |
15463 | /* Iterate through notes to find note.gnu.build-id. |
15464 | FIXME: Only the first note in any note section is examined. */ | |
301a9420 AM |
15465 | for (i = 0, shdr = filedata->section_headers; |
15466 | i < filedata->file_header.e_shnum && shdr != NULL; | |
15467 | i++, shdr++) | |
15468 | { | |
15469 | if (shdr->sh_type != SHT_NOTE) | |
15470 | continue; | |
15471 | ||
15472 | char * next; | |
15473 | char * end; | |
15474 | size_t data_remaining; | |
15475 | size_t min_notesz; | |
15476 | Elf_External_Note * enote; | |
15477 | Elf_Internal_Note inote; | |
15478 | ||
15479 | bfd_vma offset = shdr->sh_offset; | |
15480 | bfd_vma align = shdr->sh_addralign; | |
15481 | bfd_vma length = shdr->sh_size; | |
15482 | ||
15483 | enote = (Elf_External_Note *) get_section_contents (shdr, filedata); | |
15484 | if (enote == NULL) | |
15485 | continue; | |
15486 | ||
15487 | if (align < 4) | |
15488 | align = 4; | |
15489 | else if (align != 4 && align != 8) | |
f761cb13 AM |
15490 | { |
15491 | free (enote); | |
15492 | continue; | |
15493 | } | |
301a9420 AM |
15494 | |
15495 | end = (char *) enote + length; | |
15496 | data_remaining = end - (char *) enote; | |
15497 | ||
15498 | if (!is_ia64_vms (filedata)) | |
15499 | { | |
15500 | min_notesz = offsetof (Elf_External_Note, name); | |
15501 | if (data_remaining < min_notesz) | |
15502 | { | |
55be8fd0 NC |
15503 | warn (_("\ |
15504 | malformed note encountered in section %s whilst scanning for build-id note\n"), | |
15505 | printable_section_name (filedata, shdr)); | |
f761cb13 | 15506 | free (enote); |
55be8fd0 | 15507 | continue; |
301a9420 AM |
15508 | } |
15509 | data_remaining -= min_notesz; | |
15510 | ||
15511 | inote.type = BYTE_GET (enote->type); | |
15512 | inote.namesz = BYTE_GET (enote->namesz); | |
15513 | inote.namedata = enote->name; | |
15514 | inote.descsz = BYTE_GET (enote->descsz); | |
15515 | inote.descdata = ((char *) enote | |
15516 | + ELF_NOTE_DESC_OFFSET (inote.namesz, align)); | |
15517 | inote.descpos = offset + (inote.descdata - (char *) enote); | |
15518 | next = ((char *) enote | |
15519 | + ELF_NOTE_NEXT_OFFSET (inote.namesz, inote.descsz, align)); | |
15520 | } | |
15521 | else | |
15522 | { | |
15523 | Elf64_External_VMS_Note *vms_enote; | |
15524 | ||
15525 | /* PR binutils/15191 | |
15526 | Make sure that there is enough data to read. */ | |
15527 | min_notesz = offsetof (Elf64_External_VMS_Note, name); | |
15528 | if (data_remaining < min_notesz) | |
15529 | { | |
55be8fd0 NC |
15530 | warn (_("\ |
15531 | malformed note encountered in section %s whilst scanning for build-id note\n"), | |
15532 | printable_section_name (filedata, shdr)); | |
f761cb13 | 15533 | free (enote); |
55be8fd0 | 15534 | continue; |
301a9420 AM |
15535 | } |
15536 | data_remaining -= min_notesz; | |
15537 | ||
15538 | vms_enote = (Elf64_External_VMS_Note *) enote; | |
15539 | inote.type = BYTE_GET (vms_enote->type); | |
15540 | inote.namesz = BYTE_GET (vms_enote->namesz); | |
15541 | inote.namedata = vms_enote->name; | |
15542 | inote.descsz = BYTE_GET (vms_enote->descsz); | |
15543 | inote.descdata = inote.namedata + align_power (inote.namesz, 3); | |
15544 | inote.descpos = offset + (inote.descdata - (char *) enote); | |
15545 | next = inote.descdata + align_power (inote.descsz, 3); | |
15546 | } | |
15547 | ||
15548 | /* Skip malformed notes. */ | |
15549 | if ((size_t) (inote.descdata - inote.namedata) < inote.namesz | |
15550 | || (size_t) (inote.descdata - inote.namedata) > data_remaining | |
15551 | || (size_t) (next - inote.descdata) < inote.descsz | |
15552 | || ((size_t) (next - inote.descdata) | |
15553 | > data_remaining - (size_t) (inote.descdata - inote.namedata))) | |
15554 | { | |
55be8fd0 NC |
15555 | warn (_("\ |
15556 | malformed note encountered in section %s whilst scanning for build-id note\n"), | |
15557 | printable_section_name (filedata, shdr)); | |
f761cb13 | 15558 | free (enote); |
301a9420 AM |
15559 | continue; |
15560 | } | |
15561 | ||
15562 | /* Check if this is the build-id note. If so then convert the build-id | |
15563 | bytes to a hex string. */ | |
15564 | if (inote.namesz > 0 | |
24d127aa | 15565 | && startswith (inote.namedata, "GNU") |
301a9420 AM |
15566 | && inote.type == NT_GNU_BUILD_ID) |
15567 | { | |
15568 | unsigned long j; | |
15569 | char * build_id; | |
15570 | ||
15571 | build_id = malloc (inote.descsz * 2 + 1); | |
15572 | if (build_id == NULL) | |
f761cb13 AM |
15573 | { |
15574 | free (enote); | |
15575 | return NULL; | |
15576 | } | |
301a9420 AM |
15577 | |
15578 | for (j = 0; j < inote.descsz; ++j) | |
15579 | sprintf (build_id + (j * 2), "%02x", inote.descdata[j] & 0xff); | |
15580 | build_id[inote.descsz * 2] = '\0'; | |
f761cb13 | 15581 | free (enote); |
301a9420 | 15582 | |
55be8fd0 | 15583 | return (unsigned char *) build_id; |
301a9420 | 15584 | } |
f761cb13 | 15585 | free (enote); |
301a9420 AM |
15586 | } |
15587 | ||
15588 | return NULL; | |
15589 | } | |
15590 | #endif /* HAVE_LIBDEBUGINFOD */ | |
15591 | ||
657d0d47 CC |
15592 | /* If this is not NULL, load_debug_section will only look for sections |
15593 | within the list of sections given here. */ | |
32ec8896 | 15594 | static unsigned int * section_subset = NULL; |
657d0d47 | 15595 | |
015dc7e1 | 15596 | bool |
dda8d76d | 15597 | load_debug_section (enum dwarf_section_display_enum debug, void * data) |
d966045b | 15598 | { |
2cf0635d NC |
15599 | struct dwarf_section * section = &debug_displays [debug].section; |
15600 | Elf_Internal_Shdr * sec; | |
dda8d76d NC |
15601 | Filedata * filedata = (Filedata *) data; |
15602 | ||
f425ec66 NC |
15603 | /* Without section headers we cannot find any sections. */ |
15604 | if (filedata->section_headers == NULL) | |
015dc7e1 | 15605 | return false; |
f425ec66 | 15606 | |
9c1ce108 AM |
15607 | if (filedata->string_table == NULL |
15608 | && filedata->file_header.e_shstrndx != SHN_UNDEF | |
15609 | && filedata->file_header.e_shstrndx < filedata->file_header.e_shnum) | |
dda8d76d NC |
15610 | { |
15611 | Elf_Internal_Shdr * strs; | |
15612 | ||
15613 | /* Read in the string table, so that we have section names to scan. */ | |
15614 | strs = filedata->section_headers + filedata->file_header.e_shstrndx; | |
15615 | ||
4dff97b2 | 15616 | if (strs != NULL && strs->sh_size != 0) |
dda8d76d | 15617 | { |
9c1ce108 AM |
15618 | filedata->string_table |
15619 | = (char *) get_data (NULL, filedata, strs->sh_offset, | |
15620 | 1, strs->sh_size, _("string table")); | |
dda8d76d | 15621 | |
9c1ce108 AM |
15622 | filedata->string_table_length |
15623 | = filedata->string_table != NULL ? strs->sh_size : 0; | |
dda8d76d NC |
15624 | } |
15625 | } | |
d966045b DJ |
15626 | |
15627 | /* Locate the debug section. */ | |
dda8d76d | 15628 | sec = find_section_in_set (filedata, section->uncompressed_name, section_subset); |
d966045b DJ |
15629 | if (sec != NULL) |
15630 | section->name = section->uncompressed_name; | |
15631 | else | |
15632 | { | |
dda8d76d | 15633 | sec = find_section_in_set (filedata, section->compressed_name, section_subset); |
d966045b DJ |
15634 | if (sec != NULL) |
15635 | section->name = section->compressed_name; | |
15636 | } | |
15637 | if (sec == NULL) | |
015dc7e1 | 15638 | return false; |
d966045b | 15639 | |
657d0d47 CC |
15640 | /* If we're loading from a subset of sections, and we've loaded |
15641 | a section matching this name before, it's likely that it's a | |
15642 | different one. */ | |
15643 | if (section_subset != NULL) | |
15644 | free_debug_section (debug); | |
15645 | ||
dda8d76d | 15646 | return load_specific_debug_section (debug, sec, data); |
d966045b DJ |
15647 | } |
15648 | ||
19e6b90e L |
15649 | void |
15650 | free_debug_section (enum dwarf_section_display_enum debug) | |
1007acb3 | 15651 | { |
2cf0635d | 15652 | struct dwarf_section * section = &debug_displays [debug].section; |
1007acb3 | 15653 | |
19e6b90e L |
15654 | if (section->start == NULL) |
15655 | return; | |
1007acb3 | 15656 | |
19e6b90e L |
15657 | free ((char *) section->start); |
15658 | section->start = NULL; | |
15659 | section->address = 0; | |
15660 | section->size = 0; | |
a788aedd | 15661 | |
9db70fc3 AM |
15662 | free (section->reloc_info); |
15663 | section->reloc_info = NULL; | |
15664 | section->num_relocs = 0; | |
1007acb3 L |
15665 | } |
15666 | ||
015dc7e1 | 15667 | static bool |
dda8d76d | 15668 | display_debug_section (int shndx, Elf_Internal_Shdr * section, Filedata * filedata) |
1007acb3 | 15669 | { |
84714f86 AM |
15670 | const char *name = (section_name_valid (filedata, section) |
15671 | ? section_name (filedata, section) : ""); | |
15672 | const char *print_name = printable_section_name (filedata, section); | |
19e6b90e | 15673 | bfd_size_type length; |
015dc7e1 | 15674 | bool result = true; |
3f5e193b | 15675 | int i; |
1007acb3 | 15676 | |
19e6b90e L |
15677 | length = section->sh_size; |
15678 | if (length == 0) | |
1007acb3 | 15679 | { |
74e1a04b | 15680 | printf (_("\nSection '%s' has no debugging data.\n"), print_name); |
015dc7e1 | 15681 | return true; |
1007acb3 | 15682 | } |
5dff79d8 NC |
15683 | if (section->sh_type == SHT_NOBITS) |
15684 | { | |
15685 | /* There is no point in dumping the contents of a debugging section | |
15686 | which has the NOBITS type - the bits in the file will be random. | |
15687 | This can happen when a file containing a .eh_frame section is | |
15688 | stripped with the --only-keep-debug command line option. */ | |
74e1a04b NC |
15689 | printf (_("section '%s' has the NOBITS type - its contents are unreliable.\n"), |
15690 | print_name); | |
015dc7e1 | 15691 | return false; |
5dff79d8 | 15692 | } |
1007acb3 | 15693 | |
24d127aa | 15694 | if (startswith (name, ".gnu.linkonce.wi.")) |
19e6b90e | 15695 | name = ".debug_info"; |
1007acb3 | 15696 | |
19e6b90e L |
15697 | /* See if we know how to display the contents of this section. */ |
15698 | for (i = 0; i < max; i++) | |
d85bf2ba NC |
15699 | { |
15700 | enum dwarf_section_display_enum id = (enum dwarf_section_display_enum) i; | |
15701 | struct dwarf_section_display * display = debug_displays + i; | |
15702 | struct dwarf_section * sec = & display->section; | |
d966045b | 15703 | |
d85bf2ba | 15704 | if (streq (sec->uncompressed_name, name) |
24d127aa | 15705 | || (id == line && startswith (name, ".debug_line.")) |
d85bf2ba NC |
15706 | || streq (sec->compressed_name, name)) |
15707 | { | |
015dc7e1 | 15708 | bool secondary = (section != find_section (filedata, name)); |
1007acb3 | 15709 | |
d85bf2ba NC |
15710 | if (secondary) |
15711 | free_debug_section (id); | |
dda8d76d | 15712 | |
24d127aa | 15713 | if (i == line && startswith (name, ".debug_line.")) |
d85bf2ba NC |
15714 | sec->name = name; |
15715 | else if (streq (sec->uncompressed_name, name)) | |
15716 | sec->name = sec->uncompressed_name; | |
15717 | else | |
15718 | sec->name = sec->compressed_name; | |
657d0d47 | 15719 | |
d85bf2ba NC |
15720 | if (load_specific_debug_section (id, section, filedata)) |
15721 | { | |
15722 | /* If this debug section is part of a CU/TU set in a .dwp file, | |
15723 | restrict load_debug_section to the sections in that set. */ | |
15724 | section_subset = find_cu_tu_set (filedata, shndx); | |
1007acb3 | 15725 | |
d85bf2ba | 15726 | result &= display->display (sec, filedata); |
657d0d47 | 15727 | |
d85bf2ba | 15728 | section_subset = NULL; |
1007acb3 | 15729 | |
44266f36 | 15730 | if (secondary || (id != info && id != abbrev && id != debug_addr)) |
d85bf2ba NC |
15731 | free_debug_section (id); |
15732 | } | |
15733 | break; | |
15734 | } | |
15735 | } | |
1007acb3 | 15736 | |
19e6b90e | 15737 | if (i == max) |
1007acb3 | 15738 | { |
74e1a04b | 15739 | printf (_("Unrecognized debug section: %s\n"), print_name); |
015dc7e1 | 15740 | result = false; |
1007acb3 L |
15741 | } |
15742 | ||
19e6b90e | 15743 | return result; |
5b18a4bc | 15744 | } |
103f02d3 | 15745 | |
aef1f6d0 DJ |
15746 | /* Set DUMP_SECTS for all sections where dumps were requested |
15747 | based on section name. */ | |
15748 | ||
15749 | static void | |
dda8d76d | 15750 | initialise_dumps_byname (Filedata * filedata) |
aef1f6d0 | 15751 | { |
2cf0635d | 15752 | struct dump_list_entry * cur; |
aef1f6d0 DJ |
15753 | |
15754 | for (cur = dump_sects_byname; cur; cur = cur->next) | |
15755 | { | |
15756 | unsigned int i; | |
015dc7e1 | 15757 | bool any = false; |
aef1f6d0 | 15758 | |
dda8d76d | 15759 | for (i = 0; i < filedata->file_header.e_shnum; i++) |
84714f86 AM |
15760 | if (section_name_valid (filedata, filedata->section_headers + i) |
15761 | && streq (section_name (filedata, filedata->section_headers + i), | |
15762 | cur->name)) | |
aef1f6d0 | 15763 | { |
6431e409 | 15764 | request_dump_bynumber (&filedata->dump, i, cur->type); |
015dc7e1 | 15765 | any = true; |
aef1f6d0 DJ |
15766 | } |
15767 | ||
835f2fae NC |
15768 | if (!any && !filedata->is_separate) |
15769 | warn (_("Section '%s' was not dumped because it does not exist\n"), | |
15770 | cur->name); | |
aef1f6d0 DJ |
15771 | } |
15772 | } | |
15773 | ||
015dc7e1 | 15774 | static bool |
dda8d76d | 15775 | process_section_contents (Filedata * filedata) |
5b18a4bc | 15776 | { |
2cf0635d | 15777 | Elf_Internal_Shdr * section; |
19e6b90e | 15778 | unsigned int i; |
015dc7e1 | 15779 | bool res = true; |
103f02d3 | 15780 | |
19e6b90e | 15781 | if (! do_dump) |
015dc7e1 | 15782 | return true; |
103f02d3 | 15783 | |
dda8d76d | 15784 | initialise_dumps_byname (filedata); |
aef1f6d0 | 15785 | |
dda8d76d | 15786 | for (i = 0, section = filedata->section_headers; |
6431e409 | 15787 | i < filedata->file_header.e_shnum && i < filedata->dump.num_dump_sects; |
19e6b90e L |
15788 | i++, section++) |
15789 | { | |
6431e409 | 15790 | dump_type dump = filedata->dump.dump_sects[i]; |
dda8d76d | 15791 | |
d6bfbc39 NC |
15792 | if (filedata->is_separate && ! process_links) |
15793 | dump &= DEBUG_DUMP; | |
047c3dbf | 15794 | |
19e6b90e | 15795 | #ifdef SUPPORT_DISASSEMBLY |
dda8d76d NC |
15796 | if (dump & DISASS_DUMP) |
15797 | { | |
15798 | if (! disassemble_section (section, filedata)) | |
015dc7e1 | 15799 | res = false; |
dda8d76d | 15800 | } |
19e6b90e | 15801 | #endif |
dda8d76d | 15802 | if (dump & HEX_DUMP) |
32ec8896 | 15803 | { |
015dc7e1 AM |
15804 | if (! dump_section_as_bytes (section, filedata, false)) |
15805 | res = false; | |
32ec8896 | 15806 | } |
103f02d3 | 15807 | |
dda8d76d | 15808 | if (dump & RELOC_DUMP) |
32ec8896 | 15809 | { |
015dc7e1 AM |
15810 | if (! dump_section_as_bytes (section, filedata, true)) |
15811 | res = false; | |
32ec8896 | 15812 | } |
09c11c86 | 15813 | |
dda8d76d | 15814 | if (dump & STRING_DUMP) |
32ec8896 | 15815 | { |
dda8d76d | 15816 | if (! dump_section_as_strings (section, filedata)) |
015dc7e1 | 15817 | res = false; |
32ec8896 | 15818 | } |
cf13d699 | 15819 | |
dda8d76d | 15820 | if (dump & DEBUG_DUMP) |
32ec8896 | 15821 | { |
dda8d76d | 15822 | if (! display_debug_section (i, section, filedata)) |
015dc7e1 | 15823 | res = false; |
32ec8896 | 15824 | } |
7d9813f1 | 15825 | |
094e34f2 | 15826 | #ifdef ENABLE_LIBCTF |
7d9813f1 NA |
15827 | if (dump & CTF_DUMP) |
15828 | { | |
15829 | if (! dump_section_as_ctf (section, filedata)) | |
015dc7e1 | 15830 | res = false; |
7d9813f1 | 15831 | } |
094e34f2 | 15832 | #endif |
5b18a4bc | 15833 | } |
103f02d3 | 15834 | |
835f2fae | 15835 | if (! filedata->is_separate) |
0ee3043f | 15836 | { |
835f2fae NC |
15837 | /* Check to see if the user requested a |
15838 | dump of a section that does not exist. */ | |
15839 | for (; i < filedata->dump.num_dump_sects; i++) | |
15840 | if (filedata->dump.dump_sects[i]) | |
15841 | { | |
ca0e11aa | 15842 | warn (_("Section %d was not dumped because it does not exist!\n"), i); |
015dc7e1 | 15843 | res = false; |
835f2fae | 15844 | } |
0ee3043f | 15845 | } |
32ec8896 NC |
15846 | |
15847 | return res; | |
5b18a4bc | 15848 | } |
103f02d3 | 15849 | |
5b18a4bc | 15850 | static void |
19e6b90e | 15851 | process_mips_fpe_exception (int mask) |
5b18a4bc | 15852 | { |
19e6b90e L |
15853 | if (mask) |
15854 | { | |
015dc7e1 | 15855 | bool first = true; |
32ec8896 | 15856 | |
19e6b90e | 15857 | if (mask & OEX_FPU_INEX) |
015dc7e1 | 15858 | fputs ("INEX", stdout), first = false; |
19e6b90e | 15859 | if (mask & OEX_FPU_UFLO) |
015dc7e1 | 15860 | printf ("%sUFLO", first ? "" : "|"), first = false; |
19e6b90e | 15861 | if (mask & OEX_FPU_OFLO) |
015dc7e1 | 15862 | printf ("%sOFLO", first ? "" : "|"), first = false; |
19e6b90e | 15863 | if (mask & OEX_FPU_DIV0) |
015dc7e1 | 15864 | printf ("%sDIV0", first ? "" : "|"), first = false; |
19e6b90e L |
15865 | if (mask & OEX_FPU_INVAL) |
15866 | printf ("%sINVAL", first ? "" : "|"); | |
15867 | } | |
5b18a4bc | 15868 | else |
19e6b90e | 15869 | fputs ("0", stdout); |
5b18a4bc | 15870 | } |
103f02d3 | 15871 | |
f6f0e17b NC |
15872 | /* Display's the value of TAG at location P. If TAG is |
15873 | greater than 0 it is assumed to be an unknown tag, and | |
15874 | a message is printed to this effect. Otherwise it is | |
15875 | assumed that a message has already been printed. | |
15876 | ||
15877 | If the bottom bit of TAG is set it assumed to have a | |
15878 | string value, otherwise it is assumed to have an integer | |
15879 | value. | |
15880 | ||
15881 | Returns an updated P pointing to the first unread byte | |
15882 | beyond the end of TAG's value. | |
15883 | ||
15884 | Reads at or beyond END will not be made. */ | |
15885 | ||
15886 | static unsigned char * | |
60abdbed | 15887 | display_tag_value (signed int tag, |
f6f0e17b NC |
15888 | unsigned char * p, |
15889 | const unsigned char * const end) | |
15890 | { | |
15891 | unsigned long val; | |
15892 | ||
15893 | if (tag > 0) | |
15894 | printf (" Tag_unknown_%d: ", tag); | |
15895 | ||
15896 | if (p >= end) | |
15897 | { | |
4082ef84 | 15898 | warn (_("<corrupt tag>\n")); |
f6f0e17b NC |
15899 | } |
15900 | else if (tag & 1) | |
15901 | { | |
071436c6 NC |
15902 | /* PR 17531 file: 027-19978-0.004. */ |
15903 | size_t maxlen = (end - p) - 1; | |
15904 | ||
15905 | putchar ('"'); | |
4082ef84 NC |
15906 | if (maxlen > 0) |
15907 | { | |
15908 | print_symbol ((int) maxlen, (const char *) p); | |
15909 | p += strnlen ((char *) p, maxlen) + 1; | |
15910 | } | |
15911 | else | |
15912 | { | |
15913 | printf (_("<corrupt string tag>")); | |
15914 | p = (unsigned char *) end; | |
15915 | } | |
071436c6 | 15916 | printf ("\"\n"); |
f6f0e17b NC |
15917 | } |
15918 | else | |
15919 | { | |
cd30bcef | 15920 | READ_ULEB (val, p, end); |
f6f0e17b NC |
15921 | printf ("%ld (0x%lx)\n", val, val); |
15922 | } | |
15923 | ||
4082ef84 | 15924 | assert (p <= end); |
f6f0e17b NC |
15925 | return p; |
15926 | } | |
15927 | ||
53a346d8 CZ |
15928 | /* ARC ABI attributes section. */ |
15929 | ||
15930 | static unsigned char * | |
15931 | display_arc_attribute (unsigned char * p, | |
15932 | const unsigned char * const end) | |
15933 | { | |
15934 | unsigned int tag; | |
53a346d8 CZ |
15935 | unsigned int val; |
15936 | ||
cd30bcef | 15937 | READ_ULEB (tag, p, end); |
53a346d8 CZ |
15938 | |
15939 | switch (tag) | |
15940 | { | |
15941 | case Tag_ARC_PCS_config: | |
cd30bcef | 15942 | READ_ULEB (val, p, end); |
53a346d8 CZ |
15943 | printf (" Tag_ARC_PCS_config: "); |
15944 | switch (val) | |
15945 | { | |
15946 | case 0: | |
15947 | printf (_("Absent/Non standard\n")); | |
15948 | break; | |
15949 | case 1: | |
15950 | printf (_("Bare metal/mwdt\n")); | |
15951 | break; | |
15952 | case 2: | |
15953 | printf (_("Bare metal/newlib\n")); | |
15954 | break; | |
15955 | case 3: | |
15956 | printf (_("Linux/uclibc\n")); | |
15957 | break; | |
15958 | case 4: | |
15959 | printf (_("Linux/glibc\n")); | |
15960 | break; | |
15961 | default: | |
15962 | printf (_("Unknown\n")); | |
15963 | break; | |
15964 | } | |
15965 | break; | |
15966 | ||
15967 | case Tag_ARC_CPU_base: | |
cd30bcef | 15968 | READ_ULEB (val, p, end); |
53a346d8 CZ |
15969 | printf (" Tag_ARC_CPU_base: "); |
15970 | switch (val) | |
15971 | { | |
15972 | default: | |
15973 | case TAG_CPU_NONE: | |
15974 | printf (_("Absent\n")); | |
15975 | break; | |
15976 | case TAG_CPU_ARC6xx: | |
15977 | printf ("ARC6xx\n"); | |
15978 | break; | |
15979 | case TAG_CPU_ARC7xx: | |
15980 | printf ("ARC7xx\n"); | |
15981 | break; | |
15982 | case TAG_CPU_ARCEM: | |
15983 | printf ("ARCEM\n"); | |
15984 | break; | |
15985 | case TAG_CPU_ARCHS: | |
15986 | printf ("ARCHS\n"); | |
15987 | break; | |
15988 | } | |
15989 | break; | |
15990 | ||
15991 | case Tag_ARC_CPU_variation: | |
cd30bcef | 15992 | READ_ULEB (val, p, end); |
53a346d8 CZ |
15993 | printf (" Tag_ARC_CPU_variation: "); |
15994 | switch (val) | |
15995 | { | |
15996 | default: | |
15997 | if (val > 0 && val < 16) | |
53a346d8 | 15998 | printf ("Core%d\n", val); |
d8cbc93b JL |
15999 | else |
16000 | printf ("Unknown\n"); | |
16001 | break; | |
16002 | ||
53a346d8 CZ |
16003 | case 0: |
16004 | printf (_("Absent\n")); | |
16005 | break; | |
16006 | } | |
16007 | break; | |
16008 | ||
16009 | case Tag_ARC_CPU_name: | |
16010 | printf (" Tag_ARC_CPU_name: "); | |
16011 | p = display_tag_value (-1, p, end); | |
16012 | break; | |
16013 | ||
16014 | case Tag_ARC_ABI_rf16: | |
cd30bcef | 16015 | READ_ULEB (val, p, end); |
53a346d8 CZ |
16016 | printf (" Tag_ARC_ABI_rf16: %s\n", val ? _("yes") : _("no")); |
16017 | break; | |
16018 | ||
16019 | case Tag_ARC_ABI_osver: | |
cd30bcef | 16020 | READ_ULEB (val, p, end); |
53a346d8 CZ |
16021 | printf (" Tag_ARC_ABI_osver: v%d\n", val); |
16022 | break; | |
16023 | ||
16024 | case Tag_ARC_ABI_pic: | |
16025 | case Tag_ARC_ABI_sda: | |
cd30bcef | 16026 | READ_ULEB (val, p, end); |
53a346d8 CZ |
16027 | printf (tag == Tag_ARC_ABI_sda ? " Tag_ARC_ABI_sda: " |
16028 | : " Tag_ARC_ABI_pic: "); | |
16029 | switch (val) | |
16030 | { | |
16031 | case 0: | |
16032 | printf (_("Absent\n")); | |
16033 | break; | |
16034 | case 1: | |
16035 | printf ("MWDT\n"); | |
16036 | break; | |
16037 | case 2: | |
16038 | printf ("GNU\n"); | |
16039 | break; | |
16040 | default: | |
16041 | printf (_("Unknown\n")); | |
16042 | break; | |
16043 | } | |
16044 | break; | |
16045 | ||
16046 | case Tag_ARC_ABI_tls: | |
cd30bcef | 16047 | READ_ULEB (val, p, end); |
53a346d8 CZ |
16048 | printf (" Tag_ARC_ABI_tls: %s\n", val ? "r25": "none"); |
16049 | break; | |
16050 | ||
16051 | case Tag_ARC_ABI_enumsize: | |
cd30bcef | 16052 | READ_ULEB (val, p, end); |
53a346d8 CZ |
16053 | printf (" Tag_ARC_ABI_enumsize: %s\n", val ? _("default") : |
16054 | _("smallest")); | |
16055 | break; | |
16056 | ||
16057 | case Tag_ARC_ABI_exceptions: | |
cd30bcef | 16058 | READ_ULEB (val, p, end); |
53a346d8 CZ |
16059 | printf (" Tag_ARC_ABI_exceptions: %s\n", val ? _("OPTFP") |
16060 | : _("default")); | |
16061 | break; | |
16062 | ||
16063 | case Tag_ARC_ABI_double_size: | |
cd30bcef | 16064 | READ_ULEB (val, p, end); |
53a346d8 CZ |
16065 | printf (" Tag_ARC_ABI_double_size: %d\n", val); |
16066 | break; | |
16067 | ||
16068 | case Tag_ARC_ISA_config: | |
16069 | printf (" Tag_ARC_ISA_config: "); | |
16070 | p = display_tag_value (-1, p, end); | |
16071 | break; | |
16072 | ||
16073 | case Tag_ARC_ISA_apex: | |
16074 | printf (" Tag_ARC_ISA_apex: "); | |
16075 | p = display_tag_value (-1, p, end); | |
16076 | break; | |
16077 | ||
16078 | case Tag_ARC_ISA_mpy_option: | |
cd30bcef | 16079 | READ_ULEB (val, p, end); |
53a346d8 CZ |
16080 | printf (" Tag_ARC_ISA_mpy_option: %d\n", val); |
16081 | break; | |
16082 | ||
db1e1b45 | 16083 | case Tag_ARC_ATR_version: |
cd30bcef | 16084 | READ_ULEB (val, p, end); |
db1e1b45 | 16085 | printf (" Tag_ARC_ATR_version: %d\n", val); |
16086 | break; | |
16087 | ||
53a346d8 CZ |
16088 | default: |
16089 | return display_tag_value (tag & 1, p, end); | |
16090 | } | |
16091 | ||
16092 | return p; | |
16093 | } | |
16094 | ||
11c1ff18 PB |
16095 | /* ARM EABI attributes section. */ |
16096 | typedef struct | |
16097 | { | |
70e99720 | 16098 | unsigned int tag; |
2cf0635d | 16099 | const char * name; |
11c1ff18 | 16100 | /* 0 = special, 1 = string, 2 = uleb123, > 0x80 == table lookup. */ |
70e99720 | 16101 | unsigned int type; |
288f0ba2 | 16102 | const char *const *table; |
11c1ff18 PB |
16103 | } arm_attr_public_tag; |
16104 | ||
288f0ba2 | 16105 | static const char *const arm_attr_tag_CPU_arch[] = |
11c1ff18 | 16106 | {"Pre-v4", "v4", "v4T", "v5T", "v5TE", "v5TEJ", "v6", "v6KZ", "v6T2", |
ced40572 | 16107 | "v6K", "v7", "v6-M", "v6S-M", "v7E-M", "v8", "v8-R", "v8-M.baseline", |
3197e593 PW |
16108 | "v8-M.mainline", "v8.1-A", "v8.2-A", "v8.3-A", |
16109 | "v8.1-M.mainline", "v9"}; | |
288f0ba2 AM |
16110 | static const char *const arm_attr_tag_ARM_ISA_use[] = {"No", "Yes"}; |
16111 | static const char *const arm_attr_tag_THUMB_ISA_use[] = | |
4ed7ed8d | 16112 | {"No", "Thumb-1", "Thumb-2", "Yes"}; |
288f0ba2 | 16113 | static const char *const arm_attr_tag_FP_arch[] = |
bca38921 | 16114 | {"No", "VFPv1", "VFPv2", "VFPv3", "VFPv3-D16", "VFPv4", "VFPv4-D16", |
a715796b | 16115 | "FP for ARMv8", "FPv5/FP-D16 for ARMv8"}; |
288f0ba2 AM |
16116 | static const char *const arm_attr_tag_WMMX_arch[] = {"No", "WMMXv1", "WMMXv2"}; |
16117 | static const char *const arm_attr_tag_Advanced_SIMD_arch[] = | |
9411fd44 MW |
16118 | {"No", "NEONv1", "NEONv1 with Fused-MAC", "NEON for ARMv8", |
16119 | "NEON for ARMv8.1"}; | |
288f0ba2 | 16120 | static const char *const arm_attr_tag_PCS_config[] = |
11c1ff18 PB |
16121 | {"None", "Bare platform", "Linux application", "Linux DSO", "PalmOS 2004", |
16122 | "PalmOS (reserved)", "SymbianOS 2004", "SymbianOS (reserved)"}; | |
288f0ba2 | 16123 | static const char *const arm_attr_tag_ABI_PCS_R9_use[] = |
11c1ff18 | 16124 | {"V6", "SB", "TLS", "Unused"}; |
288f0ba2 | 16125 | static const char *const arm_attr_tag_ABI_PCS_RW_data[] = |
11c1ff18 | 16126 | {"Absolute", "PC-relative", "SB-relative", "None"}; |
288f0ba2 | 16127 | static const char *const arm_attr_tag_ABI_PCS_RO_data[] = |
11c1ff18 | 16128 | {"Absolute", "PC-relative", "None"}; |
288f0ba2 | 16129 | static const char *const arm_attr_tag_ABI_PCS_GOT_use[] = |
11c1ff18 | 16130 | {"None", "direct", "GOT-indirect"}; |
288f0ba2 | 16131 | static const char *const arm_attr_tag_ABI_PCS_wchar_t[] = |
11c1ff18 | 16132 | {"None", "??? 1", "2", "??? 3", "4"}; |
288f0ba2 AM |
16133 | static const char *const arm_attr_tag_ABI_FP_rounding[] = {"Unused", "Needed"}; |
16134 | static const char *const arm_attr_tag_ABI_FP_denormal[] = | |
f5f53991 | 16135 | {"Unused", "Needed", "Sign only"}; |
288f0ba2 AM |
16136 | static const char *const arm_attr_tag_ABI_FP_exceptions[] = {"Unused", "Needed"}; |
16137 | static const char *const arm_attr_tag_ABI_FP_user_exceptions[] = {"Unused", "Needed"}; | |
16138 | static const char *const arm_attr_tag_ABI_FP_number_model[] = | |
11c1ff18 | 16139 | {"Unused", "Finite", "RTABI", "IEEE 754"}; |
288f0ba2 | 16140 | static const char *const arm_attr_tag_ABI_enum_size[] = |
11c1ff18 | 16141 | {"Unused", "small", "int", "forced to int"}; |
288f0ba2 | 16142 | static const char *const arm_attr_tag_ABI_HardFP_use[] = |
99654aaf | 16143 | {"As Tag_FP_arch", "SP only", "Reserved", "Deprecated"}; |
288f0ba2 | 16144 | static const char *const arm_attr_tag_ABI_VFP_args[] = |
5c294fee | 16145 | {"AAPCS", "VFP registers", "custom", "compatible"}; |
288f0ba2 | 16146 | static const char *const arm_attr_tag_ABI_WMMX_args[] = |
11c1ff18 | 16147 | {"AAPCS", "WMMX registers", "custom"}; |
288f0ba2 | 16148 | static const char *const arm_attr_tag_ABI_optimization_goals[] = |
11c1ff18 PB |
16149 | {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size", |
16150 | "Aggressive Size", "Prefer Debug", "Aggressive Debug"}; | |
288f0ba2 | 16151 | static const char *const arm_attr_tag_ABI_FP_optimization_goals[] = |
11c1ff18 PB |
16152 | {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size", |
16153 | "Aggressive Size", "Prefer Accuracy", "Aggressive Accuracy"}; | |
288f0ba2 AM |
16154 | static const char *const arm_attr_tag_CPU_unaligned_access[] = {"None", "v6"}; |
16155 | static const char *const arm_attr_tag_FP_HP_extension[] = | |
8e79c3df | 16156 | {"Not Allowed", "Allowed"}; |
288f0ba2 | 16157 | static const char *const arm_attr_tag_ABI_FP_16bit_format[] = |
8e79c3df | 16158 | {"None", "IEEE 754", "Alternative Format"}; |
288f0ba2 | 16159 | static const char *const arm_attr_tag_DSP_extension[] = |
15afaa63 | 16160 | {"Follow architecture", "Allowed"}; |
288f0ba2 | 16161 | static const char *const arm_attr_tag_MPextension_use[] = |
cd21e546 | 16162 | {"Not Allowed", "Allowed"}; |
288f0ba2 | 16163 | static const char *const arm_attr_tag_DIV_use[] = |
dd24e3da | 16164 | {"Allowed in Thumb-ISA, v7-R or v7-M", "Not allowed", |
cd21e546 | 16165 | "Allowed in v7-A with integer division extension"}; |
288f0ba2 AM |
16166 | static const char *const arm_attr_tag_T2EE_use[] = {"Not Allowed", "Allowed"}; |
16167 | static const char *const arm_attr_tag_Virtualization_use[] = | |
dd24e3da | 16168 | {"Not Allowed", "TrustZone", "Virtualization Extensions", |
cd21e546 | 16169 | "TrustZone and Virtualization Extensions"}; |
288f0ba2 | 16170 | static const char *const arm_attr_tag_MPextension_use_legacy[] = |
f5f53991 | 16171 | {"Not Allowed", "Allowed"}; |
11c1ff18 | 16172 | |
288f0ba2 | 16173 | static const char *const arm_attr_tag_MVE_arch[] = |
a7ad558c AV |
16174 | {"No MVE", "MVE Integer only", "MVE Integer and FP"}; |
16175 | ||
99db83d0 AC |
16176 | static const char * arm_attr_tag_PAC_extension[] = |
16177 | {"No PAC/AUT instructions", | |
16178 | "PAC/AUT instructions permitted in the NOP space", | |
16179 | "PAC/AUT instructions permitted in the NOP and in the non-NOP space"}; | |
16180 | ||
4b535030 AC |
16181 | static const char * arm_attr_tag_BTI_extension[] = |
16182 | {"BTI instructions not permitted", | |
16183 | "BTI instructions permitted in the NOP space", | |
16184 | "BTI instructions permitted in the NOP and in the non-NOP space"}; | |
16185 | ||
b81ee92f AC |
16186 | static const char * arm_attr_tag_BTI_use[] = |
16187 | {"Compiled without branch target enforcement", | |
16188 | "Compiled with branch target enforcement"}; | |
16189 | ||
c9fed665 AC |
16190 | static const char * arm_attr_tag_PACRET_use[] = |
16191 | {"Compiled without return address signing and authentication", | |
16192 | "Compiled with return address signing and authentication"}; | |
16193 | ||
11c1ff18 PB |
16194 | #define LOOKUP(id, name) \ |
16195 | {id, #name, 0x80 | ARRAY_SIZE(arm_attr_tag_##name), arm_attr_tag_##name} | |
d70c5fc7 | 16196 | static arm_attr_public_tag arm_attr_public_tags[] = |
11c1ff18 PB |
16197 | { |
16198 | {4, "CPU_raw_name", 1, NULL}, | |
16199 | {5, "CPU_name", 1, NULL}, | |
16200 | LOOKUP(6, CPU_arch), | |
16201 | {7, "CPU_arch_profile", 0, NULL}, | |
16202 | LOOKUP(8, ARM_ISA_use), | |
16203 | LOOKUP(9, THUMB_ISA_use), | |
75375b3e | 16204 | LOOKUP(10, FP_arch), |
11c1ff18 | 16205 | LOOKUP(11, WMMX_arch), |
f5f53991 AS |
16206 | LOOKUP(12, Advanced_SIMD_arch), |
16207 | LOOKUP(13, PCS_config), | |
11c1ff18 PB |
16208 | LOOKUP(14, ABI_PCS_R9_use), |
16209 | LOOKUP(15, ABI_PCS_RW_data), | |
f5f53991 | 16210 | LOOKUP(16, ABI_PCS_RO_data), |
11c1ff18 PB |
16211 | LOOKUP(17, ABI_PCS_GOT_use), |
16212 | LOOKUP(18, ABI_PCS_wchar_t), | |
16213 | LOOKUP(19, ABI_FP_rounding), | |
16214 | LOOKUP(20, ABI_FP_denormal), | |
16215 | LOOKUP(21, ABI_FP_exceptions), | |
16216 | LOOKUP(22, ABI_FP_user_exceptions), | |
16217 | LOOKUP(23, ABI_FP_number_model), | |
75375b3e MGD |
16218 | {24, "ABI_align_needed", 0, NULL}, |
16219 | {25, "ABI_align_preserved", 0, NULL}, | |
11c1ff18 PB |
16220 | LOOKUP(26, ABI_enum_size), |
16221 | LOOKUP(27, ABI_HardFP_use), | |
16222 | LOOKUP(28, ABI_VFP_args), | |
16223 | LOOKUP(29, ABI_WMMX_args), | |
16224 | LOOKUP(30, ABI_optimization_goals), | |
16225 | LOOKUP(31, ABI_FP_optimization_goals), | |
8e79c3df | 16226 | {32, "compatibility", 0, NULL}, |
f5f53991 | 16227 | LOOKUP(34, CPU_unaligned_access), |
75375b3e | 16228 | LOOKUP(36, FP_HP_extension), |
8e79c3df | 16229 | LOOKUP(38, ABI_FP_16bit_format), |
cd21e546 MGD |
16230 | LOOKUP(42, MPextension_use), |
16231 | LOOKUP(44, DIV_use), | |
15afaa63 | 16232 | LOOKUP(46, DSP_extension), |
a7ad558c | 16233 | LOOKUP(48, MVE_arch), |
99db83d0 | 16234 | LOOKUP(50, PAC_extension), |
4b535030 | 16235 | LOOKUP(52, BTI_extension), |
b81ee92f | 16236 | LOOKUP(74, BTI_use), |
c9fed665 | 16237 | LOOKUP(76, PACRET_use), |
f5f53991 AS |
16238 | {64, "nodefaults", 0, NULL}, |
16239 | {65, "also_compatible_with", 0, NULL}, | |
16240 | LOOKUP(66, T2EE_use), | |
16241 | {67, "conformance", 1, NULL}, | |
16242 | LOOKUP(68, Virtualization_use), | |
cd21e546 | 16243 | LOOKUP(70, MPextension_use_legacy) |
11c1ff18 PB |
16244 | }; |
16245 | #undef LOOKUP | |
16246 | ||
11c1ff18 | 16247 | static unsigned char * |
f6f0e17b NC |
16248 | display_arm_attribute (unsigned char * p, |
16249 | const unsigned char * const end) | |
11c1ff18 | 16250 | { |
70e99720 | 16251 | unsigned int tag; |
70e99720 | 16252 | unsigned int val; |
2cf0635d | 16253 | arm_attr_public_tag * attr; |
11c1ff18 | 16254 | unsigned i; |
70e99720 | 16255 | unsigned int type; |
11c1ff18 | 16256 | |
cd30bcef | 16257 | READ_ULEB (tag, p, end); |
11c1ff18 | 16258 | attr = NULL; |
2cf0635d | 16259 | for (i = 0; i < ARRAY_SIZE (arm_attr_public_tags); i++) |
11c1ff18 PB |
16260 | { |
16261 | if (arm_attr_public_tags[i].tag == tag) | |
16262 | { | |
16263 | attr = &arm_attr_public_tags[i]; | |
16264 | break; | |
16265 | } | |
16266 | } | |
16267 | ||
16268 | if (attr) | |
16269 | { | |
16270 | printf (" Tag_%s: ", attr->name); | |
16271 | switch (attr->type) | |
16272 | { | |
16273 | case 0: | |
16274 | switch (tag) | |
16275 | { | |
16276 | case 7: /* Tag_CPU_arch_profile. */ | |
cd30bcef | 16277 | READ_ULEB (val, p, end); |
11c1ff18 PB |
16278 | switch (val) |
16279 | { | |
2b692964 NC |
16280 | case 0: printf (_("None\n")); break; |
16281 | case 'A': printf (_("Application\n")); break; | |
16282 | case 'R': printf (_("Realtime\n")); break; | |
16283 | case 'M': printf (_("Microcontroller\n")); break; | |
16284 | case 'S': printf (_("Application or Realtime\n")); break; | |
11c1ff18 PB |
16285 | default: printf ("??? (%d)\n", val); break; |
16286 | } | |
16287 | break; | |
16288 | ||
75375b3e | 16289 | case 24: /* Tag_align_needed. */ |
cd30bcef | 16290 | READ_ULEB (val, p, end); |
75375b3e MGD |
16291 | switch (val) |
16292 | { | |
2b692964 NC |
16293 | case 0: printf (_("None\n")); break; |
16294 | case 1: printf (_("8-byte\n")); break; | |
16295 | case 2: printf (_("4-byte\n")); break; | |
75375b3e MGD |
16296 | case 3: printf ("??? 3\n"); break; |
16297 | default: | |
16298 | if (val <= 12) | |
dd24e3da | 16299 | printf (_("8-byte and up to %d-byte extended\n"), |
75375b3e MGD |
16300 | 1 << val); |
16301 | else | |
16302 | printf ("??? (%d)\n", val); | |
16303 | break; | |
16304 | } | |
16305 | break; | |
16306 | ||
16307 | case 25: /* Tag_align_preserved. */ | |
cd30bcef | 16308 | READ_ULEB (val, p, end); |
75375b3e MGD |
16309 | switch (val) |
16310 | { | |
2b692964 NC |
16311 | case 0: printf (_("None\n")); break; |
16312 | case 1: printf (_("8-byte, except leaf SP\n")); break; | |
16313 | case 2: printf (_("8-byte\n")); break; | |
75375b3e MGD |
16314 | case 3: printf ("??? 3\n"); break; |
16315 | default: | |
16316 | if (val <= 12) | |
dd24e3da | 16317 | printf (_("8-byte and up to %d-byte extended\n"), |
75375b3e MGD |
16318 | 1 << val); |
16319 | else | |
16320 | printf ("??? (%d)\n", val); | |
16321 | break; | |
16322 | } | |
16323 | break; | |
16324 | ||
11c1ff18 | 16325 | case 32: /* Tag_compatibility. */ |
071436c6 | 16326 | { |
cd30bcef | 16327 | READ_ULEB (val, p, end); |
071436c6 | 16328 | printf (_("flag = %d, vendor = "), val); |
4082ef84 NC |
16329 | if (p < end - 1) |
16330 | { | |
16331 | size_t maxlen = (end - p) - 1; | |
16332 | ||
16333 | print_symbol ((int) maxlen, (const char *) p); | |
16334 | p += strnlen ((char *) p, maxlen) + 1; | |
16335 | } | |
16336 | else | |
16337 | { | |
16338 | printf (_("<corrupt>")); | |
16339 | p = (unsigned char *) end; | |
16340 | } | |
071436c6 | 16341 | putchar ('\n'); |
071436c6 | 16342 | } |
11c1ff18 PB |
16343 | break; |
16344 | ||
f5f53991 | 16345 | case 64: /* Tag_nodefaults. */ |
541a3cbd NC |
16346 | /* PR 17531: file: 001-505008-0.01. */ |
16347 | if (p < end) | |
16348 | p++; | |
2b692964 | 16349 | printf (_("True\n")); |
f5f53991 AS |
16350 | break; |
16351 | ||
16352 | case 65: /* Tag_also_compatible_with. */ | |
cd30bcef | 16353 | READ_ULEB (val, p, end); |
f5f53991 AS |
16354 | if (val == 6 /* Tag_CPU_arch. */) |
16355 | { | |
cd30bcef | 16356 | READ_ULEB (val, p, end); |
071436c6 | 16357 | if ((unsigned int) val >= ARRAY_SIZE (arm_attr_tag_CPU_arch)) |
f5f53991 AS |
16358 | printf ("??? (%d)\n", val); |
16359 | else | |
16360 | printf ("%s\n", arm_attr_tag_CPU_arch[val]); | |
16361 | } | |
16362 | else | |
16363 | printf ("???\n"); | |
071436c6 NC |
16364 | while (p < end && *(p++) != '\0' /* NUL terminator. */) |
16365 | ; | |
f5f53991 AS |
16366 | break; |
16367 | ||
11c1ff18 | 16368 | default: |
bee0ee85 NC |
16369 | printf (_("<unknown: %d>\n"), tag); |
16370 | break; | |
11c1ff18 PB |
16371 | } |
16372 | return p; | |
16373 | ||
16374 | case 1: | |
f6f0e17b | 16375 | return display_tag_value (-1, p, end); |
11c1ff18 | 16376 | case 2: |
f6f0e17b | 16377 | return display_tag_value (0, p, end); |
11c1ff18 PB |
16378 | |
16379 | default: | |
16380 | assert (attr->type & 0x80); | |
cd30bcef | 16381 | READ_ULEB (val, p, end); |
11c1ff18 PB |
16382 | type = attr->type & 0x7f; |
16383 | if (val >= type) | |
16384 | printf ("??? (%d)\n", val); | |
16385 | else | |
16386 | printf ("%s\n", attr->table[val]); | |
16387 | return p; | |
16388 | } | |
16389 | } | |
11c1ff18 | 16390 | |
f6f0e17b | 16391 | return display_tag_value (tag, p, end); |
11c1ff18 PB |
16392 | } |
16393 | ||
104d59d1 | 16394 | static unsigned char * |
60bca95a | 16395 | display_gnu_attribute (unsigned char * p, |
60abdbed | 16396 | unsigned char * (* display_proc_gnu_attribute) (unsigned char *, unsigned int, const unsigned char * const), |
f6f0e17b | 16397 | const unsigned char * const end) |
104d59d1 | 16398 | { |
cd30bcef | 16399 | unsigned int tag; |
60abdbed | 16400 | unsigned int val; |
104d59d1 | 16401 | |
cd30bcef | 16402 | READ_ULEB (tag, p, end); |
104d59d1 JM |
16403 | |
16404 | /* Tag_compatibility is the only generic GNU attribute defined at | |
16405 | present. */ | |
16406 | if (tag == 32) | |
16407 | { | |
cd30bcef | 16408 | READ_ULEB (val, p, end); |
071436c6 NC |
16409 | |
16410 | printf (_("flag = %d, vendor = "), val); | |
f6f0e17b NC |
16411 | if (p == end) |
16412 | { | |
071436c6 | 16413 | printf (_("<corrupt>\n")); |
f6f0e17b NC |
16414 | warn (_("corrupt vendor attribute\n")); |
16415 | } | |
16416 | else | |
16417 | { | |
4082ef84 NC |
16418 | if (p < end - 1) |
16419 | { | |
16420 | size_t maxlen = (end - p) - 1; | |
071436c6 | 16421 | |
4082ef84 NC |
16422 | print_symbol ((int) maxlen, (const char *) p); |
16423 | p += strnlen ((char *) p, maxlen) + 1; | |
16424 | } | |
16425 | else | |
16426 | { | |
16427 | printf (_("<corrupt>")); | |
16428 | p = (unsigned char *) end; | |
16429 | } | |
071436c6 | 16430 | putchar ('\n'); |
f6f0e17b | 16431 | } |
104d59d1 JM |
16432 | return p; |
16433 | } | |
16434 | ||
16435 | if ((tag & 2) == 0 && display_proc_gnu_attribute) | |
f6f0e17b | 16436 | return display_proc_gnu_attribute (p, tag, end); |
104d59d1 | 16437 | |
f6f0e17b | 16438 | return display_tag_value (tag, p, end); |
104d59d1 JM |
16439 | } |
16440 | ||
85f7484a PB |
16441 | static unsigned char * |
16442 | display_m68k_gnu_attribute (unsigned char * p, | |
16443 | unsigned int tag, | |
16444 | const unsigned char * const end) | |
16445 | { | |
16446 | unsigned int val; | |
16447 | ||
16448 | if (tag == Tag_GNU_M68K_ABI_FP) | |
16449 | { | |
16450 | printf (" Tag_GNU_M68K_ABI_FP: "); | |
16451 | if (p == end) | |
16452 | { | |
16453 | printf (_("<corrupt>\n")); | |
16454 | return p; | |
16455 | } | |
16456 | READ_ULEB (val, p, end); | |
16457 | ||
16458 | if (val > 3) | |
16459 | printf ("(%#x), ", val); | |
16460 | ||
16461 | switch (val & 3) | |
16462 | { | |
16463 | case 0: | |
16464 | printf (_("unspecified hard/soft float\n")); | |
16465 | break; | |
16466 | case 1: | |
16467 | printf (_("hard float\n")); | |
16468 | break; | |
16469 | case 2: | |
16470 | printf (_("soft float\n")); | |
16471 | break; | |
16472 | } | |
16473 | return p; | |
16474 | } | |
16475 | ||
16476 | return display_tag_value (tag & 1, p, end); | |
16477 | } | |
16478 | ||
34c8bcba | 16479 | static unsigned char * |
f6f0e17b | 16480 | display_power_gnu_attribute (unsigned char * p, |
60abdbed | 16481 | unsigned int tag, |
f6f0e17b | 16482 | const unsigned char * const end) |
34c8bcba | 16483 | { |
005d79fd | 16484 | unsigned int val; |
34c8bcba JM |
16485 | |
16486 | if (tag == Tag_GNU_Power_ABI_FP) | |
16487 | { | |
34c8bcba | 16488 | printf (" Tag_GNU_Power_ABI_FP: "); |
cd30bcef | 16489 | if (p == end) |
005d79fd AM |
16490 | { |
16491 | printf (_("<corrupt>\n")); | |
16492 | return p; | |
16493 | } | |
cd30bcef | 16494 | READ_ULEB (val, p, end); |
60bca95a | 16495 | |
005d79fd AM |
16496 | if (val > 15) |
16497 | printf ("(%#x), ", val); | |
16498 | ||
16499 | switch (val & 3) | |
34c8bcba JM |
16500 | { |
16501 | case 0: | |
005d79fd | 16502 | printf (_("unspecified hard/soft float, ")); |
34c8bcba JM |
16503 | break; |
16504 | case 1: | |
005d79fd | 16505 | printf (_("hard float, ")); |
34c8bcba JM |
16506 | break; |
16507 | case 2: | |
005d79fd | 16508 | printf (_("soft float, ")); |
34c8bcba | 16509 | break; |
3c7b9897 | 16510 | case 3: |
005d79fd | 16511 | printf (_("single-precision hard float, ")); |
3c7b9897 | 16512 | break; |
005d79fd AM |
16513 | } |
16514 | ||
16515 | switch (val & 0xC) | |
16516 | { | |
16517 | case 0: | |
16518 | printf (_("unspecified long double\n")); | |
16519 | break; | |
16520 | case 4: | |
16521 | printf (_("128-bit IBM long double\n")); | |
16522 | break; | |
16523 | case 8: | |
16524 | printf (_("64-bit long double\n")); | |
16525 | break; | |
16526 | case 12: | |
16527 | printf (_("128-bit IEEE long double\n")); | |
34c8bcba JM |
16528 | break; |
16529 | } | |
16530 | return p; | |
005d79fd | 16531 | } |
34c8bcba | 16532 | |
c6e65352 DJ |
16533 | if (tag == Tag_GNU_Power_ABI_Vector) |
16534 | { | |
c6e65352 | 16535 | printf (" Tag_GNU_Power_ABI_Vector: "); |
cd30bcef | 16536 | if (p == end) |
005d79fd AM |
16537 | { |
16538 | printf (_("<corrupt>\n")); | |
16539 | return p; | |
16540 | } | |
cd30bcef | 16541 | READ_ULEB (val, p, end); |
005d79fd AM |
16542 | |
16543 | if (val > 3) | |
16544 | printf ("(%#x), ", val); | |
16545 | ||
16546 | switch (val & 3) | |
c6e65352 DJ |
16547 | { |
16548 | case 0: | |
005d79fd | 16549 | printf (_("unspecified\n")); |
c6e65352 DJ |
16550 | break; |
16551 | case 1: | |
005d79fd | 16552 | printf (_("generic\n")); |
c6e65352 DJ |
16553 | break; |
16554 | case 2: | |
16555 | printf ("AltiVec\n"); | |
16556 | break; | |
16557 | case 3: | |
16558 | printf ("SPE\n"); | |
16559 | break; | |
c6e65352 DJ |
16560 | } |
16561 | return p; | |
005d79fd | 16562 | } |
c6e65352 | 16563 | |
f82e0623 NF |
16564 | if (tag == Tag_GNU_Power_ABI_Struct_Return) |
16565 | { | |
005d79fd | 16566 | printf (" Tag_GNU_Power_ABI_Struct_Return: "); |
cd30bcef | 16567 | if (p == end) |
f6f0e17b | 16568 | { |
005d79fd | 16569 | printf (_("<corrupt>\n")); |
f6f0e17b NC |
16570 | return p; |
16571 | } | |
cd30bcef | 16572 | READ_ULEB (val, p, end); |
0b4362b0 | 16573 | |
005d79fd AM |
16574 | if (val > 2) |
16575 | printf ("(%#x), ", val); | |
16576 | ||
16577 | switch (val & 3) | |
16578 | { | |
16579 | case 0: | |
16580 | printf (_("unspecified\n")); | |
16581 | break; | |
16582 | case 1: | |
16583 | printf ("r3/r4\n"); | |
16584 | break; | |
16585 | case 2: | |
16586 | printf (_("memory\n")); | |
16587 | break; | |
16588 | case 3: | |
16589 | printf ("???\n"); | |
16590 | break; | |
16591 | } | |
f82e0623 NF |
16592 | return p; |
16593 | } | |
16594 | ||
f6f0e17b | 16595 | return display_tag_value (tag & 1, p, end); |
34c8bcba JM |
16596 | } |
16597 | ||
643f7afb AK |
16598 | static unsigned char * |
16599 | display_s390_gnu_attribute (unsigned char * p, | |
60abdbed | 16600 | unsigned int tag, |
643f7afb AK |
16601 | const unsigned char * const end) |
16602 | { | |
cd30bcef | 16603 | unsigned int val; |
643f7afb AK |
16604 | |
16605 | if (tag == Tag_GNU_S390_ABI_Vector) | |
16606 | { | |
643f7afb | 16607 | printf (" Tag_GNU_S390_ABI_Vector: "); |
cd30bcef | 16608 | READ_ULEB (val, p, end); |
643f7afb AK |
16609 | |
16610 | switch (val) | |
16611 | { | |
16612 | case 0: | |
16613 | printf (_("any\n")); | |
16614 | break; | |
16615 | case 1: | |
16616 | printf (_("software\n")); | |
16617 | break; | |
16618 | case 2: | |
16619 | printf (_("hardware\n")); | |
16620 | break; | |
16621 | default: | |
16622 | printf ("??? (%d)\n", val); | |
16623 | break; | |
16624 | } | |
16625 | return p; | |
16626 | } | |
16627 | ||
16628 | return display_tag_value (tag & 1, p, end); | |
16629 | } | |
16630 | ||
9e8c70f9 | 16631 | static void |
60abdbed | 16632 | display_sparc_hwcaps (unsigned int mask) |
9e8c70f9 DM |
16633 | { |
16634 | if (mask) | |
16635 | { | |
015dc7e1 | 16636 | bool first = true; |
071436c6 | 16637 | |
9e8c70f9 | 16638 | if (mask & ELF_SPARC_HWCAP_MUL32) |
015dc7e1 | 16639 | fputs ("mul32", stdout), first = false; |
9e8c70f9 | 16640 | if (mask & ELF_SPARC_HWCAP_DIV32) |
015dc7e1 | 16641 | printf ("%sdiv32", first ? "" : "|"), first = false; |
9e8c70f9 | 16642 | if (mask & ELF_SPARC_HWCAP_FSMULD) |
015dc7e1 | 16643 | printf ("%sfsmuld", first ? "" : "|"), first = false; |
9e8c70f9 | 16644 | if (mask & ELF_SPARC_HWCAP_V8PLUS) |
015dc7e1 | 16645 | printf ("%sv8plus", first ? "" : "|"), first = false; |
9e8c70f9 | 16646 | if (mask & ELF_SPARC_HWCAP_POPC) |
015dc7e1 | 16647 | printf ("%spopc", first ? "" : "|"), first = false; |
9e8c70f9 | 16648 | if (mask & ELF_SPARC_HWCAP_VIS) |
015dc7e1 | 16649 | printf ("%svis", first ? "" : "|"), first = false; |
9e8c70f9 | 16650 | if (mask & ELF_SPARC_HWCAP_VIS2) |
015dc7e1 | 16651 | printf ("%svis2", first ? "" : "|"), first = false; |
9e8c70f9 | 16652 | if (mask & ELF_SPARC_HWCAP_ASI_BLK_INIT) |
015dc7e1 | 16653 | printf ("%sASIBlkInit", first ? "" : "|"), first = false; |
9e8c70f9 | 16654 | if (mask & ELF_SPARC_HWCAP_FMAF) |
015dc7e1 | 16655 | printf ("%sfmaf", first ? "" : "|"), first = false; |
9e8c70f9 | 16656 | if (mask & ELF_SPARC_HWCAP_VIS3) |
015dc7e1 | 16657 | printf ("%svis3", first ? "" : "|"), first = false; |
9e8c70f9 | 16658 | if (mask & ELF_SPARC_HWCAP_HPC) |
015dc7e1 | 16659 | printf ("%shpc", first ? "" : "|"), first = false; |
9e8c70f9 | 16660 | if (mask & ELF_SPARC_HWCAP_RANDOM) |
015dc7e1 | 16661 | printf ("%srandom", first ? "" : "|"), first = false; |
9e8c70f9 | 16662 | if (mask & ELF_SPARC_HWCAP_TRANS) |
015dc7e1 | 16663 | printf ("%strans", first ? "" : "|"), first = false; |
9e8c70f9 | 16664 | if (mask & ELF_SPARC_HWCAP_FJFMAU) |
015dc7e1 | 16665 | printf ("%sfjfmau", first ? "" : "|"), first = false; |
9e8c70f9 | 16666 | if (mask & ELF_SPARC_HWCAP_IMA) |
015dc7e1 | 16667 | printf ("%sima", first ? "" : "|"), first = false; |
9e8c70f9 | 16668 | if (mask & ELF_SPARC_HWCAP_ASI_CACHE_SPARING) |
015dc7e1 | 16669 | printf ("%scspare", first ? "" : "|"), first = false; |
9e8c70f9 DM |
16670 | } |
16671 | else | |
071436c6 NC |
16672 | fputc ('0', stdout); |
16673 | fputc ('\n', stdout); | |
9e8c70f9 DM |
16674 | } |
16675 | ||
3d68f91c | 16676 | static void |
60abdbed | 16677 | display_sparc_hwcaps2 (unsigned int mask) |
3d68f91c JM |
16678 | { |
16679 | if (mask) | |
16680 | { | |
015dc7e1 | 16681 | bool first = true; |
071436c6 | 16682 | |
3d68f91c | 16683 | if (mask & ELF_SPARC_HWCAP2_FJATHPLUS) |
015dc7e1 | 16684 | fputs ("fjathplus", stdout), first = false; |
3d68f91c | 16685 | if (mask & ELF_SPARC_HWCAP2_VIS3B) |
015dc7e1 | 16686 | printf ("%svis3b", first ? "" : "|"), first = false; |
3d68f91c | 16687 | if (mask & ELF_SPARC_HWCAP2_ADP) |
015dc7e1 | 16688 | printf ("%sadp", first ? "" : "|"), first = false; |
3d68f91c | 16689 | if (mask & ELF_SPARC_HWCAP2_SPARC5) |
015dc7e1 | 16690 | printf ("%ssparc5", first ? "" : "|"), first = false; |
3d68f91c | 16691 | if (mask & ELF_SPARC_HWCAP2_MWAIT) |
015dc7e1 | 16692 | printf ("%smwait", first ? "" : "|"), first = false; |
3d68f91c | 16693 | if (mask & ELF_SPARC_HWCAP2_XMPMUL) |
015dc7e1 | 16694 | printf ("%sxmpmul", first ? "" : "|"), first = false; |
3d68f91c | 16695 | if (mask & ELF_SPARC_HWCAP2_XMONT) |
015dc7e1 | 16696 | printf ("%sxmont2", first ? "" : "|"), first = false; |
3d68f91c | 16697 | if (mask & ELF_SPARC_HWCAP2_NSEC) |
015dc7e1 | 16698 | printf ("%snsec", first ? "" : "|"), first = false; |
3d68f91c | 16699 | if (mask & ELF_SPARC_HWCAP2_FJATHHPC) |
015dc7e1 | 16700 | printf ("%sfjathhpc", first ? "" : "|"), first = false; |
3d68f91c | 16701 | if (mask & ELF_SPARC_HWCAP2_FJDES) |
015dc7e1 | 16702 | printf ("%sfjdes", first ? "" : "|"), first = false; |
3d68f91c | 16703 | if (mask & ELF_SPARC_HWCAP2_FJAES) |
015dc7e1 | 16704 | printf ("%sfjaes", first ? "" : "|"), first = false; |
3d68f91c JM |
16705 | } |
16706 | else | |
071436c6 NC |
16707 | fputc ('0', stdout); |
16708 | fputc ('\n', stdout); | |
3d68f91c JM |
16709 | } |
16710 | ||
9e8c70f9 | 16711 | static unsigned char * |
f6f0e17b | 16712 | display_sparc_gnu_attribute (unsigned char * p, |
60abdbed | 16713 | unsigned int tag, |
f6f0e17b | 16714 | const unsigned char * const end) |
9e8c70f9 | 16715 | { |
cd30bcef | 16716 | unsigned int val; |
3d68f91c | 16717 | |
9e8c70f9 DM |
16718 | if (tag == Tag_GNU_Sparc_HWCAPS) |
16719 | { | |
cd30bcef | 16720 | READ_ULEB (val, p, end); |
9e8c70f9 | 16721 | printf (" Tag_GNU_Sparc_HWCAPS: "); |
9e8c70f9 DM |
16722 | display_sparc_hwcaps (val); |
16723 | return p; | |
3d68f91c JM |
16724 | } |
16725 | if (tag == Tag_GNU_Sparc_HWCAPS2) | |
16726 | { | |
cd30bcef | 16727 | READ_ULEB (val, p, end); |
3d68f91c JM |
16728 | printf (" Tag_GNU_Sparc_HWCAPS2: "); |
16729 | display_sparc_hwcaps2 (val); | |
16730 | return p; | |
16731 | } | |
9e8c70f9 | 16732 | |
f6f0e17b | 16733 | return display_tag_value (tag, p, end); |
9e8c70f9 DM |
16734 | } |
16735 | ||
351cdf24 | 16736 | static void |
32ec8896 | 16737 | print_mips_fp_abi_value (unsigned int val) |
351cdf24 MF |
16738 | { |
16739 | switch (val) | |
16740 | { | |
16741 | case Val_GNU_MIPS_ABI_FP_ANY: | |
16742 | printf (_("Hard or soft float\n")); | |
16743 | break; | |
16744 | case Val_GNU_MIPS_ABI_FP_DOUBLE: | |
16745 | printf (_("Hard float (double precision)\n")); | |
16746 | break; | |
16747 | case Val_GNU_MIPS_ABI_FP_SINGLE: | |
16748 | printf (_("Hard float (single precision)\n")); | |
16749 | break; | |
16750 | case Val_GNU_MIPS_ABI_FP_SOFT: | |
16751 | printf (_("Soft float\n")); | |
16752 | break; | |
16753 | case Val_GNU_MIPS_ABI_FP_OLD_64: | |
16754 | printf (_("Hard float (MIPS32r2 64-bit FPU 12 callee-saved)\n")); | |
16755 | break; | |
16756 | case Val_GNU_MIPS_ABI_FP_XX: | |
16757 | printf (_("Hard float (32-bit CPU, Any FPU)\n")); | |
16758 | break; | |
16759 | case Val_GNU_MIPS_ABI_FP_64: | |
16760 | printf (_("Hard float (32-bit CPU, 64-bit FPU)\n")); | |
16761 | break; | |
16762 | case Val_GNU_MIPS_ABI_FP_64A: | |
16763 | printf (_("Hard float compat (32-bit CPU, 64-bit FPU)\n")); | |
16764 | break; | |
3350cc01 CM |
16765 | case Val_GNU_MIPS_ABI_FP_NAN2008: |
16766 | printf (_("NaN 2008 compatibility\n")); | |
16767 | break; | |
351cdf24 MF |
16768 | default: |
16769 | printf ("??? (%d)\n", val); | |
16770 | break; | |
16771 | } | |
16772 | } | |
16773 | ||
2cf19d5c | 16774 | static unsigned char * |
f6f0e17b | 16775 | display_mips_gnu_attribute (unsigned char * p, |
60abdbed | 16776 | unsigned int tag, |
f6f0e17b | 16777 | const unsigned char * const end) |
2cf19d5c | 16778 | { |
2cf19d5c JM |
16779 | if (tag == Tag_GNU_MIPS_ABI_FP) |
16780 | { | |
32ec8896 | 16781 | unsigned int val; |
f6f0e17b | 16782 | |
2cf19d5c | 16783 | printf (" Tag_GNU_MIPS_ABI_FP: "); |
cd30bcef | 16784 | READ_ULEB (val, p, end); |
351cdf24 | 16785 | print_mips_fp_abi_value (val); |
2cf19d5c JM |
16786 | return p; |
16787 | } | |
16788 | ||
a9f58168 CF |
16789 | if (tag == Tag_GNU_MIPS_ABI_MSA) |
16790 | { | |
32ec8896 | 16791 | unsigned int val; |
a9f58168 | 16792 | |
a9f58168 | 16793 | printf (" Tag_GNU_MIPS_ABI_MSA: "); |
cd30bcef | 16794 | READ_ULEB (val, p, end); |
a9f58168 CF |
16795 | |
16796 | switch (val) | |
16797 | { | |
16798 | case Val_GNU_MIPS_ABI_MSA_ANY: | |
16799 | printf (_("Any MSA or not\n")); | |
16800 | break; | |
16801 | case Val_GNU_MIPS_ABI_MSA_128: | |
16802 | printf (_("128-bit MSA\n")); | |
16803 | break; | |
16804 | default: | |
16805 | printf ("??? (%d)\n", val); | |
16806 | break; | |
16807 | } | |
16808 | return p; | |
16809 | } | |
16810 | ||
f6f0e17b | 16811 | return display_tag_value (tag & 1, p, end); |
2cf19d5c JM |
16812 | } |
16813 | ||
59e6276b | 16814 | static unsigned char * |
f6f0e17b NC |
16815 | display_tic6x_attribute (unsigned char * p, |
16816 | const unsigned char * const end) | |
59e6276b | 16817 | { |
60abdbed | 16818 | unsigned int tag; |
cd30bcef | 16819 | unsigned int val; |
59e6276b | 16820 | |
cd30bcef | 16821 | READ_ULEB (tag, p, end); |
59e6276b JM |
16822 | |
16823 | switch (tag) | |
16824 | { | |
75fa6dc1 | 16825 | case Tag_ISA: |
75fa6dc1 | 16826 | printf (" Tag_ISA: "); |
cd30bcef | 16827 | READ_ULEB (val, p, end); |
59e6276b JM |
16828 | |
16829 | switch (val) | |
16830 | { | |
75fa6dc1 | 16831 | case C6XABI_Tag_ISA_none: |
59e6276b JM |
16832 | printf (_("None\n")); |
16833 | break; | |
75fa6dc1 | 16834 | case C6XABI_Tag_ISA_C62X: |
59e6276b JM |
16835 | printf ("C62x\n"); |
16836 | break; | |
75fa6dc1 | 16837 | case C6XABI_Tag_ISA_C67X: |
59e6276b JM |
16838 | printf ("C67x\n"); |
16839 | break; | |
75fa6dc1 | 16840 | case C6XABI_Tag_ISA_C67XP: |
59e6276b JM |
16841 | printf ("C67x+\n"); |
16842 | break; | |
75fa6dc1 | 16843 | case C6XABI_Tag_ISA_C64X: |
59e6276b JM |
16844 | printf ("C64x\n"); |
16845 | break; | |
75fa6dc1 | 16846 | case C6XABI_Tag_ISA_C64XP: |
59e6276b JM |
16847 | printf ("C64x+\n"); |
16848 | break; | |
75fa6dc1 | 16849 | case C6XABI_Tag_ISA_C674X: |
59e6276b JM |
16850 | printf ("C674x\n"); |
16851 | break; | |
16852 | default: | |
16853 | printf ("??? (%d)\n", val); | |
16854 | break; | |
16855 | } | |
16856 | return p; | |
16857 | ||
87779176 | 16858 | case Tag_ABI_wchar_t: |
87779176 | 16859 | printf (" Tag_ABI_wchar_t: "); |
cd30bcef | 16860 | READ_ULEB (val, p, end); |
87779176 JM |
16861 | switch (val) |
16862 | { | |
16863 | case 0: | |
16864 | printf (_("Not used\n")); | |
16865 | break; | |
16866 | case 1: | |
16867 | printf (_("2 bytes\n")); | |
16868 | break; | |
16869 | case 2: | |
16870 | printf (_("4 bytes\n")); | |
16871 | break; | |
16872 | default: | |
16873 | printf ("??? (%d)\n", val); | |
16874 | break; | |
16875 | } | |
16876 | return p; | |
16877 | ||
16878 | case Tag_ABI_stack_align_needed: | |
87779176 | 16879 | printf (" Tag_ABI_stack_align_needed: "); |
cd30bcef | 16880 | READ_ULEB (val, p, end); |
87779176 JM |
16881 | switch (val) |
16882 | { | |
16883 | case 0: | |
16884 | printf (_("8-byte\n")); | |
16885 | break; | |
16886 | case 1: | |
16887 | printf (_("16-byte\n")); | |
16888 | break; | |
16889 | default: | |
16890 | printf ("??? (%d)\n", val); | |
16891 | break; | |
16892 | } | |
16893 | return p; | |
16894 | ||
16895 | case Tag_ABI_stack_align_preserved: | |
cd30bcef | 16896 | READ_ULEB (val, p, end); |
87779176 JM |
16897 | printf (" Tag_ABI_stack_align_preserved: "); |
16898 | switch (val) | |
16899 | { | |
16900 | case 0: | |
16901 | printf (_("8-byte\n")); | |
16902 | break; | |
16903 | case 1: | |
16904 | printf (_("16-byte\n")); | |
16905 | break; | |
16906 | default: | |
16907 | printf ("??? (%d)\n", val); | |
16908 | break; | |
16909 | } | |
16910 | return p; | |
16911 | ||
b5593623 | 16912 | case Tag_ABI_DSBT: |
cd30bcef | 16913 | READ_ULEB (val, p, end); |
b5593623 JM |
16914 | printf (" Tag_ABI_DSBT: "); |
16915 | switch (val) | |
16916 | { | |
16917 | case 0: | |
16918 | printf (_("DSBT addressing not used\n")); | |
16919 | break; | |
16920 | case 1: | |
16921 | printf (_("DSBT addressing used\n")); | |
16922 | break; | |
16923 | default: | |
16924 | printf ("??? (%d)\n", val); | |
16925 | break; | |
16926 | } | |
16927 | return p; | |
16928 | ||
87779176 | 16929 | case Tag_ABI_PID: |
cd30bcef | 16930 | READ_ULEB (val, p, end); |
87779176 JM |
16931 | printf (" Tag_ABI_PID: "); |
16932 | switch (val) | |
16933 | { | |
16934 | case 0: | |
16935 | printf (_("Data addressing position-dependent\n")); | |
16936 | break; | |
16937 | case 1: | |
16938 | printf (_("Data addressing position-independent, GOT near DP\n")); | |
16939 | break; | |
16940 | case 2: | |
16941 | printf (_("Data addressing position-independent, GOT far from DP\n")); | |
16942 | break; | |
16943 | default: | |
16944 | printf ("??? (%d)\n", val); | |
16945 | break; | |
16946 | } | |
16947 | return p; | |
16948 | ||
16949 | case Tag_ABI_PIC: | |
cd30bcef | 16950 | READ_ULEB (val, p, end); |
87779176 JM |
16951 | printf (" Tag_ABI_PIC: "); |
16952 | switch (val) | |
16953 | { | |
16954 | case 0: | |
16955 | printf (_("Code addressing position-dependent\n")); | |
16956 | break; | |
16957 | case 1: | |
16958 | printf (_("Code addressing position-independent\n")); | |
16959 | break; | |
16960 | default: | |
16961 | printf ("??? (%d)\n", val); | |
16962 | break; | |
16963 | } | |
16964 | return p; | |
16965 | ||
16966 | case Tag_ABI_array_object_alignment: | |
cd30bcef | 16967 | READ_ULEB (val, p, end); |
87779176 JM |
16968 | printf (" Tag_ABI_array_object_alignment: "); |
16969 | switch (val) | |
16970 | { | |
16971 | case 0: | |
16972 | printf (_("8-byte\n")); | |
16973 | break; | |
16974 | case 1: | |
16975 | printf (_("4-byte\n")); | |
16976 | break; | |
16977 | case 2: | |
16978 | printf (_("16-byte\n")); | |
16979 | break; | |
16980 | default: | |
16981 | printf ("??? (%d)\n", val); | |
16982 | break; | |
16983 | } | |
16984 | return p; | |
16985 | ||
16986 | case Tag_ABI_array_object_align_expected: | |
cd30bcef | 16987 | READ_ULEB (val, p, end); |
87779176 JM |
16988 | printf (" Tag_ABI_array_object_align_expected: "); |
16989 | switch (val) | |
16990 | { | |
16991 | case 0: | |
16992 | printf (_("8-byte\n")); | |
16993 | break; | |
16994 | case 1: | |
16995 | printf (_("4-byte\n")); | |
16996 | break; | |
16997 | case 2: | |
16998 | printf (_("16-byte\n")); | |
16999 | break; | |
17000 | default: | |
17001 | printf ("??? (%d)\n", val); | |
17002 | break; | |
17003 | } | |
17004 | return p; | |
17005 | ||
3cbd1c06 | 17006 | case Tag_ABI_compatibility: |
071436c6 | 17007 | { |
cd30bcef | 17008 | READ_ULEB (val, p, end); |
071436c6 | 17009 | printf (" Tag_ABI_compatibility: "); |
071436c6 | 17010 | printf (_("flag = %d, vendor = "), val); |
4082ef84 NC |
17011 | if (p < end - 1) |
17012 | { | |
17013 | size_t maxlen = (end - p) - 1; | |
17014 | ||
17015 | print_symbol ((int) maxlen, (const char *) p); | |
17016 | p += strnlen ((char *) p, maxlen) + 1; | |
17017 | } | |
17018 | else | |
17019 | { | |
17020 | printf (_("<corrupt>")); | |
17021 | p = (unsigned char *) end; | |
17022 | } | |
071436c6 | 17023 | putchar ('\n'); |
071436c6 NC |
17024 | return p; |
17025 | } | |
87779176 JM |
17026 | |
17027 | case Tag_ABI_conformance: | |
071436c6 | 17028 | { |
4082ef84 NC |
17029 | printf (" Tag_ABI_conformance: \""); |
17030 | if (p < end - 1) | |
17031 | { | |
17032 | size_t maxlen = (end - p) - 1; | |
071436c6 | 17033 | |
4082ef84 NC |
17034 | print_symbol ((int) maxlen, (const char *) p); |
17035 | p += strnlen ((char *) p, maxlen) + 1; | |
17036 | } | |
17037 | else | |
17038 | { | |
17039 | printf (_("<corrupt>")); | |
17040 | p = (unsigned char *) end; | |
17041 | } | |
071436c6 | 17042 | printf ("\"\n"); |
071436c6 NC |
17043 | return p; |
17044 | } | |
59e6276b JM |
17045 | } |
17046 | ||
f6f0e17b NC |
17047 | return display_tag_value (tag, p, end); |
17048 | } | |
59e6276b | 17049 | |
f6f0e17b | 17050 | static void |
60abdbed | 17051 | display_raw_attribute (unsigned char * p, unsigned char const * const end) |
f6f0e17b NC |
17052 | { |
17053 | unsigned long addr = 0; | |
17054 | size_t bytes = end - p; | |
17055 | ||
feceaa59 | 17056 | assert (end >= p); |
f6f0e17b | 17057 | while (bytes) |
87779176 | 17058 | { |
f6f0e17b NC |
17059 | int j; |
17060 | int k; | |
17061 | int lbytes = (bytes > 16 ? 16 : bytes); | |
17062 | ||
17063 | printf (" 0x%8.8lx ", addr); | |
17064 | ||
17065 | for (j = 0; j < 16; j++) | |
17066 | { | |
17067 | if (j < lbytes) | |
17068 | printf ("%2.2x", p[j]); | |
17069 | else | |
17070 | printf (" "); | |
17071 | ||
17072 | if ((j & 3) == 3) | |
17073 | printf (" "); | |
17074 | } | |
17075 | ||
17076 | for (j = 0; j < lbytes; j++) | |
17077 | { | |
17078 | k = p[j]; | |
17079 | if (k >= ' ' && k < 0x7f) | |
17080 | printf ("%c", k); | |
17081 | else | |
17082 | printf ("."); | |
17083 | } | |
17084 | ||
17085 | putchar ('\n'); | |
17086 | ||
17087 | p += lbytes; | |
17088 | bytes -= lbytes; | |
17089 | addr += lbytes; | |
87779176 | 17090 | } |
59e6276b | 17091 | |
f6f0e17b | 17092 | putchar ('\n'); |
59e6276b JM |
17093 | } |
17094 | ||
13761a11 | 17095 | static unsigned char * |
b0191216 | 17096 | display_msp430_attribute (unsigned char * p, |
13761a11 NC |
17097 | const unsigned char * const end) |
17098 | { | |
60abdbed NC |
17099 | unsigned int val; |
17100 | unsigned int tag; | |
13761a11 | 17101 | |
cd30bcef | 17102 | READ_ULEB (tag, p, end); |
0b4362b0 | 17103 | |
13761a11 NC |
17104 | switch (tag) |
17105 | { | |
17106 | case OFBA_MSPABI_Tag_ISA: | |
13761a11 | 17107 | printf (" Tag_ISA: "); |
cd30bcef | 17108 | READ_ULEB (val, p, end); |
13761a11 NC |
17109 | switch (val) |
17110 | { | |
17111 | case 0: printf (_("None\n")); break; | |
17112 | case 1: printf (_("MSP430\n")); break; | |
17113 | case 2: printf (_("MSP430X\n")); break; | |
17114 | default: printf ("??? (%d)\n", val); break; | |
17115 | } | |
17116 | break; | |
17117 | ||
17118 | case OFBA_MSPABI_Tag_Code_Model: | |
13761a11 | 17119 | printf (" Tag_Code_Model: "); |
cd30bcef | 17120 | READ_ULEB (val, p, end); |
13761a11 NC |
17121 | switch (val) |
17122 | { | |
17123 | case 0: printf (_("None\n")); break; | |
17124 | case 1: printf (_("Small\n")); break; | |
17125 | case 2: printf (_("Large\n")); break; | |
17126 | default: printf ("??? (%d)\n", val); break; | |
17127 | } | |
17128 | break; | |
17129 | ||
17130 | case OFBA_MSPABI_Tag_Data_Model: | |
13761a11 | 17131 | printf (" Tag_Data_Model: "); |
cd30bcef | 17132 | READ_ULEB (val, p, end); |
13761a11 NC |
17133 | switch (val) |
17134 | { | |
17135 | case 0: printf (_("None\n")); break; | |
17136 | case 1: printf (_("Small\n")); break; | |
17137 | case 2: printf (_("Large\n")); break; | |
17138 | case 3: printf (_("Restricted Large\n")); break; | |
17139 | default: printf ("??? (%d)\n", val); break; | |
17140 | } | |
17141 | break; | |
17142 | ||
17143 | default: | |
17144 | printf (_(" <unknown tag %d>: "), tag); | |
17145 | ||
17146 | if (tag & 1) | |
17147 | { | |
071436c6 | 17148 | putchar ('"'); |
4082ef84 NC |
17149 | if (p < end - 1) |
17150 | { | |
17151 | size_t maxlen = (end - p) - 1; | |
17152 | ||
17153 | print_symbol ((int) maxlen, (const char *) p); | |
17154 | p += strnlen ((char *) p, maxlen) + 1; | |
17155 | } | |
17156 | else | |
17157 | { | |
17158 | printf (_("<corrupt>")); | |
17159 | p = (unsigned char *) end; | |
17160 | } | |
071436c6 | 17161 | printf ("\"\n"); |
13761a11 NC |
17162 | } |
17163 | else | |
17164 | { | |
cd30bcef | 17165 | READ_ULEB (val, p, end); |
13761a11 NC |
17166 | printf ("%d (0x%x)\n", val, val); |
17167 | } | |
17168 | break; | |
17169 | } | |
17170 | ||
4082ef84 | 17171 | assert (p <= end); |
13761a11 NC |
17172 | return p; |
17173 | } | |
17174 | ||
c0ea7c52 JL |
17175 | static unsigned char * |
17176 | display_msp430_gnu_attribute (unsigned char * p, | |
17177 | unsigned int tag, | |
17178 | const unsigned char * const end) | |
17179 | { | |
17180 | if (tag == Tag_GNU_MSP430_Data_Region) | |
17181 | { | |
cd30bcef | 17182 | unsigned int val; |
c0ea7c52 | 17183 | |
c0ea7c52 | 17184 | printf (" Tag_GNU_MSP430_Data_Region: "); |
cd30bcef | 17185 | READ_ULEB (val, p, end); |
c0ea7c52 JL |
17186 | |
17187 | switch (val) | |
17188 | { | |
17189 | case Val_GNU_MSP430_Data_Region_Any: | |
17190 | printf (_("Any Region\n")); | |
17191 | break; | |
17192 | case Val_GNU_MSP430_Data_Region_Lower: | |
17193 | printf (_("Lower Region Only\n")); | |
17194 | break; | |
17195 | default: | |
cd30bcef | 17196 | printf ("??? (%u)\n", val); |
c0ea7c52 JL |
17197 | } |
17198 | return p; | |
17199 | } | |
17200 | return display_tag_value (tag & 1, p, end); | |
17201 | } | |
17202 | ||
2dc8dd17 JW |
17203 | struct riscv_attr_tag_t { |
17204 | const char *name; | |
cd30bcef | 17205 | unsigned int tag; |
2dc8dd17 JW |
17206 | }; |
17207 | ||
17208 | static struct riscv_attr_tag_t riscv_attr_tag[] = | |
17209 | { | |
17210 | #define T(tag) {"Tag_RISCV_" #tag, Tag_RISCV_##tag} | |
17211 | T(arch), | |
17212 | T(priv_spec), | |
17213 | T(priv_spec_minor), | |
17214 | T(priv_spec_revision), | |
17215 | T(unaligned_access), | |
17216 | T(stack_align), | |
17217 | #undef T | |
17218 | }; | |
17219 | ||
17220 | static unsigned char * | |
17221 | display_riscv_attribute (unsigned char *p, | |
17222 | const unsigned char * const end) | |
17223 | { | |
cd30bcef AM |
17224 | unsigned int val; |
17225 | unsigned int tag; | |
2dc8dd17 JW |
17226 | struct riscv_attr_tag_t *attr = NULL; |
17227 | unsigned i; | |
17228 | ||
cd30bcef | 17229 | READ_ULEB (tag, p, end); |
2dc8dd17 JW |
17230 | |
17231 | /* Find the name of attribute. */ | |
17232 | for (i = 0; i < ARRAY_SIZE (riscv_attr_tag); i++) | |
17233 | { | |
17234 | if (riscv_attr_tag[i].tag == tag) | |
17235 | { | |
17236 | attr = &riscv_attr_tag[i]; | |
17237 | break; | |
17238 | } | |
17239 | } | |
17240 | ||
17241 | if (attr) | |
17242 | printf (" %s: ", attr->name); | |
17243 | else | |
17244 | return display_tag_value (tag, p, end); | |
17245 | ||
17246 | switch (tag) | |
17247 | { | |
17248 | case Tag_RISCV_priv_spec: | |
17249 | case Tag_RISCV_priv_spec_minor: | |
17250 | case Tag_RISCV_priv_spec_revision: | |
cd30bcef AM |
17251 | READ_ULEB (val, p, end); |
17252 | printf (_("%u\n"), val); | |
2dc8dd17 JW |
17253 | break; |
17254 | case Tag_RISCV_unaligned_access: | |
cd30bcef | 17255 | READ_ULEB (val, p, end); |
2dc8dd17 JW |
17256 | switch (val) |
17257 | { | |
17258 | case 0: | |
17259 | printf (_("No unaligned access\n")); | |
17260 | break; | |
17261 | case 1: | |
17262 | printf (_("Unaligned access\n")); | |
17263 | break; | |
17264 | } | |
17265 | break; | |
17266 | case Tag_RISCV_stack_align: | |
cd30bcef AM |
17267 | READ_ULEB (val, p, end); |
17268 | printf (_("%u-bytes\n"), val); | |
2dc8dd17 JW |
17269 | break; |
17270 | case Tag_RISCV_arch: | |
17271 | p = display_tag_value (-1, p, end); | |
17272 | break; | |
17273 | default: | |
17274 | return display_tag_value (tag, p, end); | |
17275 | } | |
17276 | ||
17277 | return p; | |
17278 | } | |
17279 | ||
0861f561 CQ |
17280 | static unsigned char * |
17281 | display_csky_attribute (unsigned char * p, | |
17282 | const unsigned char * const end) | |
17283 | { | |
17284 | unsigned int tag; | |
17285 | unsigned int val; | |
17286 | READ_ULEB (tag, p, end); | |
17287 | ||
17288 | if (tag >= Tag_CSKY_MAX) | |
17289 | { | |
17290 | return display_tag_value (-1, p, end); | |
17291 | } | |
17292 | ||
17293 | switch (tag) | |
17294 | { | |
17295 | case Tag_CSKY_ARCH_NAME: | |
17296 | printf (" Tag_CSKY_ARCH_NAME:\t\t"); | |
17297 | return display_tag_value (-1, p, end); | |
17298 | case Tag_CSKY_CPU_NAME: | |
17299 | printf (" Tag_CSKY_CPU_NAME:\t\t"); | |
17300 | return display_tag_value (-1, p, end); | |
17301 | ||
17302 | case Tag_CSKY_ISA_FLAGS: | |
17303 | printf (" Tag_CSKY_ISA_FLAGS:\t\t"); | |
17304 | return display_tag_value (0, p, end); | |
17305 | case Tag_CSKY_ISA_EXT_FLAGS: | |
17306 | printf (" Tag_CSKY_ISA_EXT_FLAGS:\t"); | |
17307 | return display_tag_value (0, p, end); | |
17308 | ||
17309 | case Tag_CSKY_DSP_VERSION: | |
17310 | printf (" Tag_CSKY_DSP_VERSION:\t\t"); | |
17311 | READ_ULEB (val, p, end); | |
17312 | if (val == VAL_CSKY_DSP_VERSION_EXTENSION) | |
17313 | printf ("DSP Extension\n"); | |
17314 | else if (val == VAL_CSKY_DSP_VERSION_2) | |
17315 | printf ("DSP 2.0\n"); | |
17316 | break; | |
17317 | ||
17318 | case Tag_CSKY_VDSP_VERSION: | |
17319 | printf (" Tag_CSKY_VDSP_VERSION:\t"); | |
17320 | READ_ULEB (val, p, end); | |
17321 | printf ("VDSP Version %d\n", val); | |
17322 | break; | |
17323 | ||
17324 | case Tag_CSKY_FPU_VERSION: | |
17325 | printf (" Tag_CSKY_FPU_VERSION:\t\t"); | |
17326 | READ_ULEB (val, p, end); | |
17327 | if (val == VAL_CSKY_FPU_VERSION_1) | |
17328 | printf ("ABIV1 FPU Version 1\n"); | |
17329 | else if (val == VAL_CSKY_FPU_VERSION_2) | |
17330 | printf ("FPU Version 2\n"); | |
17331 | break; | |
17332 | ||
17333 | case Tag_CSKY_FPU_ABI: | |
17334 | printf (" Tag_CSKY_FPU_ABI:\t\t"); | |
17335 | READ_ULEB (val, p, end); | |
17336 | if (val == VAL_CSKY_FPU_ABI_HARD) | |
17337 | printf ("Hard\n"); | |
17338 | else if (val == VAL_CSKY_FPU_ABI_SOFTFP) | |
17339 | printf ("SoftFP\n"); | |
17340 | else if (val == VAL_CSKY_FPU_ABI_SOFT) | |
17341 | printf ("Soft\n"); | |
17342 | break; | |
17343 | case Tag_CSKY_FPU_ROUNDING: | |
17344 | READ_ULEB (val, p, end); | |
f253158f NC |
17345 | if (val == 1) |
17346 | { | |
17347 | printf (" Tag_CSKY_FPU_ROUNDING:\t"); | |
17348 | printf ("Needed\n"); | |
17349 | } | |
0861f561 CQ |
17350 | break; |
17351 | case Tag_CSKY_FPU_DENORMAL: | |
17352 | READ_ULEB (val, p, end); | |
f253158f NC |
17353 | if (val == 1) |
17354 | { | |
17355 | printf (" Tag_CSKY_FPU_DENORMAL:\t"); | |
17356 | printf ("Needed\n"); | |
17357 | } | |
0861f561 CQ |
17358 | break; |
17359 | case Tag_CSKY_FPU_Exception: | |
17360 | READ_ULEB (val, p, end); | |
f253158f NC |
17361 | if (val == 1) |
17362 | { | |
17363 | printf (" Tag_CSKY_FPU_Exception:\t"); | |
17364 | printf ("Needed\n"); | |
17365 | } | |
0861f561 CQ |
17366 | break; |
17367 | case Tag_CSKY_FPU_NUMBER_MODULE: | |
17368 | printf (" Tag_CSKY_FPU_NUMBER_MODULE:\t"); | |
17369 | return display_tag_value (-1, p, end); | |
17370 | case Tag_CSKY_FPU_HARDFP: | |
17371 | printf (" Tag_CSKY_FPU_HARDFP:\t\t"); | |
17372 | READ_ULEB (val, p, end); | |
17373 | if (val & VAL_CSKY_FPU_HARDFP_HALF) | |
17374 | printf (" Half"); | |
17375 | if (val & VAL_CSKY_FPU_HARDFP_SINGLE) | |
17376 | printf (" Single"); | |
17377 | if (val & VAL_CSKY_FPU_HARDFP_DOUBLE) | |
17378 | printf (" Double"); | |
17379 | printf ("\n"); | |
17380 | break; | |
17381 | default: | |
17382 | return display_tag_value (tag, p, end); | |
17383 | } | |
17384 | return p; | |
17385 | } | |
17386 | ||
015dc7e1 | 17387 | static bool |
dda8d76d | 17388 | process_attributes (Filedata * filedata, |
60bca95a | 17389 | const char * public_name, |
104d59d1 | 17390 | unsigned int proc_type, |
f6f0e17b | 17391 | unsigned char * (* display_pub_attribute) (unsigned char *, const unsigned char * const), |
60abdbed | 17392 | unsigned char * (* display_proc_gnu_attribute) (unsigned char *, unsigned int, const unsigned char * const)) |
11c1ff18 | 17393 | { |
2cf0635d | 17394 | Elf_Internal_Shdr * sect; |
11c1ff18 | 17395 | unsigned i; |
015dc7e1 | 17396 | bool res = true; |
11c1ff18 PB |
17397 | |
17398 | /* Find the section header so that we get the size. */ | |
dda8d76d NC |
17399 | for (i = 0, sect = filedata->section_headers; |
17400 | i < filedata->file_header.e_shnum; | |
11c1ff18 PB |
17401 | i++, sect++) |
17402 | { | |
071436c6 NC |
17403 | unsigned char * contents; |
17404 | unsigned char * p; | |
17405 | ||
104d59d1 | 17406 | if (sect->sh_type != proc_type && sect->sh_type != SHT_GNU_ATTRIBUTES) |
11c1ff18 PB |
17407 | continue; |
17408 | ||
dda8d76d | 17409 | contents = (unsigned char *) get_data (NULL, filedata, sect->sh_offset, 1, |
3f5e193b | 17410 | sect->sh_size, _("attributes")); |
60bca95a | 17411 | if (contents == NULL) |
32ec8896 | 17412 | { |
015dc7e1 | 17413 | res = false; |
32ec8896 NC |
17414 | continue; |
17415 | } | |
60bca95a | 17416 | |
11c1ff18 | 17417 | p = contents; |
60abdbed NC |
17418 | /* The first character is the version of the attributes. |
17419 | Currently only version 1, (aka 'A') is recognised here. */ | |
17420 | if (*p != 'A') | |
32ec8896 NC |
17421 | { |
17422 | printf (_("Unknown attributes version '%c'(%d) - expecting 'A'\n"), *p, *p); | |
015dc7e1 | 17423 | res = false; |
32ec8896 | 17424 | } |
60abdbed | 17425 | else |
11c1ff18 | 17426 | { |
071436c6 NC |
17427 | bfd_vma section_len; |
17428 | ||
17429 | section_len = sect->sh_size - 1; | |
11c1ff18 | 17430 | p++; |
60bca95a | 17431 | |
071436c6 | 17432 | while (section_len > 0) |
11c1ff18 | 17433 | { |
071436c6 | 17434 | bfd_vma attr_len; |
e9847026 | 17435 | unsigned int namelen; |
015dc7e1 AM |
17436 | bool public_section; |
17437 | bool gnu_section; | |
11c1ff18 | 17438 | |
071436c6 | 17439 | if (section_len <= 4) |
e0a31db1 NC |
17440 | { |
17441 | error (_("Tag section ends prematurely\n")); | |
015dc7e1 | 17442 | res = false; |
e0a31db1 NC |
17443 | break; |
17444 | } | |
071436c6 | 17445 | attr_len = byte_get (p, 4); |
11c1ff18 | 17446 | p += 4; |
60bca95a | 17447 | |
071436c6 | 17448 | if (attr_len > section_len) |
11c1ff18 | 17449 | { |
071436c6 NC |
17450 | error (_("Bad attribute length (%u > %u)\n"), |
17451 | (unsigned) attr_len, (unsigned) section_len); | |
17452 | attr_len = section_len; | |
015dc7e1 | 17453 | res = false; |
11c1ff18 | 17454 | } |
74e1a04b | 17455 | /* PR 17531: file: 001-101425-0.004 */ |
071436c6 | 17456 | else if (attr_len < 5) |
74e1a04b | 17457 | { |
071436c6 | 17458 | error (_("Attribute length of %u is too small\n"), (unsigned) attr_len); |
015dc7e1 | 17459 | res = false; |
74e1a04b NC |
17460 | break; |
17461 | } | |
e9847026 | 17462 | |
071436c6 NC |
17463 | section_len -= attr_len; |
17464 | attr_len -= 4; | |
17465 | ||
17466 | namelen = strnlen ((char *) p, attr_len) + 1; | |
17467 | if (namelen == 0 || namelen >= attr_len) | |
e9847026 NC |
17468 | { |
17469 | error (_("Corrupt attribute section name\n")); | |
015dc7e1 | 17470 | res = false; |
e9847026 NC |
17471 | break; |
17472 | } | |
17473 | ||
071436c6 NC |
17474 | printf (_("Attribute Section: ")); |
17475 | print_symbol (INT_MAX, (const char *) p); | |
17476 | putchar ('\n'); | |
60bca95a NC |
17477 | |
17478 | if (public_name && streq ((char *) p, public_name)) | |
015dc7e1 | 17479 | public_section = true; |
11c1ff18 | 17480 | else |
015dc7e1 | 17481 | public_section = false; |
60bca95a NC |
17482 | |
17483 | if (streq ((char *) p, "gnu")) | |
015dc7e1 | 17484 | gnu_section = true; |
104d59d1 | 17485 | else |
015dc7e1 | 17486 | gnu_section = false; |
60bca95a | 17487 | |
11c1ff18 | 17488 | p += namelen; |
071436c6 | 17489 | attr_len -= namelen; |
e0a31db1 | 17490 | |
071436c6 | 17491 | while (attr_len > 0 && p < contents + sect->sh_size) |
11c1ff18 | 17492 | { |
e0a31db1 | 17493 | int tag; |
cd30bcef | 17494 | unsigned int val; |
11c1ff18 | 17495 | bfd_vma size; |
071436c6 | 17496 | unsigned char * end; |
60bca95a | 17497 | |
e0a31db1 | 17498 | /* PR binutils/17531: Safe handling of corrupt files. */ |
071436c6 | 17499 | if (attr_len < 6) |
e0a31db1 NC |
17500 | { |
17501 | error (_("Unused bytes at end of section\n")); | |
015dc7e1 | 17502 | res = false; |
e0a31db1 NC |
17503 | section_len = 0; |
17504 | break; | |
17505 | } | |
17506 | ||
17507 | tag = *(p++); | |
11c1ff18 | 17508 | size = byte_get (p, 4); |
071436c6 | 17509 | if (size > attr_len) |
11c1ff18 | 17510 | { |
e9847026 | 17511 | error (_("Bad subsection length (%u > %u)\n"), |
071436c6 | 17512 | (unsigned) size, (unsigned) attr_len); |
015dc7e1 | 17513 | res = false; |
071436c6 | 17514 | size = attr_len; |
11c1ff18 | 17515 | } |
e0a31db1 NC |
17516 | /* PR binutils/17531: Safe handling of corrupt files. */ |
17517 | if (size < 6) | |
17518 | { | |
17519 | error (_("Bad subsection length (%u < 6)\n"), | |
17520 | (unsigned) size); | |
015dc7e1 | 17521 | res = false; |
e0a31db1 NC |
17522 | section_len = 0; |
17523 | break; | |
17524 | } | |
60bca95a | 17525 | |
071436c6 | 17526 | attr_len -= size; |
11c1ff18 | 17527 | end = p + size - 1; |
071436c6 | 17528 | assert (end <= contents + sect->sh_size); |
11c1ff18 | 17529 | p += 4; |
60bca95a | 17530 | |
11c1ff18 PB |
17531 | switch (tag) |
17532 | { | |
17533 | case 1: | |
2b692964 | 17534 | printf (_("File Attributes\n")); |
11c1ff18 PB |
17535 | break; |
17536 | case 2: | |
2b692964 | 17537 | printf (_("Section Attributes:")); |
11c1ff18 PB |
17538 | goto do_numlist; |
17539 | case 3: | |
2b692964 | 17540 | printf (_("Symbol Attributes:")); |
1a0670f3 | 17541 | /* Fall through. */ |
11c1ff18 PB |
17542 | do_numlist: |
17543 | for (;;) | |
17544 | { | |
cd30bcef | 17545 | READ_ULEB (val, p, end); |
11c1ff18 PB |
17546 | if (val == 0) |
17547 | break; | |
17548 | printf (" %d", val); | |
17549 | } | |
17550 | printf ("\n"); | |
17551 | break; | |
17552 | default: | |
2b692964 | 17553 | printf (_("Unknown tag: %d\n"), tag); |
015dc7e1 | 17554 | public_section = false; |
11c1ff18 PB |
17555 | break; |
17556 | } | |
60bca95a | 17557 | |
071436c6 | 17558 | if (public_section && display_pub_attribute != NULL) |
11c1ff18 PB |
17559 | { |
17560 | while (p < end) | |
f6f0e17b | 17561 | p = display_pub_attribute (p, end); |
60abdbed | 17562 | assert (p == end); |
104d59d1 | 17563 | } |
071436c6 | 17564 | else if (gnu_section && display_proc_gnu_attribute != NULL) |
104d59d1 JM |
17565 | { |
17566 | while (p < end) | |
17567 | p = display_gnu_attribute (p, | |
f6f0e17b NC |
17568 | display_proc_gnu_attribute, |
17569 | end); | |
60abdbed | 17570 | assert (p == end); |
11c1ff18 | 17571 | } |
071436c6 | 17572 | else if (p < end) |
11c1ff18 | 17573 | { |
071436c6 | 17574 | printf (_(" Unknown attribute:\n")); |
f6f0e17b | 17575 | display_raw_attribute (p, end); |
11c1ff18 PB |
17576 | p = end; |
17577 | } | |
071436c6 NC |
17578 | else |
17579 | attr_len = 0; | |
11c1ff18 PB |
17580 | } |
17581 | } | |
17582 | } | |
d70c5fc7 | 17583 | |
60bca95a | 17584 | free (contents); |
11c1ff18 | 17585 | } |
32ec8896 NC |
17586 | |
17587 | return res; | |
11c1ff18 PB |
17588 | } |
17589 | ||
ccb4c951 RS |
17590 | /* DATA points to the contents of a MIPS GOT that starts at VMA PLTGOT. |
17591 | Print the Address, Access and Initial fields of an entry at VMA ADDR | |
82b1b41b NC |
17592 | and return the VMA of the next entry, or -1 if there was a problem. |
17593 | Does not read from DATA_END or beyond. */ | |
ccb4c951 RS |
17594 | |
17595 | static bfd_vma | |
82b1b41b NC |
17596 | print_mips_got_entry (unsigned char * data, bfd_vma pltgot, bfd_vma addr, |
17597 | unsigned char * data_end) | |
ccb4c951 RS |
17598 | { |
17599 | printf (" "); | |
17600 | print_vma (addr, LONG_HEX); | |
17601 | printf (" "); | |
17602 | if (addr < pltgot + 0xfff0) | |
17603 | printf ("%6d(gp)", (int) (addr - pltgot - 0x7ff0)); | |
17604 | else | |
17605 | printf ("%10s", ""); | |
17606 | printf (" "); | |
17607 | if (data == NULL) | |
2b692964 | 17608 | printf ("%*s", is_32bit_elf ? 8 : 16, _("<unknown>")); |
ccb4c951 RS |
17609 | else |
17610 | { | |
17611 | bfd_vma entry; | |
82b1b41b | 17612 | unsigned char * from = data + addr - pltgot; |
ccb4c951 | 17613 | |
82b1b41b NC |
17614 | if (from + (is_32bit_elf ? 4 : 8) > data_end) |
17615 | { | |
17616 | warn (_("MIPS GOT entry extends beyond the end of available data\n")); | |
17617 | printf ("%*s", is_32bit_elf ? 8 : 16, _("<corrupt>")); | |
17618 | return (bfd_vma) -1; | |
17619 | } | |
17620 | else | |
17621 | { | |
17622 | entry = byte_get (data + addr - pltgot, is_32bit_elf ? 4 : 8); | |
17623 | print_vma (entry, LONG_HEX); | |
17624 | } | |
ccb4c951 RS |
17625 | } |
17626 | return addr + (is_32bit_elf ? 4 : 8); | |
17627 | } | |
17628 | ||
861fb55a DJ |
17629 | /* DATA points to the contents of a MIPS PLT GOT that starts at VMA |
17630 | PLTGOT. Print the Address and Initial fields of an entry at VMA | |
17631 | ADDR and return the VMA of the next entry. */ | |
17632 | ||
17633 | static bfd_vma | |
2cf0635d | 17634 | print_mips_pltgot_entry (unsigned char * data, bfd_vma pltgot, bfd_vma addr) |
861fb55a DJ |
17635 | { |
17636 | printf (" "); | |
17637 | print_vma (addr, LONG_HEX); | |
17638 | printf (" "); | |
17639 | if (data == NULL) | |
2b692964 | 17640 | printf ("%*s", is_32bit_elf ? 8 : 16, _("<unknown>")); |
861fb55a DJ |
17641 | else |
17642 | { | |
17643 | bfd_vma entry; | |
17644 | ||
17645 | entry = byte_get (data + addr - pltgot, is_32bit_elf ? 4 : 8); | |
17646 | print_vma (entry, LONG_HEX); | |
17647 | } | |
17648 | return addr + (is_32bit_elf ? 4 : 8); | |
17649 | } | |
17650 | ||
351cdf24 MF |
17651 | static void |
17652 | print_mips_ases (unsigned int mask) | |
17653 | { | |
17654 | if (mask & AFL_ASE_DSP) | |
17655 | fputs ("\n\tDSP ASE", stdout); | |
17656 | if (mask & AFL_ASE_DSPR2) | |
17657 | fputs ("\n\tDSP R2 ASE", stdout); | |
8f4f9071 MF |
17658 | if (mask & AFL_ASE_DSPR3) |
17659 | fputs ("\n\tDSP R3 ASE", stdout); | |
351cdf24 MF |
17660 | if (mask & AFL_ASE_EVA) |
17661 | fputs ("\n\tEnhanced VA Scheme", stdout); | |
17662 | if (mask & AFL_ASE_MCU) | |
17663 | fputs ("\n\tMCU (MicroController) ASE", stdout); | |
17664 | if (mask & AFL_ASE_MDMX) | |
17665 | fputs ("\n\tMDMX ASE", stdout); | |
17666 | if (mask & AFL_ASE_MIPS3D) | |
17667 | fputs ("\n\tMIPS-3D ASE", stdout); | |
17668 | if (mask & AFL_ASE_MT) | |
17669 | fputs ("\n\tMT ASE", stdout); | |
17670 | if (mask & AFL_ASE_SMARTMIPS) | |
17671 | fputs ("\n\tSmartMIPS ASE", stdout); | |
17672 | if (mask & AFL_ASE_VIRT) | |
17673 | fputs ("\n\tVZ ASE", stdout); | |
17674 | if (mask & AFL_ASE_MSA) | |
17675 | fputs ("\n\tMSA ASE", stdout); | |
17676 | if (mask & AFL_ASE_MIPS16) | |
17677 | fputs ("\n\tMIPS16 ASE", stdout); | |
17678 | if (mask & AFL_ASE_MICROMIPS) | |
17679 | fputs ("\n\tMICROMIPS ASE", stdout); | |
17680 | if (mask & AFL_ASE_XPA) | |
17681 | fputs ("\n\tXPA ASE", stdout); | |
25499ac7 MR |
17682 | if (mask & AFL_ASE_MIPS16E2) |
17683 | fputs ("\n\tMIPS16e2 ASE", stdout); | |
730c3174 SE |
17684 | if (mask & AFL_ASE_CRC) |
17685 | fputs ("\n\tCRC ASE", stdout); | |
6f20c942 FS |
17686 | if (mask & AFL_ASE_GINV) |
17687 | fputs ("\n\tGINV ASE", stdout); | |
8095d2f7 CX |
17688 | if (mask & AFL_ASE_LOONGSON_MMI) |
17689 | fputs ("\n\tLoongson MMI ASE", stdout); | |
716c08de CX |
17690 | if (mask & AFL_ASE_LOONGSON_CAM) |
17691 | fputs ("\n\tLoongson CAM ASE", stdout); | |
bdc6c06e CX |
17692 | if (mask & AFL_ASE_LOONGSON_EXT) |
17693 | fputs ("\n\tLoongson EXT ASE", stdout); | |
a693765e CX |
17694 | if (mask & AFL_ASE_LOONGSON_EXT2) |
17695 | fputs ("\n\tLoongson EXT2 ASE", stdout); | |
351cdf24 MF |
17696 | if (mask == 0) |
17697 | fprintf (stdout, "\n\t%s", _("None")); | |
00ac7aa0 MF |
17698 | else if ((mask & ~AFL_ASE_MASK) != 0) |
17699 | fprintf (stdout, "\n\t%s (%x)", _("Unknown"), mask & ~AFL_ASE_MASK); | |
351cdf24 MF |
17700 | } |
17701 | ||
17702 | static void | |
17703 | print_mips_isa_ext (unsigned int isa_ext) | |
17704 | { | |
17705 | switch (isa_ext) | |
17706 | { | |
17707 | case 0: | |
17708 | fputs (_("None"), stdout); | |
17709 | break; | |
17710 | case AFL_EXT_XLR: | |
17711 | fputs ("RMI XLR", stdout); | |
17712 | break; | |
2c629856 N |
17713 | case AFL_EXT_OCTEON3: |
17714 | fputs ("Cavium Networks Octeon3", stdout); | |
17715 | break; | |
351cdf24 MF |
17716 | case AFL_EXT_OCTEON2: |
17717 | fputs ("Cavium Networks Octeon2", stdout); | |
17718 | break; | |
17719 | case AFL_EXT_OCTEONP: | |
17720 | fputs ("Cavium Networks OcteonP", stdout); | |
17721 | break; | |
351cdf24 MF |
17722 | case AFL_EXT_OCTEON: |
17723 | fputs ("Cavium Networks Octeon", stdout); | |
17724 | break; | |
17725 | case AFL_EXT_5900: | |
17726 | fputs ("Toshiba R5900", stdout); | |
17727 | break; | |
17728 | case AFL_EXT_4650: | |
17729 | fputs ("MIPS R4650", stdout); | |
17730 | break; | |
17731 | case AFL_EXT_4010: | |
17732 | fputs ("LSI R4010", stdout); | |
17733 | break; | |
17734 | case AFL_EXT_4100: | |
17735 | fputs ("NEC VR4100", stdout); | |
17736 | break; | |
17737 | case AFL_EXT_3900: | |
17738 | fputs ("Toshiba R3900", stdout); | |
17739 | break; | |
17740 | case AFL_EXT_10000: | |
17741 | fputs ("MIPS R10000", stdout); | |
17742 | break; | |
17743 | case AFL_EXT_SB1: | |
17744 | fputs ("Broadcom SB-1", stdout); | |
17745 | break; | |
17746 | case AFL_EXT_4111: | |
17747 | fputs ("NEC VR4111/VR4181", stdout); | |
17748 | break; | |
17749 | case AFL_EXT_4120: | |
17750 | fputs ("NEC VR4120", stdout); | |
17751 | break; | |
17752 | case AFL_EXT_5400: | |
17753 | fputs ("NEC VR5400", stdout); | |
17754 | break; | |
17755 | case AFL_EXT_5500: | |
17756 | fputs ("NEC VR5500", stdout); | |
17757 | break; | |
17758 | case AFL_EXT_LOONGSON_2E: | |
17759 | fputs ("ST Microelectronics Loongson 2E", stdout); | |
17760 | break; | |
17761 | case AFL_EXT_LOONGSON_2F: | |
17762 | fputs ("ST Microelectronics Loongson 2F", stdout); | |
17763 | break; | |
38bf472a MR |
17764 | case AFL_EXT_INTERAPTIV_MR2: |
17765 | fputs ("Imagination interAptiv MR2", stdout); | |
17766 | break; | |
351cdf24 | 17767 | default: |
00ac7aa0 | 17768 | fprintf (stdout, "%s (%d)", _("Unknown"), isa_ext); |
351cdf24 MF |
17769 | } |
17770 | } | |
17771 | ||
32ec8896 | 17772 | static signed int |
351cdf24 MF |
17773 | get_mips_reg_size (int reg_size) |
17774 | { | |
17775 | return (reg_size == AFL_REG_NONE) ? 0 | |
17776 | : (reg_size == AFL_REG_32) ? 32 | |
17777 | : (reg_size == AFL_REG_64) ? 64 | |
17778 | : (reg_size == AFL_REG_128) ? 128 | |
17779 | : -1; | |
17780 | } | |
17781 | ||
015dc7e1 | 17782 | static bool |
dda8d76d | 17783 | process_mips_specific (Filedata * filedata) |
5b18a4bc | 17784 | { |
2cf0635d | 17785 | Elf_Internal_Dyn * entry; |
351cdf24 | 17786 | Elf_Internal_Shdr *sect = NULL; |
19e6b90e L |
17787 | size_t liblist_offset = 0; |
17788 | size_t liblistno = 0; | |
17789 | size_t conflictsno = 0; | |
17790 | size_t options_offset = 0; | |
17791 | size_t conflicts_offset = 0; | |
861fb55a DJ |
17792 | size_t pltrelsz = 0; |
17793 | size_t pltrel = 0; | |
ccb4c951 | 17794 | bfd_vma pltgot = 0; |
861fb55a DJ |
17795 | bfd_vma mips_pltgot = 0; |
17796 | bfd_vma jmprel = 0; | |
ccb4c951 RS |
17797 | bfd_vma local_gotno = 0; |
17798 | bfd_vma gotsym = 0; | |
17799 | bfd_vma symtabno = 0; | |
015dc7e1 | 17800 | bool res = true; |
103f02d3 | 17801 | |
dda8d76d | 17802 | if (! process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL, |
32ec8896 | 17803 | display_mips_gnu_attribute)) |
015dc7e1 | 17804 | res = false; |
2cf19d5c | 17805 | |
dda8d76d | 17806 | sect = find_section (filedata, ".MIPS.abiflags"); |
351cdf24 MF |
17807 | |
17808 | if (sect != NULL) | |
17809 | { | |
17810 | Elf_External_ABIFlags_v0 *abiflags_ext; | |
17811 | Elf_Internal_ABIFlags_v0 abiflags_in; | |
17812 | ||
17813 | if (sizeof (Elf_External_ABIFlags_v0) != sect->sh_size) | |
32ec8896 NC |
17814 | { |
17815 | error (_("Corrupt MIPS ABI Flags section.\n")); | |
015dc7e1 | 17816 | res = false; |
32ec8896 | 17817 | } |
351cdf24 MF |
17818 | else |
17819 | { | |
dda8d76d | 17820 | abiflags_ext = get_data (NULL, filedata, sect->sh_offset, 1, |
351cdf24 MF |
17821 | sect->sh_size, _("MIPS ABI Flags section")); |
17822 | if (abiflags_ext) | |
17823 | { | |
17824 | abiflags_in.version = BYTE_GET (abiflags_ext->version); | |
17825 | abiflags_in.isa_level = BYTE_GET (abiflags_ext->isa_level); | |
17826 | abiflags_in.isa_rev = BYTE_GET (abiflags_ext->isa_rev); | |
17827 | abiflags_in.gpr_size = BYTE_GET (abiflags_ext->gpr_size); | |
17828 | abiflags_in.cpr1_size = BYTE_GET (abiflags_ext->cpr1_size); | |
17829 | abiflags_in.cpr2_size = BYTE_GET (abiflags_ext->cpr2_size); | |
17830 | abiflags_in.fp_abi = BYTE_GET (abiflags_ext->fp_abi); | |
17831 | abiflags_in.isa_ext = BYTE_GET (abiflags_ext->isa_ext); | |
17832 | abiflags_in.ases = BYTE_GET (abiflags_ext->ases); | |
17833 | abiflags_in.flags1 = BYTE_GET (abiflags_ext->flags1); | |
17834 | abiflags_in.flags2 = BYTE_GET (abiflags_ext->flags2); | |
17835 | ||
17836 | printf ("\nMIPS ABI Flags Version: %d\n", abiflags_in.version); | |
17837 | printf ("\nISA: MIPS%d", abiflags_in.isa_level); | |
17838 | if (abiflags_in.isa_rev > 1) | |
17839 | printf ("r%d", abiflags_in.isa_rev); | |
17840 | printf ("\nGPR size: %d", | |
17841 | get_mips_reg_size (abiflags_in.gpr_size)); | |
17842 | printf ("\nCPR1 size: %d", | |
17843 | get_mips_reg_size (abiflags_in.cpr1_size)); | |
17844 | printf ("\nCPR2 size: %d", | |
17845 | get_mips_reg_size (abiflags_in.cpr2_size)); | |
17846 | fputs ("\nFP ABI: ", stdout); | |
17847 | print_mips_fp_abi_value (abiflags_in.fp_abi); | |
17848 | fputs ("ISA Extension: ", stdout); | |
17849 | print_mips_isa_ext (abiflags_in.isa_ext); | |
17850 | fputs ("\nASEs:", stdout); | |
17851 | print_mips_ases (abiflags_in.ases); | |
17852 | printf ("\nFLAGS 1: %8.8lx", abiflags_in.flags1); | |
17853 | printf ("\nFLAGS 2: %8.8lx", abiflags_in.flags2); | |
17854 | fputc ('\n', stdout); | |
17855 | free (abiflags_ext); | |
17856 | } | |
17857 | } | |
17858 | } | |
17859 | ||
19e6b90e | 17860 | /* We have a lot of special sections. Thanks SGI! */ |
978c4450 | 17861 | if (filedata->dynamic_section == NULL) |
bbdd9a68 MR |
17862 | { |
17863 | /* No dynamic information available. See if there is static GOT. */ | |
dda8d76d | 17864 | sect = find_section (filedata, ".got"); |
bbdd9a68 MR |
17865 | if (sect != NULL) |
17866 | { | |
17867 | unsigned char *data_end; | |
17868 | unsigned char *data; | |
17869 | bfd_vma ent, end; | |
17870 | int addr_size; | |
17871 | ||
17872 | pltgot = sect->sh_addr; | |
17873 | ||
17874 | ent = pltgot; | |
17875 | addr_size = (is_32bit_elf ? 4 : 8); | |
17876 | end = pltgot + sect->sh_size; | |
17877 | ||
dda8d76d | 17878 | data = (unsigned char *) get_data (NULL, filedata, sect->sh_offset, |
bbdd9a68 MR |
17879 | end - pltgot, 1, |
17880 | _("Global Offset Table data")); | |
17881 | /* PR 12855: Null data is handled gracefully throughout. */ | |
17882 | data_end = data + (end - pltgot); | |
17883 | ||
17884 | printf (_("\nStatic GOT:\n")); | |
17885 | printf (_(" Canonical gp value: ")); | |
17886 | print_vma (ent + 0x7ff0, LONG_HEX); | |
17887 | printf ("\n\n"); | |
17888 | ||
17889 | /* In a dynamic binary GOT[0] is reserved for the dynamic | |
17890 | loader to store the lazy resolver pointer, however in | |
17891 | a static binary it may well have been omitted and GOT | |
17892 | reduced to a table of addresses. | |
17893 | PR 21344: Check for the entry being fully available | |
17894 | before fetching it. */ | |
17895 | if (data | |
17896 | && data + ent - pltgot + addr_size <= data_end | |
17897 | && byte_get (data + ent - pltgot, addr_size) == 0) | |
17898 | { | |
17899 | printf (_(" Reserved entries:\n")); | |
17900 | printf (_(" %*s %10s %*s\n"), | |
17901 | addr_size * 2, _("Address"), _("Access"), | |
17902 | addr_size * 2, _("Value")); | |
17903 | ent = print_mips_got_entry (data, pltgot, ent, data_end); | |
17904 | printf ("\n"); | |
17905 | if (ent == (bfd_vma) -1) | |
17906 | goto sgot_print_fail; | |
17907 | ||
17908 | /* Check for the MSB of GOT[1] being set, identifying a | |
17909 | GNU object. This entry will be used by some runtime | |
17910 | loaders, to store the module pointer. Otherwise this | |
17911 | is an ordinary local entry. | |
17912 | PR 21344: Check for the entry being fully available | |
17913 | before fetching it. */ | |
17914 | if (data | |
17915 | && data + ent - pltgot + addr_size <= data_end | |
17916 | && (byte_get (data + ent - pltgot, addr_size) | |
17917 | >> (addr_size * 8 - 1)) != 0) | |
17918 | { | |
17919 | ent = print_mips_got_entry (data, pltgot, ent, data_end); | |
17920 | printf ("\n"); | |
17921 | if (ent == (bfd_vma) -1) | |
17922 | goto sgot_print_fail; | |
17923 | } | |
17924 | printf ("\n"); | |
17925 | } | |
17926 | ||
f17e9d8a | 17927 | if (data != NULL && ent < end) |
bbdd9a68 MR |
17928 | { |
17929 | printf (_(" Local entries:\n")); | |
17930 | printf (" %*s %10s %*s\n", | |
17931 | addr_size * 2, _("Address"), _("Access"), | |
17932 | addr_size * 2, _("Value")); | |
17933 | while (ent < end) | |
17934 | { | |
17935 | ent = print_mips_got_entry (data, pltgot, ent, data_end); | |
17936 | printf ("\n"); | |
17937 | if (ent == (bfd_vma) -1) | |
17938 | goto sgot_print_fail; | |
17939 | } | |
17940 | printf ("\n"); | |
17941 | } | |
17942 | ||
17943 | sgot_print_fail: | |
9db70fc3 | 17944 | free (data); |
bbdd9a68 MR |
17945 | } |
17946 | return res; | |
17947 | } | |
252b5132 | 17948 | |
978c4450 | 17949 | for (entry = filedata->dynamic_section; |
071436c6 | 17950 | /* PR 17531 file: 012-50589-0.004. */ |
978c4450 AM |
17951 | (entry < filedata->dynamic_section + filedata->dynamic_nent |
17952 | && entry->d_tag != DT_NULL); | |
071436c6 | 17953 | ++entry) |
252b5132 RH |
17954 | switch (entry->d_tag) |
17955 | { | |
17956 | case DT_MIPS_LIBLIST: | |
d93f0186 | 17957 | liblist_offset |
dda8d76d | 17958 | = offset_from_vma (filedata, entry->d_un.d_val, |
d93f0186 | 17959 | liblistno * sizeof (Elf32_External_Lib)); |
252b5132 RH |
17960 | break; |
17961 | case DT_MIPS_LIBLISTNO: | |
17962 | liblistno = entry->d_un.d_val; | |
17963 | break; | |
17964 | case DT_MIPS_OPTIONS: | |
dda8d76d | 17965 | options_offset = offset_from_vma (filedata, entry->d_un.d_val, 0); |
252b5132 RH |
17966 | break; |
17967 | case DT_MIPS_CONFLICT: | |
d93f0186 | 17968 | conflicts_offset |
dda8d76d | 17969 | = offset_from_vma (filedata, entry->d_un.d_val, |
d93f0186 | 17970 | conflictsno * sizeof (Elf32_External_Conflict)); |
252b5132 RH |
17971 | break; |
17972 | case DT_MIPS_CONFLICTNO: | |
17973 | conflictsno = entry->d_un.d_val; | |
17974 | break; | |
ccb4c951 | 17975 | case DT_PLTGOT: |
861fb55a DJ |
17976 | pltgot = entry->d_un.d_ptr; |
17977 | break; | |
ccb4c951 RS |
17978 | case DT_MIPS_LOCAL_GOTNO: |
17979 | local_gotno = entry->d_un.d_val; | |
17980 | break; | |
17981 | case DT_MIPS_GOTSYM: | |
17982 | gotsym = entry->d_un.d_val; | |
17983 | break; | |
17984 | case DT_MIPS_SYMTABNO: | |
17985 | symtabno = entry->d_un.d_val; | |
17986 | break; | |
861fb55a DJ |
17987 | case DT_MIPS_PLTGOT: |
17988 | mips_pltgot = entry->d_un.d_ptr; | |
17989 | break; | |
17990 | case DT_PLTREL: | |
17991 | pltrel = entry->d_un.d_val; | |
17992 | break; | |
17993 | case DT_PLTRELSZ: | |
17994 | pltrelsz = entry->d_un.d_val; | |
17995 | break; | |
17996 | case DT_JMPREL: | |
17997 | jmprel = entry->d_un.d_ptr; | |
17998 | break; | |
252b5132 RH |
17999 | default: |
18000 | break; | |
18001 | } | |
18002 | ||
18003 | if (liblist_offset != 0 && liblistno != 0 && do_dynamic) | |
18004 | { | |
2cf0635d | 18005 | Elf32_External_Lib * elib; |
252b5132 RH |
18006 | size_t cnt; |
18007 | ||
dda8d76d | 18008 | elib = (Elf32_External_Lib *) get_data (NULL, filedata, liblist_offset, |
95099889 AM |
18009 | sizeof (Elf32_External_Lib), |
18010 | liblistno, | |
18011 | _("liblist section data")); | |
a6e9f9df | 18012 | if (elib) |
252b5132 | 18013 | { |
d3a49aa8 AM |
18014 | printf (ngettext ("\nSection '.liblist' contains %lu entry:\n", |
18015 | "\nSection '.liblist' contains %lu entries:\n", | |
18016 | (unsigned long) liblistno), | |
a6e9f9df | 18017 | (unsigned long) liblistno); |
2b692964 | 18018 | fputs (_(" Library Time Stamp Checksum Version Flags\n"), |
a6e9f9df AM |
18019 | stdout); |
18020 | ||
18021 | for (cnt = 0; cnt < liblistno; ++cnt) | |
252b5132 | 18022 | { |
a6e9f9df | 18023 | Elf32_Lib liblist; |
91d6fa6a | 18024 | time_t atime; |
d5b07ef4 | 18025 | char timebuf[128]; |
2cf0635d | 18026 | struct tm * tmp; |
a6e9f9df AM |
18027 | |
18028 | liblist.l_name = BYTE_GET (elib[cnt].l_name); | |
91d6fa6a | 18029 | atime = BYTE_GET (elib[cnt].l_time_stamp); |
a6e9f9df AM |
18030 | liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum); |
18031 | liblist.l_version = BYTE_GET (elib[cnt].l_version); | |
18032 | liblist.l_flags = BYTE_GET (elib[cnt].l_flags); | |
18033 | ||
91d6fa6a | 18034 | tmp = gmtime (&atime); |
e9e44622 JJ |
18035 | snprintf (timebuf, sizeof (timebuf), |
18036 | "%04u-%02u-%02uT%02u:%02u:%02u", | |
18037 | tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday, | |
18038 | tmp->tm_hour, tmp->tm_min, tmp->tm_sec); | |
a6e9f9df | 18039 | |
31104126 | 18040 | printf ("%3lu: ", (unsigned long) cnt); |
84714f86 AM |
18041 | if (valid_dynamic_name (filedata, liblist.l_name)) |
18042 | print_symbol (20, get_dynamic_name (filedata, liblist.l_name)); | |
d79b3d50 | 18043 | else |
2b692964 | 18044 | printf (_("<corrupt: %9ld>"), liblist.l_name); |
31104126 NC |
18045 | printf (" %s %#10lx %-7ld", timebuf, liblist.l_checksum, |
18046 | liblist.l_version); | |
a6e9f9df AM |
18047 | |
18048 | if (liblist.l_flags == 0) | |
2b692964 | 18049 | puts (_(" NONE")); |
a6e9f9df AM |
18050 | else |
18051 | { | |
18052 | static const struct | |
252b5132 | 18053 | { |
2cf0635d | 18054 | const char * name; |
a6e9f9df | 18055 | int bit; |
252b5132 | 18056 | } |
a6e9f9df AM |
18057 | l_flags_vals[] = |
18058 | { | |
18059 | { " EXACT_MATCH", LL_EXACT_MATCH }, | |
18060 | { " IGNORE_INT_VER", LL_IGNORE_INT_VER }, | |
18061 | { " REQUIRE_MINOR", LL_REQUIRE_MINOR }, | |
18062 | { " EXPORTS", LL_EXPORTS }, | |
18063 | { " DELAY_LOAD", LL_DELAY_LOAD }, | |
18064 | { " DELTA", LL_DELTA } | |
18065 | }; | |
18066 | int flags = liblist.l_flags; | |
18067 | size_t fcnt; | |
18068 | ||
60bca95a | 18069 | for (fcnt = 0; fcnt < ARRAY_SIZE (l_flags_vals); ++fcnt) |
a6e9f9df AM |
18070 | if ((flags & l_flags_vals[fcnt].bit) != 0) |
18071 | { | |
18072 | fputs (l_flags_vals[fcnt].name, stdout); | |
18073 | flags ^= l_flags_vals[fcnt].bit; | |
18074 | } | |
18075 | if (flags != 0) | |
18076 | printf (" %#x", (unsigned int) flags); | |
252b5132 | 18077 | |
a6e9f9df AM |
18078 | puts (""); |
18079 | } | |
252b5132 | 18080 | } |
252b5132 | 18081 | |
a6e9f9df AM |
18082 | free (elib); |
18083 | } | |
32ec8896 | 18084 | else |
015dc7e1 | 18085 | res = false; |
252b5132 RH |
18086 | } |
18087 | ||
18088 | if (options_offset != 0) | |
18089 | { | |
2cf0635d | 18090 | Elf_External_Options * eopt; |
252b5132 RH |
18091 | size_t offset; |
18092 | int cnt; | |
dda8d76d | 18093 | sect = filedata->section_headers; |
252b5132 RH |
18094 | |
18095 | /* Find the section header so that we get the size. */ | |
dda8d76d | 18096 | sect = find_section_by_type (filedata, SHT_MIPS_OPTIONS); |
948f632f | 18097 | /* PR 17533 file: 012-277276-0.004. */ |
071436c6 NC |
18098 | if (sect == NULL) |
18099 | { | |
18100 | error (_("No MIPS_OPTIONS header found\n")); | |
015dc7e1 | 18101 | return false; |
071436c6 | 18102 | } |
7fc0c668 NC |
18103 | /* PR 24243 */ |
18104 | if (sect->sh_size < sizeof (* eopt)) | |
18105 | { | |
18106 | error (_("The MIPS options section is too small.\n")); | |
015dc7e1 | 18107 | return false; |
7fc0c668 | 18108 | } |
252b5132 | 18109 | |
dda8d76d | 18110 | eopt = (Elf_External_Options *) get_data (NULL, filedata, options_offset, 1, |
3f5e193b | 18111 | sect->sh_size, _("options")); |
a6e9f9df | 18112 | if (eopt) |
252b5132 | 18113 | { |
fd17d1e6 | 18114 | Elf_Internal_Options option; |
76da6bbe | 18115 | |
a6e9f9df | 18116 | offset = cnt = 0; |
82b1b41b | 18117 | while (offset <= sect->sh_size - sizeof (* eopt)) |
a6e9f9df | 18118 | { |
2cf0635d | 18119 | Elf_External_Options * eoption; |
fd17d1e6 | 18120 | unsigned int optsize; |
252b5132 | 18121 | |
a6e9f9df | 18122 | eoption = (Elf_External_Options *) ((char *) eopt + offset); |
252b5132 | 18123 | |
fd17d1e6 | 18124 | optsize = BYTE_GET (eoption->size); |
76da6bbe | 18125 | |
82b1b41b | 18126 | /* PR 17531: file: ffa0fa3b. */ |
fd17d1e6 AM |
18127 | if (optsize < sizeof (* eopt) |
18128 | || optsize > sect->sh_size - offset) | |
82b1b41b | 18129 | { |
645f43a8 | 18130 | error (_("Invalid size (%u) for MIPS option\n"), |
fd17d1e6 | 18131 | optsize); |
645f43a8 | 18132 | free (eopt); |
015dc7e1 | 18133 | return false; |
82b1b41b | 18134 | } |
fd17d1e6 | 18135 | offset += optsize; |
a6e9f9df AM |
18136 | ++cnt; |
18137 | } | |
252b5132 | 18138 | |
d3a49aa8 AM |
18139 | printf (ngettext ("\nSection '%s' contains %d entry:\n", |
18140 | "\nSection '%s' contains %d entries:\n", | |
18141 | cnt), | |
dda8d76d | 18142 | printable_section_name (filedata, sect), cnt); |
76da6bbe | 18143 | |
82b1b41b | 18144 | offset = 0; |
a6e9f9df | 18145 | while (cnt-- > 0) |
252b5132 | 18146 | { |
a6e9f9df | 18147 | size_t len; |
fd17d1e6 AM |
18148 | Elf_External_Options * eoption; |
18149 | ||
18150 | eoption = (Elf_External_Options *) ((char *) eopt + offset); | |
18151 | ||
18152 | option.kind = BYTE_GET (eoption->kind); | |
18153 | option.size = BYTE_GET (eoption->size); | |
18154 | option.section = BYTE_GET (eoption->section); | |
18155 | option.info = BYTE_GET (eoption->info); | |
a6e9f9df | 18156 | |
fd17d1e6 | 18157 | switch (option.kind) |
252b5132 | 18158 | { |
a6e9f9df AM |
18159 | case ODK_NULL: |
18160 | /* This shouldn't happen. */ | |
d0c4e780 | 18161 | printf (" NULL %" PRId16 " %" PRIx32, |
fd17d1e6 | 18162 | option.section, option.info); |
a6e9f9df | 18163 | break; |
2e6be59c | 18164 | |
a6e9f9df AM |
18165 | case ODK_REGINFO: |
18166 | printf (" REGINFO "); | |
dda8d76d | 18167 | if (filedata->file_header.e_machine == EM_MIPS) |
a6e9f9df | 18168 | { |
2cf0635d | 18169 | Elf32_External_RegInfo * ereg; |
b34976b6 | 18170 | Elf32_RegInfo reginfo; |
a6e9f9df | 18171 | |
2e6be59c | 18172 | /* 32bit form. */ |
fd17d1e6 AM |
18173 | if (option.size < (sizeof (Elf_External_Options) |
18174 | + sizeof (Elf32_External_RegInfo))) | |
2e6be59c NC |
18175 | { |
18176 | printf (_("<corrupt>\n")); | |
18177 | error (_("Truncated MIPS REGINFO option\n")); | |
18178 | cnt = 0; | |
18179 | break; | |
18180 | } | |
18181 | ||
fd17d1e6 | 18182 | ereg = (Elf32_External_RegInfo *) (eoption + 1); |
2e6be59c | 18183 | |
a6e9f9df AM |
18184 | reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask); |
18185 | reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]); | |
18186 | reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]); | |
18187 | reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]); | |
18188 | reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]); | |
18189 | reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value); | |
18190 | ||
d0c4e780 AM |
18191 | printf ("GPR %08" PRIx32 " GP 0x%" PRIx32 "\n", |
18192 | reginfo.ri_gprmask, reginfo.ri_gp_value); | |
18193 | printf (" " | |
18194 | " CPR0 %08" PRIx32 " CPR1 %08" PRIx32 | |
18195 | " CPR2 %08" PRIx32 " CPR3 %08" PRIx32 "\n", | |
a6e9f9df AM |
18196 | reginfo.ri_cprmask[0], reginfo.ri_cprmask[1], |
18197 | reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]); | |
18198 | } | |
18199 | else | |
18200 | { | |
18201 | /* 64 bit form. */ | |
2cf0635d | 18202 | Elf64_External_RegInfo * ereg; |
a6e9f9df AM |
18203 | Elf64_Internal_RegInfo reginfo; |
18204 | ||
fd17d1e6 AM |
18205 | if (option.size < (sizeof (Elf_External_Options) |
18206 | + sizeof (Elf64_External_RegInfo))) | |
2e6be59c NC |
18207 | { |
18208 | printf (_("<corrupt>\n")); | |
18209 | error (_("Truncated MIPS REGINFO option\n")); | |
18210 | cnt = 0; | |
18211 | break; | |
18212 | } | |
18213 | ||
fd17d1e6 | 18214 | ereg = (Elf64_External_RegInfo *) (eoption + 1); |
a6e9f9df AM |
18215 | reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask); |
18216 | reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]); | |
18217 | reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]); | |
18218 | reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]); | |
18219 | reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]); | |
66543521 | 18220 | reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value); |
a6e9f9df | 18221 | |
d0c4e780 AM |
18222 | printf ("GPR %08" PRIx32 " GP 0x%" PRIx64 "\n", |
18223 | reginfo.ri_gprmask, reginfo.ri_gp_value); | |
18224 | printf (" " | |
18225 | " CPR0 %08" PRIx32 " CPR1 %08" PRIx32 | |
18226 | " CPR2 %08" PRIx32 " CPR3 %08" PRIx32 "\n", | |
a6e9f9df AM |
18227 | reginfo.ri_cprmask[0], reginfo.ri_cprmask[1], |
18228 | reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]); | |
18229 | } | |
fd17d1e6 | 18230 | offset += option.size; |
a6e9f9df | 18231 | continue; |
2e6be59c | 18232 | |
a6e9f9df AM |
18233 | case ODK_EXCEPTIONS: |
18234 | fputs (" EXCEPTIONS fpe_min(", stdout); | |
fd17d1e6 | 18235 | process_mips_fpe_exception (option.info & OEX_FPU_MIN); |
a6e9f9df | 18236 | fputs (") fpe_max(", stdout); |
fd17d1e6 | 18237 | process_mips_fpe_exception ((option.info & OEX_FPU_MAX) >> 8); |
a6e9f9df AM |
18238 | fputs (")", stdout); |
18239 | ||
fd17d1e6 | 18240 | if (option.info & OEX_PAGE0) |
a6e9f9df | 18241 | fputs (" PAGE0", stdout); |
fd17d1e6 | 18242 | if (option.info & OEX_SMM) |
a6e9f9df | 18243 | fputs (" SMM", stdout); |
fd17d1e6 | 18244 | if (option.info & OEX_FPDBUG) |
a6e9f9df | 18245 | fputs (" FPDBUG", stdout); |
fd17d1e6 | 18246 | if (option.info & OEX_DISMISS) |
a6e9f9df AM |
18247 | fputs (" DISMISS", stdout); |
18248 | break; | |
2e6be59c | 18249 | |
a6e9f9df AM |
18250 | case ODK_PAD: |
18251 | fputs (" PAD ", stdout); | |
fd17d1e6 | 18252 | if (option.info & OPAD_PREFIX) |
a6e9f9df | 18253 | fputs (" PREFIX", stdout); |
fd17d1e6 | 18254 | if (option.info & OPAD_POSTFIX) |
a6e9f9df | 18255 | fputs (" POSTFIX", stdout); |
fd17d1e6 | 18256 | if (option.info & OPAD_SYMBOL) |
a6e9f9df AM |
18257 | fputs (" SYMBOL", stdout); |
18258 | break; | |
2e6be59c | 18259 | |
a6e9f9df AM |
18260 | case ODK_HWPATCH: |
18261 | fputs (" HWPATCH ", stdout); | |
fd17d1e6 | 18262 | if (option.info & OHW_R4KEOP) |
a6e9f9df | 18263 | fputs (" R4KEOP", stdout); |
fd17d1e6 | 18264 | if (option.info & OHW_R8KPFETCH) |
a6e9f9df | 18265 | fputs (" R8KPFETCH", stdout); |
fd17d1e6 | 18266 | if (option.info & OHW_R5KEOP) |
a6e9f9df | 18267 | fputs (" R5KEOP", stdout); |
fd17d1e6 | 18268 | if (option.info & OHW_R5KCVTL) |
a6e9f9df AM |
18269 | fputs (" R5KCVTL", stdout); |
18270 | break; | |
2e6be59c | 18271 | |
a6e9f9df AM |
18272 | case ODK_FILL: |
18273 | fputs (" FILL ", stdout); | |
18274 | /* XXX Print content of info word? */ | |
18275 | break; | |
2e6be59c | 18276 | |
a6e9f9df AM |
18277 | case ODK_TAGS: |
18278 | fputs (" TAGS ", stdout); | |
18279 | /* XXX Print content of info word? */ | |
18280 | break; | |
2e6be59c | 18281 | |
a6e9f9df AM |
18282 | case ODK_HWAND: |
18283 | fputs (" HWAND ", stdout); | |
fd17d1e6 | 18284 | if (option.info & OHWA0_R4KEOP_CHECKED) |
a6e9f9df | 18285 | fputs (" R4KEOP_CHECKED", stdout); |
fd17d1e6 | 18286 | if (option.info & OHWA0_R4KEOP_CLEAN) |
a6e9f9df AM |
18287 | fputs (" R4KEOP_CLEAN", stdout); |
18288 | break; | |
2e6be59c | 18289 | |
a6e9f9df AM |
18290 | case ODK_HWOR: |
18291 | fputs (" HWOR ", stdout); | |
fd17d1e6 | 18292 | if (option.info & OHWA0_R4KEOP_CHECKED) |
a6e9f9df | 18293 | fputs (" R4KEOP_CHECKED", stdout); |
fd17d1e6 | 18294 | if (option.info & OHWA0_R4KEOP_CLEAN) |
a6e9f9df AM |
18295 | fputs (" R4KEOP_CLEAN", stdout); |
18296 | break; | |
2e6be59c | 18297 | |
a6e9f9df | 18298 | case ODK_GP_GROUP: |
d0c4e780 | 18299 | printf (" GP_GROUP %#06x self-contained %#06x", |
fd17d1e6 AM |
18300 | option.info & OGP_GROUP, |
18301 | (option.info & OGP_SELF) >> 16); | |
a6e9f9df | 18302 | break; |
2e6be59c | 18303 | |
a6e9f9df | 18304 | case ODK_IDENT: |
d0c4e780 | 18305 | printf (" IDENT %#06x self-contained %#06x", |
fd17d1e6 AM |
18306 | option.info & OGP_GROUP, |
18307 | (option.info & OGP_SELF) >> 16); | |
a6e9f9df | 18308 | break; |
2e6be59c | 18309 | |
a6e9f9df AM |
18310 | default: |
18311 | /* This shouldn't happen. */ | |
d0c4e780 | 18312 | printf (" %3d ??? %" PRId16 " %" PRIx32, |
fd17d1e6 | 18313 | option.kind, option.section, option.info); |
a6e9f9df | 18314 | break; |
252b5132 | 18315 | } |
a6e9f9df | 18316 | |
2cf0635d | 18317 | len = sizeof (* eopt); |
fd17d1e6 | 18318 | while (len < option.size) |
82b1b41b | 18319 | { |
fd17d1e6 | 18320 | unsigned char datum = *((unsigned char *) eoption + len); |
a6e9f9df | 18321 | |
82b1b41b NC |
18322 | if (ISPRINT (datum)) |
18323 | printf ("%c", datum); | |
18324 | else | |
18325 | printf ("\\%03o", datum); | |
18326 | len ++; | |
18327 | } | |
a6e9f9df | 18328 | fputs ("\n", stdout); |
82b1b41b | 18329 | |
fd17d1e6 | 18330 | offset += option.size; |
252b5132 | 18331 | } |
a6e9f9df | 18332 | free (eopt); |
252b5132 | 18333 | } |
32ec8896 | 18334 | else |
015dc7e1 | 18335 | res = false; |
252b5132 RH |
18336 | } |
18337 | ||
18338 | if (conflicts_offset != 0 && conflictsno != 0) | |
18339 | { | |
2cf0635d | 18340 | Elf32_Conflict * iconf; |
252b5132 RH |
18341 | size_t cnt; |
18342 | ||
978c4450 | 18343 | if (filedata->dynamic_symbols == NULL) |
252b5132 | 18344 | { |
591a748a | 18345 | error (_("conflict list found without a dynamic symbol table\n")); |
015dc7e1 | 18346 | return false; |
252b5132 RH |
18347 | } |
18348 | ||
7296a62a NC |
18349 | /* PR 21345 - print a slightly more helpful error message |
18350 | if we are sure that the cmalloc will fail. */ | |
645f43a8 | 18351 | if (conflictsno > filedata->file_size / sizeof (* iconf)) |
7296a62a NC |
18352 | { |
18353 | error (_("Overlarge number of conflicts detected: %lx\n"), | |
18354 | (long) conflictsno); | |
015dc7e1 | 18355 | return false; |
7296a62a NC |
18356 | } |
18357 | ||
3f5e193b | 18358 | iconf = (Elf32_Conflict *) cmalloc (conflictsno, sizeof (* iconf)); |
252b5132 RH |
18359 | if (iconf == NULL) |
18360 | { | |
8b73c356 | 18361 | error (_("Out of memory allocating space for dynamic conflicts\n")); |
015dc7e1 | 18362 | return false; |
252b5132 RH |
18363 | } |
18364 | ||
9ea033b2 | 18365 | if (is_32bit_elf) |
252b5132 | 18366 | { |
2cf0635d | 18367 | Elf32_External_Conflict * econf32; |
a6e9f9df | 18368 | |
3f5e193b | 18369 | econf32 = (Elf32_External_Conflict *) |
95099889 AM |
18370 | get_data (NULL, filedata, conflicts_offset, |
18371 | sizeof (*econf32), conflictsno, _("conflict")); | |
a6e9f9df | 18372 | if (!econf32) |
5a814d6d AM |
18373 | { |
18374 | free (iconf); | |
015dc7e1 | 18375 | return false; |
5a814d6d | 18376 | } |
252b5132 RH |
18377 | |
18378 | for (cnt = 0; cnt < conflictsno; ++cnt) | |
18379 | iconf[cnt] = BYTE_GET (econf32[cnt]); | |
a6e9f9df AM |
18380 | |
18381 | free (econf32); | |
252b5132 RH |
18382 | } |
18383 | else | |
18384 | { | |
2cf0635d | 18385 | Elf64_External_Conflict * econf64; |
a6e9f9df | 18386 | |
3f5e193b | 18387 | econf64 = (Elf64_External_Conflict *) |
95099889 AM |
18388 | get_data (NULL, filedata, conflicts_offset, |
18389 | sizeof (*econf64), conflictsno, _("conflict")); | |
a6e9f9df | 18390 | if (!econf64) |
5a814d6d AM |
18391 | { |
18392 | free (iconf); | |
015dc7e1 | 18393 | return false; |
5a814d6d | 18394 | } |
252b5132 RH |
18395 | |
18396 | for (cnt = 0; cnt < conflictsno; ++cnt) | |
18397 | iconf[cnt] = BYTE_GET (econf64[cnt]); | |
a6e9f9df AM |
18398 | |
18399 | free (econf64); | |
252b5132 RH |
18400 | } |
18401 | ||
d3a49aa8 AM |
18402 | printf (ngettext ("\nSection '.conflict' contains %lu entry:\n", |
18403 | "\nSection '.conflict' contains %lu entries:\n", | |
18404 | (unsigned long) conflictsno), | |
c7e7ca54 | 18405 | (unsigned long) conflictsno); |
252b5132 RH |
18406 | puts (_(" Num: Index Value Name")); |
18407 | ||
18408 | for (cnt = 0; cnt < conflictsno; ++cnt) | |
18409 | { | |
b34976b6 | 18410 | printf ("%5lu: %8lu ", (unsigned long) cnt, iconf[cnt]); |
e0a31db1 | 18411 | |
978c4450 | 18412 | if (iconf[cnt] >= filedata->num_dynamic_syms) |
e0a31db1 | 18413 | printf (_("<corrupt symbol index>")); |
d79b3d50 | 18414 | else |
e0a31db1 NC |
18415 | { |
18416 | Elf_Internal_Sym * psym; | |
18417 | ||
978c4450 | 18418 | psym = & filedata->dynamic_symbols[iconf[cnt]]; |
e0a31db1 NC |
18419 | print_vma (psym->st_value, FULL_HEX); |
18420 | putchar (' '); | |
84714f86 AM |
18421 | if (valid_dynamic_name (filedata, psym->st_name)) |
18422 | print_symbol (25, get_dynamic_name (filedata, psym->st_name)); | |
e0a31db1 NC |
18423 | else |
18424 | printf (_("<corrupt: %14ld>"), psym->st_name); | |
18425 | } | |
31104126 | 18426 | putchar ('\n'); |
252b5132 RH |
18427 | } |
18428 | ||
252b5132 RH |
18429 | free (iconf); |
18430 | } | |
18431 | ||
ccb4c951 RS |
18432 | if (pltgot != 0 && local_gotno != 0) |
18433 | { | |
91d6fa6a | 18434 | bfd_vma ent, local_end, global_end; |
bbeee7ea | 18435 | size_t i, offset; |
2cf0635d | 18436 | unsigned char * data; |
82b1b41b | 18437 | unsigned char * data_end; |
bbeee7ea | 18438 | int addr_size; |
ccb4c951 | 18439 | |
91d6fa6a | 18440 | ent = pltgot; |
ccb4c951 RS |
18441 | addr_size = (is_32bit_elf ? 4 : 8); |
18442 | local_end = pltgot + local_gotno * addr_size; | |
ccb4c951 | 18443 | |
74e1a04b NC |
18444 | /* PR binutils/17533 file: 012-111227-0.004 */ |
18445 | if (symtabno < gotsym) | |
18446 | { | |
18447 | error (_("The GOT symbol offset (%lu) is greater than the symbol table size (%lu)\n"), | |
82b1b41b | 18448 | (unsigned long) gotsym, (unsigned long) symtabno); |
015dc7e1 | 18449 | return false; |
74e1a04b | 18450 | } |
82b1b41b | 18451 | |
74e1a04b | 18452 | global_end = local_end + (symtabno - gotsym) * addr_size; |
82b1b41b NC |
18453 | /* PR 17531: file: 54c91a34. */ |
18454 | if (global_end < local_end) | |
18455 | { | |
18456 | error (_("Too many GOT symbols: %lu\n"), (unsigned long) symtabno); | |
015dc7e1 | 18457 | return false; |
82b1b41b | 18458 | } |
948f632f | 18459 | |
dda8d76d NC |
18460 | offset = offset_from_vma (filedata, pltgot, global_end - pltgot); |
18461 | data = (unsigned char *) get_data (NULL, filedata, offset, | |
9cf03b7e NC |
18462 | global_end - pltgot, 1, |
18463 | _("Global Offset Table data")); | |
919383ac | 18464 | /* PR 12855: Null data is handled gracefully throughout. */ |
82b1b41b | 18465 | data_end = data + (global_end - pltgot); |
59245841 | 18466 | |
ccb4c951 RS |
18467 | printf (_("\nPrimary GOT:\n")); |
18468 | printf (_(" Canonical gp value: ")); | |
18469 | print_vma (pltgot + 0x7ff0, LONG_HEX); | |
18470 | printf ("\n\n"); | |
18471 | ||
18472 | printf (_(" Reserved entries:\n")); | |
18473 | printf (_(" %*s %10s %*s Purpose\n"), | |
2b692964 NC |
18474 | addr_size * 2, _("Address"), _("Access"), |
18475 | addr_size * 2, _("Initial")); | |
82b1b41b | 18476 | ent = print_mips_got_entry (data, pltgot, ent, data_end); |
2b692964 | 18477 | printf (_(" Lazy resolver\n")); |
82b1b41b NC |
18478 | if (ent == (bfd_vma) -1) |
18479 | goto got_print_fail; | |
75ec1fdb | 18480 | |
c4ab9505 MR |
18481 | /* Check for the MSB of GOT[1] being set, denoting a GNU object. |
18482 | This entry will be used by some runtime loaders, to store the | |
18483 | module pointer. Otherwise this is an ordinary local entry. | |
18484 | PR 21344: Check for the entry being fully available before | |
18485 | fetching it. */ | |
18486 | if (data | |
18487 | && data + ent - pltgot + addr_size <= data_end | |
18488 | && (byte_get (data + ent - pltgot, addr_size) | |
18489 | >> (addr_size * 8 - 1)) != 0) | |
18490 | { | |
18491 | ent = print_mips_got_entry (data, pltgot, ent, data_end); | |
18492 | printf (_(" Module pointer (GNU extension)\n")); | |
18493 | if (ent == (bfd_vma) -1) | |
18494 | goto got_print_fail; | |
ccb4c951 RS |
18495 | } |
18496 | printf ("\n"); | |
18497 | ||
f17e9d8a | 18498 | if (data != NULL && ent < local_end) |
ccb4c951 RS |
18499 | { |
18500 | printf (_(" Local entries:\n")); | |
cc5914eb | 18501 | printf (" %*s %10s %*s\n", |
2b692964 NC |
18502 | addr_size * 2, _("Address"), _("Access"), |
18503 | addr_size * 2, _("Initial")); | |
91d6fa6a | 18504 | while (ent < local_end) |
ccb4c951 | 18505 | { |
82b1b41b | 18506 | ent = print_mips_got_entry (data, pltgot, ent, data_end); |
ccb4c951 | 18507 | printf ("\n"); |
82b1b41b NC |
18508 | if (ent == (bfd_vma) -1) |
18509 | goto got_print_fail; | |
ccb4c951 RS |
18510 | } |
18511 | printf ("\n"); | |
18512 | } | |
18513 | ||
f17e9d8a | 18514 | if (data != NULL && gotsym < symtabno) |
ccb4c951 RS |
18515 | { |
18516 | int sym_width; | |
18517 | ||
18518 | printf (_(" Global entries:\n")); | |
cc5914eb | 18519 | printf (" %*s %10s %*s %*s %-7s %3s %s\n", |
9cf03b7e NC |
18520 | addr_size * 2, _("Address"), |
18521 | _("Access"), | |
2b692964 | 18522 | addr_size * 2, _("Initial"), |
9cf03b7e NC |
18523 | addr_size * 2, _("Sym.Val."), |
18524 | _("Type"), | |
18525 | /* Note for translators: "Ndx" = abbreviated form of "Index". */ | |
18526 | _("Ndx"), _("Name")); | |
0b4362b0 | 18527 | |
ccb4c951 | 18528 | sym_width = (is_32bit_elf ? 80 : 160) - 28 - addr_size * 6 - 1; |
e0a31db1 | 18529 | |
ccb4c951 RS |
18530 | for (i = gotsym; i < symtabno; i++) |
18531 | { | |
82b1b41b | 18532 | ent = print_mips_got_entry (data, pltgot, ent, data_end); |
ccb4c951 | 18533 | printf (" "); |
e0a31db1 | 18534 | |
978c4450 | 18535 | if (filedata->dynamic_symbols == NULL) |
e0a31db1 | 18536 | printf (_("<no dynamic symbols>")); |
978c4450 | 18537 | else if (i < filedata->num_dynamic_syms) |
e0a31db1 | 18538 | { |
978c4450 | 18539 | Elf_Internal_Sym * psym = filedata->dynamic_symbols + i; |
e0a31db1 NC |
18540 | |
18541 | print_vma (psym->st_value, LONG_HEX); | |
18542 | printf (" %-7s %3s ", | |
dda8d76d NC |
18543 | get_symbol_type (filedata, ELF_ST_TYPE (psym->st_info)), |
18544 | get_symbol_index_type (filedata, psym->st_shndx)); | |
e0a31db1 | 18545 | |
84714f86 | 18546 | if (valid_dynamic_name (filedata, psym->st_name)) |
978c4450 | 18547 | print_symbol (sym_width, |
84714f86 | 18548 | get_dynamic_name (filedata, psym->st_name)); |
e0a31db1 NC |
18549 | else |
18550 | printf (_("<corrupt: %14ld>"), psym->st_name); | |
18551 | } | |
ccb4c951 | 18552 | else |
7fc5ac57 JBG |
18553 | printf (_("<symbol index %lu exceeds number of dynamic symbols>"), |
18554 | (unsigned long) i); | |
e0a31db1 | 18555 | |
ccb4c951 | 18556 | printf ("\n"); |
82b1b41b NC |
18557 | if (ent == (bfd_vma) -1) |
18558 | break; | |
ccb4c951 RS |
18559 | } |
18560 | printf ("\n"); | |
18561 | } | |
18562 | ||
82b1b41b | 18563 | got_print_fail: |
9db70fc3 | 18564 | free (data); |
ccb4c951 RS |
18565 | } |
18566 | ||
861fb55a DJ |
18567 | if (mips_pltgot != 0 && jmprel != 0 && pltrel != 0 && pltrelsz != 0) |
18568 | { | |
91d6fa6a | 18569 | bfd_vma ent, end; |
861fb55a DJ |
18570 | size_t offset, rel_offset; |
18571 | unsigned long count, i; | |
2cf0635d | 18572 | unsigned char * data; |
861fb55a | 18573 | int addr_size, sym_width; |
2cf0635d | 18574 | Elf_Internal_Rela * rels; |
861fb55a | 18575 | |
dda8d76d | 18576 | rel_offset = offset_from_vma (filedata, jmprel, pltrelsz); |
861fb55a DJ |
18577 | if (pltrel == DT_RELA) |
18578 | { | |
dda8d76d | 18579 | if (!slurp_rela_relocs (filedata, rel_offset, pltrelsz, &rels, &count)) |
015dc7e1 | 18580 | return false; |
861fb55a DJ |
18581 | } |
18582 | else | |
18583 | { | |
dda8d76d | 18584 | if (!slurp_rel_relocs (filedata, rel_offset, pltrelsz, &rels, &count)) |
015dc7e1 | 18585 | return false; |
861fb55a DJ |
18586 | } |
18587 | ||
91d6fa6a | 18588 | ent = mips_pltgot; |
861fb55a DJ |
18589 | addr_size = (is_32bit_elf ? 4 : 8); |
18590 | end = mips_pltgot + (2 + count) * addr_size; | |
18591 | ||
dda8d76d NC |
18592 | offset = offset_from_vma (filedata, mips_pltgot, end - mips_pltgot); |
18593 | data = (unsigned char *) get_data (NULL, filedata, offset, end - mips_pltgot, | |
9cf03b7e | 18594 | 1, _("Procedure Linkage Table data")); |
59245841 | 18595 | if (data == NULL) |
288f0ba2 AM |
18596 | { |
18597 | free (rels); | |
015dc7e1 | 18598 | return false; |
288f0ba2 | 18599 | } |
59245841 | 18600 | |
9cf03b7e | 18601 | printf ("\nPLT GOT:\n\n"); |
861fb55a DJ |
18602 | printf (_(" Reserved entries:\n")); |
18603 | printf (_(" %*s %*s Purpose\n"), | |
2b692964 | 18604 | addr_size * 2, _("Address"), addr_size * 2, _("Initial")); |
91d6fa6a | 18605 | ent = print_mips_pltgot_entry (data, mips_pltgot, ent); |
2b692964 | 18606 | printf (_(" PLT lazy resolver\n")); |
91d6fa6a | 18607 | ent = print_mips_pltgot_entry (data, mips_pltgot, ent); |
2b692964 | 18608 | printf (_(" Module pointer\n")); |
861fb55a DJ |
18609 | printf ("\n"); |
18610 | ||
18611 | printf (_(" Entries:\n")); | |
cc5914eb | 18612 | printf (" %*s %*s %*s %-7s %3s %s\n", |
2b692964 NC |
18613 | addr_size * 2, _("Address"), |
18614 | addr_size * 2, _("Initial"), | |
18615 | addr_size * 2, _("Sym.Val."), _("Type"), _("Ndx"), _("Name")); | |
861fb55a DJ |
18616 | sym_width = (is_32bit_elf ? 80 : 160) - 17 - addr_size * 6 - 1; |
18617 | for (i = 0; i < count; i++) | |
18618 | { | |
df97ab2a | 18619 | unsigned long idx = get_reloc_symindex (rels[i].r_info); |
861fb55a | 18620 | |
91d6fa6a | 18621 | ent = print_mips_pltgot_entry (data, mips_pltgot, ent); |
861fb55a | 18622 | printf (" "); |
e0a31db1 | 18623 | |
978c4450 | 18624 | if (idx >= filedata->num_dynamic_syms) |
df97ab2a | 18625 | printf (_("<corrupt symbol index: %lu>"), idx); |
861fb55a | 18626 | else |
e0a31db1 | 18627 | { |
978c4450 | 18628 | Elf_Internal_Sym * psym = filedata->dynamic_symbols + idx; |
e0a31db1 NC |
18629 | |
18630 | print_vma (psym->st_value, LONG_HEX); | |
18631 | printf (" %-7s %3s ", | |
dda8d76d NC |
18632 | get_symbol_type (filedata, ELF_ST_TYPE (psym->st_info)), |
18633 | get_symbol_index_type (filedata, psym->st_shndx)); | |
84714f86 | 18634 | if (valid_dynamic_name (filedata, psym->st_name)) |
978c4450 | 18635 | print_symbol (sym_width, |
84714f86 | 18636 | get_dynamic_name (filedata, psym->st_name)); |
e0a31db1 NC |
18637 | else |
18638 | printf (_("<corrupt: %14ld>"), psym->st_name); | |
18639 | } | |
861fb55a DJ |
18640 | printf ("\n"); |
18641 | } | |
18642 | printf ("\n"); | |
18643 | ||
9db70fc3 | 18644 | free (data); |
861fb55a DJ |
18645 | free (rels); |
18646 | } | |
18647 | ||
32ec8896 | 18648 | return res; |
252b5132 RH |
18649 | } |
18650 | ||
015dc7e1 | 18651 | static bool |
dda8d76d | 18652 | process_nds32_specific (Filedata * filedata) |
35c08157 KLC |
18653 | { |
18654 | Elf_Internal_Shdr *sect = NULL; | |
18655 | ||
dda8d76d | 18656 | sect = find_section (filedata, ".nds32_e_flags"); |
9c7b8e9b | 18657 | if (sect != NULL && sect->sh_size >= 4) |
35c08157 | 18658 | { |
9c7b8e9b AM |
18659 | unsigned char *buf; |
18660 | unsigned int flag; | |
35c08157 KLC |
18661 | |
18662 | printf ("\nNDS32 elf flags section:\n"); | |
9c7b8e9b AM |
18663 | buf = get_data (NULL, filedata, sect->sh_offset, 1, 4, |
18664 | _("NDS32 elf flags section")); | |
35c08157 | 18665 | |
9c7b8e9b | 18666 | if (buf == NULL) |
015dc7e1 | 18667 | return false; |
32ec8896 | 18668 | |
9c7b8e9b AM |
18669 | flag = byte_get (buf, 4); |
18670 | free (buf); | |
18671 | switch (flag & 0x3) | |
35c08157 KLC |
18672 | { |
18673 | case 0: | |
18674 | printf ("(VEC_SIZE):\tNo entry.\n"); | |
18675 | break; | |
18676 | case 1: | |
18677 | printf ("(VEC_SIZE):\t4 bytes\n"); | |
18678 | break; | |
18679 | case 2: | |
18680 | printf ("(VEC_SIZE):\t16 bytes\n"); | |
18681 | break; | |
18682 | case 3: | |
18683 | printf ("(VEC_SIZE):\treserved\n"); | |
18684 | break; | |
18685 | } | |
18686 | } | |
18687 | ||
015dc7e1 | 18688 | return true; |
35c08157 KLC |
18689 | } |
18690 | ||
015dc7e1 | 18691 | static bool |
dda8d76d | 18692 | process_gnu_liblist (Filedata * filedata) |
047b2264 | 18693 | { |
2cf0635d NC |
18694 | Elf_Internal_Shdr * section; |
18695 | Elf_Internal_Shdr * string_sec; | |
18696 | Elf32_External_Lib * elib; | |
18697 | char * strtab; | |
c256ffe7 | 18698 | size_t strtab_size; |
047b2264 | 18699 | size_t cnt; |
d3a49aa8 | 18700 | unsigned long num_liblist; |
047b2264 | 18701 | unsigned i; |
015dc7e1 | 18702 | bool res = true; |
047b2264 JJ |
18703 | |
18704 | if (! do_arch) | |
015dc7e1 | 18705 | return true; |
047b2264 | 18706 | |
dda8d76d NC |
18707 | for (i = 0, section = filedata->section_headers; |
18708 | i < filedata->file_header.e_shnum; | |
b34976b6 | 18709 | i++, section++) |
047b2264 JJ |
18710 | { |
18711 | switch (section->sh_type) | |
18712 | { | |
18713 | case SHT_GNU_LIBLIST: | |
dda8d76d | 18714 | if (section->sh_link >= filedata->file_header.e_shnum) |
c256ffe7 JJ |
18715 | break; |
18716 | ||
3f5e193b | 18717 | elib = (Elf32_External_Lib *) |
dda8d76d | 18718 | get_data (NULL, filedata, section->sh_offset, 1, section->sh_size, |
9cf03b7e | 18719 | _("liblist section data")); |
047b2264 JJ |
18720 | |
18721 | if (elib == NULL) | |
32ec8896 | 18722 | { |
015dc7e1 | 18723 | res = false; |
32ec8896 NC |
18724 | break; |
18725 | } | |
047b2264 | 18726 | |
dda8d76d NC |
18727 | string_sec = filedata->section_headers + section->sh_link; |
18728 | strtab = (char *) get_data (NULL, filedata, string_sec->sh_offset, 1, | |
3f5e193b NC |
18729 | string_sec->sh_size, |
18730 | _("liblist string table")); | |
047b2264 JJ |
18731 | if (strtab == NULL |
18732 | || section->sh_entsize != sizeof (Elf32_External_Lib)) | |
18733 | { | |
18734 | free (elib); | |
2842702f | 18735 | free (strtab); |
015dc7e1 | 18736 | res = false; |
047b2264 JJ |
18737 | break; |
18738 | } | |
59245841 | 18739 | strtab_size = string_sec->sh_size; |
047b2264 | 18740 | |
d3a49aa8 AM |
18741 | num_liblist = section->sh_size / sizeof (Elf32_External_Lib); |
18742 | printf (ngettext ("\nLibrary list section '%s' contains %lu entries:\n", | |
18743 | "\nLibrary list section '%s' contains %lu entries:\n", | |
18744 | num_liblist), | |
dda8d76d | 18745 | printable_section_name (filedata, section), |
d3a49aa8 | 18746 | num_liblist); |
047b2264 | 18747 | |
2b692964 | 18748 | puts (_(" Library Time Stamp Checksum Version Flags")); |
047b2264 JJ |
18749 | |
18750 | for (cnt = 0; cnt < section->sh_size / sizeof (Elf32_External_Lib); | |
18751 | ++cnt) | |
18752 | { | |
18753 | Elf32_Lib liblist; | |
91d6fa6a | 18754 | time_t atime; |
d5b07ef4 | 18755 | char timebuf[128]; |
2cf0635d | 18756 | struct tm * tmp; |
047b2264 JJ |
18757 | |
18758 | liblist.l_name = BYTE_GET (elib[cnt].l_name); | |
91d6fa6a | 18759 | atime = BYTE_GET (elib[cnt].l_time_stamp); |
047b2264 JJ |
18760 | liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum); |
18761 | liblist.l_version = BYTE_GET (elib[cnt].l_version); | |
18762 | liblist.l_flags = BYTE_GET (elib[cnt].l_flags); | |
18763 | ||
91d6fa6a | 18764 | tmp = gmtime (&atime); |
e9e44622 JJ |
18765 | snprintf (timebuf, sizeof (timebuf), |
18766 | "%04u-%02u-%02uT%02u:%02u:%02u", | |
18767 | tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday, | |
18768 | tmp->tm_hour, tmp->tm_min, tmp->tm_sec); | |
047b2264 JJ |
18769 | |
18770 | printf ("%3lu: ", (unsigned long) cnt); | |
18771 | if (do_wide) | |
c256ffe7 | 18772 | printf ("%-20s", liblist.l_name < strtab_size |
2b692964 | 18773 | ? strtab + liblist.l_name : _("<corrupt>")); |
047b2264 | 18774 | else |
c256ffe7 | 18775 | printf ("%-20.20s", liblist.l_name < strtab_size |
2b692964 | 18776 | ? strtab + liblist.l_name : _("<corrupt>")); |
047b2264 JJ |
18777 | printf (" %s %#010lx %-7ld %-7ld\n", timebuf, liblist.l_checksum, |
18778 | liblist.l_version, liblist.l_flags); | |
18779 | } | |
18780 | ||
18781 | free (elib); | |
2842702f | 18782 | free (strtab); |
047b2264 JJ |
18783 | } |
18784 | } | |
18785 | ||
32ec8896 | 18786 | return res; |
047b2264 JJ |
18787 | } |
18788 | ||
9437c45b | 18789 | static const char * |
dda8d76d | 18790 | get_note_type (Filedata * filedata, unsigned e_type) |
779fe533 NC |
18791 | { |
18792 | static char buff[64]; | |
103f02d3 | 18793 | |
dda8d76d | 18794 | if (filedata->file_header.e_type == ET_CORE) |
1ec5cd37 NC |
18795 | switch (e_type) |
18796 | { | |
57346661 | 18797 | case NT_AUXV: |
1ec5cd37 | 18798 | return _("NT_AUXV (auxiliary vector)"); |
57346661 | 18799 | case NT_PRSTATUS: |
1ec5cd37 | 18800 | return _("NT_PRSTATUS (prstatus structure)"); |
57346661 | 18801 | case NT_FPREGSET: |
1ec5cd37 | 18802 | return _("NT_FPREGSET (floating point registers)"); |
57346661 | 18803 | case NT_PRPSINFO: |
1ec5cd37 | 18804 | return _("NT_PRPSINFO (prpsinfo structure)"); |
57346661 | 18805 | case NT_TASKSTRUCT: |
1ec5cd37 | 18806 | return _("NT_TASKSTRUCT (task structure)"); |
b63a5e38 AB |
18807 | case NT_GDB_TDESC: |
18808 | return _("NT_GDB_TDESC (GDB XML target description)"); | |
57346661 | 18809 | case NT_PRXFPREG: |
1ec5cd37 | 18810 | return _("NT_PRXFPREG (user_xfpregs structure)"); |
e1e95dec AM |
18811 | case NT_PPC_VMX: |
18812 | return _("NT_PPC_VMX (ppc Altivec registers)"); | |
89eeb0bc LM |
18813 | case NT_PPC_VSX: |
18814 | return _("NT_PPC_VSX (ppc VSX registers)"); | |
66c3b5f8 GR |
18815 | case NT_PPC_TAR: |
18816 | return _("NT_PPC_TAR (ppc TAR register)"); | |
18817 | case NT_PPC_PPR: | |
18818 | return _("NT_PPC_PPR (ppc PPR register)"); | |
18819 | case NT_PPC_DSCR: | |
18820 | return _("NT_PPC_DSCR (ppc DSCR register)"); | |
18821 | case NT_PPC_EBB: | |
18822 | return _("NT_PPC_EBB (ppc EBB registers)"); | |
18823 | case NT_PPC_PMU: | |
18824 | return _("NT_PPC_PMU (ppc PMU registers)"); | |
18825 | case NT_PPC_TM_CGPR: | |
18826 | return _("NT_PPC_TM_CGPR (ppc checkpointed GPR registers)"); | |
18827 | case NT_PPC_TM_CFPR: | |
18828 | return _("NT_PPC_TM_CFPR (ppc checkpointed floating point registers)"); | |
18829 | case NT_PPC_TM_CVMX: | |
18830 | return _("NT_PPC_TM_CVMX (ppc checkpointed Altivec registers)"); | |
18831 | case NT_PPC_TM_CVSX: | |
3fd21718 | 18832 | return _("NT_PPC_TM_CVSX (ppc checkpointed VSX registers)"); |
66c3b5f8 GR |
18833 | case NT_PPC_TM_SPR: |
18834 | return _("NT_PPC_TM_SPR (ppc TM special purpose registers)"); | |
18835 | case NT_PPC_TM_CTAR: | |
18836 | return _("NT_PPC_TM_CTAR (ppc checkpointed TAR register)"); | |
18837 | case NT_PPC_TM_CPPR: | |
18838 | return _("NT_PPC_TM_CPPR (ppc checkpointed PPR register)"); | |
18839 | case NT_PPC_TM_CDSCR: | |
18840 | return _("NT_PPC_TM_CDSCR (ppc checkpointed DSCR register)"); | |
ff826ef3 TT |
18841 | case NT_386_TLS: |
18842 | return _("NT_386_TLS (x86 TLS information)"); | |
18843 | case NT_386_IOPERM: | |
18844 | return _("NT_386_IOPERM (x86 I/O permissions)"); | |
4339cae0 L |
18845 | case NT_X86_XSTATE: |
18846 | return _("NT_X86_XSTATE (x86 XSAVE extended state)"); | |
8d58ed37 L |
18847 | case NT_X86_CET: |
18848 | return _("NT_X86_CET (x86 CET state)"); | |
0675e188 UW |
18849 | case NT_S390_HIGH_GPRS: |
18850 | return _("NT_S390_HIGH_GPRS (s390 upper register halves)"); | |
d7eeb400 MS |
18851 | case NT_S390_TIMER: |
18852 | return _("NT_S390_TIMER (s390 timer register)"); | |
18853 | case NT_S390_TODCMP: | |
18854 | return _("NT_S390_TODCMP (s390 TOD comparator register)"); | |
18855 | case NT_S390_TODPREG: | |
18856 | return _("NT_S390_TODPREG (s390 TOD programmable register)"); | |
18857 | case NT_S390_CTRS: | |
18858 | return _("NT_S390_CTRS (s390 control registers)"); | |
18859 | case NT_S390_PREFIX: | |
18860 | return _("NT_S390_PREFIX (s390 prefix register)"); | |
a367d729 AK |
18861 | case NT_S390_LAST_BREAK: |
18862 | return _("NT_S390_LAST_BREAK (s390 last breaking event address)"); | |
18863 | case NT_S390_SYSTEM_CALL: | |
18864 | return _("NT_S390_SYSTEM_CALL (s390 system call restart data)"); | |
abb3f6cc NC |
18865 | case NT_S390_TDB: |
18866 | return _("NT_S390_TDB (s390 transaction diagnostic block)"); | |
4ef9f41a AA |
18867 | case NT_S390_VXRS_LOW: |
18868 | return _("NT_S390_VXRS_LOW (s390 vector registers 0-15 upper half)"); | |
18869 | case NT_S390_VXRS_HIGH: | |
18870 | return _("NT_S390_VXRS_HIGH (s390 vector registers 16-31)"); | |
88ab90e8 AA |
18871 | case NT_S390_GS_CB: |
18872 | return _("NT_S390_GS_CB (s390 guarded-storage registers)"); | |
18873 | case NT_S390_GS_BC: | |
18874 | return _("NT_S390_GS_BC (s390 guarded-storage broadcast control)"); | |
faa9a424 UW |
18875 | case NT_ARM_VFP: |
18876 | return _("NT_ARM_VFP (arm VFP registers)"); | |
652451f8 YZ |
18877 | case NT_ARM_TLS: |
18878 | return _("NT_ARM_TLS (AArch TLS registers)"); | |
18879 | case NT_ARM_HW_BREAK: | |
18880 | return _("NT_ARM_HW_BREAK (AArch hardware breakpoint registers)"); | |
18881 | case NT_ARM_HW_WATCH: | |
18882 | return _("NT_ARM_HW_WATCH (AArch hardware watchpoint registers)"); | |
3b2bef8b LM |
18883 | case NT_ARM_SVE: |
18884 | return _("NT_ARM_SVE (AArch SVE registers)"); | |
18885 | case NT_ARM_PAC_MASK: | |
18886 | return _("NT_ARM_PAC_MASK (AArch pointer authentication code masks)"); | |
3af2785c LM |
18887 | case NT_ARM_PACA_KEYS: |
18888 | return _("NT_ARM_PACA_KEYS (ARM pointer authentication address keys)"); | |
18889 | case NT_ARM_PACG_KEYS: | |
18890 | return _("NT_ARM_PACG_KEYS (ARM pointer authentication generic keys)"); | |
3b2bef8b LM |
18891 | case NT_ARM_TAGGED_ADDR_CTRL: |
18892 | return _("NT_ARM_TAGGED_ADDR_CTRL (AArch tagged address control)"); | |
3af2785c LM |
18893 | case NT_ARM_PAC_ENABLED_KEYS: |
18894 | return _("NT_ARM_PAC_ENABLED_KEYS (AArch64 pointer authentication enabled keys)"); | |
27456742 AK |
18895 | case NT_ARC_V2: |
18896 | return _("NT_ARC_V2 (ARC HS accumulator/extra registers)"); | |
db6092f3 AB |
18897 | case NT_RISCV_CSR: |
18898 | return _("NT_RISCV_CSR (RISC-V control and status registers)"); | |
57346661 | 18899 | case NT_PSTATUS: |
1ec5cd37 | 18900 | return _("NT_PSTATUS (pstatus structure)"); |
57346661 | 18901 | case NT_FPREGS: |
1ec5cd37 | 18902 | return _("NT_FPREGS (floating point registers)"); |
57346661 | 18903 | case NT_PSINFO: |
1ec5cd37 | 18904 | return _("NT_PSINFO (psinfo structure)"); |
57346661 | 18905 | case NT_LWPSTATUS: |
1ec5cd37 | 18906 | return _("NT_LWPSTATUS (lwpstatus_t structure)"); |
57346661 | 18907 | case NT_LWPSINFO: |
1ec5cd37 | 18908 | return _("NT_LWPSINFO (lwpsinfo_t structure)"); |
57346661 | 18909 | case NT_WIN32PSTATUS: |
1ec5cd37 | 18910 | return _("NT_WIN32PSTATUS (win32_pstatus structure)"); |
9ece1fa9 TT |
18911 | case NT_SIGINFO: |
18912 | return _("NT_SIGINFO (siginfo_t data)"); | |
18913 | case NT_FILE: | |
18914 | return _("NT_FILE (mapped files)"); | |
1ec5cd37 NC |
18915 | default: |
18916 | break; | |
18917 | } | |
18918 | else | |
18919 | switch (e_type) | |
18920 | { | |
18921 | case NT_VERSION: | |
18922 | return _("NT_VERSION (version)"); | |
18923 | case NT_ARCH: | |
18924 | return _("NT_ARCH (architecture)"); | |
9ef920e9 | 18925 | case NT_GNU_BUILD_ATTRIBUTE_OPEN: |
6f156d7a | 18926 | return _("OPEN"); |
9ef920e9 | 18927 | case NT_GNU_BUILD_ATTRIBUTE_FUNC: |
6f156d7a | 18928 | return _("func"); |
c8795e1f NC |
18929 | case NT_GO_BUILDID: |
18930 | return _("GO BUILDID"); | |
1ec5cd37 NC |
18931 | default: |
18932 | break; | |
18933 | } | |
18934 | ||
e9e44622 | 18935 | snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type); |
1ec5cd37 | 18936 | return buff; |
779fe533 NC |
18937 | } |
18938 | ||
015dc7e1 | 18939 | static bool |
9ece1fa9 TT |
18940 | print_core_note (Elf_Internal_Note *pnote) |
18941 | { | |
18942 | unsigned int addr_size = is_32bit_elf ? 4 : 8; | |
18943 | bfd_vma count, page_size; | |
18944 | unsigned char *descdata, *filenames, *descend; | |
18945 | ||
18946 | if (pnote->type != NT_FILE) | |
04ac15ab AS |
18947 | { |
18948 | if (do_wide) | |
18949 | printf ("\n"); | |
015dc7e1 | 18950 | return true; |
04ac15ab | 18951 | } |
9ece1fa9 TT |
18952 | |
18953 | #ifndef BFD64 | |
18954 | if (!is_32bit_elf) | |
18955 | { | |
18956 | printf (_(" Cannot decode 64-bit note in 32-bit build\n")); | |
18957 | /* Still "successful". */ | |
015dc7e1 | 18958 | return true; |
9ece1fa9 TT |
18959 | } |
18960 | #endif | |
18961 | ||
18962 | if (pnote->descsz < 2 * addr_size) | |
18963 | { | |
32ec8896 | 18964 | error (_(" Malformed note - too short for header\n")); |
015dc7e1 | 18965 | return false; |
9ece1fa9 TT |
18966 | } |
18967 | ||
18968 | descdata = (unsigned char *) pnote->descdata; | |
18969 | descend = descdata + pnote->descsz; | |
18970 | ||
18971 | if (descdata[pnote->descsz - 1] != '\0') | |
18972 | { | |
32ec8896 | 18973 | error (_(" Malformed note - does not end with \\0\n")); |
015dc7e1 | 18974 | return false; |
9ece1fa9 TT |
18975 | } |
18976 | ||
18977 | count = byte_get (descdata, addr_size); | |
18978 | descdata += addr_size; | |
18979 | ||
18980 | page_size = byte_get (descdata, addr_size); | |
18981 | descdata += addr_size; | |
18982 | ||
5396a86e AM |
18983 | if (count > ((bfd_vma) -1 - 2 * addr_size) / (3 * addr_size) |
18984 | || pnote->descsz < 2 * addr_size + count * 3 * addr_size) | |
9ece1fa9 | 18985 | { |
32ec8896 | 18986 | error (_(" Malformed note - too short for supplied file count\n")); |
015dc7e1 | 18987 | return false; |
9ece1fa9 TT |
18988 | } |
18989 | ||
18990 | printf (_(" Page size: ")); | |
18991 | print_vma (page_size, DEC); | |
18992 | printf ("\n"); | |
18993 | ||
18994 | printf (_(" %*s%*s%*s\n"), | |
18995 | (int) (2 + 2 * addr_size), _("Start"), | |
18996 | (int) (4 + 2 * addr_size), _("End"), | |
18997 | (int) (4 + 2 * addr_size), _("Page Offset")); | |
18998 | filenames = descdata + count * 3 * addr_size; | |
595712bb | 18999 | while (count-- > 0) |
9ece1fa9 TT |
19000 | { |
19001 | bfd_vma start, end, file_ofs; | |
19002 | ||
19003 | if (filenames == descend) | |
19004 | { | |
32ec8896 | 19005 | error (_(" Malformed note - filenames end too early\n")); |
015dc7e1 | 19006 | return false; |
9ece1fa9 TT |
19007 | } |
19008 | ||
19009 | start = byte_get (descdata, addr_size); | |
19010 | descdata += addr_size; | |
19011 | end = byte_get (descdata, addr_size); | |
19012 | descdata += addr_size; | |
19013 | file_ofs = byte_get (descdata, addr_size); | |
19014 | descdata += addr_size; | |
19015 | ||
19016 | printf (" "); | |
19017 | print_vma (start, FULL_HEX); | |
19018 | printf (" "); | |
19019 | print_vma (end, FULL_HEX); | |
19020 | printf (" "); | |
19021 | print_vma (file_ofs, FULL_HEX); | |
19022 | printf ("\n %s\n", filenames); | |
19023 | ||
19024 | filenames += 1 + strlen ((char *) filenames); | |
19025 | } | |
19026 | ||
015dc7e1 | 19027 | return true; |
9ece1fa9 TT |
19028 | } |
19029 | ||
1118d252 RM |
19030 | static const char * |
19031 | get_gnu_elf_note_type (unsigned e_type) | |
19032 | { | |
1449284b | 19033 | /* NB/ Keep this switch statement in sync with print_gnu_note (). */ |
1118d252 RM |
19034 | switch (e_type) |
19035 | { | |
19036 | case NT_GNU_ABI_TAG: | |
19037 | return _("NT_GNU_ABI_TAG (ABI version tag)"); | |
19038 | case NT_GNU_HWCAP: | |
19039 | return _("NT_GNU_HWCAP (DSO-supplied software HWCAP info)"); | |
19040 | case NT_GNU_BUILD_ID: | |
19041 | return _("NT_GNU_BUILD_ID (unique build ID bitstring)"); | |
0297aed6 DM |
19042 | case NT_GNU_GOLD_VERSION: |
19043 | return _("NT_GNU_GOLD_VERSION (gold version)"); | |
9ef920e9 NC |
19044 | case NT_GNU_PROPERTY_TYPE_0: |
19045 | return _("NT_GNU_PROPERTY_TYPE_0"); | |
19046 | case NT_GNU_BUILD_ATTRIBUTE_OPEN: | |
19047 | return _("NT_GNU_BUILD_ATTRIBUTE_OPEN"); | |
19048 | case NT_GNU_BUILD_ATTRIBUTE_FUNC: | |
19049 | return _("NT_GNU_BUILD_ATTRIBUTE_FUNC"); | |
1118d252 | 19050 | default: |
1449284b NC |
19051 | { |
19052 | static char buff[64]; | |
1118d252 | 19053 | |
1449284b NC |
19054 | snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type); |
19055 | return buff; | |
19056 | } | |
19057 | } | |
1118d252 RM |
19058 | } |
19059 | ||
a9eafb08 L |
19060 | static void |
19061 | decode_x86_compat_isa (unsigned int bitmask) | |
19062 | { | |
19063 | while (bitmask) | |
19064 | { | |
19065 | unsigned int bit = bitmask & (- bitmask); | |
19066 | ||
19067 | bitmask &= ~ bit; | |
19068 | switch (bit) | |
19069 | { | |
19070 | case GNU_PROPERTY_X86_COMPAT_ISA_1_486: | |
19071 | printf ("i486"); | |
19072 | break; | |
19073 | case GNU_PROPERTY_X86_COMPAT_ISA_1_586: | |
19074 | printf ("586"); | |
19075 | break; | |
19076 | case GNU_PROPERTY_X86_COMPAT_ISA_1_686: | |
19077 | printf ("686"); | |
19078 | break; | |
19079 | case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE: | |
19080 | printf ("SSE"); | |
19081 | break; | |
19082 | case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE2: | |
19083 | printf ("SSE2"); | |
19084 | break; | |
19085 | case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE3: | |
19086 | printf ("SSE3"); | |
19087 | break; | |
19088 | case GNU_PROPERTY_X86_COMPAT_ISA_1_SSSE3: | |
19089 | printf ("SSSE3"); | |
19090 | break; | |
19091 | case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE4_1: | |
19092 | printf ("SSE4_1"); | |
19093 | break; | |
19094 | case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE4_2: | |
19095 | printf ("SSE4_2"); | |
19096 | break; | |
19097 | case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX: | |
19098 | printf ("AVX"); | |
19099 | break; | |
19100 | case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX2: | |
19101 | printf ("AVX2"); | |
19102 | break; | |
19103 | case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512F: | |
19104 | printf ("AVX512F"); | |
19105 | break; | |
19106 | case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512CD: | |
19107 | printf ("AVX512CD"); | |
19108 | break; | |
19109 | case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512ER: | |
19110 | printf ("AVX512ER"); | |
19111 | break; | |
19112 | case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512PF: | |
19113 | printf ("AVX512PF"); | |
19114 | break; | |
19115 | case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512VL: | |
19116 | printf ("AVX512VL"); | |
19117 | break; | |
19118 | case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512DQ: | |
19119 | printf ("AVX512DQ"); | |
19120 | break; | |
19121 | case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512BW: | |
19122 | printf ("AVX512BW"); | |
19123 | break; | |
65b3d26e L |
19124 | default: |
19125 | printf (_("<unknown: %x>"), bit); | |
19126 | break; | |
a9eafb08 L |
19127 | } |
19128 | if (bitmask) | |
19129 | printf (", "); | |
19130 | } | |
19131 | } | |
19132 | ||
9ef920e9 | 19133 | static void |
32930e4e | 19134 | decode_x86_compat_2_isa (unsigned int bitmask) |
9ef920e9 | 19135 | { |
0a59decb | 19136 | if (!bitmask) |
90c745dc L |
19137 | { |
19138 | printf (_("<None>")); | |
19139 | return; | |
19140 | } | |
90c745dc | 19141 | |
9ef920e9 NC |
19142 | while (bitmask) |
19143 | { | |
1fc87489 | 19144 | unsigned int bit = bitmask & (- bitmask); |
9ef920e9 NC |
19145 | |
19146 | bitmask &= ~ bit; | |
19147 | switch (bit) | |
19148 | { | |
32930e4e | 19149 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_CMOV: |
a9eafb08 L |
19150 | printf ("CMOV"); |
19151 | break; | |
32930e4e | 19152 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE: |
a9eafb08 L |
19153 | printf ("SSE"); |
19154 | break; | |
32930e4e | 19155 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE2: |
a9eafb08 L |
19156 | printf ("SSE2"); |
19157 | break; | |
32930e4e | 19158 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE3: |
a9eafb08 L |
19159 | printf ("SSE3"); |
19160 | break; | |
32930e4e | 19161 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSSE3: |
a9eafb08 L |
19162 | printf ("SSSE3"); |
19163 | break; | |
32930e4e | 19164 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE4_1: |
a9eafb08 L |
19165 | printf ("SSE4_1"); |
19166 | break; | |
32930e4e | 19167 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE4_2: |
a9eafb08 L |
19168 | printf ("SSE4_2"); |
19169 | break; | |
32930e4e | 19170 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX: |
a9eafb08 L |
19171 | printf ("AVX"); |
19172 | break; | |
32930e4e | 19173 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX2: |
a9eafb08 L |
19174 | printf ("AVX2"); |
19175 | break; | |
32930e4e | 19176 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_FMA: |
a9eafb08 L |
19177 | printf ("FMA"); |
19178 | break; | |
32930e4e | 19179 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512F: |
a9eafb08 L |
19180 | printf ("AVX512F"); |
19181 | break; | |
32930e4e | 19182 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512CD: |
a9eafb08 L |
19183 | printf ("AVX512CD"); |
19184 | break; | |
32930e4e | 19185 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512ER: |
a9eafb08 L |
19186 | printf ("AVX512ER"); |
19187 | break; | |
32930e4e | 19188 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512PF: |
a9eafb08 L |
19189 | printf ("AVX512PF"); |
19190 | break; | |
32930e4e | 19191 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512VL: |
a9eafb08 L |
19192 | printf ("AVX512VL"); |
19193 | break; | |
32930e4e | 19194 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512DQ: |
a9eafb08 L |
19195 | printf ("AVX512DQ"); |
19196 | break; | |
32930e4e | 19197 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512BW: |
a9eafb08 L |
19198 | printf ("AVX512BW"); |
19199 | break; | |
32930e4e | 19200 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_4FMAPS: |
a9eafb08 L |
19201 | printf ("AVX512_4FMAPS"); |
19202 | break; | |
32930e4e | 19203 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_4VNNIW: |
a9eafb08 L |
19204 | printf ("AVX512_4VNNIW"); |
19205 | break; | |
32930e4e | 19206 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_BITALG: |
a9eafb08 L |
19207 | printf ("AVX512_BITALG"); |
19208 | break; | |
32930e4e | 19209 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_IFMA: |
a9eafb08 L |
19210 | printf ("AVX512_IFMA"); |
19211 | break; | |
32930e4e | 19212 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_VBMI: |
a9eafb08 L |
19213 | printf ("AVX512_VBMI"); |
19214 | break; | |
32930e4e | 19215 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_VBMI2: |
a9eafb08 L |
19216 | printf ("AVX512_VBMI2"); |
19217 | break; | |
32930e4e | 19218 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_VNNI: |
a9eafb08 L |
19219 | printf ("AVX512_VNNI"); |
19220 | break; | |
32930e4e | 19221 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_BF16: |
462cac58 L |
19222 | printf ("AVX512_BF16"); |
19223 | break; | |
65b3d26e L |
19224 | default: |
19225 | printf (_("<unknown: %x>"), bit); | |
19226 | break; | |
9ef920e9 NC |
19227 | } |
19228 | if (bitmask) | |
19229 | printf (", "); | |
19230 | } | |
19231 | } | |
19232 | ||
32930e4e L |
19233 | static void |
19234 | decode_x86_isa (unsigned int bitmask) | |
19235 | { | |
32930e4e L |
19236 | while (bitmask) |
19237 | { | |
19238 | unsigned int bit = bitmask & (- bitmask); | |
19239 | ||
19240 | bitmask &= ~ bit; | |
19241 | switch (bit) | |
19242 | { | |
b0ab0693 L |
19243 | case GNU_PROPERTY_X86_ISA_1_BASELINE: |
19244 | printf ("x86-64-baseline"); | |
19245 | break; | |
32930e4e L |
19246 | case GNU_PROPERTY_X86_ISA_1_V2: |
19247 | printf ("x86-64-v2"); | |
19248 | break; | |
19249 | case GNU_PROPERTY_X86_ISA_1_V3: | |
19250 | printf ("x86-64-v3"); | |
19251 | break; | |
19252 | case GNU_PROPERTY_X86_ISA_1_V4: | |
19253 | printf ("x86-64-v4"); | |
19254 | break; | |
19255 | default: | |
19256 | printf (_("<unknown: %x>"), bit); | |
19257 | break; | |
19258 | } | |
19259 | if (bitmask) | |
19260 | printf (", "); | |
19261 | } | |
19262 | } | |
19263 | ||
ee2fdd6f | 19264 | static void |
a9eafb08 | 19265 | decode_x86_feature_1 (unsigned int bitmask) |
ee2fdd6f | 19266 | { |
0a59decb | 19267 | if (!bitmask) |
90c745dc L |
19268 | { |
19269 | printf (_("<None>")); | |
19270 | return; | |
19271 | } | |
90c745dc | 19272 | |
ee2fdd6f L |
19273 | while (bitmask) |
19274 | { | |
19275 | unsigned int bit = bitmask & (- bitmask); | |
19276 | ||
19277 | bitmask &= ~ bit; | |
19278 | switch (bit) | |
19279 | { | |
19280 | case GNU_PROPERTY_X86_FEATURE_1_IBT: | |
a9eafb08 | 19281 | printf ("IBT"); |
ee2fdd6f | 19282 | break; |
48580982 | 19283 | case GNU_PROPERTY_X86_FEATURE_1_SHSTK: |
a9eafb08 | 19284 | printf ("SHSTK"); |
48580982 | 19285 | break; |
279d901e L |
19286 | case GNU_PROPERTY_X86_FEATURE_1_LAM_U48: |
19287 | printf ("LAM_U48"); | |
19288 | break; | |
19289 | case GNU_PROPERTY_X86_FEATURE_1_LAM_U57: | |
19290 | printf ("LAM_U57"); | |
19291 | break; | |
ee2fdd6f L |
19292 | default: |
19293 | printf (_("<unknown: %x>"), bit); | |
19294 | break; | |
19295 | } | |
19296 | if (bitmask) | |
19297 | printf (", "); | |
19298 | } | |
19299 | } | |
19300 | ||
a9eafb08 L |
19301 | static void |
19302 | decode_x86_feature_2 (unsigned int bitmask) | |
19303 | { | |
0a59decb | 19304 | if (!bitmask) |
90c745dc L |
19305 | { |
19306 | printf (_("<None>")); | |
19307 | return; | |
19308 | } | |
90c745dc | 19309 | |
a9eafb08 L |
19310 | while (bitmask) |
19311 | { | |
19312 | unsigned int bit = bitmask & (- bitmask); | |
19313 | ||
19314 | bitmask &= ~ bit; | |
19315 | switch (bit) | |
19316 | { | |
19317 | case GNU_PROPERTY_X86_FEATURE_2_X86: | |
19318 | printf ("x86"); | |
19319 | break; | |
19320 | case GNU_PROPERTY_X86_FEATURE_2_X87: | |
19321 | printf ("x87"); | |
19322 | break; | |
19323 | case GNU_PROPERTY_X86_FEATURE_2_MMX: | |
19324 | printf ("MMX"); | |
19325 | break; | |
19326 | case GNU_PROPERTY_X86_FEATURE_2_XMM: | |
19327 | printf ("XMM"); | |
19328 | break; | |
19329 | case GNU_PROPERTY_X86_FEATURE_2_YMM: | |
19330 | printf ("YMM"); | |
19331 | break; | |
19332 | case GNU_PROPERTY_X86_FEATURE_2_ZMM: | |
19333 | printf ("ZMM"); | |
19334 | break; | |
a308b89d L |
19335 | case GNU_PROPERTY_X86_FEATURE_2_TMM: |
19336 | printf ("TMM"); | |
19337 | break; | |
32930e4e L |
19338 | case GNU_PROPERTY_X86_FEATURE_2_MASK: |
19339 | printf ("MASK"); | |
19340 | break; | |
a9eafb08 L |
19341 | case GNU_PROPERTY_X86_FEATURE_2_FXSR: |
19342 | printf ("FXSR"); | |
19343 | break; | |
19344 | case GNU_PROPERTY_X86_FEATURE_2_XSAVE: | |
19345 | printf ("XSAVE"); | |
19346 | break; | |
19347 | case GNU_PROPERTY_X86_FEATURE_2_XSAVEOPT: | |
19348 | printf ("XSAVEOPT"); | |
19349 | break; | |
19350 | case GNU_PROPERTY_X86_FEATURE_2_XSAVEC: | |
19351 | printf ("XSAVEC"); | |
19352 | break; | |
65b3d26e L |
19353 | default: |
19354 | printf (_("<unknown: %x>"), bit); | |
19355 | break; | |
a9eafb08 L |
19356 | } |
19357 | if (bitmask) | |
19358 | printf (", "); | |
19359 | } | |
19360 | } | |
19361 | ||
cd702818 SD |
19362 | static void |
19363 | decode_aarch64_feature_1_and (unsigned int bitmask) | |
19364 | { | |
19365 | while (bitmask) | |
19366 | { | |
19367 | unsigned int bit = bitmask & (- bitmask); | |
19368 | ||
19369 | bitmask &= ~ bit; | |
19370 | switch (bit) | |
19371 | { | |
19372 | case GNU_PROPERTY_AARCH64_FEATURE_1_BTI: | |
19373 | printf ("BTI"); | |
19374 | break; | |
19375 | ||
19376 | case GNU_PROPERTY_AARCH64_FEATURE_1_PAC: | |
19377 | printf ("PAC"); | |
19378 | break; | |
19379 | ||
19380 | default: | |
19381 | printf (_("<unknown: %x>"), bit); | |
19382 | break; | |
19383 | } | |
19384 | if (bitmask) | |
19385 | printf (", "); | |
19386 | } | |
19387 | } | |
19388 | ||
6320fd00 L |
19389 | static void |
19390 | decode_1_needed (unsigned int bitmask) | |
19391 | { | |
19392 | while (bitmask) | |
19393 | { | |
19394 | unsigned int bit = bitmask & (- bitmask); | |
19395 | ||
19396 | bitmask &= ~ bit; | |
19397 | switch (bit) | |
19398 | { | |
19399 | case GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS: | |
19400 | printf ("indirect external access"); | |
19401 | break; | |
19402 | default: | |
19403 | printf (_("<unknown: %x>"), bit); | |
19404 | break; | |
19405 | } | |
19406 | if (bitmask) | |
19407 | printf (", "); | |
19408 | } | |
19409 | } | |
19410 | ||
9ef920e9 | 19411 | static void |
dda8d76d | 19412 | print_gnu_property_note (Filedata * filedata, Elf_Internal_Note * pnote) |
9ef920e9 NC |
19413 | { |
19414 | unsigned char * ptr = (unsigned char *) pnote->descdata; | |
19415 | unsigned char * ptr_end = ptr + pnote->descsz; | |
19416 | unsigned int size = is_32bit_elf ? 4 : 8; | |
19417 | ||
19418 | printf (_(" Properties: ")); | |
19419 | ||
1fc87489 | 19420 | if (pnote->descsz < 8 || (pnote->descsz % size) != 0) |
9ef920e9 NC |
19421 | { |
19422 | printf (_("<corrupt GNU_PROPERTY_TYPE, size = %#lx>\n"), pnote->descsz); | |
19423 | return; | |
19424 | } | |
19425 | ||
6ab2c4ed | 19426 | while (ptr < ptr_end) |
9ef920e9 | 19427 | { |
1fc87489 | 19428 | unsigned int j; |
6ab2c4ed MC |
19429 | unsigned int type; |
19430 | unsigned int datasz; | |
19431 | ||
19432 | if ((size_t) (ptr_end - ptr) < 8) | |
19433 | { | |
19434 | printf (_("<corrupt descsz: %#lx>\n"), pnote->descsz); | |
19435 | break; | |
19436 | } | |
19437 | ||
19438 | type = byte_get (ptr, 4); | |
19439 | datasz = byte_get (ptr + 4, 4); | |
9ef920e9 | 19440 | |
1fc87489 | 19441 | ptr += 8; |
9ef920e9 | 19442 | |
6ab2c4ed | 19443 | if (datasz > (size_t) (ptr_end - ptr)) |
9ef920e9 | 19444 | { |
1fc87489 L |
19445 | printf (_("<corrupt type (%#x) datasz: %#x>\n"), |
19446 | type, datasz); | |
9ef920e9 | 19447 | break; |
1fc87489 | 19448 | } |
9ef920e9 | 19449 | |
1fc87489 L |
19450 | if (type >= GNU_PROPERTY_LOPROC && type <= GNU_PROPERTY_HIPROC) |
19451 | { | |
dda8d76d NC |
19452 | if (filedata->file_header.e_machine == EM_X86_64 |
19453 | || filedata->file_header.e_machine == EM_IAMCU | |
19454 | || filedata->file_header.e_machine == EM_386) | |
1fc87489 | 19455 | { |
aa7bca9b L |
19456 | unsigned int bitmask; |
19457 | ||
19458 | if (datasz == 4) | |
0a59decb | 19459 | bitmask = byte_get (ptr, 4); |
aa7bca9b L |
19460 | else |
19461 | bitmask = 0; | |
19462 | ||
1fc87489 L |
19463 | switch (type) |
19464 | { | |
19465 | case GNU_PROPERTY_X86_ISA_1_USED: | |
1fc87489 | 19466 | if (datasz != 4) |
aa7bca9b L |
19467 | printf (_("x86 ISA used: <corrupt length: %#x> "), |
19468 | datasz); | |
1fc87489 | 19469 | else |
aa7bca9b L |
19470 | { |
19471 | printf ("x86 ISA used: "); | |
19472 | decode_x86_isa (bitmask); | |
19473 | } | |
1fc87489 | 19474 | goto next; |
9ef920e9 | 19475 | |
1fc87489 | 19476 | case GNU_PROPERTY_X86_ISA_1_NEEDED: |
1fc87489 | 19477 | if (datasz != 4) |
aa7bca9b L |
19478 | printf (_("x86 ISA needed: <corrupt length: %#x> "), |
19479 | datasz); | |
1fc87489 | 19480 | else |
aa7bca9b L |
19481 | { |
19482 | printf ("x86 ISA needed: "); | |
19483 | decode_x86_isa (bitmask); | |
19484 | } | |
1fc87489 | 19485 | goto next; |
9ef920e9 | 19486 | |
ee2fdd6f | 19487 | case GNU_PROPERTY_X86_FEATURE_1_AND: |
ee2fdd6f | 19488 | if (datasz != 4) |
aa7bca9b L |
19489 | printf (_("x86 feature: <corrupt length: %#x> "), |
19490 | datasz); | |
ee2fdd6f | 19491 | else |
aa7bca9b L |
19492 | { |
19493 | printf ("x86 feature: "); | |
a9eafb08 L |
19494 | decode_x86_feature_1 (bitmask); |
19495 | } | |
19496 | goto next; | |
19497 | ||
19498 | case GNU_PROPERTY_X86_FEATURE_2_USED: | |
19499 | if (datasz != 4) | |
19500 | printf (_("x86 feature used: <corrupt length: %#x> "), | |
19501 | datasz); | |
19502 | else | |
19503 | { | |
19504 | printf ("x86 feature used: "); | |
19505 | decode_x86_feature_2 (bitmask); | |
19506 | } | |
19507 | goto next; | |
19508 | ||
19509 | case GNU_PROPERTY_X86_FEATURE_2_NEEDED: | |
19510 | if (datasz != 4) | |
19511 | printf (_("x86 feature needed: <corrupt length: %#x> "), datasz); | |
19512 | else | |
19513 | { | |
19514 | printf ("x86 feature needed: "); | |
19515 | decode_x86_feature_2 (bitmask); | |
19516 | } | |
19517 | goto next; | |
19518 | ||
19519 | case GNU_PROPERTY_X86_COMPAT_ISA_1_USED: | |
19520 | if (datasz != 4) | |
19521 | printf (_("x86 ISA used: <corrupt length: %#x> "), | |
19522 | datasz); | |
19523 | else | |
19524 | { | |
19525 | printf ("x86 ISA used: "); | |
19526 | decode_x86_compat_isa (bitmask); | |
19527 | } | |
19528 | goto next; | |
19529 | ||
19530 | case GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED: | |
19531 | if (datasz != 4) | |
19532 | printf (_("x86 ISA needed: <corrupt length: %#x> "), | |
19533 | datasz); | |
19534 | else | |
19535 | { | |
19536 | printf ("x86 ISA needed: "); | |
19537 | decode_x86_compat_isa (bitmask); | |
aa7bca9b | 19538 | } |
ee2fdd6f L |
19539 | goto next; |
19540 | ||
32930e4e L |
19541 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_USED: |
19542 | if (datasz != 4) | |
19543 | printf (_("x86 ISA used: <corrupt length: %#x> "), | |
19544 | datasz); | |
19545 | else | |
19546 | { | |
19547 | printf ("x86 ISA used: "); | |
19548 | decode_x86_compat_2_isa (bitmask); | |
19549 | } | |
19550 | goto next; | |
19551 | ||
19552 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_NEEDED: | |
19553 | if (datasz != 4) | |
19554 | printf (_("x86 ISA needed: <corrupt length: %#x> "), | |
19555 | datasz); | |
19556 | else | |
19557 | { | |
19558 | printf ("x86 ISA needed: "); | |
19559 | decode_x86_compat_2_isa (bitmask); | |
19560 | } | |
19561 | goto next; | |
19562 | ||
1fc87489 L |
19563 | default: |
19564 | break; | |
19565 | } | |
19566 | } | |
cd702818 SD |
19567 | else if (filedata->file_header.e_machine == EM_AARCH64) |
19568 | { | |
19569 | if (type == GNU_PROPERTY_AARCH64_FEATURE_1_AND) | |
19570 | { | |
19571 | printf ("AArch64 feature: "); | |
19572 | if (datasz != 4) | |
19573 | printf (_("<corrupt length: %#x> "), datasz); | |
19574 | else | |
19575 | decode_aarch64_feature_1_and (byte_get (ptr, 4)); | |
19576 | goto next; | |
19577 | } | |
19578 | } | |
1fc87489 L |
19579 | } |
19580 | else | |
19581 | { | |
19582 | switch (type) | |
9ef920e9 | 19583 | { |
1fc87489 L |
19584 | case GNU_PROPERTY_STACK_SIZE: |
19585 | printf (_("stack size: ")); | |
19586 | if (datasz != size) | |
19587 | printf (_("<corrupt length: %#x> "), datasz); | |
19588 | else | |
19589 | printf ("%#lx", (unsigned long) byte_get (ptr, size)); | |
19590 | goto next; | |
19591 | ||
19592 | case GNU_PROPERTY_NO_COPY_ON_PROTECTED: | |
19593 | printf ("no copy on protected "); | |
19594 | if (datasz) | |
19595 | printf (_("<corrupt length: %#x> "), datasz); | |
19596 | goto next; | |
19597 | ||
19598 | default: | |
5a767724 L |
19599 | if ((type >= GNU_PROPERTY_UINT32_AND_LO |
19600 | && type <= GNU_PROPERTY_UINT32_AND_HI) | |
19601 | || (type >= GNU_PROPERTY_UINT32_OR_LO | |
19602 | && type <= GNU_PROPERTY_UINT32_OR_HI)) | |
19603 | { | |
6320fd00 L |
19604 | switch (type) |
19605 | { | |
19606 | case GNU_PROPERTY_1_NEEDED: | |
19607 | if (datasz != 4) | |
19608 | printf (_("1_needed: <corrupt length: %#x> "), | |
19609 | datasz); | |
19610 | else | |
19611 | { | |
19612 | unsigned int bitmask = byte_get (ptr, 4); | |
19613 | printf ("1_needed: "); | |
19614 | decode_1_needed (bitmask); | |
19615 | } | |
19616 | goto next; | |
19617 | ||
19618 | default: | |
19619 | break; | |
19620 | } | |
5a767724 L |
19621 | if (type <= GNU_PROPERTY_UINT32_AND_HI) |
19622 | printf (_("UINT32_AND (%#x): "), type); | |
19623 | else | |
19624 | printf (_("UINT32_OR (%#x): "), type); | |
19625 | if (datasz != 4) | |
19626 | printf (_("<corrupt length: %#x> "), datasz); | |
19627 | else | |
19628 | printf ("%#x", (unsigned int) byte_get (ptr, 4)); | |
19629 | goto next; | |
19630 | } | |
9ef920e9 NC |
19631 | break; |
19632 | } | |
9ef920e9 NC |
19633 | } |
19634 | ||
1fc87489 L |
19635 | if (type < GNU_PROPERTY_LOPROC) |
19636 | printf (_("<unknown type %#x data: "), type); | |
19637 | else if (type < GNU_PROPERTY_LOUSER) | |
8c3853d9 | 19638 | printf (_("<processor-specific type %#x data: "), type); |
1fc87489 L |
19639 | else |
19640 | printf (_("<application-specific type %#x data: "), type); | |
19641 | for (j = 0; j < datasz; ++j) | |
19642 | printf ("%02x ", ptr[j] & 0xff); | |
19643 | printf (">"); | |
19644 | ||
dc1e8a47 | 19645 | next: |
9ef920e9 | 19646 | ptr += ((datasz + (size - 1)) & ~ (size - 1)); |
1fc87489 L |
19647 | if (ptr == ptr_end) |
19648 | break; | |
1fc87489 | 19649 | |
6ab2c4ed MC |
19650 | if (do_wide) |
19651 | printf (", "); | |
19652 | else | |
19653 | printf ("\n\t"); | |
9ef920e9 NC |
19654 | } |
19655 | ||
19656 | printf ("\n"); | |
19657 | } | |
19658 | ||
015dc7e1 | 19659 | static bool |
dda8d76d | 19660 | print_gnu_note (Filedata * filedata, Elf_Internal_Note *pnote) |
664f90a3 | 19661 | { |
1449284b | 19662 | /* NB/ Keep this switch statement in sync with get_gnu_elf_note_type (). */ |
664f90a3 TT |
19663 | switch (pnote->type) |
19664 | { | |
19665 | case NT_GNU_BUILD_ID: | |
19666 | { | |
19667 | unsigned long i; | |
19668 | ||
19669 | printf (_(" Build ID: ")); | |
19670 | for (i = 0; i < pnote->descsz; ++i) | |
19671 | printf ("%02x", pnote->descdata[i] & 0xff); | |
9cf03b7e | 19672 | printf ("\n"); |
664f90a3 TT |
19673 | } |
19674 | break; | |
19675 | ||
19676 | case NT_GNU_ABI_TAG: | |
19677 | { | |
19678 | unsigned long os, major, minor, subminor; | |
19679 | const char *osname; | |
19680 | ||
3102e897 NC |
19681 | /* PR 17531: file: 030-599401-0.004. */ |
19682 | if (pnote->descsz < 16) | |
19683 | { | |
19684 | printf (_(" <corrupt GNU_ABI_TAG>\n")); | |
19685 | break; | |
19686 | } | |
19687 | ||
664f90a3 TT |
19688 | os = byte_get ((unsigned char *) pnote->descdata, 4); |
19689 | major = byte_get ((unsigned char *) pnote->descdata + 4, 4); | |
19690 | minor = byte_get ((unsigned char *) pnote->descdata + 8, 4); | |
19691 | subminor = byte_get ((unsigned char *) pnote->descdata + 12, 4); | |
19692 | ||
19693 | switch (os) | |
19694 | { | |
19695 | case GNU_ABI_TAG_LINUX: | |
19696 | osname = "Linux"; | |
19697 | break; | |
19698 | case GNU_ABI_TAG_HURD: | |
19699 | osname = "Hurd"; | |
19700 | break; | |
19701 | case GNU_ABI_TAG_SOLARIS: | |
19702 | osname = "Solaris"; | |
19703 | break; | |
19704 | case GNU_ABI_TAG_FREEBSD: | |
19705 | osname = "FreeBSD"; | |
19706 | break; | |
19707 | case GNU_ABI_TAG_NETBSD: | |
19708 | osname = "NetBSD"; | |
19709 | break; | |
14ae95f2 RM |
19710 | case GNU_ABI_TAG_SYLLABLE: |
19711 | osname = "Syllable"; | |
19712 | break; | |
19713 | case GNU_ABI_TAG_NACL: | |
19714 | osname = "NaCl"; | |
19715 | break; | |
664f90a3 TT |
19716 | default: |
19717 | osname = "Unknown"; | |
19718 | break; | |
19719 | } | |
19720 | ||
19721 | printf (_(" OS: %s, ABI: %ld.%ld.%ld\n"), osname, | |
19722 | major, minor, subminor); | |
19723 | } | |
19724 | break; | |
926c5385 CC |
19725 | |
19726 | case NT_GNU_GOLD_VERSION: | |
19727 | { | |
19728 | unsigned long i; | |
19729 | ||
19730 | printf (_(" Version: ")); | |
19731 | for (i = 0; i < pnote->descsz && pnote->descdata[i] != '\0'; ++i) | |
19732 | printf ("%c", pnote->descdata[i]); | |
19733 | printf ("\n"); | |
19734 | } | |
19735 | break; | |
1449284b NC |
19736 | |
19737 | case NT_GNU_HWCAP: | |
19738 | { | |
19739 | unsigned long num_entries, mask; | |
19740 | ||
19741 | /* Hardware capabilities information. Word 0 is the number of entries. | |
19742 | Word 1 is a bitmask of enabled entries. The rest of the descriptor | |
19743 | is a series of entries, where each entry is a single byte followed | |
19744 | by a nul terminated string. The byte gives the bit number to test | |
19745 | if enabled in the bitmask. */ | |
19746 | printf (_(" Hardware Capabilities: ")); | |
19747 | if (pnote->descsz < 8) | |
19748 | { | |
32ec8896 | 19749 | error (_("<corrupt GNU_HWCAP>\n")); |
015dc7e1 | 19750 | return false; |
1449284b NC |
19751 | } |
19752 | num_entries = byte_get ((unsigned char *) pnote->descdata, 4); | |
19753 | mask = byte_get ((unsigned char *) pnote->descdata + 4, 4); | |
19754 | printf (_("num entries: %ld, enabled mask: %lx\n"), num_entries, mask); | |
19755 | /* FIXME: Add code to display the entries... */ | |
19756 | } | |
19757 | break; | |
19758 | ||
9ef920e9 | 19759 | case NT_GNU_PROPERTY_TYPE_0: |
dda8d76d | 19760 | print_gnu_property_note (filedata, pnote); |
9ef920e9 | 19761 | break; |
9abca702 | 19762 | |
1449284b NC |
19763 | default: |
19764 | /* Handle unrecognised types. An error message should have already been | |
19765 | created by get_gnu_elf_note_type(), so all that we need to do is to | |
19766 | display the data. */ | |
19767 | { | |
19768 | unsigned long i; | |
19769 | ||
19770 | printf (_(" Description data: ")); | |
19771 | for (i = 0; i < pnote->descsz; ++i) | |
19772 | printf ("%02x ", pnote->descdata[i] & 0xff); | |
19773 | printf ("\n"); | |
19774 | } | |
19775 | break; | |
664f90a3 TT |
19776 | } |
19777 | ||
015dc7e1 | 19778 | return true; |
664f90a3 TT |
19779 | } |
19780 | ||
685080f2 NC |
19781 | static const char * |
19782 | get_v850_elf_note_type (enum v850_notes n_type) | |
19783 | { | |
19784 | static char buff[64]; | |
19785 | ||
19786 | switch (n_type) | |
19787 | { | |
19788 | case V850_NOTE_ALIGNMENT: return _("Alignment of 8-byte objects"); | |
19789 | case V850_NOTE_DATA_SIZE: return _("Sizeof double and long double"); | |
19790 | case V850_NOTE_FPU_INFO: return _("Type of FPU support needed"); | |
19791 | case V850_NOTE_SIMD_INFO: return _("Use of SIMD instructions"); | |
19792 | case V850_NOTE_CACHE_INFO: return _("Use of cache"); | |
19793 | case V850_NOTE_MMU_INFO: return _("Use of MMU"); | |
19794 | default: | |
19795 | snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), n_type); | |
19796 | return buff; | |
19797 | } | |
19798 | } | |
19799 | ||
015dc7e1 | 19800 | static bool |
685080f2 NC |
19801 | print_v850_note (Elf_Internal_Note * pnote) |
19802 | { | |
19803 | unsigned int val; | |
19804 | ||
19805 | if (pnote->descsz != 4) | |
015dc7e1 | 19806 | return false; |
32ec8896 | 19807 | |
685080f2 NC |
19808 | val = byte_get ((unsigned char *) pnote->descdata, pnote->descsz); |
19809 | ||
19810 | if (val == 0) | |
19811 | { | |
19812 | printf (_("not set\n")); | |
015dc7e1 | 19813 | return true; |
685080f2 NC |
19814 | } |
19815 | ||
19816 | switch (pnote->type) | |
19817 | { | |
19818 | case V850_NOTE_ALIGNMENT: | |
19819 | switch (val) | |
19820 | { | |
015dc7e1 AM |
19821 | case EF_RH850_DATA_ALIGN4: printf (_("4-byte\n")); return true; |
19822 | case EF_RH850_DATA_ALIGN8: printf (_("8-byte\n")); return true; | |
685080f2 NC |
19823 | } |
19824 | break; | |
14ae95f2 | 19825 | |
685080f2 NC |
19826 | case V850_NOTE_DATA_SIZE: |
19827 | switch (val) | |
19828 | { | |
015dc7e1 AM |
19829 | case EF_RH850_DOUBLE32: printf (_("4-bytes\n")); return true; |
19830 | case EF_RH850_DOUBLE64: printf (_("8-bytes\n")); return true; | |
685080f2 NC |
19831 | } |
19832 | break; | |
14ae95f2 | 19833 | |
685080f2 NC |
19834 | case V850_NOTE_FPU_INFO: |
19835 | switch (val) | |
19836 | { | |
015dc7e1 AM |
19837 | case EF_RH850_FPU20: printf (_("FPU-2.0\n")); return true; |
19838 | case EF_RH850_FPU30: printf (_("FPU-3.0\n")); return true; | |
685080f2 NC |
19839 | } |
19840 | break; | |
14ae95f2 | 19841 | |
685080f2 NC |
19842 | case V850_NOTE_MMU_INFO: |
19843 | case V850_NOTE_CACHE_INFO: | |
19844 | case V850_NOTE_SIMD_INFO: | |
19845 | if (val == EF_RH850_SIMD) | |
19846 | { | |
19847 | printf (_("yes\n")); | |
015dc7e1 | 19848 | return true; |
685080f2 NC |
19849 | } |
19850 | break; | |
19851 | ||
19852 | default: | |
19853 | /* An 'unknown note type' message will already have been displayed. */ | |
19854 | break; | |
19855 | } | |
19856 | ||
19857 | printf (_("unknown value: %x\n"), val); | |
015dc7e1 | 19858 | return false; |
685080f2 NC |
19859 | } |
19860 | ||
015dc7e1 | 19861 | static bool |
c6056a74 SF |
19862 | process_netbsd_elf_note (Elf_Internal_Note * pnote) |
19863 | { | |
19864 | unsigned int version; | |
19865 | ||
19866 | switch (pnote->type) | |
19867 | { | |
19868 | case NT_NETBSD_IDENT: | |
b966f55f AM |
19869 | if (pnote->descsz < 1) |
19870 | break; | |
c6056a74 SF |
19871 | version = byte_get ((unsigned char *) pnote->descdata, sizeof (version)); |
19872 | if ((version / 10000) % 100) | |
b966f55f | 19873 | printf (" NetBSD\t\t0x%08lx\tIDENT %u (%u.%u%s%c)\n", pnote->descsz, |
c6056a74 SF |
19874 | version, version / 100000000, (version / 1000000) % 100, |
19875 | (version / 10000) % 100 > 26 ? "Z" : "", | |
15f205b1 | 19876 | 'A' + (version / 10000) % 26); |
c6056a74 SF |
19877 | else |
19878 | printf (" NetBSD\t\t0x%08lx\tIDENT %u (%u.%u.%u)\n", pnote->descsz, | |
b966f55f | 19879 | version, version / 100000000, (version / 1000000) % 100, |
15f205b1 | 19880 | (version / 100) % 100); |
015dc7e1 | 19881 | return true; |
c6056a74 SF |
19882 | |
19883 | case NT_NETBSD_MARCH: | |
9abca702 | 19884 | printf (" NetBSD\t\t0x%08lx\tMARCH <%s>\n", pnote->descsz, |
c6056a74 | 19885 | pnote->descdata); |
015dc7e1 | 19886 | return true; |
c6056a74 | 19887 | |
9abca702 | 19888 | case NT_NETBSD_PAX: |
b966f55f AM |
19889 | if (pnote->descsz < 1) |
19890 | break; | |
9abca702 CZ |
19891 | version = byte_get ((unsigned char *) pnote->descdata, sizeof (version)); |
19892 | printf (" NetBSD\t\t0x%08lx\tPaX <%s%s%s%s%s%s>\n", pnote->descsz, | |
19893 | ((version & NT_NETBSD_PAX_MPROTECT) ? "+mprotect" : ""), | |
19894 | ((version & NT_NETBSD_PAX_NOMPROTECT) ? "-mprotect" : ""), | |
19895 | ((version & NT_NETBSD_PAX_GUARD) ? "+guard" : ""), | |
19896 | ((version & NT_NETBSD_PAX_NOGUARD) ? "-guard" : ""), | |
19897 | ((version & NT_NETBSD_PAX_ASLR) ? "+ASLR" : ""), | |
19898 | ((version & NT_NETBSD_PAX_NOASLR) ? "-ASLR" : "")); | |
015dc7e1 | 19899 | return true; |
c6056a74 | 19900 | } |
b966f55f AM |
19901 | |
19902 | printf (" NetBSD\t0x%08lx\tUnknown note type: (0x%08lx)\n", | |
19903 | pnote->descsz, pnote->type); | |
015dc7e1 | 19904 | return false; |
c6056a74 SF |
19905 | } |
19906 | ||
f4ddf30f | 19907 | static const char * |
dda8d76d | 19908 | get_freebsd_elfcore_note_type (Filedata * filedata, unsigned e_type) |
f4ddf30f | 19909 | { |
f4ddf30f JB |
19910 | switch (e_type) |
19911 | { | |
19912 | case NT_FREEBSD_THRMISC: | |
19913 | return _("NT_THRMISC (thrmisc structure)"); | |
19914 | case NT_FREEBSD_PROCSTAT_PROC: | |
19915 | return _("NT_PROCSTAT_PROC (proc data)"); | |
19916 | case NT_FREEBSD_PROCSTAT_FILES: | |
19917 | return _("NT_PROCSTAT_FILES (files data)"); | |
19918 | case NT_FREEBSD_PROCSTAT_VMMAP: | |
19919 | return _("NT_PROCSTAT_VMMAP (vmmap data)"); | |
19920 | case NT_FREEBSD_PROCSTAT_GROUPS: | |
19921 | return _("NT_PROCSTAT_GROUPS (groups data)"); | |
19922 | case NT_FREEBSD_PROCSTAT_UMASK: | |
19923 | return _("NT_PROCSTAT_UMASK (umask data)"); | |
19924 | case NT_FREEBSD_PROCSTAT_RLIMIT: | |
19925 | return _("NT_PROCSTAT_RLIMIT (rlimit data)"); | |
19926 | case NT_FREEBSD_PROCSTAT_OSREL: | |
19927 | return _("NT_PROCSTAT_OSREL (osreldate data)"); | |
19928 | case NT_FREEBSD_PROCSTAT_PSSTRINGS: | |
19929 | return _("NT_PROCSTAT_PSSTRINGS (ps_strings data)"); | |
19930 | case NT_FREEBSD_PROCSTAT_AUXV: | |
19931 | return _("NT_PROCSTAT_AUXV (auxv data)"); | |
0b9305ed JB |
19932 | case NT_FREEBSD_PTLWPINFO: |
19933 | return _("NT_PTLWPINFO (ptrace_lwpinfo structure)"); | |
f4ddf30f | 19934 | } |
dda8d76d | 19935 | return get_note_type (filedata, e_type); |
f4ddf30f JB |
19936 | } |
19937 | ||
9437c45b | 19938 | static const char * |
dda8d76d | 19939 | get_netbsd_elfcore_note_type (Filedata * filedata, unsigned e_type) |
9437c45b JT |
19940 | { |
19941 | static char buff[64]; | |
19942 | ||
540e6170 CZ |
19943 | switch (e_type) |
19944 | { | |
19945 | case NT_NETBSDCORE_PROCINFO: | |
19946 | /* NetBSD core "procinfo" structure. */ | |
19947 | return _("NetBSD procinfo structure"); | |
9437c45b | 19948 | |
540e6170 CZ |
19949 | case NT_NETBSDCORE_AUXV: |
19950 | return _("NetBSD ELF auxiliary vector data"); | |
9437c45b | 19951 | |
06d949ec KR |
19952 | case NT_NETBSDCORE_LWPSTATUS: |
19953 | return _("PT_LWPSTATUS (ptrace_lwpstatus structure)"); | |
06d949ec | 19954 | |
540e6170 | 19955 | default: |
06d949ec | 19956 | /* As of Jan 2020 there are no other machine-independent notes |
540e6170 CZ |
19957 | defined for NetBSD core files. If the note type is less |
19958 | than the start of the machine-dependent note types, we don't | |
19959 | understand it. */ | |
19960 | ||
19961 | if (e_type < NT_NETBSDCORE_FIRSTMACH) | |
19962 | { | |
19963 | snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type); | |
19964 | return buff; | |
19965 | } | |
19966 | break; | |
9437c45b JT |
19967 | } |
19968 | ||
dda8d76d | 19969 | switch (filedata->file_header.e_machine) |
9437c45b JT |
19970 | { |
19971 | /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0 | |
19972 | and PT_GETFPREGS == mach+2. */ | |
19973 | ||
19974 | case EM_OLD_ALPHA: | |
19975 | case EM_ALPHA: | |
19976 | case EM_SPARC: | |
19977 | case EM_SPARC32PLUS: | |
19978 | case EM_SPARCV9: | |
19979 | switch (e_type) | |
19980 | { | |
2b692964 | 19981 | case NT_NETBSDCORE_FIRSTMACH + 0: |
b4db1224 | 19982 | return _("PT_GETREGS (reg structure)"); |
2b692964 | 19983 | case NT_NETBSDCORE_FIRSTMACH + 2: |
b4db1224 | 19984 | return _("PT_GETFPREGS (fpreg structure)"); |
9437c45b JT |
19985 | default: |
19986 | break; | |
19987 | } | |
19988 | break; | |
19989 | ||
c0d38b0e CZ |
19990 | /* On SuperH, PT_GETREGS == mach+3 and PT_GETFPREGS == mach+5. |
19991 | There's also old PT___GETREGS40 == mach + 1 for old reg | |
19992 | structure which lacks GBR. */ | |
19993 | case EM_SH: | |
19994 | switch (e_type) | |
19995 | { | |
19996 | case NT_NETBSDCORE_FIRSTMACH + 1: | |
19997 | return _("PT___GETREGS40 (old reg structure)"); | |
19998 | case NT_NETBSDCORE_FIRSTMACH + 3: | |
19999 | return _("PT_GETREGS (reg structure)"); | |
20000 | case NT_NETBSDCORE_FIRSTMACH + 5: | |
20001 | return _("PT_GETFPREGS (fpreg structure)"); | |
20002 | default: | |
20003 | break; | |
20004 | } | |
20005 | break; | |
20006 | ||
9437c45b JT |
20007 | /* On all other arch's, PT_GETREGS == mach+1 and |
20008 | PT_GETFPREGS == mach+3. */ | |
20009 | default: | |
20010 | switch (e_type) | |
20011 | { | |
2b692964 | 20012 | case NT_NETBSDCORE_FIRSTMACH + 1: |
b4db1224 | 20013 | return _("PT_GETREGS (reg structure)"); |
2b692964 | 20014 | case NT_NETBSDCORE_FIRSTMACH + 3: |
b4db1224 | 20015 | return _("PT_GETFPREGS (fpreg structure)"); |
9437c45b JT |
20016 | default: |
20017 | break; | |
20018 | } | |
20019 | } | |
20020 | ||
9cf03b7e | 20021 | snprintf (buff, sizeof (buff), "PT_FIRSTMACH+%d", |
e9e44622 | 20022 | e_type - NT_NETBSDCORE_FIRSTMACH); |
9437c45b JT |
20023 | return buff; |
20024 | } | |
20025 | ||
98ca73af FC |
20026 | static const char * |
20027 | get_openbsd_elfcore_note_type (Filedata * filedata, unsigned e_type) | |
20028 | { | |
20029 | switch (e_type) | |
20030 | { | |
20031 | case NT_OPENBSD_PROCINFO: | |
20032 | return _("OpenBSD procinfo structure"); | |
20033 | case NT_OPENBSD_AUXV: | |
20034 | return _("OpenBSD ELF auxiliary vector data"); | |
20035 | case NT_OPENBSD_REGS: | |
20036 | return _("OpenBSD regular registers"); | |
20037 | case NT_OPENBSD_FPREGS: | |
20038 | return _("OpenBSD floating point registers"); | |
20039 | case NT_OPENBSD_WCOOKIE: | |
20040 | return _("OpenBSD window cookie"); | |
20041 | } | |
20042 | ||
20043 | return get_note_type (filedata, e_type); | |
20044 | } | |
20045 | ||
70616151 TT |
20046 | static const char * |
20047 | get_stapsdt_note_type (unsigned e_type) | |
20048 | { | |
20049 | static char buff[64]; | |
20050 | ||
20051 | switch (e_type) | |
20052 | { | |
20053 | case NT_STAPSDT: | |
20054 | return _("NT_STAPSDT (SystemTap probe descriptors)"); | |
20055 | ||
20056 | default: | |
20057 | break; | |
20058 | } | |
20059 | ||
20060 | snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type); | |
20061 | return buff; | |
20062 | } | |
20063 | ||
015dc7e1 | 20064 | static bool |
c6a9fc58 TT |
20065 | print_stapsdt_note (Elf_Internal_Note *pnote) |
20066 | { | |
3ca60c57 NC |
20067 | size_t len, maxlen; |
20068 | unsigned long addr_size = is_32bit_elf ? 4 : 8; | |
c6a9fc58 TT |
20069 | char *data = pnote->descdata; |
20070 | char *data_end = pnote->descdata + pnote->descsz; | |
20071 | bfd_vma pc, base_addr, semaphore; | |
20072 | char *provider, *probe, *arg_fmt; | |
20073 | ||
3ca60c57 NC |
20074 | if (pnote->descsz < (addr_size * 3)) |
20075 | goto stapdt_note_too_small; | |
20076 | ||
c6a9fc58 TT |
20077 | pc = byte_get ((unsigned char *) data, addr_size); |
20078 | data += addr_size; | |
3ca60c57 | 20079 | |
c6a9fc58 TT |
20080 | base_addr = byte_get ((unsigned char *) data, addr_size); |
20081 | data += addr_size; | |
3ca60c57 | 20082 | |
c6a9fc58 TT |
20083 | semaphore = byte_get ((unsigned char *) data, addr_size); |
20084 | data += addr_size; | |
20085 | ||
3ca60c57 NC |
20086 | if (data >= data_end) |
20087 | goto stapdt_note_too_small; | |
20088 | maxlen = data_end - data; | |
20089 | len = strnlen (data, maxlen); | |
20090 | if (len < maxlen) | |
20091 | { | |
20092 | provider = data; | |
20093 | data += len + 1; | |
20094 | } | |
20095 | else | |
20096 | goto stapdt_note_too_small; | |
20097 | ||
20098 | if (data >= data_end) | |
20099 | goto stapdt_note_too_small; | |
20100 | maxlen = data_end - data; | |
20101 | len = strnlen (data, maxlen); | |
20102 | if (len < maxlen) | |
20103 | { | |
20104 | probe = data; | |
20105 | data += len + 1; | |
20106 | } | |
20107 | else | |
20108 | goto stapdt_note_too_small; | |
9abca702 | 20109 | |
3ca60c57 NC |
20110 | if (data >= data_end) |
20111 | goto stapdt_note_too_small; | |
20112 | maxlen = data_end - data; | |
20113 | len = strnlen (data, maxlen); | |
20114 | if (len < maxlen) | |
20115 | { | |
20116 | arg_fmt = data; | |
20117 | data += len + 1; | |
20118 | } | |
20119 | else | |
20120 | goto stapdt_note_too_small; | |
c6a9fc58 TT |
20121 | |
20122 | printf (_(" Provider: %s\n"), provider); | |
20123 | printf (_(" Name: %s\n"), probe); | |
20124 | printf (_(" Location: ")); | |
20125 | print_vma (pc, FULL_HEX); | |
20126 | printf (_(", Base: ")); | |
20127 | print_vma (base_addr, FULL_HEX); | |
20128 | printf (_(", Semaphore: ")); | |
20129 | print_vma (semaphore, FULL_HEX); | |
9cf03b7e | 20130 | printf ("\n"); |
c6a9fc58 TT |
20131 | printf (_(" Arguments: %s\n"), arg_fmt); |
20132 | ||
20133 | return data == data_end; | |
3ca60c57 NC |
20134 | |
20135 | stapdt_note_too_small: | |
20136 | printf (_(" <corrupt - note is too small>\n")); | |
20137 | error (_("corrupt stapdt note - the data size is too small\n")); | |
015dc7e1 | 20138 | return false; |
c6a9fc58 TT |
20139 | } |
20140 | ||
00e98fc7 TG |
20141 | static const char * |
20142 | get_ia64_vms_note_type (unsigned e_type) | |
20143 | { | |
20144 | static char buff[64]; | |
20145 | ||
20146 | switch (e_type) | |
20147 | { | |
20148 | case NT_VMS_MHD: | |
20149 | return _("NT_VMS_MHD (module header)"); | |
20150 | case NT_VMS_LNM: | |
20151 | return _("NT_VMS_LNM (language name)"); | |
20152 | case NT_VMS_SRC: | |
20153 | return _("NT_VMS_SRC (source files)"); | |
20154 | case NT_VMS_TITLE: | |
9cf03b7e | 20155 | return "NT_VMS_TITLE"; |
00e98fc7 TG |
20156 | case NT_VMS_EIDC: |
20157 | return _("NT_VMS_EIDC (consistency check)"); | |
20158 | case NT_VMS_FPMODE: | |
20159 | return _("NT_VMS_FPMODE (FP mode)"); | |
20160 | case NT_VMS_LINKTIME: | |
9cf03b7e | 20161 | return "NT_VMS_LINKTIME"; |
00e98fc7 TG |
20162 | case NT_VMS_IMGNAM: |
20163 | return _("NT_VMS_IMGNAM (image name)"); | |
20164 | case NT_VMS_IMGID: | |
20165 | return _("NT_VMS_IMGID (image id)"); | |
20166 | case NT_VMS_LINKID: | |
20167 | return _("NT_VMS_LINKID (link id)"); | |
20168 | case NT_VMS_IMGBID: | |
20169 | return _("NT_VMS_IMGBID (build id)"); | |
20170 | case NT_VMS_GSTNAM: | |
20171 | return _("NT_VMS_GSTNAM (sym table name)"); | |
20172 | case NT_VMS_ORIG_DYN: | |
9cf03b7e | 20173 | return "NT_VMS_ORIG_DYN"; |
00e98fc7 | 20174 | case NT_VMS_PATCHTIME: |
9cf03b7e | 20175 | return "NT_VMS_PATCHTIME"; |
00e98fc7 TG |
20176 | default: |
20177 | snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type); | |
20178 | return buff; | |
20179 | } | |
20180 | } | |
20181 | ||
015dc7e1 | 20182 | static bool |
00e98fc7 TG |
20183 | print_ia64_vms_note (Elf_Internal_Note * pnote) |
20184 | { | |
8d18bf79 NC |
20185 | int maxlen = pnote->descsz; |
20186 | ||
20187 | if (maxlen < 2 || (unsigned long) maxlen != pnote->descsz) | |
20188 | goto desc_size_fail; | |
20189 | ||
00e98fc7 TG |
20190 | switch (pnote->type) |
20191 | { | |
20192 | case NT_VMS_MHD: | |
8d18bf79 NC |
20193 | if (maxlen <= 36) |
20194 | goto desc_size_fail; | |
20195 | ||
20196 | int l = (int) strnlen (pnote->descdata + 34, maxlen - 34); | |
20197 | ||
20198 | printf (_(" Creation date : %.17s\n"), pnote->descdata); | |
20199 | printf (_(" Last patch date: %.17s\n"), pnote->descdata + 17); | |
20200 | if (l + 34 < maxlen) | |
20201 | { | |
20202 | printf (_(" Module name : %s\n"), pnote->descdata + 34); | |
20203 | if (l + 35 < maxlen) | |
20204 | printf (_(" Module version : %s\n"), pnote->descdata + 34 + l + 1); | |
20205 | else | |
20206 | printf (_(" Module version : <missing>\n")); | |
20207 | } | |
00e98fc7 | 20208 | else |
8d18bf79 NC |
20209 | { |
20210 | printf (_(" Module name : <missing>\n")); | |
20211 | printf (_(" Module version : <missing>\n")); | |
20212 | } | |
00e98fc7 | 20213 | break; |
8d18bf79 | 20214 | |
00e98fc7 | 20215 | case NT_VMS_LNM: |
8d18bf79 | 20216 | printf (_(" Language: %.*s\n"), maxlen, pnote->descdata); |
00e98fc7 | 20217 | break; |
8d18bf79 | 20218 | |
00e98fc7 TG |
20219 | #ifdef BFD64 |
20220 | case NT_VMS_FPMODE: | |
9cf03b7e | 20221 | printf (_(" Floating Point mode: ")); |
8d18bf79 NC |
20222 | if (maxlen < 8) |
20223 | goto desc_size_fail; | |
20224 | /* FIXME: Generate an error if descsz > 8 ? */ | |
20225 | ||
4a5cb34f | 20226 | printf ("0x%016" BFD_VMA_FMT "x\n", |
8d18bf79 | 20227 | (bfd_vma) byte_get ((unsigned char *)pnote->descdata, 8)); |
00e98fc7 | 20228 | break; |
8d18bf79 | 20229 | |
00e98fc7 TG |
20230 | case NT_VMS_LINKTIME: |
20231 | printf (_(" Link time: ")); | |
8d18bf79 NC |
20232 | if (maxlen < 8) |
20233 | goto desc_size_fail; | |
20234 | /* FIXME: Generate an error if descsz > 8 ? */ | |
20235 | ||
00e98fc7 | 20236 | print_vms_time |
8d18bf79 | 20237 | ((bfd_int64_t) byte_get ((unsigned char *)pnote->descdata, 8)); |
00e98fc7 TG |
20238 | printf ("\n"); |
20239 | break; | |
8d18bf79 | 20240 | |
00e98fc7 TG |
20241 | case NT_VMS_PATCHTIME: |
20242 | printf (_(" Patch time: ")); | |
8d18bf79 NC |
20243 | if (maxlen < 8) |
20244 | goto desc_size_fail; | |
20245 | /* FIXME: Generate an error if descsz > 8 ? */ | |
20246 | ||
00e98fc7 | 20247 | print_vms_time |
8d18bf79 | 20248 | ((bfd_int64_t) byte_get ((unsigned char *)pnote->descdata, 8)); |
00e98fc7 TG |
20249 | printf ("\n"); |
20250 | break; | |
8d18bf79 | 20251 | |
00e98fc7 | 20252 | case NT_VMS_ORIG_DYN: |
8d18bf79 NC |
20253 | if (maxlen < 34) |
20254 | goto desc_size_fail; | |
20255 | ||
00e98fc7 TG |
20256 | printf (_(" Major id: %u, minor id: %u\n"), |
20257 | (unsigned) byte_get ((unsigned char *)pnote->descdata, 4), | |
20258 | (unsigned) byte_get ((unsigned char *)pnote->descdata + 4, 4)); | |
9cf03b7e | 20259 | printf (_(" Last modified : ")); |
00e98fc7 TG |
20260 | print_vms_time |
20261 | ((bfd_int64_t) byte_get ((unsigned char *)pnote->descdata + 8, 8)); | |
9cf03b7e | 20262 | printf (_("\n Link flags : ")); |
4a5cb34f | 20263 | printf ("0x%016" BFD_VMA_FMT "x\n", |
948f632f | 20264 | (bfd_vma) byte_get ((unsigned char *)pnote->descdata + 16, 8)); |
00e98fc7 | 20265 | printf (_(" Header flags: 0x%08x\n"), |
948f632f | 20266 | (unsigned) byte_get ((unsigned char *)pnote->descdata + 24, 4)); |
8d18bf79 | 20267 | printf (_(" Image id : %.*s\n"), maxlen - 32, pnote->descdata + 32); |
00e98fc7 TG |
20268 | break; |
20269 | #endif | |
8d18bf79 | 20270 | |
00e98fc7 | 20271 | case NT_VMS_IMGNAM: |
8d18bf79 | 20272 | printf (_(" Image name: %.*s\n"), maxlen, pnote->descdata); |
00e98fc7 | 20273 | break; |
8d18bf79 | 20274 | |
00e98fc7 | 20275 | case NT_VMS_GSTNAM: |
8d18bf79 | 20276 | printf (_(" Global symbol table name: %.*s\n"), maxlen, pnote->descdata); |
00e98fc7 | 20277 | break; |
8d18bf79 | 20278 | |
00e98fc7 | 20279 | case NT_VMS_IMGID: |
8d18bf79 | 20280 | printf (_(" Image id: %.*s\n"), maxlen, pnote->descdata); |
00e98fc7 | 20281 | break; |
8d18bf79 | 20282 | |
00e98fc7 | 20283 | case NT_VMS_LINKID: |
8d18bf79 | 20284 | printf (_(" Linker id: %.*s\n"), maxlen, pnote->descdata); |
00e98fc7 | 20285 | break; |
8d18bf79 | 20286 | |
00e98fc7 | 20287 | default: |
015dc7e1 | 20288 | return false; |
00e98fc7 | 20289 | } |
8d18bf79 | 20290 | |
015dc7e1 | 20291 | return true; |
8d18bf79 NC |
20292 | |
20293 | desc_size_fail: | |
20294 | printf (_(" <corrupt - data size is too small>\n")); | |
20295 | error (_("corrupt IA64 note: data size is too small\n")); | |
015dc7e1 | 20296 | return false; |
00e98fc7 TG |
20297 | } |
20298 | ||
fd486f32 AM |
20299 | struct build_attr_cache { |
20300 | Filedata *filedata; | |
20301 | char *strtab; | |
20302 | unsigned long strtablen; | |
20303 | Elf_Internal_Sym *symtab; | |
20304 | unsigned long nsyms; | |
20305 | } ba_cache; | |
20306 | ||
6f156d7a NC |
20307 | /* Find the symbol associated with a build attribute that is attached |
20308 | to address OFFSET. If PNAME is non-NULL then store the name of | |
20309 | the symbol (if found) in the provided pointer, Returns NULL if a | |
20310 | symbol could not be found. */ | |
c799a79d | 20311 | |
6f156d7a | 20312 | static Elf_Internal_Sym * |
015dc7e1 AM |
20313 | get_symbol_for_build_attribute (Filedata *filedata, |
20314 | unsigned long offset, | |
20315 | bool is_open_attr, | |
20316 | const char **pname) | |
9ef920e9 | 20317 | { |
fd486f32 AM |
20318 | Elf_Internal_Sym *saved_sym = NULL; |
20319 | Elf_Internal_Sym *sym; | |
9ef920e9 | 20320 | |
dda8d76d | 20321 | if (filedata->section_headers != NULL |
fd486f32 | 20322 | && (ba_cache.filedata == NULL || filedata != ba_cache.filedata)) |
9ef920e9 | 20323 | { |
c799a79d | 20324 | Elf_Internal_Shdr * symsec; |
9ef920e9 | 20325 | |
fd486f32 AM |
20326 | free (ba_cache.strtab); |
20327 | ba_cache.strtab = NULL; | |
20328 | free (ba_cache.symtab); | |
20329 | ba_cache.symtab = NULL; | |
20330 | ||
c799a79d | 20331 | /* Load the symbol and string sections. */ |
dda8d76d NC |
20332 | for (symsec = filedata->section_headers; |
20333 | symsec < filedata->section_headers + filedata->file_header.e_shnum; | |
c799a79d | 20334 | symsec ++) |
9ef920e9 | 20335 | { |
28d13567 AM |
20336 | if (symsec->sh_type == SHT_SYMTAB |
20337 | && get_symtab (filedata, symsec, | |
20338 | &ba_cache.symtab, &ba_cache.nsyms, | |
20339 | &ba_cache.strtab, &ba_cache.strtablen)) | |
20340 | break; | |
9ef920e9 | 20341 | } |
fd486f32 | 20342 | ba_cache.filedata = filedata; |
9ef920e9 NC |
20343 | } |
20344 | ||
fd486f32 | 20345 | if (ba_cache.symtab == NULL) |
6f156d7a | 20346 | return NULL; |
9ef920e9 | 20347 | |
c799a79d | 20348 | /* Find a symbol whose value matches offset. */ |
fd486f32 | 20349 | for (sym = ba_cache.symtab; sym < ba_cache.symtab + ba_cache.nsyms; sym ++) |
c799a79d NC |
20350 | if (sym->st_value == offset) |
20351 | { | |
fd486f32 | 20352 | if (sym->st_name >= ba_cache.strtablen) |
c799a79d NC |
20353 | /* Huh ? This should not happen. */ |
20354 | continue; | |
9ef920e9 | 20355 | |
fd486f32 | 20356 | if (ba_cache.strtab[sym->st_name] == 0) |
c799a79d | 20357 | continue; |
9ef920e9 | 20358 | |
9b9b1092 | 20359 | /* The AArch64, ARM and RISC-V architectures define mapping symbols |
8fd75781 | 20360 | (eg $d, $x, $t) which we want to ignore. */ |
fd486f32 AM |
20361 | if (ba_cache.strtab[sym->st_name] == '$' |
20362 | && ba_cache.strtab[sym->st_name + 1] != 0 | |
20363 | && ba_cache.strtab[sym->st_name + 2] == 0) | |
8fd75781 NC |
20364 | continue; |
20365 | ||
c799a79d NC |
20366 | if (is_open_attr) |
20367 | { | |
20368 | /* For OPEN attributes we prefer GLOBAL over LOCAL symbols | |
20369 | and FILE or OBJECT symbols over NOTYPE symbols. We skip | |
20370 | FUNC symbols entirely. */ | |
20371 | switch (ELF_ST_TYPE (sym->st_info)) | |
20372 | { | |
c799a79d | 20373 | case STT_OBJECT: |
6f156d7a | 20374 | case STT_FILE: |
c799a79d | 20375 | saved_sym = sym; |
6f156d7a NC |
20376 | if (sym->st_size) |
20377 | { | |
20378 | /* If the symbol has a size associated | |
20379 | with it then we can stop searching. */ | |
fd486f32 | 20380 | sym = ba_cache.symtab + ba_cache.nsyms; |
6f156d7a | 20381 | } |
c799a79d | 20382 | continue; |
9ef920e9 | 20383 | |
c799a79d NC |
20384 | case STT_FUNC: |
20385 | /* Ignore function symbols. */ | |
20386 | continue; | |
20387 | ||
20388 | default: | |
20389 | break; | |
20390 | } | |
20391 | ||
20392 | switch (ELF_ST_BIND (sym->st_info)) | |
9ef920e9 | 20393 | { |
c799a79d NC |
20394 | case STB_GLOBAL: |
20395 | if (saved_sym == NULL | |
20396 | || ELF_ST_TYPE (saved_sym->st_info) != STT_OBJECT) | |
20397 | saved_sym = sym; | |
20398 | break; | |
c871dade | 20399 | |
c799a79d NC |
20400 | case STB_LOCAL: |
20401 | if (saved_sym == NULL) | |
20402 | saved_sym = sym; | |
20403 | break; | |
20404 | ||
20405 | default: | |
9ef920e9 NC |
20406 | break; |
20407 | } | |
20408 | } | |
c799a79d NC |
20409 | else |
20410 | { | |
20411 | if (ELF_ST_TYPE (sym->st_info) != STT_FUNC) | |
20412 | continue; | |
20413 | ||
20414 | saved_sym = sym; | |
20415 | break; | |
20416 | } | |
20417 | } | |
20418 | ||
6f156d7a | 20419 | if (saved_sym && pname) |
fd486f32 | 20420 | * pname = ba_cache.strtab + saved_sym->st_name; |
6f156d7a NC |
20421 | |
20422 | return saved_sym; | |
c799a79d NC |
20423 | } |
20424 | ||
d20e98ab NC |
20425 | /* Returns true iff addr1 and addr2 are in the same section. */ |
20426 | ||
015dc7e1 | 20427 | static bool |
d20e98ab NC |
20428 | same_section (Filedata * filedata, unsigned long addr1, unsigned long addr2) |
20429 | { | |
20430 | Elf_Internal_Shdr * a1; | |
20431 | Elf_Internal_Shdr * a2; | |
20432 | ||
20433 | a1 = find_section_by_address (filedata, addr1); | |
20434 | a2 = find_section_by_address (filedata, addr2); | |
9abca702 | 20435 | |
d20e98ab NC |
20436 | return a1 == a2 && a1 != NULL; |
20437 | } | |
20438 | ||
015dc7e1 | 20439 | static bool |
dda8d76d NC |
20440 | print_gnu_build_attribute_description (Elf_Internal_Note * pnote, |
20441 | Filedata * filedata) | |
c799a79d | 20442 | { |
015dc7e1 AM |
20443 | static unsigned long global_offset = 0; |
20444 | static unsigned long global_end = 0; | |
20445 | static unsigned long func_offset = 0; | |
20446 | static unsigned long func_end = 0; | |
c871dade | 20447 | |
015dc7e1 AM |
20448 | Elf_Internal_Sym *sym; |
20449 | const char *name; | |
20450 | unsigned long start; | |
20451 | unsigned long end; | |
20452 | bool is_open_attr = pnote->type == NT_GNU_BUILD_ATTRIBUTE_OPEN; | |
6f156d7a NC |
20453 | |
20454 | switch (pnote->descsz) | |
c799a79d | 20455 | { |
6f156d7a NC |
20456 | case 0: |
20457 | /* A zero-length description means that the range of | |
20458 | the previous note of the same type should be used. */ | |
c799a79d | 20459 | if (is_open_attr) |
c871dade | 20460 | { |
6f156d7a NC |
20461 | if (global_end > global_offset) |
20462 | printf (_(" Applies to region from %#lx to %#lx\n"), | |
20463 | global_offset, global_end); | |
20464 | else | |
20465 | printf (_(" Applies to region from %#lx\n"), global_offset); | |
c799a79d NC |
20466 | } |
20467 | else | |
20468 | { | |
6f156d7a NC |
20469 | if (func_end > func_offset) |
20470 | printf (_(" Applies to region from %#lx to %#lx\n"), func_offset, func_end); | |
20471 | else | |
20472 | printf (_(" Applies to region from %#lx\n"), func_offset); | |
c871dade | 20473 | } |
015dc7e1 | 20474 | return true; |
9ef920e9 | 20475 | |
6f156d7a NC |
20476 | case 4: |
20477 | start = byte_get ((unsigned char *) pnote->descdata, 4); | |
20478 | end = 0; | |
20479 | break; | |
20480 | ||
20481 | case 8: | |
c74147bb NC |
20482 | start = byte_get ((unsigned char *) pnote->descdata, 4); |
20483 | end = byte_get ((unsigned char *) pnote->descdata + 4, 4); | |
6f156d7a NC |
20484 | break; |
20485 | ||
20486 | case 16: | |
20487 | start = byte_get ((unsigned char *) pnote->descdata, 8); | |
20488 | end = byte_get ((unsigned char *) pnote->descdata + 8, 8); | |
20489 | break; | |
9abca702 | 20490 | |
6f156d7a | 20491 | default: |
c799a79d NC |
20492 | error (_(" <invalid description size: %lx>\n"), pnote->descsz); |
20493 | printf (_(" <invalid descsz>")); | |
015dc7e1 | 20494 | return false; |
c799a79d NC |
20495 | } |
20496 | ||
6f156d7a NC |
20497 | name = NULL; |
20498 | sym = get_symbol_for_build_attribute (filedata, start, is_open_attr, & name); | |
8fd75781 NC |
20499 | /* As of version 5 of the annobin plugin, filename symbols are biased by 2 |
20500 | in order to avoid them being confused with the start address of the | |
20501 | first function in the file... */ | |
20502 | if (sym == NULL && is_open_attr) | |
20503 | sym = get_symbol_for_build_attribute (filedata, start + 2, is_open_attr, | |
20504 | & name); | |
6f156d7a NC |
20505 | |
20506 | if (end == 0 && sym != NULL && sym->st_size > 0) | |
20507 | end = start + sym->st_size; | |
c799a79d NC |
20508 | |
20509 | if (is_open_attr) | |
20510 | { | |
d20e98ab NC |
20511 | /* FIXME: Need to properly allow for section alignment. |
20512 | 16 is just the alignment used on x86_64. */ | |
20513 | if (global_end > 0 | |
20514 | && start > BFD_ALIGN (global_end, 16) | |
20515 | /* Build notes are not guaranteed to be organised in order of | |
20516 | increasing address, but we should find the all of the notes | |
20517 | for one section in the same place. */ | |
20518 | && same_section (filedata, start, global_end)) | |
6f156d7a NC |
20519 | warn (_("Gap in build notes detected from %#lx to %#lx\n"), |
20520 | global_end + 1, start - 1); | |
20521 | ||
20522 | printf (_(" Applies to region from %#lx"), start); | |
20523 | global_offset = start; | |
20524 | ||
20525 | if (end) | |
20526 | { | |
20527 | printf (_(" to %#lx"), end); | |
20528 | global_end = end; | |
20529 | } | |
c799a79d NC |
20530 | } |
20531 | else | |
20532 | { | |
6f156d7a NC |
20533 | printf (_(" Applies to region from %#lx"), start); |
20534 | func_offset = start; | |
20535 | ||
20536 | if (end) | |
20537 | { | |
20538 | printf (_(" to %#lx"), end); | |
20539 | func_end = end; | |
20540 | } | |
c799a79d NC |
20541 | } |
20542 | ||
6f156d7a NC |
20543 | if (sym && name) |
20544 | printf (_(" (%s)"), name); | |
20545 | ||
20546 | printf ("\n"); | |
015dc7e1 | 20547 | return true; |
9ef920e9 NC |
20548 | } |
20549 | ||
015dc7e1 | 20550 | static bool |
9ef920e9 NC |
20551 | print_gnu_build_attribute_name (Elf_Internal_Note * pnote) |
20552 | { | |
1d15e434 NC |
20553 | static const char string_expected [2] = { GNU_BUILD_ATTRIBUTE_TYPE_STRING, 0 }; |
20554 | static const char number_expected [2] = { GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC, 0 }; | |
20555 | static const char bool_expected [3] = { GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE, GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE, 0 }; | |
9ef920e9 NC |
20556 | char name_type; |
20557 | char name_attribute; | |
1d15e434 | 20558 | const char * expected_types; |
9ef920e9 NC |
20559 | const char * name = pnote->namedata; |
20560 | const char * text; | |
88305e1b | 20561 | signed int left; |
9ef920e9 NC |
20562 | |
20563 | if (name == NULL || pnote->namesz < 2) | |
20564 | { | |
20565 | error (_("corrupt name field in GNU build attribute note: size = %ld\n"), pnote->namesz); | |
7296a62a | 20566 | print_symbol (-20, _(" <corrupt name>")); |
015dc7e1 | 20567 | return false; |
9ef920e9 NC |
20568 | } |
20569 | ||
6f156d7a NC |
20570 | if (do_wide) |
20571 | left = 28; | |
20572 | else | |
20573 | left = 20; | |
88305e1b NC |
20574 | |
20575 | /* Version 2 of the spec adds a "GA" prefix to the name field. */ | |
20576 | if (name[0] == 'G' && name[1] == 'A') | |
20577 | { | |
6f156d7a NC |
20578 | if (pnote->namesz < 4) |
20579 | { | |
20580 | error (_("corrupt name field in GNU build attribute note: size = %ld\n"), pnote->namesz); | |
20581 | print_symbol (-20, _(" <corrupt name>")); | |
015dc7e1 | 20582 | return false; |
6f156d7a NC |
20583 | } |
20584 | ||
88305e1b NC |
20585 | printf ("GA"); |
20586 | name += 2; | |
20587 | left -= 2; | |
20588 | } | |
20589 | ||
9ef920e9 NC |
20590 | switch ((name_type = * name)) |
20591 | { | |
20592 | case GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC: | |
20593 | case GNU_BUILD_ATTRIBUTE_TYPE_STRING: | |
20594 | case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE: | |
20595 | case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE: | |
20596 | printf ("%c", * name); | |
88305e1b | 20597 | left --; |
9ef920e9 NC |
20598 | break; |
20599 | default: | |
20600 | error (_("unrecognised attribute type in name field: %d\n"), name_type); | |
20601 | print_symbol (-20, _("<unknown name type>")); | |
015dc7e1 | 20602 | return false; |
9ef920e9 NC |
20603 | } |
20604 | ||
9ef920e9 NC |
20605 | ++ name; |
20606 | text = NULL; | |
20607 | ||
20608 | switch ((name_attribute = * name)) | |
20609 | { | |
20610 | case GNU_BUILD_ATTRIBUTE_VERSION: | |
20611 | text = _("<version>"); | |
1d15e434 | 20612 | expected_types = string_expected; |
9ef920e9 NC |
20613 | ++ name; |
20614 | break; | |
20615 | case GNU_BUILD_ATTRIBUTE_STACK_PROT: | |
20616 | text = _("<stack prot>"); | |
75d7d298 | 20617 | expected_types = "!+*"; |
9ef920e9 NC |
20618 | ++ name; |
20619 | break; | |
20620 | case GNU_BUILD_ATTRIBUTE_RELRO: | |
20621 | text = _("<relro>"); | |
1d15e434 | 20622 | expected_types = bool_expected; |
9ef920e9 NC |
20623 | ++ name; |
20624 | break; | |
20625 | case GNU_BUILD_ATTRIBUTE_STACK_SIZE: | |
20626 | text = _("<stack size>"); | |
1d15e434 | 20627 | expected_types = number_expected; |
9ef920e9 NC |
20628 | ++ name; |
20629 | break; | |
20630 | case GNU_BUILD_ATTRIBUTE_TOOL: | |
20631 | text = _("<tool>"); | |
1d15e434 | 20632 | expected_types = string_expected; |
9ef920e9 NC |
20633 | ++ name; |
20634 | break; | |
20635 | case GNU_BUILD_ATTRIBUTE_ABI: | |
20636 | text = _("<ABI>"); | |
20637 | expected_types = "$*"; | |
20638 | ++ name; | |
20639 | break; | |
20640 | case GNU_BUILD_ATTRIBUTE_PIC: | |
20641 | text = _("<PIC>"); | |
1d15e434 | 20642 | expected_types = number_expected; |
9ef920e9 NC |
20643 | ++ name; |
20644 | break; | |
a8be5506 NC |
20645 | case GNU_BUILD_ATTRIBUTE_SHORT_ENUM: |
20646 | text = _("<short enum>"); | |
1d15e434 | 20647 | expected_types = bool_expected; |
a8be5506 NC |
20648 | ++ name; |
20649 | break; | |
9ef920e9 NC |
20650 | default: |
20651 | if (ISPRINT (* name)) | |
20652 | { | |
20653 | int len = strnlen (name, pnote->namesz - (name - pnote->namedata)) + 1; | |
20654 | ||
20655 | if (len > left && ! do_wide) | |
20656 | len = left; | |
75d7d298 | 20657 | printf ("%.*s:", len, name); |
9ef920e9 | 20658 | left -= len; |
0dd6ae21 | 20659 | name += len; |
9ef920e9 NC |
20660 | } |
20661 | else | |
20662 | { | |
3e6b6445 | 20663 | static char tmpbuf [128]; |
88305e1b | 20664 | |
3e6b6445 NC |
20665 | error (_("unrecognised byte in name field: %d\n"), * name); |
20666 | sprintf (tmpbuf, _("<unknown:_%d>"), * name); | |
20667 | text = tmpbuf; | |
20668 | name ++; | |
9ef920e9 NC |
20669 | } |
20670 | expected_types = "*$!+"; | |
20671 | break; | |
20672 | } | |
20673 | ||
20674 | if (text) | |
88305e1b | 20675 | left -= printf ("%s", text); |
9ef920e9 NC |
20676 | |
20677 | if (strchr (expected_types, name_type) == NULL) | |
75d7d298 | 20678 | warn (_("attribute does not have an expected type (%c)\n"), name_type); |
9ef920e9 NC |
20679 | |
20680 | if ((unsigned long)(name - pnote->namedata) > pnote->namesz) | |
20681 | { | |
20682 | error (_("corrupt name field: namesz: %lu but parsing gets to %ld\n"), | |
20683 | (unsigned long) pnote->namesz, | |
20684 | (long) (name - pnote->namedata)); | |
015dc7e1 | 20685 | return false; |
9ef920e9 NC |
20686 | } |
20687 | ||
20688 | if (left < 1 && ! do_wide) | |
015dc7e1 | 20689 | return true; |
9ef920e9 NC |
20690 | |
20691 | switch (name_type) | |
20692 | { | |
20693 | case GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC: | |
20694 | { | |
b06b2c92 | 20695 | unsigned int bytes; |
ddef72cd NC |
20696 | unsigned long long val = 0; |
20697 | unsigned int shift = 0; | |
20698 | char * decoded = NULL; | |
20699 | ||
b06b2c92 NC |
20700 | bytes = pnote->namesz - (name - pnote->namedata); |
20701 | if (bytes > 0) | |
20702 | /* The -1 is because the name field is always 0 terminated, and we | |
20703 | want to be able to ensure that the shift in the while loop below | |
20704 | will not overflow. */ | |
20705 | -- bytes; | |
20706 | ||
ddef72cd NC |
20707 | if (bytes > sizeof (val)) |
20708 | { | |
3e6b6445 NC |
20709 | error (_("corrupt numeric name field: too many bytes in the value: %x\n"), |
20710 | bytes); | |
20711 | bytes = sizeof (val); | |
ddef72cd | 20712 | } |
3e6b6445 NC |
20713 | /* We do not bother to warn if bytes == 0 as this can |
20714 | happen with some early versions of the gcc plugin. */ | |
9ef920e9 NC |
20715 | |
20716 | while (bytes --) | |
20717 | { | |
54b8331d | 20718 | unsigned long long byte = *name++ & 0xff; |
79a964dc NC |
20719 | |
20720 | val |= byte << shift; | |
9ef920e9 NC |
20721 | shift += 8; |
20722 | } | |
20723 | ||
75d7d298 | 20724 | switch (name_attribute) |
9ef920e9 | 20725 | { |
75d7d298 | 20726 | case GNU_BUILD_ATTRIBUTE_PIC: |
9ef920e9 NC |
20727 | switch (val) |
20728 | { | |
75d7d298 NC |
20729 | case 0: decoded = "static"; break; |
20730 | case 1: decoded = "pic"; break; | |
20731 | case 2: decoded = "PIC"; break; | |
20732 | case 3: decoded = "pie"; break; | |
20733 | case 4: decoded = "PIE"; break; | |
20734 | default: break; | |
9ef920e9 | 20735 | } |
75d7d298 NC |
20736 | break; |
20737 | case GNU_BUILD_ATTRIBUTE_STACK_PROT: | |
20738 | switch (val) | |
9ef920e9 | 20739 | { |
75d7d298 NC |
20740 | /* Based upon the SPCT_FLAG_xxx enum values in gcc/cfgexpand.c. */ |
20741 | case 0: decoded = "off"; break; | |
20742 | case 1: decoded = "on"; break; | |
20743 | case 2: decoded = "all"; break; | |
20744 | case 3: decoded = "strong"; break; | |
20745 | case 4: decoded = "explicit"; break; | |
20746 | default: break; | |
9ef920e9 | 20747 | } |
75d7d298 NC |
20748 | break; |
20749 | default: | |
20750 | break; | |
9ef920e9 NC |
20751 | } |
20752 | ||
75d7d298 | 20753 | if (decoded != NULL) |
3e6b6445 NC |
20754 | { |
20755 | print_symbol (-left, decoded); | |
20756 | left = 0; | |
20757 | } | |
20758 | else if (val == 0) | |
20759 | { | |
20760 | printf ("0x0"); | |
20761 | left -= 3; | |
20762 | } | |
9ef920e9 | 20763 | else |
75d7d298 NC |
20764 | { |
20765 | if (do_wide) | |
ddef72cd | 20766 | left -= printf ("0x%llx", val); |
75d7d298 | 20767 | else |
ddef72cd | 20768 | left -= printf ("0x%-.*llx", left, val); |
75d7d298 | 20769 | } |
9ef920e9 NC |
20770 | } |
20771 | break; | |
20772 | case GNU_BUILD_ATTRIBUTE_TYPE_STRING: | |
20773 | left -= print_symbol (- left, name); | |
20774 | break; | |
20775 | case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE: | |
20776 | left -= print_symbol (- left, "true"); | |
20777 | break; | |
20778 | case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE: | |
20779 | left -= print_symbol (- left, "false"); | |
20780 | break; | |
20781 | } | |
20782 | ||
20783 | if (do_wide && left > 0) | |
20784 | printf ("%-*s", left, " "); | |
9abca702 | 20785 | |
015dc7e1 | 20786 | return true; |
9ef920e9 NC |
20787 | } |
20788 | ||
6d118b09 NC |
20789 | /* Note that by the ELF standard, the name field is already null byte |
20790 | terminated, and namesz includes the terminating null byte. | |
20791 | I.E. the value of namesz for the name "FSF" is 4. | |
20792 | ||
e3c8793a | 20793 | If the value of namesz is zero, there is no name present. */ |
9ef920e9 | 20794 | |
015dc7e1 | 20795 | static bool |
9ef920e9 | 20796 | process_note (Elf_Internal_Note * pnote, |
dda8d76d | 20797 | Filedata * filedata) |
779fe533 | 20798 | { |
2cf0635d NC |
20799 | const char * name = pnote->namesz ? pnote->namedata : "(NONE)"; |
20800 | const char * nt; | |
9437c45b JT |
20801 | |
20802 | if (pnote->namesz == 0) | |
1ec5cd37 NC |
20803 | /* If there is no note name, then use the default set of |
20804 | note type strings. */ | |
dda8d76d | 20805 | nt = get_note_type (filedata, pnote->type); |
1ec5cd37 | 20806 | |
24d127aa | 20807 | else if (startswith (pnote->namedata, "GNU")) |
1118d252 RM |
20808 | /* GNU-specific object file notes. */ |
20809 | nt = get_gnu_elf_note_type (pnote->type); | |
f4ddf30f | 20810 | |
24d127aa | 20811 | else if (startswith (pnote->namedata, "FreeBSD")) |
f4ddf30f | 20812 | /* FreeBSD-specific core file notes. */ |
dda8d76d | 20813 | nt = get_freebsd_elfcore_note_type (filedata, pnote->type); |
1118d252 | 20814 | |
24d127aa | 20815 | else if (startswith (pnote->namedata, "NetBSD-CORE")) |
1ec5cd37 | 20816 | /* NetBSD-specific core file notes. */ |
dda8d76d | 20817 | nt = get_netbsd_elfcore_note_type (filedata, pnote->type); |
1ec5cd37 | 20818 | |
24d127aa | 20819 | else if (startswith (pnote->namedata, "NetBSD")) |
c6056a74 SF |
20820 | /* NetBSD-specific core file notes. */ |
20821 | return process_netbsd_elf_note (pnote); | |
20822 | ||
24d127aa | 20823 | else if (startswith (pnote->namedata, "PaX")) |
9abca702 CZ |
20824 | /* NetBSD-specific core file notes. */ |
20825 | return process_netbsd_elf_note (pnote); | |
20826 | ||
98ca73af FC |
20827 | else if (startswith (pnote->namedata, "OpenBSD")) |
20828 | /* OpenBSD-specific core file notes. */ | |
20829 | nt = get_openbsd_elfcore_note_type (filedata, pnote->type); | |
20830 | ||
e9b095a5 | 20831 | else if (startswith (pnote->namedata, "SPU/")) |
b15fa79e AM |
20832 | { |
20833 | /* SPU-specific core file notes. */ | |
20834 | nt = pnote->namedata + 4; | |
20835 | name = "SPU"; | |
20836 | } | |
20837 | ||
24d127aa | 20838 | else if (startswith (pnote->namedata, "IPF/VMS")) |
00e98fc7 TG |
20839 | /* VMS/ia64-specific file notes. */ |
20840 | nt = get_ia64_vms_note_type (pnote->type); | |
20841 | ||
24d127aa | 20842 | else if (startswith (pnote->namedata, "stapsdt")) |
70616151 TT |
20843 | nt = get_stapsdt_note_type (pnote->type); |
20844 | ||
9437c45b | 20845 | else |
1ec5cd37 NC |
20846 | /* Don't recognize this note name; just use the default set of |
20847 | note type strings. */ | |
dda8d76d | 20848 | nt = get_note_type (filedata, pnote->type); |
9437c45b | 20849 | |
1449284b | 20850 | printf (" "); |
9ef920e9 | 20851 | |
24d127aa | 20852 | if (((startswith (pnote->namedata, "GA") |
483767a3 AM |
20853 | && strchr ("*$!+", pnote->namedata[2]) != NULL) |
20854 | || strchr ("*$!+", pnote->namedata[0]) != NULL) | |
20855 | && (pnote->type == NT_GNU_BUILD_ATTRIBUTE_OPEN | |
20856 | || pnote->type == NT_GNU_BUILD_ATTRIBUTE_FUNC)) | |
9ef920e9 NC |
20857 | print_gnu_build_attribute_name (pnote); |
20858 | else | |
20859 | print_symbol (-20, name); | |
20860 | ||
20861 | if (do_wide) | |
20862 | printf (" 0x%08lx\t%s\t", pnote->descsz, nt); | |
20863 | else | |
20864 | printf (" 0x%08lx\t%s\n", pnote->descsz, nt); | |
00e98fc7 | 20865 | |
24d127aa | 20866 | if (startswith (pnote->namedata, "IPF/VMS")) |
00e98fc7 | 20867 | return print_ia64_vms_note (pnote); |
24d127aa | 20868 | else if (startswith (pnote->namedata, "GNU")) |
dda8d76d | 20869 | return print_gnu_note (filedata, pnote); |
24d127aa | 20870 | else if (startswith (pnote->namedata, "stapsdt")) |
c6a9fc58 | 20871 | return print_stapsdt_note (pnote); |
24d127aa | 20872 | else if (startswith (pnote->namedata, "CORE")) |
9ece1fa9 | 20873 | return print_core_note (pnote); |
24d127aa | 20874 | else if (((startswith (pnote->namedata, "GA") |
483767a3 AM |
20875 | && strchr ("*$!+", pnote->namedata[2]) != NULL) |
20876 | || strchr ("*$!+", pnote->namedata[0]) != NULL) | |
20877 | && (pnote->type == NT_GNU_BUILD_ATTRIBUTE_OPEN | |
20878 | || pnote->type == NT_GNU_BUILD_ATTRIBUTE_FUNC)) | |
dda8d76d | 20879 | return print_gnu_build_attribute_description (pnote, filedata); |
779fe533 | 20880 | |
9ef920e9 | 20881 | if (pnote->descsz) |
1449284b NC |
20882 | { |
20883 | unsigned long i; | |
20884 | ||
20885 | printf (_(" description data: ")); | |
20886 | for (i = 0; i < pnote->descsz; i++) | |
178d8719 | 20887 | printf ("%02x ", pnote->descdata[i] & 0xff); |
04ac15ab AS |
20888 | if (!do_wide) |
20889 | printf ("\n"); | |
1449284b NC |
20890 | } |
20891 | ||
9ef920e9 NC |
20892 | if (do_wide) |
20893 | printf ("\n"); | |
20894 | ||
015dc7e1 | 20895 | return true; |
1449284b | 20896 | } |
6d118b09 | 20897 | |
015dc7e1 | 20898 | static bool |
dda8d76d NC |
20899 | process_notes_at (Filedata * filedata, |
20900 | Elf_Internal_Shdr * section, | |
20901 | bfd_vma offset, | |
82ed9683 L |
20902 | bfd_vma length, |
20903 | bfd_vma align) | |
779fe533 | 20904 | { |
015dc7e1 AM |
20905 | Elf_External_Note *pnotes; |
20906 | Elf_External_Note *external; | |
20907 | char *end; | |
20908 | bool res = true; | |
103f02d3 | 20909 | |
779fe533 | 20910 | if (length <= 0) |
015dc7e1 | 20911 | return false; |
103f02d3 | 20912 | |
1449284b NC |
20913 | if (section) |
20914 | { | |
dda8d76d | 20915 | pnotes = (Elf_External_Note *) get_section_contents (section, filedata); |
1449284b | 20916 | if (pnotes) |
32ec8896 | 20917 | { |
dda8d76d | 20918 | if (! apply_relocations (filedata, section, (unsigned char *) pnotes, length, NULL, NULL)) |
f761cb13 AM |
20919 | { |
20920 | free (pnotes); | |
015dc7e1 | 20921 | return false; |
f761cb13 | 20922 | } |
32ec8896 | 20923 | } |
1449284b NC |
20924 | } |
20925 | else | |
82ed9683 | 20926 | pnotes = (Elf_External_Note *) get_data (NULL, filedata, offset, 1, length, |
1449284b | 20927 | _("notes")); |
4dff97b2 | 20928 | |
dd24e3da | 20929 | if (pnotes == NULL) |
015dc7e1 | 20930 | return false; |
779fe533 | 20931 | |
103f02d3 | 20932 | external = pnotes; |
103f02d3 | 20933 | |
ca0e11aa NC |
20934 | if (filedata->is_separate) |
20935 | printf (_("In linked file '%s': "), filedata->file_name); | |
20936 | else | |
20937 | printf ("\n"); | |
1449284b | 20938 | if (section) |
ca0e11aa | 20939 | printf (_("Displaying notes found in: %s\n"), printable_section_name (filedata, section)); |
1449284b | 20940 | else |
ca0e11aa | 20941 | printf (_("Displaying notes found at file offset 0x%08lx with length 0x%08lx:\n"), |
1449284b NC |
20942 | (unsigned long) offset, (unsigned long) length); |
20943 | ||
82ed9683 L |
20944 | /* NB: Some note sections may have alignment value of 0 or 1. gABI |
20945 | specifies that notes should be aligned to 4 bytes in 32-bit | |
20946 | objects and to 8 bytes in 64-bit objects. As a Linux extension, | |
20947 | we also support 4 byte alignment in 64-bit objects. If section | |
20948 | alignment is less than 4, we treate alignment as 4 bytes. */ | |
20949 | if (align < 4) | |
20950 | align = 4; | |
20951 | else if (align != 4 && align != 8) | |
20952 | { | |
20953 | warn (_("Corrupt note: alignment %ld, expecting 4 or 8\n"), | |
20954 | (long) align); | |
a788aedd | 20955 | free (pnotes); |
015dc7e1 | 20956 | return false; |
82ed9683 L |
20957 | } |
20958 | ||
dbe15e4e | 20959 | printf (_(" %-20s %-10s\tDescription\n"), _("Owner"), _("Data size")); |
103f02d3 | 20960 | |
c8071705 NC |
20961 | end = (char *) pnotes + length; |
20962 | while ((char *) external < end) | |
779fe533 | 20963 | { |
b34976b6 | 20964 | Elf_Internal_Note inote; |
15b42fb0 | 20965 | size_t min_notesz; |
4dff97b2 | 20966 | char * next; |
2cf0635d | 20967 | char * temp = NULL; |
c8071705 | 20968 | size_t data_remaining = end - (char *) external; |
6d118b09 | 20969 | |
dda8d76d | 20970 | if (!is_ia64_vms (filedata)) |
15b42fb0 | 20971 | { |
9dd3a467 NC |
20972 | /* PR binutils/15191 |
20973 | Make sure that there is enough data to read. */ | |
15b42fb0 AM |
20974 | min_notesz = offsetof (Elf_External_Note, name); |
20975 | if (data_remaining < min_notesz) | |
9dd3a467 | 20976 | { |
d3a49aa8 AM |
20977 | warn (ngettext ("Corrupt note: only %ld byte remains, " |
20978 | "not enough for a full note\n", | |
20979 | "Corrupt note: only %ld bytes remain, " | |
20980 | "not enough for a full note\n", | |
20981 | data_remaining), | |
20982 | (long) data_remaining); | |
9dd3a467 NC |
20983 | break; |
20984 | } | |
5396a86e AM |
20985 | data_remaining -= min_notesz; |
20986 | ||
15b42fb0 AM |
20987 | inote.type = BYTE_GET (external->type); |
20988 | inote.namesz = BYTE_GET (external->namesz); | |
20989 | inote.namedata = external->name; | |
20990 | inote.descsz = BYTE_GET (external->descsz); | |
276da9b3 | 20991 | inote.descdata = ((char *) external |
4dff97b2 | 20992 | + ELF_NOTE_DESC_OFFSET (inote.namesz, align)); |
15b42fb0 | 20993 | inote.descpos = offset + (inote.descdata - (char *) pnotes); |
276da9b3 | 20994 | next = ((char *) external |
4dff97b2 | 20995 | + ELF_NOTE_NEXT_OFFSET (inote.namesz, inote.descsz, align)); |
15b42fb0 | 20996 | } |
00e98fc7 | 20997 | else |
15b42fb0 AM |
20998 | { |
20999 | Elf64_External_VMS_Note *vms_external; | |
00e98fc7 | 21000 | |
9dd3a467 NC |
21001 | /* PR binutils/15191 |
21002 | Make sure that there is enough data to read. */ | |
15b42fb0 AM |
21003 | min_notesz = offsetof (Elf64_External_VMS_Note, name); |
21004 | if (data_remaining < min_notesz) | |
9dd3a467 | 21005 | { |
d3a49aa8 AM |
21006 | warn (ngettext ("Corrupt note: only %ld byte remains, " |
21007 | "not enough for a full note\n", | |
21008 | "Corrupt note: only %ld bytes remain, " | |
21009 | "not enough for a full note\n", | |
21010 | data_remaining), | |
21011 | (long) data_remaining); | |
9dd3a467 NC |
21012 | break; |
21013 | } | |
5396a86e | 21014 | data_remaining -= min_notesz; |
3e55a963 | 21015 | |
15b42fb0 AM |
21016 | vms_external = (Elf64_External_VMS_Note *) external; |
21017 | inote.type = BYTE_GET (vms_external->type); | |
21018 | inote.namesz = BYTE_GET (vms_external->namesz); | |
21019 | inote.namedata = vms_external->name; | |
21020 | inote.descsz = BYTE_GET (vms_external->descsz); | |
21021 | inote.descdata = inote.namedata + align_power (inote.namesz, 3); | |
21022 | inote.descpos = offset + (inote.descdata - (char *) pnotes); | |
21023 | next = inote.descdata + align_power (inote.descsz, 3); | |
21024 | } | |
21025 | ||
5396a86e AM |
21026 | /* PR 17531: file: 3443835e. */ |
21027 | /* PR 17531: file: id:000000,sig:11,src:006986,op:havoc,rep:4. */ | |
21028 | if ((size_t) (inote.descdata - inote.namedata) < inote.namesz | |
21029 | || (size_t) (inote.descdata - inote.namedata) > data_remaining | |
21030 | || (size_t) (next - inote.descdata) < inote.descsz | |
21031 | || ((size_t) (next - inote.descdata) | |
21032 | > data_remaining - (size_t) (inote.descdata - inote.namedata))) | |
3e55a963 | 21033 | { |
15b42fb0 | 21034 | warn (_("note with invalid namesz and/or descsz found at offset 0x%lx\n"), |
0af1713e | 21035 | (unsigned long) ((char *) external - (char *) pnotes)); |
4dff97b2 NC |
21036 | warn (_(" type: 0x%lx, namesize: 0x%08lx, descsize: 0x%08lx, alignment: %u\n"), |
21037 | inote.type, inote.namesz, inote.descsz, (int) align); | |
3e55a963 NC |
21038 | break; |
21039 | } | |
21040 | ||
15b42fb0 | 21041 | external = (Elf_External_Note *) next; |
dd24e3da | 21042 | |
6d118b09 NC |
21043 | /* Verify that name is null terminated. It appears that at least |
21044 | one version of Linux (RedHat 6.0) generates corefiles that don't | |
21045 | comply with the ELF spec by failing to include the null byte in | |
21046 | namesz. */ | |
18344509 | 21047 | if (inote.namesz > 0 && inote.namedata[inote.namesz - 1] != '\0') |
6d118b09 | 21048 | { |
5396a86e | 21049 | if ((size_t) (inote.descdata - inote.namedata) == inote.namesz) |
6d118b09 | 21050 | { |
5396a86e AM |
21051 | temp = (char *) malloc (inote.namesz + 1); |
21052 | if (temp == NULL) | |
21053 | { | |
21054 | error (_("Out of memory allocating space for inote name\n")); | |
015dc7e1 | 21055 | res = false; |
5396a86e AM |
21056 | break; |
21057 | } | |
76da6bbe | 21058 | |
5396a86e AM |
21059 | memcpy (temp, inote.namedata, inote.namesz); |
21060 | inote.namedata = temp; | |
21061 | } | |
21062 | inote.namedata[inote.namesz] = 0; | |
6d118b09 NC |
21063 | } |
21064 | ||
dda8d76d | 21065 | if (! process_note (& inote, filedata)) |
015dc7e1 | 21066 | res = false; |
103f02d3 | 21067 | |
9db70fc3 AM |
21068 | free (temp); |
21069 | temp = NULL; | |
779fe533 NC |
21070 | } |
21071 | ||
21072 | free (pnotes); | |
103f02d3 | 21073 | |
779fe533 NC |
21074 | return res; |
21075 | } | |
21076 | ||
015dc7e1 | 21077 | static bool |
dda8d76d | 21078 | process_corefile_note_segments (Filedata * filedata) |
779fe533 | 21079 | { |
015dc7e1 | 21080 | Elf_Internal_Phdr *segment; |
b34976b6 | 21081 | unsigned int i; |
015dc7e1 | 21082 | bool res = true; |
103f02d3 | 21083 | |
dda8d76d | 21084 | if (! get_program_headers (filedata)) |
015dc7e1 | 21085 | return true; |
103f02d3 | 21086 | |
dda8d76d NC |
21087 | for (i = 0, segment = filedata->program_headers; |
21088 | i < filedata->file_header.e_phnum; | |
b34976b6 | 21089 | i++, segment++) |
779fe533 NC |
21090 | { |
21091 | if (segment->p_type == PT_NOTE) | |
dda8d76d | 21092 | if (! process_notes_at (filedata, NULL, |
32ec8896 | 21093 | (bfd_vma) segment->p_offset, |
82ed9683 L |
21094 | (bfd_vma) segment->p_filesz, |
21095 | (bfd_vma) segment->p_align)) | |
015dc7e1 | 21096 | res = false; |
779fe533 | 21097 | } |
103f02d3 | 21098 | |
779fe533 NC |
21099 | return res; |
21100 | } | |
21101 | ||
015dc7e1 | 21102 | static bool |
dda8d76d | 21103 | process_v850_notes (Filedata * filedata, bfd_vma offset, bfd_vma length) |
685080f2 NC |
21104 | { |
21105 | Elf_External_Note * pnotes; | |
21106 | Elf_External_Note * external; | |
c8071705 | 21107 | char * end; |
015dc7e1 | 21108 | bool res = true; |
685080f2 NC |
21109 | |
21110 | if (length <= 0) | |
015dc7e1 | 21111 | return false; |
685080f2 | 21112 | |
dda8d76d | 21113 | pnotes = (Elf_External_Note *) get_data (NULL, filedata, offset, 1, length, |
685080f2 NC |
21114 | _("v850 notes")); |
21115 | if (pnotes == NULL) | |
015dc7e1 | 21116 | return false; |
685080f2 NC |
21117 | |
21118 | external = pnotes; | |
c8071705 | 21119 | end = (char*) pnotes + length; |
685080f2 NC |
21120 | |
21121 | printf (_("\nDisplaying contents of Renesas V850 notes section at offset 0x%lx with length 0x%lx:\n"), | |
21122 | (unsigned long) offset, (unsigned long) length); | |
21123 | ||
c8071705 | 21124 | while ((char *) external + sizeof (Elf_External_Note) < end) |
685080f2 NC |
21125 | { |
21126 | Elf_External_Note * next; | |
21127 | Elf_Internal_Note inote; | |
21128 | ||
21129 | inote.type = BYTE_GET (external->type); | |
21130 | inote.namesz = BYTE_GET (external->namesz); | |
21131 | inote.namedata = external->name; | |
21132 | inote.descsz = BYTE_GET (external->descsz); | |
21133 | inote.descdata = inote.namedata + align_power (inote.namesz, 2); | |
21134 | inote.descpos = offset + (inote.descdata - (char *) pnotes); | |
21135 | ||
c8071705 NC |
21136 | if (inote.descdata < (char *) pnotes || inote.descdata >= end) |
21137 | { | |
21138 | warn (_("Corrupt note: name size is too big: %lx\n"), inote.namesz); | |
21139 | inote.descdata = inote.namedata; | |
21140 | inote.namesz = 0; | |
21141 | } | |
21142 | ||
685080f2 NC |
21143 | next = (Elf_External_Note *) (inote.descdata + align_power (inote.descsz, 2)); |
21144 | ||
c8071705 | 21145 | if ( ((char *) next > end) |
685080f2 NC |
21146 | || ((char *) next < (char *) pnotes)) |
21147 | { | |
21148 | warn (_("corrupt descsz found in note at offset 0x%lx\n"), | |
21149 | (unsigned long) ((char *) external - (char *) pnotes)); | |
21150 | warn (_(" type: 0x%lx, namesize: 0x%lx, descsize: 0x%lx\n"), | |
21151 | inote.type, inote.namesz, inote.descsz); | |
21152 | break; | |
21153 | } | |
21154 | ||
21155 | external = next; | |
21156 | ||
21157 | /* Prevent out-of-bounds indexing. */ | |
c8071705 | 21158 | if ( inote.namedata + inote.namesz > end |
685080f2 NC |
21159 | || inote.namedata + inote.namesz < inote.namedata) |
21160 | { | |
21161 | warn (_("corrupt namesz found in note at offset 0x%lx\n"), | |
21162 | (unsigned long) ((char *) external - (char *) pnotes)); | |
21163 | warn (_(" type: 0x%lx, namesize: 0x%lx, descsize: 0x%lx\n"), | |
21164 | inote.type, inote.namesz, inote.descsz); | |
21165 | break; | |
21166 | } | |
21167 | ||
21168 | printf (" %s: ", get_v850_elf_note_type (inote.type)); | |
21169 | ||
21170 | if (! print_v850_note (& inote)) | |
21171 | { | |
015dc7e1 | 21172 | res = false; |
685080f2 NC |
21173 | printf ("<corrupt sizes: namesz: %lx, descsz: %lx>\n", |
21174 | inote.namesz, inote.descsz); | |
21175 | } | |
21176 | } | |
21177 | ||
21178 | free (pnotes); | |
21179 | ||
21180 | return res; | |
21181 | } | |
21182 | ||
015dc7e1 | 21183 | static bool |
dda8d76d | 21184 | process_note_sections (Filedata * filedata) |
1ec5cd37 | 21185 | { |
015dc7e1 | 21186 | Elf_Internal_Shdr *section; |
1ec5cd37 | 21187 | unsigned long i; |
32ec8896 | 21188 | unsigned int n = 0; |
015dc7e1 | 21189 | bool res = true; |
1ec5cd37 | 21190 | |
dda8d76d NC |
21191 | for (i = 0, section = filedata->section_headers; |
21192 | i < filedata->file_header.e_shnum && section != NULL; | |
1ec5cd37 | 21193 | i++, section++) |
685080f2 NC |
21194 | { |
21195 | if (section->sh_type == SHT_NOTE) | |
21196 | { | |
dda8d76d | 21197 | if (! process_notes_at (filedata, section, |
32ec8896 | 21198 | (bfd_vma) section->sh_offset, |
82ed9683 L |
21199 | (bfd_vma) section->sh_size, |
21200 | (bfd_vma) section->sh_addralign)) | |
015dc7e1 | 21201 | res = false; |
685080f2 NC |
21202 | n++; |
21203 | } | |
21204 | ||
dda8d76d NC |
21205 | if (( filedata->file_header.e_machine == EM_V800 |
21206 | || filedata->file_header.e_machine == EM_V850 | |
21207 | || filedata->file_header.e_machine == EM_CYGNUS_V850) | |
685080f2 NC |
21208 | && section->sh_type == SHT_RENESAS_INFO) |
21209 | { | |
dda8d76d | 21210 | if (! process_v850_notes (filedata, |
32ec8896 NC |
21211 | (bfd_vma) section->sh_offset, |
21212 | (bfd_vma) section->sh_size)) | |
015dc7e1 | 21213 | res = false; |
685080f2 NC |
21214 | n++; |
21215 | } | |
21216 | } | |
df565f32 NC |
21217 | |
21218 | if (n == 0) | |
21219 | /* Try processing NOTE segments instead. */ | |
dda8d76d | 21220 | return process_corefile_note_segments (filedata); |
1ec5cd37 NC |
21221 | |
21222 | return res; | |
21223 | } | |
21224 | ||
015dc7e1 | 21225 | static bool |
dda8d76d | 21226 | process_notes (Filedata * filedata) |
779fe533 NC |
21227 | { |
21228 | /* If we have not been asked to display the notes then do nothing. */ | |
21229 | if (! do_notes) | |
015dc7e1 | 21230 | return true; |
103f02d3 | 21231 | |
dda8d76d NC |
21232 | if (filedata->file_header.e_type != ET_CORE) |
21233 | return process_note_sections (filedata); | |
103f02d3 | 21234 | |
779fe533 | 21235 | /* No program headers means no NOTE segment. */ |
dda8d76d NC |
21236 | if (filedata->file_header.e_phnum > 0) |
21237 | return process_corefile_note_segments (filedata); | |
779fe533 | 21238 | |
ca0e11aa NC |
21239 | if (filedata->is_separate) |
21240 | printf (_("No notes found in linked file '%s'.\n"), | |
21241 | filedata->file_name); | |
21242 | else | |
21243 | printf (_("No notes found file.\n")); | |
21244 | ||
015dc7e1 | 21245 | return true; |
779fe533 NC |
21246 | } |
21247 | ||
60abdbed NC |
21248 | static unsigned char * |
21249 | display_public_gnu_attributes (unsigned char * start, | |
21250 | const unsigned char * const end) | |
21251 | { | |
21252 | printf (_(" Unknown GNU attribute: %s\n"), start); | |
21253 | ||
21254 | start += strnlen ((char *) start, end - start); | |
21255 | display_raw_attribute (start, end); | |
21256 | ||
21257 | return (unsigned char *) end; | |
21258 | } | |
21259 | ||
21260 | static unsigned char * | |
21261 | display_generic_attribute (unsigned char * start, | |
21262 | unsigned int tag, | |
21263 | const unsigned char * const end) | |
21264 | { | |
21265 | if (tag == 0) | |
21266 | return (unsigned char *) end; | |
21267 | ||
21268 | return display_tag_value (tag, start, end); | |
21269 | } | |
21270 | ||
015dc7e1 | 21271 | static bool |
dda8d76d | 21272 | process_arch_specific (Filedata * filedata) |
252b5132 | 21273 | { |
a952a375 | 21274 | if (! do_arch) |
015dc7e1 | 21275 | return true; |
a952a375 | 21276 | |
dda8d76d | 21277 | switch (filedata->file_header.e_machine) |
252b5132 | 21278 | { |
53a346d8 CZ |
21279 | case EM_ARC: |
21280 | case EM_ARC_COMPACT: | |
21281 | case EM_ARC_COMPACT2: | |
dda8d76d | 21282 | return process_attributes (filedata, "ARC", SHT_ARC_ATTRIBUTES, |
53a346d8 CZ |
21283 | display_arc_attribute, |
21284 | display_generic_attribute); | |
11c1ff18 | 21285 | case EM_ARM: |
dda8d76d | 21286 | return process_attributes (filedata, "aeabi", SHT_ARM_ATTRIBUTES, |
60abdbed NC |
21287 | display_arm_attribute, |
21288 | display_generic_attribute); | |
21289 | ||
252b5132 | 21290 | case EM_MIPS: |
4fe85591 | 21291 | case EM_MIPS_RS3_LE: |
dda8d76d | 21292 | return process_mips_specific (filedata); |
60abdbed NC |
21293 | |
21294 | case EM_MSP430: | |
dda8d76d | 21295 | return process_attributes (filedata, "mspabi", SHT_MSP430_ATTRIBUTES, |
b0191216 | 21296 | display_msp430_attribute, |
c0ea7c52 | 21297 | display_msp430_gnu_attribute); |
60abdbed | 21298 | |
2dc8dd17 JW |
21299 | case EM_RISCV: |
21300 | return process_attributes (filedata, "riscv", SHT_RISCV_ATTRIBUTES, | |
21301 | display_riscv_attribute, | |
21302 | display_generic_attribute); | |
21303 | ||
35c08157 | 21304 | case EM_NDS32: |
dda8d76d | 21305 | return process_nds32_specific (filedata); |
60abdbed | 21306 | |
85f7484a PB |
21307 | case EM_68K: |
21308 | return process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL, | |
21309 | display_m68k_gnu_attribute); | |
21310 | ||
34c8bcba | 21311 | case EM_PPC: |
b82317dd | 21312 | case EM_PPC64: |
dda8d76d | 21313 | return process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL, |
60abdbed NC |
21314 | display_power_gnu_attribute); |
21315 | ||
643f7afb AK |
21316 | case EM_S390: |
21317 | case EM_S390_OLD: | |
dda8d76d | 21318 | return process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL, |
60abdbed NC |
21319 | display_s390_gnu_attribute); |
21320 | ||
9e8c70f9 DM |
21321 | case EM_SPARC: |
21322 | case EM_SPARC32PLUS: | |
21323 | case EM_SPARCV9: | |
dda8d76d | 21324 | return process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL, |
60abdbed NC |
21325 | display_sparc_gnu_attribute); |
21326 | ||
59e6276b | 21327 | case EM_TI_C6000: |
dda8d76d | 21328 | return process_attributes (filedata, "c6xabi", SHT_C6000_ATTRIBUTES, |
60abdbed NC |
21329 | display_tic6x_attribute, |
21330 | display_generic_attribute); | |
21331 | ||
0861f561 CQ |
21332 | case EM_CSKY: |
21333 | return process_attributes (filedata, "csky", SHT_CSKY_ATTRIBUTES, | |
21334 | display_csky_attribute, NULL); | |
21335 | ||
252b5132 | 21336 | default: |
dda8d76d | 21337 | return process_attributes (filedata, "gnu", SHT_GNU_ATTRIBUTES, |
60abdbed NC |
21338 | display_public_gnu_attributes, |
21339 | display_generic_attribute); | |
252b5132 | 21340 | } |
252b5132 RH |
21341 | } |
21342 | ||
015dc7e1 | 21343 | static bool |
dda8d76d | 21344 | get_file_header (Filedata * filedata) |
252b5132 | 21345 | { |
9ea033b2 | 21346 | /* Read in the identity array. */ |
dda8d76d | 21347 | if (fread (filedata->file_header.e_ident, EI_NIDENT, 1, filedata->handle) != 1) |
015dc7e1 | 21348 | return false; |
252b5132 | 21349 | |
9ea033b2 | 21350 | /* Determine how to read the rest of the header. */ |
dda8d76d | 21351 | switch (filedata->file_header.e_ident[EI_DATA]) |
9ea033b2 | 21352 | { |
1a0670f3 AM |
21353 | default: |
21354 | case ELFDATANONE: | |
adab8cdc AO |
21355 | case ELFDATA2LSB: |
21356 | byte_get = byte_get_little_endian; | |
21357 | byte_put = byte_put_little_endian; | |
21358 | break; | |
21359 | case ELFDATA2MSB: | |
21360 | byte_get = byte_get_big_endian; | |
21361 | byte_put = byte_put_big_endian; | |
21362 | break; | |
9ea033b2 NC |
21363 | } |
21364 | ||
21365 | /* For now we only support 32 bit and 64 bit ELF files. */ | |
dda8d76d | 21366 | is_32bit_elf = (filedata->file_header.e_ident[EI_CLASS] != ELFCLASS64); |
9ea033b2 NC |
21367 | |
21368 | /* Read in the rest of the header. */ | |
21369 | if (is_32bit_elf) | |
21370 | { | |
21371 | Elf32_External_Ehdr ehdr32; | |
252b5132 | 21372 | |
dda8d76d | 21373 | if (fread (ehdr32.e_type, sizeof (ehdr32) - EI_NIDENT, 1, filedata->handle) != 1) |
015dc7e1 | 21374 | return false; |
103f02d3 | 21375 | |
dda8d76d NC |
21376 | filedata->file_header.e_type = BYTE_GET (ehdr32.e_type); |
21377 | filedata->file_header.e_machine = BYTE_GET (ehdr32.e_machine); | |
21378 | filedata->file_header.e_version = BYTE_GET (ehdr32.e_version); | |
21379 | filedata->file_header.e_entry = BYTE_GET (ehdr32.e_entry); | |
21380 | filedata->file_header.e_phoff = BYTE_GET (ehdr32.e_phoff); | |
21381 | filedata->file_header.e_shoff = BYTE_GET (ehdr32.e_shoff); | |
21382 | filedata->file_header.e_flags = BYTE_GET (ehdr32.e_flags); | |
21383 | filedata->file_header.e_ehsize = BYTE_GET (ehdr32.e_ehsize); | |
21384 | filedata->file_header.e_phentsize = BYTE_GET (ehdr32.e_phentsize); | |
21385 | filedata->file_header.e_phnum = BYTE_GET (ehdr32.e_phnum); | |
21386 | filedata->file_header.e_shentsize = BYTE_GET (ehdr32.e_shentsize); | |
21387 | filedata->file_header.e_shnum = BYTE_GET (ehdr32.e_shnum); | |
21388 | filedata->file_header.e_shstrndx = BYTE_GET (ehdr32.e_shstrndx); | |
9ea033b2 | 21389 | } |
252b5132 | 21390 | else |
9ea033b2 NC |
21391 | { |
21392 | Elf64_External_Ehdr ehdr64; | |
a952a375 NC |
21393 | |
21394 | /* If we have been compiled with sizeof (bfd_vma) == 4, then | |
21395 | we will not be able to cope with the 64bit data found in | |
21396 | 64 ELF files. Detect this now and abort before we start | |
50c2245b | 21397 | overwriting things. */ |
a952a375 NC |
21398 | if (sizeof (bfd_vma) < 8) |
21399 | { | |
e3c8793a NC |
21400 | error (_("This instance of readelf has been built without support for a\n\ |
21401 | 64 bit data type and so it cannot read 64 bit ELF files.\n")); | |
015dc7e1 | 21402 | return false; |
a952a375 | 21403 | } |
103f02d3 | 21404 | |
dda8d76d | 21405 | if (fread (ehdr64.e_type, sizeof (ehdr64) - EI_NIDENT, 1, filedata->handle) != 1) |
015dc7e1 | 21406 | return false; |
103f02d3 | 21407 | |
dda8d76d NC |
21408 | filedata->file_header.e_type = BYTE_GET (ehdr64.e_type); |
21409 | filedata->file_header.e_machine = BYTE_GET (ehdr64.e_machine); | |
21410 | filedata->file_header.e_version = BYTE_GET (ehdr64.e_version); | |
21411 | filedata->file_header.e_entry = BYTE_GET (ehdr64.e_entry); | |
21412 | filedata->file_header.e_phoff = BYTE_GET (ehdr64.e_phoff); | |
21413 | filedata->file_header.e_shoff = BYTE_GET (ehdr64.e_shoff); | |
21414 | filedata->file_header.e_flags = BYTE_GET (ehdr64.e_flags); | |
21415 | filedata->file_header.e_ehsize = BYTE_GET (ehdr64.e_ehsize); | |
21416 | filedata->file_header.e_phentsize = BYTE_GET (ehdr64.e_phentsize); | |
21417 | filedata->file_header.e_phnum = BYTE_GET (ehdr64.e_phnum); | |
21418 | filedata->file_header.e_shentsize = BYTE_GET (ehdr64.e_shentsize); | |
21419 | filedata->file_header.e_shnum = BYTE_GET (ehdr64.e_shnum); | |
21420 | filedata->file_header.e_shstrndx = BYTE_GET (ehdr64.e_shstrndx); | |
9ea033b2 | 21421 | } |
252b5132 | 21422 | |
015dc7e1 | 21423 | return true; |
252b5132 RH |
21424 | } |
21425 | ||
13acb58d AM |
21426 | static void |
21427 | free_filedata (Filedata *filedata) | |
21428 | { | |
21429 | free (filedata->program_interpreter); | |
13acb58d | 21430 | free (filedata->program_headers); |
13acb58d | 21431 | free (filedata->section_headers); |
13acb58d | 21432 | free (filedata->string_table); |
13acb58d | 21433 | free (filedata->dump.dump_sects); |
13acb58d | 21434 | free (filedata->dynamic_strings); |
13acb58d | 21435 | free (filedata->dynamic_symbols); |
13acb58d | 21436 | free (filedata->dynamic_syminfo); |
13acb58d | 21437 | free (filedata->dynamic_section); |
13acb58d AM |
21438 | |
21439 | while (filedata->symtab_shndx_list != NULL) | |
21440 | { | |
21441 | elf_section_list *next = filedata->symtab_shndx_list->next; | |
21442 | free (filedata->symtab_shndx_list); | |
21443 | filedata->symtab_shndx_list = next; | |
21444 | } | |
21445 | ||
21446 | free (filedata->section_headers_groups); | |
13acb58d AM |
21447 | |
21448 | if (filedata->section_groups) | |
21449 | { | |
21450 | size_t i; | |
21451 | struct group_list * g; | |
21452 | struct group_list * next; | |
21453 | ||
21454 | for (i = 0; i < filedata->group_count; i++) | |
21455 | { | |
21456 | for (g = filedata->section_groups [i].root; g != NULL; g = next) | |
21457 | { | |
21458 | next = g->next; | |
21459 | free (g); | |
21460 | } | |
21461 | } | |
21462 | ||
21463 | free (filedata->section_groups); | |
13acb58d | 21464 | } |
066f8fbe AM |
21465 | memset (&filedata->section_headers, 0, |
21466 | sizeof (Filedata) - offsetof (Filedata, section_headers)); | |
13acb58d AM |
21467 | } |
21468 | ||
dda8d76d NC |
21469 | static void |
21470 | close_file (Filedata * filedata) | |
21471 | { | |
21472 | if (filedata) | |
21473 | { | |
21474 | if (filedata->handle) | |
21475 | fclose (filedata->handle); | |
21476 | free (filedata); | |
21477 | } | |
21478 | } | |
21479 | ||
21480 | void | |
21481 | close_debug_file (void * data) | |
21482 | { | |
13acb58d | 21483 | free_filedata ((Filedata *) data); |
dda8d76d NC |
21484 | close_file ((Filedata *) data); |
21485 | } | |
21486 | ||
21487 | static Filedata * | |
015dc7e1 | 21488 | open_file (const char * pathname, bool is_separate) |
dda8d76d NC |
21489 | { |
21490 | struct stat statbuf; | |
21491 | Filedata * filedata = NULL; | |
21492 | ||
21493 | if (stat (pathname, & statbuf) < 0 | |
21494 | || ! S_ISREG (statbuf.st_mode)) | |
21495 | goto fail; | |
21496 | ||
21497 | filedata = calloc (1, sizeof * filedata); | |
21498 | if (filedata == NULL) | |
21499 | goto fail; | |
21500 | ||
21501 | filedata->handle = fopen (pathname, "rb"); | |
21502 | if (filedata->handle == NULL) | |
21503 | goto fail; | |
21504 | ||
21505 | filedata->file_size = (bfd_size_type) statbuf.st_size; | |
21506 | filedata->file_name = pathname; | |
ca0e11aa | 21507 | filedata->is_separate = is_separate; |
dda8d76d NC |
21508 | |
21509 | if (! get_file_header (filedata)) | |
21510 | goto fail; | |
21511 | ||
4de91c10 AM |
21512 | if (!get_section_headers (filedata, false)) |
21513 | goto fail; | |
dda8d76d NC |
21514 | |
21515 | return filedata; | |
21516 | ||
21517 | fail: | |
21518 | if (filedata) | |
21519 | { | |
21520 | if (filedata->handle) | |
21521 | fclose (filedata->handle); | |
21522 | free (filedata); | |
21523 | } | |
21524 | return NULL; | |
21525 | } | |
21526 | ||
21527 | void * | |
21528 | open_debug_file (const char * pathname) | |
21529 | { | |
015dc7e1 | 21530 | return open_file (pathname, true); |
dda8d76d NC |
21531 | } |
21532 | ||
835f2fae NC |
21533 | static void |
21534 | initialise_dump_sects (Filedata * filedata) | |
21535 | { | |
21536 | /* Initialise the dump_sects array from the cmdline_dump_sects array. | |
21537 | Note we do this even if cmdline_dump_sects is empty because we | |
21538 | must make sure that the dump_sets array is zeroed out before each | |
21539 | object file is processed. */ | |
21540 | if (filedata->dump.num_dump_sects > cmdline.num_dump_sects) | |
21541 | memset (filedata->dump.dump_sects, 0, | |
21542 | filedata->dump.num_dump_sects * sizeof (*filedata->dump.dump_sects)); | |
21543 | ||
21544 | if (cmdline.num_dump_sects > 0) | |
21545 | { | |
21546 | if (filedata->dump.num_dump_sects == 0) | |
21547 | /* A sneaky way of allocating the dump_sects array. */ | |
21548 | request_dump_bynumber (&filedata->dump, cmdline.num_dump_sects, 0); | |
21549 | ||
21550 | assert (filedata->dump.num_dump_sects >= cmdline.num_dump_sects); | |
21551 | memcpy (filedata->dump.dump_sects, cmdline.dump_sects, | |
21552 | cmdline.num_dump_sects * sizeof (*filedata->dump.dump_sects)); | |
21553 | } | |
21554 | } | |
21555 | ||
fb52b2f4 NC |
21556 | /* Process one ELF object file according to the command line options. |
21557 | This file may actually be stored in an archive. The file is | |
32ec8896 NC |
21558 | positioned at the start of the ELF object. Returns TRUE if no |
21559 | problems were encountered, FALSE otherwise. */ | |
fb52b2f4 | 21560 | |
015dc7e1 | 21561 | static bool |
dda8d76d | 21562 | process_object (Filedata * filedata) |
252b5132 | 21563 | { |
015dc7e1 | 21564 | bool have_separate_files; |
252b5132 | 21565 | unsigned int i; |
015dc7e1 | 21566 | bool res; |
252b5132 | 21567 | |
dda8d76d | 21568 | if (! get_file_header (filedata)) |
252b5132 | 21569 | { |
dda8d76d | 21570 | error (_("%s: Failed to read file header\n"), filedata->file_name); |
015dc7e1 | 21571 | return false; |
252b5132 RH |
21572 | } |
21573 | ||
21574 | /* Initialise per file variables. */ | |
978c4450 AM |
21575 | for (i = ARRAY_SIZE (filedata->version_info); i--;) |
21576 | filedata->version_info[i] = 0; | |
252b5132 | 21577 | |
978c4450 AM |
21578 | for (i = ARRAY_SIZE (filedata->dynamic_info); i--;) |
21579 | filedata->dynamic_info[i] = 0; | |
21580 | filedata->dynamic_info_DT_GNU_HASH = 0; | |
21581 | filedata->dynamic_info_DT_MIPS_XHASH = 0; | |
252b5132 RH |
21582 | |
21583 | /* Process the file. */ | |
21584 | if (show_name) | |
dda8d76d | 21585 | printf (_("\nFile: %s\n"), filedata->file_name); |
252b5132 | 21586 | |
835f2fae | 21587 | initialise_dump_sects (filedata); |
d70c5fc7 | 21588 | |
4de91c10 AM |
21589 | /* There may be some extensions in the first section header. Don't |
21590 | bomb if we can't read it. */ | |
21591 | get_section_headers (filedata, true); | |
21592 | ||
dda8d76d | 21593 | if (! process_file_header (filedata)) |
4de91c10 AM |
21594 | { |
21595 | res = false; | |
21596 | goto out; | |
21597 | } | |
252b5132 | 21598 | |
e331b18d AM |
21599 | /* Throw away the single section header read above, so that we |
21600 | re-read the entire set. */ | |
21601 | free (filedata->section_headers); | |
21602 | filedata->section_headers = NULL; | |
21603 | ||
dda8d76d | 21604 | if (! process_section_headers (filedata)) |
2f62977e | 21605 | { |
32ec8896 | 21606 | /* Without loaded section headers we cannot process lots of things. */ |
015dc7e1 | 21607 | do_unwind = do_version = do_dump = do_arch = false; |
252b5132 | 21608 | |
2f62977e | 21609 | if (! do_using_dynamic) |
015dc7e1 | 21610 | do_syms = do_dyn_syms = do_reloc = false; |
2f62977e | 21611 | } |
252b5132 | 21612 | |
dda8d76d | 21613 | if (! process_section_groups (filedata)) |
32ec8896 | 21614 | /* Without loaded section groups we cannot process unwind. */ |
015dc7e1 | 21615 | do_unwind = false; |
d1f5c6e3 | 21616 | |
93df3340 AM |
21617 | process_program_headers (filedata); |
21618 | ||
21619 | res = process_dynamic_section (filedata); | |
252b5132 | 21620 | |
dda8d76d | 21621 | if (! process_relocs (filedata)) |
015dc7e1 | 21622 | res = false; |
252b5132 | 21623 | |
dda8d76d | 21624 | if (! process_unwind (filedata)) |
015dc7e1 | 21625 | res = false; |
4d6ed7c8 | 21626 | |
dda8d76d | 21627 | if (! process_symbol_table (filedata)) |
015dc7e1 | 21628 | res = false; |
252b5132 | 21629 | |
0f03783c | 21630 | if (! process_lto_symbol_tables (filedata)) |
015dc7e1 | 21631 | res = false; |
b9e920ec | 21632 | |
dda8d76d | 21633 | if (! process_syminfo (filedata)) |
015dc7e1 | 21634 | res = false; |
252b5132 | 21635 | |
dda8d76d | 21636 | if (! process_version_sections (filedata)) |
015dc7e1 | 21637 | res = false; |
252b5132 | 21638 | |
82ed9683 | 21639 | if (filedata->file_header.e_shstrndx != SHN_UNDEF) |
24841daa | 21640 | have_separate_files = load_separate_debug_files (filedata, filedata->file_name); |
82ed9683 | 21641 | else |
015dc7e1 | 21642 | have_separate_files = false; |
dda8d76d NC |
21643 | |
21644 | if (! process_section_contents (filedata)) | |
015dc7e1 | 21645 | res = false; |
f5842774 | 21646 | |
24841daa | 21647 | if (have_separate_files) |
dda8d76d | 21648 | { |
24841daa NC |
21649 | separate_info * d; |
21650 | ||
21651 | for (d = first_separate_info; d != NULL; d = d->next) | |
21652 | { | |
835f2fae NC |
21653 | initialise_dump_sects (d->handle); |
21654 | ||
ca0e11aa | 21655 | if (process_links && ! process_file_header (d->handle)) |
015dc7e1 | 21656 | res = false; |
ca0e11aa | 21657 | else if (! process_section_headers (d->handle)) |
015dc7e1 | 21658 | res = false; |
d6bfbc39 | 21659 | else if (! process_section_contents (d->handle)) |
015dc7e1 | 21660 | res = false; |
ca0e11aa NC |
21661 | else if (process_links) |
21662 | { | |
ca0e11aa | 21663 | if (! process_section_groups (d->handle)) |
015dc7e1 | 21664 | res = false; |
93df3340 | 21665 | process_program_headers (d->handle); |
ca0e11aa | 21666 | if (! process_dynamic_section (d->handle)) |
015dc7e1 | 21667 | res = false; |
ca0e11aa | 21668 | if (! process_relocs (d->handle)) |
015dc7e1 | 21669 | res = false; |
ca0e11aa | 21670 | if (! process_unwind (d->handle)) |
015dc7e1 | 21671 | res = false; |
ca0e11aa | 21672 | if (! process_symbol_table (d->handle)) |
015dc7e1 | 21673 | res = false; |
ca0e11aa | 21674 | if (! process_lto_symbol_tables (d->handle)) |
015dc7e1 | 21675 | res = false; |
ca0e11aa | 21676 | if (! process_syminfo (d->handle)) |
015dc7e1 | 21677 | res = false; |
ca0e11aa | 21678 | if (! process_version_sections (d->handle)) |
015dc7e1 | 21679 | res = false; |
ca0e11aa | 21680 | if (! process_notes (d->handle)) |
015dc7e1 | 21681 | res = false; |
ca0e11aa | 21682 | } |
24841daa NC |
21683 | } |
21684 | ||
21685 | /* The file handles are closed by the call to free_debug_memory() below. */ | |
dda8d76d NC |
21686 | } |
21687 | ||
21688 | if (! process_notes (filedata)) | |
015dc7e1 | 21689 | res = false; |
103f02d3 | 21690 | |
dda8d76d | 21691 | if (! process_gnu_liblist (filedata)) |
015dc7e1 | 21692 | res = false; |
047b2264 | 21693 | |
dda8d76d | 21694 | if (! process_arch_specific (filedata)) |
015dc7e1 | 21695 | res = false; |
252b5132 | 21696 | |
4de91c10 | 21697 | out: |
13acb58d | 21698 | free_filedata (filedata); |
e4b17d5c | 21699 | |
19e6b90e | 21700 | free_debug_memory (); |
18bd398b | 21701 | |
32ec8896 | 21702 | return res; |
252b5132 RH |
21703 | } |
21704 | ||
2cf0635d | 21705 | /* Process an ELF archive. |
32ec8896 NC |
21706 | On entry the file is positioned just after the ARMAG string. |
21707 | Returns TRUE upon success, FALSE otherwise. */ | |
2cf0635d | 21708 | |
015dc7e1 AM |
21709 | static bool |
21710 | process_archive (Filedata * filedata, bool is_thin_archive) | |
2cf0635d NC |
21711 | { |
21712 | struct archive_info arch; | |
21713 | struct archive_info nested_arch; | |
21714 | size_t got; | |
015dc7e1 | 21715 | bool ret = true; |
2cf0635d | 21716 | |
015dc7e1 | 21717 | show_name = true; |
2cf0635d NC |
21718 | |
21719 | /* The ARCH structure is used to hold information about this archive. */ | |
21720 | arch.file_name = NULL; | |
21721 | arch.file = NULL; | |
21722 | arch.index_array = NULL; | |
21723 | arch.sym_table = NULL; | |
21724 | arch.longnames = NULL; | |
21725 | ||
21726 | /* The NESTED_ARCH structure is used as a single-item cache of information | |
21727 | about a nested archive (when members of a thin archive reside within | |
21728 | another regular archive file). */ | |
21729 | nested_arch.file_name = NULL; | |
21730 | nested_arch.file = NULL; | |
21731 | nested_arch.index_array = NULL; | |
21732 | nested_arch.sym_table = NULL; | |
21733 | nested_arch.longnames = NULL; | |
21734 | ||
dda8d76d | 21735 | if (setup_archive (&arch, filedata->file_name, filedata->handle, |
780f96ae AM |
21736 | filedata->file_size, is_thin_archive, |
21737 | do_archive_index) != 0) | |
2cf0635d | 21738 | { |
015dc7e1 | 21739 | ret = false; |
2cf0635d | 21740 | goto out; |
4145f1d5 | 21741 | } |
fb52b2f4 | 21742 | |
4145f1d5 NC |
21743 | if (do_archive_index) |
21744 | { | |
2cf0635d | 21745 | if (arch.sym_table == NULL) |
1cb7d8b1 AM |
21746 | error (_("%s: unable to dump the index as none was found\n"), |
21747 | filedata->file_name); | |
4145f1d5 NC |
21748 | else |
21749 | { | |
591f7597 | 21750 | unsigned long i, l; |
4145f1d5 NC |
21751 | unsigned long current_pos; |
21752 | ||
1cb7d8b1 AM |
21753 | printf (_("Index of archive %s: (%lu entries, 0x%lx bytes " |
21754 | "in the symbol table)\n"), | |
21755 | filedata->file_name, (unsigned long) arch.index_num, | |
21756 | arch.sym_size); | |
dda8d76d NC |
21757 | |
21758 | current_pos = ftell (filedata->handle); | |
4145f1d5 | 21759 | |
2cf0635d | 21760 | for (i = l = 0; i < arch.index_num; i++) |
4145f1d5 | 21761 | { |
1cb7d8b1 AM |
21762 | if (i == 0 |
21763 | || (i > 0 && arch.index_array[i] != arch.index_array[i - 1])) | |
21764 | { | |
21765 | char * member_name | |
21766 | = get_archive_member_name_at (&arch, arch.index_array[i], | |
21767 | &nested_arch); | |
2cf0635d | 21768 | |
1cb7d8b1 AM |
21769 | if (member_name != NULL) |
21770 | { | |
21771 | char * qualified_name | |
21772 | = make_qualified_name (&arch, &nested_arch, | |
21773 | member_name); | |
2cf0635d | 21774 | |
1cb7d8b1 AM |
21775 | if (qualified_name != NULL) |
21776 | { | |
21777 | printf (_("Contents of binary %s at offset "), | |
21778 | qualified_name); | |
c2a7d3f5 NC |
21779 | (void) print_vma (arch.index_array[i], PREFIX_HEX); |
21780 | putchar ('\n'); | |
1cb7d8b1 AM |
21781 | free (qualified_name); |
21782 | } | |
fd486f32 | 21783 | free (member_name); |
4145f1d5 NC |
21784 | } |
21785 | } | |
2cf0635d NC |
21786 | |
21787 | if (l >= arch.sym_size) | |
4145f1d5 | 21788 | { |
1cb7d8b1 AM |
21789 | error (_("%s: end of the symbol table reached " |
21790 | "before the end of the index\n"), | |
dda8d76d | 21791 | filedata->file_name); |
015dc7e1 | 21792 | ret = false; |
cb8f3167 | 21793 | break; |
4145f1d5 | 21794 | } |
591f7597 | 21795 | /* PR 17531: file: 0b6630b2. */ |
1cb7d8b1 AM |
21796 | printf ("\t%.*s\n", |
21797 | (int) (arch.sym_size - l), arch.sym_table + l); | |
591f7597 | 21798 | l += strnlen (arch.sym_table + l, arch.sym_size - l) + 1; |
4145f1d5 NC |
21799 | } |
21800 | ||
67ce483b | 21801 | if (arch.uses_64bit_indices) |
c2a7d3f5 NC |
21802 | l = (l + 7) & ~ 7; |
21803 | else | |
21804 | l += l & 1; | |
21805 | ||
2cf0635d | 21806 | if (l < arch.sym_size) |
32ec8896 | 21807 | { |
d3a49aa8 AM |
21808 | error (ngettext ("%s: %ld byte remains in the symbol table, " |
21809 | "but without corresponding entries in " | |
21810 | "the index table\n", | |
21811 | "%s: %ld bytes remain in the symbol table, " | |
21812 | "but without corresponding entries in " | |
21813 | "the index table\n", | |
21814 | arch.sym_size - l), | |
dda8d76d | 21815 | filedata->file_name, arch.sym_size - l); |
015dc7e1 | 21816 | ret = false; |
32ec8896 | 21817 | } |
4145f1d5 | 21818 | |
dda8d76d | 21819 | if (fseek (filedata->handle, current_pos, SEEK_SET) != 0) |
4145f1d5 | 21820 | { |
1cb7d8b1 AM |
21821 | error (_("%s: failed to seek back to start of object files " |
21822 | "in the archive\n"), | |
dda8d76d | 21823 | filedata->file_name); |
015dc7e1 | 21824 | ret = false; |
2cf0635d | 21825 | goto out; |
4145f1d5 | 21826 | } |
fb52b2f4 | 21827 | } |
4145f1d5 NC |
21828 | |
21829 | if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections | |
21830 | && !do_segments && !do_header && !do_dump && !do_version | |
21831 | && !do_histogram && !do_debugging && !do_arch && !do_notes | |
2c610e4b | 21832 | && !do_section_groups && !do_dyn_syms) |
2cf0635d | 21833 | { |
015dc7e1 | 21834 | ret = true; /* Archive index only. */ |
2cf0635d NC |
21835 | goto out; |
21836 | } | |
fb52b2f4 NC |
21837 | } |
21838 | ||
fb52b2f4 NC |
21839 | while (1) |
21840 | { | |
2cf0635d NC |
21841 | char * name; |
21842 | size_t namelen; | |
21843 | char * qualified_name; | |
21844 | ||
21845 | /* Read the next archive header. */ | |
dda8d76d | 21846 | if (fseek (filedata->handle, arch.next_arhdr_offset, SEEK_SET) != 0) |
1cb7d8b1 AM |
21847 | { |
21848 | error (_("%s: failed to seek to next archive header\n"), | |
21849 | arch.file_name); | |
015dc7e1 | 21850 | ret = false; |
1cb7d8b1 AM |
21851 | break; |
21852 | } | |
dda8d76d | 21853 | got = fread (&arch.arhdr, 1, sizeof arch.arhdr, filedata->handle); |
2cf0635d | 21854 | if (got != sizeof arch.arhdr) |
1cb7d8b1 AM |
21855 | { |
21856 | if (got == 0) | |
2cf0635d | 21857 | break; |
28e817cc NC |
21858 | /* PR 24049 - we cannot use filedata->file_name as this will |
21859 | have already been freed. */ | |
21860 | error (_("%s: failed to read archive header\n"), arch.file_name); | |
9abca702 | 21861 | |
015dc7e1 | 21862 | ret = false; |
1cb7d8b1 AM |
21863 | break; |
21864 | } | |
2cf0635d | 21865 | if (memcmp (arch.arhdr.ar_fmag, ARFMAG, 2) != 0) |
1cb7d8b1 AM |
21866 | { |
21867 | error (_("%s: did not find a valid archive header\n"), | |
21868 | arch.file_name); | |
015dc7e1 | 21869 | ret = false; |
1cb7d8b1 AM |
21870 | break; |
21871 | } | |
2cf0635d NC |
21872 | |
21873 | arch.next_arhdr_offset += sizeof arch.arhdr; | |
21874 | ||
978c4450 | 21875 | filedata->archive_file_size = strtoul (arch.arhdr.ar_size, NULL, 10); |
2cf0635d NC |
21876 | |
21877 | name = get_archive_member_name (&arch, &nested_arch); | |
21878 | if (name == NULL) | |
fb52b2f4 | 21879 | { |
28e817cc | 21880 | error (_("%s: bad archive file name\n"), arch.file_name); |
015dc7e1 | 21881 | ret = false; |
d989285c | 21882 | break; |
fb52b2f4 | 21883 | } |
2cf0635d | 21884 | namelen = strlen (name); |
fb52b2f4 | 21885 | |
2cf0635d NC |
21886 | qualified_name = make_qualified_name (&arch, &nested_arch, name); |
21887 | if (qualified_name == NULL) | |
fb52b2f4 | 21888 | { |
28e817cc | 21889 | error (_("%s: bad archive file name\n"), arch.file_name); |
fd486f32 | 21890 | free (name); |
015dc7e1 | 21891 | ret = false; |
d989285c | 21892 | break; |
fb52b2f4 NC |
21893 | } |
21894 | ||
2cf0635d | 21895 | if (is_thin_archive && arch.nested_member_origin == 0) |
1cb7d8b1 AM |
21896 | { |
21897 | /* This is a proxy for an external member of a thin archive. */ | |
21898 | Filedata * member_filedata; | |
21899 | char * member_file_name = adjust_relative_path | |
dda8d76d | 21900 | (filedata->file_name, name, namelen); |
32ec8896 | 21901 | |
fd486f32 | 21902 | free (name); |
1cb7d8b1 AM |
21903 | if (member_file_name == NULL) |
21904 | { | |
fd486f32 | 21905 | free (qualified_name); |
015dc7e1 | 21906 | ret = false; |
1cb7d8b1 AM |
21907 | break; |
21908 | } | |
2cf0635d | 21909 | |
015dc7e1 | 21910 | member_filedata = open_file (member_file_name, false); |
1cb7d8b1 AM |
21911 | if (member_filedata == NULL) |
21912 | { | |
21913 | error (_("Input file '%s' is not readable.\n"), member_file_name); | |
21914 | free (member_file_name); | |
fd486f32 | 21915 | free (qualified_name); |
015dc7e1 | 21916 | ret = false; |
1cb7d8b1 AM |
21917 | break; |
21918 | } | |
2cf0635d | 21919 | |
978c4450 | 21920 | filedata->archive_file_offset = arch.nested_member_origin; |
dda8d76d | 21921 | member_filedata->file_name = qualified_name; |
2cf0635d | 21922 | |
75a2da57 AH |
21923 | /* The call to process_object() expects the file to be at the beginning. */ |
21924 | rewind (member_filedata->handle); | |
21925 | ||
1cb7d8b1 | 21926 | if (! process_object (member_filedata)) |
015dc7e1 | 21927 | ret = false; |
2cf0635d | 21928 | |
1cb7d8b1 AM |
21929 | close_file (member_filedata); |
21930 | free (member_file_name); | |
1cb7d8b1 | 21931 | } |
2cf0635d | 21932 | else if (is_thin_archive) |
1cb7d8b1 AM |
21933 | { |
21934 | Filedata thin_filedata; | |
eb02c04d | 21935 | |
1cb7d8b1 | 21936 | memset (&thin_filedata, 0, sizeof (thin_filedata)); |
dda8d76d | 21937 | |
a043396b NC |
21938 | /* PR 15140: Allow for corrupt thin archives. */ |
21939 | if (nested_arch.file == NULL) | |
21940 | { | |
21941 | error (_("%s: contains corrupt thin archive: %s\n"), | |
28e817cc | 21942 | qualified_name, name); |
fd486f32 AM |
21943 | free (qualified_name); |
21944 | free (name); | |
015dc7e1 | 21945 | ret = false; |
a043396b NC |
21946 | break; |
21947 | } | |
fd486f32 | 21948 | free (name); |
a043396b | 21949 | |
1cb7d8b1 | 21950 | /* This is a proxy for a member of a nested archive. */ |
978c4450 AM |
21951 | filedata->archive_file_offset |
21952 | = arch.nested_member_origin + sizeof arch.arhdr; | |
2cf0635d | 21953 | |
1cb7d8b1 AM |
21954 | /* The nested archive file will have been opened and setup by |
21955 | get_archive_member_name. */ | |
978c4450 AM |
21956 | if (fseek (nested_arch.file, filedata->archive_file_offset, |
21957 | SEEK_SET) != 0) | |
1cb7d8b1 AM |
21958 | { |
21959 | error (_("%s: failed to seek to archive member.\n"), | |
21960 | nested_arch.file_name); | |
fd486f32 | 21961 | free (qualified_name); |
015dc7e1 | 21962 | ret = false; |
1cb7d8b1 AM |
21963 | break; |
21964 | } | |
2cf0635d | 21965 | |
dda8d76d NC |
21966 | thin_filedata.handle = nested_arch.file; |
21967 | thin_filedata.file_name = qualified_name; | |
9abca702 | 21968 | |
1cb7d8b1 | 21969 | if (! process_object (& thin_filedata)) |
015dc7e1 | 21970 | ret = false; |
1cb7d8b1 | 21971 | } |
2cf0635d | 21972 | else |
1cb7d8b1 | 21973 | { |
fd486f32 | 21974 | free (name); |
978c4450 | 21975 | filedata->archive_file_offset = arch.next_arhdr_offset; |
6a6196fc | 21976 | filedata->file_name = qualified_name; |
1cb7d8b1 | 21977 | if (! process_object (filedata)) |
015dc7e1 | 21978 | ret = false; |
237877b8 | 21979 | arch.next_arhdr_offset += (filedata->archive_file_size + 1) & -2; |
4c836627 | 21980 | /* Stop looping with "negative" archive_file_size. */ |
978c4450 | 21981 | if (arch.next_arhdr_offset < filedata->archive_file_size) |
80e2a3b6 | 21982 | arch.next_arhdr_offset = -1ul; |
1cb7d8b1 | 21983 | } |
fb52b2f4 | 21984 | |
2cf0635d | 21985 | free (qualified_name); |
fb52b2f4 NC |
21986 | } |
21987 | ||
4145f1d5 | 21988 | out: |
2cf0635d NC |
21989 | if (nested_arch.file != NULL) |
21990 | fclose (nested_arch.file); | |
21991 | release_archive (&nested_arch); | |
21992 | release_archive (&arch); | |
fb52b2f4 | 21993 | |
d989285c | 21994 | return ret; |
fb52b2f4 NC |
21995 | } |
21996 | ||
015dc7e1 | 21997 | static bool |
2cf0635d | 21998 | process_file (char * file_name) |
fb52b2f4 | 21999 | { |
dda8d76d | 22000 | Filedata * filedata = NULL; |
fb52b2f4 NC |
22001 | struct stat statbuf; |
22002 | char armag[SARMAG]; | |
015dc7e1 | 22003 | bool ret = true; |
fb52b2f4 NC |
22004 | |
22005 | if (stat (file_name, &statbuf) < 0) | |
22006 | { | |
f24ddbdd NC |
22007 | if (errno == ENOENT) |
22008 | error (_("'%s': No such file\n"), file_name); | |
22009 | else | |
22010 | error (_("Could not locate '%s'. System error message: %s\n"), | |
22011 | file_name, strerror (errno)); | |
015dc7e1 | 22012 | return false; |
f24ddbdd NC |
22013 | } |
22014 | ||
22015 | if (! S_ISREG (statbuf.st_mode)) | |
22016 | { | |
22017 | error (_("'%s' is not an ordinary file\n"), file_name); | |
015dc7e1 | 22018 | return false; |
fb52b2f4 NC |
22019 | } |
22020 | ||
dda8d76d NC |
22021 | filedata = calloc (1, sizeof * filedata); |
22022 | if (filedata == NULL) | |
22023 | { | |
22024 | error (_("Out of memory allocating file data structure\n")); | |
015dc7e1 | 22025 | return false; |
dda8d76d NC |
22026 | } |
22027 | ||
22028 | filedata->file_name = file_name; | |
22029 | filedata->handle = fopen (file_name, "rb"); | |
22030 | if (filedata->handle == NULL) | |
fb52b2f4 | 22031 | { |
f24ddbdd | 22032 | error (_("Input file '%s' is not readable.\n"), file_name); |
dda8d76d | 22033 | free (filedata); |
015dc7e1 | 22034 | return false; |
fb52b2f4 NC |
22035 | } |
22036 | ||
dda8d76d | 22037 | if (fread (armag, SARMAG, 1, filedata->handle) != 1) |
fb52b2f4 | 22038 | { |
4145f1d5 | 22039 | error (_("%s: Failed to read file's magic number\n"), file_name); |
dda8d76d NC |
22040 | fclose (filedata->handle); |
22041 | free (filedata); | |
015dc7e1 | 22042 | return false; |
fb52b2f4 NC |
22043 | } |
22044 | ||
dda8d76d | 22045 | filedata->file_size = (bfd_size_type) statbuf.st_size; |
015dc7e1 | 22046 | filedata->is_separate = false; |
f54498b4 | 22047 | |
fb52b2f4 | 22048 | if (memcmp (armag, ARMAG, SARMAG) == 0) |
32ec8896 | 22049 | { |
015dc7e1 AM |
22050 | if (! process_archive (filedata, false)) |
22051 | ret = false; | |
32ec8896 | 22052 | } |
2cf0635d | 22053 | else if (memcmp (armag, ARMAGT, SARMAG) == 0) |
32ec8896 | 22054 | { |
015dc7e1 AM |
22055 | if ( ! process_archive (filedata, true)) |
22056 | ret = false; | |
32ec8896 | 22057 | } |
fb52b2f4 NC |
22058 | else |
22059 | { | |
1b513401 | 22060 | if (do_archive_index && !check_all) |
4145f1d5 NC |
22061 | error (_("File %s is not an archive so its index cannot be displayed.\n"), |
22062 | file_name); | |
22063 | ||
dda8d76d | 22064 | rewind (filedata->handle); |
978c4450 | 22065 | filedata->archive_file_size = filedata->archive_file_offset = 0; |
32ec8896 | 22066 | |
dda8d76d | 22067 | if (! process_object (filedata)) |
015dc7e1 | 22068 | ret = false; |
fb52b2f4 NC |
22069 | } |
22070 | ||
dda8d76d | 22071 | fclose (filedata->handle); |
8fb879cd AM |
22072 | free (filedata->section_headers); |
22073 | free (filedata->program_headers); | |
22074 | free (filedata->string_table); | |
6431e409 | 22075 | free (filedata->dump.dump_sects); |
dda8d76d | 22076 | free (filedata); |
32ec8896 | 22077 | |
fd486f32 | 22078 | free (ba_cache.strtab); |
1bd6175a | 22079 | ba_cache.strtab = NULL; |
fd486f32 | 22080 | free (ba_cache.symtab); |
1bd6175a | 22081 | ba_cache.symtab = NULL; |
fd486f32 AM |
22082 | ba_cache.filedata = NULL; |
22083 | ||
fb52b2f4 NC |
22084 | return ret; |
22085 | } | |
22086 | ||
252b5132 RH |
22087 | #ifdef SUPPORT_DISASSEMBLY |
22088 | /* Needed by the i386 disassembler. For extra credit, someone could | |
9ea033b2 | 22089 | fix this so that we insert symbolic addresses here, esp for GOT/PLT |
e3c8793a | 22090 | symbols. */ |
252b5132 RH |
22091 | |
22092 | void | |
2cf0635d | 22093 | print_address (unsigned int addr, FILE * outfile) |
252b5132 RH |
22094 | { |
22095 | fprintf (outfile,"0x%8.8x", addr); | |
22096 | } | |
22097 | ||
e3c8793a | 22098 | /* Needed by the i386 disassembler. */ |
dda8d76d | 22099 | |
252b5132 RH |
22100 | void |
22101 | db_task_printsym (unsigned int addr) | |
22102 | { | |
22103 | print_address (addr, stderr); | |
22104 | } | |
22105 | #endif | |
22106 | ||
22107 | int | |
2cf0635d | 22108 | main (int argc, char ** argv) |
252b5132 | 22109 | { |
ff78d6d6 L |
22110 | int err; |
22111 | ||
87b9f255 | 22112 | #ifdef HAVE_LC_MESSAGES |
252b5132 | 22113 | setlocale (LC_MESSAGES, ""); |
3882b010 | 22114 | #endif |
3882b010 | 22115 | setlocale (LC_CTYPE, ""); |
252b5132 RH |
22116 | bindtextdomain (PACKAGE, LOCALEDIR); |
22117 | textdomain (PACKAGE); | |
22118 | ||
869b9d07 MM |
22119 | expandargv (&argc, &argv); |
22120 | ||
dda8d76d | 22121 | parse_args (& cmdline, argc, argv); |
59f14fc0 | 22122 | |
18bd398b | 22123 | if (optind < (argc - 1)) |
1b513401 NC |
22124 | /* When displaying information for more than one file, |
22125 | prefix the information with the file name. */ | |
015dc7e1 | 22126 | show_name = true; |
5656ba2c L |
22127 | else if (optind >= argc) |
22128 | { | |
1b513401 | 22129 | /* Ensure that the warning is always displayed. */ |
015dc7e1 | 22130 | do_checks = true; |
1b513401 | 22131 | |
5656ba2c L |
22132 | warn (_("Nothing to do.\n")); |
22133 | usage (stderr); | |
22134 | } | |
18bd398b | 22135 | |
015dc7e1 | 22136 | err = false; |
252b5132 | 22137 | while (optind < argc) |
32ec8896 | 22138 | if (! process_file (argv[optind++])) |
015dc7e1 | 22139 | err = true; |
252b5132 | 22140 | |
9db70fc3 | 22141 | free (cmdline.dump_sects); |
252b5132 | 22142 | |
7d9813f1 NA |
22143 | free (dump_ctf_symtab_name); |
22144 | free (dump_ctf_strtab_name); | |
22145 | free (dump_ctf_parent_name); | |
22146 | ||
32ec8896 | 22147 | return err ? EXIT_FAILURE : EXIT_SUCCESS; |
252b5132 | 22148 | } |