]>
Commit | Line | Data |
---|---|---|
1 | /* readelf.c -- display contents of an ELF format file | |
2 | Copyright (C) 1998-2021 Free Software Foundation, Inc. | |
3 | ||
4 | Originally developed by Eric Youngdale <eric@andante.jic.com> | |
5 | Modifications by Nick Clifton <nickc@redhat.com> | |
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 | |
11 | the Free Software Foundation; either version 3 of the License, or | |
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 | |
21 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA | |
22 | 02110-1301, USA. */ | |
23 | \f | |
24 | /* The difference between readelf and objdump: | |
25 | ||
26 | Both programs are capable of displaying the contents of ELF format files, | |
27 | so why does the binutils project have two file dumpers ? | |
28 | ||
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 | |
43 | #include "sysdep.h" | |
44 | #include <assert.h> | |
45 | #include <time.h> | |
46 | #include <zlib.h> | |
47 | #ifdef HAVE_WCHAR_H | |
48 | #include <wchar.h> | |
49 | #endif | |
50 | ||
51 | #if __GNUC__ >= 2 | |
52 | /* Define BFD64 here, even if our default architecture is 32 bit ELF | |
53 | as this will allow us to read in and parse 64bit and 32bit ELF files. | |
54 | Only do this if we believe that the compiler can support a 64 bit | |
55 | data type. For now we only rely on GCC being able to do this. */ | |
56 | #define BFD64 | |
57 | #endif | |
58 | ||
59 | #include "bfd.h" | |
60 | #include "bucomm.h" | |
61 | #include "elfcomm.h" | |
62 | #include "dwarf.h" | |
63 | #include "ctf-api.h" | |
64 | #include "demangle.h" | |
65 | ||
66 | #include "elf/common.h" | |
67 | #include "elf/external.h" | |
68 | #include "elf/internal.h" | |
69 | ||
70 | ||
71 | /* Included here, before RELOC_MACROS_GEN_FUNC is defined, so that | |
72 | we can obtain the H8 reloc numbers. We need these for the | |
73 | get_reloc_size() function. We include h8.h again after defining | |
74 | RELOC_MACROS_GEN_FUNC so that we get the naming function as well. */ | |
75 | ||
76 | #include "elf/h8.h" | |
77 | #undef _ELF_H8_H | |
78 | ||
79 | /* Undo the effects of #including reloc-macros.h. */ | |
80 | ||
81 | #undef START_RELOC_NUMBERS | |
82 | #undef RELOC_NUMBER | |
83 | #undef FAKE_RELOC | |
84 | #undef EMPTY_RELOC | |
85 | #undef END_RELOC_NUMBERS | |
86 | #undef _RELOC_MACROS_H | |
87 | ||
88 | /* The following headers use the elf/reloc-macros.h file to | |
89 | automatically generate relocation recognition functions | |
90 | such as elf_mips_reloc_type() */ | |
91 | ||
92 | #define RELOC_MACROS_GEN_FUNC | |
93 | ||
94 | #include "elf/aarch64.h" | |
95 | #include "elf/alpha.h" | |
96 | #include "elf/arc.h" | |
97 | #include "elf/arm.h" | |
98 | #include "elf/avr.h" | |
99 | #include "elf/bfin.h" | |
100 | #include "elf/cr16.h" | |
101 | #include "elf/cris.h" | |
102 | #include "elf/crx.h" | |
103 | #include "elf/csky.h" | |
104 | #include "elf/d10v.h" | |
105 | #include "elf/d30v.h" | |
106 | #include "elf/dlx.h" | |
107 | #include "elf/bpf.h" | |
108 | #include "elf/epiphany.h" | |
109 | #include "elf/fr30.h" | |
110 | #include "elf/frv.h" | |
111 | #include "elf/ft32.h" | |
112 | #include "elf/h8.h" | |
113 | #include "elf/hppa.h" | |
114 | #include "elf/i386.h" | |
115 | #include "elf/i370.h" | |
116 | #include "elf/i860.h" | |
117 | #include "elf/i960.h" | |
118 | #include "elf/ia64.h" | |
119 | #include "elf/ip2k.h" | |
120 | #include "elf/lm32.h" | |
121 | #include "elf/iq2000.h" | |
122 | #include "elf/m32c.h" | |
123 | #include "elf/m32r.h" | |
124 | #include "elf/m68k.h" | |
125 | #include "elf/m68hc11.h" | |
126 | #include "elf/s12z.h" | |
127 | #include "elf/mcore.h" | |
128 | #include "elf/mep.h" | |
129 | #include "elf/metag.h" | |
130 | #include "elf/microblaze.h" | |
131 | #include "elf/mips.h" | |
132 | #include "elf/mmix.h" | |
133 | #include "elf/mn10200.h" | |
134 | #include "elf/mn10300.h" | |
135 | #include "elf/moxie.h" | |
136 | #include "elf/mt.h" | |
137 | #include "elf/msp430.h" | |
138 | #include "elf/nds32.h" | |
139 | #include "elf/nfp.h" | |
140 | #include "elf/nios2.h" | |
141 | #include "elf/or1k.h" | |
142 | #include "elf/pj.h" | |
143 | #include "elf/ppc.h" | |
144 | #include "elf/ppc64.h" | |
145 | #include "elf/pru.h" | |
146 | #include "elf/riscv.h" | |
147 | #include "elf/rl78.h" | |
148 | #include "elf/rx.h" | |
149 | #include "elf/s390.h" | |
150 | #include "elf/score.h" | |
151 | #include "elf/sh.h" | |
152 | #include "elf/sparc.h" | |
153 | #include "elf/spu.h" | |
154 | #include "elf/tic6x.h" | |
155 | #include "elf/tilegx.h" | |
156 | #include "elf/tilepro.h" | |
157 | #include "elf/v850.h" | |
158 | #include "elf/vax.h" | |
159 | #include "elf/visium.h" | |
160 | #include "elf/wasm32.h" | |
161 | #include "elf/x86-64.h" | |
162 | #include "elf/xc16x.h" | |
163 | #include "elf/xgate.h" | |
164 | #include "elf/xstormy16.h" | |
165 | #include "elf/xtensa.h" | |
166 | #include "elf/z80.h" | |
167 | ||
168 | #include "getopt.h" | |
169 | #include "libiberty.h" | |
170 | #include "safe-ctype.h" | |
171 | #include "filenames.h" | |
172 | ||
173 | #ifndef offsetof | |
174 | #define offsetof(TYPE, MEMBER) ((size_t) &(((TYPE *) 0)->MEMBER)) | |
175 | #endif | |
176 | ||
177 | typedef struct elf_section_list | |
178 | { | |
179 | Elf_Internal_Shdr * hdr; | |
180 | struct elf_section_list * next; | |
181 | } elf_section_list; | |
182 | ||
183 | /* Flag bits indicating particular types of dump. */ | |
184 | #define HEX_DUMP (1 << 0) /* The -x command line switch. */ | |
185 | #define DISASS_DUMP (1 << 1) /* The -i command line switch. */ | |
186 | #define DEBUG_DUMP (1 << 2) /* The -w command line switch. */ | |
187 | #define STRING_DUMP (1 << 3) /* The -p command line switch. */ | |
188 | #define RELOC_DUMP (1 << 4) /* The -R command line switch. */ | |
189 | #define CTF_DUMP (1 << 5) /* The --ctf command line switch. */ | |
190 | ||
191 | typedef unsigned char dump_type; | |
192 | ||
193 | /* A linked list of the section names for which dumps were requested. */ | |
194 | struct dump_list_entry | |
195 | { | |
196 | char * name; | |
197 | dump_type type; | |
198 | struct dump_list_entry * next; | |
199 | }; | |
200 | ||
201 | /* A dynamic array of flags indicating for which sections a dump | |
202 | has been requested via command line switches. */ | |
203 | struct dump_data | |
204 | { | |
205 | dump_type * dump_sects; | |
206 | unsigned int num_dump_sects; | |
207 | }; | |
208 | ||
209 | static struct dump_data cmdline; | |
210 | ||
211 | static struct dump_list_entry * dump_sects_byname; | |
212 | ||
213 | char * program_name = "readelf"; | |
214 | ||
215 | static bfd_boolean show_name = FALSE; | |
216 | static bfd_boolean do_dynamic = FALSE; | |
217 | static bfd_boolean do_syms = FALSE; | |
218 | static bfd_boolean do_dyn_syms = FALSE; | |
219 | static bfd_boolean do_lto_syms = FALSE; | |
220 | static bfd_boolean do_reloc = FALSE; | |
221 | static bfd_boolean do_sections = FALSE; | |
222 | static bfd_boolean do_section_groups = FALSE; | |
223 | static bfd_boolean do_section_details = FALSE; | |
224 | static bfd_boolean do_segments = FALSE; | |
225 | static bfd_boolean do_unwind = FALSE; | |
226 | static bfd_boolean do_using_dynamic = FALSE; | |
227 | static bfd_boolean do_header = FALSE; | |
228 | static bfd_boolean do_dump = FALSE; | |
229 | static bfd_boolean do_version = FALSE; | |
230 | static bfd_boolean do_histogram = FALSE; | |
231 | static bfd_boolean do_debugging = FALSE; | |
232 | static bfd_boolean do_ctf = FALSE; | |
233 | static bfd_boolean do_arch = FALSE; | |
234 | static bfd_boolean do_notes = FALSE; | |
235 | static bfd_boolean do_archive_index = FALSE; | |
236 | static bfd_boolean check_all = FALSE; | |
237 | static bfd_boolean is_32bit_elf = FALSE; | |
238 | static bfd_boolean decompress_dumps = FALSE; | |
239 | static bfd_boolean do_not_show_symbol_truncation = FALSE; | |
240 | static bfd_boolean do_demangle = FALSE; /* Pretty print C++ symbol names. */ | |
241 | static bfd_boolean process_links = FALSE; | |
242 | static int demangle_flags = DMGL_ANSI | DMGL_PARAMS; | |
243 | ||
244 | static char *dump_ctf_parent_name; | |
245 | static char *dump_ctf_symtab_name; | |
246 | static char *dump_ctf_strtab_name; | |
247 | ||
248 | struct group_list | |
249 | { | |
250 | struct group_list * next; | |
251 | unsigned int section_index; | |
252 | }; | |
253 | ||
254 | struct group | |
255 | { | |
256 | struct group_list * root; | |
257 | unsigned int group_index; | |
258 | }; | |
259 | ||
260 | typedef struct filedata | |
261 | { | |
262 | const char * file_name; | |
263 | bfd_boolean is_separate; | |
264 | FILE * handle; | |
265 | bfd_size_type file_size; | |
266 | Elf_Internal_Ehdr file_header; | |
267 | Elf_Internal_Shdr * section_headers; | |
268 | Elf_Internal_Phdr * program_headers; | |
269 | char * string_table; | |
270 | unsigned long string_table_length; | |
271 | unsigned long archive_file_offset; | |
272 | unsigned long archive_file_size; | |
273 | unsigned long dynamic_addr; | |
274 | bfd_size_type dynamic_size; | |
275 | size_t dynamic_nent; | |
276 | Elf_Internal_Dyn * dynamic_section; | |
277 | Elf_Internal_Shdr * dynamic_strtab_section; | |
278 | char * dynamic_strings; | |
279 | unsigned long dynamic_strings_length; | |
280 | Elf_Internal_Shdr * dynamic_symtab_section; | |
281 | unsigned long num_dynamic_syms; | |
282 | Elf_Internal_Sym * dynamic_symbols; | |
283 | bfd_vma version_info[16]; | |
284 | unsigned int dynamic_syminfo_nent; | |
285 | Elf_Internal_Syminfo * dynamic_syminfo; | |
286 | unsigned long dynamic_syminfo_offset; | |
287 | bfd_size_type nbuckets; | |
288 | bfd_size_type nchains; | |
289 | bfd_vma * buckets; | |
290 | bfd_vma * chains; | |
291 | bfd_size_type ngnubuckets; | |
292 | bfd_size_type ngnuchains; | |
293 | bfd_vma * gnubuckets; | |
294 | bfd_vma * gnuchains; | |
295 | bfd_vma * mipsxlat; | |
296 | bfd_vma gnusymidx; | |
297 | char program_interpreter[PATH_MAX]; | |
298 | bfd_vma dynamic_info[DT_ENCODING]; | |
299 | bfd_vma dynamic_info_DT_GNU_HASH; | |
300 | bfd_vma dynamic_info_DT_MIPS_XHASH; | |
301 | elf_section_list * symtab_shndx_list; | |
302 | size_t group_count; | |
303 | struct group * section_groups; | |
304 | struct group ** section_headers_groups; | |
305 | /* A dynamic array of flags indicating for which sections a dump of | |
306 | some kind has been requested. It is reset on a per-object file | |
307 | basis and then initialised from the cmdline_dump_sects array, | |
308 | the results of interpreting the -w switch, and the | |
309 | dump_sects_byname list. */ | |
310 | struct dump_data dump; | |
311 | } Filedata; | |
312 | ||
313 | /* How to print a vma value. */ | |
314 | typedef enum print_mode | |
315 | { | |
316 | HEX, | |
317 | DEC, | |
318 | DEC_5, | |
319 | UNSIGNED, | |
320 | PREFIX_HEX, | |
321 | FULL_HEX, | |
322 | LONG_HEX | |
323 | } | |
324 | print_mode; | |
325 | ||
326 | /* Versioned symbol info. */ | |
327 | enum versioned_symbol_info | |
328 | { | |
329 | symbol_undefined, | |
330 | symbol_hidden, | |
331 | symbol_public | |
332 | }; | |
333 | ||
334 | static const char * get_symbol_version_string | |
335 | (Filedata *, bfd_boolean, const char *, unsigned long, unsigned, | |
336 | Elf_Internal_Sym *, enum versioned_symbol_info *, unsigned short *); | |
337 | ||
338 | #define UNKNOWN -1 | |
339 | ||
340 | #define SECTION_NAME(X) \ | |
341 | (filedata->string_table + (X)->sh_name) | |
342 | ||
343 | #define SECTION_NAME_VALID(X) \ | |
344 | ((X) != NULL \ | |
345 | && filedata->string_table != NULL \ | |
346 | && (X)->sh_name < filedata->string_table_length) | |
347 | ||
348 | #define SECTION_NAME_PRINT(X) \ | |
349 | ((X) == NULL ? _("<none>") \ | |
350 | : filedata->string_table == NULL ? _("<no-strings>") \ | |
351 | : (X)->sh_name >= filedata->string_table_length ? _("<corrupt>") \ | |
352 | : filedata->string_table + (X)->sh_name) | |
353 | ||
354 | #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */ | |
355 | ||
356 | #define GET_ELF_SYMBOLS(file, section, sym_count) \ | |
357 | (is_32bit_elf ? get_32bit_elf_symbols (file, section, sym_count) \ | |
358 | : get_64bit_elf_symbols (file, section, sym_count)) | |
359 | ||
360 | #define VALID_SYMBOL_NAME(strtab, strtab_size, offset) \ | |
361 | (strtab != NULL && offset < strtab_size) | |
362 | #define VALID_DYNAMIC_NAME(filedata, offset) \ | |
363 | VALID_SYMBOL_NAME (filedata->dynamic_strings, \ | |
364 | filedata->dynamic_strings_length, offset) | |
365 | /* GET_DYNAMIC_NAME asssumes that VALID_DYNAMIC_NAME has | |
366 | already been called and verified that the string exists. */ | |
367 | #define GET_DYNAMIC_NAME(filedata, offset) \ | |
368 | (filedata->dynamic_strings + offset) | |
369 | ||
370 | #define REMOVE_ARCH_BITS(ADDR) \ | |
371 | do \ | |
372 | { \ | |
373 | if (filedata->file_header.e_machine == EM_ARM) \ | |
374 | (ADDR) &= ~1; \ | |
375 | } \ | |
376 | while (0) | |
377 | ||
378 | /* Get the correct GNU hash section name. */ | |
379 | #define GNU_HASH_SECTION_NAME(filedata) \ | |
380 | filedata->dynamic_info_DT_MIPS_XHASH ? ".MIPS.xhash" : ".gnu.hash" | |
381 | \f | |
382 | /* Print a BFD_VMA to an internal buffer, for use in error messages. | |
383 | BFD_FMA_FMT can't be used in translated strings. */ | |
384 | ||
385 | static const char * | |
386 | bfd_vmatoa (char *fmtch, bfd_vma value) | |
387 | { | |
388 | /* bfd_vmatoa is used more then once in a printf call for output. | |
389 | Cycle through an array of buffers. */ | |
390 | static int buf_pos = 0; | |
391 | static struct bfd_vmatoa_buf | |
392 | { | |
393 | char place[64]; | |
394 | } buf[4]; | |
395 | char *ret; | |
396 | char fmt[32]; | |
397 | ||
398 | ret = buf[buf_pos++].place; | |
399 | buf_pos %= ARRAY_SIZE (buf); | |
400 | ||
401 | sprintf (fmt, "%%%s%s", BFD_VMA_FMT, fmtch); | |
402 | snprintf (ret, sizeof (buf[0].place), fmt, value); | |
403 | return ret; | |
404 | } | |
405 | ||
406 | /* Retrieve NMEMB structures, each SIZE bytes long from FILEDATA starting at | |
407 | OFFSET + the offset of the current archive member, if we are examining an | |
408 | archive. Put the retrieved data into VAR, if it is not NULL. Otherwise | |
409 | allocate a buffer using malloc and fill that. In either case return the | |
410 | pointer to the start of the retrieved data or NULL if something went wrong. | |
411 | If something does go wrong and REASON is not NULL then emit an error | |
412 | message using REASON as part of the context. */ | |
413 | ||
414 | static void * | |
415 | get_data (void * var, | |
416 | Filedata * filedata, | |
417 | unsigned long offset, | |
418 | bfd_size_type size, | |
419 | bfd_size_type nmemb, | |
420 | const char * reason) | |
421 | { | |
422 | void * mvar; | |
423 | bfd_size_type amt = size * nmemb; | |
424 | ||
425 | if (size == 0 || nmemb == 0) | |
426 | return NULL; | |
427 | ||
428 | /* If the size_t type is smaller than the bfd_size_type, eg because | |
429 | you are building a 32-bit tool on a 64-bit host, then make sure | |
430 | that when the sizes are cast to (size_t) no information is lost. */ | |
431 | if ((size_t) size != size | |
432 | || (size_t) nmemb != nmemb | |
433 | || (size_t) amt != amt) | |
434 | { | |
435 | if (reason) | |
436 | error (_("Size truncation prevents reading %s" | |
437 | " elements of size %s for %s\n"), | |
438 | bfd_vmatoa ("u", nmemb), bfd_vmatoa ("u", size), reason); | |
439 | return NULL; | |
440 | } | |
441 | ||
442 | /* Check for size overflow. */ | |
443 | if (amt / size != nmemb || (size_t) amt + 1 == 0) | |
444 | { | |
445 | if (reason) | |
446 | error (_("Size overflow prevents reading %s" | |
447 | " elements of size %s for %s\n"), | |
448 | bfd_vmatoa ("u", nmemb), bfd_vmatoa ("u", size), reason); | |
449 | return NULL; | |
450 | } | |
451 | ||
452 | /* Be kind to memory checkers (eg valgrind, address sanitizer) by not | |
453 | attempting to allocate memory when the read is bound to fail. */ | |
454 | if (filedata->archive_file_offset > filedata->file_size | |
455 | || offset > filedata->file_size - filedata->archive_file_offset | |
456 | || amt > filedata->file_size - filedata->archive_file_offset - offset) | |
457 | { | |
458 | if (reason) | |
459 | error (_("Reading %s bytes extends past end of file for %s\n"), | |
460 | bfd_vmatoa ("u", amt), reason); | |
461 | return NULL; | |
462 | } | |
463 | ||
464 | if (fseek (filedata->handle, filedata->archive_file_offset + offset, | |
465 | SEEK_SET)) | |
466 | { | |
467 | if (reason) | |
468 | error (_("Unable to seek to 0x%lx for %s\n"), | |
469 | filedata->archive_file_offset + offset, reason); | |
470 | return NULL; | |
471 | } | |
472 | ||
473 | mvar = var; | |
474 | if (mvar == NULL) | |
475 | { | |
476 | /* + 1 so that we can '\0' terminate invalid string table sections. */ | |
477 | mvar = malloc ((size_t) amt + 1); | |
478 | ||
479 | if (mvar == NULL) | |
480 | { | |
481 | if (reason) | |
482 | error (_("Out of memory allocating %s bytes for %s\n"), | |
483 | bfd_vmatoa ("u", amt), reason); | |
484 | return NULL; | |
485 | } | |
486 | ||
487 | ((char *) mvar)[amt] = '\0'; | |
488 | } | |
489 | ||
490 | if (fread (mvar, (size_t) size, (size_t) nmemb, filedata->handle) != nmemb) | |
491 | { | |
492 | if (reason) | |
493 | error (_("Unable to read in %s bytes of %s\n"), | |
494 | bfd_vmatoa ("u", amt), reason); | |
495 | if (mvar != var) | |
496 | free (mvar); | |
497 | return NULL; | |
498 | } | |
499 | ||
500 | return mvar; | |
501 | } | |
502 | ||
503 | /* Print a VMA value in the MODE specified. | |
504 | Returns the number of characters displayed. */ | |
505 | ||
506 | static unsigned int | |
507 | print_vma (bfd_vma vma, print_mode mode) | |
508 | { | |
509 | unsigned int nc = 0; | |
510 | ||
511 | switch (mode) | |
512 | { | |
513 | case FULL_HEX: | |
514 | nc = printf ("0x"); | |
515 | /* Fall through. */ | |
516 | case LONG_HEX: | |
517 | #ifdef BFD64 | |
518 | if (is_32bit_elf) | |
519 | return nc + printf ("%8.8" BFD_VMA_FMT "x", vma); | |
520 | #endif | |
521 | printf_vma (vma); | |
522 | return nc + 16; | |
523 | ||
524 | case DEC_5: | |
525 | if (vma <= 99999) | |
526 | return printf ("%5" BFD_VMA_FMT "d", vma); | |
527 | /* Fall through. */ | |
528 | case PREFIX_HEX: | |
529 | nc = printf ("0x"); | |
530 | /* Fall through. */ | |
531 | case HEX: | |
532 | return nc + printf ("%" BFD_VMA_FMT "x", vma); | |
533 | ||
534 | case DEC: | |
535 | return printf ("%" BFD_VMA_FMT "d", vma); | |
536 | ||
537 | case UNSIGNED: | |
538 | return printf ("%" BFD_VMA_FMT "u", vma); | |
539 | ||
540 | default: | |
541 | /* FIXME: Report unrecognised mode ? */ | |
542 | return 0; | |
543 | } | |
544 | } | |
545 | ||
546 | /* Display a symbol on stdout. Handles the display of control characters and | |
547 | multibye characters (assuming the host environment supports them). | |
548 | ||
549 | Display at most abs(WIDTH) characters, truncating as necessary, unless do_wide is true. | |
550 | ||
551 | If truncation will happen and do_not_show_symbol_truncation is FALSE then display | |
552 | abs(WIDTH) - 5 characters followed by "[...]". | |
553 | ||
554 | If WIDTH is negative then ensure that the output is at least (- WIDTH) characters, | |
555 | padding as necessary. | |
556 | ||
557 | Returns the number of emitted characters. */ | |
558 | ||
559 | static unsigned int | |
560 | print_symbol (signed int width, const char * symbol) | |
561 | { | |
562 | bfd_boolean extra_padding = FALSE; | |
563 | bfd_boolean do_dots = FALSE; | |
564 | signed int num_printed = 0; | |
565 | #ifdef HAVE_MBSTATE_T | |
566 | mbstate_t state; | |
567 | #endif | |
568 | unsigned int width_remaining; | |
569 | const void * alloced_symbol = NULL; | |
570 | ||
571 | if (width < 0) | |
572 | { | |
573 | /* Keep the width positive. This helps the code below. */ | |
574 | width = - width; | |
575 | extra_padding = TRUE; | |
576 | } | |
577 | else if (width == 0) | |
578 | return 0; | |
579 | ||
580 | if (do_wide) | |
581 | /* Set the remaining width to a very large value. | |
582 | This simplifies the code below. */ | |
583 | width_remaining = INT_MAX; | |
584 | else | |
585 | { | |
586 | width_remaining = width; | |
587 | if (! do_not_show_symbol_truncation | |
588 | && (int) strlen (symbol) > width) | |
589 | { | |
590 | width_remaining -= 5; | |
591 | if ((int) width_remaining < 0) | |
592 | width_remaining = 0; | |
593 | do_dots = TRUE; | |
594 | } | |
595 | } | |
596 | ||
597 | #ifdef HAVE_MBSTATE_T | |
598 | /* Initialise the multibyte conversion state. */ | |
599 | memset (& state, 0, sizeof (state)); | |
600 | #endif | |
601 | ||
602 | if (do_demangle && *symbol) | |
603 | { | |
604 | const char * res = cplus_demangle (symbol, demangle_flags); | |
605 | ||
606 | if (res != NULL) | |
607 | alloced_symbol = symbol = res; | |
608 | } | |
609 | ||
610 | while (width_remaining) | |
611 | { | |
612 | size_t n; | |
613 | const char c = *symbol++; | |
614 | ||
615 | if (c == 0) | |
616 | break; | |
617 | ||
618 | /* Do not print control characters directly as they can affect terminal | |
619 | settings. Such characters usually appear in the names generated | |
620 | by the assembler for local labels. */ | |
621 | if (ISCNTRL (c)) | |
622 | { | |
623 | if (width_remaining < 2) | |
624 | break; | |
625 | ||
626 | printf ("^%c", c + 0x40); | |
627 | width_remaining -= 2; | |
628 | num_printed += 2; | |
629 | } | |
630 | else if (ISPRINT (c)) | |
631 | { | |
632 | putchar (c); | |
633 | width_remaining --; | |
634 | num_printed ++; | |
635 | } | |
636 | else | |
637 | { | |
638 | #ifdef HAVE_MBSTATE_T | |
639 | wchar_t w; | |
640 | #endif | |
641 | /* Let printf do the hard work of displaying multibyte characters. */ | |
642 | printf ("%.1s", symbol - 1); | |
643 | width_remaining --; | |
644 | num_printed ++; | |
645 | ||
646 | #ifdef HAVE_MBSTATE_T | |
647 | /* Try to find out how many bytes made up the character that was | |
648 | just printed. Advance the symbol pointer past the bytes that | |
649 | were displayed. */ | |
650 | n = mbrtowc (& w, symbol - 1, MB_CUR_MAX, & state); | |
651 | #else | |
652 | n = 1; | |
653 | #endif | |
654 | if (n != (size_t) -1 && n != (size_t) -2 && n > 0) | |
655 | symbol += (n - 1); | |
656 | } | |
657 | } | |
658 | ||
659 | if (do_dots) | |
660 | num_printed += printf ("[...]"); | |
661 | ||
662 | if (extra_padding && num_printed < width) | |
663 | { | |
664 | /* Fill in the remaining spaces. */ | |
665 | printf ("%-*s", width - num_printed, " "); | |
666 | num_printed = width; | |
667 | } | |
668 | ||
669 | free ((void *) alloced_symbol); | |
670 | return num_printed; | |
671 | } | |
672 | ||
673 | /* Returns a pointer to a static buffer containing a printable version of | |
674 | the given section's name. Like print_symbol, except that it does not try | |
675 | to print multibyte characters, it just interprets them as hex values. */ | |
676 | ||
677 | static const char * | |
678 | printable_section_name (Filedata * filedata, const Elf_Internal_Shdr * sec) | |
679 | { | |
680 | #define MAX_PRINT_SEC_NAME_LEN 256 | |
681 | static char sec_name_buf [MAX_PRINT_SEC_NAME_LEN + 1]; | |
682 | const char * name = SECTION_NAME_PRINT (sec); | |
683 | char * buf = sec_name_buf; | |
684 | char c; | |
685 | unsigned int remaining = MAX_PRINT_SEC_NAME_LEN; | |
686 | ||
687 | while ((c = * name ++) != 0) | |
688 | { | |
689 | if (ISCNTRL (c)) | |
690 | { | |
691 | if (remaining < 2) | |
692 | break; | |
693 | ||
694 | * buf ++ = '^'; | |
695 | * buf ++ = c + 0x40; | |
696 | remaining -= 2; | |
697 | } | |
698 | else if (ISPRINT (c)) | |
699 | { | |
700 | * buf ++ = c; | |
701 | remaining -= 1; | |
702 | } | |
703 | else | |
704 | { | |
705 | static char hex[17] = "0123456789ABCDEF"; | |
706 | ||
707 | if (remaining < 4) | |
708 | break; | |
709 | * buf ++ = '<'; | |
710 | * buf ++ = hex[(c & 0xf0) >> 4]; | |
711 | * buf ++ = hex[c & 0x0f]; | |
712 | * buf ++ = '>'; | |
713 | remaining -= 4; | |
714 | } | |
715 | ||
716 | if (remaining == 0) | |
717 | break; | |
718 | } | |
719 | ||
720 | * buf = 0; | |
721 | return sec_name_buf; | |
722 | } | |
723 | ||
724 | static const char * | |
725 | printable_section_name_from_index (Filedata * filedata, unsigned long ndx) | |
726 | { | |
727 | if (ndx >= filedata->file_header.e_shnum) | |
728 | return _("<corrupt>"); | |
729 | ||
730 | return printable_section_name (filedata, filedata->section_headers + ndx); | |
731 | } | |
732 | ||
733 | /* Return a pointer to section NAME, or NULL if no such section exists. */ | |
734 | ||
735 | static Elf_Internal_Shdr * | |
736 | find_section (Filedata * filedata, const char * name) | |
737 | { | |
738 | unsigned int i; | |
739 | ||
740 | if (filedata->section_headers == NULL) | |
741 | return NULL; | |
742 | ||
743 | for (i = 0; i < filedata->file_header.e_shnum; i++) | |
744 | if (SECTION_NAME_VALID (filedata->section_headers + i) | |
745 | && streq (SECTION_NAME (filedata->section_headers + i), name)) | |
746 | return filedata->section_headers + i; | |
747 | ||
748 | return NULL; | |
749 | } | |
750 | ||
751 | /* Return a pointer to a section containing ADDR, or NULL if no such | |
752 | section exists. */ | |
753 | ||
754 | static Elf_Internal_Shdr * | |
755 | find_section_by_address (Filedata * filedata, bfd_vma addr) | |
756 | { | |
757 | unsigned int i; | |
758 | ||
759 | if (filedata->section_headers == NULL) | |
760 | return NULL; | |
761 | ||
762 | for (i = 0; i < filedata->file_header.e_shnum; i++) | |
763 | { | |
764 | Elf_Internal_Shdr *sec = filedata->section_headers + i; | |
765 | ||
766 | if (addr >= sec->sh_addr && addr < sec->sh_addr + sec->sh_size) | |
767 | return sec; | |
768 | } | |
769 | ||
770 | return NULL; | |
771 | } | |
772 | ||
773 | static Elf_Internal_Shdr * | |
774 | find_section_by_type (Filedata * filedata, unsigned int type) | |
775 | { | |
776 | unsigned int i; | |
777 | ||
778 | if (filedata->section_headers == NULL) | |
779 | return NULL; | |
780 | ||
781 | for (i = 0; i < filedata->file_header.e_shnum; i++) | |
782 | { | |
783 | Elf_Internal_Shdr *sec = filedata->section_headers + i; | |
784 | ||
785 | if (sec->sh_type == type) | |
786 | return sec; | |
787 | } | |
788 | ||
789 | return NULL; | |
790 | } | |
791 | ||
792 | /* Return a pointer to section NAME, or NULL if no such section exists, | |
793 | restricted to the list of sections given in SET. */ | |
794 | ||
795 | static Elf_Internal_Shdr * | |
796 | find_section_in_set (Filedata * filedata, const char * name, unsigned int * set) | |
797 | { | |
798 | unsigned int i; | |
799 | ||
800 | if (filedata->section_headers == NULL) | |
801 | return NULL; | |
802 | ||
803 | if (set != NULL) | |
804 | { | |
805 | while ((i = *set++) > 0) | |
806 | { | |
807 | /* See PR 21156 for a reproducer. */ | |
808 | if (i >= filedata->file_header.e_shnum) | |
809 | continue; /* FIXME: Should we issue an error message ? */ | |
810 | ||
811 | if (SECTION_NAME_VALID (filedata->section_headers + i) | |
812 | && streq (SECTION_NAME (filedata->section_headers + i), name)) | |
813 | return filedata->section_headers + i; | |
814 | } | |
815 | } | |
816 | ||
817 | return find_section (filedata, name); | |
818 | } | |
819 | ||
820 | /* Return TRUE if the current file is for IA-64 machine and OpenVMS ABI. | |
821 | This OS has so many departures from the ELF standard that we test it at | |
822 | many places. */ | |
823 | ||
824 | static inline bfd_boolean | |
825 | is_ia64_vms (Filedata * filedata) | |
826 | { | |
827 | return filedata->file_header.e_machine == EM_IA_64 | |
828 | && filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_OPENVMS; | |
829 | } | |
830 | ||
831 | /* Guess the relocation size commonly used by the specific machines. */ | |
832 | ||
833 | static bfd_boolean | |
834 | guess_is_rela (unsigned int e_machine) | |
835 | { | |
836 | switch (e_machine) | |
837 | { | |
838 | /* Targets that use REL relocations. */ | |
839 | case EM_386: | |
840 | case EM_IAMCU: | |
841 | case EM_960: | |
842 | case EM_ARM: | |
843 | case EM_D10V: | |
844 | case EM_CYGNUS_D10V: | |
845 | case EM_DLX: | |
846 | case EM_MIPS: | |
847 | case EM_MIPS_RS3_LE: | |
848 | case EM_CYGNUS_M32R: | |
849 | case EM_SCORE: | |
850 | case EM_XGATE: | |
851 | case EM_NFP: | |
852 | case EM_BPF: | |
853 | return FALSE; | |
854 | ||
855 | /* Targets that use RELA relocations. */ | |
856 | case EM_68K: | |
857 | case EM_860: | |
858 | case EM_AARCH64: | |
859 | case EM_ADAPTEVA_EPIPHANY: | |
860 | case EM_ALPHA: | |
861 | case EM_ALTERA_NIOS2: | |
862 | case EM_ARC: | |
863 | case EM_ARC_COMPACT: | |
864 | case EM_ARC_COMPACT2: | |
865 | case EM_AVR: | |
866 | case EM_AVR_OLD: | |
867 | case EM_BLACKFIN: | |
868 | case EM_CR16: | |
869 | case EM_CRIS: | |
870 | case EM_CRX: | |
871 | case EM_CSKY: | |
872 | case EM_D30V: | |
873 | case EM_CYGNUS_D30V: | |
874 | case EM_FR30: | |
875 | case EM_FT32: | |
876 | case EM_CYGNUS_FR30: | |
877 | case EM_CYGNUS_FRV: | |
878 | case EM_H8S: | |
879 | case EM_H8_300: | |
880 | case EM_H8_300H: | |
881 | case EM_IA_64: | |
882 | case EM_IP2K: | |
883 | case EM_IP2K_OLD: | |
884 | case EM_IQ2000: | |
885 | case EM_LATTICEMICO32: | |
886 | case EM_M32C_OLD: | |
887 | case EM_M32C: | |
888 | case EM_M32R: | |
889 | case EM_MCORE: | |
890 | case EM_CYGNUS_MEP: | |
891 | case EM_METAG: | |
892 | case EM_MMIX: | |
893 | case EM_MN10200: | |
894 | case EM_CYGNUS_MN10200: | |
895 | case EM_MN10300: | |
896 | case EM_CYGNUS_MN10300: | |
897 | case EM_MOXIE: | |
898 | case EM_MSP430: | |
899 | case EM_MSP430_OLD: | |
900 | case EM_MT: | |
901 | case EM_NDS32: | |
902 | case EM_NIOS32: | |
903 | case EM_OR1K: | |
904 | case EM_PPC64: | |
905 | case EM_PPC: | |
906 | case EM_TI_PRU: | |
907 | case EM_RISCV: | |
908 | case EM_RL78: | |
909 | case EM_RX: | |
910 | case EM_S390: | |
911 | case EM_S390_OLD: | |
912 | case EM_SH: | |
913 | case EM_SPARC: | |
914 | case EM_SPARC32PLUS: | |
915 | case EM_SPARCV9: | |
916 | case EM_SPU: | |
917 | case EM_TI_C6000: | |
918 | case EM_TILEGX: | |
919 | case EM_TILEPRO: | |
920 | case EM_V800: | |
921 | case EM_V850: | |
922 | case EM_CYGNUS_V850: | |
923 | case EM_VAX: | |
924 | case EM_VISIUM: | |
925 | case EM_X86_64: | |
926 | case EM_L1OM: | |
927 | case EM_K1OM: | |
928 | case EM_XSTORMY16: | |
929 | case EM_XTENSA: | |
930 | case EM_XTENSA_OLD: | |
931 | case EM_MICROBLAZE: | |
932 | case EM_MICROBLAZE_OLD: | |
933 | case EM_WEBASSEMBLY: | |
934 | return TRUE; | |
935 | ||
936 | case EM_68HC05: | |
937 | case EM_68HC08: | |
938 | case EM_68HC11: | |
939 | case EM_68HC16: | |
940 | case EM_FX66: | |
941 | case EM_ME16: | |
942 | case EM_MMA: | |
943 | case EM_NCPU: | |
944 | case EM_NDR1: | |
945 | case EM_PCP: | |
946 | case EM_ST100: | |
947 | case EM_ST19: | |
948 | case EM_ST7: | |
949 | case EM_ST9PLUS: | |
950 | case EM_STARCORE: | |
951 | case EM_SVX: | |
952 | case EM_TINYJ: | |
953 | default: | |
954 | warn (_("Don't know about relocations on this machine architecture\n")); | |
955 | return FALSE; | |
956 | } | |
957 | } | |
958 | ||
959 | /* Load RELA type relocations from FILEDATA at REL_OFFSET extending for REL_SIZE bytes. | |
960 | Returns TRUE upon success, FALSE otherwise. If successful then a | |
961 | pointer to a malloc'ed buffer containing the relocs is placed in *RELASP, | |
962 | and the number of relocs loaded is placed in *NRELASP. It is the caller's | |
963 | responsibility to free the allocated buffer. */ | |
964 | ||
965 | static bfd_boolean | |
966 | slurp_rela_relocs (Filedata * filedata, | |
967 | unsigned long rel_offset, | |
968 | unsigned long rel_size, | |
969 | Elf_Internal_Rela ** relasp, | |
970 | unsigned long * nrelasp) | |
971 | { | |
972 | Elf_Internal_Rela * relas; | |
973 | size_t nrelas; | |
974 | unsigned int i; | |
975 | ||
976 | if (is_32bit_elf) | |
977 | { | |
978 | Elf32_External_Rela * erelas; | |
979 | ||
980 | erelas = (Elf32_External_Rela *) get_data (NULL, filedata, rel_offset, 1, | |
981 | rel_size, _("32-bit relocation data")); | |
982 | if (!erelas) | |
983 | return FALSE; | |
984 | ||
985 | nrelas = rel_size / sizeof (Elf32_External_Rela); | |
986 | ||
987 | relas = (Elf_Internal_Rela *) cmalloc (nrelas, | |
988 | sizeof (Elf_Internal_Rela)); | |
989 | ||
990 | if (relas == NULL) | |
991 | { | |
992 | free (erelas); | |
993 | error (_("out of memory parsing relocs\n")); | |
994 | return FALSE; | |
995 | } | |
996 | ||
997 | for (i = 0; i < nrelas; i++) | |
998 | { | |
999 | relas[i].r_offset = BYTE_GET (erelas[i].r_offset); | |
1000 | relas[i].r_info = BYTE_GET (erelas[i].r_info); | |
1001 | relas[i].r_addend = BYTE_GET_SIGNED (erelas[i].r_addend); | |
1002 | } | |
1003 | ||
1004 | free (erelas); | |
1005 | } | |
1006 | else | |
1007 | { | |
1008 | Elf64_External_Rela * erelas; | |
1009 | ||
1010 | erelas = (Elf64_External_Rela *) get_data (NULL, filedata, rel_offset, 1, | |
1011 | rel_size, _("64-bit relocation data")); | |
1012 | if (!erelas) | |
1013 | return FALSE; | |
1014 | ||
1015 | nrelas = rel_size / sizeof (Elf64_External_Rela); | |
1016 | ||
1017 | relas = (Elf_Internal_Rela *) cmalloc (nrelas, | |
1018 | sizeof (Elf_Internal_Rela)); | |
1019 | ||
1020 | if (relas == NULL) | |
1021 | { | |
1022 | free (erelas); | |
1023 | error (_("out of memory parsing relocs\n")); | |
1024 | return FALSE; | |
1025 | } | |
1026 | ||
1027 | for (i = 0; i < nrelas; i++) | |
1028 | { | |
1029 | relas[i].r_offset = BYTE_GET (erelas[i].r_offset); | |
1030 | relas[i].r_info = BYTE_GET (erelas[i].r_info); | |
1031 | relas[i].r_addend = BYTE_GET_SIGNED (erelas[i].r_addend); | |
1032 | ||
1033 | /* The #ifdef BFD64 below is to prevent a compile time | |
1034 | warning. We know that if we do not have a 64 bit data | |
1035 | type that we will never execute this code anyway. */ | |
1036 | #ifdef BFD64 | |
1037 | if (filedata->file_header.e_machine == EM_MIPS | |
1038 | && filedata->file_header.e_ident[EI_DATA] != ELFDATA2MSB) | |
1039 | { | |
1040 | /* In little-endian objects, r_info isn't really a | |
1041 | 64-bit little-endian value: it has a 32-bit | |
1042 | little-endian symbol index followed by four | |
1043 | individual byte fields. Reorder INFO | |
1044 | accordingly. */ | |
1045 | bfd_vma inf = relas[i].r_info; | |
1046 | inf = (((inf & 0xffffffff) << 32) | |
1047 | | ((inf >> 56) & 0xff) | |
1048 | | ((inf >> 40) & 0xff00) | |
1049 | | ((inf >> 24) & 0xff0000) | |
1050 | | ((inf >> 8) & 0xff000000)); | |
1051 | relas[i].r_info = inf; | |
1052 | } | |
1053 | #endif /* BFD64 */ | |
1054 | } | |
1055 | ||
1056 | free (erelas); | |
1057 | } | |
1058 | ||
1059 | *relasp = relas; | |
1060 | *nrelasp = nrelas; | |
1061 | return TRUE; | |
1062 | } | |
1063 | ||
1064 | /* Load REL type relocations from FILEDATA at REL_OFFSET extending for REL_SIZE bytes. | |
1065 | Returns TRUE upon success, FALSE otherwise. If successful then a | |
1066 | pointer to a malloc'ed buffer containing the relocs is placed in *RELSP, | |
1067 | and the number of relocs loaded is placed in *NRELSP. It is the caller's | |
1068 | responsibility to free the allocated buffer. */ | |
1069 | ||
1070 | static bfd_boolean | |
1071 | slurp_rel_relocs (Filedata * filedata, | |
1072 | unsigned long rel_offset, | |
1073 | unsigned long rel_size, | |
1074 | Elf_Internal_Rela ** relsp, | |
1075 | unsigned long * nrelsp) | |
1076 | { | |
1077 | Elf_Internal_Rela * rels; | |
1078 | size_t nrels; | |
1079 | unsigned int i; | |
1080 | ||
1081 | if (is_32bit_elf) | |
1082 | { | |
1083 | Elf32_External_Rel * erels; | |
1084 | ||
1085 | erels = (Elf32_External_Rel *) get_data (NULL, filedata, rel_offset, 1, | |
1086 | rel_size, _("32-bit relocation data")); | |
1087 | if (!erels) | |
1088 | return FALSE; | |
1089 | ||
1090 | nrels = rel_size / sizeof (Elf32_External_Rel); | |
1091 | ||
1092 | rels = (Elf_Internal_Rela *) cmalloc (nrels, sizeof (Elf_Internal_Rela)); | |
1093 | ||
1094 | if (rels == NULL) | |
1095 | { | |
1096 | free (erels); | |
1097 | error (_("out of memory parsing relocs\n")); | |
1098 | return FALSE; | |
1099 | } | |
1100 | ||
1101 | for (i = 0; i < nrels; i++) | |
1102 | { | |
1103 | rels[i].r_offset = BYTE_GET (erels[i].r_offset); | |
1104 | rels[i].r_info = BYTE_GET (erels[i].r_info); | |
1105 | rels[i].r_addend = 0; | |
1106 | } | |
1107 | ||
1108 | free (erels); | |
1109 | } | |
1110 | else | |
1111 | { | |
1112 | Elf64_External_Rel * erels; | |
1113 | ||
1114 | erels = (Elf64_External_Rel *) get_data (NULL, filedata, rel_offset, 1, | |
1115 | rel_size, _("64-bit relocation data")); | |
1116 | if (!erels) | |
1117 | return FALSE; | |
1118 | ||
1119 | nrels = rel_size / sizeof (Elf64_External_Rel); | |
1120 | ||
1121 | rels = (Elf_Internal_Rela *) cmalloc (nrels, sizeof (Elf_Internal_Rela)); | |
1122 | ||
1123 | if (rels == NULL) | |
1124 | { | |
1125 | free (erels); | |
1126 | error (_("out of memory parsing relocs\n")); | |
1127 | return FALSE; | |
1128 | } | |
1129 | ||
1130 | for (i = 0; i < nrels; i++) | |
1131 | { | |
1132 | rels[i].r_offset = BYTE_GET (erels[i].r_offset); | |
1133 | rels[i].r_info = BYTE_GET (erels[i].r_info); | |
1134 | rels[i].r_addend = 0; | |
1135 | ||
1136 | /* The #ifdef BFD64 below is to prevent a compile time | |
1137 | warning. We know that if we do not have a 64 bit data | |
1138 | type that we will never execute this code anyway. */ | |
1139 | #ifdef BFD64 | |
1140 | if (filedata->file_header.e_machine == EM_MIPS | |
1141 | && filedata->file_header.e_ident[EI_DATA] != ELFDATA2MSB) | |
1142 | { | |
1143 | /* In little-endian objects, r_info isn't really a | |
1144 | 64-bit little-endian value: it has a 32-bit | |
1145 | little-endian symbol index followed by four | |
1146 | individual byte fields. Reorder INFO | |
1147 | accordingly. */ | |
1148 | bfd_vma inf = rels[i].r_info; | |
1149 | inf = (((inf & 0xffffffff) << 32) | |
1150 | | ((inf >> 56) & 0xff) | |
1151 | | ((inf >> 40) & 0xff00) | |
1152 | | ((inf >> 24) & 0xff0000) | |
1153 | | ((inf >> 8) & 0xff000000)); | |
1154 | rels[i].r_info = inf; | |
1155 | } | |
1156 | #endif /* BFD64 */ | |
1157 | } | |
1158 | ||
1159 | free (erels); | |
1160 | } | |
1161 | ||
1162 | *relsp = rels; | |
1163 | *nrelsp = nrels; | |
1164 | return TRUE; | |
1165 | } | |
1166 | ||
1167 | /* Returns the reloc type extracted from the reloc info field. */ | |
1168 | ||
1169 | static unsigned int | |
1170 | get_reloc_type (Filedata * filedata, bfd_vma reloc_info) | |
1171 | { | |
1172 | if (is_32bit_elf) | |
1173 | return ELF32_R_TYPE (reloc_info); | |
1174 | ||
1175 | switch (filedata->file_header.e_machine) | |
1176 | { | |
1177 | case EM_MIPS: | |
1178 | /* Note: We assume that reloc_info has already been adjusted for us. */ | |
1179 | return ELF64_MIPS_R_TYPE (reloc_info); | |
1180 | ||
1181 | case EM_SPARCV9: | |
1182 | return ELF64_R_TYPE_ID (reloc_info); | |
1183 | ||
1184 | default: | |
1185 | return ELF64_R_TYPE (reloc_info); | |
1186 | } | |
1187 | } | |
1188 | ||
1189 | /* Return the symbol index extracted from the reloc info field. */ | |
1190 | ||
1191 | static bfd_vma | |
1192 | get_reloc_symindex (bfd_vma reloc_info) | |
1193 | { | |
1194 | return is_32bit_elf ? ELF32_R_SYM (reloc_info) : ELF64_R_SYM (reloc_info); | |
1195 | } | |
1196 | ||
1197 | static inline bfd_boolean | |
1198 | uses_msp430x_relocs (Filedata * filedata) | |
1199 | { | |
1200 | return | |
1201 | filedata->file_header.e_machine == EM_MSP430 /* Paranoia. */ | |
1202 | /* GCC uses osabi == ELFOSBI_STANDALONE. */ | |
1203 | && (((filedata->file_header.e_flags & EF_MSP430_MACH) == E_MSP430_MACH_MSP430X) | |
1204 | /* TI compiler uses ELFOSABI_NONE. */ | |
1205 | || (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_NONE)); | |
1206 | } | |
1207 | ||
1208 | /* Display the contents of the relocation data found at the specified | |
1209 | offset. */ | |
1210 | ||
1211 | static bfd_boolean | |
1212 | dump_relocations (Filedata * filedata, | |
1213 | unsigned long rel_offset, | |
1214 | unsigned long rel_size, | |
1215 | Elf_Internal_Sym * symtab, | |
1216 | unsigned long nsyms, | |
1217 | char * strtab, | |
1218 | unsigned long strtablen, | |
1219 | int is_rela, | |
1220 | bfd_boolean is_dynsym) | |
1221 | { | |
1222 | unsigned long i; | |
1223 | Elf_Internal_Rela * rels; | |
1224 | bfd_boolean res = TRUE; | |
1225 | ||
1226 | if (is_rela == UNKNOWN) | |
1227 | is_rela = guess_is_rela (filedata->file_header.e_machine); | |
1228 | ||
1229 | if (is_rela) | |
1230 | { | |
1231 | if (!slurp_rela_relocs (filedata, rel_offset, rel_size, &rels, &rel_size)) | |
1232 | return FALSE; | |
1233 | } | |
1234 | else | |
1235 | { | |
1236 | if (!slurp_rel_relocs (filedata, rel_offset, rel_size, &rels, &rel_size)) | |
1237 | return FALSE; | |
1238 | } | |
1239 | ||
1240 | if (is_32bit_elf) | |
1241 | { | |
1242 | if (is_rela) | |
1243 | { | |
1244 | if (do_wide) | |
1245 | printf (_(" Offset Info Type Sym. Value Symbol's Name + Addend\n")); | |
1246 | else | |
1247 | printf (_(" Offset Info Type Sym.Value Sym. Name + Addend\n")); | |
1248 | } | |
1249 | else | |
1250 | { | |
1251 | if (do_wide) | |
1252 | printf (_(" Offset Info Type Sym. Value Symbol's Name\n")); | |
1253 | else | |
1254 | printf (_(" Offset Info Type Sym.Value Sym. Name\n")); | |
1255 | } | |
1256 | } | |
1257 | else | |
1258 | { | |
1259 | if (is_rela) | |
1260 | { | |
1261 | if (do_wide) | |
1262 | printf (_(" Offset Info Type Symbol's Value Symbol's Name + Addend\n")); | |
1263 | else | |
1264 | printf (_(" Offset Info Type Sym. Value Sym. Name + Addend\n")); | |
1265 | } | |
1266 | else | |
1267 | { | |
1268 | if (do_wide) | |
1269 | printf (_(" Offset Info Type Symbol's Value Symbol's Name\n")); | |
1270 | else | |
1271 | printf (_(" Offset Info Type Sym. Value Sym. Name\n")); | |
1272 | } | |
1273 | } | |
1274 | ||
1275 | for (i = 0; i < rel_size; i++) | |
1276 | { | |
1277 | const char * rtype; | |
1278 | bfd_vma offset; | |
1279 | bfd_vma inf; | |
1280 | bfd_vma symtab_index; | |
1281 | bfd_vma type; | |
1282 | ||
1283 | offset = rels[i].r_offset; | |
1284 | inf = rels[i].r_info; | |
1285 | ||
1286 | type = get_reloc_type (filedata, inf); | |
1287 | symtab_index = get_reloc_symindex (inf); | |
1288 | ||
1289 | if (is_32bit_elf) | |
1290 | { | |
1291 | printf ("%8.8lx %8.8lx ", | |
1292 | (unsigned long) offset & 0xffffffff, | |
1293 | (unsigned long) inf & 0xffffffff); | |
1294 | } | |
1295 | else | |
1296 | { | |
1297 | printf (do_wide | |
1298 | ? "%16.16" BFD_VMA_FMT "x %16.16" BFD_VMA_FMT "x " | |
1299 | : "%12.12" BFD_VMA_FMT "x %12.12" BFD_VMA_FMT "x ", | |
1300 | offset, inf); | |
1301 | } | |
1302 | ||
1303 | switch (filedata->file_header.e_machine) | |
1304 | { | |
1305 | default: | |
1306 | rtype = NULL; | |
1307 | break; | |
1308 | ||
1309 | case EM_AARCH64: | |
1310 | rtype = elf_aarch64_reloc_type (type); | |
1311 | break; | |
1312 | ||
1313 | case EM_M32R: | |
1314 | case EM_CYGNUS_M32R: | |
1315 | rtype = elf_m32r_reloc_type (type); | |
1316 | break; | |
1317 | ||
1318 | case EM_386: | |
1319 | case EM_IAMCU: | |
1320 | rtype = elf_i386_reloc_type (type); | |
1321 | break; | |
1322 | ||
1323 | case EM_68HC11: | |
1324 | case EM_68HC12: | |
1325 | rtype = elf_m68hc11_reloc_type (type); | |
1326 | break; | |
1327 | ||
1328 | case EM_S12Z: | |
1329 | rtype = elf_s12z_reloc_type (type); | |
1330 | break; | |
1331 | ||
1332 | case EM_68K: | |
1333 | rtype = elf_m68k_reloc_type (type); | |
1334 | break; | |
1335 | ||
1336 | case EM_960: | |
1337 | rtype = elf_i960_reloc_type (type); | |
1338 | break; | |
1339 | ||
1340 | case EM_AVR: | |
1341 | case EM_AVR_OLD: | |
1342 | rtype = elf_avr_reloc_type (type); | |
1343 | break; | |
1344 | ||
1345 | case EM_OLD_SPARCV9: | |
1346 | case EM_SPARC32PLUS: | |
1347 | case EM_SPARCV9: | |
1348 | case EM_SPARC: | |
1349 | rtype = elf_sparc_reloc_type (type); | |
1350 | break; | |
1351 | ||
1352 | case EM_SPU: | |
1353 | rtype = elf_spu_reloc_type (type); | |
1354 | break; | |
1355 | ||
1356 | case EM_V800: | |
1357 | rtype = v800_reloc_type (type); | |
1358 | break; | |
1359 | case EM_V850: | |
1360 | case EM_CYGNUS_V850: | |
1361 | rtype = v850_reloc_type (type); | |
1362 | break; | |
1363 | ||
1364 | case EM_D10V: | |
1365 | case EM_CYGNUS_D10V: | |
1366 | rtype = elf_d10v_reloc_type (type); | |
1367 | break; | |
1368 | ||
1369 | case EM_D30V: | |
1370 | case EM_CYGNUS_D30V: | |
1371 | rtype = elf_d30v_reloc_type (type); | |
1372 | break; | |
1373 | ||
1374 | case EM_DLX: | |
1375 | rtype = elf_dlx_reloc_type (type); | |
1376 | break; | |
1377 | ||
1378 | case EM_SH: | |
1379 | rtype = elf_sh_reloc_type (type); | |
1380 | break; | |
1381 | ||
1382 | case EM_MN10300: | |
1383 | case EM_CYGNUS_MN10300: | |
1384 | rtype = elf_mn10300_reloc_type (type); | |
1385 | break; | |
1386 | ||
1387 | case EM_MN10200: | |
1388 | case EM_CYGNUS_MN10200: | |
1389 | rtype = elf_mn10200_reloc_type (type); | |
1390 | break; | |
1391 | ||
1392 | case EM_FR30: | |
1393 | case EM_CYGNUS_FR30: | |
1394 | rtype = elf_fr30_reloc_type (type); | |
1395 | break; | |
1396 | ||
1397 | case EM_CYGNUS_FRV: | |
1398 | rtype = elf_frv_reloc_type (type); | |
1399 | break; | |
1400 | ||
1401 | case EM_CSKY: | |
1402 | rtype = elf_csky_reloc_type (type); | |
1403 | break; | |
1404 | ||
1405 | case EM_FT32: | |
1406 | rtype = elf_ft32_reloc_type (type); | |
1407 | break; | |
1408 | ||
1409 | case EM_MCORE: | |
1410 | rtype = elf_mcore_reloc_type (type); | |
1411 | break; | |
1412 | ||
1413 | case EM_MMIX: | |
1414 | rtype = elf_mmix_reloc_type (type); | |
1415 | break; | |
1416 | ||
1417 | case EM_MOXIE: | |
1418 | rtype = elf_moxie_reloc_type (type); | |
1419 | break; | |
1420 | ||
1421 | case EM_MSP430: | |
1422 | if (uses_msp430x_relocs (filedata)) | |
1423 | { | |
1424 | rtype = elf_msp430x_reloc_type (type); | |
1425 | break; | |
1426 | } | |
1427 | /* Fall through. */ | |
1428 | case EM_MSP430_OLD: | |
1429 | rtype = elf_msp430_reloc_type (type); | |
1430 | break; | |
1431 | ||
1432 | case EM_NDS32: | |
1433 | rtype = elf_nds32_reloc_type (type); | |
1434 | break; | |
1435 | ||
1436 | case EM_PPC: | |
1437 | rtype = elf_ppc_reloc_type (type); | |
1438 | break; | |
1439 | ||
1440 | case EM_PPC64: | |
1441 | rtype = elf_ppc64_reloc_type (type); | |
1442 | break; | |
1443 | ||
1444 | case EM_MIPS: | |
1445 | case EM_MIPS_RS3_LE: | |
1446 | rtype = elf_mips_reloc_type (type); | |
1447 | break; | |
1448 | ||
1449 | case EM_RISCV: | |
1450 | rtype = elf_riscv_reloc_type (type); | |
1451 | break; | |
1452 | ||
1453 | case EM_ALPHA: | |
1454 | rtype = elf_alpha_reloc_type (type); | |
1455 | break; | |
1456 | ||
1457 | case EM_ARM: | |
1458 | rtype = elf_arm_reloc_type (type); | |
1459 | break; | |
1460 | ||
1461 | case EM_ARC: | |
1462 | case EM_ARC_COMPACT: | |
1463 | case EM_ARC_COMPACT2: | |
1464 | rtype = elf_arc_reloc_type (type); | |
1465 | break; | |
1466 | ||
1467 | case EM_PARISC: | |
1468 | rtype = elf_hppa_reloc_type (type); | |
1469 | break; | |
1470 | ||
1471 | case EM_H8_300: | |
1472 | case EM_H8_300H: | |
1473 | case EM_H8S: | |
1474 | rtype = elf_h8_reloc_type (type); | |
1475 | break; | |
1476 | ||
1477 | case EM_OR1K: | |
1478 | rtype = elf_or1k_reloc_type (type); | |
1479 | break; | |
1480 | ||
1481 | case EM_PJ: | |
1482 | case EM_PJ_OLD: | |
1483 | rtype = elf_pj_reloc_type (type); | |
1484 | break; | |
1485 | case EM_IA_64: | |
1486 | rtype = elf_ia64_reloc_type (type); | |
1487 | break; | |
1488 | ||
1489 | case EM_CRIS: | |
1490 | rtype = elf_cris_reloc_type (type); | |
1491 | break; | |
1492 | ||
1493 | case EM_860: | |
1494 | rtype = elf_i860_reloc_type (type); | |
1495 | break; | |
1496 | ||
1497 | case EM_X86_64: | |
1498 | case EM_L1OM: | |
1499 | case EM_K1OM: | |
1500 | rtype = elf_x86_64_reloc_type (type); | |
1501 | break; | |
1502 | ||
1503 | case EM_S370: | |
1504 | rtype = i370_reloc_type (type); | |
1505 | break; | |
1506 | ||
1507 | case EM_S390_OLD: | |
1508 | case EM_S390: | |
1509 | rtype = elf_s390_reloc_type (type); | |
1510 | break; | |
1511 | ||
1512 | case EM_SCORE: | |
1513 | rtype = elf_score_reloc_type (type); | |
1514 | break; | |
1515 | ||
1516 | case EM_XSTORMY16: | |
1517 | rtype = elf_xstormy16_reloc_type (type); | |
1518 | break; | |
1519 | ||
1520 | case EM_CRX: | |
1521 | rtype = elf_crx_reloc_type (type); | |
1522 | break; | |
1523 | ||
1524 | case EM_VAX: | |
1525 | rtype = elf_vax_reloc_type (type); | |
1526 | break; | |
1527 | ||
1528 | case EM_VISIUM: | |
1529 | rtype = elf_visium_reloc_type (type); | |
1530 | break; | |
1531 | ||
1532 | case EM_BPF: | |
1533 | rtype = elf_bpf_reloc_type (type); | |
1534 | break; | |
1535 | ||
1536 | case EM_ADAPTEVA_EPIPHANY: | |
1537 | rtype = elf_epiphany_reloc_type (type); | |
1538 | break; | |
1539 | ||
1540 | case EM_IP2K: | |
1541 | case EM_IP2K_OLD: | |
1542 | rtype = elf_ip2k_reloc_type (type); | |
1543 | break; | |
1544 | ||
1545 | case EM_IQ2000: | |
1546 | rtype = elf_iq2000_reloc_type (type); | |
1547 | break; | |
1548 | ||
1549 | case EM_XTENSA_OLD: | |
1550 | case EM_XTENSA: | |
1551 | rtype = elf_xtensa_reloc_type (type); | |
1552 | break; | |
1553 | ||
1554 | case EM_LATTICEMICO32: | |
1555 | rtype = elf_lm32_reloc_type (type); | |
1556 | break; | |
1557 | ||
1558 | case EM_M32C_OLD: | |
1559 | case EM_M32C: | |
1560 | rtype = elf_m32c_reloc_type (type); | |
1561 | break; | |
1562 | ||
1563 | case EM_MT: | |
1564 | rtype = elf_mt_reloc_type (type); | |
1565 | break; | |
1566 | ||
1567 | case EM_BLACKFIN: | |
1568 | rtype = elf_bfin_reloc_type (type); | |
1569 | break; | |
1570 | ||
1571 | case EM_CYGNUS_MEP: | |
1572 | rtype = elf_mep_reloc_type (type); | |
1573 | break; | |
1574 | ||
1575 | case EM_CR16: | |
1576 | rtype = elf_cr16_reloc_type (type); | |
1577 | break; | |
1578 | ||
1579 | case EM_MICROBLAZE: | |
1580 | case EM_MICROBLAZE_OLD: | |
1581 | rtype = elf_microblaze_reloc_type (type); | |
1582 | break; | |
1583 | ||
1584 | case EM_RL78: | |
1585 | rtype = elf_rl78_reloc_type (type); | |
1586 | break; | |
1587 | ||
1588 | case EM_RX: | |
1589 | rtype = elf_rx_reloc_type (type); | |
1590 | break; | |
1591 | ||
1592 | case EM_METAG: | |
1593 | rtype = elf_metag_reloc_type (type); | |
1594 | break; | |
1595 | ||
1596 | case EM_XC16X: | |
1597 | case EM_C166: | |
1598 | rtype = elf_xc16x_reloc_type (type); | |
1599 | break; | |
1600 | ||
1601 | case EM_TI_C6000: | |
1602 | rtype = elf_tic6x_reloc_type (type); | |
1603 | break; | |
1604 | ||
1605 | case EM_TILEGX: | |
1606 | rtype = elf_tilegx_reloc_type (type); | |
1607 | break; | |
1608 | ||
1609 | case EM_TILEPRO: | |
1610 | rtype = elf_tilepro_reloc_type (type); | |
1611 | break; | |
1612 | ||
1613 | case EM_WEBASSEMBLY: | |
1614 | rtype = elf_wasm32_reloc_type (type); | |
1615 | break; | |
1616 | ||
1617 | case EM_XGATE: | |
1618 | rtype = elf_xgate_reloc_type (type); | |
1619 | break; | |
1620 | ||
1621 | case EM_ALTERA_NIOS2: | |
1622 | rtype = elf_nios2_reloc_type (type); | |
1623 | break; | |
1624 | ||
1625 | case EM_TI_PRU: | |
1626 | rtype = elf_pru_reloc_type (type); | |
1627 | break; | |
1628 | ||
1629 | case EM_NFP: | |
1630 | if (EF_NFP_MACH (filedata->file_header.e_flags) == E_NFP_MACH_3200) | |
1631 | rtype = elf_nfp3200_reloc_type (type); | |
1632 | else | |
1633 | rtype = elf_nfp_reloc_type (type); | |
1634 | break; | |
1635 | ||
1636 | case EM_Z80: | |
1637 | rtype = elf_z80_reloc_type (type); | |
1638 | break; | |
1639 | } | |
1640 | ||
1641 | if (rtype == NULL) | |
1642 | printf (_("unrecognized: %-7lx"), (unsigned long) type & 0xffffffff); | |
1643 | else | |
1644 | printf (do_wide ? "%-22s" : "%-17.17s", rtype); | |
1645 | ||
1646 | if (filedata->file_header.e_machine == EM_ALPHA | |
1647 | && rtype != NULL | |
1648 | && streq (rtype, "R_ALPHA_LITUSE") | |
1649 | && is_rela) | |
1650 | { | |
1651 | switch (rels[i].r_addend) | |
1652 | { | |
1653 | case LITUSE_ALPHA_ADDR: rtype = "ADDR"; break; | |
1654 | case LITUSE_ALPHA_BASE: rtype = "BASE"; break; | |
1655 | case LITUSE_ALPHA_BYTOFF: rtype = "BYTOFF"; break; | |
1656 | case LITUSE_ALPHA_JSR: rtype = "JSR"; break; | |
1657 | case LITUSE_ALPHA_TLSGD: rtype = "TLSGD"; break; | |
1658 | case LITUSE_ALPHA_TLSLDM: rtype = "TLSLDM"; break; | |
1659 | case LITUSE_ALPHA_JSRDIRECT: rtype = "JSRDIRECT"; break; | |
1660 | default: rtype = NULL; | |
1661 | } | |
1662 | ||
1663 | if (rtype) | |
1664 | printf (" (%s)", rtype); | |
1665 | else | |
1666 | { | |
1667 | putchar (' '); | |
1668 | printf (_("<unknown addend: %lx>"), | |
1669 | (unsigned long) rels[i].r_addend); | |
1670 | res = FALSE; | |
1671 | } | |
1672 | } | |
1673 | else if (symtab_index) | |
1674 | { | |
1675 | if (symtab == NULL || symtab_index >= nsyms) | |
1676 | { | |
1677 | error (_(" bad symbol index: %08lx in reloc\n"), | |
1678 | (unsigned long) symtab_index); | |
1679 | res = FALSE; | |
1680 | } | |
1681 | else | |
1682 | { | |
1683 | Elf_Internal_Sym * psym; | |
1684 | const char * version_string; | |
1685 | enum versioned_symbol_info sym_info; | |
1686 | unsigned short vna_other; | |
1687 | ||
1688 | psym = symtab + symtab_index; | |
1689 | ||
1690 | version_string | |
1691 | = get_symbol_version_string (filedata, is_dynsym, | |
1692 | strtab, strtablen, | |
1693 | symtab_index, | |
1694 | psym, | |
1695 | &sym_info, | |
1696 | &vna_other); | |
1697 | ||
1698 | printf (" "); | |
1699 | ||
1700 | if (ELF_ST_TYPE (psym->st_info) == STT_GNU_IFUNC) | |
1701 | { | |
1702 | const char * name; | |
1703 | unsigned int len; | |
1704 | unsigned int width = is_32bit_elf ? 8 : 14; | |
1705 | ||
1706 | /* Relocations against GNU_IFUNC symbols do not use the value | |
1707 | of the symbol as the address to relocate against. Instead | |
1708 | they invoke the function named by the symbol and use its | |
1709 | result as the address for relocation. | |
1710 | ||
1711 | To indicate this to the user, do not display the value of | |
1712 | the symbol in the "Symbols's Value" field. Instead show | |
1713 | its name followed by () as a hint that the symbol is | |
1714 | invoked. */ | |
1715 | ||
1716 | if (strtab == NULL | |
1717 | || psym->st_name == 0 | |
1718 | || psym->st_name >= strtablen) | |
1719 | name = "??"; | |
1720 | else | |
1721 | name = strtab + psym->st_name; | |
1722 | ||
1723 | len = print_symbol (width, name); | |
1724 | if (version_string) | |
1725 | printf (sym_info == symbol_public ? "@@%s" : "@%s", | |
1726 | version_string); | |
1727 | printf ("()%-*s", len <= width ? (width + 1) - len : 1, " "); | |
1728 | } | |
1729 | else | |
1730 | { | |
1731 | print_vma (psym->st_value, LONG_HEX); | |
1732 | ||
1733 | printf (is_32bit_elf ? " " : " "); | |
1734 | } | |
1735 | ||
1736 | if (psym->st_name == 0) | |
1737 | { | |
1738 | const char * sec_name = "<null>"; | |
1739 | char name_buf[40]; | |
1740 | ||
1741 | if (ELF_ST_TYPE (psym->st_info) == STT_SECTION) | |
1742 | { | |
1743 | if (psym->st_shndx < filedata->file_header.e_shnum) | |
1744 | sec_name = SECTION_NAME_PRINT (filedata->section_headers | |
1745 | + psym->st_shndx); | |
1746 | else if (psym->st_shndx == SHN_ABS) | |
1747 | sec_name = "ABS"; | |
1748 | else if (psym->st_shndx == SHN_COMMON) | |
1749 | sec_name = "COMMON"; | |
1750 | else if ((filedata->file_header.e_machine == EM_MIPS | |
1751 | && psym->st_shndx == SHN_MIPS_SCOMMON) | |
1752 | || (filedata->file_header.e_machine == EM_TI_C6000 | |
1753 | && psym->st_shndx == SHN_TIC6X_SCOMMON)) | |
1754 | sec_name = "SCOMMON"; | |
1755 | else if (filedata->file_header.e_machine == EM_MIPS | |
1756 | && psym->st_shndx == SHN_MIPS_SUNDEFINED) | |
1757 | sec_name = "SUNDEF"; | |
1758 | else if ((filedata->file_header.e_machine == EM_X86_64 | |
1759 | || filedata->file_header.e_machine == EM_L1OM | |
1760 | || filedata->file_header.e_machine == EM_K1OM) | |
1761 | && psym->st_shndx == SHN_X86_64_LCOMMON) | |
1762 | sec_name = "LARGE_COMMON"; | |
1763 | else if (filedata->file_header.e_machine == EM_IA_64 | |
1764 | && filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_HPUX | |
1765 | && psym->st_shndx == SHN_IA_64_ANSI_COMMON) | |
1766 | sec_name = "ANSI_COM"; | |
1767 | else if (is_ia64_vms (filedata) | |
1768 | && psym->st_shndx == SHN_IA_64_VMS_SYMVEC) | |
1769 | sec_name = "VMS_SYMVEC"; | |
1770 | else | |
1771 | { | |
1772 | sprintf (name_buf, "<section 0x%x>", | |
1773 | (unsigned int) psym->st_shndx); | |
1774 | sec_name = name_buf; | |
1775 | } | |
1776 | } | |
1777 | print_symbol (22, sec_name); | |
1778 | } | |
1779 | else if (strtab == NULL) | |
1780 | printf (_("<string table index: %3ld>"), psym->st_name); | |
1781 | else if (psym->st_name >= strtablen) | |
1782 | { | |
1783 | error (_("<corrupt string table index: %3ld>\n"), | |
1784 | psym->st_name); | |
1785 | res = FALSE; | |
1786 | } | |
1787 | else | |
1788 | { | |
1789 | print_symbol (22, strtab + psym->st_name); | |
1790 | if (version_string) | |
1791 | printf (sym_info == symbol_public ? "@@%s" : "@%s", | |
1792 | version_string); | |
1793 | } | |
1794 | ||
1795 | if (is_rela) | |
1796 | { | |
1797 | bfd_vma off = rels[i].r_addend; | |
1798 | ||
1799 | if ((bfd_signed_vma) off < 0) | |
1800 | printf (" - %" BFD_VMA_FMT "x", - off); | |
1801 | else | |
1802 | printf (" + %" BFD_VMA_FMT "x", off); | |
1803 | } | |
1804 | } | |
1805 | } | |
1806 | else if (is_rela) | |
1807 | { | |
1808 | bfd_vma off = rels[i].r_addend; | |
1809 | ||
1810 | printf ("%*c", is_32bit_elf ? 12 : 20, ' '); | |
1811 | if ((bfd_signed_vma) off < 0) | |
1812 | printf ("-%" BFD_VMA_FMT "x", - off); | |
1813 | else | |
1814 | printf ("%" BFD_VMA_FMT "x", off); | |
1815 | } | |
1816 | ||
1817 | if (filedata->file_header.e_machine == EM_SPARCV9 | |
1818 | && rtype != NULL | |
1819 | && streq (rtype, "R_SPARC_OLO10")) | |
1820 | printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (inf)); | |
1821 | ||
1822 | putchar ('\n'); | |
1823 | ||
1824 | #ifdef BFD64 | |
1825 | if (! is_32bit_elf && filedata->file_header.e_machine == EM_MIPS) | |
1826 | { | |
1827 | bfd_vma type2 = ELF64_MIPS_R_TYPE2 (inf); | |
1828 | bfd_vma type3 = ELF64_MIPS_R_TYPE3 (inf); | |
1829 | const char * rtype2 = elf_mips_reloc_type (type2); | |
1830 | const char * rtype3 = elf_mips_reloc_type (type3); | |
1831 | ||
1832 | printf (" Type2: "); | |
1833 | ||
1834 | if (rtype2 == NULL) | |
1835 | printf (_("unrecognized: %-7lx"), | |
1836 | (unsigned long) type2 & 0xffffffff); | |
1837 | else | |
1838 | printf ("%-17.17s", rtype2); | |
1839 | ||
1840 | printf ("\n Type3: "); | |
1841 | ||
1842 | if (rtype3 == NULL) | |
1843 | printf (_("unrecognized: %-7lx"), | |
1844 | (unsigned long) type3 & 0xffffffff); | |
1845 | else | |
1846 | printf ("%-17.17s", rtype3); | |
1847 | ||
1848 | putchar ('\n'); | |
1849 | } | |
1850 | #endif /* BFD64 */ | |
1851 | } | |
1852 | ||
1853 | free (rels); | |
1854 | ||
1855 | return res; | |
1856 | } | |
1857 | ||
1858 | static const char * | |
1859 | get_aarch64_dynamic_type (unsigned long type) | |
1860 | { | |
1861 | switch (type) | |
1862 | { | |
1863 | case DT_AARCH64_BTI_PLT: return "AARCH64_BTI_PLT"; | |
1864 | case DT_AARCH64_PAC_PLT: return "AARCH64_PAC_PLT"; | |
1865 | case DT_AARCH64_VARIANT_PCS: return "AARCH64_VARIANT_PCS"; | |
1866 | default: | |
1867 | return NULL; | |
1868 | } | |
1869 | } | |
1870 | ||
1871 | static const char * | |
1872 | get_mips_dynamic_type (unsigned long type) | |
1873 | { | |
1874 | switch (type) | |
1875 | { | |
1876 | case DT_MIPS_RLD_VERSION: return "MIPS_RLD_VERSION"; | |
1877 | case DT_MIPS_TIME_STAMP: return "MIPS_TIME_STAMP"; | |
1878 | case DT_MIPS_ICHECKSUM: return "MIPS_ICHECKSUM"; | |
1879 | case DT_MIPS_IVERSION: return "MIPS_IVERSION"; | |
1880 | case DT_MIPS_FLAGS: return "MIPS_FLAGS"; | |
1881 | case DT_MIPS_BASE_ADDRESS: return "MIPS_BASE_ADDRESS"; | |
1882 | case DT_MIPS_MSYM: return "MIPS_MSYM"; | |
1883 | case DT_MIPS_CONFLICT: return "MIPS_CONFLICT"; | |
1884 | case DT_MIPS_LIBLIST: return "MIPS_LIBLIST"; | |
1885 | case DT_MIPS_LOCAL_GOTNO: return "MIPS_LOCAL_GOTNO"; | |
1886 | case DT_MIPS_CONFLICTNO: return "MIPS_CONFLICTNO"; | |
1887 | case DT_MIPS_LIBLISTNO: return "MIPS_LIBLISTNO"; | |
1888 | case DT_MIPS_SYMTABNO: return "MIPS_SYMTABNO"; | |
1889 | case DT_MIPS_UNREFEXTNO: return "MIPS_UNREFEXTNO"; | |
1890 | case DT_MIPS_GOTSYM: return "MIPS_GOTSYM"; | |
1891 | case DT_MIPS_HIPAGENO: return "MIPS_HIPAGENO"; | |
1892 | case DT_MIPS_RLD_MAP: return "MIPS_RLD_MAP"; | |
1893 | case DT_MIPS_RLD_MAP_REL: return "MIPS_RLD_MAP_REL"; | |
1894 | case DT_MIPS_DELTA_CLASS: return "MIPS_DELTA_CLASS"; | |
1895 | case DT_MIPS_DELTA_CLASS_NO: return "MIPS_DELTA_CLASS_NO"; | |
1896 | case DT_MIPS_DELTA_INSTANCE: return "MIPS_DELTA_INSTANCE"; | |
1897 | case DT_MIPS_DELTA_INSTANCE_NO: return "MIPS_DELTA_INSTANCE_NO"; | |
1898 | case DT_MIPS_DELTA_RELOC: return "MIPS_DELTA_RELOC"; | |
1899 | case DT_MIPS_DELTA_RELOC_NO: return "MIPS_DELTA_RELOC_NO"; | |
1900 | case DT_MIPS_DELTA_SYM: return "MIPS_DELTA_SYM"; | |
1901 | case DT_MIPS_DELTA_SYM_NO: return "MIPS_DELTA_SYM_NO"; | |
1902 | case DT_MIPS_DELTA_CLASSSYM: return "MIPS_DELTA_CLASSSYM"; | |
1903 | case DT_MIPS_DELTA_CLASSSYM_NO: return "MIPS_DELTA_CLASSSYM_NO"; | |
1904 | case DT_MIPS_CXX_FLAGS: return "MIPS_CXX_FLAGS"; | |
1905 | case DT_MIPS_PIXIE_INIT: return "MIPS_PIXIE_INIT"; | |
1906 | case DT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB"; | |
1907 | case DT_MIPS_LOCALPAGE_GOTIDX: return "MIPS_LOCALPAGE_GOTIDX"; | |
1908 | case DT_MIPS_LOCAL_GOTIDX: return "MIPS_LOCAL_GOTIDX"; | |
1909 | case DT_MIPS_HIDDEN_GOTIDX: return "MIPS_HIDDEN_GOTIDX"; | |
1910 | case DT_MIPS_PROTECTED_GOTIDX: return "MIPS_PROTECTED_GOTIDX"; | |
1911 | case DT_MIPS_OPTIONS: return "MIPS_OPTIONS"; | |
1912 | case DT_MIPS_INTERFACE: return "MIPS_INTERFACE"; | |
1913 | case DT_MIPS_DYNSTR_ALIGN: return "MIPS_DYNSTR_ALIGN"; | |
1914 | case DT_MIPS_INTERFACE_SIZE: return "MIPS_INTERFACE_SIZE"; | |
1915 | case DT_MIPS_RLD_TEXT_RESOLVE_ADDR: return "MIPS_RLD_TEXT_RESOLVE_ADDR"; | |
1916 | case DT_MIPS_PERF_SUFFIX: return "MIPS_PERF_SUFFIX"; | |
1917 | case DT_MIPS_COMPACT_SIZE: return "MIPS_COMPACT_SIZE"; | |
1918 | case DT_MIPS_GP_VALUE: return "MIPS_GP_VALUE"; | |
1919 | case DT_MIPS_AUX_DYNAMIC: return "MIPS_AUX_DYNAMIC"; | |
1920 | case DT_MIPS_PLTGOT: return "MIPS_PLTGOT"; | |
1921 | case DT_MIPS_RWPLT: return "MIPS_RWPLT"; | |
1922 | case DT_MIPS_XHASH: return "MIPS_XHASH"; | |
1923 | default: | |
1924 | return NULL; | |
1925 | } | |
1926 | } | |
1927 | ||
1928 | static const char * | |
1929 | get_sparc64_dynamic_type (unsigned long type) | |
1930 | { | |
1931 | switch (type) | |
1932 | { | |
1933 | case DT_SPARC_REGISTER: return "SPARC_REGISTER"; | |
1934 | default: | |
1935 | return NULL; | |
1936 | } | |
1937 | } | |
1938 | ||
1939 | static const char * | |
1940 | get_ppc_dynamic_type (unsigned long type) | |
1941 | { | |
1942 | switch (type) | |
1943 | { | |
1944 | case DT_PPC_GOT: return "PPC_GOT"; | |
1945 | case DT_PPC_OPT: return "PPC_OPT"; | |
1946 | default: | |
1947 | return NULL; | |
1948 | } | |
1949 | } | |
1950 | ||
1951 | static const char * | |
1952 | get_ppc64_dynamic_type (unsigned long type) | |
1953 | { | |
1954 | switch (type) | |
1955 | { | |
1956 | case DT_PPC64_GLINK: return "PPC64_GLINK"; | |
1957 | case DT_PPC64_OPD: return "PPC64_OPD"; | |
1958 | case DT_PPC64_OPDSZ: return "PPC64_OPDSZ"; | |
1959 | case DT_PPC64_OPT: return "PPC64_OPT"; | |
1960 | default: | |
1961 | return NULL; | |
1962 | } | |
1963 | } | |
1964 | ||
1965 | static const char * | |
1966 | get_parisc_dynamic_type (unsigned long type) | |
1967 | { | |
1968 | switch (type) | |
1969 | { | |
1970 | case DT_HP_LOAD_MAP: return "HP_LOAD_MAP"; | |
1971 | case DT_HP_DLD_FLAGS: return "HP_DLD_FLAGS"; | |
1972 | case DT_HP_DLD_HOOK: return "HP_DLD_HOOK"; | |
1973 | case DT_HP_UX10_INIT: return "HP_UX10_INIT"; | |
1974 | case DT_HP_UX10_INITSZ: return "HP_UX10_INITSZ"; | |
1975 | case DT_HP_PREINIT: return "HP_PREINIT"; | |
1976 | case DT_HP_PREINITSZ: return "HP_PREINITSZ"; | |
1977 | case DT_HP_NEEDED: return "HP_NEEDED"; | |
1978 | case DT_HP_TIME_STAMP: return "HP_TIME_STAMP"; | |
1979 | case DT_HP_CHECKSUM: return "HP_CHECKSUM"; | |
1980 | case DT_HP_GST_SIZE: return "HP_GST_SIZE"; | |
1981 | case DT_HP_GST_VERSION: return "HP_GST_VERSION"; | |
1982 | case DT_HP_GST_HASHVAL: return "HP_GST_HASHVAL"; | |
1983 | case DT_HP_EPLTREL: return "HP_GST_EPLTREL"; | |
1984 | case DT_HP_EPLTRELSZ: return "HP_GST_EPLTRELSZ"; | |
1985 | case DT_HP_FILTERED: return "HP_FILTERED"; | |
1986 | case DT_HP_FILTER_TLS: return "HP_FILTER_TLS"; | |
1987 | case DT_HP_COMPAT_FILTERED: return "HP_COMPAT_FILTERED"; | |
1988 | case DT_HP_LAZYLOAD: return "HP_LAZYLOAD"; | |
1989 | case DT_HP_BIND_NOW_COUNT: return "HP_BIND_NOW_COUNT"; | |
1990 | case DT_PLT: return "PLT"; | |
1991 | case DT_PLT_SIZE: return "PLT_SIZE"; | |
1992 | case DT_DLT: return "DLT"; | |
1993 | case DT_DLT_SIZE: return "DLT_SIZE"; | |
1994 | default: | |
1995 | return NULL; | |
1996 | } | |
1997 | } | |
1998 | ||
1999 | static const char * | |
2000 | get_ia64_dynamic_type (unsigned long type) | |
2001 | { | |
2002 | switch (type) | |
2003 | { | |
2004 | case DT_IA_64_PLT_RESERVE: return "IA_64_PLT_RESERVE"; | |
2005 | case DT_IA_64_VMS_SUBTYPE: return "VMS_SUBTYPE"; | |
2006 | case DT_IA_64_VMS_IMGIOCNT: return "VMS_IMGIOCNT"; | |
2007 | case DT_IA_64_VMS_LNKFLAGS: return "VMS_LNKFLAGS"; | |
2008 | case DT_IA_64_VMS_VIR_MEM_BLK_SIZ: return "VMS_VIR_MEM_BLK_SIZ"; | |
2009 | case DT_IA_64_VMS_IDENT: return "VMS_IDENT"; | |
2010 | case DT_IA_64_VMS_NEEDED_IDENT: return "VMS_NEEDED_IDENT"; | |
2011 | case DT_IA_64_VMS_IMG_RELA_CNT: return "VMS_IMG_RELA_CNT"; | |
2012 | case DT_IA_64_VMS_SEG_RELA_CNT: return "VMS_SEG_RELA_CNT"; | |
2013 | case DT_IA_64_VMS_FIXUP_RELA_CNT: return "VMS_FIXUP_RELA_CNT"; | |
2014 | case DT_IA_64_VMS_FIXUP_NEEDED: return "VMS_FIXUP_NEEDED"; | |
2015 | case DT_IA_64_VMS_SYMVEC_CNT: return "VMS_SYMVEC_CNT"; | |
2016 | case DT_IA_64_VMS_XLATED: return "VMS_XLATED"; | |
2017 | case DT_IA_64_VMS_STACKSIZE: return "VMS_STACKSIZE"; | |
2018 | case DT_IA_64_VMS_UNWINDSZ: return "VMS_UNWINDSZ"; | |
2019 | case DT_IA_64_VMS_UNWIND_CODSEG: return "VMS_UNWIND_CODSEG"; | |
2020 | case DT_IA_64_VMS_UNWIND_INFOSEG: return "VMS_UNWIND_INFOSEG"; | |
2021 | case DT_IA_64_VMS_LINKTIME: return "VMS_LINKTIME"; | |
2022 | case DT_IA_64_VMS_SEG_NO: return "VMS_SEG_NO"; | |
2023 | case DT_IA_64_VMS_SYMVEC_OFFSET: return "VMS_SYMVEC_OFFSET"; | |
2024 | case DT_IA_64_VMS_SYMVEC_SEG: return "VMS_SYMVEC_SEG"; | |
2025 | case DT_IA_64_VMS_UNWIND_OFFSET: return "VMS_UNWIND_OFFSET"; | |
2026 | case DT_IA_64_VMS_UNWIND_SEG: return "VMS_UNWIND_SEG"; | |
2027 | case DT_IA_64_VMS_STRTAB_OFFSET: return "VMS_STRTAB_OFFSET"; | |
2028 | case DT_IA_64_VMS_SYSVER_OFFSET: return "VMS_SYSVER_OFFSET"; | |
2029 | case DT_IA_64_VMS_IMG_RELA_OFF: return "VMS_IMG_RELA_OFF"; | |
2030 | case DT_IA_64_VMS_SEG_RELA_OFF: return "VMS_SEG_RELA_OFF"; | |
2031 | case DT_IA_64_VMS_FIXUP_RELA_OFF: return "VMS_FIXUP_RELA_OFF"; | |
2032 | case DT_IA_64_VMS_PLTGOT_OFFSET: return "VMS_PLTGOT_OFFSET"; | |
2033 | case DT_IA_64_VMS_PLTGOT_SEG: return "VMS_PLTGOT_SEG"; | |
2034 | case DT_IA_64_VMS_FPMODE: return "VMS_FPMODE"; | |
2035 | default: | |
2036 | return NULL; | |
2037 | } | |
2038 | } | |
2039 | ||
2040 | static const char * | |
2041 | get_solaris_section_type (unsigned long type) | |
2042 | { | |
2043 | switch (type) | |
2044 | { | |
2045 | case 0x6fffffee: return "SUNW_ancillary"; | |
2046 | case 0x6fffffef: return "SUNW_capchain"; | |
2047 | case 0x6ffffff0: return "SUNW_capinfo"; | |
2048 | case 0x6ffffff1: return "SUNW_symsort"; | |
2049 | case 0x6ffffff2: return "SUNW_tlssort"; | |
2050 | case 0x6ffffff3: return "SUNW_LDYNSYM"; | |
2051 | case 0x6ffffff4: return "SUNW_dof"; | |
2052 | case 0x6ffffff5: return "SUNW_cap"; | |
2053 | case 0x6ffffff6: return "SUNW_SIGNATURE"; | |
2054 | case 0x6ffffff7: return "SUNW_ANNOTATE"; | |
2055 | case 0x6ffffff8: return "SUNW_DEBUGSTR"; | |
2056 | case 0x6ffffff9: return "SUNW_DEBUG"; | |
2057 | case 0x6ffffffa: return "SUNW_move"; | |
2058 | case 0x6ffffffb: return "SUNW_COMDAT"; | |
2059 | case 0x6ffffffc: return "SUNW_syminfo"; | |
2060 | case 0x6ffffffd: return "SUNW_verdef"; | |
2061 | case 0x6ffffffe: return "SUNW_verneed"; | |
2062 | case 0x6fffffff: return "SUNW_versym"; | |
2063 | case 0x70000000: return "SPARC_GOTDATA"; | |
2064 | default: return NULL; | |
2065 | } | |
2066 | } | |
2067 | ||
2068 | static const char * | |
2069 | get_alpha_dynamic_type (unsigned long type) | |
2070 | { | |
2071 | switch (type) | |
2072 | { | |
2073 | case DT_ALPHA_PLTRO: return "ALPHA_PLTRO"; | |
2074 | default: return NULL; | |
2075 | } | |
2076 | } | |
2077 | ||
2078 | static const char * | |
2079 | get_score_dynamic_type (unsigned long type) | |
2080 | { | |
2081 | switch (type) | |
2082 | { | |
2083 | case DT_SCORE_BASE_ADDRESS: return "SCORE_BASE_ADDRESS"; | |
2084 | case DT_SCORE_LOCAL_GOTNO: return "SCORE_LOCAL_GOTNO"; | |
2085 | case DT_SCORE_SYMTABNO: return "SCORE_SYMTABNO"; | |
2086 | case DT_SCORE_GOTSYM: return "SCORE_GOTSYM"; | |
2087 | case DT_SCORE_UNREFEXTNO: return "SCORE_UNREFEXTNO"; | |
2088 | case DT_SCORE_HIPAGENO: return "SCORE_HIPAGENO"; | |
2089 | default: return NULL; | |
2090 | } | |
2091 | } | |
2092 | ||
2093 | static const char * | |
2094 | get_tic6x_dynamic_type (unsigned long type) | |
2095 | { | |
2096 | switch (type) | |
2097 | { | |
2098 | case DT_C6000_GSYM_OFFSET: return "C6000_GSYM_OFFSET"; | |
2099 | case DT_C6000_GSTR_OFFSET: return "C6000_GSTR_OFFSET"; | |
2100 | case DT_C6000_DSBT_BASE: return "C6000_DSBT_BASE"; | |
2101 | case DT_C6000_DSBT_SIZE: return "C6000_DSBT_SIZE"; | |
2102 | case DT_C6000_PREEMPTMAP: return "C6000_PREEMPTMAP"; | |
2103 | case DT_C6000_DSBT_INDEX: return "C6000_DSBT_INDEX"; | |
2104 | default: return NULL; | |
2105 | } | |
2106 | } | |
2107 | ||
2108 | static const char * | |
2109 | get_nios2_dynamic_type (unsigned long type) | |
2110 | { | |
2111 | switch (type) | |
2112 | { | |
2113 | case DT_NIOS2_GP: return "NIOS2_GP"; | |
2114 | default: return NULL; | |
2115 | } | |
2116 | } | |
2117 | ||
2118 | static const char * | |
2119 | get_solaris_dynamic_type (unsigned long type) | |
2120 | { | |
2121 | switch (type) | |
2122 | { | |
2123 | case 0x6000000d: return "SUNW_AUXILIARY"; | |
2124 | case 0x6000000e: return "SUNW_RTLDINF"; | |
2125 | case 0x6000000f: return "SUNW_FILTER"; | |
2126 | case 0x60000010: return "SUNW_CAP"; | |
2127 | case 0x60000011: return "SUNW_SYMTAB"; | |
2128 | case 0x60000012: return "SUNW_SYMSZ"; | |
2129 | case 0x60000013: return "SUNW_SORTENT"; | |
2130 | case 0x60000014: return "SUNW_SYMSORT"; | |
2131 | case 0x60000015: return "SUNW_SYMSORTSZ"; | |
2132 | case 0x60000016: return "SUNW_TLSSORT"; | |
2133 | case 0x60000017: return "SUNW_TLSSORTSZ"; | |
2134 | case 0x60000018: return "SUNW_CAPINFO"; | |
2135 | case 0x60000019: return "SUNW_STRPAD"; | |
2136 | case 0x6000001a: return "SUNW_CAPCHAIN"; | |
2137 | case 0x6000001b: return "SUNW_LDMACH"; | |
2138 | case 0x6000001d: return "SUNW_CAPCHAINENT"; | |
2139 | case 0x6000001f: return "SUNW_CAPCHAINSZ"; | |
2140 | case 0x60000021: return "SUNW_PARENT"; | |
2141 | case 0x60000023: return "SUNW_ASLR"; | |
2142 | case 0x60000025: return "SUNW_RELAX"; | |
2143 | case 0x60000029: return "SUNW_NXHEAP"; | |
2144 | case 0x6000002b: return "SUNW_NXSTACK"; | |
2145 | ||
2146 | case 0x70000001: return "SPARC_REGISTER"; | |
2147 | case 0x7ffffffd: return "AUXILIARY"; | |
2148 | case 0x7ffffffe: return "USED"; | |
2149 | case 0x7fffffff: return "FILTER"; | |
2150 | ||
2151 | default: return NULL; | |
2152 | } | |
2153 | } | |
2154 | ||
2155 | static const char * | |
2156 | get_dynamic_type (Filedata * filedata, unsigned long type) | |
2157 | { | |
2158 | static char buff[64]; | |
2159 | ||
2160 | switch (type) | |
2161 | { | |
2162 | case DT_NULL: return "NULL"; | |
2163 | case DT_NEEDED: return "NEEDED"; | |
2164 | case DT_PLTRELSZ: return "PLTRELSZ"; | |
2165 | case DT_PLTGOT: return "PLTGOT"; | |
2166 | case DT_HASH: return "HASH"; | |
2167 | case DT_STRTAB: return "STRTAB"; | |
2168 | case DT_SYMTAB: return "SYMTAB"; | |
2169 | case DT_RELA: return "RELA"; | |
2170 | case DT_RELASZ: return "RELASZ"; | |
2171 | case DT_RELAENT: return "RELAENT"; | |
2172 | case DT_STRSZ: return "STRSZ"; | |
2173 | case DT_SYMENT: return "SYMENT"; | |
2174 | case DT_INIT: return "INIT"; | |
2175 | case DT_FINI: return "FINI"; | |
2176 | case DT_SONAME: return "SONAME"; | |
2177 | case DT_RPATH: return "RPATH"; | |
2178 | case DT_SYMBOLIC: return "SYMBOLIC"; | |
2179 | case DT_REL: return "REL"; | |
2180 | case DT_RELSZ: return "RELSZ"; | |
2181 | case DT_RELENT: return "RELENT"; | |
2182 | case DT_PLTREL: return "PLTREL"; | |
2183 | case DT_DEBUG: return "DEBUG"; | |
2184 | case DT_TEXTREL: return "TEXTREL"; | |
2185 | case DT_JMPREL: return "JMPREL"; | |
2186 | case DT_BIND_NOW: return "BIND_NOW"; | |
2187 | case DT_INIT_ARRAY: return "INIT_ARRAY"; | |
2188 | case DT_FINI_ARRAY: return "FINI_ARRAY"; | |
2189 | case DT_INIT_ARRAYSZ: return "INIT_ARRAYSZ"; | |
2190 | case DT_FINI_ARRAYSZ: return "FINI_ARRAYSZ"; | |
2191 | case DT_RUNPATH: return "RUNPATH"; | |
2192 | case DT_FLAGS: return "FLAGS"; | |
2193 | ||
2194 | case DT_PREINIT_ARRAY: return "PREINIT_ARRAY"; | |
2195 | case DT_PREINIT_ARRAYSZ: return "PREINIT_ARRAYSZ"; | |
2196 | case DT_SYMTAB_SHNDX: return "SYMTAB_SHNDX"; | |
2197 | ||
2198 | case DT_CHECKSUM: return "CHECKSUM"; | |
2199 | case DT_PLTPADSZ: return "PLTPADSZ"; | |
2200 | case DT_MOVEENT: return "MOVEENT"; | |
2201 | case DT_MOVESZ: return "MOVESZ"; | |
2202 | case DT_FEATURE: return "FEATURE"; | |
2203 | case DT_POSFLAG_1: return "POSFLAG_1"; | |
2204 | case DT_SYMINSZ: return "SYMINSZ"; | |
2205 | case DT_SYMINENT: return "SYMINENT"; /* aka VALRNGHI */ | |
2206 | ||
2207 | case DT_ADDRRNGLO: return "ADDRRNGLO"; | |
2208 | case DT_CONFIG: return "CONFIG"; | |
2209 | case DT_DEPAUDIT: return "DEPAUDIT"; | |
2210 | case DT_AUDIT: return "AUDIT"; | |
2211 | case DT_PLTPAD: return "PLTPAD"; | |
2212 | case DT_MOVETAB: return "MOVETAB"; | |
2213 | case DT_SYMINFO: return "SYMINFO"; /* aka ADDRRNGHI */ | |
2214 | ||
2215 | case DT_VERSYM: return "VERSYM"; | |
2216 | ||
2217 | case DT_TLSDESC_GOT: return "TLSDESC_GOT"; | |
2218 | case DT_TLSDESC_PLT: return "TLSDESC_PLT"; | |
2219 | case DT_RELACOUNT: return "RELACOUNT"; | |
2220 | case DT_RELCOUNT: return "RELCOUNT"; | |
2221 | case DT_FLAGS_1: return "FLAGS_1"; | |
2222 | case DT_VERDEF: return "VERDEF"; | |
2223 | case DT_VERDEFNUM: return "VERDEFNUM"; | |
2224 | case DT_VERNEED: return "VERNEED"; | |
2225 | case DT_VERNEEDNUM: return "VERNEEDNUM"; | |
2226 | ||
2227 | case DT_AUXILIARY: return "AUXILIARY"; | |
2228 | case DT_USED: return "USED"; | |
2229 | case DT_FILTER: return "FILTER"; | |
2230 | ||
2231 | case DT_GNU_PRELINKED: return "GNU_PRELINKED"; | |
2232 | case DT_GNU_CONFLICT: return "GNU_CONFLICT"; | |
2233 | case DT_GNU_CONFLICTSZ: return "GNU_CONFLICTSZ"; | |
2234 | case DT_GNU_LIBLIST: return "GNU_LIBLIST"; | |
2235 | case DT_GNU_LIBLISTSZ: return "GNU_LIBLISTSZ"; | |
2236 | case DT_GNU_HASH: return "GNU_HASH"; | |
2237 | case DT_GNU_FLAGS_1: return "GNU_FLAGS_1"; | |
2238 | ||
2239 | default: | |
2240 | if ((type >= DT_LOPROC) && (type <= DT_HIPROC)) | |
2241 | { | |
2242 | const char * result; | |
2243 | ||
2244 | switch (filedata->file_header.e_machine) | |
2245 | { | |
2246 | case EM_AARCH64: | |
2247 | result = get_aarch64_dynamic_type (type); | |
2248 | break; | |
2249 | case EM_MIPS: | |
2250 | case EM_MIPS_RS3_LE: | |
2251 | result = get_mips_dynamic_type (type); | |
2252 | break; | |
2253 | case EM_SPARCV9: | |
2254 | result = get_sparc64_dynamic_type (type); | |
2255 | break; | |
2256 | case EM_PPC: | |
2257 | result = get_ppc_dynamic_type (type); | |
2258 | break; | |
2259 | case EM_PPC64: | |
2260 | result = get_ppc64_dynamic_type (type); | |
2261 | break; | |
2262 | case EM_IA_64: | |
2263 | result = get_ia64_dynamic_type (type); | |
2264 | break; | |
2265 | case EM_ALPHA: | |
2266 | result = get_alpha_dynamic_type (type); | |
2267 | break; | |
2268 | case EM_SCORE: | |
2269 | result = get_score_dynamic_type (type); | |
2270 | break; | |
2271 | case EM_TI_C6000: | |
2272 | result = get_tic6x_dynamic_type (type); | |
2273 | break; | |
2274 | case EM_ALTERA_NIOS2: | |
2275 | result = get_nios2_dynamic_type (type); | |
2276 | break; | |
2277 | default: | |
2278 | if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS) | |
2279 | result = get_solaris_dynamic_type (type); | |
2280 | else | |
2281 | result = NULL; | |
2282 | break; | |
2283 | } | |
2284 | ||
2285 | if (result != NULL) | |
2286 | return result; | |
2287 | ||
2288 | snprintf (buff, sizeof (buff), _("Processor Specific: %lx"), type); | |
2289 | } | |
2290 | else if (((type >= DT_LOOS) && (type <= DT_HIOS)) | |
2291 | || (filedata->file_header.e_machine == EM_PARISC | |
2292 | && (type >= OLD_DT_LOOS) && (type <= OLD_DT_HIOS))) | |
2293 | { | |
2294 | const char * result; | |
2295 | ||
2296 | switch (filedata->file_header.e_machine) | |
2297 | { | |
2298 | case EM_PARISC: | |
2299 | result = get_parisc_dynamic_type (type); | |
2300 | break; | |
2301 | case EM_IA_64: | |
2302 | result = get_ia64_dynamic_type (type); | |
2303 | break; | |
2304 | default: | |
2305 | if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS) | |
2306 | result = get_solaris_dynamic_type (type); | |
2307 | else | |
2308 | result = NULL; | |
2309 | break; | |
2310 | } | |
2311 | ||
2312 | if (result != NULL) | |
2313 | return result; | |
2314 | ||
2315 | snprintf (buff, sizeof (buff), _("Operating System specific: %lx"), | |
2316 | type); | |
2317 | } | |
2318 | else | |
2319 | snprintf (buff, sizeof (buff), _("<unknown>: %lx"), type); | |
2320 | ||
2321 | return buff; | |
2322 | } | |
2323 | } | |
2324 | ||
2325 | static char * | |
2326 | get_file_type (unsigned e_type) | |
2327 | { | |
2328 | static char buff[64]; | |
2329 | ||
2330 | switch (e_type) | |
2331 | { | |
2332 | case ET_NONE: return _("NONE (None)"); | |
2333 | case ET_REL: return _("REL (Relocatable file)"); | |
2334 | case ET_EXEC: return _("EXEC (Executable file)"); | |
2335 | case ET_DYN: return _("DYN (Shared object file)"); | |
2336 | case ET_CORE: return _("CORE (Core file)"); | |
2337 | ||
2338 | default: | |
2339 | if ((e_type >= ET_LOPROC) && (e_type <= ET_HIPROC)) | |
2340 | snprintf (buff, sizeof (buff), _("Processor Specific: (%x)"), e_type); | |
2341 | else if ((e_type >= ET_LOOS) && (e_type <= ET_HIOS)) | |
2342 | snprintf (buff, sizeof (buff), _("OS Specific: (%x)"), e_type); | |
2343 | else | |
2344 | snprintf (buff, sizeof (buff), _("<unknown>: %x"), e_type); | |
2345 | return buff; | |
2346 | } | |
2347 | } | |
2348 | ||
2349 | static char * | |
2350 | get_machine_name (unsigned e_machine) | |
2351 | { | |
2352 | static char buff[64]; /* XXX */ | |
2353 | ||
2354 | switch (e_machine) | |
2355 | { | |
2356 | /* Please keep this switch table sorted by increasing EM_ value. */ | |
2357 | /* 0 */ | |
2358 | case EM_NONE: return _("None"); | |
2359 | case EM_M32: return "WE32100"; | |
2360 | case EM_SPARC: return "Sparc"; | |
2361 | case EM_386: return "Intel 80386"; | |
2362 | case EM_68K: return "MC68000"; | |
2363 | case EM_88K: return "MC88000"; | |
2364 | case EM_IAMCU: return "Intel MCU"; | |
2365 | case EM_860: return "Intel 80860"; | |
2366 | case EM_MIPS: return "MIPS R3000"; | |
2367 | case EM_S370: return "IBM System/370"; | |
2368 | /* 10 */ | |
2369 | case EM_MIPS_RS3_LE: return "MIPS R4000 big-endian"; | |
2370 | case EM_OLD_SPARCV9: return "Sparc v9 (old)"; | |
2371 | case EM_PARISC: return "HPPA"; | |
2372 | case EM_VPP550: return "Fujitsu VPP500"; | |
2373 | case EM_SPARC32PLUS: return "Sparc v8+" ; | |
2374 | case EM_960: return "Intel 80960"; | |
2375 | case EM_PPC: return "PowerPC"; | |
2376 | /* 20 */ | |
2377 | case EM_PPC64: return "PowerPC64"; | |
2378 | case EM_S390_OLD: | |
2379 | case EM_S390: return "IBM S/390"; | |
2380 | case EM_SPU: return "SPU"; | |
2381 | /* 30 */ | |
2382 | case EM_V800: return "Renesas V850 (using RH850 ABI)"; | |
2383 | case EM_FR20: return "Fujitsu FR20"; | |
2384 | case EM_RH32: return "TRW RH32"; | |
2385 | case EM_MCORE: return "MCORE"; | |
2386 | /* 40 */ | |
2387 | case EM_ARM: return "ARM"; | |
2388 | case EM_OLD_ALPHA: return "Digital Alpha (old)"; | |
2389 | case EM_SH: return "Renesas / SuperH SH"; | |
2390 | case EM_SPARCV9: return "Sparc v9"; | |
2391 | case EM_TRICORE: return "Siemens Tricore"; | |
2392 | case EM_ARC: return "ARC"; | |
2393 | case EM_H8_300: return "Renesas H8/300"; | |
2394 | case EM_H8_300H: return "Renesas H8/300H"; | |
2395 | case EM_H8S: return "Renesas H8S"; | |
2396 | case EM_H8_500: return "Renesas H8/500"; | |
2397 | /* 50 */ | |
2398 | case EM_IA_64: return "Intel IA-64"; | |
2399 | case EM_MIPS_X: return "Stanford MIPS-X"; | |
2400 | case EM_COLDFIRE: return "Motorola Coldfire"; | |
2401 | case EM_68HC12: return "Motorola MC68HC12 Microcontroller"; | |
2402 | case EM_MMA: return "Fujitsu Multimedia Accelerator"; | |
2403 | case EM_PCP: return "Siemens PCP"; | |
2404 | case EM_NCPU: return "Sony nCPU embedded RISC processor"; | |
2405 | case EM_NDR1: return "Denso NDR1 microprocesspr"; | |
2406 | case EM_STARCORE: return "Motorola Star*Core processor"; | |
2407 | case EM_ME16: return "Toyota ME16 processor"; | |
2408 | /* 60 */ | |
2409 | case EM_ST100: return "STMicroelectronics ST100 processor"; | |
2410 | case EM_TINYJ: return "Advanced Logic Corp. TinyJ embedded processor"; | |
2411 | case EM_X86_64: return "Advanced Micro Devices X86-64"; | |
2412 | case EM_PDSP: return "Sony DSP processor"; | |
2413 | case EM_PDP10: return "Digital Equipment Corp. PDP-10"; | |
2414 | case EM_PDP11: return "Digital Equipment Corp. PDP-11"; | |
2415 | case EM_FX66: return "Siemens FX66 microcontroller"; | |
2416 | case EM_ST9PLUS: return "STMicroelectronics ST9+ 8/16 bit microcontroller"; | |
2417 | case EM_ST7: return "STMicroelectronics ST7 8-bit microcontroller"; | |
2418 | case EM_68HC16: return "Motorola MC68HC16 Microcontroller"; | |
2419 | /* 70 */ | |
2420 | case EM_68HC11: return "Motorola MC68HC11 Microcontroller"; | |
2421 | case EM_68HC08: return "Motorola MC68HC08 Microcontroller"; | |
2422 | case EM_68HC05: return "Motorola MC68HC05 Microcontroller"; | |
2423 | case EM_SVX: return "Silicon Graphics SVx"; | |
2424 | case EM_ST19: return "STMicroelectronics ST19 8-bit microcontroller"; | |
2425 | case EM_VAX: return "Digital VAX"; | |
2426 | case EM_CRIS: return "Axis Communications 32-bit embedded processor"; | |
2427 | case EM_JAVELIN: return "Infineon Technologies 32-bit embedded cpu"; | |
2428 | case EM_FIREPATH: return "Element 14 64-bit DSP processor"; | |
2429 | case EM_ZSP: return "LSI Logic's 16-bit DSP processor"; | |
2430 | /* 80 */ | |
2431 | case EM_MMIX: return "Donald Knuth's educational 64-bit processor"; | |
2432 | case EM_HUANY: return "Harvard Universitys's machine-independent object format"; | |
2433 | case EM_PRISM: return "Vitesse Prism"; | |
2434 | case EM_AVR_OLD: | |
2435 | case EM_AVR: return "Atmel AVR 8-bit microcontroller"; | |
2436 | case EM_CYGNUS_FR30: | |
2437 | case EM_FR30: return "Fujitsu FR30"; | |
2438 | case EM_CYGNUS_D10V: | |
2439 | case EM_D10V: return "d10v"; | |
2440 | case EM_CYGNUS_D30V: | |
2441 | case EM_D30V: return "d30v"; | |
2442 | case EM_CYGNUS_V850: | |
2443 | case EM_V850: return "Renesas V850"; | |
2444 | case EM_CYGNUS_M32R: | |
2445 | case EM_M32R: return "Renesas M32R (formerly Mitsubishi M32r)"; | |
2446 | case EM_CYGNUS_MN10300: | |
2447 | case EM_MN10300: return "mn10300"; | |
2448 | /* 90 */ | |
2449 | case EM_CYGNUS_MN10200: | |
2450 | case EM_MN10200: return "mn10200"; | |
2451 | case EM_PJ: return "picoJava"; | |
2452 | case EM_OR1K: return "OpenRISC 1000"; | |
2453 | case EM_ARC_COMPACT: return "ARCompact"; | |
2454 | case EM_XTENSA_OLD: | |
2455 | case EM_XTENSA: return "Tensilica Xtensa Processor"; | |
2456 | case EM_VIDEOCORE: return "Alphamosaic VideoCore processor"; | |
2457 | case EM_TMM_GPP: return "Thompson Multimedia General Purpose Processor"; | |
2458 | case EM_NS32K: return "National Semiconductor 32000 series"; | |
2459 | case EM_TPC: return "Tenor Network TPC processor"; | |
2460 | case EM_SNP1K: return "Trebia SNP 1000 processor"; | |
2461 | /* 100 */ | |
2462 | case EM_ST200: return "STMicroelectronics ST200 microcontroller"; | |
2463 | case EM_IP2K_OLD: | |
2464 | case EM_IP2K: return "Ubicom IP2xxx 8-bit microcontrollers"; | |
2465 | case EM_MAX: return "MAX Processor"; | |
2466 | case EM_CR: return "National Semiconductor CompactRISC"; | |
2467 | case EM_F2MC16: return "Fujitsu F2MC16"; | |
2468 | case EM_MSP430: return "Texas Instruments msp430 microcontroller"; | |
2469 | case EM_BLACKFIN: return "Analog Devices Blackfin"; | |
2470 | case EM_SE_C33: return "S1C33 Family of Seiko Epson processors"; | |
2471 | case EM_SEP: return "Sharp embedded microprocessor"; | |
2472 | case EM_ARCA: return "Arca RISC microprocessor"; | |
2473 | /* 110 */ | |
2474 | case EM_UNICORE: return "Unicore"; | |
2475 | case EM_EXCESS: return "eXcess 16/32/64-bit configurable embedded CPU"; | |
2476 | case EM_DXP: return "Icera Semiconductor Inc. Deep Execution Processor"; | |
2477 | case EM_ALTERA_NIOS2: return "Altera Nios II"; | |
2478 | case EM_CRX: return "National Semiconductor CRX microprocessor"; | |
2479 | case EM_XGATE: return "Motorola XGATE embedded processor"; | |
2480 | case EM_C166: | |
2481 | case EM_XC16X: return "Infineon Technologies xc16x"; | |
2482 | case EM_M16C: return "Renesas M16C series microprocessors"; | |
2483 | case EM_DSPIC30F: return "Microchip Technology dsPIC30F Digital Signal Controller"; | |
2484 | case EM_CE: return "Freescale Communication Engine RISC core"; | |
2485 | /* 120 */ | |
2486 | case EM_M32C: return "Renesas M32c"; | |
2487 | /* 130 */ | |
2488 | case EM_TSK3000: return "Altium TSK3000 core"; | |
2489 | case EM_RS08: return "Freescale RS08 embedded processor"; | |
2490 | case EM_ECOG2: return "Cyan Technology eCOG2 microprocessor"; | |
2491 | case EM_SCORE: return "SUNPLUS S+Core"; | |
2492 | case EM_DSP24: return "New Japan Radio (NJR) 24-bit DSP Processor"; | |
2493 | case EM_VIDEOCORE3: return "Broadcom VideoCore III processor"; | |
2494 | case EM_LATTICEMICO32: return "Lattice Mico32"; | |
2495 | case EM_SE_C17: return "Seiko Epson C17 family"; | |
2496 | /* 140 */ | |
2497 | case EM_TI_C6000: return "Texas Instruments TMS320C6000 DSP family"; | |
2498 | case EM_TI_C2000: return "Texas Instruments TMS320C2000 DSP family"; | |
2499 | case EM_TI_C5500: return "Texas Instruments TMS320C55x DSP family"; | |
2500 | case EM_TI_PRU: return "TI PRU I/O processor"; | |
2501 | /* 160 */ | |
2502 | case EM_MMDSP_PLUS: return "STMicroelectronics 64bit VLIW Data Signal Processor"; | |
2503 | case EM_CYPRESS_M8C: return "Cypress M8C microprocessor"; | |
2504 | case EM_R32C: return "Renesas R32C series microprocessors"; | |
2505 | case EM_TRIMEDIA: return "NXP Semiconductors TriMedia architecture family"; | |
2506 | case EM_QDSP6: return "QUALCOMM DSP6 Processor"; | |
2507 | case EM_8051: return "Intel 8051 and variants"; | |
2508 | case EM_STXP7X: return "STMicroelectronics STxP7x family"; | |
2509 | case EM_NDS32: return "Andes Technology compact code size embedded RISC processor family"; | |
2510 | case EM_ECOG1X: return "Cyan Technology eCOG1X family"; | |
2511 | case EM_MAXQ30: return "Dallas Semiconductor MAXQ30 Core microcontrollers"; | |
2512 | /* 170 */ | |
2513 | case EM_XIMO16: return "New Japan Radio (NJR) 16-bit DSP Processor"; | |
2514 | case EM_MANIK: return "M2000 Reconfigurable RISC Microprocessor"; | |
2515 | case EM_CRAYNV2: return "Cray Inc. NV2 vector architecture"; | |
2516 | case EM_RX: return "Renesas RX"; | |
2517 | case EM_METAG: return "Imagination Technologies Meta processor architecture"; | |
2518 | case EM_MCST_ELBRUS: return "MCST Elbrus general purpose hardware architecture"; | |
2519 | case EM_ECOG16: return "Cyan Technology eCOG16 family"; | |
2520 | case EM_CR16: | |
2521 | case EM_MICROBLAZE: | |
2522 | case EM_MICROBLAZE_OLD: return "Xilinx MicroBlaze"; | |
2523 | case EM_ETPU: return "Freescale Extended Time Processing Unit"; | |
2524 | case EM_SLE9X: return "Infineon Technologies SLE9X core"; | |
2525 | /* 180 */ | |
2526 | case EM_L1OM: return "Intel L1OM"; | |
2527 | case EM_K1OM: return "Intel K1OM"; | |
2528 | case EM_INTEL182: return "Intel (reserved)"; | |
2529 | case EM_AARCH64: return "AArch64"; | |
2530 | case EM_ARM184: return "ARM (reserved)"; | |
2531 | case EM_AVR32: return "Atmel Corporation 32-bit microprocessor"; | |
2532 | case EM_STM8: return "STMicroeletronics STM8 8-bit microcontroller"; | |
2533 | case EM_TILE64: return "Tilera TILE64 multicore architecture family"; | |
2534 | case EM_TILEPRO: return "Tilera TILEPro multicore architecture family"; | |
2535 | /* 190 */ | |
2536 | case EM_CUDA: return "NVIDIA CUDA architecture"; | |
2537 | case EM_TILEGX: return "Tilera TILE-Gx multicore architecture family"; | |
2538 | case EM_CLOUDSHIELD: return "CloudShield architecture family"; | |
2539 | case EM_COREA_1ST: return "KIPO-KAIST Core-A 1st generation processor family"; | |
2540 | case EM_COREA_2ND: return "KIPO-KAIST Core-A 2nd generation processor family"; | |
2541 | case EM_ARC_COMPACT2: return "ARCv2"; | |
2542 | case EM_OPEN8: return "Open8 8-bit RISC soft processor core"; | |
2543 | case EM_RL78: return "Renesas RL78"; | |
2544 | case EM_VIDEOCORE5: return "Broadcom VideoCore V processor"; | |
2545 | case EM_78K0R: return "Renesas 78K0R"; | |
2546 | /* 200 */ | |
2547 | case EM_56800EX: return "Freescale 56800EX Digital Signal Controller (DSC)"; | |
2548 | case EM_BA1: return "Beyond BA1 CPU architecture"; | |
2549 | case EM_BA2: return "Beyond BA2 CPU architecture"; | |
2550 | case EM_XCORE: return "XMOS xCORE processor family"; | |
2551 | case EM_MCHP_PIC: return "Microchip 8-bit PIC(r) family"; | |
2552 | /* 210 */ | |
2553 | case EM_KM32: return "KM211 KM32 32-bit processor"; | |
2554 | case EM_KMX32: return "KM211 KMX32 32-bit processor"; | |
2555 | case EM_KMX16: return "KM211 KMX16 16-bit processor"; | |
2556 | case EM_KMX8: return "KM211 KMX8 8-bit processor"; | |
2557 | case EM_KVARC: return "KM211 KVARC processor"; | |
2558 | case EM_CDP: return "Paneve CDP architecture family"; | |
2559 | case EM_COGE: return "Cognitive Smart Memory Processor"; | |
2560 | case EM_COOL: return "Bluechip Systems CoolEngine"; | |
2561 | case EM_NORC: return "Nanoradio Optimized RISC"; | |
2562 | case EM_CSR_KALIMBA: return "CSR Kalimba architecture family"; | |
2563 | /* 220 */ | |
2564 | case EM_Z80: return "Zilog Z80"; | |
2565 | case EM_VISIUM: return "CDS VISIUMcore processor"; | |
2566 | case EM_FT32: return "FTDI Chip FT32"; | |
2567 | case EM_MOXIE: return "Moxie"; | |
2568 | case EM_AMDGPU: return "AMD GPU"; | |
2569 | /* 230 (all reserved) */ | |
2570 | /* 240 */ | |
2571 | case EM_RISCV: return "RISC-V"; | |
2572 | case EM_LANAI: return "Lanai 32-bit processor"; | |
2573 | case EM_CEVA: return "CEVA Processor Architecture Family"; | |
2574 | case EM_CEVA_X2: return "CEVA X2 Processor Family"; | |
2575 | case EM_BPF: return "Linux BPF"; | |
2576 | case EM_GRAPHCORE_IPU: return "Graphcore Intelligent Processing Unit"; | |
2577 | case EM_IMG1: return "Imagination Technologies"; | |
2578 | /* 250 */ | |
2579 | case EM_NFP: return "Netronome Flow Processor"; | |
2580 | case EM_VE: return "NEC Vector Engine"; | |
2581 | case EM_CSKY: return "C-SKY"; | |
2582 | case EM_ARC_COMPACT3_64: return "Synopsys ARCv2.3 64-bit"; | |
2583 | case EM_MCS6502: return "MOS Technology MCS 6502 processor"; | |
2584 | case EM_ARC_COMPACT3: return "Synopsys ARCv2.3 32-bit"; | |
2585 | case EM_KVX: return "Kalray VLIW core of the MPPA processor family"; | |
2586 | case EM_65816: return "WDC 65816/65C816"; | |
2587 | case EM_LOONGARCH: return "Loongson Loongarch"; | |
2588 | case EM_KF32: return "ChipON KungFu32"; | |
2589 | ||
2590 | /* Large numbers... */ | |
2591 | case EM_MT: return "Morpho Techologies MT processor"; | |
2592 | case EM_ALPHA: return "Alpha"; | |
2593 | case EM_WEBASSEMBLY: return "Web Assembly"; | |
2594 | case EM_DLX: return "OpenDLX"; | |
2595 | case EM_XSTORMY16: return "Sanyo XStormy16 CPU core"; | |
2596 | case EM_IQ2000: return "Vitesse IQ2000"; | |
2597 | case EM_M32C_OLD: | |
2598 | case EM_NIOS32: return "Altera Nios"; | |
2599 | case EM_CYGNUS_MEP: return "Toshiba MeP Media Engine"; | |
2600 | case EM_ADAPTEVA_EPIPHANY: return "Adapteva EPIPHANY"; | |
2601 | case EM_CYGNUS_FRV: return "Fujitsu FR-V"; | |
2602 | case EM_S12Z: return "Freescale S12Z"; | |
2603 | ||
2604 | default: | |
2605 | snprintf (buff, sizeof (buff), _("<unknown>: 0x%x"), e_machine); | |
2606 | return buff; | |
2607 | } | |
2608 | } | |
2609 | ||
2610 | static void | |
2611 | decode_ARC_machine_flags (unsigned e_flags, unsigned e_machine, char buf[]) | |
2612 | { | |
2613 | /* ARC has two machine types EM_ARC_COMPACT and EM_ARC_COMPACT2. Some | |
2614 | other compilers don't specify an architecture type in the e_flags, and | |
2615 | instead use EM_ARC_COMPACT for old ARC600, ARC601, and ARC700 | |
2616 | architectures, and switch to EM_ARC_COMPACT2 for newer ARCEM and ARCHS | |
2617 | architectures. | |
2618 | ||
2619 | Th GNU tools follows this use of EM_ARC_COMPACT and EM_ARC_COMPACT2, | |
2620 | but also sets a specific architecture type in the e_flags field. | |
2621 | ||
2622 | However, when decoding the flags we don't worry if we see an | |
2623 | unexpected pairing, for example EM_ARC_COMPACT machine type, with | |
2624 | ARCEM architecture type. */ | |
2625 | ||
2626 | switch (e_flags & EF_ARC_MACH_MSK) | |
2627 | { | |
2628 | /* We only expect these to occur for EM_ARC_COMPACT2. */ | |
2629 | case EF_ARC_CPU_ARCV2EM: | |
2630 | strcat (buf, ", ARC EM"); | |
2631 | break; | |
2632 | case EF_ARC_CPU_ARCV2HS: | |
2633 | strcat (buf, ", ARC HS"); | |
2634 | break; | |
2635 | ||
2636 | /* We only expect these to occur for EM_ARC_COMPACT. */ | |
2637 | case E_ARC_MACH_ARC600: | |
2638 | strcat (buf, ", ARC600"); | |
2639 | break; | |
2640 | case E_ARC_MACH_ARC601: | |
2641 | strcat (buf, ", ARC601"); | |
2642 | break; | |
2643 | case E_ARC_MACH_ARC700: | |
2644 | strcat (buf, ", ARC700"); | |
2645 | break; | |
2646 | ||
2647 | /* The only times we should end up here are (a) A corrupt ELF, (b) A | |
2648 | new ELF with new architecture being read by an old version of | |
2649 | readelf, or (c) An ELF built with non-GNU compiler that does not | |
2650 | set the architecture in the e_flags. */ | |
2651 | default: | |
2652 | if (e_machine == EM_ARC_COMPACT) | |
2653 | strcat (buf, ", Unknown ARCompact"); | |
2654 | else | |
2655 | strcat (buf, ", Unknown ARC"); | |
2656 | break; | |
2657 | } | |
2658 | ||
2659 | switch (e_flags & EF_ARC_OSABI_MSK) | |
2660 | { | |
2661 | case E_ARC_OSABI_ORIG: | |
2662 | strcat (buf, ", (ABI:legacy)"); | |
2663 | break; | |
2664 | case E_ARC_OSABI_V2: | |
2665 | strcat (buf, ", (ABI:v2)"); | |
2666 | break; | |
2667 | /* Only upstream 3.9+ kernels will support ARCv2 ISA. */ | |
2668 | case E_ARC_OSABI_V3: | |
2669 | strcat (buf, ", v3 no-legacy-syscalls ABI"); | |
2670 | break; | |
2671 | case E_ARC_OSABI_V4: | |
2672 | strcat (buf, ", v4 ABI"); | |
2673 | break; | |
2674 | default: | |
2675 | strcat (buf, ", unrecognised ARC OSABI flag"); | |
2676 | break; | |
2677 | } | |
2678 | } | |
2679 | ||
2680 | static void | |
2681 | decode_ARM_machine_flags (unsigned e_flags, char buf[]) | |
2682 | { | |
2683 | unsigned eabi; | |
2684 | bfd_boolean unknown = FALSE; | |
2685 | ||
2686 | eabi = EF_ARM_EABI_VERSION (e_flags); | |
2687 | e_flags &= ~ EF_ARM_EABIMASK; | |
2688 | ||
2689 | /* Handle "generic" ARM flags. */ | |
2690 | if (e_flags & EF_ARM_RELEXEC) | |
2691 | { | |
2692 | strcat (buf, ", relocatable executable"); | |
2693 | e_flags &= ~ EF_ARM_RELEXEC; | |
2694 | } | |
2695 | ||
2696 | if (e_flags & EF_ARM_PIC) | |
2697 | { | |
2698 | strcat (buf, ", position independent"); | |
2699 | e_flags &= ~ EF_ARM_PIC; | |
2700 | } | |
2701 | ||
2702 | /* Now handle EABI specific flags. */ | |
2703 | switch (eabi) | |
2704 | { | |
2705 | default: | |
2706 | strcat (buf, ", <unrecognized EABI>"); | |
2707 | if (e_flags) | |
2708 | unknown = TRUE; | |
2709 | break; | |
2710 | ||
2711 | case EF_ARM_EABI_VER1: | |
2712 | strcat (buf, ", Version1 EABI"); | |
2713 | while (e_flags) | |
2714 | { | |
2715 | unsigned flag; | |
2716 | ||
2717 | /* Process flags one bit at a time. */ | |
2718 | flag = e_flags & - e_flags; | |
2719 | e_flags &= ~ flag; | |
2720 | ||
2721 | switch (flag) | |
2722 | { | |
2723 | case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK. */ | |
2724 | strcat (buf, ", sorted symbol tables"); | |
2725 | break; | |
2726 | ||
2727 | default: | |
2728 | unknown = TRUE; | |
2729 | break; | |
2730 | } | |
2731 | } | |
2732 | break; | |
2733 | ||
2734 | case EF_ARM_EABI_VER2: | |
2735 | strcat (buf, ", Version2 EABI"); | |
2736 | while (e_flags) | |
2737 | { | |
2738 | unsigned flag; | |
2739 | ||
2740 | /* Process flags one bit at a time. */ | |
2741 | flag = e_flags & - e_flags; | |
2742 | e_flags &= ~ flag; | |
2743 | ||
2744 | switch (flag) | |
2745 | { | |
2746 | case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK. */ | |
2747 | strcat (buf, ", sorted symbol tables"); | |
2748 | break; | |
2749 | ||
2750 | case EF_ARM_DYNSYMSUSESEGIDX: | |
2751 | strcat (buf, ", dynamic symbols use segment index"); | |
2752 | break; | |
2753 | ||
2754 | case EF_ARM_MAPSYMSFIRST: | |
2755 | strcat (buf, ", mapping symbols precede others"); | |
2756 | break; | |
2757 | ||
2758 | default: | |
2759 | unknown = TRUE; | |
2760 | break; | |
2761 | } | |
2762 | } | |
2763 | break; | |
2764 | ||
2765 | case EF_ARM_EABI_VER3: | |
2766 | strcat (buf, ", Version3 EABI"); | |
2767 | break; | |
2768 | ||
2769 | case EF_ARM_EABI_VER4: | |
2770 | strcat (buf, ", Version4 EABI"); | |
2771 | while (e_flags) | |
2772 | { | |
2773 | unsigned flag; | |
2774 | ||
2775 | /* Process flags one bit at a time. */ | |
2776 | flag = e_flags & - e_flags; | |
2777 | e_flags &= ~ flag; | |
2778 | ||
2779 | switch (flag) | |
2780 | { | |
2781 | case EF_ARM_BE8: | |
2782 | strcat (buf, ", BE8"); | |
2783 | break; | |
2784 | ||
2785 | case EF_ARM_LE8: | |
2786 | strcat (buf, ", LE8"); | |
2787 | break; | |
2788 | ||
2789 | default: | |
2790 | unknown = TRUE; | |
2791 | break; | |
2792 | } | |
2793 | } | |
2794 | break; | |
2795 | ||
2796 | case EF_ARM_EABI_VER5: | |
2797 | strcat (buf, ", Version5 EABI"); | |
2798 | while (e_flags) | |
2799 | { | |
2800 | unsigned flag; | |
2801 | ||
2802 | /* Process flags one bit at a time. */ | |
2803 | flag = e_flags & - e_flags; | |
2804 | e_flags &= ~ flag; | |
2805 | ||
2806 | switch (flag) | |
2807 | { | |
2808 | case EF_ARM_BE8: | |
2809 | strcat (buf, ", BE8"); | |
2810 | break; | |
2811 | ||
2812 | case EF_ARM_LE8: | |
2813 | strcat (buf, ", LE8"); | |
2814 | break; | |
2815 | ||
2816 | case EF_ARM_ABI_FLOAT_SOFT: /* Conflicts with EF_ARM_SOFT_FLOAT. */ | |
2817 | strcat (buf, ", soft-float ABI"); | |
2818 | break; | |
2819 | ||
2820 | case EF_ARM_ABI_FLOAT_HARD: /* Conflicts with EF_ARM_VFP_FLOAT. */ | |
2821 | strcat (buf, ", hard-float ABI"); | |
2822 | break; | |
2823 | ||
2824 | default: | |
2825 | unknown = TRUE; | |
2826 | break; | |
2827 | } | |
2828 | } | |
2829 | break; | |
2830 | ||
2831 | case EF_ARM_EABI_UNKNOWN: | |
2832 | strcat (buf, ", GNU EABI"); | |
2833 | while (e_flags) | |
2834 | { | |
2835 | unsigned flag; | |
2836 | ||
2837 | /* Process flags one bit at a time. */ | |
2838 | flag = e_flags & - e_flags; | |
2839 | e_flags &= ~ flag; | |
2840 | ||
2841 | switch (flag) | |
2842 | { | |
2843 | case EF_ARM_INTERWORK: | |
2844 | strcat (buf, ", interworking enabled"); | |
2845 | break; | |
2846 | ||
2847 | case EF_ARM_APCS_26: | |
2848 | strcat (buf, ", uses APCS/26"); | |
2849 | break; | |
2850 | ||
2851 | case EF_ARM_APCS_FLOAT: | |
2852 | strcat (buf, ", uses APCS/float"); | |
2853 | break; | |
2854 | ||
2855 | case EF_ARM_PIC: | |
2856 | strcat (buf, ", position independent"); | |
2857 | break; | |
2858 | ||
2859 | case EF_ARM_ALIGN8: | |
2860 | strcat (buf, ", 8 bit structure alignment"); | |
2861 | break; | |
2862 | ||
2863 | case EF_ARM_NEW_ABI: | |
2864 | strcat (buf, ", uses new ABI"); | |
2865 | break; | |
2866 | ||
2867 | case EF_ARM_OLD_ABI: | |
2868 | strcat (buf, ", uses old ABI"); | |
2869 | break; | |
2870 | ||
2871 | case EF_ARM_SOFT_FLOAT: | |
2872 | strcat (buf, ", software FP"); | |
2873 | break; | |
2874 | ||
2875 | case EF_ARM_VFP_FLOAT: | |
2876 | strcat (buf, ", VFP"); | |
2877 | break; | |
2878 | ||
2879 | case EF_ARM_MAVERICK_FLOAT: | |
2880 | strcat (buf, ", Maverick FP"); | |
2881 | break; | |
2882 | ||
2883 | default: | |
2884 | unknown = TRUE; | |
2885 | break; | |
2886 | } | |
2887 | } | |
2888 | } | |
2889 | ||
2890 | if (unknown) | |
2891 | strcat (buf,_(", <unknown>")); | |
2892 | } | |
2893 | ||
2894 | static void | |
2895 | decode_AVR_machine_flags (unsigned e_flags, char buf[], size_t size) | |
2896 | { | |
2897 | --size; /* Leave space for null terminator. */ | |
2898 | ||
2899 | switch (e_flags & EF_AVR_MACH) | |
2900 | { | |
2901 | case E_AVR_MACH_AVR1: | |
2902 | strncat (buf, ", avr:1", size); | |
2903 | break; | |
2904 | case E_AVR_MACH_AVR2: | |
2905 | strncat (buf, ", avr:2", size); | |
2906 | break; | |
2907 | case E_AVR_MACH_AVR25: | |
2908 | strncat (buf, ", avr:25", size); | |
2909 | break; | |
2910 | case E_AVR_MACH_AVR3: | |
2911 | strncat (buf, ", avr:3", size); | |
2912 | break; | |
2913 | case E_AVR_MACH_AVR31: | |
2914 | strncat (buf, ", avr:31", size); | |
2915 | break; | |
2916 | case E_AVR_MACH_AVR35: | |
2917 | strncat (buf, ", avr:35", size); | |
2918 | break; | |
2919 | case E_AVR_MACH_AVR4: | |
2920 | strncat (buf, ", avr:4", size); | |
2921 | break; | |
2922 | case E_AVR_MACH_AVR5: | |
2923 | strncat (buf, ", avr:5", size); | |
2924 | break; | |
2925 | case E_AVR_MACH_AVR51: | |
2926 | strncat (buf, ", avr:51", size); | |
2927 | break; | |
2928 | case E_AVR_MACH_AVR6: | |
2929 | strncat (buf, ", avr:6", size); | |
2930 | break; | |
2931 | case E_AVR_MACH_AVRTINY: | |
2932 | strncat (buf, ", avr:100", size); | |
2933 | break; | |
2934 | case E_AVR_MACH_XMEGA1: | |
2935 | strncat (buf, ", avr:101", size); | |
2936 | break; | |
2937 | case E_AVR_MACH_XMEGA2: | |
2938 | strncat (buf, ", avr:102", size); | |
2939 | break; | |
2940 | case E_AVR_MACH_XMEGA3: | |
2941 | strncat (buf, ", avr:103", size); | |
2942 | break; | |
2943 | case E_AVR_MACH_XMEGA4: | |
2944 | strncat (buf, ", avr:104", size); | |
2945 | break; | |
2946 | case E_AVR_MACH_XMEGA5: | |
2947 | strncat (buf, ", avr:105", size); | |
2948 | break; | |
2949 | case E_AVR_MACH_XMEGA6: | |
2950 | strncat (buf, ", avr:106", size); | |
2951 | break; | |
2952 | case E_AVR_MACH_XMEGA7: | |
2953 | strncat (buf, ", avr:107", size); | |
2954 | break; | |
2955 | default: | |
2956 | strncat (buf, ", avr:<unknown>", size); | |
2957 | break; | |
2958 | } | |
2959 | ||
2960 | size -= strlen (buf); | |
2961 | if (e_flags & EF_AVR_LINKRELAX_PREPARED) | |
2962 | strncat (buf, ", link-relax", size); | |
2963 | } | |
2964 | ||
2965 | static void | |
2966 | decode_NDS32_machine_flags (unsigned e_flags, char buf[], size_t size) | |
2967 | { | |
2968 | unsigned abi; | |
2969 | unsigned arch; | |
2970 | unsigned config; | |
2971 | unsigned version; | |
2972 | bfd_boolean has_fpu = FALSE; | |
2973 | unsigned int r = 0; | |
2974 | ||
2975 | static const char *ABI_STRINGS[] = | |
2976 | { | |
2977 | "ABI v0", /* use r5 as return register; only used in N1213HC */ | |
2978 | "ABI v1", /* use r0 as return register */ | |
2979 | "ABI v2", /* use r0 as return register and don't reserve 24 bytes for arguments */ | |
2980 | "ABI v2fp", /* for FPU */ | |
2981 | "AABI", | |
2982 | "ABI2 FP+" | |
2983 | }; | |
2984 | static const char *VER_STRINGS[] = | |
2985 | { | |
2986 | "Andes ELF V1.3 or older", | |
2987 | "Andes ELF V1.3.1", | |
2988 | "Andes ELF V1.4" | |
2989 | }; | |
2990 | static const char *ARCH_STRINGS[] = | |
2991 | { | |
2992 | "", | |
2993 | "Andes Star v1.0", | |
2994 | "Andes Star v2.0", | |
2995 | "Andes Star v3.0", | |
2996 | "Andes Star v3.0m" | |
2997 | }; | |
2998 | ||
2999 | abi = EF_NDS_ABI & e_flags; | |
3000 | arch = EF_NDS_ARCH & e_flags; | |
3001 | config = EF_NDS_INST & e_flags; | |
3002 | version = EF_NDS32_ELF_VERSION & e_flags; | |
3003 | ||
3004 | memset (buf, 0, size); | |
3005 | ||
3006 | switch (abi) | |
3007 | { | |
3008 | case E_NDS_ABI_V0: | |
3009 | case E_NDS_ABI_V1: | |
3010 | case E_NDS_ABI_V2: | |
3011 | case E_NDS_ABI_V2FP: | |
3012 | case E_NDS_ABI_AABI: | |
3013 | case E_NDS_ABI_V2FP_PLUS: | |
3014 | /* In case there are holes in the array. */ | |
3015 | r += snprintf (buf + r, size - r, ", %s", ABI_STRINGS[abi >> EF_NDS_ABI_SHIFT]); | |
3016 | break; | |
3017 | ||
3018 | default: | |
3019 | r += snprintf (buf + r, size - r, ", <unrecognized ABI>"); | |
3020 | break; | |
3021 | } | |
3022 | ||
3023 | switch (version) | |
3024 | { | |
3025 | case E_NDS32_ELF_VER_1_2: | |
3026 | case E_NDS32_ELF_VER_1_3: | |
3027 | case E_NDS32_ELF_VER_1_4: | |
3028 | r += snprintf (buf + r, size - r, ", %s", VER_STRINGS[version >> EF_NDS32_ELF_VERSION_SHIFT]); | |
3029 | break; | |
3030 | ||
3031 | default: | |
3032 | r += snprintf (buf + r, size - r, ", <unrecognized ELF version number>"); | |
3033 | break; | |
3034 | } | |
3035 | ||
3036 | if (E_NDS_ABI_V0 == abi) | |
3037 | { | |
3038 | /* OLD ABI; only used in N1213HC, has performance extension 1. */ | |
3039 | r += snprintf (buf + r, size - r, ", Andes Star v1.0, N1213HC, MAC, PERF1"); | |
3040 | if (arch == E_NDS_ARCH_STAR_V1_0) | |
3041 | r += snprintf (buf + r, size -r, ", 16b"); /* has 16-bit instructions */ | |
3042 | return; | |
3043 | } | |
3044 | ||
3045 | switch (arch) | |
3046 | { | |
3047 | case E_NDS_ARCH_STAR_V1_0: | |
3048 | case E_NDS_ARCH_STAR_V2_0: | |
3049 | case E_NDS_ARCH_STAR_V3_0: | |
3050 | case E_NDS_ARCH_STAR_V3_M: | |
3051 | r += snprintf (buf + r, size - r, ", %s", ARCH_STRINGS[arch >> EF_NDS_ARCH_SHIFT]); | |
3052 | break; | |
3053 | ||
3054 | default: | |
3055 | r += snprintf (buf + r, size - r, ", <unrecognized architecture>"); | |
3056 | /* ARCH version determines how the e_flags are interpreted. | |
3057 | If it is unknown, we cannot proceed. */ | |
3058 | return; | |
3059 | } | |
3060 | ||
3061 | /* Newer ABI; Now handle architecture specific flags. */ | |
3062 | if (arch == E_NDS_ARCH_STAR_V1_0) | |
3063 | { | |
3064 | if (config & E_NDS32_HAS_MFUSR_PC_INST) | |
3065 | r += snprintf (buf + r, size -r, ", MFUSR_PC"); | |
3066 | ||
3067 | if (!(config & E_NDS32_HAS_NO_MAC_INST)) | |
3068 | r += snprintf (buf + r, size -r, ", MAC"); | |
3069 | ||
3070 | if (config & E_NDS32_HAS_DIV_INST) | |
3071 | r += snprintf (buf + r, size -r, ", DIV"); | |
3072 | ||
3073 | if (config & E_NDS32_HAS_16BIT_INST) | |
3074 | r += snprintf (buf + r, size -r, ", 16b"); | |
3075 | } | |
3076 | else | |
3077 | { | |
3078 | if (config & E_NDS32_HAS_MFUSR_PC_INST) | |
3079 | { | |
3080 | if (version <= E_NDS32_ELF_VER_1_3) | |
3081 | r += snprintf (buf + r, size -r, ", [B8]"); | |
3082 | else | |
3083 | r += snprintf (buf + r, size -r, ", EX9"); | |
3084 | } | |
3085 | ||
3086 | if (config & E_NDS32_HAS_MAC_DX_INST) | |
3087 | r += snprintf (buf + r, size -r, ", MAC_DX"); | |
3088 | ||
3089 | if (config & E_NDS32_HAS_DIV_DX_INST) | |
3090 | r += snprintf (buf + r, size -r, ", DIV_DX"); | |
3091 | ||
3092 | if (config & E_NDS32_HAS_16BIT_INST) | |
3093 | { | |
3094 | if (version <= E_NDS32_ELF_VER_1_3) | |
3095 | r += snprintf (buf + r, size -r, ", 16b"); | |
3096 | else | |
3097 | r += snprintf (buf + r, size -r, ", IFC"); | |
3098 | } | |
3099 | } | |
3100 | ||
3101 | if (config & E_NDS32_HAS_EXT_INST) | |
3102 | r += snprintf (buf + r, size -r, ", PERF1"); | |
3103 | ||
3104 | if (config & E_NDS32_HAS_EXT2_INST) | |
3105 | r += snprintf (buf + r, size -r, ", PERF2"); | |
3106 | ||
3107 | if (config & E_NDS32_HAS_FPU_INST) | |
3108 | { | |
3109 | has_fpu = TRUE; | |
3110 | r += snprintf (buf + r, size -r, ", FPU_SP"); | |
3111 | } | |
3112 | ||
3113 | if (config & E_NDS32_HAS_FPU_DP_INST) | |
3114 | { | |
3115 | has_fpu = TRUE; | |
3116 | r += snprintf (buf + r, size -r, ", FPU_DP"); | |
3117 | } | |
3118 | ||
3119 | if (config & E_NDS32_HAS_FPU_MAC_INST) | |
3120 | { | |
3121 | has_fpu = TRUE; | |
3122 | r += snprintf (buf + r, size -r, ", FPU_MAC"); | |
3123 | } | |
3124 | ||
3125 | if (has_fpu) | |
3126 | { | |
3127 | switch ((config & E_NDS32_FPU_REG_CONF) >> E_NDS32_FPU_REG_CONF_SHIFT) | |
3128 | { | |
3129 | case E_NDS32_FPU_REG_8SP_4DP: | |
3130 | r += snprintf (buf + r, size -r, ", FPU_REG:8/4"); | |
3131 | break; | |
3132 | case E_NDS32_FPU_REG_16SP_8DP: | |
3133 | r += snprintf (buf + r, size -r, ", FPU_REG:16/8"); | |
3134 | break; | |
3135 | case E_NDS32_FPU_REG_32SP_16DP: | |
3136 | r += snprintf (buf + r, size -r, ", FPU_REG:32/16"); | |
3137 | break; | |
3138 | case E_NDS32_FPU_REG_32SP_32DP: | |
3139 | r += snprintf (buf + r, size -r, ", FPU_REG:32/32"); | |
3140 | break; | |
3141 | } | |
3142 | } | |
3143 | ||
3144 | if (config & E_NDS32_HAS_AUDIO_INST) | |
3145 | r += snprintf (buf + r, size -r, ", AUDIO"); | |
3146 | ||
3147 | if (config & E_NDS32_HAS_STRING_INST) | |
3148 | r += snprintf (buf + r, size -r, ", STR"); | |
3149 | ||
3150 | if (config & E_NDS32_HAS_REDUCED_REGS) | |
3151 | r += snprintf (buf + r, size -r, ", 16REG"); | |
3152 | ||
3153 | if (config & E_NDS32_HAS_VIDEO_INST) | |
3154 | { | |
3155 | if (version <= E_NDS32_ELF_VER_1_3) | |
3156 | r += snprintf (buf + r, size -r, ", VIDEO"); | |
3157 | else | |
3158 | r += snprintf (buf + r, size -r, ", SATURATION"); | |
3159 | } | |
3160 | ||
3161 | if (config & E_NDS32_HAS_ENCRIPT_INST) | |
3162 | r += snprintf (buf + r, size -r, ", ENCRP"); | |
3163 | ||
3164 | if (config & E_NDS32_HAS_L2C_INST) | |
3165 | r += snprintf (buf + r, size -r, ", L2C"); | |
3166 | } | |
3167 | ||
3168 | static char * | |
3169 | get_machine_flags (Filedata * filedata, unsigned e_flags, unsigned e_machine) | |
3170 | { | |
3171 | static char buf[1024]; | |
3172 | ||
3173 | buf[0] = '\0'; | |
3174 | ||
3175 | if (e_flags) | |
3176 | { | |
3177 | switch (e_machine) | |
3178 | { | |
3179 | default: | |
3180 | break; | |
3181 | ||
3182 | case EM_ARC_COMPACT2: | |
3183 | case EM_ARC_COMPACT: | |
3184 | decode_ARC_machine_flags (e_flags, e_machine, buf); | |
3185 | break; | |
3186 | ||
3187 | case EM_ARM: | |
3188 | decode_ARM_machine_flags (e_flags, buf); | |
3189 | break; | |
3190 | ||
3191 | case EM_AVR: | |
3192 | decode_AVR_machine_flags (e_flags, buf, sizeof buf); | |
3193 | break; | |
3194 | ||
3195 | case EM_BLACKFIN: | |
3196 | if (e_flags & EF_BFIN_PIC) | |
3197 | strcat (buf, ", PIC"); | |
3198 | ||
3199 | if (e_flags & EF_BFIN_FDPIC) | |
3200 | strcat (buf, ", FDPIC"); | |
3201 | ||
3202 | if (e_flags & EF_BFIN_CODE_IN_L1) | |
3203 | strcat (buf, ", code in L1"); | |
3204 | ||
3205 | if (e_flags & EF_BFIN_DATA_IN_L1) | |
3206 | strcat (buf, ", data in L1"); | |
3207 | ||
3208 | break; | |
3209 | ||
3210 | case EM_CYGNUS_FRV: | |
3211 | switch (e_flags & EF_FRV_CPU_MASK) | |
3212 | { | |
3213 | case EF_FRV_CPU_GENERIC: | |
3214 | break; | |
3215 | ||
3216 | default: | |
3217 | strcat (buf, ", fr???"); | |
3218 | break; | |
3219 | ||
3220 | case EF_FRV_CPU_FR300: | |
3221 | strcat (buf, ", fr300"); | |
3222 | break; | |
3223 | ||
3224 | case EF_FRV_CPU_FR400: | |
3225 | strcat (buf, ", fr400"); | |
3226 | break; | |
3227 | case EF_FRV_CPU_FR405: | |
3228 | strcat (buf, ", fr405"); | |
3229 | break; | |
3230 | ||
3231 | case EF_FRV_CPU_FR450: | |
3232 | strcat (buf, ", fr450"); | |
3233 | break; | |
3234 | ||
3235 | case EF_FRV_CPU_FR500: | |
3236 | strcat (buf, ", fr500"); | |
3237 | break; | |
3238 | case EF_FRV_CPU_FR550: | |
3239 | strcat (buf, ", fr550"); | |
3240 | break; | |
3241 | ||
3242 | case EF_FRV_CPU_SIMPLE: | |
3243 | strcat (buf, ", simple"); | |
3244 | break; | |
3245 | case EF_FRV_CPU_TOMCAT: | |
3246 | strcat (buf, ", tomcat"); | |
3247 | break; | |
3248 | } | |
3249 | break; | |
3250 | ||
3251 | case EM_68K: | |
3252 | if ((e_flags & EF_M68K_ARCH_MASK) == EF_M68K_M68000) | |
3253 | strcat (buf, ", m68000"); | |
3254 | else if ((e_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32) | |
3255 | strcat (buf, ", cpu32"); | |
3256 | else if ((e_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO) | |
3257 | strcat (buf, ", fido_a"); | |
3258 | else | |
3259 | { | |
3260 | char const * isa = _("unknown"); | |
3261 | char const * mac = _("unknown mac"); | |
3262 | char const * additional = NULL; | |
3263 | ||
3264 | switch (e_flags & EF_M68K_CF_ISA_MASK) | |
3265 | { | |
3266 | case EF_M68K_CF_ISA_A_NODIV: | |
3267 | isa = "A"; | |
3268 | additional = ", nodiv"; | |
3269 | break; | |
3270 | case EF_M68K_CF_ISA_A: | |
3271 | isa = "A"; | |
3272 | break; | |
3273 | case EF_M68K_CF_ISA_A_PLUS: | |
3274 | isa = "A+"; | |
3275 | break; | |
3276 | case EF_M68K_CF_ISA_B_NOUSP: | |
3277 | isa = "B"; | |
3278 | additional = ", nousp"; | |
3279 | break; | |
3280 | case EF_M68K_CF_ISA_B: | |
3281 | isa = "B"; | |
3282 | break; | |
3283 | case EF_M68K_CF_ISA_C: | |
3284 | isa = "C"; | |
3285 | break; | |
3286 | case EF_M68K_CF_ISA_C_NODIV: | |
3287 | isa = "C"; | |
3288 | additional = ", nodiv"; | |
3289 | break; | |
3290 | } | |
3291 | strcat (buf, ", cf, isa "); | |
3292 | strcat (buf, isa); | |
3293 | if (additional) | |
3294 | strcat (buf, additional); | |
3295 | if (e_flags & EF_M68K_CF_FLOAT) | |
3296 | strcat (buf, ", float"); | |
3297 | switch (e_flags & EF_M68K_CF_MAC_MASK) | |
3298 | { | |
3299 | case 0: | |
3300 | mac = NULL; | |
3301 | break; | |
3302 | case EF_M68K_CF_MAC: | |
3303 | mac = "mac"; | |
3304 | break; | |
3305 | case EF_M68K_CF_EMAC: | |
3306 | mac = "emac"; | |
3307 | break; | |
3308 | case EF_M68K_CF_EMAC_B: | |
3309 | mac = "emac_b"; | |
3310 | break; | |
3311 | } | |
3312 | if (mac) | |
3313 | { | |
3314 | strcat (buf, ", "); | |
3315 | strcat (buf, mac); | |
3316 | } | |
3317 | } | |
3318 | break; | |
3319 | ||
3320 | case EM_CYGNUS_MEP: | |
3321 | switch (e_flags & EF_MEP_CPU_MASK) | |
3322 | { | |
3323 | case EF_MEP_CPU_MEP: strcat (buf, ", generic MeP"); break; | |
3324 | case EF_MEP_CPU_C2: strcat (buf, ", MeP C2"); break; | |
3325 | case EF_MEP_CPU_C3: strcat (buf, ", MeP C3"); break; | |
3326 | case EF_MEP_CPU_C4: strcat (buf, ", MeP C4"); break; | |
3327 | case EF_MEP_CPU_C5: strcat (buf, ", MeP C5"); break; | |
3328 | case EF_MEP_CPU_H1: strcat (buf, ", MeP H1"); break; | |
3329 | default: strcat (buf, _(", <unknown MeP cpu type>")); break; | |
3330 | } | |
3331 | ||
3332 | switch (e_flags & EF_MEP_COP_MASK) | |
3333 | { | |
3334 | case EF_MEP_COP_NONE: break; | |
3335 | case EF_MEP_COP_AVC: strcat (buf, ", AVC coprocessor"); break; | |
3336 | case EF_MEP_COP_AVC2: strcat (buf, ", AVC2 coprocessor"); break; | |
3337 | case EF_MEP_COP_FMAX: strcat (buf, ", FMAX coprocessor"); break; | |
3338 | case EF_MEP_COP_IVC2: strcat (buf, ", IVC2 coprocessor"); break; | |
3339 | default: strcat (buf, _("<unknown MeP copro type>")); break; | |
3340 | } | |
3341 | ||
3342 | if (e_flags & EF_MEP_LIBRARY) | |
3343 | strcat (buf, ", Built for Library"); | |
3344 | ||
3345 | if (e_flags & EF_MEP_INDEX_MASK) | |
3346 | sprintf (buf + strlen (buf), ", Configuration Index: %#x", | |
3347 | e_flags & EF_MEP_INDEX_MASK); | |
3348 | ||
3349 | if (e_flags & ~ EF_MEP_ALL_FLAGS) | |
3350 | sprintf (buf + strlen (buf), _(", unknown flags bits: %#x"), | |
3351 | e_flags & ~ EF_MEP_ALL_FLAGS); | |
3352 | break; | |
3353 | ||
3354 | case EM_PPC: | |
3355 | if (e_flags & EF_PPC_EMB) | |
3356 | strcat (buf, ", emb"); | |
3357 | ||
3358 | if (e_flags & EF_PPC_RELOCATABLE) | |
3359 | strcat (buf, _(", relocatable")); | |
3360 | ||
3361 | if (e_flags & EF_PPC_RELOCATABLE_LIB) | |
3362 | strcat (buf, _(", relocatable-lib")); | |
3363 | break; | |
3364 | ||
3365 | case EM_PPC64: | |
3366 | if (e_flags & EF_PPC64_ABI) | |
3367 | { | |
3368 | char abi[] = ", abiv0"; | |
3369 | ||
3370 | abi[6] += e_flags & EF_PPC64_ABI; | |
3371 | strcat (buf, abi); | |
3372 | } | |
3373 | break; | |
3374 | ||
3375 | case EM_V800: | |
3376 | if ((e_flags & EF_RH850_ABI) == EF_RH850_ABI) | |
3377 | strcat (buf, ", RH850 ABI"); | |
3378 | ||
3379 | if (e_flags & EF_V800_850E3) | |
3380 | strcat (buf, ", V3 architecture"); | |
3381 | ||
3382 | if ((e_flags & (EF_RH850_FPU_DOUBLE | EF_RH850_FPU_SINGLE)) == 0) | |
3383 | strcat (buf, ", FPU not used"); | |
3384 | ||
3385 | if ((e_flags & (EF_RH850_REGMODE22 | EF_RH850_REGMODE32)) == 0) | |
3386 | strcat (buf, ", regmode: COMMON"); | |
3387 | ||
3388 | if ((e_flags & (EF_RH850_GP_FIX | EF_RH850_GP_NOFIX)) == 0) | |
3389 | strcat (buf, ", r4 not used"); | |
3390 | ||
3391 | if ((e_flags & (EF_RH850_EP_FIX | EF_RH850_EP_NOFIX)) == 0) | |
3392 | strcat (buf, ", r30 not used"); | |
3393 | ||
3394 | if ((e_flags & (EF_RH850_TP_FIX | EF_RH850_TP_NOFIX)) == 0) | |
3395 | strcat (buf, ", r5 not used"); | |
3396 | ||
3397 | if ((e_flags & (EF_RH850_REG2_RESERVE | EF_RH850_REG2_NORESERVE)) == 0) | |
3398 | strcat (buf, ", r2 not used"); | |
3399 | ||
3400 | for (e_flags &= 0xFFFF; e_flags; e_flags &= ~ (e_flags & - e_flags)) | |
3401 | { | |
3402 | switch (e_flags & - e_flags) | |
3403 | { | |
3404 | case EF_RH850_FPU_DOUBLE: strcat (buf, ", double precision FPU"); break; | |
3405 | case EF_RH850_FPU_SINGLE: strcat (buf, ", single precision FPU"); break; | |
3406 | case EF_RH850_REGMODE22: strcat (buf, ", regmode:22"); break; | |
3407 | case EF_RH850_REGMODE32: strcat (buf, ", regmode:23"); break; | |
3408 | case EF_RH850_GP_FIX: strcat (buf, ", r4 fixed"); break; | |
3409 | case EF_RH850_GP_NOFIX: strcat (buf, ", r4 free"); break; | |
3410 | case EF_RH850_EP_FIX: strcat (buf, ", r30 fixed"); break; | |
3411 | case EF_RH850_EP_NOFIX: strcat (buf, ", r30 free"); break; | |
3412 | case EF_RH850_TP_FIX: strcat (buf, ", r5 fixed"); break; | |
3413 | case EF_RH850_TP_NOFIX: strcat (buf, ", r5 free"); break; | |
3414 | case EF_RH850_REG2_RESERVE: strcat (buf, ", r2 fixed"); break; | |
3415 | case EF_RH850_REG2_NORESERVE: strcat (buf, ", r2 free"); break; | |
3416 | default: break; | |
3417 | } | |
3418 | } | |
3419 | break; | |
3420 | ||
3421 | case EM_V850: | |
3422 | case EM_CYGNUS_V850: | |
3423 | switch (e_flags & EF_V850_ARCH) | |
3424 | { | |
3425 | case E_V850E3V5_ARCH: | |
3426 | strcat (buf, ", v850e3v5"); | |
3427 | break; | |
3428 | case E_V850E2V3_ARCH: | |
3429 | strcat (buf, ", v850e2v3"); | |
3430 | break; | |
3431 | case E_V850E2_ARCH: | |
3432 | strcat (buf, ", v850e2"); | |
3433 | break; | |
3434 | case E_V850E1_ARCH: | |
3435 | strcat (buf, ", v850e1"); | |
3436 | break; | |
3437 | case E_V850E_ARCH: | |
3438 | strcat (buf, ", v850e"); | |
3439 | break; | |
3440 | case E_V850_ARCH: | |
3441 | strcat (buf, ", v850"); | |
3442 | break; | |
3443 | default: | |
3444 | strcat (buf, _(", unknown v850 architecture variant")); | |
3445 | break; | |
3446 | } | |
3447 | break; | |
3448 | ||
3449 | case EM_M32R: | |
3450 | case EM_CYGNUS_M32R: | |
3451 | if ((e_flags & EF_M32R_ARCH) == E_M32R_ARCH) | |
3452 | strcat (buf, ", m32r"); | |
3453 | break; | |
3454 | ||
3455 | case EM_MIPS: | |
3456 | case EM_MIPS_RS3_LE: | |
3457 | if (e_flags & EF_MIPS_NOREORDER) | |
3458 | strcat (buf, ", noreorder"); | |
3459 | ||
3460 | if (e_flags & EF_MIPS_PIC) | |
3461 | strcat (buf, ", pic"); | |
3462 | ||
3463 | if (e_flags & EF_MIPS_CPIC) | |
3464 | strcat (buf, ", cpic"); | |
3465 | ||
3466 | if (e_flags & EF_MIPS_UCODE) | |
3467 | strcat (buf, ", ugen_reserved"); | |
3468 | ||
3469 | if (e_flags & EF_MIPS_ABI2) | |
3470 | strcat (buf, ", abi2"); | |
3471 | ||
3472 | if (e_flags & EF_MIPS_OPTIONS_FIRST) | |
3473 | strcat (buf, ", odk first"); | |
3474 | ||
3475 | if (e_flags & EF_MIPS_32BITMODE) | |
3476 | strcat (buf, ", 32bitmode"); | |
3477 | ||
3478 | if (e_flags & EF_MIPS_NAN2008) | |
3479 | strcat (buf, ", nan2008"); | |
3480 | ||
3481 | if (e_flags & EF_MIPS_FP64) | |
3482 | strcat (buf, ", fp64"); | |
3483 | ||
3484 | switch ((e_flags & EF_MIPS_MACH)) | |
3485 | { | |
3486 | case E_MIPS_MACH_3900: strcat (buf, ", 3900"); break; | |
3487 | case E_MIPS_MACH_4010: strcat (buf, ", 4010"); break; | |
3488 | case E_MIPS_MACH_4100: strcat (buf, ", 4100"); break; | |
3489 | case E_MIPS_MACH_4111: strcat (buf, ", 4111"); break; | |
3490 | case E_MIPS_MACH_4120: strcat (buf, ", 4120"); break; | |
3491 | case E_MIPS_MACH_4650: strcat (buf, ", 4650"); break; | |
3492 | case E_MIPS_MACH_5400: strcat (buf, ", 5400"); break; | |
3493 | case E_MIPS_MACH_5500: strcat (buf, ", 5500"); break; | |
3494 | case E_MIPS_MACH_5900: strcat (buf, ", 5900"); break; | |
3495 | case E_MIPS_MACH_SB1: strcat (buf, ", sb1"); break; | |
3496 | case E_MIPS_MACH_9000: strcat (buf, ", 9000"); break; | |
3497 | case E_MIPS_MACH_LS2E: strcat (buf, ", loongson-2e"); break; | |
3498 | case E_MIPS_MACH_LS2F: strcat (buf, ", loongson-2f"); break; | |
3499 | case E_MIPS_MACH_GS464: strcat (buf, ", gs464"); break; | |
3500 | case E_MIPS_MACH_GS464E: strcat (buf, ", gs464e"); break; | |
3501 | case E_MIPS_MACH_GS264E: strcat (buf, ", gs264e"); break; | |
3502 | case E_MIPS_MACH_OCTEON: strcat (buf, ", octeon"); break; | |
3503 | case E_MIPS_MACH_OCTEON2: strcat (buf, ", octeon2"); break; | |
3504 | case E_MIPS_MACH_OCTEON3: strcat (buf, ", octeon3"); break; | |
3505 | case E_MIPS_MACH_XLR: strcat (buf, ", xlr"); break; | |
3506 | case E_MIPS_MACH_IAMR2: strcat (buf, ", interaptiv-mr2"); break; | |
3507 | case 0: | |
3508 | /* We simply ignore the field in this case to avoid confusion: | |
3509 | MIPS ELF does not specify EF_MIPS_MACH, it is a GNU | |
3510 | extension. */ | |
3511 | break; | |
3512 | default: strcat (buf, _(", unknown CPU")); break; | |
3513 | } | |
3514 | ||
3515 | switch ((e_flags & EF_MIPS_ABI)) | |
3516 | { | |
3517 | case E_MIPS_ABI_O32: strcat (buf, ", o32"); break; | |
3518 | case E_MIPS_ABI_O64: strcat (buf, ", o64"); break; | |
3519 | case E_MIPS_ABI_EABI32: strcat (buf, ", eabi32"); break; | |
3520 | case E_MIPS_ABI_EABI64: strcat (buf, ", eabi64"); break; | |
3521 | case 0: | |
3522 | /* We simply ignore the field in this case to avoid confusion: | |
3523 | MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension. | |
3524 | This means it is likely to be an o32 file, but not for | |
3525 | sure. */ | |
3526 | break; | |
3527 | default: strcat (buf, _(", unknown ABI")); break; | |
3528 | } | |
3529 | ||
3530 | if (e_flags & EF_MIPS_ARCH_ASE_MDMX) | |
3531 | strcat (buf, ", mdmx"); | |
3532 | ||
3533 | if (e_flags & EF_MIPS_ARCH_ASE_M16) | |
3534 | strcat (buf, ", mips16"); | |
3535 | ||
3536 | if (e_flags & EF_MIPS_ARCH_ASE_MICROMIPS) | |
3537 | strcat (buf, ", micromips"); | |
3538 | ||
3539 | switch ((e_flags & EF_MIPS_ARCH)) | |
3540 | { | |
3541 | case E_MIPS_ARCH_1: strcat (buf, ", mips1"); break; | |
3542 | case E_MIPS_ARCH_2: strcat (buf, ", mips2"); break; | |
3543 | case E_MIPS_ARCH_3: strcat (buf, ", mips3"); break; | |
3544 | case E_MIPS_ARCH_4: strcat (buf, ", mips4"); break; | |
3545 | case E_MIPS_ARCH_5: strcat (buf, ", mips5"); break; | |
3546 | case E_MIPS_ARCH_32: strcat (buf, ", mips32"); break; | |
3547 | case E_MIPS_ARCH_32R2: strcat (buf, ", mips32r2"); break; | |
3548 | case E_MIPS_ARCH_32R6: strcat (buf, ", mips32r6"); break; | |
3549 | case E_MIPS_ARCH_64: strcat (buf, ", mips64"); break; | |
3550 | case E_MIPS_ARCH_64R2: strcat (buf, ", mips64r2"); break; | |
3551 | case E_MIPS_ARCH_64R6: strcat (buf, ", mips64r6"); break; | |
3552 | default: strcat (buf, _(", unknown ISA")); break; | |
3553 | } | |
3554 | break; | |
3555 | ||
3556 | case EM_NDS32: | |
3557 | decode_NDS32_machine_flags (e_flags, buf, sizeof buf); | |
3558 | break; | |
3559 | ||
3560 | case EM_NFP: | |
3561 | switch (EF_NFP_MACH (e_flags)) | |
3562 | { | |
3563 | case E_NFP_MACH_3200: | |
3564 | strcat (buf, ", NFP-32xx"); | |
3565 | break; | |
3566 | case E_NFP_MACH_6000: | |
3567 | strcat (buf, ", NFP-6xxx"); | |
3568 | break; | |
3569 | } | |
3570 | break; | |
3571 | ||
3572 | case EM_RISCV: | |
3573 | if (e_flags & EF_RISCV_RVC) | |
3574 | strcat (buf, ", RVC"); | |
3575 | ||
3576 | if (e_flags & EF_RISCV_RVE) | |
3577 | strcat (buf, ", RVE"); | |
3578 | ||
3579 | switch (e_flags & EF_RISCV_FLOAT_ABI) | |
3580 | { | |
3581 | case EF_RISCV_FLOAT_ABI_SOFT: | |
3582 | strcat (buf, ", soft-float ABI"); | |
3583 | break; | |
3584 | ||
3585 | case EF_RISCV_FLOAT_ABI_SINGLE: | |
3586 | strcat (buf, ", single-float ABI"); | |
3587 | break; | |
3588 | ||
3589 | case EF_RISCV_FLOAT_ABI_DOUBLE: | |
3590 | strcat (buf, ", double-float ABI"); | |
3591 | break; | |
3592 | ||
3593 | case EF_RISCV_FLOAT_ABI_QUAD: | |
3594 | strcat (buf, ", quad-float ABI"); | |
3595 | break; | |
3596 | } | |
3597 | break; | |
3598 | ||
3599 | case EM_SH: | |
3600 | switch ((e_flags & EF_SH_MACH_MASK)) | |
3601 | { | |
3602 | case EF_SH1: strcat (buf, ", sh1"); break; | |
3603 | case EF_SH2: strcat (buf, ", sh2"); break; | |
3604 | case EF_SH3: strcat (buf, ", sh3"); break; | |
3605 | case EF_SH_DSP: strcat (buf, ", sh-dsp"); break; | |
3606 | case EF_SH3_DSP: strcat (buf, ", sh3-dsp"); break; | |
3607 | case EF_SH4AL_DSP: strcat (buf, ", sh4al-dsp"); break; | |
3608 | case EF_SH3E: strcat (buf, ", sh3e"); break; | |
3609 | case EF_SH4: strcat (buf, ", sh4"); break; | |
3610 | case EF_SH5: strcat (buf, ", sh5"); break; | |
3611 | case EF_SH2E: strcat (buf, ", sh2e"); break; | |
3612 | case EF_SH4A: strcat (buf, ", sh4a"); break; | |
3613 | case EF_SH2A: strcat (buf, ", sh2a"); break; | |
3614 | case EF_SH4_NOFPU: strcat (buf, ", sh4-nofpu"); break; | |
3615 | case EF_SH4A_NOFPU: strcat (buf, ", sh4a-nofpu"); break; | |
3616 | case EF_SH2A_NOFPU: strcat (buf, ", sh2a-nofpu"); break; | |
3617 | case EF_SH3_NOMMU: strcat (buf, ", sh3-nommu"); break; | |
3618 | case EF_SH4_NOMMU_NOFPU: strcat (buf, ", sh4-nommu-nofpu"); break; | |
3619 | case EF_SH2A_SH4_NOFPU: strcat (buf, ", sh2a-nofpu-or-sh4-nommu-nofpu"); break; | |
3620 | case EF_SH2A_SH3_NOFPU: strcat (buf, ", sh2a-nofpu-or-sh3-nommu"); break; | |
3621 | case EF_SH2A_SH4: strcat (buf, ", sh2a-or-sh4"); break; | |
3622 | case EF_SH2A_SH3E: strcat (buf, ", sh2a-or-sh3e"); break; | |
3623 | default: strcat (buf, _(", unknown ISA")); break; | |
3624 | } | |
3625 | ||
3626 | if (e_flags & EF_SH_PIC) | |
3627 | strcat (buf, ", pic"); | |
3628 | ||
3629 | if (e_flags & EF_SH_FDPIC) | |
3630 | strcat (buf, ", fdpic"); | |
3631 | break; | |
3632 | ||
3633 | case EM_OR1K: | |
3634 | if (e_flags & EF_OR1K_NODELAY) | |
3635 | strcat (buf, ", no delay"); | |
3636 | break; | |
3637 | ||
3638 | case EM_SPARCV9: | |
3639 | if (e_flags & EF_SPARC_32PLUS) | |
3640 | strcat (buf, ", v8+"); | |
3641 | ||
3642 | if (e_flags & EF_SPARC_SUN_US1) | |
3643 | strcat (buf, ", ultrasparcI"); | |
3644 | ||
3645 | if (e_flags & EF_SPARC_SUN_US3) | |
3646 | strcat (buf, ", ultrasparcIII"); | |
3647 | ||
3648 | if (e_flags & EF_SPARC_HAL_R1) | |
3649 | strcat (buf, ", halr1"); | |
3650 | ||
3651 | if (e_flags & EF_SPARC_LEDATA) | |
3652 | strcat (buf, ", ledata"); | |
3653 | ||
3654 | if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_TSO) | |
3655 | strcat (buf, ", tso"); | |
3656 | ||
3657 | if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_PSO) | |
3658 | strcat (buf, ", pso"); | |
3659 | ||
3660 | if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_RMO) | |
3661 | strcat (buf, ", rmo"); | |
3662 | break; | |
3663 | ||
3664 | case EM_PARISC: | |
3665 | switch (e_flags & EF_PARISC_ARCH) | |
3666 | { | |
3667 | case EFA_PARISC_1_0: | |
3668 | strcpy (buf, ", PA-RISC 1.0"); | |
3669 | break; | |
3670 | case EFA_PARISC_1_1: | |
3671 | strcpy (buf, ", PA-RISC 1.1"); | |
3672 | break; | |
3673 | case EFA_PARISC_2_0: | |
3674 | strcpy (buf, ", PA-RISC 2.0"); | |
3675 | break; | |
3676 | default: | |
3677 | break; | |
3678 | } | |
3679 | if (e_flags & EF_PARISC_TRAPNIL) | |
3680 | strcat (buf, ", trapnil"); | |
3681 | if (e_flags & EF_PARISC_EXT) | |
3682 | strcat (buf, ", ext"); | |
3683 | if (e_flags & EF_PARISC_LSB) | |
3684 | strcat (buf, ", lsb"); | |
3685 | if (e_flags & EF_PARISC_WIDE) | |
3686 | strcat (buf, ", wide"); | |
3687 | if (e_flags & EF_PARISC_NO_KABP) | |
3688 | strcat (buf, ", no kabp"); | |
3689 | if (e_flags & EF_PARISC_LAZYSWAP) | |
3690 | strcat (buf, ", lazyswap"); | |
3691 | break; | |
3692 | ||
3693 | case EM_PJ: | |
3694 | case EM_PJ_OLD: | |
3695 | if ((e_flags & EF_PICOJAVA_NEWCALLS) == EF_PICOJAVA_NEWCALLS) | |
3696 | strcat (buf, ", new calling convention"); | |
3697 | ||
3698 | if ((e_flags & EF_PICOJAVA_GNUCALLS) == EF_PICOJAVA_GNUCALLS) | |
3699 | strcat (buf, ", gnu calling convention"); | |
3700 | break; | |
3701 | ||
3702 | case EM_IA_64: | |
3703 | if ((e_flags & EF_IA_64_ABI64)) | |
3704 | strcat (buf, ", 64-bit"); | |
3705 | else | |
3706 | strcat (buf, ", 32-bit"); | |
3707 | if ((e_flags & EF_IA_64_REDUCEDFP)) | |
3708 | strcat (buf, ", reduced fp model"); | |
3709 | if ((e_flags & EF_IA_64_NOFUNCDESC_CONS_GP)) | |
3710 | strcat (buf, ", no function descriptors, constant gp"); | |
3711 | else if ((e_flags & EF_IA_64_CONS_GP)) | |
3712 | strcat (buf, ", constant gp"); | |
3713 | if ((e_flags & EF_IA_64_ABSOLUTE)) | |
3714 | strcat (buf, ", absolute"); | |
3715 | if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_OPENVMS) | |
3716 | { | |
3717 | if ((e_flags & EF_IA_64_VMS_LINKAGES)) | |
3718 | strcat (buf, ", vms_linkages"); | |
3719 | switch ((e_flags & EF_IA_64_VMS_COMCOD)) | |
3720 | { | |
3721 | case EF_IA_64_VMS_COMCOD_SUCCESS: | |
3722 | break; | |
3723 | case EF_IA_64_VMS_COMCOD_WARNING: | |
3724 | strcat (buf, ", warning"); | |
3725 | break; | |
3726 | case EF_IA_64_VMS_COMCOD_ERROR: | |
3727 | strcat (buf, ", error"); | |
3728 | break; | |
3729 | case EF_IA_64_VMS_COMCOD_ABORT: | |
3730 | strcat (buf, ", abort"); | |
3731 | break; | |
3732 | default: | |
3733 | warn (_("Unrecognised IA64 VMS Command Code: %x\n"), | |
3734 | e_flags & EF_IA_64_VMS_COMCOD); | |
3735 | strcat (buf, ", <unknown>"); | |
3736 | } | |
3737 | } | |
3738 | break; | |
3739 | ||
3740 | case EM_VAX: | |
3741 | if ((e_flags & EF_VAX_NONPIC)) | |
3742 | strcat (buf, ", non-PIC"); | |
3743 | if ((e_flags & EF_VAX_DFLOAT)) | |
3744 | strcat (buf, ", D-Float"); | |
3745 | if ((e_flags & EF_VAX_GFLOAT)) | |
3746 | strcat (buf, ", G-Float"); | |
3747 | break; | |
3748 | ||
3749 | case EM_VISIUM: | |
3750 | if (e_flags & EF_VISIUM_ARCH_MCM) | |
3751 | strcat (buf, ", mcm"); | |
3752 | else if (e_flags & EF_VISIUM_ARCH_MCM24) | |
3753 | strcat (buf, ", mcm24"); | |
3754 | if (e_flags & EF_VISIUM_ARCH_GR6) | |
3755 | strcat (buf, ", gr6"); | |
3756 | break; | |
3757 | ||
3758 | case EM_RL78: | |
3759 | switch (e_flags & E_FLAG_RL78_CPU_MASK) | |
3760 | { | |
3761 | case E_FLAG_RL78_ANY_CPU: break; | |
3762 | case E_FLAG_RL78_G10: strcat (buf, ", G10"); break; | |
3763 | case E_FLAG_RL78_G13: strcat (buf, ", G13"); break; | |
3764 | case E_FLAG_RL78_G14: strcat (buf, ", G14"); break; | |
3765 | } | |
3766 | if (e_flags & E_FLAG_RL78_64BIT_DOUBLES) | |
3767 | strcat (buf, ", 64-bit doubles"); | |
3768 | break; | |
3769 | ||
3770 | case EM_RX: | |
3771 | if (e_flags & E_FLAG_RX_64BIT_DOUBLES) | |
3772 | strcat (buf, ", 64-bit doubles"); | |
3773 | if (e_flags & E_FLAG_RX_DSP) | |
3774 | strcat (buf, ", dsp"); | |
3775 | if (e_flags & E_FLAG_RX_PID) | |
3776 | strcat (buf, ", pid"); | |
3777 | if (e_flags & E_FLAG_RX_ABI) | |
3778 | strcat (buf, ", RX ABI"); | |
3779 | if (e_flags & E_FLAG_RX_SINSNS_SET) | |
3780 | strcat (buf, e_flags & E_FLAG_RX_SINSNS_YES | |
3781 | ? ", uses String instructions" : ", bans String instructions"); | |
3782 | if (e_flags & E_FLAG_RX_V2) | |
3783 | strcat (buf, ", V2"); | |
3784 | if (e_flags & E_FLAG_RX_V3) | |
3785 | strcat (buf, ", V3"); | |
3786 | break; | |
3787 | ||
3788 | case EM_S390: | |
3789 | if (e_flags & EF_S390_HIGH_GPRS) | |
3790 | strcat (buf, ", highgprs"); | |
3791 | break; | |
3792 | ||
3793 | case EM_TI_C6000: | |
3794 | if ((e_flags & EF_C6000_REL)) | |
3795 | strcat (buf, ", relocatable module"); | |
3796 | break; | |
3797 | ||
3798 | case EM_MSP430: | |
3799 | strcat (buf, _(": architecture variant: ")); | |
3800 | switch (e_flags & EF_MSP430_MACH) | |
3801 | { | |
3802 | case E_MSP430_MACH_MSP430x11: strcat (buf, "MSP430x11"); break; | |
3803 | case E_MSP430_MACH_MSP430x11x1 : strcat (buf, "MSP430x11x1 "); break; | |
3804 | case E_MSP430_MACH_MSP430x12: strcat (buf, "MSP430x12"); break; | |
3805 | case E_MSP430_MACH_MSP430x13: strcat (buf, "MSP430x13"); break; | |
3806 | case E_MSP430_MACH_MSP430x14: strcat (buf, "MSP430x14"); break; | |
3807 | case E_MSP430_MACH_MSP430x15: strcat (buf, "MSP430x15"); break; | |
3808 | case E_MSP430_MACH_MSP430x16: strcat (buf, "MSP430x16"); break; | |
3809 | case E_MSP430_MACH_MSP430x31: strcat (buf, "MSP430x31"); break; | |
3810 | case E_MSP430_MACH_MSP430x32: strcat (buf, "MSP430x32"); break; | |
3811 | case E_MSP430_MACH_MSP430x33: strcat (buf, "MSP430x33"); break; | |
3812 | case E_MSP430_MACH_MSP430x41: strcat (buf, "MSP430x41"); break; | |
3813 | case E_MSP430_MACH_MSP430x42: strcat (buf, "MSP430x42"); break; | |
3814 | case E_MSP430_MACH_MSP430x43: strcat (buf, "MSP430x43"); break; | |
3815 | case E_MSP430_MACH_MSP430x44: strcat (buf, "MSP430x44"); break; | |
3816 | case E_MSP430_MACH_MSP430X : strcat (buf, "MSP430X"); break; | |
3817 | default: | |
3818 | strcat (buf, _(": unknown")); break; | |
3819 | } | |
3820 | ||
3821 | if (e_flags & ~ EF_MSP430_MACH) | |
3822 | strcat (buf, _(": unknown extra flag bits also present")); | |
3823 | break; | |
3824 | ||
3825 | case EM_Z80: | |
3826 | switch (e_flags & EF_Z80_MACH_MSK) | |
3827 | { | |
3828 | case EF_Z80_MACH_Z80: strcat (buf, ", Z80"); break; | |
3829 | case EF_Z80_MACH_Z180: strcat (buf, ", Z180"); break; | |
3830 | case EF_Z80_MACH_R800: strcat (buf, ", R800"); break; | |
3831 | case EF_Z80_MACH_EZ80_Z80: strcat (buf, ", EZ80"); break; | |
3832 | case EF_Z80_MACH_EZ80_ADL: strcat (buf, ", EZ80, ADL"); break; | |
3833 | case EF_Z80_MACH_GBZ80: strcat (buf, ", GBZ80"); break; | |
3834 | case EF_Z80_MACH_Z80N: strcat (buf, ", Z80N"); break; | |
3835 | default: | |
3836 | strcat (buf, _(", unknown")); break; | |
3837 | } | |
3838 | break; | |
3839 | } | |
3840 | } | |
3841 | ||
3842 | return buf; | |
3843 | } | |
3844 | ||
3845 | static const char * | |
3846 | get_osabi_name (Filedata * filedata, unsigned int osabi) | |
3847 | { | |
3848 | static char buff[32]; | |
3849 | ||
3850 | switch (osabi) | |
3851 | { | |
3852 | case ELFOSABI_NONE: return "UNIX - System V"; | |
3853 | case ELFOSABI_HPUX: return "UNIX - HP-UX"; | |
3854 | case ELFOSABI_NETBSD: return "UNIX - NetBSD"; | |
3855 | case ELFOSABI_GNU: return "UNIX - GNU"; | |
3856 | case ELFOSABI_SOLARIS: return "UNIX - Solaris"; | |
3857 | case ELFOSABI_AIX: return "UNIX - AIX"; | |
3858 | case ELFOSABI_IRIX: return "UNIX - IRIX"; | |
3859 | case ELFOSABI_FREEBSD: return "UNIX - FreeBSD"; | |
3860 | case ELFOSABI_TRU64: return "UNIX - TRU64"; | |
3861 | case ELFOSABI_MODESTO: return "Novell - Modesto"; | |
3862 | case ELFOSABI_OPENBSD: return "UNIX - OpenBSD"; | |
3863 | case ELFOSABI_OPENVMS: return "VMS - OpenVMS"; | |
3864 | case ELFOSABI_NSK: return "HP - Non-Stop Kernel"; | |
3865 | case ELFOSABI_AROS: return "AROS"; | |
3866 | case ELFOSABI_FENIXOS: return "FenixOS"; | |
3867 | case ELFOSABI_CLOUDABI: return "Nuxi CloudABI"; | |
3868 | case ELFOSABI_OPENVOS: return "Stratus Technologies OpenVOS"; | |
3869 | default: | |
3870 | if (osabi >= 64) | |
3871 | switch (filedata->file_header.e_machine) | |
3872 | { | |
3873 | case EM_ARM: | |
3874 | switch (osabi) | |
3875 | { | |
3876 | case ELFOSABI_ARM: return "ARM"; | |
3877 | case ELFOSABI_ARM_FDPIC: return "ARM FDPIC"; | |
3878 | default: | |
3879 | break; | |
3880 | } | |
3881 | break; | |
3882 | ||
3883 | case EM_MSP430: | |
3884 | case EM_MSP430_OLD: | |
3885 | case EM_VISIUM: | |
3886 | switch (osabi) | |
3887 | { | |
3888 | case ELFOSABI_STANDALONE: return _("Standalone App"); | |
3889 | default: | |
3890 | break; | |
3891 | } | |
3892 | break; | |
3893 | ||
3894 | case EM_TI_C6000: | |
3895 | switch (osabi) | |
3896 | { | |
3897 | case ELFOSABI_C6000_ELFABI: return _("Bare-metal C6000"); | |
3898 | case ELFOSABI_C6000_LINUX: return "Linux C6000"; | |
3899 | default: | |
3900 | break; | |
3901 | } | |
3902 | break; | |
3903 | ||
3904 | default: | |
3905 | break; | |
3906 | } | |
3907 | snprintf (buff, sizeof (buff), _("<unknown: %x>"), osabi); | |
3908 | return buff; | |
3909 | } | |
3910 | } | |
3911 | ||
3912 | static const char * | |
3913 | get_aarch64_segment_type (unsigned long type) | |
3914 | { | |
3915 | switch (type) | |
3916 | { | |
3917 | case PT_AARCH64_ARCHEXT: return "AARCH64_ARCHEXT"; | |
3918 | default: return NULL; | |
3919 | } | |
3920 | } | |
3921 | ||
3922 | static const char * | |
3923 | get_arm_segment_type (unsigned long type) | |
3924 | { | |
3925 | switch (type) | |
3926 | { | |
3927 | case PT_ARM_EXIDX: return "EXIDX"; | |
3928 | default: return NULL; | |
3929 | } | |
3930 | } | |
3931 | ||
3932 | static const char * | |
3933 | get_s390_segment_type (unsigned long type) | |
3934 | { | |
3935 | switch (type) | |
3936 | { | |
3937 | case PT_S390_PGSTE: return "S390_PGSTE"; | |
3938 | default: return NULL; | |
3939 | } | |
3940 | } | |
3941 | ||
3942 | static const char * | |
3943 | get_mips_segment_type (unsigned long type) | |
3944 | { | |
3945 | switch (type) | |
3946 | { | |
3947 | case PT_MIPS_REGINFO: return "REGINFO"; | |
3948 | case PT_MIPS_RTPROC: return "RTPROC"; | |
3949 | case PT_MIPS_OPTIONS: return "OPTIONS"; | |
3950 | case PT_MIPS_ABIFLAGS: return "ABIFLAGS"; | |
3951 | default: return NULL; | |
3952 | } | |
3953 | } | |
3954 | ||
3955 | static const char * | |
3956 | get_parisc_segment_type (unsigned long type) | |
3957 | { | |
3958 | switch (type) | |
3959 | { | |
3960 | case PT_PARISC_ARCHEXT: return "PARISC_ARCHEXT"; | |
3961 | case PT_PARISC_UNWIND: return "PARISC_UNWIND"; | |
3962 | case PT_PARISC_WEAKORDER: return "PARISC_WEAKORDER"; | |
3963 | default: return NULL; | |
3964 | } | |
3965 | } | |
3966 | ||
3967 | static const char * | |
3968 | get_ia64_segment_type (unsigned long type) | |
3969 | { | |
3970 | switch (type) | |
3971 | { | |
3972 | case PT_IA_64_ARCHEXT: return "IA_64_ARCHEXT"; | |
3973 | case PT_IA_64_UNWIND: return "IA_64_UNWIND"; | |
3974 | default: return NULL; | |
3975 | } | |
3976 | } | |
3977 | ||
3978 | static const char * | |
3979 | get_tic6x_segment_type (unsigned long type) | |
3980 | { | |
3981 | switch (type) | |
3982 | { | |
3983 | case PT_C6000_PHATTR: return "C6000_PHATTR"; | |
3984 | default: return NULL; | |
3985 | } | |
3986 | } | |
3987 | ||
3988 | static const char * | |
3989 | get_hpux_segment_type (unsigned long type, unsigned e_machine) | |
3990 | { | |
3991 | if (e_machine == EM_PARISC) | |
3992 | switch (type) | |
3993 | { | |
3994 | case PT_HP_TLS: return "HP_TLS"; | |
3995 | case PT_HP_CORE_NONE: return "HP_CORE_NONE"; | |
3996 | case PT_HP_CORE_VERSION: return "HP_CORE_VERSION"; | |
3997 | case PT_HP_CORE_KERNEL: return "HP_CORE_KERNEL"; | |
3998 | case PT_HP_CORE_COMM: return "HP_CORE_COMM"; | |
3999 | case PT_HP_CORE_PROC: return "HP_CORE_PROC"; | |
4000 | case PT_HP_CORE_LOADABLE: return "HP_CORE_LOADABLE"; | |
4001 | case PT_HP_CORE_STACK: return "HP_CORE_STACK"; | |
4002 | case PT_HP_CORE_SHM: return "HP_CORE_SHM"; | |
4003 | case PT_HP_CORE_MMF: return "HP_CORE_MMF"; | |
4004 | case PT_HP_PARALLEL: return "HP_PARALLEL"; | |
4005 | case PT_HP_FASTBIND: return "HP_FASTBIND"; | |
4006 | case PT_HP_OPT_ANNOT: return "HP_OPT_ANNOT"; | |
4007 | case PT_HP_HSL_ANNOT: return "HP_HSL_ANNOT"; | |
4008 | case PT_HP_STACK: return "HP_STACK"; | |
4009 | case PT_HP_CORE_UTSNAME: return "HP_CORE_UTSNAME"; | |
4010 | default: return NULL; | |
4011 | } | |
4012 | ||
4013 | if (e_machine == EM_IA_64) | |
4014 | switch (type) | |
4015 | { | |
4016 | case PT_HP_TLS: return "HP_TLS"; | |
4017 | case PT_IA_64_HP_OPT_ANOT: return "HP_OPT_ANNOT"; | |
4018 | case PT_IA_64_HP_HSL_ANOT: return "HP_HSL_ANNOT"; | |
4019 | case PT_IA_64_HP_STACK: return "HP_STACK"; | |
4020 | default: return NULL; | |
4021 | } | |
4022 | ||
4023 | return NULL; | |
4024 | } | |
4025 | ||
4026 | static const char * | |
4027 | get_solaris_segment_type (unsigned long type) | |
4028 | { | |
4029 | switch (type) | |
4030 | { | |
4031 | case 0x6464e550: return "PT_SUNW_UNWIND"; | |
4032 | case 0x6474e550: return "PT_SUNW_EH_FRAME"; | |
4033 | case 0x6ffffff7: return "PT_LOSUNW"; | |
4034 | case 0x6ffffffa: return "PT_SUNWBSS"; | |
4035 | case 0x6ffffffb: return "PT_SUNWSTACK"; | |
4036 | case 0x6ffffffc: return "PT_SUNWDTRACE"; | |
4037 | case 0x6ffffffd: return "PT_SUNWCAP"; | |
4038 | case 0x6fffffff: return "PT_HISUNW"; | |
4039 | default: return NULL; | |
4040 | } | |
4041 | } | |
4042 | ||
4043 | static const char * | |
4044 | get_segment_type (Filedata * filedata, unsigned long p_type) | |
4045 | { | |
4046 | static char buff[32]; | |
4047 | ||
4048 | switch (p_type) | |
4049 | { | |
4050 | case PT_NULL: return "NULL"; | |
4051 | case PT_LOAD: return "LOAD"; | |
4052 | case PT_DYNAMIC: return "DYNAMIC"; | |
4053 | case PT_INTERP: return "INTERP"; | |
4054 | case PT_NOTE: return "NOTE"; | |
4055 | case PT_SHLIB: return "SHLIB"; | |
4056 | case PT_PHDR: return "PHDR"; | |
4057 | case PT_TLS: return "TLS"; | |
4058 | case PT_GNU_EH_FRAME: return "GNU_EH_FRAME"; | |
4059 | case PT_GNU_STACK: return "GNU_STACK"; | |
4060 | case PT_GNU_RELRO: return "GNU_RELRO"; | |
4061 | case PT_GNU_PROPERTY: return "GNU_PROPERTY"; | |
4062 | ||
4063 | case PT_OPENBSD_RANDOMIZE: return "OPENBSD_RANDOMIZE"; | |
4064 | case PT_OPENBSD_WXNEEDED: return "OPENBSD_WXNEEDED"; | |
4065 | case PT_OPENBSD_BOOTDATA: return "OPENBSD_BOOTDATA"; | |
4066 | ||
4067 | default: | |
4068 | if ((p_type >= PT_LOPROC) && (p_type <= PT_HIPROC)) | |
4069 | { | |
4070 | const char * result; | |
4071 | ||
4072 | switch (filedata->file_header.e_machine) | |
4073 | { | |
4074 | case EM_AARCH64: | |
4075 | result = get_aarch64_segment_type (p_type); | |
4076 | break; | |
4077 | case EM_ARM: | |
4078 | result = get_arm_segment_type (p_type); | |
4079 | break; | |
4080 | case EM_MIPS: | |
4081 | case EM_MIPS_RS3_LE: | |
4082 | result = get_mips_segment_type (p_type); | |
4083 | break; | |
4084 | case EM_PARISC: | |
4085 | result = get_parisc_segment_type (p_type); | |
4086 | break; | |
4087 | case EM_IA_64: | |
4088 | result = get_ia64_segment_type (p_type); | |
4089 | break; | |
4090 | case EM_TI_C6000: | |
4091 | result = get_tic6x_segment_type (p_type); | |
4092 | break; | |
4093 | case EM_S390: | |
4094 | case EM_S390_OLD: | |
4095 | result = get_s390_segment_type (p_type); | |
4096 | break; | |
4097 | default: | |
4098 | result = NULL; | |
4099 | break; | |
4100 | } | |
4101 | ||
4102 | if (result != NULL) | |
4103 | return result; | |
4104 | ||
4105 | sprintf (buff, "LOPROC+%#lx", p_type - PT_LOPROC); | |
4106 | } | |
4107 | else if ((p_type >= PT_LOOS) && (p_type <= PT_HIOS)) | |
4108 | { | |
4109 | const char * result = NULL; | |
4110 | ||
4111 | switch (filedata->file_header.e_ident[EI_OSABI]) | |
4112 | { | |
4113 | case ELFOSABI_GNU: | |
4114 | case ELFOSABI_FREEBSD: | |
4115 | if (p_type >= PT_GNU_MBIND_LO && p_type <= PT_GNU_MBIND_HI) | |
4116 | { | |
4117 | sprintf (buff, "GNU_MBIND+%#lx", p_type - PT_GNU_MBIND_LO); | |
4118 | result = buff; | |
4119 | } | |
4120 | break; | |
4121 | case ELFOSABI_HPUX: | |
4122 | result = get_hpux_segment_type (p_type, | |
4123 | filedata->file_header.e_machine); | |
4124 | break; | |
4125 | case ELFOSABI_SOLARIS: | |
4126 | result = get_solaris_segment_type (p_type); | |
4127 | break; | |
4128 | default: | |
4129 | break; | |
4130 | } | |
4131 | if (result != NULL) | |
4132 | return result; | |
4133 | ||
4134 | sprintf (buff, "LOOS+%#lx", p_type - PT_LOOS); | |
4135 | } | |
4136 | else | |
4137 | snprintf (buff, sizeof (buff), _("<unknown>: %lx"), p_type); | |
4138 | ||
4139 | return buff; | |
4140 | } | |
4141 | } | |
4142 | ||
4143 | static const char * | |
4144 | get_arc_section_type_name (unsigned int sh_type) | |
4145 | { | |
4146 | switch (sh_type) | |
4147 | { | |
4148 | case SHT_ARC_ATTRIBUTES: return "ARC_ATTRIBUTES"; | |
4149 | default: | |
4150 | break; | |
4151 | } | |
4152 | return NULL; | |
4153 | } | |
4154 | ||
4155 | static const char * | |
4156 | get_mips_section_type_name (unsigned int sh_type) | |
4157 | { | |
4158 | switch (sh_type) | |
4159 | { | |
4160 | case SHT_MIPS_LIBLIST: return "MIPS_LIBLIST"; | |
4161 | case SHT_MIPS_MSYM: return "MIPS_MSYM"; | |
4162 | case SHT_MIPS_CONFLICT: return "MIPS_CONFLICT"; | |
4163 | case SHT_MIPS_GPTAB: return "MIPS_GPTAB"; | |
4164 | case SHT_MIPS_UCODE: return "MIPS_UCODE"; | |
4165 | case SHT_MIPS_DEBUG: return "MIPS_DEBUG"; | |
4166 | case SHT_MIPS_REGINFO: return "MIPS_REGINFO"; | |
4167 | case SHT_MIPS_PACKAGE: return "MIPS_PACKAGE"; | |
4168 | case SHT_MIPS_PACKSYM: return "MIPS_PACKSYM"; | |
4169 | case SHT_MIPS_RELD: return "MIPS_RELD"; | |
4170 | case SHT_MIPS_IFACE: return "MIPS_IFACE"; | |
4171 | case SHT_MIPS_CONTENT: return "MIPS_CONTENT"; | |
4172 | case SHT_MIPS_OPTIONS: return "MIPS_OPTIONS"; | |
4173 | case SHT_MIPS_SHDR: return "MIPS_SHDR"; | |
4174 | case SHT_MIPS_FDESC: return "MIPS_FDESC"; | |
4175 | case SHT_MIPS_EXTSYM: return "MIPS_EXTSYM"; | |
4176 | case SHT_MIPS_DENSE: return "MIPS_DENSE"; | |
4177 | case SHT_MIPS_PDESC: return "MIPS_PDESC"; | |
4178 | case SHT_MIPS_LOCSYM: return "MIPS_LOCSYM"; | |
4179 | case SHT_MIPS_AUXSYM: return "MIPS_AUXSYM"; | |
4180 | case SHT_MIPS_OPTSYM: return "MIPS_OPTSYM"; | |
4181 | case SHT_MIPS_LOCSTR: return "MIPS_LOCSTR"; | |
4182 | case SHT_MIPS_LINE: return "MIPS_LINE"; | |
4183 | case SHT_MIPS_RFDESC: return "MIPS_RFDESC"; | |
4184 | case SHT_MIPS_DELTASYM: return "MIPS_DELTASYM"; | |
4185 | case SHT_MIPS_DELTAINST: return "MIPS_DELTAINST"; | |
4186 | case SHT_MIPS_DELTACLASS: return "MIPS_DELTACLASS"; | |
4187 | case SHT_MIPS_DWARF: return "MIPS_DWARF"; | |
4188 | case SHT_MIPS_DELTADECL: return "MIPS_DELTADECL"; | |
4189 | case SHT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB"; | |
4190 | case SHT_MIPS_EVENTS: return "MIPS_EVENTS"; | |
4191 | case SHT_MIPS_TRANSLATE: return "MIPS_TRANSLATE"; | |
4192 | case SHT_MIPS_PIXIE: return "MIPS_PIXIE"; | |
4193 | case SHT_MIPS_XLATE: return "MIPS_XLATE"; | |
4194 | case SHT_MIPS_XLATE_DEBUG: return "MIPS_XLATE_DEBUG"; | |
4195 | case SHT_MIPS_WHIRL: return "MIPS_WHIRL"; | |
4196 | case SHT_MIPS_EH_REGION: return "MIPS_EH_REGION"; | |
4197 | case SHT_MIPS_XLATE_OLD: return "MIPS_XLATE_OLD"; | |
4198 | case SHT_MIPS_PDR_EXCEPTION: return "MIPS_PDR_EXCEPTION"; | |
4199 | case SHT_MIPS_ABIFLAGS: return "MIPS_ABIFLAGS"; | |
4200 | case SHT_MIPS_XHASH: return "MIPS_XHASH"; | |
4201 | default: | |
4202 | break; | |
4203 | } | |
4204 | return NULL; | |
4205 | } | |
4206 | ||
4207 | static const char * | |
4208 | get_parisc_section_type_name (unsigned int sh_type) | |
4209 | { | |
4210 | switch (sh_type) | |
4211 | { | |
4212 | case SHT_PARISC_EXT: return "PARISC_EXT"; | |
4213 | case SHT_PARISC_UNWIND: return "PARISC_UNWIND"; | |
4214 | case SHT_PARISC_DOC: return "PARISC_DOC"; | |
4215 | case SHT_PARISC_ANNOT: return "PARISC_ANNOT"; | |
4216 | case SHT_PARISC_SYMEXTN: return "PARISC_SYMEXTN"; | |
4217 | case SHT_PARISC_STUBS: return "PARISC_STUBS"; | |
4218 | case SHT_PARISC_DLKM: return "PARISC_DLKM"; | |
4219 | default: return NULL; | |
4220 | } | |
4221 | } | |
4222 | ||
4223 | static const char * | |
4224 | get_ia64_section_type_name (Filedata * filedata, unsigned int sh_type) | |
4225 | { | |
4226 | /* If the top 8 bits are 0x78 the next 8 are the os/abi ID. */ | |
4227 | if ((sh_type & 0xFF000000) == SHT_IA_64_LOPSREG) | |
4228 | return get_osabi_name (filedata, (sh_type & 0x00FF0000) >> 16); | |
4229 | ||
4230 | switch (sh_type) | |
4231 | { | |
4232 | case SHT_IA_64_EXT: return "IA_64_EXT"; | |
4233 | case SHT_IA_64_UNWIND: return "IA_64_UNWIND"; | |
4234 | case SHT_IA_64_PRIORITY_INIT: return "IA_64_PRIORITY_INIT"; | |
4235 | case SHT_IA_64_VMS_TRACE: return "VMS_TRACE"; | |
4236 | case SHT_IA_64_VMS_TIE_SIGNATURES: return "VMS_TIE_SIGNATURES"; | |
4237 | case SHT_IA_64_VMS_DEBUG: return "VMS_DEBUG"; | |
4238 | case SHT_IA_64_VMS_DEBUG_STR: return "VMS_DEBUG_STR"; | |
4239 | case SHT_IA_64_VMS_LINKAGES: return "VMS_LINKAGES"; | |
4240 | case SHT_IA_64_VMS_SYMBOL_VECTOR: return "VMS_SYMBOL_VECTOR"; | |
4241 | case SHT_IA_64_VMS_FIXUP: return "VMS_FIXUP"; | |
4242 | default: | |
4243 | break; | |
4244 | } | |
4245 | return NULL; | |
4246 | } | |
4247 | ||
4248 | static const char * | |
4249 | get_x86_64_section_type_name (unsigned int sh_type) | |
4250 | { | |
4251 | switch (sh_type) | |
4252 | { | |
4253 | case SHT_X86_64_UNWIND: return "X86_64_UNWIND"; | |
4254 | default: return NULL; | |
4255 | } | |
4256 | } | |
4257 | ||
4258 | static const char * | |
4259 | get_aarch64_section_type_name (unsigned int sh_type) | |
4260 | { | |
4261 | switch (sh_type) | |
4262 | { | |
4263 | case SHT_AARCH64_ATTRIBUTES: return "AARCH64_ATTRIBUTES"; | |
4264 | default: return NULL; | |
4265 | } | |
4266 | } | |
4267 | ||
4268 | static const char * | |
4269 | get_arm_section_type_name (unsigned int sh_type) | |
4270 | { | |
4271 | switch (sh_type) | |
4272 | { | |
4273 | case SHT_ARM_EXIDX: return "ARM_EXIDX"; | |
4274 | case SHT_ARM_PREEMPTMAP: return "ARM_PREEMPTMAP"; | |
4275 | case SHT_ARM_ATTRIBUTES: return "ARM_ATTRIBUTES"; | |
4276 | case SHT_ARM_DEBUGOVERLAY: return "ARM_DEBUGOVERLAY"; | |
4277 | case SHT_ARM_OVERLAYSECTION: return "ARM_OVERLAYSECTION"; | |
4278 | default: return NULL; | |
4279 | } | |
4280 | } | |
4281 | ||
4282 | static const char * | |
4283 | get_tic6x_section_type_name (unsigned int sh_type) | |
4284 | { | |
4285 | switch (sh_type) | |
4286 | { | |
4287 | case SHT_C6000_UNWIND: return "C6000_UNWIND"; | |
4288 | case SHT_C6000_PREEMPTMAP: return "C6000_PREEMPTMAP"; | |
4289 | case SHT_C6000_ATTRIBUTES: return "C6000_ATTRIBUTES"; | |
4290 | case SHT_TI_ICODE: return "TI_ICODE"; | |
4291 | case SHT_TI_XREF: return "TI_XREF"; | |
4292 | case SHT_TI_HANDLER: return "TI_HANDLER"; | |
4293 | case SHT_TI_INITINFO: return "TI_INITINFO"; | |
4294 | case SHT_TI_PHATTRS: return "TI_PHATTRS"; | |
4295 | default: return NULL; | |
4296 | } | |
4297 | } | |
4298 | ||
4299 | static const char * | |
4300 | get_msp430_section_type_name (unsigned int sh_type) | |
4301 | { | |
4302 | switch (sh_type) | |
4303 | { | |
4304 | case SHT_MSP430_SEC_FLAGS: return "MSP430_SEC_FLAGS"; | |
4305 | case SHT_MSP430_SYM_ALIASES: return "MSP430_SYM_ALIASES"; | |
4306 | case SHT_MSP430_ATTRIBUTES: return "MSP430_ATTRIBUTES"; | |
4307 | default: return NULL; | |
4308 | } | |
4309 | } | |
4310 | ||
4311 | static const char * | |
4312 | get_nfp_section_type_name (unsigned int sh_type) | |
4313 | { | |
4314 | switch (sh_type) | |
4315 | { | |
4316 | case SHT_NFP_MECONFIG: return "NFP_MECONFIG"; | |
4317 | case SHT_NFP_INITREG: return "NFP_INITREG"; | |
4318 | case SHT_NFP_UDEBUG: return "NFP_UDEBUG"; | |
4319 | default: return NULL; | |
4320 | } | |
4321 | } | |
4322 | ||
4323 | static const char * | |
4324 | get_v850_section_type_name (unsigned int sh_type) | |
4325 | { | |
4326 | switch (sh_type) | |
4327 | { | |
4328 | case SHT_V850_SCOMMON: return "V850 Small Common"; | |
4329 | case SHT_V850_TCOMMON: return "V850 Tiny Common"; | |
4330 | case SHT_V850_ZCOMMON: return "V850 Zero Common"; | |
4331 | case SHT_RENESAS_IOP: return "RENESAS IOP"; | |
4332 | case SHT_RENESAS_INFO: return "RENESAS INFO"; | |
4333 | default: return NULL; | |
4334 | } | |
4335 | } | |
4336 | ||
4337 | static const char * | |
4338 | get_riscv_section_type_name (unsigned int sh_type) | |
4339 | { | |
4340 | switch (sh_type) | |
4341 | { | |
4342 | case SHT_RISCV_ATTRIBUTES: return "RISCV_ATTRIBUTES"; | |
4343 | default: return NULL; | |
4344 | } | |
4345 | } | |
4346 | ||
4347 | static const char * | |
4348 | get_csky_section_type_name (unsigned int sh_type) | |
4349 | { | |
4350 | switch (sh_type) | |
4351 | { | |
4352 | case SHT_CSKY_ATTRIBUTES: return "CSKY_ATTRIBUTES"; | |
4353 | default: return NULL; | |
4354 | } | |
4355 | } | |
4356 | ||
4357 | static const char * | |
4358 | get_section_type_name (Filedata * filedata, unsigned int sh_type) | |
4359 | { | |
4360 | static char buff[32]; | |
4361 | const char * result; | |
4362 | ||
4363 | switch (sh_type) | |
4364 | { | |
4365 | case SHT_NULL: return "NULL"; | |
4366 | case SHT_PROGBITS: return "PROGBITS"; | |
4367 | case SHT_SYMTAB: return "SYMTAB"; | |
4368 | case SHT_STRTAB: return "STRTAB"; | |
4369 | case SHT_RELA: return "RELA"; | |
4370 | case SHT_HASH: return "HASH"; | |
4371 | case SHT_DYNAMIC: return "DYNAMIC"; | |
4372 | case SHT_NOTE: return "NOTE"; | |
4373 | case SHT_NOBITS: return "NOBITS"; | |
4374 | case SHT_REL: return "REL"; | |
4375 | case SHT_SHLIB: return "SHLIB"; | |
4376 | case SHT_DYNSYM: return "DYNSYM"; | |
4377 | case SHT_INIT_ARRAY: return "INIT_ARRAY"; | |
4378 | case SHT_FINI_ARRAY: return "FINI_ARRAY"; | |
4379 | case SHT_PREINIT_ARRAY: return "PREINIT_ARRAY"; | |
4380 | case SHT_GNU_HASH: return "GNU_HASH"; | |
4381 | case SHT_GROUP: return "GROUP"; | |
4382 | case SHT_SYMTAB_SHNDX: return "SYMTAB SECTION INDICES"; | |
4383 | case SHT_GNU_verdef: return "VERDEF"; | |
4384 | case SHT_GNU_verneed: return "VERNEED"; | |
4385 | case SHT_GNU_versym: return "VERSYM"; | |
4386 | case 0x6ffffff0: return "VERSYM"; | |
4387 | case 0x6ffffffc: return "VERDEF"; | |
4388 | case 0x7ffffffd: return "AUXILIARY"; | |
4389 | case 0x7fffffff: return "FILTER"; | |
4390 | case SHT_GNU_LIBLIST: return "GNU_LIBLIST"; | |
4391 | ||
4392 | default: | |
4393 | if ((sh_type >= SHT_LOPROC) && (sh_type <= SHT_HIPROC)) | |
4394 | { | |
4395 | switch (filedata->file_header.e_machine) | |
4396 | { | |
4397 | case EM_ARC: | |
4398 | case EM_ARC_COMPACT: | |
4399 | case EM_ARC_COMPACT2: | |
4400 | result = get_arc_section_type_name (sh_type); | |
4401 | break; | |
4402 | case EM_MIPS: | |
4403 | case EM_MIPS_RS3_LE: | |
4404 | result = get_mips_section_type_name (sh_type); | |
4405 | break; | |
4406 | case EM_PARISC: | |
4407 | result = get_parisc_section_type_name (sh_type); | |
4408 | break; | |
4409 | case EM_IA_64: | |
4410 | result = get_ia64_section_type_name (filedata, sh_type); | |
4411 | break; | |
4412 | case EM_X86_64: | |
4413 | case EM_L1OM: | |
4414 | case EM_K1OM: | |
4415 | result = get_x86_64_section_type_name (sh_type); | |
4416 | break; | |
4417 | case EM_AARCH64: | |
4418 | result = get_aarch64_section_type_name (sh_type); | |
4419 | break; | |
4420 | case EM_ARM: | |
4421 | result = get_arm_section_type_name (sh_type); | |
4422 | break; | |
4423 | case EM_TI_C6000: | |
4424 | result = get_tic6x_section_type_name (sh_type); | |
4425 | break; | |
4426 | case EM_MSP430: | |
4427 | result = get_msp430_section_type_name (sh_type); | |
4428 | break; | |
4429 | case EM_NFP: | |
4430 | result = get_nfp_section_type_name (sh_type); | |
4431 | break; | |
4432 | case EM_V800: | |
4433 | case EM_V850: | |
4434 | case EM_CYGNUS_V850: | |
4435 | result = get_v850_section_type_name (sh_type); | |
4436 | break; | |
4437 | case EM_RISCV: | |
4438 | result = get_riscv_section_type_name (sh_type); | |
4439 | break; | |
4440 | case EM_CSKY: | |
4441 | result = get_csky_section_type_name (sh_type); | |
4442 | break; | |
4443 | default: | |
4444 | result = NULL; | |
4445 | break; | |
4446 | } | |
4447 | ||
4448 | if (result != NULL) | |
4449 | return result; | |
4450 | ||
4451 | sprintf (buff, "LOPROC+%#x", sh_type - SHT_LOPROC); | |
4452 | } | |
4453 | else if ((sh_type >= SHT_LOOS) && (sh_type <= SHT_HIOS)) | |
4454 | { | |
4455 | switch (filedata->file_header.e_machine) | |
4456 | { | |
4457 | case EM_IA_64: | |
4458 | result = get_ia64_section_type_name (filedata, sh_type); | |
4459 | break; | |
4460 | default: | |
4461 | if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS) | |
4462 | result = get_solaris_section_type (sh_type); | |
4463 | else | |
4464 | { | |
4465 | switch (sh_type) | |
4466 | { | |
4467 | case SHT_GNU_INCREMENTAL_INPUTS: result = "GNU_INCREMENTAL_INPUTS"; break; | |
4468 | case SHT_GNU_ATTRIBUTES: result = "GNU_ATTRIBUTES"; break; | |
4469 | case SHT_GNU_HASH: result = "GNU_HASH"; break; | |
4470 | case SHT_GNU_LIBLIST: result = "GNU_LIBLIST"; break; | |
4471 | default: | |
4472 | result = NULL; | |
4473 | break; | |
4474 | } | |
4475 | } | |
4476 | break; | |
4477 | } | |
4478 | ||
4479 | if (result != NULL) | |
4480 | return result; | |
4481 | ||
4482 | sprintf (buff, "LOOS+%#x", sh_type - SHT_LOOS); | |
4483 | } | |
4484 | else if ((sh_type >= SHT_LOUSER) && (sh_type <= SHT_HIUSER)) | |
4485 | { | |
4486 | switch (filedata->file_header.e_machine) | |
4487 | { | |
4488 | case EM_V800: | |
4489 | case EM_V850: | |
4490 | case EM_CYGNUS_V850: | |
4491 | result = get_v850_section_type_name (sh_type); | |
4492 | break; | |
4493 | default: | |
4494 | result = NULL; | |
4495 | break; | |
4496 | } | |
4497 | ||
4498 | if (result != NULL) | |
4499 | return result; | |
4500 | ||
4501 | sprintf (buff, "LOUSER+%#x", sh_type - SHT_LOUSER); | |
4502 | } | |
4503 | else | |
4504 | /* This message is probably going to be displayed in a 15 | |
4505 | character wide field, so put the hex value first. */ | |
4506 | snprintf (buff, sizeof (buff), _("%08x: <unknown>"), sh_type); | |
4507 | ||
4508 | return buff; | |
4509 | } | |
4510 | } | |
4511 | ||
4512 | enum long_option_values | |
4513 | { | |
4514 | OPTION_DEBUG_DUMP = 512, | |
4515 | OPTION_DYN_SYMS, | |
4516 | OPTION_LTO_SYMS, | |
4517 | OPTION_DWARF_DEPTH, | |
4518 | OPTION_DWARF_START, | |
4519 | OPTION_DWARF_CHECK, | |
4520 | OPTION_CTF_DUMP, | |
4521 | OPTION_CTF_PARENT, | |
4522 | OPTION_CTF_SYMBOLS, | |
4523 | OPTION_CTF_STRINGS, | |
4524 | OPTION_WITH_SYMBOL_VERSIONS, | |
4525 | OPTION_RECURSE_LIMIT, | |
4526 | OPTION_NO_RECURSE_LIMIT, | |
4527 | OPTION_NO_DEMANGLING | |
4528 | }; | |
4529 | ||
4530 | static struct option options[] = | |
4531 | { | |
4532 | /* Note - This table is alpha-sorted on the 'val' | |
4533 | field in order to make adding new options easier. */ | |
4534 | {"arch-specific", no_argument, 0, 'A'}, | |
4535 | {"all", no_argument, 0, 'a'}, | |
4536 | {"demangle", optional_argument, 0, 'C'}, | |
4537 | {"archive-index", no_argument, 0, 'c'}, | |
4538 | {"use-dynamic", no_argument, 0, 'D'}, | |
4539 | {"dynamic", no_argument, 0, 'd'}, | |
4540 | {"headers", no_argument, 0, 'e'}, | |
4541 | {"section-groups", no_argument, 0, 'g'}, | |
4542 | {"help", no_argument, 0, 'H'}, | |
4543 | {"file-header", no_argument, 0, 'h'}, | |
4544 | {"histogram", no_argument, 0, 'I'}, | |
4545 | {"lint", no_argument, 0, 'L'}, | |
4546 | {"enable-checks", no_argument, 0, 'L'}, | |
4547 | {"program-headers", no_argument, 0, 'l'}, | |
4548 | {"segments", no_argument, 0, 'l'}, | |
4549 | {"full-section-name",no_argument, 0, 'N'}, | |
4550 | {"notes", no_argument, 0, 'n'}, | |
4551 | {"process-links", no_argument, 0, 'P'}, | |
4552 | {"string-dump", required_argument, 0, 'p'}, | |
4553 | {"relocated-dump", required_argument, 0, 'R'}, | |
4554 | {"relocs", no_argument, 0, 'r'}, | |
4555 | {"section-headers", no_argument, 0, 'S'}, | |
4556 | {"sections", no_argument, 0, 'S'}, | |
4557 | {"symbols", no_argument, 0, 's'}, | |
4558 | {"syms", no_argument, 0, 's'}, | |
4559 | {"silent-truncation",no_argument, 0, 'T'}, | |
4560 | {"section-details", no_argument, 0, 't'}, | |
4561 | {"unwind", no_argument, 0, 'u'}, | |
4562 | {"version-info", no_argument, 0, 'V'}, | |
4563 | {"version", no_argument, 0, 'v'}, | |
4564 | {"wide", no_argument, 0, 'W'}, | |
4565 | {"hex-dump", required_argument, 0, 'x'}, | |
4566 | {"decompress", no_argument, 0, 'z'}, | |
4567 | ||
4568 | {"no-demangle", no_argument, 0, OPTION_NO_DEMANGLING}, | |
4569 | {"recurse-limit", no_argument, NULL, OPTION_RECURSE_LIMIT}, | |
4570 | {"no-recurse-limit", no_argument, NULL, OPTION_NO_RECURSE_LIMIT}, | |
4571 | {"no-recursion-limit", no_argument, NULL, OPTION_NO_RECURSE_LIMIT}, | |
4572 | {"dyn-syms", no_argument, 0, OPTION_DYN_SYMS}, | |
4573 | {"lto-syms", no_argument, 0, OPTION_LTO_SYMS}, | |
4574 | {"debug-dump", optional_argument, 0, OPTION_DEBUG_DUMP}, | |
4575 | {"dwarf-depth", required_argument, 0, OPTION_DWARF_DEPTH}, | |
4576 | {"dwarf-start", required_argument, 0, OPTION_DWARF_START}, | |
4577 | {"dwarf-check", no_argument, 0, OPTION_DWARF_CHECK}, | |
4578 | #ifdef ENABLE_LIBCTF | |
4579 | {"ctf", required_argument, 0, OPTION_CTF_DUMP}, | |
4580 | {"ctf-symbols", required_argument, 0, OPTION_CTF_SYMBOLS}, | |
4581 | {"ctf-strings", required_argument, 0, OPTION_CTF_STRINGS}, | |
4582 | {"ctf-parent", required_argument, 0, OPTION_CTF_PARENT}, | |
4583 | #endif | |
4584 | ||
4585 | {0, no_argument, 0, 0} | |
4586 | }; | |
4587 | ||
4588 | static void | |
4589 | usage (FILE * stream) | |
4590 | { | |
4591 | fprintf (stream, _("Usage: readelf <option(s)> elf-file(s)\n")); | |
4592 | fprintf (stream, _(" Display information about the contents of ELF format files\n")); | |
4593 | fprintf (stream, _(" Options are:\n\ | |
4594 | -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n\ | |
4595 | -h --file-header Display the ELF file header\n\ | |
4596 | -l --program-headers Display the program headers\n\ | |
4597 | --segments An alias for --program-headers\n\ | |
4598 | -S --section-headers Display the sections' header\n\ | |
4599 | --sections An alias for --section-headers\n\ | |
4600 | -g --section-groups Display the section groups\n\ | |
4601 | -t --section-details Display the section details\n\ | |
4602 | -e --headers Equivalent to: -h -l -S\n\ | |
4603 | -s --syms Display the symbol table\n\ | |
4604 | --symbols An alias for --syms\n\ | |
4605 | --dyn-syms Display the dynamic symbol table\n\ | |
4606 | --lto-syms Display LTO symbol tables\n\ | |
4607 | -C --demangle[=STYLE] Decode low-level symbol names into user-level names\n\ | |
4608 | The STYLE, if specified, can be `auto' (the default),\n\ | |
4609 | `gnu', `lucid', `arm', `hp', `edg', `gnu-v3', `java'\n\ | |
4610 | or `gnat'\n\ | |
4611 | --no-demangle Do not demangle low-level symbol names. (This is the default)\n\ | |
4612 | --recurse-limit Enable a demangling recursion limit. (This is the default)\n\ | |
4613 | --no-recurse-limit Disable a demangling recursion limit\n\ | |
4614 | -n --notes Display the core notes (if present)\n\ | |
4615 | -r --relocs Display the relocations (if present)\n\ | |
4616 | -u --unwind Display the unwind info (if present)\n\ | |
4617 | -d --dynamic Display the dynamic section (if present)\n\ | |
4618 | -V --version-info Display the version sections (if present)\n\ | |
4619 | -A --arch-specific Display architecture specific information (if any)\n\ | |
4620 | -c --archive-index Display the symbol/file index in an archive\n\ | |
4621 | -D --use-dynamic Use the dynamic section info when displaying symbols\n\ | |
4622 | -L --lint|--enable-checks Display warning messages for possible problems\n\ | |
4623 | -x --hex-dump=<number|name>\n\ | |
4624 | Dump the contents of section <number|name> as bytes\n\ | |
4625 | -p --string-dump=<number|name>\n\ | |
4626 | Dump the contents of section <number|name> as strings\n\ | |
4627 | -R --relocated-dump=<number|name>\n\ | |
4628 | Dump the contents of section <number|name> as relocated bytes\n\ | |
4629 | -z --decompress Decompress section before dumping it\n\ | |
4630 | -w[lLiaprmfFsoORtUuTgAc] or\n\ | |
4631 | --debug-dump[=rawline,=decodedline,=info,=abbrev,=pubnames,=aranges,=macro,=frames,\n\ | |
4632 | =frames-interp,=str,=str-offsets,=loc,=Ranges,=pubtypes,\n\ | |
4633 | =gdb_index,=trace_info,=trace_abbrev,=trace_aranges,\n\ | |
4634 | =addr,=cu_index]\n\ | |
4635 | Display the contents of DWARF debug sections\n\ | |
4636 | -wk,--debug-dump=links Display the contents of sections that link to separate debuginfo files\n\ | |
4637 | -P,--process-links Display the contents of non-debug sections in separate debuginfo files. (Implies -wK)\n")); | |
4638 | #if DEFAULT_FOR_FOLLOW_LINKS | |
4639 | fprintf (stream, _("\ | |
4640 | -wK,--debug-dump=follow-links Follow links to separate debug info files (default)\n\ | |
4641 | -wN,--debug-dump=no-follow-links Do not follow links to separate debug info files\n\ | |
4642 | ")); | |
4643 | #else | |
4644 | fprintf (stream, _("\ | |
4645 | -wK,--debug-dump=follow-links Follow links to separate debug info files\n\ | |
4646 | -wN,--debug-dump=no-follow-links Do not follow links to separate debug info files (default)\n\ | |
4647 | ")); | |
4648 | #endif | |
4649 | fprintf (stream, _("\ | |
4650 | --dwarf-depth=N Do not display DIEs at depth N or greater\n\ | |
4651 | --dwarf-start=N Display DIEs starting with N, at the same depth\n\ | |
4652 | or deeper\n")); | |
4653 | #ifdef ENABLE_LIBCTF | |
4654 | fprintf (stream, _("\ | |
4655 | --ctf=<number|name> Display CTF info from section <number|name>\n\ | |
4656 | --ctf-parent=<number|name>\n\ | |
4657 | Use section <number|name> as the CTF parent\n\n\ | |
4658 | --ctf-symbols=<number|name>\n\ | |
4659 | Use section <number|name> as the CTF external symtab\n\n\ | |
4660 | --ctf-strings=<number|name>\n\ | |
4661 | Use section <number|name> as the CTF external strtab\n\n")); | |
4662 | #endif | |
4663 | ||
4664 | #ifdef SUPPORT_DISASSEMBLY | |
4665 | fprintf (stream, _("\ | |
4666 | -i --instruction-dump=<number|name>\n\ | |
4667 | Disassemble the contents of section <number|name>\n")); | |
4668 | #endif | |
4669 | fprintf (stream, _("\ | |
4670 | -I --histogram Display histogram of bucket list lengths\n\ | |
4671 | -W --wide Allow output width to exceed 80 characters\n\ | |
4672 | -T --silent-truncation If a symbol name is truncated, do not add a suffix [...]\n\ | |
4673 | @<file> Read options from <file>\n\ | |
4674 | -H --help Display this information\n\ | |
4675 | -v --version Display the version number of readelf\n")); | |
4676 | ||
4677 | if (REPORT_BUGS_TO[0] && stream == stdout) | |
4678 | fprintf (stdout, _("Report bugs to %s\n"), REPORT_BUGS_TO); | |
4679 | ||
4680 | exit (stream == stdout ? 0 : 1); | |
4681 | } | |
4682 | ||
4683 | /* Record the fact that the user wants the contents of section number | |
4684 | SECTION to be displayed using the method(s) encoded as flags bits | |
4685 | in TYPE. Note, TYPE can be zero if we are creating the array for | |
4686 | the first time. */ | |
4687 | ||
4688 | static void | |
4689 | request_dump_bynumber (struct dump_data *dumpdata, | |
4690 | unsigned int section, dump_type type) | |
4691 | { | |
4692 | if (section >= dumpdata->num_dump_sects) | |
4693 | { | |
4694 | dump_type * new_dump_sects; | |
4695 | ||
4696 | new_dump_sects = (dump_type *) calloc (section + 1, | |
4697 | sizeof (* new_dump_sects)); | |
4698 | ||
4699 | if (new_dump_sects == NULL) | |
4700 | error (_("Out of memory allocating dump request table.\n")); | |
4701 | else | |
4702 | { | |
4703 | if (dumpdata->dump_sects) | |
4704 | { | |
4705 | /* Copy current flag settings. */ | |
4706 | memcpy (new_dump_sects, dumpdata->dump_sects, | |
4707 | dumpdata->num_dump_sects * sizeof (* new_dump_sects)); | |
4708 | ||
4709 | free (dumpdata->dump_sects); | |
4710 | } | |
4711 | ||
4712 | dumpdata->dump_sects = new_dump_sects; | |
4713 | dumpdata->num_dump_sects = section + 1; | |
4714 | } | |
4715 | } | |
4716 | ||
4717 | if (dumpdata->dump_sects) | |
4718 | dumpdata->dump_sects[section] |= type; | |
4719 | } | |
4720 | ||
4721 | /* Request a dump by section name. */ | |
4722 | ||
4723 | static void | |
4724 | request_dump_byname (const char * section, dump_type type) | |
4725 | { | |
4726 | struct dump_list_entry * new_request; | |
4727 | ||
4728 | new_request = (struct dump_list_entry *) | |
4729 | malloc (sizeof (struct dump_list_entry)); | |
4730 | if (!new_request) | |
4731 | error (_("Out of memory allocating dump request table.\n")); | |
4732 | ||
4733 | new_request->name = strdup (section); | |
4734 | if (!new_request->name) | |
4735 | error (_("Out of memory allocating dump request table.\n")); | |
4736 | ||
4737 | new_request->type = type; | |
4738 | ||
4739 | new_request->next = dump_sects_byname; | |
4740 | dump_sects_byname = new_request; | |
4741 | } | |
4742 | ||
4743 | static inline void | |
4744 | request_dump (struct dump_data *dumpdata, dump_type type) | |
4745 | { | |
4746 | int section; | |
4747 | char * cp; | |
4748 | ||
4749 | do_dump++; | |
4750 | section = strtoul (optarg, & cp, 0); | |
4751 | ||
4752 | if (! *cp && section >= 0) | |
4753 | request_dump_bynumber (dumpdata, section, type); | |
4754 | else | |
4755 | request_dump_byname (optarg, type); | |
4756 | } | |
4757 | ||
4758 | static void | |
4759 | parse_args (struct dump_data *dumpdata, int argc, char ** argv) | |
4760 | { | |
4761 | int c; | |
4762 | ||
4763 | if (argc < 2) | |
4764 | usage (stderr); | |
4765 | ||
4766 | while ((c = getopt_long | |
4767 | (argc, argv, "ACDHILNPR:STVWacdeghi:lnp:rstuvw::x:z", options, NULL)) != EOF) | |
4768 | { | |
4769 | switch (c) | |
4770 | { | |
4771 | case 0: | |
4772 | /* Long options. */ | |
4773 | break; | |
4774 | case 'H': | |
4775 | usage (stdout); | |
4776 | break; | |
4777 | ||
4778 | case 'a': | |
4779 | do_syms = TRUE; | |
4780 | do_reloc = TRUE; | |
4781 | do_unwind = TRUE; | |
4782 | do_dynamic = TRUE; | |
4783 | do_header = TRUE; | |
4784 | do_sections = TRUE; | |
4785 | do_section_groups = TRUE; | |
4786 | do_segments = TRUE; | |
4787 | do_version = TRUE; | |
4788 | do_histogram = TRUE; | |
4789 | do_arch = TRUE; | |
4790 | do_notes = TRUE; | |
4791 | break; | |
4792 | ||
4793 | case 'g': | |
4794 | do_section_groups = TRUE; | |
4795 | break; | |
4796 | case 't': | |
4797 | case 'N': | |
4798 | do_sections = TRUE; | |
4799 | do_section_details = TRUE; | |
4800 | break; | |
4801 | case 'e': | |
4802 | do_header = TRUE; | |
4803 | do_sections = TRUE; | |
4804 | do_segments = TRUE; | |
4805 | break; | |
4806 | case 'A': | |
4807 | do_arch = TRUE; | |
4808 | break; | |
4809 | case 'D': | |
4810 | do_using_dynamic = TRUE; | |
4811 | break; | |
4812 | case 'r': | |
4813 | do_reloc = TRUE; | |
4814 | break; | |
4815 | case 'u': | |
4816 | do_unwind = TRUE; | |
4817 | break; | |
4818 | case 'h': | |
4819 | do_header = TRUE; | |
4820 | break; | |
4821 | case 'l': | |
4822 | do_segments = TRUE; | |
4823 | break; | |
4824 | case 's': | |
4825 | do_syms = TRUE; | |
4826 | break; | |
4827 | case 'S': | |
4828 | do_sections = TRUE; | |
4829 | break; | |
4830 | case 'd': | |
4831 | do_dynamic = TRUE; | |
4832 | break; | |
4833 | case 'I': | |
4834 | do_histogram = TRUE; | |
4835 | break; | |
4836 | case 'n': | |
4837 | do_notes = TRUE; | |
4838 | break; | |
4839 | case 'c': | |
4840 | do_archive_index = TRUE; | |
4841 | break; | |
4842 | case 'L': | |
4843 | do_checks = TRUE; | |
4844 | break; | |
4845 | case 'P': | |
4846 | process_links = TRUE; | |
4847 | do_follow_links = TRUE; | |
4848 | break; | |
4849 | case 'x': | |
4850 | request_dump (dumpdata, HEX_DUMP); | |
4851 | break; | |
4852 | case 'p': | |
4853 | request_dump (dumpdata, STRING_DUMP); | |
4854 | break; | |
4855 | case 'R': | |
4856 | request_dump (dumpdata, RELOC_DUMP); | |
4857 | break; | |
4858 | case 'z': | |
4859 | decompress_dumps = TRUE; | |
4860 | break; | |
4861 | case 'w': | |
4862 | do_dump = TRUE; | |
4863 | if (optarg == NULL) | |
4864 | { | |
4865 | do_debugging = TRUE; | |
4866 | dwarf_select_sections_all (); | |
4867 | } | |
4868 | else | |
4869 | { | |
4870 | do_debugging = FALSE; | |
4871 | dwarf_select_sections_by_letters (optarg); | |
4872 | } | |
4873 | break; | |
4874 | case OPTION_DEBUG_DUMP: | |
4875 | do_dump = TRUE; | |
4876 | if (optarg == NULL) | |
4877 | do_debugging = TRUE; | |
4878 | else | |
4879 | { | |
4880 | do_debugging = FALSE; | |
4881 | dwarf_select_sections_by_names (optarg); | |
4882 | } | |
4883 | break; | |
4884 | case OPTION_DWARF_DEPTH: | |
4885 | { | |
4886 | char *cp; | |
4887 | ||
4888 | dwarf_cutoff_level = strtoul (optarg, & cp, 0); | |
4889 | } | |
4890 | break; | |
4891 | case OPTION_DWARF_START: | |
4892 | { | |
4893 | char *cp; | |
4894 | ||
4895 | dwarf_start_die = strtoul (optarg, & cp, 0); | |
4896 | } | |
4897 | break; | |
4898 | case OPTION_DWARF_CHECK: | |
4899 | dwarf_check = TRUE; | |
4900 | break; | |
4901 | case OPTION_CTF_DUMP: | |
4902 | do_ctf = TRUE; | |
4903 | request_dump (dumpdata, CTF_DUMP); | |
4904 | break; | |
4905 | case OPTION_CTF_SYMBOLS: | |
4906 | free (dump_ctf_symtab_name); | |
4907 | dump_ctf_symtab_name = strdup (optarg); | |
4908 | break; | |
4909 | case OPTION_CTF_STRINGS: | |
4910 | free (dump_ctf_strtab_name); | |
4911 | dump_ctf_strtab_name = strdup (optarg); | |
4912 | break; | |
4913 | case OPTION_CTF_PARENT: | |
4914 | free (dump_ctf_parent_name); | |
4915 | dump_ctf_parent_name = strdup (optarg); | |
4916 | break; | |
4917 | case OPTION_DYN_SYMS: | |
4918 | do_dyn_syms = TRUE; | |
4919 | break; | |
4920 | case OPTION_LTO_SYMS: | |
4921 | do_lto_syms = TRUE; | |
4922 | break; | |
4923 | #ifdef SUPPORT_DISASSEMBLY | |
4924 | case 'i': | |
4925 | request_dump (dumpdata, DISASS_DUMP); | |
4926 | break; | |
4927 | #endif | |
4928 | case 'v': | |
4929 | print_version (program_name); | |
4930 | break; | |
4931 | case 'V': | |
4932 | do_version = TRUE; | |
4933 | break; | |
4934 | case 'W': | |
4935 | do_wide = TRUE; | |
4936 | break; | |
4937 | case 'T': | |
4938 | do_not_show_symbol_truncation = TRUE; | |
4939 | break; | |
4940 | case 'C': | |
4941 | do_demangle = TRUE; | |
4942 | if (optarg != NULL) | |
4943 | { | |
4944 | enum demangling_styles style; | |
4945 | ||
4946 | style = cplus_demangle_name_to_style (optarg); | |
4947 | if (style == unknown_demangling) | |
4948 | error (_("unknown demangling style `%s'"), optarg); | |
4949 | ||
4950 | cplus_demangle_set_style (style); | |
4951 | } | |
4952 | break; | |
4953 | case OPTION_NO_DEMANGLING: | |
4954 | do_demangle = FALSE; | |
4955 | break; | |
4956 | case OPTION_RECURSE_LIMIT: | |
4957 | demangle_flags &= ~ DMGL_NO_RECURSE_LIMIT; | |
4958 | break; | |
4959 | case OPTION_NO_RECURSE_LIMIT: | |
4960 | demangle_flags |= DMGL_NO_RECURSE_LIMIT; | |
4961 | break; | |
4962 | case OPTION_WITH_SYMBOL_VERSIONS: | |
4963 | /* Ignored for backward compatibility. */ | |
4964 | break; | |
4965 | ||
4966 | default: | |
4967 | /* xgettext:c-format */ | |
4968 | error (_("Invalid option '-%c'\n"), c); | |
4969 | /* Fall through. */ | |
4970 | case '?': | |
4971 | usage (stderr); | |
4972 | } | |
4973 | } | |
4974 | ||
4975 | if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections | |
4976 | && !do_segments && !do_header && !do_dump && !do_version | |
4977 | && !do_histogram && !do_debugging && !do_arch && !do_notes | |
4978 | && !do_section_groups && !do_archive_index | |
4979 | && !do_dyn_syms && !do_lto_syms) | |
4980 | { | |
4981 | if (do_checks) | |
4982 | { | |
4983 | check_all = TRUE; | |
4984 | do_dynamic = do_syms = do_reloc = do_unwind = do_sections = TRUE; | |
4985 | do_segments = do_header = do_dump = do_version = TRUE; | |
4986 | do_histogram = do_debugging = do_arch = do_notes = TRUE; | |
4987 | do_section_groups = do_archive_index = do_dyn_syms = TRUE; | |
4988 | do_lto_syms = TRUE; | |
4989 | } | |
4990 | else | |
4991 | usage (stderr); | |
4992 | } | |
4993 | } | |
4994 | ||
4995 | static const char * | |
4996 | get_elf_class (unsigned int elf_class) | |
4997 | { | |
4998 | static char buff[32]; | |
4999 | ||
5000 | switch (elf_class) | |
5001 | { | |
5002 | case ELFCLASSNONE: return _("none"); | |
5003 | case ELFCLASS32: return "ELF32"; | |
5004 | case ELFCLASS64: return "ELF64"; | |
5005 | default: | |
5006 | snprintf (buff, sizeof (buff), _("<unknown: %x>"), elf_class); | |
5007 | return buff; | |
5008 | } | |
5009 | } | |
5010 | ||
5011 | static const char * | |
5012 | get_data_encoding (unsigned int encoding) | |
5013 | { | |
5014 | static char buff[32]; | |
5015 | ||
5016 | switch (encoding) | |
5017 | { | |
5018 | case ELFDATANONE: return _("none"); | |
5019 | case ELFDATA2LSB: return _("2's complement, little endian"); | |
5020 | case ELFDATA2MSB: return _("2's complement, big endian"); | |
5021 | default: | |
5022 | snprintf (buff, sizeof (buff), _("<unknown: %x>"), encoding); | |
5023 | return buff; | |
5024 | } | |
5025 | } | |
5026 | ||
5027 | /* Decode the data held in 'filedata->file_header'. */ | |
5028 | ||
5029 | static bfd_boolean | |
5030 | process_file_header (Filedata * filedata) | |
5031 | { | |
5032 | Elf_Internal_Ehdr * header = & filedata->file_header; | |
5033 | ||
5034 | if ( header->e_ident[EI_MAG0] != ELFMAG0 | |
5035 | || header->e_ident[EI_MAG1] != ELFMAG1 | |
5036 | || header->e_ident[EI_MAG2] != ELFMAG2 | |
5037 | || header->e_ident[EI_MAG3] != ELFMAG3) | |
5038 | { | |
5039 | error | |
5040 | (_("Not an ELF file - it has the wrong magic bytes at the start\n")); | |
5041 | return FALSE; | |
5042 | } | |
5043 | ||
5044 | if (! filedata->is_separate) | |
5045 | init_dwarf_regnames_by_elf_machine_code (header->e_machine); | |
5046 | ||
5047 | if (do_header) | |
5048 | { | |
5049 | unsigned i; | |
5050 | ||
5051 | if (filedata->is_separate) | |
5052 | printf (_("ELF Header in linked file '%s':\n"), filedata->file_name); | |
5053 | else | |
5054 | printf (_("ELF Header:\n")); | |
5055 | printf (_(" Magic: ")); | |
5056 | for (i = 0; i < EI_NIDENT; i++) | |
5057 | printf ("%2.2x ", header->e_ident[i]); | |
5058 | printf ("\n"); | |
5059 | printf (_(" Class: %s\n"), | |
5060 | get_elf_class (header->e_ident[EI_CLASS])); | |
5061 | printf (_(" Data: %s\n"), | |
5062 | get_data_encoding (header->e_ident[EI_DATA])); | |
5063 | printf (_(" Version: %d%s\n"), | |
5064 | header->e_ident[EI_VERSION], | |
5065 | (header->e_ident[EI_VERSION] == EV_CURRENT | |
5066 | ? _(" (current)") | |
5067 | : (header->e_ident[EI_VERSION] != EV_NONE | |
5068 | ? _(" <unknown>") | |
5069 | : ""))); | |
5070 | printf (_(" OS/ABI: %s\n"), | |
5071 | get_osabi_name (filedata, header->e_ident[EI_OSABI])); | |
5072 | printf (_(" ABI Version: %d\n"), | |
5073 | header->e_ident[EI_ABIVERSION]); | |
5074 | printf (_(" Type: %s\n"), | |
5075 | get_file_type (header->e_type)); | |
5076 | printf (_(" Machine: %s\n"), | |
5077 | get_machine_name (header->e_machine)); | |
5078 | printf (_(" Version: 0x%lx\n"), | |
5079 | header->e_version); | |
5080 | ||
5081 | printf (_(" Entry point address: ")); | |
5082 | print_vma (header->e_entry, PREFIX_HEX); | |
5083 | printf (_("\n Start of program headers: ")); | |
5084 | print_vma (header->e_phoff, DEC); | |
5085 | printf (_(" (bytes into file)\n Start of section headers: ")); | |
5086 | print_vma (header->e_shoff, DEC); | |
5087 | printf (_(" (bytes into file)\n")); | |
5088 | ||
5089 | printf (_(" Flags: 0x%lx%s\n"), | |
5090 | header->e_flags, | |
5091 | get_machine_flags (filedata, header->e_flags, header->e_machine)); | |
5092 | printf (_(" Size of this header: %u (bytes)\n"), | |
5093 | header->e_ehsize); | |
5094 | printf (_(" Size of program headers: %u (bytes)\n"), | |
5095 | header->e_phentsize); | |
5096 | printf (_(" Number of program headers: %u"), | |
5097 | header->e_phnum); | |
5098 | if (filedata->section_headers != NULL | |
5099 | && header->e_phnum == PN_XNUM | |
5100 | && filedata->section_headers[0].sh_info != 0) | |
5101 | { | |
5102 | header->e_phnum = filedata->section_headers[0].sh_info; | |
5103 | printf (" (%u)", header->e_phnum); | |
5104 | } | |
5105 | putc ('\n', stdout); | |
5106 | printf (_(" Size of section headers: %u (bytes)\n"), | |
5107 | header->e_shentsize); | |
5108 | printf (_(" Number of section headers: %u"), | |
5109 | header->e_shnum); | |
5110 | if (filedata->section_headers != NULL && header->e_shnum == SHN_UNDEF) | |
5111 | { | |
5112 | header->e_shnum = filedata->section_headers[0].sh_size; | |
5113 | printf (" (%u)", header->e_shnum); | |
5114 | } | |
5115 | putc ('\n', stdout); | |
5116 | printf (_(" Section header string table index: %u"), | |
5117 | header->e_shstrndx); | |
5118 | if (filedata->section_headers != NULL | |
5119 | && header->e_shstrndx == (SHN_XINDEX & 0xffff)) | |
5120 | { | |
5121 | header->e_shstrndx = filedata->section_headers[0].sh_link; | |
5122 | printf (" (%u)", header->e_shstrndx); | |
5123 | } | |
5124 | if (header->e_shstrndx != SHN_UNDEF | |
5125 | && header->e_shstrndx >= header->e_shnum) | |
5126 | { | |
5127 | header->e_shstrndx = SHN_UNDEF; | |
5128 | printf (_(" <corrupt: out of range>")); | |
5129 | } | |
5130 | putc ('\n', stdout); | |
5131 | } | |
5132 | ||
5133 | if (filedata->section_headers != NULL) | |
5134 | { | |
5135 | if (header->e_phnum == PN_XNUM | |
5136 | && filedata->section_headers[0].sh_info != 0) | |
5137 | header->e_phnum = filedata->section_headers[0].sh_info; | |
5138 | if (header->e_shnum == SHN_UNDEF) | |
5139 | header->e_shnum = filedata->section_headers[0].sh_size; | |
5140 | if (header->e_shstrndx == (SHN_XINDEX & 0xffff)) | |
5141 | header->e_shstrndx = filedata->section_headers[0].sh_link; | |
5142 | if (header->e_shstrndx >= header->e_shnum) | |
5143 | header->e_shstrndx = SHN_UNDEF; | |
5144 | free (filedata->section_headers); | |
5145 | filedata->section_headers = NULL; | |
5146 | } | |
5147 | ||
5148 | return TRUE; | |
5149 | } | |
5150 | ||
5151 | /* Read in the program headers from FILEDATA and store them in PHEADERS. | |
5152 | Returns TRUE upon success, FALSE otherwise. Loads 32-bit headers. */ | |
5153 | ||
5154 | static bfd_boolean | |
5155 | get_32bit_program_headers (Filedata * filedata, Elf_Internal_Phdr * pheaders) | |
5156 | { | |
5157 | Elf32_External_Phdr * phdrs; | |
5158 | Elf32_External_Phdr * external; | |
5159 | Elf_Internal_Phdr * internal; | |
5160 | unsigned int i; | |
5161 | unsigned int size = filedata->file_header.e_phentsize; | |
5162 | unsigned int num = filedata->file_header.e_phnum; | |
5163 | ||
5164 | /* PR binutils/17531: Cope with unexpected section header sizes. */ | |
5165 | if (size == 0 || num == 0) | |
5166 | return FALSE; | |
5167 | if (size < sizeof * phdrs) | |
5168 | { | |
5169 | error (_("The e_phentsize field in the ELF header is less than the size of an ELF program header\n")); | |
5170 | return FALSE; | |
5171 | } | |
5172 | if (size > sizeof * phdrs) | |
5173 | warn (_("The e_phentsize field in the ELF header is larger than the size of an ELF program header\n")); | |
5174 | ||
5175 | phdrs = (Elf32_External_Phdr *) get_data (NULL, filedata, filedata->file_header.e_phoff, | |
5176 | size, num, _("program headers")); | |
5177 | if (phdrs == NULL) | |
5178 | return FALSE; | |
5179 | ||
5180 | for (i = 0, internal = pheaders, external = phdrs; | |
5181 | i < filedata->file_header.e_phnum; | |
5182 | i++, internal++, external++) | |
5183 | { | |
5184 | internal->p_type = BYTE_GET (external->p_type); | |
5185 | internal->p_offset = BYTE_GET (external->p_offset); | |
5186 | internal->p_vaddr = BYTE_GET (external->p_vaddr); | |
5187 | internal->p_paddr = BYTE_GET (external->p_paddr); | |
5188 | internal->p_filesz = BYTE_GET (external->p_filesz); | |
5189 | internal->p_memsz = BYTE_GET (external->p_memsz); | |
5190 | internal->p_flags = BYTE_GET (external->p_flags); | |
5191 | internal->p_align = BYTE_GET (external->p_align); | |
5192 | } | |
5193 | ||
5194 | free (phdrs); | |
5195 | return TRUE; | |
5196 | } | |
5197 | ||
5198 | /* Read in the program headers from FILEDATA and store them in PHEADERS. | |
5199 | Returns TRUE upon success, FALSE otherwise. Loads 64-bit headers. */ | |
5200 | ||
5201 | static bfd_boolean | |
5202 | get_64bit_program_headers (Filedata * filedata, Elf_Internal_Phdr * pheaders) | |
5203 | { | |
5204 | Elf64_External_Phdr * phdrs; | |
5205 | Elf64_External_Phdr * external; | |
5206 | Elf_Internal_Phdr * internal; | |
5207 | unsigned int i; | |
5208 | unsigned int size = filedata->file_header.e_phentsize; | |
5209 | unsigned int num = filedata->file_header.e_phnum; | |
5210 | ||
5211 | /* PR binutils/17531: Cope with unexpected section header sizes. */ | |
5212 | if (size == 0 || num == 0) | |
5213 | return FALSE; | |
5214 | if (size < sizeof * phdrs) | |
5215 | { | |
5216 | error (_("The e_phentsize field in the ELF header is less than the size of an ELF program header\n")); | |
5217 | return FALSE; | |
5218 | } | |
5219 | if (size > sizeof * phdrs) | |
5220 | warn (_("The e_phentsize field in the ELF header is larger than the size of an ELF program header\n")); | |
5221 | ||
5222 | phdrs = (Elf64_External_Phdr *) get_data (NULL, filedata, filedata->file_header.e_phoff, | |
5223 | size, num, _("program headers")); | |
5224 | if (!phdrs) | |
5225 | return FALSE; | |
5226 | ||
5227 | for (i = 0, internal = pheaders, external = phdrs; | |
5228 | i < filedata->file_header.e_phnum; | |
5229 | i++, internal++, external++) | |
5230 | { | |
5231 | internal->p_type = BYTE_GET (external->p_type); | |
5232 | internal->p_flags = BYTE_GET (external->p_flags); | |
5233 | internal->p_offset = BYTE_GET (external->p_offset); | |
5234 | internal->p_vaddr = BYTE_GET (external->p_vaddr); | |
5235 | internal->p_paddr = BYTE_GET (external->p_paddr); | |
5236 | internal->p_filesz = BYTE_GET (external->p_filesz); | |
5237 | internal->p_memsz = BYTE_GET (external->p_memsz); | |
5238 | internal->p_align = BYTE_GET (external->p_align); | |
5239 | } | |
5240 | ||
5241 | free (phdrs); | |
5242 | return TRUE; | |
5243 | } | |
5244 | ||
5245 | /* Returns TRUE if the program headers were read into `program_headers'. */ | |
5246 | ||
5247 | static bfd_boolean | |
5248 | get_program_headers (Filedata * filedata) | |
5249 | { | |
5250 | Elf_Internal_Phdr * phdrs; | |
5251 | ||
5252 | /* Check cache of prior read. */ | |
5253 | if (filedata->program_headers != NULL) | |
5254 | return TRUE; | |
5255 | ||
5256 | /* Be kind to memory checkers by looking for | |
5257 | e_phnum values which we know must be invalid. */ | |
5258 | if (filedata->file_header.e_phnum | |
5259 | * (is_32bit_elf ? sizeof (Elf32_External_Phdr) : sizeof (Elf64_External_Phdr)) | |
5260 | >= filedata->file_size) | |
5261 | { | |
5262 | error (_("Too many program headers - %#x - the file is not that big\n"), | |
5263 | filedata->file_header.e_phnum); | |
5264 | return FALSE; | |
5265 | } | |
5266 | ||
5267 | phdrs = (Elf_Internal_Phdr *) cmalloc (filedata->file_header.e_phnum, | |
5268 | sizeof (Elf_Internal_Phdr)); | |
5269 | if (phdrs == NULL) | |
5270 | { | |
5271 | error (_("Out of memory reading %u program headers\n"), | |
5272 | filedata->file_header.e_phnum); | |
5273 | return FALSE; | |
5274 | } | |
5275 | ||
5276 | if (is_32bit_elf | |
5277 | ? get_32bit_program_headers (filedata, phdrs) | |
5278 | : get_64bit_program_headers (filedata, phdrs)) | |
5279 | { | |
5280 | filedata->program_headers = phdrs; | |
5281 | return TRUE; | |
5282 | } | |
5283 | ||
5284 | free (phdrs); | |
5285 | return FALSE; | |
5286 | } | |
5287 | ||
5288 | /* Returns TRUE if the program headers were loaded. */ | |
5289 | ||
5290 | static bfd_boolean | |
5291 | process_program_headers (Filedata * filedata) | |
5292 | { | |
5293 | Elf_Internal_Phdr * segment; | |
5294 | unsigned int i; | |
5295 | Elf_Internal_Phdr * previous_load = NULL; | |
5296 | ||
5297 | filedata->dynamic_addr = 0; | |
5298 | filedata->dynamic_size = 0; | |
5299 | ||
5300 | if (filedata->file_header.e_phnum == 0) | |
5301 | { | |
5302 | /* PR binutils/12467. */ | |
5303 | if (filedata->file_header.e_phoff != 0) | |
5304 | { | |
5305 | warn (_("possibly corrupt ELF header - it has a non-zero program" | |
5306 | " header offset, but no program headers\n")); | |
5307 | return FALSE; | |
5308 | } | |
5309 | else if (do_segments) | |
5310 | { | |
5311 | if (filedata->is_separate) | |
5312 | printf (_("\nThere are no program headers in linked file '%s'.\n"), | |
5313 | filedata->file_name); | |
5314 | else | |
5315 | printf (_("\nThere are no program headers in this file.\n")); | |
5316 | } | |
5317 | return TRUE; | |
5318 | } | |
5319 | ||
5320 | if (do_segments && !do_header) | |
5321 | { | |
5322 | if (filedata->is_separate) | |
5323 | printf ("\nIn linked file '%s' the ELF file type is %s\n", | |
5324 | filedata->file_name, | |
5325 | get_file_type (filedata->file_header.e_type)); | |
5326 | else | |
5327 | printf (_("\nElf file type is %s\n"), get_file_type (filedata->file_header.e_type)); | |
5328 | printf (_("Entry point 0x%s\n"), bfd_vmatoa ("x", filedata->file_header.e_entry)); | |
5329 | printf (ngettext ("There is %d program header, starting at offset %s\n", | |
5330 | "There are %d program headers, starting at offset %s\n", | |
5331 | filedata->file_header.e_phnum), | |
5332 | filedata->file_header.e_phnum, | |
5333 | bfd_vmatoa ("u", filedata->file_header.e_phoff)); | |
5334 | } | |
5335 | ||
5336 | if (! get_program_headers (filedata)) | |
5337 | return TRUE; | |
5338 | ||
5339 | if (do_segments) | |
5340 | { | |
5341 | if (filedata->file_header.e_phnum > 1) | |
5342 | printf (_("\nProgram Headers:\n")); | |
5343 | else | |
5344 | printf (_("\nProgram Headers:\n")); | |
5345 | ||
5346 | if (is_32bit_elf) | |
5347 | printf | |
5348 | (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n")); | |
5349 | else if (do_wide) | |
5350 | printf | |
5351 | (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n")); | |
5352 | else | |
5353 | { | |
5354 | printf | |
5355 | (_(" Type Offset VirtAddr PhysAddr\n")); | |
5356 | printf | |
5357 | (_(" FileSiz MemSiz Flags Align\n")); | |
5358 | } | |
5359 | } | |
5360 | ||
5361 | for (i = 0, segment = filedata->program_headers; | |
5362 | i < filedata->file_header.e_phnum; | |
5363 | i++, segment++) | |
5364 | { | |
5365 | if (do_segments) | |
5366 | { | |
5367 | printf (" %-14.14s ", get_segment_type (filedata, segment->p_type)); | |
5368 | ||
5369 | if (is_32bit_elf) | |
5370 | { | |
5371 | printf ("0x%6.6lx ", (unsigned long) segment->p_offset); | |
5372 | printf ("0x%8.8lx ", (unsigned long) segment->p_vaddr); | |
5373 | printf ("0x%8.8lx ", (unsigned long) segment->p_paddr); | |
5374 | printf ("0x%5.5lx ", (unsigned long) segment->p_filesz); | |
5375 | printf ("0x%5.5lx ", (unsigned long) segment->p_memsz); | |
5376 | printf ("%c%c%c ", | |
5377 | (segment->p_flags & PF_R ? 'R' : ' '), | |
5378 | (segment->p_flags & PF_W ? 'W' : ' '), | |
5379 | (segment->p_flags & PF_X ? 'E' : ' ')); | |
5380 | printf ("%#lx", (unsigned long) segment->p_align); | |
5381 | } | |
5382 | else if (do_wide) | |
5383 | { | |
5384 | if ((unsigned long) segment->p_offset == segment->p_offset) | |
5385 | printf ("0x%6.6lx ", (unsigned long) segment->p_offset); | |
5386 | else | |
5387 | { | |
5388 | print_vma (segment->p_offset, FULL_HEX); | |
5389 | putchar (' '); | |
5390 | } | |
5391 | ||
5392 | print_vma (segment->p_vaddr, FULL_HEX); | |
5393 | putchar (' '); | |
5394 | print_vma (segment->p_paddr, FULL_HEX); | |
5395 | putchar (' '); | |
5396 | ||
5397 | if ((unsigned long) segment->p_filesz == segment->p_filesz) | |
5398 | printf ("0x%6.6lx ", (unsigned long) segment->p_filesz); | |
5399 | else | |
5400 | { | |
5401 | print_vma (segment->p_filesz, FULL_HEX); | |
5402 | putchar (' '); | |
5403 | } | |
5404 | ||
5405 | if ((unsigned long) segment->p_memsz == segment->p_memsz) | |
5406 | printf ("0x%6.6lx", (unsigned long) segment->p_memsz); | |
5407 | else | |
5408 | { | |
5409 | print_vma (segment->p_memsz, FULL_HEX); | |
5410 | } | |
5411 | ||
5412 | printf (" %c%c%c ", | |
5413 | (segment->p_flags & PF_R ? 'R' : ' '), | |
5414 | (segment->p_flags & PF_W ? 'W' : ' '), | |
5415 | (segment->p_flags & PF_X ? 'E' : ' ')); | |
5416 | ||
5417 | if ((unsigned long) segment->p_align == segment->p_align) | |
5418 | printf ("%#lx", (unsigned long) segment->p_align); | |
5419 | else | |
5420 | { | |
5421 | print_vma (segment->p_align, PREFIX_HEX); | |
5422 | } | |
5423 | } | |
5424 | else | |
5425 | { | |
5426 | print_vma (segment->p_offset, FULL_HEX); | |
5427 | putchar (' '); | |
5428 | print_vma (segment->p_vaddr, FULL_HEX); | |
5429 | putchar (' '); | |
5430 | print_vma (segment->p_paddr, FULL_HEX); | |
5431 | printf ("\n "); | |
5432 | print_vma (segment->p_filesz, FULL_HEX); | |
5433 | putchar (' '); | |
5434 | print_vma (segment->p_memsz, FULL_HEX); | |
5435 | printf (" %c%c%c ", | |
5436 | (segment->p_flags & PF_R ? 'R' : ' '), | |
5437 | (segment->p_flags & PF_W ? 'W' : ' '), | |
5438 | (segment->p_flags & PF_X ? 'E' : ' ')); | |
5439 | print_vma (segment->p_align, PREFIX_HEX); | |
5440 | } | |
5441 | ||
5442 | putc ('\n', stdout); | |
5443 | } | |
5444 | ||
5445 | switch (segment->p_type) | |
5446 | { | |
5447 | case PT_LOAD: | |
5448 | #if 0 /* Do not warn about out of order PT_LOAD segments. Although officially | |
5449 | required by the ELF standard, several programs, including the Linux | |
5450 | kernel, make use of non-ordered segments. */ | |
5451 | if (previous_load | |
5452 | && previous_load->p_vaddr > segment->p_vaddr) | |
5453 | error (_("LOAD segments must be sorted in order of increasing VirtAddr\n")); | |
5454 | #endif | |
5455 | if (segment->p_memsz < segment->p_filesz) | |
5456 | error (_("the segment's file size is larger than its memory size\n")); | |
5457 | previous_load = segment; | |
5458 | break; | |
5459 | ||
5460 | case PT_PHDR: | |
5461 | /* PR 20815 - Verify that the program header is loaded into memory. */ | |
5462 | if (i > 0 && previous_load != NULL) | |
5463 | error (_("the PHDR segment must occur before any LOAD segment\n")); | |
5464 | if (filedata->file_header.e_machine != EM_PARISC) | |
5465 | { | |
5466 | unsigned int j; | |
5467 | ||
5468 | for (j = 1; j < filedata->file_header.e_phnum; j++) | |
5469 | { | |
5470 | Elf_Internal_Phdr *load = filedata->program_headers + j; | |
5471 | if (load->p_type == PT_LOAD | |
5472 | && load->p_offset <= segment->p_offset | |
5473 | && (load->p_offset + load->p_filesz | |
5474 | >= segment->p_offset + segment->p_filesz) | |
5475 | && load->p_vaddr <= segment->p_vaddr | |
5476 | && (load->p_vaddr + load->p_filesz | |
5477 | >= segment->p_vaddr + segment->p_filesz)) | |
5478 | break; | |
5479 | } | |
5480 | if (j == filedata->file_header.e_phnum) | |
5481 | error (_("the PHDR segment is not covered by a LOAD segment\n")); | |
5482 | } | |
5483 | break; | |
5484 | ||
5485 | case PT_DYNAMIC: | |
5486 | if (filedata->dynamic_addr) | |
5487 | error (_("more than one dynamic segment\n")); | |
5488 | ||
5489 | /* By default, assume that the .dynamic section is the first | |
5490 | section in the DYNAMIC segment. */ | |
5491 | filedata->dynamic_addr = segment->p_offset; | |
5492 | filedata->dynamic_size = segment->p_filesz; | |
5493 | ||
5494 | /* Try to locate the .dynamic section. If there is | |
5495 | a section header table, we can easily locate it. */ | |
5496 | if (filedata->section_headers != NULL) | |
5497 | { | |
5498 | Elf_Internal_Shdr * sec; | |
5499 | ||
5500 | sec = find_section (filedata, ".dynamic"); | |
5501 | if (sec == NULL || sec->sh_size == 0) | |
5502 | { | |
5503 | /* A corresponding .dynamic section is expected, but on | |
5504 | IA-64/OpenVMS it is OK for it to be missing. */ | |
5505 | if (!is_ia64_vms (filedata)) | |
5506 | error (_("no .dynamic section in the dynamic segment\n")); | |
5507 | break; | |
5508 | } | |
5509 | ||
5510 | if (sec->sh_type == SHT_NOBITS) | |
5511 | { | |
5512 | filedata->dynamic_size = 0; | |
5513 | break; | |
5514 | } | |
5515 | ||
5516 | filedata->dynamic_addr = sec->sh_offset; | |
5517 | filedata->dynamic_size = sec->sh_size; | |
5518 | ||
5519 | /* The PT_DYNAMIC segment, which is used by the run-time | |
5520 | loader, should exactly match the .dynamic section. */ | |
5521 | if (do_checks | |
5522 | && (filedata->dynamic_addr != segment->p_offset | |
5523 | || filedata->dynamic_size != segment->p_filesz)) | |
5524 | warn (_("\ | |
5525 | the .dynamic section is not the same as the dynamic segment\n")); | |
5526 | } | |
5527 | ||
5528 | /* PR binutils/17512: Avoid corrupt dynamic section info in the | |
5529 | segment. Check this after matching against the section headers | |
5530 | so we don't warn on debuginfo file (which have NOBITS .dynamic | |
5531 | sections). */ | |
5532 | if (filedata->dynamic_addr > filedata->file_size | |
5533 | || (filedata->dynamic_size | |
5534 | > filedata->file_size - filedata->dynamic_addr)) | |
5535 | { | |
5536 | error (_("the dynamic segment offset + size exceeds the size of the file\n")); | |
5537 | filedata->dynamic_addr = filedata->dynamic_size = 0; | |
5538 | } | |
5539 | break; | |
5540 | ||
5541 | case PT_INTERP: | |
5542 | if (fseek (filedata->handle, | |
5543 | filedata->archive_file_offset + (long) segment->p_offset, | |
5544 | SEEK_SET)) | |
5545 | error (_("Unable to find program interpreter name\n")); | |
5546 | else | |
5547 | { | |
5548 | char fmt [32]; | |
5549 | int ret = snprintf (fmt, sizeof (fmt), "%%%ds", PATH_MAX - 1); | |
5550 | ||
5551 | if (ret >= (int) sizeof (fmt) || ret < 0) | |
5552 | error (_("Internal error: failed to create format string to display program interpreter\n")); | |
5553 | ||
5554 | filedata->program_interpreter[0] = 0; | |
5555 | if (fscanf (filedata->handle, fmt, | |
5556 | filedata->program_interpreter) <= 0) | |
5557 | error (_("Unable to read program interpreter name\n")); | |
5558 | ||
5559 | if (do_segments) | |
5560 | printf (_(" [Requesting program interpreter: %s]\n"), | |
5561 | filedata->program_interpreter); | |
5562 | } | |
5563 | break; | |
5564 | } | |
5565 | } | |
5566 | ||
5567 | if (do_segments | |
5568 | && filedata->section_headers != NULL | |
5569 | && filedata->string_table != NULL) | |
5570 | { | |
5571 | printf (_("\n Section to Segment mapping:\n")); | |
5572 | printf (_(" Segment Sections...\n")); | |
5573 | ||
5574 | for (i = 0; i < filedata->file_header.e_phnum; i++) | |
5575 | { | |
5576 | unsigned int j; | |
5577 | Elf_Internal_Shdr * section; | |
5578 | ||
5579 | segment = filedata->program_headers + i; | |
5580 | section = filedata->section_headers + 1; | |
5581 | ||
5582 | printf (" %2.2d ", i); | |
5583 | ||
5584 | for (j = 1; j < filedata->file_header.e_shnum; j++, section++) | |
5585 | { | |
5586 | if (!ELF_TBSS_SPECIAL (section, segment) | |
5587 | && ELF_SECTION_IN_SEGMENT_STRICT (section, segment)) | |
5588 | printf ("%s ", printable_section_name (filedata, section)); | |
5589 | } | |
5590 | ||
5591 | putc ('\n',stdout); | |
5592 | } | |
5593 | } | |
5594 | ||
5595 | return TRUE; | |
5596 | } | |
5597 | ||
5598 | ||
5599 | /* Find the file offset corresponding to VMA by using the program headers. */ | |
5600 | ||
5601 | static long | |
5602 | offset_from_vma (Filedata * filedata, bfd_vma vma, bfd_size_type size) | |
5603 | { | |
5604 | Elf_Internal_Phdr * seg; | |
5605 | ||
5606 | if (! get_program_headers (filedata)) | |
5607 | { | |
5608 | warn (_("Cannot interpret virtual addresses without program headers.\n")); | |
5609 | return (long) vma; | |
5610 | } | |
5611 | ||
5612 | for (seg = filedata->program_headers; | |
5613 | seg < filedata->program_headers + filedata->file_header.e_phnum; | |
5614 | ++seg) | |
5615 | { | |
5616 | if (seg->p_type != PT_LOAD) | |
5617 | continue; | |
5618 | ||
5619 | if (vma >= (seg->p_vaddr & -seg->p_align) | |
5620 | && vma + size <= seg->p_vaddr + seg->p_filesz) | |
5621 | return vma - seg->p_vaddr + seg->p_offset; | |
5622 | } | |
5623 | ||
5624 | warn (_("Virtual address 0x%lx not located in any PT_LOAD segment.\n"), | |
5625 | (unsigned long) vma); | |
5626 | return (long) vma; | |
5627 | } | |
5628 | ||
5629 | ||
5630 | /* Allocate memory and load the sections headers into FILEDATA->filedata->section_headers. | |
5631 | If PROBE is true, this is just a probe and we do not generate any error | |
5632 | messages if the load fails. */ | |
5633 | ||
5634 | static bfd_boolean | |
5635 | get_32bit_section_headers (Filedata * filedata, bfd_boolean probe) | |
5636 | { | |
5637 | Elf32_External_Shdr * shdrs; | |
5638 | Elf_Internal_Shdr * internal; | |
5639 | unsigned int i; | |
5640 | unsigned int size = filedata->file_header.e_shentsize; | |
5641 | unsigned int num = probe ? 1 : filedata->file_header.e_shnum; | |
5642 | ||
5643 | /* PR binutils/17531: Cope with unexpected section header sizes. */ | |
5644 | if (size == 0 || num == 0) | |
5645 | return FALSE; | |
5646 | if (size < sizeof * shdrs) | |
5647 | { | |
5648 | if (! probe) | |
5649 | error (_("The e_shentsize field in the ELF header is less than the size of an ELF section header\n")); | |
5650 | return FALSE; | |
5651 | } | |
5652 | if (!probe && size > sizeof * shdrs) | |
5653 | warn (_("The e_shentsize field in the ELF header is larger than the size of an ELF section header\n")); | |
5654 | ||
5655 | shdrs = (Elf32_External_Shdr *) get_data (NULL, filedata, filedata->file_header.e_shoff, | |
5656 | size, num, | |
5657 | probe ? NULL : _("section headers")); | |
5658 | if (shdrs == NULL) | |
5659 | return FALSE; | |
5660 | ||
5661 | free (filedata->section_headers); | |
5662 | filedata->section_headers = (Elf_Internal_Shdr *) | |
5663 | cmalloc (num, sizeof (Elf_Internal_Shdr)); | |
5664 | if (filedata->section_headers == NULL) | |
5665 | { | |
5666 | if (!probe) | |
5667 | error (_("Out of memory reading %u section headers\n"), num); | |
5668 | free (shdrs); | |
5669 | return FALSE; | |
5670 | } | |
5671 | ||
5672 | for (i = 0, internal = filedata->section_headers; | |
5673 | i < num; | |
5674 | i++, internal++) | |
5675 | { | |
5676 | internal->sh_name = BYTE_GET (shdrs[i].sh_name); | |
5677 | internal->sh_type = BYTE_GET (shdrs[i].sh_type); | |
5678 | internal->sh_flags = BYTE_GET (shdrs[i].sh_flags); | |
5679 | internal->sh_addr = BYTE_GET (shdrs[i].sh_addr); | |
5680 | internal->sh_offset = BYTE_GET (shdrs[i].sh_offset); | |
5681 | internal->sh_size = BYTE_GET (shdrs[i].sh_size); | |
5682 | internal->sh_link = BYTE_GET (shdrs[i].sh_link); | |
5683 | internal->sh_info = BYTE_GET (shdrs[i].sh_info); | |
5684 | internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign); | |
5685 | internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize); | |
5686 | if (!probe && internal->sh_link > num) | |
5687 | warn (_("Section %u has an out of range sh_link value of %u\n"), i, internal->sh_link); | |
5688 | if (!probe && internal->sh_flags & SHF_INFO_LINK && internal->sh_info > num) | |
5689 | warn (_("Section %u has an out of range sh_info value of %u\n"), i, internal->sh_info); | |
5690 | } | |
5691 | ||
5692 | free (shdrs); | |
5693 | return TRUE; | |
5694 | } | |
5695 | ||
5696 | /* Like get_32bit_section_headers, except that it fetches 64-bit headers. */ | |
5697 | ||
5698 | static bfd_boolean | |
5699 | get_64bit_section_headers (Filedata * filedata, bfd_boolean probe) | |
5700 | { | |
5701 | Elf64_External_Shdr * shdrs; | |
5702 | Elf_Internal_Shdr * internal; | |
5703 | unsigned int i; | |
5704 | unsigned int size = filedata->file_header.e_shentsize; | |
5705 | unsigned int num = probe ? 1 : filedata->file_header.e_shnum; | |
5706 | ||
5707 | /* PR binutils/17531: Cope with unexpected section header sizes. */ | |
5708 | if (size == 0 || num == 0) | |
5709 | return FALSE; | |
5710 | ||
5711 | if (size < sizeof * shdrs) | |
5712 | { | |
5713 | if (! probe) | |
5714 | error (_("The e_shentsize field in the ELF header is less than the size of an ELF section header\n")); | |
5715 | return FALSE; | |
5716 | } | |
5717 | ||
5718 | if (! probe && size > sizeof * shdrs) | |
5719 | warn (_("The e_shentsize field in the ELF header is larger than the size of an ELF section header\n")); | |
5720 | ||
5721 | shdrs = (Elf64_External_Shdr *) get_data (NULL, filedata, | |
5722 | filedata->file_header.e_shoff, | |
5723 | size, num, | |
5724 | probe ? NULL : _("section headers")); | |
5725 | if (shdrs == NULL) | |
5726 | return FALSE; | |
5727 | ||
5728 | free (filedata->section_headers); | |
5729 | filedata->section_headers = (Elf_Internal_Shdr *) | |
5730 | cmalloc (num, sizeof (Elf_Internal_Shdr)); | |
5731 | if (filedata->section_headers == NULL) | |
5732 | { | |
5733 | if (! probe) | |
5734 | error (_("Out of memory reading %u section headers\n"), num); | |
5735 | free (shdrs); | |
5736 | return FALSE; | |
5737 | } | |
5738 | ||
5739 | for (i = 0, internal = filedata->section_headers; | |
5740 | i < num; | |
5741 | i++, internal++) | |
5742 | { | |
5743 | internal->sh_name = BYTE_GET (shdrs[i].sh_name); | |
5744 | internal->sh_type = BYTE_GET (shdrs[i].sh_type); | |
5745 | internal->sh_flags = BYTE_GET (shdrs[i].sh_flags); | |
5746 | internal->sh_addr = BYTE_GET (shdrs[i].sh_addr); | |
5747 | internal->sh_size = BYTE_GET (shdrs[i].sh_size); | |
5748 | internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize); | |
5749 | internal->sh_link = BYTE_GET (shdrs[i].sh_link); | |
5750 | internal->sh_info = BYTE_GET (shdrs[i].sh_info); | |
5751 | internal->sh_offset = BYTE_GET (shdrs[i].sh_offset); | |
5752 | internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign); | |
5753 | if (!probe && internal->sh_link > num) | |
5754 | warn (_("Section %u has an out of range sh_link value of %u\n"), i, internal->sh_link); | |
5755 | if (!probe && internal->sh_flags & SHF_INFO_LINK && internal->sh_info > num) | |
5756 | warn (_("Section %u has an out of range sh_info value of %u\n"), i, internal->sh_info); | |
5757 | } | |
5758 | ||
5759 | free (shdrs); | |
5760 | return TRUE; | |
5761 | } | |
5762 | ||
5763 | static Elf_Internal_Sym * | |
5764 | get_32bit_elf_symbols (Filedata * filedata, | |
5765 | Elf_Internal_Shdr * section, | |
5766 | unsigned long * num_syms_return) | |
5767 | { | |
5768 | unsigned long number = 0; | |
5769 | Elf32_External_Sym * esyms = NULL; | |
5770 | Elf_External_Sym_Shndx * shndx = NULL; | |
5771 | Elf_Internal_Sym * isyms = NULL; | |
5772 | Elf_Internal_Sym * psym; | |
5773 | unsigned int j; | |
5774 | elf_section_list * entry; | |
5775 | ||
5776 | if (section->sh_size == 0) | |
5777 | { | |
5778 | if (num_syms_return != NULL) | |
5779 | * num_syms_return = 0; | |
5780 | return NULL; | |
5781 | } | |
5782 | ||
5783 | /* Run some sanity checks first. */ | |
5784 | if (section->sh_entsize == 0 || section->sh_entsize > section->sh_size) | |
5785 | { | |
5786 | error (_("Section %s has an invalid sh_entsize of 0x%lx\n"), | |
5787 | printable_section_name (filedata, section), | |
5788 | (unsigned long) section->sh_entsize); | |
5789 | goto exit_point; | |
5790 | } | |
5791 | ||
5792 | if (section->sh_size > filedata->file_size) | |
5793 | { | |
5794 | error (_("Section %s has an invalid sh_size of 0x%lx\n"), | |
5795 | printable_section_name (filedata, section), | |
5796 | (unsigned long) section->sh_size); | |
5797 | goto exit_point; | |
5798 | } | |
5799 | ||
5800 | number = section->sh_size / section->sh_entsize; | |
5801 | ||
5802 | if (number * sizeof (Elf32_External_Sym) > section->sh_size + 1) | |
5803 | { | |
5804 | error (_("Size (0x%lx) of section %s is not a multiple of its sh_entsize (0x%lx)\n"), | |
5805 | (unsigned long) section->sh_size, | |
5806 | printable_section_name (filedata, section), | |
5807 | (unsigned long) section->sh_entsize); | |
5808 | goto exit_point; | |
5809 | } | |
5810 | ||
5811 | esyms = (Elf32_External_Sym *) get_data (NULL, filedata, section->sh_offset, 1, | |
5812 | section->sh_size, _("symbols")); | |
5813 | if (esyms == NULL) | |
5814 | goto exit_point; | |
5815 | ||
5816 | shndx = NULL; | |
5817 | for (entry = filedata->symtab_shndx_list; entry != NULL; entry = entry->next) | |
5818 | { | |
5819 | if (entry->hdr->sh_link != (unsigned long) (section - filedata->section_headers)) | |
5820 | continue; | |
5821 | ||
5822 | if (shndx != NULL) | |
5823 | { | |
5824 | error (_("Multiple symbol table index sections associated with the same symbol section\n")); | |
5825 | free (shndx); | |
5826 | } | |
5827 | ||
5828 | shndx = (Elf_External_Sym_Shndx *) get_data (NULL, filedata, | |
5829 | entry->hdr->sh_offset, | |
5830 | 1, entry->hdr->sh_size, | |
5831 | _("symbol table section indices")); | |
5832 | if (shndx == NULL) | |
5833 | goto exit_point; | |
5834 | ||
5835 | /* PR17531: file: heap-buffer-overflow */ | |
5836 | if (entry->hdr->sh_size / sizeof (Elf_External_Sym_Shndx) < number) | |
5837 | { | |
5838 | error (_("Index section %s has an sh_size of 0x%lx - expected 0x%lx\n"), | |
5839 | printable_section_name (filedata, entry->hdr), | |
5840 | (unsigned long) entry->hdr->sh_size, | |
5841 | (unsigned long) section->sh_size); | |
5842 | goto exit_point; | |
5843 | } | |
5844 | } | |
5845 | ||
5846 | isyms = (Elf_Internal_Sym *) cmalloc (number, sizeof (Elf_Internal_Sym)); | |
5847 | ||
5848 | if (isyms == NULL) | |
5849 | { | |
5850 | error (_("Out of memory reading %lu symbols\n"), | |
5851 | (unsigned long) number); | |
5852 | goto exit_point; | |
5853 | } | |
5854 | ||
5855 | for (j = 0, psym = isyms; j < number; j++, psym++) | |
5856 | { | |
5857 | psym->st_name = BYTE_GET (esyms[j].st_name); | |
5858 | psym->st_value = BYTE_GET (esyms[j].st_value); | |
5859 | psym->st_size = BYTE_GET (esyms[j].st_size); | |
5860 | psym->st_shndx = BYTE_GET (esyms[j].st_shndx); | |
5861 | if (psym->st_shndx == (SHN_XINDEX & 0xffff) && shndx != NULL) | |
5862 | psym->st_shndx | |
5863 | = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j])); | |
5864 | else if (psym->st_shndx >= (SHN_LORESERVE & 0xffff)) | |
5865 | psym->st_shndx += SHN_LORESERVE - (SHN_LORESERVE & 0xffff); | |
5866 | psym->st_info = BYTE_GET (esyms[j].st_info); | |
5867 | psym->st_other = BYTE_GET (esyms[j].st_other); | |
5868 | } | |
5869 | ||
5870 | exit_point: | |
5871 | free (shndx); | |
5872 | free (esyms); | |
5873 | ||
5874 | if (num_syms_return != NULL) | |
5875 | * num_syms_return = isyms == NULL ? 0 : number; | |
5876 | ||
5877 | return isyms; | |
5878 | } | |
5879 | ||
5880 | static Elf_Internal_Sym * | |
5881 | get_64bit_elf_symbols (Filedata * filedata, | |
5882 | Elf_Internal_Shdr * section, | |
5883 | unsigned long * num_syms_return) | |
5884 | { | |
5885 | unsigned long number = 0; | |
5886 | Elf64_External_Sym * esyms = NULL; | |
5887 | Elf_External_Sym_Shndx * shndx = NULL; | |
5888 | Elf_Internal_Sym * isyms = NULL; | |
5889 | Elf_Internal_Sym * psym; | |
5890 | unsigned int j; | |
5891 | elf_section_list * entry; | |
5892 | ||
5893 | if (section->sh_size == 0) | |
5894 | { | |
5895 | if (num_syms_return != NULL) | |
5896 | * num_syms_return = 0; | |
5897 | return NULL; | |
5898 | } | |
5899 | ||
5900 | /* Run some sanity checks first. */ | |
5901 | if (section->sh_entsize == 0 || section->sh_entsize > section->sh_size) | |
5902 | { | |
5903 | error (_("Section %s has an invalid sh_entsize of 0x%lx\n"), | |
5904 | printable_section_name (filedata, section), | |
5905 | (unsigned long) section->sh_entsize); | |
5906 | goto exit_point; | |
5907 | } | |
5908 | ||
5909 | if (section->sh_size > filedata->file_size) | |
5910 | { | |
5911 | error (_("Section %s has an invalid sh_size of 0x%lx\n"), | |
5912 | printable_section_name (filedata, section), | |
5913 | (unsigned long) section->sh_size); | |
5914 | goto exit_point; | |
5915 | } | |
5916 | ||
5917 | number = section->sh_size / section->sh_entsize; | |
5918 | ||
5919 | if (number * sizeof (Elf64_External_Sym) > section->sh_size + 1) | |
5920 | { | |
5921 | error (_("Size (0x%lx) of section %s is not a multiple of its sh_entsize (0x%lx)\n"), | |
5922 | (unsigned long) section->sh_size, | |
5923 | printable_section_name (filedata, section), | |
5924 | (unsigned long) section->sh_entsize); | |
5925 | goto exit_point; | |
5926 | } | |
5927 | ||
5928 | esyms = (Elf64_External_Sym *) get_data (NULL, filedata, section->sh_offset, 1, | |
5929 | section->sh_size, _("symbols")); | |
5930 | if (!esyms) | |
5931 | goto exit_point; | |
5932 | ||
5933 | shndx = NULL; | |
5934 | for (entry = filedata->symtab_shndx_list; entry != NULL; entry = entry->next) | |
5935 | { | |
5936 | if (entry->hdr->sh_link != (unsigned long) (section - filedata->section_headers)) | |
5937 | continue; | |
5938 | ||
5939 | if (shndx != NULL) | |
5940 | { | |
5941 | error (_("Multiple symbol table index sections associated with the same symbol section\n")); | |
5942 | free (shndx); | |
5943 | } | |
5944 | ||
5945 | shndx = (Elf_External_Sym_Shndx *) get_data (NULL, filedata, | |
5946 | entry->hdr->sh_offset, | |
5947 | 1, entry->hdr->sh_size, | |
5948 | _("symbol table section indices")); | |
5949 | if (shndx == NULL) | |
5950 | goto exit_point; | |
5951 | ||
5952 | /* PR17531: file: heap-buffer-overflow */ | |
5953 | if (entry->hdr->sh_size / sizeof (Elf_External_Sym_Shndx) < number) | |
5954 | { | |
5955 | error (_("Index section %s has an sh_size of 0x%lx - expected 0x%lx\n"), | |
5956 | printable_section_name (filedata, entry->hdr), | |
5957 | (unsigned long) entry->hdr->sh_size, | |
5958 | (unsigned long) section->sh_size); | |
5959 | goto exit_point; | |
5960 | } | |
5961 | } | |
5962 | ||
5963 | isyms = (Elf_Internal_Sym *) cmalloc (number, sizeof (Elf_Internal_Sym)); | |
5964 | ||
5965 | if (isyms == NULL) | |
5966 | { | |
5967 | error (_("Out of memory reading %lu symbols\n"), | |
5968 | (unsigned long) number); | |
5969 | goto exit_point; | |
5970 | } | |
5971 | ||
5972 | for (j = 0, psym = isyms; j < number; j++, psym++) | |
5973 | { | |
5974 | psym->st_name = BYTE_GET (esyms[j].st_name); | |
5975 | psym->st_info = BYTE_GET (esyms[j].st_info); | |
5976 | psym->st_other = BYTE_GET (esyms[j].st_other); | |
5977 | psym->st_shndx = BYTE_GET (esyms[j].st_shndx); | |
5978 | ||
5979 | if (psym->st_shndx == (SHN_XINDEX & 0xffff) && shndx != NULL) | |
5980 | psym->st_shndx | |
5981 | = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j])); | |
5982 | else if (psym->st_shndx >= (SHN_LORESERVE & 0xffff)) | |
5983 | psym->st_shndx += SHN_LORESERVE - (SHN_LORESERVE & 0xffff); | |
5984 | ||
5985 | psym->st_value = BYTE_GET (esyms[j].st_value); | |
5986 | psym->st_size = BYTE_GET (esyms[j].st_size); | |
5987 | } | |
5988 | ||
5989 | exit_point: | |
5990 | free (shndx); | |
5991 | free (esyms); | |
5992 | ||
5993 | if (num_syms_return != NULL) | |
5994 | * num_syms_return = isyms == NULL ? 0 : number; | |
5995 | ||
5996 | return isyms; | |
5997 | } | |
5998 | ||
5999 | static const char * | |
6000 | get_elf_section_flags (Filedata * filedata, bfd_vma sh_flags) | |
6001 | { | |
6002 | static char buff[1024]; | |
6003 | char * p = buff; | |
6004 | unsigned int field_size = is_32bit_elf ? 8 : 16; | |
6005 | signed int sindex; | |
6006 | unsigned int size = sizeof (buff) - (field_size + 4 + 1); | |
6007 | bfd_vma os_flags = 0; | |
6008 | bfd_vma proc_flags = 0; | |
6009 | bfd_vma unknown_flags = 0; | |
6010 | static const struct | |
6011 | { | |
6012 | const char * str; | |
6013 | unsigned int len; | |
6014 | } | |
6015 | flags [] = | |
6016 | { | |
6017 | /* 0 */ { STRING_COMMA_LEN ("WRITE") }, | |
6018 | /* 1 */ { STRING_COMMA_LEN ("ALLOC") }, | |
6019 | /* 2 */ { STRING_COMMA_LEN ("EXEC") }, | |
6020 | /* 3 */ { STRING_COMMA_LEN ("MERGE") }, | |
6021 | /* 4 */ { STRING_COMMA_LEN ("STRINGS") }, | |
6022 | /* 5 */ { STRING_COMMA_LEN ("INFO LINK") }, | |
6023 | /* 6 */ { STRING_COMMA_LEN ("LINK ORDER") }, | |
6024 | /* 7 */ { STRING_COMMA_LEN ("OS NONCONF") }, | |
6025 | /* 8 */ { STRING_COMMA_LEN ("GROUP") }, | |
6026 | /* 9 */ { STRING_COMMA_LEN ("TLS") }, | |
6027 | /* IA-64 specific. */ | |
6028 | /* 10 */ { STRING_COMMA_LEN ("SHORT") }, | |
6029 | /* 11 */ { STRING_COMMA_LEN ("NORECOV") }, | |
6030 | /* IA-64 OpenVMS specific. */ | |
6031 | /* 12 */ { STRING_COMMA_LEN ("VMS_GLOBAL") }, | |
6032 | /* 13 */ { STRING_COMMA_LEN ("VMS_OVERLAID") }, | |
6033 | /* 14 */ { STRING_COMMA_LEN ("VMS_SHARED") }, | |
6034 | /* 15 */ { STRING_COMMA_LEN ("VMS_VECTOR") }, | |
6035 | /* 16 */ { STRING_COMMA_LEN ("VMS_ALLOC_64BIT") }, | |
6036 | /* 17 */ { STRING_COMMA_LEN ("VMS_PROTECTED") }, | |
6037 | /* Generic. */ | |
6038 | /* 18 */ { STRING_COMMA_LEN ("EXCLUDE") }, | |
6039 | /* SPARC specific. */ | |
6040 | /* 19 */ { STRING_COMMA_LEN ("ORDERED") }, | |
6041 | /* 20 */ { STRING_COMMA_LEN ("COMPRESSED") }, | |
6042 | /* ARM specific. */ | |
6043 | /* 21 */ { STRING_COMMA_LEN ("ENTRYSECT") }, | |
6044 | /* 22 */ { STRING_COMMA_LEN ("ARM_PURECODE") }, | |
6045 | /* 23 */ { STRING_COMMA_LEN ("COMDEF") }, | |
6046 | /* GNU specific. */ | |
6047 | /* 24 */ { STRING_COMMA_LEN ("GNU_MBIND") }, | |
6048 | /* VLE specific. */ | |
6049 | /* 25 */ { STRING_COMMA_LEN ("VLE") }, | |
6050 | /* GNU specific. */ | |
6051 | /* 26 */ { STRING_COMMA_LEN ("GNU_RETAIN") }, | |
6052 | }; | |
6053 | ||
6054 | if (do_section_details) | |
6055 | { | |
6056 | sprintf (buff, "[%*.*lx]: ", | |
6057 | field_size, field_size, (unsigned long) sh_flags); | |
6058 | p += field_size + 4; | |
6059 | } | |
6060 | ||
6061 | while (sh_flags) | |
6062 | { | |
6063 | bfd_vma flag; | |
6064 | ||
6065 | flag = sh_flags & - sh_flags; | |
6066 | sh_flags &= ~ flag; | |
6067 | ||
6068 | if (do_section_details) | |
6069 | { | |
6070 | switch (flag) | |
6071 | { | |
6072 | case SHF_WRITE: sindex = 0; break; | |
6073 | case SHF_ALLOC: sindex = 1; break; | |
6074 | case SHF_EXECINSTR: sindex = 2; break; | |
6075 | case SHF_MERGE: sindex = 3; break; | |
6076 | case SHF_STRINGS: sindex = 4; break; | |
6077 | case SHF_INFO_LINK: sindex = 5; break; | |
6078 | case SHF_LINK_ORDER: sindex = 6; break; | |
6079 | case SHF_OS_NONCONFORMING: sindex = 7; break; | |
6080 | case SHF_GROUP: sindex = 8; break; | |
6081 | case SHF_TLS: sindex = 9; break; | |
6082 | case SHF_EXCLUDE: sindex = 18; break; | |
6083 | case SHF_COMPRESSED: sindex = 20; break; | |
6084 | ||
6085 | default: | |
6086 | sindex = -1; | |
6087 | switch (filedata->file_header.e_machine) | |
6088 | { | |
6089 | case EM_IA_64: | |
6090 | if (flag == SHF_IA_64_SHORT) | |
6091 | sindex = 10; | |
6092 | else if (flag == SHF_IA_64_NORECOV) | |
6093 | sindex = 11; | |
6094 | #ifdef BFD64 | |
6095 | else if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_OPENVMS) | |
6096 | switch (flag) | |
6097 | { | |
6098 | case SHF_IA_64_VMS_GLOBAL: sindex = 12; break; | |
6099 | case SHF_IA_64_VMS_OVERLAID: sindex = 13; break; | |
6100 | case SHF_IA_64_VMS_SHARED: sindex = 14; break; | |
6101 | case SHF_IA_64_VMS_VECTOR: sindex = 15; break; | |
6102 | case SHF_IA_64_VMS_ALLOC_64BIT: sindex = 16; break; | |
6103 | case SHF_IA_64_VMS_PROTECTED: sindex = 17; break; | |
6104 | default: break; | |
6105 | } | |
6106 | #endif | |
6107 | break; | |
6108 | ||
6109 | case EM_386: | |
6110 | case EM_IAMCU: | |
6111 | case EM_X86_64: | |
6112 | case EM_L1OM: | |
6113 | case EM_K1OM: | |
6114 | case EM_OLD_SPARCV9: | |
6115 | case EM_SPARC32PLUS: | |
6116 | case EM_SPARCV9: | |
6117 | case EM_SPARC: | |
6118 | if (flag == SHF_ORDERED) | |
6119 | sindex = 19; | |
6120 | break; | |
6121 | ||
6122 | case EM_ARM: | |
6123 | switch (flag) | |
6124 | { | |
6125 | case SHF_ENTRYSECT: sindex = 21; break; | |
6126 | case SHF_ARM_PURECODE: sindex = 22; break; | |
6127 | case SHF_COMDEF: sindex = 23; break; | |
6128 | default: break; | |
6129 | } | |
6130 | break; | |
6131 | case EM_PPC: | |
6132 | if (flag == SHF_PPC_VLE) | |
6133 | sindex = 25; | |
6134 | break; | |
6135 | default: | |
6136 | break; | |
6137 | } | |
6138 | ||
6139 | switch (filedata->file_header.e_ident[EI_OSABI]) | |
6140 | { | |
6141 | case ELFOSABI_GNU: | |
6142 | case ELFOSABI_FREEBSD: | |
6143 | if (flag == SHF_GNU_RETAIN) | |
6144 | sindex = 26; | |
6145 | /* Fall through */ | |
6146 | case ELFOSABI_NONE: | |
6147 | if (flag == SHF_GNU_MBIND) | |
6148 | /* We should not recognize SHF_GNU_MBIND for | |
6149 | ELFOSABI_NONE, but binutils as of 2019-07-23 did | |
6150 | not set the EI_OSABI header byte. */ | |
6151 | sindex = 24; | |
6152 | break; | |
6153 | default: | |
6154 | break; | |
6155 | } | |
6156 | break; | |
6157 | } | |
6158 | ||
6159 | if (sindex != -1) | |
6160 | { | |
6161 | if (p != buff + field_size + 4) | |
6162 | { | |
6163 | if (size < (10 + 2)) | |
6164 | { | |
6165 | warn (_("Internal error: not enough buffer room for section flag info")); | |
6166 | return _("<unknown>"); | |
6167 | } | |
6168 | size -= 2; | |
6169 | *p++ = ','; | |
6170 | *p++ = ' '; | |
6171 | } | |
6172 | ||
6173 | size -= flags [sindex].len; | |
6174 | p = stpcpy (p, flags [sindex].str); | |
6175 | } | |
6176 | else if (flag & SHF_MASKOS) | |
6177 | os_flags |= flag; | |
6178 | else if (flag & SHF_MASKPROC) | |
6179 | proc_flags |= flag; | |
6180 | else | |
6181 | unknown_flags |= flag; | |
6182 | } | |
6183 | else | |
6184 | { | |
6185 | switch (flag) | |
6186 | { | |
6187 | case SHF_WRITE: *p = 'W'; break; | |
6188 | case SHF_ALLOC: *p = 'A'; break; | |
6189 | case SHF_EXECINSTR: *p = 'X'; break; | |
6190 | case SHF_MERGE: *p = 'M'; break; | |
6191 | case SHF_STRINGS: *p = 'S'; break; | |
6192 | case SHF_INFO_LINK: *p = 'I'; break; | |
6193 | case SHF_LINK_ORDER: *p = 'L'; break; | |
6194 | case SHF_OS_NONCONFORMING: *p = 'O'; break; | |
6195 | case SHF_GROUP: *p = 'G'; break; | |
6196 | case SHF_TLS: *p = 'T'; break; | |
6197 | case SHF_EXCLUDE: *p = 'E'; break; | |
6198 | case SHF_COMPRESSED: *p = 'C'; break; | |
6199 | ||
6200 | default: | |
6201 | if ((filedata->file_header.e_machine == EM_X86_64 | |
6202 | || filedata->file_header.e_machine == EM_L1OM | |
6203 | || filedata->file_header.e_machine == EM_K1OM) | |
6204 | && flag == SHF_X86_64_LARGE) | |
6205 | *p = 'l'; | |
6206 | else if (filedata->file_header.e_machine == EM_ARM | |
6207 | && flag == SHF_ARM_PURECODE) | |
6208 | *p = 'y'; | |
6209 | else if (filedata->file_header.e_machine == EM_PPC | |
6210 | && flag == SHF_PPC_VLE) | |
6211 | *p = 'v'; | |
6212 | else if (flag & SHF_MASKOS) | |
6213 | { | |
6214 | switch (filedata->file_header.e_ident[EI_OSABI]) | |
6215 | { | |
6216 | case ELFOSABI_GNU: | |
6217 | case ELFOSABI_FREEBSD: | |
6218 | if (flag == SHF_GNU_RETAIN) | |
6219 | { | |
6220 | *p = 'R'; | |
6221 | break; | |
6222 | } | |
6223 | /* Fall through */ | |
6224 | case ELFOSABI_NONE: | |
6225 | if (flag == SHF_GNU_MBIND) | |
6226 | { | |
6227 | /* We should not recognize SHF_GNU_MBIND for | |
6228 | ELFOSABI_NONE, but binutils as of 2019-07-23 did | |
6229 | not set the EI_OSABI header byte. */ | |
6230 | *p = 'D'; | |
6231 | break; | |
6232 | } | |
6233 | /* Fall through */ | |
6234 | default: | |
6235 | *p = 'o'; | |
6236 | sh_flags &= ~SHF_MASKOS; | |
6237 | break; | |
6238 | } | |
6239 | } | |
6240 | else if (flag & SHF_MASKPROC) | |
6241 | { | |
6242 | *p = 'p'; | |
6243 | sh_flags &= ~ SHF_MASKPROC; | |
6244 | } | |
6245 | else | |
6246 | *p = 'x'; | |
6247 | break; | |
6248 | } | |
6249 | p++; | |
6250 | } | |
6251 | } | |
6252 | ||
6253 | if (do_section_details) | |
6254 | { | |
6255 | if (os_flags) | |
6256 | { | |
6257 | size -= 5 + field_size; | |
6258 | if (p != buff + field_size + 4) | |
6259 | { | |
6260 | if (size < (2 + 1)) | |
6261 | { | |
6262 | warn (_("Internal error: not enough buffer room for section flag info")); | |
6263 | return _("<unknown>"); | |
6264 | } | |
6265 | size -= 2; | |
6266 | *p++ = ','; | |
6267 | *p++ = ' '; | |
6268 | } | |
6269 | sprintf (p, "OS (%*.*lx)", field_size, field_size, | |
6270 | (unsigned long) os_flags); | |
6271 | p += 5 + field_size; | |
6272 | } | |
6273 | if (proc_flags) | |
6274 | { | |
6275 | size -= 7 + field_size; | |
6276 | if (p != buff + field_size + 4) | |
6277 | { | |
6278 | if (size < (2 + 1)) | |
6279 | { | |
6280 | warn (_("Internal error: not enough buffer room for section flag info")); | |
6281 | return _("<unknown>"); | |
6282 | } | |
6283 | size -= 2; | |
6284 | *p++ = ','; | |
6285 | *p++ = ' '; | |
6286 | } | |
6287 | sprintf (p, "PROC (%*.*lx)", field_size, field_size, | |
6288 | (unsigned long) proc_flags); | |
6289 | p += 7 + field_size; | |
6290 | } | |
6291 | if (unknown_flags) | |
6292 | { | |
6293 | size -= 10 + field_size; | |
6294 | if (p != buff + field_size + 4) | |
6295 | { | |
6296 | if (size < (2 + 1)) | |
6297 | { | |
6298 | warn (_("Internal error: not enough buffer room for section flag info")); | |
6299 | return _("<unknown>"); | |
6300 | } | |
6301 | size -= 2; | |
6302 | *p++ = ','; | |
6303 | *p++ = ' '; | |
6304 | } | |
6305 | sprintf (p, _("UNKNOWN (%*.*lx)"), field_size, field_size, | |
6306 | (unsigned long) unknown_flags); | |
6307 | p += 10 + field_size; | |
6308 | } | |
6309 | } | |
6310 | ||
6311 | *p = '\0'; | |
6312 | return buff; | |
6313 | } | |
6314 | ||
6315 | static unsigned int ATTRIBUTE_WARN_UNUSED_RESULT | |
6316 | get_compression_header (Elf_Internal_Chdr *chdr, unsigned char *buf, bfd_size_type size) | |
6317 | { | |
6318 | if (is_32bit_elf) | |
6319 | { | |
6320 | Elf32_External_Chdr *echdr = (Elf32_External_Chdr *) buf; | |
6321 | ||
6322 | if (size < sizeof (* echdr)) | |
6323 | { | |
6324 | error (_("Compressed section is too small even for a compression header\n")); | |
6325 | return 0; | |
6326 | } | |
6327 | ||
6328 | chdr->ch_type = BYTE_GET (echdr->ch_type); | |
6329 | chdr->ch_size = BYTE_GET (echdr->ch_size); | |
6330 | chdr->ch_addralign = BYTE_GET (echdr->ch_addralign); | |
6331 | return sizeof (*echdr); | |
6332 | } | |
6333 | else | |
6334 | { | |
6335 | Elf64_External_Chdr *echdr = (Elf64_External_Chdr *) buf; | |
6336 | ||
6337 | if (size < sizeof (* echdr)) | |
6338 | { | |
6339 | error (_("Compressed section is too small even for a compression header\n")); | |
6340 | return 0; | |
6341 | } | |
6342 | ||
6343 | chdr->ch_type = BYTE_GET (echdr->ch_type); | |
6344 | chdr->ch_size = BYTE_GET (echdr->ch_size); | |
6345 | chdr->ch_addralign = BYTE_GET (echdr->ch_addralign); | |
6346 | return sizeof (*echdr); | |
6347 | } | |
6348 | } | |
6349 | ||
6350 | static bfd_boolean | |
6351 | process_section_headers (Filedata * filedata) | |
6352 | { | |
6353 | Elf_Internal_Shdr * section; | |
6354 | unsigned int i; | |
6355 | ||
6356 | free (filedata->section_headers); | |
6357 | filedata->section_headers = NULL; | |
6358 | free (filedata->dynamic_symbols); | |
6359 | filedata->dynamic_symbols = NULL; | |
6360 | filedata->num_dynamic_syms = 0; | |
6361 | free (filedata->dynamic_strings); | |
6362 | filedata->dynamic_strings = NULL; | |
6363 | filedata->dynamic_strings_length = 0; | |
6364 | free (filedata->dynamic_syminfo); | |
6365 | filedata->dynamic_syminfo = NULL; | |
6366 | while (filedata->symtab_shndx_list != NULL) | |
6367 | { | |
6368 | elf_section_list *next = filedata->symtab_shndx_list->next; | |
6369 | free (filedata->symtab_shndx_list); | |
6370 | filedata->symtab_shndx_list = next; | |
6371 | } | |
6372 | ||
6373 | if (filedata->file_header.e_shnum == 0) | |
6374 | { | |
6375 | /* PR binutils/12467. */ | |
6376 | if (filedata->file_header.e_shoff != 0) | |
6377 | { | |
6378 | warn (_("possibly corrupt ELF file header - it has a non-zero" | |
6379 | " section header offset, but no section headers\n")); | |
6380 | return FALSE; | |
6381 | } | |
6382 | else if (do_sections) | |
6383 | printf (_("\nThere are no sections in this file.\n")); | |
6384 | ||
6385 | return TRUE; | |
6386 | } | |
6387 | ||
6388 | if (do_sections && !do_header) | |
6389 | { | |
6390 | if (filedata->is_separate && process_links) | |
6391 | printf (_("In linked file '%s': "), filedata->file_name); | |
6392 | if (! filedata->is_separate || process_links) | |
6393 | printf (ngettext ("There is %d section header, " | |
6394 | "starting at offset 0x%lx:\n", | |
6395 | "There are %d section headers, " | |
6396 | "starting at offset 0x%lx:\n", | |
6397 | filedata->file_header.e_shnum), | |
6398 | filedata->file_header.e_shnum, | |
6399 | (unsigned long) filedata->file_header.e_shoff); | |
6400 | } | |
6401 | ||
6402 | if (is_32bit_elf) | |
6403 | { | |
6404 | if (! get_32bit_section_headers (filedata, FALSE)) | |
6405 | return FALSE; | |
6406 | } | |
6407 | else | |
6408 | { | |
6409 | if (! get_64bit_section_headers (filedata, FALSE)) | |
6410 | return FALSE; | |
6411 | } | |
6412 | ||
6413 | /* Read in the string table, so that we have names to display. */ | |
6414 | if (filedata->file_header.e_shstrndx != SHN_UNDEF | |
6415 | && filedata->file_header.e_shstrndx < filedata->file_header.e_shnum) | |
6416 | { | |
6417 | section = filedata->section_headers + filedata->file_header.e_shstrndx; | |
6418 | ||
6419 | if (section->sh_size != 0) | |
6420 | { | |
6421 | filedata->string_table = (char *) get_data (NULL, filedata, section->sh_offset, | |
6422 | 1, section->sh_size, | |
6423 | _("string table")); | |
6424 | ||
6425 | filedata->string_table_length = filedata->string_table != NULL ? section->sh_size : 0; | |
6426 | } | |
6427 | } | |
6428 | ||
6429 | /* Scan the sections for the dynamic symbol table | |
6430 | and dynamic string table and debug sections. */ | |
6431 | eh_addr_size = is_32bit_elf ? 4 : 8; | |
6432 | switch (filedata->file_header.e_machine) | |
6433 | { | |
6434 | case EM_MIPS: | |
6435 | case EM_MIPS_RS3_LE: | |
6436 | /* The 64-bit MIPS EABI uses a combination of 32-bit ELF and 64-bit | |
6437 | FDE addresses. However, the ABI also has a semi-official ILP32 | |
6438 | variant for which the normal FDE address size rules apply. | |
6439 | ||
6440 | GCC 4.0 marks EABI64 objects with a dummy .gcc_compiled_longXX | |
6441 | section, where XX is the size of longs in bits. Unfortunately, | |
6442 | earlier compilers provided no way of distinguishing ILP32 objects | |
6443 | from LP64 objects, so if there's any doubt, we should assume that | |
6444 | the official LP64 form is being used. */ | |
6445 | if ((filedata->file_header.e_flags & EF_MIPS_ABI) == E_MIPS_ABI_EABI64 | |
6446 | && find_section (filedata, ".gcc_compiled_long32") == NULL) | |
6447 | eh_addr_size = 8; | |
6448 | break; | |
6449 | ||
6450 | case EM_H8_300: | |
6451 | case EM_H8_300H: | |
6452 | switch (filedata->file_header.e_flags & EF_H8_MACH) | |
6453 | { | |
6454 | case E_H8_MACH_H8300: | |
6455 | case E_H8_MACH_H8300HN: | |
6456 | case E_H8_MACH_H8300SN: | |
6457 | case E_H8_MACH_H8300SXN: | |
6458 | eh_addr_size = 2; | |
6459 | break; | |
6460 | case E_H8_MACH_H8300H: | |
6461 | case E_H8_MACH_H8300S: | |
6462 | case E_H8_MACH_H8300SX: | |
6463 | eh_addr_size = 4; | |
6464 | break; | |
6465 | } | |
6466 | break; | |
6467 | ||
6468 | case EM_M32C_OLD: | |
6469 | case EM_M32C: | |
6470 | switch (filedata->file_header.e_flags & EF_M32C_CPU_MASK) | |
6471 | { | |
6472 | case EF_M32C_CPU_M16C: | |
6473 | eh_addr_size = 2; | |
6474 | break; | |
6475 | } | |
6476 | break; | |
6477 | } | |
6478 | ||
6479 | #define CHECK_ENTSIZE_VALUES(section, i, size32, size64) \ | |
6480 | do \ | |
6481 | { \ | |
6482 | bfd_size_type expected_entsize = is_32bit_elf ? size32 : size64; \ | |
6483 | if (section->sh_entsize != expected_entsize) \ | |
6484 | { \ | |
6485 | char buf[40]; \ | |
6486 | sprintf_vma (buf, section->sh_entsize); \ | |
6487 | /* Note: coded this way so that there is a single string for \ | |
6488 | translation. */ \ | |
6489 | error (_("Section %d has invalid sh_entsize of %s\n"), i, buf); \ | |
6490 | error (_("(Using the expected size of %u for the rest of this dump)\n"), \ | |
6491 | (unsigned) expected_entsize); \ | |
6492 | section->sh_entsize = expected_entsize; \ | |
6493 | } \ | |
6494 | } \ | |
6495 | while (0) | |
6496 | ||
6497 | #define CHECK_ENTSIZE(section, i, type) \ | |
6498 | CHECK_ENTSIZE_VALUES (section, i, sizeof (Elf32_External_##type), \ | |
6499 | sizeof (Elf64_External_##type)) | |
6500 | ||
6501 | for (i = 0, section = filedata->section_headers; | |
6502 | i < filedata->file_header.e_shnum; | |
6503 | i++, section++) | |
6504 | { | |
6505 | char * name = SECTION_NAME_PRINT (section); | |
6506 | ||
6507 | /* Run some sanity checks on the headers and | |
6508 | possibly fill in some file data as well. */ | |
6509 | switch (section->sh_type) | |
6510 | { | |
6511 | case SHT_DYNSYM: | |
6512 | if (filedata->dynamic_symbols != NULL) | |
6513 | { | |
6514 | error (_("File contains multiple dynamic symbol tables\n")); | |
6515 | continue; | |
6516 | } | |
6517 | ||
6518 | CHECK_ENTSIZE (section, i, Sym); | |
6519 | filedata->dynamic_symbols | |
6520 | = GET_ELF_SYMBOLS (filedata, section, &filedata->num_dynamic_syms); | |
6521 | filedata->dynamic_symtab_section = section; | |
6522 | break; | |
6523 | ||
6524 | case SHT_STRTAB: | |
6525 | if (streq (name, ".dynstr")) | |
6526 | { | |
6527 | if (filedata->dynamic_strings != NULL) | |
6528 | { | |
6529 | error (_("File contains multiple dynamic string tables\n")); | |
6530 | continue; | |
6531 | } | |
6532 | ||
6533 | filedata->dynamic_strings | |
6534 | = (char *) get_data (NULL, filedata, section->sh_offset, | |
6535 | 1, section->sh_size, _("dynamic strings")); | |
6536 | filedata->dynamic_strings_length | |
6537 | = filedata->dynamic_strings == NULL ? 0 : section->sh_size; | |
6538 | filedata->dynamic_strtab_section = section; | |
6539 | } | |
6540 | break; | |
6541 | ||
6542 | case SHT_SYMTAB_SHNDX: | |
6543 | { | |
6544 | elf_section_list * entry = xmalloc (sizeof * entry); | |
6545 | ||
6546 | entry->hdr = section; | |
6547 | entry->next = filedata->symtab_shndx_list; | |
6548 | filedata->symtab_shndx_list = entry; | |
6549 | } | |
6550 | break; | |
6551 | ||
6552 | case SHT_SYMTAB: | |
6553 | CHECK_ENTSIZE (section, i, Sym); | |
6554 | break; | |
6555 | ||
6556 | case SHT_GROUP: | |
6557 | CHECK_ENTSIZE_VALUES (section, i, GRP_ENTRY_SIZE, GRP_ENTRY_SIZE); | |
6558 | break; | |
6559 | ||
6560 | case SHT_REL: | |
6561 | CHECK_ENTSIZE (section, i, Rel); | |
6562 | if (do_checks && section->sh_size == 0) | |
6563 | warn (_("Section '%s': zero-sized relocation section\n"), name); | |
6564 | break; | |
6565 | ||
6566 | case SHT_RELA: | |
6567 | CHECK_ENTSIZE (section, i, Rela); | |
6568 | if (do_checks && section->sh_size == 0) | |
6569 | warn (_("Section '%s': zero-sized relocation section\n"), name); | |
6570 | break; | |
6571 | ||
6572 | case SHT_NOTE: | |
6573 | case SHT_PROGBITS: | |
6574 | /* Having a zero sized section is not illegal according to the | |
6575 | ELF standard, but it might be an indication that something | |
6576 | is wrong. So issue a warning if we are running in lint mode. */ | |
6577 | if (do_checks && section->sh_size == 0) | |
6578 | warn (_("Section '%s': has a size of zero - is this intended ?\n"), name); | |
6579 | break; | |
6580 | ||
6581 | default: | |
6582 | break; | |
6583 | } | |
6584 | ||
6585 | if ((do_debugging || do_debug_info || do_debug_abbrevs | |
6586 | || do_debug_lines || do_debug_pubnames || do_debug_pubtypes | |
6587 | || do_debug_aranges || do_debug_frames || do_debug_macinfo | |
6588 | || do_debug_str || do_debug_str_offsets || do_debug_loc | |
6589 | || do_debug_ranges | |
6590 | || do_debug_addr || do_debug_cu_index || do_debug_links) | |
6591 | && (const_strneq (name, ".debug_") | |
6592 | || const_strneq (name, ".zdebug_"))) | |
6593 | { | |
6594 | if (name[1] == 'z') | |
6595 | name += sizeof (".zdebug_") - 1; | |
6596 | else | |
6597 | name += sizeof (".debug_") - 1; | |
6598 | ||
6599 | if (do_debugging | |
6600 | || (do_debug_info && const_strneq (name, "info")) | |
6601 | || (do_debug_info && const_strneq (name, "types")) | |
6602 | || (do_debug_abbrevs && const_strneq (name, "abbrev")) | |
6603 | || (do_debug_lines && strcmp (name, "line") == 0) | |
6604 | || (do_debug_lines && const_strneq (name, "line.")) | |
6605 | || (do_debug_pubnames && const_strneq (name, "pubnames")) | |
6606 | || (do_debug_pubtypes && const_strneq (name, "pubtypes")) | |
6607 | || (do_debug_pubnames && const_strneq (name, "gnu_pubnames")) | |
6608 | || (do_debug_pubtypes && const_strneq (name, "gnu_pubtypes")) | |
6609 | || (do_debug_aranges && const_strneq (name, "aranges")) | |
6610 | || (do_debug_ranges && const_strneq (name, "ranges")) | |
6611 | || (do_debug_ranges && const_strneq (name, "rnglists")) | |
6612 | || (do_debug_frames && const_strneq (name, "frame")) | |
6613 | || (do_debug_macinfo && const_strneq (name, "macinfo")) | |
6614 | || (do_debug_macinfo && const_strneq (name, "macro")) | |
6615 | || (do_debug_str && const_strneq (name, "str")) | |
6616 | || (do_debug_links && const_strneq (name, "sup")) | |
6617 | || (do_debug_str_offsets && const_strneq (name, "str_offsets")) | |
6618 | || (do_debug_loc && const_strneq (name, "loc")) | |
6619 | || (do_debug_loc && const_strneq (name, "loclists")) | |
6620 | || (do_debug_addr && const_strneq (name, "addr")) | |
6621 | || (do_debug_cu_index && const_strneq (name, "cu_index")) | |
6622 | || (do_debug_cu_index && const_strneq (name, "tu_index")) | |
6623 | ) | |
6624 | request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP); | |
6625 | } | |
6626 | /* Linkonce section to be combined with .debug_info at link time. */ | |
6627 | else if ((do_debugging || do_debug_info) | |
6628 | && const_strneq (name, ".gnu.linkonce.wi.")) | |
6629 | request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP); | |
6630 | else if (do_debug_frames && streq (name, ".eh_frame")) | |
6631 | request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP); | |
6632 | else if (do_gdb_index && (streq (name, ".gdb_index") | |
6633 | || streq (name, ".debug_names"))) | |
6634 | request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP); | |
6635 | /* Trace sections for Itanium VMS. */ | |
6636 | else if ((do_debugging || do_trace_info || do_trace_abbrevs | |
6637 | || do_trace_aranges) | |
6638 | && const_strneq (name, ".trace_")) | |
6639 | { | |
6640 | name += sizeof (".trace_") - 1; | |
6641 | ||
6642 | if (do_debugging | |
6643 | || (do_trace_info && streq (name, "info")) | |
6644 | || (do_trace_abbrevs && streq (name, "abbrev")) | |
6645 | || (do_trace_aranges && streq (name, "aranges")) | |
6646 | ) | |
6647 | request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP); | |
6648 | } | |
6649 | else if ((do_debugging || do_debug_links) | |
6650 | && (const_strneq (name, ".gnu_debuglink") | |
6651 | || const_strneq (name, ".gnu_debugaltlink"))) | |
6652 | request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP); | |
6653 | } | |
6654 | ||
6655 | if (! do_sections) | |
6656 | return TRUE; | |
6657 | ||
6658 | if (filedata->is_separate && ! process_links) | |
6659 | return TRUE; | |
6660 | ||
6661 | if (filedata->is_separate) | |
6662 | printf (_("\nSection Headers in linked file '%s':\n"), filedata->file_name); | |
6663 | else if (filedata->file_header.e_shnum > 1) | |
6664 | printf (_("\nSection Headers:\n")); | |
6665 | else | |
6666 | printf (_("\nSection Header:\n")); | |
6667 | ||
6668 | if (is_32bit_elf) | |
6669 | { | |
6670 | if (do_section_details) | |
6671 | { | |
6672 | printf (_(" [Nr] Name\n")); | |
6673 | printf (_(" Type Addr Off Size ES Lk Inf Al\n")); | |
6674 | } | |
6675 | else | |
6676 | printf | |
6677 | (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n")); | |
6678 | } | |
6679 | else if (do_wide) | |
6680 | { | |
6681 | if (do_section_details) | |
6682 | { | |
6683 | printf (_(" [Nr] Name\n")); | |
6684 | printf (_(" Type Address Off Size ES Lk Inf Al\n")); | |
6685 | } | |
6686 | else | |
6687 | printf | |
6688 | (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n")); | |
6689 | } | |
6690 | else | |
6691 | { | |
6692 | if (do_section_details) | |
6693 | { | |
6694 | printf (_(" [Nr] Name\n")); | |
6695 | printf (_(" Type Address Offset Link\n")); | |
6696 | printf (_(" Size EntSize Info Align\n")); | |
6697 | } | |
6698 | else | |
6699 | { | |
6700 | printf (_(" [Nr] Name Type Address Offset\n")); | |
6701 | printf (_(" Size EntSize Flags Link Info Align\n")); | |
6702 | } | |
6703 | } | |
6704 | ||
6705 | if (do_section_details) | |
6706 | printf (_(" Flags\n")); | |
6707 | ||
6708 | for (i = 0, section = filedata->section_headers; | |
6709 | i < filedata->file_header.e_shnum; | |
6710 | i++, section++) | |
6711 | { | |
6712 | /* Run some sanity checks on the section header. */ | |
6713 | ||
6714 | /* Check the sh_link field. */ | |
6715 | switch (section->sh_type) | |
6716 | { | |
6717 | case SHT_REL: | |
6718 | case SHT_RELA: | |
6719 | if (section->sh_link == 0 | |
6720 | && (filedata->file_header.e_type == ET_EXEC | |
6721 | || filedata->file_header.e_type == ET_DYN)) | |
6722 | /* A dynamic relocation section where all entries use a | |
6723 | zero symbol index need not specify a symtab section. */ | |
6724 | break; | |
6725 | /* Fall through. */ | |
6726 | case SHT_SYMTAB_SHNDX: | |
6727 | case SHT_GROUP: | |
6728 | case SHT_HASH: | |
6729 | case SHT_GNU_HASH: | |
6730 | case SHT_GNU_versym: | |
6731 | if (section->sh_link == 0 | |
6732 | || section->sh_link >= filedata->file_header.e_shnum | |
6733 | || (filedata->section_headers[section->sh_link].sh_type != SHT_SYMTAB | |
6734 | && filedata->section_headers[section->sh_link].sh_type != SHT_DYNSYM)) | |
6735 | warn (_("[%2u]: Link field (%u) should index a symtab section.\n"), | |
6736 | i, section->sh_link); | |
6737 | break; | |
6738 | ||
6739 | case SHT_DYNAMIC: | |
6740 | case SHT_SYMTAB: | |
6741 | case SHT_DYNSYM: | |
6742 | case SHT_GNU_verneed: | |
6743 | case SHT_GNU_verdef: | |
6744 | case SHT_GNU_LIBLIST: | |
6745 | if (section->sh_link == 0 | |
6746 | || section->sh_link >= filedata->file_header.e_shnum | |
6747 | || filedata->section_headers[section->sh_link].sh_type != SHT_STRTAB) | |
6748 | warn (_("[%2u]: Link field (%u) should index a string section.\n"), | |
6749 | i, section->sh_link); | |
6750 | break; | |
6751 | ||
6752 | case SHT_INIT_ARRAY: | |
6753 | case SHT_FINI_ARRAY: | |
6754 | case SHT_PREINIT_ARRAY: | |
6755 | if (section->sh_type < SHT_LOOS && section->sh_link != 0) | |
6756 | warn (_("[%2u]: Unexpected value (%u) in link field.\n"), | |
6757 | i, section->sh_link); | |
6758 | break; | |
6759 | ||
6760 | default: | |
6761 | /* FIXME: Add support for target specific section types. */ | |
6762 | #if 0 /* Currently we do not check other section types as there are too | |
6763 | many special cases. Stab sections for example have a type | |
6764 | of SHT_PROGBITS but an sh_link field that links to the .stabstr | |
6765 | section. */ | |
6766 | if (section->sh_type < SHT_LOOS && section->sh_link != 0) | |
6767 | warn (_("[%2u]: Unexpected value (%u) in link field.\n"), | |
6768 | i, section->sh_link); | |
6769 | #endif | |
6770 | break; | |
6771 | } | |
6772 | ||
6773 | /* Check the sh_info field. */ | |
6774 | switch (section->sh_type) | |
6775 | { | |
6776 | case SHT_REL: | |
6777 | case SHT_RELA: | |
6778 | if (section->sh_info == 0 | |
6779 | && (filedata->file_header.e_type == ET_EXEC | |
6780 | || filedata->file_header.e_type == ET_DYN)) | |
6781 | /* Dynamic relocations apply to segments, so they do not | |
6782 | need to specify the section they relocate. */ | |
6783 | break; | |
6784 | if (section->sh_info == 0 | |
6785 | || section->sh_info >= filedata->file_header.e_shnum | |
6786 | || (filedata->section_headers[section->sh_info].sh_type != SHT_PROGBITS | |
6787 | && filedata->section_headers[section->sh_info].sh_type != SHT_NOBITS | |
6788 | && filedata->section_headers[section->sh_info].sh_type != SHT_NOTE | |
6789 | && filedata->section_headers[section->sh_info].sh_type != SHT_INIT_ARRAY | |
6790 | && filedata->section_headers[section->sh_info].sh_type != SHT_FINI_ARRAY | |
6791 | && filedata->section_headers[section->sh_info].sh_type != SHT_PREINIT_ARRAY | |
6792 | /* FIXME: Are other section types valid ? */ | |
6793 | && filedata->section_headers[section->sh_info].sh_type < SHT_LOOS)) | |
6794 | warn (_("[%2u]: Info field (%u) should index a relocatable section.\n"), | |
6795 | i, section->sh_info); | |
6796 | break; | |
6797 | ||
6798 | case SHT_DYNAMIC: | |
6799 | case SHT_HASH: | |
6800 | case SHT_SYMTAB_SHNDX: | |
6801 | case SHT_INIT_ARRAY: | |
6802 | case SHT_FINI_ARRAY: | |
6803 | case SHT_PREINIT_ARRAY: | |
6804 | if (section->sh_info != 0) | |
6805 | warn (_("[%2u]: Unexpected value (%u) in info field.\n"), | |
6806 | i, section->sh_info); | |
6807 | break; | |
6808 | ||
6809 | case SHT_GROUP: | |
6810 | case SHT_SYMTAB: | |
6811 | case SHT_DYNSYM: | |
6812 | /* A symbol index - we assume that it is valid. */ | |
6813 | break; | |
6814 | ||
6815 | default: | |
6816 | /* FIXME: Add support for target specific section types. */ | |
6817 | if (section->sh_type == SHT_NOBITS) | |
6818 | /* NOBITS section headers with non-zero sh_info fields can be | |
6819 | created when a binary is stripped of everything but its debug | |
6820 | information. The stripped sections have their headers | |
6821 | preserved but their types set to SHT_NOBITS. So do not check | |
6822 | this type of section. */ | |
6823 | ; | |
6824 | else if (section->sh_flags & SHF_INFO_LINK) | |
6825 | { | |
6826 | if (section->sh_info < 1 || section->sh_info >= filedata->file_header.e_shnum) | |
6827 | warn (_("[%2u]: Expected link to another section in info field"), i); | |
6828 | } | |
6829 | else if (section->sh_type < SHT_LOOS | |
6830 | && (section->sh_flags & SHF_GNU_MBIND) == 0 | |
6831 | && section->sh_info != 0) | |
6832 | warn (_("[%2u]: Unexpected value (%u) in info field.\n"), | |
6833 | i, section->sh_info); | |
6834 | break; | |
6835 | } | |
6836 | ||
6837 | /* Check the sh_size field. */ | |
6838 | if (section->sh_size > filedata->file_size | |
6839 | && section->sh_type != SHT_NOBITS | |
6840 | && section->sh_type != SHT_NULL | |
6841 | && section->sh_type < SHT_LOOS) | |
6842 | warn (_("Size of section %u is larger than the entire file!\n"), i); | |
6843 | ||
6844 | printf (" [%2u] ", i); | |
6845 | if (do_section_details) | |
6846 | printf ("%s\n ", printable_section_name (filedata, section)); | |
6847 | else | |
6848 | print_symbol (-17, SECTION_NAME_PRINT (section)); | |
6849 | ||
6850 | printf (do_wide ? " %-15s " : " %-15.15s ", | |
6851 | get_section_type_name (filedata, section->sh_type)); | |
6852 | ||
6853 | if (is_32bit_elf) | |
6854 | { | |
6855 | const char * link_too_big = NULL; | |
6856 | ||
6857 | print_vma (section->sh_addr, LONG_HEX); | |
6858 | ||
6859 | printf ( " %6.6lx %6.6lx %2.2lx", | |
6860 | (unsigned long) section->sh_offset, | |
6861 | (unsigned long) section->sh_size, | |
6862 | (unsigned long) section->sh_entsize); | |
6863 | ||
6864 | if (do_section_details) | |
6865 | fputs (" ", stdout); | |
6866 | else | |
6867 | printf (" %3s ", get_elf_section_flags (filedata, section->sh_flags)); | |
6868 | ||
6869 | if (section->sh_link >= filedata->file_header.e_shnum) | |
6870 | { | |
6871 | link_too_big = ""; | |
6872 | /* The sh_link value is out of range. Normally this indicates | |
6873 | an error but it can have special values in Solaris binaries. */ | |
6874 | switch (filedata->file_header.e_machine) | |
6875 | { | |
6876 | case EM_386: | |
6877 | case EM_IAMCU: | |
6878 | case EM_X86_64: | |
6879 | case EM_L1OM: | |
6880 | case EM_K1OM: | |
6881 | case EM_OLD_SPARCV9: | |
6882 | case EM_SPARC32PLUS: | |
6883 | case EM_SPARCV9: | |
6884 | case EM_SPARC: | |
6885 | if (section->sh_link == (SHN_BEFORE & 0xffff)) | |
6886 | link_too_big = "BEFORE"; | |
6887 | else if (section->sh_link == (SHN_AFTER & 0xffff)) | |
6888 | link_too_big = "AFTER"; | |
6889 | break; | |
6890 | default: | |
6891 | break; | |
6892 | } | |
6893 | } | |
6894 | ||
6895 | if (do_section_details) | |
6896 | { | |
6897 | if (link_too_big != NULL && * link_too_big) | |
6898 | printf ("<%s> ", link_too_big); | |
6899 | else | |
6900 | printf ("%2u ", section->sh_link); | |
6901 | printf ("%3u %2lu\n", section->sh_info, | |
6902 | (unsigned long) section->sh_addralign); | |
6903 | } | |
6904 | else | |
6905 | printf ("%2u %3u %2lu\n", | |
6906 | section->sh_link, | |
6907 | section->sh_info, | |
6908 | (unsigned long) section->sh_addralign); | |
6909 | ||
6910 | if (link_too_big && ! * link_too_big) | |
6911 | warn (_("section %u: sh_link value of %u is larger than the number of sections\n"), | |
6912 | i, section->sh_link); | |
6913 | } | |
6914 | else if (do_wide) | |
6915 | { | |
6916 | print_vma (section->sh_addr, LONG_HEX); | |
6917 | ||
6918 | if ((long) section->sh_offset == section->sh_offset) | |
6919 | printf (" %6.6lx", (unsigned long) section->sh_offset); | |
6920 | else | |
6921 | { | |
6922 | putchar (' '); | |
6923 | print_vma (section->sh_offset, LONG_HEX); | |
6924 | } | |
6925 | ||
6926 | if ((unsigned long) section->sh_size == section->sh_size) | |
6927 | printf (" %6.6lx", (unsigned long) section->sh_size); | |
6928 | else | |
6929 | { | |
6930 | putchar (' '); | |
6931 | print_vma (section->sh_size, LONG_HEX); | |
6932 | } | |
6933 | ||
6934 | if ((unsigned long) section->sh_entsize == section->sh_entsize) | |
6935 | printf (" %2.2lx", (unsigned long) section->sh_entsize); | |
6936 | else | |
6937 | { | |
6938 | putchar (' '); | |
6939 | print_vma (section->sh_entsize, LONG_HEX); | |
6940 | } | |
6941 | ||
6942 | if (do_section_details) | |
6943 | fputs (" ", stdout); | |
6944 | else | |
6945 | printf (" %3s ", get_elf_section_flags (filedata, section->sh_flags)); | |
6946 | ||
6947 | printf ("%2u %3u ", section->sh_link, section->sh_info); | |
6948 | ||
6949 | if ((unsigned long) section->sh_addralign == section->sh_addralign) | |
6950 | printf ("%2lu\n", (unsigned long) section->sh_addralign); | |
6951 | else | |
6952 | { | |
6953 | print_vma (section->sh_addralign, DEC); | |
6954 | putchar ('\n'); | |
6955 | } | |
6956 | } | |
6957 | else if (do_section_details) | |
6958 | { | |
6959 | putchar (' '); | |
6960 | print_vma (section->sh_addr, LONG_HEX); | |
6961 | if ((long) section->sh_offset == section->sh_offset) | |
6962 | printf (" %16.16lx", (unsigned long) section->sh_offset); | |
6963 | else | |
6964 | { | |
6965 | printf (" "); | |
6966 | print_vma (section->sh_offset, LONG_HEX); | |
6967 | } | |
6968 | printf (" %u\n ", section->sh_link); | |
6969 | print_vma (section->sh_size, LONG_HEX); | |
6970 | putchar (' '); | |
6971 | print_vma (section->sh_entsize, LONG_HEX); | |
6972 | ||
6973 | printf (" %-16u %lu\n", | |
6974 | section->sh_info, | |
6975 | (unsigned long) section->sh_addralign); | |
6976 | } | |
6977 | else | |
6978 | { | |
6979 | putchar (' '); | |
6980 | print_vma (section->sh_addr, LONG_HEX); | |
6981 | if ((long) section->sh_offset == section->sh_offset) | |
6982 | printf (" %8.8lx", (unsigned long) section->sh_offset); | |
6983 | else | |
6984 | { | |
6985 | printf (" "); | |
6986 | print_vma (section->sh_offset, LONG_HEX); | |
6987 | } | |
6988 | printf ("\n "); | |
6989 | print_vma (section->sh_size, LONG_HEX); | |
6990 | printf (" "); | |
6991 | print_vma (section->sh_entsize, LONG_HEX); | |
6992 | ||
6993 | printf (" %3s ", get_elf_section_flags (filedata, section->sh_flags)); | |
6994 | ||
6995 | printf (" %2u %3u %lu\n", | |
6996 | section->sh_link, | |
6997 | section->sh_info, | |
6998 | (unsigned long) section->sh_addralign); | |
6999 | } | |
7000 | ||
7001 | if (do_section_details) | |
7002 | { | |
7003 | printf (" %s\n", get_elf_section_flags (filedata, section->sh_flags)); | |
7004 | if ((section->sh_flags & SHF_COMPRESSED) != 0) | |
7005 | { | |
7006 | /* Minimum section size is 12 bytes for 32-bit compression | |
7007 | header + 12 bytes for compressed data header. */ | |
7008 | unsigned char buf[24]; | |
7009 | ||
7010 | assert (sizeof (buf) >= sizeof (Elf64_External_Chdr)); | |
7011 | if (get_data (&buf, filedata, section->sh_offset, 1, | |
7012 | sizeof (buf), _("compression header"))) | |
7013 | { | |
7014 | Elf_Internal_Chdr chdr; | |
7015 | ||
7016 | if (get_compression_header (&chdr, buf, sizeof (buf)) == 0) | |
7017 | printf (_(" [<corrupt>]\n")); | |
7018 | else | |
7019 | { | |
7020 | if (chdr.ch_type == ELFCOMPRESS_ZLIB) | |
7021 | printf (" ZLIB, "); | |
7022 | else | |
7023 | printf (_(" [<unknown>: 0x%x], "), | |
7024 | chdr.ch_type); | |
7025 | print_vma (chdr.ch_size, LONG_HEX); | |
7026 | printf (", %lu\n", (unsigned long) chdr.ch_addralign); | |
7027 | } | |
7028 | } | |
7029 | } | |
7030 | } | |
7031 | } | |
7032 | ||
7033 | if (!do_section_details) | |
7034 | { | |
7035 | /* The ordering of the letters shown here matches the ordering of the | |
7036 | corresponding SHF_xxx values, and hence the order in which these | |
7037 | letters will be displayed to the user. */ | |
7038 | printf (_("Key to Flags:\n\ | |
7039 | W (write), A (alloc), X (execute), M (merge), S (strings), I (info),\n\ | |
7040 | L (link order), O (extra OS processing required), G (group), T (TLS),\n\ | |
7041 | C (compressed), x (unknown), o (OS specific), E (exclude),\n ")); | |
7042 | switch (filedata->file_header.e_ident[EI_OSABI]) | |
7043 | { | |
7044 | case ELFOSABI_GNU: | |
7045 | case ELFOSABI_FREEBSD: | |
7046 | printf (_("R (retain), ")); | |
7047 | /* Fall through */ | |
7048 | case ELFOSABI_NONE: | |
7049 | printf (_("D (mbind), ")); | |
7050 | break; | |
7051 | default: | |
7052 | break; | |
7053 | } | |
7054 | if (filedata->file_header.e_machine == EM_X86_64 | |
7055 | || filedata->file_header.e_machine == EM_L1OM | |
7056 | || filedata->file_header.e_machine == EM_K1OM) | |
7057 | printf (_("l (large), ")); | |
7058 | else if (filedata->file_header.e_machine == EM_ARM) | |
7059 | printf (_("y (purecode), ")); | |
7060 | else if (filedata->file_header.e_machine == EM_PPC) | |
7061 | printf (_("v (VLE), ")); | |
7062 | printf ("p (processor specific)\n"); | |
7063 | } | |
7064 | ||
7065 | return TRUE; | |
7066 | } | |
7067 | ||
7068 | static bfd_boolean | |
7069 | get_symtab (Filedata *filedata, Elf_Internal_Shdr *symsec, | |
7070 | Elf_Internal_Sym **symtab, unsigned long *nsyms, | |
7071 | char **strtab, unsigned long *strtablen) | |
7072 | { | |
7073 | *strtab = NULL; | |
7074 | *strtablen = 0; | |
7075 | *symtab = GET_ELF_SYMBOLS (filedata, symsec, nsyms); | |
7076 | ||
7077 | if (*symtab == NULL) | |
7078 | return FALSE; | |
7079 | ||
7080 | if (symsec->sh_link != 0) | |
7081 | { | |
7082 | Elf_Internal_Shdr *strsec; | |
7083 | ||
7084 | if (symsec->sh_link >= filedata->file_header.e_shnum) | |
7085 | { | |
7086 | error (_("Bad sh_link in symbol table section\n")); | |
7087 | free (*symtab); | |
7088 | *symtab = NULL; | |
7089 | *nsyms = 0; | |
7090 | return FALSE; | |
7091 | } | |
7092 | ||
7093 | strsec = filedata->section_headers + symsec->sh_link; | |
7094 | ||
7095 | *strtab = (char *) get_data (NULL, filedata, strsec->sh_offset, | |
7096 | 1, strsec->sh_size, _("string table")); | |
7097 | if (*strtab == NULL) | |
7098 | { | |
7099 | free (*symtab); | |
7100 | *symtab = NULL; | |
7101 | *nsyms = 0; | |
7102 | return FALSE; | |
7103 | } | |
7104 | *strtablen = strsec->sh_size; | |
7105 | } | |
7106 | return TRUE; | |
7107 | } | |
7108 | ||
7109 | static const char * | |
7110 | get_group_flags (unsigned int flags) | |
7111 | { | |
7112 | static char buff[128]; | |
7113 | ||
7114 | if (flags == 0) | |
7115 | return ""; | |
7116 | else if (flags == GRP_COMDAT) | |
7117 | return "COMDAT "; | |
7118 | ||
7119 | snprintf (buff, sizeof buff, "[0x%x: %s%s%s]", | |
7120 | flags, | |
7121 | flags & GRP_MASKOS ? _("<OS specific>") : "", | |
7122 | flags & GRP_MASKPROC ? _("<PROC specific>") : "", | |
7123 | (flags & ~(GRP_COMDAT | GRP_MASKOS | GRP_MASKPROC) | |
7124 | ? _("<unknown>") : "")); | |
7125 | ||
7126 | return buff; | |
7127 | } | |
7128 | ||
7129 | static bfd_boolean | |
7130 | process_section_groups (Filedata * filedata) | |
7131 | { | |
7132 | Elf_Internal_Shdr * section; | |
7133 | unsigned int i; | |
7134 | struct group * group; | |
7135 | Elf_Internal_Shdr * symtab_sec; | |
7136 | Elf_Internal_Shdr * strtab_sec; | |
7137 | Elf_Internal_Sym * symtab; | |
7138 | unsigned long num_syms; | |
7139 | char * strtab; | |
7140 | size_t strtab_size; | |
7141 | ||
7142 | /* Don't process section groups unless needed. */ | |
7143 | if (!do_unwind && !do_section_groups) | |
7144 | return TRUE; | |
7145 | ||
7146 | if (filedata->file_header.e_shnum == 0) | |
7147 | { | |
7148 | if (do_section_groups) | |
7149 | { | |
7150 | if (filedata->is_separate) | |
7151 | printf (_("\nThere are no sections group in linked file '%s'.\n"), | |
7152 | filedata->file_name); | |
7153 | else | |
7154 | printf (_("\nThere are no section groups in this file.\n")); | |
7155 | } | |
7156 | return TRUE; | |
7157 | } | |
7158 | ||
7159 | if (filedata->section_headers == NULL) | |
7160 | { | |
7161 | error (_("Section headers are not available!\n")); | |
7162 | /* PR 13622: This can happen with a corrupt ELF header. */ | |
7163 | return FALSE; | |
7164 | } | |
7165 | ||
7166 | filedata->section_headers_groups | |
7167 | = (struct group **) calloc (filedata->file_header.e_shnum, | |
7168 | sizeof (struct group *)); | |
7169 | ||
7170 | if (filedata->section_headers_groups == NULL) | |
7171 | { | |
7172 | error (_("Out of memory reading %u section group headers\n"), | |
7173 | filedata->file_header.e_shnum); | |
7174 | return FALSE; | |
7175 | } | |
7176 | ||
7177 | /* Scan the sections for the group section. */ | |
7178 | filedata->group_count = 0; | |
7179 | for (i = 0, section = filedata->section_headers; | |
7180 | i < filedata->file_header.e_shnum; | |
7181 | i++, section++) | |
7182 | if (section->sh_type == SHT_GROUP) | |
7183 | filedata->group_count++; | |
7184 | ||
7185 | if (filedata->group_count == 0) | |
7186 | { | |
7187 | if (do_section_groups) | |
7188 | { | |
7189 | if (filedata->is_separate) | |
7190 | printf (_("\nThere are no section groups in linked file '%s'.\n"), | |
7191 | filedata->file_name); | |
7192 | else | |
7193 | printf (_("\nThere are no section groups in this file.\n")); | |
7194 | } | |
7195 | ||
7196 | return TRUE; | |
7197 | } | |
7198 | ||
7199 | filedata->section_groups = (struct group *) calloc (filedata->group_count, | |
7200 | sizeof (struct group)); | |
7201 | ||
7202 | if (filedata->section_groups == NULL) | |
7203 | { | |
7204 | error (_("Out of memory reading %lu groups\n"), | |
7205 | (unsigned long) filedata->group_count); | |
7206 | return FALSE; | |
7207 | } | |
7208 | ||
7209 | symtab_sec = NULL; | |
7210 | strtab_sec = NULL; | |
7211 | symtab = NULL; | |
7212 | num_syms = 0; | |
7213 | strtab = NULL; | |
7214 | strtab_size = 0; | |
7215 | ||
7216 | if (filedata->is_separate) | |
7217 | printf (_("Section groups in linked file '%s'\n"), filedata->file_name); | |
7218 | ||
7219 | for (i = 0, section = filedata->section_headers, group = filedata->section_groups; | |
7220 | i < filedata->file_header.e_shnum; | |
7221 | i++, section++) | |
7222 | { | |
7223 | if (section->sh_type == SHT_GROUP) | |
7224 | { | |
7225 | const char * name = printable_section_name (filedata, section); | |
7226 | const char * group_name; | |
7227 | unsigned char * start; | |
7228 | unsigned char * indices; | |
7229 | unsigned int entry, j, size; | |
7230 | Elf_Internal_Shdr * sec; | |
7231 | Elf_Internal_Sym * sym; | |
7232 | ||
7233 | /* Get the symbol table. */ | |
7234 | if (section->sh_link >= filedata->file_header.e_shnum | |
7235 | || ((sec = filedata->section_headers + section->sh_link)->sh_type | |
7236 | != SHT_SYMTAB)) | |
7237 | { | |
7238 | error (_("Bad sh_link in group section `%s'\n"), name); | |
7239 | continue; | |
7240 | } | |
7241 | ||
7242 | if (symtab_sec != sec) | |
7243 | { | |
7244 | symtab_sec = sec; | |
7245 | free (symtab); | |
7246 | symtab = GET_ELF_SYMBOLS (filedata, symtab_sec, & num_syms); | |
7247 | } | |
7248 | ||
7249 | if (symtab == NULL) | |
7250 | { | |
7251 | error (_("Corrupt header in group section `%s'\n"), name); | |
7252 | continue; | |
7253 | } | |
7254 | ||
7255 | if (section->sh_info >= num_syms) | |
7256 | { | |
7257 | error (_("Bad sh_info in group section `%s'\n"), name); | |
7258 | continue; | |
7259 | } | |
7260 | ||
7261 | sym = symtab + section->sh_info; | |
7262 | ||
7263 | if (ELF_ST_TYPE (sym->st_info) == STT_SECTION) | |
7264 | { | |
7265 | if (sym->st_shndx == 0 | |
7266 | || sym->st_shndx >= filedata->file_header.e_shnum) | |
7267 | { | |
7268 | error (_("Bad sh_info in group section `%s'\n"), name); | |
7269 | continue; | |
7270 | } | |
7271 | ||
7272 | group_name = SECTION_NAME_PRINT (filedata->section_headers | |
7273 | + sym->st_shndx); | |
7274 | strtab_sec = NULL; | |
7275 | free (strtab); | |
7276 | strtab = NULL; | |
7277 | strtab_size = 0; | |
7278 | } | |
7279 | else | |
7280 | { | |
7281 | /* Get the string table. */ | |
7282 | if (symtab_sec->sh_link >= filedata->file_header.e_shnum) | |
7283 | { | |
7284 | strtab_sec = NULL; | |
7285 | free (strtab); | |
7286 | strtab = NULL; | |
7287 | strtab_size = 0; | |
7288 | } | |
7289 | else if (strtab_sec | |
7290 | != (sec = filedata->section_headers + symtab_sec->sh_link)) | |
7291 | { | |
7292 | strtab_sec = sec; | |
7293 | free (strtab); | |
7294 | ||
7295 | strtab = (char *) get_data (NULL, filedata, strtab_sec->sh_offset, | |
7296 | 1, strtab_sec->sh_size, | |
7297 | _("string table")); | |
7298 | strtab_size = strtab != NULL ? strtab_sec->sh_size : 0; | |
7299 | } | |
7300 | group_name = sym->st_name < strtab_size | |
7301 | ? strtab + sym->st_name : _("<corrupt>"); | |
7302 | } | |
7303 | ||
7304 | /* PR 17531: file: loop. */ | |
7305 | if (section->sh_entsize > section->sh_size) | |
7306 | { | |
7307 | error (_("Section %s has sh_entsize (0x%lx) which is larger than its size (0x%lx)\n"), | |
7308 | printable_section_name (filedata, section), | |
7309 | (unsigned long) section->sh_entsize, | |
7310 | (unsigned long) section->sh_size); | |
7311 | continue; | |
7312 | } | |
7313 | ||
7314 | start = (unsigned char *) get_data (NULL, filedata, section->sh_offset, | |
7315 | 1, section->sh_size, | |
7316 | _("section data")); | |
7317 | if (start == NULL) | |
7318 | continue; | |
7319 | ||
7320 | indices = start; | |
7321 | size = (section->sh_size / section->sh_entsize) - 1; | |
7322 | entry = byte_get (indices, 4); | |
7323 | indices += 4; | |
7324 | ||
7325 | if (do_section_groups) | |
7326 | { | |
7327 | printf (_("\n%sgroup section [%5u] `%s' [%s] contains %u sections:\n"), | |
7328 | get_group_flags (entry), i, name, group_name, size); | |
7329 | ||
7330 | printf (_(" [Index] Name\n")); | |
7331 | } | |
7332 | ||
7333 | group->group_index = i; | |
7334 | ||
7335 | for (j = 0; j < size; j++) | |
7336 | { | |
7337 | struct group_list * g; | |
7338 | ||
7339 | entry = byte_get (indices, 4); | |
7340 | indices += 4; | |
7341 | ||
7342 | if (entry >= filedata->file_header.e_shnum) | |
7343 | { | |
7344 | static unsigned num_group_errors = 0; | |
7345 | ||
7346 | if (num_group_errors ++ < 10) | |
7347 | { | |
7348 | error (_("section [%5u] in group section [%5u] > maximum section [%5u]\n"), | |
7349 | entry, i, filedata->file_header.e_shnum - 1); | |
7350 | if (num_group_errors == 10) | |
7351 | warn (_("Further error messages about overlarge group section indices suppressed\n")); | |
7352 | } | |
7353 | continue; | |
7354 | } | |
7355 | ||
7356 | if (filedata->section_headers_groups [entry] != NULL) | |
7357 | { | |
7358 | if (entry) | |
7359 | { | |
7360 | static unsigned num_errs = 0; | |
7361 | ||
7362 | if (num_errs ++ < 10) | |
7363 | { | |
7364 | error (_("section [%5u] in group section [%5u] already in group section [%5u]\n"), | |
7365 | entry, i, | |
7366 | filedata->section_headers_groups [entry]->group_index); | |
7367 | if (num_errs == 10) | |
7368 | warn (_("Further error messages about already contained group sections suppressed\n")); | |
7369 | } | |
7370 | continue; | |
7371 | } | |
7372 | else | |
7373 | { | |
7374 | /* Intel C/C++ compiler may put section 0 in a | |
7375 | section group. We just warn it the first time | |
7376 | and ignore it afterwards. */ | |
7377 | static bfd_boolean warned = FALSE; | |
7378 | if (!warned) | |
7379 | { | |
7380 | error (_("section 0 in group section [%5u]\n"), | |
7381 | filedata->section_headers_groups [entry]->group_index); | |
7382 | warned = TRUE; | |
7383 | } | |
7384 | } | |
7385 | } | |
7386 | ||
7387 | filedata->section_headers_groups [entry] = group; | |
7388 | ||
7389 | if (do_section_groups) | |
7390 | { | |
7391 | sec = filedata->section_headers + entry; | |
7392 | printf (" [%5u] %s\n", entry, printable_section_name (filedata, sec)); | |
7393 | } | |
7394 | ||
7395 | g = (struct group_list *) xmalloc (sizeof (struct group_list)); | |
7396 | g->section_index = entry; | |
7397 | g->next = group->root; | |
7398 | group->root = g; | |
7399 | } | |
7400 | ||
7401 | free (start); | |
7402 | ||
7403 | group++; | |
7404 | } | |
7405 | } | |
7406 | ||
7407 | free (symtab); | |
7408 | free (strtab); | |
7409 | return TRUE; | |
7410 | } | |
7411 | ||
7412 | /* Data used to display dynamic fixups. */ | |
7413 | ||
7414 | struct ia64_vms_dynfixup | |
7415 | { | |
7416 | bfd_vma needed_ident; /* Library ident number. */ | |
7417 | bfd_vma needed; /* Index in the dstrtab of the library name. */ | |
7418 | bfd_vma fixup_needed; /* Index of the library. */ | |
7419 | bfd_vma fixup_rela_cnt; /* Number of fixups. */ | |
7420 | bfd_vma fixup_rela_off; /* Fixups offset in the dynamic segment. */ | |
7421 | }; | |
7422 | ||
7423 | /* Data used to display dynamic relocations. */ | |
7424 | ||
7425 | struct ia64_vms_dynimgrela | |
7426 | { | |
7427 | bfd_vma img_rela_cnt; /* Number of relocations. */ | |
7428 | bfd_vma img_rela_off; /* Reloc offset in the dynamic segment. */ | |
7429 | }; | |
7430 | ||
7431 | /* Display IA-64 OpenVMS dynamic fixups (used to dynamically link a shared | |
7432 | library). */ | |
7433 | ||
7434 | static bfd_boolean | |
7435 | dump_ia64_vms_dynamic_fixups (Filedata * filedata, | |
7436 | struct ia64_vms_dynfixup * fixup, | |
7437 | const char * strtab, | |
7438 | unsigned int strtab_sz) | |
7439 | { | |
7440 | Elf64_External_VMS_IMAGE_FIXUP * imfs; | |
7441 | long i; | |
7442 | const char * lib_name; | |
7443 | ||
7444 | imfs = get_data (NULL, filedata, | |
7445 | filedata->dynamic_addr + fixup->fixup_rela_off, | |
7446 | sizeof (*imfs), fixup->fixup_rela_cnt, | |
7447 | _("dynamic section image fixups")); | |
7448 | if (!imfs) | |
7449 | return FALSE; | |
7450 | ||
7451 | if (fixup->needed < strtab_sz) | |
7452 | lib_name = strtab + fixup->needed; | |
7453 | else | |
7454 | { | |
7455 | warn (_("corrupt library name index of 0x%lx found in dynamic entry"), | |
7456 | (unsigned long) fixup->needed); | |
7457 | lib_name = "???"; | |
7458 | } | |
7459 | ||
7460 | printf (_("\nImage fixups for needed library #%d: %s - ident: %lx\n"), | |
7461 | (int) fixup->fixup_needed, lib_name, (long) fixup->needed_ident); | |
7462 | printf | |
7463 | (_("Seg Offset Type SymVec DataType\n")); | |
7464 | ||
7465 | for (i = 0; i < (long) fixup->fixup_rela_cnt; i++) | |
7466 | { | |
7467 | unsigned int type; | |
7468 | const char *rtype; | |
7469 | ||
7470 | printf ("%3u ", (unsigned) BYTE_GET (imfs [i].fixup_seg)); | |
7471 | printf_vma ((bfd_vma) BYTE_GET (imfs [i].fixup_offset)); | |
7472 | type = BYTE_GET (imfs [i].type); | |
7473 | rtype = elf_ia64_reloc_type (type); | |
7474 | if (rtype == NULL) | |
7475 | printf (" 0x%08x ", type); | |
7476 | else | |
7477 | printf (" %-32s ", rtype); | |
7478 | printf ("%6u ", (unsigned) BYTE_GET (imfs [i].symvec_index)); | |
7479 | printf ("0x%08x\n", (unsigned) BYTE_GET (imfs [i].data_type)); | |
7480 | } | |
7481 | ||
7482 | free (imfs); | |
7483 | return TRUE; | |
7484 | } | |
7485 | ||
7486 | /* Display IA-64 OpenVMS dynamic relocations (used to relocate an image). */ | |
7487 | ||
7488 | static bfd_boolean | |
7489 | dump_ia64_vms_dynamic_relocs (Filedata * filedata, struct ia64_vms_dynimgrela *imgrela) | |
7490 | { | |
7491 | Elf64_External_VMS_IMAGE_RELA *imrs; | |
7492 | long i; | |
7493 | ||
7494 | imrs = get_data (NULL, filedata, | |
7495 | filedata->dynamic_addr + imgrela->img_rela_off, | |
7496 | sizeof (*imrs), imgrela->img_rela_cnt, | |
7497 | _("dynamic section image relocations")); | |
7498 | if (!imrs) | |
7499 | return FALSE; | |
7500 | ||
7501 | printf (_("\nImage relocs\n")); | |
7502 | printf | |
7503 | (_("Seg Offset Type Addend Seg Sym Off\n")); | |
7504 | ||
7505 | for (i = 0; i < (long) imgrela->img_rela_cnt; i++) | |
7506 | { | |
7507 | unsigned int type; | |
7508 | const char *rtype; | |
7509 | ||
7510 | printf ("%3u ", (unsigned) BYTE_GET (imrs [i].rela_seg)); | |
7511 | printf ("%08" BFD_VMA_FMT "x ", | |
7512 | (bfd_vma) BYTE_GET (imrs [i].rela_offset)); | |
7513 | type = BYTE_GET (imrs [i].type); | |
7514 | rtype = elf_ia64_reloc_type (type); | |
7515 | if (rtype == NULL) | |
7516 | printf ("0x%08x ", type); | |
7517 | else | |
7518 | printf ("%-31s ", rtype); | |
7519 | print_vma (BYTE_GET (imrs [i].addend), FULL_HEX); | |
7520 | printf ("%3u ", (unsigned) BYTE_GET (imrs [i].sym_seg)); | |
7521 | printf ("%08" BFD_VMA_FMT "x\n", | |
7522 | (bfd_vma) BYTE_GET (imrs [i].sym_offset)); | |
7523 | } | |
7524 | ||
7525 | free (imrs); | |
7526 | return TRUE; | |
7527 | } | |
7528 | ||
7529 | /* Display IA-64 OpenVMS dynamic relocations and fixups. */ | |
7530 | ||
7531 | static bfd_boolean | |
7532 | process_ia64_vms_dynamic_relocs (Filedata * filedata) | |
7533 | { | |
7534 | struct ia64_vms_dynfixup fixup; | |
7535 | struct ia64_vms_dynimgrela imgrela; | |
7536 | Elf_Internal_Dyn *entry; | |
7537 | bfd_vma strtab_off = 0; | |
7538 | bfd_vma strtab_sz = 0; | |
7539 | char *strtab = NULL; | |
7540 | bfd_boolean res = TRUE; | |
7541 | ||
7542 | memset (&fixup, 0, sizeof (fixup)); | |
7543 | memset (&imgrela, 0, sizeof (imgrela)); | |
7544 | ||
7545 | /* Note: the order of the entries is specified by the OpenVMS specs. */ | |
7546 | for (entry = filedata->dynamic_section; | |
7547 | entry < filedata->dynamic_section + filedata->dynamic_nent; | |
7548 | entry++) | |
7549 | { | |
7550 | switch (entry->d_tag) | |
7551 | { | |
7552 | case DT_IA_64_VMS_STRTAB_OFFSET: | |
7553 | strtab_off = entry->d_un.d_val; | |
7554 | break; | |
7555 | case DT_STRSZ: | |
7556 | strtab_sz = entry->d_un.d_val; | |
7557 | if (strtab == NULL) | |
7558 | strtab = get_data (NULL, filedata, | |
7559 | filedata->dynamic_addr + strtab_off, | |
7560 | 1, strtab_sz, _("dynamic string section")); | |
7561 | if (strtab == NULL) | |
7562 | strtab_sz = 0; | |
7563 | break; | |
7564 | ||
7565 | case DT_IA_64_VMS_NEEDED_IDENT: | |
7566 | fixup.needed_ident = entry->d_un.d_val; | |
7567 | break; | |
7568 | case DT_NEEDED: | |
7569 | fixup.needed = entry->d_un.d_val; | |
7570 | break; | |
7571 | case DT_IA_64_VMS_FIXUP_NEEDED: | |
7572 | fixup.fixup_needed = entry->d_un.d_val; | |
7573 | break; | |
7574 | case DT_IA_64_VMS_FIXUP_RELA_CNT: | |
7575 | fixup.fixup_rela_cnt = entry->d_un.d_val; | |
7576 | break; | |
7577 | case DT_IA_64_VMS_FIXUP_RELA_OFF: | |
7578 | fixup.fixup_rela_off = entry->d_un.d_val; | |
7579 | if (! dump_ia64_vms_dynamic_fixups (filedata, &fixup, strtab, strtab_sz)) | |
7580 | res = FALSE; | |
7581 | break; | |
7582 | case DT_IA_64_VMS_IMG_RELA_CNT: | |
7583 | imgrela.img_rela_cnt = entry->d_un.d_val; | |
7584 | break; | |
7585 | case DT_IA_64_VMS_IMG_RELA_OFF: | |
7586 | imgrela.img_rela_off = entry->d_un.d_val; | |
7587 | if (! dump_ia64_vms_dynamic_relocs (filedata, &imgrela)) | |
7588 | res = FALSE; | |
7589 | break; | |
7590 | ||
7591 | default: | |
7592 | break; | |
7593 | } | |
7594 | } | |
7595 | ||
7596 | free (strtab); | |
7597 | ||
7598 | return res; | |
7599 | } | |
7600 | ||
7601 | static struct | |
7602 | { | |
7603 | const char * name; | |
7604 | int reloc; | |
7605 | int size; | |
7606 | int rela; | |
7607 | } | |
7608 | dynamic_relocations [] = | |
7609 | { | |
7610 | { "REL", DT_REL, DT_RELSZ, FALSE }, | |
7611 | { "RELA", DT_RELA, DT_RELASZ, TRUE }, | |
7612 | { "PLT", DT_JMPREL, DT_PLTRELSZ, UNKNOWN } | |
7613 | }; | |
7614 | ||
7615 | /* Process the reloc section. */ | |
7616 | ||
7617 | static bfd_boolean | |
7618 | process_relocs (Filedata * filedata) | |
7619 | { | |
7620 | unsigned long rel_size; | |
7621 | unsigned long rel_offset; | |
7622 | ||
7623 | if (!do_reloc) | |
7624 | return TRUE; | |
7625 | ||
7626 | if (do_using_dynamic) | |
7627 | { | |
7628 | int is_rela; | |
7629 | const char * name; | |
7630 | bfd_boolean has_dynamic_reloc; | |
7631 | unsigned int i; | |
7632 | ||
7633 | has_dynamic_reloc = FALSE; | |
7634 | ||
7635 | for (i = 0; i < ARRAY_SIZE (dynamic_relocations); i++) | |
7636 | { | |
7637 | is_rela = dynamic_relocations [i].rela; | |
7638 | name = dynamic_relocations [i].name; | |
7639 | rel_size = filedata->dynamic_info[dynamic_relocations [i].size]; | |
7640 | rel_offset = filedata->dynamic_info[dynamic_relocations [i].reloc]; | |
7641 | ||
7642 | if (rel_size) | |
7643 | has_dynamic_reloc = TRUE; | |
7644 | ||
7645 | if (is_rela == UNKNOWN) | |
7646 | { | |
7647 | if (dynamic_relocations [i].reloc == DT_JMPREL) | |
7648 | switch (filedata->dynamic_info[DT_PLTREL]) | |
7649 | { | |
7650 | case DT_REL: | |
7651 | is_rela = FALSE; | |
7652 | break; | |
7653 | case DT_RELA: | |
7654 | is_rela = TRUE; | |
7655 | break; | |
7656 | } | |
7657 | } | |
7658 | ||
7659 | if (rel_size) | |
7660 | { | |
7661 | if (filedata->is_separate) | |
7662 | printf | |
7663 | (_("\nIn linked file '%s' section '%s' at offset 0x%lx contains %ld bytes:\n"), | |
7664 | filedata->file_name, name, rel_offset, rel_size); | |
7665 | else | |
7666 | printf | |
7667 | (_("\n'%s' relocation section at offset 0x%lx contains %ld bytes:\n"), | |
7668 | name, rel_offset, rel_size); | |
7669 | ||
7670 | ||
7671 | dump_relocations (filedata, | |
7672 | offset_from_vma (filedata, rel_offset, rel_size), | |
7673 | rel_size, | |
7674 | filedata->dynamic_symbols, | |
7675 | filedata->num_dynamic_syms, | |
7676 | filedata->dynamic_strings, | |
7677 | filedata->dynamic_strings_length, | |
7678 | is_rela, TRUE /* is_dynamic */); | |
7679 | } | |
7680 | } | |
7681 | ||
7682 | if (is_ia64_vms (filedata)) | |
7683 | if (process_ia64_vms_dynamic_relocs (filedata)) | |
7684 | has_dynamic_reloc = TRUE; | |
7685 | ||
7686 | if (! has_dynamic_reloc) | |
7687 | { | |
7688 | if (filedata->is_separate) | |
7689 | printf (_("\nThere are no dynamic relocations in linked file '%s'.\n"), | |
7690 | filedata->file_name); | |
7691 | else | |
7692 | printf (_("\nThere are no dynamic relocations in this file.\n")); | |
7693 | } | |
7694 | } | |
7695 | else | |
7696 | { | |
7697 | Elf_Internal_Shdr * section; | |
7698 | unsigned long i; | |
7699 | bfd_boolean found = FALSE; | |
7700 | ||
7701 | for (i = 0, section = filedata->section_headers; | |
7702 | i < filedata->file_header.e_shnum; | |
7703 | i++, section++) | |
7704 | { | |
7705 | if ( section->sh_type != SHT_RELA | |
7706 | && section->sh_type != SHT_REL) | |
7707 | continue; | |
7708 | ||
7709 | rel_offset = section->sh_offset; | |
7710 | rel_size = section->sh_size; | |
7711 | ||
7712 | if (rel_size) | |
7713 | { | |
7714 | int is_rela; | |
7715 | unsigned long num_rela; | |
7716 | ||
7717 | if (filedata->is_separate) | |
7718 | printf (_("\nIn linked file '%s' relocation section "), | |
7719 | filedata->file_name); | |
7720 | else | |
7721 | printf (_("\nRelocation section ")); | |
7722 | ||
7723 | if (filedata->string_table == NULL) | |
7724 | printf ("%d", section->sh_name); | |
7725 | else | |
7726 | printf ("'%s'", printable_section_name (filedata, section)); | |
7727 | ||
7728 | num_rela = rel_size / section->sh_entsize; | |
7729 | printf (ngettext (" at offset 0x%lx contains %lu entry:\n", | |
7730 | " at offset 0x%lx contains %lu entries:\n", | |
7731 | num_rela), | |
7732 | rel_offset, num_rela); | |
7733 | ||
7734 | is_rela = section->sh_type == SHT_RELA; | |
7735 | ||
7736 | if (section->sh_link != 0 | |
7737 | && section->sh_link < filedata->file_header.e_shnum) | |
7738 | { | |
7739 | Elf_Internal_Shdr * symsec; | |
7740 | Elf_Internal_Sym * symtab; | |
7741 | unsigned long nsyms; | |
7742 | unsigned long strtablen = 0; | |
7743 | char * strtab = NULL; | |
7744 | ||
7745 | symsec = filedata->section_headers + section->sh_link; | |
7746 | if (symsec->sh_type != SHT_SYMTAB | |
7747 | && symsec->sh_type != SHT_DYNSYM) | |
7748 | continue; | |
7749 | ||
7750 | if (!get_symtab (filedata, symsec, | |
7751 | &symtab, &nsyms, &strtab, &strtablen)) | |
7752 | continue; | |
7753 | ||
7754 | dump_relocations (filedata, rel_offset, rel_size, | |
7755 | symtab, nsyms, strtab, strtablen, | |
7756 | is_rela, | |
7757 | symsec->sh_type == SHT_DYNSYM); | |
7758 | free (strtab); | |
7759 | free (symtab); | |
7760 | } | |
7761 | else | |
7762 | dump_relocations (filedata, rel_offset, rel_size, | |
7763 | NULL, 0, NULL, 0, is_rela, | |
7764 | FALSE /* is_dynamic */); | |
7765 | ||
7766 | found = TRUE; | |
7767 | } | |
7768 | } | |
7769 | ||
7770 | if (! found) | |
7771 | { | |
7772 | /* Users sometimes forget the -D option, so try to be helpful. */ | |
7773 | for (i = 0; i < ARRAY_SIZE (dynamic_relocations); i++) | |
7774 | { | |
7775 | if (filedata->dynamic_info[dynamic_relocations [i].size]) | |
7776 | { | |
7777 | if (filedata->is_separate) | |
7778 | printf (_("\nThere are no static relocations in linked file '%s'."), | |
7779 | filedata->file_name); | |
7780 | else | |
7781 | printf (_("\nThere are no static relocations in this file.")); | |
7782 | printf (_("\nTo see the dynamic relocations add --use-dynamic to the command line.\n")); | |
7783 | ||
7784 | break; | |
7785 | } | |
7786 | } | |
7787 | if (i == ARRAY_SIZE (dynamic_relocations)) | |
7788 | { | |
7789 | if (filedata->is_separate) | |
7790 | printf (_("\nThere are no relocations in linked file '%s'.\n"), | |
7791 | filedata->file_name); | |
7792 | else | |
7793 | printf (_("\nThere are no relocations in this file.\n")); | |
7794 | } | |
7795 | } | |
7796 | } | |
7797 | ||
7798 | return TRUE; | |
7799 | } | |
7800 | ||
7801 | /* An absolute address consists of a section and an offset. If the | |
7802 | section is NULL, the offset itself is the address, otherwise, the | |
7803 | address equals to LOAD_ADDRESS(section) + offset. */ | |
7804 | ||
7805 | struct absaddr | |
7806 | { | |
7807 | unsigned short section; | |
7808 | bfd_vma offset; | |
7809 | }; | |
7810 | ||
7811 | /* Find the nearest symbol at or below ADDR. Returns the symbol | |
7812 | name, if found, and the offset from the symbol to ADDR. */ | |
7813 | ||
7814 | static void | |
7815 | find_symbol_for_address (Filedata * filedata, | |
7816 | Elf_Internal_Sym * symtab, | |
7817 | unsigned long nsyms, | |
7818 | const char * strtab, | |
7819 | unsigned long strtab_size, | |
7820 | struct absaddr addr, | |
7821 | const char ** symname, | |
7822 | bfd_vma * offset) | |
7823 | { | |
7824 | bfd_vma dist = 0x100000; | |
7825 | Elf_Internal_Sym * sym; | |
7826 | Elf_Internal_Sym * beg; | |
7827 | Elf_Internal_Sym * end; | |
7828 | Elf_Internal_Sym * best = NULL; | |
7829 | ||
7830 | REMOVE_ARCH_BITS (addr.offset); | |
7831 | beg = symtab; | |
7832 | end = symtab + nsyms; | |
7833 | ||
7834 | while (beg < end) | |
7835 | { | |
7836 | bfd_vma value; | |
7837 | ||
7838 | sym = beg + (end - beg) / 2; | |
7839 | ||
7840 | value = sym->st_value; | |
7841 | REMOVE_ARCH_BITS (value); | |
7842 | ||
7843 | if (sym->st_name != 0 | |
7844 | && (addr.section == SHN_UNDEF || addr.section == sym->st_shndx) | |
7845 | && addr.offset >= value | |
7846 | && addr.offset - value < dist) | |
7847 | { | |
7848 | best = sym; | |
7849 | dist = addr.offset - value; | |
7850 | if (!dist) | |
7851 | break; | |
7852 | } | |
7853 | ||
7854 | if (addr.offset < value) | |
7855 | end = sym; | |
7856 | else | |
7857 | beg = sym + 1; | |
7858 | } | |
7859 | ||
7860 | if (best) | |
7861 | { | |
7862 | *symname = (best->st_name >= strtab_size | |
7863 | ? _("<corrupt>") : strtab + best->st_name); | |
7864 | *offset = dist; | |
7865 | return; | |
7866 | } | |
7867 | ||
7868 | *symname = NULL; | |
7869 | *offset = addr.offset; | |
7870 | } | |
7871 | ||
7872 | static /* signed */ int | |
7873 | symcmp (const void *p, const void *q) | |
7874 | { | |
7875 | Elf_Internal_Sym *sp = (Elf_Internal_Sym *) p; | |
7876 | Elf_Internal_Sym *sq = (Elf_Internal_Sym *) q; | |
7877 | ||
7878 | return sp->st_value > sq->st_value ? 1 : (sp->st_value < sq->st_value ? -1 : 0); | |
7879 | } | |
7880 | ||
7881 | /* Process the unwind section. */ | |
7882 | ||
7883 | #include "unwind-ia64.h" | |
7884 | ||
7885 | struct ia64_unw_table_entry | |
7886 | { | |
7887 | struct absaddr start; | |
7888 | struct absaddr end; | |
7889 | struct absaddr info; | |
7890 | }; | |
7891 | ||
7892 | struct ia64_unw_aux_info | |
7893 | { | |
7894 | struct ia64_unw_table_entry * table; /* Unwind table. */ | |
7895 | unsigned long table_len; /* Length of unwind table. */ | |
7896 | unsigned char * info; /* Unwind info. */ | |
7897 | unsigned long info_size; /* Size of unwind info. */ | |
7898 | bfd_vma info_addr; /* Starting address of unwind info. */ | |
7899 | bfd_vma seg_base; /* Starting address of segment. */ | |
7900 | Elf_Internal_Sym * symtab; /* The symbol table. */ | |
7901 | unsigned long nsyms; /* Number of symbols. */ | |
7902 | Elf_Internal_Sym * funtab; /* Sorted table of STT_FUNC symbols. */ | |
7903 | unsigned long nfuns; /* Number of entries in funtab. */ | |
7904 | char * strtab; /* The string table. */ | |
7905 | unsigned long strtab_size; /* Size of string table. */ | |
7906 | }; | |
7907 | ||
7908 | static bfd_boolean | |
7909 | dump_ia64_unwind (Filedata * filedata, struct ia64_unw_aux_info * aux) | |
7910 | { | |
7911 | struct ia64_unw_table_entry * tp; | |
7912 | unsigned long j, nfuns; | |
7913 | int in_body; | |
7914 | bfd_boolean res = TRUE; | |
7915 | ||
7916 | aux->funtab = xmalloc (aux->nsyms * sizeof (Elf_Internal_Sym)); | |
7917 | for (nfuns = 0, j = 0; j < aux->nsyms; j++) | |
7918 | if (aux->symtab[j].st_value && ELF_ST_TYPE (aux->symtab[j].st_info) == STT_FUNC) | |
7919 | aux->funtab[nfuns++] = aux->symtab[j]; | |
7920 | aux->nfuns = nfuns; | |
7921 | qsort (aux->funtab, aux->nfuns, sizeof (Elf_Internal_Sym), symcmp); | |
7922 | ||
7923 | for (tp = aux->table; tp < aux->table + aux->table_len; ++tp) | |
7924 | { | |
7925 | bfd_vma stamp; | |
7926 | bfd_vma offset; | |
7927 | const unsigned char * dp; | |
7928 | const unsigned char * head; | |
7929 | const unsigned char * end; | |
7930 | const char * procname; | |
7931 | ||
7932 | find_symbol_for_address (filedata, aux->funtab, aux->nfuns, aux->strtab, | |
7933 | aux->strtab_size, tp->start, &procname, &offset); | |
7934 | ||
7935 | fputs ("\n<", stdout); | |
7936 | ||
7937 | if (procname) | |
7938 | { | |
7939 | fputs (procname, stdout); | |
7940 | ||
7941 | if (offset) | |
7942 | printf ("+%lx", (unsigned long) offset); | |
7943 | } | |
7944 | ||
7945 | fputs (">: [", stdout); | |
7946 | print_vma (tp->start.offset, PREFIX_HEX); | |
7947 | fputc ('-', stdout); | |
7948 | print_vma (tp->end.offset, PREFIX_HEX); | |
7949 | printf ("], info at +0x%lx\n", | |
7950 | (unsigned long) (tp->info.offset - aux->seg_base)); | |
7951 | ||
7952 | /* PR 17531: file: 86232b32. */ | |
7953 | if (aux->info == NULL) | |
7954 | continue; | |
7955 | ||
7956 | offset = tp->info.offset; | |
7957 | if (tp->info.section) | |
7958 | { | |
7959 | if (tp->info.section >= filedata->file_header.e_shnum) | |
7960 | { | |
7961 | warn (_("Invalid section %u in table entry %ld\n"), | |
7962 | tp->info.section, (long) (tp - aux->table)); | |
7963 | res = FALSE; | |
7964 | continue; | |
7965 | } | |
7966 | offset += filedata->section_headers[tp->info.section].sh_addr; | |
7967 | } | |
7968 | offset -= aux->info_addr; | |
7969 | /* PR 17531: file: 0997b4d1. */ | |
7970 | if (offset >= aux->info_size | |
7971 | || aux->info_size - offset < 8) | |
7972 | { | |
7973 | warn (_("Invalid offset %lx in table entry %ld\n"), | |
7974 | (long) tp->info.offset, (long) (tp - aux->table)); | |
7975 | res = FALSE; | |
7976 | continue; | |
7977 | } | |
7978 | ||
7979 | head = aux->info + offset; | |
7980 | stamp = byte_get ((unsigned char *) head, sizeof (stamp)); | |
7981 | ||
7982 | printf (" v%u, flags=0x%lx (%s%s), len=%lu bytes\n", | |
7983 | (unsigned) UNW_VER (stamp), | |
7984 | (unsigned long) ((stamp & UNW_FLAG_MASK) >> 32), | |
7985 | UNW_FLAG_EHANDLER (stamp) ? " ehandler" : "", | |
7986 | UNW_FLAG_UHANDLER (stamp) ? " uhandler" : "", | |
7987 | (unsigned long) (eh_addr_size * UNW_LENGTH (stamp))); | |
7988 | ||
7989 | if (UNW_VER (stamp) != 1) | |
7990 | { | |
7991 | printf (_("\tUnknown version.\n")); | |
7992 | continue; | |
7993 | } | |
7994 | ||
7995 | in_body = 0; | |
7996 | end = head + 8 + eh_addr_size * UNW_LENGTH (stamp); | |
7997 | /* PR 17531: file: 16ceda89. */ | |
7998 | if (end > aux->info + aux->info_size) | |
7999 | end = aux->info + aux->info_size; | |
8000 | for (dp = head + 8; dp < end;) | |
8001 | dp = unw_decode (dp, in_body, & in_body, end); | |
8002 | } | |
8003 | ||
8004 | free (aux->funtab); | |
8005 | ||
8006 | return res; | |
8007 | } | |
8008 | ||
8009 | static bfd_boolean | |
8010 | slurp_ia64_unwind_table (Filedata * filedata, | |
8011 | struct ia64_unw_aux_info * aux, | |
8012 | Elf_Internal_Shdr * sec) | |
8013 | { | |
8014 | unsigned long size, nrelas, i; | |
8015 | Elf_Internal_Phdr * seg; | |
8016 | struct ia64_unw_table_entry * tep; | |
8017 | Elf_Internal_Shdr * relsec; | |
8018 | Elf_Internal_Rela * rela; | |
8019 | Elf_Internal_Rela * rp; | |
8020 | unsigned char * table; | |
8021 | unsigned char * tp; | |
8022 | Elf_Internal_Sym * sym; | |
8023 | const char * relname; | |
8024 | ||
8025 | aux->table_len = 0; | |
8026 | ||
8027 | /* First, find the starting address of the segment that includes | |
8028 | this section: */ | |
8029 | ||
8030 | if (filedata->file_header.e_phnum) | |
8031 | { | |
8032 | if (! get_program_headers (filedata)) | |
8033 | return FALSE; | |
8034 | ||
8035 | for (seg = filedata->program_headers; | |
8036 | seg < filedata->program_headers + filedata->file_header.e_phnum; | |
8037 | ++seg) | |
8038 | { | |
8039 | if (seg->p_type != PT_LOAD) | |
8040 | continue; | |
8041 | ||
8042 | if (sec->sh_addr >= seg->p_vaddr | |
8043 | && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz)) | |
8044 | { | |
8045 | aux->seg_base = seg->p_vaddr; | |
8046 | break; | |
8047 | } | |
8048 | } | |
8049 | } | |
8050 | ||
8051 | /* Second, build the unwind table from the contents of the unwind section: */ | |
8052 | size = sec->sh_size; | |
8053 | table = (unsigned char *) get_data (NULL, filedata, sec->sh_offset, 1, size, | |
8054 | _("unwind table")); | |
8055 | if (!table) | |
8056 | return FALSE; | |
8057 | ||
8058 | aux->table_len = size / (3 * eh_addr_size); | |
8059 | aux->table = (struct ia64_unw_table_entry *) | |
8060 | xcmalloc (aux->table_len, sizeof (aux->table[0])); | |
8061 | tep = aux->table; | |
8062 | ||
8063 | for (tp = table; tp <= table + size - (3 * eh_addr_size); ++tep) | |
8064 | { | |
8065 | tep->start.section = SHN_UNDEF; | |
8066 | tep->end.section = SHN_UNDEF; | |
8067 | tep->info.section = SHN_UNDEF; | |
8068 | tep->start.offset = byte_get (tp, eh_addr_size); tp += eh_addr_size; | |
8069 | tep->end.offset = byte_get (tp, eh_addr_size); tp += eh_addr_size; | |
8070 | tep->info.offset = byte_get (tp, eh_addr_size); tp += eh_addr_size; | |
8071 | tep->start.offset += aux->seg_base; | |
8072 | tep->end.offset += aux->seg_base; | |
8073 | tep->info.offset += aux->seg_base; | |
8074 | } | |
8075 | free (table); | |
8076 | ||
8077 | /* Third, apply any relocations to the unwind table: */ | |
8078 | for (relsec = filedata->section_headers; | |
8079 | relsec < filedata->section_headers + filedata->file_header.e_shnum; | |
8080 | ++relsec) | |
8081 | { | |
8082 | if (relsec->sh_type != SHT_RELA | |
8083 | || relsec->sh_info >= filedata->file_header.e_shnum | |
8084 | || filedata->section_headers + relsec->sh_info != sec) | |
8085 | continue; | |
8086 | ||
8087 | if (!slurp_rela_relocs (filedata, relsec->sh_offset, relsec->sh_size, | |
8088 | & rela, & nrelas)) | |
8089 | { | |
8090 | free (aux->table); | |
8091 | aux->table = NULL; | |
8092 | aux->table_len = 0; | |
8093 | return FALSE; | |
8094 | } | |
8095 | ||
8096 | for (rp = rela; rp < rela + nrelas; ++rp) | |
8097 | { | |
8098 | unsigned int sym_ndx; | |
8099 | unsigned int r_type = get_reloc_type (filedata, rp->r_info); | |
8100 | relname = elf_ia64_reloc_type (r_type); | |
8101 | ||
8102 | /* PR 17531: file: 9fa67536. */ | |
8103 | if (relname == NULL) | |
8104 | { | |
8105 | warn (_("Skipping unknown relocation type: %u\n"), r_type); | |
8106 | continue; | |
8107 | } | |
8108 | ||
8109 | if (! const_strneq (relname, "R_IA64_SEGREL")) | |
8110 | { | |
8111 | warn (_("Skipping unexpected relocation type: %s\n"), relname); | |
8112 | continue; | |
8113 | } | |
8114 | ||
8115 | i = rp->r_offset / (3 * eh_addr_size); | |
8116 | ||
8117 | /* PR 17531: file: 5bc8d9bf. */ | |
8118 | if (i >= aux->table_len) | |
8119 | { | |
8120 | warn (_("Skipping reloc with overlarge offset: %lx\n"), i); | |
8121 | continue; | |
8122 | } | |
8123 | ||
8124 | sym_ndx = get_reloc_symindex (rp->r_info); | |
8125 | if (sym_ndx >= aux->nsyms) | |
8126 | { | |
8127 | warn (_("Skipping reloc with invalid symbol index: %u\n"), | |
8128 | sym_ndx); | |
8129 | continue; | |
8130 | } | |
8131 | sym = aux->symtab + sym_ndx; | |
8132 | ||
8133 | switch (rp->r_offset / eh_addr_size % 3) | |
8134 | { | |
8135 | case 0: | |
8136 | aux->table[i].start.section = sym->st_shndx; | |
8137 | aux->table[i].start.offset = rp->r_addend + sym->st_value; | |
8138 | break; | |
8139 | case 1: | |
8140 | aux->table[i].end.section = sym->st_shndx; | |
8141 | aux->table[i].end.offset = rp->r_addend + sym->st_value; | |
8142 | break; | |
8143 | case 2: | |
8144 | aux->table[i].info.section = sym->st_shndx; | |
8145 | aux->table[i].info.offset = rp->r_addend + sym->st_value; | |
8146 | break; | |
8147 | default: | |
8148 | break; | |
8149 | } | |
8150 | } | |
8151 | ||
8152 | free (rela); | |
8153 | } | |
8154 | ||
8155 | return TRUE; | |
8156 | } | |
8157 | ||
8158 | static bfd_boolean | |
8159 | ia64_process_unwind (Filedata * filedata) | |
8160 | { | |
8161 | Elf_Internal_Shdr * sec; | |
8162 | Elf_Internal_Shdr * unwsec = NULL; | |
8163 | unsigned long i, unwcount = 0, unwstart = 0; | |
8164 | struct ia64_unw_aux_info aux; | |
8165 | bfd_boolean res = TRUE; | |
8166 | ||
8167 | memset (& aux, 0, sizeof (aux)); | |
8168 | ||
8169 | for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec) | |
8170 | { | |
8171 | if (sec->sh_type == SHT_SYMTAB) | |
8172 | { | |
8173 | if (aux.symtab) | |
8174 | { | |
8175 | error (_("Multiple symbol tables encountered\n")); | |
8176 | free (aux.symtab); | |
8177 | aux.symtab = NULL; | |
8178 | free (aux.strtab); | |
8179 | aux.strtab = NULL; | |
8180 | } | |
8181 | if (!get_symtab (filedata, sec, &aux.symtab, &aux.nsyms, | |
8182 | &aux.strtab, &aux.strtab_size)) | |
8183 | return FALSE; | |
8184 | } | |
8185 | else if (sec->sh_type == SHT_IA_64_UNWIND) | |
8186 | unwcount++; | |
8187 | } | |
8188 | ||
8189 | if (!unwcount) | |
8190 | printf (_("\nThere are no unwind sections in this file.\n")); | |
8191 | ||
8192 | while (unwcount-- > 0) | |
8193 | { | |
8194 | char * suffix; | |
8195 | size_t len, len2; | |
8196 | ||
8197 | for (i = unwstart, sec = filedata->section_headers + unwstart, unwsec = NULL; | |
8198 | i < filedata->file_header.e_shnum; ++i, ++sec) | |
8199 | if (sec->sh_type == SHT_IA_64_UNWIND) | |
8200 | { | |
8201 | unwsec = sec; | |
8202 | break; | |
8203 | } | |
8204 | /* We have already counted the number of SHT_IA64_UNWIND | |
8205 | sections so the loop above should never fail. */ | |
8206 | assert (unwsec != NULL); | |
8207 | ||
8208 | unwstart = i + 1; | |
8209 | len = sizeof (ELF_STRING_ia64_unwind_once) - 1; | |
8210 | ||
8211 | if ((unwsec->sh_flags & SHF_GROUP) != 0) | |
8212 | { | |
8213 | /* We need to find which section group it is in. */ | |
8214 | struct group_list * g; | |
8215 | ||
8216 | if (filedata->section_headers_groups == NULL | |
8217 | || filedata->section_headers_groups[i] == NULL) | |
8218 | i = filedata->file_header.e_shnum; | |
8219 | else | |
8220 | { | |
8221 | g = filedata->section_headers_groups[i]->root; | |
8222 | ||
8223 | for (; g != NULL; g = g->next) | |
8224 | { | |
8225 | sec = filedata->section_headers + g->section_index; | |
8226 | ||
8227 | if (SECTION_NAME_VALID (sec) | |
8228 | && streq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info)) | |
8229 | break; | |
8230 | } | |
8231 | ||
8232 | if (g == NULL) | |
8233 | i = filedata->file_header.e_shnum; | |
8234 | } | |
8235 | } | |
8236 | else if (SECTION_NAME_VALID (unwsec) | |
8237 | && strneq (SECTION_NAME (unwsec), | |
8238 | ELF_STRING_ia64_unwind_once, len)) | |
8239 | { | |
8240 | /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO. */ | |
8241 | len2 = sizeof (ELF_STRING_ia64_unwind_info_once) - 1; | |
8242 | suffix = SECTION_NAME (unwsec) + len; | |
8243 | for (i = 0, sec = filedata->section_headers; | |
8244 | i < filedata->file_header.e_shnum; | |
8245 | ++i, ++sec) | |
8246 | if (SECTION_NAME_VALID (sec) | |
8247 | && strneq (SECTION_NAME (sec), | |
8248 | ELF_STRING_ia64_unwind_info_once, len2) | |
8249 | && streq (SECTION_NAME (sec) + len2, suffix)) | |
8250 | break; | |
8251 | } | |
8252 | else | |
8253 | { | |
8254 | /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO | |
8255 | .IA_64.unwind or BAR -> .IA_64.unwind_info. */ | |
8256 | len = sizeof (ELF_STRING_ia64_unwind) - 1; | |
8257 | len2 = sizeof (ELF_STRING_ia64_unwind_info) - 1; | |
8258 | suffix = ""; | |
8259 | if (SECTION_NAME_VALID (unwsec) | |
8260 | && strneq (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind, len)) | |
8261 | suffix = SECTION_NAME (unwsec) + len; | |
8262 | for (i = 0, sec = filedata->section_headers; | |
8263 | i < filedata->file_header.e_shnum; | |
8264 | ++i, ++sec) | |
8265 | if (SECTION_NAME_VALID (sec) | |
8266 | && strneq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info, len2) | |
8267 | && streq (SECTION_NAME (sec) + len2, suffix)) | |
8268 | break; | |
8269 | } | |
8270 | ||
8271 | if (i == filedata->file_header.e_shnum) | |
8272 | { | |
8273 | printf (_("\nCould not find unwind info section for ")); | |
8274 | ||
8275 | if (filedata->string_table == NULL) | |
8276 | printf ("%d", unwsec->sh_name); | |
8277 | else | |
8278 | printf ("'%s'", printable_section_name (filedata, unwsec)); | |
8279 | } | |
8280 | else | |
8281 | { | |
8282 | aux.info_addr = sec->sh_addr; | |
8283 | aux.info = (unsigned char *) get_data (NULL, filedata, sec->sh_offset, 1, | |
8284 | sec->sh_size, | |
8285 | _("unwind info")); | |
8286 | aux.info_size = aux.info == NULL ? 0 : sec->sh_size; | |
8287 | ||
8288 | printf (_("\nUnwind section ")); | |
8289 | ||
8290 | if (filedata->string_table == NULL) | |
8291 | printf ("%d", unwsec->sh_name); | |
8292 | else | |
8293 | printf ("'%s'", printable_section_name (filedata, unwsec)); | |
8294 | ||
8295 | printf (_(" at offset 0x%lx contains %lu entries:\n"), | |
8296 | (unsigned long) unwsec->sh_offset, | |
8297 | (unsigned long) (unwsec->sh_size / (3 * eh_addr_size))); | |
8298 | ||
8299 | if (slurp_ia64_unwind_table (filedata, & aux, unwsec) | |
8300 | && aux.table_len > 0) | |
8301 | dump_ia64_unwind (filedata, & aux); | |
8302 | ||
8303 | free ((char *) aux.table); | |
8304 | free ((char *) aux.info); | |
8305 | aux.table = NULL; | |
8306 | aux.info = NULL; | |
8307 | } | |
8308 | } | |
8309 | ||
8310 | free (aux.symtab); | |
8311 | free ((char *) aux.strtab); | |
8312 | ||
8313 | return res; | |
8314 | } | |
8315 | ||
8316 | struct hppa_unw_table_entry | |
8317 | { | |
8318 | struct absaddr start; | |
8319 | struct absaddr end; | |
8320 | unsigned int Cannot_unwind:1; /* 0 */ | |
8321 | unsigned int Millicode:1; /* 1 */ | |
8322 | unsigned int Millicode_save_sr0:1; /* 2 */ | |
8323 | unsigned int Region_description:2; /* 3..4 */ | |
8324 | unsigned int reserved1:1; /* 5 */ | |
8325 | unsigned int Entry_SR:1; /* 6 */ | |
8326 | unsigned int Entry_FR:4; /* Number saved 7..10 */ | |
8327 | unsigned int Entry_GR:5; /* Number saved 11..15 */ | |
8328 | unsigned int Args_stored:1; /* 16 */ | |
8329 | unsigned int Variable_Frame:1; /* 17 */ | |
8330 | unsigned int Separate_Package_Body:1; /* 18 */ | |
8331 | unsigned int Frame_Extension_Millicode:1; /* 19 */ | |
8332 | unsigned int Stack_Overflow_Check:1; /* 20 */ | |
8333 | unsigned int Two_Instruction_SP_Increment:1; /* 21 */ | |
8334 | unsigned int Ada_Region:1; /* 22 */ | |
8335 | unsigned int cxx_info:1; /* 23 */ | |
8336 | unsigned int cxx_try_catch:1; /* 24 */ | |
8337 | unsigned int sched_entry_seq:1; /* 25 */ | |
8338 | unsigned int reserved2:1; /* 26 */ | |
8339 | unsigned int Save_SP:1; /* 27 */ | |
8340 | unsigned int Save_RP:1; /* 28 */ | |
8341 | unsigned int Save_MRP_in_frame:1; /* 29 */ | |
8342 | unsigned int extn_ptr_defined:1; /* 30 */ | |
8343 | unsigned int Cleanup_defined:1; /* 31 */ | |
8344 | ||
8345 | unsigned int MPE_XL_interrupt_marker:1; /* 0 */ | |
8346 | unsigned int HP_UX_interrupt_marker:1; /* 1 */ | |
8347 | unsigned int Large_frame:1; /* 2 */ | |
8348 | unsigned int Pseudo_SP_Set:1; /* 3 */ | |
8349 | unsigned int reserved4:1; /* 4 */ | |
8350 | unsigned int Total_frame_size:27; /* 5..31 */ | |
8351 | }; | |
8352 | ||
8353 | struct hppa_unw_aux_info | |
8354 | { | |
8355 | struct hppa_unw_table_entry * table; /* Unwind table. */ | |
8356 | unsigned long table_len; /* Length of unwind table. */ | |
8357 | bfd_vma seg_base; /* Starting address of segment. */ | |
8358 | Elf_Internal_Sym * symtab; /* The symbol table. */ | |
8359 | unsigned long nsyms; /* Number of symbols. */ | |
8360 | Elf_Internal_Sym * funtab; /* Sorted table of STT_FUNC symbols. */ | |
8361 | unsigned long nfuns; /* Number of entries in funtab. */ | |
8362 | char * strtab; /* The string table. */ | |
8363 | unsigned long strtab_size; /* Size of string table. */ | |
8364 | }; | |
8365 | ||
8366 | static bfd_boolean | |
8367 | dump_hppa_unwind (Filedata * filedata, struct hppa_unw_aux_info * aux) | |
8368 | { | |
8369 | struct hppa_unw_table_entry * tp; | |
8370 | unsigned long j, nfuns; | |
8371 | bfd_boolean res = TRUE; | |
8372 | ||
8373 | aux->funtab = xmalloc (aux->nsyms * sizeof (Elf_Internal_Sym)); | |
8374 | for (nfuns = 0, j = 0; j < aux->nsyms; j++) | |
8375 | if (aux->symtab[j].st_value && ELF_ST_TYPE (aux->symtab[j].st_info) == STT_FUNC) | |
8376 | aux->funtab[nfuns++] = aux->symtab[j]; | |
8377 | aux->nfuns = nfuns; | |
8378 | qsort (aux->funtab, aux->nfuns, sizeof (Elf_Internal_Sym), symcmp); | |
8379 | ||
8380 | for (tp = aux->table; tp < aux->table + aux->table_len; ++tp) | |
8381 | { | |
8382 | bfd_vma offset; | |
8383 | const char * procname; | |
8384 | ||
8385 | find_symbol_for_address (filedata, aux->funtab, aux->nfuns, aux->strtab, | |
8386 | aux->strtab_size, tp->start, &procname, | |
8387 | &offset); | |
8388 | ||
8389 | fputs ("\n<", stdout); | |
8390 | ||
8391 | if (procname) | |
8392 | { | |
8393 | fputs (procname, stdout); | |
8394 | ||
8395 | if (offset) | |
8396 | printf ("+%lx", (unsigned long) offset); | |
8397 | } | |
8398 | ||
8399 | fputs (">: [", stdout); | |
8400 | print_vma (tp->start.offset, PREFIX_HEX); | |
8401 | fputc ('-', stdout); | |
8402 | print_vma (tp->end.offset, PREFIX_HEX); | |
8403 | printf ("]\n\t"); | |
8404 | ||
8405 | #define PF(_m) if (tp->_m) printf (#_m " "); | |
8406 | #define PV(_m) if (tp->_m) printf (#_m "=%d ", tp->_m); | |
8407 | PF(Cannot_unwind); | |
8408 | PF(Millicode); | |
8409 | PF(Millicode_save_sr0); | |
8410 | /* PV(Region_description); */ | |
8411 | PF(Entry_SR); | |
8412 | PV(Entry_FR); | |
8413 | PV(Entry_GR); | |
8414 | PF(Args_stored); | |
8415 | PF(Variable_Frame); | |
8416 | PF(Separate_Package_Body); | |
8417 | PF(Frame_Extension_Millicode); | |
8418 | PF(Stack_Overflow_Check); | |
8419 | PF(Two_Instruction_SP_Increment); | |
8420 | PF(Ada_Region); | |
8421 | PF(cxx_info); | |
8422 | PF(cxx_try_catch); | |
8423 | PF(sched_entry_seq); | |
8424 | PF(Save_SP); | |
8425 | PF(Save_RP); | |
8426 | PF(Save_MRP_in_frame); | |
8427 | PF(extn_ptr_defined); | |
8428 | PF(Cleanup_defined); | |
8429 | PF(MPE_XL_interrupt_marker); | |
8430 | PF(HP_UX_interrupt_marker); | |
8431 | PF(Large_frame); | |
8432 | PF(Pseudo_SP_Set); | |
8433 | PV(Total_frame_size); | |
8434 | #undef PF | |
8435 | #undef PV | |
8436 | } | |
8437 | ||
8438 | printf ("\n"); | |
8439 | ||
8440 | free (aux->funtab); | |
8441 | ||
8442 | return res; | |
8443 | } | |
8444 | ||
8445 | static bfd_boolean | |
8446 | slurp_hppa_unwind_table (Filedata * filedata, | |
8447 | struct hppa_unw_aux_info * aux, | |
8448 | Elf_Internal_Shdr * sec) | |
8449 | { | |
8450 | unsigned long size, unw_ent_size, nentries, nrelas, i; | |
8451 | Elf_Internal_Phdr * seg; | |
8452 | struct hppa_unw_table_entry * tep; | |
8453 | Elf_Internal_Shdr * relsec; | |
8454 | Elf_Internal_Rela * rela; | |
8455 | Elf_Internal_Rela * rp; | |
8456 | unsigned char * table; | |
8457 | unsigned char * tp; | |
8458 | Elf_Internal_Sym * sym; | |
8459 | const char * relname; | |
8460 | ||
8461 | /* First, find the starting address of the segment that includes | |
8462 | this section. */ | |
8463 | if (filedata->file_header.e_phnum) | |
8464 | { | |
8465 | if (! get_program_headers (filedata)) | |
8466 | return FALSE; | |
8467 | ||
8468 | for (seg = filedata->program_headers; | |
8469 | seg < filedata->program_headers + filedata->file_header.e_phnum; | |
8470 | ++seg) | |
8471 | { | |
8472 | if (seg->p_type != PT_LOAD) | |
8473 | continue; | |
8474 | ||
8475 | if (sec->sh_addr >= seg->p_vaddr | |
8476 | && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz)) | |
8477 | { | |
8478 | aux->seg_base = seg->p_vaddr; | |
8479 | break; | |
8480 | } | |
8481 | } | |
8482 | } | |
8483 | ||
8484 | /* Second, build the unwind table from the contents of the unwind | |
8485 | section. */ | |
8486 | size = sec->sh_size; | |
8487 | table = (unsigned char *) get_data (NULL, filedata, sec->sh_offset, 1, size, | |
8488 | _("unwind table")); | |
8489 | if (!table) | |
8490 | return FALSE; | |
8491 | ||
8492 | unw_ent_size = 16; | |
8493 | nentries = size / unw_ent_size; | |
8494 | size = unw_ent_size * nentries; | |
8495 | ||
8496 | aux->table_len = nentries; | |
8497 | tep = aux->table = (struct hppa_unw_table_entry *) | |
8498 | xcmalloc (nentries, sizeof (aux->table[0])); | |
8499 | ||
8500 | for (tp = table; tp < table + size; tp += unw_ent_size, ++tep) | |
8501 | { | |
8502 | unsigned int tmp1, tmp2; | |
8503 | ||
8504 | tep->start.section = SHN_UNDEF; | |
8505 | tep->end.section = SHN_UNDEF; | |
8506 | ||
8507 | tep->start.offset = byte_get ((unsigned char *) tp + 0, 4); | |
8508 | tep->end.offset = byte_get ((unsigned char *) tp + 4, 4); | |
8509 | tmp1 = byte_get ((unsigned char *) tp + 8, 4); | |
8510 | tmp2 = byte_get ((unsigned char *) tp + 12, 4); | |
8511 | ||
8512 | tep->start.offset += aux->seg_base; | |
8513 | tep->end.offset += aux->seg_base; | |
8514 | ||
8515 | tep->Cannot_unwind = (tmp1 >> 31) & 0x1; | |
8516 | tep->Millicode = (tmp1 >> 30) & 0x1; | |
8517 | tep->Millicode_save_sr0 = (tmp1 >> 29) & 0x1; | |
8518 | tep->Region_description = (tmp1 >> 27) & 0x3; | |
8519 | tep->reserved1 = (tmp1 >> 26) & 0x1; | |
8520 | tep->Entry_SR = (tmp1 >> 25) & 0x1; | |
8521 | tep->Entry_FR = (tmp1 >> 21) & 0xf; | |
8522 | tep->Entry_GR = (tmp1 >> 16) & 0x1f; | |
8523 | tep->Args_stored = (tmp1 >> 15) & 0x1; | |
8524 | tep->Variable_Frame = (tmp1 >> 14) & 0x1; | |
8525 | tep->Separate_Package_Body = (tmp1 >> 13) & 0x1; | |
8526 | tep->Frame_Extension_Millicode = (tmp1 >> 12) & 0x1; | |
8527 | tep->Stack_Overflow_Check = (tmp1 >> 11) & 0x1; | |
8528 | tep->Two_Instruction_SP_Increment = (tmp1 >> 10) & 0x1; | |
8529 | tep->Ada_Region = (tmp1 >> 9) & 0x1; | |
8530 | tep->cxx_info = (tmp1 >> 8) & 0x1; | |
8531 | tep->cxx_try_catch = (tmp1 >> 7) & 0x1; | |
8532 | tep->sched_entry_seq = (tmp1 >> 6) & 0x1; | |
8533 | tep->reserved2 = (tmp1 >> 5) & 0x1; | |
8534 | tep->Save_SP = (tmp1 >> 4) & 0x1; | |
8535 | tep->Save_RP = (tmp1 >> 3) & 0x1; | |
8536 | tep->Save_MRP_in_frame = (tmp1 >> 2) & 0x1; | |
8537 | tep->extn_ptr_defined = (tmp1 >> 1) & 0x1; | |
8538 | tep->Cleanup_defined = tmp1 & 0x1; | |
8539 | ||
8540 | tep->MPE_XL_interrupt_marker = (tmp2 >> 31) & 0x1; | |
8541 | tep->HP_UX_interrupt_marker = (tmp2 >> 30) & 0x1; | |
8542 | tep->Large_frame = (tmp2 >> 29) & 0x1; | |
8543 | tep->Pseudo_SP_Set = (tmp2 >> 28) & 0x1; | |
8544 | tep->reserved4 = (tmp2 >> 27) & 0x1; | |
8545 | tep->Total_frame_size = tmp2 & 0x7ffffff; | |
8546 | } | |
8547 | free (table); | |
8548 | ||
8549 | /* Third, apply any relocations to the unwind table. */ | |
8550 | for (relsec = filedata->section_headers; | |
8551 | relsec < filedata->section_headers + filedata->file_header.e_shnum; | |
8552 | ++relsec) | |
8553 | { | |
8554 | if (relsec->sh_type != SHT_RELA | |
8555 | || relsec->sh_info >= filedata->file_header.e_shnum | |
8556 | || filedata->section_headers + relsec->sh_info != sec) | |
8557 | continue; | |
8558 | ||
8559 | if (!slurp_rela_relocs (filedata, relsec->sh_offset, relsec->sh_size, | |
8560 | & rela, & nrelas)) | |
8561 | return FALSE; | |
8562 | ||
8563 | for (rp = rela; rp < rela + nrelas; ++rp) | |
8564 | { | |
8565 | unsigned int sym_ndx; | |
8566 | unsigned int r_type = get_reloc_type (filedata, rp->r_info); | |
8567 | relname = elf_hppa_reloc_type (r_type); | |
8568 | ||
8569 | if (relname == NULL) | |
8570 | { | |
8571 | warn (_("Skipping unknown relocation type: %u\n"), r_type); | |
8572 | continue; | |
8573 | } | |
8574 | ||
8575 | /* R_PARISC_SEGREL32 or R_PARISC_SEGREL64. */ | |
8576 | if (! const_strneq (relname, "R_PARISC_SEGREL")) | |
8577 | { | |
8578 | warn (_("Skipping unexpected relocation type: %s\n"), relname); | |
8579 | continue; | |
8580 | } | |
8581 | ||
8582 | i = rp->r_offset / unw_ent_size; | |
8583 | if (i >= aux->table_len) | |
8584 | { | |
8585 | warn (_("Skipping reloc with overlarge offset: %lx\n"), i); | |
8586 | continue; | |
8587 | } | |
8588 | ||
8589 | sym_ndx = get_reloc_symindex (rp->r_info); | |
8590 | if (sym_ndx >= aux->nsyms) | |
8591 | { | |
8592 | warn (_("Skipping reloc with invalid symbol index: %u\n"), | |
8593 | sym_ndx); | |
8594 | continue; | |
8595 | } | |
8596 | sym = aux->symtab + sym_ndx; | |
8597 | ||
8598 | switch ((rp->r_offset % unw_ent_size) / 4) | |
8599 | { | |
8600 | case 0: | |
8601 | aux->table[i].start.section = sym->st_shndx; | |
8602 | aux->table[i].start.offset = sym->st_value + rp->r_addend; | |
8603 | break; | |
8604 | case 1: | |
8605 | aux->table[i].end.section = sym->st_shndx; | |
8606 | aux->table[i].end.offset = sym->st_value + rp->r_addend; | |
8607 | break; | |
8608 | default: | |
8609 | break; | |
8610 | } | |
8611 | } | |
8612 | ||
8613 | free (rela); | |
8614 | } | |
8615 | ||
8616 | return TRUE; | |
8617 | } | |
8618 | ||
8619 | static bfd_boolean | |
8620 | hppa_process_unwind (Filedata * filedata) | |
8621 | { | |
8622 | struct hppa_unw_aux_info aux; | |
8623 | Elf_Internal_Shdr * unwsec = NULL; | |
8624 | Elf_Internal_Shdr * sec; | |
8625 | unsigned long i; | |
8626 | bfd_boolean res = TRUE; | |
8627 | ||
8628 | if (filedata->string_table == NULL) | |
8629 | return FALSE; | |
8630 | ||
8631 | memset (& aux, 0, sizeof (aux)); | |
8632 | ||
8633 | for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec) | |
8634 | { | |
8635 | if (sec->sh_type == SHT_SYMTAB) | |
8636 | { | |
8637 | if (aux.symtab) | |
8638 | { | |
8639 | error (_("Multiple symbol tables encountered\n")); | |
8640 | free (aux.symtab); | |
8641 | aux.symtab = NULL; | |
8642 | free (aux.strtab); | |
8643 | aux.strtab = NULL; | |
8644 | } | |
8645 | if (!get_symtab (filedata, sec, &aux.symtab, &aux.nsyms, | |
8646 | &aux.strtab, &aux.strtab_size)) | |
8647 | return FALSE; | |
8648 | } | |
8649 | else if (SECTION_NAME_VALID (sec) | |
8650 | && streq (SECTION_NAME (sec), ".PARISC.unwind")) | |
8651 | unwsec = sec; | |
8652 | } | |
8653 | ||
8654 | if (!unwsec) | |
8655 | printf (_("\nThere are no unwind sections in this file.\n")); | |
8656 | ||
8657 | for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec) | |
8658 | { | |
8659 | if (SECTION_NAME_VALID (sec) | |
8660 | && streq (SECTION_NAME (sec), ".PARISC.unwind")) | |
8661 | { | |
8662 | unsigned long num_unwind = sec->sh_size / 16; | |
8663 | ||
8664 | printf (ngettext ("\nUnwind section '%s' at offset 0x%lx " | |
8665 | "contains %lu entry:\n", | |
8666 | "\nUnwind section '%s' at offset 0x%lx " | |
8667 | "contains %lu entries:\n", | |
8668 | num_unwind), | |
8669 | printable_section_name (filedata, sec), | |
8670 | (unsigned long) sec->sh_offset, | |
8671 | num_unwind); | |
8672 | ||
8673 | if (! slurp_hppa_unwind_table (filedata, &aux, sec)) | |
8674 | res = FALSE; | |
8675 | ||
8676 | if (res && aux.table_len > 0) | |
8677 | { | |
8678 | if (! dump_hppa_unwind (filedata, &aux)) | |
8679 | res = FALSE; | |
8680 | } | |
8681 | ||
8682 | free ((char *) aux.table); | |
8683 | aux.table = NULL; | |
8684 | } | |
8685 | } | |
8686 | ||
8687 | free (aux.symtab); | |
8688 | free ((char *) aux.strtab); | |
8689 | ||
8690 | return res; | |
8691 | } | |
8692 | ||
8693 | struct arm_section | |
8694 | { | |
8695 | unsigned char * data; /* The unwind data. */ | |
8696 | Elf_Internal_Shdr * sec; /* The cached unwind section header. */ | |
8697 | Elf_Internal_Rela * rela; /* The cached relocations for this section. */ | |
8698 | unsigned long nrelas; /* The number of relocations. */ | |
8699 | unsigned int rel_type; /* REL or RELA ? */ | |
8700 | Elf_Internal_Rela * next_rela; /* Cyclic pointer to the next reloc to process. */ | |
8701 | }; | |
8702 | ||
8703 | struct arm_unw_aux_info | |
8704 | { | |
8705 | Filedata * filedata; /* The file containing the unwind sections. */ | |
8706 | Elf_Internal_Sym * symtab; /* The file's symbol table. */ | |
8707 | unsigned long nsyms; /* Number of symbols. */ | |
8708 | Elf_Internal_Sym * funtab; /* Sorted table of STT_FUNC symbols. */ | |
8709 | unsigned long nfuns; /* Number of these symbols. */ | |
8710 | char * strtab; /* The file's string table. */ | |
8711 | unsigned long strtab_size; /* Size of string table. */ | |
8712 | }; | |
8713 | ||
8714 | static const char * | |
8715 | arm_print_vma_and_name (Filedata * filedata, | |
8716 | struct arm_unw_aux_info * aux, | |
8717 | bfd_vma fn, | |
8718 | struct absaddr addr) | |
8719 | { | |
8720 | const char *procname; | |
8721 | bfd_vma sym_offset; | |
8722 | ||
8723 | if (addr.section == SHN_UNDEF) | |
8724 | addr.offset = fn; | |
8725 | ||
8726 | find_symbol_for_address (filedata, aux->funtab, aux->nfuns, aux->strtab, | |
8727 | aux->strtab_size, addr, &procname, | |
8728 | &sym_offset); | |
8729 | ||
8730 | print_vma (fn, PREFIX_HEX); | |
8731 | ||
8732 | if (procname) | |
8733 | { | |
8734 | fputs (" <", stdout); | |
8735 | fputs (procname, stdout); | |
8736 | ||
8737 | if (sym_offset) | |
8738 | printf ("+0x%lx", (unsigned long) sym_offset); | |
8739 | fputc ('>', stdout); | |
8740 | } | |
8741 | ||
8742 | return procname; | |
8743 | } | |
8744 | ||
8745 | static void | |
8746 | arm_free_section (struct arm_section *arm_sec) | |
8747 | { | |
8748 | free (arm_sec->data); | |
8749 | free (arm_sec->rela); | |
8750 | } | |
8751 | ||
8752 | /* 1) If SEC does not match the one cached in ARM_SEC, then free the current | |
8753 | cached section and install SEC instead. | |
8754 | 2) Locate the 32-bit word at WORD_OFFSET in unwind section SEC | |
8755 | and return its valued in * WORDP, relocating if necessary. | |
8756 | 3) Update the NEXT_RELA field in ARM_SEC and store the section index and | |
8757 | relocation's offset in ADDR. | |
8758 | 4) If SYM_NAME is non-NULL and a relocation was applied, record the offset | |
8759 | into the string table of the symbol associated with the reloc. If no | |
8760 | reloc was applied store -1 there. | |
8761 | 5) Return TRUE upon success, FALSE otherwise. */ | |
8762 | ||
8763 | static bfd_boolean | |
8764 | get_unwind_section_word (Filedata * filedata, | |
8765 | struct arm_unw_aux_info * aux, | |
8766 | struct arm_section * arm_sec, | |
8767 | Elf_Internal_Shdr * sec, | |
8768 | bfd_vma word_offset, | |
8769 | unsigned int * wordp, | |
8770 | struct absaddr * addr, | |
8771 | bfd_vma * sym_name) | |
8772 | { | |
8773 | Elf_Internal_Rela *rp; | |
8774 | Elf_Internal_Sym *sym; | |
8775 | const char * relname; | |
8776 | unsigned int word; | |
8777 | bfd_boolean wrapped; | |
8778 | ||
8779 | if (sec == NULL || arm_sec == NULL) | |
8780 | return FALSE; | |
8781 | ||
8782 | addr->section = SHN_UNDEF; | |
8783 | addr->offset = 0; | |
8784 | ||
8785 | if (sym_name != NULL) | |
8786 | *sym_name = (bfd_vma) -1; | |
8787 | ||
8788 | /* If necessary, update the section cache. */ | |
8789 | if (sec != arm_sec->sec) | |
8790 | { | |
8791 | Elf_Internal_Shdr *relsec; | |
8792 | ||
8793 | arm_free_section (arm_sec); | |
8794 | ||
8795 | arm_sec->sec = sec; | |
8796 | arm_sec->data = get_data (NULL, aux->filedata, sec->sh_offset, 1, | |
8797 | sec->sh_size, _("unwind data")); | |
8798 | arm_sec->rela = NULL; | |
8799 | arm_sec->nrelas = 0; | |
8800 | ||
8801 | for (relsec = filedata->section_headers; | |
8802 | relsec < filedata->section_headers + filedata->file_header.e_shnum; | |
8803 | ++relsec) | |
8804 | { | |
8805 | if (relsec->sh_info >= filedata->file_header.e_shnum | |
8806 | || filedata->section_headers + relsec->sh_info != sec | |
8807 | /* PR 15745: Check the section type as well. */ | |
8808 | || (relsec->sh_type != SHT_REL | |
8809 | && relsec->sh_type != SHT_RELA)) | |
8810 | continue; | |
8811 | ||
8812 | arm_sec->rel_type = relsec->sh_type; | |
8813 | if (relsec->sh_type == SHT_REL) | |
8814 | { | |
8815 | if (!slurp_rel_relocs (aux->filedata, relsec->sh_offset, | |
8816 | relsec->sh_size, | |
8817 | & arm_sec->rela, & arm_sec->nrelas)) | |
8818 | return FALSE; | |
8819 | } | |
8820 | else /* relsec->sh_type == SHT_RELA */ | |
8821 | { | |
8822 | if (!slurp_rela_relocs (aux->filedata, relsec->sh_offset, | |
8823 | relsec->sh_size, | |
8824 | & arm_sec->rela, & arm_sec->nrelas)) | |
8825 | return FALSE; | |
8826 | } | |
8827 | break; | |
8828 | } | |
8829 | ||
8830 | arm_sec->next_rela = arm_sec->rela; | |
8831 | } | |
8832 | ||
8833 | /* If there is no unwind data we can do nothing. */ | |
8834 | if (arm_sec->data == NULL) | |
8835 | return FALSE; | |
8836 | ||
8837 | /* If the offset is invalid then fail. */ | |
8838 | if (/* PR 21343 *//* PR 18879 */ | |
8839 | sec->sh_size < 4 | |
8840 | || word_offset > (sec->sh_size - 4) | |
8841 | || ((bfd_signed_vma) word_offset) < 0) | |
8842 | return FALSE; | |
8843 | ||
8844 | /* Get the word at the required offset. */ | |
8845 | word = byte_get (arm_sec->data + word_offset, 4); | |
8846 | ||
8847 | /* PR 17531: file: id:000001,src:001266+003044,op:splice,rep:128. */ | |
8848 | if (arm_sec->rela == NULL) | |
8849 | { | |
8850 | * wordp = word; | |
8851 | return TRUE; | |
8852 | } | |
8853 | ||
8854 | /* Look through the relocs to find the one that applies to the provided offset. */ | |
8855 | wrapped = FALSE; | |
8856 | for (rp = arm_sec->next_rela; rp != arm_sec->rela + arm_sec->nrelas; rp++) | |
8857 | { | |
8858 | bfd_vma prelval, offset; | |
8859 | ||
8860 | if (rp->r_offset > word_offset && !wrapped) | |
8861 | { | |
8862 | rp = arm_sec->rela; | |
8863 | wrapped = TRUE; | |
8864 | } | |
8865 | if (rp->r_offset > word_offset) | |
8866 | break; | |
8867 | ||
8868 | if (rp->r_offset & 3) | |
8869 | { | |
8870 | warn (_("Skipping unexpected relocation at offset 0x%lx\n"), | |
8871 | (unsigned long) rp->r_offset); | |
8872 | continue; | |
8873 | } | |
8874 | ||
8875 | if (rp->r_offset < word_offset) | |
8876 | continue; | |
8877 | ||
8878 | /* PR 17531: file: 027-161405-0.004 */ | |
8879 | if (aux->symtab == NULL) | |
8880 | continue; | |
8881 | ||
8882 | if (arm_sec->rel_type == SHT_REL) | |
8883 | { | |
8884 | offset = word & 0x7fffffff; | |
8885 | if (offset & 0x40000000) | |
8886 | offset |= ~ (bfd_vma) 0x7fffffff; | |
8887 | } | |
8888 | else if (arm_sec->rel_type == SHT_RELA) | |
8889 | offset = rp->r_addend; | |
8890 | else | |
8891 | { | |
8892 | error (_("Unknown section relocation type %d encountered\n"), | |
8893 | arm_sec->rel_type); | |
8894 | break; | |
8895 | } | |
8896 | ||
8897 | /* PR 17531 file: 027-1241568-0.004. */ | |
8898 | if (ELF32_R_SYM (rp->r_info) >= aux->nsyms) | |
8899 | { | |
8900 | error (_("Bad symbol index in unwind relocation (%lu > %lu)\n"), | |
8901 | (unsigned long) ELF32_R_SYM (rp->r_info), aux->nsyms); | |
8902 | break; | |
8903 | } | |
8904 | ||
8905 | sym = aux->symtab + ELF32_R_SYM (rp->r_info); | |
8906 | offset += sym->st_value; | |
8907 | prelval = offset - (arm_sec->sec->sh_addr + rp->r_offset); | |
8908 | ||
8909 | /* Check that we are processing the expected reloc type. */ | |
8910 | if (filedata->file_header.e_machine == EM_ARM) | |
8911 | { | |
8912 | relname = elf_arm_reloc_type (ELF32_R_TYPE (rp->r_info)); | |
8913 | if (relname == NULL) | |
8914 | { | |
8915 | warn (_("Skipping unknown ARM relocation type: %d\n"), | |
8916 | (int) ELF32_R_TYPE (rp->r_info)); | |
8917 | continue; | |
8918 | } | |
8919 | ||
8920 | if (streq (relname, "R_ARM_NONE")) | |
8921 | continue; | |
8922 | ||
8923 | if (! streq (relname, "R_ARM_PREL31")) | |
8924 | { | |
8925 | warn (_("Skipping unexpected ARM relocation type %s\n"), relname); | |
8926 | continue; | |
8927 | } | |
8928 | } | |
8929 | else if (filedata->file_header.e_machine == EM_TI_C6000) | |
8930 | { | |
8931 | relname = elf_tic6x_reloc_type (ELF32_R_TYPE (rp->r_info)); | |
8932 | if (relname == NULL) | |
8933 | { | |
8934 | warn (_("Skipping unknown C6000 relocation type: %d\n"), | |
8935 | (int) ELF32_R_TYPE (rp->r_info)); | |
8936 | continue; | |
8937 | } | |
8938 | ||
8939 | if (streq (relname, "R_C6000_NONE")) | |
8940 | continue; | |
8941 | ||
8942 | if (! streq (relname, "R_C6000_PREL31")) | |
8943 | { | |
8944 | warn (_("Skipping unexpected C6000 relocation type %s\n"), relname); | |
8945 | continue; | |
8946 | } | |
8947 | ||
8948 | prelval >>= 1; | |
8949 | } | |
8950 | else | |
8951 | { | |
8952 | /* This function currently only supports ARM and TI unwinders. */ | |
8953 | warn (_("Only TI and ARM unwinders are currently supported\n")); | |
8954 | break; | |
8955 | } | |
8956 | ||
8957 | word = (word & ~ (bfd_vma) 0x7fffffff) | (prelval & 0x7fffffff); | |
8958 | addr->section = sym->st_shndx; | |
8959 | addr->offset = offset; | |
8960 | ||
8961 | if (sym_name) | |
8962 | * sym_name = sym->st_name; | |
8963 | break; | |
8964 | } | |
8965 | ||
8966 | *wordp = word; | |
8967 | arm_sec->next_rela = rp; | |
8968 | ||
8969 | return TRUE; | |
8970 | } | |
8971 | ||
8972 | static const char *tic6x_unwind_regnames[16] = | |
8973 | { | |
8974 | "A15", "B15", "B14", "B13", "B12", "B11", "B10", "B3", | |
8975 | "A14", "A13", "A12", "A11", "A10", | |
8976 | "[invalid reg 13]", "[invalid reg 14]", "[invalid reg 15]" | |
8977 | }; | |
8978 | ||
8979 | static void | |
8980 | decode_tic6x_unwind_regmask (unsigned int mask) | |
8981 | { | |
8982 | int i; | |
8983 | ||
8984 | for (i = 12; mask; mask >>= 1, i--) | |
8985 | { | |
8986 | if (mask & 1) | |
8987 | { | |
8988 | fputs (tic6x_unwind_regnames[i], stdout); | |
8989 | if (mask > 1) | |
8990 | fputs (", ", stdout); | |
8991 | } | |
8992 | } | |
8993 | } | |
8994 | ||
8995 | #define ADVANCE \ | |
8996 | if (remaining == 0 && more_words) \ | |
8997 | { \ | |
8998 | data_offset += 4; \ | |
8999 | if (! get_unwind_section_word (filedata, aux, data_arm_sec, data_sec, \ | |
9000 | data_offset, & word, & addr, NULL)) \ | |
9001 | return FALSE; \ | |
9002 | remaining = 4; \ | |
9003 | more_words--; \ | |
9004 | } \ | |
9005 | ||
9006 | #define GET_OP(OP) \ | |
9007 | ADVANCE; \ | |
9008 | if (remaining) \ | |
9009 | { \ | |
9010 | remaining--; \ | |
9011 | (OP) = word >> 24; \ | |
9012 | word <<= 8; \ | |
9013 | } \ | |
9014 | else \ | |
9015 | { \ | |
9016 | printf (_("[Truncated opcode]\n")); \ | |
9017 | return FALSE; \ | |
9018 | } \ | |
9019 | printf ("0x%02x ", OP) | |
9020 | ||
9021 | static bfd_boolean | |
9022 | decode_arm_unwind_bytecode (Filedata * filedata, | |
9023 | struct arm_unw_aux_info * aux, | |
9024 | unsigned int word, | |
9025 | unsigned int remaining, | |
9026 | unsigned int more_words, | |
9027 | bfd_vma data_offset, | |
9028 | Elf_Internal_Shdr * data_sec, | |
9029 | struct arm_section * data_arm_sec) | |
9030 | { | |
9031 | struct absaddr addr; | |
9032 | bfd_boolean res = TRUE; | |
9033 | ||
9034 | /* Decode the unwinding instructions. */ | |
9035 | while (1) | |
9036 | { | |
9037 | unsigned int op, op2; | |
9038 | ||
9039 | ADVANCE; | |
9040 | if (remaining == 0) | |
9041 | break; | |
9042 | remaining--; | |
9043 | op = word >> 24; | |
9044 | word <<= 8; | |
9045 | ||
9046 | printf (" 0x%02x ", op); | |
9047 | ||
9048 | if ((op & 0xc0) == 0x00) | |
9049 | { | |
9050 | int offset = ((op & 0x3f) << 2) + 4; | |
9051 | ||
9052 | printf (" vsp = vsp + %d", offset); | |
9053 | } | |
9054 | else if ((op & 0xc0) == 0x40) | |
9055 | { | |
9056 | int offset = ((op & 0x3f) << 2) + 4; | |
9057 | ||
9058 | printf (" vsp = vsp - %d", offset); | |
9059 | } | |
9060 | else if ((op & 0xf0) == 0x80) | |
9061 | { | |
9062 | GET_OP (op2); | |
9063 | if (op == 0x80 && op2 == 0) | |
9064 | printf (_("Refuse to unwind")); | |
9065 | else | |
9066 | { | |
9067 | unsigned int mask = ((op & 0x0f) << 8) | op2; | |
9068 | bfd_boolean first = TRUE; | |
9069 | int i; | |
9070 | ||
9071 | printf ("pop {"); | |
9072 | for (i = 0; i < 12; i++) | |
9073 | if (mask & (1 << i)) | |
9074 | { | |
9075 | if (first) | |
9076 | first = FALSE; | |
9077 | else | |
9078 | printf (", "); | |
9079 | printf ("r%d", 4 + i); | |
9080 | } | |
9081 | printf ("}"); | |
9082 | } | |
9083 | } | |
9084 | else if ((op & 0xf0) == 0x90) | |
9085 | { | |
9086 | if (op == 0x9d || op == 0x9f) | |
9087 | printf (_(" [Reserved]")); | |
9088 | else | |
9089 | printf (" vsp = r%d", op & 0x0f); | |
9090 | } | |
9091 | else if ((op & 0xf0) == 0xa0) | |
9092 | { | |
9093 | int end = 4 + (op & 0x07); | |
9094 | bfd_boolean first = TRUE; | |
9095 | int i; | |
9096 | ||
9097 | printf (" pop {"); | |
9098 | for (i = 4; i <= end; i++) | |
9099 | { | |
9100 | if (first) | |
9101 | first = FALSE; | |
9102 | else | |
9103 | printf (", "); | |
9104 | printf ("r%d", i); | |
9105 | } | |
9106 | if (op & 0x08) | |
9107 | { | |
9108 | if (!first) | |
9109 | printf (", "); | |
9110 | printf ("r14"); | |
9111 | } | |
9112 | printf ("}"); | |
9113 | } | |
9114 | else if (op == 0xb0) | |
9115 | printf (_(" finish")); | |
9116 | else if (op == 0xb1) | |
9117 | { | |
9118 | GET_OP (op2); | |
9119 | if (op2 == 0 || (op2 & 0xf0) != 0) | |
9120 | printf (_("[Spare]")); | |
9121 | else | |
9122 | { | |
9123 | unsigned int mask = op2 & 0x0f; | |
9124 | bfd_boolean first = TRUE; | |
9125 | int i; | |
9126 | ||
9127 | printf ("pop {"); | |
9128 | for (i = 0; i < 12; i++) | |
9129 | if (mask & (1 << i)) | |
9130 | { | |
9131 | if (first) | |
9132 | first = FALSE; | |
9133 | else | |
9134 | printf (", "); | |
9135 | printf ("r%d", i); | |
9136 | } | |
9137 | printf ("}"); | |
9138 | } | |
9139 | } | |
9140 | else if (op == 0xb2) | |
9141 | { | |
9142 | unsigned char buf[9]; | |
9143 | unsigned int i, len; | |
9144 | unsigned long offset; | |
9145 | ||
9146 | for (i = 0; i < sizeof (buf); i++) | |
9147 | { | |
9148 | GET_OP (buf[i]); | |
9149 | if ((buf[i] & 0x80) == 0) | |
9150 | break; | |
9151 | } | |
9152 | if (i == sizeof (buf)) | |
9153 | { | |
9154 | error (_("corrupt change to vsp\n")); | |
9155 | res = FALSE; | |
9156 | } | |
9157 | else | |
9158 | { | |
9159 | offset = read_leb128 (buf, buf + i + 1, FALSE, &len, NULL); | |
9160 | assert (len == i + 1); | |
9161 | offset = offset * 4 + 0x204; | |
9162 | printf ("vsp = vsp + %ld", offset); | |
9163 | } | |
9164 | } | |
9165 | else if (op == 0xb3 || op == 0xc8 || op == 0xc9) | |
9166 | { | |
9167 | unsigned int first, last; | |
9168 | ||
9169 | GET_OP (op2); | |
9170 | first = op2 >> 4; | |
9171 | last = op2 & 0x0f; | |
9172 | if (op == 0xc8) | |
9173 | first = first + 16; | |
9174 | printf ("pop {D%d", first); | |
9175 | if (last) | |
9176 | printf ("-D%d", first + last); | |
9177 | printf ("}"); | |
9178 | } | |
9179 | else if ((op & 0xf8) == 0xb8 || (op & 0xf8) == 0xd0) | |
9180 | { | |
9181 | unsigned int count = op & 0x07; | |
9182 | ||
9183 | printf ("pop {D8"); | |
9184 | if (count) | |
9185 | printf ("-D%d", 8 + count); | |
9186 | printf ("}"); | |
9187 | } | |
9188 | else if (op >= 0xc0 && op <= 0xc5) | |
9189 | { | |
9190 | unsigned int count = op & 0x07; | |
9191 | ||
9192 | printf (" pop {wR10"); | |
9193 | if (count) | |
9194 | printf ("-wR%d", 10 + count); | |
9195 | printf ("}"); | |
9196 | } | |
9197 | else if (op == 0xc6) | |
9198 | { | |
9199 | unsigned int first, last; | |
9200 | ||
9201 | GET_OP (op2); | |
9202 | first = op2 >> 4; | |
9203 | last = op2 & 0x0f; | |
9204 | printf ("pop {wR%d", first); | |
9205 | if (last) | |
9206 | printf ("-wR%d", first + last); | |
9207 | printf ("}"); | |
9208 | } | |
9209 | else if (op == 0xc7) | |
9210 | { | |
9211 | GET_OP (op2); | |
9212 | if (op2 == 0 || (op2 & 0xf0) != 0) | |
9213 | printf (_("[Spare]")); | |
9214 | else | |
9215 | { | |
9216 | unsigned int mask = op2 & 0x0f; | |
9217 | bfd_boolean first = TRUE; | |
9218 | int i; | |
9219 | ||
9220 | printf ("pop {"); | |
9221 | for (i = 0; i < 4; i++) | |
9222 | if (mask & (1 << i)) | |
9223 | { | |
9224 | if (first) | |
9225 | first = FALSE; | |
9226 | else | |
9227 | printf (", "); | |
9228 | printf ("wCGR%d", i); | |
9229 | } | |
9230 | printf ("}"); | |
9231 | } | |
9232 | } | |
9233 | else | |
9234 | { | |
9235 | printf (_(" [unsupported opcode]")); | |
9236 | res = FALSE; | |
9237 | } | |
9238 | ||
9239 | printf ("\n"); | |
9240 | } | |
9241 | ||
9242 | return res; | |
9243 | } | |
9244 | ||
9245 | static bfd_boolean | |
9246 | decode_tic6x_unwind_bytecode (Filedata * filedata, | |
9247 | struct arm_unw_aux_info * aux, | |
9248 | unsigned int word, | |
9249 | unsigned int remaining, | |
9250 | unsigned int more_words, | |
9251 | bfd_vma data_offset, | |
9252 | Elf_Internal_Shdr * data_sec, | |
9253 | struct arm_section * data_arm_sec) | |
9254 | { | |
9255 | struct absaddr addr; | |
9256 | ||
9257 | /* Decode the unwinding instructions. */ | |
9258 | while (1) | |
9259 | { | |
9260 | unsigned int op, op2; | |
9261 | ||
9262 | ADVANCE; | |
9263 | if (remaining == 0) | |
9264 | break; | |
9265 | remaining--; | |
9266 | op = word >> 24; | |
9267 | word <<= 8; | |
9268 | ||
9269 | printf (" 0x%02x ", op); | |
9270 | ||
9271 | if ((op & 0xc0) == 0x00) | |
9272 | { | |
9273 | int offset = ((op & 0x3f) << 3) + 8; | |
9274 | printf (" sp = sp + %d", offset); | |
9275 | } | |
9276 | else if ((op & 0xc0) == 0x80) | |
9277 | { | |
9278 | GET_OP (op2); | |
9279 | if (op == 0x80 && op2 == 0) | |
9280 | printf (_("Refuse to unwind")); | |
9281 | else | |
9282 | { | |
9283 | unsigned int mask = ((op & 0x1f) << 8) | op2; | |
9284 | if (op & 0x20) | |
9285 | printf ("pop compact {"); | |
9286 | else | |
9287 | printf ("pop {"); | |
9288 | ||
9289 | decode_tic6x_unwind_regmask (mask); | |
9290 | printf("}"); | |
9291 | } | |
9292 | } | |
9293 | else if ((op & 0xf0) == 0xc0) | |
9294 | { | |
9295 | unsigned int reg; | |
9296 | unsigned int nregs; | |
9297 | unsigned int i; | |
9298 | const char *name; | |
9299 | struct | |
9300 | { | |
9301 | unsigned int offset; | |
9302 | unsigned int reg; | |
9303 | } regpos[16]; | |
9304 | ||
9305 | /* Scan entire instruction first so that GET_OP output is not | |
9306 | interleaved with disassembly. */ | |
9307 | nregs = 0; | |
9308 | for (i = 0; nregs < (op & 0xf); i++) | |
9309 | { | |
9310 | GET_OP (op2); | |
9311 | reg = op2 >> 4; | |
9312 | if (reg != 0xf) | |
9313 | { | |
9314 | regpos[nregs].offset = i * 2; | |
9315 | regpos[nregs].reg = reg; | |
9316 | nregs++; | |
9317 | } | |
9318 | ||
9319 | reg = op2 & 0xf; | |
9320 | if (reg != 0xf) | |
9321 | { | |
9322 | regpos[nregs].offset = i * 2 + 1; | |
9323 | regpos[nregs].reg = reg; | |
9324 | nregs++; | |
9325 | } | |
9326 | } | |
9327 | ||
9328 | printf (_("pop frame {")); | |
9329 | if (nregs == 0) | |
9330 | { | |
9331 | printf (_("*corrupt* - no registers specified")); | |
9332 | } | |
9333 | else | |
9334 | { | |
9335 | reg = nregs - 1; | |
9336 | for (i = i * 2; i > 0; i--) | |
9337 | { | |
9338 | if (regpos[reg].offset == i - 1) | |
9339 | { | |
9340 | name = tic6x_unwind_regnames[regpos[reg].reg]; | |
9341 | if (reg > 0) | |
9342 | reg--; | |
9343 | } | |
9344 | else | |
9345 | name = _("[pad]"); | |
9346 | ||
9347 | fputs (name, stdout); | |
9348 | if (i > 1) | |
9349 | printf (", "); | |
9350 | } | |
9351 | } | |
9352 | ||
9353 | printf ("}"); | |
9354 | } | |
9355 | else if (op == 0xd0) | |
9356 | printf (" MOV FP, SP"); | |
9357 | else if (op == 0xd1) | |
9358 | printf (" __c6xabi_pop_rts"); | |
9359 | else if (op == 0xd2) | |
9360 | { | |
9361 | unsigned char buf[9]; | |
9362 | unsigned int i, len; | |
9363 | unsigned long offset; | |
9364 | ||
9365 | for (i = 0; i < sizeof (buf); i++) | |
9366 | { | |
9367 | GET_OP (buf[i]); | |
9368 | if ((buf[i] & 0x80) == 0) | |
9369 | break; | |
9370 | } | |
9371 | /* PR 17531: file: id:000001,src:001906+004739,op:splice,rep:2. */ | |
9372 | if (i == sizeof (buf)) | |
9373 | { | |
9374 | warn (_("Corrupt stack pointer adjustment detected\n")); | |
9375 | return FALSE; | |
9376 | } | |
9377 | ||
9378 | offset = read_leb128 (buf, buf + i + 1, FALSE, &len, NULL); | |
9379 | assert (len == i + 1); | |
9380 | offset = offset * 8 + 0x408; | |
9381 | printf (_("sp = sp + %ld"), offset); | |
9382 | } | |
9383 | else if ((op & 0xf0) == 0xe0) | |
9384 | { | |
9385 | if ((op & 0x0f) == 7) | |
9386 | printf (" RETURN"); | |
9387 | else | |
9388 | printf (" MV %s, B3", tic6x_unwind_regnames[op & 0x0f]); | |
9389 | } | |
9390 | else | |
9391 | { | |
9392 | printf (_(" [unsupported opcode]")); | |
9393 | } | |
9394 | putchar ('\n'); | |
9395 | } | |
9396 | ||
9397 | return TRUE; | |
9398 | } | |
9399 | ||
9400 | static bfd_vma | |
9401 | arm_expand_prel31 (Filedata * filedata, bfd_vma word, bfd_vma where) | |
9402 | { | |
9403 | bfd_vma offset; | |
9404 | ||
9405 | offset = word & 0x7fffffff; | |
9406 | if (offset & 0x40000000) | |
9407 | offset |= ~ (bfd_vma) 0x7fffffff; | |
9408 | ||
9409 | if (filedata->file_header.e_machine == EM_TI_C6000) | |
9410 | offset <<= 1; | |
9411 | ||
9412 | return offset + where; | |
9413 | } | |
9414 | ||
9415 | static bfd_boolean | |
9416 | decode_arm_unwind (Filedata * filedata, | |
9417 | struct arm_unw_aux_info * aux, | |
9418 | unsigned int word, | |
9419 | unsigned int remaining, | |
9420 | bfd_vma data_offset, | |
9421 | Elf_Internal_Shdr * data_sec, | |
9422 | struct arm_section * data_arm_sec) | |
9423 | { | |
9424 | int per_index; | |
9425 | unsigned int more_words = 0; | |
9426 | struct absaddr addr; | |
9427 | bfd_vma sym_name = (bfd_vma) -1; | |
9428 | bfd_boolean res = TRUE; | |
9429 | ||
9430 | if (remaining == 0) | |
9431 | { | |
9432 | /* Fetch the first word. | |
9433 | Note - when decoding an object file the address extracted | |
9434 | here will always be 0. So we also pass in the sym_name | |
9435 | parameter so that we can find the symbol associated with | |
9436 | the personality routine. */ | |
9437 | if (! get_unwind_section_word (filedata, aux, data_arm_sec, data_sec, data_offset, | |
9438 | & word, & addr, & sym_name)) | |
9439 | return FALSE; | |
9440 | ||
9441 | remaining = 4; | |
9442 | } | |
9443 | else | |
9444 | { | |
9445 | addr.section = SHN_UNDEF; | |
9446 | addr.offset = 0; | |
9447 | } | |
9448 | ||
9449 | if ((word & 0x80000000) == 0) | |
9450 | { | |
9451 | /* Expand prel31 for personality routine. */ | |
9452 | bfd_vma fn; | |
9453 | const char *procname; | |
9454 | ||
9455 | fn = arm_expand_prel31 (filedata, word, data_sec->sh_addr + data_offset); | |
9456 | printf (_(" Personality routine: ")); | |
9457 | if (fn == 0 | |
9458 | && addr.section == SHN_UNDEF && addr.offset == 0 | |
9459 | && sym_name != (bfd_vma) -1 && sym_name < aux->strtab_size) | |
9460 | { | |
9461 | procname = aux->strtab + sym_name; | |
9462 | print_vma (fn, PREFIX_HEX); | |
9463 | if (procname) | |
9464 | { | |
9465 | fputs (" <", stdout); | |
9466 | fputs (procname, stdout); | |
9467 | fputc ('>', stdout); | |
9468 | } | |
9469 | } | |
9470 | else | |
9471 | procname = arm_print_vma_and_name (filedata, aux, fn, addr); | |
9472 | fputc ('\n', stdout); | |
9473 | ||
9474 | /* The GCC personality routines use the standard compact | |
9475 | encoding, starting with one byte giving the number of | |
9476 | words. */ | |
9477 | if (procname != NULL | |
9478 | && (const_strneq (procname, "__gcc_personality_v0") | |
9479 | || const_strneq (procname, "__gxx_personality_v0") | |
9480 | || const_strneq (procname, "__gcj_personality_v0") | |
9481 | || const_strneq (procname, "__gnu_objc_personality_v0"))) | |
9482 | { | |
9483 | remaining = 0; | |
9484 | more_words = 1; | |
9485 | ADVANCE; | |
9486 | if (!remaining) | |
9487 | { | |
9488 | printf (_(" [Truncated data]\n")); | |
9489 | return FALSE; | |
9490 | } | |
9491 | more_words = word >> 24; | |
9492 | word <<= 8; | |
9493 | remaining--; | |
9494 | per_index = -1; | |
9495 | } | |
9496 | else | |
9497 | return TRUE; | |
9498 | } | |
9499 | else | |
9500 | { | |
9501 | /* ARM EHABI Section 6.3: | |
9502 | ||
9503 | An exception-handling table entry for the compact model looks like: | |
9504 | ||
9505 | 31 30-28 27-24 23-0 | |
9506 | -- ----- ----- ---- | |
9507 | 1 0 index Data for personalityRoutine[index] */ | |
9508 | ||
9509 | if (filedata->file_header.e_machine == EM_ARM | |
9510 | && (word & 0x70000000)) | |
9511 | { | |
9512 | warn (_("Corrupt ARM compact model table entry: %x \n"), word); | |
9513 | res = FALSE; | |
9514 | } | |
9515 | ||
9516 | per_index = (word >> 24) & 0x7f; | |
9517 | printf (_(" Compact model index: %d\n"), per_index); | |
9518 | if (per_index == 0) | |
9519 | { | |
9520 | more_words = 0; | |
9521 | word <<= 8; | |
9522 | remaining--; | |
9523 | } | |
9524 | else if (per_index < 3) | |
9525 | { | |
9526 | more_words = (word >> 16) & 0xff; | |
9527 | word <<= 16; | |
9528 | remaining -= 2; | |
9529 | } | |
9530 | } | |
9531 | ||
9532 | switch (filedata->file_header.e_machine) | |
9533 | { | |
9534 | case EM_ARM: | |
9535 | if (per_index < 3) | |
9536 | { | |
9537 | if (! decode_arm_unwind_bytecode (filedata, aux, word, remaining, more_words, | |
9538 | data_offset, data_sec, data_arm_sec)) | |
9539 | res = FALSE; | |
9540 | } | |
9541 | else | |
9542 | { | |
9543 | warn (_("Unknown ARM compact model index encountered\n")); | |
9544 | printf (_(" [reserved]\n")); | |
9545 | res = FALSE; | |
9546 | } | |
9547 | break; | |
9548 | ||
9549 | case EM_TI_C6000: | |
9550 | if (per_index < 3) | |
9551 | { | |
9552 | if (! decode_tic6x_unwind_bytecode (filedata, aux, word, remaining, more_words, | |
9553 | data_offset, data_sec, data_arm_sec)) | |
9554 | res = FALSE; | |
9555 | } | |
9556 | else if (per_index < 5) | |
9557 | { | |
9558 | if (((word >> 17) & 0x7f) == 0x7f) | |
9559 | printf (_(" Restore stack from frame pointer\n")); | |
9560 | else | |
9561 | printf (_(" Stack increment %d\n"), (word >> 14) & 0x1fc); | |
9562 | printf (_(" Registers restored: ")); | |
9563 | if (per_index == 4) | |
9564 | printf (" (compact) "); | |
9565 | decode_tic6x_unwind_regmask ((word >> 4) & 0x1fff); | |
9566 | putchar ('\n'); | |
9567 | printf (_(" Return register: %s\n"), | |
9568 | tic6x_unwind_regnames[word & 0xf]); | |
9569 | } | |
9570 | else | |
9571 | printf (_(" [reserved (%d)]\n"), per_index); | |
9572 | break; | |
9573 | ||
9574 | default: | |
9575 | error (_("Unsupported architecture type %d encountered when decoding unwind table\n"), | |
9576 | filedata->file_header.e_machine); | |
9577 | res = FALSE; | |
9578 | } | |
9579 | ||
9580 | /* Decode the descriptors. Not implemented. */ | |
9581 | ||
9582 | return res; | |
9583 | } | |
9584 | ||
9585 | static bfd_boolean | |
9586 | dump_arm_unwind (Filedata * filedata, | |
9587 | struct arm_unw_aux_info * aux, | |
9588 | Elf_Internal_Shdr * exidx_sec) | |
9589 | { | |
9590 | struct arm_section exidx_arm_sec, extab_arm_sec; | |
9591 | unsigned int i, exidx_len; | |
9592 | unsigned long j, nfuns; | |
9593 | bfd_boolean res = TRUE; | |
9594 | ||
9595 | memset (&exidx_arm_sec, 0, sizeof (exidx_arm_sec)); | |
9596 | memset (&extab_arm_sec, 0, sizeof (extab_arm_sec)); | |
9597 | exidx_len = exidx_sec->sh_size / 8; | |
9598 | ||
9599 | aux->funtab = xmalloc (aux->nsyms * sizeof (Elf_Internal_Sym)); | |
9600 | for (nfuns = 0, j = 0; j < aux->nsyms; j++) | |
9601 | if (aux->symtab[j].st_value && ELF_ST_TYPE (aux->symtab[j].st_info) == STT_FUNC) | |
9602 | aux->funtab[nfuns++] = aux->symtab[j]; | |
9603 | aux->nfuns = nfuns; | |
9604 | qsort (aux->funtab, aux->nfuns, sizeof (Elf_Internal_Sym), symcmp); | |
9605 | ||
9606 | for (i = 0; i < exidx_len; i++) | |
9607 | { | |
9608 | unsigned int exidx_fn, exidx_entry; | |
9609 | struct absaddr fn_addr, entry_addr; | |
9610 | bfd_vma fn; | |
9611 | ||
9612 | fputc ('\n', stdout); | |
9613 | ||
9614 | if (! get_unwind_section_word (filedata, aux, & exidx_arm_sec, exidx_sec, | |
9615 | 8 * i, & exidx_fn, & fn_addr, NULL) | |
9616 | || ! get_unwind_section_word (filedata, aux, & exidx_arm_sec, exidx_sec, | |
9617 | 8 * i + 4, & exidx_entry, & entry_addr, NULL)) | |
9618 | { | |
9619 | free (aux->funtab); | |
9620 | arm_free_section (& exidx_arm_sec); | |
9621 | arm_free_section (& extab_arm_sec); | |
9622 | return FALSE; | |
9623 | } | |
9624 | ||
9625 | /* ARM EHABI, Section 5: | |
9626 | An index table entry consists of 2 words. | |
9627 | The first word contains a prel31 offset to the start of a function, with bit 31 clear. */ | |
9628 | if (exidx_fn & 0x80000000) | |
9629 | { | |
9630 | warn (_("corrupt index table entry: %x\n"), exidx_fn); | |
9631 | res = FALSE; | |
9632 | } | |
9633 | ||
9634 | fn = arm_expand_prel31 (filedata, exidx_fn, exidx_sec->sh_addr + 8 * i); | |
9635 | ||
9636 | arm_print_vma_and_name (filedata, aux, fn, fn_addr); | |
9637 | fputs (": ", stdout); | |
9638 | ||
9639 | if (exidx_entry == 1) | |
9640 | { | |
9641 | print_vma (exidx_entry, PREFIX_HEX); | |
9642 | fputs (" [cantunwind]\n", stdout); | |
9643 | } | |
9644 | else if (exidx_entry & 0x80000000) | |
9645 | { | |
9646 | print_vma (exidx_entry, PREFIX_HEX); | |
9647 | fputc ('\n', stdout); | |
9648 | decode_arm_unwind (filedata, aux, exidx_entry, 4, 0, NULL, NULL); | |
9649 | } | |
9650 | else | |
9651 | { | |
9652 | bfd_vma table, table_offset = 0; | |
9653 | Elf_Internal_Shdr *table_sec; | |
9654 | ||
9655 | fputs ("@", stdout); | |
9656 | table = arm_expand_prel31 (filedata, exidx_entry, exidx_sec->sh_addr + 8 * i + 4); | |
9657 | print_vma (table, PREFIX_HEX); | |
9658 | printf ("\n"); | |
9659 | ||
9660 | /* Locate the matching .ARM.extab. */ | |
9661 | if (entry_addr.section != SHN_UNDEF | |
9662 | && entry_addr.section < filedata->file_header.e_shnum) | |
9663 | { | |
9664 | table_sec = filedata->section_headers + entry_addr.section; | |
9665 | table_offset = entry_addr.offset; | |
9666 | /* PR 18879 */ | |
9667 | if (table_offset > table_sec->sh_size | |
9668 | || ((bfd_signed_vma) table_offset) < 0) | |
9669 | { | |
9670 | warn (_("Unwind entry contains corrupt offset (0x%lx) into section %s\n"), | |
9671 | (unsigned long) table_offset, | |
9672 | printable_section_name (filedata, table_sec)); | |
9673 | res = FALSE; | |
9674 | continue; | |
9675 | } | |
9676 | } | |
9677 | else | |
9678 | { | |
9679 | table_sec = find_section_by_address (filedata, table); | |
9680 | if (table_sec != NULL) | |
9681 | table_offset = table - table_sec->sh_addr; | |
9682 | } | |
9683 | ||
9684 | if (table_sec == NULL) | |
9685 | { | |
9686 | warn (_("Could not locate .ARM.extab section containing 0x%lx.\n"), | |
9687 | (unsigned long) table); | |
9688 | res = FALSE; | |
9689 | continue; | |
9690 | } | |
9691 | ||
9692 | if (! decode_arm_unwind (filedata, aux, 0, 0, table_offset, table_sec, | |
9693 | &extab_arm_sec)) | |
9694 | res = FALSE; | |
9695 | } | |
9696 | } | |
9697 | ||
9698 | printf ("\n"); | |
9699 | ||
9700 | free (aux->funtab); | |
9701 | arm_free_section (&exidx_arm_sec); | |
9702 | arm_free_section (&extab_arm_sec); | |
9703 | ||
9704 | return res; | |
9705 | } | |
9706 | ||
9707 | /* Used for both ARM and C6X unwinding tables. */ | |
9708 | ||
9709 | static bfd_boolean | |
9710 | arm_process_unwind (Filedata * filedata) | |
9711 | { | |
9712 | struct arm_unw_aux_info aux; | |
9713 | Elf_Internal_Shdr *unwsec = NULL; | |
9714 | Elf_Internal_Shdr *sec; | |
9715 | unsigned long i; | |
9716 | unsigned int sec_type; | |
9717 | bfd_boolean res = TRUE; | |
9718 | ||
9719 | switch (filedata->file_header.e_machine) | |
9720 | { | |
9721 | case EM_ARM: | |
9722 | sec_type = SHT_ARM_EXIDX; | |
9723 | break; | |
9724 | ||
9725 | case EM_TI_C6000: | |
9726 | sec_type = SHT_C6000_UNWIND; | |
9727 | break; | |
9728 | ||
9729 | default: | |
9730 | error (_("Unsupported architecture type %d encountered when processing unwind table\n"), | |
9731 | filedata->file_header.e_machine); | |
9732 | return FALSE; | |
9733 | } | |
9734 | ||
9735 | if (filedata->string_table == NULL) | |
9736 | return FALSE; | |
9737 | ||
9738 | memset (& aux, 0, sizeof (aux)); | |
9739 | aux.filedata = filedata; | |
9740 | ||
9741 | for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec) | |
9742 | { | |
9743 | if (sec->sh_type == SHT_SYMTAB) | |
9744 | { | |
9745 | if (aux.symtab) | |
9746 | { | |
9747 | error (_("Multiple symbol tables encountered\n")); | |
9748 | free (aux.symtab); | |
9749 | aux.symtab = NULL; | |
9750 | free (aux.strtab); | |
9751 | aux.strtab = NULL; | |
9752 | } | |
9753 | if (!get_symtab (filedata, sec, &aux.symtab, &aux.nsyms, | |
9754 | &aux.strtab, &aux.strtab_size)) | |
9755 | return FALSE; | |
9756 | } | |
9757 | else if (sec->sh_type == sec_type) | |
9758 | unwsec = sec; | |
9759 | } | |
9760 | ||
9761 | if (unwsec == NULL) | |
9762 | printf (_("\nThere are no unwind sections in this file.\n")); | |
9763 | else | |
9764 | for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec) | |
9765 | { | |
9766 | if (sec->sh_type == sec_type) | |
9767 | { | |
9768 | unsigned long num_unwind = sec->sh_size / (2 * eh_addr_size); | |
9769 | printf (ngettext ("\nUnwind section '%s' at offset 0x%lx " | |
9770 | "contains %lu entry:\n", | |
9771 | "\nUnwind section '%s' at offset 0x%lx " | |
9772 | "contains %lu entries:\n", | |
9773 | num_unwind), | |
9774 | printable_section_name (filedata, sec), | |
9775 | (unsigned long) sec->sh_offset, | |
9776 | num_unwind); | |
9777 | ||
9778 | if (! dump_arm_unwind (filedata, &aux, sec)) | |
9779 | res = FALSE; | |
9780 | } | |
9781 | } | |
9782 | ||
9783 | free (aux.symtab); | |
9784 | free ((char *) aux.strtab); | |
9785 | ||
9786 | return res; | |
9787 | } | |
9788 | ||
9789 | static bfd_boolean | |
9790 | process_unwind (Filedata * filedata) | |
9791 | { | |
9792 | struct unwind_handler | |
9793 | { | |
9794 | unsigned int machtype; | |
9795 | bfd_boolean (* handler)(Filedata *); | |
9796 | } handlers[] = | |
9797 | { | |
9798 | { EM_ARM, arm_process_unwind }, | |
9799 | { EM_IA_64, ia64_process_unwind }, | |
9800 | { EM_PARISC, hppa_process_unwind }, | |
9801 | { EM_TI_C6000, arm_process_unwind }, | |
9802 | { 0, NULL } | |
9803 | }; | |
9804 | int i; | |
9805 | ||
9806 | if (!do_unwind) | |
9807 | return TRUE; | |
9808 | ||
9809 | for (i = 0; handlers[i].handler != NULL; i++) | |
9810 | if (filedata->file_header.e_machine == handlers[i].machtype) | |
9811 | return handlers[i].handler (filedata); | |
9812 | ||
9813 | printf (_("\nThe decoding of unwind sections for machine type %s is not currently supported.\n"), | |
9814 | get_machine_name (filedata->file_header.e_machine)); | |
9815 | return TRUE; | |
9816 | } | |
9817 | ||
9818 | static void | |
9819 | dynamic_section_aarch64_val (Elf_Internal_Dyn * entry) | |
9820 | { | |
9821 | switch (entry->d_tag) | |
9822 | { | |
9823 | case DT_AARCH64_BTI_PLT: | |
9824 | case DT_AARCH64_PAC_PLT: | |
9825 | break; | |
9826 | default: | |
9827 | print_vma (entry->d_un.d_ptr, PREFIX_HEX); | |
9828 | break; | |
9829 | } | |
9830 | putchar ('\n'); | |
9831 | } | |
9832 | ||
9833 | static void | |
9834 | dynamic_section_mips_val (Filedata * filedata, Elf_Internal_Dyn * entry) | |
9835 | { | |
9836 | switch (entry->d_tag) | |
9837 | { | |
9838 | case DT_MIPS_FLAGS: | |
9839 | if (entry->d_un.d_val == 0) | |
9840 | printf (_("NONE")); | |
9841 | else | |
9842 | { | |
9843 | static const char * opts[] = | |
9844 | { | |
9845 | "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT", | |
9846 | "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS", | |
9847 | "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD", | |
9848 | "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF", | |
9849 | "RLD_ORDER_SAFE" | |
9850 | }; | |
9851 | unsigned int cnt; | |
9852 | bfd_boolean first = TRUE; | |
9853 | ||
9854 | for (cnt = 0; cnt < ARRAY_SIZE (opts); ++cnt) | |
9855 | if (entry->d_un.d_val & (1 << cnt)) | |
9856 | { | |
9857 | printf ("%s%s", first ? "" : " ", opts[cnt]); | |
9858 | first = FALSE; | |
9859 | } | |
9860 | } | |
9861 | break; | |
9862 | ||
9863 | case DT_MIPS_IVERSION: | |
9864 | if (VALID_DYNAMIC_NAME (filedata, entry->d_un.d_val)) | |
9865 | printf (_("Interface Version: %s"), | |
9866 | GET_DYNAMIC_NAME (filedata, entry->d_un.d_val)); | |
9867 | else | |
9868 | { | |
9869 | char buf[40]; | |
9870 | sprintf_vma (buf, entry->d_un.d_ptr); | |
9871 | /* Note: coded this way so that there is a single string for translation. */ | |
9872 | printf (_("<corrupt: %s>"), buf); | |
9873 | } | |
9874 | break; | |
9875 | ||
9876 | case DT_MIPS_TIME_STAMP: | |
9877 | { | |
9878 | char timebuf[128]; | |
9879 | struct tm * tmp; | |
9880 | time_t atime = entry->d_un.d_val; | |
9881 | ||
9882 | tmp = gmtime (&atime); | |
9883 | /* PR 17531: file: 6accc532. */ | |
9884 | if (tmp == NULL) | |
9885 | snprintf (timebuf, sizeof (timebuf), _("<corrupt>")); | |
9886 | else | |
9887 | snprintf (timebuf, sizeof (timebuf), "%04u-%02u-%02uT%02u:%02u:%02u", | |
9888 | tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday, | |
9889 | tmp->tm_hour, tmp->tm_min, tmp->tm_sec); | |
9890 | printf (_("Time Stamp: %s"), timebuf); | |
9891 | } | |
9892 | break; | |
9893 | ||
9894 | case DT_MIPS_RLD_VERSION: | |
9895 | case DT_MIPS_LOCAL_GOTNO: | |
9896 | case DT_MIPS_CONFLICTNO: | |
9897 | case DT_MIPS_LIBLISTNO: | |
9898 | case DT_MIPS_SYMTABNO: | |
9899 | case DT_MIPS_UNREFEXTNO: | |
9900 | case DT_MIPS_HIPAGENO: | |
9901 | case DT_MIPS_DELTA_CLASS_NO: | |
9902 | case DT_MIPS_DELTA_INSTANCE_NO: | |
9903 | case DT_MIPS_DELTA_RELOC_NO: | |
9904 | case DT_MIPS_DELTA_SYM_NO: | |
9905 | case DT_MIPS_DELTA_CLASSSYM_NO: | |
9906 | case DT_MIPS_COMPACT_SIZE: | |
9907 | print_vma (entry->d_un.d_val, DEC); | |
9908 | break; | |
9909 | ||
9910 | case DT_MIPS_XHASH: | |
9911 | filedata->dynamic_info_DT_MIPS_XHASH = entry->d_un.d_val; | |
9912 | filedata->dynamic_info_DT_GNU_HASH = entry->d_un.d_val; | |
9913 | /* Falls through. */ | |
9914 | ||
9915 | default: | |
9916 | print_vma (entry->d_un.d_ptr, PREFIX_HEX); | |
9917 | } | |
9918 | putchar ('\n'); | |
9919 | } | |
9920 | ||
9921 | static void | |
9922 | dynamic_section_parisc_val (Elf_Internal_Dyn * entry) | |
9923 | { | |
9924 | switch (entry->d_tag) | |
9925 | { | |
9926 | case DT_HP_DLD_FLAGS: | |
9927 | { | |
9928 | static struct | |
9929 | { | |
9930 | long int bit; | |
9931 | const char * str; | |
9932 | } | |
9933 | flags[] = | |
9934 | { | |
9935 | { DT_HP_DEBUG_PRIVATE, "HP_DEBUG_PRIVATE" }, | |
9936 | { DT_HP_DEBUG_CALLBACK, "HP_DEBUG_CALLBACK" }, | |
9937 | { DT_HP_DEBUG_CALLBACK_BOR, "HP_DEBUG_CALLBACK_BOR" }, | |
9938 | { DT_HP_NO_ENVVAR, "HP_NO_ENVVAR" }, | |
9939 | { DT_HP_BIND_NOW, "HP_BIND_NOW" }, | |
9940 | { DT_HP_BIND_NONFATAL, "HP_BIND_NONFATAL" }, | |
9941 | { DT_HP_BIND_VERBOSE, "HP_BIND_VERBOSE" }, | |
9942 | { DT_HP_BIND_RESTRICTED, "HP_BIND_RESTRICTED" }, | |
9943 | { DT_HP_BIND_SYMBOLIC, "HP_BIND_SYMBOLIC" }, | |
9944 | { DT_HP_RPATH_FIRST, "HP_RPATH_FIRST" }, | |
9945 | { DT_HP_BIND_DEPTH_FIRST, "HP_BIND_DEPTH_FIRST" }, | |
9946 | { DT_HP_GST, "HP_GST" }, | |
9947 | { DT_HP_SHLIB_FIXED, "HP_SHLIB_FIXED" }, | |
9948 | { DT_HP_MERGE_SHLIB_SEG, "HP_MERGE_SHLIB_SEG" }, | |
9949 | { DT_HP_NODELETE, "HP_NODELETE" }, | |
9950 | { DT_HP_GROUP, "HP_GROUP" }, | |
9951 | { DT_HP_PROTECT_LINKAGE_TABLE, "HP_PROTECT_LINKAGE_TABLE" } | |
9952 | }; | |
9953 | bfd_boolean first = TRUE; | |
9954 | size_t cnt; | |
9955 | bfd_vma val = entry->d_un.d_val; | |
9956 | ||
9957 | for (cnt = 0; cnt < ARRAY_SIZE (flags); ++cnt) | |
9958 | if (val & flags[cnt].bit) | |
9959 | { | |
9960 | if (! first) | |
9961 | putchar (' '); | |
9962 | fputs (flags[cnt].str, stdout); | |
9963 | first = FALSE; | |
9964 | val ^= flags[cnt].bit; | |
9965 | } | |
9966 | ||
9967 | if (val != 0 || first) | |
9968 | { | |
9969 | if (! first) | |
9970 | putchar (' '); | |
9971 | print_vma (val, HEX); | |
9972 | } | |
9973 | } | |
9974 | break; | |
9975 | ||
9976 | default: | |
9977 | print_vma (entry->d_un.d_ptr, PREFIX_HEX); | |
9978 | break; | |
9979 | } | |
9980 | putchar ('\n'); | |
9981 | } | |
9982 | ||
9983 | #ifdef BFD64 | |
9984 | ||
9985 | /* VMS vs Unix time offset and factor. */ | |
9986 | ||
9987 | #define VMS_EPOCH_OFFSET 35067168000000000LL | |
9988 | #define VMS_GRANULARITY_FACTOR 10000000 | |
9989 | #ifndef INT64_MIN | |
9990 | #define INT64_MIN (-9223372036854775807LL - 1) | |
9991 | #endif | |
9992 | ||
9993 | /* Display a VMS time in a human readable format. */ | |
9994 | ||
9995 | static void | |
9996 | print_vms_time (bfd_int64_t vmstime) | |
9997 | { | |
9998 | struct tm *tm = NULL; | |
9999 | time_t unxtime; | |
10000 | ||
10001 | if (vmstime >= INT64_MIN + VMS_EPOCH_OFFSET) | |
10002 | { | |
10003 | vmstime = (vmstime - VMS_EPOCH_OFFSET) / VMS_GRANULARITY_FACTOR; | |
10004 | unxtime = vmstime; | |
10005 | if (unxtime == vmstime) | |
10006 | tm = gmtime (&unxtime); | |
10007 | } | |
10008 | if (tm != NULL) | |
10009 | printf ("%04u-%02u-%02uT%02u:%02u:%02u", | |
10010 | tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, | |
10011 | tm->tm_hour, tm->tm_min, tm->tm_sec); | |
10012 | } | |
10013 | #endif /* BFD64 */ | |
10014 | ||
10015 | static void | |
10016 | dynamic_section_ia64_val (Elf_Internal_Dyn * entry) | |
10017 | { | |
10018 | switch (entry->d_tag) | |
10019 | { | |
10020 | case DT_IA_64_PLT_RESERVE: | |
10021 | /* First 3 slots reserved. */ | |
10022 | print_vma (entry->d_un.d_ptr, PREFIX_HEX); | |
10023 | printf (" -- "); | |
10024 | print_vma (entry->d_un.d_ptr + (3 * 8), PREFIX_HEX); | |
10025 | break; | |
10026 | ||
10027 | case DT_IA_64_VMS_LINKTIME: | |
10028 | #ifdef BFD64 | |
10029 | print_vms_time (entry->d_un.d_val); | |
10030 | #endif | |
10031 | break; | |
10032 | ||
10033 | case DT_IA_64_VMS_LNKFLAGS: | |
10034 | print_vma (entry->d_un.d_ptr, PREFIX_HEX); | |
10035 | if (entry->d_un.d_val & VMS_LF_CALL_DEBUG) | |
10036 | printf (" CALL_DEBUG"); | |
10037 | if (entry->d_un.d_val & VMS_LF_NOP0BUFS) | |
10038 | printf (" NOP0BUFS"); | |
10039 | if (entry->d_un.d_val & VMS_LF_P0IMAGE) | |
10040 | printf (" P0IMAGE"); | |
10041 | if (entry->d_un.d_val & VMS_LF_MKTHREADS) | |
10042 | printf (" MKTHREADS"); | |
10043 | if (entry->d_un.d_val & VMS_LF_UPCALLS) | |
10044 | printf (" UPCALLS"); | |
10045 | if (entry->d_un.d_val & VMS_LF_IMGSTA) | |
10046 | printf (" IMGSTA"); | |
10047 | if (entry->d_un.d_val & VMS_LF_INITIALIZE) | |
10048 | printf (" INITIALIZE"); | |
10049 | if (entry->d_un.d_val & VMS_LF_MAIN) | |
10050 | printf (" MAIN"); | |
10051 | if (entry->d_un.d_val & VMS_LF_EXE_INIT) | |
10052 | printf (" EXE_INIT"); | |
10053 | if (entry->d_un.d_val & VMS_LF_TBK_IN_IMG) | |
10054 | printf (" TBK_IN_IMG"); | |
10055 | if (entry->d_un.d_val & VMS_LF_DBG_IN_IMG) | |
10056 | printf (" DBG_IN_IMG"); | |
10057 | if (entry->d_un.d_val & VMS_LF_TBK_IN_DSF) | |
10058 | printf (" TBK_IN_DSF"); | |
10059 | if (entry->d_un.d_val & VMS_LF_DBG_IN_DSF) | |
10060 | printf (" DBG_IN_DSF"); | |
10061 | if (entry->d_un.d_val & VMS_LF_SIGNATURES) | |
10062 | printf (" SIGNATURES"); | |
10063 | if (entry->d_un.d_val & VMS_LF_REL_SEG_OFF) | |
10064 | printf (" REL_SEG_OFF"); | |
10065 | break; | |
10066 | ||
10067 | default: | |
10068 | print_vma (entry->d_un.d_ptr, PREFIX_HEX); | |
10069 | break; | |
10070 | } | |
10071 | putchar ('\n'); | |
10072 | } | |
10073 | ||
10074 | static bfd_boolean | |
10075 | get_32bit_dynamic_section (Filedata * filedata) | |
10076 | { | |
10077 | Elf32_External_Dyn * edyn; | |
10078 | Elf32_External_Dyn * ext; | |
10079 | Elf_Internal_Dyn * entry; | |
10080 | ||
10081 | edyn = (Elf32_External_Dyn *) get_data (NULL, filedata, | |
10082 | filedata->dynamic_addr, 1, | |
10083 | filedata->dynamic_size, | |
10084 | _("dynamic section")); | |
10085 | if (!edyn) | |
10086 | return FALSE; | |
10087 | ||
10088 | /* SGI's ELF has more than one section in the DYNAMIC segment, and we | |
10089 | might not have the luxury of section headers. Look for the DT_NULL | |
10090 | terminator to determine the number of entries. */ | |
10091 | for (ext = edyn, filedata->dynamic_nent = 0; | |
10092 | (char *) (ext + 1) <= (char *) edyn + filedata->dynamic_size; | |
10093 | ext++) | |
10094 | { | |
10095 | filedata->dynamic_nent++; | |
10096 | if (BYTE_GET (ext->d_tag) == DT_NULL) | |
10097 | break; | |
10098 | } | |
10099 | ||
10100 | filedata->dynamic_section | |
10101 | = (Elf_Internal_Dyn *) cmalloc (filedata->dynamic_nent, sizeof (* entry)); | |
10102 | if (filedata->dynamic_section == NULL) | |
10103 | { | |
10104 | error (_("Out of memory allocating space for %lu dynamic entries\n"), | |
10105 | (unsigned long) filedata->dynamic_nent); | |
10106 | free (edyn); | |
10107 | return FALSE; | |
10108 | } | |
10109 | ||
10110 | for (ext = edyn, entry = filedata->dynamic_section; | |
10111 | entry < filedata->dynamic_section + filedata->dynamic_nent; | |
10112 | ext++, entry++) | |
10113 | { | |
10114 | entry->d_tag = BYTE_GET (ext->d_tag); | |
10115 | entry->d_un.d_val = BYTE_GET (ext->d_un.d_val); | |
10116 | } | |
10117 | ||
10118 | free (edyn); | |
10119 | ||
10120 | return TRUE; | |
10121 | } | |
10122 | ||
10123 | static bfd_boolean | |
10124 | get_64bit_dynamic_section (Filedata * filedata) | |
10125 | { | |
10126 | Elf64_External_Dyn * edyn; | |
10127 | Elf64_External_Dyn * ext; | |
10128 | Elf_Internal_Dyn * entry; | |
10129 | ||
10130 | /* Read in the data. */ | |
10131 | edyn = (Elf64_External_Dyn *) get_data (NULL, filedata, | |
10132 | filedata->dynamic_addr, 1, | |
10133 | filedata->dynamic_size, | |
10134 | _("dynamic section")); | |
10135 | if (!edyn) | |
10136 | return FALSE; | |
10137 | ||
10138 | /* SGI's ELF has more than one section in the DYNAMIC segment, and we | |
10139 | might not have the luxury of section headers. Look for the DT_NULL | |
10140 | terminator to determine the number of entries. */ | |
10141 | for (ext = edyn, filedata->dynamic_nent = 0; | |
10142 | /* PR 17533 file: 033-67080-0.004 - do not read past end of buffer. */ | |
10143 | (char *) (ext + 1) <= (char *) edyn + filedata->dynamic_size; | |
10144 | ext++) | |
10145 | { | |
10146 | filedata->dynamic_nent++; | |
10147 | if (BYTE_GET (ext->d_tag) == DT_NULL) | |
10148 | break; | |
10149 | } | |
10150 | ||
10151 | filedata->dynamic_section | |
10152 | = (Elf_Internal_Dyn *) cmalloc (filedata->dynamic_nent, sizeof (* entry)); | |
10153 | if (filedata->dynamic_section == NULL) | |
10154 | { | |
10155 | error (_("Out of memory allocating space for %lu dynamic entries\n"), | |
10156 | (unsigned long) filedata->dynamic_nent); | |
10157 | free (edyn); | |
10158 | return FALSE; | |
10159 | } | |
10160 | ||
10161 | /* Convert from external to internal formats. */ | |
10162 | for (ext = edyn, entry = filedata->dynamic_section; | |
10163 | entry < filedata->dynamic_section + filedata->dynamic_nent; | |
10164 | ext++, entry++) | |
10165 | { | |
10166 | entry->d_tag = BYTE_GET (ext->d_tag); | |
10167 | entry->d_un.d_val = BYTE_GET (ext->d_un.d_val); | |
10168 | } | |
10169 | ||
10170 | free (edyn); | |
10171 | ||
10172 | return TRUE; | |
10173 | } | |
10174 | ||
10175 | static void | |
10176 | print_dynamic_flags (bfd_vma flags) | |
10177 | { | |
10178 | bfd_boolean first = TRUE; | |
10179 | ||
10180 | while (flags) | |
10181 | { | |
10182 | bfd_vma flag; | |
10183 | ||
10184 | flag = flags & - flags; | |
10185 | flags &= ~ flag; | |
10186 | ||
10187 | if (first) | |
10188 | first = FALSE; | |
10189 | else | |
10190 | putc (' ', stdout); | |
10191 | ||
10192 | switch (flag) | |
10193 | { | |
10194 | case DF_ORIGIN: fputs ("ORIGIN", stdout); break; | |
10195 | case DF_SYMBOLIC: fputs ("SYMBOLIC", stdout); break; | |
10196 | case DF_TEXTREL: fputs ("TEXTREL", stdout); break; | |
10197 | case DF_BIND_NOW: fputs ("BIND_NOW", stdout); break; | |
10198 | case DF_STATIC_TLS: fputs ("STATIC_TLS", stdout); break; | |
10199 | default: fputs (_("unknown"), stdout); break; | |
10200 | } | |
10201 | } | |
10202 | puts (""); | |
10203 | } | |
10204 | ||
10205 | static bfd_vma * | |
10206 | get_dynamic_data (Filedata * filedata, bfd_size_type number, unsigned int ent_size) | |
10207 | { | |
10208 | unsigned char * e_data; | |
10209 | bfd_vma * i_data; | |
10210 | ||
10211 | /* If the size_t type is smaller than the bfd_size_type, eg because | |
10212 | you are building a 32-bit tool on a 64-bit host, then make sure | |
10213 | that when (number) is cast to (size_t) no information is lost. */ | |
10214 | if (sizeof (size_t) < sizeof (bfd_size_type) | |
10215 | && (bfd_size_type) ((size_t) number) != number) | |
10216 | { | |
10217 | error (_("Size truncation prevents reading %s elements of size %u\n"), | |
10218 | bfd_vmatoa ("u", number), ent_size); | |
10219 | return NULL; | |
10220 | } | |
10221 | ||
10222 | /* Be kind to memory checkers (eg valgrind, address sanitizer) by not | |
10223 | attempting to allocate memory when the read is bound to fail. */ | |
10224 | if (ent_size * number > filedata->file_size) | |
10225 | { | |
10226 | error (_("Invalid number of dynamic entries: %s\n"), | |
10227 | bfd_vmatoa ("u", number)); | |
10228 | return NULL; | |
10229 | } | |
10230 | ||
10231 | e_data = (unsigned char *) cmalloc ((size_t) number, ent_size); | |
10232 | if (e_data == NULL) | |
10233 | { | |
10234 | error (_("Out of memory reading %s dynamic entries\n"), | |
10235 | bfd_vmatoa ("u", number)); | |
10236 | return NULL; | |
10237 | } | |
10238 | ||
10239 | if (fread (e_data, ent_size, (size_t) number, filedata->handle) != number) | |
10240 | { | |
10241 | error (_("Unable to read in %s bytes of dynamic data\n"), | |
10242 | bfd_vmatoa ("u", number * ent_size)); | |
10243 | free (e_data); | |
10244 | return NULL; | |
10245 | } | |
10246 | ||
10247 | i_data = (bfd_vma *) cmalloc ((size_t) number, sizeof (*i_data)); | |
10248 | if (i_data == NULL) | |
10249 | { | |
10250 | error (_("Out of memory allocating space for %s dynamic entries\n"), | |
10251 | bfd_vmatoa ("u", number)); | |
10252 | free (e_data); | |
10253 | return NULL; | |
10254 | } | |
10255 | ||
10256 | while (number--) | |
10257 | i_data[number] = byte_get (e_data + number * ent_size, ent_size); | |
10258 | ||
10259 | free (e_data); | |
10260 | ||
10261 | return i_data; | |
10262 | } | |
10263 | ||
10264 | static unsigned long | |
10265 | get_num_dynamic_syms (Filedata * filedata) | |
10266 | { | |
10267 | unsigned long num_of_syms = 0; | |
10268 | ||
10269 | if (!do_histogram && (!do_using_dynamic || do_dyn_syms)) | |
10270 | return num_of_syms; | |
10271 | ||
10272 | if (filedata->dynamic_info[DT_HASH]) | |
10273 | { | |
10274 | unsigned char nb[8]; | |
10275 | unsigned char nc[8]; | |
10276 | unsigned int hash_ent_size = 4; | |
10277 | ||
10278 | if ((filedata->file_header.e_machine == EM_ALPHA | |
10279 | || filedata->file_header.e_machine == EM_S390 | |
10280 | || filedata->file_header.e_machine == EM_S390_OLD) | |
10281 | && filedata->file_header.e_ident[EI_CLASS] == ELFCLASS64) | |
10282 | hash_ent_size = 8; | |
10283 | ||
10284 | if (fseek (filedata->handle, | |
10285 | (filedata->archive_file_offset | |
10286 | + offset_from_vma (filedata, filedata->dynamic_info[DT_HASH], | |
10287 | sizeof nb + sizeof nc)), | |
10288 | SEEK_SET)) | |
10289 | { | |
10290 | error (_("Unable to seek to start of dynamic information\n")); | |
10291 | goto no_hash; | |
10292 | } | |
10293 | ||
10294 | if (fread (nb, hash_ent_size, 1, filedata->handle) != 1) | |
10295 | { | |
10296 | error (_("Failed to read in number of buckets\n")); | |
10297 | goto no_hash; | |
10298 | } | |
10299 | ||
10300 | if (fread (nc, hash_ent_size, 1, filedata->handle) != 1) | |
10301 | { | |
10302 | error (_("Failed to read in number of chains\n")); | |
10303 | goto no_hash; | |
10304 | } | |
10305 | ||
10306 | filedata->nbuckets = byte_get (nb, hash_ent_size); | |
10307 | filedata->nchains = byte_get (nc, hash_ent_size); | |
10308 | ||
10309 | if (filedata->nbuckets != 0 && filedata->nchains != 0) | |
10310 | { | |
10311 | filedata->buckets = get_dynamic_data (filedata, filedata->nbuckets, | |
10312 | hash_ent_size); | |
10313 | filedata->chains = get_dynamic_data (filedata, filedata->nchains, | |
10314 | hash_ent_size); | |
10315 | ||
10316 | if (filedata->buckets != NULL && filedata->chains != NULL) | |
10317 | num_of_syms = filedata->nchains; | |
10318 | } | |
10319 | no_hash: | |
10320 | if (num_of_syms == 0) | |
10321 | { | |
10322 | free (filedata->buckets); | |
10323 | filedata->buckets = NULL; | |
10324 | free (filedata->chains); | |
10325 | filedata->chains = NULL; | |
10326 | filedata->nbuckets = 0; | |
10327 | } | |
10328 | } | |
10329 | ||
10330 | if (filedata->dynamic_info_DT_GNU_HASH) | |
10331 | { | |
10332 | unsigned char nb[16]; | |
10333 | bfd_vma i, maxchain = 0xffffffff, bitmaskwords; | |
10334 | bfd_vma buckets_vma; | |
10335 | unsigned long hn; | |
10336 | ||
10337 | if (fseek (filedata->handle, | |
10338 | (filedata->archive_file_offset | |
10339 | + offset_from_vma (filedata, | |
10340 | filedata->dynamic_info_DT_GNU_HASH, | |
10341 | sizeof nb)), | |
10342 | SEEK_SET)) | |
10343 | { | |
10344 | error (_("Unable to seek to start of dynamic information\n")); | |
10345 | goto no_gnu_hash; | |
10346 | } | |
10347 | ||
10348 | if (fread (nb, 16, 1, filedata->handle) != 1) | |
10349 | { | |
10350 | error (_("Failed to read in number of buckets\n")); | |
10351 | goto no_gnu_hash; | |
10352 | } | |
10353 | ||
10354 | filedata->ngnubuckets = byte_get (nb, 4); | |
10355 | filedata->gnusymidx = byte_get (nb + 4, 4); | |
10356 | bitmaskwords = byte_get (nb + 8, 4); | |
10357 | buckets_vma = filedata->dynamic_info_DT_GNU_HASH + 16; | |
10358 | if (is_32bit_elf) | |
10359 | buckets_vma += bitmaskwords * 4; | |
10360 | else | |
10361 | buckets_vma += bitmaskwords * 8; | |
10362 | ||
10363 | if (fseek (filedata->handle, | |
10364 | (filedata->archive_file_offset | |
10365 | + offset_from_vma (filedata, buckets_vma, 4)), | |
10366 | SEEK_SET)) | |
10367 | { | |
10368 | error (_("Unable to seek to start of dynamic information\n")); | |
10369 | goto no_gnu_hash; | |
10370 | } | |
10371 | ||
10372 | filedata->gnubuckets | |
10373 | = get_dynamic_data (filedata, filedata->ngnubuckets, 4); | |
10374 | ||
10375 | if (filedata->gnubuckets == NULL) | |
10376 | goto no_gnu_hash; | |
10377 | ||
10378 | for (i = 0; i < filedata->ngnubuckets; i++) | |
10379 | if (filedata->gnubuckets[i] != 0) | |
10380 | { | |
10381 | if (filedata->gnubuckets[i] < filedata->gnusymidx) | |
10382 | goto no_gnu_hash; | |
10383 | ||
10384 | if (maxchain == 0xffffffff || filedata->gnubuckets[i] > maxchain) | |
10385 | maxchain = filedata->gnubuckets[i]; | |
10386 | } | |
10387 | ||
10388 | if (maxchain == 0xffffffff) | |
10389 | goto no_gnu_hash; | |
10390 | ||
10391 | maxchain -= filedata->gnusymidx; | |
10392 | ||
10393 | if (fseek (filedata->handle, | |
10394 | (filedata->archive_file_offset | |
10395 | + offset_from_vma (filedata, | |
10396 | buckets_vma + 4 * (filedata->ngnubuckets | |
10397 | + maxchain), | |
10398 | 4)), | |
10399 | SEEK_SET)) | |
10400 | { | |
10401 | error (_("Unable to seek to start of dynamic information\n")); | |
10402 | goto no_gnu_hash; | |
10403 | } | |
10404 | ||
10405 | do | |
10406 | { | |
10407 | if (fread (nb, 4, 1, filedata->handle) != 1) | |
10408 | { | |
10409 | error (_("Failed to determine last chain length\n")); | |
10410 | goto no_gnu_hash; | |
10411 | } | |
10412 | ||
10413 | if (maxchain + 1 == 0) | |
10414 | goto no_gnu_hash; | |
10415 | ||
10416 | ++maxchain; | |
10417 | } | |
10418 | while ((byte_get (nb, 4) & 1) == 0); | |
10419 | ||
10420 | if (fseek (filedata->handle, | |
10421 | (filedata->archive_file_offset | |
10422 | + offset_from_vma (filedata, (buckets_vma | |
10423 | + 4 * filedata->ngnubuckets), | |
10424 | 4)), | |
10425 | SEEK_SET)) | |
10426 | { | |
10427 | error (_("Unable to seek to start of dynamic information\n")); | |
10428 | goto no_gnu_hash; | |
10429 | } | |
10430 | ||
10431 | filedata->gnuchains = get_dynamic_data (filedata, maxchain, 4); | |
10432 | filedata->ngnuchains = maxchain; | |
10433 | ||
10434 | if (filedata->gnuchains == NULL) | |
10435 | goto no_gnu_hash; | |
10436 | ||
10437 | if (filedata->dynamic_info_DT_MIPS_XHASH) | |
10438 | { | |
10439 | if (fseek (filedata->handle, | |
10440 | (filedata->archive_file_offset | |
10441 | + offset_from_vma (filedata, (buckets_vma | |
10442 | + 4 * (filedata->ngnubuckets | |
10443 | + maxchain)), 4)), | |
10444 | SEEK_SET)) | |
10445 | { | |
10446 | error (_("Unable to seek to start of dynamic information\n")); | |
10447 | goto no_gnu_hash; | |
10448 | } | |
10449 | ||
10450 | filedata->mipsxlat = get_dynamic_data (filedata, maxchain, 4); | |
10451 | if (filedata->mipsxlat == NULL) | |
10452 | goto no_gnu_hash; | |
10453 | } | |
10454 | ||
10455 | for (hn = 0; hn < filedata->ngnubuckets; ++hn) | |
10456 | if (filedata->gnubuckets[hn] != 0) | |
10457 | { | |
10458 | bfd_vma si = filedata->gnubuckets[hn]; | |
10459 | bfd_vma off = si - filedata->gnusymidx; | |
10460 | ||
10461 | do | |
10462 | { | |
10463 | if (filedata->dynamic_info_DT_MIPS_XHASH) | |
10464 | { | |
10465 | if (off < filedata->ngnuchains | |
10466 | && filedata->mipsxlat[off] >= num_of_syms) | |
10467 | num_of_syms = filedata->mipsxlat[off] + 1; | |
10468 | } | |
10469 | else | |
10470 | { | |
10471 | if (si >= num_of_syms) | |
10472 | num_of_syms = si + 1; | |
10473 | } | |
10474 | si++; | |
10475 | } | |
10476 | while (off < filedata->ngnuchains | |
10477 | && (filedata->gnuchains[off++] & 1) == 0); | |
10478 | } | |
10479 | ||
10480 | if (num_of_syms == 0) | |
10481 | { | |
10482 | no_gnu_hash: | |
10483 | free (filedata->mipsxlat); | |
10484 | filedata->mipsxlat = NULL; | |
10485 | free (filedata->gnuchains); | |
10486 | filedata->gnuchains = NULL; | |
10487 | free (filedata->gnubuckets); | |
10488 | filedata->gnubuckets = NULL; | |
10489 | filedata->ngnubuckets = 0; | |
10490 | filedata->ngnuchains = 0; | |
10491 | } | |
10492 | } | |
10493 | ||
10494 | return num_of_syms; | |
10495 | } | |
10496 | ||
10497 | /* Parse and display the contents of the dynamic section. */ | |
10498 | ||
10499 | static bfd_boolean | |
10500 | process_dynamic_section (Filedata * filedata) | |
10501 | { | |
10502 | Elf_Internal_Dyn * entry; | |
10503 | ||
10504 | if (filedata->dynamic_size == 0) | |
10505 | { | |
10506 | if (do_dynamic) | |
10507 | { | |
10508 | if (filedata->is_separate) | |
10509 | printf (_("\nThere is no dynamic section in linked file '%s'.\n"), | |
10510 | filedata->file_name); | |
10511 | else | |
10512 | printf (_("\nThere is no dynamic section in this file.\n")); | |
10513 | } | |
10514 | ||
10515 | return TRUE; | |
10516 | } | |
10517 | ||
10518 | if (is_32bit_elf) | |
10519 | { | |
10520 | if (! get_32bit_dynamic_section (filedata)) | |
10521 | return FALSE; | |
10522 | } | |
10523 | else | |
10524 | { | |
10525 | if (! get_64bit_dynamic_section (filedata)) | |
10526 | return FALSE; | |
10527 | } | |
10528 | ||
10529 | /* Find the appropriate symbol table. */ | |
10530 | if (filedata->dynamic_symbols == NULL || do_histogram) | |
10531 | { | |
10532 | unsigned long num_of_syms; | |
10533 | ||
10534 | for (entry = filedata->dynamic_section; | |
10535 | entry < filedata->dynamic_section + filedata->dynamic_nent; | |
10536 | ++entry) | |
10537 | if (entry->d_tag == DT_SYMTAB) | |
10538 | filedata->dynamic_info[DT_SYMTAB] = entry->d_un.d_val; | |
10539 | else if (entry->d_tag == DT_SYMENT) | |
10540 | filedata->dynamic_info[DT_SYMENT] = entry->d_un.d_val; | |
10541 | else if (entry->d_tag == DT_HASH) | |
10542 | filedata->dynamic_info[DT_HASH] = entry->d_un.d_val; | |
10543 | else if (entry->d_tag == DT_GNU_HASH) | |
10544 | filedata->dynamic_info_DT_GNU_HASH = entry->d_un.d_val; | |
10545 | else if ((filedata->file_header.e_machine == EM_MIPS | |
10546 | || filedata->file_header.e_machine == EM_MIPS_RS3_LE) | |
10547 | && entry->d_tag == DT_MIPS_XHASH) | |
10548 | { | |
10549 | filedata->dynamic_info_DT_MIPS_XHASH = entry->d_un.d_val; | |
10550 | filedata->dynamic_info_DT_GNU_HASH = entry->d_un.d_val; | |
10551 | } | |
10552 | ||
10553 | num_of_syms = get_num_dynamic_syms (filedata); | |
10554 | ||
10555 | if (num_of_syms != 0 | |
10556 | && filedata->dynamic_symbols == NULL | |
10557 | && filedata->dynamic_info[DT_SYMTAB] | |
10558 | && filedata->dynamic_info[DT_SYMENT]) | |
10559 | { | |
10560 | Elf_Internal_Phdr *seg; | |
10561 | bfd_vma vma = filedata->dynamic_info[DT_SYMTAB]; | |
10562 | ||
10563 | if (! get_program_headers (filedata)) | |
10564 | { | |
10565 | error (_("Cannot interpret virtual addresses " | |
10566 | "without program headers.\n")); | |
10567 | return FALSE; | |
10568 | } | |
10569 | ||
10570 | for (seg = filedata->program_headers; | |
10571 | seg < filedata->program_headers + filedata->file_header.e_phnum; | |
10572 | ++seg) | |
10573 | { | |
10574 | if (seg->p_type != PT_LOAD) | |
10575 | continue; | |
10576 | ||
10577 | if (seg->p_offset + seg->p_filesz > filedata->file_size) | |
10578 | { | |
10579 | /* See PR 21379 for a reproducer. */ | |
10580 | error (_("Invalid PT_LOAD entry\n")); | |
10581 | return FALSE; | |
10582 | } | |
10583 | ||
10584 | if (vma >= (seg->p_vaddr & -seg->p_align) | |
10585 | && vma < seg->p_vaddr + seg->p_filesz) | |
10586 | { | |
10587 | /* Since we do not know how big the symbol table is, | |
10588 | we default to reading in up to the end of PT_LOAD | |
10589 | segment and processing that. This is overkill, I | |
10590 | know, but it should work. */ | |
10591 | Elf_Internal_Shdr section; | |
10592 | section.sh_offset = (vma - seg->p_vaddr | |
10593 | + seg->p_offset); | |
10594 | section.sh_size = (num_of_syms | |
10595 | * filedata->dynamic_info[DT_SYMENT]); | |
10596 | section.sh_entsize = filedata->dynamic_info[DT_SYMENT]; | |
10597 | ||
10598 | if (do_checks | |
10599 | && filedata->dynamic_symtab_section != NULL | |
10600 | && ((filedata->dynamic_symtab_section->sh_offset | |
10601 | != section.sh_offset) | |
10602 | || (filedata->dynamic_symtab_section->sh_size | |
10603 | != section.sh_size) | |
10604 | || (filedata->dynamic_symtab_section->sh_entsize | |
10605 | != section.sh_entsize))) | |
10606 | warn (_("\ | |
10607 | the .dynsym section doesn't match the DT_SYMTAB and DT_SYMENT tags\n")); | |
10608 | ||
10609 | section.sh_name = filedata->string_table_length; | |
10610 | filedata->dynamic_symbols | |
10611 | = GET_ELF_SYMBOLS (filedata, §ion, | |
10612 | &filedata->num_dynamic_syms); | |
10613 | if (filedata->dynamic_symbols == NULL | |
10614 | || filedata->num_dynamic_syms != num_of_syms) | |
10615 | { | |
10616 | error (_("Corrupt DT_SYMTAB dynamic entry\n")); | |
10617 | return FALSE; | |
10618 | } | |
10619 | break; | |
10620 | } | |
10621 | } | |
10622 | } | |
10623 | } | |
10624 | ||
10625 | /* Similarly find a string table. */ | |
10626 | if (filedata->dynamic_strings == NULL) | |
10627 | for (entry = filedata->dynamic_section; | |
10628 | entry < filedata->dynamic_section + filedata->dynamic_nent; | |
10629 | ++entry) | |
10630 | { | |
10631 | if (entry->d_tag == DT_STRTAB) | |
10632 | filedata->dynamic_info[DT_STRTAB] = entry->d_un.d_val; | |
10633 | ||
10634 | if (entry->d_tag == DT_STRSZ) | |
10635 | filedata->dynamic_info[DT_STRSZ] = entry->d_un.d_val; | |
10636 | ||
10637 | if (filedata->dynamic_info[DT_STRTAB] | |
10638 | && filedata->dynamic_info[DT_STRSZ]) | |
10639 | { | |
10640 | unsigned long offset; | |
10641 | bfd_size_type str_tab_len = filedata->dynamic_info[DT_STRSZ]; | |
10642 | ||
10643 | offset = offset_from_vma (filedata, | |
10644 | filedata->dynamic_info[DT_STRTAB], | |
10645 | str_tab_len); | |
10646 | if (do_checks | |
10647 | && filedata->dynamic_strtab_section | |
10648 | && ((filedata->dynamic_strtab_section->sh_offset | |
10649 | != (file_ptr) offset) | |
10650 | || (filedata->dynamic_strtab_section->sh_size | |
10651 | != str_tab_len))) | |
10652 | warn (_("\ | |
10653 | the .dynstr section doesn't match the DT_STRTAB and DT_STRSZ tags\n")); | |
10654 | ||
10655 | filedata->dynamic_strings | |
10656 | = (char *) get_data (NULL, filedata, offset, 1, str_tab_len, | |
10657 | _("dynamic string table")); | |
10658 | if (filedata->dynamic_strings == NULL) | |
10659 | { | |
10660 | error (_("Corrupt DT_STRTAB dynamic entry\n")); | |
10661 | break; | |
10662 | } | |
10663 | ||
10664 | filedata->dynamic_strings_length = str_tab_len; | |
10665 | break; | |
10666 | } | |
10667 | } | |
10668 | ||
10669 | /* And find the syminfo section if available. */ | |
10670 | if (filedata->dynamic_syminfo == NULL) | |
10671 | { | |
10672 | unsigned long syminsz = 0; | |
10673 | ||
10674 | for (entry = filedata->dynamic_section; | |
10675 | entry < filedata->dynamic_section + filedata->dynamic_nent; | |
10676 | ++entry) | |
10677 | { | |
10678 | if (entry->d_tag == DT_SYMINENT) | |
10679 | { | |
10680 | /* Note: these braces are necessary to avoid a syntax | |
10681 | error from the SunOS4 C compiler. */ | |
10682 | /* PR binutils/17531: A corrupt file can trigger this test. | |
10683 | So do not use an assert, instead generate an error message. */ | |
10684 | if (sizeof (Elf_External_Syminfo) != entry->d_un.d_val) | |
10685 | error (_("Bad value (%d) for SYMINENT entry\n"), | |
10686 | (int) entry->d_un.d_val); | |
10687 | } | |
10688 | else if (entry->d_tag == DT_SYMINSZ) | |
10689 | syminsz = entry->d_un.d_val; | |
10690 | else if (entry->d_tag == DT_SYMINFO) | |
10691 | filedata->dynamic_syminfo_offset | |
10692 | = offset_from_vma (filedata, entry->d_un.d_val, syminsz); | |
10693 | } | |
10694 | ||
10695 | if (filedata->dynamic_syminfo_offset != 0 && syminsz != 0) | |
10696 | { | |
10697 | Elf_External_Syminfo * extsyminfo; | |
10698 | Elf_External_Syminfo * extsym; | |
10699 | Elf_Internal_Syminfo * syminfo; | |
10700 | ||
10701 | /* There is a syminfo section. Read the data. */ | |
10702 | extsyminfo = (Elf_External_Syminfo *) | |
10703 | get_data (NULL, filedata, filedata->dynamic_syminfo_offset, | |
10704 | 1, syminsz, _("symbol information")); | |
10705 | if (!extsyminfo) | |
10706 | return FALSE; | |
10707 | ||
10708 | if (filedata->dynamic_syminfo != NULL) | |
10709 | { | |
10710 | error (_("Multiple dynamic symbol information sections found\n")); | |
10711 | free (filedata->dynamic_syminfo); | |
10712 | } | |
10713 | filedata->dynamic_syminfo = (Elf_Internal_Syminfo *) malloc (syminsz); | |
10714 | if (filedata->dynamic_syminfo == NULL) | |
10715 | { | |
10716 | error (_("Out of memory allocating %lu bytes " | |
10717 | "for dynamic symbol info\n"), | |
10718 | (unsigned long) syminsz); | |
10719 | return FALSE; | |
10720 | } | |
10721 | ||
10722 | filedata->dynamic_syminfo_nent | |
10723 | = syminsz / sizeof (Elf_External_Syminfo); | |
10724 | for (syminfo = filedata->dynamic_syminfo, extsym = extsyminfo; | |
10725 | syminfo < (filedata->dynamic_syminfo | |
10726 | + filedata->dynamic_syminfo_nent); | |
10727 | ++syminfo, ++extsym) | |
10728 | { | |
10729 | syminfo->si_boundto = BYTE_GET (extsym->si_boundto); | |
10730 | syminfo->si_flags = BYTE_GET (extsym->si_flags); | |
10731 | } | |
10732 | ||
10733 | free (extsyminfo); | |
10734 | } | |
10735 | } | |
10736 | ||
10737 | if (do_dynamic && filedata->dynamic_addr) | |
10738 | { | |
10739 | if (filedata->dynamic_nent == 1) | |
10740 | { | |
10741 | if (filedata->is_separate) | |
10742 | printf (_("\nIn linked file '%s' the dynamic section at offset 0x%lx contains 1 entry:\n"), | |
10743 | filedata->file_name, | |
10744 | filedata->dynamic_addr); | |
10745 | else | |
10746 | printf (_("\nDynamic section at offset 0x%lx contains 1 entry:\n"), | |
10747 | filedata->dynamic_addr); | |
10748 | } | |
10749 | else | |
10750 | { | |
10751 | if (filedata->is_separate) | |
10752 | printf (_("\nIn linked file '%s' the dynamic section at offset 0x%lx contains %lu entries:\n"), | |
10753 | filedata->file_name, | |
10754 | filedata->dynamic_addr, | |
10755 | (unsigned long) filedata->dynamic_nent); | |
10756 | else | |
10757 | printf (_("\nDynamic section at offset 0x%lx contains %lu entries:\n"), | |
10758 | filedata->dynamic_addr, | |
10759 | (unsigned long) filedata->dynamic_nent); | |
10760 | } | |
10761 | } | |
10762 | if (do_dynamic) | |
10763 | printf (_(" Tag Type Name/Value\n")); | |
10764 | ||
10765 | for (entry = filedata->dynamic_section; | |
10766 | entry < filedata->dynamic_section + filedata->dynamic_nent; | |
10767 | entry++) | |
10768 | { | |
10769 | if (do_dynamic) | |
10770 | { | |
10771 | const char * dtype; | |
10772 | ||
10773 | putchar (' '); | |
10774 | print_vma (entry->d_tag, FULL_HEX); | |
10775 | dtype = get_dynamic_type (filedata, entry->d_tag); | |
10776 | printf (" (%s)%*s", dtype, | |
10777 | ((is_32bit_elf ? 27 : 19) - (int) strlen (dtype)), " "); | |
10778 | } | |
10779 | ||
10780 | switch (entry->d_tag) | |
10781 | { | |
10782 | case DT_FLAGS: | |
10783 | if (do_dynamic) | |
10784 | print_dynamic_flags (entry->d_un.d_val); | |
10785 | break; | |
10786 | ||
10787 | case DT_AUXILIARY: | |
10788 | case DT_FILTER: | |
10789 | case DT_CONFIG: | |
10790 | case DT_DEPAUDIT: | |
10791 | case DT_AUDIT: | |
10792 | if (do_dynamic) | |
10793 | { | |
10794 | switch (entry->d_tag) | |
10795 | { | |
10796 | case DT_AUXILIARY: | |
10797 | printf (_("Auxiliary library")); | |
10798 | break; | |
10799 | ||
10800 | case DT_FILTER: | |
10801 | printf (_("Filter library")); | |
10802 | break; | |
10803 | ||
10804 | case DT_CONFIG: | |
10805 | printf (_("Configuration file")); | |
10806 | break; | |
10807 | ||
10808 | case DT_DEPAUDIT: | |
10809 | printf (_("Dependency audit library")); | |
10810 | break; | |
10811 | ||
10812 | case DT_AUDIT: | |
10813 | printf (_("Audit library")); | |
10814 | break; | |
10815 | } | |
10816 | ||
10817 | if (VALID_DYNAMIC_NAME (filedata, entry->d_un.d_val)) | |
10818 | printf (": [%s]\n", | |
10819 | GET_DYNAMIC_NAME (filedata, entry->d_un.d_val)); | |
10820 | else | |
10821 | { | |
10822 | printf (": "); | |
10823 | print_vma (entry->d_un.d_val, PREFIX_HEX); | |
10824 | putchar ('\n'); | |
10825 | } | |
10826 | } | |
10827 | break; | |
10828 | ||
10829 | case DT_FEATURE: | |
10830 | if (do_dynamic) | |
10831 | { | |
10832 | printf (_("Flags:")); | |
10833 | ||
10834 | if (entry->d_un.d_val == 0) | |
10835 | printf (_(" None\n")); | |
10836 | else | |
10837 | { | |
10838 | unsigned long int val = entry->d_un.d_val; | |
10839 | ||
10840 | if (val & DTF_1_PARINIT) | |
10841 | { | |
10842 | printf (" PARINIT"); | |
10843 | val ^= DTF_1_PARINIT; | |
10844 | } | |
10845 | if (val & DTF_1_CONFEXP) | |
10846 | { | |
10847 | printf (" CONFEXP"); | |
10848 | val ^= DTF_1_CONFEXP; | |
10849 | } | |
10850 | if (val != 0) | |
10851 | printf (" %lx", val); | |
10852 | puts (""); | |
10853 | } | |
10854 | } | |
10855 | break; | |
10856 | ||
10857 | case DT_POSFLAG_1: | |
10858 | if (do_dynamic) | |
10859 | { | |
10860 | printf (_("Flags:")); | |
10861 | ||
10862 | if (entry->d_un.d_val == 0) | |
10863 | printf (_(" None\n")); | |
10864 | else | |
10865 | { | |
10866 | unsigned long int val = entry->d_un.d_val; | |
10867 | ||
10868 | if (val & DF_P1_LAZYLOAD) | |
10869 | { | |
10870 | printf (" LAZYLOAD"); | |
10871 | val ^= DF_P1_LAZYLOAD; | |
10872 | } | |
10873 | if (val & DF_P1_GROUPPERM) | |
10874 | { | |
10875 | printf (" GROUPPERM"); | |
10876 | val ^= DF_P1_GROUPPERM; | |
10877 | } | |
10878 | if (val != 0) | |
10879 | printf (" %lx", val); | |
10880 | puts (""); | |
10881 | } | |
10882 | } | |
10883 | break; | |
10884 | ||
10885 | case DT_FLAGS_1: | |
10886 | if (do_dynamic) | |
10887 | { | |
10888 | printf (_("Flags:")); | |
10889 | if (entry->d_un.d_val == 0) | |
10890 | printf (_(" None\n")); | |
10891 | else | |
10892 | { | |
10893 | unsigned long int val = entry->d_un.d_val; | |
10894 | ||
10895 | if (val & DF_1_NOW) | |
10896 | { | |
10897 | printf (" NOW"); | |
10898 | val ^= DF_1_NOW; | |
10899 | } | |
10900 | if (val & DF_1_GLOBAL) | |
10901 | { | |
10902 | printf (" GLOBAL"); | |
10903 | val ^= DF_1_GLOBAL; | |
10904 | } | |
10905 | if (val & DF_1_GROUP) | |
10906 | { | |
10907 | printf (" GROUP"); | |
10908 | val ^= DF_1_GROUP; | |
10909 | } | |
10910 | if (val & DF_1_NODELETE) | |
10911 | { | |
10912 | printf (" NODELETE"); | |
10913 | val ^= DF_1_NODELETE; | |
10914 | } | |
10915 | if (val & DF_1_LOADFLTR) | |
10916 | { | |
10917 | printf (" LOADFLTR"); | |
10918 | val ^= DF_1_LOADFLTR; | |
10919 | } | |
10920 | if (val & DF_1_INITFIRST) | |
10921 | { | |
10922 | printf (" INITFIRST"); | |
10923 | val ^= DF_1_INITFIRST; | |
10924 | } | |
10925 | if (val & DF_1_NOOPEN) | |
10926 | { | |
10927 | printf (" NOOPEN"); | |
10928 | val ^= DF_1_NOOPEN; | |
10929 | } | |
10930 | if (val & DF_1_ORIGIN) | |
10931 | { | |
10932 | printf (" ORIGIN"); | |
10933 | val ^= DF_1_ORIGIN; | |
10934 | } | |
10935 | if (val & DF_1_DIRECT) | |
10936 | { | |
10937 | printf (" DIRECT"); | |
10938 | val ^= DF_1_DIRECT; | |
10939 | } | |
10940 | if (val & DF_1_TRANS) | |
10941 | { | |
10942 | printf (" TRANS"); | |
10943 | val ^= DF_1_TRANS; | |
10944 | } | |
10945 | if (val & DF_1_INTERPOSE) | |
10946 | { | |
10947 | printf (" INTERPOSE"); | |
10948 | val ^= DF_1_INTERPOSE; | |
10949 | } | |
10950 | if (val & DF_1_NODEFLIB) | |
10951 | { | |
10952 | printf (" NODEFLIB"); | |
10953 | val ^= DF_1_NODEFLIB; | |
10954 | } | |
10955 | if (val & DF_1_NODUMP) | |
10956 | { | |
10957 | printf (" NODUMP"); | |
10958 | val ^= DF_1_NODUMP; | |
10959 | } | |
10960 | if (val & DF_1_CONFALT) | |
10961 | { | |
10962 | printf (" CONFALT"); | |
10963 | val ^= DF_1_CONFALT; | |
10964 | } | |
10965 | if (val & DF_1_ENDFILTEE) | |
10966 | { | |
10967 | printf (" ENDFILTEE"); | |
10968 | val ^= DF_1_ENDFILTEE; | |
10969 | } | |
10970 | if (val & DF_1_DISPRELDNE) | |
10971 | { | |
10972 | printf (" DISPRELDNE"); | |
10973 | val ^= DF_1_DISPRELDNE; | |
10974 | } | |
10975 | if (val & DF_1_DISPRELPND) | |
10976 | { | |
10977 | printf (" DISPRELPND"); | |
10978 | val ^= DF_1_DISPRELPND; | |
10979 | } | |
10980 | if (val & DF_1_NODIRECT) | |
10981 | { | |
10982 | printf (" NODIRECT"); | |
10983 | val ^= DF_1_NODIRECT; | |
10984 | } | |
10985 | if (val & DF_1_IGNMULDEF) | |
10986 | { | |
10987 | printf (" IGNMULDEF"); | |
10988 | val ^= DF_1_IGNMULDEF; | |
10989 | } | |
10990 | if (val & DF_1_NOKSYMS) | |
10991 | { | |
10992 | printf (" NOKSYMS"); | |
10993 | val ^= DF_1_NOKSYMS; | |
10994 | } | |
10995 | if (val & DF_1_NOHDR) | |
10996 | { | |
10997 | printf (" NOHDR"); | |
10998 | val ^= DF_1_NOHDR; | |
10999 | } | |
11000 | if (val & DF_1_EDITED) | |
11001 | { | |
11002 | printf (" EDITED"); | |
11003 | val ^= DF_1_EDITED; | |
11004 | } | |
11005 | if (val & DF_1_NORELOC) | |
11006 | { | |
11007 | printf (" NORELOC"); | |
11008 | val ^= DF_1_NORELOC; | |
11009 | } | |
11010 | if (val & DF_1_SYMINTPOSE) | |
11011 | { | |
11012 | printf (" SYMINTPOSE"); | |
11013 | val ^= DF_1_SYMINTPOSE; | |
11014 | } | |
11015 | if (val & DF_1_GLOBAUDIT) | |
11016 | { | |
11017 | printf (" GLOBAUDIT"); | |
11018 | val ^= DF_1_GLOBAUDIT; | |
11019 | } | |
11020 | if (val & DF_1_SINGLETON) | |
11021 | { | |
11022 | printf (" SINGLETON"); | |
11023 | val ^= DF_1_SINGLETON; | |
11024 | } | |
11025 | if (val & DF_1_STUB) | |
11026 | { | |
11027 | printf (" STUB"); | |
11028 | val ^= DF_1_STUB; | |
11029 | } | |
11030 | if (val & DF_1_PIE) | |
11031 | { | |
11032 | printf (" PIE"); | |
11033 | val ^= DF_1_PIE; | |
11034 | } | |
11035 | if (val & DF_1_KMOD) | |
11036 | { | |
11037 | printf (" KMOD"); | |
11038 | val ^= DF_1_KMOD; | |
11039 | } | |
11040 | if (val & DF_1_WEAKFILTER) | |
11041 | { | |
11042 | printf (" WEAKFILTER"); | |
11043 | val ^= DF_1_WEAKFILTER; | |
11044 | } | |
11045 | if (val & DF_1_NOCOMMON) | |
11046 | { | |
11047 | printf (" NOCOMMON"); | |
11048 | val ^= DF_1_NOCOMMON; | |
11049 | } | |
11050 | if (val != 0) | |
11051 | printf (" %lx", val); | |
11052 | puts (""); | |
11053 | } | |
11054 | } | |
11055 | break; | |
11056 | ||
11057 | case DT_PLTREL: | |
11058 | filedata->dynamic_info[entry->d_tag] = entry->d_un.d_val; | |
11059 | if (do_dynamic) | |
11060 | puts (get_dynamic_type (filedata, entry->d_un.d_val)); | |
11061 | break; | |
11062 | ||
11063 | case DT_NULL : | |
11064 | case DT_NEEDED : | |
11065 | case DT_PLTGOT : | |
11066 | case DT_HASH : | |
11067 | case DT_STRTAB : | |
11068 | case DT_SYMTAB : | |
11069 | case DT_RELA : | |
11070 | case DT_INIT : | |
11071 | case DT_FINI : | |
11072 | case DT_SONAME : | |
11073 | case DT_RPATH : | |
11074 | case DT_SYMBOLIC: | |
11075 | case DT_REL : | |
11076 | case DT_DEBUG : | |
11077 | case DT_TEXTREL : | |
11078 | case DT_JMPREL : | |
11079 | case DT_RUNPATH : | |
11080 | filedata->dynamic_info[entry->d_tag] = entry->d_un.d_val; | |
11081 | ||
11082 | if (do_dynamic) | |
11083 | { | |
11084 | char * name; | |
11085 | ||
11086 | if (VALID_DYNAMIC_NAME (filedata, entry->d_un.d_val)) | |
11087 | name = GET_DYNAMIC_NAME (filedata, entry->d_un.d_val); | |
11088 | else | |
11089 | name = NULL; | |
11090 | ||
11091 | if (name) | |
11092 | { | |
11093 | switch (entry->d_tag) | |
11094 | { | |
11095 | case DT_NEEDED: | |
11096 | printf (_("Shared library: [%s]"), name); | |
11097 | ||
11098 | if (streq (name, filedata->program_interpreter)) | |
11099 | printf (_(" program interpreter")); | |
11100 | break; | |
11101 | ||
11102 | case DT_SONAME: | |
11103 | printf (_("Library soname: [%s]"), name); | |
11104 | break; | |
11105 | ||
11106 | case DT_RPATH: | |
11107 | printf (_("Library rpath: [%s]"), name); | |
11108 | break; | |
11109 | ||
11110 | case DT_RUNPATH: | |
11111 | printf (_("Library runpath: [%s]"), name); | |
11112 | break; | |
11113 | ||
11114 | default: | |
11115 | print_vma (entry->d_un.d_val, PREFIX_HEX); | |
11116 | break; | |
11117 | } | |
11118 | } | |
11119 | else | |
11120 | print_vma (entry->d_un.d_val, PREFIX_HEX); | |
11121 | ||
11122 | putchar ('\n'); | |
11123 | } | |
11124 | break; | |
11125 | ||
11126 | case DT_PLTRELSZ: | |
11127 | case DT_RELASZ : | |
11128 | case DT_STRSZ : | |
11129 | case DT_RELSZ : | |
11130 | case DT_RELAENT : | |
11131 | case DT_SYMENT : | |
11132 | case DT_RELENT : | |
11133 | filedata->dynamic_info[entry->d_tag] = entry->d_un.d_val; | |
11134 | /* Fall through. */ | |
11135 | case DT_PLTPADSZ: | |
11136 | case DT_MOVEENT : | |
11137 | case DT_MOVESZ : | |
11138 | case DT_INIT_ARRAYSZ: | |
11139 | case DT_FINI_ARRAYSZ: | |
11140 | case DT_GNU_CONFLICTSZ: | |
11141 | case DT_GNU_LIBLISTSZ: | |
11142 | if (do_dynamic) | |
11143 | { | |
11144 | print_vma (entry->d_un.d_val, UNSIGNED); | |
11145 | printf (_(" (bytes)\n")); | |
11146 | } | |
11147 | break; | |
11148 | ||
11149 | case DT_VERDEFNUM: | |
11150 | case DT_VERNEEDNUM: | |
11151 | case DT_RELACOUNT: | |
11152 | case DT_RELCOUNT: | |
11153 | if (do_dynamic) | |
11154 | { | |
11155 | print_vma (entry->d_un.d_val, UNSIGNED); | |
11156 | putchar ('\n'); | |
11157 | } | |
11158 | break; | |
11159 | ||
11160 | case DT_SYMINSZ: | |
11161 | case DT_SYMINENT: | |
11162 | case DT_SYMINFO: | |
11163 | case DT_USED: | |
11164 | case DT_INIT_ARRAY: | |
11165 | case DT_FINI_ARRAY: | |
11166 | if (do_dynamic) | |
11167 | { | |
11168 | if (entry->d_tag == DT_USED | |
11169 | && VALID_DYNAMIC_NAME (filedata, entry->d_un.d_val)) | |
11170 | { | |
11171 | char * name = GET_DYNAMIC_NAME (filedata, entry->d_un.d_val); | |
11172 | ||
11173 | if (*name) | |
11174 | { | |
11175 | printf (_("Not needed object: [%s]\n"), name); | |
11176 | break; | |
11177 | } | |
11178 | } | |
11179 | ||
11180 | print_vma (entry->d_un.d_val, PREFIX_HEX); | |
11181 | putchar ('\n'); | |
11182 | } | |
11183 | break; | |
11184 | ||
11185 | case DT_BIND_NOW: | |
11186 | /* The value of this entry is ignored. */ | |
11187 | if (do_dynamic) | |
11188 | putchar ('\n'); | |
11189 | break; | |
11190 | ||
11191 | case DT_GNU_PRELINKED: | |
11192 | if (do_dynamic) | |
11193 | { | |
11194 | struct tm * tmp; | |
11195 | time_t atime = entry->d_un.d_val; | |
11196 | ||
11197 | tmp = gmtime (&atime); | |
11198 | /* PR 17533 file: 041-1244816-0.004. */ | |
11199 | if (tmp == NULL) | |
11200 | printf (_("<corrupt time val: %lx"), | |
11201 | (unsigned long) atime); | |
11202 | else | |
11203 | printf ("%04u-%02u-%02uT%02u:%02u:%02u\n", | |
11204 | tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday, | |
11205 | tmp->tm_hour, tmp->tm_min, tmp->tm_sec); | |
11206 | ||
11207 | } | |
11208 | break; | |
11209 | ||
11210 | case DT_GNU_HASH: | |
11211 | filedata->dynamic_info_DT_GNU_HASH = entry->d_un.d_val; | |
11212 | if (do_dynamic) | |
11213 | { | |
11214 | print_vma (entry->d_un.d_val, PREFIX_HEX); | |
11215 | putchar ('\n'); | |
11216 | } | |
11217 | break; | |
11218 | ||
11219 | case DT_GNU_FLAGS_1: | |
11220 | if (do_dynamic) | |
11221 | { | |
11222 | printf (_("Flags:")); | |
11223 | if (entry->d_un.d_val == 0) | |
11224 | printf (_(" None\n")); | |
11225 | else | |
11226 | { | |
11227 | unsigned long int val = entry->d_un.d_val; | |
11228 | ||
11229 | if (val & DF_GNU_1_UNIQUE) | |
11230 | { | |
11231 | printf (" UNIQUE"); | |
11232 | val ^= DF_GNU_1_UNIQUE; | |
11233 | } | |
11234 | if (val != 0) | |
11235 | printf (" %lx", val); | |
11236 | puts (""); | |
11237 | } | |
11238 | } | |
11239 | break; | |
11240 | ||
11241 | default: | |
11242 | if ((entry->d_tag >= DT_VERSYM) && (entry->d_tag <= DT_VERNEEDNUM)) | |
11243 | filedata->version_info[DT_VERSIONTAGIDX (entry->d_tag)] | |
11244 | = entry->d_un.d_val; | |
11245 | ||
11246 | if (do_dynamic) | |
11247 | { | |
11248 | switch (filedata->file_header.e_machine) | |
11249 | { | |
11250 | case EM_AARCH64: | |
11251 | dynamic_section_aarch64_val (entry); | |
11252 | break; | |
11253 | case EM_MIPS: | |
11254 | case EM_MIPS_RS3_LE: | |
11255 | dynamic_section_mips_val (filedata, entry); | |
11256 | break; | |
11257 | case EM_PARISC: | |
11258 | dynamic_section_parisc_val (entry); | |
11259 | break; | |
11260 | case EM_IA_64: | |
11261 | dynamic_section_ia64_val (entry); | |
11262 | break; | |
11263 | default: | |
11264 | print_vma (entry->d_un.d_val, PREFIX_HEX); | |
11265 | putchar ('\n'); | |
11266 | } | |
11267 | } | |
11268 | break; | |
11269 | } | |
11270 | } | |
11271 | ||
11272 | return TRUE; | |
11273 | } | |
11274 | ||
11275 | static char * | |
11276 | get_ver_flags (unsigned int flags) | |
11277 | { | |
11278 | static char buff[128]; | |
11279 | ||
11280 | buff[0] = 0; | |
11281 | ||
11282 | if (flags == 0) | |
11283 | return _("none"); | |
11284 | ||
11285 | if (flags & VER_FLG_BASE) | |
11286 | strcat (buff, "BASE"); | |
11287 | ||
11288 | if (flags & VER_FLG_WEAK) | |
11289 | { | |
11290 | if (flags & VER_FLG_BASE) | |
11291 | strcat (buff, " | "); | |
11292 | ||
11293 | strcat (buff, "WEAK"); | |
11294 | } | |
11295 | ||
11296 | if (flags & VER_FLG_INFO) | |
11297 | { | |
11298 | if (flags & (VER_FLG_BASE|VER_FLG_WEAK)) | |
11299 | strcat (buff, " | "); | |
11300 | ||
11301 | strcat (buff, "INFO"); | |
11302 | } | |
11303 | ||
11304 | if (flags & ~(VER_FLG_BASE | VER_FLG_WEAK | VER_FLG_INFO)) | |
11305 | { | |
11306 | if (flags & (VER_FLG_BASE | VER_FLG_WEAK | VER_FLG_INFO)) | |
11307 | strcat (buff, " | "); | |
11308 | ||
11309 | strcat (buff, _("<unknown>")); | |
11310 | } | |
11311 | ||
11312 | return buff; | |
11313 | } | |
11314 | ||
11315 | /* Display the contents of the version sections. */ | |
11316 | ||
11317 | static bfd_boolean | |
11318 | process_version_sections (Filedata * filedata) | |
11319 | { | |
11320 | Elf_Internal_Shdr * section; | |
11321 | unsigned i; | |
11322 | bfd_boolean found = FALSE; | |
11323 | ||
11324 | if (! do_version) | |
11325 | return TRUE; | |
11326 | ||
11327 | for (i = 0, section = filedata->section_headers; | |
11328 | i < filedata->file_header.e_shnum; | |
11329 | i++, section++) | |
11330 | { | |
11331 | switch (section->sh_type) | |
11332 | { | |
11333 | case SHT_GNU_verdef: | |
11334 | { | |
11335 | Elf_External_Verdef * edefs; | |
11336 | unsigned long idx; | |
11337 | unsigned long cnt; | |
11338 | char * endbuf; | |
11339 | ||
11340 | found = TRUE; | |
11341 | ||
11342 | if (filedata->is_separate) | |
11343 | printf (ngettext ("\nIn linked file '%s' the version definition section '%s' contains %u entry:\n", | |
11344 | "\nIn linked file '%s' the version definition section '%s' contains %u entries:\n", | |
11345 | section->sh_info), | |
11346 | filedata->file_name, | |
11347 | printable_section_name (filedata, section), | |
11348 | section->sh_info); | |
11349 | else | |
11350 | printf (ngettext ("\nVersion definition section '%s' " | |
11351 | "contains %u entry:\n", | |
11352 | "\nVersion definition section '%s' " | |
11353 | "contains %u entries:\n", | |
11354 | section->sh_info), | |
11355 | printable_section_name (filedata, section), | |
11356 | section->sh_info); | |
11357 | ||
11358 | printf (_(" Addr: 0x")); | |
11359 | printf_vma (section->sh_addr); | |
11360 | printf (_(" Offset: %#08lx Link: %u (%s)\n"), | |
11361 | (unsigned long) section->sh_offset, section->sh_link, | |
11362 | printable_section_name_from_index (filedata, section->sh_link)); | |
11363 | ||
11364 | edefs = (Elf_External_Verdef *) | |
11365 | get_data (NULL, filedata, section->sh_offset, 1,section->sh_size, | |
11366 | _("version definition section")); | |
11367 | if (!edefs) | |
11368 | break; | |
11369 | endbuf = (char *) edefs + section->sh_size; | |
11370 | ||
11371 | for (idx = cnt = 0; cnt < section->sh_info; ++cnt) | |
11372 | { | |
11373 | char * vstart; | |
11374 | Elf_External_Verdef * edef; | |
11375 | Elf_Internal_Verdef ent; | |
11376 | Elf_External_Verdaux * eaux; | |
11377 | Elf_Internal_Verdaux aux; | |
11378 | unsigned long isum; | |
11379 | int j; | |
11380 | ||
11381 | vstart = ((char *) edefs) + idx; | |
11382 | if (vstart + sizeof (*edef) > endbuf) | |
11383 | break; | |
11384 | ||
11385 | edef = (Elf_External_Verdef *) vstart; | |
11386 | ||
11387 | ent.vd_version = BYTE_GET (edef->vd_version); | |
11388 | ent.vd_flags = BYTE_GET (edef->vd_flags); | |
11389 | ent.vd_ndx = BYTE_GET (edef->vd_ndx); | |
11390 | ent.vd_cnt = BYTE_GET (edef->vd_cnt); | |
11391 | ent.vd_hash = BYTE_GET (edef->vd_hash); | |
11392 | ent.vd_aux = BYTE_GET (edef->vd_aux); | |
11393 | ent.vd_next = BYTE_GET (edef->vd_next); | |
11394 | ||
11395 | printf (_(" %#06lx: Rev: %d Flags: %s"), | |
11396 | idx, ent.vd_version, get_ver_flags (ent.vd_flags)); | |
11397 | ||
11398 | printf (_(" Index: %d Cnt: %d "), | |
11399 | ent.vd_ndx, ent.vd_cnt); | |
11400 | ||
11401 | /* Check for overflow. */ | |
11402 | if (ent.vd_aux > (size_t) (endbuf - vstart)) | |
11403 | break; | |
11404 | ||
11405 | vstart += ent.vd_aux; | |
11406 | ||
11407 | if (vstart + sizeof (*eaux) > endbuf) | |
11408 | break; | |
11409 | eaux = (Elf_External_Verdaux *) vstart; | |
11410 | ||
11411 | aux.vda_name = BYTE_GET (eaux->vda_name); | |
11412 | aux.vda_next = BYTE_GET (eaux->vda_next); | |
11413 | ||
11414 | if (VALID_DYNAMIC_NAME (filedata, aux.vda_name)) | |
11415 | printf (_("Name: %s\n"), | |
11416 | GET_DYNAMIC_NAME (filedata, aux.vda_name)); | |
11417 | else | |
11418 | printf (_("Name index: %ld\n"), aux.vda_name); | |
11419 | ||
11420 | isum = idx + ent.vd_aux; | |
11421 | ||
11422 | for (j = 1; j < ent.vd_cnt; j++) | |
11423 | { | |
11424 | if (aux.vda_next < sizeof (*eaux) | |
11425 | && !(j == ent.vd_cnt - 1 && aux.vda_next == 0)) | |
11426 | { | |
11427 | warn (_("Invalid vda_next field of %lx\n"), | |
11428 | aux.vda_next); | |
11429 | j = ent.vd_cnt; | |
11430 | break; | |
11431 | } | |
11432 | /* Check for overflow. */ | |
11433 | if (aux.vda_next > (size_t) (endbuf - vstart)) | |
11434 | break; | |
11435 | ||
11436 | isum += aux.vda_next; | |
11437 | vstart += aux.vda_next; | |
11438 | ||
11439 | if (vstart + sizeof (*eaux) > endbuf) | |
11440 | break; | |
11441 | eaux = (Elf_External_Verdaux *) vstart; | |
11442 | ||
11443 | aux.vda_name = BYTE_GET (eaux->vda_name); | |
11444 | aux.vda_next = BYTE_GET (eaux->vda_next); | |
11445 | ||
11446 | if (VALID_DYNAMIC_NAME (filedata, aux.vda_name)) | |
11447 | printf (_(" %#06lx: Parent %d: %s\n"), | |
11448 | isum, j, | |
11449 | GET_DYNAMIC_NAME (filedata, aux.vda_name)); | |
11450 | else | |
11451 | printf (_(" %#06lx: Parent %d, name index: %ld\n"), | |
11452 | isum, j, aux.vda_name); | |
11453 | } | |
11454 | ||
11455 | if (j < ent.vd_cnt) | |
11456 | printf (_(" Version def aux past end of section\n")); | |
11457 | ||
11458 | /* PR 17531: | |
11459 | file: id:000001,src:000172+005151,op:splice,rep:2. */ | |
11460 | if (ent.vd_next < sizeof (*edef) | |
11461 | && !(cnt == section->sh_info - 1 && ent.vd_next == 0)) | |
11462 | { | |
11463 | warn (_("Invalid vd_next field of %lx\n"), ent.vd_next); | |
11464 | cnt = section->sh_info; | |
11465 | break; | |
11466 | } | |
11467 | if (ent.vd_next > (size_t) (endbuf - ((char *) edefs + idx))) | |
11468 | break; | |
11469 | ||
11470 | idx += ent.vd_next; | |
11471 | } | |
11472 | ||
11473 | if (cnt < section->sh_info) | |
11474 | printf (_(" Version definition past end of section\n")); | |
11475 | ||
11476 | free (edefs); | |
11477 | } | |
11478 | break; | |
11479 | ||
11480 | case SHT_GNU_verneed: | |
11481 | { | |
11482 | Elf_External_Verneed * eneed; | |
11483 | unsigned long idx; | |
11484 | unsigned long cnt; | |
11485 | char * endbuf; | |
11486 | ||
11487 | found = TRUE; | |
11488 | ||
11489 | if (filedata->is_separate) | |
11490 | printf (ngettext ("\nIn linked file '%s' the version needs section '%s' contains %u entry:\n", | |
11491 | "\nIn linked file '%s' the version needs section '%s' contains %u entries:\n", | |
11492 | section->sh_info), | |
11493 | filedata->file_name, | |
11494 | printable_section_name (filedata, section), | |
11495 | section->sh_info); | |
11496 | else | |
11497 | printf (ngettext ("\nVersion needs section '%s' " | |
11498 | "contains %u entry:\n", | |
11499 | "\nVersion needs section '%s' " | |
11500 | "contains %u entries:\n", | |
11501 | section->sh_info), | |
11502 | printable_section_name (filedata, section), | |
11503 | section->sh_info); | |
11504 | ||
11505 | printf (_(" Addr: 0x")); | |
11506 | printf_vma (section->sh_addr); | |
11507 | printf (_(" Offset: %#08lx Link: %u (%s)\n"), | |
11508 | (unsigned long) section->sh_offset, section->sh_link, | |
11509 | printable_section_name_from_index (filedata, section->sh_link)); | |
11510 | ||
11511 | eneed = (Elf_External_Verneed *) get_data (NULL, filedata, | |
11512 | section->sh_offset, 1, | |
11513 | section->sh_size, | |
11514 | _("Version Needs section")); | |
11515 | if (!eneed) | |
11516 | break; | |
11517 | endbuf = (char *) eneed + section->sh_size; | |
11518 | ||
11519 | for (idx = cnt = 0; cnt < section->sh_info; ++cnt) | |
11520 | { | |
11521 | Elf_External_Verneed * entry; | |
11522 | Elf_Internal_Verneed ent; | |
11523 | unsigned long isum; | |
11524 | int j; | |
11525 | char * vstart; | |
11526 | ||
11527 | vstart = ((char *) eneed) + idx; | |
11528 | if (vstart + sizeof (*entry) > endbuf) | |
11529 | break; | |
11530 | ||
11531 | entry = (Elf_External_Verneed *) vstart; | |
11532 | ||
11533 | ent.vn_version = BYTE_GET (entry->vn_version); | |
11534 | ent.vn_cnt = BYTE_GET (entry->vn_cnt); | |
11535 | ent.vn_file = BYTE_GET (entry->vn_file); | |
11536 | ent.vn_aux = BYTE_GET (entry->vn_aux); | |
11537 | ent.vn_next = BYTE_GET (entry->vn_next); | |
11538 | ||
11539 | printf (_(" %#06lx: Version: %d"), idx, ent.vn_version); | |
11540 | ||
11541 | if (VALID_DYNAMIC_NAME (filedata, ent.vn_file)) | |
11542 | printf (_(" File: %s"), | |
11543 | GET_DYNAMIC_NAME (filedata, ent.vn_file)); | |
11544 | else | |
11545 | printf (_(" File: %lx"), ent.vn_file); | |
11546 | ||
11547 | printf (_(" Cnt: %d\n"), ent.vn_cnt); | |
11548 | ||
11549 | /* Check for overflow. */ | |
11550 | if (ent.vn_aux > (size_t) (endbuf - vstart)) | |
11551 | break; | |
11552 | vstart += ent.vn_aux; | |
11553 | ||
11554 | for (j = 0, isum = idx + ent.vn_aux; j < ent.vn_cnt; ++j) | |
11555 | { | |
11556 | Elf_External_Vernaux * eaux; | |
11557 | Elf_Internal_Vernaux aux; | |
11558 | ||
11559 | if (vstart + sizeof (*eaux) > endbuf) | |
11560 | break; | |
11561 | eaux = (Elf_External_Vernaux *) vstart; | |
11562 | ||
11563 | aux.vna_hash = BYTE_GET (eaux->vna_hash); | |
11564 | aux.vna_flags = BYTE_GET (eaux->vna_flags); | |
11565 | aux.vna_other = BYTE_GET (eaux->vna_other); | |
11566 | aux.vna_name = BYTE_GET (eaux->vna_name); | |
11567 | aux.vna_next = BYTE_GET (eaux->vna_next); | |
11568 | ||
11569 | if (VALID_DYNAMIC_NAME (filedata, aux.vna_name)) | |
11570 | printf (_(" %#06lx: Name: %s"), | |
11571 | isum, GET_DYNAMIC_NAME (filedata, aux.vna_name)); | |
11572 | else | |
11573 | printf (_(" %#06lx: Name index: %lx"), | |
11574 | isum, aux.vna_name); | |
11575 | ||
11576 | printf (_(" Flags: %s Version: %d\n"), | |
11577 | get_ver_flags (aux.vna_flags), aux.vna_other); | |
11578 | ||
11579 | if (aux.vna_next < sizeof (*eaux) | |
11580 | && !(j == ent.vn_cnt - 1 && aux.vna_next == 0)) | |
11581 | { | |
11582 | warn (_("Invalid vna_next field of %lx\n"), | |
11583 | aux.vna_next); | |
11584 | j = ent.vn_cnt; | |
11585 | break; | |
11586 | } | |
11587 | /* Check for overflow. */ | |
11588 | if (aux.vna_next > (size_t) (endbuf - vstart)) | |
11589 | break; | |
11590 | isum += aux.vna_next; | |
11591 | vstart += aux.vna_next; | |
11592 | } | |
11593 | ||
11594 | if (j < ent.vn_cnt) | |
11595 | warn (_("Missing Version Needs auxiliary information\n")); | |
11596 | ||
11597 | if (ent.vn_next < sizeof (*entry) | |
11598 | && !(cnt == section->sh_info - 1 && ent.vn_next == 0)) | |
11599 | { | |
11600 | warn (_("Invalid vn_next field of %lx\n"), ent.vn_next); | |
11601 | cnt = section->sh_info; | |
11602 | break; | |
11603 | } | |
11604 | if (ent.vn_next > (size_t) (endbuf - ((char *) eneed + idx))) | |
11605 | break; | |
11606 | idx += ent.vn_next; | |
11607 | } | |
11608 | ||
11609 | if (cnt < section->sh_info) | |
11610 | warn (_("Missing Version Needs information\n")); | |
11611 | ||
11612 | free (eneed); | |
11613 | } | |
11614 | break; | |
11615 | ||
11616 | case SHT_GNU_versym: | |
11617 | { | |
11618 | Elf_Internal_Shdr * link_section; | |
11619 | size_t total; | |
11620 | unsigned int cnt; | |
11621 | unsigned char * edata; | |
11622 | unsigned short * data; | |
11623 | char * strtab; | |
11624 | Elf_Internal_Sym * symbols; | |
11625 | Elf_Internal_Shdr * string_sec; | |
11626 | unsigned long num_syms; | |
11627 | long off; | |
11628 | ||
11629 | if (section->sh_link >= filedata->file_header.e_shnum) | |
11630 | break; | |
11631 | ||
11632 | link_section = filedata->section_headers + section->sh_link; | |
11633 | total = section->sh_size / sizeof (Elf_External_Versym); | |
11634 | ||
11635 | if (link_section->sh_link >= filedata->file_header.e_shnum) | |
11636 | break; | |
11637 | ||
11638 | found = TRUE; | |
11639 | ||
11640 | symbols = GET_ELF_SYMBOLS (filedata, link_section, & num_syms); | |
11641 | if (symbols == NULL) | |
11642 | break; | |
11643 | ||
11644 | string_sec = filedata->section_headers + link_section->sh_link; | |
11645 | ||
11646 | strtab = (char *) get_data (NULL, filedata, string_sec->sh_offset, 1, | |
11647 | string_sec->sh_size, | |
11648 | _("version string table")); | |
11649 | if (!strtab) | |
11650 | { | |
11651 | free (symbols); | |
11652 | break; | |
11653 | } | |
11654 | ||
11655 | if (filedata->is_separate) | |
11656 | printf (ngettext ("\nIn linked file '%s' the version symbols section '%s' contains %lu entry:\n", | |
11657 | "\nIn linked file '%s' the version symbols section '%s' contains %lu entries:\n", | |
11658 | total), | |
11659 | filedata->file_name, | |
11660 | printable_section_name (filedata, section), | |
11661 | (unsigned long) total); | |
11662 | else | |
11663 | printf (ngettext ("\nVersion symbols section '%s' " | |
11664 | "contains %lu entry:\n", | |
11665 | "\nVersion symbols section '%s' " | |
11666 | "contains %lu entries:\n", | |
11667 | total), | |
11668 | printable_section_name (filedata, section), | |
11669 | (unsigned long) total); | |
11670 | ||
11671 | printf (_(" Addr: 0x")); | |
11672 | printf_vma (section->sh_addr); | |
11673 | printf (_(" Offset: %#08lx Link: %u (%s)\n"), | |
11674 | (unsigned long) section->sh_offset, section->sh_link, | |
11675 | printable_section_name (filedata, link_section)); | |
11676 | ||
11677 | off = offset_from_vma (filedata, | |
11678 | filedata->version_info[DT_VERSIONTAGIDX (DT_VERSYM)], | |
11679 | total * sizeof (short)); | |
11680 | edata = (unsigned char *) get_data (NULL, filedata, off, | |
11681 | sizeof (short), total, | |
11682 | _("version symbol data")); | |
11683 | if (!edata) | |
11684 | { | |
11685 | free (strtab); | |
11686 | free (symbols); | |
11687 | break; | |
11688 | } | |
11689 | ||
11690 | data = (short unsigned int *) cmalloc (total, sizeof (short)); | |
11691 | ||
11692 | for (cnt = total; cnt --;) | |
11693 | data[cnt] = byte_get (edata + cnt * sizeof (short), | |
11694 | sizeof (short)); | |
11695 | ||
11696 | free (edata); | |
11697 | ||
11698 | for (cnt = 0; cnt < total; cnt += 4) | |
11699 | { | |
11700 | int j, nn; | |
11701 | char *name; | |
11702 | char *invalid = _("*invalid*"); | |
11703 | ||
11704 | printf (" %03x:", cnt); | |
11705 | ||
11706 | for (j = 0; (j < 4) && (cnt + j) < total; ++j) | |
11707 | switch (data[cnt + j]) | |
11708 | { | |
11709 | case 0: | |
11710 | fputs (_(" 0 (*local*) "), stdout); | |
11711 | break; | |
11712 | ||
11713 | case 1: | |
11714 | fputs (_(" 1 (*global*) "), stdout); | |
11715 | break; | |
11716 | ||
11717 | default: | |
11718 | nn = printf ("%4x%c", data[cnt + j] & VERSYM_VERSION, | |
11719 | data[cnt + j] & VERSYM_HIDDEN ? 'h' : ' '); | |
11720 | ||
11721 | /* If this index value is greater than the size of the symbols | |
11722 | array, break to avoid an out-of-bounds read. */ | |
11723 | if ((unsigned long)(cnt + j) >= num_syms) | |
11724 | { | |
11725 | warn (_("invalid index into symbol array\n")); | |
11726 | break; | |
11727 | } | |
11728 | ||
11729 | name = NULL; | |
11730 | if (filedata->version_info[DT_VERSIONTAGIDX (DT_VERNEED)]) | |
11731 | { | |
11732 | Elf_Internal_Verneed ivn; | |
11733 | unsigned long offset; | |
11734 | ||
11735 | offset = offset_from_vma | |
11736 | (filedata, | |
11737 | filedata->version_info[DT_VERSIONTAGIDX (DT_VERNEED)], | |
11738 | sizeof (Elf_External_Verneed)); | |
11739 | ||
11740 | do | |
11741 | { | |
11742 | Elf_Internal_Vernaux ivna; | |
11743 | Elf_External_Verneed evn; | |
11744 | Elf_External_Vernaux evna; | |
11745 | unsigned long a_off; | |
11746 | ||
11747 | if (get_data (&evn, filedata, offset, sizeof (evn), 1, | |
11748 | _("version need")) == NULL) | |
11749 | break; | |
11750 | ||
11751 | ivn.vn_aux = BYTE_GET (evn.vn_aux); | |
11752 | ivn.vn_next = BYTE_GET (evn.vn_next); | |
11753 | ||
11754 | a_off = offset + ivn.vn_aux; | |
11755 | ||
11756 | do | |
11757 | { | |
11758 | if (get_data (&evna, filedata, a_off, sizeof (evna), | |
11759 | 1, _("version need aux (2)")) == NULL) | |
11760 | { | |
11761 | ivna.vna_next = 0; | |
11762 | ivna.vna_other = 0; | |
11763 | } | |
11764 | else | |
11765 | { | |
11766 | ivna.vna_next = BYTE_GET (evna.vna_next); | |
11767 | ivna.vna_other = BYTE_GET (evna.vna_other); | |
11768 | } | |
11769 | ||
11770 | a_off += ivna.vna_next; | |
11771 | } | |
11772 | while (ivna.vna_other != data[cnt + j] | |
11773 | && ivna.vna_next != 0); | |
11774 | ||
11775 | if (ivna.vna_other == data[cnt + j]) | |
11776 | { | |
11777 | ivna.vna_name = BYTE_GET (evna.vna_name); | |
11778 | ||
11779 | if (ivna.vna_name >= string_sec->sh_size) | |
11780 | name = invalid; | |
11781 | else | |
11782 | name = strtab + ivna.vna_name; | |
11783 | break; | |
11784 | } | |
11785 | ||
11786 | offset += ivn.vn_next; | |
11787 | } | |
11788 | while (ivn.vn_next); | |
11789 | } | |
11790 | ||
11791 | if (data[cnt + j] != 0x8001 | |
11792 | && filedata->version_info[DT_VERSIONTAGIDX (DT_VERDEF)]) | |
11793 | { | |
11794 | Elf_Internal_Verdef ivd; | |
11795 | Elf_External_Verdef evd; | |
11796 | unsigned long offset; | |
11797 | ||
11798 | offset = offset_from_vma | |
11799 | (filedata, | |
11800 | filedata->version_info[DT_VERSIONTAGIDX (DT_VERDEF)], | |
11801 | sizeof evd); | |
11802 | ||
11803 | do | |
11804 | { | |
11805 | if (get_data (&evd, filedata, offset, sizeof (evd), 1, | |
11806 | _("version def")) == NULL) | |
11807 | { | |
11808 | ivd.vd_next = 0; | |
11809 | /* PR 17531: file: 046-1082287-0.004. */ | |
11810 | ivd.vd_ndx = (data[cnt + j] & VERSYM_VERSION) + 1; | |
11811 | break; | |
11812 | } | |
11813 | else | |
11814 | { | |
11815 | ivd.vd_next = BYTE_GET (evd.vd_next); | |
11816 | ivd.vd_ndx = BYTE_GET (evd.vd_ndx); | |
11817 | } | |
11818 | ||
11819 | offset += ivd.vd_next; | |
11820 | } | |
11821 | while (ivd.vd_ndx != (data[cnt + j] & VERSYM_VERSION) | |
11822 | && ivd.vd_next != 0); | |
11823 | ||
11824 | if (ivd.vd_ndx == (data[cnt + j] & VERSYM_VERSION)) | |
11825 | { | |
11826 | Elf_External_Verdaux evda; | |
11827 | Elf_Internal_Verdaux ivda; | |
11828 | ||
11829 | ivd.vd_aux = BYTE_GET (evd.vd_aux); | |
11830 | ||
11831 | if (get_data (&evda, filedata, | |
11832 | offset - ivd.vd_next + ivd.vd_aux, | |
11833 | sizeof (evda), 1, | |
11834 | _("version def aux")) == NULL) | |
11835 | break; | |
11836 | ||
11837 | ivda.vda_name = BYTE_GET (evda.vda_name); | |
11838 | ||
11839 | if (ivda.vda_name >= string_sec->sh_size) | |
11840 | name = invalid; | |
11841 | else if (name != NULL && name != invalid) | |
11842 | name = _("*both*"); | |
11843 | else | |
11844 | name = strtab + ivda.vda_name; | |
11845 | } | |
11846 | } | |
11847 | if (name != NULL) | |
11848 | nn += printf ("(%s%-*s", | |
11849 | name, | |
11850 | 12 - (int) strlen (name), | |
11851 | ")"); | |
11852 | ||
11853 | if (nn < 18) | |
11854 | printf ("%*c", 18 - nn, ' '); | |
11855 | } | |
11856 | ||
11857 | putchar ('\n'); | |
11858 | } | |
11859 | ||
11860 | free (data); | |
11861 | free (strtab); | |
11862 | free (symbols); | |
11863 | } | |
11864 | break; | |
11865 | ||
11866 | default: | |
11867 | break; | |
11868 | } | |
11869 | } | |
11870 | ||
11871 | if (! found) | |
11872 | { | |
11873 | if (filedata->is_separate) | |
11874 | printf (_("\nNo version information found in linked file '%s'.\n"), | |
11875 | filedata->file_name); | |
11876 | else | |
11877 | printf (_("\nNo version information found in this file.\n")); | |
11878 | } | |
11879 | ||
11880 | return TRUE; | |
11881 | } | |
11882 | ||
11883 | static const char * | |
11884 | get_symbol_binding (Filedata * filedata, unsigned int binding) | |
11885 | { | |
11886 | static char buff[64]; | |
11887 | ||
11888 | switch (binding) | |
11889 | { | |
11890 | case STB_LOCAL: return "LOCAL"; | |
11891 | case STB_GLOBAL: return "GLOBAL"; | |
11892 | case STB_WEAK: return "WEAK"; | |
11893 | default: | |
11894 | if (binding >= STB_LOPROC && binding <= STB_HIPROC) | |
11895 | snprintf (buff, sizeof (buff), _("<processor specific>: %d"), | |
11896 | binding); | |
11897 | else if (binding >= STB_LOOS && binding <= STB_HIOS) | |
11898 | { | |
11899 | if (binding == STB_GNU_UNIQUE | |
11900 | && filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_GNU) | |
11901 | return "UNIQUE"; | |
11902 | snprintf (buff, sizeof (buff), _("<OS specific>: %d"), binding); | |
11903 | } | |
11904 | else | |
11905 | snprintf (buff, sizeof (buff), _("<unknown>: %d"), binding); | |
11906 | return buff; | |
11907 | } | |
11908 | } | |
11909 | ||
11910 | static const char * | |
11911 | get_symbol_type (Filedata * filedata, unsigned int type) | |
11912 | { | |
11913 | static char buff[64]; | |
11914 | ||
11915 | switch (type) | |
11916 | { | |
11917 | case STT_NOTYPE: return "NOTYPE"; | |
11918 | case STT_OBJECT: return "OBJECT"; | |
11919 | case STT_FUNC: return "FUNC"; | |
11920 | case STT_SECTION: return "SECTION"; | |
11921 | case STT_FILE: return "FILE"; | |
11922 | case STT_COMMON: return "COMMON"; | |
11923 | case STT_TLS: return "TLS"; | |
11924 | case STT_RELC: return "RELC"; | |
11925 | case STT_SRELC: return "SRELC"; | |
11926 | default: | |
11927 | if (type >= STT_LOPROC && type <= STT_HIPROC) | |
11928 | { | |
11929 | if (filedata->file_header.e_machine == EM_ARM && type == STT_ARM_TFUNC) | |
11930 | return "THUMB_FUNC"; | |
11931 | ||
11932 | if (filedata->file_header.e_machine == EM_SPARCV9 && type == STT_REGISTER) | |
11933 | return "REGISTER"; | |
11934 | ||
11935 | if (filedata->file_header.e_machine == EM_PARISC && type == STT_PARISC_MILLI) | |
11936 | return "PARISC_MILLI"; | |
11937 | ||
11938 | snprintf (buff, sizeof (buff), _("<processor specific>: %d"), type); | |
11939 | } | |
11940 | else if (type >= STT_LOOS && type <= STT_HIOS) | |
11941 | { | |
11942 | if (filedata->file_header.e_machine == EM_PARISC) | |
11943 | { | |
11944 | if (type == STT_HP_OPAQUE) | |
11945 | return "HP_OPAQUE"; | |
11946 | if (type == STT_HP_STUB) | |
11947 | return "HP_STUB"; | |
11948 | } | |
11949 | ||
11950 | if (type == STT_GNU_IFUNC | |
11951 | && (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_GNU | |
11952 | || filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_FREEBSD)) | |
11953 | return "IFUNC"; | |
11954 | ||
11955 | snprintf (buff, sizeof (buff), _("<OS specific>: %d"), type); | |
11956 | } | |
11957 | else | |
11958 | snprintf (buff, sizeof (buff), _("<unknown>: %d"), type); | |
11959 | return buff; | |
11960 | } | |
11961 | } | |
11962 | ||
11963 | static const char * | |
11964 | get_symbol_visibility (unsigned int visibility) | |
11965 | { | |
11966 | switch (visibility) | |
11967 | { | |
11968 | case STV_DEFAULT: return "DEFAULT"; | |
11969 | case STV_INTERNAL: return "INTERNAL"; | |
11970 | case STV_HIDDEN: return "HIDDEN"; | |
11971 | case STV_PROTECTED: return "PROTECTED"; | |
11972 | default: | |
11973 | error (_("Unrecognized visibility value: %u\n"), visibility); | |
11974 | return _("<unknown>"); | |
11975 | } | |
11976 | } | |
11977 | ||
11978 | static const char * | |
11979 | get_alpha_symbol_other (unsigned int other) | |
11980 | { | |
11981 | switch (other) | |
11982 | { | |
11983 | case STO_ALPHA_NOPV: return "NOPV"; | |
11984 | case STO_ALPHA_STD_GPLOAD: return "STD GPLOAD"; | |
11985 | default: | |
11986 | error (_("Unrecognized alpha specific other value: %u\n"), other); | |
11987 | return _("<unknown>"); | |
11988 | } | |
11989 | } | |
11990 | ||
11991 | static const char * | |
11992 | get_solaris_symbol_visibility (unsigned int visibility) | |
11993 | { | |
11994 | switch (visibility) | |
11995 | { | |
11996 | case 4: return "EXPORTED"; | |
11997 | case 5: return "SINGLETON"; | |
11998 | case 6: return "ELIMINATE"; | |
11999 | default: return get_symbol_visibility (visibility); | |
12000 | } | |
12001 | } | |
12002 | ||
12003 | static const char * | |
12004 | get_aarch64_symbol_other (unsigned int other) | |
12005 | { | |
12006 | static char buf[32]; | |
12007 | ||
12008 | if (other & STO_AARCH64_VARIANT_PCS) | |
12009 | { | |
12010 | other &= ~STO_AARCH64_VARIANT_PCS; | |
12011 | if (other == 0) | |
12012 | return "VARIANT_PCS"; | |
12013 | snprintf (buf, sizeof buf, "VARIANT_PCS | %x", other); | |
12014 | return buf; | |
12015 | } | |
12016 | return NULL; | |
12017 | } | |
12018 | ||
12019 | static const char * | |
12020 | get_mips_symbol_other (unsigned int other) | |
12021 | { | |
12022 | switch (other) | |
12023 | { | |
12024 | case STO_OPTIONAL: return "OPTIONAL"; | |
12025 | case STO_MIPS_PLT: return "MIPS PLT"; | |
12026 | case STO_MIPS_PIC: return "MIPS PIC"; | |
12027 | case STO_MICROMIPS: return "MICROMIPS"; | |
12028 | case STO_MICROMIPS | STO_MIPS_PIC: return "MICROMIPS, MIPS PIC"; | |
12029 | case STO_MIPS16: return "MIPS16"; | |
12030 | default: return NULL; | |
12031 | } | |
12032 | } | |
12033 | ||
12034 | static const char * | |
12035 | get_ia64_symbol_other (Filedata * filedata, unsigned int other) | |
12036 | { | |
12037 | if (is_ia64_vms (filedata)) | |
12038 | { | |
12039 | static char res[32]; | |
12040 | ||
12041 | res[0] = 0; | |
12042 | ||
12043 | /* Function types is for images and .STB files only. */ | |
12044 | switch (filedata->file_header.e_type) | |
12045 | { | |
12046 | case ET_DYN: | |
12047 | case ET_EXEC: | |
12048 | switch (VMS_ST_FUNC_TYPE (other)) | |
12049 | { | |
12050 | case VMS_SFT_CODE_ADDR: | |
12051 | strcat (res, " CA"); | |
12052 | break; | |
12053 | case VMS_SFT_SYMV_IDX: | |
12054 | strcat (res, " VEC"); | |
12055 | break; | |
12056 | case VMS_SFT_FD: | |
12057 | strcat (res, " FD"); | |
12058 | break; | |
12059 | case VMS_SFT_RESERVE: | |
12060 | strcat (res, " RSV"); | |
12061 | break; | |
12062 | default: | |
12063 | warn (_("Unrecognized IA64 VMS ST Function type: %d\n"), | |
12064 | VMS_ST_FUNC_TYPE (other)); | |
12065 | strcat (res, " <unknown>"); | |
12066 | break; | |
12067 | } | |
12068 | break; | |
12069 | default: | |
12070 | break; | |
12071 | } | |
12072 | switch (VMS_ST_LINKAGE (other)) | |
12073 | { | |
12074 | case VMS_STL_IGNORE: | |
12075 | strcat (res, " IGN"); | |
12076 | break; | |
12077 | case VMS_STL_RESERVE: | |
12078 | strcat (res, " RSV"); | |
12079 | break; | |
12080 | case VMS_STL_STD: | |
12081 | strcat (res, " STD"); | |
12082 | break; | |
12083 | case VMS_STL_LNK: | |
12084 | strcat (res, " LNK"); | |
12085 | break; | |
12086 | default: | |
12087 | warn (_("Unrecognized IA64 VMS ST Linkage: %d\n"), | |
12088 | VMS_ST_LINKAGE (other)); | |
12089 | strcat (res, " <unknown>"); | |
12090 | break; | |
12091 | } | |
12092 | ||
12093 | if (res[0] != 0) | |
12094 | return res + 1; | |
12095 | else | |
12096 | return res; | |
12097 | } | |
12098 | return NULL; | |
12099 | } | |
12100 | ||
12101 | static const char * | |
12102 | get_ppc64_symbol_other (unsigned int other) | |
12103 | { | |
12104 | if ((other & ~STO_PPC64_LOCAL_MASK) != 0) | |
12105 | return NULL; | |
12106 | ||
12107 | other >>= STO_PPC64_LOCAL_BIT; | |
12108 | if (other <= 6) | |
12109 | { | |
12110 | static char buf[64]; | |
12111 | if (other >= 2) | |
12112 | other = ppc64_decode_local_entry (other); | |
12113 | snprintf (buf, sizeof buf, _("<localentry>: %d"), other); | |
12114 | return buf; | |
12115 | } | |
12116 | return NULL; | |
12117 | } | |
12118 | ||
12119 | static const char * | |
12120 | get_symbol_other (Filedata * filedata, unsigned int other) | |
12121 | { | |
12122 | const char * result = NULL; | |
12123 | static char buff [64]; | |
12124 | ||
12125 | if (other == 0) | |
12126 | return ""; | |
12127 | ||
12128 | switch (filedata->file_header.e_machine) | |
12129 | { | |
12130 | case EM_ALPHA: | |
12131 | result = get_alpha_symbol_other (other); | |
12132 | break; | |
12133 | case EM_AARCH64: | |
12134 | result = get_aarch64_symbol_other (other); | |
12135 | break; | |
12136 | case EM_MIPS: | |
12137 | result = get_mips_symbol_other (other); | |
12138 | break; | |
12139 | case EM_IA_64: | |
12140 | result = get_ia64_symbol_other (filedata, other); | |
12141 | break; | |
12142 | case EM_PPC64: | |
12143 | result = get_ppc64_symbol_other (other); | |
12144 | break; | |
12145 | default: | |
12146 | result = NULL; | |
12147 | break; | |
12148 | } | |
12149 | ||
12150 | if (result) | |
12151 | return result; | |
12152 | ||
12153 | snprintf (buff, sizeof buff, _("<other>: %x"), other); | |
12154 | return buff; | |
12155 | } | |
12156 | ||
12157 | static const char * | |
12158 | get_symbol_index_type (Filedata * filedata, unsigned int type) | |
12159 | { | |
12160 | static char buff[32]; | |
12161 | ||
12162 | switch (type) | |
12163 | { | |
12164 | case SHN_UNDEF: return "UND"; | |
12165 | case SHN_ABS: return "ABS"; | |
12166 | case SHN_COMMON: return "COM"; | |
12167 | default: | |
12168 | if (type == SHN_IA_64_ANSI_COMMON | |
12169 | && filedata->file_header.e_machine == EM_IA_64 | |
12170 | && filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_HPUX) | |
12171 | return "ANSI_COM"; | |
12172 | else if ((filedata->file_header.e_machine == EM_X86_64 | |
12173 | || filedata->file_header.e_machine == EM_L1OM | |
12174 | || filedata->file_header.e_machine == EM_K1OM) | |
12175 | && type == SHN_X86_64_LCOMMON) | |
12176 | return "LARGE_COM"; | |
12177 | else if ((type == SHN_MIPS_SCOMMON | |
12178 | && filedata->file_header.e_machine == EM_MIPS) | |
12179 | || (type == SHN_TIC6X_SCOMMON | |
12180 | && filedata->file_header.e_machine == EM_TI_C6000)) | |
12181 | return "SCOM"; | |
12182 | else if (type == SHN_MIPS_SUNDEFINED | |
12183 | && filedata->file_header.e_machine == EM_MIPS) | |
12184 | return "SUND"; | |
12185 | else if (type >= SHN_LOPROC && type <= SHN_HIPROC) | |
12186 | sprintf (buff, "PRC[0x%04x]", type & 0xffff); | |
12187 | else if (type >= SHN_LOOS && type <= SHN_HIOS) | |
12188 | sprintf (buff, "OS [0x%04x]", type & 0xffff); | |
12189 | else if (type >= SHN_LORESERVE) | |
12190 | sprintf (buff, "RSV[0x%04x]", type & 0xffff); | |
12191 | else if (filedata->file_header.e_shnum != 0 | |
12192 | && type >= filedata->file_header.e_shnum) | |
12193 | sprintf (buff, _("bad section index[%3d]"), type); | |
12194 | else | |
12195 | sprintf (buff, "%3d", type); | |
12196 | break; | |
12197 | } | |
12198 | ||
12199 | return buff; | |
12200 | } | |
12201 | ||
12202 | static const char * | |
12203 | get_symbol_version_string (Filedata * filedata, | |
12204 | bfd_boolean is_dynsym, | |
12205 | const char * strtab, | |
12206 | unsigned long int strtab_size, | |
12207 | unsigned int si, | |
12208 | Elf_Internal_Sym * psym, | |
12209 | enum versioned_symbol_info * sym_info, | |
12210 | unsigned short * vna_other) | |
12211 | { | |
12212 | unsigned char data[2]; | |
12213 | unsigned short vers_data; | |
12214 | unsigned long offset; | |
12215 | unsigned short max_vd_ndx; | |
12216 | ||
12217 | if (!is_dynsym | |
12218 | || filedata->version_info[DT_VERSIONTAGIDX (DT_VERSYM)] == 0) | |
12219 | return NULL; | |
12220 | ||
12221 | offset = offset_from_vma (filedata, | |
12222 | filedata->version_info[DT_VERSIONTAGIDX (DT_VERSYM)], | |
12223 | sizeof data + si * sizeof (vers_data)); | |
12224 | ||
12225 | if (get_data (&data, filedata, offset + si * sizeof (vers_data), | |
12226 | sizeof (data), 1, _("version data")) == NULL) | |
12227 | return NULL; | |
12228 | ||
12229 | vers_data = byte_get (data, 2); | |
12230 | ||
12231 | if ((vers_data & VERSYM_HIDDEN) == 0 && vers_data == 0) | |
12232 | return NULL; | |
12233 | ||
12234 | *sym_info = (vers_data & VERSYM_HIDDEN) != 0 ? symbol_hidden : symbol_public; | |
12235 | max_vd_ndx = 0; | |
12236 | ||
12237 | /* Usually we'd only see verdef for defined symbols, and verneed for | |
12238 | undefined symbols. However, symbols defined by the linker in | |
12239 | .dynbss for variables copied from a shared library in order to | |
12240 | avoid text relocations are defined yet have verneed. We could | |
12241 | use a heuristic to detect the special case, for example, check | |
12242 | for verneed first on symbols defined in SHT_NOBITS sections, but | |
12243 | it is simpler and more reliable to just look for both verdef and | |
12244 | verneed. .dynbss might not be mapped to a SHT_NOBITS section. */ | |
12245 | ||
12246 | if (psym->st_shndx != SHN_UNDEF | |
12247 | && vers_data != 0x8001 | |
12248 | && filedata->version_info[DT_VERSIONTAGIDX (DT_VERDEF)]) | |
12249 | { | |
12250 | Elf_Internal_Verdef ivd; | |
12251 | Elf_Internal_Verdaux ivda; | |
12252 | Elf_External_Verdaux evda; | |
12253 | unsigned long off; | |
12254 | ||
12255 | off = offset_from_vma (filedata, | |
12256 | filedata->version_info[DT_VERSIONTAGIDX (DT_VERDEF)], | |
12257 | sizeof (Elf_External_Verdef)); | |
12258 | ||
12259 | do | |
12260 | { | |
12261 | Elf_External_Verdef evd; | |
12262 | ||
12263 | if (get_data (&evd, filedata, off, sizeof (evd), 1, | |
12264 | _("version def")) == NULL) | |
12265 | { | |
12266 | ivd.vd_ndx = 0; | |
12267 | ivd.vd_aux = 0; | |
12268 | ivd.vd_next = 0; | |
12269 | ivd.vd_flags = 0; | |
12270 | } | |
12271 | else | |
12272 | { | |
12273 | ivd.vd_ndx = BYTE_GET (evd.vd_ndx); | |
12274 | ivd.vd_aux = BYTE_GET (evd.vd_aux); | |
12275 | ivd.vd_next = BYTE_GET (evd.vd_next); | |
12276 | ivd.vd_flags = BYTE_GET (evd.vd_flags); | |
12277 | } | |
12278 | ||
12279 | if ((ivd.vd_ndx & VERSYM_VERSION) > max_vd_ndx) | |
12280 | max_vd_ndx = ivd.vd_ndx & VERSYM_VERSION; | |
12281 | ||
12282 | off += ivd.vd_next; | |
12283 | } | |
12284 | while (ivd.vd_ndx != (vers_data & VERSYM_VERSION) && ivd.vd_next != 0); | |
12285 | ||
12286 | if (ivd.vd_ndx == (vers_data & VERSYM_VERSION)) | |
12287 | { | |
12288 | if (ivd.vd_ndx == 1 && ivd.vd_flags == VER_FLG_BASE) | |
12289 | return NULL; | |
12290 | ||
12291 | off -= ivd.vd_next; | |
12292 | off += ivd.vd_aux; | |
12293 | ||
12294 | if (get_data (&evda, filedata, off, sizeof (evda), 1, | |
12295 | _("version def aux")) != NULL) | |
12296 | { | |
12297 | ivda.vda_name = BYTE_GET (evda.vda_name); | |
12298 | ||
12299 | if (psym->st_name != ivda.vda_name) | |
12300 | return (ivda.vda_name < strtab_size | |
12301 | ? strtab + ivda.vda_name : _("<corrupt>")); | |
12302 | } | |
12303 | } | |
12304 | } | |
12305 | ||
12306 | if (filedata->version_info[DT_VERSIONTAGIDX (DT_VERNEED)]) | |
12307 | { | |
12308 | Elf_External_Verneed evn; | |
12309 | Elf_Internal_Verneed ivn; | |
12310 | Elf_Internal_Vernaux ivna; | |
12311 | ||
12312 | offset = offset_from_vma (filedata, | |
12313 | filedata->version_info[DT_VERSIONTAGIDX (DT_VERNEED)], | |
12314 | sizeof evn); | |
12315 | do | |
12316 | { | |
12317 | unsigned long vna_off; | |
12318 | ||
12319 | if (get_data (&evn, filedata, offset, sizeof (evn), 1, | |
12320 | _("version need")) == NULL) | |
12321 | { | |
12322 | ivna.vna_next = 0; | |
12323 | ivna.vna_other = 0; | |
12324 | ivna.vna_name = 0; | |
12325 | break; | |
12326 | } | |
12327 | ||
12328 | ivn.vn_aux = BYTE_GET (evn.vn_aux); | |
12329 | ivn.vn_next = BYTE_GET (evn.vn_next); | |
12330 | ||
12331 | vna_off = offset + ivn.vn_aux; | |
12332 | ||
12333 | do | |
12334 | { | |
12335 | Elf_External_Vernaux evna; | |
12336 | ||
12337 | if (get_data (&evna, filedata, vna_off, sizeof (evna), 1, | |
12338 | _("version need aux (3)")) == NULL) | |
12339 | { | |
12340 | ivna.vna_next = 0; | |
12341 | ivna.vna_other = 0; | |
12342 | ivna.vna_name = 0; | |
12343 | } | |
12344 | else | |
12345 | { | |
12346 | ivna.vna_other = BYTE_GET (evna.vna_other); | |
12347 | ivna.vna_next = BYTE_GET (evna.vna_next); | |
12348 | ivna.vna_name = BYTE_GET (evna.vna_name); | |
12349 | } | |
12350 | ||
12351 | vna_off += ivna.vna_next; | |
12352 | } | |
12353 | while (ivna.vna_other != vers_data && ivna.vna_next != 0); | |
12354 | ||
12355 | if (ivna.vna_other == vers_data) | |
12356 | break; | |
12357 | ||
12358 | offset += ivn.vn_next; | |
12359 | } | |
12360 | while (ivn.vn_next != 0); | |
12361 | ||
12362 | if (ivna.vna_other == vers_data) | |
12363 | { | |
12364 | *sym_info = symbol_undefined; | |
12365 | *vna_other = ivna.vna_other; | |
12366 | return (ivna.vna_name < strtab_size | |
12367 | ? strtab + ivna.vna_name : _("<corrupt>")); | |
12368 | } | |
12369 | else if ((max_vd_ndx || (vers_data & VERSYM_VERSION) != 1) | |
12370 | && (vers_data & VERSYM_VERSION) > max_vd_ndx) | |
12371 | return _("<corrupt>"); | |
12372 | } | |
12373 | return NULL; | |
12374 | } | |
12375 | ||
12376 | static void | |
12377 | print_dynamic_symbol (Filedata *filedata, unsigned long si, | |
12378 | Elf_Internal_Sym *symtab, | |
12379 | Elf_Internal_Shdr *section, | |
12380 | char *strtab, size_t strtab_size) | |
12381 | { | |
12382 | const char *version_string; | |
12383 | enum versioned_symbol_info sym_info; | |
12384 | unsigned short vna_other; | |
12385 | Elf_Internal_Sym *psym = symtab + si; | |
12386 | ||
12387 | printf ("%6ld: ", si); | |
12388 | print_vma (psym->st_value, LONG_HEX); | |
12389 | putchar (' '); | |
12390 | print_vma (psym->st_size, DEC_5); | |
12391 | printf (" %-7s", get_symbol_type (filedata, ELF_ST_TYPE (psym->st_info))); | |
12392 | printf (" %-6s", get_symbol_binding (filedata, ELF_ST_BIND (psym->st_info))); | |
12393 | if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS) | |
12394 | printf (" %-7s", get_solaris_symbol_visibility (psym->st_other)); | |
12395 | else | |
12396 | { | |
12397 | unsigned int vis = ELF_ST_VISIBILITY (psym->st_other); | |
12398 | ||
12399 | printf (" %-7s", get_symbol_visibility (vis)); | |
12400 | /* Check to see if any other bits in the st_other field are set. | |
12401 | Note - displaying this information disrupts the layout of the | |
12402 | table being generated, but for the moment this case is very rare. */ | |
12403 | if (psym->st_other ^ vis) | |
12404 | printf (" [%s] ", get_symbol_other (filedata, psym->st_other ^ vis)); | |
12405 | } | |
12406 | printf (" %4s ", get_symbol_index_type (filedata, psym->st_shndx)); | |
12407 | ||
12408 | bfd_boolean is_valid = VALID_SYMBOL_NAME (strtab, strtab_size, | |
12409 | psym->st_name); | |
12410 | const char * sstr = is_valid ? strtab + psym->st_name : _("<corrupt>"); | |
12411 | ||
12412 | version_string | |
12413 | = get_symbol_version_string (filedata, | |
12414 | (section == NULL | |
12415 | || section->sh_type == SHT_DYNSYM), | |
12416 | strtab, strtab_size, si, | |
12417 | psym, &sym_info, &vna_other); | |
12418 | ||
12419 | int len_avail = 21; | |
12420 | if (! do_wide && version_string != NULL) | |
12421 | { | |
12422 | char buffer[16]; | |
12423 | ||
12424 | len_avail -= 1 + strlen (version_string); | |
12425 | ||
12426 | if (sym_info == symbol_undefined) | |
12427 | len_avail -= sprintf (buffer," (%d)", vna_other); | |
12428 | else if (sym_info != symbol_hidden) | |
12429 | len_avail -= 1; | |
12430 | } | |
12431 | ||
12432 | print_symbol (len_avail, sstr); | |
12433 | ||
12434 | if (version_string) | |
12435 | { | |
12436 | if (sym_info == symbol_undefined) | |
12437 | printf ("@%s (%d)", version_string, vna_other); | |
12438 | else | |
12439 | printf (sym_info == symbol_hidden ? "@%s" : "@@%s", | |
12440 | version_string); | |
12441 | } | |
12442 | ||
12443 | putchar ('\n'); | |
12444 | ||
12445 | if (ELF_ST_BIND (psym->st_info) == STB_LOCAL | |
12446 | && section != NULL | |
12447 | && si >= section->sh_info | |
12448 | /* Irix 5 and 6 MIPS binaries are known to ignore this requirement. */ | |
12449 | && filedata->file_header.e_machine != EM_MIPS | |
12450 | /* Solaris binaries have been found to violate this requirement as | |
12451 | well. Not sure if this is a bug or an ABI requirement. */ | |
12452 | && filedata->file_header.e_ident[EI_OSABI] != ELFOSABI_SOLARIS) | |
12453 | warn (_("local symbol %lu found at index >= %s's sh_info value of %u\n"), | |
12454 | si, printable_section_name (filedata, section), section->sh_info); | |
12455 | } | |
12456 | ||
12457 | static const char * | |
12458 | get_lto_kind (unsigned int kind) | |
12459 | { | |
12460 | switch (kind) | |
12461 | { | |
12462 | case 0: return "DEF"; | |
12463 | case 1: return "WEAKDEF"; | |
12464 | case 2: return "UNDEF"; | |
12465 | case 3: return "WEAKUNDEF"; | |
12466 | case 4: return "COMMON"; | |
12467 | default: | |
12468 | break; | |
12469 | } | |
12470 | ||
12471 | static char buffer[30]; | |
12472 | error (_("Unknown LTO symbol definition encountered: %u\n"), kind); | |
12473 | sprintf (buffer, "<unknown: %u>", kind); | |
12474 | return buffer; | |
12475 | } | |
12476 | ||
12477 | static const char * | |
12478 | get_lto_visibility (unsigned int visibility) | |
12479 | { | |
12480 | switch (visibility) | |
12481 | { | |
12482 | case 0: return "DEFAULT"; | |
12483 | case 1: return "PROTECTED"; | |
12484 | case 2: return "INTERNAL"; | |
12485 | case 3: return "HIDDEN"; | |
12486 | default: | |
12487 | break; | |
12488 | } | |
12489 | ||
12490 | static char buffer[30]; | |
12491 | error (_("Unknown LTO symbol visibility encountered: %u\n"), visibility); | |
12492 | sprintf (buffer, "<unknown: %u>", visibility); | |
12493 | return buffer; | |
12494 | } | |
12495 | ||
12496 | static const char * | |
12497 | get_lto_sym_type (unsigned int sym_type) | |
12498 | { | |
12499 | switch (sym_type) | |
12500 | { | |
12501 | case 0: return "UNKNOWN"; | |
12502 | case 1: return "FUNCTION"; | |
12503 | case 2: return "VARIABLE"; | |
12504 | default: | |
12505 | break; | |
12506 | } | |
12507 | ||
12508 | static char buffer[30]; | |
12509 | error (_("Unknown LTO symbol type encountered: %u\n"), sym_type); | |
12510 | sprintf (buffer, "<unknown: %u>", sym_type); | |
12511 | return buffer; | |
12512 | } | |
12513 | ||
12514 | /* Display an LTO format symbol table. | |
12515 | FIXME: The format of LTO symbol tables is not formalized. | |
12516 | So this code could need changing in the future. */ | |
12517 | ||
12518 | static bfd_boolean | |
12519 | display_lto_symtab (Filedata * filedata, | |
12520 | Elf_Internal_Shdr * section) | |
12521 | { | |
12522 | if (section->sh_size == 0) | |
12523 | { | |
12524 | if (filedata->is_separate) | |
12525 | printf (_("\nThe LTO Symbol table section '%s' in linked file '%s' is empty!\n"), | |
12526 | printable_section_name (filedata, section), | |
12527 | filedata->file_name); | |
12528 | else | |
12529 | printf (_("\nLTO Symbol table '%s' is empty!\n"), | |
12530 | printable_section_name (filedata, section)); | |
12531 | ||
12532 | return TRUE; | |
12533 | } | |
12534 | ||
12535 | if (section->sh_size > filedata->file_size) | |
12536 | { | |
12537 | error (_("Section %s has an invalid sh_size of 0x%lx\n"), | |
12538 | printable_section_name (filedata, section), | |
12539 | (unsigned long) section->sh_size); | |
12540 | return FALSE; | |
12541 | } | |
12542 | ||
12543 | void * alloced_data = get_data (NULL, filedata, section->sh_offset, | |
12544 | section->sh_size, 1, _("LTO symbols")); | |
12545 | if (alloced_data == NULL) | |
12546 | return FALSE; | |
12547 | ||
12548 | /* Look for extended data for the symbol table. */ | |
12549 | Elf_Internal_Shdr * ext; | |
12550 | void * ext_data_orig = NULL; | |
12551 | char * ext_data = NULL; | |
12552 | char * ext_data_end = NULL; | |
12553 | char * ext_name = NULL; | |
12554 | ||
12555 | if (asprintf (& ext_name, ".gnu.lto_.ext_symtab.%s", | |
12556 | SECTION_NAME (section) + sizeof (".gnu.lto_.symtab.") - 1) > 0 | |
12557 | && ext_name != NULL /* Paranoia. */ | |
12558 | && (ext = find_section (filedata, ext_name)) != NULL) | |
12559 | { | |
12560 | if (ext->sh_size < 3) | |
12561 | error (_("LTO Symbol extension table '%s' is empty!\n"), | |
12562 | printable_section_name (filedata, ext)); | |
12563 | else | |
12564 | { | |
12565 | ext_data_orig = ext_data = get_data (NULL, filedata, ext->sh_offset, | |
12566 | ext->sh_size, 1, | |
12567 | _("LTO ext symbol data")); | |
12568 | if (ext_data != NULL) | |
12569 | { | |
12570 | ext_data_end = ext_data + ext->sh_size; | |
12571 | if (* ext_data++ != 1) | |
12572 | error (_("Unexpected version number in symbol extension table\n")); | |
12573 | } | |
12574 | } | |
12575 | } | |
12576 | ||
12577 | const unsigned char * data = (const unsigned char *) alloced_data; | |
12578 | const unsigned char * end = data + section->sh_size; | |
12579 | ||
12580 | if (filedata->is_separate) | |
12581 | printf (_("\nIn linked file '%s': "), filedata->file_name); | |
12582 | else | |
12583 | printf ("\n"); | |
12584 | ||
12585 | if (ext_data_orig != NULL) | |
12586 | { | |
12587 | if (do_wide) | |
12588 | printf (_("LTO Symbol table '%s' and extension table '%s' contain:\n"), | |
12589 | printable_section_name (filedata, section), | |
12590 | printable_section_name (filedata, ext)); | |
12591 | else | |
12592 | { | |
12593 | printf (_("LTO Symbol table '%s'\n"), | |
12594 | printable_section_name (filedata, section)); | |
12595 | printf (_(" and extension table '%s' contain:\n"), | |
12596 | printable_section_name (filedata, ext)); | |
12597 | } | |
12598 | } | |
12599 | else | |
12600 | printf (_("LTO Symbol table '%s' contains:\n"), | |
12601 | printable_section_name (filedata, section)); | |
12602 | ||
12603 | /* FIXME: Add a wide version. */ | |
12604 | if (ext_data_orig != NULL) | |
12605 | printf (_(" Comdat_Key Kind Visibility Size Slot Type Section Name\n")); | |
12606 | else | |
12607 | printf (_(" Comdat_Key Kind Visibility Size Slot Name\n")); | |
12608 | ||
12609 | /* FIXME: We do not handle style prefixes. */ | |
12610 | ||
12611 | while (data < end) | |
12612 | { | |
12613 | const unsigned char * sym_name = data; | |
12614 | data += strnlen ((const char *) sym_name, end - data) + 1; | |
12615 | if (data >= end) | |
12616 | goto fail; | |
12617 | ||
12618 | const unsigned char * comdat_key = data; | |
12619 | data += strnlen ((const char *) comdat_key, end - data) + 1; | |
12620 | if (data >= end) | |
12621 | goto fail; | |
12622 | ||
12623 | if (data + 2 + 8 + 4 > end) | |
12624 | goto fail; | |
12625 | ||
12626 | unsigned int kind = *data++; | |
12627 | unsigned int visibility = *data++; | |
12628 | ||
12629 | elf_vma size = byte_get (data, 8); | |
12630 | data += 8; | |
12631 | ||
12632 | elf_vma slot = byte_get (data, 4); | |
12633 | data += 4; | |
12634 | ||
12635 | if (ext_data != NULL) | |
12636 | { | |
12637 | if (ext_data < (ext_data_end - 1)) | |
12638 | { | |
12639 | unsigned int sym_type = * ext_data ++; | |
12640 | unsigned int sec_kind = * ext_data ++; | |
12641 | ||
12642 | printf (" %10s %10s %11s %08lx %08lx %9s %08lx _", | |
12643 | * comdat_key == 0 ? "-" : (char *) comdat_key, | |
12644 | get_lto_kind (kind), | |
12645 | get_lto_visibility (visibility), | |
12646 | (long) size, | |
12647 | (long) slot, | |
12648 | get_lto_sym_type (sym_type), | |
12649 | (long) sec_kind); | |
12650 | print_symbol (6, (const char *) sym_name); | |
12651 | } | |
12652 | else | |
12653 | { | |
12654 | error (_("Ran out of LTO symbol extension data\n")); | |
12655 | ext_data = NULL; | |
12656 | /* FIXME: return FAIL result ? */ | |
12657 | } | |
12658 | } | |
12659 | else | |
12660 | { | |
12661 | printf (" %10s %10s %11s %08lx %08lx _", | |
12662 | * comdat_key == 0 ? "-" : (char *) comdat_key, | |
12663 | get_lto_kind (kind), | |
12664 | get_lto_visibility (visibility), | |
12665 | (long) size, | |
12666 | (long) slot); | |
12667 | print_symbol (21, (const char *) sym_name); | |
12668 | } | |
12669 | putchar ('\n'); | |
12670 | } | |
12671 | ||
12672 | if (ext_data != NULL && ext_data < ext_data_end) | |
12673 | { | |
12674 | error (_("Data remains in the LTO symbol extension table\n")); | |
12675 | goto fail; | |
12676 | } | |
12677 | ||
12678 | free (alloced_data); | |
12679 | free (ext_data_orig); | |
12680 | free (ext_name); | |
12681 | return TRUE; | |
12682 | ||
12683 | fail: | |
12684 | error (_("Buffer overrun encountered whilst decoding LTO symbol table\n")); | |
12685 | free (alloced_data); | |
12686 | free (ext_data_orig); | |
12687 | free (ext_name); | |
12688 | return FALSE; | |
12689 | } | |
12690 | ||
12691 | /* Display LTO symbol tables. */ | |
12692 | ||
12693 | static bfd_boolean | |
12694 | process_lto_symbol_tables (Filedata * filedata) | |
12695 | { | |
12696 | Elf_Internal_Shdr * section; | |
12697 | unsigned int i; | |
12698 | bfd_boolean res = TRUE; | |
12699 | ||
12700 | if (!do_lto_syms) | |
12701 | return TRUE; | |
12702 | ||
12703 | if (filedata->section_headers == NULL) | |
12704 | return TRUE; | |
12705 | ||
12706 | for (i = 0, section = filedata->section_headers; | |
12707 | i < filedata->file_header.e_shnum; | |
12708 | i++, section++) | |
12709 | if (SECTION_NAME_VALID (section) | |
12710 | && CONST_STRNEQ (SECTION_NAME (section), ".gnu.lto_.symtab.")) | |
12711 | res &= display_lto_symtab (filedata, section); | |
12712 | ||
12713 | return res; | |
12714 | } | |
12715 | ||
12716 | /* Dump the symbol table. */ | |
12717 | ||
12718 | static bfd_boolean | |
12719 | process_symbol_table (Filedata * filedata) | |
12720 | { | |
12721 | Elf_Internal_Shdr * section; | |
12722 | ||
12723 | if (!do_syms && !do_dyn_syms && !do_histogram) | |
12724 | return TRUE; | |
12725 | ||
12726 | if ((filedata->dynamic_info[DT_HASH] || filedata->dynamic_info_DT_GNU_HASH) | |
12727 | && do_syms | |
12728 | && do_using_dynamic | |
12729 | && filedata->dynamic_strings != NULL | |
12730 | && filedata->dynamic_symbols != NULL) | |
12731 | { | |
12732 | unsigned long si; | |
12733 | ||
12734 | if (filedata->is_separate) | |
12735 | { | |
12736 | printf (ngettext ("\nIn linked file '%s' the dynamic symbol table contains %lu entry:\n", | |
12737 | "\nIn linked file '%s' the dynamic symbol table contains %lu entries:\n", | |
12738 | filedata->num_dynamic_syms), | |
12739 | filedata->file_name, | |
12740 | filedata->num_dynamic_syms); | |
12741 | } | |
12742 | else | |
12743 | { | |
12744 | printf (ngettext ("\nSymbol table for image contains %lu entry:\n", | |
12745 | "\nSymbol table for image contains %lu entries:\n", | |
12746 | filedata->num_dynamic_syms), | |
12747 | filedata->num_dynamic_syms); | |
12748 | } | |
12749 | if (is_32bit_elf) | |
12750 | printf (_(" Num: Value Size Type Bind Vis Ndx Name\n")); | |
12751 | else | |
12752 | printf (_(" Num: Value Size Type Bind Vis Ndx Name\n")); | |
12753 | ||
12754 | for (si = 0; si < filedata->num_dynamic_syms; si++) | |
12755 | print_dynamic_symbol (filedata, si, filedata->dynamic_symbols, NULL, | |
12756 | filedata->dynamic_strings, | |
12757 | filedata->dynamic_strings_length); | |
12758 | } | |
12759 | else if ((do_dyn_syms || (do_syms && !do_using_dynamic)) | |
12760 | && filedata->section_headers != NULL) | |
12761 | { | |
12762 | unsigned int i; | |
12763 | ||
12764 | for (i = 0, section = filedata->section_headers; | |
12765 | i < filedata->file_header.e_shnum; | |
12766 | i++, section++) | |
12767 | { | |
12768 | char * strtab = NULL; | |
12769 | unsigned long int strtab_size = 0; | |
12770 | Elf_Internal_Sym * symtab; | |
12771 | unsigned long si, num_syms; | |
12772 | ||
12773 | if ((section->sh_type != SHT_SYMTAB | |
12774 | && section->sh_type != SHT_DYNSYM) | |
12775 | || (!do_syms | |
12776 | && section->sh_type == SHT_SYMTAB)) | |
12777 | continue; | |
12778 | ||
12779 | if (section->sh_entsize == 0) | |
12780 | { | |
12781 | printf (_("\nSymbol table '%s' has a sh_entsize of zero!\n"), | |
12782 | printable_section_name (filedata, section)); | |
12783 | continue; | |
12784 | } | |
12785 | ||
12786 | num_syms = section->sh_size / section->sh_entsize; | |
12787 | ||
12788 | if (filedata->is_separate) | |
12789 | printf (ngettext ("\nIn linked file '%s' symbol section '%s' contains %lu entry:\n", | |
12790 | "\nIn linked file '%s' symbol section '%s' contains %lu entries:\n", | |
12791 | num_syms), | |
12792 | filedata->file_name, | |
12793 | printable_section_name (filedata, section), | |
12794 | num_syms); | |
12795 | else | |
12796 | printf (ngettext ("\nSymbol table '%s' contains %lu entry:\n", | |
12797 | "\nSymbol table '%s' contains %lu entries:\n", | |
12798 | num_syms), | |
12799 | printable_section_name (filedata, section), | |
12800 | num_syms); | |
12801 | ||
12802 | if (is_32bit_elf) | |
12803 | printf (_(" Num: Value Size Type Bind Vis Ndx Name\n")); | |
12804 | else | |
12805 | printf (_(" Num: Value Size Type Bind Vis Ndx Name\n")); | |
12806 | ||
12807 | symtab = GET_ELF_SYMBOLS (filedata, section, & num_syms); | |
12808 | if (symtab == NULL) | |
12809 | continue; | |
12810 | ||
12811 | if (section->sh_link == filedata->file_header.e_shstrndx) | |
12812 | { | |
12813 | strtab = filedata->string_table; | |
12814 | strtab_size = filedata->string_table_length; | |
12815 | } | |
12816 | else if (section->sh_link < filedata->file_header.e_shnum) | |
12817 | { | |
12818 | Elf_Internal_Shdr * string_sec; | |
12819 | ||
12820 | string_sec = filedata->section_headers + section->sh_link; | |
12821 | ||
12822 | strtab = (char *) get_data (NULL, filedata, string_sec->sh_offset, | |
12823 | 1, string_sec->sh_size, | |
12824 | _("string table")); | |
12825 | strtab_size = strtab != NULL ? string_sec->sh_size : 0; | |
12826 | } | |
12827 | ||
12828 | for (si = 0; si < num_syms; si++) | |
12829 | print_dynamic_symbol (filedata, si, symtab, section, | |
12830 | strtab, strtab_size); | |
12831 | ||
12832 | free (symtab); | |
12833 | if (strtab != filedata->string_table) | |
12834 | free (strtab); | |
12835 | } | |
12836 | } | |
12837 | else if (do_syms) | |
12838 | printf | |
12839 | (_("\nDynamic symbol information is not available for displaying symbols.\n")); | |
12840 | ||
12841 | if (do_histogram && filedata->buckets != NULL) | |
12842 | { | |
12843 | unsigned long * lengths; | |
12844 | unsigned long * counts; | |
12845 | unsigned long hn; | |
12846 | bfd_vma si; | |
12847 | unsigned long maxlength = 0; | |
12848 | unsigned long nzero_counts = 0; | |
12849 | unsigned long nsyms = 0; | |
12850 | char *visited; | |
12851 | ||
12852 | printf (ngettext ("\nHistogram for bucket list length " | |
12853 | "(total of %lu bucket):\n", | |
12854 | "\nHistogram for bucket list length " | |
12855 | "(total of %lu buckets):\n", | |
12856 | (unsigned long) filedata->nbuckets), | |
12857 | (unsigned long) filedata->nbuckets); | |
12858 | ||
12859 | lengths = (unsigned long *) calloc (filedata->nbuckets, | |
12860 | sizeof (*lengths)); | |
12861 | if (lengths == NULL) | |
12862 | { | |
12863 | error (_("Out of memory allocating space for histogram buckets\n")); | |
12864 | goto err_out; | |
12865 | } | |
12866 | visited = xcmalloc (filedata->nchains, 1); | |
12867 | memset (visited, 0, filedata->nchains); | |
12868 | ||
12869 | printf (_(" Length Number %% of total Coverage\n")); | |
12870 | for (hn = 0; hn < filedata->nbuckets; ++hn) | |
12871 | { | |
12872 | for (si = filedata->buckets[hn]; si > 0; si = filedata->chains[si]) | |
12873 | { | |
12874 | ++nsyms; | |
12875 | if (maxlength < ++lengths[hn]) | |
12876 | ++maxlength; | |
12877 | if (si >= filedata->nchains || visited[si]) | |
12878 | { | |
12879 | error (_("histogram chain is corrupt\n")); | |
12880 | break; | |
12881 | } | |
12882 | visited[si] = 1; | |
12883 | } | |
12884 | } | |
12885 | free (visited); | |
12886 | ||
12887 | counts = (unsigned long *) calloc (maxlength + 1, sizeof (*counts)); | |
12888 | if (counts == NULL) | |
12889 | { | |
12890 | free (lengths); | |
12891 | error (_("Out of memory allocating space for histogram counts\n")); | |
12892 | goto err_out; | |
12893 | } | |
12894 | ||
12895 | for (hn = 0; hn < filedata->nbuckets; ++hn) | |
12896 | ++counts[lengths[hn]]; | |
12897 | ||
12898 | if (filedata->nbuckets > 0) | |
12899 | { | |
12900 | unsigned long i; | |
12901 | printf (" 0 %-10lu (%5.1f%%)\n", | |
12902 | counts[0], (counts[0] * 100.0) / filedata->nbuckets); | |
12903 | for (i = 1; i <= maxlength; ++i) | |
12904 | { | |
12905 | nzero_counts += counts[i] * i; | |
12906 | printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n", | |
12907 | i, counts[i], (counts[i] * 100.0) / filedata->nbuckets, | |
12908 | (nzero_counts * 100.0) / nsyms); | |
12909 | } | |
12910 | } | |
12911 | ||
12912 | free (counts); | |
12913 | free (lengths); | |
12914 | } | |
12915 | ||
12916 | free (filedata->buckets); | |
12917 | filedata->buckets = NULL; | |
12918 | filedata->nbuckets = 0; | |
12919 | free (filedata->chains); | |
12920 | filedata->chains = NULL; | |
12921 | ||
12922 | if (do_histogram && filedata->gnubuckets != NULL) | |
12923 | { | |
12924 | unsigned long * lengths; | |
12925 | unsigned long * counts; | |
12926 | unsigned long hn; | |
12927 | unsigned long maxlength = 0; | |
12928 | unsigned long nzero_counts = 0; | |
12929 | unsigned long nsyms = 0; | |
12930 | ||
12931 | printf (ngettext ("\nHistogram for `%s' bucket list length " | |
12932 | "(total of %lu bucket):\n", | |
12933 | "\nHistogram for `%s' bucket list length " | |
12934 | "(total of %lu buckets):\n", | |
12935 | (unsigned long) filedata->ngnubuckets), | |
12936 | GNU_HASH_SECTION_NAME (filedata), | |
12937 | (unsigned long) filedata->ngnubuckets); | |
12938 | ||
12939 | lengths = (unsigned long *) calloc (filedata->ngnubuckets, | |
12940 | sizeof (*lengths)); | |
12941 | if (lengths == NULL) | |
12942 | { | |
12943 | error (_("Out of memory allocating space for gnu histogram buckets\n")); | |
12944 | goto err_out; | |
12945 | } | |
12946 | ||
12947 | printf (_(" Length Number %% of total Coverage\n")); | |
12948 | ||
12949 | for (hn = 0; hn < filedata->ngnubuckets; ++hn) | |
12950 | if (filedata->gnubuckets[hn] != 0) | |
12951 | { | |
12952 | bfd_vma off, length = 1; | |
12953 | ||
12954 | for (off = filedata->gnubuckets[hn] - filedata->gnusymidx; | |
12955 | /* PR 17531 file: 010-77222-0.004. */ | |
12956 | off < filedata->ngnuchains | |
12957 | && (filedata->gnuchains[off] & 1) == 0; | |
12958 | ++off) | |
12959 | ++length; | |
12960 | lengths[hn] = length; | |
12961 | if (length > maxlength) | |
12962 | maxlength = length; | |
12963 | nsyms += length; | |
12964 | } | |
12965 | ||
12966 | counts = (unsigned long *) calloc (maxlength + 1, sizeof (*counts)); | |
12967 | if (counts == NULL) | |
12968 | { | |
12969 | free (lengths); | |
12970 | error (_("Out of memory allocating space for gnu histogram counts\n")); | |
12971 | goto err_out; | |
12972 | } | |
12973 | ||
12974 | for (hn = 0; hn < filedata->ngnubuckets; ++hn) | |
12975 | ++counts[lengths[hn]]; | |
12976 | ||
12977 | if (filedata->ngnubuckets > 0) | |
12978 | { | |
12979 | unsigned long j; | |
12980 | printf (" 0 %-10lu (%5.1f%%)\n", | |
12981 | counts[0], (counts[0] * 100.0) / filedata->ngnubuckets); | |
12982 | for (j = 1; j <= maxlength; ++j) | |
12983 | { | |
12984 | nzero_counts += counts[j] * j; | |
12985 | printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n", | |
12986 | j, counts[j], (counts[j] * 100.0) / filedata->ngnubuckets, | |
12987 | (nzero_counts * 100.0) / nsyms); | |
12988 | } | |
12989 | } | |
12990 | ||
12991 | free (counts); | |
12992 | free (lengths); | |
12993 | } | |
12994 | free (filedata->gnubuckets); | |
12995 | filedata->gnubuckets = NULL; | |
12996 | filedata->ngnubuckets = 0; | |
12997 | free (filedata->gnuchains); | |
12998 | filedata->gnuchains = NULL; | |
12999 | filedata->ngnuchains = 0; | |
13000 | free (filedata->mipsxlat); | |
13001 | filedata->mipsxlat = NULL; | |
13002 | return TRUE; | |
13003 | ||
13004 | err_out: | |
13005 | free (filedata->gnubuckets); | |
13006 | filedata->gnubuckets = NULL; | |
13007 | filedata->ngnubuckets = 0; | |
13008 | free (filedata->gnuchains); | |
13009 | filedata->gnuchains = NULL; | |
13010 | filedata->ngnuchains = 0; | |
13011 | free (filedata->mipsxlat); | |
13012 | filedata->mipsxlat = NULL; | |
13013 | free (filedata->buckets); | |
13014 | filedata->buckets = NULL; | |
13015 | filedata->nbuckets = 0; | |
13016 | free (filedata->chains); | |
13017 | filedata->chains = NULL; | |
13018 | return FALSE; | |
13019 | } | |
13020 | ||
13021 | static bfd_boolean | |
13022 | process_syminfo (Filedata * filedata) | |
13023 | { | |
13024 | unsigned int i; | |
13025 | ||
13026 | if (filedata->dynamic_syminfo == NULL | |
13027 | || !do_dynamic) | |
13028 | /* No syminfo, this is ok. */ | |
13029 | return TRUE; | |
13030 | ||
13031 | /* There better should be a dynamic symbol section. */ | |
13032 | if (filedata->dynamic_symbols == NULL || filedata->dynamic_strings == NULL) | |
13033 | return FALSE; | |
13034 | ||
13035 | if (filedata->is_separate) | |
13036 | printf (ngettext ("\nIn linked file '%s: the dynamic info segment at offset 0x%lx contains %d entry:\n", | |
13037 | "\nIn linked file '%s: the dynamic info segment at offset 0x%lx contains %d entries:\n", | |
13038 | filedata->dynamic_syminfo_nent), | |
13039 | filedata->file_name, | |
13040 | filedata->dynamic_syminfo_offset, | |
13041 | filedata->dynamic_syminfo_nent); | |
13042 | else | |
13043 | printf (ngettext ("\nDynamic info segment at offset 0x%lx " | |
13044 | "contains %d entry:\n", | |
13045 | "\nDynamic info segment at offset 0x%lx " | |
13046 | "contains %d entries:\n", | |
13047 | filedata->dynamic_syminfo_nent), | |
13048 | filedata->dynamic_syminfo_offset, | |
13049 | filedata->dynamic_syminfo_nent); | |
13050 | ||
13051 | printf (_(" Num: Name BoundTo Flags\n")); | |
13052 | for (i = 0; i < filedata->dynamic_syminfo_nent; ++i) | |
13053 | { | |
13054 | unsigned short int flags = filedata->dynamic_syminfo[i].si_flags; | |
13055 | ||
13056 | printf ("%4d: ", i); | |
13057 | if (i >= filedata->num_dynamic_syms) | |
13058 | printf (_("<corrupt index>")); | |
13059 | else if (VALID_DYNAMIC_NAME (filedata, filedata->dynamic_symbols[i].st_name)) | |
13060 | print_symbol (30, GET_DYNAMIC_NAME (filedata, | |
13061 | filedata->dynamic_symbols[i].st_name)); | |
13062 | else | |
13063 | printf (_("<corrupt: %19ld>"), filedata->dynamic_symbols[i].st_name); | |
13064 | putchar (' '); | |
13065 | ||
13066 | switch (filedata->dynamic_syminfo[i].si_boundto) | |
13067 | { | |
13068 | case SYMINFO_BT_SELF: | |
13069 | fputs ("SELF ", stdout); | |
13070 | break; | |
13071 | case SYMINFO_BT_PARENT: | |
13072 | fputs ("PARENT ", stdout); | |
13073 | break; | |
13074 | default: | |
13075 | if (filedata->dynamic_syminfo[i].si_boundto > 0 | |
13076 | && filedata->dynamic_syminfo[i].si_boundto < filedata->dynamic_nent | |
13077 | && VALID_DYNAMIC_NAME (filedata, | |
13078 | filedata->dynamic_section[filedata->dynamic_syminfo[i].si_boundto].d_un.d_val)) | |
13079 | { | |
13080 | print_symbol (10, GET_DYNAMIC_NAME (filedata, | |
13081 | filedata->dynamic_section[filedata->dynamic_syminfo[i].si_boundto].d_un.d_val)); | |
13082 | putchar (' ' ); | |
13083 | } | |
13084 | else | |
13085 | printf ("%-10d ", filedata->dynamic_syminfo[i].si_boundto); | |
13086 | break; | |
13087 | } | |
13088 | ||
13089 | if (flags & SYMINFO_FLG_DIRECT) | |
13090 | printf (" DIRECT"); | |
13091 | if (flags & SYMINFO_FLG_PASSTHRU) | |
13092 | printf (" PASSTHRU"); | |
13093 | if (flags & SYMINFO_FLG_COPY) | |
13094 | printf (" COPY"); | |
13095 | if (flags & SYMINFO_FLG_LAZYLOAD) | |
13096 | printf (" LAZYLOAD"); | |
13097 | ||
13098 | puts (""); | |
13099 | } | |
13100 | ||
13101 | return TRUE; | |
13102 | } | |
13103 | ||
13104 | /* A macro which evaluates to TRUE if the region ADDR .. ADDR + NELEM | |
13105 | is contained by the region START .. END. The types of ADDR, START | |
13106 | and END should all be the same. Note both ADDR + NELEM and END | |
13107 | point to just beyond the end of the regions that are being tested. */ | |
13108 | #define IN_RANGE(START,END,ADDR,NELEM) \ | |
13109 | (((ADDR) >= (START)) && ((ADDR) < (END)) && ((ADDR) + (NELEM) <= (END))) | |
13110 | ||
13111 | /* Check to see if the given reloc needs to be handled in a target specific | |
13112 | manner. If so then process the reloc and return TRUE otherwise return | |
13113 | FALSE. | |
13114 | ||
13115 | If called with reloc == NULL, then this is a signal that reloc processing | |
13116 | for the current section has finished, and any saved state should be | |
13117 | discarded. */ | |
13118 | ||
13119 | static bfd_boolean | |
13120 | target_specific_reloc_handling (Filedata * filedata, | |
13121 | Elf_Internal_Rela * reloc, | |
13122 | unsigned char * start, | |
13123 | unsigned char * end, | |
13124 | Elf_Internal_Sym * symtab, | |
13125 | unsigned long num_syms) | |
13126 | { | |
13127 | unsigned int reloc_type = 0; | |
13128 | unsigned long sym_index = 0; | |
13129 | ||
13130 | if (reloc) | |
13131 | { | |
13132 | reloc_type = get_reloc_type (filedata, reloc->r_info); | |
13133 | sym_index = get_reloc_symindex (reloc->r_info); | |
13134 | } | |
13135 | ||
13136 | switch (filedata->file_header.e_machine) | |
13137 | { | |
13138 | case EM_MSP430: | |
13139 | case EM_MSP430_OLD: | |
13140 | { | |
13141 | static Elf_Internal_Sym * saved_sym = NULL; | |
13142 | ||
13143 | if (reloc == NULL) | |
13144 | { | |
13145 | saved_sym = NULL; | |
13146 | return TRUE; | |
13147 | } | |
13148 | ||
13149 | switch (reloc_type) | |
13150 | { | |
13151 | case 10: /* R_MSP430_SYM_DIFF */ | |
13152 | case 12: /* R_MSP430_GNU_SUB_ULEB128 */ | |
13153 | if (uses_msp430x_relocs (filedata)) | |
13154 | break; | |
13155 | /* Fall through. */ | |
13156 | case 21: /* R_MSP430X_SYM_DIFF */ | |
13157 | case 23: /* R_MSP430X_GNU_SUB_ULEB128 */ | |
13158 | /* PR 21139. */ | |
13159 | if (sym_index >= num_syms) | |
13160 | error (_("MSP430 SYM_DIFF reloc contains invalid symbol index %lu\n"), | |
13161 | sym_index); | |
13162 | else | |
13163 | saved_sym = symtab + sym_index; | |
13164 | return TRUE; | |
13165 | ||
13166 | case 1: /* R_MSP430_32 or R_MSP430_ABS32 */ | |
13167 | case 3: /* R_MSP430_16 or R_MSP430_ABS8 */ | |
13168 | goto handle_sym_diff; | |
13169 | ||
13170 | case 5: /* R_MSP430_16_BYTE */ | |
13171 | case 9: /* R_MSP430_8 */ | |
13172 | case 11: /* R_MSP430_GNU_SET_ULEB128 */ | |
13173 | if (uses_msp430x_relocs (filedata)) | |
13174 | break; | |
13175 | goto handle_sym_diff; | |
13176 | ||
13177 | case 2: /* R_MSP430_ABS16 */ | |
13178 | case 15: /* R_MSP430X_ABS16 */ | |
13179 | case 22: /* R_MSP430X_GNU_SET_ULEB128 */ | |
13180 | if (! uses_msp430x_relocs (filedata)) | |
13181 | break; | |
13182 | goto handle_sym_diff; | |
13183 | ||
13184 | handle_sym_diff: | |
13185 | if (saved_sym != NULL) | |
13186 | { | |
13187 | bfd_vma value; | |
13188 | unsigned int reloc_size = 0; | |
13189 | int leb_ret = 0; | |
13190 | switch (reloc_type) | |
13191 | { | |
13192 | case 1: /* R_MSP430_32 or R_MSP430_ABS32 */ | |
13193 | reloc_size = 4; | |
13194 | break; | |
13195 | case 11: /* R_MSP430_GNU_SET_ULEB128 */ | |
13196 | case 22: /* R_MSP430X_GNU_SET_ULEB128 */ | |
13197 | if (reloc->r_offset < (size_t) (end - start)) | |
13198 | read_leb128 (start + reloc->r_offset, end, FALSE, | |
13199 | &reloc_size, &leb_ret); | |
13200 | break; | |
13201 | default: | |
13202 | reloc_size = 2; | |
13203 | break; | |
13204 | } | |
13205 | ||
13206 | if (leb_ret != 0 || reloc_size == 0 || reloc_size > 8) | |
13207 | error (_("MSP430 ULEB128 field at 0x%lx contains invalid " | |
13208 | "ULEB128 value\n"), | |
13209 | (long) reloc->r_offset); | |
13210 | else if (sym_index >= num_syms) | |
13211 | error (_("MSP430 reloc contains invalid symbol index %lu\n"), | |
13212 | sym_index); | |
13213 | else | |
13214 | { | |
13215 | value = reloc->r_addend + (symtab[sym_index].st_value | |
13216 | - saved_sym->st_value); | |
13217 | ||
13218 | if (IN_RANGE (start, end, start + reloc->r_offset, reloc_size)) | |
13219 | byte_put (start + reloc->r_offset, value, reloc_size); | |
13220 | else | |
13221 | /* PR 21137 */ | |
13222 | error (_("MSP430 sym diff reloc contains invalid offset: 0x%lx\n"), | |
13223 | (long) reloc->r_offset); | |
13224 | } | |
13225 | ||
13226 | saved_sym = NULL; | |
13227 | return TRUE; | |
13228 | } | |
13229 | break; | |
13230 | ||
13231 | default: | |
13232 | if (saved_sym != NULL) | |
13233 | error (_("Unhandled MSP430 reloc type found after SYM_DIFF reloc\n")); | |
13234 | break; | |
13235 | } | |
13236 | break; | |
13237 | } | |
13238 | ||
13239 | case EM_MN10300: | |
13240 | case EM_CYGNUS_MN10300: | |
13241 | { | |
13242 | static Elf_Internal_Sym * saved_sym = NULL; | |
13243 | ||
13244 | if (reloc == NULL) | |
13245 | { | |
13246 | saved_sym = NULL; | |
13247 | return TRUE; | |
13248 | } | |
13249 | ||
13250 | switch (reloc_type) | |
13251 | { | |
13252 | case 34: /* R_MN10300_ALIGN */ | |
13253 | return TRUE; | |
13254 | case 33: /* R_MN10300_SYM_DIFF */ | |
13255 | if (sym_index >= num_syms) | |
13256 | error (_("MN10300_SYM_DIFF reloc contains invalid symbol index %lu\n"), | |
13257 | sym_index); | |
13258 | else | |
13259 | saved_sym = symtab + sym_index; | |
13260 | return TRUE; | |
13261 | ||
13262 | case 1: /* R_MN10300_32 */ | |
13263 | case 2: /* R_MN10300_16 */ | |
13264 | if (saved_sym != NULL) | |
13265 | { | |
13266 | int reloc_size = reloc_type == 1 ? 4 : 2; | |
13267 | bfd_vma value; | |
13268 | ||
13269 | if (sym_index >= num_syms) | |
13270 | error (_("MN10300 reloc contains invalid symbol index %lu\n"), | |
13271 | sym_index); | |
13272 | else | |
13273 | { | |
13274 | value = reloc->r_addend + (symtab[sym_index].st_value | |
13275 | - saved_sym->st_value); | |
13276 | ||
13277 | if (IN_RANGE (start, end, start + reloc->r_offset, reloc_size)) | |
13278 | byte_put (start + reloc->r_offset, value, reloc_size); | |
13279 | else | |
13280 | error (_("MN10300 sym diff reloc contains invalid offset: 0x%lx\n"), | |
13281 | (long) reloc->r_offset); | |
13282 | } | |
13283 | ||
13284 | saved_sym = NULL; | |
13285 | return TRUE; | |
13286 | } | |
13287 | break; | |
13288 | default: | |
13289 | if (saved_sym != NULL) | |
13290 | error (_("Unhandled MN10300 reloc type found after SYM_DIFF reloc\n")); | |
13291 | break; | |
13292 | } | |
13293 | break; | |
13294 | } | |
13295 | ||
13296 | case EM_RL78: | |
13297 | { | |
13298 | static bfd_vma saved_sym1 = 0; | |
13299 | static bfd_vma saved_sym2 = 0; | |
13300 | static bfd_vma value; | |
13301 | ||
13302 | if (reloc == NULL) | |
13303 | { | |
13304 | saved_sym1 = saved_sym2 = 0; | |
13305 | return TRUE; | |
13306 | } | |
13307 | ||
13308 | switch (reloc_type) | |
13309 | { | |
13310 | case 0x80: /* R_RL78_SYM. */ | |
13311 | saved_sym1 = saved_sym2; | |
13312 | if (sym_index >= num_syms) | |
13313 | error (_("RL78_SYM reloc contains invalid symbol index %lu\n"), | |
13314 | sym_index); | |
13315 | else | |
13316 | { | |
13317 | saved_sym2 = symtab[sym_index].st_value; | |
13318 | saved_sym2 += reloc->r_addend; | |
13319 | } | |
13320 | return TRUE; | |
13321 | ||
13322 | case 0x83: /* R_RL78_OPsub. */ | |
13323 | value = saved_sym1 - saved_sym2; | |
13324 | saved_sym2 = saved_sym1 = 0; | |
13325 | return TRUE; | |
13326 | break; | |
13327 | ||
13328 | case 0x41: /* R_RL78_ABS32. */ | |
13329 | if (IN_RANGE (start, end, start + reloc->r_offset, 4)) | |
13330 | byte_put (start + reloc->r_offset, value, 4); | |
13331 | else | |
13332 | error (_("RL78 sym diff reloc contains invalid offset: 0x%lx\n"), | |
13333 | (long) reloc->r_offset); | |
13334 | value = 0; | |
13335 | return TRUE; | |
13336 | ||
13337 | case 0x43: /* R_RL78_ABS16. */ | |
13338 | if (IN_RANGE (start, end, start + reloc->r_offset, 2)) | |
13339 | byte_put (start + reloc->r_offset, value, 2); | |
13340 | else | |
13341 | error (_("RL78 sym diff reloc contains invalid offset: 0x%lx\n"), | |
13342 | (long) reloc->r_offset); | |
13343 | value = 0; | |
13344 | return TRUE; | |
13345 | ||
13346 | default: | |
13347 | break; | |
13348 | } | |
13349 | break; | |
13350 | } | |
13351 | } | |
13352 | ||
13353 | return FALSE; | |
13354 | } | |
13355 | ||
13356 | /* Returns TRUE iff RELOC_TYPE is a 32-bit absolute RELA relocation used in | |
13357 | DWARF debug sections. This is a target specific test. Note - we do not | |
13358 | go through the whole including-target-headers-multiple-times route, (as | |
13359 | we have already done with <elf/h8.h>) because this would become very | |
13360 | messy and even then this function would have to contain target specific | |
13361 | information (the names of the relocs instead of their numeric values). | |
13362 | FIXME: This is not the correct way to solve this problem. The proper way | |
13363 | is to have target specific reloc sizing and typing functions created by | |
13364 | the reloc-macros.h header, in the same way that it already creates the | |
13365 | reloc naming functions. */ | |
13366 | ||
13367 | static bfd_boolean | |
13368 | is_32bit_abs_reloc (Filedata * filedata, unsigned int reloc_type) | |
13369 | { | |
13370 | /* Please keep this table alpha-sorted for ease of visual lookup. */ | |
13371 | switch (filedata->file_header.e_machine) | |
13372 | { | |
13373 | case EM_386: | |
13374 | case EM_IAMCU: | |
13375 | return reloc_type == 1; /* R_386_32. */ | |
13376 | case EM_68K: | |
13377 | return reloc_type == 1; /* R_68K_32. */ | |
13378 | case EM_860: | |
13379 | return reloc_type == 1; /* R_860_32. */ | |
13380 | case EM_960: | |
13381 | return reloc_type == 2; /* R_960_32. */ | |
13382 | case EM_AARCH64: | |
13383 | return (reloc_type == 258 | |
13384 | || reloc_type == 1); /* R_AARCH64_ABS32 || R_AARCH64_P32_ABS32 */ | |
13385 | case EM_BPF: | |
13386 | return reloc_type == 11; /* R_BPF_DATA_32 */ | |
13387 | case EM_ADAPTEVA_EPIPHANY: | |
13388 | return reloc_type == 3; | |
13389 | case EM_ALPHA: | |
13390 | return reloc_type == 1; /* R_ALPHA_REFLONG. */ | |
13391 | case EM_ARC: | |
13392 | return reloc_type == 1; /* R_ARC_32. */ | |
13393 | case EM_ARC_COMPACT: | |
13394 | case EM_ARC_COMPACT2: | |
13395 | return reloc_type == 4; /* R_ARC_32. */ | |
13396 | case EM_ARM: | |
13397 | return reloc_type == 2; /* R_ARM_ABS32 */ | |
13398 | case EM_AVR_OLD: | |
13399 | case EM_AVR: | |
13400 | return reloc_type == 1; | |
13401 | case EM_BLACKFIN: | |
13402 | return reloc_type == 0x12; /* R_byte4_data. */ | |
13403 | case EM_CRIS: | |
13404 | return reloc_type == 3; /* R_CRIS_32. */ | |
13405 | case EM_CR16: | |
13406 | return reloc_type == 3; /* R_CR16_NUM32. */ | |
13407 | case EM_CRX: | |
13408 | return reloc_type == 15; /* R_CRX_NUM32. */ | |
13409 | case EM_CSKY: | |
13410 | return reloc_type == 1; /* R_CKCORE_ADDR32. */ | |
13411 | case EM_CYGNUS_FRV: | |
13412 | return reloc_type == 1; | |
13413 | case EM_CYGNUS_D10V: | |
13414 | case EM_D10V: | |
13415 | return reloc_type == 6; /* R_D10V_32. */ | |
13416 | case EM_CYGNUS_D30V: | |
13417 | case EM_D30V: | |
13418 | return reloc_type == 12; /* R_D30V_32_NORMAL. */ | |
13419 | case EM_DLX: | |
13420 | return reloc_type == 3; /* R_DLX_RELOC_32. */ | |
13421 | case EM_CYGNUS_FR30: | |
13422 | case EM_FR30: | |
13423 | return reloc_type == 3; /* R_FR30_32. */ | |
13424 | case EM_FT32: | |
13425 | return reloc_type == 1; /* R_FT32_32. */ | |
13426 | case EM_H8S: | |
13427 | case EM_H8_300: | |
13428 | case EM_H8_300H: | |
13429 | return reloc_type == 1; /* R_H8_DIR32. */ | |
13430 | case EM_IA_64: | |
13431 | return (reloc_type == 0x64 /* R_IA64_SECREL32MSB. */ | |
13432 | || reloc_type == 0x65 /* R_IA64_SECREL32LSB. */ | |
13433 | || reloc_type == 0x24 /* R_IA64_DIR32MSB. */ | |
13434 | || reloc_type == 0x25 /* R_IA64_DIR32LSB. */); | |
13435 | case EM_IP2K_OLD: | |
13436 | case EM_IP2K: | |
13437 | return reloc_type == 2; /* R_IP2K_32. */ | |
13438 | case EM_IQ2000: | |
13439 | return reloc_type == 2; /* R_IQ2000_32. */ | |
13440 | case EM_LATTICEMICO32: | |
13441 | return reloc_type == 3; /* R_LM32_32. */ | |
13442 | case EM_M32C_OLD: | |
13443 | case EM_M32C: | |
13444 | return reloc_type == 3; /* R_M32C_32. */ | |
13445 | case EM_M32R: | |
13446 | return reloc_type == 34; /* R_M32R_32_RELA. */ | |
13447 | case EM_68HC11: | |
13448 | case EM_68HC12: | |
13449 | return reloc_type == 6; /* R_M68HC11_32. */ | |
13450 | case EM_S12Z: | |
13451 | return reloc_type == 7 || /* R_S12Z_EXT32 */ | |
13452 | reloc_type == 6; /* R_S12Z_CW32. */ | |
13453 | case EM_MCORE: | |
13454 | return reloc_type == 1; /* R_MCORE_ADDR32. */ | |
13455 | case EM_CYGNUS_MEP: | |
13456 | return reloc_type == 4; /* R_MEP_32. */ | |
13457 | case EM_METAG: | |
13458 | return reloc_type == 2; /* R_METAG_ADDR32. */ | |
13459 | case EM_MICROBLAZE: | |
13460 | return reloc_type == 1; /* R_MICROBLAZE_32. */ | |
13461 | case EM_MIPS: | |
13462 | return reloc_type == 2; /* R_MIPS_32. */ | |
13463 | case EM_MMIX: | |
13464 | return reloc_type == 4; /* R_MMIX_32. */ | |
13465 | case EM_CYGNUS_MN10200: | |
13466 | case EM_MN10200: | |
13467 | return reloc_type == 1; /* R_MN10200_32. */ | |
13468 | case EM_CYGNUS_MN10300: | |
13469 | case EM_MN10300: | |
13470 | return reloc_type == 1; /* R_MN10300_32. */ | |
13471 | case EM_MOXIE: | |
13472 | return reloc_type == 1; /* R_MOXIE_32. */ | |
13473 | case EM_MSP430_OLD: | |
13474 | case EM_MSP430: | |
13475 | return reloc_type == 1; /* R_MSP430_32 or R_MSP320_ABS32. */ | |
13476 | case EM_MT: | |
13477 | return reloc_type == 2; /* R_MT_32. */ | |
13478 | case EM_NDS32: | |
13479 | return reloc_type == 20; /* R_NDS32_RELA. */ | |
13480 | case EM_ALTERA_NIOS2: | |
13481 | return reloc_type == 12; /* R_NIOS2_BFD_RELOC_32. */ | |
13482 | case EM_NIOS32: | |
13483 | return reloc_type == 1; /* R_NIOS_32. */ | |
13484 | case EM_OR1K: | |
13485 | return reloc_type == 1; /* R_OR1K_32. */ | |
13486 | case EM_PARISC: | |
13487 | return (reloc_type == 1 /* R_PARISC_DIR32. */ | |
13488 | || reloc_type == 2 /* R_PARISC_DIR21L. */ | |
13489 | || reloc_type == 41); /* R_PARISC_SECREL32. */ | |
13490 | case EM_PJ: | |
13491 | case EM_PJ_OLD: | |
13492 | return reloc_type == 1; /* R_PJ_DATA_DIR32. */ | |
13493 | case EM_PPC64: | |
13494 | return reloc_type == 1; /* R_PPC64_ADDR32. */ | |
13495 | case EM_PPC: | |
13496 | return reloc_type == 1; /* R_PPC_ADDR32. */ | |
13497 | case EM_TI_PRU: | |
13498 | return reloc_type == 11; /* R_PRU_BFD_RELOC_32. */ | |
13499 | case EM_RISCV: | |
13500 | return reloc_type == 1; /* R_RISCV_32. */ | |
13501 | case EM_RL78: | |
13502 | return reloc_type == 1; /* R_RL78_DIR32. */ | |
13503 | case EM_RX: | |
13504 | return reloc_type == 1; /* R_RX_DIR32. */ | |
13505 | case EM_S370: | |
13506 | return reloc_type == 1; /* R_I370_ADDR31. */ | |
13507 | case EM_S390_OLD: | |
13508 | case EM_S390: | |
13509 | return reloc_type == 4; /* R_S390_32. */ | |
13510 | case EM_SCORE: | |
13511 | return reloc_type == 8; /* R_SCORE_ABS32. */ | |
13512 | case EM_SH: | |
13513 | return reloc_type == 1; /* R_SH_DIR32. */ | |
13514 | case EM_SPARC32PLUS: | |
13515 | case EM_SPARCV9: | |
13516 | case EM_SPARC: | |
13517 | return reloc_type == 3 /* R_SPARC_32. */ | |
13518 | || reloc_type == 23; /* R_SPARC_UA32. */ | |
13519 | case EM_SPU: | |
13520 | return reloc_type == 6; /* R_SPU_ADDR32 */ | |
13521 | case EM_TI_C6000: | |
13522 | return reloc_type == 1; /* R_C6000_ABS32. */ | |
13523 | case EM_TILEGX: | |
13524 | return reloc_type == 2; /* R_TILEGX_32. */ | |
13525 | case EM_TILEPRO: | |
13526 | return reloc_type == 1; /* R_TILEPRO_32. */ | |
13527 | case EM_CYGNUS_V850: | |
13528 | case EM_V850: | |
13529 | return reloc_type == 6; /* R_V850_ABS32. */ | |
13530 | case EM_V800: | |
13531 | return reloc_type == 0x33; /* R_V810_WORD. */ | |
13532 | case EM_VAX: | |
13533 | return reloc_type == 1; /* R_VAX_32. */ | |
13534 | case EM_VISIUM: | |
13535 | return reloc_type == 3; /* R_VISIUM_32. */ | |
13536 | case EM_WEBASSEMBLY: | |
13537 | return reloc_type == 1; /* R_WASM32_32. */ | |
13538 | case EM_X86_64: | |
13539 | case EM_L1OM: | |
13540 | case EM_K1OM: | |
13541 | return reloc_type == 10; /* R_X86_64_32. */ | |
13542 | case EM_XC16X: | |
13543 | case EM_C166: | |
13544 | return reloc_type == 3; /* R_XC16C_ABS_32. */ | |
13545 | case EM_XGATE: | |
13546 | return reloc_type == 4; /* R_XGATE_32. */ | |
13547 | case EM_XSTORMY16: | |
13548 | return reloc_type == 1; /* R_XSTROMY16_32. */ | |
13549 | case EM_XTENSA_OLD: | |
13550 | case EM_XTENSA: | |
13551 | return reloc_type == 1; /* R_XTENSA_32. */ | |
13552 | case EM_Z80: | |
13553 | return reloc_type == 6; /* R_Z80_32. */ | |
13554 | default: | |
13555 | { | |
13556 | static unsigned int prev_warn = 0; | |
13557 | ||
13558 | /* Avoid repeating the same warning multiple times. */ | |
13559 | if (prev_warn != filedata->file_header.e_machine) | |
13560 | error (_("Missing knowledge of 32-bit reloc types used in DWARF sections of machine number %d\n"), | |
13561 | filedata->file_header.e_machine); | |
13562 | prev_warn = filedata->file_header.e_machine; | |
13563 | return FALSE; | |
13564 | } | |
13565 | } | |
13566 | } | |
13567 | ||
13568 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
13569 | a 32-bit pc-relative RELA relocation used in DWARF debug sections. */ | |
13570 | ||
13571 | static bfd_boolean | |
13572 | is_32bit_pcrel_reloc (Filedata * filedata, unsigned int reloc_type) | |
13573 | { | |
13574 | switch (filedata->file_header.e_machine) | |
13575 | /* Please keep this table alpha-sorted for ease of visual lookup. */ | |
13576 | { | |
13577 | case EM_386: | |
13578 | case EM_IAMCU: | |
13579 | return reloc_type == 2; /* R_386_PC32. */ | |
13580 | case EM_68K: | |
13581 | return reloc_type == 4; /* R_68K_PC32. */ | |
13582 | case EM_AARCH64: | |
13583 | return reloc_type == 261; /* R_AARCH64_PREL32 */ | |
13584 | case EM_ADAPTEVA_EPIPHANY: | |
13585 | return reloc_type == 6; | |
13586 | case EM_ALPHA: | |
13587 | return reloc_type == 10; /* R_ALPHA_SREL32. */ | |
13588 | case EM_ARC_COMPACT: | |
13589 | case EM_ARC_COMPACT2: | |
13590 | return reloc_type == 49; /* R_ARC_32_PCREL. */ | |
13591 | case EM_ARM: | |
13592 | return reloc_type == 3; /* R_ARM_REL32 */ | |
13593 | case EM_AVR_OLD: | |
13594 | case EM_AVR: | |
13595 | return reloc_type == 36; /* R_AVR_32_PCREL. */ | |
13596 | case EM_MICROBLAZE: | |
13597 | return reloc_type == 2; /* R_MICROBLAZE_32_PCREL. */ | |
13598 | case EM_OR1K: | |
13599 | return reloc_type == 9; /* R_OR1K_32_PCREL. */ | |
13600 | case EM_PARISC: | |
13601 | return reloc_type == 9; /* R_PARISC_PCREL32. */ | |
13602 | case EM_PPC: | |
13603 | return reloc_type == 26; /* R_PPC_REL32. */ | |
13604 | case EM_PPC64: | |
13605 | return reloc_type == 26; /* R_PPC64_REL32. */ | |
13606 | case EM_RISCV: | |
13607 | return reloc_type == 57; /* R_RISCV_32_PCREL. */ | |
13608 | case EM_S390_OLD: | |
13609 | case EM_S390: | |
13610 | return reloc_type == 5; /* R_390_PC32. */ | |
13611 | case EM_SH: | |
13612 | return reloc_type == 2; /* R_SH_REL32. */ | |
13613 | case EM_SPARC32PLUS: | |
13614 | case EM_SPARCV9: | |
13615 | case EM_SPARC: | |
13616 | return reloc_type == 6; /* R_SPARC_DISP32. */ | |
13617 | case EM_SPU: | |
13618 | return reloc_type == 13; /* R_SPU_REL32. */ | |
13619 | case EM_TILEGX: | |
13620 | return reloc_type == 6; /* R_TILEGX_32_PCREL. */ | |
13621 | case EM_TILEPRO: | |
13622 | return reloc_type == 4; /* R_TILEPRO_32_PCREL. */ | |
13623 | case EM_VISIUM: | |
13624 | return reloc_type == 6; /* R_VISIUM_32_PCREL */ | |
13625 | case EM_X86_64: | |
13626 | case EM_L1OM: | |
13627 | case EM_K1OM: | |
13628 | return reloc_type == 2; /* R_X86_64_PC32. */ | |
13629 | case EM_VAX: | |
13630 | return reloc_type == 4; /* R_VAX_PCREL32. */ | |
13631 | case EM_XTENSA_OLD: | |
13632 | case EM_XTENSA: | |
13633 | return reloc_type == 14; /* R_XTENSA_32_PCREL. */ | |
13634 | default: | |
13635 | /* Do not abort or issue an error message here. Not all targets use | |
13636 | pc-relative 32-bit relocs in their DWARF debug information and we | |
13637 | have already tested for target coverage in is_32bit_abs_reloc. A | |
13638 | more helpful warning message will be generated by apply_relocations | |
13639 | anyway, so just return. */ | |
13640 | return FALSE; | |
13641 | } | |
13642 | } | |
13643 | ||
13644 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
13645 | a 64-bit absolute RELA relocation used in DWARF debug sections. */ | |
13646 | ||
13647 | static bfd_boolean | |
13648 | is_64bit_abs_reloc (Filedata * filedata, unsigned int reloc_type) | |
13649 | { | |
13650 | switch (filedata->file_header.e_machine) | |
13651 | { | |
13652 | case EM_AARCH64: | |
13653 | return reloc_type == 257; /* R_AARCH64_ABS64. */ | |
13654 | case EM_ALPHA: | |
13655 | return reloc_type == 2; /* R_ALPHA_REFQUAD. */ | |
13656 | case EM_IA_64: | |
13657 | return (reloc_type == 0x26 /* R_IA64_DIR64MSB. */ | |
13658 | || reloc_type == 0x27 /* R_IA64_DIR64LSB. */); | |
13659 | case EM_PARISC: | |
13660 | return reloc_type == 80; /* R_PARISC_DIR64. */ | |
13661 | case EM_PPC64: | |
13662 | return reloc_type == 38; /* R_PPC64_ADDR64. */ | |
13663 | case EM_RISCV: | |
13664 | return reloc_type == 2; /* R_RISCV_64. */ | |
13665 | case EM_SPARC32PLUS: | |
13666 | case EM_SPARCV9: | |
13667 | case EM_SPARC: | |
13668 | return reloc_type == 32 /* R_SPARC_64. */ | |
13669 | || reloc_type == 54; /* R_SPARC_UA64. */ | |
13670 | case EM_X86_64: | |
13671 | case EM_L1OM: | |
13672 | case EM_K1OM: | |
13673 | return reloc_type == 1; /* R_X86_64_64. */ | |
13674 | case EM_S390_OLD: | |
13675 | case EM_S390: | |
13676 | return reloc_type == 22; /* R_S390_64. */ | |
13677 | case EM_TILEGX: | |
13678 | return reloc_type == 1; /* R_TILEGX_64. */ | |
13679 | case EM_MIPS: | |
13680 | return reloc_type == 18; /* R_MIPS_64. */ | |
13681 | default: | |
13682 | return FALSE; | |
13683 | } | |
13684 | } | |
13685 | ||
13686 | /* Like is_32bit_pcrel_reloc except that it returns TRUE iff RELOC_TYPE is | |
13687 | a 64-bit pc-relative RELA relocation used in DWARF debug sections. */ | |
13688 | ||
13689 | static bfd_boolean | |
13690 | is_64bit_pcrel_reloc (Filedata * filedata, unsigned int reloc_type) | |
13691 | { | |
13692 | switch (filedata->file_header.e_machine) | |
13693 | { | |
13694 | case EM_AARCH64: | |
13695 | return reloc_type == 260; /* R_AARCH64_PREL64. */ | |
13696 | case EM_ALPHA: | |
13697 | return reloc_type == 11; /* R_ALPHA_SREL64. */ | |
13698 | case EM_IA_64: | |
13699 | return (reloc_type == 0x4e /* R_IA64_PCREL64MSB. */ | |
13700 | || reloc_type == 0x4f /* R_IA64_PCREL64LSB. */); | |
13701 | case EM_PARISC: | |
13702 | return reloc_type == 72; /* R_PARISC_PCREL64. */ | |
13703 | case EM_PPC64: | |
13704 | return reloc_type == 44; /* R_PPC64_REL64. */ | |
13705 | case EM_SPARC32PLUS: | |
13706 | case EM_SPARCV9: | |
13707 | case EM_SPARC: | |
13708 | return reloc_type == 46; /* R_SPARC_DISP64. */ | |
13709 | case EM_X86_64: | |
13710 | case EM_L1OM: | |
13711 | case EM_K1OM: | |
13712 | return reloc_type == 24; /* R_X86_64_PC64. */ | |
13713 | case EM_S390_OLD: | |
13714 | case EM_S390: | |
13715 | return reloc_type == 23; /* R_S390_PC64. */ | |
13716 | case EM_TILEGX: | |
13717 | return reloc_type == 5; /* R_TILEGX_64_PCREL. */ | |
13718 | default: | |
13719 | return FALSE; | |
13720 | } | |
13721 | } | |
13722 | ||
13723 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
13724 | a 24-bit absolute RELA relocation used in DWARF debug sections. */ | |
13725 | ||
13726 | static bfd_boolean | |
13727 | is_24bit_abs_reloc (Filedata * filedata, unsigned int reloc_type) | |
13728 | { | |
13729 | switch (filedata->file_header.e_machine) | |
13730 | { | |
13731 | case EM_CYGNUS_MN10200: | |
13732 | case EM_MN10200: | |
13733 | return reloc_type == 4; /* R_MN10200_24. */ | |
13734 | case EM_FT32: | |
13735 | return reloc_type == 5; /* R_FT32_20. */ | |
13736 | case EM_Z80: | |
13737 | return reloc_type == 5; /* R_Z80_24. */ | |
13738 | default: | |
13739 | return FALSE; | |
13740 | } | |
13741 | } | |
13742 | ||
13743 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
13744 | a 16-bit absolute RELA relocation used in DWARF debug sections. */ | |
13745 | ||
13746 | static bfd_boolean | |
13747 | is_16bit_abs_reloc (Filedata * filedata, unsigned int reloc_type) | |
13748 | { | |
13749 | /* Please keep this table alpha-sorted for ease of visual lookup. */ | |
13750 | switch (filedata->file_header.e_machine) | |
13751 | { | |
13752 | case EM_ARC: | |
13753 | case EM_ARC_COMPACT: | |
13754 | case EM_ARC_COMPACT2: | |
13755 | return reloc_type == 2; /* R_ARC_16. */ | |
13756 | case EM_ADAPTEVA_EPIPHANY: | |
13757 | return reloc_type == 5; | |
13758 | case EM_AVR_OLD: | |
13759 | case EM_AVR: | |
13760 | return reloc_type == 4; /* R_AVR_16. */ | |
13761 | case EM_CYGNUS_D10V: | |
13762 | case EM_D10V: | |
13763 | return reloc_type == 3; /* R_D10V_16. */ | |
13764 | case EM_FT32: | |
13765 | return reloc_type == 2; /* R_FT32_16. */ | |
13766 | case EM_H8S: | |
13767 | case EM_H8_300: | |
13768 | case EM_H8_300H: | |
13769 | return reloc_type == R_H8_DIR16; | |
13770 | case EM_IP2K_OLD: | |
13771 | case EM_IP2K: | |
13772 | return reloc_type == 1; /* R_IP2K_16. */ | |
13773 | case EM_M32C_OLD: | |
13774 | case EM_M32C: | |
13775 | return reloc_type == 1; /* R_M32C_16 */ | |
13776 | case EM_CYGNUS_MN10200: | |
13777 | case EM_MN10200: | |
13778 | return reloc_type == 2; /* R_MN10200_16. */ | |
13779 | case EM_CYGNUS_MN10300: | |
13780 | case EM_MN10300: | |
13781 | return reloc_type == 2; /* R_MN10300_16. */ | |
13782 | case EM_MSP430: | |
13783 | if (uses_msp430x_relocs (filedata)) | |
13784 | return reloc_type == 2; /* R_MSP430_ABS16. */ | |
13785 | /* Fall through. */ | |
13786 | case EM_MSP430_OLD: | |
13787 | return reloc_type == 5; /* R_MSP430_16_BYTE. */ | |
13788 | case EM_NDS32: | |
13789 | return reloc_type == 19; /* R_NDS32_RELA. */ | |
13790 | case EM_ALTERA_NIOS2: | |
13791 | return reloc_type == 13; /* R_NIOS2_BFD_RELOC_16. */ | |
13792 | case EM_NIOS32: | |
13793 | return reloc_type == 9; /* R_NIOS_16. */ | |
13794 | case EM_OR1K: | |
13795 | return reloc_type == 2; /* R_OR1K_16. */ | |
13796 | case EM_RISCV: | |
13797 | return reloc_type == 55; /* R_RISCV_SET16. */ | |
13798 | case EM_TI_PRU: | |
13799 | return reloc_type == 8; /* R_PRU_BFD_RELOC_16. */ | |
13800 | case EM_TI_C6000: | |
13801 | return reloc_type == 2; /* R_C6000_ABS16. */ | |
13802 | case EM_VISIUM: | |
13803 | return reloc_type == 2; /* R_VISIUM_16. */ | |
13804 | case EM_XC16X: | |
13805 | case EM_C166: | |
13806 | return reloc_type == 2; /* R_XC16C_ABS_16. */ | |
13807 | case EM_XGATE: | |
13808 | return reloc_type == 3; /* R_XGATE_16. */ | |
13809 | case EM_Z80: | |
13810 | return reloc_type == 4; /* R_Z80_16. */ | |
13811 | default: | |
13812 | return FALSE; | |
13813 | } | |
13814 | } | |
13815 | ||
13816 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
13817 | a 8-bit absolute RELA relocation used in DWARF debug sections. */ | |
13818 | ||
13819 | static bfd_boolean | |
13820 | is_8bit_abs_reloc (Filedata * filedata, unsigned int reloc_type) | |
13821 | { | |
13822 | switch (filedata->file_header.e_machine) | |
13823 | { | |
13824 | case EM_RISCV: | |
13825 | return reloc_type == 54; /* R_RISCV_SET8. */ | |
13826 | case EM_Z80: | |
13827 | return reloc_type == 1; /* R_Z80_8. */ | |
13828 | default: | |
13829 | return FALSE; | |
13830 | } | |
13831 | } | |
13832 | ||
13833 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
13834 | a 6-bit absolute RELA relocation used in DWARF debug sections. */ | |
13835 | ||
13836 | static bfd_boolean | |
13837 | is_6bit_abs_reloc (Filedata * filedata, unsigned int reloc_type) | |
13838 | { | |
13839 | switch (filedata->file_header.e_machine) | |
13840 | { | |
13841 | case EM_RISCV: | |
13842 | return reloc_type == 53; /* R_RISCV_SET6. */ | |
13843 | default: | |
13844 | return FALSE; | |
13845 | } | |
13846 | } | |
13847 | ||
13848 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
13849 | a 32-bit inplace add RELA relocation used in DWARF debug sections. */ | |
13850 | ||
13851 | static bfd_boolean | |
13852 | is_32bit_inplace_add_reloc (Filedata * filedata, unsigned int reloc_type) | |
13853 | { | |
13854 | /* Please keep this table alpha-sorted for ease of visual lookup. */ | |
13855 | switch (filedata->file_header.e_machine) | |
13856 | { | |
13857 | case EM_RISCV: | |
13858 | return reloc_type == 35; /* R_RISCV_ADD32. */ | |
13859 | default: | |
13860 | return FALSE; | |
13861 | } | |
13862 | } | |
13863 | ||
13864 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
13865 | a 32-bit inplace sub RELA relocation used in DWARF debug sections. */ | |
13866 | ||
13867 | static bfd_boolean | |
13868 | is_32bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type) | |
13869 | { | |
13870 | /* Please keep this table alpha-sorted for ease of visual lookup. */ | |
13871 | switch (filedata->file_header.e_machine) | |
13872 | { | |
13873 | case EM_RISCV: | |
13874 | return reloc_type == 39; /* R_RISCV_SUB32. */ | |
13875 | default: | |
13876 | return FALSE; | |
13877 | } | |
13878 | } | |
13879 | ||
13880 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
13881 | a 64-bit inplace add RELA relocation used in DWARF debug sections. */ | |
13882 | ||
13883 | static bfd_boolean | |
13884 | is_64bit_inplace_add_reloc (Filedata * filedata, unsigned int reloc_type) | |
13885 | { | |
13886 | /* Please keep this table alpha-sorted for ease of visual lookup. */ | |
13887 | switch (filedata->file_header.e_machine) | |
13888 | { | |
13889 | case EM_RISCV: | |
13890 | return reloc_type == 36; /* R_RISCV_ADD64. */ | |
13891 | default: | |
13892 | return FALSE; | |
13893 | } | |
13894 | } | |
13895 | ||
13896 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
13897 | a 64-bit inplace sub RELA relocation used in DWARF debug sections. */ | |
13898 | ||
13899 | static bfd_boolean | |
13900 | is_64bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type) | |
13901 | { | |
13902 | /* Please keep this table alpha-sorted for ease of visual lookup. */ | |
13903 | switch (filedata->file_header.e_machine) | |
13904 | { | |
13905 | case EM_RISCV: | |
13906 | return reloc_type == 40; /* R_RISCV_SUB64. */ | |
13907 | default: | |
13908 | return FALSE; | |
13909 | } | |
13910 | } | |
13911 | ||
13912 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
13913 | a 16-bit inplace add RELA relocation used in DWARF debug sections. */ | |
13914 | ||
13915 | static bfd_boolean | |
13916 | is_16bit_inplace_add_reloc (Filedata * filedata, unsigned int reloc_type) | |
13917 | { | |
13918 | /* Please keep this table alpha-sorted for ease of visual lookup. */ | |
13919 | switch (filedata->file_header.e_machine) | |
13920 | { | |
13921 | case EM_RISCV: | |
13922 | return reloc_type == 34; /* R_RISCV_ADD16. */ | |
13923 | default: | |
13924 | return FALSE; | |
13925 | } | |
13926 | } | |
13927 | ||
13928 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
13929 | a 16-bit inplace sub RELA relocation used in DWARF debug sections. */ | |
13930 | ||
13931 | static bfd_boolean | |
13932 | is_16bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type) | |
13933 | { | |
13934 | /* Please keep this table alpha-sorted for ease of visual lookup. */ | |
13935 | switch (filedata->file_header.e_machine) | |
13936 | { | |
13937 | case EM_RISCV: | |
13938 | return reloc_type == 38; /* R_RISCV_SUB16. */ | |
13939 | default: | |
13940 | return FALSE; | |
13941 | } | |
13942 | } | |
13943 | ||
13944 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
13945 | a 8-bit inplace add RELA relocation used in DWARF debug sections. */ | |
13946 | ||
13947 | static bfd_boolean | |
13948 | is_8bit_inplace_add_reloc (Filedata * filedata, unsigned int reloc_type) | |
13949 | { | |
13950 | /* Please keep this table alpha-sorted for ease of visual lookup. */ | |
13951 | switch (filedata->file_header.e_machine) | |
13952 | { | |
13953 | case EM_RISCV: | |
13954 | return reloc_type == 33; /* R_RISCV_ADD8. */ | |
13955 | default: | |
13956 | return FALSE; | |
13957 | } | |
13958 | } | |
13959 | ||
13960 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
13961 | a 8-bit inplace sub RELA relocation used in DWARF debug sections. */ | |
13962 | ||
13963 | static bfd_boolean | |
13964 | is_8bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type) | |
13965 | { | |
13966 | /* Please keep this table alpha-sorted for ease of visual lookup. */ | |
13967 | switch (filedata->file_header.e_machine) | |
13968 | { | |
13969 | case EM_RISCV: | |
13970 | return reloc_type == 37; /* R_RISCV_SUB8. */ | |
13971 | default: | |
13972 | return FALSE; | |
13973 | } | |
13974 | } | |
13975 | ||
13976 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
13977 | a 6-bit inplace sub RELA relocation used in DWARF debug sections. */ | |
13978 | ||
13979 | static bfd_boolean | |
13980 | is_6bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type) | |
13981 | { | |
13982 | switch (filedata->file_header.e_machine) | |
13983 | { | |
13984 | case EM_RISCV: | |
13985 | return reloc_type == 52; /* R_RISCV_SUB6. */ | |
13986 | default: | |
13987 | return FALSE; | |
13988 | } | |
13989 | } | |
13990 | ||
13991 | /* Returns TRUE iff RELOC_TYPE is a NONE relocation used for discarded | |
13992 | relocation entries (possibly formerly used for SHT_GROUP sections). */ | |
13993 | ||
13994 | static bfd_boolean | |
13995 | is_none_reloc (Filedata * filedata, unsigned int reloc_type) | |
13996 | { | |
13997 | switch (filedata->file_header.e_machine) | |
13998 | { | |
13999 | case EM_386: /* R_386_NONE. */ | |
14000 | case EM_68K: /* R_68K_NONE. */ | |
14001 | case EM_ADAPTEVA_EPIPHANY: | |
14002 | case EM_ALPHA: /* R_ALPHA_NONE. */ | |
14003 | case EM_ALTERA_NIOS2: /* R_NIOS2_NONE. */ | |
14004 | case EM_ARC: /* R_ARC_NONE. */ | |
14005 | case EM_ARC_COMPACT2: /* R_ARC_NONE. */ | |
14006 | case EM_ARC_COMPACT: /* R_ARC_NONE. */ | |
14007 | case EM_ARM: /* R_ARM_NONE. */ | |
14008 | case EM_C166: /* R_XC16X_NONE. */ | |
14009 | case EM_CRIS: /* R_CRIS_NONE. */ | |
14010 | case EM_FT32: /* R_FT32_NONE. */ | |
14011 | case EM_IA_64: /* R_IA64_NONE. */ | |
14012 | case EM_K1OM: /* R_X86_64_NONE. */ | |
14013 | case EM_L1OM: /* R_X86_64_NONE. */ | |
14014 | case EM_M32R: /* R_M32R_NONE. */ | |
14015 | case EM_MIPS: /* R_MIPS_NONE. */ | |
14016 | case EM_MN10300: /* R_MN10300_NONE. */ | |
14017 | case EM_MOXIE: /* R_MOXIE_NONE. */ | |
14018 | case EM_NIOS32: /* R_NIOS_NONE. */ | |
14019 | case EM_OR1K: /* R_OR1K_NONE. */ | |
14020 | case EM_PARISC: /* R_PARISC_NONE. */ | |
14021 | case EM_PPC64: /* R_PPC64_NONE. */ | |
14022 | case EM_PPC: /* R_PPC_NONE. */ | |
14023 | case EM_RISCV: /* R_RISCV_NONE. */ | |
14024 | case EM_S390: /* R_390_NONE. */ | |
14025 | case EM_S390_OLD: | |
14026 | case EM_SH: /* R_SH_NONE. */ | |
14027 | case EM_SPARC32PLUS: | |
14028 | case EM_SPARC: /* R_SPARC_NONE. */ | |
14029 | case EM_SPARCV9: | |
14030 | case EM_TILEGX: /* R_TILEGX_NONE. */ | |
14031 | case EM_TILEPRO: /* R_TILEPRO_NONE. */ | |
14032 | case EM_TI_C6000:/* R_C6000_NONE. */ | |
14033 | case EM_X86_64: /* R_X86_64_NONE. */ | |
14034 | case EM_XC16X: | |
14035 | case EM_Z80: /* R_Z80_NONE. */ | |
14036 | case EM_WEBASSEMBLY: /* R_WASM32_NONE. */ | |
14037 | return reloc_type == 0; | |
14038 | ||
14039 | case EM_AARCH64: | |
14040 | return reloc_type == 0 || reloc_type == 256; | |
14041 | case EM_AVR_OLD: | |
14042 | case EM_AVR: | |
14043 | return (reloc_type == 0 /* R_AVR_NONE. */ | |
14044 | || reloc_type == 30 /* R_AVR_DIFF8. */ | |
14045 | || reloc_type == 31 /* R_AVR_DIFF16. */ | |
14046 | || reloc_type == 32 /* R_AVR_DIFF32. */); | |
14047 | case EM_METAG: | |
14048 | return reloc_type == 3; /* R_METAG_NONE. */ | |
14049 | case EM_NDS32: | |
14050 | return (reloc_type == 0 /* R_XTENSA_NONE. */ | |
14051 | || reloc_type == 204 /* R_NDS32_DIFF8. */ | |
14052 | || reloc_type == 205 /* R_NDS32_DIFF16. */ | |
14053 | || reloc_type == 206 /* R_NDS32_DIFF32. */ | |
14054 | || reloc_type == 207 /* R_NDS32_ULEB128. */); | |
14055 | case EM_TI_PRU: | |
14056 | return (reloc_type == 0 /* R_PRU_NONE. */ | |
14057 | || reloc_type == 65 /* R_PRU_DIFF8. */ | |
14058 | || reloc_type == 66 /* R_PRU_DIFF16. */ | |
14059 | || reloc_type == 67 /* R_PRU_DIFF32. */); | |
14060 | case EM_XTENSA_OLD: | |
14061 | case EM_XTENSA: | |
14062 | return (reloc_type == 0 /* R_XTENSA_NONE. */ | |
14063 | || reloc_type == 17 /* R_XTENSA_DIFF8. */ | |
14064 | || reloc_type == 18 /* R_XTENSA_DIFF16. */ | |
14065 | || reloc_type == 19 /* R_XTENSA_DIFF32. */ | |
14066 | || reloc_type == 57 /* R_XTENSA_PDIFF8. */ | |
14067 | || reloc_type == 58 /* R_XTENSA_PDIFF16. */ | |
14068 | || reloc_type == 59 /* R_XTENSA_PDIFF32. */ | |
14069 | || reloc_type == 60 /* R_XTENSA_NDIFF8. */ | |
14070 | || reloc_type == 61 /* R_XTENSA_NDIFF16. */ | |
14071 | || reloc_type == 62 /* R_XTENSA_NDIFF32. */); | |
14072 | } | |
14073 | return FALSE; | |
14074 | } | |
14075 | ||
14076 | /* Returns TRUE if there is a relocation against | |
14077 | section NAME at OFFSET bytes. */ | |
14078 | ||
14079 | bfd_boolean | |
14080 | reloc_at (struct dwarf_section * dsec, dwarf_vma offset) | |
14081 | { | |
14082 | Elf_Internal_Rela * relocs; | |
14083 | Elf_Internal_Rela * rp; | |
14084 | ||
14085 | if (dsec == NULL || dsec->reloc_info == NULL) | |
14086 | return FALSE; | |
14087 | ||
14088 | relocs = (Elf_Internal_Rela *) dsec->reloc_info; | |
14089 | ||
14090 | for (rp = relocs; rp < relocs + dsec->num_relocs; ++rp) | |
14091 | if (rp->r_offset == offset) | |
14092 | return TRUE; | |
14093 | ||
14094 | return FALSE; | |
14095 | } | |
14096 | ||
14097 | /* Apply relocations to a section. | |
14098 | Returns TRUE upon success, FALSE otherwise. | |
14099 | If RELOCS_RETURN is non-NULL then it is set to point to the loaded relocs. | |
14100 | It is then the caller's responsibility to free them. NUM_RELOCS_RETURN | |
14101 | will be set to the number of relocs loaded. | |
14102 | ||
14103 | Note: So far support has been added only for those relocations | |
14104 | which can be found in debug sections. FIXME: Add support for | |
14105 | more relocations ? */ | |
14106 | ||
14107 | static bfd_boolean | |
14108 | apply_relocations (Filedata * filedata, | |
14109 | const Elf_Internal_Shdr * section, | |
14110 | unsigned char * start, | |
14111 | bfd_size_type size, | |
14112 | void ** relocs_return, | |
14113 | unsigned long * num_relocs_return) | |
14114 | { | |
14115 | Elf_Internal_Shdr * relsec; | |
14116 | unsigned char * end = start + size; | |
14117 | ||
14118 | if (relocs_return != NULL) | |
14119 | { | |
14120 | * (Elf_Internal_Rela **) relocs_return = NULL; | |
14121 | * num_relocs_return = 0; | |
14122 | } | |
14123 | ||
14124 | if (filedata->file_header.e_type != ET_REL) | |
14125 | /* No relocs to apply. */ | |
14126 | return TRUE; | |
14127 | ||
14128 | /* Find the reloc section associated with the section. */ | |
14129 | for (relsec = filedata->section_headers; | |
14130 | relsec < filedata->section_headers + filedata->file_header.e_shnum; | |
14131 | ++relsec) | |
14132 | { | |
14133 | bfd_boolean is_rela; | |
14134 | unsigned long num_relocs; | |
14135 | Elf_Internal_Rela * relocs; | |
14136 | Elf_Internal_Rela * rp; | |
14137 | Elf_Internal_Shdr * symsec; | |
14138 | Elf_Internal_Sym * symtab; | |
14139 | unsigned long num_syms; | |
14140 | Elf_Internal_Sym * sym; | |
14141 | ||
14142 | if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL) | |
14143 | || relsec->sh_info >= filedata->file_header.e_shnum | |
14144 | || filedata->section_headers + relsec->sh_info != section | |
14145 | || relsec->sh_size == 0 | |
14146 | || relsec->sh_link >= filedata->file_header.e_shnum) | |
14147 | continue; | |
14148 | ||
14149 | symsec = filedata->section_headers + relsec->sh_link; | |
14150 | if (symsec->sh_type != SHT_SYMTAB | |
14151 | && symsec->sh_type != SHT_DYNSYM) | |
14152 | return FALSE; | |
14153 | ||
14154 | is_rela = relsec->sh_type == SHT_RELA; | |
14155 | ||
14156 | if (is_rela) | |
14157 | { | |
14158 | if (!slurp_rela_relocs (filedata, relsec->sh_offset, | |
14159 | relsec->sh_size, & relocs, & num_relocs)) | |
14160 | return FALSE; | |
14161 | } | |
14162 | else | |
14163 | { | |
14164 | if (!slurp_rel_relocs (filedata, relsec->sh_offset, | |
14165 | relsec->sh_size, & relocs, & num_relocs)) | |
14166 | return FALSE; | |
14167 | } | |
14168 | ||
14169 | /* SH uses RELA but uses in place value instead of the addend field. */ | |
14170 | if (filedata->file_header.e_machine == EM_SH) | |
14171 | is_rela = FALSE; | |
14172 | ||
14173 | symtab = GET_ELF_SYMBOLS (filedata, symsec, & num_syms); | |
14174 | ||
14175 | for (rp = relocs; rp < relocs + num_relocs; ++rp) | |
14176 | { | |
14177 | bfd_vma addend; | |
14178 | unsigned int reloc_type; | |
14179 | unsigned int reloc_size; | |
14180 | bfd_boolean reloc_inplace = FALSE; | |
14181 | bfd_boolean reloc_subtract = FALSE; | |
14182 | unsigned char * rloc; | |
14183 | unsigned long sym_index; | |
14184 | ||
14185 | reloc_type = get_reloc_type (filedata, rp->r_info); | |
14186 | ||
14187 | if (target_specific_reloc_handling (filedata, rp, start, end, symtab, num_syms)) | |
14188 | continue; | |
14189 | else if (is_none_reloc (filedata, reloc_type)) | |
14190 | continue; | |
14191 | else if (is_32bit_abs_reloc (filedata, reloc_type) | |
14192 | || is_32bit_pcrel_reloc (filedata, reloc_type)) | |
14193 | reloc_size = 4; | |
14194 | else if (is_64bit_abs_reloc (filedata, reloc_type) | |
14195 | || is_64bit_pcrel_reloc (filedata, reloc_type)) | |
14196 | reloc_size = 8; | |
14197 | else if (is_24bit_abs_reloc (filedata, reloc_type)) | |
14198 | reloc_size = 3; | |
14199 | else if (is_16bit_abs_reloc (filedata, reloc_type)) | |
14200 | reloc_size = 2; | |
14201 | else if (is_8bit_abs_reloc (filedata, reloc_type) | |
14202 | || is_6bit_abs_reloc (filedata, reloc_type)) | |
14203 | reloc_size = 1; | |
14204 | else if ((reloc_subtract = is_32bit_inplace_sub_reloc (filedata, | |
14205 | reloc_type)) | |
14206 | || is_32bit_inplace_add_reloc (filedata, reloc_type)) | |
14207 | { | |
14208 | reloc_size = 4; | |
14209 | reloc_inplace = TRUE; | |
14210 | } | |
14211 | else if ((reloc_subtract = is_64bit_inplace_sub_reloc (filedata, | |
14212 | reloc_type)) | |
14213 | || is_64bit_inplace_add_reloc (filedata, reloc_type)) | |
14214 | { | |
14215 | reloc_size = 8; | |
14216 | reloc_inplace = TRUE; | |
14217 | } | |
14218 | else if ((reloc_subtract = is_16bit_inplace_sub_reloc (filedata, | |
14219 | reloc_type)) | |
14220 | || is_16bit_inplace_add_reloc (filedata, reloc_type)) | |
14221 | { | |
14222 | reloc_size = 2; | |
14223 | reloc_inplace = TRUE; | |
14224 | } | |
14225 | else if ((reloc_subtract = is_8bit_inplace_sub_reloc (filedata, | |
14226 | reloc_type)) | |
14227 | || is_8bit_inplace_add_reloc (filedata, reloc_type)) | |
14228 | { | |
14229 | reloc_size = 1; | |
14230 | reloc_inplace = TRUE; | |
14231 | } | |
14232 | else if ((reloc_subtract = is_6bit_inplace_sub_reloc (filedata, | |
14233 | reloc_type))) | |
14234 | { | |
14235 | reloc_size = 1; | |
14236 | reloc_inplace = TRUE; | |
14237 | } | |
14238 | else | |
14239 | { | |
14240 | static unsigned int prev_reloc = 0; | |
14241 | ||
14242 | if (reloc_type != prev_reloc) | |
14243 | warn (_("unable to apply unsupported reloc type %d to section %s\n"), | |
14244 | reloc_type, printable_section_name (filedata, section)); | |
14245 | prev_reloc = reloc_type; | |
14246 | continue; | |
14247 | } | |
14248 | ||
14249 | rloc = start + rp->r_offset; | |
14250 | if (!IN_RANGE (start, end, rloc, reloc_size)) | |
14251 | { | |
14252 | warn (_("skipping invalid relocation offset 0x%lx in section %s\n"), | |
14253 | (unsigned long) rp->r_offset, | |
14254 | printable_section_name (filedata, section)); | |
14255 | continue; | |
14256 | } | |
14257 | ||
14258 | sym_index = (unsigned long) get_reloc_symindex (rp->r_info); | |
14259 | if (sym_index >= num_syms) | |
14260 | { | |
14261 | warn (_("skipping invalid relocation symbol index 0x%lx in section %s\n"), | |
14262 | sym_index, printable_section_name (filedata, section)); | |
14263 | continue; | |
14264 | } | |
14265 | sym = symtab + sym_index; | |
14266 | ||
14267 | /* If the reloc has a symbol associated with it, | |
14268 | make sure that it is of an appropriate type. | |
14269 | ||
14270 | Relocations against symbols without type can happen. | |
14271 | Gcc -feliminate-dwarf2-dups may generate symbols | |
14272 | without type for debug info. | |
14273 | ||
14274 | Icc generates relocations against function symbols | |
14275 | instead of local labels. | |
14276 | ||
14277 | Relocations against object symbols can happen, eg when | |
14278 | referencing a global array. For an example of this see | |
14279 | the _clz.o binary in libgcc.a. */ | |
14280 | if (sym != symtab | |
14281 | && ELF_ST_TYPE (sym->st_info) != STT_COMMON | |
14282 | && ELF_ST_TYPE (sym->st_info) > STT_SECTION) | |
14283 | { | |
14284 | warn (_("skipping unexpected symbol type %s in section %s relocation %ld\n"), | |
14285 | get_symbol_type (filedata, ELF_ST_TYPE (sym->st_info)), | |
14286 | printable_section_name (filedata, relsec), | |
14287 | (long int)(rp - relocs)); | |
14288 | continue; | |
14289 | } | |
14290 | ||
14291 | addend = 0; | |
14292 | if (is_rela) | |
14293 | addend += rp->r_addend; | |
14294 | /* R_XTENSA_32, R_PJ_DATA_DIR32 and R_D30V_32_NORMAL are | |
14295 | partial_inplace. */ | |
14296 | if (!is_rela | |
14297 | || (filedata->file_header.e_machine == EM_XTENSA | |
14298 | && reloc_type == 1) | |
14299 | || ((filedata->file_header.e_machine == EM_PJ | |
14300 | || filedata->file_header.e_machine == EM_PJ_OLD) | |
14301 | && reloc_type == 1) | |
14302 | || ((filedata->file_header.e_machine == EM_D30V | |
14303 | || filedata->file_header.e_machine == EM_CYGNUS_D30V) | |
14304 | && reloc_type == 12) | |
14305 | || reloc_inplace) | |
14306 | { | |
14307 | if (is_6bit_inplace_sub_reloc (filedata, reloc_type)) | |
14308 | addend += byte_get (rloc, reloc_size) & 0x3f; | |
14309 | else | |
14310 | addend += byte_get (rloc, reloc_size); | |
14311 | } | |
14312 | ||
14313 | if (is_32bit_pcrel_reloc (filedata, reloc_type) | |
14314 | || is_64bit_pcrel_reloc (filedata, reloc_type)) | |
14315 | { | |
14316 | /* On HPPA, all pc-relative relocations are biased by 8. */ | |
14317 | if (filedata->file_header.e_machine == EM_PARISC) | |
14318 | addend -= 8; | |
14319 | byte_put (rloc, (addend + sym->st_value) - rp->r_offset, | |
14320 | reloc_size); | |
14321 | } | |
14322 | else if (is_6bit_abs_reloc (filedata, reloc_type) | |
14323 | || is_6bit_inplace_sub_reloc (filedata, reloc_type)) | |
14324 | { | |
14325 | if (reloc_subtract) | |
14326 | addend -= sym->st_value; | |
14327 | else | |
14328 | addend += sym->st_value; | |
14329 | addend = (addend & 0x3f) | (byte_get (rloc, reloc_size) & 0xc0); | |
14330 | byte_put (rloc, addend, reloc_size); | |
14331 | } | |
14332 | else if (reloc_subtract) | |
14333 | byte_put (rloc, addend - sym->st_value, reloc_size); | |
14334 | else | |
14335 | byte_put (rloc, addend + sym->st_value, reloc_size); | |
14336 | } | |
14337 | ||
14338 | free (symtab); | |
14339 | /* Let the target specific reloc processing code know that | |
14340 | we have finished with these relocs. */ | |
14341 | target_specific_reloc_handling (filedata, NULL, NULL, NULL, NULL, 0); | |
14342 | ||
14343 | if (relocs_return) | |
14344 | { | |
14345 | * (Elf_Internal_Rela **) relocs_return = relocs; | |
14346 | * num_relocs_return = num_relocs; | |
14347 | } | |
14348 | else | |
14349 | free (relocs); | |
14350 | ||
14351 | break; | |
14352 | } | |
14353 | ||
14354 | return TRUE; | |
14355 | } | |
14356 | ||
14357 | #ifdef SUPPORT_DISASSEMBLY | |
14358 | static bfd_boolean | |
14359 | disassemble_section (Elf_Internal_Shdr * section, Filedata * filedata) | |
14360 | { | |
14361 | printf (_("\nAssembly dump of section %s\n"), printable_section_name (filedata, section)); | |
14362 | ||
14363 | /* FIXME: XXX -- to be done --- XXX */ | |
14364 | ||
14365 | return TRUE; | |
14366 | } | |
14367 | #endif | |
14368 | ||
14369 | /* Reads in the contents of SECTION from FILE, returning a pointer | |
14370 | to a malloc'ed buffer or NULL if something went wrong. */ | |
14371 | ||
14372 | static char * | |
14373 | get_section_contents (Elf_Internal_Shdr * section, Filedata * filedata) | |
14374 | { | |
14375 | bfd_size_type num_bytes = section->sh_size; | |
14376 | ||
14377 | if (num_bytes == 0 || section->sh_type == SHT_NOBITS) | |
14378 | { | |
14379 | printf (_("Section '%s' has no data to dump.\n"), | |
14380 | printable_section_name (filedata, section)); | |
14381 | return NULL; | |
14382 | } | |
14383 | ||
14384 | return (char *) get_data (NULL, filedata, section->sh_offset, 1, num_bytes, | |
14385 | _("section contents")); | |
14386 | } | |
14387 | ||
14388 | /* Uncompresses a section that was compressed using zlib, in place. */ | |
14389 | ||
14390 | static bfd_boolean | |
14391 | uncompress_section_contents (unsigned char ** buffer, | |
14392 | dwarf_size_type uncompressed_size, | |
14393 | dwarf_size_type * size) | |
14394 | { | |
14395 | dwarf_size_type compressed_size = *size; | |
14396 | unsigned char * compressed_buffer = *buffer; | |
14397 | unsigned char * uncompressed_buffer; | |
14398 | z_stream strm; | |
14399 | int rc; | |
14400 | ||
14401 | /* It is possible the section consists of several compressed | |
14402 | buffers concatenated together, so we uncompress in a loop. */ | |
14403 | /* PR 18313: The state field in the z_stream structure is supposed | |
14404 | to be invisible to the user (ie us), but some compilers will | |
14405 | still complain about it being used without initialisation. So | |
14406 | we first zero the entire z_stream structure and then set the fields | |
14407 | that we need. */ | |
14408 | memset (& strm, 0, sizeof strm); | |
14409 | strm.avail_in = compressed_size; | |
14410 | strm.next_in = (Bytef *) compressed_buffer; | |
14411 | strm.avail_out = uncompressed_size; | |
14412 | uncompressed_buffer = (unsigned char *) xmalloc (uncompressed_size); | |
14413 | ||
14414 | rc = inflateInit (& strm); | |
14415 | while (strm.avail_in > 0) | |
14416 | { | |
14417 | if (rc != Z_OK) | |
14418 | break; | |
14419 | strm.next_out = ((Bytef *) uncompressed_buffer | |
14420 | + (uncompressed_size - strm.avail_out)); | |
14421 | rc = inflate (&strm, Z_FINISH); | |
14422 | if (rc != Z_STREAM_END) | |
14423 | break; | |
14424 | rc = inflateReset (& strm); | |
14425 | } | |
14426 | if (inflateEnd (& strm) != Z_OK | |
14427 | || rc != Z_OK | |
14428 | || strm.avail_out != 0) | |
14429 | goto fail; | |
14430 | ||
14431 | *buffer = uncompressed_buffer; | |
14432 | *size = uncompressed_size; | |
14433 | return TRUE; | |
14434 | ||
14435 | fail: | |
14436 | free (uncompressed_buffer); | |
14437 | /* Indicate decompression failure. */ | |
14438 | *buffer = NULL; | |
14439 | return FALSE; | |
14440 | } | |
14441 | ||
14442 | static bfd_boolean | |
14443 | dump_section_as_strings (Elf_Internal_Shdr * section, Filedata * filedata) | |
14444 | { | |
14445 | Elf_Internal_Shdr * relsec; | |
14446 | bfd_size_type num_bytes; | |
14447 | unsigned char * data; | |
14448 | unsigned char * end; | |
14449 | unsigned char * real_start; | |
14450 | unsigned char * start; | |
14451 | bfd_boolean some_strings_shown; | |
14452 | ||
14453 | real_start = start = (unsigned char *) get_section_contents (section, filedata); | |
14454 | if (start == NULL) | |
14455 | /* PR 21820: Do not fail if the section was empty. */ | |
14456 | return (section->sh_size == 0 || section->sh_type == SHT_NOBITS) ? TRUE : FALSE; | |
14457 | ||
14458 | num_bytes = section->sh_size; | |
14459 | ||
14460 | printf (_("\nString dump of section '%s':\n"), printable_section_name (filedata, section)); | |
14461 | ||
14462 | if (decompress_dumps) | |
14463 | { | |
14464 | dwarf_size_type new_size = num_bytes; | |
14465 | dwarf_size_type uncompressed_size = 0; | |
14466 | ||
14467 | if ((section->sh_flags & SHF_COMPRESSED) != 0) | |
14468 | { | |
14469 | Elf_Internal_Chdr chdr; | |
14470 | unsigned int compression_header_size | |
14471 | = get_compression_header (& chdr, (unsigned char *) start, | |
14472 | num_bytes); | |
14473 | if (compression_header_size == 0) | |
14474 | /* An error message will have already been generated | |
14475 | by get_compression_header. */ | |
14476 | goto error_out; | |
14477 | ||
14478 | if (chdr.ch_type != ELFCOMPRESS_ZLIB) | |
14479 | { | |
14480 | warn (_("section '%s' has unsupported compress type: %d\n"), | |
14481 | printable_section_name (filedata, section), chdr.ch_type); | |
14482 | goto error_out; | |
14483 | } | |
14484 | uncompressed_size = chdr.ch_size; | |
14485 | start += compression_header_size; | |
14486 | new_size -= compression_header_size; | |
14487 | } | |
14488 | else if (new_size > 12 && streq ((char *) start, "ZLIB")) | |
14489 | { | |
14490 | /* Read the zlib header. In this case, it should be "ZLIB" | |
14491 | followed by the uncompressed section size, 8 bytes in | |
14492 | big-endian order. */ | |
14493 | uncompressed_size = start[4]; uncompressed_size <<= 8; | |
14494 | uncompressed_size += start[5]; uncompressed_size <<= 8; | |
14495 | uncompressed_size += start[6]; uncompressed_size <<= 8; | |
14496 | uncompressed_size += start[7]; uncompressed_size <<= 8; | |
14497 | uncompressed_size += start[8]; uncompressed_size <<= 8; | |
14498 | uncompressed_size += start[9]; uncompressed_size <<= 8; | |
14499 | uncompressed_size += start[10]; uncompressed_size <<= 8; | |
14500 | uncompressed_size += start[11]; | |
14501 | start += 12; | |
14502 | new_size -= 12; | |
14503 | } | |
14504 | ||
14505 | if (uncompressed_size) | |
14506 | { | |
14507 | if (uncompress_section_contents (& start, | |
14508 | uncompressed_size, & new_size)) | |
14509 | num_bytes = new_size; | |
14510 | else | |
14511 | { | |
14512 | error (_("Unable to decompress section %s\n"), | |
14513 | printable_section_name (filedata, section)); | |
14514 | goto error_out; | |
14515 | } | |
14516 | } | |
14517 | else | |
14518 | start = real_start; | |
14519 | } | |
14520 | ||
14521 | /* If the section being dumped has relocations against it the user might | |
14522 | be expecting these relocations to have been applied. Check for this | |
14523 | case and issue a warning message in order to avoid confusion. | |
14524 | FIXME: Maybe we ought to have an option that dumps a section with | |
14525 | relocs applied ? */ | |
14526 | for (relsec = filedata->section_headers; | |
14527 | relsec < filedata->section_headers + filedata->file_header.e_shnum; | |
14528 | ++relsec) | |
14529 | { | |
14530 | if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL) | |
14531 | || relsec->sh_info >= filedata->file_header.e_shnum | |
14532 | || filedata->section_headers + relsec->sh_info != section | |
14533 | || relsec->sh_size == 0 | |
14534 | || relsec->sh_link >= filedata->file_header.e_shnum) | |
14535 | continue; | |
14536 | ||
14537 | printf (_(" Note: This section has relocations against it, but these have NOT been applied to this dump.\n")); | |
14538 | break; | |
14539 | } | |
14540 | ||
14541 | data = start; | |
14542 | end = start + num_bytes; | |
14543 | some_strings_shown = FALSE; | |
14544 | ||
14545 | #ifdef HAVE_MBSTATE_T | |
14546 | mbstate_t state; | |
14547 | /* Initialise the multibyte conversion state. */ | |
14548 | memset (& state, 0, sizeof (state)); | |
14549 | #endif | |
14550 | ||
14551 | bfd_boolean continuing = FALSE; | |
14552 | ||
14553 | while (data < end) | |
14554 | { | |
14555 | while (!ISPRINT (* data)) | |
14556 | if (++ data >= end) | |
14557 | break; | |
14558 | ||
14559 | if (data < end) | |
14560 | { | |
14561 | size_t maxlen = end - data; | |
14562 | ||
14563 | if (continuing) | |
14564 | { | |
14565 | printf (" "); | |
14566 | continuing = FALSE; | |
14567 | } | |
14568 | else | |
14569 | { | |
14570 | printf (" [%6lx] ", (unsigned long) (data - start)); | |
14571 | } | |
14572 | ||
14573 | if (maxlen > 0) | |
14574 | { | |
14575 | char c = 0; | |
14576 | ||
14577 | while (maxlen) | |
14578 | { | |
14579 | c = *data++; | |
14580 | ||
14581 | if (c == 0) | |
14582 | break; | |
14583 | ||
14584 | /* PR 25543: Treat new-lines as string-ending characters. */ | |
14585 | if (c == '\n') | |
14586 | { | |
14587 | printf ("\\n\n"); | |
14588 | if (*data != 0) | |
14589 | continuing = TRUE; | |
14590 | break; | |
14591 | } | |
14592 | ||
14593 | /* Do not print control characters directly as they can affect terminal | |
14594 | settings. Such characters usually appear in the names generated | |
14595 | by the assembler for local labels. */ | |
14596 | if (ISCNTRL (c)) | |
14597 | { | |
14598 | printf ("^%c", c + 0x40); | |
14599 | } | |
14600 | else if (ISPRINT (c)) | |
14601 | { | |
14602 | putchar (c); | |
14603 | } | |
14604 | else | |
14605 | { | |
14606 | size_t n; | |
14607 | #ifdef HAVE_MBSTATE_T | |
14608 | wchar_t w; | |
14609 | #endif | |
14610 | /* Let printf do the hard work of displaying multibyte characters. */ | |
14611 | printf ("%.1s", data - 1); | |
14612 | #ifdef HAVE_MBSTATE_T | |
14613 | /* Try to find out how many bytes made up the character that was | |
14614 | just printed. Advance the symbol pointer past the bytes that | |
14615 | were displayed. */ | |
14616 | n = mbrtowc (& w, (char *)(data - 1), MB_CUR_MAX, & state); | |
14617 | #else | |
14618 | n = 1; | |
14619 | #endif | |
14620 | if (n != (size_t) -1 && n != (size_t) -2 && n > 0) | |
14621 | data += (n - 1); | |
14622 | } | |
14623 | } | |
14624 | ||
14625 | if (c != '\n') | |
14626 | putchar ('\n'); | |
14627 | } | |
14628 | else | |
14629 | { | |
14630 | printf (_("<corrupt>\n")); | |
14631 | data = end; | |
14632 | } | |
14633 | some_strings_shown = TRUE; | |
14634 | } | |
14635 | } | |
14636 | ||
14637 | if (! some_strings_shown) | |
14638 | printf (_(" No strings found in this section.")); | |
14639 | ||
14640 | free (real_start); | |
14641 | ||
14642 | putchar ('\n'); | |
14643 | return TRUE; | |
14644 | ||
14645 | error_out: | |
14646 | free (real_start); | |
14647 | return FALSE; | |
14648 | } | |
14649 | ||
14650 | static bfd_boolean | |
14651 | dump_section_as_bytes (Elf_Internal_Shdr * section, | |
14652 | Filedata * filedata, | |
14653 | bfd_boolean relocate) | |
14654 | { | |
14655 | Elf_Internal_Shdr * relsec; | |
14656 | bfd_size_type bytes; | |
14657 | bfd_size_type section_size; | |
14658 | bfd_vma addr; | |
14659 | unsigned char * data; | |
14660 | unsigned char * real_start; | |
14661 | unsigned char * start; | |
14662 | ||
14663 | real_start = start = (unsigned char *) get_section_contents (section, filedata); | |
14664 | if (start == NULL) | |
14665 | /* PR 21820: Do not fail if the section was empty. */ | |
14666 | return (section->sh_size == 0 || section->sh_type == SHT_NOBITS) ? TRUE : FALSE; | |
14667 | ||
14668 | section_size = section->sh_size; | |
14669 | ||
14670 | printf (_("\nHex dump of section '%s':\n"), printable_section_name (filedata, section)); | |
14671 | ||
14672 | if (decompress_dumps) | |
14673 | { | |
14674 | dwarf_size_type new_size = section_size; | |
14675 | dwarf_size_type uncompressed_size = 0; | |
14676 | ||
14677 | if ((section->sh_flags & SHF_COMPRESSED) != 0) | |
14678 | { | |
14679 | Elf_Internal_Chdr chdr; | |
14680 | unsigned int compression_header_size | |
14681 | = get_compression_header (& chdr, start, section_size); | |
14682 | ||
14683 | if (compression_header_size == 0) | |
14684 | /* An error message will have already been generated | |
14685 | by get_compression_header. */ | |
14686 | goto error_out; | |
14687 | ||
14688 | if (chdr.ch_type != ELFCOMPRESS_ZLIB) | |
14689 | { | |
14690 | warn (_("section '%s' has unsupported compress type: %d\n"), | |
14691 | printable_section_name (filedata, section), chdr.ch_type); | |
14692 | goto error_out; | |
14693 | } | |
14694 | uncompressed_size = chdr.ch_size; | |
14695 | start += compression_header_size; | |
14696 | new_size -= compression_header_size; | |
14697 | } | |
14698 | else if (new_size > 12 && streq ((char *) start, "ZLIB")) | |
14699 | { | |
14700 | /* Read the zlib header. In this case, it should be "ZLIB" | |
14701 | followed by the uncompressed section size, 8 bytes in | |
14702 | big-endian order. */ | |
14703 | uncompressed_size = start[4]; uncompressed_size <<= 8; | |
14704 | uncompressed_size += start[5]; uncompressed_size <<= 8; | |
14705 | uncompressed_size += start[6]; uncompressed_size <<= 8; | |
14706 | uncompressed_size += start[7]; uncompressed_size <<= 8; | |
14707 | uncompressed_size += start[8]; uncompressed_size <<= 8; | |
14708 | uncompressed_size += start[9]; uncompressed_size <<= 8; | |
14709 | uncompressed_size += start[10]; uncompressed_size <<= 8; | |
14710 | uncompressed_size += start[11]; | |
14711 | start += 12; | |
14712 | new_size -= 12; | |
14713 | } | |
14714 | ||
14715 | if (uncompressed_size) | |
14716 | { | |
14717 | if (uncompress_section_contents (& start, uncompressed_size, | |
14718 | & new_size)) | |
14719 | { | |
14720 | section_size = new_size; | |
14721 | } | |
14722 | else | |
14723 | { | |
14724 | error (_("Unable to decompress section %s\n"), | |
14725 | printable_section_name (filedata, section)); | |
14726 | /* FIXME: Print the section anyway ? */ | |
14727 | goto error_out; | |
14728 | } | |
14729 | } | |
14730 | else | |
14731 | start = real_start; | |
14732 | } | |
14733 | ||
14734 | if (relocate) | |
14735 | { | |
14736 | if (! apply_relocations (filedata, section, start, section_size, NULL, NULL)) | |
14737 | goto error_out; | |
14738 | } | |
14739 | else | |
14740 | { | |
14741 | /* If the section being dumped has relocations against it the user might | |
14742 | be expecting these relocations to have been applied. Check for this | |
14743 | case and issue a warning message in order to avoid confusion. | |
14744 | FIXME: Maybe we ought to have an option that dumps a section with | |
14745 | relocs applied ? */ | |
14746 | for (relsec = filedata->section_headers; | |
14747 | relsec < filedata->section_headers + filedata->file_header.e_shnum; | |
14748 | ++relsec) | |
14749 | { | |
14750 | if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL) | |
14751 | || relsec->sh_info >= filedata->file_header.e_shnum | |
14752 | || filedata->section_headers + relsec->sh_info != section | |
14753 | || relsec->sh_size == 0 | |
14754 | || relsec->sh_link >= filedata->file_header.e_shnum) | |
14755 | continue; | |
14756 | ||
14757 | printf (_(" NOTE: This section has relocations against it, but these have NOT been applied to this dump.\n")); | |
14758 | break; | |
14759 | } | |
14760 | } | |
14761 | ||
14762 | addr = section->sh_addr; | |
14763 | bytes = section_size; | |
14764 | data = start; | |
14765 | ||
14766 | while (bytes) | |
14767 | { | |
14768 | int j; | |
14769 | int k; | |
14770 | int lbytes; | |
14771 | ||
14772 | lbytes = (bytes > 16 ? 16 : bytes); | |
14773 | ||
14774 | printf (" 0x%8.8lx ", (unsigned long) addr); | |
14775 | ||
14776 | for (j = 0; j < 16; j++) | |
14777 | { | |
14778 | if (j < lbytes) | |
14779 | printf ("%2.2x", data[j]); | |
14780 | else | |
14781 | printf (" "); | |
14782 | ||
14783 | if ((j & 3) == 3) | |
14784 | printf (" "); | |
14785 | } | |
14786 | ||
14787 | for (j = 0; j < lbytes; j++) | |
14788 | { | |
14789 | k = data[j]; | |
14790 | if (k >= ' ' && k < 0x7f) | |
14791 | printf ("%c", k); | |
14792 | else | |
14793 | printf ("."); | |
14794 | } | |
14795 | ||
14796 | putchar ('\n'); | |
14797 | ||
14798 | data += lbytes; | |
14799 | addr += lbytes; | |
14800 | bytes -= lbytes; | |
14801 | } | |
14802 | ||
14803 | free (real_start); | |
14804 | ||
14805 | putchar ('\n'); | |
14806 | return TRUE; | |
14807 | ||
14808 | error_out: | |
14809 | free (real_start); | |
14810 | return FALSE; | |
14811 | } | |
14812 | ||
14813 | #ifdef ENABLE_LIBCTF | |
14814 | static ctf_sect_t * | |
14815 | shdr_to_ctf_sect (ctf_sect_t *buf, Elf_Internal_Shdr *shdr, Filedata *filedata) | |
14816 | { | |
14817 | buf->cts_name = SECTION_NAME_PRINT (shdr); | |
14818 | buf->cts_size = shdr->sh_size; | |
14819 | buf->cts_entsize = shdr->sh_entsize; | |
14820 | ||
14821 | return buf; | |
14822 | } | |
14823 | ||
14824 | /* Formatting callback function passed to ctf_dump. Returns either the pointer | |
14825 | it is passed, or a pointer to newly-allocated storage, in which case | |
14826 | dump_ctf() will free it when it no longer needs it. */ | |
14827 | ||
14828 | static char * | |
14829 | dump_ctf_indent_lines (ctf_sect_names_t sect ATTRIBUTE_UNUSED, | |
14830 | char *s, void *arg) | |
14831 | { | |
14832 | const char *blanks = arg; | |
14833 | char *new_s; | |
14834 | ||
14835 | if (asprintf (&new_s, "%s%s", blanks, s) < 0) | |
14836 | return s; | |
14837 | return new_s; | |
14838 | } | |
14839 | ||
14840 | /* Dump CTF errors/warnings. */ | |
14841 | static void | |
14842 | dump_ctf_errs (ctf_dict_t *fp) | |
14843 | { | |
14844 | ctf_next_t *it = NULL; | |
14845 | char *errtext; | |
14846 | int is_warning; | |
14847 | int err; | |
14848 | ||
14849 | /* Dump accumulated errors and warnings. */ | |
14850 | while ((errtext = ctf_errwarning_next (fp, &it, &is_warning, &err)) != NULL) | |
14851 | { | |
14852 | error (_("%s: %s"), is_warning ? _("warning"): _("error"), | |
14853 | errtext); | |
14854 | free (errtext); | |
14855 | } | |
14856 | if (err != ECTF_NEXT_END) | |
14857 | error (_("CTF error: cannot get CTF errors: `%s'"), ctf_errmsg (err)); | |
14858 | } | |
14859 | ||
14860 | /* Dump one CTF archive member. */ | |
14861 | ||
14862 | static int | |
14863 | dump_ctf_archive_member (ctf_dict_t *ctf, const char *name, void *arg) | |
14864 | { | |
14865 | ctf_dict_t *parent = (ctf_dict_t *) arg; | |
14866 | const char *things[] = {"Header", "Labels", "Data objects", | |
14867 | "Function objects", "Variables", "Types", "Strings", | |
14868 | ""}; | |
14869 | const char **thing; | |
14870 | size_t i; | |
14871 | int err = 0; | |
14872 | ||
14873 | /* Only print out the name of non-default-named archive members. | |
14874 | The name .ctf appears everywhere, even for things that aren't | |
14875 | really archives, so printing it out is liable to be confusing. | |
14876 | ||
14877 | The parent, if there is one, is the default-owned archive member: | |
14878 | avoid importing it into itself. (This does no harm, but looks | |
14879 | confusing.) */ | |
14880 | ||
14881 | if (strcmp (name, ".ctf") != 0) | |
14882 | { | |
14883 | printf (_("\nCTF archive member: %s:\n"), name); | |
14884 | ctf_import (ctf, parent); | |
14885 | } | |
14886 | ||
14887 | for (i = 0, thing = things; *thing[0]; thing++, i++) | |
14888 | { | |
14889 | ctf_dump_state_t *s = NULL; | |
14890 | char *item; | |
14891 | ||
14892 | printf ("\n %s:\n", *thing); | |
14893 | while ((item = ctf_dump (ctf, &s, i, dump_ctf_indent_lines, | |
14894 | (void *) " ")) != NULL) | |
14895 | { | |
14896 | printf ("%s\n", item); | |
14897 | free (item); | |
14898 | } | |
14899 | ||
14900 | if (ctf_errno (ctf)) | |
14901 | { | |
14902 | error (_("Iteration failed: %s, %s\n"), *thing, | |
14903 | ctf_errmsg (ctf_errno (ctf))); | |
14904 | err = 1; | |
14905 | goto out; | |
14906 | } | |
14907 | } | |
14908 | ||
14909 | out: | |
14910 | dump_ctf_errs (ctf); | |
14911 | return err; | |
14912 | } | |
14913 | ||
14914 | static bfd_boolean | |
14915 | dump_section_as_ctf (Elf_Internal_Shdr * section, Filedata * filedata) | |
14916 | { | |
14917 | Elf_Internal_Shdr * parent_sec = NULL; | |
14918 | Elf_Internal_Shdr * symtab_sec = NULL; | |
14919 | Elf_Internal_Shdr * strtab_sec = NULL; | |
14920 | void * data = NULL; | |
14921 | void * symdata = NULL; | |
14922 | void * strdata = NULL; | |
14923 | void * parentdata = NULL; | |
14924 | ctf_sect_t ctfsect, symsect, strsect, parentsect; | |
14925 | ctf_sect_t * symsectp = NULL; | |
14926 | ctf_sect_t * strsectp = NULL; | |
14927 | ctf_archive_t * ctfa = NULL; | |
14928 | ctf_archive_t * parenta = NULL, *lookparent; | |
14929 | ctf_dict_t * parent = NULL; | |
14930 | ||
14931 | int err; | |
14932 | bfd_boolean ret = FALSE; | |
14933 | ||
14934 | shdr_to_ctf_sect (&ctfsect, section, filedata); | |
14935 | data = get_section_contents (section, filedata); | |
14936 | ctfsect.cts_data = data; | |
14937 | ||
14938 | if (!dump_ctf_symtab_name) | |
14939 | dump_ctf_symtab_name = strdup (".dynsym"); | |
14940 | ||
14941 | if (!dump_ctf_strtab_name) | |
14942 | dump_ctf_strtab_name = strdup (".dynstr"); | |
14943 | ||
14944 | if (dump_ctf_symtab_name && dump_ctf_symtab_name[0] != 0) | |
14945 | { | |
14946 | if ((symtab_sec = find_section (filedata, dump_ctf_symtab_name)) == NULL) | |
14947 | { | |
14948 | error (_("No symbol section named %s\n"), dump_ctf_symtab_name); | |
14949 | goto fail; | |
14950 | } | |
14951 | if ((symdata = (void *) get_data (NULL, filedata, | |
14952 | symtab_sec->sh_offset, 1, | |
14953 | symtab_sec->sh_size, | |
14954 | _("symbols"))) == NULL) | |
14955 | goto fail; | |
14956 | symsectp = shdr_to_ctf_sect (&symsect, symtab_sec, filedata); | |
14957 | symsect.cts_data = symdata; | |
14958 | } | |
14959 | if (dump_ctf_strtab_name && dump_ctf_strtab_name[0] != 0) | |
14960 | { | |
14961 | if ((strtab_sec = find_section (filedata, dump_ctf_strtab_name)) == NULL) | |
14962 | { | |
14963 | error (_("No string table section named %s\n"), | |
14964 | dump_ctf_strtab_name); | |
14965 | goto fail; | |
14966 | } | |
14967 | if ((strdata = (void *) get_data (NULL, filedata, | |
14968 | strtab_sec->sh_offset, 1, | |
14969 | strtab_sec->sh_size, | |
14970 | _("strings"))) == NULL) | |
14971 | goto fail; | |
14972 | strsectp = shdr_to_ctf_sect (&strsect, strtab_sec, filedata); | |
14973 | strsect.cts_data = strdata; | |
14974 | } | |
14975 | if (dump_ctf_parent_name) | |
14976 | { | |
14977 | if ((parent_sec = find_section (filedata, dump_ctf_parent_name)) == NULL) | |
14978 | { | |
14979 | error (_("No CTF parent section named %s\n"), dump_ctf_parent_name); | |
14980 | goto fail; | |
14981 | } | |
14982 | if ((parentdata = (void *) get_data (NULL, filedata, | |
14983 | parent_sec->sh_offset, 1, | |
14984 | parent_sec->sh_size, | |
14985 | _("CTF parent"))) == NULL) | |
14986 | goto fail; | |
14987 | shdr_to_ctf_sect (&parentsect, parent_sec, filedata); | |
14988 | parentsect.cts_data = parentdata; | |
14989 | } | |
14990 | ||
14991 | /* Load the CTF file and dump it. It may be a raw CTF section, or an archive: | |
14992 | libctf papers over the difference, so we can pretend it is always an | |
14993 | archive. Possibly open the parent as well, if one was specified. */ | |
14994 | ||
14995 | if ((ctfa = ctf_arc_bufopen (&ctfsect, symsectp, strsectp, &err)) == NULL) | |
14996 | { | |
14997 | dump_ctf_errs (NULL); | |
14998 | error (_("CTF open failure: %s\n"), ctf_errmsg (err)); | |
14999 | goto fail; | |
15000 | } | |
15001 | ||
15002 | ctf_arc_symsect_endianness (ctfa, filedata->file_header.e_ident[EI_DATA] | |
15003 | != ELFDATA2MSB); | |
15004 | ||
15005 | if (parentdata) | |
15006 | { | |
15007 | if ((parenta = ctf_arc_bufopen (&parentsect, symsectp, strsectp, | |
15008 | &err)) == NULL) | |
15009 | { | |
15010 | dump_ctf_errs (NULL); | |
15011 | error (_("CTF open failure: %s\n"), ctf_errmsg (err)); | |
15012 | goto fail; | |
15013 | } | |
15014 | lookparent = parenta; | |
15015 | } | |
15016 | else | |
15017 | lookparent = ctfa; | |
15018 | ||
15019 | /* Assume that the applicable parent archive member is the default one. | |
15020 | (This is what all known implementations are expected to do, if they | |
15021 | put CTFs and their parents in archives together.) */ | |
15022 | if ((parent = ctf_dict_open (lookparent, NULL, &err)) == NULL) | |
15023 | { | |
15024 | dump_ctf_errs (NULL); | |
15025 | error (_("CTF open failure: %s\n"), ctf_errmsg (err)); | |
15026 | goto fail; | |
15027 | } | |
15028 | ||
15029 | ret = TRUE; | |
15030 | ||
15031 | printf (_("\nDump of CTF section '%s':\n"), | |
15032 | printable_section_name (filedata, section)); | |
15033 | ||
15034 | if ((err = ctf_archive_iter (ctfa, dump_ctf_archive_member, parent)) != 0) | |
15035 | { | |
15036 | dump_ctf_errs (NULL); | |
15037 | error (_("CTF member open failure: %s\n"), ctf_errmsg (err)); | |
15038 | ret = FALSE; | |
15039 | } | |
15040 | ||
15041 | fail: | |
15042 | ctf_dict_close (parent); | |
15043 | ctf_close (ctfa); | |
15044 | ctf_close (parenta); | |
15045 | free (parentdata); | |
15046 | free (data); | |
15047 | free (symdata); | |
15048 | free (strdata); | |
15049 | return ret; | |
15050 | } | |
15051 | #endif | |
15052 | ||
15053 | static bfd_boolean | |
15054 | load_specific_debug_section (enum dwarf_section_display_enum debug, | |
15055 | const Elf_Internal_Shdr * sec, | |
15056 | void * data) | |
15057 | { | |
15058 | struct dwarf_section * section = &debug_displays [debug].section; | |
15059 | char buf [64]; | |
15060 | Filedata * filedata = (Filedata *) data; | |
15061 | ||
15062 | if (section->start != NULL) | |
15063 | { | |
15064 | /* If it is already loaded, do nothing. */ | |
15065 | if (streq (section->filename, filedata->file_name)) | |
15066 | return TRUE; | |
15067 | free (section->start); | |
15068 | } | |
15069 | ||
15070 | snprintf (buf, sizeof (buf), _("%s section data"), section->name); | |
15071 | section->address = sec->sh_addr; | |
15072 | section->filename = filedata->file_name; | |
15073 | section->start = (unsigned char *) get_data (NULL, filedata, | |
15074 | sec->sh_offset, 1, | |
15075 | sec->sh_size, buf); | |
15076 | if (section->start == NULL) | |
15077 | section->size = 0; | |
15078 | else | |
15079 | { | |
15080 | unsigned char *start = section->start; | |
15081 | dwarf_size_type size = sec->sh_size; | |
15082 | dwarf_size_type uncompressed_size = 0; | |
15083 | ||
15084 | if ((sec->sh_flags & SHF_COMPRESSED) != 0) | |
15085 | { | |
15086 | Elf_Internal_Chdr chdr; | |
15087 | unsigned int compression_header_size; | |
15088 | ||
15089 | if (size < (is_32bit_elf | |
15090 | ? sizeof (Elf32_External_Chdr) | |
15091 | : sizeof (Elf64_External_Chdr))) | |
15092 | { | |
15093 | warn (_("compressed section %s is too small to contain a compression header\n"), | |
15094 | section->name); | |
15095 | return FALSE; | |
15096 | } | |
15097 | ||
15098 | compression_header_size = get_compression_header (&chdr, start, size); | |
15099 | if (compression_header_size == 0) | |
15100 | /* An error message will have already been generated | |
15101 | by get_compression_header. */ | |
15102 | return FALSE; | |
15103 | ||
15104 | if (chdr.ch_type != ELFCOMPRESS_ZLIB) | |
15105 | { | |
15106 | warn (_("section '%s' has unsupported compress type: %d\n"), | |
15107 | section->name, chdr.ch_type); | |
15108 | return FALSE; | |
15109 | } | |
15110 | uncompressed_size = chdr.ch_size; | |
15111 | start += compression_header_size; | |
15112 | size -= compression_header_size; | |
15113 | } | |
15114 | else if (size > 12 && streq ((char *) start, "ZLIB")) | |
15115 | { | |
15116 | /* Read the zlib header. In this case, it should be "ZLIB" | |
15117 | followed by the uncompressed section size, 8 bytes in | |
15118 | big-endian order. */ | |
15119 | uncompressed_size = start[4]; uncompressed_size <<= 8; | |
15120 | uncompressed_size += start[5]; uncompressed_size <<= 8; | |
15121 | uncompressed_size += start[6]; uncompressed_size <<= 8; | |
15122 | uncompressed_size += start[7]; uncompressed_size <<= 8; | |
15123 | uncompressed_size += start[8]; uncompressed_size <<= 8; | |
15124 | uncompressed_size += start[9]; uncompressed_size <<= 8; | |
15125 | uncompressed_size += start[10]; uncompressed_size <<= 8; | |
15126 | uncompressed_size += start[11]; | |
15127 | start += 12; | |
15128 | size -= 12; | |
15129 | } | |
15130 | ||
15131 | if (uncompressed_size) | |
15132 | { | |
15133 | if (uncompress_section_contents (&start, uncompressed_size, | |
15134 | &size)) | |
15135 | { | |
15136 | /* Free the compressed buffer, update the section buffer | |
15137 | and the section size if uncompress is successful. */ | |
15138 | free (section->start); | |
15139 | section->start = start; | |
15140 | } | |
15141 | else | |
15142 | { | |
15143 | error (_("Unable to decompress section %s\n"), | |
15144 | printable_section_name (filedata, sec)); | |
15145 | return FALSE; | |
15146 | } | |
15147 | } | |
15148 | ||
15149 | section->size = size; | |
15150 | } | |
15151 | ||
15152 | if (section->start == NULL) | |
15153 | return FALSE; | |
15154 | ||
15155 | if (debug_displays [debug].relocate) | |
15156 | { | |
15157 | if (! apply_relocations (filedata, sec, section->start, section->size, | |
15158 | & section->reloc_info, & section->num_relocs)) | |
15159 | return FALSE; | |
15160 | } | |
15161 | else | |
15162 | { | |
15163 | section->reloc_info = NULL; | |
15164 | section->num_relocs = 0; | |
15165 | } | |
15166 | ||
15167 | return TRUE; | |
15168 | } | |
15169 | ||
15170 | #if HAVE_LIBDEBUGINFOD | |
15171 | /* Return a hex string representation of the build-id. */ | |
15172 | unsigned char * | |
15173 | get_build_id (void * data) | |
15174 | { | |
15175 | Filedata * filedata = (Filedata *) data; | |
15176 | Elf_Internal_Shdr * shdr; | |
15177 | unsigned long i; | |
15178 | ||
15179 | /* Iterate through notes to find note.gnu.build-id. | |
15180 | FIXME: Only the first note in any note section is examined. */ | |
15181 | for (i = 0, shdr = filedata->section_headers; | |
15182 | i < filedata->file_header.e_shnum && shdr != NULL; | |
15183 | i++, shdr++) | |
15184 | { | |
15185 | if (shdr->sh_type != SHT_NOTE) | |
15186 | continue; | |
15187 | ||
15188 | char * next; | |
15189 | char * end; | |
15190 | size_t data_remaining; | |
15191 | size_t min_notesz; | |
15192 | Elf_External_Note * enote; | |
15193 | Elf_Internal_Note inote; | |
15194 | ||
15195 | bfd_vma offset = shdr->sh_offset; | |
15196 | bfd_vma align = shdr->sh_addralign; | |
15197 | bfd_vma length = shdr->sh_size; | |
15198 | ||
15199 | enote = (Elf_External_Note *) get_section_contents (shdr, filedata); | |
15200 | if (enote == NULL) | |
15201 | continue; | |
15202 | ||
15203 | if (align < 4) | |
15204 | align = 4; | |
15205 | else if (align != 4 && align != 8) | |
15206 | { | |
15207 | free (enote); | |
15208 | continue; | |
15209 | } | |
15210 | ||
15211 | end = (char *) enote + length; | |
15212 | data_remaining = end - (char *) enote; | |
15213 | ||
15214 | if (!is_ia64_vms (filedata)) | |
15215 | { | |
15216 | min_notesz = offsetof (Elf_External_Note, name); | |
15217 | if (data_remaining < min_notesz) | |
15218 | { | |
15219 | warn (_("\ | |
15220 | malformed note encountered in section %s whilst scanning for build-id note\n"), | |
15221 | printable_section_name (filedata, shdr)); | |
15222 | free (enote); | |
15223 | continue; | |
15224 | } | |
15225 | data_remaining -= min_notesz; | |
15226 | ||
15227 | inote.type = BYTE_GET (enote->type); | |
15228 | inote.namesz = BYTE_GET (enote->namesz); | |
15229 | inote.namedata = enote->name; | |
15230 | inote.descsz = BYTE_GET (enote->descsz); | |
15231 | inote.descdata = ((char *) enote | |
15232 | + ELF_NOTE_DESC_OFFSET (inote.namesz, align)); | |
15233 | inote.descpos = offset + (inote.descdata - (char *) enote); | |
15234 | next = ((char *) enote | |
15235 | + ELF_NOTE_NEXT_OFFSET (inote.namesz, inote.descsz, align)); | |
15236 | } | |
15237 | else | |
15238 | { | |
15239 | Elf64_External_VMS_Note *vms_enote; | |
15240 | ||
15241 | /* PR binutils/15191 | |
15242 | Make sure that there is enough data to read. */ | |
15243 | min_notesz = offsetof (Elf64_External_VMS_Note, name); | |
15244 | if (data_remaining < min_notesz) | |
15245 | { | |
15246 | warn (_("\ | |
15247 | malformed note encountered in section %s whilst scanning for build-id note\n"), | |
15248 | printable_section_name (filedata, shdr)); | |
15249 | free (enote); | |
15250 | continue; | |
15251 | } | |
15252 | data_remaining -= min_notesz; | |
15253 | ||
15254 | vms_enote = (Elf64_External_VMS_Note *) enote; | |
15255 | inote.type = BYTE_GET (vms_enote->type); | |
15256 | inote.namesz = BYTE_GET (vms_enote->namesz); | |
15257 | inote.namedata = vms_enote->name; | |
15258 | inote.descsz = BYTE_GET (vms_enote->descsz); | |
15259 | inote.descdata = inote.namedata + align_power (inote.namesz, 3); | |
15260 | inote.descpos = offset + (inote.descdata - (char *) enote); | |
15261 | next = inote.descdata + align_power (inote.descsz, 3); | |
15262 | } | |
15263 | ||
15264 | /* Skip malformed notes. */ | |
15265 | if ((size_t) (inote.descdata - inote.namedata) < inote.namesz | |
15266 | || (size_t) (inote.descdata - inote.namedata) > data_remaining | |
15267 | || (size_t) (next - inote.descdata) < inote.descsz | |
15268 | || ((size_t) (next - inote.descdata) | |
15269 | > data_remaining - (size_t) (inote.descdata - inote.namedata))) | |
15270 | { | |
15271 | warn (_("\ | |
15272 | malformed note encountered in section %s whilst scanning for build-id note\n"), | |
15273 | printable_section_name (filedata, shdr)); | |
15274 | free (enote); | |
15275 | continue; | |
15276 | } | |
15277 | ||
15278 | /* Check if this is the build-id note. If so then convert the build-id | |
15279 | bytes to a hex string. */ | |
15280 | if (inote.namesz > 0 | |
15281 | && const_strneq (inote.namedata, "GNU") | |
15282 | && inote.type == NT_GNU_BUILD_ID) | |
15283 | { | |
15284 | unsigned long j; | |
15285 | char * build_id; | |
15286 | ||
15287 | build_id = malloc (inote.descsz * 2 + 1); | |
15288 | if (build_id == NULL) | |
15289 | { | |
15290 | free (enote); | |
15291 | return NULL; | |
15292 | } | |
15293 | ||
15294 | for (j = 0; j < inote.descsz; ++j) | |
15295 | sprintf (build_id + (j * 2), "%02x", inote.descdata[j] & 0xff); | |
15296 | build_id[inote.descsz * 2] = '\0'; | |
15297 | free (enote); | |
15298 | ||
15299 | return (unsigned char *) build_id; | |
15300 | } | |
15301 | free (enote); | |
15302 | } | |
15303 | ||
15304 | return NULL; | |
15305 | } | |
15306 | #endif /* HAVE_LIBDEBUGINFOD */ | |
15307 | ||
15308 | /* If this is not NULL, load_debug_section will only look for sections | |
15309 | within the list of sections given here. */ | |
15310 | static unsigned int * section_subset = NULL; | |
15311 | ||
15312 | bfd_boolean | |
15313 | load_debug_section (enum dwarf_section_display_enum debug, void * data) | |
15314 | { | |
15315 | struct dwarf_section * section = &debug_displays [debug].section; | |
15316 | Elf_Internal_Shdr * sec; | |
15317 | Filedata * filedata = (Filedata *) data; | |
15318 | ||
15319 | /* Without section headers we cannot find any sections. */ | |
15320 | if (filedata->section_headers == NULL) | |
15321 | return FALSE; | |
15322 | ||
15323 | if (filedata->string_table == NULL | |
15324 | && filedata->file_header.e_shstrndx != SHN_UNDEF | |
15325 | && filedata->file_header.e_shstrndx < filedata->file_header.e_shnum) | |
15326 | { | |
15327 | Elf_Internal_Shdr * strs; | |
15328 | ||
15329 | /* Read in the string table, so that we have section names to scan. */ | |
15330 | strs = filedata->section_headers + filedata->file_header.e_shstrndx; | |
15331 | ||
15332 | if (strs != NULL && strs->sh_size != 0) | |
15333 | { | |
15334 | filedata->string_table | |
15335 | = (char *) get_data (NULL, filedata, strs->sh_offset, | |
15336 | 1, strs->sh_size, _("string table")); | |
15337 | ||
15338 | filedata->string_table_length | |
15339 | = filedata->string_table != NULL ? strs->sh_size : 0; | |
15340 | } | |
15341 | } | |
15342 | ||
15343 | /* Locate the debug section. */ | |
15344 | sec = find_section_in_set (filedata, section->uncompressed_name, section_subset); | |
15345 | if (sec != NULL) | |
15346 | section->name = section->uncompressed_name; | |
15347 | else | |
15348 | { | |
15349 | sec = find_section_in_set (filedata, section->compressed_name, section_subset); | |
15350 | if (sec != NULL) | |
15351 | section->name = section->compressed_name; | |
15352 | } | |
15353 | if (sec == NULL) | |
15354 | return FALSE; | |
15355 | ||
15356 | /* If we're loading from a subset of sections, and we've loaded | |
15357 | a section matching this name before, it's likely that it's a | |
15358 | different one. */ | |
15359 | if (section_subset != NULL) | |
15360 | free_debug_section (debug); | |
15361 | ||
15362 | return load_specific_debug_section (debug, sec, data); | |
15363 | } | |
15364 | ||
15365 | void | |
15366 | free_debug_section (enum dwarf_section_display_enum debug) | |
15367 | { | |
15368 | struct dwarf_section * section = &debug_displays [debug].section; | |
15369 | ||
15370 | if (section->start == NULL) | |
15371 | return; | |
15372 | ||
15373 | free ((char *) section->start); | |
15374 | section->start = NULL; | |
15375 | section->address = 0; | |
15376 | section->size = 0; | |
15377 | ||
15378 | free (section->reloc_info); | |
15379 | section->reloc_info = NULL; | |
15380 | section->num_relocs = 0; | |
15381 | } | |
15382 | ||
15383 | static bfd_boolean | |
15384 | display_debug_section (int shndx, Elf_Internal_Shdr * section, Filedata * filedata) | |
15385 | { | |
15386 | char * name = SECTION_NAME_VALID (section) ? SECTION_NAME (section) : ""; | |
15387 | const char * print_name = printable_section_name (filedata, section); | |
15388 | bfd_size_type length; | |
15389 | bfd_boolean result = TRUE; | |
15390 | int i; | |
15391 | ||
15392 | length = section->sh_size; | |
15393 | if (length == 0) | |
15394 | { | |
15395 | printf (_("\nSection '%s' has no debugging data.\n"), print_name); | |
15396 | return TRUE; | |
15397 | } | |
15398 | if (section->sh_type == SHT_NOBITS) | |
15399 | { | |
15400 | /* There is no point in dumping the contents of a debugging section | |
15401 | which has the NOBITS type - the bits in the file will be random. | |
15402 | This can happen when a file containing a .eh_frame section is | |
15403 | stripped with the --only-keep-debug command line option. */ | |
15404 | printf (_("section '%s' has the NOBITS type - its contents are unreliable.\n"), | |
15405 | print_name); | |
15406 | return FALSE; | |
15407 | } | |
15408 | ||
15409 | if (const_strneq (name, ".gnu.linkonce.wi.")) | |
15410 | name = ".debug_info"; | |
15411 | ||
15412 | /* See if we know how to display the contents of this section. */ | |
15413 | for (i = 0; i < max; i++) | |
15414 | { | |
15415 | enum dwarf_section_display_enum id = (enum dwarf_section_display_enum) i; | |
15416 | struct dwarf_section_display * display = debug_displays + i; | |
15417 | struct dwarf_section * sec = & display->section; | |
15418 | ||
15419 | if (streq (sec->uncompressed_name, name) | |
15420 | || (id == line && const_strneq (name, ".debug_line.")) | |
15421 | || streq (sec->compressed_name, name)) | |
15422 | { | |
15423 | bfd_boolean secondary = (section != find_section (filedata, name)); | |
15424 | ||
15425 | if (secondary) | |
15426 | free_debug_section (id); | |
15427 | ||
15428 | if (i == line && const_strneq (name, ".debug_line.")) | |
15429 | sec->name = name; | |
15430 | else if (streq (sec->uncompressed_name, name)) | |
15431 | sec->name = sec->uncompressed_name; | |
15432 | else | |
15433 | sec->name = sec->compressed_name; | |
15434 | ||
15435 | if (load_specific_debug_section (id, section, filedata)) | |
15436 | { | |
15437 | /* If this debug section is part of a CU/TU set in a .dwp file, | |
15438 | restrict load_debug_section to the sections in that set. */ | |
15439 | section_subset = find_cu_tu_set (filedata, shndx); | |
15440 | ||
15441 | result &= display->display (sec, filedata); | |
15442 | ||
15443 | section_subset = NULL; | |
15444 | ||
15445 | if (secondary || (id != info && id != abbrev)) | |
15446 | free_debug_section (id); | |
15447 | } | |
15448 | break; | |
15449 | } | |
15450 | } | |
15451 | ||
15452 | if (i == max) | |
15453 | { | |
15454 | printf (_("Unrecognized debug section: %s\n"), print_name); | |
15455 | result = FALSE; | |
15456 | } | |
15457 | ||
15458 | return result; | |
15459 | } | |
15460 | ||
15461 | /* Set DUMP_SECTS for all sections where dumps were requested | |
15462 | based on section name. */ | |
15463 | ||
15464 | static void | |
15465 | initialise_dumps_byname (Filedata * filedata) | |
15466 | { | |
15467 | struct dump_list_entry * cur; | |
15468 | ||
15469 | for (cur = dump_sects_byname; cur; cur = cur->next) | |
15470 | { | |
15471 | unsigned int i; | |
15472 | bfd_boolean any = FALSE; | |
15473 | ||
15474 | for (i = 0; i < filedata->file_header.e_shnum; i++) | |
15475 | if (SECTION_NAME_VALID (filedata->section_headers + i) | |
15476 | && streq (SECTION_NAME (filedata->section_headers + i), cur->name)) | |
15477 | { | |
15478 | request_dump_bynumber (&filedata->dump, i, cur->type); | |
15479 | any = TRUE; | |
15480 | } | |
15481 | ||
15482 | if (!any) | |
15483 | { | |
15484 | if (filedata->is_separate) | |
15485 | warn (_("Section '%s' in linked file '%s' was not dumped because it does not exist\n"), | |
15486 | cur->name, filedata->file_name); | |
15487 | else | |
15488 | warn (_("Section '%s' was not dumped because it does not exist\n"), | |
15489 | cur->name); | |
15490 | } | |
15491 | } | |
15492 | } | |
15493 | ||
15494 | static bfd_boolean | |
15495 | process_section_contents (Filedata * filedata) | |
15496 | { | |
15497 | Elf_Internal_Shdr * section; | |
15498 | unsigned int i; | |
15499 | bfd_boolean res = TRUE; | |
15500 | ||
15501 | if (! do_dump) | |
15502 | return TRUE; | |
15503 | ||
15504 | initialise_dumps_byname (filedata); | |
15505 | ||
15506 | for (i = 0, section = filedata->section_headers; | |
15507 | i < filedata->file_header.e_shnum && i < filedata->dump.num_dump_sects; | |
15508 | i++, section++) | |
15509 | { | |
15510 | dump_type dump = filedata->dump.dump_sects[i]; | |
15511 | ||
15512 | if (filedata->is_separate && ! process_links) | |
15513 | dump &= DEBUG_DUMP; | |
15514 | ||
15515 | #ifdef SUPPORT_DISASSEMBLY | |
15516 | if (dump & DISASS_DUMP) | |
15517 | { | |
15518 | if (! disassemble_section (section, filedata)) | |
15519 | res = FALSE; | |
15520 | } | |
15521 | #endif | |
15522 | if (dump & HEX_DUMP) | |
15523 | { | |
15524 | if (! dump_section_as_bytes (section, filedata, FALSE)) | |
15525 | res = FALSE; | |
15526 | } | |
15527 | ||
15528 | if (dump & RELOC_DUMP) | |
15529 | { | |
15530 | if (! dump_section_as_bytes (section, filedata, TRUE)) | |
15531 | res = FALSE; | |
15532 | } | |
15533 | ||
15534 | if (dump & STRING_DUMP) | |
15535 | { | |
15536 | if (! dump_section_as_strings (section, filedata)) | |
15537 | res = FALSE; | |
15538 | } | |
15539 | ||
15540 | if (dump & DEBUG_DUMP) | |
15541 | { | |
15542 | if (! display_debug_section (i, section, filedata)) | |
15543 | res = FALSE; | |
15544 | } | |
15545 | ||
15546 | #ifdef ENABLE_LIBCTF | |
15547 | if (dump & CTF_DUMP) | |
15548 | { | |
15549 | if (! dump_section_as_ctf (section, filedata)) | |
15550 | res = FALSE; | |
15551 | } | |
15552 | #endif | |
15553 | } | |
15554 | ||
15555 | /* Check to see if the user requested a | |
15556 | dump of a section that does not exist. */ | |
15557 | while (i < filedata->dump.num_dump_sects) | |
15558 | { | |
15559 | if (filedata->dump.dump_sects[i]) | |
15560 | { | |
15561 | if (filedata->is_separate) | |
15562 | warn (_("Section %d in linked file '%s' was not dumped because it does not exist!\n"), | |
15563 | i, filedata->file_name); | |
15564 | else | |
15565 | warn (_("Section %d was not dumped because it does not exist!\n"), i); | |
15566 | res = FALSE; | |
15567 | } | |
15568 | i++; | |
15569 | } | |
15570 | ||
15571 | return res; | |
15572 | } | |
15573 | ||
15574 | static void | |
15575 | process_mips_fpe_exception (int mask) | |
15576 | { | |
15577 | if (mask) | |
15578 | { | |
15579 | bfd_boolean first = TRUE; | |
15580 | ||
15581 | if (mask & OEX_FPU_INEX) | |
15582 | fputs ("INEX", stdout), first = FALSE; | |
15583 | if (mask & OEX_FPU_UFLO) | |
15584 | printf ("%sUFLO", first ? "" : "|"), first = FALSE; | |
15585 | if (mask & OEX_FPU_OFLO) | |
15586 | printf ("%sOFLO", first ? "" : "|"), first = FALSE; | |
15587 | if (mask & OEX_FPU_DIV0) | |
15588 | printf ("%sDIV0", first ? "" : "|"), first = FALSE; | |
15589 | if (mask & OEX_FPU_INVAL) | |
15590 | printf ("%sINVAL", first ? "" : "|"); | |
15591 | } | |
15592 | else | |
15593 | fputs ("0", stdout); | |
15594 | } | |
15595 | ||
15596 | /* Display's the value of TAG at location P. If TAG is | |
15597 | greater than 0 it is assumed to be an unknown tag, and | |
15598 | a message is printed to this effect. Otherwise it is | |
15599 | assumed that a message has already been printed. | |
15600 | ||
15601 | If the bottom bit of TAG is set it assumed to have a | |
15602 | string value, otherwise it is assumed to have an integer | |
15603 | value. | |
15604 | ||
15605 | Returns an updated P pointing to the first unread byte | |
15606 | beyond the end of TAG's value. | |
15607 | ||
15608 | Reads at or beyond END will not be made. */ | |
15609 | ||
15610 | static unsigned char * | |
15611 | display_tag_value (signed int tag, | |
15612 | unsigned char * p, | |
15613 | const unsigned char * const end) | |
15614 | { | |
15615 | unsigned long val; | |
15616 | ||
15617 | if (tag > 0) | |
15618 | printf (" Tag_unknown_%d: ", tag); | |
15619 | ||
15620 | if (p >= end) | |
15621 | { | |
15622 | warn (_("<corrupt tag>\n")); | |
15623 | } | |
15624 | else if (tag & 1) | |
15625 | { | |
15626 | /* PR 17531 file: 027-19978-0.004. */ | |
15627 | size_t maxlen = (end - p) - 1; | |
15628 | ||
15629 | putchar ('"'); | |
15630 | if (maxlen > 0) | |
15631 | { | |
15632 | print_symbol ((int) maxlen, (const char *) p); | |
15633 | p += strnlen ((char *) p, maxlen) + 1; | |
15634 | } | |
15635 | else | |
15636 | { | |
15637 | printf (_("<corrupt string tag>")); | |
15638 | p = (unsigned char *) end; | |
15639 | } | |
15640 | printf ("\"\n"); | |
15641 | } | |
15642 | else | |
15643 | { | |
15644 | READ_ULEB (val, p, end); | |
15645 | printf ("%ld (0x%lx)\n", val, val); | |
15646 | } | |
15647 | ||
15648 | assert (p <= end); | |
15649 | return p; | |
15650 | } | |
15651 | ||
15652 | /* ARC ABI attributes section. */ | |
15653 | ||
15654 | static unsigned char * | |
15655 | display_arc_attribute (unsigned char * p, | |
15656 | const unsigned char * const end) | |
15657 | { | |
15658 | unsigned int tag; | |
15659 | unsigned int val; | |
15660 | ||
15661 | READ_ULEB (tag, p, end); | |
15662 | ||
15663 | switch (tag) | |
15664 | { | |
15665 | case Tag_ARC_PCS_config: | |
15666 | READ_ULEB (val, p, end); | |
15667 | printf (" Tag_ARC_PCS_config: "); | |
15668 | switch (val) | |
15669 | { | |
15670 | case 0: | |
15671 | printf (_("Absent/Non standard\n")); | |
15672 | break; | |
15673 | case 1: | |
15674 | printf (_("Bare metal/mwdt\n")); | |
15675 | break; | |
15676 | case 2: | |
15677 | printf (_("Bare metal/newlib\n")); | |
15678 | break; | |
15679 | case 3: | |
15680 | printf (_("Linux/uclibc\n")); | |
15681 | break; | |
15682 | case 4: | |
15683 | printf (_("Linux/glibc\n")); | |
15684 | break; | |
15685 | default: | |
15686 | printf (_("Unknown\n")); | |
15687 | break; | |
15688 | } | |
15689 | break; | |
15690 | ||
15691 | case Tag_ARC_CPU_base: | |
15692 | READ_ULEB (val, p, end); | |
15693 | printf (" Tag_ARC_CPU_base: "); | |
15694 | switch (val) | |
15695 | { | |
15696 | default: | |
15697 | case TAG_CPU_NONE: | |
15698 | printf (_("Absent\n")); | |
15699 | break; | |
15700 | case TAG_CPU_ARC6xx: | |
15701 | printf ("ARC6xx\n"); | |
15702 | break; | |
15703 | case TAG_CPU_ARC7xx: | |
15704 | printf ("ARC7xx\n"); | |
15705 | break; | |
15706 | case TAG_CPU_ARCEM: | |
15707 | printf ("ARCEM\n"); | |
15708 | break; | |
15709 | case TAG_CPU_ARCHS: | |
15710 | printf ("ARCHS\n"); | |
15711 | break; | |
15712 | } | |
15713 | break; | |
15714 | ||
15715 | case Tag_ARC_CPU_variation: | |
15716 | READ_ULEB (val, p, end); | |
15717 | printf (" Tag_ARC_CPU_variation: "); | |
15718 | switch (val) | |
15719 | { | |
15720 | default: | |
15721 | if (val > 0 && val < 16) | |
15722 | printf ("Core%d\n", val); | |
15723 | else | |
15724 | printf ("Unknown\n"); | |
15725 | break; | |
15726 | ||
15727 | case 0: | |
15728 | printf (_("Absent\n")); | |
15729 | break; | |
15730 | } | |
15731 | break; | |
15732 | ||
15733 | case Tag_ARC_CPU_name: | |
15734 | printf (" Tag_ARC_CPU_name: "); | |
15735 | p = display_tag_value (-1, p, end); | |
15736 | break; | |
15737 | ||
15738 | case Tag_ARC_ABI_rf16: | |
15739 | READ_ULEB (val, p, end); | |
15740 | printf (" Tag_ARC_ABI_rf16: %s\n", val ? _("yes") : _("no")); | |
15741 | break; | |
15742 | ||
15743 | case Tag_ARC_ABI_osver: | |
15744 | READ_ULEB (val, p, end); | |
15745 | printf (" Tag_ARC_ABI_osver: v%d\n", val); | |
15746 | break; | |
15747 | ||
15748 | case Tag_ARC_ABI_pic: | |
15749 | case Tag_ARC_ABI_sda: | |
15750 | READ_ULEB (val, p, end); | |
15751 | printf (tag == Tag_ARC_ABI_sda ? " Tag_ARC_ABI_sda: " | |
15752 | : " Tag_ARC_ABI_pic: "); | |
15753 | switch (val) | |
15754 | { | |
15755 | case 0: | |
15756 | printf (_("Absent\n")); | |
15757 | break; | |
15758 | case 1: | |
15759 | printf ("MWDT\n"); | |
15760 | break; | |
15761 | case 2: | |
15762 | printf ("GNU\n"); | |
15763 | break; | |
15764 | default: | |
15765 | printf (_("Unknown\n")); | |
15766 | break; | |
15767 | } | |
15768 | break; | |
15769 | ||
15770 | case Tag_ARC_ABI_tls: | |
15771 | READ_ULEB (val, p, end); | |
15772 | printf (" Tag_ARC_ABI_tls: %s\n", val ? "r25": "none"); | |
15773 | break; | |
15774 | ||
15775 | case Tag_ARC_ABI_enumsize: | |
15776 | READ_ULEB (val, p, end); | |
15777 | printf (" Tag_ARC_ABI_enumsize: %s\n", val ? _("default") : | |
15778 | _("smallest")); | |
15779 | break; | |
15780 | ||
15781 | case Tag_ARC_ABI_exceptions: | |
15782 | READ_ULEB (val, p, end); | |
15783 | printf (" Tag_ARC_ABI_exceptions: %s\n", val ? _("OPTFP") | |
15784 | : _("default")); | |
15785 | break; | |
15786 | ||
15787 | case Tag_ARC_ABI_double_size: | |
15788 | READ_ULEB (val, p, end); | |
15789 | printf (" Tag_ARC_ABI_double_size: %d\n", val); | |
15790 | break; | |
15791 | ||
15792 | case Tag_ARC_ISA_config: | |
15793 | printf (" Tag_ARC_ISA_config: "); | |
15794 | p = display_tag_value (-1, p, end); | |
15795 | break; | |
15796 | ||
15797 | case Tag_ARC_ISA_apex: | |
15798 | printf (" Tag_ARC_ISA_apex: "); | |
15799 | p = display_tag_value (-1, p, end); | |
15800 | break; | |
15801 | ||
15802 | case Tag_ARC_ISA_mpy_option: | |
15803 | READ_ULEB (val, p, end); | |
15804 | printf (" Tag_ARC_ISA_mpy_option: %d\n", val); | |
15805 | break; | |
15806 | ||
15807 | case Tag_ARC_ATR_version: | |
15808 | READ_ULEB (val, p, end); | |
15809 | printf (" Tag_ARC_ATR_version: %d\n", val); | |
15810 | break; | |
15811 | ||
15812 | default: | |
15813 | return display_tag_value (tag & 1, p, end); | |
15814 | } | |
15815 | ||
15816 | return p; | |
15817 | } | |
15818 | ||
15819 | /* ARM EABI attributes section. */ | |
15820 | typedef struct | |
15821 | { | |
15822 | unsigned int tag; | |
15823 | const char * name; | |
15824 | /* 0 = special, 1 = string, 2 = uleb123, > 0x80 == table lookup. */ | |
15825 | unsigned int type; | |
15826 | const char *const *table; | |
15827 | } arm_attr_public_tag; | |
15828 | ||
15829 | static const char *const arm_attr_tag_CPU_arch[] = | |
15830 | {"Pre-v4", "v4", "v4T", "v5T", "v5TE", "v5TEJ", "v6", "v6KZ", "v6T2", | |
15831 | "v6K", "v7", "v6-M", "v6S-M", "v7E-M", "v8", "v8-R", "v8-M.baseline", | |
15832 | "v8-M.mainline", "", "", "", "v8.1-M.mainline"}; | |
15833 | static const char *const arm_attr_tag_ARM_ISA_use[] = {"No", "Yes"}; | |
15834 | static const char *const arm_attr_tag_THUMB_ISA_use[] = | |
15835 | {"No", "Thumb-1", "Thumb-2", "Yes"}; | |
15836 | static const char *const arm_attr_tag_FP_arch[] = | |
15837 | {"No", "VFPv1", "VFPv2", "VFPv3", "VFPv3-D16", "VFPv4", "VFPv4-D16", | |
15838 | "FP for ARMv8", "FPv5/FP-D16 for ARMv8"}; | |
15839 | static const char *const arm_attr_tag_WMMX_arch[] = {"No", "WMMXv1", "WMMXv2"}; | |
15840 | static const char *const arm_attr_tag_Advanced_SIMD_arch[] = | |
15841 | {"No", "NEONv1", "NEONv1 with Fused-MAC", "NEON for ARMv8", | |
15842 | "NEON for ARMv8.1"}; | |
15843 | static const char *const arm_attr_tag_PCS_config[] = | |
15844 | {"None", "Bare platform", "Linux application", "Linux DSO", "PalmOS 2004", | |
15845 | "PalmOS (reserved)", "SymbianOS 2004", "SymbianOS (reserved)"}; | |
15846 | static const char *const arm_attr_tag_ABI_PCS_R9_use[] = | |
15847 | {"V6", "SB", "TLS", "Unused"}; | |
15848 | static const char *const arm_attr_tag_ABI_PCS_RW_data[] = | |
15849 | {"Absolute", "PC-relative", "SB-relative", "None"}; | |
15850 | static const char *const arm_attr_tag_ABI_PCS_RO_data[] = | |
15851 | {"Absolute", "PC-relative", "None"}; | |
15852 | static const char *const arm_attr_tag_ABI_PCS_GOT_use[] = | |
15853 | {"None", "direct", "GOT-indirect"}; | |
15854 | static const char *const arm_attr_tag_ABI_PCS_wchar_t[] = | |
15855 | {"None", "??? 1", "2", "??? 3", "4"}; | |
15856 | static const char *const arm_attr_tag_ABI_FP_rounding[] = {"Unused", "Needed"}; | |
15857 | static const char *const arm_attr_tag_ABI_FP_denormal[] = | |
15858 | {"Unused", "Needed", "Sign only"}; | |
15859 | static const char *const arm_attr_tag_ABI_FP_exceptions[] = {"Unused", "Needed"}; | |
15860 | static const char *const arm_attr_tag_ABI_FP_user_exceptions[] = {"Unused", "Needed"}; | |
15861 | static const char *const arm_attr_tag_ABI_FP_number_model[] = | |
15862 | {"Unused", "Finite", "RTABI", "IEEE 754"}; | |
15863 | static const char *const arm_attr_tag_ABI_enum_size[] = | |
15864 | {"Unused", "small", "int", "forced to int"}; | |
15865 | static const char *const arm_attr_tag_ABI_HardFP_use[] = | |
15866 | {"As Tag_FP_arch", "SP only", "Reserved", "Deprecated"}; | |
15867 | static const char *const arm_attr_tag_ABI_VFP_args[] = | |
15868 | {"AAPCS", "VFP registers", "custom", "compatible"}; | |
15869 | static const char *const arm_attr_tag_ABI_WMMX_args[] = | |
15870 | {"AAPCS", "WMMX registers", "custom"}; | |
15871 | static const char *const arm_attr_tag_ABI_optimization_goals[] = | |
15872 | {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size", | |
15873 | "Aggressive Size", "Prefer Debug", "Aggressive Debug"}; | |
15874 | static const char *const arm_attr_tag_ABI_FP_optimization_goals[] = | |
15875 | {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size", | |
15876 | "Aggressive Size", "Prefer Accuracy", "Aggressive Accuracy"}; | |
15877 | static const char *const arm_attr_tag_CPU_unaligned_access[] = {"None", "v6"}; | |
15878 | static const char *const arm_attr_tag_FP_HP_extension[] = | |
15879 | {"Not Allowed", "Allowed"}; | |
15880 | static const char *const arm_attr_tag_ABI_FP_16bit_format[] = | |
15881 | {"None", "IEEE 754", "Alternative Format"}; | |
15882 | static const char *const arm_attr_tag_DSP_extension[] = | |
15883 | {"Follow architecture", "Allowed"}; | |
15884 | static const char *const arm_attr_tag_MPextension_use[] = | |
15885 | {"Not Allowed", "Allowed"}; | |
15886 | static const char *const arm_attr_tag_DIV_use[] = | |
15887 | {"Allowed in Thumb-ISA, v7-R or v7-M", "Not allowed", | |
15888 | "Allowed in v7-A with integer division extension"}; | |
15889 | static const char *const arm_attr_tag_T2EE_use[] = {"Not Allowed", "Allowed"}; | |
15890 | static const char *const arm_attr_tag_Virtualization_use[] = | |
15891 | {"Not Allowed", "TrustZone", "Virtualization Extensions", | |
15892 | "TrustZone and Virtualization Extensions"}; | |
15893 | static const char *const arm_attr_tag_MPextension_use_legacy[] = | |
15894 | {"Not Allowed", "Allowed"}; | |
15895 | ||
15896 | static const char *const arm_attr_tag_MVE_arch[] = | |
15897 | {"No MVE", "MVE Integer only", "MVE Integer and FP"}; | |
15898 | ||
15899 | #define LOOKUP(id, name) \ | |
15900 | {id, #name, 0x80 | ARRAY_SIZE(arm_attr_tag_##name), arm_attr_tag_##name} | |
15901 | static arm_attr_public_tag arm_attr_public_tags[] = | |
15902 | { | |
15903 | {4, "CPU_raw_name", 1, NULL}, | |
15904 | {5, "CPU_name", 1, NULL}, | |
15905 | LOOKUP(6, CPU_arch), | |
15906 | {7, "CPU_arch_profile", 0, NULL}, | |
15907 | LOOKUP(8, ARM_ISA_use), | |
15908 | LOOKUP(9, THUMB_ISA_use), | |
15909 | LOOKUP(10, FP_arch), | |
15910 | LOOKUP(11, WMMX_arch), | |
15911 | LOOKUP(12, Advanced_SIMD_arch), | |
15912 | LOOKUP(13, PCS_config), | |
15913 | LOOKUP(14, ABI_PCS_R9_use), | |
15914 | LOOKUP(15, ABI_PCS_RW_data), | |
15915 | LOOKUP(16, ABI_PCS_RO_data), | |
15916 | LOOKUP(17, ABI_PCS_GOT_use), | |
15917 | LOOKUP(18, ABI_PCS_wchar_t), | |
15918 | LOOKUP(19, ABI_FP_rounding), | |
15919 | LOOKUP(20, ABI_FP_denormal), | |
15920 | LOOKUP(21, ABI_FP_exceptions), | |
15921 | LOOKUP(22, ABI_FP_user_exceptions), | |
15922 | LOOKUP(23, ABI_FP_number_model), | |
15923 | {24, "ABI_align_needed", 0, NULL}, | |
15924 | {25, "ABI_align_preserved", 0, NULL}, | |
15925 | LOOKUP(26, ABI_enum_size), | |
15926 | LOOKUP(27, ABI_HardFP_use), | |
15927 | LOOKUP(28, ABI_VFP_args), | |
15928 | LOOKUP(29, ABI_WMMX_args), | |
15929 | LOOKUP(30, ABI_optimization_goals), | |
15930 | LOOKUP(31, ABI_FP_optimization_goals), | |
15931 | {32, "compatibility", 0, NULL}, | |
15932 | LOOKUP(34, CPU_unaligned_access), | |
15933 | LOOKUP(36, FP_HP_extension), | |
15934 | LOOKUP(38, ABI_FP_16bit_format), | |
15935 | LOOKUP(42, MPextension_use), | |
15936 | LOOKUP(44, DIV_use), | |
15937 | LOOKUP(46, DSP_extension), | |
15938 | LOOKUP(48, MVE_arch), | |
15939 | {64, "nodefaults", 0, NULL}, | |
15940 | {65, "also_compatible_with", 0, NULL}, | |
15941 | LOOKUP(66, T2EE_use), | |
15942 | {67, "conformance", 1, NULL}, | |
15943 | LOOKUP(68, Virtualization_use), | |
15944 | LOOKUP(70, MPextension_use_legacy) | |
15945 | }; | |
15946 | #undef LOOKUP | |
15947 | ||
15948 | static unsigned char * | |
15949 | display_arm_attribute (unsigned char * p, | |
15950 | const unsigned char * const end) | |
15951 | { | |
15952 | unsigned int tag; | |
15953 | unsigned int val; | |
15954 | arm_attr_public_tag * attr; | |
15955 | unsigned i; | |
15956 | unsigned int type; | |
15957 | ||
15958 | READ_ULEB (tag, p, end); | |
15959 | attr = NULL; | |
15960 | for (i = 0; i < ARRAY_SIZE (arm_attr_public_tags); i++) | |
15961 | { | |
15962 | if (arm_attr_public_tags[i].tag == tag) | |
15963 | { | |
15964 | attr = &arm_attr_public_tags[i]; | |
15965 | break; | |
15966 | } | |
15967 | } | |
15968 | ||
15969 | if (attr) | |
15970 | { | |
15971 | printf (" Tag_%s: ", attr->name); | |
15972 | switch (attr->type) | |
15973 | { | |
15974 | case 0: | |
15975 | switch (tag) | |
15976 | { | |
15977 | case 7: /* Tag_CPU_arch_profile. */ | |
15978 | READ_ULEB (val, p, end); | |
15979 | switch (val) | |
15980 | { | |
15981 | case 0: printf (_("None\n")); break; | |
15982 | case 'A': printf (_("Application\n")); break; | |
15983 | case 'R': printf (_("Realtime\n")); break; | |
15984 | case 'M': printf (_("Microcontroller\n")); break; | |
15985 | case 'S': printf (_("Application or Realtime\n")); break; | |
15986 | default: printf ("??? (%d)\n", val); break; | |
15987 | } | |
15988 | break; | |
15989 | ||
15990 | case 24: /* Tag_align_needed. */ | |
15991 | READ_ULEB (val, p, end); | |
15992 | switch (val) | |
15993 | { | |
15994 | case 0: printf (_("None\n")); break; | |
15995 | case 1: printf (_("8-byte\n")); break; | |
15996 | case 2: printf (_("4-byte\n")); break; | |
15997 | case 3: printf ("??? 3\n"); break; | |
15998 | default: | |
15999 | if (val <= 12) | |
16000 | printf (_("8-byte and up to %d-byte extended\n"), | |
16001 | 1 << val); | |
16002 | else | |
16003 | printf ("??? (%d)\n", val); | |
16004 | break; | |
16005 | } | |
16006 | break; | |
16007 | ||
16008 | case 25: /* Tag_align_preserved. */ | |
16009 | READ_ULEB (val, p, end); | |
16010 | switch (val) | |
16011 | { | |
16012 | case 0: printf (_("None\n")); break; | |
16013 | case 1: printf (_("8-byte, except leaf SP\n")); break; | |
16014 | case 2: printf (_("8-byte\n")); break; | |
16015 | case 3: printf ("??? 3\n"); break; | |
16016 | default: | |
16017 | if (val <= 12) | |
16018 | printf (_("8-byte and up to %d-byte extended\n"), | |
16019 | 1 << val); | |
16020 | else | |
16021 | printf ("??? (%d)\n", val); | |
16022 | break; | |
16023 | } | |
16024 | break; | |
16025 | ||
16026 | case 32: /* Tag_compatibility. */ | |
16027 | { | |
16028 | READ_ULEB (val, p, end); | |
16029 | printf (_("flag = %d, vendor = "), val); | |
16030 | if (p < end - 1) | |
16031 | { | |
16032 | size_t maxlen = (end - p) - 1; | |
16033 | ||
16034 | print_symbol ((int) maxlen, (const char *) p); | |
16035 | p += strnlen ((char *) p, maxlen) + 1; | |
16036 | } | |
16037 | else | |
16038 | { | |
16039 | printf (_("<corrupt>")); | |
16040 | p = (unsigned char *) end; | |
16041 | } | |
16042 | putchar ('\n'); | |
16043 | } | |
16044 | break; | |
16045 | ||
16046 | case 64: /* Tag_nodefaults. */ | |
16047 | /* PR 17531: file: 001-505008-0.01. */ | |
16048 | if (p < end) | |
16049 | p++; | |
16050 | printf (_("True\n")); | |
16051 | break; | |
16052 | ||
16053 | case 65: /* Tag_also_compatible_with. */ | |
16054 | READ_ULEB (val, p, end); | |
16055 | if (val == 6 /* Tag_CPU_arch. */) | |
16056 | { | |
16057 | READ_ULEB (val, p, end); | |
16058 | if ((unsigned int) val >= ARRAY_SIZE (arm_attr_tag_CPU_arch)) | |
16059 | printf ("??? (%d)\n", val); | |
16060 | else | |
16061 | printf ("%s\n", arm_attr_tag_CPU_arch[val]); | |
16062 | } | |
16063 | else | |
16064 | printf ("???\n"); | |
16065 | while (p < end && *(p++) != '\0' /* NUL terminator. */) | |
16066 | ; | |
16067 | break; | |
16068 | ||
16069 | default: | |
16070 | printf (_("<unknown: %d>\n"), tag); | |
16071 | break; | |
16072 | } | |
16073 | return p; | |
16074 | ||
16075 | case 1: | |
16076 | return display_tag_value (-1, p, end); | |
16077 | case 2: | |
16078 | return display_tag_value (0, p, end); | |
16079 | ||
16080 | default: | |
16081 | assert (attr->type & 0x80); | |
16082 | READ_ULEB (val, p, end); | |
16083 | type = attr->type & 0x7f; | |
16084 | if (val >= type) | |
16085 | printf ("??? (%d)\n", val); | |
16086 | else | |
16087 | printf ("%s\n", attr->table[val]); | |
16088 | return p; | |
16089 | } | |
16090 | } | |
16091 | ||
16092 | return display_tag_value (tag, p, end); | |
16093 | } | |
16094 | ||
16095 | static unsigned char * | |
16096 | display_gnu_attribute (unsigned char * p, | |
16097 | unsigned char * (* display_proc_gnu_attribute) (unsigned char *, unsigned int, const unsigned char * const), | |
16098 | const unsigned char * const end) | |
16099 | { | |
16100 | unsigned int tag; | |
16101 | unsigned int val; | |
16102 | ||
16103 | READ_ULEB (tag, p, end); | |
16104 | ||
16105 | /* Tag_compatibility is the only generic GNU attribute defined at | |
16106 | present. */ | |
16107 | if (tag == 32) | |
16108 | { | |
16109 | READ_ULEB (val, p, end); | |
16110 | ||
16111 | printf (_("flag = %d, vendor = "), val); | |
16112 | if (p == end) | |
16113 | { | |
16114 | printf (_("<corrupt>\n")); | |
16115 | warn (_("corrupt vendor attribute\n")); | |
16116 | } | |
16117 | else | |
16118 | { | |
16119 | if (p < end - 1) | |
16120 | { | |
16121 | size_t maxlen = (end - p) - 1; | |
16122 | ||
16123 | print_symbol ((int) maxlen, (const char *) p); | |
16124 | p += strnlen ((char *) p, maxlen) + 1; | |
16125 | } | |
16126 | else | |
16127 | { | |
16128 | printf (_("<corrupt>")); | |
16129 | p = (unsigned char *) end; | |
16130 | } | |
16131 | putchar ('\n'); | |
16132 | } | |
16133 | return p; | |
16134 | } | |
16135 | ||
16136 | if ((tag & 2) == 0 && display_proc_gnu_attribute) | |
16137 | return display_proc_gnu_attribute (p, tag, end); | |
16138 | ||
16139 | return display_tag_value (tag, p, end); | |
16140 | } | |
16141 | ||
16142 | static unsigned char * | |
16143 | display_m68k_gnu_attribute (unsigned char * p, | |
16144 | unsigned int tag, | |
16145 | const unsigned char * const end) | |
16146 | { | |
16147 | unsigned int val; | |
16148 | ||
16149 | if (tag == Tag_GNU_M68K_ABI_FP) | |
16150 | { | |
16151 | printf (" Tag_GNU_M68K_ABI_FP: "); | |
16152 | if (p == end) | |
16153 | { | |
16154 | printf (_("<corrupt>\n")); | |
16155 | return p; | |
16156 | } | |
16157 | READ_ULEB (val, p, end); | |
16158 | ||
16159 | if (val > 3) | |
16160 | printf ("(%#x), ", val); | |
16161 | ||
16162 | switch (val & 3) | |
16163 | { | |
16164 | case 0: | |
16165 | printf (_("unspecified hard/soft float\n")); | |
16166 | break; | |
16167 | case 1: | |
16168 | printf (_("hard float\n")); | |
16169 | break; | |
16170 | case 2: | |
16171 | printf (_("soft float\n")); | |
16172 | break; | |
16173 | } | |
16174 | return p; | |
16175 | } | |
16176 | ||
16177 | return display_tag_value (tag & 1, p, end); | |
16178 | } | |
16179 | ||
16180 | static unsigned char * | |
16181 | display_power_gnu_attribute (unsigned char * p, | |
16182 | unsigned int tag, | |
16183 | const unsigned char * const end) | |
16184 | { | |
16185 | unsigned int val; | |
16186 | ||
16187 | if (tag == Tag_GNU_Power_ABI_FP) | |
16188 | { | |
16189 | printf (" Tag_GNU_Power_ABI_FP: "); | |
16190 | if (p == end) | |
16191 | { | |
16192 | printf (_("<corrupt>\n")); | |
16193 | return p; | |
16194 | } | |
16195 | READ_ULEB (val, p, end); | |
16196 | ||
16197 | if (val > 15) | |
16198 | printf ("(%#x), ", val); | |
16199 | ||
16200 | switch (val & 3) | |
16201 | { | |
16202 | case 0: | |
16203 | printf (_("unspecified hard/soft float, ")); | |
16204 | break; | |
16205 | case 1: | |
16206 | printf (_("hard float, ")); | |
16207 | break; | |
16208 | case 2: | |
16209 | printf (_("soft float, ")); | |
16210 | break; | |
16211 | case 3: | |
16212 | printf (_("single-precision hard float, ")); | |
16213 | break; | |
16214 | } | |
16215 | ||
16216 | switch (val & 0xC) | |
16217 | { | |
16218 | case 0: | |
16219 | printf (_("unspecified long double\n")); | |
16220 | break; | |
16221 | case 4: | |
16222 | printf (_("128-bit IBM long double\n")); | |
16223 | break; | |
16224 | case 8: | |
16225 | printf (_("64-bit long double\n")); | |
16226 | break; | |
16227 | case 12: | |
16228 | printf (_("128-bit IEEE long double\n")); | |
16229 | break; | |
16230 | } | |
16231 | return p; | |
16232 | } | |
16233 | ||
16234 | if (tag == Tag_GNU_Power_ABI_Vector) | |
16235 | { | |
16236 | printf (" Tag_GNU_Power_ABI_Vector: "); | |
16237 | if (p == end) | |
16238 | { | |
16239 | printf (_("<corrupt>\n")); | |
16240 | return p; | |
16241 | } | |
16242 | READ_ULEB (val, p, end); | |
16243 | ||
16244 | if (val > 3) | |
16245 | printf ("(%#x), ", val); | |
16246 | ||
16247 | switch (val & 3) | |
16248 | { | |
16249 | case 0: | |
16250 | printf (_("unspecified\n")); | |
16251 | break; | |
16252 | case 1: | |
16253 | printf (_("generic\n")); | |
16254 | break; | |
16255 | case 2: | |
16256 | printf ("AltiVec\n"); | |
16257 | break; | |
16258 | case 3: | |
16259 | printf ("SPE\n"); | |
16260 | break; | |
16261 | } | |
16262 | return p; | |
16263 | } | |
16264 | ||
16265 | if (tag == Tag_GNU_Power_ABI_Struct_Return) | |
16266 | { | |
16267 | printf (" Tag_GNU_Power_ABI_Struct_Return: "); | |
16268 | if (p == end) | |
16269 | { | |
16270 | printf (_("<corrupt>\n")); | |
16271 | return p; | |
16272 | } | |
16273 | READ_ULEB (val, p, end); | |
16274 | ||
16275 | if (val > 2) | |
16276 | printf ("(%#x), ", val); | |
16277 | ||
16278 | switch (val & 3) | |
16279 | { | |
16280 | case 0: | |
16281 | printf (_("unspecified\n")); | |
16282 | break; | |
16283 | case 1: | |
16284 | printf ("r3/r4\n"); | |
16285 | break; | |
16286 | case 2: | |
16287 | printf (_("memory\n")); | |
16288 | break; | |
16289 | case 3: | |
16290 | printf ("???\n"); | |
16291 | break; | |
16292 | } | |
16293 | return p; | |
16294 | } | |
16295 | ||
16296 | return display_tag_value (tag & 1, p, end); | |
16297 | } | |
16298 | ||
16299 | static unsigned char * | |
16300 | display_s390_gnu_attribute (unsigned char * p, | |
16301 | unsigned int tag, | |
16302 | const unsigned char * const end) | |
16303 | { | |
16304 | unsigned int val; | |
16305 | ||
16306 | if (tag == Tag_GNU_S390_ABI_Vector) | |
16307 | { | |
16308 | printf (" Tag_GNU_S390_ABI_Vector: "); | |
16309 | READ_ULEB (val, p, end); | |
16310 | ||
16311 | switch (val) | |
16312 | { | |
16313 | case 0: | |
16314 | printf (_("any\n")); | |
16315 | break; | |
16316 | case 1: | |
16317 | printf (_("software\n")); | |
16318 | break; | |
16319 | case 2: | |
16320 | printf (_("hardware\n")); | |
16321 | break; | |
16322 | default: | |
16323 | printf ("??? (%d)\n", val); | |
16324 | break; | |
16325 | } | |
16326 | return p; | |
16327 | } | |
16328 | ||
16329 | return display_tag_value (tag & 1, p, end); | |
16330 | } | |
16331 | ||
16332 | static void | |
16333 | display_sparc_hwcaps (unsigned int mask) | |
16334 | { | |
16335 | if (mask) | |
16336 | { | |
16337 | bfd_boolean first = TRUE; | |
16338 | ||
16339 | if (mask & ELF_SPARC_HWCAP_MUL32) | |
16340 | fputs ("mul32", stdout), first = FALSE; | |
16341 | if (mask & ELF_SPARC_HWCAP_DIV32) | |
16342 | printf ("%sdiv32", first ? "" : "|"), first = FALSE; | |
16343 | if (mask & ELF_SPARC_HWCAP_FSMULD) | |
16344 | printf ("%sfsmuld", first ? "" : "|"), first = FALSE; | |
16345 | if (mask & ELF_SPARC_HWCAP_V8PLUS) | |
16346 | printf ("%sv8plus", first ? "" : "|"), first = FALSE; | |
16347 | if (mask & ELF_SPARC_HWCAP_POPC) | |
16348 | printf ("%spopc", first ? "" : "|"), first = FALSE; | |
16349 | if (mask & ELF_SPARC_HWCAP_VIS) | |
16350 | printf ("%svis", first ? "" : "|"), first = FALSE; | |
16351 | if (mask & ELF_SPARC_HWCAP_VIS2) | |
16352 | printf ("%svis2", first ? "" : "|"), first = FALSE; | |
16353 | if (mask & ELF_SPARC_HWCAP_ASI_BLK_INIT) | |
16354 | printf ("%sASIBlkInit", first ? "" : "|"), first = FALSE; | |
16355 | if (mask & ELF_SPARC_HWCAP_FMAF) | |
16356 | printf ("%sfmaf", first ? "" : "|"), first = FALSE; | |
16357 | if (mask & ELF_SPARC_HWCAP_VIS3) | |
16358 | printf ("%svis3", first ? "" : "|"), first = FALSE; | |
16359 | if (mask & ELF_SPARC_HWCAP_HPC) | |
16360 | printf ("%shpc", first ? "" : "|"), first = FALSE; | |
16361 | if (mask & ELF_SPARC_HWCAP_RANDOM) | |
16362 | printf ("%srandom", first ? "" : "|"), first = FALSE; | |
16363 | if (mask & ELF_SPARC_HWCAP_TRANS) | |
16364 | printf ("%strans", first ? "" : "|"), first = FALSE; | |
16365 | if (mask & ELF_SPARC_HWCAP_FJFMAU) | |
16366 | printf ("%sfjfmau", first ? "" : "|"), first = FALSE; | |
16367 | if (mask & ELF_SPARC_HWCAP_IMA) | |
16368 | printf ("%sima", first ? "" : "|"), first = FALSE; | |
16369 | if (mask & ELF_SPARC_HWCAP_ASI_CACHE_SPARING) | |
16370 | printf ("%scspare", first ? "" : "|"), first = FALSE; | |
16371 | } | |
16372 | else | |
16373 | fputc ('0', stdout); | |
16374 | fputc ('\n', stdout); | |
16375 | } | |
16376 | ||
16377 | static void | |
16378 | display_sparc_hwcaps2 (unsigned int mask) | |
16379 | { | |
16380 | if (mask) | |
16381 | { | |
16382 | bfd_boolean first = TRUE; | |
16383 | ||
16384 | if (mask & ELF_SPARC_HWCAP2_FJATHPLUS) | |
16385 | fputs ("fjathplus", stdout), first = FALSE; | |
16386 | if (mask & ELF_SPARC_HWCAP2_VIS3B) | |
16387 | printf ("%svis3b", first ? "" : "|"), first = FALSE; | |
16388 | if (mask & ELF_SPARC_HWCAP2_ADP) | |
16389 | printf ("%sadp", first ? "" : "|"), first = FALSE; | |
16390 | if (mask & ELF_SPARC_HWCAP2_SPARC5) | |
16391 | printf ("%ssparc5", first ? "" : "|"), first = FALSE; | |
16392 | if (mask & ELF_SPARC_HWCAP2_MWAIT) | |
16393 | printf ("%smwait", first ? "" : "|"), first = FALSE; | |
16394 | if (mask & ELF_SPARC_HWCAP2_XMPMUL) | |
16395 | printf ("%sxmpmul", first ? "" : "|"), first = FALSE; | |
16396 | if (mask & ELF_SPARC_HWCAP2_XMONT) | |
16397 | printf ("%sxmont2", first ? "" : "|"), first = FALSE; | |
16398 | if (mask & ELF_SPARC_HWCAP2_NSEC) | |
16399 | printf ("%snsec", first ? "" : "|"), first = FALSE; | |
16400 | if (mask & ELF_SPARC_HWCAP2_FJATHHPC) | |
16401 | printf ("%sfjathhpc", first ? "" : "|"), first = FALSE; | |
16402 | if (mask & ELF_SPARC_HWCAP2_FJDES) | |
16403 | printf ("%sfjdes", first ? "" : "|"), first = FALSE; | |
16404 | if (mask & ELF_SPARC_HWCAP2_FJAES) | |
16405 | printf ("%sfjaes", first ? "" : "|"), first = FALSE; | |
16406 | } | |
16407 | else | |
16408 | fputc ('0', stdout); | |
16409 | fputc ('\n', stdout); | |
16410 | } | |
16411 | ||
16412 | static unsigned char * | |
16413 | display_sparc_gnu_attribute (unsigned char * p, | |
16414 | unsigned int tag, | |
16415 | const unsigned char * const end) | |
16416 | { | |
16417 | unsigned int val; | |
16418 | ||
16419 | if (tag == Tag_GNU_Sparc_HWCAPS) | |
16420 | { | |
16421 | READ_ULEB (val, p, end); | |
16422 | printf (" Tag_GNU_Sparc_HWCAPS: "); | |
16423 | display_sparc_hwcaps (val); | |
16424 | return p; | |
16425 | } | |
16426 | if (tag == Tag_GNU_Sparc_HWCAPS2) | |
16427 | { | |
16428 | READ_ULEB (val, p, end); | |
16429 | printf (" Tag_GNU_Sparc_HWCAPS2: "); | |
16430 | display_sparc_hwcaps2 (val); | |
16431 | return p; | |
16432 | } | |
16433 | ||
16434 | return display_tag_value (tag, p, end); | |
16435 | } | |
16436 | ||
16437 | static void | |
16438 | print_mips_fp_abi_value (unsigned int val) | |
16439 | { | |
16440 | switch (val) | |
16441 | { | |
16442 | case Val_GNU_MIPS_ABI_FP_ANY: | |
16443 | printf (_("Hard or soft float\n")); | |
16444 | break; | |
16445 | case Val_GNU_MIPS_ABI_FP_DOUBLE: | |
16446 | printf (_("Hard float (double precision)\n")); | |
16447 | break; | |
16448 | case Val_GNU_MIPS_ABI_FP_SINGLE: | |
16449 | printf (_("Hard float (single precision)\n")); | |
16450 | break; | |
16451 | case Val_GNU_MIPS_ABI_FP_SOFT: | |
16452 | printf (_("Soft float\n")); | |
16453 | break; | |
16454 | case Val_GNU_MIPS_ABI_FP_OLD_64: | |
16455 | printf (_("Hard float (MIPS32r2 64-bit FPU 12 callee-saved)\n")); | |
16456 | break; | |
16457 | case Val_GNU_MIPS_ABI_FP_XX: | |
16458 | printf (_("Hard float (32-bit CPU, Any FPU)\n")); | |
16459 | break; | |
16460 | case Val_GNU_MIPS_ABI_FP_64: | |
16461 | printf (_("Hard float (32-bit CPU, 64-bit FPU)\n")); | |
16462 | break; | |
16463 | case Val_GNU_MIPS_ABI_FP_64A: | |
16464 | printf (_("Hard float compat (32-bit CPU, 64-bit FPU)\n")); | |
16465 | break; | |
16466 | case Val_GNU_MIPS_ABI_FP_NAN2008: | |
16467 | printf (_("NaN 2008 compatibility\n")); | |
16468 | break; | |
16469 | default: | |
16470 | printf ("??? (%d)\n", val); | |
16471 | break; | |
16472 | } | |
16473 | } | |
16474 | ||
16475 | static unsigned char * | |
16476 | display_mips_gnu_attribute (unsigned char * p, | |
16477 | unsigned int tag, | |
16478 | const unsigned char * const end) | |
16479 | { | |
16480 | if (tag == Tag_GNU_MIPS_ABI_FP) | |
16481 | { | |
16482 | unsigned int val; | |
16483 | ||
16484 | printf (" Tag_GNU_MIPS_ABI_FP: "); | |
16485 | READ_ULEB (val, p, end); | |
16486 | print_mips_fp_abi_value (val); | |
16487 | return p; | |
16488 | } | |
16489 | ||
16490 | if (tag == Tag_GNU_MIPS_ABI_MSA) | |
16491 | { | |
16492 | unsigned int val; | |
16493 | ||
16494 | printf (" Tag_GNU_MIPS_ABI_MSA: "); | |
16495 | READ_ULEB (val, p, end); | |
16496 | ||
16497 | switch (val) | |
16498 | { | |
16499 | case Val_GNU_MIPS_ABI_MSA_ANY: | |
16500 | printf (_("Any MSA or not\n")); | |
16501 | break; | |
16502 | case Val_GNU_MIPS_ABI_MSA_128: | |
16503 | printf (_("128-bit MSA\n")); | |
16504 | break; | |
16505 | default: | |
16506 | printf ("??? (%d)\n", val); | |
16507 | break; | |
16508 | } | |
16509 | return p; | |
16510 | } | |
16511 | ||
16512 | return display_tag_value (tag & 1, p, end); | |
16513 | } | |
16514 | ||
16515 | static unsigned char * | |
16516 | display_tic6x_attribute (unsigned char * p, | |
16517 | const unsigned char * const end) | |
16518 | { | |
16519 | unsigned int tag; | |
16520 | unsigned int val; | |
16521 | ||
16522 | READ_ULEB (tag, p, end); | |
16523 | ||
16524 | switch (tag) | |
16525 | { | |
16526 | case Tag_ISA: | |
16527 | printf (" Tag_ISA: "); | |
16528 | READ_ULEB (val, p, end); | |
16529 | ||
16530 | switch (val) | |
16531 | { | |
16532 | case C6XABI_Tag_ISA_none: | |
16533 | printf (_("None\n")); | |
16534 | break; | |
16535 | case C6XABI_Tag_ISA_C62X: | |
16536 | printf ("C62x\n"); | |
16537 | break; | |
16538 | case C6XABI_Tag_ISA_C67X: | |
16539 | printf ("C67x\n"); | |
16540 | break; | |
16541 | case C6XABI_Tag_ISA_C67XP: | |
16542 | printf ("C67x+\n"); | |
16543 | break; | |
16544 | case C6XABI_Tag_ISA_C64X: | |
16545 | printf ("C64x\n"); | |
16546 | break; | |
16547 | case C6XABI_Tag_ISA_C64XP: | |
16548 | printf ("C64x+\n"); | |
16549 | break; | |
16550 | case C6XABI_Tag_ISA_C674X: | |
16551 | printf ("C674x\n"); | |
16552 | break; | |
16553 | default: | |
16554 | printf ("??? (%d)\n", val); | |
16555 | break; | |
16556 | } | |
16557 | return p; | |
16558 | ||
16559 | case Tag_ABI_wchar_t: | |
16560 | printf (" Tag_ABI_wchar_t: "); | |
16561 | READ_ULEB (val, p, end); | |
16562 | switch (val) | |
16563 | { | |
16564 | case 0: | |
16565 | printf (_("Not used\n")); | |
16566 | break; | |
16567 | case 1: | |
16568 | printf (_("2 bytes\n")); | |
16569 | break; | |
16570 | case 2: | |
16571 | printf (_("4 bytes\n")); | |
16572 | break; | |
16573 | default: | |
16574 | printf ("??? (%d)\n", val); | |
16575 | break; | |
16576 | } | |
16577 | return p; | |
16578 | ||
16579 | case Tag_ABI_stack_align_needed: | |
16580 | printf (" Tag_ABI_stack_align_needed: "); | |
16581 | READ_ULEB (val, p, end); | |
16582 | switch (val) | |
16583 | { | |
16584 | case 0: | |
16585 | printf (_("8-byte\n")); | |
16586 | break; | |
16587 | case 1: | |
16588 | printf (_("16-byte\n")); | |
16589 | break; | |
16590 | default: | |
16591 | printf ("??? (%d)\n", val); | |
16592 | break; | |
16593 | } | |
16594 | return p; | |
16595 | ||
16596 | case Tag_ABI_stack_align_preserved: | |
16597 | READ_ULEB (val, p, end); | |
16598 | printf (" Tag_ABI_stack_align_preserved: "); | |
16599 | switch (val) | |
16600 | { | |
16601 | case 0: | |
16602 | printf (_("8-byte\n")); | |
16603 | break; | |
16604 | case 1: | |
16605 | printf (_("16-byte\n")); | |
16606 | break; | |
16607 | default: | |
16608 | printf ("??? (%d)\n", val); | |
16609 | break; | |
16610 | } | |
16611 | return p; | |
16612 | ||
16613 | case Tag_ABI_DSBT: | |
16614 | READ_ULEB (val, p, end); | |
16615 | printf (" Tag_ABI_DSBT: "); | |
16616 | switch (val) | |
16617 | { | |
16618 | case 0: | |
16619 | printf (_("DSBT addressing not used\n")); | |
16620 | break; | |
16621 | case 1: | |
16622 | printf (_("DSBT addressing used\n")); | |
16623 | break; | |
16624 | default: | |
16625 | printf ("??? (%d)\n", val); | |
16626 | break; | |
16627 | } | |
16628 | return p; | |
16629 | ||
16630 | case Tag_ABI_PID: | |
16631 | READ_ULEB (val, p, end); | |
16632 | printf (" Tag_ABI_PID: "); | |
16633 | switch (val) | |
16634 | { | |
16635 | case 0: | |
16636 | printf (_("Data addressing position-dependent\n")); | |
16637 | break; | |
16638 | case 1: | |
16639 | printf (_("Data addressing position-independent, GOT near DP\n")); | |
16640 | break; | |
16641 | case 2: | |
16642 | printf (_("Data addressing position-independent, GOT far from DP\n")); | |
16643 | break; | |
16644 | default: | |
16645 | printf ("??? (%d)\n", val); | |
16646 | break; | |
16647 | } | |
16648 | return p; | |
16649 | ||
16650 | case Tag_ABI_PIC: | |
16651 | READ_ULEB (val, p, end); | |
16652 | printf (" Tag_ABI_PIC: "); | |
16653 | switch (val) | |
16654 | { | |
16655 | case 0: | |
16656 | printf (_("Code addressing position-dependent\n")); | |
16657 | break; | |
16658 | case 1: | |
16659 | printf (_("Code addressing position-independent\n")); | |
16660 | break; | |
16661 | default: | |
16662 | printf ("??? (%d)\n", val); | |
16663 | break; | |
16664 | } | |
16665 | return p; | |
16666 | ||
16667 | case Tag_ABI_array_object_alignment: | |
16668 | READ_ULEB (val, p, end); | |
16669 | printf (" Tag_ABI_array_object_alignment: "); | |
16670 | switch (val) | |
16671 | { | |
16672 | case 0: | |
16673 | printf (_("8-byte\n")); | |
16674 | break; | |
16675 | case 1: | |
16676 | printf (_("4-byte\n")); | |
16677 | break; | |
16678 | case 2: | |
16679 | printf (_("16-byte\n")); | |
16680 | break; | |
16681 | default: | |
16682 | printf ("??? (%d)\n", val); | |
16683 | break; | |
16684 | } | |
16685 | return p; | |
16686 | ||
16687 | case Tag_ABI_array_object_align_expected: | |
16688 | READ_ULEB (val, p, end); | |
16689 | printf (" Tag_ABI_array_object_align_expected: "); | |
16690 | switch (val) | |
16691 | { | |
16692 | case 0: | |
16693 | printf (_("8-byte\n")); | |
16694 | break; | |
16695 | case 1: | |
16696 | printf (_("4-byte\n")); | |
16697 | break; | |
16698 | case 2: | |
16699 | printf (_("16-byte\n")); | |
16700 | break; | |
16701 | default: | |
16702 | printf ("??? (%d)\n", val); | |
16703 | break; | |
16704 | } | |
16705 | return p; | |
16706 | ||
16707 | case Tag_ABI_compatibility: | |
16708 | { | |
16709 | READ_ULEB (val, p, end); | |
16710 | printf (" Tag_ABI_compatibility: "); | |
16711 | printf (_("flag = %d, vendor = "), val); | |
16712 | if (p < end - 1) | |
16713 | { | |
16714 | size_t maxlen = (end - p) - 1; | |
16715 | ||
16716 | print_symbol ((int) maxlen, (const char *) p); | |
16717 | p += strnlen ((char *) p, maxlen) + 1; | |
16718 | } | |
16719 | else | |
16720 | { | |
16721 | printf (_("<corrupt>")); | |
16722 | p = (unsigned char *) end; | |
16723 | } | |
16724 | putchar ('\n'); | |
16725 | return p; | |
16726 | } | |
16727 | ||
16728 | case Tag_ABI_conformance: | |
16729 | { | |
16730 | printf (" Tag_ABI_conformance: \""); | |
16731 | if (p < end - 1) | |
16732 | { | |
16733 | size_t maxlen = (end - p) - 1; | |
16734 | ||
16735 | print_symbol ((int) maxlen, (const char *) p); | |
16736 | p += strnlen ((char *) p, maxlen) + 1; | |
16737 | } | |
16738 | else | |
16739 | { | |
16740 | printf (_("<corrupt>")); | |
16741 | p = (unsigned char *) end; | |
16742 | } | |
16743 | printf ("\"\n"); | |
16744 | return p; | |
16745 | } | |
16746 | } | |
16747 | ||
16748 | return display_tag_value (tag, p, end); | |
16749 | } | |
16750 | ||
16751 | static void | |
16752 | display_raw_attribute (unsigned char * p, unsigned char const * const end) | |
16753 | { | |
16754 | unsigned long addr = 0; | |
16755 | size_t bytes = end - p; | |
16756 | ||
16757 | assert (end >= p); | |
16758 | while (bytes) | |
16759 | { | |
16760 | int j; | |
16761 | int k; | |
16762 | int lbytes = (bytes > 16 ? 16 : bytes); | |
16763 | ||
16764 | printf (" 0x%8.8lx ", addr); | |
16765 | ||
16766 | for (j = 0; j < 16; j++) | |
16767 | { | |
16768 | if (j < lbytes) | |
16769 | printf ("%2.2x", p[j]); | |
16770 | else | |
16771 | printf (" "); | |
16772 | ||
16773 | if ((j & 3) == 3) | |
16774 | printf (" "); | |
16775 | } | |
16776 | ||
16777 | for (j = 0; j < lbytes; j++) | |
16778 | { | |
16779 | k = p[j]; | |
16780 | if (k >= ' ' && k < 0x7f) | |
16781 | printf ("%c", k); | |
16782 | else | |
16783 | printf ("."); | |
16784 | } | |
16785 | ||
16786 | putchar ('\n'); | |
16787 | ||
16788 | p += lbytes; | |
16789 | bytes -= lbytes; | |
16790 | addr += lbytes; | |
16791 | } | |
16792 | ||
16793 | putchar ('\n'); | |
16794 | } | |
16795 | ||
16796 | static unsigned char * | |
16797 | display_msp430_attribute (unsigned char * p, | |
16798 | const unsigned char * const end) | |
16799 | { | |
16800 | unsigned int val; | |
16801 | unsigned int tag; | |
16802 | ||
16803 | READ_ULEB (tag, p, end); | |
16804 | ||
16805 | switch (tag) | |
16806 | { | |
16807 | case OFBA_MSPABI_Tag_ISA: | |
16808 | printf (" Tag_ISA: "); | |
16809 | READ_ULEB (val, p, end); | |
16810 | switch (val) | |
16811 | { | |
16812 | case 0: printf (_("None\n")); break; | |
16813 | case 1: printf (_("MSP430\n")); break; | |
16814 | case 2: printf (_("MSP430X\n")); break; | |
16815 | default: printf ("??? (%d)\n", val); break; | |
16816 | } | |
16817 | break; | |
16818 | ||
16819 | case OFBA_MSPABI_Tag_Code_Model: | |
16820 | printf (" Tag_Code_Model: "); | |
16821 | READ_ULEB (val, p, end); | |
16822 | switch (val) | |
16823 | { | |
16824 | case 0: printf (_("None\n")); break; | |
16825 | case 1: printf (_("Small\n")); break; | |
16826 | case 2: printf (_("Large\n")); break; | |
16827 | default: printf ("??? (%d)\n", val); break; | |
16828 | } | |
16829 | break; | |
16830 | ||
16831 | case OFBA_MSPABI_Tag_Data_Model: | |
16832 | printf (" Tag_Data_Model: "); | |
16833 | READ_ULEB (val, p, end); | |
16834 | switch (val) | |
16835 | { | |
16836 | case 0: printf (_("None\n")); break; | |
16837 | case 1: printf (_("Small\n")); break; | |
16838 | case 2: printf (_("Large\n")); break; | |
16839 | case 3: printf (_("Restricted Large\n")); break; | |
16840 | default: printf ("??? (%d)\n", val); break; | |
16841 | } | |
16842 | break; | |
16843 | ||
16844 | default: | |
16845 | printf (_(" <unknown tag %d>: "), tag); | |
16846 | ||
16847 | if (tag & 1) | |
16848 | { | |
16849 | putchar ('"'); | |
16850 | if (p < end - 1) | |
16851 | { | |
16852 | size_t maxlen = (end - p) - 1; | |
16853 | ||
16854 | print_symbol ((int) maxlen, (const char *) p); | |
16855 | p += strnlen ((char *) p, maxlen) + 1; | |
16856 | } | |
16857 | else | |
16858 | { | |
16859 | printf (_("<corrupt>")); | |
16860 | p = (unsigned char *) end; | |
16861 | } | |
16862 | printf ("\"\n"); | |
16863 | } | |
16864 | else | |
16865 | { | |
16866 | READ_ULEB (val, p, end); | |
16867 | printf ("%d (0x%x)\n", val, val); | |
16868 | } | |
16869 | break; | |
16870 | } | |
16871 | ||
16872 | assert (p <= end); | |
16873 | return p; | |
16874 | } | |
16875 | ||
16876 | static unsigned char * | |
16877 | display_msp430_gnu_attribute (unsigned char * p, | |
16878 | unsigned int tag, | |
16879 | const unsigned char * const end) | |
16880 | { | |
16881 | if (tag == Tag_GNU_MSP430_Data_Region) | |
16882 | { | |
16883 | unsigned int val; | |
16884 | ||
16885 | printf (" Tag_GNU_MSP430_Data_Region: "); | |
16886 | READ_ULEB (val, p, end); | |
16887 | ||
16888 | switch (val) | |
16889 | { | |
16890 | case Val_GNU_MSP430_Data_Region_Any: | |
16891 | printf (_("Any Region\n")); | |
16892 | break; | |
16893 | case Val_GNU_MSP430_Data_Region_Lower: | |
16894 | printf (_("Lower Region Only\n")); | |
16895 | break; | |
16896 | default: | |
16897 | printf ("??? (%u)\n", val); | |
16898 | } | |
16899 | return p; | |
16900 | } | |
16901 | return display_tag_value (tag & 1, p, end); | |
16902 | } | |
16903 | ||
16904 | struct riscv_attr_tag_t { | |
16905 | const char *name; | |
16906 | unsigned int tag; | |
16907 | }; | |
16908 | ||
16909 | static struct riscv_attr_tag_t riscv_attr_tag[] = | |
16910 | { | |
16911 | #define T(tag) {"Tag_RISCV_" #tag, Tag_RISCV_##tag} | |
16912 | T(arch), | |
16913 | T(priv_spec), | |
16914 | T(priv_spec_minor), | |
16915 | T(priv_spec_revision), | |
16916 | T(unaligned_access), | |
16917 | T(stack_align), | |
16918 | #undef T | |
16919 | }; | |
16920 | ||
16921 | static unsigned char * | |
16922 | display_riscv_attribute (unsigned char *p, | |
16923 | const unsigned char * const end) | |
16924 | { | |
16925 | unsigned int val; | |
16926 | unsigned int tag; | |
16927 | struct riscv_attr_tag_t *attr = NULL; | |
16928 | unsigned i; | |
16929 | ||
16930 | READ_ULEB (tag, p, end); | |
16931 | ||
16932 | /* Find the name of attribute. */ | |
16933 | for (i = 0; i < ARRAY_SIZE (riscv_attr_tag); i++) | |
16934 | { | |
16935 | if (riscv_attr_tag[i].tag == tag) | |
16936 | { | |
16937 | attr = &riscv_attr_tag[i]; | |
16938 | break; | |
16939 | } | |
16940 | } | |
16941 | ||
16942 | if (attr) | |
16943 | printf (" %s: ", attr->name); | |
16944 | else | |
16945 | return display_tag_value (tag, p, end); | |
16946 | ||
16947 | switch (tag) | |
16948 | { | |
16949 | case Tag_RISCV_priv_spec: | |
16950 | case Tag_RISCV_priv_spec_minor: | |
16951 | case Tag_RISCV_priv_spec_revision: | |
16952 | READ_ULEB (val, p, end); | |
16953 | printf (_("%u\n"), val); | |
16954 | break; | |
16955 | case Tag_RISCV_unaligned_access: | |
16956 | READ_ULEB (val, p, end); | |
16957 | switch (val) | |
16958 | { | |
16959 | case 0: | |
16960 | printf (_("No unaligned access\n")); | |
16961 | break; | |
16962 | case 1: | |
16963 | printf (_("Unaligned access\n")); | |
16964 | break; | |
16965 | } | |
16966 | break; | |
16967 | case Tag_RISCV_stack_align: | |
16968 | READ_ULEB (val, p, end); | |
16969 | printf (_("%u-bytes\n"), val); | |
16970 | break; | |
16971 | case Tag_RISCV_arch: | |
16972 | p = display_tag_value (-1, p, end); | |
16973 | break; | |
16974 | default: | |
16975 | return display_tag_value (tag, p, end); | |
16976 | } | |
16977 | ||
16978 | return p; | |
16979 | } | |
16980 | ||
16981 | static unsigned char * | |
16982 | display_csky_attribute (unsigned char * p, | |
16983 | const unsigned char * const end) | |
16984 | { | |
16985 | unsigned int tag; | |
16986 | unsigned int val; | |
16987 | READ_ULEB (tag, p, end); | |
16988 | ||
16989 | if (tag >= Tag_CSKY_MAX) | |
16990 | { | |
16991 | return display_tag_value (-1, p, end); | |
16992 | } | |
16993 | ||
16994 | switch (tag) | |
16995 | { | |
16996 | case Tag_CSKY_ARCH_NAME: | |
16997 | printf (" Tag_CSKY_ARCH_NAME:\t\t"); | |
16998 | return display_tag_value (-1, p, end); | |
16999 | case Tag_CSKY_CPU_NAME: | |
17000 | printf (" Tag_CSKY_CPU_NAME:\t\t"); | |
17001 | return display_tag_value (-1, p, end); | |
17002 | ||
17003 | case Tag_CSKY_ISA_FLAGS: | |
17004 | printf (" Tag_CSKY_ISA_FLAGS:\t\t"); | |
17005 | return display_tag_value (0, p, end); | |
17006 | case Tag_CSKY_ISA_EXT_FLAGS: | |
17007 | printf (" Tag_CSKY_ISA_EXT_FLAGS:\t"); | |
17008 | return display_tag_value (0, p, end); | |
17009 | ||
17010 | case Tag_CSKY_DSP_VERSION: | |
17011 | printf (" Tag_CSKY_DSP_VERSION:\t\t"); | |
17012 | READ_ULEB (val, p, end); | |
17013 | if (val == VAL_CSKY_DSP_VERSION_EXTENSION) | |
17014 | printf ("DSP Extension\n"); | |
17015 | else if (val == VAL_CSKY_DSP_VERSION_2) | |
17016 | printf ("DSP 2.0\n"); | |
17017 | break; | |
17018 | ||
17019 | case Tag_CSKY_VDSP_VERSION: | |
17020 | printf (" Tag_CSKY_VDSP_VERSION:\t"); | |
17021 | READ_ULEB (val, p, end); | |
17022 | printf ("VDSP Version %d\n", val); | |
17023 | break; | |
17024 | ||
17025 | case Tag_CSKY_FPU_VERSION: | |
17026 | printf (" Tag_CSKY_FPU_VERSION:\t\t"); | |
17027 | READ_ULEB (val, p, end); | |
17028 | if (val == VAL_CSKY_FPU_VERSION_1) | |
17029 | printf ("ABIV1 FPU Version 1\n"); | |
17030 | else if (val == VAL_CSKY_FPU_VERSION_2) | |
17031 | printf ("FPU Version 2\n"); | |
17032 | break; | |
17033 | ||
17034 | case Tag_CSKY_FPU_ABI: | |
17035 | printf (" Tag_CSKY_FPU_ABI:\t\t"); | |
17036 | READ_ULEB (val, p, end); | |
17037 | if (val == VAL_CSKY_FPU_ABI_HARD) | |
17038 | printf ("Hard\n"); | |
17039 | else if (val == VAL_CSKY_FPU_ABI_SOFTFP) | |
17040 | printf ("SoftFP\n"); | |
17041 | else if (val == VAL_CSKY_FPU_ABI_SOFT) | |
17042 | printf ("Soft\n"); | |
17043 | break; | |
17044 | case Tag_CSKY_FPU_ROUNDING: | |
17045 | READ_ULEB (val, p, end); | |
17046 | if (val == 1) { | |
17047 | printf (" Tag_CSKY_FPU_ROUNDING:\t"); | |
17048 | printf ("Needed\n"); | |
17049 | } | |
17050 | break; | |
17051 | case Tag_CSKY_FPU_DENORMAL: | |
17052 | READ_ULEB (val, p, end); | |
17053 | if (val == 1) { | |
17054 | printf (" Tag_CSKY_FPU_DENORMAL:\t"); | |
17055 | printf ("Needed\n"); | |
17056 | } | |
17057 | break; | |
17058 | case Tag_CSKY_FPU_Exception: | |
17059 | READ_ULEB (val, p, end); | |
17060 | if (val == 1) { | |
17061 | printf (" Tag_CSKY_FPU_Exception:\t"); | |
17062 | printf ("Needed\n"); | |
17063 | } | |
17064 | break; | |
17065 | case Tag_CSKY_FPU_NUMBER_MODULE: | |
17066 | printf (" Tag_CSKY_FPU_NUMBER_MODULE:\t"); | |
17067 | return display_tag_value (-1, p, end); | |
17068 | case Tag_CSKY_FPU_HARDFP: | |
17069 | printf (" Tag_CSKY_FPU_HARDFP:\t\t"); | |
17070 | READ_ULEB (val, p, end); | |
17071 | if (val & VAL_CSKY_FPU_HARDFP_HALF) | |
17072 | printf (" Half"); | |
17073 | if (val & VAL_CSKY_FPU_HARDFP_SINGLE) | |
17074 | printf (" Single"); | |
17075 | if (val & VAL_CSKY_FPU_HARDFP_DOUBLE) | |
17076 | printf (" Double"); | |
17077 | printf ("\n"); | |
17078 | break; | |
17079 | default: | |
17080 | return display_tag_value (tag, p, end); | |
17081 | } | |
17082 | return p; | |
17083 | } | |
17084 | ||
17085 | static bfd_boolean | |
17086 | process_attributes (Filedata * filedata, | |
17087 | const char * public_name, | |
17088 | unsigned int proc_type, | |
17089 | unsigned char * (* display_pub_attribute) (unsigned char *, const unsigned char * const), | |
17090 | unsigned char * (* display_proc_gnu_attribute) (unsigned char *, unsigned int, const unsigned char * const)) | |
17091 | { | |
17092 | Elf_Internal_Shdr * sect; | |
17093 | unsigned i; | |
17094 | bfd_boolean res = TRUE; | |
17095 | ||
17096 | /* Find the section header so that we get the size. */ | |
17097 | for (i = 0, sect = filedata->section_headers; | |
17098 | i < filedata->file_header.e_shnum; | |
17099 | i++, sect++) | |
17100 | { | |
17101 | unsigned char * contents; | |
17102 | unsigned char * p; | |
17103 | ||
17104 | if (sect->sh_type != proc_type && sect->sh_type != SHT_GNU_ATTRIBUTES) | |
17105 | continue; | |
17106 | ||
17107 | contents = (unsigned char *) get_data (NULL, filedata, sect->sh_offset, 1, | |
17108 | sect->sh_size, _("attributes")); | |
17109 | if (contents == NULL) | |
17110 | { | |
17111 | res = FALSE; | |
17112 | continue; | |
17113 | } | |
17114 | ||
17115 | p = contents; | |
17116 | /* The first character is the version of the attributes. | |
17117 | Currently only version 1, (aka 'A') is recognised here. */ | |
17118 | if (*p != 'A') | |
17119 | { | |
17120 | printf (_("Unknown attributes version '%c'(%d) - expecting 'A'\n"), *p, *p); | |
17121 | res = FALSE; | |
17122 | } | |
17123 | else | |
17124 | { | |
17125 | bfd_vma section_len; | |
17126 | ||
17127 | section_len = sect->sh_size - 1; | |
17128 | p++; | |
17129 | ||
17130 | while (section_len > 0) | |
17131 | { | |
17132 | bfd_vma attr_len; | |
17133 | unsigned int namelen; | |
17134 | bfd_boolean public_section; | |
17135 | bfd_boolean gnu_section; | |
17136 | ||
17137 | if (section_len <= 4) | |
17138 | { | |
17139 | error (_("Tag section ends prematurely\n")); | |
17140 | res = FALSE; | |
17141 | break; | |
17142 | } | |
17143 | attr_len = byte_get (p, 4); | |
17144 | p += 4; | |
17145 | ||
17146 | if (attr_len > section_len) | |
17147 | { | |
17148 | error (_("Bad attribute length (%u > %u)\n"), | |
17149 | (unsigned) attr_len, (unsigned) section_len); | |
17150 | attr_len = section_len; | |
17151 | res = FALSE; | |
17152 | } | |
17153 | /* PR 17531: file: 001-101425-0.004 */ | |
17154 | else if (attr_len < 5) | |
17155 | { | |
17156 | error (_("Attribute length of %u is too small\n"), (unsigned) attr_len); | |
17157 | res = FALSE; | |
17158 | break; | |
17159 | } | |
17160 | ||
17161 | section_len -= attr_len; | |
17162 | attr_len -= 4; | |
17163 | ||
17164 | namelen = strnlen ((char *) p, attr_len) + 1; | |
17165 | if (namelen == 0 || namelen >= attr_len) | |
17166 | { | |
17167 | error (_("Corrupt attribute section name\n")); | |
17168 | res = FALSE; | |
17169 | break; | |
17170 | } | |
17171 | ||
17172 | printf (_("Attribute Section: ")); | |
17173 | print_symbol (INT_MAX, (const char *) p); | |
17174 | putchar ('\n'); | |
17175 | ||
17176 | if (public_name && streq ((char *) p, public_name)) | |
17177 | public_section = TRUE; | |
17178 | else | |
17179 | public_section = FALSE; | |
17180 | ||
17181 | if (streq ((char *) p, "gnu")) | |
17182 | gnu_section = TRUE; | |
17183 | else | |
17184 | gnu_section = FALSE; | |
17185 | ||
17186 | p += namelen; | |
17187 | attr_len -= namelen; | |
17188 | ||
17189 | while (attr_len > 0 && p < contents + sect->sh_size) | |
17190 | { | |
17191 | int tag; | |
17192 | unsigned int val; | |
17193 | bfd_vma size; | |
17194 | unsigned char * end; | |
17195 | ||
17196 | /* PR binutils/17531: Safe handling of corrupt files. */ | |
17197 | if (attr_len < 6) | |
17198 | { | |
17199 | error (_("Unused bytes at end of section\n")); | |
17200 | res = FALSE; | |
17201 | section_len = 0; | |
17202 | break; | |
17203 | } | |
17204 | ||
17205 | tag = *(p++); | |
17206 | size = byte_get (p, 4); | |
17207 | if (size > attr_len) | |
17208 | { | |
17209 | error (_("Bad subsection length (%u > %u)\n"), | |
17210 | (unsigned) size, (unsigned) attr_len); | |
17211 | res = FALSE; | |
17212 | size = attr_len; | |
17213 | } | |
17214 | /* PR binutils/17531: Safe handling of corrupt files. */ | |
17215 | if (size < 6) | |
17216 | { | |
17217 | error (_("Bad subsection length (%u < 6)\n"), | |
17218 | (unsigned) size); | |
17219 | res = FALSE; | |
17220 | section_len = 0; | |
17221 | break; | |
17222 | } | |
17223 | ||
17224 | attr_len -= size; | |
17225 | end = p + size - 1; | |
17226 | assert (end <= contents + sect->sh_size); | |
17227 | p += 4; | |
17228 | ||
17229 | switch (tag) | |
17230 | { | |
17231 | case 1: | |
17232 | printf (_("File Attributes\n")); | |
17233 | break; | |
17234 | case 2: | |
17235 | printf (_("Section Attributes:")); | |
17236 | goto do_numlist; | |
17237 | case 3: | |
17238 | printf (_("Symbol Attributes:")); | |
17239 | /* Fall through. */ | |
17240 | do_numlist: | |
17241 | for (;;) | |
17242 | { | |
17243 | READ_ULEB (val, p, end); | |
17244 | if (val == 0) | |
17245 | break; | |
17246 | printf (" %d", val); | |
17247 | } | |
17248 | printf ("\n"); | |
17249 | break; | |
17250 | default: | |
17251 | printf (_("Unknown tag: %d\n"), tag); | |
17252 | public_section = FALSE; | |
17253 | break; | |
17254 | } | |
17255 | ||
17256 | if (public_section && display_pub_attribute != NULL) | |
17257 | { | |
17258 | while (p < end) | |
17259 | p = display_pub_attribute (p, end); | |
17260 | assert (p == end); | |
17261 | } | |
17262 | else if (gnu_section && display_proc_gnu_attribute != NULL) | |
17263 | { | |
17264 | while (p < end) | |
17265 | p = display_gnu_attribute (p, | |
17266 | display_proc_gnu_attribute, | |
17267 | end); | |
17268 | assert (p == end); | |
17269 | } | |
17270 | else if (p < end) | |
17271 | { | |
17272 | printf (_(" Unknown attribute:\n")); | |
17273 | display_raw_attribute (p, end); | |
17274 | p = end; | |
17275 | } | |
17276 | else | |
17277 | attr_len = 0; | |
17278 | } | |
17279 | } | |
17280 | } | |
17281 | ||
17282 | free (contents); | |
17283 | } | |
17284 | ||
17285 | return res; | |
17286 | } | |
17287 | ||
17288 | /* DATA points to the contents of a MIPS GOT that starts at VMA PLTGOT. | |
17289 | Print the Address, Access and Initial fields of an entry at VMA ADDR | |
17290 | and return the VMA of the next entry, or -1 if there was a problem. | |
17291 | Does not read from DATA_END or beyond. */ | |
17292 | ||
17293 | static bfd_vma | |
17294 | print_mips_got_entry (unsigned char * data, bfd_vma pltgot, bfd_vma addr, | |
17295 | unsigned char * data_end) | |
17296 | { | |
17297 | printf (" "); | |
17298 | print_vma (addr, LONG_HEX); | |
17299 | printf (" "); | |
17300 | if (addr < pltgot + 0xfff0) | |
17301 | printf ("%6d(gp)", (int) (addr - pltgot - 0x7ff0)); | |
17302 | else | |
17303 | printf ("%10s", ""); | |
17304 | printf (" "); | |
17305 | if (data == NULL) | |
17306 | printf ("%*s", is_32bit_elf ? 8 : 16, _("<unknown>")); | |
17307 | else | |
17308 | { | |
17309 | bfd_vma entry; | |
17310 | unsigned char * from = data + addr - pltgot; | |
17311 | ||
17312 | if (from + (is_32bit_elf ? 4 : 8) > data_end) | |
17313 | { | |
17314 | warn (_("MIPS GOT entry extends beyond the end of available data\n")); | |
17315 | printf ("%*s", is_32bit_elf ? 8 : 16, _("<corrupt>")); | |
17316 | return (bfd_vma) -1; | |
17317 | } | |
17318 | else | |
17319 | { | |
17320 | entry = byte_get (data + addr - pltgot, is_32bit_elf ? 4 : 8); | |
17321 | print_vma (entry, LONG_HEX); | |
17322 | } | |
17323 | } | |
17324 | return addr + (is_32bit_elf ? 4 : 8); | |
17325 | } | |
17326 | ||
17327 | /* DATA points to the contents of a MIPS PLT GOT that starts at VMA | |
17328 | PLTGOT. Print the Address and Initial fields of an entry at VMA | |
17329 | ADDR and return the VMA of the next entry. */ | |
17330 | ||
17331 | static bfd_vma | |
17332 | print_mips_pltgot_entry (unsigned char * data, bfd_vma pltgot, bfd_vma addr) | |
17333 | { | |
17334 | printf (" "); | |
17335 | print_vma (addr, LONG_HEX); | |
17336 | printf (" "); | |
17337 | if (data == NULL) | |
17338 | printf ("%*s", is_32bit_elf ? 8 : 16, _("<unknown>")); | |
17339 | else | |
17340 | { | |
17341 | bfd_vma entry; | |
17342 | ||
17343 | entry = byte_get (data + addr - pltgot, is_32bit_elf ? 4 : 8); | |
17344 | print_vma (entry, LONG_HEX); | |
17345 | } | |
17346 | return addr + (is_32bit_elf ? 4 : 8); | |
17347 | } | |
17348 | ||
17349 | static void | |
17350 | print_mips_ases (unsigned int mask) | |
17351 | { | |
17352 | if (mask & AFL_ASE_DSP) | |
17353 | fputs ("\n\tDSP ASE", stdout); | |
17354 | if (mask & AFL_ASE_DSPR2) | |
17355 | fputs ("\n\tDSP R2 ASE", stdout); | |
17356 | if (mask & AFL_ASE_DSPR3) | |
17357 | fputs ("\n\tDSP R3 ASE", stdout); | |
17358 | if (mask & AFL_ASE_EVA) | |
17359 | fputs ("\n\tEnhanced VA Scheme", stdout); | |
17360 | if (mask & AFL_ASE_MCU) | |
17361 | fputs ("\n\tMCU (MicroController) ASE", stdout); | |
17362 | if (mask & AFL_ASE_MDMX) | |
17363 | fputs ("\n\tMDMX ASE", stdout); | |
17364 | if (mask & AFL_ASE_MIPS3D) | |
17365 | fputs ("\n\tMIPS-3D ASE", stdout); | |
17366 | if (mask & AFL_ASE_MT) | |
17367 | fputs ("\n\tMT ASE", stdout); | |
17368 | if (mask & AFL_ASE_SMARTMIPS) | |
17369 | fputs ("\n\tSmartMIPS ASE", stdout); | |
17370 | if (mask & AFL_ASE_VIRT) | |
17371 | fputs ("\n\tVZ ASE", stdout); | |
17372 | if (mask & AFL_ASE_MSA) | |
17373 | fputs ("\n\tMSA ASE", stdout); | |
17374 | if (mask & AFL_ASE_MIPS16) | |
17375 | fputs ("\n\tMIPS16 ASE", stdout); | |
17376 | if (mask & AFL_ASE_MICROMIPS) | |
17377 | fputs ("\n\tMICROMIPS ASE", stdout); | |
17378 | if (mask & AFL_ASE_XPA) | |
17379 | fputs ("\n\tXPA ASE", stdout); | |
17380 | if (mask & AFL_ASE_MIPS16E2) | |
17381 | fputs ("\n\tMIPS16e2 ASE", stdout); | |
17382 | if (mask & AFL_ASE_CRC) | |
17383 | fputs ("\n\tCRC ASE", stdout); | |
17384 | if (mask & AFL_ASE_GINV) | |
17385 | fputs ("\n\tGINV ASE", stdout); | |
17386 | if (mask & AFL_ASE_LOONGSON_MMI) | |
17387 | fputs ("\n\tLoongson MMI ASE", stdout); | |
17388 | if (mask & AFL_ASE_LOONGSON_CAM) | |
17389 | fputs ("\n\tLoongson CAM ASE", stdout); | |
17390 | if (mask & AFL_ASE_LOONGSON_EXT) | |
17391 | fputs ("\n\tLoongson EXT ASE", stdout); | |
17392 | if (mask & AFL_ASE_LOONGSON_EXT2) | |
17393 | fputs ("\n\tLoongson EXT2 ASE", stdout); | |
17394 | if (mask == 0) | |
17395 | fprintf (stdout, "\n\t%s", _("None")); | |
17396 | else if ((mask & ~AFL_ASE_MASK) != 0) | |
17397 | fprintf (stdout, "\n\t%s (%x)", _("Unknown"), mask & ~AFL_ASE_MASK); | |
17398 | } | |
17399 | ||
17400 | static void | |
17401 | print_mips_isa_ext (unsigned int isa_ext) | |
17402 | { | |
17403 | switch (isa_ext) | |
17404 | { | |
17405 | case 0: | |
17406 | fputs (_("None"), stdout); | |
17407 | break; | |
17408 | case AFL_EXT_XLR: | |
17409 | fputs ("RMI XLR", stdout); | |
17410 | break; | |
17411 | case AFL_EXT_OCTEON3: | |
17412 | fputs ("Cavium Networks Octeon3", stdout); | |
17413 | break; | |
17414 | case AFL_EXT_OCTEON2: | |
17415 | fputs ("Cavium Networks Octeon2", stdout); | |
17416 | break; | |
17417 | case AFL_EXT_OCTEONP: | |
17418 | fputs ("Cavium Networks OcteonP", stdout); | |
17419 | break; | |
17420 | case AFL_EXT_OCTEON: | |
17421 | fputs ("Cavium Networks Octeon", stdout); | |
17422 | break; | |
17423 | case AFL_EXT_5900: | |
17424 | fputs ("Toshiba R5900", stdout); | |
17425 | break; | |
17426 | case AFL_EXT_4650: | |
17427 | fputs ("MIPS R4650", stdout); | |
17428 | break; | |
17429 | case AFL_EXT_4010: | |
17430 | fputs ("LSI R4010", stdout); | |
17431 | break; | |
17432 | case AFL_EXT_4100: | |
17433 | fputs ("NEC VR4100", stdout); | |
17434 | break; | |
17435 | case AFL_EXT_3900: | |
17436 | fputs ("Toshiba R3900", stdout); | |
17437 | break; | |
17438 | case AFL_EXT_10000: | |
17439 | fputs ("MIPS R10000", stdout); | |
17440 | break; | |
17441 | case AFL_EXT_SB1: | |
17442 | fputs ("Broadcom SB-1", stdout); | |
17443 | break; | |
17444 | case AFL_EXT_4111: | |
17445 | fputs ("NEC VR4111/VR4181", stdout); | |
17446 | break; | |
17447 | case AFL_EXT_4120: | |
17448 | fputs ("NEC VR4120", stdout); | |
17449 | break; | |
17450 | case AFL_EXT_5400: | |
17451 | fputs ("NEC VR5400", stdout); | |
17452 | break; | |
17453 | case AFL_EXT_5500: | |
17454 | fputs ("NEC VR5500", stdout); | |
17455 | break; | |
17456 | case AFL_EXT_LOONGSON_2E: | |
17457 | fputs ("ST Microelectronics Loongson 2E", stdout); | |
17458 | break; | |
17459 | case AFL_EXT_LOONGSON_2F: | |
17460 | fputs ("ST Microelectronics Loongson 2F", stdout); | |
17461 | break; | |
17462 | case AFL_EXT_INTERAPTIV_MR2: | |
17463 | fputs ("Imagination interAptiv MR2", stdout); | |
17464 | break; | |
17465 | default: | |
17466 | fprintf (stdout, "%s (%d)", _("Unknown"), isa_ext); | |
17467 | } | |
17468 | } | |
17469 | ||
17470 | static signed int | |
17471 | get_mips_reg_size (int reg_size) | |
17472 | { | |
17473 | return (reg_size == AFL_REG_NONE) ? 0 | |
17474 | : (reg_size == AFL_REG_32) ? 32 | |
17475 | : (reg_size == AFL_REG_64) ? 64 | |
17476 | : (reg_size == AFL_REG_128) ? 128 | |
17477 | : -1; | |
17478 | } | |
17479 | ||
17480 | static bfd_boolean | |
17481 | process_mips_specific (Filedata * filedata) | |
17482 | { | |
17483 | Elf_Internal_Dyn * entry; | |
17484 | Elf_Internal_Shdr *sect = NULL; | |
17485 | size_t liblist_offset = 0; | |
17486 | size_t liblistno = 0; | |
17487 | size_t conflictsno = 0; | |
17488 | size_t options_offset = 0; | |
17489 | size_t conflicts_offset = 0; | |
17490 | size_t pltrelsz = 0; | |
17491 | size_t pltrel = 0; | |
17492 | bfd_vma pltgot = 0; | |
17493 | bfd_vma mips_pltgot = 0; | |
17494 | bfd_vma jmprel = 0; | |
17495 | bfd_vma local_gotno = 0; | |
17496 | bfd_vma gotsym = 0; | |
17497 | bfd_vma symtabno = 0; | |
17498 | bfd_boolean res = TRUE; | |
17499 | ||
17500 | if (! process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL, | |
17501 | display_mips_gnu_attribute)) | |
17502 | res = FALSE; | |
17503 | ||
17504 | sect = find_section (filedata, ".MIPS.abiflags"); | |
17505 | ||
17506 | if (sect != NULL) | |
17507 | { | |
17508 | Elf_External_ABIFlags_v0 *abiflags_ext; | |
17509 | Elf_Internal_ABIFlags_v0 abiflags_in; | |
17510 | ||
17511 | if (sizeof (Elf_External_ABIFlags_v0) != sect->sh_size) | |
17512 | { | |
17513 | error (_("Corrupt MIPS ABI Flags section.\n")); | |
17514 | res = FALSE; | |
17515 | } | |
17516 | else | |
17517 | { | |
17518 | abiflags_ext = get_data (NULL, filedata, sect->sh_offset, 1, | |
17519 | sect->sh_size, _("MIPS ABI Flags section")); | |
17520 | if (abiflags_ext) | |
17521 | { | |
17522 | abiflags_in.version = BYTE_GET (abiflags_ext->version); | |
17523 | abiflags_in.isa_level = BYTE_GET (abiflags_ext->isa_level); | |
17524 | abiflags_in.isa_rev = BYTE_GET (abiflags_ext->isa_rev); | |
17525 | abiflags_in.gpr_size = BYTE_GET (abiflags_ext->gpr_size); | |
17526 | abiflags_in.cpr1_size = BYTE_GET (abiflags_ext->cpr1_size); | |
17527 | abiflags_in.cpr2_size = BYTE_GET (abiflags_ext->cpr2_size); | |
17528 | abiflags_in.fp_abi = BYTE_GET (abiflags_ext->fp_abi); | |
17529 | abiflags_in.isa_ext = BYTE_GET (abiflags_ext->isa_ext); | |
17530 | abiflags_in.ases = BYTE_GET (abiflags_ext->ases); | |
17531 | abiflags_in.flags1 = BYTE_GET (abiflags_ext->flags1); | |
17532 | abiflags_in.flags2 = BYTE_GET (abiflags_ext->flags2); | |
17533 | ||
17534 | printf ("\nMIPS ABI Flags Version: %d\n", abiflags_in.version); | |
17535 | printf ("\nISA: MIPS%d", abiflags_in.isa_level); | |
17536 | if (abiflags_in.isa_rev > 1) | |
17537 | printf ("r%d", abiflags_in.isa_rev); | |
17538 | printf ("\nGPR size: %d", | |
17539 | get_mips_reg_size (abiflags_in.gpr_size)); | |
17540 | printf ("\nCPR1 size: %d", | |
17541 | get_mips_reg_size (abiflags_in.cpr1_size)); | |
17542 | printf ("\nCPR2 size: %d", | |
17543 | get_mips_reg_size (abiflags_in.cpr2_size)); | |
17544 | fputs ("\nFP ABI: ", stdout); | |
17545 | print_mips_fp_abi_value (abiflags_in.fp_abi); | |
17546 | fputs ("ISA Extension: ", stdout); | |
17547 | print_mips_isa_ext (abiflags_in.isa_ext); | |
17548 | fputs ("\nASEs:", stdout); | |
17549 | print_mips_ases (abiflags_in.ases); | |
17550 | printf ("\nFLAGS 1: %8.8lx", abiflags_in.flags1); | |
17551 | printf ("\nFLAGS 2: %8.8lx", abiflags_in.flags2); | |
17552 | fputc ('\n', stdout); | |
17553 | free (abiflags_ext); | |
17554 | } | |
17555 | } | |
17556 | } | |
17557 | ||
17558 | /* We have a lot of special sections. Thanks SGI! */ | |
17559 | if (filedata->dynamic_section == NULL) | |
17560 | { | |
17561 | /* No dynamic information available. See if there is static GOT. */ | |
17562 | sect = find_section (filedata, ".got"); | |
17563 | if (sect != NULL) | |
17564 | { | |
17565 | unsigned char *data_end; | |
17566 | unsigned char *data; | |
17567 | bfd_vma ent, end; | |
17568 | int addr_size; | |
17569 | ||
17570 | pltgot = sect->sh_addr; | |
17571 | ||
17572 | ent = pltgot; | |
17573 | addr_size = (is_32bit_elf ? 4 : 8); | |
17574 | end = pltgot + sect->sh_size; | |
17575 | ||
17576 | data = (unsigned char *) get_data (NULL, filedata, sect->sh_offset, | |
17577 | end - pltgot, 1, | |
17578 | _("Global Offset Table data")); | |
17579 | /* PR 12855: Null data is handled gracefully throughout. */ | |
17580 | data_end = data + (end - pltgot); | |
17581 | ||
17582 | printf (_("\nStatic GOT:\n")); | |
17583 | printf (_(" Canonical gp value: ")); | |
17584 | print_vma (ent + 0x7ff0, LONG_HEX); | |
17585 | printf ("\n\n"); | |
17586 | ||
17587 | /* In a dynamic binary GOT[0] is reserved for the dynamic | |
17588 | loader to store the lazy resolver pointer, however in | |
17589 | a static binary it may well have been omitted and GOT | |
17590 | reduced to a table of addresses. | |
17591 | PR 21344: Check for the entry being fully available | |
17592 | before fetching it. */ | |
17593 | if (data | |
17594 | && data + ent - pltgot + addr_size <= data_end | |
17595 | && byte_get (data + ent - pltgot, addr_size) == 0) | |
17596 | { | |
17597 | printf (_(" Reserved entries:\n")); | |
17598 | printf (_(" %*s %10s %*s\n"), | |
17599 | addr_size * 2, _("Address"), _("Access"), | |
17600 | addr_size * 2, _("Value")); | |
17601 | ent = print_mips_got_entry (data, pltgot, ent, data_end); | |
17602 | printf ("\n"); | |
17603 | if (ent == (bfd_vma) -1) | |
17604 | goto sgot_print_fail; | |
17605 | ||
17606 | /* Check for the MSB of GOT[1] being set, identifying a | |
17607 | GNU object. This entry will be used by some runtime | |
17608 | loaders, to store the module pointer. Otherwise this | |
17609 | is an ordinary local entry. | |
17610 | PR 21344: Check for the entry being fully available | |
17611 | before fetching it. */ | |
17612 | if (data | |
17613 | && data + ent - pltgot + addr_size <= data_end | |
17614 | && (byte_get (data + ent - pltgot, addr_size) | |
17615 | >> (addr_size * 8 - 1)) != 0) | |
17616 | { | |
17617 | ent = print_mips_got_entry (data, pltgot, ent, data_end); | |
17618 | printf ("\n"); | |
17619 | if (ent == (bfd_vma) -1) | |
17620 | goto sgot_print_fail; | |
17621 | } | |
17622 | printf ("\n"); | |
17623 | } | |
17624 | ||
17625 | if (data != NULL && ent < end) | |
17626 | { | |
17627 | printf (_(" Local entries:\n")); | |
17628 | printf (" %*s %10s %*s\n", | |
17629 | addr_size * 2, _("Address"), _("Access"), | |
17630 | addr_size * 2, _("Value")); | |
17631 | while (ent < end) | |
17632 | { | |
17633 | ent = print_mips_got_entry (data, pltgot, ent, data_end); | |
17634 | printf ("\n"); | |
17635 | if (ent == (bfd_vma) -1) | |
17636 | goto sgot_print_fail; | |
17637 | } | |
17638 | printf ("\n"); | |
17639 | } | |
17640 | ||
17641 | sgot_print_fail: | |
17642 | free (data); | |
17643 | } | |
17644 | return res; | |
17645 | } | |
17646 | ||
17647 | for (entry = filedata->dynamic_section; | |
17648 | /* PR 17531 file: 012-50589-0.004. */ | |
17649 | (entry < filedata->dynamic_section + filedata->dynamic_nent | |
17650 | && entry->d_tag != DT_NULL); | |
17651 | ++entry) | |
17652 | switch (entry->d_tag) | |
17653 | { | |
17654 | case DT_MIPS_LIBLIST: | |
17655 | liblist_offset | |
17656 | = offset_from_vma (filedata, entry->d_un.d_val, | |
17657 | liblistno * sizeof (Elf32_External_Lib)); | |
17658 | break; | |
17659 | case DT_MIPS_LIBLISTNO: | |
17660 | liblistno = entry->d_un.d_val; | |
17661 | break; | |
17662 | case DT_MIPS_OPTIONS: | |
17663 | options_offset = offset_from_vma (filedata, entry->d_un.d_val, 0); | |
17664 | break; | |
17665 | case DT_MIPS_CONFLICT: | |
17666 | conflicts_offset | |
17667 | = offset_from_vma (filedata, entry->d_un.d_val, | |
17668 | conflictsno * sizeof (Elf32_External_Conflict)); | |
17669 | break; | |
17670 | case DT_MIPS_CONFLICTNO: | |
17671 | conflictsno = entry->d_un.d_val; | |
17672 | break; | |
17673 | case DT_PLTGOT: | |
17674 | pltgot = entry->d_un.d_ptr; | |
17675 | break; | |
17676 | case DT_MIPS_LOCAL_GOTNO: | |
17677 | local_gotno = entry->d_un.d_val; | |
17678 | break; | |
17679 | case DT_MIPS_GOTSYM: | |
17680 | gotsym = entry->d_un.d_val; | |
17681 | break; | |
17682 | case DT_MIPS_SYMTABNO: | |
17683 | symtabno = entry->d_un.d_val; | |
17684 | break; | |
17685 | case DT_MIPS_PLTGOT: | |
17686 | mips_pltgot = entry->d_un.d_ptr; | |
17687 | break; | |
17688 | case DT_PLTREL: | |
17689 | pltrel = entry->d_un.d_val; | |
17690 | break; | |
17691 | case DT_PLTRELSZ: | |
17692 | pltrelsz = entry->d_un.d_val; | |
17693 | break; | |
17694 | case DT_JMPREL: | |
17695 | jmprel = entry->d_un.d_ptr; | |
17696 | break; | |
17697 | default: | |
17698 | break; | |
17699 | } | |
17700 | ||
17701 | if (liblist_offset != 0 && liblistno != 0 && do_dynamic) | |
17702 | { | |
17703 | Elf32_External_Lib * elib; | |
17704 | size_t cnt; | |
17705 | ||
17706 | elib = (Elf32_External_Lib *) get_data (NULL, filedata, liblist_offset, | |
17707 | sizeof (Elf32_External_Lib), | |
17708 | liblistno, | |
17709 | _("liblist section data")); | |
17710 | if (elib) | |
17711 | { | |
17712 | printf (ngettext ("\nSection '.liblist' contains %lu entry:\n", | |
17713 | "\nSection '.liblist' contains %lu entries:\n", | |
17714 | (unsigned long) liblistno), | |
17715 | (unsigned long) liblistno); | |
17716 | fputs (_(" Library Time Stamp Checksum Version Flags\n"), | |
17717 | stdout); | |
17718 | ||
17719 | for (cnt = 0; cnt < liblistno; ++cnt) | |
17720 | { | |
17721 | Elf32_Lib liblist; | |
17722 | time_t atime; | |
17723 | char timebuf[128]; | |
17724 | struct tm * tmp; | |
17725 | ||
17726 | liblist.l_name = BYTE_GET (elib[cnt].l_name); | |
17727 | atime = BYTE_GET (elib[cnt].l_time_stamp); | |
17728 | liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum); | |
17729 | liblist.l_version = BYTE_GET (elib[cnt].l_version); | |
17730 | liblist.l_flags = BYTE_GET (elib[cnt].l_flags); | |
17731 | ||
17732 | tmp = gmtime (&atime); | |
17733 | snprintf (timebuf, sizeof (timebuf), | |
17734 | "%04u-%02u-%02uT%02u:%02u:%02u", | |
17735 | tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday, | |
17736 | tmp->tm_hour, tmp->tm_min, tmp->tm_sec); | |
17737 | ||
17738 | printf ("%3lu: ", (unsigned long) cnt); | |
17739 | if (VALID_DYNAMIC_NAME (filedata, liblist.l_name)) | |
17740 | print_symbol (20, GET_DYNAMIC_NAME (filedata, liblist.l_name)); | |
17741 | else | |
17742 | printf (_("<corrupt: %9ld>"), liblist.l_name); | |
17743 | printf (" %s %#10lx %-7ld", timebuf, liblist.l_checksum, | |
17744 | liblist.l_version); | |
17745 | ||
17746 | if (liblist.l_flags == 0) | |
17747 | puts (_(" NONE")); | |
17748 | else | |
17749 | { | |
17750 | static const struct | |
17751 | { | |
17752 | const char * name; | |
17753 | int bit; | |
17754 | } | |
17755 | l_flags_vals[] = | |
17756 | { | |
17757 | { " EXACT_MATCH", LL_EXACT_MATCH }, | |
17758 | { " IGNORE_INT_VER", LL_IGNORE_INT_VER }, | |
17759 | { " REQUIRE_MINOR", LL_REQUIRE_MINOR }, | |
17760 | { " EXPORTS", LL_EXPORTS }, | |
17761 | { " DELAY_LOAD", LL_DELAY_LOAD }, | |
17762 | { " DELTA", LL_DELTA } | |
17763 | }; | |
17764 | int flags = liblist.l_flags; | |
17765 | size_t fcnt; | |
17766 | ||
17767 | for (fcnt = 0; fcnt < ARRAY_SIZE (l_flags_vals); ++fcnt) | |
17768 | if ((flags & l_flags_vals[fcnt].bit) != 0) | |
17769 | { | |
17770 | fputs (l_flags_vals[fcnt].name, stdout); | |
17771 | flags ^= l_flags_vals[fcnt].bit; | |
17772 | } | |
17773 | if (flags != 0) | |
17774 | printf (" %#x", (unsigned int) flags); | |
17775 | ||
17776 | puts (""); | |
17777 | } | |
17778 | } | |
17779 | ||
17780 | free (elib); | |
17781 | } | |
17782 | else | |
17783 | res = FALSE; | |
17784 | } | |
17785 | ||
17786 | if (options_offset != 0) | |
17787 | { | |
17788 | Elf_External_Options * eopt; | |
17789 | size_t offset; | |
17790 | int cnt; | |
17791 | sect = filedata->section_headers; | |
17792 | ||
17793 | /* Find the section header so that we get the size. */ | |
17794 | sect = find_section_by_type (filedata, SHT_MIPS_OPTIONS); | |
17795 | /* PR 17533 file: 012-277276-0.004. */ | |
17796 | if (sect == NULL) | |
17797 | { | |
17798 | error (_("No MIPS_OPTIONS header found\n")); | |
17799 | return FALSE; | |
17800 | } | |
17801 | /* PR 24243 */ | |
17802 | if (sect->sh_size < sizeof (* eopt)) | |
17803 | { | |
17804 | error (_("The MIPS options section is too small.\n")); | |
17805 | return FALSE; | |
17806 | } | |
17807 | ||
17808 | eopt = (Elf_External_Options *) get_data (NULL, filedata, options_offset, 1, | |
17809 | sect->sh_size, _("options")); | |
17810 | if (eopt) | |
17811 | { | |
17812 | Elf_Internal_Options option; | |
17813 | ||
17814 | offset = cnt = 0; | |
17815 | while (offset <= sect->sh_size - sizeof (* eopt)) | |
17816 | { | |
17817 | Elf_External_Options * eoption; | |
17818 | unsigned int optsize; | |
17819 | ||
17820 | eoption = (Elf_External_Options *) ((char *) eopt + offset); | |
17821 | ||
17822 | optsize = BYTE_GET (eoption->size); | |
17823 | ||
17824 | /* PR 17531: file: ffa0fa3b. */ | |
17825 | if (optsize < sizeof (* eopt) | |
17826 | || optsize > sect->sh_size - offset) | |
17827 | { | |
17828 | error (_("Invalid size (%u) for MIPS option\n"), | |
17829 | optsize); | |
17830 | free (eopt); | |
17831 | return FALSE; | |
17832 | } | |
17833 | offset += optsize; | |
17834 | ++cnt; | |
17835 | } | |
17836 | ||
17837 | printf (ngettext ("\nSection '%s' contains %d entry:\n", | |
17838 | "\nSection '%s' contains %d entries:\n", | |
17839 | cnt), | |
17840 | printable_section_name (filedata, sect), cnt); | |
17841 | ||
17842 | offset = 0; | |
17843 | while (cnt-- > 0) | |
17844 | { | |
17845 | size_t len; | |
17846 | Elf_External_Options * eoption; | |
17847 | ||
17848 | eoption = (Elf_External_Options *) ((char *) eopt + offset); | |
17849 | ||
17850 | option.kind = BYTE_GET (eoption->kind); | |
17851 | option.size = BYTE_GET (eoption->size); | |
17852 | option.section = BYTE_GET (eoption->section); | |
17853 | option.info = BYTE_GET (eoption->info); | |
17854 | ||
17855 | switch (option.kind) | |
17856 | { | |
17857 | case ODK_NULL: | |
17858 | /* This shouldn't happen. */ | |
17859 | printf (" NULL %" PRId16 " %" PRIx32, | |
17860 | option.section, option.info); | |
17861 | break; | |
17862 | ||
17863 | case ODK_REGINFO: | |
17864 | printf (" REGINFO "); | |
17865 | if (filedata->file_header.e_machine == EM_MIPS) | |
17866 | { | |
17867 | Elf32_External_RegInfo * ereg; | |
17868 | Elf32_RegInfo reginfo; | |
17869 | ||
17870 | /* 32bit form. */ | |
17871 | if (option.size < (sizeof (Elf_External_Options) | |
17872 | + sizeof (Elf32_External_RegInfo))) | |
17873 | { | |
17874 | printf (_("<corrupt>\n")); | |
17875 | error (_("Truncated MIPS REGINFO option\n")); | |
17876 | cnt = 0; | |
17877 | break; | |
17878 | } | |
17879 | ||
17880 | ereg = (Elf32_External_RegInfo *) (eoption + 1); | |
17881 | ||
17882 | reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask); | |
17883 | reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]); | |
17884 | reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]); | |
17885 | reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]); | |
17886 | reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]); | |
17887 | reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value); | |
17888 | ||
17889 | printf ("GPR %08" PRIx32 " GP 0x%" PRIx32 "\n", | |
17890 | reginfo.ri_gprmask, reginfo.ri_gp_value); | |
17891 | printf (" " | |
17892 | " CPR0 %08" PRIx32 " CPR1 %08" PRIx32 | |
17893 | " CPR2 %08" PRIx32 " CPR3 %08" PRIx32 "\n", | |
17894 | reginfo.ri_cprmask[0], reginfo.ri_cprmask[1], | |
17895 | reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]); | |
17896 | } | |
17897 | else | |
17898 | { | |
17899 | /* 64 bit form. */ | |
17900 | Elf64_External_RegInfo * ereg; | |
17901 | Elf64_Internal_RegInfo reginfo; | |
17902 | ||
17903 | if (option.size < (sizeof (Elf_External_Options) | |
17904 | + sizeof (Elf64_External_RegInfo))) | |
17905 | { | |
17906 | printf (_("<corrupt>\n")); | |
17907 | error (_("Truncated MIPS REGINFO option\n")); | |
17908 | cnt = 0; | |
17909 | break; | |
17910 | } | |
17911 | ||
17912 | ereg = (Elf64_External_RegInfo *) (eoption + 1); | |
17913 | reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask); | |
17914 | reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]); | |
17915 | reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]); | |
17916 | reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]); | |
17917 | reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]); | |
17918 | reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value); | |
17919 | ||
17920 | printf ("GPR %08" PRIx32 " GP 0x%" PRIx64 "\n", | |
17921 | reginfo.ri_gprmask, reginfo.ri_gp_value); | |
17922 | printf (" " | |
17923 | " CPR0 %08" PRIx32 " CPR1 %08" PRIx32 | |
17924 | " CPR2 %08" PRIx32 " CPR3 %08" PRIx32 "\n", | |
17925 | reginfo.ri_cprmask[0], reginfo.ri_cprmask[1], | |
17926 | reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]); | |
17927 | } | |
17928 | offset += option.size; | |
17929 | continue; | |
17930 | ||
17931 | case ODK_EXCEPTIONS: | |
17932 | fputs (" EXCEPTIONS fpe_min(", stdout); | |
17933 | process_mips_fpe_exception (option.info & OEX_FPU_MIN); | |
17934 | fputs (") fpe_max(", stdout); | |
17935 | process_mips_fpe_exception ((option.info & OEX_FPU_MAX) >> 8); | |
17936 | fputs (")", stdout); | |
17937 | ||
17938 | if (option.info & OEX_PAGE0) | |
17939 | fputs (" PAGE0", stdout); | |
17940 | if (option.info & OEX_SMM) | |
17941 | fputs (" SMM", stdout); | |
17942 | if (option.info & OEX_FPDBUG) | |
17943 | fputs (" FPDBUG", stdout); | |
17944 | if (option.info & OEX_DISMISS) | |
17945 | fputs (" DISMISS", stdout); | |
17946 | break; | |
17947 | ||
17948 | case ODK_PAD: | |
17949 | fputs (" PAD ", stdout); | |
17950 | if (option.info & OPAD_PREFIX) | |
17951 | fputs (" PREFIX", stdout); | |
17952 | if (option.info & OPAD_POSTFIX) | |
17953 | fputs (" POSTFIX", stdout); | |
17954 | if (option.info & OPAD_SYMBOL) | |
17955 | fputs (" SYMBOL", stdout); | |
17956 | break; | |
17957 | ||
17958 | case ODK_HWPATCH: | |
17959 | fputs (" HWPATCH ", stdout); | |
17960 | if (option.info & OHW_R4KEOP) | |
17961 | fputs (" R4KEOP", stdout); | |
17962 | if (option.info & OHW_R8KPFETCH) | |
17963 | fputs (" R8KPFETCH", stdout); | |
17964 | if (option.info & OHW_R5KEOP) | |
17965 | fputs (" R5KEOP", stdout); | |
17966 | if (option.info & OHW_R5KCVTL) | |
17967 | fputs (" R5KCVTL", stdout); | |
17968 | break; | |
17969 | ||
17970 | case ODK_FILL: | |
17971 | fputs (" FILL ", stdout); | |
17972 | /* XXX Print content of info word? */ | |
17973 | break; | |
17974 | ||
17975 | case ODK_TAGS: | |
17976 | fputs (" TAGS ", stdout); | |
17977 | /* XXX Print content of info word? */ | |
17978 | break; | |
17979 | ||
17980 | case ODK_HWAND: | |
17981 | fputs (" HWAND ", stdout); | |
17982 | if (option.info & OHWA0_R4KEOP_CHECKED) | |
17983 | fputs (" R4KEOP_CHECKED", stdout); | |
17984 | if (option.info & OHWA0_R4KEOP_CLEAN) | |
17985 | fputs (" R4KEOP_CLEAN", stdout); | |
17986 | break; | |
17987 | ||
17988 | case ODK_HWOR: | |
17989 | fputs (" HWOR ", stdout); | |
17990 | if (option.info & OHWA0_R4KEOP_CHECKED) | |
17991 | fputs (" R4KEOP_CHECKED", stdout); | |
17992 | if (option.info & OHWA0_R4KEOP_CLEAN) | |
17993 | fputs (" R4KEOP_CLEAN", stdout); | |
17994 | break; | |
17995 | ||
17996 | case ODK_GP_GROUP: | |
17997 | printf (" GP_GROUP %#06x self-contained %#06x", | |
17998 | option.info & OGP_GROUP, | |
17999 | (option.info & OGP_SELF) >> 16); | |
18000 | break; | |
18001 | ||
18002 | case ODK_IDENT: | |
18003 | printf (" IDENT %#06x self-contained %#06x", | |
18004 | option.info & OGP_GROUP, | |
18005 | (option.info & OGP_SELF) >> 16); | |
18006 | break; | |
18007 | ||
18008 | default: | |
18009 | /* This shouldn't happen. */ | |
18010 | printf (" %3d ??? %" PRId16 " %" PRIx32, | |
18011 | option.kind, option.section, option.info); | |
18012 | break; | |
18013 | } | |
18014 | ||
18015 | len = sizeof (* eopt); | |
18016 | while (len < option.size) | |
18017 | { | |
18018 | unsigned char datum = *((unsigned char *) eoption + len); | |
18019 | ||
18020 | if (ISPRINT (datum)) | |
18021 | printf ("%c", datum); | |
18022 | else | |
18023 | printf ("\\%03o", datum); | |
18024 | len ++; | |
18025 | } | |
18026 | fputs ("\n", stdout); | |
18027 | ||
18028 | offset += option.size; | |
18029 | } | |
18030 | free (eopt); | |
18031 | } | |
18032 | else | |
18033 | res = FALSE; | |
18034 | } | |
18035 | ||
18036 | if (conflicts_offset != 0 && conflictsno != 0) | |
18037 | { | |
18038 | Elf32_Conflict * iconf; | |
18039 | size_t cnt; | |
18040 | ||
18041 | if (filedata->dynamic_symbols == NULL) | |
18042 | { | |
18043 | error (_("conflict list found without a dynamic symbol table\n")); | |
18044 | return FALSE; | |
18045 | } | |
18046 | ||
18047 | /* PR 21345 - print a slightly more helpful error message | |
18048 | if we are sure that the cmalloc will fail. */ | |
18049 | if (conflictsno > filedata->file_size / sizeof (* iconf)) | |
18050 | { | |
18051 | error (_("Overlarge number of conflicts detected: %lx\n"), | |
18052 | (long) conflictsno); | |
18053 | return FALSE; | |
18054 | } | |
18055 | ||
18056 | iconf = (Elf32_Conflict *) cmalloc (conflictsno, sizeof (* iconf)); | |
18057 | if (iconf == NULL) | |
18058 | { | |
18059 | error (_("Out of memory allocating space for dynamic conflicts\n")); | |
18060 | return FALSE; | |
18061 | } | |
18062 | ||
18063 | if (is_32bit_elf) | |
18064 | { | |
18065 | Elf32_External_Conflict * econf32; | |
18066 | ||
18067 | econf32 = (Elf32_External_Conflict *) | |
18068 | get_data (NULL, filedata, conflicts_offset, | |
18069 | sizeof (*econf32), conflictsno, _("conflict")); | |
18070 | if (!econf32) | |
18071 | { | |
18072 | free (iconf); | |
18073 | return FALSE; | |
18074 | } | |
18075 | ||
18076 | for (cnt = 0; cnt < conflictsno; ++cnt) | |
18077 | iconf[cnt] = BYTE_GET (econf32[cnt]); | |
18078 | ||
18079 | free (econf32); | |
18080 | } | |
18081 | else | |
18082 | { | |
18083 | Elf64_External_Conflict * econf64; | |
18084 | ||
18085 | econf64 = (Elf64_External_Conflict *) | |
18086 | get_data (NULL, filedata, conflicts_offset, | |
18087 | sizeof (*econf64), conflictsno, _("conflict")); | |
18088 | if (!econf64) | |
18089 | { | |
18090 | free (iconf); | |
18091 | return FALSE; | |
18092 | } | |
18093 | ||
18094 | for (cnt = 0; cnt < conflictsno; ++cnt) | |
18095 | iconf[cnt] = BYTE_GET (econf64[cnt]); | |
18096 | ||
18097 | free (econf64); | |
18098 | } | |
18099 | ||
18100 | printf (ngettext ("\nSection '.conflict' contains %lu entry:\n", | |
18101 | "\nSection '.conflict' contains %lu entries:\n", | |
18102 | (unsigned long) conflictsno), | |
18103 | (unsigned long) conflictsno); | |
18104 | puts (_(" Num: Index Value Name")); | |
18105 | ||
18106 | for (cnt = 0; cnt < conflictsno; ++cnt) | |
18107 | { | |
18108 | printf ("%5lu: %8lu ", (unsigned long) cnt, iconf[cnt]); | |
18109 | ||
18110 | if (iconf[cnt] >= filedata->num_dynamic_syms) | |
18111 | printf (_("<corrupt symbol index>")); | |
18112 | else | |
18113 | { | |
18114 | Elf_Internal_Sym * psym; | |
18115 | ||
18116 | psym = & filedata->dynamic_symbols[iconf[cnt]]; | |
18117 | print_vma (psym->st_value, FULL_HEX); | |
18118 | putchar (' '); | |
18119 | if (VALID_DYNAMIC_NAME (filedata, psym->st_name)) | |
18120 | print_symbol (25, GET_DYNAMIC_NAME (filedata, psym->st_name)); | |
18121 | else | |
18122 | printf (_("<corrupt: %14ld>"), psym->st_name); | |
18123 | } | |
18124 | putchar ('\n'); | |
18125 | } | |
18126 | ||
18127 | free (iconf); | |
18128 | } | |
18129 | ||
18130 | if (pltgot != 0 && local_gotno != 0) | |
18131 | { | |
18132 | bfd_vma ent, local_end, global_end; | |
18133 | size_t i, offset; | |
18134 | unsigned char * data; | |
18135 | unsigned char * data_end; | |
18136 | int addr_size; | |
18137 | ||
18138 | ent = pltgot; | |
18139 | addr_size = (is_32bit_elf ? 4 : 8); | |
18140 | local_end = pltgot + local_gotno * addr_size; | |
18141 | ||
18142 | /* PR binutils/17533 file: 012-111227-0.004 */ | |
18143 | if (symtabno < gotsym) | |
18144 | { | |
18145 | error (_("The GOT symbol offset (%lu) is greater than the symbol table size (%lu)\n"), | |
18146 | (unsigned long) gotsym, (unsigned long) symtabno); | |
18147 | return FALSE; | |
18148 | } | |
18149 | ||
18150 | global_end = local_end + (symtabno - gotsym) * addr_size; | |
18151 | /* PR 17531: file: 54c91a34. */ | |
18152 | if (global_end < local_end) | |
18153 | { | |
18154 | error (_("Too many GOT symbols: %lu\n"), (unsigned long) symtabno); | |
18155 | return FALSE; | |
18156 | } | |
18157 | ||
18158 | offset = offset_from_vma (filedata, pltgot, global_end - pltgot); | |
18159 | data = (unsigned char *) get_data (NULL, filedata, offset, | |
18160 | global_end - pltgot, 1, | |
18161 | _("Global Offset Table data")); | |
18162 | /* PR 12855: Null data is handled gracefully throughout. */ | |
18163 | data_end = data + (global_end - pltgot); | |
18164 | ||
18165 | printf (_("\nPrimary GOT:\n")); | |
18166 | printf (_(" Canonical gp value: ")); | |
18167 | print_vma (pltgot + 0x7ff0, LONG_HEX); | |
18168 | printf ("\n\n"); | |
18169 | ||
18170 | printf (_(" Reserved entries:\n")); | |
18171 | printf (_(" %*s %10s %*s Purpose\n"), | |
18172 | addr_size * 2, _("Address"), _("Access"), | |
18173 | addr_size * 2, _("Initial")); | |
18174 | ent = print_mips_got_entry (data, pltgot, ent, data_end); | |
18175 | printf (_(" Lazy resolver\n")); | |
18176 | if (ent == (bfd_vma) -1) | |
18177 | goto got_print_fail; | |
18178 | ||
18179 | /* Check for the MSB of GOT[1] being set, denoting a GNU object. | |
18180 | This entry will be used by some runtime loaders, to store the | |
18181 | module pointer. Otherwise this is an ordinary local entry. | |
18182 | PR 21344: Check for the entry being fully available before | |
18183 | fetching it. */ | |
18184 | if (data | |
18185 | && data + ent - pltgot + addr_size <= data_end | |
18186 | && (byte_get (data + ent - pltgot, addr_size) | |
18187 | >> (addr_size * 8 - 1)) != 0) | |
18188 | { | |
18189 | ent = print_mips_got_entry (data, pltgot, ent, data_end); | |
18190 | printf (_(" Module pointer (GNU extension)\n")); | |
18191 | if (ent == (bfd_vma) -1) | |
18192 | goto got_print_fail; | |
18193 | } | |
18194 | printf ("\n"); | |
18195 | ||
18196 | if (data != NULL && ent < local_end) | |
18197 | { | |
18198 | printf (_(" Local entries:\n")); | |
18199 | printf (" %*s %10s %*s\n", | |
18200 | addr_size * 2, _("Address"), _("Access"), | |
18201 | addr_size * 2, _("Initial")); | |
18202 | while (ent < local_end) | |
18203 | { | |
18204 | ent = print_mips_got_entry (data, pltgot, ent, data_end); | |
18205 | printf ("\n"); | |
18206 | if (ent == (bfd_vma) -1) | |
18207 | goto got_print_fail; | |
18208 | } | |
18209 | printf ("\n"); | |
18210 | } | |
18211 | ||
18212 | if (data != NULL && gotsym < symtabno) | |
18213 | { | |
18214 | int sym_width; | |
18215 | ||
18216 | printf (_(" Global entries:\n")); | |
18217 | printf (" %*s %10s %*s %*s %-7s %3s %s\n", | |
18218 | addr_size * 2, _("Address"), | |
18219 | _("Access"), | |
18220 | addr_size * 2, _("Initial"), | |
18221 | addr_size * 2, _("Sym.Val."), | |
18222 | _("Type"), | |
18223 | /* Note for translators: "Ndx" = abbreviated form of "Index". */ | |
18224 | _("Ndx"), _("Name")); | |
18225 | ||
18226 | sym_width = (is_32bit_elf ? 80 : 160) - 28 - addr_size * 6 - 1; | |
18227 | ||
18228 | for (i = gotsym; i < symtabno; i++) | |
18229 | { | |
18230 | ent = print_mips_got_entry (data, pltgot, ent, data_end); | |
18231 | printf (" "); | |
18232 | ||
18233 | if (filedata->dynamic_symbols == NULL) | |
18234 | printf (_("<no dynamic symbols>")); | |
18235 | else if (i < filedata->num_dynamic_syms) | |
18236 | { | |
18237 | Elf_Internal_Sym * psym = filedata->dynamic_symbols + i; | |
18238 | ||
18239 | print_vma (psym->st_value, LONG_HEX); | |
18240 | printf (" %-7s %3s ", | |
18241 | get_symbol_type (filedata, ELF_ST_TYPE (psym->st_info)), | |
18242 | get_symbol_index_type (filedata, psym->st_shndx)); | |
18243 | ||
18244 | if (VALID_DYNAMIC_NAME (filedata, psym->st_name)) | |
18245 | print_symbol (sym_width, | |
18246 | GET_DYNAMIC_NAME (filedata, psym->st_name)); | |
18247 | else | |
18248 | printf (_("<corrupt: %14ld>"), psym->st_name); | |
18249 | } | |
18250 | else | |
18251 | printf (_("<symbol index %lu exceeds number of dynamic symbols>"), | |
18252 | (unsigned long) i); | |
18253 | ||
18254 | printf ("\n"); | |
18255 | if (ent == (bfd_vma) -1) | |
18256 | break; | |
18257 | } | |
18258 | printf ("\n"); | |
18259 | } | |
18260 | ||
18261 | got_print_fail: | |
18262 | free (data); | |
18263 | } | |
18264 | ||
18265 | if (mips_pltgot != 0 && jmprel != 0 && pltrel != 0 && pltrelsz != 0) | |
18266 | { | |
18267 | bfd_vma ent, end; | |
18268 | size_t offset, rel_offset; | |
18269 | unsigned long count, i; | |
18270 | unsigned char * data; | |
18271 | int addr_size, sym_width; | |
18272 | Elf_Internal_Rela * rels; | |
18273 | ||
18274 | rel_offset = offset_from_vma (filedata, jmprel, pltrelsz); | |
18275 | if (pltrel == DT_RELA) | |
18276 | { | |
18277 | if (!slurp_rela_relocs (filedata, rel_offset, pltrelsz, &rels, &count)) | |
18278 | return FALSE; | |
18279 | } | |
18280 | else | |
18281 | { | |
18282 | if (!slurp_rel_relocs (filedata, rel_offset, pltrelsz, &rels, &count)) | |
18283 | return FALSE; | |
18284 | } | |
18285 | ||
18286 | ent = mips_pltgot; | |
18287 | addr_size = (is_32bit_elf ? 4 : 8); | |
18288 | end = mips_pltgot + (2 + count) * addr_size; | |
18289 | ||
18290 | offset = offset_from_vma (filedata, mips_pltgot, end - mips_pltgot); | |
18291 | data = (unsigned char *) get_data (NULL, filedata, offset, end - mips_pltgot, | |
18292 | 1, _("Procedure Linkage Table data")); | |
18293 | if (data == NULL) | |
18294 | { | |
18295 | free (rels); | |
18296 | return FALSE; | |
18297 | } | |
18298 | ||
18299 | printf ("\nPLT GOT:\n\n"); | |
18300 | printf (_(" Reserved entries:\n")); | |
18301 | printf (_(" %*s %*s Purpose\n"), | |
18302 | addr_size * 2, _("Address"), addr_size * 2, _("Initial")); | |
18303 | ent = print_mips_pltgot_entry (data, mips_pltgot, ent); | |
18304 | printf (_(" PLT lazy resolver\n")); | |
18305 | ent = print_mips_pltgot_entry (data, mips_pltgot, ent); | |
18306 | printf (_(" Module pointer\n")); | |
18307 | printf ("\n"); | |
18308 | ||
18309 | printf (_(" Entries:\n")); | |
18310 | printf (" %*s %*s %*s %-7s %3s %s\n", | |
18311 | addr_size * 2, _("Address"), | |
18312 | addr_size * 2, _("Initial"), | |
18313 | addr_size * 2, _("Sym.Val."), _("Type"), _("Ndx"), _("Name")); | |
18314 | sym_width = (is_32bit_elf ? 80 : 160) - 17 - addr_size * 6 - 1; | |
18315 | for (i = 0; i < count; i++) | |
18316 | { | |
18317 | unsigned long idx = get_reloc_symindex (rels[i].r_info); | |
18318 | ||
18319 | ent = print_mips_pltgot_entry (data, mips_pltgot, ent); | |
18320 | printf (" "); | |
18321 | ||
18322 | if (idx >= filedata->num_dynamic_syms) | |
18323 | printf (_("<corrupt symbol index: %lu>"), idx); | |
18324 | else | |
18325 | { | |
18326 | Elf_Internal_Sym * psym = filedata->dynamic_symbols + idx; | |
18327 | ||
18328 | print_vma (psym->st_value, LONG_HEX); | |
18329 | printf (" %-7s %3s ", | |
18330 | get_symbol_type (filedata, ELF_ST_TYPE (psym->st_info)), | |
18331 | get_symbol_index_type (filedata, psym->st_shndx)); | |
18332 | if (VALID_DYNAMIC_NAME (filedata, psym->st_name)) | |
18333 | print_symbol (sym_width, | |
18334 | GET_DYNAMIC_NAME (filedata, psym->st_name)); | |
18335 | else | |
18336 | printf (_("<corrupt: %14ld>"), psym->st_name); | |
18337 | } | |
18338 | printf ("\n"); | |
18339 | } | |
18340 | printf ("\n"); | |
18341 | ||
18342 | free (data); | |
18343 | free (rels); | |
18344 | } | |
18345 | ||
18346 | return res; | |
18347 | } | |
18348 | ||
18349 | static bfd_boolean | |
18350 | process_nds32_specific (Filedata * filedata) | |
18351 | { | |
18352 | Elf_Internal_Shdr *sect = NULL; | |
18353 | ||
18354 | sect = find_section (filedata, ".nds32_e_flags"); | |
18355 | if (sect != NULL && sect->sh_size >= 4) | |
18356 | { | |
18357 | unsigned char *buf; | |
18358 | unsigned int flag; | |
18359 | ||
18360 | printf ("\nNDS32 elf flags section:\n"); | |
18361 | buf = get_data (NULL, filedata, sect->sh_offset, 1, 4, | |
18362 | _("NDS32 elf flags section")); | |
18363 | ||
18364 | if (buf == NULL) | |
18365 | return FALSE; | |
18366 | ||
18367 | flag = byte_get (buf, 4); | |
18368 | free (buf); | |
18369 | switch (flag & 0x3) | |
18370 | { | |
18371 | case 0: | |
18372 | printf ("(VEC_SIZE):\tNo entry.\n"); | |
18373 | break; | |
18374 | case 1: | |
18375 | printf ("(VEC_SIZE):\t4 bytes\n"); | |
18376 | break; | |
18377 | case 2: | |
18378 | printf ("(VEC_SIZE):\t16 bytes\n"); | |
18379 | break; | |
18380 | case 3: | |
18381 | printf ("(VEC_SIZE):\treserved\n"); | |
18382 | break; | |
18383 | } | |
18384 | } | |
18385 | ||
18386 | return TRUE; | |
18387 | } | |
18388 | ||
18389 | static bfd_boolean | |
18390 | process_gnu_liblist (Filedata * filedata) | |
18391 | { | |
18392 | Elf_Internal_Shdr * section; | |
18393 | Elf_Internal_Shdr * string_sec; | |
18394 | Elf32_External_Lib * elib; | |
18395 | char * strtab; | |
18396 | size_t strtab_size; | |
18397 | size_t cnt; | |
18398 | unsigned long num_liblist; | |
18399 | unsigned i; | |
18400 | bfd_boolean res = TRUE; | |
18401 | ||
18402 | if (! do_arch) | |
18403 | return TRUE; | |
18404 | ||
18405 | for (i = 0, section = filedata->section_headers; | |
18406 | i < filedata->file_header.e_shnum; | |
18407 | i++, section++) | |
18408 | { | |
18409 | switch (section->sh_type) | |
18410 | { | |
18411 | case SHT_GNU_LIBLIST: | |
18412 | if (section->sh_link >= filedata->file_header.e_shnum) | |
18413 | break; | |
18414 | ||
18415 | elib = (Elf32_External_Lib *) | |
18416 | get_data (NULL, filedata, section->sh_offset, 1, section->sh_size, | |
18417 | _("liblist section data")); | |
18418 | ||
18419 | if (elib == NULL) | |
18420 | { | |
18421 | res = FALSE; | |
18422 | break; | |
18423 | } | |
18424 | ||
18425 | string_sec = filedata->section_headers + section->sh_link; | |
18426 | strtab = (char *) get_data (NULL, filedata, string_sec->sh_offset, 1, | |
18427 | string_sec->sh_size, | |
18428 | _("liblist string table")); | |
18429 | if (strtab == NULL | |
18430 | || section->sh_entsize != sizeof (Elf32_External_Lib)) | |
18431 | { | |
18432 | free (elib); | |
18433 | free (strtab); | |
18434 | res = FALSE; | |
18435 | break; | |
18436 | } | |
18437 | strtab_size = string_sec->sh_size; | |
18438 | ||
18439 | num_liblist = section->sh_size / sizeof (Elf32_External_Lib); | |
18440 | printf (ngettext ("\nLibrary list section '%s' contains %lu entries:\n", | |
18441 | "\nLibrary list section '%s' contains %lu entries:\n", | |
18442 | num_liblist), | |
18443 | printable_section_name (filedata, section), | |
18444 | num_liblist); | |
18445 | ||
18446 | puts (_(" Library Time Stamp Checksum Version Flags")); | |
18447 | ||
18448 | for (cnt = 0; cnt < section->sh_size / sizeof (Elf32_External_Lib); | |
18449 | ++cnt) | |
18450 | { | |
18451 | Elf32_Lib liblist; | |
18452 | time_t atime; | |
18453 | char timebuf[128]; | |
18454 | struct tm * tmp; | |
18455 | ||
18456 | liblist.l_name = BYTE_GET (elib[cnt].l_name); | |
18457 | atime = BYTE_GET (elib[cnt].l_time_stamp); | |
18458 | liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum); | |
18459 | liblist.l_version = BYTE_GET (elib[cnt].l_version); | |
18460 | liblist.l_flags = BYTE_GET (elib[cnt].l_flags); | |
18461 | ||
18462 | tmp = gmtime (&atime); | |
18463 | snprintf (timebuf, sizeof (timebuf), | |
18464 | "%04u-%02u-%02uT%02u:%02u:%02u", | |
18465 | tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday, | |
18466 | tmp->tm_hour, tmp->tm_min, tmp->tm_sec); | |
18467 | ||
18468 | printf ("%3lu: ", (unsigned long) cnt); | |
18469 | if (do_wide) | |
18470 | printf ("%-20s", liblist.l_name < strtab_size | |
18471 | ? strtab + liblist.l_name : _("<corrupt>")); | |
18472 | else | |
18473 | printf ("%-20.20s", liblist.l_name < strtab_size | |
18474 | ? strtab + liblist.l_name : _("<corrupt>")); | |
18475 | printf (" %s %#010lx %-7ld %-7ld\n", timebuf, liblist.l_checksum, | |
18476 | liblist.l_version, liblist.l_flags); | |
18477 | } | |
18478 | ||
18479 | free (elib); | |
18480 | free (strtab); | |
18481 | } | |
18482 | } | |
18483 | ||
18484 | return res; | |
18485 | } | |
18486 | ||
18487 | static const char * | |
18488 | get_note_type (Filedata * filedata, unsigned e_type) | |
18489 | { | |
18490 | static char buff[64]; | |
18491 | ||
18492 | if (filedata->file_header.e_type == ET_CORE) | |
18493 | switch (e_type) | |
18494 | { | |
18495 | case NT_AUXV: | |
18496 | return _("NT_AUXV (auxiliary vector)"); | |
18497 | case NT_PRSTATUS: | |
18498 | return _("NT_PRSTATUS (prstatus structure)"); | |
18499 | case NT_FPREGSET: | |
18500 | return _("NT_FPREGSET (floating point registers)"); | |
18501 | case NT_PRPSINFO: | |
18502 | return _("NT_PRPSINFO (prpsinfo structure)"); | |
18503 | case NT_TASKSTRUCT: | |
18504 | return _("NT_TASKSTRUCT (task structure)"); | |
18505 | case NT_GDB_TDESC: | |
18506 | return _("NT_GDB_TDESC (GDB XML target description)"); | |
18507 | case NT_PRXFPREG: | |
18508 | return _("NT_PRXFPREG (user_xfpregs structure)"); | |
18509 | case NT_PPC_VMX: | |
18510 | return _("NT_PPC_VMX (ppc Altivec registers)"); | |
18511 | case NT_PPC_VSX: | |
18512 | return _("NT_PPC_VSX (ppc VSX registers)"); | |
18513 | case NT_PPC_TAR: | |
18514 | return _("NT_PPC_TAR (ppc TAR register)"); | |
18515 | case NT_PPC_PPR: | |
18516 | return _("NT_PPC_PPR (ppc PPR register)"); | |
18517 | case NT_PPC_DSCR: | |
18518 | return _("NT_PPC_DSCR (ppc DSCR register)"); | |
18519 | case NT_PPC_EBB: | |
18520 | return _("NT_PPC_EBB (ppc EBB registers)"); | |
18521 | case NT_PPC_PMU: | |
18522 | return _("NT_PPC_PMU (ppc PMU registers)"); | |
18523 | case NT_PPC_TM_CGPR: | |
18524 | return _("NT_PPC_TM_CGPR (ppc checkpointed GPR registers)"); | |
18525 | case NT_PPC_TM_CFPR: | |
18526 | return _("NT_PPC_TM_CFPR (ppc checkpointed floating point registers)"); | |
18527 | case NT_PPC_TM_CVMX: | |
18528 | return _("NT_PPC_TM_CVMX (ppc checkpointed Altivec registers)"); | |
18529 | case NT_PPC_TM_CVSX: | |
18530 | return _("NT_PPC_TM_CVSX (ppc checkpointed VSX registers)"); | |
18531 | case NT_PPC_TM_SPR: | |
18532 | return _("NT_PPC_TM_SPR (ppc TM special purpose registers)"); | |
18533 | case NT_PPC_TM_CTAR: | |
18534 | return _("NT_PPC_TM_CTAR (ppc checkpointed TAR register)"); | |
18535 | case NT_PPC_TM_CPPR: | |
18536 | return _("NT_PPC_TM_CPPR (ppc checkpointed PPR register)"); | |
18537 | case NT_PPC_TM_CDSCR: | |
18538 | return _("NT_PPC_TM_CDSCR (ppc checkpointed DSCR register)"); | |
18539 | case NT_386_TLS: | |
18540 | return _("NT_386_TLS (x86 TLS information)"); | |
18541 | case NT_386_IOPERM: | |
18542 | return _("NT_386_IOPERM (x86 I/O permissions)"); | |
18543 | case NT_X86_XSTATE: | |
18544 | return _("NT_X86_XSTATE (x86 XSAVE extended state)"); | |
18545 | case NT_X86_CET: | |
18546 | return _("NT_X86_CET (x86 CET state)"); | |
18547 | case NT_S390_HIGH_GPRS: | |
18548 | return _("NT_S390_HIGH_GPRS (s390 upper register halves)"); | |
18549 | case NT_S390_TIMER: | |
18550 | return _("NT_S390_TIMER (s390 timer register)"); | |
18551 | case NT_S390_TODCMP: | |
18552 | return _("NT_S390_TODCMP (s390 TOD comparator register)"); | |
18553 | case NT_S390_TODPREG: | |
18554 | return _("NT_S390_TODPREG (s390 TOD programmable register)"); | |
18555 | case NT_S390_CTRS: | |
18556 | return _("NT_S390_CTRS (s390 control registers)"); | |
18557 | case NT_S390_PREFIX: | |
18558 | return _("NT_S390_PREFIX (s390 prefix register)"); | |
18559 | case NT_S390_LAST_BREAK: | |
18560 | return _("NT_S390_LAST_BREAK (s390 last breaking event address)"); | |
18561 | case NT_S390_SYSTEM_CALL: | |
18562 | return _("NT_S390_SYSTEM_CALL (s390 system call restart data)"); | |
18563 | case NT_S390_TDB: | |
18564 | return _("NT_S390_TDB (s390 transaction diagnostic block)"); | |
18565 | case NT_S390_VXRS_LOW: | |
18566 | return _("NT_S390_VXRS_LOW (s390 vector registers 0-15 upper half)"); | |
18567 | case NT_S390_VXRS_HIGH: | |
18568 | return _("NT_S390_VXRS_HIGH (s390 vector registers 16-31)"); | |
18569 | case NT_S390_GS_CB: | |
18570 | return _("NT_S390_GS_CB (s390 guarded-storage registers)"); | |
18571 | case NT_S390_GS_BC: | |
18572 | return _("NT_S390_GS_BC (s390 guarded-storage broadcast control)"); | |
18573 | case NT_ARM_VFP: | |
18574 | return _("NT_ARM_VFP (arm VFP registers)"); | |
18575 | case NT_ARM_TLS: | |
18576 | return _("NT_ARM_TLS (AArch TLS registers)"); | |
18577 | case NT_ARM_HW_BREAK: | |
18578 | return _("NT_ARM_HW_BREAK (AArch hardware breakpoint registers)"); | |
18579 | case NT_ARM_HW_WATCH: | |
18580 | return _("NT_ARM_HW_WATCH (AArch hardware watchpoint registers)"); | |
18581 | case NT_ARC_V2: | |
18582 | return _("NT_ARC_V2 (ARC HS accumulator/extra registers)"); | |
18583 | case NT_RISCV_CSR: | |
18584 | return _("NT_RISCV_CSR (RISC-V control and status registers)"); | |
18585 | case NT_PSTATUS: | |
18586 | return _("NT_PSTATUS (pstatus structure)"); | |
18587 | case NT_FPREGS: | |
18588 | return _("NT_FPREGS (floating point registers)"); | |
18589 | case NT_PSINFO: | |
18590 | return _("NT_PSINFO (psinfo structure)"); | |
18591 | case NT_LWPSTATUS: | |
18592 | return _("NT_LWPSTATUS (lwpstatus_t structure)"); | |
18593 | case NT_LWPSINFO: | |
18594 | return _("NT_LWPSINFO (lwpsinfo_t structure)"); | |
18595 | case NT_WIN32PSTATUS: | |
18596 | return _("NT_WIN32PSTATUS (win32_pstatus structure)"); | |
18597 | case NT_SIGINFO: | |
18598 | return _("NT_SIGINFO (siginfo_t data)"); | |
18599 | case NT_FILE: | |
18600 | return _("NT_FILE (mapped files)"); | |
18601 | default: | |
18602 | break; | |
18603 | } | |
18604 | else | |
18605 | switch (e_type) | |
18606 | { | |
18607 | case NT_VERSION: | |
18608 | return _("NT_VERSION (version)"); | |
18609 | case NT_ARCH: | |
18610 | return _("NT_ARCH (architecture)"); | |
18611 | case NT_GNU_BUILD_ATTRIBUTE_OPEN: | |
18612 | return _("OPEN"); | |
18613 | case NT_GNU_BUILD_ATTRIBUTE_FUNC: | |
18614 | return _("func"); | |
18615 | default: | |
18616 | break; | |
18617 | } | |
18618 | ||
18619 | snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type); | |
18620 | return buff; | |
18621 | } | |
18622 | ||
18623 | static bfd_boolean | |
18624 | print_core_note (Elf_Internal_Note *pnote) | |
18625 | { | |
18626 | unsigned int addr_size = is_32bit_elf ? 4 : 8; | |
18627 | bfd_vma count, page_size; | |
18628 | unsigned char *descdata, *filenames, *descend; | |
18629 | ||
18630 | if (pnote->type != NT_FILE) | |
18631 | { | |
18632 | if (do_wide) | |
18633 | printf ("\n"); | |
18634 | return TRUE; | |
18635 | } | |
18636 | ||
18637 | #ifndef BFD64 | |
18638 | if (!is_32bit_elf) | |
18639 | { | |
18640 | printf (_(" Cannot decode 64-bit note in 32-bit build\n")); | |
18641 | /* Still "successful". */ | |
18642 | return TRUE; | |
18643 | } | |
18644 | #endif | |
18645 | ||
18646 | if (pnote->descsz < 2 * addr_size) | |
18647 | { | |
18648 | error (_(" Malformed note - too short for header\n")); | |
18649 | return FALSE; | |
18650 | } | |
18651 | ||
18652 | descdata = (unsigned char *) pnote->descdata; | |
18653 | descend = descdata + pnote->descsz; | |
18654 | ||
18655 | if (descdata[pnote->descsz - 1] != '\0') | |
18656 | { | |
18657 | error (_(" Malformed note - does not end with \\0\n")); | |
18658 | return FALSE; | |
18659 | } | |
18660 | ||
18661 | count = byte_get (descdata, addr_size); | |
18662 | descdata += addr_size; | |
18663 | ||
18664 | page_size = byte_get (descdata, addr_size); | |
18665 | descdata += addr_size; | |
18666 | ||
18667 | if (count > ((bfd_vma) -1 - 2 * addr_size) / (3 * addr_size) | |
18668 | || pnote->descsz < 2 * addr_size + count * 3 * addr_size) | |
18669 | { | |
18670 | error (_(" Malformed note - too short for supplied file count\n")); | |
18671 | return FALSE; | |
18672 | } | |
18673 | ||
18674 | printf (_(" Page size: ")); | |
18675 | print_vma (page_size, DEC); | |
18676 | printf ("\n"); | |
18677 | ||
18678 | printf (_(" %*s%*s%*s\n"), | |
18679 | (int) (2 + 2 * addr_size), _("Start"), | |
18680 | (int) (4 + 2 * addr_size), _("End"), | |
18681 | (int) (4 + 2 * addr_size), _("Page Offset")); | |
18682 | filenames = descdata + count * 3 * addr_size; | |
18683 | while (count-- > 0) | |
18684 | { | |
18685 | bfd_vma start, end, file_ofs; | |
18686 | ||
18687 | if (filenames == descend) | |
18688 | { | |
18689 | error (_(" Malformed note - filenames end too early\n")); | |
18690 | return FALSE; | |
18691 | } | |
18692 | ||
18693 | start = byte_get (descdata, addr_size); | |
18694 | descdata += addr_size; | |
18695 | end = byte_get (descdata, addr_size); | |
18696 | descdata += addr_size; | |
18697 | file_ofs = byte_get (descdata, addr_size); | |
18698 | descdata += addr_size; | |
18699 | ||
18700 | printf (" "); | |
18701 | print_vma (start, FULL_HEX); | |
18702 | printf (" "); | |
18703 | print_vma (end, FULL_HEX); | |
18704 | printf (" "); | |
18705 | print_vma (file_ofs, FULL_HEX); | |
18706 | printf ("\n %s\n", filenames); | |
18707 | ||
18708 | filenames += 1 + strlen ((char *) filenames); | |
18709 | } | |
18710 | ||
18711 | return TRUE; | |
18712 | } | |
18713 | ||
18714 | static const char * | |
18715 | get_gnu_elf_note_type (unsigned e_type) | |
18716 | { | |
18717 | /* NB/ Keep this switch statement in sync with print_gnu_note (). */ | |
18718 | switch (e_type) | |
18719 | { | |
18720 | case NT_GNU_ABI_TAG: | |
18721 | return _("NT_GNU_ABI_TAG (ABI version tag)"); | |
18722 | case NT_GNU_HWCAP: | |
18723 | return _("NT_GNU_HWCAP (DSO-supplied software HWCAP info)"); | |
18724 | case NT_GNU_BUILD_ID: | |
18725 | return _("NT_GNU_BUILD_ID (unique build ID bitstring)"); | |
18726 | case NT_GNU_GOLD_VERSION: | |
18727 | return _("NT_GNU_GOLD_VERSION (gold version)"); | |
18728 | case NT_GNU_PROPERTY_TYPE_0: | |
18729 | return _("NT_GNU_PROPERTY_TYPE_0"); | |
18730 | case NT_GNU_BUILD_ATTRIBUTE_OPEN: | |
18731 | return _("NT_GNU_BUILD_ATTRIBUTE_OPEN"); | |
18732 | case NT_GNU_BUILD_ATTRIBUTE_FUNC: | |
18733 | return _("NT_GNU_BUILD_ATTRIBUTE_FUNC"); | |
18734 | default: | |
18735 | { | |
18736 | static char buff[64]; | |
18737 | ||
18738 | snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type); | |
18739 | return buff; | |
18740 | } | |
18741 | } | |
18742 | } | |
18743 | ||
18744 | static void | |
18745 | decode_x86_compat_isa (unsigned int bitmask) | |
18746 | { | |
18747 | while (bitmask) | |
18748 | { | |
18749 | unsigned int bit = bitmask & (- bitmask); | |
18750 | ||
18751 | bitmask &= ~ bit; | |
18752 | switch (bit) | |
18753 | { | |
18754 | case GNU_PROPERTY_X86_COMPAT_ISA_1_486: | |
18755 | printf ("i486"); | |
18756 | break; | |
18757 | case GNU_PROPERTY_X86_COMPAT_ISA_1_586: | |
18758 | printf ("586"); | |
18759 | break; | |
18760 | case GNU_PROPERTY_X86_COMPAT_ISA_1_686: | |
18761 | printf ("686"); | |
18762 | break; | |
18763 | case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE: | |
18764 | printf ("SSE"); | |
18765 | break; | |
18766 | case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE2: | |
18767 | printf ("SSE2"); | |
18768 | break; | |
18769 | case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE3: | |
18770 | printf ("SSE3"); | |
18771 | break; | |
18772 | case GNU_PROPERTY_X86_COMPAT_ISA_1_SSSE3: | |
18773 | printf ("SSSE3"); | |
18774 | break; | |
18775 | case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE4_1: | |
18776 | printf ("SSE4_1"); | |
18777 | break; | |
18778 | case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE4_2: | |
18779 | printf ("SSE4_2"); | |
18780 | break; | |
18781 | case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX: | |
18782 | printf ("AVX"); | |
18783 | break; | |
18784 | case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX2: | |
18785 | printf ("AVX2"); | |
18786 | break; | |
18787 | case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512F: | |
18788 | printf ("AVX512F"); | |
18789 | break; | |
18790 | case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512CD: | |
18791 | printf ("AVX512CD"); | |
18792 | break; | |
18793 | case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512ER: | |
18794 | printf ("AVX512ER"); | |
18795 | break; | |
18796 | case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512PF: | |
18797 | printf ("AVX512PF"); | |
18798 | break; | |
18799 | case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512VL: | |
18800 | printf ("AVX512VL"); | |
18801 | break; | |
18802 | case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512DQ: | |
18803 | printf ("AVX512DQ"); | |
18804 | break; | |
18805 | case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512BW: | |
18806 | printf ("AVX512BW"); | |
18807 | break; | |
18808 | default: | |
18809 | printf (_("<unknown: %x>"), bit); | |
18810 | break; | |
18811 | } | |
18812 | if (bitmask) | |
18813 | printf (", "); | |
18814 | } | |
18815 | } | |
18816 | ||
18817 | static void | |
18818 | decode_x86_compat_2_isa (unsigned int bitmask) | |
18819 | { | |
18820 | if (!bitmask) | |
18821 | { | |
18822 | printf (_("<None>")); | |
18823 | return; | |
18824 | } | |
18825 | ||
18826 | while (bitmask) | |
18827 | { | |
18828 | unsigned int bit = bitmask & (- bitmask); | |
18829 | ||
18830 | bitmask &= ~ bit; | |
18831 | switch (bit) | |
18832 | { | |
18833 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_CMOV: | |
18834 | printf ("CMOV"); | |
18835 | break; | |
18836 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE: | |
18837 | printf ("SSE"); | |
18838 | break; | |
18839 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE2: | |
18840 | printf ("SSE2"); | |
18841 | break; | |
18842 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE3: | |
18843 | printf ("SSE3"); | |
18844 | break; | |
18845 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSSE3: | |
18846 | printf ("SSSE3"); | |
18847 | break; | |
18848 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE4_1: | |
18849 | printf ("SSE4_1"); | |
18850 | break; | |
18851 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE4_2: | |
18852 | printf ("SSE4_2"); | |
18853 | break; | |
18854 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX: | |
18855 | printf ("AVX"); | |
18856 | break; | |
18857 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX2: | |
18858 | printf ("AVX2"); | |
18859 | break; | |
18860 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_FMA: | |
18861 | printf ("FMA"); | |
18862 | break; | |
18863 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512F: | |
18864 | printf ("AVX512F"); | |
18865 | break; | |
18866 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512CD: | |
18867 | printf ("AVX512CD"); | |
18868 | break; | |
18869 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512ER: | |
18870 | printf ("AVX512ER"); | |
18871 | break; | |
18872 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512PF: | |
18873 | printf ("AVX512PF"); | |
18874 | break; | |
18875 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512VL: | |
18876 | printf ("AVX512VL"); | |
18877 | break; | |
18878 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512DQ: | |
18879 | printf ("AVX512DQ"); | |
18880 | break; | |
18881 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512BW: | |
18882 | printf ("AVX512BW"); | |
18883 | break; | |
18884 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_4FMAPS: | |
18885 | printf ("AVX512_4FMAPS"); | |
18886 | break; | |
18887 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_4VNNIW: | |
18888 | printf ("AVX512_4VNNIW"); | |
18889 | break; | |
18890 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_BITALG: | |
18891 | printf ("AVX512_BITALG"); | |
18892 | break; | |
18893 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_IFMA: | |
18894 | printf ("AVX512_IFMA"); | |
18895 | break; | |
18896 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_VBMI: | |
18897 | printf ("AVX512_VBMI"); | |
18898 | break; | |
18899 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_VBMI2: | |
18900 | printf ("AVX512_VBMI2"); | |
18901 | break; | |
18902 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_VNNI: | |
18903 | printf ("AVX512_VNNI"); | |
18904 | break; | |
18905 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_BF16: | |
18906 | printf ("AVX512_BF16"); | |
18907 | break; | |
18908 | default: | |
18909 | printf (_("<unknown: %x>"), bit); | |
18910 | break; | |
18911 | } | |
18912 | if (bitmask) | |
18913 | printf (", "); | |
18914 | } | |
18915 | } | |
18916 | ||
18917 | static void | |
18918 | decode_x86_isa (unsigned int bitmask) | |
18919 | { | |
18920 | while (bitmask) | |
18921 | { | |
18922 | unsigned int bit = bitmask & (- bitmask); | |
18923 | ||
18924 | bitmask &= ~ bit; | |
18925 | switch (bit) | |
18926 | { | |
18927 | case GNU_PROPERTY_X86_ISA_1_BASELINE: | |
18928 | printf ("x86-64-baseline"); | |
18929 | break; | |
18930 | case GNU_PROPERTY_X86_ISA_1_V2: | |
18931 | printf ("x86-64-v2"); | |
18932 | break; | |
18933 | case GNU_PROPERTY_X86_ISA_1_V3: | |
18934 | printf ("x86-64-v3"); | |
18935 | break; | |
18936 | case GNU_PROPERTY_X86_ISA_1_V4: | |
18937 | printf ("x86-64-v4"); | |
18938 | break; | |
18939 | default: | |
18940 | printf (_("<unknown: %x>"), bit); | |
18941 | break; | |
18942 | } | |
18943 | if (bitmask) | |
18944 | printf (", "); | |
18945 | } | |
18946 | } | |
18947 | ||
18948 | static void | |
18949 | decode_x86_feature_1 (unsigned int bitmask) | |
18950 | { | |
18951 | if (!bitmask) | |
18952 | { | |
18953 | printf (_("<None>")); | |
18954 | return; | |
18955 | } | |
18956 | ||
18957 | while (bitmask) | |
18958 | { | |
18959 | unsigned int bit = bitmask & (- bitmask); | |
18960 | ||
18961 | bitmask &= ~ bit; | |
18962 | switch (bit) | |
18963 | { | |
18964 | case GNU_PROPERTY_X86_FEATURE_1_IBT: | |
18965 | printf ("IBT"); | |
18966 | break; | |
18967 | case GNU_PROPERTY_X86_FEATURE_1_SHSTK: | |
18968 | printf ("SHSTK"); | |
18969 | break; | |
18970 | case GNU_PROPERTY_X86_FEATURE_1_LAM_U48: | |
18971 | printf ("LAM_U48"); | |
18972 | break; | |
18973 | case GNU_PROPERTY_X86_FEATURE_1_LAM_U57: | |
18974 | printf ("LAM_U57"); | |
18975 | break; | |
18976 | default: | |
18977 | printf (_("<unknown: %x>"), bit); | |
18978 | break; | |
18979 | } | |
18980 | if (bitmask) | |
18981 | printf (", "); | |
18982 | } | |
18983 | } | |
18984 | ||
18985 | static void | |
18986 | decode_x86_feature_2 (unsigned int bitmask) | |
18987 | { | |
18988 | if (!bitmask) | |
18989 | { | |
18990 | printf (_("<None>")); | |
18991 | return; | |
18992 | } | |
18993 | ||
18994 | while (bitmask) | |
18995 | { | |
18996 | unsigned int bit = bitmask & (- bitmask); | |
18997 | ||
18998 | bitmask &= ~ bit; | |
18999 | switch (bit) | |
19000 | { | |
19001 | case GNU_PROPERTY_X86_FEATURE_2_X86: | |
19002 | printf ("x86"); | |
19003 | break; | |
19004 | case GNU_PROPERTY_X86_FEATURE_2_X87: | |
19005 | printf ("x87"); | |
19006 | break; | |
19007 | case GNU_PROPERTY_X86_FEATURE_2_MMX: | |
19008 | printf ("MMX"); | |
19009 | break; | |
19010 | case GNU_PROPERTY_X86_FEATURE_2_XMM: | |
19011 | printf ("XMM"); | |
19012 | break; | |
19013 | case GNU_PROPERTY_X86_FEATURE_2_YMM: | |
19014 | printf ("YMM"); | |
19015 | break; | |
19016 | case GNU_PROPERTY_X86_FEATURE_2_ZMM: | |
19017 | printf ("ZMM"); | |
19018 | break; | |
19019 | case GNU_PROPERTY_X86_FEATURE_2_TMM: | |
19020 | printf ("TMM"); | |
19021 | break; | |
19022 | case GNU_PROPERTY_X86_FEATURE_2_MASK: | |
19023 | printf ("MASK"); | |
19024 | break; | |
19025 | case GNU_PROPERTY_X86_FEATURE_2_FXSR: | |
19026 | printf ("FXSR"); | |
19027 | break; | |
19028 | case GNU_PROPERTY_X86_FEATURE_2_XSAVE: | |
19029 | printf ("XSAVE"); | |
19030 | break; | |
19031 | case GNU_PROPERTY_X86_FEATURE_2_XSAVEOPT: | |
19032 | printf ("XSAVEOPT"); | |
19033 | break; | |
19034 | case GNU_PROPERTY_X86_FEATURE_2_XSAVEC: | |
19035 | printf ("XSAVEC"); | |
19036 | break; | |
19037 | default: | |
19038 | printf (_("<unknown: %x>"), bit); | |
19039 | break; | |
19040 | } | |
19041 | if (bitmask) | |
19042 | printf (", "); | |
19043 | } | |
19044 | } | |
19045 | ||
19046 | static void | |
19047 | decode_aarch64_feature_1_and (unsigned int bitmask) | |
19048 | { | |
19049 | while (bitmask) | |
19050 | { | |
19051 | unsigned int bit = bitmask & (- bitmask); | |
19052 | ||
19053 | bitmask &= ~ bit; | |
19054 | switch (bit) | |
19055 | { | |
19056 | case GNU_PROPERTY_AARCH64_FEATURE_1_BTI: | |
19057 | printf ("BTI"); | |
19058 | break; | |
19059 | ||
19060 | case GNU_PROPERTY_AARCH64_FEATURE_1_PAC: | |
19061 | printf ("PAC"); | |
19062 | break; | |
19063 | ||
19064 | default: | |
19065 | printf (_("<unknown: %x>"), bit); | |
19066 | break; | |
19067 | } | |
19068 | if (bitmask) | |
19069 | printf (", "); | |
19070 | } | |
19071 | } | |
19072 | ||
19073 | static void | |
19074 | print_gnu_property_note (Filedata * filedata, Elf_Internal_Note * pnote) | |
19075 | { | |
19076 | unsigned char * ptr = (unsigned char *) pnote->descdata; | |
19077 | unsigned char * ptr_end = ptr + pnote->descsz; | |
19078 | unsigned int size = is_32bit_elf ? 4 : 8; | |
19079 | ||
19080 | printf (_(" Properties: ")); | |
19081 | ||
19082 | if (pnote->descsz < 8 || (pnote->descsz % size) != 0) | |
19083 | { | |
19084 | printf (_("<corrupt GNU_PROPERTY_TYPE, size = %#lx>\n"), pnote->descsz); | |
19085 | return; | |
19086 | } | |
19087 | ||
19088 | while (ptr < ptr_end) | |
19089 | { | |
19090 | unsigned int j; | |
19091 | unsigned int type; | |
19092 | unsigned int datasz; | |
19093 | ||
19094 | if ((size_t) (ptr_end - ptr) < 8) | |
19095 | { | |
19096 | printf (_("<corrupt descsz: %#lx>\n"), pnote->descsz); | |
19097 | break; | |
19098 | } | |
19099 | ||
19100 | type = byte_get (ptr, 4); | |
19101 | datasz = byte_get (ptr + 4, 4); | |
19102 | ||
19103 | ptr += 8; | |
19104 | ||
19105 | if (datasz > (size_t) (ptr_end - ptr)) | |
19106 | { | |
19107 | printf (_("<corrupt type (%#x) datasz: %#x>\n"), | |
19108 | type, datasz); | |
19109 | break; | |
19110 | } | |
19111 | ||
19112 | if (type >= GNU_PROPERTY_LOPROC && type <= GNU_PROPERTY_HIPROC) | |
19113 | { | |
19114 | if (filedata->file_header.e_machine == EM_X86_64 | |
19115 | || filedata->file_header.e_machine == EM_IAMCU | |
19116 | || filedata->file_header.e_machine == EM_386) | |
19117 | { | |
19118 | unsigned int bitmask; | |
19119 | ||
19120 | if (datasz == 4) | |
19121 | bitmask = byte_get (ptr, 4); | |
19122 | else | |
19123 | bitmask = 0; | |
19124 | ||
19125 | switch (type) | |
19126 | { | |
19127 | case GNU_PROPERTY_X86_ISA_1_USED: | |
19128 | if (datasz != 4) | |
19129 | printf (_("x86 ISA used: <corrupt length: %#x> "), | |
19130 | datasz); | |
19131 | else | |
19132 | { | |
19133 | printf ("x86 ISA used: "); | |
19134 | decode_x86_isa (bitmask); | |
19135 | } | |
19136 | goto next; | |
19137 | ||
19138 | case GNU_PROPERTY_X86_ISA_1_NEEDED: | |
19139 | if (datasz != 4) | |
19140 | printf (_("x86 ISA needed: <corrupt length: %#x> "), | |
19141 | datasz); | |
19142 | else | |
19143 | { | |
19144 | printf ("x86 ISA needed: "); | |
19145 | decode_x86_isa (bitmask); | |
19146 | } | |
19147 | goto next; | |
19148 | ||
19149 | case GNU_PROPERTY_X86_FEATURE_1_AND: | |
19150 | if (datasz != 4) | |
19151 | printf (_("x86 feature: <corrupt length: %#x> "), | |
19152 | datasz); | |
19153 | else | |
19154 | { | |
19155 | printf ("x86 feature: "); | |
19156 | decode_x86_feature_1 (bitmask); | |
19157 | } | |
19158 | goto next; | |
19159 | ||
19160 | case GNU_PROPERTY_X86_FEATURE_2_USED: | |
19161 | if (datasz != 4) | |
19162 | printf (_("x86 feature used: <corrupt length: %#x> "), | |
19163 | datasz); | |
19164 | else | |
19165 | { | |
19166 | printf ("x86 feature used: "); | |
19167 | decode_x86_feature_2 (bitmask); | |
19168 | } | |
19169 | goto next; | |
19170 | ||
19171 | case GNU_PROPERTY_X86_FEATURE_2_NEEDED: | |
19172 | if (datasz != 4) | |
19173 | printf (_("x86 feature needed: <corrupt length: %#x> "), datasz); | |
19174 | else | |
19175 | { | |
19176 | printf ("x86 feature needed: "); | |
19177 | decode_x86_feature_2 (bitmask); | |
19178 | } | |
19179 | goto next; | |
19180 | ||
19181 | case GNU_PROPERTY_X86_COMPAT_ISA_1_USED: | |
19182 | if (datasz != 4) | |
19183 | printf (_("x86 ISA used: <corrupt length: %#x> "), | |
19184 | datasz); | |
19185 | else | |
19186 | { | |
19187 | printf ("x86 ISA used: "); | |
19188 | decode_x86_compat_isa (bitmask); | |
19189 | } | |
19190 | goto next; | |
19191 | ||
19192 | case GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED: | |
19193 | if (datasz != 4) | |
19194 | printf (_("x86 ISA needed: <corrupt length: %#x> "), | |
19195 | datasz); | |
19196 | else | |
19197 | { | |
19198 | printf ("x86 ISA needed: "); | |
19199 | decode_x86_compat_isa (bitmask); | |
19200 | } | |
19201 | goto next; | |
19202 | ||
19203 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_USED: | |
19204 | if (datasz != 4) | |
19205 | printf (_("x86 ISA used: <corrupt length: %#x> "), | |
19206 | datasz); | |
19207 | else | |
19208 | { | |
19209 | printf ("x86 ISA used: "); | |
19210 | decode_x86_compat_2_isa (bitmask); | |
19211 | } | |
19212 | goto next; | |
19213 | ||
19214 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_NEEDED: | |
19215 | if (datasz != 4) | |
19216 | printf (_("x86 ISA needed: <corrupt length: %#x> "), | |
19217 | datasz); | |
19218 | else | |
19219 | { | |
19220 | printf ("x86 ISA needed: "); | |
19221 | decode_x86_compat_2_isa (bitmask); | |
19222 | } | |
19223 | goto next; | |
19224 | ||
19225 | default: | |
19226 | break; | |
19227 | } | |
19228 | } | |
19229 | else if (filedata->file_header.e_machine == EM_AARCH64) | |
19230 | { | |
19231 | if (type == GNU_PROPERTY_AARCH64_FEATURE_1_AND) | |
19232 | { | |
19233 | printf ("AArch64 feature: "); | |
19234 | if (datasz != 4) | |
19235 | printf (_("<corrupt length: %#x> "), datasz); | |
19236 | else | |
19237 | decode_aarch64_feature_1_and (byte_get (ptr, 4)); | |
19238 | goto next; | |
19239 | } | |
19240 | } | |
19241 | } | |
19242 | else | |
19243 | { | |
19244 | switch (type) | |
19245 | { | |
19246 | case GNU_PROPERTY_STACK_SIZE: | |
19247 | printf (_("stack size: ")); | |
19248 | if (datasz != size) | |
19249 | printf (_("<corrupt length: %#x> "), datasz); | |
19250 | else | |
19251 | printf ("%#lx", (unsigned long) byte_get (ptr, size)); | |
19252 | goto next; | |
19253 | ||
19254 | case GNU_PROPERTY_NO_COPY_ON_PROTECTED: | |
19255 | printf ("no copy on protected "); | |
19256 | if (datasz) | |
19257 | printf (_("<corrupt length: %#x> "), datasz); | |
19258 | goto next; | |
19259 | ||
19260 | default: | |
19261 | break; | |
19262 | } | |
19263 | } | |
19264 | ||
19265 | if (type < GNU_PROPERTY_LOPROC) | |
19266 | printf (_("<unknown type %#x data: "), type); | |
19267 | else if (type < GNU_PROPERTY_LOUSER) | |
19268 | printf (_("<processor-specific type %#x data: "), type); | |
19269 | else | |
19270 | printf (_("<application-specific type %#x data: "), type); | |
19271 | for (j = 0; j < datasz; ++j) | |
19272 | printf ("%02x ", ptr[j] & 0xff); | |
19273 | printf (">"); | |
19274 | ||
19275 | next: | |
19276 | ptr += ((datasz + (size - 1)) & ~ (size - 1)); | |
19277 | if (ptr == ptr_end) | |
19278 | break; | |
19279 | ||
19280 | if (do_wide) | |
19281 | printf (", "); | |
19282 | else | |
19283 | printf ("\n\t"); | |
19284 | } | |
19285 | ||
19286 | printf ("\n"); | |
19287 | } | |
19288 | ||
19289 | static bfd_boolean | |
19290 | print_gnu_note (Filedata * filedata, Elf_Internal_Note *pnote) | |
19291 | { | |
19292 | /* NB/ Keep this switch statement in sync with get_gnu_elf_note_type (). */ | |
19293 | switch (pnote->type) | |
19294 | { | |
19295 | case NT_GNU_BUILD_ID: | |
19296 | { | |
19297 | unsigned long i; | |
19298 | ||
19299 | printf (_(" Build ID: ")); | |
19300 | for (i = 0; i < pnote->descsz; ++i) | |
19301 | printf ("%02x", pnote->descdata[i] & 0xff); | |
19302 | printf ("\n"); | |
19303 | } | |
19304 | break; | |
19305 | ||
19306 | case NT_GNU_ABI_TAG: | |
19307 | { | |
19308 | unsigned long os, major, minor, subminor; | |
19309 | const char *osname; | |
19310 | ||
19311 | /* PR 17531: file: 030-599401-0.004. */ | |
19312 | if (pnote->descsz < 16) | |
19313 | { | |
19314 | printf (_(" <corrupt GNU_ABI_TAG>\n")); | |
19315 | break; | |
19316 | } | |
19317 | ||
19318 | os = byte_get ((unsigned char *) pnote->descdata, 4); | |
19319 | major = byte_get ((unsigned char *) pnote->descdata + 4, 4); | |
19320 | minor = byte_get ((unsigned char *) pnote->descdata + 8, 4); | |
19321 | subminor = byte_get ((unsigned char *) pnote->descdata + 12, 4); | |
19322 | ||
19323 | switch (os) | |
19324 | { | |
19325 | case GNU_ABI_TAG_LINUX: | |
19326 | osname = "Linux"; | |
19327 | break; | |
19328 | case GNU_ABI_TAG_HURD: | |
19329 | osname = "Hurd"; | |
19330 | break; | |
19331 | case GNU_ABI_TAG_SOLARIS: | |
19332 | osname = "Solaris"; | |
19333 | break; | |
19334 | case GNU_ABI_TAG_FREEBSD: | |
19335 | osname = "FreeBSD"; | |
19336 | break; | |
19337 | case GNU_ABI_TAG_NETBSD: | |
19338 | osname = "NetBSD"; | |
19339 | break; | |
19340 | case GNU_ABI_TAG_SYLLABLE: | |
19341 | osname = "Syllable"; | |
19342 | break; | |
19343 | case GNU_ABI_TAG_NACL: | |
19344 | osname = "NaCl"; | |
19345 | break; | |
19346 | default: | |
19347 | osname = "Unknown"; | |
19348 | break; | |
19349 | } | |
19350 | ||
19351 | printf (_(" OS: %s, ABI: %ld.%ld.%ld\n"), osname, | |
19352 | major, minor, subminor); | |
19353 | } | |
19354 | break; | |
19355 | ||
19356 | case NT_GNU_GOLD_VERSION: | |
19357 | { | |
19358 | unsigned long i; | |
19359 | ||
19360 | printf (_(" Version: ")); | |
19361 | for (i = 0; i < pnote->descsz && pnote->descdata[i] != '\0'; ++i) | |
19362 | printf ("%c", pnote->descdata[i]); | |
19363 | printf ("\n"); | |
19364 | } | |
19365 | break; | |
19366 | ||
19367 | case NT_GNU_HWCAP: | |
19368 | { | |
19369 | unsigned long num_entries, mask; | |
19370 | ||
19371 | /* Hardware capabilities information. Word 0 is the number of entries. | |
19372 | Word 1 is a bitmask of enabled entries. The rest of the descriptor | |
19373 | is a series of entries, where each entry is a single byte followed | |
19374 | by a nul terminated string. The byte gives the bit number to test | |
19375 | if enabled in the bitmask. */ | |
19376 | printf (_(" Hardware Capabilities: ")); | |
19377 | if (pnote->descsz < 8) | |
19378 | { | |
19379 | error (_("<corrupt GNU_HWCAP>\n")); | |
19380 | return FALSE; | |
19381 | } | |
19382 | num_entries = byte_get ((unsigned char *) pnote->descdata, 4); | |
19383 | mask = byte_get ((unsigned char *) pnote->descdata + 4, 4); | |
19384 | printf (_("num entries: %ld, enabled mask: %lx\n"), num_entries, mask); | |
19385 | /* FIXME: Add code to display the entries... */ | |
19386 | } | |
19387 | break; | |
19388 | ||
19389 | case NT_GNU_PROPERTY_TYPE_0: | |
19390 | print_gnu_property_note (filedata, pnote); | |
19391 | break; | |
19392 | ||
19393 | default: | |
19394 | /* Handle unrecognised types. An error message should have already been | |
19395 | created by get_gnu_elf_note_type(), so all that we need to do is to | |
19396 | display the data. */ | |
19397 | { | |
19398 | unsigned long i; | |
19399 | ||
19400 | printf (_(" Description data: ")); | |
19401 | for (i = 0; i < pnote->descsz; ++i) | |
19402 | printf ("%02x ", pnote->descdata[i] & 0xff); | |
19403 | printf ("\n"); | |
19404 | } | |
19405 | break; | |
19406 | } | |
19407 | ||
19408 | return TRUE; | |
19409 | } | |
19410 | ||
19411 | static const char * | |
19412 | get_v850_elf_note_type (enum v850_notes n_type) | |
19413 | { | |
19414 | static char buff[64]; | |
19415 | ||
19416 | switch (n_type) | |
19417 | { | |
19418 | case V850_NOTE_ALIGNMENT: return _("Alignment of 8-byte objects"); | |
19419 | case V850_NOTE_DATA_SIZE: return _("Sizeof double and long double"); | |
19420 | case V850_NOTE_FPU_INFO: return _("Type of FPU support needed"); | |
19421 | case V850_NOTE_SIMD_INFO: return _("Use of SIMD instructions"); | |
19422 | case V850_NOTE_CACHE_INFO: return _("Use of cache"); | |
19423 | case V850_NOTE_MMU_INFO: return _("Use of MMU"); | |
19424 | default: | |
19425 | snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), n_type); | |
19426 | return buff; | |
19427 | } | |
19428 | } | |
19429 | ||
19430 | static bfd_boolean | |
19431 | print_v850_note (Elf_Internal_Note * pnote) | |
19432 | { | |
19433 | unsigned int val; | |
19434 | ||
19435 | if (pnote->descsz != 4) | |
19436 | return FALSE; | |
19437 | ||
19438 | val = byte_get ((unsigned char *) pnote->descdata, pnote->descsz); | |
19439 | ||
19440 | if (val == 0) | |
19441 | { | |
19442 | printf (_("not set\n")); | |
19443 | return TRUE; | |
19444 | } | |
19445 | ||
19446 | switch (pnote->type) | |
19447 | { | |
19448 | case V850_NOTE_ALIGNMENT: | |
19449 | switch (val) | |
19450 | { | |
19451 | case EF_RH850_DATA_ALIGN4: printf (_("4-byte\n")); return TRUE; | |
19452 | case EF_RH850_DATA_ALIGN8: printf (_("8-byte\n")); return TRUE; | |
19453 | } | |
19454 | break; | |
19455 | ||
19456 | case V850_NOTE_DATA_SIZE: | |
19457 | switch (val) | |
19458 | { | |
19459 | case EF_RH850_DOUBLE32: printf (_("4-bytes\n")); return TRUE; | |
19460 | case EF_RH850_DOUBLE64: printf (_("8-bytes\n")); return TRUE; | |
19461 | } | |
19462 | break; | |
19463 | ||
19464 | case V850_NOTE_FPU_INFO: | |
19465 | switch (val) | |
19466 | { | |
19467 | case EF_RH850_FPU20: printf (_("FPU-2.0\n")); return TRUE; | |
19468 | case EF_RH850_FPU30: printf (_("FPU-3.0\n")); return TRUE; | |
19469 | } | |
19470 | break; | |
19471 | ||
19472 | case V850_NOTE_MMU_INFO: | |
19473 | case V850_NOTE_CACHE_INFO: | |
19474 | case V850_NOTE_SIMD_INFO: | |
19475 | if (val == EF_RH850_SIMD) | |
19476 | { | |
19477 | printf (_("yes\n")); | |
19478 | return TRUE; | |
19479 | } | |
19480 | break; | |
19481 | ||
19482 | default: | |
19483 | /* An 'unknown note type' message will already have been displayed. */ | |
19484 | break; | |
19485 | } | |
19486 | ||
19487 | printf (_("unknown value: %x\n"), val); | |
19488 | return FALSE; | |
19489 | } | |
19490 | ||
19491 | static bfd_boolean | |
19492 | process_netbsd_elf_note (Elf_Internal_Note * pnote) | |
19493 | { | |
19494 | unsigned int version; | |
19495 | ||
19496 | switch (pnote->type) | |
19497 | { | |
19498 | case NT_NETBSD_IDENT: | |
19499 | if (pnote->descsz < 1) | |
19500 | break; | |
19501 | version = byte_get ((unsigned char *) pnote->descdata, sizeof (version)); | |
19502 | if ((version / 10000) % 100) | |
19503 | printf (" NetBSD\t\t0x%08lx\tIDENT %u (%u.%u%s%c)\n", pnote->descsz, | |
19504 | version, version / 100000000, (version / 1000000) % 100, | |
19505 | (version / 10000) % 100 > 26 ? "Z" : "", | |
19506 | 'A' + (version / 10000) % 26); | |
19507 | else | |
19508 | printf (" NetBSD\t\t0x%08lx\tIDENT %u (%u.%u.%u)\n", pnote->descsz, | |
19509 | version, version / 100000000, (version / 1000000) % 100, | |
19510 | (version / 100) % 100); | |
19511 | return TRUE; | |
19512 | ||
19513 | case NT_NETBSD_MARCH: | |
19514 | printf (" NetBSD\t\t0x%08lx\tMARCH <%s>\n", pnote->descsz, | |
19515 | pnote->descdata); | |
19516 | return TRUE; | |
19517 | ||
19518 | #ifdef NT_NETBSD_PAX | |
19519 | case NT_NETBSD_PAX: | |
19520 | if (pnote->descsz < 1) | |
19521 | break; | |
19522 | version = byte_get ((unsigned char *) pnote->descdata, sizeof (version)); | |
19523 | printf (" NetBSD\t\t0x%08lx\tPaX <%s%s%s%s%s%s>\n", pnote->descsz, | |
19524 | ((version & NT_NETBSD_PAX_MPROTECT) ? "+mprotect" : ""), | |
19525 | ((version & NT_NETBSD_PAX_NOMPROTECT) ? "-mprotect" : ""), | |
19526 | ((version & NT_NETBSD_PAX_GUARD) ? "+guard" : ""), | |
19527 | ((version & NT_NETBSD_PAX_NOGUARD) ? "-guard" : ""), | |
19528 | ((version & NT_NETBSD_PAX_ASLR) ? "+ASLR" : ""), | |
19529 | ((version & NT_NETBSD_PAX_NOASLR) ? "-ASLR" : "")); | |
19530 | return TRUE; | |
19531 | #endif | |
19532 | } | |
19533 | ||
19534 | printf (" NetBSD\t0x%08lx\tUnknown note type: (0x%08lx)\n", | |
19535 | pnote->descsz, pnote->type); | |
19536 | return FALSE; | |
19537 | } | |
19538 | ||
19539 | static const char * | |
19540 | get_freebsd_elfcore_note_type (Filedata * filedata, unsigned e_type) | |
19541 | { | |
19542 | switch (e_type) | |
19543 | { | |
19544 | case NT_FREEBSD_THRMISC: | |
19545 | return _("NT_THRMISC (thrmisc structure)"); | |
19546 | case NT_FREEBSD_PROCSTAT_PROC: | |
19547 | return _("NT_PROCSTAT_PROC (proc data)"); | |
19548 | case NT_FREEBSD_PROCSTAT_FILES: | |
19549 | return _("NT_PROCSTAT_FILES (files data)"); | |
19550 | case NT_FREEBSD_PROCSTAT_VMMAP: | |
19551 | return _("NT_PROCSTAT_VMMAP (vmmap data)"); | |
19552 | case NT_FREEBSD_PROCSTAT_GROUPS: | |
19553 | return _("NT_PROCSTAT_GROUPS (groups data)"); | |
19554 | case NT_FREEBSD_PROCSTAT_UMASK: | |
19555 | return _("NT_PROCSTAT_UMASK (umask data)"); | |
19556 | case NT_FREEBSD_PROCSTAT_RLIMIT: | |
19557 | return _("NT_PROCSTAT_RLIMIT (rlimit data)"); | |
19558 | case NT_FREEBSD_PROCSTAT_OSREL: | |
19559 | return _("NT_PROCSTAT_OSREL (osreldate data)"); | |
19560 | case NT_FREEBSD_PROCSTAT_PSSTRINGS: | |
19561 | return _("NT_PROCSTAT_PSSTRINGS (ps_strings data)"); | |
19562 | case NT_FREEBSD_PROCSTAT_AUXV: | |
19563 | return _("NT_PROCSTAT_AUXV (auxv data)"); | |
19564 | case NT_FREEBSD_PTLWPINFO: | |
19565 | return _("NT_PTLWPINFO (ptrace_lwpinfo structure)"); | |
19566 | } | |
19567 | return get_note_type (filedata, e_type); | |
19568 | } | |
19569 | ||
19570 | static const char * | |
19571 | get_netbsd_elfcore_note_type (Filedata * filedata, unsigned e_type) | |
19572 | { | |
19573 | static char buff[64]; | |
19574 | ||
19575 | switch (e_type) | |
19576 | { | |
19577 | case NT_NETBSDCORE_PROCINFO: | |
19578 | /* NetBSD core "procinfo" structure. */ | |
19579 | return _("NetBSD procinfo structure"); | |
19580 | ||
19581 | #ifdef NT_NETBSDCORE_AUXV | |
19582 | case NT_NETBSDCORE_AUXV: | |
19583 | return _("NetBSD ELF auxiliary vector data"); | |
19584 | #endif | |
19585 | ||
19586 | #ifdef NT_NETBSDCORE_LWPSTATUS | |
19587 | case NT_NETBSDCORE_LWPSTATUS: | |
19588 | return _("PT_LWPSTATUS (ptrace_lwpstatus structure)"); | |
19589 | #endif | |
19590 | ||
19591 | default: | |
19592 | /* As of Jan 2020 there are no other machine-independent notes | |
19593 | defined for NetBSD core files. If the note type is less | |
19594 | than the start of the machine-dependent note types, we don't | |
19595 | understand it. */ | |
19596 | ||
19597 | if (e_type < NT_NETBSDCORE_FIRSTMACH) | |
19598 | { | |
19599 | snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type); | |
19600 | return buff; | |
19601 | } | |
19602 | break; | |
19603 | } | |
19604 | ||
19605 | switch (filedata->file_header.e_machine) | |
19606 | { | |
19607 | /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0 | |
19608 | and PT_GETFPREGS == mach+2. */ | |
19609 | ||
19610 | case EM_OLD_ALPHA: | |
19611 | case EM_ALPHA: | |
19612 | case EM_SPARC: | |
19613 | case EM_SPARC32PLUS: | |
19614 | case EM_SPARCV9: | |
19615 | switch (e_type) | |
19616 | { | |
19617 | case NT_NETBSDCORE_FIRSTMACH + 0: | |
19618 | return _("PT_GETREGS (reg structure)"); | |
19619 | case NT_NETBSDCORE_FIRSTMACH + 2: | |
19620 | return _("PT_GETFPREGS (fpreg structure)"); | |
19621 | default: | |
19622 | break; | |
19623 | } | |
19624 | break; | |
19625 | ||
19626 | /* On SuperH, PT_GETREGS == mach+3 and PT_GETFPREGS == mach+5. | |
19627 | There's also old PT___GETREGS40 == mach + 1 for old reg | |
19628 | structure which lacks GBR. */ | |
19629 | case EM_SH: | |
19630 | switch (e_type) | |
19631 | { | |
19632 | case NT_NETBSDCORE_FIRSTMACH + 1: | |
19633 | return _("PT___GETREGS40 (old reg structure)"); | |
19634 | case NT_NETBSDCORE_FIRSTMACH + 3: | |
19635 | return _("PT_GETREGS (reg structure)"); | |
19636 | case NT_NETBSDCORE_FIRSTMACH + 5: | |
19637 | return _("PT_GETFPREGS (fpreg structure)"); | |
19638 | default: | |
19639 | break; | |
19640 | } | |
19641 | break; | |
19642 | ||
19643 | /* On all other arch's, PT_GETREGS == mach+1 and | |
19644 | PT_GETFPREGS == mach+3. */ | |
19645 | default: | |
19646 | switch (e_type) | |
19647 | { | |
19648 | case NT_NETBSDCORE_FIRSTMACH + 1: | |
19649 | return _("PT_GETREGS (reg structure)"); | |
19650 | case NT_NETBSDCORE_FIRSTMACH + 3: | |
19651 | return _("PT_GETFPREGS (fpreg structure)"); | |
19652 | default: | |
19653 | break; | |
19654 | } | |
19655 | } | |
19656 | ||
19657 | snprintf (buff, sizeof (buff), "PT_FIRSTMACH+%d", | |
19658 | e_type - NT_NETBSDCORE_FIRSTMACH); | |
19659 | return buff; | |
19660 | } | |
19661 | ||
19662 | static const char * | |
19663 | get_stapsdt_note_type (unsigned e_type) | |
19664 | { | |
19665 | static char buff[64]; | |
19666 | ||
19667 | switch (e_type) | |
19668 | { | |
19669 | case NT_STAPSDT: | |
19670 | return _("NT_STAPSDT (SystemTap probe descriptors)"); | |
19671 | ||
19672 | default: | |
19673 | break; | |
19674 | } | |
19675 | ||
19676 | snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type); | |
19677 | return buff; | |
19678 | } | |
19679 | ||
19680 | static bfd_boolean | |
19681 | print_stapsdt_note (Elf_Internal_Note *pnote) | |
19682 | { | |
19683 | size_t len, maxlen; | |
19684 | unsigned long addr_size = is_32bit_elf ? 4 : 8; | |
19685 | char *data = pnote->descdata; | |
19686 | char *data_end = pnote->descdata + pnote->descsz; | |
19687 | bfd_vma pc, base_addr, semaphore; | |
19688 | char *provider, *probe, *arg_fmt; | |
19689 | ||
19690 | if (pnote->descsz < (addr_size * 3)) | |
19691 | goto stapdt_note_too_small; | |
19692 | ||
19693 | pc = byte_get ((unsigned char *) data, addr_size); | |
19694 | data += addr_size; | |
19695 | ||
19696 | base_addr = byte_get ((unsigned char *) data, addr_size); | |
19697 | data += addr_size; | |
19698 | ||
19699 | semaphore = byte_get ((unsigned char *) data, addr_size); | |
19700 | data += addr_size; | |
19701 | ||
19702 | if (data >= data_end) | |
19703 | goto stapdt_note_too_small; | |
19704 | maxlen = data_end - data; | |
19705 | len = strnlen (data, maxlen); | |
19706 | if (len < maxlen) | |
19707 | { | |
19708 | provider = data; | |
19709 | data += len + 1; | |
19710 | } | |
19711 | else | |
19712 | goto stapdt_note_too_small; | |
19713 | ||
19714 | if (data >= data_end) | |
19715 | goto stapdt_note_too_small; | |
19716 | maxlen = data_end - data; | |
19717 | len = strnlen (data, maxlen); | |
19718 | if (len < maxlen) | |
19719 | { | |
19720 | probe = data; | |
19721 | data += len + 1; | |
19722 | } | |
19723 | else | |
19724 | goto stapdt_note_too_small; | |
19725 | ||
19726 | if (data >= data_end) | |
19727 | goto stapdt_note_too_small; | |
19728 | maxlen = data_end - data; | |
19729 | len = strnlen (data, maxlen); | |
19730 | if (len < maxlen) | |
19731 | { | |
19732 | arg_fmt = data; | |
19733 | data += len + 1; | |
19734 | } | |
19735 | else | |
19736 | goto stapdt_note_too_small; | |
19737 | ||
19738 | printf (_(" Provider: %s\n"), provider); | |
19739 | printf (_(" Name: %s\n"), probe); | |
19740 | printf (_(" Location: ")); | |
19741 | print_vma (pc, FULL_HEX); | |
19742 | printf (_(", Base: ")); | |
19743 | print_vma (base_addr, FULL_HEX); | |
19744 | printf (_(", Semaphore: ")); | |
19745 | print_vma (semaphore, FULL_HEX); | |
19746 | printf ("\n"); | |
19747 | printf (_(" Arguments: %s\n"), arg_fmt); | |
19748 | ||
19749 | return data == data_end; | |
19750 | ||
19751 | stapdt_note_too_small: | |
19752 | printf (_(" <corrupt - note is too small>\n")); | |
19753 | error (_("corrupt stapdt note - the data size is too small\n")); | |
19754 | return FALSE; | |
19755 | } | |
19756 | ||
19757 | static const char * | |
19758 | get_ia64_vms_note_type (unsigned e_type) | |
19759 | { | |
19760 | static char buff[64]; | |
19761 | ||
19762 | switch (e_type) | |
19763 | { | |
19764 | case NT_VMS_MHD: | |
19765 | return _("NT_VMS_MHD (module header)"); | |
19766 | case NT_VMS_LNM: | |
19767 | return _("NT_VMS_LNM (language name)"); | |
19768 | case NT_VMS_SRC: | |
19769 | return _("NT_VMS_SRC (source files)"); | |
19770 | case NT_VMS_TITLE: | |
19771 | return "NT_VMS_TITLE"; | |
19772 | case NT_VMS_EIDC: | |
19773 | return _("NT_VMS_EIDC (consistency check)"); | |
19774 | case NT_VMS_FPMODE: | |
19775 | return _("NT_VMS_FPMODE (FP mode)"); | |
19776 | case NT_VMS_LINKTIME: | |
19777 | return "NT_VMS_LINKTIME"; | |
19778 | case NT_VMS_IMGNAM: | |
19779 | return _("NT_VMS_IMGNAM (image name)"); | |
19780 | case NT_VMS_IMGID: | |
19781 | return _("NT_VMS_IMGID (image id)"); | |
19782 | case NT_VMS_LINKID: | |
19783 | return _("NT_VMS_LINKID (link id)"); | |
19784 | case NT_VMS_IMGBID: | |
19785 | return _("NT_VMS_IMGBID (build id)"); | |
19786 | case NT_VMS_GSTNAM: | |
19787 | return _("NT_VMS_GSTNAM (sym table name)"); | |
19788 | case NT_VMS_ORIG_DYN: | |
19789 | return "NT_VMS_ORIG_DYN"; | |
19790 | case NT_VMS_PATCHTIME: | |
19791 | return "NT_VMS_PATCHTIME"; | |
19792 | default: | |
19793 | snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type); | |
19794 | return buff; | |
19795 | } | |
19796 | } | |
19797 | ||
19798 | static bfd_boolean | |
19799 | print_ia64_vms_note (Elf_Internal_Note * pnote) | |
19800 | { | |
19801 | int maxlen = pnote->descsz; | |
19802 | ||
19803 | if (maxlen < 2 || (unsigned long) maxlen != pnote->descsz) | |
19804 | goto desc_size_fail; | |
19805 | ||
19806 | switch (pnote->type) | |
19807 | { | |
19808 | case NT_VMS_MHD: | |
19809 | if (maxlen <= 36) | |
19810 | goto desc_size_fail; | |
19811 | ||
19812 | int l = (int) strnlen (pnote->descdata + 34, maxlen - 34); | |
19813 | ||
19814 | printf (_(" Creation date : %.17s\n"), pnote->descdata); | |
19815 | printf (_(" Last patch date: %.17s\n"), pnote->descdata + 17); | |
19816 | if (l + 34 < maxlen) | |
19817 | { | |
19818 | printf (_(" Module name : %s\n"), pnote->descdata + 34); | |
19819 | if (l + 35 < maxlen) | |
19820 | printf (_(" Module version : %s\n"), pnote->descdata + 34 + l + 1); | |
19821 | else | |
19822 | printf (_(" Module version : <missing>\n")); | |
19823 | } | |
19824 | else | |
19825 | { | |
19826 | printf (_(" Module name : <missing>\n")); | |
19827 | printf (_(" Module version : <missing>\n")); | |
19828 | } | |
19829 | break; | |
19830 | ||
19831 | case NT_VMS_LNM: | |
19832 | printf (_(" Language: %.*s\n"), maxlen, pnote->descdata); | |
19833 | break; | |
19834 | ||
19835 | #ifdef BFD64 | |
19836 | case NT_VMS_FPMODE: | |
19837 | printf (_(" Floating Point mode: ")); | |
19838 | if (maxlen < 8) | |
19839 | goto desc_size_fail; | |
19840 | /* FIXME: Generate an error if descsz > 8 ? */ | |
19841 | ||
19842 | printf ("0x%016" BFD_VMA_FMT "x\n", | |
19843 | (bfd_vma) byte_get ((unsigned char *)pnote->descdata, 8)); | |
19844 | break; | |
19845 | ||
19846 | case NT_VMS_LINKTIME: | |
19847 | printf (_(" Link time: ")); | |
19848 | if (maxlen < 8) | |
19849 | goto desc_size_fail; | |
19850 | /* FIXME: Generate an error if descsz > 8 ? */ | |
19851 | ||
19852 | print_vms_time | |
19853 | ((bfd_int64_t) byte_get ((unsigned char *)pnote->descdata, 8)); | |
19854 | printf ("\n"); | |
19855 | break; | |
19856 | ||
19857 | case NT_VMS_PATCHTIME: | |
19858 | printf (_(" Patch time: ")); | |
19859 | if (maxlen < 8) | |
19860 | goto desc_size_fail; | |
19861 | /* FIXME: Generate an error if descsz > 8 ? */ | |
19862 | ||
19863 | print_vms_time | |
19864 | ((bfd_int64_t) byte_get ((unsigned char *)pnote->descdata, 8)); | |
19865 | printf ("\n"); | |
19866 | break; | |
19867 | ||
19868 | case NT_VMS_ORIG_DYN: | |
19869 | if (maxlen < 34) | |
19870 | goto desc_size_fail; | |
19871 | ||
19872 | printf (_(" Major id: %u, minor id: %u\n"), | |
19873 | (unsigned) byte_get ((unsigned char *)pnote->descdata, 4), | |
19874 | (unsigned) byte_get ((unsigned char *)pnote->descdata + 4, 4)); | |
19875 | printf (_(" Last modified : ")); | |
19876 | print_vms_time | |
19877 | ((bfd_int64_t) byte_get ((unsigned char *)pnote->descdata + 8, 8)); | |
19878 | printf (_("\n Link flags : ")); | |
19879 | printf ("0x%016" BFD_VMA_FMT "x\n", | |
19880 | (bfd_vma) byte_get ((unsigned char *)pnote->descdata + 16, 8)); | |
19881 | printf (_(" Header flags: 0x%08x\n"), | |
19882 | (unsigned) byte_get ((unsigned char *)pnote->descdata + 24, 4)); | |
19883 | printf (_(" Image id : %.*s\n"), maxlen - 32, pnote->descdata + 32); | |
19884 | break; | |
19885 | #endif | |
19886 | ||
19887 | case NT_VMS_IMGNAM: | |
19888 | printf (_(" Image name: %.*s\n"), maxlen, pnote->descdata); | |
19889 | break; | |
19890 | ||
19891 | case NT_VMS_GSTNAM: | |
19892 | printf (_(" Global symbol table name: %.*s\n"), maxlen, pnote->descdata); | |
19893 | break; | |
19894 | ||
19895 | case NT_VMS_IMGID: | |
19896 | printf (_(" Image id: %.*s\n"), maxlen, pnote->descdata); | |
19897 | break; | |
19898 | ||
19899 | case NT_VMS_LINKID: | |
19900 | printf (_(" Linker id: %.*s\n"), maxlen, pnote->descdata); | |
19901 | break; | |
19902 | ||
19903 | default: | |
19904 | return FALSE; | |
19905 | } | |
19906 | ||
19907 | return TRUE; | |
19908 | ||
19909 | desc_size_fail: | |
19910 | printf (_(" <corrupt - data size is too small>\n")); | |
19911 | error (_("corrupt IA64 note: data size is too small\n")); | |
19912 | return FALSE; | |
19913 | } | |
19914 | ||
19915 | struct build_attr_cache { | |
19916 | Filedata *filedata; | |
19917 | char *strtab; | |
19918 | unsigned long strtablen; | |
19919 | Elf_Internal_Sym *symtab; | |
19920 | unsigned long nsyms; | |
19921 | } ba_cache; | |
19922 | ||
19923 | /* Find the symbol associated with a build attribute that is attached | |
19924 | to address OFFSET. If PNAME is non-NULL then store the name of | |
19925 | the symbol (if found) in the provided pointer, Returns NULL if a | |
19926 | symbol could not be found. */ | |
19927 | ||
19928 | static Elf_Internal_Sym * | |
19929 | get_symbol_for_build_attribute (Filedata * filedata, | |
19930 | unsigned long offset, | |
19931 | bfd_boolean is_open_attr, | |
19932 | const char ** pname) | |
19933 | { | |
19934 | Elf_Internal_Sym *saved_sym = NULL; | |
19935 | Elf_Internal_Sym *sym; | |
19936 | ||
19937 | if (filedata->section_headers != NULL | |
19938 | && (ba_cache.filedata == NULL || filedata != ba_cache.filedata)) | |
19939 | { | |
19940 | Elf_Internal_Shdr * symsec; | |
19941 | ||
19942 | free (ba_cache.strtab); | |
19943 | ba_cache.strtab = NULL; | |
19944 | free (ba_cache.symtab); | |
19945 | ba_cache.symtab = NULL; | |
19946 | ||
19947 | /* Load the symbol and string sections. */ | |
19948 | for (symsec = filedata->section_headers; | |
19949 | symsec < filedata->section_headers + filedata->file_header.e_shnum; | |
19950 | symsec ++) | |
19951 | { | |
19952 | if (symsec->sh_type == SHT_SYMTAB | |
19953 | && get_symtab (filedata, symsec, | |
19954 | &ba_cache.symtab, &ba_cache.nsyms, | |
19955 | &ba_cache.strtab, &ba_cache.strtablen)) | |
19956 | break; | |
19957 | } | |
19958 | ba_cache.filedata = filedata; | |
19959 | } | |
19960 | ||
19961 | if (ba_cache.symtab == NULL) | |
19962 | return NULL; | |
19963 | ||
19964 | /* Find a symbol whose value matches offset. */ | |
19965 | for (sym = ba_cache.symtab; sym < ba_cache.symtab + ba_cache.nsyms; sym ++) | |
19966 | if (sym->st_value == offset) | |
19967 | { | |
19968 | if (sym->st_name >= ba_cache.strtablen) | |
19969 | /* Huh ? This should not happen. */ | |
19970 | continue; | |
19971 | ||
19972 | if (ba_cache.strtab[sym->st_name] == 0) | |
19973 | continue; | |
19974 | ||
19975 | /* The AArch64 and ARM architectures define mapping symbols | |
19976 | (eg $d, $x, $t) which we want to ignore. */ | |
19977 | if (ba_cache.strtab[sym->st_name] == '$' | |
19978 | && ba_cache.strtab[sym->st_name + 1] != 0 | |
19979 | && ba_cache.strtab[sym->st_name + 2] == 0) | |
19980 | continue; | |
19981 | ||
19982 | if (is_open_attr) | |
19983 | { | |
19984 | /* For OPEN attributes we prefer GLOBAL over LOCAL symbols | |
19985 | and FILE or OBJECT symbols over NOTYPE symbols. We skip | |
19986 | FUNC symbols entirely. */ | |
19987 | switch (ELF_ST_TYPE (sym->st_info)) | |
19988 | { | |
19989 | case STT_OBJECT: | |
19990 | case STT_FILE: | |
19991 | saved_sym = sym; | |
19992 | if (sym->st_size) | |
19993 | { | |
19994 | /* If the symbol has a size associated | |
19995 | with it then we can stop searching. */ | |
19996 | sym = ba_cache.symtab + ba_cache.nsyms; | |
19997 | } | |
19998 | continue; | |
19999 | ||
20000 | case STT_FUNC: | |
20001 | /* Ignore function symbols. */ | |
20002 | continue; | |
20003 | ||
20004 | default: | |
20005 | break; | |
20006 | } | |
20007 | ||
20008 | switch (ELF_ST_BIND (sym->st_info)) | |
20009 | { | |
20010 | case STB_GLOBAL: | |
20011 | if (saved_sym == NULL | |
20012 | || ELF_ST_TYPE (saved_sym->st_info) != STT_OBJECT) | |
20013 | saved_sym = sym; | |
20014 | break; | |
20015 | ||
20016 | case STB_LOCAL: | |
20017 | if (saved_sym == NULL) | |
20018 | saved_sym = sym; | |
20019 | break; | |
20020 | ||
20021 | default: | |
20022 | break; | |
20023 | } | |
20024 | } | |
20025 | else | |
20026 | { | |
20027 | if (ELF_ST_TYPE (sym->st_info) != STT_FUNC) | |
20028 | continue; | |
20029 | ||
20030 | saved_sym = sym; | |
20031 | break; | |
20032 | } | |
20033 | } | |
20034 | ||
20035 | if (saved_sym && pname) | |
20036 | * pname = ba_cache.strtab + saved_sym->st_name; | |
20037 | ||
20038 | return saved_sym; | |
20039 | } | |
20040 | ||
20041 | /* Returns true iff addr1 and addr2 are in the same section. */ | |
20042 | ||
20043 | static bfd_boolean | |
20044 | same_section (Filedata * filedata, unsigned long addr1, unsigned long addr2) | |
20045 | { | |
20046 | Elf_Internal_Shdr * a1; | |
20047 | Elf_Internal_Shdr * a2; | |
20048 | ||
20049 | a1 = find_section_by_address (filedata, addr1); | |
20050 | a2 = find_section_by_address (filedata, addr2); | |
20051 | ||
20052 | return a1 == a2 && a1 != NULL; | |
20053 | } | |
20054 | ||
20055 | static bfd_boolean | |
20056 | print_gnu_build_attribute_description (Elf_Internal_Note * pnote, | |
20057 | Filedata * filedata) | |
20058 | { | |
20059 | static unsigned long global_offset = 0; | |
20060 | static unsigned long global_end = 0; | |
20061 | static unsigned long func_offset = 0; | |
20062 | static unsigned long func_end = 0; | |
20063 | ||
20064 | Elf_Internal_Sym * sym; | |
20065 | const char * name; | |
20066 | unsigned long start; | |
20067 | unsigned long end; | |
20068 | bfd_boolean is_open_attr = pnote->type == NT_GNU_BUILD_ATTRIBUTE_OPEN; | |
20069 | ||
20070 | switch (pnote->descsz) | |
20071 | { | |
20072 | case 0: | |
20073 | /* A zero-length description means that the range of | |
20074 | the previous note of the same type should be used. */ | |
20075 | if (is_open_attr) | |
20076 | { | |
20077 | if (global_end > global_offset) | |
20078 | printf (_(" Applies to region from %#lx to %#lx\n"), | |
20079 | global_offset, global_end); | |
20080 | else | |
20081 | printf (_(" Applies to region from %#lx\n"), global_offset); | |
20082 | } | |
20083 | else | |
20084 | { | |
20085 | if (func_end > func_offset) | |
20086 | printf (_(" Applies to region from %#lx to %#lx\n"), func_offset, func_end); | |
20087 | else | |
20088 | printf (_(" Applies to region from %#lx\n"), func_offset); | |
20089 | } | |
20090 | return TRUE; | |
20091 | ||
20092 | case 4: | |
20093 | start = byte_get ((unsigned char *) pnote->descdata, 4); | |
20094 | end = 0; | |
20095 | break; | |
20096 | ||
20097 | case 8: | |
20098 | start = byte_get ((unsigned char *) pnote->descdata, 4); | |
20099 | end = byte_get ((unsigned char *) pnote->descdata + 4, 4); | |
20100 | break; | |
20101 | ||
20102 | case 16: | |
20103 | start = byte_get ((unsigned char *) pnote->descdata, 8); | |
20104 | end = byte_get ((unsigned char *) pnote->descdata + 8, 8); | |
20105 | break; | |
20106 | ||
20107 | default: | |
20108 | error (_(" <invalid description size: %lx>\n"), pnote->descsz); | |
20109 | printf (_(" <invalid descsz>")); | |
20110 | return FALSE; | |
20111 | } | |
20112 | ||
20113 | name = NULL; | |
20114 | sym = get_symbol_for_build_attribute (filedata, start, is_open_attr, & name); | |
20115 | /* As of version 5 of the annobin plugin, filename symbols are biased by 2 | |
20116 | in order to avoid them being confused with the start address of the | |
20117 | first function in the file... */ | |
20118 | if (sym == NULL && is_open_attr) | |
20119 | sym = get_symbol_for_build_attribute (filedata, start + 2, is_open_attr, | |
20120 | & name); | |
20121 | ||
20122 | if (end == 0 && sym != NULL && sym->st_size > 0) | |
20123 | end = start + sym->st_size; | |
20124 | ||
20125 | if (is_open_attr) | |
20126 | { | |
20127 | /* FIXME: Need to properly allow for section alignment. | |
20128 | 16 is just the alignment used on x86_64. */ | |
20129 | if (global_end > 0 | |
20130 | && start > BFD_ALIGN (global_end, 16) | |
20131 | /* Build notes are not guaranteed to be organised in order of | |
20132 | increasing address, but we should find the all of the notes | |
20133 | for one section in the same place. */ | |
20134 | && same_section (filedata, start, global_end)) | |
20135 | warn (_("Gap in build notes detected from %#lx to %#lx\n"), | |
20136 | global_end + 1, start - 1); | |
20137 | ||
20138 | printf (_(" Applies to region from %#lx"), start); | |
20139 | global_offset = start; | |
20140 | ||
20141 | if (end) | |
20142 | { | |
20143 | printf (_(" to %#lx"), end); | |
20144 | global_end = end; | |
20145 | } | |
20146 | } | |
20147 | else | |
20148 | { | |
20149 | printf (_(" Applies to region from %#lx"), start); | |
20150 | func_offset = start; | |
20151 | ||
20152 | if (end) | |
20153 | { | |
20154 | printf (_(" to %#lx"), end); | |
20155 | func_end = end; | |
20156 | } | |
20157 | } | |
20158 | ||
20159 | if (sym && name) | |
20160 | printf (_(" (%s)"), name); | |
20161 | ||
20162 | printf ("\n"); | |
20163 | return TRUE; | |
20164 | } | |
20165 | ||
20166 | static bfd_boolean | |
20167 | print_gnu_build_attribute_name (Elf_Internal_Note * pnote) | |
20168 | { | |
20169 | static const char string_expected [2] = { GNU_BUILD_ATTRIBUTE_TYPE_STRING, 0 }; | |
20170 | static const char number_expected [2] = { GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC, 0 }; | |
20171 | static const char bool_expected [3] = { GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE, GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE, 0 }; | |
20172 | char name_type; | |
20173 | char name_attribute; | |
20174 | const char * expected_types; | |
20175 | const char * name = pnote->namedata; | |
20176 | const char * text; | |
20177 | signed int left; | |
20178 | ||
20179 | if (name == NULL || pnote->namesz < 2) | |
20180 | { | |
20181 | error (_("corrupt name field in GNU build attribute note: size = %ld\n"), pnote->namesz); | |
20182 | print_symbol (-20, _(" <corrupt name>")); | |
20183 | return FALSE; | |
20184 | } | |
20185 | ||
20186 | if (do_wide) | |
20187 | left = 28; | |
20188 | else | |
20189 | left = 20; | |
20190 | ||
20191 | /* Version 2 of the spec adds a "GA" prefix to the name field. */ | |
20192 | if (name[0] == 'G' && name[1] == 'A') | |
20193 | { | |
20194 | if (pnote->namesz < 4) | |
20195 | { | |
20196 | error (_("corrupt name field in GNU build attribute note: size = %ld\n"), pnote->namesz); | |
20197 | print_symbol (-20, _(" <corrupt name>")); | |
20198 | return FALSE; | |
20199 | } | |
20200 | ||
20201 | printf ("GA"); | |
20202 | name += 2; | |
20203 | left -= 2; | |
20204 | } | |
20205 | ||
20206 | switch ((name_type = * name)) | |
20207 | { | |
20208 | case GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC: | |
20209 | case GNU_BUILD_ATTRIBUTE_TYPE_STRING: | |
20210 | case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE: | |
20211 | case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE: | |
20212 | printf ("%c", * name); | |
20213 | left --; | |
20214 | break; | |
20215 | default: | |
20216 | error (_("unrecognised attribute type in name field: %d\n"), name_type); | |
20217 | print_symbol (-20, _("<unknown name type>")); | |
20218 | return FALSE; | |
20219 | } | |
20220 | ||
20221 | ++ name; | |
20222 | text = NULL; | |
20223 | ||
20224 | switch ((name_attribute = * name)) | |
20225 | { | |
20226 | case GNU_BUILD_ATTRIBUTE_VERSION: | |
20227 | text = _("<version>"); | |
20228 | expected_types = string_expected; | |
20229 | ++ name; | |
20230 | break; | |
20231 | case GNU_BUILD_ATTRIBUTE_STACK_PROT: | |
20232 | text = _("<stack prot>"); | |
20233 | expected_types = "!+*"; | |
20234 | ++ name; | |
20235 | break; | |
20236 | case GNU_BUILD_ATTRIBUTE_RELRO: | |
20237 | text = _("<relro>"); | |
20238 | expected_types = bool_expected; | |
20239 | ++ name; | |
20240 | break; | |
20241 | case GNU_BUILD_ATTRIBUTE_STACK_SIZE: | |
20242 | text = _("<stack size>"); | |
20243 | expected_types = number_expected; | |
20244 | ++ name; | |
20245 | break; | |
20246 | case GNU_BUILD_ATTRIBUTE_TOOL: | |
20247 | text = _("<tool>"); | |
20248 | expected_types = string_expected; | |
20249 | ++ name; | |
20250 | break; | |
20251 | case GNU_BUILD_ATTRIBUTE_ABI: | |
20252 | text = _("<ABI>"); | |
20253 | expected_types = "$*"; | |
20254 | ++ name; | |
20255 | break; | |
20256 | case GNU_BUILD_ATTRIBUTE_PIC: | |
20257 | text = _("<PIC>"); | |
20258 | expected_types = number_expected; | |
20259 | ++ name; | |
20260 | break; | |
20261 | case GNU_BUILD_ATTRIBUTE_SHORT_ENUM: | |
20262 | text = _("<short enum>"); | |
20263 | expected_types = bool_expected; | |
20264 | ++ name; | |
20265 | break; | |
20266 | default: | |
20267 | if (ISPRINT (* name)) | |
20268 | { | |
20269 | int len = strnlen (name, pnote->namesz - (name - pnote->namedata)) + 1; | |
20270 | ||
20271 | if (len > left && ! do_wide) | |
20272 | len = left; | |
20273 | printf ("%.*s:", len, name); | |
20274 | left -= len; | |
20275 | name += len; | |
20276 | } | |
20277 | else | |
20278 | { | |
20279 | static char tmpbuf [128]; | |
20280 | ||
20281 | error (_("unrecognised byte in name field: %d\n"), * name); | |
20282 | sprintf (tmpbuf, _("<unknown:_%d>"), * name); | |
20283 | text = tmpbuf; | |
20284 | name ++; | |
20285 | } | |
20286 | expected_types = "*$!+"; | |
20287 | break; | |
20288 | } | |
20289 | ||
20290 | if (text) | |
20291 | left -= printf ("%s", text); | |
20292 | ||
20293 | if (strchr (expected_types, name_type) == NULL) | |
20294 | warn (_("attribute does not have an expected type (%c)\n"), name_type); | |
20295 | ||
20296 | if ((unsigned long)(name - pnote->namedata) > pnote->namesz) | |
20297 | { | |
20298 | error (_("corrupt name field: namesz: %lu but parsing gets to %ld\n"), | |
20299 | (unsigned long) pnote->namesz, | |
20300 | (long) (name - pnote->namedata)); | |
20301 | return FALSE; | |
20302 | } | |
20303 | ||
20304 | if (left < 1 && ! do_wide) | |
20305 | return TRUE; | |
20306 | ||
20307 | switch (name_type) | |
20308 | { | |
20309 | case GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC: | |
20310 | { | |
20311 | unsigned int bytes; | |
20312 | unsigned long long val = 0; | |
20313 | unsigned int shift = 0; | |
20314 | char * decoded = NULL; | |
20315 | ||
20316 | bytes = pnote->namesz - (name - pnote->namedata); | |
20317 | if (bytes > 0) | |
20318 | /* The -1 is because the name field is always 0 terminated, and we | |
20319 | want to be able to ensure that the shift in the while loop below | |
20320 | will not overflow. */ | |
20321 | -- bytes; | |
20322 | ||
20323 | if (bytes > sizeof (val)) | |
20324 | { | |
20325 | error (_("corrupt numeric name field: too many bytes in the value: %x\n"), | |
20326 | bytes); | |
20327 | bytes = sizeof (val); | |
20328 | } | |
20329 | /* We do not bother to warn if bytes == 0 as this can | |
20330 | happen with some early versions of the gcc plugin. */ | |
20331 | ||
20332 | while (bytes --) | |
20333 | { | |
20334 | unsigned long long byte = *name++ & 0xff; | |
20335 | ||
20336 | val |= byte << shift; | |
20337 | shift += 8; | |
20338 | } | |
20339 | ||
20340 | switch (name_attribute) | |
20341 | { | |
20342 | case GNU_BUILD_ATTRIBUTE_PIC: | |
20343 | switch (val) | |
20344 | { | |
20345 | case 0: decoded = "static"; break; | |
20346 | case 1: decoded = "pic"; break; | |
20347 | case 2: decoded = "PIC"; break; | |
20348 | case 3: decoded = "pie"; break; | |
20349 | case 4: decoded = "PIE"; break; | |
20350 | default: break; | |
20351 | } | |
20352 | break; | |
20353 | case GNU_BUILD_ATTRIBUTE_STACK_PROT: | |
20354 | switch (val) | |
20355 | { | |
20356 | /* Based upon the SPCT_FLAG_xxx enum values in gcc/cfgexpand.c. */ | |
20357 | case 0: decoded = "off"; break; | |
20358 | case 1: decoded = "on"; break; | |
20359 | case 2: decoded = "all"; break; | |
20360 | case 3: decoded = "strong"; break; | |
20361 | case 4: decoded = "explicit"; break; | |
20362 | default: break; | |
20363 | } | |
20364 | break; | |
20365 | default: | |
20366 | break; | |
20367 | } | |
20368 | ||
20369 | if (decoded != NULL) | |
20370 | { | |
20371 | print_symbol (-left, decoded); | |
20372 | left = 0; | |
20373 | } | |
20374 | else if (val == 0) | |
20375 | { | |
20376 | printf ("0x0"); | |
20377 | left -= 3; | |
20378 | } | |
20379 | else | |
20380 | { | |
20381 | if (do_wide) | |
20382 | left -= printf ("0x%llx", val); | |
20383 | else | |
20384 | left -= printf ("0x%-.*llx", left, val); | |
20385 | } | |
20386 | } | |
20387 | break; | |
20388 | case GNU_BUILD_ATTRIBUTE_TYPE_STRING: | |
20389 | left -= print_symbol (- left, name); | |
20390 | break; | |
20391 | case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE: | |
20392 | left -= print_symbol (- left, "true"); | |
20393 | break; | |
20394 | case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE: | |
20395 | left -= print_symbol (- left, "false"); | |
20396 | break; | |
20397 | } | |
20398 | ||
20399 | if (do_wide && left > 0) | |
20400 | printf ("%-*s", left, " "); | |
20401 | ||
20402 | return TRUE; | |
20403 | } | |
20404 | ||
20405 | /* Note that by the ELF standard, the name field is already null byte | |
20406 | terminated, and namesz includes the terminating null byte. | |
20407 | I.E. the value of namesz for the name "FSF" is 4. | |
20408 | ||
20409 | If the value of namesz is zero, there is no name present. */ | |
20410 | ||
20411 | static bfd_boolean | |
20412 | process_note (Elf_Internal_Note * pnote, | |
20413 | Filedata * filedata) | |
20414 | { | |
20415 | const char * name = pnote->namesz ? pnote->namedata : "(NONE)"; | |
20416 | const char * nt; | |
20417 | ||
20418 | if (pnote->namesz == 0) | |
20419 | /* If there is no note name, then use the default set of | |
20420 | note type strings. */ | |
20421 | nt = get_note_type (filedata, pnote->type); | |
20422 | ||
20423 | else if (const_strneq (pnote->namedata, "GNU")) | |
20424 | /* GNU-specific object file notes. */ | |
20425 | nt = get_gnu_elf_note_type (pnote->type); | |
20426 | ||
20427 | else if (const_strneq (pnote->namedata, "FreeBSD")) | |
20428 | /* FreeBSD-specific core file notes. */ | |
20429 | nt = get_freebsd_elfcore_note_type (filedata, pnote->type); | |
20430 | ||
20431 | else if (const_strneq (pnote->namedata, "NetBSD-CORE")) | |
20432 | /* NetBSD-specific core file notes. */ | |
20433 | nt = get_netbsd_elfcore_note_type (filedata, pnote->type); | |
20434 | ||
20435 | else if (const_strneq (pnote->namedata, "NetBSD")) | |
20436 | /* NetBSD-specific core file notes. */ | |
20437 | return process_netbsd_elf_note (pnote); | |
20438 | ||
20439 | else if (const_strneq (pnote->namedata, "PaX")) | |
20440 | /* NetBSD-specific core file notes. */ | |
20441 | return process_netbsd_elf_note (pnote); | |
20442 | ||
20443 | else if (strneq (pnote->namedata, "SPU/", 4)) | |
20444 | { | |
20445 | /* SPU-specific core file notes. */ | |
20446 | nt = pnote->namedata + 4; | |
20447 | name = "SPU"; | |
20448 | } | |
20449 | ||
20450 | else if (const_strneq (pnote->namedata, "IPF/VMS")) | |
20451 | /* VMS/ia64-specific file notes. */ | |
20452 | nt = get_ia64_vms_note_type (pnote->type); | |
20453 | ||
20454 | else if (const_strneq (pnote->namedata, "stapsdt")) | |
20455 | nt = get_stapsdt_note_type (pnote->type); | |
20456 | ||
20457 | else | |
20458 | /* Don't recognize this note name; just use the default set of | |
20459 | note type strings. */ | |
20460 | nt = get_note_type (filedata, pnote->type); | |
20461 | ||
20462 | printf (" "); | |
20463 | ||
20464 | if (((const_strneq (pnote->namedata, "GA") | |
20465 | && strchr ("*$!+", pnote->namedata[2]) != NULL) | |
20466 | || strchr ("*$!+", pnote->namedata[0]) != NULL) | |
20467 | && (pnote->type == NT_GNU_BUILD_ATTRIBUTE_OPEN | |
20468 | || pnote->type == NT_GNU_BUILD_ATTRIBUTE_FUNC)) | |
20469 | print_gnu_build_attribute_name (pnote); | |
20470 | else | |
20471 | print_symbol (-20, name); | |
20472 | ||
20473 | if (do_wide) | |
20474 | printf (" 0x%08lx\t%s\t", pnote->descsz, nt); | |
20475 | else | |
20476 | printf (" 0x%08lx\t%s\n", pnote->descsz, nt); | |
20477 | ||
20478 | if (const_strneq (pnote->namedata, "IPF/VMS")) | |
20479 | return print_ia64_vms_note (pnote); | |
20480 | else if (const_strneq (pnote->namedata, "GNU")) | |
20481 | return print_gnu_note (filedata, pnote); | |
20482 | else if (const_strneq (pnote->namedata, "stapsdt")) | |
20483 | return print_stapsdt_note (pnote); | |
20484 | else if (const_strneq (pnote->namedata, "CORE")) | |
20485 | return print_core_note (pnote); | |
20486 | else if (((const_strneq (pnote->namedata, "GA") | |
20487 | && strchr ("*$!+", pnote->namedata[2]) != NULL) | |
20488 | || strchr ("*$!+", pnote->namedata[0]) != NULL) | |
20489 | && (pnote->type == NT_GNU_BUILD_ATTRIBUTE_OPEN | |
20490 | || pnote->type == NT_GNU_BUILD_ATTRIBUTE_FUNC)) | |
20491 | return print_gnu_build_attribute_description (pnote, filedata); | |
20492 | ||
20493 | if (pnote->descsz) | |
20494 | { | |
20495 | unsigned long i; | |
20496 | ||
20497 | printf (_(" description data: ")); | |
20498 | for (i = 0; i < pnote->descsz; i++) | |
20499 | printf ("%02x ", pnote->descdata[i] & 0xff); | |
20500 | if (!do_wide) | |
20501 | printf ("\n"); | |
20502 | } | |
20503 | ||
20504 | if (do_wide) | |
20505 | printf ("\n"); | |
20506 | ||
20507 | return TRUE; | |
20508 | } | |
20509 | ||
20510 | static bfd_boolean | |
20511 | process_notes_at (Filedata * filedata, | |
20512 | Elf_Internal_Shdr * section, | |
20513 | bfd_vma offset, | |
20514 | bfd_vma length, | |
20515 | bfd_vma align) | |
20516 | { | |
20517 | Elf_External_Note * pnotes; | |
20518 | Elf_External_Note * external; | |
20519 | char * end; | |
20520 | bfd_boolean res = TRUE; | |
20521 | ||
20522 | if (length <= 0) | |
20523 | return FALSE; | |
20524 | ||
20525 | if (section) | |
20526 | { | |
20527 | pnotes = (Elf_External_Note *) get_section_contents (section, filedata); | |
20528 | if (pnotes) | |
20529 | { | |
20530 | if (! apply_relocations (filedata, section, (unsigned char *) pnotes, length, NULL, NULL)) | |
20531 | { | |
20532 | free (pnotes); | |
20533 | return FALSE; | |
20534 | } | |
20535 | } | |
20536 | } | |
20537 | else | |
20538 | pnotes = (Elf_External_Note *) get_data (NULL, filedata, offset, 1, length, | |
20539 | _("notes")); | |
20540 | ||
20541 | if (pnotes == NULL) | |
20542 | return FALSE; | |
20543 | ||
20544 | external = pnotes; | |
20545 | ||
20546 | if (filedata->is_separate) | |
20547 | printf (_("In linked file '%s': "), filedata->file_name); | |
20548 | else | |
20549 | printf ("\n"); | |
20550 | if (section) | |
20551 | printf (_("Displaying notes found in: %s\n"), printable_section_name (filedata, section)); | |
20552 | else | |
20553 | printf (_("Displaying notes found at file offset 0x%08lx with length 0x%08lx:\n"), | |
20554 | (unsigned long) offset, (unsigned long) length); | |
20555 | ||
20556 | /* NB: Some note sections may have alignment value of 0 or 1. gABI | |
20557 | specifies that notes should be aligned to 4 bytes in 32-bit | |
20558 | objects and to 8 bytes in 64-bit objects. As a Linux extension, | |
20559 | we also support 4 byte alignment in 64-bit objects. If section | |
20560 | alignment is less than 4, we treate alignment as 4 bytes. */ | |
20561 | if (align < 4) | |
20562 | align = 4; | |
20563 | else if (align != 4 && align != 8) | |
20564 | { | |
20565 | warn (_("Corrupt note: alignment %ld, expecting 4 or 8\n"), | |
20566 | (long) align); | |
20567 | free (pnotes); | |
20568 | return FALSE; | |
20569 | } | |
20570 | ||
20571 | printf (_(" %-20s %-10s\tDescription\n"), _("Owner"), _("Data size")); | |
20572 | ||
20573 | end = (char *) pnotes + length; | |
20574 | while ((char *) external < end) | |
20575 | { | |
20576 | Elf_Internal_Note inote; | |
20577 | size_t min_notesz; | |
20578 | char * next; | |
20579 | char * temp = NULL; | |
20580 | size_t data_remaining = end - (char *) external; | |
20581 | ||
20582 | if (!is_ia64_vms (filedata)) | |
20583 | { | |
20584 | /* PR binutils/15191 | |
20585 | Make sure that there is enough data to read. */ | |
20586 | min_notesz = offsetof (Elf_External_Note, name); | |
20587 | if (data_remaining < min_notesz) | |
20588 | { | |
20589 | warn (ngettext ("Corrupt note: only %ld byte remains, " | |
20590 | "not enough for a full note\n", | |
20591 | "Corrupt note: only %ld bytes remain, " | |
20592 | "not enough for a full note\n", | |
20593 | data_remaining), | |
20594 | (long) data_remaining); | |
20595 | break; | |
20596 | } | |
20597 | data_remaining -= min_notesz; | |
20598 | ||
20599 | inote.type = BYTE_GET (external->type); | |
20600 | inote.namesz = BYTE_GET (external->namesz); | |
20601 | inote.namedata = external->name; | |
20602 | inote.descsz = BYTE_GET (external->descsz); | |
20603 | inote.descdata = ((char *) external | |
20604 | + ELF_NOTE_DESC_OFFSET (inote.namesz, align)); | |
20605 | inote.descpos = offset + (inote.descdata - (char *) pnotes); | |
20606 | next = ((char *) external | |
20607 | + ELF_NOTE_NEXT_OFFSET (inote.namesz, inote.descsz, align)); | |
20608 | } | |
20609 | else | |
20610 | { | |
20611 | Elf64_External_VMS_Note *vms_external; | |
20612 | ||
20613 | /* PR binutils/15191 | |
20614 | Make sure that there is enough data to read. */ | |
20615 | min_notesz = offsetof (Elf64_External_VMS_Note, name); | |
20616 | if (data_remaining < min_notesz) | |
20617 | { | |
20618 | warn (ngettext ("Corrupt note: only %ld byte remains, " | |
20619 | "not enough for a full note\n", | |
20620 | "Corrupt note: only %ld bytes remain, " | |
20621 | "not enough for a full note\n", | |
20622 | data_remaining), | |
20623 | (long) data_remaining); | |
20624 | break; | |
20625 | } | |
20626 | data_remaining -= min_notesz; | |
20627 | ||
20628 | vms_external = (Elf64_External_VMS_Note *) external; | |
20629 | inote.type = BYTE_GET (vms_external->type); | |
20630 | inote.namesz = BYTE_GET (vms_external->namesz); | |
20631 | inote.namedata = vms_external->name; | |
20632 | inote.descsz = BYTE_GET (vms_external->descsz); | |
20633 | inote.descdata = inote.namedata + align_power (inote.namesz, 3); | |
20634 | inote.descpos = offset + (inote.descdata - (char *) pnotes); | |
20635 | next = inote.descdata + align_power (inote.descsz, 3); | |
20636 | } | |
20637 | ||
20638 | /* PR 17531: file: 3443835e. */ | |
20639 | /* PR 17531: file: id:000000,sig:11,src:006986,op:havoc,rep:4. */ | |
20640 | if ((size_t) (inote.descdata - inote.namedata) < inote.namesz | |
20641 | || (size_t) (inote.descdata - inote.namedata) > data_remaining | |
20642 | || (size_t) (next - inote.descdata) < inote.descsz | |
20643 | || ((size_t) (next - inote.descdata) | |
20644 | > data_remaining - (size_t) (inote.descdata - inote.namedata))) | |
20645 | { | |
20646 | warn (_("note with invalid namesz and/or descsz found at offset 0x%lx\n"), | |
20647 | (unsigned long) ((char *) external - (char *) pnotes)); | |
20648 | warn (_(" type: 0x%lx, namesize: 0x%08lx, descsize: 0x%08lx, alignment: %u\n"), | |
20649 | inote.type, inote.namesz, inote.descsz, (int) align); | |
20650 | break; | |
20651 | } | |
20652 | ||
20653 | external = (Elf_External_Note *) next; | |
20654 | ||
20655 | /* Verify that name is null terminated. It appears that at least | |
20656 | one version of Linux (RedHat 6.0) generates corefiles that don't | |
20657 | comply with the ELF spec by failing to include the null byte in | |
20658 | namesz. */ | |
20659 | if (inote.namesz > 0 && inote.namedata[inote.namesz - 1] != '\0') | |
20660 | { | |
20661 | if ((size_t) (inote.descdata - inote.namedata) == inote.namesz) | |
20662 | { | |
20663 | temp = (char *) malloc (inote.namesz + 1); | |
20664 | if (temp == NULL) | |
20665 | { | |
20666 | error (_("Out of memory allocating space for inote name\n")); | |
20667 | res = FALSE; | |
20668 | break; | |
20669 | } | |
20670 | ||
20671 | memcpy (temp, inote.namedata, inote.namesz); | |
20672 | inote.namedata = temp; | |
20673 | } | |
20674 | inote.namedata[inote.namesz] = 0; | |
20675 | } | |
20676 | ||
20677 | if (! process_note (& inote, filedata)) | |
20678 | res = FALSE; | |
20679 | ||
20680 | free (temp); | |
20681 | temp = NULL; | |
20682 | } | |
20683 | ||
20684 | free (pnotes); | |
20685 | ||
20686 | return res; | |
20687 | } | |
20688 | ||
20689 | static bfd_boolean | |
20690 | process_corefile_note_segments (Filedata * filedata) | |
20691 | { | |
20692 | Elf_Internal_Phdr * segment; | |
20693 | unsigned int i; | |
20694 | bfd_boolean res = TRUE; | |
20695 | ||
20696 | if (! get_program_headers (filedata)) | |
20697 | return TRUE; | |
20698 | ||
20699 | for (i = 0, segment = filedata->program_headers; | |
20700 | i < filedata->file_header.e_phnum; | |
20701 | i++, segment++) | |
20702 | { | |
20703 | if (segment->p_type == PT_NOTE) | |
20704 | if (! process_notes_at (filedata, NULL, | |
20705 | (bfd_vma) segment->p_offset, | |
20706 | (bfd_vma) segment->p_filesz, | |
20707 | (bfd_vma) segment->p_align)) | |
20708 | res = FALSE; | |
20709 | } | |
20710 | ||
20711 | return res; | |
20712 | } | |
20713 | ||
20714 | static bfd_boolean | |
20715 | process_v850_notes (Filedata * filedata, bfd_vma offset, bfd_vma length) | |
20716 | { | |
20717 | Elf_External_Note * pnotes; | |
20718 | Elf_External_Note * external; | |
20719 | char * end; | |
20720 | bfd_boolean res = TRUE; | |
20721 | ||
20722 | if (length <= 0) | |
20723 | return FALSE; | |
20724 | ||
20725 | pnotes = (Elf_External_Note *) get_data (NULL, filedata, offset, 1, length, | |
20726 | _("v850 notes")); | |
20727 | if (pnotes == NULL) | |
20728 | return FALSE; | |
20729 | ||
20730 | external = pnotes; | |
20731 | end = (char*) pnotes + length; | |
20732 | ||
20733 | printf (_("\nDisplaying contents of Renesas V850 notes section at offset 0x%lx with length 0x%lx:\n"), | |
20734 | (unsigned long) offset, (unsigned long) length); | |
20735 | ||
20736 | while ((char *) external + sizeof (Elf_External_Note) < end) | |
20737 | { | |
20738 | Elf_External_Note * next; | |
20739 | Elf_Internal_Note inote; | |
20740 | ||
20741 | inote.type = BYTE_GET (external->type); | |
20742 | inote.namesz = BYTE_GET (external->namesz); | |
20743 | inote.namedata = external->name; | |
20744 | inote.descsz = BYTE_GET (external->descsz); | |
20745 | inote.descdata = inote.namedata + align_power (inote.namesz, 2); | |
20746 | inote.descpos = offset + (inote.descdata - (char *) pnotes); | |
20747 | ||
20748 | if (inote.descdata < (char *) pnotes || inote.descdata >= end) | |
20749 | { | |
20750 | warn (_("Corrupt note: name size is too big: %lx\n"), inote.namesz); | |
20751 | inote.descdata = inote.namedata; | |
20752 | inote.namesz = 0; | |
20753 | } | |
20754 | ||
20755 | next = (Elf_External_Note *) (inote.descdata + align_power (inote.descsz, 2)); | |
20756 | ||
20757 | if ( ((char *) next > end) | |
20758 | || ((char *) next < (char *) pnotes)) | |
20759 | { | |
20760 | warn (_("corrupt descsz found in note at offset 0x%lx\n"), | |
20761 | (unsigned long) ((char *) external - (char *) pnotes)); | |
20762 | warn (_(" type: 0x%lx, namesize: 0x%lx, descsize: 0x%lx\n"), | |
20763 | inote.type, inote.namesz, inote.descsz); | |
20764 | break; | |
20765 | } | |
20766 | ||
20767 | external = next; | |
20768 | ||
20769 | /* Prevent out-of-bounds indexing. */ | |
20770 | if ( inote.namedata + inote.namesz > end | |
20771 | || inote.namedata + inote.namesz < inote.namedata) | |
20772 | { | |
20773 | warn (_("corrupt namesz found in note at offset 0x%lx\n"), | |
20774 | (unsigned long) ((char *) external - (char *) pnotes)); | |
20775 | warn (_(" type: 0x%lx, namesize: 0x%lx, descsize: 0x%lx\n"), | |
20776 | inote.type, inote.namesz, inote.descsz); | |
20777 | break; | |
20778 | } | |
20779 | ||
20780 | printf (" %s: ", get_v850_elf_note_type (inote.type)); | |
20781 | ||
20782 | if (! print_v850_note (& inote)) | |
20783 | { | |
20784 | res = FALSE; | |
20785 | printf ("<corrupt sizes: namesz: %lx, descsz: %lx>\n", | |
20786 | inote.namesz, inote.descsz); | |
20787 | } | |
20788 | } | |
20789 | ||
20790 | free (pnotes); | |
20791 | ||
20792 | return res; | |
20793 | } | |
20794 | ||
20795 | static bfd_boolean | |
20796 | process_note_sections (Filedata * filedata) | |
20797 | { | |
20798 | Elf_Internal_Shdr * section; | |
20799 | unsigned long i; | |
20800 | unsigned int n = 0; | |
20801 | bfd_boolean res = TRUE; | |
20802 | ||
20803 | for (i = 0, section = filedata->section_headers; | |
20804 | i < filedata->file_header.e_shnum && section != NULL; | |
20805 | i++, section++) | |
20806 | { | |
20807 | if (section->sh_type == SHT_NOTE) | |
20808 | { | |
20809 | if (! process_notes_at (filedata, section, | |
20810 | (bfd_vma) section->sh_offset, | |
20811 | (bfd_vma) section->sh_size, | |
20812 | (bfd_vma) section->sh_addralign)) | |
20813 | res = FALSE; | |
20814 | n++; | |
20815 | } | |
20816 | ||
20817 | if (( filedata->file_header.e_machine == EM_V800 | |
20818 | || filedata->file_header.e_machine == EM_V850 | |
20819 | || filedata->file_header.e_machine == EM_CYGNUS_V850) | |
20820 | && section->sh_type == SHT_RENESAS_INFO) | |
20821 | { | |
20822 | if (! process_v850_notes (filedata, | |
20823 | (bfd_vma) section->sh_offset, | |
20824 | (bfd_vma) section->sh_size)) | |
20825 | res = FALSE; | |
20826 | n++; | |
20827 | } | |
20828 | } | |
20829 | ||
20830 | if (n == 0) | |
20831 | /* Try processing NOTE segments instead. */ | |
20832 | return process_corefile_note_segments (filedata); | |
20833 | ||
20834 | return res; | |
20835 | } | |
20836 | ||
20837 | static bfd_boolean | |
20838 | process_notes (Filedata * filedata) | |
20839 | { | |
20840 | /* If we have not been asked to display the notes then do nothing. */ | |
20841 | if (! do_notes) | |
20842 | return TRUE; | |
20843 | ||
20844 | if (filedata->file_header.e_type != ET_CORE) | |
20845 | return process_note_sections (filedata); | |
20846 | ||
20847 | /* No program headers means no NOTE segment. */ | |
20848 | if (filedata->file_header.e_phnum > 0) | |
20849 | return process_corefile_note_segments (filedata); | |
20850 | ||
20851 | if (filedata->is_separate) | |
20852 | printf (_("No notes found in linked file '%s'.\n"), | |
20853 | filedata->file_name); | |
20854 | else | |
20855 | printf (_("No notes found file.\n")); | |
20856 | ||
20857 | return TRUE; | |
20858 | } | |
20859 | ||
20860 | static unsigned char * | |
20861 | display_public_gnu_attributes (unsigned char * start, | |
20862 | const unsigned char * const end) | |
20863 | { | |
20864 | printf (_(" Unknown GNU attribute: %s\n"), start); | |
20865 | ||
20866 | start += strnlen ((char *) start, end - start); | |
20867 | display_raw_attribute (start, end); | |
20868 | ||
20869 | return (unsigned char *) end; | |
20870 | } | |
20871 | ||
20872 | static unsigned char * | |
20873 | display_generic_attribute (unsigned char * start, | |
20874 | unsigned int tag, | |
20875 | const unsigned char * const end) | |
20876 | { | |
20877 | if (tag == 0) | |
20878 | return (unsigned char *) end; | |
20879 | ||
20880 | return display_tag_value (tag, start, end); | |
20881 | } | |
20882 | ||
20883 | static bfd_boolean | |
20884 | process_arch_specific (Filedata * filedata) | |
20885 | { | |
20886 | if (! do_arch) | |
20887 | return TRUE; | |
20888 | ||
20889 | switch (filedata->file_header.e_machine) | |
20890 | { | |
20891 | case EM_ARC: | |
20892 | case EM_ARC_COMPACT: | |
20893 | case EM_ARC_COMPACT2: | |
20894 | return process_attributes (filedata, "ARC", SHT_ARC_ATTRIBUTES, | |
20895 | display_arc_attribute, | |
20896 | display_generic_attribute); | |
20897 | case EM_ARM: | |
20898 | return process_attributes (filedata, "aeabi", SHT_ARM_ATTRIBUTES, | |
20899 | display_arm_attribute, | |
20900 | display_generic_attribute); | |
20901 | ||
20902 | case EM_MIPS: | |
20903 | case EM_MIPS_RS3_LE: | |
20904 | return process_mips_specific (filedata); | |
20905 | ||
20906 | case EM_MSP430: | |
20907 | return process_attributes (filedata, "mspabi", SHT_MSP430_ATTRIBUTES, | |
20908 | display_msp430_attribute, | |
20909 | display_msp430_gnu_attribute); | |
20910 | ||
20911 | case EM_RISCV: | |
20912 | return process_attributes (filedata, "riscv", SHT_RISCV_ATTRIBUTES, | |
20913 | display_riscv_attribute, | |
20914 | display_generic_attribute); | |
20915 | ||
20916 | case EM_NDS32: | |
20917 | return process_nds32_specific (filedata); | |
20918 | ||
20919 | case EM_68K: | |
20920 | return process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL, | |
20921 | display_m68k_gnu_attribute); | |
20922 | ||
20923 | case EM_PPC: | |
20924 | case EM_PPC64: | |
20925 | return process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL, | |
20926 | display_power_gnu_attribute); | |
20927 | ||
20928 | case EM_S390: | |
20929 | case EM_S390_OLD: | |
20930 | return process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL, | |
20931 | display_s390_gnu_attribute); | |
20932 | ||
20933 | case EM_SPARC: | |
20934 | case EM_SPARC32PLUS: | |
20935 | case EM_SPARCV9: | |
20936 | return process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL, | |
20937 | display_sparc_gnu_attribute); | |
20938 | ||
20939 | case EM_TI_C6000: | |
20940 | return process_attributes (filedata, "c6xabi", SHT_C6000_ATTRIBUTES, | |
20941 | display_tic6x_attribute, | |
20942 | display_generic_attribute); | |
20943 | ||
20944 | case EM_CSKY: | |
20945 | return process_attributes (filedata, "csky", SHT_CSKY_ATTRIBUTES, | |
20946 | display_csky_attribute, NULL); | |
20947 | ||
20948 | default: | |
20949 | return process_attributes (filedata, "gnu", SHT_GNU_ATTRIBUTES, | |
20950 | display_public_gnu_attributes, | |
20951 | display_generic_attribute); | |
20952 | } | |
20953 | } | |
20954 | ||
20955 | static bfd_boolean | |
20956 | get_file_header (Filedata * filedata) | |
20957 | { | |
20958 | /* Read in the identity array. */ | |
20959 | if (fread (filedata->file_header.e_ident, EI_NIDENT, 1, filedata->handle) != 1) | |
20960 | return FALSE; | |
20961 | ||
20962 | /* Determine how to read the rest of the header. */ | |
20963 | switch (filedata->file_header.e_ident[EI_DATA]) | |
20964 | { | |
20965 | default: | |
20966 | case ELFDATANONE: | |
20967 | case ELFDATA2LSB: | |
20968 | byte_get = byte_get_little_endian; | |
20969 | byte_put = byte_put_little_endian; | |
20970 | break; | |
20971 | case ELFDATA2MSB: | |
20972 | byte_get = byte_get_big_endian; | |
20973 | byte_put = byte_put_big_endian; | |
20974 | break; | |
20975 | } | |
20976 | ||
20977 | /* For now we only support 32 bit and 64 bit ELF files. */ | |
20978 | is_32bit_elf = (filedata->file_header.e_ident[EI_CLASS] != ELFCLASS64); | |
20979 | ||
20980 | /* Read in the rest of the header. */ | |
20981 | if (is_32bit_elf) | |
20982 | { | |
20983 | Elf32_External_Ehdr ehdr32; | |
20984 | ||
20985 | if (fread (ehdr32.e_type, sizeof (ehdr32) - EI_NIDENT, 1, filedata->handle) != 1) | |
20986 | return FALSE; | |
20987 | ||
20988 | filedata->file_header.e_type = BYTE_GET (ehdr32.e_type); | |
20989 | filedata->file_header.e_machine = BYTE_GET (ehdr32.e_machine); | |
20990 | filedata->file_header.e_version = BYTE_GET (ehdr32.e_version); | |
20991 | filedata->file_header.e_entry = BYTE_GET (ehdr32.e_entry); | |
20992 | filedata->file_header.e_phoff = BYTE_GET (ehdr32.e_phoff); | |
20993 | filedata->file_header.e_shoff = BYTE_GET (ehdr32.e_shoff); | |
20994 | filedata->file_header.e_flags = BYTE_GET (ehdr32.e_flags); | |
20995 | filedata->file_header.e_ehsize = BYTE_GET (ehdr32.e_ehsize); | |
20996 | filedata->file_header.e_phentsize = BYTE_GET (ehdr32.e_phentsize); | |
20997 | filedata->file_header.e_phnum = BYTE_GET (ehdr32.e_phnum); | |
20998 | filedata->file_header.e_shentsize = BYTE_GET (ehdr32.e_shentsize); | |
20999 | filedata->file_header.e_shnum = BYTE_GET (ehdr32.e_shnum); | |
21000 | filedata->file_header.e_shstrndx = BYTE_GET (ehdr32.e_shstrndx); | |
21001 | } | |
21002 | else | |
21003 | { | |
21004 | Elf64_External_Ehdr ehdr64; | |
21005 | ||
21006 | /* If we have been compiled with sizeof (bfd_vma) == 4, then | |
21007 | we will not be able to cope with the 64bit data found in | |
21008 | 64 ELF files. Detect this now and abort before we start | |
21009 | overwriting things. */ | |
21010 | if (sizeof (bfd_vma) < 8) | |
21011 | { | |
21012 | error (_("This instance of readelf has been built without support for a\n\ | |
21013 | 64 bit data type and so it cannot read 64 bit ELF files.\n")); | |
21014 | return FALSE; | |
21015 | } | |
21016 | ||
21017 | if (fread (ehdr64.e_type, sizeof (ehdr64) - EI_NIDENT, 1, filedata->handle) != 1) | |
21018 | return FALSE; | |
21019 | ||
21020 | filedata->file_header.e_type = BYTE_GET (ehdr64.e_type); | |
21021 | filedata->file_header.e_machine = BYTE_GET (ehdr64.e_machine); | |
21022 | filedata->file_header.e_version = BYTE_GET (ehdr64.e_version); | |
21023 | filedata->file_header.e_entry = BYTE_GET (ehdr64.e_entry); | |
21024 | filedata->file_header.e_phoff = BYTE_GET (ehdr64.e_phoff); | |
21025 | filedata->file_header.e_shoff = BYTE_GET (ehdr64.e_shoff); | |
21026 | filedata->file_header.e_flags = BYTE_GET (ehdr64.e_flags); | |
21027 | filedata->file_header.e_ehsize = BYTE_GET (ehdr64.e_ehsize); | |
21028 | filedata->file_header.e_phentsize = BYTE_GET (ehdr64.e_phentsize); | |
21029 | filedata->file_header.e_phnum = BYTE_GET (ehdr64.e_phnum); | |
21030 | filedata->file_header.e_shentsize = BYTE_GET (ehdr64.e_shentsize); | |
21031 | filedata->file_header.e_shnum = BYTE_GET (ehdr64.e_shnum); | |
21032 | filedata->file_header.e_shstrndx = BYTE_GET (ehdr64.e_shstrndx); | |
21033 | } | |
21034 | ||
21035 | if (filedata->file_header.e_shoff) | |
21036 | { | |
21037 | /* There may be some extensions in the first section header. Don't | |
21038 | bomb if we can't read it. */ | |
21039 | if (is_32bit_elf) | |
21040 | get_32bit_section_headers (filedata, TRUE); | |
21041 | else | |
21042 | get_64bit_section_headers (filedata, TRUE); | |
21043 | } | |
21044 | ||
21045 | return TRUE; | |
21046 | } | |
21047 | ||
21048 | static void | |
21049 | close_file (Filedata * filedata) | |
21050 | { | |
21051 | if (filedata) | |
21052 | { | |
21053 | if (filedata->handle) | |
21054 | fclose (filedata->handle); | |
21055 | free (filedata); | |
21056 | } | |
21057 | } | |
21058 | ||
21059 | void | |
21060 | close_debug_file (void * data) | |
21061 | { | |
21062 | close_file ((Filedata *) data); | |
21063 | } | |
21064 | ||
21065 | static Filedata * | |
21066 | open_file (const char * pathname, bfd_boolean is_separate) | |
21067 | { | |
21068 | struct stat statbuf; | |
21069 | Filedata * filedata = NULL; | |
21070 | ||
21071 | if (stat (pathname, & statbuf) < 0 | |
21072 | || ! S_ISREG (statbuf.st_mode)) | |
21073 | goto fail; | |
21074 | ||
21075 | filedata = calloc (1, sizeof * filedata); | |
21076 | if (filedata == NULL) | |
21077 | goto fail; | |
21078 | ||
21079 | filedata->handle = fopen (pathname, "rb"); | |
21080 | if (filedata->handle == NULL) | |
21081 | goto fail; | |
21082 | ||
21083 | filedata->file_size = (bfd_size_type) statbuf.st_size; | |
21084 | filedata->file_name = pathname; | |
21085 | filedata->is_separate = is_separate; | |
21086 | ||
21087 | if (! get_file_header (filedata)) | |
21088 | goto fail; | |
21089 | ||
21090 | if (filedata->file_header.e_shoff) | |
21091 | { | |
21092 | bfd_boolean res; | |
21093 | ||
21094 | /* Read the section headers again, this time for real. */ | |
21095 | if (is_32bit_elf) | |
21096 | res = get_32bit_section_headers (filedata, FALSE); | |
21097 | else | |
21098 | res = get_64bit_section_headers (filedata, FALSE); | |
21099 | ||
21100 | if (!res) | |
21101 | goto fail; | |
21102 | } | |
21103 | ||
21104 | return filedata; | |
21105 | ||
21106 | fail: | |
21107 | if (filedata) | |
21108 | { | |
21109 | if (filedata->handle) | |
21110 | fclose (filedata->handle); | |
21111 | free (filedata); | |
21112 | } | |
21113 | return NULL; | |
21114 | } | |
21115 | ||
21116 | void * | |
21117 | open_debug_file (const char * pathname) | |
21118 | { | |
21119 | return open_file (pathname, TRUE); | |
21120 | } | |
21121 | ||
21122 | /* Process one ELF object file according to the command line options. | |
21123 | This file may actually be stored in an archive. The file is | |
21124 | positioned at the start of the ELF object. Returns TRUE if no | |
21125 | problems were encountered, FALSE otherwise. */ | |
21126 | ||
21127 | static bfd_boolean | |
21128 | process_object (Filedata * filedata) | |
21129 | { | |
21130 | bfd_boolean have_separate_files; | |
21131 | unsigned int i; | |
21132 | bfd_boolean res; | |
21133 | ||
21134 | if (! get_file_header (filedata)) | |
21135 | { | |
21136 | error (_("%s: Failed to read file header\n"), filedata->file_name); | |
21137 | return FALSE; | |
21138 | } | |
21139 | ||
21140 | /* Initialise per file variables. */ | |
21141 | for (i = ARRAY_SIZE (filedata->version_info); i--;) | |
21142 | filedata->version_info[i] = 0; | |
21143 | ||
21144 | for (i = ARRAY_SIZE (filedata->dynamic_info); i--;) | |
21145 | filedata->dynamic_info[i] = 0; | |
21146 | filedata->dynamic_info_DT_GNU_HASH = 0; | |
21147 | filedata->dynamic_info_DT_MIPS_XHASH = 0; | |
21148 | ||
21149 | /* Process the file. */ | |
21150 | if (show_name) | |
21151 | printf (_("\nFile: %s\n"), filedata->file_name); | |
21152 | ||
21153 | /* Initialise the dump_sects array from the cmdline_dump_sects array. | |
21154 | Note we do this even if cmdline_dump_sects is empty because we | |
21155 | must make sure that the dump_sets array is zeroed out before each | |
21156 | object file is processed. */ | |
21157 | if (filedata->dump.num_dump_sects > cmdline.num_dump_sects) | |
21158 | memset (filedata->dump.dump_sects, 0, | |
21159 | filedata->dump.num_dump_sects * sizeof (*filedata->dump.dump_sects)); | |
21160 | ||
21161 | if (cmdline.num_dump_sects > 0) | |
21162 | { | |
21163 | if (filedata->dump.num_dump_sects == 0) | |
21164 | /* A sneaky way of allocating the dump_sects array. */ | |
21165 | request_dump_bynumber (&filedata->dump, cmdline.num_dump_sects, 0); | |
21166 | ||
21167 | assert (filedata->dump.num_dump_sects >= cmdline.num_dump_sects); | |
21168 | memcpy (filedata->dump.dump_sects, cmdline.dump_sects, | |
21169 | cmdline.num_dump_sects * sizeof (*filedata->dump.dump_sects)); | |
21170 | } | |
21171 | ||
21172 | if (! process_file_header (filedata)) | |
21173 | return FALSE; | |
21174 | ||
21175 | if (! process_section_headers (filedata)) | |
21176 | { | |
21177 | /* Without loaded section headers we cannot process lots of things. */ | |
21178 | do_unwind = do_version = do_dump = do_arch = FALSE; | |
21179 | ||
21180 | if (! do_using_dynamic) | |
21181 | do_syms = do_dyn_syms = do_reloc = FALSE; | |
21182 | } | |
21183 | ||
21184 | if (! process_section_groups (filedata)) | |
21185 | /* Without loaded section groups we cannot process unwind. */ | |
21186 | do_unwind = FALSE; | |
21187 | ||
21188 | res = process_program_headers (filedata); | |
21189 | if (res) | |
21190 | res = process_dynamic_section (filedata); | |
21191 | ||
21192 | if (! process_relocs (filedata)) | |
21193 | res = FALSE; | |
21194 | ||
21195 | if (! process_unwind (filedata)) | |
21196 | res = FALSE; | |
21197 | ||
21198 | if (! process_symbol_table (filedata)) | |
21199 | res = FALSE; | |
21200 | ||
21201 | if (! process_lto_symbol_tables (filedata)) | |
21202 | res = FALSE; | |
21203 | ||
21204 | if (! process_syminfo (filedata)) | |
21205 | res = FALSE; | |
21206 | ||
21207 | if (! process_version_sections (filedata)) | |
21208 | res = FALSE; | |
21209 | ||
21210 | if (filedata->file_header.e_shstrndx != SHN_UNDEF) | |
21211 | have_separate_files = load_separate_debug_files (filedata, filedata->file_name); | |
21212 | else | |
21213 | have_separate_files = FALSE; | |
21214 | ||
21215 | if (! process_section_contents (filedata)) | |
21216 | res = FALSE; | |
21217 | ||
21218 | if (have_separate_files) | |
21219 | { | |
21220 | separate_info * d; | |
21221 | ||
21222 | for (d = first_separate_info; d != NULL; d = d->next) | |
21223 | { | |
21224 | if (process_links && ! process_file_header (d->handle)) | |
21225 | res = FALSE; | |
21226 | else if (! process_section_headers (d->handle)) | |
21227 | res = FALSE; | |
21228 | else if (! process_section_contents (d->handle)) | |
21229 | res = FALSE; | |
21230 | else if (process_links) | |
21231 | { | |
21232 | if (! process_section_groups (d->handle)) | |
21233 | res = FALSE; | |
21234 | if (! process_program_headers (d->handle)) | |
21235 | res = FALSE; | |
21236 | if (! process_dynamic_section (d->handle)) | |
21237 | res = FALSE; | |
21238 | if (! process_relocs (d->handle)) | |
21239 | res = FALSE; | |
21240 | if (! process_unwind (d->handle)) | |
21241 | res = FALSE; | |
21242 | if (! process_symbol_table (d->handle)) | |
21243 | res = FALSE; | |
21244 | if (! process_lto_symbol_tables (d->handle)) | |
21245 | res = FALSE; | |
21246 | if (! process_syminfo (d->handle)) | |
21247 | res = FALSE; | |
21248 | if (! process_version_sections (d->handle)) | |
21249 | res = FALSE; | |
21250 | if (! process_notes (d->handle)) | |
21251 | res = FALSE; | |
21252 | } | |
21253 | } | |
21254 | ||
21255 | /* The file handles are closed by the call to free_debug_memory() below. */ | |
21256 | } | |
21257 | ||
21258 | if (! process_notes (filedata)) | |
21259 | res = FALSE; | |
21260 | ||
21261 | if (! process_gnu_liblist (filedata)) | |
21262 | res = FALSE; | |
21263 | ||
21264 | if (! process_arch_specific (filedata)) | |
21265 | res = FALSE; | |
21266 | ||
21267 | free (filedata->program_headers); | |
21268 | filedata->program_headers = NULL; | |
21269 | ||
21270 | free (filedata->section_headers); | |
21271 | filedata->section_headers = NULL; | |
21272 | ||
21273 | free (filedata->string_table); | |
21274 | filedata->string_table = NULL; | |
21275 | filedata->string_table_length = 0; | |
21276 | ||
21277 | free (filedata->dump.dump_sects); | |
21278 | filedata->dump.dump_sects = NULL; | |
21279 | filedata->dump.num_dump_sects = 0; | |
21280 | ||
21281 | free (filedata->dynamic_strings); | |
21282 | filedata->dynamic_strings = NULL; | |
21283 | filedata->dynamic_strings_length = 0; | |
21284 | ||
21285 | free (filedata->dynamic_symbols); | |
21286 | filedata->dynamic_symbols = NULL; | |
21287 | filedata->num_dynamic_syms = 0; | |
21288 | ||
21289 | free (filedata->dynamic_syminfo); | |
21290 | filedata->dynamic_syminfo = NULL; | |
21291 | ||
21292 | free (filedata->dynamic_section); | |
21293 | filedata->dynamic_section = NULL; | |
21294 | ||
21295 | while (filedata->symtab_shndx_list != NULL) | |
21296 | { | |
21297 | elf_section_list *next = filedata->symtab_shndx_list->next; | |
21298 | free (filedata->symtab_shndx_list); | |
21299 | filedata->symtab_shndx_list = next; | |
21300 | } | |
21301 | ||
21302 | free (filedata->section_headers_groups); | |
21303 | filedata->section_headers_groups = NULL; | |
21304 | ||
21305 | if (filedata->section_groups) | |
21306 | { | |
21307 | struct group_list * g; | |
21308 | struct group_list * next; | |
21309 | ||
21310 | for (i = 0; i < filedata->group_count; i++) | |
21311 | { | |
21312 | for (g = filedata->section_groups [i].root; g != NULL; g = next) | |
21313 | { | |
21314 | next = g->next; | |
21315 | free (g); | |
21316 | } | |
21317 | } | |
21318 | ||
21319 | free (filedata->section_groups); | |
21320 | filedata->section_groups = NULL; | |
21321 | } | |
21322 | ||
21323 | free_debug_memory (); | |
21324 | ||
21325 | return res; | |
21326 | } | |
21327 | ||
21328 | /* Process an ELF archive. | |
21329 | On entry the file is positioned just after the ARMAG string. | |
21330 | Returns TRUE upon success, FALSE otherwise. */ | |
21331 | ||
21332 | static bfd_boolean | |
21333 | process_archive (Filedata * filedata, bfd_boolean is_thin_archive) | |
21334 | { | |
21335 | struct archive_info arch; | |
21336 | struct archive_info nested_arch; | |
21337 | size_t got; | |
21338 | bfd_boolean ret = TRUE; | |
21339 | ||
21340 | show_name = TRUE; | |
21341 | ||
21342 | /* The ARCH structure is used to hold information about this archive. */ | |
21343 | arch.file_name = NULL; | |
21344 | arch.file = NULL; | |
21345 | arch.index_array = NULL; | |
21346 | arch.sym_table = NULL; | |
21347 | arch.longnames = NULL; | |
21348 | ||
21349 | /* The NESTED_ARCH structure is used as a single-item cache of information | |
21350 | about a nested archive (when members of a thin archive reside within | |
21351 | another regular archive file). */ | |
21352 | nested_arch.file_name = NULL; | |
21353 | nested_arch.file = NULL; | |
21354 | nested_arch.index_array = NULL; | |
21355 | nested_arch.sym_table = NULL; | |
21356 | nested_arch.longnames = NULL; | |
21357 | ||
21358 | if (setup_archive (&arch, filedata->file_name, filedata->handle, | |
21359 | filedata->file_size, is_thin_archive, | |
21360 | do_archive_index) != 0) | |
21361 | { | |
21362 | ret = FALSE; | |
21363 | goto out; | |
21364 | } | |
21365 | ||
21366 | if (do_archive_index) | |
21367 | { | |
21368 | if (arch.sym_table == NULL) | |
21369 | error (_("%s: unable to dump the index as none was found\n"), | |
21370 | filedata->file_name); | |
21371 | else | |
21372 | { | |
21373 | unsigned long i, l; | |
21374 | unsigned long current_pos; | |
21375 | ||
21376 | printf (_("Index of archive %s: (%lu entries, 0x%lx bytes " | |
21377 | "in the symbol table)\n"), | |
21378 | filedata->file_name, (unsigned long) arch.index_num, | |
21379 | arch.sym_size); | |
21380 | ||
21381 | current_pos = ftell (filedata->handle); | |
21382 | ||
21383 | for (i = l = 0; i < arch.index_num; i++) | |
21384 | { | |
21385 | if (i == 0 | |
21386 | || (i > 0 && arch.index_array[i] != arch.index_array[i - 1])) | |
21387 | { | |
21388 | char * member_name | |
21389 | = get_archive_member_name_at (&arch, arch.index_array[i], | |
21390 | &nested_arch); | |
21391 | ||
21392 | if (member_name != NULL) | |
21393 | { | |
21394 | char * qualified_name | |
21395 | = make_qualified_name (&arch, &nested_arch, | |
21396 | member_name); | |
21397 | ||
21398 | if (qualified_name != NULL) | |
21399 | { | |
21400 | printf (_("Contents of binary %s at offset "), | |
21401 | qualified_name); | |
21402 | (void) print_vma (arch.index_array[i], PREFIX_HEX); | |
21403 | putchar ('\n'); | |
21404 | free (qualified_name); | |
21405 | } | |
21406 | free (member_name); | |
21407 | } | |
21408 | } | |
21409 | ||
21410 | if (l >= arch.sym_size) | |
21411 | { | |
21412 | error (_("%s: end of the symbol table reached " | |
21413 | "before the end of the index\n"), | |
21414 | filedata->file_name); | |
21415 | ret = FALSE; | |
21416 | break; | |
21417 | } | |
21418 | /* PR 17531: file: 0b6630b2. */ | |
21419 | printf ("\t%.*s\n", | |
21420 | (int) (arch.sym_size - l), arch.sym_table + l); | |
21421 | l += strnlen (arch.sym_table + l, arch.sym_size - l) + 1; | |
21422 | } | |
21423 | ||
21424 | if (arch.uses_64bit_indices) | |
21425 | l = (l + 7) & ~ 7; | |
21426 | else | |
21427 | l += l & 1; | |
21428 | ||
21429 | if (l < arch.sym_size) | |
21430 | { | |
21431 | error (ngettext ("%s: %ld byte remains in the symbol table, " | |
21432 | "but without corresponding entries in " | |
21433 | "the index table\n", | |
21434 | "%s: %ld bytes remain in the symbol table, " | |
21435 | "but without corresponding entries in " | |
21436 | "the index table\n", | |
21437 | arch.sym_size - l), | |
21438 | filedata->file_name, arch.sym_size - l); | |
21439 | ret = FALSE; | |
21440 | } | |
21441 | ||
21442 | if (fseek (filedata->handle, current_pos, SEEK_SET) != 0) | |
21443 | { | |
21444 | error (_("%s: failed to seek back to start of object files " | |
21445 | "in the archive\n"), | |
21446 | filedata->file_name); | |
21447 | ret = FALSE; | |
21448 | goto out; | |
21449 | } | |
21450 | } | |
21451 | ||
21452 | if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections | |
21453 | && !do_segments && !do_header && !do_dump && !do_version | |
21454 | && !do_histogram && !do_debugging && !do_arch && !do_notes | |
21455 | && !do_section_groups && !do_dyn_syms) | |
21456 | { | |
21457 | ret = TRUE; /* Archive index only. */ | |
21458 | goto out; | |
21459 | } | |
21460 | } | |
21461 | ||
21462 | while (1) | |
21463 | { | |
21464 | char * name; | |
21465 | size_t namelen; | |
21466 | char * qualified_name; | |
21467 | ||
21468 | /* Read the next archive header. */ | |
21469 | if (fseek (filedata->handle, arch.next_arhdr_offset, SEEK_SET) != 0) | |
21470 | { | |
21471 | error (_("%s: failed to seek to next archive header\n"), | |
21472 | arch.file_name); | |
21473 | ret = FALSE; | |
21474 | break; | |
21475 | } | |
21476 | got = fread (&arch.arhdr, 1, sizeof arch.arhdr, filedata->handle); | |
21477 | if (got != sizeof arch.arhdr) | |
21478 | { | |
21479 | if (got == 0) | |
21480 | break; | |
21481 | /* PR 24049 - we cannot use filedata->file_name as this will | |
21482 | have already been freed. */ | |
21483 | error (_("%s: failed to read archive header\n"), arch.file_name); | |
21484 | ||
21485 | ret = FALSE; | |
21486 | break; | |
21487 | } | |
21488 | if (memcmp (arch.arhdr.ar_fmag, ARFMAG, 2) != 0) | |
21489 | { | |
21490 | error (_("%s: did not find a valid archive header\n"), | |
21491 | arch.file_name); | |
21492 | ret = FALSE; | |
21493 | break; | |
21494 | } | |
21495 | ||
21496 | arch.next_arhdr_offset += sizeof arch.arhdr; | |
21497 | ||
21498 | filedata->archive_file_size = strtoul (arch.arhdr.ar_size, NULL, 10); | |
21499 | if (filedata->archive_file_size & 01) | |
21500 | ++filedata->archive_file_size; | |
21501 | ||
21502 | name = get_archive_member_name (&arch, &nested_arch); | |
21503 | if (name == NULL) | |
21504 | { | |
21505 | error (_("%s: bad archive file name\n"), arch.file_name); | |
21506 | ret = FALSE; | |
21507 | break; | |
21508 | } | |
21509 | namelen = strlen (name); | |
21510 | ||
21511 | qualified_name = make_qualified_name (&arch, &nested_arch, name); | |
21512 | if (qualified_name == NULL) | |
21513 | { | |
21514 | error (_("%s: bad archive file name\n"), arch.file_name); | |
21515 | free (name); | |
21516 | ret = FALSE; | |
21517 | break; | |
21518 | } | |
21519 | ||
21520 | if (is_thin_archive && arch.nested_member_origin == 0) | |
21521 | { | |
21522 | /* This is a proxy for an external member of a thin archive. */ | |
21523 | Filedata * member_filedata; | |
21524 | char * member_file_name = adjust_relative_path | |
21525 | (filedata->file_name, name, namelen); | |
21526 | ||
21527 | free (name); | |
21528 | if (member_file_name == NULL) | |
21529 | { | |
21530 | free (qualified_name); | |
21531 | ret = FALSE; | |
21532 | break; | |
21533 | } | |
21534 | ||
21535 | member_filedata = open_file (member_file_name, FALSE); | |
21536 | if (member_filedata == NULL) | |
21537 | { | |
21538 | error (_("Input file '%s' is not readable.\n"), member_file_name); | |
21539 | free (member_file_name); | |
21540 | free (qualified_name); | |
21541 | ret = FALSE; | |
21542 | break; | |
21543 | } | |
21544 | ||
21545 | filedata->archive_file_offset = arch.nested_member_origin; | |
21546 | member_filedata->file_name = qualified_name; | |
21547 | ||
21548 | if (! process_object (member_filedata)) | |
21549 | ret = FALSE; | |
21550 | ||
21551 | close_file (member_filedata); | |
21552 | free (member_file_name); | |
21553 | } | |
21554 | else if (is_thin_archive) | |
21555 | { | |
21556 | Filedata thin_filedata; | |
21557 | ||
21558 | memset (&thin_filedata, 0, sizeof (thin_filedata)); | |
21559 | ||
21560 | /* PR 15140: Allow for corrupt thin archives. */ | |
21561 | if (nested_arch.file == NULL) | |
21562 | { | |
21563 | error (_("%s: contains corrupt thin archive: %s\n"), | |
21564 | qualified_name, name); | |
21565 | free (qualified_name); | |
21566 | free (name); | |
21567 | ret = FALSE; | |
21568 | break; | |
21569 | } | |
21570 | free (name); | |
21571 | ||
21572 | /* This is a proxy for a member of a nested archive. */ | |
21573 | filedata->archive_file_offset | |
21574 | = arch.nested_member_origin + sizeof arch.arhdr; | |
21575 | ||
21576 | /* The nested archive file will have been opened and setup by | |
21577 | get_archive_member_name. */ | |
21578 | if (fseek (nested_arch.file, filedata->archive_file_offset, | |
21579 | SEEK_SET) != 0) | |
21580 | { | |
21581 | error (_("%s: failed to seek to archive member.\n"), | |
21582 | nested_arch.file_name); | |
21583 | free (qualified_name); | |
21584 | ret = FALSE; | |
21585 | break; | |
21586 | } | |
21587 | ||
21588 | thin_filedata.handle = nested_arch.file; | |
21589 | thin_filedata.file_name = qualified_name; | |
21590 | ||
21591 | if (! process_object (& thin_filedata)) | |
21592 | ret = FALSE; | |
21593 | } | |
21594 | else | |
21595 | { | |
21596 | free (name); | |
21597 | filedata->archive_file_offset = arch.next_arhdr_offset; | |
21598 | filedata->file_name = qualified_name; | |
21599 | if (! process_object (filedata)) | |
21600 | ret = FALSE; | |
21601 | arch.next_arhdr_offset += filedata->archive_file_size; | |
21602 | /* Stop looping with "negative" archive_file_size. */ | |
21603 | if (arch.next_arhdr_offset < filedata->archive_file_size) | |
21604 | arch.next_arhdr_offset = -1ul; | |
21605 | } | |
21606 | ||
21607 | free (qualified_name); | |
21608 | } | |
21609 | ||
21610 | out: | |
21611 | if (nested_arch.file != NULL) | |
21612 | fclose (nested_arch.file); | |
21613 | release_archive (&nested_arch); | |
21614 | release_archive (&arch); | |
21615 | ||
21616 | return ret; | |
21617 | } | |
21618 | ||
21619 | static bfd_boolean | |
21620 | process_file (char * file_name) | |
21621 | { | |
21622 | Filedata * filedata = NULL; | |
21623 | struct stat statbuf; | |
21624 | char armag[SARMAG]; | |
21625 | bfd_boolean ret = TRUE; | |
21626 | ||
21627 | if (stat (file_name, &statbuf) < 0) | |
21628 | { | |
21629 | if (errno == ENOENT) | |
21630 | error (_("'%s': No such file\n"), file_name); | |
21631 | else | |
21632 | error (_("Could not locate '%s'. System error message: %s\n"), | |
21633 | file_name, strerror (errno)); | |
21634 | return FALSE; | |
21635 | } | |
21636 | ||
21637 | if (! S_ISREG (statbuf.st_mode)) | |
21638 | { | |
21639 | error (_("'%s' is not an ordinary file\n"), file_name); | |
21640 | return FALSE; | |
21641 | } | |
21642 | ||
21643 | filedata = calloc (1, sizeof * filedata); | |
21644 | if (filedata == NULL) | |
21645 | { | |
21646 | error (_("Out of memory allocating file data structure\n")); | |
21647 | return FALSE; | |
21648 | } | |
21649 | ||
21650 | filedata->file_name = file_name; | |
21651 | filedata->handle = fopen (file_name, "rb"); | |
21652 | if (filedata->handle == NULL) | |
21653 | { | |
21654 | error (_("Input file '%s' is not readable.\n"), file_name); | |
21655 | free (filedata); | |
21656 | return FALSE; | |
21657 | } | |
21658 | ||
21659 | if (fread (armag, SARMAG, 1, filedata->handle) != 1) | |
21660 | { | |
21661 | error (_("%s: Failed to read file's magic number\n"), file_name); | |
21662 | fclose (filedata->handle); | |
21663 | free (filedata); | |
21664 | return FALSE; | |
21665 | } | |
21666 | ||
21667 | filedata->file_size = (bfd_size_type) statbuf.st_size; | |
21668 | filedata->is_separate = FALSE; | |
21669 | ||
21670 | if (memcmp (armag, ARMAG, SARMAG) == 0) | |
21671 | { | |
21672 | if (! process_archive (filedata, FALSE)) | |
21673 | ret = FALSE; | |
21674 | } | |
21675 | else if (memcmp (armag, ARMAGT, SARMAG) == 0) | |
21676 | { | |
21677 | if ( ! process_archive (filedata, TRUE)) | |
21678 | ret = FALSE; | |
21679 | } | |
21680 | else | |
21681 | { | |
21682 | if (do_archive_index && !check_all) | |
21683 | error (_("File %s is not an archive so its index cannot be displayed.\n"), | |
21684 | file_name); | |
21685 | ||
21686 | rewind (filedata->handle); | |
21687 | filedata->archive_file_size = filedata->archive_file_offset = 0; | |
21688 | ||
21689 | if (! process_object (filedata)) | |
21690 | ret = FALSE; | |
21691 | } | |
21692 | ||
21693 | fclose (filedata->handle); | |
21694 | free (filedata->section_headers); | |
21695 | free (filedata->program_headers); | |
21696 | free (filedata->string_table); | |
21697 | free (filedata->dump.dump_sects); | |
21698 | free (filedata); | |
21699 | ||
21700 | free (ba_cache.strtab); | |
21701 | ba_cache.strtab = NULL; | |
21702 | free (ba_cache.symtab); | |
21703 | ba_cache.symtab = NULL; | |
21704 | ba_cache.filedata = NULL; | |
21705 | ||
21706 | return ret; | |
21707 | } | |
21708 | ||
21709 | #ifdef SUPPORT_DISASSEMBLY | |
21710 | /* Needed by the i386 disassembler. For extra credit, someone could | |
21711 | fix this so that we insert symbolic addresses here, esp for GOT/PLT | |
21712 | symbols. */ | |
21713 | ||
21714 | void | |
21715 | print_address (unsigned int addr, FILE * outfile) | |
21716 | { | |
21717 | fprintf (outfile,"0x%8.8x", addr); | |
21718 | } | |
21719 | ||
21720 | /* Needed by the i386 disassembler. */ | |
21721 | ||
21722 | void | |
21723 | db_task_printsym (unsigned int addr) | |
21724 | { | |
21725 | print_address (addr, stderr); | |
21726 | } | |
21727 | #endif | |
21728 | ||
21729 | int | |
21730 | main (int argc, char ** argv) | |
21731 | { | |
21732 | int err; | |
21733 | ||
21734 | #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES) | |
21735 | setlocale (LC_MESSAGES, ""); | |
21736 | #endif | |
21737 | #if defined (HAVE_SETLOCALE) | |
21738 | setlocale (LC_CTYPE, ""); | |
21739 | #endif | |
21740 | bindtextdomain (PACKAGE, LOCALEDIR); | |
21741 | textdomain (PACKAGE); | |
21742 | ||
21743 | expandargv (&argc, &argv); | |
21744 | ||
21745 | parse_args (& cmdline, argc, argv); | |
21746 | ||
21747 | if (optind < (argc - 1)) | |
21748 | /* When displaying information for more than one file, | |
21749 | prefix the information with the file name. */ | |
21750 | show_name = TRUE; | |
21751 | else if (optind >= argc) | |
21752 | { | |
21753 | /* Ensure that the warning is always displayed. */ | |
21754 | do_checks = TRUE; | |
21755 | ||
21756 | warn (_("Nothing to do.\n")); | |
21757 | usage (stderr); | |
21758 | } | |
21759 | ||
21760 | err = FALSE; | |
21761 | while (optind < argc) | |
21762 | if (! process_file (argv[optind++])) | |
21763 | err = TRUE; | |
21764 | ||
21765 | free (cmdline.dump_sects); | |
21766 | ||
21767 | free (dump_ctf_symtab_name); | |
21768 | free (dump_ctf_strtab_name); | |
21769 | free (dump_ctf_parent_name); | |
21770 | ||
21771 | return err ? EXIT_FAILURE : EXIT_SUCCESS; | |
21772 | } |