]>
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 | case EM_INTELGT: return "Intel Graphics Technology"; | |
2553 | /* 210 */ | |
2554 | case EM_KM32: return "KM211 KM32 32-bit processor"; | |
2555 | case EM_KMX32: return "KM211 KMX32 32-bit processor"; | |
2556 | case EM_KMX16: return "KM211 KMX16 16-bit processor"; | |
2557 | case EM_KMX8: return "KM211 KMX8 8-bit processor"; | |
2558 | case EM_KVARC: return "KM211 KVARC processor"; | |
2559 | case EM_CDP: return "Paneve CDP architecture family"; | |
2560 | case EM_COGE: return "Cognitive Smart Memory Processor"; | |
2561 | case EM_COOL: return "Bluechip Systems CoolEngine"; | |
2562 | case EM_NORC: return "Nanoradio Optimized RISC"; | |
2563 | case EM_CSR_KALIMBA: return "CSR Kalimba architecture family"; | |
2564 | /* 220 */ | |
2565 | case EM_Z80: return "Zilog Z80"; | |
2566 | case EM_VISIUM: return "CDS VISIUMcore processor"; | |
2567 | case EM_FT32: return "FTDI Chip FT32"; | |
2568 | case EM_MOXIE: return "Moxie"; | |
2569 | case EM_AMDGPU: return "AMD GPU"; | |
2570 | /* 230 (all reserved) */ | |
2571 | /* 240 */ | |
2572 | case EM_RISCV: return "RISC-V"; | |
2573 | case EM_LANAI: return "Lanai 32-bit processor"; | |
2574 | case EM_CEVA: return "CEVA Processor Architecture Family"; | |
2575 | case EM_CEVA_X2: return "CEVA X2 Processor Family"; | |
2576 | case EM_BPF: return "Linux BPF"; | |
2577 | case EM_GRAPHCORE_IPU: return "Graphcore Intelligent Processing Unit"; | |
2578 | case EM_IMG1: return "Imagination Technologies"; | |
2579 | /* 250 */ | |
2580 | case EM_NFP: return "Netronome Flow Processor"; | |
2581 | case EM_VE: return "NEC Vector Engine"; | |
2582 | case EM_CSKY: return "C-SKY"; | |
2583 | case EM_ARC_COMPACT3_64: return "Synopsys ARCv2.3 64-bit"; | |
2584 | case EM_MCS6502: return "MOS Technology MCS 6502 processor"; | |
2585 | case EM_ARC_COMPACT3: return "Synopsys ARCv2.3 32-bit"; | |
2586 | case EM_KVX: return "Kalray VLIW core of the MPPA processor family"; | |
2587 | case EM_65816: return "WDC 65816/65C816"; | |
2588 | case EM_LOONGARCH: return "Loongson Loongarch"; | |
2589 | case EM_KF32: return "ChipON KungFu32"; | |
2590 | ||
2591 | /* Large numbers... */ | |
2592 | case EM_MT: return "Morpho Techologies MT processor"; | |
2593 | case EM_ALPHA: return "Alpha"; | |
2594 | case EM_WEBASSEMBLY: return "Web Assembly"; | |
2595 | case EM_DLX: return "OpenDLX"; | |
2596 | case EM_XSTORMY16: return "Sanyo XStormy16 CPU core"; | |
2597 | case EM_IQ2000: return "Vitesse IQ2000"; | |
2598 | case EM_M32C_OLD: | |
2599 | case EM_NIOS32: return "Altera Nios"; | |
2600 | case EM_CYGNUS_MEP: return "Toshiba MeP Media Engine"; | |
2601 | case EM_ADAPTEVA_EPIPHANY: return "Adapteva EPIPHANY"; | |
2602 | case EM_CYGNUS_FRV: return "Fujitsu FR-V"; | |
2603 | case EM_S12Z: return "Freescale S12Z"; | |
2604 | ||
2605 | default: | |
2606 | snprintf (buff, sizeof (buff), _("<unknown>: 0x%x"), e_machine); | |
2607 | return buff; | |
2608 | } | |
2609 | } | |
2610 | ||
2611 | static void | |
2612 | decode_ARC_machine_flags (unsigned e_flags, unsigned e_machine, char buf[]) | |
2613 | { | |
2614 | /* ARC has two machine types EM_ARC_COMPACT and EM_ARC_COMPACT2. Some | |
2615 | other compilers don't specify an architecture type in the e_flags, and | |
2616 | instead use EM_ARC_COMPACT for old ARC600, ARC601, and ARC700 | |
2617 | architectures, and switch to EM_ARC_COMPACT2 for newer ARCEM and ARCHS | |
2618 | architectures. | |
2619 | ||
2620 | Th GNU tools follows this use of EM_ARC_COMPACT and EM_ARC_COMPACT2, | |
2621 | but also sets a specific architecture type in the e_flags field. | |
2622 | ||
2623 | However, when decoding the flags we don't worry if we see an | |
2624 | unexpected pairing, for example EM_ARC_COMPACT machine type, with | |
2625 | ARCEM architecture type. */ | |
2626 | ||
2627 | switch (e_flags & EF_ARC_MACH_MSK) | |
2628 | { | |
2629 | /* We only expect these to occur for EM_ARC_COMPACT2. */ | |
2630 | case EF_ARC_CPU_ARCV2EM: | |
2631 | strcat (buf, ", ARC EM"); | |
2632 | break; | |
2633 | case EF_ARC_CPU_ARCV2HS: | |
2634 | strcat (buf, ", ARC HS"); | |
2635 | break; | |
2636 | ||
2637 | /* We only expect these to occur for EM_ARC_COMPACT. */ | |
2638 | case E_ARC_MACH_ARC600: | |
2639 | strcat (buf, ", ARC600"); | |
2640 | break; | |
2641 | case E_ARC_MACH_ARC601: | |
2642 | strcat (buf, ", ARC601"); | |
2643 | break; | |
2644 | case E_ARC_MACH_ARC700: | |
2645 | strcat (buf, ", ARC700"); | |
2646 | break; | |
2647 | ||
2648 | /* The only times we should end up here are (a) A corrupt ELF, (b) A | |
2649 | new ELF with new architecture being read by an old version of | |
2650 | readelf, or (c) An ELF built with non-GNU compiler that does not | |
2651 | set the architecture in the e_flags. */ | |
2652 | default: | |
2653 | if (e_machine == EM_ARC_COMPACT) | |
2654 | strcat (buf, ", Unknown ARCompact"); | |
2655 | else | |
2656 | strcat (buf, ", Unknown ARC"); | |
2657 | break; | |
2658 | } | |
2659 | ||
2660 | switch (e_flags & EF_ARC_OSABI_MSK) | |
2661 | { | |
2662 | case E_ARC_OSABI_ORIG: | |
2663 | strcat (buf, ", (ABI:legacy)"); | |
2664 | break; | |
2665 | case E_ARC_OSABI_V2: | |
2666 | strcat (buf, ", (ABI:v2)"); | |
2667 | break; | |
2668 | /* Only upstream 3.9+ kernels will support ARCv2 ISA. */ | |
2669 | case E_ARC_OSABI_V3: | |
2670 | strcat (buf, ", v3 no-legacy-syscalls ABI"); | |
2671 | break; | |
2672 | case E_ARC_OSABI_V4: | |
2673 | strcat (buf, ", v4 ABI"); | |
2674 | break; | |
2675 | default: | |
2676 | strcat (buf, ", unrecognised ARC OSABI flag"); | |
2677 | break; | |
2678 | } | |
2679 | } | |
2680 | ||
2681 | static void | |
2682 | decode_ARM_machine_flags (unsigned e_flags, char buf[]) | |
2683 | { | |
2684 | unsigned eabi; | |
2685 | bfd_boolean unknown = FALSE; | |
2686 | ||
2687 | eabi = EF_ARM_EABI_VERSION (e_flags); | |
2688 | e_flags &= ~ EF_ARM_EABIMASK; | |
2689 | ||
2690 | /* Handle "generic" ARM flags. */ | |
2691 | if (e_flags & EF_ARM_RELEXEC) | |
2692 | { | |
2693 | strcat (buf, ", relocatable executable"); | |
2694 | e_flags &= ~ EF_ARM_RELEXEC; | |
2695 | } | |
2696 | ||
2697 | if (e_flags & EF_ARM_PIC) | |
2698 | { | |
2699 | strcat (buf, ", position independent"); | |
2700 | e_flags &= ~ EF_ARM_PIC; | |
2701 | } | |
2702 | ||
2703 | /* Now handle EABI specific flags. */ | |
2704 | switch (eabi) | |
2705 | { | |
2706 | default: | |
2707 | strcat (buf, ", <unrecognized EABI>"); | |
2708 | if (e_flags) | |
2709 | unknown = TRUE; | |
2710 | break; | |
2711 | ||
2712 | case EF_ARM_EABI_VER1: | |
2713 | strcat (buf, ", Version1 EABI"); | |
2714 | while (e_flags) | |
2715 | { | |
2716 | unsigned flag; | |
2717 | ||
2718 | /* Process flags one bit at a time. */ | |
2719 | flag = e_flags & - e_flags; | |
2720 | e_flags &= ~ flag; | |
2721 | ||
2722 | switch (flag) | |
2723 | { | |
2724 | case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK. */ | |
2725 | strcat (buf, ", sorted symbol tables"); | |
2726 | break; | |
2727 | ||
2728 | default: | |
2729 | unknown = TRUE; | |
2730 | break; | |
2731 | } | |
2732 | } | |
2733 | break; | |
2734 | ||
2735 | case EF_ARM_EABI_VER2: | |
2736 | strcat (buf, ", Version2 EABI"); | |
2737 | while (e_flags) | |
2738 | { | |
2739 | unsigned flag; | |
2740 | ||
2741 | /* Process flags one bit at a time. */ | |
2742 | flag = e_flags & - e_flags; | |
2743 | e_flags &= ~ flag; | |
2744 | ||
2745 | switch (flag) | |
2746 | { | |
2747 | case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK. */ | |
2748 | strcat (buf, ", sorted symbol tables"); | |
2749 | break; | |
2750 | ||
2751 | case EF_ARM_DYNSYMSUSESEGIDX: | |
2752 | strcat (buf, ", dynamic symbols use segment index"); | |
2753 | break; | |
2754 | ||
2755 | case EF_ARM_MAPSYMSFIRST: | |
2756 | strcat (buf, ", mapping symbols precede others"); | |
2757 | break; | |
2758 | ||
2759 | default: | |
2760 | unknown = TRUE; | |
2761 | break; | |
2762 | } | |
2763 | } | |
2764 | break; | |
2765 | ||
2766 | case EF_ARM_EABI_VER3: | |
2767 | strcat (buf, ", Version3 EABI"); | |
2768 | break; | |
2769 | ||
2770 | case EF_ARM_EABI_VER4: | |
2771 | strcat (buf, ", Version4 EABI"); | |
2772 | while (e_flags) | |
2773 | { | |
2774 | unsigned flag; | |
2775 | ||
2776 | /* Process flags one bit at a time. */ | |
2777 | flag = e_flags & - e_flags; | |
2778 | e_flags &= ~ flag; | |
2779 | ||
2780 | switch (flag) | |
2781 | { | |
2782 | case EF_ARM_BE8: | |
2783 | strcat (buf, ", BE8"); | |
2784 | break; | |
2785 | ||
2786 | case EF_ARM_LE8: | |
2787 | strcat (buf, ", LE8"); | |
2788 | break; | |
2789 | ||
2790 | default: | |
2791 | unknown = TRUE; | |
2792 | break; | |
2793 | } | |
2794 | } | |
2795 | break; | |
2796 | ||
2797 | case EF_ARM_EABI_VER5: | |
2798 | strcat (buf, ", Version5 EABI"); | |
2799 | while (e_flags) | |
2800 | { | |
2801 | unsigned flag; | |
2802 | ||
2803 | /* Process flags one bit at a time. */ | |
2804 | flag = e_flags & - e_flags; | |
2805 | e_flags &= ~ flag; | |
2806 | ||
2807 | switch (flag) | |
2808 | { | |
2809 | case EF_ARM_BE8: | |
2810 | strcat (buf, ", BE8"); | |
2811 | break; | |
2812 | ||
2813 | case EF_ARM_LE8: | |
2814 | strcat (buf, ", LE8"); | |
2815 | break; | |
2816 | ||
2817 | case EF_ARM_ABI_FLOAT_SOFT: /* Conflicts with EF_ARM_SOFT_FLOAT. */ | |
2818 | strcat (buf, ", soft-float ABI"); | |
2819 | break; | |
2820 | ||
2821 | case EF_ARM_ABI_FLOAT_HARD: /* Conflicts with EF_ARM_VFP_FLOAT. */ | |
2822 | strcat (buf, ", hard-float ABI"); | |
2823 | break; | |
2824 | ||
2825 | default: | |
2826 | unknown = TRUE; | |
2827 | break; | |
2828 | } | |
2829 | } | |
2830 | break; | |
2831 | ||
2832 | case EF_ARM_EABI_UNKNOWN: | |
2833 | strcat (buf, ", GNU EABI"); | |
2834 | while (e_flags) | |
2835 | { | |
2836 | unsigned flag; | |
2837 | ||
2838 | /* Process flags one bit at a time. */ | |
2839 | flag = e_flags & - e_flags; | |
2840 | e_flags &= ~ flag; | |
2841 | ||
2842 | switch (flag) | |
2843 | { | |
2844 | case EF_ARM_INTERWORK: | |
2845 | strcat (buf, ", interworking enabled"); | |
2846 | break; | |
2847 | ||
2848 | case EF_ARM_APCS_26: | |
2849 | strcat (buf, ", uses APCS/26"); | |
2850 | break; | |
2851 | ||
2852 | case EF_ARM_APCS_FLOAT: | |
2853 | strcat (buf, ", uses APCS/float"); | |
2854 | break; | |
2855 | ||
2856 | case EF_ARM_PIC: | |
2857 | strcat (buf, ", position independent"); | |
2858 | break; | |
2859 | ||
2860 | case EF_ARM_ALIGN8: | |
2861 | strcat (buf, ", 8 bit structure alignment"); | |
2862 | break; | |
2863 | ||
2864 | case EF_ARM_NEW_ABI: | |
2865 | strcat (buf, ", uses new ABI"); | |
2866 | break; | |
2867 | ||
2868 | case EF_ARM_OLD_ABI: | |
2869 | strcat (buf, ", uses old ABI"); | |
2870 | break; | |
2871 | ||
2872 | case EF_ARM_SOFT_FLOAT: | |
2873 | strcat (buf, ", software FP"); | |
2874 | break; | |
2875 | ||
2876 | case EF_ARM_VFP_FLOAT: | |
2877 | strcat (buf, ", VFP"); | |
2878 | break; | |
2879 | ||
2880 | case EF_ARM_MAVERICK_FLOAT: | |
2881 | strcat (buf, ", Maverick FP"); | |
2882 | break; | |
2883 | ||
2884 | default: | |
2885 | unknown = TRUE; | |
2886 | break; | |
2887 | } | |
2888 | } | |
2889 | } | |
2890 | ||
2891 | if (unknown) | |
2892 | strcat (buf,_(", <unknown>")); | |
2893 | } | |
2894 | ||
2895 | static void | |
2896 | decode_AVR_machine_flags (unsigned e_flags, char buf[], size_t size) | |
2897 | { | |
2898 | --size; /* Leave space for null terminator. */ | |
2899 | ||
2900 | switch (e_flags & EF_AVR_MACH) | |
2901 | { | |
2902 | case E_AVR_MACH_AVR1: | |
2903 | strncat (buf, ", avr:1", size); | |
2904 | break; | |
2905 | case E_AVR_MACH_AVR2: | |
2906 | strncat (buf, ", avr:2", size); | |
2907 | break; | |
2908 | case E_AVR_MACH_AVR25: | |
2909 | strncat (buf, ", avr:25", size); | |
2910 | break; | |
2911 | case E_AVR_MACH_AVR3: | |
2912 | strncat (buf, ", avr:3", size); | |
2913 | break; | |
2914 | case E_AVR_MACH_AVR31: | |
2915 | strncat (buf, ", avr:31", size); | |
2916 | break; | |
2917 | case E_AVR_MACH_AVR35: | |
2918 | strncat (buf, ", avr:35", size); | |
2919 | break; | |
2920 | case E_AVR_MACH_AVR4: | |
2921 | strncat (buf, ", avr:4", size); | |
2922 | break; | |
2923 | case E_AVR_MACH_AVR5: | |
2924 | strncat (buf, ", avr:5", size); | |
2925 | break; | |
2926 | case E_AVR_MACH_AVR51: | |
2927 | strncat (buf, ", avr:51", size); | |
2928 | break; | |
2929 | case E_AVR_MACH_AVR6: | |
2930 | strncat (buf, ", avr:6", size); | |
2931 | break; | |
2932 | case E_AVR_MACH_AVRTINY: | |
2933 | strncat (buf, ", avr:100", size); | |
2934 | break; | |
2935 | case E_AVR_MACH_XMEGA1: | |
2936 | strncat (buf, ", avr:101", size); | |
2937 | break; | |
2938 | case E_AVR_MACH_XMEGA2: | |
2939 | strncat (buf, ", avr:102", size); | |
2940 | break; | |
2941 | case E_AVR_MACH_XMEGA3: | |
2942 | strncat (buf, ", avr:103", size); | |
2943 | break; | |
2944 | case E_AVR_MACH_XMEGA4: | |
2945 | strncat (buf, ", avr:104", size); | |
2946 | break; | |
2947 | case E_AVR_MACH_XMEGA5: | |
2948 | strncat (buf, ", avr:105", size); | |
2949 | break; | |
2950 | case E_AVR_MACH_XMEGA6: | |
2951 | strncat (buf, ", avr:106", size); | |
2952 | break; | |
2953 | case E_AVR_MACH_XMEGA7: | |
2954 | strncat (buf, ", avr:107", size); | |
2955 | break; | |
2956 | default: | |
2957 | strncat (buf, ", avr:<unknown>", size); | |
2958 | break; | |
2959 | } | |
2960 | ||
2961 | size -= strlen (buf); | |
2962 | if (e_flags & EF_AVR_LINKRELAX_PREPARED) | |
2963 | strncat (buf, ", link-relax", size); | |
2964 | } | |
2965 | ||
2966 | static void | |
2967 | decode_NDS32_machine_flags (unsigned e_flags, char buf[], size_t size) | |
2968 | { | |
2969 | unsigned abi; | |
2970 | unsigned arch; | |
2971 | unsigned config; | |
2972 | unsigned version; | |
2973 | bfd_boolean has_fpu = FALSE; | |
2974 | unsigned int r = 0; | |
2975 | ||
2976 | static const char *ABI_STRINGS[] = | |
2977 | { | |
2978 | "ABI v0", /* use r5 as return register; only used in N1213HC */ | |
2979 | "ABI v1", /* use r0 as return register */ | |
2980 | "ABI v2", /* use r0 as return register and don't reserve 24 bytes for arguments */ | |
2981 | "ABI v2fp", /* for FPU */ | |
2982 | "AABI", | |
2983 | "ABI2 FP+" | |
2984 | }; | |
2985 | static const char *VER_STRINGS[] = | |
2986 | { | |
2987 | "Andes ELF V1.3 or older", | |
2988 | "Andes ELF V1.3.1", | |
2989 | "Andes ELF V1.4" | |
2990 | }; | |
2991 | static const char *ARCH_STRINGS[] = | |
2992 | { | |
2993 | "", | |
2994 | "Andes Star v1.0", | |
2995 | "Andes Star v2.0", | |
2996 | "Andes Star v3.0", | |
2997 | "Andes Star v3.0m" | |
2998 | }; | |
2999 | ||
3000 | abi = EF_NDS_ABI & e_flags; | |
3001 | arch = EF_NDS_ARCH & e_flags; | |
3002 | config = EF_NDS_INST & e_flags; | |
3003 | version = EF_NDS32_ELF_VERSION & e_flags; | |
3004 | ||
3005 | memset (buf, 0, size); | |
3006 | ||
3007 | switch (abi) | |
3008 | { | |
3009 | case E_NDS_ABI_V0: | |
3010 | case E_NDS_ABI_V1: | |
3011 | case E_NDS_ABI_V2: | |
3012 | case E_NDS_ABI_V2FP: | |
3013 | case E_NDS_ABI_AABI: | |
3014 | case E_NDS_ABI_V2FP_PLUS: | |
3015 | /* In case there are holes in the array. */ | |
3016 | r += snprintf (buf + r, size - r, ", %s", ABI_STRINGS[abi >> EF_NDS_ABI_SHIFT]); | |
3017 | break; | |
3018 | ||
3019 | default: | |
3020 | r += snprintf (buf + r, size - r, ", <unrecognized ABI>"); | |
3021 | break; | |
3022 | } | |
3023 | ||
3024 | switch (version) | |
3025 | { | |
3026 | case E_NDS32_ELF_VER_1_2: | |
3027 | case E_NDS32_ELF_VER_1_3: | |
3028 | case E_NDS32_ELF_VER_1_4: | |
3029 | r += snprintf (buf + r, size - r, ", %s", VER_STRINGS[version >> EF_NDS32_ELF_VERSION_SHIFT]); | |
3030 | break; | |
3031 | ||
3032 | default: | |
3033 | r += snprintf (buf + r, size - r, ", <unrecognized ELF version number>"); | |
3034 | break; | |
3035 | } | |
3036 | ||
3037 | if (E_NDS_ABI_V0 == abi) | |
3038 | { | |
3039 | /* OLD ABI; only used in N1213HC, has performance extension 1. */ | |
3040 | r += snprintf (buf + r, size - r, ", Andes Star v1.0, N1213HC, MAC, PERF1"); | |
3041 | if (arch == E_NDS_ARCH_STAR_V1_0) | |
3042 | r += snprintf (buf + r, size -r, ", 16b"); /* has 16-bit instructions */ | |
3043 | return; | |
3044 | } | |
3045 | ||
3046 | switch (arch) | |
3047 | { | |
3048 | case E_NDS_ARCH_STAR_V1_0: | |
3049 | case E_NDS_ARCH_STAR_V2_0: | |
3050 | case E_NDS_ARCH_STAR_V3_0: | |
3051 | case E_NDS_ARCH_STAR_V3_M: | |
3052 | r += snprintf (buf + r, size - r, ", %s", ARCH_STRINGS[arch >> EF_NDS_ARCH_SHIFT]); | |
3053 | break; | |
3054 | ||
3055 | default: | |
3056 | r += snprintf (buf + r, size - r, ", <unrecognized architecture>"); | |
3057 | /* ARCH version determines how the e_flags are interpreted. | |
3058 | If it is unknown, we cannot proceed. */ | |
3059 | return; | |
3060 | } | |
3061 | ||
3062 | /* Newer ABI; Now handle architecture specific flags. */ | |
3063 | if (arch == E_NDS_ARCH_STAR_V1_0) | |
3064 | { | |
3065 | if (config & E_NDS32_HAS_MFUSR_PC_INST) | |
3066 | r += snprintf (buf + r, size -r, ", MFUSR_PC"); | |
3067 | ||
3068 | if (!(config & E_NDS32_HAS_NO_MAC_INST)) | |
3069 | r += snprintf (buf + r, size -r, ", MAC"); | |
3070 | ||
3071 | if (config & E_NDS32_HAS_DIV_INST) | |
3072 | r += snprintf (buf + r, size -r, ", DIV"); | |
3073 | ||
3074 | if (config & E_NDS32_HAS_16BIT_INST) | |
3075 | r += snprintf (buf + r, size -r, ", 16b"); | |
3076 | } | |
3077 | else | |
3078 | { | |
3079 | if (config & E_NDS32_HAS_MFUSR_PC_INST) | |
3080 | { | |
3081 | if (version <= E_NDS32_ELF_VER_1_3) | |
3082 | r += snprintf (buf + r, size -r, ", [B8]"); | |
3083 | else | |
3084 | r += snprintf (buf + r, size -r, ", EX9"); | |
3085 | } | |
3086 | ||
3087 | if (config & E_NDS32_HAS_MAC_DX_INST) | |
3088 | r += snprintf (buf + r, size -r, ", MAC_DX"); | |
3089 | ||
3090 | if (config & E_NDS32_HAS_DIV_DX_INST) | |
3091 | r += snprintf (buf + r, size -r, ", DIV_DX"); | |
3092 | ||
3093 | if (config & E_NDS32_HAS_16BIT_INST) | |
3094 | { | |
3095 | if (version <= E_NDS32_ELF_VER_1_3) | |
3096 | r += snprintf (buf + r, size -r, ", 16b"); | |
3097 | else | |
3098 | r += snprintf (buf + r, size -r, ", IFC"); | |
3099 | } | |
3100 | } | |
3101 | ||
3102 | if (config & E_NDS32_HAS_EXT_INST) | |
3103 | r += snprintf (buf + r, size -r, ", PERF1"); | |
3104 | ||
3105 | if (config & E_NDS32_HAS_EXT2_INST) | |
3106 | r += snprintf (buf + r, size -r, ", PERF2"); | |
3107 | ||
3108 | if (config & E_NDS32_HAS_FPU_INST) | |
3109 | { | |
3110 | has_fpu = TRUE; | |
3111 | r += snprintf (buf + r, size -r, ", FPU_SP"); | |
3112 | } | |
3113 | ||
3114 | if (config & E_NDS32_HAS_FPU_DP_INST) | |
3115 | { | |
3116 | has_fpu = TRUE; | |
3117 | r += snprintf (buf + r, size -r, ", FPU_DP"); | |
3118 | } | |
3119 | ||
3120 | if (config & E_NDS32_HAS_FPU_MAC_INST) | |
3121 | { | |
3122 | has_fpu = TRUE; | |
3123 | r += snprintf (buf + r, size -r, ", FPU_MAC"); | |
3124 | } | |
3125 | ||
3126 | if (has_fpu) | |
3127 | { | |
3128 | switch ((config & E_NDS32_FPU_REG_CONF) >> E_NDS32_FPU_REG_CONF_SHIFT) | |
3129 | { | |
3130 | case E_NDS32_FPU_REG_8SP_4DP: | |
3131 | r += snprintf (buf + r, size -r, ", FPU_REG:8/4"); | |
3132 | break; | |
3133 | case E_NDS32_FPU_REG_16SP_8DP: | |
3134 | r += snprintf (buf + r, size -r, ", FPU_REG:16/8"); | |
3135 | break; | |
3136 | case E_NDS32_FPU_REG_32SP_16DP: | |
3137 | r += snprintf (buf + r, size -r, ", FPU_REG:32/16"); | |
3138 | break; | |
3139 | case E_NDS32_FPU_REG_32SP_32DP: | |
3140 | r += snprintf (buf + r, size -r, ", FPU_REG:32/32"); | |
3141 | break; | |
3142 | } | |
3143 | } | |
3144 | ||
3145 | if (config & E_NDS32_HAS_AUDIO_INST) | |
3146 | r += snprintf (buf + r, size -r, ", AUDIO"); | |
3147 | ||
3148 | if (config & E_NDS32_HAS_STRING_INST) | |
3149 | r += snprintf (buf + r, size -r, ", STR"); | |
3150 | ||
3151 | if (config & E_NDS32_HAS_REDUCED_REGS) | |
3152 | r += snprintf (buf + r, size -r, ", 16REG"); | |
3153 | ||
3154 | if (config & E_NDS32_HAS_VIDEO_INST) | |
3155 | { | |
3156 | if (version <= E_NDS32_ELF_VER_1_3) | |
3157 | r += snprintf (buf + r, size -r, ", VIDEO"); | |
3158 | else | |
3159 | r += snprintf (buf + r, size -r, ", SATURATION"); | |
3160 | } | |
3161 | ||
3162 | if (config & E_NDS32_HAS_ENCRIPT_INST) | |
3163 | r += snprintf (buf + r, size -r, ", ENCRP"); | |
3164 | ||
3165 | if (config & E_NDS32_HAS_L2C_INST) | |
3166 | r += snprintf (buf + r, size -r, ", L2C"); | |
3167 | } | |
3168 | ||
3169 | static char * | |
3170 | get_machine_flags (Filedata * filedata, unsigned e_flags, unsigned e_machine) | |
3171 | { | |
3172 | static char buf[1024]; | |
3173 | ||
3174 | buf[0] = '\0'; | |
3175 | ||
3176 | if (e_flags) | |
3177 | { | |
3178 | switch (e_machine) | |
3179 | { | |
3180 | default: | |
3181 | break; | |
3182 | ||
3183 | case EM_ARC_COMPACT2: | |
3184 | case EM_ARC_COMPACT: | |
3185 | decode_ARC_machine_flags (e_flags, e_machine, buf); | |
3186 | break; | |
3187 | ||
3188 | case EM_ARM: | |
3189 | decode_ARM_machine_flags (e_flags, buf); | |
3190 | break; | |
3191 | ||
3192 | case EM_AVR: | |
3193 | decode_AVR_machine_flags (e_flags, buf, sizeof buf); | |
3194 | break; | |
3195 | ||
3196 | case EM_BLACKFIN: | |
3197 | if (e_flags & EF_BFIN_PIC) | |
3198 | strcat (buf, ", PIC"); | |
3199 | ||
3200 | if (e_flags & EF_BFIN_FDPIC) | |
3201 | strcat (buf, ", FDPIC"); | |
3202 | ||
3203 | if (e_flags & EF_BFIN_CODE_IN_L1) | |
3204 | strcat (buf, ", code in L1"); | |
3205 | ||
3206 | if (e_flags & EF_BFIN_DATA_IN_L1) | |
3207 | strcat (buf, ", data in L1"); | |
3208 | ||
3209 | break; | |
3210 | ||
3211 | case EM_CYGNUS_FRV: | |
3212 | switch (e_flags & EF_FRV_CPU_MASK) | |
3213 | { | |
3214 | case EF_FRV_CPU_GENERIC: | |
3215 | break; | |
3216 | ||
3217 | default: | |
3218 | strcat (buf, ", fr???"); | |
3219 | break; | |
3220 | ||
3221 | case EF_FRV_CPU_FR300: | |
3222 | strcat (buf, ", fr300"); | |
3223 | break; | |
3224 | ||
3225 | case EF_FRV_CPU_FR400: | |
3226 | strcat (buf, ", fr400"); | |
3227 | break; | |
3228 | case EF_FRV_CPU_FR405: | |
3229 | strcat (buf, ", fr405"); | |
3230 | break; | |
3231 | ||
3232 | case EF_FRV_CPU_FR450: | |
3233 | strcat (buf, ", fr450"); | |
3234 | break; | |
3235 | ||
3236 | case EF_FRV_CPU_FR500: | |
3237 | strcat (buf, ", fr500"); | |
3238 | break; | |
3239 | case EF_FRV_CPU_FR550: | |
3240 | strcat (buf, ", fr550"); | |
3241 | break; | |
3242 | ||
3243 | case EF_FRV_CPU_SIMPLE: | |
3244 | strcat (buf, ", simple"); | |
3245 | break; | |
3246 | case EF_FRV_CPU_TOMCAT: | |
3247 | strcat (buf, ", tomcat"); | |
3248 | break; | |
3249 | } | |
3250 | break; | |
3251 | ||
3252 | case EM_68K: | |
3253 | if ((e_flags & EF_M68K_ARCH_MASK) == EF_M68K_M68000) | |
3254 | strcat (buf, ", m68000"); | |
3255 | else if ((e_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32) | |
3256 | strcat (buf, ", cpu32"); | |
3257 | else if ((e_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO) | |
3258 | strcat (buf, ", fido_a"); | |
3259 | else | |
3260 | { | |
3261 | char const * isa = _("unknown"); | |
3262 | char const * mac = _("unknown mac"); | |
3263 | char const * additional = NULL; | |
3264 | ||
3265 | switch (e_flags & EF_M68K_CF_ISA_MASK) | |
3266 | { | |
3267 | case EF_M68K_CF_ISA_A_NODIV: | |
3268 | isa = "A"; | |
3269 | additional = ", nodiv"; | |
3270 | break; | |
3271 | case EF_M68K_CF_ISA_A: | |
3272 | isa = "A"; | |
3273 | break; | |
3274 | case EF_M68K_CF_ISA_A_PLUS: | |
3275 | isa = "A+"; | |
3276 | break; | |
3277 | case EF_M68K_CF_ISA_B_NOUSP: | |
3278 | isa = "B"; | |
3279 | additional = ", nousp"; | |
3280 | break; | |
3281 | case EF_M68K_CF_ISA_B: | |
3282 | isa = "B"; | |
3283 | break; | |
3284 | case EF_M68K_CF_ISA_C: | |
3285 | isa = "C"; | |
3286 | break; | |
3287 | case EF_M68K_CF_ISA_C_NODIV: | |
3288 | isa = "C"; | |
3289 | additional = ", nodiv"; | |
3290 | break; | |
3291 | } | |
3292 | strcat (buf, ", cf, isa "); | |
3293 | strcat (buf, isa); | |
3294 | if (additional) | |
3295 | strcat (buf, additional); | |
3296 | if (e_flags & EF_M68K_CF_FLOAT) | |
3297 | strcat (buf, ", float"); | |
3298 | switch (e_flags & EF_M68K_CF_MAC_MASK) | |
3299 | { | |
3300 | case 0: | |
3301 | mac = NULL; | |
3302 | break; | |
3303 | case EF_M68K_CF_MAC: | |
3304 | mac = "mac"; | |
3305 | break; | |
3306 | case EF_M68K_CF_EMAC: | |
3307 | mac = "emac"; | |
3308 | break; | |
3309 | case EF_M68K_CF_EMAC_B: | |
3310 | mac = "emac_b"; | |
3311 | break; | |
3312 | } | |
3313 | if (mac) | |
3314 | { | |
3315 | strcat (buf, ", "); | |
3316 | strcat (buf, mac); | |
3317 | } | |
3318 | } | |
3319 | break; | |
3320 | ||
3321 | case EM_CYGNUS_MEP: | |
3322 | switch (e_flags & EF_MEP_CPU_MASK) | |
3323 | { | |
3324 | case EF_MEP_CPU_MEP: strcat (buf, ", generic MeP"); break; | |
3325 | case EF_MEP_CPU_C2: strcat (buf, ", MeP C2"); break; | |
3326 | case EF_MEP_CPU_C3: strcat (buf, ", MeP C3"); break; | |
3327 | case EF_MEP_CPU_C4: strcat (buf, ", MeP C4"); break; | |
3328 | case EF_MEP_CPU_C5: strcat (buf, ", MeP C5"); break; | |
3329 | case EF_MEP_CPU_H1: strcat (buf, ", MeP H1"); break; | |
3330 | default: strcat (buf, _(", <unknown MeP cpu type>")); break; | |
3331 | } | |
3332 | ||
3333 | switch (e_flags & EF_MEP_COP_MASK) | |
3334 | { | |
3335 | case EF_MEP_COP_NONE: break; | |
3336 | case EF_MEP_COP_AVC: strcat (buf, ", AVC coprocessor"); break; | |
3337 | case EF_MEP_COP_AVC2: strcat (buf, ", AVC2 coprocessor"); break; | |
3338 | case EF_MEP_COP_FMAX: strcat (buf, ", FMAX coprocessor"); break; | |
3339 | case EF_MEP_COP_IVC2: strcat (buf, ", IVC2 coprocessor"); break; | |
3340 | default: strcat (buf, _("<unknown MeP copro type>")); break; | |
3341 | } | |
3342 | ||
3343 | if (e_flags & EF_MEP_LIBRARY) | |
3344 | strcat (buf, ", Built for Library"); | |
3345 | ||
3346 | if (e_flags & EF_MEP_INDEX_MASK) | |
3347 | sprintf (buf + strlen (buf), ", Configuration Index: %#x", | |
3348 | e_flags & EF_MEP_INDEX_MASK); | |
3349 | ||
3350 | if (e_flags & ~ EF_MEP_ALL_FLAGS) | |
3351 | sprintf (buf + strlen (buf), _(", unknown flags bits: %#x"), | |
3352 | e_flags & ~ EF_MEP_ALL_FLAGS); | |
3353 | break; | |
3354 | ||
3355 | case EM_PPC: | |
3356 | if (e_flags & EF_PPC_EMB) | |
3357 | strcat (buf, ", emb"); | |
3358 | ||
3359 | if (e_flags & EF_PPC_RELOCATABLE) | |
3360 | strcat (buf, _(", relocatable")); | |
3361 | ||
3362 | if (e_flags & EF_PPC_RELOCATABLE_LIB) | |
3363 | strcat (buf, _(", relocatable-lib")); | |
3364 | break; | |
3365 | ||
3366 | case EM_PPC64: | |
3367 | if (e_flags & EF_PPC64_ABI) | |
3368 | { | |
3369 | char abi[] = ", abiv0"; | |
3370 | ||
3371 | abi[6] += e_flags & EF_PPC64_ABI; | |
3372 | strcat (buf, abi); | |
3373 | } | |
3374 | break; | |
3375 | ||
3376 | case EM_V800: | |
3377 | if ((e_flags & EF_RH850_ABI) == EF_RH850_ABI) | |
3378 | strcat (buf, ", RH850 ABI"); | |
3379 | ||
3380 | if (e_flags & EF_V800_850E3) | |
3381 | strcat (buf, ", V3 architecture"); | |
3382 | ||
3383 | if ((e_flags & (EF_RH850_FPU_DOUBLE | EF_RH850_FPU_SINGLE)) == 0) | |
3384 | strcat (buf, ", FPU not used"); | |
3385 | ||
3386 | if ((e_flags & (EF_RH850_REGMODE22 | EF_RH850_REGMODE32)) == 0) | |
3387 | strcat (buf, ", regmode: COMMON"); | |
3388 | ||
3389 | if ((e_flags & (EF_RH850_GP_FIX | EF_RH850_GP_NOFIX)) == 0) | |
3390 | strcat (buf, ", r4 not used"); | |
3391 | ||
3392 | if ((e_flags & (EF_RH850_EP_FIX | EF_RH850_EP_NOFIX)) == 0) | |
3393 | strcat (buf, ", r30 not used"); | |
3394 | ||
3395 | if ((e_flags & (EF_RH850_TP_FIX | EF_RH850_TP_NOFIX)) == 0) | |
3396 | strcat (buf, ", r5 not used"); | |
3397 | ||
3398 | if ((e_flags & (EF_RH850_REG2_RESERVE | EF_RH850_REG2_NORESERVE)) == 0) | |
3399 | strcat (buf, ", r2 not used"); | |
3400 | ||
3401 | for (e_flags &= 0xFFFF; e_flags; e_flags &= ~ (e_flags & - e_flags)) | |
3402 | { | |
3403 | switch (e_flags & - e_flags) | |
3404 | { | |
3405 | case EF_RH850_FPU_DOUBLE: strcat (buf, ", double precision FPU"); break; | |
3406 | case EF_RH850_FPU_SINGLE: strcat (buf, ", single precision FPU"); break; | |
3407 | case EF_RH850_REGMODE22: strcat (buf, ", regmode:22"); break; | |
3408 | case EF_RH850_REGMODE32: strcat (buf, ", regmode:23"); break; | |
3409 | case EF_RH850_GP_FIX: strcat (buf, ", r4 fixed"); break; | |
3410 | case EF_RH850_GP_NOFIX: strcat (buf, ", r4 free"); break; | |
3411 | case EF_RH850_EP_FIX: strcat (buf, ", r30 fixed"); break; | |
3412 | case EF_RH850_EP_NOFIX: strcat (buf, ", r30 free"); break; | |
3413 | case EF_RH850_TP_FIX: strcat (buf, ", r5 fixed"); break; | |
3414 | case EF_RH850_TP_NOFIX: strcat (buf, ", r5 free"); break; | |
3415 | case EF_RH850_REG2_RESERVE: strcat (buf, ", r2 fixed"); break; | |
3416 | case EF_RH850_REG2_NORESERVE: strcat (buf, ", r2 free"); break; | |
3417 | default: break; | |
3418 | } | |
3419 | } | |
3420 | break; | |
3421 | ||
3422 | case EM_V850: | |
3423 | case EM_CYGNUS_V850: | |
3424 | switch (e_flags & EF_V850_ARCH) | |
3425 | { | |
3426 | case E_V850E3V5_ARCH: | |
3427 | strcat (buf, ", v850e3v5"); | |
3428 | break; | |
3429 | case E_V850E2V3_ARCH: | |
3430 | strcat (buf, ", v850e2v3"); | |
3431 | break; | |
3432 | case E_V850E2_ARCH: | |
3433 | strcat (buf, ", v850e2"); | |
3434 | break; | |
3435 | case E_V850E1_ARCH: | |
3436 | strcat (buf, ", v850e1"); | |
3437 | break; | |
3438 | case E_V850E_ARCH: | |
3439 | strcat (buf, ", v850e"); | |
3440 | break; | |
3441 | case E_V850_ARCH: | |
3442 | strcat (buf, ", v850"); | |
3443 | break; | |
3444 | default: | |
3445 | strcat (buf, _(", unknown v850 architecture variant")); | |
3446 | break; | |
3447 | } | |
3448 | break; | |
3449 | ||
3450 | case EM_M32R: | |
3451 | case EM_CYGNUS_M32R: | |
3452 | if ((e_flags & EF_M32R_ARCH) == E_M32R_ARCH) | |
3453 | strcat (buf, ", m32r"); | |
3454 | break; | |
3455 | ||
3456 | case EM_MIPS: | |
3457 | case EM_MIPS_RS3_LE: | |
3458 | if (e_flags & EF_MIPS_NOREORDER) | |
3459 | strcat (buf, ", noreorder"); | |
3460 | ||
3461 | if (e_flags & EF_MIPS_PIC) | |
3462 | strcat (buf, ", pic"); | |
3463 | ||
3464 | if (e_flags & EF_MIPS_CPIC) | |
3465 | strcat (buf, ", cpic"); | |
3466 | ||
3467 | if (e_flags & EF_MIPS_UCODE) | |
3468 | strcat (buf, ", ugen_reserved"); | |
3469 | ||
3470 | if (e_flags & EF_MIPS_ABI2) | |
3471 | strcat (buf, ", abi2"); | |
3472 | ||
3473 | if (e_flags & EF_MIPS_OPTIONS_FIRST) | |
3474 | strcat (buf, ", odk first"); | |
3475 | ||
3476 | if (e_flags & EF_MIPS_32BITMODE) | |
3477 | strcat (buf, ", 32bitmode"); | |
3478 | ||
3479 | if (e_flags & EF_MIPS_NAN2008) | |
3480 | strcat (buf, ", nan2008"); | |
3481 | ||
3482 | if (e_flags & EF_MIPS_FP64) | |
3483 | strcat (buf, ", fp64"); | |
3484 | ||
3485 | switch ((e_flags & EF_MIPS_MACH)) | |
3486 | { | |
3487 | case E_MIPS_MACH_3900: strcat (buf, ", 3900"); break; | |
3488 | case E_MIPS_MACH_4010: strcat (buf, ", 4010"); break; | |
3489 | case E_MIPS_MACH_4100: strcat (buf, ", 4100"); break; | |
3490 | case E_MIPS_MACH_4111: strcat (buf, ", 4111"); break; | |
3491 | case E_MIPS_MACH_4120: strcat (buf, ", 4120"); break; | |
3492 | case E_MIPS_MACH_4650: strcat (buf, ", 4650"); break; | |
3493 | case E_MIPS_MACH_5400: strcat (buf, ", 5400"); break; | |
3494 | case E_MIPS_MACH_5500: strcat (buf, ", 5500"); break; | |
3495 | case E_MIPS_MACH_5900: strcat (buf, ", 5900"); break; | |
3496 | case E_MIPS_MACH_SB1: strcat (buf, ", sb1"); break; | |
3497 | case E_MIPS_MACH_9000: strcat (buf, ", 9000"); break; | |
3498 | case E_MIPS_MACH_LS2E: strcat (buf, ", loongson-2e"); break; | |
3499 | case E_MIPS_MACH_LS2F: strcat (buf, ", loongson-2f"); break; | |
3500 | case E_MIPS_MACH_GS464: strcat (buf, ", gs464"); break; | |
3501 | case E_MIPS_MACH_GS464E: strcat (buf, ", gs464e"); break; | |
3502 | case E_MIPS_MACH_GS264E: strcat (buf, ", gs264e"); break; | |
3503 | case E_MIPS_MACH_OCTEON: strcat (buf, ", octeon"); break; | |
3504 | case E_MIPS_MACH_OCTEON2: strcat (buf, ", octeon2"); break; | |
3505 | case E_MIPS_MACH_OCTEON3: strcat (buf, ", octeon3"); break; | |
3506 | case E_MIPS_MACH_XLR: strcat (buf, ", xlr"); break; | |
3507 | case E_MIPS_MACH_IAMR2: strcat (buf, ", interaptiv-mr2"); break; | |
3508 | case 0: | |
3509 | /* We simply ignore the field in this case to avoid confusion: | |
3510 | MIPS ELF does not specify EF_MIPS_MACH, it is a GNU | |
3511 | extension. */ | |
3512 | break; | |
3513 | default: strcat (buf, _(", unknown CPU")); break; | |
3514 | } | |
3515 | ||
3516 | switch ((e_flags & EF_MIPS_ABI)) | |
3517 | { | |
3518 | case E_MIPS_ABI_O32: strcat (buf, ", o32"); break; | |
3519 | case E_MIPS_ABI_O64: strcat (buf, ", o64"); break; | |
3520 | case E_MIPS_ABI_EABI32: strcat (buf, ", eabi32"); break; | |
3521 | case E_MIPS_ABI_EABI64: strcat (buf, ", eabi64"); break; | |
3522 | case 0: | |
3523 | /* We simply ignore the field in this case to avoid confusion: | |
3524 | MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension. | |
3525 | This means it is likely to be an o32 file, but not for | |
3526 | sure. */ | |
3527 | break; | |
3528 | default: strcat (buf, _(", unknown ABI")); break; | |
3529 | } | |
3530 | ||
3531 | if (e_flags & EF_MIPS_ARCH_ASE_MDMX) | |
3532 | strcat (buf, ", mdmx"); | |
3533 | ||
3534 | if (e_flags & EF_MIPS_ARCH_ASE_M16) | |
3535 | strcat (buf, ", mips16"); | |
3536 | ||
3537 | if (e_flags & EF_MIPS_ARCH_ASE_MICROMIPS) | |
3538 | strcat (buf, ", micromips"); | |
3539 | ||
3540 | switch ((e_flags & EF_MIPS_ARCH)) | |
3541 | { | |
3542 | case E_MIPS_ARCH_1: strcat (buf, ", mips1"); break; | |
3543 | case E_MIPS_ARCH_2: strcat (buf, ", mips2"); break; | |
3544 | case E_MIPS_ARCH_3: strcat (buf, ", mips3"); break; | |
3545 | case E_MIPS_ARCH_4: strcat (buf, ", mips4"); break; | |
3546 | case E_MIPS_ARCH_5: strcat (buf, ", mips5"); break; | |
3547 | case E_MIPS_ARCH_32: strcat (buf, ", mips32"); break; | |
3548 | case E_MIPS_ARCH_32R2: strcat (buf, ", mips32r2"); break; | |
3549 | case E_MIPS_ARCH_32R6: strcat (buf, ", mips32r6"); break; | |
3550 | case E_MIPS_ARCH_64: strcat (buf, ", mips64"); break; | |
3551 | case E_MIPS_ARCH_64R2: strcat (buf, ", mips64r2"); break; | |
3552 | case E_MIPS_ARCH_64R6: strcat (buf, ", mips64r6"); break; | |
3553 | default: strcat (buf, _(", unknown ISA")); break; | |
3554 | } | |
3555 | break; | |
3556 | ||
3557 | case EM_NDS32: | |
3558 | decode_NDS32_machine_flags (e_flags, buf, sizeof buf); | |
3559 | break; | |
3560 | ||
3561 | case EM_NFP: | |
3562 | switch (EF_NFP_MACH (e_flags)) | |
3563 | { | |
3564 | case E_NFP_MACH_3200: | |
3565 | strcat (buf, ", NFP-32xx"); | |
3566 | break; | |
3567 | case E_NFP_MACH_6000: | |
3568 | strcat (buf, ", NFP-6xxx"); | |
3569 | break; | |
3570 | } | |
3571 | break; | |
3572 | ||
3573 | case EM_RISCV: | |
3574 | if (e_flags & EF_RISCV_RVC) | |
3575 | strcat (buf, ", RVC"); | |
3576 | ||
3577 | if (e_flags & EF_RISCV_RVE) | |
3578 | strcat (buf, ", RVE"); | |
3579 | ||
3580 | switch (e_flags & EF_RISCV_FLOAT_ABI) | |
3581 | { | |
3582 | case EF_RISCV_FLOAT_ABI_SOFT: | |
3583 | strcat (buf, ", soft-float ABI"); | |
3584 | break; | |
3585 | ||
3586 | case EF_RISCV_FLOAT_ABI_SINGLE: | |
3587 | strcat (buf, ", single-float ABI"); | |
3588 | break; | |
3589 | ||
3590 | case EF_RISCV_FLOAT_ABI_DOUBLE: | |
3591 | strcat (buf, ", double-float ABI"); | |
3592 | break; | |
3593 | ||
3594 | case EF_RISCV_FLOAT_ABI_QUAD: | |
3595 | strcat (buf, ", quad-float ABI"); | |
3596 | break; | |
3597 | } | |
3598 | break; | |
3599 | ||
3600 | case EM_SH: | |
3601 | switch ((e_flags & EF_SH_MACH_MASK)) | |
3602 | { | |
3603 | case EF_SH1: strcat (buf, ", sh1"); break; | |
3604 | case EF_SH2: strcat (buf, ", sh2"); break; | |
3605 | case EF_SH3: strcat (buf, ", sh3"); break; | |
3606 | case EF_SH_DSP: strcat (buf, ", sh-dsp"); break; | |
3607 | case EF_SH3_DSP: strcat (buf, ", sh3-dsp"); break; | |
3608 | case EF_SH4AL_DSP: strcat (buf, ", sh4al-dsp"); break; | |
3609 | case EF_SH3E: strcat (buf, ", sh3e"); break; | |
3610 | case EF_SH4: strcat (buf, ", sh4"); break; | |
3611 | case EF_SH5: strcat (buf, ", sh5"); break; | |
3612 | case EF_SH2E: strcat (buf, ", sh2e"); break; | |
3613 | case EF_SH4A: strcat (buf, ", sh4a"); break; | |
3614 | case EF_SH2A: strcat (buf, ", sh2a"); break; | |
3615 | case EF_SH4_NOFPU: strcat (buf, ", sh4-nofpu"); break; | |
3616 | case EF_SH4A_NOFPU: strcat (buf, ", sh4a-nofpu"); break; | |
3617 | case EF_SH2A_NOFPU: strcat (buf, ", sh2a-nofpu"); break; | |
3618 | case EF_SH3_NOMMU: strcat (buf, ", sh3-nommu"); break; | |
3619 | case EF_SH4_NOMMU_NOFPU: strcat (buf, ", sh4-nommu-nofpu"); break; | |
3620 | case EF_SH2A_SH4_NOFPU: strcat (buf, ", sh2a-nofpu-or-sh4-nommu-nofpu"); break; | |
3621 | case EF_SH2A_SH3_NOFPU: strcat (buf, ", sh2a-nofpu-or-sh3-nommu"); break; | |
3622 | case EF_SH2A_SH4: strcat (buf, ", sh2a-or-sh4"); break; | |
3623 | case EF_SH2A_SH3E: strcat (buf, ", sh2a-or-sh3e"); break; | |
3624 | default: strcat (buf, _(", unknown ISA")); break; | |
3625 | } | |
3626 | ||
3627 | if (e_flags & EF_SH_PIC) | |
3628 | strcat (buf, ", pic"); | |
3629 | ||
3630 | if (e_flags & EF_SH_FDPIC) | |
3631 | strcat (buf, ", fdpic"); | |
3632 | break; | |
3633 | ||
3634 | case EM_OR1K: | |
3635 | if (e_flags & EF_OR1K_NODELAY) | |
3636 | strcat (buf, ", no delay"); | |
3637 | break; | |
3638 | ||
3639 | case EM_SPARCV9: | |
3640 | if (e_flags & EF_SPARC_32PLUS) | |
3641 | strcat (buf, ", v8+"); | |
3642 | ||
3643 | if (e_flags & EF_SPARC_SUN_US1) | |
3644 | strcat (buf, ", ultrasparcI"); | |
3645 | ||
3646 | if (e_flags & EF_SPARC_SUN_US3) | |
3647 | strcat (buf, ", ultrasparcIII"); | |
3648 | ||
3649 | if (e_flags & EF_SPARC_HAL_R1) | |
3650 | strcat (buf, ", halr1"); | |
3651 | ||
3652 | if (e_flags & EF_SPARC_LEDATA) | |
3653 | strcat (buf, ", ledata"); | |
3654 | ||
3655 | if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_TSO) | |
3656 | strcat (buf, ", tso"); | |
3657 | ||
3658 | if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_PSO) | |
3659 | strcat (buf, ", pso"); | |
3660 | ||
3661 | if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_RMO) | |
3662 | strcat (buf, ", rmo"); | |
3663 | break; | |
3664 | ||
3665 | case EM_PARISC: | |
3666 | switch (e_flags & EF_PARISC_ARCH) | |
3667 | { | |
3668 | case EFA_PARISC_1_0: | |
3669 | strcpy (buf, ", PA-RISC 1.0"); | |
3670 | break; | |
3671 | case EFA_PARISC_1_1: | |
3672 | strcpy (buf, ", PA-RISC 1.1"); | |
3673 | break; | |
3674 | case EFA_PARISC_2_0: | |
3675 | strcpy (buf, ", PA-RISC 2.0"); | |
3676 | break; | |
3677 | default: | |
3678 | break; | |
3679 | } | |
3680 | if (e_flags & EF_PARISC_TRAPNIL) | |
3681 | strcat (buf, ", trapnil"); | |
3682 | if (e_flags & EF_PARISC_EXT) | |
3683 | strcat (buf, ", ext"); | |
3684 | if (e_flags & EF_PARISC_LSB) | |
3685 | strcat (buf, ", lsb"); | |
3686 | if (e_flags & EF_PARISC_WIDE) | |
3687 | strcat (buf, ", wide"); | |
3688 | if (e_flags & EF_PARISC_NO_KABP) | |
3689 | strcat (buf, ", no kabp"); | |
3690 | if (e_flags & EF_PARISC_LAZYSWAP) | |
3691 | strcat (buf, ", lazyswap"); | |
3692 | break; | |
3693 | ||
3694 | case EM_PJ: | |
3695 | case EM_PJ_OLD: | |
3696 | if ((e_flags & EF_PICOJAVA_NEWCALLS) == EF_PICOJAVA_NEWCALLS) | |
3697 | strcat (buf, ", new calling convention"); | |
3698 | ||
3699 | if ((e_flags & EF_PICOJAVA_GNUCALLS) == EF_PICOJAVA_GNUCALLS) | |
3700 | strcat (buf, ", gnu calling convention"); | |
3701 | break; | |
3702 | ||
3703 | case EM_IA_64: | |
3704 | if ((e_flags & EF_IA_64_ABI64)) | |
3705 | strcat (buf, ", 64-bit"); | |
3706 | else | |
3707 | strcat (buf, ", 32-bit"); | |
3708 | if ((e_flags & EF_IA_64_REDUCEDFP)) | |
3709 | strcat (buf, ", reduced fp model"); | |
3710 | if ((e_flags & EF_IA_64_NOFUNCDESC_CONS_GP)) | |
3711 | strcat (buf, ", no function descriptors, constant gp"); | |
3712 | else if ((e_flags & EF_IA_64_CONS_GP)) | |
3713 | strcat (buf, ", constant gp"); | |
3714 | if ((e_flags & EF_IA_64_ABSOLUTE)) | |
3715 | strcat (buf, ", absolute"); | |
3716 | if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_OPENVMS) | |
3717 | { | |
3718 | if ((e_flags & EF_IA_64_VMS_LINKAGES)) | |
3719 | strcat (buf, ", vms_linkages"); | |
3720 | switch ((e_flags & EF_IA_64_VMS_COMCOD)) | |
3721 | { | |
3722 | case EF_IA_64_VMS_COMCOD_SUCCESS: | |
3723 | break; | |
3724 | case EF_IA_64_VMS_COMCOD_WARNING: | |
3725 | strcat (buf, ", warning"); | |
3726 | break; | |
3727 | case EF_IA_64_VMS_COMCOD_ERROR: | |
3728 | strcat (buf, ", error"); | |
3729 | break; | |
3730 | case EF_IA_64_VMS_COMCOD_ABORT: | |
3731 | strcat (buf, ", abort"); | |
3732 | break; | |
3733 | default: | |
3734 | warn (_("Unrecognised IA64 VMS Command Code: %x\n"), | |
3735 | e_flags & EF_IA_64_VMS_COMCOD); | |
3736 | strcat (buf, ", <unknown>"); | |
3737 | } | |
3738 | } | |
3739 | break; | |
3740 | ||
3741 | case EM_VAX: | |
3742 | if ((e_flags & EF_VAX_NONPIC)) | |
3743 | strcat (buf, ", non-PIC"); | |
3744 | if ((e_flags & EF_VAX_DFLOAT)) | |
3745 | strcat (buf, ", D-Float"); | |
3746 | if ((e_flags & EF_VAX_GFLOAT)) | |
3747 | strcat (buf, ", G-Float"); | |
3748 | break; | |
3749 | ||
3750 | case EM_VISIUM: | |
3751 | if (e_flags & EF_VISIUM_ARCH_MCM) | |
3752 | strcat (buf, ", mcm"); | |
3753 | else if (e_flags & EF_VISIUM_ARCH_MCM24) | |
3754 | strcat (buf, ", mcm24"); | |
3755 | if (e_flags & EF_VISIUM_ARCH_GR6) | |
3756 | strcat (buf, ", gr6"); | |
3757 | break; | |
3758 | ||
3759 | case EM_RL78: | |
3760 | switch (e_flags & E_FLAG_RL78_CPU_MASK) | |
3761 | { | |
3762 | case E_FLAG_RL78_ANY_CPU: break; | |
3763 | case E_FLAG_RL78_G10: strcat (buf, ", G10"); break; | |
3764 | case E_FLAG_RL78_G13: strcat (buf, ", G13"); break; | |
3765 | case E_FLAG_RL78_G14: strcat (buf, ", G14"); break; | |
3766 | } | |
3767 | if (e_flags & E_FLAG_RL78_64BIT_DOUBLES) | |
3768 | strcat (buf, ", 64-bit doubles"); | |
3769 | break; | |
3770 | ||
3771 | case EM_RX: | |
3772 | if (e_flags & E_FLAG_RX_64BIT_DOUBLES) | |
3773 | strcat (buf, ", 64-bit doubles"); | |
3774 | if (e_flags & E_FLAG_RX_DSP) | |
3775 | strcat (buf, ", dsp"); | |
3776 | if (e_flags & E_FLAG_RX_PID) | |
3777 | strcat (buf, ", pid"); | |
3778 | if (e_flags & E_FLAG_RX_ABI) | |
3779 | strcat (buf, ", RX ABI"); | |
3780 | if (e_flags & E_FLAG_RX_SINSNS_SET) | |
3781 | strcat (buf, e_flags & E_FLAG_RX_SINSNS_YES | |
3782 | ? ", uses String instructions" : ", bans String instructions"); | |
3783 | if (e_flags & E_FLAG_RX_V2) | |
3784 | strcat (buf, ", V2"); | |
3785 | if (e_flags & E_FLAG_RX_V3) | |
3786 | strcat (buf, ", V3"); | |
3787 | break; | |
3788 | ||
3789 | case EM_S390: | |
3790 | if (e_flags & EF_S390_HIGH_GPRS) | |
3791 | strcat (buf, ", highgprs"); | |
3792 | break; | |
3793 | ||
3794 | case EM_TI_C6000: | |
3795 | if ((e_flags & EF_C6000_REL)) | |
3796 | strcat (buf, ", relocatable module"); | |
3797 | break; | |
3798 | ||
3799 | case EM_MSP430: | |
3800 | strcat (buf, _(": architecture variant: ")); | |
3801 | switch (e_flags & EF_MSP430_MACH) | |
3802 | { | |
3803 | case E_MSP430_MACH_MSP430x11: strcat (buf, "MSP430x11"); break; | |
3804 | case E_MSP430_MACH_MSP430x11x1 : strcat (buf, "MSP430x11x1 "); break; | |
3805 | case E_MSP430_MACH_MSP430x12: strcat (buf, "MSP430x12"); break; | |
3806 | case E_MSP430_MACH_MSP430x13: strcat (buf, "MSP430x13"); break; | |
3807 | case E_MSP430_MACH_MSP430x14: strcat (buf, "MSP430x14"); break; | |
3808 | case E_MSP430_MACH_MSP430x15: strcat (buf, "MSP430x15"); break; | |
3809 | case E_MSP430_MACH_MSP430x16: strcat (buf, "MSP430x16"); break; | |
3810 | case E_MSP430_MACH_MSP430x31: strcat (buf, "MSP430x31"); break; | |
3811 | case E_MSP430_MACH_MSP430x32: strcat (buf, "MSP430x32"); break; | |
3812 | case E_MSP430_MACH_MSP430x33: strcat (buf, "MSP430x33"); break; | |
3813 | case E_MSP430_MACH_MSP430x41: strcat (buf, "MSP430x41"); break; | |
3814 | case E_MSP430_MACH_MSP430x42: strcat (buf, "MSP430x42"); break; | |
3815 | case E_MSP430_MACH_MSP430x43: strcat (buf, "MSP430x43"); break; | |
3816 | case E_MSP430_MACH_MSP430x44: strcat (buf, "MSP430x44"); break; | |
3817 | case E_MSP430_MACH_MSP430X : strcat (buf, "MSP430X"); break; | |
3818 | default: | |
3819 | strcat (buf, _(": unknown")); break; | |
3820 | } | |
3821 | ||
3822 | if (e_flags & ~ EF_MSP430_MACH) | |
3823 | strcat (buf, _(": unknown extra flag bits also present")); | |
3824 | break; | |
3825 | ||
3826 | case EM_Z80: | |
3827 | switch (e_flags & EF_Z80_MACH_MSK) | |
3828 | { | |
3829 | case EF_Z80_MACH_Z80: strcat (buf, ", Z80"); break; | |
3830 | case EF_Z80_MACH_Z180: strcat (buf, ", Z180"); break; | |
3831 | case EF_Z80_MACH_R800: strcat (buf, ", R800"); break; | |
3832 | case EF_Z80_MACH_EZ80_Z80: strcat (buf, ", EZ80"); break; | |
3833 | case EF_Z80_MACH_EZ80_ADL: strcat (buf, ", EZ80, ADL"); break; | |
3834 | case EF_Z80_MACH_GBZ80: strcat (buf, ", GBZ80"); break; | |
3835 | case EF_Z80_MACH_Z80N: strcat (buf, ", Z80N"); break; | |
3836 | default: | |
3837 | strcat (buf, _(", unknown")); break; | |
3838 | } | |
3839 | break; | |
3840 | } | |
3841 | } | |
3842 | ||
3843 | return buf; | |
3844 | } | |
3845 | ||
3846 | static const char * | |
3847 | get_osabi_name (Filedata * filedata, unsigned int osabi) | |
3848 | { | |
3849 | static char buff[32]; | |
3850 | ||
3851 | switch (osabi) | |
3852 | { | |
3853 | case ELFOSABI_NONE: return "UNIX - System V"; | |
3854 | case ELFOSABI_HPUX: return "UNIX - HP-UX"; | |
3855 | case ELFOSABI_NETBSD: return "UNIX - NetBSD"; | |
3856 | case ELFOSABI_GNU: return "UNIX - GNU"; | |
3857 | case ELFOSABI_SOLARIS: return "UNIX - Solaris"; | |
3858 | case ELFOSABI_AIX: return "UNIX - AIX"; | |
3859 | case ELFOSABI_IRIX: return "UNIX - IRIX"; | |
3860 | case ELFOSABI_FREEBSD: return "UNIX - FreeBSD"; | |
3861 | case ELFOSABI_TRU64: return "UNIX - TRU64"; | |
3862 | case ELFOSABI_MODESTO: return "Novell - Modesto"; | |
3863 | case ELFOSABI_OPENBSD: return "UNIX - OpenBSD"; | |
3864 | case ELFOSABI_OPENVMS: return "VMS - OpenVMS"; | |
3865 | case ELFOSABI_NSK: return "HP - Non-Stop Kernel"; | |
3866 | case ELFOSABI_AROS: return "AROS"; | |
3867 | case ELFOSABI_FENIXOS: return "FenixOS"; | |
3868 | case ELFOSABI_CLOUDABI: return "Nuxi CloudABI"; | |
3869 | case ELFOSABI_OPENVOS: return "Stratus Technologies OpenVOS"; | |
3870 | default: | |
3871 | if (osabi >= 64) | |
3872 | switch (filedata->file_header.e_machine) | |
3873 | { | |
3874 | case EM_ARM: | |
3875 | switch (osabi) | |
3876 | { | |
3877 | case ELFOSABI_ARM: return "ARM"; | |
3878 | case ELFOSABI_ARM_FDPIC: return "ARM FDPIC"; | |
3879 | default: | |
3880 | break; | |
3881 | } | |
3882 | break; | |
3883 | ||
3884 | case EM_MSP430: | |
3885 | case EM_MSP430_OLD: | |
3886 | case EM_VISIUM: | |
3887 | switch (osabi) | |
3888 | { | |
3889 | case ELFOSABI_STANDALONE: return _("Standalone App"); | |
3890 | default: | |
3891 | break; | |
3892 | } | |
3893 | break; | |
3894 | ||
3895 | case EM_TI_C6000: | |
3896 | switch (osabi) | |
3897 | { | |
3898 | case ELFOSABI_C6000_ELFABI: return _("Bare-metal C6000"); | |
3899 | case ELFOSABI_C6000_LINUX: return "Linux C6000"; | |
3900 | default: | |
3901 | break; | |
3902 | } | |
3903 | break; | |
3904 | ||
3905 | default: | |
3906 | break; | |
3907 | } | |
3908 | snprintf (buff, sizeof (buff), _("<unknown: %x>"), osabi); | |
3909 | return buff; | |
3910 | } | |
3911 | } | |
3912 | ||
3913 | static const char * | |
3914 | get_aarch64_segment_type (unsigned long type) | |
3915 | { | |
3916 | switch (type) | |
3917 | { | |
3918 | case PT_AARCH64_ARCHEXT: return "AARCH64_ARCHEXT"; | |
3919 | default: return NULL; | |
3920 | } | |
3921 | } | |
3922 | ||
3923 | static const char * | |
3924 | get_arm_segment_type (unsigned long type) | |
3925 | { | |
3926 | switch (type) | |
3927 | { | |
3928 | case PT_ARM_EXIDX: return "EXIDX"; | |
3929 | default: return NULL; | |
3930 | } | |
3931 | } | |
3932 | ||
3933 | static const char * | |
3934 | get_s390_segment_type (unsigned long type) | |
3935 | { | |
3936 | switch (type) | |
3937 | { | |
3938 | case PT_S390_PGSTE: return "S390_PGSTE"; | |
3939 | default: return NULL; | |
3940 | } | |
3941 | } | |
3942 | ||
3943 | static const char * | |
3944 | get_mips_segment_type (unsigned long type) | |
3945 | { | |
3946 | switch (type) | |
3947 | { | |
3948 | case PT_MIPS_REGINFO: return "REGINFO"; | |
3949 | case PT_MIPS_RTPROC: return "RTPROC"; | |
3950 | case PT_MIPS_OPTIONS: return "OPTIONS"; | |
3951 | case PT_MIPS_ABIFLAGS: return "ABIFLAGS"; | |
3952 | default: return NULL; | |
3953 | } | |
3954 | } | |
3955 | ||
3956 | static const char * | |
3957 | get_parisc_segment_type (unsigned long type) | |
3958 | { | |
3959 | switch (type) | |
3960 | { | |
3961 | case PT_PARISC_ARCHEXT: return "PARISC_ARCHEXT"; | |
3962 | case PT_PARISC_UNWIND: return "PARISC_UNWIND"; | |
3963 | case PT_PARISC_WEAKORDER: return "PARISC_WEAKORDER"; | |
3964 | default: return NULL; | |
3965 | } | |
3966 | } | |
3967 | ||
3968 | static const char * | |
3969 | get_ia64_segment_type (unsigned long type) | |
3970 | { | |
3971 | switch (type) | |
3972 | { | |
3973 | case PT_IA_64_ARCHEXT: return "IA_64_ARCHEXT"; | |
3974 | case PT_IA_64_UNWIND: return "IA_64_UNWIND"; | |
3975 | default: return NULL; | |
3976 | } | |
3977 | } | |
3978 | ||
3979 | static const char * | |
3980 | get_tic6x_segment_type (unsigned long type) | |
3981 | { | |
3982 | switch (type) | |
3983 | { | |
3984 | case PT_C6000_PHATTR: return "C6000_PHATTR"; | |
3985 | default: return NULL; | |
3986 | } | |
3987 | } | |
3988 | ||
3989 | static const char * | |
3990 | get_hpux_segment_type (unsigned long type, unsigned e_machine) | |
3991 | { | |
3992 | if (e_machine == EM_PARISC) | |
3993 | switch (type) | |
3994 | { | |
3995 | case PT_HP_TLS: return "HP_TLS"; | |
3996 | case PT_HP_CORE_NONE: return "HP_CORE_NONE"; | |
3997 | case PT_HP_CORE_VERSION: return "HP_CORE_VERSION"; | |
3998 | case PT_HP_CORE_KERNEL: return "HP_CORE_KERNEL"; | |
3999 | case PT_HP_CORE_COMM: return "HP_CORE_COMM"; | |
4000 | case PT_HP_CORE_PROC: return "HP_CORE_PROC"; | |
4001 | case PT_HP_CORE_LOADABLE: return "HP_CORE_LOADABLE"; | |
4002 | case PT_HP_CORE_STACK: return "HP_CORE_STACK"; | |
4003 | case PT_HP_CORE_SHM: return "HP_CORE_SHM"; | |
4004 | case PT_HP_CORE_MMF: return "HP_CORE_MMF"; | |
4005 | case PT_HP_PARALLEL: return "HP_PARALLEL"; | |
4006 | case PT_HP_FASTBIND: return "HP_FASTBIND"; | |
4007 | case PT_HP_OPT_ANNOT: return "HP_OPT_ANNOT"; | |
4008 | case PT_HP_HSL_ANNOT: return "HP_HSL_ANNOT"; | |
4009 | case PT_HP_STACK: return "HP_STACK"; | |
4010 | case PT_HP_CORE_UTSNAME: return "HP_CORE_UTSNAME"; | |
4011 | default: return NULL; | |
4012 | } | |
4013 | ||
4014 | if (e_machine == EM_IA_64) | |
4015 | switch (type) | |
4016 | { | |
4017 | case PT_HP_TLS: return "HP_TLS"; | |
4018 | case PT_IA_64_HP_OPT_ANOT: return "HP_OPT_ANNOT"; | |
4019 | case PT_IA_64_HP_HSL_ANOT: return "HP_HSL_ANNOT"; | |
4020 | case PT_IA_64_HP_STACK: return "HP_STACK"; | |
4021 | default: return NULL; | |
4022 | } | |
4023 | ||
4024 | return NULL; | |
4025 | } | |
4026 | ||
4027 | static const char * | |
4028 | get_solaris_segment_type (unsigned long type) | |
4029 | { | |
4030 | switch (type) | |
4031 | { | |
4032 | case 0x6464e550: return "PT_SUNW_UNWIND"; | |
4033 | case 0x6474e550: return "PT_SUNW_EH_FRAME"; | |
4034 | case 0x6ffffff7: return "PT_LOSUNW"; | |
4035 | case 0x6ffffffa: return "PT_SUNWBSS"; | |
4036 | case 0x6ffffffb: return "PT_SUNWSTACK"; | |
4037 | case 0x6ffffffc: return "PT_SUNWDTRACE"; | |
4038 | case 0x6ffffffd: return "PT_SUNWCAP"; | |
4039 | case 0x6fffffff: return "PT_HISUNW"; | |
4040 | default: return NULL; | |
4041 | } | |
4042 | } | |
4043 | ||
4044 | static const char * | |
4045 | get_segment_type (Filedata * filedata, unsigned long p_type) | |
4046 | { | |
4047 | static char buff[32]; | |
4048 | ||
4049 | switch (p_type) | |
4050 | { | |
4051 | case PT_NULL: return "NULL"; | |
4052 | case PT_LOAD: return "LOAD"; | |
4053 | case PT_DYNAMIC: return "DYNAMIC"; | |
4054 | case PT_INTERP: return "INTERP"; | |
4055 | case PT_NOTE: return "NOTE"; | |
4056 | case PT_SHLIB: return "SHLIB"; | |
4057 | case PT_PHDR: return "PHDR"; | |
4058 | case PT_TLS: return "TLS"; | |
4059 | case PT_GNU_EH_FRAME: return "GNU_EH_FRAME"; | |
4060 | case PT_GNU_STACK: return "GNU_STACK"; | |
4061 | case PT_GNU_RELRO: return "GNU_RELRO"; | |
4062 | case PT_GNU_PROPERTY: return "GNU_PROPERTY"; | |
4063 | ||
4064 | case PT_OPENBSD_RANDOMIZE: return "OPENBSD_RANDOMIZE"; | |
4065 | case PT_OPENBSD_WXNEEDED: return "OPENBSD_WXNEEDED"; | |
4066 | case PT_OPENBSD_BOOTDATA: return "OPENBSD_BOOTDATA"; | |
4067 | ||
4068 | default: | |
4069 | if ((p_type >= PT_LOPROC) && (p_type <= PT_HIPROC)) | |
4070 | { | |
4071 | const char * result; | |
4072 | ||
4073 | switch (filedata->file_header.e_machine) | |
4074 | { | |
4075 | case EM_AARCH64: | |
4076 | result = get_aarch64_segment_type (p_type); | |
4077 | break; | |
4078 | case EM_ARM: | |
4079 | result = get_arm_segment_type (p_type); | |
4080 | break; | |
4081 | case EM_MIPS: | |
4082 | case EM_MIPS_RS3_LE: | |
4083 | result = get_mips_segment_type (p_type); | |
4084 | break; | |
4085 | case EM_PARISC: | |
4086 | result = get_parisc_segment_type (p_type); | |
4087 | break; | |
4088 | case EM_IA_64: | |
4089 | result = get_ia64_segment_type (p_type); | |
4090 | break; | |
4091 | case EM_TI_C6000: | |
4092 | result = get_tic6x_segment_type (p_type); | |
4093 | break; | |
4094 | case EM_S390: | |
4095 | case EM_S390_OLD: | |
4096 | result = get_s390_segment_type (p_type); | |
4097 | break; | |
4098 | default: | |
4099 | result = NULL; | |
4100 | break; | |
4101 | } | |
4102 | ||
4103 | if (result != NULL) | |
4104 | return result; | |
4105 | ||
4106 | sprintf (buff, "LOPROC+%#lx", p_type - PT_LOPROC); | |
4107 | } | |
4108 | else if ((p_type >= PT_LOOS) && (p_type <= PT_HIOS)) | |
4109 | { | |
4110 | const char * result = NULL; | |
4111 | ||
4112 | switch (filedata->file_header.e_ident[EI_OSABI]) | |
4113 | { | |
4114 | case ELFOSABI_GNU: | |
4115 | case ELFOSABI_FREEBSD: | |
4116 | if (p_type >= PT_GNU_MBIND_LO && p_type <= PT_GNU_MBIND_HI) | |
4117 | { | |
4118 | sprintf (buff, "GNU_MBIND+%#lx", p_type - PT_GNU_MBIND_LO); | |
4119 | result = buff; | |
4120 | } | |
4121 | break; | |
4122 | case ELFOSABI_HPUX: | |
4123 | result = get_hpux_segment_type (p_type, | |
4124 | filedata->file_header.e_machine); | |
4125 | break; | |
4126 | case ELFOSABI_SOLARIS: | |
4127 | result = get_solaris_segment_type (p_type); | |
4128 | break; | |
4129 | default: | |
4130 | break; | |
4131 | } | |
4132 | if (result != NULL) | |
4133 | return result; | |
4134 | ||
4135 | sprintf (buff, "LOOS+%#lx", p_type - PT_LOOS); | |
4136 | } | |
4137 | else | |
4138 | snprintf (buff, sizeof (buff), _("<unknown>: %lx"), p_type); | |
4139 | ||
4140 | return buff; | |
4141 | } | |
4142 | } | |
4143 | ||
4144 | static const char * | |
4145 | get_arc_section_type_name (unsigned int sh_type) | |
4146 | { | |
4147 | switch (sh_type) | |
4148 | { | |
4149 | case SHT_ARC_ATTRIBUTES: return "ARC_ATTRIBUTES"; | |
4150 | default: | |
4151 | break; | |
4152 | } | |
4153 | return NULL; | |
4154 | } | |
4155 | ||
4156 | static const char * | |
4157 | get_mips_section_type_name (unsigned int sh_type) | |
4158 | { | |
4159 | switch (sh_type) | |
4160 | { | |
4161 | case SHT_MIPS_LIBLIST: return "MIPS_LIBLIST"; | |
4162 | case SHT_MIPS_MSYM: return "MIPS_MSYM"; | |
4163 | case SHT_MIPS_CONFLICT: return "MIPS_CONFLICT"; | |
4164 | case SHT_MIPS_GPTAB: return "MIPS_GPTAB"; | |
4165 | case SHT_MIPS_UCODE: return "MIPS_UCODE"; | |
4166 | case SHT_MIPS_DEBUG: return "MIPS_DEBUG"; | |
4167 | case SHT_MIPS_REGINFO: return "MIPS_REGINFO"; | |
4168 | case SHT_MIPS_PACKAGE: return "MIPS_PACKAGE"; | |
4169 | case SHT_MIPS_PACKSYM: return "MIPS_PACKSYM"; | |
4170 | case SHT_MIPS_RELD: return "MIPS_RELD"; | |
4171 | case SHT_MIPS_IFACE: return "MIPS_IFACE"; | |
4172 | case SHT_MIPS_CONTENT: return "MIPS_CONTENT"; | |
4173 | case SHT_MIPS_OPTIONS: return "MIPS_OPTIONS"; | |
4174 | case SHT_MIPS_SHDR: return "MIPS_SHDR"; | |
4175 | case SHT_MIPS_FDESC: return "MIPS_FDESC"; | |
4176 | case SHT_MIPS_EXTSYM: return "MIPS_EXTSYM"; | |
4177 | case SHT_MIPS_DENSE: return "MIPS_DENSE"; | |
4178 | case SHT_MIPS_PDESC: return "MIPS_PDESC"; | |
4179 | case SHT_MIPS_LOCSYM: return "MIPS_LOCSYM"; | |
4180 | case SHT_MIPS_AUXSYM: return "MIPS_AUXSYM"; | |
4181 | case SHT_MIPS_OPTSYM: return "MIPS_OPTSYM"; | |
4182 | case SHT_MIPS_LOCSTR: return "MIPS_LOCSTR"; | |
4183 | case SHT_MIPS_LINE: return "MIPS_LINE"; | |
4184 | case SHT_MIPS_RFDESC: return "MIPS_RFDESC"; | |
4185 | case SHT_MIPS_DELTASYM: return "MIPS_DELTASYM"; | |
4186 | case SHT_MIPS_DELTAINST: return "MIPS_DELTAINST"; | |
4187 | case SHT_MIPS_DELTACLASS: return "MIPS_DELTACLASS"; | |
4188 | case SHT_MIPS_DWARF: return "MIPS_DWARF"; | |
4189 | case SHT_MIPS_DELTADECL: return "MIPS_DELTADECL"; | |
4190 | case SHT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB"; | |
4191 | case SHT_MIPS_EVENTS: return "MIPS_EVENTS"; | |
4192 | case SHT_MIPS_TRANSLATE: return "MIPS_TRANSLATE"; | |
4193 | case SHT_MIPS_PIXIE: return "MIPS_PIXIE"; | |
4194 | case SHT_MIPS_XLATE: return "MIPS_XLATE"; | |
4195 | case SHT_MIPS_XLATE_DEBUG: return "MIPS_XLATE_DEBUG"; | |
4196 | case SHT_MIPS_WHIRL: return "MIPS_WHIRL"; | |
4197 | case SHT_MIPS_EH_REGION: return "MIPS_EH_REGION"; | |
4198 | case SHT_MIPS_XLATE_OLD: return "MIPS_XLATE_OLD"; | |
4199 | case SHT_MIPS_PDR_EXCEPTION: return "MIPS_PDR_EXCEPTION"; | |
4200 | case SHT_MIPS_ABIFLAGS: return "MIPS_ABIFLAGS"; | |
4201 | case SHT_MIPS_XHASH: return "MIPS_XHASH"; | |
4202 | default: | |
4203 | break; | |
4204 | } | |
4205 | return NULL; | |
4206 | } | |
4207 | ||
4208 | static const char * | |
4209 | get_parisc_section_type_name (unsigned int sh_type) | |
4210 | { | |
4211 | switch (sh_type) | |
4212 | { | |
4213 | case SHT_PARISC_EXT: return "PARISC_EXT"; | |
4214 | case SHT_PARISC_UNWIND: return "PARISC_UNWIND"; | |
4215 | case SHT_PARISC_DOC: return "PARISC_DOC"; | |
4216 | case SHT_PARISC_ANNOT: return "PARISC_ANNOT"; | |
4217 | case SHT_PARISC_SYMEXTN: return "PARISC_SYMEXTN"; | |
4218 | case SHT_PARISC_STUBS: return "PARISC_STUBS"; | |
4219 | case SHT_PARISC_DLKM: return "PARISC_DLKM"; | |
4220 | default: return NULL; | |
4221 | } | |
4222 | } | |
4223 | ||
4224 | static const char * | |
4225 | get_ia64_section_type_name (Filedata * filedata, unsigned int sh_type) | |
4226 | { | |
4227 | /* If the top 8 bits are 0x78 the next 8 are the os/abi ID. */ | |
4228 | if ((sh_type & 0xFF000000) == SHT_IA_64_LOPSREG) | |
4229 | return get_osabi_name (filedata, (sh_type & 0x00FF0000) >> 16); | |
4230 | ||
4231 | switch (sh_type) | |
4232 | { | |
4233 | case SHT_IA_64_EXT: return "IA_64_EXT"; | |
4234 | case SHT_IA_64_UNWIND: return "IA_64_UNWIND"; | |
4235 | case SHT_IA_64_PRIORITY_INIT: return "IA_64_PRIORITY_INIT"; | |
4236 | case SHT_IA_64_VMS_TRACE: return "VMS_TRACE"; | |
4237 | case SHT_IA_64_VMS_TIE_SIGNATURES: return "VMS_TIE_SIGNATURES"; | |
4238 | case SHT_IA_64_VMS_DEBUG: return "VMS_DEBUG"; | |
4239 | case SHT_IA_64_VMS_DEBUG_STR: return "VMS_DEBUG_STR"; | |
4240 | case SHT_IA_64_VMS_LINKAGES: return "VMS_LINKAGES"; | |
4241 | case SHT_IA_64_VMS_SYMBOL_VECTOR: return "VMS_SYMBOL_VECTOR"; | |
4242 | case SHT_IA_64_VMS_FIXUP: return "VMS_FIXUP"; | |
4243 | default: | |
4244 | break; | |
4245 | } | |
4246 | return NULL; | |
4247 | } | |
4248 | ||
4249 | static const char * | |
4250 | get_x86_64_section_type_name (unsigned int sh_type) | |
4251 | { | |
4252 | switch (sh_type) | |
4253 | { | |
4254 | case SHT_X86_64_UNWIND: return "X86_64_UNWIND"; | |
4255 | default: return NULL; | |
4256 | } | |
4257 | } | |
4258 | ||
4259 | static const char * | |
4260 | get_aarch64_section_type_name (unsigned int sh_type) | |
4261 | { | |
4262 | switch (sh_type) | |
4263 | { | |
4264 | case SHT_AARCH64_ATTRIBUTES: return "AARCH64_ATTRIBUTES"; | |
4265 | default: return NULL; | |
4266 | } | |
4267 | } | |
4268 | ||
4269 | static const char * | |
4270 | get_arm_section_type_name (unsigned int sh_type) | |
4271 | { | |
4272 | switch (sh_type) | |
4273 | { | |
4274 | case SHT_ARM_EXIDX: return "ARM_EXIDX"; | |
4275 | case SHT_ARM_PREEMPTMAP: return "ARM_PREEMPTMAP"; | |
4276 | case SHT_ARM_ATTRIBUTES: return "ARM_ATTRIBUTES"; | |
4277 | case SHT_ARM_DEBUGOVERLAY: return "ARM_DEBUGOVERLAY"; | |
4278 | case SHT_ARM_OVERLAYSECTION: return "ARM_OVERLAYSECTION"; | |
4279 | default: return NULL; | |
4280 | } | |
4281 | } | |
4282 | ||
4283 | static const char * | |
4284 | get_tic6x_section_type_name (unsigned int sh_type) | |
4285 | { | |
4286 | switch (sh_type) | |
4287 | { | |
4288 | case SHT_C6000_UNWIND: return "C6000_UNWIND"; | |
4289 | case SHT_C6000_PREEMPTMAP: return "C6000_PREEMPTMAP"; | |
4290 | case SHT_C6000_ATTRIBUTES: return "C6000_ATTRIBUTES"; | |
4291 | case SHT_TI_ICODE: return "TI_ICODE"; | |
4292 | case SHT_TI_XREF: return "TI_XREF"; | |
4293 | case SHT_TI_HANDLER: return "TI_HANDLER"; | |
4294 | case SHT_TI_INITINFO: return "TI_INITINFO"; | |
4295 | case SHT_TI_PHATTRS: return "TI_PHATTRS"; | |
4296 | default: return NULL; | |
4297 | } | |
4298 | } | |
4299 | ||
4300 | static const char * | |
4301 | get_msp430_section_type_name (unsigned int sh_type) | |
4302 | { | |
4303 | switch (sh_type) | |
4304 | { | |
4305 | case SHT_MSP430_SEC_FLAGS: return "MSP430_SEC_FLAGS"; | |
4306 | case SHT_MSP430_SYM_ALIASES: return "MSP430_SYM_ALIASES"; | |
4307 | case SHT_MSP430_ATTRIBUTES: return "MSP430_ATTRIBUTES"; | |
4308 | default: return NULL; | |
4309 | } | |
4310 | } | |
4311 | ||
4312 | static const char * | |
4313 | get_nfp_section_type_name (unsigned int sh_type) | |
4314 | { | |
4315 | switch (sh_type) | |
4316 | { | |
4317 | case SHT_NFP_MECONFIG: return "NFP_MECONFIG"; | |
4318 | case SHT_NFP_INITREG: return "NFP_INITREG"; | |
4319 | case SHT_NFP_UDEBUG: return "NFP_UDEBUG"; | |
4320 | default: return NULL; | |
4321 | } | |
4322 | } | |
4323 | ||
4324 | static const char * | |
4325 | get_v850_section_type_name (unsigned int sh_type) | |
4326 | { | |
4327 | switch (sh_type) | |
4328 | { | |
4329 | case SHT_V850_SCOMMON: return "V850 Small Common"; | |
4330 | case SHT_V850_TCOMMON: return "V850 Tiny Common"; | |
4331 | case SHT_V850_ZCOMMON: return "V850 Zero Common"; | |
4332 | case SHT_RENESAS_IOP: return "RENESAS IOP"; | |
4333 | case SHT_RENESAS_INFO: return "RENESAS INFO"; | |
4334 | default: return NULL; | |
4335 | } | |
4336 | } | |
4337 | ||
4338 | static const char * | |
4339 | get_riscv_section_type_name (unsigned int sh_type) | |
4340 | { | |
4341 | switch (sh_type) | |
4342 | { | |
4343 | case SHT_RISCV_ATTRIBUTES: return "RISCV_ATTRIBUTES"; | |
4344 | default: return NULL; | |
4345 | } | |
4346 | } | |
4347 | ||
4348 | static const char * | |
4349 | get_csky_section_type_name (unsigned int sh_type) | |
4350 | { | |
4351 | switch (sh_type) | |
4352 | { | |
4353 | case SHT_CSKY_ATTRIBUTES: return "CSKY_ATTRIBUTES"; | |
4354 | default: return NULL; | |
4355 | } | |
4356 | } | |
4357 | ||
4358 | static const char * | |
4359 | get_section_type_name (Filedata * filedata, unsigned int sh_type) | |
4360 | { | |
4361 | static char buff[32]; | |
4362 | const char * result; | |
4363 | ||
4364 | switch (sh_type) | |
4365 | { | |
4366 | case SHT_NULL: return "NULL"; | |
4367 | case SHT_PROGBITS: return "PROGBITS"; | |
4368 | case SHT_SYMTAB: return "SYMTAB"; | |
4369 | case SHT_STRTAB: return "STRTAB"; | |
4370 | case SHT_RELA: return "RELA"; | |
4371 | case SHT_HASH: return "HASH"; | |
4372 | case SHT_DYNAMIC: return "DYNAMIC"; | |
4373 | case SHT_NOTE: return "NOTE"; | |
4374 | case SHT_NOBITS: return "NOBITS"; | |
4375 | case SHT_REL: return "REL"; | |
4376 | case SHT_SHLIB: return "SHLIB"; | |
4377 | case SHT_DYNSYM: return "DYNSYM"; | |
4378 | case SHT_INIT_ARRAY: return "INIT_ARRAY"; | |
4379 | case SHT_FINI_ARRAY: return "FINI_ARRAY"; | |
4380 | case SHT_PREINIT_ARRAY: return "PREINIT_ARRAY"; | |
4381 | case SHT_GNU_HASH: return "GNU_HASH"; | |
4382 | case SHT_GROUP: return "GROUP"; | |
4383 | case SHT_SYMTAB_SHNDX: return "SYMTAB SECTION INDICES"; | |
4384 | case SHT_GNU_verdef: return "VERDEF"; | |
4385 | case SHT_GNU_verneed: return "VERNEED"; | |
4386 | case SHT_GNU_versym: return "VERSYM"; | |
4387 | case 0x6ffffff0: return "VERSYM"; | |
4388 | case 0x6ffffffc: return "VERDEF"; | |
4389 | case 0x7ffffffd: return "AUXILIARY"; | |
4390 | case 0x7fffffff: return "FILTER"; | |
4391 | case SHT_GNU_LIBLIST: return "GNU_LIBLIST"; | |
4392 | ||
4393 | default: | |
4394 | if ((sh_type >= SHT_LOPROC) && (sh_type <= SHT_HIPROC)) | |
4395 | { | |
4396 | switch (filedata->file_header.e_machine) | |
4397 | { | |
4398 | case EM_ARC: | |
4399 | case EM_ARC_COMPACT: | |
4400 | case EM_ARC_COMPACT2: | |
4401 | result = get_arc_section_type_name (sh_type); | |
4402 | break; | |
4403 | case EM_MIPS: | |
4404 | case EM_MIPS_RS3_LE: | |
4405 | result = get_mips_section_type_name (sh_type); | |
4406 | break; | |
4407 | case EM_PARISC: | |
4408 | result = get_parisc_section_type_name (sh_type); | |
4409 | break; | |
4410 | case EM_IA_64: | |
4411 | result = get_ia64_section_type_name (filedata, sh_type); | |
4412 | break; | |
4413 | case EM_X86_64: | |
4414 | case EM_L1OM: | |
4415 | case EM_K1OM: | |
4416 | result = get_x86_64_section_type_name (sh_type); | |
4417 | break; | |
4418 | case EM_AARCH64: | |
4419 | result = get_aarch64_section_type_name (sh_type); | |
4420 | break; | |
4421 | case EM_ARM: | |
4422 | result = get_arm_section_type_name (sh_type); | |
4423 | break; | |
4424 | case EM_TI_C6000: | |
4425 | result = get_tic6x_section_type_name (sh_type); | |
4426 | break; | |
4427 | case EM_MSP430: | |
4428 | result = get_msp430_section_type_name (sh_type); | |
4429 | break; | |
4430 | case EM_NFP: | |
4431 | result = get_nfp_section_type_name (sh_type); | |
4432 | break; | |
4433 | case EM_V800: | |
4434 | case EM_V850: | |
4435 | case EM_CYGNUS_V850: | |
4436 | result = get_v850_section_type_name (sh_type); | |
4437 | break; | |
4438 | case EM_RISCV: | |
4439 | result = get_riscv_section_type_name (sh_type); | |
4440 | break; | |
4441 | case EM_CSKY: | |
4442 | result = get_csky_section_type_name (sh_type); | |
4443 | break; | |
4444 | default: | |
4445 | result = NULL; | |
4446 | break; | |
4447 | } | |
4448 | ||
4449 | if (result != NULL) | |
4450 | return result; | |
4451 | ||
4452 | sprintf (buff, "LOPROC+%#x", sh_type - SHT_LOPROC); | |
4453 | } | |
4454 | else if ((sh_type >= SHT_LOOS) && (sh_type <= SHT_HIOS)) | |
4455 | { | |
4456 | switch (filedata->file_header.e_machine) | |
4457 | { | |
4458 | case EM_IA_64: | |
4459 | result = get_ia64_section_type_name (filedata, sh_type); | |
4460 | break; | |
4461 | default: | |
4462 | if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS) | |
4463 | result = get_solaris_section_type (sh_type); | |
4464 | else | |
4465 | { | |
4466 | switch (sh_type) | |
4467 | { | |
4468 | case SHT_GNU_INCREMENTAL_INPUTS: result = "GNU_INCREMENTAL_INPUTS"; break; | |
4469 | case SHT_GNU_ATTRIBUTES: result = "GNU_ATTRIBUTES"; break; | |
4470 | case SHT_GNU_HASH: result = "GNU_HASH"; break; | |
4471 | case SHT_GNU_LIBLIST: result = "GNU_LIBLIST"; break; | |
4472 | default: | |
4473 | result = NULL; | |
4474 | break; | |
4475 | } | |
4476 | } | |
4477 | break; | |
4478 | } | |
4479 | ||
4480 | if (result != NULL) | |
4481 | return result; | |
4482 | ||
4483 | sprintf (buff, "LOOS+%#x", sh_type - SHT_LOOS); | |
4484 | } | |
4485 | else if ((sh_type >= SHT_LOUSER) && (sh_type <= SHT_HIUSER)) | |
4486 | { | |
4487 | switch (filedata->file_header.e_machine) | |
4488 | { | |
4489 | case EM_V800: | |
4490 | case EM_V850: | |
4491 | case EM_CYGNUS_V850: | |
4492 | result = get_v850_section_type_name (sh_type); | |
4493 | break; | |
4494 | default: | |
4495 | result = NULL; | |
4496 | break; | |
4497 | } | |
4498 | ||
4499 | if (result != NULL) | |
4500 | return result; | |
4501 | ||
4502 | sprintf (buff, "LOUSER+%#x", sh_type - SHT_LOUSER); | |
4503 | } | |
4504 | else | |
4505 | /* This message is probably going to be displayed in a 15 | |
4506 | character wide field, so put the hex value first. */ | |
4507 | snprintf (buff, sizeof (buff), _("%08x: <unknown>"), sh_type); | |
4508 | ||
4509 | return buff; | |
4510 | } | |
4511 | } | |
4512 | ||
4513 | enum long_option_values | |
4514 | { | |
4515 | OPTION_DEBUG_DUMP = 512, | |
4516 | OPTION_DYN_SYMS, | |
4517 | OPTION_LTO_SYMS, | |
4518 | OPTION_DWARF_DEPTH, | |
4519 | OPTION_DWARF_START, | |
4520 | OPTION_DWARF_CHECK, | |
4521 | OPTION_CTF_DUMP, | |
4522 | OPTION_CTF_PARENT, | |
4523 | OPTION_CTF_SYMBOLS, | |
4524 | OPTION_CTF_STRINGS, | |
4525 | OPTION_WITH_SYMBOL_VERSIONS, | |
4526 | OPTION_RECURSE_LIMIT, | |
4527 | OPTION_NO_RECURSE_LIMIT, | |
4528 | OPTION_NO_DEMANGLING | |
4529 | }; | |
4530 | ||
4531 | static struct option options[] = | |
4532 | { | |
4533 | /* Note - This table is alpha-sorted on the 'val' | |
4534 | field in order to make adding new options easier. */ | |
4535 | {"arch-specific", no_argument, 0, 'A'}, | |
4536 | {"all", no_argument, 0, 'a'}, | |
4537 | {"demangle", optional_argument, 0, 'C'}, | |
4538 | {"archive-index", no_argument, 0, 'c'}, | |
4539 | {"use-dynamic", no_argument, 0, 'D'}, | |
4540 | {"dynamic", no_argument, 0, 'd'}, | |
4541 | {"headers", no_argument, 0, 'e'}, | |
4542 | {"section-groups", no_argument, 0, 'g'}, | |
4543 | {"help", no_argument, 0, 'H'}, | |
4544 | {"file-header", no_argument, 0, 'h'}, | |
4545 | {"histogram", no_argument, 0, 'I'}, | |
4546 | {"lint", no_argument, 0, 'L'}, | |
4547 | {"enable-checks", no_argument, 0, 'L'}, | |
4548 | {"program-headers", no_argument, 0, 'l'}, | |
4549 | {"segments", no_argument, 0, 'l'}, | |
4550 | {"full-section-name",no_argument, 0, 'N'}, | |
4551 | {"notes", no_argument, 0, 'n'}, | |
4552 | {"process-links", no_argument, 0, 'P'}, | |
4553 | {"string-dump", required_argument, 0, 'p'}, | |
4554 | {"relocated-dump", required_argument, 0, 'R'}, | |
4555 | {"relocs", no_argument, 0, 'r'}, | |
4556 | {"section-headers", no_argument, 0, 'S'}, | |
4557 | {"sections", no_argument, 0, 'S'}, | |
4558 | {"symbols", no_argument, 0, 's'}, | |
4559 | {"syms", no_argument, 0, 's'}, | |
4560 | {"silent-truncation",no_argument, 0, 'T'}, | |
4561 | {"section-details", no_argument, 0, 't'}, | |
4562 | {"unwind", no_argument, 0, 'u'}, | |
4563 | {"version-info", no_argument, 0, 'V'}, | |
4564 | {"version", no_argument, 0, 'v'}, | |
4565 | {"wide", no_argument, 0, 'W'}, | |
4566 | {"hex-dump", required_argument, 0, 'x'}, | |
4567 | {"decompress", no_argument, 0, 'z'}, | |
4568 | ||
4569 | {"no-demangle", no_argument, 0, OPTION_NO_DEMANGLING}, | |
4570 | {"recurse-limit", no_argument, NULL, OPTION_RECURSE_LIMIT}, | |
4571 | {"no-recurse-limit", no_argument, NULL, OPTION_NO_RECURSE_LIMIT}, | |
4572 | {"no-recursion-limit", no_argument, NULL, OPTION_NO_RECURSE_LIMIT}, | |
4573 | {"dyn-syms", no_argument, 0, OPTION_DYN_SYMS}, | |
4574 | {"lto-syms", no_argument, 0, OPTION_LTO_SYMS}, | |
4575 | {"debug-dump", optional_argument, 0, OPTION_DEBUG_DUMP}, | |
4576 | {"dwarf-depth", required_argument, 0, OPTION_DWARF_DEPTH}, | |
4577 | {"dwarf-start", required_argument, 0, OPTION_DWARF_START}, | |
4578 | {"dwarf-check", no_argument, 0, OPTION_DWARF_CHECK}, | |
4579 | #ifdef ENABLE_LIBCTF | |
4580 | {"ctf", required_argument, 0, OPTION_CTF_DUMP}, | |
4581 | {"ctf-symbols", required_argument, 0, OPTION_CTF_SYMBOLS}, | |
4582 | {"ctf-strings", required_argument, 0, OPTION_CTF_STRINGS}, | |
4583 | {"ctf-parent", required_argument, 0, OPTION_CTF_PARENT}, | |
4584 | #endif | |
4585 | ||
4586 | {0, no_argument, 0, 0} | |
4587 | }; | |
4588 | ||
4589 | static void | |
4590 | usage (FILE * stream) | |
4591 | { | |
4592 | fprintf (stream, _("Usage: readelf <option(s)> elf-file(s)\n")); | |
4593 | fprintf (stream, _(" Display information about the contents of ELF format files\n")); | |
4594 | fprintf (stream, _(" Options are:\n\ | |
4595 | -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n\ | |
4596 | -h --file-header Display the ELF file header\n\ | |
4597 | -l --program-headers Display the program headers\n\ | |
4598 | --segments An alias for --program-headers\n\ | |
4599 | -S --section-headers Display the sections' header\n\ | |
4600 | --sections An alias for --section-headers\n\ | |
4601 | -g --section-groups Display the section groups\n\ | |
4602 | -t --section-details Display the section details\n\ | |
4603 | -e --headers Equivalent to: -h -l -S\n\ | |
4604 | -s --syms Display the symbol table\n\ | |
4605 | --symbols An alias for --syms\n\ | |
4606 | --dyn-syms Display the dynamic symbol table\n\ | |
4607 | --lto-syms Display LTO symbol tables\n\ | |
4608 | -C --demangle[=STYLE] Decode low-level symbol names into user-level names\n\ | |
4609 | The STYLE, if specified, can be `auto' (the default),\n\ | |
4610 | `gnu', `lucid', `arm', `hp', `edg', `gnu-v3', `java'\n\ | |
4611 | or `gnat'\n\ | |
4612 | --no-demangle Do not demangle low-level symbol names. (This is the default)\n\ | |
4613 | --recurse-limit Enable a demangling recursion limit. (This is the default)\n\ | |
4614 | --no-recurse-limit Disable a demangling recursion limit\n\ | |
4615 | -n --notes Display the core notes (if present)\n\ | |
4616 | -r --relocs Display the relocations (if present)\n\ | |
4617 | -u --unwind Display the unwind info (if present)\n\ | |
4618 | -d --dynamic Display the dynamic section (if present)\n\ | |
4619 | -V --version-info Display the version sections (if present)\n\ | |
4620 | -A --arch-specific Display architecture specific information (if any)\n\ | |
4621 | -c --archive-index Display the symbol/file index in an archive\n\ | |
4622 | -D --use-dynamic Use the dynamic section info when displaying symbols\n\ | |
4623 | -L --lint|--enable-checks Display warning messages for possible problems\n\ | |
4624 | -x --hex-dump=<number|name>\n\ | |
4625 | Dump the contents of section <number|name> as bytes\n\ | |
4626 | -p --string-dump=<number|name>\n\ | |
4627 | Dump the contents of section <number|name> as strings\n\ | |
4628 | -R --relocated-dump=<number|name>\n\ | |
4629 | Dump the contents of section <number|name> as relocated bytes\n\ | |
4630 | -z --decompress Decompress section before dumping it\n\ | |
4631 | -w[lLiaprmfFsoORtUuTgAc] or\n\ | |
4632 | --debug-dump[=rawline,=decodedline,=info,=abbrev,=pubnames,=aranges,=macro,=frames,\n\ | |
4633 | =frames-interp,=str,=str-offsets,=loc,=Ranges,=pubtypes,\n\ | |
4634 | =gdb_index,=trace_info,=trace_abbrev,=trace_aranges,\n\ | |
4635 | =addr,=cu_index]\n\ | |
4636 | Display the contents of DWARF debug sections\n\ | |
4637 | -wk,--debug-dump=links Display the contents of sections that link to separate debuginfo files\n\ | |
4638 | -P,--process-links Display the contents of non-debug sections in separate debuginfo files. (Implies -wK)\n")); | |
4639 | #if DEFAULT_FOR_FOLLOW_LINKS | |
4640 | fprintf (stream, _("\ | |
4641 | -wK,--debug-dump=follow-links Follow links to separate debug info files (default)\n\ | |
4642 | -wN,--debug-dump=no-follow-links Do not follow links to separate debug info files\n\ | |
4643 | ")); | |
4644 | #else | |
4645 | fprintf (stream, _("\ | |
4646 | -wK,--debug-dump=follow-links Follow links to separate debug info files\n\ | |
4647 | -wN,--debug-dump=no-follow-links Do not follow links to separate debug info files (default)\n\ | |
4648 | ")); | |
4649 | #endif | |
4650 | fprintf (stream, _("\ | |
4651 | --dwarf-depth=N Do not display DIEs at depth N or greater\n\ | |
4652 | --dwarf-start=N Display DIEs starting with N, at the same depth\n\ | |
4653 | or deeper\n")); | |
4654 | #ifdef ENABLE_LIBCTF | |
4655 | fprintf (stream, _("\ | |
4656 | --ctf=<number|name> Display CTF info from section <number|name>\n\ | |
4657 | --ctf-parent=<number|name>\n\ | |
4658 | Use section <number|name> as the CTF parent\n\n\ | |
4659 | --ctf-symbols=<number|name>\n\ | |
4660 | Use section <number|name> as the CTF external symtab\n\n\ | |
4661 | --ctf-strings=<number|name>\n\ | |
4662 | Use section <number|name> as the CTF external strtab\n\n")); | |
4663 | #endif | |
4664 | ||
4665 | #ifdef SUPPORT_DISASSEMBLY | |
4666 | fprintf (stream, _("\ | |
4667 | -i --instruction-dump=<number|name>\n\ | |
4668 | Disassemble the contents of section <number|name>\n")); | |
4669 | #endif | |
4670 | fprintf (stream, _("\ | |
4671 | -I --histogram Display histogram of bucket list lengths\n\ | |
4672 | -W --wide Allow output width to exceed 80 characters\n\ | |
4673 | -T --silent-truncation If a symbol name is truncated, do not add a suffix [...]\n\ | |
4674 | @<file> Read options from <file>\n\ | |
4675 | -H --help Display this information\n\ | |
4676 | -v --version Display the version number of readelf\n")); | |
4677 | ||
4678 | if (REPORT_BUGS_TO[0] && stream == stdout) | |
4679 | fprintf (stdout, _("Report bugs to %s\n"), REPORT_BUGS_TO); | |
4680 | ||
4681 | exit (stream == stdout ? 0 : 1); | |
4682 | } | |
4683 | ||
4684 | /* Record the fact that the user wants the contents of section number | |
4685 | SECTION to be displayed using the method(s) encoded as flags bits | |
4686 | in TYPE. Note, TYPE can be zero if we are creating the array for | |
4687 | the first time. */ | |
4688 | ||
4689 | static void | |
4690 | request_dump_bynumber (struct dump_data *dumpdata, | |
4691 | unsigned int section, dump_type type) | |
4692 | { | |
4693 | if (section >= dumpdata->num_dump_sects) | |
4694 | { | |
4695 | dump_type * new_dump_sects; | |
4696 | ||
4697 | new_dump_sects = (dump_type *) calloc (section + 1, | |
4698 | sizeof (* new_dump_sects)); | |
4699 | ||
4700 | if (new_dump_sects == NULL) | |
4701 | error (_("Out of memory allocating dump request table.\n")); | |
4702 | else | |
4703 | { | |
4704 | if (dumpdata->dump_sects) | |
4705 | { | |
4706 | /* Copy current flag settings. */ | |
4707 | memcpy (new_dump_sects, dumpdata->dump_sects, | |
4708 | dumpdata->num_dump_sects * sizeof (* new_dump_sects)); | |
4709 | ||
4710 | free (dumpdata->dump_sects); | |
4711 | } | |
4712 | ||
4713 | dumpdata->dump_sects = new_dump_sects; | |
4714 | dumpdata->num_dump_sects = section + 1; | |
4715 | } | |
4716 | } | |
4717 | ||
4718 | if (dumpdata->dump_sects) | |
4719 | dumpdata->dump_sects[section] |= type; | |
4720 | } | |
4721 | ||
4722 | /* Request a dump by section name. */ | |
4723 | ||
4724 | static void | |
4725 | request_dump_byname (const char * section, dump_type type) | |
4726 | { | |
4727 | struct dump_list_entry * new_request; | |
4728 | ||
4729 | new_request = (struct dump_list_entry *) | |
4730 | malloc (sizeof (struct dump_list_entry)); | |
4731 | if (!new_request) | |
4732 | error (_("Out of memory allocating dump request table.\n")); | |
4733 | ||
4734 | new_request->name = strdup (section); | |
4735 | if (!new_request->name) | |
4736 | error (_("Out of memory allocating dump request table.\n")); | |
4737 | ||
4738 | new_request->type = type; | |
4739 | ||
4740 | new_request->next = dump_sects_byname; | |
4741 | dump_sects_byname = new_request; | |
4742 | } | |
4743 | ||
4744 | static inline void | |
4745 | request_dump (struct dump_data *dumpdata, dump_type type) | |
4746 | { | |
4747 | int section; | |
4748 | char * cp; | |
4749 | ||
4750 | do_dump = TRUE; | |
4751 | section = strtoul (optarg, & cp, 0); | |
4752 | ||
4753 | if (! *cp && section >= 0) | |
4754 | request_dump_bynumber (dumpdata, section, type); | |
4755 | else | |
4756 | request_dump_byname (optarg, type); | |
4757 | } | |
4758 | ||
4759 | static void | |
4760 | parse_args (struct dump_data *dumpdata, int argc, char ** argv) | |
4761 | { | |
4762 | int c; | |
4763 | ||
4764 | if (argc < 2) | |
4765 | usage (stderr); | |
4766 | ||
4767 | while ((c = getopt_long | |
4768 | (argc, argv, "ACDHILNPR:STVWacdeghi:lnp:rstuvw::x:z", options, NULL)) != EOF) | |
4769 | { | |
4770 | switch (c) | |
4771 | { | |
4772 | case 0: | |
4773 | /* Long options. */ | |
4774 | break; | |
4775 | case 'H': | |
4776 | usage (stdout); | |
4777 | break; | |
4778 | ||
4779 | case 'a': | |
4780 | do_syms = TRUE; | |
4781 | do_reloc = TRUE; | |
4782 | do_unwind = TRUE; | |
4783 | do_dynamic = TRUE; | |
4784 | do_header = TRUE; | |
4785 | do_sections = TRUE; | |
4786 | do_section_groups = TRUE; | |
4787 | do_segments = TRUE; | |
4788 | do_version = TRUE; | |
4789 | do_histogram = TRUE; | |
4790 | do_arch = TRUE; | |
4791 | do_notes = TRUE; | |
4792 | break; | |
4793 | ||
4794 | case 'g': | |
4795 | do_section_groups = TRUE; | |
4796 | break; | |
4797 | case 't': | |
4798 | case 'N': | |
4799 | do_sections = TRUE; | |
4800 | do_section_details = TRUE; | |
4801 | break; | |
4802 | case 'e': | |
4803 | do_header = TRUE; | |
4804 | do_sections = TRUE; | |
4805 | do_segments = TRUE; | |
4806 | break; | |
4807 | case 'A': | |
4808 | do_arch = TRUE; | |
4809 | break; | |
4810 | case 'D': | |
4811 | do_using_dynamic = TRUE; | |
4812 | break; | |
4813 | case 'r': | |
4814 | do_reloc = TRUE; | |
4815 | break; | |
4816 | case 'u': | |
4817 | do_unwind = TRUE; | |
4818 | break; | |
4819 | case 'h': | |
4820 | do_header = TRUE; | |
4821 | break; | |
4822 | case 'l': | |
4823 | do_segments = TRUE; | |
4824 | break; | |
4825 | case 's': | |
4826 | do_syms = TRUE; | |
4827 | break; | |
4828 | case 'S': | |
4829 | do_sections = TRUE; | |
4830 | break; | |
4831 | case 'd': | |
4832 | do_dynamic = TRUE; | |
4833 | break; | |
4834 | case 'I': | |
4835 | do_histogram = TRUE; | |
4836 | break; | |
4837 | case 'n': | |
4838 | do_notes = TRUE; | |
4839 | break; | |
4840 | case 'c': | |
4841 | do_archive_index = TRUE; | |
4842 | break; | |
4843 | case 'L': | |
4844 | do_checks = TRUE; | |
4845 | break; | |
4846 | case 'P': | |
4847 | process_links = TRUE; | |
4848 | do_follow_links = TRUE; | |
4849 | break; | |
4850 | case 'x': | |
4851 | request_dump (dumpdata, HEX_DUMP); | |
4852 | break; | |
4853 | case 'p': | |
4854 | request_dump (dumpdata, STRING_DUMP); | |
4855 | break; | |
4856 | case 'R': | |
4857 | request_dump (dumpdata, RELOC_DUMP); | |
4858 | break; | |
4859 | case 'z': | |
4860 | decompress_dumps = TRUE; | |
4861 | break; | |
4862 | case 'w': | |
4863 | do_dump = TRUE; | |
4864 | if (optarg == NULL) | |
4865 | { | |
4866 | do_debugging = TRUE; | |
4867 | dwarf_select_sections_all (); | |
4868 | } | |
4869 | else | |
4870 | { | |
4871 | do_debugging = FALSE; | |
4872 | dwarf_select_sections_by_letters (optarg); | |
4873 | } | |
4874 | break; | |
4875 | case OPTION_DEBUG_DUMP: | |
4876 | do_dump = TRUE; | |
4877 | if (optarg == NULL) | |
4878 | do_debugging = TRUE; | |
4879 | else | |
4880 | { | |
4881 | do_debugging = FALSE; | |
4882 | dwarf_select_sections_by_names (optarg); | |
4883 | } | |
4884 | break; | |
4885 | case OPTION_DWARF_DEPTH: | |
4886 | { | |
4887 | char *cp; | |
4888 | ||
4889 | dwarf_cutoff_level = strtoul (optarg, & cp, 0); | |
4890 | } | |
4891 | break; | |
4892 | case OPTION_DWARF_START: | |
4893 | { | |
4894 | char *cp; | |
4895 | ||
4896 | dwarf_start_die = strtoul (optarg, & cp, 0); | |
4897 | } | |
4898 | break; | |
4899 | case OPTION_DWARF_CHECK: | |
4900 | dwarf_check = TRUE; | |
4901 | break; | |
4902 | case OPTION_CTF_DUMP: | |
4903 | do_ctf = TRUE; | |
4904 | request_dump (dumpdata, CTF_DUMP); | |
4905 | break; | |
4906 | case OPTION_CTF_SYMBOLS: | |
4907 | free (dump_ctf_symtab_name); | |
4908 | dump_ctf_symtab_name = strdup (optarg); | |
4909 | break; | |
4910 | case OPTION_CTF_STRINGS: | |
4911 | free (dump_ctf_strtab_name); | |
4912 | dump_ctf_strtab_name = strdup (optarg); | |
4913 | break; | |
4914 | case OPTION_CTF_PARENT: | |
4915 | free (dump_ctf_parent_name); | |
4916 | dump_ctf_parent_name = strdup (optarg); | |
4917 | break; | |
4918 | case OPTION_DYN_SYMS: | |
4919 | do_dyn_syms = TRUE; | |
4920 | break; | |
4921 | case OPTION_LTO_SYMS: | |
4922 | do_lto_syms = TRUE; | |
4923 | break; | |
4924 | #ifdef SUPPORT_DISASSEMBLY | |
4925 | case 'i': | |
4926 | request_dump (dumpdata, DISASS_DUMP); | |
4927 | break; | |
4928 | #endif | |
4929 | case 'v': | |
4930 | print_version (program_name); | |
4931 | break; | |
4932 | case 'V': | |
4933 | do_version = TRUE; | |
4934 | break; | |
4935 | case 'W': | |
4936 | do_wide = TRUE; | |
4937 | break; | |
4938 | case 'T': | |
4939 | do_not_show_symbol_truncation = TRUE; | |
4940 | break; | |
4941 | case 'C': | |
4942 | do_demangle = TRUE; | |
4943 | if (optarg != NULL) | |
4944 | { | |
4945 | enum demangling_styles style; | |
4946 | ||
4947 | style = cplus_demangle_name_to_style (optarg); | |
4948 | if (style == unknown_demangling) | |
4949 | error (_("unknown demangling style `%s'"), optarg); | |
4950 | ||
4951 | cplus_demangle_set_style (style); | |
4952 | } | |
4953 | break; | |
4954 | case OPTION_NO_DEMANGLING: | |
4955 | do_demangle = FALSE; | |
4956 | break; | |
4957 | case OPTION_RECURSE_LIMIT: | |
4958 | demangle_flags &= ~ DMGL_NO_RECURSE_LIMIT; | |
4959 | break; | |
4960 | case OPTION_NO_RECURSE_LIMIT: | |
4961 | demangle_flags |= DMGL_NO_RECURSE_LIMIT; | |
4962 | break; | |
4963 | case OPTION_WITH_SYMBOL_VERSIONS: | |
4964 | /* Ignored for backward compatibility. */ | |
4965 | break; | |
4966 | ||
4967 | default: | |
4968 | /* xgettext:c-format */ | |
4969 | error (_("Invalid option '-%c'\n"), c); | |
4970 | /* Fall through. */ | |
4971 | case '?': | |
4972 | usage (stderr); | |
4973 | } | |
4974 | } | |
4975 | ||
4976 | if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections | |
4977 | && !do_segments && !do_header && !do_dump && !do_version | |
4978 | && !do_histogram && !do_debugging && !do_arch && !do_notes | |
4979 | && !do_section_groups && !do_archive_index | |
4980 | && !do_dyn_syms && !do_lto_syms) | |
4981 | { | |
4982 | if (do_checks) | |
4983 | { | |
4984 | check_all = TRUE; | |
4985 | do_dynamic = do_syms = do_reloc = do_unwind = do_sections = TRUE; | |
4986 | do_segments = do_header = do_dump = do_version = TRUE; | |
4987 | do_histogram = do_debugging = do_arch = do_notes = TRUE; | |
4988 | do_section_groups = do_archive_index = do_dyn_syms = TRUE; | |
4989 | do_lto_syms = TRUE; | |
4990 | } | |
4991 | else | |
4992 | usage (stderr); | |
4993 | } | |
4994 | } | |
4995 | ||
4996 | static const char * | |
4997 | get_elf_class (unsigned int elf_class) | |
4998 | { | |
4999 | static char buff[32]; | |
5000 | ||
5001 | switch (elf_class) | |
5002 | { | |
5003 | case ELFCLASSNONE: return _("none"); | |
5004 | case ELFCLASS32: return "ELF32"; | |
5005 | case ELFCLASS64: return "ELF64"; | |
5006 | default: | |
5007 | snprintf (buff, sizeof (buff), _("<unknown: %x>"), elf_class); | |
5008 | return buff; | |
5009 | } | |
5010 | } | |
5011 | ||
5012 | static const char * | |
5013 | get_data_encoding (unsigned int encoding) | |
5014 | { | |
5015 | static char buff[32]; | |
5016 | ||
5017 | switch (encoding) | |
5018 | { | |
5019 | case ELFDATANONE: return _("none"); | |
5020 | case ELFDATA2LSB: return _("2's complement, little endian"); | |
5021 | case ELFDATA2MSB: return _("2's complement, big endian"); | |
5022 | default: | |
5023 | snprintf (buff, sizeof (buff), _("<unknown: %x>"), encoding); | |
5024 | return buff; | |
5025 | } | |
5026 | } | |
5027 | ||
5028 | /* Decode the data held in 'filedata->file_header'. */ | |
5029 | ||
5030 | static bfd_boolean | |
5031 | process_file_header (Filedata * filedata) | |
5032 | { | |
5033 | Elf_Internal_Ehdr * header = & filedata->file_header; | |
5034 | ||
5035 | if ( header->e_ident[EI_MAG0] != ELFMAG0 | |
5036 | || header->e_ident[EI_MAG1] != ELFMAG1 | |
5037 | || header->e_ident[EI_MAG2] != ELFMAG2 | |
5038 | || header->e_ident[EI_MAG3] != ELFMAG3) | |
5039 | { | |
5040 | error | |
5041 | (_("Not an ELF file - it has the wrong magic bytes at the start\n")); | |
5042 | return FALSE; | |
5043 | } | |
5044 | ||
5045 | if (! filedata->is_separate) | |
5046 | init_dwarf_regnames_by_elf_machine_code (header->e_machine); | |
5047 | ||
5048 | if (do_header) | |
5049 | { | |
5050 | unsigned i; | |
5051 | ||
5052 | if (filedata->is_separate) | |
5053 | printf (_("ELF Header in linked file '%s':\n"), filedata->file_name); | |
5054 | else | |
5055 | printf (_("ELF Header:\n")); | |
5056 | printf (_(" Magic: ")); | |
5057 | for (i = 0; i < EI_NIDENT; i++) | |
5058 | printf ("%2.2x ", header->e_ident[i]); | |
5059 | printf ("\n"); | |
5060 | printf (_(" Class: %s\n"), | |
5061 | get_elf_class (header->e_ident[EI_CLASS])); | |
5062 | printf (_(" Data: %s\n"), | |
5063 | get_data_encoding (header->e_ident[EI_DATA])); | |
5064 | printf (_(" Version: %d%s\n"), | |
5065 | header->e_ident[EI_VERSION], | |
5066 | (header->e_ident[EI_VERSION] == EV_CURRENT | |
5067 | ? _(" (current)") | |
5068 | : (header->e_ident[EI_VERSION] != EV_NONE | |
5069 | ? _(" <unknown>") | |
5070 | : ""))); | |
5071 | printf (_(" OS/ABI: %s\n"), | |
5072 | get_osabi_name (filedata, header->e_ident[EI_OSABI])); | |
5073 | printf (_(" ABI Version: %d\n"), | |
5074 | header->e_ident[EI_ABIVERSION]); | |
5075 | printf (_(" Type: %s\n"), | |
5076 | get_file_type (header->e_type)); | |
5077 | printf (_(" Machine: %s\n"), | |
5078 | get_machine_name (header->e_machine)); | |
5079 | printf (_(" Version: 0x%lx\n"), | |
5080 | header->e_version); | |
5081 | ||
5082 | printf (_(" Entry point address: ")); | |
5083 | print_vma (header->e_entry, PREFIX_HEX); | |
5084 | printf (_("\n Start of program headers: ")); | |
5085 | print_vma (header->e_phoff, DEC); | |
5086 | printf (_(" (bytes into file)\n Start of section headers: ")); | |
5087 | print_vma (header->e_shoff, DEC); | |
5088 | printf (_(" (bytes into file)\n")); | |
5089 | ||
5090 | printf (_(" Flags: 0x%lx%s\n"), | |
5091 | header->e_flags, | |
5092 | get_machine_flags (filedata, header->e_flags, header->e_machine)); | |
5093 | printf (_(" Size of this header: %u (bytes)\n"), | |
5094 | header->e_ehsize); | |
5095 | printf (_(" Size of program headers: %u (bytes)\n"), | |
5096 | header->e_phentsize); | |
5097 | printf (_(" Number of program headers: %u"), | |
5098 | header->e_phnum); | |
5099 | if (filedata->section_headers != NULL | |
5100 | && header->e_phnum == PN_XNUM | |
5101 | && filedata->section_headers[0].sh_info != 0) | |
5102 | { | |
5103 | header->e_phnum = filedata->section_headers[0].sh_info; | |
5104 | printf (" (%u)", header->e_phnum); | |
5105 | } | |
5106 | putc ('\n', stdout); | |
5107 | printf (_(" Size of section headers: %u (bytes)\n"), | |
5108 | header->e_shentsize); | |
5109 | printf (_(" Number of section headers: %u"), | |
5110 | header->e_shnum); | |
5111 | if (filedata->section_headers != NULL && header->e_shnum == SHN_UNDEF) | |
5112 | { | |
5113 | header->e_shnum = filedata->section_headers[0].sh_size; | |
5114 | printf (" (%u)", header->e_shnum); | |
5115 | } | |
5116 | putc ('\n', stdout); | |
5117 | printf (_(" Section header string table index: %u"), | |
5118 | header->e_shstrndx); | |
5119 | if (filedata->section_headers != NULL | |
5120 | && header->e_shstrndx == (SHN_XINDEX & 0xffff)) | |
5121 | { | |
5122 | header->e_shstrndx = filedata->section_headers[0].sh_link; | |
5123 | printf (" (%u)", header->e_shstrndx); | |
5124 | } | |
5125 | if (header->e_shstrndx != SHN_UNDEF | |
5126 | && header->e_shstrndx >= header->e_shnum) | |
5127 | { | |
5128 | header->e_shstrndx = SHN_UNDEF; | |
5129 | printf (_(" <corrupt: out of range>")); | |
5130 | } | |
5131 | putc ('\n', stdout); | |
5132 | } | |
5133 | ||
5134 | if (filedata->section_headers != NULL) | |
5135 | { | |
5136 | if (header->e_phnum == PN_XNUM | |
5137 | && filedata->section_headers[0].sh_info != 0) | |
5138 | header->e_phnum = filedata->section_headers[0].sh_info; | |
5139 | if (header->e_shnum == SHN_UNDEF) | |
5140 | header->e_shnum = filedata->section_headers[0].sh_size; | |
5141 | if (header->e_shstrndx == (SHN_XINDEX & 0xffff)) | |
5142 | header->e_shstrndx = filedata->section_headers[0].sh_link; | |
5143 | if (header->e_shstrndx >= header->e_shnum) | |
5144 | header->e_shstrndx = SHN_UNDEF; | |
5145 | free (filedata->section_headers); | |
5146 | filedata->section_headers = NULL; | |
5147 | } | |
5148 | ||
5149 | return TRUE; | |
5150 | } | |
5151 | ||
5152 | /* Read in the program headers from FILEDATA and store them in PHEADERS. | |
5153 | Returns TRUE upon success, FALSE otherwise. Loads 32-bit headers. */ | |
5154 | ||
5155 | static bfd_boolean | |
5156 | get_32bit_program_headers (Filedata * filedata, Elf_Internal_Phdr * pheaders) | |
5157 | { | |
5158 | Elf32_External_Phdr * phdrs; | |
5159 | Elf32_External_Phdr * external; | |
5160 | Elf_Internal_Phdr * internal; | |
5161 | unsigned int i; | |
5162 | unsigned int size = filedata->file_header.e_phentsize; | |
5163 | unsigned int num = filedata->file_header.e_phnum; | |
5164 | ||
5165 | /* PR binutils/17531: Cope with unexpected section header sizes. */ | |
5166 | if (size == 0 || num == 0) | |
5167 | return FALSE; | |
5168 | if (size < sizeof * phdrs) | |
5169 | { | |
5170 | error (_("The e_phentsize field in the ELF header is less than the size of an ELF program header\n")); | |
5171 | return FALSE; | |
5172 | } | |
5173 | if (size > sizeof * phdrs) | |
5174 | warn (_("The e_phentsize field in the ELF header is larger than the size of an ELF program header\n")); | |
5175 | ||
5176 | phdrs = (Elf32_External_Phdr *) get_data (NULL, filedata, filedata->file_header.e_phoff, | |
5177 | size, num, _("program headers")); | |
5178 | if (phdrs == NULL) | |
5179 | return FALSE; | |
5180 | ||
5181 | for (i = 0, internal = pheaders, external = phdrs; | |
5182 | i < filedata->file_header.e_phnum; | |
5183 | i++, internal++, external++) | |
5184 | { | |
5185 | internal->p_type = BYTE_GET (external->p_type); | |
5186 | internal->p_offset = BYTE_GET (external->p_offset); | |
5187 | internal->p_vaddr = BYTE_GET (external->p_vaddr); | |
5188 | internal->p_paddr = BYTE_GET (external->p_paddr); | |
5189 | internal->p_filesz = BYTE_GET (external->p_filesz); | |
5190 | internal->p_memsz = BYTE_GET (external->p_memsz); | |
5191 | internal->p_flags = BYTE_GET (external->p_flags); | |
5192 | internal->p_align = BYTE_GET (external->p_align); | |
5193 | } | |
5194 | ||
5195 | free (phdrs); | |
5196 | return TRUE; | |
5197 | } | |
5198 | ||
5199 | /* Read in the program headers from FILEDATA and store them in PHEADERS. | |
5200 | Returns TRUE upon success, FALSE otherwise. Loads 64-bit headers. */ | |
5201 | ||
5202 | static bfd_boolean | |
5203 | get_64bit_program_headers (Filedata * filedata, Elf_Internal_Phdr * pheaders) | |
5204 | { | |
5205 | Elf64_External_Phdr * phdrs; | |
5206 | Elf64_External_Phdr * external; | |
5207 | Elf_Internal_Phdr * internal; | |
5208 | unsigned int i; | |
5209 | unsigned int size = filedata->file_header.e_phentsize; | |
5210 | unsigned int num = filedata->file_header.e_phnum; | |
5211 | ||
5212 | /* PR binutils/17531: Cope with unexpected section header sizes. */ | |
5213 | if (size == 0 || num == 0) | |
5214 | return FALSE; | |
5215 | if (size < sizeof * phdrs) | |
5216 | { | |
5217 | error (_("The e_phentsize field in the ELF header is less than the size of an ELF program header\n")); | |
5218 | return FALSE; | |
5219 | } | |
5220 | if (size > sizeof * phdrs) | |
5221 | warn (_("The e_phentsize field in the ELF header is larger than the size of an ELF program header\n")); | |
5222 | ||
5223 | phdrs = (Elf64_External_Phdr *) get_data (NULL, filedata, filedata->file_header.e_phoff, | |
5224 | size, num, _("program headers")); | |
5225 | if (!phdrs) | |
5226 | return FALSE; | |
5227 | ||
5228 | for (i = 0, internal = pheaders, external = phdrs; | |
5229 | i < filedata->file_header.e_phnum; | |
5230 | i++, internal++, external++) | |
5231 | { | |
5232 | internal->p_type = BYTE_GET (external->p_type); | |
5233 | internal->p_flags = BYTE_GET (external->p_flags); | |
5234 | internal->p_offset = BYTE_GET (external->p_offset); | |
5235 | internal->p_vaddr = BYTE_GET (external->p_vaddr); | |
5236 | internal->p_paddr = BYTE_GET (external->p_paddr); | |
5237 | internal->p_filesz = BYTE_GET (external->p_filesz); | |
5238 | internal->p_memsz = BYTE_GET (external->p_memsz); | |
5239 | internal->p_align = BYTE_GET (external->p_align); | |
5240 | } | |
5241 | ||
5242 | free (phdrs); | |
5243 | return TRUE; | |
5244 | } | |
5245 | ||
5246 | /* Returns TRUE if the program headers were read into `program_headers'. */ | |
5247 | ||
5248 | static bfd_boolean | |
5249 | get_program_headers (Filedata * filedata) | |
5250 | { | |
5251 | Elf_Internal_Phdr * phdrs; | |
5252 | ||
5253 | /* Check cache of prior read. */ | |
5254 | if (filedata->program_headers != NULL) | |
5255 | return TRUE; | |
5256 | ||
5257 | /* Be kind to memory checkers by looking for | |
5258 | e_phnum values which we know must be invalid. */ | |
5259 | if (filedata->file_header.e_phnum | |
5260 | * (is_32bit_elf ? sizeof (Elf32_External_Phdr) : sizeof (Elf64_External_Phdr)) | |
5261 | >= filedata->file_size) | |
5262 | { | |
5263 | error (_("Too many program headers - %#x - the file is not that big\n"), | |
5264 | filedata->file_header.e_phnum); | |
5265 | return FALSE; | |
5266 | } | |
5267 | ||
5268 | phdrs = (Elf_Internal_Phdr *) cmalloc (filedata->file_header.e_phnum, | |
5269 | sizeof (Elf_Internal_Phdr)); | |
5270 | if (phdrs == NULL) | |
5271 | { | |
5272 | error (_("Out of memory reading %u program headers\n"), | |
5273 | filedata->file_header.e_phnum); | |
5274 | return FALSE; | |
5275 | } | |
5276 | ||
5277 | if (is_32bit_elf | |
5278 | ? get_32bit_program_headers (filedata, phdrs) | |
5279 | : get_64bit_program_headers (filedata, phdrs)) | |
5280 | { | |
5281 | filedata->program_headers = phdrs; | |
5282 | return TRUE; | |
5283 | } | |
5284 | ||
5285 | free (phdrs); | |
5286 | return FALSE; | |
5287 | } | |
5288 | ||
5289 | /* Returns TRUE if the program headers were loaded. */ | |
5290 | ||
5291 | static bfd_boolean | |
5292 | process_program_headers (Filedata * filedata) | |
5293 | { | |
5294 | Elf_Internal_Phdr * segment; | |
5295 | unsigned int i; | |
5296 | Elf_Internal_Phdr * previous_load = NULL; | |
5297 | ||
5298 | filedata->dynamic_addr = 0; | |
5299 | filedata->dynamic_size = 0; | |
5300 | ||
5301 | if (filedata->file_header.e_phnum == 0) | |
5302 | { | |
5303 | /* PR binutils/12467. */ | |
5304 | if (filedata->file_header.e_phoff != 0) | |
5305 | { | |
5306 | warn (_("possibly corrupt ELF header - it has a non-zero program" | |
5307 | " header offset, but no program headers\n")); | |
5308 | return FALSE; | |
5309 | } | |
5310 | else if (do_segments) | |
5311 | { | |
5312 | if (filedata->is_separate) | |
5313 | printf (_("\nThere are no program headers in linked file '%s'.\n"), | |
5314 | filedata->file_name); | |
5315 | else | |
5316 | printf (_("\nThere are no program headers in this file.\n")); | |
5317 | } | |
5318 | return TRUE; | |
5319 | } | |
5320 | ||
5321 | if (do_segments && !do_header) | |
5322 | { | |
5323 | if (filedata->is_separate) | |
5324 | printf ("\nIn linked file '%s' the ELF file type is %s\n", | |
5325 | filedata->file_name, | |
5326 | get_file_type (filedata->file_header.e_type)); | |
5327 | else | |
5328 | printf (_("\nElf file type is %s\n"), get_file_type (filedata->file_header.e_type)); | |
5329 | printf (_("Entry point 0x%s\n"), bfd_vmatoa ("x", filedata->file_header.e_entry)); | |
5330 | printf (ngettext ("There is %d program header, starting at offset %s\n", | |
5331 | "There are %d program headers, starting at offset %s\n", | |
5332 | filedata->file_header.e_phnum), | |
5333 | filedata->file_header.e_phnum, | |
5334 | bfd_vmatoa ("u", filedata->file_header.e_phoff)); | |
5335 | } | |
5336 | ||
5337 | if (! get_program_headers (filedata)) | |
5338 | return TRUE; | |
5339 | ||
5340 | if (do_segments) | |
5341 | { | |
5342 | if (filedata->file_header.e_phnum > 1) | |
5343 | printf (_("\nProgram Headers:\n")); | |
5344 | else | |
5345 | printf (_("\nProgram Headers:\n")); | |
5346 | ||
5347 | if (is_32bit_elf) | |
5348 | printf | |
5349 | (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n")); | |
5350 | else if (do_wide) | |
5351 | printf | |
5352 | (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n")); | |
5353 | else | |
5354 | { | |
5355 | printf | |
5356 | (_(" Type Offset VirtAddr PhysAddr\n")); | |
5357 | printf | |
5358 | (_(" FileSiz MemSiz Flags Align\n")); | |
5359 | } | |
5360 | } | |
5361 | ||
5362 | for (i = 0, segment = filedata->program_headers; | |
5363 | i < filedata->file_header.e_phnum; | |
5364 | i++, segment++) | |
5365 | { | |
5366 | if (do_segments) | |
5367 | { | |
5368 | printf (" %-14.14s ", get_segment_type (filedata, segment->p_type)); | |
5369 | ||
5370 | if (is_32bit_elf) | |
5371 | { | |
5372 | printf ("0x%6.6lx ", (unsigned long) segment->p_offset); | |
5373 | printf ("0x%8.8lx ", (unsigned long) segment->p_vaddr); | |
5374 | printf ("0x%8.8lx ", (unsigned long) segment->p_paddr); | |
5375 | printf ("0x%5.5lx ", (unsigned long) segment->p_filesz); | |
5376 | printf ("0x%5.5lx ", (unsigned long) segment->p_memsz); | |
5377 | printf ("%c%c%c ", | |
5378 | (segment->p_flags & PF_R ? 'R' : ' '), | |
5379 | (segment->p_flags & PF_W ? 'W' : ' '), | |
5380 | (segment->p_flags & PF_X ? 'E' : ' ')); | |
5381 | printf ("%#lx", (unsigned long) segment->p_align); | |
5382 | } | |
5383 | else if (do_wide) | |
5384 | { | |
5385 | if ((unsigned long) segment->p_offset == segment->p_offset) | |
5386 | printf ("0x%6.6lx ", (unsigned long) segment->p_offset); | |
5387 | else | |
5388 | { | |
5389 | print_vma (segment->p_offset, FULL_HEX); | |
5390 | putchar (' '); | |
5391 | } | |
5392 | ||
5393 | print_vma (segment->p_vaddr, FULL_HEX); | |
5394 | putchar (' '); | |
5395 | print_vma (segment->p_paddr, FULL_HEX); | |
5396 | putchar (' '); | |
5397 | ||
5398 | if ((unsigned long) segment->p_filesz == segment->p_filesz) | |
5399 | printf ("0x%6.6lx ", (unsigned long) segment->p_filesz); | |
5400 | else | |
5401 | { | |
5402 | print_vma (segment->p_filesz, FULL_HEX); | |
5403 | putchar (' '); | |
5404 | } | |
5405 | ||
5406 | if ((unsigned long) segment->p_memsz == segment->p_memsz) | |
5407 | printf ("0x%6.6lx", (unsigned long) segment->p_memsz); | |
5408 | else | |
5409 | { | |
5410 | print_vma (segment->p_memsz, FULL_HEX); | |
5411 | } | |
5412 | ||
5413 | printf (" %c%c%c ", | |
5414 | (segment->p_flags & PF_R ? 'R' : ' '), | |
5415 | (segment->p_flags & PF_W ? 'W' : ' '), | |
5416 | (segment->p_flags & PF_X ? 'E' : ' ')); | |
5417 | ||
5418 | if ((unsigned long) segment->p_align == segment->p_align) | |
5419 | printf ("%#lx", (unsigned long) segment->p_align); | |
5420 | else | |
5421 | { | |
5422 | print_vma (segment->p_align, PREFIX_HEX); | |
5423 | } | |
5424 | } | |
5425 | else | |
5426 | { | |
5427 | print_vma (segment->p_offset, FULL_HEX); | |
5428 | putchar (' '); | |
5429 | print_vma (segment->p_vaddr, FULL_HEX); | |
5430 | putchar (' '); | |
5431 | print_vma (segment->p_paddr, FULL_HEX); | |
5432 | printf ("\n "); | |
5433 | print_vma (segment->p_filesz, FULL_HEX); | |
5434 | putchar (' '); | |
5435 | print_vma (segment->p_memsz, FULL_HEX); | |
5436 | printf (" %c%c%c ", | |
5437 | (segment->p_flags & PF_R ? 'R' : ' '), | |
5438 | (segment->p_flags & PF_W ? 'W' : ' '), | |
5439 | (segment->p_flags & PF_X ? 'E' : ' ')); | |
5440 | print_vma (segment->p_align, PREFIX_HEX); | |
5441 | } | |
5442 | ||
5443 | putc ('\n', stdout); | |
5444 | } | |
5445 | ||
5446 | switch (segment->p_type) | |
5447 | { | |
5448 | case PT_LOAD: | |
5449 | #if 0 /* Do not warn about out of order PT_LOAD segments. Although officially | |
5450 | required by the ELF standard, several programs, including the Linux | |
5451 | kernel, make use of non-ordered segments. */ | |
5452 | if (previous_load | |
5453 | && previous_load->p_vaddr > segment->p_vaddr) | |
5454 | error (_("LOAD segments must be sorted in order of increasing VirtAddr\n")); | |
5455 | #endif | |
5456 | if (segment->p_memsz < segment->p_filesz) | |
5457 | error (_("the segment's file size is larger than its memory size\n")); | |
5458 | previous_load = segment; | |
5459 | break; | |
5460 | ||
5461 | case PT_PHDR: | |
5462 | /* PR 20815 - Verify that the program header is loaded into memory. */ | |
5463 | if (i > 0 && previous_load != NULL) | |
5464 | error (_("the PHDR segment must occur before any LOAD segment\n")); | |
5465 | if (filedata->file_header.e_machine != EM_PARISC) | |
5466 | { | |
5467 | unsigned int j; | |
5468 | ||
5469 | for (j = 1; j < filedata->file_header.e_phnum; j++) | |
5470 | { | |
5471 | Elf_Internal_Phdr *load = filedata->program_headers + j; | |
5472 | if (load->p_type == PT_LOAD | |
5473 | && load->p_offset <= segment->p_offset | |
5474 | && (load->p_offset + load->p_filesz | |
5475 | >= segment->p_offset + segment->p_filesz) | |
5476 | && load->p_vaddr <= segment->p_vaddr | |
5477 | && (load->p_vaddr + load->p_filesz | |
5478 | >= segment->p_vaddr + segment->p_filesz)) | |
5479 | break; | |
5480 | } | |
5481 | if (j == filedata->file_header.e_phnum) | |
5482 | error (_("the PHDR segment is not covered by a LOAD segment\n")); | |
5483 | } | |
5484 | break; | |
5485 | ||
5486 | case PT_DYNAMIC: | |
5487 | if (filedata->dynamic_addr) | |
5488 | error (_("more than one dynamic segment\n")); | |
5489 | ||
5490 | /* By default, assume that the .dynamic section is the first | |
5491 | section in the DYNAMIC segment. */ | |
5492 | filedata->dynamic_addr = segment->p_offset; | |
5493 | filedata->dynamic_size = segment->p_filesz; | |
5494 | ||
5495 | /* Try to locate the .dynamic section. If there is | |
5496 | a section header table, we can easily locate it. */ | |
5497 | if (filedata->section_headers != NULL) | |
5498 | { | |
5499 | Elf_Internal_Shdr * sec; | |
5500 | ||
5501 | sec = find_section (filedata, ".dynamic"); | |
5502 | if (sec == NULL || sec->sh_size == 0) | |
5503 | { | |
5504 | /* A corresponding .dynamic section is expected, but on | |
5505 | IA-64/OpenVMS it is OK for it to be missing. */ | |
5506 | if (!is_ia64_vms (filedata)) | |
5507 | error (_("no .dynamic section in the dynamic segment\n")); | |
5508 | break; | |
5509 | } | |
5510 | ||
5511 | if (sec->sh_type == SHT_NOBITS) | |
5512 | { | |
5513 | filedata->dynamic_size = 0; | |
5514 | break; | |
5515 | } | |
5516 | ||
5517 | filedata->dynamic_addr = sec->sh_offset; | |
5518 | filedata->dynamic_size = sec->sh_size; | |
5519 | ||
5520 | /* The PT_DYNAMIC segment, which is used by the run-time | |
5521 | loader, should exactly match the .dynamic section. */ | |
5522 | if (do_checks | |
5523 | && (filedata->dynamic_addr != segment->p_offset | |
5524 | || filedata->dynamic_size != segment->p_filesz)) | |
5525 | warn (_("\ | |
5526 | the .dynamic section is not the same as the dynamic segment\n")); | |
5527 | } | |
5528 | ||
5529 | /* PR binutils/17512: Avoid corrupt dynamic section info in the | |
5530 | segment. Check this after matching against the section headers | |
5531 | so we don't warn on debuginfo file (which have NOBITS .dynamic | |
5532 | sections). */ | |
5533 | if (filedata->dynamic_addr > filedata->file_size | |
5534 | || (filedata->dynamic_size | |
5535 | > filedata->file_size - filedata->dynamic_addr)) | |
5536 | { | |
5537 | error (_("the dynamic segment offset + size exceeds the size of the file\n")); | |
5538 | filedata->dynamic_addr = filedata->dynamic_size = 0; | |
5539 | } | |
5540 | break; | |
5541 | ||
5542 | case PT_INTERP: | |
5543 | if (fseek (filedata->handle, | |
5544 | filedata->archive_file_offset + (long) segment->p_offset, | |
5545 | SEEK_SET)) | |
5546 | error (_("Unable to find program interpreter name\n")); | |
5547 | else | |
5548 | { | |
5549 | char fmt [32]; | |
5550 | int ret = snprintf (fmt, sizeof (fmt), "%%%ds", PATH_MAX - 1); | |
5551 | ||
5552 | if (ret >= (int) sizeof (fmt) || ret < 0) | |
5553 | error (_("Internal error: failed to create format string to display program interpreter\n")); | |
5554 | ||
5555 | filedata->program_interpreter[0] = 0; | |
5556 | if (fscanf (filedata->handle, fmt, | |
5557 | filedata->program_interpreter) <= 0) | |
5558 | error (_("Unable to read program interpreter name\n")); | |
5559 | ||
5560 | if (do_segments) | |
5561 | printf (_(" [Requesting program interpreter: %s]\n"), | |
5562 | filedata->program_interpreter); | |
5563 | } | |
5564 | break; | |
5565 | } | |
5566 | } | |
5567 | ||
5568 | if (do_segments | |
5569 | && filedata->section_headers != NULL | |
5570 | && filedata->string_table != NULL) | |
5571 | { | |
5572 | printf (_("\n Section to Segment mapping:\n")); | |
5573 | printf (_(" Segment Sections...\n")); | |
5574 | ||
5575 | for (i = 0; i < filedata->file_header.e_phnum; i++) | |
5576 | { | |
5577 | unsigned int j; | |
5578 | Elf_Internal_Shdr * section; | |
5579 | ||
5580 | segment = filedata->program_headers + i; | |
5581 | section = filedata->section_headers + 1; | |
5582 | ||
5583 | printf (" %2.2d ", i); | |
5584 | ||
5585 | for (j = 1; j < filedata->file_header.e_shnum; j++, section++) | |
5586 | { | |
5587 | if (!ELF_TBSS_SPECIAL (section, segment) | |
5588 | && ELF_SECTION_IN_SEGMENT_STRICT (section, segment)) | |
5589 | printf ("%s ", printable_section_name (filedata, section)); | |
5590 | } | |
5591 | ||
5592 | putc ('\n',stdout); | |
5593 | } | |
5594 | } | |
5595 | ||
5596 | return TRUE; | |
5597 | } | |
5598 | ||
5599 | ||
5600 | /* Find the file offset corresponding to VMA by using the program headers. */ | |
5601 | ||
5602 | static long | |
5603 | offset_from_vma (Filedata * filedata, bfd_vma vma, bfd_size_type size) | |
5604 | { | |
5605 | Elf_Internal_Phdr * seg; | |
5606 | ||
5607 | if (! get_program_headers (filedata)) | |
5608 | { | |
5609 | warn (_("Cannot interpret virtual addresses without program headers.\n")); | |
5610 | return (long) vma; | |
5611 | } | |
5612 | ||
5613 | for (seg = filedata->program_headers; | |
5614 | seg < filedata->program_headers + filedata->file_header.e_phnum; | |
5615 | ++seg) | |
5616 | { | |
5617 | if (seg->p_type != PT_LOAD) | |
5618 | continue; | |
5619 | ||
5620 | if (vma >= (seg->p_vaddr & -seg->p_align) | |
5621 | && vma + size <= seg->p_vaddr + seg->p_filesz) | |
5622 | return vma - seg->p_vaddr + seg->p_offset; | |
5623 | } | |
5624 | ||
5625 | warn (_("Virtual address 0x%lx not located in any PT_LOAD segment.\n"), | |
5626 | (unsigned long) vma); | |
5627 | return (long) vma; | |
5628 | } | |
5629 | ||
5630 | ||
5631 | /* Allocate memory and load the sections headers into FILEDATA->filedata->section_headers. | |
5632 | If PROBE is true, this is just a probe and we do not generate any error | |
5633 | messages if the load fails. */ | |
5634 | ||
5635 | static bfd_boolean | |
5636 | get_32bit_section_headers (Filedata * filedata, bfd_boolean probe) | |
5637 | { | |
5638 | Elf32_External_Shdr * shdrs; | |
5639 | Elf_Internal_Shdr * internal; | |
5640 | unsigned int i; | |
5641 | unsigned int size = filedata->file_header.e_shentsize; | |
5642 | unsigned int num = probe ? 1 : filedata->file_header.e_shnum; | |
5643 | ||
5644 | /* PR binutils/17531: Cope with unexpected section header sizes. */ | |
5645 | if (size == 0 || num == 0) | |
5646 | return FALSE; | |
5647 | if (size < sizeof * shdrs) | |
5648 | { | |
5649 | if (! probe) | |
5650 | error (_("The e_shentsize field in the ELF header is less than the size of an ELF section header\n")); | |
5651 | return FALSE; | |
5652 | } | |
5653 | if (!probe && size > sizeof * shdrs) | |
5654 | warn (_("The e_shentsize field in the ELF header is larger than the size of an ELF section header\n")); | |
5655 | ||
5656 | shdrs = (Elf32_External_Shdr *) get_data (NULL, filedata, filedata->file_header.e_shoff, | |
5657 | size, num, | |
5658 | probe ? NULL : _("section headers")); | |
5659 | if (shdrs == NULL) | |
5660 | return FALSE; | |
5661 | ||
5662 | free (filedata->section_headers); | |
5663 | filedata->section_headers = (Elf_Internal_Shdr *) | |
5664 | cmalloc (num, sizeof (Elf_Internal_Shdr)); | |
5665 | if (filedata->section_headers == NULL) | |
5666 | { | |
5667 | if (!probe) | |
5668 | error (_("Out of memory reading %u section headers\n"), num); | |
5669 | free (shdrs); | |
5670 | return FALSE; | |
5671 | } | |
5672 | ||
5673 | for (i = 0, internal = filedata->section_headers; | |
5674 | i < num; | |
5675 | i++, internal++) | |
5676 | { | |
5677 | internal->sh_name = BYTE_GET (shdrs[i].sh_name); | |
5678 | internal->sh_type = BYTE_GET (shdrs[i].sh_type); | |
5679 | internal->sh_flags = BYTE_GET (shdrs[i].sh_flags); | |
5680 | internal->sh_addr = BYTE_GET (shdrs[i].sh_addr); | |
5681 | internal->sh_offset = BYTE_GET (shdrs[i].sh_offset); | |
5682 | internal->sh_size = BYTE_GET (shdrs[i].sh_size); | |
5683 | internal->sh_link = BYTE_GET (shdrs[i].sh_link); | |
5684 | internal->sh_info = BYTE_GET (shdrs[i].sh_info); | |
5685 | internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign); | |
5686 | internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize); | |
5687 | if (!probe && internal->sh_link > num) | |
5688 | warn (_("Section %u has an out of range sh_link value of %u\n"), i, internal->sh_link); | |
5689 | if (!probe && internal->sh_flags & SHF_INFO_LINK && internal->sh_info > num) | |
5690 | warn (_("Section %u has an out of range sh_info value of %u\n"), i, internal->sh_info); | |
5691 | } | |
5692 | ||
5693 | free (shdrs); | |
5694 | return TRUE; | |
5695 | } | |
5696 | ||
5697 | /* Like get_32bit_section_headers, except that it fetches 64-bit headers. */ | |
5698 | ||
5699 | static bfd_boolean | |
5700 | get_64bit_section_headers (Filedata * filedata, bfd_boolean probe) | |
5701 | { | |
5702 | Elf64_External_Shdr * shdrs; | |
5703 | Elf_Internal_Shdr * internal; | |
5704 | unsigned int i; | |
5705 | unsigned int size = filedata->file_header.e_shentsize; | |
5706 | unsigned int num = probe ? 1 : filedata->file_header.e_shnum; | |
5707 | ||
5708 | /* PR binutils/17531: Cope with unexpected section header sizes. */ | |
5709 | if (size == 0 || num == 0) | |
5710 | return FALSE; | |
5711 | ||
5712 | if (size < sizeof * shdrs) | |
5713 | { | |
5714 | if (! probe) | |
5715 | error (_("The e_shentsize field in the ELF header is less than the size of an ELF section header\n")); | |
5716 | return FALSE; | |
5717 | } | |
5718 | ||
5719 | if (! probe && size > sizeof * shdrs) | |
5720 | warn (_("The e_shentsize field in the ELF header is larger than the size of an ELF section header\n")); | |
5721 | ||
5722 | shdrs = (Elf64_External_Shdr *) get_data (NULL, filedata, | |
5723 | filedata->file_header.e_shoff, | |
5724 | size, num, | |
5725 | probe ? NULL : _("section headers")); | |
5726 | if (shdrs == NULL) | |
5727 | return FALSE; | |
5728 | ||
5729 | free (filedata->section_headers); | |
5730 | filedata->section_headers = (Elf_Internal_Shdr *) | |
5731 | cmalloc (num, sizeof (Elf_Internal_Shdr)); | |
5732 | if (filedata->section_headers == NULL) | |
5733 | { | |
5734 | if (! probe) | |
5735 | error (_("Out of memory reading %u section headers\n"), num); | |
5736 | free (shdrs); | |
5737 | return FALSE; | |
5738 | } | |
5739 | ||
5740 | for (i = 0, internal = filedata->section_headers; | |
5741 | i < num; | |
5742 | i++, internal++) | |
5743 | { | |
5744 | internal->sh_name = BYTE_GET (shdrs[i].sh_name); | |
5745 | internal->sh_type = BYTE_GET (shdrs[i].sh_type); | |
5746 | internal->sh_flags = BYTE_GET (shdrs[i].sh_flags); | |
5747 | internal->sh_addr = BYTE_GET (shdrs[i].sh_addr); | |
5748 | internal->sh_size = BYTE_GET (shdrs[i].sh_size); | |
5749 | internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize); | |
5750 | internal->sh_link = BYTE_GET (shdrs[i].sh_link); | |
5751 | internal->sh_info = BYTE_GET (shdrs[i].sh_info); | |
5752 | internal->sh_offset = BYTE_GET (shdrs[i].sh_offset); | |
5753 | internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign); | |
5754 | if (!probe && internal->sh_link > num) | |
5755 | warn (_("Section %u has an out of range sh_link value of %u\n"), i, internal->sh_link); | |
5756 | if (!probe && internal->sh_flags & SHF_INFO_LINK && internal->sh_info > num) | |
5757 | warn (_("Section %u has an out of range sh_info value of %u\n"), i, internal->sh_info); | |
5758 | } | |
5759 | ||
5760 | free (shdrs); | |
5761 | return TRUE; | |
5762 | } | |
5763 | ||
5764 | static Elf_Internal_Sym * | |
5765 | get_32bit_elf_symbols (Filedata * filedata, | |
5766 | Elf_Internal_Shdr * section, | |
5767 | unsigned long * num_syms_return) | |
5768 | { | |
5769 | unsigned long number = 0; | |
5770 | Elf32_External_Sym * esyms = NULL; | |
5771 | Elf_External_Sym_Shndx * shndx = NULL; | |
5772 | Elf_Internal_Sym * isyms = NULL; | |
5773 | Elf_Internal_Sym * psym; | |
5774 | unsigned int j; | |
5775 | elf_section_list * entry; | |
5776 | ||
5777 | if (section->sh_size == 0) | |
5778 | { | |
5779 | if (num_syms_return != NULL) | |
5780 | * num_syms_return = 0; | |
5781 | return NULL; | |
5782 | } | |
5783 | ||
5784 | /* Run some sanity checks first. */ | |
5785 | if (section->sh_entsize == 0 || section->sh_entsize > section->sh_size) | |
5786 | { | |
5787 | error (_("Section %s has an invalid sh_entsize of 0x%lx\n"), | |
5788 | printable_section_name (filedata, section), | |
5789 | (unsigned long) section->sh_entsize); | |
5790 | goto exit_point; | |
5791 | } | |
5792 | ||
5793 | if (section->sh_size > filedata->file_size) | |
5794 | { | |
5795 | error (_("Section %s has an invalid sh_size of 0x%lx\n"), | |
5796 | printable_section_name (filedata, section), | |
5797 | (unsigned long) section->sh_size); | |
5798 | goto exit_point; | |
5799 | } | |
5800 | ||
5801 | number = section->sh_size / section->sh_entsize; | |
5802 | ||
5803 | if (number * sizeof (Elf32_External_Sym) > section->sh_size + 1) | |
5804 | { | |
5805 | error (_("Size (0x%lx) of section %s is not a multiple of its sh_entsize (0x%lx)\n"), | |
5806 | (unsigned long) section->sh_size, | |
5807 | printable_section_name (filedata, section), | |
5808 | (unsigned long) section->sh_entsize); | |
5809 | goto exit_point; | |
5810 | } | |
5811 | ||
5812 | esyms = (Elf32_External_Sym *) get_data (NULL, filedata, section->sh_offset, 1, | |
5813 | section->sh_size, _("symbols")); | |
5814 | if (esyms == NULL) | |
5815 | goto exit_point; | |
5816 | ||
5817 | shndx = NULL; | |
5818 | for (entry = filedata->symtab_shndx_list; entry != NULL; entry = entry->next) | |
5819 | { | |
5820 | if (entry->hdr->sh_link != (unsigned long) (section - filedata->section_headers)) | |
5821 | continue; | |
5822 | ||
5823 | if (shndx != NULL) | |
5824 | { | |
5825 | error (_("Multiple symbol table index sections associated with the same symbol section\n")); | |
5826 | free (shndx); | |
5827 | } | |
5828 | ||
5829 | shndx = (Elf_External_Sym_Shndx *) get_data (NULL, filedata, | |
5830 | entry->hdr->sh_offset, | |
5831 | 1, entry->hdr->sh_size, | |
5832 | _("symbol table section indices")); | |
5833 | if (shndx == NULL) | |
5834 | goto exit_point; | |
5835 | ||
5836 | /* PR17531: file: heap-buffer-overflow */ | |
5837 | if (entry->hdr->sh_size / sizeof (Elf_External_Sym_Shndx) < number) | |
5838 | { | |
5839 | error (_("Index section %s has an sh_size of 0x%lx - expected 0x%lx\n"), | |
5840 | printable_section_name (filedata, entry->hdr), | |
5841 | (unsigned long) entry->hdr->sh_size, | |
5842 | (unsigned long) section->sh_size); | |
5843 | goto exit_point; | |
5844 | } | |
5845 | } | |
5846 | ||
5847 | isyms = (Elf_Internal_Sym *) cmalloc (number, sizeof (Elf_Internal_Sym)); | |
5848 | ||
5849 | if (isyms == NULL) | |
5850 | { | |
5851 | error (_("Out of memory reading %lu symbols\n"), | |
5852 | (unsigned long) number); | |
5853 | goto exit_point; | |
5854 | } | |
5855 | ||
5856 | for (j = 0, psym = isyms; j < number; j++, psym++) | |
5857 | { | |
5858 | psym->st_name = BYTE_GET (esyms[j].st_name); | |
5859 | psym->st_value = BYTE_GET (esyms[j].st_value); | |
5860 | psym->st_size = BYTE_GET (esyms[j].st_size); | |
5861 | psym->st_shndx = BYTE_GET (esyms[j].st_shndx); | |
5862 | if (psym->st_shndx == (SHN_XINDEX & 0xffff) && shndx != NULL) | |
5863 | psym->st_shndx | |
5864 | = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j])); | |
5865 | else if (psym->st_shndx >= (SHN_LORESERVE & 0xffff)) | |
5866 | psym->st_shndx += SHN_LORESERVE - (SHN_LORESERVE & 0xffff); | |
5867 | psym->st_info = BYTE_GET (esyms[j].st_info); | |
5868 | psym->st_other = BYTE_GET (esyms[j].st_other); | |
5869 | } | |
5870 | ||
5871 | exit_point: | |
5872 | free (shndx); | |
5873 | free (esyms); | |
5874 | ||
5875 | if (num_syms_return != NULL) | |
5876 | * num_syms_return = isyms == NULL ? 0 : number; | |
5877 | ||
5878 | return isyms; | |
5879 | } | |
5880 | ||
5881 | static Elf_Internal_Sym * | |
5882 | get_64bit_elf_symbols (Filedata * filedata, | |
5883 | Elf_Internal_Shdr * section, | |
5884 | unsigned long * num_syms_return) | |
5885 | { | |
5886 | unsigned long number = 0; | |
5887 | Elf64_External_Sym * esyms = NULL; | |
5888 | Elf_External_Sym_Shndx * shndx = NULL; | |
5889 | Elf_Internal_Sym * isyms = NULL; | |
5890 | Elf_Internal_Sym * psym; | |
5891 | unsigned int j; | |
5892 | elf_section_list * entry; | |
5893 | ||
5894 | if (section->sh_size == 0) | |
5895 | { | |
5896 | if (num_syms_return != NULL) | |
5897 | * num_syms_return = 0; | |
5898 | return NULL; | |
5899 | } | |
5900 | ||
5901 | /* Run some sanity checks first. */ | |
5902 | if (section->sh_entsize == 0 || section->sh_entsize > section->sh_size) | |
5903 | { | |
5904 | error (_("Section %s has an invalid sh_entsize of 0x%lx\n"), | |
5905 | printable_section_name (filedata, section), | |
5906 | (unsigned long) section->sh_entsize); | |
5907 | goto exit_point; | |
5908 | } | |
5909 | ||
5910 | if (section->sh_size > filedata->file_size) | |
5911 | { | |
5912 | error (_("Section %s has an invalid sh_size of 0x%lx\n"), | |
5913 | printable_section_name (filedata, section), | |
5914 | (unsigned long) section->sh_size); | |
5915 | goto exit_point; | |
5916 | } | |
5917 | ||
5918 | number = section->sh_size / section->sh_entsize; | |
5919 | ||
5920 | if (number * sizeof (Elf64_External_Sym) > section->sh_size + 1) | |
5921 | { | |
5922 | error (_("Size (0x%lx) of section %s is not a multiple of its sh_entsize (0x%lx)\n"), | |
5923 | (unsigned long) section->sh_size, | |
5924 | printable_section_name (filedata, section), | |
5925 | (unsigned long) section->sh_entsize); | |
5926 | goto exit_point; | |
5927 | } | |
5928 | ||
5929 | esyms = (Elf64_External_Sym *) get_data (NULL, filedata, section->sh_offset, 1, | |
5930 | section->sh_size, _("symbols")); | |
5931 | if (!esyms) | |
5932 | goto exit_point; | |
5933 | ||
5934 | shndx = NULL; | |
5935 | for (entry = filedata->symtab_shndx_list; entry != NULL; entry = entry->next) | |
5936 | { | |
5937 | if (entry->hdr->sh_link != (unsigned long) (section - filedata->section_headers)) | |
5938 | continue; | |
5939 | ||
5940 | if (shndx != NULL) | |
5941 | { | |
5942 | error (_("Multiple symbol table index sections associated with the same symbol section\n")); | |
5943 | free (shndx); | |
5944 | } | |
5945 | ||
5946 | shndx = (Elf_External_Sym_Shndx *) get_data (NULL, filedata, | |
5947 | entry->hdr->sh_offset, | |
5948 | 1, entry->hdr->sh_size, | |
5949 | _("symbol table section indices")); | |
5950 | if (shndx == NULL) | |
5951 | goto exit_point; | |
5952 | ||
5953 | /* PR17531: file: heap-buffer-overflow */ | |
5954 | if (entry->hdr->sh_size / sizeof (Elf_External_Sym_Shndx) < number) | |
5955 | { | |
5956 | error (_("Index section %s has an sh_size of 0x%lx - expected 0x%lx\n"), | |
5957 | printable_section_name (filedata, entry->hdr), | |
5958 | (unsigned long) entry->hdr->sh_size, | |
5959 | (unsigned long) section->sh_size); | |
5960 | goto exit_point; | |
5961 | } | |
5962 | } | |
5963 | ||
5964 | isyms = (Elf_Internal_Sym *) cmalloc (number, sizeof (Elf_Internal_Sym)); | |
5965 | ||
5966 | if (isyms == NULL) | |
5967 | { | |
5968 | error (_("Out of memory reading %lu symbols\n"), | |
5969 | (unsigned long) number); | |
5970 | goto exit_point; | |
5971 | } | |
5972 | ||
5973 | for (j = 0, psym = isyms; j < number; j++, psym++) | |
5974 | { | |
5975 | psym->st_name = BYTE_GET (esyms[j].st_name); | |
5976 | psym->st_info = BYTE_GET (esyms[j].st_info); | |
5977 | psym->st_other = BYTE_GET (esyms[j].st_other); | |
5978 | psym->st_shndx = BYTE_GET (esyms[j].st_shndx); | |
5979 | ||
5980 | if (psym->st_shndx == (SHN_XINDEX & 0xffff) && shndx != NULL) | |
5981 | psym->st_shndx | |
5982 | = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j])); | |
5983 | else if (psym->st_shndx >= (SHN_LORESERVE & 0xffff)) | |
5984 | psym->st_shndx += SHN_LORESERVE - (SHN_LORESERVE & 0xffff); | |
5985 | ||
5986 | psym->st_value = BYTE_GET (esyms[j].st_value); | |
5987 | psym->st_size = BYTE_GET (esyms[j].st_size); | |
5988 | } | |
5989 | ||
5990 | exit_point: | |
5991 | free (shndx); | |
5992 | free (esyms); | |
5993 | ||
5994 | if (num_syms_return != NULL) | |
5995 | * num_syms_return = isyms == NULL ? 0 : number; | |
5996 | ||
5997 | return isyms; | |
5998 | } | |
5999 | ||
6000 | static const char * | |
6001 | get_elf_section_flags (Filedata * filedata, bfd_vma sh_flags) | |
6002 | { | |
6003 | static char buff[1024]; | |
6004 | char * p = buff; | |
6005 | unsigned int field_size = is_32bit_elf ? 8 : 16; | |
6006 | signed int sindex; | |
6007 | unsigned int size = sizeof (buff) - (field_size + 4 + 1); | |
6008 | bfd_vma os_flags = 0; | |
6009 | bfd_vma proc_flags = 0; | |
6010 | bfd_vma unknown_flags = 0; | |
6011 | static const struct | |
6012 | { | |
6013 | const char * str; | |
6014 | unsigned int len; | |
6015 | } | |
6016 | flags [] = | |
6017 | { | |
6018 | /* 0 */ { STRING_COMMA_LEN ("WRITE") }, | |
6019 | /* 1 */ { STRING_COMMA_LEN ("ALLOC") }, | |
6020 | /* 2 */ { STRING_COMMA_LEN ("EXEC") }, | |
6021 | /* 3 */ { STRING_COMMA_LEN ("MERGE") }, | |
6022 | /* 4 */ { STRING_COMMA_LEN ("STRINGS") }, | |
6023 | /* 5 */ { STRING_COMMA_LEN ("INFO LINK") }, | |
6024 | /* 6 */ { STRING_COMMA_LEN ("LINK ORDER") }, | |
6025 | /* 7 */ { STRING_COMMA_LEN ("OS NONCONF") }, | |
6026 | /* 8 */ { STRING_COMMA_LEN ("GROUP") }, | |
6027 | /* 9 */ { STRING_COMMA_LEN ("TLS") }, | |
6028 | /* IA-64 specific. */ | |
6029 | /* 10 */ { STRING_COMMA_LEN ("SHORT") }, | |
6030 | /* 11 */ { STRING_COMMA_LEN ("NORECOV") }, | |
6031 | /* IA-64 OpenVMS specific. */ | |
6032 | /* 12 */ { STRING_COMMA_LEN ("VMS_GLOBAL") }, | |
6033 | /* 13 */ { STRING_COMMA_LEN ("VMS_OVERLAID") }, | |
6034 | /* 14 */ { STRING_COMMA_LEN ("VMS_SHARED") }, | |
6035 | /* 15 */ { STRING_COMMA_LEN ("VMS_VECTOR") }, | |
6036 | /* 16 */ { STRING_COMMA_LEN ("VMS_ALLOC_64BIT") }, | |
6037 | /* 17 */ { STRING_COMMA_LEN ("VMS_PROTECTED") }, | |
6038 | /* Generic. */ | |
6039 | /* 18 */ { STRING_COMMA_LEN ("EXCLUDE") }, | |
6040 | /* SPARC specific. */ | |
6041 | /* 19 */ { STRING_COMMA_LEN ("ORDERED") }, | |
6042 | /* 20 */ { STRING_COMMA_LEN ("COMPRESSED") }, | |
6043 | /* ARM specific. */ | |
6044 | /* 21 */ { STRING_COMMA_LEN ("ENTRYSECT") }, | |
6045 | /* 22 */ { STRING_COMMA_LEN ("ARM_PURECODE") }, | |
6046 | /* 23 */ { STRING_COMMA_LEN ("COMDEF") }, | |
6047 | /* GNU specific. */ | |
6048 | /* 24 */ { STRING_COMMA_LEN ("GNU_MBIND") }, | |
6049 | /* VLE specific. */ | |
6050 | /* 25 */ { STRING_COMMA_LEN ("VLE") }, | |
6051 | /* GNU specific. */ | |
6052 | /* 26 */ { STRING_COMMA_LEN ("GNU_RETAIN") }, | |
6053 | }; | |
6054 | ||
6055 | if (do_section_details) | |
6056 | { | |
6057 | sprintf (buff, "[%*.*lx]: ", | |
6058 | field_size, field_size, (unsigned long) sh_flags); | |
6059 | p += field_size + 4; | |
6060 | } | |
6061 | ||
6062 | while (sh_flags) | |
6063 | { | |
6064 | bfd_vma flag; | |
6065 | ||
6066 | flag = sh_flags & - sh_flags; | |
6067 | sh_flags &= ~ flag; | |
6068 | ||
6069 | if (do_section_details) | |
6070 | { | |
6071 | switch (flag) | |
6072 | { | |
6073 | case SHF_WRITE: sindex = 0; break; | |
6074 | case SHF_ALLOC: sindex = 1; break; | |
6075 | case SHF_EXECINSTR: sindex = 2; break; | |
6076 | case SHF_MERGE: sindex = 3; break; | |
6077 | case SHF_STRINGS: sindex = 4; break; | |
6078 | case SHF_INFO_LINK: sindex = 5; break; | |
6079 | case SHF_LINK_ORDER: sindex = 6; break; | |
6080 | case SHF_OS_NONCONFORMING: sindex = 7; break; | |
6081 | case SHF_GROUP: sindex = 8; break; | |
6082 | case SHF_TLS: sindex = 9; break; | |
6083 | case SHF_EXCLUDE: sindex = 18; break; | |
6084 | case SHF_COMPRESSED: sindex = 20; break; | |
6085 | ||
6086 | default: | |
6087 | sindex = -1; | |
6088 | switch (filedata->file_header.e_machine) | |
6089 | { | |
6090 | case EM_IA_64: | |
6091 | if (flag == SHF_IA_64_SHORT) | |
6092 | sindex = 10; | |
6093 | else if (flag == SHF_IA_64_NORECOV) | |
6094 | sindex = 11; | |
6095 | #ifdef BFD64 | |
6096 | else if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_OPENVMS) | |
6097 | switch (flag) | |
6098 | { | |
6099 | case SHF_IA_64_VMS_GLOBAL: sindex = 12; break; | |
6100 | case SHF_IA_64_VMS_OVERLAID: sindex = 13; break; | |
6101 | case SHF_IA_64_VMS_SHARED: sindex = 14; break; | |
6102 | case SHF_IA_64_VMS_VECTOR: sindex = 15; break; | |
6103 | case SHF_IA_64_VMS_ALLOC_64BIT: sindex = 16; break; | |
6104 | case SHF_IA_64_VMS_PROTECTED: sindex = 17; break; | |
6105 | default: break; | |
6106 | } | |
6107 | #endif | |
6108 | break; | |
6109 | ||
6110 | case EM_386: | |
6111 | case EM_IAMCU: | |
6112 | case EM_X86_64: | |
6113 | case EM_L1OM: | |
6114 | case EM_K1OM: | |
6115 | case EM_OLD_SPARCV9: | |
6116 | case EM_SPARC32PLUS: | |
6117 | case EM_SPARCV9: | |
6118 | case EM_SPARC: | |
6119 | if (flag == SHF_ORDERED) | |
6120 | sindex = 19; | |
6121 | break; | |
6122 | ||
6123 | case EM_ARM: | |
6124 | switch (flag) | |
6125 | { | |
6126 | case SHF_ENTRYSECT: sindex = 21; break; | |
6127 | case SHF_ARM_PURECODE: sindex = 22; break; | |
6128 | case SHF_COMDEF: sindex = 23; break; | |
6129 | default: break; | |
6130 | } | |
6131 | break; | |
6132 | case EM_PPC: | |
6133 | if (flag == SHF_PPC_VLE) | |
6134 | sindex = 25; | |
6135 | break; | |
6136 | default: | |
6137 | break; | |
6138 | } | |
6139 | ||
6140 | switch (filedata->file_header.e_ident[EI_OSABI]) | |
6141 | { | |
6142 | case ELFOSABI_GNU: | |
6143 | case ELFOSABI_FREEBSD: | |
6144 | if (flag == SHF_GNU_RETAIN) | |
6145 | sindex = 26; | |
6146 | /* Fall through */ | |
6147 | case ELFOSABI_NONE: | |
6148 | if (flag == SHF_GNU_MBIND) | |
6149 | /* We should not recognize SHF_GNU_MBIND for | |
6150 | ELFOSABI_NONE, but binutils as of 2019-07-23 did | |
6151 | not set the EI_OSABI header byte. */ | |
6152 | sindex = 24; | |
6153 | break; | |
6154 | default: | |
6155 | break; | |
6156 | } | |
6157 | break; | |
6158 | } | |
6159 | ||
6160 | if (sindex != -1) | |
6161 | { | |
6162 | if (p != buff + field_size + 4) | |
6163 | { | |
6164 | if (size < (10 + 2)) | |
6165 | { | |
6166 | warn (_("Internal error: not enough buffer room for section flag info")); | |
6167 | return _("<unknown>"); | |
6168 | } | |
6169 | size -= 2; | |
6170 | *p++ = ','; | |
6171 | *p++ = ' '; | |
6172 | } | |
6173 | ||
6174 | size -= flags [sindex].len; | |
6175 | p = stpcpy (p, flags [sindex].str); | |
6176 | } | |
6177 | else if (flag & SHF_MASKOS) | |
6178 | os_flags |= flag; | |
6179 | else if (flag & SHF_MASKPROC) | |
6180 | proc_flags |= flag; | |
6181 | else | |
6182 | unknown_flags |= flag; | |
6183 | } | |
6184 | else | |
6185 | { | |
6186 | switch (flag) | |
6187 | { | |
6188 | case SHF_WRITE: *p = 'W'; break; | |
6189 | case SHF_ALLOC: *p = 'A'; break; | |
6190 | case SHF_EXECINSTR: *p = 'X'; break; | |
6191 | case SHF_MERGE: *p = 'M'; break; | |
6192 | case SHF_STRINGS: *p = 'S'; break; | |
6193 | case SHF_INFO_LINK: *p = 'I'; break; | |
6194 | case SHF_LINK_ORDER: *p = 'L'; break; | |
6195 | case SHF_OS_NONCONFORMING: *p = 'O'; break; | |
6196 | case SHF_GROUP: *p = 'G'; break; | |
6197 | case SHF_TLS: *p = 'T'; break; | |
6198 | case SHF_EXCLUDE: *p = 'E'; break; | |
6199 | case SHF_COMPRESSED: *p = 'C'; break; | |
6200 | ||
6201 | default: | |
6202 | if ((filedata->file_header.e_machine == EM_X86_64 | |
6203 | || filedata->file_header.e_machine == EM_L1OM | |
6204 | || filedata->file_header.e_machine == EM_K1OM) | |
6205 | && flag == SHF_X86_64_LARGE) | |
6206 | *p = 'l'; | |
6207 | else if (filedata->file_header.e_machine == EM_ARM | |
6208 | && flag == SHF_ARM_PURECODE) | |
6209 | *p = 'y'; | |
6210 | else if (filedata->file_header.e_machine == EM_PPC | |
6211 | && flag == SHF_PPC_VLE) | |
6212 | *p = 'v'; | |
6213 | else if (flag & SHF_MASKOS) | |
6214 | { | |
6215 | switch (filedata->file_header.e_ident[EI_OSABI]) | |
6216 | { | |
6217 | case ELFOSABI_GNU: | |
6218 | case ELFOSABI_FREEBSD: | |
6219 | if (flag == SHF_GNU_RETAIN) | |
6220 | { | |
6221 | *p = 'R'; | |
6222 | break; | |
6223 | } | |
6224 | /* Fall through */ | |
6225 | case ELFOSABI_NONE: | |
6226 | if (flag == SHF_GNU_MBIND) | |
6227 | { | |
6228 | /* We should not recognize SHF_GNU_MBIND for | |
6229 | ELFOSABI_NONE, but binutils as of 2019-07-23 did | |
6230 | not set the EI_OSABI header byte. */ | |
6231 | *p = 'D'; | |
6232 | break; | |
6233 | } | |
6234 | /* Fall through */ | |
6235 | default: | |
6236 | *p = 'o'; | |
6237 | sh_flags &= ~SHF_MASKOS; | |
6238 | break; | |
6239 | } | |
6240 | } | |
6241 | else if (flag & SHF_MASKPROC) | |
6242 | { | |
6243 | *p = 'p'; | |
6244 | sh_flags &= ~ SHF_MASKPROC; | |
6245 | } | |
6246 | else | |
6247 | *p = 'x'; | |
6248 | break; | |
6249 | } | |
6250 | p++; | |
6251 | } | |
6252 | } | |
6253 | ||
6254 | if (do_section_details) | |
6255 | { | |
6256 | if (os_flags) | |
6257 | { | |
6258 | size -= 5 + field_size; | |
6259 | if (p != buff + field_size + 4) | |
6260 | { | |
6261 | if (size < (2 + 1)) | |
6262 | { | |
6263 | warn (_("Internal error: not enough buffer room for section flag info")); | |
6264 | return _("<unknown>"); | |
6265 | } | |
6266 | size -= 2; | |
6267 | *p++ = ','; | |
6268 | *p++ = ' '; | |
6269 | } | |
6270 | sprintf (p, "OS (%*.*lx)", field_size, field_size, | |
6271 | (unsigned long) os_flags); | |
6272 | p += 5 + field_size; | |
6273 | } | |
6274 | if (proc_flags) | |
6275 | { | |
6276 | size -= 7 + field_size; | |
6277 | if (p != buff + field_size + 4) | |
6278 | { | |
6279 | if (size < (2 + 1)) | |
6280 | { | |
6281 | warn (_("Internal error: not enough buffer room for section flag info")); | |
6282 | return _("<unknown>"); | |
6283 | } | |
6284 | size -= 2; | |
6285 | *p++ = ','; | |
6286 | *p++ = ' '; | |
6287 | } | |
6288 | sprintf (p, "PROC (%*.*lx)", field_size, field_size, | |
6289 | (unsigned long) proc_flags); | |
6290 | p += 7 + field_size; | |
6291 | } | |
6292 | if (unknown_flags) | |
6293 | { | |
6294 | size -= 10 + field_size; | |
6295 | if (p != buff + field_size + 4) | |
6296 | { | |
6297 | if (size < (2 + 1)) | |
6298 | { | |
6299 | warn (_("Internal error: not enough buffer room for section flag info")); | |
6300 | return _("<unknown>"); | |
6301 | } | |
6302 | size -= 2; | |
6303 | *p++ = ','; | |
6304 | *p++ = ' '; | |
6305 | } | |
6306 | sprintf (p, _("UNKNOWN (%*.*lx)"), field_size, field_size, | |
6307 | (unsigned long) unknown_flags); | |
6308 | p += 10 + field_size; | |
6309 | } | |
6310 | } | |
6311 | ||
6312 | *p = '\0'; | |
6313 | return buff; | |
6314 | } | |
6315 | ||
6316 | static unsigned int ATTRIBUTE_WARN_UNUSED_RESULT | |
6317 | get_compression_header (Elf_Internal_Chdr *chdr, unsigned char *buf, bfd_size_type size) | |
6318 | { | |
6319 | if (is_32bit_elf) | |
6320 | { | |
6321 | Elf32_External_Chdr *echdr = (Elf32_External_Chdr *) buf; | |
6322 | ||
6323 | if (size < sizeof (* echdr)) | |
6324 | { | |
6325 | error (_("Compressed section is too small even for a compression header\n")); | |
6326 | return 0; | |
6327 | } | |
6328 | ||
6329 | chdr->ch_type = BYTE_GET (echdr->ch_type); | |
6330 | chdr->ch_size = BYTE_GET (echdr->ch_size); | |
6331 | chdr->ch_addralign = BYTE_GET (echdr->ch_addralign); | |
6332 | return sizeof (*echdr); | |
6333 | } | |
6334 | else | |
6335 | { | |
6336 | Elf64_External_Chdr *echdr = (Elf64_External_Chdr *) buf; | |
6337 | ||
6338 | if (size < sizeof (* echdr)) | |
6339 | { | |
6340 | error (_("Compressed section is too small even for a compression header\n")); | |
6341 | return 0; | |
6342 | } | |
6343 | ||
6344 | chdr->ch_type = BYTE_GET (echdr->ch_type); | |
6345 | chdr->ch_size = BYTE_GET (echdr->ch_size); | |
6346 | chdr->ch_addralign = BYTE_GET (echdr->ch_addralign); | |
6347 | return sizeof (*echdr); | |
6348 | } | |
6349 | } | |
6350 | ||
6351 | static bfd_boolean | |
6352 | process_section_headers (Filedata * filedata) | |
6353 | { | |
6354 | Elf_Internal_Shdr * section; | |
6355 | unsigned int i; | |
6356 | ||
6357 | free (filedata->section_headers); | |
6358 | filedata->section_headers = NULL; | |
6359 | free (filedata->dynamic_symbols); | |
6360 | filedata->dynamic_symbols = NULL; | |
6361 | filedata->num_dynamic_syms = 0; | |
6362 | free (filedata->dynamic_strings); | |
6363 | filedata->dynamic_strings = NULL; | |
6364 | filedata->dynamic_strings_length = 0; | |
6365 | free (filedata->dynamic_syminfo); | |
6366 | filedata->dynamic_syminfo = NULL; | |
6367 | while (filedata->symtab_shndx_list != NULL) | |
6368 | { | |
6369 | elf_section_list *next = filedata->symtab_shndx_list->next; | |
6370 | free (filedata->symtab_shndx_list); | |
6371 | filedata->symtab_shndx_list = next; | |
6372 | } | |
6373 | ||
6374 | if (filedata->file_header.e_shnum == 0) | |
6375 | { | |
6376 | /* PR binutils/12467. */ | |
6377 | if (filedata->file_header.e_shoff != 0) | |
6378 | { | |
6379 | warn (_("possibly corrupt ELF file header - it has a non-zero" | |
6380 | " section header offset, but no section headers\n")); | |
6381 | return FALSE; | |
6382 | } | |
6383 | else if (do_sections) | |
6384 | printf (_("\nThere are no sections in this file.\n")); | |
6385 | ||
6386 | return TRUE; | |
6387 | } | |
6388 | ||
6389 | if (do_sections && !do_header) | |
6390 | { | |
6391 | if (filedata->is_separate && process_links) | |
6392 | printf (_("In linked file '%s': "), filedata->file_name); | |
6393 | if (! filedata->is_separate || process_links) | |
6394 | printf (ngettext ("There is %d section header, " | |
6395 | "starting at offset 0x%lx:\n", | |
6396 | "There are %d section headers, " | |
6397 | "starting at offset 0x%lx:\n", | |
6398 | filedata->file_header.e_shnum), | |
6399 | filedata->file_header.e_shnum, | |
6400 | (unsigned long) filedata->file_header.e_shoff); | |
6401 | } | |
6402 | ||
6403 | if (is_32bit_elf) | |
6404 | { | |
6405 | if (! get_32bit_section_headers (filedata, FALSE)) | |
6406 | return FALSE; | |
6407 | } | |
6408 | else | |
6409 | { | |
6410 | if (! get_64bit_section_headers (filedata, FALSE)) | |
6411 | return FALSE; | |
6412 | } | |
6413 | ||
6414 | /* Read in the string table, so that we have names to display. */ | |
6415 | if (filedata->file_header.e_shstrndx != SHN_UNDEF | |
6416 | && filedata->file_header.e_shstrndx < filedata->file_header.e_shnum) | |
6417 | { | |
6418 | section = filedata->section_headers + filedata->file_header.e_shstrndx; | |
6419 | ||
6420 | if (section->sh_size != 0) | |
6421 | { | |
6422 | filedata->string_table = (char *) get_data (NULL, filedata, section->sh_offset, | |
6423 | 1, section->sh_size, | |
6424 | _("string table")); | |
6425 | ||
6426 | filedata->string_table_length = filedata->string_table != NULL ? section->sh_size : 0; | |
6427 | } | |
6428 | } | |
6429 | ||
6430 | /* Scan the sections for the dynamic symbol table | |
6431 | and dynamic string table and debug sections. */ | |
6432 | eh_addr_size = is_32bit_elf ? 4 : 8; | |
6433 | switch (filedata->file_header.e_machine) | |
6434 | { | |
6435 | case EM_MIPS: | |
6436 | case EM_MIPS_RS3_LE: | |
6437 | /* The 64-bit MIPS EABI uses a combination of 32-bit ELF and 64-bit | |
6438 | FDE addresses. However, the ABI also has a semi-official ILP32 | |
6439 | variant for which the normal FDE address size rules apply. | |
6440 | ||
6441 | GCC 4.0 marks EABI64 objects with a dummy .gcc_compiled_longXX | |
6442 | section, where XX is the size of longs in bits. Unfortunately, | |
6443 | earlier compilers provided no way of distinguishing ILP32 objects | |
6444 | from LP64 objects, so if there's any doubt, we should assume that | |
6445 | the official LP64 form is being used. */ | |
6446 | if ((filedata->file_header.e_flags & EF_MIPS_ABI) == E_MIPS_ABI_EABI64 | |
6447 | && find_section (filedata, ".gcc_compiled_long32") == NULL) | |
6448 | eh_addr_size = 8; | |
6449 | break; | |
6450 | ||
6451 | case EM_H8_300: | |
6452 | case EM_H8_300H: | |
6453 | switch (filedata->file_header.e_flags & EF_H8_MACH) | |
6454 | { | |
6455 | case E_H8_MACH_H8300: | |
6456 | case E_H8_MACH_H8300HN: | |
6457 | case E_H8_MACH_H8300SN: | |
6458 | case E_H8_MACH_H8300SXN: | |
6459 | eh_addr_size = 2; | |
6460 | break; | |
6461 | case E_H8_MACH_H8300H: | |
6462 | case E_H8_MACH_H8300S: | |
6463 | case E_H8_MACH_H8300SX: | |
6464 | eh_addr_size = 4; | |
6465 | break; | |
6466 | } | |
6467 | break; | |
6468 | ||
6469 | case EM_M32C_OLD: | |
6470 | case EM_M32C: | |
6471 | switch (filedata->file_header.e_flags & EF_M32C_CPU_MASK) | |
6472 | { | |
6473 | case EF_M32C_CPU_M16C: | |
6474 | eh_addr_size = 2; | |
6475 | break; | |
6476 | } | |
6477 | break; | |
6478 | } | |
6479 | ||
6480 | #define CHECK_ENTSIZE_VALUES(section, i, size32, size64) \ | |
6481 | do \ | |
6482 | { \ | |
6483 | bfd_size_type expected_entsize = is_32bit_elf ? size32 : size64; \ | |
6484 | if (section->sh_entsize != expected_entsize) \ | |
6485 | { \ | |
6486 | char buf[40]; \ | |
6487 | sprintf_vma (buf, section->sh_entsize); \ | |
6488 | /* Note: coded this way so that there is a single string for \ | |
6489 | translation. */ \ | |
6490 | error (_("Section %d has invalid sh_entsize of %s\n"), i, buf); \ | |
6491 | error (_("(Using the expected size of %u for the rest of this dump)\n"), \ | |
6492 | (unsigned) expected_entsize); \ | |
6493 | section->sh_entsize = expected_entsize; \ | |
6494 | } \ | |
6495 | } \ | |
6496 | while (0) | |
6497 | ||
6498 | #define CHECK_ENTSIZE(section, i, type) \ | |
6499 | CHECK_ENTSIZE_VALUES (section, i, sizeof (Elf32_External_##type), \ | |
6500 | sizeof (Elf64_External_##type)) | |
6501 | ||
6502 | for (i = 0, section = filedata->section_headers; | |
6503 | i < filedata->file_header.e_shnum; | |
6504 | i++, section++) | |
6505 | { | |
6506 | char * name = SECTION_NAME_PRINT (section); | |
6507 | ||
6508 | /* Run some sanity checks on the headers and | |
6509 | possibly fill in some file data as well. */ | |
6510 | switch (section->sh_type) | |
6511 | { | |
6512 | case SHT_DYNSYM: | |
6513 | if (filedata->dynamic_symbols != NULL) | |
6514 | { | |
6515 | error (_("File contains multiple dynamic symbol tables\n")); | |
6516 | continue; | |
6517 | } | |
6518 | ||
6519 | CHECK_ENTSIZE (section, i, Sym); | |
6520 | filedata->dynamic_symbols | |
6521 | = GET_ELF_SYMBOLS (filedata, section, &filedata->num_dynamic_syms); | |
6522 | filedata->dynamic_symtab_section = section; | |
6523 | break; | |
6524 | ||
6525 | case SHT_STRTAB: | |
6526 | if (streq (name, ".dynstr")) | |
6527 | { | |
6528 | if (filedata->dynamic_strings != NULL) | |
6529 | { | |
6530 | error (_("File contains multiple dynamic string tables\n")); | |
6531 | continue; | |
6532 | } | |
6533 | ||
6534 | filedata->dynamic_strings | |
6535 | = (char *) get_data (NULL, filedata, section->sh_offset, | |
6536 | 1, section->sh_size, _("dynamic strings")); | |
6537 | filedata->dynamic_strings_length | |
6538 | = filedata->dynamic_strings == NULL ? 0 : section->sh_size; | |
6539 | filedata->dynamic_strtab_section = section; | |
6540 | } | |
6541 | break; | |
6542 | ||
6543 | case SHT_SYMTAB_SHNDX: | |
6544 | { | |
6545 | elf_section_list * entry = xmalloc (sizeof * entry); | |
6546 | ||
6547 | entry->hdr = section; | |
6548 | entry->next = filedata->symtab_shndx_list; | |
6549 | filedata->symtab_shndx_list = entry; | |
6550 | } | |
6551 | break; | |
6552 | ||
6553 | case SHT_SYMTAB: | |
6554 | CHECK_ENTSIZE (section, i, Sym); | |
6555 | break; | |
6556 | ||
6557 | case SHT_GROUP: | |
6558 | CHECK_ENTSIZE_VALUES (section, i, GRP_ENTRY_SIZE, GRP_ENTRY_SIZE); | |
6559 | break; | |
6560 | ||
6561 | case SHT_REL: | |
6562 | CHECK_ENTSIZE (section, i, Rel); | |
6563 | if (do_checks && section->sh_size == 0) | |
6564 | warn (_("Section '%s': zero-sized relocation section\n"), name); | |
6565 | break; | |
6566 | ||
6567 | case SHT_RELA: | |
6568 | CHECK_ENTSIZE (section, i, Rela); | |
6569 | if (do_checks && section->sh_size == 0) | |
6570 | warn (_("Section '%s': zero-sized relocation section\n"), name); | |
6571 | break; | |
6572 | ||
6573 | case SHT_NOTE: | |
6574 | case SHT_PROGBITS: | |
6575 | /* Having a zero sized section is not illegal according to the | |
6576 | ELF standard, but it might be an indication that something | |
6577 | is wrong. So issue a warning if we are running in lint mode. */ | |
6578 | if (do_checks && section->sh_size == 0) | |
6579 | warn (_("Section '%s': has a size of zero - is this intended ?\n"), name); | |
6580 | break; | |
6581 | ||
6582 | default: | |
6583 | break; | |
6584 | } | |
6585 | ||
6586 | if ((do_debugging || do_debug_info || do_debug_abbrevs | |
6587 | || do_debug_lines || do_debug_pubnames || do_debug_pubtypes | |
6588 | || do_debug_aranges || do_debug_frames || do_debug_macinfo | |
6589 | || do_debug_str || do_debug_str_offsets || do_debug_loc | |
6590 | || do_debug_ranges | |
6591 | || do_debug_addr || do_debug_cu_index || do_debug_links) | |
6592 | && (const_strneq (name, ".debug_") | |
6593 | || const_strneq (name, ".zdebug_"))) | |
6594 | { | |
6595 | if (name[1] == 'z') | |
6596 | name += sizeof (".zdebug_") - 1; | |
6597 | else | |
6598 | name += sizeof (".debug_") - 1; | |
6599 | ||
6600 | if (do_debugging | |
6601 | || (do_debug_info && const_strneq (name, "info")) | |
6602 | || (do_debug_info && const_strneq (name, "types")) | |
6603 | || (do_debug_abbrevs && const_strneq (name, "abbrev")) | |
6604 | || (do_debug_lines && strcmp (name, "line") == 0) | |
6605 | || (do_debug_lines && const_strneq (name, "line.")) | |
6606 | || (do_debug_pubnames && const_strneq (name, "pubnames")) | |
6607 | || (do_debug_pubtypes && const_strneq (name, "pubtypes")) | |
6608 | || (do_debug_pubnames && const_strneq (name, "gnu_pubnames")) | |
6609 | || (do_debug_pubtypes && const_strneq (name, "gnu_pubtypes")) | |
6610 | || (do_debug_aranges && const_strneq (name, "aranges")) | |
6611 | || (do_debug_ranges && const_strneq (name, "ranges")) | |
6612 | || (do_debug_ranges && const_strneq (name, "rnglists")) | |
6613 | || (do_debug_frames && const_strneq (name, "frame")) | |
6614 | || (do_debug_macinfo && const_strneq (name, "macinfo")) | |
6615 | || (do_debug_macinfo && const_strneq (name, "macro")) | |
6616 | || (do_debug_str && const_strneq (name, "str")) | |
6617 | || (do_debug_links && const_strneq (name, "sup")) | |
6618 | || (do_debug_str_offsets && const_strneq (name, "str_offsets")) | |
6619 | || (do_debug_loc && const_strneq (name, "loc")) | |
6620 | || (do_debug_loc && const_strneq (name, "loclists")) | |
6621 | || (do_debug_addr && const_strneq (name, "addr")) | |
6622 | || (do_debug_cu_index && const_strneq (name, "cu_index")) | |
6623 | || (do_debug_cu_index && const_strneq (name, "tu_index")) | |
6624 | ) | |
6625 | request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP); | |
6626 | } | |
6627 | /* Linkonce section to be combined with .debug_info at link time. */ | |
6628 | else if ((do_debugging || do_debug_info) | |
6629 | && const_strneq (name, ".gnu.linkonce.wi.")) | |
6630 | request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP); | |
6631 | else if (do_debug_frames && streq (name, ".eh_frame")) | |
6632 | request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP); | |
6633 | else if (do_gdb_index && (streq (name, ".gdb_index") | |
6634 | || streq (name, ".debug_names"))) | |
6635 | request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP); | |
6636 | /* Trace sections for Itanium VMS. */ | |
6637 | else if ((do_debugging || do_trace_info || do_trace_abbrevs | |
6638 | || do_trace_aranges) | |
6639 | && const_strneq (name, ".trace_")) | |
6640 | { | |
6641 | name += sizeof (".trace_") - 1; | |
6642 | ||
6643 | if (do_debugging | |
6644 | || (do_trace_info && streq (name, "info")) | |
6645 | || (do_trace_abbrevs && streq (name, "abbrev")) | |
6646 | || (do_trace_aranges && streq (name, "aranges")) | |
6647 | ) | |
6648 | request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP); | |
6649 | } | |
6650 | else if ((do_debugging || do_debug_links) | |
6651 | && (const_strneq (name, ".gnu_debuglink") | |
6652 | || const_strneq (name, ".gnu_debugaltlink"))) | |
6653 | request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP); | |
6654 | } | |
6655 | ||
6656 | if (! do_sections) | |
6657 | return TRUE; | |
6658 | ||
6659 | if (filedata->is_separate && ! process_links) | |
6660 | return TRUE; | |
6661 | ||
6662 | if (filedata->is_separate) | |
6663 | printf (_("\nSection Headers in linked file '%s':\n"), filedata->file_name); | |
6664 | else if (filedata->file_header.e_shnum > 1) | |
6665 | printf (_("\nSection Headers:\n")); | |
6666 | else | |
6667 | printf (_("\nSection Header:\n")); | |
6668 | ||
6669 | if (is_32bit_elf) | |
6670 | { | |
6671 | if (do_section_details) | |
6672 | { | |
6673 | printf (_(" [Nr] Name\n")); | |
6674 | printf (_(" Type Addr Off Size ES Lk Inf Al\n")); | |
6675 | } | |
6676 | else | |
6677 | printf | |
6678 | (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n")); | |
6679 | } | |
6680 | else if (do_wide) | |
6681 | { | |
6682 | if (do_section_details) | |
6683 | { | |
6684 | printf (_(" [Nr] Name\n")); | |
6685 | printf (_(" Type Address Off Size ES Lk Inf Al\n")); | |
6686 | } | |
6687 | else | |
6688 | printf | |
6689 | (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n")); | |
6690 | } | |
6691 | else | |
6692 | { | |
6693 | if (do_section_details) | |
6694 | { | |
6695 | printf (_(" [Nr] Name\n")); | |
6696 | printf (_(" Type Address Offset Link\n")); | |
6697 | printf (_(" Size EntSize Info Align\n")); | |
6698 | } | |
6699 | else | |
6700 | { | |
6701 | printf (_(" [Nr] Name Type Address Offset\n")); | |
6702 | printf (_(" Size EntSize Flags Link Info Align\n")); | |
6703 | } | |
6704 | } | |
6705 | ||
6706 | if (do_section_details) | |
6707 | printf (_(" Flags\n")); | |
6708 | ||
6709 | for (i = 0, section = filedata->section_headers; | |
6710 | i < filedata->file_header.e_shnum; | |
6711 | i++, section++) | |
6712 | { | |
6713 | /* Run some sanity checks on the section header. */ | |
6714 | ||
6715 | /* Check the sh_link field. */ | |
6716 | switch (section->sh_type) | |
6717 | { | |
6718 | case SHT_REL: | |
6719 | case SHT_RELA: | |
6720 | if (section->sh_link == 0 | |
6721 | && (filedata->file_header.e_type == ET_EXEC | |
6722 | || filedata->file_header.e_type == ET_DYN)) | |
6723 | /* A dynamic relocation section where all entries use a | |
6724 | zero symbol index need not specify a symtab section. */ | |
6725 | break; | |
6726 | /* Fall through. */ | |
6727 | case SHT_SYMTAB_SHNDX: | |
6728 | case SHT_GROUP: | |
6729 | case SHT_HASH: | |
6730 | case SHT_GNU_HASH: | |
6731 | case SHT_GNU_versym: | |
6732 | if (section->sh_link == 0 | |
6733 | || section->sh_link >= filedata->file_header.e_shnum | |
6734 | || (filedata->section_headers[section->sh_link].sh_type != SHT_SYMTAB | |
6735 | && filedata->section_headers[section->sh_link].sh_type != SHT_DYNSYM)) | |
6736 | warn (_("[%2u]: Link field (%u) should index a symtab section.\n"), | |
6737 | i, section->sh_link); | |
6738 | break; | |
6739 | ||
6740 | case SHT_DYNAMIC: | |
6741 | case SHT_SYMTAB: | |
6742 | case SHT_DYNSYM: | |
6743 | case SHT_GNU_verneed: | |
6744 | case SHT_GNU_verdef: | |
6745 | case SHT_GNU_LIBLIST: | |
6746 | if (section->sh_link == 0 | |
6747 | || section->sh_link >= filedata->file_header.e_shnum | |
6748 | || filedata->section_headers[section->sh_link].sh_type != SHT_STRTAB) | |
6749 | warn (_("[%2u]: Link field (%u) should index a string section.\n"), | |
6750 | i, section->sh_link); | |
6751 | break; | |
6752 | ||
6753 | case SHT_INIT_ARRAY: | |
6754 | case SHT_FINI_ARRAY: | |
6755 | case SHT_PREINIT_ARRAY: | |
6756 | if (section->sh_type < SHT_LOOS && section->sh_link != 0) | |
6757 | warn (_("[%2u]: Unexpected value (%u) in link field.\n"), | |
6758 | i, section->sh_link); | |
6759 | break; | |
6760 | ||
6761 | default: | |
6762 | /* FIXME: Add support for target specific section types. */ | |
6763 | #if 0 /* Currently we do not check other section types as there are too | |
6764 | many special cases. Stab sections for example have a type | |
6765 | of SHT_PROGBITS but an sh_link field that links to the .stabstr | |
6766 | section. */ | |
6767 | if (section->sh_type < SHT_LOOS && section->sh_link != 0) | |
6768 | warn (_("[%2u]: Unexpected value (%u) in link field.\n"), | |
6769 | i, section->sh_link); | |
6770 | #endif | |
6771 | break; | |
6772 | } | |
6773 | ||
6774 | /* Check the sh_info field. */ | |
6775 | switch (section->sh_type) | |
6776 | { | |
6777 | case SHT_REL: | |
6778 | case SHT_RELA: | |
6779 | if (section->sh_info == 0 | |
6780 | && (filedata->file_header.e_type == ET_EXEC | |
6781 | || filedata->file_header.e_type == ET_DYN)) | |
6782 | /* Dynamic relocations apply to segments, so they do not | |
6783 | need to specify the section they relocate. */ | |
6784 | break; | |
6785 | if (section->sh_info == 0 | |
6786 | || section->sh_info >= filedata->file_header.e_shnum | |
6787 | || (filedata->section_headers[section->sh_info].sh_type != SHT_PROGBITS | |
6788 | && filedata->section_headers[section->sh_info].sh_type != SHT_NOBITS | |
6789 | && filedata->section_headers[section->sh_info].sh_type != SHT_NOTE | |
6790 | && filedata->section_headers[section->sh_info].sh_type != SHT_INIT_ARRAY | |
6791 | && filedata->section_headers[section->sh_info].sh_type != SHT_FINI_ARRAY | |
6792 | && filedata->section_headers[section->sh_info].sh_type != SHT_PREINIT_ARRAY | |
6793 | /* FIXME: Are other section types valid ? */ | |
6794 | && filedata->section_headers[section->sh_info].sh_type < SHT_LOOS)) | |
6795 | warn (_("[%2u]: Info field (%u) should index a relocatable section.\n"), | |
6796 | i, section->sh_info); | |
6797 | break; | |
6798 | ||
6799 | case SHT_DYNAMIC: | |
6800 | case SHT_HASH: | |
6801 | case SHT_SYMTAB_SHNDX: | |
6802 | case SHT_INIT_ARRAY: | |
6803 | case SHT_FINI_ARRAY: | |
6804 | case SHT_PREINIT_ARRAY: | |
6805 | if (section->sh_info != 0) | |
6806 | warn (_("[%2u]: Unexpected value (%u) in info field.\n"), | |
6807 | i, section->sh_info); | |
6808 | break; | |
6809 | ||
6810 | case SHT_GROUP: | |
6811 | case SHT_SYMTAB: | |
6812 | case SHT_DYNSYM: | |
6813 | /* A symbol index - we assume that it is valid. */ | |
6814 | break; | |
6815 | ||
6816 | default: | |
6817 | /* FIXME: Add support for target specific section types. */ | |
6818 | if (section->sh_type == SHT_NOBITS) | |
6819 | /* NOBITS section headers with non-zero sh_info fields can be | |
6820 | created when a binary is stripped of everything but its debug | |
6821 | information. The stripped sections have their headers | |
6822 | preserved but their types set to SHT_NOBITS. So do not check | |
6823 | this type of section. */ | |
6824 | ; | |
6825 | else if (section->sh_flags & SHF_INFO_LINK) | |
6826 | { | |
6827 | if (section->sh_info < 1 || section->sh_info >= filedata->file_header.e_shnum) | |
6828 | warn (_("[%2u]: Expected link to another section in info field"), i); | |
6829 | } | |
6830 | else if (section->sh_type < SHT_LOOS | |
6831 | && (section->sh_flags & SHF_GNU_MBIND) == 0 | |
6832 | && section->sh_info != 0) | |
6833 | warn (_("[%2u]: Unexpected value (%u) in info field.\n"), | |
6834 | i, section->sh_info); | |
6835 | break; | |
6836 | } | |
6837 | ||
6838 | /* Check the sh_size field. */ | |
6839 | if (section->sh_size > filedata->file_size | |
6840 | && section->sh_type != SHT_NOBITS | |
6841 | && section->sh_type != SHT_NULL | |
6842 | && section->sh_type < SHT_LOOS) | |
6843 | warn (_("Size of section %u is larger than the entire file!\n"), i); | |
6844 | ||
6845 | printf (" [%2u] ", i); | |
6846 | if (do_section_details) | |
6847 | printf ("%s\n ", printable_section_name (filedata, section)); | |
6848 | else | |
6849 | print_symbol (-17, SECTION_NAME_PRINT (section)); | |
6850 | ||
6851 | printf (do_wide ? " %-15s " : " %-15.15s ", | |
6852 | get_section_type_name (filedata, section->sh_type)); | |
6853 | ||
6854 | if (is_32bit_elf) | |
6855 | { | |
6856 | const char * link_too_big = NULL; | |
6857 | ||
6858 | print_vma (section->sh_addr, LONG_HEX); | |
6859 | ||
6860 | printf ( " %6.6lx %6.6lx %2.2lx", | |
6861 | (unsigned long) section->sh_offset, | |
6862 | (unsigned long) section->sh_size, | |
6863 | (unsigned long) section->sh_entsize); | |
6864 | ||
6865 | if (do_section_details) | |
6866 | fputs (" ", stdout); | |
6867 | else | |
6868 | printf (" %3s ", get_elf_section_flags (filedata, section->sh_flags)); | |
6869 | ||
6870 | if (section->sh_link >= filedata->file_header.e_shnum) | |
6871 | { | |
6872 | link_too_big = ""; | |
6873 | /* The sh_link value is out of range. Normally this indicates | |
6874 | an error but it can have special values in Solaris binaries. */ | |
6875 | switch (filedata->file_header.e_machine) | |
6876 | { | |
6877 | case EM_386: | |
6878 | case EM_IAMCU: | |
6879 | case EM_X86_64: | |
6880 | case EM_L1OM: | |
6881 | case EM_K1OM: | |
6882 | case EM_OLD_SPARCV9: | |
6883 | case EM_SPARC32PLUS: | |
6884 | case EM_SPARCV9: | |
6885 | case EM_SPARC: | |
6886 | if (section->sh_link == (SHN_BEFORE & 0xffff)) | |
6887 | link_too_big = "BEFORE"; | |
6888 | else if (section->sh_link == (SHN_AFTER & 0xffff)) | |
6889 | link_too_big = "AFTER"; | |
6890 | break; | |
6891 | default: | |
6892 | break; | |
6893 | } | |
6894 | } | |
6895 | ||
6896 | if (do_section_details) | |
6897 | { | |
6898 | if (link_too_big != NULL && * link_too_big) | |
6899 | printf ("<%s> ", link_too_big); | |
6900 | else | |
6901 | printf ("%2u ", section->sh_link); | |
6902 | printf ("%3u %2lu\n", section->sh_info, | |
6903 | (unsigned long) section->sh_addralign); | |
6904 | } | |
6905 | else | |
6906 | printf ("%2u %3u %2lu\n", | |
6907 | section->sh_link, | |
6908 | section->sh_info, | |
6909 | (unsigned long) section->sh_addralign); | |
6910 | ||
6911 | if (link_too_big && ! * link_too_big) | |
6912 | warn (_("section %u: sh_link value of %u is larger than the number of sections\n"), | |
6913 | i, section->sh_link); | |
6914 | } | |
6915 | else if (do_wide) | |
6916 | { | |
6917 | print_vma (section->sh_addr, LONG_HEX); | |
6918 | ||
6919 | if ((long) section->sh_offset == section->sh_offset) | |
6920 | printf (" %6.6lx", (unsigned long) section->sh_offset); | |
6921 | else | |
6922 | { | |
6923 | putchar (' '); | |
6924 | print_vma (section->sh_offset, LONG_HEX); | |
6925 | } | |
6926 | ||
6927 | if ((unsigned long) section->sh_size == section->sh_size) | |
6928 | printf (" %6.6lx", (unsigned long) section->sh_size); | |
6929 | else | |
6930 | { | |
6931 | putchar (' '); | |
6932 | print_vma (section->sh_size, LONG_HEX); | |
6933 | } | |
6934 | ||
6935 | if ((unsigned long) section->sh_entsize == section->sh_entsize) | |
6936 | printf (" %2.2lx", (unsigned long) section->sh_entsize); | |
6937 | else | |
6938 | { | |
6939 | putchar (' '); | |
6940 | print_vma (section->sh_entsize, LONG_HEX); | |
6941 | } | |
6942 | ||
6943 | if (do_section_details) | |
6944 | fputs (" ", stdout); | |
6945 | else | |
6946 | printf (" %3s ", get_elf_section_flags (filedata, section->sh_flags)); | |
6947 | ||
6948 | printf ("%2u %3u ", section->sh_link, section->sh_info); | |
6949 | ||
6950 | if ((unsigned long) section->sh_addralign == section->sh_addralign) | |
6951 | printf ("%2lu\n", (unsigned long) section->sh_addralign); | |
6952 | else | |
6953 | { | |
6954 | print_vma (section->sh_addralign, DEC); | |
6955 | putchar ('\n'); | |
6956 | } | |
6957 | } | |
6958 | else if (do_section_details) | |
6959 | { | |
6960 | putchar (' '); | |
6961 | print_vma (section->sh_addr, LONG_HEX); | |
6962 | if ((long) section->sh_offset == section->sh_offset) | |
6963 | printf (" %16.16lx", (unsigned long) section->sh_offset); | |
6964 | else | |
6965 | { | |
6966 | printf (" "); | |
6967 | print_vma (section->sh_offset, LONG_HEX); | |
6968 | } | |
6969 | printf (" %u\n ", section->sh_link); | |
6970 | print_vma (section->sh_size, LONG_HEX); | |
6971 | putchar (' '); | |
6972 | print_vma (section->sh_entsize, LONG_HEX); | |
6973 | ||
6974 | printf (" %-16u %lu\n", | |
6975 | section->sh_info, | |
6976 | (unsigned long) section->sh_addralign); | |
6977 | } | |
6978 | else | |
6979 | { | |
6980 | putchar (' '); | |
6981 | print_vma (section->sh_addr, LONG_HEX); | |
6982 | if ((long) section->sh_offset == section->sh_offset) | |
6983 | printf (" %8.8lx", (unsigned long) section->sh_offset); | |
6984 | else | |
6985 | { | |
6986 | printf (" "); | |
6987 | print_vma (section->sh_offset, LONG_HEX); | |
6988 | } | |
6989 | printf ("\n "); | |
6990 | print_vma (section->sh_size, LONG_HEX); | |
6991 | printf (" "); | |
6992 | print_vma (section->sh_entsize, LONG_HEX); | |
6993 | ||
6994 | printf (" %3s ", get_elf_section_flags (filedata, section->sh_flags)); | |
6995 | ||
6996 | printf (" %2u %3u %lu\n", | |
6997 | section->sh_link, | |
6998 | section->sh_info, | |
6999 | (unsigned long) section->sh_addralign); | |
7000 | } | |
7001 | ||
7002 | if (do_section_details) | |
7003 | { | |
7004 | printf (" %s\n", get_elf_section_flags (filedata, section->sh_flags)); | |
7005 | if ((section->sh_flags & SHF_COMPRESSED) != 0) | |
7006 | { | |
7007 | /* Minimum section size is 12 bytes for 32-bit compression | |
7008 | header + 12 bytes for compressed data header. */ | |
7009 | unsigned char buf[24]; | |
7010 | ||
7011 | assert (sizeof (buf) >= sizeof (Elf64_External_Chdr)); | |
7012 | if (get_data (&buf, filedata, section->sh_offset, 1, | |
7013 | sizeof (buf), _("compression header"))) | |
7014 | { | |
7015 | Elf_Internal_Chdr chdr; | |
7016 | ||
7017 | if (get_compression_header (&chdr, buf, sizeof (buf)) == 0) | |
7018 | printf (_(" [<corrupt>]\n")); | |
7019 | else | |
7020 | { | |
7021 | if (chdr.ch_type == ELFCOMPRESS_ZLIB) | |
7022 | printf (" ZLIB, "); | |
7023 | else | |
7024 | printf (_(" [<unknown>: 0x%x], "), | |
7025 | chdr.ch_type); | |
7026 | print_vma (chdr.ch_size, LONG_HEX); | |
7027 | printf (", %lu\n", (unsigned long) chdr.ch_addralign); | |
7028 | } | |
7029 | } | |
7030 | } | |
7031 | } | |
7032 | } | |
7033 | ||
7034 | if (!do_section_details) | |
7035 | { | |
7036 | /* The ordering of the letters shown here matches the ordering of the | |
7037 | corresponding SHF_xxx values, and hence the order in which these | |
7038 | letters will be displayed to the user. */ | |
7039 | printf (_("Key to Flags:\n\ | |
7040 | W (write), A (alloc), X (execute), M (merge), S (strings), I (info),\n\ | |
7041 | L (link order), O (extra OS processing required), G (group), T (TLS),\n\ | |
7042 | C (compressed), x (unknown), o (OS specific), E (exclude),\n ")); | |
7043 | switch (filedata->file_header.e_ident[EI_OSABI]) | |
7044 | { | |
7045 | case ELFOSABI_GNU: | |
7046 | case ELFOSABI_FREEBSD: | |
7047 | printf (_("R (retain), ")); | |
7048 | /* Fall through */ | |
7049 | case ELFOSABI_NONE: | |
7050 | printf (_("D (mbind), ")); | |
7051 | break; | |
7052 | default: | |
7053 | break; | |
7054 | } | |
7055 | if (filedata->file_header.e_machine == EM_X86_64 | |
7056 | || filedata->file_header.e_machine == EM_L1OM | |
7057 | || filedata->file_header.e_machine == EM_K1OM) | |
7058 | printf (_("l (large), ")); | |
7059 | else if (filedata->file_header.e_machine == EM_ARM) | |
7060 | printf (_("y (purecode), ")); | |
7061 | else if (filedata->file_header.e_machine == EM_PPC) | |
7062 | printf (_("v (VLE), ")); | |
7063 | printf ("p (processor specific)\n"); | |
7064 | } | |
7065 | ||
7066 | return TRUE; | |
7067 | } | |
7068 | ||
7069 | static bfd_boolean | |
7070 | get_symtab (Filedata *filedata, Elf_Internal_Shdr *symsec, | |
7071 | Elf_Internal_Sym **symtab, unsigned long *nsyms, | |
7072 | char **strtab, unsigned long *strtablen) | |
7073 | { | |
7074 | *strtab = NULL; | |
7075 | *strtablen = 0; | |
7076 | *symtab = GET_ELF_SYMBOLS (filedata, symsec, nsyms); | |
7077 | ||
7078 | if (*symtab == NULL) | |
7079 | return FALSE; | |
7080 | ||
7081 | if (symsec->sh_link != 0) | |
7082 | { | |
7083 | Elf_Internal_Shdr *strsec; | |
7084 | ||
7085 | if (symsec->sh_link >= filedata->file_header.e_shnum) | |
7086 | { | |
7087 | error (_("Bad sh_link in symbol table section\n")); | |
7088 | free (*symtab); | |
7089 | *symtab = NULL; | |
7090 | *nsyms = 0; | |
7091 | return FALSE; | |
7092 | } | |
7093 | ||
7094 | strsec = filedata->section_headers + symsec->sh_link; | |
7095 | ||
7096 | *strtab = (char *) get_data (NULL, filedata, strsec->sh_offset, | |
7097 | 1, strsec->sh_size, _("string table")); | |
7098 | if (*strtab == NULL) | |
7099 | { | |
7100 | free (*symtab); | |
7101 | *symtab = NULL; | |
7102 | *nsyms = 0; | |
7103 | return FALSE; | |
7104 | } | |
7105 | *strtablen = strsec->sh_size; | |
7106 | } | |
7107 | return TRUE; | |
7108 | } | |
7109 | ||
7110 | static const char * | |
7111 | get_group_flags (unsigned int flags) | |
7112 | { | |
7113 | static char buff[128]; | |
7114 | ||
7115 | if (flags == 0) | |
7116 | return ""; | |
7117 | else if (flags == GRP_COMDAT) | |
7118 | return "COMDAT "; | |
7119 | ||
7120 | snprintf (buff, sizeof buff, "[0x%x: %s%s%s]", | |
7121 | flags, | |
7122 | flags & GRP_MASKOS ? _("<OS specific>") : "", | |
7123 | flags & GRP_MASKPROC ? _("<PROC specific>") : "", | |
7124 | (flags & ~(GRP_COMDAT | GRP_MASKOS | GRP_MASKPROC) | |
7125 | ? _("<unknown>") : "")); | |
7126 | ||
7127 | return buff; | |
7128 | } | |
7129 | ||
7130 | static bfd_boolean | |
7131 | process_section_groups (Filedata * filedata) | |
7132 | { | |
7133 | Elf_Internal_Shdr * section; | |
7134 | unsigned int i; | |
7135 | struct group * group; | |
7136 | Elf_Internal_Shdr * symtab_sec; | |
7137 | Elf_Internal_Shdr * strtab_sec; | |
7138 | Elf_Internal_Sym * symtab; | |
7139 | unsigned long num_syms; | |
7140 | char * strtab; | |
7141 | size_t strtab_size; | |
7142 | ||
7143 | /* Don't process section groups unless needed. */ | |
7144 | if (!do_unwind && !do_section_groups) | |
7145 | return TRUE; | |
7146 | ||
7147 | if (filedata->file_header.e_shnum == 0) | |
7148 | { | |
7149 | if (do_section_groups) | |
7150 | { | |
7151 | if (filedata->is_separate) | |
7152 | printf (_("\nThere are no sections group in linked file '%s'.\n"), | |
7153 | filedata->file_name); | |
7154 | else | |
7155 | printf (_("\nThere are no section groups in this file.\n")); | |
7156 | } | |
7157 | return TRUE; | |
7158 | } | |
7159 | ||
7160 | if (filedata->section_headers == NULL) | |
7161 | { | |
7162 | error (_("Section headers are not available!\n")); | |
7163 | /* PR 13622: This can happen with a corrupt ELF header. */ | |
7164 | return FALSE; | |
7165 | } | |
7166 | ||
7167 | filedata->section_headers_groups | |
7168 | = (struct group **) calloc (filedata->file_header.e_shnum, | |
7169 | sizeof (struct group *)); | |
7170 | ||
7171 | if (filedata->section_headers_groups == NULL) | |
7172 | { | |
7173 | error (_("Out of memory reading %u section group headers\n"), | |
7174 | filedata->file_header.e_shnum); | |
7175 | return FALSE; | |
7176 | } | |
7177 | ||
7178 | /* Scan the sections for the group section. */ | |
7179 | filedata->group_count = 0; | |
7180 | for (i = 0, section = filedata->section_headers; | |
7181 | i < filedata->file_header.e_shnum; | |
7182 | i++, section++) | |
7183 | if (section->sh_type == SHT_GROUP) | |
7184 | filedata->group_count++; | |
7185 | ||
7186 | if (filedata->group_count == 0) | |
7187 | { | |
7188 | if (do_section_groups) | |
7189 | { | |
7190 | if (filedata->is_separate) | |
7191 | printf (_("\nThere are no section groups in linked file '%s'.\n"), | |
7192 | filedata->file_name); | |
7193 | else | |
7194 | printf (_("\nThere are no section groups in this file.\n")); | |
7195 | } | |
7196 | ||
7197 | return TRUE; | |
7198 | } | |
7199 | ||
7200 | filedata->section_groups = (struct group *) calloc (filedata->group_count, | |
7201 | sizeof (struct group)); | |
7202 | ||
7203 | if (filedata->section_groups == NULL) | |
7204 | { | |
7205 | error (_("Out of memory reading %lu groups\n"), | |
7206 | (unsigned long) filedata->group_count); | |
7207 | return FALSE; | |
7208 | } | |
7209 | ||
7210 | symtab_sec = NULL; | |
7211 | strtab_sec = NULL; | |
7212 | symtab = NULL; | |
7213 | num_syms = 0; | |
7214 | strtab = NULL; | |
7215 | strtab_size = 0; | |
7216 | ||
7217 | if (filedata->is_separate) | |
7218 | printf (_("Section groups in linked file '%s'\n"), filedata->file_name); | |
7219 | ||
7220 | for (i = 0, section = filedata->section_headers, group = filedata->section_groups; | |
7221 | i < filedata->file_header.e_shnum; | |
7222 | i++, section++) | |
7223 | { | |
7224 | if (section->sh_type == SHT_GROUP) | |
7225 | { | |
7226 | const char * name = printable_section_name (filedata, section); | |
7227 | const char * group_name; | |
7228 | unsigned char * start; | |
7229 | unsigned char * indices; | |
7230 | unsigned int entry, j, size; | |
7231 | Elf_Internal_Shdr * sec; | |
7232 | Elf_Internal_Sym * sym; | |
7233 | ||
7234 | /* Get the symbol table. */ | |
7235 | if (section->sh_link >= filedata->file_header.e_shnum | |
7236 | || ((sec = filedata->section_headers + section->sh_link)->sh_type | |
7237 | != SHT_SYMTAB)) | |
7238 | { | |
7239 | error (_("Bad sh_link in group section `%s'\n"), name); | |
7240 | continue; | |
7241 | } | |
7242 | ||
7243 | if (symtab_sec != sec) | |
7244 | { | |
7245 | symtab_sec = sec; | |
7246 | free (symtab); | |
7247 | symtab = GET_ELF_SYMBOLS (filedata, symtab_sec, & num_syms); | |
7248 | } | |
7249 | ||
7250 | if (symtab == NULL) | |
7251 | { | |
7252 | error (_("Corrupt header in group section `%s'\n"), name); | |
7253 | continue; | |
7254 | } | |
7255 | ||
7256 | if (section->sh_info >= num_syms) | |
7257 | { | |
7258 | error (_("Bad sh_info in group section `%s'\n"), name); | |
7259 | continue; | |
7260 | } | |
7261 | ||
7262 | sym = symtab + section->sh_info; | |
7263 | ||
7264 | if (ELF_ST_TYPE (sym->st_info) == STT_SECTION) | |
7265 | { | |
7266 | if (sym->st_shndx == 0 | |
7267 | || sym->st_shndx >= filedata->file_header.e_shnum) | |
7268 | { | |
7269 | error (_("Bad sh_info in group section `%s'\n"), name); | |
7270 | continue; | |
7271 | } | |
7272 | ||
7273 | group_name = SECTION_NAME_PRINT (filedata->section_headers | |
7274 | + sym->st_shndx); | |
7275 | strtab_sec = NULL; | |
7276 | free (strtab); | |
7277 | strtab = NULL; | |
7278 | strtab_size = 0; | |
7279 | } | |
7280 | else | |
7281 | { | |
7282 | /* Get the string table. */ | |
7283 | if (symtab_sec->sh_link >= filedata->file_header.e_shnum) | |
7284 | { | |
7285 | strtab_sec = NULL; | |
7286 | free (strtab); | |
7287 | strtab = NULL; | |
7288 | strtab_size = 0; | |
7289 | } | |
7290 | else if (strtab_sec | |
7291 | != (sec = filedata->section_headers + symtab_sec->sh_link)) | |
7292 | { | |
7293 | strtab_sec = sec; | |
7294 | free (strtab); | |
7295 | ||
7296 | strtab = (char *) get_data (NULL, filedata, strtab_sec->sh_offset, | |
7297 | 1, strtab_sec->sh_size, | |
7298 | _("string table")); | |
7299 | strtab_size = strtab != NULL ? strtab_sec->sh_size : 0; | |
7300 | } | |
7301 | group_name = sym->st_name < strtab_size | |
7302 | ? strtab + sym->st_name : _("<corrupt>"); | |
7303 | } | |
7304 | ||
7305 | /* PR 17531: file: loop. */ | |
7306 | if (section->sh_entsize > section->sh_size) | |
7307 | { | |
7308 | error (_("Section %s has sh_entsize (0x%lx) which is larger than its size (0x%lx)\n"), | |
7309 | printable_section_name (filedata, section), | |
7310 | (unsigned long) section->sh_entsize, | |
7311 | (unsigned long) section->sh_size); | |
7312 | continue; | |
7313 | } | |
7314 | ||
7315 | start = (unsigned char *) get_data (NULL, filedata, section->sh_offset, | |
7316 | 1, section->sh_size, | |
7317 | _("section data")); | |
7318 | if (start == NULL) | |
7319 | continue; | |
7320 | ||
7321 | indices = start; | |
7322 | size = (section->sh_size / section->sh_entsize) - 1; | |
7323 | entry = byte_get (indices, 4); | |
7324 | indices += 4; | |
7325 | ||
7326 | if (do_section_groups) | |
7327 | { | |
7328 | printf (_("\n%sgroup section [%5u] `%s' [%s] contains %u sections:\n"), | |
7329 | get_group_flags (entry), i, name, group_name, size); | |
7330 | ||
7331 | printf (_(" [Index] Name\n")); | |
7332 | } | |
7333 | ||
7334 | group->group_index = i; | |
7335 | ||
7336 | for (j = 0; j < size; j++) | |
7337 | { | |
7338 | struct group_list * g; | |
7339 | ||
7340 | entry = byte_get (indices, 4); | |
7341 | indices += 4; | |
7342 | ||
7343 | if (entry >= filedata->file_header.e_shnum) | |
7344 | { | |
7345 | static unsigned num_group_errors = 0; | |
7346 | ||
7347 | if (num_group_errors ++ < 10) | |
7348 | { | |
7349 | error (_("section [%5u] in group section [%5u] > maximum section [%5u]\n"), | |
7350 | entry, i, filedata->file_header.e_shnum - 1); | |
7351 | if (num_group_errors == 10) | |
7352 | warn (_("Further error messages about overlarge group section indices suppressed\n")); | |
7353 | } | |
7354 | continue; | |
7355 | } | |
7356 | ||
7357 | if (filedata->section_headers_groups [entry] != NULL) | |
7358 | { | |
7359 | if (entry) | |
7360 | { | |
7361 | static unsigned num_errs = 0; | |
7362 | ||
7363 | if (num_errs ++ < 10) | |
7364 | { | |
7365 | error (_("section [%5u] in group section [%5u] already in group section [%5u]\n"), | |
7366 | entry, i, | |
7367 | filedata->section_headers_groups [entry]->group_index); | |
7368 | if (num_errs == 10) | |
7369 | warn (_("Further error messages about already contained group sections suppressed\n")); | |
7370 | } | |
7371 | continue; | |
7372 | } | |
7373 | else | |
7374 | { | |
7375 | /* Intel C/C++ compiler may put section 0 in a | |
7376 | section group. We just warn it the first time | |
7377 | and ignore it afterwards. */ | |
7378 | static bfd_boolean warned = FALSE; | |
7379 | if (!warned) | |
7380 | { | |
7381 | error (_("section 0 in group section [%5u]\n"), | |
7382 | filedata->section_headers_groups [entry]->group_index); | |
7383 | warned = TRUE; | |
7384 | } | |
7385 | } | |
7386 | } | |
7387 | ||
7388 | filedata->section_headers_groups [entry] = group; | |
7389 | ||
7390 | if (do_section_groups) | |
7391 | { | |
7392 | sec = filedata->section_headers + entry; | |
7393 | printf (" [%5u] %s\n", entry, printable_section_name (filedata, sec)); | |
7394 | } | |
7395 | ||
7396 | g = (struct group_list *) xmalloc (sizeof (struct group_list)); | |
7397 | g->section_index = entry; | |
7398 | g->next = group->root; | |
7399 | group->root = g; | |
7400 | } | |
7401 | ||
7402 | free (start); | |
7403 | ||
7404 | group++; | |
7405 | } | |
7406 | } | |
7407 | ||
7408 | free (symtab); | |
7409 | free (strtab); | |
7410 | return TRUE; | |
7411 | } | |
7412 | ||
7413 | /* Data used to display dynamic fixups. */ | |
7414 | ||
7415 | struct ia64_vms_dynfixup | |
7416 | { | |
7417 | bfd_vma needed_ident; /* Library ident number. */ | |
7418 | bfd_vma needed; /* Index in the dstrtab of the library name. */ | |
7419 | bfd_vma fixup_needed; /* Index of the library. */ | |
7420 | bfd_vma fixup_rela_cnt; /* Number of fixups. */ | |
7421 | bfd_vma fixup_rela_off; /* Fixups offset in the dynamic segment. */ | |
7422 | }; | |
7423 | ||
7424 | /* Data used to display dynamic relocations. */ | |
7425 | ||
7426 | struct ia64_vms_dynimgrela | |
7427 | { | |
7428 | bfd_vma img_rela_cnt; /* Number of relocations. */ | |
7429 | bfd_vma img_rela_off; /* Reloc offset in the dynamic segment. */ | |
7430 | }; | |
7431 | ||
7432 | /* Display IA-64 OpenVMS dynamic fixups (used to dynamically link a shared | |
7433 | library). */ | |
7434 | ||
7435 | static bfd_boolean | |
7436 | dump_ia64_vms_dynamic_fixups (Filedata * filedata, | |
7437 | struct ia64_vms_dynfixup * fixup, | |
7438 | const char * strtab, | |
7439 | unsigned int strtab_sz) | |
7440 | { | |
7441 | Elf64_External_VMS_IMAGE_FIXUP * imfs; | |
7442 | long i; | |
7443 | const char * lib_name; | |
7444 | ||
7445 | imfs = get_data (NULL, filedata, | |
7446 | filedata->dynamic_addr + fixup->fixup_rela_off, | |
7447 | sizeof (*imfs), fixup->fixup_rela_cnt, | |
7448 | _("dynamic section image fixups")); | |
7449 | if (!imfs) | |
7450 | return FALSE; | |
7451 | ||
7452 | if (fixup->needed < strtab_sz) | |
7453 | lib_name = strtab + fixup->needed; | |
7454 | else | |
7455 | { | |
7456 | warn (_("corrupt library name index of 0x%lx found in dynamic entry"), | |
7457 | (unsigned long) fixup->needed); | |
7458 | lib_name = "???"; | |
7459 | } | |
7460 | ||
7461 | printf (_("\nImage fixups for needed library #%d: %s - ident: %lx\n"), | |
7462 | (int) fixup->fixup_needed, lib_name, (long) fixup->needed_ident); | |
7463 | printf | |
7464 | (_("Seg Offset Type SymVec DataType\n")); | |
7465 | ||
7466 | for (i = 0; i < (long) fixup->fixup_rela_cnt; i++) | |
7467 | { | |
7468 | unsigned int type; | |
7469 | const char *rtype; | |
7470 | ||
7471 | printf ("%3u ", (unsigned) BYTE_GET (imfs [i].fixup_seg)); | |
7472 | printf_vma ((bfd_vma) BYTE_GET (imfs [i].fixup_offset)); | |
7473 | type = BYTE_GET (imfs [i].type); | |
7474 | rtype = elf_ia64_reloc_type (type); | |
7475 | if (rtype == NULL) | |
7476 | printf (" 0x%08x ", type); | |
7477 | else | |
7478 | printf (" %-32s ", rtype); | |
7479 | printf ("%6u ", (unsigned) BYTE_GET (imfs [i].symvec_index)); | |
7480 | printf ("0x%08x\n", (unsigned) BYTE_GET (imfs [i].data_type)); | |
7481 | } | |
7482 | ||
7483 | free (imfs); | |
7484 | return TRUE; | |
7485 | } | |
7486 | ||
7487 | /* Display IA-64 OpenVMS dynamic relocations (used to relocate an image). */ | |
7488 | ||
7489 | static bfd_boolean | |
7490 | dump_ia64_vms_dynamic_relocs (Filedata * filedata, struct ia64_vms_dynimgrela *imgrela) | |
7491 | { | |
7492 | Elf64_External_VMS_IMAGE_RELA *imrs; | |
7493 | long i; | |
7494 | ||
7495 | imrs = get_data (NULL, filedata, | |
7496 | filedata->dynamic_addr + imgrela->img_rela_off, | |
7497 | sizeof (*imrs), imgrela->img_rela_cnt, | |
7498 | _("dynamic section image relocations")); | |
7499 | if (!imrs) | |
7500 | return FALSE; | |
7501 | ||
7502 | printf (_("\nImage relocs\n")); | |
7503 | printf | |
7504 | (_("Seg Offset Type Addend Seg Sym Off\n")); | |
7505 | ||
7506 | for (i = 0; i < (long) imgrela->img_rela_cnt; i++) | |
7507 | { | |
7508 | unsigned int type; | |
7509 | const char *rtype; | |
7510 | ||
7511 | printf ("%3u ", (unsigned) BYTE_GET (imrs [i].rela_seg)); | |
7512 | printf ("%08" BFD_VMA_FMT "x ", | |
7513 | (bfd_vma) BYTE_GET (imrs [i].rela_offset)); | |
7514 | type = BYTE_GET (imrs [i].type); | |
7515 | rtype = elf_ia64_reloc_type (type); | |
7516 | if (rtype == NULL) | |
7517 | printf ("0x%08x ", type); | |
7518 | else | |
7519 | printf ("%-31s ", rtype); | |
7520 | print_vma (BYTE_GET (imrs [i].addend), FULL_HEX); | |
7521 | printf ("%3u ", (unsigned) BYTE_GET (imrs [i].sym_seg)); | |
7522 | printf ("%08" BFD_VMA_FMT "x\n", | |
7523 | (bfd_vma) BYTE_GET (imrs [i].sym_offset)); | |
7524 | } | |
7525 | ||
7526 | free (imrs); | |
7527 | return TRUE; | |
7528 | } | |
7529 | ||
7530 | /* Display IA-64 OpenVMS dynamic relocations and fixups. */ | |
7531 | ||
7532 | static bfd_boolean | |
7533 | process_ia64_vms_dynamic_relocs (Filedata * filedata) | |
7534 | { | |
7535 | struct ia64_vms_dynfixup fixup; | |
7536 | struct ia64_vms_dynimgrela imgrela; | |
7537 | Elf_Internal_Dyn *entry; | |
7538 | bfd_vma strtab_off = 0; | |
7539 | bfd_vma strtab_sz = 0; | |
7540 | char *strtab = NULL; | |
7541 | bfd_boolean res = TRUE; | |
7542 | ||
7543 | memset (&fixup, 0, sizeof (fixup)); | |
7544 | memset (&imgrela, 0, sizeof (imgrela)); | |
7545 | ||
7546 | /* Note: the order of the entries is specified by the OpenVMS specs. */ | |
7547 | for (entry = filedata->dynamic_section; | |
7548 | entry < filedata->dynamic_section + filedata->dynamic_nent; | |
7549 | entry++) | |
7550 | { | |
7551 | switch (entry->d_tag) | |
7552 | { | |
7553 | case DT_IA_64_VMS_STRTAB_OFFSET: | |
7554 | strtab_off = entry->d_un.d_val; | |
7555 | break; | |
7556 | case DT_STRSZ: | |
7557 | strtab_sz = entry->d_un.d_val; | |
7558 | if (strtab == NULL) | |
7559 | strtab = get_data (NULL, filedata, | |
7560 | filedata->dynamic_addr + strtab_off, | |
7561 | 1, strtab_sz, _("dynamic string section")); | |
7562 | if (strtab == NULL) | |
7563 | strtab_sz = 0; | |
7564 | break; | |
7565 | ||
7566 | case DT_IA_64_VMS_NEEDED_IDENT: | |
7567 | fixup.needed_ident = entry->d_un.d_val; | |
7568 | break; | |
7569 | case DT_NEEDED: | |
7570 | fixup.needed = entry->d_un.d_val; | |
7571 | break; | |
7572 | case DT_IA_64_VMS_FIXUP_NEEDED: | |
7573 | fixup.fixup_needed = entry->d_un.d_val; | |
7574 | break; | |
7575 | case DT_IA_64_VMS_FIXUP_RELA_CNT: | |
7576 | fixup.fixup_rela_cnt = entry->d_un.d_val; | |
7577 | break; | |
7578 | case DT_IA_64_VMS_FIXUP_RELA_OFF: | |
7579 | fixup.fixup_rela_off = entry->d_un.d_val; | |
7580 | if (! dump_ia64_vms_dynamic_fixups (filedata, &fixup, strtab, strtab_sz)) | |
7581 | res = FALSE; | |
7582 | break; | |
7583 | case DT_IA_64_VMS_IMG_RELA_CNT: | |
7584 | imgrela.img_rela_cnt = entry->d_un.d_val; | |
7585 | break; | |
7586 | case DT_IA_64_VMS_IMG_RELA_OFF: | |
7587 | imgrela.img_rela_off = entry->d_un.d_val; | |
7588 | if (! dump_ia64_vms_dynamic_relocs (filedata, &imgrela)) | |
7589 | res = FALSE; | |
7590 | break; | |
7591 | ||
7592 | default: | |
7593 | break; | |
7594 | } | |
7595 | } | |
7596 | ||
7597 | free (strtab); | |
7598 | ||
7599 | return res; | |
7600 | } | |
7601 | ||
7602 | static struct | |
7603 | { | |
7604 | const char * name; | |
7605 | int reloc; | |
7606 | int size; | |
7607 | int rela; | |
7608 | } | |
7609 | dynamic_relocations [] = | |
7610 | { | |
7611 | { "REL", DT_REL, DT_RELSZ, FALSE }, | |
7612 | { "RELA", DT_RELA, DT_RELASZ, TRUE }, | |
7613 | { "PLT", DT_JMPREL, DT_PLTRELSZ, UNKNOWN } | |
7614 | }; | |
7615 | ||
7616 | /* Process the reloc section. */ | |
7617 | ||
7618 | static bfd_boolean | |
7619 | process_relocs (Filedata * filedata) | |
7620 | { | |
7621 | unsigned long rel_size; | |
7622 | unsigned long rel_offset; | |
7623 | ||
7624 | if (!do_reloc) | |
7625 | return TRUE; | |
7626 | ||
7627 | if (do_using_dynamic) | |
7628 | { | |
7629 | int is_rela; | |
7630 | const char * name; | |
7631 | bfd_boolean has_dynamic_reloc; | |
7632 | unsigned int i; | |
7633 | ||
7634 | has_dynamic_reloc = FALSE; | |
7635 | ||
7636 | for (i = 0; i < ARRAY_SIZE (dynamic_relocations); i++) | |
7637 | { | |
7638 | is_rela = dynamic_relocations [i].rela; | |
7639 | name = dynamic_relocations [i].name; | |
7640 | rel_size = filedata->dynamic_info[dynamic_relocations [i].size]; | |
7641 | rel_offset = filedata->dynamic_info[dynamic_relocations [i].reloc]; | |
7642 | ||
7643 | if (rel_size) | |
7644 | has_dynamic_reloc = TRUE; | |
7645 | ||
7646 | if (is_rela == UNKNOWN) | |
7647 | { | |
7648 | if (dynamic_relocations [i].reloc == DT_JMPREL) | |
7649 | switch (filedata->dynamic_info[DT_PLTREL]) | |
7650 | { | |
7651 | case DT_REL: | |
7652 | is_rela = FALSE; | |
7653 | break; | |
7654 | case DT_RELA: | |
7655 | is_rela = TRUE; | |
7656 | break; | |
7657 | } | |
7658 | } | |
7659 | ||
7660 | if (rel_size) | |
7661 | { | |
7662 | if (filedata->is_separate) | |
7663 | printf | |
7664 | (_("\nIn linked file '%s' section '%s' at offset 0x%lx contains %ld bytes:\n"), | |
7665 | filedata->file_name, name, rel_offset, rel_size); | |
7666 | else | |
7667 | printf | |
7668 | (_("\n'%s' relocation section at offset 0x%lx contains %ld bytes:\n"), | |
7669 | name, rel_offset, rel_size); | |
7670 | ||
7671 | ||
7672 | dump_relocations (filedata, | |
7673 | offset_from_vma (filedata, rel_offset, rel_size), | |
7674 | rel_size, | |
7675 | filedata->dynamic_symbols, | |
7676 | filedata->num_dynamic_syms, | |
7677 | filedata->dynamic_strings, | |
7678 | filedata->dynamic_strings_length, | |
7679 | is_rela, TRUE /* is_dynamic */); | |
7680 | } | |
7681 | } | |
7682 | ||
7683 | if (is_ia64_vms (filedata)) | |
7684 | if (process_ia64_vms_dynamic_relocs (filedata)) | |
7685 | has_dynamic_reloc = TRUE; | |
7686 | ||
7687 | if (! has_dynamic_reloc) | |
7688 | { | |
7689 | if (filedata->is_separate) | |
7690 | printf (_("\nThere are no dynamic relocations in linked file '%s'.\n"), | |
7691 | filedata->file_name); | |
7692 | else | |
7693 | printf (_("\nThere are no dynamic relocations in this file.\n")); | |
7694 | } | |
7695 | } | |
7696 | else | |
7697 | { | |
7698 | Elf_Internal_Shdr * section; | |
7699 | unsigned long i; | |
7700 | bfd_boolean found = FALSE; | |
7701 | ||
7702 | for (i = 0, section = filedata->section_headers; | |
7703 | i < filedata->file_header.e_shnum; | |
7704 | i++, section++) | |
7705 | { | |
7706 | if ( section->sh_type != SHT_RELA | |
7707 | && section->sh_type != SHT_REL) | |
7708 | continue; | |
7709 | ||
7710 | rel_offset = section->sh_offset; | |
7711 | rel_size = section->sh_size; | |
7712 | ||
7713 | if (rel_size) | |
7714 | { | |
7715 | int is_rela; | |
7716 | unsigned long num_rela; | |
7717 | ||
7718 | if (filedata->is_separate) | |
7719 | printf (_("\nIn linked file '%s' relocation section "), | |
7720 | filedata->file_name); | |
7721 | else | |
7722 | printf (_("\nRelocation section ")); | |
7723 | ||
7724 | if (filedata->string_table == NULL) | |
7725 | printf ("%d", section->sh_name); | |
7726 | else | |
7727 | printf ("'%s'", printable_section_name (filedata, section)); | |
7728 | ||
7729 | num_rela = rel_size / section->sh_entsize; | |
7730 | printf (ngettext (" at offset 0x%lx contains %lu entry:\n", | |
7731 | " at offset 0x%lx contains %lu entries:\n", | |
7732 | num_rela), | |
7733 | rel_offset, num_rela); | |
7734 | ||
7735 | is_rela = section->sh_type == SHT_RELA; | |
7736 | ||
7737 | if (section->sh_link != 0 | |
7738 | && section->sh_link < filedata->file_header.e_shnum) | |
7739 | { | |
7740 | Elf_Internal_Shdr * symsec; | |
7741 | Elf_Internal_Sym * symtab; | |
7742 | unsigned long nsyms; | |
7743 | unsigned long strtablen = 0; | |
7744 | char * strtab = NULL; | |
7745 | ||
7746 | symsec = filedata->section_headers + section->sh_link; | |
7747 | if (symsec->sh_type != SHT_SYMTAB | |
7748 | && symsec->sh_type != SHT_DYNSYM) | |
7749 | continue; | |
7750 | ||
7751 | if (!get_symtab (filedata, symsec, | |
7752 | &symtab, &nsyms, &strtab, &strtablen)) | |
7753 | continue; | |
7754 | ||
7755 | dump_relocations (filedata, rel_offset, rel_size, | |
7756 | symtab, nsyms, strtab, strtablen, | |
7757 | is_rela, | |
7758 | symsec->sh_type == SHT_DYNSYM); | |
7759 | free (strtab); | |
7760 | free (symtab); | |
7761 | } | |
7762 | else | |
7763 | dump_relocations (filedata, rel_offset, rel_size, | |
7764 | NULL, 0, NULL, 0, is_rela, | |
7765 | FALSE /* is_dynamic */); | |
7766 | ||
7767 | found = TRUE; | |
7768 | } | |
7769 | } | |
7770 | ||
7771 | if (! found) | |
7772 | { | |
7773 | /* Users sometimes forget the -D option, so try to be helpful. */ | |
7774 | for (i = 0; i < ARRAY_SIZE (dynamic_relocations); i++) | |
7775 | { | |
7776 | if (filedata->dynamic_info[dynamic_relocations [i].size]) | |
7777 | { | |
7778 | if (filedata->is_separate) | |
7779 | printf (_("\nThere are no static relocations in linked file '%s'."), | |
7780 | filedata->file_name); | |
7781 | else | |
7782 | printf (_("\nThere are no static relocations in this file.")); | |
7783 | printf (_("\nTo see the dynamic relocations add --use-dynamic to the command line.\n")); | |
7784 | ||
7785 | break; | |
7786 | } | |
7787 | } | |
7788 | if (i == ARRAY_SIZE (dynamic_relocations)) | |
7789 | { | |
7790 | if (filedata->is_separate) | |
7791 | printf (_("\nThere are no relocations in linked file '%s'.\n"), | |
7792 | filedata->file_name); | |
7793 | else | |
7794 | printf (_("\nThere are no relocations in this file.\n")); | |
7795 | } | |
7796 | } | |
7797 | } | |
7798 | ||
7799 | return TRUE; | |
7800 | } | |
7801 | ||
7802 | /* An absolute address consists of a section and an offset. If the | |
7803 | section is NULL, the offset itself is the address, otherwise, the | |
7804 | address equals to LOAD_ADDRESS(section) + offset. */ | |
7805 | ||
7806 | struct absaddr | |
7807 | { | |
7808 | unsigned short section; | |
7809 | bfd_vma offset; | |
7810 | }; | |
7811 | ||
7812 | /* Find the nearest symbol at or below ADDR. Returns the symbol | |
7813 | name, if found, and the offset from the symbol to ADDR. */ | |
7814 | ||
7815 | static void | |
7816 | find_symbol_for_address (Filedata * filedata, | |
7817 | Elf_Internal_Sym * symtab, | |
7818 | unsigned long nsyms, | |
7819 | const char * strtab, | |
7820 | unsigned long strtab_size, | |
7821 | struct absaddr addr, | |
7822 | const char ** symname, | |
7823 | bfd_vma * offset) | |
7824 | { | |
7825 | bfd_vma dist = 0x100000; | |
7826 | Elf_Internal_Sym * sym; | |
7827 | Elf_Internal_Sym * beg; | |
7828 | Elf_Internal_Sym * end; | |
7829 | Elf_Internal_Sym * best = NULL; | |
7830 | ||
7831 | REMOVE_ARCH_BITS (addr.offset); | |
7832 | beg = symtab; | |
7833 | end = symtab + nsyms; | |
7834 | ||
7835 | while (beg < end) | |
7836 | { | |
7837 | bfd_vma value; | |
7838 | ||
7839 | sym = beg + (end - beg) / 2; | |
7840 | ||
7841 | value = sym->st_value; | |
7842 | REMOVE_ARCH_BITS (value); | |
7843 | ||
7844 | if (sym->st_name != 0 | |
7845 | && (addr.section == SHN_UNDEF || addr.section == sym->st_shndx) | |
7846 | && addr.offset >= value | |
7847 | && addr.offset - value < dist) | |
7848 | { | |
7849 | best = sym; | |
7850 | dist = addr.offset - value; | |
7851 | if (!dist) | |
7852 | break; | |
7853 | } | |
7854 | ||
7855 | if (addr.offset < value) | |
7856 | end = sym; | |
7857 | else | |
7858 | beg = sym + 1; | |
7859 | } | |
7860 | ||
7861 | if (best) | |
7862 | { | |
7863 | *symname = (best->st_name >= strtab_size | |
7864 | ? _("<corrupt>") : strtab + best->st_name); | |
7865 | *offset = dist; | |
7866 | return; | |
7867 | } | |
7868 | ||
7869 | *symname = NULL; | |
7870 | *offset = addr.offset; | |
7871 | } | |
7872 | ||
7873 | static /* signed */ int | |
7874 | symcmp (const void *p, const void *q) | |
7875 | { | |
7876 | Elf_Internal_Sym *sp = (Elf_Internal_Sym *) p; | |
7877 | Elf_Internal_Sym *sq = (Elf_Internal_Sym *) q; | |
7878 | ||
7879 | return sp->st_value > sq->st_value ? 1 : (sp->st_value < sq->st_value ? -1 : 0); | |
7880 | } | |
7881 | ||
7882 | /* Process the unwind section. */ | |
7883 | ||
7884 | #include "unwind-ia64.h" | |
7885 | ||
7886 | struct ia64_unw_table_entry | |
7887 | { | |
7888 | struct absaddr start; | |
7889 | struct absaddr end; | |
7890 | struct absaddr info; | |
7891 | }; | |
7892 | ||
7893 | struct ia64_unw_aux_info | |
7894 | { | |
7895 | struct ia64_unw_table_entry * table; /* Unwind table. */ | |
7896 | unsigned long table_len; /* Length of unwind table. */ | |
7897 | unsigned char * info; /* Unwind info. */ | |
7898 | unsigned long info_size; /* Size of unwind info. */ | |
7899 | bfd_vma info_addr; /* Starting address of unwind info. */ | |
7900 | bfd_vma seg_base; /* Starting address of segment. */ | |
7901 | Elf_Internal_Sym * symtab; /* The symbol table. */ | |
7902 | unsigned long nsyms; /* Number of symbols. */ | |
7903 | Elf_Internal_Sym * funtab; /* Sorted table of STT_FUNC symbols. */ | |
7904 | unsigned long nfuns; /* Number of entries in funtab. */ | |
7905 | char * strtab; /* The string table. */ | |
7906 | unsigned long strtab_size; /* Size of string table. */ | |
7907 | }; | |
7908 | ||
7909 | static bfd_boolean | |
7910 | dump_ia64_unwind (Filedata * filedata, struct ia64_unw_aux_info * aux) | |
7911 | { | |
7912 | struct ia64_unw_table_entry * tp; | |
7913 | unsigned long j, nfuns; | |
7914 | int in_body; | |
7915 | bfd_boolean res = TRUE; | |
7916 | ||
7917 | aux->funtab = xmalloc (aux->nsyms * sizeof (Elf_Internal_Sym)); | |
7918 | for (nfuns = 0, j = 0; j < aux->nsyms; j++) | |
7919 | if (aux->symtab[j].st_value && ELF_ST_TYPE (aux->symtab[j].st_info) == STT_FUNC) | |
7920 | aux->funtab[nfuns++] = aux->symtab[j]; | |
7921 | aux->nfuns = nfuns; | |
7922 | qsort (aux->funtab, aux->nfuns, sizeof (Elf_Internal_Sym), symcmp); | |
7923 | ||
7924 | for (tp = aux->table; tp < aux->table + aux->table_len; ++tp) | |
7925 | { | |
7926 | bfd_vma stamp; | |
7927 | bfd_vma offset; | |
7928 | const unsigned char * dp; | |
7929 | const unsigned char * head; | |
7930 | const unsigned char * end; | |
7931 | const char * procname; | |
7932 | ||
7933 | find_symbol_for_address (filedata, aux->funtab, aux->nfuns, aux->strtab, | |
7934 | aux->strtab_size, tp->start, &procname, &offset); | |
7935 | ||
7936 | fputs ("\n<", stdout); | |
7937 | ||
7938 | if (procname) | |
7939 | { | |
7940 | fputs (procname, stdout); | |
7941 | ||
7942 | if (offset) | |
7943 | printf ("+%lx", (unsigned long) offset); | |
7944 | } | |
7945 | ||
7946 | fputs (">: [", stdout); | |
7947 | print_vma (tp->start.offset, PREFIX_HEX); | |
7948 | fputc ('-', stdout); | |
7949 | print_vma (tp->end.offset, PREFIX_HEX); | |
7950 | printf ("], info at +0x%lx\n", | |
7951 | (unsigned long) (tp->info.offset - aux->seg_base)); | |
7952 | ||
7953 | /* PR 17531: file: 86232b32. */ | |
7954 | if (aux->info == NULL) | |
7955 | continue; | |
7956 | ||
7957 | offset = tp->info.offset; | |
7958 | if (tp->info.section) | |
7959 | { | |
7960 | if (tp->info.section >= filedata->file_header.e_shnum) | |
7961 | { | |
7962 | warn (_("Invalid section %u in table entry %ld\n"), | |
7963 | tp->info.section, (long) (tp - aux->table)); | |
7964 | res = FALSE; | |
7965 | continue; | |
7966 | } | |
7967 | offset += filedata->section_headers[tp->info.section].sh_addr; | |
7968 | } | |
7969 | offset -= aux->info_addr; | |
7970 | /* PR 17531: file: 0997b4d1. */ | |
7971 | if (offset >= aux->info_size | |
7972 | || aux->info_size - offset < 8) | |
7973 | { | |
7974 | warn (_("Invalid offset %lx in table entry %ld\n"), | |
7975 | (long) tp->info.offset, (long) (tp - aux->table)); | |
7976 | res = FALSE; | |
7977 | continue; | |
7978 | } | |
7979 | ||
7980 | head = aux->info + offset; | |
7981 | stamp = byte_get ((unsigned char *) head, sizeof (stamp)); | |
7982 | ||
7983 | printf (" v%u, flags=0x%lx (%s%s), len=%lu bytes\n", | |
7984 | (unsigned) UNW_VER (stamp), | |
7985 | (unsigned long) ((stamp & UNW_FLAG_MASK) >> 32), | |
7986 | UNW_FLAG_EHANDLER (stamp) ? " ehandler" : "", | |
7987 | UNW_FLAG_UHANDLER (stamp) ? " uhandler" : "", | |
7988 | (unsigned long) (eh_addr_size * UNW_LENGTH (stamp))); | |
7989 | ||
7990 | if (UNW_VER (stamp) != 1) | |
7991 | { | |
7992 | printf (_("\tUnknown version.\n")); | |
7993 | continue; | |
7994 | } | |
7995 | ||
7996 | in_body = 0; | |
7997 | end = head + 8 + eh_addr_size * UNW_LENGTH (stamp); | |
7998 | /* PR 17531: file: 16ceda89. */ | |
7999 | if (end > aux->info + aux->info_size) | |
8000 | end = aux->info + aux->info_size; | |
8001 | for (dp = head + 8; dp < end;) | |
8002 | dp = unw_decode (dp, in_body, & in_body, end); | |
8003 | } | |
8004 | ||
8005 | free (aux->funtab); | |
8006 | ||
8007 | return res; | |
8008 | } | |
8009 | ||
8010 | static bfd_boolean | |
8011 | slurp_ia64_unwind_table (Filedata * filedata, | |
8012 | struct ia64_unw_aux_info * aux, | |
8013 | Elf_Internal_Shdr * sec) | |
8014 | { | |
8015 | unsigned long size, nrelas, i; | |
8016 | Elf_Internal_Phdr * seg; | |
8017 | struct ia64_unw_table_entry * tep; | |
8018 | Elf_Internal_Shdr * relsec; | |
8019 | Elf_Internal_Rela * rela; | |
8020 | Elf_Internal_Rela * rp; | |
8021 | unsigned char * table; | |
8022 | unsigned char * tp; | |
8023 | Elf_Internal_Sym * sym; | |
8024 | const char * relname; | |
8025 | ||
8026 | aux->table_len = 0; | |
8027 | ||
8028 | /* First, find the starting address of the segment that includes | |
8029 | this section: */ | |
8030 | ||
8031 | if (filedata->file_header.e_phnum) | |
8032 | { | |
8033 | if (! get_program_headers (filedata)) | |
8034 | return FALSE; | |
8035 | ||
8036 | for (seg = filedata->program_headers; | |
8037 | seg < filedata->program_headers + filedata->file_header.e_phnum; | |
8038 | ++seg) | |
8039 | { | |
8040 | if (seg->p_type != PT_LOAD) | |
8041 | continue; | |
8042 | ||
8043 | if (sec->sh_addr >= seg->p_vaddr | |
8044 | && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz)) | |
8045 | { | |
8046 | aux->seg_base = seg->p_vaddr; | |
8047 | break; | |
8048 | } | |
8049 | } | |
8050 | } | |
8051 | ||
8052 | /* Second, build the unwind table from the contents of the unwind section: */ | |
8053 | size = sec->sh_size; | |
8054 | table = (unsigned char *) get_data (NULL, filedata, sec->sh_offset, 1, size, | |
8055 | _("unwind table")); | |
8056 | if (!table) | |
8057 | return FALSE; | |
8058 | ||
8059 | aux->table_len = size / (3 * eh_addr_size); | |
8060 | aux->table = (struct ia64_unw_table_entry *) | |
8061 | xcmalloc (aux->table_len, sizeof (aux->table[0])); | |
8062 | tep = aux->table; | |
8063 | ||
8064 | for (tp = table; tp <= table + size - (3 * eh_addr_size); ++tep) | |
8065 | { | |
8066 | tep->start.section = SHN_UNDEF; | |
8067 | tep->end.section = SHN_UNDEF; | |
8068 | tep->info.section = SHN_UNDEF; | |
8069 | tep->start.offset = byte_get (tp, eh_addr_size); tp += eh_addr_size; | |
8070 | tep->end.offset = byte_get (tp, eh_addr_size); tp += eh_addr_size; | |
8071 | tep->info.offset = byte_get (tp, eh_addr_size); tp += eh_addr_size; | |
8072 | tep->start.offset += aux->seg_base; | |
8073 | tep->end.offset += aux->seg_base; | |
8074 | tep->info.offset += aux->seg_base; | |
8075 | } | |
8076 | free (table); | |
8077 | ||
8078 | /* Third, apply any relocations to the unwind table: */ | |
8079 | for (relsec = filedata->section_headers; | |
8080 | relsec < filedata->section_headers + filedata->file_header.e_shnum; | |
8081 | ++relsec) | |
8082 | { | |
8083 | if (relsec->sh_type != SHT_RELA | |
8084 | || relsec->sh_info >= filedata->file_header.e_shnum | |
8085 | || filedata->section_headers + relsec->sh_info != sec) | |
8086 | continue; | |
8087 | ||
8088 | if (!slurp_rela_relocs (filedata, relsec->sh_offset, relsec->sh_size, | |
8089 | & rela, & nrelas)) | |
8090 | { | |
8091 | free (aux->table); | |
8092 | aux->table = NULL; | |
8093 | aux->table_len = 0; | |
8094 | return FALSE; | |
8095 | } | |
8096 | ||
8097 | for (rp = rela; rp < rela + nrelas; ++rp) | |
8098 | { | |
8099 | unsigned int sym_ndx; | |
8100 | unsigned int r_type = get_reloc_type (filedata, rp->r_info); | |
8101 | relname = elf_ia64_reloc_type (r_type); | |
8102 | ||
8103 | /* PR 17531: file: 9fa67536. */ | |
8104 | if (relname == NULL) | |
8105 | { | |
8106 | warn (_("Skipping unknown relocation type: %u\n"), r_type); | |
8107 | continue; | |
8108 | } | |
8109 | ||
8110 | if (! const_strneq (relname, "R_IA64_SEGREL")) | |
8111 | { | |
8112 | warn (_("Skipping unexpected relocation type: %s\n"), relname); | |
8113 | continue; | |
8114 | } | |
8115 | ||
8116 | i = rp->r_offset / (3 * eh_addr_size); | |
8117 | ||
8118 | /* PR 17531: file: 5bc8d9bf. */ | |
8119 | if (i >= aux->table_len) | |
8120 | { | |
8121 | warn (_("Skipping reloc with overlarge offset: %lx\n"), i); | |
8122 | continue; | |
8123 | } | |
8124 | ||
8125 | sym_ndx = get_reloc_symindex (rp->r_info); | |
8126 | if (sym_ndx >= aux->nsyms) | |
8127 | { | |
8128 | warn (_("Skipping reloc with invalid symbol index: %u\n"), | |
8129 | sym_ndx); | |
8130 | continue; | |
8131 | } | |
8132 | sym = aux->symtab + sym_ndx; | |
8133 | ||
8134 | switch (rp->r_offset / eh_addr_size % 3) | |
8135 | { | |
8136 | case 0: | |
8137 | aux->table[i].start.section = sym->st_shndx; | |
8138 | aux->table[i].start.offset = rp->r_addend + sym->st_value; | |
8139 | break; | |
8140 | case 1: | |
8141 | aux->table[i].end.section = sym->st_shndx; | |
8142 | aux->table[i].end.offset = rp->r_addend + sym->st_value; | |
8143 | break; | |
8144 | case 2: | |
8145 | aux->table[i].info.section = sym->st_shndx; | |
8146 | aux->table[i].info.offset = rp->r_addend + sym->st_value; | |
8147 | break; | |
8148 | default: | |
8149 | break; | |
8150 | } | |
8151 | } | |
8152 | ||
8153 | free (rela); | |
8154 | } | |
8155 | ||
8156 | return TRUE; | |
8157 | } | |
8158 | ||
8159 | static bfd_boolean | |
8160 | ia64_process_unwind (Filedata * filedata) | |
8161 | { | |
8162 | Elf_Internal_Shdr * sec; | |
8163 | Elf_Internal_Shdr * unwsec = NULL; | |
8164 | unsigned long i, unwcount = 0, unwstart = 0; | |
8165 | struct ia64_unw_aux_info aux; | |
8166 | bfd_boolean res = TRUE; | |
8167 | ||
8168 | memset (& aux, 0, sizeof (aux)); | |
8169 | ||
8170 | for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec) | |
8171 | { | |
8172 | if (sec->sh_type == SHT_SYMTAB) | |
8173 | { | |
8174 | if (aux.symtab) | |
8175 | { | |
8176 | error (_("Multiple symbol tables encountered\n")); | |
8177 | free (aux.symtab); | |
8178 | aux.symtab = NULL; | |
8179 | free (aux.strtab); | |
8180 | aux.strtab = NULL; | |
8181 | } | |
8182 | if (!get_symtab (filedata, sec, &aux.symtab, &aux.nsyms, | |
8183 | &aux.strtab, &aux.strtab_size)) | |
8184 | return FALSE; | |
8185 | } | |
8186 | else if (sec->sh_type == SHT_IA_64_UNWIND) | |
8187 | unwcount++; | |
8188 | } | |
8189 | ||
8190 | if (!unwcount) | |
8191 | printf (_("\nThere are no unwind sections in this file.\n")); | |
8192 | ||
8193 | while (unwcount-- > 0) | |
8194 | { | |
8195 | char * suffix; | |
8196 | size_t len, len2; | |
8197 | ||
8198 | for (i = unwstart, sec = filedata->section_headers + unwstart, unwsec = NULL; | |
8199 | i < filedata->file_header.e_shnum; ++i, ++sec) | |
8200 | if (sec->sh_type == SHT_IA_64_UNWIND) | |
8201 | { | |
8202 | unwsec = sec; | |
8203 | break; | |
8204 | } | |
8205 | /* We have already counted the number of SHT_IA64_UNWIND | |
8206 | sections so the loop above should never fail. */ | |
8207 | assert (unwsec != NULL); | |
8208 | ||
8209 | unwstart = i + 1; | |
8210 | len = sizeof (ELF_STRING_ia64_unwind_once) - 1; | |
8211 | ||
8212 | if ((unwsec->sh_flags & SHF_GROUP) != 0) | |
8213 | { | |
8214 | /* We need to find which section group it is in. */ | |
8215 | struct group_list * g; | |
8216 | ||
8217 | if (filedata->section_headers_groups == NULL | |
8218 | || filedata->section_headers_groups[i] == NULL) | |
8219 | i = filedata->file_header.e_shnum; | |
8220 | else | |
8221 | { | |
8222 | g = filedata->section_headers_groups[i]->root; | |
8223 | ||
8224 | for (; g != NULL; g = g->next) | |
8225 | { | |
8226 | sec = filedata->section_headers + g->section_index; | |
8227 | ||
8228 | if (SECTION_NAME_VALID (sec) | |
8229 | && streq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info)) | |
8230 | break; | |
8231 | } | |
8232 | ||
8233 | if (g == NULL) | |
8234 | i = filedata->file_header.e_shnum; | |
8235 | } | |
8236 | } | |
8237 | else if (SECTION_NAME_VALID (unwsec) | |
8238 | && strneq (SECTION_NAME (unwsec), | |
8239 | ELF_STRING_ia64_unwind_once, len)) | |
8240 | { | |
8241 | /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO. */ | |
8242 | len2 = sizeof (ELF_STRING_ia64_unwind_info_once) - 1; | |
8243 | suffix = SECTION_NAME (unwsec) + len; | |
8244 | for (i = 0, sec = filedata->section_headers; | |
8245 | i < filedata->file_header.e_shnum; | |
8246 | ++i, ++sec) | |
8247 | if (SECTION_NAME_VALID (sec) | |
8248 | && strneq (SECTION_NAME (sec), | |
8249 | ELF_STRING_ia64_unwind_info_once, len2) | |
8250 | && streq (SECTION_NAME (sec) + len2, suffix)) | |
8251 | break; | |
8252 | } | |
8253 | else | |
8254 | { | |
8255 | /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO | |
8256 | .IA_64.unwind or BAR -> .IA_64.unwind_info. */ | |
8257 | len = sizeof (ELF_STRING_ia64_unwind) - 1; | |
8258 | len2 = sizeof (ELF_STRING_ia64_unwind_info) - 1; | |
8259 | suffix = ""; | |
8260 | if (SECTION_NAME_VALID (unwsec) | |
8261 | && strneq (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind, len)) | |
8262 | suffix = SECTION_NAME (unwsec) + len; | |
8263 | for (i = 0, sec = filedata->section_headers; | |
8264 | i < filedata->file_header.e_shnum; | |
8265 | ++i, ++sec) | |
8266 | if (SECTION_NAME_VALID (sec) | |
8267 | && strneq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info, len2) | |
8268 | && streq (SECTION_NAME (sec) + len2, suffix)) | |
8269 | break; | |
8270 | } | |
8271 | ||
8272 | if (i == filedata->file_header.e_shnum) | |
8273 | { | |
8274 | printf (_("\nCould not find unwind info section for ")); | |
8275 | ||
8276 | if (filedata->string_table == NULL) | |
8277 | printf ("%d", unwsec->sh_name); | |
8278 | else | |
8279 | printf ("'%s'", printable_section_name (filedata, unwsec)); | |
8280 | } | |
8281 | else | |
8282 | { | |
8283 | aux.info_addr = sec->sh_addr; | |
8284 | aux.info = (unsigned char *) get_data (NULL, filedata, sec->sh_offset, 1, | |
8285 | sec->sh_size, | |
8286 | _("unwind info")); | |
8287 | aux.info_size = aux.info == NULL ? 0 : sec->sh_size; | |
8288 | ||
8289 | printf (_("\nUnwind section ")); | |
8290 | ||
8291 | if (filedata->string_table == NULL) | |
8292 | printf ("%d", unwsec->sh_name); | |
8293 | else | |
8294 | printf ("'%s'", printable_section_name (filedata, unwsec)); | |
8295 | ||
8296 | printf (_(" at offset 0x%lx contains %lu entries:\n"), | |
8297 | (unsigned long) unwsec->sh_offset, | |
8298 | (unsigned long) (unwsec->sh_size / (3 * eh_addr_size))); | |
8299 | ||
8300 | if (slurp_ia64_unwind_table (filedata, & aux, unwsec) | |
8301 | && aux.table_len > 0) | |
8302 | dump_ia64_unwind (filedata, & aux); | |
8303 | ||
8304 | free ((char *) aux.table); | |
8305 | free ((char *) aux.info); | |
8306 | aux.table = NULL; | |
8307 | aux.info = NULL; | |
8308 | } | |
8309 | } | |
8310 | ||
8311 | free (aux.symtab); | |
8312 | free ((char *) aux.strtab); | |
8313 | ||
8314 | return res; | |
8315 | } | |
8316 | ||
8317 | struct hppa_unw_table_entry | |
8318 | { | |
8319 | struct absaddr start; | |
8320 | struct absaddr end; | |
8321 | unsigned int Cannot_unwind:1; /* 0 */ | |
8322 | unsigned int Millicode:1; /* 1 */ | |
8323 | unsigned int Millicode_save_sr0:1; /* 2 */ | |
8324 | unsigned int Region_description:2; /* 3..4 */ | |
8325 | unsigned int reserved1:1; /* 5 */ | |
8326 | unsigned int Entry_SR:1; /* 6 */ | |
8327 | unsigned int Entry_FR:4; /* Number saved 7..10 */ | |
8328 | unsigned int Entry_GR:5; /* Number saved 11..15 */ | |
8329 | unsigned int Args_stored:1; /* 16 */ | |
8330 | unsigned int Variable_Frame:1; /* 17 */ | |
8331 | unsigned int Separate_Package_Body:1; /* 18 */ | |
8332 | unsigned int Frame_Extension_Millicode:1; /* 19 */ | |
8333 | unsigned int Stack_Overflow_Check:1; /* 20 */ | |
8334 | unsigned int Two_Instruction_SP_Increment:1; /* 21 */ | |
8335 | unsigned int Ada_Region:1; /* 22 */ | |
8336 | unsigned int cxx_info:1; /* 23 */ | |
8337 | unsigned int cxx_try_catch:1; /* 24 */ | |
8338 | unsigned int sched_entry_seq:1; /* 25 */ | |
8339 | unsigned int reserved2:1; /* 26 */ | |
8340 | unsigned int Save_SP:1; /* 27 */ | |
8341 | unsigned int Save_RP:1; /* 28 */ | |
8342 | unsigned int Save_MRP_in_frame:1; /* 29 */ | |
8343 | unsigned int extn_ptr_defined:1; /* 30 */ | |
8344 | unsigned int Cleanup_defined:1; /* 31 */ | |
8345 | ||
8346 | unsigned int MPE_XL_interrupt_marker:1; /* 0 */ | |
8347 | unsigned int HP_UX_interrupt_marker:1; /* 1 */ | |
8348 | unsigned int Large_frame:1; /* 2 */ | |
8349 | unsigned int Pseudo_SP_Set:1; /* 3 */ | |
8350 | unsigned int reserved4:1; /* 4 */ | |
8351 | unsigned int Total_frame_size:27; /* 5..31 */ | |
8352 | }; | |
8353 | ||
8354 | struct hppa_unw_aux_info | |
8355 | { | |
8356 | struct hppa_unw_table_entry * table; /* Unwind table. */ | |
8357 | unsigned long table_len; /* Length of unwind table. */ | |
8358 | bfd_vma seg_base; /* Starting address of segment. */ | |
8359 | Elf_Internal_Sym * symtab; /* The symbol table. */ | |
8360 | unsigned long nsyms; /* Number of symbols. */ | |
8361 | Elf_Internal_Sym * funtab; /* Sorted table of STT_FUNC symbols. */ | |
8362 | unsigned long nfuns; /* Number of entries in funtab. */ | |
8363 | char * strtab; /* The string table. */ | |
8364 | unsigned long strtab_size; /* Size of string table. */ | |
8365 | }; | |
8366 | ||
8367 | static bfd_boolean | |
8368 | dump_hppa_unwind (Filedata * filedata, struct hppa_unw_aux_info * aux) | |
8369 | { | |
8370 | struct hppa_unw_table_entry * tp; | |
8371 | unsigned long j, nfuns; | |
8372 | bfd_boolean res = TRUE; | |
8373 | ||
8374 | aux->funtab = xmalloc (aux->nsyms * sizeof (Elf_Internal_Sym)); | |
8375 | for (nfuns = 0, j = 0; j < aux->nsyms; j++) | |
8376 | if (aux->symtab[j].st_value && ELF_ST_TYPE (aux->symtab[j].st_info) == STT_FUNC) | |
8377 | aux->funtab[nfuns++] = aux->symtab[j]; | |
8378 | aux->nfuns = nfuns; | |
8379 | qsort (aux->funtab, aux->nfuns, sizeof (Elf_Internal_Sym), symcmp); | |
8380 | ||
8381 | for (tp = aux->table; tp < aux->table + aux->table_len; ++tp) | |
8382 | { | |
8383 | bfd_vma offset; | |
8384 | const char * procname; | |
8385 | ||
8386 | find_symbol_for_address (filedata, aux->funtab, aux->nfuns, aux->strtab, | |
8387 | aux->strtab_size, tp->start, &procname, | |
8388 | &offset); | |
8389 | ||
8390 | fputs ("\n<", stdout); | |
8391 | ||
8392 | if (procname) | |
8393 | { | |
8394 | fputs (procname, stdout); | |
8395 | ||
8396 | if (offset) | |
8397 | printf ("+%lx", (unsigned long) offset); | |
8398 | } | |
8399 | ||
8400 | fputs (">: [", stdout); | |
8401 | print_vma (tp->start.offset, PREFIX_HEX); | |
8402 | fputc ('-', stdout); | |
8403 | print_vma (tp->end.offset, PREFIX_HEX); | |
8404 | printf ("]\n\t"); | |
8405 | ||
8406 | #define PF(_m) if (tp->_m) printf (#_m " "); | |
8407 | #define PV(_m) if (tp->_m) printf (#_m "=%d ", tp->_m); | |
8408 | PF(Cannot_unwind); | |
8409 | PF(Millicode); | |
8410 | PF(Millicode_save_sr0); | |
8411 | /* PV(Region_description); */ | |
8412 | PF(Entry_SR); | |
8413 | PV(Entry_FR); | |
8414 | PV(Entry_GR); | |
8415 | PF(Args_stored); | |
8416 | PF(Variable_Frame); | |
8417 | PF(Separate_Package_Body); | |
8418 | PF(Frame_Extension_Millicode); | |
8419 | PF(Stack_Overflow_Check); | |
8420 | PF(Two_Instruction_SP_Increment); | |
8421 | PF(Ada_Region); | |
8422 | PF(cxx_info); | |
8423 | PF(cxx_try_catch); | |
8424 | PF(sched_entry_seq); | |
8425 | PF(Save_SP); | |
8426 | PF(Save_RP); | |
8427 | PF(Save_MRP_in_frame); | |
8428 | PF(extn_ptr_defined); | |
8429 | PF(Cleanup_defined); | |
8430 | PF(MPE_XL_interrupt_marker); | |
8431 | PF(HP_UX_interrupt_marker); | |
8432 | PF(Large_frame); | |
8433 | PF(Pseudo_SP_Set); | |
8434 | PV(Total_frame_size); | |
8435 | #undef PF | |
8436 | #undef PV | |
8437 | } | |
8438 | ||
8439 | printf ("\n"); | |
8440 | ||
8441 | free (aux->funtab); | |
8442 | ||
8443 | return res; | |
8444 | } | |
8445 | ||
8446 | static bfd_boolean | |
8447 | slurp_hppa_unwind_table (Filedata * filedata, | |
8448 | struct hppa_unw_aux_info * aux, | |
8449 | Elf_Internal_Shdr * sec) | |
8450 | { | |
8451 | unsigned long size, unw_ent_size, nentries, nrelas, i; | |
8452 | Elf_Internal_Phdr * seg; | |
8453 | struct hppa_unw_table_entry * tep; | |
8454 | Elf_Internal_Shdr * relsec; | |
8455 | Elf_Internal_Rela * rela; | |
8456 | Elf_Internal_Rela * rp; | |
8457 | unsigned char * table; | |
8458 | unsigned char * tp; | |
8459 | Elf_Internal_Sym * sym; | |
8460 | const char * relname; | |
8461 | ||
8462 | /* First, find the starting address of the segment that includes | |
8463 | this section. */ | |
8464 | if (filedata->file_header.e_phnum) | |
8465 | { | |
8466 | if (! get_program_headers (filedata)) | |
8467 | return FALSE; | |
8468 | ||
8469 | for (seg = filedata->program_headers; | |
8470 | seg < filedata->program_headers + filedata->file_header.e_phnum; | |
8471 | ++seg) | |
8472 | { | |
8473 | if (seg->p_type != PT_LOAD) | |
8474 | continue; | |
8475 | ||
8476 | if (sec->sh_addr >= seg->p_vaddr | |
8477 | && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz)) | |
8478 | { | |
8479 | aux->seg_base = seg->p_vaddr; | |
8480 | break; | |
8481 | } | |
8482 | } | |
8483 | } | |
8484 | ||
8485 | /* Second, build the unwind table from the contents of the unwind | |
8486 | section. */ | |
8487 | size = sec->sh_size; | |
8488 | table = (unsigned char *) get_data (NULL, filedata, sec->sh_offset, 1, size, | |
8489 | _("unwind table")); | |
8490 | if (!table) | |
8491 | return FALSE; | |
8492 | ||
8493 | unw_ent_size = 16; | |
8494 | nentries = size / unw_ent_size; | |
8495 | size = unw_ent_size * nentries; | |
8496 | ||
8497 | aux->table_len = nentries; | |
8498 | tep = aux->table = (struct hppa_unw_table_entry *) | |
8499 | xcmalloc (nentries, sizeof (aux->table[0])); | |
8500 | ||
8501 | for (tp = table; tp < table + size; tp += unw_ent_size, ++tep) | |
8502 | { | |
8503 | unsigned int tmp1, tmp2; | |
8504 | ||
8505 | tep->start.section = SHN_UNDEF; | |
8506 | tep->end.section = SHN_UNDEF; | |
8507 | ||
8508 | tep->start.offset = byte_get ((unsigned char *) tp + 0, 4); | |
8509 | tep->end.offset = byte_get ((unsigned char *) tp + 4, 4); | |
8510 | tmp1 = byte_get ((unsigned char *) tp + 8, 4); | |
8511 | tmp2 = byte_get ((unsigned char *) tp + 12, 4); | |
8512 | ||
8513 | tep->start.offset += aux->seg_base; | |
8514 | tep->end.offset += aux->seg_base; | |
8515 | ||
8516 | tep->Cannot_unwind = (tmp1 >> 31) & 0x1; | |
8517 | tep->Millicode = (tmp1 >> 30) & 0x1; | |
8518 | tep->Millicode_save_sr0 = (tmp1 >> 29) & 0x1; | |
8519 | tep->Region_description = (tmp1 >> 27) & 0x3; | |
8520 | tep->reserved1 = (tmp1 >> 26) & 0x1; | |
8521 | tep->Entry_SR = (tmp1 >> 25) & 0x1; | |
8522 | tep->Entry_FR = (tmp1 >> 21) & 0xf; | |
8523 | tep->Entry_GR = (tmp1 >> 16) & 0x1f; | |
8524 | tep->Args_stored = (tmp1 >> 15) & 0x1; | |
8525 | tep->Variable_Frame = (tmp1 >> 14) & 0x1; | |
8526 | tep->Separate_Package_Body = (tmp1 >> 13) & 0x1; | |
8527 | tep->Frame_Extension_Millicode = (tmp1 >> 12) & 0x1; | |
8528 | tep->Stack_Overflow_Check = (tmp1 >> 11) & 0x1; | |
8529 | tep->Two_Instruction_SP_Increment = (tmp1 >> 10) & 0x1; | |
8530 | tep->Ada_Region = (tmp1 >> 9) & 0x1; | |
8531 | tep->cxx_info = (tmp1 >> 8) & 0x1; | |
8532 | tep->cxx_try_catch = (tmp1 >> 7) & 0x1; | |
8533 | tep->sched_entry_seq = (tmp1 >> 6) & 0x1; | |
8534 | tep->reserved2 = (tmp1 >> 5) & 0x1; | |
8535 | tep->Save_SP = (tmp1 >> 4) & 0x1; | |
8536 | tep->Save_RP = (tmp1 >> 3) & 0x1; | |
8537 | tep->Save_MRP_in_frame = (tmp1 >> 2) & 0x1; | |
8538 | tep->extn_ptr_defined = (tmp1 >> 1) & 0x1; | |
8539 | tep->Cleanup_defined = tmp1 & 0x1; | |
8540 | ||
8541 | tep->MPE_XL_interrupt_marker = (tmp2 >> 31) & 0x1; | |
8542 | tep->HP_UX_interrupt_marker = (tmp2 >> 30) & 0x1; | |
8543 | tep->Large_frame = (tmp2 >> 29) & 0x1; | |
8544 | tep->Pseudo_SP_Set = (tmp2 >> 28) & 0x1; | |
8545 | tep->reserved4 = (tmp2 >> 27) & 0x1; | |
8546 | tep->Total_frame_size = tmp2 & 0x7ffffff; | |
8547 | } | |
8548 | free (table); | |
8549 | ||
8550 | /* Third, apply any relocations to the unwind table. */ | |
8551 | for (relsec = filedata->section_headers; | |
8552 | relsec < filedata->section_headers + filedata->file_header.e_shnum; | |
8553 | ++relsec) | |
8554 | { | |
8555 | if (relsec->sh_type != SHT_RELA | |
8556 | || relsec->sh_info >= filedata->file_header.e_shnum | |
8557 | || filedata->section_headers + relsec->sh_info != sec) | |
8558 | continue; | |
8559 | ||
8560 | if (!slurp_rela_relocs (filedata, relsec->sh_offset, relsec->sh_size, | |
8561 | & rela, & nrelas)) | |
8562 | return FALSE; | |
8563 | ||
8564 | for (rp = rela; rp < rela + nrelas; ++rp) | |
8565 | { | |
8566 | unsigned int sym_ndx; | |
8567 | unsigned int r_type = get_reloc_type (filedata, rp->r_info); | |
8568 | relname = elf_hppa_reloc_type (r_type); | |
8569 | ||
8570 | if (relname == NULL) | |
8571 | { | |
8572 | warn (_("Skipping unknown relocation type: %u\n"), r_type); | |
8573 | continue; | |
8574 | } | |
8575 | ||
8576 | /* R_PARISC_SEGREL32 or R_PARISC_SEGREL64. */ | |
8577 | if (! const_strneq (relname, "R_PARISC_SEGREL")) | |
8578 | { | |
8579 | warn (_("Skipping unexpected relocation type: %s\n"), relname); | |
8580 | continue; | |
8581 | } | |
8582 | ||
8583 | i = rp->r_offset / unw_ent_size; | |
8584 | if (i >= aux->table_len) | |
8585 | { | |
8586 | warn (_("Skipping reloc with overlarge offset: %lx\n"), i); | |
8587 | continue; | |
8588 | } | |
8589 | ||
8590 | sym_ndx = get_reloc_symindex (rp->r_info); | |
8591 | if (sym_ndx >= aux->nsyms) | |
8592 | { | |
8593 | warn (_("Skipping reloc with invalid symbol index: %u\n"), | |
8594 | sym_ndx); | |
8595 | continue; | |
8596 | } | |
8597 | sym = aux->symtab + sym_ndx; | |
8598 | ||
8599 | switch ((rp->r_offset % unw_ent_size) / 4) | |
8600 | { | |
8601 | case 0: | |
8602 | aux->table[i].start.section = sym->st_shndx; | |
8603 | aux->table[i].start.offset = sym->st_value + rp->r_addend; | |
8604 | break; | |
8605 | case 1: | |
8606 | aux->table[i].end.section = sym->st_shndx; | |
8607 | aux->table[i].end.offset = sym->st_value + rp->r_addend; | |
8608 | break; | |
8609 | default: | |
8610 | break; | |
8611 | } | |
8612 | } | |
8613 | ||
8614 | free (rela); | |
8615 | } | |
8616 | ||
8617 | return TRUE; | |
8618 | } | |
8619 | ||
8620 | static bfd_boolean | |
8621 | hppa_process_unwind (Filedata * filedata) | |
8622 | { | |
8623 | struct hppa_unw_aux_info aux; | |
8624 | Elf_Internal_Shdr * unwsec = NULL; | |
8625 | Elf_Internal_Shdr * sec; | |
8626 | unsigned long i; | |
8627 | bfd_boolean res = TRUE; | |
8628 | ||
8629 | if (filedata->string_table == NULL) | |
8630 | return FALSE; | |
8631 | ||
8632 | memset (& aux, 0, sizeof (aux)); | |
8633 | ||
8634 | for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec) | |
8635 | { | |
8636 | if (sec->sh_type == SHT_SYMTAB) | |
8637 | { | |
8638 | if (aux.symtab) | |
8639 | { | |
8640 | error (_("Multiple symbol tables encountered\n")); | |
8641 | free (aux.symtab); | |
8642 | aux.symtab = NULL; | |
8643 | free (aux.strtab); | |
8644 | aux.strtab = NULL; | |
8645 | } | |
8646 | if (!get_symtab (filedata, sec, &aux.symtab, &aux.nsyms, | |
8647 | &aux.strtab, &aux.strtab_size)) | |
8648 | return FALSE; | |
8649 | } | |
8650 | else if (SECTION_NAME_VALID (sec) | |
8651 | && streq (SECTION_NAME (sec), ".PARISC.unwind")) | |
8652 | unwsec = sec; | |
8653 | } | |
8654 | ||
8655 | if (!unwsec) | |
8656 | printf (_("\nThere are no unwind sections in this file.\n")); | |
8657 | ||
8658 | for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec) | |
8659 | { | |
8660 | if (SECTION_NAME_VALID (sec) | |
8661 | && streq (SECTION_NAME (sec), ".PARISC.unwind")) | |
8662 | { | |
8663 | unsigned long num_unwind = sec->sh_size / 16; | |
8664 | ||
8665 | printf (ngettext ("\nUnwind section '%s' at offset 0x%lx " | |
8666 | "contains %lu entry:\n", | |
8667 | "\nUnwind section '%s' at offset 0x%lx " | |
8668 | "contains %lu entries:\n", | |
8669 | num_unwind), | |
8670 | printable_section_name (filedata, sec), | |
8671 | (unsigned long) sec->sh_offset, | |
8672 | num_unwind); | |
8673 | ||
8674 | if (! slurp_hppa_unwind_table (filedata, &aux, sec)) | |
8675 | res = FALSE; | |
8676 | ||
8677 | if (res && aux.table_len > 0) | |
8678 | { | |
8679 | if (! dump_hppa_unwind (filedata, &aux)) | |
8680 | res = FALSE; | |
8681 | } | |
8682 | ||
8683 | free ((char *) aux.table); | |
8684 | aux.table = NULL; | |
8685 | } | |
8686 | } | |
8687 | ||
8688 | free (aux.symtab); | |
8689 | free ((char *) aux.strtab); | |
8690 | ||
8691 | return res; | |
8692 | } | |
8693 | ||
8694 | struct arm_section | |
8695 | { | |
8696 | unsigned char * data; /* The unwind data. */ | |
8697 | Elf_Internal_Shdr * sec; /* The cached unwind section header. */ | |
8698 | Elf_Internal_Rela * rela; /* The cached relocations for this section. */ | |
8699 | unsigned long nrelas; /* The number of relocations. */ | |
8700 | unsigned int rel_type; /* REL or RELA ? */ | |
8701 | Elf_Internal_Rela * next_rela; /* Cyclic pointer to the next reloc to process. */ | |
8702 | }; | |
8703 | ||
8704 | struct arm_unw_aux_info | |
8705 | { | |
8706 | Filedata * filedata; /* The file containing the unwind sections. */ | |
8707 | Elf_Internal_Sym * symtab; /* The file's symbol table. */ | |
8708 | unsigned long nsyms; /* Number of symbols. */ | |
8709 | Elf_Internal_Sym * funtab; /* Sorted table of STT_FUNC symbols. */ | |
8710 | unsigned long nfuns; /* Number of these symbols. */ | |
8711 | char * strtab; /* The file's string table. */ | |
8712 | unsigned long strtab_size; /* Size of string table. */ | |
8713 | }; | |
8714 | ||
8715 | static const char * | |
8716 | arm_print_vma_and_name (Filedata * filedata, | |
8717 | struct arm_unw_aux_info * aux, | |
8718 | bfd_vma fn, | |
8719 | struct absaddr addr) | |
8720 | { | |
8721 | const char *procname; | |
8722 | bfd_vma sym_offset; | |
8723 | ||
8724 | if (addr.section == SHN_UNDEF) | |
8725 | addr.offset = fn; | |
8726 | ||
8727 | find_symbol_for_address (filedata, aux->funtab, aux->nfuns, aux->strtab, | |
8728 | aux->strtab_size, addr, &procname, | |
8729 | &sym_offset); | |
8730 | ||
8731 | print_vma (fn, PREFIX_HEX); | |
8732 | ||
8733 | if (procname) | |
8734 | { | |
8735 | fputs (" <", stdout); | |
8736 | fputs (procname, stdout); | |
8737 | ||
8738 | if (sym_offset) | |
8739 | printf ("+0x%lx", (unsigned long) sym_offset); | |
8740 | fputc ('>', stdout); | |
8741 | } | |
8742 | ||
8743 | return procname; | |
8744 | } | |
8745 | ||
8746 | static void | |
8747 | arm_free_section (struct arm_section *arm_sec) | |
8748 | { | |
8749 | free (arm_sec->data); | |
8750 | free (arm_sec->rela); | |
8751 | } | |
8752 | ||
8753 | /* 1) If SEC does not match the one cached in ARM_SEC, then free the current | |
8754 | cached section and install SEC instead. | |
8755 | 2) Locate the 32-bit word at WORD_OFFSET in unwind section SEC | |
8756 | and return its valued in * WORDP, relocating if necessary. | |
8757 | 3) Update the NEXT_RELA field in ARM_SEC and store the section index and | |
8758 | relocation's offset in ADDR. | |
8759 | 4) If SYM_NAME is non-NULL and a relocation was applied, record the offset | |
8760 | into the string table of the symbol associated with the reloc. If no | |
8761 | reloc was applied store -1 there. | |
8762 | 5) Return TRUE upon success, FALSE otherwise. */ | |
8763 | ||
8764 | static bfd_boolean | |
8765 | get_unwind_section_word (Filedata * filedata, | |
8766 | struct arm_unw_aux_info * aux, | |
8767 | struct arm_section * arm_sec, | |
8768 | Elf_Internal_Shdr * sec, | |
8769 | bfd_vma word_offset, | |
8770 | unsigned int * wordp, | |
8771 | struct absaddr * addr, | |
8772 | bfd_vma * sym_name) | |
8773 | { | |
8774 | Elf_Internal_Rela *rp; | |
8775 | Elf_Internal_Sym *sym; | |
8776 | const char * relname; | |
8777 | unsigned int word; | |
8778 | bfd_boolean wrapped; | |
8779 | ||
8780 | if (sec == NULL || arm_sec == NULL) | |
8781 | return FALSE; | |
8782 | ||
8783 | addr->section = SHN_UNDEF; | |
8784 | addr->offset = 0; | |
8785 | ||
8786 | if (sym_name != NULL) | |
8787 | *sym_name = (bfd_vma) -1; | |
8788 | ||
8789 | /* If necessary, update the section cache. */ | |
8790 | if (sec != arm_sec->sec) | |
8791 | { | |
8792 | Elf_Internal_Shdr *relsec; | |
8793 | ||
8794 | arm_free_section (arm_sec); | |
8795 | ||
8796 | arm_sec->sec = sec; | |
8797 | arm_sec->data = get_data (NULL, aux->filedata, sec->sh_offset, 1, | |
8798 | sec->sh_size, _("unwind data")); | |
8799 | arm_sec->rela = NULL; | |
8800 | arm_sec->nrelas = 0; | |
8801 | ||
8802 | for (relsec = filedata->section_headers; | |
8803 | relsec < filedata->section_headers + filedata->file_header.e_shnum; | |
8804 | ++relsec) | |
8805 | { | |
8806 | if (relsec->sh_info >= filedata->file_header.e_shnum | |
8807 | || filedata->section_headers + relsec->sh_info != sec | |
8808 | /* PR 15745: Check the section type as well. */ | |
8809 | || (relsec->sh_type != SHT_REL | |
8810 | && relsec->sh_type != SHT_RELA)) | |
8811 | continue; | |
8812 | ||
8813 | arm_sec->rel_type = relsec->sh_type; | |
8814 | if (relsec->sh_type == SHT_REL) | |
8815 | { | |
8816 | if (!slurp_rel_relocs (aux->filedata, relsec->sh_offset, | |
8817 | relsec->sh_size, | |
8818 | & arm_sec->rela, & arm_sec->nrelas)) | |
8819 | return FALSE; | |
8820 | } | |
8821 | else /* relsec->sh_type == SHT_RELA */ | |
8822 | { | |
8823 | if (!slurp_rela_relocs (aux->filedata, relsec->sh_offset, | |
8824 | relsec->sh_size, | |
8825 | & arm_sec->rela, & arm_sec->nrelas)) | |
8826 | return FALSE; | |
8827 | } | |
8828 | break; | |
8829 | } | |
8830 | ||
8831 | arm_sec->next_rela = arm_sec->rela; | |
8832 | } | |
8833 | ||
8834 | /* If there is no unwind data we can do nothing. */ | |
8835 | if (arm_sec->data == NULL) | |
8836 | return FALSE; | |
8837 | ||
8838 | /* If the offset is invalid then fail. */ | |
8839 | if (/* PR 21343 *//* PR 18879 */ | |
8840 | sec->sh_size < 4 | |
8841 | || word_offset > (sec->sh_size - 4) | |
8842 | || ((bfd_signed_vma) word_offset) < 0) | |
8843 | return FALSE; | |
8844 | ||
8845 | /* Get the word at the required offset. */ | |
8846 | word = byte_get (arm_sec->data + word_offset, 4); | |
8847 | ||
8848 | /* PR 17531: file: id:000001,src:001266+003044,op:splice,rep:128. */ | |
8849 | if (arm_sec->rela == NULL) | |
8850 | { | |
8851 | * wordp = word; | |
8852 | return TRUE; | |
8853 | } | |
8854 | ||
8855 | /* Look through the relocs to find the one that applies to the provided offset. */ | |
8856 | wrapped = FALSE; | |
8857 | for (rp = arm_sec->next_rela; rp != arm_sec->rela + arm_sec->nrelas; rp++) | |
8858 | { | |
8859 | bfd_vma prelval, offset; | |
8860 | ||
8861 | if (rp->r_offset > word_offset && !wrapped) | |
8862 | { | |
8863 | rp = arm_sec->rela; | |
8864 | wrapped = TRUE; | |
8865 | } | |
8866 | if (rp->r_offset > word_offset) | |
8867 | break; | |
8868 | ||
8869 | if (rp->r_offset & 3) | |
8870 | { | |
8871 | warn (_("Skipping unexpected relocation at offset 0x%lx\n"), | |
8872 | (unsigned long) rp->r_offset); | |
8873 | continue; | |
8874 | } | |
8875 | ||
8876 | if (rp->r_offset < word_offset) | |
8877 | continue; | |
8878 | ||
8879 | /* PR 17531: file: 027-161405-0.004 */ | |
8880 | if (aux->symtab == NULL) | |
8881 | continue; | |
8882 | ||
8883 | if (arm_sec->rel_type == SHT_REL) | |
8884 | { | |
8885 | offset = word & 0x7fffffff; | |
8886 | if (offset & 0x40000000) | |
8887 | offset |= ~ (bfd_vma) 0x7fffffff; | |
8888 | } | |
8889 | else if (arm_sec->rel_type == SHT_RELA) | |
8890 | offset = rp->r_addend; | |
8891 | else | |
8892 | { | |
8893 | error (_("Unknown section relocation type %d encountered\n"), | |
8894 | arm_sec->rel_type); | |
8895 | break; | |
8896 | } | |
8897 | ||
8898 | /* PR 17531 file: 027-1241568-0.004. */ | |
8899 | if (ELF32_R_SYM (rp->r_info) >= aux->nsyms) | |
8900 | { | |
8901 | error (_("Bad symbol index in unwind relocation (%lu > %lu)\n"), | |
8902 | (unsigned long) ELF32_R_SYM (rp->r_info), aux->nsyms); | |
8903 | break; | |
8904 | } | |
8905 | ||
8906 | sym = aux->symtab + ELF32_R_SYM (rp->r_info); | |
8907 | offset += sym->st_value; | |
8908 | prelval = offset - (arm_sec->sec->sh_addr + rp->r_offset); | |
8909 | ||
8910 | /* Check that we are processing the expected reloc type. */ | |
8911 | if (filedata->file_header.e_machine == EM_ARM) | |
8912 | { | |
8913 | relname = elf_arm_reloc_type (ELF32_R_TYPE (rp->r_info)); | |
8914 | if (relname == NULL) | |
8915 | { | |
8916 | warn (_("Skipping unknown ARM relocation type: %d\n"), | |
8917 | (int) ELF32_R_TYPE (rp->r_info)); | |
8918 | continue; | |
8919 | } | |
8920 | ||
8921 | if (streq (relname, "R_ARM_NONE")) | |
8922 | continue; | |
8923 | ||
8924 | if (! streq (relname, "R_ARM_PREL31")) | |
8925 | { | |
8926 | warn (_("Skipping unexpected ARM relocation type %s\n"), relname); | |
8927 | continue; | |
8928 | } | |
8929 | } | |
8930 | else if (filedata->file_header.e_machine == EM_TI_C6000) | |
8931 | { | |
8932 | relname = elf_tic6x_reloc_type (ELF32_R_TYPE (rp->r_info)); | |
8933 | if (relname == NULL) | |
8934 | { | |
8935 | warn (_("Skipping unknown C6000 relocation type: %d\n"), | |
8936 | (int) ELF32_R_TYPE (rp->r_info)); | |
8937 | continue; | |
8938 | } | |
8939 | ||
8940 | if (streq (relname, "R_C6000_NONE")) | |
8941 | continue; | |
8942 | ||
8943 | if (! streq (relname, "R_C6000_PREL31")) | |
8944 | { | |
8945 | warn (_("Skipping unexpected C6000 relocation type %s\n"), relname); | |
8946 | continue; | |
8947 | } | |
8948 | ||
8949 | prelval >>= 1; | |
8950 | } | |
8951 | else | |
8952 | { | |
8953 | /* This function currently only supports ARM and TI unwinders. */ | |
8954 | warn (_("Only TI and ARM unwinders are currently supported\n")); | |
8955 | break; | |
8956 | } | |
8957 | ||
8958 | word = (word & ~ (bfd_vma) 0x7fffffff) | (prelval & 0x7fffffff); | |
8959 | addr->section = sym->st_shndx; | |
8960 | addr->offset = offset; | |
8961 | ||
8962 | if (sym_name) | |
8963 | * sym_name = sym->st_name; | |
8964 | break; | |
8965 | } | |
8966 | ||
8967 | *wordp = word; | |
8968 | arm_sec->next_rela = rp; | |
8969 | ||
8970 | return TRUE; | |
8971 | } | |
8972 | ||
8973 | static const char *tic6x_unwind_regnames[16] = | |
8974 | { | |
8975 | "A15", "B15", "B14", "B13", "B12", "B11", "B10", "B3", | |
8976 | "A14", "A13", "A12", "A11", "A10", | |
8977 | "[invalid reg 13]", "[invalid reg 14]", "[invalid reg 15]" | |
8978 | }; | |
8979 | ||
8980 | static void | |
8981 | decode_tic6x_unwind_regmask (unsigned int mask) | |
8982 | { | |
8983 | int i; | |
8984 | ||
8985 | for (i = 12; mask; mask >>= 1, i--) | |
8986 | { | |
8987 | if (mask & 1) | |
8988 | { | |
8989 | fputs (tic6x_unwind_regnames[i], stdout); | |
8990 | if (mask > 1) | |
8991 | fputs (", ", stdout); | |
8992 | } | |
8993 | } | |
8994 | } | |
8995 | ||
8996 | #define ADVANCE \ | |
8997 | if (remaining == 0 && more_words) \ | |
8998 | { \ | |
8999 | data_offset += 4; \ | |
9000 | if (! get_unwind_section_word (filedata, aux, data_arm_sec, data_sec, \ | |
9001 | data_offset, & word, & addr, NULL)) \ | |
9002 | return FALSE; \ | |
9003 | remaining = 4; \ | |
9004 | more_words--; \ | |
9005 | } \ | |
9006 | ||
9007 | #define GET_OP(OP) \ | |
9008 | ADVANCE; \ | |
9009 | if (remaining) \ | |
9010 | { \ | |
9011 | remaining--; \ | |
9012 | (OP) = word >> 24; \ | |
9013 | word <<= 8; \ | |
9014 | } \ | |
9015 | else \ | |
9016 | { \ | |
9017 | printf (_("[Truncated opcode]\n")); \ | |
9018 | return FALSE; \ | |
9019 | } \ | |
9020 | printf ("0x%02x ", OP) | |
9021 | ||
9022 | static bfd_boolean | |
9023 | decode_arm_unwind_bytecode (Filedata * filedata, | |
9024 | struct arm_unw_aux_info * aux, | |
9025 | unsigned int word, | |
9026 | unsigned int remaining, | |
9027 | unsigned int more_words, | |
9028 | bfd_vma data_offset, | |
9029 | Elf_Internal_Shdr * data_sec, | |
9030 | struct arm_section * data_arm_sec) | |
9031 | { | |
9032 | struct absaddr addr; | |
9033 | bfd_boolean res = TRUE; | |
9034 | ||
9035 | /* Decode the unwinding instructions. */ | |
9036 | while (1) | |
9037 | { | |
9038 | unsigned int op, op2; | |
9039 | ||
9040 | ADVANCE; | |
9041 | if (remaining == 0) | |
9042 | break; | |
9043 | remaining--; | |
9044 | op = word >> 24; | |
9045 | word <<= 8; | |
9046 | ||
9047 | printf (" 0x%02x ", op); | |
9048 | ||
9049 | if ((op & 0xc0) == 0x00) | |
9050 | { | |
9051 | int offset = ((op & 0x3f) << 2) + 4; | |
9052 | ||
9053 | printf (" vsp = vsp + %d", offset); | |
9054 | } | |
9055 | else if ((op & 0xc0) == 0x40) | |
9056 | { | |
9057 | int offset = ((op & 0x3f) << 2) + 4; | |
9058 | ||
9059 | printf (" vsp = vsp - %d", offset); | |
9060 | } | |
9061 | else if ((op & 0xf0) == 0x80) | |
9062 | { | |
9063 | GET_OP (op2); | |
9064 | if (op == 0x80 && op2 == 0) | |
9065 | printf (_("Refuse to unwind")); | |
9066 | else | |
9067 | { | |
9068 | unsigned int mask = ((op & 0x0f) << 8) | op2; | |
9069 | bfd_boolean first = TRUE; | |
9070 | int i; | |
9071 | ||
9072 | printf ("pop {"); | |
9073 | for (i = 0; i < 12; i++) | |
9074 | if (mask & (1 << i)) | |
9075 | { | |
9076 | if (first) | |
9077 | first = FALSE; | |
9078 | else | |
9079 | printf (", "); | |
9080 | printf ("r%d", 4 + i); | |
9081 | } | |
9082 | printf ("}"); | |
9083 | } | |
9084 | } | |
9085 | else if ((op & 0xf0) == 0x90) | |
9086 | { | |
9087 | if (op == 0x9d || op == 0x9f) | |
9088 | printf (_(" [Reserved]")); | |
9089 | else | |
9090 | printf (" vsp = r%d", op & 0x0f); | |
9091 | } | |
9092 | else if ((op & 0xf0) == 0xa0) | |
9093 | { | |
9094 | int end = 4 + (op & 0x07); | |
9095 | bfd_boolean first = TRUE; | |
9096 | int i; | |
9097 | ||
9098 | printf (" pop {"); | |
9099 | for (i = 4; i <= end; i++) | |
9100 | { | |
9101 | if (first) | |
9102 | first = FALSE; | |
9103 | else | |
9104 | printf (", "); | |
9105 | printf ("r%d", i); | |
9106 | } | |
9107 | if (op & 0x08) | |
9108 | { | |
9109 | if (!first) | |
9110 | printf (", "); | |
9111 | printf ("r14"); | |
9112 | } | |
9113 | printf ("}"); | |
9114 | } | |
9115 | else if (op == 0xb0) | |
9116 | printf (_(" finish")); | |
9117 | else if (op == 0xb1) | |
9118 | { | |
9119 | GET_OP (op2); | |
9120 | if (op2 == 0 || (op2 & 0xf0) != 0) | |
9121 | printf (_("[Spare]")); | |
9122 | else | |
9123 | { | |
9124 | unsigned int mask = op2 & 0x0f; | |
9125 | bfd_boolean first = TRUE; | |
9126 | int i; | |
9127 | ||
9128 | printf ("pop {"); | |
9129 | for (i = 0; i < 12; i++) | |
9130 | if (mask & (1 << i)) | |
9131 | { | |
9132 | if (first) | |
9133 | first = FALSE; | |
9134 | else | |
9135 | printf (", "); | |
9136 | printf ("r%d", i); | |
9137 | } | |
9138 | printf ("}"); | |
9139 | } | |
9140 | } | |
9141 | else if (op == 0xb2) | |
9142 | { | |
9143 | unsigned char buf[9]; | |
9144 | unsigned int i, len; | |
9145 | unsigned long offset; | |
9146 | ||
9147 | for (i = 0; i < sizeof (buf); i++) | |
9148 | { | |
9149 | GET_OP (buf[i]); | |
9150 | if ((buf[i] & 0x80) == 0) | |
9151 | break; | |
9152 | } | |
9153 | if (i == sizeof (buf)) | |
9154 | { | |
9155 | error (_("corrupt change to vsp\n")); | |
9156 | res = FALSE; | |
9157 | } | |
9158 | else | |
9159 | { | |
9160 | offset = read_leb128 (buf, buf + i + 1, FALSE, &len, NULL); | |
9161 | assert (len == i + 1); | |
9162 | offset = offset * 4 + 0x204; | |
9163 | printf ("vsp = vsp + %ld", offset); | |
9164 | } | |
9165 | } | |
9166 | else if (op == 0xb3 || op == 0xc8 || op == 0xc9) | |
9167 | { | |
9168 | unsigned int first, last; | |
9169 | ||
9170 | GET_OP (op2); | |
9171 | first = op2 >> 4; | |
9172 | last = op2 & 0x0f; | |
9173 | if (op == 0xc8) | |
9174 | first = first + 16; | |
9175 | printf ("pop {D%d", first); | |
9176 | if (last) | |
9177 | printf ("-D%d", first + last); | |
9178 | printf ("}"); | |
9179 | } | |
9180 | else if ((op & 0xf8) == 0xb8 || (op & 0xf8) == 0xd0) | |
9181 | { | |
9182 | unsigned int count = op & 0x07; | |
9183 | ||
9184 | printf ("pop {D8"); | |
9185 | if (count) | |
9186 | printf ("-D%d", 8 + count); | |
9187 | printf ("}"); | |
9188 | } | |
9189 | else if (op >= 0xc0 && op <= 0xc5) | |
9190 | { | |
9191 | unsigned int count = op & 0x07; | |
9192 | ||
9193 | printf (" pop {wR10"); | |
9194 | if (count) | |
9195 | printf ("-wR%d", 10 + count); | |
9196 | printf ("}"); | |
9197 | } | |
9198 | else if (op == 0xc6) | |
9199 | { | |
9200 | unsigned int first, last; | |
9201 | ||
9202 | GET_OP (op2); | |
9203 | first = op2 >> 4; | |
9204 | last = op2 & 0x0f; | |
9205 | printf ("pop {wR%d", first); | |
9206 | if (last) | |
9207 | printf ("-wR%d", first + last); | |
9208 | printf ("}"); | |
9209 | } | |
9210 | else if (op == 0xc7) | |
9211 | { | |
9212 | GET_OP (op2); | |
9213 | if (op2 == 0 || (op2 & 0xf0) != 0) | |
9214 | printf (_("[Spare]")); | |
9215 | else | |
9216 | { | |
9217 | unsigned int mask = op2 & 0x0f; | |
9218 | bfd_boolean first = TRUE; | |
9219 | int i; | |
9220 | ||
9221 | printf ("pop {"); | |
9222 | for (i = 0; i < 4; i++) | |
9223 | if (mask & (1 << i)) | |
9224 | { | |
9225 | if (first) | |
9226 | first = FALSE; | |
9227 | else | |
9228 | printf (", "); | |
9229 | printf ("wCGR%d", i); | |
9230 | } | |
9231 | printf ("}"); | |
9232 | } | |
9233 | } | |
9234 | else | |
9235 | { | |
9236 | printf (_(" [unsupported opcode]")); | |
9237 | res = FALSE; | |
9238 | } | |
9239 | ||
9240 | printf ("\n"); | |
9241 | } | |
9242 | ||
9243 | return res; | |
9244 | } | |
9245 | ||
9246 | static bfd_boolean | |
9247 | decode_tic6x_unwind_bytecode (Filedata * filedata, | |
9248 | struct arm_unw_aux_info * aux, | |
9249 | unsigned int word, | |
9250 | unsigned int remaining, | |
9251 | unsigned int more_words, | |
9252 | bfd_vma data_offset, | |
9253 | Elf_Internal_Shdr * data_sec, | |
9254 | struct arm_section * data_arm_sec) | |
9255 | { | |
9256 | struct absaddr addr; | |
9257 | ||
9258 | /* Decode the unwinding instructions. */ | |
9259 | while (1) | |
9260 | { | |
9261 | unsigned int op, op2; | |
9262 | ||
9263 | ADVANCE; | |
9264 | if (remaining == 0) | |
9265 | break; | |
9266 | remaining--; | |
9267 | op = word >> 24; | |
9268 | word <<= 8; | |
9269 | ||
9270 | printf (" 0x%02x ", op); | |
9271 | ||
9272 | if ((op & 0xc0) == 0x00) | |
9273 | { | |
9274 | int offset = ((op & 0x3f) << 3) + 8; | |
9275 | printf (" sp = sp + %d", offset); | |
9276 | } | |
9277 | else if ((op & 0xc0) == 0x80) | |
9278 | { | |
9279 | GET_OP (op2); | |
9280 | if (op == 0x80 && op2 == 0) | |
9281 | printf (_("Refuse to unwind")); | |
9282 | else | |
9283 | { | |
9284 | unsigned int mask = ((op & 0x1f) << 8) | op2; | |
9285 | if (op & 0x20) | |
9286 | printf ("pop compact {"); | |
9287 | else | |
9288 | printf ("pop {"); | |
9289 | ||
9290 | decode_tic6x_unwind_regmask (mask); | |
9291 | printf("}"); | |
9292 | } | |
9293 | } | |
9294 | else if ((op & 0xf0) == 0xc0) | |
9295 | { | |
9296 | unsigned int reg; | |
9297 | unsigned int nregs; | |
9298 | unsigned int i; | |
9299 | const char *name; | |
9300 | struct | |
9301 | { | |
9302 | unsigned int offset; | |
9303 | unsigned int reg; | |
9304 | } regpos[16]; | |
9305 | ||
9306 | /* Scan entire instruction first so that GET_OP output is not | |
9307 | interleaved with disassembly. */ | |
9308 | nregs = 0; | |
9309 | for (i = 0; nregs < (op & 0xf); i++) | |
9310 | { | |
9311 | GET_OP (op2); | |
9312 | reg = op2 >> 4; | |
9313 | if (reg != 0xf) | |
9314 | { | |
9315 | regpos[nregs].offset = i * 2; | |
9316 | regpos[nregs].reg = reg; | |
9317 | nregs++; | |
9318 | } | |
9319 | ||
9320 | reg = op2 & 0xf; | |
9321 | if (reg != 0xf) | |
9322 | { | |
9323 | regpos[nregs].offset = i * 2 + 1; | |
9324 | regpos[nregs].reg = reg; | |
9325 | nregs++; | |
9326 | } | |
9327 | } | |
9328 | ||
9329 | printf (_("pop frame {")); | |
9330 | if (nregs == 0) | |
9331 | { | |
9332 | printf (_("*corrupt* - no registers specified")); | |
9333 | } | |
9334 | else | |
9335 | { | |
9336 | reg = nregs - 1; | |
9337 | for (i = i * 2; i > 0; i--) | |
9338 | { | |
9339 | if (regpos[reg].offset == i - 1) | |
9340 | { | |
9341 | name = tic6x_unwind_regnames[regpos[reg].reg]; | |
9342 | if (reg > 0) | |
9343 | reg--; | |
9344 | } | |
9345 | else | |
9346 | name = _("[pad]"); | |
9347 | ||
9348 | fputs (name, stdout); | |
9349 | if (i > 1) | |
9350 | printf (", "); | |
9351 | } | |
9352 | } | |
9353 | ||
9354 | printf ("}"); | |
9355 | } | |
9356 | else if (op == 0xd0) | |
9357 | printf (" MOV FP, SP"); | |
9358 | else if (op == 0xd1) | |
9359 | printf (" __c6xabi_pop_rts"); | |
9360 | else if (op == 0xd2) | |
9361 | { | |
9362 | unsigned char buf[9]; | |
9363 | unsigned int i, len; | |
9364 | unsigned long offset; | |
9365 | ||
9366 | for (i = 0; i < sizeof (buf); i++) | |
9367 | { | |
9368 | GET_OP (buf[i]); | |
9369 | if ((buf[i] & 0x80) == 0) | |
9370 | break; | |
9371 | } | |
9372 | /* PR 17531: file: id:000001,src:001906+004739,op:splice,rep:2. */ | |
9373 | if (i == sizeof (buf)) | |
9374 | { | |
9375 | warn (_("Corrupt stack pointer adjustment detected\n")); | |
9376 | return FALSE; | |
9377 | } | |
9378 | ||
9379 | offset = read_leb128 (buf, buf + i + 1, FALSE, &len, NULL); | |
9380 | assert (len == i + 1); | |
9381 | offset = offset * 8 + 0x408; | |
9382 | printf (_("sp = sp + %ld"), offset); | |
9383 | } | |
9384 | else if ((op & 0xf0) == 0xe0) | |
9385 | { | |
9386 | if ((op & 0x0f) == 7) | |
9387 | printf (" RETURN"); | |
9388 | else | |
9389 | printf (" MV %s, B3", tic6x_unwind_regnames[op & 0x0f]); | |
9390 | } | |
9391 | else | |
9392 | { | |
9393 | printf (_(" [unsupported opcode]")); | |
9394 | } | |
9395 | putchar ('\n'); | |
9396 | } | |
9397 | ||
9398 | return TRUE; | |
9399 | } | |
9400 | ||
9401 | static bfd_vma | |
9402 | arm_expand_prel31 (Filedata * filedata, bfd_vma word, bfd_vma where) | |
9403 | { | |
9404 | bfd_vma offset; | |
9405 | ||
9406 | offset = word & 0x7fffffff; | |
9407 | if (offset & 0x40000000) | |
9408 | offset |= ~ (bfd_vma) 0x7fffffff; | |
9409 | ||
9410 | if (filedata->file_header.e_machine == EM_TI_C6000) | |
9411 | offset <<= 1; | |
9412 | ||
9413 | return offset + where; | |
9414 | } | |
9415 | ||
9416 | static bfd_boolean | |
9417 | decode_arm_unwind (Filedata * filedata, | |
9418 | struct arm_unw_aux_info * aux, | |
9419 | unsigned int word, | |
9420 | unsigned int remaining, | |
9421 | bfd_vma data_offset, | |
9422 | Elf_Internal_Shdr * data_sec, | |
9423 | struct arm_section * data_arm_sec) | |
9424 | { | |
9425 | int per_index; | |
9426 | unsigned int more_words = 0; | |
9427 | struct absaddr addr; | |
9428 | bfd_vma sym_name = (bfd_vma) -1; | |
9429 | bfd_boolean res = TRUE; | |
9430 | ||
9431 | if (remaining == 0) | |
9432 | { | |
9433 | /* Fetch the first word. | |
9434 | Note - when decoding an object file the address extracted | |
9435 | here will always be 0. So we also pass in the sym_name | |
9436 | parameter so that we can find the symbol associated with | |
9437 | the personality routine. */ | |
9438 | if (! get_unwind_section_word (filedata, aux, data_arm_sec, data_sec, data_offset, | |
9439 | & word, & addr, & sym_name)) | |
9440 | return FALSE; | |
9441 | ||
9442 | remaining = 4; | |
9443 | } | |
9444 | else | |
9445 | { | |
9446 | addr.section = SHN_UNDEF; | |
9447 | addr.offset = 0; | |
9448 | } | |
9449 | ||
9450 | if ((word & 0x80000000) == 0) | |
9451 | { | |
9452 | /* Expand prel31 for personality routine. */ | |
9453 | bfd_vma fn; | |
9454 | const char *procname; | |
9455 | ||
9456 | fn = arm_expand_prel31 (filedata, word, data_sec->sh_addr + data_offset); | |
9457 | printf (_(" Personality routine: ")); | |
9458 | if (fn == 0 | |
9459 | && addr.section == SHN_UNDEF && addr.offset == 0 | |
9460 | && sym_name != (bfd_vma) -1 && sym_name < aux->strtab_size) | |
9461 | { | |
9462 | procname = aux->strtab + sym_name; | |
9463 | print_vma (fn, PREFIX_HEX); | |
9464 | if (procname) | |
9465 | { | |
9466 | fputs (" <", stdout); | |
9467 | fputs (procname, stdout); | |
9468 | fputc ('>', stdout); | |
9469 | } | |
9470 | } | |
9471 | else | |
9472 | procname = arm_print_vma_and_name (filedata, aux, fn, addr); | |
9473 | fputc ('\n', stdout); | |
9474 | ||
9475 | /* The GCC personality routines use the standard compact | |
9476 | encoding, starting with one byte giving the number of | |
9477 | words. */ | |
9478 | if (procname != NULL | |
9479 | && (const_strneq (procname, "__gcc_personality_v0") | |
9480 | || const_strneq (procname, "__gxx_personality_v0") | |
9481 | || const_strneq (procname, "__gcj_personality_v0") | |
9482 | || const_strneq (procname, "__gnu_objc_personality_v0"))) | |
9483 | { | |
9484 | remaining = 0; | |
9485 | more_words = 1; | |
9486 | ADVANCE; | |
9487 | if (!remaining) | |
9488 | { | |
9489 | printf (_(" [Truncated data]\n")); | |
9490 | return FALSE; | |
9491 | } | |
9492 | more_words = word >> 24; | |
9493 | word <<= 8; | |
9494 | remaining--; | |
9495 | per_index = -1; | |
9496 | } | |
9497 | else | |
9498 | return TRUE; | |
9499 | } | |
9500 | else | |
9501 | { | |
9502 | /* ARM EHABI Section 6.3: | |
9503 | ||
9504 | An exception-handling table entry for the compact model looks like: | |
9505 | ||
9506 | 31 30-28 27-24 23-0 | |
9507 | -- ----- ----- ---- | |
9508 | 1 0 index Data for personalityRoutine[index] */ | |
9509 | ||
9510 | if (filedata->file_header.e_machine == EM_ARM | |
9511 | && (word & 0x70000000)) | |
9512 | { | |
9513 | warn (_("Corrupt ARM compact model table entry: %x \n"), word); | |
9514 | res = FALSE; | |
9515 | } | |
9516 | ||
9517 | per_index = (word >> 24) & 0x7f; | |
9518 | printf (_(" Compact model index: %d\n"), per_index); | |
9519 | if (per_index == 0) | |
9520 | { | |
9521 | more_words = 0; | |
9522 | word <<= 8; | |
9523 | remaining--; | |
9524 | } | |
9525 | else if (per_index < 3) | |
9526 | { | |
9527 | more_words = (word >> 16) & 0xff; | |
9528 | word <<= 16; | |
9529 | remaining -= 2; | |
9530 | } | |
9531 | } | |
9532 | ||
9533 | switch (filedata->file_header.e_machine) | |
9534 | { | |
9535 | case EM_ARM: | |
9536 | if (per_index < 3) | |
9537 | { | |
9538 | if (! decode_arm_unwind_bytecode (filedata, aux, word, remaining, more_words, | |
9539 | data_offset, data_sec, data_arm_sec)) | |
9540 | res = FALSE; | |
9541 | } | |
9542 | else | |
9543 | { | |
9544 | warn (_("Unknown ARM compact model index encountered\n")); | |
9545 | printf (_(" [reserved]\n")); | |
9546 | res = FALSE; | |
9547 | } | |
9548 | break; | |
9549 | ||
9550 | case EM_TI_C6000: | |
9551 | if (per_index < 3) | |
9552 | { | |
9553 | if (! decode_tic6x_unwind_bytecode (filedata, aux, word, remaining, more_words, | |
9554 | data_offset, data_sec, data_arm_sec)) | |
9555 | res = FALSE; | |
9556 | } | |
9557 | else if (per_index < 5) | |
9558 | { | |
9559 | if (((word >> 17) & 0x7f) == 0x7f) | |
9560 | printf (_(" Restore stack from frame pointer\n")); | |
9561 | else | |
9562 | printf (_(" Stack increment %d\n"), (word >> 14) & 0x1fc); | |
9563 | printf (_(" Registers restored: ")); | |
9564 | if (per_index == 4) | |
9565 | printf (" (compact) "); | |
9566 | decode_tic6x_unwind_regmask ((word >> 4) & 0x1fff); | |
9567 | putchar ('\n'); | |
9568 | printf (_(" Return register: %s\n"), | |
9569 | tic6x_unwind_regnames[word & 0xf]); | |
9570 | } | |
9571 | else | |
9572 | printf (_(" [reserved (%d)]\n"), per_index); | |
9573 | break; | |
9574 | ||
9575 | default: | |
9576 | error (_("Unsupported architecture type %d encountered when decoding unwind table\n"), | |
9577 | filedata->file_header.e_machine); | |
9578 | res = FALSE; | |
9579 | } | |
9580 | ||
9581 | /* Decode the descriptors. Not implemented. */ | |
9582 | ||
9583 | return res; | |
9584 | } | |
9585 | ||
9586 | static bfd_boolean | |
9587 | dump_arm_unwind (Filedata * filedata, | |
9588 | struct arm_unw_aux_info * aux, | |
9589 | Elf_Internal_Shdr * exidx_sec) | |
9590 | { | |
9591 | struct arm_section exidx_arm_sec, extab_arm_sec; | |
9592 | unsigned int i, exidx_len; | |
9593 | unsigned long j, nfuns; | |
9594 | bfd_boolean res = TRUE; | |
9595 | ||
9596 | memset (&exidx_arm_sec, 0, sizeof (exidx_arm_sec)); | |
9597 | memset (&extab_arm_sec, 0, sizeof (extab_arm_sec)); | |
9598 | exidx_len = exidx_sec->sh_size / 8; | |
9599 | ||
9600 | aux->funtab = xmalloc (aux->nsyms * sizeof (Elf_Internal_Sym)); | |
9601 | for (nfuns = 0, j = 0; j < aux->nsyms; j++) | |
9602 | if (aux->symtab[j].st_value && ELF_ST_TYPE (aux->symtab[j].st_info) == STT_FUNC) | |
9603 | aux->funtab[nfuns++] = aux->symtab[j]; | |
9604 | aux->nfuns = nfuns; | |
9605 | qsort (aux->funtab, aux->nfuns, sizeof (Elf_Internal_Sym), symcmp); | |
9606 | ||
9607 | for (i = 0; i < exidx_len; i++) | |
9608 | { | |
9609 | unsigned int exidx_fn, exidx_entry; | |
9610 | struct absaddr fn_addr, entry_addr; | |
9611 | bfd_vma fn; | |
9612 | ||
9613 | fputc ('\n', stdout); | |
9614 | ||
9615 | if (! get_unwind_section_word (filedata, aux, & exidx_arm_sec, exidx_sec, | |
9616 | 8 * i, & exidx_fn, & fn_addr, NULL) | |
9617 | || ! get_unwind_section_word (filedata, aux, & exidx_arm_sec, exidx_sec, | |
9618 | 8 * i + 4, & exidx_entry, & entry_addr, NULL)) | |
9619 | { | |
9620 | free (aux->funtab); | |
9621 | arm_free_section (& exidx_arm_sec); | |
9622 | arm_free_section (& extab_arm_sec); | |
9623 | return FALSE; | |
9624 | } | |
9625 | ||
9626 | /* ARM EHABI, Section 5: | |
9627 | An index table entry consists of 2 words. | |
9628 | The first word contains a prel31 offset to the start of a function, with bit 31 clear. */ | |
9629 | if (exidx_fn & 0x80000000) | |
9630 | { | |
9631 | warn (_("corrupt index table entry: %x\n"), exidx_fn); | |
9632 | res = FALSE; | |
9633 | } | |
9634 | ||
9635 | fn = arm_expand_prel31 (filedata, exidx_fn, exidx_sec->sh_addr + 8 * i); | |
9636 | ||
9637 | arm_print_vma_and_name (filedata, aux, fn, fn_addr); | |
9638 | fputs (": ", stdout); | |
9639 | ||
9640 | if (exidx_entry == 1) | |
9641 | { | |
9642 | print_vma (exidx_entry, PREFIX_HEX); | |
9643 | fputs (" [cantunwind]\n", stdout); | |
9644 | } | |
9645 | else if (exidx_entry & 0x80000000) | |
9646 | { | |
9647 | print_vma (exidx_entry, PREFIX_HEX); | |
9648 | fputc ('\n', stdout); | |
9649 | decode_arm_unwind (filedata, aux, exidx_entry, 4, 0, NULL, NULL); | |
9650 | } | |
9651 | else | |
9652 | { | |
9653 | bfd_vma table, table_offset = 0; | |
9654 | Elf_Internal_Shdr *table_sec; | |
9655 | ||
9656 | fputs ("@", stdout); | |
9657 | table = arm_expand_prel31 (filedata, exidx_entry, exidx_sec->sh_addr + 8 * i + 4); | |
9658 | print_vma (table, PREFIX_HEX); | |
9659 | printf ("\n"); | |
9660 | ||
9661 | /* Locate the matching .ARM.extab. */ | |
9662 | if (entry_addr.section != SHN_UNDEF | |
9663 | && entry_addr.section < filedata->file_header.e_shnum) | |
9664 | { | |
9665 | table_sec = filedata->section_headers + entry_addr.section; | |
9666 | table_offset = entry_addr.offset; | |
9667 | /* PR 18879 */ | |
9668 | if (table_offset > table_sec->sh_size | |
9669 | || ((bfd_signed_vma) table_offset) < 0) | |
9670 | { | |
9671 | warn (_("Unwind entry contains corrupt offset (0x%lx) into section %s\n"), | |
9672 | (unsigned long) table_offset, | |
9673 | printable_section_name (filedata, table_sec)); | |
9674 | res = FALSE; | |
9675 | continue; | |
9676 | } | |
9677 | } | |
9678 | else | |
9679 | { | |
9680 | table_sec = find_section_by_address (filedata, table); | |
9681 | if (table_sec != NULL) | |
9682 | table_offset = table - table_sec->sh_addr; | |
9683 | } | |
9684 | ||
9685 | if (table_sec == NULL) | |
9686 | { | |
9687 | warn (_("Could not locate .ARM.extab section containing 0x%lx.\n"), | |
9688 | (unsigned long) table); | |
9689 | res = FALSE; | |
9690 | continue; | |
9691 | } | |
9692 | ||
9693 | if (! decode_arm_unwind (filedata, aux, 0, 0, table_offset, table_sec, | |
9694 | &extab_arm_sec)) | |
9695 | res = FALSE; | |
9696 | } | |
9697 | } | |
9698 | ||
9699 | printf ("\n"); | |
9700 | ||
9701 | free (aux->funtab); | |
9702 | arm_free_section (&exidx_arm_sec); | |
9703 | arm_free_section (&extab_arm_sec); | |
9704 | ||
9705 | return res; | |
9706 | } | |
9707 | ||
9708 | /* Used for both ARM and C6X unwinding tables. */ | |
9709 | ||
9710 | static bfd_boolean | |
9711 | arm_process_unwind (Filedata * filedata) | |
9712 | { | |
9713 | struct arm_unw_aux_info aux; | |
9714 | Elf_Internal_Shdr *unwsec = NULL; | |
9715 | Elf_Internal_Shdr *sec; | |
9716 | unsigned long i; | |
9717 | unsigned int sec_type; | |
9718 | bfd_boolean res = TRUE; | |
9719 | ||
9720 | switch (filedata->file_header.e_machine) | |
9721 | { | |
9722 | case EM_ARM: | |
9723 | sec_type = SHT_ARM_EXIDX; | |
9724 | break; | |
9725 | ||
9726 | case EM_TI_C6000: | |
9727 | sec_type = SHT_C6000_UNWIND; | |
9728 | break; | |
9729 | ||
9730 | default: | |
9731 | error (_("Unsupported architecture type %d encountered when processing unwind table\n"), | |
9732 | filedata->file_header.e_machine); | |
9733 | return FALSE; | |
9734 | } | |
9735 | ||
9736 | if (filedata->string_table == NULL) | |
9737 | return FALSE; | |
9738 | ||
9739 | memset (& aux, 0, sizeof (aux)); | |
9740 | aux.filedata = filedata; | |
9741 | ||
9742 | for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec) | |
9743 | { | |
9744 | if (sec->sh_type == SHT_SYMTAB) | |
9745 | { | |
9746 | if (aux.symtab) | |
9747 | { | |
9748 | error (_("Multiple symbol tables encountered\n")); | |
9749 | free (aux.symtab); | |
9750 | aux.symtab = NULL; | |
9751 | free (aux.strtab); | |
9752 | aux.strtab = NULL; | |
9753 | } | |
9754 | if (!get_symtab (filedata, sec, &aux.symtab, &aux.nsyms, | |
9755 | &aux.strtab, &aux.strtab_size)) | |
9756 | return FALSE; | |
9757 | } | |
9758 | else if (sec->sh_type == sec_type) | |
9759 | unwsec = sec; | |
9760 | } | |
9761 | ||
9762 | if (unwsec == NULL) | |
9763 | printf (_("\nThere are no unwind sections in this file.\n")); | |
9764 | else | |
9765 | for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec) | |
9766 | { | |
9767 | if (sec->sh_type == sec_type) | |
9768 | { | |
9769 | unsigned long num_unwind = sec->sh_size / (2 * eh_addr_size); | |
9770 | printf (ngettext ("\nUnwind section '%s' at offset 0x%lx " | |
9771 | "contains %lu entry:\n", | |
9772 | "\nUnwind section '%s' at offset 0x%lx " | |
9773 | "contains %lu entries:\n", | |
9774 | num_unwind), | |
9775 | printable_section_name (filedata, sec), | |
9776 | (unsigned long) sec->sh_offset, | |
9777 | num_unwind); | |
9778 | ||
9779 | if (! dump_arm_unwind (filedata, &aux, sec)) | |
9780 | res = FALSE; | |
9781 | } | |
9782 | } | |
9783 | ||
9784 | free (aux.symtab); | |
9785 | free ((char *) aux.strtab); | |
9786 | ||
9787 | return res; | |
9788 | } | |
9789 | ||
9790 | static bfd_boolean | |
9791 | process_unwind (Filedata * filedata) | |
9792 | { | |
9793 | struct unwind_handler | |
9794 | { | |
9795 | unsigned int machtype; | |
9796 | bfd_boolean (* handler)(Filedata *); | |
9797 | } handlers[] = | |
9798 | { | |
9799 | { EM_ARM, arm_process_unwind }, | |
9800 | { EM_IA_64, ia64_process_unwind }, | |
9801 | { EM_PARISC, hppa_process_unwind }, | |
9802 | { EM_TI_C6000, arm_process_unwind }, | |
9803 | { 0, NULL } | |
9804 | }; | |
9805 | int i; | |
9806 | ||
9807 | if (!do_unwind) | |
9808 | return TRUE; | |
9809 | ||
9810 | for (i = 0; handlers[i].handler != NULL; i++) | |
9811 | if (filedata->file_header.e_machine == handlers[i].machtype) | |
9812 | return handlers[i].handler (filedata); | |
9813 | ||
9814 | printf (_("\nThe decoding of unwind sections for machine type %s is not currently supported.\n"), | |
9815 | get_machine_name (filedata->file_header.e_machine)); | |
9816 | return TRUE; | |
9817 | } | |
9818 | ||
9819 | static void | |
9820 | dynamic_section_aarch64_val (Elf_Internal_Dyn * entry) | |
9821 | { | |
9822 | switch (entry->d_tag) | |
9823 | { | |
9824 | case DT_AARCH64_BTI_PLT: | |
9825 | case DT_AARCH64_PAC_PLT: | |
9826 | break; | |
9827 | default: | |
9828 | print_vma (entry->d_un.d_ptr, PREFIX_HEX); | |
9829 | break; | |
9830 | } | |
9831 | putchar ('\n'); | |
9832 | } | |
9833 | ||
9834 | static void | |
9835 | dynamic_section_mips_val (Filedata * filedata, Elf_Internal_Dyn * entry) | |
9836 | { | |
9837 | switch (entry->d_tag) | |
9838 | { | |
9839 | case DT_MIPS_FLAGS: | |
9840 | if (entry->d_un.d_val == 0) | |
9841 | printf (_("NONE")); | |
9842 | else | |
9843 | { | |
9844 | static const char * opts[] = | |
9845 | { | |
9846 | "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT", | |
9847 | "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS", | |
9848 | "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD", | |
9849 | "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF", | |
9850 | "RLD_ORDER_SAFE" | |
9851 | }; | |
9852 | unsigned int cnt; | |
9853 | bfd_boolean first = TRUE; | |
9854 | ||
9855 | for (cnt = 0; cnt < ARRAY_SIZE (opts); ++cnt) | |
9856 | if (entry->d_un.d_val & (1 << cnt)) | |
9857 | { | |
9858 | printf ("%s%s", first ? "" : " ", opts[cnt]); | |
9859 | first = FALSE; | |
9860 | } | |
9861 | } | |
9862 | break; | |
9863 | ||
9864 | case DT_MIPS_IVERSION: | |
9865 | if (VALID_DYNAMIC_NAME (filedata, entry->d_un.d_val)) | |
9866 | printf (_("Interface Version: %s"), | |
9867 | GET_DYNAMIC_NAME (filedata, entry->d_un.d_val)); | |
9868 | else | |
9869 | { | |
9870 | char buf[40]; | |
9871 | sprintf_vma (buf, entry->d_un.d_ptr); | |
9872 | /* Note: coded this way so that there is a single string for translation. */ | |
9873 | printf (_("<corrupt: %s>"), buf); | |
9874 | } | |
9875 | break; | |
9876 | ||
9877 | case DT_MIPS_TIME_STAMP: | |
9878 | { | |
9879 | char timebuf[128]; | |
9880 | struct tm * tmp; | |
9881 | time_t atime = entry->d_un.d_val; | |
9882 | ||
9883 | tmp = gmtime (&atime); | |
9884 | /* PR 17531: file: 6accc532. */ | |
9885 | if (tmp == NULL) | |
9886 | snprintf (timebuf, sizeof (timebuf), _("<corrupt>")); | |
9887 | else | |
9888 | snprintf (timebuf, sizeof (timebuf), "%04u-%02u-%02uT%02u:%02u:%02u", | |
9889 | tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday, | |
9890 | tmp->tm_hour, tmp->tm_min, tmp->tm_sec); | |
9891 | printf (_("Time Stamp: %s"), timebuf); | |
9892 | } | |
9893 | break; | |
9894 | ||
9895 | case DT_MIPS_RLD_VERSION: | |
9896 | case DT_MIPS_LOCAL_GOTNO: | |
9897 | case DT_MIPS_CONFLICTNO: | |
9898 | case DT_MIPS_LIBLISTNO: | |
9899 | case DT_MIPS_SYMTABNO: | |
9900 | case DT_MIPS_UNREFEXTNO: | |
9901 | case DT_MIPS_HIPAGENO: | |
9902 | case DT_MIPS_DELTA_CLASS_NO: | |
9903 | case DT_MIPS_DELTA_INSTANCE_NO: | |
9904 | case DT_MIPS_DELTA_RELOC_NO: | |
9905 | case DT_MIPS_DELTA_SYM_NO: | |
9906 | case DT_MIPS_DELTA_CLASSSYM_NO: | |
9907 | case DT_MIPS_COMPACT_SIZE: | |
9908 | print_vma (entry->d_un.d_val, DEC); | |
9909 | break; | |
9910 | ||
9911 | case DT_MIPS_XHASH: | |
9912 | filedata->dynamic_info_DT_MIPS_XHASH = entry->d_un.d_val; | |
9913 | filedata->dynamic_info_DT_GNU_HASH = entry->d_un.d_val; | |
9914 | /* Falls through. */ | |
9915 | ||
9916 | default: | |
9917 | print_vma (entry->d_un.d_ptr, PREFIX_HEX); | |
9918 | } | |
9919 | putchar ('\n'); | |
9920 | } | |
9921 | ||
9922 | static void | |
9923 | dynamic_section_parisc_val (Elf_Internal_Dyn * entry) | |
9924 | { | |
9925 | switch (entry->d_tag) | |
9926 | { | |
9927 | case DT_HP_DLD_FLAGS: | |
9928 | { | |
9929 | static struct | |
9930 | { | |
9931 | long int bit; | |
9932 | const char * str; | |
9933 | } | |
9934 | flags[] = | |
9935 | { | |
9936 | { DT_HP_DEBUG_PRIVATE, "HP_DEBUG_PRIVATE" }, | |
9937 | { DT_HP_DEBUG_CALLBACK, "HP_DEBUG_CALLBACK" }, | |
9938 | { DT_HP_DEBUG_CALLBACK_BOR, "HP_DEBUG_CALLBACK_BOR" }, | |
9939 | { DT_HP_NO_ENVVAR, "HP_NO_ENVVAR" }, | |
9940 | { DT_HP_BIND_NOW, "HP_BIND_NOW" }, | |
9941 | { DT_HP_BIND_NONFATAL, "HP_BIND_NONFATAL" }, | |
9942 | { DT_HP_BIND_VERBOSE, "HP_BIND_VERBOSE" }, | |
9943 | { DT_HP_BIND_RESTRICTED, "HP_BIND_RESTRICTED" }, | |
9944 | { DT_HP_BIND_SYMBOLIC, "HP_BIND_SYMBOLIC" }, | |
9945 | { DT_HP_RPATH_FIRST, "HP_RPATH_FIRST" }, | |
9946 | { DT_HP_BIND_DEPTH_FIRST, "HP_BIND_DEPTH_FIRST" }, | |
9947 | { DT_HP_GST, "HP_GST" }, | |
9948 | { DT_HP_SHLIB_FIXED, "HP_SHLIB_FIXED" }, | |
9949 | { DT_HP_MERGE_SHLIB_SEG, "HP_MERGE_SHLIB_SEG" }, | |
9950 | { DT_HP_NODELETE, "HP_NODELETE" }, | |
9951 | { DT_HP_GROUP, "HP_GROUP" }, | |
9952 | { DT_HP_PROTECT_LINKAGE_TABLE, "HP_PROTECT_LINKAGE_TABLE" } | |
9953 | }; | |
9954 | bfd_boolean first = TRUE; | |
9955 | size_t cnt; | |
9956 | bfd_vma val = entry->d_un.d_val; | |
9957 | ||
9958 | for (cnt = 0; cnt < ARRAY_SIZE (flags); ++cnt) | |
9959 | if (val & flags[cnt].bit) | |
9960 | { | |
9961 | if (! first) | |
9962 | putchar (' '); | |
9963 | fputs (flags[cnt].str, stdout); | |
9964 | first = FALSE; | |
9965 | val ^= flags[cnt].bit; | |
9966 | } | |
9967 | ||
9968 | if (val != 0 || first) | |
9969 | { | |
9970 | if (! first) | |
9971 | putchar (' '); | |
9972 | print_vma (val, HEX); | |
9973 | } | |
9974 | } | |
9975 | break; | |
9976 | ||
9977 | default: | |
9978 | print_vma (entry->d_un.d_ptr, PREFIX_HEX); | |
9979 | break; | |
9980 | } | |
9981 | putchar ('\n'); | |
9982 | } | |
9983 | ||
9984 | #ifdef BFD64 | |
9985 | ||
9986 | /* VMS vs Unix time offset and factor. */ | |
9987 | ||
9988 | #define VMS_EPOCH_OFFSET 35067168000000000LL | |
9989 | #define VMS_GRANULARITY_FACTOR 10000000 | |
9990 | #ifndef INT64_MIN | |
9991 | #define INT64_MIN (-9223372036854775807LL - 1) | |
9992 | #endif | |
9993 | ||
9994 | /* Display a VMS time in a human readable format. */ | |
9995 | ||
9996 | static void | |
9997 | print_vms_time (bfd_int64_t vmstime) | |
9998 | { | |
9999 | struct tm *tm = NULL; | |
10000 | time_t unxtime; | |
10001 | ||
10002 | if (vmstime >= INT64_MIN + VMS_EPOCH_OFFSET) | |
10003 | { | |
10004 | vmstime = (vmstime - VMS_EPOCH_OFFSET) / VMS_GRANULARITY_FACTOR; | |
10005 | unxtime = vmstime; | |
10006 | if (unxtime == vmstime) | |
10007 | tm = gmtime (&unxtime); | |
10008 | } | |
10009 | if (tm != NULL) | |
10010 | printf ("%04u-%02u-%02uT%02u:%02u:%02u", | |
10011 | tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, | |
10012 | tm->tm_hour, tm->tm_min, tm->tm_sec); | |
10013 | } | |
10014 | #endif /* BFD64 */ | |
10015 | ||
10016 | static void | |
10017 | dynamic_section_ia64_val (Elf_Internal_Dyn * entry) | |
10018 | { | |
10019 | switch (entry->d_tag) | |
10020 | { | |
10021 | case DT_IA_64_PLT_RESERVE: | |
10022 | /* First 3 slots reserved. */ | |
10023 | print_vma (entry->d_un.d_ptr, PREFIX_HEX); | |
10024 | printf (" -- "); | |
10025 | print_vma (entry->d_un.d_ptr + (3 * 8), PREFIX_HEX); | |
10026 | break; | |
10027 | ||
10028 | case DT_IA_64_VMS_LINKTIME: | |
10029 | #ifdef BFD64 | |
10030 | print_vms_time (entry->d_un.d_val); | |
10031 | #endif | |
10032 | break; | |
10033 | ||
10034 | case DT_IA_64_VMS_LNKFLAGS: | |
10035 | print_vma (entry->d_un.d_ptr, PREFIX_HEX); | |
10036 | if (entry->d_un.d_val & VMS_LF_CALL_DEBUG) | |
10037 | printf (" CALL_DEBUG"); | |
10038 | if (entry->d_un.d_val & VMS_LF_NOP0BUFS) | |
10039 | printf (" NOP0BUFS"); | |
10040 | if (entry->d_un.d_val & VMS_LF_P0IMAGE) | |
10041 | printf (" P0IMAGE"); | |
10042 | if (entry->d_un.d_val & VMS_LF_MKTHREADS) | |
10043 | printf (" MKTHREADS"); | |
10044 | if (entry->d_un.d_val & VMS_LF_UPCALLS) | |
10045 | printf (" UPCALLS"); | |
10046 | if (entry->d_un.d_val & VMS_LF_IMGSTA) | |
10047 | printf (" IMGSTA"); | |
10048 | if (entry->d_un.d_val & VMS_LF_INITIALIZE) | |
10049 | printf (" INITIALIZE"); | |
10050 | if (entry->d_un.d_val & VMS_LF_MAIN) | |
10051 | printf (" MAIN"); | |
10052 | if (entry->d_un.d_val & VMS_LF_EXE_INIT) | |
10053 | printf (" EXE_INIT"); | |
10054 | if (entry->d_un.d_val & VMS_LF_TBK_IN_IMG) | |
10055 | printf (" TBK_IN_IMG"); | |
10056 | if (entry->d_un.d_val & VMS_LF_DBG_IN_IMG) | |
10057 | printf (" DBG_IN_IMG"); | |
10058 | if (entry->d_un.d_val & VMS_LF_TBK_IN_DSF) | |
10059 | printf (" TBK_IN_DSF"); | |
10060 | if (entry->d_un.d_val & VMS_LF_DBG_IN_DSF) | |
10061 | printf (" DBG_IN_DSF"); | |
10062 | if (entry->d_un.d_val & VMS_LF_SIGNATURES) | |
10063 | printf (" SIGNATURES"); | |
10064 | if (entry->d_un.d_val & VMS_LF_REL_SEG_OFF) | |
10065 | printf (" REL_SEG_OFF"); | |
10066 | break; | |
10067 | ||
10068 | default: | |
10069 | print_vma (entry->d_un.d_ptr, PREFIX_HEX); | |
10070 | break; | |
10071 | } | |
10072 | putchar ('\n'); | |
10073 | } | |
10074 | ||
10075 | static bfd_boolean | |
10076 | get_32bit_dynamic_section (Filedata * filedata) | |
10077 | { | |
10078 | Elf32_External_Dyn * edyn; | |
10079 | Elf32_External_Dyn * ext; | |
10080 | Elf_Internal_Dyn * entry; | |
10081 | ||
10082 | edyn = (Elf32_External_Dyn *) get_data (NULL, filedata, | |
10083 | filedata->dynamic_addr, 1, | |
10084 | filedata->dynamic_size, | |
10085 | _("dynamic section")); | |
10086 | if (!edyn) | |
10087 | return FALSE; | |
10088 | ||
10089 | /* SGI's ELF has more than one section in the DYNAMIC segment, and we | |
10090 | might not have the luxury of section headers. Look for the DT_NULL | |
10091 | terminator to determine the number of entries. */ | |
10092 | for (ext = edyn, filedata->dynamic_nent = 0; | |
10093 | (char *) (ext + 1) <= (char *) edyn + filedata->dynamic_size; | |
10094 | ext++) | |
10095 | { | |
10096 | filedata->dynamic_nent++; | |
10097 | if (BYTE_GET (ext->d_tag) == DT_NULL) | |
10098 | break; | |
10099 | } | |
10100 | ||
10101 | filedata->dynamic_section | |
10102 | = (Elf_Internal_Dyn *) cmalloc (filedata->dynamic_nent, sizeof (* entry)); | |
10103 | if (filedata->dynamic_section == NULL) | |
10104 | { | |
10105 | error (_("Out of memory allocating space for %lu dynamic entries\n"), | |
10106 | (unsigned long) filedata->dynamic_nent); | |
10107 | free (edyn); | |
10108 | return FALSE; | |
10109 | } | |
10110 | ||
10111 | for (ext = edyn, entry = filedata->dynamic_section; | |
10112 | entry < filedata->dynamic_section + filedata->dynamic_nent; | |
10113 | ext++, entry++) | |
10114 | { | |
10115 | entry->d_tag = BYTE_GET (ext->d_tag); | |
10116 | entry->d_un.d_val = BYTE_GET (ext->d_un.d_val); | |
10117 | } | |
10118 | ||
10119 | free (edyn); | |
10120 | ||
10121 | return TRUE; | |
10122 | } | |
10123 | ||
10124 | static bfd_boolean | |
10125 | get_64bit_dynamic_section (Filedata * filedata) | |
10126 | { | |
10127 | Elf64_External_Dyn * edyn; | |
10128 | Elf64_External_Dyn * ext; | |
10129 | Elf_Internal_Dyn * entry; | |
10130 | ||
10131 | /* Read in the data. */ | |
10132 | edyn = (Elf64_External_Dyn *) get_data (NULL, filedata, | |
10133 | filedata->dynamic_addr, 1, | |
10134 | filedata->dynamic_size, | |
10135 | _("dynamic section")); | |
10136 | if (!edyn) | |
10137 | return FALSE; | |
10138 | ||
10139 | /* SGI's ELF has more than one section in the DYNAMIC segment, and we | |
10140 | might not have the luxury of section headers. Look for the DT_NULL | |
10141 | terminator to determine the number of entries. */ | |
10142 | for (ext = edyn, filedata->dynamic_nent = 0; | |
10143 | /* PR 17533 file: 033-67080-0.004 - do not read past end of buffer. */ | |
10144 | (char *) (ext + 1) <= (char *) edyn + filedata->dynamic_size; | |
10145 | ext++) | |
10146 | { | |
10147 | filedata->dynamic_nent++; | |
10148 | if (BYTE_GET (ext->d_tag) == DT_NULL) | |
10149 | break; | |
10150 | } | |
10151 | ||
10152 | filedata->dynamic_section | |
10153 | = (Elf_Internal_Dyn *) cmalloc (filedata->dynamic_nent, sizeof (* entry)); | |
10154 | if (filedata->dynamic_section == NULL) | |
10155 | { | |
10156 | error (_("Out of memory allocating space for %lu dynamic entries\n"), | |
10157 | (unsigned long) filedata->dynamic_nent); | |
10158 | free (edyn); | |
10159 | return FALSE; | |
10160 | } | |
10161 | ||
10162 | /* Convert from external to internal formats. */ | |
10163 | for (ext = edyn, entry = filedata->dynamic_section; | |
10164 | entry < filedata->dynamic_section + filedata->dynamic_nent; | |
10165 | ext++, entry++) | |
10166 | { | |
10167 | entry->d_tag = BYTE_GET (ext->d_tag); | |
10168 | entry->d_un.d_val = BYTE_GET (ext->d_un.d_val); | |
10169 | } | |
10170 | ||
10171 | free (edyn); | |
10172 | ||
10173 | return TRUE; | |
10174 | } | |
10175 | ||
10176 | static void | |
10177 | print_dynamic_flags (bfd_vma flags) | |
10178 | { | |
10179 | bfd_boolean first = TRUE; | |
10180 | ||
10181 | while (flags) | |
10182 | { | |
10183 | bfd_vma flag; | |
10184 | ||
10185 | flag = flags & - flags; | |
10186 | flags &= ~ flag; | |
10187 | ||
10188 | if (first) | |
10189 | first = FALSE; | |
10190 | else | |
10191 | putc (' ', stdout); | |
10192 | ||
10193 | switch (flag) | |
10194 | { | |
10195 | case DF_ORIGIN: fputs ("ORIGIN", stdout); break; | |
10196 | case DF_SYMBOLIC: fputs ("SYMBOLIC", stdout); break; | |
10197 | case DF_TEXTREL: fputs ("TEXTREL", stdout); break; | |
10198 | case DF_BIND_NOW: fputs ("BIND_NOW", stdout); break; | |
10199 | case DF_STATIC_TLS: fputs ("STATIC_TLS", stdout); break; | |
10200 | default: fputs (_("unknown"), stdout); break; | |
10201 | } | |
10202 | } | |
10203 | puts (""); | |
10204 | } | |
10205 | ||
10206 | static bfd_vma * | |
10207 | get_dynamic_data (Filedata * filedata, bfd_size_type number, unsigned int ent_size) | |
10208 | { | |
10209 | unsigned char * e_data; | |
10210 | bfd_vma * i_data; | |
10211 | ||
10212 | /* If the size_t type is smaller than the bfd_size_type, eg because | |
10213 | you are building a 32-bit tool on a 64-bit host, then make sure | |
10214 | that when (number) is cast to (size_t) no information is lost. */ | |
10215 | if (sizeof (size_t) < sizeof (bfd_size_type) | |
10216 | && (bfd_size_type) ((size_t) number) != number) | |
10217 | { | |
10218 | error (_("Size truncation prevents reading %s elements of size %u\n"), | |
10219 | bfd_vmatoa ("u", number), ent_size); | |
10220 | return NULL; | |
10221 | } | |
10222 | ||
10223 | /* Be kind to memory checkers (eg valgrind, address sanitizer) by not | |
10224 | attempting to allocate memory when the read is bound to fail. */ | |
10225 | if (ent_size * number > filedata->file_size) | |
10226 | { | |
10227 | error (_("Invalid number of dynamic entries: %s\n"), | |
10228 | bfd_vmatoa ("u", number)); | |
10229 | return NULL; | |
10230 | } | |
10231 | ||
10232 | e_data = (unsigned char *) cmalloc ((size_t) number, ent_size); | |
10233 | if (e_data == NULL) | |
10234 | { | |
10235 | error (_("Out of memory reading %s dynamic entries\n"), | |
10236 | bfd_vmatoa ("u", number)); | |
10237 | return NULL; | |
10238 | } | |
10239 | ||
10240 | if (fread (e_data, ent_size, (size_t) number, filedata->handle) != number) | |
10241 | { | |
10242 | error (_("Unable to read in %s bytes of dynamic data\n"), | |
10243 | bfd_vmatoa ("u", number * ent_size)); | |
10244 | free (e_data); | |
10245 | return NULL; | |
10246 | } | |
10247 | ||
10248 | i_data = (bfd_vma *) cmalloc ((size_t) number, sizeof (*i_data)); | |
10249 | if (i_data == NULL) | |
10250 | { | |
10251 | error (_("Out of memory allocating space for %s dynamic entries\n"), | |
10252 | bfd_vmatoa ("u", number)); | |
10253 | free (e_data); | |
10254 | return NULL; | |
10255 | } | |
10256 | ||
10257 | while (number--) | |
10258 | i_data[number] = byte_get (e_data + number * ent_size, ent_size); | |
10259 | ||
10260 | free (e_data); | |
10261 | ||
10262 | return i_data; | |
10263 | } | |
10264 | ||
10265 | static unsigned long | |
10266 | get_num_dynamic_syms (Filedata * filedata) | |
10267 | { | |
10268 | unsigned long num_of_syms = 0; | |
10269 | ||
10270 | if (!do_histogram && (!do_using_dynamic || do_dyn_syms)) | |
10271 | return num_of_syms; | |
10272 | ||
10273 | if (filedata->dynamic_info[DT_HASH]) | |
10274 | { | |
10275 | unsigned char nb[8]; | |
10276 | unsigned char nc[8]; | |
10277 | unsigned int hash_ent_size = 4; | |
10278 | ||
10279 | if ((filedata->file_header.e_machine == EM_ALPHA | |
10280 | || filedata->file_header.e_machine == EM_S390 | |
10281 | || filedata->file_header.e_machine == EM_S390_OLD) | |
10282 | && filedata->file_header.e_ident[EI_CLASS] == ELFCLASS64) | |
10283 | hash_ent_size = 8; | |
10284 | ||
10285 | if (fseek (filedata->handle, | |
10286 | (filedata->archive_file_offset | |
10287 | + offset_from_vma (filedata, filedata->dynamic_info[DT_HASH], | |
10288 | sizeof nb + sizeof nc)), | |
10289 | SEEK_SET)) | |
10290 | { | |
10291 | error (_("Unable to seek to start of dynamic information\n")); | |
10292 | goto no_hash; | |
10293 | } | |
10294 | ||
10295 | if (fread (nb, hash_ent_size, 1, filedata->handle) != 1) | |
10296 | { | |
10297 | error (_("Failed to read in number of buckets\n")); | |
10298 | goto no_hash; | |
10299 | } | |
10300 | ||
10301 | if (fread (nc, hash_ent_size, 1, filedata->handle) != 1) | |
10302 | { | |
10303 | error (_("Failed to read in number of chains\n")); | |
10304 | goto no_hash; | |
10305 | } | |
10306 | ||
10307 | filedata->nbuckets = byte_get (nb, hash_ent_size); | |
10308 | filedata->nchains = byte_get (nc, hash_ent_size); | |
10309 | ||
10310 | if (filedata->nbuckets != 0 && filedata->nchains != 0) | |
10311 | { | |
10312 | filedata->buckets = get_dynamic_data (filedata, filedata->nbuckets, | |
10313 | hash_ent_size); | |
10314 | filedata->chains = get_dynamic_data (filedata, filedata->nchains, | |
10315 | hash_ent_size); | |
10316 | ||
10317 | if (filedata->buckets != NULL && filedata->chains != NULL) | |
10318 | num_of_syms = filedata->nchains; | |
10319 | } | |
10320 | no_hash: | |
10321 | if (num_of_syms == 0) | |
10322 | { | |
10323 | free (filedata->buckets); | |
10324 | filedata->buckets = NULL; | |
10325 | free (filedata->chains); | |
10326 | filedata->chains = NULL; | |
10327 | filedata->nbuckets = 0; | |
10328 | } | |
10329 | } | |
10330 | ||
10331 | if (filedata->dynamic_info_DT_GNU_HASH) | |
10332 | { | |
10333 | unsigned char nb[16]; | |
10334 | bfd_vma i, maxchain = 0xffffffff, bitmaskwords; | |
10335 | bfd_vma buckets_vma; | |
10336 | unsigned long hn; | |
10337 | ||
10338 | if (fseek (filedata->handle, | |
10339 | (filedata->archive_file_offset | |
10340 | + offset_from_vma (filedata, | |
10341 | filedata->dynamic_info_DT_GNU_HASH, | |
10342 | sizeof nb)), | |
10343 | SEEK_SET)) | |
10344 | { | |
10345 | error (_("Unable to seek to start of dynamic information\n")); | |
10346 | goto no_gnu_hash; | |
10347 | } | |
10348 | ||
10349 | if (fread (nb, 16, 1, filedata->handle) != 1) | |
10350 | { | |
10351 | error (_("Failed to read in number of buckets\n")); | |
10352 | goto no_gnu_hash; | |
10353 | } | |
10354 | ||
10355 | filedata->ngnubuckets = byte_get (nb, 4); | |
10356 | filedata->gnusymidx = byte_get (nb + 4, 4); | |
10357 | bitmaskwords = byte_get (nb + 8, 4); | |
10358 | buckets_vma = filedata->dynamic_info_DT_GNU_HASH + 16; | |
10359 | if (is_32bit_elf) | |
10360 | buckets_vma += bitmaskwords * 4; | |
10361 | else | |
10362 | buckets_vma += bitmaskwords * 8; | |
10363 | ||
10364 | if (fseek (filedata->handle, | |
10365 | (filedata->archive_file_offset | |
10366 | + offset_from_vma (filedata, buckets_vma, 4)), | |
10367 | SEEK_SET)) | |
10368 | { | |
10369 | error (_("Unable to seek to start of dynamic information\n")); | |
10370 | goto no_gnu_hash; | |
10371 | } | |
10372 | ||
10373 | filedata->gnubuckets | |
10374 | = get_dynamic_data (filedata, filedata->ngnubuckets, 4); | |
10375 | ||
10376 | if (filedata->gnubuckets == NULL) | |
10377 | goto no_gnu_hash; | |
10378 | ||
10379 | for (i = 0; i < filedata->ngnubuckets; i++) | |
10380 | if (filedata->gnubuckets[i] != 0) | |
10381 | { | |
10382 | if (filedata->gnubuckets[i] < filedata->gnusymidx) | |
10383 | goto no_gnu_hash; | |
10384 | ||
10385 | if (maxchain == 0xffffffff || filedata->gnubuckets[i] > maxchain) | |
10386 | maxchain = filedata->gnubuckets[i]; | |
10387 | } | |
10388 | ||
10389 | if (maxchain == 0xffffffff) | |
10390 | goto no_gnu_hash; | |
10391 | ||
10392 | maxchain -= filedata->gnusymidx; | |
10393 | ||
10394 | if (fseek (filedata->handle, | |
10395 | (filedata->archive_file_offset | |
10396 | + offset_from_vma (filedata, | |
10397 | buckets_vma + 4 * (filedata->ngnubuckets | |
10398 | + maxchain), | |
10399 | 4)), | |
10400 | SEEK_SET)) | |
10401 | { | |
10402 | error (_("Unable to seek to start of dynamic information\n")); | |
10403 | goto no_gnu_hash; | |
10404 | } | |
10405 | ||
10406 | do | |
10407 | { | |
10408 | if (fread (nb, 4, 1, filedata->handle) != 1) | |
10409 | { | |
10410 | error (_("Failed to determine last chain length\n")); | |
10411 | goto no_gnu_hash; | |
10412 | } | |
10413 | ||
10414 | if (maxchain + 1 == 0) | |
10415 | goto no_gnu_hash; | |
10416 | ||
10417 | ++maxchain; | |
10418 | } | |
10419 | while ((byte_get (nb, 4) & 1) == 0); | |
10420 | ||
10421 | if (fseek (filedata->handle, | |
10422 | (filedata->archive_file_offset | |
10423 | + offset_from_vma (filedata, (buckets_vma | |
10424 | + 4 * filedata->ngnubuckets), | |
10425 | 4)), | |
10426 | SEEK_SET)) | |
10427 | { | |
10428 | error (_("Unable to seek to start of dynamic information\n")); | |
10429 | goto no_gnu_hash; | |
10430 | } | |
10431 | ||
10432 | filedata->gnuchains = get_dynamic_data (filedata, maxchain, 4); | |
10433 | filedata->ngnuchains = maxchain; | |
10434 | ||
10435 | if (filedata->gnuchains == NULL) | |
10436 | goto no_gnu_hash; | |
10437 | ||
10438 | if (filedata->dynamic_info_DT_MIPS_XHASH) | |
10439 | { | |
10440 | if (fseek (filedata->handle, | |
10441 | (filedata->archive_file_offset | |
10442 | + offset_from_vma (filedata, (buckets_vma | |
10443 | + 4 * (filedata->ngnubuckets | |
10444 | + maxchain)), 4)), | |
10445 | SEEK_SET)) | |
10446 | { | |
10447 | error (_("Unable to seek to start of dynamic information\n")); | |
10448 | goto no_gnu_hash; | |
10449 | } | |
10450 | ||
10451 | filedata->mipsxlat = get_dynamic_data (filedata, maxchain, 4); | |
10452 | if (filedata->mipsxlat == NULL) | |
10453 | goto no_gnu_hash; | |
10454 | } | |
10455 | ||
10456 | for (hn = 0; hn < filedata->ngnubuckets; ++hn) | |
10457 | if (filedata->gnubuckets[hn] != 0) | |
10458 | { | |
10459 | bfd_vma si = filedata->gnubuckets[hn]; | |
10460 | bfd_vma off = si - filedata->gnusymidx; | |
10461 | ||
10462 | do | |
10463 | { | |
10464 | if (filedata->dynamic_info_DT_MIPS_XHASH) | |
10465 | { | |
10466 | if (off < filedata->ngnuchains | |
10467 | && filedata->mipsxlat[off] >= num_of_syms) | |
10468 | num_of_syms = filedata->mipsxlat[off] + 1; | |
10469 | } | |
10470 | else | |
10471 | { | |
10472 | if (si >= num_of_syms) | |
10473 | num_of_syms = si + 1; | |
10474 | } | |
10475 | si++; | |
10476 | } | |
10477 | while (off < filedata->ngnuchains | |
10478 | && (filedata->gnuchains[off++] & 1) == 0); | |
10479 | } | |
10480 | ||
10481 | if (num_of_syms == 0) | |
10482 | { | |
10483 | no_gnu_hash: | |
10484 | free (filedata->mipsxlat); | |
10485 | filedata->mipsxlat = NULL; | |
10486 | free (filedata->gnuchains); | |
10487 | filedata->gnuchains = NULL; | |
10488 | free (filedata->gnubuckets); | |
10489 | filedata->gnubuckets = NULL; | |
10490 | filedata->ngnubuckets = 0; | |
10491 | filedata->ngnuchains = 0; | |
10492 | } | |
10493 | } | |
10494 | ||
10495 | return num_of_syms; | |
10496 | } | |
10497 | ||
10498 | /* Parse and display the contents of the dynamic section. */ | |
10499 | ||
10500 | static bfd_boolean | |
10501 | process_dynamic_section (Filedata * filedata) | |
10502 | { | |
10503 | Elf_Internal_Dyn * entry; | |
10504 | ||
10505 | if (filedata->dynamic_size == 0) | |
10506 | { | |
10507 | if (do_dynamic) | |
10508 | { | |
10509 | if (filedata->is_separate) | |
10510 | printf (_("\nThere is no dynamic section in linked file '%s'.\n"), | |
10511 | filedata->file_name); | |
10512 | else | |
10513 | printf (_("\nThere is no dynamic section in this file.\n")); | |
10514 | } | |
10515 | ||
10516 | return TRUE; | |
10517 | } | |
10518 | ||
10519 | if (is_32bit_elf) | |
10520 | { | |
10521 | if (! get_32bit_dynamic_section (filedata)) | |
10522 | return FALSE; | |
10523 | } | |
10524 | else | |
10525 | { | |
10526 | if (! get_64bit_dynamic_section (filedata)) | |
10527 | return FALSE; | |
10528 | } | |
10529 | ||
10530 | /* Find the appropriate symbol table. */ | |
10531 | if (filedata->dynamic_symbols == NULL || do_histogram) | |
10532 | { | |
10533 | unsigned long num_of_syms; | |
10534 | ||
10535 | for (entry = filedata->dynamic_section; | |
10536 | entry < filedata->dynamic_section + filedata->dynamic_nent; | |
10537 | ++entry) | |
10538 | if (entry->d_tag == DT_SYMTAB) | |
10539 | filedata->dynamic_info[DT_SYMTAB] = entry->d_un.d_val; | |
10540 | else if (entry->d_tag == DT_SYMENT) | |
10541 | filedata->dynamic_info[DT_SYMENT] = entry->d_un.d_val; | |
10542 | else if (entry->d_tag == DT_HASH) | |
10543 | filedata->dynamic_info[DT_HASH] = entry->d_un.d_val; | |
10544 | else if (entry->d_tag == DT_GNU_HASH) | |
10545 | filedata->dynamic_info_DT_GNU_HASH = entry->d_un.d_val; | |
10546 | else if ((filedata->file_header.e_machine == EM_MIPS | |
10547 | || filedata->file_header.e_machine == EM_MIPS_RS3_LE) | |
10548 | && entry->d_tag == DT_MIPS_XHASH) | |
10549 | { | |
10550 | filedata->dynamic_info_DT_MIPS_XHASH = entry->d_un.d_val; | |
10551 | filedata->dynamic_info_DT_GNU_HASH = entry->d_un.d_val; | |
10552 | } | |
10553 | ||
10554 | num_of_syms = get_num_dynamic_syms (filedata); | |
10555 | ||
10556 | if (num_of_syms != 0 | |
10557 | && filedata->dynamic_symbols == NULL | |
10558 | && filedata->dynamic_info[DT_SYMTAB] | |
10559 | && filedata->dynamic_info[DT_SYMENT]) | |
10560 | { | |
10561 | Elf_Internal_Phdr *seg; | |
10562 | bfd_vma vma = filedata->dynamic_info[DT_SYMTAB]; | |
10563 | ||
10564 | if (! get_program_headers (filedata)) | |
10565 | { | |
10566 | error (_("Cannot interpret virtual addresses " | |
10567 | "without program headers.\n")); | |
10568 | return FALSE; | |
10569 | } | |
10570 | ||
10571 | for (seg = filedata->program_headers; | |
10572 | seg < filedata->program_headers + filedata->file_header.e_phnum; | |
10573 | ++seg) | |
10574 | { | |
10575 | if (seg->p_type != PT_LOAD) | |
10576 | continue; | |
10577 | ||
10578 | if (seg->p_offset + seg->p_filesz > filedata->file_size) | |
10579 | { | |
10580 | /* See PR 21379 for a reproducer. */ | |
10581 | error (_("Invalid PT_LOAD entry\n")); | |
10582 | return FALSE; | |
10583 | } | |
10584 | ||
10585 | if (vma >= (seg->p_vaddr & -seg->p_align) | |
10586 | && vma < seg->p_vaddr + seg->p_filesz) | |
10587 | { | |
10588 | /* Since we do not know how big the symbol table is, | |
10589 | we default to reading in up to the end of PT_LOAD | |
10590 | segment and processing that. This is overkill, I | |
10591 | know, but it should work. */ | |
10592 | Elf_Internal_Shdr section; | |
10593 | section.sh_offset = (vma - seg->p_vaddr | |
10594 | + seg->p_offset); | |
10595 | section.sh_size = (num_of_syms | |
10596 | * filedata->dynamic_info[DT_SYMENT]); | |
10597 | section.sh_entsize = filedata->dynamic_info[DT_SYMENT]; | |
10598 | ||
10599 | if (do_checks | |
10600 | && filedata->dynamic_symtab_section != NULL | |
10601 | && ((filedata->dynamic_symtab_section->sh_offset | |
10602 | != section.sh_offset) | |
10603 | || (filedata->dynamic_symtab_section->sh_size | |
10604 | != section.sh_size) | |
10605 | || (filedata->dynamic_symtab_section->sh_entsize | |
10606 | != section.sh_entsize))) | |
10607 | warn (_("\ | |
10608 | the .dynsym section doesn't match the DT_SYMTAB and DT_SYMENT tags\n")); | |
10609 | ||
10610 | section.sh_name = filedata->string_table_length; | |
10611 | filedata->dynamic_symbols | |
10612 | = GET_ELF_SYMBOLS (filedata, §ion, | |
10613 | &filedata->num_dynamic_syms); | |
10614 | if (filedata->dynamic_symbols == NULL | |
10615 | || filedata->num_dynamic_syms != num_of_syms) | |
10616 | { | |
10617 | error (_("Corrupt DT_SYMTAB dynamic entry\n")); | |
10618 | return FALSE; | |
10619 | } | |
10620 | break; | |
10621 | } | |
10622 | } | |
10623 | } | |
10624 | } | |
10625 | ||
10626 | /* Similarly find a string table. */ | |
10627 | if (filedata->dynamic_strings == NULL) | |
10628 | for (entry = filedata->dynamic_section; | |
10629 | entry < filedata->dynamic_section + filedata->dynamic_nent; | |
10630 | ++entry) | |
10631 | { | |
10632 | if (entry->d_tag == DT_STRTAB) | |
10633 | filedata->dynamic_info[DT_STRTAB] = entry->d_un.d_val; | |
10634 | ||
10635 | if (entry->d_tag == DT_STRSZ) | |
10636 | filedata->dynamic_info[DT_STRSZ] = entry->d_un.d_val; | |
10637 | ||
10638 | if (filedata->dynamic_info[DT_STRTAB] | |
10639 | && filedata->dynamic_info[DT_STRSZ]) | |
10640 | { | |
10641 | unsigned long offset; | |
10642 | bfd_size_type str_tab_len = filedata->dynamic_info[DT_STRSZ]; | |
10643 | ||
10644 | offset = offset_from_vma (filedata, | |
10645 | filedata->dynamic_info[DT_STRTAB], | |
10646 | str_tab_len); | |
10647 | if (do_checks | |
10648 | && filedata->dynamic_strtab_section | |
10649 | && ((filedata->dynamic_strtab_section->sh_offset | |
10650 | != (file_ptr) offset) | |
10651 | || (filedata->dynamic_strtab_section->sh_size | |
10652 | != str_tab_len))) | |
10653 | warn (_("\ | |
10654 | the .dynstr section doesn't match the DT_STRTAB and DT_STRSZ tags\n")); | |
10655 | ||
10656 | filedata->dynamic_strings | |
10657 | = (char *) get_data (NULL, filedata, offset, 1, str_tab_len, | |
10658 | _("dynamic string table")); | |
10659 | if (filedata->dynamic_strings == NULL) | |
10660 | { | |
10661 | error (_("Corrupt DT_STRTAB dynamic entry\n")); | |
10662 | break; | |
10663 | } | |
10664 | ||
10665 | filedata->dynamic_strings_length = str_tab_len; | |
10666 | break; | |
10667 | } | |
10668 | } | |
10669 | ||
10670 | /* And find the syminfo section if available. */ | |
10671 | if (filedata->dynamic_syminfo == NULL) | |
10672 | { | |
10673 | unsigned long syminsz = 0; | |
10674 | ||
10675 | for (entry = filedata->dynamic_section; | |
10676 | entry < filedata->dynamic_section + filedata->dynamic_nent; | |
10677 | ++entry) | |
10678 | { | |
10679 | if (entry->d_tag == DT_SYMINENT) | |
10680 | { | |
10681 | /* Note: these braces are necessary to avoid a syntax | |
10682 | error from the SunOS4 C compiler. */ | |
10683 | /* PR binutils/17531: A corrupt file can trigger this test. | |
10684 | So do not use an assert, instead generate an error message. */ | |
10685 | if (sizeof (Elf_External_Syminfo) != entry->d_un.d_val) | |
10686 | error (_("Bad value (%d) for SYMINENT entry\n"), | |
10687 | (int) entry->d_un.d_val); | |
10688 | } | |
10689 | else if (entry->d_tag == DT_SYMINSZ) | |
10690 | syminsz = entry->d_un.d_val; | |
10691 | else if (entry->d_tag == DT_SYMINFO) | |
10692 | filedata->dynamic_syminfo_offset | |
10693 | = offset_from_vma (filedata, entry->d_un.d_val, syminsz); | |
10694 | } | |
10695 | ||
10696 | if (filedata->dynamic_syminfo_offset != 0 && syminsz != 0) | |
10697 | { | |
10698 | Elf_External_Syminfo * extsyminfo; | |
10699 | Elf_External_Syminfo * extsym; | |
10700 | Elf_Internal_Syminfo * syminfo; | |
10701 | ||
10702 | /* There is a syminfo section. Read the data. */ | |
10703 | extsyminfo = (Elf_External_Syminfo *) | |
10704 | get_data (NULL, filedata, filedata->dynamic_syminfo_offset, | |
10705 | 1, syminsz, _("symbol information")); | |
10706 | if (!extsyminfo) | |
10707 | return FALSE; | |
10708 | ||
10709 | if (filedata->dynamic_syminfo != NULL) | |
10710 | { | |
10711 | error (_("Multiple dynamic symbol information sections found\n")); | |
10712 | free (filedata->dynamic_syminfo); | |
10713 | } | |
10714 | filedata->dynamic_syminfo = (Elf_Internal_Syminfo *) malloc (syminsz); | |
10715 | if (filedata->dynamic_syminfo == NULL) | |
10716 | { | |
10717 | error (_("Out of memory allocating %lu bytes " | |
10718 | "for dynamic symbol info\n"), | |
10719 | (unsigned long) syminsz); | |
10720 | return FALSE; | |
10721 | } | |
10722 | ||
10723 | filedata->dynamic_syminfo_nent | |
10724 | = syminsz / sizeof (Elf_External_Syminfo); | |
10725 | for (syminfo = filedata->dynamic_syminfo, extsym = extsyminfo; | |
10726 | syminfo < (filedata->dynamic_syminfo | |
10727 | + filedata->dynamic_syminfo_nent); | |
10728 | ++syminfo, ++extsym) | |
10729 | { | |
10730 | syminfo->si_boundto = BYTE_GET (extsym->si_boundto); | |
10731 | syminfo->si_flags = BYTE_GET (extsym->si_flags); | |
10732 | } | |
10733 | ||
10734 | free (extsyminfo); | |
10735 | } | |
10736 | } | |
10737 | ||
10738 | if (do_dynamic && filedata->dynamic_addr) | |
10739 | { | |
10740 | if (filedata->dynamic_nent == 1) | |
10741 | { | |
10742 | if (filedata->is_separate) | |
10743 | printf (_("\nIn linked file '%s' the dynamic section at offset 0x%lx contains 1 entry:\n"), | |
10744 | filedata->file_name, | |
10745 | filedata->dynamic_addr); | |
10746 | else | |
10747 | printf (_("\nDynamic section at offset 0x%lx contains 1 entry:\n"), | |
10748 | filedata->dynamic_addr); | |
10749 | } | |
10750 | else | |
10751 | { | |
10752 | if (filedata->is_separate) | |
10753 | printf (_("\nIn linked file '%s' the dynamic section at offset 0x%lx contains %lu entries:\n"), | |
10754 | filedata->file_name, | |
10755 | filedata->dynamic_addr, | |
10756 | (unsigned long) filedata->dynamic_nent); | |
10757 | else | |
10758 | printf (_("\nDynamic section at offset 0x%lx contains %lu entries:\n"), | |
10759 | filedata->dynamic_addr, | |
10760 | (unsigned long) filedata->dynamic_nent); | |
10761 | } | |
10762 | } | |
10763 | if (do_dynamic) | |
10764 | printf (_(" Tag Type Name/Value\n")); | |
10765 | ||
10766 | for (entry = filedata->dynamic_section; | |
10767 | entry < filedata->dynamic_section + filedata->dynamic_nent; | |
10768 | entry++) | |
10769 | { | |
10770 | if (do_dynamic) | |
10771 | { | |
10772 | const char * dtype; | |
10773 | ||
10774 | putchar (' '); | |
10775 | print_vma (entry->d_tag, FULL_HEX); | |
10776 | dtype = get_dynamic_type (filedata, entry->d_tag); | |
10777 | printf (" (%s)%*s", dtype, | |
10778 | ((is_32bit_elf ? 27 : 19) - (int) strlen (dtype)), " "); | |
10779 | } | |
10780 | ||
10781 | switch (entry->d_tag) | |
10782 | { | |
10783 | case DT_FLAGS: | |
10784 | if (do_dynamic) | |
10785 | print_dynamic_flags (entry->d_un.d_val); | |
10786 | break; | |
10787 | ||
10788 | case DT_AUXILIARY: | |
10789 | case DT_FILTER: | |
10790 | case DT_CONFIG: | |
10791 | case DT_DEPAUDIT: | |
10792 | case DT_AUDIT: | |
10793 | if (do_dynamic) | |
10794 | { | |
10795 | switch (entry->d_tag) | |
10796 | { | |
10797 | case DT_AUXILIARY: | |
10798 | printf (_("Auxiliary library")); | |
10799 | break; | |
10800 | ||
10801 | case DT_FILTER: | |
10802 | printf (_("Filter library")); | |
10803 | break; | |
10804 | ||
10805 | case DT_CONFIG: | |
10806 | printf (_("Configuration file")); | |
10807 | break; | |
10808 | ||
10809 | case DT_DEPAUDIT: | |
10810 | printf (_("Dependency audit library")); | |
10811 | break; | |
10812 | ||
10813 | case DT_AUDIT: | |
10814 | printf (_("Audit library")); | |
10815 | break; | |
10816 | } | |
10817 | ||
10818 | if (VALID_DYNAMIC_NAME (filedata, entry->d_un.d_val)) | |
10819 | printf (": [%s]\n", | |
10820 | GET_DYNAMIC_NAME (filedata, entry->d_un.d_val)); | |
10821 | else | |
10822 | { | |
10823 | printf (": "); | |
10824 | print_vma (entry->d_un.d_val, PREFIX_HEX); | |
10825 | putchar ('\n'); | |
10826 | } | |
10827 | } | |
10828 | break; | |
10829 | ||
10830 | case DT_FEATURE: | |
10831 | if (do_dynamic) | |
10832 | { | |
10833 | printf (_("Flags:")); | |
10834 | ||
10835 | if (entry->d_un.d_val == 0) | |
10836 | printf (_(" None\n")); | |
10837 | else | |
10838 | { | |
10839 | unsigned long int val = entry->d_un.d_val; | |
10840 | ||
10841 | if (val & DTF_1_PARINIT) | |
10842 | { | |
10843 | printf (" PARINIT"); | |
10844 | val ^= DTF_1_PARINIT; | |
10845 | } | |
10846 | if (val & DTF_1_CONFEXP) | |
10847 | { | |
10848 | printf (" CONFEXP"); | |
10849 | val ^= DTF_1_CONFEXP; | |
10850 | } | |
10851 | if (val != 0) | |
10852 | printf (" %lx", val); | |
10853 | puts (""); | |
10854 | } | |
10855 | } | |
10856 | break; | |
10857 | ||
10858 | case DT_POSFLAG_1: | |
10859 | if (do_dynamic) | |
10860 | { | |
10861 | printf (_("Flags:")); | |
10862 | ||
10863 | if (entry->d_un.d_val == 0) | |
10864 | printf (_(" None\n")); | |
10865 | else | |
10866 | { | |
10867 | unsigned long int val = entry->d_un.d_val; | |
10868 | ||
10869 | if (val & DF_P1_LAZYLOAD) | |
10870 | { | |
10871 | printf (" LAZYLOAD"); | |
10872 | val ^= DF_P1_LAZYLOAD; | |
10873 | } | |
10874 | if (val & DF_P1_GROUPPERM) | |
10875 | { | |
10876 | printf (" GROUPPERM"); | |
10877 | val ^= DF_P1_GROUPPERM; | |
10878 | } | |
10879 | if (val != 0) | |
10880 | printf (" %lx", val); | |
10881 | puts (""); | |
10882 | } | |
10883 | } | |
10884 | break; | |
10885 | ||
10886 | case DT_FLAGS_1: | |
10887 | if (do_dynamic) | |
10888 | { | |
10889 | printf (_("Flags:")); | |
10890 | if (entry->d_un.d_val == 0) | |
10891 | printf (_(" None\n")); | |
10892 | else | |
10893 | { | |
10894 | unsigned long int val = entry->d_un.d_val; | |
10895 | ||
10896 | if (val & DF_1_NOW) | |
10897 | { | |
10898 | printf (" NOW"); | |
10899 | val ^= DF_1_NOW; | |
10900 | } | |
10901 | if (val & DF_1_GLOBAL) | |
10902 | { | |
10903 | printf (" GLOBAL"); | |
10904 | val ^= DF_1_GLOBAL; | |
10905 | } | |
10906 | if (val & DF_1_GROUP) | |
10907 | { | |
10908 | printf (" GROUP"); | |
10909 | val ^= DF_1_GROUP; | |
10910 | } | |
10911 | if (val & DF_1_NODELETE) | |
10912 | { | |
10913 | printf (" NODELETE"); | |
10914 | val ^= DF_1_NODELETE; | |
10915 | } | |
10916 | if (val & DF_1_LOADFLTR) | |
10917 | { | |
10918 | printf (" LOADFLTR"); | |
10919 | val ^= DF_1_LOADFLTR; | |
10920 | } | |
10921 | if (val & DF_1_INITFIRST) | |
10922 | { | |
10923 | printf (" INITFIRST"); | |
10924 | val ^= DF_1_INITFIRST; | |
10925 | } | |
10926 | if (val & DF_1_NOOPEN) | |
10927 | { | |
10928 | printf (" NOOPEN"); | |
10929 | val ^= DF_1_NOOPEN; | |
10930 | } | |
10931 | if (val & DF_1_ORIGIN) | |
10932 | { | |
10933 | printf (" ORIGIN"); | |
10934 | val ^= DF_1_ORIGIN; | |
10935 | } | |
10936 | if (val & DF_1_DIRECT) | |
10937 | { | |
10938 | printf (" DIRECT"); | |
10939 | val ^= DF_1_DIRECT; | |
10940 | } | |
10941 | if (val & DF_1_TRANS) | |
10942 | { | |
10943 | printf (" TRANS"); | |
10944 | val ^= DF_1_TRANS; | |
10945 | } | |
10946 | if (val & DF_1_INTERPOSE) | |
10947 | { | |
10948 | printf (" INTERPOSE"); | |
10949 | val ^= DF_1_INTERPOSE; | |
10950 | } | |
10951 | if (val & DF_1_NODEFLIB) | |
10952 | { | |
10953 | printf (" NODEFLIB"); | |
10954 | val ^= DF_1_NODEFLIB; | |
10955 | } | |
10956 | if (val & DF_1_NODUMP) | |
10957 | { | |
10958 | printf (" NODUMP"); | |
10959 | val ^= DF_1_NODUMP; | |
10960 | } | |
10961 | if (val & DF_1_CONFALT) | |
10962 | { | |
10963 | printf (" CONFALT"); | |
10964 | val ^= DF_1_CONFALT; | |
10965 | } | |
10966 | if (val & DF_1_ENDFILTEE) | |
10967 | { | |
10968 | printf (" ENDFILTEE"); | |
10969 | val ^= DF_1_ENDFILTEE; | |
10970 | } | |
10971 | if (val & DF_1_DISPRELDNE) | |
10972 | { | |
10973 | printf (" DISPRELDNE"); | |
10974 | val ^= DF_1_DISPRELDNE; | |
10975 | } | |
10976 | if (val & DF_1_DISPRELPND) | |
10977 | { | |
10978 | printf (" DISPRELPND"); | |
10979 | val ^= DF_1_DISPRELPND; | |
10980 | } | |
10981 | if (val & DF_1_NODIRECT) | |
10982 | { | |
10983 | printf (" NODIRECT"); | |
10984 | val ^= DF_1_NODIRECT; | |
10985 | } | |
10986 | if (val & DF_1_IGNMULDEF) | |
10987 | { | |
10988 | printf (" IGNMULDEF"); | |
10989 | val ^= DF_1_IGNMULDEF; | |
10990 | } | |
10991 | if (val & DF_1_NOKSYMS) | |
10992 | { | |
10993 | printf (" NOKSYMS"); | |
10994 | val ^= DF_1_NOKSYMS; | |
10995 | } | |
10996 | if (val & DF_1_NOHDR) | |
10997 | { | |
10998 | printf (" NOHDR"); | |
10999 | val ^= DF_1_NOHDR; | |
11000 | } | |
11001 | if (val & DF_1_EDITED) | |
11002 | { | |
11003 | printf (" EDITED"); | |
11004 | val ^= DF_1_EDITED; | |
11005 | } | |
11006 | if (val & DF_1_NORELOC) | |
11007 | { | |
11008 | printf (" NORELOC"); | |
11009 | val ^= DF_1_NORELOC; | |
11010 | } | |
11011 | if (val & DF_1_SYMINTPOSE) | |
11012 | { | |
11013 | printf (" SYMINTPOSE"); | |
11014 | val ^= DF_1_SYMINTPOSE; | |
11015 | } | |
11016 | if (val & DF_1_GLOBAUDIT) | |
11017 | { | |
11018 | printf (" GLOBAUDIT"); | |
11019 | val ^= DF_1_GLOBAUDIT; | |
11020 | } | |
11021 | if (val & DF_1_SINGLETON) | |
11022 | { | |
11023 | printf (" SINGLETON"); | |
11024 | val ^= DF_1_SINGLETON; | |
11025 | } | |
11026 | if (val & DF_1_STUB) | |
11027 | { | |
11028 | printf (" STUB"); | |
11029 | val ^= DF_1_STUB; | |
11030 | } | |
11031 | if (val & DF_1_PIE) | |
11032 | { | |
11033 | printf (" PIE"); | |
11034 | val ^= DF_1_PIE; | |
11035 | } | |
11036 | if (val & DF_1_KMOD) | |
11037 | { | |
11038 | printf (" KMOD"); | |
11039 | val ^= DF_1_KMOD; | |
11040 | } | |
11041 | if (val & DF_1_WEAKFILTER) | |
11042 | { | |
11043 | printf (" WEAKFILTER"); | |
11044 | val ^= DF_1_WEAKFILTER; | |
11045 | } | |
11046 | if (val & DF_1_NOCOMMON) | |
11047 | { | |
11048 | printf (" NOCOMMON"); | |
11049 | val ^= DF_1_NOCOMMON; | |
11050 | } | |
11051 | if (val != 0) | |
11052 | printf (" %lx", val); | |
11053 | puts (""); | |
11054 | } | |
11055 | } | |
11056 | break; | |
11057 | ||
11058 | case DT_PLTREL: | |
11059 | filedata->dynamic_info[entry->d_tag] = entry->d_un.d_val; | |
11060 | if (do_dynamic) | |
11061 | puts (get_dynamic_type (filedata, entry->d_un.d_val)); | |
11062 | break; | |
11063 | ||
11064 | case DT_NULL : | |
11065 | case DT_NEEDED : | |
11066 | case DT_PLTGOT : | |
11067 | case DT_HASH : | |
11068 | case DT_STRTAB : | |
11069 | case DT_SYMTAB : | |
11070 | case DT_RELA : | |
11071 | case DT_INIT : | |
11072 | case DT_FINI : | |
11073 | case DT_SONAME : | |
11074 | case DT_RPATH : | |
11075 | case DT_SYMBOLIC: | |
11076 | case DT_REL : | |
11077 | case DT_DEBUG : | |
11078 | case DT_TEXTREL : | |
11079 | case DT_JMPREL : | |
11080 | case DT_RUNPATH : | |
11081 | filedata->dynamic_info[entry->d_tag] = entry->d_un.d_val; | |
11082 | ||
11083 | if (do_dynamic) | |
11084 | { | |
11085 | char * name; | |
11086 | ||
11087 | if (VALID_DYNAMIC_NAME (filedata, entry->d_un.d_val)) | |
11088 | name = GET_DYNAMIC_NAME (filedata, entry->d_un.d_val); | |
11089 | else | |
11090 | name = NULL; | |
11091 | ||
11092 | if (name) | |
11093 | { | |
11094 | switch (entry->d_tag) | |
11095 | { | |
11096 | case DT_NEEDED: | |
11097 | printf (_("Shared library: [%s]"), name); | |
11098 | ||
11099 | if (streq (name, filedata->program_interpreter)) | |
11100 | printf (_(" program interpreter")); | |
11101 | break; | |
11102 | ||
11103 | case DT_SONAME: | |
11104 | printf (_("Library soname: [%s]"), name); | |
11105 | break; | |
11106 | ||
11107 | case DT_RPATH: | |
11108 | printf (_("Library rpath: [%s]"), name); | |
11109 | break; | |
11110 | ||
11111 | case DT_RUNPATH: | |
11112 | printf (_("Library runpath: [%s]"), name); | |
11113 | break; | |
11114 | ||
11115 | default: | |
11116 | print_vma (entry->d_un.d_val, PREFIX_HEX); | |
11117 | break; | |
11118 | } | |
11119 | } | |
11120 | else | |
11121 | print_vma (entry->d_un.d_val, PREFIX_HEX); | |
11122 | ||
11123 | putchar ('\n'); | |
11124 | } | |
11125 | break; | |
11126 | ||
11127 | case DT_PLTRELSZ: | |
11128 | case DT_RELASZ : | |
11129 | case DT_STRSZ : | |
11130 | case DT_RELSZ : | |
11131 | case DT_RELAENT : | |
11132 | case DT_SYMENT : | |
11133 | case DT_RELENT : | |
11134 | filedata->dynamic_info[entry->d_tag] = entry->d_un.d_val; | |
11135 | /* Fall through. */ | |
11136 | case DT_PLTPADSZ: | |
11137 | case DT_MOVEENT : | |
11138 | case DT_MOVESZ : | |
11139 | case DT_INIT_ARRAYSZ: | |
11140 | case DT_FINI_ARRAYSZ: | |
11141 | case DT_GNU_CONFLICTSZ: | |
11142 | case DT_GNU_LIBLISTSZ: | |
11143 | if (do_dynamic) | |
11144 | { | |
11145 | print_vma (entry->d_un.d_val, UNSIGNED); | |
11146 | printf (_(" (bytes)\n")); | |
11147 | } | |
11148 | break; | |
11149 | ||
11150 | case DT_VERDEFNUM: | |
11151 | case DT_VERNEEDNUM: | |
11152 | case DT_RELACOUNT: | |
11153 | case DT_RELCOUNT: | |
11154 | if (do_dynamic) | |
11155 | { | |
11156 | print_vma (entry->d_un.d_val, UNSIGNED); | |
11157 | putchar ('\n'); | |
11158 | } | |
11159 | break; | |
11160 | ||
11161 | case DT_SYMINSZ: | |
11162 | case DT_SYMINENT: | |
11163 | case DT_SYMINFO: | |
11164 | case DT_USED: | |
11165 | case DT_INIT_ARRAY: | |
11166 | case DT_FINI_ARRAY: | |
11167 | if (do_dynamic) | |
11168 | { | |
11169 | if (entry->d_tag == DT_USED | |
11170 | && VALID_DYNAMIC_NAME (filedata, entry->d_un.d_val)) | |
11171 | { | |
11172 | char * name = GET_DYNAMIC_NAME (filedata, entry->d_un.d_val); | |
11173 | ||
11174 | if (*name) | |
11175 | { | |
11176 | printf (_("Not needed object: [%s]\n"), name); | |
11177 | break; | |
11178 | } | |
11179 | } | |
11180 | ||
11181 | print_vma (entry->d_un.d_val, PREFIX_HEX); | |
11182 | putchar ('\n'); | |
11183 | } | |
11184 | break; | |
11185 | ||
11186 | case DT_BIND_NOW: | |
11187 | /* The value of this entry is ignored. */ | |
11188 | if (do_dynamic) | |
11189 | putchar ('\n'); | |
11190 | break; | |
11191 | ||
11192 | case DT_GNU_PRELINKED: | |
11193 | if (do_dynamic) | |
11194 | { | |
11195 | struct tm * tmp; | |
11196 | time_t atime = entry->d_un.d_val; | |
11197 | ||
11198 | tmp = gmtime (&atime); | |
11199 | /* PR 17533 file: 041-1244816-0.004. */ | |
11200 | if (tmp == NULL) | |
11201 | printf (_("<corrupt time val: %lx"), | |
11202 | (unsigned long) atime); | |
11203 | else | |
11204 | printf ("%04u-%02u-%02uT%02u:%02u:%02u\n", | |
11205 | tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday, | |
11206 | tmp->tm_hour, tmp->tm_min, tmp->tm_sec); | |
11207 | ||
11208 | } | |
11209 | break; | |
11210 | ||
11211 | case DT_GNU_HASH: | |
11212 | filedata->dynamic_info_DT_GNU_HASH = entry->d_un.d_val; | |
11213 | if (do_dynamic) | |
11214 | { | |
11215 | print_vma (entry->d_un.d_val, PREFIX_HEX); | |
11216 | putchar ('\n'); | |
11217 | } | |
11218 | break; | |
11219 | ||
11220 | case DT_GNU_FLAGS_1: | |
11221 | if (do_dynamic) | |
11222 | { | |
11223 | printf (_("Flags:")); | |
11224 | if (entry->d_un.d_val == 0) | |
11225 | printf (_(" None\n")); | |
11226 | else | |
11227 | { | |
11228 | unsigned long int val = entry->d_un.d_val; | |
11229 | ||
11230 | if (val & DF_GNU_1_UNIQUE) | |
11231 | { | |
11232 | printf (" UNIQUE"); | |
11233 | val ^= DF_GNU_1_UNIQUE; | |
11234 | } | |
11235 | if (val != 0) | |
11236 | printf (" %lx", val); | |
11237 | puts (""); | |
11238 | } | |
11239 | } | |
11240 | break; | |
11241 | ||
11242 | default: | |
11243 | if ((entry->d_tag >= DT_VERSYM) && (entry->d_tag <= DT_VERNEEDNUM)) | |
11244 | filedata->version_info[DT_VERSIONTAGIDX (entry->d_tag)] | |
11245 | = entry->d_un.d_val; | |
11246 | ||
11247 | if (do_dynamic) | |
11248 | { | |
11249 | switch (filedata->file_header.e_machine) | |
11250 | { | |
11251 | case EM_AARCH64: | |
11252 | dynamic_section_aarch64_val (entry); | |
11253 | break; | |
11254 | case EM_MIPS: | |
11255 | case EM_MIPS_RS3_LE: | |
11256 | dynamic_section_mips_val (filedata, entry); | |
11257 | break; | |
11258 | case EM_PARISC: | |
11259 | dynamic_section_parisc_val (entry); | |
11260 | break; | |
11261 | case EM_IA_64: | |
11262 | dynamic_section_ia64_val (entry); | |
11263 | break; | |
11264 | default: | |
11265 | print_vma (entry->d_un.d_val, PREFIX_HEX); | |
11266 | putchar ('\n'); | |
11267 | } | |
11268 | } | |
11269 | break; | |
11270 | } | |
11271 | } | |
11272 | ||
11273 | return TRUE; | |
11274 | } | |
11275 | ||
11276 | static char * | |
11277 | get_ver_flags (unsigned int flags) | |
11278 | { | |
11279 | static char buff[128]; | |
11280 | ||
11281 | buff[0] = 0; | |
11282 | ||
11283 | if (flags == 0) | |
11284 | return _("none"); | |
11285 | ||
11286 | if (flags & VER_FLG_BASE) | |
11287 | strcat (buff, "BASE"); | |
11288 | ||
11289 | if (flags & VER_FLG_WEAK) | |
11290 | { | |
11291 | if (flags & VER_FLG_BASE) | |
11292 | strcat (buff, " | "); | |
11293 | ||
11294 | strcat (buff, "WEAK"); | |
11295 | } | |
11296 | ||
11297 | if (flags & VER_FLG_INFO) | |
11298 | { | |
11299 | if (flags & (VER_FLG_BASE|VER_FLG_WEAK)) | |
11300 | strcat (buff, " | "); | |
11301 | ||
11302 | strcat (buff, "INFO"); | |
11303 | } | |
11304 | ||
11305 | if (flags & ~(VER_FLG_BASE | VER_FLG_WEAK | VER_FLG_INFO)) | |
11306 | { | |
11307 | if (flags & (VER_FLG_BASE | VER_FLG_WEAK | VER_FLG_INFO)) | |
11308 | strcat (buff, " | "); | |
11309 | ||
11310 | strcat (buff, _("<unknown>")); | |
11311 | } | |
11312 | ||
11313 | return buff; | |
11314 | } | |
11315 | ||
11316 | /* Display the contents of the version sections. */ | |
11317 | ||
11318 | static bfd_boolean | |
11319 | process_version_sections (Filedata * filedata) | |
11320 | { | |
11321 | Elf_Internal_Shdr * section; | |
11322 | unsigned i; | |
11323 | bfd_boolean found = FALSE; | |
11324 | ||
11325 | if (! do_version) | |
11326 | return TRUE; | |
11327 | ||
11328 | for (i = 0, section = filedata->section_headers; | |
11329 | i < filedata->file_header.e_shnum; | |
11330 | i++, section++) | |
11331 | { | |
11332 | switch (section->sh_type) | |
11333 | { | |
11334 | case SHT_GNU_verdef: | |
11335 | { | |
11336 | Elf_External_Verdef * edefs; | |
11337 | unsigned long idx; | |
11338 | unsigned long cnt; | |
11339 | char * endbuf; | |
11340 | ||
11341 | found = TRUE; | |
11342 | ||
11343 | if (filedata->is_separate) | |
11344 | printf (ngettext ("\nIn linked file '%s' the version definition section '%s' contains %u entry:\n", | |
11345 | "\nIn linked file '%s' the version definition section '%s' contains %u entries:\n", | |
11346 | section->sh_info), | |
11347 | filedata->file_name, | |
11348 | printable_section_name (filedata, section), | |
11349 | section->sh_info); | |
11350 | else | |
11351 | printf (ngettext ("\nVersion definition section '%s' " | |
11352 | "contains %u entry:\n", | |
11353 | "\nVersion definition section '%s' " | |
11354 | "contains %u entries:\n", | |
11355 | section->sh_info), | |
11356 | printable_section_name (filedata, section), | |
11357 | section->sh_info); | |
11358 | ||
11359 | printf (_(" Addr: 0x")); | |
11360 | printf_vma (section->sh_addr); | |
11361 | printf (_(" Offset: %#08lx Link: %u (%s)\n"), | |
11362 | (unsigned long) section->sh_offset, section->sh_link, | |
11363 | printable_section_name_from_index (filedata, section->sh_link)); | |
11364 | ||
11365 | edefs = (Elf_External_Verdef *) | |
11366 | get_data (NULL, filedata, section->sh_offset, 1,section->sh_size, | |
11367 | _("version definition section")); | |
11368 | if (!edefs) | |
11369 | break; | |
11370 | endbuf = (char *) edefs + section->sh_size; | |
11371 | ||
11372 | for (idx = cnt = 0; cnt < section->sh_info; ++cnt) | |
11373 | { | |
11374 | char * vstart; | |
11375 | Elf_External_Verdef * edef; | |
11376 | Elf_Internal_Verdef ent; | |
11377 | Elf_External_Verdaux * eaux; | |
11378 | Elf_Internal_Verdaux aux; | |
11379 | unsigned long isum; | |
11380 | int j; | |
11381 | ||
11382 | vstart = ((char *) edefs) + idx; | |
11383 | if (vstart + sizeof (*edef) > endbuf) | |
11384 | break; | |
11385 | ||
11386 | edef = (Elf_External_Verdef *) vstart; | |
11387 | ||
11388 | ent.vd_version = BYTE_GET (edef->vd_version); | |
11389 | ent.vd_flags = BYTE_GET (edef->vd_flags); | |
11390 | ent.vd_ndx = BYTE_GET (edef->vd_ndx); | |
11391 | ent.vd_cnt = BYTE_GET (edef->vd_cnt); | |
11392 | ent.vd_hash = BYTE_GET (edef->vd_hash); | |
11393 | ent.vd_aux = BYTE_GET (edef->vd_aux); | |
11394 | ent.vd_next = BYTE_GET (edef->vd_next); | |
11395 | ||
11396 | printf (_(" %#06lx: Rev: %d Flags: %s"), | |
11397 | idx, ent.vd_version, get_ver_flags (ent.vd_flags)); | |
11398 | ||
11399 | printf (_(" Index: %d Cnt: %d "), | |
11400 | ent.vd_ndx, ent.vd_cnt); | |
11401 | ||
11402 | /* Check for overflow. */ | |
11403 | if (ent.vd_aux > (size_t) (endbuf - vstart)) | |
11404 | break; | |
11405 | ||
11406 | vstart += ent.vd_aux; | |
11407 | ||
11408 | if (vstart + sizeof (*eaux) > endbuf) | |
11409 | break; | |
11410 | eaux = (Elf_External_Verdaux *) vstart; | |
11411 | ||
11412 | aux.vda_name = BYTE_GET (eaux->vda_name); | |
11413 | aux.vda_next = BYTE_GET (eaux->vda_next); | |
11414 | ||
11415 | if (VALID_DYNAMIC_NAME (filedata, aux.vda_name)) | |
11416 | printf (_("Name: %s\n"), | |
11417 | GET_DYNAMIC_NAME (filedata, aux.vda_name)); | |
11418 | else | |
11419 | printf (_("Name index: %ld\n"), aux.vda_name); | |
11420 | ||
11421 | isum = idx + ent.vd_aux; | |
11422 | ||
11423 | for (j = 1; j < ent.vd_cnt; j++) | |
11424 | { | |
11425 | if (aux.vda_next < sizeof (*eaux) | |
11426 | && !(j == ent.vd_cnt - 1 && aux.vda_next == 0)) | |
11427 | { | |
11428 | warn (_("Invalid vda_next field of %lx\n"), | |
11429 | aux.vda_next); | |
11430 | j = ent.vd_cnt; | |
11431 | break; | |
11432 | } | |
11433 | /* Check for overflow. */ | |
11434 | if (aux.vda_next > (size_t) (endbuf - vstart)) | |
11435 | break; | |
11436 | ||
11437 | isum += aux.vda_next; | |
11438 | vstart += aux.vda_next; | |
11439 | ||
11440 | if (vstart + sizeof (*eaux) > endbuf) | |
11441 | break; | |
11442 | eaux = (Elf_External_Verdaux *) vstart; | |
11443 | ||
11444 | aux.vda_name = BYTE_GET (eaux->vda_name); | |
11445 | aux.vda_next = BYTE_GET (eaux->vda_next); | |
11446 | ||
11447 | if (VALID_DYNAMIC_NAME (filedata, aux.vda_name)) | |
11448 | printf (_(" %#06lx: Parent %d: %s\n"), | |
11449 | isum, j, | |
11450 | GET_DYNAMIC_NAME (filedata, aux.vda_name)); | |
11451 | else | |
11452 | printf (_(" %#06lx: Parent %d, name index: %ld\n"), | |
11453 | isum, j, aux.vda_name); | |
11454 | } | |
11455 | ||
11456 | if (j < ent.vd_cnt) | |
11457 | printf (_(" Version def aux past end of section\n")); | |
11458 | ||
11459 | /* PR 17531: | |
11460 | file: id:000001,src:000172+005151,op:splice,rep:2. */ | |
11461 | if (ent.vd_next < sizeof (*edef) | |
11462 | && !(cnt == section->sh_info - 1 && ent.vd_next == 0)) | |
11463 | { | |
11464 | warn (_("Invalid vd_next field of %lx\n"), ent.vd_next); | |
11465 | cnt = section->sh_info; | |
11466 | break; | |
11467 | } | |
11468 | if (ent.vd_next > (size_t) (endbuf - ((char *) edefs + idx))) | |
11469 | break; | |
11470 | ||
11471 | idx += ent.vd_next; | |
11472 | } | |
11473 | ||
11474 | if (cnt < section->sh_info) | |
11475 | printf (_(" Version definition past end of section\n")); | |
11476 | ||
11477 | free (edefs); | |
11478 | } | |
11479 | break; | |
11480 | ||
11481 | case SHT_GNU_verneed: | |
11482 | { | |
11483 | Elf_External_Verneed * eneed; | |
11484 | unsigned long idx; | |
11485 | unsigned long cnt; | |
11486 | char * endbuf; | |
11487 | ||
11488 | found = TRUE; | |
11489 | ||
11490 | if (filedata->is_separate) | |
11491 | printf (ngettext ("\nIn linked file '%s' the version needs section '%s' contains %u entry:\n", | |
11492 | "\nIn linked file '%s' the version needs section '%s' contains %u entries:\n", | |
11493 | section->sh_info), | |
11494 | filedata->file_name, | |
11495 | printable_section_name (filedata, section), | |
11496 | section->sh_info); | |
11497 | else | |
11498 | printf (ngettext ("\nVersion needs section '%s' " | |
11499 | "contains %u entry:\n", | |
11500 | "\nVersion needs section '%s' " | |
11501 | "contains %u entries:\n", | |
11502 | section->sh_info), | |
11503 | printable_section_name (filedata, section), | |
11504 | section->sh_info); | |
11505 | ||
11506 | printf (_(" Addr: 0x")); | |
11507 | printf_vma (section->sh_addr); | |
11508 | printf (_(" Offset: %#08lx Link: %u (%s)\n"), | |
11509 | (unsigned long) section->sh_offset, section->sh_link, | |
11510 | printable_section_name_from_index (filedata, section->sh_link)); | |
11511 | ||
11512 | eneed = (Elf_External_Verneed *) get_data (NULL, filedata, | |
11513 | section->sh_offset, 1, | |
11514 | section->sh_size, | |
11515 | _("Version Needs section")); | |
11516 | if (!eneed) | |
11517 | break; | |
11518 | endbuf = (char *) eneed + section->sh_size; | |
11519 | ||
11520 | for (idx = cnt = 0; cnt < section->sh_info; ++cnt) | |
11521 | { | |
11522 | Elf_External_Verneed * entry; | |
11523 | Elf_Internal_Verneed ent; | |
11524 | unsigned long isum; | |
11525 | int j; | |
11526 | char * vstart; | |
11527 | ||
11528 | vstart = ((char *) eneed) + idx; | |
11529 | if (vstart + sizeof (*entry) > endbuf) | |
11530 | break; | |
11531 | ||
11532 | entry = (Elf_External_Verneed *) vstart; | |
11533 | ||
11534 | ent.vn_version = BYTE_GET (entry->vn_version); | |
11535 | ent.vn_cnt = BYTE_GET (entry->vn_cnt); | |
11536 | ent.vn_file = BYTE_GET (entry->vn_file); | |
11537 | ent.vn_aux = BYTE_GET (entry->vn_aux); | |
11538 | ent.vn_next = BYTE_GET (entry->vn_next); | |
11539 | ||
11540 | printf (_(" %#06lx: Version: %d"), idx, ent.vn_version); | |
11541 | ||
11542 | if (VALID_DYNAMIC_NAME (filedata, ent.vn_file)) | |
11543 | printf (_(" File: %s"), | |
11544 | GET_DYNAMIC_NAME (filedata, ent.vn_file)); | |
11545 | else | |
11546 | printf (_(" File: %lx"), ent.vn_file); | |
11547 | ||
11548 | printf (_(" Cnt: %d\n"), ent.vn_cnt); | |
11549 | ||
11550 | /* Check for overflow. */ | |
11551 | if (ent.vn_aux > (size_t) (endbuf - vstart)) | |
11552 | break; | |
11553 | vstart += ent.vn_aux; | |
11554 | ||
11555 | for (j = 0, isum = idx + ent.vn_aux; j < ent.vn_cnt; ++j) | |
11556 | { | |
11557 | Elf_External_Vernaux * eaux; | |
11558 | Elf_Internal_Vernaux aux; | |
11559 | ||
11560 | if (vstart + sizeof (*eaux) > endbuf) | |
11561 | break; | |
11562 | eaux = (Elf_External_Vernaux *) vstart; | |
11563 | ||
11564 | aux.vna_hash = BYTE_GET (eaux->vna_hash); | |
11565 | aux.vna_flags = BYTE_GET (eaux->vna_flags); | |
11566 | aux.vna_other = BYTE_GET (eaux->vna_other); | |
11567 | aux.vna_name = BYTE_GET (eaux->vna_name); | |
11568 | aux.vna_next = BYTE_GET (eaux->vna_next); | |
11569 | ||
11570 | if (VALID_DYNAMIC_NAME (filedata, aux.vna_name)) | |
11571 | printf (_(" %#06lx: Name: %s"), | |
11572 | isum, GET_DYNAMIC_NAME (filedata, aux.vna_name)); | |
11573 | else | |
11574 | printf (_(" %#06lx: Name index: %lx"), | |
11575 | isum, aux.vna_name); | |
11576 | ||
11577 | printf (_(" Flags: %s Version: %d\n"), | |
11578 | get_ver_flags (aux.vna_flags), aux.vna_other); | |
11579 | ||
11580 | if (aux.vna_next < sizeof (*eaux) | |
11581 | && !(j == ent.vn_cnt - 1 && aux.vna_next == 0)) | |
11582 | { | |
11583 | warn (_("Invalid vna_next field of %lx\n"), | |
11584 | aux.vna_next); | |
11585 | j = ent.vn_cnt; | |
11586 | break; | |
11587 | } | |
11588 | /* Check for overflow. */ | |
11589 | if (aux.vna_next > (size_t) (endbuf - vstart)) | |
11590 | break; | |
11591 | isum += aux.vna_next; | |
11592 | vstart += aux.vna_next; | |
11593 | } | |
11594 | ||
11595 | if (j < ent.vn_cnt) | |
11596 | warn (_("Missing Version Needs auxiliary information\n")); | |
11597 | ||
11598 | if (ent.vn_next < sizeof (*entry) | |
11599 | && !(cnt == section->sh_info - 1 && ent.vn_next == 0)) | |
11600 | { | |
11601 | warn (_("Invalid vn_next field of %lx\n"), ent.vn_next); | |
11602 | cnt = section->sh_info; | |
11603 | break; | |
11604 | } | |
11605 | if (ent.vn_next > (size_t) (endbuf - ((char *) eneed + idx))) | |
11606 | break; | |
11607 | idx += ent.vn_next; | |
11608 | } | |
11609 | ||
11610 | if (cnt < section->sh_info) | |
11611 | warn (_("Missing Version Needs information\n")); | |
11612 | ||
11613 | free (eneed); | |
11614 | } | |
11615 | break; | |
11616 | ||
11617 | case SHT_GNU_versym: | |
11618 | { | |
11619 | Elf_Internal_Shdr * link_section; | |
11620 | size_t total; | |
11621 | unsigned int cnt; | |
11622 | unsigned char * edata; | |
11623 | unsigned short * data; | |
11624 | char * strtab; | |
11625 | Elf_Internal_Sym * symbols; | |
11626 | Elf_Internal_Shdr * string_sec; | |
11627 | unsigned long num_syms; | |
11628 | long off; | |
11629 | ||
11630 | if (section->sh_link >= filedata->file_header.e_shnum) | |
11631 | break; | |
11632 | ||
11633 | link_section = filedata->section_headers + section->sh_link; | |
11634 | total = section->sh_size / sizeof (Elf_External_Versym); | |
11635 | ||
11636 | if (link_section->sh_link >= filedata->file_header.e_shnum) | |
11637 | break; | |
11638 | ||
11639 | found = TRUE; | |
11640 | ||
11641 | symbols = GET_ELF_SYMBOLS (filedata, link_section, & num_syms); | |
11642 | if (symbols == NULL) | |
11643 | break; | |
11644 | ||
11645 | string_sec = filedata->section_headers + link_section->sh_link; | |
11646 | ||
11647 | strtab = (char *) get_data (NULL, filedata, string_sec->sh_offset, 1, | |
11648 | string_sec->sh_size, | |
11649 | _("version string table")); | |
11650 | if (!strtab) | |
11651 | { | |
11652 | free (symbols); | |
11653 | break; | |
11654 | } | |
11655 | ||
11656 | if (filedata->is_separate) | |
11657 | printf (ngettext ("\nIn linked file '%s' the version symbols section '%s' contains %lu entry:\n", | |
11658 | "\nIn linked file '%s' the version symbols section '%s' contains %lu entries:\n", | |
11659 | total), | |
11660 | filedata->file_name, | |
11661 | printable_section_name (filedata, section), | |
11662 | (unsigned long) total); | |
11663 | else | |
11664 | printf (ngettext ("\nVersion symbols section '%s' " | |
11665 | "contains %lu entry:\n", | |
11666 | "\nVersion symbols section '%s' " | |
11667 | "contains %lu entries:\n", | |
11668 | total), | |
11669 | printable_section_name (filedata, section), | |
11670 | (unsigned long) total); | |
11671 | ||
11672 | printf (_(" Addr: 0x")); | |
11673 | printf_vma (section->sh_addr); | |
11674 | printf (_(" Offset: %#08lx Link: %u (%s)\n"), | |
11675 | (unsigned long) section->sh_offset, section->sh_link, | |
11676 | printable_section_name (filedata, link_section)); | |
11677 | ||
11678 | off = offset_from_vma (filedata, | |
11679 | filedata->version_info[DT_VERSIONTAGIDX (DT_VERSYM)], | |
11680 | total * sizeof (short)); | |
11681 | edata = (unsigned char *) get_data (NULL, filedata, off, | |
11682 | sizeof (short), total, | |
11683 | _("version symbol data")); | |
11684 | if (!edata) | |
11685 | { | |
11686 | free (strtab); | |
11687 | free (symbols); | |
11688 | break; | |
11689 | } | |
11690 | ||
11691 | data = (short unsigned int *) cmalloc (total, sizeof (short)); | |
11692 | ||
11693 | for (cnt = total; cnt --;) | |
11694 | data[cnt] = byte_get (edata + cnt * sizeof (short), | |
11695 | sizeof (short)); | |
11696 | ||
11697 | free (edata); | |
11698 | ||
11699 | for (cnt = 0; cnt < total; cnt += 4) | |
11700 | { | |
11701 | int j, nn; | |
11702 | char *name; | |
11703 | char *invalid = _("*invalid*"); | |
11704 | ||
11705 | printf (" %03x:", cnt); | |
11706 | ||
11707 | for (j = 0; (j < 4) && (cnt + j) < total; ++j) | |
11708 | switch (data[cnt + j]) | |
11709 | { | |
11710 | case 0: | |
11711 | fputs (_(" 0 (*local*) "), stdout); | |
11712 | break; | |
11713 | ||
11714 | case 1: | |
11715 | fputs (_(" 1 (*global*) "), stdout); | |
11716 | break; | |
11717 | ||
11718 | default: | |
11719 | nn = printf ("%4x%c", data[cnt + j] & VERSYM_VERSION, | |
11720 | data[cnt + j] & VERSYM_HIDDEN ? 'h' : ' '); | |
11721 | ||
11722 | /* If this index value is greater than the size of the symbols | |
11723 | array, break to avoid an out-of-bounds read. */ | |
11724 | if ((unsigned long)(cnt + j) >= num_syms) | |
11725 | { | |
11726 | warn (_("invalid index into symbol array\n")); | |
11727 | break; | |
11728 | } | |
11729 | ||
11730 | name = NULL; | |
11731 | if (filedata->version_info[DT_VERSIONTAGIDX (DT_VERNEED)]) | |
11732 | { | |
11733 | Elf_Internal_Verneed ivn; | |
11734 | unsigned long offset; | |
11735 | ||
11736 | offset = offset_from_vma | |
11737 | (filedata, | |
11738 | filedata->version_info[DT_VERSIONTAGIDX (DT_VERNEED)], | |
11739 | sizeof (Elf_External_Verneed)); | |
11740 | ||
11741 | do | |
11742 | { | |
11743 | Elf_Internal_Vernaux ivna; | |
11744 | Elf_External_Verneed evn; | |
11745 | Elf_External_Vernaux evna; | |
11746 | unsigned long a_off; | |
11747 | ||
11748 | if (get_data (&evn, filedata, offset, sizeof (evn), 1, | |
11749 | _("version need")) == NULL) | |
11750 | break; | |
11751 | ||
11752 | ivn.vn_aux = BYTE_GET (evn.vn_aux); | |
11753 | ivn.vn_next = BYTE_GET (evn.vn_next); | |
11754 | ||
11755 | a_off = offset + ivn.vn_aux; | |
11756 | ||
11757 | do | |
11758 | { | |
11759 | if (get_data (&evna, filedata, a_off, sizeof (evna), | |
11760 | 1, _("version need aux (2)")) == NULL) | |
11761 | { | |
11762 | ivna.vna_next = 0; | |
11763 | ivna.vna_other = 0; | |
11764 | } | |
11765 | else | |
11766 | { | |
11767 | ivna.vna_next = BYTE_GET (evna.vna_next); | |
11768 | ivna.vna_other = BYTE_GET (evna.vna_other); | |
11769 | } | |
11770 | ||
11771 | a_off += ivna.vna_next; | |
11772 | } | |
11773 | while (ivna.vna_other != data[cnt + j] | |
11774 | && ivna.vna_next != 0); | |
11775 | ||
11776 | if (ivna.vna_other == data[cnt + j]) | |
11777 | { | |
11778 | ivna.vna_name = BYTE_GET (evna.vna_name); | |
11779 | ||
11780 | if (ivna.vna_name >= string_sec->sh_size) | |
11781 | name = invalid; | |
11782 | else | |
11783 | name = strtab + ivna.vna_name; | |
11784 | break; | |
11785 | } | |
11786 | ||
11787 | offset += ivn.vn_next; | |
11788 | } | |
11789 | while (ivn.vn_next); | |
11790 | } | |
11791 | ||
11792 | if (data[cnt + j] != 0x8001 | |
11793 | && filedata->version_info[DT_VERSIONTAGIDX (DT_VERDEF)]) | |
11794 | { | |
11795 | Elf_Internal_Verdef ivd; | |
11796 | Elf_External_Verdef evd; | |
11797 | unsigned long offset; | |
11798 | ||
11799 | offset = offset_from_vma | |
11800 | (filedata, | |
11801 | filedata->version_info[DT_VERSIONTAGIDX (DT_VERDEF)], | |
11802 | sizeof evd); | |
11803 | ||
11804 | do | |
11805 | { | |
11806 | if (get_data (&evd, filedata, offset, sizeof (evd), 1, | |
11807 | _("version def")) == NULL) | |
11808 | { | |
11809 | ivd.vd_next = 0; | |
11810 | /* PR 17531: file: 046-1082287-0.004. */ | |
11811 | ivd.vd_ndx = (data[cnt + j] & VERSYM_VERSION) + 1; | |
11812 | break; | |
11813 | } | |
11814 | else | |
11815 | { | |
11816 | ivd.vd_next = BYTE_GET (evd.vd_next); | |
11817 | ivd.vd_ndx = BYTE_GET (evd.vd_ndx); | |
11818 | } | |
11819 | ||
11820 | offset += ivd.vd_next; | |
11821 | } | |
11822 | while (ivd.vd_ndx != (data[cnt + j] & VERSYM_VERSION) | |
11823 | && ivd.vd_next != 0); | |
11824 | ||
11825 | if (ivd.vd_ndx == (data[cnt + j] & VERSYM_VERSION)) | |
11826 | { | |
11827 | Elf_External_Verdaux evda; | |
11828 | Elf_Internal_Verdaux ivda; | |
11829 | ||
11830 | ivd.vd_aux = BYTE_GET (evd.vd_aux); | |
11831 | ||
11832 | if (get_data (&evda, filedata, | |
11833 | offset - ivd.vd_next + ivd.vd_aux, | |
11834 | sizeof (evda), 1, | |
11835 | _("version def aux")) == NULL) | |
11836 | break; | |
11837 | ||
11838 | ivda.vda_name = BYTE_GET (evda.vda_name); | |
11839 | ||
11840 | if (ivda.vda_name >= string_sec->sh_size) | |
11841 | name = invalid; | |
11842 | else if (name != NULL && name != invalid) | |
11843 | name = _("*both*"); | |
11844 | else | |
11845 | name = strtab + ivda.vda_name; | |
11846 | } | |
11847 | } | |
11848 | if (name != NULL) | |
11849 | nn += printf ("(%s%-*s", | |
11850 | name, | |
11851 | 12 - (int) strlen (name), | |
11852 | ")"); | |
11853 | ||
11854 | if (nn < 18) | |
11855 | printf ("%*c", 18 - nn, ' '); | |
11856 | } | |
11857 | ||
11858 | putchar ('\n'); | |
11859 | } | |
11860 | ||
11861 | free (data); | |
11862 | free (strtab); | |
11863 | free (symbols); | |
11864 | } | |
11865 | break; | |
11866 | ||
11867 | default: | |
11868 | break; | |
11869 | } | |
11870 | } | |
11871 | ||
11872 | if (! found) | |
11873 | { | |
11874 | if (filedata->is_separate) | |
11875 | printf (_("\nNo version information found in linked file '%s'.\n"), | |
11876 | filedata->file_name); | |
11877 | else | |
11878 | printf (_("\nNo version information found in this file.\n")); | |
11879 | } | |
11880 | ||
11881 | return TRUE; | |
11882 | } | |
11883 | ||
11884 | static const char * | |
11885 | get_symbol_binding (Filedata * filedata, unsigned int binding) | |
11886 | { | |
11887 | static char buff[64]; | |
11888 | ||
11889 | switch (binding) | |
11890 | { | |
11891 | case STB_LOCAL: return "LOCAL"; | |
11892 | case STB_GLOBAL: return "GLOBAL"; | |
11893 | case STB_WEAK: return "WEAK"; | |
11894 | default: | |
11895 | if (binding >= STB_LOPROC && binding <= STB_HIPROC) | |
11896 | snprintf (buff, sizeof (buff), _("<processor specific>: %d"), | |
11897 | binding); | |
11898 | else if (binding >= STB_LOOS && binding <= STB_HIOS) | |
11899 | { | |
11900 | if (binding == STB_GNU_UNIQUE | |
11901 | && filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_GNU) | |
11902 | return "UNIQUE"; | |
11903 | snprintf (buff, sizeof (buff), _("<OS specific>: %d"), binding); | |
11904 | } | |
11905 | else | |
11906 | snprintf (buff, sizeof (buff), _("<unknown>: %d"), binding); | |
11907 | return buff; | |
11908 | } | |
11909 | } | |
11910 | ||
11911 | static const char * | |
11912 | get_symbol_type (Filedata * filedata, unsigned int type) | |
11913 | { | |
11914 | static char buff[64]; | |
11915 | ||
11916 | switch (type) | |
11917 | { | |
11918 | case STT_NOTYPE: return "NOTYPE"; | |
11919 | case STT_OBJECT: return "OBJECT"; | |
11920 | case STT_FUNC: return "FUNC"; | |
11921 | case STT_SECTION: return "SECTION"; | |
11922 | case STT_FILE: return "FILE"; | |
11923 | case STT_COMMON: return "COMMON"; | |
11924 | case STT_TLS: return "TLS"; | |
11925 | case STT_RELC: return "RELC"; | |
11926 | case STT_SRELC: return "SRELC"; | |
11927 | default: | |
11928 | if (type >= STT_LOPROC && type <= STT_HIPROC) | |
11929 | { | |
11930 | if (filedata->file_header.e_machine == EM_ARM && type == STT_ARM_TFUNC) | |
11931 | return "THUMB_FUNC"; | |
11932 | ||
11933 | if (filedata->file_header.e_machine == EM_SPARCV9 && type == STT_REGISTER) | |
11934 | return "REGISTER"; | |
11935 | ||
11936 | if (filedata->file_header.e_machine == EM_PARISC && type == STT_PARISC_MILLI) | |
11937 | return "PARISC_MILLI"; | |
11938 | ||
11939 | snprintf (buff, sizeof (buff), _("<processor specific>: %d"), type); | |
11940 | } | |
11941 | else if (type >= STT_LOOS && type <= STT_HIOS) | |
11942 | { | |
11943 | if (filedata->file_header.e_machine == EM_PARISC) | |
11944 | { | |
11945 | if (type == STT_HP_OPAQUE) | |
11946 | return "HP_OPAQUE"; | |
11947 | if (type == STT_HP_STUB) | |
11948 | return "HP_STUB"; | |
11949 | } | |
11950 | ||
11951 | if (type == STT_GNU_IFUNC | |
11952 | && (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_GNU | |
11953 | || filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_FREEBSD)) | |
11954 | return "IFUNC"; | |
11955 | ||
11956 | snprintf (buff, sizeof (buff), _("<OS specific>: %d"), type); | |
11957 | } | |
11958 | else | |
11959 | snprintf (buff, sizeof (buff), _("<unknown>: %d"), type); | |
11960 | return buff; | |
11961 | } | |
11962 | } | |
11963 | ||
11964 | static const char * | |
11965 | get_symbol_visibility (unsigned int visibility) | |
11966 | { | |
11967 | switch (visibility) | |
11968 | { | |
11969 | case STV_DEFAULT: return "DEFAULT"; | |
11970 | case STV_INTERNAL: return "INTERNAL"; | |
11971 | case STV_HIDDEN: return "HIDDEN"; | |
11972 | case STV_PROTECTED: return "PROTECTED"; | |
11973 | default: | |
11974 | error (_("Unrecognized visibility value: %u\n"), visibility); | |
11975 | return _("<unknown>"); | |
11976 | } | |
11977 | } | |
11978 | ||
11979 | static const char * | |
11980 | get_alpha_symbol_other (unsigned int other) | |
11981 | { | |
11982 | switch (other) | |
11983 | { | |
11984 | case STO_ALPHA_NOPV: return "NOPV"; | |
11985 | case STO_ALPHA_STD_GPLOAD: return "STD GPLOAD"; | |
11986 | default: | |
11987 | error (_("Unrecognized alpha specific other value: %u\n"), other); | |
11988 | return _("<unknown>"); | |
11989 | } | |
11990 | } | |
11991 | ||
11992 | static const char * | |
11993 | get_solaris_symbol_visibility (unsigned int visibility) | |
11994 | { | |
11995 | switch (visibility) | |
11996 | { | |
11997 | case 4: return "EXPORTED"; | |
11998 | case 5: return "SINGLETON"; | |
11999 | case 6: return "ELIMINATE"; | |
12000 | default: return get_symbol_visibility (visibility); | |
12001 | } | |
12002 | } | |
12003 | ||
12004 | static const char * | |
12005 | get_aarch64_symbol_other (unsigned int other) | |
12006 | { | |
12007 | static char buf[32]; | |
12008 | ||
12009 | if (other & STO_AARCH64_VARIANT_PCS) | |
12010 | { | |
12011 | other &= ~STO_AARCH64_VARIANT_PCS; | |
12012 | if (other == 0) | |
12013 | return "VARIANT_PCS"; | |
12014 | snprintf (buf, sizeof buf, "VARIANT_PCS | %x", other); | |
12015 | return buf; | |
12016 | } | |
12017 | return NULL; | |
12018 | } | |
12019 | ||
12020 | static const char * | |
12021 | get_mips_symbol_other (unsigned int other) | |
12022 | { | |
12023 | switch (other) | |
12024 | { | |
12025 | case STO_OPTIONAL: return "OPTIONAL"; | |
12026 | case STO_MIPS_PLT: return "MIPS PLT"; | |
12027 | case STO_MIPS_PIC: return "MIPS PIC"; | |
12028 | case STO_MICROMIPS: return "MICROMIPS"; | |
12029 | case STO_MICROMIPS | STO_MIPS_PIC: return "MICROMIPS, MIPS PIC"; | |
12030 | case STO_MIPS16: return "MIPS16"; | |
12031 | default: return NULL; | |
12032 | } | |
12033 | } | |
12034 | ||
12035 | static const char * | |
12036 | get_ia64_symbol_other (Filedata * filedata, unsigned int other) | |
12037 | { | |
12038 | if (is_ia64_vms (filedata)) | |
12039 | { | |
12040 | static char res[32]; | |
12041 | ||
12042 | res[0] = 0; | |
12043 | ||
12044 | /* Function types is for images and .STB files only. */ | |
12045 | switch (filedata->file_header.e_type) | |
12046 | { | |
12047 | case ET_DYN: | |
12048 | case ET_EXEC: | |
12049 | switch (VMS_ST_FUNC_TYPE (other)) | |
12050 | { | |
12051 | case VMS_SFT_CODE_ADDR: | |
12052 | strcat (res, " CA"); | |
12053 | break; | |
12054 | case VMS_SFT_SYMV_IDX: | |
12055 | strcat (res, " VEC"); | |
12056 | break; | |
12057 | case VMS_SFT_FD: | |
12058 | strcat (res, " FD"); | |
12059 | break; | |
12060 | case VMS_SFT_RESERVE: | |
12061 | strcat (res, " RSV"); | |
12062 | break; | |
12063 | default: | |
12064 | warn (_("Unrecognized IA64 VMS ST Function type: %d\n"), | |
12065 | VMS_ST_FUNC_TYPE (other)); | |
12066 | strcat (res, " <unknown>"); | |
12067 | break; | |
12068 | } | |
12069 | break; | |
12070 | default: | |
12071 | break; | |
12072 | } | |
12073 | switch (VMS_ST_LINKAGE (other)) | |
12074 | { | |
12075 | case VMS_STL_IGNORE: | |
12076 | strcat (res, " IGN"); | |
12077 | break; | |
12078 | case VMS_STL_RESERVE: | |
12079 | strcat (res, " RSV"); | |
12080 | break; | |
12081 | case VMS_STL_STD: | |
12082 | strcat (res, " STD"); | |
12083 | break; | |
12084 | case VMS_STL_LNK: | |
12085 | strcat (res, " LNK"); | |
12086 | break; | |
12087 | default: | |
12088 | warn (_("Unrecognized IA64 VMS ST Linkage: %d\n"), | |
12089 | VMS_ST_LINKAGE (other)); | |
12090 | strcat (res, " <unknown>"); | |
12091 | break; | |
12092 | } | |
12093 | ||
12094 | if (res[0] != 0) | |
12095 | return res + 1; | |
12096 | else | |
12097 | return res; | |
12098 | } | |
12099 | return NULL; | |
12100 | } | |
12101 | ||
12102 | static const char * | |
12103 | get_ppc64_symbol_other (unsigned int other) | |
12104 | { | |
12105 | if ((other & ~STO_PPC64_LOCAL_MASK) != 0) | |
12106 | return NULL; | |
12107 | ||
12108 | other >>= STO_PPC64_LOCAL_BIT; | |
12109 | if (other <= 6) | |
12110 | { | |
12111 | static char buf[64]; | |
12112 | if (other >= 2) | |
12113 | other = ppc64_decode_local_entry (other); | |
12114 | snprintf (buf, sizeof buf, _("<localentry>: %d"), other); | |
12115 | return buf; | |
12116 | } | |
12117 | return NULL; | |
12118 | } | |
12119 | ||
12120 | static const char * | |
12121 | get_symbol_other (Filedata * filedata, unsigned int other) | |
12122 | { | |
12123 | const char * result = NULL; | |
12124 | static char buff [64]; | |
12125 | ||
12126 | if (other == 0) | |
12127 | return ""; | |
12128 | ||
12129 | switch (filedata->file_header.e_machine) | |
12130 | { | |
12131 | case EM_ALPHA: | |
12132 | result = get_alpha_symbol_other (other); | |
12133 | break; | |
12134 | case EM_AARCH64: | |
12135 | result = get_aarch64_symbol_other (other); | |
12136 | break; | |
12137 | case EM_MIPS: | |
12138 | result = get_mips_symbol_other (other); | |
12139 | break; | |
12140 | case EM_IA_64: | |
12141 | result = get_ia64_symbol_other (filedata, other); | |
12142 | break; | |
12143 | case EM_PPC64: | |
12144 | result = get_ppc64_symbol_other (other); | |
12145 | break; | |
12146 | default: | |
12147 | result = NULL; | |
12148 | break; | |
12149 | } | |
12150 | ||
12151 | if (result) | |
12152 | return result; | |
12153 | ||
12154 | snprintf (buff, sizeof buff, _("<other>: %x"), other); | |
12155 | return buff; | |
12156 | } | |
12157 | ||
12158 | static const char * | |
12159 | get_symbol_index_type (Filedata * filedata, unsigned int type) | |
12160 | { | |
12161 | static char buff[32]; | |
12162 | ||
12163 | switch (type) | |
12164 | { | |
12165 | case SHN_UNDEF: return "UND"; | |
12166 | case SHN_ABS: return "ABS"; | |
12167 | case SHN_COMMON: return "COM"; | |
12168 | default: | |
12169 | if (type == SHN_IA_64_ANSI_COMMON | |
12170 | && filedata->file_header.e_machine == EM_IA_64 | |
12171 | && filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_HPUX) | |
12172 | return "ANSI_COM"; | |
12173 | else if ((filedata->file_header.e_machine == EM_X86_64 | |
12174 | || filedata->file_header.e_machine == EM_L1OM | |
12175 | || filedata->file_header.e_machine == EM_K1OM) | |
12176 | && type == SHN_X86_64_LCOMMON) | |
12177 | return "LARGE_COM"; | |
12178 | else if ((type == SHN_MIPS_SCOMMON | |
12179 | && filedata->file_header.e_machine == EM_MIPS) | |
12180 | || (type == SHN_TIC6X_SCOMMON | |
12181 | && filedata->file_header.e_machine == EM_TI_C6000)) | |
12182 | return "SCOM"; | |
12183 | else if (type == SHN_MIPS_SUNDEFINED | |
12184 | && filedata->file_header.e_machine == EM_MIPS) | |
12185 | return "SUND"; | |
12186 | else if (type >= SHN_LOPROC && type <= SHN_HIPROC) | |
12187 | sprintf (buff, "PRC[0x%04x]", type & 0xffff); | |
12188 | else if (type >= SHN_LOOS && type <= SHN_HIOS) | |
12189 | sprintf (buff, "OS [0x%04x]", type & 0xffff); | |
12190 | else if (type >= SHN_LORESERVE) | |
12191 | sprintf (buff, "RSV[0x%04x]", type & 0xffff); | |
12192 | else if (filedata->file_header.e_shnum != 0 | |
12193 | && type >= filedata->file_header.e_shnum) | |
12194 | sprintf (buff, _("bad section index[%3d]"), type); | |
12195 | else | |
12196 | sprintf (buff, "%3d", type); | |
12197 | break; | |
12198 | } | |
12199 | ||
12200 | return buff; | |
12201 | } | |
12202 | ||
12203 | static const char * | |
12204 | get_symbol_version_string (Filedata * filedata, | |
12205 | bfd_boolean is_dynsym, | |
12206 | const char * strtab, | |
12207 | unsigned long int strtab_size, | |
12208 | unsigned int si, | |
12209 | Elf_Internal_Sym * psym, | |
12210 | enum versioned_symbol_info * sym_info, | |
12211 | unsigned short * vna_other) | |
12212 | { | |
12213 | unsigned char data[2]; | |
12214 | unsigned short vers_data; | |
12215 | unsigned long offset; | |
12216 | unsigned short max_vd_ndx; | |
12217 | ||
12218 | if (!is_dynsym | |
12219 | || filedata->version_info[DT_VERSIONTAGIDX (DT_VERSYM)] == 0) | |
12220 | return NULL; | |
12221 | ||
12222 | offset = offset_from_vma (filedata, | |
12223 | filedata->version_info[DT_VERSIONTAGIDX (DT_VERSYM)], | |
12224 | sizeof data + si * sizeof (vers_data)); | |
12225 | ||
12226 | if (get_data (&data, filedata, offset + si * sizeof (vers_data), | |
12227 | sizeof (data), 1, _("version data")) == NULL) | |
12228 | return NULL; | |
12229 | ||
12230 | vers_data = byte_get (data, 2); | |
12231 | ||
12232 | if ((vers_data & VERSYM_HIDDEN) == 0 && vers_data == 0) | |
12233 | return NULL; | |
12234 | ||
12235 | *sym_info = (vers_data & VERSYM_HIDDEN) != 0 ? symbol_hidden : symbol_public; | |
12236 | max_vd_ndx = 0; | |
12237 | ||
12238 | /* Usually we'd only see verdef for defined symbols, and verneed for | |
12239 | undefined symbols. However, symbols defined by the linker in | |
12240 | .dynbss for variables copied from a shared library in order to | |
12241 | avoid text relocations are defined yet have verneed. We could | |
12242 | use a heuristic to detect the special case, for example, check | |
12243 | for verneed first on symbols defined in SHT_NOBITS sections, but | |
12244 | it is simpler and more reliable to just look for both verdef and | |
12245 | verneed. .dynbss might not be mapped to a SHT_NOBITS section. */ | |
12246 | ||
12247 | if (psym->st_shndx != SHN_UNDEF | |
12248 | && vers_data != 0x8001 | |
12249 | && filedata->version_info[DT_VERSIONTAGIDX (DT_VERDEF)]) | |
12250 | { | |
12251 | Elf_Internal_Verdef ivd; | |
12252 | Elf_Internal_Verdaux ivda; | |
12253 | Elf_External_Verdaux evda; | |
12254 | unsigned long off; | |
12255 | ||
12256 | off = offset_from_vma (filedata, | |
12257 | filedata->version_info[DT_VERSIONTAGIDX (DT_VERDEF)], | |
12258 | sizeof (Elf_External_Verdef)); | |
12259 | ||
12260 | do | |
12261 | { | |
12262 | Elf_External_Verdef evd; | |
12263 | ||
12264 | if (get_data (&evd, filedata, off, sizeof (evd), 1, | |
12265 | _("version def")) == NULL) | |
12266 | { | |
12267 | ivd.vd_ndx = 0; | |
12268 | ivd.vd_aux = 0; | |
12269 | ivd.vd_next = 0; | |
12270 | ivd.vd_flags = 0; | |
12271 | } | |
12272 | else | |
12273 | { | |
12274 | ivd.vd_ndx = BYTE_GET (evd.vd_ndx); | |
12275 | ivd.vd_aux = BYTE_GET (evd.vd_aux); | |
12276 | ivd.vd_next = BYTE_GET (evd.vd_next); | |
12277 | ivd.vd_flags = BYTE_GET (evd.vd_flags); | |
12278 | } | |
12279 | ||
12280 | if ((ivd.vd_ndx & VERSYM_VERSION) > max_vd_ndx) | |
12281 | max_vd_ndx = ivd.vd_ndx & VERSYM_VERSION; | |
12282 | ||
12283 | off += ivd.vd_next; | |
12284 | } | |
12285 | while (ivd.vd_ndx != (vers_data & VERSYM_VERSION) && ivd.vd_next != 0); | |
12286 | ||
12287 | if (ivd.vd_ndx == (vers_data & VERSYM_VERSION)) | |
12288 | { | |
12289 | if (ivd.vd_ndx == 1 && ivd.vd_flags == VER_FLG_BASE) | |
12290 | return NULL; | |
12291 | ||
12292 | off -= ivd.vd_next; | |
12293 | off += ivd.vd_aux; | |
12294 | ||
12295 | if (get_data (&evda, filedata, off, sizeof (evda), 1, | |
12296 | _("version def aux")) != NULL) | |
12297 | { | |
12298 | ivda.vda_name = BYTE_GET (evda.vda_name); | |
12299 | ||
12300 | if (psym->st_name != ivda.vda_name) | |
12301 | return (ivda.vda_name < strtab_size | |
12302 | ? strtab + ivda.vda_name : _("<corrupt>")); | |
12303 | } | |
12304 | } | |
12305 | } | |
12306 | ||
12307 | if (filedata->version_info[DT_VERSIONTAGIDX (DT_VERNEED)]) | |
12308 | { | |
12309 | Elf_External_Verneed evn; | |
12310 | Elf_Internal_Verneed ivn; | |
12311 | Elf_Internal_Vernaux ivna; | |
12312 | ||
12313 | offset = offset_from_vma (filedata, | |
12314 | filedata->version_info[DT_VERSIONTAGIDX (DT_VERNEED)], | |
12315 | sizeof evn); | |
12316 | do | |
12317 | { | |
12318 | unsigned long vna_off; | |
12319 | ||
12320 | if (get_data (&evn, filedata, offset, sizeof (evn), 1, | |
12321 | _("version need")) == NULL) | |
12322 | { | |
12323 | ivna.vna_next = 0; | |
12324 | ivna.vna_other = 0; | |
12325 | ivna.vna_name = 0; | |
12326 | break; | |
12327 | } | |
12328 | ||
12329 | ivn.vn_aux = BYTE_GET (evn.vn_aux); | |
12330 | ivn.vn_next = BYTE_GET (evn.vn_next); | |
12331 | ||
12332 | vna_off = offset + ivn.vn_aux; | |
12333 | ||
12334 | do | |
12335 | { | |
12336 | Elf_External_Vernaux evna; | |
12337 | ||
12338 | if (get_data (&evna, filedata, vna_off, sizeof (evna), 1, | |
12339 | _("version need aux (3)")) == NULL) | |
12340 | { | |
12341 | ivna.vna_next = 0; | |
12342 | ivna.vna_other = 0; | |
12343 | ivna.vna_name = 0; | |
12344 | } | |
12345 | else | |
12346 | { | |
12347 | ivna.vna_other = BYTE_GET (evna.vna_other); | |
12348 | ivna.vna_next = BYTE_GET (evna.vna_next); | |
12349 | ivna.vna_name = BYTE_GET (evna.vna_name); | |
12350 | } | |
12351 | ||
12352 | vna_off += ivna.vna_next; | |
12353 | } | |
12354 | while (ivna.vna_other != vers_data && ivna.vna_next != 0); | |
12355 | ||
12356 | if (ivna.vna_other == vers_data) | |
12357 | break; | |
12358 | ||
12359 | offset += ivn.vn_next; | |
12360 | } | |
12361 | while (ivn.vn_next != 0); | |
12362 | ||
12363 | if (ivna.vna_other == vers_data) | |
12364 | { | |
12365 | *sym_info = symbol_undefined; | |
12366 | *vna_other = ivna.vna_other; | |
12367 | return (ivna.vna_name < strtab_size | |
12368 | ? strtab + ivna.vna_name : _("<corrupt>")); | |
12369 | } | |
12370 | else if ((max_vd_ndx || (vers_data & VERSYM_VERSION) != 1) | |
12371 | && (vers_data & VERSYM_VERSION) > max_vd_ndx) | |
12372 | return _("<corrupt>"); | |
12373 | } | |
12374 | return NULL; | |
12375 | } | |
12376 | ||
12377 | static void | |
12378 | print_dynamic_symbol (Filedata *filedata, unsigned long si, | |
12379 | Elf_Internal_Sym *symtab, | |
12380 | Elf_Internal_Shdr *section, | |
12381 | char *strtab, size_t strtab_size) | |
12382 | { | |
12383 | const char *version_string; | |
12384 | enum versioned_symbol_info sym_info; | |
12385 | unsigned short vna_other; | |
12386 | Elf_Internal_Sym *psym = symtab + si; | |
12387 | ||
12388 | printf ("%6ld: ", si); | |
12389 | print_vma (psym->st_value, LONG_HEX); | |
12390 | putchar (' '); | |
12391 | print_vma (psym->st_size, DEC_5); | |
12392 | printf (" %-7s", get_symbol_type (filedata, ELF_ST_TYPE (psym->st_info))); | |
12393 | printf (" %-6s", get_symbol_binding (filedata, ELF_ST_BIND (psym->st_info))); | |
12394 | if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS) | |
12395 | printf (" %-7s", get_solaris_symbol_visibility (psym->st_other)); | |
12396 | else | |
12397 | { | |
12398 | unsigned int vis = ELF_ST_VISIBILITY (psym->st_other); | |
12399 | ||
12400 | printf (" %-7s", get_symbol_visibility (vis)); | |
12401 | /* Check to see if any other bits in the st_other field are set. | |
12402 | Note - displaying this information disrupts the layout of the | |
12403 | table being generated, but for the moment this case is very rare. */ | |
12404 | if (psym->st_other ^ vis) | |
12405 | printf (" [%s] ", get_symbol_other (filedata, psym->st_other ^ vis)); | |
12406 | } | |
12407 | printf (" %4s ", get_symbol_index_type (filedata, psym->st_shndx)); | |
12408 | ||
12409 | bfd_boolean is_valid = VALID_SYMBOL_NAME (strtab, strtab_size, | |
12410 | psym->st_name); | |
12411 | const char * sstr = is_valid ? strtab + psym->st_name : _("<corrupt>"); | |
12412 | ||
12413 | version_string | |
12414 | = get_symbol_version_string (filedata, | |
12415 | (section == NULL | |
12416 | || section->sh_type == SHT_DYNSYM), | |
12417 | strtab, strtab_size, si, | |
12418 | psym, &sym_info, &vna_other); | |
12419 | ||
12420 | int len_avail = 21; | |
12421 | if (! do_wide && version_string != NULL) | |
12422 | { | |
12423 | char buffer[16]; | |
12424 | ||
12425 | len_avail -= 1 + strlen (version_string); | |
12426 | ||
12427 | if (sym_info == symbol_undefined) | |
12428 | len_avail -= sprintf (buffer," (%d)", vna_other); | |
12429 | else if (sym_info != symbol_hidden) | |
12430 | len_avail -= 1; | |
12431 | } | |
12432 | ||
12433 | print_symbol (len_avail, sstr); | |
12434 | ||
12435 | if (version_string) | |
12436 | { | |
12437 | if (sym_info == symbol_undefined) | |
12438 | printf ("@%s (%d)", version_string, vna_other); | |
12439 | else | |
12440 | printf (sym_info == symbol_hidden ? "@%s" : "@@%s", | |
12441 | version_string); | |
12442 | } | |
12443 | ||
12444 | putchar ('\n'); | |
12445 | ||
12446 | if (ELF_ST_BIND (psym->st_info) == STB_LOCAL | |
12447 | && section != NULL | |
12448 | && si >= section->sh_info | |
12449 | /* Irix 5 and 6 MIPS binaries are known to ignore this requirement. */ | |
12450 | && filedata->file_header.e_machine != EM_MIPS | |
12451 | /* Solaris binaries have been found to violate this requirement as | |
12452 | well. Not sure if this is a bug or an ABI requirement. */ | |
12453 | && filedata->file_header.e_ident[EI_OSABI] != ELFOSABI_SOLARIS) | |
12454 | warn (_("local symbol %lu found at index >= %s's sh_info value of %u\n"), | |
12455 | si, printable_section_name (filedata, section), section->sh_info); | |
12456 | } | |
12457 | ||
12458 | static const char * | |
12459 | get_lto_kind (unsigned int kind) | |
12460 | { | |
12461 | switch (kind) | |
12462 | { | |
12463 | case 0: return "DEF"; | |
12464 | case 1: return "WEAKDEF"; | |
12465 | case 2: return "UNDEF"; | |
12466 | case 3: return "WEAKUNDEF"; | |
12467 | case 4: return "COMMON"; | |
12468 | default: | |
12469 | break; | |
12470 | } | |
12471 | ||
12472 | static char buffer[30]; | |
12473 | error (_("Unknown LTO symbol definition encountered: %u\n"), kind); | |
12474 | sprintf (buffer, "<unknown: %u>", kind); | |
12475 | return buffer; | |
12476 | } | |
12477 | ||
12478 | static const char * | |
12479 | get_lto_visibility (unsigned int visibility) | |
12480 | { | |
12481 | switch (visibility) | |
12482 | { | |
12483 | case 0: return "DEFAULT"; | |
12484 | case 1: return "PROTECTED"; | |
12485 | case 2: return "INTERNAL"; | |
12486 | case 3: return "HIDDEN"; | |
12487 | default: | |
12488 | break; | |
12489 | } | |
12490 | ||
12491 | static char buffer[30]; | |
12492 | error (_("Unknown LTO symbol visibility encountered: %u\n"), visibility); | |
12493 | sprintf (buffer, "<unknown: %u>", visibility); | |
12494 | return buffer; | |
12495 | } | |
12496 | ||
12497 | static const char * | |
12498 | get_lto_sym_type (unsigned int sym_type) | |
12499 | { | |
12500 | switch (sym_type) | |
12501 | { | |
12502 | case 0: return "UNKNOWN"; | |
12503 | case 1: return "FUNCTION"; | |
12504 | case 2: return "VARIABLE"; | |
12505 | default: | |
12506 | break; | |
12507 | } | |
12508 | ||
12509 | static char buffer[30]; | |
12510 | error (_("Unknown LTO symbol type encountered: %u\n"), sym_type); | |
12511 | sprintf (buffer, "<unknown: %u>", sym_type); | |
12512 | return buffer; | |
12513 | } | |
12514 | ||
12515 | /* Display an LTO format symbol table. | |
12516 | FIXME: The format of LTO symbol tables is not formalized. | |
12517 | So this code could need changing in the future. */ | |
12518 | ||
12519 | static bfd_boolean | |
12520 | display_lto_symtab (Filedata * filedata, | |
12521 | Elf_Internal_Shdr * section) | |
12522 | { | |
12523 | if (section->sh_size == 0) | |
12524 | { | |
12525 | if (filedata->is_separate) | |
12526 | printf (_("\nThe LTO Symbol table section '%s' in linked file '%s' is empty!\n"), | |
12527 | printable_section_name (filedata, section), | |
12528 | filedata->file_name); | |
12529 | else | |
12530 | printf (_("\nLTO Symbol table '%s' is empty!\n"), | |
12531 | printable_section_name (filedata, section)); | |
12532 | ||
12533 | return TRUE; | |
12534 | } | |
12535 | ||
12536 | if (section->sh_size > filedata->file_size) | |
12537 | { | |
12538 | error (_("Section %s has an invalid sh_size of 0x%lx\n"), | |
12539 | printable_section_name (filedata, section), | |
12540 | (unsigned long) section->sh_size); | |
12541 | return FALSE; | |
12542 | } | |
12543 | ||
12544 | void * alloced_data = get_data (NULL, filedata, section->sh_offset, | |
12545 | section->sh_size, 1, _("LTO symbols")); | |
12546 | if (alloced_data == NULL) | |
12547 | return FALSE; | |
12548 | ||
12549 | /* Look for extended data for the symbol table. */ | |
12550 | Elf_Internal_Shdr * ext; | |
12551 | void * ext_data_orig = NULL; | |
12552 | char * ext_data = NULL; | |
12553 | char * ext_data_end = NULL; | |
12554 | char * ext_name = NULL; | |
12555 | ||
12556 | if (asprintf (& ext_name, ".gnu.lto_.ext_symtab.%s", | |
12557 | SECTION_NAME (section) + sizeof (".gnu.lto_.symtab.") - 1) > 0 | |
12558 | && ext_name != NULL /* Paranoia. */ | |
12559 | && (ext = find_section (filedata, ext_name)) != NULL) | |
12560 | { | |
12561 | if (ext->sh_size < 3) | |
12562 | error (_("LTO Symbol extension table '%s' is empty!\n"), | |
12563 | printable_section_name (filedata, ext)); | |
12564 | else | |
12565 | { | |
12566 | ext_data_orig = ext_data = get_data (NULL, filedata, ext->sh_offset, | |
12567 | ext->sh_size, 1, | |
12568 | _("LTO ext symbol data")); | |
12569 | if (ext_data != NULL) | |
12570 | { | |
12571 | ext_data_end = ext_data + ext->sh_size; | |
12572 | if (* ext_data++ != 1) | |
12573 | error (_("Unexpected version number in symbol extension table\n")); | |
12574 | } | |
12575 | } | |
12576 | } | |
12577 | ||
12578 | const unsigned char * data = (const unsigned char *) alloced_data; | |
12579 | const unsigned char * end = data + section->sh_size; | |
12580 | ||
12581 | if (filedata->is_separate) | |
12582 | printf (_("\nIn linked file '%s': "), filedata->file_name); | |
12583 | else | |
12584 | printf ("\n"); | |
12585 | ||
12586 | if (ext_data_orig != NULL) | |
12587 | { | |
12588 | if (do_wide) | |
12589 | printf (_("LTO Symbol table '%s' and extension table '%s' contain:\n"), | |
12590 | printable_section_name (filedata, section), | |
12591 | printable_section_name (filedata, ext)); | |
12592 | else | |
12593 | { | |
12594 | printf (_("LTO Symbol table '%s'\n"), | |
12595 | printable_section_name (filedata, section)); | |
12596 | printf (_(" and extension table '%s' contain:\n"), | |
12597 | printable_section_name (filedata, ext)); | |
12598 | } | |
12599 | } | |
12600 | else | |
12601 | printf (_("LTO Symbol table '%s' contains:\n"), | |
12602 | printable_section_name (filedata, section)); | |
12603 | ||
12604 | /* FIXME: Add a wide version. */ | |
12605 | if (ext_data_orig != NULL) | |
12606 | printf (_(" Comdat_Key Kind Visibility Size Slot Type Section Name\n")); | |
12607 | else | |
12608 | printf (_(" Comdat_Key Kind Visibility Size Slot Name\n")); | |
12609 | ||
12610 | /* FIXME: We do not handle style prefixes. */ | |
12611 | ||
12612 | while (data < end) | |
12613 | { | |
12614 | const unsigned char * sym_name = data; | |
12615 | data += strnlen ((const char *) sym_name, end - data) + 1; | |
12616 | if (data >= end) | |
12617 | goto fail; | |
12618 | ||
12619 | const unsigned char * comdat_key = data; | |
12620 | data += strnlen ((const char *) comdat_key, end - data) + 1; | |
12621 | if (data >= end) | |
12622 | goto fail; | |
12623 | ||
12624 | if (data + 2 + 8 + 4 > end) | |
12625 | goto fail; | |
12626 | ||
12627 | unsigned int kind = *data++; | |
12628 | unsigned int visibility = *data++; | |
12629 | ||
12630 | elf_vma size = byte_get (data, 8); | |
12631 | data += 8; | |
12632 | ||
12633 | elf_vma slot = byte_get (data, 4); | |
12634 | data += 4; | |
12635 | ||
12636 | if (ext_data != NULL) | |
12637 | { | |
12638 | if (ext_data < (ext_data_end - 1)) | |
12639 | { | |
12640 | unsigned int sym_type = * ext_data ++; | |
12641 | unsigned int sec_kind = * ext_data ++; | |
12642 | ||
12643 | printf (" %10s %10s %11s %08lx %08lx %9s %08lx _", | |
12644 | * comdat_key == 0 ? "-" : (char *) comdat_key, | |
12645 | get_lto_kind (kind), | |
12646 | get_lto_visibility (visibility), | |
12647 | (long) size, | |
12648 | (long) slot, | |
12649 | get_lto_sym_type (sym_type), | |
12650 | (long) sec_kind); | |
12651 | print_symbol (6, (const char *) sym_name); | |
12652 | } | |
12653 | else | |
12654 | { | |
12655 | error (_("Ran out of LTO symbol extension data\n")); | |
12656 | ext_data = NULL; | |
12657 | /* FIXME: return FAIL result ? */ | |
12658 | } | |
12659 | } | |
12660 | else | |
12661 | { | |
12662 | printf (" %10s %10s %11s %08lx %08lx _", | |
12663 | * comdat_key == 0 ? "-" : (char *) comdat_key, | |
12664 | get_lto_kind (kind), | |
12665 | get_lto_visibility (visibility), | |
12666 | (long) size, | |
12667 | (long) slot); | |
12668 | print_symbol (21, (const char *) sym_name); | |
12669 | } | |
12670 | putchar ('\n'); | |
12671 | } | |
12672 | ||
12673 | if (ext_data != NULL && ext_data < ext_data_end) | |
12674 | { | |
12675 | error (_("Data remains in the LTO symbol extension table\n")); | |
12676 | goto fail; | |
12677 | } | |
12678 | ||
12679 | free (alloced_data); | |
12680 | free (ext_data_orig); | |
12681 | free (ext_name); | |
12682 | return TRUE; | |
12683 | ||
12684 | fail: | |
12685 | error (_("Buffer overrun encountered whilst decoding LTO symbol table\n")); | |
12686 | free (alloced_data); | |
12687 | free (ext_data_orig); | |
12688 | free (ext_name); | |
12689 | return FALSE; | |
12690 | } | |
12691 | ||
12692 | /* Display LTO symbol tables. */ | |
12693 | ||
12694 | static bfd_boolean | |
12695 | process_lto_symbol_tables (Filedata * filedata) | |
12696 | { | |
12697 | Elf_Internal_Shdr * section; | |
12698 | unsigned int i; | |
12699 | bfd_boolean res = TRUE; | |
12700 | ||
12701 | if (!do_lto_syms) | |
12702 | return TRUE; | |
12703 | ||
12704 | if (filedata->section_headers == NULL) | |
12705 | return TRUE; | |
12706 | ||
12707 | for (i = 0, section = filedata->section_headers; | |
12708 | i < filedata->file_header.e_shnum; | |
12709 | i++, section++) | |
12710 | if (SECTION_NAME_VALID (section) | |
12711 | && startswith (SECTION_NAME (section), ".gnu.lto_.symtab.")) | |
12712 | res &= display_lto_symtab (filedata, section); | |
12713 | ||
12714 | return res; | |
12715 | } | |
12716 | ||
12717 | /* Dump the symbol table. */ | |
12718 | ||
12719 | static bfd_boolean | |
12720 | process_symbol_table (Filedata * filedata) | |
12721 | { | |
12722 | Elf_Internal_Shdr * section; | |
12723 | ||
12724 | if (!do_syms && !do_dyn_syms && !do_histogram) | |
12725 | return TRUE; | |
12726 | ||
12727 | if ((filedata->dynamic_info[DT_HASH] || filedata->dynamic_info_DT_GNU_HASH) | |
12728 | && do_syms | |
12729 | && do_using_dynamic | |
12730 | && filedata->dynamic_strings != NULL | |
12731 | && filedata->dynamic_symbols != NULL) | |
12732 | { | |
12733 | unsigned long si; | |
12734 | ||
12735 | if (filedata->is_separate) | |
12736 | { | |
12737 | printf (ngettext ("\nIn linked file '%s' the dynamic symbol table contains %lu entry:\n", | |
12738 | "\nIn linked file '%s' the dynamic symbol table contains %lu entries:\n", | |
12739 | filedata->num_dynamic_syms), | |
12740 | filedata->file_name, | |
12741 | filedata->num_dynamic_syms); | |
12742 | } | |
12743 | else | |
12744 | { | |
12745 | printf (ngettext ("\nSymbol table for image contains %lu entry:\n", | |
12746 | "\nSymbol table for image contains %lu entries:\n", | |
12747 | filedata->num_dynamic_syms), | |
12748 | filedata->num_dynamic_syms); | |
12749 | } | |
12750 | if (is_32bit_elf) | |
12751 | printf (_(" Num: Value Size Type Bind Vis Ndx Name\n")); | |
12752 | else | |
12753 | printf (_(" Num: Value Size Type Bind Vis Ndx Name\n")); | |
12754 | ||
12755 | for (si = 0; si < filedata->num_dynamic_syms; si++) | |
12756 | print_dynamic_symbol (filedata, si, filedata->dynamic_symbols, NULL, | |
12757 | filedata->dynamic_strings, | |
12758 | filedata->dynamic_strings_length); | |
12759 | } | |
12760 | else if ((do_dyn_syms || (do_syms && !do_using_dynamic)) | |
12761 | && filedata->section_headers != NULL) | |
12762 | { | |
12763 | unsigned int i; | |
12764 | ||
12765 | for (i = 0, section = filedata->section_headers; | |
12766 | i < filedata->file_header.e_shnum; | |
12767 | i++, section++) | |
12768 | { | |
12769 | char * strtab = NULL; | |
12770 | unsigned long int strtab_size = 0; | |
12771 | Elf_Internal_Sym * symtab; | |
12772 | unsigned long si, num_syms; | |
12773 | ||
12774 | if ((section->sh_type != SHT_SYMTAB | |
12775 | && section->sh_type != SHT_DYNSYM) | |
12776 | || (!do_syms | |
12777 | && section->sh_type == SHT_SYMTAB)) | |
12778 | continue; | |
12779 | ||
12780 | if (section->sh_entsize == 0) | |
12781 | { | |
12782 | printf (_("\nSymbol table '%s' has a sh_entsize of zero!\n"), | |
12783 | printable_section_name (filedata, section)); | |
12784 | continue; | |
12785 | } | |
12786 | ||
12787 | num_syms = section->sh_size / section->sh_entsize; | |
12788 | ||
12789 | if (filedata->is_separate) | |
12790 | printf (ngettext ("\nIn linked file '%s' symbol section '%s' contains %lu entry:\n", | |
12791 | "\nIn linked file '%s' symbol section '%s' contains %lu entries:\n", | |
12792 | num_syms), | |
12793 | filedata->file_name, | |
12794 | printable_section_name (filedata, section), | |
12795 | num_syms); | |
12796 | else | |
12797 | printf (ngettext ("\nSymbol table '%s' contains %lu entry:\n", | |
12798 | "\nSymbol table '%s' contains %lu entries:\n", | |
12799 | num_syms), | |
12800 | printable_section_name (filedata, section), | |
12801 | num_syms); | |
12802 | ||
12803 | if (is_32bit_elf) | |
12804 | printf (_(" Num: Value Size Type Bind Vis Ndx Name\n")); | |
12805 | else | |
12806 | printf (_(" Num: Value Size Type Bind Vis Ndx Name\n")); | |
12807 | ||
12808 | symtab = GET_ELF_SYMBOLS (filedata, section, & num_syms); | |
12809 | if (symtab == NULL) | |
12810 | continue; | |
12811 | ||
12812 | if (section->sh_link == filedata->file_header.e_shstrndx) | |
12813 | { | |
12814 | strtab = filedata->string_table; | |
12815 | strtab_size = filedata->string_table_length; | |
12816 | } | |
12817 | else if (section->sh_link < filedata->file_header.e_shnum) | |
12818 | { | |
12819 | Elf_Internal_Shdr * string_sec; | |
12820 | ||
12821 | string_sec = filedata->section_headers + section->sh_link; | |
12822 | ||
12823 | strtab = (char *) get_data (NULL, filedata, string_sec->sh_offset, | |
12824 | 1, string_sec->sh_size, | |
12825 | _("string table")); | |
12826 | strtab_size = strtab != NULL ? string_sec->sh_size : 0; | |
12827 | } | |
12828 | ||
12829 | for (si = 0; si < num_syms; si++) | |
12830 | print_dynamic_symbol (filedata, si, symtab, section, | |
12831 | strtab, strtab_size); | |
12832 | ||
12833 | free (symtab); | |
12834 | if (strtab != filedata->string_table) | |
12835 | free (strtab); | |
12836 | } | |
12837 | } | |
12838 | else if (do_syms) | |
12839 | printf | |
12840 | (_("\nDynamic symbol information is not available for displaying symbols.\n")); | |
12841 | ||
12842 | if (do_histogram && filedata->buckets != NULL) | |
12843 | { | |
12844 | unsigned long * lengths; | |
12845 | unsigned long * counts; | |
12846 | unsigned long hn; | |
12847 | bfd_vma si; | |
12848 | unsigned long maxlength = 0; | |
12849 | unsigned long nzero_counts = 0; | |
12850 | unsigned long nsyms = 0; | |
12851 | char *visited; | |
12852 | ||
12853 | printf (ngettext ("\nHistogram for bucket list length " | |
12854 | "(total of %lu bucket):\n", | |
12855 | "\nHistogram for bucket list length " | |
12856 | "(total of %lu buckets):\n", | |
12857 | (unsigned long) filedata->nbuckets), | |
12858 | (unsigned long) filedata->nbuckets); | |
12859 | ||
12860 | lengths = (unsigned long *) calloc (filedata->nbuckets, | |
12861 | sizeof (*lengths)); | |
12862 | if (lengths == NULL) | |
12863 | { | |
12864 | error (_("Out of memory allocating space for histogram buckets\n")); | |
12865 | goto err_out; | |
12866 | } | |
12867 | visited = xcmalloc (filedata->nchains, 1); | |
12868 | memset (visited, 0, filedata->nchains); | |
12869 | ||
12870 | printf (_(" Length Number %% of total Coverage\n")); | |
12871 | for (hn = 0; hn < filedata->nbuckets; ++hn) | |
12872 | { | |
12873 | for (si = filedata->buckets[hn]; si > 0; si = filedata->chains[si]) | |
12874 | { | |
12875 | ++nsyms; | |
12876 | if (maxlength < ++lengths[hn]) | |
12877 | ++maxlength; | |
12878 | if (si >= filedata->nchains || visited[si]) | |
12879 | { | |
12880 | error (_("histogram chain is corrupt\n")); | |
12881 | break; | |
12882 | } | |
12883 | visited[si] = 1; | |
12884 | } | |
12885 | } | |
12886 | free (visited); | |
12887 | ||
12888 | counts = (unsigned long *) calloc (maxlength + 1, sizeof (*counts)); | |
12889 | if (counts == NULL) | |
12890 | { | |
12891 | free (lengths); | |
12892 | error (_("Out of memory allocating space for histogram counts\n")); | |
12893 | goto err_out; | |
12894 | } | |
12895 | ||
12896 | for (hn = 0; hn < filedata->nbuckets; ++hn) | |
12897 | ++counts[lengths[hn]]; | |
12898 | ||
12899 | if (filedata->nbuckets > 0) | |
12900 | { | |
12901 | unsigned long i; | |
12902 | printf (" 0 %-10lu (%5.1f%%)\n", | |
12903 | counts[0], (counts[0] * 100.0) / filedata->nbuckets); | |
12904 | for (i = 1; i <= maxlength; ++i) | |
12905 | { | |
12906 | nzero_counts += counts[i] * i; | |
12907 | printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n", | |
12908 | i, counts[i], (counts[i] * 100.0) / filedata->nbuckets, | |
12909 | (nzero_counts * 100.0) / nsyms); | |
12910 | } | |
12911 | } | |
12912 | ||
12913 | free (counts); | |
12914 | free (lengths); | |
12915 | } | |
12916 | ||
12917 | free (filedata->buckets); | |
12918 | filedata->buckets = NULL; | |
12919 | filedata->nbuckets = 0; | |
12920 | free (filedata->chains); | |
12921 | filedata->chains = NULL; | |
12922 | ||
12923 | if (do_histogram && filedata->gnubuckets != NULL) | |
12924 | { | |
12925 | unsigned long * lengths; | |
12926 | unsigned long * counts; | |
12927 | unsigned long hn; | |
12928 | unsigned long maxlength = 0; | |
12929 | unsigned long nzero_counts = 0; | |
12930 | unsigned long nsyms = 0; | |
12931 | ||
12932 | printf (ngettext ("\nHistogram for `%s' bucket list length " | |
12933 | "(total of %lu bucket):\n", | |
12934 | "\nHistogram for `%s' bucket list length " | |
12935 | "(total of %lu buckets):\n", | |
12936 | (unsigned long) filedata->ngnubuckets), | |
12937 | GNU_HASH_SECTION_NAME (filedata), | |
12938 | (unsigned long) filedata->ngnubuckets); | |
12939 | ||
12940 | lengths = (unsigned long *) calloc (filedata->ngnubuckets, | |
12941 | sizeof (*lengths)); | |
12942 | if (lengths == NULL) | |
12943 | { | |
12944 | error (_("Out of memory allocating space for gnu histogram buckets\n")); | |
12945 | goto err_out; | |
12946 | } | |
12947 | ||
12948 | printf (_(" Length Number %% of total Coverage\n")); | |
12949 | ||
12950 | for (hn = 0; hn < filedata->ngnubuckets; ++hn) | |
12951 | if (filedata->gnubuckets[hn] != 0) | |
12952 | { | |
12953 | bfd_vma off, length = 1; | |
12954 | ||
12955 | for (off = filedata->gnubuckets[hn] - filedata->gnusymidx; | |
12956 | /* PR 17531 file: 010-77222-0.004. */ | |
12957 | off < filedata->ngnuchains | |
12958 | && (filedata->gnuchains[off] & 1) == 0; | |
12959 | ++off) | |
12960 | ++length; | |
12961 | lengths[hn] = length; | |
12962 | if (length > maxlength) | |
12963 | maxlength = length; | |
12964 | nsyms += length; | |
12965 | } | |
12966 | ||
12967 | counts = (unsigned long *) calloc (maxlength + 1, sizeof (*counts)); | |
12968 | if (counts == NULL) | |
12969 | { | |
12970 | free (lengths); | |
12971 | error (_("Out of memory allocating space for gnu histogram counts\n")); | |
12972 | goto err_out; | |
12973 | } | |
12974 | ||
12975 | for (hn = 0; hn < filedata->ngnubuckets; ++hn) | |
12976 | ++counts[lengths[hn]]; | |
12977 | ||
12978 | if (filedata->ngnubuckets > 0) | |
12979 | { | |
12980 | unsigned long j; | |
12981 | printf (" 0 %-10lu (%5.1f%%)\n", | |
12982 | counts[0], (counts[0] * 100.0) / filedata->ngnubuckets); | |
12983 | for (j = 1; j <= maxlength; ++j) | |
12984 | { | |
12985 | nzero_counts += counts[j] * j; | |
12986 | printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n", | |
12987 | j, counts[j], (counts[j] * 100.0) / filedata->ngnubuckets, | |
12988 | (nzero_counts * 100.0) / nsyms); | |
12989 | } | |
12990 | } | |
12991 | ||
12992 | free (counts); | |
12993 | free (lengths); | |
12994 | } | |
12995 | free (filedata->gnubuckets); | |
12996 | filedata->gnubuckets = NULL; | |
12997 | filedata->ngnubuckets = 0; | |
12998 | free (filedata->gnuchains); | |
12999 | filedata->gnuchains = NULL; | |
13000 | filedata->ngnuchains = 0; | |
13001 | free (filedata->mipsxlat); | |
13002 | filedata->mipsxlat = NULL; | |
13003 | return TRUE; | |
13004 | ||
13005 | err_out: | |
13006 | free (filedata->gnubuckets); | |
13007 | filedata->gnubuckets = NULL; | |
13008 | filedata->ngnubuckets = 0; | |
13009 | free (filedata->gnuchains); | |
13010 | filedata->gnuchains = NULL; | |
13011 | filedata->ngnuchains = 0; | |
13012 | free (filedata->mipsxlat); | |
13013 | filedata->mipsxlat = NULL; | |
13014 | free (filedata->buckets); | |
13015 | filedata->buckets = NULL; | |
13016 | filedata->nbuckets = 0; | |
13017 | free (filedata->chains); | |
13018 | filedata->chains = NULL; | |
13019 | return FALSE; | |
13020 | } | |
13021 | ||
13022 | static bfd_boolean | |
13023 | process_syminfo (Filedata * filedata) | |
13024 | { | |
13025 | unsigned int i; | |
13026 | ||
13027 | if (filedata->dynamic_syminfo == NULL | |
13028 | || !do_dynamic) | |
13029 | /* No syminfo, this is ok. */ | |
13030 | return TRUE; | |
13031 | ||
13032 | /* There better should be a dynamic symbol section. */ | |
13033 | if (filedata->dynamic_symbols == NULL || filedata->dynamic_strings == NULL) | |
13034 | return FALSE; | |
13035 | ||
13036 | if (filedata->is_separate) | |
13037 | printf (ngettext ("\nIn linked file '%s: the dynamic info segment at offset 0x%lx contains %d entry:\n", | |
13038 | "\nIn linked file '%s: the dynamic info segment at offset 0x%lx contains %d entries:\n", | |
13039 | filedata->dynamic_syminfo_nent), | |
13040 | filedata->file_name, | |
13041 | filedata->dynamic_syminfo_offset, | |
13042 | filedata->dynamic_syminfo_nent); | |
13043 | else | |
13044 | printf (ngettext ("\nDynamic info segment at offset 0x%lx " | |
13045 | "contains %d entry:\n", | |
13046 | "\nDynamic info segment at offset 0x%lx " | |
13047 | "contains %d entries:\n", | |
13048 | filedata->dynamic_syminfo_nent), | |
13049 | filedata->dynamic_syminfo_offset, | |
13050 | filedata->dynamic_syminfo_nent); | |
13051 | ||
13052 | printf (_(" Num: Name BoundTo Flags\n")); | |
13053 | for (i = 0; i < filedata->dynamic_syminfo_nent; ++i) | |
13054 | { | |
13055 | unsigned short int flags = filedata->dynamic_syminfo[i].si_flags; | |
13056 | ||
13057 | printf ("%4d: ", i); | |
13058 | if (i >= filedata->num_dynamic_syms) | |
13059 | printf (_("<corrupt index>")); | |
13060 | else if (VALID_DYNAMIC_NAME (filedata, filedata->dynamic_symbols[i].st_name)) | |
13061 | print_symbol (30, GET_DYNAMIC_NAME (filedata, | |
13062 | filedata->dynamic_symbols[i].st_name)); | |
13063 | else | |
13064 | printf (_("<corrupt: %19ld>"), filedata->dynamic_symbols[i].st_name); | |
13065 | putchar (' '); | |
13066 | ||
13067 | switch (filedata->dynamic_syminfo[i].si_boundto) | |
13068 | { | |
13069 | case SYMINFO_BT_SELF: | |
13070 | fputs ("SELF ", stdout); | |
13071 | break; | |
13072 | case SYMINFO_BT_PARENT: | |
13073 | fputs ("PARENT ", stdout); | |
13074 | break; | |
13075 | default: | |
13076 | if (filedata->dynamic_syminfo[i].si_boundto > 0 | |
13077 | && filedata->dynamic_syminfo[i].si_boundto < filedata->dynamic_nent | |
13078 | && VALID_DYNAMIC_NAME (filedata, | |
13079 | filedata->dynamic_section[filedata->dynamic_syminfo[i].si_boundto].d_un.d_val)) | |
13080 | { | |
13081 | print_symbol (10, GET_DYNAMIC_NAME (filedata, | |
13082 | filedata->dynamic_section[filedata->dynamic_syminfo[i].si_boundto].d_un.d_val)); | |
13083 | putchar (' ' ); | |
13084 | } | |
13085 | else | |
13086 | printf ("%-10d ", filedata->dynamic_syminfo[i].si_boundto); | |
13087 | break; | |
13088 | } | |
13089 | ||
13090 | if (flags & SYMINFO_FLG_DIRECT) | |
13091 | printf (" DIRECT"); | |
13092 | if (flags & SYMINFO_FLG_PASSTHRU) | |
13093 | printf (" PASSTHRU"); | |
13094 | if (flags & SYMINFO_FLG_COPY) | |
13095 | printf (" COPY"); | |
13096 | if (flags & SYMINFO_FLG_LAZYLOAD) | |
13097 | printf (" LAZYLOAD"); | |
13098 | ||
13099 | puts (""); | |
13100 | } | |
13101 | ||
13102 | return TRUE; | |
13103 | } | |
13104 | ||
13105 | /* A macro which evaluates to TRUE if the region ADDR .. ADDR + NELEM | |
13106 | is contained by the region START .. END. The types of ADDR, START | |
13107 | and END should all be the same. Note both ADDR + NELEM and END | |
13108 | point to just beyond the end of the regions that are being tested. */ | |
13109 | #define IN_RANGE(START,END,ADDR,NELEM) \ | |
13110 | (((ADDR) >= (START)) && ((ADDR) < (END)) && ((ADDR) + (NELEM) <= (END))) | |
13111 | ||
13112 | /* Check to see if the given reloc needs to be handled in a target specific | |
13113 | manner. If so then process the reloc and return TRUE otherwise return | |
13114 | FALSE. | |
13115 | ||
13116 | If called with reloc == NULL, then this is a signal that reloc processing | |
13117 | for the current section has finished, and any saved state should be | |
13118 | discarded. */ | |
13119 | ||
13120 | static bfd_boolean | |
13121 | target_specific_reloc_handling (Filedata * filedata, | |
13122 | Elf_Internal_Rela * reloc, | |
13123 | unsigned char * start, | |
13124 | unsigned char * end, | |
13125 | Elf_Internal_Sym * symtab, | |
13126 | unsigned long num_syms) | |
13127 | { | |
13128 | unsigned int reloc_type = 0; | |
13129 | unsigned long sym_index = 0; | |
13130 | ||
13131 | if (reloc) | |
13132 | { | |
13133 | reloc_type = get_reloc_type (filedata, reloc->r_info); | |
13134 | sym_index = get_reloc_symindex (reloc->r_info); | |
13135 | } | |
13136 | ||
13137 | switch (filedata->file_header.e_machine) | |
13138 | { | |
13139 | case EM_MSP430: | |
13140 | case EM_MSP430_OLD: | |
13141 | { | |
13142 | static Elf_Internal_Sym * saved_sym = NULL; | |
13143 | ||
13144 | if (reloc == NULL) | |
13145 | { | |
13146 | saved_sym = NULL; | |
13147 | return TRUE; | |
13148 | } | |
13149 | ||
13150 | switch (reloc_type) | |
13151 | { | |
13152 | case 10: /* R_MSP430_SYM_DIFF */ | |
13153 | case 12: /* R_MSP430_GNU_SUB_ULEB128 */ | |
13154 | if (uses_msp430x_relocs (filedata)) | |
13155 | break; | |
13156 | /* Fall through. */ | |
13157 | case 21: /* R_MSP430X_SYM_DIFF */ | |
13158 | case 23: /* R_MSP430X_GNU_SUB_ULEB128 */ | |
13159 | /* PR 21139. */ | |
13160 | if (sym_index >= num_syms) | |
13161 | error (_("MSP430 SYM_DIFF reloc contains invalid symbol index %lu\n"), | |
13162 | sym_index); | |
13163 | else | |
13164 | saved_sym = symtab + sym_index; | |
13165 | return TRUE; | |
13166 | ||
13167 | case 1: /* R_MSP430_32 or R_MSP430_ABS32 */ | |
13168 | case 3: /* R_MSP430_16 or R_MSP430_ABS8 */ | |
13169 | goto handle_sym_diff; | |
13170 | ||
13171 | case 5: /* R_MSP430_16_BYTE */ | |
13172 | case 9: /* R_MSP430_8 */ | |
13173 | case 11: /* R_MSP430_GNU_SET_ULEB128 */ | |
13174 | if (uses_msp430x_relocs (filedata)) | |
13175 | break; | |
13176 | goto handle_sym_diff; | |
13177 | ||
13178 | case 2: /* R_MSP430_ABS16 */ | |
13179 | case 15: /* R_MSP430X_ABS16 */ | |
13180 | case 22: /* R_MSP430X_GNU_SET_ULEB128 */ | |
13181 | if (! uses_msp430x_relocs (filedata)) | |
13182 | break; | |
13183 | goto handle_sym_diff; | |
13184 | ||
13185 | handle_sym_diff: | |
13186 | if (saved_sym != NULL) | |
13187 | { | |
13188 | bfd_vma value; | |
13189 | unsigned int reloc_size = 0; | |
13190 | int leb_ret = 0; | |
13191 | switch (reloc_type) | |
13192 | { | |
13193 | case 1: /* R_MSP430_32 or R_MSP430_ABS32 */ | |
13194 | reloc_size = 4; | |
13195 | break; | |
13196 | case 11: /* R_MSP430_GNU_SET_ULEB128 */ | |
13197 | case 22: /* R_MSP430X_GNU_SET_ULEB128 */ | |
13198 | if (reloc->r_offset < (size_t) (end - start)) | |
13199 | read_leb128 (start + reloc->r_offset, end, FALSE, | |
13200 | &reloc_size, &leb_ret); | |
13201 | break; | |
13202 | default: | |
13203 | reloc_size = 2; | |
13204 | break; | |
13205 | } | |
13206 | ||
13207 | if (leb_ret != 0 || reloc_size == 0 || reloc_size > 8) | |
13208 | error (_("MSP430 ULEB128 field at 0x%lx contains invalid " | |
13209 | "ULEB128 value\n"), | |
13210 | (long) reloc->r_offset); | |
13211 | else if (sym_index >= num_syms) | |
13212 | error (_("MSP430 reloc contains invalid symbol index %lu\n"), | |
13213 | sym_index); | |
13214 | else | |
13215 | { | |
13216 | value = reloc->r_addend + (symtab[sym_index].st_value | |
13217 | - saved_sym->st_value); | |
13218 | ||
13219 | if (IN_RANGE (start, end, start + reloc->r_offset, reloc_size)) | |
13220 | byte_put (start + reloc->r_offset, value, reloc_size); | |
13221 | else | |
13222 | /* PR 21137 */ | |
13223 | error (_("MSP430 sym diff reloc contains invalid offset: 0x%lx\n"), | |
13224 | (long) reloc->r_offset); | |
13225 | } | |
13226 | ||
13227 | saved_sym = NULL; | |
13228 | return TRUE; | |
13229 | } | |
13230 | break; | |
13231 | ||
13232 | default: | |
13233 | if (saved_sym != NULL) | |
13234 | error (_("Unhandled MSP430 reloc type found after SYM_DIFF reloc\n")); | |
13235 | break; | |
13236 | } | |
13237 | break; | |
13238 | } | |
13239 | ||
13240 | case EM_MN10300: | |
13241 | case EM_CYGNUS_MN10300: | |
13242 | { | |
13243 | static Elf_Internal_Sym * saved_sym = NULL; | |
13244 | ||
13245 | if (reloc == NULL) | |
13246 | { | |
13247 | saved_sym = NULL; | |
13248 | return TRUE; | |
13249 | } | |
13250 | ||
13251 | switch (reloc_type) | |
13252 | { | |
13253 | case 34: /* R_MN10300_ALIGN */ | |
13254 | return TRUE; | |
13255 | case 33: /* R_MN10300_SYM_DIFF */ | |
13256 | if (sym_index >= num_syms) | |
13257 | error (_("MN10300_SYM_DIFF reloc contains invalid symbol index %lu\n"), | |
13258 | sym_index); | |
13259 | else | |
13260 | saved_sym = symtab + sym_index; | |
13261 | return TRUE; | |
13262 | ||
13263 | case 1: /* R_MN10300_32 */ | |
13264 | case 2: /* R_MN10300_16 */ | |
13265 | if (saved_sym != NULL) | |
13266 | { | |
13267 | int reloc_size = reloc_type == 1 ? 4 : 2; | |
13268 | bfd_vma value; | |
13269 | ||
13270 | if (sym_index >= num_syms) | |
13271 | error (_("MN10300 reloc contains invalid symbol index %lu\n"), | |
13272 | sym_index); | |
13273 | else | |
13274 | { | |
13275 | value = reloc->r_addend + (symtab[sym_index].st_value | |
13276 | - saved_sym->st_value); | |
13277 | ||
13278 | if (IN_RANGE (start, end, start + reloc->r_offset, reloc_size)) | |
13279 | byte_put (start + reloc->r_offset, value, reloc_size); | |
13280 | else | |
13281 | error (_("MN10300 sym diff reloc contains invalid offset: 0x%lx\n"), | |
13282 | (long) reloc->r_offset); | |
13283 | } | |
13284 | ||
13285 | saved_sym = NULL; | |
13286 | return TRUE; | |
13287 | } | |
13288 | break; | |
13289 | default: | |
13290 | if (saved_sym != NULL) | |
13291 | error (_("Unhandled MN10300 reloc type found after SYM_DIFF reloc\n")); | |
13292 | break; | |
13293 | } | |
13294 | break; | |
13295 | } | |
13296 | ||
13297 | case EM_RL78: | |
13298 | { | |
13299 | static bfd_vma saved_sym1 = 0; | |
13300 | static bfd_vma saved_sym2 = 0; | |
13301 | static bfd_vma value; | |
13302 | ||
13303 | if (reloc == NULL) | |
13304 | { | |
13305 | saved_sym1 = saved_sym2 = 0; | |
13306 | return TRUE; | |
13307 | } | |
13308 | ||
13309 | switch (reloc_type) | |
13310 | { | |
13311 | case 0x80: /* R_RL78_SYM. */ | |
13312 | saved_sym1 = saved_sym2; | |
13313 | if (sym_index >= num_syms) | |
13314 | error (_("RL78_SYM reloc contains invalid symbol index %lu\n"), | |
13315 | sym_index); | |
13316 | else | |
13317 | { | |
13318 | saved_sym2 = symtab[sym_index].st_value; | |
13319 | saved_sym2 += reloc->r_addend; | |
13320 | } | |
13321 | return TRUE; | |
13322 | ||
13323 | case 0x83: /* R_RL78_OPsub. */ | |
13324 | value = saved_sym1 - saved_sym2; | |
13325 | saved_sym2 = saved_sym1 = 0; | |
13326 | return TRUE; | |
13327 | break; | |
13328 | ||
13329 | case 0x41: /* R_RL78_ABS32. */ | |
13330 | if (IN_RANGE (start, end, start + reloc->r_offset, 4)) | |
13331 | byte_put (start + reloc->r_offset, value, 4); | |
13332 | else | |
13333 | error (_("RL78 sym diff reloc contains invalid offset: 0x%lx\n"), | |
13334 | (long) reloc->r_offset); | |
13335 | value = 0; | |
13336 | return TRUE; | |
13337 | ||
13338 | case 0x43: /* R_RL78_ABS16. */ | |
13339 | if (IN_RANGE (start, end, start + reloc->r_offset, 2)) | |
13340 | byte_put (start + reloc->r_offset, value, 2); | |
13341 | else | |
13342 | error (_("RL78 sym diff reloc contains invalid offset: 0x%lx\n"), | |
13343 | (long) reloc->r_offset); | |
13344 | value = 0; | |
13345 | return TRUE; | |
13346 | ||
13347 | default: | |
13348 | break; | |
13349 | } | |
13350 | break; | |
13351 | } | |
13352 | } | |
13353 | ||
13354 | return FALSE; | |
13355 | } | |
13356 | ||
13357 | /* Returns TRUE iff RELOC_TYPE is a 32-bit absolute RELA relocation used in | |
13358 | DWARF debug sections. This is a target specific test. Note - we do not | |
13359 | go through the whole including-target-headers-multiple-times route, (as | |
13360 | we have already done with <elf/h8.h>) because this would become very | |
13361 | messy and even then this function would have to contain target specific | |
13362 | information (the names of the relocs instead of their numeric values). | |
13363 | FIXME: This is not the correct way to solve this problem. The proper way | |
13364 | is to have target specific reloc sizing and typing functions created by | |
13365 | the reloc-macros.h header, in the same way that it already creates the | |
13366 | reloc naming functions. */ | |
13367 | ||
13368 | static bfd_boolean | |
13369 | is_32bit_abs_reloc (Filedata * filedata, unsigned int reloc_type) | |
13370 | { | |
13371 | /* Please keep this table alpha-sorted for ease of visual lookup. */ | |
13372 | switch (filedata->file_header.e_machine) | |
13373 | { | |
13374 | case EM_386: | |
13375 | case EM_IAMCU: | |
13376 | return reloc_type == 1; /* R_386_32. */ | |
13377 | case EM_68K: | |
13378 | return reloc_type == 1; /* R_68K_32. */ | |
13379 | case EM_860: | |
13380 | return reloc_type == 1; /* R_860_32. */ | |
13381 | case EM_960: | |
13382 | return reloc_type == 2; /* R_960_32. */ | |
13383 | case EM_AARCH64: | |
13384 | return (reloc_type == 258 | |
13385 | || reloc_type == 1); /* R_AARCH64_ABS32 || R_AARCH64_P32_ABS32 */ | |
13386 | case EM_BPF: | |
13387 | return reloc_type == 11; /* R_BPF_DATA_32 */ | |
13388 | case EM_ADAPTEVA_EPIPHANY: | |
13389 | return reloc_type == 3; | |
13390 | case EM_ALPHA: | |
13391 | return reloc_type == 1; /* R_ALPHA_REFLONG. */ | |
13392 | case EM_ARC: | |
13393 | return reloc_type == 1; /* R_ARC_32. */ | |
13394 | case EM_ARC_COMPACT: | |
13395 | case EM_ARC_COMPACT2: | |
13396 | return reloc_type == 4; /* R_ARC_32. */ | |
13397 | case EM_ARM: | |
13398 | return reloc_type == 2; /* R_ARM_ABS32 */ | |
13399 | case EM_AVR_OLD: | |
13400 | case EM_AVR: | |
13401 | return reloc_type == 1; | |
13402 | case EM_BLACKFIN: | |
13403 | return reloc_type == 0x12; /* R_byte4_data. */ | |
13404 | case EM_CRIS: | |
13405 | return reloc_type == 3; /* R_CRIS_32. */ | |
13406 | case EM_CR16: | |
13407 | return reloc_type == 3; /* R_CR16_NUM32. */ | |
13408 | case EM_CRX: | |
13409 | return reloc_type == 15; /* R_CRX_NUM32. */ | |
13410 | case EM_CSKY: | |
13411 | return reloc_type == 1; /* R_CKCORE_ADDR32. */ | |
13412 | case EM_CYGNUS_FRV: | |
13413 | return reloc_type == 1; | |
13414 | case EM_CYGNUS_D10V: | |
13415 | case EM_D10V: | |
13416 | return reloc_type == 6; /* R_D10V_32. */ | |
13417 | case EM_CYGNUS_D30V: | |
13418 | case EM_D30V: | |
13419 | return reloc_type == 12; /* R_D30V_32_NORMAL. */ | |
13420 | case EM_DLX: | |
13421 | return reloc_type == 3; /* R_DLX_RELOC_32. */ | |
13422 | case EM_CYGNUS_FR30: | |
13423 | case EM_FR30: | |
13424 | return reloc_type == 3; /* R_FR30_32. */ | |
13425 | case EM_FT32: | |
13426 | return reloc_type == 1; /* R_FT32_32. */ | |
13427 | case EM_H8S: | |
13428 | case EM_H8_300: | |
13429 | case EM_H8_300H: | |
13430 | return reloc_type == 1; /* R_H8_DIR32. */ | |
13431 | case EM_IA_64: | |
13432 | return (reloc_type == 0x64 /* R_IA64_SECREL32MSB. */ | |
13433 | || reloc_type == 0x65 /* R_IA64_SECREL32LSB. */ | |
13434 | || reloc_type == 0x24 /* R_IA64_DIR32MSB. */ | |
13435 | || reloc_type == 0x25 /* R_IA64_DIR32LSB. */); | |
13436 | case EM_IP2K_OLD: | |
13437 | case EM_IP2K: | |
13438 | return reloc_type == 2; /* R_IP2K_32. */ | |
13439 | case EM_IQ2000: | |
13440 | return reloc_type == 2; /* R_IQ2000_32. */ | |
13441 | case EM_LATTICEMICO32: | |
13442 | return reloc_type == 3; /* R_LM32_32. */ | |
13443 | case EM_M32C_OLD: | |
13444 | case EM_M32C: | |
13445 | return reloc_type == 3; /* R_M32C_32. */ | |
13446 | case EM_M32R: | |
13447 | return reloc_type == 34; /* R_M32R_32_RELA. */ | |
13448 | case EM_68HC11: | |
13449 | case EM_68HC12: | |
13450 | return reloc_type == 6; /* R_M68HC11_32. */ | |
13451 | case EM_S12Z: | |
13452 | return reloc_type == 7 || /* R_S12Z_EXT32 */ | |
13453 | reloc_type == 6; /* R_S12Z_CW32. */ | |
13454 | case EM_MCORE: | |
13455 | return reloc_type == 1; /* R_MCORE_ADDR32. */ | |
13456 | case EM_CYGNUS_MEP: | |
13457 | return reloc_type == 4; /* R_MEP_32. */ | |
13458 | case EM_METAG: | |
13459 | return reloc_type == 2; /* R_METAG_ADDR32. */ | |
13460 | case EM_MICROBLAZE: | |
13461 | return reloc_type == 1; /* R_MICROBLAZE_32. */ | |
13462 | case EM_MIPS: | |
13463 | return reloc_type == 2; /* R_MIPS_32. */ | |
13464 | case EM_MMIX: | |
13465 | return reloc_type == 4; /* R_MMIX_32. */ | |
13466 | case EM_CYGNUS_MN10200: | |
13467 | case EM_MN10200: | |
13468 | return reloc_type == 1; /* R_MN10200_32. */ | |
13469 | case EM_CYGNUS_MN10300: | |
13470 | case EM_MN10300: | |
13471 | return reloc_type == 1; /* R_MN10300_32. */ | |
13472 | case EM_MOXIE: | |
13473 | return reloc_type == 1; /* R_MOXIE_32. */ | |
13474 | case EM_MSP430_OLD: | |
13475 | case EM_MSP430: | |
13476 | return reloc_type == 1; /* R_MSP430_32 or R_MSP320_ABS32. */ | |
13477 | case EM_MT: | |
13478 | return reloc_type == 2; /* R_MT_32. */ | |
13479 | case EM_NDS32: | |
13480 | return reloc_type == 20; /* R_NDS32_RELA. */ | |
13481 | case EM_ALTERA_NIOS2: | |
13482 | return reloc_type == 12; /* R_NIOS2_BFD_RELOC_32. */ | |
13483 | case EM_NIOS32: | |
13484 | return reloc_type == 1; /* R_NIOS_32. */ | |
13485 | case EM_OR1K: | |
13486 | return reloc_type == 1; /* R_OR1K_32. */ | |
13487 | case EM_PARISC: | |
13488 | return (reloc_type == 1 /* R_PARISC_DIR32. */ | |
13489 | || reloc_type == 2 /* R_PARISC_DIR21L. */ | |
13490 | || reloc_type == 41); /* R_PARISC_SECREL32. */ | |
13491 | case EM_PJ: | |
13492 | case EM_PJ_OLD: | |
13493 | return reloc_type == 1; /* R_PJ_DATA_DIR32. */ | |
13494 | case EM_PPC64: | |
13495 | return reloc_type == 1; /* R_PPC64_ADDR32. */ | |
13496 | case EM_PPC: | |
13497 | return reloc_type == 1; /* R_PPC_ADDR32. */ | |
13498 | case EM_TI_PRU: | |
13499 | return reloc_type == 11; /* R_PRU_BFD_RELOC_32. */ | |
13500 | case EM_RISCV: | |
13501 | return reloc_type == 1; /* R_RISCV_32. */ | |
13502 | case EM_RL78: | |
13503 | return reloc_type == 1; /* R_RL78_DIR32. */ | |
13504 | case EM_RX: | |
13505 | return reloc_type == 1; /* R_RX_DIR32. */ | |
13506 | case EM_S370: | |
13507 | return reloc_type == 1; /* R_I370_ADDR31. */ | |
13508 | case EM_S390_OLD: | |
13509 | case EM_S390: | |
13510 | return reloc_type == 4; /* R_S390_32. */ | |
13511 | case EM_SCORE: | |
13512 | return reloc_type == 8; /* R_SCORE_ABS32. */ | |
13513 | case EM_SH: | |
13514 | return reloc_type == 1; /* R_SH_DIR32. */ | |
13515 | case EM_SPARC32PLUS: | |
13516 | case EM_SPARCV9: | |
13517 | case EM_SPARC: | |
13518 | return reloc_type == 3 /* R_SPARC_32. */ | |
13519 | || reloc_type == 23; /* R_SPARC_UA32. */ | |
13520 | case EM_SPU: | |
13521 | return reloc_type == 6; /* R_SPU_ADDR32 */ | |
13522 | case EM_TI_C6000: | |
13523 | return reloc_type == 1; /* R_C6000_ABS32. */ | |
13524 | case EM_TILEGX: | |
13525 | return reloc_type == 2; /* R_TILEGX_32. */ | |
13526 | case EM_TILEPRO: | |
13527 | return reloc_type == 1; /* R_TILEPRO_32. */ | |
13528 | case EM_CYGNUS_V850: | |
13529 | case EM_V850: | |
13530 | return reloc_type == 6; /* R_V850_ABS32. */ | |
13531 | case EM_V800: | |
13532 | return reloc_type == 0x33; /* R_V810_WORD. */ | |
13533 | case EM_VAX: | |
13534 | return reloc_type == 1; /* R_VAX_32. */ | |
13535 | case EM_VISIUM: | |
13536 | return reloc_type == 3; /* R_VISIUM_32. */ | |
13537 | case EM_WEBASSEMBLY: | |
13538 | return reloc_type == 1; /* R_WASM32_32. */ | |
13539 | case EM_X86_64: | |
13540 | case EM_L1OM: | |
13541 | case EM_K1OM: | |
13542 | return reloc_type == 10; /* R_X86_64_32. */ | |
13543 | case EM_XC16X: | |
13544 | case EM_C166: | |
13545 | return reloc_type == 3; /* R_XC16C_ABS_32. */ | |
13546 | case EM_XGATE: | |
13547 | return reloc_type == 4; /* R_XGATE_32. */ | |
13548 | case EM_XSTORMY16: | |
13549 | return reloc_type == 1; /* R_XSTROMY16_32. */ | |
13550 | case EM_XTENSA_OLD: | |
13551 | case EM_XTENSA: | |
13552 | return reloc_type == 1; /* R_XTENSA_32. */ | |
13553 | case EM_Z80: | |
13554 | return reloc_type == 6; /* R_Z80_32. */ | |
13555 | default: | |
13556 | { | |
13557 | static unsigned int prev_warn = 0; | |
13558 | ||
13559 | /* Avoid repeating the same warning multiple times. */ | |
13560 | if (prev_warn != filedata->file_header.e_machine) | |
13561 | error (_("Missing knowledge of 32-bit reloc types used in DWARF sections of machine number %d\n"), | |
13562 | filedata->file_header.e_machine); | |
13563 | prev_warn = filedata->file_header.e_machine; | |
13564 | return FALSE; | |
13565 | } | |
13566 | } | |
13567 | } | |
13568 | ||
13569 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
13570 | a 32-bit pc-relative RELA relocation used in DWARF debug sections. */ | |
13571 | ||
13572 | static bfd_boolean | |
13573 | is_32bit_pcrel_reloc (Filedata * filedata, unsigned int reloc_type) | |
13574 | { | |
13575 | switch (filedata->file_header.e_machine) | |
13576 | /* Please keep this table alpha-sorted for ease of visual lookup. */ | |
13577 | { | |
13578 | case EM_386: | |
13579 | case EM_IAMCU: | |
13580 | return reloc_type == 2; /* R_386_PC32. */ | |
13581 | case EM_68K: | |
13582 | return reloc_type == 4; /* R_68K_PC32. */ | |
13583 | case EM_AARCH64: | |
13584 | return reloc_type == 261; /* R_AARCH64_PREL32 */ | |
13585 | case EM_ADAPTEVA_EPIPHANY: | |
13586 | return reloc_type == 6; | |
13587 | case EM_ALPHA: | |
13588 | return reloc_type == 10; /* R_ALPHA_SREL32. */ | |
13589 | case EM_ARC_COMPACT: | |
13590 | case EM_ARC_COMPACT2: | |
13591 | return reloc_type == 49; /* R_ARC_32_PCREL. */ | |
13592 | case EM_ARM: | |
13593 | return reloc_type == 3; /* R_ARM_REL32 */ | |
13594 | case EM_AVR_OLD: | |
13595 | case EM_AVR: | |
13596 | return reloc_type == 36; /* R_AVR_32_PCREL. */ | |
13597 | case EM_MICROBLAZE: | |
13598 | return reloc_type == 2; /* R_MICROBLAZE_32_PCREL. */ | |
13599 | case EM_OR1K: | |
13600 | return reloc_type == 9; /* R_OR1K_32_PCREL. */ | |
13601 | case EM_PARISC: | |
13602 | return reloc_type == 9; /* R_PARISC_PCREL32. */ | |
13603 | case EM_PPC: | |
13604 | return reloc_type == 26; /* R_PPC_REL32. */ | |
13605 | case EM_PPC64: | |
13606 | return reloc_type == 26; /* R_PPC64_REL32. */ | |
13607 | case EM_RISCV: | |
13608 | return reloc_type == 57; /* R_RISCV_32_PCREL. */ | |
13609 | case EM_S390_OLD: | |
13610 | case EM_S390: | |
13611 | return reloc_type == 5; /* R_390_PC32. */ | |
13612 | case EM_SH: | |
13613 | return reloc_type == 2; /* R_SH_REL32. */ | |
13614 | case EM_SPARC32PLUS: | |
13615 | case EM_SPARCV9: | |
13616 | case EM_SPARC: | |
13617 | return reloc_type == 6; /* R_SPARC_DISP32. */ | |
13618 | case EM_SPU: | |
13619 | return reloc_type == 13; /* R_SPU_REL32. */ | |
13620 | case EM_TILEGX: | |
13621 | return reloc_type == 6; /* R_TILEGX_32_PCREL. */ | |
13622 | case EM_TILEPRO: | |
13623 | return reloc_type == 4; /* R_TILEPRO_32_PCREL. */ | |
13624 | case EM_VISIUM: | |
13625 | return reloc_type == 6; /* R_VISIUM_32_PCREL */ | |
13626 | case EM_X86_64: | |
13627 | case EM_L1OM: | |
13628 | case EM_K1OM: | |
13629 | return reloc_type == 2; /* R_X86_64_PC32. */ | |
13630 | case EM_VAX: | |
13631 | return reloc_type == 4; /* R_VAX_PCREL32. */ | |
13632 | case EM_XTENSA_OLD: | |
13633 | case EM_XTENSA: | |
13634 | return reloc_type == 14; /* R_XTENSA_32_PCREL. */ | |
13635 | default: | |
13636 | /* Do not abort or issue an error message here. Not all targets use | |
13637 | pc-relative 32-bit relocs in their DWARF debug information and we | |
13638 | have already tested for target coverage in is_32bit_abs_reloc. A | |
13639 | more helpful warning message will be generated by apply_relocations | |
13640 | anyway, so just return. */ | |
13641 | return FALSE; | |
13642 | } | |
13643 | } | |
13644 | ||
13645 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
13646 | a 64-bit absolute RELA relocation used in DWARF debug sections. */ | |
13647 | ||
13648 | static bfd_boolean | |
13649 | is_64bit_abs_reloc (Filedata * filedata, unsigned int reloc_type) | |
13650 | { | |
13651 | switch (filedata->file_header.e_machine) | |
13652 | { | |
13653 | case EM_AARCH64: | |
13654 | return reloc_type == 257; /* R_AARCH64_ABS64. */ | |
13655 | case EM_ALPHA: | |
13656 | return reloc_type == 2; /* R_ALPHA_REFQUAD. */ | |
13657 | case EM_IA_64: | |
13658 | return (reloc_type == 0x26 /* R_IA64_DIR64MSB. */ | |
13659 | || reloc_type == 0x27 /* R_IA64_DIR64LSB. */); | |
13660 | case EM_PARISC: | |
13661 | return reloc_type == 80; /* R_PARISC_DIR64. */ | |
13662 | case EM_PPC64: | |
13663 | return reloc_type == 38; /* R_PPC64_ADDR64. */ | |
13664 | case EM_RISCV: | |
13665 | return reloc_type == 2; /* R_RISCV_64. */ | |
13666 | case EM_SPARC32PLUS: | |
13667 | case EM_SPARCV9: | |
13668 | case EM_SPARC: | |
13669 | return reloc_type == 32 /* R_SPARC_64. */ | |
13670 | || reloc_type == 54; /* R_SPARC_UA64. */ | |
13671 | case EM_X86_64: | |
13672 | case EM_L1OM: | |
13673 | case EM_K1OM: | |
13674 | return reloc_type == 1; /* R_X86_64_64. */ | |
13675 | case EM_S390_OLD: | |
13676 | case EM_S390: | |
13677 | return reloc_type == 22; /* R_S390_64. */ | |
13678 | case EM_TILEGX: | |
13679 | return reloc_type == 1; /* R_TILEGX_64. */ | |
13680 | case EM_MIPS: | |
13681 | return reloc_type == 18; /* R_MIPS_64. */ | |
13682 | default: | |
13683 | return FALSE; | |
13684 | } | |
13685 | } | |
13686 | ||
13687 | /* Like is_32bit_pcrel_reloc except that it returns TRUE iff RELOC_TYPE is | |
13688 | a 64-bit pc-relative RELA relocation used in DWARF debug sections. */ | |
13689 | ||
13690 | static bfd_boolean | |
13691 | is_64bit_pcrel_reloc (Filedata * filedata, unsigned int reloc_type) | |
13692 | { | |
13693 | switch (filedata->file_header.e_machine) | |
13694 | { | |
13695 | case EM_AARCH64: | |
13696 | return reloc_type == 260; /* R_AARCH64_PREL64. */ | |
13697 | case EM_ALPHA: | |
13698 | return reloc_type == 11; /* R_ALPHA_SREL64. */ | |
13699 | case EM_IA_64: | |
13700 | return (reloc_type == 0x4e /* R_IA64_PCREL64MSB. */ | |
13701 | || reloc_type == 0x4f /* R_IA64_PCREL64LSB. */); | |
13702 | case EM_PARISC: | |
13703 | return reloc_type == 72; /* R_PARISC_PCREL64. */ | |
13704 | case EM_PPC64: | |
13705 | return reloc_type == 44; /* R_PPC64_REL64. */ | |
13706 | case EM_SPARC32PLUS: | |
13707 | case EM_SPARCV9: | |
13708 | case EM_SPARC: | |
13709 | return reloc_type == 46; /* R_SPARC_DISP64. */ | |
13710 | case EM_X86_64: | |
13711 | case EM_L1OM: | |
13712 | case EM_K1OM: | |
13713 | return reloc_type == 24; /* R_X86_64_PC64. */ | |
13714 | case EM_S390_OLD: | |
13715 | case EM_S390: | |
13716 | return reloc_type == 23; /* R_S390_PC64. */ | |
13717 | case EM_TILEGX: | |
13718 | return reloc_type == 5; /* R_TILEGX_64_PCREL. */ | |
13719 | default: | |
13720 | return FALSE; | |
13721 | } | |
13722 | } | |
13723 | ||
13724 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
13725 | a 24-bit absolute RELA relocation used in DWARF debug sections. */ | |
13726 | ||
13727 | static bfd_boolean | |
13728 | is_24bit_abs_reloc (Filedata * filedata, unsigned int reloc_type) | |
13729 | { | |
13730 | switch (filedata->file_header.e_machine) | |
13731 | { | |
13732 | case EM_CYGNUS_MN10200: | |
13733 | case EM_MN10200: | |
13734 | return reloc_type == 4; /* R_MN10200_24. */ | |
13735 | case EM_FT32: | |
13736 | return reloc_type == 5; /* R_FT32_20. */ | |
13737 | case EM_Z80: | |
13738 | return reloc_type == 5; /* R_Z80_24. */ | |
13739 | default: | |
13740 | return FALSE; | |
13741 | } | |
13742 | } | |
13743 | ||
13744 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
13745 | a 16-bit absolute RELA relocation used in DWARF debug sections. */ | |
13746 | ||
13747 | static bfd_boolean | |
13748 | is_16bit_abs_reloc (Filedata * filedata, unsigned int reloc_type) | |
13749 | { | |
13750 | /* Please keep this table alpha-sorted for ease of visual lookup. */ | |
13751 | switch (filedata->file_header.e_machine) | |
13752 | { | |
13753 | case EM_ARC: | |
13754 | case EM_ARC_COMPACT: | |
13755 | case EM_ARC_COMPACT2: | |
13756 | return reloc_type == 2; /* R_ARC_16. */ | |
13757 | case EM_ADAPTEVA_EPIPHANY: | |
13758 | return reloc_type == 5; | |
13759 | case EM_AVR_OLD: | |
13760 | case EM_AVR: | |
13761 | return reloc_type == 4; /* R_AVR_16. */ | |
13762 | case EM_CYGNUS_D10V: | |
13763 | case EM_D10V: | |
13764 | return reloc_type == 3; /* R_D10V_16. */ | |
13765 | case EM_FT32: | |
13766 | return reloc_type == 2; /* R_FT32_16. */ | |
13767 | case EM_H8S: | |
13768 | case EM_H8_300: | |
13769 | case EM_H8_300H: | |
13770 | return reloc_type == R_H8_DIR16; | |
13771 | case EM_IP2K_OLD: | |
13772 | case EM_IP2K: | |
13773 | return reloc_type == 1; /* R_IP2K_16. */ | |
13774 | case EM_M32C_OLD: | |
13775 | case EM_M32C: | |
13776 | return reloc_type == 1; /* R_M32C_16 */ | |
13777 | case EM_CYGNUS_MN10200: | |
13778 | case EM_MN10200: | |
13779 | return reloc_type == 2; /* R_MN10200_16. */ | |
13780 | case EM_CYGNUS_MN10300: | |
13781 | case EM_MN10300: | |
13782 | return reloc_type == 2; /* R_MN10300_16. */ | |
13783 | case EM_MSP430: | |
13784 | if (uses_msp430x_relocs (filedata)) | |
13785 | return reloc_type == 2; /* R_MSP430_ABS16. */ | |
13786 | /* Fall through. */ | |
13787 | case EM_MSP430_OLD: | |
13788 | return reloc_type == 5; /* R_MSP430_16_BYTE. */ | |
13789 | case EM_NDS32: | |
13790 | return reloc_type == 19; /* R_NDS32_RELA. */ | |
13791 | case EM_ALTERA_NIOS2: | |
13792 | return reloc_type == 13; /* R_NIOS2_BFD_RELOC_16. */ | |
13793 | case EM_NIOS32: | |
13794 | return reloc_type == 9; /* R_NIOS_16. */ | |
13795 | case EM_OR1K: | |
13796 | return reloc_type == 2; /* R_OR1K_16. */ | |
13797 | case EM_RISCV: | |
13798 | return reloc_type == 55; /* R_RISCV_SET16. */ | |
13799 | case EM_TI_PRU: | |
13800 | return reloc_type == 8; /* R_PRU_BFD_RELOC_16. */ | |
13801 | case EM_TI_C6000: | |
13802 | return reloc_type == 2; /* R_C6000_ABS16. */ | |
13803 | case EM_VISIUM: | |
13804 | return reloc_type == 2; /* R_VISIUM_16. */ | |
13805 | case EM_XC16X: | |
13806 | case EM_C166: | |
13807 | return reloc_type == 2; /* R_XC16C_ABS_16. */ | |
13808 | case EM_XGATE: | |
13809 | return reloc_type == 3; /* R_XGATE_16. */ | |
13810 | case EM_Z80: | |
13811 | return reloc_type == 4; /* R_Z80_16. */ | |
13812 | default: | |
13813 | return FALSE; | |
13814 | } | |
13815 | } | |
13816 | ||
13817 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
13818 | a 8-bit absolute RELA relocation used in DWARF debug sections. */ | |
13819 | ||
13820 | static bfd_boolean | |
13821 | is_8bit_abs_reloc (Filedata * filedata, unsigned int reloc_type) | |
13822 | { | |
13823 | switch (filedata->file_header.e_machine) | |
13824 | { | |
13825 | case EM_RISCV: | |
13826 | return reloc_type == 54; /* R_RISCV_SET8. */ | |
13827 | case EM_Z80: | |
13828 | return reloc_type == 1; /* R_Z80_8. */ | |
13829 | default: | |
13830 | return FALSE; | |
13831 | } | |
13832 | } | |
13833 | ||
13834 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
13835 | a 6-bit absolute RELA relocation used in DWARF debug sections. */ | |
13836 | ||
13837 | static bfd_boolean | |
13838 | is_6bit_abs_reloc (Filedata * filedata, unsigned int reloc_type) | |
13839 | { | |
13840 | switch (filedata->file_header.e_machine) | |
13841 | { | |
13842 | case EM_RISCV: | |
13843 | return reloc_type == 53; /* R_RISCV_SET6. */ | |
13844 | default: | |
13845 | return FALSE; | |
13846 | } | |
13847 | } | |
13848 | ||
13849 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
13850 | a 32-bit inplace add RELA relocation used in DWARF debug sections. */ | |
13851 | ||
13852 | static bfd_boolean | |
13853 | is_32bit_inplace_add_reloc (Filedata * filedata, unsigned int reloc_type) | |
13854 | { | |
13855 | /* Please keep this table alpha-sorted for ease of visual lookup. */ | |
13856 | switch (filedata->file_header.e_machine) | |
13857 | { | |
13858 | case EM_RISCV: | |
13859 | return reloc_type == 35; /* R_RISCV_ADD32. */ | |
13860 | default: | |
13861 | return FALSE; | |
13862 | } | |
13863 | } | |
13864 | ||
13865 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
13866 | a 32-bit inplace sub RELA relocation used in DWARF debug sections. */ | |
13867 | ||
13868 | static bfd_boolean | |
13869 | is_32bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type) | |
13870 | { | |
13871 | /* Please keep this table alpha-sorted for ease of visual lookup. */ | |
13872 | switch (filedata->file_header.e_machine) | |
13873 | { | |
13874 | case EM_RISCV: | |
13875 | return reloc_type == 39; /* R_RISCV_SUB32. */ | |
13876 | default: | |
13877 | return FALSE; | |
13878 | } | |
13879 | } | |
13880 | ||
13881 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
13882 | a 64-bit inplace add RELA relocation used in DWARF debug sections. */ | |
13883 | ||
13884 | static bfd_boolean | |
13885 | is_64bit_inplace_add_reloc (Filedata * filedata, unsigned int reloc_type) | |
13886 | { | |
13887 | /* Please keep this table alpha-sorted for ease of visual lookup. */ | |
13888 | switch (filedata->file_header.e_machine) | |
13889 | { | |
13890 | case EM_RISCV: | |
13891 | return reloc_type == 36; /* R_RISCV_ADD64. */ | |
13892 | default: | |
13893 | return FALSE; | |
13894 | } | |
13895 | } | |
13896 | ||
13897 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
13898 | a 64-bit inplace sub RELA relocation used in DWARF debug sections. */ | |
13899 | ||
13900 | static bfd_boolean | |
13901 | is_64bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type) | |
13902 | { | |
13903 | /* Please keep this table alpha-sorted for ease of visual lookup. */ | |
13904 | switch (filedata->file_header.e_machine) | |
13905 | { | |
13906 | case EM_RISCV: | |
13907 | return reloc_type == 40; /* R_RISCV_SUB64. */ | |
13908 | default: | |
13909 | return FALSE; | |
13910 | } | |
13911 | } | |
13912 | ||
13913 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
13914 | a 16-bit inplace add RELA relocation used in DWARF debug sections. */ | |
13915 | ||
13916 | static bfd_boolean | |
13917 | is_16bit_inplace_add_reloc (Filedata * filedata, unsigned int reloc_type) | |
13918 | { | |
13919 | /* Please keep this table alpha-sorted for ease of visual lookup. */ | |
13920 | switch (filedata->file_header.e_machine) | |
13921 | { | |
13922 | case EM_RISCV: | |
13923 | return reloc_type == 34; /* R_RISCV_ADD16. */ | |
13924 | default: | |
13925 | return FALSE; | |
13926 | } | |
13927 | } | |
13928 | ||
13929 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
13930 | a 16-bit inplace sub RELA relocation used in DWARF debug sections. */ | |
13931 | ||
13932 | static bfd_boolean | |
13933 | is_16bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type) | |
13934 | { | |
13935 | /* Please keep this table alpha-sorted for ease of visual lookup. */ | |
13936 | switch (filedata->file_header.e_machine) | |
13937 | { | |
13938 | case EM_RISCV: | |
13939 | return reloc_type == 38; /* R_RISCV_SUB16. */ | |
13940 | default: | |
13941 | return FALSE; | |
13942 | } | |
13943 | } | |
13944 | ||
13945 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
13946 | a 8-bit inplace add RELA relocation used in DWARF debug sections. */ | |
13947 | ||
13948 | static bfd_boolean | |
13949 | is_8bit_inplace_add_reloc (Filedata * filedata, unsigned int reloc_type) | |
13950 | { | |
13951 | /* Please keep this table alpha-sorted for ease of visual lookup. */ | |
13952 | switch (filedata->file_header.e_machine) | |
13953 | { | |
13954 | case EM_RISCV: | |
13955 | return reloc_type == 33; /* R_RISCV_ADD8. */ | |
13956 | default: | |
13957 | return FALSE; | |
13958 | } | |
13959 | } | |
13960 | ||
13961 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
13962 | a 8-bit inplace sub RELA relocation used in DWARF debug sections. */ | |
13963 | ||
13964 | static bfd_boolean | |
13965 | is_8bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type) | |
13966 | { | |
13967 | /* Please keep this table alpha-sorted for ease of visual lookup. */ | |
13968 | switch (filedata->file_header.e_machine) | |
13969 | { | |
13970 | case EM_RISCV: | |
13971 | return reloc_type == 37; /* R_RISCV_SUB8. */ | |
13972 | default: | |
13973 | return FALSE; | |
13974 | } | |
13975 | } | |
13976 | ||
13977 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
13978 | a 6-bit inplace sub RELA relocation used in DWARF debug sections. */ | |
13979 | ||
13980 | static bfd_boolean | |
13981 | is_6bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type) | |
13982 | { | |
13983 | switch (filedata->file_header.e_machine) | |
13984 | { | |
13985 | case EM_RISCV: | |
13986 | return reloc_type == 52; /* R_RISCV_SUB6. */ | |
13987 | default: | |
13988 | return FALSE; | |
13989 | } | |
13990 | } | |
13991 | ||
13992 | /* Returns TRUE iff RELOC_TYPE is a NONE relocation used for discarded | |
13993 | relocation entries (possibly formerly used for SHT_GROUP sections). */ | |
13994 | ||
13995 | static bfd_boolean | |
13996 | is_none_reloc (Filedata * filedata, unsigned int reloc_type) | |
13997 | { | |
13998 | switch (filedata->file_header.e_machine) | |
13999 | { | |
14000 | case EM_386: /* R_386_NONE. */ | |
14001 | case EM_68K: /* R_68K_NONE. */ | |
14002 | case EM_ADAPTEVA_EPIPHANY: | |
14003 | case EM_ALPHA: /* R_ALPHA_NONE. */ | |
14004 | case EM_ALTERA_NIOS2: /* R_NIOS2_NONE. */ | |
14005 | case EM_ARC: /* R_ARC_NONE. */ | |
14006 | case EM_ARC_COMPACT2: /* R_ARC_NONE. */ | |
14007 | case EM_ARC_COMPACT: /* R_ARC_NONE. */ | |
14008 | case EM_ARM: /* R_ARM_NONE. */ | |
14009 | case EM_C166: /* R_XC16X_NONE. */ | |
14010 | case EM_CRIS: /* R_CRIS_NONE. */ | |
14011 | case EM_FT32: /* R_FT32_NONE. */ | |
14012 | case EM_IA_64: /* R_IA64_NONE. */ | |
14013 | case EM_K1OM: /* R_X86_64_NONE. */ | |
14014 | case EM_L1OM: /* R_X86_64_NONE. */ | |
14015 | case EM_M32R: /* R_M32R_NONE. */ | |
14016 | case EM_MIPS: /* R_MIPS_NONE. */ | |
14017 | case EM_MN10300: /* R_MN10300_NONE. */ | |
14018 | case EM_MOXIE: /* R_MOXIE_NONE. */ | |
14019 | case EM_NIOS32: /* R_NIOS_NONE. */ | |
14020 | case EM_OR1K: /* R_OR1K_NONE. */ | |
14021 | case EM_PARISC: /* R_PARISC_NONE. */ | |
14022 | case EM_PPC64: /* R_PPC64_NONE. */ | |
14023 | case EM_PPC: /* R_PPC_NONE. */ | |
14024 | case EM_RISCV: /* R_RISCV_NONE. */ | |
14025 | case EM_S390: /* R_390_NONE. */ | |
14026 | case EM_S390_OLD: | |
14027 | case EM_SH: /* R_SH_NONE. */ | |
14028 | case EM_SPARC32PLUS: | |
14029 | case EM_SPARC: /* R_SPARC_NONE. */ | |
14030 | case EM_SPARCV9: | |
14031 | case EM_TILEGX: /* R_TILEGX_NONE. */ | |
14032 | case EM_TILEPRO: /* R_TILEPRO_NONE. */ | |
14033 | case EM_TI_C6000:/* R_C6000_NONE. */ | |
14034 | case EM_X86_64: /* R_X86_64_NONE. */ | |
14035 | case EM_XC16X: | |
14036 | case EM_Z80: /* R_Z80_NONE. */ | |
14037 | case EM_WEBASSEMBLY: /* R_WASM32_NONE. */ | |
14038 | return reloc_type == 0; | |
14039 | ||
14040 | case EM_AARCH64: | |
14041 | return reloc_type == 0 || reloc_type == 256; | |
14042 | case EM_AVR_OLD: | |
14043 | case EM_AVR: | |
14044 | return (reloc_type == 0 /* R_AVR_NONE. */ | |
14045 | || reloc_type == 30 /* R_AVR_DIFF8. */ | |
14046 | || reloc_type == 31 /* R_AVR_DIFF16. */ | |
14047 | || reloc_type == 32 /* R_AVR_DIFF32. */); | |
14048 | case EM_METAG: | |
14049 | return reloc_type == 3; /* R_METAG_NONE. */ | |
14050 | case EM_NDS32: | |
14051 | return (reloc_type == 0 /* R_XTENSA_NONE. */ | |
14052 | || reloc_type == 204 /* R_NDS32_DIFF8. */ | |
14053 | || reloc_type == 205 /* R_NDS32_DIFF16. */ | |
14054 | || reloc_type == 206 /* R_NDS32_DIFF32. */ | |
14055 | || reloc_type == 207 /* R_NDS32_ULEB128. */); | |
14056 | case EM_TI_PRU: | |
14057 | return (reloc_type == 0 /* R_PRU_NONE. */ | |
14058 | || reloc_type == 65 /* R_PRU_DIFF8. */ | |
14059 | || reloc_type == 66 /* R_PRU_DIFF16. */ | |
14060 | || reloc_type == 67 /* R_PRU_DIFF32. */); | |
14061 | case EM_XTENSA_OLD: | |
14062 | case EM_XTENSA: | |
14063 | return (reloc_type == 0 /* R_XTENSA_NONE. */ | |
14064 | || reloc_type == 17 /* R_XTENSA_DIFF8. */ | |
14065 | || reloc_type == 18 /* R_XTENSA_DIFF16. */ | |
14066 | || reloc_type == 19 /* R_XTENSA_DIFF32. */ | |
14067 | || reloc_type == 57 /* R_XTENSA_PDIFF8. */ | |
14068 | || reloc_type == 58 /* R_XTENSA_PDIFF16. */ | |
14069 | || reloc_type == 59 /* R_XTENSA_PDIFF32. */ | |
14070 | || reloc_type == 60 /* R_XTENSA_NDIFF8. */ | |
14071 | || reloc_type == 61 /* R_XTENSA_NDIFF16. */ | |
14072 | || reloc_type == 62 /* R_XTENSA_NDIFF32. */); | |
14073 | } | |
14074 | return FALSE; | |
14075 | } | |
14076 | ||
14077 | /* Returns TRUE if there is a relocation against | |
14078 | section NAME at OFFSET bytes. */ | |
14079 | ||
14080 | bfd_boolean | |
14081 | reloc_at (struct dwarf_section * dsec, dwarf_vma offset) | |
14082 | { | |
14083 | Elf_Internal_Rela * relocs; | |
14084 | Elf_Internal_Rela * rp; | |
14085 | ||
14086 | if (dsec == NULL || dsec->reloc_info == NULL) | |
14087 | return FALSE; | |
14088 | ||
14089 | relocs = (Elf_Internal_Rela *) dsec->reloc_info; | |
14090 | ||
14091 | for (rp = relocs; rp < relocs + dsec->num_relocs; ++rp) | |
14092 | if (rp->r_offset == offset) | |
14093 | return TRUE; | |
14094 | ||
14095 | return FALSE; | |
14096 | } | |
14097 | ||
14098 | /* Apply relocations to a section. | |
14099 | Returns TRUE upon success, FALSE otherwise. | |
14100 | If RELOCS_RETURN is non-NULL then it is set to point to the loaded relocs. | |
14101 | It is then the caller's responsibility to free them. NUM_RELOCS_RETURN | |
14102 | will be set to the number of relocs loaded. | |
14103 | ||
14104 | Note: So far support has been added only for those relocations | |
14105 | which can be found in debug sections. FIXME: Add support for | |
14106 | more relocations ? */ | |
14107 | ||
14108 | static bfd_boolean | |
14109 | apply_relocations (Filedata * filedata, | |
14110 | const Elf_Internal_Shdr * section, | |
14111 | unsigned char * start, | |
14112 | bfd_size_type size, | |
14113 | void ** relocs_return, | |
14114 | unsigned long * num_relocs_return) | |
14115 | { | |
14116 | Elf_Internal_Shdr * relsec; | |
14117 | unsigned char * end = start + size; | |
14118 | ||
14119 | if (relocs_return != NULL) | |
14120 | { | |
14121 | * (Elf_Internal_Rela **) relocs_return = NULL; | |
14122 | * num_relocs_return = 0; | |
14123 | } | |
14124 | ||
14125 | if (filedata->file_header.e_type != ET_REL) | |
14126 | /* No relocs to apply. */ | |
14127 | return TRUE; | |
14128 | ||
14129 | /* Find the reloc section associated with the section. */ | |
14130 | for (relsec = filedata->section_headers; | |
14131 | relsec < filedata->section_headers + filedata->file_header.e_shnum; | |
14132 | ++relsec) | |
14133 | { | |
14134 | bfd_boolean is_rela; | |
14135 | unsigned long num_relocs; | |
14136 | Elf_Internal_Rela * relocs; | |
14137 | Elf_Internal_Rela * rp; | |
14138 | Elf_Internal_Shdr * symsec; | |
14139 | Elf_Internal_Sym * symtab; | |
14140 | unsigned long num_syms; | |
14141 | Elf_Internal_Sym * sym; | |
14142 | ||
14143 | if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL) | |
14144 | || relsec->sh_info >= filedata->file_header.e_shnum | |
14145 | || filedata->section_headers + relsec->sh_info != section | |
14146 | || relsec->sh_size == 0 | |
14147 | || relsec->sh_link >= filedata->file_header.e_shnum) | |
14148 | continue; | |
14149 | ||
14150 | symsec = filedata->section_headers + relsec->sh_link; | |
14151 | if (symsec->sh_type != SHT_SYMTAB | |
14152 | && symsec->sh_type != SHT_DYNSYM) | |
14153 | return FALSE; | |
14154 | ||
14155 | is_rela = relsec->sh_type == SHT_RELA; | |
14156 | ||
14157 | if (is_rela) | |
14158 | { | |
14159 | if (!slurp_rela_relocs (filedata, relsec->sh_offset, | |
14160 | relsec->sh_size, & relocs, & num_relocs)) | |
14161 | return FALSE; | |
14162 | } | |
14163 | else | |
14164 | { | |
14165 | if (!slurp_rel_relocs (filedata, relsec->sh_offset, | |
14166 | relsec->sh_size, & relocs, & num_relocs)) | |
14167 | return FALSE; | |
14168 | } | |
14169 | ||
14170 | /* SH uses RELA but uses in place value instead of the addend field. */ | |
14171 | if (filedata->file_header.e_machine == EM_SH) | |
14172 | is_rela = FALSE; | |
14173 | ||
14174 | symtab = GET_ELF_SYMBOLS (filedata, symsec, & num_syms); | |
14175 | ||
14176 | for (rp = relocs; rp < relocs + num_relocs; ++rp) | |
14177 | { | |
14178 | bfd_vma addend; | |
14179 | unsigned int reloc_type; | |
14180 | unsigned int reloc_size; | |
14181 | bfd_boolean reloc_inplace = FALSE; | |
14182 | bfd_boolean reloc_subtract = FALSE; | |
14183 | unsigned char * rloc; | |
14184 | unsigned long sym_index; | |
14185 | ||
14186 | reloc_type = get_reloc_type (filedata, rp->r_info); | |
14187 | ||
14188 | if (target_specific_reloc_handling (filedata, rp, start, end, symtab, num_syms)) | |
14189 | continue; | |
14190 | else if (is_none_reloc (filedata, reloc_type)) | |
14191 | continue; | |
14192 | else if (is_32bit_abs_reloc (filedata, reloc_type) | |
14193 | || is_32bit_pcrel_reloc (filedata, reloc_type)) | |
14194 | reloc_size = 4; | |
14195 | else if (is_64bit_abs_reloc (filedata, reloc_type) | |
14196 | || is_64bit_pcrel_reloc (filedata, reloc_type)) | |
14197 | reloc_size = 8; | |
14198 | else if (is_24bit_abs_reloc (filedata, reloc_type)) | |
14199 | reloc_size = 3; | |
14200 | else if (is_16bit_abs_reloc (filedata, reloc_type)) | |
14201 | reloc_size = 2; | |
14202 | else if (is_8bit_abs_reloc (filedata, reloc_type) | |
14203 | || is_6bit_abs_reloc (filedata, reloc_type)) | |
14204 | reloc_size = 1; | |
14205 | else if ((reloc_subtract = is_32bit_inplace_sub_reloc (filedata, | |
14206 | reloc_type)) | |
14207 | || is_32bit_inplace_add_reloc (filedata, reloc_type)) | |
14208 | { | |
14209 | reloc_size = 4; | |
14210 | reloc_inplace = TRUE; | |
14211 | } | |
14212 | else if ((reloc_subtract = is_64bit_inplace_sub_reloc (filedata, | |
14213 | reloc_type)) | |
14214 | || is_64bit_inplace_add_reloc (filedata, reloc_type)) | |
14215 | { | |
14216 | reloc_size = 8; | |
14217 | reloc_inplace = TRUE; | |
14218 | } | |
14219 | else if ((reloc_subtract = is_16bit_inplace_sub_reloc (filedata, | |
14220 | reloc_type)) | |
14221 | || is_16bit_inplace_add_reloc (filedata, reloc_type)) | |
14222 | { | |
14223 | reloc_size = 2; | |
14224 | reloc_inplace = TRUE; | |
14225 | } | |
14226 | else if ((reloc_subtract = is_8bit_inplace_sub_reloc (filedata, | |
14227 | reloc_type)) | |
14228 | || is_8bit_inplace_add_reloc (filedata, reloc_type)) | |
14229 | { | |
14230 | reloc_size = 1; | |
14231 | reloc_inplace = TRUE; | |
14232 | } | |
14233 | else if ((reloc_subtract = is_6bit_inplace_sub_reloc (filedata, | |
14234 | reloc_type))) | |
14235 | { | |
14236 | reloc_size = 1; | |
14237 | reloc_inplace = TRUE; | |
14238 | } | |
14239 | else | |
14240 | { | |
14241 | static unsigned int prev_reloc = 0; | |
14242 | ||
14243 | if (reloc_type != prev_reloc) | |
14244 | warn (_("unable to apply unsupported reloc type %d to section %s\n"), | |
14245 | reloc_type, printable_section_name (filedata, section)); | |
14246 | prev_reloc = reloc_type; | |
14247 | continue; | |
14248 | } | |
14249 | ||
14250 | rloc = start + rp->r_offset; | |
14251 | if (!IN_RANGE (start, end, rloc, reloc_size)) | |
14252 | { | |
14253 | warn (_("skipping invalid relocation offset 0x%lx in section %s\n"), | |
14254 | (unsigned long) rp->r_offset, | |
14255 | printable_section_name (filedata, section)); | |
14256 | continue; | |
14257 | } | |
14258 | ||
14259 | sym_index = (unsigned long) get_reloc_symindex (rp->r_info); | |
14260 | if (sym_index >= num_syms) | |
14261 | { | |
14262 | warn (_("skipping invalid relocation symbol index 0x%lx in section %s\n"), | |
14263 | sym_index, printable_section_name (filedata, section)); | |
14264 | continue; | |
14265 | } | |
14266 | sym = symtab + sym_index; | |
14267 | ||
14268 | /* If the reloc has a symbol associated with it, | |
14269 | make sure that it is of an appropriate type. | |
14270 | ||
14271 | Relocations against symbols without type can happen. | |
14272 | Gcc -feliminate-dwarf2-dups may generate symbols | |
14273 | without type for debug info. | |
14274 | ||
14275 | Icc generates relocations against function symbols | |
14276 | instead of local labels. | |
14277 | ||
14278 | Relocations against object symbols can happen, eg when | |
14279 | referencing a global array. For an example of this see | |
14280 | the _clz.o binary in libgcc.a. */ | |
14281 | if (sym != symtab | |
14282 | && ELF_ST_TYPE (sym->st_info) != STT_COMMON | |
14283 | && ELF_ST_TYPE (sym->st_info) > STT_SECTION) | |
14284 | { | |
14285 | warn (_("skipping unexpected symbol type %s in section %s relocation %ld\n"), | |
14286 | get_symbol_type (filedata, ELF_ST_TYPE (sym->st_info)), | |
14287 | printable_section_name (filedata, relsec), | |
14288 | (long int)(rp - relocs)); | |
14289 | continue; | |
14290 | } | |
14291 | ||
14292 | addend = 0; | |
14293 | if (is_rela) | |
14294 | addend += rp->r_addend; | |
14295 | /* R_XTENSA_32, R_PJ_DATA_DIR32 and R_D30V_32_NORMAL are | |
14296 | partial_inplace. */ | |
14297 | if (!is_rela | |
14298 | || (filedata->file_header.e_machine == EM_XTENSA | |
14299 | && reloc_type == 1) | |
14300 | || ((filedata->file_header.e_machine == EM_PJ | |
14301 | || filedata->file_header.e_machine == EM_PJ_OLD) | |
14302 | && reloc_type == 1) | |
14303 | || ((filedata->file_header.e_machine == EM_D30V | |
14304 | || filedata->file_header.e_machine == EM_CYGNUS_D30V) | |
14305 | && reloc_type == 12) | |
14306 | || reloc_inplace) | |
14307 | { | |
14308 | if (is_6bit_inplace_sub_reloc (filedata, reloc_type)) | |
14309 | addend += byte_get (rloc, reloc_size) & 0x3f; | |
14310 | else | |
14311 | addend += byte_get (rloc, reloc_size); | |
14312 | } | |
14313 | ||
14314 | if (is_32bit_pcrel_reloc (filedata, reloc_type) | |
14315 | || is_64bit_pcrel_reloc (filedata, reloc_type)) | |
14316 | { | |
14317 | /* On HPPA, all pc-relative relocations are biased by 8. */ | |
14318 | if (filedata->file_header.e_machine == EM_PARISC) | |
14319 | addend -= 8; | |
14320 | byte_put (rloc, (addend + sym->st_value) - rp->r_offset, | |
14321 | reloc_size); | |
14322 | } | |
14323 | else if (is_6bit_abs_reloc (filedata, reloc_type) | |
14324 | || is_6bit_inplace_sub_reloc (filedata, reloc_type)) | |
14325 | { | |
14326 | if (reloc_subtract) | |
14327 | addend -= sym->st_value; | |
14328 | else | |
14329 | addend += sym->st_value; | |
14330 | addend = (addend & 0x3f) | (byte_get (rloc, reloc_size) & 0xc0); | |
14331 | byte_put (rloc, addend, reloc_size); | |
14332 | } | |
14333 | else if (reloc_subtract) | |
14334 | byte_put (rloc, addend - sym->st_value, reloc_size); | |
14335 | else | |
14336 | byte_put (rloc, addend + sym->st_value, reloc_size); | |
14337 | } | |
14338 | ||
14339 | free (symtab); | |
14340 | /* Let the target specific reloc processing code know that | |
14341 | we have finished with these relocs. */ | |
14342 | target_specific_reloc_handling (filedata, NULL, NULL, NULL, NULL, 0); | |
14343 | ||
14344 | if (relocs_return) | |
14345 | { | |
14346 | * (Elf_Internal_Rela **) relocs_return = relocs; | |
14347 | * num_relocs_return = num_relocs; | |
14348 | } | |
14349 | else | |
14350 | free (relocs); | |
14351 | ||
14352 | break; | |
14353 | } | |
14354 | ||
14355 | return TRUE; | |
14356 | } | |
14357 | ||
14358 | #ifdef SUPPORT_DISASSEMBLY | |
14359 | static bfd_boolean | |
14360 | disassemble_section (Elf_Internal_Shdr * section, Filedata * filedata) | |
14361 | { | |
14362 | printf (_("\nAssembly dump of section %s\n"), printable_section_name (filedata, section)); | |
14363 | ||
14364 | /* FIXME: XXX -- to be done --- XXX */ | |
14365 | ||
14366 | return TRUE; | |
14367 | } | |
14368 | #endif | |
14369 | ||
14370 | /* Reads in the contents of SECTION from FILE, returning a pointer | |
14371 | to a malloc'ed buffer or NULL if something went wrong. */ | |
14372 | ||
14373 | static char * | |
14374 | get_section_contents (Elf_Internal_Shdr * section, Filedata * filedata) | |
14375 | { | |
14376 | bfd_size_type num_bytes = section->sh_size; | |
14377 | ||
14378 | if (num_bytes == 0 || section->sh_type == SHT_NOBITS) | |
14379 | { | |
14380 | printf (_("Section '%s' has no data to dump.\n"), | |
14381 | printable_section_name (filedata, section)); | |
14382 | return NULL; | |
14383 | } | |
14384 | ||
14385 | return (char *) get_data (NULL, filedata, section->sh_offset, 1, num_bytes, | |
14386 | _("section contents")); | |
14387 | } | |
14388 | ||
14389 | /* Uncompresses a section that was compressed using zlib, in place. */ | |
14390 | ||
14391 | static bfd_boolean | |
14392 | uncompress_section_contents (unsigned char ** buffer, | |
14393 | dwarf_size_type uncompressed_size, | |
14394 | dwarf_size_type * size) | |
14395 | { | |
14396 | dwarf_size_type compressed_size = *size; | |
14397 | unsigned char * compressed_buffer = *buffer; | |
14398 | unsigned char * uncompressed_buffer; | |
14399 | z_stream strm; | |
14400 | int rc; | |
14401 | ||
14402 | /* It is possible the section consists of several compressed | |
14403 | buffers concatenated together, so we uncompress in a loop. */ | |
14404 | /* PR 18313: The state field in the z_stream structure is supposed | |
14405 | to be invisible to the user (ie us), but some compilers will | |
14406 | still complain about it being used without initialisation. So | |
14407 | we first zero the entire z_stream structure and then set the fields | |
14408 | that we need. */ | |
14409 | memset (& strm, 0, sizeof strm); | |
14410 | strm.avail_in = compressed_size; | |
14411 | strm.next_in = (Bytef *) compressed_buffer; | |
14412 | strm.avail_out = uncompressed_size; | |
14413 | uncompressed_buffer = (unsigned char *) xmalloc (uncompressed_size); | |
14414 | ||
14415 | rc = inflateInit (& strm); | |
14416 | while (strm.avail_in > 0) | |
14417 | { | |
14418 | if (rc != Z_OK) | |
14419 | break; | |
14420 | strm.next_out = ((Bytef *) uncompressed_buffer | |
14421 | + (uncompressed_size - strm.avail_out)); | |
14422 | rc = inflate (&strm, Z_FINISH); | |
14423 | if (rc != Z_STREAM_END) | |
14424 | break; | |
14425 | rc = inflateReset (& strm); | |
14426 | } | |
14427 | if (inflateEnd (& strm) != Z_OK | |
14428 | || rc != Z_OK | |
14429 | || strm.avail_out != 0) | |
14430 | goto fail; | |
14431 | ||
14432 | *buffer = uncompressed_buffer; | |
14433 | *size = uncompressed_size; | |
14434 | return TRUE; | |
14435 | ||
14436 | fail: | |
14437 | free (uncompressed_buffer); | |
14438 | /* Indicate decompression failure. */ | |
14439 | *buffer = NULL; | |
14440 | return FALSE; | |
14441 | } | |
14442 | ||
14443 | static bfd_boolean | |
14444 | dump_section_as_strings (Elf_Internal_Shdr * section, Filedata * filedata) | |
14445 | { | |
14446 | Elf_Internal_Shdr * relsec; | |
14447 | bfd_size_type num_bytes; | |
14448 | unsigned char * data; | |
14449 | unsigned char * end; | |
14450 | unsigned char * real_start; | |
14451 | unsigned char * start; | |
14452 | bfd_boolean some_strings_shown; | |
14453 | ||
14454 | real_start = start = (unsigned char *) get_section_contents (section, filedata); | |
14455 | if (start == NULL) | |
14456 | /* PR 21820: Do not fail if the section was empty. */ | |
14457 | return section->sh_size == 0 || section->sh_type == SHT_NOBITS; | |
14458 | ||
14459 | num_bytes = section->sh_size; | |
14460 | ||
14461 | if (filedata->is_separate) | |
14462 | printf (_("\nString dump of section '%s' in linked file %s:\n"), | |
14463 | printable_section_name (filedata, section), | |
14464 | filedata->file_name); | |
14465 | else | |
14466 | printf (_("\nString dump of section '%s':\n"), | |
14467 | printable_section_name (filedata, section)); | |
14468 | ||
14469 | if (decompress_dumps) | |
14470 | { | |
14471 | dwarf_size_type new_size = num_bytes; | |
14472 | dwarf_size_type uncompressed_size = 0; | |
14473 | ||
14474 | if ((section->sh_flags & SHF_COMPRESSED) != 0) | |
14475 | { | |
14476 | Elf_Internal_Chdr chdr; | |
14477 | unsigned int compression_header_size | |
14478 | = get_compression_header (& chdr, (unsigned char *) start, | |
14479 | num_bytes); | |
14480 | if (compression_header_size == 0) | |
14481 | /* An error message will have already been generated | |
14482 | by get_compression_header. */ | |
14483 | goto error_out; | |
14484 | ||
14485 | if (chdr.ch_type != ELFCOMPRESS_ZLIB) | |
14486 | { | |
14487 | warn (_("section '%s' has unsupported compress type: %d\n"), | |
14488 | printable_section_name (filedata, section), chdr.ch_type); | |
14489 | goto error_out; | |
14490 | } | |
14491 | uncompressed_size = chdr.ch_size; | |
14492 | start += compression_header_size; | |
14493 | new_size -= compression_header_size; | |
14494 | } | |
14495 | else if (new_size > 12 && streq ((char *) start, "ZLIB")) | |
14496 | { | |
14497 | /* Read the zlib header. In this case, it should be "ZLIB" | |
14498 | followed by the uncompressed section size, 8 bytes in | |
14499 | big-endian order. */ | |
14500 | uncompressed_size = start[4]; uncompressed_size <<= 8; | |
14501 | uncompressed_size += start[5]; uncompressed_size <<= 8; | |
14502 | uncompressed_size += start[6]; uncompressed_size <<= 8; | |
14503 | uncompressed_size += start[7]; uncompressed_size <<= 8; | |
14504 | uncompressed_size += start[8]; uncompressed_size <<= 8; | |
14505 | uncompressed_size += start[9]; uncompressed_size <<= 8; | |
14506 | uncompressed_size += start[10]; uncompressed_size <<= 8; | |
14507 | uncompressed_size += start[11]; | |
14508 | start += 12; | |
14509 | new_size -= 12; | |
14510 | } | |
14511 | ||
14512 | if (uncompressed_size) | |
14513 | { | |
14514 | if (uncompress_section_contents (& start, | |
14515 | uncompressed_size, & new_size)) | |
14516 | num_bytes = new_size; | |
14517 | else | |
14518 | { | |
14519 | error (_("Unable to decompress section %s\n"), | |
14520 | printable_section_name (filedata, section)); | |
14521 | goto error_out; | |
14522 | } | |
14523 | } | |
14524 | else | |
14525 | start = real_start; | |
14526 | } | |
14527 | ||
14528 | /* If the section being dumped has relocations against it the user might | |
14529 | be expecting these relocations to have been applied. Check for this | |
14530 | case and issue a warning message in order to avoid confusion. | |
14531 | FIXME: Maybe we ought to have an option that dumps a section with | |
14532 | relocs applied ? */ | |
14533 | for (relsec = filedata->section_headers; | |
14534 | relsec < filedata->section_headers + filedata->file_header.e_shnum; | |
14535 | ++relsec) | |
14536 | { | |
14537 | if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL) | |
14538 | || relsec->sh_info >= filedata->file_header.e_shnum | |
14539 | || filedata->section_headers + relsec->sh_info != section | |
14540 | || relsec->sh_size == 0 | |
14541 | || relsec->sh_link >= filedata->file_header.e_shnum) | |
14542 | continue; | |
14543 | ||
14544 | printf (_(" Note: This section has relocations against it, but these have NOT been applied to this dump.\n")); | |
14545 | break; | |
14546 | } | |
14547 | ||
14548 | data = start; | |
14549 | end = start + num_bytes; | |
14550 | some_strings_shown = FALSE; | |
14551 | ||
14552 | #ifdef HAVE_MBSTATE_T | |
14553 | mbstate_t state; | |
14554 | /* Initialise the multibyte conversion state. */ | |
14555 | memset (& state, 0, sizeof (state)); | |
14556 | #endif | |
14557 | ||
14558 | bfd_boolean continuing = FALSE; | |
14559 | ||
14560 | while (data < end) | |
14561 | { | |
14562 | while (!ISPRINT (* data)) | |
14563 | if (++ data >= end) | |
14564 | break; | |
14565 | ||
14566 | if (data < end) | |
14567 | { | |
14568 | size_t maxlen = end - data; | |
14569 | ||
14570 | if (continuing) | |
14571 | { | |
14572 | printf (" "); | |
14573 | continuing = FALSE; | |
14574 | } | |
14575 | else | |
14576 | { | |
14577 | printf (" [%6lx] ", (unsigned long) (data - start)); | |
14578 | } | |
14579 | ||
14580 | if (maxlen > 0) | |
14581 | { | |
14582 | char c = 0; | |
14583 | ||
14584 | while (maxlen) | |
14585 | { | |
14586 | c = *data++; | |
14587 | ||
14588 | if (c == 0) | |
14589 | break; | |
14590 | ||
14591 | /* PR 25543: Treat new-lines as string-ending characters. */ | |
14592 | if (c == '\n') | |
14593 | { | |
14594 | printf ("\\n\n"); | |
14595 | if (*data != 0) | |
14596 | continuing = TRUE; | |
14597 | break; | |
14598 | } | |
14599 | ||
14600 | /* Do not print control characters directly as they can affect terminal | |
14601 | settings. Such characters usually appear in the names generated | |
14602 | by the assembler for local labels. */ | |
14603 | if (ISCNTRL (c)) | |
14604 | { | |
14605 | printf ("^%c", c + 0x40); | |
14606 | } | |
14607 | else if (ISPRINT (c)) | |
14608 | { | |
14609 | putchar (c); | |
14610 | } | |
14611 | else | |
14612 | { | |
14613 | size_t n; | |
14614 | #ifdef HAVE_MBSTATE_T | |
14615 | wchar_t w; | |
14616 | #endif | |
14617 | /* Let printf do the hard work of displaying multibyte characters. */ | |
14618 | printf ("%.1s", data - 1); | |
14619 | #ifdef HAVE_MBSTATE_T | |
14620 | /* Try to find out how many bytes made up the character that was | |
14621 | just printed. Advance the symbol pointer past the bytes that | |
14622 | were displayed. */ | |
14623 | n = mbrtowc (& w, (char *)(data - 1), MB_CUR_MAX, & state); | |
14624 | #else | |
14625 | n = 1; | |
14626 | #endif | |
14627 | if (n != (size_t) -1 && n != (size_t) -2 && n > 0) | |
14628 | data += (n - 1); | |
14629 | } | |
14630 | } | |
14631 | ||
14632 | if (c != '\n') | |
14633 | putchar ('\n'); | |
14634 | } | |
14635 | else | |
14636 | { | |
14637 | printf (_("<corrupt>\n")); | |
14638 | data = end; | |
14639 | } | |
14640 | some_strings_shown = TRUE; | |
14641 | } | |
14642 | } | |
14643 | ||
14644 | if (! some_strings_shown) | |
14645 | printf (_(" No strings found in this section.")); | |
14646 | ||
14647 | free (real_start); | |
14648 | ||
14649 | putchar ('\n'); | |
14650 | return TRUE; | |
14651 | ||
14652 | error_out: | |
14653 | free (real_start); | |
14654 | return FALSE; | |
14655 | } | |
14656 | ||
14657 | static bfd_boolean | |
14658 | dump_section_as_bytes (Elf_Internal_Shdr * section, | |
14659 | Filedata * filedata, | |
14660 | bfd_boolean relocate) | |
14661 | { | |
14662 | Elf_Internal_Shdr * relsec; | |
14663 | bfd_size_type bytes; | |
14664 | bfd_size_type section_size; | |
14665 | bfd_vma addr; | |
14666 | unsigned char * data; | |
14667 | unsigned char * real_start; | |
14668 | unsigned char * start; | |
14669 | ||
14670 | real_start = start = (unsigned char *) get_section_contents (section, filedata); | |
14671 | if (start == NULL) | |
14672 | /* PR 21820: Do not fail if the section was empty. */ | |
14673 | return section->sh_size == 0 || section->sh_type == SHT_NOBITS; | |
14674 | ||
14675 | section_size = section->sh_size; | |
14676 | ||
14677 | if (filedata->is_separate) | |
14678 | printf (_("\nHex dump of section '%s' in linked file %s:\n"), | |
14679 | printable_section_name (filedata, section), | |
14680 | filedata->file_name); | |
14681 | else | |
14682 | printf (_("\nHex dump of section '%s':\n"), | |
14683 | printable_section_name (filedata, section)); | |
14684 | ||
14685 | if (decompress_dumps) | |
14686 | { | |
14687 | dwarf_size_type new_size = section_size; | |
14688 | dwarf_size_type uncompressed_size = 0; | |
14689 | ||
14690 | if ((section->sh_flags & SHF_COMPRESSED) != 0) | |
14691 | { | |
14692 | Elf_Internal_Chdr chdr; | |
14693 | unsigned int compression_header_size | |
14694 | = get_compression_header (& chdr, start, section_size); | |
14695 | ||
14696 | if (compression_header_size == 0) | |
14697 | /* An error message will have already been generated | |
14698 | by get_compression_header. */ | |
14699 | goto error_out; | |
14700 | ||
14701 | if (chdr.ch_type != ELFCOMPRESS_ZLIB) | |
14702 | { | |
14703 | warn (_("section '%s' has unsupported compress type: %d\n"), | |
14704 | printable_section_name (filedata, section), chdr.ch_type); | |
14705 | goto error_out; | |
14706 | } | |
14707 | uncompressed_size = chdr.ch_size; | |
14708 | start += compression_header_size; | |
14709 | new_size -= compression_header_size; | |
14710 | } | |
14711 | else if (new_size > 12 && streq ((char *) start, "ZLIB")) | |
14712 | { | |
14713 | /* Read the zlib header. In this case, it should be "ZLIB" | |
14714 | followed by the uncompressed section size, 8 bytes in | |
14715 | big-endian order. */ | |
14716 | uncompressed_size = start[4]; uncompressed_size <<= 8; | |
14717 | uncompressed_size += start[5]; uncompressed_size <<= 8; | |
14718 | uncompressed_size += start[6]; uncompressed_size <<= 8; | |
14719 | uncompressed_size += start[7]; uncompressed_size <<= 8; | |
14720 | uncompressed_size += start[8]; uncompressed_size <<= 8; | |
14721 | uncompressed_size += start[9]; uncompressed_size <<= 8; | |
14722 | uncompressed_size += start[10]; uncompressed_size <<= 8; | |
14723 | uncompressed_size += start[11]; | |
14724 | start += 12; | |
14725 | new_size -= 12; | |
14726 | } | |
14727 | ||
14728 | if (uncompressed_size) | |
14729 | { | |
14730 | if (uncompress_section_contents (& start, uncompressed_size, | |
14731 | & new_size)) | |
14732 | { | |
14733 | section_size = new_size; | |
14734 | } | |
14735 | else | |
14736 | { | |
14737 | error (_("Unable to decompress section %s\n"), | |
14738 | printable_section_name (filedata, section)); | |
14739 | /* FIXME: Print the section anyway ? */ | |
14740 | goto error_out; | |
14741 | } | |
14742 | } | |
14743 | else | |
14744 | start = real_start; | |
14745 | } | |
14746 | ||
14747 | if (relocate) | |
14748 | { | |
14749 | if (! apply_relocations (filedata, section, start, section_size, NULL, NULL)) | |
14750 | goto error_out; | |
14751 | } | |
14752 | else | |
14753 | { | |
14754 | /* If the section being dumped has relocations against it the user might | |
14755 | be expecting these relocations to have been applied. Check for this | |
14756 | case and issue a warning message in order to avoid confusion. | |
14757 | FIXME: Maybe we ought to have an option that dumps a section with | |
14758 | relocs applied ? */ | |
14759 | for (relsec = filedata->section_headers; | |
14760 | relsec < filedata->section_headers + filedata->file_header.e_shnum; | |
14761 | ++relsec) | |
14762 | { | |
14763 | if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL) | |
14764 | || relsec->sh_info >= filedata->file_header.e_shnum | |
14765 | || filedata->section_headers + relsec->sh_info != section | |
14766 | || relsec->sh_size == 0 | |
14767 | || relsec->sh_link >= filedata->file_header.e_shnum) | |
14768 | continue; | |
14769 | ||
14770 | printf (_(" NOTE: This section has relocations against it, but these have NOT been applied to this dump.\n")); | |
14771 | break; | |
14772 | } | |
14773 | } | |
14774 | ||
14775 | addr = section->sh_addr; | |
14776 | bytes = section_size; | |
14777 | data = start; | |
14778 | ||
14779 | while (bytes) | |
14780 | { | |
14781 | int j; | |
14782 | int k; | |
14783 | int lbytes; | |
14784 | ||
14785 | lbytes = (bytes > 16 ? 16 : bytes); | |
14786 | ||
14787 | printf (" 0x%8.8lx ", (unsigned long) addr); | |
14788 | ||
14789 | for (j = 0; j < 16; j++) | |
14790 | { | |
14791 | if (j < lbytes) | |
14792 | printf ("%2.2x", data[j]); | |
14793 | else | |
14794 | printf (" "); | |
14795 | ||
14796 | if ((j & 3) == 3) | |
14797 | printf (" "); | |
14798 | } | |
14799 | ||
14800 | for (j = 0; j < lbytes; j++) | |
14801 | { | |
14802 | k = data[j]; | |
14803 | if (k >= ' ' && k < 0x7f) | |
14804 | printf ("%c", k); | |
14805 | else | |
14806 | printf ("."); | |
14807 | } | |
14808 | ||
14809 | putchar ('\n'); | |
14810 | ||
14811 | data += lbytes; | |
14812 | addr += lbytes; | |
14813 | bytes -= lbytes; | |
14814 | } | |
14815 | ||
14816 | free (real_start); | |
14817 | ||
14818 | putchar ('\n'); | |
14819 | return TRUE; | |
14820 | ||
14821 | error_out: | |
14822 | free (real_start); | |
14823 | return FALSE; | |
14824 | } | |
14825 | ||
14826 | #ifdef ENABLE_LIBCTF | |
14827 | static ctf_sect_t * | |
14828 | shdr_to_ctf_sect (ctf_sect_t *buf, Elf_Internal_Shdr *shdr, Filedata *filedata) | |
14829 | { | |
14830 | buf->cts_name = SECTION_NAME_PRINT (shdr); | |
14831 | buf->cts_size = shdr->sh_size; | |
14832 | buf->cts_entsize = shdr->sh_entsize; | |
14833 | ||
14834 | return buf; | |
14835 | } | |
14836 | ||
14837 | /* Formatting callback function passed to ctf_dump. Returns either the pointer | |
14838 | it is passed, or a pointer to newly-allocated storage, in which case | |
14839 | dump_ctf() will free it when it no longer needs it. */ | |
14840 | ||
14841 | static char * | |
14842 | dump_ctf_indent_lines (ctf_sect_names_t sect ATTRIBUTE_UNUSED, | |
14843 | char *s, void *arg) | |
14844 | { | |
14845 | const char *blanks = arg; | |
14846 | char *new_s; | |
14847 | ||
14848 | if (asprintf (&new_s, "%s%s", blanks, s) < 0) | |
14849 | return s; | |
14850 | return new_s; | |
14851 | } | |
14852 | ||
14853 | /* Dump CTF errors/warnings. */ | |
14854 | static void | |
14855 | dump_ctf_errs (ctf_dict_t *fp) | |
14856 | { | |
14857 | ctf_next_t *it = NULL; | |
14858 | char *errtext; | |
14859 | int is_warning; | |
14860 | int err; | |
14861 | ||
14862 | /* Dump accumulated errors and warnings. */ | |
14863 | while ((errtext = ctf_errwarning_next (fp, &it, &is_warning, &err)) != NULL) | |
14864 | { | |
14865 | error (_("%s: %s"), is_warning ? _("warning"): _("error"), | |
14866 | errtext); | |
14867 | free (errtext); | |
14868 | } | |
14869 | if (err != ECTF_NEXT_END) | |
14870 | error (_("CTF error: cannot get CTF errors: `%s'"), ctf_errmsg (err)); | |
14871 | } | |
14872 | ||
14873 | /* Dump one CTF archive member. */ | |
14874 | ||
14875 | static int | |
14876 | dump_ctf_archive_member (ctf_dict_t *ctf, const char *name, void *arg) | |
14877 | { | |
14878 | ctf_dict_t *parent = (ctf_dict_t *) arg; | |
14879 | const char *things[] = {"Header", "Labels", "Data objects", | |
14880 | "Function objects", "Variables", "Types", "Strings", | |
14881 | ""}; | |
14882 | const char **thing; | |
14883 | size_t i; | |
14884 | int err = 0; | |
14885 | ||
14886 | /* Only print out the name of non-default-named archive members. | |
14887 | The name .ctf appears everywhere, even for things that aren't | |
14888 | really archives, so printing it out is liable to be confusing. | |
14889 | ||
14890 | The parent, if there is one, is the default-owned archive member: | |
14891 | avoid importing it into itself. (This does no harm, but looks | |
14892 | confusing.) */ | |
14893 | ||
14894 | if (strcmp (name, ".ctf") != 0) | |
14895 | { | |
14896 | printf (_("\nCTF archive member: %s:\n"), name); | |
14897 | ctf_import (ctf, parent); | |
14898 | } | |
14899 | ||
14900 | for (i = 0, thing = things; *thing[0]; thing++, i++) | |
14901 | { | |
14902 | ctf_dump_state_t *s = NULL; | |
14903 | char *item; | |
14904 | ||
14905 | printf ("\n %s:\n", *thing); | |
14906 | while ((item = ctf_dump (ctf, &s, i, dump_ctf_indent_lines, | |
14907 | (void *) " ")) != NULL) | |
14908 | { | |
14909 | printf ("%s\n", item); | |
14910 | free (item); | |
14911 | } | |
14912 | ||
14913 | if (ctf_errno (ctf)) | |
14914 | { | |
14915 | error (_("Iteration failed: %s, %s\n"), *thing, | |
14916 | ctf_errmsg (ctf_errno (ctf))); | |
14917 | err = 1; | |
14918 | goto out; | |
14919 | } | |
14920 | } | |
14921 | ||
14922 | out: | |
14923 | dump_ctf_errs (ctf); | |
14924 | return err; | |
14925 | } | |
14926 | ||
14927 | static bfd_boolean | |
14928 | dump_section_as_ctf (Elf_Internal_Shdr * section, Filedata * filedata) | |
14929 | { | |
14930 | Elf_Internal_Shdr * parent_sec = NULL; | |
14931 | Elf_Internal_Shdr * symtab_sec = NULL; | |
14932 | Elf_Internal_Shdr * strtab_sec = NULL; | |
14933 | void * data = NULL; | |
14934 | void * symdata = NULL; | |
14935 | void * strdata = NULL; | |
14936 | void * parentdata = NULL; | |
14937 | ctf_sect_t ctfsect, symsect, strsect, parentsect; | |
14938 | ctf_sect_t * symsectp = NULL; | |
14939 | ctf_sect_t * strsectp = NULL; | |
14940 | ctf_archive_t * ctfa = NULL; | |
14941 | ctf_archive_t * parenta = NULL, *lookparent; | |
14942 | ctf_dict_t * parent = NULL; | |
14943 | ||
14944 | int err; | |
14945 | bfd_boolean ret = FALSE; | |
14946 | ||
14947 | shdr_to_ctf_sect (&ctfsect, section, filedata); | |
14948 | data = get_section_contents (section, filedata); | |
14949 | ctfsect.cts_data = data; | |
14950 | ||
14951 | if (!dump_ctf_symtab_name) | |
14952 | dump_ctf_symtab_name = strdup (".dynsym"); | |
14953 | ||
14954 | if (!dump_ctf_strtab_name) | |
14955 | dump_ctf_strtab_name = strdup (".dynstr"); | |
14956 | ||
14957 | if (dump_ctf_symtab_name && dump_ctf_symtab_name[0] != 0) | |
14958 | { | |
14959 | if ((symtab_sec = find_section (filedata, dump_ctf_symtab_name)) == NULL) | |
14960 | { | |
14961 | error (_("No symbol section named %s\n"), dump_ctf_symtab_name); | |
14962 | goto fail; | |
14963 | } | |
14964 | if ((symdata = (void *) get_data (NULL, filedata, | |
14965 | symtab_sec->sh_offset, 1, | |
14966 | symtab_sec->sh_size, | |
14967 | _("symbols"))) == NULL) | |
14968 | goto fail; | |
14969 | symsectp = shdr_to_ctf_sect (&symsect, symtab_sec, filedata); | |
14970 | symsect.cts_data = symdata; | |
14971 | } | |
14972 | ||
14973 | if (dump_ctf_strtab_name && dump_ctf_strtab_name[0] != 0) | |
14974 | { | |
14975 | if ((strtab_sec = find_section (filedata, dump_ctf_strtab_name)) == NULL) | |
14976 | { | |
14977 | error (_("No string table section named %s\n"), | |
14978 | dump_ctf_strtab_name); | |
14979 | goto fail; | |
14980 | } | |
14981 | if ((strdata = (void *) get_data (NULL, filedata, | |
14982 | strtab_sec->sh_offset, 1, | |
14983 | strtab_sec->sh_size, | |
14984 | _("strings"))) == NULL) | |
14985 | goto fail; | |
14986 | strsectp = shdr_to_ctf_sect (&strsect, strtab_sec, filedata); | |
14987 | strsect.cts_data = strdata; | |
14988 | } | |
14989 | ||
14990 | if (dump_ctf_parent_name) | |
14991 | { | |
14992 | if ((parent_sec = find_section (filedata, dump_ctf_parent_name)) == NULL) | |
14993 | { | |
14994 | error (_("No CTF parent section named %s\n"), dump_ctf_parent_name); | |
14995 | goto fail; | |
14996 | } | |
14997 | if ((parentdata = (void *) get_data (NULL, filedata, | |
14998 | parent_sec->sh_offset, 1, | |
14999 | parent_sec->sh_size, | |
15000 | _("CTF parent"))) == NULL) | |
15001 | goto fail; | |
15002 | shdr_to_ctf_sect (&parentsect, parent_sec, filedata); | |
15003 | parentsect.cts_data = parentdata; | |
15004 | } | |
15005 | ||
15006 | /* Load the CTF file and dump it. It may be a raw CTF section, or an archive: | |
15007 | libctf papers over the difference, so we can pretend it is always an | |
15008 | archive. Possibly open the parent as well, if one was specified. */ | |
15009 | ||
15010 | if ((ctfa = ctf_arc_bufopen (&ctfsect, symsectp, strsectp, &err)) == NULL) | |
15011 | { | |
15012 | dump_ctf_errs (NULL); | |
15013 | error (_("CTF open failure: %s\n"), ctf_errmsg (err)); | |
15014 | goto fail; | |
15015 | } | |
15016 | ||
15017 | ctf_arc_symsect_endianness (ctfa, filedata->file_header.e_ident[EI_DATA] | |
15018 | != ELFDATA2MSB); | |
15019 | ||
15020 | if (parentdata) | |
15021 | { | |
15022 | if ((parenta = ctf_arc_bufopen (&parentsect, symsectp, strsectp, | |
15023 | &err)) == NULL) | |
15024 | { | |
15025 | dump_ctf_errs (NULL); | |
15026 | error (_("CTF open failure: %s\n"), ctf_errmsg (err)); | |
15027 | goto fail; | |
15028 | } | |
15029 | lookparent = parenta; | |
15030 | } | |
15031 | else | |
15032 | lookparent = ctfa; | |
15033 | ||
15034 | /* Assume that the applicable parent archive member is the default one. | |
15035 | (This is what all known implementations are expected to do, if they | |
15036 | put CTFs and their parents in archives together.) */ | |
15037 | if ((parent = ctf_dict_open (lookparent, NULL, &err)) == NULL) | |
15038 | { | |
15039 | dump_ctf_errs (NULL); | |
15040 | error (_("CTF open failure: %s\n"), ctf_errmsg (err)); | |
15041 | goto fail; | |
15042 | } | |
15043 | ||
15044 | ret = TRUE; | |
15045 | ||
15046 | if (filedata->is_separate) | |
15047 | printf (_("\nDump of CTF section '%s' in linked file %s:\n"), | |
15048 | printable_section_name (filedata, section), | |
15049 | filedata->file_name); | |
15050 | else | |
15051 | printf (_("\nDump of CTF section '%s':\n"), | |
15052 | printable_section_name (filedata, section)); | |
15053 | ||
15054 | if ((err = ctf_archive_iter (ctfa, dump_ctf_archive_member, parent)) != 0) | |
15055 | { | |
15056 | dump_ctf_errs (NULL); | |
15057 | error (_("CTF member open failure: %s\n"), ctf_errmsg (err)); | |
15058 | ret = FALSE; | |
15059 | } | |
15060 | ||
15061 | fail: | |
15062 | ctf_dict_close (parent); | |
15063 | ctf_close (ctfa); | |
15064 | ctf_close (parenta); | |
15065 | free (parentdata); | |
15066 | free (data); | |
15067 | free (symdata); | |
15068 | free (strdata); | |
15069 | return ret; | |
15070 | } | |
15071 | #endif | |
15072 | ||
15073 | static bfd_boolean | |
15074 | load_specific_debug_section (enum dwarf_section_display_enum debug, | |
15075 | const Elf_Internal_Shdr * sec, | |
15076 | void * data) | |
15077 | { | |
15078 | struct dwarf_section * section = &debug_displays [debug].section; | |
15079 | char buf [64]; | |
15080 | Filedata * filedata = (Filedata *) data; | |
15081 | ||
15082 | if (section->start != NULL) | |
15083 | { | |
15084 | /* If it is already loaded, do nothing. */ | |
15085 | if (streq (section->filename, filedata->file_name)) | |
15086 | return TRUE; | |
15087 | free (section->start); | |
15088 | } | |
15089 | ||
15090 | snprintf (buf, sizeof (buf), _("%s section data"), section->name); | |
15091 | section->address = sec->sh_addr; | |
15092 | section->filename = filedata->file_name; | |
15093 | section->start = (unsigned char *) get_data (NULL, filedata, | |
15094 | sec->sh_offset, 1, | |
15095 | sec->sh_size, buf); | |
15096 | if (section->start == NULL) | |
15097 | section->size = 0; | |
15098 | else | |
15099 | { | |
15100 | unsigned char *start = section->start; | |
15101 | dwarf_size_type size = sec->sh_size; | |
15102 | dwarf_size_type uncompressed_size = 0; | |
15103 | ||
15104 | if ((sec->sh_flags & SHF_COMPRESSED) != 0) | |
15105 | { | |
15106 | Elf_Internal_Chdr chdr; | |
15107 | unsigned int compression_header_size; | |
15108 | ||
15109 | if (size < (is_32bit_elf | |
15110 | ? sizeof (Elf32_External_Chdr) | |
15111 | : sizeof (Elf64_External_Chdr))) | |
15112 | { | |
15113 | warn (_("compressed section %s is too small to contain a compression header\n"), | |
15114 | section->name); | |
15115 | return FALSE; | |
15116 | } | |
15117 | ||
15118 | compression_header_size = get_compression_header (&chdr, start, size); | |
15119 | if (compression_header_size == 0) | |
15120 | /* An error message will have already been generated | |
15121 | by get_compression_header. */ | |
15122 | return FALSE; | |
15123 | ||
15124 | if (chdr.ch_type != ELFCOMPRESS_ZLIB) | |
15125 | { | |
15126 | warn (_("section '%s' has unsupported compress type: %d\n"), | |
15127 | section->name, chdr.ch_type); | |
15128 | return FALSE; | |
15129 | } | |
15130 | uncompressed_size = chdr.ch_size; | |
15131 | start += compression_header_size; | |
15132 | size -= compression_header_size; | |
15133 | } | |
15134 | else if (size > 12 && streq ((char *) start, "ZLIB")) | |
15135 | { | |
15136 | /* Read the zlib header. In this case, it should be "ZLIB" | |
15137 | followed by the uncompressed section size, 8 bytes in | |
15138 | big-endian order. */ | |
15139 | uncompressed_size = start[4]; uncompressed_size <<= 8; | |
15140 | uncompressed_size += start[5]; uncompressed_size <<= 8; | |
15141 | uncompressed_size += start[6]; uncompressed_size <<= 8; | |
15142 | uncompressed_size += start[7]; uncompressed_size <<= 8; | |
15143 | uncompressed_size += start[8]; uncompressed_size <<= 8; | |
15144 | uncompressed_size += start[9]; uncompressed_size <<= 8; | |
15145 | uncompressed_size += start[10]; uncompressed_size <<= 8; | |
15146 | uncompressed_size += start[11]; | |
15147 | start += 12; | |
15148 | size -= 12; | |
15149 | } | |
15150 | ||
15151 | if (uncompressed_size) | |
15152 | { | |
15153 | if (uncompress_section_contents (&start, uncompressed_size, | |
15154 | &size)) | |
15155 | { | |
15156 | /* Free the compressed buffer, update the section buffer | |
15157 | and the section size if uncompress is successful. */ | |
15158 | free (section->start); | |
15159 | section->start = start; | |
15160 | } | |
15161 | else | |
15162 | { | |
15163 | error (_("Unable to decompress section %s\n"), | |
15164 | printable_section_name (filedata, sec)); | |
15165 | return FALSE; | |
15166 | } | |
15167 | } | |
15168 | ||
15169 | section->size = size; | |
15170 | } | |
15171 | ||
15172 | if (section->start == NULL) | |
15173 | return FALSE; | |
15174 | ||
15175 | if (debug_displays [debug].relocate) | |
15176 | { | |
15177 | if (! apply_relocations (filedata, sec, section->start, section->size, | |
15178 | & section->reloc_info, & section->num_relocs)) | |
15179 | return FALSE; | |
15180 | } | |
15181 | else | |
15182 | { | |
15183 | section->reloc_info = NULL; | |
15184 | section->num_relocs = 0; | |
15185 | } | |
15186 | ||
15187 | return TRUE; | |
15188 | } | |
15189 | ||
15190 | #if HAVE_LIBDEBUGINFOD | |
15191 | /* Return a hex string representation of the build-id. */ | |
15192 | unsigned char * | |
15193 | get_build_id (void * data) | |
15194 | { | |
15195 | Filedata * filedata = (Filedata *) data; | |
15196 | Elf_Internal_Shdr * shdr; | |
15197 | unsigned long i; | |
15198 | ||
15199 | /* Iterate through notes to find note.gnu.build-id. | |
15200 | FIXME: Only the first note in any note section is examined. */ | |
15201 | for (i = 0, shdr = filedata->section_headers; | |
15202 | i < filedata->file_header.e_shnum && shdr != NULL; | |
15203 | i++, shdr++) | |
15204 | { | |
15205 | if (shdr->sh_type != SHT_NOTE) | |
15206 | continue; | |
15207 | ||
15208 | char * next; | |
15209 | char * end; | |
15210 | size_t data_remaining; | |
15211 | size_t min_notesz; | |
15212 | Elf_External_Note * enote; | |
15213 | Elf_Internal_Note inote; | |
15214 | ||
15215 | bfd_vma offset = shdr->sh_offset; | |
15216 | bfd_vma align = shdr->sh_addralign; | |
15217 | bfd_vma length = shdr->sh_size; | |
15218 | ||
15219 | enote = (Elf_External_Note *) get_section_contents (shdr, filedata); | |
15220 | if (enote == NULL) | |
15221 | continue; | |
15222 | ||
15223 | if (align < 4) | |
15224 | align = 4; | |
15225 | else if (align != 4 && align != 8) | |
15226 | { | |
15227 | free (enote); | |
15228 | continue; | |
15229 | } | |
15230 | ||
15231 | end = (char *) enote + length; | |
15232 | data_remaining = end - (char *) enote; | |
15233 | ||
15234 | if (!is_ia64_vms (filedata)) | |
15235 | { | |
15236 | min_notesz = offsetof (Elf_External_Note, name); | |
15237 | if (data_remaining < min_notesz) | |
15238 | { | |
15239 | warn (_("\ | |
15240 | malformed note encountered in section %s whilst scanning for build-id note\n"), | |
15241 | printable_section_name (filedata, shdr)); | |
15242 | free (enote); | |
15243 | continue; | |
15244 | } | |
15245 | data_remaining -= min_notesz; | |
15246 | ||
15247 | inote.type = BYTE_GET (enote->type); | |
15248 | inote.namesz = BYTE_GET (enote->namesz); | |
15249 | inote.namedata = enote->name; | |
15250 | inote.descsz = BYTE_GET (enote->descsz); | |
15251 | inote.descdata = ((char *) enote | |
15252 | + ELF_NOTE_DESC_OFFSET (inote.namesz, align)); | |
15253 | inote.descpos = offset + (inote.descdata - (char *) enote); | |
15254 | next = ((char *) enote | |
15255 | + ELF_NOTE_NEXT_OFFSET (inote.namesz, inote.descsz, align)); | |
15256 | } | |
15257 | else | |
15258 | { | |
15259 | Elf64_External_VMS_Note *vms_enote; | |
15260 | ||
15261 | /* PR binutils/15191 | |
15262 | Make sure that there is enough data to read. */ | |
15263 | min_notesz = offsetof (Elf64_External_VMS_Note, name); | |
15264 | if (data_remaining < min_notesz) | |
15265 | { | |
15266 | warn (_("\ | |
15267 | malformed note encountered in section %s whilst scanning for build-id note\n"), | |
15268 | printable_section_name (filedata, shdr)); | |
15269 | free (enote); | |
15270 | continue; | |
15271 | } | |
15272 | data_remaining -= min_notesz; | |
15273 | ||
15274 | vms_enote = (Elf64_External_VMS_Note *) enote; | |
15275 | inote.type = BYTE_GET (vms_enote->type); | |
15276 | inote.namesz = BYTE_GET (vms_enote->namesz); | |
15277 | inote.namedata = vms_enote->name; | |
15278 | inote.descsz = BYTE_GET (vms_enote->descsz); | |
15279 | inote.descdata = inote.namedata + align_power (inote.namesz, 3); | |
15280 | inote.descpos = offset + (inote.descdata - (char *) enote); | |
15281 | next = inote.descdata + align_power (inote.descsz, 3); | |
15282 | } | |
15283 | ||
15284 | /* Skip malformed notes. */ | |
15285 | if ((size_t) (inote.descdata - inote.namedata) < inote.namesz | |
15286 | || (size_t) (inote.descdata - inote.namedata) > data_remaining | |
15287 | || (size_t) (next - inote.descdata) < inote.descsz | |
15288 | || ((size_t) (next - inote.descdata) | |
15289 | > data_remaining - (size_t) (inote.descdata - inote.namedata))) | |
15290 | { | |
15291 | warn (_("\ | |
15292 | malformed note encountered in section %s whilst scanning for build-id note\n"), | |
15293 | printable_section_name (filedata, shdr)); | |
15294 | free (enote); | |
15295 | continue; | |
15296 | } | |
15297 | ||
15298 | /* Check if this is the build-id note. If so then convert the build-id | |
15299 | bytes to a hex string. */ | |
15300 | if (inote.namesz > 0 | |
15301 | && const_strneq (inote.namedata, "GNU") | |
15302 | && inote.type == NT_GNU_BUILD_ID) | |
15303 | { | |
15304 | unsigned long j; | |
15305 | char * build_id; | |
15306 | ||
15307 | build_id = malloc (inote.descsz * 2 + 1); | |
15308 | if (build_id == NULL) | |
15309 | { | |
15310 | free (enote); | |
15311 | return NULL; | |
15312 | } | |
15313 | ||
15314 | for (j = 0; j < inote.descsz; ++j) | |
15315 | sprintf (build_id + (j * 2), "%02x", inote.descdata[j] & 0xff); | |
15316 | build_id[inote.descsz * 2] = '\0'; | |
15317 | free (enote); | |
15318 | ||
15319 | return (unsigned char *) build_id; | |
15320 | } | |
15321 | free (enote); | |
15322 | } | |
15323 | ||
15324 | return NULL; | |
15325 | } | |
15326 | #endif /* HAVE_LIBDEBUGINFOD */ | |
15327 | ||
15328 | /* If this is not NULL, load_debug_section will only look for sections | |
15329 | within the list of sections given here. */ | |
15330 | static unsigned int * section_subset = NULL; | |
15331 | ||
15332 | bfd_boolean | |
15333 | load_debug_section (enum dwarf_section_display_enum debug, void * data) | |
15334 | { | |
15335 | struct dwarf_section * section = &debug_displays [debug].section; | |
15336 | Elf_Internal_Shdr * sec; | |
15337 | Filedata * filedata = (Filedata *) data; | |
15338 | ||
15339 | /* Without section headers we cannot find any sections. */ | |
15340 | if (filedata->section_headers == NULL) | |
15341 | return FALSE; | |
15342 | ||
15343 | if (filedata->string_table == NULL | |
15344 | && filedata->file_header.e_shstrndx != SHN_UNDEF | |
15345 | && filedata->file_header.e_shstrndx < filedata->file_header.e_shnum) | |
15346 | { | |
15347 | Elf_Internal_Shdr * strs; | |
15348 | ||
15349 | /* Read in the string table, so that we have section names to scan. */ | |
15350 | strs = filedata->section_headers + filedata->file_header.e_shstrndx; | |
15351 | ||
15352 | if (strs != NULL && strs->sh_size != 0) | |
15353 | { | |
15354 | filedata->string_table | |
15355 | = (char *) get_data (NULL, filedata, strs->sh_offset, | |
15356 | 1, strs->sh_size, _("string table")); | |
15357 | ||
15358 | filedata->string_table_length | |
15359 | = filedata->string_table != NULL ? strs->sh_size : 0; | |
15360 | } | |
15361 | } | |
15362 | ||
15363 | /* Locate the debug section. */ | |
15364 | sec = find_section_in_set (filedata, section->uncompressed_name, section_subset); | |
15365 | if (sec != NULL) | |
15366 | section->name = section->uncompressed_name; | |
15367 | else | |
15368 | { | |
15369 | sec = find_section_in_set (filedata, section->compressed_name, section_subset); | |
15370 | if (sec != NULL) | |
15371 | section->name = section->compressed_name; | |
15372 | } | |
15373 | if (sec == NULL) | |
15374 | return FALSE; | |
15375 | ||
15376 | /* If we're loading from a subset of sections, and we've loaded | |
15377 | a section matching this name before, it's likely that it's a | |
15378 | different one. */ | |
15379 | if (section_subset != NULL) | |
15380 | free_debug_section (debug); | |
15381 | ||
15382 | return load_specific_debug_section (debug, sec, data); | |
15383 | } | |
15384 | ||
15385 | void | |
15386 | free_debug_section (enum dwarf_section_display_enum debug) | |
15387 | { | |
15388 | struct dwarf_section * section = &debug_displays [debug].section; | |
15389 | ||
15390 | if (section->start == NULL) | |
15391 | return; | |
15392 | ||
15393 | free ((char *) section->start); | |
15394 | section->start = NULL; | |
15395 | section->address = 0; | |
15396 | section->size = 0; | |
15397 | ||
15398 | free (section->reloc_info); | |
15399 | section->reloc_info = NULL; | |
15400 | section->num_relocs = 0; | |
15401 | } | |
15402 | ||
15403 | static bfd_boolean | |
15404 | display_debug_section (int shndx, Elf_Internal_Shdr * section, Filedata * filedata) | |
15405 | { | |
15406 | char * name = SECTION_NAME_VALID (section) ? SECTION_NAME (section) : ""; | |
15407 | const char * print_name = printable_section_name (filedata, section); | |
15408 | bfd_size_type length; | |
15409 | bfd_boolean result = TRUE; | |
15410 | int i; | |
15411 | ||
15412 | length = section->sh_size; | |
15413 | if (length == 0) | |
15414 | { | |
15415 | printf (_("\nSection '%s' has no debugging data.\n"), print_name); | |
15416 | return TRUE; | |
15417 | } | |
15418 | if (section->sh_type == SHT_NOBITS) | |
15419 | { | |
15420 | /* There is no point in dumping the contents of a debugging section | |
15421 | which has the NOBITS type - the bits in the file will be random. | |
15422 | This can happen when a file containing a .eh_frame section is | |
15423 | stripped with the --only-keep-debug command line option. */ | |
15424 | printf (_("section '%s' has the NOBITS type - its contents are unreliable.\n"), | |
15425 | print_name); | |
15426 | return FALSE; | |
15427 | } | |
15428 | ||
15429 | if (const_strneq (name, ".gnu.linkonce.wi.")) | |
15430 | name = ".debug_info"; | |
15431 | ||
15432 | /* See if we know how to display the contents of this section. */ | |
15433 | for (i = 0; i < max; i++) | |
15434 | { | |
15435 | enum dwarf_section_display_enum id = (enum dwarf_section_display_enum) i; | |
15436 | struct dwarf_section_display * display = debug_displays + i; | |
15437 | struct dwarf_section * sec = & display->section; | |
15438 | ||
15439 | if (streq (sec->uncompressed_name, name) | |
15440 | || (id == line && const_strneq (name, ".debug_line.")) | |
15441 | || streq (sec->compressed_name, name)) | |
15442 | { | |
15443 | bfd_boolean secondary = (section != find_section (filedata, name)); | |
15444 | ||
15445 | if (secondary) | |
15446 | free_debug_section (id); | |
15447 | ||
15448 | if (i == line && const_strneq (name, ".debug_line.")) | |
15449 | sec->name = name; | |
15450 | else if (streq (sec->uncompressed_name, name)) | |
15451 | sec->name = sec->uncompressed_name; | |
15452 | else | |
15453 | sec->name = sec->compressed_name; | |
15454 | ||
15455 | if (load_specific_debug_section (id, section, filedata)) | |
15456 | { | |
15457 | /* If this debug section is part of a CU/TU set in a .dwp file, | |
15458 | restrict load_debug_section to the sections in that set. */ | |
15459 | section_subset = find_cu_tu_set (filedata, shndx); | |
15460 | ||
15461 | result &= display->display (sec, filedata); | |
15462 | ||
15463 | section_subset = NULL; | |
15464 | ||
15465 | if (secondary || (id != info && id != abbrev && id != debug_addr)) | |
15466 | free_debug_section (id); | |
15467 | } | |
15468 | break; | |
15469 | } | |
15470 | } | |
15471 | ||
15472 | if (i == max) | |
15473 | { | |
15474 | printf (_("Unrecognized debug section: %s\n"), print_name); | |
15475 | result = FALSE; | |
15476 | } | |
15477 | ||
15478 | return result; | |
15479 | } | |
15480 | ||
15481 | /* Set DUMP_SECTS for all sections where dumps were requested | |
15482 | based on section name. */ | |
15483 | ||
15484 | static void | |
15485 | initialise_dumps_byname (Filedata * filedata) | |
15486 | { | |
15487 | struct dump_list_entry * cur; | |
15488 | ||
15489 | for (cur = dump_sects_byname; cur; cur = cur->next) | |
15490 | { | |
15491 | unsigned int i; | |
15492 | bfd_boolean any = FALSE; | |
15493 | ||
15494 | for (i = 0; i < filedata->file_header.e_shnum; i++) | |
15495 | if (SECTION_NAME_VALID (filedata->section_headers + i) | |
15496 | && streq (SECTION_NAME (filedata->section_headers + i), cur->name)) | |
15497 | { | |
15498 | request_dump_bynumber (&filedata->dump, i, cur->type); | |
15499 | any = TRUE; | |
15500 | } | |
15501 | ||
15502 | if (!any && !filedata->is_separate) | |
15503 | warn (_("Section '%s' was not dumped because it does not exist\n"), | |
15504 | cur->name); | |
15505 | } | |
15506 | } | |
15507 | ||
15508 | static bfd_boolean | |
15509 | process_section_contents (Filedata * filedata) | |
15510 | { | |
15511 | Elf_Internal_Shdr * section; | |
15512 | unsigned int i; | |
15513 | bfd_boolean res = TRUE; | |
15514 | ||
15515 | if (! do_dump) | |
15516 | return TRUE; | |
15517 | ||
15518 | initialise_dumps_byname (filedata); | |
15519 | ||
15520 | for (i = 0, section = filedata->section_headers; | |
15521 | i < filedata->file_header.e_shnum && i < filedata->dump.num_dump_sects; | |
15522 | i++, section++) | |
15523 | { | |
15524 | dump_type dump = filedata->dump.dump_sects[i]; | |
15525 | ||
15526 | if (filedata->is_separate && ! process_links) | |
15527 | dump &= DEBUG_DUMP; | |
15528 | ||
15529 | #ifdef SUPPORT_DISASSEMBLY | |
15530 | if (dump & DISASS_DUMP) | |
15531 | { | |
15532 | if (! disassemble_section (section, filedata)) | |
15533 | res = FALSE; | |
15534 | } | |
15535 | #endif | |
15536 | if (dump & HEX_DUMP) | |
15537 | { | |
15538 | if (! dump_section_as_bytes (section, filedata, FALSE)) | |
15539 | res = FALSE; | |
15540 | } | |
15541 | ||
15542 | if (dump & RELOC_DUMP) | |
15543 | { | |
15544 | if (! dump_section_as_bytes (section, filedata, TRUE)) | |
15545 | res = FALSE; | |
15546 | } | |
15547 | ||
15548 | if (dump & STRING_DUMP) | |
15549 | { | |
15550 | if (! dump_section_as_strings (section, filedata)) | |
15551 | res = FALSE; | |
15552 | } | |
15553 | ||
15554 | if (dump & DEBUG_DUMP) | |
15555 | { | |
15556 | if (! display_debug_section (i, section, filedata)) | |
15557 | res = FALSE; | |
15558 | } | |
15559 | ||
15560 | #ifdef ENABLE_LIBCTF | |
15561 | if (dump & CTF_DUMP) | |
15562 | { | |
15563 | if (! dump_section_as_ctf (section, filedata)) | |
15564 | res = FALSE; | |
15565 | } | |
15566 | #endif | |
15567 | } | |
15568 | ||
15569 | if (! filedata->is_separate) | |
15570 | { | |
15571 | /* Check to see if the user requested a | |
15572 | dump of a section that does not exist. */ | |
15573 | for (; i < filedata->dump.num_dump_sects; i++) | |
15574 | if (filedata->dump.dump_sects[i]) | |
15575 | { | |
15576 | warn (_("Section %d was not dumped because it does not exist!\n"), i); | |
15577 | res = FALSE; | |
15578 | } | |
15579 | } | |
15580 | ||
15581 | return res; | |
15582 | } | |
15583 | ||
15584 | static void | |
15585 | process_mips_fpe_exception (int mask) | |
15586 | { | |
15587 | if (mask) | |
15588 | { | |
15589 | bfd_boolean first = TRUE; | |
15590 | ||
15591 | if (mask & OEX_FPU_INEX) | |
15592 | fputs ("INEX", stdout), first = FALSE; | |
15593 | if (mask & OEX_FPU_UFLO) | |
15594 | printf ("%sUFLO", first ? "" : "|"), first = FALSE; | |
15595 | if (mask & OEX_FPU_OFLO) | |
15596 | printf ("%sOFLO", first ? "" : "|"), first = FALSE; | |
15597 | if (mask & OEX_FPU_DIV0) | |
15598 | printf ("%sDIV0", first ? "" : "|"), first = FALSE; | |
15599 | if (mask & OEX_FPU_INVAL) | |
15600 | printf ("%sINVAL", first ? "" : "|"); | |
15601 | } | |
15602 | else | |
15603 | fputs ("0", stdout); | |
15604 | } | |
15605 | ||
15606 | /* Display's the value of TAG at location P. If TAG is | |
15607 | greater than 0 it is assumed to be an unknown tag, and | |
15608 | a message is printed to this effect. Otherwise it is | |
15609 | assumed that a message has already been printed. | |
15610 | ||
15611 | If the bottom bit of TAG is set it assumed to have a | |
15612 | string value, otherwise it is assumed to have an integer | |
15613 | value. | |
15614 | ||
15615 | Returns an updated P pointing to the first unread byte | |
15616 | beyond the end of TAG's value. | |
15617 | ||
15618 | Reads at or beyond END will not be made. */ | |
15619 | ||
15620 | static unsigned char * | |
15621 | display_tag_value (signed int tag, | |
15622 | unsigned char * p, | |
15623 | const unsigned char * const end) | |
15624 | { | |
15625 | unsigned long val; | |
15626 | ||
15627 | if (tag > 0) | |
15628 | printf (" Tag_unknown_%d: ", tag); | |
15629 | ||
15630 | if (p >= end) | |
15631 | { | |
15632 | warn (_("<corrupt tag>\n")); | |
15633 | } | |
15634 | else if (tag & 1) | |
15635 | { | |
15636 | /* PR 17531 file: 027-19978-0.004. */ | |
15637 | size_t maxlen = (end - p) - 1; | |
15638 | ||
15639 | putchar ('"'); | |
15640 | if (maxlen > 0) | |
15641 | { | |
15642 | print_symbol ((int) maxlen, (const char *) p); | |
15643 | p += strnlen ((char *) p, maxlen) + 1; | |
15644 | } | |
15645 | else | |
15646 | { | |
15647 | printf (_("<corrupt string tag>")); | |
15648 | p = (unsigned char *) end; | |
15649 | } | |
15650 | printf ("\"\n"); | |
15651 | } | |
15652 | else | |
15653 | { | |
15654 | READ_ULEB (val, p, end); | |
15655 | printf ("%ld (0x%lx)\n", val, val); | |
15656 | } | |
15657 | ||
15658 | assert (p <= end); | |
15659 | return p; | |
15660 | } | |
15661 | ||
15662 | /* ARC ABI attributes section. */ | |
15663 | ||
15664 | static unsigned char * | |
15665 | display_arc_attribute (unsigned char * p, | |
15666 | const unsigned char * const end) | |
15667 | { | |
15668 | unsigned int tag; | |
15669 | unsigned int val; | |
15670 | ||
15671 | READ_ULEB (tag, p, end); | |
15672 | ||
15673 | switch (tag) | |
15674 | { | |
15675 | case Tag_ARC_PCS_config: | |
15676 | READ_ULEB (val, p, end); | |
15677 | printf (" Tag_ARC_PCS_config: "); | |
15678 | switch (val) | |
15679 | { | |
15680 | case 0: | |
15681 | printf (_("Absent/Non standard\n")); | |
15682 | break; | |
15683 | case 1: | |
15684 | printf (_("Bare metal/mwdt\n")); | |
15685 | break; | |
15686 | case 2: | |
15687 | printf (_("Bare metal/newlib\n")); | |
15688 | break; | |
15689 | case 3: | |
15690 | printf (_("Linux/uclibc\n")); | |
15691 | break; | |
15692 | case 4: | |
15693 | printf (_("Linux/glibc\n")); | |
15694 | break; | |
15695 | default: | |
15696 | printf (_("Unknown\n")); | |
15697 | break; | |
15698 | } | |
15699 | break; | |
15700 | ||
15701 | case Tag_ARC_CPU_base: | |
15702 | READ_ULEB (val, p, end); | |
15703 | printf (" Tag_ARC_CPU_base: "); | |
15704 | switch (val) | |
15705 | { | |
15706 | default: | |
15707 | case TAG_CPU_NONE: | |
15708 | printf (_("Absent\n")); | |
15709 | break; | |
15710 | case TAG_CPU_ARC6xx: | |
15711 | printf ("ARC6xx\n"); | |
15712 | break; | |
15713 | case TAG_CPU_ARC7xx: | |
15714 | printf ("ARC7xx\n"); | |
15715 | break; | |
15716 | case TAG_CPU_ARCEM: | |
15717 | printf ("ARCEM\n"); | |
15718 | break; | |
15719 | case TAG_CPU_ARCHS: | |
15720 | printf ("ARCHS\n"); | |
15721 | break; | |
15722 | } | |
15723 | break; | |
15724 | ||
15725 | case Tag_ARC_CPU_variation: | |
15726 | READ_ULEB (val, p, end); | |
15727 | printf (" Tag_ARC_CPU_variation: "); | |
15728 | switch (val) | |
15729 | { | |
15730 | default: | |
15731 | if (val > 0 && val < 16) | |
15732 | printf ("Core%d\n", val); | |
15733 | else | |
15734 | printf ("Unknown\n"); | |
15735 | break; | |
15736 | ||
15737 | case 0: | |
15738 | printf (_("Absent\n")); | |
15739 | break; | |
15740 | } | |
15741 | break; | |
15742 | ||
15743 | case Tag_ARC_CPU_name: | |
15744 | printf (" Tag_ARC_CPU_name: "); | |
15745 | p = display_tag_value (-1, p, end); | |
15746 | break; | |
15747 | ||
15748 | case Tag_ARC_ABI_rf16: | |
15749 | READ_ULEB (val, p, end); | |
15750 | printf (" Tag_ARC_ABI_rf16: %s\n", val ? _("yes") : _("no")); | |
15751 | break; | |
15752 | ||
15753 | case Tag_ARC_ABI_osver: | |
15754 | READ_ULEB (val, p, end); | |
15755 | printf (" Tag_ARC_ABI_osver: v%d\n", val); | |
15756 | break; | |
15757 | ||
15758 | case Tag_ARC_ABI_pic: | |
15759 | case Tag_ARC_ABI_sda: | |
15760 | READ_ULEB (val, p, end); | |
15761 | printf (tag == Tag_ARC_ABI_sda ? " Tag_ARC_ABI_sda: " | |
15762 | : " Tag_ARC_ABI_pic: "); | |
15763 | switch (val) | |
15764 | { | |
15765 | case 0: | |
15766 | printf (_("Absent\n")); | |
15767 | break; | |
15768 | case 1: | |
15769 | printf ("MWDT\n"); | |
15770 | break; | |
15771 | case 2: | |
15772 | printf ("GNU\n"); | |
15773 | break; | |
15774 | default: | |
15775 | printf (_("Unknown\n")); | |
15776 | break; | |
15777 | } | |
15778 | break; | |
15779 | ||
15780 | case Tag_ARC_ABI_tls: | |
15781 | READ_ULEB (val, p, end); | |
15782 | printf (" Tag_ARC_ABI_tls: %s\n", val ? "r25": "none"); | |
15783 | break; | |
15784 | ||
15785 | case Tag_ARC_ABI_enumsize: | |
15786 | READ_ULEB (val, p, end); | |
15787 | printf (" Tag_ARC_ABI_enumsize: %s\n", val ? _("default") : | |
15788 | _("smallest")); | |
15789 | break; | |
15790 | ||
15791 | case Tag_ARC_ABI_exceptions: | |
15792 | READ_ULEB (val, p, end); | |
15793 | printf (" Tag_ARC_ABI_exceptions: %s\n", val ? _("OPTFP") | |
15794 | : _("default")); | |
15795 | break; | |
15796 | ||
15797 | case Tag_ARC_ABI_double_size: | |
15798 | READ_ULEB (val, p, end); | |
15799 | printf (" Tag_ARC_ABI_double_size: %d\n", val); | |
15800 | break; | |
15801 | ||
15802 | case Tag_ARC_ISA_config: | |
15803 | printf (" Tag_ARC_ISA_config: "); | |
15804 | p = display_tag_value (-1, p, end); | |
15805 | break; | |
15806 | ||
15807 | case Tag_ARC_ISA_apex: | |
15808 | printf (" Tag_ARC_ISA_apex: "); | |
15809 | p = display_tag_value (-1, p, end); | |
15810 | break; | |
15811 | ||
15812 | case Tag_ARC_ISA_mpy_option: | |
15813 | READ_ULEB (val, p, end); | |
15814 | printf (" Tag_ARC_ISA_mpy_option: %d\n", val); | |
15815 | break; | |
15816 | ||
15817 | case Tag_ARC_ATR_version: | |
15818 | READ_ULEB (val, p, end); | |
15819 | printf (" Tag_ARC_ATR_version: %d\n", val); | |
15820 | break; | |
15821 | ||
15822 | default: | |
15823 | return display_tag_value (tag & 1, p, end); | |
15824 | } | |
15825 | ||
15826 | return p; | |
15827 | } | |
15828 | ||
15829 | /* ARM EABI attributes section. */ | |
15830 | typedef struct | |
15831 | { | |
15832 | unsigned int tag; | |
15833 | const char * name; | |
15834 | /* 0 = special, 1 = string, 2 = uleb123, > 0x80 == table lookup. */ | |
15835 | unsigned int type; | |
15836 | const char *const *table; | |
15837 | } arm_attr_public_tag; | |
15838 | ||
15839 | static const char *const arm_attr_tag_CPU_arch[] = | |
15840 | {"Pre-v4", "v4", "v4T", "v5T", "v5TE", "v5TEJ", "v6", "v6KZ", "v6T2", | |
15841 | "v6K", "v7", "v6-M", "v6S-M", "v7E-M", "v8", "v8-R", "v8-M.baseline", | |
15842 | "v8-M.mainline", "", "", "", "v8.1-M.mainline"}; | |
15843 | static const char *const arm_attr_tag_ARM_ISA_use[] = {"No", "Yes"}; | |
15844 | static const char *const arm_attr_tag_THUMB_ISA_use[] = | |
15845 | {"No", "Thumb-1", "Thumb-2", "Yes"}; | |
15846 | static const char *const arm_attr_tag_FP_arch[] = | |
15847 | {"No", "VFPv1", "VFPv2", "VFPv3", "VFPv3-D16", "VFPv4", "VFPv4-D16", | |
15848 | "FP for ARMv8", "FPv5/FP-D16 for ARMv8"}; | |
15849 | static const char *const arm_attr_tag_WMMX_arch[] = {"No", "WMMXv1", "WMMXv2"}; | |
15850 | static const char *const arm_attr_tag_Advanced_SIMD_arch[] = | |
15851 | {"No", "NEONv1", "NEONv1 with Fused-MAC", "NEON for ARMv8", | |
15852 | "NEON for ARMv8.1"}; | |
15853 | static const char *const arm_attr_tag_PCS_config[] = | |
15854 | {"None", "Bare platform", "Linux application", "Linux DSO", "PalmOS 2004", | |
15855 | "PalmOS (reserved)", "SymbianOS 2004", "SymbianOS (reserved)"}; | |
15856 | static const char *const arm_attr_tag_ABI_PCS_R9_use[] = | |
15857 | {"V6", "SB", "TLS", "Unused"}; | |
15858 | static const char *const arm_attr_tag_ABI_PCS_RW_data[] = | |
15859 | {"Absolute", "PC-relative", "SB-relative", "None"}; | |
15860 | static const char *const arm_attr_tag_ABI_PCS_RO_data[] = | |
15861 | {"Absolute", "PC-relative", "None"}; | |
15862 | static const char *const arm_attr_tag_ABI_PCS_GOT_use[] = | |
15863 | {"None", "direct", "GOT-indirect"}; | |
15864 | static const char *const arm_attr_tag_ABI_PCS_wchar_t[] = | |
15865 | {"None", "??? 1", "2", "??? 3", "4"}; | |
15866 | static const char *const arm_attr_tag_ABI_FP_rounding[] = {"Unused", "Needed"}; | |
15867 | static const char *const arm_attr_tag_ABI_FP_denormal[] = | |
15868 | {"Unused", "Needed", "Sign only"}; | |
15869 | static const char *const arm_attr_tag_ABI_FP_exceptions[] = {"Unused", "Needed"}; | |
15870 | static const char *const arm_attr_tag_ABI_FP_user_exceptions[] = {"Unused", "Needed"}; | |
15871 | static const char *const arm_attr_tag_ABI_FP_number_model[] = | |
15872 | {"Unused", "Finite", "RTABI", "IEEE 754"}; | |
15873 | static const char *const arm_attr_tag_ABI_enum_size[] = | |
15874 | {"Unused", "small", "int", "forced to int"}; | |
15875 | static const char *const arm_attr_tag_ABI_HardFP_use[] = | |
15876 | {"As Tag_FP_arch", "SP only", "Reserved", "Deprecated"}; | |
15877 | static const char *const arm_attr_tag_ABI_VFP_args[] = | |
15878 | {"AAPCS", "VFP registers", "custom", "compatible"}; | |
15879 | static const char *const arm_attr_tag_ABI_WMMX_args[] = | |
15880 | {"AAPCS", "WMMX registers", "custom"}; | |
15881 | static const char *const arm_attr_tag_ABI_optimization_goals[] = | |
15882 | {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size", | |
15883 | "Aggressive Size", "Prefer Debug", "Aggressive Debug"}; | |
15884 | static const char *const arm_attr_tag_ABI_FP_optimization_goals[] = | |
15885 | {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size", | |
15886 | "Aggressive Size", "Prefer Accuracy", "Aggressive Accuracy"}; | |
15887 | static const char *const arm_attr_tag_CPU_unaligned_access[] = {"None", "v6"}; | |
15888 | static const char *const arm_attr_tag_FP_HP_extension[] = | |
15889 | {"Not Allowed", "Allowed"}; | |
15890 | static const char *const arm_attr_tag_ABI_FP_16bit_format[] = | |
15891 | {"None", "IEEE 754", "Alternative Format"}; | |
15892 | static const char *const arm_attr_tag_DSP_extension[] = | |
15893 | {"Follow architecture", "Allowed"}; | |
15894 | static const char *const arm_attr_tag_MPextension_use[] = | |
15895 | {"Not Allowed", "Allowed"}; | |
15896 | static const char *const arm_attr_tag_DIV_use[] = | |
15897 | {"Allowed in Thumb-ISA, v7-R or v7-M", "Not allowed", | |
15898 | "Allowed in v7-A with integer division extension"}; | |
15899 | static const char *const arm_attr_tag_T2EE_use[] = {"Not Allowed", "Allowed"}; | |
15900 | static const char *const arm_attr_tag_Virtualization_use[] = | |
15901 | {"Not Allowed", "TrustZone", "Virtualization Extensions", | |
15902 | "TrustZone and Virtualization Extensions"}; | |
15903 | static const char *const arm_attr_tag_MPextension_use_legacy[] = | |
15904 | {"Not Allowed", "Allowed"}; | |
15905 | ||
15906 | static const char *const arm_attr_tag_MVE_arch[] = | |
15907 | {"No MVE", "MVE Integer only", "MVE Integer and FP"}; | |
15908 | ||
15909 | #define LOOKUP(id, name) \ | |
15910 | {id, #name, 0x80 | ARRAY_SIZE(arm_attr_tag_##name), arm_attr_tag_##name} | |
15911 | static arm_attr_public_tag arm_attr_public_tags[] = | |
15912 | { | |
15913 | {4, "CPU_raw_name", 1, NULL}, | |
15914 | {5, "CPU_name", 1, NULL}, | |
15915 | LOOKUP(6, CPU_arch), | |
15916 | {7, "CPU_arch_profile", 0, NULL}, | |
15917 | LOOKUP(8, ARM_ISA_use), | |
15918 | LOOKUP(9, THUMB_ISA_use), | |
15919 | LOOKUP(10, FP_arch), | |
15920 | LOOKUP(11, WMMX_arch), | |
15921 | LOOKUP(12, Advanced_SIMD_arch), | |
15922 | LOOKUP(13, PCS_config), | |
15923 | LOOKUP(14, ABI_PCS_R9_use), | |
15924 | LOOKUP(15, ABI_PCS_RW_data), | |
15925 | LOOKUP(16, ABI_PCS_RO_data), | |
15926 | LOOKUP(17, ABI_PCS_GOT_use), | |
15927 | LOOKUP(18, ABI_PCS_wchar_t), | |
15928 | LOOKUP(19, ABI_FP_rounding), | |
15929 | LOOKUP(20, ABI_FP_denormal), | |
15930 | LOOKUP(21, ABI_FP_exceptions), | |
15931 | LOOKUP(22, ABI_FP_user_exceptions), | |
15932 | LOOKUP(23, ABI_FP_number_model), | |
15933 | {24, "ABI_align_needed", 0, NULL}, | |
15934 | {25, "ABI_align_preserved", 0, NULL}, | |
15935 | LOOKUP(26, ABI_enum_size), | |
15936 | LOOKUP(27, ABI_HardFP_use), | |
15937 | LOOKUP(28, ABI_VFP_args), | |
15938 | LOOKUP(29, ABI_WMMX_args), | |
15939 | LOOKUP(30, ABI_optimization_goals), | |
15940 | LOOKUP(31, ABI_FP_optimization_goals), | |
15941 | {32, "compatibility", 0, NULL}, | |
15942 | LOOKUP(34, CPU_unaligned_access), | |
15943 | LOOKUP(36, FP_HP_extension), | |
15944 | LOOKUP(38, ABI_FP_16bit_format), | |
15945 | LOOKUP(42, MPextension_use), | |
15946 | LOOKUP(44, DIV_use), | |
15947 | LOOKUP(46, DSP_extension), | |
15948 | LOOKUP(48, MVE_arch), | |
15949 | {64, "nodefaults", 0, NULL}, | |
15950 | {65, "also_compatible_with", 0, NULL}, | |
15951 | LOOKUP(66, T2EE_use), | |
15952 | {67, "conformance", 1, NULL}, | |
15953 | LOOKUP(68, Virtualization_use), | |
15954 | LOOKUP(70, MPextension_use_legacy) | |
15955 | }; | |
15956 | #undef LOOKUP | |
15957 | ||
15958 | static unsigned char * | |
15959 | display_arm_attribute (unsigned char * p, | |
15960 | const unsigned char * const end) | |
15961 | { | |
15962 | unsigned int tag; | |
15963 | unsigned int val; | |
15964 | arm_attr_public_tag * attr; | |
15965 | unsigned i; | |
15966 | unsigned int type; | |
15967 | ||
15968 | READ_ULEB (tag, p, end); | |
15969 | attr = NULL; | |
15970 | for (i = 0; i < ARRAY_SIZE (arm_attr_public_tags); i++) | |
15971 | { | |
15972 | if (arm_attr_public_tags[i].tag == tag) | |
15973 | { | |
15974 | attr = &arm_attr_public_tags[i]; | |
15975 | break; | |
15976 | } | |
15977 | } | |
15978 | ||
15979 | if (attr) | |
15980 | { | |
15981 | printf (" Tag_%s: ", attr->name); | |
15982 | switch (attr->type) | |
15983 | { | |
15984 | case 0: | |
15985 | switch (tag) | |
15986 | { | |
15987 | case 7: /* Tag_CPU_arch_profile. */ | |
15988 | READ_ULEB (val, p, end); | |
15989 | switch (val) | |
15990 | { | |
15991 | case 0: printf (_("None\n")); break; | |
15992 | case 'A': printf (_("Application\n")); break; | |
15993 | case 'R': printf (_("Realtime\n")); break; | |
15994 | case 'M': printf (_("Microcontroller\n")); break; | |
15995 | case 'S': printf (_("Application or Realtime\n")); break; | |
15996 | default: printf ("??? (%d)\n", val); break; | |
15997 | } | |
15998 | break; | |
15999 | ||
16000 | case 24: /* Tag_align_needed. */ | |
16001 | READ_ULEB (val, p, end); | |
16002 | switch (val) | |
16003 | { | |
16004 | case 0: printf (_("None\n")); break; | |
16005 | case 1: printf (_("8-byte\n")); break; | |
16006 | case 2: printf (_("4-byte\n")); break; | |
16007 | case 3: printf ("??? 3\n"); break; | |
16008 | default: | |
16009 | if (val <= 12) | |
16010 | printf (_("8-byte and up to %d-byte extended\n"), | |
16011 | 1 << val); | |
16012 | else | |
16013 | printf ("??? (%d)\n", val); | |
16014 | break; | |
16015 | } | |
16016 | break; | |
16017 | ||
16018 | case 25: /* Tag_align_preserved. */ | |
16019 | READ_ULEB (val, p, end); | |
16020 | switch (val) | |
16021 | { | |
16022 | case 0: printf (_("None\n")); break; | |
16023 | case 1: printf (_("8-byte, except leaf SP\n")); break; | |
16024 | case 2: printf (_("8-byte\n")); break; | |
16025 | case 3: printf ("??? 3\n"); break; | |
16026 | default: | |
16027 | if (val <= 12) | |
16028 | printf (_("8-byte and up to %d-byte extended\n"), | |
16029 | 1 << val); | |
16030 | else | |
16031 | printf ("??? (%d)\n", val); | |
16032 | break; | |
16033 | } | |
16034 | break; | |
16035 | ||
16036 | case 32: /* Tag_compatibility. */ | |
16037 | { | |
16038 | READ_ULEB (val, p, end); | |
16039 | printf (_("flag = %d, vendor = "), val); | |
16040 | if (p < end - 1) | |
16041 | { | |
16042 | size_t maxlen = (end - p) - 1; | |
16043 | ||
16044 | print_symbol ((int) maxlen, (const char *) p); | |
16045 | p += strnlen ((char *) p, maxlen) + 1; | |
16046 | } | |
16047 | else | |
16048 | { | |
16049 | printf (_("<corrupt>")); | |
16050 | p = (unsigned char *) end; | |
16051 | } | |
16052 | putchar ('\n'); | |
16053 | } | |
16054 | break; | |
16055 | ||
16056 | case 64: /* Tag_nodefaults. */ | |
16057 | /* PR 17531: file: 001-505008-0.01. */ | |
16058 | if (p < end) | |
16059 | p++; | |
16060 | printf (_("True\n")); | |
16061 | break; | |
16062 | ||
16063 | case 65: /* Tag_also_compatible_with. */ | |
16064 | READ_ULEB (val, p, end); | |
16065 | if (val == 6 /* Tag_CPU_arch. */) | |
16066 | { | |
16067 | READ_ULEB (val, p, end); | |
16068 | if ((unsigned int) val >= ARRAY_SIZE (arm_attr_tag_CPU_arch)) | |
16069 | printf ("??? (%d)\n", val); | |
16070 | else | |
16071 | printf ("%s\n", arm_attr_tag_CPU_arch[val]); | |
16072 | } | |
16073 | else | |
16074 | printf ("???\n"); | |
16075 | while (p < end && *(p++) != '\0' /* NUL terminator. */) | |
16076 | ; | |
16077 | break; | |
16078 | ||
16079 | default: | |
16080 | printf (_("<unknown: %d>\n"), tag); | |
16081 | break; | |
16082 | } | |
16083 | return p; | |
16084 | ||
16085 | case 1: | |
16086 | return display_tag_value (-1, p, end); | |
16087 | case 2: | |
16088 | return display_tag_value (0, p, end); | |
16089 | ||
16090 | default: | |
16091 | assert (attr->type & 0x80); | |
16092 | READ_ULEB (val, p, end); | |
16093 | type = attr->type & 0x7f; | |
16094 | if (val >= type) | |
16095 | printf ("??? (%d)\n", val); | |
16096 | else | |
16097 | printf ("%s\n", attr->table[val]); | |
16098 | return p; | |
16099 | } | |
16100 | } | |
16101 | ||
16102 | return display_tag_value (tag, p, end); | |
16103 | } | |
16104 | ||
16105 | static unsigned char * | |
16106 | display_gnu_attribute (unsigned char * p, | |
16107 | unsigned char * (* display_proc_gnu_attribute) (unsigned char *, unsigned int, const unsigned char * const), | |
16108 | const unsigned char * const end) | |
16109 | { | |
16110 | unsigned int tag; | |
16111 | unsigned int val; | |
16112 | ||
16113 | READ_ULEB (tag, p, end); | |
16114 | ||
16115 | /* Tag_compatibility is the only generic GNU attribute defined at | |
16116 | present. */ | |
16117 | if (tag == 32) | |
16118 | { | |
16119 | READ_ULEB (val, p, end); | |
16120 | ||
16121 | printf (_("flag = %d, vendor = "), val); | |
16122 | if (p == end) | |
16123 | { | |
16124 | printf (_("<corrupt>\n")); | |
16125 | warn (_("corrupt vendor attribute\n")); | |
16126 | } | |
16127 | else | |
16128 | { | |
16129 | if (p < end - 1) | |
16130 | { | |
16131 | size_t maxlen = (end - p) - 1; | |
16132 | ||
16133 | print_symbol ((int) maxlen, (const char *) p); | |
16134 | p += strnlen ((char *) p, maxlen) + 1; | |
16135 | } | |
16136 | else | |
16137 | { | |
16138 | printf (_("<corrupt>")); | |
16139 | p = (unsigned char *) end; | |
16140 | } | |
16141 | putchar ('\n'); | |
16142 | } | |
16143 | return p; | |
16144 | } | |
16145 | ||
16146 | if ((tag & 2) == 0 && display_proc_gnu_attribute) | |
16147 | return display_proc_gnu_attribute (p, tag, end); | |
16148 | ||
16149 | return display_tag_value (tag, p, end); | |
16150 | } | |
16151 | ||
16152 | static unsigned char * | |
16153 | display_m68k_gnu_attribute (unsigned char * p, | |
16154 | unsigned int tag, | |
16155 | const unsigned char * const end) | |
16156 | { | |
16157 | unsigned int val; | |
16158 | ||
16159 | if (tag == Tag_GNU_M68K_ABI_FP) | |
16160 | { | |
16161 | printf (" Tag_GNU_M68K_ABI_FP: "); | |
16162 | if (p == end) | |
16163 | { | |
16164 | printf (_("<corrupt>\n")); | |
16165 | return p; | |
16166 | } | |
16167 | READ_ULEB (val, p, end); | |
16168 | ||
16169 | if (val > 3) | |
16170 | printf ("(%#x), ", val); | |
16171 | ||
16172 | switch (val & 3) | |
16173 | { | |
16174 | case 0: | |
16175 | printf (_("unspecified hard/soft float\n")); | |
16176 | break; | |
16177 | case 1: | |
16178 | printf (_("hard float\n")); | |
16179 | break; | |
16180 | case 2: | |
16181 | printf (_("soft float\n")); | |
16182 | break; | |
16183 | } | |
16184 | return p; | |
16185 | } | |
16186 | ||
16187 | return display_tag_value (tag & 1, p, end); | |
16188 | } | |
16189 | ||
16190 | static unsigned char * | |
16191 | display_power_gnu_attribute (unsigned char * p, | |
16192 | unsigned int tag, | |
16193 | const unsigned char * const end) | |
16194 | { | |
16195 | unsigned int val; | |
16196 | ||
16197 | if (tag == Tag_GNU_Power_ABI_FP) | |
16198 | { | |
16199 | printf (" Tag_GNU_Power_ABI_FP: "); | |
16200 | if (p == end) | |
16201 | { | |
16202 | printf (_("<corrupt>\n")); | |
16203 | return p; | |
16204 | } | |
16205 | READ_ULEB (val, p, end); | |
16206 | ||
16207 | if (val > 15) | |
16208 | printf ("(%#x), ", val); | |
16209 | ||
16210 | switch (val & 3) | |
16211 | { | |
16212 | case 0: | |
16213 | printf (_("unspecified hard/soft float, ")); | |
16214 | break; | |
16215 | case 1: | |
16216 | printf (_("hard float, ")); | |
16217 | break; | |
16218 | case 2: | |
16219 | printf (_("soft float, ")); | |
16220 | break; | |
16221 | case 3: | |
16222 | printf (_("single-precision hard float, ")); | |
16223 | break; | |
16224 | } | |
16225 | ||
16226 | switch (val & 0xC) | |
16227 | { | |
16228 | case 0: | |
16229 | printf (_("unspecified long double\n")); | |
16230 | break; | |
16231 | case 4: | |
16232 | printf (_("128-bit IBM long double\n")); | |
16233 | break; | |
16234 | case 8: | |
16235 | printf (_("64-bit long double\n")); | |
16236 | break; | |
16237 | case 12: | |
16238 | printf (_("128-bit IEEE long double\n")); | |
16239 | break; | |
16240 | } | |
16241 | return p; | |
16242 | } | |
16243 | ||
16244 | if (tag == Tag_GNU_Power_ABI_Vector) | |
16245 | { | |
16246 | printf (" Tag_GNU_Power_ABI_Vector: "); | |
16247 | if (p == end) | |
16248 | { | |
16249 | printf (_("<corrupt>\n")); | |
16250 | return p; | |
16251 | } | |
16252 | READ_ULEB (val, p, end); | |
16253 | ||
16254 | if (val > 3) | |
16255 | printf ("(%#x), ", val); | |
16256 | ||
16257 | switch (val & 3) | |
16258 | { | |
16259 | case 0: | |
16260 | printf (_("unspecified\n")); | |
16261 | break; | |
16262 | case 1: | |
16263 | printf (_("generic\n")); | |
16264 | break; | |
16265 | case 2: | |
16266 | printf ("AltiVec\n"); | |
16267 | break; | |
16268 | case 3: | |
16269 | printf ("SPE\n"); | |
16270 | break; | |
16271 | } | |
16272 | return p; | |
16273 | } | |
16274 | ||
16275 | if (tag == Tag_GNU_Power_ABI_Struct_Return) | |
16276 | { | |
16277 | printf (" Tag_GNU_Power_ABI_Struct_Return: "); | |
16278 | if (p == end) | |
16279 | { | |
16280 | printf (_("<corrupt>\n")); | |
16281 | return p; | |
16282 | } | |
16283 | READ_ULEB (val, p, end); | |
16284 | ||
16285 | if (val > 2) | |
16286 | printf ("(%#x), ", val); | |
16287 | ||
16288 | switch (val & 3) | |
16289 | { | |
16290 | case 0: | |
16291 | printf (_("unspecified\n")); | |
16292 | break; | |
16293 | case 1: | |
16294 | printf ("r3/r4\n"); | |
16295 | break; | |
16296 | case 2: | |
16297 | printf (_("memory\n")); | |
16298 | break; | |
16299 | case 3: | |
16300 | printf ("???\n"); | |
16301 | break; | |
16302 | } | |
16303 | return p; | |
16304 | } | |
16305 | ||
16306 | return display_tag_value (tag & 1, p, end); | |
16307 | } | |
16308 | ||
16309 | static unsigned char * | |
16310 | display_s390_gnu_attribute (unsigned char * p, | |
16311 | unsigned int tag, | |
16312 | const unsigned char * const end) | |
16313 | { | |
16314 | unsigned int val; | |
16315 | ||
16316 | if (tag == Tag_GNU_S390_ABI_Vector) | |
16317 | { | |
16318 | printf (" Tag_GNU_S390_ABI_Vector: "); | |
16319 | READ_ULEB (val, p, end); | |
16320 | ||
16321 | switch (val) | |
16322 | { | |
16323 | case 0: | |
16324 | printf (_("any\n")); | |
16325 | break; | |
16326 | case 1: | |
16327 | printf (_("software\n")); | |
16328 | break; | |
16329 | case 2: | |
16330 | printf (_("hardware\n")); | |
16331 | break; | |
16332 | default: | |
16333 | printf ("??? (%d)\n", val); | |
16334 | break; | |
16335 | } | |
16336 | return p; | |
16337 | } | |
16338 | ||
16339 | return display_tag_value (tag & 1, p, end); | |
16340 | } | |
16341 | ||
16342 | static void | |
16343 | display_sparc_hwcaps (unsigned int mask) | |
16344 | { | |
16345 | if (mask) | |
16346 | { | |
16347 | bfd_boolean first = TRUE; | |
16348 | ||
16349 | if (mask & ELF_SPARC_HWCAP_MUL32) | |
16350 | fputs ("mul32", stdout), first = FALSE; | |
16351 | if (mask & ELF_SPARC_HWCAP_DIV32) | |
16352 | printf ("%sdiv32", first ? "" : "|"), first = FALSE; | |
16353 | if (mask & ELF_SPARC_HWCAP_FSMULD) | |
16354 | printf ("%sfsmuld", first ? "" : "|"), first = FALSE; | |
16355 | if (mask & ELF_SPARC_HWCAP_V8PLUS) | |
16356 | printf ("%sv8plus", first ? "" : "|"), first = FALSE; | |
16357 | if (mask & ELF_SPARC_HWCAP_POPC) | |
16358 | printf ("%spopc", first ? "" : "|"), first = FALSE; | |
16359 | if (mask & ELF_SPARC_HWCAP_VIS) | |
16360 | printf ("%svis", first ? "" : "|"), first = FALSE; | |
16361 | if (mask & ELF_SPARC_HWCAP_VIS2) | |
16362 | printf ("%svis2", first ? "" : "|"), first = FALSE; | |
16363 | if (mask & ELF_SPARC_HWCAP_ASI_BLK_INIT) | |
16364 | printf ("%sASIBlkInit", first ? "" : "|"), first = FALSE; | |
16365 | if (mask & ELF_SPARC_HWCAP_FMAF) | |
16366 | printf ("%sfmaf", first ? "" : "|"), first = FALSE; | |
16367 | if (mask & ELF_SPARC_HWCAP_VIS3) | |
16368 | printf ("%svis3", first ? "" : "|"), first = FALSE; | |
16369 | if (mask & ELF_SPARC_HWCAP_HPC) | |
16370 | printf ("%shpc", first ? "" : "|"), first = FALSE; | |
16371 | if (mask & ELF_SPARC_HWCAP_RANDOM) | |
16372 | printf ("%srandom", first ? "" : "|"), first = FALSE; | |
16373 | if (mask & ELF_SPARC_HWCAP_TRANS) | |
16374 | printf ("%strans", first ? "" : "|"), first = FALSE; | |
16375 | if (mask & ELF_SPARC_HWCAP_FJFMAU) | |
16376 | printf ("%sfjfmau", first ? "" : "|"), first = FALSE; | |
16377 | if (mask & ELF_SPARC_HWCAP_IMA) | |
16378 | printf ("%sima", first ? "" : "|"), first = FALSE; | |
16379 | if (mask & ELF_SPARC_HWCAP_ASI_CACHE_SPARING) | |
16380 | printf ("%scspare", first ? "" : "|"), first = FALSE; | |
16381 | } | |
16382 | else | |
16383 | fputc ('0', stdout); | |
16384 | fputc ('\n', stdout); | |
16385 | } | |
16386 | ||
16387 | static void | |
16388 | display_sparc_hwcaps2 (unsigned int mask) | |
16389 | { | |
16390 | if (mask) | |
16391 | { | |
16392 | bfd_boolean first = TRUE; | |
16393 | ||
16394 | if (mask & ELF_SPARC_HWCAP2_FJATHPLUS) | |
16395 | fputs ("fjathplus", stdout), first = FALSE; | |
16396 | if (mask & ELF_SPARC_HWCAP2_VIS3B) | |
16397 | printf ("%svis3b", first ? "" : "|"), first = FALSE; | |
16398 | if (mask & ELF_SPARC_HWCAP2_ADP) | |
16399 | printf ("%sadp", first ? "" : "|"), first = FALSE; | |
16400 | if (mask & ELF_SPARC_HWCAP2_SPARC5) | |
16401 | printf ("%ssparc5", first ? "" : "|"), first = FALSE; | |
16402 | if (mask & ELF_SPARC_HWCAP2_MWAIT) | |
16403 | printf ("%smwait", first ? "" : "|"), first = FALSE; | |
16404 | if (mask & ELF_SPARC_HWCAP2_XMPMUL) | |
16405 | printf ("%sxmpmul", first ? "" : "|"), first = FALSE; | |
16406 | if (mask & ELF_SPARC_HWCAP2_XMONT) | |
16407 | printf ("%sxmont2", first ? "" : "|"), first = FALSE; | |
16408 | if (mask & ELF_SPARC_HWCAP2_NSEC) | |
16409 | printf ("%snsec", first ? "" : "|"), first = FALSE; | |
16410 | if (mask & ELF_SPARC_HWCAP2_FJATHHPC) | |
16411 | printf ("%sfjathhpc", first ? "" : "|"), first = FALSE; | |
16412 | if (mask & ELF_SPARC_HWCAP2_FJDES) | |
16413 | printf ("%sfjdes", first ? "" : "|"), first = FALSE; | |
16414 | if (mask & ELF_SPARC_HWCAP2_FJAES) | |
16415 | printf ("%sfjaes", first ? "" : "|"), first = FALSE; | |
16416 | } | |
16417 | else | |
16418 | fputc ('0', stdout); | |
16419 | fputc ('\n', stdout); | |
16420 | } | |
16421 | ||
16422 | static unsigned char * | |
16423 | display_sparc_gnu_attribute (unsigned char * p, | |
16424 | unsigned int tag, | |
16425 | const unsigned char * const end) | |
16426 | { | |
16427 | unsigned int val; | |
16428 | ||
16429 | if (tag == Tag_GNU_Sparc_HWCAPS) | |
16430 | { | |
16431 | READ_ULEB (val, p, end); | |
16432 | printf (" Tag_GNU_Sparc_HWCAPS: "); | |
16433 | display_sparc_hwcaps (val); | |
16434 | return p; | |
16435 | } | |
16436 | if (tag == Tag_GNU_Sparc_HWCAPS2) | |
16437 | { | |
16438 | READ_ULEB (val, p, end); | |
16439 | printf (" Tag_GNU_Sparc_HWCAPS2: "); | |
16440 | display_sparc_hwcaps2 (val); | |
16441 | return p; | |
16442 | } | |
16443 | ||
16444 | return display_tag_value (tag, p, end); | |
16445 | } | |
16446 | ||
16447 | static void | |
16448 | print_mips_fp_abi_value (unsigned int val) | |
16449 | { | |
16450 | switch (val) | |
16451 | { | |
16452 | case Val_GNU_MIPS_ABI_FP_ANY: | |
16453 | printf (_("Hard or soft float\n")); | |
16454 | break; | |
16455 | case Val_GNU_MIPS_ABI_FP_DOUBLE: | |
16456 | printf (_("Hard float (double precision)\n")); | |
16457 | break; | |
16458 | case Val_GNU_MIPS_ABI_FP_SINGLE: | |
16459 | printf (_("Hard float (single precision)\n")); | |
16460 | break; | |
16461 | case Val_GNU_MIPS_ABI_FP_SOFT: | |
16462 | printf (_("Soft float\n")); | |
16463 | break; | |
16464 | case Val_GNU_MIPS_ABI_FP_OLD_64: | |
16465 | printf (_("Hard float (MIPS32r2 64-bit FPU 12 callee-saved)\n")); | |
16466 | break; | |
16467 | case Val_GNU_MIPS_ABI_FP_XX: | |
16468 | printf (_("Hard float (32-bit CPU, Any FPU)\n")); | |
16469 | break; | |
16470 | case Val_GNU_MIPS_ABI_FP_64: | |
16471 | printf (_("Hard float (32-bit CPU, 64-bit FPU)\n")); | |
16472 | break; | |
16473 | case Val_GNU_MIPS_ABI_FP_64A: | |
16474 | printf (_("Hard float compat (32-bit CPU, 64-bit FPU)\n")); | |
16475 | break; | |
16476 | case Val_GNU_MIPS_ABI_FP_NAN2008: | |
16477 | printf (_("NaN 2008 compatibility\n")); | |
16478 | break; | |
16479 | default: | |
16480 | printf ("??? (%d)\n", val); | |
16481 | break; | |
16482 | } | |
16483 | } | |
16484 | ||
16485 | static unsigned char * | |
16486 | display_mips_gnu_attribute (unsigned char * p, | |
16487 | unsigned int tag, | |
16488 | const unsigned char * const end) | |
16489 | { | |
16490 | if (tag == Tag_GNU_MIPS_ABI_FP) | |
16491 | { | |
16492 | unsigned int val; | |
16493 | ||
16494 | printf (" Tag_GNU_MIPS_ABI_FP: "); | |
16495 | READ_ULEB (val, p, end); | |
16496 | print_mips_fp_abi_value (val); | |
16497 | return p; | |
16498 | } | |
16499 | ||
16500 | if (tag == Tag_GNU_MIPS_ABI_MSA) | |
16501 | { | |
16502 | unsigned int val; | |
16503 | ||
16504 | printf (" Tag_GNU_MIPS_ABI_MSA: "); | |
16505 | READ_ULEB (val, p, end); | |
16506 | ||
16507 | switch (val) | |
16508 | { | |
16509 | case Val_GNU_MIPS_ABI_MSA_ANY: | |
16510 | printf (_("Any MSA or not\n")); | |
16511 | break; | |
16512 | case Val_GNU_MIPS_ABI_MSA_128: | |
16513 | printf (_("128-bit MSA\n")); | |
16514 | break; | |
16515 | default: | |
16516 | printf ("??? (%d)\n", val); | |
16517 | break; | |
16518 | } | |
16519 | return p; | |
16520 | } | |
16521 | ||
16522 | return display_tag_value (tag & 1, p, end); | |
16523 | } | |
16524 | ||
16525 | static unsigned char * | |
16526 | display_tic6x_attribute (unsigned char * p, | |
16527 | const unsigned char * const end) | |
16528 | { | |
16529 | unsigned int tag; | |
16530 | unsigned int val; | |
16531 | ||
16532 | READ_ULEB (tag, p, end); | |
16533 | ||
16534 | switch (tag) | |
16535 | { | |
16536 | case Tag_ISA: | |
16537 | printf (" Tag_ISA: "); | |
16538 | READ_ULEB (val, p, end); | |
16539 | ||
16540 | switch (val) | |
16541 | { | |
16542 | case C6XABI_Tag_ISA_none: | |
16543 | printf (_("None\n")); | |
16544 | break; | |
16545 | case C6XABI_Tag_ISA_C62X: | |
16546 | printf ("C62x\n"); | |
16547 | break; | |
16548 | case C6XABI_Tag_ISA_C67X: | |
16549 | printf ("C67x\n"); | |
16550 | break; | |
16551 | case C6XABI_Tag_ISA_C67XP: | |
16552 | printf ("C67x+\n"); | |
16553 | break; | |
16554 | case C6XABI_Tag_ISA_C64X: | |
16555 | printf ("C64x\n"); | |
16556 | break; | |
16557 | case C6XABI_Tag_ISA_C64XP: | |
16558 | printf ("C64x+\n"); | |
16559 | break; | |
16560 | case C6XABI_Tag_ISA_C674X: | |
16561 | printf ("C674x\n"); | |
16562 | break; | |
16563 | default: | |
16564 | printf ("??? (%d)\n", val); | |
16565 | break; | |
16566 | } | |
16567 | return p; | |
16568 | ||
16569 | case Tag_ABI_wchar_t: | |
16570 | printf (" Tag_ABI_wchar_t: "); | |
16571 | READ_ULEB (val, p, end); | |
16572 | switch (val) | |
16573 | { | |
16574 | case 0: | |
16575 | printf (_("Not used\n")); | |
16576 | break; | |
16577 | case 1: | |
16578 | printf (_("2 bytes\n")); | |
16579 | break; | |
16580 | case 2: | |
16581 | printf (_("4 bytes\n")); | |
16582 | break; | |
16583 | default: | |
16584 | printf ("??? (%d)\n", val); | |
16585 | break; | |
16586 | } | |
16587 | return p; | |
16588 | ||
16589 | case Tag_ABI_stack_align_needed: | |
16590 | printf (" Tag_ABI_stack_align_needed: "); | |
16591 | READ_ULEB (val, p, end); | |
16592 | switch (val) | |
16593 | { | |
16594 | case 0: | |
16595 | printf (_("8-byte\n")); | |
16596 | break; | |
16597 | case 1: | |
16598 | printf (_("16-byte\n")); | |
16599 | break; | |
16600 | default: | |
16601 | printf ("??? (%d)\n", val); | |
16602 | break; | |
16603 | } | |
16604 | return p; | |
16605 | ||
16606 | case Tag_ABI_stack_align_preserved: | |
16607 | READ_ULEB (val, p, end); | |
16608 | printf (" Tag_ABI_stack_align_preserved: "); | |
16609 | switch (val) | |
16610 | { | |
16611 | case 0: | |
16612 | printf (_("8-byte\n")); | |
16613 | break; | |
16614 | case 1: | |
16615 | printf (_("16-byte\n")); | |
16616 | break; | |
16617 | default: | |
16618 | printf ("??? (%d)\n", val); | |
16619 | break; | |
16620 | } | |
16621 | return p; | |
16622 | ||
16623 | case Tag_ABI_DSBT: | |
16624 | READ_ULEB (val, p, end); | |
16625 | printf (" Tag_ABI_DSBT: "); | |
16626 | switch (val) | |
16627 | { | |
16628 | case 0: | |
16629 | printf (_("DSBT addressing not used\n")); | |
16630 | break; | |
16631 | case 1: | |
16632 | printf (_("DSBT addressing used\n")); | |
16633 | break; | |
16634 | default: | |
16635 | printf ("??? (%d)\n", val); | |
16636 | break; | |
16637 | } | |
16638 | return p; | |
16639 | ||
16640 | case Tag_ABI_PID: | |
16641 | READ_ULEB (val, p, end); | |
16642 | printf (" Tag_ABI_PID: "); | |
16643 | switch (val) | |
16644 | { | |
16645 | case 0: | |
16646 | printf (_("Data addressing position-dependent\n")); | |
16647 | break; | |
16648 | case 1: | |
16649 | printf (_("Data addressing position-independent, GOT near DP\n")); | |
16650 | break; | |
16651 | case 2: | |
16652 | printf (_("Data addressing position-independent, GOT far from DP\n")); | |
16653 | break; | |
16654 | default: | |
16655 | printf ("??? (%d)\n", val); | |
16656 | break; | |
16657 | } | |
16658 | return p; | |
16659 | ||
16660 | case Tag_ABI_PIC: | |
16661 | READ_ULEB (val, p, end); | |
16662 | printf (" Tag_ABI_PIC: "); | |
16663 | switch (val) | |
16664 | { | |
16665 | case 0: | |
16666 | printf (_("Code addressing position-dependent\n")); | |
16667 | break; | |
16668 | case 1: | |
16669 | printf (_("Code addressing position-independent\n")); | |
16670 | break; | |
16671 | default: | |
16672 | printf ("??? (%d)\n", val); | |
16673 | break; | |
16674 | } | |
16675 | return p; | |
16676 | ||
16677 | case Tag_ABI_array_object_alignment: | |
16678 | READ_ULEB (val, p, end); | |
16679 | printf (" Tag_ABI_array_object_alignment: "); | |
16680 | switch (val) | |
16681 | { | |
16682 | case 0: | |
16683 | printf (_("8-byte\n")); | |
16684 | break; | |
16685 | case 1: | |
16686 | printf (_("4-byte\n")); | |
16687 | break; | |
16688 | case 2: | |
16689 | printf (_("16-byte\n")); | |
16690 | break; | |
16691 | default: | |
16692 | printf ("??? (%d)\n", val); | |
16693 | break; | |
16694 | } | |
16695 | return p; | |
16696 | ||
16697 | case Tag_ABI_array_object_align_expected: | |
16698 | READ_ULEB (val, p, end); | |
16699 | printf (" Tag_ABI_array_object_align_expected: "); | |
16700 | switch (val) | |
16701 | { | |
16702 | case 0: | |
16703 | printf (_("8-byte\n")); | |
16704 | break; | |
16705 | case 1: | |
16706 | printf (_("4-byte\n")); | |
16707 | break; | |
16708 | case 2: | |
16709 | printf (_("16-byte\n")); | |
16710 | break; | |
16711 | default: | |
16712 | printf ("??? (%d)\n", val); | |
16713 | break; | |
16714 | } | |
16715 | return p; | |
16716 | ||
16717 | case Tag_ABI_compatibility: | |
16718 | { | |
16719 | READ_ULEB (val, p, end); | |
16720 | printf (" Tag_ABI_compatibility: "); | |
16721 | printf (_("flag = %d, vendor = "), val); | |
16722 | if (p < end - 1) | |
16723 | { | |
16724 | size_t maxlen = (end - p) - 1; | |
16725 | ||
16726 | print_symbol ((int) maxlen, (const char *) p); | |
16727 | p += strnlen ((char *) p, maxlen) + 1; | |
16728 | } | |
16729 | else | |
16730 | { | |
16731 | printf (_("<corrupt>")); | |
16732 | p = (unsigned char *) end; | |
16733 | } | |
16734 | putchar ('\n'); | |
16735 | return p; | |
16736 | } | |
16737 | ||
16738 | case Tag_ABI_conformance: | |
16739 | { | |
16740 | printf (" Tag_ABI_conformance: \""); | |
16741 | if (p < end - 1) | |
16742 | { | |
16743 | size_t maxlen = (end - p) - 1; | |
16744 | ||
16745 | print_symbol ((int) maxlen, (const char *) p); | |
16746 | p += strnlen ((char *) p, maxlen) + 1; | |
16747 | } | |
16748 | else | |
16749 | { | |
16750 | printf (_("<corrupt>")); | |
16751 | p = (unsigned char *) end; | |
16752 | } | |
16753 | printf ("\"\n"); | |
16754 | return p; | |
16755 | } | |
16756 | } | |
16757 | ||
16758 | return display_tag_value (tag, p, end); | |
16759 | } | |
16760 | ||
16761 | static void | |
16762 | display_raw_attribute (unsigned char * p, unsigned char const * const end) | |
16763 | { | |
16764 | unsigned long addr = 0; | |
16765 | size_t bytes = end - p; | |
16766 | ||
16767 | assert (end >= p); | |
16768 | while (bytes) | |
16769 | { | |
16770 | int j; | |
16771 | int k; | |
16772 | int lbytes = (bytes > 16 ? 16 : bytes); | |
16773 | ||
16774 | printf (" 0x%8.8lx ", addr); | |
16775 | ||
16776 | for (j = 0; j < 16; j++) | |
16777 | { | |
16778 | if (j < lbytes) | |
16779 | printf ("%2.2x", p[j]); | |
16780 | else | |
16781 | printf (" "); | |
16782 | ||
16783 | if ((j & 3) == 3) | |
16784 | printf (" "); | |
16785 | } | |
16786 | ||
16787 | for (j = 0; j < lbytes; j++) | |
16788 | { | |
16789 | k = p[j]; | |
16790 | if (k >= ' ' && k < 0x7f) | |
16791 | printf ("%c", k); | |
16792 | else | |
16793 | printf ("."); | |
16794 | } | |
16795 | ||
16796 | putchar ('\n'); | |
16797 | ||
16798 | p += lbytes; | |
16799 | bytes -= lbytes; | |
16800 | addr += lbytes; | |
16801 | } | |
16802 | ||
16803 | putchar ('\n'); | |
16804 | } | |
16805 | ||
16806 | static unsigned char * | |
16807 | display_msp430_attribute (unsigned char * p, | |
16808 | const unsigned char * const end) | |
16809 | { | |
16810 | unsigned int val; | |
16811 | unsigned int tag; | |
16812 | ||
16813 | READ_ULEB (tag, p, end); | |
16814 | ||
16815 | switch (tag) | |
16816 | { | |
16817 | case OFBA_MSPABI_Tag_ISA: | |
16818 | printf (" Tag_ISA: "); | |
16819 | READ_ULEB (val, p, end); | |
16820 | switch (val) | |
16821 | { | |
16822 | case 0: printf (_("None\n")); break; | |
16823 | case 1: printf (_("MSP430\n")); break; | |
16824 | case 2: printf (_("MSP430X\n")); break; | |
16825 | default: printf ("??? (%d)\n", val); break; | |
16826 | } | |
16827 | break; | |
16828 | ||
16829 | case OFBA_MSPABI_Tag_Code_Model: | |
16830 | printf (" Tag_Code_Model: "); | |
16831 | READ_ULEB (val, p, end); | |
16832 | switch (val) | |
16833 | { | |
16834 | case 0: printf (_("None\n")); break; | |
16835 | case 1: printf (_("Small\n")); break; | |
16836 | case 2: printf (_("Large\n")); break; | |
16837 | default: printf ("??? (%d)\n", val); break; | |
16838 | } | |
16839 | break; | |
16840 | ||
16841 | case OFBA_MSPABI_Tag_Data_Model: | |
16842 | printf (" Tag_Data_Model: "); | |
16843 | READ_ULEB (val, p, end); | |
16844 | switch (val) | |
16845 | { | |
16846 | case 0: printf (_("None\n")); break; | |
16847 | case 1: printf (_("Small\n")); break; | |
16848 | case 2: printf (_("Large\n")); break; | |
16849 | case 3: printf (_("Restricted Large\n")); break; | |
16850 | default: printf ("??? (%d)\n", val); break; | |
16851 | } | |
16852 | break; | |
16853 | ||
16854 | default: | |
16855 | printf (_(" <unknown tag %d>: "), tag); | |
16856 | ||
16857 | if (tag & 1) | |
16858 | { | |
16859 | putchar ('"'); | |
16860 | if (p < end - 1) | |
16861 | { | |
16862 | size_t maxlen = (end - p) - 1; | |
16863 | ||
16864 | print_symbol ((int) maxlen, (const char *) p); | |
16865 | p += strnlen ((char *) p, maxlen) + 1; | |
16866 | } | |
16867 | else | |
16868 | { | |
16869 | printf (_("<corrupt>")); | |
16870 | p = (unsigned char *) end; | |
16871 | } | |
16872 | printf ("\"\n"); | |
16873 | } | |
16874 | else | |
16875 | { | |
16876 | READ_ULEB (val, p, end); | |
16877 | printf ("%d (0x%x)\n", val, val); | |
16878 | } | |
16879 | break; | |
16880 | } | |
16881 | ||
16882 | assert (p <= end); | |
16883 | return p; | |
16884 | } | |
16885 | ||
16886 | static unsigned char * | |
16887 | display_msp430_gnu_attribute (unsigned char * p, | |
16888 | unsigned int tag, | |
16889 | const unsigned char * const end) | |
16890 | { | |
16891 | if (tag == Tag_GNU_MSP430_Data_Region) | |
16892 | { | |
16893 | unsigned int val; | |
16894 | ||
16895 | printf (" Tag_GNU_MSP430_Data_Region: "); | |
16896 | READ_ULEB (val, p, end); | |
16897 | ||
16898 | switch (val) | |
16899 | { | |
16900 | case Val_GNU_MSP430_Data_Region_Any: | |
16901 | printf (_("Any Region\n")); | |
16902 | break; | |
16903 | case Val_GNU_MSP430_Data_Region_Lower: | |
16904 | printf (_("Lower Region Only\n")); | |
16905 | break; | |
16906 | default: | |
16907 | printf ("??? (%u)\n", val); | |
16908 | } | |
16909 | return p; | |
16910 | } | |
16911 | return display_tag_value (tag & 1, p, end); | |
16912 | } | |
16913 | ||
16914 | struct riscv_attr_tag_t { | |
16915 | const char *name; | |
16916 | unsigned int tag; | |
16917 | }; | |
16918 | ||
16919 | static struct riscv_attr_tag_t riscv_attr_tag[] = | |
16920 | { | |
16921 | #define T(tag) {"Tag_RISCV_" #tag, Tag_RISCV_##tag} | |
16922 | T(arch), | |
16923 | T(priv_spec), | |
16924 | T(priv_spec_minor), | |
16925 | T(priv_spec_revision), | |
16926 | T(unaligned_access), | |
16927 | T(stack_align), | |
16928 | #undef T | |
16929 | }; | |
16930 | ||
16931 | static unsigned char * | |
16932 | display_riscv_attribute (unsigned char *p, | |
16933 | const unsigned char * const end) | |
16934 | { | |
16935 | unsigned int val; | |
16936 | unsigned int tag; | |
16937 | struct riscv_attr_tag_t *attr = NULL; | |
16938 | unsigned i; | |
16939 | ||
16940 | READ_ULEB (tag, p, end); | |
16941 | ||
16942 | /* Find the name of attribute. */ | |
16943 | for (i = 0; i < ARRAY_SIZE (riscv_attr_tag); i++) | |
16944 | { | |
16945 | if (riscv_attr_tag[i].tag == tag) | |
16946 | { | |
16947 | attr = &riscv_attr_tag[i]; | |
16948 | break; | |
16949 | } | |
16950 | } | |
16951 | ||
16952 | if (attr) | |
16953 | printf (" %s: ", attr->name); | |
16954 | else | |
16955 | return display_tag_value (tag, p, end); | |
16956 | ||
16957 | switch (tag) | |
16958 | { | |
16959 | case Tag_RISCV_priv_spec: | |
16960 | case Tag_RISCV_priv_spec_minor: | |
16961 | case Tag_RISCV_priv_spec_revision: | |
16962 | READ_ULEB (val, p, end); | |
16963 | printf (_("%u\n"), val); | |
16964 | break; | |
16965 | case Tag_RISCV_unaligned_access: | |
16966 | READ_ULEB (val, p, end); | |
16967 | switch (val) | |
16968 | { | |
16969 | case 0: | |
16970 | printf (_("No unaligned access\n")); | |
16971 | break; | |
16972 | case 1: | |
16973 | printf (_("Unaligned access\n")); | |
16974 | break; | |
16975 | } | |
16976 | break; | |
16977 | case Tag_RISCV_stack_align: | |
16978 | READ_ULEB (val, p, end); | |
16979 | printf (_("%u-bytes\n"), val); | |
16980 | break; | |
16981 | case Tag_RISCV_arch: | |
16982 | p = display_tag_value (-1, p, end); | |
16983 | break; | |
16984 | default: | |
16985 | return display_tag_value (tag, p, end); | |
16986 | } | |
16987 | ||
16988 | return p; | |
16989 | } | |
16990 | ||
16991 | static unsigned char * | |
16992 | display_csky_attribute (unsigned char * p, | |
16993 | const unsigned char * const end) | |
16994 | { | |
16995 | unsigned int tag; | |
16996 | unsigned int val; | |
16997 | READ_ULEB (tag, p, end); | |
16998 | ||
16999 | if (tag >= Tag_CSKY_MAX) | |
17000 | { | |
17001 | return display_tag_value (-1, p, end); | |
17002 | } | |
17003 | ||
17004 | switch (tag) | |
17005 | { | |
17006 | case Tag_CSKY_ARCH_NAME: | |
17007 | printf (" Tag_CSKY_ARCH_NAME:\t\t"); | |
17008 | return display_tag_value (-1, p, end); | |
17009 | case Tag_CSKY_CPU_NAME: | |
17010 | printf (" Tag_CSKY_CPU_NAME:\t\t"); | |
17011 | return display_tag_value (-1, p, end); | |
17012 | ||
17013 | case Tag_CSKY_ISA_FLAGS: | |
17014 | printf (" Tag_CSKY_ISA_FLAGS:\t\t"); | |
17015 | return display_tag_value (0, p, end); | |
17016 | case Tag_CSKY_ISA_EXT_FLAGS: | |
17017 | printf (" Tag_CSKY_ISA_EXT_FLAGS:\t"); | |
17018 | return display_tag_value (0, p, end); | |
17019 | ||
17020 | case Tag_CSKY_DSP_VERSION: | |
17021 | printf (" Tag_CSKY_DSP_VERSION:\t\t"); | |
17022 | READ_ULEB (val, p, end); | |
17023 | if (val == VAL_CSKY_DSP_VERSION_EXTENSION) | |
17024 | printf ("DSP Extension\n"); | |
17025 | else if (val == VAL_CSKY_DSP_VERSION_2) | |
17026 | printf ("DSP 2.0\n"); | |
17027 | break; | |
17028 | ||
17029 | case Tag_CSKY_VDSP_VERSION: | |
17030 | printf (" Tag_CSKY_VDSP_VERSION:\t"); | |
17031 | READ_ULEB (val, p, end); | |
17032 | printf ("VDSP Version %d\n", val); | |
17033 | break; | |
17034 | ||
17035 | case Tag_CSKY_FPU_VERSION: | |
17036 | printf (" Tag_CSKY_FPU_VERSION:\t\t"); | |
17037 | READ_ULEB (val, p, end); | |
17038 | if (val == VAL_CSKY_FPU_VERSION_1) | |
17039 | printf ("ABIV1 FPU Version 1\n"); | |
17040 | else if (val == VAL_CSKY_FPU_VERSION_2) | |
17041 | printf ("FPU Version 2\n"); | |
17042 | break; | |
17043 | ||
17044 | case Tag_CSKY_FPU_ABI: | |
17045 | printf (" Tag_CSKY_FPU_ABI:\t\t"); | |
17046 | READ_ULEB (val, p, end); | |
17047 | if (val == VAL_CSKY_FPU_ABI_HARD) | |
17048 | printf ("Hard\n"); | |
17049 | else if (val == VAL_CSKY_FPU_ABI_SOFTFP) | |
17050 | printf ("SoftFP\n"); | |
17051 | else if (val == VAL_CSKY_FPU_ABI_SOFT) | |
17052 | printf ("Soft\n"); | |
17053 | break; | |
17054 | case Tag_CSKY_FPU_ROUNDING: | |
17055 | READ_ULEB (val, p, end); | |
17056 | if (val == 1) { | |
17057 | printf (" Tag_CSKY_FPU_ROUNDING:\t"); | |
17058 | printf ("Needed\n"); | |
17059 | } | |
17060 | break; | |
17061 | case Tag_CSKY_FPU_DENORMAL: | |
17062 | READ_ULEB (val, p, end); | |
17063 | if (val == 1) { | |
17064 | printf (" Tag_CSKY_FPU_DENORMAL:\t"); | |
17065 | printf ("Needed\n"); | |
17066 | } | |
17067 | break; | |
17068 | case Tag_CSKY_FPU_Exception: | |
17069 | READ_ULEB (val, p, end); | |
17070 | if (val == 1) { | |
17071 | printf (" Tag_CSKY_FPU_Exception:\t"); | |
17072 | printf ("Needed\n"); | |
17073 | } | |
17074 | break; | |
17075 | case Tag_CSKY_FPU_NUMBER_MODULE: | |
17076 | printf (" Tag_CSKY_FPU_NUMBER_MODULE:\t"); | |
17077 | return display_tag_value (-1, p, end); | |
17078 | case Tag_CSKY_FPU_HARDFP: | |
17079 | printf (" Tag_CSKY_FPU_HARDFP:\t\t"); | |
17080 | READ_ULEB (val, p, end); | |
17081 | if (val & VAL_CSKY_FPU_HARDFP_HALF) | |
17082 | printf (" Half"); | |
17083 | if (val & VAL_CSKY_FPU_HARDFP_SINGLE) | |
17084 | printf (" Single"); | |
17085 | if (val & VAL_CSKY_FPU_HARDFP_DOUBLE) | |
17086 | printf (" Double"); | |
17087 | printf ("\n"); | |
17088 | break; | |
17089 | default: | |
17090 | return display_tag_value (tag, p, end); | |
17091 | } | |
17092 | return p; | |
17093 | } | |
17094 | ||
17095 | static bfd_boolean | |
17096 | process_attributes (Filedata * filedata, | |
17097 | const char * public_name, | |
17098 | unsigned int proc_type, | |
17099 | unsigned char * (* display_pub_attribute) (unsigned char *, const unsigned char * const), | |
17100 | unsigned char * (* display_proc_gnu_attribute) (unsigned char *, unsigned int, const unsigned char * const)) | |
17101 | { | |
17102 | Elf_Internal_Shdr * sect; | |
17103 | unsigned i; | |
17104 | bfd_boolean res = TRUE; | |
17105 | ||
17106 | /* Find the section header so that we get the size. */ | |
17107 | for (i = 0, sect = filedata->section_headers; | |
17108 | i < filedata->file_header.e_shnum; | |
17109 | i++, sect++) | |
17110 | { | |
17111 | unsigned char * contents; | |
17112 | unsigned char * p; | |
17113 | ||
17114 | if (sect->sh_type != proc_type && sect->sh_type != SHT_GNU_ATTRIBUTES) | |
17115 | continue; | |
17116 | ||
17117 | contents = (unsigned char *) get_data (NULL, filedata, sect->sh_offset, 1, | |
17118 | sect->sh_size, _("attributes")); | |
17119 | if (contents == NULL) | |
17120 | { | |
17121 | res = FALSE; | |
17122 | continue; | |
17123 | } | |
17124 | ||
17125 | p = contents; | |
17126 | /* The first character is the version of the attributes. | |
17127 | Currently only version 1, (aka 'A') is recognised here. */ | |
17128 | if (*p != 'A') | |
17129 | { | |
17130 | printf (_("Unknown attributes version '%c'(%d) - expecting 'A'\n"), *p, *p); | |
17131 | res = FALSE; | |
17132 | } | |
17133 | else | |
17134 | { | |
17135 | bfd_vma section_len; | |
17136 | ||
17137 | section_len = sect->sh_size - 1; | |
17138 | p++; | |
17139 | ||
17140 | while (section_len > 0) | |
17141 | { | |
17142 | bfd_vma attr_len; | |
17143 | unsigned int namelen; | |
17144 | bfd_boolean public_section; | |
17145 | bfd_boolean gnu_section; | |
17146 | ||
17147 | if (section_len <= 4) | |
17148 | { | |
17149 | error (_("Tag section ends prematurely\n")); | |
17150 | res = FALSE; | |
17151 | break; | |
17152 | } | |
17153 | attr_len = byte_get (p, 4); | |
17154 | p += 4; | |
17155 | ||
17156 | if (attr_len > section_len) | |
17157 | { | |
17158 | error (_("Bad attribute length (%u > %u)\n"), | |
17159 | (unsigned) attr_len, (unsigned) section_len); | |
17160 | attr_len = section_len; | |
17161 | res = FALSE; | |
17162 | } | |
17163 | /* PR 17531: file: 001-101425-0.004 */ | |
17164 | else if (attr_len < 5) | |
17165 | { | |
17166 | error (_("Attribute length of %u is too small\n"), (unsigned) attr_len); | |
17167 | res = FALSE; | |
17168 | break; | |
17169 | } | |
17170 | ||
17171 | section_len -= attr_len; | |
17172 | attr_len -= 4; | |
17173 | ||
17174 | namelen = strnlen ((char *) p, attr_len) + 1; | |
17175 | if (namelen == 0 || namelen >= attr_len) | |
17176 | { | |
17177 | error (_("Corrupt attribute section name\n")); | |
17178 | res = FALSE; | |
17179 | break; | |
17180 | } | |
17181 | ||
17182 | printf (_("Attribute Section: ")); | |
17183 | print_symbol (INT_MAX, (const char *) p); | |
17184 | putchar ('\n'); | |
17185 | ||
17186 | if (public_name && streq ((char *) p, public_name)) | |
17187 | public_section = TRUE; | |
17188 | else | |
17189 | public_section = FALSE; | |
17190 | ||
17191 | if (streq ((char *) p, "gnu")) | |
17192 | gnu_section = TRUE; | |
17193 | else | |
17194 | gnu_section = FALSE; | |
17195 | ||
17196 | p += namelen; | |
17197 | attr_len -= namelen; | |
17198 | ||
17199 | while (attr_len > 0 && p < contents + sect->sh_size) | |
17200 | { | |
17201 | int tag; | |
17202 | unsigned int val; | |
17203 | bfd_vma size; | |
17204 | unsigned char * end; | |
17205 | ||
17206 | /* PR binutils/17531: Safe handling of corrupt files. */ | |
17207 | if (attr_len < 6) | |
17208 | { | |
17209 | error (_("Unused bytes at end of section\n")); | |
17210 | res = FALSE; | |
17211 | section_len = 0; | |
17212 | break; | |
17213 | } | |
17214 | ||
17215 | tag = *(p++); | |
17216 | size = byte_get (p, 4); | |
17217 | if (size > attr_len) | |
17218 | { | |
17219 | error (_("Bad subsection length (%u > %u)\n"), | |
17220 | (unsigned) size, (unsigned) attr_len); | |
17221 | res = FALSE; | |
17222 | size = attr_len; | |
17223 | } | |
17224 | /* PR binutils/17531: Safe handling of corrupt files. */ | |
17225 | if (size < 6) | |
17226 | { | |
17227 | error (_("Bad subsection length (%u < 6)\n"), | |
17228 | (unsigned) size); | |
17229 | res = FALSE; | |
17230 | section_len = 0; | |
17231 | break; | |
17232 | } | |
17233 | ||
17234 | attr_len -= size; | |
17235 | end = p + size - 1; | |
17236 | assert (end <= contents + sect->sh_size); | |
17237 | p += 4; | |
17238 | ||
17239 | switch (tag) | |
17240 | { | |
17241 | case 1: | |
17242 | printf (_("File Attributes\n")); | |
17243 | break; | |
17244 | case 2: | |
17245 | printf (_("Section Attributes:")); | |
17246 | goto do_numlist; | |
17247 | case 3: | |
17248 | printf (_("Symbol Attributes:")); | |
17249 | /* Fall through. */ | |
17250 | do_numlist: | |
17251 | for (;;) | |
17252 | { | |
17253 | READ_ULEB (val, p, end); | |
17254 | if (val == 0) | |
17255 | break; | |
17256 | printf (" %d", val); | |
17257 | } | |
17258 | printf ("\n"); | |
17259 | break; | |
17260 | default: | |
17261 | printf (_("Unknown tag: %d\n"), tag); | |
17262 | public_section = FALSE; | |
17263 | break; | |
17264 | } | |
17265 | ||
17266 | if (public_section && display_pub_attribute != NULL) | |
17267 | { | |
17268 | while (p < end) | |
17269 | p = display_pub_attribute (p, end); | |
17270 | assert (p == end); | |
17271 | } | |
17272 | else if (gnu_section && display_proc_gnu_attribute != NULL) | |
17273 | { | |
17274 | while (p < end) | |
17275 | p = display_gnu_attribute (p, | |
17276 | display_proc_gnu_attribute, | |
17277 | end); | |
17278 | assert (p == end); | |
17279 | } | |
17280 | else if (p < end) | |
17281 | { | |
17282 | printf (_(" Unknown attribute:\n")); | |
17283 | display_raw_attribute (p, end); | |
17284 | p = end; | |
17285 | } | |
17286 | else | |
17287 | attr_len = 0; | |
17288 | } | |
17289 | } | |
17290 | } | |
17291 | ||
17292 | free (contents); | |
17293 | } | |
17294 | ||
17295 | return res; | |
17296 | } | |
17297 | ||
17298 | /* DATA points to the contents of a MIPS GOT that starts at VMA PLTGOT. | |
17299 | Print the Address, Access and Initial fields of an entry at VMA ADDR | |
17300 | and return the VMA of the next entry, or -1 if there was a problem. | |
17301 | Does not read from DATA_END or beyond. */ | |
17302 | ||
17303 | static bfd_vma | |
17304 | print_mips_got_entry (unsigned char * data, bfd_vma pltgot, bfd_vma addr, | |
17305 | unsigned char * data_end) | |
17306 | { | |
17307 | printf (" "); | |
17308 | print_vma (addr, LONG_HEX); | |
17309 | printf (" "); | |
17310 | if (addr < pltgot + 0xfff0) | |
17311 | printf ("%6d(gp)", (int) (addr - pltgot - 0x7ff0)); | |
17312 | else | |
17313 | printf ("%10s", ""); | |
17314 | printf (" "); | |
17315 | if (data == NULL) | |
17316 | printf ("%*s", is_32bit_elf ? 8 : 16, _("<unknown>")); | |
17317 | else | |
17318 | { | |
17319 | bfd_vma entry; | |
17320 | unsigned char * from = data + addr - pltgot; | |
17321 | ||
17322 | if (from + (is_32bit_elf ? 4 : 8) > data_end) | |
17323 | { | |
17324 | warn (_("MIPS GOT entry extends beyond the end of available data\n")); | |
17325 | printf ("%*s", is_32bit_elf ? 8 : 16, _("<corrupt>")); | |
17326 | return (bfd_vma) -1; | |
17327 | } | |
17328 | else | |
17329 | { | |
17330 | entry = byte_get (data + addr - pltgot, is_32bit_elf ? 4 : 8); | |
17331 | print_vma (entry, LONG_HEX); | |
17332 | } | |
17333 | } | |
17334 | return addr + (is_32bit_elf ? 4 : 8); | |
17335 | } | |
17336 | ||
17337 | /* DATA points to the contents of a MIPS PLT GOT that starts at VMA | |
17338 | PLTGOT. Print the Address and Initial fields of an entry at VMA | |
17339 | ADDR and return the VMA of the next entry. */ | |
17340 | ||
17341 | static bfd_vma | |
17342 | print_mips_pltgot_entry (unsigned char * data, bfd_vma pltgot, bfd_vma addr) | |
17343 | { | |
17344 | printf (" "); | |
17345 | print_vma (addr, LONG_HEX); | |
17346 | printf (" "); | |
17347 | if (data == NULL) | |
17348 | printf ("%*s", is_32bit_elf ? 8 : 16, _("<unknown>")); | |
17349 | else | |
17350 | { | |
17351 | bfd_vma entry; | |
17352 | ||
17353 | entry = byte_get (data + addr - pltgot, is_32bit_elf ? 4 : 8); | |
17354 | print_vma (entry, LONG_HEX); | |
17355 | } | |
17356 | return addr + (is_32bit_elf ? 4 : 8); | |
17357 | } | |
17358 | ||
17359 | static void | |
17360 | print_mips_ases (unsigned int mask) | |
17361 | { | |
17362 | if (mask & AFL_ASE_DSP) | |
17363 | fputs ("\n\tDSP ASE", stdout); | |
17364 | if (mask & AFL_ASE_DSPR2) | |
17365 | fputs ("\n\tDSP R2 ASE", stdout); | |
17366 | if (mask & AFL_ASE_DSPR3) | |
17367 | fputs ("\n\tDSP R3 ASE", stdout); | |
17368 | if (mask & AFL_ASE_EVA) | |
17369 | fputs ("\n\tEnhanced VA Scheme", stdout); | |
17370 | if (mask & AFL_ASE_MCU) | |
17371 | fputs ("\n\tMCU (MicroController) ASE", stdout); | |
17372 | if (mask & AFL_ASE_MDMX) | |
17373 | fputs ("\n\tMDMX ASE", stdout); | |
17374 | if (mask & AFL_ASE_MIPS3D) | |
17375 | fputs ("\n\tMIPS-3D ASE", stdout); | |
17376 | if (mask & AFL_ASE_MT) | |
17377 | fputs ("\n\tMT ASE", stdout); | |
17378 | if (mask & AFL_ASE_SMARTMIPS) | |
17379 | fputs ("\n\tSmartMIPS ASE", stdout); | |
17380 | if (mask & AFL_ASE_VIRT) | |
17381 | fputs ("\n\tVZ ASE", stdout); | |
17382 | if (mask & AFL_ASE_MSA) | |
17383 | fputs ("\n\tMSA ASE", stdout); | |
17384 | if (mask & AFL_ASE_MIPS16) | |
17385 | fputs ("\n\tMIPS16 ASE", stdout); | |
17386 | if (mask & AFL_ASE_MICROMIPS) | |
17387 | fputs ("\n\tMICROMIPS ASE", stdout); | |
17388 | if (mask & AFL_ASE_XPA) | |
17389 | fputs ("\n\tXPA ASE", stdout); | |
17390 | if (mask & AFL_ASE_MIPS16E2) | |
17391 | fputs ("\n\tMIPS16e2 ASE", stdout); | |
17392 | if (mask & AFL_ASE_CRC) | |
17393 | fputs ("\n\tCRC ASE", stdout); | |
17394 | if (mask & AFL_ASE_GINV) | |
17395 | fputs ("\n\tGINV ASE", stdout); | |
17396 | if (mask & AFL_ASE_LOONGSON_MMI) | |
17397 | fputs ("\n\tLoongson MMI ASE", stdout); | |
17398 | if (mask & AFL_ASE_LOONGSON_CAM) | |
17399 | fputs ("\n\tLoongson CAM ASE", stdout); | |
17400 | if (mask & AFL_ASE_LOONGSON_EXT) | |
17401 | fputs ("\n\tLoongson EXT ASE", stdout); | |
17402 | if (mask & AFL_ASE_LOONGSON_EXT2) | |
17403 | fputs ("\n\tLoongson EXT2 ASE", stdout); | |
17404 | if (mask == 0) | |
17405 | fprintf (stdout, "\n\t%s", _("None")); | |
17406 | else if ((mask & ~AFL_ASE_MASK) != 0) | |
17407 | fprintf (stdout, "\n\t%s (%x)", _("Unknown"), mask & ~AFL_ASE_MASK); | |
17408 | } | |
17409 | ||
17410 | static void | |
17411 | print_mips_isa_ext (unsigned int isa_ext) | |
17412 | { | |
17413 | switch (isa_ext) | |
17414 | { | |
17415 | case 0: | |
17416 | fputs (_("None"), stdout); | |
17417 | break; | |
17418 | case AFL_EXT_XLR: | |
17419 | fputs ("RMI XLR", stdout); | |
17420 | break; | |
17421 | case AFL_EXT_OCTEON3: | |
17422 | fputs ("Cavium Networks Octeon3", stdout); | |
17423 | break; | |
17424 | case AFL_EXT_OCTEON2: | |
17425 | fputs ("Cavium Networks Octeon2", stdout); | |
17426 | break; | |
17427 | case AFL_EXT_OCTEONP: | |
17428 | fputs ("Cavium Networks OcteonP", stdout); | |
17429 | break; | |
17430 | case AFL_EXT_OCTEON: | |
17431 | fputs ("Cavium Networks Octeon", stdout); | |
17432 | break; | |
17433 | case AFL_EXT_5900: | |
17434 | fputs ("Toshiba R5900", stdout); | |
17435 | break; | |
17436 | case AFL_EXT_4650: | |
17437 | fputs ("MIPS R4650", stdout); | |
17438 | break; | |
17439 | case AFL_EXT_4010: | |
17440 | fputs ("LSI R4010", stdout); | |
17441 | break; | |
17442 | case AFL_EXT_4100: | |
17443 | fputs ("NEC VR4100", stdout); | |
17444 | break; | |
17445 | case AFL_EXT_3900: | |
17446 | fputs ("Toshiba R3900", stdout); | |
17447 | break; | |
17448 | case AFL_EXT_10000: | |
17449 | fputs ("MIPS R10000", stdout); | |
17450 | break; | |
17451 | case AFL_EXT_SB1: | |
17452 | fputs ("Broadcom SB-1", stdout); | |
17453 | break; | |
17454 | case AFL_EXT_4111: | |
17455 | fputs ("NEC VR4111/VR4181", stdout); | |
17456 | break; | |
17457 | case AFL_EXT_4120: | |
17458 | fputs ("NEC VR4120", stdout); | |
17459 | break; | |
17460 | case AFL_EXT_5400: | |
17461 | fputs ("NEC VR5400", stdout); | |
17462 | break; | |
17463 | case AFL_EXT_5500: | |
17464 | fputs ("NEC VR5500", stdout); | |
17465 | break; | |
17466 | case AFL_EXT_LOONGSON_2E: | |
17467 | fputs ("ST Microelectronics Loongson 2E", stdout); | |
17468 | break; | |
17469 | case AFL_EXT_LOONGSON_2F: | |
17470 | fputs ("ST Microelectronics Loongson 2F", stdout); | |
17471 | break; | |
17472 | case AFL_EXT_INTERAPTIV_MR2: | |
17473 | fputs ("Imagination interAptiv MR2", stdout); | |
17474 | break; | |
17475 | default: | |
17476 | fprintf (stdout, "%s (%d)", _("Unknown"), isa_ext); | |
17477 | } | |
17478 | } | |
17479 | ||
17480 | static signed int | |
17481 | get_mips_reg_size (int reg_size) | |
17482 | { | |
17483 | return (reg_size == AFL_REG_NONE) ? 0 | |
17484 | : (reg_size == AFL_REG_32) ? 32 | |
17485 | : (reg_size == AFL_REG_64) ? 64 | |
17486 | : (reg_size == AFL_REG_128) ? 128 | |
17487 | : -1; | |
17488 | } | |
17489 | ||
17490 | static bfd_boolean | |
17491 | process_mips_specific (Filedata * filedata) | |
17492 | { | |
17493 | Elf_Internal_Dyn * entry; | |
17494 | Elf_Internal_Shdr *sect = NULL; | |
17495 | size_t liblist_offset = 0; | |
17496 | size_t liblistno = 0; | |
17497 | size_t conflictsno = 0; | |
17498 | size_t options_offset = 0; | |
17499 | size_t conflicts_offset = 0; | |
17500 | size_t pltrelsz = 0; | |
17501 | size_t pltrel = 0; | |
17502 | bfd_vma pltgot = 0; | |
17503 | bfd_vma mips_pltgot = 0; | |
17504 | bfd_vma jmprel = 0; | |
17505 | bfd_vma local_gotno = 0; | |
17506 | bfd_vma gotsym = 0; | |
17507 | bfd_vma symtabno = 0; | |
17508 | bfd_boolean res = TRUE; | |
17509 | ||
17510 | if (! process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL, | |
17511 | display_mips_gnu_attribute)) | |
17512 | res = FALSE; | |
17513 | ||
17514 | sect = find_section (filedata, ".MIPS.abiflags"); | |
17515 | ||
17516 | if (sect != NULL) | |
17517 | { | |
17518 | Elf_External_ABIFlags_v0 *abiflags_ext; | |
17519 | Elf_Internal_ABIFlags_v0 abiflags_in; | |
17520 | ||
17521 | if (sizeof (Elf_External_ABIFlags_v0) != sect->sh_size) | |
17522 | { | |
17523 | error (_("Corrupt MIPS ABI Flags section.\n")); | |
17524 | res = FALSE; | |
17525 | } | |
17526 | else | |
17527 | { | |
17528 | abiflags_ext = get_data (NULL, filedata, sect->sh_offset, 1, | |
17529 | sect->sh_size, _("MIPS ABI Flags section")); | |
17530 | if (abiflags_ext) | |
17531 | { | |
17532 | abiflags_in.version = BYTE_GET (abiflags_ext->version); | |
17533 | abiflags_in.isa_level = BYTE_GET (abiflags_ext->isa_level); | |
17534 | abiflags_in.isa_rev = BYTE_GET (abiflags_ext->isa_rev); | |
17535 | abiflags_in.gpr_size = BYTE_GET (abiflags_ext->gpr_size); | |
17536 | abiflags_in.cpr1_size = BYTE_GET (abiflags_ext->cpr1_size); | |
17537 | abiflags_in.cpr2_size = BYTE_GET (abiflags_ext->cpr2_size); | |
17538 | abiflags_in.fp_abi = BYTE_GET (abiflags_ext->fp_abi); | |
17539 | abiflags_in.isa_ext = BYTE_GET (abiflags_ext->isa_ext); | |
17540 | abiflags_in.ases = BYTE_GET (abiflags_ext->ases); | |
17541 | abiflags_in.flags1 = BYTE_GET (abiflags_ext->flags1); | |
17542 | abiflags_in.flags2 = BYTE_GET (abiflags_ext->flags2); | |
17543 | ||
17544 | printf ("\nMIPS ABI Flags Version: %d\n", abiflags_in.version); | |
17545 | printf ("\nISA: MIPS%d", abiflags_in.isa_level); | |
17546 | if (abiflags_in.isa_rev > 1) | |
17547 | printf ("r%d", abiflags_in.isa_rev); | |
17548 | printf ("\nGPR size: %d", | |
17549 | get_mips_reg_size (abiflags_in.gpr_size)); | |
17550 | printf ("\nCPR1 size: %d", | |
17551 | get_mips_reg_size (abiflags_in.cpr1_size)); | |
17552 | printf ("\nCPR2 size: %d", | |
17553 | get_mips_reg_size (abiflags_in.cpr2_size)); | |
17554 | fputs ("\nFP ABI: ", stdout); | |
17555 | print_mips_fp_abi_value (abiflags_in.fp_abi); | |
17556 | fputs ("ISA Extension: ", stdout); | |
17557 | print_mips_isa_ext (abiflags_in.isa_ext); | |
17558 | fputs ("\nASEs:", stdout); | |
17559 | print_mips_ases (abiflags_in.ases); | |
17560 | printf ("\nFLAGS 1: %8.8lx", abiflags_in.flags1); | |
17561 | printf ("\nFLAGS 2: %8.8lx", abiflags_in.flags2); | |
17562 | fputc ('\n', stdout); | |
17563 | free (abiflags_ext); | |
17564 | } | |
17565 | } | |
17566 | } | |
17567 | ||
17568 | /* We have a lot of special sections. Thanks SGI! */ | |
17569 | if (filedata->dynamic_section == NULL) | |
17570 | { | |
17571 | /* No dynamic information available. See if there is static GOT. */ | |
17572 | sect = find_section (filedata, ".got"); | |
17573 | if (sect != NULL) | |
17574 | { | |
17575 | unsigned char *data_end; | |
17576 | unsigned char *data; | |
17577 | bfd_vma ent, end; | |
17578 | int addr_size; | |
17579 | ||
17580 | pltgot = sect->sh_addr; | |
17581 | ||
17582 | ent = pltgot; | |
17583 | addr_size = (is_32bit_elf ? 4 : 8); | |
17584 | end = pltgot + sect->sh_size; | |
17585 | ||
17586 | data = (unsigned char *) get_data (NULL, filedata, sect->sh_offset, | |
17587 | end - pltgot, 1, | |
17588 | _("Global Offset Table data")); | |
17589 | /* PR 12855: Null data is handled gracefully throughout. */ | |
17590 | data_end = data + (end - pltgot); | |
17591 | ||
17592 | printf (_("\nStatic GOT:\n")); | |
17593 | printf (_(" Canonical gp value: ")); | |
17594 | print_vma (ent + 0x7ff0, LONG_HEX); | |
17595 | printf ("\n\n"); | |
17596 | ||
17597 | /* In a dynamic binary GOT[0] is reserved for the dynamic | |
17598 | loader to store the lazy resolver pointer, however in | |
17599 | a static binary it may well have been omitted and GOT | |
17600 | reduced to a table of addresses. | |
17601 | PR 21344: Check for the entry being fully available | |
17602 | before fetching it. */ | |
17603 | if (data | |
17604 | && data + ent - pltgot + addr_size <= data_end | |
17605 | && byte_get (data + ent - pltgot, addr_size) == 0) | |
17606 | { | |
17607 | printf (_(" Reserved entries:\n")); | |
17608 | printf (_(" %*s %10s %*s\n"), | |
17609 | addr_size * 2, _("Address"), _("Access"), | |
17610 | addr_size * 2, _("Value")); | |
17611 | ent = print_mips_got_entry (data, pltgot, ent, data_end); | |
17612 | printf ("\n"); | |
17613 | if (ent == (bfd_vma) -1) | |
17614 | goto sgot_print_fail; | |
17615 | ||
17616 | /* Check for the MSB of GOT[1] being set, identifying a | |
17617 | GNU object. This entry will be used by some runtime | |
17618 | loaders, to store the module pointer. Otherwise this | |
17619 | is an ordinary local entry. | |
17620 | PR 21344: Check for the entry being fully available | |
17621 | before fetching it. */ | |
17622 | if (data | |
17623 | && data + ent - pltgot + addr_size <= data_end | |
17624 | && (byte_get (data + ent - pltgot, addr_size) | |
17625 | >> (addr_size * 8 - 1)) != 0) | |
17626 | { | |
17627 | ent = print_mips_got_entry (data, pltgot, ent, data_end); | |
17628 | printf ("\n"); | |
17629 | if (ent == (bfd_vma) -1) | |
17630 | goto sgot_print_fail; | |
17631 | } | |
17632 | printf ("\n"); | |
17633 | } | |
17634 | ||
17635 | if (data != NULL && ent < end) | |
17636 | { | |
17637 | printf (_(" Local entries:\n")); | |
17638 | printf (" %*s %10s %*s\n", | |
17639 | addr_size * 2, _("Address"), _("Access"), | |
17640 | addr_size * 2, _("Value")); | |
17641 | while (ent < end) | |
17642 | { | |
17643 | ent = print_mips_got_entry (data, pltgot, ent, data_end); | |
17644 | printf ("\n"); | |
17645 | if (ent == (bfd_vma) -1) | |
17646 | goto sgot_print_fail; | |
17647 | } | |
17648 | printf ("\n"); | |
17649 | } | |
17650 | ||
17651 | sgot_print_fail: | |
17652 | free (data); | |
17653 | } | |
17654 | return res; | |
17655 | } | |
17656 | ||
17657 | for (entry = filedata->dynamic_section; | |
17658 | /* PR 17531 file: 012-50589-0.004. */ | |
17659 | (entry < filedata->dynamic_section + filedata->dynamic_nent | |
17660 | && entry->d_tag != DT_NULL); | |
17661 | ++entry) | |
17662 | switch (entry->d_tag) | |
17663 | { | |
17664 | case DT_MIPS_LIBLIST: | |
17665 | liblist_offset | |
17666 | = offset_from_vma (filedata, entry->d_un.d_val, | |
17667 | liblistno * sizeof (Elf32_External_Lib)); | |
17668 | break; | |
17669 | case DT_MIPS_LIBLISTNO: | |
17670 | liblistno = entry->d_un.d_val; | |
17671 | break; | |
17672 | case DT_MIPS_OPTIONS: | |
17673 | options_offset = offset_from_vma (filedata, entry->d_un.d_val, 0); | |
17674 | break; | |
17675 | case DT_MIPS_CONFLICT: | |
17676 | conflicts_offset | |
17677 | = offset_from_vma (filedata, entry->d_un.d_val, | |
17678 | conflictsno * sizeof (Elf32_External_Conflict)); | |
17679 | break; | |
17680 | case DT_MIPS_CONFLICTNO: | |
17681 | conflictsno = entry->d_un.d_val; | |
17682 | break; | |
17683 | case DT_PLTGOT: | |
17684 | pltgot = entry->d_un.d_ptr; | |
17685 | break; | |
17686 | case DT_MIPS_LOCAL_GOTNO: | |
17687 | local_gotno = entry->d_un.d_val; | |
17688 | break; | |
17689 | case DT_MIPS_GOTSYM: | |
17690 | gotsym = entry->d_un.d_val; | |
17691 | break; | |
17692 | case DT_MIPS_SYMTABNO: | |
17693 | symtabno = entry->d_un.d_val; | |
17694 | break; | |
17695 | case DT_MIPS_PLTGOT: | |
17696 | mips_pltgot = entry->d_un.d_ptr; | |
17697 | break; | |
17698 | case DT_PLTREL: | |
17699 | pltrel = entry->d_un.d_val; | |
17700 | break; | |
17701 | case DT_PLTRELSZ: | |
17702 | pltrelsz = entry->d_un.d_val; | |
17703 | break; | |
17704 | case DT_JMPREL: | |
17705 | jmprel = entry->d_un.d_ptr; | |
17706 | break; | |
17707 | default: | |
17708 | break; | |
17709 | } | |
17710 | ||
17711 | if (liblist_offset != 0 && liblistno != 0 && do_dynamic) | |
17712 | { | |
17713 | Elf32_External_Lib * elib; | |
17714 | size_t cnt; | |
17715 | ||
17716 | elib = (Elf32_External_Lib *) get_data (NULL, filedata, liblist_offset, | |
17717 | sizeof (Elf32_External_Lib), | |
17718 | liblistno, | |
17719 | _("liblist section data")); | |
17720 | if (elib) | |
17721 | { | |
17722 | printf (ngettext ("\nSection '.liblist' contains %lu entry:\n", | |
17723 | "\nSection '.liblist' contains %lu entries:\n", | |
17724 | (unsigned long) liblistno), | |
17725 | (unsigned long) liblistno); | |
17726 | fputs (_(" Library Time Stamp Checksum Version Flags\n"), | |
17727 | stdout); | |
17728 | ||
17729 | for (cnt = 0; cnt < liblistno; ++cnt) | |
17730 | { | |
17731 | Elf32_Lib liblist; | |
17732 | time_t atime; | |
17733 | char timebuf[128]; | |
17734 | struct tm * tmp; | |
17735 | ||
17736 | liblist.l_name = BYTE_GET (elib[cnt].l_name); | |
17737 | atime = BYTE_GET (elib[cnt].l_time_stamp); | |
17738 | liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum); | |
17739 | liblist.l_version = BYTE_GET (elib[cnt].l_version); | |
17740 | liblist.l_flags = BYTE_GET (elib[cnt].l_flags); | |
17741 | ||
17742 | tmp = gmtime (&atime); | |
17743 | snprintf (timebuf, sizeof (timebuf), | |
17744 | "%04u-%02u-%02uT%02u:%02u:%02u", | |
17745 | tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday, | |
17746 | tmp->tm_hour, tmp->tm_min, tmp->tm_sec); | |
17747 | ||
17748 | printf ("%3lu: ", (unsigned long) cnt); | |
17749 | if (VALID_DYNAMIC_NAME (filedata, liblist.l_name)) | |
17750 | print_symbol (20, GET_DYNAMIC_NAME (filedata, liblist.l_name)); | |
17751 | else | |
17752 | printf (_("<corrupt: %9ld>"), liblist.l_name); | |
17753 | printf (" %s %#10lx %-7ld", timebuf, liblist.l_checksum, | |
17754 | liblist.l_version); | |
17755 | ||
17756 | if (liblist.l_flags == 0) | |
17757 | puts (_(" NONE")); | |
17758 | else | |
17759 | { | |
17760 | static const struct | |
17761 | { | |
17762 | const char * name; | |
17763 | int bit; | |
17764 | } | |
17765 | l_flags_vals[] = | |
17766 | { | |
17767 | { " EXACT_MATCH", LL_EXACT_MATCH }, | |
17768 | { " IGNORE_INT_VER", LL_IGNORE_INT_VER }, | |
17769 | { " REQUIRE_MINOR", LL_REQUIRE_MINOR }, | |
17770 | { " EXPORTS", LL_EXPORTS }, | |
17771 | { " DELAY_LOAD", LL_DELAY_LOAD }, | |
17772 | { " DELTA", LL_DELTA } | |
17773 | }; | |
17774 | int flags = liblist.l_flags; | |
17775 | size_t fcnt; | |
17776 | ||
17777 | for (fcnt = 0; fcnt < ARRAY_SIZE (l_flags_vals); ++fcnt) | |
17778 | if ((flags & l_flags_vals[fcnt].bit) != 0) | |
17779 | { | |
17780 | fputs (l_flags_vals[fcnt].name, stdout); | |
17781 | flags ^= l_flags_vals[fcnt].bit; | |
17782 | } | |
17783 | if (flags != 0) | |
17784 | printf (" %#x", (unsigned int) flags); | |
17785 | ||
17786 | puts (""); | |
17787 | } | |
17788 | } | |
17789 | ||
17790 | free (elib); | |
17791 | } | |
17792 | else | |
17793 | res = FALSE; | |
17794 | } | |
17795 | ||
17796 | if (options_offset != 0) | |
17797 | { | |
17798 | Elf_External_Options * eopt; | |
17799 | size_t offset; | |
17800 | int cnt; | |
17801 | sect = filedata->section_headers; | |
17802 | ||
17803 | /* Find the section header so that we get the size. */ | |
17804 | sect = find_section_by_type (filedata, SHT_MIPS_OPTIONS); | |
17805 | /* PR 17533 file: 012-277276-0.004. */ | |
17806 | if (sect == NULL) | |
17807 | { | |
17808 | error (_("No MIPS_OPTIONS header found\n")); | |
17809 | return FALSE; | |
17810 | } | |
17811 | /* PR 24243 */ | |
17812 | if (sect->sh_size < sizeof (* eopt)) | |
17813 | { | |
17814 | error (_("The MIPS options section is too small.\n")); | |
17815 | return FALSE; | |
17816 | } | |
17817 | ||
17818 | eopt = (Elf_External_Options *) get_data (NULL, filedata, options_offset, 1, | |
17819 | sect->sh_size, _("options")); | |
17820 | if (eopt) | |
17821 | { | |
17822 | Elf_Internal_Options option; | |
17823 | ||
17824 | offset = cnt = 0; | |
17825 | while (offset <= sect->sh_size - sizeof (* eopt)) | |
17826 | { | |
17827 | Elf_External_Options * eoption; | |
17828 | unsigned int optsize; | |
17829 | ||
17830 | eoption = (Elf_External_Options *) ((char *) eopt + offset); | |
17831 | ||
17832 | optsize = BYTE_GET (eoption->size); | |
17833 | ||
17834 | /* PR 17531: file: ffa0fa3b. */ | |
17835 | if (optsize < sizeof (* eopt) | |
17836 | || optsize > sect->sh_size - offset) | |
17837 | { | |
17838 | error (_("Invalid size (%u) for MIPS option\n"), | |
17839 | optsize); | |
17840 | free (eopt); | |
17841 | return FALSE; | |
17842 | } | |
17843 | offset += optsize; | |
17844 | ++cnt; | |
17845 | } | |
17846 | ||
17847 | printf (ngettext ("\nSection '%s' contains %d entry:\n", | |
17848 | "\nSection '%s' contains %d entries:\n", | |
17849 | cnt), | |
17850 | printable_section_name (filedata, sect), cnt); | |
17851 | ||
17852 | offset = 0; | |
17853 | while (cnt-- > 0) | |
17854 | { | |
17855 | size_t len; | |
17856 | Elf_External_Options * eoption; | |
17857 | ||
17858 | eoption = (Elf_External_Options *) ((char *) eopt + offset); | |
17859 | ||
17860 | option.kind = BYTE_GET (eoption->kind); | |
17861 | option.size = BYTE_GET (eoption->size); | |
17862 | option.section = BYTE_GET (eoption->section); | |
17863 | option.info = BYTE_GET (eoption->info); | |
17864 | ||
17865 | switch (option.kind) | |
17866 | { | |
17867 | case ODK_NULL: | |
17868 | /* This shouldn't happen. */ | |
17869 | printf (" NULL %" PRId16 " %" PRIx32, | |
17870 | option.section, option.info); | |
17871 | break; | |
17872 | ||
17873 | case ODK_REGINFO: | |
17874 | printf (" REGINFO "); | |
17875 | if (filedata->file_header.e_machine == EM_MIPS) | |
17876 | { | |
17877 | Elf32_External_RegInfo * ereg; | |
17878 | Elf32_RegInfo reginfo; | |
17879 | ||
17880 | /* 32bit form. */ | |
17881 | if (option.size < (sizeof (Elf_External_Options) | |
17882 | + sizeof (Elf32_External_RegInfo))) | |
17883 | { | |
17884 | printf (_("<corrupt>\n")); | |
17885 | error (_("Truncated MIPS REGINFO option\n")); | |
17886 | cnt = 0; | |
17887 | break; | |
17888 | } | |
17889 | ||
17890 | ereg = (Elf32_External_RegInfo *) (eoption + 1); | |
17891 | ||
17892 | reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask); | |
17893 | reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]); | |
17894 | reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]); | |
17895 | reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]); | |
17896 | reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]); | |
17897 | reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value); | |
17898 | ||
17899 | printf ("GPR %08" PRIx32 " GP 0x%" PRIx32 "\n", | |
17900 | reginfo.ri_gprmask, reginfo.ri_gp_value); | |
17901 | printf (" " | |
17902 | " CPR0 %08" PRIx32 " CPR1 %08" PRIx32 | |
17903 | " CPR2 %08" PRIx32 " CPR3 %08" PRIx32 "\n", | |
17904 | reginfo.ri_cprmask[0], reginfo.ri_cprmask[1], | |
17905 | reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]); | |
17906 | } | |
17907 | else | |
17908 | { | |
17909 | /* 64 bit form. */ | |
17910 | Elf64_External_RegInfo * ereg; | |
17911 | Elf64_Internal_RegInfo reginfo; | |
17912 | ||
17913 | if (option.size < (sizeof (Elf_External_Options) | |
17914 | + sizeof (Elf64_External_RegInfo))) | |
17915 | { | |
17916 | printf (_("<corrupt>\n")); | |
17917 | error (_("Truncated MIPS REGINFO option\n")); | |
17918 | cnt = 0; | |
17919 | break; | |
17920 | } | |
17921 | ||
17922 | ereg = (Elf64_External_RegInfo *) (eoption + 1); | |
17923 | reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask); | |
17924 | reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]); | |
17925 | reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]); | |
17926 | reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]); | |
17927 | reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]); | |
17928 | reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value); | |
17929 | ||
17930 | printf ("GPR %08" PRIx32 " GP 0x%" PRIx64 "\n", | |
17931 | reginfo.ri_gprmask, reginfo.ri_gp_value); | |
17932 | printf (" " | |
17933 | " CPR0 %08" PRIx32 " CPR1 %08" PRIx32 | |
17934 | " CPR2 %08" PRIx32 " CPR3 %08" PRIx32 "\n", | |
17935 | reginfo.ri_cprmask[0], reginfo.ri_cprmask[1], | |
17936 | reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]); | |
17937 | } | |
17938 | offset += option.size; | |
17939 | continue; | |
17940 | ||
17941 | case ODK_EXCEPTIONS: | |
17942 | fputs (" EXCEPTIONS fpe_min(", stdout); | |
17943 | process_mips_fpe_exception (option.info & OEX_FPU_MIN); | |
17944 | fputs (") fpe_max(", stdout); | |
17945 | process_mips_fpe_exception ((option.info & OEX_FPU_MAX) >> 8); | |
17946 | fputs (")", stdout); | |
17947 | ||
17948 | if (option.info & OEX_PAGE0) | |
17949 | fputs (" PAGE0", stdout); | |
17950 | if (option.info & OEX_SMM) | |
17951 | fputs (" SMM", stdout); | |
17952 | if (option.info & OEX_FPDBUG) | |
17953 | fputs (" FPDBUG", stdout); | |
17954 | if (option.info & OEX_DISMISS) | |
17955 | fputs (" DISMISS", stdout); | |
17956 | break; | |
17957 | ||
17958 | case ODK_PAD: | |
17959 | fputs (" PAD ", stdout); | |
17960 | if (option.info & OPAD_PREFIX) | |
17961 | fputs (" PREFIX", stdout); | |
17962 | if (option.info & OPAD_POSTFIX) | |
17963 | fputs (" POSTFIX", stdout); | |
17964 | if (option.info & OPAD_SYMBOL) | |
17965 | fputs (" SYMBOL", stdout); | |
17966 | break; | |
17967 | ||
17968 | case ODK_HWPATCH: | |
17969 | fputs (" HWPATCH ", stdout); | |
17970 | if (option.info & OHW_R4KEOP) | |
17971 | fputs (" R4KEOP", stdout); | |
17972 | if (option.info & OHW_R8KPFETCH) | |
17973 | fputs (" R8KPFETCH", stdout); | |
17974 | if (option.info & OHW_R5KEOP) | |
17975 | fputs (" R5KEOP", stdout); | |
17976 | if (option.info & OHW_R5KCVTL) | |
17977 | fputs (" R5KCVTL", stdout); | |
17978 | break; | |
17979 | ||
17980 | case ODK_FILL: | |
17981 | fputs (" FILL ", stdout); | |
17982 | /* XXX Print content of info word? */ | |
17983 | break; | |
17984 | ||
17985 | case ODK_TAGS: | |
17986 | fputs (" TAGS ", stdout); | |
17987 | /* XXX Print content of info word? */ | |
17988 | break; | |
17989 | ||
17990 | case ODK_HWAND: | |
17991 | fputs (" HWAND ", stdout); | |
17992 | if (option.info & OHWA0_R4KEOP_CHECKED) | |
17993 | fputs (" R4KEOP_CHECKED", stdout); | |
17994 | if (option.info & OHWA0_R4KEOP_CLEAN) | |
17995 | fputs (" R4KEOP_CLEAN", stdout); | |
17996 | break; | |
17997 | ||
17998 | case ODK_HWOR: | |
17999 | fputs (" HWOR ", stdout); | |
18000 | if (option.info & OHWA0_R4KEOP_CHECKED) | |
18001 | fputs (" R4KEOP_CHECKED", stdout); | |
18002 | if (option.info & OHWA0_R4KEOP_CLEAN) | |
18003 | fputs (" R4KEOP_CLEAN", stdout); | |
18004 | break; | |
18005 | ||
18006 | case ODK_GP_GROUP: | |
18007 | printf (" GP_GROUP %#06x self-contained %#06x", | |
18008 | option.info & OGP_GROUP, | |
18009 | (option.info & OGP_SELF) >> 16); | |
18010 | break; | |
18011 | ||
18012 | case ODK_IDENT: | |
18013 | printf (" IDENT %#06x self-contained %#06x", | |
18014 | option.info & OGP_GROUP, | |
18015 | (option.info & OGP_SELF) >> 16); | |
18016 | break; | |
18017 | ||
18018 | default: | |
18019 | /* This shouldn't happen. */ | |
18020 | printf (" %3d ??? %" PRId16 " %" PRIx32, | |
18021 | option.kind, option.section, option.info); | |
18022 | break; | |
18023 | } | |
18024 | ||
18025 | len = sizeof (* eopt); | |
18026 | while (len < option.size) | |
18027 | { | |
18028 | unsigned char datum = *((unsigned char *) eoption + len); | |
18029 | ||
18030 | if (ISPRINT (datum)) | |
18031 | printf ("%c", datum); | |
18032 | else | |
18033 | printf ("\\%03o", datum); | |
18034 | len ++; | |
18035 | } | |
18036 | fputs ("\n", stdout); | |
18037 | ||
18038 | offset += option.size; | |
18039 | } | |
18040 | free (eopt); | |
18041 | } | |
18042 | else | |
18043 | res = FALSE; | |
18044 | } | |
18045 | ||
18046 | if (conflicts_offset != 0 && conflictsno != 0) | |
18047 | { | |
18048 | Elf32_Conflict * iconf; | |
18049 | size_t cnt; | |
18050 | ||
18051 | if (filedata->dynamic_symbols == NULL) | |
18052 | { | |
18053 | error (_("conflict list found without a dynamic symbol table\n")); | |
18054 | return FALSE; | |
18055 | } | |
18056 | ||
18057 | /* PR 21345 - print a slightly more helpful error message | |
18058 | if we are sure that the cmalloc will fail. */ | |
18059 | if (conflictsno > filedata->file_size / sizeof (* iconf)) | |
18060 | { | |
18061 | error (_("Overlarge number of conflicts detected: %lx\n"), | |
18062 | (long) conflictsno); | |
18063 | return FALSE; | |
18064 | } | |
18065 | ||
18066 | iconf = (Elf32_Conflict *) cmalloc (conflictsno, sizeof (* iconf)); | |
18067 | if (iconf == NULL) | |
18068 | { | |
18069 | error (_("Out of memory allocating space for dynamic conflicts\n")); | |
18070 | return FALSE; | |
18071 | } | |
18072 | ||
18073 | if (is_32bit_elf) | |
18074 | { | |
18075 | Elf32_External_Conflict * econf32; | |
18076 | ||
18077 | econf32 = (Elf32_External_Conflict *) | |
18078 | get_data (NULL, filedata, conflicts_offset, | |
18079 | sizeof (*econf32), conflictsno, _("conflict")); | |
18080 | if (!econf32) | |
18081 | { | |
18082 | free (iconf); | |
18083 | return FALSE; | |
18084 | } | |
18085 | ||
18086 | for (cnt = 0; cnt < conflictsno; ++cnt) | |
18087 | iconf[cnt] = BYTE_GET (econf32[cnt]); | |
18088 | ||
18089 | free (econf32); | |
18090 | } | |
18091 | else | |
18092 | { | |
18093 | Elf64_External_Conflict * econf64; | |
18094 | ||
18095 | econf64 = (Elf64_External_Conflict *) | |
18096 | get_data (NULL, filedata, conflicts_offset, | |
18097 | sizeof (*econf64), conflictsno, _("conflict")); | |
18098 | if (!econf64) | |
18099 | { | |
18100 | free (iconf); | |
18101 | return FALSE; | |
18102 | } | |
18103 | ||
18104 | for (cnt = 0; cnt < conflictsno; ++cnt) | |
18105 | iconf[cnt] = BYTE_GET (econf64[cnt]); | |
18106 | ||
18107 | free (econf64); | |
18108 | } | |
18109 | ||
18110 | printf (ngettext ("\nSection '.conflict' contains %lu entry:\n", | |
18111 | "\nSection '.conflict' contains %lu entries:\n", | |
18112 | (unsigned long) conflictsno), | |
18113 | (unsigned long) conflictsno); | |
18114 | puts (_(" Num: Index Value Name")); | |
18115 | ||
18116 | for (cnt = 0; cnt < conflictsno; ++cnt) | |
18117 | { | |
18118 | printf ("%5lu: %8lu ", (unsigned long) cnt, iconf[cnt]); | |
18119 | ||
18120 | if (iconf[cnt] >= filedata->num_dynamic_syms) | |
18121 | printf (_("<corrupt symbol index>")); | |
18122 | else | |
18123 | { | |
18124 | Elf_Internal_Sym * psym; | |
18125 | ||
18126 | psym = & filedata->dynamic_symbols[iconf[cnt]]; | |
18127 | print_vma (psym->st_value, FULL_HEX); | |
18128 | putchar (' '); | |
18129 | if (VALID_DYNAMIC_NAME (filedata, psym->st_name)) | |
18130 | print_symbol (25, GET_DYNAMIC_NAME (filedata, psym->st_name)); | |
18131 | else | |
18132 | printf (_("<corrupt: %14ld>"), psym->st_name); | |
18133 | } | |
18134 | putchar ('\n'); | |
18135 | } | |
18136 | ||
18137 | free (iconf); | |
18138 | } | |
18139 | ||
18140 | if (pltgot != 0 && local_gotno != 0) | |
18141 | { | |
18142 | bfd_vma ent, local_end, global_end; | |
18143 | size_t i, offset; | |
18144 | unsigned char * data; | |
18145 | unsigned char * data_end; | |
18146 | int addr_size; | |
18147 | ||
18148 | ent = pltgot; | |
18149 | addr_size = (is_32bit_elf ? 4 : 8); | |
18150 | local_end = pltgot + local_gotno * addr_size; | |
18151 | ||
18152 | /* PR binutils/17533 file: 012-111227-0.004 */ | |
18153 | if (symtabno < gotsym) | |
18154 | { | |
18155 | error (_("The GOT symbol offset (%lu) is greater than the symbol table size (%lu)\n"), | |
18156 | (unsigned long) gotsym, (unsigned long) symtabno); | |
18157 | return FALSE; | |
18158 | } | |
18159 | ||
18160 | global_end = local_end + (symtabno - gotsym) * addr_size; | |
18161 | /* PR 17531: file: 54c91a34. */ | |
18162 | if (global_end < local_end) | |
18163 | { | |
18164 | error (_("Too many GOT symbols: %lu\n"), (unsigned long) symtabno); | |
18165 | return FALSE; | |
18166 | } | |
18167 | ||
18168 | offset = offset_from_vma (filedata, pltgot, global_end - pltgot); | |
18169 | data = (unsigned char *) get_data (NULL, filedata, offset, | |
18170 | global_end - pltgot, 1, | |
18171 | _("Global Offset Table data")); | |
18172 | /* PR 12855: Null data is handled gracefully throughout. */ | |
18173 | data_end = data + (global_end - pltgot); | |
18174 | ||
18175 | printf (_("\nPrimary GOT:\n")); | |
18176 | printf (_(" Canonical gp value: ")); | |
18177 | print_vma (pltgot + 0x7ff0, LONG_HEX); | |
18178 | printf ("\n\n"); | |
18179 | ||
18180 | printf (_(" Reserved entries:\n")); | |
18181 | printf (_(" %*s %10s %*s Purpose\n"), | |
18182 | addr_size * 2, _("Address"), _("Access"), | |
18183 | addr_size * 2, _("Initial")); | |
18184 | ent = print_mips_got_entry (data, pltgot, ent, data_end); | |
18185 | printf (_(" Lazy resolver\n")); | |
18186 | if (ent == (bfd_vma) -1) | |
18187 | goto got_print_fail; | |
18188 | ||
18189 | /* Check for the MSB of GOT[1] being set, denoting a GNU object. | |
18190 | This entry will be used by some runtime loaders, to store the | |
18191 | module pointer. Otherwise this is an ordinary local entry. | |
18192 | PR 21344: Check for the entry being fully available before | |
18193 | fetching it. */ | |
18194 | if (data | |
18195 | && data + ent - pltgot + addr_size <= data_end | |
18196 | && (byte_get (data + ent - pltgot, addr_size) | |
18197 | >> (addr_size * 8 - 1)) != 0) | |
18198 | { | |
18199 | ent = print_mips_got_entry (data, pltgot, ent, data_end); | |
18200 | printf (_(" Module pointer (GNU extension)\n")); | |
18201 | if (ent == (bfd_vma) -1) | |
18202 | goto got_print_fail; | |
18203 | } | |
18204 | printf ("\n"); | |
18205 | ||
18206 | if (data != NULL && ent < local_end) | |
18207 | { | |
18208 | printf (_(" Local entries:\n")); | |
18209 | printf (" %*s %10s %*s\n", | |
18210 | addr_size * 2, _("Address"), _("Access"), | |
18211 | addr_size * 2, _("Initial")); | |
18212 | while (ent < local_end) | |
18213 | { | |
18214 | ent = print_mips_got_entry (data, pltgot, ent, data_end); | |
18215 | printf ("\n"); | |
18216 | if (ent == (bfd_vma) -1) | |
18217 | goto got_print_fail; | |
18218 | } | |
18219 | printf ("\n"); | |
18220 | } | |
18221 | ||
18222 | if (data != NULL && gotsym < symtabno) | |
18223 | { | |
18224 | int sym_width; | |
18225 | ||
18226 | printf (_(" Global entries:\n")); | |
18227 | printf (" %*s %10s %*s %*s %-7s %3s %s\n", | |
18228 | addr_size * 2, _("Address"), | |
18229 | _("Access"), | |
18230 | addr_size * 2, _("Initial"), | |
18231 | addr_size * 2, _("Sym.Val."), | |
18232 | _("Type"), | |
18233 | /* Note for translators: "Ndx" = abbreviated form of "Index". */ | |
18234 | _("Ndx"), _("Name")); | |
18235 | ||
18236 | sym_width = (is_32bit_elf ? 80 : 160) - 28 - addr_size * 6 - 1; | |
18237 | ||
18238 | for (i = gotsym; i < symtabno; i++) | |
18239 | { | |
18240 | ent = print_mips_got_entry (data, pltgot, ent, data_end); | |
18241 | printf (" "); | |
18242 | ||
18243 | if (filedata->dynamic_symbols == NULL) | |
18244 | printf (_("<no dynamic symbols>")); | |
18245 | else if (i < filedata->num_dynamic_syms) | |
18246 | { | |
18247 | Elf_Internal_Sym * psym = filedata->dynamic_symbols + i; | |
18248 | ||
18249 | print_vma (psym->st_value, LONG_HEX); | |
18250 | printf (" %-7s %3s ", | |
18251 | get_symbol_type (filedata, ELF_ST_TYPE (psym->st_info)), | |
18252 | get_symbol_index_type (filedata, psym->st_shndx)); | |
18253 | ||
18254 | if (VALID_DYNAMIC_NAME (filedata, psym->st_name)) | |
18255 | print_symbol (sym_width, | |
18256 | GET_DYNAMIC_NAME (filedata, psym->st_name)); | |
18257 | else | |
18258 | printf (_("<corrupt: %14ld>"), psym->st_name); | |
18259 | } | |
18260 | else | |
18261 | printf (_("<symbol index %lu exceeds number of dynamic symbols>"), | |
18262 | (unsigned long) i); | |
18263 | ||
18264 | printf ("\n"); | |
18265 | if (ent == (bfd_vma) -1) | |
18266 | break; | |
18267 | } | |
18268 | printf ("\n"); | |
18269 | } | |
18270 | ||
18271 | got_print_fail: | |
18272 | free (data); | |
18273 | } | |
18274 | ||
18275 | if (mips_pltgot != 0 && jmprel != 0 && pltrel != 0 && pltrelsz != 0) | |
18276 | { | |
18277 | bfd_vma ent, end; | |
18278 | size_t offset, rel_offset; | |
18279 | unsigned long count, i; | |
18280 | unsigned char * data; | |
18281 | int addr_size, sym_width; | |
18282 | Elf_Internal_Rela * rels; | |
18283 | ||
18284 | rel_offset = offset_from_vma (filedata, jmprel, pltrelsz); | |
18285 | if (pltrel == DT_RELA) | |
18286 | { | |
18287 | if (!slurp_rela_relocs (filedata, rel_offset, pltrelsz, &rels, &count)) | |
18288 | return FALSE; | |
18289 | } | |
18290 | else | |
18291 | { | |
18292 | if (!slurp_rel_relocs (filedata, rel_offset, pltrelsz, &rels, &count)) | |
18293 | return FALSE; | |
18294 | } | |
18295 | ||
18296 | ent = mips_pltgot; | |
18297 | addr_size = (is_32bit_elf ? 4 : 8); | |
18298 | end = mips_pltgot + (2 + count) * addr_size; | |
18299 | ||
18300 | offset = offset_from_vma (filedata, mips_pltgot, end - mips_pltgot); | |
18301 | data = (unsigned char *) get_data (NULL, filedata, offset, end - mips_pltgot, | |
18302 | 1, _("Procedure Linkage Table data")); | |
18303 | if (data == NULL) | |
18304 | { | |
18305 | free (rels); | |
18306 | return FALSE; | |
18307 | } | |
18308 | ||
18309 | printf ("\nPLT GOT:\n\n"); | |
18310 | printf (_(" Reserved entries:\n")); | |
18311 | printf (_(" %*s %*s Purpose\n"), | |
18312 | addr_size * 2, _("Address"), addr_size * 2, _("Initial")); | |
18313 | ent = print_mips_pltgot_entry (data, mips_pltgot, ent); | |
18314 | printf (_(" PLT lazy resolver\n")); | |
18315 | ent = print_mips_pltgot_entry (data, mips_pltgot, ent); | |
18316 | printf (_(" Module pointer\n")); | |
18317 | printf ("\n"); | |
18318 | ||
18319 | printf (_(" Entries:\n")); | |
18320 | printf (" %*s %*s %*s %-7s %3s %s\n", | |
18321 | addr_size * 2, _("Address"), | |
18322 | addr_size * 2, _("Initial"), | |
18323 | addr_size * 2, _("Sym.Val."), _("Type"), _("Ndx"), _("Name")); | |
18324 | sym_width = (is_32bit_elf ? 80 : 160) - 17 - addr_size * 6 - 1; | |
18325 | for (i = 0; i < count; i++) | |
18326 | { | |
18327 | unsigned long idx = get_reloc_symindex (rels[i].r_info); | |
18328 | ||
18329 | ent = print_mips_pltgot_entry (data, mips_pltgot, ent); | |
18330 | printf (" "); | |
18331 | ||
18332 | if (idx >= filedata->num_dynamic_syms) | |
18333 | printf (_("<corrupt symbol index: %lu>"), idx); | |
18334 | else | |
18335 | { | |
18336 | Elf_Internal_Sym * psym = filedata->dynamic_symbols + idx; | |
18337 | ||
18338 | print_vma (psym->st_value, LONG_HEX); | |
18339 | printf (" %-7s %3s ", | |
18340 | get_symbol_type (filedata, ELF_ST_TYPE (psym->st_info)), | |
18341 | get_symbol_index_type (filedata, psym->st_shndx)); | |
18342 | if (VALID_DYNAMIC_NAME (filedata, psym->st_name)) | |
18343 | print_symbol (sym_width, | |
18344 | GET_DYNAMIC_NAME (filedata, psym->st_name)); | |
18345 | else | |
18346 | printf (_("<corrupt: %14ld>"), psym->st_name); | |
18347 | } | |
18348 | printf ("\n"); | |
18349 | } | |
18350 | printf ("\n"); | |
18351 | ||
18352 | free (data); | |
18353 | free (rels); | |
18354 | } | |
18355 | ||
18356 | return res; | |
18357 | } | |
18358 | ||
18359 | static bfd_boolean | |
18360 | process_nds32_specific (Filedata * filedata) | |
18361 | { | |
18362 | Elf_Internal_Shdr *sect = NULL; | |
18363 | ||
18364 | sect = find_section (filedata, ".nds32_e_flags"); | |
18365 | if (sect != NULL && sect->sh_size >= 4) | |
18366 | { | |
18367 | unsigned char *buf; | |
18368 | unsigned int flag; | |
18369 | ||
18370 | printf ("\nNDS32 elf flags section:\n"); | |
18371 | buf = get_data (NULL, filedata, sect->sh_offset, 1, 4, | |
18372 | _("NDS32 elf flags section")); | |
18373 | ||
18374 | if (buf == NULL) | |
18375 | return FALSE; | |
18376 | ||
18377 | flag = byte_get (buf, 4); | |
18378 | free (buf); | |
18379 | switch (flag & 0x3) | |
18380 | { | |
18381 | case 0: | |
18382 | printf ("(VEC_SIZE):\tNo entry.\n"); | |
18383 | break; | |
18384 | case 1: | |
18385 | printf ("(VEC_SIZE):\t4 bytes\n"); | |
18386 | break; | |
18387 | case 2: | |
18388 | printf ("(VEC_SIZE):\t16 bytes\n"); | |
18389 | break; | |
18390 | case 3: | |
18391 | printf ("(VEC_SIZE):\treserved\n"); | |
18392 | break; | |
18393 | } | |
18394 | } | |
18395 | ||
18396 | return TRUE; | |
18397 | } | |
18398 | ||
18399 | static bfd_boolean | |
18400 | process_gnu_liblist (Filedata * filedata) | |
18401 | { | |
18402 | Elf_Internal_Shdr * section; | |
18403 | Elf_Internal_Shdr * string_sec; | |
18404 | Elf32_External_Lib * elib; | |
18405 | char * strtab; | |
18406 | size_t strtab_size; | |
18407 | size_t cnt; | |
18408 | unsigned long num_liblist; | |
18409 | unsigned i; | |
18410 | bfd_boolean res = TRUE; | |
18411 | ||
18412 | if (! do_arch) | |
18413 | return TRUE; | |
18414 | ||
18415 | for (i = 0, section = filedata->section_headers; | |
18416 | i < filedata->file_header.e_shnum; | |
18417 | i++, section++) | |
18418 | { | |
18419 | switch (section->sh_type) | |
18420 | { | |
18421 | case SHT_GNU_LIBLIST: | |
18422 | if (section->sh_link >= filedata->file_header.e_shnum) | |
18423 | break; | |
18424 | ||
18425 | elib = (Elf32_External_Lib *) | |
18426 | get_data (NULL, filedata, section->sh_offset, 1, section->sh_size, | |
18427 | _("liblist section data")); | |
18428 | ||
18429 | if (elib == NULL) | |
18430 | { | |
18431 | res = FALSE; | |
18432 | break; | |
18433 | } | |
18434 | ||
18435 | string_sec = filedata->section_headers + section->sh_link; | |
18436 | strtab = (char *) get_data (NULL, filedata, string_sec->sh_offset, 1, | |
18437 | string_sec->sh_size, | |
18438 | _("liblist string table")); | |
18439 | if (strtab == NULL | |
18440 | || section->sh_entsize != sizeof (Elf32_External_Lib)) | |
18441 | { | |
18442 | free (elib); | |
18443 | free (strtab); | |
18444 | res = FALSE; | |
18445 | break; | |
18446 | } | |
18447 | strtab_size = string_sec->sh_size; | |
18448 | ||
18449 | num_liblist = section->sh_size / sizeof (Elf32_External_Lib); | |
18450 | printf (ngettext ("\nLibrary list section '%s' contains %lu entries:\n", | |
18451 | "\nLibrary list section '%s' contains %lu entries:\n", | |
18452 | num_liblist), | |
18453 | printable_section_name (filedata, section), | |
18454 | num_liblist); | |
18455 | ||
18456 | puts (_(" Library Time Stamp Checksum Version Flags")); | |
18457 | ||
18458 | for (cnt = 0; cnt < section->sh_size / sizeof (Elf32_External_Lib); | |
18459 | ++cnt) | |
18460 | { | |
18461 | Elf32_Lib liblist; | |
18462 | time_t atime; | |
18463 | char timebuf[128]; | |
18464 | struct tm * tmp; | |
18465 | ||
18466 | liblist.l_name = BYTE_GET (elib[cnt].l_name); | |
18467 | atime = BYTE_GET (elib[cnt].l_time_stamp); | |
18468 | liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum); | |
18469 | liblist.l_version = BYTE_GET (elib[cnt].l_version); | |
18470 | liblist.l_flags = BYTE_GET (elib[cnt].l_flags); | |
18471 | ||
18472 | tmp = gmtime (&atime); | |
18473 | snprintf (timebuf, sizeof (timebuf), | |
18474 | "%04u-%02u-%02uT%02u:%02u:%02u", | |
18475 | tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday, | |
18476 | tmp->tm_hour, tmp->tm_min, tmp->tm_sec); | |
18477 | ||
18478 | printf ("%3lu: ", (unsigned long) cnt); | |
18479 | if (do_wide) | |
18480 | printf ("%-20s", liblist.l_name < strtab_size | |
18481 | ? strtab + liblist.l_name : _("<corrupt>")); | |
18482 | else | |
18483 | printf ("%-20.20s", liblist.l_name < strtab_size | |
18484 | ? strtab + liblist.l_name : _("<corrupt>")); | |
18485 | printf (" %s %#010lx %-7ld %-7ld\n", timebuf, liblist.l_checksum, | |
18486 | liblist.l_version, liblist.l_flags); | |
18487 | } | |
18488 | ||
18489 | free (elib); | |
18490 | free (strtab); | |
18491 | } | |
18492 | } | |
18493 | ||
18494 | return res; | |
18495 | } | |
18496 | ||
18497 | static const char * | |
18498 | get_note_type (Filedata * filedata, unsigned e_type) | |
18499 | { | |
18500 | static char buff[64]; | |
18501 | ||
18502 | if (filedata->file_header.e_type == ET_CORE) | |
18503 | switch (e_type) | |
18504 | { | |
18505 | case NT_AUXV: | |
18506 | return _("NT_AUXV (auxiliary vector)"); | |
18507 | case NT_PRSTATUS: | |
18508 | return _("NT_PRSTATUS (prstatus structure)"); | |
18509 | case NT_FPREGSET: | |
18510 | return _("NT_FPREGSET (floating point registers)"); | |
18511 | case NT_PRPSINFO: | |
18512 | return _("NT_PRPSINFO (prpsinfo structure)"); | |
18513 | case NT_TASKSTRUCT: | |
18514 | return _("NT_TASKSTRUCT (task structure)"); | |
18515 | case NT_GDB_TDESC: | |
18516 | return _("NT_GDB_TDESC (GDB XML target description)"); | |
18517 | case NT_PRXFPREG: | |
18518 | return _("NT_PRXFPREG (user_xfpregs structure)"); | |
18519 | case NT_PPC_VMX: | |
18520 | return _("NT_PPC_VMX (ppc Altivec registers)"); | |
18521 | case NT_PPC_VSX: | |
18522 | return _("NT_PPC_VSX (ppc VSX registers)"); | |
18523 | case NT_PPC_TAR: | |
18524 | return _("NT_PPC_TAR (ppc TAR register)"); | |
18525 | case NT_PPC_PPR: | |
18526 | return _("NT_PPC_PPR (ppc PPR register)"); | |
18527 | case NT_PPC_DSCR: | |
18528 | return _("NT_PPC_DSCR (ppc DSCR register)"); | |
18529 | case NT_PPC_EBB: | |
18530 | return _("NT_PPC_EBB (ppc EBB registers)"); | |
18531 | case NT_PPC_PMU: | |
18532 | return _("NT_PPC_PMU (ppc PMU registers)"); | |
18533 | case NT_PPC_TM_CGPR: | |
18534 | return _("NT_PPC_TM_CGPR (ppc checkpointed GPR registers)"); | |
18535 | case NT_PPC_TM_CFPR: | |
18536 | return _("NT_PPC_TM_CFPR (ppc checkpointed floating point registers)"); | |
18537 | case NT_PPC_TM_CVMX: | |
18538 | return _("NT_PPC_TM_CVMX (ppc checkpointed Altivec registers)"); | |
18539 | case NT_PPC_TM_CVSX: | |
18540 | return _("NT_PPC_TM_CVSX (ppc checkpointed VSX registers)"); | |
18541 | case NT_PPC_TM_SPR: | |
18542 | return _("NT_PPC_TM_SPR (ppc TM special purpose registers)"); | |
18543 | case NT_PPC_TM_CTAR: | |
18544 | return _("NT_PPC_TM_CTAR (ppc checkpointed TAR register)"); | |
18545 | case NT_PPC_TM_CPPR: | |
18546 | return _("NT_PPC_TM_CPPR (ppc checkpointed PPR register)"); | |
18547 | case NT_PPC_TM_CDSCR: | |
18548 | return _("NT_PPC_TM_CDSCR (ppc checkpointed DSCR register)"); | |
18549 | case NT_386_TLS: | |
18550 | return _("NT_386_TLS (x86 TLS information)"); | |
18551 | case NT_386_IOPERM: | |
18552 | return _("NT_386_IOPERM (x86 I/O permissions)"); | |
18553 | case NT_X86_XSTATE: | |
18554 | return _("NT_X86_XSTATE (x86 XSAVE extended state)"); | |
18555 | case NT_X86_CET: | |
18556 | return _("NT_X86_CET (x86 CET state)"); | |
18557 | case NT_S390_HIGH_GPRS: | |
18558 | return _("NT_S390_HIGH_GPRS (s390 upper register halves)"); | |
18559 | case NT_S390_TIMER: | |
18560 | return _("NT_S390_TIMER (s390 timer register)"); | |
18561 | case NT_S390_TODCMP: | |
18562 | return _("NT_S390_TODCMP (s390 TOD comparator register)"); | |
18563 | case NT_S390_TODPREG: | |
18564 | return _("NT_S390_TODPREG (s390 TOD programmable register)"); | |
18565 | case NT_S390_CTRS: | |
18566 | return _("NT_S390_CTRS (s390 control registers)"); | |
18567 | case NT_S390_PREFIX: | |
18568 | return _("NT_S390_PREFIX (s390 prefix register)"); | |
18569 | case NT_S390_LAST_BREAK: | |
18570 | return _("NT_S390_LAST_BREAK (s390 last breaking event address)"); | |
18571 | case NT_S390_SYSTEM_CALL: | |
18572 | return _("NT_S390_SYSTEM_CALL (s390 system call restart data)"); | |
18573 | case NT_S390_TDB: | |
18574 | return _("NT_S390_TDB (s390 transaction diagnostic block)"); | |
18575 | case NT_S390_VXRS_LOW: | |
18576 | return _("NT_S390_VXRS_LOW (s390 vector registers 0-15 upper half)"); | |
18577 | case NT_S390_VXRS_HIGH: | |
18578 | return _("NT_S390_VXRS_HIGH (s390 vector registers 16-31)"); | |
18579 | case NT_S390_GS_CB: | |
18580 | return _("NT_S390_GS_CB (s390 guarded-storage registers)"); | |
18581 | case NT_S390_GS_BC: | |
18582 | return _("NT_S390_GS_BC (s390 guarded-storage broadcast control)"); | |
18583 | case NT_ARM_VFP: | |
18584 | return _("NT_ARM_VFP (arm VFP registers)"); | |
18585 | case NT_ARM_TLS: | |
18586 | return _("NT_ARM_TLS (AArch TLS registers)"); | |
18587 | case NT_ARM_HW_BREAK: | |
18588 | return _("NT_ARM_HW_BREAK (AArch hardware breakpoint registers)"); | |
18589 | case NT_ARM_HW_WATCH: | |
18590 | return _("NT_ARM_HW_WATCH (AArch hardware watchpoint registers)"); | |
18591 | case NT_ARC_V2: | |
18592 | return _("NT_ARC_V2 (ARC HS accumulator/extra registers)"); | |
18593 | case NT_RISCV_CSR: | |
18594 | return _("NT_RISCV_CSR (RISC-V control and status registers)"); | |
18595 | case NT_PSTATUS: | |
18596 | return _("NT_PSTATUS (pstatus structure)"); | |
18597 | case NT_FPREGS: | |
18598 | return _("NT_FPREGS (floating point registers)"); | |
18599 | case NT_PSINFO: | |
18600 | return _("NT_PSINFO (psinfo structure)"); | |
18601 | case NT_LWPSTATUS: | |
18602 | return _("NT_LWPSTATUS (lwpstatus_t structure)"); | |
18603 | case NT_LWPSINFO: | |
18604 | return _("NT_LWPSINFO (lwpsinfo_t structure)"); | |
18605 | case NT_WIN32PSTATUS: | |
18606 | return _("NT_WIN32PSTATUS (win32_pstatus structure)"); | |
18607 | case NT_SIGINFO: | |
18608 | return _("NT_SIGINFO (siginfo_t data)"); | |
18609 | case NT_FILE: | |
18610 | return _("NT_FILE (mapped files)"); | |
18611 | default: | |
18612 | break; | |
18613 | } | |
18614 | else | |
18615 | switch (e_type) | |
18616 | { | |
18617 | case NT_VERSION: | |
18618 | return _("NT_VERSION (version)"); | |
18619 | case NT_ARCH: | |
18620 | return _("NT_ARCH (architecture)"); | |
18621 | case NT_GNU_BUILD_ATTRIBUTE_OPEN: | |
18622 | return _("OPEN"); | |
18623 | case NT_GNU_BUILD_ATTRIBUTE_FUNC: | |
18624 | return _("func"); | |
18625 | default: | |
18626 | break; | |
18627 | } | |
18628 | ||
18629 | snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type); | |
18630 | return buff; | |
18631 | } | |
18632 | ||
18633 | static bfd_boolean | |
18634 | print_core_note (Elf_Internal_Note *pnote) | |
18635 | { | |
18636 | unsigned int addr_size = is_32bit_elf ? 4 : 8; | |
18637 | bfd_vma count, page_size; | |
18638 | unsigned char *descdata, *filenames, *descend; | |
18639 | ||
18640 | if (pnote->type != NT_FILE) | |
18641 | { | |
18642 | if (do_wide) | |
18643 | printf ("\n"); | |
18644 | return TRUE; | |
18645 | } | |
18646 | ||
18647 | #ifndef BFD64 | |
18648 | if (!is_32bit_elf) | |
18649 | { | |
18650 | printf (_(" Cannot decode 64-bit note in 32-bit build\n")); | |
18651 | /* Still "successful". */ | |
18652 | return TRUE; | |
18653 | } | |
18654 | #endif | |
18655 | ||
18656 | if (pnote->descsz < 2 * addr_size) | |
18657 | { | |
18658 | error (_(" Malformed note - too short for header\n")); | |
18659 | return FALSE; | |
18660 | } | |
18661 | ||
18662 | descdata = (unsigned char *) pnote->descdata; | |
18663 | descend = descdata + pnote->descsz; | |
18664 | ||
18665 | if (descdata[pnote->descsz - 1] != '\0') | |
18666 | { | |
18667 | error (_(" Malformed note - does not end with \\0\n")); | |
18668 | return FALSE; | |
18669 | } | |
18670 | ||
18671 | count = byte_get (descdata, addr_size); | |
18672 | descdata += addr_size; | |
18673 | ||
18674 | page_size = byte_get (descdata, addr_size); | |
18675 | descdata += addr_size; | |
18676 | ||
18677 | if (count > ((bfd_vma) -1 - 2 * addr_size) / (3 * addr_size) | |
18678 | || pnote->descsz < 2 * addr_size + count * 3 * addr_size) | |
18679 | { | |
18680 | error (_(" Malformed note - too short for supplied file count\n")); | |
18681 | return FALSE; | |
18682 | } | |
18683 | ||
18684 | printf (_(" Page size: ")); | |
18685 | print_vma (page_size, DEC); | |
18686 | printf ("\n"); | |
18687 | ||
18688 | printf (_(" %*s%*s%*s\n"), | |
18689 | (int) (2 + 2 * addr_size), _("Start"), | |
18690 | (int) (4 + 2 * addr_size), _("End"), | |
18691 | (int) (4 + 2 * addr_size), _("Page Offset")); | |
18692 | filenames = descdata + count * 3 * addr_size; | |
18693 | while (count-- > 0) | |
18694 | { | |
18695 | bfd_vma start, end, file_ofs; | |
18696 | ||
18697 | if (filenames == descend) | |
18698 | { | |
18699 | error (_(" Malformed note - filenames end too early\n")); | |
18700 | return FALSE; | |
18701 | } | |
18702 | ||
18703 | start = byte_get (descdata, addr_size); | |
18704 | descdata += addr_size; | |
18705 | end = byte_get (descdata, addr_size); | |
18706 | descdata += addr_size; | |
18707 | file_ofs = byte_get (descdata, addr_size); | |
18708 | descdata += addr_size; | |
18709 | ||
18710 | printf (" "); | |
18711 | print_vma (start, FULL_HEX); | |
18712 | printf (" "); | |
18713 | print_vma (end, FULL_HEX); | |
18714 | printf (" "); | |
18715 | print_vma (file_ofs, FULL_HEX); | |
18716 | printf ("\n %s\n", filenames); | |
18717 | ||
18718 | filenames += 1 + strlen ((char *) filenames); | |
18719 | } | |
18720 | ||
18721 | return TRUE; | |
18722 | } | |
18723 | ||
18724 | static const char * | |
18725 | get_gnu_elf_note_type (unsigned e_type) | |
18726 | { | |
18727 | /* NB/ Keep this switch statement in sync with print_gnu_note (). */ | |
18728 | switch (e_type) | |
18729 | { | |
18730 | case NT_GNU_ABI_TAG: | |
18731 | return _("NT_GNU_ABI_TAG (ABI version tag)"); | |
18732 | case NT_GNU_HWCAP: | |
18733 | return _("NT_GNU_HWCAP (DSO-supplied software HWCAP info)"); | |
18734 | case NT_GNU_BUILD_ID: | |
18735 | return _("NT_GNU_BUILD_ID (unique build ID bitstring)"); | |
18736 | case NT_GNU_GOLD_VERSION: | |
18737 | return _("NT_GNU_GOLD_VERSION (gold version)"); | |
18738 | case NT_GNU_PROPERTY_TYPE_0: | |
18739 | return _("NT_GNU_PROPERTY_TYPE_0"); | |
18740 | case NT_GNU_BUILD_ATTRIBUTE_OPEN: | |
18741 | return _("NT_GNU_BUILD_ATTRIBUTE_OPEN"); | |
18742 | case NT_GNU_BUILD_ATTRIBUTE_FUNC: | |
18743 | return _("NT_GNU_BUILD_ATTRIBUTE_FUNC"); | |
18744 | default: | |
18745 | { | |
18746 | static char buff[64]; | |
18747 | ||
18748 | snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type); | |
18749 | return buff; | |
18750 | } | |
18751 | } | |
18752 | } | |
18753 | ||
18754 | static void | |
18755 | decode_x86_compat_isa (unsigned int bitmask) | |
18756 | { | |
18757 | while (bitmask) | |
18758 | { | |
18759 | unsigned int bit = bitmask & (- bitmask); | |
18760 | ||
18761 | bitmask &= ~ bit; | |
18762 | switch (bit) | |
18763 | { | |
18764 | case GNU_PROPERTY_X86_COMPAT_ISA_1_486: | |
18765 | printf ("i486"); | |
18766 | break; | |
18767 | case GNU_PROPERTY_X86_COMPAT_ISA_1_586: | |
18768 | printf ("586"); | |
18769 | break; | |
18770 | case GNU_PROPERTY_X86_COMPAT_ISA_1_686: | |
18771 | printf ("686"); | |
18772 | break; | |
18773 | case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE: | |
18774 | printf ("SSE"); | |
18775 | break; | |
18776 | case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE2: | |
18777 | printf ("SSE2"); | |
18778 | break; | |
18779 | case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE3: | |
18780 | printf ("SSE3"); | |
18781 | break; | |
18782 | case GNU_PROPERTY_X86_COMPAT_ISA_1_SSSE3: | |
18783 | printf ("SSSE3"); | |
18784 | break; | |
18785 | case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE4_1: | |
18786 | printf ("SSE4_1"); | |
18787 | break; | |
18788 | case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE4_2: | |
18789 | printf ("SSE4_2"); | |
18790 | break; | |
18791 | case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX: | |
18792 | printf ("AVX"); | |
18793 | break; | |
18794 | case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX2: | |
18795 | printf ("AVX2"); | |
18796 | break; | |
18797 | case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512F: | |
18798 | printf ("AVX512F"); | |
18799 | break; | |
18800 | case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512CD: | |
18801 | printf ("AVX512CD"); | |
18802 | break; | |
18803 | case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512ER: | |
18804 | printf ("AVX512ER"); | |
18805 | break; | |
18806 | case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512PF: | |
18807 | printf ("AVX512PF"); | |
18808 | break; | |
18809 | case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512VL: | |
18810 | printf ("AVX512VL"); | |
18811 | break; | |
18812 | case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512DQ: | |
18813 | printf ("AVX512DQ"); | |
18814 | break; | |
18815 | case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512BW: | |
18816 | printf ("AVX512BW"); | |
18817 | break; | |
18818 | default: | |
18819 | printf (_("<unknown: %x>"), bit); | |
18820 | break; | |
18821 | } | |
18822 | if (bitmask) | |
18823 | printf (", "); | |
18824 | } | |
18825 | } | |
18826 | ||
18827 | static void | |
18828 | decode_x86_compat_2_isa (unsigned int bitmask) | |
18829 | { | |
18830 | if (!bitmask) | |
18831 | { | |
18832 | printf (_("<None>")); | |
18833 | return; | |
18834 | } | |
18835 | ||
18836 | while (bitmask) | |
18837 | { | |
18838 | unsigned int bit = bitmask & (- bitmask); | |
18839 | ||
18840 | bitmask &= ~ bit; | |
18841 | switch (bit) | |
18842 | { | |
18843 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_CMOV: | |
18844 | printf ("CMOV"); | |
18845 | break; | |
18846 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE: | |
18847 | printf ("SSE"); | |
18848 | break; | |
18849 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE2: | |
18850 | printf ("SSE2"); | |
18851 | break; | |
18852 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE3: | |
18853 | printf ("SSE3"); | |
18854 | break; | |
18855 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSSE3: | |
18856 | printf ("SSSE3"); | |
18857 | break; | |
18858 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE4_1: | |
18859 | printf ("SSE4_1"); | |
18860 | break; | |
18861 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE4_2: | |
18862 | printf ("SSE4_2"); | |
18863 | break; | |
18864 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX: | |
18865 | printf ("AVX"); | |
18866 | break; | |
18867 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX2: | |
18868 | printf ("AVX2"); | |
18869 | break; | |
18870 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_FMA: | |
18871 | printf ("FMA"); | |
18872 | break; | |
18873 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512F: | |
18874 | printf ("AVX512F"); | |
18875 | break; | |
18876 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512CD: | |
18877 | printf ("AVX512CD"); | |
18878 | break; | |
18879 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512ER: | |
18880 | printf ("AVX512ER"); | |
18881 | break; | |
18882 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512PF: | |
18883 | printf ("AVX512PF"); | |
18884 | break; | |
18885 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512VL: | |
18886 | printf ("AVX512VL"); | |
18887 | break; | |
18888 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512DQ: | |
18889 | printf ("AVX512DQ"); | |
18890 | break; | |
18891 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512BW: | |
18892 | printf ("AVX512BW"); | |
18893 | break; | |
18894 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_4FMAPS: | |
18895 | printf ("AVX512_4FMAPS"); | |
18896 | break; | |
18897 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_4VNNIW: | |
18898 | printf ("AVX512_4VNNIW"); | |
18899 | break; | |
18900 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_BITALG: | |
18901 | printf ("AVX512_BITALG"); | |
18902 | break; | |
18903 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_IFMA: | |
18904 | printf ("AVX512_IFMA"); | |
18905 | break; | |
18906 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_VBMI: | |
18907 | printf ("AVX512_VBMI"); | |
18908 | break; | |
18909 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_VBMI2: | |
18910 | printf ("AVX512_VBMI2"); | |
18911 | break; | |
18912 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_VNNI: | |
18913 | printf ("AVX512_VNNI"); | |
18914 | break; | |
18915 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_BF16: | |
18916 | printf ("AVX512_BF16"); | |
18917 | break; | |
18918 | default: | |
18919 | printf (_("<unknown: %x>"), bit); | |
18920 | break; | |
18921 | } | |
18922 | if (bitmask) | |
18923 | printf (", "); | |
18924 | } | |
18925 | } | |
18926 | ||
18927 | static void | |
18928 | decode_x86_isa (unsigned int bitmask) | |
18929 | { | |
18930 | while (bitmask) | |
18931 | { | |
18932 | unsigned int bit = bitmask & (- bitmask); | |
18933 | ||
18934 | bitmask &= ~ bit; | |
18935 | switch (bit) | |
18936 | { | |
18937 | case GNU_PROPERTY_X86_ISA_1_BASELINE: | |
18938 | printf ("x86-64-baseline"); | |
18939 | break; | |
18940 | case GNU_PROPERTY_X86_ISA_1_V2: | |
18941 | printf ("x86-64-v2"); | |
18942 | break; | |
18943 | case GNU_PROPERTY_X86_ISA_1_V3: | |
18944 | printf ("x86-64-v3"); | |
18945 | break; | |
18946 | case GNU_PROPERTY_X86_ISA_1_V4: | |
18947 | printf ("x86-64-v4"); | |
18948 | break; | |
18949 | default: | |
18950 | printf (_("<unknown: %x>"), bit); | |
18951 | break; | |
18952 | } | |
18953 | if (bitmask) | |
18954 | printf (", "); | |
18955 | } | |
18956 | } | |
18957 | ||
18958 | static void | |
18959 | decode_x86_feature_1 (unsigned int bitmask) | |
18960 | { | |
18961 | if (!bitmask) | |
18962 | { | |
18963 | printf (_("<None>")); | |
18964 | return; | |
18965 | } | |
18966 | ||
18967 | while (bitmask) | |
18968 | { | |
18969 | unsigned int bit = bitmask & (- bitmask); | |
18970 | ||
18971 | bitmask &= ~ bit; | |
18972 | switch (bit) | |
18973 | { | |
18974 | case GNU_PROPERTY_X86_FEATURE_1_IBT: | |
18975 | printf ("IBT"); | |
18976 | break; | |
18977 | case GNU_PROPERTY_X86_FEATURE_1_SHSTK: | |
18978 | printf ("SHSTK"); | |
18979 | break; | |
18980 | case GNU_PROPERTY_X86_FEATURE_1_LAM_U48: | |
18981 | printf ("LAM_U48"); | |
18982 | break; | |
18983 | case GNU_PROPERTY_X86_FEATURE_1_LAM_U57: | |
18984 | printf ("LAM_U57"); | |
18985 | break; | |
18986 | default: | |
18987 | printf (_("<unknown: %x>"), bit); | |
18988 | break; | |
18989 | } | |
18990 | if (bitmask) | |
18991 | printf (", "); | |
18992 | } | |
18993 | } | |
18994 | ||
18995 | static void | |
18996 | decode_x86_feature_2 (unsigned int bitmask) | |
18997 | { | |
18998 | if (!bitmask) | |
18999 | { | |
19000 | printf (_("<None>")); | |
19001 | return; | |
19002 | } | |
19003 | ||
19004 | while (bitmask) | |
19005 | { | |
19006 | unsigned int bit = bitmask & (- bitmask); | |
19007 | ||
19008 | bitmask &= ~ bit; | |
19009 | switch (bit) | |
19010 | { | |
19011 | case GNU_PROPERTY_X86_FEATURE_2_X86: | |
19012 | printf ("x86"); | |
19013 | break; | |
19014 | case GNU_PROPERTY_X86_FEATURE_2_X87: | |
19015 | printf ("x87"); | |
19016 | break; | |
19017 | case GNU_PROPERTY_X86_FEATURE_2_MMX: | |
19018 | printf ("MMX"); | |
19019 | break; | |
19020 | case GNU_PROPERTY_X86_FEATURE_2_XMM: | |
19021 | printf ("XMM"); | |
19022 | break; | |
19023 | case GNU_PROPERTY_X86_FEATURE_2_YMM: | |
19024 | printf ("YMM"); | |
19025 | break; | |
19026 | case GNU_PROPERTY_X86_FEATURE_2_ZMM: | |
19027 | printf ("ZMM"); | |
19028 | break; | |
19029 | case GNU_PROPERTY_X86_FEATURE_2_TMM: | |
19030 | printf ("TMM"); | |
19031 | break; | |
19032 | case GNU_PROPERTY_X86_FEATURE_2_MASK: | |
19033 | printf ("MASK"); | |
19034 | break; | |
19035 | case GNU_PROPERTY_X86_FEATURE_2_FXSR: | |
19036 | printf ("FXSR"); | |
19037 | break; | |
19038 | case GNU_PROPERTY_X86_FEATURE_2_XSAVE: | |
19039 | printf ("XSAVE"); | |
19040 | break; | |
19041 | case GNU_PROPERTY_X86_FEATURE_2_XSAVEOPT: | |
19042 | printf ("XSAVEOPT"); | |
19043 | break; | |
19044 | case GNU_PROPERTY_X86_FEATURE_2_XSAVEC: | |
19045 | printf ("XSAVEC"); | |
19046 | break; | |
19047 | default: | |
19048 | printf (_("<unknown: %x>"), bit); | |
19049 | break; | |
19050 | } | |
19051 | if (bitmask) | |
19052 | printf (", "); | |
19053 | } | |
19054 | } | |
19055 | ||
19056 | static void | |
19057 | decode_aarch64_feature_1_and (unsigned int bitmask) | |
19058 | { | |
19059 | while (bitmask) | |
19060 | { | |
19061 | unsigned int bit = bitmask & (- bitmask); | |
19062 | ||
19063 | bitmask &= ~ bit; | |
19064 | switch (bit) | |
19065 | { | |
19066 | case GNU_PROPERTY_AARCH64_FEATURE_1_BTI: | |
19067 | printf ("BTI"); | |
19068 | break; | |
19069 | ||
19070 | case GNU_PROPERTY_AARCH64_FEATURE_1_PAC: | |
19071 | printf ("PAC"); | |
19072 | break; | |
19073 | ||
19074 | default: | |
19075 | printf (_("<unknown: %x>"), bit); | |
19076 | break; | |
19077 | } | |
19078 | if (bitmask) | |
19079 | printf (", "); | |
19080 | } | |
19081 | } | |
19082 | ||
19083 | static void | |
19084 | print_gnu_property_note (Filedata * filedata, Elf_Internal_Note * pnote) | |
19085 | { | |
19086 | unsigned char * ptr = (unsigned char *) pnote->descdata; | |
19087 | unsigned char * ptr_end = ptr + pnote->descsz; | |
19088 | unsigned int size = is_32bit_elf ? 4 : 8; | |
19089 | ||
19090 | printf (_(" Properties: ")); | |
19091 | ||
19092 | if (pnote->descsz < 8 || (pnote->descsz % size) != 0) | |
19093 | { | |
19094 | printf (_("<corrupt GNU_PROPERTY_TYPE, size = %#lx>\n"), pnote->descsz); | |
19095 | return; | |
19096 | } | |
19097 | ||
19098 | while (ptr < ptr_end) | |
19099 | { | |
19100 | unsigned int j; | |
19101 | unsigned int type; | |
19102 | unsigned int datasz; | |
19103 | ||
19104 | if ((size_t) (ptr_end - ptr) < 8) | |
19105 | { | |
19106 | printf (_("<corrupt descsz: %#lx>\n"), pnote->descsz); | |
19107 | break; | |
19108 | } | |
19109 | ||
19110 | type = byte_get (ptr, 4); | |
19111 | datasz = byte_get (ptr + 4, 4); | |
19112 | ||
19113 | ptr += 8; | |
19114 | ||
19115 | if (datasz > (size_t) (ptr_end - ptr)) | |
19116 | { | |
19117 | printf (_("<corrupt type (%#x) datasz: %#x>\n"), | |
19118 | type, datasz); | |
19119 | break; | |
19120 | } | |
19121 | ||
19122 | if (type >= GNU_PROPERTY_LOPROC && type <= GNU_PROPERTY_HIPROC) | |
19123 | { | |
19124 | if (filedata->file_header.e_machine == EM_X86_64 | |
19125 | || filedata->file_header.e_machine == EM_IAMCU | |
19126 | || filedata->file_header.e_machine == EM_386) | |
19127 | { | |
19128 | unsigned int bitmask; | |
19129 | ||
19130 | if (datasz == 4) | |
19131 | bitmask = byte_get (ptr, 4); | |
19132 | else | |
19133 | bitmask = 0; | |
19134 | ||
19135 | switch (type) | |
19136 | { | |
19137 | case GNU_PROPERTY_X86_ISA_1_USED: | |
19138 | if (datasz != 4) | |
19139 | printf (_("x86 ISA used: <corrupt length: %#x> "), | |
19140 | datasz); | |
19141 | else | |
19142 | { | |
19143 | printf ("x86 ISA used: "); | |
19144 | decode_x86_isa (bitmask); | |
19145 | } | |
19146 | goto next; | |
19147 | ||
19148 | case GNU_PROPERTY_X86_ISA_1_NEEDED: | |
19149 | if (datasz != 4) | |
19150 | printf (_("x86 ISA needed: <corrupt length: %#x> "), | |
19151 | datasz); | |
19152 | else | |
19153 | { | |
19154 | printf ("x86 ISA needed: "); | |
19155 | decode_x86_isa (bitmask); | |
19156 | } | |
19157 | goto next; | |
19158 | ||
19159 | case GNU_PROPERTY_X86_FEATURE_1_AND: | |
19160 | if (datasz != 4) | |
19161 | printf (_("x86 feature: <corrupt length: %#x> "), | |
19162 | datasz); | |
19163 | else | |
19164 | { | |
19165 | printf ("x86 feature: "); | |
19166 | decode_x86_feature_1 (bitmask); | |
19167 | } | |
19168 | goto next; | |
19169 | ||
19170 | case GNU_PROPERTY_X86_FEATURE_2_USED: | |
19171 | if (datasz != 4) | |
19172 | printf (_("x86 feature used: <corrupt length: %#x> "), | |
19173 | datasz); | |
19174 | else | |
19175 | { | |
19176 | printf ("x86 feature used: "); | |
19177 | decode_x86_feature_2 (bitmask); | |
19178 | } | |
19179 | goto next; | |
19180 | ||
19181 | case GNU_PROPERTY_X86_FEATURE_2_NEEDED: | |
19182 | if (datasz != 4) | |
19183 | printf (_("x86 feature needed: <corrupt length: %#x> "), datasz); | |
19184 | else | |
19185 | { | |
19186 | printf ("x86 feature needed: "); | |
19187 | decode_x86_feature_2 (bitmask); | |
19188 | } | |
19189 | goto next; | |
19190 | ||
19191 | case GNU_PROPERTY_X86_COMPAT_ISA_1_USED: | |
19192 | if (datasz != 4) | |
19193 | printf (_("x86 ISA used: <corrupt length: %#x> "), | |
19194 | datasz); | |
19195 | else | |
19196 | { | |
19197 | printf ("x86 ISA used: "); | |
19198 | decode_x86_compat_isa (bitmask); | |
19199 | } | |
19200 | goto next; | |
19201 | ||
19202 | case GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED: | |
19203 | if (datasz != 4) | |
19204 | printf (_("x86 ISA needed: <corrupt length: %#x> "), | |
19205 | datasz); | |
19206 | else | |
19207 | { | |
19208 | printf ("x86 ISA needed: "); | |
19209 | decode_x86_compat_isa (bitmask); | |
19210 | } | |
19211 | goto next; | |
19212 | ||
19213 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_USED: | |
19214 | if (datasz != 4) | |
19215 | printf (_("x86 ISA used: <corrupt length: %#x> "), | |
19216 | datasz); | |
19217 | else | |
19218 | { | |
19219 | printf ("x86 ISA used: "); | |
19220 | decode_x86_compat_2_isa (bitmask); | |
19221 | } | |
19222 | goto next; | |
19223 | ||
19224 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_NEEDED: | |
19225 | if (datasz != 4) | |
19226 | printf (_("x86 ISA needed: <corrupt length: %#x> "), | |
19227 | datasz); | |
19228 | else | |
19229 | { | |
19230 | printf ("x86 ISA needed: "); | |
19231 | decode_x86_compat_2_isa (bitmask); | |
19232 | } | |
19233 | goto next; | |
19234 | ||
19235 | default: | |
19236 | break; | |
19237 | } | |
19238 | } | |
19239 | else if (filedata->file_header.e_machine == EM_AARCH64) | |
19240 | { | |
19241 | if (type == GNU_PROPERTY_AARCH64_FEATURE_1_AND) | |
19242 | { | |
19243 | printf ("AArch64 feature: "); | |
19244 | if (datasz != 4) | |
19245 | printf (_("<corrupt length: %#x> "), datasz); | |
19246 | else | |
19247 | decode_aarch64_feature_1_and (byte_get (ptr, 4)); | |
19248 | goto next; | |
19249 | } | |
19250 | } | |
19251 | } | |
19252 | else | |
19253 | { | |
19254 | switch (type) | |
19255 | { | |
19256 | case GNU_PROPERTY_STACK_SIZE: | |
19257 | printf (_("stack size: ")); | |
19258 | if (datasz != size) | |
19259 | printf (_("<corrupt length: %#x> "), datasz); | |
19260 | else | |
19261 | printf ("%#lx", (unsigned long) byte_get (ptr, size)); | |
19262 | goto next; | |
19263 | ||
19264 | case GNU_PROPERTY_NO_COPY_ON_PROTECTED: | |
19265 | printf ("no copy on protected "); | |
19266 | if (datasz) | |
19267 | printf (_("<corrupt length: %#x> "), datasz); | |
19268 | goto next; | |
19269 | ||
19270 | default: | |
19271 | break; | |
19272 | } | |
19273 | } | |
19274 | ||
19275 | if (type < GNU_PROPERTY_LOPROC) | |
19276 | printf (_("<unknown type %#x data: "), type); | |
19277 | else if (type < GNU_PROPERTY_LOUSER) | |
19278 | printf (_("<processor-specific type %#x data: "), type); | |
19279 | else | |
19280 | printf (_("<application-specific type %#x data: "), type); | |
19281 | for (j = 0; j < datasz; ++j) | |
19282 | printf ("%02x ", ptr[j] & 0xff); | |
19283 | printf (">"); | |
19284 | ||
19285 | next: | |
19286 | ptr += ((datasz + (size - 1)) & ~ (size - 1)); | |
19287 | if (ptr == ptr_end) | |
19288 | break; | |
19289 | ||
19290 | if (do_wide) | |
19291 | printf (", "); | |
19292 | else | |
19293 | printf ("\n\t"); | |
19294 | } | |
19295 | ||
19296 | printf ("\n"); | |
19297 | } | |
19298 | ||
19299 | static bfd_boolean | |
19300 | print_gnu_note (Filedata * filedata, Elf_Internal_Note *pnote) | |
19301 | { | |
19302 | /* NB/ Keep this switch statement in sync with get_gnu_elf_note_type (). */ | |
19303 | switch (pnote->type) | |
19304 | { | |
19305 | case NT_GNU_BUILD_ID: | |
19306 | { | |
19307 | unsigned long i; | |
19308 | ||
19309 | printf (_(" Build ID: ")); | |
19310 | for (i = 0; i < pnote->descsz; ++i) | |
19311 | printf ("%02x", pnote->descdata[i] & 0xff); | |
19312 | printf ("\n"); | |
19313 | } | |
19314 | break; | |
19315 | ||
19316 | case NT_GNU_ABI_TAG: | |
19317 | { | |
19318 | unsigned long os, major, minor, subminor; | |
19319 | const char *osname; | |
19320 | ||
19321 | /* PR 17531: file: 030-599401-0.004. */ | |
19322 | if (pnote->descsz < 16) | |
19323 | { | |
19324 | printf (_(" <corrupt GNU_ABI_TAG>\n")); | |
19325 | break; | |
19326 | } | |
19327 | ||
19328 | os = byte_get ((unsigned char *) pnote->descdata, 4); | |
19329 | major = byte_get ((unsigned char *) pnote->descdata + 4, 4); | |
19330 | minor = byte_get ((unsigned char *) pnote->descdata + 8, 4); | |
19331 | subminor = byte_get ((unsigned char *) pnote->descdata + 12, 4); | |
19332 | ||
19333 | switch (os) | |
19334 | { | |
19335 | case GNU_ABI_TAG_LINUX: | |
19336 | osname = "Linux"; | |
19337 | break; | |
19338 | case GNU_ABI_TAG_HURD: | |
19339 | osname = "Hurd"; | |
19340 | break; | |
19341 | case GNU_ABI_TAG_SOLARIS: | |
19342 | osname = "Solaris"; | |
19343 | break; | |
19344 | case GNU_ABI_TAG_FREEBSD: | |
19345 | osname = "FreeBSD"; | |
19346 | break; | |
19347 | case GNU_ABI_TAG_NETBSD: | |
19348 | osname = "NetBSD"; | |
19349 | break; | |
19350 | case GNU_ABI_TAG_SYLLABLE: | |
19351 | osname = "Syllable"; | |
19352 | break; | |
19353 | case GNU_ABI_TAG_NACL: | |
19354 | osname = "NaCl"; | |
19355 | break; | |
19356 | default: | |
19357 | osname = "Unknown"; | |
19358 | break; | |
19359 | } | |
19360 | ||
19361 | printf (_(" OS: %s, ABI: %ld.%ld.%ld\n"), osname, | |
19362 | major, minor, subminor); | |
19363 | } | |
19364 | break; | |
19365 | ||
19366 | case NT_GNU_GOLD_VERSION: | |
19367 | { | |
19368 | unsigned long i; | |
19369 | ||
19370 | printf (_(" Version: ")); | |
19371 | for (i = 0; i < pnote->descsz && pnote->descdata[i] != '\0'; ++i) | |
19372 | printf ("%c", pnote->descdata[i]); | |
19373 | printf ("\n"); | |
19374 | } | |
19375 | break; | |
19376 | ||
19377 | case NT_GNU_HWCAP: | |
19378 | { | |
19379 | unsigned long num_entries, mask; | |
19380 | ||
19381 | /* Hardware capabilities information. Word 0 is the number of entries. | |
19382 | Word 1 is a bitmask of enabled entries. The rest of the descriptor | |
19383 | is a series of entries, where each entry is a single byte followed | |
19384 | by a nul terminated string. The byte gives the bit number to test | |
19385 | if enabled in the bitmask. */ | |
19386 | printf (_(" Hardware Capabilities: ")); | |
19387 | if (pnote->descsz < 8) | |
19388 | { | |
19389 | error (_("<corrupt GNU_HWCAP>\n")); | |
19390 | return FALSE; | |
19391 | } | |
19392 | num_entries = byte_get ((unsigned char *) pnote->descdata, 4); | |
19393 | mask = byte_get ((unsigned char *) pnote->descdata + 4, 4); | |
19394 | printf (_("num entries: %ld, enabled mask: %lx\n"), num_entries, mask); | |
19395 | /* FIXME: Add code to display the entries... */ | |
19396 | } | |
19397 | break; | |
19398 | ||
19399 | case NT_GNU_PROPERTY_TYPE_0: | |
19400 | print_gnu_property_note (filedata, pnote); | |
19401 | break; | |
19402 | ||
19403 | default: | |
19404 | /* Handle unrecognised types. An error message should have already been | |
19405 | created by get_gnu_elf_note_type(), so all that we need to do is to | |
19406 | display the data. */ | |
19407 | { | |
19408 | unsigned long i; | |
19409 | ||
19410 | printf (_(" Description data: ")); | |
19411 | for (i = 0; i < pnote->descsz; ++i) | |
19412 | printf ("%02x ", pnote->descdata[i] & 0xff); | |
19413 | printf ("\n"); | |
19414 | } | |
19415 | break; | |
19416 | } | |
19417 | ||
19418 | return TRUE; | |
19419 | } | |
19420 | ||
19421 | static const char * | |
19422 | get_v850_elf_note_type (enum v850_notes n_type) | |
19423 | { | |
19424 | static char buff[64]; | |
19425 | ||
19426 | switch (n_type) | |
19427 | { | |
19428 | case V850_NOTE_ALIGNMENT: return _("Alignment of 8-byte objects"); | |
19429 | case V850_NOTE_DATA_SIZE: return _("Sizeof double and long double"); | |
19430 | case V850_NOTE_FPU_INFO: return _("Type of FPU support needed"); | |
19431 | case V850_NOTE_SIMD_INFO: return _("Use of SIMD instructions"); | |
19432 | case V850_NOTE_CACHE_INFO: return _("Use of cache"); | |
19433 | case V850_NOTE_MMU_INFO: return _("Use of MMU"); | |
19434 | default: | |
19435 | snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), n_type); | |
19436 | return buff; | |
19437 | } | |
19438 | } | |
19439 | ||
19440 | static bfd_boolean | |
19441 | print_v850_note (Elf_Internal_Note * pnote) | |
19442 | { | |
19443 | unsigned int val; | |
19444 | ||
19445 | if (pnote->descsz != 4) | |
19446 | return FALSE; | |
19447 | ||
19448 | val = byte_get ((unsigned char *) pnote->descdata, pnote->descsz); | |
19449 | ||
19450 | if (val == 0) | |
19451 | { | |
19452 | printf (_("not set\n")); | |
19453 | return TRUE; | |
19454 | } | |
19455 | ||
19456 | switch (pnote->type) | |
19457 | { | |
19458 | case V850_NOTE_ALIGNMENT: | |
19459 | switch (val) | |
19460 | { | |
19461 | case EF_RH850_DATA_ALIGN4: printf (_("4-byte\n")); return TRUE; | |
19462 | case EF_RH850_DATA_ALIGN8: printf (_("8-byte\n")); return TRUE; | |
19463 | } | |
19464 | break; | |
19465 | ||
19466 | case V850_NOTE_DATA_SIZE: | |
19467 | switch (val) | |
19468 | { | |
19469 | case EF_RH850_DOUBLE32: printf (_("4-bytes\n")); return TRUE; | |
19470 | case EF_RH850_DOUBLE64: printf (_("8-bytes\n")); return TRUE; | |
19471 | } | |
19472 | break; | |
19473 | ||
19474 | case V850_NOTE_FPU_INFO: | |
19475 | switch (val) | |
19476 | { | |
19477 | case EF_RH850_FPU20: printf (_("FPU-2.0\n")); return TRUE; | |
19478 | case EF_RH850_FPU30: printf (_("FPU-3.0\n")); return TRUE; | |
19479 | } | |
19480 | break; | |
19481 | ||
19482 | case V850_NOTE_MMU_INFO: | |
19483 | case V850_NOTE_CACHE_INFO: | |
19484 | case V850_NOTE_SIMD_INFO: | |
19485 | if (val == EF_RH850_SIMD) | |
19486 | { | |
19487 | printf (_("yes\n")); | |
19488 | return TRUE; | |
19489 | } | |
19490 | break; | |
19491 | ||
19492 | default: | |
19493 | /* An 'unknown note type' message will already have been displayed. */ | |
19494 | break; | |
19495 | } | |
19496 | ||
19497 | printf (_("unknown value: %x\n"), val); | |
19498 | return FALSE; | |
19499 | } | |
19500 | ||
19501 | static bfd_boolean | |
19502 | process_netbsd_elf_note (Elf_Internal_Note * pnote) | |
19503 | { | |
19504 | unsigned int version; | |
19505 | ||
19506 | switch (pnote->type) | |
19507 | { | |
19508 | case NT_NETBSD_IDENT: | |
19509 | if (pnote->descsz < 1) | |
19510 | break; | |
19511 | version = byte_get ((unsigned char *) pnote->descdata, sizeof (version)); | |
19512 | if ((version / 10000) % 100) | |
19513 | printf (" NetBSD\t\t0x%08lx\tIDENT %u (%u.%u%s%c)\n", pnote->descsz, | |
19514 | version, version / 100000000, (version / 1000000) % 100, | |
19515 | (version / 10000) % 100 > 26 ? "Z" : "", | |
19516 | 'A' + (version / 10000) % 26); | |
19517 | else | |
19518 | printf (" NetBSD\t\t0x%08lx\tIDENT %u (%u.%u.%u)\n", pnote->descsz, | |
19519 | version, version / 100000000, (version / 1000000) % 100, | |
19520 | (version / 100) % 100); | |
19521 | return TRUE; | |
19522 | ||
19523 | case NT_NETBSD_MARCH: | |
19524 | printf (" NetBSD\t\t0x%08lx\tMARCH <%s>\n", pnote->descsz, | |
19525 | pnote->descdata); | |
19526 | return TRUE; | |
19527 | ||
19528 | #ifdef NT_NETBSD_PAX | |
19529 | case NT_NETBSD_PAX: | |
19530 | if (pnote->descsz < 1) | |
19531 | break; | |
19532 | version = byte_get ((unsigned char *) pnote->descdata, sizeof (version)); | |
19533 | printf (" NetBSD\t\t0x%08lx\tPaX <%s%s%s%s%s%s>\n", pnote->descsz, | |
19534 | ((version & NT_NETBSD_PAX_MPROTECT) ? "+mprotect" : ""), | |
19535 | ((version & NT_NETBSD_PAX_NOMPROTECT) ? "-mprotect" : ""), | |
19536 | ((version & NT_NETBSD_PAX_GUARD) ? "+guard" : ""), | |
19537 | ((version & NT_NETBSD_PAX_NOGUARD) ? "-guard" : ""), | |
19538 | ((version & NT_NETBSD_PAX_ASLR) ? "+ASLR" : ""), | |
19539 | ((version & NT_NETBSD_PAX_NOASLR) ? "-ASLR" : "")); | |
19540 | return TRUE; | |
19541 | #endif | |
19542 | } | |
19543 | ||
19544 | printf (" NetBSD\t0x%08lx\tUnknown note type: (0x%08lx)\n", | |
19545 | pnote->descsz, pnote->type); | |
19546 | return FALSE; | |
19547 | } | |
19548 | ||
19549 | static const char * | |
19550 | get_freebsd_elfcore_note_type (Filedata * filedata, unsigned e_type) | |
19551 | { | |
19552 | switch (e_type) | |
19553 | { | |
19554 | case NT_FREEBSD_THRMISC: | |
19555 | return _("NT_THRMISC (thrmisc structure)"); | |
19556 | case NT_FREEBSD_PROCSTAT_PROC: | |
19557 | return _("NT_PROCSTAT_PROC (proc data)"); | |
19558 | case NT_FREEBSD_PROCSTAT_FILES: | |
19559 | return _("NT_PROCSTAT_FILES (files data)"); | |
19560 | case NT_FREEBSD_PROCSTAT_VMMAP: | |
19561 | return _("NT_PROCSTAT_VMMAP (vmmap data)"); | |
19562 | case NT_FREEBSD_PROCSTAT_GROUPS: | |
19563 | return _("NT_PROCSTAT_GROUPS (groups data)"); | |
19564 | case NT_FREEBSD_PROCSTAT_UMASK: | |
19565 | return _("NT_PROCSTAT_UMASK (umask data)"); | |
19566 | case NT_FREEBSD_PROCSTAT_RLIMIT: | |
19567 | return _("NT_PROCSTAT_RLIMIT (rlimit data)"); | |
19568 | case NT_FREEBSD_PROCSTAT_OSREL: | |
19569 | return _("NT_PROCSTAT_OSREL (osreldate data)"); | |
19570 | case NT_FREEBSD_PROCSTAT_PSSTRINGS: | |
19571 | return _("NT_PROCSTAT_PSSTRINGS (ps_strings data)"); | |
19572 | case NT_FREEBSD_PROCSTAT_AUXV: | |
19573 | return _("NT_PROCSTAT_AUXV (auxv data)"); | |
19574 | case NT_FREEBSD_PTLWPINFO: | |
19575 | return _("NT_PTLWPINFO (ptrace_lwpinfo structure)"); | |
19576 | } | |
19577 | return get_note_type (filedata, e_type); | |
19578 | } | |
19579 | ||
19580 | static const char * | |
19581 | get_netbsd_elfcore_note_type (Filedata * filedata, unsigned e_type) | |
19582 | { | |
19583 | static char buff[64]; | |
19584 | ||
19585 | switch (e_type) | |
19586 | { | |
19587 | case NT_NETBSDCORE_PROCINFO: | |
19588 | /* NetBSD core "procinfo" structure. */ | |
19589 | return _("NetBSD procinfo structure"); | |
19590 | ||
19591 | #ifdef NT_NETBSDCORE_AUXV | |
19592 | case NT_NETBSDCORE_AUXV: | |
19593 | return _("NetBSD ELF auxiliary vector data"); | |
19594 | #endif | |
19595 | ||
19596 | #ifdef NT_NETBSDCORE_LWPSTATUS | |
19597 | case NT_NETBSDCORE_LWPSTATUS: | |
19598 | return _("PT_LWPSTATUS (ptrace_lwpstatus structure)"); | |
19599 | #endif | |
19600 | ||
19601 | default: | |
19602 | /* As of Jan 2020 there are no other machine-independent notes | |
19603 | defined for NetBSD core files. If the note type is less | |
19604 | than the start of the machine-dependent note types, we don't | |
19605 | understand it. */ | |
19606 | ||
19607 | if (e_type < NT_NETBSDCORE_FIRSTMACH) | |
19608 | { | |
19609 | snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type); | |
19610 | return buff; | |
19611 | } | |
19612 | break; | |
19613 | } | |
19614 | ||
19615 | switch (filedata->file_header.e_machine) | |
19616 | { | |
19617 | /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0 | |
19618 | and PT_GETFPREGS == mach+2. */ | |
19619 | ||
19620 | case EM_OLD_ALPHA: | |
19621 | case EM_ALPHA: | |
19622 | case EM_SPARC: | |
19623 | case EM_SPARC32PLUS: | |
19624 | case EM_SPARCV9: | |
19625 | switch (e_type) | |
19626 | { | |
19627 | case NT_NETBSDCORE_FIRSTMACH + 0: | |
19628 | return _("PT_GETREGS (reg structure)"); | |
19629 | case NT_NETBSDCORE_FIRSTMACH + 2: | |
19630 | return _("PT_GETFPREGS (fpreg structure)"); | |
19631 | default: | |
19632 | break; | |
19633 | } | |
19634 | break; | |
19635 | ||
19636 | /* On SuperH, PT_GETREGS == mach+3 and PT_GETFPREGS == mach+5. | |
19637 | There's also old PT___GETREGS40 == mach + 1 for old reg | |
19638 | structure which lacks GBR. */ | |
19639 | case EM_SH: | |
19640 | switch (e_type) | |
19641 | { | |
19642 | case NT_NETBSDCORE_FIRSTMACH + 1: | |
19643 | return _("PT___GETREGS40 (old reg structure)"); | |
19644 | case NT_NETBSDCORE_FIRSTMACH + 3: | |
19645 | return _("PT_GETREGS (reg structure)"); | |
19646 | case NT_NETBSDCORE_FIRSTMACH + 5: | |
19647 | return _("PT_GETFPREGS (fpreg structure)"); | |
19648 | default: | |
19649 | break; | |
19650 | } | |
19651 | break; | |
19652 | ||
19653 | /* On all other arch's, PT_GETREGS == mach+1 and | |
19654 | PT_GETFPREGS == mach+3. */ | |
19655 | default: | |
19656 | switch (e_type) | |
19657 | { | |
19658 | case NT_NETBSDCORE_FIRSTMACH + 1: | |
19659 | return _("PT_GETREGS (reg structure)"); | |
19660 | case NT_NETBSDCORE_FIRSTMACH + 3: | |
19661 | return _("PT_GETFPREGS (fpreg structure)"); | |
19662 | default: | |
19663 | break; | |
19664 | } | |
19665 | } | |
19666 | ||
19667 | snprintf (buff, sizeof (buff), "PT_FIRSTMACH+%d", | |
19668 | e_type - NT_NETBSDCORE_FIRSTMACH); | |
19669 | return buff; | |
19670 | } | |
19671 | ||
19672 | static const char * | |
19673 | get_stapsdt_note_type (unsigned e_type) | |
19674 | { | |
19675 | static char buff[64]; | |
19676 | ||
19677 | switch (e_type) | |
19678 | { | |
19679 | case NT_STAPSDT: | |
19680 | return _("NT_STAPSDT (SystemTap probe descriptors)"); | |
19681 | ||
19682 | default: | |
19683 | break; | |
19684 | } | |
19685 | ||
19686 | snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type); | |
19687 | return buff; | |
19688 | } | |
19689 | ||
19690 | static bfd_boolean | |
19691 | print_stapsdt_note (Elf_Internal_Note *pnote) | |
19692 | { | |
19693 | size_t len, maxlen; | |
19694 | unsigned long addr_size = is_32bit_elf ? 4 : 8; | |
19695 | char *data = pnote->descdata; | |
19696 | char *data_end = pnote->descdata + pnote->descsz; | |
19697 | bfd_vma pc, base_addr, semaphore; | |
19698 | char *provider, *probe, *arg_fmt; | |
19699 | ||
19700 | if (pnote->descsz < (addr_size * 3)) | |
19701 | goto stapdt_note_too_small; | |
19702 | ||
19703 | pc = byte_get ((unsigned char *) data, addr_size); | |
19704 | data += addr_size; | |
19705 | ||
19706 | base_addr = byte_get ((unsigned char *) data, addr_size); | |
19707 | data += addr_size; | |
19708 | ||
19709 | semaphore = byte_get ((unsigned char *) data, addr_size); | |
19710 | data += addr_size; | |
19711 | ||
19712 | if (data >= data_end) | |
19713 | goto stapdt_note_too_small; | |
19714 | maxlen = data_end - data; | |
19715 | len = strnlen (data, maxlen); | |
19716 | if (len < maxlen) | |
19717 | { | |
19718 | provider = data; | |
19719 | data += len + 1; | |
19720 | } | |
19721 | else | |
19722 | goto stapdt_note_too_small; | |
19723 | ||
19724 | if (data >= data_end) | |
19725 | goto stapdt_note_too_small; | |
19726 | maxlen = data_end - data; | |
19727 | len = strnlen (data, maxlen); | |
19728 | if (len < maxlen) | |
19729 | { | |
19730 | probe = data; | |
19731 | data += len + 1; | |
19732 | } | |
19733 | else | |
19734 | goto stapdt_note_too_small; | |
19735 | ||
19736 | if (data >= data_end) | |
19737 | goto stapdt_note_too_small; | |
19738 | maxlen = data_end - data; | |
19739 | len = strnlen (data, maxlen); | |
19740 | if (len < maxlen) | |
19741 | { | |
19742 | arg_fmt = data; | |
19743 | data += len + 1; | |
19744 | } | |
19745 | else | |
19746 | goto stapdt_note_too_small; | |
19747 | ||
19748 | printf (_(" Provider: %s\n"), provider); | |
19749 | printf (_(" Name: %s\n"), probe); | |
19750 | printf (_(" Location: ")); | |
19751 | print_vma (pc, FULL_HEX); | |
19752 | printf (_(", Base: ")); | |
19753 | print_vma (base_addr, FULL_HEX); | |
19754 | printf (_(", Semaphore: ")); | |
19755 | print_vma (semaphore, FULL_HEX); | |
19756 | printf ("\n"); | |
19757 | printf (_(" Arguments: %s\n"), arg_fmt); | |
19758 | ||
19759 | return data == data_end; | |
19760 | ||
19761 | stapdt_note_too_small: | |
19762 | printf (_(" <corrupt - note is too small>\n")); | |
19763 | error (_("corrupt stapdt note - the data size is too small\n")); | |
19764 | return FALSE; | |
19765 | } | |
19766 | ||
19767 | static const char * | |
19768 | get_ia64_vms_note_type (unsigned e_type) | |
19769 | { | |
19770 | static char buff[64]; | |
19771 | ||
19772 | switch (e_type) | |
19773 | { | |
19774 | case NT_VMS_MHD: | |
19775 | return _("NT_VMS_MHD (module header)"); | |
19776 | case NT_VMS_LNM: | |
19777 | return _("NT_VMS_LNM (language name)"); | |
19778 | case NT_VMS_SRC: | |
19779 | return _("NT_VMS_SRC (source files)"); | |
19780 | case NT_VMS_TITLE: | |
19781 | return "NT_VMS_TITLE"; | |
19782 | case NT_VMS_EIDC: | |
19783 | return _("NT_VMS_EIDC (consistency check)"); | |
19784 | case NT_VMS_FPMODE: | |
19785 | return _("NT_VMS_FPMODE (FP mode)"); | |
19786 | case NT_VMS_LINKTIME: | |
19787 | return "NT_VMS_LINKTIME"; | |
19788 | case NT_VMS_IMGNAM: | |
19789 | return _("NT_VMS_IMGNAM (image name)"); | |
19790 | case NT_VMS_IMGID: | |
19791 | return _("NT_VMS_IMGID (image id)"); | |
19792 | case NT_VMS_LINKID: | |
19793 | return _("NT_VMS_LINKID (link id)"); | |
19794 | case NT_VMS_IMGBID: | |
19795 | return _("NT_VMS_IMGBID (build id)"); | |
19796 | case NT_VMS_GSTNAM: | |
19797 | return _("NT_VMS_GSTNAM (sym table name)"); | |
19798 | case NT_VMS_ORIG_DYN: | |
19799 | return "NT_VMS_ORIG_DYN"; | |
19800 | case NT_VMS_PATCHTIME: | |
19801 | return "NT_VMS_PATCHTIME"; | |
19802 | default: | |
19803 | snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type); | |
19804 | return buff; | |
19805 | } | |
19806 | } | |
19807 | ||
19808 | static bfd_boolean | |
19809 | print_ia64_vms_note (Elf_Internal_Note * pnote) | |
19810 | { | |
19811 | int maxlen = pnote->descsz; | |
19812 | ||
19813 | if (maxlen < 2 || (unsigned long) maxlen != pnote->descsz) | |
19814 | goto desc_size_fail; | |
19815 | ||
19816 | switch (pnote->type) | |
19817 | { | |
19818 | case NT_VMS_MHD: | |
19819 | if (maxlen <= 36) | |
19820 | goto desc_size_fail; | |
19821 | ||
19822 | int l = (int) strnlen (pnote->descdata + 34, maxlen - 34); | |
19823 | ||
19824 | printf (_(" Creation date : %.17s\n"), pnote->descdata); | |
19825 | printf (_(" Last patch date: %.17s\n"), pnote->descdata + 17); | |
19826 | if (l + 34 < maxlen) | |
19827 | { | |
19828 | printf (_(" Module name : %s\n"), pnote->descdata + 34); | |
19829 | if (l + 35 < maxlen) | |
19830 | printf (_(" Module version : %s\n"), pnote->descdata + 34 + l + 1); | |
19831 | else | |
19832 | printf (_(" Module version : <missing>\n")); | |
19833 | } | |
19834 | else | |
19835 | { | |
19836 | printf (_(" Module name : <missing>\n")); | |
19837 | printf (_(" Module version : <missing>\n")); | |
19838 | } | |
19839 | break; | |
19840 | ||
19841 | case NT_VMS_LNM: | |
19842 | printf (_(" Language: %.*s\n"), maxlen, pnote->descdata); | |
19843 | break; | |
19844 | ||
19845 | #ifdef BFD64 | |
19846 | case NT_VMS_FPMODE: | |
19847 | printf (_(" Floating Point mode: ")); | |
19848 | if (maxlen < 8) | |
19849 | goto desc_size_fail; | |
19850 | /* FIXME: Generate an error if descsz > 8 ? */ | |
19851 | ||
19852 | printf ("0x%016" BFD_VMA_FMT "x\n", | |
19853 | (bfd_vma) byte_get ((unsigned char *)pnote->descdata, 8)); | |
19854 | break; | |
19855 | ||
19856 | case NT_VMS_LINKTIME: | |
19857 | printf (_(" Link time: ")); | |
19858 | if (maxlen < 8) | |
19859 | goto desc_size_fail; | |
19860 | /* FIXME: Generate an error if descsz > 8 ? */ | |
19861 | ||
19862 | print_vms_time | |
19863 | ((bfd_int64_t) byte_get ((unsigned char *)pnote->descdata, 8)); | |
19864 | printf ("\n"); | |
19865 | break; | |
19866 | ||
19867 | case NT_VMS_PATCHTIME: | |
19868 | printf (_(" Patch time: ")); | |
19869 | if (maxlen < 8) | |
19870 | goto desc_size_fail; | |
19871 | /* FIXME: Generate an error if descsz > 8 ? */ | |
19872 | ||
19873 | print_vms_time | |
19874 | ((bfd_int64_t) byte_get ((unsigned char *)pnote->descdata, 8)); | |
19875 | printf ("\n"); | |
19876 | break; | |
19877 | ||
19878 | case NT_VMS_ORIG_DYN: | |
19879 | if (maxlen < 34) | |
19880 | goto desc_size_fail; | |
19881 | ||
19882 | printf (_(" Major id: %u, minor id: %u\n"), | |
19883 | (unsigned) byte_get ((unsigned char *)pnote->descdata, 4), | |
19884 | (unsigned) byte_get ((unsigned char *)pnote->descdata + 4, 4)); | |
19885 | printf (_(" Last modified : ")); | |
19886 | print_vms_time | |
19887 | ((bfd_int64_t) byte_get ((unsigned char *)pnote->descdata + 8, 8)); | |
19888 | printf (_("\n Link flags : ")); | |
19889 | printf ("0x%016" BFD_VMA_FMT "x\n", | |
19890 | (bfd_vma) byte_get ((unsigned char *)pnote->descdata + 16, 8)); | |
19891 | printf (_(" Header flags: 0x%08x\n"), | |
19892 | (unsigned) byte_get ((unsigned char *)pnote->descdata + 24, 4)); | |
19893 | printf (_(" Image id : %.*s\n"), maxlen - 32, pnote->descdata + 32); | |
19894 | break; | |
19895 | #endif | |
19896 | ||
19897 | case NT_VMS_IMGNAM: | |
19898 | printf (_(" Image name: %.*s\n"), maxlen, pnote->descdata); | |
19899 | break; | |
19900 | ||
19901 | case NT_VMS_GSTNAM: | |
19902 | printf (_(" Global symbol table name: %.*s\n"), maxlen, pnote->descdata); | |
19903 | break; | |
19904 | ||
19905 | case NT_VMS_IMGID: | |
19906 | printf (_(" Image id: %.*s\n"), maxlen, pnote->descdata); | |
19907 | break; | |
19908 | ||
19909 | case NT_VMS_LINKID: | |
19910 | printf (_(" Linker id: %.*s\n"), maxlen, pnote->descdata); | |
19911 | break; | |
19912 | ||
19913 | default: | |
19914 | return FALSE; | |
19915 | } | |
19916 | ||
19917 | return TRUE; | |
19918 | ||
19919 | desc_size_fail: | |
19920 | printf (_(" <corrupt - data size is too small>\n")); | |
19921 | error (_("corrupt IA64 note: data size is too small\n")); | |
19922 | return FALSE; | |
19923 | } | |
19924 | ||
19925 | struct build_attr_cache { | |
19926 | Filedata *filedata; | |
19927 | char *strtab; | |
19928 | unsigned long strtablen; | |
19929 | Elf_Internal_Sym *symtab; | |
19930 | unsigned long nsyms; | |
19931 | } ba_cache; | |
19932 | ||
19933 | /* Find the symbol associated with a build attribute that is attached | |
19934 | to address OFFSET. If PNAME is non-NULL then store the name of | |
19935 | the symbol (if found) in the provided pointer, Returns NULL if a | |
19936 | symbol could not be found. */ | |
19937 | ||
19938 | static Elf_Internal_Sym * | |
19939 | get_symbol_for_build_attribute (Filedata * filedata, | |
19940 | unsigned long offset, | |
19941 | bfd_boolean is_open_attr, | |
19942 | const char ** pname) | |
19943 | { | |
19944 | Elf_Internal_Sym *saved_sym = NULL; | |
19945 | Elf_Internal_Sym *sym; | |
19946 | ||
19947 | if (filedata->section_headers != NULL | |
19948 | && (ba_cache.filedata == NULL || filedata != ba_cache.filedata)) | |
19949 | { | |
19950 | Elf_Internal_Shdr * symsec; | |
19951 | ||
19952 | free (ba_cache.strtab); | |
19953 | ba_cache.strtab = NULL; | |
19954 | free (ba_cache.symtab); | |
19955 | ba_cache.symtab = NULL; | |
19956 | ||
19957 | /* Load the symbol and string sections. */ | |
19958 | for (symsec = filedata->section_headers; | |
19959 | symsec < filedata->section_headers + filedata->file_header.e_shnum; | |
19960 | symsec ++) | |
19961 | { | |
19962 | if (symsec->sh_type == SHT_SYMTAB | |
19963 | && get_symtab (filedata, symsec, | |
19964 | &ba_cache.symtab, &ba_cache.nsyms, | |
19965 | &ba_cache.strtab, &ba_cache.strtablen)) | |
19966 | break; | |
19967 | } | |
19968 | ba_cache.filedata = filedata; | |
19969 | } | |
19970 | ||
19971 | if (ba_cache.symtab == NULL) | |
19972 | return NULL; | |
19973 | ||
19974 | /* Find a symbol whose value matches offset. */ | |
19975 | for (sym = ba_cache.symtab; sym < ba_cache.symtab + ba_cache.nsyms; sym ++) | |
19976 | if (sym->st_value == offset) | |
19977 | { | |
19978 | if (sym->st_name >= ba_cache.strtablen) | |
19979 | /* Huh ? This should not happen. */ | |
19980 | continue; | |
19981 | ||
19982 | if (ba_cache.strtab[sym->st_name] == 0) | |
19983 | continue; | |
19984 | ||
19985 | /* The AArch64 and ARM architectures define mapping symbols | |
19986 | (eg $d, $x, $t) which we want to ignore. */ | |
19987 | if (ba_cache.strtab[sym->st_name] == '$' | |
19988 | && ba_cache.strtab[sym->st_name + 1] != 0 | |
19989 | && ba_cache.strtab[sym->st_name + 2] == 0) | |
19990 | continue; | |
19991 | ||
19992 | if (is_open_attr) | |
19993 | { | |
19994 | /* For OPEN attributes we prefer GLOBAL over LOCAL symbols | |
19995 | and FILE or OBJECT symbols over NOTYPE symbols. We skip | |
19996 | FUNC symbols entirely. */ | |
19997 | switch (ELF_ST_TYPE (sym->st_info)) | |
19998 | { | |
19999 | case STT_OBJECT: | |
20000 | case STT_FILE: | |
20001 | saved_sym = sym; | |
20002 | if (sym->st_size) | |
20003 | { | |
20004 | /* If the symbol has a size associated | |
20005 | with it then we can stop searching. */ | |
20006 | sym = ba_cache.symtab + ba_cache.nsyms; | |
20007 | } | |
20008 | continue; | |
20009 | ||
20010 | case STT_FUNC: | |
20011 | /* Ignore function symbols. */ | |
20012 | continue; | |
20013 | ||
20014 | default: | |
20015 | break; | |
20016 | } | |
20017 | ||
20018 | switch (ELF_ST_BIND (sym->st_info)) | |
20019 | { | |
20020 | case STB_GLOBAL: | |
20021 | if (saved_sym == NULL | |
20022 | || ELF_ST_TYPE (saved_sym->st_info) != STT_OBJECT) | |
20023 | saved_sym = sym; | |
20024 | break; | |
20025 | ||
20026 | case STB_LOCAL: | |
20027 | if (saved_sym == NULL) | |
20028 | saved_sym = sym; | |
20029 | break; | |
20030 | ||
20031 | default: | |
20032 | break; | |
20033 | } | |
20034 | } | |
20035 | else | |
20036 | { | |
20037 | if (ELF_ST_TYPE (sym->st_info) != STT_FUNC) | |
20038 | continue; | |
20039 | ||
20040 | saved_sym = sym; | |
20041 | break; | |
20042 | } | |
20043 | } | |
20044 | ||
20045 | if (saved_sym && pname) | |
20046 | * pname = ba_cache.strtab + saved_sym->st_name; | |
20047 | ||
20048 | return saved_sym; | |
20049 | } | |
20050 | ||
20051 | /* Returns true iff addr1 and addr2 are in the same section. */ | |
20052 | ||
20053 | static bfd_boolean | |
20054 | same_section (Filedata * filedata, unsigned long addr1, unsigned long addr2) | |
20055 | { | |
20056 | Elf_Internal_Shdr * a1; | |
20057 | Elf_Internal_Shdr * a2; | |
20058 | ||
20059 | a1 = find_section_by_address (filedata, addr1); | |
20060 | a2 = find_section_by_address (filedata, addr2); | |
20061 | ||
20062 | return a1 == a2 && a1 != NULL; | |
20063 | } | |
20064 | ||
20065 | static bfd_boolean | |
20066 | print_gnu_build_attribute_description (Elf_Internal_Note * pnote, | |
20067 | Filedata * filedata) | |
20068 | { | |
20069 | static unsigned long global_offset = 0; | |
20070 | static unsigned long global_end = 0; | |
20071 | static unsigned long func_offset = 0; | |
20072 | static unsigned long func_end = 0; | |
20073 | ||
20074 | Elf_Internal_Sym * sym; | |
20075 | const char * name; | |
20076 | unsigned long start; | |
20077 | unsigned long end; | |
20078 | bfd_boolean is_open_attr = pnote->type == NT_GNU_BUILD_ATTRIBUTE_OPEN; | |
20079 | ||
20080 | switch (pnote->descsz) | |
20081 | { | |
20082 | case 0: | |
20083 | /* A zero-length description means that the range of | |
20084 | the previous note of the same type should be used. */ | |
20085 | if (is_open_attr) | |
20086 | { | |
20087 | if (global_end > global_offset) | |
20088 | printf (_(" Applies to region from %#lx to %#lx\n"), | |
20089 | global_offset, global_end); | |
20090 | else | |
20091 | printf (_(" Applies to region from %#lx\n"), global_offset); | |
20092 | } | |
20093 | else | |
20094 | { | |
20095 | if (func_end > func_offset) | |
20096 | printf (_(" Applies to region from %#lx to %#lx\n"), func_offset, func_end); | |
20097 | else | |
20098 | printf (_(" Applies to region from %#lx\n"), func_offset); | |
20099 | } | |
20100 | return TRUE; | |
20101 | ||
20102 | case 4: | |
20103 | start = byte_get ((unsigned char *) pnote->descdata, 4); | |
20104 | end = 0; | |
20105 | break; | |
20106 | ||
20107 | case 8: | |
20108 | start = byte_get ((unsigned char *) pnote->descdata, 4); | |
20109 | end = byte_get ((unsigned char *) pnote->descdata + 4, 4); | |
20110 | break; | |
20111 | ||
20112 | case 16: | |
20113 | start = byte_get ((unsigned char *) pnote->descdata, 8); | |
20114 | end = byte_get ((unsigned char *) pnote->descdata + 8, 8); | |
20115 | break; | |
20116 | ||
20117 | default: | |
20118 | error (_(" <invalid description size: %lx>\n"), pnote->descsz); | |
20119 | printf (_(" <invalid descsz>")); | |
20120 | return FALSE; | |
20121 | } | |
20122 | ||
20123 | name = NULL; | |
20124 | sym = get_symbol_for_build_attribute (filedata, start, is_open_attr, & name); | |
20125 | /* As of version 5 of the annobin plugin, filename symbols are biased by 2 | |
20126 | in order to avoid them being confused with the start address of the | |
20127 | first function in the file... */ | |
20128 | if (sym == NULL && is_open_attr) | |
20129 | sym = get_symbol_for_build_attribute (filedata, start + 2, is_open_attr, | |
20130 | & name); | |
20131 | ||
20132 | if (end == 0 && sym != NULL && sym->st_size > 0) | |
20133 | end = start + sym->st_size; | |
20134 | ||
20135 | if (is_open_attr) | |
20136 | { | |
20137 | /* FIXME: Need to properly allow for section alignment. | |
20138 | 16 is just the alignment used on x86_64. */ | |
20139 | if (global_end > 0 | |
20140 | && start > BFD_ALIGN (global_end, 16) | |
20141 | /* Build notes are not guaranteed to be organised in order of | |
20142 | increasing address, but we should find the all of the notes | |
20143 | for one section in the same place. */ | |
20144 | && same_section (filedata, start, global_end)) | |
20145 | warn (_("Gap in build notes detected from %#lx to %#lx\n"), | |
20146 | global_end + 1, start - 1); | |
20147 | ||
20148 | printf (_(" Applies to region from %#lx"), start); | |
20149 | global_offset = start; | |
20150 | ||
20151 | if (end) | |
20152 | { | |
20153 | printf (_(" to %#lx"), end); | |
20154 | global_end = end; | |
20155 | } | |
20156 | } | |
20157 | else | |
20158 | { | |
20159 | printf (_(" Applies to region from %#lx"), start); | |
20160 | func_offset = start; | |
20161 | ||
20162 | if (end) | |
20163 | { | |
20164 | printf (_(" to %#lx"), end); | |
20165 | func_end = end; | |
20166 | } | |
20167 | } | |
20168 | ||
20169 | if (sym && name) | |
20170 | printf (_(" (%s)"), name); | |
20171 | ||
20172 | printf ("\n"); | |
20173 | return TRUE; | |
20174 | } | |
20175 | ||
20176 | static bfd_boolean | |
20177 | print_gnu_build_attribute_name (Elf_Internal_Note * pnote) | |
20178 | { | |
20179 | static const char string_expected [2] = { GNU_BUILD_ATTRIBUTE_TYPE_STRING, 0 }; | |
20180 | static const char number_expected [2] = { GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC, 0 }; | |
20181 | static const char bool_expected [3] = { GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE, GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE, 0 }; | |
20182 | char name_type; | |
20183 | char name_attribute; | |
20184 | const char * expected_types; | |
20185 | const char * name = pnote->namedata; | |
20186 | const char * text; | |
20187 | signed int left; | |
20188 | ||
20189 | if (name == NULL || pnote->namesz < 2) | |
20190 | { | |
20191 | error (_("corrupt name field in GNU build attribute note: size = %ld\n"), pnote->namesz); | |
20192 | print_symbol (-20, _(" <corrupt name>")); | |
20193 | return FALSE; | |
20194 | } | |
20195 | ||
20196 | if (do_wide) | |
20197 | left = 28; | |
20198 | else | |
20199 | left = 20; | |
20200 | ||
20201 | /* Version 2 of the spec adds a "GA" prefix to the name field. */ | |
20202 | if (name[0] == 'G' && name[1] == 'A') | |
20203 | { | |
20204 | if (pnote->namesz < 4) | |
20205 | { | |
20206 | error (_("corrupt name field in GNU build attribute note: size = %ld\n"), pnote->namesz); | |
20207 | print_symbol (-20, _(" <corrupt name>")); | |
20208 | return FALSE; | |
20209 | } | |
20210 | ||
20211 | printf ("GA"); | |
20212 | name += 2; | |
20213 | left -= 2; | |
20214 | } | |
20215 | ||
20216 | switch ((name_type = * name)) | |
20217 | { | |
20218 | case GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC: | |
20219 | case GNU_BUILD_ATTRIBUTE_TYPE_STRING: | |
20220 | case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE: | |
20221 | case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE: | |
20222 | printf ("%c", * name); | |
20223 | left --; | |
20224 | break; | |
20225 | default: | |
20226 | error (_("unrecognised attribute type in name field: %d\n"), name_type); | |
20227 | print_symbol (-20, _("<unknown name type>")); | |
20228 | return FALSE; | |
20229 | } | |
20230 | ||
20231 | ++ name; | |
20232 | text = NULL; | |
20233 | ||
20234 | switch ((name_attribute = * name)) | |
20235 | { | |
20236 | case GNU_BUILD_ATTRIBUTE_VERSION: | |
20237 | text = _("<version>"); | |
20238 | expected_types = string_expected; | |
20239 | ++ name; | |
20240 | break; | |
20241 | case GNU_BUILD_ATTRIBUTE_STACK_PROT: | |
20242 | text = _("<stack prot>"); | |
20243 | expected_types = "!+*"; | |
20244 | ++ name; | |
20245 | break; | |
20246 | case GNU_BUILD_ATTRIBUTE_RELRO: | |
20247 | text = _("<relro>"); | |
20248 | expected_types = bool_expected; | |
20249 | ++ name; | |
20250 | break; | |
20251 | case GNU_BUILD_ATTRIBUTE_STACK_SIZE: | |
20252 | text = _("<stack size>"); | |
20253 | expected_types = number_expected; | |
20254 | ++ name; | |
20255 | break; | |
20256 | case GNU_BUILD_ATTRIBUTE_TOOL: | |
20257 | text = _("<tool>"); | |
20258 | expected_types = string_expected; | |
20259 | ++ name; | |
20260 | break; | |
20261 | case GNU_BUILD_ATTRIBUTE_ABI: | |
20262 | text = _("<ABI>"); | |
20263 | expected_types = "$*"; | |
20264 | ++ name; | |
20265 | break; | |
20266 | case GNU_BUILD_ATTRIBUTE_PIC: | |
20267 | text = _("<PIC>"); | |
20268 | expected_types = number_expected; | |
20269 | ++ name; | |
20270 | break; | |
20271 | case GNU_BUILD_ATTRIBUTE_SHORT_ENUM: | |
20272 | text = _("<short enum>"); | |
20273 | expected_types = bool_expected; | |
20274 | ++ name; | |
20275 | break; | |
20276 | default: | |
20277 | if (ISPRINT (* name)) | |
20278 | { | |
20279 | int len = strnlen (name, pnote->namesz - (name - pnote->namedata)) + 1; | |
20280 | ||
20281 | if (len > left && ! do_wide) | |
20282 | len = left; | |
20283 | printf ("%.*s:", len, name); | |
20284 | left -= len; | |
20285 | name += len; | |
20286 | } | |
20287 | else | |
20288 | { | |
20289 | static char tmpbuf [128]; | |
20290 | ||
20291 | error (_("unrecognised byte in name field: %d\n"), * name); | |
20292 | sprintf (tmpbuf, _("<unknown:_%d>"), * name); | |
20293 | text = tmpbuf; | |
20294 | name ++; | |
20295 | } | |
20296 | expected_types = "*$!+"; | |
20297 | break; | |
20298 | } | |
20299 | ||
20300 | if (text) | |
20301 | left -= printf ("%s", text); | |
20302 | ||
20303 | if (strchr (expected_types, name_type) == NULL) | |
20304 | warn (_("attribute does not have an expected type (%c)\n"), name_type); | |
20305 | ||
20306 | if ((unsigned long)(name - pnote->namedata) > pnote->namesz) | |
20307 | { | |
20308 | error (_("corrupt name field: namesz: %lu but parsing gets to %ld\n"), | |
20309 | (unsigned long) pnote->namesz, | |
20310 | (long) (name - pnote->namedata)); | |
20311 | return FALSE; | |
20312 | } | |
20313 | ||
20314 | if (left < 1 && ! do_wide) | |
20315 | return TRUE; | |
20316 | ||
20317 | switch (name_type) | |
20318 | { | |
20319 | case GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC: | |
20320 | { | |
20321 | unsigned int bytes; | |
20322 | unsigned long long val = 0; | |
20323 | unsigned int shift = 0; | |
20324 | char * decoded = NULL; | |
20325 | ||
20326 | bytes = pnote->namesz - (name - pnote->namedata); | |
20327 | if (bytes > 0) | |
20328 | /* The -1 is because the name field is always 0 terminated, and we | |
20329 | want to be able to ensure that the shift in the while loop below | |
20330 | will not overflow. */ | |
20331 | -- bytes; | |
20332 | ||
20333 | if (bytes > sizeof (val)) | |
20334 | { | |
20335 | error (_("corrupt numeric name field: too many bytes in the value: %x\n"), | |
20336 | bytes); | |
20337 | bytes = sizeof (val); | |
20338 | } | |
20339 | /* We do not bother to warn if bytes == 0 as this can | |
20340 | happen with some early versions of the gcc plugin. */ | |
20341 | ||
20342 | while (bytes --) | |
20343 | { | |
20344 | unsigned long long byte = *name++ & 0xff; | |
20345 | ||
20346 | val |= byte << shift; | |
20347 | shift += 8; | |
20348 | } | |
20349 | ||
20350 | switch (name_attribute) | |
20351 | { | |
20352 | case GNU_BUILD_ATTRIBUTE_PIC: | |
20353 | switch (val) | |
20354 | { | |
20355 | case 0: decoded = "static"; break; | |
20356 | case 1: decoded = "pic"; break; | |
20357 | case 2: decoded = "PIC"; break; | |
20358 | case 3: decoded = "pie"; break; | |
20359 | case 4: decoded = "PIE"; break; | |
20360 | default: break; | |
20361 | } | |
20362 | break; | |
20363 | case GNU_BUILD_ATTRIBUTE_STACK_PROT: | |
20364 | switch (val) | |
20365 | { | |
20366 | /* Based upon the SPCT_FLAG_xxx enum values in gcc/cfgexpand.c. */ | |
20367 | case 0: decoded = "off"; break; | |
20368 | case 1: decoded = "on"; break; | |
20369 | case 2: decoded = "all"; break; | |
20370 | case 3: decoded = "strong"; break; | |
20371 | case 4: decoded = "explicit"; break; | |
20372 | default: break; | |
20373 | } | |
20374 | break; | |
20375 | default: | |
20376 | break; | |
20377 | } | |
20378 | ||
20379 | if (decoded != NULL) | |
20380 | { | |
20381 | print_symbol (-left, decoded); | |
20382 | left = 0; | |
20383 | } | |
20384 | else if (val == 0) | |
20385 | { | |
20386 | printf ("0x0"); | |
20387 | left -= 3; | |
20388 | } | |
20389 | else | |
20390 | { | |
20391 | if (do_wide) | |
20392 | left -= printf ("0x%llx", val); | |
20393 | else | |
20394 | left -= printf ("0x%-.*llx", left, val); | |
20395 | } | |
20396 | } | |
20397 | break; | |
20398 | case GNU_BUILD_ATTRIBUTE_TYPE_STRING: | |
20399 | left -= print_symbol (- left, name); | |
20400 | break; | |
20401 | case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE: | |
20402 | left -= print_symbol (- left, "true"); | |
20403 | break; | |
20404 | case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE: | |
20405 | left -= print_symbol (- left, "false"); | |
20406 | break; | |
20407 | } | |
20408 | ||
20409 | if (do_wide && left > 0) | |
20410 | printf ("%-*s", left, " "); | |
20411 | ||
20412 | return TRUE; | |
20413 | } | |
20414 | ||
20415 | /* Note that by the ELF standard, the name field is already null byte | |
20416 | terminated, and namesz includes the terminating null byte. | |
20417 | I.E. the value of namesz for the name "FSF" is 4. | |
20418 | ||
20419 | If the value of namesz is zero, there is no name present. */ | |
20420 | ||
20421 | static bfd_boolean | |
20422 | process_note (Elf_Internal_Note * pnote, | |
20423 | Filedata * filedata) | |
20424 | { | |
20425 | const char * name = pnote->namesz ? pnote->namedata : "(NONE)"; | |
20426 | const char * nt; | |
20427 | ||
20428 | if (pnote->namesz == 0) | |
20429 | /* If there is no note name, then use the default set of | |
20430 | note type strings. */ | |
20431 | nt = get_note_type (filedata, pnote->type); | |
20432 | ||
20433 | else if (const_strneq (pnote->namedata, "GNU")) | |
20434 | /* GNU-specific object file notes. */ | |
20435 | nt = get_gnu_elf_note_type (pnote->type); | |
20436 | ||
20437 | else if (const_strneq (pnote->namedata, "FreeBSD")) | |
20438 | /* FreeBSD-specific core file notes. */ | |
20439 | nt = get_freebsd_elfcore_note_type (filedata, pnote->type); | |
20440 | ||
20441 | else if (const_strneq (pnote->namedata, "NetBSD-CORE")) | |
20442 | /* NetBSD-specific core file notes. */ | |
20443 | nt = get_netbsd_elfcore_note_type (filedata, pnote->type); | |
20444 | ||
20445 | else if (const_strneq (pnote->namedata, "NetBSD")) | |
20446 | /* NetBSD-specific core file notes. */ | |
20447 | return process_netbsd_elf_note (pnote); | |
20448 | ||
20449 | else if (const_strneq (pnote->namedata, "PaX")) | |
20450 | /* NetBSD-specific core file notes. */ | |
20451 | return process_netbsd_elf_note (pnote); | |
20452 | ||
20453 | else if (strneq (pnote->namedata, "SPU/", 4)) | |
20454 | { | |
20455 | /* SPU-specific core file notes. */ | |
20456 | nt = pnote->namedata + 4; | |
20457 | name = "SPU"; | |
20458 | } | |
20459 | ||
20460 | else if (const_strneq (pnote->namedata, "IPF/VMS")) | |
20461 | /* VMS/ia64-specific file notes. */ | |
20462 | nt = get_ia64_vms_note_type (pnote->type); | |
20463 | ||
20464 | else if (const_strneq (pnote->namedata, "stapsdt")) | |
20465 | nt = get_stapsdt_note_type (pnote->type); | |
20466 | ||
20467 | else | |
20468 | /* Don't recognize this note name; just use the default set of | |
20469 | note type strings. */ | |
20470 | nt = get_note_type (filedata, pnote->type); | |
20471 | ||
20472 | printf (" "); | |
20473 | ||
20474 | if (((const_strneq (pnote->namedata, "GA") | |
20475 | && strchr ("*$!+", pnote->namedata[2]) != NULL) | |
20476 | || strchr ("*$!+", pnote->namedata[0]) != NULL) | |
20477 | && (pnote->type == NT_GNU_BUILD_ATTRIBUTE_OPEN | |
20478 | || pnote->type == NT_GNU_BUILD_ATTRIBUTE_FUNC)) | |
20479 | print_gnu_build_attribute_name (pnote); | |
20480 | else | |
20481 | print_symbol (-20, name); | |
20482 | ||
20483 | if (do_wide) | |
20484 | printf (" 0x%08lx\t%s\t", pnote->descsz, nt); | |
20485 | else | |
20486 | printf (" 0x%08lx\t%s\n", pnote->descsz, nt); | |
20487 | ||
20488 | if (const_strneq (pnote->namedata, "IPF/VMS")) | |
20489 | return print_ia64_vms_note (pnote); | |
20490 | else if (const_strneq (pnote->namedata, "GNU")) | |
20491 | return print_gnu_note (filedata, pnote); | |
20492 | else if (const_strneq (pnote->namedata, "stapsdt")) | |
20493 | return print_stapsdt_note (pnote); | |
20494 | else if (const_strneq (pnote->namedata, "CORE")) | |
20495 | return print_core_note (pnote); | |
20496 | else if (((const_strneq (pnote->namedata, "GA") | |
20497 | && strchr ("*$!+", pnote->namedata[2]) != NULL) | |
20498 | || strchr ("*$!+", pnote->namedata[0]) != NULL) | |
20499 | && (pnote->type == NT_GNU_BUILD_ATTRIBUTE_OPEN | |
20500 | || pnote->type == NT_GNU_BUILD_ATTRIBUTE_FUNC)) | |
20501 | return print_gnu_build_attribute_description (pnote, filedata); | |
20502 | ||
20503 | if (pnote->descsz) | |
20504 | { | |
20505 | unsigned long i; | |
20506 | ||
20507 | printf (_(" description data: ")); | |
20508 | for (i = 0; i < pnote->descsz; i++) | |
20509 | printf ("%02x ", pnote->descdata[i] & 0xff); | |
20510 | if (!do_wide) | |
20511 | printf ("\n"); | |
20512 | } | |
20513 | ||
20514 | if (do_wide) | |
20515 | printf ("\n"); | |
20516 | ||
20517 | return TRUE; | |
20518 | } | |
20519 | ||
20520 | static bfd_boolean | |
20521 | process_notes_at (Filedata * filedata, | |
20522 | Elf_Internal_Shdr * section, | |
20523 | bfd_vma offset, | |
20524 | bfd_vma length, | |
20525 | bfd_vma align) | |
20526 | { | |
20527 | Elf_External_Note * pnotes; | |
20528 | Elf_External_Note * external; | |
20529 | char * end; | |
20530 | bfd_boolean res = TRUE; | |
20531 | ||
20532 | if (length <= 0) | |
20533 | return FALSE; | |
20534 | ||
20535 | if (section) | |
20536 | { | |
20537 | pnotes = (Elf_External_Note *) get_section_contents (section, filedata); | |
20538 | if (pnotes) | |
20539 | { | |
20540 | if (! apply_relocations (filedata, section, (unsigned char *) pnotes, length, NULL, NULL)) | |
20541 | { | |
20542 | free (pnotes); | |
20543 | return FALSE; | |
20544 | } | |
20545 | } | |
20546 | } | |
20547 | else | |
20548 | pnotes = (Elf_External_Note *) get_data (NULL, filedata, offset, 1, length, | |
20549 | _("notes")); | |
20550 | ||
20551 | if (pnotes == NULL) | |
20552 | return FALSE; | |
20553 | ||
20554 | external = pnotes; | |
20555 | ||
20556 | if (filedata->is_separate) | |
20557 | printf (_("In linked file '%s': "), filedata->file_name); | |
20558 | else | |
20559 | printf ("\n"); | |
20560 | if (section) | |
20561 | printf (_("Displaying notes found in: %s\n"), printable_section_name (filedata, section)); | |
20562 | else | |
20563 | printf (_("Displaying notes found at file offset 0x%08lx with length 0x%08lx:\n"), | |
20564 | (unsigned long) offset, (unsigned long) length); | |
20565 | ||
20566 | /* NB: Some note sections may have alignment value of 0 or 1. gABI | |
20567 | specifies that notes should be aligned to 4 bytes in 32-bit | |
20568 | objects and to 8 bytes in 64-bit objects. As a Linux extension, | |
20569 | we also support 4 byte alignment in 64-bit objects. If section | |
20570 | alignment is less than 4, we treate alignment as 4 bytes. */ | |
20571 | if (align < 4) | |
20572 | align = 4; | |
20573 | else if (align != 4 && align != 8) | |
20574 | { | |
20575 | warn (_("Corrupt note: alignment %ld, expecting 4 or 8\n"), | |
20576 | (long) align); | |
20577 | free (pnotes); | |
20578 | return FALSE; | |
20579 | } | |
20580 | ||
20581 | printf (_(" %-20s %-10s\tDescription\n"), _("Owner"), _("Data size")); | |
20582 | ||
20583 | end = (char *) pnotes + length; | |
20584 | while ((char *) external < end) | |
20585 | { | |
20586 | Elf_Internal_Note inote; | |
20587 | size_t min_notesz; | |
20588 | char * next; | |
20589 | char * temp = NULL; | |
20590 | size_t data_remaining = end - (char *) external; | |
20591 | ||
20592 | if (!is_ia64_vms (filedata)) | |
20593 | { | |
20594 | /* PR binutils/15191 | |
20595 | Make sure that there is enough data to read. */ | |
20596 | min_notesz = offsetof (Elf_External_Note, name); | |
20597 | if (data_remaining < min_notesz) | |
20598 | { | |
20599 | warn (ngettext ("Corrupt note: only %ld byte remains, " | |
20600 | "not enough for a full note\n", | |
20601 | "Corrupt note: only %ld bytes remain, " | |
20602 | "not enough for a full note\n", | |
20603 | data_remaining), | |
20604 | (long) data_remaining); | |
20605 | break; | |
20606 | } | |
20607 | data_remaining -= min_notesz; | |
20608 | ||
20609 | inote.type = BYTE_GET (external->type); | |
20610 | inote.namesz = BYTE_GET (external->namesz); | |
20611 | inote.namedata = external->name; | |
20612 | inote.descsz = BYTE_GET (external->descsz); | |
20613 | inote.descdata = ((char *) external | |
20614 | + ELF_NOTE_DESC_OFFSET (inote.namesz, align)); | |
20615 | inote.descpos = offset + (inote.descdata - (char *) pnotes); | |
20616 | next = ((char *) external | |
20617 | + ELF_NOTE_NEXT_OFFSET (inote.namesz, inote.descsz, align)); | |
20618 | } | |
20619 | else | |
20620 | { | |
20621 | Elf64_External_VMS_Note *vms_external; | |
20622 | ||
20623 | /* PR binutils/15191 | |
20624 | Make sure that there is enough data to read. */ | |
20625 | min_notesz = offsetof (Elf64_External_VMS_Note, name); | |
20626 | if (data_remaining < min_notesz) | |
20627 | { | |
20628 | warn (ngettext ("Corrupt note: only %ld byte remains, " | |
20629 | "not enough for a full note\n", | |
20630 | "Corrupt note: only %ld bytes remain, " | |
20631 | "not enough for a full note\n", | |
20632 | data_remaining), | |
20633 | (long) data_remaining); | |
20634 | break; | |
20635 | } | |
20636 | data_remaining -= min_notesz; | |
20637 | ||
20638 | vms_external = (Elf64_External_VMS_Note *) external; | |
20639 | inote.type = BYTE_GET (vms_external->type); | |
20640 | inote.namesz = BYTE_GET (vms_external->namesz); | |
20641 | inote.namedata = vms_external->name; | |
20642 | inote.descsz = BYTE_GET (vms_external->descsz); | |
20643 | inote.descdata = inote.namedata + align_power (inote.namesz, 3); | |
20644 | inote.descpos = offset + (inote.descdata - (char *) pnotes); | |
20645 | next = inote.descdata + align_power (inote.descsz, 3); | |
20646 | } | |
20647 | ||
20648 | /* PR 17531: file: 3443835e. */ | |
20649 | /* PR 17531: file: id:000000,sig:11,src:006986,op:havoc,rep:4. */ | |
20650 | if ((size_t) (inote.descdata - inote.namedata) < inote.namesz | |
20651 | || (size_t) (inote.descdata - inote.namedata) > data_remaining | |
20652 | || (size_t) (next - inote.descdata) < inote.descsz | |
20653 | || ((size_t) (next - inote.descdata) | |
20654 | > data_remaining - (size_t) (inote.descdata - inote.namedata))) | |
20655 | { | |
20656 | warn (_("note with invalid namesz and/or descsz found at offset 0x%lx\n"), | |
20657 | (unsigned long) ((char *) external - (char *) pnotes)); | |
20658 | warn (_(" type: 0x%lx, namesize: 0x%08lx, descsize: 0x%08lx, alignment: %u\n"), | |
20659 | inote.type, inote.namesz, inote.descsz, (int) align); | |
20660 | break; | |
20661 | } | |
20662 | ||
20663 | external = (Elf_External_Note *) next; | |
20664 | ||
20665 | /* Verify that name is null terminated. It appears that at least | |
20666 | one version of Linux (RedHat 6.0) generates corefiles that don't | |
20667 | comply with the ELF spec by failing to include the null byte in | |
20668 | namesz. */ | |
20669 | if (inote.namesz > 0 && inote.namedata[inote.namesz - 1] != '\0') | |
20670 | { | |
20671 | if ((size_t) (inote.descdata - inote.namedata) == inote.namesz) | |
20672 | { | |
20673 | temp = (char *) malloc (inote.namesz + 1); | |
20674 | if (temp == NULL) | |
20675 | { | |
20676 | error (_("Out of memory allocating space for inote name\n")); | |
20677 | res = FALSE; | |
20678 | break; | |
20679 | } | |
20680 | ||
20681 | memcpy (temp, inote.namedata, inote.namesz); | |
20682 | inote.namedata = temp; | |
20683 | } | |
20684 | inote.namedata[inote.namesz] = 0; | |
20685 | } | |
20686 | ||
20687 | if (! process_note (& inote, filedata)) | |
20688 | res = FALSE; | |
20689 | ||
20690 | free (temp); | |
20691 | temp = NULL; | |
20692 | } | |
20693 | ||
20694 | free (pnotes); | |
20695 | ||
20696 | return res; | |
20697 | } | |
20698 | ||
20699 | static bfd_boolean | |
20700 | process_corefile_note_segments (Filedata * filedata) | |
20701 | { | |
20702 | Elf_Internal_Phdr * segment; | |
20703 | unsigned int i; | |
20704 | bfd_boolean res = TRUE; | |
20705 | ||
20706 | if (! get_program_headers (filedata)) | |
20707 | return TRUE; | |
20708 | ||
20709 | for (i = 0, segment = filedata->program_headers; | |
20710 | i < filedata->file_header.e_phnum; | |
20711 | i++, segment++) | |
20712 | { | |
20713 | if (segment->p_type == PT_NOTE) | |
20714 | if (! process_notes_at (filedata, NULL, | |
20715 | (bfd_vma) segment->p_offset, | |
20716 | (bfd_vma) segment->p_filesz, | |
20717 | (bfd_vma) segment->p_align)) | |
20718 | res = FALSE; | |
20719 | } | |
20720 | ||
20721 | return res; | |
20722 | } | |
20723 | ||
20724 | static bfd_boolean | |
20725 | process_v850_notes (Filedata * filedata, bfd_vma offset, bfd_vma length) | |
20726 | { | |
20727 | Elf_External_Note * pnotes; | |
20728 | Elf_External_Note * external; | |
20729 | char * end; | |
20730 | bfd_boolean res = TRUE; | |
20731 | ||
20732 | if (length <= 0) | |
20733 | return FALSE; | |
20734 | ||
20735 | pnotes = (Elf_External_Note *) get_data (NULL, filedata, offset, 1, length, | |
20736 | _("v850 notes")); | |
20737 | if (pnotes == NULL) | |
20738 | return FALSE; | |
20739 | ||
20740 | external = pnotes; | |
20741 | end = (char*) pnotes + length; | |
20742 | ||
20743 | printf (_("\nDisplaying contents of Renesas V850 notes section at offset 0x%lx with length 0x%lx:\n"), | |
20744 | (unsigned long) offset, (unsigned long) length); | |
20745 | ||
20746 | while ((char *) external + sizeof (Elf_External_Note) < end) | |
20747 | { | |
20748 | Elf_External_Note * next; | |
20749 | Elf_Internal_Note inote; | |
20750 | ||
20751 | inote.type = BYTE_GET (external->type); | |
20752 | inote.namesz = BYTE_GET (external->namesz); | |
20753 | inote.namedata = external->name; | |
20754 | inote.descsz = BYTE_GET (external->descsz); | |
20755 | inote.descdata = inote.namedata + align_power (inote.namesz, 2); | |
20756 | inote.descpos = offset + (inote.descdata - (char *) pnotes); | |
20757 | ||
20758 | if (inote.descdata < (char *) pnotes || inote.descdata >= end) | |
20759 | { | |
20760 | warn (_("Corrupt note: name size is too big: %lx\n"), inote.namesz); | |
20761 | inote.descdata = inote.namedata; | |
20762 | inote.namesz = 0; | |
20763 | } | |
20764 | ||
20765 | next = (Elf_External_Note *) (inote.descdata + align_power (inote.descsz, 2)); | |
20766 | ||
20767 | if ( ((char *) next > end) | |
20768 | || ((char *) next < (char *) pnotes)) | |
20769 | { | |
20770 | warn (_("corrupt descsz found in note at offset 0x%lx\n"), | |
20771 | (unsigned long) ((char *) external - (char *) pnotes)); | |
20772 | warn (_(" type: 0x%lx, namesize: 0x%lx, descsize: 0x%lx\n"), | |
20773 | inote.type, inote.namesz, inote.descsz); | |
20774 | break; | |
20775 | } | |
20776 | ||
20777 | external = next; | |
20778 | ||
20779 | /* Prevent out-of-bounds indexing. */ | |
20780 | if ( inote.namedata + inote.namesz > end | |
20781 | || inote.namedata + inote.namesz < inote.namedata) | |
20782 | { | |
20783 | warn (_("corrupt namesz found in note at offset 0x%lx\n"), | |
20784 | (unsigned long) ((char *) external - (char *) pnotes)); | |
20785 | warn (_(" type: 0x%lx, namesize: 0x%lx, descsize: 0x%lx\n"), | |
20786 | inote.type, inote.namesz, inote.descsz); | |
20787 | break; | |
20788 | } | |
20789 | ||
20790 | printf (" %s: ", get_v850_elf_note_type (inote.type)); | |
20791 | ||
20792 | if (! print_v850_note (& inote)) | |
20793 | { | |
20794 | res = FALSE; | |
20795 | printf ("<corrupt sizes: namesz: %lx, descsz: %lx>\n", | |
20796 | inote.namesz, inote.descsz); | |
20797 | } | |
20798 | } | |
20799 | ||
20800 | free (pnotes); | |
20801 | ||
20802 | return res; | |
20803 | } | |
20804 | ||
20805 | static bfd_boolean | |
20806 | process_note_sections (Filedata * filedata) | |
20807 | { | |
20808 | Elf_Internal_Shdr * section; | |
20809 | unsigned long i; | |
20810 | unsigned int n = 0; | |
20811 | bfd_boolean res = TRUE; | |
20812 | ||
20813 | for (i = 0, section = filedata->section_headers; | |
20814 | i < filedata->file_header.e_shnum && section != NULL; | |
20815 | i++, section++) | |
20816 | { | |
20817 | if (section->sh_type == SHT_NOTE) | |
20818 | { | |
20819 | if (! process_notes_at (filedata, section, | |
20820 | (bfd_vma) section->sh_offset, | |
20821 | (bfd_vma) section->sh_size, | |
20822 | (bfd_vma) section->sh_addralign)) | |
20823 | res = FALSE; | |
20824 | n++; | |
20825 | } | |
20826 | ||
20827 | if (( filedata->file_header.e_machine == EM_V800 | |
20828 | || filedata->file_header.e_machine == EM_V850 | |
20829 | || filedata->file_header.e_machine == EM_CYGNUS_V850) | |
20830 | && section->sh_type == SHT_RENESAS_INFO) | |
20831 | { | |
20832 | if (! process_v850_notes (filedata, | |
20833 | (bfd_vma) section->sh_offset, | |
20834 | (bfd_vma) section->sh_size)) | |
20835 | res = FALSE; | |
20836 | n++; | |
20837 | } | |
20838 | } | |
20839 | ||
20840 | if (n == 0) | |
20841 | /* Try processing NOTE segments instead. */ | |
20842 | return process_corefile_note_segments (filedata); | |
20843 | ||
20844 | return res; | |
20845 | } | |
20846 | ||
20847 | static bfd_boolean | |
20848 | process_notes (Filedata * filedata) | |
20849 | { | |
20850 | /* If we have not been asked to display the notes then do nothing. */ | |
20851 | if (! do_notes) | |
20852 | return TRUE; | |
20853 | ||
20854 | if (filedata->file_header.e_type != ET_CORE) | |
20855 | return process_note_sections (filedata); | |
20856 | ||
20857 | /* No program headers means no NOTE segment. */ | |
20858 | if (filedata->file_header.e_phnum > 0) | |
20859 | return process_corefile_note_segments (filedata); | |
20860 | ||
20861 | if (filedata->is_separate) | |
20862 | printf (_("No notes found in linked file '%s'.\n"), | |
20863 | filedata->file_name); | |
20864 | else | |
20865 | printf (_("No notes found file.\n")); | |
20866 | ||
20867 | return TRUE; | |
20868 | } | |
20869 | ||
20870 | static unsigned char * | |
20871 | display_public_gnu_attributes (unsigned char * start, | |
20872 | const unsigned char * const end) | |
20873 | { | |
20874 | printf (_(" Unknown GNU attribute: %s\n"), start); | |
20875 | ||
20876 | start += strnlen ((char *) start, end - start); | |
20877 | display_raw_attribute (start, end); | |
20878 | ||
20879 | return (unsigned char *) end; | |
20880 | } | |
20881 | ||
20882 | static unsigned char * | |
20883 | display_generic_attribute (unsigned char * start, | |
20884 | unsigned int tag, | |
20885 | const unsigned char * const end) | |
20886 | { | |
20887 | if (tag == 0) | |
20888 | return (unsigned char *) end; | |
20889 | ||
20890 | return display_tag_value (tag, start, end); | |
20891 | } | |
20892 | ||
20893 | static bfd_boolean | |
20894 | process_arch_specific (Filedata * filedata) | |
20895 | { | |
20896 | if (! do_arch) | |
20897 | return TRUE; | |
20898 | ||
20899 | switch (filedata->file_header.e_machine) | |
20900 | { | |
20901 | case EM_ARC: | |
20902 | case EM_ARC_COMPACT: | |
20903 | case EM_ARC_COMPACT2: | |
20904 | return process_attributes (filedata, "ARC", SHT_ARC_ATTRIBUTES, | |
20905 | display_arc_attribute, | |
20906 | display_generic_attribute); | |
20907 | case EM_ARM: | |
20908 | return process_attributes (filedata, "aeabi", SHT_ARM_ATTRIBUTES, | |
20909 | display_arm_attribute, | |
20910 | display_generic_attribute); | |
20911 | ||
20912 | case EM_MIPS: | |
20913 | case EM_MIPS_RS3_LE: | |
20914 | return process_mips_specific (filedata); | |
20915 | ||
20916 | case EM_MSP430: | |
20917 | return process_attributes (filedata, "mspabi", SHT_MSP430_ATTRIBUTES, | |
20918 | display_msp430_attribute, | |
20919 | display_msp430_gnu_attribute); | |
20920 | ||
20921 | case EM_RISCV: | |
20922 | return process_attributes (filedata, "riscv", SHT_RISCV_ATTRIBUTES, | |
20923 | display_riscv_attribute, | |
20924 | display_generic_attribute); | |
20925 | ||
20926 | case EM_NDS32: | |
20927 | return process_nds32_specific (filedata); | |
20928 | ||
20929 | case EM_68K: | |
20930 | return process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL, | |
20931 | display_m68k_gnu_attribute); | |
20932 | ||
20933 | case EM_PPC: | |
20934 | case EM_PPC64: | |
20935 | return process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL, | |
20936 | display_power_gnu_attribute); | |
20937 | ||
20938 | case EM_S390: | |
20939 | case EM_S390_OLD: | |
20940 | return process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL, | |
20941 | display_s390_gnu_attribute); | |
20942 | ||
20943 | case EM_SPARC: | |
20944 | case EM_SPARC32PLUS: | |
20945 | case EM_SPARCV9: | |
20946 | return process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL, | |
20947 | display_sparc_gnu_attribute); | |
20948 | ||
20949 | case EM_TI_C6000: | |
20950 | return process_attributes (filedata, "c6xabi", SHT_C6000_ATTRIBUTES, | |
20951 | display_tic6x_attribute, | |
20952 | display_generic_attribute); | |
20953 | ||
20954 | case EM_CSKY: | |
20955 | return process_attributes (filedata, "csky", SHT_CSKY_ATTRIBUTES, | |
20956 | display_csky_attribute, NULL); | |
20957 | ||
20958 | default: | |
20959 | return process_attributes (filedata, "gnu", SHT_GNU_ATTRIBUTES, | |
20960 | display_public_gnu_attributes, | |
20961 | display_generic_attribute); | |
20962 | } | |
20963 | } | |
20964 | ||
20965 | static bfd_boolean | |
20966 | get_file_header (Filedata * filedata) | |
20967 | { | |
20968 | /* Read in the identity array. */ | |
20969 | if (fread (filedata->file_header.e_ident, EI_NIDENT, 1, filedata->handle) != 1) | |
20970 | return FALSE; | |
20971 | ||
20972 | /* Determine how to read the rest of the header. */ | |
20973 | switch (filedata->file_header.e_ident[EI_DATA]) | |
20974 | { | |
20975 | default: | |
20976 | case ELFDATANONE: | |
20977 | case ELFDATA2LSB: | |
20978 | byte_get = byte_get_little_endian; | |
20979 | byte_put = byte_put_little_endian; | |
20980 | break; | |
20981 | case ELFDATA2MSB: | |
20982 | byte_get = byte_get_big_endian; | |
20983 | byte_put = byte_put_big_endian; | |
20984 | break; | |
20985 | } | |
20986 | ||
20987 | /* For now we only support 32 bit and 64 bit ELF files. */ | |
20988 | is_32bit_elf = (filedata->file_header.e_ident[EI_CLASS] != ELFCLASS64); | |
20989 | ||
20990 | /* Read in the rest of the header. */ | |
20991 | if (is_32bit_elf) | |
20992 | { | |
20993 | Elf32_External_Ehdr ehdr32; | |
20994 | ||
20995 | if (fread (ehdr32.e_type, sizeof (ehdr32) - EI_NIDENT, 1, filedata->handle) != 1) | |
20996 | return FALSE; | |
20997 | ||
20998 | filedata->file_header.e_type = BYTE_GET (ehdr32.e_type); | |
20999 | filedata->file_header.e_machine = BYTE_GET (ehdr32.e_machine); | |
21000 | filedata->file_header.e_version = BYTE_GET (ehdr32.e_version); | |
21001 | filedata->file_header.e_entry = BYTE_GET (ehdr32.e_entry); | |
21002 | filedata->file_header.e_phoff = BYTE_GET (ehdr32.e_phoff); | |
21003 | filedata->file_header.e_shoff = BYTE_GET (ehdr32.e_shoff); | |
21004 | filedata->file_header.e_flags = BYTE_GET (ehdr32.e_flags); | |
21005 | filedata->file_header.e_ehsize = BYTE_GET (ehdr32.e_ehsize); | |
21006 | filedata->file_header.e_phentsize = BYTE_GET (ehdr32.e_phentsize); | |
21007 | filedata->file_header.e_phnum = BYTE_GET (ehdr32.e_phnum); | |
21008 | filedata->file_header.e_shentsize = BYTE_GET (ehdr32.e_shentsize); | |
21009 | filedata->file_header.e_shnum = BYTE_GET (ehdr32.e_shnum); | |
21010 | filedata->file_header.e_shstrndx = BYTE_GET (ehdr32.e_shstrndx); | |
21011 | } | |
21012 | else | |
21013 | { | |
21014 | Elf64_External_Ehdr ehdr64; | |
21015 | ||
21016 | /* If we have been compiled with sizeof (bfd_vma) == 4, then | |
21017 | we will not be able to cope with the 64bit data found in | |
21018 | 64 ELF files. Detect this now and abort before we start | |
21019 | overwriting things. */ | |
21020 | if (sizeof (bfd_vma) < 8) | |
21021 | { | |
21022 | error (_("This instance of readelf has been built without support for a\n\ | |
21023 | 64 bit data type and so it cannot read 64 bit ELF files.\n")); | |
21024 | return FALSE; | |
21025 | } | |
21026 | ||
21027 | if (fread (ehdr64.e_type, sizeof (ehdr64) - EI_NIDENT, 1, filedata->handle) != 1) | |
21028 | return FALSE; | |
21029 | ||
21030 | filedata->file_header.e_type = BYTE_GET (ehdr64.e_type); | |
21031 | filedata->file_header.e_machine = BYTE_GET (ehdr64.e_machine); | |
21032 | filedata->file_header.e_version = BYTE_GET (ehdr64.e_version); | |
21033 | filedata->file_header.e_entry = BYTE_GET (ehdr64.e_entry); | |
21034 | filedata->file_header.e_phoff = BYTE_GET (ehdr64.e_phoff); | |
21035 | filedata->file_header.e_shoff = BYTE_GET (ehdr64.e_shoff); | |
21036 | filedata->file_header.e_flags = BYTE_GET (ehdr64.e_flags); | |
21037 | filedata->file_header.e_ehsize = BYTE_GET (ehdr64.e_ehsize); | |
21038 | filedata->file_header.e_phentsize = BYTE_GET (ehdr64.e_phentsize); | |
21039 | filedata->file_header.e_phnum = BYTE_GET (ehdr64.e_phnum); | |
21040 | filedata->file_header.e_shentsize = BYTE_GET (ehdr64.e_shentsize); | |
21041 | filedata->file_header.e_shnum = BYTE_GET (ehdr64.e_shnum); | |
21042 | filedata->file_header.e_shstrndx = BYTE_GET (ehdr64.e_shstrndx); | |
21043 | } | |
21044 | ||
21045 | if (filedata->file_header.e_shoff) | |
21046 | { | |
21047 | /* There may be some extensions in the first section header. Don't | |
21048 | bomb if we can't read it. */ | |
21049 | if (is_32bit_elf) | |
21050 | get_32bit_section_headers (filedata, TRUE); | |
21051 | else | |
21052 | get_64bit_section_headers (filedata, TRUE); | |
21053 | } | |
21054 | ||
21055 | return TRUE; | |
21056 | } | |
21057 | ||
21058 | static void | |
21059 | close_file (Filedata * filedata) | |
21060 | { | |
21061 | if (filedata) | |
21062 | { | |
21063 | if (filedata->handle) | |
21064 | fclose (filedata->handle); | |
21065 | free (filedata); | |
21066 | } | |
21067 | } | |
21068 | ||
21069 | void | |
21070 | close_debug_file (void * data) | |
21071 | { | |
21072 | close_file ((Filedata *) data); | |
21073 | } | |
21074 | ||
21075 | static Filedata * | |
21076 | open_file (const char * pathname, bfd_boolean is_separate) | |
21077 | { | |
21078 | struct stat statbuf; | |
21079 | Filedata * filedata = NULL; | |
21080 | ||
21081 | if (stat (pathname, & statbuf) < 0 | |
21082 | || ! S_ISREG (statbuf.st_mode)) | |
21083 | goto fail; | |
21084 | ||
21085 | filedata = calloc (1, sizeof * filedata); | |
21086 | if (filedata == NULL) | |
21087 | goto fail; | |
21088 | ||
21089 | filedata->handle = fopen (pathname, "rb"); | |
21090 | if (filedata->handle == NULL) | |
21091 | goto fail; | |
21092 | ||
21093 | filedata->file_size = (bfd_size_type) statbuf.st_size; | |
21094 | filedata->file_name = pathname; | |
21095 | filedata->is_separate = is_separate; | |
21096 | ||
21097 | if (! get_file_header (filedata)) | |
21098 | goto fail; | |
21099 | ||
21100 | if (filedata->file_header.e_shoff) | |
21101 | { | |
21102 | bfd_boolean res; | |
21103 | ||
21104 | /* Read the section headers again, this time for real. */ | |
21105 | if (is_32bit_elf) | |
21106 | res = get_32bit_section_headers (filedata, FALSE); | |
21107 | else | |
21108 | res = get_64bit_section_headers (filedata, FALSE); | |
21109 | ||
21110 | if (!res) | |
21111 | goto fail; | |
21112 | } | |
21113 | ||
21114 | return filedata; | |
21115 | ||
21116 | fail: | |
21117 | if (filedata) | |
21118 | { | |
21119 | if (filedata->handle) | |
21120 | fclose (filedata->handle); | |
21121 | free (filedata); | |
21122 | } | |
21123 | return NULL; | |
21124 | } | |
21125 | ||
21126 | void * | |
21127 | open_debug_file (const char * pathname) | |
21128 | { | |
21129 | return open_file (pathname, TRUE); | |
21130 | } | |
21131 | ||
21132 | static void | |
21133 | initialise_dump_sects (Filedata * filedata) | |
21134 | { | |
21135 | /* Initialise the dump_sects array from the cmdline_dump_sects array. | |
21136 | Note we do this even if cmdline_dump_sects is empty because we | |
21137 | must make sure that the dump_sets array is zeroed out before each | |
21138 | object file is processed. */ | |
21139 | if (filedata->dump.num_dump_sects > cmdline.num_dump_sects) | |
21140 | memset (filedata->dump.dump_sects, 0, | |
21141 | filedata->dump.num_dump_sects * sizeof (*filedata->dump.dump_sects)); | |
21142 | ||
21143 | if (cmdline.num_dump_sects > 0) | |
21144 | { | |
21145 | if (filedata->dump.num_dump_sects == 0) | |
21146 | /* A sneaky way of allocating the dump_sects array. */ | |
21147 | request_dump_bynumber (&filedata->dump, cmdline.num_dump_sects, 0); | |
21148 | ||
21149 | assert (filedata->dump.num_dump_sects >= cmdline.num_dump_sects); | |
21150 | memcpy (filedata->dump.dump_sects, cmdline.dump_sects, | |
21151 | cmdline.num_dump_sects * sizeof (*filedata->dump.dump_sects)); | |
21152 | } | |
21153 | } | |
21154 | ||
21155 | /* Process one ELF object file according to the command line options. | |
21156 | This file may actually be stored in an archive. The file is | |
21157 | positioned at the start of the ELF object. Returns TRUE if no | |
21158 | problems were encountered, FALSE otherwise. */ | |
21159 | ||
21160 | static bfd_boolean | |
21161 | process_object (Filedata * filedata) | |
21162 | { | |
21163 | bfd_boolean have_separate_files; | |
21164 | unsigned int i; | |
21165 | bfd_boolean res; | |
21166 | ||
21167 | if (! get_file_header (filedata)) | |
21168 | { | |
21169 | error (_("%s: Failed to read file header\n"), filedata->file_name); | |
21170 | return FALSE; | |
21171 | } | |
21172 | ||
21173 | /* Initialise per file variables. */ | |
21174 | for (i = ARRAY_SIZE (filedata->version_info); i--;) | |
21175 | filedata->version_info[i] = 0; | |
21176 | ||
21177 | for (i = ARRAY_SIZE (filedata->dynamic_info); i--;) | |
21178 | filedata->dynamic_info[i] = 0; | |
21179 | filedata->dynamic_info_DT_GNU_HASH = 0; | |
21180 | filedata->dynamic_info_DT_MIPS_XHASH = 0; | |
21181 | ||
21182 | /* Process the file. */ | |
21183 | if (show_name) | |
21184 | printf (_("\nFile: %s\n"), filedata->file_name); | |
21185 | ||
21186 | initialise_dump_sects (filedata); | |
21187 | ||
21188 | if (! process_file_header (filedata)) | |
21189 | return FALSE; | |
21190 | ||
21191 | if (! process_section_headers (filedata)) | |
21192 | { | |
21193 | /* Without loaded section headers we cannot process lots of things. */ | |
21194 | do_unwind = do_version = do_dump = do_arch = FALSE; | |
21195 | ||
21196 | if (! do_using_dynamic) | |
21197 | do_syms = do_dyn_syms = do_reloc = FALSE; | |
21198 | } | |
21199 | ||
21200 | if (! process_section_groups (filedata)) | |
21201 | /* Without loaded section groups we cannot process unwind. */ | |
21202 | do_unwind = FALSE; | |
21203 | ||
21204 | res = process_program_headers (filedata); | |
21205 | if (res) | |
21206 | res = process_dynamic_section (filedata); | |
21207 | ||
21208 | if (! process_relocs (filedata)) | |
21209 | res = FALSE; | |
21210 | ||
21211 | if (! process_unwind (filedata)) | |
21212 | res = FALSE; | |
21213 | ||
21214 | if (! process_symbol_table (filedata)) | |
21215 | res = FALSE; | |
21216 | ||
21217 | if (! process_lto_symbol_tables (filedata)) | |
21218 | res = FALSE; | |
21219 | ||
21220 | if (! process_syminfo (filedata)) | |
21221 | res = FALSE; | |
21222 | ||
21223 | if (! process_version_sections (filedata)) | |
21224 | res = FALSE; | |
21225 | ||
21226 | if (filedata->file_header.e_shstrndx != SHN_UNDEF) | |
21227 | have_separate_files = load_separate_debug_files (filedata, filedata->file_name); | |
21228 | else | |
21229 | have_separate_files = FALSE; | |
21230 | ||
21231 | if (! process_section_contents (filedata)) | |
21232 | res = FALSE; | |
21233 | ||
21234 | if (have_separate_files) | |
21235 | { | |
21236 | separate_info * d; | |
21237 | ||
21238 | for (d = first_separate_info; d != NULL; d = d->next) | |
21239 | { | |
21240 | initialise_dump_sects (d->handle); | |
21241 | ||
21242 | if (process_links && ! process_file_header (d->handle)) | |
21243 | res = FALSE; | |
21244 | else if (! process_section_headers (d->handle)) | |
21245 | res = FALSE; | |
21246 | else if (! process_section_contents (d->handle)) | |
21247 | res = FALSE; | |
21248 | else if (process_links) | |
21249 | { | |
21250 | if (! process_section_groups (d->handle)) | |
21251 | res = FALSE; | |
21252 | if (! process_program_headers (d->handle)) | |
21253 | res = FALSE; | |
21254 | if (! process_dynamic_section (d->handle)) | |
21255 | res = FALSE; | |
21256 | if (! process_relocs (d->handle)) | |
21257 | res = FALSE; | |
21258 | if (! process_unwind (d->handle)) | |
21259 | res = FALSE; | |
21260 | if (! process_symbol_table (d->handle)) | |
21261 | res = FALSE; | |
21262 | if (! process_lto_symbol_tables (d->handle)) | |
21263 | res = FALSE; | |
21264 | if (! process_syminfo (d->handle)) | |
21265 | res = FALSE; | |
21266 | if (! process_version_sections (d->handle)) | |
21267 | res = FALSE; | |
21268 | if (! process_notes (d->handle)) | |
21269 | res = FALSE; | |
21270 | } | |
21271 | } | |
21272 | ||
21273 | /* The file handles are closed by the call to free_debug_memory() below. */ | |
21274 | } | |
21275 | ||
21276 | if (! process_notes (filedata)) | |
21277 | res = FALSE; | |
21278 | ||
21279 | if (! process_gnu_liblist (filedata)) | |
21280 | res = FALSE; | |
21281 | ||
21282 | if (! process_arch_specific (filedata)) | |
21283 | res = FALSE; | |
21284 | ||
21285 | free (filedata->program_headers); | |
21286 | filedata->program_headers = NULL; | |
21287 | ||
21288 | free (filedata->section_headers); | |
21289 | filedata->section_headers = NULL; | |
21290 | ||
21291 | free (filedata->string_table); | |
21292 | filedata->string_table = NULL; | |
21293 | filedata->string_table_length = 0; | |
21294 | ||
21295 | free (filedata->dump.dump_sects); | |
21296 | filedata->dump.dump_sects = NULL; | |
21297 | filedata->dump.num_dump_sects = 0; | |
21298 | ||
21299 | free (filedata->dynamic_strings); | |
21300 | filedata->dynamic_strings = NULL; | |
21301 | filedata->dynamic_strings_length = 0; | |
21302 | ||
21303 | free (filedata->dynamic_symbols); | |
21304 | filedata->dynamic_symbols = NULL; | |
21305 | filedata->num_dynamic_syms = 0; | |
21306 | ||
21307 | free (filedata->dynamic_syminfo); | |
21308 | filedata->dynamic_syminfo = NULL; | |
21309 | ||
21310 | free (filedata->dynamic_section); | |
21311 | filedata->dynamic_section = NULL; | |
21312 | ||
21313 | while (filedata->symtab_shndx_list != NULL) | |
21314 | { | |
21315 | elf_section_list *next = filedata->symtab_shndx_list->next; | |
21316 | free (filedata->symtab_shndx_list); | |
21317 | filedata->symtab_shndx_list = next; | |
21318 | } | |
21319 | ||
21320 | free (filedata->section_headers_groups); | |
21321 | filedata->section_headers_groups = NULL; | |
21322 | ||
21323 | if (filedata->section_groups) | |
21324 | { | |
21325 | struct group_list * g; | |
21326 | struct group_list * next; | |
21327 | ||
21328 | for (i = 0; i < filedata->group_count; i++) | |
21329 | { | |
21330 | for (g = filedata->section_groups [i].root; g != NULL; g = next) | |
21331 | { | |
21332 | next = g->next; | |
21333 | free (g); | |
21334 | } | |
21335 | } | |
21336 | ||
21337 | free (filedata->section_groups); | |
21338 | filedata->section_groups = NULL; | |
21339 | } | |
21340 | ||
21341 | free_debug_memory (); | |
21342 | ||
21343 | return res; | |
21344 | } | |
21345 | ||
21346 | /* Process an ELF archive. | |
21347 | On entry the file is positioned just after the ARMAG string. | |
21348 | Returns TRUE upon success, FALSE otherwise. */ | |
21349 | ||
21350 | static bfd_boolean | |
21351 | process_archive (Filedata * filedata, bfd_boolean is_thin_archive) | |
21352 | { | |
21353 | struct archive_info arch; | |
21354 | struct archive_info nested_arch; | |
21355 | size_t got; | |
21356 | bfd_boolean ret = TRUE; | |
21357 | ||
21358 | show_name = TRUE; | |
21359 | ||
21360 | /* The ARCH structure is used to hold information about this archive. */ | |
21361 | arch.file_name = NULL; | |
21362 | arch.file = NULL; | |
21363 | arch.index_array = NULL; | |
21364 | arch.sym_table = NULL; | |
21365 | arch.longnames = NULL; | |
21366 | ||
21367 | /* The NESTED_ARCH structure is used as a single-item cache of information | |
21368 | about a nested archive (when members of a thin archive reside within | |
21369 | another regular archive file). */ | |
21370 | nested_arch.file_name = NULL; | |
21371 | nested_arch.file = NULL; | |
21372 | nested_arch.index_array = NULL; | |
21373 | nested_arch.sym_table = NULL; | |
21374 | nested_arch.longnames = NULL; | |
21375 | ||
21376 | if (setup_archive (&arch, filedata->file_name, filedata->handle, | |
21377 | filedata->file_size, is_thin_archive, | |
21378 | do_archive_index) != 0) | |
21379 | { | |
21380 | ret = FALSE; | |
21381 | goto out; | |
21382 | } | |
21383 | ||
21384 | if (do_archive_index) | |
21385 | { | |
21386 | if (arch.sym_table == NULL) | |
21387 | error (_("%s: unable to dump the index as none was found\n"), | |
21388 | filedata->file_name); | |
21389 | else | |
21390 | { | |
21391 | unsigned long i, l; | |
21392 | unsigned long current_pos; | |
21393 | ||
21394 | printf (_("Index of archive %s: (%lu entries, 0x%lx bytes " | |
21395 | "in the symbol table)\n"), | |
21396 | filedata->file_name, (unsigned long) arch.index_num, | |
21397 | arch.sym_size); | |
21398 | ||
21399 | current_pos = ftell (filedata->handle); | |
21400 | ||
21401 | for (i = l = 0; i < arch.index_num; i++) | |
21402 | { | |
21403 | if (i == 0 | |
21404 | || (i > 0 && arch.index_array[i] != arch.index_array[i - 1])) | |
21405 | { | |
21406 | char * member_name | |
21407 | = get_archive_member_name_at (&arch, arch.index_array[i], | |
21408 | &nested_arch); | |
21409 | ||
21410 | if (member_name != NULL) | |
21411 | { | |
21412 | char * qualified_name | |
21413 | = make_qualified_name (&arch, &nested_arch, | |
21414 | member_name); | |
21415 | ||
21416 | if (qualified_name != NULL) | |
21417 | { | |
21418 | printf (_("Contents of binary %s at offset "), | |
21419 | qualified_name); | |
21420 | (void) print_vma (arch.index_array[i], PREFIX_HEX); | |
21421 | putchar ('\n'); | |
21422 | free (qualified_name); | |
21423 | } | |
21424 | free (member_name); | |
21425 | } | |
21426 | } | |
21427 | ||
21428 | if (l >= arch.sym_size) | |
21429 | { | |
21430 | error (_("%s: end of the symbol table reached " | |
21431 | "before the end of the index\n"), | |
21432 | filedata->file_name); | |
21433 | ret = FALSE; | |
21434 | break; | |
21435 | } | |
21436 | /* PR 17531: file: 0b6630b2. */ | |
21437 | printf ("\t%.*s\n", | |
21438 | (int) (arch.sym_size - l), arch.sym_table + l); | |
21439 | l += strnlen (arch.sym_table + l, arch.sym_size - l) + 1; | |
21440 | } | |
21441 | ||
21442 | if (arch.uses_64bit_indices) | |
21443 | l = (l + 7) & ~ 7; | |
21444 | else | |
21445 | l += l & 1; | |
21446 | ||
21447 | if (l < arch.sym_size) | |
21448 | { | |
21449 | error (ngettext ("%s: %ld byte remains in the symbol table, " | |
21450 | "but without corresponding entries in " | |
21451 | "the index table\n", | |
21452 | "%s: %ld bytes remain in the symbol table, " | |
21453 | "but without corresponding entries in " | |
21454 | "the index table\n", | |
21455 | arch.sym_size - l), | |
21456 | filedata->file_name, arch.sym_size - l); | |
21457 | ret = FALSE; | |
21458 | } | |
21459 | ||
21460 | if (fseek (filedata->handle, current_pos, SEEK_SET) != 0) | |
21461 | { | |
21462 | error (_("%s: failed to seek back to start of object files " | |
21463 | "in the archive\n"), | |
21464 | filedata->file_name); | |
21465 | ret = FALSE; | |
21466 | goto out; | |
21467 | } | |
21468 | } | |
21469 | ||
21470 | if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections | |
21471 | && !do_segments && !do_header && !do_dump && !do_version | |
21472 | && !do_histogram && !do_debugging && !do_arch && !do_notes | |
21473 | && !do_section_groups && !do_dyn_syms) | |
21474 | { | |
21475 | ret = TRUE; /* Archive index only. */ | |
21476 | goto out; | |
21477 | } | |
21478 | } | |
21479 | ||
21480 | while (1) | |
21481 | { | |
21482 | char * name; | |
21483 | size_t namelen; | |
21484 | char * qualified_name; | |
21485 | ||
21486 | /* Read the next archive header. */ | |
21487 | if (fseek (filedata->handle, arch.next_arhdr_offset, SEEK_SET) != 0) | |
21488 | { | |
21489 | error (_("%s: failed to seek to next archive header\n"), | |
21490 | arch.file_name); | |
21491 | ret = FALSE; | |
21492 | break; | |
21493 | } | |
21494 | got = fread (&arch.arhdr, 1, sizeof arch.arhdr, filedata->handle); | |
21495 | if (got != sizeof arch.arhdr) | |
21496 | { | |
21497 | if (got == 0) | |
21498 | break; | |
21499 | /* PR 24049 - we cannot use filedata->file_name as this will | |
21500 | have already been freed. */ | |
21501 | error (_("%s: failed to read archive header\n"), arch.file_name); | |
21502 | ||
21503 | ret = FALSE; | |
21504 | break; | |
21505 | } | |
21506 | if (memcmp (arch.arhdr.ar_fmag, ARFMAG, 2) != 0) | |
21507 | { | |
21508 | error (_("%s: did not find a valid archive header\n"), | |
21509 | arch.file_name); | |
21510 | ret = FALSE; | |
21511 | break; | |
21512 | } | |
21513 | ||
21514 | arch.next_arhdr_offset += sizeof arch.arhdr; | |
21515 | ||
21516 | filedata->archive_file_size = strtoul (arch.arhdr.ar_size, NULL, 10); | |
21517 | if (filedata->archive_file_size & 01) | |
21518 | ++filedata->archive_file_size; | |
21519 | ||
21520 | name = get_archive_member_name (&arch, &nested_arch); | |
21521 | if (name == NULL) | |
21522 | { | |
21523 | error (_("%s: bad archive file name\n"), arch.file_name); | |
21524 | ret = FALSE; | |
21525 | break; | |
21526 | } | |
21527 | namelen = strlen (name); | |
21528 | ||
21529 | qualified_name = make_qualified_name (&arch, &nested_arch, name); | |
21530 | if (qualified_name == NULL) | |
21531 | { | |
21532 | error (_("%s: bad archive file name\n"), arch.file_name); | |
21533 | free (name); | |
21534 | ret = FALSE; | |
21535 | break; | |
21536 | } | |
21537 | ||
21538 | if (is_thin_archive && arch.nested_member_origin == 0) | |
21539 | { | |
21540 | /* This is a proxy for an external member of a thin archive. */ | |
21541 | Filedata * member_filedata; | |
21542 | char * member_file_name = adjust_relative_path | |
21543 | (filedata->file_name, name, namelen); | |
21544 | ||
21545 | free (name); | |
21546 | if (member_file_name == NULL) | |
21547 | { | |
21548 | free (qualified_name); | |
21549 | ret = FALSE; | |
21550 | break; | |
21551 | } | |
21552 | ||
21553 | member_filedata = open_file (member_file_name, FALSE); | |
21554 | if (member_filedata == NULL) | |
21555 | { | |
21556 | error (_("Input file '%s' is not readable.\n"), member_file_name); | |
21557 | free (member_file_name); | |
21558 | free (qualified_name); | |
21559 | ret = FALSE; | |
21560 | break; | |
21561 | } | |
21562 | ||
21563 | filedata->archive_file_offset = arch.nested_member_origin; | |
21564 | member_filedata->file_name = qualified_name; | |
21565 | ||
21566 | if (! process_object (member_filedata)) | |
21567 | ret = FALSE; | |
21568 | ||
21569 | close_file (member_filedata); | |
21570 | free (member_file_name); | |
21571 | } | |
21572 | else if (is_thin_archive) | |
21573 | { | |
21574 | Filedata thin_filedata; | |
21575 | ||
21576 | memset (&thin_filedata, 0, sizeof (thin_filedata)); | |
21577 | ||
21578 | /* PR 15140: Allow for corrupt thin archives. */ | |
21579 | if (nested_arch.file == NULL) | |
21580 | { | |
21581 | error (_("%s: contains corrupt thin archive: %s\n"), | |
21582 | qualified_name, name); | |
21583 | free (qualified_name); | |
21584 | free (name); | |
21585 | ret = FALSE; | |
21586 | break; | |
21587 | } | |
21588 | free (name); | |
21589 | ||
21590 | /* This is a proxy for a member of a nested archive. */ | |
21591 | filedata->archive_file_offset | |
21592 | = arch.nested_member_origin + sizeof arch.arhdr; | |
21593 | ||
21594 | /* The nested archive file will have been opened and setup by | |
21595 | get_archive_member_name. */ | |
21596 | if (fseek (nested_arch.file, filedata->archive_file_offset, | |
21597 | SEEK_SET) != 0) | |
21598 | { | |
21599 | error (_("%s: failed to seek to archive member.\n"), | |
21600 | nested_arch.file_name); | |
21601 | free (qualified_name); | |
21602 | ret = FALSE; | |
21603 | break; | |
21604 | } | |
21605 | ||
21606 | thin_filedata.handle = nested_arch.file; | |
21607 | thin_filedata.file_name = qualified_name; | |
21608 | ||
21609 | if (! process_object (& thin_filedata)) | |
21610 | ret = FALSE; | |
21611 | } | |
21612 | else | |
21613 | { | |
21614 | free (name); | |
21615 | filedata->archive_file_offset = arch.next_arhdr_offset; | |
21616 | filedata->file_name = qualified_name; | |
21617 | if (! process_object (filedata)) | |
21618 | ret = FALSE; | |
21619 | arch.next_arhdr_offset += filedata->archive_file_size; | |
21620 | /* Stop looping with "negative" archive_file_size. */ | |
21621 | if (arch.next_arhdr_offset < filedata->archive_file_size) | |
21622 | arch.next_arhdr_offset = -1ul; | |
21623 | } | |
21624 | ||
21625 | free (qualified_name); | |
21626 | } | |
21627 | ||
21628 | out: | |
21629 | if (nested_arch.file != NULL) | |
21630 | fclose (nested_arch.file); | |
21631 | release_archive (&nested_arch); | |
21632 | release_archive (&arch); | |
21633 | ||
21634 | return ret; | |
21635 | } | |
21636 | ||
21637 | static bfd_boolean | |
21638 | process_file (char * file_name) | |
21639 | { | |
21640 | Filedata * filedata = NULL; | |
21641 | struct stat statbuf; | |
21642 | char armag[SARMAG]; | |
21643 | bfd_boolean ret = TRUE; | |
21644 | ||
21645 | if (stat (file_name, &statbuf) < 0) | |
21646 | { | |
21647 | if (errno == ENOENT) | |
21648 | error (_("'%s': No such file\n"), file_name); | |
21649 | else | |
21650 | error (_("Could not locate '%s'. System error message: %s\n"), | |
21651 | file_name, strerror (errno)); | |
21652 | return FALSE; | |
21653 | } | |
21654 | ||
21655 | if (! S_ISREG (statbuf.st_mode)) | |
21656 | { | |
21657 | error (_("'%s' is not an ordinary file\n"), file_name); | |
21658 | return FALSE; | |
21659 | } | |
21660 | ||
21661 | filedata = calloc (1, sizeof * filedata); | |
21662 | if (filedata == NULL) | |
21663 | { | |
21664 | error (_("Out of memory allocating file data structure\n")); | |
21665 | return FALSE; | |
21666 | } | |
21667 | ||
21668 | filedata->file_name = file_name; | |
21669 | filedata->handle = fopen (file_name, "rb"); | |
21670 | if (filedata->handle == NULL) | |
21671 | { | |
21672 | error (_("Input file '%s' is not readable.\n"), file_name); | |
21673 | free (filedata); | |
21674 | return FALSE; | |
21675 | } | |
21676 | ||
21677 | if (fread (armag, SARMAG, 1, filedata->handle) != 1) | |
21678 | { | |
21679 | error (_("%s: Failed to read file's magic number\n"), file_name); | |
21680 | fclose (filedata->handle); | |
21681 | free (filedata); | |
21682 | return FALSE; | |
21683 | } | |
21684 | ||
21685 | filedata->file_size = (bfd_size_type) statbuf.st_size; | |
21686 | filedata->is_separate = FALSE; | |
21687 | ||
21688 | if (memcmp (armag, ARMAG, SARMAG) == 0) | |
21689 | { | |
21690 | if (! process_archive (filedata, FALSE)) | |
21691 | ret = FALSE; | |
21692 | } | |
21693 | else if (memcmp (armag, ARMAGT, SARMAG) == 0) | |
21694 | { | |
21695 | if ( ! process_archive (filedata, TRUE)) | |
21696 | ret = FALSE; | |
21697 | } | |
21698 | else | |
21699 | { | |
21700 | if (do_archive_index && !check_all) | |
21701 | error (_("File %s is not an archive so its index cannot be displayed.\n"), | |
21702 | file_name); | |
21703 | ||
21704 | rewind (filedata->handle); | |
21705 | filedata->archive_file_size = filedata->archive_file_offset = 0; | |
21706 | ||
21707 | if (! process_object (filedata)) | |
21708 | ret = FALSE; | |
21709 | } | |
21710 | ||
21711 | fclose (filedata->handle); | |
21712 | free (filedata->section_headers); | |
21713 | free (filedata->program_headers); | |
21714 | free (filedata->string_table); | |
21715 | free (filedata->dump.dump_sects); | |
21716 | free (filedata); | |
21717 | ||
21718 | free (ba_cache.strtab); | |
21719 | ba_cache.strtab = NULL; | |
21720 | free (ba_cache.symtab); | |
21721 | ba_cache.symtab = NULL; | |
21722 | ba_cache.filedata = NULL; | |
21723 | ||
21724 | return ret; | |
21725 | } | |
21726 | ||
21727 | #ifdef SUPPORT_DISASSEMBLY | |
21728 | /* Needed by the i386 disassembler. For extra credit, someone could | |
21729 | fix this so that we insert symbolic addresses here, esp for GOT/PLT | |
21730 | symbols. */ | |
21731 | ||
21732 | void | |
21733 | print_address (unsigned int addr, FILE * outfile) | |
21734 | { | |
21735 | fprintf (outfile,"0x%8.8x", addr); | |
21736 | } | |
21737 | ||
21738 | /* Needed by the i386 disassembler. */ | |
21739 | ||
21740 | void | |
21741 | db_task_printsym (unsigned int addr) | |
21742 | { | |
21743 | print_address (addr, stderr); | |
21744 | } | |
21745 | #endif | |
21746 | ||
21747 | int | |
21748 | main (int argc, char ** argv) | |
21749 | { | |
21750 | int err; | |
21751 | ||
21752 | #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES) | |
21753 | setlocale (LC_MESSAGES, ""); | |
21754 | #endif | |
21755 | #if defined (HAVE_SETLOCALE) | |
21756 | setlocale (LC_CTYPE, ""); | |
21757 | #endif | |
21758 | bindtextdomain (PACKAGE, LOCALEDIR); | |
21759 | textdomain (PACKAGE); | |
21760 | ||
21761 | expandargv (&argc, &argv); | |
21762 | ||
21763 | parse_args (& cmdline, argc, argv); | |
21764 | ||
21765 | if (optind < (argc - 1)) | |
21766 | /* When displaying information for more than one file, | |
21767 | prefix the information with the file name. */ | |
21768 | show_name = TRUE; | |
21769 | else if (optind >= argc) | |
21770 | { | |
21771 | /* Ensure that the warning is always displayed. */ | |
21772 | do_checks = TRUE; | |
21773 | ||
21774 | warn (_("Nothing to do.\n")); | |
21775 | usage (stderr); | |
21776 | } | |
21777 | ||
21778 | err = FALSE; | |
21779 | while (optind < argc) | |
21780 | if (! process_file (argv[optind++])) | |
21781 | err = TRUE; | |
21782 | ||
21783 | free (cmdline.dump_sects); | |
21784 | ||
21785 | free (dump_ctf_symtab_name); | |
21786 | free (dump_ctf_strtab_name); | |
21787 | free (dump_ctf_parent_name); | |
21788 | ||
21789 | return err ? EXIT_FAILURE : EXIT_SUCCESS; | |
21790 | } |