]>
Commit | Line | Data |
---|---|---|
1 | /* readelf.c -- display contents of an ELF format file | |
2 | Copyright (C) 1998-2022 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_ZSTD | |
48 | #include <zstd.h> | |
49 | #endif | |
50 | #include <wchar.h> | |
51 | ||
52 | #if defined HAVE_MSGPACK | |
53 | #include <msgpack.h> | |
54 | #endif | |
55 | ||
56 | /* Define BFD64 here, even if our default architecture is 32 bit ELF | |
57 | as this will allow us to read in and parse 64bit and 32bit ELF files. */ | |
58 | #define BFD64 | |
59 | ||
60 | #include "bfd.h" | |
61 | #include "bucomm.h" | |
62 | #include "elfcomm.h" | |
63 | #include "demanguse.h" | |
64 | #include "dwarf.h" | |
65 | #include "ctf-api.h" | |
66 | #include "sframe-api.h" | |
67 | #include "demangle.h" | |
68 | ||
69 | #include "elf/common.h" | |
70 | #include "elf/external.h" | |
71 | #include "elf/internal.h" | |
72 | ||
73 | ||
74 | /* Included here, before RELOC_MACROS_GEN_FUNC is defined, so that | |
75 | we can obtain the H8 reloc numbers. We need these for the | |
76 | get_reloc_size() function. We include h8.h again after defining | |
77 | RELOC_MACROS_GEN_FUNC so that we get the naming function as well. */ | |
78 | ||
79 | #include "elf/h8.h" | |
80 | #undef _ELF_H8_H | |
81 | ||
82 | /* Undo the effects of #including reloc-macros.h. */ | |
83 | ||
84 | #undef START_RELOC_NUMBERS | |
85 | #undef RELOC_NUMBER | |
86 | #undef FAKE_RELOC | |
87 | #undef EMPTY_RELOC | |
88 | #undef END_RELOC_NUMBERS | |
89 | #undef _RELOC_MACROS_H | |
90 | ||
91 | /* The following headers use the elf/reloc-macros.h file to | |
92 | automatically generate relocation recognition functions | |
93 | such as elf_mips_reloc_type() */ | |
94 | ||
95 | #define RELOC_MACROS_GEN_FUNC | |
96 | ||
97 | #include "elf/aarch64.h" | |
98 | #include "elf/alpha.h" | |
99 | #include "elf/amdgpu.h" | |
100 | #include "elf/arc.h" | |
101 | #include "elf/arm.h" | |
102 | #include "elf/avr.h" | |
103 | #include "elf/bfin.h" | |
104 | #include "elf/cr16.h" | |
105 | #include "elf/cris.h" | |
106 | #include "elf/crx.h" | |
107 | #include "elf/csky.h" | |
108 | #include "elf/d10v.h" | |
109 | #include "elf/d30v.h" | |
110 | #include "elf/dlx.h" | |
111 | #include "elf/bpf.h" | |
112 | #include "elf/epiphany.h" | |
113 | #include "elf/fr30.h" | |
114 | #include "elf/frv.h" | |
115 | #include "elf/ft32.h" | |
116 | #include "elf/h8.h" | |
117 | #include "elf/hppa.h" | |
118 | #include "elf/i386.h" | |
119 | #include "elf/i370.h" | |
120 | #include "elf/i860.h" | |
121 | #include "elf/i960.h" | |
122 | #include "elf/ia64.h" | |
123 | #include "elf/ip2k.h" | |
124 | #include "elf/lm32.h" | |
125 | #include "elf/iq2000.h" | |
126 | #include "elf/m32c.h" | |
127 | #include "elf/m32r.h" | |
128 | #include "elf/m68k.h" | |
129 | #include "elf/m68hc11.h" | |
130 | #include "elf/s12z.h" | |
131 | #include "elf/mcore.h" | |
132 | #include "elf/mep.h" | |
133 | #include "elf/metag.h" | |
134 | #include "elf/microblaze.h" | |
135 | #include "elf/mips.h" | |
136 | #include "elf/mmix.h" | |
137 | #include "elf/mn10200.h" | |
138 | #include "elf/mn10300.h" | |
139 | #include "elf/moxie.h" | |
140 | #include "elf/mt.h" | |
141 | #include "elf/msp430.h" | |
142 | #include "elf/nds32.h" | |
143 | #include "elf/nfp.h" | |
144 | #include "elf/nios2.h" | |
145 | #include "elf/or1k.h" | |
146 | #include "elf/pj.h" | |
147 | #include "elf/ppc.h" | |
148 | #include "elf/ppc64.h" | |
149 | #include "elf/pru.h" | |
150 | #include "elf/riscv.h" | |
151 | #include "elf/rl78.h" | |
152 | #include "elf/rx.h" | |
153 | #include "elf/s390.h" | |
154 | #include "elf/score.h" | |
155 | #include "elf/sh.h" | |
156 | #include "elf/sparc.h" | |
157 | #include "elf/spu.h" | |
158 | #include "elf/tic6x.h" | |
159 | #include "elf/tilegx.h" | |
160 | #include "elf/tilepro.h" | |
161 | #include "elf/v850.h" | |
162 | #include "elf/vax.h" | |
163 | #include "elf/visium.h" | |
164 | #include "elf/wasm32.h" | |
165 | #include "elf/x86-64.h" | |
166 | #include "elf/xgate.h" | |
167 | #include "elf/xstormy16.h" | |
168 | #include "elf/xtensa.h" | |
169 | #include "elf/z80.h" | |
170 | #include "elf/loongarch.h" | |
171 | ||
172 | #include "getopt.h" | |
173 | #include "libiberty.h" | |
174 | #include "safe-ctype.h" | |
175 | #include "filenames.h" | |
176 | ||
177 | #ifndef offsetof | |
178 | #define offsetof(TYPE, MEMBER) ((size_t) &(((TYPE *) 0)->MEMBER)) | |
179 | #endif | |
180 | ||
181 | typedef struct elf_section_list | |
182 | { | |
183 | Elf_Internal_Shdr * hdr; | |
184 | struct elf_section_list * next; | |
185 | } elf_section_list; | |
186 | ||
187 | /* Flag bits indicating particular types of dump. */ | |
188 | #define HEX_DUMP (1 << 0) /* The -x command line switch. */ | |
189 | #define DISASS_DUMP (1 << 1) /* The -i command line switch. */ | |
190 | #define DEBUG_DUMP (1 << 2) /* The -w command line switch. */ | |
191 | #define STRING_DUMP (1 << 3) /* The -p command line switch. */ | |
192 | #define RELOC_DUMP (1 << 4) /* The -R command line switch. */ | |
193 | #define CTF_DUMP (1 << 5) /* The --ctf command line switch. */ | |
194 | #define SFRAME_DUMP (1 << 6) /* The --sframe command line switch. */ | |
195 | ||
196 | typedef unsigned char dump_type; | |
197 | ||
198 | /* A linked list of the section names for which dumps were requested. */ | |
199 | struct dump_list_entry | |
200 | { | |
201 | char * name; | |
202 | dump_type type; | |
203 | struct dump_list_entry * next; | |
204 | }; | |
205 | ||
206 | /* A dynamic array of flags indicating for which sections a dump | |
207 | has been requested via command line switches. */ | |
208 | struct dump_data | |
209 | { | |
210 | dump_type * dump_sects; | |
211 | unsigned int num_dump_sects; | |
212 | }; | |
213 | ||
214 | static struct dump_data cmdline; | |
215 | ||
216 | static struct dump_list_entry * dump_sects_byname; | |
217 | ||
218 | char * program_name = "readelf"; | |
219 | ||
220 | static bool show_name = false; | |
221 | static bool do_dynamic = false; | |
222 | static bool do_syms = false; | |
223 | static bool do_dyn_syms = false; | |
224 | static bool do_lto_syms = false; | |
225 | static bool do_reloc = false; | |
226 | static bool do_sections = false; | |
227 | static bool do_section_groups = false; | |
228 | static bool do_section_details = false; | |
229 | static bool do_segments = false; | |
230 | static bool do_unwind = false; | |
231 | static bool do_using_dynamic = false; | |
232 | static bool do_header = false; | |
233 | static bool do_dump = false; | |
234 | static bool do_version = false; | |
235 | static bool do_histogram = false; | |
236 | static bool do_debugging = false; | |
237 | static bool do_ctf = false; | |
238 | static bool do_sframe = false; | |
239 | static bool do_arch = false; | |
240 | static bool do_notes = false; | |
241 | static bool do_archive_index = false; | |
242 | static bool check_all = false; | |
243 | static bool is_32bit_elf = false; | |
244 | static bool decompress_dumps = false; | |
245 | static bool do_not_show_symbol_truncation = false; | |
246 | static bool do_demangle = false; /* Pretty print C++ symbol names. */ | |
247 | static bool process_links = false; | |
248 | static bool dump_any_debugging = false; | |
249 | static int demangle_flags = DMGL_ANSI | DMGL_PARAMS; | |
250 | static int sym_base = 0; | |
251 | ||
252 | static char *dump_ctf_parent_name; | |
253 | static char *dump_ctf_symtab_name; | |
254 | static char *dump_ctf_strtab_name; | |
255 | ||
256 | struct group_list | |
257 | { | |
258 | struct group_list * next; | |
259 | unsigned int section_index; | |
260 | }; | |
261 | ||
262 | struct group | |
263 | { | |
264 | struct group_list * root; | |
265 | unsigned int group_index; | |
266 | }; | |
267 | ||
268 | typedef struct filedata | |
269 | { | |
270 | const char * file_name; | |
271 | bool is_separate; | |
272 | FILE * handle; | |
273 | uint64_t file_size; | |
274 | Elf_Internal_Ehdr file_header; | |
275 | uint64_t archive_file_offset; | |
276 | uint64_t archive_file_size; | |
277 | /* Everything below this point is cleared out by free_filedata. */ | |
278 | Elf_Internal_Shdr * section_headers; | |
279 | Elf_Internal_Phdr * program_headers; | |
280 | char * string_table; | |
281 | uint64_t string_table_length; | |
282 | uint64_t dynamic_addr; | |
283 | uint64_t dynamic_size; | |
284 | uint64_t dynamic_nent; | |
285 | Elf_Internal_Dyn * dynamic_section; | |
286 | Elf_Internal_Shdr * dynamic_strtab_section; | |
287 | char * dynamic_strings; | |
288 | uint64_t dynamic_strings_length; | |
289 | Elf_Internal_Shdr * dynamic_symtab_section; | |
290 | uint64_t num_dynamic_syms; | |
291 | Elf_Internal_Sym * dynamic_symbols; | |
292 | uint64_t version_info[16]; | |
293 | unsigned int dynamic_syminfo_nent; | |
294 | Elf_Internal_Syminfo * dynamic_syminfo; | |
295 | uint64_t dynamic_syminfo_offset; | |
296 | uint64_t nbuckets; | |
297 | uint64_t nchains; | |
298 | uint64_t * buckets; | |
299 | uint64_t * chains; | |
300 | uint64_t ngnubuckets; | |
301 | uint64_t ngnuchains; | |
302 | uint64_t * gnubuckets; | |
303 | uint64_t * gnuchains; | |
304 | uint64_t * mipsxlat; | |
305 | uint64_t gnusymidx; | |
306 | char * program_interpreter; | |
307 | uint64_t dynamic_info[DT_ENCODING]; | |
308 | uint64_t dynamic_info_DT_GNU_HASH; | |
309 | uint64_t dynamic_info_DT_MIPS_XHASH; | |
310 | elf_section_list * symtab_shndx_list; | |
311 | size_t group_count; | |
312 | struct group * section_groups; | |
313 | struct group ** section_headers_groups; | |
314 | /* A dynamic array of flags indicating for which sections a dump of | |
315 | some kind has been requested. It is reset on a per-object file | |
316 | basis and then initialised from the cmdline_dump_sects array, | |
317 | the results of interpreting the -w switch, and the | |
318 | dump_sects_byname list. */ | |
319 | struct dump_data dump; | |
320 | } Filedata; | |
321 | ||
322 | /* How to print a vma value. */ | |
323 | typedef enum print_mode | |
324 | { | |
325 | HEX, | |
326 | HEX_5, | |
327 | DEC, | |
328 | DEC_5, | |
329 | UNSIGNED, | |
330 | UNSIGNED_5, | |
331 | PREFIX_HEX, | |
332 | PREFIX_HEX_5, | |
333 | FULL_HEX, | |
334 | LONG_HEX, | |
335 | OCTAL, | |
336 | OCTAL_5 | |
337 | } | |
338 | print_mode; | |
339 | ||
340 | typedef enum unicode_display_type | |
341 | { | |
342 | unicode_default = 0, | |
343 | unicode_locale, | |
344 | unicode_escape, | |
345 | unicode_hex, | |
346 | unicode_highlight, | |
347 | unicode_invalid | |
348 | } unicode_display_type; | |
349 | ||
350 | static unicode_display_type unicode_display = unicode_default; | |
351 | ||
352 | typedef enum | |
353 | { | |
354 | reltype_unknown, | |
355 | reltype_rel, | |
356 | reltype_rela, | |
357 | reltype_relr | |
358 | } relocation_type; | |
359 | ||
360 | /* Versioned symbol info. */ | |
361 | enum versioned_symbol_info | |
362 | { | |
363 | symbol_undefined, | |
364 | symbol_hidden, | |
365 | symbol_public | |
366 | }; | |
367 | ||
368 | static int | |
369 | fseek64 (FILE *stream, int64_t offset, int whence) | |
370 | { | |
371 | #if defined (HAVE_FSEEKO64) | |
372 | off64_t o = offset; | |
373 | if (o != offset) | |
374 | { | |
375 | errno = EINVAL; | |
376 | return -1; | |
377 | } | |
378 | return fseeko64 (stream, o, whence); | |
379 | #elif defined (HAVE_FSEEKO) | |
380 | off_t o = offset; | |
381 | if (o != offset) | |
382 | { | |
383 | errno = EINVAL; | |
384 | return -1; | |
385 | } | |
386 | return fseeko (stream, o, whence); | |
387 | #else | |
388 | long o = offset; | |
389 | if (o != offset) | |
390 | { | |
391 | errno = EINVAL; | |
392 | return -1; | |
393 | } | |
394 | return fseek (stream, o, whence); | |
395 | #endif | |
396 | } | |
397 | ||
398 | static const char * get_symbol_version_string | |
399 | (Filedata *, bool, const char *, size_t, unsigned, | |
400 | Elf_Internal_Sym *, enum versioned_symbol_info *, unsigned short *); | |
401 | ||
402 | #define UNKNOWN -1 | |
403 | ||
404 | static inline const char * | |
405 | section_name (const Filedata *filedata, const Elf_Internal_Shdr *hdr) | |
406 | { | |
407 | return filedata->string_table + hdr->sh_name; | |
408 | } | |
409 | ||
410 | static inline bool | |
411 | section_name_valid (const Filedata *filedata, const Elf_Internal_Shdr *hdr) | |
412 | { | |
413 | return (hdr != NULL | |
414 | && filedata->string_table != NULL | |
415 | && hdr->sh_name < filedata->string_table_length); | |
416 | } | |
417 | ||
418 | static inline const char * | |
419 | section_name_print (const Filedata *filedata, const Elf_Internal_Shdr *hdr) | |
420 | { | |
421 | if (hdr == NULL) | |
422 | return _("<none>"); | |
423 | if (filedata->string_table == NULL) | |
424 | return _("<no-strings>"); | |
425 | if (hdr->sh_name >= filedata->string_table_length) | |
426 | return _("<corrupt>"); | |
427 | return section_name (filedata, hdr); | |
428 | } | |
429 | ||
430 | #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */ | |
431 | ||
432 | static inline bool | |
433 | valid_symbol_name (const char *strtab, size_t strtab_size, uint64_t offset) | |
434 | { | |
435 | return strtab != NULL && offset < strtab_size; | |
436 | } | |
437 | ||
438 | static inline bool | |
439 | valid_dynamic_name (const Filedata *filedata, uint64_t offset) | |
440 | { | |
441 | return valid_symbol_name (filedata->dynamic_strings, | |
442 | filedata->dynamic_strings_length, offset); | |
443 | } | |
444 | ||
445 | /* GET_DYNAMIC_NAME asssumes that VALID_DYNAMIC_NAME has | |
446 | already been called and verified that the string exists. */ | |
447 | static inline const char * | |
448 | get_dynamic_name (const Filedata *filedata, size_t offset) | |
449 | { | |
450 | return filedata->dynamic_strings + offset; | |
451 | } | |
452 | ||
453 | #define REMOVE_ARCH_BITS(ADDR) \ | |
454 | do \ | |
455 | { \ | |
456 | if (filedata->file_header.e_machine == EM_ARM) \ | |
457 | (ADDR) &= ~1; \ | |
458 | } \ | |
459 | while (0) | |
460 | ||
461 | /* Get the correct GNU hash section name. */ | |
462 | #define GNU_HASH_SECTION_NAME(filedata) \ | |
463 | filedata->dynamic_info_DT_MIPS_XHASH ? ".MIPS.xhash" : ".gnu.hash" | |
464 | \f | |
465 | /* Retrieve NMEMB structures, each SIZE bytes long from FILEDATA starting at | |
466 | OFFSET + the offset of the current archive member, if we are examining an | |
467 | archive. Put the retrieved data into VAR, if it is not NULL. Otherwise | |
468 | allocate a buffer using malloc and fill that. In either case return the | |
469 | pointer to the start of the retrieved data or NULL if something went wrong. | |
470 | If something does go wrong and REASON is not NULL then emit an error | |
471 | message using REASON as part of the context. */ | |
472 | ||
473 | static void * | |
474 | get_data (void *var, | |
475 | Filedata *filedata, | |
476 | uint64_t offset, | |
477 | uint64_t size, | |
478 | uint64_t nmemb, | |
479 | const char *reason) | |
480 | { | |
481 | void * mvar; | |
482 | uint64_t amt = size * nmemb; | |
483 | ||
484 | if (size == 0 || nmemb == 0) | |
485 | return NULL; | |
486 | ||
487 | /* If size_t is smaller than uint64_t, eg because you are building | |
488 | on a 32-bit host, then make sure that when the sizes are cast to | |
489 | size_t no information is lost. */ | |
490 | if ((size_t) size != size | |
491 | || (size_t) nmemb != nmemb | |
492 | || (size_t) amt != amt | |
493 | || amt / size != nmemb | |
494 | || (size_t) amt + 1 == 0) | |
495 | { | |
496 | if (reason) | |
497 | error (_("Size overflow prevents reading %" PRIu64 | |
498 | " elements of size %" PRIu64 " for %s\n"), | |
499 | nmemb, size, reason); | |
500 | return NULL; | |
501 | } | |
502 | ||
503 | /* Be kind to memory checkers (eg valgrind, address sanitizer) by not | |
504 | attempting to allocate memory when the read is bound to fail. */ | |
505 | if (filedata->archive_file_offset > filedata->file_size | |
506 | || offset > filedata->file_size - filedata->archive_file_offset | |
507 | || amt > filedata->file_size - filedata->archive_file_offset - offset) | |
508 | { | |
509 | if (reason) | |
510 | error (_("Reading %" PRIu64 " bytes extends past end of file for %s\n"), | |
511 | amt, reason); | |
512 | return NULL; | |
513 | } | |
514 | ||
515 | if (fseek64 (filedata->handle, filedata->archive_file_offset + offset, | |
516 | SEEK_SET)) | |
517 | { | |
518 | if (reason) | |
519 | error (_("Unable to seek to %#" PRIx64 " for %s\n"), | |
520 | filedata->archive_file_offset + offset, reason); | |
521 | return NULL; | |
522 | } | |
523 | ||
524 | mvar = var; | |
525 | if (mvar == NULL) | |
526 | { | |
527 | /* + 1 so that we can '\0' terminate invalid string table sections. */ | |
528 | mvar = malloc ((size_t) amt + 1); | |
529 | ||
530 | if (mvar == NULL) | |
531 | { | |
532 | if (reason) | |
533 | error (_("Out of memory allocating %" PRIu64 " bytes for %s\n"), | |
534 | amt, reason); | |
535 | return NULL; | |
536 | } | |
537 | ||
538 | ((char *) mvar)[amt] = '\0'; | |
539 | } | |
540 | ||
541 | if (fread (mvar, (size_t) size, (size_t) nmemb, filedata->handle) != nmemb) | |
542 | { | |
543 | if (reason) | |
544 | error (_("Unable to read in %" PRIu64 " bytes of %s\n"), | |
545 | amt, reason); | |
546 | if (mvar != var) | |
547 | free (mvar); | |
548 | return NULL; | |
549 | } | |
550 | ||
551 | return mvar; | |
552 | } | |
553 | ||
554 | /* Print a VMA value in the MODE specified. | |
555 | Returns the number of characters displayed. */ | |
556 | ||
557 | static unsigned int | |
558 | print_vma (uint64_t vma, print_mode mode) | |
559 | { | |
560 | unsigned int nc = 0; | |
561 | ||
562 | switch (mode) | |
563 | { | |
564 | case FULL_HEX: | |
565 | nc = printf ("0x"); | |
566 | /* Fall through. */ | |
567 | case LONG_HEX: | |
568 | if (!is_32bit_elf) | |
569 | return nc + printf ("%16.16" PRIx64, vma); | |
570 | return nc + printf ("%8.8" PRIx64, vma); | |
571 | ||
572 | case DEC_5: | |
573 | if (vma <= 99999) | |
574 | return printf ("%5" PRId64, vma); | |
575 | /* Fall through. */ | |
576 | case PREFIX_HEX: | |
577 | nc = printf ("0x"); | |
578 | /* Fall through. */ | |
579 | case HEX: | |
580 | return nc + printf ("%" PRIx64, vma); | |
581 | ||
582 | case PREFIX_HEX_5: | |
583 | nc = printf ("0x"); | |
584 | /* Fall through. */ | |
585 | case HEX_5: | |
586 | return nc + printf ("%05" PRIx64, vma); | |
587 | ||
588 | case DEC: | |
589 | return printf ("%" PRId64, vma); | |
590 | ||
591 | case UNSIGNED: | |
592 | return printf ("%" PRIu64, vma); | |
593 | ||
594 | case UNSIGNED_5: | |
595 | return printf ("%5" PRIu64, vma); | |
596 | ||
597 | case OCTAL: | |
598 | return printf ("%" PRIo64, vma); | |
599 | ||
600 | case OCTAL_5: | |
601 | return printf ("%5" PRIo64, vma); | |
602 | ||
603 | default: | |
604 | /* FIXME: Report unrecognised mode ? */ | |
605 | return 0; | |
606 | } | |
607 | } | |
608 | ||
609 | ||
610 | /* Display a symbol on stdout. Handles the display of control characters and | |
611 | multibye characters (assuming the host environment supports them). | |
612 | ||
613 | Display at most abs(WIDTH) characters, truncating as necessary, unless do_wide is true. | |
614 | ||
615 | If truncation will happen and do_not_show_symbol_truncation is FALSE then display | |
616 | abs(WIDTH) - 5 characters followed by "[...]". | |
617 | ||
618 | If WIDTH is negative then ensure that the output is at least (- WIDTH) characters, | |
619 | padding as necessary. | |
620 | ||
621 | Returns the number of emitted characters. */ | |
622 | ||
623 | static unsigned int | |
624 | print_symbol (signed int width, const char * symbol) | |
625 | { | |
626 | bool extra_padding = false; | |
627 | bool do_dots = false; | |
628 | signed int num_printed = 0; | |
629 | #ifdef HAVE_MBSTATE_T | |
630 | mbstate_t state; | |
631 | #endif | |
632 | unsigned int width_remaining; | |
633 | const void * alloced_symbol = NULL; | |
634 | ||
635 | if (width < 0) | |
636 | { | |
637 | /* Keep the width positive. This helps the code below. */ | |
638 | width = - width; | |
639 | extra_padding = true; | |
640 | } | |
641 | else if (width == 0) | |
642 | return 0; | |
643 | ||
644 | if (do_wide) | |
645 | /* Set the remaining width to a very large value. | |
646 | This simplifies the code below. */ | |
647 | width_remaining = INT_MAX; | |
648 | else | |
649 | { | |
650 | width_remaining = width; | |
651 | if (! do_not_show_symbol_truncation | |
652 | && (int) strlen (symbol) > width) | |
653 | { | |
654 | width_remaining -= 5; | |
655 | if ((int) width_remaining < 0) | |
656 | width_remaining = 0; | |
657 | do_dots = true; | |
658 | } | |
659 | } | |
660 | ||
661 | #ifdef HAVE_MBSTATE_T | |
662 | /* Initialise the multibyte conversion state. */ | |
663 | memset (& state, 0, sizeof (state)); | |
664 | #endif | |
665 | ||
666 | if (do_demangle && *symbol) | |
667 | { | |
668 | const char * res = cplus_demangle (symbol, demangle_flags); | |
669 | ||
670 | if (res != NULL) | |
671 | alloced_symbol = symbol = res; | |
672 | } | |
673 | ||
674 | while (width_remaining) | |
675 | { | |
676 | size_t n; | |
677 | const char c = *symbol++; | |
678 | ||
679 | if (c == 0) | |
680 | break; | |
681 | ||
682 | if (ISPRINT (c)) | |
683 | { | |
684 | putchar (c); | |
685 | width_remaining --; | |
686 | num_printed ++; | |
687 | } | |
688 | else if (ISCNTRL (c)) | |
689 | { | |
690 | /* Do not print control characters directly as they can affect terminal | |
691 | settings. Such characters usually appear in the names generated | |
692 | by the assembler for local labels. */ | |
693 | ||
694 | if (width_remaining < 2) | |
695 | break; | |
696 | ||
697 | printf ("^%c", c + 0x40); | |
698 | width_remaining -= 2; | |
699 | num_printed += 2; | |
700 | } | |
701 | else if (c == 0x7f) | |
702 | { | |
703 | if (width_remaining < 5) | |
704 | break; | |
705 | printf ("<DEL>"); | |
706 | width_remaining -= 5; | |
707 | num_printed += 5; | |
708 | } | |
709 | else if (unicode_display != unicode_locale | |
710 | && unicode_display != unicode_default) | |
711 | { | |
712 | /* Display unicode characters as something else. */ | |
713 | unsigned char bytes[4]; | |
714 | bool is_utf8; | |
715 | unsigned int nbytes; | |
716 | ||
717 | bytes[0] = c; | |
718 | ||
719 | if (bytes[0] < 0xc0) | |
720 | { | |
721 | nbytes = 1; | |
722 | is_utf8 = false; | |
723 | } | |
724 | else | |
725 | { | |
726 | bytes[1] = *symbol++; | |
727 | ||
728 | if ((bytes[1] & 0xc0) != 0x80) | |
729 | { | |
730 | is_utf8 = false; | |
731 | /* Do not consume this character. It may only | |
732 | be the first byte in the sequence that was | |
733 | corrupt. */ | |
734 | --symbol; | |
735 | nbytes = 1; | |
736 | } | |
737 | else if ((bytes[0] & 0x20) == 0) | |
738 | { | |
739 | is_utf8 = true; | |
740 | nbytes = 2; | |
741 | } | |
742 | else | |
743 | { | |
744 | bytes[2] = *symbol++; | |
745 | ||
746 | if ((bytes[2] & 0xc0) != 0x80) | |
747 | { | |
748 | is_utf8 = false; | |
749 | symbol -= 2; | |
750 | nbytes = 1; | |
751 | } | |
752 | else if ((bytes[0] & 0x10) == 0) | |
753 | { | |
754 | is_utf8 = true; | |
755 | nbytes = 3; | |
756 | } | |
757 | else | |
758 | { | |
759 | bytes[3] = *symbol++; | |
760 | ||
761 | nbytes = 4; | |
762 | ||
763 | if ((bytes[3] & 0xc0) != 0x80) | |
764 | { | |
765 | is_utf8 = false; | |
766 | symbol -= 3; | |
767 | nbytes = 1; | |
768 | } | |
769 | else | |
770 | is_utf8 = true; | |
771 | } | |
772 | } | |
773 | } | |
774 | ||
775 | if (unicode_display == unicode_invalid) | |
776 | is_utf8 = false; | |
777 | ||
778 | if (unicode_display == unicode_hex || ! is_utf8) | |
779 | { | |
780 | unsigned int i; | |
781 | ||
782 | if (width_remaining < (nbytes * 2) + 2) | |
783 | break; | |
784 | ||
785 | putchar (is_utf8 ? '<' : '{'); | |
786 | printf ("0x"); | |
787 | for (i = 0; i < nbytes; i++) | |
788 | printf ("%02x", bytes[i]); | |
789 | putchar (is_utf8 ? '>' : '}'); | |
790 | } | |
791 | else | |
792 | { | |
793 | if (unicode_display == unicode_highlight && isatty (1)) | |
794 | printf ("\x1B[31;47m"); /* Red. */ | |
795 | ||
796 | switch (nbytes) | |
797 | { | |
798 | case 2: | |
799 | if (width_remaining < 6) | |
800 | break; | |
801 | printf ("\\u%02x%02x", | |
802 | (bytes[0] & 0x1c) >> 2, | |
803 | ((bytes[0] & 0x03) << 6) | (bytes[1] & 0x3f)); | |
804 | break; | |
805 | case 3: | |
806 | if (width_remaining < 6) | |
807 | break; | |
808 | printf ("\\u%02x%02x", | |
809 | ((bytes[0] & 0x0f) << 4) | ((bytes[1] & 0x3c) >> 2), | |
810 | ((bytes[1] & 0x03) << 6) | (bytes[2] & 0x3f)); | |
811 | break; | |
812 | case 4: | |
813 | if (width_remaining < 8) | |
814 | break; | |
815 | printf ("\\u%02x%02x%02x", | |
816 | ((bytes[0] & 0x07) << 6) | ((bytes[1] & 0x3c) >> 2), | |
817 | ((bytes[1] & 0x03) << 6) | ((bytes[2] & 0x3c) >> 2), | |
818 | ((bytes[2] & 0x03) << 6) | (bytes[3] & 0x3f)); | |
819 | ||
820 | break; | |
821 | default: | |
822 | /* URG. */ | |
823 | break; | |
824 | } | |
825 | ||
826 | if (unicode_display == unicode_highlight && isatty (1)) | |
827 | printf ("\033[0m"); /* Default colour. */ | |
828 | } | |
829 | ||
830 | if (bytes[nbytes - 1] == 0) | |
831 | break; | |
832 | } | |
833 | else | |
834 | { | |
835 | #ifdef HAVE_MBSTATE_T | |
836 | wchar_t w; | |
837 | #endif | |
838 | /* Let printf do the hard work of displaying multibyte characters. */ | |
839 | printf ("%.1s", symbol - 1); | |
840 | width_remaining --; | |
841 | num_printed ++; | |
842 | ||
843 | #ifdef HAVE_MBSTATE_T | |
844 | /* Try to find out how many bytes made up the character that was | |
845 | just printed. Advance the symbol pointer past the bytes that | |
846 | were displayed. */ | |
847 | n = mbrtowc (& w, symbol - 1, MB_CUR_MAX, & state); | |
848 | #else | |
849 | n = 1; | |
850 | #endif | |
851 | if (n != (size_t) -1 && n != (size_t) -2 && n > 0) | |
852 | symbol += (n - 1); | |
853 | } | |
854 | } | |
855 | ||
856 | if (do_dots) | |
857 | num_printed += printf ("[...]"); | |
858 | ||
859 | if (extra_padding && num_printed < width) | |
860 | { | |
861 | /* Fill in the remaining spaces. */ | |
862 | printf ("%-*s", width - num_printed, " "); | |
863 | num_printed = width; | |
864 | } | |
865 | ||
866 | free ((void *) alloced_symbol); | |
867 | return num_printed; | |
868 | } | |
869 | ||
870 | /* Returns a pointer to a static buffer containing a printable version of | |
871 | the given section's name. Like print_symbol, except that it does not try | |
872 | to print multibyte characters, it just interprets them as hex values. */ | |
873 | ||
874 | static const char * | |
875 | printable_section_name (Filedata * filedata, const Elf_Internal_Shdr * sec) | |
876 | { | |
877 | #define MAX_PRINT_SEC_NAME_LEN 256 | |
878 | static char sec_name_buf [MAX_PRINT_SEC_NAME_LEN + 1]; | |
879 | const char * name = section_name_print (filedata, sec); | |
880 | char * buf = sec_name_buf; | |
881 | char c; | |
882 | unsigned int remaining = MAX_PRINT_SEC_NAME_LEN; | |
883 | ||
884 | while ((c = * name ++) != 0) | |
885 | { | |
886 | if (ISCNTRL (c)) | |
887 | { | |
888 | if (remaining < 2) | |
889 | break; | |
890 | ||
891 | * buf ++ = '^'; | |
892 | * buf ++ = c + 0x40; | |
893 | remaining -= 2; | |
894 | } | |
895 | else if (ISPRINT (c)) | |
896 | { | |
897 | * buf ++ = c; | |
898 | remaining -= 1; | |
899 | } | |
900 | else | |
901 | { | |
902 | static char hex[17] = "0123456789ABCDEF"; | |
903 | ||
904 | if (remaining < 4) | |
905 | break; | |
906 | * buf ++ = '<'; | |
907 | * buf ++ = hex[(c & 0xf0) >> 4]; | |
908 | * buf ++ = hex[c & 0x0f]; | |
909 | * buf ++ = '>'; | |
910 | remaining -= 4; | |
911 | } | |
912 | ||
913 | if (remaining == 0) | |
914 | break; | |
915 | } | |
916 | ||
917 | * buf = 0; | |
918 | return sec_name_buf; | |
919 | } | |
920 | ||
921 | static const char * | |
922 | printable_section_name_from_index (Filedata *filedata, size_t ndx) | |
923 | { | |
924 | if (ndx >= filedata->file_header.e_shnum) | |
925 | return _("<corrupt>"); | |
926 | ||
927 | return printable_section_name (filedata, filedata->section_headers + ndx); | |
928 | } | |
929 | ||
930 | /* Return a pointer to section NAME, or NULL if no such section exists. */ | |
931 | ||
932 | static Elf_Internal_Shdr * | |
933 | find_section (Filedata * filedata, const char * name) | |
934 | { | |
935 | unsigned int i; | |
936 | ||
937 | if (filedata->section_headers == NULL) | |
938 | return NULL; | |
939 | ||
940 | for (i = 0; i < filedata->file_header.e_shnum; i++) | |
941 | if (section_name_valid (filedata, filedata->section_headers + i) | |
942 | && streq (section_name (filedata, filedata->section_headers + i), | |
943 | name)) | |
944 | return filedata->section_headers + i; | |
945 | ||
946 | return NULL; | |
947 | } | |
948 | ||
949 | /* Return a pointer to a section containing ADDR, or NULL if no such | |
950 | section exists. */ | |
951 | ||
952 | static Elf_Internal_Shdr * | |
953 | find_section_by_address (Filedata * filedata, uint64_t addr) | |
954 | { | |
955 | unsigned int i; | |
956 | ||
957 | if (filedata->section_headers == NULL) | |
958 | return NULL; | |
959 | ||
960 | for (i = 0; i < filedata->file_header.e_shnum; i++) | |
961 | { | |
962 | Elf_Internal_Shdr *sec = filedata->section_headers + i; | |
963 | ||
964 | if (addr >= sec->sh_addr && addr < sec->sh_addr + sec->sh_size) | |
965 | return sec; | |
966 | } | |
967 | ||
968 | return NULL; | |
969 | } | |
970 | ||
971 | static Elf_Internal_Shdr * | |
972 | find_section_by_type (Filedata * filedata, unsigned int type) | |
973 | { | |
974 | unsigned int i; | |
975 | ||
976 | if (filedata->section_headers == NULL) | |
977 | return NULL; | |
978 | ||
979 | for (i = 0; i < filedata->file_header.e_shnum; i++) | |
980 | { | |
981 | Elf_Internal_Shdr *sec = filedata->section_headers + i; | |
982 | ||
983 | if (sec->sh_type == type) | |
984 | return sec; | |
985 | } | |
986 | ||
987 | return NULL; | |
988 | } | |
989 | ||
990 | /* Return a pointer to section NAME, or NULL if no such section exists, | |
991 | restricted to the list of sections given in SET. */ | |
992 | ||
993 | static Elf_Internal_Shdr * | |
994 | find_section_in_set (Filedata * filedata, const char * name, unsigned int * set) | |
995 | { | |
996 | unsigned int i; | |
997 | ||
998 | if (filedata->section_headers == NULL) | |
999 | return NULL; | |
1000 | ||
1001 | if (set != NULL) | |
1002 | { | |
1003 | while ((i = *set++) > 0) | |
1004 | { | |
1005 | /* See PR 21156 for a reproducer. */ | |
1006 | if (i >= filedata->file_header.e_shnum) | |
1007 | continue; /* FIXME: Should we issue an error message ? */ | |
1008 | ||
1009 | if (section_name_valid (filedata, filedata->section_headers + i) | |
1010 | && streq (section_name (filedata, filedata->section_headers + i), | |
1011 | name)) | |
1012 | return filedata->section_headers + i; | |
1013 | } | |
1014 | } | |
1015 | ||
1016 | return find_section (filedata, name); | |
1017 | } | |
1018 | ||
1019 | /* Return TRUE if the current file is for IA-64 machine and OpenVMS ABI. | |
1020 | This OS has so many departures from the ELF standard that we test it at | |
1021 | many places. */ | |
1022 | ||
1023 | static inline bool | |
1024 | is_ia64_vms (Filedata * filedata) | |
1025 | { | |
1026 | return filedata->file_header.e_machine == EM_IA_64 | |
1027 | && filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_OPENVMS; | |
1028 | } | |
1029 | ||
1030 | /* Guess the relocation size commonly used by the specific machines. */ | |
1031 | ||
1032 | static bool | |
1033 | guess_is_rela (unsigned int e_machine) | |
1034 | { | |
1035 | switch (e_machine) | |
1036 | { | |
1037 | /* Targets that use REL relocations. */ | |
1038 | case EM_386: | |
1039 | case EM_IAMCU: | |
1040 | case EM_960: | |
1041 | case EM_ARM: | |
1042 | case EM_D10V: | |
1043 | case EM_CYGNUS_D10V: | |
1044 | case EM_DLX: | |
1045 | case EM_MIPS: | |
1046 | case EM_MIPS_RS3_LE: | |
1047 | case EM_CYGNUS_M32R: | |
1048 | case EM_SCORE: | |
1049 | case EM_XGATE: | |
1050 | case EM_NFP: | |
1051 | case EM_BPF: | |
1052 | return false; | |
1053 | ||
1054 | /* Targets that use RELA relocations. */ | |
1055 | case EM_68K: | |
1056 | case EM_860: | |
1057 | case EM_AARCH64: | |
1058 | case EM_ADAPTEVA_EPIPHANY: | |
1059 | case EM_ALPHA: | |
1060 | case EM_ALTERA_NIOS2: | |
1061 | case EM_ARC: | |
1062 | case EM_ARC_COMPACT: | |
1063 | case EM_ARC_COMPACT2: | |
1064 | case EM_AVR: | |
1065 | case EM_AVR_OLD: | |
1066 | case EM_BLACKFIN: | |
1067 | case EM_CR16: | |
1068 | case EM_CRIS: | |
1069 | case EM_CRX: | |
1070 | case EM_CSKY: | |
1071 | case EM_D30V: | |
1072 | case EM_CYGNUS_D30V: | |
1073 | case EM_FR30: | |
1074 | case EM_FT32: | |
1075 | case EM_CYGNUS_FR30: | |
1076 | case EM_CYGNUS_FRV: | |
1077 | case EM_H8S: | |
1078 | case EM_H8_300: | |
1079 | case EM_H8_300H: | |
1080 | case EM_IA_64: | |
1081 | case EM_IP2K: | |
1082 | case EM_IP2K_OLD: | |
1083 | case EM_IQ2000: | |
1084 | case EM_LATTICEMICO32: | |
1085 | case EM_M32C_OLD: | |
1086 | case EM_M32C: | |
1087 | case EM_M32R: | |
1088 | case EM_MCORE: | |
1089 | case EM_CYGNUS_MEP: | |
1090 | case EM_METAG: | |
1091 | case EM_MMIX: | |
1092 | case EM_MN10200: | |
1093 | case EM_CYGNUS_MN10200: | |
1094 | case EM_MN10300: | |
1095 | case EM_CYGNUS_MN10300: | |
1096 | case EM_MOXIE: | |
1097 | case EM_MSP430: | |
1098 | case EM_MSP430_OLD: | |
1099 | case EM_MT: | |
1100 | case EM_NDS32: | |
1101 | case EM_NIOS32: | |
1102 | case EM_OR1K: | |
1103 | case EM_PPC64: | |
1104 | case EM_PPC: | |
1105 | case EM_TI_PRU: | |
1106 | case EM_RISCV: | |
1107 | case EM_RL78: | |
1108 | case EM_RX: | |
1109 | case EM_S390: | |
1110 | case EM_S390_OLD: | |
1111 | case EM_SH: | |
1112 | case EM_SPARC: | |
1113 | case EM_SPARC32PLUS: | |
1114 | case EM_SPARCV9: | |
1115 | case EM_SPU: | |
1116 | case EM_TI_C6000: | |
1117 | case EM_TILEGX: | |
1118 | case EM_TILEPRO: | |
1119 | case EM_V800: | |
1120 | case EM_V850: | |
1121 | case EM_CYGNUS_V850: | |
1122 | case EM_VAX: | |
1123 | case EM_VISIUM: | |
1124 | case EM_X86_64: | |
1125 | case EM_L1OM: | |
1126 | case EM_K1OM: | |
1127 | case EM_XSTORMY16: | |
1128 | case EM_XTENSA: | |
1129 | case EM_XTENSA_OLD: | |
1130 | case EM_MICROBLAZE: | |
1131 | case EM_MICROBLAZE_OLD: | |
1132 | case EM_WEBASSEMBLY: | |
1133 | return true; | |
1134 | ||
1135 | case EM_68HC05: | |
1136 | case EM_68HC08: | |
1137 | case EM_68HC11: | |
1138 | case EM_68HC16: | |
1139 | case EM_FX66: | |
1140 | case EM_ME16: | |
1141 | case EM_MMA: | |
1142 | case EM_NCPU: | |
1143 | case EM_NDR1: | |
1144 | case EM_PCP: | |
1145 | case EM_ST100: | |
1146 | case EM_ST19: | |
1147 | case EM_ST7: | |
1148 | case EM_ST9PLUS: | |
1149 | case EM_STARCORE: | |
1150 | case EM_SVX: | |
1151 | case EM_TINYJ: | |
1152 | default: | |
1153 | warn (_("Don't know about relocations on this machine architecture\n")); | |
1154 | return false; | |
1155 | } | |
1156 | } | |
1157 | ||
1158 | /* Load RELA type relocations from FILEDATA at REL_OFFSET extending for REL_SIZE bytes. | |
1159 | Returns TRUE upon success, FALSE otherwise. If successful then a | |
1160 | pointer to a malloc'ed buffer containing the relocs is placed in *RELASP, | |
1161 | and the number of relocs loaded is placed in *NRELASP. It is the caller's | |
1162 | responsibility to free the allocated buffer. */ | |
1163 | ||
1164 | static bool | |
1165 | slurp_rela_relocs (Filedata *filedata, | |
1166 | uint64_t rel_offset, | |
1167 | uint64_t rel_size, | |
1168 | Elf_Internal_Rela **relasp, | |
1169 | uint64_t *nrelasp) | |
1170 | { | |
1171 | Elf_Internal_Rela * relas; | |
1172 | uint64_t nrelas; | |
1173 | unsigned int i; | |
1174 | ||
1175 | if (is_32bit_elf) | |
1176 | { | |
1177 | Elf32_External_Rela * erelas; | |
1178 | ||
1179 | erelas = (Elf32_External_Rela *) get_data (NULL, filedata, rel_offset, 1, | |
1180 | rel_size, _("32-bit relocation data")); | |
1181 | if (!erelas) | |
1182 | return false; | |
1183 | ||
1184 | nrelas = rel_size / sizeof (Elf32_External_Rela); | |
1185 | ||
1186 | relas = (Elf_Internal_Rela *) cmalloc (nrelas, | |
1187 | sizeof (Elf_Internal_Rela)); | |
1188 | ||
1189 | if (relas == NULL) | |
1190 | { | |
1191 | free (erelas); | |
1192 | error (_("out of memory parsing relocs\n")); | |
1193 | return false; | |
1194 | } | |
1195 | ||
1196 | for (i = 0; i < nrelas; i++) | |
1197 | { | |
1198 | relas[i].r_offset = BYTE_GET (erelas[i].r_offset); | |
1199 | relas[i].r_info = BYTE_GET (erelas[i].r_info); | |
1200 | relas[i].r_addend = BYTE_GET_SIGNED (erelas[i].r_addend); | |
1201 | } | |
1202 | ||
1203 | free (erelas); | |
1204 | } | |
1205 | else | |
1206 | { | |
1207 | Elf64_External_Rela * erelas; | |
1208 | ||
1209 | erelas = (Elf64_External_Rela *) get_data (NULL, filedata, rel_offset, 1, | |
1210 | rel_size, _("64-bit relocation data")); | |
1211 | if (!erelas) | |
1212 | return false; | |
1213 | ||
1214 | nrelas = rel_size / sizeof (Elf64_External_Rela); | |
1215 | ||
1216 | relas = (Elf_Internal_Rela *) cmalloc (nrelas, | |
1217 | sizeof (Elf_Internal_Rela)); | |
1218 | ||
1219 | if (relas == NULL) | |
1220 | { | |
1221 | free (erelas); | |
1222 | error (_("out of memory parsing relocs\n")); | |
1223 | return false; | |
1224 | } | |
1225 | ||
1226 | for (i = 0; i < nrelas; i++) | |
1227 | { | |
1228 | relas[i].r_offset = BYTE_GET (erelas[i].r_offset); | |
1229 | relas[i].r_info = BYTE_GET (erelas[i].r_info); | |
1230 | relas[i].r_addend = BYTE_GET_SIGNED (erelas[i].r_addend); | |
1231 | ||
1232 | if (filedata->file_header.e_machine == EM_MIPS | |
1233 | && filedata->file_header.e_ident[EI_DATA] != ELFDATA2MSB) | |
1234 | { | |
1235 | /* In little-endian objects, r_info isn't really a | |
1236 | 64-bit little-endian value: it has a 32-bit | |
1237 | little-endian symbol index followed by four | |
1238 | individual byte fields. Reorder INFO | |
1239 | accordingly. */ | |
1240 | uint64_t inf = relas[i].r_info; | |
1241 | inf = (((inf & 0xffffffff) << 32) | |
1242 | | ((inf >> 56) & 0xff) | |
1243 | | ((inf >> 40) & 0xff00) | |
1244 | | ((inf >> 24) & 0xff0000) | |
1245 | | ((inf >> 8) & 0xff000000)); | |
1246 | relas[i].r_info = inf; | |
1247 | } | |
1248 | } | |
1249 | ||
1250 | free (erelas); | |
1251 | } | |
1252 | ||
1253 | *relasp = relas; | |
1254 | *nrelasp = nrelas; | |
1255 | return true; | |
1256 | } | |
1257 | ||
1258 | /* Load REL type relocations from FILEDATA at REL_OFFSET extending for REL_SIZE bytes. | |
1259 | Returns TRUE upon success, FALSE otherwise. If successful then a | |
1260 | pointer to a malloc'ed buffer containing the relocs is placed in *RELSP, | |
1261 | and the number of relocs loaded is placed in *NRELSP. It is the caller's | |
1262 | responsibility to free the allocated buffer. */ | |
1263 | ||
1264 | static bool | |
1265 | slurp_rel_relocs (Filedata *filedata, | |
1266 | uint64_t rel_offset, | |
1267 | uint64_t rel_size, | |
1268 | Elf_Internal_Rela **relsp, | |
1269 | uint64_t *nrelsp) | |
1270 | { | |
1271 | Elf_Internal_Rela * rels; | |
1272 | uint64_t nrels; | |
1273 | unsigned int i; | |
1274 | ||
1275 | if (is_32bit_elf) | |
1276 | { | |
1277 | Elf32_External_Rel * erels; | |
1278 | ||
1279 | erels = (Elf32_External_Rel *) get_data (NULL, filedata, rel_offset, 1, | |
1280 | rel_size, _("32-bit relocation data")); | |
1281 | if (!erels) | |
1282 | return false; | |
1283 | ||
1284 | nrels = rel_size / sizeof (Elf32_External_Rel); | |
1285 | ||
1286 | rels = (Elf_Internal_Rela *) cmalloc (nrels, sizeof (Elf_Internal_Rela)); | |
1287 | ||
1288 | if (rels == NULL) | |
1289 | { | |
1290 | free (erels); | |
1291 | error (_("out of memory parsing relocs\n")); | |
1292 | return false; | |
1293 | } | |
1294 | ||
1295 | for (i = 0; i < nrels; i++) | |
1296 | { | |
1297 | rels[i].r_offset = BYTE_GET (erels[i].r_offset); | |
1298 | rels[i].r_info = BYTE_GET (erels[i].r_info); | |
1299 | rels[i].r_addend = 0; | |
1300 | } | |
1301 | ||
1302 | free (erels); | |
1303 | } | |
1304 | else | |
1305 | { | |
1306 | Elf64_External_Rel * erels; | |
1307 | ||
1308 | erels = (Elf64_External_Rel *) get_data (NULL, filedata, rel_offset, 1, | |
1309 | rel_size, _("64-bit relocation data")); | |
1310 | if (!erels) | |
1311 | return false; | |
1312 | ||
1313 | nrels = rel_size / sizeof (Elf64_External_Rel); | |
1314 | ||
1315 | rels = (Elf_Internal_Rela *) cmalloc (nrels, sizeof (Elf_Internal_Rela)); | |
1316 | ||
1317 | if (rels == NULL) | |
1318 | { | |
1319 | free (erels); | |
1320 | error (_("out of memory parsing relocs\n")); | |
1321 | return false; | |
1322 | } | |
1323 | ||
1324 | for (i = 0; i < nrels; i++) | |
1325 | { | |
1326 | rels[i].r_offset = BYTE_GET (erels[i].r_offset); | |
1327 | rels[i].r_info = BYTE_GET (erels[i].r_info); | |
1328 | rels[i].r_addend = 0; | |
1329 | ||
1330 | if (filedata->file_header.e_machine == EM_MIPS | |
1331 | && filedata->file_header.e_ident[EI_DATA] != ELFDATA2MSB) | |
1332 | { | |
1333 | /* In little-endian objects, r_info isn't really a | |
1334 | 64-bit little-endian value: it has a 32-bit | |
1335 | little-endian symbol index followed by four | |
1336 | individual byte fields. Reorder INFO | |
1337 | accordingly. */ | |
1338 | uint64_t inf = rels[i].r_info; | |
1339 | inf = (((inf & 0xffffffff) << 32) | |
1340 | | ((inf >> 56) & 0xff) | |
1341 | | ((inf >> 40) & 0xff00) | |
1342 | | ((inf >> 24) & 0xff0000) | |
1343 | | ((inf >> 8) & 0xff000000)); | |
1344 | rels[i].r_info = inf; | |
1345 | } | |
1346 | } | |
1347 | ||
1348 | free (erels); | |
1349 | } | |
1350 | ||
1351 | *relsp = rels; | |
1352 | *nrelsp = nrels; | |
1353 | return true; | |
1354 | } | |
1355 | ||
1356 | static bool | |
1357 | slurp_relr_relocs (Filedata *filedata, | |
1358 | uint64_t relr_offset, | |
1359 | uint64_t relr_size, | |
1360 | uint64_t **relrsp, | |
1361 | uint64_t *nrelrsp) | |
1362 | { | |
1363 | void *relrs; | |
1364 | size_t size = 0, nentries, i; | |
1365 | uint64_t base = 0, addr, entry; | |
1366 | ||
1367 | relrs = get_data (NULL, filedata, relr_offset, 1, relr_size, | |
1368 | _("RELR relocation data")); | |
1369 | if (!relrs) | |
1370 | return false; | |
1371 | ||
1372 | if (is_32bit_elf) | |
1373 | nentries = relr_size / sizeof (Elf32_External_Relr); | |
1374 | else | |
1375 | nentries = relr_size / sizeof (Elf64_External_Relr); | |
1376 | for (i = 0; i < nentries; i++) | |
1377 | { | |
1378 | if (is_32bit_elf) | |
1379 | entry = BYTE_GET (((Elf32_External_Relr *)relrs)[i].r_data); | |
1380 | else | |
1381 | entry = BYTE_GET (((Elf64_External_Relr *)relrs)[i].r_data); | |
1382 | if ((entry & 1) == 0) | |
1383 | size++; | |
1384 | else | |
1385 | while ((entry >>= 1) != 0) | |
1386 | if ((entry & 1) == 1) | |
1387 | size++; | |
1388 | } | |
1389 | ||
1390 | *relrsp = malloc (size * sizeof (**relrsp)); | |
1391 | if (*relrsp == NULL) | |
1392 | { | |
1393 | free (relrs); | |
1394 | error (_("out of memory parsing relocs\n")); | |
1395 | return false; | |
1396 | } | |
1397 | ||
1398 | size = 0; | |
1399 | for (i = 0; i < nentries; i++) | |
1400 | { | |
1401 | const uint64_t entry_bytes = is_32bit_elf ? 4 : 8; | |
1402 | ||
1403 | if (is_32bit_elf) | |
1404 | entry = BYTE_GET (((Elf32_External_Relr *)relrs)[i].r_data); | |
1405 | else | |
1406 | entry = BYTE_GET (((Elf64_External_Relr *)relrs)[i].r_data); | |
1407 | if ((entry & 1) == 0) | |
1408 | { | |
1409 | (*relrsp)[size++] = entry; | |
1410 | base = entry + entry_bytes; | |
1411 | } | |
1412 | else | |
1413 | { | |
1414 | for (addr = base; (entry >>= 1) != 0; addr += entry_bytes) | |
1415 | if ((entry & 1) != 0) | |
1416 | (*relrsp)[size++] = addr; | |
1417 | base += entry_bytes * (entry_bytes * CHAR_BIT - 1); | |
1418 | } | |
1419 | } | |
1420 | ||
1421 | *nrelrsp = size; | |
1422 | free (relrs); | |
1423 | return true; | |
1424 | } | |
1425 | ||
1426 | /* Returns the reloc type extracted from the reloc info field. */ | |
1427 | ||
1428 | static unsigned int | |
1429 | get_reloc_type (Filedata * filedata, uint64_t reloc_info) | |
1430 | { | |
1431 | if (is_32bit_elf) | |
1432 | return ELF32_R_TYPE (reloc_info); | |
1433 | ||
1434 | switch (filedata->file_header.e_machine) | |
1435 | { | |
1436 | case EM_MIPS: | |
1437 | /* Note: We assume that reloc_info has already been adjusted for us. */ | |
1438 | return ELF64_MIPS_R_TYPE (reloc_info); | |
1439 | ||
1440 | case EM_SPARCV9: | |
1441 | return ELF64_R_TYPE_ID (reloc_info); | |
1442 | ||
1443 | default: | |
1444 | return ELF64_R_TYPE (reloc_info); | |
1445 | } | |
1446 | } | |
1447 | ||
1448 | /* Return the symbol index extracted from the reloc info field. */ | |
1449 | ||
1450 | static uint64_t | |
1451 | get_reloc_symindex (uint64_t reloc_info) | |
1452 | { | |
1453 | return is_32bit_elf ? ELF32_R_SYM (reloc_info) : ELF64_R_SYM (reloc_info); | |
1454 | } | |
1455 | ||
1456 | static inline bool | |
1457 | uses_msp430x_relocs (Filedata * filedata) | |
1458 | { | |
1459 | return | |
1460 | filedata->file_header.e_machine == EM_MSP430 /* Paranoia. */ | |
1461 | /* GCC uses osabi == ELFOSBI_STANDALONE. */ | |
1462 | && (((filedata->file_header.e_flags & EF_MSP430_MACH) == E_MSP430_MACH_MSP430X) | |
1463 | /* TI compiler uses ELFOSABI_NONE. */ | |
1464 | || (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_NONE)); | |
1465 | } | |
1466 | ||
1467 | /* Display the contents of the relocation data found at the specified | |
1468 | offset. */ | |
1469 | ||
1470 | static bool | |
1471 | dump_relocations (Filedata *filedata, | |
1472 | uint64_t rel_offset, | |
1473 | uint64_t rel_size, | |
1474 | Elf_Internal_Sym *symtab, | |
1475 | uint64_t nsyms, | |
1476 | char *strtab, | |
1477 | uint64_t strtablen, | |
1478 | relocation_type rel_type, | |
1479 | bool is_dynsym) | |
1480 | { | |
1481 | size_t i; | |
1482 | Elf_Internal_Rela * rels; | |
1483 | bool res = true; | |
1484 | ||
1485 | if (rel_type == reltype_unknown) | |
1486 | rel_type = guess_is_rela (filedata->file_header.e_machine) ? reltype_rela : reltype_rel; | |
1487 | ||
1488 | if (rel_type == reltype_rela) | |
1489 | { | |
1490 | if (!slurp_rela_relocs (filedata, rel_offset, rel_size, &rels, &rel_size)) | |
1491 | return false; | |
1492 | } | |
1493 | else if (rel_type == reltype_rel) | |
1494 | { | |
1495 | if (!slurp_rel_relocs (filedata, rel_offset, rel_size, &rels, &rel_size)) | |
1496 | return false; | |
1497 | } | |
1498 | else if (rel_type == reltype_relr) | |
1499 | { | |
1500 | uint64_t * relrs; | |
1501 | const char *format | |
1502 | = is_32bit_elf ? "%08" PRIx64 "\n" : "%016" PRIx64 "\n"; | |
1503 | ||
1504 | if (!slurp_relr_relocs (filedata, rel_offset, rel_size, &relrs, | |
1505 | &rel_size)) | |
1506 | return false; | |
1507 | ||
1508 | printf (ngettext (" %" PRIu64 " offset\n", | |
1509 | " %" PRIu64 " offsets\n", rel_size), | |
1510 | rel_size); | |
1511 | for (i = 0; i < rel_size; i++) | |
1512 | printf (format, relrs[i]); | |
1513 | free (relrs); | |
1514 | return true; | |
1515 | } | |
1516 | ||
1517 | if (is_32bit_elf) | |
1518 | { | |
1519 | if (rel_type == reltype_rela) | |
1520 | { | |
1521 | if (do_wide) | |
1522 | printf (_(" Offset Info Type Sym. Value Symbol's Name + Addend\n")); | |
1523 | else | |
1524 | printf (_(" Offset Info Type Sym.Value Sym. Name + Addend\n")); | |
1525 | } | |
1526 | else | |
1527 | { | |
1528 | if (do_wide) | |
1529 | printf (_(" Offset Info Type Sym. Value Symbol's Name\n")); | |
1530 | else | |
1531 | printf (_(" Offset Info Type Sym.Value Sym. Name\n")); | |
1532 | } | |
1533 | } | |
1534 | else | |
1535 | { | |
1536 | if (rel_type == reltype_rela) | |
1537 | { | |
1538 | if (do_wide) | |
1539 | printf (_(" Offset Info Type Symbol's Value Symbol's Name + Addend\n")); | |
1540 | else | |
1541 | printf (_(" Offset Info Type Sym. Value Sym. Name + Addend\n")); | |
1542 | } | |
1543 | else | |
1544 | { | |
1545 | if (do_wide) | |
1546 | printf (_(" Offset Info Type Symbol's Value Symbol's Name\n")); | |
1547 | else | |
1548 | printf (_(" Offset Info Type Sym. Value Sym. Name\n")); | |
1549 | } | |
1550 | } | |
1551 | ||
1552 | for (i = 0; i < rel_size; i++) | |
1553 | { | |
1554 | const char * rtype; | |
1555 | uint64_t offset; | |
1556 | uint64_t inf; | |
1557 | uint64_t symtab_index; | |
1558 | uint64_t type; | |
1559 | ||
1560 | offset = rels[i].r_offset; | |
1561 | inf = rels[i].r_info; | |
1562 | ||
1563 | type = get_reloc_type (filedata, inf); | |
1564 | symtab_index = get_reloc_symindex (inf); | |
1565 | ||
1566 | if (is_32bit_elf) | |
1567 | { | |
1568 | printf ("%8.8lx %8.8lx ", | |
1569 | (unsigned long) offset & 0xffffffff, | |
1570 | (unsigned long) inf & 0xffffffff); | |
1571 | } | |
1572 | else | |
1573 | { | |
1574 | printf (do_wide | |
1575 | ? "%16.16" PRIx64 " %16.16" PRIx64 " " | |
1576 | : "%12.12" PRIx64 " %12.12" PRIx64 " ", | |
1577 | offset, inf); | |
1578 | } | |
1579 | ||
1580 | switch (filedata->file_header.e_machine) | |
1581 | { | |
1582 | default: | |
1583 | rtype = NULL; | |
1584 | break; | |
1585 | ||
1586 | case EM_AARCH64: | |
1587 | rtype = elf_aarch64_reloc_type (type); | |
1588 | break; | |
1589 | ||
1590 | case EM_M32R: | |
1591 | case EM_CYGNUS_M32R: | |
1592 | rtype = elf_m32r_reloc_type (type); | |
1593 | break; | |
1594 | ||
1595 | case EM_386: | |
1596 | case EM_IAMCU: | |
1597 | rtype = elf_i386_reloc_type (type); | |
1598 | break; | |
1599 | ||
1600 | case EM_68HC11: | |
1601 | case EM_68HC12: | |
1602 | rtype = elf_m68hc11_reloc_type (type); | |
1603 | break; | |
1604 | ||
1605 | case EM_S12Z: | |
1606 | rtype = elf_s12z_reloc_type (type); | |
1607 | break; | |
1608 | ||
1609 | case EM_68K: | |
1610 | rtype = elf_m68k_reloc_type (type); | |
1611 | break; | |
1612 | ||
1613 | case EM_960: | |
1614 | rtype = elf_i960_reloc_type (type); | |
1615 | break; | |
1616 | ||
1617 | case EM_AVR: | |
1618 | case EM_AVR_OLD: | |
1619 | rtype = elf_avr_reloc_type (type); | |
1620 | break; | |
1621 | ||
1622 | case EM_OLD_SPARCV9: | |
1623 | case EM_SPARC32PLUS: | |
1624 | case EM_SPARCV9: | |
1625 | case EM_SPARC: | |
1626 | rtype = elf_sparc_reloc_type (type); | |
1627 | break; | |
1628 | ||
1629 | case EM_SPU: | |
1630 | rtype = elf_spu_reloc_type (type); | |
1631 | break; | |
1632 | ||
1633 | case EM_V800: | |
1634 | rtype = v800_reloc_type (type); | |
1635 | break; | |
1636 | case EM_V850: | |
1637 | case EM_CYGNUS_V850: | |
1638 | rtype = v850_reloc_type (type); | |
1639 | break; | |
1640 | ||
1641 | case EM_D10V: | |
1642 | case EM_CYGNUS_D10V: | |
1643 | rtype = elf_d10v_reloc_type (type); | |
1644 | break; | |
1645 | ||
1646 | case EM_D30V: | |
1647 | case EM_CYGNUS_D30V: | |
1648 | rtype = elf_d30v_reloc_type (type); | |
1649 | break; | |
1650 | ||
1651 | case EM_DLX: | |
1652 | rtype = elf_dlx_reloc_type (type); | |
1653 | break; | |
1654 | ||
1655 | case EM_SH: | |
1656 | rtype = elf_sh_reloc_type (type); | |
1657 | break; | |
1658 | ||
1659 | case EM_MN10300: | |
1660 | case EM_CYGNUS_MN10300: | |
1661 | rtype = elf_mn10300_reloc_type (type); | |
1662 | break; | |
1663 | ||
1664 | case EM_MN10200: | |
1665 | case EM_CYGNUS_MN10200: | |
1666 | rtype = elf_mn10200_reloc_type (type); | |
1667 | break; | |
1668 | ||
1669 | case EM_FR30: | |
1670 | case EM_CYGNUS_FR30: | |
1671 | rtype = elf_fr30_reloc_type (type); | |
1672 | break; | |
1673 | ||
1674 | case EM_CYGNUS_FRV: | |
1675 | rtype = elf_frv_reloc_type (type); | |
1676 | break; | |
1677 | ||
1678 | case EM_CSKY: | |
1679 | rtype = elf_csky_reloc_type (type); | |
1680 | break; | |
1681 | ||
1682 | case EM_FT32: | |
1683 | rtype = elf_ft32_reloc_type (type); | |
1684 | break; | |
1685 | ||
1686 | case EM_MCORE: | |
1687 | rtype = elf_mcore_reloc_type (type); | |
1688 | break; | |
1689 | ||
1690 | case EM_MMIX: | |
1691 | rtype = elf_mmix_reloc_type (type); | |
1692 | break; | |
1693 | ||
1694 | case EM_MOXIE: | |
1695 | rtype = elf_moxie_reloc_type (type); | |
1696 | break; | |
1697 | ||
1698 | case EM_MSP430: | |
1699 | if (uses_msp430x_relocs (filedata)) | |
1700 | { | |
1701 | rtype = elf_msp430x_reloc_type (type); | |
1702 | break; | |
1703 | } | |
1704 | /* Fall through. */ | |
1705 | case EM_MSP430_OLD: | |
1706 | rtype = elf_msp430_reloc_type (type); | |
1707 | break; | |
1708 | ||
1709 | case EM_NDS32: | |
1710 | rtype = elf_nds32_reloc_type (type); | |
1711 | break; | |
1712 | ||
1713 | case EM_PPC: | |
1714 | rtype = elf_ppc_reloc_type (type); | |
1715 | break; | |
1716 | ||
1717 | case EM_PPC64: | |
1718 | rtype = elf_ppc64_reloc_type (type); | |
1719 | break; | |
1720 | ||
1721 | case EM_MIPS: | |
1722 | case EM_MIPS_RS3_LE: | |
1723 | rtype = elf_mips_reloc_type (type); | |
1724 | break; | |
1725 | ||
1726 | case EM_RISCV: | |
1727 | rtype = elf_riscv_reloc_type (type); | |
1728 | break; | |
1729 | ||
1730 | case EM_ALPHA: | |
1731 | rtype = elf_alpha_reloc_type (type); | |
1732 | break; | |
1733 | ||
1734 | case EM_ARM: | |
1735 | rtype = elf_arm_reloc_type (type); | |
1736 | break; | |
1737 | ||
1738 | case EM_ARC: | |
1739 | case EM_ARC_COMPACT: | |
1740 | case EM_ARC_COMPACT2: | |
1741 | rtype = elf_arc_reloc_type (type); | |
1742 | break; | |
1743 | ||
1744 | case EM_PARISC: | |
1745 | rtype = elf_hppa_reloc_type (type); | |
1746 | break; | |
1747 | ||
1748 | case EM_H8_300: | |
1749 | case EM_H8_300H: | |
1750 | case EM_H8S: | |
1751 | rtype = elf_h8_reloc_type (type); | |
1752 | break; | |
1753 | ||
1754 | case EM_OR1K: | |
1755 | rtype = elf_or1k_reloc_type (type); | |
1756 | break; | |
1757 | ||
1758 | case EM_PJ: | |
1759 | case EM_PJ_OLD: | |
1760 | rtype = elf_pj_reloc_type (type); | |
1761 | break; | |
1762 | case EM_IA_64: | |
1763 | rtype = elf_ia64_reloc_type (type); | |
1764 | break; | |
1765 | ||
1766 | case EM_CRIS: | |
1767 | rtype = elf_cris_reloc_type (type); | |
1768 | break; | |
1769 | ||
1770 | case EM_860: | |
1771 | rtype = elf_i860_reloc_type (type); | |
1772 | break; | |
1773 | ||
1774 | case EM_X86_64: | |
1775 | case EM_L1OM: | |
1776 | case EM_K1OM: | |
1777 | rtype = elf_x86_64_reloc_type (type); | |
1778 | break; | |
1779 | ||
1780 | case EM_S370: | |
1781 | rtype = i370_reloc_type (type); | |
1782 | break; | |
1783 | ||
1784 | case EM_S390_OLD: | |
1785 | case EM_S390: | |
1786 | rtype = elf_s390_reloc_type (type); | |
1787 | break; | |
1788 | ||
1789 | case EM_SCORE: | |
1790 | rtype = elf_score_reloc_type (type); | |
1791 | break; | |
1792 | ||
1793 | case EM_XSTORMY16: | |
1794 | rtype = elf_xstormy16_reloc_type (type); | |
1795 | break; | |
1796 | ||
1797 | case EM_CRX: | |
1798 | rtype = elf_crx_reloc_type (type); | |
1799 | break; | |
1800 | ||
1801 | case EM_VAX: | |
1802 | rtype = elf_vax_reloc_type (type); | |
1803 | break; | |
1804 | ||
1805 | case EM_VISIUM: | |
1806 | rtype = elf_visium_reloc_type (type); | |
1807 | break; | |
1808 | ||
1809 | case EM_BPF: | |
1810 | rtype = elf_bpf_reloc_type (type); | |
1811 | break; | |
1812 | ||
1813 | case EM_ADAPTEVA_EPIPHANY: | |
1814 | rtype = elf_epiphany_reloc_type (type); | |
1815 | break; | |
1816 | ||
1817 | case EM_IP2K: | |
1818 | case EM_IP2K_OLD: | |
1819 | rtype = elf_ip2k_reloc_type (type); | |
1820 | break; | |
1821 | ||
1822 | case EM_IQ2000: | |
1823 | rtype = elf_iq2000_reloc_type (type); | |
1824 | break; | |
1825 | ||
1826 | case EM_XTENSA_OLD: | |
1827 | case EM_XTENSA: | |
1828 | rtype = elf_xtensa_reloc_type (type); | |
1829 | break; | |
1830 | ||
1831 | case EM_LATTICEMICO32: | |
1832 | rtype = elf_lm32_reloc_type (type); | |
1833 | break; | |
1834 | ||
1835 | case EM_M32C_OLD: | |
1836 | case EM_M32C: | |
1837 | rtype = elf_m32c_reloc_type (type); | |
1838 | break; | |
1839 | ||
1840 | case EM_MT: | |
1841 | rtype = elf_mt_reloc_type (type); | |
1842 | break; | |
1843 | ||
1844 | case EM_BLACKFIN: | |
1845 | rtype = elf_bfin_reloc_type (type); | |
1846 | break; | |
1847 | ||
1848 | case EM_CYGNUS_MEP: | |
1849 | rtype = elf_mep_reloc_type (type); | |
1850 | break; | |
1851 | ||
1852 | case EM_CR16: | |
1853 | rtype = elf_cr16_reloc_type (type); | |
1854 | break; | |
1855 | ||
1856 | case EM_MICROBLAZE: | |
1857 | case EM_MICROBLAZE_OLD: | |
1858 | rtype = elf_microblaze_reloc_type (type); | |
1859 | break; | |
1860 | ||
1861 | case EM_RL78: | |
1862 | rtype = elf_rl78_reloc_type (type); | |
1863 | break; | |
1864 | ||
1865 | case EM_RX: | |
1866 | rtype = elf_rx_reloc_type (type); | |
1867 | break; | |
1868 | ||
1869 | case EM_METAG: | |
1870 | rtype = elf_metag_reloc_type (type); | |
1871 | break; | |
1872 | ||
1873 | case EM_TI_C6000: | |
1874 | rtype = elf_tic6x_reloc_type (type); | |
1875 | break; | |
1876 | ||
1877 | case EM_TILEGX: | |
1878 | rtype = elf_tilegx_reloc_type (type); | |
1879 | break; | |
1880 | ||
1881 | case EM_TILEPRO: | |
1882 | rtype = elf_tilepro_reloc_type (type); | |
1883 | break; | |
1884 | ||
1885 | case EM_WEBASSEMBLY: | |
1886 | rtype = elf_wasm32_reloc_type (type); | |
1887 | break; | |
1888 | ||
1889 | case EM_XGATE: | |
1890 | rtype = elf_xgate_reloc_type (type); | |
1891 | break; | |
1892 | ||
1893 | case EM_ALTERA_NIOS2: | |
1894 | rtype = elf_nios2_reloc_type (type); | |
1895 | break; | |
1896 | ||
1897 | case EM_TI_PRU: | |
1898 | rtype = elf_pru_reloc_type (type); | |
1899 | break; | |
1900 | ||
1901 | case EM_NFP: | |
1902 | if (EF_NFP_MACH (filedata->file_header.e_flags) == E_NFP_MACH_3200) | |
1903 | rtype = elf_nfp3200_reloc_type (type); | |
1904 | else | |
1905 | rtype = elf_nfp_reloc_type (type); | |
1906 | break; | |
1907 | ||
1908 | case EM_Z80: | |
1909 | rtype = elf_z80_reloc_type (type); | |
1910 | break; | |
1911 | ||
1912 | case EM_LOONGARCH: | |
1913 | rtype = elf_loongarch_reloc_type (type); | |
1914 | break; | |
1915 | ||
1916 | case EM_AMDGPU: | |
1917 | rtype = elf_amdgpu_reloc_type (type); | |
1918 | break; | |
1919 | } | |
1920 | ||
1921 | if (rtype == NULL) | |
1922 | printf (_("unrecognized: %-7lx"), (unsigned long) type & 0xffffffff); | |
1923 | else | |
1924 | printf (do_wide ? "%-22s" : "%-17.17s", rtype); | |
1925 | ||
1926 | if (filedata->file_header.e_machine == EM_ALPHA | |
1927 | && rtype != NULL | |
1928 | && streq (rtype, "R_ALPHA_LITUSE") | |
1929 | && rel_type == reltype_rela) | |
1930 | { | |
1931 | switch (rels[i].r_addend) | |
1932 | { | |
1933 | case LITUSE_ALPHA_ADDR: rtype = "ADDR"; break; | |
1934 | case LITUSE_ALPHA_BASE: rtype = "BASE"; break; | |
1935 | case LITUSE_ALPHA_BYTOFF: rtype = "BYTOFF"; break; | |
1936 | case LITUSE_ALPHA_JSR: rtype = "JSR"; break; | |
1937 | case LITUSE_ALPHA_TLSGD: rtype = "TLSGD"; break; | |
1938 | case LITUSE_ALPHA_TLSLDM: rtype = "TLSLDM"; break; | |
1939 | case LITUSE_ALPHA_JSRDIRECT: rtype = "JSRDIRECT"; break; | |
1940 | default: rtype = NULL; | |
1941 | } | |
1942 | ||
1943 | if (rtype) | |
1944 | printf (" (%s)", rtype); | |
1945 | else | |
1946 | { | |
1947 | putchar (' '); | |
1948 | printf (_("<unknown addend: %" PRIx64 ">"), | |
1949 | rels[i].r_addend); | |
1950 | res = false; | |
1951 | } | |
1952 | } | |
1953 | else if (symtab_index) | |
1954 | { | |
1955 | if (symtab == NULL || symtab_index >= nsyms) | |
1956 | { | |
1957 | error (_(" bad symbol index: %08lx in reloc\n"), | |
1958 | (unsigned long) symtab_index); | |
1959 | res = false; | |
1960 | } | |
1961 | else | |
1962 | { | |
1963 | Elf_Internal_Sym * psym; | |
1964 | const char * version_string; | |
1965 | enum versioned_symbol_info sym_info; | |
1966 | unsigned short vna_other; | |
1967 | ||
1968 | psym = symtab + symtab_index; | |
1969 | ||
1970 | version_string | |
1971 | = get_symbol_version_string (filedata, is_dynsym, | |
1972 | strtab, strtablen, | |
1973 | symtab_index, | |
1974 | psym, | |
1975 | &sym_info, | |
1976 | &vna_other); | |
1977 | ||
1978 | printf (" "); | |
1979 | ||
1980 | if (ELF_ST_TYPE (psym->st_info) == STT_GNU_IFUNC) | |
1981 | { | |
1982 | const char * name; | |
1983 | unsigned int len; | |
1984 | unsigned int width = is_32bit_elf ? 8 : 14; | |
1985 | ||
1986 | /* Relocations against GNU_IFUNC symbols do not use the value | |
1987 | of the symbol as the address to relocate against. Instead | |
1988 | they invoke the function named by the symbol and use its | |
1989 | result as the address for relocation. | |
1990 | ||
1991 | To indicate this to the user, do not display the value of | |
1992 | the symbol in the "Symbols's Value" field. Instead show | |
1993 | its name followed by () as a hint that the symbol is | |
1994 | invoked. */ | |
1995 | ||
1996 | if (strtab == NULL | |
1997 | || psym->st_name == 0 | |
1998 | || psym->st_name >= strtablen) | |
1999 | name = "??"; | |
2000 | else | |
2001 | name = strtab + psym->st_name; | |
2002 | ||
2003 | len = print_symbol (width, name); | |
2004 | if (version_string) | |
2005 | printf (sym_info == symbol_public ? "@@%s" : "@%s", | |
2006 | version_string); | |
2007 | printf ("()%-*s", len <= width ? (width + 1) - len : 1, " "); | |
2008 | } | |
2009 | else | |
2010 | { | |
2011 | print_vma (psym->st_value, LONG_HEX); | |
2012 | ||
2013 | printf (is_32bit_elf ? " " : " "); | |
2014 | } | |
2015 | ||
2016 | if (psym->st_name == 0) | |
2017 | { | |
2018 | const char * sec_name = "<null>"; | |
2019 | char name_buf[40]; | |
2020 | ||
2021 | if (ELF_ST_TYPE (psym->st_info) == STT_SECTION) | |
2022 | { | |
2023 | if (psym->st_shndx < filedata->file_header.e_shnum | |
2024 | && filedata->section_headers != NULL) | |
2025 | sec_name = section_name_print (filedata, | |
2026 | filedata->section_headers | |
2027 | + psym->st_shndx); | |
2028 | else if (psym->st_shndx == SHN_ABS) | |
2029 | sec_name = "ABS"; | |
2030 | else if (psym->st_shndx == SHN_COMMON) | |
2031 | sec_name = "COMMON"; | |
2032 | else if ((filedata->file_header.e_machine == EM_MIPS | |
2033 | && psym->st_shndx == SHN_MIPS_SCOMMON) | |
2034 | || (filedata->file_header.e_machine == EM_TI_C6000 | |
2035 | && psym->st_shndx == SHN_TIC6X_SCOMMON)) | |
2036 | sec_name = "SCOMMON"; | |
2037 | else if (filedata->file_header.e_machine == EM_MIPS | |
2038 | && psym->st_shndx == SHN_MIPS_SUNDEFINED) | |
2039 | sec_name = "SUNDEF"; | |
2040 | else if ((filedata->file_header.e_machine == EM_X86_64 | |
2041 | || filedata->file_header.e_machine == EM_L1OM | |
2042 | || filedata->file_header.e_machine == EM_K1OM) | |
2043 | && psym->st_shndx == SHN_X86_64_LCOMMON) | |
2044 | sec_name = "LARGE_COMMON"; | |
2045 | else if (filedata->file_header.e_machine == EM_IA_64 | |
2046 | && filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_HPUX | |
2047 | && psym->st_shndx == SHN_IA_64_ANSI_COMMON) | |
2048 | sec_name = "ANSI_COM"; | |
2049 | else if (is_ia64_vms (filedata) | |
2050 | && psym->st_shndx == SHN_IA_64_VMS_SYMVEC) | |
2051 | sec_name = "VMS_SYMVEC"; | |
2052 | else | |
2053 | { | |
2054 | sprintf (name_buf, "<section 0x%x>", | |
2055 | (unsigned int) psym->st_shndx); | |
2056 | sec_name = name_buf; | |
2057 | } | |
2058 | } | |
2059 | print_symbol (22, sec_name); | |
2060 | } | |
2061 | else if (strtab == NULL) | |
2062 | printf (_("<string table index: %3ld>"), psym->st_name); | |
2063 | else if (psym->st_name >= strtablen) | |
2064 | { | |
2065 | error (_("<corrupt string table index: %3ld>\n"), | |
2066 | psym->st_name); | |
2067 | res = false; | |
2068 | } | |
2069 | else | |
2070 | { | |
2071 | print_symbol (22, strtab + psym->st_name); | |
2072 | if (version_string) | |
2073 | printf (sym_info == symbol_public ? "@@%s" : "@%s", | |
2074 | version_string); | |
2075 | } | |
2076 | ||
2077 | if (rel_type == reltype_rela) | |
2078 | { | |
2079 | uint64_t off = rels[i].r_addend; | |
2080 | ||
2081 | if ((int64_t) off < 0) | |
2082 | printf (" - %" PRIx64, -off); | |
2083 | else | |
2084 | printf (" + %" PRIx64, off); | |
2085 | } | |
2086 | } | |
2087 | } | |
2088 | else if (rel_type == reltype_rela) | |
2089 | { | |
2090 | uint64_t off = rels[i].r_addend; | |
2091 | ||
2092 | printf ("%*c", is_32bit_elf ? 12 : 20, ' '); | |
2093 | if ((int64_t) off < 0) | |
2094 | printf ("-%" PRIx64, -off); | |
2095 | else | |
2096 | printf ("%" PRIx64, off); | |
2097 | } | |
2098 | ||
2099 | if (filedata->file_header.e_machine == EM_SPARCV9 | |
2100 | && rtype != NULL | |
2101 | && streq (rtype, "R_SPARC_OLO10")) | |
2102 | printf (" + %" PRIx64, ELF64_R_TYPE_DATA (inf)); | |
2103 | ||
2104 | putchar ('\n'); | |
2105 | ||
2106 | if (! is_32bit_elf && filedata->file_header.e_machine == EM_MIPS) | |
2107 | { | |
2108 | uint64_t type2 = ELF64_MIPS_R_TYPE2 (inf); | |
2109 | uint64_t type3 = ELF64_MIPS_R_TYPE3 (inf); | |
2110 | const char * rtype2 = elf_mips_reloc_type (type2); | |
2111 | const char * rtype3 = elf_mips_reloc_type (type3); | |
2112 | ||
2113 | printf (" Type2: "); | |
2114 | ||
2115 | if (rtype2 == NULL) | |
2116 | printf (_("unrecognized: %-7lx"), | |
2117 | (unsigned long) type2 & 0xffffffff); | |
2118 | else | |
2119 | printf ("%-17.17s", rtype2); | |
2120 | ||
2121 | printf ("\n Type3: "); | |
2122 | ||
2123 | if (rtype3 == NULL) | |
2124 | printf (_("unrecognized: %-7lx"), | |
2125 | (unsigned long) type3 & 0xffffffff); | |
2126 | else | |
2127 | printf ("%-17.17s", rtype3); | |
2128 | ||
2129 | putchar ('\n'); | |
2130 | } | |
2131 | } | |
2132 | ||
2133 | free (rels); | |
2134 | ||
2135 | return res; | |
2136 | } | |
2137 | ||
2138 | static const char * | |
2139 | get_aarch64_dynamic_type (unsigned long type) | |
2140 | { | |
2141 | switch (type) | |
2142 | { | |
2143 | case DT_AARCH64_BTI_PLT: return "AARCH64_BTI_PLT"; | |
2144 | case DT_AARCH64_PAC_PLT: return "AARCH64_PAC_PLT"; | |
2145 | case DT_AARCH64_VARIANT_PCS: return "AARCH64_VARIANT_PCS"; | |
2146 | default: | |
2147 | return NULL; | |
2148 | } | |
2149 | } | |
2150 | ||
2151 | static const char * | |
2152 | get_mips_dynamic_type (unsigned long type) | |
2153 | { | |
2154 | switch (type) | |
2155 | { | |
2156 | case DT_MIPS_RLD_VERSION: return "MIPS_RLD_VERSION"; | |
2157 | case DT_MIPS_TIME_STAMP: return "MIPS_TIME_STAMP"; | |
2158 | case DT_MIPS_ICHECKSUM: return "MIPS_ICHECKSUM"; | |
2159 | case DT_MIPS_IVERSION: return "MIPS_IVERSION"; | |
2160 | case DT_MIPS_FLAGS: return "MIPS_FLAGS"; | |
2161 | case DT_MIPS_BASE_ADDRESS: return "MIPS_BASE_ADDRESS"; | |
2162 | case DT_MIPS_MSYM: return "MIPS_MSYM"; | |
2163 | case DT_MIPS_CONFLICT: return "MIPS_CONFLICT"; | |
2164 | case DT_MIPS_LIBLIST: return "MIPS_LIBLIST"; | |
2165 | case DT_MIPS_LOCAL_GOTNO: return "MIPS_LOCAL_GOTNO"; | |
2166 | case DT_MIPS_CONFLICTNO: return "MIPS_CONFLICTNO"; | |
2167 | case DT_MIPS_LIBLISTNO: return "MIPS_LIBLISTNO"; | |
2168 | case DT_MIPS_SYMTABNO: return "MIPS_SYMTABNO"; | |
2169 | case DT_MIPS_UNREFEXTNO: return "MIPS_UNREFEXTNO"; | |
2170 | case DT_MIPS_GOTSYM: return "MIPS_GOTSYM"; | |
2171 | case DT_MIPS_HIPAGENO: return "MIPS_HIPAGENO"; | |
2172 | case DT_MIPS_RLD_MAP: return "MIPS_RLD_MAP"; | |
2173 | case DT_MIPS_RLD_MAP_REL: return "MIPS_RLD_MAP_REL"; | |
2174 | case DT_MIPS_DELTA_CLASS: return "MIPS_DELTA_CLASS"; | |
2175 | case DT_MIPS_DELTA_CLASS_NO: return "MIPS_DELTA_CLASS_NO"; | |
2176 | case DT_MIPS_DELTA_INSTANCE: return "MIPS_DELTA_INSTANCE"; | |
2177 | case DT_MIPS_DELTA_INSTANCE_NO: return "MIPS_DELTA_INSTANCE_NO"; | |
2178 | case DT_MIPS_DELTA_RELOC: return "MIPS_DELTA_RELOC"; | |
2179 | case DT_MIPS_DELTA_RELOC_NO: return "MIPS_DELTA_RELOC_NO"; | |
2180 | case DT_MIPS_DELTA_SYM: return "MIPS_DELTA_SYM"; | |
2181 | case DT_MIPS_DELTA_SYM_NO: return "MIPS_DELTA_SYM_NO"; | |
2182 | case DT_MIPS_DELTA_CLASSSYM: return "MIPS_DELTA_CLASSSYM"; | |
2183 | case DT_MIPS_DELTA_CLASSSYM_NO: return "MIPS_DELTA_CLASSSYM_NO"; | |
2184 | case DT_MIPS_CXX_FLAGS: return "MIPS_CXX_FLAGS"; | |
2185 | case DT_MIPS_PIXIE_INIT: return "MIPS_PIXIE_INIT"; | |
2186 | case DT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB"; | |
2187 | case DT_MIPS_LOCALPAGE_GOTIDX: return "MIPS_LOCALPAGE_GOTIDX"; | |
2188 | case DT_MIPS_LOCAL_GOTIDX: return "MIPS_LOCAL_GOTIDX"; | |
2189 | case DT_MIPS_HIDDEN_GOTIDX: return "MIPS_HIDDEN_GOTIDX"; | |
2190 | case DT_MIPS_PROTECTED_GOTIDX: return "MIPS_PROTECTED_GOTIDX"; | |
2191 | case DT_MIPS_OPTIONS: return "MIPS_OPTIONS"; | |
2192 | case DT_MIPS_INTERFACE: return "MIPS_INTERFACE"; | |
2193 | case DT_MIPS_DYNSTR_ALIGN: return "MIPS_DYNSTR_ALIGN"; | |
2194 | case DT_MIPS_INTERFACE_SIZE: return "MIPS_INTERFACE_SIZE"; | |
2195 | case DT_MIPS_RLD_TEXT_RESOLVE_ADDR: return "MIPS_RLD_TEXT_RESOLVE_ADDR"; | |
2196 | case DT_MIPS_PERF_SUFFIX: return "MIPS_PERF_SUFFIX"; | |
2197 | case DT_MIPS_COMPACT_SIZE: return "MIPS_COMPACT_SIZE"; | |
2198 | case DT_MIPS_GP_VALUE: return "MIPS_GP_VALUE"; | |
2199 | case DT_MIPS_AUX_DYNAMIC: return "MIPS_AUX_DYNAMIC"; | |
2200 | case DT_MIPS_PLTGOT: return "MIPS_PLTGOT"; | |
2201 | case DT_MIPS_RWPLT: return "MIPS_RWPLT"; | |
2202 | case DT_MIPS_XHASH: return "MIPS_XHASH"; | |
2203 | default: | |
2204 | return NULL; | |
2205 | } | |
2206 | } | |
2207 | ||
2208 | static const char * | |
2209 | get_sparc64_dynamic_type (unsigned long type) | |
2210 | { | |
2211 | switch (type) | |
2212 | { | |
2213 | case DT_SPARC_REGISTER: return "SPARC_REGISTER"; | |
2214 | default: | |
2215 | return NULL; | |
2216 | } | |
2217 | } | |
2218 | ||
2219 | static const char * | |
2220 | get_ppc_dynamic_type (unsigned long type) | |
2221 | { | |
2222 | switch (type) | |
2223 | { | |
2224 | case DT_PPC_GOT: return "PPC_GOT"; | |
2225 | case DT_PPC_OPT: return "PPC_OPT"; | |
2226 | default: | |
2227 | return NULL; | |
2228 | } | |
2229 | } | |
2230 | ||
2231 | static const char * | |
2232 | get_ppc64_dynamic_type (unsigned long type) | |
2233 | { | |
2234 | switch (type) | |
2235 | { | |
2236 | case DT_PPC64_GLINK: return "PPC64_GLINK"; | |
2237 | case DT_PPC64_OPD: return "PPC64_OPD"; | |
2238 | case DT_PPC64_OPDSZ: return "PPC64_OPDSZ"; | |
2239 | case DT_PPC64_OPT: return "PPC64_OPT"; | |
2240 | default: | |
2241 | return NULL; | |
2242 | } | |
2243 | } | |
2244 | ||
2245 | static const char * | |
2246 | get_parisc_dynamic_type (unsigned long type) | |
2247 | { | |
2248 | switch (type) | |
2249 | { | |
2250 | case DT_HP_LOAD_MAP: return "HP_LOAD_MAP"; | |
2251 | case DT_HP_DLD_FLAGS: return "HP_DLD_FLAGS"; | |
2252 | case DT_HP_DLD_HOOK: return "HP_DLD_HOOK"; | |
2253 | case DT_HP_UX10_INIT: return "HP_UX10_INIT"; | |
2254 | case DT_HP_UX10_INITSZ: return "HP_UX10_INITSZ"; | |
2255 | case DT_HP_PREINIT: return "HP_PREINIT"; | |
2256 | case DT_HP_PREINITSZ: return "HP_PREINITSZ"; | |
2257 | case DT_HP_NEEDED: return "HP_NEEDED"; | |
2258 | case DT_HP_TIME_STAMP: return "HP_TIME_STAMP"; | |
2259 | case DT_HP_CHECKSUM: return "HP_CHECKSUM"; | |
2260 | case DT_HP_GST_SIZE: return "HP_GST_SIZE"; | |
2261 | case DT_HP_GST_VERSION: return "HP_GST_VERSION"; | |
2262 | case DT_HP_GST_HASHVAL: return "HP_GST_HASHVAL"; | |
2263 | case DT_HP_EPLTREL: return "HP_GST_EPLTREL"; | |
2264 | case DT_HP_EPLTRELSZ: return "HP_GST_EPLTRELSZ"; | |
2265 | case DT_HP_FILTERED: return "HP_FILTERED"; | |
2266 | case DT_HP_FILTER_TLS: return "HP_FILTER_TLS"; | |
2267 | case DT_HP_COMPAT_FILTERED: return "HP_COMPAT_FILTERED"; | |
2268 | case DT_HP_LAZYLOAD: return "HP_LAZYLOAD"; | |
2269 | case DT_HP_BIND_NOW_COUNT: return "HP_BIND_NOW_COUNT"; | |
2270 | case DT_PLT: return "PLT"; | |
2271 | case DT_PLT_SIZE: return "PLT_SIZE"; | |
2272 | case DT_DLT: return "DLT"; | |
2273 | case DT_DLT_SIZE: return "DLT_SIZE"; | |
2274 | default: | |
2275 | return NULL; | |
2276 | } | |
2277 | } | |
2278 | ||
2279 | static const char * | |
2280 | get_ia64_dynamic_type (unsigned long type) | |
2281 | { | |
2282 | switch (type) | |
2283 | { | |
2284 | case DT_IA_64_PLT_RESERVE: return "IA_64_PLT_RESERVE"; | |
2285 | case DT_IA_64_VMS_SUBTYPE: return "VMS_SUBTYPE"; | |
2286 | case DT_IA_64_VMS_IMGIOCNT: return "VMS_IMGIOCNT"; | |
2287 | case DT_IA_64_VMS_LNKFLAGS: return "VMS_LNKFLAGS"; | |
2288 | case DT_IA_64_VMS_VIR_MEM_BLK_SIZ: return "VMS_VIR_MEM_BLK_SIZ"; | |
2289 | case DT_IA_64_VMS_IDENT: return "VMS_IDENT"; | |
2290 | case DT_IA_64_VMS_NEEDED_IDENT: return "VMS_NEEDED_IDENT"; | |
2291 | case DT_IA_64_VMS_IMG_RELA_CNT: return "VMS_IMG_RELA_CNT"; | |
2292 | case DT_IA_64_VMS_SEG_RELA_CNT: return "VMS_SEG_RELA_CNT"; | |
2293 | case DT_IA_64_VMS_FIXUP_RELA_CNT: return "VMS_FIXUP_RELA_CNT"; | |
2294 | case DT_IA_64_VMS_FIXUP_NEEDED: return "VMS_FIXUP_NEEDED"; | |
2295 | case DT_IA_64_VMS_SYMVEC_CNT: return "VMS_SYMVEC_CNT"; | |
2296 | case DT_IA_64_VMS_XLATED: return "VMS_XLATED"; | |
2297 | case DT_IA_64_VMS_STACKSIZE: return "VMS_STACKSIZE"; | |
2298 | case DT_IA_64_VMS_UNWINDSZ: return "VMS_UNWINDSZ"; | |
2299 | case DT_IA_64_VMS_UNWIND_CODSEG: return "VMS_UNWIND_CODSEG"; | |
2300 | case DT_IA_64_VMS_UNWIND_INFOSEG: return "VMS_UNWIND_INFOSEG"; | |
2301 | case DT_IA_64_VMS_LINKTIME: return "VMS_LINKTIME"; | |
2302 | case DT_IA_64_VMS_SEG_NO: return "VMS_SEG_NO"; | |
2303 | case DT_IA_64_VMS_SYMVEC_OFFSET: return "VMS_SYMVEC_OFFSET"; | |
2304 | case DT_IA_64_VMS_SYMVEC_SEG: return "VMS_SYMVEC_SEG"; | |
2305 | case DT_IA_64_VMS_UNWIND_OFFSET: return "VMS_UNWIND_OFFSET"; | |
2306 | case DT_IA_64_VMS_UNWIND_SEG: return "VMS_UNWIND_SEG"; | |
2307 | case DT_IA_64_VMS_STRTAB_OFFSET: return "VMS_STRTAB_OFFSET"; | |
2308 | case DT_IA_64_VMS_SYSVER_OFFSET: return "VMS_SYSVER_OFFSET"; | |
2309 | case DT_IA_64_VMS_IMG_RELA_OFF: return "VMS_IMG_RELA_OFF"; | |
2310 | case DT_IA_64_VMS_SEG_RELA_OFF: return "VMS_SEG_RELA_OFF"; | |
2311 | case DT_IA_64_VMS_FIXUP_RELA_OFF: return "VMS_FIXUP_RELA_OFF"; | |
2312 | case DT_IA_64_VMS_PLTGOT_OFFSET: return "VMS_PLTGOT_OFFSET"; | |
2313 | case DT_IA_64_VMS_PLTGOT_SEG: return "VMS_PLTGOT_SEG"; | |
2314 | case DT_IA_64_VMS_FPMODE: return "VMS_FPMODE"; | |
2315 | default: | |
2316 | return NULL; | |
2317 | } | |
2318 | } | |
2319 | ||
2320 | static const char * | |
2321 | get_solaris_section_type (unsigned long type) | |
2322 | { | |
2323 | switch (type) | |
2324 | { | |
2325 | case 0x6fffffee: return "SUNW_ancillary"; | |
2326 | case 0x6fffffef: return "SUNW_capchain"; | |
2327 | case 0x6ffffff0: return "SUNW_capinfo"; | |
2328 | case 0x6ffffff1: return "SUNW_symsort"; | |
2329 | case 0x6ffffff2: return "SUNW_tlssort"; | |
2330 | case 0x6ffffff3: return "SUNW_LDYNSYM"; | |
2331 | case 0x6ffffff4: return "SUNW_dof"; | |
2332 | case 0x6ffffff5: return "SUNW_cap"; | |
2333 | case 0x6ffffff6: return "SUNW_SIGNATURE"; | |
2334 | case 0x6ffffff7: return "SUNW_ANNOTATE"; | |
2335 | case 0x6ffffff8: return "SUNW_DEBUGSTR"; | |
2336 | case 0x6ffffff9: return "SUNW_DEBUG"; | |
2337 | case 0x6ffffffa: return "SUNW_move"; | |
2338 | case 0x6ffffffb: return "SUNW_COMDAT"; | |
2339 | case 0x6ffffffc: return "SUNW_syminfo"; | |
2340 | case 0x6ffffffd: return "SUNW_verdef"; | |
2341 | case 0x6ffffffe: return "SUNW_verneed"; | |
2342 | case 0x6fffffff: return "SUNW_versym"; | |
2343 | case 0x70000000: return "SPARC_GOTDATA"; | |
2344 | default: return NULL; | |
2345 | } | |
2346 | } | |
2347 | ||
2348 | static const char * | |
2349 | get_alpha_dynamic_type (unsigned long type) | |
2350 | { | |
2351 | switch (type) | |
2352 | { | |
2353 | case DT_ALPHA_PLTRO: return "ALPHA_PLTRO"; | |
2354 | default: return NULL; | |
2355 | } | |
2356 | } | |
2357 | ||
2358 | static const char * | |
2359 | get_score_dynamic_type (unsigned long type) | |
2360 | { | |
2361 | switch (type) | |
2362 | { | |
2363 | case DT_SCORE_BASE_ADDRESS: return "SCORE_BASE_ADDRESS"; | |
2364 | case DT_SCORE_LOCAL_GOTNO: return "SCORE_LOCAL_GOTNO"; | |
2365 | case DT_SCORE_SYMTABNO: return "SCORE_SYMTABNO"; | |
2366 | case DT_SCORE_GOTSYM: return "SCORE_GOTSYM"; | |
2367 | case DT_SCORE_UNREFEXTNO: return "SCORE_UNREFEXTNO"; | |
2368 | case DT_SCORE_HIPAGENO: return "SCORE_HIPAGENO"; | |
2369 | default: return NULL; | |
2370 | } | |
2371 | } | |
2372 | ||
2373 | static const char * | |
2374 | get_tic6x_dynamic_type (unsigned long type) | |
2375 | { | |
2376 | switch (type) | |
2377 | { | |
2378 | case DT_C6000_GSYM_OFFSET: return "C6000_GSYM_OFFSET"; | |
2379 | case DT_C6000_GSTR_OFFSET: return "C6000_GSTR_OFFSET"; | |
2380 | case DT_C6000_DSBT_BASE: return "C6000_DSBT_BASE"; | |
2381 | case DT_C6000_DSBT_SIZE: return "C6000_DSBT_SIZE"; | |
2382 | case DT_C6000_PREEMPTMAP: return "C6000_PREEMPTMAP"; | |
2383 | case DT_C6000_DSBT_INDEX: return "C6000_DSBT_INDEX"; | |
2384 | default: return NULL; | |
2385 | } | |
2386 | } | |
2387 | ||
2388 | static const char * | |
2389 | get_nios2_dynamic_type (unsigned long type) | |
2390 | { | |
2391 | switch (type) | |
2392 | { | |
2393 | case DT_NIOS2_GP: return "NIOS2_GP"; | |
2394 | default: return NULL; | |
2395 | } | |
2396 | } | |
2397 | ||
2398 | static const char * | |
2399 | get_solaris_dynamic_type (unsigned long type) | |
2400 | { | |
2401 | switch (type) | |
2402 | { | |
2403 | case 0x6000000d: return "SUNW_AUXILIARY"; | |
2404 | case 0x6000000e: return "SUNW_RTLDINF"; | |
2405 | case 0x6000000f: return "SUNW_FILTER"; | |
2406 | case 0x60000010: return "SUNW_CAP"; | |
2407 | case 0x60000011: return "SUNW_SYMTAB"; | |
2408 | case 0x60000012: return "SUNW_SYMSZ"; | |
2409 | case 0x60000013: return "SUNW_SORTENT"; | |
2410 | case 0x60000014: return "SUNW_SYMSORT"; | |
2411 | case 0x60000015: return "SUNW_SYMSORTSZ"; | |
2412 | case 0x60000016: return "SUNW_TLSSORT"; | |
2413 | case 0x60000017: return "SUNW_TLSSORTSZ"; | |
2414 | case 0x60000018: return "SUNW_CAPINFO"; | |
2415 | case 0x60000019: return "SUNW_STRPAD"; | |
2416 | case 0x6000001a: return "SUNW_CAPCHAIN"; | |
2417 | case 0x6000001b: return "SUNW_LDMACH"; | |
2418 | case 0x6000001d: return "SUNW_CAPCHAINENT"; | |
2419 | case 0x6000001f: return "SUNW_CAPCHAINSZ"; | |
2420 | case 0x60000021: return "SUNW_PARENT"; | |
2421 | case 0x60000023: return "SUNW_ASLR"; | |
2422 | case 0x60000025: return "SUNW_RELAX"; | |
2423 | case 0x60000029: return "SUNW_NXHEAP"; | |
2424 | case 0x6000002b: return "SUNW_NXSTACK"; | |
2425 | ||
2426 | case 0x70000001: return "SPARC_REGISTER"; | |
2427 | case 0x7ffffffd: return "AUXILIARY"; | |
2428 | case 0x7ffffffe: return "USED"; | |
2429 | case 0x7fffffff: return "FILTER"; | |
2430 | ||
2431 | default: return NULL; | |
2432 | } | |
2433 | } | |
2434 | ||
2435 | static const char * | |
2436 | get_riscv_dynamic_type (unsigned long type) | |
2437 | { | |
2438 | switch (type) | |
2439 | { | |
2440 | case DT_RISCV_VARIANT_CC: return "RISCV_VARIANT_CC"; | |
2441 | default: | |
2442 | return NULL; | |
2443 | } | |
2444 | } | |
2445 | ||
2446 | static const char * | |
2447 | get_dynamic_type (Filedata * filedata, unsigned long type) | |
2448 | { | |
2449 | static char buff[64]; | |
2450 | ||
2451 | switch (type) | |
2452 | { | |
2453 | case DT_NULL: return "NULL"; | |
2454 | case DT_NEEDED: return "NEEDED"; | |
2455 | case DT_PLTRELSZ: return "PLTRELSZ"; | |
2456 | case DT_PLTGOT: return "PLTGOT"; | |
2457 | case DT_HASH: return "HASH"; | |
2458 | case DT_STRTAB: return "STRTAB"; | |
2459 | case DT_SYMTAB: return "SYMTAB"; | |
2460 | case DT_RELA: return "RELA"; | |
2461 | case DT_RELASZ: return "RELASZ"; | |
2462 | case DT_RELAENT: return "RELAENT"; | |
2463 | case DT_STRSZ: return "STRSZ"; | |
2464 | case DT_SYMENT: return "SYMENT"; | |
2465 | case DT_INIT: return "INIT"; | |
2466 | case DT_FINI: return "FINI"; | |
2467 | case DT_SONAME: return "SONAME"; | |
2468 | case DT_RPATH: return "RPATH"; | |
2469 | case DT_SYMBOLIC: return "SYMBOLIC"; | |
2470 | case DT_REL: return "REL"; | |
2471 | case DT_RELSZ: return "RELSZ"; | |
2472 | case DT_RELENT: return "RELENT"; | |
2473 | case DT_RELR: return "RELR"; | |
2474 | case DT_RELRSZ: return "RELRSZ"; | |
2475 | case DT_RELRENT: return "RELRENT"; | |
2476 | case DT_PLTREL: return "PLTREL"; | |
2477 | case DT_DEBUG: return "DEBUG"; | |
2478 | case DT_TEXTREL: return "TEXTREL"; | |
2479 | case DT_JMPREL: return "JMPREL"; | |
2480 | case DT_BIND_NOW: return "BIND_NOW"; | |
2481 | case DT_INIT_ARRAY: return "INIT_ARRAY"; | |
2482 | case DT_FINI_ARRAY: return "FINI_ARRAY"; | |
2483 | case DT_INIT_ARRAYSZ: return "INIT_ARRAYSZ"; | |
2484 | case DT_FINI_ARRAYSZ: return "FINI_ARRAYSZ"; | |
2485 | case DT_RUNPATH: return "RUNPATH"; | |
2486 | case DT_FLAGS: return "FLAGS"; | |
2487 | ||
2488 | case DT_PREINIT_ARRAY: return "PREINIT_ARRAY"; | |
2489 | case DT_PREINIT_ARRAYSZ: return "PREINIT_ARRAYSZ"; | |
2490 | case DT_SYMTAB_SHNDX: return "SYMTAB_SHNDX"; | |
2491 | ||
2492 | case DT_CHECKSUM: return "CHECKSUM"; | |
2493 | case DT_PLTPADSZ: return "PLTPADSZ"; | |
2494 | case DT_MOVEENT: return "MOVEENT"; | |
2495 | case DT_MOVESZ: return "MOVESZ"; | |
2496 | case DT_FEATURE: return "FEATURE"; | |
2497 | case DT_POSFLAG_1: return "POSFLAG_1"; | |
2498 | case DT_SYMINSZ: return "SYMINSZ"; | |
2499 | case DT_SYMINENT: return "SYMINENT"; /* aka VALRNGHI */ | |
2500 | ||
2501 | case DT_ADDRRNGLO: return "ADDRRNGLO"; | |
2502 | case DT_CONFIG: return "CONFIG"; | |
2503 | case DT_DEPAUDIT: return "DEPAUDIT"; | |
2504 | case DT_AUDIT: return "AUDIT"; | |
2505 | case DT_PLTPAD: return "PLTPAD"; | |
2506 | case DT_MOVETAB: return "MOVETAB"; | |
2507 | case DT_SYMINFO: return "SYMINFO"; /* aka ADDRRNGHI */ | |
2508 | ||
2509 | case DT_VERSYM: return "VERSYM"; | |
2510 | ||
2511 | case DT_TLSDESC_GOT: return "TLSDESC_GOT"; | |
2512 | case DT_TLSDESC_PLT: return "TLSDESC_PLT"; | |
2513 | case DT_RELACOUNT: return "RELACOUNT"; | |
2514 | case DT_RELCOUNT: return "RELCOUNT"; | |
2515 | case DT_FLAGS_1: return "FLAGS_1"; | |
2516 | case DT_VERDEF: return "VERDEF"; | |
2517 | case DT_VERDEFNUM: return "VERDEFNUM"; | |
2518 | case DT_VERNEED: return "VERNEED"; | |
2519 | case DT_VERNEEDNUM: return "VERNEEDNUM"; | |
2520 | ||
2521 | case DT_AUXILIARY: return "AUXILIARY"; | |
2522 | case DT_USED: return "USED"; | |
2523 | case DT_FILTER: return "FILTER"; | |
2524 | ||
2525 | case DT_GNU_PRELINKED: return "GNU_PRELINKED"; | |
2526 | case DT_GNU_CONFLICT: return "GNU_CONFLICT"; | |
2527 | case DT_GNU_CONFLICTSZ: return "GNU_CONFLICTSZ"; | |
2528 | case DT_GNU_LIBLIST: return "GNU_LIBLIST"; | |
2529 | case DT_GNU_LIBLISTSZ: return "GNU_LIBLISTSZ"; | |
2530 | case DT_GNU_HASH: return "GNU_HASH"; | |
2531 | case DT_GNU_FLAGS_1: return "GNU_FLAGS_1"; | |
2532 | ||
2533 | default: | |
2534 | if ((type >= DT_LOPROC) && (type <= DT_HIPROC)) | |
2535 | { | |
2536 | const char * result; | |
2537 | ||
2538 | switch (filedata->file_header.e_machine) | |
2539 | { | |
2540 | case EM_AARCH64: | |
2541 | result = get_aarch64_dynamic_type (type); | |
2542 | break; | |
2543 | case EM_MIPS: | |
2544 | case EM_MIPS_RS3_LE: | |
2545 | result = get_mips_dynamic_type (type); | |
2546 | break; | |
2547 | case EM_SPARCV9: | |
2548 | result = get_sparc64_dynamic_type (type); | |
2549 | break; | |
2550 | case EM_PPC: | |
2551 | result = get_ppc_dynamic_type (type); | |
2552 | break; | |
2553 | case EM_PPC64: | |
2554 | result = get_ppc64_dynamic_type (type); | |
2555 | break; | |
2556 | case EM_IA_64: | |
2557 | result = get_ia64_dynamic_type (type); | |
2558 | break; | |
2559 | case EM_ALPHA: | |
2560 | result = get_alpha_dynamic_type (type); | |
2561 | break; | |
2562 | case EM_SCORE: | |
2563 | result = get_score_dynamic_type (type); | |
2564 | break; | |
2565 | case EM_TI_C6000: | |
2566 | result = get_tic6x_dynamic_type (type); | |
2567 | break; | |
2568 | case EM_ALTERA_NIOS2: | |
2569 | result = get_nios2_dynamic_type (type); | |
2570 | break; | |
2571 | case EM_RISCV: | |
2572 | result = get_riscv_dynamic_type (type); | |
2573 | break; | |
2574 | default: | |
2575 | if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS) | |
2576 | result = get_solaris_dynamic_type (type); | |
2577 | else | |
2578 | result = NULL; | |
2579 | break; | |
2580 | } | |
2581 | ||
2582 | if (result != NULL) | |
2583 | return result; | |
2584 | ||
2585 | snprintf (buff, sizeof (buff), _("Processor Specific: %lx"), type); | |
2586 | } | |
2587 | else if (((type >= DT_LOOS) && (type <= DT_HIOS)) | |
2588 | || (filedata->file_header.e_machine == EM_PARISC | |
2589 | && (type >= OLD_DT_LOOS) && (type <= OLD_DT_HIOS))) | |
2590 | { | |
2591 | const char * result; | |
2592 | ||
2593 | switch (filedata->file_header.e_machine) | |
2594 | { | |
2595 | case EM_PARISC: | |
2596 | result = get_parisc_dynamic_type (type); | |
2597 | break; | |
2598 | case EM_IA_64: | |
2599 | result = get_ia64_dynamic_type (type); | |
2600 | break; | |
2601 | default: | |
2602 | if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS) | |
2603 | result = get_solaris_dynamic_type (type); | |
2604 | else | |
2605 | result = NULL; | |
2606 | break; | |
2607 | } | |
2608 | ||
2609 | if (result != NULL) | |
2610 | return result; | |
2611 | ||
2612 | snprintf (buff, sizeof (buff), _("Operating System specific: %lx"), | |
2613 | type); | |
2614 | } | |
2615 | else | |
2616 | snprintf (buff, sizeof (buff), _("<unknown>: %lx"), type); | |
2617 | ||
2618 | return buff; | |
2619 | } | |
2620 | } | |
2621 | ||
2622 | static bool get_program_headers (Filedata *); | |
2623 | static bool get_dynamic_section (Filedata *); | |
2624 | ||
2625 | static void | |
2626 | locate_dynamic_section (Filedata *filedata) | |
2627 | { | |
2628 | uint64_t dynamic_addr = 0; | |
2629 | uint64_t dynamic_size = 0; | |
2630 | ||
2631 | if (filedata->file_header.e_phnum != 0 | |
2632 | && get_program_headers (filedata)) | |
2633 | { | |
2634 | Elf_Internal_Phdr *segment; | |
2635 | unsigned int i; | |
2636 | ||
2637 | for (i = 0, segment = filedata->program_headers; | |
2638 | i < filedata->file_header.e_phnum; | |
2639 | i++, segment++) | |
2640 | { | |
2641 | if (segment->p_type == PT_DYNAMIC) | |
2642 | { | |
2643 | dynamic_addr = segment->p_offset; | |
2644 | dynamic_size = segment->p_filesz; | |
2645 | ||
2646 | if (filedata->section_headers != NULL) | |
2647 | { | |
2648 | Elf_Internal_Shdr *sec; | |
2649 | ||
2650 | sec = find_section (filedata, ".dynamic"); | |
2651 | if (sec != NULL) | |
2652 | { | |
2653 | if (sec->sh_size == 0 | |
2654 | || sec->sh_type == SHT_NOBITS) | |
2655 | { | |
2656 | dynamic_addr = 0; | |
2657 | dynamic_size = 0; | |
2658 | } | |
2659 | else | |
2660 | { | |
2661 | dynamic_addr = sec->sh_offset; | |
2662 | dynamic_size = sec->sh_size; | |
2663 | } | |
2664 | } | |
2665 | } | |
2666 | ||
2667 | if (dynamic_addr > filedata->file_size | |
2668 | || (dynamic_size > filedata->file_size - dynamic_addr)) | |
2669 | { | |
2670 | dynamic_addr = 0; | |
2671 | dynamic_size = 0; | |
2672 | } | |
2673 | break; | |
2674 | } | |
2675 | } | |
2676 | } | |
2677 | filedata->dynamic_addr = dynamic_addr; | |
2678 | filedata->dynamic_size = dynamic_size ? dynamic_size : 1; | |
2679 | } | |
2680 | ||
2681 | static bool | |
2682 | is_pie (Filedata *filedata) | |
2683 | { | |
2684 | Elf_Internal_Dyn *entry; | |
2685 | ||
2686 | if (filedata->dynamic_size == 0) | |
2687 | locate_dynamic_section (filedata); | |
2688 | if (filedata->dynamic_size <= 1) | |
2689 | return false; | |
2690 | ||
2691 | if (!get_dynamic_section (filedata)) | |
2692 | return false; | |
2693 | ||
2694 | for (entry = filedata->dynamic_section; | |
2695 | entry < filedata->dynamic_section + filedata->dynamic_nent; | |
2696 | entry++) | |
2697 | { | |
2698 | if (entry->d_tag == DT_FLAGS_1) | |
2699 | { | |
2700 | if ((entry->d_un.d_val & DF_1_PIE) != 0) | |
2701 | return true; | |
2702 | break; | |
2703 | } | |
2704 | } | |
2705 | return false; | |
2706 | } | |
2707 | ||
2708 | static char * | |
2709 | get_file_type (Filedata *filedata) | |
2710 | { | |
2711 | unsigned e_type = filedata->file_header.e_type; | |
2712 | static char buff[64]; | |
2713 | ||
2714 | switch (e_type) | |
2715 | { | |
2716 | case ET_NONE: return _("NONE (None)"); | |
2717 | case ET_REL: return _("REL (Relocatable file)"); | |
2718 | case ET_EXEC: return _("EXEC (Executable file)"); | |
2719 | case ET_DYN: | |
2720 | if (is_pie (filedata)) | |
2721 | return _("DYN (Position-Independent Executable file)"); | |
2722 | else | |
2723 | return _("DYN (Shared object file)"); | |
2724 | case ET_CORE: return _("CORE (Core file)"); | |
2725 | ||
2726 | default: | |
2727 | if ((e_type >= ET_LOPROC) && (e_type <= ET_HIPROC)) | |
2728 | snprintf (buff, sizeof (buff), _("Processor Specific: (%x)"), e_type); | |
2729 | else if ((e_type >= ET_LOOS) && (e_type <= ET_HIOS)) | |
2730 | snprintf (buff, sizeof (buff), _("OS Specific: (%x)"), e_type); | |
2731 | else | |
2732 | snprintf (buff, sizeof (buff), _("<unknown>: %x"), e_type); | |
2733 | return buff; | |
2734 | } | |
2735 | } | |
2736 | ||
2737 | static char * | |
2738 | get_machine_name (unsigned e_machine) | |
2739 | { | |
2740 | static char buff[64]; /* XXX */ | |
2741 | ||
2742 | switch (e_machine) | |
2743 | { | |
2744 | /* Please keep this switch table sorted by increasing EM_ value. */ | |
2745 | /* 0 */ | |
2746 | case EM_NONE: return _("None"); | |
2747 | case EM_M32: return "WE32100"; | |
2748 | case EM_SPARC: return "Sparc"; | |
2749 | case EM_386: return "Intel 80386"; | |
2750 | case EM_68K: return "MC68000"; | |
2751 | case EM_88K: return "MC88000"; | |
2752 | case EM_IAMCU: return "Intel MCU"; | |
2753 | case EM_860: return "Intel 80860"; | |
2754 | case EM_MIPS: return "MIPS R3000"; | |
2755 | case EM_S370: return "IBM System/370"; | |
2756 | /* 10 */ | |
2757 | case EM_MIPS_RS3_LE: return "MIPS R4000 big-endian"; | |
2758 | case EM_OLD_SPARCV9: return "Sparc v9 (old)"; | |
2759 | case EM_PARISC: return "HPPA"; | |
2760 | case EM_VPP550: return "Fujitsu VPP500"; | |
2761 | case EM_SPARC32PLUS: return "Sparc v8+" ; | |
2762 | case EM_960: return "Intel 80960"; | |
2763 | case EM_PPC: return "PowerPC"; | |
2764 | /* 20 */ | |
2765 | case EM_PPC64: return "PowerPC64"; | |
2766 | case EM_S390_OLD: | |
2767 | case EM_S390: return "IBM S/390"; | |
2768 | case EM_SPU: return "SPU"; | |
2769 | /* 30 */ | |
2770 | case EM_V800: return "Renesas V850 (using RH850 ABI)"; | |
2771 | case EM_FR20: return "Fujitsu FR20"; | |
2772 | case EM_RH32: return "TRW RH32"; | |
2773 | case EM_MCORE: return "MCORE"; | |
2774 | /* 40 */ | |
2775 | case EM_ARM: return "ARM"; | |
2776 | case EM_OLD_ALPHA: return "Digital Alpha (old)"; | |
2777 | case EM_SH: return "Renesas / SuperH SH"; | |
2778 | case EM_SPARCV9: return "Sparc v9"; | |
2779 | case EM_TRICORE: return "Siemens Tricore"; | |
2780 | case EM_ARC: return "ARC"; | |
2781 | case EM_H8_300: return "Renesas H8/300"; | |
2782 | case EM_H8_300H: return "Renesas H8/300H"; | |
2783 | case EM_H8S: return "Renesas H8S"; | |
2784 | case EM_H8_500: return "Renesas H8/500"; | |
2785 | /* 50 */ | |
2786 | case EM_IA_64: return "Intel IA-64"; | |
2787 | case EM_MIPS_X: return "Stanford MIPS-X"; | |
2788 | case EM_COLDFIRE: return "Motorola Coldfire"; | |
2789 | case EM_68HC12: return "Motorola MC68HC12 Microcontroller"; | |
2790 | case EM_MMA: return "Fujitsu Multimedia Accelerator"; | |
2791 | case EM_PCP: return "Siemens PCP"; | |
2792 | case EM_NCPU: return "Sony nCPU embedded RISC processor"; | |
2793 | case EM_NDR1: return "Denso NDR1 microprocesspr"; | |
2794 | case EM_STARCORE: return "Motorola Star*Core processor"; | |
2795 | case EM_ME16: return "Toyota ME16 processor"; | |
2796 | /* 60 */ | |
2797 | case EM_ST100: return "STMicroelectronics ST100 processor"; | |
2798 | case EM_TINYJ: return "Advanced Logic Corp. TinyJ embedded processor"; | |
2799 | case EM_X86_64: return "Advanced Micro Devices X86-64"; | |
2800 | case EM_PDSP: return "Sony DSP processor"; | |
2801 | case EM_PDP10: return "Digital Equipment Corp. PDP-10"; | |
2802 | case EM_PDP11: return "Digital Equipment Corp. PDP-11"; | |
2803 | case EM_FX66: return "Siemens FX66 microcontroller"; | |
2804 | case EM_ST9PLUS: return "STMicroelectronics ST9+ 8/16 bit microcontroller"; | |
2805 | case EM_ST7: return "STMicroelectronics ST7 8-bit microcontroller"; | |
2806 | case EM_68HC16: return "Motorola MC68HC16 Microcontroller"; | |
2807 | /* 70 */ | |
2808 | case EM_68HC11: return "Motorola MC68HC11 Microcontroller"; | |
2809 | case EM_68HC08: return "Motorola MC68HC08 Microcontroller"; | |
2810 | case EM_68HC05: return "Motorola MC68HC05 Microcontroller"; | |
2811 | case EM_SVX: return "Silicon Graphics SVx"; | |
2812 | case EM_ST19: return "STMicroelectronics ST19 8-bit microcontroller"; | |
2813 | case EM_VAX: return "Digital VAX"; | |
2814 | case EM_CRIS: return "Axis Communications 32-bit embedded processor"; | |
2815 | case EM_JAVELIN: return "Infineon Technologies 32-bit embedded cpu"; | |
2816 | case EM_FIREPATH: return "Element 14 64-bit DSP processor"; | |
2817 | case EM_ZSP: return "LSI Logic's 16-bit DSP processor"; | |
2818 | /* 80 */ | |
2819 | case EM_MMIX: return "Donald Knuth's educational 64-bit processor"; | |
2820 | case EM_HUANY: return "Harvard Universitys's machine-independent object format"; | |
2821 | case EM_PRISM: return "Vitesse Prism"; | |
2822 | case EM_AVR_OLD: | |
2823 | case EM_AVR: return "Atmel AVR 8-bit microcontroller"; | |
2824 | case EM_CYGNUS_FR30: | |
2825 | case EM_FR30: return "Fujitsu FR30"; | |
2826 | case EM_CYGNUS_D10V: | |
2827 | case EM_D10V: return "d10v"; | |
2828 | case EM_CYGNUS_D30V: | |
2829 | case EM_D30V: return "d30v"; | |
2830 | case EM_CYGNUS_V850: | |
2831 | case EM_V850: return "Renesas V850"; | |
2832 | case EM_CYGNUS_M32R: | |
2833 | case EM_M32R: return "Renesas M32R (formerly Mitsubishi M32r)"; | |
2834 | case EM_CYGNUS_MN10300: | |
2835 | case EM_MN10300: return "mn10300"; | |
2836 | /* 90 */ | |
2837 | case EM_CYGNUS_MN10200: | |
2838 | case EM_MN10200: return "mn10200"; | |
2839 | case EM_PJ: return "picoJava"; | |
2840 | case EM_OR1K: return "OpenRISC 1000"; | |
2841 | case EM_ARC_COMPACT: return "ARCompact"; | |
2842 | case EM_XTENSA_OLD: | |
2843 | case EM_XTENSA: return "Tensilica Xtensa Processor"; | |
2844 | case EM_VIDEOCORE: return "Alphamosaic VideoCore processor"; | |
2845 | case EM_TMM_GPP: return "Thompson Multimedia General Purpose Processor"; | |
2846 | case EM_NS32K: return "National Semiconductor 32000 series"; | |
2847 | case EM_TPC: return "Tenor Network TPC processor"; | |
2848 | case EM_SNP1K: return "Trebia SNP 1000 processor"; | |
2849 | /* 100 */ | |
2850 | case EM_ST200: return "STMicroelectronics ST200 microcontroller"; | |
2851 | case EM_IP2K_OLD: | |
2852 | case EM_IP2K: return "Ubicom IP2xxx 8-bit microcontrollers"; | |
2853 | case EM_MAX: return "MAX Processor"; | |
2854 | case EM_CR: return "National Semiconductor CompactRISC"; | |
2855 | case EM_F2MC16: return "Fujitsu F2MC16"; | |
2856 | case EM_MSP430: return "Texas Instruments msp430 microcontroller"; | |
2857 | case EM_BLACKFIN: return "Analog Devices Blackfin"; | |
2858 | case EM_SE_C33: return "S1C33 Family of Seiko Epson processors"; | |
2859 | case EM_SEP: return "Sharp embedded microprocessor"; | |
2860 | case EM_ARCA: return "Arca RISC microprocessor"; | |
2861 | /* 110 */ | |
2862 | case EM_UNICORE: return "Unicore"; | |
2863 | case EM_EXCESS: return "eXcess 16/32/64-bit configurable embedded CPU"; | |
2864 | case EM_DXP: return "Icera Semiconductor Inc. Deep Execution Processor"; | |
2865 | case EM_ALTERA_NIOS2: return "Altera Nios II"; | |
2866 | case EM_CRX: return "National Semiconductor CRX microprocessor"; | |
2867 | case EM_XGATE: return "Motorola XGATE embedded processor"; | |
2868 | case EM_C166: | |
2869 | case EM_XC16X: return "Infineon Technologies xc16x"; | |
2870 | case EM_M16C: return "Renesas M16C series microprocessors"; | |
2871 | case EM_DSPIC30F: return "Microchip Technology dsPIC30F Digital Signal Controller"; | |
2872 | case EM_CE: return "Freescale Communication Engine RISC core"; | |
2873 | /* 120 */ | |
2874 | case EM_M32C: return "Renesas M32c"; | |
2875 | /* 130 */ | |
2876 | case EM_TSK3000: return "Altium TSK3000 core"; | |
2877 | case EM_RS08: return "Freescale RS08 embedded processor"; | |
2878 | case EM_ECOG2: return "Cyan Technology eCOG2 microprocessor"; | |
2879 | case EM_SCORE: return "SUNPLUS S+Core"; | |
2880 | case EM_DSP24: return "New Japan Radio (NJR) 24-bit DSP Processor"; | |
2881 | case EM_VIDEOCORE3: return "Broadcom VideoCore III processor"; | |
2882 | case EM_LATTICEMICO32: return "Lattice Mico32"; | |
2883 | case EM_SE_C17: return "Seiko Epson C17 family"; | |
2884 | /* 140 */ | |
2885 | case EM_TI_C6000: return "Texas Instruments TMS320C6000 DSP family"; | |
2886 | case EM_TI_C2000: return "Texas Instruments TMS320C2000 DSP family"; | |
2887 | case EM_TI_C5500: return "Texas Instruments TMS320C55x DSP family"; | |
2888 | case EM_TI_PRU: return "TI PRU I/O processor"; | |
2889 | /* 160 */ | |
2890 | case EM_MMDSP_PLUS: return "STMicroelectronics 64bit VLIW Data Signal Processor"; | |
2891 | case EM_CYPRESS_M8C: return "Cypress M8C microprocessor"; | |
2892 | case EM_R32C: return "Renesas R32C series microprocessors"; | |
2893 | case EM_TRIMEDIA: return "NXP Semiconductors TriMedia architecture family"; | |
2894 | case EM_QDSP6: return "QUALCOMM DSP6 Processor"; | |
2895 | case EM_8051: return "Intel 8051 and variants"; | |
2896 | case EM_STXP7X: return "STMicroelectronics STxP7x family"; | |
2897 | case EM_NDS32: return "Andes Technology compact code size embedded RISC processor family"; | |
2898 | case EM_ECOG1X: return "Cyan Technology eCOG1X family"; | |
2899 | case EM_MAXQ30: return "Dallas Semiconductor MAXQ30 Core microcontrollers"; | |
2900 | /* 170 */ | |
2901 | case EM_XIMO16: return "New Japan Radio (NJR) 16-bit DSP Processor"; | |
2902 | case EM_MANIK: return "M2000 Reconfigurable RISC Microprocessor"; | |
2903 | case EM_CRAYNV2: return "Cray Inc. NV2 vector architecture"; | |
2904 | case EM_RX: return "Renesas RX"; | |
2905 | case EM_METAG: return "Imagination Technologies Meta processor architecture"; | |
2906 | case EM_MCST_ELBRUS: return "MCST Elbrus general purpose hardware architecture"; | |
2907 | case EM_ECOG16: return "Cyan Technology eCOG16 family"; | |
2908 | case EM_CR16: | |
2909 | case EM_MICROBLAZE: | |
2910 | case EM_MICROBLAZE_OLD: return "Xilinx MicroBlaze"; | |
2911 | case EM_ETPU: return "Freescale Extended Time Processing Unit"; | |
2912 | case EM_SLE9X: return "Infineon Technologies SLE9X core"; | |
2913 | /* 180 */ | |
2914 | case EM_L1OM: return "Intel L1OM"; | |
2915 | case EM_K1OM: return "Intel K1OM"; | |
2916 | case EM_INTEL182: return "Intel (reserved)"; | |
2917 | case EM_AARCH64: return "AArch64"; | |
2918 | case EM_ARM184: return "ARM (reserved)"; | |
2919 | case EM_AVR32: return "Atmel Corporation 32-bit microprocessor"; | |
2920 | case EM_STM8: return "STMicroeletronics STM8 8-bit microcontroller"; | |
2921 | case EM_TILE64: return "Tilera TILE64 multicore architecture family"; | |
2922 | case EM_TILEPRO: return "Tilera TILEPro multicore architecture family"; | |
2923 | /* 190 */ | |
2924 | case EM_CUDA: return "NVIDIA CUDA architecture"; | |
2925 | case EM_TILEGX: return "Tilera TILE-Gx multicore architecture family"; | |
2926 | case EM_CLOUDSHIELD: return "CloudShield architecture family"; | |
2927 | case EM_COREA_1ST: return "KIPO-KAIST Core-A 1st generation processor family"; | |
2928 | case EM_COREA_2ND: return "KIPO-KAIST Core-A 2nd generation processor family"; | |
2929 | case EM_ARC_COMPACT2: return "ARCv2"; | |
2930 | case EM_OPEN8: return "Open8 8-bit RISC soft processor core"; | |
2931 | case EM_RL78: return "Renesas RL78"; | |
2932 | case EM_VIDEOCORE5: return "Broadcom VideoCore V processor"; | |
2933 | case EM_78K0R: return "Renesas 78K0R"; | |
2934 | /* 200 */ | |
2935 | case EM_56800EX: return "Freescale 56800EX Digital Signal Controller (DSC)"; | |
2936 | case EM_BA1: return "Beyond BA1 CPU architecture"; | |
2937 | case EM_BA2: return "Beyond BA2 CPU architecture"; | |
2938 | case EM_XCORE: return "XMOS xCORE processor family"; | |
2939 | case EM_MCHP_PIC: return "Microchip 8-bit PIC(r) family"; | |
2940 | case EM_INTELGT: return "Intel Graphics Technology"; | |
2941 | /* 210 */ | |
2942 | case EM_KM32: return "KM211 KM32 32-bit processor"; | |
2943 | case EM_KMX32: return "KM211 KMX32 32-bit processor"; | |
2944 | case EM_KMX16: return "KM211 KMX16 16-bit processor"; | |
2945 | case EM_KMX8: return "KM211 KMX8 8-bit processor"; | |
2946 | case EM_KVARC: return "KM211 KVARC processor"; | |
2947 | case EM_CDP: return "Paneve CDP architecture family"; | |
2948 | case EM_COGE: return "Cognitive Smart Memory Processor"; | |
2949 | case EM_COOL: return "Bluechip Systems CoolEngine"; | |
2950 | case EM_NORC: return "Nanoradio Optimized RISC"; | |
2951 | case EM_CSR_KALIMBA: return "CSR Kalimba architecture family"; | |
2952 | /* 220 */ | |
2953 | case EM_Z80: return "Zilog Z80"; | |
2954 | case EM_VISIUM: return "CDS VISIUMcore processor"; | |
2955 | case EM_FT32: return "FTDI Chip FT32"; | |
2956 | case EM_MOXIE: return "Moxie"; | |
2957 | case EM_AMDGPU: return "AMD GPU"; | |
2958 | /* 230 (all reserved) */ | |
2959 | /* 240 */ | |
2960 | case EM_RISCV: return "RISC-V"; | |
2961 | case EM_LANAI: return "Lanai 32-bit processor"; | |
2962 | case EM_CEVA: return "CEVA Processor Architecture Family"; | |
2963 | case EM_CEVA_X2: return "CEVA X2 Processor Family"; | |
2964 | case EM_BPF: return "Linux BPF"; | |
2965 | case EM_GRAPHCORE_IPU: return "Graphcore Intelligent Processing Unit"; | |
2966 | case EM_IMG1: return "Imagination Technologies"; | |
2967 | /* 250 */ | |
2968 | case EM_NFP: return "Netronome Flow Processor"; | |
2969 | case EM_VE: return "NEC Vector Engine"; | |
2970 | case EM_CSKY: return "C-SKY"; | |
2971 | case EM_ARC_COMPACT3_64: return "Synopsys ARCv2.3 64-bit"; | |
2972 | case EM_MCS6502: return "MOS Technology MCS 6502 processor"; | |
2973 | case EM_ARC_COMPACT3: return "Synopsys ARCv2.3 32-bit"; | |
2974 | case EM_KVX: return "Kalray VLIW core of the MPPA processor family"; | |
2975 | case EM_65816: return "WDC 65816/65C816"; | |
2976 | case EM_LOONGARCH: return "LoongArch"; | |
2977 | case EM_KF32: return "ChipON KungFu32"; | |
2978 | ||
2979 | /* Large numbers... */ | |
2980 | case EM_MT: return "Morpho Techologies MT processor"; | |
2981 | case EM_ALPHA: return "Alpha"; | |
2982 | case EM_WEBASSEMBLY: return "Web Assembly"; | |
2983 | case EM_DLX: return "OpenDLX"; | |
2984 | case EM_XSTORMY16: return "Sanyo XStormy16 CPU core"; | |
2985 | case EM_IQ2000: return "Vitesse IQ2000"; | |
2986 | case EM_M32C_OLD: | |
2987 | case EM_NIOS32: return "Altera Nios"; | |
2988 | case EM_CYGNUS_MEP: return "Toshiba MeP Media Engine"; | |
2989 | case EM_ADAPTEVA_EPIPHANY: return "Adapteva EPIPHANY"; | |
2990 | case EM_CYGNUS_FRV: return "Fujitsu FR-V"; | |
2991 | case EM_S12Z: return "Freescale S12Z"; | |
2992 | ||
2993 | default: | |
2994 | snprintf (buff, sizeof (buff), _("<unknown>: 0x%x"), e_machine); | |
2995 | return buff; | |
2996 | } | |
2997 | } | |
2998 | ||
2999 | static void | |
3000 | decode_ARC_machine_flags (unsigned e_flags, unsigned e_machine, char buf[]) | |
3001 | { | |
3002 | /* ARC has two machine types EM_ARC_COMPACT and EM_ARC_COMPACT2. Some | |
3003 | other compilers don't specify an architecture type in the e_flags, and | |
3004 | instead use EM_ARC_COMPACT for old ARC600, ARC601, and ARC700 | |
3005 | architectures, and switch to EM_ARC_COMPACT2 for newer ARCEM and ARCHS | |
3006 | architectures. | |
3007 | ||
3008 | Th GNU tools follows this use of EM_ARC_COMPACT and EM_ARC_COMPACT2, | |
3009 | but also sets a specific architecture type in the e_flags field. | |
3010 | ||
3011 | However, when decoding the flags we don't worry if we see an | |
3012 | unexpected pairing, for example EM_ARC_COMPACT machine type, with | |
3013 | ARCEM architecture type. */ | |
3014 | ||
3015 | switch (e_flags & EF_ARC_MACH_MSK) | |
3016 | { | |
3017 | /* We only expect these to occur for EM_ARC_COMPACT2. */ | |
3018 | case EF_ARC_CPU_ARCV2EM: | |
3019 | strcat (buf, ", ARC EM"); | |
3020 | break; | |
3021 | case EF_ARC_CPU_ARCV2HS: | |
3022 | strcat (buf, ", ARC HS"); | |
3023 | break; | |
3024 | ||
3025 | /* We only expect these to occur for EM_ARC_COMPACT. */ | |
3026 | case E_ARC_MACH_ARC600: | |
3027 | strcat (buf, ", ARC600"); | |
3028 | break; | |
3029 | case E_ARC_MACH_ARC601: | |
3030 | strcat (buf, ", ARC601"); | |
3031 | break; | |
3032 | case E_ARC_MACH_ARC700: | |
3033 | strcat (buf, ", ARC700"); | |
3034 | break; | |
3035 | ||
3036 | /* The only times we should end up here are (a) A corrupt ELF, (b) A | |
3037 | new ELF with new architecture being read by an old version of | |
3038 | readelf, or (c) An ELF built with non-GNU compiler that does not | |
3039 | set the architecture in the e_flags. */ | |
3040 | default: | |
3041 | if (e_machine == EM_ARC_COMPACT) | |
3042 | strcat (buf, ", Unknown ARCompact"); | |
3043 | else | |
3044 | strcat (buf, ", Unknown ARC"); | |
3045 | break; | |
3046 | } | |
3047 | ||
3048 | switch (e_flags & EF_ARC_OSABI_MSK) | |
3049 | { | |
3050 | case E_ARC_OSABI_ORIG: | |
3051 | strcat (buf, ", (ABI:legacy)"); | |
3052 | break; | |
3053 | case E_ARC_OSABI_V2: | |
3054 | strcat (buf, ", (ABI:v2)"); | |
3055 | break; | |
3056 | /* Only upstream 3.9+ kernels will support ARCv2 ISA. */ | |
3057 | case E_ARC_OSABI_V3: | |
3058 | strcat (buf, ", v3 no-legacy-syscalls ABI"); | |
3059 | break; | |
3060 | case E_ARC_OSABI_V4: | |
3061 | strcat (buf, ", v4 ABI"); | |
3062 | break; | |
3063 | default: | |
3064 | strcat (buf, ", unrecognised ARC OSABI flag"); | |
3065 | break; | |
3066 | } | |
3067 | } | |
3068 | ||
3069 | static void | |
3070 | decode_ARM_machine_flags (unsigned e_flags, char buf[]) | |
3071 | { | |
3072 | unsigned eabi; | |
3073 | bool unknown = false; | |
3074 | ||
3075 | eabi = EF_ARM_EABI_VERSION (e_flags); | |
3076 | e_flags &= ~ EF_ARM_EABIMASK; | |
3077 | ||
3078 | /* Handle "generic" ARM flags. */ | |
3079 | if (e_flags & EF_ARM_RELEXEC) | |
3080 | { | |
3081 | strcat (buf, ", relocatable executable"); | |
3082 | e_flags &= ~ EF_ARM_RELEXEC; | |
3083 | } | |
3084 | ||
3085 | if (e_flags & EF_ARM_PIC) | |
3086 | { | |
3087 | strcat (buf, ", position independent"); | |
3088 | e_flags &= ~ EF_ARM_PIC; | |
3089 | } | |
3090 | ||
3091 | /* Now handle EABI specific flags. */ | |
3092 | switch (eabi) | |
3093 | { | |
3094 | default: | |
3095 | strcat (buf, ", <unrecognized EABI>"); | |
3096 | if (e_flags) | |
3097 | unknown = true; | |
3098 | break; | |
3099 | ||
3100 | case EF_ARM_EABI_VER1: | |
3101 | strcat (buf, ", Version1 EABI"); | |
3102 | while (e_flags) | |
3103 | { | |
3104 | unsigned flag; | |
3105 | ||
3106 | /* Process flags one bit at a time. */ | |
3107 | flag = e_flags & - e_flags; | |
3108 | e_flags &= ~ flag; | |
3109 | ||
3110 | switch (flag) | |
3111 | { | |
3112 | case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK. */ | |
3113 | strcat (buf, ", sorted symbol tables"); | |
3114 | break; | |
3115 | ||
3116 | default: | |
3117 | unknown = true; | |
3118 | break; | |
3119 | } | |
3120 | } | |
3121 | break; | |
3122 | ||
3123 | case EF_ARM_EABI_VER2: | |
3124 | strcat (buf, ", Version2 EABI"); | |
3125 | while (e_flags) | |
3126 | { | |
3127 | unsigned flag; | |
3128 | ||
3129 | /* Process flags one bit at a time. */ | |
3130 | flag = e_flags & - e_flags; | |
3131 | e_flags &= ~ flag; | |
3132 | ||
3133 | switch (flag) | |
3134 | { | |
3135 | case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK. */ | |
3136 | strcat (buf, ", sorted symbol tables"); | |
3137 | break; | |
3138 | ||
3139 | case EF_ARM_DYNSYMSUSESEGIDX: | |
3140 | strcat (buf, ", dynamic symbols use segment index"); | |
3141 | break; | |
3142 | ||
3143 | case EF_ARM_MAPSYMSFIRST: | |
3144 | strcat (buf, ", mapping symbols precede others"); | |
3145 | break; | |
3146 | ||
3147 | default: | |
3148 | unknown = true; | |
3149 | break; | |
3150 | } | |
3151 | } | |
3152 | break; | |
3153 | ||
3154 | case EF_ARM_EABI_VER3: | |
3155 | strcat (buf, ", Version3 EABI"); | |
3156 | break; | |
3157 | ||
3158 | case EF_ARM_EABI_VER4: | |
3159 | strcat (buf, ", Version4 EABI"); | |
3160 | while (e_flags) | |
3161 | { | |
3162 | unsigned flag; | |
3163 | ||
3164 | /* Process flags one bit at a time. */ | |
3165 | flag = e_flags & - e_flags; | |
3166 | e_flags &= ~ flag; | |
3167 | ||
3168 | switch (flag) | |
3169 | { | |
3170 | case EF_ARM_BE8: | |
3171 | strcat (buf, ", BE8"); | |
3172 | break; | |
3173 | ||
3174 | case EF_ARM_LE8: | |
3175 | strcat (buf, ", LE8"); | |
3176 | break; | |
3177 | ||
3178 | default: | |
3179 | unknown = true; | |
3180 | break; | |
3181 | } | |
3182 | } | |
3183 | break; | |
3184 | ||
3185 | case EF_ARM_EABI_VER5: | |
3186 | strcat (buf, ", Version5 EABI"); | |
3187 | while (e_flags) | |
3188 | { | |
3189 | unsigned flag; | |
3190 | ||
3191 | /* Process flags one bit at a time. */ | |
3192 | flag = e_flags & - e_flags; | |
3193 | e_flags &= ~ flag; | |
3194 | ||
3195 | switch (flag) | |
3196 | { | |
3197 | case EF_ARM_BE8: | |
3198 | strcat (buf, ", BE8"); | |
3199 | break; | |
3200 | ||
3201 | case EF_ARM_LE8: | |
3202 | strcat (buf, ", LE8"); | |
3203 | break; | |
3204 | ||
3205 | case EF_ARM_ABI_FLOAT_SOFT: /* Conflicts with EF_ARM_SOFT_FLOAT. */ | |
3206 | strcat (buf, ", soft-float ABI"); | |
3207 | break; | |
3208 | ||
3209 | case EF_ARM_ABI_FLOAT_HARD: /* Conflicts with EF_ARM_VFP_FLOAT. */ | |
3210 | strcat (buf, ", hard-float ABI"); | |
3211 | break; | |
3212 | ||
3213 | default: | |
3214 | unknown = true; | |
3215 | break; | |
3216 | } | |
3217 | } | |
3218 | break; | |
3219 | ||
3220 | case EF_ARM_EABI_UNKNOWN: | |
3221 | strcat (buf, ", GNU EABI"); | |
3222 | while (e_flags) | |
3223 | { | |
3224 | unsigned flag; | |
3225 | ||
3226 | /* Process flags one bit at a time. */ | |
3227 | flag = e_flags & - e_flags; | |
3228 | e_flags &= ~ flag; | |
3229 | ||
3230 | switch (flag) | |
3231 | { | |
3232 | case EF_ARM_INTERWORK: | |
3233 | strcat (buf, ", interworking enabled"); | |
3234 | break; | |
3235 | ||
3236 | case EF_ARM_APCS_26: | |
3237 | strcat (buf, ", uses APCS/26"); | |
3238 | break; | |
3239 | ||
3240 | case EF_ARM_APCS_FLOAT: | |
3241 | strcat (buf, ", uses APCS/float"); | |
3242 | break; | |
3243 | ||
3244 | case EF_ARM_PIC: | |
3245 | strcat (buf, ", position independent"); | |
3246 | break; | |
3247 | ||
3248 | case EF_ARM_ALIGN8: | |
3249 | strcat (buf, ", 8 bit structure alignment"); | |
3250 | break; | |
3251 | ||
3252 | case EF_ARM_NEW_ABI: | |
3253 | strcat (buf, ", uses new ABI"); | |
3254 | break; | |
3255 | ||
3256 | case EF_ARM_OLD_ABI: | |
3257 | strcat (buf, ", uses old ABI"); | |
3258 | break; | |
3259 | ||
3260 | case EF_ARM_SOFT_FLOAT: | |
3261 | strcat (buf, ", software FP"); | |
3262 | break; | |
3263 | ||
3264 | case EF_ARM_VFP_FLOAT: | |
3265 | strcat (buf, ", VFP"); | |
3266 | break; | |
3267 | ||
3268 | case EF_ARM_MAVERICK_FLOAT: | |
3269 | strcat (buf, ", Maverick FP"); | |
3270 | break; | |
3271 | ||
3272 | default: | |
3273 | unknown = true; | |
3274 | break; | |
3275 | } | |
3276 | } | |
3277 | } | |
3278 | ||
3279 | if (unknown) | |
3280 | strcat (buf,_(", <unknown>")); | |
3281 | } | |
3282 | ||
3283 | static void | |
3284 | decode_AVR_machine_flags (unsigned e_flags, char buf[], size_t size) | |
3285 | { | |
3286 | --size; /* Leave space for null terminator. */ | |
3287 | ||
3288 | switch (e_flags & EF_AVR_MACH) | |
3289 | { | |
3290 | case E_AVR_MACH_AVR1: | |
3291 | strncat (buf, ", avr:1", size); | |
3292 | break; | |
3293 | case E_AVR_MACH_AVR2: | |
3294 | strncat (buf, ", avr:2", size); | |
3295 | break; | |
3296 | case E_AVR_MACH_AVR25: | |
3297 | strncat (buf, ", avr:25", size); | |
3298 | break; | |
3299 | case E_AVR_MACH_AVR3: | |
3300 | strncat (buf, ", avr:3", size); | |
3301 | break; | |
3302 | case E_AVR_MACH_AVR31: | |
3303 | strncat (buf, ", avr:31", size); | |
3304 | break; | |
3305 | case E_AVR_MACH_AVR35: | |
3306 | strncat (buf, ", avr:35", size); | |
3307 | break; | |
3308 | case E_AVR_MACH_AVR4: | |
3309 | strncat (buf, ", avr:4", size); | |
3310 | break; | |
3311 | case E_AVR_MACH_AVR5: | |
3312 | strncat (buf, ", avr:5", size); | |
3313 | break; | |
3314 | case E_AVR_MACH_AVR51: | |
3315 | strncat (buf, ", avr:51", size); | |
3316 | break; | |
3317 | case E_AVR_MACH_AVR6: | |
3318 | strncat (buf, ", avr:6", size); | |
3319 | break; | |
3320 | case E_AVR_MACH_AVRTINY: | |
3321 | strncat (buf, ", avr:100", size); | |
3322 | break; | |
3323 | case E_AVR_MACH_XMEGA1: | |
3324 | strncat (buf, ", avr:101", size); | |
3325 | break; | |
3326 | case E_AVR_MACH_XMEGA2: | |
3327 | strncat (buf, ", avr:102", size); | |
3328 | break; | |
3329 | case E_AVR_MACH_XMEGA3: | |
3330 | strncat (buf, ", avr:103", size); | |
3331 | break; | |
3332 | case E_AVR_MACH_XMEGA4: | |
3333 | strncat (buf, ", avr:104", size); | |
3334 | break; | |
3335 | case E_AVR_MACH_XMEGA5: | |
3336 | strncat (buf, ", avr:105", size); | |
3337 | break; | |
3338 | case E_AVR_MACH_XMEGA6: | |
3339 | strncat (buf, ", avr:106", size); | |
3340 | break; | |
3341 | case E_AVR_MACH_XMEGA7: | |
3342 | strncat (buf, ", avr:107", size); | |
3343 | break; | |
3344 | default: | |
3345 | strncat (buf, ", avr:<unknown>", size); | |
3346 | break; | |
3347 | } | |
3348 | ||
3349 | size -= strlen (buf); | |
3350 | if (e_flags & EF_AVR_LINKRELAX_PREPARED) | |
3351 | strncat (buf, ", link-relax", size); | |
3352 | } | |
3353 | ||
3354 | static void | |
3355 | decode_NDS32_machine_flags (unsigned e_flags, char buf[], size_t size) | |
3356 | { | |
3357 | unsigned abi; | |
3358 | unsigned arch; | |
3359 | unsigned config; | |
3360 | unsigned version; | |
3361 | bool has_fpu = false; | |
3362 | unsigned int r = 0; | |
3363 | ||
3364 | static const char *ABI_STRINGS[] = | |
3365 | { | |
3366 | "ABI v0", /* use r5 as return register; only used in N1213HC */ | |
3367 | "ABI v1", /* use r0 as return register */ | |
3368 | "ABI v2", /* use r0 as return register and don't reserve 24 bytes for arguments */ | |
3369 | "ABI v2fp", /* for FPU */ | |
3370 | "AABI", | |
3371 | "ABI2 FP+" | |
3372 | }; | |
3373 | static const char *VER_STRINGS[] = | |
3374 | { | |
3375 | "Andes ELF V1.3 or older", | |
3376 | "Andes ELF V1.3.1", | |
3377 | "Andes ELF V1.4" | |
3378 | }; | |
3379 | static const char *ARCH_STRINGS[] = | |
3380 | { | |
3381 | "", | |
3382 | "Andes Star v1.0", | |
3383 | "Andes Star v2.0", | |
3384 | "Andes Star v3.0", | |
3385 | "Andes Star v3.0m" | |
3386 | }; | |
3387 | ||
3388 | abi = EF_NDS_ABI & e_flags; | |
3389 | arch = EF_NDS_ARCH & e_flags; | |
3390 | config = EF_NDS_INST & e_flags; | |
3391 | version = EF_NDS32_ELF_VERSION & e_flags; | |
3392 | ||
3393 | memset (buf, 0, size); | |
3394 | ||
3395 | switch (abi) | |
3396 | { | |
3397 | case E_NDS_ABI_V0: | |
3398 | case E_NDS_ABI_V1: | |
3399 | case E_NDS_ABI_V2: | |
3400 | case E_NDS_ABI_V2FP: | |
3401 | case E_NDS_ABI_AABI: | |
3402 | case E_NDS_ABI_V2FP_PLUS: | |
3403 | /* In case there are holes in the array. */ | |
3404 | r += snprintf (buf + r, size - r, ", %s", ABI_STRINGS[abi >> EF_NDS_ABI_SHIFT]); | |
3405 | break; | |
3406 | ||
3407 | default: | |
3408 | r += snprintf (buf + r, size - r, ", <unrecognized ABI>"); | |
3409 | break; | |
3410 | } | |
3411 | ||
3412 | switch (version) | |
3413 | { | |
3414 | case E_NDS32_ELF_VER_1_2: | |
3415 | case E_NDS32_ELF_VER_1_3: | |
3416 | case E_NDS32_ELF_VER_1_4: | |
3417 | r += snprintf (buf + r, size - r, ", %s", VER_STRINGS[version >> EF_NDS32_ELF_VERSION_SHIFT]); | |
3418 | break; | |
3419 | ||
3420 | default: | |
3421 | r += snprintf (buf + r, size - r, ", <unrecognized ELF version number>"); | |
3422 | break; | |
3423 | } | |
3424 | ||
3425 | if (E_NDS_ABI_V0 == abi) | |
3426 | { | |
3427 | /* OLD ABI; only used in N1213HC, has performance extension 1. */ | |
3428 | r += snprintf (buf + r, size - r, ", Andes Star v1.0, N1213HC, MAC, PERF1"); | |
3429 | if (arch == E_NDS_ARCH_STAR_V1_0) | |
3430 | r += snprintf (buf + r, size -r, ", 16b"); /* has 16-bit instructions */ | |
3431 | return; | |
3432 | } | |
3433 | ||
3434 | switch (arch) | |
3435 | { | |
3436 | case E_NDS_ARCH_STAR_V1_0: | |
3437 | case E_NDS_ARCH_STAR_V2_0: | |
3438 | case E_NDS_ARCH_STAR_V3_0: | |
3439 | case E_NDS_ARCH_STAR_V3_M: | |
3440 | r += snprintf (buf + r, size - r, ", %s", ARCH_STRINGS[arch >> EF_NDS_ARCH_SHIFT]); | |
3441 | break; | |
3442 | ||
3443 | default: | |
3444 | r += snprintf (buf + r, size - r, ", <unrecognized architecture>"); | |
3445 | /* ARCH version determines how the e_flags are interpreted. | |
3446 | If it is unknown, we cannot proceed. */ | |
3447 | return; | |
3448 | } | |
3449 | ||
3450 | /* Newer ABI; Now handle architecture specific flags. */ | |
3451 | if (arch == E_NDS_ARCH_STAR_V1_0) | |
3452 | { | |
3453 | if (config & E_NDS32_HAS_MFUSR_PC_INST) | |
3454 | r += snprintf (buf + r, size -r, ", MFUSR_PC"); | |
3455 | ||
3456 | if (!(config & E_NDS32_HAS_NO_MAC_INST)) | |
3457 | r += snprintf (buf + r, size -r, ", MAC"); | |
3458 | ||
3459 | if (config & E_NDS32_HAS_DIV_INST) | |
3460 | r += snprintf (buf + r, size -r, ", DIV"); | |
3461 | ||
3462 | if (config & E_NDS32_HAS_16BIT_INST) | |
3463 | r += snprintf (buf + r, size -r, ", 16b"); | |
3464 | } | |
3465 | else | |
3466 | { | |
3467 | if (config & E_NDS32_HAS_MFUSR_PC_INST) | |
3468 | { | |
3469 | if (version <= E_NDS32_ELF_VER_1_3) | |
3470 | r += snprintf (buf + r, size -r, ", [B8]"); | |
3471 | else | |
3472 | r += snprintf (buf + r, size -r, ", EX9"); | |
3473 | } | |
3474 | ||
3475 | if (config & E_NDS32_HAS_MAC_DX_INST) | |
3476 | r += snprintf (buf + r, size -r, ", MAC_DX"); | |
3477 | ||
3478 | if (config & E_NDS32_HAS_DIV_DX_INST) | |
3479 | r += snprintf (buf + r, size -r, ", DIV_DX"); | |
3480 | ||
3481 | if (config & E_NDS32_HAS_16BIT_INST) | |
3482 | { | |
3483 | if (version <= E_NDS32_ELF_VER_1_3) | |
3484 | r += snprintf (buf + r, size -r, ", 16b"); | |
3485 | else | |
3486 | r += snprintf (buf + r, size -r, ", IFC"); | |
3487 | } | |
3488 | } | |
3489 | ||
3490 | if (config & E_NDS32_HAS_EXT_INST) | |
3491 | r += snprintf (buf + r, size -r, ", PERF1"); | |
3492 | ||
3493 | if (config & E_NDS32_HAS_EXT2_INST) | |
3494 | r += snprintf (buf + r, size -r, ", PERF2"); | |
3495 | ||
3496 | if (config & E_NDS32_HAS_FPU_INST) | |
3497 | { | |
3498 | has_fpu = true; | |
3499 | r += snprintf (buf + r, size -r, ", FPU_SP"); | |
3500 | } | |
3501 | ||
3502 | if (config & E_NDS32_HAS_FPU_DP_INST) | |
3503 | { | |
3504 | has_fpu = true; | |
3505 | r += snprintf (buf + r, size -r, ", FPU_DP"); | |
3506 | } | |
3507 | ||
3508 | if (config & E_NDS32_HAS_FPU_MAC_INST) | |
3509 | { | |
3510 | has_fpu = true; | |
3511 | r += snprintf (buf + r, size -r, ", FPU_MAC"); | |
3512 | } | |
3513 | ||
3514 | if (has_fpu) | |
3515 | { | |
3516 | switch ((config & E_NDS32_FPU_REG_CONF) >> E_NDS32_FPU_REG_CONF_SHIFT) | |
3517 | { | |
3518 | case E_NDS32_FPU_REG_8SP_4DP: | |
3519 | r += snprintf (buf + r, size -r, ", FPU_REG:8/4"); | |
3520 | break; | |
3521 | case E_NDS32_FPU_REG_16SP_8DP: | |
3522 | r += snprintf (buf + r, size -r, ", FPU_REG:16/8"); | |
3523 | break; | |
3524 | case E_NDS32_FPU_REG_32SP_16DP: | |
3525 | r += snprintf (buf + r, size -r, ", FPU_REG:32/16"); | |
3526 | break; | |
3527 | case E_NDS32_FPU_REG_32SP_32DP: | |
3528 | r += snprintf (buf + r, size -r, ", FPU_REG:32/32"); | |
3529 | break; | |
3530 | } | |
3531 | } | |
3532 | ||
3533 | if (config & E_NDS32_HAS_AUDIO_INST) | |
3534 | r += snprintf (buf + r, size -r, ", AUDIO"); | |
3535 | ||
3536 | if (config & E_NDS32_HAS_STRING_INST) | |
3537 | r += snprintf (buf + r, size -r, ", STR"); | |
3538 | ||
3539 | if (config & E_NDS32_HAS_REDUCED_REGS) | |
3540 | r += snprintf (buf + r, size -r, ", 16REG"); | |
3541 | ||
3542 | if (config & E_NDS32_HAS_VIDEO_INST) | |
3543 | { | |
3544 | if (version <= E_NDS32_ELF_VER_1_3) | |
3545 | r += snprintf (buf + r, size -r, ", VIDEO"); | |
3546 | else | |
3547 | r += snprintf (buf + r, size -r, ", SATURATION"); | |
3548 | } | |
3549 | ||
3550 | if (config & E_NDS32_HAS_ENCRIPT_INST) | |
3551 | r += snprintf (buf + r, size -r, ", ENCRP"); | |
3552 | ||
3553 | if (config & E_NDS32_HAS_L2C_INST) | |
3554 | r += snprintf (buf + r, size -r, ", L2C"); | |
3555 | } | |
3556 | ||
3557 | static void | |
3558 | decode_AMDGPU_machine_flags (Filedata *filedata, unsigned int e_flags, | |
3559 | char *buf) | |
3560 | { | |
3561 | unsigned char *e_ident = filedata->file_header.e_ident; | |
3562 | unsigned char osabi = e_ident[EI_OSABI]; | |
3563 | unsigned char abiversion = e_ident[EI_ABIVERSION]; | |
3564 | unsigned int mach; | |
3565 | ||
3566 | /* HSA OS ABI v2 used a different encoding, but we don't need to support it, | |
3567 | it has been deprecated for a while. | |
3568 | ||
3569 | The PAL, MESA3D and NONE OS ABIs are not properly versioned, at the time | |
3570 | of writing, they use the same flags as HSA v3, so the code below uses that | |
3571 | assumption. */ | |
3572 | if (osabi == ELFOSABI_AMDGPU_HSA && abiversion < ELFABIVERSION_AMDGPU_HSA_V3) | |
3573 | return; | |
3574 | ||
3575 | mach = e_flags & EF_AMDGPU_MACH; | |
3576 | switch (mach) | |
3577 | { | |
3578 | #define AMDGPU_CASE(code, string) \ | |
3579 | case code: strcat (buf, ", " string); break; | |
3580 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX600, "gfx600") | |
3581 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX601, "gfx601") | |
3582 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX700, "gfx700") | |
3583 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX701, "gfx701") | |
3584 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX702, "gfx702") | |
3585 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX703, "gfx703") | |
3586 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX704, "gfx704") | |
3587 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX801, "gfx801") | |
3588 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX802, "gfx802") | |
3589 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX803, "gfx803") | |
3590 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX810, "gfx810") | |
3591 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX900, "gfx900") | |
3592 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX902, "gfx902") | |
3593 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX904, "gfx904") | |
3594 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX906, "gfx906") | |
3595 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX908, "gfx908") | |
3596 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX909, "gfx909") | |
3597 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX90C, "gfx90c") | |
3598 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1010, "gfx1010") | |
3599 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1011, "gfx1011") | |
3600 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1012, "gfx1012") | |
3601 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1030, "gfx1030") | |
3602 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1031, "gfx1031") | |
3603 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1032, "gfx1032") | |
3604 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1033, "gfx1033") | |
3605 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX602, "gfx602") | |
3606 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX705, "gfx705") | |
3607 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX805, "gfx805") | |
3608 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1035, "gfx1035") | |
3609 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1034, "gfx1034") | |
3610 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX90A, "gfx90a") | |
3611 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX940, "gfx940") | |
3612 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1013, "gfx1013") | |
3613 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1036, "gfx1036") | |
3614 | default: | |
3615 | sprintf (buf, _(", <unknown AMDGPU GPU type: %#x>"), mach); | |
3616 | break; | |
3617 | #undef AMDGPU_CASE | |
3618 | } | |
3619 | ||
3620 | buf += strlen (buf); | |
3621 | e_flags &= ~EF_AMDGPU_MACH; | |
3622 | ||
3623 | if ((osabi == ELFOSABI_AMDGPU_HSA | |
3624 | && abiversion == ELFABIVERSION_AMDGPU_HSA_V3) | |
3625 | || osabi != ELFOSABI_AMDGPU_HSA) | |
3626 | { | |
3627 | /* For HSA v3 and other OS ABIs. */ | |
3628 | if (e_flags & EF_AMDGPU_FEATURE_XNACK_V3) | |
3629 | { | |
3630 | strcat (buf, ", xnack on"); | |
3631 | buf += strlen (buf); | |
3632 | e_flags &= ~EF_AMDGPU_FEATURE_XNACK_V3; | |
3633 | } | |
3634 | ||
3635 | if (e_flags & EF_AMDGPU_FEATURE_SRAMECC_V3) | |
3636 | { | |
3637 | strcat (buf, ", sramecc on"); | |
3638 | buf += strlen (buf); | |
3639 | e_flags &= ~EF_AMDGPU_FEATURE_SRAMECC_V3; | |
3640 | } | |
3641 | } | |
3642 | else | |
3643 | { | |
3644 | /* For HSA v4+. */ | |
3645 | int xnack, sramecc; | |
3646 | ||
3647 | xnack = e_flags & EF_AMDGPU_FEATURE_XNACK_V4; | |
3648 | switch (xnack) | |
3649 | { | |
3650 | case EF_AMDGPU_FEATURE_XNACK_UNSUPPORTED_V4: | |
3651 | break; | |
3652 | ||
3653 | case EF_AMDGPU_FEATURE_XNACK_ANY_V4: | |
3654 | strcat (buf, ", xnack any"); | |
3655 | break; | |
3656 | ||
3657 | case EF_AMDGPU_FEATURE_XNACK_OFF_V4: | |
3658 | strcat (buf, ", xnack off"); | |
3659 | break; | |
3660 | ||
3661 | case EF_AMDGPU_FEATURE_XNACK_ON_V4: | |
3662 | strcat (buf, ", xnack on"); | |
3663 | break; | |
3664 | ||
3665 | default: | |
3666 | sprintf (buf, _(", <unknown xnack value: %#x>"), xnack); | |
3667 | break; | |
3668 | } | |
3669 | ||
3670 | buf += strlen (buf); | |
3671 | e_flags &= ~EF_AMDGPU_FEATURE_XNACK_V4; | |
3672 | ||
3673 | sramecc = e_flags & EF_AMDGPU_FEATURE_SRAMECC_V4; | |
3674 | switch (sramecc) | |
3675 | { | |
3676 | case EF_AMDGPU_FEATURE_SRAMECC_UNSUPPORTED_V4: | |
3677 | break; | |
3678 | ||
3679 | case EF_AMDGPU_FEATURE_SRAMECC_ANY_V4: | |
3680 | strcat (buf, ", sramecc any"); | |
3681 | break; | |
3682 | ||
3683 | case EF_AMDGPU_FEATURE_SRAMECC_OFF_V4: | |
3684 | strcat (buf, ", sramecc off"); | |
3685 | break; | |
3686 | ||
3687 | case EF_AMDGPU_FEATURE_SRAMECC_ON_V4: | |
3688 | strcat (buf, ", sramecc on"); | |
3689 | break; | |
3690 | ||
3691 | default: | |
3692 | sprintf (buf, _(", <unknown sramecc value: %#x>"), sramecc); | |
3693 | break; | |
3694 | } | |
3695 | ||
3696 | buf += strlen (buf); | |
3697 | e_flags &= ~EF_AMDGPU_FEATURE_SRAMECC_V4; | |
3698 | } | |
3699 | ||
3700 | if (e_flags != 0) | |
3701 | sprintf (buf, _(", unknown flags bits: %#x"), e_flags); | |
3702 | } | |
3703 | ||
3704 | static char * | |
3705 | get_machine_flags (Filedata * filedata, unsigned e_flags, unsigned e_machine) | |
3706 | { | |
3707 | static char buf[1024]; | |
3708 | ||
3709 | buf[0] = '\0'; | |
3710 | ||
3711 | if (e_flags) | |
3712 | { | |
3713 | switch (e_machine) | |
3714 | { | |
3715 | default: | |
3716 | break; | |
3717 | ||
3718 | case EM_ARC_COMPACT2: | |
3719 | case EM_ARC_COMPACT: | |
3720 | decode_ARC_machine_flags (e_flags, e_machine, buf); | |
3721 | break; | |
3722 | ||
3723 | case EM_ARM: | |
3724 | decode_ARM_machine_flags (e_flags, buf); | |
3725 | break; | |
3726 | ||
3727 | case EM_AVR: | |
3728 | decode_AVR_machine_flags (e_flags, buf, sizeof buf); | |
3729 | break; | |
3730 | ||
3731 | case EM_BLACKFIN: | |
3732 | if (e_flags & EF_BFIN_PIC) | |
3733 | strcat (buf, ", PIC"); | |
3734 | ||
3735 | if (e_flags & EF_BFIN_FDPIC) | |
3736 | strcat (buf, ", FDPIC"); | |
3737 | ||
3738 | if (e_flags & EF_BFIN_CODE_IN_L1) | |
3739 | strcat (buf, ", code in L1"); | |
3740 | ||
3741 | if (e_flags & EF_BFIN_DATA_IN_L1) | |
3742 | strcat (buf, ", data in L1"); | |
3743 | ||
3744 | break; | |
3745 | ||
3746 | case EM_CYGNUS_FRV: | |
3747 | switch (e_flags & EF_FRV_CPU_MASK) | |
3748 | { | |
3749 | case EF_FRV_CPU_GENERIC: | |
3750 | break; | |
3751 | ||
3752 | default: | |
3753 | strcat (buf, ", fr???"); | |
3754 | break; | |
3755 | ||
3756 | case EF_FRV_CPU_FR300: | |
3757 | strcat (buf, ", fr300"); | |
3758 | break; | |
3759 | ||
3760 | case EF_FRV_CPU_FR400: | |
3761 | strcat (buf, ", fr400"); | |
3762 | break; | |
3763 | case EF_FRV_CPU_FR405: | |
3764 | strcat (buf, ", fr405"); | |
3765 | break; | |
3766 | ||
3767 | case EF_FRV_CPU_FR450: | |
3768 | strcat (buf, ", fr450"); | |
3769 | break; | |
3770 | ||
3771 | case EF_FRV_CPU_FR500: | |
3772 | strcat (buf, ", fr500"); | |
3773 | break; | |
3774 | case EF_FRV_CPU_FR550: | |
3775 | strcat (buf, ", fr550"); | |
3776 | break; | |
3777 | ||
3778 | case EF_FRV_CPU_SIMPLE: | |
3779 | strcat (buf, ", simple"); | |
3780 | break; | |
3781 | case EF_FRV_CPU_TOMCAT: | |
3782 | strcat (buf, ", tomcat"); | |
3783 | break; | |
3784 | } | |
3785 | break; | |
3786 | ||
3787 | case EM_68K: | |
3788 | if ((e_flags & EF_M68K_ARCH_MASK) == EF_M68K_M68000) | |
3789 | strcat (buf, ", m68000"); | |
3790 | else if ((e_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32) | |
3791 | strcat (buf, ", cpu32"); | |
3792 | else if ((e_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO) | |
3793 | strcat (buf, ", fido_a"); | |
3794 | else | |
3795 | { | |
3796 | char const * isa = _("unknown"); | |
3797 | char const * mac = _("unknown mac"); | |
3798 | char const * additional = NULL; | |
3799 | ||
3800 | switch (e_flags & EF_M68K_CF_ISA_MASK) | |
3801 | { | |
3802 | case EF_M68K_CF_ISA_A_NODIV: | |
3803 | isa = "A"; | |
3804 | additional = ", nodiv"; | |
3805 | break; | |
3806 | case EF_M68K_CF_ISA_A: | |
3807 | isa = "A"; | |
3808 | break; | |
3809 | case EF_M68K_CF_ISA_A_PLUS: | |
3810 | isa = "A+"; | |
3811 | break; | |
3812 | case EF_M68K_CF_ISA_B_NOUSP: | |
3813 | isa = "B"; | |
3814 | additional = ", nousp"; | |
3815 | break; | |
3816 | case EF_M68K_CF_ISA_B: | |
3817 | isa = "B"; | |
3818 | break; | |
3819 | case EF_M68K_CF_ISA_C: | |
3820 | isa = "C"; | |
3821 | break; | |
3822 | case EF_M68K_CF_ISA_C_NODIV: | |
3823 | isa = "C"; | |
3824 | additional = ", nodiv"; | |
3825 | break; | |
3826 | } | |
3827 | strcat (buf, ", cf, isa "); | |
3828 | strcat (buf, isa); | |
3829 | if (additional) | |
3830 | strcat (buf, additional); | |
3831 | if (e_flags & EF_M68K_CF_FLOAT) | |
3832 | strcat (buf, ", float"); | |
3833 | switch (e_flags & EF_M68K_CF_MAC_MASK) | |
3834 | { | |
3835 | case 0: | |
3836 | mac = NULL; | |
3837 | break; | |
3838 | case EF_M68K_CF_MAC: | |
3839 | mac = "mac"; | |
3840 | break; | |
3841 | case EF_M68K_CF_EMAC: | |
3842 | mac = "emac"; | |
3843 | break; | |
3844 | case EF_M68K_CF_EMAC_B: | |
3845 | mac = "emac_b"; | |
3846 | break; | |
3847 | } | |
3848 | if (mac) | |
3849 | { | |
3850 | strcat (buf, ", "); | |
3851 | strcat (buf, mac); | |
3852 | } | |
3853 | } | |
3854 | break; | |
3855 | ||
3856 | case EM_AMDGPU: | |
3857 | decode_AMDGPU_machine_flags (filedata, e_flags, buf); | |
3858 | break; | |
3859 | ||
3860 | case EM_CYGNUS_MEP: | |
3861 | switch (e_flags & EF_MEP_CPU_MASK) | |
3862 | { | |
3863 | case EF_MEP_CPU_MEP: strcat (buf, ", generic MeP"); break; | |
3864 | case EF_MEP_CPU_C2: strcat (buf, ", MeP C2"); break; | |
3865 | case EF_MEP_CPU_C3: strcat (buf, ", MeP C3"); break; | |
3866 | case EF_MEP_CPU_C4: strcat (buf, ", MeP C4"); break; | |
3867 | case EF_MEP_CPU_C5: strcat (buf, ", MeP C5"); break; | |
3868 | case EF_MEP_CPU_H1: strcat (buf, ", MeP H1"); break; | |
3869 | default: strcat (buf, _(", <unknown MeP cpu type>")); break; | |
3870 | } | |
3871 | ||
3872 | switch (e_flags & EF_MEP_COP_MASK) | |
3873 | { | |
3874 | case EF_MEP_COP_NONE: break; | |
3875 | case EF_MEP_COP_AVC: strcat (buf, ", AVC coprocessor"); break; | |
3876 | case EF_MEP_COP_AVC2: strcat (buf, ", AVC2 coprocessor"); break; | |
3877 | case EF_MEP_COP_FMAX: strcat (buf, ", FMAX coprocessor"); break; | |
3878 | case EF_MEP_COP_IVC2: strcat (buf, ", IVC2 coprocessor"); break; | |
3879 | default: strcat (buf, _("<unknown MeP copro type>")); break; | |
3880 | } | |
3881 | ||
3882 | if (e_flags & EF_MEP_LIBRARY) | |
3883 | strcat (buf, ", Built for Library"); | |
3884 | ||
3885 | if (e_flags & EF_MEP_INDEX_MASK) | |
3886 | sprintf (buf + strlen (buf), ", Configuration Index: %#x", | |
3887 | e_flags & EF_MEP_INDEX_MASK); | |
3888 | ||
3889 | if (e_flags & ~ EF_MEP_ALL_FLAGS) | |
3890 | sprintf (buf + strlen (buf), _(", unknown flags bits: %#x"), | |
3891 | e_flags & ~ EF_MEP_ALL_FLAGS); | |
3892 | break; | |
3893 | ||
3894 | case EM_PPC: | |
3895 | if (e_flags & EF_PPC_EMB) | |
3896 | strcat (buf, ", emb"); | |
3897 | ||
3898 | if (e_flags & EF_PPC_RELOCATABLE) | |
3899 | strcat (buf, _(", relocatable")); | |
3900 | ||
3901 | if (e_flags & EF_PPC_RELOCATABLE_LIB) | |
3902 | strcat (buf, _(", relocatable-lib")); | |
3903 | break; | |
3904 | ||
3905 | case EM_PPC64: | |
3906 | if (e_flags & EF_PPC64_ABI) | |
3907 | { | |
3908 | char abi[] = ", abiv0"; | |
3909 | ||
3910 | abi[6] += e_flags & EF_PPC64_ABI; | |
3911 | strcat (buf, abi); | |
3912 | } | |
3913 | break; | |
3914 | ||
3915 | case EM_V800: | |
3916 | if ((e_flags & EF_RH850_ABI) == EF_RH850_ABI) | |
3917 | strcat (buf, ", RH850 ABI"); | |
3918 | ||
3919 | if (e_flags & EF_V800_850E3) | |
3920 | strcat (buf, ", V3 architecture"); | |
3921 | ||
3922 | if ((e_flags & (EF_RH850_FPU_DOUBLE | EF_RH850_FPU_SINGLE)) == 0) | |
3923 | strcat (buf, ", FPU not used"); | |
3924 | ||
3925 | if ((e_flags & (EF_RH850_REGMODE22 | EF_RH850_REGMODE32)) == 0) | |
3926 | strcat (buf, ", regmode: COMMON"); | |
3927 | ||
3928 | if ((e_flags & (EF_RH850_GP_FIX | EF_RH850_GP_NOFIX)) == 0) | |
3929 | strcat (buf, ", r4 not used"); | |
3930 | ||
3931 | if ((e_flags & (EF_RH850_EP_FIX | EF_RH850_EP_NOFIX)) == 0) | |
3932 | strcat (buf, ", r30 not used"); | |
3933 | ||
3934 | if ((e_flags & (EF_RH850_TP_FIX | EF_RH850_TP_NOFIX)) == 0) | |
3935 | strcat (buf, ", r5 not used"); | |
3936 | ||
3937 | if ((e_flags & (EF_RH850_REG2_RESERVE | EF_RH850_REG2_NORESERVE)) == 0) | |
3938 | strcat (buf, ", r2 not used"); | |
3939 | ||
3940 | for (e_flags &= 0xFFFF; e_flags; e_flags &= ~ (e_flags & - e_flags)) | |
3941 | { | |
3942 | switch (e_flags & - e_flags) | |
3943 | { | |
3944 | case EF_RH850_FPU_DOUBLE: strcat (buf, ", double precision FPU"); break; | |
3945 | case EF_RH850_FPU_SINGLE: strcat (buf, ", single precision FPU"); break; | |
3946 | case EF_RH850_REGMODE22: strcat (buf, ", regmode:22"); break; | |
3947 | case EF_RH850_REGMODE32: strcat (buf, ", regmode:23"); break; | |
3948 | case EF_RH850_GP_FIX: strcat (buf, ", r4 fixed"); break; | |
3949 | case EF_RH850_GP_NOFIX: strcat (buf, ", r4 free"); break; | |
3950 | case EF_RH850_EP_FIX: strcat (buf, ", r30 fixed"); break; | |
3951 | case EF_RH850_EP_NOFIX: strcat (buf, ", r30 free"); break; | |
3952 | case EF_RH850_TP_FIX: strcat (buf, ", r5 fixed"); break; | |
3953 | case EF_RH850_TP_NOFIX: strcat (buf, ", r5 free"); break; | |
3954 | case EF_RH850_REG2_RESERVE: strcat (buf, ", r2 fixed"); break; | |
3955 | case EF_RH850_REG2_NORESERVE: strcat (buf, ", r2 free"); break; | |
3956 | default: break; | |
3957 | } | |
3958 | } | |
3959 | break; | |
3960 | ||
3961 | case EM_V850: | |
3962 | case EM_CYGNUS_V850: | |
3963 | switch (e_flags & EF_V850_ARCH) | |
3964 | { | |
3965 | case E_V850E3V5_ARCH: | |
3966 | strcat (buf, ", v850e3v5"); | |
3967 | break; | |
3968 | case E_V850E2V3_ARCH: | |
3969 | strcat (buf, ", v850e2v3"); | |
3970 | break; | |
3971 | case E_V850E2_ARCH: | |
3972 | strcat (buf, ", v850e2"); | |
3973 | break; | |
3974 | case E_V850E1_ARCH: | |
3975 | strcat (buf, ", v850e1"); | |
3976 | break; | |
3977 | case E_V850E_ARCH: | |
3978 | strcat (buf, ", v850e"); | |
3979 | break; | |
3980 | case E_V850_ARCH: | |
3981 | strcat (buf, ", v850"); | |
3982 | break; | |
3983 | default: | |
3984 | strcat (buf, _(", unknown v850 architecture variant")); | |
3985 | break; | |
3986 | } | |
3987 | break; | |
3988 | ||
3989 | case EM_M32R: | |
3990 | case EM_CYGNUS_M32R: | |
3991 | if ((e_flags & EF_M32R_ARCH) == E_M32R_ARCH) | |
3992 | strcat (buf, ", m32r"); | |
3993 | break; | |
3994 | ||
3995 | case EM_MIPS: | |
3996 | case EM_MIPS_RS3_LE: | |
3997 | if (e_flags & EF_MIPS_NOREORDER) | |
3998 | strcat (buf, ", noreorder"); | |
3999 | ||
4000 | if (e_flags & EF_MIPS_PIC) | |
4001 | strcat (buf, ", pic"); | |
4002 | ||
4003 | if (e_flags & EF_MIPS_CPIC) | |
4004 | strcat (buf, ", cpic"); | |
4005 | ||
4006 | if (e_flags & EF_MIPS_UCODE) | |
4007 | strcat (buf, ", ugen_reserved"); | |
4008 | ||
4009 | if (e_flags & EF_MIPS_ABI2) | |
4010 | strcat (buf, ", abi2"); | |
4011 | ||
4012 | if (e_flags & EF_MIPS_OPTIONS_FIRST) | |
4013 | strcat (buf, ", odk first"); | |
4014 | ||
4015 | if (e_flags & EF_MIPS_32BITMODE) | |
4016 | strcat (buf, ", 32bitmode"); | |
4017 | ||
4018 | if (e_flags & EF_MIPS_NAN2008) | |
4019 | strcat (buf, ", nan2008"); | |
4020 | ||
4021 | if (e_flags & EF_MIPS_FP64) | |
4022 | strcat (buf, ", fp64"); | |
4023 | ||
4024 | switch ((e_flags & EF_MIPS_MACH)) | |
4025 | { | |
4026 | case E_MIPS_MACH_3900: strcat (buf, ", 3900"); break; | |
4027 | case E_MIPS_MACH_4010: strcat (buf, ", 4010"); break; | |
4028 | case E_MIPS_MACH_4100: strcat (buf, ", 4100"); break; | |
4029 | case E_MIPS_MACH_4111: strcat (buf, ", 4111"); break; | |
4030 | case E_MIPS_MACH_4120: strcat (buf, ", 4120"); break; | |
4031 | case E_MIPS_MACH_4650: strcat (buf, ", 4650"); break; | |
4032 | case E_MIPS_MACH_5400: strcat (buf, ", 5400"); break; | |
4033 | case E_MIPS_MACH_5500: strcat (buf, ", 5500"); break; | |
4034 | case E_MIPS_MACH_5900: strcat (buf, ", 5900"); break; | |
4035 | case E_MIPS_MACH_SB1: strcat (buf, ", sb1"); break; | |
4036 | case E_MIPS_MACH_9000: strcat (buf, ", 9000"); break; | |
4037 | case E_MIPS_MACH_LS2E: strcat (buf, ", loongson-2e"); break; | |
4038 | case E_MIPS_MACH_LS2F: strcat (buf, ", loongson-2f"); break; | |
4039 | case E_MIPS_MACH_GS464: strcat (buf, ", gs464"); break; | |
4040 | case E_MIPS_MACH_GS464E: strcat (buf, ", gs464e"); break; | |
4041 | case E_MIPS_MACH_GS264E: strcat (buf, ", gs264e"); break; | |
4042 | case E_MIPS_MACH_OCTEON: strcat (buf, ", octeon"); break; | |
4043 | case E_MIPS_MACH_OCTEON2: strcat (buf, ", octeon2"); break; | |
4044 | case E_MIPS_MACH_OCTEON3: strcat (buf, ", octeon3"); break; | |
4045 | case E_MIPS_MACH_XLR: strcat (buf, ", xlr"); break; | |
4046 | case E_MIPS_MACH_IAMR2: strcat (buf, ", interaptiv-mr2"); break; | |
4047 | case 0: | |
4048 | /* We simply ignore the field in this case to avoid confusion: | |
4049 | MIPS ELF does not specify EF_MIPS_MACH, it is a GNU | |
4050 | extension. */ | |
4051 | break; | |
4052 | default: strcat (buf, _(", unknown CPU")); break; | |
4053 | } | |
4054 | ||
4055 | switch ((e_flags & EF_MIPS_ABI)) | |
4056 | { | |
4057 | case E_MIPS_ABI_O32: strcat (buf, ", o32"); break; | |
4058 | case E_MIPS_ABI_O64: strcat (buf, ", o64"); break; | |
4059 | case E_MIPS_ABI_EABI32: strcat (buf, ", eabi32"); break; | |
4060 | case E_MIPS_ABI_EABI64: strcat (buf, ", eabi64"); break; | |
4061 | case 0: | |
4062 | /* We simply ignore the field in this case to avoid confusion: | |
4063 | MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension. | |
4064 | This means it is likely to be an o32 file, but not for | |
4065 | sure. */ | |
4066 | break; | |
4067 | default: strcat (buf, _(", unknown ABI")); break; | |
4068 | } | |
4069 | ||
4070 | if (e_flags & EF_MIPS_ARCH_ASE_MDMX) | |
4071 | strcat (buf, ", mdmx"); | |
4072 | ||
4073 | if (e_flags & EF_MIPS_ARCH_ASE_M16) | |
4074 | strcat (buf, ", mips16"); | |
4075 | ||
4076 | if (e_flags & EF_MIPS_ARCH_ASE_MICROMIPS) | |
4077 | strcat (buf, ", micromips"); | |
4078 | ||
4079 | switch ((e_flags & EF_MIPS_ARCH)) | |
4080 | { | |
4081 | case E_MIPS_ARCH_1: strcat (buf, ", mips1"); break; | |
4082 | case E_MIPS_ARCH_2: strcat (buf, ", mips2"); break; | |
4083 | case E_MIPS_ARCH_3: strcat (buf, ", mips3"); break; | |
4084 | case E_MIPS_ARCH_4: strcat (buf, ", mips4"); break; | |
4085 | case E_MIPS_ARCH_5: strcat (buf, ", mips5"); break; | |
4086 | case E_MIPS_ARCH_32: strcat (buf, ", mips32"); break; | |
4087 | case E_MIPS_ARCH_32R2: strcat (buf, ", mips32r2"); break; | |
4088 | case E_MIPS_ARCH_32R6: strcat (buf, ", mips32r6"); break; | |
4089 | case E_MIPS_ARCH_64: strcat (buf, ", mips64"); break; | |
4090 | case E_MIPS_ARCH_64R2: strcat (buf, ", mips64r2"); break; | |
4091 | case E_MIPS_ARCH_64R6: strcat (buf, ", mips64r6"); break; | |
4092 | default: strcat (buf, _(", unknown ISA")); break; | |
4093 | } | |
4094 | break; | |
4095 | ||
4096 | case EM_NDS32: | |
4097 | decode_NDS32_machine_flags (e_flags, buf, sizeof buf); | |
4098 | break; | |
4099 | ||
4100 | case EM_NFP: | |
4101 | switch (EF_NFP_MACH (e_flags)) | |
4102 | { | |
4103 | case E_NFP_MACH_3200: | |
4104 | strcat (buf, ", NFP-32xx"); | |
4105 | break; | |
4106 | case E_NFP_MACH_6000: | |
4107 | strcat (buf, ", NFP-6xxx"); | |
4108 | break; | |
4109 | } | |
4110 | break; | |
4111 | ||
4112 | case EM_RISCV: | |
4113 | if (e_flags & EF_RISCV_RVC) | |
4114 | strcat (buf, ", RVC"); | |
4115 | ||
4116 | if (e_flags & EF_RISCV_RVE) | |
4117 | strcat (buf, ", RVE"); | |
4118 | ||
4119 | if (e_flags & EF_RISCV_TSO) | |
4120 | strcat (buf, ", TSO"); | |
4121 | ||
4122 | switch (e_flags & EF_RISCV_FLOAT_ABI) | |
4123 | { | |
4124 | case EF_RISCV_FLOAT_ABI_SOFT: | |
4125 | strcat (buf, ", soft-float ABI"); | |
4126 | break; | |
4127 | ||
4128 | case EF_RISCV_FLOAT_ABI_SINGLE: | |
4129 | strcat (buf, ", single-float ABI"); | |
4130 | break; | |
4131 | ||
4132 | case EF_RISCV_FLOAT_ABI_DOUBLE: | |
4133 | strcat (buf, ", double-float ABI"); | |
4134 | break; | |
4135 | ||
4136 | case EF_RISCV_FLOAT_ABI_QUAD: | |
4137 | strcat (buf, ", quad-float ABI"); | |
4138 | break; | |
4139 | } | |
4140 | break; | |
4141 | ||
4142 | case EM_SH: | |
4143 | switch ((e_flags & EF_SH_MACH_MASK)) | |
4144 | { | |
4145 | case EF_SH1: strcat (buf, ", sh1"); break; | |
4146 | case EF_SH2: strcat (buf, ", sh2"); break; | |
4147 | case EF_SH3: strcat (buf, ", sh3"); break; | |
4148 | case EF_SH_DSP: strcat (buf, ", sh-dsp"); break; | |
4149 | case EF_SH3_DSP: strcat (buf, ", sh3-dsp"); break; | |
4150 | case EF_SH4AL_DSP: strcat (buf, ", sh4al-dsp"); break; | |
4151 | case EF_SH3E: strcat (buf, ", sh3e"); break; | |
4152 | case EF_SH4: strcat (buf, ", sh4"); break; | |
4153 | case EF_SH5: strcat (buf, ", sh5"); break; | |
4154 | case EF_SH2E: strcat (buf, ", sh2e"); break; | |
4155 | case EF_SH4A: strcat (buf, ", sh4a"); break; | |
4156 | case EF_SH2A: strcat (buf, ", sh2a"); break; | |
4157 | case EF_SH4_NOFPU: strcat (buf, ", sh4-nofpu"); break; | |
4158 | case EF_SH4A_NOFPU: strcat (buf, ", sh4a-nofpu"); break; | |
4159 | case EF_SH2A_NOFPU: strcat (buf, ", sh2a-nofpu"); break; | |
4160 | case EF_SH3_NOMMU: strcat (buf, ", sh3-nommu"); break; | |
4161 | case EF_SH4_NOMMU_NOFPU: strcat (buf, ", sh4-nommu-nofpu"); break; | |
4162 | case EF_SH2A_SH4_NOFPU: strcat (buf, ", sh2a-nofpu-or-sh4-nommu-nofpu"); break; | |
4163 | case EF_SH2A_SH3_NOFPU: strcat (buf, ", sh2a-nofpu-or-sh3-nommu"); break; | |
4164 | case EF_SH2A_SH4: strcat (buf, ", sh2a-or-sh4"); break; | |
4165 | case EF_SH2A_SH3E: strcat (buf, ", sh2a-or-sh3e"); break; | |
4166 | default: strcat (buf, _(", unknown ISA")); break; | |
4167 | } | |
4168 | ||
4169 | if (e_flags & EF_SH_PIC) | |
4170 | strcat (buf, ", pic"); | |
4171 | ||
4172 | if (e_flags & EF_SH_FDPIC) | |
4173 | strcat (buf, ", fdpic"); | |
4174 | break; | |
4175 | ||
4176 | case EM_OR1K: | |
4177 | if (e_flags & EF_OR1K_NODELAY) | |
4178 | strcat (buf, ", no delay"); | |
4179 | break; | |
4180 | ||
4181 | case EM_SPARCV9: | |
4182 | if (e_flags & EF_SPARC_32PLUS) | |
4183 | strcat (buf, ", v8+"); | |
4184 | ||
4185 | if (e_flags & EF_SPARC_SUN_US1) | |
4186 | strcat (buf, ", ultrasparcI"); | |
4187 | ||
4188 | if (e_flags & EF_SPARC_SUN_US3) | |
4189 | strcat (buf, ", ultrasparcIII"); | |
4190 | ||
4191 | if (e_flags & EF_SPARC_HAL_R1) | |
4192 | strcat (buf, ", halr1"); | |
4193 | ||
4194 | if (e_flags & EF_SPARC_LEDATA) | |
4195 | strcat (buf, ", ledata"); | |
4196 | ||
4197 | if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_TSO) | |
4198 | strcat (buf, ", tso"); | |
4199 | ||
4200 | if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_PSO) | |
4201 | strcat (buf, ", pso"); | |
4202 | ||
4203 | if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_RMO) | |
4204 | strcat (buf, ", rmo"); | |
4205 | break; | |
4206 | ||
4207 | case EM_PARISC: | |
4208 | switch (e_flags & EF_PARISC_ARCH) | |
4209 | { | |
4210 | case EFA_PARISC_1_0: | |
4211 | strcpy (buf, ", PA-RISC 1.0"); | |
4212 | break; | |
4213 | case EFA_PARISC_1_1: | |
4214 | strcpy (buf, ", PA-RISC 1.1"); | |
4215 | break; | |
4216 | case EFA_PARISC_2_0: | |
4217 | strcpy (buf, ", PA-RISC 2.0"); | |
4218 | break; | |
4219 | default: | |
4220 | break; | |
4221 | } | |
4222 | if (e_flags & EF_PARISC_TRAPNIL) | |
4223 | strcat (buf, ", trapnil"); | |
4224 | if (e_flags & EF_PARISC_EXT) | |
4225 | strcat (buf, ", ext"); | |
4226 | if (e_flags & EF_PARISC_LSB) | |
4227 | strcat (buf, ", lsb"); | |
4228 | if (e_flags & EF_PARISC_WIDE) | |
4229 | strcat (buf, ", wide"); | |
4230 | if (e_flags & EF_PARISC_NO_KABP) | |
4231 | strcat (buf, ", no kabp"); | |
4232 | if (e_flags & EF_PARISC_LAZYSWAP) | |
4233 | strcat (buf, ", lazyswap"); | |
4234 | break; | |
4235 | ||
4236 | case EM_PJ: | |
4237 | case EM_PJ_OLD: | |
4238 | if ((e_flags & EF_PICOJAVA_NEWCALLS) == EF_PICOJAVA_NEWCALLS) | |
4239 | strcat (buf, ", new calling convention"); | |
4240 | ||
4241 | if ((e_flags & EF_PICOJAVA_GNUCALLS) == EF_PICOJAVA_GNUCALLS) | |
4242 | strcat (buf, ", gnu calling convention"); | |
4243 | break; | |
4244 | ||
4245 | case EM_IA_64: | |
4246 | if ((e_flags & EF_IA_64_ABI64)) | |
4247 | strcat (buf, ", 64-bit"); | |
4248 | else | |
4249 | strcat (buf, ", 32-bit"); | |
4250 | if ((e_flags & EF_IA_64_REDUCEDFP)) | |
4251 | strcat (buf, ", reduced fp model"); | |
4252 | if ((e_flags & EF_IA_64_NOFUNCDESC_CONS_GP)) | |
4253 | strcat (buf, ", no function descriptors, constant gp"); | |
4254 | else if ((e_flags & EF_IA_64_CONS_GP)) | |
4255 | strcat (buf, ", constant gp"); | |
4256 | if ((e_flags & EF_IA_64_ABSOLUTE)) | |
4257 | strcat (buf, ", absolute"); | |
4258 | if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_OPENVMS) | |
4259 | { | |
4260 | if ((e_flags & EF_IA_64_VMS_LINKAGES)) | |
4261 | strcat (buf, ", vms_linkages"); | |
4262 | switch ((e_flags & EF_IA_64_VMS_COMCOD)) | |
4263 | { | |
4264 | case EF_IA_64_VMS_COMCOD_SUCCESS: | |
4265 | break; | |
4266 | case EF_IA_64_VMS_COMCOD_WARNING: | |
4267 | strcat (buf, ", warning"); | |
4268 | break; | |
4269 | case EF_IA_64_VMS_COMCOD_ERROR: | |
4270 | strcat (buf, ", error"); | |
4271 | break; | |
4272 | case EF_IA_64_VMS_COMCOD_ABORT: | |
4273 | strcat (buf, ", abort"); | |
4274 | break; | |
4275 | default: | |
4276 | warn (_("Unrecognised IA64 VMS Command Code: %x\n"), | |
4277 | e_flags & EF_IA_64_VMS_COMCOD); | |
4278 | strcat (buf, ", <unknown>"); | |
4279 | } | |
4280 | } | |
4281 | break; | |
4282 | ||
4283 | case EM_VAX: | |
4284 | if ((e_flags & EF_VAX_NONPIC)) | |
4285 | strcat (buf, ", non-PIC"); | |
4286 | if ((e_flags & EF_VAX_DFLOAT)) | |
4287 | strcat (buf, ", D-Float"); | |
4288 | if ((e_flags & EF_VAX_GFLOAT)) | |
4289 | strcat (buf, ", G-Float"); | |
4290 | break; | |
4291 | ||
4292 | case EM_VISIUM: | |
4293 | if (e_flags & EF_VISIUM_ARCH_MCM) | |
4294 | strcat (buf, ", mcm"); | |
4295 | else if (e_flags & EF_VISIUM_ARCH_MCM24) | |
4296 | strcat (buf, ", mcm24"); | |
4297 | if (e_flags & EF_VISIUM_ARCH_GR6) | |
4298 | strcat (buf, ", gr6"); | |
4299 | break; | |
4300 | ||
4301 | case EM_RL78: | |
4302 | switch (e_flags & E_FLAG_RL78_CPU_MASK) | |
4303 | { | |
4304 | case E_FLAG_RL78_ANY_CPU: break; | |
4305 | case E_FLAG_RL78_G10: strcat (buf, ", G10"); break; | |
4306 | case E_FLAG_RL78_G13: strcat (buf, ", G13"); break; | |
4307 | case E_FLAG_RL78_G14: strcat (buf, ", G14"); break; | |
4308 | } | |
4309 | if (e_flags & E_FLAG_RL78_64BIT_DOUBLES) | |
4310 | strcat (buf, ", 64-bit doubles"); | |
4311 | break; | |
4312 | ||
4313 | case EM_RX: | |
4314 | if (e_flags & E_FLAG_RX_64BIT_DOUBLES) | |
4315 | strcat (buf, ", 64-bit doubles"); | |
4316 | if (e_flags & E_FLAG_RX_DSP) | |
4317 | strcat (buf, ", dsp"); | |
4318 | if (e_flags & E_FLAG_RX_PID) | |
4319 | strcat (buf, ", pid"); | |
4320 | if (e_flags & E_FLAG_RX_ABI) | |
4321 | strcat (buf, ", RX ABI"); | |
4322 | if (e_flags & E_FLAG_RX_SINSNS_SET) | |
4323 | strcat (buf, e_flags & E_FLAG_RX_SINSNS_YES | |
4324 | ? ", uses String instructions" : ", bans String instructions"); | |
4325 | if (e_flags & E_FLAG_RX_V2) | |
4326 | strcat (buf, ", V2"); | |
4327 | if (e_flags & E_FLAG_RX_V3) | |
4328 | strcat (buf, ", V3"); | |
4329 | break; | |
4330 | ||
4331 | case EM_S390: | |
4332 | if (e_flags & EF_S390_HIGH_GPRS) | |
4333 | strcat (buf, ", highgprs"); | |
4334 | break; | |
4335 | ||
4336 | case EM_TI_C6000: | |
4337 | if ((e_flags & EF_C6000_REL)) | |
4338 | strcat (buf, ", relocatable module"); | |
4339 | break; | |
4340 | ||
4341 | case EM_MSP430: | |
4342 | strcat (buf, _(": architecture variant: ")); | |
4343 | switch (e_flags & EF_MSP430_MACH) | |
4344 | { | |
4345 | case E_MSP430_MACH_MSP430x11: strcat (buf, "MSP430x11"); break; | |
4346 | case E_MSP430_MACH_MSP430x11x1 : strcat (buf, "MSP430x11x1 "); break; | |
4347 | case E_MSP430_MACH_MSP430x12: strcat (buf, "MSP430x12"); break; | |
4348 | case E_MSP430_MACH_MSP430x13: strcat (buf, "MSP430x13"); break; | |
4349 | case E_MSP430_MACH_MSP430x14: strcat (buf, "MSP430x14"); break; | |
4350 | case E_MSP430_MACH_MSP430x15: strcat (buf, "MSP430x15"); break; | |
4351 | case E_MSP430_MACH_MSP430x16: strcat (buf, "MSP430x16"); break; | |
4352 | case E_MSP430_MACH_MSP430x31: strcat (buf, "MSP430x31"); break; | |
4353 | case E_MSP430_MACH_MSP430x32: strcat (buf, "MSP430x32"); break; | |
4354 | case E_MSP430_MACH_MSP430x33: strcat (buf, "MSP430x33"); break; | |
4355 | case E_MSP430_MACH_MSP430x41: strcat (buf, "MSP430x41"); break; | |
4356 | case E_MSP430_MACH_MSP430x42: strcat (buf, "MSP430x42"); break; | |
4357 | case E_MSP430_MACH_MSP430x43: strcat (buf, "MSP430x43"); break; | |
4358 | case E_MSP430_MACH_MSP430x44: strcat (buf, "MSP430x44"); break; | |
4359 | case E_MSP430_MACH_MSP430X : strcat (buf, "MSP430X"); break; | |
4360 | default: | |
4361 | strcat (buf, _(": unknown")); break; | |
4362 | } | |
4363 | ||
4364 | if (e_flags & ~ EF_MSP430_MACH) | |
4365 | strcat (buf, _(": unknown extra flag bits also present")); | |
4366 | break; | |
4367 | ||
4368 | case EM_Z80: | |
4369 | switch (e_flags & EF_Z80_MACH_MSK) | |
4370 | { | |
4371 | case EF_Z80_MACH_Z80: strcat (buf, ", Z80"); break; | |
4372 | case EF_Z80_MACH_Z180: strcat (buf, ", Z180"); break; | |
4373 | case EF_Z80_MACH_R800: strcat (buf, ", R800"); break; | |
4374 | case EF_Z80_MACH_EZ80_Z80: strcat (buf, ", EZ80"); break; | |
4375 | case EF_Z80_MACH_EZ80_ADL: strcat (buf, ", EZ80, ADL"); break; | |
4376 | case EF_Z80_MACH_GBZ80: strcat (buf, ", GBZ80"); break; | |
4377 | case EF_Z80_MACH_Z80N: strcat (buf, ", Z80N"); break; | |
4378 | default: | |
4379 | strcat (buf, _(", unknown")); break; | |
4380 | } | |
4381 | break; | |
4382 | case EM_LOONGARCH: | |
4383 | if (EF_LOONGARCH_IS_SOFT_FLOAT (e_flags)) | |
4384 | strcat (buf, ", SOFT-FLOAT"); | |
4385 | else if (EF_LOONGARCH_IS_SINGLE_FLOAT (e_flags)) | |
4386 | strcat (buf, ", SINGLE-FLOAT"); | |
4387 | else if (EF_LOONGARCH_IS_DOUBLE_FLOAT (e_flags)) | |
4388 | strcat (buf, ", DOUBLE-FLOAT"); | |
4389 | ||
4390 | if (EF_LOONGARCH_IS_OBJ_V0 (e_flags)) | |
4391 | strcat (buf, ", OBJ-v0"); | |
4392 | else if (EF_LOONGARCH_IS_OBJ_V1 (e_flags)) | |
4393 | strcat (buf, ", OBJ-v1"); | |
4394 | ||
4395 | break; | |
4396 | } | |
4397 | } | |
4398 | ||
4399 | return buf; | |
4400 | } | |
4401 | ||
4402 | static const char * | |
4403 | get_osabi_name (Filedata * filedata, unsigned int osabi) | |
4404 | { | |
4405 | static char buff[32]; | |
4406 | ||
4407 | switch (osabi) | |
4408 | { | |
4409 | case ELFOSABI_NONE: return "UNIX - System V"; | |
4410 | case ELFOSABI_HPUX: return "UNIX - HP-UX"; | |
4411 | case ELFOSABI_NETBSD: return "UNIX - NetBSD"; | |
4412 | case ELFOSABI_GNU: return "UNIX - GNU"; | |
4413 | case ELFOSABI_SOLARIS: return "UNIX - Solaris"; | |
4414 | case ELFOSABI_AIX: return "UNIX - AIX"; | |
4415 | case ELFOSABI_IRIX: return "UNIX - IRIX"; | |
4416 | case ELFOSABI_FREEBSD: return "UNIX - FreeBSD"; | |
4417 | case ELFOSABI_TRU64: return "UNIX - TRU64"; | |
4418 | case ELFOSABI_MODESTO: return "Novell - Modesto"; | |
4419 | case ELFOSABI_OPENBSD: return "UNIX - OpenBSD"; | |
4420 | case ELFOSABI_OPENVMS: return "VMS - OpenVMS"; | |
4421 | case ELFOSABI_NSK: return "HP - Non-Stop Kernel"; | |
4422 | case ELFOSABI_AROS: return "AROS"; | |
4423 | case ELFOSABI_FENIXOS: return "FenixOS"; | |
4424 | case ELFOSABI_CLOUDABI: return "Nuxi CloudABI"; | |
4425 | case ELFOSABI_OPENVOS: return "Stratus Technologies OpenVOS"; | |
4426 | default: | |
4427 | if (osabi >= 64) | |
4428 | switch (filedata->file_header.e_machine) | |
4429 | { | |
4430 | case EM_AMDGPU: | |
4431 | switch (osabi) | |
4432 | { | |
4433 | case ELFOSABI_AMDGPU_HSA: return "AMD HSA"; | |
4434 | case ELFOSABI_AMDGPU_PAL: return "AMD PAL"; | |
4435 | case ELFOSABI_AMDGPU_MESA3D: return "AMD Mesa3D"; | |
4436 | default: | |
4437 | break; | |
4438 | } | |
4439 | break; | |
4440 | ||
4441 | case EM_ARM: | |
4442 | switch (osabi) | |
4443 | { | |
4444 | case ELFOSABI_ARM: return "ARM"; | |
4445 | case ELFOSABI_ARM_FDPIC: return "ARM FDPIC"; | |
4446 | default: | |
4447 | break; | |
4448 | } | |
4449 | break; | |
4450 | ||
4451 | case EM_MSP430: | |
4452 | case EM_MSP430_OLD: | |
4453 | case EM_VISIUM: | |
4454 | switch (osabi) | |
4455 | { | |
4456 | case ELFOSABI_STANDALONE: return _("Standalone App"); | |
4457 | default: | |
4458 | break; | |
4459 | } | |
4460 | break; | |
4461 | ||
4462 | case EM_TI_C6000: | |
4463 | switch (osabi) | |
4464 | { | |
4465 | case ELFOSABI_C6000_ELFABI: return _("Bare-metal C6000"); | |
4466 | case ELFOSABI_C6000_LINUX: return "Linux C6000"; | |
4467 | default: | |
4468 | break; | |
4469 | } | |
4470 | break; | |
4471 | ||
4472 | default: | |
4473 | break; | |
4474 | } | |
4475 | snprintf (buff, sizeof (buff), _("<unknown: %x>"), osabi); | |
4476 | return buff; | |
4477 | } | |
4478 | } | |
4479 | ||
4480 | static const char * | |
4481 | get_aarch64_segment_type (unsigned long type) | |
4482 | { | |
4483 | switch (type) | |
4484 | { | |
4485 | case PT_AARCH64_ARCHEXT: return "AARCH64_ARCHEXT"; | |
4486 | case PT_AARCH64_MEMTAG_MTE: return "AARCH64_MEMTAG_MTE"; | |
4487 | default: return NULL; | |
4488 | } | |
4489 | } | |
4490 | ||
4491 | static const char * | |
4492 | get_arm_segment_type (unsigned long type) | |
4493 | { | |
4494 | switch (type) | |
4495 | { | |
4496 | case PT_ARM_EXIDX: return "EXIDX"; | |
4497 | default: return NULL; | |
4498 | } | |
4499 | } | |
4500 | ||
4501 | static const char * | |
4502 | get_s390_segment_type (unsigned long type) | |
4503 | { | |
4504 | switch (type) | |
4505 | { | |
4506 | case PT_S390_PGSTE: return "S390_PGSTE"; | |
4507 | default: return NULL; | |
4508 | } | |
4509 | } | |
4510 | ||
4511 | static const char * | |
4512 | get_mips_segment_type (unsigned long type) | |
4513 | { | |
4514 | switch (type) | |
4515 | { | |
4516 | case PT_MIPS_REGINFO: return "REGINFO"; | |
4517 | case PT_MIPS_RTPROC: return "RTPROC"; | |
4518 | case PT_MIPS_OPTIONS: return "OPTIONS"; | |
4519 | case PT_MIPS_ABIFLAGS: return "ABIFLAGS"; | |
4520 | default: return NULL; | |
4521 | } | |
4522 | } | |
4523 | ||
4524 | static const char * | |
4525 | get_parisc_segment_type (unsigned long type) | |
4526 | { | |
4527 | switch (type) | |
4528 | { | |
4529 | case PT_PARISC_ARCHEXT: return "PARISC_ARCHEXT"; | |
4530 | case PT_PARISC_UNWIND: return "PARISC_UNWIND"; | |
4531 | case PT_PARISC_WEAKORDER: return "PARISC_WEAKORDER"; | |
4532 | default: return NULL; | |
4533 | } | |
4534 | } | |
4535 | ||
4536 | static const char * | |
4537 | get_ia64_segment_type (unsigned long type) | |
4538 | { | |
4539 | switch (type) | |
4540 | { | |
4541 | case PT_IA_64_ARCHEXT: return "IA_64_ARCHEXT"; | |
4542 | case PT_IA_64_UNWIND: return "IA_64_UNWIND"; | |
4543 | default: return NULL; | |
4544 | } | |
4545 | } | |
4546 | ||
4547 | static const char * | |
4548 | get_tic6x_segment_type (unsigned long type) | |
4549 | { | |
4550 | switch (type) | |
4551 | { | |
4552 | case PT_C6000_PHATTR: return "C6000_PHATTR"; | |
4553 | default: return NULL; | |
4554 | } | |
4555 | } | |
4556 | ||
4557 | static const char * | |
4558 | get_riscv_segment_type (unsigned long type) | |
4559 | { | |
4560 | switch (type) | |
4561 | { | |
4562 | case PT_RISCV_ATTRIBUTES: return "RISCV_ATTRIBUTES"; | |
4563 | default: return NULL; | |
4564 | } | |
4565 | } | |
4566 | ||
4567 | static const char * | |
4568 | get_hpux_segment_type (unsigned long type, unsigned e_machine) | |
4569 | { | |
4570 | if (e_machine == EM_PARISC) | |
4571 | switch (type) | |
4572 | { | |
4573 | case PT_HP_TLS: return "HP_TLS"; | |
4574 | case PT_HP_CORE_NONE: return "HP_CORE_NONE"; | |
4575 | case PT_HP_CORE_VERSION: return "HP_CORE_VERSION"; | |
4576 | case PT_HP_CORE_KERNEL: return "HP_CORE_KERNEL"; | |
4577 | case PT_HP_CORE_COMM: return "HP_CORE_COMM"; | |
4578 | case PT_HP_CORE_PROC: return "HP_CORE_PROC"; | |
4579 | case PT_HP_CORE_LOADABLE: return "HP_CORE_LOADABLE"; | |
4580 | case PT_HP_CORE_STACK: return "HP_CORE_STACK"; | |
4581 | case PT_HP_CORE_SHM: return "HP_CORE_SHM"; | |
4582 | case PT_HP_CORE_MMF: return "HP_CORE_MMF"; | |
4583 | case PT_HP_PARALLEL: return "HP_PARALLEL"; | |
4584 | case PT_HP_FASTBIND: return "HP_FASTBIND"; | |
4585 | case PT_HP_OPT_ANNOT: return "HP_OPT_ANNOT"; | |
4586 | case PT_HP_HSL_ANNOT: return "HP_HSL_ANNOT"; | |
4587 | case PT_HP_STACK: return "HP_STACK"; | |
4588 | case PT_HP_CORE_UTSNAME: return "HP_CORE_UTSNAME"; | |
4589 | default: return NULL; | |
4590 | } | |
4591 | ||
4592 | if (e_machine == EM_IA_64) | |
4593 | switch (type) | |
4594 | { | |
4595 | case PT_HP_TLS: return "HP_TLS"; | |
4596 | case PT_IA_64_HP_OPT_ANOT: return "HP_OPT_ANNOT"; | |
4597 | case PT_IA_64_HP_HSL_ANOT: return "HP_HSL_ANNOT"; | |
4598 | case PT_IA_64_HP_STACK: return "HP_STACK"; | |
4599 | default: return NULL; | |
4600 | } | |
4601 | ||
4602 | return NULL; | |
4603 | } | |
4604 | ||
4605 | static const char * | |
4606 | get_solaris_segment_type (unsigned long type) | |
4607 | { | |
4608 | switch (type) | |
4609 | { | |
4610 | case 0x6464e550: return "PT_SUNW_UNWIND"; | |
4611 | case 0x6474e550: return "PT_SUNW_EH_FRAME"; | |
4612 | case 0x6ffffff7: return "PT_LOSUNW"; | |
4613 | case 0x6ffffffa: return "PT_SUNWBSS"; | |
4614 | case 0x6ffffffb: return "PT_SUNWSTACK"; | |
4615 | case 0x6ffffffc: return "PT_SUNWDTRACE"; | |
4616 | case 0x6ffffffd: return "PT_SUNWCAP"; | |
4617 | case 0x6fffffff: return "PT_HISUNW"; | |
4618 | default: return NULL; | |
4619 | } | |
4620 | } | |
4621 | ||
4622 | static const char * | |
4623 | get_segment_type (Filedata * filedata, unsigned long p_type) | |
4624 | { | |
4625 | static char buff[32]; | |
4626 | ||
4627 | switch (p_type) | |
4628 | { | |
4629 | case PT_NULL: return "NULL"; | |
4630 | case PT_LOAD: return "LOAD"; | |
4631 | case PT_DYNAMIC: return "DYNAMIC"; | |
4632 | case PT_INTERP: return "INTERP"; | |
4633 | case PT_NOTE: return "NOTE"; | |
4634 | case PT_SHLIB: return "SHLIB"; | |
4635 | case PT_PHDR: return "PHDR"; | |
4636 | case PT_TLS: return "TLS"; | |
4637 | case PT_GNU_EH_FRAME: return "GNU_EH_FRAME"; | |
4638 | case PT_GNU_STACK: return "GNU_STACK"; | |
4639 | case PT_GNU_RELRO: return "GNU_RELRO"; | |
4640 | case PT_GNU_PROPERTY: return "GNU_PROPERTY"; | |
4641 | case PT_GNU_SFRAME: return "GNU_SFRAME"; | |
4642 | ||
4643 | case PT_OPENBSD_RANDOMIZE: return "OPENBSD_RANDOMIZE"; | |
4644 | case PT_OPENBSD_WXNEEDED: return "OPENBSD_WXNEEDED"; | |
4645 | case PT_OPENBSD_BOOTDATA: return "OPENBSD_BOOTDATA"; | |
4646 | ||
4647 | default: | |
4648 | if ((p_type >= PT_LOPROC) && (p_type <= PT_HIPROC)) | |
4649 | { | |
4650 | const char * result; | |
4651 | ||
4652 | switch (filedata->file_header.e_machine) | |
4653 | { | |
4654 | case EM_AARCH64: | |
4655 | result = get_aarch64_segment_type (p_type); | |
4656 | break; | |
4657 | case EM_ARM: | |
4658 | result = get_arm_segment_type (p_type); | |
4659 | break; | |
4660 | case EM_MIPS: | |
4661 | case EM_MIPS_RS3_LE: | |
4662 | result = get_mips_segment_type (p_type); | |
4663 | break; | |
4664 | case EM_PARISC: | |
4665 | result = get_parisc_segment_type (p_type); | |
4666 | break; | |
4667 | case EM_IA_64: | |
4668 | result = get_ia64_segment_type (p_type); | |
4669 | break; | |
4670 | case EM_TI_C6000: | |
4671 | result = get_tic6x_segment_type (p_type); | |
4672 | break; | |
4673 | case EM_S390: | |
4674 | case EM_S390_OLD: | |
4675 | result = get_s390_segment_type (p_type); | |
4676 | break; | |
4677 | case EM_RISCV: | |
4678 | result = get_riscv_segment_type (p_type); | |
4679 | break; | |
4680 | default: | |
4681 | result = NULL; | |
4682 | break; | |
4683 | } | |
4684 | ||
4685 | if (result != NULL) | |
4686 | return result; | |
4687 | ||
4688 | sprintf (buff, "LOPROC+%#lx", p_type - PT_LOPROC); | |
4689 | } | |
4690 | else if ((p_type >= PT_LOOS) && (p_type <= PT_HIOS)) | |
4691 | { | |
4692 | const char * result = NULL; | |
4693 | ||
4694 | switch (filedata->file_header.e_ident[EI_OSABI]) | |
4695 | { | |
4696 | case ELFOSABI_GNU: | |
4697 | case ELFOSABI_FREEBSD: | |
4698 | if (p_type >= PT_GNU_MBIND_LO && p_type <= PT_GNU_MBIND_HI) | |
4699 | { | |
4700 | sprintf (buff, "GNU_MBIND+%#lx", p_type - PT_GNU_MBIND_LO); | |
4701 | result = buff; | |
4702 | } | |
4703 | break; | |
4704 | case ELFOSABI_HPUX: | |
4705 | result = get_hpux_segment_type (p_type, | |
4706 | filedata->file_header.e_machine); | |
4707 | break; | |
4708 | case ELFOSABI_SOLARIS: | |
4709 | result = get_solaris_segment_type (p_type); | |
4710 | break; | |
4711 | default: | |
4712 | break; | |
4713 | } | |
4714 | if (result != NULL) | |
4715 | return result; | |
4716 | ||
4717 | sprintf (buff, "LOOS+%#lx", p_type - PT_LOOS); | |
4718 | } | |
4719 | else | |
4720 | snprintf (buff, sizeof (buff), _("<unknown>: %lx"), p_type); | |
4721 | ||
4722 | return buff; | |
4723 | } | |
4724 | } | |
4725 | ||
4726 | static const char * | |
4727 | get_arc_section_type_name (unsigned int sh_type) | |
4728 | { | |
4729 | switch (sh_type) | |
4730 | { | |
4731 | case SHT_ARC_ATTRIBUTES: return "ARC_ATTRIBUTES"; | |
4732 | default: | |
4733 | break; | |
4734 | } | |
4735 | return NULL; | |
4736 | } | |
4737 | ||
4738 | static const char * | |
4739 | get_mips_section_type_name (unsigned int sh_type) | |
4740 | { | |
4741 | switch (sh_type) | |
4742 | { | |
4743 | case SHT_MIPS_LIBLIST: return "MIPS_LIBLIST"; | |
4744 | case SHT_MIPS_MSYM: return "MIPS_MSYM"; | |
4745 | case SHT_MIPS_CONFLICT: return "MIPS_CONFLICT"; | |
4746 | case SHT_MIPS_GPTAB: return "MIPS_GPTAB"; | |
4747 | case SHT_MIPS_UCODE: return "MIPS_UCODE"; | |
4748 | case SHT_MIPS_DEBUG: return "MIPS_DEBUG"; | |
4749 | case SHT_MIPS_REGINFO: return "MIPS_REGINFO"; | |
4750 | case SHT_MIPS_PACKAGE: return "MIPS_PACKAGE"; | |
4751 | case SHT_MIPS_PACKSYM: return "MIPS_PACKSYM"; | |
4752 | case SHT_MIPS_RELD: return "MIPS_RELD"; | |
4753 | case SHT_MIPS_IFACE: return "MIPS_IFACE"; | |
4754 | case SHT_MIPS_CONTENT: return "MIPS_CONTENT"; | |
4755 | case SHT_MIPS_OPTIONS: return "MIPS_OPTIONS"; | |
4756 | case SHT_MIPS_SHDR: return "MIPS_SHDR"; | |
4757 | case SHT_MIPS_FDESC: return "MIPS_FDESC"; | |
4758 | case SHT_MIPS_EXTSYM: return "MIPS_EXTSYM"; | |
4759 | case SHT_MIPS_DENSE: return "MIPS_DENSE"; | |
4760 | case SHT_MIPS_PDESC: return "MIPS_PDESC"; | |
4761 | case SHT_MIPS_LOCSYM: return "MIPS_LOCSYM"; | |
4762 | case SHT_MIPS_AUXSYM: return "MIPS_AUXSYM"; | |
4763 | case SHT_MIPS_OPTSYM: return "MIPS_OPTSYM"; | |
4764 | case SHT_MIPS_LOCSTR: return "MIPS_LOCSTR"; | |
4765 | case SHT_MIPS_LINE: return "MIPS_LINE"; | |
4766 | case SHT_MIPS_RFDESC: return "MIPS_RFDESC"; | |
4767 | case SHT_MIPS_DELTASYM: return "MIPS_DELTASYM"; | |
4768 | case SHT_MIPS_DELTAINST: return "MIPS_DELTAINST"; | |
4769 | case SHT_MIPS_DELTACLASS: return "MIPS_DELTACLASS"; | |
4770 | case SHT_MIPS_DWARF: return "MIPS_DWARF"; | |
4771 | case SHT_MIPS_DELTADECL: return "MIPS_DELTADECL"; | |
4772 | case SHT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB"; | |
4773 | case SHT_MIPS_EVENTS: return "MIPS_EVENTS"; | |
4774 | case SHT_MIPS_TRANSLATE: return "MIPS_TRANSLATE"; | |
4775 | case SHT_MIPS_PIXIE: return "MIPS_PIXIE"; | |
4776 | case SHT_MIPS_XLATE: return "MIPS_XLATE"; | |
4777 | case SHT_MIPS_XLATE_DEBUG: return "MIPS_XLATE_DEBUG"; | |
4778 | case SHT_MIPS_WHIRL: return "MIPS_WHIRL"; | |
4779 | case SHT_MIPS_EH_REGION: return "MIPS_EH_REGION"; | |
4780 | case SHT_MIPS_XLATE_OLD: return "MIPS_XLATE_OLD"; | |
4781 | case SHT_MIPS_PDR_EXCEPTION: return "MIPS_PDR_EXCEPTION"; | |
4782 | case SHT_MIPS_ABIFLAGS: return "MIPS_ABIFLAGS"; | |
4783 | case SHT_MIPS_XHASH: return "MIPS_XHASH"; | |
4784 | default: | |
4785 | break; | |
4786 | } | |
4787 | return NULL; | |
4788 | } | |
4789 | ||
4790 | static const char * | |
4791 | get_parisc_section_type_name (unsigned int sh_type) | |
4792 | { | |
4793 | switch (sh_type) | |
4794 | { | |
4795 | case SHT_PARISC_EXT: return "PARISC_EXT"; | |
4796 | case SHT_PARISC_UNWIND: return "PARISC_UNWIND"; | |
4797 | case SHT_PARISC_DOC: return "PARISC_DOC"; | |
4798 | case SHT_PARISC_ANNOT: return "PARISC_ANNOT"; | |
4799 | case SHT_PARISC_SYMEXTN: return "PARISC_SYMEXTN"; | |
4800 | case SHT_PARISC_STUBS: return "PARISC_STUBS"; | |
4801 | case SHT_PARISC_DLKM: return "PARISC_DLKM"; | |
4802 | default: return NULL; | |
4803 | } | |
4804 | } | |
4805 | ||
4806 | static const char * | |
4807 | get_ia64_section_type_name (Filedata * filedata, unsigned int sh_type) | |
4808 | { | |
4809 | /* If the top 8 bits are 0x78 the next 8 are the os/abi ID. */ | |
4810 | if ((sh_type & 0xFF000000) == SHT_IA_64_LOPSREG) | |
4811 | return get_osabi_name (filedata, (sh_type & 0x00FF0000) >> 16); | |
4812 | ||
4813 | switch (sh_type) | |
4814 | { | |
4815 | case SHT_IA_64_EXT: return "IA_64_EXT"; | |
4816 | case SHT_IA_64_UNWIND: return "IA_64_UNWIND"; | |
4817 | case SHT_IA_64_PRIORITY_INIT: return "IA_64_PRIORITY_INIT"; | |
4818 | case SHT_IA_64_VMS_TRACE: return "VMS_TRACE"; | |
4819 | case SHT_IA_64_VMS_TIE_SIGNATURES: return "VMS_TIE_SIGNATURES"; | |
4820 | case SHT_IA_64_VMS_DEBUG: return "VMS_DEBUG"; | |
4821 | case SHT_IA_64_VMS_DEBUG_STR: return "VMS_DEBUG_STR"; | |
4822 | case SHT_IA_64_VMS_LINKAGES: return "VMS_LINKAGES"; | |
4823 | case SHT_IA_64_VMS_SYMBOL_VECTOR: return "VMS_SYMBOL_VECTOR"; | |
4824 | case SHT_IA_64_VMS_FIXUP: return "VMS_FIXUP"; | |
4825 | default: | |
4826 | break; | |
4827 | } | |
4828 | return NULL; | |
4829 | } | |
4830 | ||
4831 | static const char * | |
4832 | get_x86_64_section_type_name (unsigned int sh_type) | |
4833 | { | |
4834 | switch (sh_type) | |
4835 | { | |
4836 | case SHT_X86_64_UNWIND: return "X86_64_UNWIND"; | |
4837 | default: return NULL; | |
4838 | } | |
4839 | } | |
4840 | ||
4841 | static const char * | |
4842 | get_aarch64_section_type_name (unsigned int sh_type) | |
4843 | { | |
4844 | switch (sh_type) | |
4845 | { | |
4846 | case SHT_AARCH64_ATTRIBUTES: return "AARCH64_ATTRIBUTES"; | |
4847 | default: return NULL; | |
4848 | } | |
4849 | } | |
4850 | ||
4851 | static const char * | |
4852 | get_arm_section_type_name (unsigned int sh_type) | |
4853 | { | |
4854 | switch (sh_type) | |
4855 | { | |
4856 | case SHT_ARM_EXIDX: return "ARM_EXIDX"; | |
4857 | case SHT_ARM_PREEMPTMAP: return "ARM_PREEMPTMAP"; | |
4858 | case SHT_ARM_ATTRIBUTES: return "ARM_ATTRIBUTES"; | |
4859 | case SHT_ARM_DEBUGOVERLAY: return "ARM_DEBUGOVERLAY"; | |
4860 | case SHT_ARM_OVERLAYSECTION: return "ARM_OVERLAYSECTION"; | |
4861 | default: return NULL; | |
4862 | } | |
4863 | } | |
4864 | ||
4865 | static const char * | |
4866 | get_tic6x_section_type_name (unsigned int sh_type) | |
4867 | { | |
4868 | switch (sh_type) | |
4869 | { | |
4870 | case SHT_C6000_UNWIND: return "C6000_UNWIND"; | |
4871 | case SHT_C6000_PREEMPTMAP: return "C6000_PREEMPTMAP"; | |
4872 | case SHT_C6000_ATTRIBUTES: return "C6000_ATTRIBUTES"; | |
4873 | case SHT_TI_ICODE: return "TI_ICODE"; | |
4874 | case SHT_TI_XREF: return "TI_XREF"; | |
4875 | case SHT_TI_HANDLER: return "TI_HANDLER"; | |
4876 | case SHT_TI_INITINFO: return "TI_INITINFO"; | |
4877 | case SHT_TI_PHATTRS: return "TI_PHATTRS"; | |
4878 | default: return NULL; | |
4879 | } | |
4880 | } | |
4881 | ||
4882 | static const char * | |
4883 | get_msp430_section_type_name (unsigned int sh_type) | |
4884 | { | |
4885 | switch (sh_type) | |
4886 | { | |
4887 | case SHT_MSP430_SEC_FLAGS: return "MSP430_SEC_FLAGS"; | |
4888 | case SHT_MSP430_SYM_ALIASES: return "MSP430_SYM_ALIASES"; | |
4889 | case SHT_MSP430_ATTRIBUTES: return "MSP430_ATTRIBUTES"; | |
4890 | default: return NULL; | |
4891 | } | |
4892 | } | |
4893 | ||
4894 | static const char * | |
4895 | get_nfp_section_type_name (unsigned int sh_type) | |
4896 | { | |
4897 | switch (sh_type) | |
4898 | { | |
4899 | case SHT_NFP_MECONFIG: return "NFP_MECONFIG"; | |
4900 | case SHT_NFP_INITREG: return "NFP_INITREG"; | |
4901 | case SHT_NFP_UDEBUG: return "NFP_UDEBUG"; | |
4902 | default: return NULL; | |
4903 | } | |
4904 | } | |
4905 | ||
4906 | static const char * | |
4907 | get_v850_section_type_name (unsigned int sh_type) | |
4908 | { | |
4909 | switch (sh_type) | |
4910 | { | |
4911 | case SHT_V850_SCOMMON: return "V850 Small Common"; | |
4912 | case SHT_V850_TCOMMON: return "V850 Tiny Common"; | |
4913 | case SHT_V850_ZCOMMON: return "V850 Zero Common"; | |
4914 | case SHT_RENESAS_IOP: return "RENESAS IOP"; | |
4915 | case SHT_RENESAS_INFO: return "RENESAS INFO"; | |
4916 | default: return NULL; | |
4917 | } | |
4918 | } | |
4919 | ||
4920 | static const char * | |
4921 | get_riscv_section_type_name (unsigned int sh_type) | |
4922 | { | |
4923 | switch (sh_type) | |
4924 | { | |
4925 | case SHT_RISCV_ATTRIBUTES: return "RISCV_ATTRIBUTES"; | |
4926 | default: return NULL; | |
4927 | } | |
4928 | } | |
4929 | ||
4930 | static const char * | |
4931 | get_csky_section_type_name (unsigned int sh_type) | |
4932 | { | |
4933 | switch (sh_type) | |
4934 | { | |
4935 | case SHT_CSKY_ATTRIBUTES: return "CSKY_ATTRIBUTES"; | |
4936 | default: return NULL; | |
4937 | } | |
4938 | } | |
4939 | ||
4940 | static const char * | |
4941 | get_section_type_name (Filedata * filedata, unsigned int sh_type) | |
4942 | { | |
4943 | static char buff[32]; | |
4944 | const char * result; | |
4945 | ||
4946 | switch (sh_type) | |
4947 | { | |
4948 | case SHT_NULL: return "NULL"; | |
4949 | case SHT_PROGBITS: return "PROGBITS"; | |
4950 | case SHT_SYMTAB: return "SYMTAB"; | |
4951 | case SHT_STRTAB: return "STRTAB"; | |
4952 | case SHT_RELA: return "RELA"; | |
4953 | case SHT_RELR: return "RELR"; | |
4954 | case SHT_HASH: return "HASH"; | |
4955 | case SHT_DYNAMIC: return "DYNAMIC"; | |
4956 | case SHT_NOTE: return "NOTE"; | |
4957 | case SHT_NOBITS: return "NOBITS"; | |
4958 | case SHT_REL: return "REL"; | |
4959 | case SHT_SHLIB: return "SHLIB"; | |
4960 | case SHT_DYNSYM: return "DYNSYM"; | |
4961 | case SHT_INIT_ARRAY: return "INIT_ARRAY"; | |
4962 | case SHT_FINI_ARRAY: return "FINI_ARRAY"; | |
4963 | case SHT_PREINIT_ARRAY: return "PREINIT_ARRAY"; | |
4964 | case SHT_GNU_HASH: return "GNU_HASH"; | |
4965 | case SHT_GROUP: return "GROUP"; | |
4966 | case SHT_SYMTAB_SHNDX: return "SYMTAB SECTION INDICES"; | |
4967 | case SHT_GNU_verdef: return "VERDEF"; | |
4968 | case SHT_GNU_verneed: return "VERNEED"; | |
4969 | case SHT_GNU_versym: return "VERSYM"; | |
4970 | case 0x6ffffff0: return "VERSYM"; | |
4971 | case 0x6ffffffc: return "VERDEF"; | |
4972 | case 0x7ffffffd: return "AUXILIARY"; | |
4973 | case 0x7fffffff: return "FILTER"; | |
4974 | case SHT_GNU_LIBLIST: return "GNU_LIBLIST"; | |
4975 | ||
4976 | default: | |
4977 | if ((sh_type >= SHT_LOPROC) && (sh_type <= SHT_HIPROC)) | |
4978 | { | |
4979 | switch (filedata->file_header.e_machine) | |
4980 | { | |
4981 | case EM_ARC: | |
4982 | case EM_ARC_COMPACT: | |
4983 | case EM_ARC_COMPACT2: | |
4984 | result = get_arc_section_type_name (sh_type); | |
4985 | break; | |
4986 | case EM_MIPS: | |
4987 | case EM_MIPS_RS3_LE: | |
4988 | result = get_mips_section_type_name (sh_type); | |
4989 | break; | |
4990 | case EM_PARISC: | |
4991 | result = get_parisc_section_type_name (sh_type); | |
4992 | break; | |
4993 | case EM_IA_64: | |
4994 | result = get_ia64_section_type_name (filedata, sh_type); | |
4995 | break; | |
4996 | case EM_X86_64: | |
4997 | case EM_L1OM: | |
4998 | case EM_K1OM: | |
4999 | result = get_x86_64_section_type_name (sh_type); | |
5000 | break; | |
5001 | case EM_AARCH64: | |
5002 | result = get_aarch64_section_type_name (sh_type); | |
5003 | break; | |
5004 | case EM_ARM: | |
5005 | result = get_arm_section_type_name (sh_type); | |
5006 | break; | |
5007 | case EM_TI_C6000: | |
5008 | result = get_tic6x_section_type_name (sh_type); | |
5009 | break; | |
5010 | case EM_MSP430: | |
5011 | result = get_msp430_section_type_name (sh_type); | |
5012 | break; | |
5013 | case EM_NFP: | |
5014 | result = get_nfp_section_type_name (sh_type); | |
5015 | break; | |
5016 | case EM_V800: | |
5017 | case EM_V850: | |
5018 | case EM_CYGNUS_V850: | |
5019 | result = get_v850_section_type_name (sh_type); | |
5020 | break; | |
5021 | case EM_RISCV: | |
5022 | result = get_riscv_section_type_name (sh_type); | |
5023 | break; | |
5024 | case EM_CSKY: | |
5025 | result = get_csky_section_type_name (sh_type); | |
5026 | break; | |
5027 | default: | |
5028 | result = NULL; | |
5029 | break; | |
5030 | } | |
5031 | ||
5032 | if (result != NULL) | |
5033 | return result; | |
5034 | ||
5035 | sprintf (buff, "LOPROC+%#x", sh_type - SHT_LOPROC); | |
5036 | } | |
5037 | else if ((sh_type >= SHT_LOOS) && (sh_type <= SHT_HIOS)) | |
5038 | { | |
5039 | switch (filedata->file_header.e_machine) | |
5040 | { | |
5041 | case EM_IA_64: | |
5042 | result = get_ia64_section_type_name (filedata, sh_type); | |
5043 | break; | |
5044 | default: | |
5045 | if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS) | |
5046 | result = get_solaris_section_type (sh_type); | |
5047 | else | |
5048 | { | |
5049 | switch (sh_type) | |
5050 | { | |
5051 | case SHT_GNU_INCREMENTAL_INPUTS: result = "GNU_INCREMENTAL_INPUTS"; break; | |
5052 | case SHT_GNU_ATTRIBUTES: result = "GNU_ATTRIBUTES"; break; | |
5053 | case SHT_GNU_HASH: result = "GNU_HASH"; break; | |
5054 | case SHT_GNU_LIBLIST: result = "GNU_LIBLIST"; break; | |
5055 | default: | |
5056 | result = NULL; | |
5057 | break; | |
5058 | } | |
5059 | } | |
5060 | break; | |
5061 | } | |
5062 | ||
5063 | if (result != NULL) | |
5064 | return result; | |
5065 | ||
5066 | sprintf (buff, "LOOS+%#x", sh_type - SHT_LOOS); | |
5067 | } | |
5068 | else if ((sh_type >= SHT_LOUSER) && (sh_type <= SHT_HIUSER)) | |
5069 | { | |
5070 | switch (filedata->file_header.e_machine) | |
5071 | { | |
5072 | case EM_V800: | |
5073 | case EM_V850: | |
5074 | case EM_CYGNUS_V850: | |
5075 | result = get_v850_section_type_name (sh_type); | |
5076 | break; | |
5077 | default: | |
5078 | result = NULL; | |
5079 | break; | |
5080 | } | |
5081 | ||
5082 | if (result != NULL) | |
5083 | return result; | |
5084 | ||
5085 | sprintf (buff, "LOUSER+%#x", sh_type - SHT_LOUSER); | |
5086 | } | |
5087 | else | |
5088 | /* This message is probably going to be displayed in a 15 | |
5089 | character wide field, so put the hex value first. */ | |
5090 | snprintf (buff, sizeof (buff), _("%08x: <unknown>"), sh_type); | |
5091 | ||
5092 | return buff; | |
5093 | } | |
5094 | } | |
5095 | ||
5096 | enum long_option_values | |
5097 | { | |
5098 | OPTION_DEBUG_DUMP = 512, | |
5099 | OPTION_DYN_SYMS, | |
5100 | OPTION_LTO_SYMS, | |
5101 | OPTION_DWARF_DEPTH, | |
5102 | OPTION_DWARF_START, | |
5103 | OPTION_DWARF_CHECK, | |
5104 | OPTION_CTF_DUMP, | |
5105 | OPTION_CTF_PARENT, | |
5106 | OPTION_CTF_SYMBOLS, | |
5107 | OPTION_CTF_STRINGS, | |
5108 | OPTION_SFRAME_DUMP, | |
5109 | OPTION_WITH_SYMBOL_VERSIONS, | |
5110 | OPTION_RECURSE_LIMIT, | |
5111 | OPTION_NO_RECURSE_LIMIT, | |
5112 | OPTION_NO_DEMANGLING, | |
5113 | OPTION_SYM_BASE | |
5114 | }; | |
5115 | ||
5116 | static struct option options[] = | |
5117 | { | |
5118 | /* Note - This table is alpha-sorted on the 'val' | |
5119 | field in order to make adding new options easier. */ | |
5120 | {"arch-specific", no_argument, 0, 'A'}, | |
5121 | {"all", no_argument, 0, 'a'}, | |
5122 | {"demangle", optional_argument, 0, 'C'}, | |
5123 | {"archive-index", no_argument, 0, 'c'}, | |
5124 | {"use-dynamic", no_argument, 0, 'D'}, | |
5125 | {"dynamic", no_argument, 0, 'd'}, | |
5126 | {"headers", no_argument, 0, 'e'}, | |
5127 | {"section-groups", no_argument, 0, 'g'}, | |
5128 | {"help", no_argument, 0, 'H'}, | |
5129 | {"file-header", no_argument, 0, 'h'}, | |
5130 | {"histogram", no_argument, 0, 'I'}, | |
5131 | {"lint", no_argument, 0, 'L'}, | |
5132 | {"enable-checks", no_argument, 0, 'L'}, | |
5133 | {"program-headers", no_argument, 0, 'l'}, | |
5134 | {"segments", no_argument, 0, 'l'}, | |
5135 | {"full-section-name",no_argument, 0, 'N'}, | |
5136 | {"notes", no_argument, 0, 'n'}, | |
5137 | {"process-links", no_argument, 0, 'P'}, | |
5138 | {"string-dump", required_argument, 0, 'p'}, | |
5139 | {"relocated-dump", required_argument, 0, 'R'}, | |
5140 | {"relocs", no_argument, 0, 'r'}, | |
5141 | {"section-headers", no_argument, 0, 'S'}, | |
5142 | {"sections", no_argument, 0, 'S'}, | |
5143 | {"symbols", no_argument, 0, 's'}, | |
5144 | {"syms", no_argument, 0, 's'}, | |
5145 | {"silent-truncation",no_argument, 0, 'T'}, | |
5146 | {"section-details", no_argument, 0, 't'}, | |
5147 | {"unicode", required_argument, NULL, 'U'}, | |
5148 | {"unwind", no_argument, 0, 'u'}, | |
5149 | {"version-info", no_argument, 0, 'V'}, | |
5150 | {"version", no_argument, 0, 'v'}, | |
5151 | {"wide", no_argument, 0, 'W'}, | |
5152 | {"hex-dump", required_argument, 0, 'x'}, | |
5153 | {"decompress", no_argument, 0, 'z'}, | |
5154 | ||
5155 | {"no-demangle", no_argument, 0, OPTION_NO_DEMANGLING}, | |
5156 | {"recurse-limit", no_argument, NULL, OPTION_RECURSE_LIMIT}, | |
5157 | {"no-recurse-limit", no_argument, NULL, OPTION_NO_RECURSE_LIMIT}, | |
5158 | {"no-recursion-limit", no_argument, NULL, OPTION_NO_RECURSE_LIMIT}, | |
5159 | {"dyn-syms", no_argument, 0, OPTION_DYN_SYMS}, | |
5160 | {"lto-syms", no_argument, 0, OPTION_LTO_SYMS}, | |
5161 | {"debug-dump", optional_argument, 0, OPTION_DEBUG_DUMP}, | |
5162 | {"dwarf-depth", required_argument, 0, OPTION_DWARF_DEPTH}, | |
5163 | {"dwarf-start", required_argument, 0, OPTION_DWARF_START}, | |
5164 | {"dwarf-check", no_argument, 0, OPTION_DWARF_CHECK}, | |
5165 | #ifdef ENABLE_LIBCTF | |
5166 | {"ctf", required_argument, 0, OPTION_CTF_DUMP}, | |
5167 | {"ctf-symbols", required_argument, 0, OPTION_CTF_SYMBOLS}, | |
5168 | {"ctf-strings", required_argument, 0, OPTION_CTF_STRINGS}, | |
5169 | {"ctf-parent", required_argument, 0, OPTION_CTF_PARENT}, | |
5170 | #endif | |
5171 | {"sframe", optional_argument, 0, OPTION_SFRAME_DUMP}, | |
5172 | {"sym-base", optional_argument, 0, OPTION_SYM_BASE}, | |
5173 | ||
5174 | {0, no_argument, 0, 0} | |
5175 | }; | |
5176 | ||
5177 | static void | |
5178 | usage (FILE * stream) | |
5179 | { | |
5180 | fprintf (stream, _("Usage: readelf <option(s)> elf-file(s)\n")); | |
5181 | fprintf (stream, _(" Display information about the contents of ELF format files\n")); | |
5182 | fprintf (stream, _(" Options are:\n")); | |
5183 | fprintf (stream, _("\ | |
5184 | -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n")); | |
5185 | fprintf (stream, _("\ | |
5186 | -h --file-header Display the ELF file header\n")); | |
5187 | fprintf (stream, _("\ | |
5188 | -l --program-headers Display the program headers\n")); | |
5189 | fprintf (stream, _("\ | |
5190 | --segments An alias for --program-headers\n")); | |
5191 | fprintf (stream, _("\ | |
5192 | -S --section-headers Display the sections' header\n")); | |
5193 | fprintf (stream, _("\ | |
5194 | --sections An alias for --section-headers\n")); | |
5195 | fprintf (stream, _("\ | |
5196 | -g --section-groups Display the section groups\n")); | |
5197 | fprintf (stream, _("\ | |
5198 | -t --section-details Display the section details\n")); | |
5199 | fprintf (stream, _("\ | |
5200 | -e --headers Equivalent to: -h -l -S\n")); | |
5201 | fprintf (stream, _("\ | |
5202 | -s --syms Display the symbol table\n")); | |
5203 | fprintf (stream, _("\ | |
5204 | --symbols An alias for --syms\n")); | |
5205 | fprintf (stream, _("\ | |
5206 | --dyn-syms Display the dynamic symbol table\n")); | |
5207 | fprintf (stream, _("\ | |
5208 | --lto-syms Display LTO symbol tables\n")); | |
5209 | fprintf (stream, _("\ | |
5210 | --sym-base=[0|8|10|16] \n\ | |
5211 | Force base for symbol sizes. The options are \n\ | |
5212 | mixed (the default), octal, decimal, hexadecimal.\n")); | |
5213 | fprintf (stream, _("\ | |
5214 | -C --demangle[=STYLE] Decode mangled/processed symbol names\n")); | |
5215 | display_demangler_styles (stream, _("\ | |
5216 | STYLE can be ")); | |
5217 | fprintf (stream, _("\ | |
5218 | --no-demangle Do not demangle low-level symbol names. (default)\n")); | |
5219 | fprintf (stream, _("\ | |
5220 | --recurse-limit Enable a demangling recursion limit. (default)\n")); | |
5221 | fprintf (stream, _("\ | |
5222 | --no-recurse-limit Disable a demangling recursion limit\n")); | |
5223 | fprintf (stream, _("\ | |
5224 | -U[dlexhi] --unicode=[default|locale|escape|hex|highlight|invalid]\n\ | |
5225 | Display unicode characters as determined by the current locale\n\ | |
5226 | (default), escape sequences, \"<hex sequences>\", highlighted\n\ | |
5227 | escape sequences, or treat them as invalid and display as\n\ | |
5228 | \"{hex sequences}\"\n")); | |
5229 | fprintf (stream, _("\ | |
5230 | -n --notes Display the core notes (if present)\n")); | |
5231 | fprintf (stream, _("\ | |
5232 | -r --relocs Display the relocations (if present)\n")); | |
5233 | fprintf (stream, _("\ | |
5234 | -u --unwind Display the unwind info (if present)\n")); | |
5235 | fprintf (stream, _("\ | |
5236 | -d --dynamic Display the dynamic section (if present)\n")); | |
5237 | fprintf (stream, _("\ | |
5238 | -V --version-info Display the version sections (if present)\n")); | |
5239 | fprintf (stream, _("\ | |
5240 | -A --arch-specific Display architecture specific information (if any)\n")); | |
5241 | fprintf (stream, _("\ | |
5242 | -c --archive-index Display the symbol/file index in an archive\n")); | |
5243 | fprintf (stream, _("\ | |
5244 | -D --use-dynamic Use the dynamic section info when displaying symbols\n")); | |
5245 | fprintf (stream, _("\ | |
5246 | -L --lint|--enable-checks\n\ | |
5247 | Display warning messages for possible problems\n")); | |
5248 | fprintf (stream, _("\ | |
5249 | -x --hex-dump=<number|name>\n\ | |
5250 | Dump the contents of section <number|name> as bytes\n")); | |
5251 | fprintf (stream, _("\ | |
5252 | -p --string-dump=<number|name>\n\ | |
5253 | Dump the contents of section <number|name> as strings\n")); | |
5254 | fprintf (stream, _("\ | |
5255 | -R --relocated-dump=<number|name>\n\ | |
5256 | Dump the relocated contents of section <number|name>\n")); | |
5257 | fprintf (stream, _("\ | |
5258 | -z --decompress Decompress section before dumping it\n")); | |
5259 | fprintf (stream, _("\ | |
5260 | -w --debug-dump[a/=abbrev, A/=addr, r/=aranges, c/=cu_index, L/=decodedline,\n\ | |
5261 | f/=frames, F/=frames-interp, g/=gdb_index, i/=info, o/=loc,\n\ | |
5262 | m/=macro, p/=pubnames, t/=pubtypes, R/=Ranges, l/=rawline,\n\ | |
5263 | s/=str, O/=str-offsets, u/=trace_abbrev, T/=trace_aranges,\n\ | |
5264 | U/=trace_info]\n\ | |
5265 | Display the contents of DWARF debug sections\n")); | |
5266 | fprintf (stream, _("\ | |
5267 | -wk --debug-dump=links Display the contents of sections that link to separate\n\ | |
5268 | debuginfo files\n")); | |
5269 | fprintf (stream, _("\ | |
5270 | -P --process-links Display the contents of non-debug sections in separate\n\ | |
5271 | debuginfo files. (Implies -wK)\n")); | |
5272 | #if DEFAULT_FOR_FOLLOW_LINKS | |
5273 | fprintf (stream, _("\ | |
5274 | -wK --debug-dump=follow-links\n\ | |
5275 | Follow links to separate debug info files (default)\n")); | |
5276 | fprintf (stream, _("\ | |
5277 | -wN --debug-dump=no-follow-links\n\ | |
5278 | Do not follow links to separate debug info files\n")); | |
5279 | #else | |
5280 | fprintf (stream, _("\ | |
5281 | -wK --debug-dump=follow-links\n\ | |
5282 | Follow links to separate debug info files\n")); | |
5283 | fprintf (stream, _("\ | |
5284 | -wN --debug-dump=no-follow-links\n\ | |
5285 | Do not follow links to separate debug info files\n\ | |
5286 | (default)\n")); | |
5287 | #endif | |
5288 | #if HAVE_LIBDEBUGINFOD | |
5289 | fprintf (stream, _("\ | |
5290 | -wD --debug-dump=use-debuginfod\n\ | |
5291 | When following links, also query debuginfod servers (default)\n")); | |
5292 | fprintf (stream, _("\ | |
5293 | -wE --debug-dump=do-not-use-debuginfod\n\ | |
5294 | When following links, do not query debuginfod servers\n")); | |
5295 | #endif | |
5296 | fprintf (stream, _("\ | |
5297 | --dwarf-depth=N Do not display DIEs at depth N or greater\n")); | |
5298 | fprintf (stream, _("\ | |
5299 | --dwarf-start=N Display DIEs starting at offset N\n")); | |
5300 | #ifdef ENABLE_LIBCTF | |
5301 | fprintf (stream, _("\ | |
5302 | --ctf=<number|name> Display CTF info from section <number|name>\n")); | |
5303 | fprintf (stream, _("\ | |
5304 | --ctf-parent=<name> Use CTF archive member <name> as the CTF parent\n")); | |
5305 | fprintf (stream, _("\ | |
5306 | --ctf-symbols=<number|name>\n\ | |
5307 | Use section <number|name> as the CTF external symtab\n")); | |
5308 | fprintf (stream, _("\ | |
5309 | --ctf-strings=<number|name>\n\ | |
5310 | Use section <number|name> as the CTF external strtab\n")); | |
5311 | #endif | |
5312 | fprintf (stream, _("\ | |
5313 | --sframe[=NAME] Display SFrame info from section NAME, (default '.sframe')\n")); | |
5314 | ||
5315 | #ifdef SUPPORT_DISASSEMBLY | |
5316 | fprintf (stream, _("\ | |
5317 | -i --instruction-dump=<number|name>\n\ | |
5318 | Disassemble the contents of section <number|name>\n")); | |
5319 | #endif | |
5320 | fprintf (stream, _("\ | |
5321 | -I --histogram Display histogram of bucket list lengths\n")); | |
5322 | fprintf (stream, _("\ | |
5323 | -W --wide Allow output width to exceed 80 characters\n")); | |
5324 | fprintf (stream, _("\ | |
5325 | -T --silent-truncation If a symbol name is truncated, do not add [...] suffix\n")); | |
5326 | fprintf (stream, _("\ | |
5327 | @<file> Read options from <file>\n")); | |
5328 | fprintf (stream, _("\ | |
5329 | -H --help Display this information\n")); | |
5330 | fprintf (stream, _("\ | |
5331 | -v --version Display the version number of readelf\n")); | |
5332 | ||
5333 | if (REPORT_BUGS_TO[0] && stream == stdout) | |
5334 | fprintf (stdout, _("Report bugs to %s\n"), REPORT_BUGS_TO); | |
5335 | ||
5336 | exit (stream == stdout ? 0 : 1); | |
5337 | } | |
5338 | ||
5339 | /* Record the fact that the user wants the contents of section number | |
5340 | SECTION to be displayed using the method(s) encoded as flags bits | |
5341 | in TYPE. Note, TYPE can be zero if we are creating the array for | |
5342 | the first time. */ | |
5343 | ||
5344 | static void | |
5345 | request_dump_bynumber (struct dump_data *dumpdata, | |
5346 | unsigned int section, dump_type type) | |
5347 | { | |
5348 | if (section >= dumpdata->num_dump_sects) | |
5349 | { | |
5350 | dump_type * new_dump_sects; | |
5351 | ||
5352 | new_dump_sects = (dump_type *) calloc (section + 1, | |
5353 | sizeof (* new_dump_sects)); | |
5354 | ||
5355 | if (new_dump_sects == NULL) | |
5356 | error (_("Out of memory allocating dump request table.\n")); | |
5357 | else | |
5358 | { | |
5359 | if (dumpdata->dump_sects) | |
5360 | { | |
5361 | /* Copy current flag settings. */ | |
5362 | memcpy (new_dump_sects, dumpdata->dump_sects, | |
5363 | dumpdata->num_dump_sects * sizeof (* new_dump_sects)); | |
5364 | ||
5365 | free (dumpdata->dump_sects); | |
5366 | } | |
5367 | ||
5368 | dumpdata->dump_sects = new_dump_sects; | |
5369 | dumpdata->num_dump_sects = section + 1; | |
5370 | } | |
5371 | } | |
5372 | ||
5373 | if (dumpdata->dump_sects) | |
5374 | dumpdata->dump_sects[section] |= type; | |
5375 | } | |
5376 | ||
5377 | /* Request a dump by section name. */ | |
5378 | ||
5379 | static void | |
5380 | request_dump_byname (const char * section, dump_type type) | |
5381 | { | |
5382 | struct dump_list_entry * new_request; | |
5383 | ||
5384 | new_request = (struct dump_list_entry *) | |
5385 | malloc (sizeof (struct dump_list_entry)); | |
5386 | if (!new_request) | |
5387 | error (_("Out of memory allocating dump request table.\n")); | |
5388 | ||
5389 | new_request->name = strdup (section); | |
5390 | if (!new_request->name) | |
5391 | error (_("Out of memory allocating dump request table.\n")); | |
5392 | ||
5393 | new_request->type = type; | |
5394 | ||
5395 | new_request->next = dump_sects_byname; | |
5396 | dump_sects_byname = new_request; | |
5397 | } | |
5398 | ||
5399 | static inline void | |
5400 | request_dump (struct dump_data *dumpdata, dump_type type) | |
5401 | { | |
5402 | int section; | |
5403 | char * cp; | |
5404 | ||
5405 | do_dump = true; | |
5406 | section = strtoul (optarg, & cp, 0); | |
5407 | ||
5408 | if (! *cp && section >= 0) | |
5409 | request_dump_bynumber (dumpdata, section, type); | |
5410 | else | |
5411 | request_dump_byname (optarg, type); | |
5412 | } | |
5413 | ||
5414 | static void | |
5415 | parse_args (struct dump_data *dumpdata, int argc, char ** argv) | |
5416 | { | |
5417 | int c; | |
5418 | ||
5419 | if (argc < 2) | |
5420 | usage (stderr); | |
5421 | ||
5422 | while ((c = getopt_long | |
5423 | (argc, argv, "ACDHILNPR:STU:VWacdeghi:lnp:rstuvw::x:z", options, NULL)) != EOF) | |
5424 | { | |
5425 | switch (c) | |
5426 | { | |
5427 | case 0: | |
5428 | /* Long options. */ | |
5429 | break; | |
5430 | case 'H': | |
5431 | usage (stdout); | |
5432 | break; | |
5433 | ||
5434 | case 'a': | |
5435 | do_syms = true; | |
5436 | do_reloc = true; | |
5437 | do_unwind = true; | |
5438 | do_dynamic = true; | |
5439 | do_header = true; | |
5440 | do_sections = true; | |
5441 | do_section_groups = true; | |
5442 | do_segments = true; | |
5443 | do_version = true; | |
5444 | do_histogram = true; | |
5445 | do_arch = true; | |
5446 | do_notes = true; | |
5447 | break; | |
5448 | ||
5449 | case 'g': | |
5450 | do_section_groups = true; | |
5451 | break; | |
5452 | case 't': | |
5453 | case 'N': | |
5454 | do_sections = true; | |
5455 | do_section_details = true; | |
5456 | break; | |
5457 | case 'e': | |
5458 | do_header = true; | |
5459 | do_sections = true; | |
5460 | do_segments = true; | |
5461 | break; | |
5462 | case 'A': | |
5463 | do_arch = true; | |
5464 | break; | |
5465 | case 'D': | |
5466 | do_using_dynamic = true; | |
5467 | break; | |
5468 | case 'r': | |
5469 | do_reloc = true; | |
5470 | break; | |
5471 | case 'u': | |
5472 | do_unwind = true; | |
5473 | break; | |
5474 | case 'h': | |
5475 | do_header = true; | |
5476 | break; | |
5477 | case 'l': | |
5478 | do_segments = true; | |
5479 | break; | |
5480 | case 's': | |
5481 | do_syms = true; | |
5482 | break; | |
5483 | case 'S': | |
5484 | do_sections = true; | |
5485 | break; | |
5486 | case 'd': | |
5487 | do_dynamic = true; | |
5488 | break; | |
5489 | case 'I': | |
5490 | do_histogram = true; | |
5491 | break; | |
5492 | case 'n': | |
5493 | do_notes = true; | |
5494 | break; | |
5495 | case 'c': | |
5496 | do_archive_index = true; | |
5497 | break; | |
5498 | case 'L': | |
5499 | do_checks = true; | |
5500 | break; | |
5501 | case 'P': | |
5502 | process_links = true; | |
5503 | do_follow_links = true; | |
5504 | dump_any_debugging = true; | |
5505 | break; | |
5506 | case 'x': | |
5507 | request_dump (dumpdata, HEX_DUMP); | |
5508 | break; | |
5509 | case 'p': | |
5510 | request_dump (dumpdata, STRING_DUMP); | |
5511 | break; | |
5512 | case 'R': | |
5513 | request_dump (dumpdata, RELOC_DUMP); | |
5514 | break; | |
5515 | case 'z': | |
5516 | decompress_dumps = true; | |
5517 | break; | |
5518 | case 'w': | |
5519 | if (optarg == NULL) | |
5520 | { | |
5521 | do_debugging = true; | |
5522 | do_dump = true; | |
5523 | dump_any_debugging = true; | |
5524 | dwarf_select_sections_all (); | |
5525 | } | |
5526 | else | |
5527 | { | |
5528 | do_debugging = false; | |
5529 | if (dwarf_select_sections_by_letters (optarg)) | |
5530 | { | |
5531 | do_dump = true; | |
5532 | dump_any_debugging = true; | |
5533 | } | |
5534 | } | |
5535 | break; | |
5536 | case OPTION_DEBUG_DUMP: | |
5537 | if (optarg == NULL) | |
5538 | { | |
5539 | do_dump = true; | |
5540 | do_debugging = true; | |
5541 | dump_any_debugging = true; | |
5542 | dwarf_select_sections_all (); | |
5543 | } | |
5544 | else | |
5545 | { | |
5546 | do_debugging = false; | |
5547 | if (dwarf_select_sections_by_names (optarg)) | |
5548 | { | |
5549 | do_dump = true; | |
5550 | dump_any_debugging = true; | |
5551 | } | |
5552 | } | |
5553 | break; | |
5554 | case OPTION_DWARF_DEPTH: | |
5555 | { | |
5556 | char *cp; | |
5557 | ||
5558 | dwarf_cutoff_level = strtoul (optarg, & cp, 0); | |
5559 | } | |
5560 | break; | |
5561 | case OPTION_DWARF_START: | |
5562 | { | |
5563 | char *cp; | |
5564 | ||
5565 | dwarf_start_die = strtoul (optarg, & cp, 0); | |
5566 | } | |
5567 | break; | |
5568 | case OPTION_DWARF_CHECK: | |
5569 | dwarf_check = true; | |
5570 | break; | |
5571 | case OPTION_CTF_DUMP: | |
5572 | do_ctf = true; | |
5573 | request_dump (dumpdata, CTF_DUMP); | |
5574 | break; | |
5575 | case OPTION_CTF_SYMBOLS: | |
5576 | free (dump_ctf_symtab_name); | |
5577 | dump_ctf_symtab_name = strdup (optarg); | |
5578 | break; | |
5579 | case OPTION_CTF_STRINGS: | |
5580 | free (dump_ctf_strtab_name); | |
5581 | dump_ctf_strtab_name = strdup (optarg); | |
5582 | break; | |
5583 | case OPTION_CTF_PARENT: | |
5584 | free (dump_ctf_parent_name); | |
5585 | dump_ctf_parent_name = strdup (optarg); | |
5586 | break; | |
5587 | case OPTION_SFRAME_DUMP: | |
5588 | do_sframe = true; | |
5589 | /* Providing section name is optional. request_dump (), however, | |
5590 | thrives on non NULL optarg. Handle it explicitly here. */ | |
5591 | if (optarg != NULL) | |
5592 | request_dump (dumpdata, SFRAME_DUMP); | |
5593 | else | |
5594 | { | |
5595 | do_dump = true; | |
5596 | const char *sframe_sec_name = strdup (".sframe"); | |
5597 | request_dump_byname (sframe_sec_name, SFRAME_DUMP); | |
5598 | } | |
5599 | break; | |
5600 | case OPTION_DYN_SYMS: | |
5601 | do_dyn_syms = true; | |
5602 | break; | |
5603 | case OPTION_LTO_SYMS: | |
5604 | do_lto_syms = true; | |
5605 | break; | |
5606 | #ifdef SUPPORT_DISASSEMBLY | |
5607 | case 'i': | |
5608 | request_dump (dumpdata, DISASS_DUMP); | |
5609 | break; | |
5610 | #endif | |
5611 | case 'v': | |
5612 | print_version (program_name); | |
5613 | break; | |
5614 | case 'V': | |
5615 | do_version = true; | |
5616 | break; | |
5617 | case 'W': | |
5618 | do_wide = true; | |
5619 | break; | |
5620 | case 'T': | |
5621 | do_not_show_symbol_truncation = true; | |
5622 | break; | |
5623 | case 'C': | |
5624 | do_demangle = true; | |
5625 | if (optarg != NULL) | |
5626 | { | |
5627 | enum demangling_styles style; | |
5628 | ||
5629 | style = cplus_demangle_name_to_style (optarg); | |
5630 | if (style == unknown_demangling) | |
5631 | error (_("unknown demangling style `%s'"), optarg); | |
5632 | ||
5633 | cplus_demangle_set_style (style); | |
5634 | } | |
5635 | break; | |
5636 | case OPTION_NO_DEMANGLING: | |
5637 | do_demangle = false; | |
5638 | break; | |
5639 | case OPTION_RECURSE_LIMIT: | |
5640 | demangle_flags &= ~ DMGL_NO_RECURSE_LIMIT; | |
5641 | break; | |
5642 | case OPTION_NO_RECURSE_LIMIT: | |
5643 | demangle_flags |= DMGL_NO_RECURSE_LIMIT; | |
5644 | break; | |
5645 | case OPTION_WITH_SYMBOL_VERSIONS: | |
5646 | /* Ignored for backward compatibility. */ | |
5647 | break; | |
5648 | ||
5649 | case 'U': | |
5650 | if (optarg == NULL) | |
5651 | error (_("Missing arg to -U/--unicode")); /* Can this happen ? */ | |
5652 | else if (streq (optarg, "default") || streq (optarg, "d")) | |
5653 | unicode_display = unicode_default; | |
5654 | else if (streq (optarg, "locale") || streq (optarg, "l")) | |
5655 | unicode_display = unicode_locale; | |
5656 | else if (streq (optarg, "escape") || streq (optarg, "e")) | |
5657 | unicode_display = unicode_escape; | |
5658 | else if (streq (optarg, "invalid") || streq (optarg, "i")) | |
5659 | unicode_display = unicode_invalid; | |
5660 | else if (streq (optarg, "hex") || streq (optarg, "x")) | |
5661 | unicode_display = unicode_hex; | |
5662 | else if (streq (optarg, "highlight") || streq (optarg, "h")) | |
5663 | unicode_display = unicode_highlight; | |
5664 | else | |
5665 | error (_("invalid argument to -U/--unicode: %s"), optarg); | |
5666 | break; | |
5667 | ||
5668 | case OPTION_SYM_BASE: | |
5669 | sym_base = 0; | |
5670 | if (optarg != NULL) | |
5671 | { | |
5672 | sym_base = strtoul (optarg, NULL, 0); | |
5673 | switch (sym_base) | |
5674 | { | |
5675 | case 0: | |
5676 | case 8: | |
5677 | case 10: | |
5678 | case 16: | |
5679 | break; | |
5680 | ||
5681 | default: | |
5682 | sym_base = 0; | |
5683 | break; | |
5684 | } | |
5685 | } | |
5686 | break; | |
5687 | ||
5688 | default: | |
5689 | /* xgettext:c-format */ | |
5690 | error (_("Invalid option '-%c'\n"), c); | |
5691 | /* Fall through. */ | |
5692 | case '?': | |
5693 | usage (stderr); | |
5694 | } | |
5695 | } | |
5696 | ||
5697 | if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections | |
5698 | && !do_segments && !do_header && !do_dump && !do_version | |
5699 | && !do_histogram && !do_debugging && !do_arch && !do_notes | |
5700 | && !do_section_groups && !do_archive_index | |
5701 | && !do_dyn_syms && !do_lto_syms) | |
5702 | { | |
5703 | if (do_checks) | |
5704 | { | |
5705 | check_all = true; | |
5706 | do_dynamic = do_syms = do_reloc = do_unwind = do_sections = true; | |
5707 | do_segments = do_header = do_dump = do_version = true; | |
5708 | do_histogram = do_debugging = do_arch = do_notes = true; | |
5709 | do_section_groups = do_archive_index = do_dyn_syms = true; | |
5710 | do_lto_syms = true; | |
5711 | } | |
5712 | else | |
5713 | usage (stderr); | |
5714 | } | |
5715 | } | |
5716 | ||
5717 | static const char * | |
5718 | get_elf_class (unsigned int elf_class) | |
5719 | { | |
5720 | static char buff[32]; | |
5721 | ||
5722 | switch (elf_class) | |
5723 | { | |
5724 | case ELFCLASSNONE: return _("none"); | |
5725 | case ELFCLASS32: return "ELF32"; | |
5726 | case ELFCLASS64: return "ELF64"; | |
5727 | default: | |
5728 | snprintf (buff, sizeof (buff), _("<unknown: %x>"), elf_class); | |
5729 | return buff; | |
5730 | } | |
5731 | } | |
5732 | ||
5733 | static const char * | |
5734 | get_data_encoding (unsigned int encoding) | |
5735 | { | |
5736 | static char buff[32]; | |
5737 | ||
5738 | switch (encoding) | |
5739 | { | |
5740 | case ELFDATANONE: return _("none"); | |
5741 | case ELFDATA2LSB: return _("2's complement, little endian"); | |
5742 | case ELFDATA2MSB: return _("2's complement, big endian"); | |
5743 | default: | |
5744 | snprintf (buff, sizeof (buff), _("<unknown: %x>"), encoding); | |
5745 | return buff; | |
5746 | } | |
5747 | } | |
5748 | ||
5749 | static bool | |
5750 | check_magic_number (Filedata * filedata, Elf_Internal_Ehdr * header) | |
5751 | { | |
5752 | if (header->e_ident[EI_MAG0] == ELFMAG0 | |
5753 | && header->e_ident[EI_MAG1] == ELFMAG1 | |
5754 | && header->e_ident[EI_MAG2] == ELFMAG2 | |
5755 | && header->e_ident[EI_MAG3] == ELFMAG3) | |
5756 | return true; | |
5757 | ||
5758 | /* Some compilers produce object files that are not in the ELF file format. | |
5759 | As an aid to users of readelf, try to identify these cases and suggest | |
5760 | alternative tools. | |
5761 | ||
5762 | FIXME: It is not clear if all four bytes are used as constant magic | |
5763 | valus by all compilers. It may be necessary to recode this function if | |
5764 | different tools use different length sequences. */ | |
5765 | ||
5766 | static struct | |
5767 | { | |
5768 | unsigned char magic[4]; | |
5769 | const char * obj_message; | |
5770 | const char * ar_message; | |
5771 | } | |
5772 | known_magic[] = | |
5773 | { | |
5774 | { { 'B', 'C', 0xc0, 0xde }, | |
5775 | N_("This is a LLVM bitcode file - try using llvm-bcanalyzer\n"), | |
5776 | N_("This is a LLVM bitcode file - try extracing and then using llvm-bcanalyzer\n") | |
5777 | }, | |
5778 | { { 'g', 'o', ' ', 'o' }, | |
5779 | N_("This is a GO binary file - try using 'go tool objdump' or 'go tool nm'\n"), | |
5780 | NULL | |
5781 | } | |
5782 | }; | |
5783 | int i; | |
5784 | ||
5785 | for (i = ARRAY_SIZE (known_magic); i--;) | |
5786 | { | |
5787 | if (header->e_ident[EI_MAG0] == known_magic[i].magic[0] | |
5788 | && header->e_ident[EI_MAG1] == known_magic[i].magic[1] | |
5789 | && header->e_ident[EI_MAG2] == known_magic[i].magic[2] | |
5790 | && header->e_ident[EI_MAG3] == known_magic[i].magic[3]) | |
5791 | { | |
5792 | /* Some compiler's analyzer tools do not handle archives, | |
5793 | so we provide two different kinds of error message. */ | |
5794 | if (filedata->archive_file_size > 0 | |
5795 | && known_magic[i].ar_message != NULL) | |
5796 | error ("%s", known_magic[i].ar_message); | |
5797 | else | |
5798 | error ("%s", known_magic[i].obj_message); | |
5799 | return false; | |
5800 | } | |
5801 | } | |
5802 | ||
5803 | error (_("Not an ELF file - it has the wrong magic bytes at the start\n")); | |
5804 | return false; | |
5805 | } | |
5806 | ||
5807 | /* Decode the data held in 'filedata->file_header'. */ | |
5808 | ||
5809 | static bool | |
5810 | process_file_header (Filedata * filedata) | |
5811 | { | |
5812 | Elf_Internal_Ehdr * header = & filedata->file_header; | |
5813 | ||
5814 | if (! check_magic_number (filedata, header)) | |
5815 | return false; | |
5816 | ||
5817 | if (! filedata->is_separate) | |
5818 | init_dwarf_regnames_by_elf_machine_code (header->e_machine); | |
5819 | ||
5820 | if (do_header) | |
5821 | { | |
5822 | unsigned i; | |
5823 | ||
5824 | if (filedata->is_separate) | |
5825 | printf (_("ELF Header in linked file '%s':\n"), filedata->file_name); | |
5826 | else | |
5827 | printf (_("ELF Header:\n")); | |
5828 | printf (_(" Magic: ")); | |
5829 | for (i = 0; i < EI_NIDENT; i++) | |
5830 | printf ("%2.2x ", header->e_ident[i]); | |
5831 | printf ("\n"); | |
5832 | printf (_(" Class: %s\n"), | |
5833 | get_elf_class (header->e_ident[EI_CLASS])); | |
5834 | printf (_(" Data: %s\n"), | |
5835 | get_data_encoding (header->e_ident[EI_DATA])); | |
5836 | printf (_(" Version: %d%s\n"), | |
5837 | header->e_ident[EI_VERSION], | |
5838 | (header->e_ident[EI_VERSION] == EV_CURRENT | |
5839 | ? _(" (current)") | |
5840 | : (header->e_ident[EI_VERSION] != EV_NONE | |
5841 | ? _(" <unknown>") | |
5842 | : ""))); | |
5843 | printf (_(" OS/ABI: %s\n"), | |
5844 | get_osabi_name (filedata, header->e_ident[EI_OSABI])); | |
5845 | printf (_(" ABI Version: %d\n"), | |
5846 | header->e_ident[EI_ABIVERSION]); | |
5847 | printf (_(" Type: %s\n"), | |
5848 | get_file_type (filedata)); | |
5849 | printf (_(" Machine: %s\n"), | |
5850 | get_machine_name (header->e_machine)); | |
5851 | printf (_(" Version: 0x%lx\n"), | |
5852 | header->e_version); | |
5853 | ||
5854 | printf (_(" Entry point address: ")); | |
5855 | print_vma (header->e_entry, PREFIX_HEX); | |
5856 | printf (_("\n Start of program headers: ")); | |
5857 | print_vma (header->e_phoff, DEC); | |
5858 | printf (_(" (bytes into file)\n Start of section headers: ")); | |
5859 | print_vma (header->e_shoff, DEC); | |
5860 | printf (_(" (bytes into file)\n")); | |
5861 | ||
5862 | printf (_(" Flags: 0x%lx%s\n"), | |
5863 | header->e_flags, | |
5864 | get_machine_flags (filedata, header->e_flags, header->e_machine)); | |
5865 | printf (_(" Size of this header: %u (bytes)\n"), | |
5866 | header->e_ehsize); | |
5867 | printf (_(" Size of program headers: %u (bytes)\n"), | |
5868 | header->e_phentsize); | |
5869 | printf (_(" Number of program headers: %u"), | |
5870 | header->e_phnum); | |
5871 | if (filedata->section_headers != NULL | |
5872 | && header->e_phnum == PN_XNUM | |
5873 | && filedata->section_headers[0].sh_info != 0) | |
5874 | printf (" (%u)", filedata->section_headers[0].sh_info); | |
5875 | putc ('\n', stdout); | |
5876 | printf (_(" Size of section headers: %u (bytes)\n"), | |
5877 | header->e_shentsize); | |
5878 | printf (_(" Number of section headers: %u"), | |
5879 | header->e_shnum); | |
5880 | if (filedata->section_headers != NULL && header->e_shnum == SHN_UNDEF) | |
5881 | { | |
5882 | header->e_shnum = filedata->section_headers[0].sh_size; | |
5883 | printf (" (%u)", header->e_shnum); | |
5884 | } | |
5885 | putc ('\n', stdout); | |
5886 | printf (_(" Section header string table index: %u"), | |
5887 | header->e_shstrndx); | |
5888 | if (filedata->section_headers != NULL | |
5889 | && header->e_shstrndx == (SHN_XINDEX & 0xffff)) | |
5890 | { | |
5891 | header->e_shstrndx = filedata->section_headers[0].sh_link; | |
5892 | printf (" (%u)", header->e_shstrndx); | |
5893 | } | |
5894 | if (header->e_shstrndx != SHN_UNDEF | |
5895 | && header->e_shstrndx >= header->e_shnum) | |
5896 | { | |
5897 | header->e_shstrndx = SHN_UNDEF; | |
5898 | printf (_(" <corrupt: out of range>")); | |
5899 | } | |
5900 | putc ('\n', stdout); | |
5901 | } | |
5902 | ||
5903 | if (filedata->section_headers != NULL) | |
5904 | { | |
5905 | if (header->e_phnum == PN_XNUM | |
5906 | && filedata->section_headers[0].sh_info != 0) | |
5907 | { | |
5908 | /* Throw away any cached read of PN_XNUM headers. */ | |
5909 | free (filedata->program_headers); | |
5910 | filedata->program_headers = NULL; | |
5911 | header->e_phnum = filedata->section_headers[0].sh_info; | |
5912 | } | |
5913 | if (header->e_shnum == SHN_UNDEF) | |
5914 | header->e_shnum = filedata->section_headers[0].sh_size; | |
5915 | if (header->e_shstrndx == (SHN_XINDEX & 0xffff)) | |
5916 | header->e_shstrndx = filedata->section_headers[0].sh_link; | |
5917 | if (header->e_shstrndx >= header->e_shnum) | |
5918 | header->e_shstrndx = SHN_UNDEF; | |
5919 | } | |
5920 | ||
5921 | return true; | |
5922 | } | |
5923 | ||
5924 | /* Read in the program headers from FILEDATA and store them in PHEADERS. | |
5925 | Returns TRUE upon success, FALSE otherwise. Loads 32-bit headers. */ | |
5926 | ||
5927 | static bool | |
5928 | get_32bit_program_headers (Filedata * filedata, Elf_Internal_Phdr * pheaders) | |
5929 | { | |
5930 | Elf32_External_Phdr * phdrs; | |
5931 | Elf32_External_Phdr * external; | |
5932 | Elf_Internal_Phdr * internal; | |
5933 | unsigned int i; | |
5934 | unsigned int size = filedata->file_header.e_phentsize; | |
5935 | unsigned int num = filedata->file_header.e_phnum; | |
5936 | ||
5937 | /* PR binutils/17531: Cope with unexpected section header sizes. */ | |
5938 | if (size == 0 || num == 0) | |
5939 | return false; | |
5940 | if (size < sizeof * phdrs) | |
5941 | { | |
5942 | error (_("The e_phentsize field in the ELF header is less than the size of an ELF program header\n")); | |
5943 | return false; | |
5944 | } | |
5945 | if (size > sizeof * phdrs) | |
5946 | warn (_("The e_phentsize field in the ELF header is larger than the size of an ELF program header\n")); | |
5947 | ||
5948 | phdrs = (Elf32_External_Phdr *) get_data (NULL, filedata, filedata->file_header.e_phoff, | |
5949 | size, num, _("program headers")); | |
5950 | if (phdrs == NULL) | |
5951 | return false; | |
5952 | ||
5953 | for (i = 0, internal = pheaders, external = phdrs; | |
5954 | i < filedata->file_header.e_phnum; | |
5955 | i++, internal++, external++) | |
5956 | { | |
5957 | internal->p_type = BYTE_GET (external->p_type); | |
5958 | internal->p_offset = BYTE_GET (external->p_offset); | |
5959 | internal->p_vaddr = BYTE_GET (external->p_vaddr); | |
5960 | internal->p_paddr = BYTE_GET (external->p_paddr); | |
5961 | internal->p_filesz = BYTE_GET (external->p_filesz); | |
5962 | internal->p_memsz = BYTE_GET (external->p_memsz); | |
5963 | internal->p_flags = BYTE_GET (external->p_flags); | |
5964 | internal->p_align = BYTE_GET (external->p_align); | |
5965 | } | |
5966 | ||
5967 | free (phdrs); | |
5968 | return true; | |
5969 | } | |
5970 | ||
5971 | /* Read in the program headers from FILEDATA and store them in PHEADERS. | |
5972 | Returns TRUE upon success, FALSE otherwise. Loads 64-bit headers. */ | |
5973 | ||
5974 | static bool | |
5975 | get_64bit_program_headers (Filedata * filedata, Elf_Internal_Phdr * pheaders) | |
5976 | { | |
5977 | Elf64_External_Phdr * phdrs; | |
5978 | Elf64_External_Phdr * external; | |
5979 | Elf_Internal_Phdr * internal; | |
5980 | unsigned int i; | |
5981 | unsigned int size = filedata->file_header.e_phentsize; | |
5982 | unsigned int num = filedata->file_header.e_phnum; | |
5983 | ||
5984 | /* PR binutils/17531: Cope with unexpected section header sizes. */ | |
5985 | if (size == 0 || num == 0) | |
5986 | return false; | |
5987 | if (size < sizeof * phdrs) | |
5988 | { | |
5989 | error (_("The e_phentsize field in the ELF header is less than the size of an ELF program header\n")); | |
5990 | return false; | |
5991 | } | |
5992 | if (size > sizeof * phdrs) | |
5993 | warn (_("The e_phentsize field in the ELF header is larger than the size of an ELF program header\n")); | |
5994 | ||
5995 | phdrs = (Elf64_External_Phdr *) get_data (NULL, filedata, filedata->file_header.e_phoff, | |
5996 | size, num, _("program headers")); | |
5997 | if (!phdrs) | |
5998 | return false; | |
5999 | ||
6000 | for (i = 0, internal = pheaders, external = phdrs; | |
6001 | i < filedata->file_header.e_phnum; | |
6002 | i++, internal++, external++) | |
6003 | { | |
6004 | internal->p_type = BYTE_GET (external->p_type); | |
6005 | internal->p_flags = BYTE_GET (external->p_flags); | |
6006 | internal->p_offset = BYTE_GET (external->p_offset); | |
6007 | internal->p_vaddr = BYTE_GET (external->p_vaddr); | |
6008 | internal->p_paddr = BYTE_GET (external->p_paddr); | |
6009 | internal->p_filesz = BYTE_GET (external->p_filesz); | |
6010 | internal->p_memsz = BYTE_GET (external->p_memsz); | |
6011 | internal->p_align = BYTE_GET (external->p_align); | |
6012 | } | |
6013 | ||
6014 | free (phdrs); | |
6015 | return true; | |
6016 | } | |
6017 | ||
6018 | /* Returns TRUE if the program headers were read into `program_headers'. */ | |
6019 | ||
6020 | static bool | |
6021 | get_program_headers (Filedata * filedata) | |
6022 | { | |
6023 | Elf_Internal_Phdr * phdrs; | |
6024 | ||
6025 | /* Check cache of prior read. */ | |
6026 | if (filedata->program_headers != NULL) | |
6027 | return true; | |
6028 | ||
6029 | /* Be kind to memory checkers by looking for | |
6030 | e_phnum values which we know must be invalid. */ | |
6031 | if (filedata->file_header.e_phnum | |
6032 | * (is_32bit_elf ? sizeof (Elf32_External_Phdr) : sizeof (Elf64_External_Phdr)) | |
6033 | >= filedata->file_size) | |
6034 | { | |
6035 | error (_("Too many program headers - %#x - the file is not that big\n"), | |
6036 | filedata->file_header.e_phnum); | |
6037 | return false; | |
6038 | } | |
6039 | ||
6040 | phdrs = (Elf_Internal_Phdr *) cmalloc (filedata->file_header.e_phnum, | |
6041 | sizeof (Elf_Internal_Phdr)); | |
6042 | if (phdrs == NULL) | |
6043 | { | |
6044 | error (_("Out of memory reading %u program headers\n"), | |
6045 | filedata->file_header.e_phnum); | |
6046 | return false; | |
6047 | } | |
6048 | ||
6049 | if (is_32bit_elf | |
6050 | ? get_32bit_program_headers (filedata, phdrs) | |
6051 | : get_64bit_program_headers (filedata, phdrs)) | |
6052 | { | |
6053 | filedata->program_headers = phdrs; | |
6054 | return true; | |
6055 | } | |
6056 | ||
6057 | free (phdrs); | |
6058 | return false; | |
6059 | } | |
6060 | ||
6061 | /* Print program header info and locate dynamic section. */ | |
6062 | ||
6063 | static void | |
6064 | process_program_headers (Filedata * filedata) | |
6065 | { | |
6066 | Elf_Internal_Phdr * segment; | |
6067 | unsigned int i; | |
6068 | Elf_Internal_Phdr * previous_load = NULL; | |
6069 | ||
6070 | if (filedata->file_header.e_phnum == 0) | |
6071 | { | |
6072 | /* PR binutils/12467. */ | |
6073 | if (filedata->file_header.e_phoff != 0) | |
6074 | warn (_("possibly corrupt ELF header - it has a non-zero program" | |
6075 | " header offset, but no program headers\n")); | |
6076 | else if (do_segments) | |
6077 | { | |
6078 | if (filedata->is_separate) | |
6079 | printf (_("\nThere are no program headers in linked file '%s'.\n"), | |
6080 | filedata->file_name); | |
6081 | else | |
6082 | printf (_("\nThere are no program headers in this file.\n")); | |
6083 | } | |
6084 | goto no_headers; | |
6085 | } | |
6086 | ||
6087 | if (do_segments && !do_header) | |
6088 | { | |
6089 | if (filedata->is_separate) | |
6090 | printf ("\nIn linked file '%s' the ELF file type is %s\n", | |
6091 | filedata->file_name, get_file_type (filedata)); | |
6092 | else | |
6093 | printf (_("\nElf file type is %s\n"), get_file_type (filedata)); | |
6094 | printf (_("Entry point 0x%" PRIx64 "\n"), | |
6095 | filedata->file_header.e_entry); | |
6096 | printf (ngettext ("There is %d program header," | |
6097 | " starting at offset %" PRIu64 "\n", | |
6098 | "There are %d program headers," | |
6099 | " starting at offset %" PRIu64 "\n", | |
6100 | filedata->file_header.e_phnum), | |
6101 | filedata->file_header.e_phnum, | |
6102 | filedata->file_header.e_phoff); | |
6103 | } | |
6104 | ||
6105 | if (! get_program_headers (filedata)) | |
6106 | goto no_headers; | |
6107 | ||
6108 | if (do_segments) | |
6109 | { | |
6110 | if (filedata->file_header.e_phnum > 1) | |
6111 | printf (_("\nProgram Headers:\n")); | |
6112 | else | |
6113 | printf (_("\nProgram Headers:\n")); | |
6114 | ||
6115 | if (is_32bit_elf) | |
6116 | printf | |
6117 | (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n")); | |
6118 | else if (do_wide) | |
6119 | printf | |
6120 | (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n")); | |
6121 | else | |
6122 | { | |
6123 | printf | |
6124 | (_(" Type Offset VirtAddr PhysAddr\n")); | |
6125 | printf | |
6126 | (_(" FileSiz MemSiz Flags Align\n")); | |
6127 | } | |
6128 | } | |
6129 | ||
6130 | uint64_t dynamic_addr = 0; | |
6131 | uint64_t dynamic_size = 0; | |
6132 | for (i = 0, segment = filedata->program_headers; | |
6133 | i < filedata->file_header.e_phnum; | |
6134 | i++, segment++) | |
6135 | { | |
6136 | if (do_segments) | |
6137 | { | |
6138 | printf (" %-14.14s ", get_segment_type (filedata, segment->p_type)); | |
6139 | ||
6140 | if (is_32bit_elf) | |
6141 | { | |
6142 | printf ("0x%6.6lx ", (unsigned long) segment->p_offset); | |
6143 | printf ("0x%8.8lx ", (unsigned long) segment->p_vaddr); | |
6144 | printf ("0x%8.8lx ", (unsigned long) segment->p_paddr); | |
6145 | printf ("0x%5.5lx ", (unsigned long) segment->p_filesz); | |
6146 | printf ("0x%5.5lx ", (unsigned long) segment->p_memsz); | |
6147 | printf ("%c%c%c ", | |
6148 | (segment->p_flags & PF_R ? 'R' : ' '), | |
6149 | (segment->p_flags & PF_W ? 'W' : ' '), | |
6150 | (segment->p_flags & PF_X ? 'E' : ' ')); | |
6151 | printf ("%#lx", (unsigned long) segment->p_align); | |
6152 | } | |
6153 | else if (do_wide) | |
6154 | { | |
6155 | if ((unsigned long) segment->p_offset == segment->p_offset) | |
6156 | printf ("0x%6.6lx ", (unsigned long) segment->p_offset); | |
6157 | else | |
6158 | { | |
6159 | print_vma (segment->p_offset, FULL_HEX); | |
6160 | putchar (' '); | |
6161 | } | |
6162 | ||
6163 | print_vma (segment->p_vaddr, FULL_HEX); | |
6164 | putchar (' '); | |
6165 | print_vma (segment->p_paddr, FULL_HEX); | |
6166 | putchar (' '); | |
6167 | ||
6168 | if ((unsigned long) segment->p_filesz == segment->p_filesz) | |
6169 | printf ("0x%6.6lx ", (unsigned long) segment->p_filesz); | |
6170 | else | |
6171 | { | |
6172 | print_vma (segment->p_filesz, FULL_HEX); | |
6173 | putchar (' '); | |
6174 | } | |
6175 | ||
6176 | if ((unsigned long) segment->p_memsz == segment->p_memsz) | |
6177 | printf ("0x%6.6lx", (unsigned long) segment->p_memsz); | |
6178 | else | |
6179 | { | |
6180 | print_vma (segment->p_memsz, FULL_HEX); | |
6181 | } | |
6182 | ||
6183 | printf (" %c%c%c ", | |
6184 | (segment->p_flags & PF_R ? 'R' : ' '), | |
6185 | (segment->p_flags & PF_W ? 'W' : ' '), | |
6186 | (segment->p_flags & PF_X ? 'E' : ' ')); | |
6187 | ||
6188 | if ((unsigned long) segment->p_align == segment->p_align) | |
6189 | printf ("%#lx", (unsigned long) segment->p_align); | |
6190 | else | |
6191 | { | |
6192 | print_vma (segment->p_align, PREFIX_HEX); | |
6193 | } | |
6194 | } | |
6195 | else | |
6196 | { | |
6197 | print_vma (segment->p_offset, FULL_HEX); | |
6198 | putchar (' '); | |
6199 | print_vma (segment->p_vaddr, FULL_HEX); | |
6200 | putchar (' '); | |
6201 | print_vma (segment->p_paddr, FULL_HEX); | |
6202 | printf ("\n "); | |
6203 | print_vma (segment->p_filesz, FULL_HEX); | |
6204 | putchar (' '); | |
6205 | print_vma (segment->p_memsz, FULL_HEX); | |
6206 | printf (" %c%c%c ", | |
6207 | (segment->p_flags & PF_R ? 'R' : ' '), | |
6208 | (segment->p_flags & PF_W ? 'W' : ' '), | |
6209 | (segment->p_flags & PF_X ? 'E' : ' ')); | |
6210 | print_vma (segment->p_align, PREFIX_HEX); | |
6211 | } | |
6212 | ||
6213 | putc ('\n', stdout); | |
6214 | } | |
6215 | ||
6216 | switch (segment->p_type) | |
6217 | { | |
6218 | case PT_LOAD: | |
6219 | #if 0 /* Do not warn about out of order PT_LOAD segments. Although officially | |
6220 | required by the ELF standard, several programs, including the Linux | |
6221 | kernel, make use of non-ordered segments. */ | |
6222 | if (previous_load | |
6223 | && previous_load->p_vaddr > segment->p_vaddr) | |
6224 | error (_("LOAD segments must be sorted in order of increasing VirtAddr\n")); | |
6225 | #endif | |
6226 | if (segment->p_memsz < segment->p_filesz) | |
6227 | error (_("the segment's file size is larger than its memory size\n")); | |
6228 | previous_load = segment; | |
6229 | break; | |
6230 | ||
6231 | case PT_PHDR: | |
6232 | /* PR 20815 - Verify that the program header is loaded into memory. */ | |
6233 | if (i > 0 && previous_load != NULL) | |
6234 | error (_("the PHDR segment must occur before any LOAD segment\n")); | |
6235 | if (filedata->file_header.e_machine != EM_PARISC) | |
6236 | { | |
6237 | unsigned int j; | |
6238 | ||
6239 | for (j = 1; j < filedata->file_header.e_phnum; j++) | |
6240 | { | |
6241 | Elf_Internal_Phdr *load = filedata->program_headers + j; | |
6242 | if (load->p_type == PT_LOAD | |
6243 | && load->p_offset <= segment->p_offset | |
6244 | && (load->p_offset + load->p_filesz | |
6245 | >= segment->p_offset + segment->p_filesz) | |
6246 | && load->p_vaddr <= segment->p_vaddr | |
6247 | && (load->p_vaddr + load->p_filesz | |
6248 | >= segment->p_vaddr + segment->p_filesz)) | |
6249 | break; | |
6250 | } | |
6251 | if (j == filedata->file_header.e_phnum) | |
6252 | error (_("the PHDR segment is not covered by a LOAD segment\n")); | |
6253 | } | |
6254 | break; | |
6255 | ||
6256 | case PT_DYNAMIC: | |
6257 | if (dynamic_addr) | |
6258 | error (_("more than one dynamic segment\n")); | |
6259 | ||
6260 | /* By default, assume that the .dynamic section is the first | |
6261 | section in the DYNAMIC segment. */ | |
6262 | dynamic_addr = segment->p_offset; | |
6263 | dynamic_size = segment->p_filesz; | |
6264 | ||
6265 | /* Try to locate the .dynamic section. If there is | |
6266 | a section header table, we can easily locate it. */ | |
6267 | if (filedata->section_headers != NULL) | |
6268 | { | |
6269 | Elf_Internal_Shdr * sec; | |
6270 | ||
6271 | sec = find_section (filedata, ".dynamic"); | |
6272 | if (sec == NULL || sec->sh_size == 0) | |
6273 | { | |
6274 | /* A corresponding .dynamic section is expected, but on | |
6275 | IA-64/OpenVMS it is OK for it to be missing. */ | |
6276 | if (!is_ia64_vms (filedata)) | |
6277 | error (_("no .dynamic section in the dynamic segment\n")); | |
6278 | break; | |
6279 | } | |
6280 | ||
6281 | if (sec->sh_type == SHT_NOBITS) | |
6282 | { | |
6283 | dynamic_addr = 0; | |
6284 | dynamic_size = 0; | |
6285 | break; | |
6286 | } | |
6287 | ||
6288 | dynamic_addr = sec->sh_offset; | |
6289 | dynamic_size = sec->sh_size; | |
6290 | ||
6291 | /* The PT_DYNAMIC segment, which is used by the run-time | |
6292 | loader, should exactly match the .dynamic section. */ | |
6293 | if (do_checks | |
6294 | && (dynamic_addr != segment->p_offset | |
6295 | || dynamic_size != segment->p_filesz)) | |
6296 | warn (_("\ | |
6297 | the .dynamic section is not the same as the dynamic segment\n")); | |
6298 | } | |
6299 | ||
6300 | /* PR binutils/17512: Avoid corrupt dynamic section info in the | |
6301 | segment. Check this after matching against the section headers | |
6302 | so we don't warn on debuginfo file (which have NOBITS .dynamic | |
6303 | sections). */ | |
6304 | if (dynamic_addr > filedata->file_size | |
6305 | || (dynamic_size > filedata->file_size - dynamic_addr)) | |
6306 | { | |
6307 | error (_("the dynamic segment offset + size exceeds the size of the file\n")); | |
6308 | dynamic_addr = 0; | |
6309 | dynamic_size = 0; | |
6310 | } | |
6311 | break; | |
6312 | ||
6313 | case PT_INTERP: | |
6314 | if (segment->p_offset >= filedata->file_size | |
6315 | || segment->p_filesz > filedata->file_size - segment->p_offset | |
6316 | || segment->p_filesz - 1 >= (size_t) -2 | |
6317 | || fseek64 (filedata->handle, | |
6318 | filedata->archive_file_offset + segment->p_offset, | |
6319 | SEEK_SET)) | |
6320 | error (_("Unable to find program interpreter name\n")); | |
6321 | else | |
6322 | { | |
6323 | size_t len = segment->p_filesz; | |
6324 | free (filedata->program_interpreter); | |
6325 | filedata->program_interpreter = xmalloc (len + 1); | |
6326 | len = fread (filedata->program_interpreter, 1, len, | |
6327 | filedata->handle); | |
6328 | filedata->program_interpreter[len] = 0; | |
6329 | ||
6330 | if (do_segments) | |
6331 | printf (_(" [Requesting program interpreter: %s]\n"), | |
6332 | filedata->program_interpreter); | |
6333 | } | |
6334 | break; | |
6335 | } | |
6336 | } | |
6337 | ||
6338 | if (do_segments | |
6339 | && filedata->section_headers != NULL | |
6340 | && filedata->string_table != NULL) | |
6341 | { | |
6342 | printf (_("\n Section to Segment mapping:\n")); | |
6343 | printf (_(" Segment Sections...\n")); | |
6344 | ||
6345 | for (i = 0; i < filedata->file_header.e_phnum; i++) | |
6346 | { | |
6347 | unsigned int j; | |
6348 | Elf_Internal_Shdr * section; | |
6349 | ||
6350 | segment = filedata->program_headers + i; | |
6351 | section = filedata->section_headers + 1; | |
6352 | ||
6353 | printf (" %2.2d ", i); | |
6354 | ||
6355 | for (j = 1; j < filedata->file_header.e_shnum; j++, section++) | |
6356 | { | |
6357 | if (!ELF_TBSS_SPECIAL (section, segment) | |
6358 | && ELF_SECTION_IN_SEGMENT_STRICT (section, segment)) | |
6359 | printf ("%s ", printable_section_name (filedata, section)); | |
6360 | } | |
6361 | ||
6362 | putc ('\n',stdout); | |
6363 | } | |
6364 | } | |
6365 | ||
6366 | filedata->dynamic_addr = dynamic_addr; | |
6367 | filedata->dynamic_size = dynamic_size ? dynamic_size : 1; | |
6368 | return; | |
6369 | ||
6370 | no_headers: | |
6371 | filedata->dynamic_addr = 0; | |
6372 | filedata->dynamic_size = 1; | |
6373 | } | |
6374 | ||
6375 | ||
6376 | /* Find the file offset corresponding to VMA by using the program headers. */ | |
6377 | ||
6378 | static int64_t | |
6379 | offset_from_vma (Filedata * filedata, uint64_t vma, uint64_t size) | |
6380 | { | |
6381 | Elf_Internal_Phdr * seg; | |
6382 | ||
6383 | if (! get_program_headers (filedata)) | |
6384 | { | |
6385 | warn (_("Cannot interpret virtual addresses without program headers.\n")); | |
6386 | return (long) vma; | |
6387 | } | |
6388 | ||
6389 | for (seg = filedata->program_headers; | |
6390 | seg < filedata->program_headers + filedata->file_header.e_phnum; | |
6391 | ++seg) | |
6392 | { | |
6393 | if (seg->p_type != PT_LOAD) | |
6394 | continue; | |
6395 | ||
6396 | if (vma >= (seg->p_vaddr & -seg->p_align) | |
6397 | && vma + size <= seg->p_vaddr + seg->p_filesz) | |
6398 | return vma - seg->p_vaddr + seg->p_offset; | |
6399 | } | |
6400 | ||
6401 | warn (_("Virtual address %#" PRIx64 | |
6402 | " not located in any PT_LOAD segment.\n"), vma); | |
6403 | return vma; | |
6404 | } | |
6405 | ||
6406 | ||
6407 | /* Allocate memory and load the sections headers into FILEDATA->filedata->section_headers. | |
6408 | If PROBE is true, this is just a probe and we do not generate any error | |
6409 | messages if the load fails. */ | |
6410 | ||
6411 | static bool | |
6412 | get_32bit_section_headers (Filedata * filedata, bool probe) | |
6413 | { | |
6414 | Elf32_External_Shdr * shdrs; | |
6415 | Elf_Internal_Shdr * internal; | |
6416 | unsigned int i; | |
6417 | unsigned int size = filedata->file_header.e_shentsize; | |
6418 | unsigned int num = probe ? 1 : filedata->file_header.e_shnum; | |
6419 | ||
6420 | /* PR binutils/17531: Cope with unexpected section header sizes. */ | |
6421 | if (size == 0 || num == 0) | |
6422 | return false; | |
6423 | ||
6424 | /* The section header cannot be at the start of the file - that is | |
6425 | where the ELF file header is located. A file with absolutely no | |
6426 | sections in it will use a shoff of 0. */ | |
6427 | if (filedata->file_header.e_shoff == 0) | |
6428 | return false; | |
6429 | ||
6430 | if (size < sizeof * shdrs) | |
6431 | { | |
6432 | if (! probe) | |
6433 | error (_("The e_shentsize field in the ELF header is less than the size of an ELF section header\n")); | |
6434 | return false; | |
6435 | } | |
6436 | if (!probe && size > sizeof * shdrs) | |
6437 | warn (_("The e_shentsize field in the ELF header is larger than the size of an ELF section header\n")); | |
6438 | ||
6439 | shdrs = (Elf32_External_Shdr *) get_data (NULL, filedata, filedata->file_header.e_shoff, | |
6440 | size, num, | |
6441 | probe ? NULL : _("section headers")); | |
6442 | if (shdrs == NULL) | |
6443 | return false; | |
6444 | ||
6445 | filedata->section_headers = (Elf_Internal_Shdr *) | |
6446 | cmalloc (num, sizeof (Elf_Internal_Shdr)); | |
6447 | if (filedata->section_headers == NULL) | |
6448 | { | |
6449 | if (!probe) | |
6450 | error (_("Out of memory reading %u section headers\n"), num); | |
6451 | free (shdrs); | |
6452 | return false; | |
6453 | } | |
6454 | ||
6455 | for (i = 0, internal = filedata->section_headers; | |
6456 | i < num; | |
6457 | i++, internal++) | |
6458 | { | |
6459 | internal->sh_name = BYTE_GET (shdrs[i].sh_name); | |
6460 | internal->sh_type = BYTE_GET (shdrs[i].sh_type); | |
6461 | internal->sh_flags = BYTE_GET (shdrs[i].sh_flags); | |
6462 | internal->sh_addr = BYTE_GET (shdrs[i].sh_addr); | |
6463 | internal->sh_offset = BYTE_GET (shdrs[i].sh_offset); | |
6464 | internal->sh_size = BYTE_GET (shdrs[i].sh_size); | |
6465 | internal->sh_link = BYTE_GET (shdrs[i].sh_link); | |
6466 | internal->sh_info = BYTE_GET (shdrs[i].sh_info); | |
6467 | internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign); | |
6468 | internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize); | |
6469 | if (!probe && internal->sh_link > num) | |
6470 | warn (_("Section %u has an out of range sh_link value of %u\n"), i, internal->sh_link); | |
6471 | if (!probe && internal->sh_flags & SHF_INFO_LINK && internal->sh_info > num) | |
6472 | warn (_("Section %u has an out of range sh_info value of %u\n"), i, internal->sh_info); | |
6473 | } | |
6474 | ||
6475 | free (shdrs); | |
6476 | return true; | |
6477 | } | |
6478 | ||
6479 | /* Like get_32bit_section_headers, except that it fetches 64-bit headers. */ | |
6480 | ||
6481 | static bool | |
6482 | get_64bit_section_headers (Filedata * filedata, bool probe) | |
6483 | { | |
6484 | Elf64_External_Shdr * shdrs; | |
6485 | Elf_Internal_Shdr * internal; | |
6486 | unsigned int i; | |
6487 | unsigned int size = filedata->file_header.e_shentsize; | |
6488 | unsigned int num = probe ? 1 : filedata->file_header.e_shnum; | |
6489 | ||
6490 | /* PR binutils/17531: Cope with unexpected section header sizes. */ | |
6491 | if (size == 0 || num == 0) | |
6492 | return false; | |
6493 | ||
6494 | /* The section header cannot be at the start of the file - that is | |
6495 | where the ELF file header is located. A file with absolutely no | |
6496 | sections in it will use a shoff of 0. */ | |
6497 | if (filedata->file_header.e_shoff == 0) | |
6498 | return false; | |
6499 | ||
6500 | if (size < sizeof * shdrs) | |
6501 | { | |
6502 | if (! probe) | |
6503 | error (_("The e_shentsize field in the ELF header is less than the size of an ELF section header\n")); | |
6504 | return false; | |
6505 | } | |
6506 | ||
6507 | if (! probe && size > sizeof * shdrs) | |
6508 | warn (_("The e_shentsize field in the ELF header is larger than the size of an ELF section header\n")); | |
6509 | ||
6510 | shdrs = (Elf64_External_Shdr *) get_data (NULL, filedata, | |
6511 | filedata->file_header.e_shoff, | |
6512 | size, num, | |
6513 | probe ? NULL : _("section headers")); | |
6514 | if (shdrs == NULL) | |
6515 | return false; | |
6516 | ||
6517 | filedata->section_headers = (Elf_Internal_Shdr *) | |
6518 | cmalloc (num, sizeof (Elf_Internal_Shdr)); | |
6519 | if (filedata->section_headers == NULL) | |
6520 | { | |
6521 | if (! probe) | |
6522 | error (_("Out of memory reading %u section headers\n"), num); | |
6523 | free (shdrs); | |
6524 | return false; | |
6525 | } | |
6526 | ||
6527 | for (i = 0, internal = filedata->section_headers; | |
6528 | i < num; | |
6529 | i++, internal++) | |
6530 | { | |
6531 | internal->sh_name = BYTE_GET (shdrs[i].sh_name); | |
6532 | internal->sh_type = BYTE_GET (shdrs[i].sh_type); | |
6533 | internal->sh_flags = BYTE_GET (shdrs[i].sh_flags); | |
6534 | internal->sh_addr = BYTE_GET (shdrs[i].sh_addr); | |
6535 | internal->sh_size = BYTE_GET (shdrs[i].sh_size); | |
6536 | internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize); | |
6537 | internal->sh_link = BYTE_GET (shdrs[i].sh_link); | |
6538 | internal->sh_info = BYTE_GET (shdrs[i].sh_info); | |
6539 | internal->sh_offset = BYTE_GET (shdrs[i].sh_offset); | |
6540 | internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign); | |
6541 | if (!probe && internal->sh_link > num) | |
6542 | warn (_("Section %u has an out of range sh_link value of %u\n"), i, internal->sh_link); | |
6543 | if (!probe && internal->sh_flags & SHF_INFO_LINK && internal->sh_info > num) | |
6544 | warn (_("Section %u has an out of range sh_info value of %u\n"), i, internal->sh_info); | |
6545 | } | |
6546 | ||
6547 | free (shdrs); | |
6548 | return true; | |
6549 | } | |
6550 | ||
6551 | static bool | |
6552 | get_section_headers (Filedata *filedata, bool probe) | |
6553 | { | |
6554 | if (filedata->section_headers != NULL) | |
6555 | return true; | |
6556 | ||
6557 | if (is_32bit_elf) | |
6558 | return get_32bit_section_headers (filedata, probe); | |
6559 | else | |
6560 | return get_64bit_section_headers (filedata, probe); | |
6561 | } | |
6562 | ||
6563 | static Elf_Internal_Sym * | |
6564 | get_32bit_elf_symbols (Filedata *filedata, | |
6565 | Elf_Internal_Shdr *section, | |
6566 | uint64_t *num_syms_return) | |
6567 | { | |
6568 | uint64_t number = 0; | |
6569 | Elf32_External_Sym * esyms = NULL; | |
6570 | Elf_External_Sym_Shndx * shndx = NULL; | |
6571 | Elf_Internal_Sym * isyms = NULL; | |
6572 | Elf_Internal_Sym * psym; | |
6573 | unsigned int j; | |
6574 | elf_section_list * entry; | |
6575 | ||
6576 | if (section->sh_size == 0) | |
6577 | { | |
6578 | if (num_syms_return != NULL) | |
6579 | * num_syms_return = 0; | |
6580 | return NULL; | |
6581 | } | |
6582 | ||
6583 | /* Run some sanity checks first. */ | |
6584 | if (section->sh_entsize == 0 || section->sh_entsize > section->sh_size) | |
6585 | { | |
6586 | error (_("Section %s has an invalid sh_entsize of %#" PRIx64 "\n"), | |
6587 | printable_section_name (filedata, section), | |
6588 | section->sh_entsize); | |
6589 | goto exit_point; | |
6590 | } | |
6591 | ||
6592 | if (section->sh_size > filedata->file_size) | |
6593 | { | |
6594 | error (_("Section %s has an invalid sh_size of %#" PRIx64 "\n"), | |
6595 | printable_section_name (filedata, section), | |
6596 | section->sh_size); | |
6597 | goto exit_point; | |
6598 | } | |
6599 | ||
6600 | number = section->sh_size / section->sh_entsize; | |
6601 | ||
6602 | if (number * sizeof (Elf32_External_Sym) > section->sh_size + 1) | |
6603 | { | |
6604 | error (_("Size (%#" PRIx64 ") of section %s " | |
6605 | "is not a multiple of its sh_entsize (%#" PRIx64 ")\n"), | |
6606 | section->sh_size, | |
6607 | printable_section_name (filedata, section), | |
6608 | section->sh_entsize); | |
6609 | goto exit_point; | |
6610 | } | |
6611 | ||
6612 | esyms = (Elf32_External_Sym *) get_data (NULL, filedata, section->sh_offset, 1, | |
6613 | section->sh_size, _("symbols")); | |
6614 | if (esyms == NULL) | |
6615 | goto exit_point; | |
6616 | ||
6617 | shndx = NULL; | |
6618 | for (entry = filedata->symtab_shndx_list; entry != NULL; entry = entry->next) | |
6619 | { | |
6620 | if (entry->hdr->sh_link != (size_t) (section - filedata->section_headers)) | |
6621 | continue; | |
6622 | ||
6623 | if (shndx != NULL) | |
6624 | { | |
6625 | error (_("Multiple symbol table index sections associated with the same symbol section\n")); | |
6626 | free (shndx); | |
6627 | } | |
6628 | ||
6629 | shndx = (Elf_External_Sym_Shndx *) get_data (NULL, filedata, | |
6630 | entry->hdr->sh_offset, | |
6631 | 1, entry->hdr->sh_size, | |
6632 | _("symbol table section indices")); | |
6633 | if (shndx == NULL) | |
6634 | goto exit_point; | |
6635 | ||
6636 | /* PR17531: file: heap-buffer-overflow */ | |
6637 | if (entry->hdr->sh_size / sizeof (Elf_External_Sym_Shndx) < number) | |
6638 | { | |
6639 | error (_("Index section %s has an sh_size of %#" PRIx64 " - expected %#" PRIx64 "\n"), | |
6640 | printable_section_name (filedata, entry->hdr), | |
6641 | entry->hdr->sh_size, | |
6642 | section->sh_size); | |
6643 | goto exit_point; | |
6644 | } | |
6645 | } | |
6646 | ||
6647 | isyms = (Elf_Internal_Sym *) cmalloc (number, sizeof (Elf_Internal_Sym)); | |
6648 | ||
6649 | if (isyms == NULL) | |
6650 | { | |
6651 | error (_("Out of memory reading %" PRIu64 " symbols\n"), number); | |
6652 | goto exit_point; | |
6653 | } | |
6654 | ||
6655 | for (j = 0, psym = isyms; j < number; j++, psym++) | |
6656 | { | |
6657 | psym->st_name = BYTE_GET (esyms[j].st_name); | |
6658 | psym->st_value = BYTE_GET (esyms[j].st_value); | |
6659 | psym->st_size = BYTE_GET (esyms[j].st_size); | |
6660 | psym->st_shndx = BYTE_GET (esyms[j].st_shndx); | |
6661 | if (psym->st_shndx == (SHN_XINDEX & 0xffff) && shndx != NULL) | |
6662 | psym->st_shndx | |
6663 | = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j])); | |
6664 | else if (psym->st_shndx >= (SHN_LORESERVE & 0xffff)) | |
6665 | psym->st_shndx += SHN_LORESERVE - (SHN_LORESERVE & 0xffff); | |
6666 | psym->st_info = BYTE_GET (esyms[j].st_info); | |
6667 | psym->st_other = BYTE_GET (esyms[j].st_other); | |
6668 | } | |
6669 | ||
6670 | exit_point: | |
6671 | free (shndx); | |
6672 | free (esyms); | |
6673 | ||
6674 | if (num_syms_return != NULL) | |
6675 | * num_syms_return = isyms == NULL ? 0 : number; | |
6676 | ||
6677 | return isyms; | |
6678 | } | |
6679 | ||
6680 | static Elf_Internal_Sym * | |
6681 | get_64bit_elf_symbols (Filedata *filedata, | |
6682 | Elf_Internal_Shdr *section, | |
6683 | uint64_t *num_syms_return) | |
6684 | { | |
6685 | uint64_t number = 0; | |
6686 | Elf64_External_Sym * esyms = NULL; | |
6687 | Elf_External_Sym_Shndx * shndx = NULL; | |
6688 | Elf_Internal_Sym * isyms = NULL; | |
6689 | Elf_Internal_Sym * psym; | |
6690 | unsigned int j; | |
6691 | elf_section_list * entry; | |
6692 | ||
6693 | if (section->sh_size == 0) | |
6694 | { | |
6695 | if (num_syms_return != NULL) | |
6696 | * num_syms_return = 0; | |
6697 | return NULL; | |
6698 | } | |
6699 | ||
6700 | /* Run some sanity checks first. */ | |
6701 | if (section->sh_entsize == 0 || section->sh_entsize > section->sh_size) | |
6702 | { | |
6703 | error (_("Section %s has an invalid sh_entsize of %#" PRIx64 "\n"), | |
6704 | printable_section_name (filedata, section), | |
6705 | section->sh_entsize); | |
6706 | goto exit_point; | |
6707 | } | |
6708 | ||
6709 | if (section->sh_size > filedata->file_size) | |
6710 | { | |
6711 | error (_("Section %s has an invalid sh_size of %#" PRIx64 "\n"), | |
6712 | printable_section_name (filedata, section), | |
6713 | section->sh_size); | |
6714 | goto exit_point; | |
6715 | } | |
6716 | ||
6717 | number = section->sh_size / section->sh_entsize; | |
6718 | ||
6719 | if (number * sizeof (Elf64_External_Sym) > section->sh_size + 1) | |
6720 | { | |
6721 | error (_("Size (%#" PRIx64 ") of section %s " | |
6722 | "is not a multiple of its sh_entsize (%#" PRIx64 ")\n"), | |
6723 | section->sh_size, | |
6724 | printable_section_name (filedata, section), | |
6725 | section->sh_entsize); | |
6726 | goto exit_point; | |
6727 | } | |
6728 | ||
6729 | esyms = (Elf64_External_Sym *) get_data (NULL, filedata, section->sh_offset, 1, | |
6730 | section->sh_size, _("symbols")); | |
6731 | if (!esyms) | |
6732 | goto exit_point; | |
6733 | ||
6734 | shndx = NULL; | |
6735 | for (entry = filedata->symtab_shndx_list; entry != NULL; entry = entry->next) | |
6736 | { | |
6737 | if (entry->hdr->sh_link != (size_t) (section - filedata->section_headers)) | |
6738 | continue; | |
6739 | ||
6740 | if (shndx != NULL) | |
6741 | { | |
6742 | error (_("Multiple symbol table index sections associated with the same symbol section\n")); | |
6743 | free (shndx); | |
6744 | } | |
6745 | ||
6746 | shndx = (Elf_External_Sym_Shndx *) get_data (NULL, filedata, | |
6747 | entry->hdr->sh_offset, | |
6748 | 1, entry->hdr->sh_size, | |
6749 | _("symbol table section indices")); | |
6750 | if (shndx == NULL) | |
6751 | goto exit_point; | |
6752 | ||
6753 | /* PR17531: file: heap-buffer-overflow */ | |
6754 | if (entry->hdr->sh_size / sizeof (Elf_External_Sym_Shndx) < number) | |
6755 | { | |
6756 | error (_("Index section %s has an sh_size of %#" PRIx64 " - expected %#" PRIx64 "\n"), | |
6757 | printable_section_name (filedata, entry->hdr), | |
6758 | entry->hdr->sh_size, | |
6759 | section->sh_size); | |
6760 | goto exit_point; | |
6761 | } | |
6762 | } | |
6763 | ||
6764 | isyms = (Elf_Internal_Sym *) cmalloc (number, sizeof (Elf_Internal_Sym)); | |
6765 | ||
6766 | if (isyms == NULL) | |
6767 | { | |
6768 | error (_("Out of memory reading %" PRIu64 " symbols\n"), number); | |
6769 | goto exit_point; | |
6770 | } | |
6771 | ||
6772 | for (j = 0, psym = isyms; j < number; j++, psym++) | |
6773 | { | |
6774 | psym->st_name = BYTE_GET (esyms[j].st_name); | |
6775 | psym->st_info = BYTE_GET (esyms[j].st_info); | |
6776 | psym->st_other = BYTE_GET (esyms[j].st_other); | |
6777 | psym->st_shndx = BYTE_GET (esyms[j].st_shndx); | |
6778 | ||
6779 | if (psym->st_shndx == (SHN_XINDEX & 0xffff) && shndx != NULL) | |
6780 | psym->st_shndx | |
6781 | = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j])); | |
6782 | else if (psym->st_shndx >= (SHN_LORESERVE & 0xffff)) | |
6783 | psym->st_shndx += SHN_LORESERVE - (SHN_LORESERVE & 0xffff); | |
6784 | ||
6785 | psym->st_value = BYTE_GET (esyms[j].st_value); | |
6786 | psym->st_size = BYTE_GET (esyms[j].st_size); | |
6787 | } | |
6788 | ||
6789 | exit_point: | |
6790 | free (shndx); | |
6791 | free (esyms); | |
6792 | ||
6793 | if (num_syms_return != NULL) | |
6794 | * num_syms_return = isyms == NULL ? 0 : number; | |
6795 | ||
6796 | return isyms; | |
6797 | } | |
6798 | ||
6799 | static Elf_Internal_Sym * | |
6800 | get_elf_symbols (Filedata *filedata, | |
6801 | Elf_Internal_Shdr *section, | |
6802 | uint64_t *num_syms_return) | |
6803 | { | |
6804 | if (is_32bit_elf) | |
6805 | return get_32bit_elf_symbols (filedata, section, num_syms_return); | |
6806 | else | |
6807 | return get_64bit_elf_symbols (filedata, section, num_syms_return); | |
6808 | } | |
6809 | ||
6810 | static const char * | |
6811 | get_elf_section_flags (Filedata * filedata, uint64_t sh_flags) | |
6812 | { | |
6813 | static char buff[1024]; | |
6814 | char * p = buff; | |
6815 | unsigned int field_size = is_32bit_elf ? 8 : 16; | |
6816 | signed int sindex; | |
6817 | unsigned int size = sizeof (buff) - (field_size + 4 + 1); | |
6818 | uint64_t os_flags = 0; | |
6819 | uint64_t proc_flags = 0; | |
6820 | uint64_t unknown_flags = 0; | |
6821 | static const struct | |
6822 | { | |
6823 | const char * str; | |
6824 | unsigned int len; | |
6825 | } | |
6826 | flags [] = | |
6827 | { | |
6828 | /* 0 */ { STRING_COMMA_LEN ("WRITE") }, | |
6829 | /* 1 */ { STRING_COMMA_LEN ("ALLOC") }, | |
6830 | /* 2 */ { STRING_COMMA_LEN ("EXEC") }, | |
6831 | /* 3 */ { STRING_COMMA_LEN ("MERGE") }, | |
6832 | /* 4 */ { STRING_COMMA_LEN ("STRINGS") }, | |
6833 | /* 5 */ { STRING_COMMA_LEN ("INFO LINK") }, | |
6834 | /* 6 */ { STRING_COMMA_LEN ("LINK ORDER") }, | |
6835 | /* 7 */ { STRING_COMMA_LEN ("OS NONCONF") }, | |
6836 | /* 8 */ { STRING_COMMA_LEN ("GROUP") }, | |
6837 | /* 9 */ { STRING_COMMA_LEN ("TLS") }, | |
6838 | /* IA-64 specific. */ | |
6839 | /* 10 */ { STRING_COMMA_LEN ("SHORT") }, | |
6840 | /* 11 */ { STRING_COMMA_LEN ("NORECOV") }, | |
6841 | /* IA-64 OpenVMS specific. */ | |
6842 | /* 12 */ { STRING_COMMA_LEN ("VMS_GLOBAL") }, | |
6843 | /* 13 */ { STRING_COMMA_LEN ("VMS_OVERLAID") }, | |
6844 | /* 14 */ { STRING_COMMA_LEN ("VMS_SHARED") }, | |
6845 | /* 15 */ { STRING_COMMA_LEN ("VMS_VECTOR") }, | |
6846 | /* 16 */ { STRING_COMMA_LEN ("VMS_ALLOC_64BIT") }, | |
6847 | /* 17 */ { STRING_COMMA_LEN ("VMS_PROTECTED") }, | |
6848 | /* Generic. */ | |
6849 | /* 18 */ { STRING_COMMA_LEN ("EXCLUDE") }, | |
6850 | /* SPARC specific. */ | |
6851 | /* 19 */ { STRING_COMMA_LEN ("ORDERED") }, | |
6852 | /* 20 */ { STRING_COMMA_LEN ("COMPRESSED") }, | |
6853 | /* ARM specific. */ | |
6854 | /* 21 */ { STRING_COMMA_LEN ("ENTRYSECT") }, | |
6855 | /* 22 */ { STRING_COMMA_LEN ("ARM_PURECODE") }, | |
6856 | /* 23 */ { STRING_COMMA_LEN ("COMDEF") }, | |
6857 | /* GNU specific. */ | |
6858 | /* 24 */ { STRING_COMMA_LEN ("GNU_MBIND") }, | |
6859 | /* VLE specific. */ | |
6860 | /* 25 */ { STRING_COMMA_LEN ("VLE") }, | |
6861 | /* GNU specific. */ | |
6862 | /* 26 */ { STRING_COMMA_LEN ("GNU_RETAIN") }, | |
6863 | }; | |
6864 | ||
6865 | if (do_section_details) | |
6866 | { | |
6867 | sprintf (buff, "[%*.*lx]: ", | |
6868 | field_size, field_size, (unsigned long) sh_flags); | |
6869 | p += field_size + 4; | |
6870 | } | |
6871 | ||
6872 | while (sh_flags) | |
6873 | { | |
6874 | uint64_t flag; | |
6875 | ||
6876 | flag = sh_flags & - sh_flags; | |
6877 | sh_flags &= ~ flag; | |
6878 | ||
6879 | if (do_section_details) | |
6880 | { | |
6881 | switch (flag) | |
6882 | { | |
6883 | case SHF_WRITE: sindex = 0; break; | |
6884 | case SHF_ALLOC: sindex = 1; break; | |
6885 | case SHF_EXECINSTR: sindex = 2; break; | |
6886 | case SHF_MERGE: sindex = 3; break; | |
6887 | case SHF_STRINGS: sindex = 4; break; | |
6888 | case SHF_INFO_LINK: sindex = 5; break; | |
6889 | case SHF_LINK_ORDER: sindex = 6; break; | |
6890 | case SHF_OS_NONCONFORMING: sindex = 7; break; | |
6891 | case SHF_GROUP: sindex = 8; break; | |
6892 | case SHF_TLS: sindex = 9; break; | |
6893 | case SHF_EXCLUDE: sindex = 18; break; | |
6894 | case SHF_COMPRESSED: sindex = 20; break; | |
6895 | ||
6896 | default: | |
6897 | sindex = -1; | |
6898 | switch (filedata->file_header.e_machine) | |
6899 | { | |
6900 | case EM_IA_64: | |
6901 | if (flag == SHF_IA_64_SHORT) | |
6902 | sindex = 10; | |
6903 | else if (flag == SHF_IA_64_NORECOV) | |
6904 | sindex = 11; | |
6905 | else if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_OPENVMS) | |
6906 | switch (flag) | |
6907 | { | |
6908 | case SHF_IA_64_VMS_GLOBAL: sindex = 12; break; | |
6909 | case SHF_IA_64_VMS_OVERLAID: sindex = 13; break; | |
6910 | case SHF_IA_64_VMS_SHARED: sindex = 14; break; | |
6911 | case SHF_IA_64_VMS_VECTOR: sindex = 15; break; | |
6912 | case SHF_IA_64_VMS_ALLOC_64BIT: sindex = 16; break; | |
6913 | case SHF_IA_64_VMS_PROTECTED: sindex = 17; break; | |
6914 | default: break; | |
6915 | } | |
6916 | break; | |
6917 | ||
6918 | case EM_386: | |
6919 | case EM_IAMCU: | |
6920 | case EM_X86_64: | |
6921 | case EM_L1OM: | |
6922 | case EM_K1OM: | |
6923 | case EM_OLD_SPARCV9: | |
6924 | case EM_SPARC32PLUS: | |
6925 | case EM_SPARCV9: | |
6926 | case EM_SPARC: | |
6927 | if (flag == SHF_ORDERED) | |
6928 | sindex = 19; | |
6929 | break; | |
6930 | ||
6931 | case EM_ARM: | |
6932 | switch (flag) | |
6933 | { | |
6934 | case SHF_ENTRYSECT: sindex = 21; break; | |
6935 | case SHF_ARM_PURECODE: sindex = 22; break; | |
6936 | case SHF_COMDEF: sindex = 23; break; | |
6937 | default: break; | |
6938 | } | |
6939 | break; | |
6940 | case EM_PPC: | |
6941 | if (flag == SHF_PPC_VLE) | |
6942 | sindex = 25; | |
6943 | break; | |
6944 | default: | |
6945 | break; | |
6946 | } | |
6947 | ||
6948 | switch (filedata->file_header.e_ident[EI_OSABI]) | |
6949 | { | |
6950 | case ELFOSABI_GNU: | |
6951 | case ELFOSABI_FREEBSD: | |
6952 | if (flag == SHF_GNU_RETAIN) | |
6953 | sindex = 26; | |
6954 | /* Fall through */ | |
6955 | case ELFOSABI_NONE: | |
6956 | if (flag == SHF_GNU_MBIND) | |
6957 | /* We should not recognize SHF_GNU_MBIND for | |
6958 | ELFOSABI_NONE, but binutils as of 2019-07-23 did | |
6959 | not set the EI_OSABI header byte. */ | |
6960 | sindex = 24; | |
6961 | break; | |
6962 | default: | |
6963 | break; | |
6964 | } | |
6965 | break; | |
6966 | } | |
6967 | ||
6968 | if (sindex != -1) | |
6969 | { | |
6970 | if (p != buff + field_size + 4) | |
6971 | { | |
6972 | if (size < (10 + 2)) | |
6973 | { | |
6974 | warn (_("Internal error: not enough buffer room for section flag info")); | |
6975 | return _("<unknown>"); | |
6976 | } | |
6977 | size -= 2; | |
6978 | *p++ = ','; | |
6979 | *p++ = ' '; | |
6980 | } | |
6981 | ||
6982 | size -= flags [sindex].len; | |
6983 | p = stpcpy (p, flags [sindex].str); | |
6984 | } | |
6985 | else if (flag & SHF_MASKOS) | |
6986 | os_flags |= flag; | |
6987 | else if (flag & SHF_MASKPROC) | |
6988 | proc_flags |= flag; | |
6989 | else | |
6990 | unknown_flags |= flag; | |
6991 | } | |
6992 | else | |
6993 | { | |
6994 | switch (flag) | |
6995 | { | |
6996 | case SHF_WRITE: *p = 'W'; break; | |
6997 | case SHF_ALLOC: *p = 'A'; break; | |
6998 | case SHF_EXECINSTR: *p = 'X'; break; | |
6999 | case SHF_MERGE: *p = 'M'; break; | |
7000 | case SHF_STRINGS: *p = 'S'; break; | |
7001 | case SHF_INFO_LINK: *p = 'I'; break; | |
7002 | case SHF_LINK_ORDER: *p = 'L'; break; | |
7003 | case SHF_OS_NONCONFORMING: *p = 'O'; break; | |
7004 | case SHF_GROUP: *p = 'G'; break; | |
7005 | case SHF_TLS: *p = 'T'; break; | |
7006 | case SHF_EXCLUDE: *p = 'E'; break; | |
7007 | case SHF_COMPRESSED: *p = 'C'; break; | |
7008 | ||
7009 | default: | |
7010 | if ((filedata->file_header.e_machine == EM_X86_64 | |
7011 | || filedata->file_header.e_machine == EM_L1OM | |
7012 | || filedata->file_header.e_machine == EM_K1OM) | |
7013 | && flag == SHF_X86_64_LARGE) | |
7014 | *p = 'l'; | |
7015 | else if (filedata->file_header.e_machine == EM_ARM | |
7016 | && flag == SHF_ARM_PURECODE) | |
7017 | *p = 'y'; | |
7018 | else if (filedata->file_header.e_machine == EM_PPC | |
7019 | && flag == SHF_PPC_VLE) | |
7020 | *p = 'v'; | |
7021 | else if (flag & SHF_MASKOS) | |
7022 | { | |
7023 | switch (filedata->file_header.e_ident[EI_OSABI]) | |
7024 | { | |
7025 | case ELFOSABI_GNU: | |
7026 | case ELFOSABI_FREEBSD: | |
7027 | if (flag == SHF_GNU_RETAIN) | |
7028 | { | |
7029 | *p = 'R'; | |
7030 | break; | |
7031 | } | |
7032 | /* Fall through */ | |
7033 | case ELFOSABI_NONE: | |
7034 | if (flag == SHF_GNU_MBIND) | |
7035 | { | |
7036 | /* We should not recognize SHF_GNU_MBIND for | |
7037 | ELFOSABI_NONE, but binutils as of 2019-07-23 did | |
7038 | not set the EI_OSABI header byte. */ | |
7039 | *p = 'D'; | |
7040 | break; | |
7041 | } | |
7042 | /* Fall through */ | |
7043 | default: | |
7044 | *p = 'o'; | |
7045 | sh_flags &= ~SHF_MASKOS; | |
7046 | break; | |
7047 | } | |
7048 | } | |
7049 | else if (flag & SHF_MASKPROC) | |
7050 | { | |
7051 | *p = 'p'; | |
7052 | sh_flags &= ~ SHF_MASKPROC; | |
7053 | } | |
7054 | else | |
7055 | *p = 'x'; | |
7056 | break; | |
7057 | } | |
7058 | p++; | |
7059 | } | |
7060 | } | |
7061 | ||
7062 | if (do_section_details) | |
7063 | { | |
7064 | if (os_flags) | |
7065 | { | |
7066 | size -= 5 + field_size; | |
7067 | if (p != buff + field_size + 4) | |
7068 | { | |
7069 | if (size < (2 + 1)) | |
7070 | { | |
7071 | warn (_("Internal error: not enough buffer room for section flag info")); | |
7072 | return _("<unknown>"); | |
7073 | } | |
7074 | size -= 2; | |
7075 | *p++ = ','; | |
7076 | *p++ = ' '; | |
7077 | } | |
7078 | sprintf (p, "OS (%*.*lx)", field_size, field_size, | |
7079 | (unsigned long) os_flags); | |
7080 | p += 5 + field_size; | |
7081 | } | |
7082 | if (proc_flags) | |
7083 | { | |
7084 | size -= 7 + field_size; | |
7085 | if (p != buff + field_size + 4) | |
7086 | { | |
7087 | if (size < (2 + 1)) | |
7088 | { | |
7089 | warn (_("Internal error: not enough buffer room for section flag info")); | |
7090 | return _("<unknown>"); | |
7091 | } | |
7092 | size -= 2; | |
7093 | *p++ = ','; | |
7094 | *p++ = ' '; | |
7095 | } | |
7096 | sprintf (p, "PROC (%*.*lx)", field_size, field_size, | |
7097 | (unsigned long) proc_flags); | |
7098 | p += 7 + field_size; | |
7099 | } | |
7100 | if (unknown_flags) | |
7101 | { | |
7102 | size -= 10 + field_size; | |
7103 | if (p != buff + field_size + 4) | |
7104 | { | |
7105 | if (size < (2 + 1)) | |
7106 | { | |
7107 | warn (_("Internal error: not enough buffer room for section flag info")); | |
7108 | return _("<unknown>"); | |
7109 | } | |
7110 | size -= 2; | |
7111 | *p++ = ','; | |
7112 | *p++ = ' '; | |
7113 | } | |
7114 | sprintf (p, _("UNKNOWN (%*.*lx)"), field_size, field_size, | |
7115 | (unsigned long) unknown_flags); | |
7116 | p += 10 + field_size; | |
7117 | } | |
7118 | } | |
7119 | ||
7120 | *p = '\0'; | |
7121 | return buff; | |
7122 | } | |
7123 | ||
7124 | static unsigned int ATTRIBUTE_WARN_UNUSED_RESULT | |
7125 | get_compression_header (Elf_Internal_Chdr *chdr, unsigned char *buf, | |
7126 | uint64_t size) | |
7127 | { | |
7128 | if (is_32bit_elf) | |
7129 | { | |
7130 | Elf32_External_Chdr *echdr = (Elf32_External_Chdr *) buf; | |
7131 | ||
7132 | if (size < sizeof (* echdr)) | |
7133 | { | |
7134 | error (_("Compressed section is too small even for a compression header\n")); | |
7135 | return 0; | |
7136 | } | |
7137 | ||
7138 | chdr->ch_type = BYTE_GET (echdr->ch_type); | |
7139 | chdr->ch_size = BYTE_GET (echdr->ch_size); | |
7140 | chdr->ch_addralign = BYTE_GET (echdr->ch_addralign); | |
7141 | return sizeof (*echdr); | |
7142 | } | |
7143 | else | |
7144 | { | |
7145 | Elf64_External_Chdr *echdr = (Elf64_External_Chdr *) buf; | |
7146 | ||
7147 | if (size < sizeof (* echdr)) | |
7148 | { | |
7149 | error (_("Compressed section is too small even for a compression header\n")); | |
7150 | return 0; | |
7151 | } | |
7152 | ||
7153 | chdr->ch_type = BYTE_GET (echdr->ch_type); | |
7154 | chdr->ch_size = BYTE_GET (echdr->ch_size); | |
7155 | chdr->ch_addralign = BYTE_GET (echdr->ch_addralign); | |
7156 | return sizeof (*echdr); | |
7157 | } | |
7158 | } | |
7159 | ||
7160 | static bool | |
7161 | process_section_headers (Filedata * filedata) | |
7162 | { | |
7163 | Elf_Internal_Shdr * section; | |
7164 | unsigned int i; | |
7165 | ||
7166 | if (filedata->file_header.e_shnum == 0) | |
7167 | { | |
7168 | /* PR binutils/12467. */ | |
7169 | if (filedata->file_header.e_shoff != 0) | |
7170 | { | |
7171 | warn (_("possibly corrupt ELF file header - it has a non-zero" | |
7172 | " section header offset, but no section headers\n")); | |
7173 | return false; | |
7174 | } | |
7175 | else if (do_sections) | |
7176 | printf (_("\nThere are no sections in this file.\n")); | |
7177 | ||
7178 | return true; | |
7179 | } | |
7180 | ||
7181 | if (do_sections && !do_header) | |
7182 | { | |
7183 | if (filedata->is_separate && process_links) | |
7184 | printf (_("In linked file '%s': "), filedata->file_name); | |
7185 | if (! filedata->is_separate || process_links) | |
7186 | printf (ngettext ("There is %d section header, " | |
7187 | "starting at offset %#" PRIx64 ":\n", | |
7188 | "There are %d section headers, " | |
7189 | "starting at offset %#" PRIx64 ":\n", | |
7190 | filedata->file_header.e_shnum), | |
7191 | filedata->file_header.e_shnum, | |
7192 | filedata->file_header.e_shoff); | |
7193 | } | |
7194 | ||
7195 | if (!get_section_headers (filedata, false)) | |
7196 | return false; | |
7197 | ||
7198 | /* Read in the string table, so that we have names to display. */ | |
7199 | if (filedata->file_header.e_shstrndx != SHN_UNDEF | |
7200 | && filedata->file_header.e_shstrndx < filedata->file_header.e_shnum) | |
7201 | { | |
7202 | section = filedata->section_headers + filedata->file_header.e_shstrndx; | |
7203 | ||
7204 | if (section->sh_size != 0) | |
7205 | { | |
7206 | filedata->string_table = (char *) get_data (NULL, filedata, section->sh_offset, | |
7207 | 1, section->sh_size, | |
7208 | _("string table")); | |
7209 | ||
7210 | filedata->string_table_length = filedata->string_table != NULL ? section->sh_size : 0; | |
7211 | } | |
7212 | } | |
7213 | ||
7214 | /* Scan the sections for the dynamic symbol table | |
7215 | and dynamic string table and debug sections. */ | |
7216 | eh_addr_size = is_32bit_elf ? 4 : 8; | |
7217 | switch (filedata->file_header.e_machine) | |
7218 | { | |
7219 | case EM_MIPS: | |
7220 | case EM_MIPS_RS3_LE: | |
7221 | /* The 64-bit MIPS EABI uses a combination of 32-bit ELF and 64-bit | |
7222 | FDE addresses. However, the ABI also has a semi-official ILP32 | |
7223 | variant for which the normal FDE address size rules apply. | |
7224 | ||
7225 | GCC 4.0 marks EABI64 objects with a dummy .gcc_compiled_longXX | |
7226 | section, where XX is the size of longs in bits. Unfortunately, | |
7227 | earlier compilers provided no way of distinguishing ILP32 objects | |
7228 | from LP64 objects, so if there's any doubt, we should assume that | |
7229 | the official LP64 form is being used. */ | |
7230 | if ((filedata->file_header.e_flags & EF_MIPS_ABI) == E_MIPS_ABI_EABI64 | |
7231 | && find_section (filedata, ".gcc_compiled_long32") == NULL) | |
7232 | eh_addr_size = 8; | |
7233 | break; | |
7234 | ||
7235 | case EM_H8_300: | |
7236 | case EM_H8_300H: | |
7237 | switch (filedata->file_header.e_flags & EF_H8_MACH) | |
7238 | { | |
7239 | case E_H8_MACH_H8300: | |
7240 | case E_H8_MACH_H8300HN: | |
7241 | case E_H8_MACH_H8300SN: | |
7242 | case E_H8_MACH_H8300SXN: | |
7243 | eh_addr_size = 2; | |
7244 | break; | |
7245 | case E_H8_MACH_H8300H: | |
7246 | case E_H8_MACH_H8300S: | |
7247 | case E_H8_MACH_H8300SX: | |
7248 | eh_addr_size = 4; | |
7249 | break; | |
7250 | } | |
7251 | break; | |
7252 | ||
7253 | case EM_M32C_OLD: | |
7254 | case EM_M32C: | |
7255 | switch (filedata->file_header.e_flags & EF_M32C_CPU_MASK) | |
7256 | { | |
7257 | case EF_M32C_CPU_M16C: | |
7258 | eh_addr_size = 2; | |
7259 | break; | |
7260 | } | |
7261 | break; | |
7262 | } | |
7263 | ||
7264 | #define CHECK_ENTSIZE_VALUES(section, i, size32, size64) \ | |
7265 | do \ | |
7266 | { \ | |
7267 | uint64_t expected_entsize = is_32bit_elf ? size32 : size64; \ | |
7268 | if (section->sh_entsize != expected_entsize) \ | |
7269 | { \ | |
7270 | error (_("Section %d has invalid sh_entsize of %" PRIx64 "\n"), \ | |
7271 | i, section->sh_entsize); \ | |
7272 | error (_("(Using the expected size of %" PRIx64 " for the rest of this dump)\n"), \ | |
7273 | expected_entsize); \ | |
7274 | section->sh_entsize = expected_entsize; \ | |
7275 | } \ | |
7276 | } \ | |
7277 | while (0) | |
7278 | ||
7279 | #define CHECK_ENTSIZE(section, i, type) \ | |
7280 | CHECK_ENTSIZE_VALUES (section, i, sizeof (Elf32_External_##type), \ | |
7281 | sizeof (Elf64_External_##type)) | |
7282 | ||
7283 | for (i = 0, section = filedata->section_headers; | |
7284 | i < filedata->file_header.e_shnum; | |
7285 | i++, section++) | |
7286 | { | |
7287 | const char *name = section_name_print (filedata, section); | |
7288 | ||
7289 | /* Run some sanity checks on the headers and | |
7290 | possibly fill in some file data as well. */ | |
7291 | switch (section->sh_type) | |
7292 | { | |
7293 | case SHT_DYNSYM: | |
7294 | if (filedata->dynamic_symbols != NULL) | |
7295 | { | |
7296 | error (_("File contains multiple dynamic symbol tables\n")); | |
7297 | continue; | |
7298 | } | |
7299 | ||
7300 | CHECK_ENTSIZE (section, i, Sym); | |
7301 | filedata->dynamic_symbols | |
7302 | = get_elf_symbols (filedata, section, &filedata->num_dynamic_syms); | |
7303 | filedata->dynamic_symtab_section = section; | |
7304 | break; | |
7305 | ||
7306 | case SHT_STRTAB: | |
7307 | if (streq (name, ".dynstr")) | |
7308 | { | |
7309 | if (filedata->dynamic_strings != NULL) | |
7310 | { | |
7311 | error (_("File contains multiple dynamic string tables\n")); | |
7312 | continue; | |
7313 | } | |
7314 | ||
7315 | filedata->dynamic_strings | |
7316 | = (char *) get_data (NULL, filedata, section->sh_offset, | |
7317 | 1, section->sh_size, _("dynamic strings")); | |
7318 | filedata->dynamic_strings_length | |
7319 | = filedata->dynamic_strings == NULL ? 0 : section->sh_size; | |
7320 | filedata->dynamic_strtab_section = section; | |
7321 | } | |
7322 | break; | |
7323 | ||
7324 | case SHT_SYMTAB_SHNDX: | |
7325 | { | |
7326 | elf_section_list * entry = xmalloc (sizeof * entry); | |
7327 | ||
7328 | entry->hdr = section; | |
7329 | entry->next = filedata->symtab_shndx_list; | |
7330 | filedata->symtab_shndx_list = entry; | |
7331 | } | |
7332 | break; | |
7333 | ||
7334 | case SHT_SYMTAB: | |
7335 | CHECK_ENTSIZE (section, i, Sym); | |
7336 | break; | |
7337 | ||
7338 | case SHT_GROUP: | |
7339 | CHECK_ENTSIZE_VALUES (section, i, GRP_ENTRY_SIZE, GRP_ENTRY_SIZE); | |
7340 | break; | |
7341 | ||
7342 | case SHT_REL: | |
7343 | CHECK_ENTSIZE (section, i, Rel); | |
7344 | if (do_checks && section->sh_size == 0) | |
7345 | warn (_("Section '%s': zero-sized relocation section\n"), name); | |
7346 | break; | |
7347 | ||
7348 | case SHT_RELA: | |
7349 | CHECK_ENTSIZE (section, i, Rela); | |
7350 | if (do_checks && section->sh_size == 0) | |
7351 | warn (_("Section '%s': zero-sized relocation section\n"), name); | |
7352 | break; | |
7353 | ||
7354 | case SHT_RELR: | |
7355 | CHECK_ENTSIZE (section, i, Relr); | |
7356 | break; | |
7357 | ||
7358 | case SHT_NOTE: | |
7359 | case SHT_PROGBITS: | |
7360 | /* Having a zero sized section is not illegal according to the | |
7361 | ELF standard, but it might be an indication that something | |
7362 | is wrong. So issue a warning if we are running in lint mode. */ | |
7363 | if (do_checks && section->sh_size == 0) | |
7364 | warn (_("Section '%s': has a size of zero - is this intended ?\n"), name); | |
7365 | break; | |
7366 | ||
7367 | default: | |
7368 | break; | |
7369 | } | |
7370 | ||
7371 | if ((do_debugging || do_debug_info || do_debug_abbrevs | |
7372 | || do_debug_lines || do_debug_pubnames || do_debug_pubtypes | |
7373 | || do_debug_aranges || do_debug_frames || do_debug_macinfo | |
7374 | || do_debug_str || do_debug_str_offsets || do_debug_loc | |
7375 | || do_debug_ranges | |
7376 | || do_debug_addr || do_debug_cu_index || do_debug_links) | |
7377 | && (startswith (name, ".debug_") | |
7378 | || startswith (name, ".zdebug_"))) | |
7379 | { | |
7380 | if (name[1] == 'z') | |
7381 | name += sizeof (".zdebug_") - 1; | |
7382 | else | |
7383 | name += sizeof (".debug_") - 1; | |
7384 | ||
7385 | if (do_debugging | |
7386 | || (do_debug_info && startswith (name, "info")) | |
7387 | || (do_debug_info && startswith (name, "types")) | |
7388 | || (do_debug_abbrevs && startswith (name, "abbrev")) | |
7389 | || (do_debug_lines && strcmp (name, "line") == 0) | |
7390 | || (do_debug_lines && startswith (name, "line.")) | |
7391 | || (do_debug_pubnames && startswith (name, "pubnames")) | |
7392 | || (do_debug_pubtypes && startswith (name, "pubtypes")) | |
7393 | || (do_debug_pubnames && startswith (name, "gnu_pubnames")) | |
7394 | || (do_debug_pubtypes && startswith (name, "gnu_pubtypes")) | |
7395 | || (do_debug_aranges && startswith (name, "aranges")) | |
7396 | || (do_debug_ranges && startswith (name, "ranges")) | |
7397 | || (do_debug_ranges && startswith (name, "rnglists")) | |
7398 | || (do_debug_frames && startswith (name, "frame")) | |
7399 | || (do_debug_macinfo && startswith (name, "macinfo")) | |
7400 | || (do_debug_macinfo && startswith (name, "macro")) | |
7401 | || (do_debug_str && startswith (name, "str")) | |
7402 | || (do_debug_links && startswith (name, "sup")) | |
7403 | || (do_debug_str_offsets && startswith (name, "str_offsets")) | |
7404 | || (do_debug_loc && startswith (name, "loc")) | |
7405 | || (do_debug_loc && startswith (name, "loclists")) | |
7406 | || (do_debug_addr && startswith (name, "addr")) | |
7407 | || (do_debug_cu_index && startswith (name, "cu_index")) | |
7408 | || (do_debug_cu_index && startswith (name, "tu_index")) | |
7409 | ) | |
7410 | request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP); | |
7411 | } | |
7412 | /* Linkonce section to be combined with .debug_info at link time. */ | |
7413 | else if ((do_debugging || do_debug_info) | |
7414 | && startswith (name, ".gnu.linkonce.wi.")) | |
7415 | request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP); | |
7416 | else if (do_debug_frames && streq (name, ".eh_frame")) | |
7417 | request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP); | |
7418 | else if (do_gdb_index && (streq (name, ".gdb_index") | |
7419 | || streq (name, ".debug_names"))) | |
7420 | request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP); | |
7421 | /* Trace sections for Itanium VMS. */ | |
7422 | else if ((do_debugging || do_trace_info || do_trace_abbrevs | |
7423 | || do_trace_aranges) | |
7424 | && startswith (name, ".trace_")) | |
7425 | { | |
7426 | name += sizeof (".trace_") - 1; | |
7427 | ||
7428 | if (do_debugging | |
7429 | || (do_trace_info && streq (name, "info")) | |
7430 | || (do_trace_abbrevs && streq (name, "abbrev")) | |
7431 | || (do_trace_aranges && streq (name, "aranges")) | |
7432 | ) | |
7433 | request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP); | |
7434 | } | |
7435 | else if ((do_debugging || do_debug_links) | |
7436 | && (startswith (name, ".gnu_debuglink") | |
7437 | || startswith (name, ".gnu_debugaltlink"))) | |
7438 | request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP); | |
7439 | } | |
7440 | ||
7441 | if (! do_sections) | |
7442 | return true; | |
7443 | ||
7444 | if (filedata->is_separate && ! process_links) | |
7445 | return true; | |
7446 | ||
7447 | if (filedata->is_separate) | |
7448 | printf (_("\nSection Headers in linked file '%s':\n"), filedata->file_name); | |
7449 | else if (filedata->file_header.e_shnum > 1) | |
7450 | printf (_("\nSection Headers:\n")); | |
7451 | else | |
7452 | printf (_("\nSection Header:\n")); | |
7453 | ||
7454 | if (is_32bit_elf) | |
7455 | { | |
7456 | if (do_section_details) | |
7457 | { | |
7458 | printf (_(" [Nr] Name\n")); | |
7459 | printf (_(" Type Addr Off Size ES Lk Inf Al\n")); | |
7460 | } | |
7461 | else | |
7462 | printf | |
7463 | (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n")); | |
7464 | } | |
7465 | else if (do_wide) | |
7466 | { | |
7467 | if (do_section_details) | |
7468 | { | |
7469 | printf (_(" [Nr] Name\n")); | |
7470 | printf (_(" Type Address Off Size ES Lk Inf Al\n")); | |
7471 | } | |
7472 | else | |
7473 | printf | |
7474 | (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n")); | |
7475 | } | |
7476 | else | |
7477 | { | |
7478 | if (do_section_details) | |
7479 | { | |
7480 | printf (_(" [Nr] Name\n")); | |
7481 | printf (_(" Type Address Offset Link\n")); | |
7482 | printf (_(" Size EntSize Info Align\n")); | |
7483 | } | |
7484 | else | |
7485 | { | |
7486 | printf (_(" [Nr] Name Type Address Offset\n")); | |
7487 | printf (_(" Size EntSize Flags Link Info Align\n")); | |
7488 | } | |
7489 | } | |
7490 | ||
7491 | if (do_section_details) | |
7492 | printf (_(" Flags\n")); | |
7493 | ||
7494 | for (i = 0, section = filedata->section_headers; | |
7495 | i < filedata->file_header.e_shnum; | |
7496 | i++, section++) | |
7497 | { | |
7498 | /* Run some sanity checks on the section header. */ | |
7499 | ||
7500 | /* Check the sh_link field. */ | |
7501 | switch (section->sh_type) | |
7502 | { | |
7503 | case SHT_REL: | |
7504 | case SHT_RELA: | |
7505 | if (section->sh_link == 0 | |
7506 | && (filedata->file_header.e_type == ET_EXEC | |
7507 | || filedata->file_header.e_type == ET_DYN)) | |
7508 | /* A dynamic relocation section where all entries use a | |
7509 | zero symbol index need not specify a symtab section. */ | |
7510 | break; | |
7511 | /* Fall through. */ | |
7512 | case SHT_SYMTAB_SHNDX: | |
7513 | case SHT_GROUP: | |
7514 | case SHT_HASH: | |
7515 | case SHT_GNU_HASH: | |
7516 | case SHT_GNU_versym: | |
7517 | if (section->sh_link == 0 | |
7518 | || section->sh_link >= filedata->file_header.e_shnum | |
7519 | || (filedata->section_headers[section->sh_link].sh_type != SHT_SYMTAB | |
7520 | && filedata->section_headers[section->sh_link].sh_type != SHT_DYNSYM)) | |
7521 | warn (_("[%2u]: Link field (%u) should index a symtab section.\n"), | |
7522 | i, section->sh_link); | |
7523 | break; | |
7524 | ||
7525 | case SHT_DYNAMIC: | |
7526 | case SHT_SYMTAB: | |
7527 | case SHT_DYNSYM: | |
7528 | case SHT_GNU_verneed: | |
7529 | case SHT_GNU_verdef: | |
7530 | case SHT_GNU_LIBLIST: | |
7531 | if (section->sh_link == 0 | |
7532 | || section->sh_link >= filedata->file_header.e_shnum | |
7533 | || filedata->section_headers[section->sh_link].sh_type != SHT_STRTAB) | |
7534 | warn (_("[%2u]: Link field (%u) should index a string section.\n"), | |
7535 | i, section->sh_link); | |
7536 | break; | |
7537 | ||
7538 | case SHT_INIT_ARRAY: | |
7539 | case SHT_FINI_ARRAY: | |
7540 | case SHT_PREINIT_ARRAY: | |
7541 | if (section->sh_type < SHT_LOOS && section->sh_link != 0) | |
7542 | warn (_("[%2u]: Unexpected value (%u) in link field.\n"), | |
7543 | i, section->sh_link); | |
7544 | break; | |
7545 | ||
7546 | default: | |
7547 | /* FIXME: Add support for target specific section types. */ | |
7548 | #if 0 /* Currently we do not check other section types as there are too | |
7549 | many special cases. Stab sections for example have a type | |
7550 | of SHT_PROGBITS but an sh_link field that links to the .stabstr | |
7551 | section. */ | |
7552 | if (section->sh_type < SHT_LOOS && section->sh_link != 0) | |
7553 | warn (_("[%2u]: Unexpected value (%u) in link field.\n"), | |
7554 | i, section->sh_link); | |
7555 | #endif | |
7556 | break; | |
7557 | } | |
7558 | ||
7559 | /* Check the sh_info field. */ | |
7560 | switch (section->sh_type) | |
7561 | { | |
7562 | case SHT_REL: | |
7563 | case SHT_RELA: | |
7564 | if (section->sh_info == 0 | |
7565 | && (filedata->file_header.e_type == ET_EXEC | |
7566 | || filedata->file_header.e_type == ET_DYN)) | |
7567 | /* Dynamic relocations apply to segments, so they do not | |
7568 | need to specify the section they relocate. */ | |
7569 | break; | |
7570 | if (section->sh_info == 0 | |
7571 | || section->sh_info >= filedata->file_header.e_shnum | |
7572 | || (filedata->section_headers[section->sh_info].sh_type != SHT_PROGBITS | |
7573 | && filedata->section_headers[section->sh_info].sh_type != SHT_NOBITS | |
7574 | && filedata->section_headers[section->sh_info].sh_type != SHT_NOTE | |
7575 | && filedata->section_headers[section->sh_info].sh_type != SHT_INIT_ARRAY | |
7576 | && filedata->section_headers[section->sh_info].sh_type != SHT_FINI_ARRAY | |
7577 | && filedata->section_headers[section->sh_info].sh_type != SHT_PREINIT_ARRAY | |
7578 | /* FIXME: Are other section types valid ? */ | |
7579 | && filedata->section_headers[section->sh_info].sh_type < SHT_LOOS)) | |
7580 | warn (_("[%2u]: Info field (%u) should index a relocatable section.\n"), | |
7581 | i, section->sh_info); | |
7582 | break; | |
7583 | ||
7584 | case SHT_DYNAMIC: | |
7585 | case SHT_HASH: | |
7586 | case SHT_SYMTAB_SHNDX: | |
7587 | case SHT_INIT_ARRAY: | |
7588 | case SHT_FINI_ARRAY: | |
7589 | case SHT_PREINIT_ARRAY: | |
7590 | if (section->sh_info != 0) | |
7591 | warn (_("[%2u]: Unexpected value (%u) in info field.\n"), | |
7592 | i, section->sh_info); | |
7593 | break; | |
7594 | ||
7595 | case SHT_GROUP: | |
7596 | case SHT_SYMTAB: | |
7597 | case SHT_DYNSYM: | |
7598 | /* A symbol index - we assume that it is valid. */ | |
7599 | break; | |
7600 | ||
7601 | default: | |
7602 | /* FIXME: Add support for target specific section types. */ | |
7603 | if (section->sh_type == SHT_NOBITS) | |
7604 | /* NOBITS section headers with non-zero sh_info fields can be | |
7605 | created when a binary is stripped of everything but its debug | |
7606 | information. The stripped sections have their headers | |
7607 | preserved but their types set to SHT_NOBITS. So do not check | |
7608 | this type of section. */ | |
7609 | ; | |
7610 | else if (section->sh_flags & SHF_INFO_LINK) | |
7611 | { | |
7612 | if (section->sh_info < 1 || section->sh_info >= filedata->file_header.e_shnum) | |
7613 | warn (_("[%2u]: Expected link to another section in info field"), i); | |
7614 | } | |
7615 | else if (section->sh_type < SHT_LOOS | |
7616 | && (section->sh_flags & SHF_GNU_MBIND) == 0 | |
7617 | && section->sh_info != 0) | |
7618 | warn (_("[%2u]: Unexpected value (%u) in info field.\n"), | |
7619 | i, section->sh_info); | |
7620 | break; | |
7621 | } | |
7622 | ||
7623 | /* Check the sh_size field. */ | |
7624 | if (section->sh_size > filedata->file_size | |
7625 | && section->sh_type != SHT_NOBITS | |
7626 | && section->sh_type != SHT_NULL | |
7627 | && section->sh_type < SHT_LOOS) | |
7628 | warn (_("Size of section %u is larger than the entire file!\n"), i); | |
7629 | ||
7630 | printf (" [%2u] ", i); | |
7631 | if (do_section_details) | |
7632 | printf ("%s\n ", printable_section_name (filedata, section)); | |
7633 | else | |
7634 | print_symbol (-17, section_name_print (filedata, section)); | |
7635 | ||
7636 | printf (do_wide ? " %-15s " : " %-15.15s ", | |
7637 | get_section_type_name (filedata, section->sh_type)); | |
7638 | ||
7639 | if (is_32bit_elf) | |
7640 | { | |
7641 | const char * link_too_big = NULL; | |
7642 | ||
7643 | print_vma (section->sh_addr, LONG_HEX); | |
7644 | ||
7645 | printf ( " %6.6lx %6.6lx %2.2lx", | |
7646 | (unsigned long) section->sh_offset, | |
7647 | (unsigned long) section->sh_size, | |
7648 | (unsigned long) section->sh_entsize); | |
7649 | ||
7650 | if (do_section_details) | |
7651 | fputs (" ", stdout); | |
7652 | else | |
7653 | printf (" %3s ", get_elf_section_flags (filedata, section->sh_flags)); | |
7654 | ||
7655 | if (section->sh_link >= filedata->file_header.e_shnum) | |
7656 | { | |
7657 | link_too_big = ""; | |
7658 | /* The sh_link value is out of range. Normally this indicates | |
7659 | an error but it can have special values in Solaris binaries. */ | |
7660 | switch (filedata->file_header.e_machine) | |
7661 | { | |
7662 | case EM_386: | |
7663 | case EM_IAMCU: | |
7664 | case EM_X86_64: | |
7665 | case EM_L1OM: | |
7666 | case EM_K1OM: | |
7667 | case EM_OLD_SPARCV9: | |
7668 | case EM_SPARC32PLUS: | |
7669 | case EM_SPARCV9: | |
7670 | case EM_SPARC: | |
7671 | if (section->sh_link == (SHN_BEFORE & 0xffff)) | |
7672 | link_too_big = "BEFORE"; | |
7673 | else if (section->sh_link == (SHN_AFTER & 0xffff)) | |
7674 | link_too_big = "AFTER"; | |
7675 | break; | |
7676 | default: | |
7677 | break; | |
7678 | } | |
7679 | } | |
7680 | ||
7681 | if (do_section_details) | |
7682 | { | |
7683 | if (link_too_big != NULL && * link_too_big) | |
7684 | printf ("<%s> ", link_too_big); | |
7685 | else | |
7686 | printf ("%2u ", section->sh_link); | |
7687 | printf ("%3u %2lu\n", section->sh_info, | |
7688 | (unsigned long) section->sh_addralign); | |
7689 | } | |
7690 | else | |
7691 | printf ("%2u %3u %2lu\n", | |
7692 | section->sh_link, | |
7693 | section->sh_info, | |
7694 | (unsigned long) section->sh_addralign); | |
7695 | ||
7696 | if (link_too_big && ! * link_too_big) | |
7697 | warn (_("section %u: sh_link value of %u is larger than the number of sections\n"), | |
7698 | i, section->sh_link); | |
7699 | } | |
7700 | else if (do_wide) | |
7701 | { | |
7702 | print_vma (section->sh_addr, LONG_HEX); | |
7703 | ||
7704 | if ((long) section->sh_offset == section->sh_offset) | |
7705 | printf (" %6.6lx", (unsigned long) section->sh_offset); | |
7706 | else | |
7707 | { | |
7708 | putchar (' '); | |
7709 | print_vma (section->sh_offset, LONG_HEX); | |
7710 | } | |
7711 | ||
7712 | if ((unsigned long) section->sh_size == section->sh_size) | |
7713 | printf (" %6.6lx", (unsigned long) section->sh_size); | |
7714 | else | |
7715 | { | |
7716 | putchar (' '); | |
7717 | print_vma (section->sh_size, LONG_HEX); | |
7718 | } | |
7719 | ||
7720 | if ((unsigned long) section->sh_entsize == section->sh_entsize) | |
7721 | printf (" %2.2lx", (unsigned long) section->sh_entsize); | |
7722 | else | |
7723 | { | |
7724 | putchar (' '); | |
7725 | print_vma (section->sh_entsize, LONG_HEX); | |
7726 | } | |
7727 | ||
7728 | if (do_section_details) | |
7729 | fputs (" ", stdout); | |
7730 | else | |
7731 | printf (" %3s ", get_elf_section_flags (filedata, section->sh_flags)); | |
7732 | ||
7733 | printf ("%2u %3u ", section->sh_link, section->sh_info); | |
7734 | ||
7735 | if ((unsigned long) section->sh_addralign == section->sh_addralign) | |
7736 | printf ("%2lu\n", (unsigned long) section->sh_addralign); | |
7737 | else | |
7738 | { | |
7739 | print_vma (section->sh_addralign, DEC); | |
7740 | putchar ('\n'); | |
7741 | } | |
7742 | } | |
7743 | else if (do_section_details) | |
7744 | { | |
7745 | putchar (' '); | |
7746 | print_vma (section->sh_addr, LONG_HEX); | |
7747 | if ((long) section->sh_offset == section->sh_offset) | |
7748 | printf (" %16.16lx", (unsigned long) section->sh_offset); | |
7749 | else | |
7750 | { | |
7751 | printf (" "); | |
7752 | print_vma (section->sh_offset, LONG_HEX); | |
7753 | } | |
7754 | printf (" %u\n ", section->sh_link); | |
7755 | print_vma (section->sh_size, LONG_HEX); | |
7756 | putchar (' '); | |
7757 | print_vma (section->sh_entsize, LONG_HEX); | |
7758 | ||
7759 | printf (" %-16u %lu\n", | |
7760 | section->sh_info, | |
7761 | (unsigned long) section->sh_addralign); | |
7762 | } | |
7763 | else | |
7764 | { | |
7765 | putchar (' '); | |
7766 | print_vma (section->sh_addr, LONG_HEX); | |
7767 | if ((long) section->sh_offset == section->sh_offset) | |
7768 | printf (" %8.8lx", (unsigned long) section->sh_offset); | |
7769 | else | |
7770 | { | |
7771 | printf (" "); | |
7772 | print_vma (section->sh_offset, LONG_HEX); | |
7773 | } | |
7774 | printf ("\n "); | |
7775 | print_vma (section->sh_size, LONG_HEX); | |
7776 | printf (" "); | |
7777 | print_vma (section->sh_entsize, LONG_HEX); | |
7778 | ||
7779 | printf (" %3s ", get_elf_section_flags (filedata, section->sh_flags)); | |
7780 | ||
7781 | printf (" %2u %3u %lu\n", | |
7782 | section->sh_link, | |
7783 | section->sh_info, | |
7784 | (unsigned long) section->sh_addralign); | |
7785 | } | |
7786 | ||
7787 | if (do_section_details) | |
7788 | { | |
7789 | printf (" %s\n", get_elf_section_flags (filedata, section->sh_flags)); | |
7790 | if ((section->sh_flags & SHF_COMPRESSED) != 0) | |
7791 | { | |
7792 | /* Minimum section size is 12 bytes for 32-bit compression | |
7793 | header + 12 bytes for compressed data header. */ | |
7794 | unsigned char buf[24]; | |
7795 | ||
7796 | assert (sizeof (buf) >= sizeof (Elf64_External_Chdr)); | |
7797 | if (get_data (&buf, filedata, section->sh_offset, 1, | |
7798 | sizeof (buf), _("compression header"))) | |
7799 | { | |
7800 | Elf_Internal_Chdr chdr; | |
7801 | ||
7802 | if (get_compression_header (&chdr, buf, sizeof (buf)) == 0) | |
7803 | printf (_(" [<corrupt>]\n")); | |
7804 | else | |
7805 | { | |
7806 | if (chdr.ch_type == ELFCOMPRESS_ZLIB) | |
7807 | printf (" ZLIB, "); | |
7808 | else if (chdr.ch_type == ELFCOMPRESS_ZSTD) | |
7809 | printf (" ZSTD, "); | |
7810 | else | |
7811 | printf (_(" [<unknown>: 0x%x], "), | |
7812 | chdr.ch_type); | |
7813 | print_vma (chdr.ch_size, LONG_HEX); | |
7814 | printf (", %lu\n", (unsigned long) chdr.ch_addralign); | |
7815 | } | |
7816 | } | |
7817 | } | |
7818 | } | |
7819 | } | |
7820 | ||
7821 | if (!do_section_details) | |
7822 | { | |
7823 | /* The ordering of the letters shown here matches the ordering of the | |
7824 | corresponding SHF_xxx values, and hence the order in which these | |
7825 | letters will be displayed to the user. */ | |
7826 | printf (_("Key to Flags:\n\ | |
7827 | W (write), A (alloc), X (execute), M (merge), S (strings), I (info),\n\ | |
7828 | L (link order), O (extra OS processing required), G (group), T (TLS),\n\ | |
7829 | C (compressed), x (unknown), o (OS specific), E (exclude),\n ")); | |
7830 | switch (filedata->file_header.e_ident[EI_OSABI]) | |
7831 | { | |
7832 | case ELFOSABI_GNU: | |
7833 | case ELFOSABI_FREEBSD: | |
7834 | printf (_("R (retain), ")); | |
7835 | /* Fall through */ | |
7836 | case ELFOSABI_NONE: | |
7837 | printf (_("D (mbind), ")); | |
7838 | break; | |
7839 | default: | |
7840 | break; | |
7841 | } | |
7842 | if (filedata->file_header.e_machine == EM_X86_64 | |
7843 | || filedata->file_header.e_machine == EM_L1OM | |
7844 | || filedata->file_header.e_machine == EM_K1OM) | |
7845 | printf (_("l (large), ")); | |
7846 | else if (filedata->file_header.e_machine == EM_ARM) | |
7847 | printf (_("y (purecode), ")); | |
7848 | else if (filedata->file_header.e_machine == EM_PPC) | |
7849 | printf (_("v (VLE), ")); | |
7850 | printf ("p (processor specific)\n"); | |
7851 | } | |
7852 | ||
7853 | return true; | |
7854 | } | |
7855 | ||
7856 | static bool | |
7857 | get_symtab (Filedata *filedata, Elf_Internal_Shdr *symsec, | |
7858 | Elf_Internal_Sym **symtab, uint64_t *nsyms, | |
7859 | char **strtab, uint64_t *strtablen) | |
7860 | { | |
7861 | *strtab = NULL; | |
7862 | *strtablen = 0; | |
7863 | *symtab = get_elf_symbols (filedata, symsec, nsyms); | |
7864 | ||
7865 | if (*symtab == NULL) | |
7866 | return false; | |
7867 | ||
7868 | if (symsec->sh_link != 0) | |
7869 | { | |
7870 | Elf_Internal_Shdr *strsec; | |
7871 | ||
7872 | if (symsec->sh_link >= filedata->file_header.e_shnum) | |
7873 | { | |
7874 | error (_("Bad sh_link in symbol table section\n")); | |
7875 | free (*symtab); | |
7876 | *symtab = NULL; | |
7877 | *nsyms = 0; | |
7878 | return false; | |
7879 | } | |
7880 | ||
7881 | strsec = filedata->section_headers + symsec->sh_link; | |
7882 | ||
7883 | *strtab = (char *) get_data (NULL, filedata, strsec->sh_offset, | |
7884 | 1, strsec->sh_size, _("string table")); | |
7885 | if (*strtab == NULL) | |
7886 | { | |
7887 | free (*symtab); | |
7888 | *symtab = NULL; | |
7889 | *nsyms = 0; | |
7890 | return false; | |
7891 | } | |
7892 | *strtablen = strsec->sh_size; | |
7893 | } | |
7894 | return true; | |
7895 | } | |
7896 | ||
7897 | static const char * | |
7898 | get_group_flags (unsigned int flags) | |
7899 | { | |
7900 | static char buff[128]; | |
7901 | ||
7902 | if (flags == 0) | |
7903 | return ""; | |
7904 | else if (flags == GRP_COMDAT) | |
7905 | return "COMDAT "; | |
7906 | ||
7907 | snprintf (buff, sizeof buff, "[0x%x: %s%s%s]", | |
7908 | flags, | |
7909 | flags & GRP_MASKOS ? _("<OS specific>") : "", | |
7910 | flags & GRP_MASKPROC ? _("<PROC specific>") : "", | |
7911 | (flags & ~(GRP_COMDAT | GRP_MASKOS | GRP_MASKPROC) | |
7912 | ? _("<unknown>") : "")); | |
7913 | ||
7914 | return buff; | |
7915 | } | |
7916 | ||
7917 | static bool | |
7918 | process_section_groups (Filedata * filedata) | |
7919 | { | |
7920 | Elf_Internal_Shdr * section; | |
7921 | unsigned int i; | |
7922 | struct group * group; | |
7923 | Elf_Internal_Shdr * symtab_sec; | |
7924 | Elf_Internal_Shdr * strtab_sec; | |
7925 | Elf_Internal_Sym * symtab; | |
7926 | uint64_t num_syms; | |
7927 | char * strtab; | |
7928 | size_t strtab_size; | |
7929 | ||
7930 | /* Don't process section groups unless needed. */ | |
7931 | if (!do_unwind && !do_section_groups) | |
7932 | return true; | |
7933 | ||
7934 | if (filedata->file_header.e_shnum == 0) | |
7935 | { | |
7936 | if (do_section_groups) | |
7937 | { | |
7938 | if (filedata->is_separate) | |
7939 | printf (_("\nThere are no sections group in linked file '%s'.\n"), | |
7940 | filedata->file_name); | |
7941 | else | |
7942 | printf (_("\nThere are no section groups in this file.\n")); | |
7943 | } | |
7944 | return true; | |
7945 | } | |
7946 | ||
7947 | if (filedata->section_headers == NULL) | |
7948 | { | |
7949 | error (_("Section headers are not available!\n")); | |
7950 | /* PR 13622: This can happen with a corrupt ELF header. */ | |
7951 | return false; | |
7952 | } | |
7953 | ||
7954 | filedata->section_headers_groups | |
7955 | = (struct group **) calloc (filedata->file_header.e_shnum, | |
7956 | sizeof (struct group *)); | |
7957 | ||
7958 | if (filedata->section_headers_groups == NULL) | |
7959 | { | |
7960 | error (_("Out of memory reading %u section group headers\n"), | |
7961 | filedata->file_header.e_shnum); | |
7962 | return false; | |
7963 | } | |
7964 | ||
7965 | /* Scan the sections for the group section. */ | |
7966 | filedata->group_count = 0; | |
7967 | for (i = 0, section = filedata->section_headers; | |
7968 | i < filedata->file_header.e_shnum; | |
7969 | i++, section++) | |
7970 | if (section->sh_type == SHT_GROUP) | |
7971 | filedata->group_count++; | |
7972 | ||
7973 | if (filedata->group_count == 0) | |
7974 | { | |
7975 | if (do_section_groups) | |
7976 | { | |
7977 | if (filedata->is_separate) | |
7978 | printf (_("\nThere are no section groups in linked file '%s'.\n"), | |
7979 | filedata->file_name); | |
7980 | else | |
7981 | printf (_("\nThere are no section groups in this file.\n")); | |
7982 | } | |
7983 | ||
7984 | return true; | |
7985 | } | |
7986 | ||
7987 | filedata->section_groups = (struct group *) calloc (filedata->group_count, | |
7988 | sizeof (struct group)); | |
7989 | ||
7990 | if (filedata->section_groups == NULL) | |
7991 | { | |
7992 | error (_("Out of memory reading %zu groups\n"), filedata->group_count); | |
7993 | return false; | |
7994 | } | |
7995 | ||
7996 | symtab_sec = NULL; | |
7997 | strtab_sec = NULL; | |
7998 | symtab = NULL; | |
7999 | num_syms = 0; | |
8000 | strtab = NULL; | |
8001 | strtab_size = 0; | |
8002 | ||
8003 | if (filedata->is_separate) | |
8004 | printf (_("Section groups in linked file '%s'\n"), filedata->file_name); | |
8005 | ||
8006 | for (i = 0, section = filedata->section_headers, group = filedata->section_groups; | |
8007 | i < filedata->file_header.e_shnum; | |
8008 | i++, section++) | |
8009 | { | |
8010 | if (section->sh_type == SHT_GROUP) | |
8011 | { | |
8012 | const char * name = printable_section_name (filedata, section); | |
8013 | const char * group_name; | |
8014 | unsigned char * start; | |
8015 | unsigned char * indices; | |
8016 | unsigned int entry, j, size; | |
8017 | Elf_Internal_Shdr * sec; | |
8018 | Elf_Internal_Sym * sym; | |
8019 | ||
8020 | /* Get the symbol table. */ | |
8021 | if (section->sh_link >= filedata->file_header.e_shnum | |
8022 | || ((sec = filedata->section_headers + section->sh_link)->sh_type | |
8023 | != SHT_SYMTAB)) | |
8024 | { | |
8025 | error (_("Bad sh_link in group section `%s'\n"), name); | |
8026 | continue; | |
8027 | } | |
8028 | ||
8029 | if (symtab_sec != sec) | |
8030 | { | |
8031 | symtab_sec = sec; | |
8032 | free (symtab); | |
8033 | symtab = get_elf_symbols (filedata, symtab_sec, & num_syms); | |
8034 | } | |
8035 | ||
8036 | if (symtab == NULL) | |
8037 | { | |
8038 | error (_("Corrupt header in group section `%s'\n"), name); | |
8039 | continue; | |
8040 | } | |
8041 | ||
8042 | if (section->sh_info >= num_syms) | |
8043 | { | |
8044 | error (_("Bad sh_info in group section `%s'\n"), name); | |
8045 | continue; | |
8046 | } | |
8047 | ||
8048 | sym = symtab + section->sh_info; | |
8049 | ||
8050 | if (ELF_ST_TYPE (sym->st_info) == STT_SECTION) | |
8051 | { | |
8052 | if (sym->st_shndx == 0 | |
8053 | || sym->st_shndx >= filedata->file_header.e_shnum) | |
8054 | { | |
8055 | error (_("Bad sh_info in group section `%s'\n"), name); | |
8056 | continue; | |
8057 | } | |
8058 | ||
8059 | group_name = section_name_print (filedata, | |
8060 | filedata->section_headers | |
8061 | + sym->st_shndx); | |
8062 | strtab_sec = NULL; | |
8063 | free (strtab); | |
8064 | strtab = NULL; | |
8065 | strtab_size = 0; | |
8066 | } | |
8067 | else | |
8068 | { | |
8069 | /* Get the string table. */ | |
8070 | if (symtab_sec->sh_link >= filedata->file_header.e_shnum) | |
8071 | { | |
8072 | strtab_sec = NULL; | |
8073 | free (strtab); | |
8074 | strtab = NULL; | |
8075 | strtab_size = 0; | |
8076 | } | |
8077 | else if (strtab_sec | |
8078 | != (sec = filedata->section_headers + symtab_sec->sh_link)) | |
8079 | { | |
8080 | strtab_sec = sec; | |
8081 | free (strtab); | |
8082 | ||
8083 | strtab = (char *) get_data (NULL, filedata, strtab_sec->sh_offset, | |
8084 | 1, strtab_sec->sh_size, | |
8085 | _("string table")); | |
8086 | strtab_size = strtab != NULL ? strtab_sec->sh_size : 0; | |
8087 | } | |
8088 | group_name = sym->st_name < strtab_size | |
8089 | ? strtab + sym->st_name : _("<corrupt>"); | |
8090 | } | |
8091 | ||
8092 | /* PR 17531: file: loop. */ | |
8093 | if (section->sh_entsize > section->sh_size) | |
8094 | { | |
8095 | error (_("Section %s has sh_entsize (%#" PRIx64 ")" | |
8096 | " which is larger than its size (%#" PRIx64 ")\n"), | |
8097 | printable_section_name (filedata, section), | |
8098 | section->sh_entsize, | |
8099 | section->sh_size); | |
8100 | continue; | |
8101 | } | |
8102 | ||
8103 | start = (unsigned char *) get_data (NULL, filedata, section->sh_offset, | |
8104 | 1, section->sh_size, | |
8105 | _("section data")); | |
8106 | if (start == NULL) | |
8107 | continue; | |
8108 | ||
8109 | indices = start; | |
8110 | size = (section->sh_size / section->sh_entsize) - 1; | |
8111 | entry = byte_get (indices, 4); | |
8112 | indices += 4; | |
8113 | ||
8114 | if (do_section_groups) | |
8115 | { | |
8116 | printf (_("\n%sgroup section [%5u] `%s' [%s] contains %u sections:\n"), | |
8117 | get_group_flags (entry), i, name, group_name, size); | |
8118 | ||
8119 | printf (_(" [Index] Name\n")); | |
8120 | } | |
8121 | ||
8122 | group->group_index = i; | |
8123 | ||
8124 | for (j = 0; j < size; j++) | |
8125 | { | |
8126 | struct group_list * g; | |
8127 | ||
8128 | entry = byte_get (indices, 4); | |
8129 | indices += 4; | |
8130 | ||
8131 | if (entry >= filedata->file_header.e_shnum) | |
8132 | { | |
8133 | static unsigned num_group_errors = 0; | |
8134 | ||
8135 | if (num_group_errors ++ < 10) | |
8136 | { | |
8137 | error (_("section [%5u] in group section [%5u] > maximum section [%5u]\n"), | |
8138 | entry, i, filedata->file_header.e_shnum - 1); | |
8139 | if (num_group_errors == 10) | |
8140 | warn (_("Further error messages about overlarge group section indices suppressed\n")); | |
8141 | } | |
8142 | continue; | |
8143 | } | |
8144 | ||
8145 | if (filedata->section_headers_groups [entry] != NULL) | |
8146 | { | |
8147 | if (entry) | |
8148 | { | |
8149 | static unsigned num_errs = 0; | |
8150 | ||
8151 | if (num_errs ++ < 10) | |
8152 | { | |
8153 | error (_("section [%5u] in group section [%5u] already in group section [%5u]\n"), | |
8154 | entry, i, | |
8155 | filedata->section_headers_groups [entry]->group_index); | |
8156 | if (num_errs == 10) | |
8157 | warn (_("Further error messages about already contained group sections suppressed\n")); | |
8158 | } | |
8159 | continue; | |
8160 | } | |
8161 | else | |
8162 | { | |
8163 | /* Intel C/C++ compiler may put section 0 in a | |
8164 | section group. We just warn it the first time | |
8165 | and ignore it afterwards. */ | |
8166 | static bool warned = false; | |
8167 | if (!warned) | |
8168 | { | |
8169 | error (_("section 0 in group section [%5u]\n"), | |
8170 | filedata->section_headers_groups [entry]->group_index); | |
8171 | warned = true; | |
8172 | } | |
8173 | } | |
8174 | } | |
8175 | ||
8176 | filedata->section_headers_groups [entry] = group; | |
8177 | ||
8178 | if (do_section_groups) | |
8179 | { | |
8180 | sec = filedata->section_headers + entry; | |
8181 | printf (" [%5u] %s\n", entry, printable_section_name (filedata, sec)); | |
8182 | } | |
8183 | ||
8184 | g = (struct group_list *) xmalloc (sizeof (struct group_list)); | |
8185 | g->section_index = entry; | |
8186 | g->next = group->root; | |
8187 | group->root = g; | |
8188 | } | |
8189 | ||
8190 | free (start); | |
8191 | ||
8192 | group++; | |
8193 | } | |
8194 | } | |
8195 | ||
8196 | free (symtab); | |
8197 | free (strtab); | |
8198 | return true; | |
8199 | } | |
8200 | ||
8201 | /* Data used to display dynamic fixups. */ | |
8202 | ||
8203 | struct ia64_vms_dynfixup | |
8204 | { | |
8205 | uint64_t needed_ident; /* Library ident number. */ | |
8206 | uint64_t needed; /* Index in the dstrtab of the library name. */ | |
8207 | uint64_t fixup_needed; /* Index of the library. */ | |
8208 | uint64_t fixup_rela_cnt; /* Number of fixups. */ | |
8209 | uint64_t fixup_rela_off; /* Fixups offset in the dynamic segment. */ | |
8210 | }; | |
8211 | ||
8212 | /* Data used to display dynamic relocations. */ | |
8213 | ||
8214 | struct ia64_vms_dynimgrela | |
8215 | { | |
8216 | uint64_t img_rela_cnt; /* Number of relocations. */ | |
8217 | uint64_t img_rela_off; /* Reloc offset in the dynamic segment. */ | |
8218 | }; | |
8219 | ||
8220 | /* Display IA-64 OpenVMS dynamic fixups (used to dynamically link a shared | |
8221 | library). */ | |
8222 | ||
8223 | static bool | |
8224 | dump_ia64_vms_dynamic_fixups (Filedata * filedata, | |
8225 | struct ia64_vms_dynfixup * fixup, | |
8226 | const char * strtab, | |
8227 | unsigned int strtab_sz) | |
8228 | { | |
8229 | Elf64_External_VMS_IMAGE_FIXUP * imfs; | |
8230 | size_t i; | |
8231 | const char * lib_name; | |
8232 | ||
8233 | imfs = get_data (NULL, filedata, | |
8234 | filedata->dynamic_addr + fixup->fixup_rela_off, | |
8235 | sizeof (*imfs), fixup->fixup_rela_cnt, | |
8236 | _("dynamic section image fixups")); | |
8237 | if (!imfs) | |
8238 | return false; | |
8239 | ||
8240 | if (fixup->needed < strtab_sz) | |
8241 | lib_name = strtab + fixup->needed; | |
8242 | else | |
8243 | { | |
8244 | warn (_("corrupt library name index of %#" PRIx64 | |
8245 | " found in dynamic entry"), fixup->needed); | |
8246 | lib_name = "???"; | |
8247 | } | |
8248 | ||
8249 | printf (_("\nImage fixups for needed library #%" PRId64 | |
8250 | ": %s - ident: %" PRIx64 "\n"), | |
8251 | fixup->fixup_needed, lib_name, fixup->needed_ident); | |
8252 | printf | |
8253 | (_("Seg Offset Type SymVec DataType\n")); | |
8254 | ||
8255 | for (i = 0; i < (size_t) fixup->fixup_rela_cnt; i++) | |
8256 | { | |
8257 | unsigned int type; | |
8258 | const char *rtype; | |
8259 | ||
8260 | printf ("%3u ", (unsigned) BYTE_GET (imfs [i].fixup_seg)); | |
8261 | printf ("%016" PRIx64 " ", BYTE_GET (imfs [i].fixup_offset)); | |
8262 | type = BYTE_GET (imfs [i].type); | |
8263 | rtype = elf_ia64_reloc_type (type); | |
8264 | if (rtype == NULL) | |
8265 | printf ("0x%08x ", type); | |
8266 | else | |
8267 | printf ("%-32s ", rtype); | |
8268 | printf ("%6u ", (unsigned) BYTE_GET (imfs [i].symvec_index)); | |
8269 | printf ("0x%08x\n", (unsigned) BYTE_GET (imfs [i].data_type)); | |
8270 | } | |
8271 | ||
8272 | free (imfs); | |
8273 | return true; | |
8274 | } | |
8275 | ||
8276 | /* Display IA-64 OpenVMS dynamic relocations (used to relocate an image). */ | |
8277 | ||
8278 | static bool | |
8279 | dump_ia64_vms_dynamic_relocs (Filedata * filedata, struct ia64_vms_dynimgrela *imgrela) | |
8280 | { | |
8281 | Elf64_External_VMS_IMAGE_RELA *imrs; | |
8282 | size_t i; | |
8283 | ||
8284 | imrs = get_data (NULL, filedata, | |
8285 | filedata->dynamic_addr + imgrela->img_rela_off, | |
8286 | sizeof (*imrs), imgrela->img_rela_cnt, | |
8287 | _("dynamic section image relocations")); | |
8288 | if (!imrs) | |
8289 | return false; | |
8290 | ||
8291 | printf (_("\nImage relocs\n")); | |
8292 | printf | |
8293 | (_("Seg Offset Type Addend Seg Sym Off\n")); | |
8294 | ||
8295 | for (i = 0; i < (size_t) imgrela->img_rela_cnt; i++) | |
8296 | { | |
8297 | unsigned int type; | |
8298 | const char *rtype; | |
8299 | ||
8300 | printf ("%3u ", (unsigned) BYTE_GET (imrs [i].rela_seg)); | |
8301 | printf ("%08" PRIx64 " ", BYTE_GET (imrs [i].rela_offset)); | |
8302 | type = BYTE_GET (imrs [i].type); | |
8303 | rtype = elf_ia64_reloc_type (type); | |
8304 | if (rtype == NULL) | |
8305 | printf ("0x%08x ", type); | |
8306 | else | |
8307 | printf ("%-31s ", rtype); | |
8308 | print_vma (BYTE_GET (imrs [i].addend), FULL_HEX); | |
8309 | printf ("%3u ", (unsigned) BYTE_GET (imrs [i].sym_seg)); | |
8310 | printf ("%08" PRIx64 "\n", BYTE_GET (imrs [i].sym_offset)); | |
8311 | } | |
8312 | ||
8313 | free (imrs); | |
8314 | return true; | |
8315 | } | |
8316 | ||
8317 | /* Display IA-64 OpenVMS dynamic relocations and fixups. */ | |
8318 | ||
8319 | static bool | |
8320 | process_ia64_vms_dynamic_relocs (Filedata * filedata) | |
8321 | { | |
8322 | struct ia64_vms_dynfixup fixup; | |
8323 | struct ia64_vms_dynimgrela imgrela; | |
8324 | Elf_Internal_Dyn *entry; | |
8325 | uint64_t strtab_off = 0; | |
8326 | uint64_t strtab_sz = 0; | |
8327 | char *strtab = NULL; | |
8328 | bool res = true; | |
8329 | ||
8330 | memset (&fixup, 0, sizeof (fixup)); | |
8331 | memset (&imgrela, 0, sizeof (imgrela)); | |
8332 | ||
8333 | /* Note: the order of the entries is specified by the OpenVMS specs. */ | |
8334 | for (entry = filedata->dynamic_section; | |
8335 | entry < filedata->dynamic_section + filedata->dynamic_nent; | |
8336 | entry++) | |
8337 | { | |
8338 | switch (entry->d_tag) | |
8339 | { | |
8340 | case DT_IA_64_VMS_STRTAB_OFFSET: | |
8341 | strtab_off = entry->d_un.d_val; | |
8342 | break; | |
8343 | case DT_STRSZ: | |
8344 | strtab_sz = entry->d_un.d_val; | |
8345 | if (strtab == NULL) | |
8346 | strtab = get_data (NULL, filedata, | |
8347 | filedata->dynamic_addr + strtab_off, | |
8348 | 1, strtab_sz, _("dynamic string section")); | |
8349 | if (strtab == NULL) | |
8350 | strtab_sz = 0; | |
8351 | break; | |
8352 | ||
8353 | case DT_IA_64_VMS_NEEDED_IDENT: | |
8354 | fixup.needed_ident = entry->d_un.d_val; | |
8355 | break; | |
8356 | case DT_NEEDED: | |
8357 | fixup.needed = entry->d_un.d_val; | |
8358 | break; | |
8359 | case DT_IA_64_VMS_FIXUP_NEEDED: | |
8360 | fixup.fixup_needed = entry->d_un.d_val; | |
8361 | break; | |
8362 | case DT_IA_64_VMS_FIXUP_RELA_CNT: | |
8363 | fixup.fixup_rela_cnt = entry->d_un.d_val; | |
8364 | break; | |
8365 | case DT_IA_64_VMS_FIXUP_RELA_OFF: | |
8366 | fixup.fixup_rela_off = entry->d_un.d_val; | |
8367 | if (! dump_ia64_vms_dynamic_fixups (filedata, &fixup, strtab, strtab_sz)) | |
8368 | res = false; | |
8369 | break; | |
8370 | case DT_IA_64_VMS_IMG_RELA_CNT: | |
8371 | imgrela.img_rela_cnt = entry->d_un.d_val; | |
8372 | break; | |
8373 | case DT_IA_64_VMS_IMG_RELA_OFF: | |
8374 | imgrela.img_rela_off = entry->d_un.d_val; | |
8375 | if (! dump_ia64_vms_dynamic_relocs (filedata, &imgrela)) | |
8376 | res = false; | |
8377 | break; | |
8378 | ||
8379 | default: | |
8380 | break; | |
8381 | } | |
8382 | } | |
8383 | ||
8384 | free (strtab); | |
8385 | ||
8386 | return res; | |
8387 | } | |
8388 | ||
8389 | static struct | |
8390 | { | |
8391 | const char * name; | |
8392 | int reloc; | |
8393 | int size; | |
8394 | relocation_type rel_type; | |
8395 | } | |
8396 | dynamic_relocations [] = | |
8397 | { | |
8398 | { "REL", DT_REL, DT_RELSZ, reltype_rel }, | |
8399 | { "RELA", DT_RELA, DT_RELASZ, reltype_rela }, | |
8400 | { "RELR", DT_RELR, DT_RELRSZ, reltype_relr }, | |
8401 | { "PLT", DT_JMPREL, DT_PLTRELSZ, reltype_unknown } | |
8402 | }; | |
8403 | ||
8404 | /* Process the reloc section. */ | |
8405 | ||
8406 | static bool | |
8407 | process_relocs (Filedata * filedata) | |
8408 | { | |
8409 | uint64_t rel_size; | |
8410 | uint64_t rel_offset; | |
8411 | ||
8412 | if (!do_reloc) | |
8413 | return true; | |
8414 | ||
8415 | if (do_using_dynamic) | |
8416 | { | |
8417 | relocation_type rel_type; | |
8418 | const char * name; | |
8419 | bool has_dynamic_reloc; | |
8420 | unsigned int i; | |
8421 | ||
8422 | has_dynamic_reloc = false; | |
8423 | ||
8424 | for (i = 0; i < ARRAY_SIZE (dynamic_relocations); i++) | |
8425 | { | |
8426 | rel_type = dynamic_relocations [i].rel_type; | |
8427 | name = dynamic_relocations [i].name; | |
8428 | rel_size = filedata->dynamic_info[dynamic_relocations [i].size]; | |
8429 | rel_offset = filedata->dynamic_info[dynamic_relocations [i].reloc]; | |
8430 | ||
8431 | if (rel_size) | |
8432 | has_dynamic_reloc = true; | |
8433 | ||
8434 | if (rel_type == reltype_unknown) | |
8435 | { | |
8436 | if (dynamic_relocations [i].reloc == DT_JMPREL) | |
8437 | switch (filedata->dynamic_info[DT_PLTREL]) | |
8438 | { | |
8439 | case DT_REL: | |
8440 | rel_type = reltype_rel; | |
8441 | break; | |
8442 | case DT_RELA: | |
8443 | rel_type = reltype_rela; | |
8444 | break; | |
8445 | } | |
8446 | } | |
8447 | ||
8448 | if (rel_size) | |
8449 | { | |
8450 | if (filedata->is_separate) | |
8451 | printf | |
8452 | (_("\nIn linked file '%s' section '%s' at offset %#" PRIx64 | |
8453 | " contains %" PRId64 " bytes:\n"), | |
8454 | filedata->file_name, name, rel_offset, rel_size); | |
8455 | else | |
8456 | printf | |
8457 | (_("\n'%s' relocation section at offset %#" PRIx64 | |
8458 | " contains %" PRId64 " bytes:\n"), | |
8459 | name, rel_offset, rel_size); | |
8460 | ||
8461 | dump_relocations (filedata, | |
8462 | offset_from_vma (filedata, rel_offset, rel_size), | |
8463 | rel_size, | |
8464 | filedata->dynamic_symbols, | |
8465 | filedata->num_dynamic_syms, | |
8466 | filedata->dynamic_strings, | |
8467 | filedata->dynamic_strings_length, | |
8468 | rel_type, true /* is_dynamic */); | |
8469 | } | |
8470 | } | |
8471 | ||
8472 | if (is_ia64_vms (filedata)) | |
8473 | if (process_ia64_vms_dynamic_relocs (filedata)) | |
8474 | has_dynamic_reloc = true; | |
8475 | ||
8476 | if (! has_dynamic_reloc) | |
8477 | { | |
8478 | if (filedata->is_separate) | |
8479 | printf (_("\nThere are no dynamic relocations in linked file '%s'.\n"), | |
8480 | filedata->file_name); | |
8481 | else | |
8482 | printf (_("\nThere are no dynamic relocations in this file.\n")); | |
8483 | } | |
8484 | } | |
8485 | else | |
8486 | { | |
8487 | Elf_Internal_Shdr * section; | |
8488 | size_t i; | |
8489 | bool found = false; | |
8490 | ||
8491 | for (i = 0, section = filedata->section_headers; | |
8492 | i < filedata->file_header.e_shnum; | |
8493 | i++, section++) | |
8494 | { | |
8495 | if ( section->sh_type != SHT_RELA | |
8496 | && section->sh_type != SHT_REL | |
8497 | && section->sh_type != SHT_RELR) | |
8498 | continue; | |
8499 | ||
8500 | rel_offset = section->sh_offset; | |
8501 | rel_size = section->sh_size; | |
8502 | ||
8503 | if (rel_size) | |
8504 | { | |
8505 | relocation_type rel_type; | |
8506 | uint64_t num_rela; | |
8507 | ||
8508 | if (filedata->is_separate) | |
8509 | printf (_("\nIn linked file '%s' relocation section "), | |
8510 | filedata->file_name); | |
8511 | else | |
8512 | printf (_("\nRelocation section ")); | |
8513 | ||
8514 | if (filedata->string_table == NULL) | |
8515 | printf ("%d", section->sh_name); | |
8516 | else | |
8517 | printf ("'%s'", printable_section_name (filedata, section)); | |
8518 | ||
8519 | num_rela = rel_size / section->sh_entsize; | |
8520 | printf (ngettext (" at offset %#" PRIx64 | |
8521 | " contains %" PRIu64 " entry:\n", | |
8522 | " at offset %#" PRIx64 | |
8523 | " contains %" PRId64 " entries:\n", | |
8524 | num_rela), | |
8525 | rel_offset, num_rela); | |
8526 | ||
8527 | rel_type = section->sh_type == SHT_RELA ? reltype_rela : | |
8528 | section->sh_type == SHT_REL ? reltype_rel : reltype_relr; | |
8529 | ||
8530 | if (section->sh_link != 0 | |
8531 | && section->sh_link < filedata->file_header.e_shnum) | |
8532 | { | |
8533 | Elf_Internal_Shdr *symsec; | |
8534 | Elf_Internal_Sym *symtab; | |
8535 | uint64_t nsyms; | |
8536 | uint64_t strtablen = 0; | |
8537 | char *strtab = NULL; | |
8538 | ||
8539 | symsec = filedata->section_headers + section->sh_link; | |
8540 | if (symsec->sh_type != SHT_SYMTAB | |
8541 | && symsec->sh_type != SHT_DYNSYM) | |
8542 | continue; | |
8543 | ||
8544 | if (!get_symtab (filedata, symsec, | |
8545 | &symtab, &nsyms, &strtab, &strtablen)) | |
8546 | continue; | |
8547 | ||
8548 | dump_relocations (filedata, rel_offset, rel_size, | |
8549 | symtab, nsyms, strtab, strtablen, | |
8550 | rel_type, | |
8551 | symsec->sh_type == SHT_DYNSYM); | |
8552 | free (strtab); | |
8553 | free (symtab); | |
8554 | } | |
8555 | else | |
8556 | dump_relocations (filedata, rel_offset, rel_size, | |
8557 | NULL, 0, NULL, 0, rel_type, false /* is_dynamic */); | |
8558 | ||
8559 | found = true; | |
8560 | } | |
8561 | } | |
8562 | ||
8563 | if (! found) | |
8564 | { | |
8565 | /* Users sometimes forget the -D option, so try to be helpful. */ | |
8566 | for (i = 0; i < ARRAY_SIZE (dynamic_relocations); i++) | |
8567 | { | |
8568 | if (filedata->dynamic_info[dynamic_relocations [i].size]) | |
8569 | { | |
8570 | if (filedata->is_separate) | |
8571 | printf (_("\nThere are no static relocations in linked file '%s'."), | |
8572 | filedata->file_name); | |
8573 | else | |
8574 | printf (_("\nThere are no static relocations in this file.")); | |
8575 | printf (_("\nTo see the dynamic relocations add --use-dynamic to the command line.\n")); | |
8576 | ||
8577 | break; | |
8578 | } | |
8579 | } | |
8580 | if (i == ARRAY_SIZE (dynamic_relocations)) | |
8581 | { | |
8582 | if (filedata->is_separate) | |
8583 | printf (_("\nThere are no relocations in linked file '%s'.\n"), | |
8584 | filedata->file_name); | |
8585 | else | |
8586 | printf (_("\nThere are no relocations in this file.\n")); | |
8587 | } | |
8588 | } | |
8589 | } | |
8590 | ||
8591 | return true; | |
8592 | } | |
8593 | ||
8594 | /* An absolute address consists of a section and an offset. If the | |
8595 | section is NULL, the offset itself is the address, otherwise, the | |
8596 | address equals to LOAD_ADDRESS(section) + offset. */ | |
8597 | ||
8598 | struct absaddr | |
8599 | { | |
8600 | unsigned short section; | |
8601 | uint64_t offset; | |
8602 | }; | |
8603 | ||
8604 | /* Find the nearest symbol at or below ADDR. Returns the symbol | |
8605 | name, if found, and the offset from the symbol to ADDR. */ | |
8606 | ||
8607 | static void | |
8608 | find_symbol_for_address (Filedata *filedata, | |
8609 | Elf_Internal_Sym *symtab, | |
8610 | uint64_t nsyms, | |
8611 | const char *strtab, | |
8612 | uint64_t strtab_size, | |
8613 | struct absaddr addr, | |
8614 | const char **symname, | |
8615 | uint64_t *offset) | |
8616 | { | |
8617 | uint64_t dist = 0x100000; | |
8618 | Elf_Internal_Sym * sym; | |
8619 | Elf_Internal_Sym * beg; | |
8620 | Elf_Internal_Sym * end; | |
8621 | Elf_Internal_Sym * best = NULL; | |
8622 | ||
8623 | REMOVE_ARCH_BITS (addr.offset); | |
8624 | beg = symtab; | |
8625 | end = symtab + nsyms; | |
8626 | ||
8627 | while (beg < end) | |
8628 | { | |
8629 | uint64_t value; | |
8630 | ||
8631 | sym = beg + (end - beg) / 2; | |
8632 | ||
8633 | value = sym->st_value; | |
8634 | REMOVE_ARCH_BITS (value); | |
8635 | ||
8636 | if (sym->st_name != 0 | |
8637 | && (addr.section == SHN_UNDEF || addr.section == sym->st_shndx) | |
8638 | && addr.offset >= value | |
8639 | && addr.offset - value < dist) | |
8640 | { | |
8641 | best = sym; | |
8642 | dist = addr.offset - value; | |
8643 | if (!dist) | |
8644 | break; | |
8645 | } | |
8646 | ||
8647 | if (addr.offset < value) | |
8648 | end = sym; | |
8649 | else | |
8650 | beg = sym + 1; | |
8651 | } | |
8652 | ||
8653 | if (best) | |
8654 | { | |
8655 | *symname = (best->st_name >= strtab_size | |
8656 | ? _("<corrupt>") : strtab + best->st_name); | |
8657 | *offset = dist; | |
8658 | return; | |
8659 | } | |
8660 | ||
8661 | *symname = NULL; | |
8662 | *offset = addr.offset; | |
8663 | } | |
8664 | ||
8665 | static /* signed */ int | |
8666 | symcmp (const void *p, const void *q) | |
8667 | { | |
8668 | Elf_Internal_Sym *sp = (Elf_Internal_Sym *) p; | |
8669 | Elf_Internal_Sym *sq = (Elf_Internal_Sym *) q; | |
8670 | ||
8671 | return sp->st_value > sq->st_value ? 1 : (sp->st_value < sq->st_value ? -1 : 0); | |
8672 | } | |
8673 | ||
8674 | /* Process the unwind section. */ | |
8675 | ||
8676 | #include "unwind-ia64.h" | |
8677 | ||
8678 | struct ia64_unw_table_entry | |
8679 | { | |
8680 | struct absaddr start; | |
8681 | struct absaddr end; | |
8682 | struct absaddr info; | |
8683 | }; | |
8684 | ||
8685 | struct ia64_unw_aux_info | |
8686 | { | |
8687 | struct ia64_unw_table_entry * table; /* Unwind table. */ | |
8688 | uint64_t table_len; /* Length of unwind table. */ | |
8689 | unsigned char * info; /* Unwind info. */ | |
8690 | uint64_t info_size; /* Size of unwind info. */ | |
8691 | uint64_t info_addr; /* Starting address of unwind info. */ | |
8692 | uint64_t seg_base; /* Starting address of segment. */ | |
8693 | Elf_Internal_Sym * symtab; /* The symbol table. */ | |
8694 | uint64_t nsyms; /* Number of symbols. */ | |
8695 | Elf_Internal_Sym * funtab; /* Sorted table of STT_FUNC symbols. */ | |
8696 | uint64_t nfuns; /* Number of entries in funtab. */ | |
8697 | char * strtab; /* The string table. */ | |
8698 | uint64_t strtab_size; /* Size of string table. */ | |
8699 | }; | |
8700 | ||
8701 | static bool | |
8702 | dump_ia64_unwind (Filedata * filedata, struct ia64_unw_aux_info * aux) | |
8703 | { | |
8704 | struct ia64_unw_table_entry * tp; | |
8705 | size_t j, nfuns; | |
8706 | int in_body; | |
8707 | bool res = true; | |
8708 | ||
8709 | aux->funtab = xmalloc (aux->nsyms * sizeof (Elf_Internal_Sym)); | |
8710 | for (nfuns = 0, j = 0; j < aux->nsyms; j++) | |
8711 | if (aux->symtab[j].st_value && ELF_ST_TYPE (aux->symtab[j].st_info) == STT_FUNC) | |
8712 | aux->funtab[nfuns++] = aux->symtab[j]; | |
8713 | aux->nfuns = nfuns; | |
8714 | qsort (aux->funtab, aux->nfuns, sizeof (Elf_Internal_Sym), symcmp); | |
8715 | ||
8716 | for (tp = aux->table; tp < aux->table + aux->table_len; ++tp) | |
8717 | { | |
8718 | uint64_t stamp; | |
8719 | uint64_t offset; | |
8720 | const unsigned char * dp; | |
8721 | const unsigned char * head; | |
8722 | const unsigned char * end; | |
8723 | const char * procname; | |
8724 | ||
8725 | find_symbol_for_address (filedata, aux->funtab, aux->nfuns, aux->strtab, | |
8726 | aux->strtab_size, tp->start, &procname, &offset); | |
8727 | ||
8728 | fputs ("\n<", stdout); | |
8729 | ||
8730 | if (procname) | |
8731 | { | |
8732 | fputs (procname, stdout); | |
8733 | ||
8734 | if (offset) | |
8735 | printf ("+%" PRIx64, offset); | |
8736 | } | |
8737 | ||
8738 | fputs (">: [", stdout); | |
8739 | print_vma (tp->start.offset, PREFIX_HEX); | |
8740 | fputc ('-', stdout); | |
8741 | print_vma (tp->end.offset, PREFIX_HEX); | |
8742 | printf ("], info at +0x%" PRIx64 "\n", | |
8743 | tp->info.offset - aux->seg_base); | |
8744 | ||
8745 | /* PR 17531: file: 86232b32. */ | |
8746 | if (aux->info == NULL) | |
8747 | continue; | |
8748 | ||
8749 | offset = tp->info.offset; | |
8750 | if (tp->info.section) | |
8751 | { | |
8752 | if (tp->info.section >= filedata->file_header.e_shnum) | |
8753 | { | |
8754 | warn (_("Invalid section %u in table entry %td\n"), | |
8755 | tp->info.section, tp - aux->table); | |
8756 | res = false; | |
8757 | continue; | |
8758 | } | |
8759 | offset += filedata->section_headers[tp->info.section].sh_addr; | |
8760 | } | |
8761 | offset -= aux->info_addr; | |
8762 | /* PR 17531: file: 0997b4d1. */ | |
8763 | if (offset >= aux->info_size | |
8764 | || aux->info_size - offset < 8) | |
8765 | { | |
8766 | warn (_("Invalid offset %" PRIx64 " in table entry %td\n"), | |
8767 | tp->info.offset, tp - aux->table); | |
8768 | res = false; | |
8769 | continue; | |
8770 | } | |
8771 | ||
8772 | head = aux->info + offset; | |
8773 | stamp = byte_get ((unsigned char *) head, sizeof (stamp)); | |
8774 | ||
8775 | printf (" v%u, flags=0x%lx (%s%s), len=%lu bytes\n", | |
8776 | (unsigned) UNW_VER (stamp), | |
8777 | (unsigned long) ((stamp & UNW_FLAG_MASK) >> 32), | |
8778 | UNW_FLAG_EHANDLER (stamp) ? " ehandler" : "", | |
8779 | UNW_FLAG_UHANDLER (stamp) ? " uhandler" : "", | |
8780 | (unsigned long) (eh_addr_size * UNW_LENGTH (stamp))); | |
8781 | ||
8782 | if (UNW_VER (stamp) != 1) | |
8783 | { | |
8784 | printf (_("\tUnknown version.\n")); | |
8785 | continue; | |
8786 | } | |
8787 | ||
8788 | in_body = 0; | |
8789 | end = head + 8 + eh_addr_size * UNW_LENGTH (stamp); | |
8790 | /* PR 17531: file: 16ceda89. */ | |
8791 | if (end > aux->info + aux->info_size) | |
8792 | end = aux->info + aux->info_size; | |
8793 | for (dp = head + 8; dp < end;) | |
8794 | dp = unw_decode (dp, in_body, & in_body, end); | |
8795 | } | |
8796 | ||
8797 | free (aux->funtab); | |
8798 | ||
8799 | return res; | |
8800 | } | |
8801 | ||
8802 | static bool | |
8803 | slurp_ia64_unwind_table (Filedata * filedata, | |
8804 | struct ia64_unw_aux_info * aux, | |
8805 | Elf_Internal_Shdr * sec) | |
8806 | { | |
8807 | uint64_t size, nrelas, i; | |
8808 | Elf_Internal_Phdr * seg; | |
8809 | struct ia64_unw_table_entry * tep; | |
8810 | Elf_Internal_Shdr * relsec; | |
8811 | Elf_Internal_Rela * rela; | |
8812 | Elf_Internal_Rela * rp; | |
8813 | unsigned char * table; | |
8814 | unsigned char * tp; | |
8815 | Elf_Internal_Sym * sym; | |
8816 | const char * relname; | |
8817 | ||
8818 | aux->table_len = 0; | |
8819 | ||
8820 | /* First, find the starting address of the segment that includes | |
8821 | this section: */ | |
8822 | ||
8823 | if (filedata->file_header.e_phnum) | |
8824 | { | |
8825 | if (! get_program_headers (filedata)) | |
8826 | return false; | |
8827 | ||
8828 | for (seg = filedata->program_headers; | |
8829 | seg < filedata->program_headers + filedata->file_header.e_phnum; | |
8830 | ++seg) | |
8831 | { | |
8832 | if (seg->p_type != PT_LOAD) | |
8833 | continue; | |
8834 | ||
8835 | if (sec->sh_addr >= seg->p_vaddr | |
8836 | && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz)) | |
8837 | { | |
8838 | aux->seg_base = seg->p_vaddr; | |
8839 | break; | |
8840 | } | |
8841 | } | |
8842 | } | |
8843 | ||
8844 | /* Second, build the unwind table from the contents of the unwind section: */ | |
8845 | size = sec->sh_size; | |
8846 | table = (unsigned char *) get_data (NULL, filedata, sec->sh_offset, 1, size, | |
8847 | _("unwind table")); | |
8848 | if (!table) | |
8849 | return false; | |
8850 | ||
8851 | aux->table_len = size / (3 * eh_addr_size); | |
8852 | aux->table = (struct ia64_unw_table_entry *) | |
8853 | xcmalloc (aux->table_len, sizeof (aux->table[0])); | |
8854 | tep = aux->table; | |
8855 | ||
8856 | for (tp = table; tp <= table + size - (3 * eh_addr_size); ++tep) | |
8857 | { | |
8858 | tep->start.section = SHN_UNDEF; | |
8859 | tep->end.section = SHN_UNDEF; | |
8860 | tep->info.section = SHN_UNDEF; | |
8861 | tep->start.offset = byte_get (tp, eh_addr_size); tp += eh_addr_size; | |
8862 | tep->end.offset = byte_get (tp, eh_addr_size); tp += eh_addr_size; | |
8863 | tep->info.offset = byte_get (tp, eh_addr_size); tp += eh_addr_size; | |
8864 | tep->start.offset += aux->seg_base; | |
8865 | tep->end.offset += aux->seg_base; | |
8866 | tep->info.offset += aux->seg_base; | |
8867 | } | |
8868 | free (table); | |
8869 | ||
8870 | /* Third, apply any relocations to the unwind table: */ | |
8871 | for (relsec = filedata->section_headers; | |
8872 | relsec < filedata->section_headers + filedata->file_header.e_shnum; | |
8873 | ++relsec) | |
8874 | { | |
8875 | if (relsec->sh_type != SHT_RELA | |
8876 | || relsec->sh_info >= filedata->file_header.e_shnum | |
8877 | || filedata->section_headers + relsec->sh_info != sec) | |
8878 | continue; | |
8879 | ||
8880 | if (!slurp_rela_relocs (filedata, relsec->sh_offset, relsec->sh_size, | |
8881 | & rela, & nrelas)) | |
8882 | { | |
8883 | free (aux->table); | |
8884 | aux->table = NULL; | |
8885 | aux->table_len = 0; | |
8886 | return false; | |
8887 | } | |
8888 | ||
8889 | for (rp = rela; rp < rela + nrelas; ++rp) | |
8890 | { | |
8891 | unsigned int sym_ndx; | |
8892 | unsigned int r_type = get_reloc_type (filedata, rp->r_info); | |
8893 | relname = elf_ia64_reloc_type (r_type); | |
8894 | ||
8895 | /* PR 17531: file: 9fa67536. */ | |
8896 | if (relname == NULL) | |
8897 | { | |
8898 | warn (_("Skipping unknown relocation type: %u\n"), r_type); | |
8899 | continue; | |
8900 | } | |
8901 | ||
8902 | if (! startswith (relname, "R_IA64_SEGREL")) | |
8903 | { | |
8904 | warn (_("Skipping unexpected relocation type: %s\n"), relname); | |
8905 | continue; | |
8906 | } | |
8907 | ||
8908 | i = rp->r_offset / (3 * eh_addr_size); | |
8909 | ||
8910 | /* PR 17531: file: 5bc8d9bf. */ | |
8911 | if (i >= aux->table_len) | |
8912 | { | |
8913 | warn (_("Skipping reloc with overlarge offset: %#" PRIx64 "\n"), | |
8914 | i); | |
8915 | continue; | |
8916 | } | |
8917 | ||
8918 | sym_ndx = get_reloc_symindex (rp->r_info); | |
8919 | if (sym_ndx >= aux->nsyms) | |
8920 | { | |
8921 | warn (_("Skipping reloc with invalid symbol index: %u\n"), | |
8922 | sym_ndx); | |
8923 | continue; | |
8924 | } | |
8925 | sym = aux->symtab + sym_ndx; | |
8926 | ||
8927 | switch (rp->r_offset / eh_addr_size % 3) | |
8928 | { | |
8929 | case 0: | |
8930 | aux->table[i].start.section = sym->st_shndx; | |
8931 | aux->table[i].start.offset = rp->r_addend + sym->st_value; | |
8932 | break; | |
8933 | case 1: | |
8934 | aux->table[i].end.section = sym->st_shndx; | |
8935 | aux->table[i].end.offset = rp->r_addend + sym->st_value; | |
8936 | break; | |
8937 | case 2: | |
8938 | aux->table[i].info.section = sym->st_shndx; | |
8939 | aux->table[i].info.offset = rp->r_addend + sym->st_value; | |
8940 | break; | |
8941 | default: | |
8942 | break; | |
8943 | } | |
8944 | } | |
8945 | ||
8946 | free (rela); | |
8947 | } | |
8948 | ||
8949 | return true; | |
8950 | } | |
8951 | ||
8952 | static bool | |
8953 | ia64_process_unwind (Filedata * filedata) | |
8954 | { | |
8955 | Elf_Internal_Shdr * sec; | |
8956 | Elf_Internal_Shdr * unwsec = NULL; | |
8957 | uint64_t i, unwcount = 0, unwstart = 0; | |
8958 | struct ia64_unw_aux_info aux; | |
8959 | bool res = true; | |
8960 | ||
8961 | memset (& aux, 0, sizeof (aux)); | |
8962 | ||
8963 | for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec) | |
8964 | { | |
8965 | if (sec->sh_type == SHT_SYMTAB) | |
8966 | { | |
8967 | if (aux.symtab) | |
8968 | { | |
8969 | error (_("Multiple symbol tables encountered\n")); | |
8970 | free (aux.symtab); | |
8971 | aux.symtab = NULL; | |
8972 | free (aux.strtab); | |
8973 | aux.strtab = NULL; | |
8974 | } | |
8975 | if (!get_symtab (filedata, sec, &aux.symtab, &aux.nsyms, | |
8976 | &aux.strtab, &aux.strtab_size)) | |
8977 | return false; | |
8978 | } | |
8979 | else if (sec->sh_type == SHT_IA_64_UNWIND) | |
8980 | unwcount++; | |
8981 | } | |
8982 | ||
8983 | if (!unwcount) | |
8984 | printf (_("\nThere are no unwind sections in this file.\n")); | |
8985 | ||
8986 | while (unwcount-- > 0) | |
8987 | { | |
8988 | const char *suffix; | |
8989 | size_t len, len2; | |
8990 | ||
8991 | for (i = unwstart, sec = filedata->section_headers + unwstart, unwsec = NULL; | |
8992 | i < filedata->file_header.e_shnum; ++i, ++sec) | |
8993 | if (sec->sh_type == SHT_IA_64_UNWIND) | |
8994 | { | |
8995 | unwsec = sec; | |
8996 | break; | |
8997 | } | |
8998 | /* We have already counted the number of SHT_IA64_UNWIND | |
8999 | sections so the loop above should never fail. */ | |
9000 | assert (unwsec != NULL); | |
9001 | ||
9002 | unwstart = i + 1; | |
9003 | len = sizeof (ELF_STRING_ia64_unwind_once) - 1; | |
9004 | ||
9005 | if ((unwsec->sh_flags & SHF_GROUP) != 0) | |
9006 | { | |
9007 | /* We need to find which section group it is in. */ | |
9008 | struct group_list * g; | |
9009 | ||
9010 | if (filedata->section_headers_groups == NULL | |
9011 | || filedata->section_headers_groups[i] == NULL) | |
9012 | i = filedata->file_header.e_shnum; | |
9013 | else | |
9014 | { | |
9015 | g = filedata->section_headers_groups[i]->root; | |
9016 | ||
9017 | for (; g != NULL; g = g->next) | |
9018 | { | |
9019 | sec = filedata->section_headers + g->section_index; | |
9020 | ||
9021 | if (section_name_valid (filedata, sec) | |
9022 | && streq (section_name (filedata, sec), | |
9023 | ELF_STRING_ia64_unwind_info)) | |
9024 | break; | |
9025 | } | |
9026 | ||
9027 | if (g == NULL) | |
9028 | i = filedata->file_header.e_shnum; | |
9029 | } | |
9030 | } | |
9031 | else if (section_name_valid (filedata, unwsec) | |
9032 | && startswith (section_name (filedata, unwsec), | |
9033 | ELF_STRING_ia64_unwind_once)) | |
9034 | { | |
9035 | /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO. */ | |
9036 | len2 = sizeof (ELF_STRING_ia64_unwind_info_once) - 1; | |
9037 | suffix = section_name (filedata, unwsec) + len; | |
9038 | for (i = 0, sec = filedata->section_headers; | |
9039 | i < filedata->file_header.e_shnum; | |
9040 | ++i, ++sec) | |
9041 | if (section_name_valid (filedata, sec) | |
9042 | && startswith (section_name (filedata, sec), | |
9043 | ELF_STRING_ia64_unwind_info_once) | |
9044 | && streq (section_name (filedata, sec) + len2, suffix)) | |
9045 | break; | |
9046 | } | |
9047 | else | |
9048 | { | |
9049 | /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO | |
9050 | .IA_64.unwind or BAR -> .IA_64.unwind_info. */ | |
9051 | len = sizeof (ELF_STRING_ia64_unwind) - 1; | |
9052 | len2 = sizeof (ELF_STRING_ia64_unwind_info) - 1; | |
9053 | suffix = ""; | |
9054 | if (section_name_valid (filedata, unwsec) | |
9055 | && startswith (section_name (filedata, unwsec), | |
9056 | ELF_STRING_ia64_unwind)) | |
9057 | suffix = section_name (filedata, unwsec) + len; | |
9058 | for (i = 0, sec = filedata->section_headers; | |
9059 | i < filedata->file_header.e_shnum; | |
9060 | ++i, ++sec) | |
9061 | if (section_name_valid (filedata, sec) | |
9062 | && startswith (section_name (filedata, sec), | |
9063 | ELF_STRING_ia64_unwind_info) | |
9064 | && streq (section_name (filedata, sec) + len2, suffix)) | |
9065 | break; | |
9066 | } | |
9067 | ||
9068 | if (i == filedata->file_header.e_shnum) | |
9069 | { | |
9070 | printf (_("\nCould not find unwind info section for ")); | |
9071 | ||
9072 | if (filedata->string_table == NULL) | |
9073 | printf ("%d", unwsec->sh_name); | |
9074 | else | |
9075 | printf ("'%s'", printable_section_name (filedata, unwsec)); | |
9076 | } | |
9077 | else | |
9078 | { | |
9079 | aux.info_addr = sec->sh_addr; | |
9080 | aux.info = (unsigned char *) get_data (NULL, filedata, sec->sh_offset, 1, | |
9081 | sec->sh_size, | |
9082 | _("unwind info")); | |
9083 | aux.info_size = aux.info == NULL ? 0 : sec->sh_size; | |
9084 | ||
9085 | printf (_("\nUnwind section ")); | |
9086 | ||
9087 | if (filedata->string_table == NULL) | |
9088 | printf ("%d", unwsec->sh_name); | |
9089 | else | |
9090 | printf ("'%s'", printable_section_name (filedata, unwsec)); | |
9091 | ||
9092 | printf (_(" at offset %#" PRIx64 " contains %" PRIu64 " entries:\n"), | |
9093 | unwsec->sh_offset, | |
9094 | unwsec->sh_size / (3 * eh_addr_size)); | |
9095 | ||
9096 | if (slurp_ia64_unwind_table (filedata, & aux, unwsec) | |
9097 | && aux.table_len > 0) | |
9098 | dump_ia64_unwind (filedata, & aux); | |
9099 | ||
9100 | free ((char *) aux.table); | |
9101 | free ((char *) aux.info); | |
9102 | aux.table = NULL; | |
9103 | aux.info = NULL; | |
9104 | } | |
9105 | } | |
9106 | ||
9107 | free (aux.symtab); | |
9108 | free ((char *) aux.strtab); | |
9109 | ||
9110 | return res; | |
9111 | } | |
9112 | ||
9113 | struct hppa_unw_table_entry | |
9114 | { | |
9115 | struct absaddr start; | |
9116 | struct absaddr end; | |
9117 | unsigned int Cannot_unwind:1; /* 0 */ | |
9118 | unsigned int Millicode:1; /* 1 */ | |
9119 | unsigned int Millicode_save_sr0:1; /* 2 */ | |
9120 | unsigned int Region_description:2; /* 3..4 */ | |
9121 | unsigned int reserved1:1; /* 5 */ | |
9122 | unsigned int Entry_SR:1; /* 6 */ | |
9123 | unsigned int Entry_FR:4; /* Number saved 7..10 */ | |
9124 | unsigned int Entry_GR:5; /* Number saved 11..15 */ | |
9125 | unsigned int Args_stored:1; /* 16 */ | |
9126 | unsigned int Variable_Frame:1; /* 17 */ | |
9127 | unsigned int Separate_Package_Body:1; /* 18 */ | |
9128 | unsigned int Frame_Extension_Millicode:1; /* 19 */ | |
9129 | unsigned int Stack_Overflow_Check:1; /* 20 */ | |
9130 | unsigned int Two_Instruction_SP_Increment:1; /* 21 */ | |
9131 | unsigned int Ada_Region:1; /* 22 */ | |
9132 | unsigned int cxx_info:1; /* 23 */ | |
9133 | unsigned int cxx_try_catch:1; /* 24 */ | |
9134 | unsigned int sched_entry_seq:1; /* 25 */ | |
9135 | unsigned int reserved2:1; /* 26 */ | |
9136 | unsigned int Save_SP:1; /* 27 */ | |
9137 | unsigned int Save_RP:1; /* 28 */ | |
9138 | unsigned int Save_MRP_in_frame:1; /* 29 */ | |
9139 | unsigned int extn_ptr_defined:1; /* 30 */ | |
9140 | unsigned int Cleanup_defined:1; /* 31 */ | |
9141 | ||
9142 | unsigned int MPE_XL_interrupt_marker:1; /* 0 */ | |
9143 | unsigned int HP_UX_interrupt_marker:1; /* 1 */ | |
9144 | unsigned int Large_frame:1; /* 2 */ | |
9145 | unsigned int Pseudo_SP_Set:1; /* 3 */ | |
9146 | unsigned int reserved4:1; /* 4 */ | |
9147 | unsigned int Total_frame_size:27; /* 5..31 */ | |
9148 | }; | |
9149 | ||
9150 | struct hppa_unw_aux_info | |
9151 | { | |
9152 | struct hppa_unw_table_entry * table; /* Unwind table. */ | |
9153 | uint64_t table_len; /* Length of unwind table. */ | |
9154 | uint64_t seg_base; /* Starting address of segment. */ | |
9155 | Elf_Internal_Sym * symtab; /* The symbol table. */ | |
9156 | uint64_t nsyms; /* Number of symbols. */ | |
9157 | Elf_Internal_Sym * funtab; /* Sorted table of STT_FUNC symbols. */ | |
9158 | uint64_t nfuns; /* Number of entries in funtab. */ | |
9159 | char * strtab; /* The string table. */ | |
9160 | uint64_t strtab_size; /* Size of string table. */ | |
9161 | }; | |
9162 | ||
9163 | static bool | |
9164 | dump_hppa_unwind (Filedata * filedata, struct hppa_unw_aux_info * aux) | |
9165 | { | |
9166 | struct hppa_unw_table_entry * tp; | |
9167 | uint64_t j, nfuns; | |
9168 | bool res = true; | |
9169 | ||
9170 | aux->funtab = xmalloc (aux->nsyms * sizeof (Elf_Internal_Sym)); | |
9171 | for (nfuns = 0, j = 0; j < aux->nsyms; j++) | |
9172 | if (aux->symtab[j].st_value && ELF_ST_TYPE (aux->symtab[j].st_info) == STT_FUNC) | |
9173 | aux->funtab[nfuns++] = aux->symtab[j]; | |
9174 | aux->nfuns = nfuns; | |
9175 | qsort (aux->funtab, aux->nfuns, sizeof (Elf_Internal_Sym), symcmp); | |
9176 | ||
9177 | for (tp = aux->table; tp < aux->table + aux->table_len; ++tp) | |
9178 | { | |
9179 | uint64_t offset; | |
9180 | const char * procname; | |
9181 | ||
9182 | find_symbol_for_address (filedata, aux->funtab, aux->nfuns, aux->strtab, | |
9183 | aux->strtab_size, tp->start, &procname, | |
9184 | &offset); | |
9185 | ||
9186 | fputs ("\n<", stdout); | |
9187 | ||
9188 | if (procname) | |
9189 | { | |
9190 | fputs (procname, stdout); | |
9191 | ||
9192 | if (offset) | |
9193 | printf ("+%" PRIx64, offset); | |
9194 | } | |
9195 | ||
9196 | fputs (">: [", stdout); | |
9197 | print_vma (tp->start.offset, PREFIX_HEX); | |
9198 | fputc ('-', stdout); | |
9199 | print_vma (tp->end.offset, PREFIX_HEX); | |
9200 | printf ("]\n\t"); | |
9201 | ||
9202 | #define PF(_m) if (tp->_m) printf (#_m " "); | |
9203 | #define PV(_m) if (tp->_m) printf (#_m "=%d ", tp->_m); | |
9204 | PF(Cannot_unwind); | |
9205 | PF(Millicode); | |
9206 | PF(Millicode_save_sr0); | |
9207 | /* PV(Region_description); */ | |
9208 | PF(Entry_SR); | |
9209 | PV(Entry_FR); | |
9210 | PV(Entry_GR); | |
9211 | PF(Args_stored); | |
9212 | PF(Variable_Frame); | |
9213 | PF(Separate_Package_Body); | |
9214 | PF(Frame_Extension_Millicode); | |
9215 | PF(Stack_Overflow_Check); | |
9216 | PF(Two_Instruction_SP_Increment); | |
9217 | PF(Ada_Region); | |
9218 | PF(cxx_info); | |
9219 | PF(cxx_try_catch); | |
9220 | PF(sched_entry_seq); | |
9221 | PF(Save_SP); | |
9222 | PF(Save_RP); | |
9223 | PF(Save_MRP_in_frame); | |
9224 | PF(extn_ptr_defined); | |
9225 | PF(Cleanup_defined); | |
9226 | PF(MPE_XL_interrupt_marker); | |
9227 | PF(HP_UX_interrupt_marker); | |
9228 | PF(Large_frame); | |
9229 | PF(Pseudo_SP_Set); | |
9230 | PV(Total_frame_size); | |
9231 | #undef PF | |
9232 | #undef PV | |
9233 | } | |
9234 | ||
9235 | printf ("\n"); | |
9236 | ||
9237 | free (aux->funtab); | |
9238 | ||
9239 | return res; | |
9240 | } | |
9241 | ||
9242 | static bool | |
9243 | slurp_hppa_unwind_table (Filedata * filedata, | |
9244 | struct hppa_unw_aux_info * aux, | |
9245 | Elf_Internal_Shdr * sec) | |
9246 | { | |
9247 | uint64_t size, unw_ent_size, nentries, nrelas, i; | |
9248 | Elf_Internal_Phdr * seg; | |
9249 | struct hppa_unw_table_entry * tep; | |
9250 | Elf_Internal_Shdr * relsec; | |
9251 | Elf_Internal_Rela * rela; | |
9252 | Elf_Internal_Rela * rp; | |
9253 | unsigned char * table; | |
9254 | unsigned char * tp; | |
9255 | Elf_Internal_Sym * sym; | |
9256 | const char * relname; | |
9257 | ||
9258 | /* First, find the starting address of the segment that includes | |
9259 | this section. */ | |
9260 | if (filedata->file_header.e_phnum) | |
9261 | { | |
9262 | if (! get_program_headers (filedata)) | |
9263 | return false; | |
9264 | ||
9265 | for (seg = filedata->program_headers; | |
9266 | seg < filedata->program_headers + filedata->file_header.e_phnum; | |
9267 | ++seg) | |
9268 | { | |
9269 | if (seg->p_type != PT_LOAD) | |
9270 | continue; | |
9271 | ||
9272 | if (sec->sh_addr >= seg->p_vaddr | |
9273 | && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz)) | |
9274 | { | |
9275 | aux->seg_base = seg->p_vaddr; | |
9276 | break; | |
9277 | } | |
9278 | } | |
9279 | } | |
9280 | ||
9281 | /* Second, build the unwind table from the contents of the unwind | |
9282 | section. */ | |
9283 | size = sec->sh_size; | |
9284 | table = (unsigned char *) get_data (NULL, filedata, sec->sh_offset, 1, size, | |
9285 | _("unwind table")); | |
9286 | if (!table) | |
9287 | return false; | |
9288 | ||
9289 | unw_ent_size = 16; | |
9290 | nentries = size / unw_ent_size; | |
9291 | size = unw_ent_size * nentries; | |
9292 | ||
9293 | aux->table_len = nentries; | |
9294 | tep = aux->table = (struct hppa_unw_table_entry *) | |
9295 | xcmalloc (nentries, sizeof (aux->table[0])); | |
9296 | ||
9297 | for (tp = table; tp < table + size; tp += unw_ent_size, ++tep) | |
9298 | { | |
9299 | unsigned int tmp1, tmp2; | |
9300 | ||
9301 | tep->start.section = SHN_UNDEF; | |
9302 | tep->end.section = SHN_UNDEF; | |
9303 | ||
9304 | tep->start.offset = byte_get ((unsigned char *) tp + 0, 4); | |
9305 | tep->end.offset = byte_get ((unsigned char *) tp + 4, 4); | |
9306 | tmp1 = byte_get ((unsigned char *) tp + 8, 4); | |
9307 | tmp2 = byte_get ((unsigned char *) tp + 12, 4); | |
9308 | ||
9309 | tep->start.offset += aux->seg_base; | |
9310 | tep->end.offset += aux->seg_base; | |
9311 | ||
9312 | tep->Cannot_unwind = (tmp1 >> 31) & 0x1; | |
9313 | tep->Millicode = (tmp1 >> 30) & 0x1; | |
9314 | tep->Millicode_save_sr0 = (tmp1 >> 29) & 0x1; | |
9315 | tep->Region_description = (tmp1 >> 27) & 0x3; | |
9316 | tep->reserved1 = (tmp1 >> 26) & 0x1; | |
9317 | tep->Entry_SR = (tmp1 >> 25) & 0x1; | |
9318 | tep->Entry_FR = (tmp1 >> 21) & 0xf; | |
9319 | tep->Entry_GR = (tmp1 >> 16) & 0x1f; | |
9320 | tep->Args_stored = (tmp1 >> 15) & 0x1; | |
9321 | tep->Variable_Frame = (tmp1 >> 14) & 0x1; | |
9322 | tep->Separate_Package_Body = (tmp1 >> 13) & 0x1; | |
9323 | tep->Frame_Extension_Millicode = (tmp1 >> 12) & 0x1; | |
9324 | tep->Stack_Overflow_Check = (tmp1 >> 11) & 0x1; | |
9325 | tep->Two_Instruction_SP_Increment = (tmp1 >> 10) & 0x1; | |
9326 | tep->Ada_Region = (tmp1 >> 9) & 0x1; | |
9327 | tep->cxx_info = (tmp1 >> 8) & 0x1; | |
9328 | tep->cxx_try_catch = (tmp1 >> 7) & 0x1; | |
9329 | tep->sched_entry_seq = (tmp1 >> 6) & 0x1; | |
9330 | tep->reserved2 = (tmp1 >> 5) & 0x1; | |
9331 | tep->Save_SP = (tmp1 >> 4) & 0x1; | |
9332 | tep->Save_RP = (tmp1 >> 3) & 0x1; | |
9333 | tep->Save_MRP_in_frame = (tmp1 >> 2) & 0x1; | |
9334 | tep->extn_ptr_defined = (tmp1 >> 1) & 0x1; | |
9335 | tep->Cleanup_defined = tmp1 & 0x1; | |
9336 | ||
9337 | tep->MPE_XL_interrupt_marker = (tmp2 >> 31) & 0x1; | |
9338 | tep->HP_UX_interrupt_marker = (tmp2 >> 30) & 0x1; | |
9339 | tep->Large_frame = (tmp2 >> 29) & 0x1; | |
9340 | tep->Pseudo_SP_Set = (tmp2 >> 28) & 0x1; | |
9341 | tep->reserved4 = (tmp2 >> 27) & 0x1; | |
9342 | tep->Total_frame_size = tmp2 & 0x7ffffff; | |
9343 | } | |
9344 | free (table); | |
9345 | ||
9346 | /* Third, apply any relocations to the unwind table. */ | |
9347 | for (relsec = filedata->section_headers; | |
9348 | relsec < filedata->section_headers + filedata->file_header.e_shnum; | |
9349 | ++relsec) | |
9350 | { | |
9351 | if (relsec->sh_type != SHT_RELA | |
9352 | || relsec->sh_info >= filedata->file_header.e_shnum | |
9353 | || filedata->section_headers + relsec->sh_info != sec) | |
9354 | continue; | |
9355 | ||
9356 | if (!slurp_rela_relocs (filedata, relsec->sh_offset, relsec->sh_size, | |
9357 | & rela, & nrelas)) | |
9358 | return false; | |
9359 | ||
9360 | for (rp = rela; rp < rela + nrelas; ++rp) | |
9361 | { | |
9362 | unsigned int sym_ndx; | |
9363 | unsigned int r_type = get_reloc_type (filedata, rp->r_info); | |
9364 | relname = elf_hppa_reloc_type (r_type); | |
9365 | ||
9366 | if (relname == NULL) | |
9367 | { | |
9368 | warn (_("Skipping unknown relocation type: %u\n"), r_type); | |
9369 | continue; | |
9370 | } | |
9371 | ||
9372 | /* R_PARISC_SEGREL32 or R_PARISC_SEGREL64. */ | |
9373 | if (! startswith (relname, "R_PARISC_SEGREL")) | |
9374 | { | |
9375 | warn (_("Skipping unexpected relocation type: %s\n"), relname); | |
9376 | continue; | |
9377 | } | |
9378 | ||
9379 | i = rp->r_offset / unw_ent_size; | |
9380 | if (i >= aux->table_len) | |
9381 | { | |
9382 | warn (_("Skipping reloc with overlarge offset: %#" PRIx64 "\n"), | |
9383 | i); | |
9384 | continue; | |
9385 | } | |
9386 | ||
9387 | sym_ndx = get_reloc_symindex (rp->r_info); | |
9388 | if (sym_ndx >= aux->nsyms) | |
9389 | { | |
9390 | warn (_("Skipping reloc with invalid symbol index: %u\n"), | |
9391 | sym_ndx); | |
9392 | continue; | |
9393 | } | |
9394 | sym = aux->symtab + sym_ndx; | |
9395 | ||
9396 | switch ((rp->r_offset % unw_ent_size) / 4) | |
9397 | { | |
9398 | case 0: | |
9399 | aux->table[i].start.section = sym->st_shndx; | |
9400 | aux->table[i].start.offset = sym->st_value + rp->r_addend; | |
9401 | break; | |
9402 | case 1: | |
9403 | aux->table[i].end.section = sym->st_shndx; | |
9404 | aux->table[i].end.offset = sym->st_value + rp->r_addend; | |
9405 | break; | |
9406 | default: | |
9407 | break; | |
9408 | } | |
9409 | } | |
9410 | ||
9411 | free (rela); | |
9412 | } | |
9413 | ||
9414 | return true; | |
9415 | } | |
9416 | ||
9417 | static bool | |
9418 | hppa_process_unwind (Filedata * filedata) | |
9419 | { | |
9420 | struct hppa_unw_aux_info aux; | |
9421 | Elf_Internal_Shdr * unwsec = NULL; | |
9422 | Elf_Internal_Shdr * sec; | |
9423 | size_t i; | |
9424 | bool res = true; | |
9425 | ||
9426 | if (filedata->string_table == NULL) | |
9427 | return false; | |
9428 | ||
9429 | memset (& aux, 0, sizeof (aux)); | |
9430 | ||
9431 | for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec) | |
9432 | { | |
9433 | if (sec->sh_type == SHT_SYMTAB) | |
9434 | { | |
9435 | if (aux.symtab) | |
9436 | { | |
9437 | error (_("Multiple symbol tables encountered\n")); | |
9438 | free (aux.symtab); | |
9439 | aux.symtab = NULL; | |
9440 | free (aux.strtab); | |
9441 | aux.strtab = NULL; | |
9442 | } | |
9443 | if (!get_symtab (filedata, sec, &aux.symtab, &aux.nsyms, | |
9444 | &aux.strtab, &aux.strtab_size)) | |
9445 | return false; | |
9446 | } | |
9447 | else if (section_name_valid (filedata, sec) | |
9448 | && streq (section_name (filedata, sec), ".PARISC.unwind")) | |
9449 | unwsec = sec; | |
9450 | } | |
9451 | ||
9452 | if (!unwsec) | |
9453 | printf (_("\nThere are no unwind sections in this file.\n")); | |
9454 | ||
9455 | for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec) | |
9456 | { | |
9457 | if (section_name_valid (filedata, sec) | |
9458 | && streq (section_name (filedata, sec), ".PARISC.unwind")) | |
9459 | { | |
9460 | uint64_t num_unwind = sec->sh_size / 16; | |
9461 | ||
9462 | printf (ngettext ("\nUnwind section '%s' at offset %#" PRIx64 " " | |
9463 | "contains %" PRIu64 " entry:\n", | |
9464 | "\nUnwind section '%s' at offset %#" PRIx64 " " | |
9465 | "contains %" PRIu64 " entries:\n", | |
9466 | num_unwind), | |
9467 | printable_section_name (filedata, sec), | |
9468 | sec->sh_offset, | |
9469 | num_unwind); | |
9470 | ||
9471 | if (! slurp_hppa_unwind_table (filedata, &aux, sec)) | |
9472 | res = false; | |
9473 | ||
9474 | if (res && aux.table_len > 0) | |
9475 | { | |
9476 | if (! dump_hppa_unwind (filedata, &aux)) | |
9477 | res = false; | |
9478 | } | |
9479 | ||
9480 | free ((char *) aux.table); | |
9481 | aux.table = NULL; | |
9482 | } | |
9483 | } | |
9484 | ||
9485 | free (aux.symtab); | |
9486 | free ((char *) aux.strtab); | |
9487 | ||
9488 | return res; | |
9489 | } | |
9490 | ||
9491 | struct arm_section | |
9492 | { | |
9493 | unsigned char * data; /* The unwind data. */ | |
9494 | Elf_Internal_Shdr * sec; /* The cached unwind section header. */ | |
9495 | Elf_Internal_Rela * rela; /* The cached relocations for this section. */ | |
9496 | uint64_t nrelas; /* The number of relocations. */ | |
9497 | unsigned int rel_type; /* REL or RELA ? */ | |
9498 | Elf_Internal_Rela * next_rela; /* Cyclic pointer to the next reloc to process. */ | |
9499 | }; | |
9500 | ||
9501 | struct arm_unw_aux_info | |
9502 | { | |
9503 | Filedata * filedata; /* The file containing the unwind sections. */ | |
9504 | Elf_Internal_Sym * symtab; /* The file's symbol table. */ | |
9505 | uint64_t nsyms; /* Number of symbols. */ | |
9506 | Elf_Internal_Sym * funtab; /* Sorted table of STT_FUNC symbols. */ | |
9507 | uint64_t nfuns; /* Number of these symbols. */ | |
9508 | char * strtab; /* The file's string table. */ | |
9509 | uint64_t strtab_size; /* Size of string table. */ | |
9510 | }; | |
9511 | ||
9512 | static const char * | |
9513 | arm_print_vma_and_name (Filedata * filedata, | |
9514 | struct arm_unw_aux_info * aux, | |
9515 | uint64_t fn, | |
9516 | struct absaddr addr) | |
9517 | { | |
9518 | const char *procname; | |
9519 | uint64_t sym_offset; | |
9520 | ||
9521 | if (addr.section == SHN_UNDEF) | |
9522 | addr.offset = fn; | |
9523 | ||
9524 | find_symbol_for_address (filedata, aux->funtab, aux->nfuns, aux->strtab, | |
9525 | aux->strtab_size, addr, &procname, | |
9526 | &sym_offset); | |
9527 | ||
9528 | print_vma (fn, PREFIX_HEX); | |
9529 | ||
9530 | if (procname) | |
9531 | { | |
9532 | fputs (" <", stdout); | |
9533 | fputs (procname, stdout); | |
9534 | ||
9535 | if (sym_offset) | |
9536 | printf ("+0x%" PRIx64, sym_offset); | |
9537 | fputc ('>', stdout); | |
9538 | } | |
9539 | ||
9540 | return procname; | |
9541 | } | |
9542 | ||
9543 | static void | |
9544 | arm_free_section (struct arm_section *arm_sec) | |
9545 | { | |
9546 | free (arm_sec->data); | |
9547 | free (arm_sec->rela); | |
9548 | } | |
9549 | ||
9550 | /* 1) If SEC does not match the one cached in ARM_SEC, then free the current | |
9551 | cached section and install SEC instead. | |
9552 | 2) Locate the 32-bit word at WORD_OFFSET in unwind section SEC | |
9553 | and return its valued in * WORDP, relocating if necessary. | |
9554 | 3) Update the NEXT_RELA field in ARM_SEC and store the section index and | |
9555 | relocation's offset in ADDR. | |
9556 | 4) If SYM_NAME is non-NULL and a relocation was applied, record the offset | |
9557 | into the string table of the symbol associated with the reloc. If no | |
9558 | reloc was applied store -1 there. | |
9559 | 5) Return TRUE upon success, FALSE otherwise. */ | |
9560 | ||
9561 | static bool | |
9562 | get_unwind_section_word (Filedata * filedata, | |
9563 | struct arm_unw_aux_info * aux, | |
9564 | struct arm_section * arm_sec, | |
9565 | Elf_Internal_Shdr * sec, | |
9566 | uint64_t word_offset, | |
9567 | unsigned int * wordp, | |
9568 | struct absaddr * addr, | |
9569 | uint64_t * sym_name) | |
9570 | { | |
9571 | Elf_Internal_Rela *rp; | |
9572 | Elf_Internal_Sym *sym; | |
9573 | const char * relname; | |
9574 | unsigned int word; | |
9575 | bool wrapped; | |
9576 | ||
9577 | if (sec == NULL || arm_sec == NULL) | |
9578 | return false; | |
9579 | ||
9580 | addr->section = SHN_UNDEF; | |
9581 | addr->offset = 0; | |
9582 | ||
9583 | if (sym_name != NULL) | |
9584 | *sym_name = (uint64_t) -1; | |
9585 | ||
9586 | /* If necessary, update the section cache. */ | |
9587 | if (sec != arm_sec->sec) | |
9588 | { | |
9589 | Elf_Internal_Shdr *relsec; | |
9590 | ||
9591 | arm_free_section (arm_sec); | |
9592 | ||
9593 | arm_sec->sec = sec; | |
9594 | arm_sec->data = get_data (NULL, aux->filedata, sec->sh_offset, 1, | |
9595 | sec->sh_size, _("unwind data")); | |
9596 | arm_sec->rela = NULL; | |
9597 | arm_sec->nrelas = 0; | |
9598 | ||
9599 | for (relsec = filedata->section_headers; | |
9600 | relsec < filedata->section_headers + filedata->file_header.e_shnum; | |
9601 | ++relsec) | |
9602 | { | |
9603 | if (relsec->sh_info >= filedata->file_header.e_shnum | |
9604 | || filedata->section_headers + relsec->sh_info != sec | |
9605 | /* PR 15745: Check the section type as well. */ | |
9606 | || (relsec->sh_type != SHT_REL | |
9607 | && relsec->sh_type != SHT_RELA)) | |
9608 | continue; | |
9609 | ||
9610 | arm_sec->rel_type = relsec->sh_type; | |
9611 | if (relsec->sh_type == SHT_REL) | |
9612 | { | |
9613 | if (!slurp_rel_relocs (aux->filedata, relsec->sh_offset, | |
9614 | relsec->sh_size, | |
9615 | & arm_sec->rela, & arm_sec->nrelas)) | |
9616 | return false; | |
9617 | } | |
9618 | else /* relsec->sh_type == SHT_RELA */ | |
9619 | { | |
9620 | if (!slurp_rela_relocs (aux->filedata, relsec->sh_offset, | |
9621 | relsec->sh_size, | |
9622 | & arm_sec->rela, & arm_sec->nrelas)) | |
9623 | return false; | |
9624 | } | |
9625 | break; | |
9626 | } | |
9627 | ||
9628 | arm_sec->next_rela = arm_sec->rela; | |
9629 | } | |
9630 | ||
9631 | /* If there is no unwind data we can do nothing. */ | |
9632 | if (arm_sec->data == NULL) | |
9633 | return false; | |
9634 | ||
9635 | /* If the offset is invalid then fail. */ | |
9636 | if (/* PR 21343 *//* PR 18879 */ | |
9637 | sec->sh_size < 4 | |
9638 | || word_offset > sec->sh_size - 4) | |
9639 | return false; | |
9640 | ||
9641 | /* Get the word at the required offset. */ | |
9642 | word = byte_get (arm_sec->data + word_offset, 4); | |
9643 | ||
9644 | /* PR 17531: file: id:000001,src:001266+003044,op:splice,rep:128. */ | |
9645 | if (arm_sec->rela == NULL) | |
9646 | { | |
9647 | * wordp = word; | |
9648 | return true; | |
9649 | } | |
9650 | ||
9651 | /* Look through the relocs to find the one that applies to the provided offset. */ | |
9652 | wrapped = false; | |
9653 | for (rp = arm_sec->next_rela; rp != arm_sec->rela + arm_sec->nrelas; rp++) | |
9654 | { | |
9655 | uint64_t prelval, offset; | |
9656 | ||
9657 | if (rp->r_offset > word_offset && !wrapped) | |
9658 | { | |
9659 | rp = arm_sec->rela; | |
9660 | wrapped = true; | |
9661 | } | |
9662 | if (rp->r_offset > word_offset) | |
9663 | break; | |
9664 | ||
9665 | if (rp->r_offset & 3) | |
9666 | { | |
9667 | warn (_("Skipping unexpected relocation at offset %#" PRIx64 "\n"), | |
9668 | rp->r_offset); | |
9669 | continue; | |
9670 | } | |
9671 | ||
9672 | if (rp->r_offset < word_offset) | |
9673 | continue; | |
9674 | ||
9675 | /* PR 17531: file: 027-161405-0.004 */ | |
9676 | if (aux->symtab == NULL) | |
9677 | continue; | |
9678 | ||
9679 | if (arm_sec->rel_type == SHT_REL) | |
9680 | { | |
9681 | offset = word & 0x7fffffff; | |
9682 | if (offset & 0x40000000) | |
9683 | offset |= ~ (uint64_t) 0x7fffffff; | |
9684 | } | |
9685 | else if (arm_sec->rel_type == SHT_RELA) | |
9686 | offset = rp->r_addend; | |
9687 | else | |
9688 | { | |
9689 | error (_("Unknown section relocation type %d encountered\n"), | |
9690 | arm_sec->rel_type); | |
9691 | break; | |
9692 | } | |
9693 | ||
9694 | /* PR 17531 file: 027-1241568-0.004. */ | |
9695 | if (ELF32_R_SYM (rp->r_info) >= aux->nsyms) | |
9696 | { | |
9697 | error (_("Bad symbol index in unwind relocation " | |
9698 | "(%" PRIu64 " > %" PRIu64 ")\n"), | |
9699 | ELF32_R_SYM (rp->r_info), aux->nsyms); | |
9700 | break; | |
9701 | } | |
9702 | ||
9703 | sym = aux->symtab + ELF32_R_SYM (rp->r_info); | |
9704 | offset += sym->st_value; | |
9705 | prelval = offset - (arm_sec->sec->sh_addr + rp->r_offset); | |
9706 | ||
9707 | /* Check that we are processing the expected reloc type. */ | |
9708 | if (filedata->file_header.e_machine == EM_ARM) | |
9709 | { | |
9710 | relname = elf_arm_reloc_type (ELF32_R_TYPE (rp->r_info)); | |
9711 | if (relname == NULL) | |
9712 | { | |
9713 | warn (_("Skipping unknown ARM relocation type: %d\n"), | |
9714 | (int) ELF32_R_TYPE (rp->r_info)); | |
9715 | continue; | |
9716 | } | |
9717 | ||
9718 | if (streq (relname, "R_ARM_NONE")) | |
9719 | continue; | |
9720 | ||
9721 | if (! streq (relname, "R_ARM_PREL31")) | |
9722 | { | |
9723 | warn (_("Skipping unexpected ARM relocation type %s\n"), relname); | |
9724 | continue; | |
9725 | } | |
9726 | } | |
9727 | else if (filedata->file_header.e_machine == EM_TI_C6000) | |
9728 | { | |
9729 | relname = elf_tic6x_reloc_type (ELF32_R_TYPE (rp->r_info)); | |
9730 | if (relname == NULL) | |
9731 | { | |
9732 | warn (_("Skipping unknown C6000 relocation type: %d\n"), | |
9733 | (int) ELF32_R_TYPE (rp->r_info)); | |
9734 | continue; | |
9735 | } | |
9736 | ||
9737 | if (streq (relname, "R_C6000_NONE")) | |
9738 | continue; | |
9739 | ||
9740 | if (! streq (relname, "R_C6000_PREL31")) | |
9741 | { | |
9742 | warn (_("Skipping unexpected C6000 relocation type %s\n"), relname); | |
9743 | continue; | |
9744 | } | |
9745 | ||
9746 | prelval >>= 1; | |
9747 | } | |
9748 | else | |
9749 | { | |
9750 | /* This function currently only supports ARM and TI unwinders. */ | |
9751 | warn (_("Only TI and ARM unwinders are currently supported\n")); | |
9752 | break; | |
9753 | } | |
9754 | ||
9755 | word = (word & ~ (uint64_t) 0x7fffffff) | (prelval & 0x7fffffff); | |
9756 | addr->section = sym->st_shndx; | |
9757 | addr->offset = offset; | |
9758 | ||
9759 | if (sym_name) | |
9760 | * sym_name = sym->st_name; | |
9761 | break; | |
9762 | } | |
9763 | ||
9764 | *wordp = word; | |
9765 | arm_sec->next_rela = rp; | |
9766 | ||
9767 | return true; | |
9768 | } | |
9769 | ||
9770 | static const char *tic6x_unwind_regnames[16] = | |
9771 | { | |
9772 | "A15", "B15", "B14", "B13", "B12", "B11", "B10", "B3", | |
9773 | "A14", "A13", "A12", "A11", "A10", | |
9774 | "[invalid reg 13]", "[invalid reg 14]", "[invalid reg 15]" | |
9775 | }; | |
9776 | ||
9777 | static void | |
9778 | decode_tic6x_unwind_regmask (unsigned int mask) | |
9779 | { | |
9780 | int i; | |
9781 | ||
9782 | for (i = 12; mask; mask >>= 1, i--) | |
9783 | { | |
9784 | if (mask & 1) | |
9785 | { | |
9786 | fputs (tic6x_unwind_regnames[i], stdout); | |
9787 | if (mask > 1) | |
9788 | fputs (", ", stdout); | |
9789 | } | |
9790 | } | |
9791 | } | |
9792 | ||
9793 | #define ADVANCE \ | |
9794 | if (remaining == 0 && more_words) \ | |
9795 | { \ | |
9796 | data_offset += 4; \ | |
9797 | if (! get_unwind_section_word (filedata, aux, data_arm_sec, data_sec, \ | |
9798 | data_offset, & word, & addr, NULL)) \ | |
9799 | return false; \ | |
9800 | remaining = 4; \ | |
9801 | more_words--; \ | |
9802 | } \ | |
9803 | ||
9804 | #define GET_OP(OP) \ | |
9805 | ADVANCE; \ | |
9806 | if (remaining) \ | |
9807 | { \ | |
9808 | remaining--; \ | |
9809 | (OP) = word >> 24; \ | |
9810 | word <<= 8; \ | |
9811 | } \ | |
9812 | else \ | |
9813 | { \ | |
9814 | printf (_("[Truncated opcode]\n")); \ | |
9815 | return false; \ | |
9816 | } \ | |
9817 | printf ("0x%02x ", OP) | |
9818 | ||
9819 | static bool | |
9820 | decode_arm_unwind_bytecode (Filedata * filedata, | |
9821 | struct arm_unw_aux_info * aux, | |
9822 | unsigned int word, | |
9823 | unsigned int remaining, | |
9824 | unsigned int more_words, | |
9825 | uint64_t data_offset, | |
9826 | Elf_Internal_Shdr * data_sec, | |
9827 | struct arm_section * data_arm_sec) | |
9828 | { | |
9829 | struct absaddr addr; | |
9830 | bool res = true; | |
9831 | ||
9832 | /* Decode the unwinding instructions. */ | |
9833 | while (1) | |
9834 | { | |
9835 | unsigned int op, op2; | |
9836 | ||
9837 | ADVANCE; | |
9838 | if (remaining == 0) | |
9839 | break; | |
9840 | remaining--; | |
9841 | op = word >> 24; | |
9842 | word <<= 8; | |
9843 | ||
9844 | printf (" 0x%02x ", op); | |
9845 | ||
9846 | if ((op & 0xc0) == 0x00) | |
9847 | { | |
9848 | int offset = ((op & 0x3f) << 2) + 4; | |
9849 | ||
9850 | printf (" vsp = vsp + %d", offset); | |
9851 | } | |
9852 | else if ((op & 0xc0) == 0x40) | |
9853 | { | |
9854 | int offset = ((op & 0x3f) << 2) + 4; | |
9855 | ||
9856 | printf (" vsp = vsp - %d", offset); | |
9857 | } | |
9858 | else if ((op & 0xf0) == 0x80) | |
9859 | { | |
9860 | GET_OP (op2); | |
9861 | if (op == 0x80 && op2 == 0) | |
9862 | printf (_("Refuse to unwind")); | |
9863 | else | |
9864 | { | |
9865 | unsigned int mask = ((op & 0x0f) << 8) | op2; | |
9866 | bool first = true; | |
9867 | int i; | |
9868 | ||
9869 | printf ("pop {"); | |
9870 | for (i = 0; i < 12; i++) | |
9871 | if (mask & (1 << i)) | |
9872 | { | |
9873 | if (first) | |
9874 | first = false; | |
9875 | else | |
9876 | printf (", "); | |
9877 | printf ("r%d", 4 + i); | |
9878 | } | |
9879 | printf ("}"); | |
9880 | } | |
9881 | } | |
9882 | else if ((op & 0xf0) == 0x90) | |
9883 | { | |
9884 | if (op == 0x9d || op == 0x9f) | |
9885 | printf (_(" [Reserved]")); | |
9886 | else | |
9887 | printf (" vsp = r%d", op & 0x0f); | |
9888 | } | |
9889 | else if ((op & 0xf0) == 0xa0) | |
9890 | { | |
9891 | int end = 4 + (op & 0x07); | |
9892 | bool first = true; | |
9893 | int i; | |
9894 | ||
9895 | printf (" pop {"); | |
9896 | for (i = 4; i <= end; i++) | |
9897 | { | |
9898 | if (first) | |
9899 | first = false; | |
9900 | else | |
9901 | printf (", "); | |
9902 | printf ("r%d", i); | |
9903 | } | |
9904 | if (op & 0x08) | |
9905 | { | |
9906 | if (!first) | |
9907 | printf (", "); | |
9908 | printf ("r14"); | |
9909 | } | |
9910 | printf ("}"); | |
9911 | } | |
9912 | else if (op == 0xb0) | |
9913 | printf (_(" finish")); | |
9914 | else if (op == 0xb1) | |
9915 | { | |
9916 | GET_OP (op2); | |
9917 | if (op2 == 0 || (op2 & 0xf0) != 0) | |
9918 | printf (_("[Spare]")); | |
9919 | else | |
9920 | { | |
9921 | unsigned int mask = op2 & 0x0f; | |
9922 | bool first = true; | |
9923 | int i; | |
9924 | ||
9925 | printf ("pop {"); | |
9926 | for (i = 0; i < 12; i++) | |
9927 | if (mask & (1 << i)) | |
9928 | { | |
9929 | if (first) | |
9930 | first = false; | |
9931 | else | |
9932 | printf (", "); | |
9933 | printf ("r%d", i); | |
9934 | } | |
9935 | printf ("}"); | |
9936 | } | |
9937 | } | |
9938 | else if (op == 0xb2) | |
9939 | { | |
9940 | unsigned char buf[9]; | |
9941 | unsigned int i, len; | |
9942 | uint64_t offset; | |
9943 | ||
9944 | for (i = 0; i < sizeof (buf); i++) | |
9945 | { | |
9946 | GET_OP (buf[i]); | |
9947 | if ((buf[i] & 0x80) == 0) | |
9948 | break; | |
9949 | } | |
9950 | if (i == sizeof (buf)) | |
9951 | { | |
9952 | error (_("corrupt change to vsp\n")); | |
9953 | res = false; | |
9954 | } | |
9955 | else | |
9956 | { | |
9957 | offset = read_leb128 (buf, buf + i + 1, false, &len, NULL); | |
9958 | assert (len == i + 1); | |
9959 | offset = offset * 4 + 0x204; | |
9960 | printf ("vsp = vsp + %" PRId64, offset); | |
9961 | } | |
9962 | } | |
9963 | else if (op == 0xb3 || op == 0xc8 || op == 0xc9) | |
9964 | { | |
9965 | unsigned int first, last; | |
9966 | ||
9967 | GET_OP (op2); | |
9968 | first = op2 >> 4; | |
9969 | last = op2 & 0x0f; | |
9970 | if (op == 0xc8) | |
9971 | first = first + 16; | |
9972 | printf ("pop {D%d", first); | |
9973 | if (last) | |
9974 | printf ("-D%d", first + last); | |
9975 | printf ("}"); | |
9976 | } | |
9977 | else if (op == 0xb4) | |
9978 | printf (_(" pop {ra_auth_code}")); | |
9979 | else if (op == 0xb5) | |
9980 | printf (_(" vsp as modifier for PAC validation")); | |
9981 | else if ((op & 0xf8) == 0xb8 || (op & 0xf8) == 0xd0) | |
9982 | { | |
9983 | unsigned int count = op & 0x07; | |
9984 | ||
9985 | printf ("pop {D8"); | |
9986 | if (count) | |
9987 | printf ("-D%d", 8 + count); | |
9988 | printf ("}"); | |
9989 | } | |
9990 | else if (op >= 0xc0 && op <= 0xc5) | |
9991 | { | |
9992 | unsigned int count = op & 0x07; | |
9993 | ||
9994 | printf (" pop {wR10"); | |
9995 | if (count) | |
9996 | printf ("-wR%d", 10 + count); | |
9997 | printf ("}"); | |
9998 | } | |
9999 | else if (op == 0xc6) | |
10000 | { | |
10001 | unsigned int first, last; | |
10002 | ||
10003 | GET_OP (op2); | |
10004 | first = op2 >> 4; | |
10005 | last = op2 & 0x0f; | |
10006 | printf ("pop {wR%d", first); | |
10007 | if (last) | |
10008 | printf ("-wR%d", first + last); | |
10009 | printf ("}"); | |
10010 | } | |
10011 | else if (op == 0xc7) | |
10012 | { | |
10013 | GET_OP (op2); | |
10014 | if (op2 == 0 || (op2 & 0xf0) != 0) | |
10015 | printf (_("[Spare]")); | |
10016 | else | |
10017 | { | |
10018 | unsigned int mask = op2 & 0x0f; | |
10019 | bool first = true; | |
10020 | int i; | |
10021 | ||
10022 | printf ("pop {"); | |
10023 | for (i = 0; i < 4; i++) | |
10024 | if (mask & (1 << i)) | |
10025 | { | |
10026 | if (first) | |
10027 | first = false; | |
10028 | else | |
10029 | printf (", "); | |
10030 | printf ("wCGR%d", i); | |
10031 | } | |
10032 | printf ("}"); | |
10033 | } | |
10034 | } | |
10035 | else | |
10036 | { | |
10037 | printf (_(" [unsupported opcode]")); | |
10038 | res = false; | |
10039 | } | |
10040 | ||
10041 | printf ("\n"); | |
10042 | } | |
10043 | ||
10044 | return res; | |
10045 | } | |
10046 | ||
10047 | static bool | |
10048 | decode_tic6x_unwind_bytecode (Filedata * filedata, | |
10049 | struct arm_unw_aux_info * aux, | |
10050 | unsigned int word, | |
10051 | unsigned int remaining, | |
10052 | unsigned int more_words, | |
10053 | uint64_t data_offset, | |
10054 | Elf_Internal_Shdr * data_sec, | |
10055 | struct arm_section * data_arm_sec) | |
10056 | { | |
10057 | struct absaddr addr; | |
10058 | ||
10059 | /* Decode the unwinding instructions. */ | |
10060 | while (1) | |
10061 | { | |
10062 | unsigned int op, op2; | |
10063 | ||
10064 | ADVANCE; | |
10065 | if (remaining == 0) | |
10066 | break; | |
10067 | remaining--; | |
10068 | op = word >> 24; | |
10069 | word <<= 8; | |
10070 | ||
10071 | printf (" 0x%02x ", op); | |
10072 | ||
10073 | if ((op & 0xc0) == 0x00) | |
10074 | { | |
10075 | int offset = ((op & 0x3f) << 3) + 8; | |
10076 | printf (" sp = sp + %d", offset); | |
10077 | } | |
10078 | else if ((op & 0xc0) == 0x80) | |
10079 | { | |
10080 | GET_OP (op2); | |
10081 | if (op == 0x80 && op2 == 0) | |
10082 | printf (_("Refuse to unwind")); | |
10083 | else | |
10084 | { | |
10085 | unsigned int mask = ((op & 0x1f) << 8) | op2; | |
10086 | if (op & 0x20) | |
10087 | printf ("pop compact {"); | |
10088 | else | |
10089 | printf ("pop {"); | |
10090 | ||
10091 | decode_tic6x_unwind_regmask (mask); | |
10092 | printf("}"); | |
10093 | } | |
10094 | } | |
10095 | else if ((op & 0xf0) == 0xc0) | |
10096 | { | |
10097 | unsigned int reg; | |
10098 | unsigned int nregs; | |
10099 | unsigned int i; | |
10100 | const char *name; | |
10101 | struct | |
10102 | { | |
10103 | unsigned int offset; | |
10104 | unsigned int reg; | |
10105 | } regpos[16]; | |
10106 | ||
10107 | /* Scan entire instruction first so that GET_OP output is not | |
10108 | interleaved with disassembly. */ | |
10109 | nregs = 0; | |
10110 | for (i = 0; nregs < (op & 0xf); i++) | |
10111 | { | |
10112 | GET_OP (op2); | |
10113 | reg = op2 >> 4; | |
10114 | if (reg != 0xf) | |
10115 | { | |
10116 | regpos[nregs].offset = i * 2; | |
10117 | regpos[nregs].reg = reg; | |
10118 | nregs++; | |
10119 | } | |
10120 | ||
10121 | reg = op2 & 0xf; | |
10122 | if (reg != 0xf) | |
10123 | { | |
10124 | regpos[nregs].offset = i * 2 + 1; | |
10125 | regpos[nregs].reg = reg; | |
10126 | nregs++; | |
10127 | } | |
10128 | } | |
10129 | ||
10130 | printf (_("pop frame {")); | |
10131 | if (nregs == 0) | |
10132 | { | |
10133 | printf (_("*corrupt* - no registers specified")); | |
10134 | } | |
10135 | else | |
10136 | { | |
10137 | reg = nregs - 1; | |
10138 | for (i = i * 2; i > 0; i--) | |
10139 | { | |
10140 | if (regpos[reg].offset == i - 1) | |
10141 | { | |
10142 | name = tic6x_unwind_regnames[regpos[reg].reg]; | |
10143 | if (reg > 0) | |
10144 | reg--; | |
10145 | } | |
10146 | else | |
10147 | name = _("[pad]"); | |
10148 | ||
10149 | fputs (name, stdout); | |
10150 | if (i > 1) | |
10151 | printf (", "); | |
10152 | } | |
10153 | } | |
10154 | ||
10155 | printf ("}"); | |
10156 | } | |
10157 | else if (op == 0xd0) | |
10158 | printf (" MOV FP, SP"); | |
10159 | else if (op == 0xd1) | |
10160 | printf (" __c6xabi_pop_rts"); | |
10161 | else if (op == 0xd2) | |
10162 | { | |
10163 | unsigned char buf[9]; | |
10164 | unsigned int i, len; | |
10165 | uint64_t offset; | |
10166 | ||
10167 | for (i = 0; i < sizeof (buf); i++) | |
10168 | { | |
10169 | GET_OP (buf[i]); | |
10170 | if ((buf[i] & 0x80) == 0) | |
10171 | break; | |
10172 | } | |
10173 | /* PR 17531: file: id:000001,src:001906+004739,op:splice,rep:2. */ | |
10174 | if (i == sizeof (buf)) | |
10175 | { | |
10176 | warn (_("Corrupt stack pointer adjustment detected\n")); | |
10177 | return false; | |
10178 | } | |
10179 | ||
10180 | offset = read_leb128 (buf, buf + i + 1, false, &len, NULL); | |
10181 | assert (len == i + 1); | |
10182 | offset = offset * 8 + 0x408; | |
10183 | printf (_("sp = sp + %" PRId64), offset); | |
10184 | } | |
10185 | else if ((op & 0xf0) == 0xe0) | |
10186 | { | |
10187 | if ((op & 0x0f) == 7) | |
10188 | printf (" RETURN"); | |
10189 | else | |
10190 | printf (" MV %s, B3", tic6x_unwind_regnames[op & 0x0f]); | |
10191 | } | |
10192 | else | |
10193 | { | |
10194 | printf (_(" [unsupported opcode]")); | |
10195 | } | |
10196 | putchar ('\n'); | |
10197 | } | |
10198 | ||
10199 | return true; | |
10200 | } | |
10201 | ||
10202 | static uint64_t | |
10203 | arm_expand_prel31 (Filedata * filedata, uint64_t word, uint64_t where) | |
10204 | { | |
10205 | uint64_t offset; | |
10206 | ||
10207 | offset = word & 0x7fffffff; | |
10208 | if (offset & 0x40000000) | |
10209 | offset |= ~ (uint64_t) 0x7fffffff; | |
10210 | ||
10211 | if (filedata->file_header.e_machine == EM_TI_C6000) | |
10212 | offset <<= 1; | |
10213 | ||
10214 | return offset + where; | |
10215 | } | |
10216 | ||
10217 | static bool | |
10218 | decode_arm_unwind (Filedata * filedata, | |
10219 | struct arm_unw_aux_info * aux, | |
10220 | unsigned int word, | |
10221 | unsigned int remaining, | |
10222 | uint64_t data_offset, | |
10223 | Elf_Internal_Shdr * data_sec, | |
10224 | struct arm_section * data_arm_sec) | |
10225 | { | |
10226 | int per_index; | |
10227 | unsigned int more_words = 0; | |
10228 | struct absaddr addr; | |
10229 | uint64_t sym_name = (uint64_t) -1; | |
10230 | bool res = true; | |
10231 | ||
10232 | if (remaining == 0) | |
10233 | { | |
10234 | /* Fetch the first word. | |
10235 | Note - when decoding an object file the address extracted | |
10236 | here will always be 0. So we also pass in the sym_name | |
10237 | parameter so that we can find the symbol associated with | |
10238 | the personality routine. */ | |
10239 | if (! get_unwind_section_word (filedata, aux, data_arm_sec, data_sec, data_offset, | |
10240 | & word, & addr, & sym_name)) | |
10241 | return false; | |
10242 | ||
10243 | remaining = 4; | |
10244 | } | |
10245 | else | |
10246 | { | |
10247 | addr.section = SHN_UNDEF; | |
10248 | addr.offset = 0; | |
10249 | } | |
10250 | ||
10251 | if ((word & 0x80000000) == 0) | |
10252 | { | |
10253 | /* Expand prel31 for personality routine. */ | |
10254 | uint64_t fn; | |
10255 | const char *procname; | |
10256 | ||
10257 | fn = arm_expand_prel31 (filedata, word, data_sec->sh_addr + data_offset); | |
10258 | printf (_(" Personality routine: ")); | |
10259 | if (fn == 0 | |
10260 | && addr.section == SHN_UNDEF && addr.offset == 0 | |
10261 | && sym_name != (uint64_t) -1 && sym_name < aux->strtab_size) | |
10262 | { | |
10263 | procname = aux->strtab + sym_name; | |
10264 | print_vma (fn, PREFIX_HEX); | |
10265 | if (procname) | |
10266 | { | |
10267 | fputs (" <", stdout); | |
10268 | fputs (procname, stdout); | |
10269 | fputc ('>', stdout); | |
10270 | } | |
10271 | } | |
10272 | else | |
10273 | procname = arm_print_vma_and_name (filedata, aux, fn, addr); | |
10274 | fputc ('\n', stdout); | |
10275 | ||
10276 | /* The GCC personality routines use the standard compact | |
10277 | encoding, starting with one byte giving the number of | |
10278 | words. */ | |
10279 | if (procname != NULL | |
10280 | && (startswith (procname, "__gcc_personality_v0") | |
10281 | || startswith (procname, "__gxx_personality_v0") | |
10282 | || startswith (procname, "__gcj_personality_v0") | |
10283 | || startswith (procname, "__gnu_objc_personality_v0"))) | |
10284 | { | |
10285 | remaining = 0; | |
10286 | more_words = 1; | |
10287 | ADVANCE; | |
10288 | if (!remaining) | |
10289 | { | |
10290 | printf (_(" [Truncated data]\n")); | |
10291 | return false; | |
10292 | } | |
10293 | more_words = word >> 24; | |
10294 | word <<= 8; | |
10295 | remaining--; | |
10296 | per_index = -1; | |
10297 | } | |
10298 | else | |
10299 | return true; | |
10300 | } | |
10301 | else | |
10302 | { | |
10303 | /* ARM EHABI Section 6.3: | |
10304 | ||
10305 | An exception-handling table entry for the compact model looks like: | |
10306 | ||
10307 | 31 30-28 27-24 23-0 | |
10308 | -- ----- ----- ---- | |
10309 | 1 0 index Data for personalityRoutine[index] */ | |
10310 | ||
10311 | if (filedata->file_header.e_machine == EM_ARM | |
10312 | && (word & 0x70000000)) | |
10313 | { | |
10314 | warn (_("Corrupt ARM compact model table entry: %x \n"), word); | |
10315 | res = false; | |
10316 | } | |
10317 | ||
10318 | per_index = (word >> 24) & 0x7f; | |
10319 | printf (_(" Compact model index: %d\n"), per_index); | |
10320 | if (per_index == 0) | |
10321 | { | |
10322 | more_words = 0; | |
10323 | word <<= 8; | |
10324 | remaining--; | |
10325 | } | |
10326 | else if (per_index < 3) | |
10327 | { | |
10328 | more_words = (word >> 16) & 0xff; | |
10329 | word <<= 16; | |
10330 | remaining -= 2; | |
10331 | } | |
10332 | } | |
10333 | ||
10334 | switch (filedata->file_header.e_machine) | |
10335 | { | |
10336 | case EM_ARM: | |
10337 | if (per_index < 3) | |
10338 | { | |
10339 | if (! decode_arm_unwind_bytecode (filedata, aux, word, remaining, more_words, | |
10340 | data_offset, data_sec, data_arm_sec)) | |
10341 | res = false; | |
10342 | } | |
10343 | else | |
10344 | { | |
10345 | warn (_("Unknown ARM compact model index encountered\n")); | |
10346 | printf (_(" [reserved]\n")); | |
10347 | res = false; | |
10348 | } | |
10349 | break; | |
10350 | ||
10351 | case EM_TI_C6000: | |
10352 | if (per_index < 3) | |
10353 | { | |
10354 | if (! decode_tic6x_unwind_bytecode (filedata, aux, word, remaining, more_words, | |
10355 | data_offset, data_sec, data_arm_sec)) | |
10356 | res = false; | |
10357 | } | |
10358 | else if (per_index < 5) | |
10359 | { | |
10360 | if (((word >> 17) & 0x7f) == 0x7f) | |
10361 | printf (_(" Restore stack from frame pointer\n")); | |
10362 | else | |
10363 | printf (_(" Stack increment %d\n"), (word >> 14) & 0x1fc); | |
10364 | printf (_(" Registers restored: ")); | |
10365 | if (per_index == 4) | |
10366 | printf (" (compact) "); | |
10367 | decode_tic6x_unwind_regmask ((word >> 4) & 0x1fff); | |
10368 | putchar ('\n'); | |
10369 | printf (_(" Return register: %s\n"), | |
10370 | tic6x_unwind_regnames[word & 0xf]); | |
10371 | } | |
10372 | else | |
10373 | printf (_(" [reserved (%d)]\n"), per_index); | |
10374 | break; | |
10375 | ||
10376 | default: | |
10377 | error (_("Unsupported architecture type %d encountered when decoding unwind table\n"), | |
10378 | filedata->file_header.e_machine); | |
10379 | res = false; | |
10380 | } | |
10381 | ||
10382 | /* Decode the descriptors. Not implemented. */ | |
10383 | ||
10384 | return res; | |
10385 | } | |
10386 | ||
10387 | static bool | |
10388 | dump_arm_unwind (Filedata * filedata, | |
10389 | struct arm_unw_aux_info * aux, | |
10390 | Elf_Internal_Shdr * exidx_sec) | |
10391 | { | |
10392 | struct arm_section exidx_arm_sec, extab_arm_sec; | |
10393 | unsigned int i, exidx_len; | |
10394 | uint64_t j, nfuns; | |
10395 | bool res = true; | |
10396 | ||
10397 | memset (&exidx_arm_sec, 0, sizeof (exidx_arm_sec)); | |
10398 | memset (&extab_arm_sec, 0, sizeof (extab_arm_sec)); | |
10399 | exidx_len = exidx_sec->sh_size / 8; | |
10400 | ||
10401 | aux->funtab = xmalloc (aux->nsyms * sizeof (Elf_Internal_Sym)); | |
10402 | for (nfuns = 0, j = 0; j < aux->nsyms; j++) | |
10403 | if (aux->symtab[j].st_value && ELF_ST_TYPE (aux->symtab[j].st_info) == STT_FUNC) | |
10404 | aux->funtab[nfuns++] = aux->symtab[j]; | |
10405 | aux->nfuns = nfuns; | |
10406 | qsort (aux->funtab, aux->nfuns, sizeof (Elf_Internal_Sym), symcmp); | |
10407 | ||
10408 | for (i = 0; i < exidx_len; i++) | |
10409 | { | |
10410 | unsigned int exidx_fn, exidx_entry; | |
10411 | struct absaddr fn_addr, entry_addr; | |
10412 | uint64_t fn; | |
10413 | ||
10414 | fputc ('\n', stdout); | |
10415 | ||
10416 | if (! get_unwind_section_word (filedata, aux, & exidx_arm_sec, exidx_sec, | |
10417 | 8 * i, & exidx_fn, & fn_addr, NULL) | |
10418 | || ! get_unwind_section_word (filedata, aux, & exidx_arm_sec, exidx_sec, | |
10419 | 8 * i + 4, & exidx_entry, & entry_addr, NULL)) | |
10420 | { | |
10421 | free (aux->funtab); | |
10422 | arm_free_section (& exidx_arm_sec); | |
10423 | arm_free_section (& extab_arm_sec); | |
10424 | return false; | |
10425 | } | |
10426 | ||
10427 | /* ARM EHABI, Section 5: | |
10428 | An index table entry consists of 2 words. | |
10429 | The first word contains a prel31 offset to the start of a function, with bit 31 clear. */ | |
10430 | if (exidx_fn & 0x80000000) | |
10431 | { | |
10432 | warn (_("corrupt index table entry: %x\n"), exidx_fn); | |
10433 | res = false; | |
10434 | } | |
10435 | ||
10436 | fn = arm_expand_prel31 (filedata, exidx_fn, exidx_sec->sh_addr + 8 * i); | |
10437 | ||
10438 | arm_print_vma_and_name (filedata, aux, fn, fn_addr); | |
10439 | fputs (": ", stdout); | |
10440 | ||
10441 | if (exidx_entry == 1) | |
10442 | { | |
10443 | print_vma (exidx_entry, PREFIX_HEX); | |
10444 | fputs (" [cantunwind]\n", stdout); | |
10445 | } | |
10446 | else if (exidx_entry & 0x80000000) | |
10447 | { | |
10448 | print_vma (exidx_entry, PREFIX_HEX); | |
10449 | fputc ('\n', stdout); | |
10450 | decode_arm_unwind (filedata, aux, exidx_entry, 4, 0, NULL, NULL); | |
10451 | } | |
10452 | else | |
10453 | { | |
10454 | uint64_t table, table_offset = 0; | |
10455 | Elf_Internal_Shdr *table_sec; | |
10456 | ||
10457 | fputs ("@", stdout); | |
10458 | table = arm_expand_prel31 (filedata, exidx_entry, exidx_sec->sh_addr + 8 * i + 4); | |
10459 | print_vma (table, PREFIX_HEX); | |
10460 | printf ("\n"); | |
10461 | ||
10462 | /* Locate the matching .ARM.extab. */ | |
10463 | if (entry_addr.section != SHN_UNDEF | |
10464 | && entry_addr.section < filedata->file_header.e_shnum) | |
10465 | { | |
10466 | table_sec = filedata->section_headers + entry_addr.section; | |
10467 | table_offset = entry_addr.offset; | |
10468 | /* PR 18879 */ | |
10469 | if (table_offset > table_sec->sh_size) | |
10470 | { | |
10471 | warn (_("Unwind entry contains corrupt offset (%#" PRIx64 ") into section %s\n"), | |
10472 | table_offset, | |
10473 | printable_section_name (filedata, table_sec)); | |
10474 | res = false; | |
10475 | continue; | |
10476 | } | |
10477 | } | |
10478 | else | |
10479 | { | |
10480 | table_sec = find_section_by_address (filedata, table); | |
10481 | if (table_sec != NULL) | |
10482 | table_offset = table - table_sec->sh_addr; | |
10483 | } | |
10484 | ||
10485 | if (table_sec == NULL) | |
10486 | { | |
10487 | warn (_("Could not locate .ARM.extab section containing %#" PRIx64 ".\n"), | |
10488 | table); | |
10489 | res = false; | |
10490 | continue; | |
10491 | } | |
10492 | ||
10493 | if (! decode_arm_unwind (filedata, aux, 0, 0, table_offset, table_sec, | |
10494 | &extab_arm_sec)) | |
10495 | res = false; | |
10496 | } | |
10497 | } | |
10498 | ||
10499 | printf ("\n"); | |
10500 | ||
10501 | free (aux->funtab); | |
10502 | arm_free_section (&exidx_arm_sec); | |
10503 | arm_free_section (&extab_arm_sec); | |
10504 | ||
10505 | return res; | |
10506 | } | |
10507 | ||
10508 | /* Used for both ARM and C6X unwinding tables. */ | |
10509 | ||
10510 | static bool | |
10511 | arm_process_unwind (Filedata * filedata) | |
10512 | { | |
10513 | struct arm_unw_aux_info aux; | |
10514 | Elf_Internal_Shdr *unwsec = NULL; | |
10515 | Elf_Internal_Shdr *sec; | |
10516 | size_t i; | |
10517 | unsigned int sec_type; | |
10518 | bool res = true; | |
10519 | ||
10520 | switch (filedata->file_header.e_machine) | |
10521 | { | |
10522 | case EM_ARM: | |
10523 | sec_type = SHT_ARM_EXIDX; | |
10524 | break; | |
10525 | ||
10526 | case EM_TI_C6000: | |
10527 | sec_type = SHT_C6000_UNWIND; | |
10528 | break; | |
10529 | ||
10530 | default: | |
10531 | error (_("Unsupported architecture type %d encountered when processing unwind table\n"), | |
10532 | filedata->file_header.e_machine); | |
10533 | return false; | |
10534 | } | |
10535 | ||
10536 | if (filedata->string_table == NULL) | |
10537 | return false; | |
10538 | ||
10539 | memset (& aux, 0, sizeof (aux)); | |
10540 | aux.filedata = filedata; | |
10541 | ||
10542 | for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec) | |
10543 | { | |
10544 | if (sec->sh_type == SHT_SYMTAB) | |
10545 | { | |
10546 | if (aux.symtab) | |
10547 | { | |
10548 | error (_("Multiple symbol tables encountered\n")); | |
10549 | free (aux.symtab); | |
10550 | aux.symtab = NULL; | |
10551 | free (aux.strtab); | |
10552 | aux.strtab = NULL; | |
10553 | } | |
10554 | if (!get_symtab (filedata, sec, &aux.symtab, &aux.nsyms, | |
10555 | &aux.strtab, &aux.strtab_size)) | |
10556 | return false; | |
10557 | } | |
10558 | else if (sec->sh_type == sec_type) | |
10559 | unwsec = sec; | |
10560 | } | |
10561 | ||
10562 | if (unwsec == NULL) | |
10563 | printf (_("\nThere are no unwind sections in this file.\n")); | |
10564 | else | |
10565 | for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec) | |
10566 | { | |
10567 | if (sec->sh_type == sec_type) | |
10568 | { | |
10569 | uint64_t num_unwind = sec->sh_size / (2 * eh_addr_size); | |
10570 | printf (ngettext ("\nUnwind section '%s' at offset %#" PRIx64 " " | |
10571 | "contains %" PRIu64 " entry:\n", | |
10572 | "\nUnwind section '%s' at offset %#" PRIx64 " " | |
10573 | "contains %" PRIu64 " entries:\n", | |
10574 | num_unwind), | |
10575 | printable_section_name (filedata, sec), | |
10576 | sec->sh_offset, | |
10577 | num_unwind); | |
10578 | ||
10579 | if (! dump_arm_unwind (filedata, &aux, sec)) | |
10580 | res = false; | |
10581 | } | |
10582 | } | |
10583 | ||
10584 | free (aux.symtab); | |
10585 | free ((char *) aux.strtab); | |
10586 | ||
10587 | return res; | |
10588 | } | |
10589 | ||
10590 | static bool | |
10591 | no_processor_specific_unwind (Filedata * filedata ATTRIBUTE_UNUSED) | |
10592 | { | |
10593 | printf (_("No processor specific unwind information to decode\n")); | |
10594 | return true; | |
10595 | } | |
10596 | ||
10597 | static bool | |
10598 | process_unwind (Filedata * filedata) | |
10599 | { | |
10600 | struct unwind_handler | |
10601 | { | |
10602 | unsigned int machtype; | |
10603 | bool (* handler)(Filedata *); | |
10604 | } handlers[] = | |
10605 | { | |
10606 | { EM_ARM, arm_process_unwind }, | |
10607 | { EM_IA_64, ia64_process_unwind }, | |
10608 | { EM_PARISC, hppa_process_unwind }, | |
10609 | { EM_TI_C6000, arm_process_unwind }, | |
10610 | { EM_386, no_processor_specific_unwind }, | |
10611 | { EM_X86_64, no_processor_specific_unwind }, | |
10612 | { 0, NULL } | |
10613 | }; | |
10614 | int i; | |
10615 | ||
10616 | if (!do_unwind) | |
10617 | return true; | |
10618 | ||
10619 | for (i = 0; handlers[i].handler != NULL; i++) | |
10620 | if (filedata->file_header.e_machine == handlers[i].machtype) | |
10621 | return handlers[i].handler (filedata); | |
10622 | ||
10623 | printf (_("\nThe decoding of unwind sections for machine type %s is not currently supported.\n"), | |
10624 | get_machine_name (filedata->file_header.e_machine)); | |
10625 | return true; | |
10626 | } | |
10627 | ||
10628 | static void | |
10629 | dynamic_section_aarch64_val (Elf_Internal_Dyn * entry) | |
10630 | { | |
10631 | switch (entry->d_tag) | |
10632 | { | |
10633 | case DT_AARCH64_BTI_PLT: | |
10634 | case DT_AARCH64_PAC_PLT: | |
10635 | break; | |
10636 | default: | |
10637 | print_vma (entry->d_un.d_ptr, PREFIX_HEX); | |
10638 | break; | |
10639 | } | |
10640 | putchar ('\n'); | |
10641 | } | |
10642 | ||
10643 | static void | |
10644 | dynamic_section_mips_val (Filedata * filedata, Elf_Internal_Dyn * entry) | |
10645 | { | |
10646 | switch (entry->d_tag) | |
10647 | { | |
10648 | case DT_MIPS_FLAGS: | |
10649 | if (entry->d_un.d_val == 0) | |
10650 | printf (_("NONE")); | |
10651 | else | |
10652 | { | |
10653 | static const char * opts[] = | |
10654 | { | |
10655 | "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT", | |
10656 | "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS", | |
10657 | "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD", | |
10658 | "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF", | |
10659 | "RLD_ORDER_SAFE" | |
10660 | }; | |
10661 | unsigned int cnt; | |
10662 | bool first = true; | |
10663 | ||
10664 | for (cnt = 0; cnt < ARRAY_SIZE (opts); ++cnt) | |
10665 | if (entry->d_un.d_val & (1 << cnt)) | |
10666 | { | |
10667 | printf ("%s%s", first ? "" : " ", opts[cnt]); | |
10668 | first = false; | |
10669 | } | |
10670 | } | |
10671 | break; | |
10672 | ||
10673 | case DT_MIPS_IVERSION: | |
10674 | if (valid_dynamic_name (filedata, entry->d_un.d_val)) | |
10675 | printf (_("Interface Version: %s"), | |
10676 | get_dynamic_name (filedata, entry->d_un.d_val)); | |
10677 | else | |
10678 | printf (_("Interface Version: <corrupt: %" PRIx64 ">"), | |
10679 | entry->d_un.d_ptr); | |
10680 | break; | |
10681 | ||
10682 | case DT_MIPS_TIME_STAMP: | |
10683 | { | |
10684 | char timebuf[128]; | |
10685 | struct tm * tmp; | |
10686 | time_t atime = entry->d_un.d_val; | |
10687 | ||
10688 | tmp = gmtime (&atime); | |
10689 | /* PR 17531: file: 6accc532. */ | |
10690 | if (tmp == NULL) | |
10691 | snprintf (timebuf, sizeof (timebuf), _("<corrupt>")); | |
10692 | else | |
10693 | snprintf (timebuf, sizeof (timebuf), "%04u-%02u-%02uT%02u:%02u:%02u", | |
10694 | tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday, | |
10695 | tmp->tm_hour, tmp->tm_min, tmp->tm_sec); | |
10696 | printf (_("Time Stamp: %s"), timebuf); | |
10697 | } | |
10698 | break; | |
10699 | ||
10700 | case DT_MIPS_RLD_VERSION: | |
10701 | case DT_MIPS_LOCAL_GOTNO: | |
10702 | case DT_MIPS_CONFLICTNO: | |
10703 | case DT_MIPS_LIBLISTNO: | |
10704 | case DT_MIPS_SYMTABNO: | |
10705 | case DT_MIPS_UNREFEXTNO: | |
10706 | case DT_MIPS_HIPAGENO: | |
10707 | case DT_MIPS_DELTA_CLASS_NO: | |
10708 | case DT_MIPS_DELTA_INSTANCE_NO: | |
10709 | case DT_MIPS_DELTA_RELOC_NO: | |
10710 | case DT_MIPS_DELTA_SYM_NO: | |
10711 | case DT_MIPS_DELTA_CLASSSYM_NO: | |
10712 | case DT_MIPS_COMPACT_SIZE: | |
10713 | print_vma (entry->d_un.d_val, DEC); | |
10714 | break; | |
10715 | ||
10716 | case DT_MIPS_XHASH: | |
10717 | filedata->dynamic_info_DT_MIPS_XHASH = entry->d_un.d_val; | |
10718 | filedata->dynamic_info_DT_GNU_HASH = entry->d_un.d_val; | |
10719 | /* Falls through. */ | |
10720 | ||
10721 | default: | |
10722 | print_vma (entry->d_un.d_ptr, PREFIX_HEX); | |
10723 | } | |
10724 | putchar ('\n'); | |
10725 | } | |
10726 | ||
10727 | static void | |
10728 | dynamic_section_parisc_val (Elf_Internal_Dyn * entry) | |
10729 | { | |
10730 | switch (entry->d_tag) | |
10731 | { | |
10732 | case DT_HP_DLD_FLAGS: | |
10733 | { | |
10734 | static struct | |
10735 | { | |
10736 | unsigned int bit; | |
10737 | const char * str; | |
10738 | } | |
10739 | flags[] = | |
10740 | { | |
10741 | { DT_HP_DEBUG_PRIVATE, "HP_DEBUG_PRIVATE" }, | |
10742 | { DT_HP_DEBUG_CALLBACK, "HP_DEBUG_CALLBACK" }, | |
10743 | { DT_HP_DEBUG_CALLBACK_BOR, "HP_DEBUG_CALLBACK_BOR" }, | |
10744 | { DT_HP_NO_ENVVAR, "HP_NO_ENVVAR" }, | |
10745 | { DT_HP_BIND_NOW, "HP_BIND_NOW" }, | |
10746 | { DT_HP_BIND_NONFATAL, "HP_BIND_NONFATAL" }, | |
10747 | { DT_HP_BIND_VERBOSE, "HP_BIND_VERBOSE" }, | |
10748 | { DT_HP_BIND_RESTRICTED, "HP_BIND_RESTRICTED" }, | |
10749 | { DT_HP_BIND_SYMBOLIC, "HP_BIND_SYMBOLIC" }, | |
10750 | { DT_HP_RPATH_FIRST, "HP_RPATH_FIRST" }, | |
10751 | { DT_HP_BIND_DEPTH_FIRST, "HP_BIND_DEPTH_FIRST" }, | |
10752 | { DT_HP_GST, "HP_GST" }, | |
10753 | { DT_HP_SHLIB_FIXED, "HP_SHLIB_FIXED" }, | |
10754 | { DT_HP_MERGE_SHLIB_SEG, "HP_MERGE_SHLIB_SEG" }, | |
10755 | { DT_HP_NODELETE, "HP_NODELETE" }, | |
10756 | { DT_HP_GROUP, "HP_GROUP" }, | |
10757 | { DT_HP_PROTECT_LINKAGE_TABLE, "HP_PROTECT_LINKAGE_TABLE" } | |
10758 | }; | |
10759 | bool first = true; | |
10760 | size_t cnt; | |
10761 | uint64_t val = entry->d_un.d_val; | |
10762 | ||
10763 | for (cnt = 0; cnt < ARRAY_SIZE (flags); ++cnt) | |
10764 | if (val & flags[cnt].bit) | |
10765 | { | |
10766 | if (! first) | |
10767 | putchar (' '); | |
10768 | fputs (flags[cnt].str, stdout); | |
10769 | first = false; | |
10770 | val ^= flags[cnt].bit; | |
10771 | } | |
10772 | ||
10773 | if (val != 0 || first) | |
10774 | { | |
10775 | if (! first) | |
10776 | putchar (' '); | |
10777 | print_vma (val, HEX); | |
10778 | } | |
10779 | } | |
10780 | break; | |
10781 | ||
10782 | default: | |
10783 | print_vma (entry->d_un.d_ptr, PREFIX_HEX); | |
10784 | break; | |
10785 | } | |
10786 | putchar ('\n'); | |
10787 | } | |
10788 | ||
10789 | /* VMS vs Unix time offset and factor. */ | |
10790 | ||
10791 | #define VMS_EPOCH_OFFSET 35067168000000000LL | |
10792 | #define VMS_GRANULARITY_FACTOR 10000000 | |
10793 | #ifndef INT64_MIN | |
10794 | #define INT64_MIN (-9223372036854775807LL - 1) | |
10795 | #endif | |
10796 | ||
10797 | /* Display a VMS time in a human readable format. */ | |
10798 | ||
10799 | static void | |
10800 | print_vms_time (int64_t vmstime) | |
10801 | { | |
10802 | struct tm *tm = NULL; | |
10803 | time_t unxtime; | |
10804 | ||
10805 | if (vmstime >= INT64_MIN + VMS_EPOCH_OFFSET) | |
10806 | { | |
10807 | vmstime = (vmstime - VMS_EPOCH_OFFSET) / VMS_GRANULARITY_FACTOR; | |
10808 | unxtime = vmstime; | |
10809 | if (unxtime == vmstime) | |
10810 | tm = gmtime (&unxtime); | |
10811 | } | |
10812 | if (tm != NULL) | |
10813 | printf ("%04u-%02u-%02uT%02u:%02u:%02u", | |
10814 | tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, | |
10815 | tm->tm_hour, tm->tm_min, tm->tm_sec); | |
10816 | } | |
10817 | ||
10818 | static void | |
10819 | dynamic_section_ia64_val (Elf_Internal_Dyn * entry) | |
10820 | { | |
10821 | switch (entry->d_tag) | |
10822 | { | |
10823 | case DT_IA_64_PLT_RESERVE: | |
10824 | /* First 3 slots reserved. */ | |
10825 | print_vma (entry->d_un.d_ptr, PREFIX_HEX); | |
10826 | printf (" -- "); | |
10827 | print_vma (entry->d_un.d_ptr + (3 * 8), PREFIX_HEX); | |
10828 | break; | |
10829 | ||
10830 | case DT_IA_64_VMS_LINKTIME: | |
10831 | print_vms_time (entry->d_un.d_val); | |
10832 | break; | |
10833 | ||
10834 | case DT_IA_64_VMS_LNKFLAGS: | |
10835 | print_vma (entry->d_un.d_ptr, PREFIX_HEX); | |
10836 | if (entry->d_un.d_val & VMS_LF_CALL_DEBUG) | |
10837 | printf (" CALL_DEBUG"); | |
10838 | if (entry->d_un.d_val & VMS_LF_NOP0BUFS) | |
10839 | printf (" NOP0BUFS"); | |
10840 | if (entry->d_un.d_val & VMS_LF_P0IMAGE) | |
10841 | printf (" P0IMAGE"); | |
10842 | if (entry->d_un.d_val & VMS_LF_MKTHREADS) | |
10843 | printf (" MKTHREADS"); | |
10844 | if (entry->d_un.d_val & VMS_LF_UPCALLS) | |
10845 | printf (" UPCALLS"); | |
10846 | if (entry->d_un.d_val & VMS_LF_IMGSTA) | |
10847 | printf (" IMGSTA"); | |
10848 | if (entry->d_un.d_val & VMS_LF_INITIALIZE) | |
10849 | printf (" INITIALIZE"); | |
10850 | if (entry->d_un.d_val & VMS_LF_MAIN) | |
10851 | printf (" MAIN"); | |
10852 | if (entry->d_un.d_val & VMS_LF_EXE_INIT) | |
10853 | printf (" EXE_INIT"); | |
10854 | if (entry->d_un.d_val & VMS_LF_TBK_IN_IMG) | |
10855 | printf (" TBK_IN_IMG"); | |
10856 | if (entry->d_un.d_val & VMS_LF_DBG_IN_IMG) | |
10857 | printf (" DBG_IN_IMG"); | |
10858 | if (entry->d_un.d_val & VMS_LF_TBK_IN_DSF) | |
10859 | printf (" TBK_IN_DSF"); | |
10860 | if (entry->d_un.d_val & VMS_LF_DBG_IN_DSF) | |
10861 | printf (" DBG_IN_DSF"); | |
10862 | if (entry->d_un.d_val & VMS_LF_SIGNATURES) | |
10863 | printf (" SIGNATURES"); | |
10864 | if (entry->d_un.d_val & VMS_LF_REL_SEG_OFF) | |
10865 | printf (" REL_SEG_OFF"); | |
10866 | break; | |
10867 | ||
10868 | default: | |
10869 | print_vma (entry->d_un.d_ptr, PREFIX_HEX); | |
10870 | break; | |
10871 | } | |
10872 | putchar ('\n'); | |
10873 | } | |
10874 | ||
10875 | static bool | |
10876 | get_32bit_dynamic_section (Filedata * filedata) | |
10877 | { | |
10878 | Elf32_External_Dyn * edyn; | |
10879 | Elf32_External_Dyn * ext; | |
10880 | Elf_Internal_Dyn * entry; | |
10881 | ||
10882 | edyn = (Elf32_External_Dyn *) get_data (NULL, filedata, | |
10883 | filedata->dynamic_addr, 1, | |
10884 | filedata->dynamic_size, | |
10885 | _("dynamic section")); | |
10886 | if (!edyn) | |
10887 | return false; | |
10888 | ||
10889 | /* SGI's ELF has more than one section in the DYNAMIC segment, and we | |
10890 | might not have the luxury of section headers. Look for the DT_NULL | |
10891 | terminator to determine the number of entries. */ | |
10892 | for (ext = edyn, filedata->dynamic_nent = 0; | |
10893 | (char *) (ext + 1) <= (char *) edyn + filedata->dynamic_size; | |
10894 | ext++) | |
10895 | { | |
10896 | filedata->dynamic_nent++; | |
10897 | if (BYTE_GET (ext->d_tag) == DT_NULL) | |
10898 | break; | |
10899 | } | |
10900 | ||
10901 | filedata->dynamic_section | |
10902 | = (Elf_Internal_Dyn *) cmalloc (filedata->dynamic_nent, sizeof (* entry)); | |
10903 | if (filedata->dynamic_section == NULL) | |
10904 | { | |
10905 | error (_("Out of memory allocating space for %" PRIu64 " dynamic entries\n"), | |
10906 | filedata->dynamic_nent); | |
10907 | free (edyn); | |
10908 | return false; | |
10909 | } | |
10910 | ||
10911 | for (ext = edyn, entry = filedata->dynamic_section; | |
10912 | entry < filedata->dynamic_section + filedata->dynamic_nent; | |
10913 | ext++, entry++) | |
10914 | { | |
10915 | entry->d_tag = BYTE_GET (ext->d_tag); | |
10916 | entry->d_un.d_val = BYTE_GET (ext->d_un.d_val); | |
10917 | } | |
10918 | ||
10919 | free (edyn); | |
10920 | ||
10921 | return true; | |
10922 | } | |
10923 | ||
10924 | static bool | |
10925 | get_64bit_dynamic_section (Filedata * filedata) | |
10926 | { | |
10927 | Elf64_External_Dyn * edyn; | |
10928 | Elf64_External_Dyn * ext; | |
10929 | Elf_Internal_Dyn * entry; | |
10930 | ||
10931 | /* Read in the data. */ | |
10932 | edyn = (Elf64_External_Dyn *) get_data (NULL, filedata, | |
10933 | filedata->dynamic_addr, 1, | |
10934 | filedata->dynamic_size, | |
10935 | _("dynamic section")); | |
10936 | if (!edyn) | |
10937 | return false; | |
10938 | ||
10939 | /* SGI's ELF has more than one section in the DYNAMIC segment, and we | |
10940 | might not have the luxury of section headers. Look for the DT_NULL | |
10941 | terminator to determine the number of entries. */ | |
10942 | for (ext = edyn, filedata->dynamic_nent = 0; | |
10943 | /* PR 17533 file: 033-67080-0.004 - do not read past end of buffer. */ | |
10944 | (char *) (ext + 1) <= (char *) edyn + filedata->dynamic_size; | |
10945 | ext++) | |
10946 | { | |
10947 | filedata->dynamic_nent++; | |
10948 | if (BYTE_GET (ext->d_tag) == DT_NULL) | |
10949 | break; | |
10950 | } | |
10951 | ||
10952 | filedata->dynamic_section | |
10953 | = (Elf_Internal_Dyn *) cmalloc (filedata->dynamic_nent, sizeof (* entry)); | |
10954 | if (filedata->dynamic_section == NULL) | |
10955 | { | |
10956 | error (_("Out of memory allocating space for %" PRIu64 " dynamic entries\n"), | |
10957 | filedata->dynamic_nent); | |
10958 | free (edyn); | |
10959 | return false; | |
10960 | } | |
10961 | ||
10962 | /* Convert from external to internal formats. */ | |
10963 | for (ext = edyn, entry = filedata->dynamic_section; | |
10964 | entry < filedata->dynamic_section + filedata->dynamic_nent; | |
10965 | ext++, entry++) | |
10966 | { | |
10967 | entry->d_tag = BYTE_GET (ext->d_tag); | |
10968 | entry->d_un.d_val = BYTE_GET (ext->d_un.d_val); | |
10969 | } | |
10970 | ||
10971 | free (edyn); | |
10972 | ||
10973 | return true; | |
10974 | } | |
10975 | ||
10976 | static bool | |
10977 | get_dynamic_section (Filedata *filedata) | |
10978 | { | |
10979 | if (filedata->dynamic_section) | |
10980 | return true; | |
10981 | ||
10982 | if (is_32bit_elf) | |
10983 | return get_32bit_dynamic_section (filedata); | |
10984 | else | |
10985 | return get_64bit_dynamic_section (filedata); | |
10986 | } | |
10987 | ||
10988 | static void | |
10989 | print_dynamic_flags (uint64_t flags) | |
10990 | { | |
10991 | bool first = true; | |
10992 | ||
10993 | while (flags) | |
10994 | { | |
10995 | uint64_t flag; | |
10996 | ||
10997 | flag = flags & - flags; | |
10998 | flags &= ~ flag; | |
10999 | ||
11000 | if (first) | |
11001 | first = false; | |
11002 | else | |
11003 | putc (' ', stdout); | |
11004 | ||
11005 | switch (flag) | |
11006 | { | |
11007 | case DF_ORIGIN: fputs ("ORIGIN", stdout); break; | |
11008 | case DF_SYMBOLIC: fputs ("SYMBOLIC", stdout); break; | |
11009 | case DF_TEXTREL: fputs ("TEXTREL", stdout); break; | |
11010 | case DF_BIND_NOW: fputs ("BIND_NOW", stdout); break; | |
11011 | case DF_STATIC_TLS: fputs ("STATIC_TLS", stdout); break; | |
11012 | default: fputs (_("unknown"), stdout); break; | |
11013 | } | |
11014 | } | |
11015 | puts (""); | |
11016 | } | |
11017 | ||
11018 | static uint64_t * | |
11019 | get_dynamic_data (Filedata * filedata, uint64_t number, unsigned int ent_size) | |
11020 | { | |
11021 | unsigned char * e_data; | |
11022 | uint64_t * i_data; | |
11023 | ||
11024 | /* If size_t is smaller than uint64_t, eg because you are building | |
11025 | on a 32-bit host, then make sure that when number is cast to | |
11026 | size_t no information is lost. */ | |
11027 | if ((size_t) number != number | |
11028 | || ent_size * number / ent_size != number) | |
11029 | { | |
11030 | error (_("Size overflow prevents reading %" PRIu64 | |
11031 | " elements of size %u\n"), | |
11032 | number, ent_size); | |
11033 | return NULL; | |
11034 | } | |
11035 | ||
11036 | /* Be kind to memory checkers (eg valgrind, address sanitizer) by not | |
11037 | attempting to allocate memory when the read is bound to fail. */ | |
11038 | if (ent_size * number > filedata->file_size) | |
11039 | { | |
11040 | error (_("Invalid number of dynamic entries: %" PRIu64 "\n"), | |
11041 | number); | |
11042 | return NULL; | |
11043 | } | |
11044 | ||
11045 | e_data = (unsigned char *) cmalloc ((size_t) number, ent_size); | |
11046 | if (e_data == NULL) | |
11047 | { | |
11048 | error (_("Out of memory reading %" PRIu64 " dynamic entries\n"), | |
11049 | number); | |
11050 | return NULL; | |
11051 | } | |
11052 | ||
11053 | if (fread (e_data, ent_size, (size_t) number, filedata->handle) != number) | |
11054 | { | |
11055 | error (_("Unable to read in %" PRIu64 " bytes of dynamic data\n"), | |
11056 | number * ent_size); | |
11057 | free (e_data); | |
11058 | return NULL; | |
11059 | } | |
11060 | ||
11061 | i_data = (uint64_t *) cmalloc ((size_t) number, sizeof (*i_data)); | |
11062 | if (i_data == NULL) | |
11063 | { | |
11064 | error (_("Out of memory allocating space for %" PRIu64 " dynamic entries\n"), | |
11065 | number); | |
11066 | free (e_data); | |
11067 | return NULL; | |
11068 | } | |
11069 | ||
11070 | while (number--) | |
11071 | i_data[number] = byte_get (e_data + number * ent_size, ent_size); | |
11072 | ||
11073 | free (e_data); | |
11074 | ||
11075 | return i_data; | |
11076 | } | |
11077 | ||
11078 | static uint64_t | |
11079 | get_num_dynamic_syms (Filedata * filedata) | |
11080 | { | |
11081 | uint64_t num_of_syms = 0; | |
11082 | ||
11083 | if (!do_histogram && (!do_using_dynamic || do_dyn_syms)) | |
11084 | return num_of_syms; | |
11085 | ||
11086 | if (filedata->dynamic_info[DT_HASH]) | |
11087 | { | |
11088 | unsigned char nb[8]; | |
11089 | unsigned char nc[8]; | |
11090 | unsigned int hash_ent_size = 4; | |
11091 | ||
11092 | if ((filedata->file_header.e_machine == EM_ALPHA | |
11093 | || filedata->file_header.e_machine == EM_S390 | |
11094 | || filedata->file_header.e_machine == EM_S390_OLD) | |
11095 | && filedata->file_header.e_ident[EI_CLASS] == ELFCLASS64) | |
11096 | hash_ent_size = 8; | |
11097 | ||
11098 | if (fseek64 (filedata->handle, | |
11099 | (filedata->archive_file_offset | |
11100 | + offset_from_vma (filedata, | |
11101 | filedata->dynamic_info[DT_HASH], | |
11102 | sizeof nb + sizeof nc)), | |
11103 | SEEK_SET)) | |
11104 | { | |
11105 | error (_("Unable to seek to start of dynamic information\n")); | |
11106 | goto no_hash; | |
11107 | } | |
11108 | ||
11109 | if (fread (nb, hash_ent_size, 1, filedata->handle) != 1) | |
11110 | { | |
11111 | error (_("Failed to read in number of buckets\n")); | |
11112 | goto no_hash; | |
11113 | } | |
11114 | ||
11115 | if (fread (nc, hash_ent_size, 1, filedata->handle) != 1) | |
11116 | { | |
11117 | error (_("Failed to read in number of chains\n")); | |
11118 | goto no_hash; | |
11119 | } | |
11120 | ||
11121 | filedata->nbuckets = byte_get (nb, hash_ent_size); | |
11122 | filedata->nchains = byte_get (nc, hash_ent_size); | |
11123 | ||
11124 | if (filedata->nbuckets != 0 && filedata->nchains != 0) | |
11125 | { | |
11126 | filedata->buckets = get_dynamic_data (filedata, filedata->nbuckets, | |
11127 | hash_ent_size); | |
11128 | filedata->chains = get_dynamic_data (filedata, filedata->nchains, | |
11129 | hash_ent_size); | |
11130 | ||
11131 | if (filedata->buckets != NULL && filedata->chains != NULL) | |
11132 | num_of_syms = filedata->nchains; | |
11133 | } | |
11134 | no_hash: | |
11135 | if (num_of_syms == 0) | |
11136 | { | |
11137 | free (filedata->buckets); | |
11138 | filedata->buckets = NULL; | |
11139 | free (filedata->chains); | |
11140 | filedata->chains = NULL; | |
11141 | filedata->nbuckets = 0; | |
11142 | } | |
11143 | } | |
11144 | ||
11145 | if (filedata->dynamic_info_DT_GNU_HASH) | |
11146 | { | |
11147 | unsigned char nb[16]; | |
11148 | uint64_t i, maxchain = 0xffffffff, bitmaskwords; | |
11149 | uint64_t buckets_vma; | |
11150 | uint64_t hn; | |
11151 | ||
11152 | if (fseek64 (filedata->handle, | |
11153 | (filedata->archive_file_offset | |
11154 | + offset_from_vma (filedata, | |
11155 | filedata->dynamic_info_DT_GNU_HASH, | |
11156 | sizeof nb)), | |
11157 | SEEK_SET)) | |
11158 | { | |
11159 | error (_("Unable to seek to start of dynamic information\n")); | |
11160 | goto no_gnu_hash; | |
11161 | } | |
11162 | ||
11163 | if (fread (nb, 16, 1, filedata->handle) != 1) | |
11164 | { | |
11165 | error (_("Failed to read in number of buckets\n")); | |
11166 | goto no_gnu_hash; | |
11167 | } | |
11168 | ||
11169 | filedata->ngnubuckets = byte_get (nb, 4); | |
11170 | filedata->gnusymidx = byte_get (nb + 4, 4); | |
11171 | bitmaskwords = byte_get (nb + 8, 4); | |
11172 | buckets_vma = filedata->dynamic_info_DT_GNU_HASH + 16; | |
11173 | if (is_32bit_elf) | |
11174 | buckets_vma += bitmaskwords * 4; | |
11175 | else | |
11176 | buckets_vma += bitmaskwords * 8; | |
11177 | ||
11178 | if (fseek64 (filedata->handle, | |
11179 | (filedata->archive_file_offset | |
11180 | + offset_from_vma (filedata, buckets_vma, 4)), | |
11181 | SEEK_SET)) | |
11182 | { | |
11183 | error (_("Unable to seek to start of dynamic information\n")); | |
11184 | goto no_gnu_hash; | |
11185 | } | |
11186 | ||
11187 | filedata->gnubuckets | |
11188 | = get_dynamic_data (filedata, filedata->ngnubuckets, 4); | |
11189 | ||
11190 | if (filedata->gnubuckets == NULL) | |
11191 | goto no_gnu_hash; | |
11192 | ||
11193 | for (i = 0; i < filedata->ngnubuckets; i++) | |
11194 | if (filedata->gnubuckets[i] != 0) | |
11195 | { | |
11196 | if (filedata->gnubuckets[i] < filedata->gnusymidx) | |
11197 | goto no_gnu_hash; | |
11198 | ||
11199 | if (maxchain == 0xffffffff || filedata->gnubuckets[i] > maxchain) | |
11200 | maxchain = filedata->gnubuckets[i]; | |
11201 | } | |
11202 | ||
11203 | if (maxchain == 0xffffffff) | |
11204 | goto no_gnu_hash; | |
11205 | ||
11206 | maxchain -= filedata->gnusymidx; | |
11207 | ||
11208 | if (fseek64 (filedata->handle, | |
11209 | (filedata->archive_file_offset | |
11210 | + offset_from_vma (filedata, | |
11211 | buckets_vma + 4 * (filedata->ngnubuckets | |
11212 | + maxchain), | |
11213 | 4)), | |
11214 | SEEK_SET)) | |
11215 | { | |
11216 | error (_("Unable to seek to start of dynamic information\n")); | |
11217 | goto no_gnu_hash; | |
11218 | } | |
11219 | ||
11220 | do | |
11221 | { | |
11222 | if (fread (nb, 4, 1, filedata->handle) != 1) | |
11223 | { | |
11224 | error (_("Failed to determine last chain length\n")); | |
11225 | goto no_gnu_hash; | |
11226 | } | |
11227 | ||
11228 | if (maxchain + 1 == 0) | |
11229 | goto no_gnu_hash; | |
11230 | ||
11231 | ++maxchain; | |
11232 | } | |
11233 | while ((byte_get (nb, 4) & 1) == 0); | |
11234 | ||
11235 | if (fseek64 (filedata->handle, | |
11236 | (filedata->archive_file_offset | |
11237 | + offset_from_vma (filedata, (buckets_vma | |
11238 | + 4 * filedata->ngnubuckets), | |
11239 | 4)), | |
11240 | SEEK_SET)) | |
11241 | { | |
11242 | error (_("Unable to seek to start of dynamic information\n")); | |
11243 | goto no_gnu_hash; | |
11244 | } | |
11245 | ||
11246 | filedata->gnuchains = get_dynamic_data (filedata, maxchain, 4); | |
11247 | filedata->ngnuchains = maxchain; | |
11248 | ||
11249 | if (filedata->gnuchains == NULL) | |
11250 | goto no_gnu_hash; | |
11251 | ||
11252 | if (filedata->dynamic_info_DT_MIPS_XHASH) | |
11253 | { | |
11254 | if (fseek64 (filedata->handle, | |
11255 | (filedata->archive_file_offset | |
11256 | + offset_from_vma (filedata, (buckets_vma | |
11257 | + 4 * (filedata->ngnubuckets | |
11258 | + maxchain)), 4)), | |
11259 | SEEK_SET)) | |
11260 | { | |
11261 | error (_("Unable to seek to start of dynamic information\n")); | |
11262 | goto no_gnu_hash; | |
11263 | } | |
11264 | ||
11265 | filedata->mipsxlat = get_dynamic_data (filedata, maxchain, 4); | |
11266 | if (filedata->mipsxlat == NULL) | |
11267 | goto no_gnu_hash; | |
11268 | } | |
11269 | ||
11270 | for (hn = 0; hn < filedata->ngnubuckets; ++hn) | |
11271 | if (filedata->gnubuckets[hn] != 0) | |
11272 | { | |
11273 | uint64_t si = filedata->gnubuckets[hn]; | |
11274 | uint64_t off = si - filedata->gnusymidx; | |
11275 | ||
11276 | do | |
11277 | { | |
11278 | if (filedata->dynamic_info_DT_MIPS_XHASH) | |
11279 | { | |
11280 | if (off < filedata->ngnuchains | |
11281 | && filedata->mipsxlat[off] >= num_of_syms) | |
11282 | num_of_syms = filedata->mipsxlat[off] + 1; | |
11283 | } | |
11284 | else | |
11285 | { | |
11286 | if (si >= num_of_syms) | |
11287 | num_of_syms = si + 1; | |
11288 | } | |
11289 | si++; | |
11290 | } | |
11291 | while (off < filedata->ngnuchains | |
11292 | && (filedata->gnuchains[off++] & 1) == 0); | |
11293 | } | |
11294 | ||
11295 | if (num_of_syms == 0) | |
11296 | { | |
11297 | no_gnu_hash: | |
11298 | free (filedata->mipsxlat); | |
11299 | filedata->mipsxlat = NULL; | |
11300 | free (filedata->gnuchains); | |
11301 | filedata->gnuchains = NULL; | |
11302 | free (filedata->gnubuckets); | |
11303 | filedata->gnubuckets = NULL; | |
11304 | filedata->ngnubuckets = 0; | |
11305 | filedata->ngnuchains = 0; | |
11306 | } | |
11307 | } | |
11308 | ||
11309 | return num_of_syms; | |
11310 | } | |
11311 | ||
11312 | /* Parse and display the contents of the dynamic section. */ | |
11313 | ||
11314 | static bool | |
11315 | process_dynamic_section (Filedata * filedata) | |
11316 | { | |
11317 | Elf_Internal_Dyn * entry; | |
11318 | ||
11319 | if (filedata->dynamic_size <= 1) | |
11320 | { | |
11321 | if (do_dynamic) | |
11322 | { | |
11323 | if (filedata->is_separate) | |
11324 | printf (_("\nThere is no dynamic section in linked file '%s'.\n"), | |
11325 | filedata->file_name); | |
11326 | else | |
11327 | printf (_("\nThere is no dynamic section in this file.\n")); | |
11328 | } | |
11329 | ||
11330 | return true; | |
11331 | } | |
11332 | ||
11333 | if (!get_dynamic_section (filedata)) | |
11334 | return false; | |
11335 | ||
11336 | /* Find the appropriate symbol table. */ | |
11337 | if (filedata->dynamic_symbols == NULL || do_histogram) | |
11338 | { | |
11339 | uint64_t num_of_syms; | |
11340 | ||
11341 | for (entry = filedata->dynamic_section; | |
11342 | entry < filedata->dynamic_section + filedata->dynamic_nent; | |
11343 | ++entry) | |
11344 | if (entry->d_tag == DT_SYMTAB) | |
11345 | filedata->dynamic_info[DT_SYMTAB] = entry->d_un.d_val; | |
11346 | else if (entry->d_tag == DT_SYMENT) | |
11347 | filedata->dynamic_info[DT_SYMENT] = entry->d_un.d_val; | |
11348 | else if (entry->d_tag == DT_HASH) | |
11349 | filedata->dynamic_info[DT_HASH] = entry->d_un.d_val; | |
11350 | else if (entry->d_tag == DT_GNU_HASH) | |
11351 | filedata->dynamic_info_DT_GNU_HASH = entry->d_un.d_val; | |
11352 | else if ((filedata->file_header.e_machine == EM_MIPS | |
11353 | || filedata->file_header.e_machine == EM_MIPS_RS3_LE) | |
11354 | && entry->d_tag == DT_MIPS_XHASH) | |
11355 | { | |
11356 | filedata->dynamic_info_DT_MIPS_XHASH = entry->d_un.d_val; | |
11357 | filedata->dynamic_info_DT_GNU_HASH = entry->d_un.d_val; | |
11358 | } | |
11359 | ||
11360 | num_of_syms = get_num_dynamic_syms (filedata); | |
11361 | ||
11362 | if (num_of_syms != 0 | |
11363 | && filedata->dynamic_symbols == NULL | |
11364 | && filedata->dynamic_info[DT_SYMTAB] | |
11365 | && filedata->dynamic_info[DT_SYMENT]) | |
11366 | { | |
11367 | Elf_Internal_Phdr *seg; | |
11368 | uint64_t vma = filedata->dynamic_info[DT_SYMTAB]; | |
11369 | ||
11370 | if (! get_program_headers (filedata)) | |
11371 | { | |
11372 | error (_("Cannot interpret virtual addresses " | |
11373 | "without program headers.\n")); | |
11374 | return false; | |
11375 | } | |
11376 | ||
11377 | for (seg = filedata->program_headers; | |
11378 | seg < filedata->program_headers + filedata->file_header.e_phnum; | |
11379 | ++seg) | |
11380 | { | |
11381 | if (seg->p_type != PT_LOAD) | |
11382 | continue; | |
11383 | ||
11384 | if (seg->p_offset + seg->p_filesz > filedata->file_size) | |
11385 | { | |
11386 | /* See PR 21379 for a reproducer. */ | |
11387 | error (_("Invalid PT_LOAD entry\n")); | |
11388 | return false; | |
11389 | } | |
11390 | ||
11391 | if (vma >= (seg->p_vaddr & -seg->p_align) | |
11392 | && vma < seg->p_vaddr + seg->p_filesz) | |
11393 | { | |
11394 | /* Since we do not know how big the symbol table is, | |
11395 | we default to reading in up to the end of PT_LOAD | |
11396 | segment and processing that. This is overkill, I | |
11397 | know, but it should work. */ | |
11398 | Elf_Internal_Shdr section; | |
11399 | section.sh_offset = (vma - seg->p_vaddr | |
11400 | + seg->p_offset); | |
11401 | section.sh_size = (num_of_syms | |
11402 | * filedata->dynamic_info[DT_SYMENT]); | |
11403 | section.sh_entsize = filedata->dynamic_info[DT_SYMENT]; | |
11404 | ||
11405 | if (do_checks | |
11406 | && filedata->dynamic_symtab_section != NULL | |
11407 | && ((filedata->dynamic_symtab_section->sh_offset | |
11408 | != section.sh_offset) | |
11409 | || (filedata->dynamic_symtab_section->sh_size | |
11410 | != section.sh_size) | |
11411 | || (filedata->dynamic_symtab_section->sh_entsize | |
11412 | != section.sh_entsize))) | |
11413 | warn (_("\ | |
11414 | the .dynsym section doesn't match the DT_SYMTAB and DT_SYMENT tags\n")); | |
11415 | ||
11416 | section.sh_name = filedata->string_table_length; | |
11417 | filedata->dynamic_symbols | |
11418 | = get_elf_symbols (filedata, §ion, | |
11419 | &filedata->num_dynamic_syms); | |
11420 | if (filedata->dynamic_symbols == NULL | |
11421 | || filedata->num_dynamic_syms != num_of_syms) | |
11422 | { | |
11423 | error (_("Corrupt DT_SYMTAB dynamic entry\n")); | |
11424 | return false; | |
11425 | } | |
11426 | break; | |
11427 | } | |
11428 | } | |
11429 | } | |
11430 | } | |
11431 | ||
11432 | /* Similarly find a string table. */ | |
11433 | if (filedata->dynamic_strings == NULL) | |
11434 | for (entry = filedata->dynamic_section; | |
11435 | entry < filedata->dynamic_section + filedata->dynamic_nent; | |
11436 | ++entry) | |
11437 | { | |
11438 | if (entry->d_tag == DT_STRTAB) | |
11439 | filedata->dynamic_info[DT_STRTAB] = entry->d_un.d_val; | |
11440 | ||
11441 | if (entry->d_tag == DT_STRSZ) | |
11442 | filedata->dynamic_info[DT_STRSZ] = entry->d_un.d_val; | |
11443 | ||
11444 | if (filedata->dynamic_info[DT_STRTAB] | |
11445 | && filedata->dynamic_info[DT_STRSZ]) | |
11446 | { | |
11447 | uint64_t offset; | |
11448 | uint64_t str_tab_len = filedata->dynamic_info[DT_STRSZ]; | |
11449 | ||
11450 | offset = offset_from_vma (filedata, | |
11451 | filedata->dynamic_info[DT_STRTAB], | |
11452 | str_tab_len); | |
11453 | if (do_checks | |
11454 | && filedata->dynamic_strtab_section | |
11455 | && ((filedata->dynamic_strtab_section->sh_offset | |
11456 | != (file_ptr) offset) | |
11457 | || (filedata->dynamic_strtab_section->sh_size | |
11458 | != str_tab_len))) | |
11459 | warn (_("\ | |
11460 | the .dynstr section doesn't match the DT_STRTAB and DT_STRSZ tags\n")); | |
11461 | ||
11462 | filedata->dynamic_strings | |
11463 | = (char *) get_data (NULL, filedata, offset, 1, str_tab_len, | |
11464 | _("dynamic string table")); | |
11465 | if (filedata->dynamic_strings == NULL) | |
11466 | { | |
11467 | error (_("Corrupt DT_STRTAB dynamic entry\n")); | |
11468 | break; | |
11469 | } | |
11470 | ||
11471 | filedata->dynamic_strings_length = str_tab_len; | |
11472 | break; | |
11473 | } | |
11474 | } | |
11475 | ||
11476 | /* And find the syminfo section if available. */ | |
11477 | if (filedata->dynamic_syminfo == NULL) | |
11478 | { | |
11479 | uint64_t syminsz = 0; | |
11480 | ||
11481 | for (entry = filedata->dynamic_section; | |
11482 | entry < filedata->dynamic_section + filedata->dynamic_nent; | |
11483 | ++entry) | |
11484 | { | |
11485 | if (entry->d_tag == DT_SYMINENT) | |
11486 | { | |
11487 | /* Note: these braces are necessary to avoid a syntax | |
11488 | error from the SunOS4 C compiler. */ | |
11489 | /* PR binutils/17531: A corrupt file can trigger this test. | |
11490 | So do not use an assert, instead generate an error message. */ | |
11491 | if (sizeof (Elf_External_Syminfo) != entry->d_un.d_val) | |
11492 | error (_("Bad value (%d) for SYMINENT entry\n"), | |
11493 | (int) entry->d_un.d_val); | |
11494 | } | |
11495 | else if (entry->d_tag == DT_SYMINSZ) | |
11496 | syminsz = entry->d_un.d_val; | |
11497 | else if (entry->d_tag == DT_SYMINFO) | |
11498 | filedata->dynamic_syminfo_offset | |
11499 | = offset_from_vma (filedata, entry->d_un.d_val, syminsz); | |
11500 | } | |
11501 | ||
11502 | if (filedata->dynamic_syminfo_offset != 0 && syminsz != 0) | |
11503 | { | |
11504 | Elf_External_Syminfo * extsyminfo; | |
11505 | Elf_External_Syminfo * extsym; | |
11506 | Elf_Internal_Syminfo * syminfo; | |
11507 | ||
11508 | /* There is a syminfo section. Read the data. */ | |
11509 | extsyminfo = (Elf_External_Syminfo *) | |
11510 | get_data (NULL, filedata, filedata->dynamic_syminfo_offset, | |
11511 | 1, syminsz, _("symbol information")); | |
11512 | if (!extsyminfo) | |
11513 | return false; | |
11514 | ||
11515 | if (filedata->dynamic_syminfo != NULL) | |
11516 | { | |
11517 | error (_("Multiple dynamic symbol information sections found\n")); | |
11518 | free (filedata->dynamic_syminfo); | |
11519 | } | |
11520 | filedata->dynamic_syminfo = (Elf_Internal_Syminfo *) malloc (syminsz); | |
11521 | if (filedata->dynamic_syminfo == NULL) | |
11522 | { | |
11523 | error (_("Out of memory allocating %" PRIu64 | |
11524 | " bytes for dynamic symbol info\n"), | |
11525 | syminsz); | |
11526 | return false; | |
11527 | } | |
11528 | ||
11529 | filedata->dynamic_syminfo_nent | |
11530 | = syminsz / sizeof (Elf_External_Syminfo); | |
11531 | for (syminfo = filedata->dynamic_syminfo, extsym = extsyminfo; | |
11532 | syminfo < (filedata->dynamic_syminfo | |
11533 | + filedata->dynamic_syminfo_nent); | |
11534 | ++syminfo, ++extsym) | |
11535 | { | |
11536 | syminfo->si_boundto = BYTE_GET (extsym->si_boundto); | |
11537 | syminfo->si_flags = BYTE_GET (extsym->si_flags); | |
11538 | } | |
11539 | ||
11540 | free (extsyminfo); | |
11541 | } | |
11542 | } | |
11543 | ||
11544 | if (do_dynamic && filedata->dynamic_addr) | |
11545 | { | |
11546 | if (filedata->is_separate) | |
11547 | printf (ngettext ("\nIn linked file '%s' the dynamic section at offset %#" PRIx64 " contains %" PRIu64 " entry:\n", | |
11548 | "\nIn linked file '%s' the dynamic section at offset %#" PRIx64 " contains %" PRIu64 " entries:\n", | |
11549 | filedata->dynamic_nent), | |
11550 | filedata->file_name, | |
11551 | filedata->dynamic_addr, | |
11552 | filedata->dynamic_nent); | |
11553 | else | |
11554 | printf (ngettext ("\nDynamic section at offset %#" PRIx64 " contains %" PRId64 " entry:\n", | |
11555 | "\nDynamic section at offset %#" PRIx64 " contains %" PRIu64 " entries:\n", | |
11556 | filedata->dynamic_nent), | |
11557 | filedata->dynamic_addr, | |
11558 | filedata->dynamic_nent); | |
11559 | } | |
11560 | if (do_dynamic) | |
11561 | printf (_(" Tag Type Name/Value\n")); | |
11562 | ||
11563 | for (entry = filedata->dynamic_section; | |
11564 | entry < filedata->dynamic_section + filedata->dynamic_nent; | |
11565 | entry++) | |
11566 | { | |
11567 | if (do_dynamic) | |
11568 | { | |
11569 | const char * dtype; | |
11570 | ||
11571 | putchar (' '); | |
11572 | print_vma (entry->d_tag, FULL_HEX); | |
11573 | dtype = get_dynamic_type (filedata, entry->d_tag); | |
11574 | printf (" (%s)%*s", dtype, | |
11575 | ((is_32bit_elf ? 27 : 19) - (int) strlen (dtype)), " "); | |
11576 | } | |
11577 | ||
11578 | switch (entry->d_tag) | |
11579 | { | |
11580 | case DT_FLAGS: | |
11581 | if (do_dynamic) | |
11582 | print_dynamic_flags (entry->d_un.d_val); | |
11583 | break; | |
11584 | ||
11585 | case DT_AUXILIARY: | |
11586 | case DT_FILTER: | |
11587 | case DT_CONFIG: | |
11588 | case DT_DEPAUDIT: | |
11589 | case DT_AUDIT: | |
11590 | if (do_dynamic) | |
11591 | { | |
11592 | switch (entry->d_tag) | |
11593 | { | |
11594 | case DT_AUXILIARY: | |
11595 | printf (_("Auxiliary library")); | |
11596 | break; | |
11597 | ||
11598 | case DT_FILTER: | |
11599 | printf (_("Filter library")); | |
11600 | break; | |
11601 | ||
11602 | case DT_CONFIG: | |
11603 | printf (_("Configuration file")); | |
11604 | break; | |
11605 | ||
11606 | case DT_DEPAUDIT: | |
11607 | printf (_("Dependency audit library")); | |
11608 | break; | |
11609 | ||
11610 | case DT_AUDIT: | |
11611 | printf (_("Audit library")); | |
11612 | break; | |
11613 | } | |
11614 | ||
11615 | if (valid_dynamic_name (filedata, entry->d_un.d_val)) | |
11616 | printf (": [%s]\n", | |
11617 | get_dynamic_name (filedata, entry->d_un.d_val)); | |
11618 | else | |
11619 | { | |
11620 | printf (": "); | |
11621 | print_vma (entry->d_un.d_val, PREFIX_HEX); | |
11622 | putchar ('\n'); | |
11623 | } | |
11624 | } | |
11625 | break; | |
11626 | ||
11627 | case DT_FEATURE: | |
11628 | if (do_dynamic) | |
11629 | { | |
11630 | printf (_("Flags:")); | |
11631 | ||
11632 | if (entry->d_un.d_val == 0) | |
11633 | printf (_(" None\n")); | |
11634 | else | |
11635 | { | |
11636 | uint64_t val = entry->d_un.d_val; | |
11637 | ||
11638 | if (val & DTF_1_PARINIT) | |
11639 | { | |
11640 | printf (" PARINIT"); | |
11641 | val ^= DTF_1_PARINIT; | |
11642 | } | |
11643 | if (val & DTF_1_CONFEXP) | |
11644 | { | |
11645 | printf (" CONFEXP"); | |
11646 | val ^= DTF_1_CONFEXP; | |
11647 | } | |
11648 | if (val != 0) | |
11649 | printf (" %" PRIx64, val); | |
11650 | puts (""); | |
11651 | } | |
11652 | } | |
11653 | break; | |
11654 | ||
11655 | case DT_POSFLAG_1: | |
11656 | if (do_dynamic) | |
11657 | { | |
11658 | printf (_("Flags:")); | |
11659 | ||
11660 | if (entry->d_un.d_val == 0) | |
11661 | printf (_(" None\n")); | |
11662 | else | |
11663 | { | |
11664 | uint64_t val = entry->d_un.d_val; | |
11665 | ||
11666 | if (val & DF_P1_LAZYLOAD) | |
11667 | { | |
11668 | printf (" LAZYLOAD"); | |
11669 | val ^= DF_P1_LAZYLOAD; | |
11670 | } | |
11671 | if (val & DF_P1_GROUPPERM) | |
11672 | { | |
11673 | printf (" GROUPPERM"); | |
11674 | val ^= DF_P1_GROUPPERM; | |
11675 | } | |
11676 | if (val != 0) | |
11677 | printf (" %" PRIx64, val); | |
11678 | puts (""); | |
11679 | } | |
11680 | } | |
11681 | break; | |
11682 | ||
11683 | case DT_FLAGS_1: | |
11684 | if (do_dynamic) | |
11685 | { | |
11686 | printf (_("Flags:")); | |
11687 | if (entry->d_un.d_val == 0) | |
11688 | printf (_(" None\n")); | |
11689 | else | |
11690 | { | |
11691 | uint64_t val = entry->d_un.d_val; | |
11692 | ||
11693 | if (val & DF_1_NOW) | |
11694 | { | |
11695 | printf (" NOW"); | |
11696 | val ^= DF_1_NOW; | |
11697 | } | |
11698 | if (val & DF_1_GLOBAL) | |
11699 | { | |
11700 | printf (" GLOBAL"); | |
11701 | val ^= DF_1_GLOBAL; | |
11702 | } | |
11703 | if (val & DF_1_GROUP) | |
11704 | { | |
11705 | printf (" GROUP"); | |
11706 | val ^= DF_1_GROUP; | |
11707 | } | |
11708 | if (val & DF_1_NODELETE) | |
11709 | { | |
11710 | printf (" NODELETE"); | |
11711 | val ^= DF_1_NODELETE; | |
11712 | } | |
11713 | if (val & DF_1_LOADFLTR) | |
11714 | { | |
11715 | printf (" LOADFLTR"); | |
11716 | val ^= DF_1_LOADFLTR; | |
11717 | } | |
11718 | if (val & DF_1_INITFIRST) | |
11719 | { | |
11720 | printf (" INITFIRST"); | |
11721 | val ^= DF_1_INITFIRST; | |
11722 | } | |
11723 | if (val & DF_1_NOOPEN) | |
11724 | { | |
11725 | printf (" NOOPEN"); | |
11726 | val ^= DF_1_NOOPEN; | |
11727 | } | |
11728 | if (val & DF_1_ORIGIN) | |
11729 | { | |
11730 | printf (" ORIGIN"); | |
11731 | val ^= DF_1_ORIGIN; | |
11732 | } | |
11733 | if (val & DF_1_DIRECT) | |
11734 | { | |
11735 | printf (" DIRECT"); | |
11736 | val ^= DF_1_DIRECT; | |
11737 | } | |
11738 | if (val & DF_1_TRANS) | |
11739 | { | |
11740 | printf (" TRANS"); | |
11741 | val ^= DF_1_TRANS; | |
11742 | } | |
11743 | if (val & DF_1_INTERPOSE) | |
11744 | { | |
11745 | printf (" INTERPOSE"); | |
11746 | val ^= DF_1_INTERPOSE; | |
11747 | } | |
11748 | if (val & DF_1_NODEFLIB) | |
11749 | { | |
11750 | printf (" NODEFLIB"); | |
11751 | val ^= DF_1_NODEFLIB; | |
11752 | } | |
11753 | if (val & DF_1_NODUMP) | |
11754 | { | |
11755 | printf (" NODUMP"); | |
11756 | val ^= DF_1_NODUMP; | |
11757 | } | |
11758 | if (val & DF_1_CONFALT) | |
11759 | { | |
11760 | printf (" CONFALT"); | |
11761 | val ^= DF_1_CONFALT; | |
11762 | } | |
11763 | if (val & DF_1_ENDFILTEE) | |
11764 | { | |
11765 | printf (" ENDFILTEE"); | |
11766 | val ^= DF_1_ENDFILTEE; | |
11767 | } | |
11768 | if (val & DF_1_DISPRELDNE) | |
11769 | { | |
11770 | printf (" DISPRELDNE"); | |
11771 | val ^= DF_1_DISPRELDNE; | |
11772 | } | |
11773 | if (val & DF_1_DISPRELPND) | |
11774 | { | |
11775 | printf (" DISPRELPND"); | |
11776 | val ^= DF_1_DISPRELPND; | |
11777 | } | |
11778 | if (val & DF_1_NODIRECT) | |
11779 | { | |
11780 | printf (" NODIRECT"); | |
11781 | val ^= DF_1_NODIRECT; | |
11782 | } | |
11783 | if (val & DF_1_IGNMULDEF) | |
11784 | { | |
11785 | printf (" IGNMULDEF"); | |
11786 | val ^= DF_1_IGNMULDEF; | |
11787 | } | |
11788 | if (val & DF_1_NOKSYMS) | |
11789 | { | |
11790 | printf (" NOKSYMS"); | |
11791 | val ^= DF_1_NOKSYMS; | |
11792 | } | |
11793 | if (val & DF_1_NOHDR) | |
11794 | { | |
11795 | printf (" NOHDR"); | |
11796 | val ^= DF_1_NOHDR; | |
11797 | } | |
11798 | if (val & DF_1_EDITED) | |
11799 | { | |
11800 | printf (" EDITED"); | |
11801 | val ^= DF_1_EDITED; | |
11802 | } | |
11803 | if (val & DF_1_NORELOC) | |
11804 | { | |
11805 | printf (" NORELOC"); | |
11806 | val ^= DF_1_NORELOC; | |
11807 | } | |
11808 | if (val & DF_1_SYMINTPOSE) | |
11809 | { | |
11810 | printf (" SYMINTPOSE"); | |
11811 | val ^= DF_1_SYMINTPOSE; | |
11812 | } | |
11813 | if (val & DF_1_GLOBAUDIT) | |
11814 | { | |
11815 | printf (" GLOBAUDIT"); | |
11816 | val ^= DF_1_GLOBAUDIT; | |
11817 | } | |
11818 | if (val & DF_1_SINGLETON) | |
11819 | { | |
11820 | printf (" SINGLETON"); | |
11821 | val ^= DF_1_SINGLETON; | |
11822 | } | |
11823 | if (val & DF_1_STUB) | |
11824 | { | |
11825 | printf (" STUB"); | |
11826 | val ^= DF_1_STUB; | |
11827 | } | |
11828 | if (val & DF_1_PIE) | |
11829 | { | |
11830 | printf (" PIE"); | |
11831 | val ^= DF_1_PIE; | |
11832 | } | |
11833 | if (val & DF_1_KMOD) | |
11834 | { | |
11835 | printf (" KMOD"); | |
11836 | val ^= DF_1_KMOD; | |
11837 | } | |
11838 | if (val & DF_1_WEAKFILTER) | |
11839 | { | |
11840 | printf (" WEAKFILTER"); | |
11841 | val ^= DF_1_WEAKFILTER; | |
11842 | } | |
11843 | if (val & DF_1_NOCOMMON) | |
11844 | { | |
11845 | printf (" NOCOMMON"); | |
11846 | val ^= DF_1_NOCOMMON; | |
11847 | } | |
11848 | if (val != 0) | |
11849 | printf (" %" PRIx64, val); | |
11850 | puts (""); | |
11851 | } | |
11852 | } | |
11853 | break; | |
11854 | ||
11855 | case DT_PLTREL: | |
11856 | filedata->dynamic_info[entry->d_tag] = entry->d_un.d_val; | |
11857 | if (do_dynamic) | |
11858 | puts (get_dynamic_type (filedata, entry->d_un.d_val)); | |
11859 | break; | |
11860 | ||
11861 | case DT_NULL : | |
11862 | case DT_NEEDED : | |
11863 | case DT_PLTGOT : | |
11864 | case DT_HASH : | |
11865 | case DT_STRTAB : | |
11866 | case DT_SYMTAB : | |
11867 | case DT_RELA : | |
11868 | case DT_INIT : | |
11869 | case DT_FINI : | |
11870 | case DT_SONAME : | |
11871 | case DT_RPATH : | |
11872 | case DT_SYMBOLIC: | |
11873 | case DT_REL : | |
11874 | case DT_RELR : | |
11875 | case DT_DEBUG : | |
11876 | case DT_TEXTREL : | |
11877 | case DT_JMPREL : | |
11878 | case DT_RUNPATH : | |
11879 | filedata->dynamic_info[entry->d_tag] = entry->d_un.d_val; | |
11880 | ||
11881 | if (do_dynamic) | |
11882 | { | |
11883 | const char *name; | |
11884 | ||
11885 | if (valid_dynamic_name (filedata, entry->d_un.d_val)) | |
11886 | name = get_dynamic_name (filedata, entry->d_un.d_val); | |
11887 | else | |
11888 | name = NULL; | |
11889 | ||
11890 | if (name) | |
11891 | { | |
11892 | switch (entry->d_tag) | |
11893 | { | |
11894 | case DT_NEEDED: | |
11895 | printf (_("Shared library: [%s]"), name); | |
11896 | ||
11897 | if (filedata->program_interpreter | |
11898 | && streq (name, filedata->program_interpreter)) | |
11899 | printf (_(" program interpreter")); | |
11900 | break; | |
11901 | ||
11902 | case DT_SONAME: | |
11903 | printf (_("Library soname: [%s]"), name); | |
11904 | break; | |
11905 | ||
11906 | case DT_RPATH: | |
11907 | printf (_("Library rpath: [%s]"), name); | |
11908 | break; | |
11909 | ||
11910 | case DT_RUNPATH: | |
11911 | printf (_("Library runpath: [%s]"), name); | |
11912 | break; | |
11913 | ||
11914 | default: | |
11915 | print_vma (entry->d_un.d_val, PREFIX_HEX); | |
11916 | break; | |
11917 | } | |
11918 | } | |
11919 | else | |
11920 | print_vma (entry->d_un.d_val, PREFIX_HEX); | |
11921 | ||
11922 | putchar ('\n'); | |
11923 | } | |
11924 | break; | |
11925 | ||
11926 | case DT_PLTRELSZ: | |
11927 | case DT_RELASZ : | |
11928 | case DT_STRSZ : | |
11929 | case DT_RELSZ : | |
11930 | case DT_RELAENT : | |
11931 | case DT_RELRENT : | |
11932 | case DT_RELRSZ : | |
11933 | case DT_SYMENT : | |
11934 | case DT_RELENT : | |
11935 | filedata->dynamic_info[entry->d_tag] = entry->d_un.d_val; | |
11936 | /* Fall through. */ | |
11937 | case DT_PLTPADSZ: | |
11938 | case DT_MOVEENT : | |
11939 | case DT_MOVESZ : | |
11940 | case DT_PREINIT_ARRAYSZ: | |
11941 | case DT_INIT_ARRAYSZ: | |
11942 | case DT_FINI_ARRAYSZ: | |
11943 | case DT_GNU_CONFLICTSZ: | |
11944 | case DT_GNU_LIBLISTSZ: | |
11945 | if (do_dynamic) | |
11946 | { | |
11947 | print_vma (entry->d_un.d_val, UNSIGNED); | |
11948 | printf (_(" (bytes)\n")); | |
11949 | } | |
11950 | break; | |
11951 | ||
11952 | case DT_VERDEFNUM: | |
11953 | case DT_VERNEEDNUM: | |
11954 | case DT_RELACOUNT: | |
11955 | case DT_RELCOUNT: | |
11956 | if (do_dynamic) | |
11957 | { | |
11958 | print_vma (entry->d_un.d_val, UNSIGNED); | |
11959 | putchar ('\n'); | |
11960 | } | |
11961 | break; | |
11962 | ||
11963 | case DT_SYMINSZ: | |
11964 | case DT_SYMINENT: | |
11965 | case DT_SYMINFO: | |
11966 | case DT_USED: | |
11967 | case DT_INIT_ARRAY: | |
11968 | case DT_FINI_ARRAY: | |
11969 | if (do_dynamic) | |
11970 | { | |
11971 | if (entry->d_tag == DT_USED | |
11972 | && valid_dynamic_name (filedata, entry->d_un.d_val)) | |
11973 | { | |
11974 | const char *name | |
11975 | = get_dynamic_name (filedata, entry->d_un.d_val); | |
11976 | ||
11977 | if (*name) | |
11978 | { | |
11979 | printf (_("Not needed object: [%s]\n"), name); | |
11980 | break; | |
11981 | } | |
11982 | } | |
11983 | ||
11984 | print_vma (entry->d_un.d_val, PREFIX_HEX); | |
11985 | putchar ('\n'); | |
11986 | } | |
11987 | break; | |
11988 | ||
11989 | case DT_BIND_NOW: | |
11990 | /* The value of this entry is ignored. */ | |
11991 | if (do_dynamic) | |
11992 | putchar ('\n'); | |
11993 | break; | |
11994 | ||
11995 | case DT_GNU_PRELINKED: | |
11996 | if (do_dynamic) | |
11997 | { | |
11998 | struct tm * tmp; | |
11999 | time_t atime = entry->d_un.d_val; | |
12000 | ||
12001 | tmp = gmtime (&atime); | |
12002 | /* PR 17533 file: 041-1244816-0.004. */ | |
12003 | if (tmp == NULL) | |
12004 | printf (_("<corrupt time val: %" PRIx64), | |
12005 | (uint64_t) atime); | |
12006 | else | |
12007 | printf ("%04u-%02u-%02uT%02u:%02u:%02u\n", | |
12008 | tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday, | |
12009 | tmp->tm_hour, tmp->tm_min, tmp->tm_sec); | |
12010 | ||
12011 | } | |
12012 | break; | |
12013 | ||
12014 | case DT_GNU_HASH: | |
12015 | filedata->dynamic_info_DT_GNU_HASH = entry->d_un.d_val; | |
12016 | if (do_dynamic) | |
12017 | { | |
12018 | print_vma (entry->d_un.d_val, PREFIX_HEX); | |
12019 | putchar ('\n'); | |
12020 | } | |
12021 | break; | |
12022 | ||
12023 | case DT_GNU_FLAGS_1: | |
12024 | if (do_dynamic) | |
12025 | { | |
12026 | printf (_("Flags:")); | |
12027 | if (entry->d_un.d_val == 0) | |
12028 | printf (_(" None\n")); | |
12029 | else | |
12030 | { | |
12031 | uint64_t val = entry->d_un.d_val; | |
12032 | ||
12033 | if (val & DF_GNU_1_UNIQUE) | |
12034 | { | |
12035 | printf (" UNIQUE"); | |
12036 | val ^= DF_GNU_1_UNIQUE; | |
12037 | } | |
12038 | if (val != 0) | |
12039 | printf (" %" PRIx64, val); | |
12040 | puts (""); | |
12041 | } | |
12042 | } | |
12043 | break; | |
12044 | ||
12045 | default: | |
12046 | if ((entry->d_tag >= DT_VERSYM) && (entry->d_tag <= DT_VERNEEDNUM)) | |
12047 | filedata->version_info[DT_VERSIONTAGIDX (entry->d_tag)] | |
12048 | = entry->d_un.d_val; | |
12049 | ||
12050 | if (do_dynamic) | |
12051 | { | |
12052 | switch (filedata->file_header.e_machine) | |
12053 | { | |
12054 | case EM_AARCH64: | |
12055 | dynamic_section_aarch64_val (entry); | |
12056 | break; | |
12057 | case EM_MIPS: | |
12058 | case EM_MIPS_RS3_LE: | |
12059 | dynamic_section_mips_val (filedata, entry); | |
12060 | break; | |
12061 | case EM_PARISC: | |
12062 | dynamic_section_parisc_val (entry); | |
12063 | break; | |
12064 | case EM_IA_64: | |
12065 | dynamic_section_ia64_val (entry); | |
12066 | break; | |
12067 | default: | |
12068 | print_vma (entry->d_un.d_val, PREFIX_HEX); | |
12069 | putchar ('\n'); | |
12070 | } | |
12071 | } | |
12072 | break; | |
12073 | } | |
12074 | } | |
12075 | ||
12076 | return true; | |
12077 | } | |
12078 | ||
12079 | static char * | |
12080 | get_ver_flags (unsigned int flags) | |
12081 | { | |
12082 | static char buff[128]; | |
12083 | ||
12084 | buff[0] = 0; | |
12085 | ||
12086 | if (flags == 0) | |
12087 | return _("none"); | |
12088 | ||
12089 | if (flags & VER_FLG_BASE) | |
12090 | strcat (buff, "BASE"); | |
12091 | ||
12092 | if (flags & VER_FLG_WEAK) | |
12093 | { | |
12094 | if (flags & VER_FLG_BASE) | |
12095 | strcat (buff, " | "); | |
12096 | ||
12097 | strcat (buff, "WEAK"); | |
12098 | } | |
12099 | ||
12100 | if (flags & VER_FLG_INFO) | |
12101 | { | |
12102 | if (flags & (VER_FLG_BASE|VER_FLG_WEAK)) | |
12103 | strcat (buff, " | "); | |
12104 | ||
12105 | strcat (buff, "INFO"); | |
12106 | } | |
12107 | ||
12108 | if (flags & ~(VER_FLG_BASE | VER_FLG_WEAK | VER_FLG_INFO)) | |
12109 | { | |
12110 | if (flags & (VER_FLG_BASE | VER_FLG_WEAK | VER_FLG_INFO)) | |
12111 | strcat (buff, " | "); | |
12112 | ||
12113 | strcat (buff, _("<unknown>")); | |
12114 | } | |
12115 | ||
12116 | return buff; | |
12117 | } | |
12118 | ||
12119 | /* Display the contents of the version sections. */ | |
12120 | ||
12121 | static bool | |
12122 | process_version_sections (Filedata * filedata) | |
12123 | { | |
12124 | Elf_Internal_Shdr * section; | |
12125 | unsigned i; | |
12126 | bool found = false; | |
12127 | ||
12128 | if (! do_version) | |
12129 | return true; | |
12130 | ||
12131 | for (i = 0, section = filedata->section_headers; | |
12132 | i < filedata->file_header.e_shnum; | |
12133 | i++, section++) | |
12134 | { | |
12135 | switch (section->sh_type) | |
12136 | { | |
12137 | case SHT_GNU_verdef: | |
12138 | { | |
12139 | Elf_External_Verdef * edefs; | |
12140 | size_t idx; | |
12141 | size_t cnt; | |
12142 | char * endbuf; | |
12143 | ||
12144 | found = true; | |
12145 | ||
12146 | if (filedata->is_separate) | |
12147 | printf (ngettext ("\nIn linked file '%s' the version definition section '%s' contains %u entry:\n", | |
12148 | "\nIn linked file '%s' the version definition section '%s' contains %u entries:\n", | |
12149 | section->sh_info), | |
12150 | filedata->file_name, | |
12151 | printable_section_name (filedata, section), | |
12152 | section->sh_info); | |
12153 | else | |
12154 | printf (ngettext ("\nVersion definition section '%s' " | |
12155 | "contains %u entry:\n", | |
12156 | "\nVersion definition section '%s' " | |
12157 | "contains %u entries:\n", | |
12158 | section->sh_info), | |
12159 | printable_section_name (filedata, section), | |
12160 | section->sh_info); | |
12161 | ||
12162 | printf (_(" Addr: 0x%016" PRIx64), section->sh_addr); | |
12163 | printf (_(" Offset: 0x%08" PRIx64 " Link: %u (%s)\n"), | |
12164 | section->sh_offset, section->sh_link, | |
12165 | printable_section_name_from_index (filedata, section->sh_link)); | |
12166 | ||
12167 | edefs = (Elf_External_Verdef *) | |
12168 | get_data (NULL, filedata, section->sh_offset, 1,section->sh_size, | |
12169 | _("version definition section")); | |
12170 | if (!edefs) | |
12171 | break; | |
12172 | endbuf = (char *) edefs + section->sh_size; | |
12173 | ||
12174 | for (idx = cnt = 0; cnt < section->sh_info; ++cnt) | |
12175 | { | |
12176 | char * vstart; | |
12177 | Elf_External_Verdef * edef; | |
12178 | Elf_Internal_Verdef ent; | |
12179 | Elf_External_Verdaux * eaux; | |
12180 | Elf_Internal_Verdaux aux; | |
12181 | size_t isum; | |
12182 | int j; | |
12183 | ||
12184 | vstart = ((char *) edefs) + idx; | |
12185 | if (vstart + sizeof (*edef) > endbuf) | |
12186 | break; | |
12187 | ||
12188 | edef = (Elf_External_Verdef *) vstart; | |
12189 | ||
12190 | ent.vd_version = BYTE_GET (edef->vd_version); | |
12191 | ent.vd_flags = BYTE_GET (edef->vd_flags); | |
12192 | ent.vd_ndx = BYTE_GET (edef->vd_ndx); | |
12193 | ent.vd_cnt = BYTE_GET (edef->vd_cnt); | |
12194 | ent.vd_hash = BYTE_GET (edef->vd_hash); | |
12195 | ent.vd_aux = BYTE_GET (edef->vd_aux); | |
12196 | ent.vd_next = BYTE_GET (edef->vd_next); | |
12197 | ||
12198 | printf (_(" %#06zx: Rev: %d Flags: %s"), | |
12199 | idx, ent.vd_version, get_ver_flags (ent.vd_flags)); | |
12200 | ||
12201 | printf (_(" Index: %d Cnt: %d "), | |
12202 | ent.vd_ndx, ent.vd_cnt); | |
12203 | ||
12204 | /* Check for overflow. */ | |
12205 | if (ent.vd_aux > (size_t) (endbuf - vstart)) | |
12206 | break; | |
12207 | ||
12208 | vstart += ent.vd_aux; | |
12209 | ||
12210 | if (vstart + sizeof (*eaux) > endbuf) | |
12211 | break; | |
12212 | eaux = (Elf_External_Verdaux *) vstart; | |
12213 | ||
12214 | aux.vda_name = BYTE_GET (eaux->vda_name); | |
12215 | aux.vda_next = BYTE_GET (eaux->vda_next); | |
12216 | ||
12217 | if (valid_dynamic_name (filedata, aux.vda_name)) | |
12218 | printf (_("Name: %s\n"), | |
12219 | get_dynamic_name (filedata, aux.vda_name)); | |
12220 | else | |
12221 | printf (_("Name index: %ld\n"), aux.vda_name); | |
12222 | ||
12223 | isum = idx + ent.vd_aux; | |
12224 | ||
12225 | for (j = 1; j < ent.vd_cnt; j++) | |
12226 | { | |
12227 | if (aux.vda_next < sizeof (*eaux) | |
12228 | && !(j == ent.vd_cnt - 1 && aux.vda_next == 0)) | |
12229 | { | |
12230 | warn (_("Invalid vda_next field of %lx\n"), | |
12231 | aux.vda_next); | |
12232 | j = ent.vd_cnt; | |
12233 | break; | |
12234 | } | |
12235 | /* Check for overflow. */ | |
12236 | if (aux.vda_next > (size_t) (endbuf - vstart)) | |
12237 | break; | |
12238 | ||
12239 | isum += aux.vda_next; | |
12240 | vstart += aux.vda_next; | |
12241 | ||
12242 | if (vstart + sizeof (*eaux) > endbuf) | |
12243 | break; | |
12244 | eaux = (Elf_External_Verdaux *) vstart; | |
12245 | ||
12246 | aux.vda_name = BYTE_GET (eaux->vda_name); | |
12247 | aux.vda_next = BYTE_GET (eaux->vda_next); | |
12248 | ||
12249 | if (valid_dynamic_name (filedata, aux.vda_name)) | |
12250 | printf (_(" %#06zx: Parent %d: %s\n"), | |
12251 | isum, j, | |
12252 | get_dynamic_name (filedata, aux.vda_name)); | |
12253 | else | |
12254 | printf (_(" %#06zx: Parent %d, name index: %ld\n"), | |
12255 | isum, j, aux.vda_name); | |
12256 | } | |
12257 | ||
12258 | if (j < ent.vd_cnt) | |
12259 | printf (_(" Version def aux past end of section\n")); | |
12260 | ||
12261 | /* PR 17531: | |
12262 | file: id:000001,src:000172+005151,op:splice,rep:2. */ | |
12263 | if (ent.vd_next < sizeof (*edef) | |
12264 | && !(cnt == section->sh_info - 1 && ent.vd_next == 0)) | |
12265 | { | |
12266 | warn (_("Invalid vd_next field of %lx\n"), ent.vd_next); | |
12267 | cnt = section->sh_info; | |
12268 | break; | |
12269 | } | |
12270 | if (ent.vd_next > (size_t) (endbuf - ((char *) edefs + idx))) | |
12271 | break; | |
12272 | ||
12273 | idx += ent.vd_next; | |
12274 | } | |
12275 | ||
12276 | if (cnt < section->sh_info) | |
12277 | printf (_(" Version definition past end of section\n")); | |
12278 | ||
12279 | free (edefs); | |
12280 | } | |
12281 | break; | |
12282 | ||
12283 | case SHT_GNU_verneed: | |
12284 | { | |
12285 | Elf_External_Verneed * eneed; | |
12286 | size_t idx; | |
12287 | size_t cnt; | |
12288 | char * endbuf; | |
12289 | ||
12290 | found = true; | |
12291 | ||
12292 | if (filedata->is_separate) | |
12293 | printf (ngettext ("\nIn linked file '%s' the version needs section '%s' contains %u entry:\n", | |
12294 | "\nIn linked file '%s' the version needs section '%s' contains %u entries:\n", | |
12295 | section->sh_info), | |
12296 | filedata->file_name, | |
12297 | printable_section_name (filedata, section), | |
12298 | section->sh_info); | |
12299 | else | |
12300 | printf (ngettext ("\nVersion needs section '%s' " | |
12301 | "contains %u entry:\n", | |
12302 | "\nVersion needs section '%s' " | |
12303 | "contains %u entries:\n", | |
12304 | section->sh_info), | |
12305 | printable_section_name (filedata, section), | |
12306 | section->sh_info); | |
12307 | ||
12308 | printf (_(" Addr: 0x%016" PRIx64), section->sh_addr); | |
12309 | printf (_(" Offset: 0x%08" PRIx64 " Link: %u (%s)\n"), | |
12310 | section->sh_offset, section->sh_link, | |
12311 | printable_section_name_from_index (filedata, section->sh_link)); | |
12312 | ||
12313 | eneed = (Elf_External_Verneed *) get_data (NULL, filedata, | |
12314 | section->sh_offset, 1, | |
12315 | section->sh_size, | |
12316 | _("Version Needs section")); | |
12317 | if (!eneed) | |
12318 | break; | |
12319 | endbuf = (char *) eneed + section->sh_size; | |
12320 | ||
12321 | for (idx = cnt = 0; cnt < section->sh_info; ++cnt) | |
12322 | { | |
12323 | Elf_External_Verneed * entry; | |
12324 | Elf_Internal_Verneed ent; | |
12325 | size_t isum; | |
12326 | int j; | |
12327 | char * vstart; | |
12328 | ||
12329 | vstart = ((char *) eneed) + idx; | |
12330 | if (vstart + sizeof (*entry) > endbuf) | |
12331 | break; | |
12332 | ||
12333 | entry = (Elf_External_Verneed *) vstart; | |
12334 | ||
12335 | ent.vn_version = BYTE_GET (entry->vn_version); | |
12336 | ent.vn_cnt = BYTE_GET (entry->vn_cnt); | |
12337 | ent.vn_file = BYTE_GET (entry->vn_file); | |
12338 | ent.vn_aux = BYTE_GET (entry->vn_aux); | |
12339 | ent.vn_next = BYTE_GET (entry->vn_next); | |
12340 | ||
12341 | printf (_(" %#06zx: Version: %d"), idx, ent.vn_version); | |
12342 | ||
12343 | if (valid_dynamic_name (filedata, ent.vn_file)) | |
12344 | printf (_(" File: %s"), | |
12345 | get_dynamic_name (filedata, ent.vn_file)); | |
12346 | else | |
12347 | printf (_(" File: %lx"), ent.vn_file); | |
12348 | ||
12349 | printf (_(" Cnt: %d\n"), ent.vn_cnt); | |
12350 | ||
12351 | /* Check for overflow. */ | |
12352 | if (ent.vn_aux > (size_t) (endbuf - vstart)) | |
12353 | break; | |
12354 | vstart += ent.vn_aux; | |
12355 | ||
12356 | for (j = 0, isum = idx + ent.vn_aux; j < ent.vn_cnt; ++j) | |
12357 | { | |
12358 | Elf_External_Vernaux * eaux; | |
12359 | Elf_Internal_Vernaux aux; | |
12360 | ||
12361 | if (vstart + sizeof (*eaux) > endbuf) | |
12362 | break; | |
12363 | eaux = (Elf_External_Vernaux *) vstart; | |
12364 | ||
12365 | aux.vna_hash = BYTE_GET (eaux->vna_hash); | |
12366 | aux.vna_flags = BYTE_GET (eaux->vna_flags); | |
12367 | aux.vna_other = BYTE_GET (eaux->vna_other); | |
12368 | aux.vna_name = BYTE_GET (eaux->vna_name); | |
12369 | aux.vna_next = BYTE_GET (eaux->vna_next); | |
12370 | ||
12371 | if (valid_dynamic_name (filedata, aux.vna_name)) | |
12372 | printf (_(" %#06zx: Name: %s"), | |
12373 | isum, get_dynamic_name (filedata, aux.vna_name)); | |
12374 | else | |
12375 | printf (_(" %#06zx: Name index: %lx"), | |
12376 | isum, aux.vna_name); | |
12377 | ||
12378 | printf (_(" Flags: %s Version: %d\n"), | |
12379 | get_ver_flags (aux.vna_flags), aux.vna_other); | |
12380 | ||
12381 | if (aux.vna_next < sizeof (*eaux) | |
12382 | && !(j == ent.vn_cnt - 1 && aux.vna_next == 0)) | |
12383 | { | |
12384 | warn (_("Invalid vna_next field of %lx\n"), | |
12385 | aux.vna_next); | |
12386 | j = ent.vn_cnt; | |
12387 | break; | |
12388 | } | |
12389 | /* Check for overflow. */ | |
12390 | if (aux.vna_next > (size_t) (endbuf - vstart)) | |
12391 | break; | |
12392 | isum += aux.vna_next; | |
12393 | vstart += aux.vna_next; | |
12394 | } | |
12395 | ||
12396 | if (j < ent.vn_cnt) | |
12397 | warn (_("Missing Version Needs auxiliary information\n")); | |
12398 | ||
12399 | if (ent.vn_next < sizeof (*entry) | |
12400 | && !(cnt == section->sh_info - 1 && ent.vn_next == 0)) | |
12401 | { | |
12402 | warn (_("Invalid vn_next field of %lx\n"), ent.vn_next); | |
12403 | cnt = section->sh_info; | |
12404 | break; | |
12405 | } | |
12406 | if (ent.vn_next > (size_t) (endbuf - ((char *) eneed + idx))) | |
12407 | break; | |
12408 | idx += ent.vn_next; | |
12409 | } | |
12410 | ||
12411 | if (cnt < section->sh_info) | |
12412 | warn (_("Missing Version Needs information\n")); | |
12413 | ||
12414 | free (eneed); | |
12415 | } | |
12416 | break; | |
12417 | ||
12418 | case SHT_GNU_versym: | |
12419 | { | |
12420 | Elf_Internal_Shdr * link_section; | |
12421 | uint64_t total; | |
12422 | unsigned int cnt; | |
12423 | unsigned char * edata; | |
12424 | unsigned short * data; | |
12425 | char * strtab; | |
12426 | Elf_Internal_Sym * symbols; | |
12427 | Elf_Internal_Shdr * string_sec; | |
12428 | uint64_t num_syms; | |
12429 | uint64_t off; | |
12430 | ||
12431 | if (section->sh_link >= filedata->file_header.e_shnum) | |
12432 | break; | |
12433 | ||
12434 | link_section = filedata->section_headers + section->sh_link; | |
12435 | total = section->sh_size / sizeof (Elf_External_Versym); | |
12436 | ||
12437 | if (link_section->sh_link >= filedata->file_header.e_shnum) | |
12438 | break; | |
12439 | ||
12440 | found = true; | |
12441 | ||
12442 | symbols = get_elf_symbols (filedata, link_section, & num_syms); | |
12443 | if (symbols == NULL) | |
12444 | break; | |
12445 | ||
12446 | string_sec = filedata->section_headers + link_section->sh_link; | |
12447 | ||
12448 | strtab = (char *) get_data (NULL, filedata, string_sec->sh_offset, 1, | |
12449 | string_sec->sh_size, | |
12450 | _("version string table")); | |
12451 | if (!strtab) | |
12452 | { | |
12453 | free (symbols); | |
12454 | break; | |
12455 | } | |
12456 | ||
12457 | if (filedata->is_separate) | |
12458 | printf (ngettext ("\nIn linked file '%s' the version symbols section '%s' contains %" PRIu64 " entry:\n", | |
12459 | "\nIn linked file '%s' the version symbols section '%s' contains %" PRIu64 " entries:\n", | |
12460 | total), | |
12461 | filedata->file_name, | |
12462 | printable_section_name (filedata, section), | |
12463 | total); | |
12464 | else | |
12465 | printf (ngettext ("\nVersion symbols section '%s' " | |
12466 | "contains %" PRIu64 " entry:\n", | |
12467 | "\nVersion symbols section '%s' " | |
12468 | "contains %" PRIu64 " entries:\n", | |
12469 | total), | |
12470 | printable_section_name (filedata, section), | |
12471 | total); | |
12472 | ||
12473 | printf (_(" Addr: 0x%016" PRIx64), section->sh_addr); | |
12474 | printf (_(" Offset: 0x%08" PRIx64 " Link: %u (%s)\n"), | |
12475 | section->sh_offset, section->sh_link, | |
12476 | printable_section_name (filedata, link_section)); | |
12477 | ||
12478 | off = offset_from_vma (filedata, | |
12479 | filedata->version_info[DT_VERSIONTAGIDX (DT_VERSYM)], | |
12480 | total * sizeof (short)); | |
12481 | edata = (unsigned char *) get_data (NULL, filedata, off, | |
12482 | sizeof (short), total, | |
12483 | _("version symbol data")); | |
12484 | if (!edata) | |
12485 | { | |
12486 | free (strtab); | |
12487 | free (symbols); | |
12488 | break; | |
12489 | } | |
12490 | ||
12491 | data = (short unsigned int *) cmalloc (total, sizeof (short)); | |
12492 | ||
12493 | for (cnt = total; cnt --;) | |
12494 | data[cnt] = byte_get (edata + cnt * sizeof (short), | |
12495 | sizeof (short)); | |
12496 | ||
12497 | free (edata); | |
12498 | ||
12499 | for (cnt = 0; cnt < total; cnt += 4) | |
12500 | { | |
12501 | int j, nn; | |
12502 | char *name; | |
12503 | char *invalid = _("*invalid*"); | |
12504 | ||
12505 | printf (" %03x:", cnt); | |
12506 | ||
12507 | for (j = 0; (j < 4) && (cnt + j) < total; ++j) | |
12508 | switch (data[cnt + j]) | |
12509 | { | |
12510 | case 0: | |
12511 | fputs (_(" 0 (*local*) "), stdout); | |
12512 | break; | |
12513 | ||
12514 | case 1: | |
12515 | fputs (_(" 1 (*global*) "), stdout); | |
12516 | break; | |
12517 | ||
12518 | default: | |
12519 | nn = printf ("%4x%c", data[cnt + j] & VERSYM_VERSION, | |
12520 | data[cnt + j] & VERSYM_HIDDEN ? 'h' : ' '); | |
12521 | ||
12522 | /* If this index value is greater than the size of the symbols | |
12523 | array, break to avoid an out-of-bounds read. */ | |
12524 | if (cnt + j >= num_syms) | |
12525 | { | |
12526 | warn (_("invalid index into symbol array\n")); | |
12527 | break; | |
12528 | } | |
12529 | ||
12530 | name = NULL; | |
12531 | if (filedata->version_info[DT_VERSIONTAGIDX (DT_VERNEED)]) | |
12532 | { | |
12533 | Elf_Internal_Verneed ivn; | |
12534 | uint64_t offset; | |
12535 | ||
12536 | offset = offset_from_vma | |
12537 | (filedata, | |
12538 | filedata->version_info[DT_VERSIONTAGIDX (DT_VERNEED)], | |
12539 | sizeof (Elf_External_Verneed)); | |
12540 | ||
12541 | do | |
12542 | { | |
12543 | Elf_Internal_Vernaux ivna; | |
12544 | Elf_External_Verneed evn; | |
12545 | Elf_External_Vernaux evna; | |
12546 | uint64_t a_off; | |
12547 | ||
12548 | if (get_data (&evn, filedata, offset, sizeof (evn), 1, | |
12549 | _("version need")) == NULL) | |
12550 | break; | |
12551 | ||
12552 | ivn.vn_aux = BYTE_GET (evn.vn_aux); | |
12553 | ivn.vn_next = BYTE_GET (evn.vn_next); | |
12554 | ||
12555 | a_off = offset + ivn.vn_aux; | |
12556 | ||
12557 | do | |
12558 | { | |
12559 | if (get_data (&evna, filedata, a_off, sizeof (evna), | |
12560 | 1, _("version need aux (2)")) == NULL) | |
12561 | { | |
12562 | ivna.vna_next = 0; | |
12563 | ivna.vna_other = 0; | |
12564 | } | |
12565 | else | |
12566 | { | |
12567 | ivna.vna_next = BYTE_GET (evna.vna_next); | |
12568 | ivna.vna_other = BYTE_GET (evna.vna_other); | |
12569 | } | |
12570 | ||
12571 | a_off += ivna.vna_next; | |
12572 | } | |
12573 | while (ivna.vna_other != data[cnt + j] | |
12574 | && ivna.vna_next != 0); | |
12575 | ||
12576 | if (ivna.vna_other == data[cnt + j]) | |
12577 | { | |
12578 | ivna.vna_name = BYTE_GET (evna.vna_name); | |
12579 | ||
12580 | if (ivna.vna_name >= string_sec->sh_size) | |
12581 | name = invalid; | |
12582 | else | |
12583 | name = strtab + ivna.vna_name; | |
12584 | break; | |
12585 | } | |
12586 | ||
12587 | offset += ivn.vn_next; | |
12588 | } | |
12589 | while (ivn.vn_next); | |
12590 | } | |
12591 | ||
12592 | if (data[cnt + j] != 0x8001 | |
12593 | && filedata->version_info[DT_VERSIONTAGIDX (DT_VERDEF)]) | |
12594 | { | |
12595 | Elf_Internal_Verdef ivd; | |
12596 | Elf_External_Verdef evd; | |
12597 | uint64_t offset; | |
12598 | ||
12599 | offset = offset_from_vma | |
12600 | (filedata, | |
12601 | filedata->version_info[DT_VERSIONTAGIDX (DT_VERDEF)], | |
12602 | sizeof evd); | |
12603 | ||
12604 | do | |
12605 | { | |
12606 | if (get_data (&evd, filedata, offset, sizeof (evd), 1, | |
12607 | _("version def")) == NULL) | |
12608 | { | |
12609 | ivd.vd_next = 0; | |
12610 | /* PR 17531: file: 046-1082287-0.004. */ | |
12611 | ivd.vd_ndx = (data[cnt + j] & VERSYM_VERSION) + 1; | |
12612 | break; | |
12613 | } | |
12614 | else | |
12615 | { | |
12616 | ivd.vd_next = BYTE_GET (evd.vd_next); | |
12617 | ivd.vd_ndx = BYTE_GET (evd.vd_ndx); | |
12618 | } | |
12619 | ||
12620 | offset += ivd.vd_next; | |
12621 | } | |
12622 | while (ivd.vd_ndx != (data[cnt + j] & VERSYM_VERSION) | |
12623 | && ivd.vd_next != 0); | |
12624 | ||
12625 | if (ivd.vd_ndx == (data[cnt + j] & VERSYM_VERSION)) | |
12626 | { | |
12627 | Elf_External_Verdaux evda; | |
12628 | Elf_Internal_Verdaux ivda; | |
12629 | ||
12630 | ivd.vd_aux = BYTE_GET (evd.vd_aux); | |
12631 | ||
12632 | if (get_data (&evda, filedata, | |
12633 | offset - ivd.vd_next + ivd.vd_aux, | |
12634 | sizeof (evda), 1, | |
12635 | _("version def aux")) == NULL) | |
12636 | break; | |
12637 | ||
12638 | ivda.vda_name = BYTE_GET (evda.vda_name); | |
12639 | ||
12640 | if (ivda.vda_name >= string_sec->sh_size) | |
12641 | name = invalid; | |
12642 | else if (name != NULL && name != invalid) | |
12643 | name = _("*both*"); | |
12644 | else | |
12645 | name = strtab + ivda.vda_name; | |
12646 | } | |
12647 | } | |
12648 | if (name != NULL) | |
12649 | nn += printf ("(%s%-*s", | |
12650 | name, | |
12651 | 12 - (int) strlen (name), | |
12652 | ")"); | |
12653 | ||
12654 | if (nn < 18) | |
12655 | printf ("%*c", 18 - nn, ' '); | |
12656 | } | |
12657 | ||
12658 | putchar ('\n'); | |
12659 | } | |
12660 | ||
12661 | free (data); | |
12662 | free (strtab); | |
12663 | free (symbols); | |
12664 | } | |
12665 | break; | |
12666 | ||
12667 | default: | |
12668 | break; | |
12669 | } | |
12670 | } | |
12671 | ||
12672 | if (! found) | |
12673 | { | |
12674 | if (filedata->is_separate) | |
12675 | printf (_("\nNo version information found in linked file '%s'.\n"), | |
12676 | filedata->file_name); | |
12677 | else | |
12678 | printf (_("\nNo version information found in this file.\n")); | |
12679 | } | |
12680 | ||
12681 | return true; | |
12682 | } | |
12683 | ||
12684 | static const char * | |
12685 | get_symbol_binding (Filedata * filedata, unsigned int binding) | |
12686 | { | |
12687 | static char buff[64]; | |
12688 | ||
12689 | switch (binding) | |
12690 | { | |
12691 | case STB_LOCAL: return "LOCAL"; | |
12692 | case STB_GLOBAL: return "GLOBAL"; | |
12693 | case STB_WEAK: return "WEAK"; | |
12694 | default: | |
12695 | if (binding >= STB_LOPROC && binding <= STB_HIPROC) | |
12696 | snprintf (buff, sizeof (buff), _("<processor specific>: %d"), | |
12697 | binding); | |
12698 | else if (binding >= STB_LOOS && binding <= STB_HIOS) | |
12699 | { | |
12700 | if (binding == STB_GNU_UNIQUE | |
12701 | && filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_GNU) | |
12702 | return "UNIQUE"; | |
12703 | snprintf (buff, sizeof (buff), _("<OS specific>: %d"), binding); | |
12704 | } | |
12705 | else | |
12706 | snprintf (buff, sizeof (buff), _("<unknown>: %d"), binding); | |
12707 | return buff; | |
12708 | } | |
12709 | } | |
12710 | ||
12711 | static const char * | |
12712 | get_symbol_type (Filedata * filedata, unsigned int type) | |
12713 | { | |
12714 | static char buff[64]; | |
12715 | ||
12716 | switch (type) | |
12717 | { | |
12718 | case STT_NOTYPE: return "NOTYPE"; | |
12719 | case STT_OBJECT: return "OBJECT"; | |
12720 | case STT_FUNC: return "FUNC"; | |
12721 | case STT_SECTION: return "SECTION"; | |
12722 | case STT_FILE: return "FILE"; | |
12723 | case STT_COMMON: return "COMMON"; | |
12724 | case STT_TLS: return "TLS"; | |
12725 | case STT_RELC: return "RELC"; | |
12726 | case STT_SRELC: return "SRELC"; | |
12727 | default: | |
12728 | if (type >= STT_LOPROC && type <= STT_HIPROC) | |
12729 | { | |
12730 | if (filedata->file_header.e_machine == EM_ARM && type == STT_ARM_TFUNC) | |
12731 | return "THUMB_FUNC"; | |
12732 | ||
12733 | if (filedata->file_header.e_machine == EM_SPARCV9 && type == STT_REGISTER) | |
12734 | return "REGISTER"; | |
12735 | ||
12736 | if (filedata->file_header.e_machine == EM_PARISC && type == STT_PARISC_MILLI) | |
12737 | return "PARISC_MILLI"; | |
12738 | ||
12739 | snprintf (buff, sizeof (buff), _("<processor specific>: %d"), type); | |
12740 | } | |
12741 | else if (type >= STT_LOOS && type <= STT_HIOS) | |
12742 | { | |
12743 | if (filedata->file_header.e_machine == EM_PARISC) | |
12744 | { | |
12745 | if (type == STT_HP_OPAQUE) | |
12746 | return "HP_OPAQUE"; | |
12747 | if (type == STT_HP_STUB) | |
12748 | return "HP_STUB"; | |
12749 | } | |
12750 | ||
12751 | if (type == STT_GNU_IFUNC | |
12752 | && (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_GNU | |
12753 | || filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_FREEBSD)) | |
12754 | return "IFUNC"; | |
12755 | ||
12756 | snprintf (buff, sizeof (buff), _("<OS specific>: %d"), type); | |
12757 | } | |
12758 | else | |
12759 | snprintf (buff, sizeof (buff), _("<unknown>: %d"), type); | |
12760 | return buff; | |
12761 | } | |
12762 | } | |
12763 | ||
12764 | static const char * | |
12765 | get_symbol_visibility (unsigned int visibility) | |
12766 | { | |
12767 | switch (visibility) | |
12768 | { | |
12769 | case STV_DEFAULT: return "DEFAULT"; | |
12770 | case STV_INTERNAL: return "INTERNAL"; | |
12771 | case STV_HIDDEN: return "HIDDEN"; | |
12772 | case STV_PROTECTED: return "PROTECTED"; | |
12773 | default: | |
12774 | error (_("Unrecognized visibility value: %u\n"), visibility); | |
12775 | return _("<unknown>"); | |
12776 | } | |
12777 | } | |
12778 | ||
12779 | static const char * | |
12780 | get_alpha_symbol_other (unsigned int other) | |
12781 | { | |
12782 | switch (other) | |
12783 | { | |
12784 | case STO_ALPHA_NOPV: return "NOPV"; | |
12785 | case STO_ALPHA_STD_GPLOAD: return "STD GPLOAD"; | |
12786 | default: | |
12787 | error (_("Unrecognized alpha specific other value: %u\n"), other); | |
12788 | return _("<unknown>"); | |
12789 | } | |
12790 | } | |
12791 | ||
12792 | static const char * | |
12793 | get_solaris_symbol_visibility (unsigned int visibility) | |
12794 | { | |
12795 | switch (visibility) | |
12796 | { | |
12797 | case 4: return "EXPORTED"; | |
12798 | case 5: return "SINGLETON"; | |
12799 | case 6: return "ELIMINATE"; | |
12800 | default: return get_symbol_visibility (visibility); | |
12801 | } | |
12802 | } | |
12803 | ||
12804 | static const char * | |
12805 | get_aarch64_symbol_other (unsigned int other) | |
12806 | { | |
12807 | static char buf[32]; | |
12808 | ||
12809 | if (other & STO_AARCH64_VARIANT_PCS) | |
12810 | { | |
12811 | other &= ~STO_AARCH64_VARIANT_PCS; | |
12812 | if (other == 0) | |
12813 | return "VARIANT_PCS"; | |
12814 | snprintf (buf, sizeof buf, "VARIANT_PCS | %x", other); | |
12815 | return buf; | |
12816 | } | |
12817 | return NULL; | |
12818 | } | |
12819 | ||
12820 | static const char * | |
12821 | get_mips_symbol_other (unsigned int other) | |
12822 | { | |
12823 | switch (other) | |
12824 | { | |
12825 | case STO_OPTIONAL: return "OPTIONAL"; | |
12826 | case STO_MIPS_PLT: return "MIPS PLT"; | |
12827 | case STO_MIPS_PIC: return "MIPS PIC"; | |
12828 | case STO_MICROMIPS: return "MICROMIPS"; | |
12829 | case STO_MICROMIPS | STO_MIPS_PIC: return "MICROMIPS, MIPS PIC"; | |
12830 | case STO_MIPS16: return "MIPS16"; | |
12831 | default: return NULL; | |
12832 | } | |
12833 | } | |
12834 | ||
12835 | static const char * | |
12836 | get_ia64_symbol_other (Filedata * filedata, unsigned int other) | |
12837 | { | |
12838 | if (is_ia64_vms (filedata)) | |
12839 | { | |
12840 | static char res[32]; | |
12841 | ||
12842 | res[0] = 0; | |
12843 | ||
12844 | /* Function types is for images and .STB files only. */ | |
12845 | switch (filedata->file_header.e_type) | |
12846 | { | |
12847 | case ET_DYN: | |
12848 | case ET_EXEC: | |
12849 | switch (VMS_ST_FUNC_TYPE (other)) | |
12850 | { | |
12851 | case VMS_SFT_CODE_ADDR: | |
12852 | strcat (res, " CA"); | |
12853 | break; | |
12854 | case VMS_SFT_SYMV_IDX: | |
12855 | strcat (res, " VEC"); | |
12856 | break; | |
12857 | case VMS_SFT_FD: | |
12858 | strcat (res, " FD"); | |
12859 | break; | |
12860 | case VMS_SFT_RESERVE: | |
12861 | strcat (res, " RSV"); | |
12862 | break; | |
12863 | default: | |
12864 | warn (_("Unrecognized IA64 VMS ST Function type: %d\n"), | |
12865 | VMS_ST_FUNC_TYPE (other)); | |
12866 | strcat (res, " <unknown>"); | |
12867 | break; | |
12868 | } | |
12869 | break; | |
12870 | default: | |
12871 | break; | |
12872 | } | |
12873 | switch (VMS_ST_LINKAGE (other)) | |
12874 | { | |
12875 | case VMS_STL_IGNORE: | |
12876 | strcat (res, " IGN"); | |
12877 | break; | |
12878 | case VMS_STL_RESERVE: | |
12879 | strcat (res, " RSV"); | |
12880 | break; | |
12881 | case VMS_STL_STD: | |
12882 | strcat (res, " STD"); | |
12883 | break; | |
12884 | case VMS_STL_LNK: | |
12885 | strcat (res, " LNK"); | |
12886 | break; | |
12887 | default: | |
12888 | warn (_("Unrecognized IA64 VMS ST Linkage: %d\n"), | |
12889 | VMS_ST_LINKAGE (other)); | |
12890 | strcat (res, " <unknown>"); | |
12891 | break; | |
12892 | } | |
12893 | ||
12894 | if (res[0] != 0) | |
12895 | return res + 1; | |
12896 | else | |
12897 | return res; | |
12898 | } | |
12899 | return NULL; | |
12900 | } | |
12901 | ||
12902 | static const char * | |
12903 | get_ppc64_symbol_other (unsigned int other) | |
12904 | { | |
12905 | if ((other & ~STO_PPC64_LOCAL_MASK) != 0) | |
12906 | return NULL; | |
12907 | ||
12908 | other >>= STO_PPC64_LOCAL_BIT; | |
12909 | if (other <= 6) | |
12910 | { | |
12911 | static char buf[64]; | |
12912 | if (other >= 2) | |
12913 | other = ppc64_decode_local_entry (other); | |
12914 | snprintf (buf, sizeof buf, _("<localentry>: %d"), other); | |
12915 | return buf; | |
12916 | } | |
12917 | return NULL; | |
12918 | } | |
12919 | ||
12920 | static const char * | |
12921 | get_riscv_symbol_other (unsigned int other) | |
12922 | { | |
12923 | static char buf[32]; | |
12924 | buf[0] = 0; | |
12925 | ||
12926 | if (other & STO_RISCV_VARIANT_CC) | |
12927 | { | |
12928 | strcat (buf, _(" VARIANT_CC")); | |
12929 | other &= ~STO_RISCV_VARIANT_CC; | |
12930 | } | |
12931 | ||
12932 | if (other != 0) | |
12933 | snprintf (buf, sizeof buf, " %x", other); | |
12934 | ||
12935 | ||
12936 | if (buf[0] != 0) | |
12937 | return buf + 1; | |
12938 | else | |
12939 | return buf; | |
12940 | } | |
12941 | ||
12942 | static const char * | |
12943 | get_symbol_other (Filedata * filedata, unsigned int other) | |
12944 | { | |
12945 | const char * result = NULL; | |
12946 | static char buff [64]; | |
12947 | ||
12948 | if (other == 0) | |
12949 | return ""; | |
12950 | ||
12951 | switch (filedata->file_header.e_machine) | |
12952 | { | |
12953 | case EM_ALPHA: | |
12954 | result = get_alpha_symbol_other (other); | |
12955 | break; | |
12956 | case EM_AARCH64: | |
12957 | result = get_aarch64_symbol_other (other); | |
12958 | break; | |
12959 | case EM_MIPS: | |
12960 | result = get_mips_symbol_other (other); | |
12961 | break; | |
12962 | case EM_IA_64: | |
12963 | result = get_ia64_symbol_other (filedata, other); | |
12964 | break; | |
12965 | case EM_PPC64: | |
12966 | result = get_ppc64_symbol_other (other); | |
12967 | break; | |
12968 | case EM_RISCV: | |
12969 | result = get_riscv_symbol_other (other); | |
12970 | break; | |
12971 | default: | |
12972 | result = NULL; | |
12973 | break; | |
12974 | } | |
12975 | ||
12976 | if (result) | |
12977 | return result; | |
12978 | ||
12979 | snprintf (buff, sizeof buff, _("<other>: %x"), other); | |
12980 | return buff; | |
12981 | } | |
12982 | ||
12983 | static const char * | |
12984 | get_symbol_index_type (Filedata * filedata, unsigned int type) | |
12985 | { | |
12986 | static char buff[32]; | |
12987 | ||
12988 | switch (type) | |
12989 | { | |
12990 | case SHN_UNDEF: return "UND"; | |
12991 | case SHN_ABS: return "ABS"; | |
12992 | case SHN_COMMON: return "COM"; | |
12993 | default: | |
12994 | if (type == SHN_IA_64_ANSI_COMMON | |
12995 | && filedata->file_header.e_machine == EM_IA_64 | |
12996 | && filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_HPUX) | |
12997 | return "ANSI_COM"; | |
12998 | else if ((filedata->file_header.e_machine == EM_X86_64 | |
12999 | || filedata->file_header.e_machine == EM_L1OM | |
13000 | || filedata->file_header.e_machine == EM_K1OM) | |
13001 | && type == SHN_X86_64_LCOMMON) | |
13002 | return "LARGE_COM"; | |
13003 | else if ((type == SHN_MIPS_SCOMMON | |
13004 | && filedata->file_header.e_machine == EM_MIPS) | |
13005 | || (type == SHN_TIC6X_SCOMMON | |
13006 | && filedata->file_header.e_machine == EM_TI_C6000)) | |
13007 | return "SCOM"; | |
13008 | else if (type == SHN_MIPS_SUNDEFINED | |
13009 | && filedata->file_header.e_machine == EM_MIPS) | |
13010 | return "SUND"; | |
13011 | else if (type >= SHN_LOPROC && type <= SHN_HIPROC) | |
13012 | sprintf (buff, "PRC[0x%04x]", type & 0xffff); | |
13013 | else if (type >= SHN_LOOS && type <= SHN_HIOS) | |
13014 | sprintf (buff, "OS [0x%04x]", type & 0xffff); | |
13015 | else if (type >= SHN_LORESERVE) | |
13016 | sprintf (buff, "RSV[0x%04x]", type & 0xffff); | |
13017 | else if (filedata->file_header.e_shnum != 0 | |
13018 | && type >= filedata->file_header.e_shnum) | |
13019 | sprintf (buff, _("bad section index[%3d]"), type); | |
13020 | else | |
13021 | sprintf (buff, "%3d", type); | |
13022 | break; | |
13023 | } | |
13024 | ||
13025 | return buff; | |
13026 | } | |
13027 | ||
13028 | static const char * | |
13029 | get_symbol_version_string (Filedata *filedata, | |
13030 | bool is_dynsym, | |
13031 | const char *strtab, | |
13032 | size_t strtab_size, | |
13033 | unsigned int si, | |
13034 | Elf_Internal_Sym *psym, | |
13035 | enum versioned_symbol_info *sym_info, | |
13036 | unsigned short *vna_other) | |
13037 | { | |
13038 | unsigned char data[2]; | |
13039 | unsigned short vers_data; | |
13040 | uint64_t offset; | |
13041 | unsigned short max_vd_ndx; | |
13042 | ||
13043 | if (!is_dynsym | |
13044 | || filedata->version_info[DT_VERSIONTAGIDX (DT_VERSYM)] == 0) | |
13045 | return NULL; | |
13046 | ||
13047 | offset = offset_from_vma (filedata, | |
13048 | filedata->version_info[DT_VERSIONTAGIDX (DT_VERSYM)], | |
13049 | sizeof data + si * sizeof (vers_data)); | |
13050 | ||
13051 | if (get_data (&data, filedata, offset + si * sizeof (vers_data), | |
13052 | sizeof (data), 1, _("version data")) == NULL) | |
13053 | return NULL; | |
13054 | ||
13055 | vers_data = byte_get (data, 2); | |
13056 | ||
13057 | if ((vers_data & VERSYM_HIDDEN) == 0 && vers_data == 0) | |
13058 | return NULL; | |
13059 | ||
13060 | *sym_info = (vers_data & VERSYM_HIDDEN) != 0 ? symbol_hidden : symbol_public; | |
13061 | max_vd_ndx = 0; | |
13062 | ||
13063 | /* Usually we'd only see verdef for defined symbols, and verneed for | |
13064 | undefined symbols. However, symbols defined by the linker in | |
13065 | .dynbss for variables copied from a shared library in order to | |
13066 | avoid text relocations are defined yet have verneed. We could | |
13067 | use a heuristic to detect the special case, for example, check | |
13068 | for verneed first on symbols defined in SHT_NOBITS sections, but | |
13069 | it is simpler and more reliable to just look for both verdef and | |
13070 | verneed. .dynbss might not be mapped to a SHT_NOBITS section. */ | |
13071 | ||
13072 | if (psym->st_shndx != SHN_UNDEF | |
13073 | && vers_data != 0x8001 | |
13074 | && filedata->version_info[DT_VERSIONTAGIDX (DT_VERDEF)]) | |
13075 | { | |
13076 | Elf_Internal_Verdef ivd; | |
13077 | Elf_Internal_Verdaux ivda; | |
13078 | Elf_External_Verdaux evda; | |
13079 | uint64_t off; | |
13080 | ||
13081 | off = offset_from_vma (filedata, | |
13082 | filedata->version_info[DT_VERSIONTAGIDX (DT_VERDEF)], | |
13083 | sizeof (Elf_External_Verdef)); | |
13084 | ||
13085 | do | |
13086 | { | |
13087 | Elf_External_Verdef evd; | |
13088 | ||
13089 | if (get_data (&evd, filedata, off, sizeof (evd), 1, | |
13090 | _("version def")) == NULL) | |
13091 | { | |
13092 | ivd.vd_ndx = 0; | |
13093 | ivd.vd_aux = 0; | |
13094 | ivd.vd_next = 0; | |
13095 | ivd.vd_flags = 0; | |
13096 | } | |
13097 | else | |
13098 | { | |
13099 | ivd.vd_ndx = BYTE_GET (evd.vd_ndx); | |
13100 | ivd.vd_aux = BYTE_GET (evd.vd_aux); | |
13101 | ivd.vd_next = BYTE_GET (evd.vd_next); | |
13102 | ivd.vd_flags = BYTE_GET (evd.vd_flags); | |
13103 | } | |
13104 | ||
13105 | if ((ivd.vd_ndx & VERSYM_VERSION) > max_vd_ndx) | |
13106 | max_vd_ndx = ivd.vd_ndx & VERSYM_VERSION; | |
13107 | ||
13108 | off += ivd.vd_next; | |
13109 | } | |
13110 | while (ivd.vd_ndx != (vers_data & VERSYM_VERSION) && ivd.vd_next != 0); | |
13111 | ||
13112 | if (ivd.vd_ndx == (vers_data & VERSYM_VERSION)) | |
13113 | { | |
13114 | if (ivd.vd_ndx == 1 && ivd.vd_flags == VER_FLG_BASE) | |
13115 | return NULL; | |
13116 | ||
13117 | off -= ivd.vd_next; | |
13118 | off += ivd.vd_aux; | |
13119 | ||
13120 | if (get_data (&evda, filedata, off, sizeof (evda), 1, | |
13121 | _("version def aux")) != NULL) | |
13122 | { | |
13123 | ivda.vda_name = BYTE_GET (evda.vda_name); | |
13124 | ||
13125 | if (psym->st_name != ivda.vda_name) | |
13126 | return (ivda.vda_name < strtab_size | |
13127 | ? strtab + ivda.vda_name : _("<corrupt>")); | |
13128 | } | |
13129 | } | |
13130 | } | |
13131 | ||
13132 | if (filedata->version_info[DT_VERSIONTAGIDX (DT_VERNEED)]) | |
13133 | { | |
13134 | Elf_External_Verneed evn; | |
13135 | Elf_Internal_Verneed ivn; | |
13136 | Elf_Internal_Vernaux ivna; | |
13137 | ||
13138 | offset = offset_from_vma (filedata, | |
13139 | filedata->version_info[DT_VERSIONTAGIDX (DT_VERNEED)], | |
13140 | sizeof evn); | |
13141 | do | |
13142 | { | |
13143 | uint64_t vna_off; | |
13144 | ||
13145 | if (get_data (&evn, filedata, offset, sizeof (evn), 1, | |
13146 | _("version need")) == NULL) | |
13147 | { | |
13148 | ivna.vna_next = 0; | |
13149 | ivna.vna_other = 0; | |
13150 | ivna.vna_name = 0; | |
13151 | break; | |
13152 | } | |
13153 | ||
13154 | ivn.vn_aux = BYTE_GET (evn.vn_aux); | |
13155 | ivn.vn_next = BYTE_GET (evn.vn_next); | |
13156 | ||
13157 | vna_off = offset + ivn.vn_aux; | |
13158 | ||
13159 | do | |
13160 | { | |
13161 | Elf_External_Vernaux evna; | |
13162 | ||
13163 | if (get_data (&evna, filedata, vna_off, sizeof (evna), 1, | |
13164 | _("version need aux (3)")) == NULL) | |
13165 | { | |
13166 | ivna.vna_next = 0; | |
13167 | ivna.vna_other = 0; | |
13168 | ivna.vna_name = 0; | |
13169 | } | |
13170 | else | |
13171 | { | |
13172 | ivna.vna_other = BYTE_GET (evna.vna_other); | |
13173 | ivna.vna_next = BYTE_GET (evna.vna_next); | |
13174 | ivna.vna_name = BYTE_GET (evna.vna_name); | |
13175 | } | |
13176 | ||
13177 | vna_off += ivna.vna_next; | |
13178 | } | |
13179 | while (ivna.vna_other != vers_data && ivna.vna_next != 0); | |
13180 | ||
13181 | if (ivna.vna_other == vers_data) | |
13182 | break; | |
13183 | ||
13184 | offset += ivn.vn_next; | |
13185 | } | |
13186 | while (ivn.vn_next != 0); | |
13187 | ||
13188 | if (ivna.vna_other == vers_data) | |
13189 | { | |
13190 | *sym_info = symbol_undefined; | |
13191 | *vna_other = ivna.vna_other; | |
13192 | return (ivna.vna_name < strtab_size | |
13193 | ? strtab + ivna.vna_name : _("<corrupt>")); | |
13194 | } | |
13195 | else if ((max_vd_ndx || (vers_data & VERSYM_VERSION) != 1) | |
13196 | && (vers_data & VERSYM_VERSION) > max_vd_ndx) | |
13197 | return _("<corrupt>"); | |
13198 | } | |
13199 | return NULL; | |
13200 | } | |
13201 | ||
13202 | /* Display a symbol size on stdout. Format is based on --sym-base setting. */ | |
13203 | ||
13204 | static unsigned int | |
13205 | print_dynamic_symbol_size (uint64_t vma, int base) | |
13206 | { | |
13207 | switch (base) | |
13208 | { | |
13209 | case 8: | |
13210 | return print_vma (vma, OCTAL_5); | |
13211 | ||
13212 | case 10: | |
13213 | return print_vma (vma, UNSIGNED_5); | |
13214 | ||
13215 | case 16: | |
13216 | return print_vma (vma, PREFIX_HEX_5); | |
13217 | ||
13218 | case 0: | |
13219 | default: | |
13220 | return print_vma (vma, DEC_5); | |
13221 | } | |
13222 | } | |
13223 | ||
13224 | static void | |
13225 | print_dynamic_symbol (Filedata *filedata, uint64_t si, | |
13226 | Elf_Internal_Sym *symtab, | |
13227 | Elf_Internal_Shdr *section, | |
13228 | char *strtab, size_t strtab_size) | |
13229 | { | |
13230 | const char *version_string; | |
13231 | enum versioned_symbol_info sym_info; | |
13232 | unsigned short vna_other; | |
13233 | bool is_valid; | |
13234 | const char * sstr; | |
13235 | Elf_Internal_Sym *psym = symtab + si; | |
13236 | ||
13237 | printf ("%6" PRId64 ": ", si); | |
13238 | print_vma (psym->st_value, LONG_HEX); | |
13239 | putchar (' '); | |
13240 | print_dynamic_symbol_size (psym->st_size, sym_base); | |
13241 | printf (" %-7s", get_symbol_type (filedata, ELF_ST_TYPE (psym->st_info))); | |
13242 | printf (" %-6s", get_symbol_binding (filedata, ELF_ST_BIND (psym->st_info))); | |
13243 | if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS) | |
13244 | printf (" %-7s", get_solaris_symbol_visibility (psym->st_other)); | |
13245 | else | |
13246 | { | |
13247 | unsigned int vis = ELF_ST_VISIBILITY (psym->st_other); | |
13248 | ||
13249 | printf (" %-7s", get_symbol_visibility (vis)); | |
13250 | /* Check to see if any other bits in the st_other field are set. | |
13251 | Note - displaying this information disrupts the layout of the | |
13252 | table being generated, but for the moment this case is very rare. */ | |
13253 | if (psym->st_other ^ vis) | |
13254 | printf (" [%s] ", get_symbol_other (filedata, psym->st_other ^ vis)); | |
13255 | } | |
13256 | printf (" %4s ", get_symbol_index_type (filedata, psym->st_shndx)); | |
13257 | ||
13258 | if (ELF_ST_TYPE (psym->st_info) == STT_SECTION | |
13259 | && psym->st_shndx < filedata->file_header.e_shnum | |
13260 | && filedata->section_headers != NULL | |
13261 | && psym->st_name == 0) | |
13262 | { | |
13263 | is_valid | |
13264 | = section_name_valid (filedata, | |
13265 | filedata->section_headers + psym->st_shndx); | |
13266 | sstr = is_valid ? | |
13267 | section_name_print (filedata, | |
13268 | filedata->section_headers + psym->st_shndx) | |
13269 | : _("<corrupt>"); | |
13270 | } | |
13271 | else | |
13272 | { | |
13273 | is_valid = valid_symbol_name (strtab, strtab_size, psym->st_name); | |
13274 | sstr = is_valid ? strtab + psym->st_name : _("<corrupt>"); | |
13275 | } | |
13276 | ||
13277 | version_string | |
13278 | = get_symbol_version_string (filedata, | |
13279 | (section == NULL | |
13280 | || section->sh_type == SHT_DYNSYM), | |
13281 | strtab, strtab_size, si, | |
13282 | psym, &sym_info, &vna_other); | |
13283 | ||
13284 | int len_avail = 21; | |
13285 | if (! do_wide && version_string != NULL) | |
13286 | { | |
13287 | char buffer[16]; | |
13288 | ||
13289 | len_avail -= 1 + strlen (version_string); | |
13290 | ||
13291 | if (sym_info == symbol_undefined) | |
13292 | len_avail -= sprintf (buffer," (%d)", vna_other); | |
13293 | else if (sym_info != symbol_hidden) | |
13294 | len_avail -= 1; | |
13295 | } | |
13296 | ||
13297 | print_symbol (len_avail, sstr); | |
13298 | ||
13299 | if (version_string) | |
13300 | { | |
13301 | if (sym_info == symbol_undefined) | |
13302 | printf ("@%s (%d)", version_string, vna_other); | |
13303 | else | |
13304 | printf (sym_info == symbol_hidden ? "@%s" : "@@%s", | |
13305 | version_string); | |
13306 | } | |
13307 | ||
13308 | putchar ('\n'); | |
13309 | ||
13310 | if (ELF_ST_BIND (psym->st_info) == STB_LOCAL | |
13311 | && section != NULL | |
13312 | && si >= section->sh_info | |
13313 | /* Irix 5 and 6 MIPS binaries are known to ignore this requirement. */ | |
13314 | && filedata->file_header.e_machine != EM_MIPS | |
13315 | /* Solaris binaries have been found to violate this requirement as | |
13316 | well. Not sure if this is a bug or an ABI requirement. */ | |
13317 | && filedata->file_header.e_ident[EI_OSABI] != ELFOSABI_SOLARIS) | |
13318 | warn (_("local symbol %" PRIu64 " found at index >= %s's sh_info value of %u\n"), | |
13319 | si, printable_section_name (filedata, section), section->sh_info); | |
13320 | } | |
13321 | ||
13322 | static const char * | |
13323 | get_lto_kind (unsigned int kind) | |
13324 | { | |
13325 | switch (kind) | |
13326 | { | |
13327 | case 0: return "DEF"; | |
13328 | case 1: return "WEAKDEF"; | |
13329 | case 2: return "UNDEF"; | |
13330 | case 3: return "WEAKUNDEF"; | |
13331 | case 4: return "COMMON"; | |
13332 | default: | |
13333 | break; | |
13334 | } | |
13335 | ||
13336 | static char buffer[30]; | |
13337 | error (_("Unknown LTO symbol definition encountered: %u\n"), kind); | |
13338 | sprintf (buffer, "<unknown: %u>", kind); | |
13339 | return buffer; | |
13340 | } | |
13341 | ||
13342 | static const char * | |
13343 | get_lto_visibility (unsigned int visibility) | |
13344 | { | |
13345 | switch (visibility) | |
13346 | { | |
13347 | case 0: return "DEFAULT"; | |
13348 | case 1: return "PROTECTED"; | |
13349 | case 2: return "INTERNAL"; | |
13350 | case 3: return "HIDDEN"; | |
13351 | default: | |
13352 | break; | |
13353 | } | |
13354 | ||
13355 | static char buffer[30]; | |
13356 | error (_("Unknown LTO symbol visibility encountered: %u\n"), visibility); | |
13357 | sprintf (buffer, "<unknown: %u>", visibility); | |
13358 | return buffer; | |
13359 | } | |
13360 | ||
13361 | static const char * | |
13362 | get_lto_sym_type (unsigned int sym_type) | |
13363 | { | |
13364 | switch (sym_type) | |
13365 | { | |
13366 | case 0: return "UNKNOWN"; | |
13367 | case 1: return "FUNCTION"; | |
13368 | case 2: return "VARIABLE"; | |
13369 | default: | |
13370 | break; | |
13371 | } | |
13372 | ||
13373 | static char buffer[30]; | |
13374 | error (_("Unknown LTO symbol type encountered: %u\n"), sym_type); | |
13375 | sprintf (buffer, "<unknown: %u>", sym_type); | |
13376 | return buffer; | |
13377 | } | |
13378 | ||
13379 | /* Display an LTO format symbol table. | |
13380 | FIXME: The format of LTO symbol tables is not formalized. | |
13381 | So this code could need changing in the future. */ | |
13382 | ||
13383 | static bool | |
13384 | display_lto_symtab (Filedata * filedata, | |
13385 | Elf_Internal_Shdr * section) | |
13386 | { | |
13387 | if (section->sh_size == 0) | |
13388 | { | |
13389 | if (filedata->is_separate) | |
13390 | printf (_("\nThe LTO Symbol table section '%s' in linked file '%s' is empty!\n"), | |
13391 | printable_section_name (filedata, section), | |
13392 | filedata->file_name); | |
13393 | else | |
13394 | printf (_("\nLTO Symbol table '%s' is empty!\n"), | |
13395 | printable_section_name (filedata, section)); | |
13396 | ||
13397 | return true; | |
13398 | } | |
13399 | ||
13400 | if (section->sh_size > filedata->file_size) | |
13401 | { | |
13402 | error (_("Section %s has an invalid sh_size of %#" PRIx64 "\n"), | |
13403 | printable_section_name (filedata, section), | |
13404 | section->sh_size); | |
13405 | return false; | |
13406 | } | |
13407 | ||
13408 | void * alloced_data = get_data (NULL, filedata, section->sh_offset, | |
13409 | section->sh_size, 1, _("LTO symbols")); | |
13410 | if (alloced_data == NULL) | |
13411 | return false; | |
13412 | ||
13413 | /* Look for extended data for the symbol table. */ | |
13414 | Elf_Internal_Shdr * ext; | |
13415 | void * ext_data_orig = NULL; | |
13416 | char * ext_data = NULL; | |
13417 | char * ext_data_end = NULL; | |
13418 | char * ext_name = NULL; | |
13419 | ||
13420 | if (asprintf (& ext_name, ".gnu.lto_.ext_symtab.%s", | |
13421 | (section_name (filedata, section) | |
13422 | + sizeof (".gnu.lto_.symtab.") - 1)) > 0 | |
13423 | && ext_name != NULL /* Paranoia. */ | |
13424 | && (ext = find_section (filedata, ext_name)) != NULL) | |
13425 | { | |
13426 | if (ext->sh_size < 3) | |
13427 | error (_("LTO Symbol extension table '%s' is empty!\n"), | |
13428 | printable_section_name (filedata, ext)); | |
13429 | else | |
13430 | { | |
13431 | ext_data_orig = ext_data = get_data (NULL, filedata, ext->sh_offset, | |
13432 | ext->sh_size, 1, | |
13433 | _("LTO ext symbol data")); | |
13434 | if (ext_data != NULL) | |
13435 | { | |
13436 | ext_data_end = ext_data + ext->sh_size; | |
13437 | if (* ext_data++ != 1) | |
13438 | error (_("Unexpected version number in symbol extension table\n")); | |
13439 | } | |
13440 | } | |
13441 | } | |
13442 | ||
13443 | const unsigned char * data = (const unsigned char *) alloced_data; | |
13444 | const unsigned char * end = data + section->sh_size; | |
13445 | ||
13446 | if (filedata->is_separate) | |
13447 | printf (_("\nIn linked file '%s': "), filedata->file_name); | |
13448 | else | |
13449 | printf ("\n"); | |
13450 | ||
13451 | if (ext_data_orig != NULL) | |
13452 | { | |
13453 | if (do_wide) | |
13454 | printf (_("LTO Symbol table '%s' and extension table '%s' contain:\n"), | |
13455 | printable_section_name (filedata, section), | |
13456 | printable_section_name (filedata, ext)); | |
13457 | else | |
13458 | { | |
13459 | printf (_("LTO Symbol table '%s'\n"), | |
13460 | printable_section_name (filedata, section)); | |
13461 | printf (_(" and extension table '%s' contain:\n"), | |
13462 | printable_section_name (filedata, ext)); | |
13463 | } | |
13464 | } | |
13465 | else | |
13466 | printf (_("LTO Symbol table '%s' contains:\n"), | |
13467 | printable_section_name (filedata, section)); | |
13468 | ||
13469 | /* FIXME: Add a wide version. */ | |
13470 | if (ext_data_orig != NULL) | |
13471 | printf (_(" Comdat_Key Kind Visibility Size Slot Type Section Name\n")); | |
13472 | else | |
13473 | printf (_(" Comdat_Key Kind Visibility Size Slot Name\n")); | |
13474 | ||
13475 | /* FIXME: We do not handle style prefixes. */ | |
13476 | ||
13477 | while (data < end) | |
13478 | { | |
13479 | const unsigned char * sym_name = data; | |
13480 | data += strnlen ((const char *) sym_name, end - data) + 1; | |
13481 | if (data >= end) | |
13482 | goto fail; | |
13483 | ||
13484 | const unsigned char * comdat_key = data; | |
13485 | data += strnlen ((const char *) comdat_key, end - data) + 1; | |
13486 | if (data >= end) | |
13487 | goto fail; | |
13488 | ||
13489 | if (data + 2 + 8 + 4 > end) | |
13490 | goto fail; | |
13491 | ||
13492 | unsigned int kind = *data++; | |
13493 | unsigned int visibility = *data++; | |
13494 | ||
13495 | uint64_t size = byte_get (data, 8); | |
13496 | data += 8; | |
13497 | ||
13498 | uint64_t slot = byte_get (data, 4); | |
13499 | data += 4; | |
13500 | ||
13501 | if (ext_data != NULL) | |
13502 | { | |
13503 | if (ext_data < (ext_data_end - 1)) | |
13504 | { | |
13505 | unsigned int sym_type = * ext_data ++; | |
13506 | unsigned int sec_kind = * ext_data ++; | |
13507 | ||
13508 | printf (" %10s %10s %11s %08" PRIx64 " %08" PRIx64 " %9s %08x _", | |
13509 | * comdat_key == 0 ? "-" : (char *) comdat_key, | |
13510 | get_lto_kind (kind), | |
13511 | get_lto_visibility (visibility), | |
13512 | size, | |
13513 | slot, | |
13514 | get_lto_sym_type (sym_type), | |
13515 | sec_kind); | |
13516 | print_symbol (6, (const char *) sym_name); | |
13517 | } | |
13518 | else | |
13519 | { | |
13520 | error (_("Ran out of LTO symbol extension data\n")); | |
13521 | ext_data = NULL; | |
13522 | /* FIXME: return FAIL result ? */ | |
13523 | } | |
13524 | } | |
13525 | else | |
13526 | { | |
13527 | printf (" %10s %10s %11s %08" PRIx64 " %08" PRIx64 " _", | |
13528 | * comdat_key == 0 ? "-" : (char *) comdat_key, | |
13529 | get_lto_kind (kind), | |
13530 | get_lto_visibility (visibility), | |
13531 | size, | |
13532 | slot); | |
13533 | print_symbol (21, (const char *) sym_name); | |
13534 | } | |
13535 | putchar ('\n'); | |
13536 | } | |
13537 | ||
13538 | if (ext_data != NULL && ext_data < ext_data_end) | |
13539 | { | |
13540 | error (_("Data remains in the LTO symbol extension table\n")); | |
13541 | goto fail; | |
13542 | } | |
13543 | ||
13544 | free (alloced_data); | |
13545 | free (ext_data_orig); | |
13546 | free (ext_name); | |
13547 | return true; | |
13548 | ||
13549 | fail: | |
13550 | error (_("Buffer overrun encountered whilst decoding LTO symbol table\n")); | |
13551 | free (alloced_data); | |
13552 | free (ext_data_orig); | |
13553 | free (ext_name); | |
13554 | return false; | |
13555 | } | |
13556 | ||
13557 | /* Display LTO symbol tables. */ | |
13558 | ||
13559 | static bool | |
13560 | process_lto_symbol_tables (Filedata * filedata) | |
13561 | { | |
13562 | Elf_Internal_Shdr * section; | |
13563 | unsigned int i; | |
13564 | bool res = true; | |
13565 | ||
13566 | if (!do_lto_syms) | |
13567 | return true; | |
13568 | ||
13569 | if (filedata->section_headers == NULL) | |
13570 | return true; | |
13571 | ||
13572 | for (i = 0, section = filedata->section_headers; | |
13573 | i < filedata->file_header.e_shnum; | |
13574 | i++, section++) | |
13575 | if (section_name_valid (filedata, section) | |
13576 | && startswith (section_name (filedata, section), ".gnu.lto_.symtab.")) | |
13577 | res &= display_lto_symtab (filedata, section); | |
13578 | ||
13579 | return res; | |
13580 | } | |
13581 | ||
13582 | /* Dump the symbol table. */ | |
13583 | ||
13584 | static bool | |
13585 | process_symbol_table (Filedata * filedata) | |
13586 | { | |
13587 | Elf_Internal_Shdr * section; | |
13588 | ||
13589 | if (!do_syms && !do_dyn_syms && !do_histogram) | |
13590 | return true; | |
13591 | ||
13592 | if ((filedata->dynamic_info[DT_HASH] || filedata->dynamic_info_DT_GNU_HASH) | |
13593 | && do_syms | |
13594 | && do_using_dynamic | |
13595 | && filedata->dynamic_strings != NULL | |
13596 | && filedata->dynamic_symbols != NULL) | |
13597 | { | |
13598 | uint64_t si; | |
13599 | ||
13600 | if (filedata->is_separate) | |
13601 | { | |
13602 | printf (ngettext ("\nIn linked file '%s' the dynamic symbol table" | |
13603 | " contains %" PRIu64 " entry:\n", | |
13604 | "\nIn linked file '%s' the dynamic symbol table" | |
13605 | " contains %" PRIu64 " entries:\n", | |
13606 | filedata->num_dynamic_syms), | |
13607 | filedata->file_name, | |
13608 | filedata->num_dynamic_syms); | |
13609 | } | |
13610 | else | |
13611 | { | |
13612 | printf (ngettext ("\nSymbol table for image contains %" PRIu64 | |
13613 | " entry:\n", | |
13614 | "\nSymbol table for image contains %" PRIu64 | |
13615 | " entries:\n", | |
13616 | filedata->num_dynamic_syms), | |
13617 | filedata->num_dynamic_syms); | |
13618 | } | |
13619 | if (is_32bit_elf) | |
13620 | printf (_(" Num: Value Size Type Bind Vis Ndx Name\n")); | |
13621 | else | |
13622 | printf (_(" Num: Value Size Type Bind Vis Ndx Name\n")); | |
13623 | ||
13624 | for (si = 0; si < filedata->num_dynamic_syms; si++) | |
13625 | print_dynamic_symbol (filedata, si, filedata->dynamic_symbols, NULL, | |
13626 | filedata->dynamic_strings, | |
13627 | filedata->dynamic_strings_length); | |
13628 | } | |
13629 | else if ((do_dyn_syms || (do_syms && !do_using_dynamic)) | |
13630 | && filedata->section_headers != NULL) | |
13631 | { | |
13632 | unsigned int i; | |
13633 | ||
13634 | for (i = 0, section = filedata->section_headers; | |
13635 | i < filedata->file_header.e_shnum; | |
13636 | i++, section++) | |
13637 | { | |
13638 | char * strtab = NULL; | |
13639 | uint64_t strtab_size = 0; | |
13640 | Elf_Internal_Sym * symtab; | |
13641 | uint64_t si, num_syms; | |
13642 | ||
13643 | if ((section->sh_type != SHT_SYMTAB | |
13644 | && section->sh_type != SHT_DYNSYM) | |
13645 | || (!do_syms | |
13646 | && section->sh_type == SHT_SYMTAB)) | |
13647 | continue; | |
13648 | ||
13649 | if (section->sh_entsize == 0) | |
13650 | { | |
13651 | printf (_("\nSymbol table '%s' has a sh_entsize of zero!\n"), | |
13652 | printable_section_name (filedata, section)); | |
13653 | continue; | |
13654 | } | |
13655 | ||
13656 | num_syms = section->sh_size / section->sh_entsize; | |
13657 | ||
13658 | if (filedata->is_separate) | |
13659 | printf (ngettext ("\nIn linked file '%s' symbol section '%s'" | |
13660 | " contains %" PRIu64 " entry:\n", | |
13661 | "\nIn linked file '%s' symbol section '%s'" | |
13662 | " contains %" PRIu64 " entries:\n", | |
13663 | num_syms), | |
13664 | filedata->file_name, | |
13665 | printable_section_name (filedata, section), | |
13666 | num_syms); | |
13667 | else | |
13668 | printf (ngettext ("\nSymbol table '%s' contains %" PRIu64 | |
13669 | " entry:\n", | |
13670 | "\nSymbol table '%s' contains %" PRIu64 | |
13671 | " entries:\n", | |
13672 | num_syms), | |
13673 | printable_section_name (filedata, section), | |
13674 | num_syms); | |
13675 | ||
13676 | if (is_32bit_elf) | |
13677 | printf (_(" Num: Value Size Type Bind Vis Ndx Name\n")); | |
13678 | else | |
13679 | printf (_(" Num: Value Size Type Bind Vis Ndx Name\n")); | |
13680 | ||
13681 | symtab = get_elf_symbols (filedata, section, & num_syms); | |
13682 | if (symtab == NULL) | |
13683 | continue; | |
13684 | ||
13685 | if (section->sh_link == filedata->file_header.e_shstrndx) | |
13686 | { | |
13687 | strtab = filedata->string_table; | |
13688 | strtab_size = filedata->string_table_length; | |
13689 | } | |
13690 | else if (section->sh_link < filedata->file_header.e_shnum) | |
13691 | { | |
13692 | Elf_Internal_Shdr * string_sec; | |
13693 | ||
13694 | string_sec = filedata->section_headers + section->sh_link; | |
13695 | ||
13696 | strtab = (char *) get_data (NULL, filedata, string_sec->sh_offset, | |
13697 | 1, string_sec->sh_size, | |
13698 | _("string table")); | |
13699 | strtab_size = strtab != NULL ? string_sec->sh_size : 0; | |
13700 | } | |
13701 | ||
13702 | for (si = 0; si < num_syms; si++) | |
13703 | print_dynamic_symbol (filedata, si, symtab, section, | |
13704 | strtab, strtab_size); | |
13705 | ||
13706 | free (symtab); | |
13707 | if (strtab != filedata->string_table) | |
13708 | free (strtab); | |
13709 | } | |
13710 | } | |
13711 | else if (do_syms) | |
13712 | printf | |
13713 | (_("\nDynamic symbol information is not available for displaying symbols.\n")); | |
13714 | ||
13715 | if (do_histogram && filedata->buckets != NULL) | |
13716 | { | |
13717 | uint64_t *lengths; | |
13718 | uint64_t *counts; | |
13719 | uint64_t hn; | |
13720 | uint64_t si; | |
13721 | uint64_t maxlength = 0; | |
13722 | uint64_t nzero_counts = 0; | |
13723 | uint64_t nsyms = 0; | |
13724 | char *visited; | |
13725 | ||
13726 | printf (ngettext ("\nHistogram for bucket list length " | |
13727 | "(total of %" PRIu64 " bucket):\n", | |
13728 | "\nHistogram for bucket list length " | |
13729 | "(total of %" PRIu64 " buckets):\n", | |
13730 | filedata->nbuckets), | |
13731 | filedata->nbuckets); | |
13732 | ||
13733 | lengths = calloc (filedata->nbuckets, sizeof (*lengths)); | |
13734 | if (lengths == NULL) | |
13735 | { | |
13736 | error (_("Out of memory allocating space for histogram buckets\n")); | |
13737 | goto err_out; | |
13738 | } | |
13739 | visited = xcmalloc (filedata->nchains, 1); | |
13740 | memset (visited, 0, filedata->nchains); | |
13741 | ||
13742 | printf (_(" Length Number %% of total Coverage\n")); | |
13743 | for (hn = 0; hn < filedata->nbuckets; ++hn) | |
13744 | { | |
13745 | for (si = filedata->buckets[hn]; si > 0; si = filedata->chains[si]) | |
13746 | { | |
13747 | ++nsyms; | |
13748 | if (maxlength < ++lengths[hn]) | |
13749 | ++maxlength; | |
13750 | if (si >= filedata->nchains || visited[si]) | |
13751 | { | |
13752 | error (_("histogram chain is corrupt\n")); | |
13753 | break; | |
13754 | } | |
13755 | visited[si] = 1; | |
13756 | } | |
13757 | } | |
13758 | free (visited); | |
13759 | ||
13760 | counts = calloc (maxlength + 1, sizeof (*counts)); | |
13761 | if (counts == NULL) | |
13762 | { | |
13763 | free (lengths); | |
13764 | error (_("Out of memory allocating space for histogram counts\n")); | |
13765 | goto err_out; | |
13766 | } | |
13767 | ||
13768 | for (hn = 0; hn < filedata->nbuckets; ++hn) | |
13769 | ++counts[lengths[hn]]; | |
13770 | ||
13771 | if (filedata->nbuckets > 0) | |
13772 | { | |
13773 | uint64_t i; | |
13774 | printf (" 0 %-10" PRIu64 " (%5.1f%%)\n", | |
13775 | counts[0], (counts[0] * 100.0) / filedata->nbuckets); | |
13776 | for (i = 1; i <= maxlength; ++i) | |
13777 | { | |
13778 | nzero_counts += counts[i] * i; | |
13779 | printf ("%7" PRIu64 " %-10" PRIu64 " (%5.1f%%) %5.1f%%\n", | |
13780 | i, counts[i], (counts[i] * 100.0) / filedata->nbuckets, | |
13781 | (nzero_counts * 100.0) / nsyms); | |
13782 | } | |
13783 | } | |
13784 | ||
13785 | free (counts); | |
13786 | free (lengths); | |
13787 | } | |
13788 | ||
13789 | free (filedata->buckets); | |
13790 | filedata->buckets = NULL; | |
13791 | filedata->nbuckets = 0; | |
13792 | free (filedata->chains); | |
13793 | filedata->chains = NULL; | |
13794 | ||
13795 | if (do_histogram && filedata->gnubuckets != NULL) | |
13796 | { | |
13797 | uint64_t *lengths; | |
13798 | uint64_t *counts; | |
13799 | uint64_t hn; | |
13800 | uint64_t maxlength = 0; | |
13801 | uint64_t nzero_counts = 0; | |
13802 | uint64_t nsyms = 0; | |
13803 | ||
13804 | printf (ngettext ("\nHistogram for `%s' bucket list length " | |
13805 | "(total of %" PRIu64 " bucket):\n", | |
13806 | "\nHistogram for `%s' bucket list length " | |
13807 | "(total of %" PRIu64 " buckets):\n", | |
13808 | filedata->ngnubuckets), | |
13809 | GNU_HASH_SECTION_NAME (filedata), | |
13810 | filedata->ngnubuckets); | |
13811 | ||
13812 | lengths = calloc (filedata->ngnubuckets, sizeof (*lengths)); | |
13813 | if (lengths == NULL) | |
13814 | { | |
13815 | error (_("Out of memory allocating space for gnu histogram buckets\n")); | |
13816 | goto err_out; | |
13817 | } | |
13818 | ||
13819 | printf (_(" Length Number %% of total Coverage\n")); | |
13820 | ||
13821 | for (hn = 0; hn < filedata->ngnubuckets; ++hn) | |
13822 | if (filedata->gnubuckets[hn] != 0) | |
13823 | { | |
13824 | uint64_t off, length = 1; | |
13825 | ||
13826 | for (off = filedata->gnubuckets[hn] - filedata->gnusymidx; | |
13827 | /* PR 17531 file: 010-77222-0.004. */ | |
13828 | off < filedata->ngnuchains | |
13829 | && (filedata->gnuchains[off] & 1) == 0; | |
13830 | ++off) | |
13831 | ++length; | |
13832 | lengths[hn] = length; | |
13833 | if (length > maxlength) | |
13834 | maxlength = length; | |
13835 | nsyms += length; | |
13836 | } | |
13837 | ||
13838 | counts = calloc (maxlength + 1, sizeof (*counts)); | |
13839 | if (counts == NULL) | |
13840 | { | |
13841 | free (lengths); | |
13842 | error (_("Out of memory allocating space for gnu histogram counts\n")); | |
13843 | goto err_out; | |
13844 | } | |
13845 | ||
13846 | for (hn = 0; hn < filedata->ngnubuckets; ++hn) | |
13847 | ++counts[lengths[hn]]; | |
13848 | ||
13849 | if (filedata->ngnubuckets > 0) | |
13850 | { | |
13851 | uint64_t j; | |
13852 | printf (" 0 %-10" PRIu64 " (%5.1f%%)\n", | |
13853 | counts[0], (counts[0] * 100.0) / filedata->ngnubuckets); | |
13854 | for (j = 1; j <= maxlength; ++j) | |
13855 | { | |
13856 | nzero_counts += counts[j] * j; | |
13857 | printf ("%7" PRIu64 " %-10" PRIu64 " (%5.1f%%) %5.1f%%\n", | |
13858 | j, counts[j], (counts[j] * 100.0) / filedata->ngnubuckets, | |
13859 | (nzero_counts * 100.0) / nsyms); | |
13860 | } | |
13861 | } | |
13862 | ||
13863 | free (counts); | |
13864 | free (lengths); | |
13865 | } | |
13866 | free (filedata->gnubuckets); | |
13867 | filedata->gnubuckets = NULL; | |
13868 | filedata->ngnubuckets = 0; | |
13869 | free (filedata->gnuchains); | |
13870 | filedata->gnuchains = NULL; | |
13871 | filedata->ngnuchains = 0; | |
13872 | free (filedata->mipsxlat); | |
13873 | filedata->mipsxlat = NULL; | |
13874 | return true; | |
13875 | ||
13876 | err_out: | |
13877 | free (filedata->gnubuckets); | |
13878 | filedata->gnubuckets = NULL; | |
13879 | filedata->ngnubuckets = 0; | |
13880 | free (filedata->gnuchains); | |
13881 | filedata->gnuchains = NULL; | |
13882 | filedata->ngnuchains = 0; | |
13883 | free (filedata->mipsxlat); | |
13884 | filedata->mipsxlat = NULL; | |
13885 | free (filedata->buckets); | |
13886 | filedata->buckets = NULL; | |
13887 | filedata->nbuckets = 0; | |
13888 | free (filedata->chains); | |
13889 | filedata->chains = NULL; | |
13890 | return false; | |
13891 | } | |
13892 | ||
13893 | static bool | |
13894 | process_syminfo (Filedata * filedata) | |
13895 | { | |
13896 | unsigned int i; | |
13897 | ||
13898 | if (filedata->dynamic_syminfo == NULL | |
13899 | || !do_dynamic) | |
13900 | /* No syminfo, this is ok. */ | |
13901 | return true; | |
13902 | ||
13903 | /* There better should be a dynamic symbol section. */ | |
13904 | if (filedata->dynamic_symbols == NULL || filedata->dynamic_strings == NULL) | |
13905 | return false; | |
13906 | ||
13907 | if (filedata->is_separate) | |
13908 | printf (ngettext ("\nIn linked file '%s: the dynamic info segment at offset %#" PRIx64 " contains %d entry:\n", | |
13909 | "\nIn linked file '%s: the dynamic info segment at offset %#" PRIx64 " contains %d entries:\n", | |
13910 | filedata->dynamic_syminfo_nent), | |
13911 | filedata->file_name, | |
13912 | filedata->dynamic_syminfo_offset, | |
13913 | filedata->dynamic_syminfo_nent); | |
13914 | else | |
13915 | printf (ngettext ("\nDynamic info segment at offset %#" PRIx64 | |
13916 | " contains %d entry:\n", | |
13917 | "\nDynamic info segment at offset %#" PRIx64 | |
13918 | " contains %d entries:\n", | |
13919 | filedata->dynamic_syminfo_nent), | |
13920 | filedata->dynamic_syminfo_offset, | |
13921 | filedata->dynamic_syminfo_nent); | |
13922 | ||
13923 | printf (_(" Num: Name BoundTo Flags\n")); | |
13924 | for (i = 0; i < filedata->dynamic_syminfo_nent; ++i) | |
13925 | { | |
13926 | unsigned short int flags = filedata->dynamic_syminfo[i].si_flags; | |
13927 | ||
13928 | printf ("%4d: ", i); | |
13929 | if (i >= filedata->num_dynamic_syms) | |
13930 | printf (_("<corrupt index>")); | |
13931 | else if (valid_dynamic_name (filedata, filedata->dynamic_symbols[i].st_name)) | |
13932 | print_symbol (30, get_dynamic_name (filedata, | |
13933 | filedata->dynamic_symbols[i].st_name)); | |
13934 | else | |
13935 | printf (_("<corrupt: %19ld>"), filedata->dynamic_symbols[i].st_name); | |
13936 | putchar (' '); | |
13937 | ||
13938 | switch (filedata->dynamic_syminfo[i].si_boundto) | |
13939 | { | |
13940 | case SYMINFO_BT_SELF: | |
13941 | fputs ("SELF ", stdout); | |
13942 | break; | |
13943 | case SYMINFO_BT_PARENT: | |
13944 | fputs ("PARENT ", stdout); | |
13945 | break; | |
13946 | default: | |
13947 | if (filedata->dynamic_syminfo[i].si_boundto > 0 | |
13948 | && filedata->dynamic_syminfo[i].si_boundto < filedata->dynamic_nent | |
13949 | && valid_dynamic_name (filedata, | |
13950 | filedata->dynamic_section[filedata->dynamic_syminfo[i].si_boundto].d_un.d_val)) | |
13951 | { | |
13952 | print_symbol (10, get_dynamic_name (filedata, | |
13953 | filedata->dynamic_section[filedata->dynamic_syminfo[i].si_boundto].d_un.d_val)); | |
13954 | putchar (' ' ); | |
13955 | } | |
13956 | else | |
13957 | printf ("%-10d ", filedata->dynamic_syminfo[i].si_boundto); | |
13958 | break; | |
13959 | } | |
13960 | ||
13961 | if (flags & SYMINFO_FLG_DIRECT) | |
13962 | printf (" DIRECT"); | |
13963 | if (flags & SYMINFO_FLG_PASSTHRU) | |
13964 | printf (" PASSTHRU"); | |
13965 | if (flags & SYMINFO_FLG_COPY) | |
13966 | printf (" COPY"); | |
13967 | if (flags & SYMINFO_FLG_LAZYLOAD) | |
13968 | printf (" LAZYLOAD"); | |
13969 | ||
13970 | puts (""); | |
13971 | } | |
13972 | ||
13973 | return true; | |
13974 | } | |
13975 | ||
13976 | /* A macro which evaluates to TRUE if the region ADDR .. ADDR + NELEM | |
13977 | is contained by the region START .. END. The types of ADDR, START | |
13978 | and END should all be the same. Note both ADDR + NELEM and END | |
13979 | point to just beyond the end of the regions that are being tested. */ | |
13980 | #define IN_RANGE(START,END,ADDR,NELEM) \ | |
13981 | (((ADDR) >= (START)) && ((ADDR) < (END)) && ((ADDR) + (NELEM) <= (END))) | |
13982 | ||
13983 | /* Check to see if the given reloc needs to be handled in a target specific | |
13984 | manner. If so then process the reloc and return TRUE otherwise return | |
13985 | FALSE. | |
13986 | ||
13987 | If called with reloc == NULL, then this is a signal that reloc processing | |
13988 | for the current section has finished, and any saved state should be | |
13989 | discarded. */ | |
13990 | ||
13991 | static bool | |
13992 | target_specific_reloc_handling (Filedata *filedata, | |
13993 | Elf_Internal_Rela *reloc, | |
13994 | unsigned char *start, | |
13995 | unsigned char *end, | |
13996 | Elf_Internal_Sym *symtab, | |
13997 | uint64_t num_syms) | |
13998 | { | |
13999 | unsigned int reloc_type = 0; | |
14000 | uint64_t sym_index = 0; | |
14001 | ||
14002 | if (reloc) | |
14003 | { | |
14004 | reloc_type = get_reloc_type (filedata, reloc->r_info); | |
14005 | sym_index = get_reloc_symindex (reloc->r_info); | |
14006 | } | |
14007 | ||
14008 | switch (filedata->file_header.e_machine) | |
14009 | { | |
14010 | case EM_MSP430: | |
14011 | case EM_MSP430_OLD: | |
14012 | { | |
14013 | static Elf_Internal_Sym * saved_sym = NULL; | |
14014 | ||
14015 | if (reloc == NULL) | |
14016 | { | |
14017 | saved_sym = NULL; | |
14018 | return true; | |
14019 | } | |
14020 | ||
14021 | switch (reloc_type) | |
14022 | { | |
14023 | case 10: /* R_MSP430_SYM_DIFF */ | |
14024 | case 12: /* R_MSP430_GNU_SUB_ULEB128 */ | |
14025 | if (uses_msp430x_relocs (filedata)) | |
14026 | break; | |
14027 | /* Fall through. */ | |
14028 | case 21: /* R_MSP430X_SYM_DIFF */ | |
14029 | case 23: /* R_MSP430X_GNU_SUB_ULEB128 */ | |
14030 | /* PR 21139. */ | |
14031 | if (sym_index >= num_syms) | |
14032 | error (_("MSP430 SYM_DIFF reloc contains invalid symbol index" | |
14033 | " %" PRIu64 "\n"), sym_index); | |
14034 | else | |
14035 | saved_sym = symtab + sym_index; | |
14036 | return true; | |
14037 | ||
14038 | case 1: /* R_MSP430_32 or R_MSP430_ABS32 */ | |
14039 | case 3: /* R_MSP430_16 or R_MSP430_ABS8 */ | |
14040 | goto handle_sym_diff; | |
14041 | ||
14042 | case 5: /* R_MSP430_16_BYTE */ | |
14043 | case 9: /* R_MSP430_8 */ | |
14044 | case 11: /* R_MSP430_GNU_SET_ULEB128 */ | |
14045 | if (uses_msp430x_relocs (filedata)) | |
14046 | break; | |
14047 | goto handle_sym_diff; | |
14048 | ||
14049 | case 2: /* R_MSP430_ABS16 */ | |
14050 | case 15: /* R_MSP430X_ABS16 */ | |
14051 | case 22: /* R_MSP430X_GNU_SET_ULEB128 */ | |
14052 | if (! uses_msp430x_relocs (filedata)) | |
14053 | break; | |
14054 | goto handle_sym_diff; | |
14055 | ||
14056 | handle_sym_diff: | |
14057 | if (saved_sym != NULL) | |
14058 | { | |
14059 | uint64_t value; | |
14060 | unsigned int reloc_size = 0; | |
14061 | int leb_ret = 0; | |
14062 | switch (reloc_type) | |
14063 | { | |
14064 | case 1: /* R_MSP430_32 or R_MSP430_ABS32 */ | |
14065 | reloc_size = 4; | |
14066 | break; | |
14067 | case 11: /* R_MSP430_GNU_SET_ULEB128 */ | |
14068 | case 22: /* R_MSP430X_GNU_SET_ULEB128 */ | |
14069 | if (reloc->r_offset < (size_t) (end - start)) | |
14070 | read_leb128 (start + reloc->r_offset, end, false, | |
14071 | &reloc_size, &leb_ret); | |
14072 | break; | |
14073 | default: | |
14074 | reloc_size = 2; | |
14075 | break; | |
14076 | } | |
14077 | ||
14078 | if (leb_ret != 0 || reloc_size == 0 || reloc_size > 8) | |
14079 | error (_("MSP430 ULEB128 field at %#" PRIx64 | |
14080 | " contains invalid ULEB128 value\n"), | |
14081 | reloc->r_offset); | |
14082 | else if (sym_index >= num_syms) | |
14083 | error (_("MSP430 reloc contains invalid symbol index " | |
14084 | "%" PRIu64 "\n"), | |
14085 | sym_index); | |
14086 | else | |
14087 | { | |
14088 | value = reloc->r_addend + (symtab[sym_index].st_value | |
14089 | - saved_sym->st_value); | |
14090 | ||
14091 | if (IN_RANGE (start, end, start + reloc->r_offset, reloc_size)) | |
14092 | byte_put (start + reloc->r_offset, value, reloc_size); | |
14093 | else | |
14094 | /* PR 21137 */ | |
14095 | error (_("MSP430 sym diff reloc contains invalid offset: " | |
14096 | "%#" PRIx64 "\n"), | |
14097 | reloc->r_offset); | |
14098 | } | |
14099 | ||
14100 | saved_sym = NULL; | |
14101 | return true; | |
14102 | } | |
14103 | break; | |
14104 | ||
14105 | default: | |
14106 | if (saved_sym != NULL) | |
14107 | error (_("Unhandled MSP430 reloc type found after SYM_DIFF reloc\n")); | |
14108 | break; | |
14109 | } | |
14110 | break; | |
14111 | } | |
14112 | ||
14113 | case EM_MN10300: | |
14114 | case EM_CYGNUS_MN10300: | |
14115 | { | |
14116 | static Elf_Internal_Sym * saved_sym = NULL; | |
14117 | ||
14118 | if (reloc == NULL) | |
14119 | { | |
14120 | saved_sym = NULL; | |
14121 | return true; | |
14122 | } | |
14123 | ||
14124 | switch (reloc_type) | |
14125 | { | |
14126 | case 34: /* R_MN10300_ALIGN */ | |
14127 | return true; | |
14128 | case 33: /* R_MN10300_SYM_DIFF */ | |
14129 | if (sym_index >= num_syms) | |
14130 | error (_("MN10300_SYM_DIFF reloc contains invalid symbol index " | |
14131 | "%" PRIu64 "\n"), | |
14132 | sym_index); | |
14133 | else | |
14134 | saved_sym = symtab + sym_index; | |
14135 | return true; | |
14136 | ||
14137 | case 1: /* R_MN10300_32 */ | |
14138 | case 2: /* R_MN10300_16 */ | |
14139 | if (saved_sym != NULL) | |
14140 | { | |
14141 | int reloc_size = reloc_type == 1 ? 4 : 2; | |
14142 | uint64_t value; | |
14143 | ||
14144 | if (sym_index >= num_syms) | |
14145 | error (_("MN10300 reloc contains invalid symbol index " | |
14146 | "%" PRIu64 "\n"), | |
14147 | sym_index); | |
14148 | else | |
14149 | { | |
14150 | value = reloc->r_addend + (symtab[sym_index].st_value | |
14151 | - saved_sym->st_value); | |
14152 | ||
14153 | if (IN_RANGE (start, end, start + reloc->r_offset, reloc_size)) | |
14154 | byte_put (start + reloc->r_offset, value, reloc_size); | |
14155 | else | |
14156 | error (_("MN10300 sym diff reloc contains invalid offset:" | |
14157 | " %#" PRIx64 "\n"), | |
14158 | reloc->r_offset); | |
14159 | } | |
14160 | ||
14161 | saved_sym = NULL; | |
14162 | return true; | |
14163 | } | |
14164 | break; | |
14165 | default: | |
14166 | if (saved_sym != NULL) | |
14167 | error (_("Unhandled MN10300 reloc type found after SYM_DIFF reloc\n")); | |
14168 | break; | |
14169 | } | |
14170 | break; | |
14171 | } | |
14172 | ||
14173 | case EM_RL78: | |
14174 | { | |
14175 | static uint64_t saved_sym1 = 0; | |
14176 | static uint64_t saved_sym2 = 0; | |
14177 | static uint64_t value; | |
14178 | ||
14179 | if (reloc == NULL) | |
14180 | { | |
14181 | saved_sym1 = saved_sym2 = 0; | |
14182 | return true; | |
14183 | } | |
14184 | ||
14185 | switch (reloc_type) | |
14186 | { | |
14187 | case 0x80: /* R_RL78_SYM. */ | |
14188 | saved_sym1 = saved_sym2; | |
14189 | if (sym_index >= num_syms) | |
14190 | error (_("RL78_SYM reloc contains invalid symbol index " | |
14191 | "%" PRIu64 "\n"), sym_index); | |
14192 | else | |
14193 | { | |
14194 | saved_sym2 = symtab[sym_index].st_value; | |
14195 | saved_sym2 += reloc->r_addend; | |
14196 | } | |
14197 | return true; | |
14198 | ||
14199 | case 0x83: /* R_RL78_OPsub. */ | |
14200 | value = saved_sym1 - saved_sym2; | |
14201 | saved_sym2 = saved_sym1 = 0; | |
14202 | return true; | |
14203 | break; | |
14204 | ||
14205 | case 0x41: /* R_RL78_ABS32. */ | |
14206 | if (IN_RANGE (start, end, start + reloc->r_offset, 4)) | |
14207 | byte_put (start + reloc->r_offset, value, 4); | |
14208 | else | |
14209 | error (_("RL78 sym diff reloc contains invalid offset: " | |
14210 | "%#" PRIx64 "\n"), | |
14211 | reloc->r_offset); | |
14212 | value = 0; | |
14213 | return true; | |
14214 | ||
14215 | case 0x43: /* R_RL78_ABS16. */ | |
14216 | if (IN_RANGE (start, end, start + reloc->r_offset, 2)) | |
14217 | byte_put (start + reloc->r_offset, value, 2); | |
14218 | else | |
14219 | error (_("RL78 sym diff reloc contains invalid offset: " | |
14220 | "%#" PRIx64 "\n"), | |
14221 | reloc->r_offset); | |
14222 | value = 0; | |
14223 | return true; | |
14224 | ||
14225 | default: | |
14226 | break; | |
14227 | } | |
14228 | break; | |
14229 | } | |
14230 | } | |
14231 | ||
14232 | return false; | |
14233 | } | |
14234 | ||
14235 | /* Returns TRUE iff RELOC_TYPE is a 32-bit absolute RELA relocation used in | |
14236 | DWARF debug sections. This is a target specific test. Note - we do not | |
14237 | go through the whole including-target-headers-multiple-times route, (as | |
14238 | we have already done with <elf/h8.h>) because this would become very | |
14239 | messy and even then this function would have to contain target specific | |
14240 | information (the names of the relocs instead of their numeric values). | |
14241 | FIXME: This is not the correct way to solve this problem. The proper way | |
14242 | is to have target specific reloc sizing and typing functions created by | |
14243 | the reloc-macros.h header, in the same way that it already creates the | |
14244 | reloc naming functions. */ | |
14245 | ||
14246 | static bool | |
14247 | is_32bit_abs_reloc (Filedata * filedata, unsigned int reloc_type) | |
14248 | { | |
14249 | /* Please keep this table alpha-sorted for ease of visual lookup. */ | |
14250 | switch (filedata->file_header.e_machine) | |
14251 | { | |
14252 | case EM_386: | |
14253 | case EM_IAMCU: | |
14254 | return reloc_type == 1; /* R_386_32. */ | |
14255 | case EM_68K: | |
14256 | return reloc_type == 1; /* R_68K_32. */ | |
14257 | case EM_860: | |
14258 | return reloc_type == 1; /* R_860_32. */ | |
14259 | case EM_960: | |
14260 | return reloc_type == 2; /* R_960_32. */ | |
14261 | case EM_AARCH64: | |
14262 | return (reloc_type == 258 | |
14263 | || reloc_type == 1); /* R_AARCH64_ABS32 || R_AARCH64_P32_ABS32 */ | |
14264 | case EM_BPF: | |
14265 | return reloc_type == 11; /* R_BPF_DATA_32 */ | |
14266 | case EM_ADAPTEVA_EPIPHANY: | |
14267 | return reloc_type == 3; | |
14268 | case EM_ALPHA: | |
14269 | return reloc_type == 1; /* R_ALPHA_REFLONG. */ | |
14270 | case EM_ARC: | |
14271 | return reloc_type == 1; /* R_ARC_32. */ | |
14272 | case EM_ARC_COMPACT: | |
14273 | case EM_ARC_COMPACT2: | |
14274 | return reloc_type == 4; /* R_ARC_32. */ | |
14275 | case EM_ARM: | |
14276 | return reloc_type == 2; /* R_ARM_ABS32 */ | |
14277 | case EM_AVR_OLD: | |
14278 | case EM_AVR: | |
14279 | return reloc_type == 1; | |
14280 | case EM_BLACKFIN: | |
14281 | return reloc_type == 0x12; /* R_byte4_data. */ | |
14282 | case EM_CRIS: | |
14283 | return reloc_type == 3; /* R_CRIS_32. */ | |
14284 | case EM_CR16: | |
14285 | return reloc_type == 3; /* R_CR16_NUM32. */ | |
14286 | case EM_CRX: | |
14287 | return reloc_type == 15; /* R_CRX_NUM32. */ | |
14288 | case EM_CSKY: | |
14289 | return reloc_type == 1; /* R_CKCORE_ADDR32. */ | |
14290 | case EM_CYGNUS_FRV: | |
14291 | return reloc_type == 1; | |
14292 | case EM_CYGNUS_D10V: | |
14293 | case EM_D10V: | |
14294 | return reloc_type == 6; /* R_D10V_32. */ | |
14295 | case EM_CYGNUS_D30V: | |
14296 | case EM_D30V: | |
14297 | return reloc_type == 12; /* R_D30V_32_NORMAL. */ | |
14298 | case EM_DLX: | |
14299 | return reloc_type == 3; /* R_DLX_RELOC_32. */ | |
14300 | case EM_CYGNUS_FR30: | |
14301 | case EM_FR30: | |
14302 | return reloc_type == 3; /* R_FR30_32. */ | |
14303 | case EM_FT32: | |
14304 | return reloc_type == 1; /* R_FT32_32. */ | |
14305 | case EM_H8S: | |
14306 | case EM_H8_300: | |
14307 | case EM_H8_300H: | |
14308 | return reloc_type == 1; /* R_H8_DIR32. */ | |
14309 | case EM_IA_64: | |
14310 | return (reloc_type == 0x64 /* R_IA64_SECREL32MSB. */ | |
14311 | || reloc_type == 0x65 /* R_IA64_SECREL32LSB. */ | |
14312 | || reloc_type == 0x24 /* R_IA64_DIR32MSB. */ | |
14313 | || reloc_type == 0x25 /* R_IA64_DIR32LSB. */); | |
14314 | case EM_IP2K_OLD: | |
14315 | case EM_IP2K: | |
14316 | return reloc_type == 2; /* R_IP2K_32. */ | |
14317 | case EM_IQ2000: | |
14318 | return reloc_type == 2; /* R_IQ2000_32. */ | |
14319 | case EM_LATTICEMICO32: | |
14320 | return reloc_type == 3; /* R_LM32_32. */ | |
14321 | case EM_LOONGARCH: | |
14322 | return reloc_type == 1; /* R_LARCH_32. */ | |
14323 | case EM_M32C_OLD: | |
14324 | case EM_M32C: | |
14325 | return reloc_type == 3; /* R_M32C_32. */ | |
14326 | case EM_M32R: | |
14327 | return reloc_type == 34; /* R_M32R_32_RELA. */ | |
14328 | case EM_68HC11: | |
14329 | case EM_68HC12: | |
14330 | return reloc_type == 6; /* R_M68HC11_32. */ | |
14331 | case EM_S12Z: | |
14332 | return reloc_type == 7 || /* R_S12Z_EXT32 */ | |
14333 | reloc_type == 6; /* R_S12Z_CW32. */ | |
14334 | case EM_MCORE: | |
14335 | return reloc_type == 1; /* R_MCORE_ADDR32. */ | |
14336 | case EM_CYGNUS_MEP: | |
14337 | return reloc_type == 4; /* R_MEP_32. */ | |
14338 | case EM_METAG: | |
14339 | return reloc_type == 2; /* R_METAG_ADDR32. */ | |
14340 | case EM_MICROBLAZE: | |
14341 | return reloc_type == 1; /* R_MICROBLAZE_32. */ | |
14342 | case EM_MIPS: | |
14343 | return reloc_type == 2; /* R_MIPS_32. */ | |
14344 | case EM_MMIX: | |
14345 | return reloc_type == 4; /* R_MMIX_32. */ | |
14346 | case EM_CYGNUS_MN10200: | |
14347 | case EM_MN10200: | |
14348 | return reloc_type == 1; /* R_MN10200_32. */ | |
14349 | case EM_CYGNUS_MN10300: | |
14350 | case EM_MN10300: | |
14351 | return reloc_type == 1; /* R_MN10300_32. */ | |
14352 | case EM_MOXIE: | |
14353 | return reloc_type == 1; /* R_MOXIE_32. */ | |
14354 | case EM_MSP430_OLD: | |
14355 | case EM_MSP430: | |
14356 | return reloc_type == 1; /* R_MSP430_32 or R_MSP320_ABS32. */ | |
14357 | case EM_MT: | |
14358 | return reloc_type == 2; /* R_MT_32. */ | |
14359 | case EM_NDS32: | |
14360 | return reloc_type == 20; /* R_NDS32_32_RELA. */ | |
14361 | case EM_ALTERA_NIOS2: | |
14362 | return reloc_type == 12; /* R_NIOS2_BFD_RELOC_32. */ | |
14363 | case EM_NIOS32: | |
14364 | return reloc_type == 1; /* R_NIOS_32. */ | |
14365 | case EM_OR1K: | |
14366 | return reloc_type == 1; /* R_OR1K_32. */ | |
14367 | case EM_PARISC: | |
14368 | return (reloc_type == 1 /* R_PARISC_DIR32. */ | |
14369 | || reloc_type == 2 /* R_PARISC_DIR21L. */ | |
14370 | || reloc_type == 41); /* R_PARISC_SECREL32. */ | |
14371 | case EM_PJ: | |
14372 | case EM_PJ_OLD: | |
14373 | return reloc_type == 1; /* R_PJ_DATA_DIR32. */ | |
14374 | case EM_PPC64: | |
14375 | return reloc_type == 1; /* R_PPC64_ADDR32. */ | |
14376 | case EM_PPC: | |
14377 | return reloc_type == 1; /* R_PPC_ADDR32. */ | |
14378 | case EM_TI_PRU: | |
14379 | return reloc_type == 11; /* R_PRU_BFD_RELOC_32. */ | |
14380 | case EM_RISCV: | |
14381 | return reloc_type == 1; /* R_RISCV_32. */ | |
14382 | case EM_RL78: | |
14383 | return reloc_type == 1; /* R_RL78_DIR32. */ | |
14384 | case EM_RX: | |
14385 | return reloc_type == 1; /* R_RX_DIR32. */ | |
14386 | case EM_S370: | |
14387 | return reloc_type == 1; /* R_I370_ADDR31. */ | |
14388 | case EM_S390_OLD: | |
14389 | case EM_S390: | |
14390 | return reloc_type == 4; /* R_S390_32. */ | |
14391 | case EM_SCORE: | |
14392 | return reloc_type == 8; /* R_SCORE_ABS32. */ | |
14393 | case EM_SH: | |
14394 | return reloc_type == 1; /* R_SH_DIR32. */ | |
14395 | case EM_SPARC32PLUS: | |
14396 | case EM_SPARCV9: | |
14397 | case EM_SPARC: | |
14398 | return reloc_type == 3 /* R_SPARC_32. */ | |
14399 | || reloc_type == 23; /* R_SPARC_UA32. */ | |
14400 | case EM_SPU: | |
14401 | return reloc_type == 6; /* R_SPU_ADDR32 */ | |
14402 | case EM_TI_C6000: | |
14403 | return reloc_type == 1; /* R_C6000_ABS32. */ | |
14404 | case EM_TILEGX: | |
14405 | return reloc_type == 2; /* R_TILEGX_32. */ | |
14406 | case EM_TILEPRO: | |
14407 | return reloc_type == 1; /* R_TILEPRO_32. */ | |
14408 | case EM_CYGNUS_V850: | |
14409 | case EM_V850: | |
14410 | return reloc_type == 6; /* R_V850_ABS32. */ | |
14411 | case EM_V800: | |
14412 | return reloc_type == 0x33; /* R_V810_WORD. */ | |
14413 | case EM_VAX: | |
14414 | return reloc_type == 1; /* R_VAX_32. */ | |
14415 | case EM_VISIUM: | |
14416 | return reloc_type == 3; /* R_VISIUM_32. */ | |
14417 | case EM_WEBASSEMBLY: | |
14418 | return reloc_type == 1; /* R_WASM32_32. */ | |
14419 | case EM_X86_64: | |
14420 | case EM_L1OM: | |
14421 | case EM_K1OM: | |
14422 | return reloc_type == 10; /* R_X86_64_32. */ | |
14423 | case EM_XGATE: | |
14424 | return reloc_type == 4; /* R_XGATE_32. */ | |
14425 | case EM_XSTORMY16: | |
14426 | return reloc_type == 1; /* R_XSTROMY16_32. */ | |
14427 | case EM_XTENSA_OLD: | |
14428 | case EM_XTENSA: | |
14429 | return reloc_type == 1; /* R_XTENSA_32. */ | |
14430 | case EM_Z80: | |
14431 | return reloc_type == 6; /* R_Z80_32. */ | |
14432 | default: | |
14433 | { | |
14434 | static unsigned int prev_warn = 0; | |
14435 | ||
14436 | /* Avoid repeating the same warning multiple times. */ | |
14437 | if (prev_warn != filedata->file_header.e_machine) | |
14438 | error (_("Missing knowledge of 32-bit reloc types used in DWARF sections of machine number %d\n"), | |
14439 | filedata->file_header.e_machine); | |
14440 | prev_warn = filedata->file_header.e_machine; | |
14441 | return false; | |
14442 | } | |
14443 | } | |
14444 | } | |
14445 | ||
14446 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
14447 | a 32-bit pc-relative RELA relocation used in DWARF debug sections. */ | |
14448 | ||
14449 | static bool | |
14450 | is_32bit_pcrel_reloc (Filedata * filedata, unsigned int reloc_type) | |
14451 | { | |
14452 | switch (filedata->file_header.e_machine) | |
14453 | /* Please keep this table alpha-sorted for ease of visual lookup. */ | |
14454 | { | |
14455 | case EM_386: | |
14456 | case EM_IAMCU: | |
14457 | return reloc_type == 2; /* R_386_PC32. */ | |
14458 | case EM_68K: | |
14459 | return reloc_type == 4; /* R_68K_PC32. */ | |
14460 | case EM_AARCH64: | |
14461 | return reloc_type == 261; /* R_AARCH64_PREL32 */ | |
14462 | case EM_ADAPTEVA_EPIPHANY: | |
14463 | return reloc_type == 6; | |
14464 | case EM_ALPHA: | |
14465 | return reloc_type == 10; /* R_ALPHA_SREL32. */ | |
14466 | case EM_ARC_COMPACT: | |
14467 | case EM_ARC_COMPACT2: | |
14468 | return reloc_type == 49; /* R_ARC_32_PCREL. */ | |
14469 | case EM_ARM: | |
14470 | return reloc_type == 3; /* R_ARM_REL32 */ | |
14471 | case EM_AVR_OLD: | |
14472 | case EM_AVR: | |
14473 | return reloc_type == 36; /* R_AVR_32_PCREL. */ | |
14474 | case EM_LOONGARCH: | |
14475 | return reloc_type == 99; /* R_LARCH_32_PCREL. */ | |
14476 | case EM_MICROBLAZE: | |
14477 | return reloc_type == 2; /* R_MICROBLAZE_32_PCREL. */ | |
14478 | case EM_OR1K: | |
14479 | return reloc_type == 9; /* R_OR1K_32_PCREL. */ | |
14480 | case EM_PARISC: | |
14481 | return reloc_type == 9; /* R_PARISC_PCREL32. */ | |
14482 | case EM_PPC: | |
14483 | return reloc_type == 26; /* R_PPC_REL32. */ | |
14484 | case EM_PPC64: | |
14485 | return reloc_type == 26; /* R_PPC64_REL32. */ | |
14486 | case EM_RISCV: | |
14487 | return reloc_type == 57; /* R_RISCV_32_PCREL. */ | |
14488 | case EM_S390_OLD: | |
14489 | case EM_S390: | |
14490 | return reloc_type == 5; /* R_390_PC32. */ | |
14491 | case EM_SH: | |
14492 | return reloc_type == 2; /* R_SH_REL32. */ | |
14493 | case EM_SPARC32PLUS: | |
14494 | case EM_SPARCV9: | |
14495 | case EM_SPARC: | |
14496 | return reloc_type == 6; /* R_SPARC_DISP32. */ | |
14497 | case EM_SPU: | |
14498 | return reloc_type == 13; /* R_SPU_REL32. */ | |
14499 | case EM_TILEGX: | |
14500 | return reloc_type == 6; /* R_TILEGX_32_PCREL. */ | |
14501 | case EM_TILEPRO: | |
14502 | return reloc_type == 4; /* R_TILEPRO_32_PCREL. */ | |
14503 | case EM_VISIUM: | |
14504 | return reloc_type == 6; /* R_VISIUM_32_PCREL */ | |
14505 | case EM_X86_64: | |
14506 | case EM_L1OM: | |
14507 | case EM_K1OM: | |
14508 | return reloc_type == 2; /* R_X86_64_PC32. */ | |
14509 | case EM_VAX: | |
14510 | return reloc_type == 4; /* R_VAX_PCREL32. */ | |
14511 | case EM_XTENSA_OLD: | |
14512 | case EM_XTENSA: | |
14513 | return reloc_type == 14; /* R_XTENSA_32_PCREL. */ | |
14514 | default: | |
14515 | /* Do not abort or issue an error message here. Not all targets use | |
14516 | pc-relative 32-bit relocs in their DWARF debug information and we | |
14517 | have already tested for target coverage in is_32bit_abs_reloc. A | |
14518 | more helpful warning message will be generated by apply_relocations | |
14519 | anyway, so just return. */ | |
14520 | return false; | |
14521 | } | |
14522 | } | |
14523 | ||
14524 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
14525 | a 64-bit absolute RELA relocation used in DWARF debug sections. */ | |
14526 | ||
14527 | static bool | |
14528 | is_64bit_abs_reloc (Filedata * filedata, unsigned int reloc_type) | |
14529 | { | |
14530 | switch (filedata->file_header.e_machine) | |
14531 | { | |
14532 | case EM_AARCH64: | |
14533 | return reloc_type == 257; /* R_AARCH64_ABS64. */ | |
14534 | case EM_ALPHA: | |
14535 | return reloc_type == 2; /* R_ALPHA_REFQUAD. */ | |
14536 | case EM_IA_64: | |
14537 | return (reloc_type == 0x26 /* R_IA64_DIR64MSB. */ | |
14538 | || reloc_type == 0x27 /* R_IA64_DIR64LSB. */); | |
14539 | case EM_LOONGARCH: | |
14540 | return reloc_type == 2; /* R_LARCH_64 */ | |
14541 | case EM_PARISC: | |
14542 | return reloc_type == 80; /* R_PARISC_DIR64. */ | |
14543 | case EM_PPC64: | |
14544 | return reloc_type == 38; /* R_PPC64_ADDR64. */ | |
14545 | case EM_RISCV: | |
14546 | return reloc_type == 2; /* R_RISCV_64. */ | |
14547 | case EM_SPARC32PLUS: | |
14548 | case EM_SPARCV9: | |
14549 | case EM_SPARC: | |
14550 | return reloc_type == 32 /* R_SPARC_64. */ | |
14551 | || reloc_type == 54; /* R_SPARC_UA64. */ | |
14552 | case EM_X86_64: | |
14553 | case EM_L1OM: | |
14554 | case EM_K1OM: | |
14555 | return reloc_type == 1; /* R_X86_64_64. */ | |
14556 | case EM_S390_OLD: | |
14557 | case EM_S390: | |
14558 | return reloc_type == 22; /* R_S390_64. */ | |
14559 | case EM_TILEGX: | |
14560 | return reloc_type == 1; /* R_TILEGX_64. */ | |
14561 | case EM_MIPS: | |
14562 | return reloc_type == 18; /* R_MIPS_64. */ | |
14563 | default: | |
14564 | return false; | |
14565 | } | |
14566 | } | |
14567 | ||
14568 | /* Like is_32bit_pcrel_reloc except that it returns TRUE iff RELOC_TYPE is | |
14569 | a 64-bit pc-relative RELA relocation used in DWARF debug sections. */ | |
14570 | ||
14571 | static bool | |
14572 | is_64bit_pcrel_reloc (Filedata * filedata, unsigned int reloc_type) | |
14573 | { | |
14574 | switch (filedata->file_header.e_machine) | |
14575 | { | |
14576 | case EM_AARCH64: | |
14577 | return reloc_type == 260; /* R_AARCH64_PREL64. */ | |
14578 | case EM_ALPHA: | |
14579 | return reloc_type == 11; /* R_ALPHA_SREL64. */ | |
14580 | case EM_IA_64: | |
14581 | return (reloc_type == 0x4e /* R_IA64_PCREL64MSB. */ | |
14582 | || reloc_type == 0x4f /* R_IA64_PCREL64LSB. */); | |
14583 | case EM_PARISC: | |
14584 | return reloc_type == 72; /* R_PARISC_PCREL64. */ | |
14585 | case EM_PPC64: | |
14586 | return reloc_type == 44; /* R_PPC64_REL64. */ | |
14587 | case EM_SPARC32PLUS: | |
14588 | case EM_SPARCV9: | |
14589 | case EM_SPARC: | |
14590 | return reloc_type == 46; /* R_SPARC_DISP64. */ | |
14591 | case EM_X86_64: | |
14592 | case EM_L1OM: | |
14593 | case EM_K1OM: | |
14594 | return reloc_type == 24; /* R_X86_64_PC64. */ | |
14595 | case EM_S390_OLD: | |
14596 | case EM_S390: | |
14597 | return reloc_type == 23; /* R_S390_PC64. */ | |
14598 | case EM_TILEGX: | |
14599 | return reloc_type == 5; /* R_TILEGX_64_PCREL. */ | |
14600 | default: | |
14601 | return false; | |
14602 | } | |
14603 | } | |
14604 | ||
14605 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
14606 | a 24-bit absolute RELA relocation used in DWARF debug sections. */ | |
14607 | ||
14608 | static bool | |
14609 | is_24bit_abs_reloc (Filedata * filedata, unsigned int reloc_type) | |
14610 | { | |
14611 | switch (filedata->file_header.e_machine) | |
14612 | { | |
14613 | case EM_CYGNUS_MN10200: | |
14614 | case EM_MN10200: | |
14615 | return reloc_type == 4; /* R_MN10200_24. */ | |
14616 | case EM_FT32: | |
14617 | return reloc_type == 5; /* R_FT32_20. */ | |
14618 | case EM_Z80: | |
14619 | return reloc_type == 5; /* R_Z80_24. */ | |
14620 | default: | |
14621 | return false; | |
14622 | } | |
14623 | } | |
14624 | ||
14625 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
14626 | a 16-bit absolute RELA relocation used in DWARF debug sections. */ | |
14627 | ||
14628 | static bool | |
14629 | is_16bit_abs_reloc (Filedata * filedata, unsigned int reloc_type) | |
14630 | { | |
14631 | /* Please keep this table alpha-sorted for ease of visual lookup. */ | |
14632 | switch (filedata->file_header.e_machine) | |
14633 | { | |
14634 | case EM_ARC: | |
14635 | case EM_ARC_COMPACT: | |
14636 | case EM_ARC_COMPACT2: | |
14637 | return reloc_type == 2; /* R_ARC_16. */ | |
14638 | case EM_ADAPTEVA_EPIPHANY: | |
14639 | return reloc_type == 5; | |
14640 | case EM_AVR_OLD: | |
14641 | case EM_AVR: | |
14642 | return reloc_type == 4; /* R_AVR_16. */ | |
14643 | case EM_CYGNUS_D10V: | |
14644 | case EM_D10V: | |
14645 | return reloc_type == 3; /* R_D10V_16. */ | |
14646 | case EM_FT32: | |
14647 | return reloc_type == 2; /* R_FT32_16. */ | |
14648 | case EM_H8S: | |
14649 | case EM_H8_300: | |
14650 | case EM_H8_300H: | |
14651 | return reloc_type == R_H8_DIR16; | |
14652 | case EM_IP2K_OLD: | |
14653 | case EM_IP2K: | |
14654 | return reloc_type == 1; /* R_IP2K_16. */ | |
14655 | case EM_M32C_OLD: | |
14656 | case EM_M32C: | |
14657 | return reloc_type == 1; /* R_M32C_16 */ | |
14658 | case EM_CYGNUS_MN10200: | |
14659 | case EM_MN10200: | |
14660 | return reloc_type == 2; /* R_MN10200_16. */ | |
14661 | case EM_CYGNUS_MN10300: | |
14662 | case EM_MN10300: | |
14663 | return reloc_type == 2; /* R_MN10300_16. */ | |
14664 | case EM_MSP430: | |
14665 | if (uses_msp430x_relocs (filedata)) | |
14666 | return reloc_type == 2; /* R_MSP430_ABS16. */ | |
14667 | /* Fall through. */ | |
14668 | case EM_MSP430_OLD: | |
14669 | return reloc_type == 5; /* R_MSP430_16_BYTE. */ | |
14670 | case EM_NDS32: | |
14671 | return reloc_type == 19; /* R_NDS32_16_RELA. */ | |
14672 | case EM_ALTERA_NIOS2: | |
14673 | return reloc_type == 13; /* R_NIOS2_BFD_RELOC_16. */ | |
14674 | case EM_NIOS32: | |
14675 | return reloc_type == 9; /* R_NIOS_16. */ | |
14676 | case EM_OR1K: | |
14677 | return reloc_type == 2; /* R_OR1K_16. */ | |
14678 | case EM_RISCV: | |
14679 | return reloc_type == 55; /* R_RISCV_SET16. */ | |
14680 | case EM_TI_PRU: | |
14681 | return reloc_type == 8; /* R_PRU_BFD_RELOC_16. */ | |
14682 | case EM_TI_C6000: | |
14683 | return reloc_type == 2; /* R_C6000_ABS16. */ | |
14684 | case EM_VISIUM: | |
14685 | return reloc_type == 2; /* R_VISIUM_16. */ | |
14686 | case EM_XGATE: | |
14687 | return reloc_type == 3; /* R_XGATE_16. */ | |
14688 | case EM_Z80: | |
14689 | return reloc_type == 4; /* R_Z80_16. */ | |
14690 | default: | |
14691 | return false; | |
14692 | } | |
14693 | } | |
14694 | ||
14695 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
14696 | a 8-bit absolute RELA relocation used in DWARF debug sections. */ | |
14697 | ||
14698 | static bool | |
14699 | is_8bit_abs_reloc (Filedata * filedata, unsigned int reloc_type) | |
14700 | { | |
14701 | switch (filedata->file_header.e_machine) | |
14702 | { | |
14703 | case EM_RISCV: | |
14704 | return reloc_type == 54; /* R_RISCV_SET8. */ | |
14705 | case EM_Z80: | |
14706 | return reloc_type == 1; /* R_Z80_8. */ | |
14707 | default: | |
14708 | return false; | |
14709 | } | |
14710 | } | |
14711 | ||
14712 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
14713 | a 6-bit absolute RELA relocation used in DWARF debug sections. */ | |
14714 | ||
14715 | static bool | |
14716 | is_6bit_abs_reloc (Filedata * filedata, unsigned int reloc_type) | |
14717 | { | |
14718 | switch (filedata->file_header.e_machine) | |
14719 | { | |
14720 | case EM_RISCV: | |
14721 | return reloc_type == 53; /* R_RISCV_SET6. */ | |
14722 | default: | |
14723 | return false; | |
14724 | } | |
14725 | } | |
14726 | ||
14727 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
14728 | a 32-bit inplace add RELA relocation used in DWARF debug sections. */ | |
14729 | ||
14730 | static bool | |
14731 | is_32bit_inplace_add_reloc (Filedata * filedata, unsigned int reloc_type) | |
14732 | { | |
14733 | /* Please keep this table alpha-sorted for ease of visual lookup. */ | |
14734 | switch (filedata->file_header.e_machine) | |
14735 | { | |
14736 | case EM_RISCV: | |
14737 | return reloc_type == 35; /* R_RISCV_ADD32. */ | |
14738 | default: | |
14739 | return false; | |
14740 | } | |
14741 | } | |
14742 | ||
14743 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
14744 | a 32-bit inplace sub RELA relocation used in DWARF debug sections. */ | |
14745 | ||
14746 | static bool | |
14747 | is_32bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type) | |
14748 | { | |
14749 | /* Please keep this table alpha-sorted for ease of visual lookup. */ | |
14750 | switch (filedata->file_header.e_machine) | |
14751 | { | |
14752 | case EM_RISCV: | |
14753 | return reloc_type == 39; /* R_RISCV_SUB32. */ | |
14754 | default: | |
14755 | return false; | |
14756 | } | |
14757 | } | |
14758 | ||
14759 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
14760 | a 64-bit inplace add RELA relocation used in DWARF debug sections. */ | |
14761 | ||
14762 | static bool | |
14763 | is_64bit_inplace_add_reloc (Filedata * filedata, unsigned int reloc_type) | |
14764 | { | |
14765 | /* Please keep this table alpha-sorted for ease of visual lookup. */ | |
14766 | switch (filedata->file_header.e_machine) | |
14767 | { | |
14768 | case EM_RISCV: | |
14769 | return reloc_type == 36; /* R_RISCV_ADD64. */ | |
14770 | default: | |
14771 | return false; | |
14772 | } | |
14773 | } | |
14774 | ||
14775 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
14776 | a 64-bit inplace sub RELA relocation used in DWARF debug sections. */ | |
14777 | ||
14778 | static bool | |
14779 | is_64bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type) | |
14780 | { | |
14781 | /* Please keep this table alpha-sorted for ease of visual lookup. */ | |
14782 | switch (filedata->file_header.e_machine) | |
14783 | { | |
14784 | case EM_RISCV: | |
14785 | return reloc_type == 40; /* R_RISCV_SUB64. */ | |
14786 | default: | |
14787 | return false; | |
14788 | } | |
14789 | } | |
14790 | ||
14791 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
14792 | a 16-bit inplace add RELA relocation used in DWARF debug sections. */ | |
14793 | ||
14794 | static bool | |
14795 | is_16bit_inplace_add_reloc (Filedata * filedata, unsigned int reloc_type) | |
14796 | { | |
14797 | /* Please keep this table alpha-sorted for ease of visual lookup. */ | |
14798 | switch (filedata->file_header.e_machine) | |
14799 | { | |
14800 | case EM_RISCV: | |
14801 | return reloc_type == 34; /* R_RISCV_ADD16. */ | |
14802 | default: | |
14803 | return false; | |
14804 | } | |
14805 | } | |
14806 | ||
14807 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
14808 | a 16-bit inplace sub RELA relocation used in DWARF debug sections. */ | |
14809 | ||
14810 | static bool | |
14811 | is_16bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type) | |
14812 | { | |
14813 | /* Please keep this table alpha-sorted for ease of visual lookup. */ | |
14814 | switch (filedata->file_header.e_machine) | |
14815 | { | |
14816 | case EM_RISCV: | |
14817 | return reloc_type == 38; /* R_RISCV_SUB16. */ | |
14818 | default: | |
14819 | return false; | |
14820 | } | |
14821 | } | |
14822 | ||
14823 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
14824 | a 8-bit inplace add RELA relocation used in DWARF debug sections. */ | |
14825 | ||
14826 | static bool | |
14827 | is_8bit_inplace_add_reloc (Filedata * filedata, unsigned int reloc_type) | |
14828 | { | |
14829 | /* Please keep this table alpha-sorted for ease of visual lookup. */ | |
14830 | switch (filedata->file_header.e_machine) | |
14831 | { | |
14832 | case EM_RISCV: | |
14833 | return reloc_type == 33; /* R_RISCV_ADD8. */ | |
14834 | default: | |
14835 | return false; | |
14836 | } | |
14837 | } | |
14838 | ||
14839 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
14840 | a 8-bit inplace sub RELA relocation used in DWARF debug sections. */ | |
14841 | ||
14842 | static bool | |
14843 | is_8bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type) | |
14844 | { | |
14845 | /* Please keep this table alpha-sorted for ease of visual lookup. */ | |
14846 | switch (filedata->file_header.e_machine) | |
14847 | { | |
14848 | case EM_RISCV: | |
14849 | return reloc_type == 37; /* R_RISCV_SUB8. */ | |
14850 | default: | |
14851 | return false; | |
14852 | } | |
14853 | } | |
14854 | ||
14855 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
14856 | a 6-bit inplace sub RELA relocation used in DWARF debug sections. */ | |
14857 | ||
14858 | static bool | |
14859 | is_6bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type) | |
14860 | { | |
14861 | switch (filedata->file_header.e_machine) | |
14862 | { | |
14863 | case EM_RISCV: | |
14864 | return reloc_type == 52; /* R_RISCV_SUB6. */ | |
14865 | default: | |
14866 | return false; | |
14867 | } | |
14868 | } | |
14869 | ||
14870 | /* Returns TRUE iff RELOC_TYPE is a NONE relocation used for discarded | |
14871 | relocation entries (possibly formerly used for SHT_GROUP sections). */ | |
14872 | ||
14873 | static bool | |
14874 | is_none_reloc (Filedata * filedata, unsigned int reloc_type) | |
14875 | { | |
14876 | switch (filedata->file_header.e_machine) | |
14877 | { | |
14878 | case EM_386: /* R_386_NONE. */ | |
14879 | case EM_68K: /* R_68K_NONE. */ | |
14880 | case EM_ADAPTEVA_EPIPHANY: | |
14881 | case EM_ALPHA: /* R_ALPHA_NONE. */ | |
14882 | case EM_ALTERA_NIOS2: /* R_NIOS2_NONE. */ | |
14883 | case EM_ARC: /* R_ARC_NONE. */ | |
14884 | case EM_ARC_COMPACT2: /* R_ARC_NONE. */ | |
14885 | case EM_ARC_COMPACT: /* R_ARC_NONE. */ | |
14886 | case EM_ARM: /* R_ARM_NONE. */ | |
14887 | case EM_CRIS: /* R_CRIS_NONE. */ | |
14888 | case EM_FT32: /* R_FT32_NONE. */ | |
14889 | case EM_IA_64: /* R_IA64_NONE. */ | |
14890 | case EM_K1OM: /* R_X86_64_NONE. */ | |
14891 | case EM_L1OM: /* R_X86_64_NONE. */ | |
14892 | case EM_M32R: /* R_M32R_NONE. */ | |
14893 | case EM_MIPS: /* R_MIPS_NONE. */ | |
14894 | case EM_MN10300: /* R_MN10300_NONE. */ | |
14895 | case EM_MOXIE: /* R_MOXIE_NONE. */ | |
14896 | case EM_NIOS32: /* R_NIOS_NONE. */ | |
14897 | case EM_OR1K: /* R_OR1K_NONE. */ | |
14898 | case EM_PARISC: /* R_PARISC_NONE. */ | |
14899 | case EM_PPC64: /* R_PPC64_NONE. */ | |
14900 | case EM_PPC: /* R_PPC_NONE. */ | |
14901 | case EM_RISCV: /* R_RISCV_NONE. */ | |
14902 | case EM_S390: /* R_390_NONE. */ | |
14903 | case EM_S390_OLD: | |
14904 | case EM_SH: /* R_SH_NONE. */ | |
14905 | case EM_SPARC32PLUS: | |
14906 | case EM_SPARC: /* R_SPARC_NONE. */ | |
14907 | case EM_SPARCV9: | |
14908 | case EM_TILEGX: /* R_TILEGX_NONE. */ | |
14909 | case EM_TILEPRO: /* R_TILEPRO_NONE. */ | |
14910 | case EM_TI_C6000:/* R_C6000_NONE. */ | |
14911 | case EM_X86_64: /* R_X86_64_NONE. */ | |
14912 | case EM_Z80: /* R_Z80_NONE. */ | |
14913 | case EM_WEBASSEMBLY: /* R_WASM32_NONE. */ | |
14914 | return reloc_type == 0; | |
14915 | ||
14916 | case EM_AARCH64: | |
14917 | return reloc_type == 0 || reloc_type == 256; | |
14918 | case EM_AVR_OLD: | |
14919 | case EM_AVR: | |
14920 | return (reloc_type == 0 /* R_AVR_NONE. */ | |
14921 | || reloc_type == 30 /* R_AVR_DIFF8. */ | |
14922 | || reloc_type == 31 /* R_AVR_DIFF16. */ | |
14923 | || reloc_type == 32 /* R_AVR_DIFF32. */); | |
14924 | case EM_METAG: | |
14925 | return reloc_type == 3; /* R_METAG_NONE. */ | |
14926 | case EM_NDS32: | |
14927 | return (reloc_type == 0 /* R_NDS32_NONE. */ | |
14928 | || reloc_type == 205 /* R_NDS32_DIFF8. */ | |
14929 | || reloc_type == 206 /* R_NDS32_DIFF16. */ | |
14930 | || reloc_type == 207 /* R_NDS32_DIFF32. */ | |
14931 | || reloc_type == 208 /* R_NDS32_DIFF_ULEB128. */); | |
14932 | case EM_TI_PRU: | |
14933 | return (reloc_type == 0 /* R_PRU_NONE. */ | |
14934 | || reloc_type == 65 /* R_PRU_DIFF8. */ | |
14935 | || reloc_type == 66 /* R_PRU_DIFF16. */ | |
14936 | || reloc_type == 67 /* R_PRU_DIFF32. */); | |
14937 | case EM_XTENSA_OLD: | |
14938 | case EM_XTENSA: | |
14939 | return (reloc_type == 0 /* R_XTENSA_NONE. */ | |
14940 | || reloc_type == 17 /* R_XTENSA_DIFF8. */ | |
14941 | || reloc_type == 18 /* R_XTENSA_DIFF16. */ | |
14942 | || reloc_type == 19 /* R_XTENSA_DIFF32. */ | |
14943 | || reloc_type == 57 /* R_XTENSA_PDIFF8. */ | |
14944 | || reloc_type == 58 /* R_XTENSA_PDIFF16. */ | |
14945 | || reloc_type == 59 /* R_XTENSA_PDIFF32. */ | |
14946 | || reloc_type == 60 /* R_XTENSA_NDIFF8. */ | |
14947 | || reloc_type == 61 /* R_XTENSA_NDIFF16. */ | |
14948 | || reloc_type == 62 /* R_XTENSA_NDIFF32. */); | |
14949 | } | |
14950 | return false; | |
14951 | } | |
14952 | ||
14953 | /* Returns TRUE if there is a relocation against | |
14954 | section NAME at OFFSET bytes. */ | |
14955 | ||
14956 | bool | |
14957 | reloc_at (struct dwarf_section * dsec, uint64_t offset) | |
14958 | { | |
14959 | Elf_Internal_Rela * relocs; | |
14960 | Elf_Internal_Rela * rp; | |
14961 | ||
14962 | if (dsec == NULL || dsec->reloc_info == NULL) | |
14963 | return false; | |
14964 | ||
14965 | relocs = (Elf_Internal_Rela *) dsec->reloc_info; | |
14966 | ||
14967 | for (rp = relocs; rp < relocs + dsec->num_relocs; ++rp) | |
14968 | if (rp->r_offset == offset) | |
14969 | return true; | |
14970 | ||
14971 | return false; | |
14972 | } | |
14973 | ||
14974 | /* Apply relocations to a section. | |
14975 | Returns TRUE upon success, FALSE otherwise. | |
14976 | If RELOCS_RETURN is non-NULL then it is set to point to the loaded relocs. | |
14977 | It is then the caller's responsibility to free them. NUM_RELOCS_RETURN | |
14978 | will be set to the number of relocs loaded. | |
14979 | ||
14980 | Note: So far support has been added only for those relocations | |
14981 | which can be found in debug sections. FIXME: Add support for | |
14982 | more relocations ? */ | |
14983 | ||
14984 | static bool | |
14985 | apply_relocations (Filedata *filedata, | |
14986 | const Elf_Internal_Shdr *section, | |
14987 | unsigned char *start, | |
14988 | size_t size, | |
14989 | void **relocs_return, | |
14990 | uint64_t *num_relocs_return) | |
14991 | { | |
14992 | Elf_Internal_Shdr * relsec; | |
14993 | unsigned char * end = start + size; | |
14994 | ||
14995 | if (relocs_return != NULL) | |
14996 | { | |
14997 | * (Elf_Internal_Rela **) relocs_return = NULL; | |
14998 | * num_relocs_return = 0; | |
14999 | } | |
15000 | ||
15001 | if (filedata->file_header.e_type != ET_REL) | |
15002 | /* No relocs to apply. */ | |
15003 | return true; | |
15004 | ||
15005 | /* Find the reloc section associated with the section. */ | |
15006 | for (relsec = filedata->section_headers; | |
15007 | relsec < filedata->section_headers + filedata->file_header.e_shnum; | |
15008 | ++relsec) | |
15009 | { | |
15010 | bool is_rela; | |
15011 | uint64_t num_relocs; | |
15012 | Elf_Internal_Rela * relocs; | |
15013 | Elf_Internal_Rela * rp; | |
15014 | Elf_Internal_Shdr * symsec; | |
15015 | Elf_Internal_Sym * symtab; | |
15016 | uint64_t num_syms; | |
15017 | Elf_Internal_Sym * sym; | |
15018 | ||
15019 | if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL) | |
15020 | || relsec->sh_info >= filedata->file_header.e_shnum | |
15021 | || filedata->section_headers + relsec->sh_info != section | |
15022 | || relsec->sh_size == 0 | |
15023 | || relsec->sh_link >= filedata->file_header.e_shnum) | |
15024 | continue; | |
15025 | ||
15026 | symsec = filedata->section_headers + relsec->sh_link; | |
15027 | if (symsec->sh_type != SHT_SYMTAB | |
15028 | && symsec->sh_type != SHT_DYNSYM) | |
15029 | return false; | |
15030 | ||
15031 | is_rela = relsec->sh_type == SHT_RELA; | |
15032 | ||
15033 | if (is_rela) | |
15034 | { | |
15035 | if (!slurp_rela_relocs (filedata, relsec->sh_offset, | |
15036 | relsec->sh_size, & relocs, & num_relocs)) | |
15037 | return false; | |
15038 | } | |
15039 | else | |
15040 | { | |
15041 | if (!slurp_rel_relocs (filedata, relsec->sh_offset, | |
15042 | relsec->sh_size, & relocs, & num_relocs)) | |
15043 | return false; | |
15044 | } | |
15045 | ||
15046 | /* SH uses RELA but uses in place value instead of the addend field. */ | |
15047 | if (filedata->file_header.e_machine == EM_SH) | |
15048 | is_rela = false; | |
15049 | ||
15050 | symtab = get_elf_symbols (filedata, symsec, & num_syms); | |
15051 | ||
15052 | for (rp = relocs; rp < relocs + num_relocs; ++rp) | |
15053 | { | |
15054 | uint64_t addend; | |
15055 | unsigned int reloc_type; | |
15056 | unsigned int reloc_size; | |
15057 | bool reloc_inplace = false; | |
15058 | bool reloc_subtract = false; | |
15059 | unsigned char *rloc; | |
15060 | uint64_t sym_index; | |
15061 | ||
15062 | reloc_type = get_reloc_type (filedata, rp->r_info); | |
15063 | ||
15064 | if (target_specific_reloc_handling (filedata, rp, start, end, symtab, num_syms)) | |
15065 | continue; | |
15066 | else if (is_none_reloc (filedata, reloc_type)) | |
15067 | continue; | |
15068 | else if (is_32bit_abs_reloc (filedata, reloc_type) | |
15069 | || is_32bit_pcrel_reloc (filedata, reloc_type)) | |
15070 | reloc_size = 4; | |
15071 | else if (is_64bit_abs_reloc (filedata, reloc_type) | |
15072 | || is_64bit_pcrel_reloc (filedata, reloc_type)) | |
15073 | reloc_size = 8; | |
15074 | else if (is_24bit_abs_reloc (filedata, reloc_type)) | |
15075 | reloc_size = 3; | |
15076 | else if (is_16bit_abs_reloc (filedata, reloc_type)) | |
15077 | reloc_size = 2; | |
15078 | else if (is_8bit_abs_reloc (filedata, reloc_type) | |
15079 | || is_6bit_abs_reloc (filedata, reloc_type)) | |
15080 | reloc_size = 1; | |
15081 | else if ((reloc_subtract = is_32bit_inplace_sub_reloc (filedata, | |
15082 | reloc_type)) | |
15083 | || is_32bit_inplace_add_reloc (filedata, reloc_type)) | |
15084 | { | |
15085 | reloc_size = 4; | |
15086 | reloc_inplace = true; | |
15087 | } | |
15088 | else if ((reloc_subtract = is_64bit_inplace_sub_reloc (filedata, | |
15089 | reloc_type)) | |
15090 | || is_64bit_inplace_add_reloc (filedata, reloc_type)) | |
15091 | { | |
15092 | reloc_size = 8; | |
15093 | reloc_inplace = true; | |
15094 | } | |
15095 | else if ((reloc_subtract = is_16bit_inplace_sub_reloc (filedata, | |
15096 | reloc_type)) | |
15097 | || is_16bit_inplace_add_reloc (filedata, reloc_type)) | |
15098 | { | |
15099 | reloc_size = 2; | |
15100 | reloc_inplace = true; | |
15101 | } | |
15102 | else if ((reloc_subtract = is_8bit_inplace_sub_reloc (filedata, | |
15103 | reloc_type)) | |
15104 | || is_8bit_inplace_add_reloc (filedata, reloc_type)) | |
15105 | { | |
15106 | reloc_size = 1; | |
15107 | reloc_inplace = true; | |
15108 | } | |
15109 | else if ((reloc_subtract = is_6bit_inplace_sub_reloc (filedata, | |
15110 | reloc_type))) | |
15111 | { | |
15112 | reloc_size = 1; | |
15113 | reloc_inplace = true; | |
15114 | } | |
15115 | else | |
15116 | { | |
15117 | static unsigned int prev_reloc = 0; | |
15118 | ||
15119 | if (reloc_type != prev_reloc) | |
15120 | warn (_("unable to apply unsupported reloc type %d to section %s\n"), | |
15121 | reloc_type, printable_section_name (filedata, section)); | |
15122 | prev_reloc = reloc_type; | |
15123 | continue; | |
15124 | } | |
15125 | ||
15126 | rloc = start + rp->r_offset; | |
15127 | if (!IN_RANGE (start, end, rloc, reloc_size)) | |
15128 | { | |
15129 | warn (_("skipping invalid relocation offset %#" PRIx64 | |
15130 | " in section %s\n"), | |
15131 | rp->r_offset, | |
15132 | printable_section_name (filedata, section)); | |
15133 | continue; | |
15134 | } | |
15135 | ||
15136 | sym_index = get_reloc_symindex (rp->r_info); | |
15137 | if (sym_index >= num_syms) | |
15138 | { | |
15139 | warn (_("skipping invalid relocation symbol index %#" PRIx64 | |
15140 | " in section %s\n"), | |
15141 | sym_index, printable_section_name (filedata, section)); | |
15142 | continue; | |
15143 | } | |
15144 | sym = symtab + sym_index; | |
15145 | ||
15146 | /* If the reloc has a symbol associated with it, | |
15147 | make sure that it is of an appropriate type. | |
15148 | ||
15149 | Relocations against symbols without type can happen. | |
15150 | Gcc -feliminate-dwarf2-dups may generate symbols | |
15151 | without type for debug info. | |
15152 | ||
15153 | Icc generates relocations against function symbols | |
15154 | instead of local labels. | |
15155 | ||
15156 | Relocations against object symbols can happen, eg when | |
15157 | referencing a global array. For an example of this see | |
15158 | the _clz.o binary in libgcc.a. */ | |
15159 | if (sym != symtab | |
15160 | && ELF_ST_TYPE (sym->st_info) != STT_COMMON | |
15161 | && ELF_ST_TYPE (sym->st_info) > STT_SECTION) | |
15162 | { | |
15163 | warn (_("skipping unexpected symbol type %s in section %s relocation %tu\n"), | |
15164 | get_symbol_type (filedata, ELF_ST_TYPE (sym->st_info)), | |
15165 | printable_section_name (filedata, relsec), | |
15166 | rp - relocs); | |
15167 | continue; | |
15168 | } | |
15169 | ||
15170 | addend = 0; | |
15171 | if (is_rela) | |
15172 | addend += rp->r_addend; | |
15173 | /* R_XTENSA_32, R_PJ_DATA_DIR32 and R_D30V_32_NORMAL are | |
15174 | partial_inplace. */ | |
15175 | if (!is_rela | |
15176 | || (filedata->file_header.e_machine == EM_XTENSA | |
15177 | && reloc_type == 1) | |
15178 | || ((filedata->file_header.e_machine == EM_PJ | |
15179 | || filedata->file_header.e_machine == EM_PJ_OLD) | |
15180 | && reloc_type == 1) | |
15181 | || ((filedata->file_header.e_machine == EM_D30V | |
15182 | || filedata->file_header.e_machine == EM_CYGNUS_D30V) | |
15183 | && reloc_type == 12) | |
15184 | || reloc_inplace) | |
15185 | { | |
15186 | if (is_6bit_inplace_sub_reloc (filedata, reloc_type)) | |
15187 | addend += byte_get (rloc, reloc_size) & 0x3f; | |
15188 | else | |
15189 | addend += byte_get (rloc, reloc_size); | |
15190 | } | |
15191 | ||
15192 | if (is_32bit_pcrel_reloc (filedata, reloc_type) | |
15193 | || is_64bit_pcrel_reloc (filedata, reloc_type)) | |
15194 | { | |
15195 | /* On HPPA, all pc-relative relocations are biased by 8. */ | |
15196 | if (filedata->file_header.e_machine == EM_PARISC) | |
15197 | addend -= 8; | |
15198 | byte_put (rloc, (addend + sym->st_value) - rp->r_offset, | |
15199 | reloc_size); | |
15200 | } | |
15201 | else if (is_6bit_abs_reloc (filedata, reloc_type) | |
15202 | || is_6bit_inplace_sub_reloc (filedata, reloc_type)) | |
15203 | { | |
15204 | if (reloc_subtract) | |
15205 | addend -= sym->st_value; | |
15206 | else | |
15207 | addend += sym->st_value; | |
15208 | addend = (addend & 0x3f) | (byte_get (rloc, reloc_size) & 0xc0); | |
15209 | byte_put (rloc, addend, reloc_size); | |
15210 | } | |
15211 | else if (reloc_subtract) | |
15212 | byte_put (rloc, addend - sym->st_value, reloc_size); | |
15213 | else | |
15214 | byte_put (rloc, addend + sym->st_value, reloc_size); | |
15215 | } | |
15216 | ||
15217 | free (symtab); | |
15218 | /* Let the target specific reloc processing code know that | |
15219 | we have finished with these relocs. */ | |
15220 | target_specific_reloc_handling (filedata, NULL, NULL, NULL, NULL, 0); | |
15221 | ||
15222 | if (relocs_return) | |
15223 | { | |
15224 | * (Elf_Internal_Rela **) relocs_return = relocs; | |
15225 | * num_relocs_return = num_relocs; | |
15226 | } | |
15227 | else | |
15228 | free (relocs); | |
15229 | ||
15230 | break; | |
15231 | } | |
15232 | ||
15233 | return true; | |
15234 | } | |
15235 | ||
15236 | #ifdef SUPPORT_DISASSEMBLY | |
15237 | static bool | |
15238 | disassemble_section (Elf_Internal_Shdr * section, Filedata * filedata) | |
15239 | { | |
15240 | printf (_("\nAssembly dump of section %s\n"), printable_section_name (filedata, section)); | |
15241 | ||
15242 | /* FIXME: XXX -- to be done --- XXX */ | |
15243 | ||
15244 | return true; | |
15245 | } | |
15246 | #endif | |
15247 | ||
15248 | /* Reads in the contents of SECTION from FILE, returning a pointer | |
15249 | to a malloc'ed buffer or NULL if something went wrong. */ | |
15250 | ||
15251 | static char * | |
15252 | get_section_contents (Elf_Internal_Shdr * section, Filedata * filedata) | |
15253 | { | |
15254 | uint64_t num_bytes = section->sh_size; | |
15255 | ||
15256 | if (num_bytes == 0 || section->sh_type == SHT_NOBITS) | |
15257 | { | |
15258 | printf (_("Section '%s' has no data to dump.\n"), | |
15259 | printable_section_name (filedata, section)); | |
15260 | return NULL; | |
15261 | } | |
15262 | ||
15263 | return (char *) get_data (NULL, filedata, section->sh_offset, 1, num_bytes, | |
15264 | _("section contents")); | |
15265 | } | |
15266 | ||
15267 | /* Uncompresses a section that was compressed using zlib/zstd, in place. */ | |
15268 | ||
15269 | static bool | |
15270 | uncompress_section_contents (bool is_zstd, unsigned char **buffer, | |
15271 | uint64_t uncompressed_size, uint64_t *size) | |
15272 | { | |
15273 | uint64_t compressed_size = *size; | |
15274 | unsigned char *compressed_buffer = *buffer; | |
15275 | unsigned char *uncompressed_buffer = xmalloc (uncompressed_size); | |
15276 | z_stream strm; | |
15277 | int rc; | |
15278 | ||
15279 | if (is_zstd) | |
15280 | { | |
15281 | #ifdef HAVE_ZSTD | |
15282 | size_t ret = ZSTD_decompress (uncompressed_buffer, uncompressed_size, | |
15283 | compressed_buffer, compressed_size); | |
15284 | if (ZSTD_isError (ret)) | |
15285 | goto fail; | |
15286 | #endif | |
15287 | } | |
15288 | else | |
15289 | { | |
15290 | /* It is possible the section consists of several compressed | |
15291 | buffers concatenated together, so we uncompress in a loop. */ | |
15292 | /* PR 18313: The state field in the z_stream structure is supposed | |
15293 | to be invisible to the user (ie us), but some compilers will | |
15294 | still complain about it being used without initialisation. So | |
15295 | we first zero the entire z_stream structure and then set the fields | |
15296 | that we need. */ | |
15297 | memset (&strm, 0, sizeof strm); | |
15298 | strm.avail_in = compressed_size; | |
15299 | strm.next_in = (Bytef *)compressed_buffer; | |
15300 | strm.avail_out = uncompressed_size; | |
15301 | ||
15302 | rc = inflateInit (&strm); | |
15303 | while (strm.avail_in > 0) | |
15304 | { | |
15305 | if (rc != Z_OK) | |
15306 | break; | |
15307 | strm.next_out = ((Bytef *)uncompressed_buffer | |
15308 | + (uncompressed_size - strm.avail_out)); | |
15309 | rc = inflate (&strm, Z_FINISH); | |
15310 | if (rc != Z_STREAM_END) | |
15311 | break; | |
15312 | rc = inflateReset (&strm); | |
15313 | } | |
15314 | if (inflateEnd (&strm) != Z_OK || rc != Z_OK || strm.avail_out != 0) | |
15315 | goto fail; | |
15316 | } | |
15317 | ||
15318 | *buffer = uncompressed_buffer; | |
15319 | *size = uncompressed_size; | |
15320 | return true; | |
15321 | ||
15322 | fail: | |
15323 | free (uncompressed_buffer); | |
15324 | /* Indicate decompression failure. */ | |
15325 | *buffer = NULL; | |
15326 | return false; | |
15327 | } | |
15328 | ||
15329 | static bool | |
15330 | dump_section_as_strings (Elf_Internal_Shdr * section, Filedata * filedata) | |
15331 | { | |
15332 | Elf_Internal_Shdr *relsec; | |
15333 | uint64_t num_bytes; | |
15334 | unsigned char *data; | |
15335 | unsigned char *end; | |
15336 | unsigned char *real_start; | |
15337 | unsigned char *start; | |
15338 | bool some_strings_shown; | |
15339 | ||
15340 | real_start = start = (unsigned char *) get_section_contents (section, filedata); | |
15341 | if (start == NULL) | |
15342 | /* PR 21820: Do not fail if the section was empty. */ | |
15343 | return section->sh_size == 0 || section->sh_type == SHT_NOBITS; | |
15344 | ||
15345 | num_bytes = section->sh_size; | |
15346 | ||
15347 | if (filedata->is_separate) | |
15348 | printf (_("\nString dump of section '%s' in linked file %s:\n"), | |
15349 | printable_section_name (filedata, section), | |
15350 | filedata->file_name); | |
15351 | else | |
15352 | printf (_("\nString dump of section '%s':\n"), | |
15353 | printable_section_name (filedata, section)); | |
15354 | ||
15355 | if (decompress_dumps) | |
15356 | { | |
15357 | uint64_t new_size = num_bytes; | |
15358 | uint64_t uncompressed_size = 0; | |
15359 | bool is_zstd = false; | |
15360 | ||
15361 | if ((section->sh_flags & SHF_COMPRESSED) != 0) | |
15362 | { | |
15363 | Elf_Internal_Chdr chdr; | |
15364 | unsigned int compression_header_size | |
15365 | = get_compression_header (& chdr, (unsigned char *) start, | |
15366 | num_bytes); | |
15367 | if (compression_header_size == 0) | |
15368 | /* An error message will have already been generated | |
15369 | by get_compression_header. */ | |
15370 | goto error_out; | |
15371 | ||
15372 | if (chdr.ch_type == ELFCOMPRESS_ZLIB) | |
15373 | ; | |
15374 | #ifdef HAVE_ZSTD | |
15375 | else if (chdr.ch_type == ELFCOMPRESS_ZSTD) | |
15376 | is_zstd = true; | |
15377 | #endif | |
15378 | else | |
15379 | { | |
15380 | warn (_("section '%s' has unsupported compress type: %d\n"), | |
15381 | printable_section_name (filedata, section), chdr.ch_type); | |
15382 | goto error_out; | |
15383 | } | |
15384 | uncompressed_size = chdr.ch_size; | |
15385 | start += compression_header_size; | |
15386 | new_size -= compression_header_size; | |
15387 | } | |
15388 | else if (new_size > 12 && streq ((char *) start, "ZLIB")) | |
15389 | { | |
15390 | /* Read the zlib header. In this case, it should be "ZLIB" | |
15391 | followed by the uncompressed section size, 8 bytes in | |
15392 | big-endian order. */ | |
15393 | uncompressed_size = start[4]; uncompressed_size <<= 8; | |
15394 | uncompressed_size += start[5]; uncompressed_size <<= 8; | |
15395 | uncompressed_size += start[6]; uncompressed_size <<= 8; | |
15396 | uncompressed_size += start[7]; uncompressed_size <<= 8; | |
15397 | uncompressed_size += start[8]; uncompressed_size <<= 8; | |
15398 | uncompressed_size += start[9]; uncompressed_size <<= 8; | |
15399 | uncompressed_size += start[10]; uncompressed_size <<= 8; | |
15400 | uncompressed_size += start[11]; | |
15401 | start += 12; | |
15402 | new_size -= 12; | |
15403 | } | |
15404 | ||
15405 | if (uncompressed_size) | |
15406 | { | |
15407 | if (uncompress_section_contents (is_zstd, &start, uncompressed_size, | |
15408 | &new_size)) | |
15409 | num_bytes = new_size; | |
15410 | else | |
15411 | { | |
15412 | error (_("Unable to decompress section %s\n"), | |
15413 | printable_section_name (filedata, section)); | |
15414 | goto error_out; | |
15415 | } | |
15416 | } | |
15417 | else | |
15418 | start = real_start; | |
15419 | } | |
15420 | ||
15421 | /* If the section being dumped has relocations against it the user might | |
15422 | be expecting these relocations to have been applied. Check for this | |
15423 | case and issue a warning message in order to avoid confusion. | |
15424 | FIXME: Maybe we ought to have an option that dumps a section with | |
15425 | relocs applied ? */ | |
15426 | for (relsec = filedata->section_headers; | |
15427 | relsec < filedata->section_headers + filedata->file_header.e_shnum; | |
15428 | ++relsec) | |
15429 | { | |
15430 | if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL) | |
15431 | || relsec->sh_info >= filedata->file_header.e_shnum | |
15432 | || filedata->section_headers + relsec->sh_info != section | |
15433 | || relsec->sh_size == 0 | |
15434 | || relsec->sh_link >= filedata->file_header.e_shnum) | |
15435 | continue; | |
15436 | ||
15437 | printf (_(" Note: This section has relocations against it, but these have NOT been applied to this dump.\n")); | |
15438 | break; | |
15439 | } | |
15440 | ||
15441 | data = start; | |
15442 | end = start + num_bytes; | |
15443 | some_strings_shown = false; | |
15444 | ||
15445 | #ifdef HAVE_MBSTATE_T | |
15446 | mbstate_t state; | |
15447 | /* Initialise the multibyte conversion state. */ | |
15448 | memset (& state, 0, sizeof (state)); | |
15449 | #endif | |
15450 | ||
15451 | bool continuing = false; | |
15452 | ||
15453 | while (data < end) | |
15454 | { | |
15455 | while (!ISPRINT (* data)) | |
15456 | if (++ data >= end) | |
15457 | break; | |
15458 | ||
15459 | if (data < end) | |
15460 | { | |
15461 | size_t maxlen = end - data; | |
15462 | ||
15463 | if (continuing) | |
15464 | { | |
15465 | printf (" "); | |
15466 | continuing = false; | |
15467 | } | |
15468 | else | |
15469 | { | |
15470 | printf (" [%6tx] ", data - start); | |
15471 | } | |
15472 | ||
15473 | if (maxlen > 0) | |
15474 | { | |
15475 | char c = 0; | |
15476 | ||
15477 | while (maxlen) | |
15478 | { | |
15479 | c = *data++; | |
15480 | ||
15481 | if (c == 0) | |
15482 | break; | |
15483 | ||
15484 | /* PR 25543: Treat new-lines as string-ending characters. */ | |
15485 | if (c == '\n') | |
15486 | { | |
15487 | printf ("\\n\n"); | |
15488 | if (*data != 0) | |
15489 | continuing = true; | |
15490 | break; | |
15491 | } | |
15492 | ||
15493 | /* Do not print control characters directly as they can affect terminal | |
15494 | settings. Such characters usually appear in the names generated | |
15495 | by the assembler for local labels. */ | |
15496 | if (ISCNTRL (c)) | |
15497 | { | |
15498 | printf ("^%c", c + 0x40); | |
15499 | } | |
15500 | else if (ISPRINT (c)) | |
15501 | { | |
15502 | putchar (c); | |
15503 | } | |
15504 | else | |
15505 | { | |
15506 | size_t n; | |
15507 | #ifdef HAVE_MBSTATE_T | |
15508 | wchar_t w; | |
15509 | #endif | |
15510 | /* Let printf do the hard work of displaying multibyte characters. */ | |
15511 | printf ("%.1s", data - 1); | |
15512 | #ifdef HAVE_MBSTATE_T | |
15513 | /* Try to find out how many bytes made up the character that was | |
15514 | just printed. Advance the symbol pointer past the bytes that | |
15515 | were displayed. */ | |
15516 | n = mbrtowc (& w, (char *)(data - 1), MB_CUR_MAX, & state); | |
15517 | #else | |
15518 | n = 1; | |
15519 | #endif | |
15520 | if (n != (size_t) -1 && n != (size_t) -2 && n > 0) | |
15521 | data += (n - 1); | |
15522 | } | |
15523 | } | |
15524 | ||
15525 | if (c != '\n') | |
15526 | putchar ('\n'); | |
15527 | } | |
15528 | else | |
15529 | { | |
15530 | printf (_("<corrupt>\n")); | |
15531 | data = end; | |
15532 | } | |
15533 | some_strings_shown = true; | |
15534 | } | |
15535 | } | |
15536 | ||
15537 | if (! some_strings_shown) | |
15538 | printf (_(" No strings found in this section.")); | |
15539 | ||
15540 | free (real_start); | |
15541 | ||
15542 | putchar ('\n'); | |
15543 | return true; | |
15544 | ||
15545 | error_out: | |
15546 | free (real_start); | |
15547 | return false; | |
15548 | } | |
15549 | ||
15550 | static bool | |
15551 | dump_section_as_bytes (Elf_Internal_Shdr *section, | |
15552 | Filedata *filedata, | |
15553 | bool relocate) | |
15554 | { | |
15555 | Elf_Internal_Shdr *relsec; | |
15556 | size_t bytes; | |
15557 | uint64_t section_size; | |
15558 | uint64_t addr; | |
15559 | unsigned char *data; | |
15560 | unsigned char *real_start; | |
15561 | unsigned char *start; | |
15562 | ||
15563 | real_start = start = (unsigned char *) get_section_contents (section, filedata); | |
15564 | if (start == NULL) | |
15565 | /* PR 21820: Do not fail if the section was empty. */ | |
15566 | return section->sh_size == 0 || section->sh_type == SHT_NOBITS; | |
15567 | ||
15568 | section_size = section->sh_size; | |
15569 | ||
15570 | if (filedata->is_separate) | |
15571 | printf (_("\nHex dump of section '%s' in linked file %s:\n"), | |
15572 | printable_section_name (filedata, section), | |
15573 | filedata->file_name); | |
15574 | else | |
15575 | printf (_("\nHex dump of section '%s':\n"), | |
15576 | printable_section_name (filedata, section)); | |
15577 | ||
15578 | if (decompress_dumps) | |
15579 | { | |
15580 | uint64_t new_size = section_size; | |
15581 | uint64_t uncompressed_size = 0; | |
15582 | bool is_zstd = false; | |
15583 | ||
15584 | if ((section->sh_flags & SHF_COMPRESSED) != 0) | |
15585 | { | |
15586 | Elf_Internal_Chdr chdr; | |
15587 | unsigned int compression_header_size | |
15588 | = get_compression_header (& chdr, start, section_size); | |
15589 | ||
15590 | if (compression_header_size == 0) | |
15591 | /* An error message will have already been generated | |
15592 | by get_compression_header. */ | |
15593 | goto error_out; | |
15594 | ||
15595 | if (chdr.ch_type == ELFCOMPRESS_ZLIB) | |
15596 | ; | |
15597 | #ifdef HAVE_ZSTD | |
15598 | else if (chdr.ch_type == ELFCOMPRESS_ZSTD) | |
15599 | is_zstd = true; | |
15600 | #endif | |
15601 | else | |
15602 | { | |
15603 | warn (_("section '%s' has unsupported compress type: %d\n"), | |
15604 | printable_section_name (filedata, section), chdr.ch_type); | |
15605 | goto error_out; | |
15606 | } | |
15607 | uncompressed_size = chdr.ch_size; | |
15608 | start += compression_header_size; | |
15609 | new_size -= compression_header_size; | |
15610 | } | |
15611 | else if (new_size > 12 && streq ((char *) start, "ZLIB")) | |
15612 | { | |
15613 | /* Read the zlib header. In this case, it should be "ZLIB" | |
15614 | followed by the uncompressed section size, 8 bytes in | |
15615 | big-endian order. */ | |
15616 | uncompressed_size = start[4]; uncompressed_size <<= 8; | |
15617 | uncompressed_size += start[5]; uncompressed_size <<= 8; | |
15618 | uncompressed_size += start[6]; uncompressed_size <<= 8; | |
15619 | uncompressed_size += start[7]; uncompressed_size <<= 8; | |
15620 | uncompressed_size += start[8]; uncompressed_size <<= 8; | |
15621 | uncompressed_size += start[9]; uncompressed_size <<= 8; | |
15622 | uncompressed_size += start[10]; uncompressed_size <<= 8; | |
15623 | uncompressed_size += start[11]; | |
15624 | start += 12; | |
15625 | new_size -= 12; | |
15626 | } | |
15627 | ||
15628 | if (uncompressed_size) | |
15629 | { | |
15630 | if (uncompress_section_contents (is_zstd, &start, uncompressed_size, | |
15631 | &new_size)) | |
15632 | { | |
15633 | section_size = new_size; | |
15634 | } | |
15635 | else | |
15636 | { | |
15637 | error (_("Unable to decompress section %s\n"), | |
15638 | printable_section_name (filedata, section)); | |
15639 | /* FIXME: Print the section anyway ? */ | |
15640 | goto error_out; | |
15641 | } | |
15642 | } | |
15643 | else | |
15644 | start = real_start; | |
15645 | } | |
15646 | ||
15647 | if (relocate) | |
15648 | { | |
15649 | if (! apply_relocations (filedata, section, start, section_size, NULL, NULL)) | |
15650 | goto error_out; | |
15651 | } | |
15652 | else | |
15653 | { | |
15654 | /* If the section being dumped has relocations against it the user might | |
15655 | be expecting these relocations to have been applied. Check for this | |
15656 | case and issue a warning message in order to avoid confusion. | |
15657 | FIXME: Maybe we ought to have an option that dumps a section with | |
15658 | relocs applied ? */ | |
15659 | for (relsec = filedata->section_headers; | |
15660 | relsec < filedata->section_headers + filedata->file_header.e_shnum; | |
15661 | ++relsec) | |
15662 | { | |
15663 | if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL) | |
15664 | || relsec->sh_info >= filedata->file_header.e_shnum | |
15665 | || filedata->section_headers + relsec->sh_info != section | |
15666 | || relsec->sh_size == 0 | |
15667 | || relsec->sh_link >= filedata->file_header.e_shnum) | |
15668 | continue; | |
15669 | ||
15670 | printf (_(" NOTE: This section has relocations against it, but these have NOT been applied to this dump.\n")); | |
15671 | break; | |
15672 | } | |
15673 | } | |
15674 | ||
15675 | addr = section->sh_addr; | |
15676 | bytes = section_size; | |
15677 | data = start; | |
15678 | ||
15679 | while (bytes) | |
15680 | { | |
15681 | int j; | |
15682 | int k; | |
15683 | int lbytes; | |
15684 | ||
15685 | lbytes = (bytes > 16 ? 16 : bytes); | |
15686 | ||
15687 | printf (" 0x%8.8" PRIx64 " ", addr); | |
15688 | ||
15689 | for (j = 0; j < 16; j++) | |
15690 | { | |
15691 | if (j < lbytes) | |
15692 | printf ("%2.2x", data[j]); | |
15693 | else | |
15694 | printf (" "); | |
15695 | ||
15696 | if ((j & 3) == 3) | |
15697 | printf (" "); | |
15698 | } | |
15699 | ||
15700 | for (j = 0; j < lbytes; j++) | |
15701 | { | |
15702 | k = data[j]; | |
15703 | if (k >= ' ' && k < 0x7f) | |
15704 | printf ("%c", k); | |
15705 | else | |
15706 | printf ("."); | |
15707 | } | |
15708 | ||
15709 | putchar ('\n'); | |
15710 | ||
15711 | data += lbytes; | |
15712 | addr += lbytes; | |
15713 | bytes -= lbytes; | |
15714 | } | |
15715 | ||
15716 | free (real_start); | |
15717 | ||
15718 | putchar ('\n'); | |
15719 | return true; | |
15720 | ||
15721 | error_out: | |
15722 | free (real_start); | |
15723 | return false; | |
15724 | } | |
15725 | ||
15726 | #ifdef ENABLE_LIBCTF | |
15727 | static ctf_sect_t * | |
15728 | shdr_to_ctf_sect (ctf_sect_t *buf, Elf_Internal_Shdr *shdr, Filedata *filedata) | |
15729 | { | |
15730 | buf->cts_name = section_name_print (filedata, shdr); | |
15731 | buf->cts_size = shdr->sh_size; | |
15732 | buf->cts_entsize = shdr->sh_entsize; | |
15733 | ||
15734 | return buf; | |
15735 | } | |
15736 | ||
15737 | /* Formatting callback function passed to ctf_dump. Returns either the pointer | |
15738 | it is passed, or a pointer to newly-allocated storage, in which case | |
15739 | dump_ctf() will free it when it no longer needs it. */ | |
15740 | ||
15741 | static char * | |
15742 | dump_ctf_indent_lines (ctf_sect_names_t sect ATTRIBUTE_UNUSED, | |
15743 | char *s, void *arg) | |
15744 | { | |
15745 | const char *blanks = arg; | |
15746 | char *new_s; | |
15747 | ||
15748 | if (asprintf (&new_s, "%s%s", blanks, s) < 0) | |
15749 | return s; | |
15750 | return new_s; | |
15751 | } | |
15752 | ||
15753 | /* Dump CTF errors/warnings. */ | |
15754 | static void | |
15755 | dump_ctf_errs (ctf_dict_t *fp) | |
15756 | { | |
15757 | ctf_next_t *it = NULL; | |
15758 | char *errtext; | |
15759 | int is_warning; | |
15760 | int err; | |
15761 | ||
15762 | /* Dump accumulated errors and warnings. */ | |
15763 | while ((errtext = ctf_errwarning_next (fp, &it, &is_warning, &err)) != NULL) | |
15764 | { | |
15765 | error (_("%s: %s"), is_warning ? _("warning"): _("error"), | |
15766 | errtext); | |
15767 | free (errtext); | |
15768 | } | |
15769 | if (err != ECTF_NEXT_END) | |
15770 | error (_("CTF error: cannot get CTF errors: `%s'"), ctf_errmsg (err)); | |
15771 | } | |
15772 | ||
15773 | /* Dump one CTF archive member. */ | |
15774 | ||
15775 | static void | |
15776 | dump_ctf_archive_member (ctf_dict_t *ctf, const char *name, ctf_dict_t *parent, | |
15777 | size_t member) | |
15778 | { | |
15779 | const char *things[] = {"Header", "Labels", "Data objects", | |
15780 | "Function objects", "Variables", "Types", "Strings", | |
15781 | ""}; | |
15782 | const char **thing; | |
15783 | size_t i; | |
15784 | ||
15785 | /* Don't print out the name of the default-named archive member if it appears | |
15786 | first in the list. The name .ctf appears everywhere, even for things that | |
15787 | aren't really archives, so printing it out is liable to be confusing; also, | |
15788 | the common case by far is for only one archive member to exist, and hiding | |
15789 | it in that case seems worthwhile. */ | |
15790 | ||
15791 | if (strcmp (name, ".ctf") != 0 || member != 0) | |
15792 | printf (_("\nCTF archive member: %s:\n"), name); | |
15793 | ||
15794 | if (ctf_parent_name (ctf) != NULL) | |
15795 | ctf_import (ctf, parent); | |
15796 | ||
15797 | for (i = 0, thing = things; *thing[0]; thing++, i++) | |
15798 | { | |
15799 | ctf_dump_state_t *s = NULL; | |
15800 | char *item; | |
15801 | ||
15802 | printf ("\n %s:\n", *thing); | |
15803 | while ((item = ctf_dump (ctf, &s, i, dump_ctf_indent_lines, | |
15804 | (void *) " ")) != NULL) | |
15805 | { | |
15806 | printf ("%s\n", item); | |
15807 | free (item); | |
15808 | } | |
15809 | ||
15810 | if (ctf_errno (ctf)) | |
15811 | { | |
15812 | error (_("Iteration failed: %s, %s\n"), *thing, | |
15813 | ctf_errmsg (ctf_errno (ctf))); | |
15814 | break; | |
15815 | } | |
15816 | } | |
15817 | ||
15818 | dump_ctf_errs (ctf); | |
15819 | } | |
15820 | ||
15821 | static bool | |
15822 | dump_section_as_ctf (Elf_Internal_Shdr * section, Filedata * filedata) | |
15823 | { | |
15824 | Elf_Internal_Shdr * symtab_sec = NULL; | |
15825 | Elf_Internal_Shdr * strtab_sec = NULL; | |
15826 | void * data = NULL; | |
15827 | void * symdata = NULL; | |
15828 | void * strdata = NULL; | |
15829 | ctf_sect_t ctfsect, symsect, strsect; | |
15830 | ctf_sect_t * symsectp = NULL; | |
15831 | ctf_sect_t * strsectp = NULL; | |
15832 | ctf_archive_t * ctfa = NULL; | |
15833 | ctf_dict_t * parent = NULL; | |
15834 | ctf_dict_t * fp; | |
15835 | ||
15836 | ctf_next_t *i = NULL; | |
15837 | const char *name; | |
15838 | size_t member = 0; | |
15839 | int err; | |
15840 | bool ret = false; | |
15841 | ||
15842 | shdr_to_ctf_sect (&ctfsect, section, filedata); | |
15843 | data = get_section_contents (section, filedata); | |
15844 | ctfsect.cts_data = data; | |
15845 | ||
15846 | if (!dump_ctf_symtab_name) | |
15847 | dump_ctf_symtab_name = strdup (".dynsym"); | |
15848 | ||
15849 | if (!dump_ctf_strtab_name) | |
15850 | dump_ctf_strtab_name = strdup (".dynstr"); | |
15851 | ||
15852 | if (dump_ctf_symtab_name && dump_ctf_symtab_name[0] != 0) | |
15853 | { | |
15854 | if ((symtab_sec = find_section (filedata, dump_ctf_symtab_name)) == NULL) | |
15855 | { | |
15856 | error (_("No symbol section named %s\n"), dump_ctf_symtab_name); | |
15857 | goto fail; | |
15858 | } | |
15859 | if ((symdata = (void *) get_data (NULL, filedata, | |
15860 | symtab_sec->sh_offset, 1, | |
15861 | symtab_sec->sh_size, | |
15862 | _("symbols"))) == NULL) | |
15863 | goto fail; | |
15864 | symsectp = shdr_to_ctf_sect (&symsect, symtab_sec, filedata); | |
15865 | symsect.cts_data = symdata; | |
15866 | } | |
15867 | ||
15868 | if (dump_ctf_strtab_name && dump_ctf_strtab_name[0] != 0) | |
15869 | { | |
15870 | if ((strtab_sec = find_section (filedata, dump_ctf_strtab_name)) == NULL) | |
15871 | { | |
15872 | error (_("No string table section named %s\n"), | |
15873 | dump_ctf_strtab_name); | |
15874 | goto fail; | |
15875 | } | |
15876 | if ((strdata = (void *) get_data (NULL, filedata, | |
15877 | strtab_sec->sh_offset, 1, | |
15878 | strtab_sec->sh_size, | |
15879 | _("strings"))) == NULL) | |
15880 | goto fail; | |
15881 | strsectp = shdr_to_ctf_sect (&strsect, strtab_sec, filedata); | |
15882 | strsect.cts_data = strdata; | |
15883 | } | |
15884 | ||
15885 | /* Load the CTF file and dump it. It may be a raw CTF section, or an archive: | |
15886 | libctf papers over the difference, so we can pretend it is always an | |
15887 | archive. */ | |
15888 | ||
15889 | if ((ctfa = ctf_arc_bufopen (&ctfsect, symsectp, strsectp, &err)) == NULL) | |
15890 | { | |
15891 | dump_ctf_errs (NULL); | |
15892 | error (_("CTF open failure: %s\n"), ctf_errmsg (err)); | |
15893 | goto fail; | |
15894 | } | |
15895 | ||
15896 | ctf_arc_symsect_endianness (ctfa, filedata->file_header.e_ident[EI_DATA] | |
15897 | != ELFDATA2MSB); | |
15898 | ||
15899 | /* Preload the parent dict, since it will need to be imported into every | |
15900 | child in turn. */ | |
15901 | if ((parent = ctf_dict_open (ctfa, dump_ctf_parent_name, &err)) == NULL) | |
15902 | { | |
15903 | dump_ctf_errs (NULL); | |
15904 | error (_("CTF open failure: %s\n"), ctf_errmsg (err)); | |
15905 | goto fail; | |
15906 | } | |
15907 | ||
15908 | ret = true; | |
15909 | ||
15910 | if (filedata->is_separate) | |
15911 | printf (_("\nDump of CTF section '%s' in linked file %s:\n"), | |
15912 | printable_section_name (filedata, section), | |
15913 | filedata->file_name); | |
15914 | else | |
15915 | printf (_("\nDump of CTF section '%s':\n"), | |
15916 | printable_section_name (filedata, section)); | |
15917 | ||
15918 | while ((fp = ctf_archive_next (ctfa, &i, &name, 0, &err)) != NULL) | |
15919 | dump_ctf_archive_member (fp, name, parent, member++); | |
15920 | if (err != ECTF_NEXT_END) | |
15921 | { | |
15922 | dump_ctf_errs (NULL); | |
15923 | error (_("CTF member open failure: %s\n"), ctf_errmsg (err)); | |
15924 | ret = false; | |
15925 | } | |
15926 | ||
15927 | fail: | |
15928 | ctf_dict_close (parent); | |
15929 | ctf_close (ctfa); | |
15930 | free (data); | |
15931 | free (symdata); | |
15932 | free (strdata); | |
15933 | return ret; | |
15934 | } | |
15935 | #endif | |
15936 | ||
15937 | static bool | |
15938 | dump_section_as_sframe (Elf_Internal_Shdr * section, Filedata * filedata) | |
15939 | { | |
15940 | void * data = NULL; | |
15941 | sframe_decoder_ctx *sfd_ctx = NULL; | |
15942 | const char *print_name = printable_section_name (filedata, section); | |
15943 | ||
15944 | bool ret = true; | |
15945 | size_t sf_size; | |
15946 | int err = 0; | |
15947 | ||
15948 | if (strcmp (print_name, "") == 0) | |
15949 | { | |
15950 | error (_("Section name must be provided \n")); | |
15951 | ret = false; | |
15952 | return ret; | |
15953 | } | |
15954 | ||
15955 | data = get_section_contents (section, filedata); | |
15956 | sf_size = section->sh_size; | |
15957 | /* Decode the contents of the section. */ | |
15958 | sfd_ctx = sframe_decode ((const char*)data, sf_size, &err); | |
15959 | if (!sfd_ctx) | |
15960 | { | |
15961 | ret = false; | |
15962 | error (_("SFrame decode failure: %s\n"), sframe_errmsg (err)); | |
15963 | goto fail; | |
15964 | } | |
15965 | ||
15966 | printf (_("Contents of the SFrame section %s:"), print_name); | |
15967 | /* Dump the contents as text. */ | |
15968 | dump_sframe (sfd_ctx, section->sh_addr); | |
15969 | ||
15970 | fail: | |
15971 | free (data); | |
15972 | return ret; | |
15973 | } | |
15974 | ||
15975 | static bool | |
15976 | load_specific_debug_section (enum dwarf_section_display_enum debug, | |
15977 | const Elf_Internal_Shdr * sec, | |
15978 | void * data) | |
15979 | { | |
15980 | struct dwarf_section * section = &debug_displays [debug].section; | |
15981 | char buf [64]; | |
15982 | Filedata * filedata = (Filedata *) data; | |
15983 | ||
15984 | if (section->start != NULL) | |
15985 | { | |
15986 | /* If it is already loaded, do nothing. */ | |
15987 | if (streq (section->filename, filedata->file_name)) | |
15988 | return true; | |
15989 | free (section->start); | |
15990 | } | |
15991 | ||
15992 | snprintf (buf, sizeof (buf), _("%s section data"), section->name); | |
15993 | section->address = sec->sh_addr; | |
15994 | section->filename = filedata->file_name; | |
15995 | section->start = (unsigned char *) get_data (NULL, filedata, | |
15996 | sec->sh_offset, 1, | |
15997 | sec->sh_size, buf); | |
15998 | if (section->start == NULL) | |
15999 | section->size = 0; | |
16000 | else | |
16001 | { | |
16002 | unsigned char *start = section->start; | |
16003 | uint64_t size = sec->sh_size; | |
16004 | uint64_t uncompressed_size = 0; | |
16005 | bool is_zstd = false; | |
16006 | ||
16007 | if ((sec->sh_flags & SHF_COMPRESSED) != 0) | |
16008 | { | |
16009 | Elf_Internal_Chdr chdr; | |
16010 | unsigned int compression_header_size; | |
16011 | ||
16012 | if (size < (is_32bit_elf | |
16013 | ? sizeof (Elf32_External_Chdr) | |
16014 | : sizeof (Elf64_External_Chdr))) | |
16015 | { | |
16016 | warn (_("compressed section %s is too small to contain a compression header\n"), | |
16017 | section->name); | |
16018 | return false; | |
16019 | } | |
16020 | ||
16021 | compression_header_size = get_compression_header (&chdr, start, size); | |
16022 | if (compression_header_size == 0) | |
16023 | /* An error message will have already been generated | |
16024 | by get_compression_header. */ | |
16025 | return false; | |
16026 | ||
16027 | if (chdr.ch_type == ELFCOMPRESS_ZLIB) | |
16028 | ; | |
16029 | #ifdef HAVE_ZSTD | |
16030 | else if (chdr.ch_type == ELFCOMPRESS_ZSTD) | |
16031 | is_zstd = true; | |
16032 | #endif | |
16033 | else | |
16034 | { | |
16035 | warn (_("section '%s' has unsupported compress type: %d\n"), | |
16036 | section->name, chdr.ch_type); | |
16037 | return false; | |
16038 | } | |
16039 | uncompressed_size = chdr.ch_size; | |
16040 | start += compression_header_size; | |
16041 | size -= compression_header_size; | |
16042 | } | |
16043 | else if (size > 12 && streq ((char *) start, "ZLIB")) | |
16044 | { | |
16045 | /* Read the zlib header. In this case, it should be "ZLIB" | |
16046 | followed by the uncompressed section size, 8 bytes in | |
16047 | big-endian order. */ | |
16048 | uncompressed_size = start[4]; uncompressed_size <<= 8; | |
16049 | uncompressed_size += start[5]; uncompressed_size <<= 8; | |
16050 | uncompressed_size += start[6]; uncompressed_size <<= 8; | |
16051 | uncompressed_size += start[7]; uncompressed_size <<= 8; | |
16052 | uncompressed_size += start[8]; uncompressed_size <<= 8; | |
16053 | uncompressed_size += start[9]; uncompressed_size <<= 8; | |
16054 | uncompressed_size += start[10]; uncompressed_size <<= 8; | |
16055 | uncompressed_size += start[11]; | |
16056 | start += 12; | |
16057 | size -= 12; | |
16058 | } | |
16059 | ||
16060 | if (uncompressed_size) | |
16061 | { | |
16062 | if (uncompress_section_contents (is_zstd, &start, uncompressed_size, | |
16063 | &size)) | |
16064 | { | |
16065 | /* Free the compressed buffer, update the section buffer | |
16066 | and the section size if uncompress is successful. */ | |
16067 | free (section->start); | |
16068 | section->start = start; | |
16069 | } | |
16070 | else | |
16071 | { | |
16072 | error (_("Unable to decompress section %s\n"), | |
16073 | printable_section_name (filedata, sec)); | |
16074 | return false; | |
16075 | } | |
16076 | } | |
16077 | ||
16078 | section->size = size; | |
16079 | } | |
16080 | ||
16081 | if (section->start == NULL) | |
16082 | return false; | |
16083 | ||
16084 | if (debug_displays [debug].relocate) | |
16085 | { | |
16086 | if (! apply_relocations (filedata, sec, section->start, section->size, | |
16087 | & section->reloc_info, & section->num_relocs)) | |
16088 | return false; | |
16089 | } | |
16090 | else | |
16091 | { | |
16092 | section->reloc_info = NULL; | |
16093 | section->num_relocs = 0; | |
16094 | } | |
16095 | ||
16096 | return true; | |
16097 | } | |
16098 | ||
16099 | #if HAVE_LIBDEBUGINFOD | |
16100 | /* Return a hex string representation of the build-id. */ | |
16101 | unsigned char * | |
16102 | get_build_id (void * data) | |
16103 | { | |
16104 | Filedata * filedata = (Filedata *) data; | |
16105 | Elf_Internal_Shdr * shdr; | |
16106 | size_t i; | |
16107 | ||
16108 | /* Iterate through notes to find note.gnu.build-id. | |
16109 | FIXME: Only the first note in any note section is examined. */ | |
16110 | for (i = 0, shdr = filedata->section_headers; | |
16111 | i < filedata->file_header.e_shnum && shdr != NULL; | |
16112 | i++, shdr++) | |
16113 | { | |
16114 | if (shdr->sh_type != SHT_NOTE) | |
16115 | continue; | |
16116 | ||
16117 | char * next; | |
16118 | char * end; | |
16119 | size_t data_remaining; | |
16120 | size_t min_notesz; | |
16121 | Elf_External_Note * enote; | |
16122 | Elf_Internal_Note inote; | |
16123 | ||
16124 | uint64_t offset = shdr->sh_offset; | |
16125 | uint64_t align = shdr->sh_addralign; | |
16126 | uint64_t length = shdr->sh_size; | |
16127 | ||
16128 | enote = (Elf_External_Note *) get_section_contents (shdr, filedata); | |
16129 | if (enote == NULL) | |
16130 | continue; | |
16131 | ||
16132 | if (align < 4) | |
16133 | align = 4; | |
16134 | else if (align != 4 && align != 8) | |
16135 | { | |
16136 | free (enote); | |
16137 | continue; | |
16138 | } | |
16139 | ||
16140 | end = (char *) enote + length; | |
16141 | data_remaining = end - (char *) enote; | |
16142 | ||
16143 | if (!is_ia64_vms (filedata)) | |
16144 | { | |
16145 | min_notesz = offsetof (Elf_External_Note, name); | |
16146 | if (data_remaining < min_notesz) | |
16147 | { | |
16148 | warn (_("\ | |
16149 | malformed note encountered in section %s whilst scanning for build-id note\n"), | |
16150 | printable_section_name (filedata, shdr)); | |
16151 | free (enote); | |
16152 | continue; | |
16153 | } | |
16154 | data_remaining -= min_notesz; | |
16155 | ||
16156 | inote.type = BYTE_GET (enote->type); | |
16157 | inote.namesz = BYTE_GET (enote->namesz); | |
16158 | inote.namedata = enote->name; | |
16159 | inote.descsz = BYTE_GET (enote->descsz); | |
16160 | inote.descdata = ((char *) enote | |
16161 | + ELF_NOTE_DESC_OFFSET (inote.namesz, align)); | |
16162 | inote.descpos = offset + (inote.descdata - (char *) enote); | |
16163 | next = ((char *) enote | |
16164 | + ELF_NOTE_NEXT_OFFSET (inote.namesz, inote.descsz, align)); | |
16165 | } | |
16166 | else | |
16167 | { | |
16168 | Elf64_External_VMS_Note *vms_enote; | |
16169 | ||
16170 | /* PR binutils/15191 | |
16171 | Make sure that there is enough data to read. */ | |
16172 | min_notesz = offsetof (Elf64_External_VMS_Note, name); | |
16173 | if (data_remaining < min_notesz) | |
16174 | { | |
16175 | warn (_("\ | |
16176 | malformed note encountered in section %s whilst scanning for build-id note\n"), | |
16177 | printable_section_name (filedata, shdr)); | |
16178 | free (enote); | |
16179 | continue; | |
16180 | } | |
16181 | data_remaining -= min_notesz; | |
16182 | ||
16183 | vms_enote = (Elf64_External_VMS_Note *) enote; | |
16184 | inote.type = BYTE_GET (vms_enote->type); | |
16185 | inote.namesz = BYTE_GET (vms_enote->namesz); | |
16186 | inote.namedata = vms_enote->name; | |
16187 | inote.descsz = BYTE_GET (vms_enote->descsz); | |
16188 | inote.descdata = inote.namedata + align_power (inote.namesz, 3); | |
16189 | inote.descpos = offset + (inote.descdata - (char *) enote); | |
16190 | next = inote.descdata + align_power (inote.descsz, 3); | |
16191 | } | |
16192 | ||
16193 | /* Skip malformed notes. */ | |
16194 | if ((size_t) (inote.descdata - inote.namedata) < inote.namesz | |
16195 | || (size_t) (inote.descdata - inote.namedata) > data_remaining | |
16196 | || (size_t) (next - inote.descdata) < inote.descsz | |
16197 | || ((size_t) (next - inote.descdata) | |
16198 | > data_remaining - (size_t) (inote.descdata - inote.namedata))) | |
16199 | { | |
16200 | warn (_("\ | |
16201 | malformed note encountered in section %s whilst scanning for build-id note\n"), | |
16202 | printable_section_name (filedata, shdr)); | |
16203 | free (enote); | |
16204 | continue; | |
16205 | } | |
16206 | ||
16207 | /* Check if this is the build-id note. If so then convert the build-id | |
16208 | bytes to a hex string. */ | |
16209 | if (inote.namesz > 0 | |
16210 | && startswith (inote.namedata, "GNU") | |
16211 | && inote.type == NT_GNU_BUILD_ID) | |
16212 | { | |
16213 | size_t j; | |
16214 | char * build_id; | |
16215 | ||
16216 | build_id = malloc (inote.descsz * 2 + 1); | |
16217 | if (build_id == NULL) | |
16218 | { | |
16219 | free (enote); | |
16220 | return NULL; | |
16221 | } | |
16222 | ||
16223 | for (j = 0; j < inote.descsz; ++j) | |
16224 | sprintf (build_id + (j * 2), "%02x", inote.descdata[j] & 0xff); | |
16225 | build_id[inote.descsz * 2] = '\0'; | |
16226 | free (enote); | |
16227 | ||
16228 | return (unsigned char *) build_id; | |
16229 | } | |
16230 | free (enote); | |
16231 | } | |
16232 | ||
16233 | return NULL; | |
16234 | } | |
16235 | #endif /* HAVE_LIBDEBUGINFOD */ | |
16236 | ||
16237 | /* If this is not NULL, load_debug_section will only look for sections | |
16238 | within the list of sections given here. */ | |
16239 | static unsigned int * section_subset = NULL; | |
16240 | ||
16241 | bool | |
16242 | load_debug_section (enum dwarf_section_display_enum debug, void * data) | |
16243 | { | |
16244 | struct dwarf_section * section = &debug_displays [debug].section; | |
16245 | Elf_Internal_Shdr * sec; | |
16246 | Filedata * filedata = (Filedata *) data; | |
16247 | ||
16248 | if (!dump_any_debugging) | |
16249 | return false; | |
16250 | ||
16251 | /* Without section headers we cannot find any sections. */ | |
16252 | if (filedata->section_headers == NULL) | |
16253 | return false; | |
16254 | ||
16255 | if (filedata->string_table == NULL | |
16256 | && filedata->file_header.e_shstrndx != SHN_UNDEF | |
16257 | && filedata->file_header.e_shstrndx < filedata->file_header.e_shnum) | |
16258 | { | |
16259 | Elf_Internal_Shdr * strs; | |
16260 | ||
16261 | /* Read in the string table, so that we have section names to scan. */ | |
16262 | strs = filedata->section_headers + filedata->file_header.e_shstrndx; | |
16263 | ||
16264 | if (strs != NULL && strs->sh_size != 0) | |
16265 | { | |
16266 | filedata->string_table | |
16267 | = (char *) get_data (NULL, filedata, strs->sh_offset, | |
16268 | 1, strs->sh_size, _("string table")); | |
16269 | ||
16270 | filedata->string_table_length | |
16271 | = filedata->string_table != NULL ? strs->sh_size : 0; | |
16272 | } | |
16273 | } | |
16274 | ||
16275 | /* Locate the debug section. */ | |
16276 | sec = find_section_in_set (filedata, section->uncompressed_name, section_subset); | |
16277 | if (sec != NULL) | |
16278 | section->name = section->uncompressed_name; | |
16279 | else | |
16280 | { | |
16281 | sec = find_section_in_set (filedata, section->compressed_name, section_subset); | |
16282 | if (sec != NULL) | |
16283 | section->name = section->compressed_name; | |
16284 | } | |
16285 | if (sec == NULL) | |
16286 | return false; | |
16287 | ||
16288 | /* If we're loading from a subset of sections, and we've loaded | |
16289 | a section matching this name before, it's likely that it's a | |
16290 | different one. */ | |
16291 | if (section_subset != NULL) | |
16292 | free_debug_section (debug); | |
16293 | ||
16294 | return load_specific_debug_section (debug, sec, data); | |
16295 | } | |
16296 | ||
16297 | void | |
16298 | free_debug_section (enum dwarf_section_display_enum debug) | |
16299 | { | |
16300 | struct dwarf_section * section = &debug_displays [debug].section; | |
16301 | ||
16302 | if (section->start == NULL) | |
16303 | return; | |
16304 | ||
16305 | free ((char *) section->start); | |
16306 | section->start = NULL; | |
16307 | section->address = 0; | |
16308 | section->size = 0; | |
16309 | ||
16310 | free (section->reloc_info); | |
16311 | section->reloc_info = NULL; | |
16312 | section->num_relocs = 0; | |
16313 | } | |
16314 | ||
16315 | static bool | |
16316 | display_debug_section (int shndx, Elf_Internal_Shdr * section, Filedata * filedata) | |
16317 | { | |
16318 | const char *name = (section_name_valid (filedata, section) | |
16319 | ? section_name (filedata, section) : ""); | |
16320 | const char *print_name = printable_section_name (filedata, section); | |
16321 | uint64_t length; | |
16322 | bool result = true; | |
16323 | int i; | |
16324 | ||
16325 | length = section->sh_size; | |
16326 | if (length == 0) | |
16327 | { | |
16328 | printf (_("\nSection '%s' has no debugging data.\n"), print_name); | |
16329 | return true; | |
16330 | } | |
16331 | if (section->sh_type == SHT_NOBITS) | |
16332 | { | |
16333 | /* There is no point in dumping the contents of a debugging section | |
16334 | which has the NOBITS type - the bits in the file will be random. | |
16335 | This can happen when a file containing a .eh_frame section is | |
16336 | stripped with the --only-keep-debug command line option. */ | |
16337 | printf (_("section '%s' has the NOBITS type - its contents are unreliable.\n"), | |
16338 | print_name); | |
16339 | return false; | |
16340 | } | |
16341 | ||
16342 | if (startswith (name, ".gnu.linkonce.wi.")) | |
16343 | name = ".debug_info"; | |
16344 | ||
16345 | /* See if we know how to display the contents of this section. */ | |
16346 | for (i = 0; i < max; i++) | |
16347 | { | |
16348 | enum dwarf_section_display_enum id = (enum dwarf_section_display_enum) i; | |
16349 | struct dwarf_section_display * display = debug_displays + i; | |
16350 | struct dwarf_section * sec = & display->section; | |
16351 | ||
16352 | if (streq (sec->uncompressed_name, name) | |
16353 | || (id == line && startswith (name, ".debug_line.")) | |
16354 | || streq (sec->compressed_name, name)) | |
16355 | { | |
16356 | bool secondary = (section != find_section (filedata, name)); | |
16357 | ||
16358 | if (secondary) | |
16359 | free_debug_section (id); | |
16360 | ||
16361 | if (i == line && startswith (name, ".debug_line.")) | |
16362 | sec->name = name; | |
16363 | else if (streq (sec->uncompressed_name, name)) | |
16364 | sec->name = sec->uncompressed_name; | |
16365 | else | |
16366 | sec->name = sec->compressed_name; | |
16367 | ||
16368 | if (load_specific_debug_section (id, section, filedata)) | |
16369 | { | |
16370 | /* If this debug section is part of a CU/TU set in a .dwp file, | |
16371 | restrict load_debug_section to the sections in that set. */ | |
16372 | section_subset = find_cu_tu_set (filedata, shndx); | |
16373 | ||
16374 | result &= display->display (sec, filedata); | |
16375 | ||
16376 | section_subset = NULL; | |
16377 | ||
16378 | if (secondary || (id != info && id != abbrev && id != debug_addr)) | |
16379 | free_debug_section (id); | |
16380 | } | |
16381 | break; | |
16382 | } | |
16383 | } | |
16384 | ||
16385 | if (i == max) | |
16386 | { | |
16387 | printf (_("Unrecognized debug section: %s\n"), print_name); | |
16388 | result = false; | |
16389 | } | |
16390 | ||
16391 | return result; | |
16392 | } | |
16393 | ||
16394 | /* Set DUMP_SECTS for all sections where dumps were requested | |
16395 | based on section name. */ | |
16396 | ||
16397 | static void | |
16398 | initialise_dumps_byname (Filedata * filedata) | |
16399 | { | |
16400 | struct dump_list_entry * cur; | |
16401 | ||
16402 | for (cur = dump_sects_byname; cur; cur = cur->next) | |
16403 | { | |
16404 | unsigned int i; | |
16405 | bool any = false; | |
16406 | ||
16407 | for (i = 0; i < filedata->file_header.e_shnum; i++) | |
16408 | if (section_name_valid (filedata, filedata->section_headers + i) | |
16409 | && streq (section_name (filedata, filedata->section_headers + i), | |
16410 | cur->name)) | |
16411 | { | |
16412 | request_dump_bynumber (&filedata->dump, i, cur->type); | |
16413 | any = true; | |
16414 | } | |
16415 | ||
16416 | if (!any && !filedata->is_separate) | |
16417 | warn (_("Section '%s' was not dumped because it does not exist\n"), | |
16418 | cur->name); | |
16419 | } | |
16420 | } | |
16421 | ||
16422 | static bool | |
16423 | process_section_contents (Filedata * filedata) | |
16424 | { | |
16425 | Elf_Internal_Shdr * section; | |
16426 | unsigned int i; | |
16427 | bool res = true; | |
16428 | ||
16429 | if (! do_dump) | |
16430 | return true; | |
16431 | ||
16432 | initialise_dumps_byname (filedata); | |
16433 | ||
16434 | for (i = 0, section = filedata->section_headers; | |
16435 | i < filedata->file_header.e_shnum && i < filedata->dump.num_dump_sects; | |
16436 | i++, section++) | |
16437 | { | |
16438 | dump_type dump = filedata->dump.dump_sects[i]; | |
16439 | ||
16440 | if (filedata->is_separate && ! process_links) | |
16441 | dump &= DEBUG_DUMP; | |
16442 | ||
16443 | #ifdef SUPPORT_DISASSEMBLY | |
16444 | if (dump & DISASS_DUMP) | |
16445 | { | |
16446 | if (! disassemble_section (section, filedata)) | |
16447 | res = false; | |
16448 | } | |
16449 | #endif | |
16450 | if (dump & HEX_DUMP) | |
16451 | { | |
16452 | if (! dump_section_as_bytes (section, filedata, false)) | |
16453 | res = false; | |
16454 | } | |
16455 | ||
16456 | if (dump & RELOC_DUMP) | |
16457 | { | |
16458 | if (! dump_section_as_bytes (section, filedata, true)) | |
16459 | res = false; | |
16460 | } | |
16461 | ||
16462 | if (dump & STRING_DUMP) | |
16463 | { | |
16464 | if (! dump_section_as_strings (section, filedata)) | |
16465 | res = false; | |
16466 | } | |
16467 | ||
16468 | if (dump & DEBUG_DUMP) | |
16469 | { | |
16470 | if (! display_debug_section (i, section, filedata)) | |
16471 | res = false; | |
16472 | } | |
16473 | ||
16474 | #ifdef ENABLE_LIBCTF | |
16475 | if (dump & CTF_DUMP) | |
16476 | { | |
16477 | if (! dump_section_as_ctf (section, filedata)) | |
16478 | res = false; | |
16479 | } | |
16480 | #endif | |
16481 | if (dump & SFRAME_DUMP) | |
16482 | { | |
16483 | if (! dump_section_as_sframe (section, filedata)) | |
16484 | res = false; | |
16485 | } | |
16486 | } | |
16487 | ||
16488 | if (! filedata->is_separate) | |
16489 | { | |
16490 | /* Check to see if the user requested a | |
16491 | dump of a section that does not exist. */ | |
16492 | for (; i < filedata->dump.num_dump_sects; i++) | |
16493 | if (filedata->dump.dump_sects[i]) | |
16494 | { | |
16495 | warn (_("Section %d was not dumped because it does not exist!\n"), i); | |
16496 | res = false; | |
16497 | } | |
16498 | } | |
16499 | ||
16500 | return res; | |
16501 | } | |
16502 | ||
16503 | static void | |
16504 | process_mips_fpe_exception (int mask) | |
16505 | { | |
16506 | if (mask) | |
16507 | { | |
16508 | bool first = true; | |
16509 | ||
16510 | if (mask & OEX_FPU_INEX) | |
16511 | fputs ("INEX", stdout), first = false; | |
16512 | if (mask & OEX_FPU_UFLO) | |
16513 | printf ("%sUFLO", first ? "" : "|"), first = false; | |
16514 | if (mask & OEX_FPU_OFLO) | |
16515 | printf ("%sOFLO", first ? "" : "|"), first = false; | |
16516 | if (mask & OEX_FPU_DIV0) | |
16517 | printf ("%sDIV0", first ? "" : "|"), first = false; | |
16518 | if (mask & OEX_FPU_INVAL) | |
16519 | printf ("%sINVAL", first ? "" : "|"); | |
16520 | } | |
16521 | else | |
16522 | fputs ("0", stdout); | |
16523 | } | |
16524 | ||
16525 | /* Display's the value of TAG at location P. If TAG is | |
16526 | greater than 0 it is assumed to be an unknown tag, and | |
16527 | a message is printed to this effect. Otherwise it is | |
16528 | assumed that a message has already been printed. | |
16529 | ||
16530 | If the bottom bit of TAG is set it assumed to have a | |
16531 | string value, otherwise it is assumed to have an integer | |
16532 | value. | |
16533 | ||
16534 | Returns an updated P pointing to the first unread byte | |
16535 | beyond the end of TAG's value. | |
16536 | ||
16537 | Reads at or beyond END will not be made. */ | |
16538 | ||
16539 | static unsigned char * | |
16540 | display_tag_value (signed int tag, | |
16541 | unsigned char * p, | |
16542 | const unsigned char * const end) | |
16543 | { | |
16544 | uint64_t val; | |
16545 | ||
16546 | if (tag > 0) | |
16547 | printf (" Tag_unknown_%d: ", tag); | |
16548 | ||
16549 | if (p >= end) | |
16550 | { | |
16551 | warn (_("<corrupt tag>\n")); | |
16552 | } | |
16553 | else if (tag & 1) | |
16554 | { | |
16555 | /* PR 17531 file: 027-19978-0.004. */ | |
16556 | size_t maxlen = (end - p) - 1; | |
16557 | ||
16558 | putchar ('"'); | |
16559 | if (maxlen > 0) | |
16560 | { | |
16561 | print_symbol ((int) maxlen, (const char *) p); | |
16562 | p += strnlen ((char *) p, maxlen) + 1; | |
16563 | } | |
16564 | else | |
16565 | { | |
16566 | printf (_("<corrupt string tag>")); | |
16567 | p = (unsigned char *) end; | |
16568 | } | |
16569 | printf ("\"\n"); | |
16570 | } | |
16571 | else | |
16572 | { | |
16573 | READ_ULEB (val, p, end); | |
16574 | printf ("%" PRId64 " (0x%" PRIx64 ")\n", val, val); | |
16575 | } | |
16576 | ||
16577 | assert (p <= end); | |
16578 | return p; | |
16579 | } | |
16580 | ||
16581 | /* ARC ABI attributes section. */ | |
16582 | ||
16583 | static unsigned char * | |
16584 | display_arc_attribute (unsigned char * p, | |
16585 | const unsigned char * const end) | |
16586 | { | |
16587 | unsigned int tag; | |
16588 | unsigned int val; | |
16589 | ||
16590 | READ_ULEB (tag, p, end); | |
16591 | ||
16592 | switch (tag) | |
16593 | { | |
16594 | case Tag_ARC_PCS_config: | |
16595 | READ_ULEB (val, p, end); | |
16596 | printf (" Tag_ARC_PCS_config: "); | |
16597 | switch (val) | |
16598 | { | |
16599 | case 0: | |
16600 | printf (_("Absent/Non standard\n")); | |
16601 | break; | |
16602 | case 1: | |
16603 | printf (_("Bare metal/mwdt\n")); | |
16604 | break; | |
16605 | case 2: | |
16606 | printf (_("Bare metal/newlib\n")); | |
16607 | break; | |
16608 | case 3: | |
16609 | printf (_("Linux/uclibc\n")); | |
16610 | break; | |
16611 | case 4: | |
16612 | printf (_("Linux/glibc\n")); | |
16613 | break; | |
16614 | default: | |
16615 | printf (_("Unknown\n")); | |
16616 | break; | |
16617 | } | |
16618 | break; | |
16619 | ||
16620 | case Tag_ARC_CPU_base: | |
16621 | READ_ULEB (val, p, end); | |
16622 | printf (" Tag_ARC_CPU_base: "); | |
16623 | switch (val) | |
16624 | { | |
16625 | default: | |
16626 | case TAG_CPU_NONE: | |
16627 | printf (_("Absent\n")); | |
16628 | break; | |
16629 | case TAG_CPU_ARC6xx: | |
16630 | printf ("ARC6xx\n"); | |
16631 | break; | |
16632 | case TAG_CPU_ARC7xx: | |
16633 | printf ("ARC7xx\n"); | |
16634 | break; | |
16635 | case TAG_CPU_ARCEM: | |
16636 | printf ("ARCEM\n"); | |
16637 | break; | |
16638 | case TAG_CPU_ARCHS: | |
16639 | printf ("ARCHS\n"); | |
16640 | break; | |
16641 | } | |
16642 | break; | |
16643 | ||
16644 | case Tag_ARC_CPU_variation: | |
16645 | READ_ULEB (val, p, end); | |
16646 | printf (" Tag_ARC_CPU_variation: "); | |
16647 | switch (val) | |
16648 | { | |
16649 | default: | |
16650 | if (val > 0 && val < 16) | |
16651 | printf ("Core%d\n", val); | |
16652 | else | |
16653 | printf ("Unknown\n"); | |
16654 | break; | |
16655 | ||
16656 | case 0: | |
16657 | printf (_("Absent\n")); | |
16658 | break; | |
16659 | } | |
16660 | break; | |
16661 | ||
16662 | case Tag_ARC_CPU_name: | |
16663 | printf (" Tag_ARC_CPU_name: "); | |
16664 | p = display_tag_value (-1, p, end); | |
16665 | break; | |
16666 | ||
16667 | case Tag_ARC_ABI_rf16: | |
16668 | READ_ULEB (val, p, end); | |
16669 | printf (" Tag_ARC_ABI_rf16: %s\n", val ? _("yes") : _("no")); | |
16670 | break; | |
16671 | ||
16672 | case Tag_ARC_ABI_osver: | |
16673 | READ_ULEB (val, p, end); | |
16674 | printf (" Tag_ARC_ABI_osver: v%d\n", val); | |
16675 | break; | |
16676 | ||
16677 | case Tag_ARC_ABI_pic: | |
16678 | case Tag_ARC_ABI_sda: | |
16679 | READ_ULEB (val, p, end); | |
16680 | printf (tag == Tag_ARC_ABI_sda ? " Tag_ARC_ABI_sda: " | |
16681 | : " Tag_ARC_ABI_pic: "); | |
16682 | switch (val) | |
16683 | { | |
16684 | case 0: | |
16685 | printf (_("Absent\n")); | |
16686 | break; | |
16687 | case 1: | |
16688 | printf ("MWDT\n"); | |
16689 | break; | |
16690 | case 2: | |
16691 | printf ("GNU\n"); | |
16692 | break; | |
16693 | default: | |
16694 | printf (_("Unknown\n")); | |
16695 | break; | |
16696 | } | |
16697 | break; | |
16698 | ||
16699 | case Tag_ARC_ABI_tls: | |
16700 | READ_ULEB (val, p, end); | |
16701 | printf (" Tag_ARC_ABI_tls: %s\n", val ? "r25": "none"); | |
16702 | break; | |
16703 | ||
16704 | case Tag_ARC_ABI_enumsize: | |
16705 | READ_ULEB (val, p, end); | |
16706 | printf (" Tag_ARC_ABI_enumsize: %s\n", val ? _("default") : | |
16707 | _("smallest")); | |
16708 | break; | |
16709 | ||
16710 | case Tag_ARC_ABI_exceptions: | |
16711 | READ_ULEB (val, p, end); | |
16712 | printf (" Tag_ARC_ABI_exceptions: %s\n", val ? _("OPTFP") | |
16713 | : _("default")); | |
16714 | break; | |
16715 | ||
16716 | case Tag_ARC_ABI_double_size: | |
16717 | READ_ULEB (val, p, end); | |
16718 | printf (" Tag_ARC_ABI_double_size: %d\n", val); | |
16719 | break; | |
16720 | ||
16721 | case Tag_ARC_ISA_config: | |
16722 | printf (" Tag_ARC_ISA_config: "); | |
16723 | p = display_tag_value (-1, p, end); | |
16724 | break; | |
16725 | ||
16726 | case Tag_ARC_ISA_apex: | |
16727 | printf (" Tag_ARC_ISA_apex: "); | |
16728 | p = display_tag_value (-1, p, end); | |
16729 | break; | |
16730 | ||
16731 | case Tag_ARC_ISA_mpy_option: | |
16732 | READ_ULEB (val, p, end); | |
16733 | printf (" Tag_ARC_ISA_mpy_option: %d\n", val); | |
16734 | break; | |
16735 | ||
16736 | case Tag_ARC_ATR_version: | |
16737 | READ_ULEB (val, p, end); | |
16738 | printf (" Tag_ARC_ATR_version: %d\n", val); | |
16739 | break; | |
16740 | ||
16741 | default: | |
16742 | return display_tag_value (tag & 1, p, end); | |
16743 | } | |
16744 | ||
16745 | return p; | |
16746 | } | |
16747 | ||
16748 | /* ARM EABI attributes section. */ | |
16749 | typedef struct | |
16750 | { | |
16751 | unsigned int tag; | |
16752 | const char * name; | |
16753 | /* 0 = special, 1 = string, 2 = uleb123, > 0x80 == table lookup. */ | |
16754 | unsigned int type; | |
16755 | const char *const *table; | |
16756 | } arm_attr_public_tag; | |
16757 | ||
16758 | static const char *const arm_attr_tag_CPU_arch[] = | |
16759 | {"Pre-v4", "v4", "v4T", "v5T", "v5TE", "v5TEJ", "v6", "v6KZ", "v6T2", | |
16760 | "v6K", "v7", "v6-M", "v6S-M", "v7E-M", "v8", "v8-R", "v8-M.baseline", | |
16761 | "v8-M.mainline", "v8.1-A", "v8.2-A", "v8.3-A", | |
16762 | "v8.1-M.mainline", "v9"}; | |
16763 | static const char *const arm_attr_tag_ARM_ISA_use[] = {"No", "Yes"}; | |
16764 | static const char *const arm_attr_tag_THUMB_ISA_use[] = | |
16765 | {"No", "Thumb-1", "Thumb-2", "Yes"}; | |
16766 | static const char *const arm_attr_tag_FP_arch[] = | |
16767 | {"No", "VFPv1", "VFPv2", "VFPv3", "VFPv3-D16", "VFPv4", "VFPv4-D16", | |
16768 | "FP for ARMv8", "FPv5/FP-D16 for ARMv8"}; | |
16769 | static const char *const arm_attr_tag_WMMX_arch[] = {"No", "WMMXv1", "WMMXv2"}; | |
16770 | static const char *const arm_attr_tag_Advanced_SIMD_arch[] = | |
16771 | {"No", "NEONv1", "NEONv1 with Fused-MAC", "NEON for ARMv8", | |
16772 | "NEON for ARMv8.1"}; | |
16773 | static const char *const arm_attr_tag_PCS_config[] = | |
16774 | {"None", "Bare platform", "Linux application", "Linux DSO", "PalmOS 2004", | |
16775 | "PalmOS (reserved)", "SymbianOS 2004", "SymbianOS (reserved)"}; | |
16776 | static const char *const arm_attr_tag_ABI_PCS_R9_use[] = | |
16777 | {"V6", "SB", "TLS", "Unused"}; | |
16778 | static const char *const arm_attr_tag_ABI_PCS_RW_data[] = | |
16779 | {"Absolute", "PC-relative", "SB-relative", "None"}; | |
16780 | static const char *const arm_attr_tag_ABI_PCS_RO_data[] = | |
16781 | {"Absolute", "PC-relative", "None"}; | |
16782 | static const char *const arm_attr_tag_ABI_PCS_GOT_use[] = | |
16783 | {"None", "direct", "GOT-indirect"}; | |
16784 | static const char *const arm_attr_tag_ABI_PCS_wchar_t[] = | |
16785 | {"None", "??? 1", "2", "??? 3", "4"}; | |
16786 | static const char *const arm_attr_tag_ABI_FP_rounding[] = {"Unused", "Needed"}; | |
16787 | static const char *const arm_attr_tag_ABI_FP_denormal[] = | |
16788 | {"Unused", "Needed", "Sign only"}; | |
16789 | static const char *const arm_attr_tag_ABI_FP_exceptions[] = {"Unused", "Needed"}; | |
16790 | static const char *const arm_attr_tag_ABI_FP_user_exceptions[] = {"Unused", "Needed"}; | |
16791 | static const char *const arm_attr_tag_ABI_FP_number_model[] = | |
16792 | {"Unused", "Finite", "RTABI", "IEEE 754"}; | |
16793 | static const char *const arm_attr_tag_ABI_enum_size[] = | |
16794 | {"Unused", "small", "int", "forced to int"}; | |
16795 | static const char *const arm_attr_tag_ABI_HardFP_use[] = | |
16796 | {"As Tag_FP_arch", "SP only", "Reserved", "Deprecated"}; | |
16797 | static const char *const arm_attr_tag_ABI_VFP_args[] = | |
16798 | {"AAPCS", "VFP registers", "custom", "compatible"}; | |
16799 | static const char *const arm_attr_tag_ABI_WMMX_args[] = | |
16800 | {"AAPCS", "WMMX registers", "custom"}; | |
16801 | static const char *const arm_attr_tag_ABI_optimization_goals[] = | |
16802 | {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size", | |
16803 | "Aggressive Size", "Prefer Debug", "Aggressive Debug"}; | |
16804 | static const char *const arm_attr_tag_ABI_FP_optimization_goals[] = | |
16805 | {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size", | |
16806 | "Aggressive Size", "Prefer Accuracy", "Aggressive Accuracy"}; | |
16807 | static const char *const arm_attr_tag_CPU_unaligned_access[] = {"None", "v6"}; | |
16808 | static const char *const arm_attr_tag_FP_HP_extension[] = | |
16809 | {"Not Allowed", "Allowed"}; | |
16810 | static const char *const arm_attr_tag_ABI_FP_16bit_format[] = | |
16811 | {"None", "IEEE 754", "Alternative Format"}; | |
16812 | static const char *const arm_attr_tag_DSP_extension[] = | |
16813 | {"Follow architecture", "Allowed"}; | |
16814 | static const char *const arm_attr_tag_MPextension_use[] = | |
16815 | {"Not Allowed", "Allowed"}; | |
16816 | static const char *const arm_attr_tag_DIV_use[] = | |
16817 | {"Allowed in Thumb-ISA, v7-R or v7-M", "Not allowed", | |
16818 | "Allowed in v7-A with integer division extension"}; | |
16819 | static const char *const arm_attr_tag_T2EE_use[] = {"Not Allowed", "Allowed"}; | |
16820 | static const char *const arm_attr_tag_Virtualization_use[] = | |
16821 | {"Not Allowed", "TrustZone", "Virtualization Extensions", | |
16822 | "TrustZone and Virtualization Extensions"}; | |
16823 | static const char *const arm_attr_tag_MPextension_use_legacy[] = | |
16824 | {"Not Allowed", "Allowed"}; | |
16825 | ||
16826 | static const char *const arm_attr_tag_MVE_arch[] = | |
16827 | {"No MVE", "MVE Integer only", "MVE Integer and FP"}; | |
16828 | ||
16829 | static const char * arm_attr_tag_PAC_extension[] = | |
16830 | {"No PAC/AUT instructions", | |
16831 | "PAC/AUT instructions permitted in the NOP space", | |
16832 | "PAC/AUT instructions permitted in the NOP and in the non-NOP space"}; | |
16833 | ||
16834 | static const char * arm_attr_tag_BTI_extension[] = | |
16835 | {"BTI instructions not permitted", | |
16836 | "BTI instructions permitted in the NOP space", | |
16837 | "BTI instructions permitted in the NOP and in the non-NOP space"}; | |
16838 | ||
16839 | static const char * arm_attr_tag_BTI_use[] = | |
16840 | {"Compiled without branch target enforcement", | |
16841 | "Compiled with branch target enforcement"}; | |
16842 | ||
16843 | static const char * arm_attr_tag_PACRET_use[] = | |
16844 | {"Compiled without return address signing and authentication", | |
16845 | "Compiled with return address signing and authentication"}; | |
16846 | ||
16847 | #define LOOKUP(id, name) \ | |
16848 | {id, #name, 0x80 | ARRAY_SIZE(arm_attr_tag_##name), arm_attr_tag_##name} | |
16849 | static arm_attr_public_tag arm_attr_public_tags[] = | |
16850 | { | |
16851 | {4, "CPU_raw_name", 1, NULL}, | |
16852 | {5, "CPU_name", 1, NULL}, | |
16853 | LOOKUP(6, CPU_arch), | |
16854 | {7, "CPU_arch_profile", 0, NULL}, | |
16855 | LOOKUP(8, ARM_ISA_use), | |
16856 | LOOKUP(9, THUMB_ISA_use), | |
16857 | LOOKUP(10, FP_arch), | |
16858 | LOOKUP(11, WMMX_arch), | |
16859 | LOOKUP(12, Advanced_SIMD_arch), | |
16860 | LOOKUP(13, PCS_config), | |
16861 | LOOKUP(14, ABI_PCS_R9_use), | |
16862 | LOOKUP(15, ABI_PCS_RW_data), | |
16863 | LOOKUP(16, ABI_PCS_RO_data), | |
16864 | LOOKUP(17, ABI_PCS_GOT_use), | |
16865 | LOOKUP(18, ABI_PCS_wchar_t), | |
16866 | LOOKUP(19, ABI_FP_rounding), | |
16867 | LOOKUP(20, ABI_FP_denormal), | |
16868 | LOOKUP(21, ABI_FP_exceptions), | |
16869 | LOOKUP(22, ABI_FP_user_exceptions), | |
16870 | LOOKUP(23, ABI_FP_number_model), | |
16871 | {24, "ABI_align_needed", 0, NULL}, | |
16872 | {25, "ABI_align_preserved", 0, NULL}, | |
16873 | LOOKUP(26, ABI_enum_size), | |
16874 | LOOKUP(27, ABI_HardFP_use), | |
16875 | LOOKUP(28, ABI_VFP_args), | |
16876 | LOOKUP(29, ABI_WMMX_args), | |
16877 | LOOKUP(30, ABI_optimization_goals), | |
16878 | LOOKUP(31, ABI_FP_optimization_goals), | |
16879 | {32, "compatibility", 0, NULL}, | |
16880 | LOOKUP(34, CPU_unaligned_access), | |
16881 | LOOKUP(36, FP_HP_extension), | |
16882 | LOOKUP(38, ABI_FP_16bit_format), | |
16883 | LOOKUP(42, MPextension_use), | |
16884 | LOOKUP(44, DIV_use), | |
16885 | LOOKUP(46, DSP_extension), | |
16886 | LOOKUP(48, MVE_arch), | |
16887 | LOOKUP(50, PAC_extension), | |
16888 | LOOKUP(52, BTI_extension), | |
16889 | LOOKUP(74, BTI_use), | |
16890 | LOOKUP(76, PACRET_use), | |
16891 | {64, "nodefaults", 0, NULL}, | |
16892 | {65, "also_compatible_with", 0, NULL}, | |
16893 | LOOKUP(66, T2EE_use), | |
16894 | {67, "conformance", 1, NULL}, | |
16895 | LOOKUP(68, Virtualization_use), | |
16896 | LOOKUP(70, MPextension_use_legacy) | |
16897 | }; | |
16898 | #undef LOOKUP | |
16899 | ||
16900 | static unsigned char * | |
16901 | display_arm_attribute (unsigned char * p, | |
16902 | const unsigned char * const end) | |
16903 | { | |
16904 | unsigned int tag; | |
16905 | unsigned int val; | |
16906 | arm_attr_public_tag * attr; | |
16907 | unsigned i; | |
16908 | unsigned int type; | |
16909 | ||
16910 | READ_ULEB (tag, p, end); | |
16911 | attr = NULL; | |
16912 | for (i = 0; i < ARRAY_SIZE (arm_attr_public_tags); i++) | |
16913 | { | |
16914 | if (arm_attr_public_tags[i].tag == tag) | |
16915 | { | |
16916 | attr = &arm_attr_public_tags[i]; | |
16917 | break; | |
16918 | } | |
16919 | } | |
16920 | ||
16921 | if (attr) | |
16922 | { | |
16923 | printf (" Tag_%s: ", attr->name); | |
16924 | switch (attr->type) | |
16925 | { | |
16926 | case 0: | |
16927 | switch (tag) | |
16928 | { | |
16929 | case 7: /* Tag_CPU_arch_profile. */ | |
16930 | READ_ULEB (val, p, end); | |
16931 | switch (val) | |
16932 | { | |
16933 | case 0: printf (_("None\n")); break; | |
16934 | case 'A': printf (_("Application\n")); break; | |
16935 | case 'R': printf (_("Realtime\n")); break; | |
16936 | case 'M': printf (_("Microcontroller\n")); break; | |
16937 | case 'S': printf (_("Application or Realtime\n")); break; | |
16938 | default: printf ("??? (%d)\n", val); break; | |
16939 | } | |
16940 | break; | |
16941 | ||
16942 | case 24: /* Tag_align_needed. */ | |
16943 | READ_ULEB (val, p, end); | |
16944 | switch (val) | |
16945 | { | |
16946 | case 0: printf (_("None\n")); break; | |
16947 | case 1: printf (_("8-byte\n")); break; | |
16948 | case 2: printf (_("4-byte\n")); break; | |
16949 | case 3: printf ("??? 3\n"); break; | |
16950 | default: | |
16951 | if (val <= 12) | |
16952 | printf (_("8-byte and up to %d-byte extended\n"), | |
16953 | 1 << val); | |
16954 | else | |
16955 | printf ("??? (%d)\n", val); | |
16956 | break; | |
16957 | } | |
16958 | break; | |
16959 | ||
16960 | case 25: /* Tag_align_preserved. */ | |
16961 | READ_ULEB (val, p, end); | |
16962 | switch (val) | |
16963 | { | |
16964 | case 0: printf (_("None\n")); break; | |
16965 | case 1: printf (_("8-byte, except leaf SP\n")); break; | |
16966 | case 2: printf (_("8-byte\n")); break; | |
16967 | case 3: printf ("??? 3\n"); break; | |
16968 | default: | |
16969 | if (val <= 12) | |
16970 | printf (_("8-byte and up to %d-byte extended\n"), | |
16971 | 1 << val); | |
16972 | else | |
16973 | printf ("??? (%d)\n", val); | |
16974 | break; | |
16975 | } | |
16976 | break; | |
16977 | ||
16978 | case 32: /* Tag_compatibility. */ | |
16979 | { | |
16980 | READ_ULEB (val, p, end); | |
16981 | printf (_("flag = %d, vendor = "), val); | |
16982 | if (p < end - 1) | |
16983 | { | |
16984 | size_t maxlen = (end - p) - 1; | |
16985 | ||
16986 | print_symbol ((int) maxlen, (const char *) p); | |
16987 | p += strnlen ((char *) p, maxlen) + 1; | |
16988 | } | |
16989 | else | |
16990 | { | |
16991 | printf (_("<corrupt>")); | |
16992 | p = (unsigned char *) end; | |
16993 | } | |
16994 | putchar ('\n'); | |
16995 | } | |
16996 | break; | |
16997 | ||
16998 | case 64: /* Tag_nodefaults. */ | |
16999 | /* PR 17531: file: 001-505008-0.01. */ | |
17000 | if (p < end) | |
17001 | p++; | |
17002 | printf (_("True\n")); | |
17003 | break; | |
17004 | ||
17005 | case 65: /* Tag_also_compatible_with. */ | |
17006 | READ_ULEB (val, p, end); | |
17007 | if (val == 6 /* Tag_CPU_arch. */) | |
17008 | { | |
17009 | READ_ULEB (val, p, end); | |
17010 | if ((unsigned int) val >= ARRAY_SIZE (arm_attr_tag_CPU_arch)) | |
17011 | printf ("??? (%d)\n", val); | |
17012 | else | |
17013 | printf ("%s\n", arm_attr_tag_CPU_arch[val]); | |
17014 | } | |
17015 | else | |
17016 | printf ("???\n"); | |
17017 | while (p < end && *(p++) != '\0' /* NUL terminator. */) | |
17018 | ; | |
17019 | break; | |
17020 | ||
17021 | default: | |
17022 | printf (_("<unknown: %d>\n"), tag); | |
17023 | break; | |
17024 | } | |
17025 | return p; | |
17026 | ||
17027 | case 1: | |
17028 | return display_tag_value (-1, p, end); | |
17029 | case 2: | |
17030 | return display_tag_value (0, p, end); | |
17031 | ||
17032 | default: | |
17033 | assert (attr->type & 0x80); | |
17034 | READ_ULEB (val, p, end); | |
17035 | type = attr->type & 0x7f; | |
17036 | if (val >= type) | |
17037 | printf ("??? (%d)\n", val); | |
17038 | else | |
17039 | printf ("%s\n", attr->table[val]); | |
17040 | return p; | |
17041 | } | |
17042 | } | |
17043 | ||
17044 | return display_tag_value (tag, p, end); | |
17045 | } | |
17046 | ||
17047 | static unsigned char * | |
17048 | display_gnu_attribute (unsigned char * p, | |
17049 | unsigned char * (* display_proc_gnu_attribute) (unsigned char *, unsigned int, const unsigned char * const), | |
17050 | const unsigned char * const end) | |
17051 | { | |
17052 | unsigned int tag; | |
17053 | unsigned int val; | |
17054 | ||
17055 | READ_ULEB (tag, p, end); | |
17056 | ||
17057 | /* Tag_compatibility is the only generic GNU attribute defined at | |
17058 | present. */ | |
17059 | if (tag == 32) | |
17060 | { | |
17061 | READ_ULEB (val, p, end); | |
17062 | ||
17063 | printf (_("flag = %d, vendor = "), val); | |
17064 | if (p == end) | |
17065 | { | |
17066 | printf (_("<corrupt>\n")); | |
17067 | warn (_("corrupt vendor attribute\n")); | |
17068 | } | |
17069 | else | |
17070 | { | |
17071 | if (p < end - 1) | |
17072 | { | |
17073 | size_t maxlen = (end - p) - 1; | |
17074 | ||
17075 | print_symbol ((int) maxlen, (const char *) p); | |
17076 | p += strnlen ((char *) p, maxlen) + 1; | |
17077 | } | |
17078 | else | |
17079 | { | |
17080 | printf (_("<corrupt>")); | |
17081 | p = (unsigned char *) end; | |
17082 | } | |
17083 | putchar ('\n'); | |
17084 | } | |
17085 | return p; | |
17086 | } | |
17087 | ||
17088 | if ((tag & 2) == 0 && display_proc_gnu_attribute) | |
17089 | return display_proc_gnu_attribute (p, tag, end); | |
17090 | ||
17091 | return display_tag_value (tag, p, end); | |
17092 | } | |
17093 | ||
17094 | static unsigned char * | |
17095 | display_m68k_gnu_attribute (unsigned char * p, | |
17096 | unsigned int tag, | |
17097 | const unsigned char * const end) | |
17098 | { | |
17099 | unsigned int val; | |
17100 | ||
17101 | if (tag == Tag_GNU_M68K_ABI_FP) | |
17102 | { | |
17103 | printf (" Tag_GNU_M68K_ABI_FP: "); | |
17104 | if (p == end) | |
17105 | { | |
17106 | printf (_("<corrupt>\n")); | |
17107 | return p; | |
17108 | } | |
17109 | READ_ULEB (val, p, end); | |
17110 | ||
17111 | if (val > 3) | |
17112 | printf ("(%#x), ", val); | |
17113 | ||
17114 | switch (val & 3) | |
17115 | { | |
17116 | case 0: | |
17117 | printf (_("unspecified hard/soft float\n")); | |
17118 | break; | |
17119 | case 1: | |
17120 | printf (_("hard float\n")); | |
17121 | break; | |
17122 | case 2: | |
17123 | printf (_("soft float\n")); | |
17124 | break; | |
17125 | } | |
17126 | return p; | |
17127 | } | |
17128 | ||
17129 | return display_tag_value (tag & 1, p, end); | |
17130 | } | |
17131 | ||
17132 | static unsigned char * | |
17133 | display_power_gnu_attribute (unsigned char * p, | |
17134 | unsigned int tag, | |
17135 | const unsigned char * const end) | |
17136 | { | |
17137 | unsigned int val; | |
17138 | ||
17139 | if (tag == Tag_GNU_Power_ABI_FP) | |
17140 | { | |
17141 | printf (" Tag_GNU_Power_ABI_FP: "); | |
17142 | if (p == end) | |
17143 | { | |
17144 | printf (_("<corrupt>\n")); | |
17145 | return p; | |
17146 | } | |
17147 | READ_ULEB (val, p, end); | |
17148 | ||
17149 | if (val > 15) | |
17150 | printf ("(%#x), ", val); | |
17151 | ||
17152 | switch (val & 3) | |
17153 | { | |
17154 | case 0: | |
17155 | printf (_("unspecified hard/soft float, ")); | |
17156 | break; | |
17157 | case 1: | |
17158 | printf (_("hard float, ")); | |
17159 | break; | |
17160 | case 2: | |
17161 | printf (_("soft float, ")); | |
17162 | break; | |
17163 | case 3: | |
17164 | printf (_("single-precision hard float, ")); | |
17165 | break; | |
17166 | } | |
17167 | ||
17168 | switch (val & 0xC) | |
17169 | { | |
17170 | case 0: | |
17171 | printf (_("unspecified long double\n")); | |
17172 | break; | |
17173 | case 4: | |
17174 | printf (_("128-bit IBM long double\n")); | |
17175 | break; | |
17176 | case 8: | |
17177 | printf (_("64-bit long double\n")); | |
17178 | break; | |
17179 | case 12: | |
17180 | printf (_("128-bit IEEE long double\n")); | |
17181 | break; | |
17182 | } | |
17183 | return p; | |
17184 | } | |
17185 | ||
17186 | if (tag == Tag_GNU_Power_ABI_Vector) | |
17187 | { | |
17188 | printf (" Tag_GNU_Power_ABI_Vector: "); | |
17189 | if (p == end) | |
17190 | { | |
17191 | printf (_("<corrupt>\n")); | |
17192 | return p; | |
17193 | } | |
17194 | READ_ULEB (val, p, end); | |
17195 | ||
17196 | if (val > 3) | |
17197 | printf ("(%#x), ", val); | |
17198 | ||
17199 | switch (val & 3) | |
17200 | { | |
17201 | case 0: | |
17202 | printf (_("unspecified\n")); | |
17203 | break; | |
17204 | case 1: | |
17205 | printf (_("generic\n")); | |
17206 | break; | |
17207 | case 2: | |
17208 | printf ("AltiVec\n"); | |
17209 | break; | |
17210 | case 3: | |
17211 | printf ("SPE\n"); | |
17212 | break; | |
17213 | } | |
17214 | return p; | |
17215 | } | |
17216 | ||
17217 | if (tag == Tag_GNU_Power_ABI_Struct_Return) | |
17218 | { | |
17219 | printf (" Tag_GNU_Power_ABI_Struct_Return: "); | |
17220 | if (p == end) | |
17221 | { | |
17222 | printf (_("<corrupt>\n")); | |
17223 | return p; | |
17224 | } | |
17225 | READ_ULEB (val, p, end); | |
17226 | ||
17227 | if (val > 2) | |
17228 | printf ("(%#x), ", val); | |
17229 | ||
17230 | switch (val & 3) | |
17231 | { | |
17232 | case 0: | |
17233 | printf (_("unspecified\n")); | |
17234 | break; | |
17235 | case 1: | |
17236 | printf ("r3/r4\n"); | |
17237 | break; | |
17238 | case 2: | |
17239 | printf (_("memory\n")); | |
17240 | break; | |
17241 | case 3: | |
17242 | printf ("???\n"); | |
17243 | break; | |
17244 | } | |
17245 | return p; | |
17246 | } | |
17247 | ||
17248 | return display_tag_value (tag & 1, p, end); | |
17249 | } | |
17250 | ||
17251 | static unsigned char * | |
17252 | display_s390_gnu_attribute (unsigned char * p, | |
17253 | unsigned int tag, | |
17254 | const unsigned char * const end) | |
17255 | { | |
17256 | unsigned int val; | |
17257 | ||
17258 | if (tag == Tag_GNU_S390_ABI_Vector) | |
17259 | { | |
17260 | printf (" Tag_GNU_S390_ABI_Vector: "); | |
17261 | READ_ULEB (val, p, end); | |
17262 | ||
17263 | switch (val) | |
17264 | { | |
17265 | case 0: | |
17266 | printf (_("any\n")); | |
17267 | break; | |
17268 | case 1: | |
17269 | printf (_("software\n")); | |
17270 | break; | |
17271 | case 2: | |
17272 | printf (_("hardware\n")); | |
17273 | break; | |
17274 | default: | |
17275 | printf ("??? (%d)\n", val); | |
17276 | break; | |
17277 | } | |
17278 | return p; | |
17279 | } | |
17280 | ||
17281 | return display_tag_value (tag & 1, p, end); | |
17282 | } | |
17283 | ||
17284 | static void | |
17285 | display_sparc_hwcaps (unsigned int mask) | |
17286 | { | |
17287 | if (mask) | |
17288 | { | |
17289 | bool first = true; | |
17290 | ||
17291 | if (mask & ELF_SPARC_HWCAP_MUL32) | |
17292 | fputs ("mul32", stdout), first = false; | |
17293 | if (mask & ELF_SPARC_HWCAP_DIV32) | |
17294 | printf ("%sdiv32", first ? "" : "|"), first = false; | |
17295 | if (mask & ELF_SPARC_HWCAP_FSMULD) | |
17296 | printf ("%sfsmuld", first ? "" : "|"), first = false; | |
17297 | if (mask & ELF_SPARC_HWCAP_V8PLUS) | |
17298 | printf ("%sv8plus", first ? "" : "|"), first = false; | |
17299 | if (mask & ELF_SPARC_HWCAP_POPC) | |
17300 | printf ("%spopc", first ? "" : "|"), first = false; | |
17301 | if (mask & ELF_SPARC_HWCAP_VIS) | |
17302 | printf ("%svis", first ? "" : "|"), first = false; | |
17303 | if (mask & ELF_SPARC_HWCAP_VIS2) | |
17304 | printf ("%svis2", first ? "" : "|"), first = false; | |
17305 | if (mask & ELF_SPARC_HWCAP_ASI_BLK_INIT) | |
17306 | printf ("%sASIBlkInit", first ? "" : "|"), first = false; | |
17307 | if (mask & ELF_SPARC_HWCAP_FMAF) | |
17308 | printf ("%sfmaf", first ? "" : "|"), first = false; | |
17309 | if (mask & ELF_SPARC_HWCAP_VIS3) | |
17310 | printf ("%svis3", first ? "" : "|"), first = false; | |
17311 | if (mask & ELF_SPARC_HWCAP_HPC) | |
17312 | printf ("%shpc", first ? "" : "|"), first = false; | |
17313 | if (mask & ELF_SPARC_HWCAP_RANDOM) | |
17314 | printf ("%srandom", first ? "" : "|"), first = false; | |
17315 | if (mask & ELF_SPARC_HWCAP_TRANS) | |
17316 | printf ("%strans", first ? "" : "|"), first = false; | |
17317 | if (mask & ELF_SPARC_HWCAP_FJFMAU) | |
17318 | printf ("%sfjfmau", first ? "" : "|"), first = false; | |
17319 | if (mask & ELF_SPARC_HWCAP_IMA) | |
17320 | printf ("%sima", first ? "" : "|"), first = false; | |
17321 | if (mask & ELF_SPARC_HWCAP_ASI_CACHE_SPARING) | |
17322 | printf ("%scspare", first ? "" : "|"), first = false; | |
17323 | } | |
17324 | else | |
17325 | fputc ('0', stdout); | |
17326 | fputc ('\n', stdout); | |
17327 | } | |
17328 | ||
17329 | static void | |
17330 | display_sparc_hwcaps2 (unsigned int mask) | |
17331 | { | |
17332 | if (mask) | |
17333 | { | |
17334 | bool first = true; | |
17335 | ||
17336 | if (mask & ELF_SPARC_HWCAP2_FJATHPLUS) | |
17337 | fputs ("fjathplus", stdout), first = false; | |
17338 | if (mask & ELF_SPARC_HWCAP2_VIS3B) | |
17339 | printf ("%svis3b", first ? "" : "|"), first = false; | |
17340 | if (mask & ELF_SPARC_HWCAP2_ADP) | |
17341 | printf ("%sadp", first ? "" : "|"), first = false; | |
17342 | if (mask & ELF_SPARC_HWCAP2_SPARC5) | |
17343 | printf ("%ssparc5", first ? "" : "|"), first = false; | |
17344 | if (mask & ELF_SPARC_HWCAP2_MWAIT) | |
17345 | printf ("%smwait", first ? "" : "|"), first = false; | |
17346 | if (mask & ELF_SPARC_HWCAP2_XMPMUL) | |
17347 | printf ("%sxmpmul", first ? "" : "|"), first = false; | |
17348 | if (mask & ELF_SPARC_HWCAP2_XMONT) | |
17349 | printf ("%sxmont2", first ? "" : "|"), first = false; | |
17350 | if (mask & ELF_SPARC_HWCAP2_NSEC) | |
17351 | printf ("%snsec", first ? "" : "|"), first = false; | |
17352 | if (mask & ELF_SPARC_HWCAP2_FJATHHPC) | |
17353 | printf ("%sfjathhpc", first ? "" : "|"), first = false; | |
17354 | if (mask & ELF_SPARC_HWCAP2_FJDES) | |
17355 | printf ("%sfjdes", first ? "" : "|"), first = false; | |
17356 | if (mask & ELF_SPARC_HWCAP2_FJAES) | |
17357 | printf ("%sfjaes", first ? "" : "|"), first = false; | |
17358 | } | |
17359 | else | |
17360 | fputc ('0', stdout); | |
17361 | fputc ('\n', stdout); | |
17362 | } | |
17363 | ||
17364 | static unsigned char * | |
17365 | display_sparc_gnu_attribute (unsigned char * p, | |
17366 | unsigned int tag, | |
17367 | const unsigned char * const end) | |
17368 | { | |
17369 | unsigned int val; | |
17370 | ||
17371 | if (tag == Tag_GNU_Sparc_HWCAPS) | |
17372 | { | |
17373 | READ_ULEB (val, p, end); | |
17374 | printf (" Tag_GNU_Sparc_HWCAPS: "); | |
17375 | display_sparc_hwcaps (val); | |
17376 | return p; | |
17377 | } | |
17378 | if (tag == Tag_GNU_Sparc_HWCAPS2) | |
17379 | { | |
17380 | READ_ULEB (val, p, end); | |
17381 | printf (" Tag_GNU_Sparc_HWCAPS2: "); | |
17382 | display_sparc_hwcaps2 (val); | |
17383 | return p; | |
17384 | } | |
17385 | ||
17386 | return display_tag_value (tag, p, end); | |
17387 | } | |
17388 | ||
17389 | static void | |
17390 | print_mips_fp_abi_value (unsigned int val) | |
17391 | { | |
17392 | switch (val) | |
17393 | { | |
17394 | case Val_GNU_MIPS_ABI_FP_ANY: | |
17395 | printf (_("Hard or soft float\n")); | |
17396 | break; | |
17397 | case Val_GNU_MIPS_ABI_FP_DOUBLE: | |
17398 | printf (_("Hard float (double precision)\n")); | |
17399 | break; | |
17400 | case Val_GNU_MIPS_ABI_FP_SINGLE: | |
17401 | printf (_("Hard float (single precision)\n")); | |
17402 | break; | |
17403 | case Val_GNU_MIPS_ABI_FP_SOFT: | |
17404 | printf (_("Soft float\n")); | |
17405 | break; | |
17406 | case Val_GNU_MIPS_ABI_FP_OLD_64: | |
17407 | printf (_("Hard float (MIPS32r2 64-bit FPU 12 callee-saved)\n")); | |
17408 | break; | |
17409 | case Val_GNU_MIPS_ABI_FP_XX: | |
17410 | printf (_("Hard float (32-bit CPU, Any FPU)\n")); | |
17411 | break; | |
17412 | case Val_GNU_MIPS_ABI_FP_64: | |
17413 | printf (_("Hard float (32-bit CPU, 64-bit FPU)\n")); | |
17414 | break; | |
17415 | case Val_GNU_MIPS_ABI_FP_64A: | |
17416 | printf (_("Hard float compat (32-bit CPU, 64-bit FPU)\n")); | |
17417 | break; | |
17418 | case Val_GNU_MIPS_ABI_FP_NAN2008: | |
17419 | printf (_("NaN 2008 compatibility\n")); | |
17420 | break; | |
17421 | default: | |
17422 | printf ("??? (%d)\n", val); | |
17423 | break; | |
17424 | } | |
17425 | } | |
17426 | ||
17427 | static unsigned char * | |
17428 | display_mips_gnu_attribute (unsigned char * p, | |
17429 | unsigned int tag, | |
17430 | const unsigned char * const end) | |
17431 | { | |
17432 | if (tag == Tag_GNU_MIPS_ABI_FP) | |
17433 | { | |
17434 | unsigned int val; | |
17435 | ||
17436 | printf (" Tag_GNU_MIPS_ABI_FP: "); | |
17437 | READ_ULEB (val, p, end); | |
17438 | print_mips_fp_abi_value (val); | |
17439 | return p; | |
17440 | } | |
17441 | ||
17442 | if (tag == Tag_GNU_MIPS_ABI_MSA) | |
17443 | { | |
17444 | unsigned int val; | |
17445 | ||
17446 | printf (" Tag_GNU_MIPS_ABI_MSA: "); | |
17447 | READ_ULEB (val, p, end); | |
17448 | ||
17449 | switch (val) | |
17450 | { | |
17451 | case Val_GNU_MIPS_ABI_MSA_ANY: | |
17452 | printf (_("Any MSA or not\n")); | |
17453 | break; | |
17454 | case Val_GNU_MIPS_ABI_MSA_128: | |
17455 | printf (_("128-bit MSA\n")); | |
17456 | break; | |
17457 | default: | |
17458 | printf ("??? (%d)\n", val); | |
17459 | break; | |
17460 | } | |
17461 | return p; | |
17462 | } | |
17463 | ||
17464 | return display_tag_value (tag & 1, p, end); | |
17465 | } | |
17466 | ||
17467 | static unsigned char * | |
17468 | display_tic6x_attribute (unsigned char * p, | |
17469 | const unsigned char * const end) | |
17470 | { | |
17471 | unsigned int tag; | |
17472 | unsigned int val; | |
17473 | ||
17474 | READ_ULEB (tag, p, end); | |
17475 | ||
17476 | switch (tag) | |
17477 | { | |
17478 | case Tag_ISA: | |
17479 | printf (" Tag_ISA: "); | |
17480 | READ_ULEB (val, p, end); | |
17481 | ||
17482 | switch (val) | |
17483 | { | |
17484 | case C6XABI_Tag_ISA_none: | |
17485 | printf (_("None\n")); | |
17486 | break; | |
17487 | case C6XABI_Tag_ISA_C62X: | |
17488 | printf ("C62x\n"); | |
17489 | break; | |
17490 | case C6XABI_Tag_ISA_C67X: | |
17491 | printf ("C67x\n"); | |
17492 | break; | |
17493 | case C6XABI_Tag_ISA_C67XP: | |
17494 | printf ("C67x+\n"); | |
17495 | break; | |
17496 | case C6XABI_Tag_ISA_C64X: | |
17497 | printf ("C64x\n"); | |
17498 | break; | |
17499 | case C6XABI_Tag_ISA_C64XP: | |
17500 | printf ("C64x+\n"); | |
17501 | break; | |
17502 | case C6XABI_Tag_ISA_C674X: | |
17503 | printf ("C674x\n"); | |
17504 | break; | |
17505 | default: | |
17506 | printf ("??? (%d)\n", val); | |
17507 | break; | |
17508 | } | |
17509 | return p; | |
17510 | ||
17511 | case Tag_ABI_wchar_t: | |
17512 | printf (" Tag_ABI_wchar_t: "); | |
17513 | READ_ULEB (val, p, end); | |
17514 | switch (val) | |
17515 | { | |
17516 | case 0: | |
17517 | printf (_("Not used\n")); | |
17518 | break; | |
17519 | case 1: | |
17520 | printf (_("2 bytes\n")); | |
17521 | break; | |
17522 | case 2: | |
17523 | printf (_("4 bytes\n")); | |
17524 | break; | |
17525 | default: | |
17526 | printf ("??? (%d)\n", val); | |
17527 | break; | |
17528 | } | |
17529 | return p; | |
17530 | ||
17531 | case Tag_ABI_stack_align_needed: | |
17532 | printf (" Tag_ABI_stack_align_needed: "); | |
17533 | READ_ULEB (val, p, end); | |
17534 | switch (val) | |
17535 | { | |
17536 | case 0: | |
17537 | printf (_("8-byte\n")); | |
17538 | break; | |
17539 | case 1: | |
17540 | printf (_("16-byte\n")); | |
17541 | break; | |
17542 | default: | |
17543 | printf ("??? (%d)\n", val); | |
17544 | break; | |
17545 | } | |
17546 | return p; | |
17547 | ||
17548 | case Tag_ABI_stack_align_preserved: | |
17549 | READ_ULEB (val, p, end); | |
17550 | printf (" Tag_ABI_stack_align_preserved: "); | |
17551 | switch (val) | |
17552 | { | |
17553 | case 0: | |
17554 | printf (_("8-byte\n")); | |
17555 | break; | |
17556 | case 1: | |
17557 | printf (_("16-byte\n")); | |
17558 | break; | |
17559 | default: | |
17560 | printf ("??? (%d)\n", val); | |
17561 | break; | |
17562 | } | |
17563 | return p; | |
17564 | ||
17565 | case Tag_ABI_DSBT: | |
17566 | READ_ULEB (val, p, end); | |
17567 | printf (" Tag_ABI_DSBT: "); | |
17568 | switch (val) | |
17569 | { | |
17570 | case 0: | |
17571 | printf (_("DSBT addressing not used\n")); | |
17572 | break; | |
17573 | case 1: | |
17574 | printf (_("DSBT addressing used\n")); | |
17575 | break; | |
17576 | default: | |
17577 | printf ("??? (%d)\n", val); | |
17578 | break; | |
17579 | } | |
17580 | return p; | |
17581 | ||
17582 | case Tag_ABI_PID: | |
17583 | READ_ULEB (val, p, end); | |
17584 | printf (" Tag_ABI_PID: "); | |
17585 | switch (val) | |
17586 | { | |
17587 | case 0: | |
17588 | printf (_("Data addressing position-dependent\n")); | |
17589 | break; | |
17590 | case 1: | |
17591 | printf (_("Data addressing position-independent, GOT near DP\n")); | |
17592 | break; | |
17593 | case 2: | |
17594 | printf (_("Data addressing position-independent, GOT far from DP\n")); | |
17595 | break; | |
17596 | default: | |
17597 | printf ("??? (%d)\n", val); | |
17598 | break; | |
17599 | } | |
17600 | return p; | |
17601 | ||
17602 | case Tag_ABI_PIC: | |
17603 | READ_ULEB (val, p, end); | |
17604 | printf (" Tag_ABI_PIC: "); | |
17605 | switch (val) | |
17606 | { | |
17607 | case 0: | |
17608 | printf (_("Code addressing position-dependent\n")); | |
17609 | break; | |
17610 | case 1: | |
17611 | printf (_("Code addressing position-independent\n")); | |
17612 | break; | |
17613 | default: | |
17614 | printf ("??? (%d)\n", val); | |
17615 | break; | |
17616 | } | |
17617 | return p; | |
17618 | ||
17619 | case Tag_ABI_array_object_alignment: | |
17620 | READ_ULEB (val, p, end); | |
17621 | printf (" Tag_ABI_array_object_alignment: "); | |
17622 | switch (val) | |
17623 | { | |
17624 | case 0: | |
17625 | printf (_("8-byte\n")); | |
17626 | break; | |
17627 | case 1: | |
17628 | printf (_("4-byte\n")); | |
17629 | break; | |
17630 | case 2: | |
17631 | printf (_("16-byte\n")); | |
17632 | break; | |
17633 | default: | |
17634 | printf ("??? (%d)\n", val); | |
17635 | break; | |
17636 | } | |
17637 | return p; | |
17638 | ||
17639 | case Tag_ABI_array_object_align_expected: | |
17640 | READ_ULEB (val, p, end); | |
17641 | printf (" Tag_ABI_array_object_align_expected: "); | |
17642 | switch (val) | |
17643 | { | |
17644 | case 0: | |
17645 | printf (_("8-byte\n")); | |
17646 | break; | |
17647 | case 1: | |
17648 | printf (_("4-byte\n")); | |
17649 | break; | |
17650 | case 2: | |
17651 | printf (_("16-byte\n")); | |
17652 | break; | |
17653 | default: | |
17654 | printf ("??? (%d)\n", val); | |
17655 | break; | |
17656 | } | |
17657 | return p; | |
17658 | ||
17659 | case Tag_ABI_compatibility: | |
17660 | { | |
17661 | READ_ULEB (val, p, end); | |
17662 | printf (" Tag_ABI_compatibility: "); | |
17663 | printf (_("flag = %d, vendor = "), val); | |
17664 | if (p < end - 1) | |
17665 | { | |
17666 | size_t maxlen = (end - p) - 1; | |
17667 | ||
17668 | print_symbol ((int) maxlen, (const char *) p); | |
17669 | p += strnlen ((char *) p, maxlen) + 1; | |
17670 | } | |
17671 | else | |
17672 | { | |
17673 | printf (_("<corrupt>")); | |
17674 | p = (unsigned char *) end; | |
17675 | } | |
17676 | putchar ('\n'); | |
17677 | return p; | |
17678 | } | |
17679 | ||
17680 | case Tag_ABI_conformance: | |
17681 | { | |
17682 | printf (" Tag_ABI_conformance: \""); | |
17683 | if (p < end - 1) | |
17684 | { | |
17685 | size_t maxlen = (end - p) - 1; | |
17686 | ||
17687 | print_symbol ((int) maxlen, (const char *) p); | |
17688 | p += strnlen ((char *) p, maxlen) + 1; | |
17689 | } | |
17690 | else | |
17691 | { | |
17692 | printf (_("<corrupt>")); | |
17693 | p = (unsigned char *) end; | |
17694 | } | |
17695 | printf ("\"\n"); | |
17696 | return p; | |
17697 | } | |
17698 | } | |
17699 | ||
17700 | return display_tag_value (tag, p, end); | |
17701 | } | |
17702 | ||
17703 | static void | |
17704 | display_raw_attribute (unsigned char * p, unsigned char const * const end) | |
17705 | { | |
17706 | uint64_t addr = 0; | |
17707 | size_t bytes = end - p; | |
17708 | ||
17709 | assert (end >= p); | |
17710 | while (bytes) | |
17711 | { | |
17712 | int j; | |
17713 | int k; | |
17714 | int lbytes = (bytes > 16 ? 16 : bytes); | |
17715 | ||
17716 | printf (" 0x%8.8" PRIx64 " ", addr); | |
17717 | ||
17718 | for (j = 0; j < 16; j++) | |
17719 | { | |
17720 | if (j < lbytes) | |
17721 | printf ("%2.2x", p[j]); | |
17722 | else | |
17723 | printf (" "); | |
17724 | ||
17725 | if ((j & 3) == 3) | |
17726 | printf (" "); | |
17727 | } | |
17728 | ||
17729 | for (j = 0; j < lbytes; j++) | |
17730 | { | |
17731 | k = p[j]; | |
17732 | if (k >= ' ' && k < 0x7f) | |
17733 | printf ("%c", k); | |
17734 | else | |
17735 | printf ("."); | |
17736 | } | |
17737 | ||
17738 | putchar ('\n'); | |
17739 | ||
17740 | p += lbytes; | |
17741 | bytes -= lbytes; | |
17742 | addr += lbytes; | |
17743 | } | |
17744 | ||
17745 | putchar ('\n'); | |
17746 | } | |
17747 | ||
17748 | static unsigned char * | |
17749 | display_msp430_attribute (unsigned char * p, | |
17750 | const unsigned char * const end) | |
17751 | { | |
17752 | uint64_t val; | |
17753 | uint64_t tag; | |
17754 | ||
17755 | READ_ULEB (tag, p, end); | |
17756 | ||
17757 | switch (tag) | |
17758 | { | |
17759 | case OFBA_MSPABI_Tag_ISA: | |
17760 | printf (" Tag_ISA: "); | |
17761 | READ_ULEB (val, p, end); | |
17762 | switch (val) | |
17763 | { | |
17764 | case 0: printf (_("None\n")); break; | |
17765 | case 1: printf (_("MSP430\n")); break; | |
17766 | case 2: printf (_("MSP430X\n")); break; | |
17767 | default: printf ("??? (%" PRId64 ")\n", val); break; | |
17768 | } | |
17769 | break; | |
17770 | ||
17771 | case OFBA_MSPABI_Tag_Code_Model: | |
17772 | printf (" Tag_Code_Model: "); | |
17773 | READ_ULEB (val, p, end); | |
17774 | switch (val) | |
17775 | { | |
17776 | case 0: printf (_("None\n")); break; | |
17777 | case 1: printf (_("Small\n")); break; | |
17778 | case 2: printf (_("Large\n")); break; | |
17779 | default: printf ("??? (%" PRId64 ")\n", val); break; | |
17780 | } | |
17781 | break; | |
17782 | ||
17783 | case OFBA_MSPABI_Tag_Data_Model: | |
17784 | printf (" Tag_Data_Model: "); | |
17785 | READ_ULEB (val, p, end); | |
17786 | switch (val) | |
17787 | { | |
17788 | case 0: printf (_("None\n")); break; | |
17789 | case 1: printf (_("Small\n")); break; | |
17790 | case 2: printf (_("Large\n")); break; | |
17791 | case 3: printf (_("Restricted Large\n")); break; | |
17792 | default: printf ("??? (%" PRId64 ")\n", val); break; | |
17793 | } | |
17794 | break; | |
17795 | ||
17796 | default: | |
17797 | printf (_(" <unknown tag %" PRId64 ">: "), tag); | |
17798 | ||
17799 | if (tag & 1) | |
17800 | { | |
17801 | putchar ('"'); | |
17802 | if (p < end - 1) | |
17803 | { | |
17804 | size_t maxlen = (end - p) - 1; | |
17805 | ||
17806 | print_symbol ((int) maxlen, (const char *) p); | |
17807 | p += strnlen ((char *) p, maxlen) + 1; | |
17808 | } | |
17809 | else | |
17810 | { | |
17811 | printf (_("<corrupt>")); | |
17812 | p = (unsigned char *) end; | |
17813 | } | |
17814 | printf ("\"\n"); | |
17815 | } | |
17816 | else | |
17817 | { | |
17818 | READ_ULEB (val, p, end); | |
17819 | printf ("%" PRId64 " (0x%" PRIx64 ")\n", val, val); | |
17820 | } | |
17821 | break; | |
17822 | } | |
17823 | ||
17824 | assert (p <= end); | |
17825 | return p; | |
17826 | } | |
17827 | ||
17828 | static unsigned char * | |
17829 | display_msp430_gnu_attribute (unsigned char * p, | |
17830 | unsigned int tag, | |
17831 | const unsigned char * const end) | |
17832 | { | |
17833 | if (tag == Tag_GNU_MSP430_Data_Region) | |
17834 | { | |
17835 | uint64_t val; | |
17836 | ||
17837 | printf (" Tag_GNU_MSP430_Data_Region: "); | |
17838 | READ_ULEB (val, p, end); | |
17839 | ||
17840 | switch (val) | |
17841 | { | |
17842 | case Val_GNU_MSP430_Data_Region_Any: | |
17843 | printf (_("Any Region\n")); | |
17844 | break; | |
17845 | case Val_GNU_MSP430_Data_Region_Lower: | |
17846 | printf (_("Lower Region Only\n")); | |
17847 | break; | |
17848 | default: | |
17849 | printf ("??? (%" PRIu64 ")\n", val); | |
17850 | } | |
17851 | return p; | |
17852 | } | |
17853 | return display_tag_value (tag & 1, p, end); | |
17854 | } | |
17855 | ||
17856 | struct riscv_attr_tag_t { | |
17857 | const char *name; | |
17858 | unsigned int tag; | |
17859 | }; | |
17860 | ||
17861 | static struct riscv_attr_tag_t riscv_attr_tag[] = | |
17862 | { | |
17863 | #define T(tag) {"Tag_RISCV_" #tag, Tag_RISCV_##tag} | |
17864 | T(arch), | |
17865 | T(priv_spec), | |
17866 | T(priv_spec_minor), | |
17867 | T(priv_spec_revision), | |
17868 | T(unaligned_access), | |
17869 | T(stack_align), | |
17870 | #undef T | |
17871 | }; | |
17872 | ||
17873 | static unsigned char * | |
17874 | display_riscv_attribute (unsigned char *p, | |
17875 | const unsigned char * const end) | |
17876 | { | |
17877 | uint64_t val; | |
17878 | uint64_t tag; | |
17879 | struct riscv_attr_tag_t *attr = NULL; | |
17880 | unsigned i; | |
17881 | ||
17882 | READ_ULEB (tag, p, end); | |
17883 | ||
17884 | /* Find the name of attribute. */ | |
17885 | for (i = 0; i < ARRAY_SIZE (riscv_attr_tag); i++) | |
17886 | { | |
17887 | if (riscv_attr_tag[i].tag == tag) | |
17888 | { | |
17889 | attr = &riscv_attr_tag[i]; | |
17890 | break; | |
17891 | } | |
17892 | } | |
17893 | ||
17894 | if (attr) | |
17895 | printf (" %s: ", attr->name); | |
17896 | else | |
17897 | return display_tag_value (tag, p, end); | |
17898 | ||
17899 | switch (tag) | |
17900 | { | |
17901 | case Tag_RISCV_priv_spec: | |
17902 | case Tag_RISCV_priv_spec_minor: | |
17903 | case Tag_RISCV_priv_spec_revision: | |
17904 | READ_ULEB (val, p, end); | |
17905 | printf ("%" PRIu64 "\n", val); | |
17906 | break; | |
17907 | case Tag_RISCV_unaligned_access: | |
17908 | READ_ULEB (val, p, end); | |
17909 | switch (val) | |
17910 | { | |
17911 | case 0: | |
17912 | printf (_("No unaligned access\n")); | |
17913 | break; | |
17914 | case 1: | |
17915 | printf (_("Unaligned access\n")); | |
17916 | break; | |
17917 | } | |
17918 | break; | |
17919 | case Tag_RISCV_stack_align: | |
17920 | READ_ULEB (val, p, end); | |
17921 | printf (_("%" PRIu64 "-bytes\n"), val); | |
17922 | break; | |
17923 | case Tag_RISCV_arch: | |
17924 | p = display_tag_value (-1, p, end); | |
17925 | break; | |
17926 | default: | |
17927 | return display_tag_value (tag, p, end); | |
17928 | } | |
17929 | ||
17930 | return p; | |
17931 | } | |
17932 | ||
17933 | static unsigned char * | |
17934 | display_csky_attribute (unsigned char * p, | |
17935 | const unsigned char * const end) | |
17936 | { | |
17937 | uint64_t tag; | |
17938 | uint64_t val; | |
17939 | READ_ULEB (tag, p, end); | |
17940 | ||
17941 | if (tag >= Tag_CSKY_MAX) | |
17942 | { | |
17943 | return display_tag_value (-1, p, end); | |
17944 | } | |
17945 | ||
17946 | switch (tag) | |
17947 | { | |
17948 | case Tag_CSKY_ARCH_NAME: | |
17949 | printf (" Tag_CSKY_ARCH_NAME:\t\t"); | |
17950 | return display_tag_value (-1, p, end); | |
17951 | case Tag_CSKY_CPU_NAME: | |
17952 | printf (" Tag_CSKY_CPU_NAME:\t\t"); | |
17953 | return display_tag_value (-1, p, end); | |
17954 | ||
17955 | case Tag_CSKY_ISA_FLAGS: | |
17956 | printf (" Tag_CSKY_ISA_FLAGS:\t\t"); | |
17957 | return display_tag_value (0, p, end); | |
17958 | case Tag_CSKY_ISA_EXT_FLAGS: | |
17959 | printf (" Tag_CSKY_ISA_EXT_FLAGS:\t"); | |
17960 | return display_tag_value (0, p, end); | |
17961 | ||
17962 | case Tag_CSKY_DSP_VERSION: | |
17963 | printf (" Tag_CSKY_DSP_VERSION:\t\t"); | |
17964 | READ_ULEB (val, p, end); | |
17965 | if (val == VAL_CSKY_DSP_VERSION_EXTENSION) | |
17966 | printf ("DSP Extension\n"); | |
17967 | else if (val == VAL_CSKY_DSP_VERSION_2) | |
17968 | printf ("DSP 2.0\n"); | |
17969 | break; | |
17970 | ||
17971 | case Tag_CSKY_VDSP_VERSION: | |
17972 | printf (" Tag_CSKY_VDSP_VERSION:\t"); | |
17973 | READ_ULEB (val, p, end); | |
17974 | printf ("VDSP Version %" PRId64 "\n", val); | |
17975 | break; | |
17976 | ||
17977 | case Tag_CSKY_FPU_VERSION: | |
17978 | printf (" Tag_CSKY_FPU_VERSION:\t\t"); | |
17979 | READ_ULEB (val, p, end); | |
17980 | if (val == VAL_CSKY_FPU_VERSION_1) | |
17981 | printf ("ABIV1 FPU Version 1\n"); | |
17982 | else if (val == VAL_CSKY_FPU_VERSION_2) | |
17983 | printf ("FPU Version 2\n"); | |
17984 | break; | |
17985 | ||
17986 | case Tag_CSKY_FPU_ABI: | |
17987 | printf (" Tag_CSKY_FPU_ABI:\t\t"); | |
17988 | READ_ULEB (val, p, end); | |
17989 | if (val == VAL_CSKY_FPU_ABI_HARD) | |
17990 | printf ("Hard\n"); | |
17991 | else if (val == VAL_CSKY_FPU_ABI_SOFTFP) | |
17992 | printf ("SoftFP\n"); | |
17993 | else if (val == VAL_CSKY_FPU_ABI_SOFT) | |
17994 | printf ("Soft\n"); | |
17995 | break; | |
17996 | case Tag_CSKY_FPU_ROUNDING: | |
17997 | READ_ULEB (val, p, end); | |
17998 | if (val == 1) | |
17999 | { | |
18000 | printf (" Tag_CSKY_FPU_ROUNDING:\t"); | |
18001 | printf ("Needed\n"); | |
18002 | } | |
18003 | break; | |
18004 | case Tag_CSKY_FPU_DENORMAL: | |
18005 | READ_ULEB (val, p, end); | |
18006 | if (val == 1) | |
18007 | { | |
18008 | printf (" Tag_CSKY_FPU_DENORMAL:\t"); | |
18009 | printf ("Needed\n"); | |
18010 | } | |
18011 | break; | |
18012 | case Tag_CSKY_FPU_Exception: | |
18013 | READ_ULEB (val, p, end); | |
18014 | if (val == 1) | |
18015 | { | |
18016 | printf (" Tag_CSKY_FPU_Exception:\t"); | |
18017 | printf ("Needed\n"); | |
18018 | } | |
18019 | break; | |
18020 | case Tag_CSKY_FPU_NUMBER_MODULE: | |
18021 | printf (" Tag_CSKY_FPU_NUMBER_MODULE:\t"); | |
18022 | return display_tag_value (-1, p, end); | |
18023 | case Tag_CSKY_FPU_HARDFP: | |
18024 | printf (" Tag_CSKY_FPU_HARDFP:\t\t"); | |
18025 | READ_ULEB (val, p, end); | |
18026 | if (val & VAL_CSKY_FPU_HARDFP_HALF) | |
18027 | printf (" Half"); | |
18028 | if (val & VAL_CSKY_FPU_HARDFP_SINGLE) | |
18029 | printf (" Single"); | |
18030 | if (val & VAL_CSKY_FPU_HARDFP_DOUBLE) | |
18031 | printf (" Double"); | |
18032 | printf ("\n"); | |
18033 | break; | |
18034 | default: | |
18035 | return display_tag_value (tag, p, end); | |
18036 | } | |
18037 | return p; | |
18038 | } | |
18039 | ||
18040 | static bool | |
18041 | process_attributes (Filedata * filedata, | |
18042 | const char * public_name, | |
18043 | unsigned int proc_type, | |
18044 | unsigned char * (* display_pub_attribute) (unsigned char *, const unsigned char * const), | |
18045 | unsigned char * (* display_proc_gnu_attribute) (unsigned char *, unsigned int, const unsigned char * const)) | |
18046 | { | |
18047 | Elf_Internal_Shdr * sect; | |
18048 | unsigned i; | |
18049 | bool res = true; | |
18050 | ||
18051 | /* Find the section header so that we get the size. */ | |
18052 | for (i = 0, sect = filedata->section_headers; | |
18053 | i < filedata->file_header.e_shnum; | |
18054 | i++, sect++) | |
18055 | { | |
18056 | unsigned char * contents; | |
18057 | unsigned char * p; | |
18058 | ||
18059 | if (sect->sh_type != proc_type && sect->sh_type != SHT_GNU_ATTRIBUTES) | |
18060 | continue; | |
18061 | ||
18062 | contents = (unsigned char *) get_data (NULL, filedata, sect->sh_offset, 1, | |
18063 | sect->sh_size, _("attributes")); | |
18064 | if (contents == NULL) | |
18065 | { | |
18066 | res = false; | |
18067 | continue; | |
18068 | } | |
18069 | ||
18070 | p = contents; | |
18071 | /* The first character is the version of the attributes. | |
18072 | Currently only version 1, (aka 'A') is recognised here. */ | |
18073 | if (*p != 'A') | |
18074 | { | |
18075 | printf (_("Unknown attributes version '%c'(%d) - expecting 'A'\n"), *p, *p); | |
18076 | res = false; | |
18077 | } | |
18078 | else | |
18079 | { | |
18080 | uint64_t section_len; | |
18081 | ||
18082 | section_len = sect->sh_size - 1; | |
18083 | p++; | |
18084 | ||
18085 | while (section_len > 0) | |
18086 | { | |
18087 | uint64_t attr_len; | |
18088 | unsigned int namelen; | |
18089 | bool public_section; | |
18090 | bool gnu_section; | |
18091 | ||
18092 | if (section_len <= 4) | |
18093 | { | |
18094 | error (_("Tag section ends prematurely\n")); | |
18095 | res = false; | |
18096 | break; | |
18097 | } | |
18098 | attr_len = byte_get (p, 4); | |
18099 | p += 4; | |
18100 | ||
18101 | if (attr_len > section_len) | |
18102 | { | |
18103 | error (_("Bad attribute length (%u > %u)\n"), | |
18104 | (unsigned) attr_len, (unsigned) section_len); | |
18105 | attr_len = section_len; | |
18106 | res = false; | |
18107 | } | |
18108 | /* PR 17531: file: 001-101425-0.004 */ | |
18109 | else if (attr_len < 5) | |
18110 | { | |
18111 | error (_("Attribute length of %u is too small\n"), (unsigned) attr_len); | |
18112 | res = false; | |
18113 | break; | |
18114 | } | |
18115 | ||
18116 | section_len -= attr_len; | |
18117 | attr_len -= 4; | |
18118 | ||
18119 | namelen = strnlen ((char *) p, attr_len) + 1; | |
18120 | if (namelen == 0 || namelen >= attr_len) | |
18121 | { | |
18122 | error (_("Corrupt attribute section name\n")); | |
18123 | res = false; | |
18124 | break; | |
18125 | } | |
18126 | ||
18127 | printf (_("Attribute Section: ")); | |
18128 | print_symbol (INT_MAX, (const char *) p); | |
18129 | putchar ('\n'); | |
18130 | ||
18131 | if (public_name && streq ((char *) p, public_name)) | |
18132 | public_section = true; | |
18133 | else | |
18134 | public_section = false; | |
18135 | ||
18136 | if (streq ((char *) p, "gnu")) | |
18137 | gnu_section = true; | |
18138 | else | |
18139 | gnu_section = false; | |
18140 | ||
18141 | p += namelen; | |
18142 | attr_len -= namelen; | |
18143 | ||
18144 | while (attr_len > 0 && p < contents + sect->sh_size) | |
18145 | { | |
18146 | int tag; | |
18147 | unsigned int val; | |
18148 | uint64_t size; | |
18149 | unsigned char * end; | |
18150 | ||
18151 | /* PR binutils/17531: Safe handling of corrupt files. */ | |
18152 | if (attr_len < 6) | |
18153 | { | |
18154 | error (_("Unused bytes at end of section\n")); | |
18155 | res = false; | |
18156 | section_len = 0; | |
18157 | break; | |
18158 | } | |
18159 | ||
18160 | tag = *(p++); | |
18161 | size = byte_get (p, 4); | |
18162 | if (size > attr_len) | |
18163 | { | |
18164 | error (_("Bad subsection length (%u > %u)\n"), | |
18165 | (unsigned) size, (unsigned) attr_len); | |
18166 | res = false; | |
18167 | size = attr_len; | |
18168 | } | |
18169 | /* PR binutils/17531: Safe handling of corrupt files. */ | |
18170 | if (size < 6) | |
18171 | { | |
18172 | error (_("Bad subsection length (%u < 6)\n"), | |
18173 | (unsigned) size); | |
18174 | res = false; | |
18175 | section_len = 0; | |
18176 | break; | |
18177 | } | |
18178 | ||
18179 | attr_len -= size; | |
18180 | end = p + size - 1; | |
18181 | assert (end <= contents + sect->sh_size); | |
18182 | p += 4; | |
18183 | ||
18184 | switch (tag) | |
18185 | { | |
18186 | case 1: | |
18187 | printf (_("File Attributes\n")); | |
18188 | break; | |
18189 | case 2: | |
18190 | printf (_("Section Attributes:")); | |
18191 | goto do_numlist; | |
18192 | case 3: | |
18193 | printf (_("Symbol Attributes:")); | |
18194 | /* Fall through. */ | |
18195 | do_numlist: | |
18196 | for (;;) | |
18197 | { | |
18198 | READ_ULEB (val, p, end); | |
18199 | if (val == 0) | |
18200 | break; | |
18201 | printf (" %d", val); | |
18202 | } | |
18203 | printf ("\n"); | |
18204 | break; | |
18205 | default: | |
18206 | printf (_("Unknown tag: %d\n"), tag); | |
18207 | public_section = false; | |
18208 | break; | |
18209 | } | |
18210 | ||
18211 | if (public_section && display_pub_attribute != NULL) | |
18212 | { | |
18213 | while (p < end) | |
18214 | p = display_pub_attribute (p, end); | |
18215 | assert (p == end); | |
18216 | } | |
18217 | else if (gnu_section && display_proc_gnu_attribute != NULL) | |
18218 | { | |
18219 | while (p < end) | |
18220 | p = display_gnu_attribute (p, | |
18221 | display_proc_gnu_attribute, | |
18222 | end); | |
18223 | assert (p == end); | |
18224 | } | |
18225 | else if (p < end) | |
18226 | { | |
18227 | printf (_(" Unknown attribute:\n")); | |
18228 | display_raw_attribute (p, end); | |
18229 | p = end; | |
18230 | } | |
18231 | else | |
18232 | attr_len = 0; | |
18233 | } | |
18234 | } | |
18235 | } | |
18236 | ||
18237 | free (contents); | |
18238 | } | |
18239 | ||
18240 | return res; | |
18241 | } | |
18242 | ||
18243 | /* DATA points to the contents of a MIPS GOT that starts at VMA PLTGOT. | |
18244 | Print the Address, Access and Initial fields of an entry at VMA ADDR | |
18245 | and return the VMA of the next entry, or -1 if there was a problem. | |
18246 | Does not read from DATA_END or beyond. */ | |
18247 | ||
18248 | static uint64_t | |
18249 | print_mips_got_entry (unsigned char * data, uint64_t pltgot, uint64_t addr, | |
18250 | unsigned char * data_end) | |
18251 | { | |
18252 | printf (" "); | |
18253 | print_vma (addr, LONG_HEX); | |
18254 | printf (" "); | |
18255 | if (addr < pltgot + 0xfff0) | |
18256 | printf ("%6d(gp)", (int) (addr - pltgot - 0x7ff0)); | |
18257 | else | |
18258 | printf ("%10s", ""); | |
18259 | printf (" "); | |
18260 | if (data == NULL) | |
18261 | printf ("%*s", is_32bit_elf ? 8 : 16, _("<unknown>")); | |
18262 | else | |
18263 | { | |
18264 | uint64_t entry; | |
18265 | unsigned char * from = data + addr - pltgot; | |
18266 | ||
18267 | if (from + (is_32bit_elf ? 4 : 8) > data_end) | |
18268 | { | |
18269 | warn (_("MIPS GOT entry extends beyond the end of available data\n")); | |
18270 | printf ("%*s", is_32bit_elf ? 8 : 16, _("<corrupt>")); | |
18271 | return (uint64_t) -1; | |
18272 | } | |
18273 | else | |
18274 | { | |
18275 | entry = byte_get (data + addr - pltgot, is_32bit_elf ? 4 : 8); | |
18276 | print_vma (entry, LONG_HEX); | |
18277 | } | |
18278 | } | |
18279 | return addr + (is_32bit_elf ? 4 : 8); | |
18280 | } | |
18281 | ||
18282 | /* DATA points to the contents of a MIPS PLT GOT that starts at VMA | |
18283 | PLTGOT. Print the Address and Initial fields of an entry at VMA | |
18284 | ADDR and return the VMA of the next entry. */ | |
18285 | ||
18286 | static uint64_t | |
18287 | print_mips_pltgot_entry (unsigned char * data, uint64_t pltgot, uint64_t addr) | |
18288 | { | |
18289 | printf (" "); | |
18290 | print_vma (addr, LONG_HEX); | |
18291 | printf (" "); | |
18292 | if (data == NULL) | |
18293 | printf ("%*s", is_32bit_elf ? 8 : 16, _("<unknown>")); | |
18294 | else | |
18295 | { | |
18296 | uint64_t entry; | |
18297 | ||
18298 | entry = byte_get (data + addr - pltgot, is_32bit_elf ? 4 : 8); | |
18299 | print_vma (entry, LONG_HEX); | |
18300 | } | |
18301 | return addr + (is_32bit_elf ? 4 : 8); | |
18302 | } | |
18303 | ||
18304 | static void | |
18305 | print_mips_ases (unsigned int mask) | |
18306 | { | |
18307 | if (mask & AFL_ASE_DSP) | |
18308 | fputs ("\n\tDSP ASE", stdout); | |
18309 | if (mask & AFL_ASE_DSPR2) | |
18310 | fputs ("\n\tDSP R2 ASE", stdout); | |
18311 | if (mask & AFL_ASE_DSPR3) | |
18312 | fputs ("\n\tDSP R3 ASE", stdout); | |
18313 | if (mask & AFL_ASE_EVA) | |
18314 | fputs ("\n\tEnhanced VA Scheme", stdout); | |
18315 | if (mask & AFL_ASE_MCU) | |
18316 | fputs ("\n\tMCU (MicroController) ASE", stdout); | |
18317 | if (mask & AFL_ASE_MDMX) | |
18318 | fputs ("\n\tMDMX ASE", stdout); | |
18319 | if (mask & AFL_ASE_MIPS3D) | |
18320 | fputs ("\n\tMIPS-3D ASE", stdout); | |
18321 | if (mask & AFL_ASE_MT) | |
18322 | fputs ("\n\tMT ASE", stdout); | |
18323 | if (mask & AFL_ASE_SMARTMIPS) | |
18324 | fputs ("\n\tSmartMIPS ASE", stdout); | |
18325 | if (mask & AFL_ASE_VIRT) | |
18326 | fputs ("\n\tVZ ASE", stdout); | |
18327 | if (mask & AFL_ASE_MSA) | |
18328 | fputs ("\n\tMSA ASE", stdout); | |
18329 | if (mask & AFL_ASE_MIPS16) | |
18330 | fputs ("\n\tMIPS16 ASE", stdout); | |
18331 | if (mask & AFL_ASE_MICROMIPS) | |
18332 | fputs ("\n\tMICROMIPS ASE", stdout); | |
18333 | if (mask & AFL_ASE_XPA) | |
18334 | fputs ("\n\tXPA ASE", stdout); | |
18335 | if (mask & AFL_ASE_MIPS16E2) | |
18336 | fputs ("\n\tMIPS16e2 ASE", stdout); | |
18337 | if (mask & AFL_ASE_CRC) | |
18338 | fputs ("\n\tCRC ASE", stdout); | |
18339 | if (mask & AFL_ASE_GINV) | |
18340 | fputs ("\n\tGINV ASE", stdout); | |
18341 | if (mask & AFL_ASE_LOONGSON_MMI) | |
18342 | fputs ("\n\tLoongson MMI ASE", stdout); | |
18343 | if (mask & AFL_ASE_LOONGSON_CAM) | |
18344 | fputs ("\n\tLoongson CAM ASE", stdout); | |
18345 | if (mask & AFL_ASE_LOONGSON_EXT) | |
18346 | fputs ("\n\tLoongson EXT ASE", stdout); | |
18347 | if (mask & AFL_ASE_LOONGSON_EXT2) | |
18348 | fputs ("\n\tLoongson EXT2 ASE", stdout); | |
18349 | if (mask == 0) | |
18350 | fprintf (stdout, "\n\t%s", _("None")); | |
18351 | else if ((mask & ~AFL_ASE_MASK) != 0) | |
18352 | fprintf (stdout, "\n\t%s (%x)", _("Unknown"), mask & ~AFL_ASE_MASK); | |
18353 | } | |
18354 | ||
18355 | static void | |
18356 | print_mips_isa_ext (unsigned int isa_ext) | |
18357 | { | |
18358 | switch (isa_ext) | |
18359 | { | |
18360 | case 0: | |
18361 | fputs (_("None"), stdout); | |
18362 | break; | |
18363 | case AFL_EXT_XLR: | |
18364 | fputs ("RMI XLR", stdout); | |
18365 | break; | |
18366 | case AFL_EXT_OCTEON3: | |
18367 | fputs ("Cavium Networks Octeon3", stdout); | |
18368 | break; | |
18369 | case AFL_EXT_OCTEON2: | |
18370 | fputs ("Cavium Networks Octeon2", stdout); | |
18371 | break; | |
18372 | case AFL_EXT_OCTEONP: | |
18373 | fputs ("Cavium Networks OcteonP", stdout); | |
18374 | break; | |
18375 | case AFL_EXT_OCTEON: | |
18376 | fputs ("Cavium Networks Octeon", stdout); | |
18377 | break; | |
18378 | case AFL_EXT_5900: | |
18379 | fputs ("Toshiba R5900", stdout); | |
18380 | break; | |
18381 | case AFL_EXT_4650: | |
18382 | fputs ("MIPS R4650", stdout); | |
18383 | break; | |
18384 | case AFL_EXT_4010: | |
18385 | fputs ("LSI R4010", stdout); | |
18386 | break; | |
18387 | case AFL_EXT_4100: | |
18388 | fputs ("NEC VR4100", stdout); | |
18389 | break; | |
18390 | case AFL_EXT_3900: | |
18391 | fputs ("Toshiba R3900", stdout); | |
18392 | break; | |
18393 | case AFL_EXT_10000: | |
18394 | fputs ("MIPS R10000", stdout); | |
18395 | break; | |
18396 | case AFL_EXT_SB1: | |
18397 | fputs ("Broadcom SB-1", stdout); | |
18398 | break; | |
18399 | case AFL_EXT_4111: | |
18400 | fputs ("NEC VR4111/VR4181", stdout); | |
18401 | break; | |
18402 | case AFL_EXT_4120: | |
18403 | fputs ("NEC VR4120", stdout); | |
18404 | break; | |
18405 | case AFL_EXT_5400: | |
18406 | fputs ("NEC VR5400", stdout); | |
18407 | break; | |
18408 | case AFL_EXT_5500: | |
18409 | fputs ("NEC VR5500", stdout); | |
18410 | break; | |
18411 | case AFL_EXT_LOONGSON_2E: | |
18412 | fputs ("ST Microelectronics Loongson 2E", stdout); | |
18413 | break; | |
18414 | case AFL_EXT_LOONGSON_2F: | |
18415 | fputs ("ST Microelectronics Loongson 2F", stdout); | |
18416 | break; | |
18417 | case AFL_EXT_INTERAPTIV_MR2: | |
18418 | fputs ("Imagination interAptiv MR2", stdout); | |
18419 | break; | |
18420 | default: | |
18421 | fprintf (stdout, "%s (%d)", _("Unknown"), isa_ext); | |
18422 | } | |
18423 | } | |
18424 | ||
18425 | static signed int | |
18426 | get_mips_reg_size (int reg_size) | |
18427 | { | |
18428 | return (reg_size == AFL_REG_NONE) ? 0 | |
18429 | : (reg_size == AFL_REG_32) ? 32 | |
18430 | : (reg_size == AFL_REG_64) ? 64 | |
18431 | : (reg_size == AFL_REG_128) ? 128 | |
18432 | : -1; | |
18433 | } | |
18434 | ||
18435 | static bool | |
18436 | process_mips_specific (Filedata * filedata) | |
18437 | { | |
18438 | Elf_Internal_Dyn * entry; | |
18439 | Elf_Internal_Shdr *sect = NULL; | |
18440 | size_t liblist_offset = 0; | |
18441 | size_t liblistno = 0; | |
18442 | size_t conflictsno = 0; | |
18443 | size_t options_offset = 0; | |
18444 | size_t conflicts_offset = 0; | |
18445 | size_t pltrelsz = 0; | |
18446 | size_t pltrel = 0; | |
18447 | uint64_t pltgot = 0; | |
18448 | uint64_t mips_pltgot = 0; | |
18449 | uint64_t jmprel = 0; | |
18450 | uint64_t local_gotno = 0; | |
18451 | uint64_t gotsym = 0; | |
18452 | uint64_t symtabno = 0; | |
18453 | bool res = true; | |
18454 | ||
18455 | if (! process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL, | |
18456 | display_mips_gnu_attribute)) | |
18457 | res = false; | |
18458 | ||
18459 | sect = find_section (filedata, ".MIPS.abiflags"); | |
18460 | ||
18461 | if (sect != NULL) | |
18462 | { | |
18463 | Elf_External_ABIFlags_v0 *abiflags_ext; | |
18464 | Elf_Internal_ABIFlags_v0 abiflags_in; | |
18465 | ||
18466 | if (sizeof (Elf_External_ABIFlags_v0) != sect->sh_size) | |
18467 | { | |
18468 | error (_("Corrupt MIPS ABI Flags section.\n")); | |
18469 | res = false; | |
18470 | } | |
18471 | else | |
18472 | { | |
18473 | abiflags_ext = get_data (NULL, filedata, sect->sh_offset, 1, | |
18474 | sect->sh_size, _("MIPS ABI Flags section")); | |
18475 | if (abiflags_ext) | |
18476 | { | |
18477 | abiflags_in.version = BYTE_GET (abiflags_ext->version); | |
18478 | abiflags_in.isa_level = BYTE_GET (abiflags_ext->isa_level); | |
18479 | abiflags_in.isa_rev = BYTE_GET (abiflags_ext->isa_rev); | |
18480 | abiflags_in.gpr_size = BYTE_GET (abiflags_ext->gpr_size); | |
18481 | abiflags_in.cpr1_size = BYTE_GET (abiflags_ext->cpr1_size); | |
18482 | abiflags_in.cpr2_size = BYTE_GET (abiflags_ext->cpr2_size); | |
18483 | abiflags_in.fp_abi = BYTE_GET (abiflags_ext->fp_abi); | |
18484 | abiflags_in.isa_ext = BYTE_GET (abiflags_ext->isa_ext); | |
18485 | abiflags_in.ases = BYTE_GET (abiflags_ext->ases); | |
18486 | abiflags_in.flags1 = BYTE_GET (abiflags_ext->flags1); | |
18487 | abiflags_in.flags2 = BYTE_GET (abiflags_ext->flags2); | |
18488 | ||
18489 | printf ("\nMIPS ABI Flags Version: %d\n", abiflags_in.version); | |
18490 | printf ("\nISA: MIPS%d", abiflags_in.isa_level); | |
18491 | if (abiflags_in.isa_rev > 1) | |
18492 | printf ("r%d", abiflags_in.isa_rev); | |
18493 | printf ("\nGPR size: %d", | |
18494 | get_mips_reg_size (abiflags_in.gpr_size)); | |
18495 | printf ("\nCPR1 size: %d", | |
18496 | get_mips_reg_size (abiflags_in.cpr1_size)); | |
18497 | printf ("\nCPR2 size: %d", | |
18498 | get_mips_reg_size (abiflags_in.cpr2_size)); | |
18499 | fputs ("\nFP ABI: ", stdout); | |
18500 | print_mips_fp_abi_value (abiflags_in.fp_abi); | |
18501 | fputs ("ISA Extension: ", stdout); | |
18502 | print_mips_isa_ext (abiflags_in.isa_ext); | |
18503 | fputs ("\nASEs:", stdout); | |
18504 | print_mips_ases (abiflags_in.ases); | |
18505 | printf ("\nFLAGS 1: %8.8lx", abiflags_in.flags1); | |
18506 | printf ("\nFLAGS 2: %8.8lx", abiflags_in.flags2); | |
18507 | fputc ('\n', stdout); | |
18508 | free (abiflags_ext); | |
18509 | } | |
18510 | } | |
18511 | } | |
18512 | ||
18513 | /* We have a lot of special sections. Thanks SGI! */ | |
18514 | if (filedata->dynamic_section == NULL) | |
18515 | { | |
18516 | /* No dynamic information available. See if there is static GOT. */ | |
18517 | sect = find_section (filedata, ".got"); | |
18518 | if (sect != NULL) | |
18519 | { | |
18520 | unsigned char *data_end; | |
18521 | unsigned char *data; | |
18522 | uint64_t ent, end; | |
18523 | int addr_size; | |
18524 | ||
18525 | pltgot = sect->sh_addr; | |
18526 | ||
18527 | ent = pltgot; | |
18528 | addr_size = (is_32bit_elf ? 4 : 8); | |
18529 | end = pltgot + sect->sh_size; | |
18530 | ||
18531 | data = (unsigned char *) get_data (NULL, filedata, sect->sh_offset, | |
18532 | end - pltgot, 1, | |
18533 | _("Global Offset Table data")); | |
18534 | /* PR 12855: Null data is handled gracefully throughout. */ | |
18535 | data_end = data + (end - pltgot); | |
18536 | ||
18537 | printf (_("\nStatic GOT:\n")); | |
18538 | printf (_(" Canonical gp value: ")); | |
18539 | print_vma (ent + 0x7ff0, LONG_HEX); | |
18540 | printf ("\n\n"); | |
18541 | ||
18542 | /* In a dynamic binary GOT[0] is reserved for the dynamic | |
18543 | loader to store the lazy resolver pointer, however in | |
18544 | a static binary it may well have been omitted and GOT | |
18545 | reduced to a table of addresses. | |
18546 | PR 21344: Check for the entry being fully available | |
18547 | before fetching it. */ | |
18548 | if (data | |
18549 | && data + ent - pltgot + addr_size <= data_end | |
18550 | && byte_get (data + ent - pltgot, addr_size) == 0) | |
18551 | { | |
18552 | printf (_(" Reserved entries:\n")); | |
18553 | printf (_(" %*s %10s %*s\n"), | |
18554 | addr_size * 2, _("Address"), _("Access"), | |
18555 | addr_size * 2, _("Value")); | |
18556 | ent = print_mips_got_entry (data, pltgot, ent, data_end); | |
18557 | printf ("\n"); | |
18558 | if (ent == (uint64_t) -1) | |
18559 | goto sgot_print_fail; | |
18560 | ||
18561 | /* Check for the MSB of GOT[1] being set, identifying a | |
18562 | GNU object. This entry will be used by some runtime | |
18563 | loaders, to store the module pointer. Otherwise this | |
18564 | is an ordinary local entry. | |
18565 | PR 21344: Check for the entry being fully available | |
18566 | before fetching it. */ | |
18567 | if (data | |
18568 | && data + ent - pltgot + addr_size <= data_end | |
18569 | && (byte_get (data + ent - pltgot, addr_size) | |
18570 | >> (addr_size * 8 - 1)) != 0) | |
18571 | { | |
18572 | ent = print_mips_got_entry (data, pltgot, ent, data_end); | |
18573 | printf ("\n"); | |
18574 | if (ent == (uint64_t) -1) | |
18575 | goto sgot_print_fail; | |
18576 | } | |
18577 | printf ("\n"); | |
18578 | } | |
18579 | ||
18580 | if (data != NULL && ent < end) | |
18581 | { | |
18582 | printf (_(" Local entries:\n")); | |
18583 | printf (" %*s %10s %*s\n", | |
18584 | addr_size * 2, _("Address"), _("Access"), | |
18585 | addr_size * 2, _("Value")); | |
18586 | while (ent < end) | |
18587 | { | |
18588 | ent = print_mips_got_entry (data, pltgot, ent, data_end); | |
18589 | printf ("\n"); | |
18590 | if (ent == (uint64_t) -1) | |
18591 | goto sgot_print_fail; | |
18592 | } | |
18593 | printf ("\n"); | |
18594 | } | |
18595 | ||
18596 | sgot_print_fail: | |
18597 | free (data); | |
18598 | } | |
18599 | return res; | |
18600 | } | |
18601 | ||
18602 | for (entry = filedata->dynamic_section; | |
18603 | /* PR 17531 file: 012-50589-0.004. */ | |
18604 | (entry < filedata->dynamic_section + filedata->dynamic_nent | |
18605 | && entry->d_tag != DT_NULL); | |
18606 | ++entry) | |
18607 | switch (entry->d_tag) | |
18608 | { | |
18609 | case DT_MIPS_LIBLIST: | |
18610 | liblist_offset | |
18611 | = offset_from_vma (filedata, entry->d_un.d_val, | |
18612 | liblistno * sizeof (Elf32_External_Lib)); | |
18613 | break; | |
18614 | case DT_MIPS_LIBLISTNO: | |
18615 | liblistno = entry->d_un.d_val; | |
18616 | break; | |
18617 | case DT_MIPS_OPTIONS: | |
18618 | options_offset = offset_from_vma (filedata, entry->d_un.d_val, 0); | |
18619 | break; | |
18620 | case DT_MIPS_CONFLICT: | |
18621 | conflicts_offset | |
18622 | = offset_from_vma (filedata, entry->d_un.d_val, | |
18623 | conflictsno * sizeof (Elf32_External_Conflict)); | |
18624 | break; | |
18625 | case DT_MIPS_CONFLICTNO: | |
18626 | conflictsno = entry->d_un.d_val; | |
18627 | break; | |
18628 | case DT_PLTGOT: | |
18629 | pltgot = entry->d_un.d_ptr; | |
18630 | break; | |
18631 | case DT_MIPS_LOCAL_GOTNO: | |
18632 | local_gotno = entry->d_un.d_val; | |
18633 | break; | |
18634 | case DT_MIPS_GOTSYM: | |
18635 | gotsym = entry->d_un.d_val; | |
18636 | break; | |
18637 | case DT_MIPS_SYMTABNO: | |
18638 | symtabno = entry->d_un.d_val; | |
18639 | break; | |
18640 | case DT_MIPS_PLTGOT: | |
18641 | mips_pltgot = entry->d_un.d_ptr; | |
18642 | break; | |
18643 | case DT_PLTREL: | |
18644 | pltrel = entry->d_un.d_val; | |
18645 | break; | |
18646 | case DT_PLTRELSZ: | |
18647 | pltrelsz = entry->d_un.d_val; | |
18648 | break; | |
18649 | case DT_JMPREL: | |
18650 | jmprel = entry->d_un.d_ptr; | |
18651 | break; | |
18652 | default: | |
18653 | break; | |
18654 | } | |
18655 | ||
18656 | if (liblist_offset != 0 && liblistno != 0 && do_dynamic) | |
18657 | { | |
18658 | Elf32_External_Lib * elib; | |
18659 | size_t cnt; | |
18660 | ||
18661 | elib = (Elf32_External_Lib *) get_data (NULL, filedata, liblist_offset, | |
18662 | sizeof (Elf32_External_Lib), | |
18663 | liblistno, | |
18664 | _("liblist section data")); | |
18665 | if (elib) | |
18666 | { | |
18667 | printf (ngettext ("\nSection '.liblist' contains %zu entry:\n", | |
18668 | "\nSection '.liblist' contains %zu entries:\n", | |
18669 | liblistno), | |
18670 | liblistno); | |
18671 | fputs (_(" Library Time Stamp Checksum Version Flags\n"), | |
18672 | stdout); | |
18673 | ||
18674 | for (cnt = 0; cnt < liblistno; ++cnt) | |
18675 | { | |
18676 | Elf32_Lib liblist; | |
18677 | time_t atime; | |
18678 | char timebuf[128]; | |
18679 | struct tm * tmp; | |
18680 | ||
18681 | liblist.l_name = BYTE_GET (elib[cnt].l_name); | |
18682 | atime = BYTE_GET (elib[cnt].l_time_stamp); | |
18683 | liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum); | |
18684 | liblist.l_version = BYTE_GET (elib[cnt].l_version); | |
18685 | liblist.l_flags = BYTE_GET (elib[cnt].l_flags); | |
18686 | ||
18687 | tmp = gmtime (&atime); | |
18688 | snprintf (timebuf, sizeof (timebuf), | |
18689 | "%04u-%02u-%02uT%02u:%02u:%02u", | |
18690 | tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday, | |
18691 | tmp->tm_hour, tmp->tm_min, tmp->tm_sec); | |
18692 | ||
18693 | printf ("%3zu: ", cnt); | |
18694 | if (valid_dynamic_name (filedata, liblist.l_name)) | |
18695 | print_symbol (20, get_dynamic_name (filedata, liblist.l_name)); | |
18696 | else | |
18697 | printf (_("<corrupt: %9ld>"), liblist.l_name); | |
18698 | printf (" %s %#10lx %-7ld", timebuf, liblist.l_checksum, | |
18699 | liblist.l_version); | |
18700 | ||
18701 | if (liblist.l_flags == 0) | |
18702 | puts (_(" NONE")); | |
18703 | else | |
18704 | { | |
18705 | static const struct | |
18706 | { | |
18707 | const char * name; | |
18708 | int bit; | |
18709 | } | |
18710 | l_flags_vals[] = | |
18711 | { | |
18712 | { " EXACT_MATCH", LL_EXACT_MATCH }, | |
18713 | { " IGNORE_INT_VER", LL_IGNORE_INT_VER }, | |
18714 | { " REQUIRE_MINOR", LL_REQUIRE_MINOR }, | |
18715 | { " EXPORTS", LL_EXPORTS }, | |
18716 | { " DELAY_LOAD", LL_DELAY_LOAD }, | |
18717 | { " DELTA", LL_DELTA } | |
18718 | }; | |
18719 | int flags = liblist.l_flags; | |
18720 | size_t fcnt; | |
18721 | ||
18722 | for (fcnt = 0; fcnt < ARRAY_SIZE (l_flags_vals); ++fcnt) | |
18723 | if ((flags & l_flags_vals[fcnt].bit) != 0) | |
18724 | { | |
18725 | fputs (l_flags_vals[fcnt].name, stdout); | |
18726 | flags ^= l_flags_vals[fcnt].bit; | |
18727 | } | |
18728 | if (flags != 0) | |
18729 | printf (" %#x", (unsigned int) flags); | |
18730 | ||
18731 | puts (""); | |
18732 | } | |
18733 | } | |
18734 | ||
18735 | free (elib); | |
18736 | } | |
18737 | else | |
18738 | res = false; | |
18739 | } | |
18740 | ||
18741 | if (options_offset != 0) | |
18742 | { | |
18743 | Elf_External_Options * eopt; | |
18744 | size_t offset; | |
18745 | int cnt; | |
18746 | ||
18747 | /* Find the section header so that we get the size. */ | |
18748 | sect = find_section_by_type (filedata, SHT_MIPS_OPTIONS); | |
18749 | /* PR 17533 file: 012-277276-0.004. */ | |
18750 | if (sect == NULL) | |
18751 | { | |
18752 | error (_("No MIPS_OPTIONS header found\n")); | |
18753 | return false; | |
18754 | } | |
18755 | /* PR 24243 */ | |
18756 | if (sect->sh_size < sizeof (* eopt)) | |
18757 | { | |
18758 | error (_("The MIPS options section is too small.\n")); | |
18759 | return false; | |
18760 | } | |
18761 | ||
18762 | eopt = (Elf_External_Options *) get_data (NULL, filedata, options_offset, 1, | |
18763 | sect->sh_size, _("options")); | |
18764 | if (eopt) | |
18765 | { | |
18766 | Elf_Internal_Options option; | |
18767 | ||
18768 | offset = cnt = 0; | |
18769 | while (offset <= sect->sh_size - sizeof (* eopt)) | |
18770 | { | |
18771 | Elf_External_Options * eoption; | |
18772 | unsigned int optsize; | |
18773 | ||
18774 | eoption = (Elf_External_Options *) ((char *) eopt + offset); | |
18775 | ||
18776 | optsize = BYTE_GET (eoption->size); | |
18777 | ||
18778 | /* PR 17531: file: ffa0fa3b. */ | |
18779 | if (optsize < sizeof (* eopt) | |
18780 | || optsize > sect->sh_size - offset) | |
18781 | { | |
18782 | error (_("Invalid size (%u) for MIPS option\n"), | |
18783 | optsize); | |
18784 | free (eopt); | |
18785 | return false; | |
18786 | } | |
18787 | offset += optsize; | |
18788 | ++cnt; | |
18789 | } | |
18790 | ||
18791 | printf (ngettext ("\nSection '%s' contains %d entry:\n", | |
18792 | "\nSection '%s' contains %d entries:\n", | |
18793 | cnt), | |
18794 | printable_section_name (filedata, sect), cnt); | |
18795 | ||
18796 | offset = 0; | |
18797 | while (cnt-- > 0) | |
18798 | { | |
18799 | size_t len; | |
18800 | Elf_External_Options * eoption; | |
18801 | ||
18802 | eoption = (Elf_External_Options *) ((char *) eopt + offset); | |
18803 | ||
18804 | option.kind = BYTE_GET (eoption->kind); | |
18805 | option.size = BYTE_GET (eoption->size); | |
18806 | option.section = BYTE_GET (eoption->section); | |
18807 | option.info = BYTE_GET (eoption->info); | |
18808 | ||
18809 | switch (option.kind) | |
18810 | { | |
18811 | case ODK_NULL: | |
18812 | /* This shouldn't happen. */ | |
18813 | printf (" NULL %" PRId16 " %" PRIx32, | |
18814 | option.section, option.info); | |
18815 | break; | |
18816 | ||
18817 | case ODK_REGINFO: | |
18818 | printf (" REGINFO "); | |
18819 | if (filedata->file_header.e_machine == EM_MIPS) | |
18820 | { | |
18821 | Elf32_External_RegInfo * ereg; | |
18822 | Elf32_RegInfo reginfo; | |
18823 | ||
18824 | /* 32bit form. */ | |
18825 | if (option.size < (sizeof (Elf_External_Options) | |
18826 | + sizeof (Elf32_External_RegInfo))) | |
18827 | { | |
18828 | printf (_("<corrupt>\n")); | |
18829 | error (_("Truncated MIPS REGINFO option\n")); | |
18830 | cnt = 0; | |
18831 | break; | |
18832 | } | |
18833 | ||
18834 | ereg = (Elf32_External_RegInfo *) (eoption + 1); | |
18835 | ||
18836 | reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask); | |
18837 | reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]); | |
18838 | reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]); | |
18839 | reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]); | |
18840 | reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]); | |
18841 | reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value); | |
18842 | ||
18843 | printf ("GPR %08" PRIx32 " GP 0x%" PRIx32 "\n", | |
18844 | reginfo.ri_gprmask, reginfo.ri_gp_value); | |
18845 | printf (" " | |
18846 | " CPR0 %08" PRIx32 " CPR1 %08" PRIx32 | |
18847 | " CPR2 %08" PRIx32 " CPR3 %08" PRIx32 "\n", | |
18848 | reginfo.ri_cprmask[0], reginfo.ri_cprmask[1], | |
18849 | reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]); | |
18850 | } | |
18851 | else | |
18852 | { | |
18853 | /* 64 bit form. */ | |
18854 | Elf64_External_RegInfo * ereg; | |
18855 | Elf64_Internal_RegInfo reginfo; | |
18856 | ||
18857 | if (option.size < (sizeof (Elf_External_Options) | |
18858 | + sizeof (Elf64_External_RegInfo))) | |
18859 | { | |
18860 | printf (_("<corrupt>\n")); | |
18861 | error (_("Truncated MIPS REGINFO option\n")); | |
18862 | cnt = 0; | |
18863 | break; | |
18864 | } | |
18865 | ||
18866 | ereg = (Elf64_External_RegInfo *) (eoption + 1); | |
18867 | reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask); | |
18868 | reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]); | |
18869 | reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]); | |
18870 | reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]); | |
18871 | reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]); | |
18872 | reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value); | |
18873 | ||
18874 | printf ("GPR %08" PRIx32 " GP 0x%" PRIx64 "\n", | |
18875 | reginfo.ri_gprmask, reginfo.ri_gp_value); | |
18876 | printf (" " | |
18877 | " CPR0 %08" PRIx32 " CPR1 %08" PRIx32 | |
18878 | " CPR2 %08" PRIx32 " CPR3 %08" PRIx32 "\n", | |
18879 | reginfo.ri_cprmask[0], reginfo.ri_cprmask[1], | |
18880 | reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]); | |
18881 | } | |
18882 | offset += option.size; | |
18883 | continue; | |
18884 | ||
18885 | case ODK_EXCEPTIONS: | |
18886 | fputs (" EXCEPTIONS fpe_min(", stdout); | |
18887 | process_mips_fpe_exception (option.info & OEX_FPU_MIN); | |
18888 | fputs (") fpe_max(", stdout); | |
18889 | process_mips_fpe_exception ((option.info & OEX_FPU_MAX) >> 8); | |
18890 | fputs (")", stdout); | |
18891 | ||
18892 | if (option.info & OEX_PAGE0) | |
18893 | fputs (" PAGE0", stdout); | |
18894 | if (option.info & OEX_SMM) | |
18895 | fputs (" SMM", stdout); | |
18896 | if (option.info & OEX_FPDBUG) | |
18897 | fputs (" FPDBUG", stdout); | |
18898 | if (option.info & OEX_DISMISS) | |
18899 | fputs (" DISMISS", stdout); | |
18900 | break; | |
18901 | ||
18902 | case ODK_PAD: | |
18903 | fputs (" PAD ", stdout); | |
18904 | if (option.info & OPAD_PREFIX) | |
18905 | fputs (" PREFIX", stdout); | |
18906 | if (option.info & OPAD_POSTFIX) | |
18907 | fputs (" POSTFIX", stdout); | |
18908 | if (option.info & OPAD_SYMBOL) | |
18909 | fputs (" SYMBOL", stdout); | |
18910 | break; | |
18911 | ||
18912 | case ODK_HWPATCH: | |
18913 | fputs (" HWPATCH ", stdout); | |
18914 | if (option.info & OHW_R4KEOP) | |
18915 | fputs (" R4KEOP", stdout); | |
18916 | if (option.info & OHW_R8KPFETCH) | |
18917 | fputs (" R8KPFETCH", stdout); | |
18918 | if (option.info & OHW_R5KEOP) | |
18919 | fputs (" R5KEOP", stdout); | |
18920 | if (option.info & OHW_R5KCVTL) | |
18921 | fputs (" R5KCVTL", stdout); | |
18922 | break; | |
18923 | ||
18924 | case ODK_FILL: | |
18925 | fputs (" FILL ", stdout); | |
18926 | /* XXX Print content of info word? */ | |
18927 | break; | |
18928 | ||
18929 | case ODK_TAGS: | |
18930 | fputs (" TAGS ", stdout); | |
18931 | /* XXX Print content of info word? */ | |
18932 | break; | |
18933 | ||
18934 | case ODK_HWAND: | |
18935 | fputs (" HWAND ", stdout); | |
18936 | if (option.info & OHWA0_R4KEOP_CHECKED) | |
18937 | fputs (" R4KEOP_CHECKED", stdout); | |
18938 | if (option.info & OHWA0_R4KEOP_CLEAN) | |
18939 | fputs (" R4KEOP_CLEAN", stdout); | |
18940 | break; | |
18941 | ||
18942 | case ODK_HWOR: | |
18943 | fputs (" HWOR ", stdout); | |
18944 | if (option.info & OHWA0_R4KEOP_CHECKED) | |
18945 | fputs (" R4KEOP_CHECKED", stdout); | |
18946 | if (option.info & OHWA0_R4KEOP_CLEAN) | |
18947 | fputs (" R4KEOP_CLEAN", stdout); | |
18948 | break; | |
18949 | ||
18950 | case ODK_GP_GROUP: | |
18951 | printf (" GP_GROUP %#06x self-contained %#06x", | |
18952 | option.info & OGP_GROUP, | |
18953 | (option.info & OGP_SELF) >> 16); | |
18954 | break; | |
18955 | ||
18956 | case ODK_IDENT: | |
18957 | printf (" IDENT %#06x self-contained %#06x", | |
18958 | option.info & OGP_GROUP, | |
18959 | (option.info & OGP_SELF) >> 16); | |
18960 | break; | |
18961 | ||
18962 | default: | |
18963 | /* This shouldn't happen. */ | |
18964 | printf (" %3d ??? %" PRId16 " %" PRIx32, | |
18965 | option.kind, option.section, option.info); | |
18966 | break; | |
18967 | } | |
18968 | ||
18969 | len = sizeof (* eopt); | |
18970 | while (len < option.size) | |
18971 | { | |
18972 | unsigned char datum = *((unsigned char *) eoption + len); | |
18973 | ||
18974 | if (ISPRINT (datum)) | |
18975 | printf ("%c", datum); | |
18976 | else | |
18977 | printf ("\\%03o", datum); | |
18978 | len ++; | |
18979 | } | |
18980 | fputs ("\n", stdout); | |
18981 | ||
18982 | offset += option.size; | |
18983 | } | |
18984 | free (eopt); | |
18985 | } | |
18986 | else | |
18987 | res = false; | |
18988 | } | |
18989 | ||
18990 | if (conflicts_offset != 0 && conflictsno != 0) | |
18991 | { | |
18992 | Elf32_Conflict * iconf; | |
18993 | size_t cnt; | |
18994 | ||
18995 | if (filedata->dynamic_symbols == NULL) | |
18996 | { | |
18997 | error (_("conflict list found without a dynamic symbol table\n")); | |
18998 | return false; | |
18999 | } | |
19000 | ||
19001 | /* PR 21345 - print a slightly more helpful error message | |
19002 | if we are sure that the cmalloc will fail. */ | |
19003 | if (conflictsno > filedata->file_size / sizeof (* iconf)) | |
19004 | { | |
19005 | error (_("Overlarge number of conflicts detected: %zx\n"), | |
19006 | conflictsno); | |
19007 | return false; | |
19008 | } | |
19009 | ||
19010 | iconf = (Elf32_Conflict *) cmalloc (conflictsno, sizeof (* iconf)); | |
19011 | if (iconf == NULL) | |
19012 | { | |
19013 | error (_("Out of memory allocating space for dynamic conflicts\n")); | |
19014 | return false; | |
19015 | } | |
19016 | ||
19017 | if (is_32bit_elf) | |
19018 | { | |
19019 | Elf32_External_Conflict * econf32; | |
19020 | ||
19021 | econf32 = (Elf32_External_Conflict *) | |
19022 | get_data (NULL, filedata, conflicts_offset, | |
19023 | sizeof (*econf32), conflictsno, _("conflict")); | |
19024 | if (!econf32) | |
19025 | { | |
19026 | free (iconf); | |
19027 | return false; | |
19028 | } | |
19029 | ||
19030 | for (cnt = 0; cnt < conflictsno; ++cnt) | |
19031 | iconf[cnt] = BYTE_GET (econf32[cnt]); | |
19032 | ||
19033 | free (econf32); | |
19034 | } | |
19035 | else | |
19036 | { | |
19037 | Elf64_External_Conflict * econf64; | |
19038 | ||
19039 | econf64 = (Elf64_External_Conflict *) | |
19040 | get_data (NULL, filedata, conflicts_offset, | |
19041 | sizeof (*econf64), conflictsno, _("conflict")); | |
19042 | if (!econf64) | |
19043 | { | |
19044 | free (iconf); | |
19045 | return false; | |
19046 | } | |
19047 | ||
19048 | for (cnt = 0; cnt < conflictsno; ++cnt) | |
19049 | iconf[cnt] = BYTE_GET (econf64[cnt]); | |
19050 | ||
19051 | free (econf64); | |
19052 | } | |
19053 | ||
19054 | printf (ngettext ("\nSection '.conflict' contains %zu entry:\n", | |
19055 | "\nSection '.conflict' contains %zu entries:\n", | |
19056 | conflictsno), | |
19057 | conflictsno); | |
19058 | puts (_(" Num: Index Value Name")); | |
19059 | ||
19060 | for (cnt = 0; cnt < conflictsno; ++cnt) | |
19061 | { | |
19062 | printf ("%5zu: %8lu ", cnt, iconf[cnt]); | |
19063 | ||
19064 | if (iconf[cnt] >= filedata->num_dynamic_syms) | |
19065 | printf (_("<corrupt symbol index>")); | |
19066 | else | |
19067 | { | |
19068 | Elf_Internal_Sym * psym; | |
19069 | ||
19070 | psym = & filedata->dynamic_symbols[iconf[cnt]]; | |
19071 | print_vma (psym->st_value, FULL_HEX); | |
19072 | putchar (' '); | |
19073 | if (valid_dynamic_name (filedata, psym->st_name)) | |
19074 | print_symbol (25, get_dynamic_name (filedata, psym->st_name)); | |
19075 | else | |
19076 | printf (_("<corrupt: %14ld>"), psym->st_name); | |
19077 | } | |
19078 | putchar ('\n'); | |
19079 | } | |
19080 | ||
19081 | free (iconf); | |
19082 | } | |
19083 | ||
19084 | if (pltgot != 0 && local_gotno != 0) | |
19085 | { | |
19086 | uint64_t ent, local_end, global_end; | |
19087 | size_t i, offset; | |
19088 | unsigned char * data; | |
19089 | unsigned char * data_end; | |
19090 | int addr_size; | |
19091 | ||
19092 | ent = pltgot; | |
19093 | addr_size = (is_32bit_elf ? 4 : 8); | |
19094 | local_end = pltgot + local_gotno * addr_size; | |
19095 | ||
19096 | /* PR binutils/17533 file: 012-111227-0.004 */ | |
19097 | if (symtabno < gotsym) | |
19098 | { | |
19099 | error (_("The GOT symbol offset (%" PRIu64 | |
19100 | ") is greater than the symbol table size (%" PRIu64 ")\n"), | |
19101 | gotsym, symtabno); | |
19102 | return false; | |
19103 | } | |
19104 | ||
19105 | global_end = local_end + (symtabno - gotsym) * addr_size; | |
19106 | /* PR 17531: file: 54c91a34. */ | |
19107 | if (global_end < local_end) | |
19108 | { | |
19109 | error (_("Too many GOT symbols: %" PRIu64 "\n"), symtabno); | |
19110 | return false; | |
19111 | } | |
19112 | ||
19113 | offset = offset_from_vma (filedata, pltgot, global_end - pltgot); | |
19114 | data = (unsigned char *) get_data (NULL, filedata, offset, | |
19115 | global_end - pltgot, 1, | |
19116 | _("Global Offset Table data")); | |
19117 | /* PR 12855: Null data is handled gracefully throughout. */ | |
19118 | data_end = data + (global_end - pltgot); | |
19119 | ||
19120 | printf (_("\nPrimary GOT:\n")); | |
19121 | printf (_(" Canonical gp value: ")); | |
19122 | print_vma (pltgot + 0x7ff0, LONG_HEX); | |
19123 | printf ("\n\n"); | |
19124 | ||
19125 | printf (_(" Reserved entries:\n")); | |
19126 | printf (_(" %*s %10s %*s Purpose\n"), | |
19127 | addr_size * 2, _("Address"), _("Access"), | |
19128 | addr_size * 2, _("Initial")); | |
19129 | ent = print_mips_got_entry (data, pltgot, ent, data_end); | |
19130 | printf (_(" Lazy resolver\n")); | |
19131 | if (ent == (uint64_t) -1) | |
19132 | goto got_print_fail; | |
19133 | ||
19134 | /* Check for the MSB of GOT[1] being set, denoting a GNU object. | |
19135 | This entry will be used by some runtime loaders, to store the | |
19136 | module pointer. Otherwise this is an ordinary local entry. | |
19137 | PR 21344: Check for the entry being fully available before | |
19138 | fetching it. */ | |
19139 | if (data | |
19140 | && data + ent - pltgot + addr_size <= data_end | |
19141 | && (byte_get (data + ent - pltgot, addr_size) | |
19142 | >> (addr_size * 8 - 1)) != 0) | |
19143 | { | |
19144 | ent = print_mips_got_entry (data, pltgot, ent, data_end); | |
19145 | printf (_(" Module pointer (GNU extension)\n")); | |
19146 | if (ent == (uint64_t) -1) | |
19147 | goto got_print_fail; | |
19148 | } | |
19149 | printf ("\n"); | |
19150 | ||
19151 | if (data != NULL && ent < local_end) | |
19152 | { | |
19153 | printf (_(" Local entries:\n")); | |
19154 | printf (" %*s %10s %*s\n", | |
19155 | addr_size * 2, _("Address"), _("Access"), | |
19156 | addr_size * 2, _("Initial")); | |
19157 | while (ent < local_end) | |
19158 | { | |
19159 | ent = print_mips_got_entry (data, pltgot, ent, data_end); | |
19160 | printf ("\n"); | |
19161 | if (ent == (uint64_t) -1) | |
19162 | goto got_print_fail; | |
19163 | } | |
19164 | printf ("\n"); | |
19165 | } | |
19166 | ||
19167 | if (data != NULL && gotsym < symtabno) | |
19168 | { | |
19169 | int sym_width; | |
19170 | ||
19171 | printf (_(" Global entries:\n")); | |
19172 | printf (" %*s %10s %*s %*s %-7s %3s %s\n", | |
19173 | addr_size * 2, _("Address"), | |
19174 | _("Access"), | |
19175 | addr_size * 2, _("Initial"), | |
19176 | addr_size * 2, _("Sym.Val."), | |
19177 | _("Type"), | |
19178 | /* Note for translators: "Ndx" = abbreviated form of "Index". */ | |
19179 | _("Ndx"), _("Name")); | |
19180 | ||
19181 | sym_width = (is_32bit_elf ? 80 : 160) - 28 - addr_size * 6 - 1; | |
19182 | ||
19183 | for (i = gotsym; i < symtabno; i++) | |
19184 | { | |
19185 | ent = print_mips_got_entry (data, pltgot, ent, data_end); | |
19186 | printf (" "); | |
19187 | ||
19188 | if (filedata->dynamic_symbols == NULL) | |
19189 | printf (_("<no dynamic symbols>")); | |
19190 | else if (i < filedata->num_dynamic_syms) | |
19191 | { | |
19192 | Elf_Internal_Sym * psym = filedata->dynamic_symbols + i; | |
19193 | ||
19194 | print_vma (psym->st_value, LONG_HEX); | |
19195 | printf (" %-7s %3s ", | |
19196 | get_symbol_type (filedata, ELF_ST_TYPE (psym->st_info)), | |
19197 | get_symbol_index_type (filedata, psym->st_shndx)); | |
19198 | ||
19199 | if (valid_dynamic_name (filedata, psym->st_name)) | |
19200 | print_symbol (sym_width, | |
19201 | get_dynamic_name (filedata, psym->st_name)); | |
19202 | else | |
19203 | printf (_("<corrupt: %14ld>"), psym->st_name); | |
19204 | } | |
19205 | else | |
19206 | printf (_("<symbol index %zu exceeds number of dynamic symbols>"), | |
19207 | i); | |
19208 | ||
19209 | printf ("\n"); | |
19210 | if (ent == (uint64_t) -1) | |
19211 | break; | |
19212 | } | |
19213 | printf ("\n"); | |
19214 | } | |
19215 | ||
19216 | got_print_fail: | |
19217 | free (data); | |
19218 | } | |
19219 | ||
19220 | if (mips_pltgot != 0 && jmprel != 0 && pltrel != 0 && pltrelsz != 0) | |
19221 | { | |
19222 | uint64_t ent, end; | |
19223 | uint64_t offset, rel_offset; | |
19224 | uint64_t count, i; | |
19225 | unsigned char * data; | |
19226 | int addr_size, sym_width; | |
19227 | Elf_Internal_Rela * rels; | |
19228 | ||
19229 | rel_offset = offset_from_vma (filedata, jmprel, pltrelsz); | |
19230 | if (pltrel == DT_RELA) | |
19231 | { | |
19232 | if (!slurp_rela_relocs (filedata, rel_offset, pltrelsz, &rels, &count)) | |
19233 | return false; | |
19234 | } | |
19235 | else | |
19236 | { | |
19237 | if (!slurp_rel_relocs (filedata, rel_offset, pltrelsz, &rels, &count)) | |
19238 | return false; | |
19239 | } | |
19240 | ||
19241 | ent = mips_pltgot; | |
19242 | addr_size = (is_32bit_elf ? 4 : 8); | |
19243 | end = mips_pltgot + (2 + count) * addr_size; | |
19244 | ||
19245 | offset = offset_from_vma (filedata, mips_pltgot, end - mips_pltgot); | |
19246 | data = (unsigned char *) get_data (NULL, filedata, offset, end - mips_pltgot, | |
19247 | 1, _("Procedure Linkage Table data")); | |
19248 | if (data == NULL) | |
19249 | { | |
19250 | free (rels); | |
19251 | return false; | |
19252 | } | |
19253 | ||
19254 | printf ("\nPLT GOT:\n\n"); | |
19255 | printf (_(" Reserved entries:\n")); | |
19256 | printf (_(" %*s %*s Purpose\n"), | |
19257 | addr_size * 2, _("Address"), addr_size * 2, _("Initial")); | |
19258 | ent = print_mips_pltgot_entry (data, mips_pltgot, ent); | |
19259 | printf (_(" PLT lazy resolver\n")); | |
19260 | ent = print_mips_pltgot_entry (data, mips_pltgot, ent); | |
19261 | printf (_(" Module pointer\n")); | |
19262 | printf ("\n"); | |
19263 | ||
19264 | printf (_(" Entries:\n")); | |
19265 | printf (" %*s %*s %*s %-7s %3s %s\n", | |
19266 | addr_size * 2, _("Address"), | |
19267 | addr_size * 2, _("Initial"), | |
19268 | addr_size * 2, _("Sym.Val."), _("Type"), _("Ndx"), _("Name")); | |
19269 | sym_width = (is_32bit_elf ? 80 : 160) - 17 - addr_size * 6 - 1; | |
19270 | for (i = 0; i < count; i++) | |
19271 | { | |
19272 | uint64_t idx = get_reloc_symindex (rels[i].r_info); | |
19273 | ||
19274 | ent = print_mips_pltgot_entry (data, mips_pltgot, ent); | |
19275 | printf (" "); | |
19276 | ||
19277 | if (idx >= filedata->num_dynamic_syms) | |
19278 | printf (_("<corrupt symbol index: %" PRIu64 ">"), idx); | |
19279 | else | |
19280 | { | |
19281 | Elf_Internal_Sym * psym = filedata->dynamic_symbols + idx; | |
19282 | ||
19283 | print_vma (psym->st_value, LONG_HEX); | |
19284 | printf (" %-7s %3s ", | |
19285 | get_symbol_type (filedata, ELF_ST_TYPE (psym->st_info)), | |
19286 | get_symbol_index_type (filedata, psym->st_shndx)); | |
19287 | if (valid_dynamic_name (filedata, psym->st_name)) | |
19288 | print_symbol (sym_width, | |
19289 | get_dynamic_name (filedata, psym->st_name)); | |
19290 | else | |
19291 | printf (_("<corrupt: %14ld>"), psym->st_name); | |
19292 | } | |
19293 | printf ("\n"); | |
19294 | } | |
19295 | printf ("\n"); | |
19296 | ||
19297 | free (data); | |
19298 | free (rels); | |
19299 | } | |
19300 | ||
19301 | return res; | |
19302 | } | |
19303 | ||
19304 | static bool | |
19305 | process_nds32_specific (Filedata * filedata) | |
19306 | { | |
19307 | Elf_Internal_Shdr *sect = NULL; | |
19308 | ||
19309 | sect = find_section (filedata, ".nds32_e_flags"); | |
19310 | if (sect != NULL && sect->sh_size >= 4) | |
19311 | { | |
19312 | unsigned char *buf; | |
19313 | unsigned int flag; | |
19314 | ||
19315 | printf ("\nNDS32 elf flags section:\n"); | |
19316 | buf = get_data (NULL, filedata, sect->sh_offset, 1, 4, | |
19317 | _("NDS32 elf flags section")); | |
19318 | ||
19319 | if (buf == NULL) | |
19320 | return false; | |
19321 | ||
19322 | flag = byte_get (buf, 4); | |
19323 | free (buf); | |
19324 | switch (flag & 0x3) | |
19325 | { | |
19326 | case 0: | |
19327 | printf ("(VEC_SIZE):\tNo entry.\n"); | |
19328 | break; | |
19329 | case 1: | |
19330 | printf ("(VEC_SIZE):\t4 bytes\n"); | |
19331 | break; | |
19332 | case 2: | |
19333 | printf ("(VEC_SIZE):\t16 bytes\n"); | |
19334 | break; | |
19335 | case 3: | |
19336 | printf ("(VEC_SIZE):\treserved\n"); | |
19337 | break; | |
19338 | } | |
19339 | } | |
19340 | ||
19341 | return true; | |
19342 | } | |
19343 | ||
19344 | static bool | |
19345 | process_gnu_liblist (Filedata * filedata) | |
19346 | { | |
19347 | Elf_Internal_Shdr * section; | |
19348 | Elf_Internal_Shdr * string_sec; | |
19349 | Elf32_External_Lib * elib; | |
19350 | char * strtab; | |
19351 | size_t strtab_size; | |
19352 | size_t cnt; | |
19353 | uint64_t num_liblist; | |
19354 | unsigned i; | |
19355 | bool res = true; | |
19356 | ||
19357 | if (! do_arch) | |
19358 | return true; | |
19359 | ||
19360 | for (i = 0, section = filedata->section_headers; | |
19361 | i < filedata->file_header.e_shnum; | |
19362 | i++, section++) | |
19363 | { | |
19364 | switch (section->sh_type) | |
19365 | { | |
19366 | case SHT_GNU_LIBLIST: | |
19367 | if (section->sh_link >= filedata->file_header.e_shnum) | |
19368 | break; | |
19369 | ||
19370 | elib = (Elf32_External_Lib *) | |
19371 | get_data (NULL, filedata, section->sh_offset, 1, section->sh_size, | |
19372 | _("liblist section data")); | |
19373 | ||
19374 | if (elib == NULL) | |
19375 | { | |
19376 | res = false; | |
19377 | break; | |
19378 | } | |
19379 | ||
19380 | string_sec = filedata->section_headers + section->sh_link; | |
19381 | strtab = (char *) get_data (NULL, filedata, string_sec->sh_offset, 1, | |
19382 | string_sec->sh_size, | |
19383 | _("liblist string table")); | |
19384 | if (strtab == NULL | |
19385 | || section->sh_entsize != sizeof (Elf32_External_Lib)) | |
19386 | { | |
19387 | free (elib); | |
19388 | free (strtab); | |
19389 | res = false; | |
19390 | break; | |
19391 | } | |
19392 | strtab_size = string_sec->sh_size; | |
19393 | ||
19394 | num_liblist = section->sh_size / sizeof (Elf32_External_Lib); | |
19395 | printf (ngettext ("\nLibrary list section '%s' contains %" PRIu64 | |
19396 | " entries:\n", | |
19397 | "\nLibrary list section '%s' contains %" PRIu64 | |
19398 | " entries:\n", | |
19399 | num_liblist), | |
19400 | printable_section_name (filedata, section), | |
19401 | num_liblist); | |
19402 | ||
19403 | puts (_(" Library Time Stamp Checksum Version Flags")); | |
19404 | ||
19405 | for (cnt = 0; cnt < section->sh_size / sizeof (Elf32_External_Lib); | |
19406 | ++cnt) | |
19407 | { | |
19408 | Elf32_Lib liblist; | |
19409 | time_t atime; | |
19410 | char timebuf[128]; | |
19411 | struct tm * tmp; | |
19412 | ||
19413 | liblist.l_name = BYTE_GET (elib[cnt].l_name); | |
19414 | atime = BYTE_GET (elib[cnt].l_time_stamp); | |
19415 | liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum); | |
19416 | liblist.l_version = BYTE_GET (elib[cnt].l_version); | |
19417 | liblist.l_flags = BYTE_GET (elib[cnt].l_flags); | |
19418 | ||
19419 | tmp = gmtime (&atime); | |
19420 | snprintf (timebuf, sizeof (timebuf), | |
19421 | "%04u-%02u-%02uT%02u:%02u:%02u", | |
19422 | tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday, | |
19423 | tmp->tm_hour, tmp->tm_min, tmp->tm_sec); | |
19424 | ||
19425 | printf ("%3zu: ", cnt); | |
19426 | if (do_wide) | |
19427 | printf ("%-20s", liblist.l_name < strtab_size | |
19428 | ? strtab + liblist.l_name : _("<corrupt>")); | |
19429 | else | |
19430 | printf ("%-20.20s", liblist.l_name < strtab_size | |
19431 | ? strtab + liblist.l_name : _("<corrupt>")); | |
19432 | printf (" %s %#010lx %-7ld %-7ld\n", timebuf, liblist.l_checksum, | |
19433 | liblist.l_version, liblist.l_flags); | |
19434 | } | |
19435 | ||
19436 | free (elib); | |
19437 | free (strtab); | |
19438 | } | |
19439 | } | |
19440 | ||
19441 | return res; | |
19442 | } | |
19443 | ||
19444 | static const char * | |
19445 | get_note_type (Filedata * filedata, unsigned e_type) | |
19446 | { | |
19447 | static char buff[64]; | |
19448 | ||
19449 | if (filedata->file_header.e_type == ET_CORE) | |
19450 | switch (e_type) | |
19451 | { | |
19452 | case NT_AUXV: | |
19453 | return _("NT_AUXV (auxiliary vector)"); | |
19454 | case NT_PRSTATUS: | |
19455 | return _("NT_PRSTATUS (prstatus structure)"); | |
19456 | case NT_FPREGSET: | |
19457 | return _("NT_FPREGSET (floating point registers)"); | |
19458 | case NT_PRPSINFO: | |
19459 | return _("NT_PRPSINFO (prpsinfo structure)"); | |
19460 | case NT_TASKSTRUCT: | |
19461 | return _("NT_TASKSTRUCT (task structure)"); | |
19462 | case NT_GDB_TDESC: | |
19463 | return _("NT_GDB_TDESC (GDB XML target description)"); | |
19464 | case NT_PRXFPREG: | |
19465 | return _("NT_PRXFPREG (user_xfpregs structure)"); | |
19466 | case NT_PPC_VMX: | |
19467 | return _("NT_PPC_VMX (ppc Altivec registers)"); | |
19468 | case NT_PPC_VSX: | |
19469 | return _("NT_PPC_VSX (ppc VSX registers)"); | |
19470 | case NT_PPC_TAR: | |
19471 | return _("NT_PPC_TAR (ppc TAR register)"); | |
19472 | case NT_PPC_PPR: | |
19473 | return _("NT_PPC_PPR (ppc PPR register)"); | |
19474 | case NT_PPC_DSCR: | |
19475 | return _("NT_PPC_DSCR (ppc DSCR register)"); | |
19476 | case NT_PPC_EBB: | |
19477 | return _("NT_PPC_EBB (ppc EBB registers)"); | |
19478 | case NT_PPC_PMU: | |
19479 | return _("NT_PPC_PMU (ppc PMU registers)"); | |
19480 | case NT_PPC_TM_CGPR: | |
19481 | return _("NT_PPC_TM_CGPR (ppc checkpointed GPR registers)"); | |
19482 | case NT_PPC_TM_CFPR: | |
19483 | return _("NT_PPC_TM_CFPR (ppc checkpointed floating point registers)"); | |
19484 | case NT_PPC_TM_CVMX: | |
19485 | return _("NT_PPC_TM_CVMX (ppc checkpointed Altivec registers)"); | |
19486 | case NT_PPC_TM_CVSX: | |
19487 | return _("NT_PPC_TM_CVSX (ppc checkpointed VSX registers)"); | |
19488 | case NT_PPC_TM_SPR: | |
19489 | return _("NT_PPC_TM_SPR (ppc TM special purpose registers)"); | |
19490 | case NT_PPC_TM_CTAR: | |
19491 | return _("NT_PPC_TM_CTAR (ppc checkpointed TAR register)"); | |
19492 | case NT_PPC_TM_CPPR: | |
19493 | return _("NT_PPC_TM_CPPR (ppc checkpointed PPR register)"); | |
19494 | case NT_PPC_TM_CDSCR: | |
19495 | return _("NT_PPC_TM_CDSCR (ppc checkpointed DSCR register)"); | |
19496 | case NT_386_TLS: | |
19497 | return _("NT_386_TLS (x86 TLS information)"); | |
19498 | case NT_386_IOPERM: | |
19499 | return _("NT_386_IOPERM (x86 I/O permissions)"); | |
19500 | case NT_X86_XSTATE: | |
19501 | return _("NT_X86_XSTATE (x86 XSAVE extended state)"); | |
19502 | case NT_X86_CET: | |
19503 | return _("NT_X86_CET (x86 CET state)"); | |
19504 | case NT_S390_HIGH_GPRS: | |
19505 | return _("NT_S390_HIGH_GPRS (s390 upper register halves)"); | |
19506 | case NT_S390_TIMER: | |
19507 | return _("NT_S390_TIMER (s390 timer register)"); | |
19508 | case NT_S390_TODCMP: | |
19509 | return _("NT_S390_TODCMP (s390 TOD comparator register)"); | |
19510 | case NT_S390_TODPREG: | |
19511 | return _("NT_S390_TODPREG (s390 TOD programmable register)"); | |
19512 | case NT_S390_CTRS: | |
19513 | return _("NT_S390_CTRS (s390 control registers)"); | |
19514 | case NT_S390_PREFIX: | |
19515 | return _("NT_S390_PREFIX (s390 prefix register)"); | |
19516 | case NT_S390_LAST_BREAK: | |
19517 | return _("NT_S390_LAST_BREAK (s390 last breaking event address)"); | |
19518 | case NT_S390_SYSTEM_CALL: | |
19519 | return _("NT_S390_SYSTEM_CALL (s390 system call restart data)"); | |
19520 | case NT_S390_TDB: | |
19521 | return _("NT_S390_TDB (s390 transaction diagnostic block)"); | |
19522 | case NT_S390_VXRS_LOW: | |
19523 | return _("NT_S390_VXRS_LOW (s390 vector registers 0-15 upper half)"); | |
19524 | case NT_S390_VXRS_HIGH: | |
19525 | return _("NT_S390_VXRS_HIGH (s390 vector registers 16-31)"); | |
19526 | case NT_S390_GS_CB: | |
19527 | return _("NT_S390_GS_CB (s390 guarded-storage registers)"); | |
19528 | case NT_S390_GS_BC: | |
19529 | return _("NT_S390_GS_BC (s390 guarded-storage broadcast control)"); | |
19530 | case NT_ARM_VFP: | |
19531 | return _("NT_ARM_VFP (arm VFP registers)"); | |
19532 | case NT_ARM_TLS: | |
19533 | return _("NT_ARM_TLS (AArch TLS registers)"); | |
19534 | case NT_ARM_HW_BREAK: | |
19535 | return _("NT_ARM_HW_BREAK (AArch hardware breakpoint registers)"); | |
19536 | case NT_ARM_HW_WATCH: | |
19537 | return _("NT_ARM_HW_WATCH (AArch hardware watchpoint registers)"); | |
19538 | case NT_ARM_SYSTEM_CALL: | |
19539 | return _("NT_ARM_SYSTEM_CALL (AArch system call number)"); | |
19540 | case NT_ARM_SVE: | |
19541 | return _("NT_ARM_SVE (AArch SVE registers)"); | |
19542 | case NT_ARM_PAC_MASK: | |
19543 | return _("NT_ARM_PAC_MASK (AArch pointer authentication code masks)"); | |
19544 | case NT_ARM_PACA_KEYS: | |
19545 | return _("NT_ARM_PACA_KEYS (ARM pointer authentication address keys)"); | |
19546 | case NT_ARM_PACG_KEYS: | |
19547 | return _("NT_ARM_PACG_KEYS (ARM pointer authentication generic keys)"); | |
19548 | case NT_ARM_TAGGED_ADDR_CTRL: | |
19549 | return _("NT_ARM_TAGGED_ADDR_CTRL (AArch tagged address control)"); | |
19550 | case NT_ARM_PAC_ENABLED_KEYS: | |
19551 | return _("NT_ARM_PAC_ENABLED_KEYS (AArch64 pointer authentication enabled keys)"); | |
19552 | case NT_ARC_V2: | |
19553 | return _("NT_ARC_V2 (ARC HS accumulator/extra registers)"); | |
19554 | case NT_RISCV_CSR: | |
19555 | return _("NT_RISCV_CSR (RISC-V control and status registers)"); | |
19556 | case NT_PSTATUS: | |
19557 | return _("NT_PSTATUS (pstatus structure)"); | |
19558 | case NT_FPREGS: | |
19559 | return _("NT_FPREGS (floating point registers)"); | |
19560 | case NT_PSINFO: | |
19561 | return _("NT_PSINFO (psinfo structure)"); | |
19562 | case NT_LWPSTATUS: | |
19563 | return _("NT_LWPSTATUS (lwpstatus_t structure)"); | |
19564 | case NT_LWPSINFO: | |
19565 | return _("NT_LWPSINFO (lwpsinfo_t structure)"); | |
19566 | case NT_WIN32PSTATUS: | |
19567 | return _("NT_WIN32PSTATUS (win32_pstatus structure)"); | |
19568 | case NT_SIGINFO: | |
19569 | return _("NT_SIGINFO (siginfo_t data)"); | |
19570 | case NT_FILE: | |
19571 | return _("NT_FILE (mapped files)"); | |
19572 | default: | |
19573 | break; | |
19574 | } | |
19575 | else | |
19576 | switch (e_type) | |
19577 | { | |
19578 | case NT_VERSION: | |
19579 | return _("NT_VERSION (version)"); | |
19580 | case NT_ARCH: | |
19581 | return _("NT_ARCH (architecture)"); | |
19582 | case NT_GNU_BUILD_ATTRIBUTE_OPEN: | |
19583 | return _("OPEN"); | |
19584 | case NT_GNU_BUILD_ATTRIBUTE_FUNC: | |
19585 | return _("func"); | |
19586 | case NT_GO_BUILDID: | |
19587 | return _("GO BUILDID"); | |
19588 | case FDO_PACKAGING_METADATA: | |
19589 | return _("FDO_PACKAGING_METADATA"); | |
19590 | default: | |
19591 | break; | |
19592 | } | |
19593 | ||
19594 | snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type); | |
19595 | return buff; | |
19596 | } | |
19597 | ||
19598 | static bool | |
19599 | print_core_note (Elf_Internal_Note *pnote) | |
19600 | { | |
19601 | unsigned int addr_size = is_32bit_elf ? 4 : 8; | |
19602 | uint64_t count, page_size; | |
19603 | unsigned char *descdata, *filenames, *descend; | |
19604 | ||
19605 | if (pnote->type != NT_FILE) | |
19606 | { | |
19607 | if (do_wide) | |
19608 | printf ("\n"); | |
19609 | return true; | |
19610 | } | |
19611 | ||
19612 | if (!is_32bit_elf) | |
19613 | { | |
19614 | printf (_(" Cannot decode 64-bit note in 32-bit build\n")); | |
19615 | /* Still "successful". */ | |
19616 | return true; | |
19617 | } | |
19618 | ||
19619 | if (pnote->descsz < 2 * addr_size) | |
19620 | { | |
19621 | error (_(" Malformed note - too short for header\n")); | |
19622 | return false; | |
19623 | } | |
19624 | ||
19625 | descdata = (unsigned char *) pnote->descdata; | |
19626 | descend = descdata + pnote->descsz; | |
19627 | ||
19628 | if (descdata[pnote->descsz - 1] != '\0') | |
19629 | { | |
19630 | error (_(" Malformed note - does not end with \\0\n")); | |
19631 | return false; | |
19632 | } | |
19633 | ||
19634 | count = byte_get (descdata, addr_size); | |
19635 | descdata += addr_size; | |
19636 | ||
19637 | page_size = byte_get (descdata, addr_size); | |
19638 | descdata += addr_size; | |
19639 | ||
19640 | if (count > ((uint64_t) -1 - 2 * addr_size) / (3 * addr_size) | |
19641 | || pnote->descsz < 2 * addr_size + count * 3 * addr_size) | |
19642 | { | |
19643 | error (_(" Malformed note - too short for supplied file count\n")); | |
19644 | return false; | |
19645 | } | |
19646 | ||
19647 | printf (_(" Page size: ")); | |
19648 | print_vma (page_size, DEC); | |
19649 | printf ("\n"); | |
19650 | ||
19651 | printf (_(" %*s%*s%*s\n"), | |
19652 | (int) (2 + 2 * addr_size), _("Start"), | |
19653 | (int) (4 + 2 * addr_size), _("End"), | |
19654 | (int) (4 + 2 * addr_size), _("Page Offset")); | |
19655 | filenames = descdata + count * 3 * addr_size; | |
19656 | while (count-- > 0) | |
19657 | { | |
19658 | uint64_t start, end, file_ofs; | |
19659 | ||
19660 | if (filenames == descend) | |
19661 | { | |
19662 | error (_(" Malformed note - filenames end too early\n")); | |
19663 | return false; | |
19664 | } | |
19665 | ||
19666 | start = byte_get (descdata, addr_size); | |
19667 | descdata += addr_size; | |
19668 | end = byte_get (descdata, addr_size); | |
19669 | descdata += addr_size; | |
19670 | file_ofs = byte_get (descdata, addr_size); | |
19671 | descdata += addr_size; | |
19672 | ||
19673 | printf (" "); | |
19674 | print_vma (start, FULL_HEX); | |
19675 | printf (" "); | |
19676 | print_vma (end, FULL_HEX); | |
19677 | printf (" "); | |
19678 | print_vma (file_ofs, FULL_HEX); | |
19679 | printf ("\n %s\n", filenames); | |
19680 | ||
19681 | filenames += 1 + strlen ((char *) filenames); | |
19682 | } | |
19683 | ||
19684 | return true; | |
19685 | } | |
19686 | ||
19687 | static const char * | |
19688 | get_gnu_elf_note_type (unsigned e_type) | |
19689 | { | |
19690 | /* NB/ Keep this switch statement in sync with print_gnu_note (). */ | |
19691 | switch (e_type) | |
19692 | { | |
19693 | case NT_GNU_ABI_TAG: | |
19694 | return _("NT_GNU_ABI_TAG (ABI version tag)"); | |
19695 | case NT_GNU_HWCAP: | |
19696 | return _("NT_GNU_HWCAP (DSO-supplied software HWCAP info)"); | |
19697 | case NT_GNU_BUILD_ID: | |
19698 | return _("NT_GNU_BUILD_ID (unique build ID bitstring)"); | |
19699 | case NT_GNU_GOLD_VERSION: | |
19700 | return _("NT_GNU_GOLD_VERSION (gold version)"); | |
19701 | case NT_GNU_PROPERTY_TYPE_0: | |
19702 | return _("NT_GNU_PROPERTY_TYPE_0"); | |
19703 | case NT_GNU_BUILD_ATTRIBUTE_OPEN: | |
19704 | return _("NT_GNU_BUILD_ATTRIBUTE_OPEN"); | |
19705 | case NT_GNU_BUILD_ATTRIBUTE_FUNC: | |
19706 | return _("NT_GNU_BUILD_ATTRIBUTE_FUNC"); | |
19707 | default: | |
19708 | { | |
19709 | static char buff[64]; | |
19710 | ||
19711 | snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type); | |
19712 | return buff; | |
19713 | } | |
19714 | } | |
19715 | } | |
19716 | ||
19717 | static void | |
19718 | decode_x86_compat_isa (unsigned int bitmask) | |
19719 | { | |
19720 | while (bitmask) | |
19721 | { | |
19722 | unsigned int bit = bitmask & (- bitmask); | |
19723 | ||
19724 | bitmask &= ~ bit; | |
19725 | switch (bit) | |
19726 | { | |
19727 | case GNU_PROPERTY_X86_COMPAT_ISA_1_486: | |
19728 | printf ("i486"); | |
19729 | break; | |
19730 | case GNU_PROPERTY_X86_COMPAT_ISA_1_586: | |
19731 | printf ("586"); | |
19732 | break; | |
19733 | case GNU_PROPERTY_X86_COMPAT_ISA_1_686: | |
19734 | printf ("686"); | |
19735 | break; | |
19736 | case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE: | |
19737 | printf ("SSE"); | |
19738 | break; | |
19739 | case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE2: | |
19740 | printf ("SSE2"); | |
19741 | break; | |
19742 | case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE3: | |
19743 | printf ("SSE3"); | |
19744 | break; | |
19745 | case GNU_PROPERTY_X86_COMPAT_ISA_1_SSSE3: | |
19746 | printf ("SSSE3"); | |
19747 | break; | |
19748 | case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE4_1: | |
19749 | printf ("SSE4_1"); | |
19750 | break; | |
19751 | case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE4_2: | |
19752 | printf ("SSE4_2"); | |
19753 | break; | |
19754 | case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX: | |
19755 | printf ("AVX"); | |
19756 | break; | |
19757 | case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX2: | |
19758 | printf ("AVX2"); | |
19759 | break; | |
19760 | case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512F: | |
19761 | printf ("AVX512F"); | |
19762 | break; | |
19763 | case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512CD: | |
19764 | printf ("AVX512CD"); | |
19765 | break; | |
19766 | case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512ER: | |
19767 | printf ("AVX512ER"); | |
19768 | break; | |
19769 | case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512PF: | |
19770 | printf ("AVX512PF"); | |
19771 | break; | |
19772 | case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512VL: | |
19773 | printf ("AVX512VL"); | |
19774 | break; | |
19775 | case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512DQ: | |
19776 | printf ("AVX512DQ"); | |
19777 | break; | |
19778 | case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512BW: | |
19779 | printf ("AVX512BW"); | |
19780 | break; | |
19781 | default: | |
19782 | printf (_("<unknown: %x>"), bit); | |
19783 | break; | |
19784 | } | |
19785 | if (bitmask) | |
19786 | printf (", "); | |
19787 | } | |
19788 | } | |
19789 | ||
19790 | static void | |
19791 | decode_x86_compat_2_isa (unsigned int bitmask) | |
19792 | { | |
19793 | if (!bitmask) | |
19794 | { | |
19795 | printf (_("<None>")); | |
19796 | return; | |
19797 | } | |
19798 | ||
19799 | while (bitmask) | |
19800 | { | |
19801 | unsigned int bit = bitmask & (- bitmask); | |
19802 | ||
19803 | bitmask &= ~ bit; | |
19804 | switch (bit) | |
19805 | { | |
19806 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_CMOV: | |
19807 | printf ("CMOV"); | |
19808 | break; | |
19809 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE: | |
19810 | printf ("SSE"); | |
19811 | break; | |
19812 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE2: | |
19813 | printf ("SSE2"); | |
19814 | break; | |
19815 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE3: | |
19816 | printf ("SSE3"); | |
19817 | break; | |
19818 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSSE3: | |
19819 | printf ("SSSE3"); | |
19820 | break; | |
19821 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE4_1: | |
19822 | printf ("SSE4_1"); | |
19823 | break; | |
19824 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE4_2: | |
19825 | printf ("SSE4_2"); | |
19826 | break; | |
19827 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX: | |
19828 | printf ("AVX"); | |
19829 | break; | |
19830 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX2: | |
19831 | printf ("AVX2"); | |
19832 | break; | |
19833 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_FMA: | |
19834 | printf ("FMA"); | |
19835 | break; | |
19836 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512F: | |
19837 | printf ("AVX512F"); | |
19838 | break; | |
19839 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512CD: | |
19840 | printf ("AVX512CD"); | |
19841 | break; | |
19842 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512ER: | |
19843 | printf ("AVX512ER"); | |
19844 | break; | |
19845 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512PF: | |
19846 | printf ("AVX512PF"); | |
19847 | break; | |
19848 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512VL: | |
19849 | printf ("AVX512VL"); | |
19850 | break; | |
19851 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512DQ: | |
19852 | printf ("AVX512DQ"); | |
19853 | break; | |
19854 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512BW: | |
19855 | printf ("AVX512BW"); | |
19856 | break; | |
19857 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_4FMAPS: | |
19858 | printf ("AVX512_4FMAPS"); | |
19859 | break; | |
19860 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_4VNNIW: | |
19861 | printf ("AVX512_4VNNIW"); | |
19862 | break; | |
19863 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_BITALG: | |
19864 | printf ("AVX512_BITALG"); | |
19865 | break; | |
19866 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_IFMA: | |
19867 | printf ("AVX512_IFMA"); | |
19868 | break; | |
19869 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_VBMI: | |
19870 | printf ("AVX512_VBMI"); | |
19871 | break; | |
19872 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_VBMI2: | |
19873 | printf ("AVX512_VBMI2"); | |
19874 | break; | |
19875 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_VNNI: | |
19876 | printf ("AVX512_VNNI"); | |
19877 | break; | |
19878 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_BF16: | |
19879 | printf ("AVX512_BF16"); | |
19880 | break; | |
19881 | default: | |
19882 | printf (_("<unknown: %x>"), bit); | |
19883 | break; | |
19884 | } | |
19885 | if (bitmask) | |
19886 | printf (", "); | |
19887 | } | |
19888 | } | |
19889 | ||
19890 | static const char * | |
19891 | get_amdgpu_elf_note_type (unsigned int e_type) | |
19892 | { | |
19893 | switch (e_type) | |
19894 | { | |
19895 | case NT_AMDGPU_METADATA: | |
19896 | return _("NT_AMDGPU_METADATA (code object metadata)"); | |
19897 | default: | |
19898 | { | |
19899 | static char buf[64]; | |
19900 | snprintf (buf, sizeof (buf), _("Unknown note type: (0x%08x)"), e_type); | |
19901 | return buf; | |
19902 | } | |
19903 | } | |
19904 | } | |
19905 | ||
19906 | static void | |
19907 | decode_x86_isa (unsigned int bitmask) | |
19908 | { | |
19909 | while (bitmask) | |
19910 | { | |
19911 | unsigned int bit = bitmask & (- bitmask); | |
19912 | ||
19913 | bitmask &= ~ bit; | |
19914 | switch (bit) | |
19915 | { | |
19916 | case GNU_PROPERTY_X86_ISA_1_BASELINE: | |
19917 | printf ("x86-64-baseline"); | |
19918 | break; | |
19919 | case GNU_PROPERTY_X86_ISA_1_V2: | |
19920 | printf ("x86-64-v2"); | |
19921 | break; | |
19922 | case GNU_PROPERTY_X86_ISA_1_V3: | |
19923 | printf ("x86-64-v3"); | |
19924 | break; | |
19925 | case GNU_PROPERTY_X86_ISA_1_V4: | |
19926 | printf ("x86-64-v4"); | |
19927 | break; | |
19928 | default: | |
19929 | printf (_("<unknown: %x>"), bit); | |
19930 | break; | |
19931 | } | |
19932 | if (bitmask) | |
19933 | printf (", "); | |
19934 | } | |
19935 | } | |
19936 | ||
19937 | static void | |
19938 | decode_x86_feature_1 (unsigned int bitmask) | |
19939 | { | |
19940 | if (!bitmask) | |
19941 | { | |
19942 | printf (_("<None>")); | |
19943 | return; | |
19944 | } | |
19945 | ||
19946 | while (bitmask) | |
19947 | { | |
19948 | unsigned int bit = bitmask & (- bitmask); | |
19949 | ||
19950 | bitmask &= ~ bit; | |
19951 | switch (bit) | |
19952 | { | |
19953 | case GNU_PROPERTY_X86_FEATURE_1_IBT: | |
19954 | printf ("IBT"); | |
19955 | break; | |
19956 | case GNU_PROPERTY_X86_FEATURE_1_SHSTK: | |
19957 | printf ("SHSTK"); | |
19958 | break; | |
19959 | case GNU_PROPERTY_X86_FEATURE_1_LAM_U48: | |
19960 | printf ("LAM_U48"); | |
19961 | break; | |
19962 | case GNU_PROPERTY_X86_FEATURE_1_LAM_U57: | |
19963 | printf ("LAM_U57"); | |
19964 | break; | |
19965 | default: | |
19966 | printf (_("<unknown: %x>"), bit); | |
19967 | break; | |
19968 | } | |
19969 | if (bitmask) | |
19970 | printf (", "); | |
19971 | } | |
19972 | } | |
19973 | ||
19974 | static void | |
19975 | decode_x86_feature_2 (unsigned int bitmask) | |
19976 | { | |
19977 | if (!bitmask) | |
19978 | { | |
19979 | printf (_("<None>")); | |
19980 | return; | |
19981 | } | |
19982 | ||
19983 | while (bitmask) | |
19984 | { | |
19985 | unsigned int bit = bitmask & (- bitmask); | |
19986 | ||
19987 | bitmask &= ~ bit; | |
19988 | switch (bit) | |
19989 | { | |
19990 | case GNU_PROPERTY_X86_FEATURE_2_X86: | |
19991 | printf ("x86"); | |
19992 | break; | |
19993 | case GNU_PROPERTY_X86_FEATURE_2_X87: | |
19994 | printf ("x87"); | |
19995 | break; | |
19996 | case GNU_PROPERTY_X86_FEATURE_2_MMX: | |
19997 | printf ("MMX"); | |
19998 | break; | |
19999 | case GNU_PROPERTY_X86_FEATURE_2_XMM: | |
20000 | printf ("XMM"); | |
20001 | break; | |
20002 | case GNU_PROPERTY_X86_FEATURE_2_YMM: | |
20003 | printf ("YMM"); | |
20004 | break; | |
20005 | case GNU_PROPERTY_X86_FEATURE_2_ZMM: | |
20006 | printf ("ZMM"); | |
20007 | break; | |
20008 | case GNU_PROPERTY_X86_FEATURE_2_TMM: | |
20009 | printf ("TMM"); | |
20010 | break; | |
20011 | case GNU_PROPERTY_X86_FEATURE_2_MASK: | |
20012 | printf ("MASK"); | |
20013 | break; | |
20014 | case GNU_PROPERTY_X86_FEATURE_2_FXSR: | |
20015 | printf ("FXSR"); | |
20016 | break; | |
20017 | case GNU_PROPERTY_X86_FEATURE_2_XSAVE: | |
20018 | printf ("XSAVE"); | |
20019 | break; | |
20020 | case GNU_PROPERTY_X86_FEATURE_2_XSAVEOPT: | |
20021 | printf ("XSAVEOPT"); | |
20022 | break; | |
20023 | case GNU_PROPERTY_X86_FEATURE_2_XSAVEC: | |
20024 | printf ("XSAVEC"); | |
20025 | break; | |
20026 | default: | |
20027 | printf (_("<unknown: %x>"), bit); | |
20028 | break; | |
20029 | } | |
20030 | if (bitmask) | |
20031 | printf (", "); | |
20032 | } | |
20033 | } | |
20034 | ||
20035 | static void | |
20036 | decode_aarch64_feature_1_and (unsigned int bitmask) | |
20037 | { | |
20038 | while (bitmask) | |
20039 | { | |
20040 | unsigned int bit = bitmask & (- bitmask); | |
20041 | ||
20042 | bitmask &= ~ bit; | |
20043 | switch (bit) | |
20044 | { | |
20045 | case GNU_PROPERTY_AARCH64_FEATURE_1_BTI: | |
20046 | printf ("BTI"); | |
20047 | break; | |
20048 | ||
20049 | case GNU_PROPERTY_AARCH64_FEATURE_1_PAC: | |
20050 | printf ("PAC"); | |
20051 | break; | |
20052 | ||
20053 | default: | |
20054 | printf (_("<unknown: %x>"), bit); | |
20055 | break; | |
20056 | } | |
20057 | if (bitmask) | |
20058 | printf (", "); | |
20059 | } | |
20060 | } | |
20061 | ||
20062 | static void | |
20063 | decode_1_needed (unsigned int bitmask) | |
20064 | { | |
20065 | while (bitmask) | |
20066 | { | |
20067 | unsigned int bit = bitmask & (- bitmask); | |
20068 | ||
20069 | bitmask &= ~ bit; | |
20070 | switch (bit) | |
20071 | { | |
20072 | case GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS: | |
20073 | printf ("indirect external access"); | |
20074 | break; | |
20075 | default: | |
20076 | printf (_("<unknown: %x>"), bit); | |
20077 | break; | |
20078 | } | |
20079 | if (bitmask) | |
20080 | printf (", "); | |
20081 | } | |
20082 | } | |
20083 | ||
20084 | static void | |
20085 | print_gnu_property_note (Filedata * filedata, Elf_Internal_Note * pnote) | |
20086 | { | |
20087 | unsigned char * ptr = (unsigned char *) pnote->descdata; | |
20088 | unsigned char * ptr_end = ptr + pnote->descsz; | |
20089 | unsigned int size = is_32bit_elf ? 4 : 8; | |
20090 | ||
20091 | printf (_(" Properties: ")); | |
20092 | ||
20093 | if (pnote->descsz < 8 || (pnote->descsz % size) != 0) | |
20094 | { | |
20095 | printf (_("<corrupt GNU_PROPERTY_TYPE, size = %#lx>\n"), pnote->descsz); | |
20096 | return; | |
20097 | } | |
20098 | ||
20099 | while (ptr < ptr_end) | |
20100 | { | |
20101 | unsigned int j; | |
20102 | unsigned int type; | |
20103 | unsigned int datasz; | |
20104 | ||
20105 | if ((size_t) (ptr_end - ptr) < 8) | |
20106 | { | |
20107 | printf (_("<corrupt descsz: %#lx>\n"), pnote->descsz); | |
20108 | break; | |
20109 | } | |
20110 | ||
20111 | type = byte_get (ptr, 4); | |
20112 | datasz = byte_get (ptr + 4, 4); | |
20113 | ||
20114 | ptr += 8; | |
20115 | ||
20116 | if (datasz > (size_t) (ptr_end - ptr)) | |
20117 | { | |
20118 | printf (_("<corrupt type (%#x) datasz: %#x>\n"), | |
20119 | type, datasz); | |
20120 | break; | |
20121 | } | |
20122 | ||
20123 | if (type >= GNU_PROPERTY_LOPROC && type <= GNU_PROPERTY_HIPROC) | |
20124 | { | |
20125 | if (filedata->file_header.e_machine == EM_X86_64 | |
20126 | || filedata->file_header.e_machine == EM_IAMCU | |
20127 | || filedata->file_header.e_machine == EM_386) | |
20128 | { | |
20129 | unsigned int bitmask; | |
20130 | ||
20131 | if (datasz == 4) | |
20132 | bitmask = byte_get (ptr, 4); | |
20133 | else | |
20134 | bitmask = 0; | |
20135 | ||
20136 | switch (type) | |
20137 | { | |
20138 | case GNU_PROPERTY_X86_ISA_1_USED: | |
20139 | if (datasz != 4) | |
20140 | printf (_("x86 ISA used: <corrupt length: %#x> "), | |
20141 | datasz); | |
20142 | else | |
20143 | { | |
20144 | printf ("x86 ISA used: "); | |
20145 | decode_x86_isa (bitmask); | |
20146 | } | |
20147 | goto next; | |
20148 | ||
20149 | case GNU_PROPERTY_X86_ISA_1_NEEDED: | |
20150 | if (datasz != 4) | |
20151 | printf (_("x86 ISA needed: <corrupt length: %#x> "), | |
20152 | datasz); | |
20153 | else | |
20154 | { | |
20155 | printf ("x86 ISA needed: "); | |
20156 | decode_x86_isa (bitmask); | |
20157 | } | |
20158 | goto next; | |
20159 | ||
20160 | case GNU_PROPERTY_X86_FEATURE_1_AND: | |
20161 | if (datasz != 4) | |
20162 | printf (_("x86 feature: <corrupt length: %#x> "), | |
20163 | datasz); | |
20164 | else | |
20165 | { | |
20166 | printf ("x86 feature: "); | |
20167 | decode_x86_feature_1 (bitmask); | |
20168 | } | |
20169 | goto next; | |
20170 | ||
20171 | case GNU_PROPERTY_X86_FEATURE_2_USED: | |
20172 | if (datasz != 4) | |
20173 | printf (_("x86 feature used: <corrupt length: %#x> "), | |
20174 | datasz); | |
20175 | else | |
20176 | { | |
20177 | printf ("x86 feature used: "); | |
20178 | decode_x86_feature_2 (bitmask); | |
20179 | } | |
20180 | goto next; | |
20181 | ||
20182 | case GNU_PROPERTY_X86_FEATURE_2_NEEDED: | |
20183 | if (datasz != 4) | |
20184 | printf (_("x86 feature needed: <corrupt length: %#x> "), datasz); | |
20185 | else | |
20186 | { | |
20187 | printf ("x86 feature needed: "); | |
20188 | decode_x86_feature_2 (bitmask); | |
20189 | } | |
20190 | goto next; | |
20191 | ||
20192 | case GNU_PROPERTY_X86_COMPAT_ISA_1_USED: | |
20193 | if (datasz != 4) | |
20194 | printf (_("x86 ISA used: <corrupt length: %#x> "), | |
20195 | datasz); | |
20196 | else | |
20197 | { | |
20198 | printf ("x86 ISA used: "); | |
20199 | decode_x86_compat_isa (bitmask); | |
20200 | } | |
20201 | goto next; | |
20202 | ||
20203 | case GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED: | |
20204 | if (datasz != 4) | |
20205 | printf (_("x86 ISA needed: <corrupt length: %#x> "), | |
20206 | datasz); | |
20207 | else | |
20208 | { | |
20209 | printf ("x86 ISA needed: "); | |
20210 | decode_x86_compat_isa (bitmask); | |
20211 | } | |
20212 | goto next; | |
20213 | ||
20214 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_USED: | |
20215 | if (datasz != 4) | |
20216 | printf (_("x86 ISA used: <corrupt length: %#x> "), | |
20217 | datasz); | |
20218 | else | |
20219 | { | |
20220 | printf ("x86 ISA used: "); | |
20221 | decode_x86_compat_2_isa (bitmask); | |
20222 | } | |
20223 | goto next; | |
20224 | ||
20225 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_NEEDED: | |
20226 | if (datasz != 4) | |
20227 | printf (_("x86 ISA needed: <corrupt length: %#x> "), | |
20228 | datasz); | |
20229 | else | |
20230 | { | |
20231 | printf ("x86 ISA needed: "); | |
20232 | decode_x86_compat_2_isa (bitmask); | |
20233 | } | |
20234 | goto next; | |
20235 | ||
20236 | default: | |
20237 | break; | |
20238 | } | |
20239 | } | |
20240 | else if (filedata->file_header.e_machine == EM_AARCH64) | |
20241 | { | |
20242 | if (type == GNU_PROPERTY_AARCH64_FEATURE_1_AND) | |
20243 | { | |
20244 | printf ("AArch64 feature: "); | |
20245 | if (datasz != 4) | |
20246 | printf (_("<corrupt length: %#x> "), datasz); | |
20247 | else | |
20248 | decode_aarch64_feature_1_and (byte_get (ptr, 4)); | |
20249 | goto next; | |
20250 | } | |
20251 | } | |
20252 | } | |
20253 | else | |
20254 | { | |
20255 | switch (type) | |
20256 | { | |
20257 | case GNU_PROPERTY_STACK_SIZE: | |
20258 | printf (_("stack size: ")); | |
20259 | if (datasz != size) | |
20260 | printf (_("<corrupt length: %#x> "), datasz); | |
20261 | else | |
20262 | printf ("%#" PRIx64, byte_get (ptr, size)); | |
20263 | goto next; | |
20264 | ||
20265 | case GNU_PROPERTY_NO_COPY_ON_PROTECTED: | |
20266 | printf ("no copy on protected "); | |
20267 | if (datasz) | |
20268 | printf (_("<corrupt length: %#x> "), datasz); | |
20269 | goto next; | |
20270 | ||
20271 | default: | |
20272 | if ((type >= GNU_PROPERTY_UINT32_AND_LO | |
20273 | && type <= GNU_PROPERTY_UINT32_AND_HI) | |
20274 | || (type >= GNU_PROPERTY_UINT32_OR_LO | |
20275 | && type <= GNU_PROPERTY_UINT32_OR_HI)) | |
20276 | { | |
20277 | switch (type) | |
20278 | { | |
20279 | case GNU_PROPERTY_1_NEEDED: | |
20280 | if (datasz != 4) | |
20281 | printf (_("1_needed: <corrupt length: %#x> "), | |
20282 | datasz); | |
20283 | else | |
20284 | { | |
20285 | unsigned int bitmask = byte_get (ptr, 4); | |
20286 | printf ("1_needed: "); | |
20287 | decode_1_needed (bitmask); | |
20288 | } | |
20289 | goto next; | |
20290 | ||
20291 | default: | |
20292 | break; | |
20293 | } | |
20294 | if (type <= GNU_PROPERTY_UINT32_AND_HI) | |
20295 | printf (_("UINT32_AND (%#x): "), type); | |
20296 | else | |
20297 | printf (_("UINT32_OR (%#x): "), type); | |
20298 | if (datasz != 4) | |
20299 | printf (_("<corrupt length: %#x> "), datasz); | |
20300 | else | |
20301 | printf ("%#x", (unsigned int) byte_get (ptr, 4)); | |
20302 | goto next; | |
20303 | } | |
20304 | break; | |
20305 | } | |
20306 | } | |
20307 | ||
20308 | if (type < GNU_PROPERTY_LOPROC) | |
20309 | printf (_("<unknown type %#x data: "), type); | |
20310 | else if (type < GNU_PROPERTY_LOUSER) | |
20311 | printf (_("<processor-specific type %#x data: "), type); | |
20312 | else | |
20313 | printf (_("<application-specific type %#x data: "), type); | |
20314 | for (j = 0; j < datasz; ++j) | |
20315 | printf ("%02x ", ptr[j] & 0xff); | |
20316 | printf (">"); | |
20317 | ||
20318 | next: | |
20319 | ptr += ((datasz + (size - 1)) & ~ (size - 1)); | |
20320 | if (ptr == ptr_end) | |
20321 | break; | |
20322 | ||
20323 | if (do_wide) | |
20324 | printf (", "); | |
20325 | else | |
20326 | printf ("\n\t"); | |
20327 | } | |
20328 | ||
20329 | printf ("\n"); | |
20330 | } | |
20331 | ||
20332 | static bool | |
20333 | print_gnu_note (Filedata * filedata, Elf_Internal_Note *pnote) | |
20334 | { | |
20335 | /* NB/ Keep this switch statement in sync with get_gnu_elf_note_type (). */ | |
20336 | switch (pnote->type) | |
20337 | { | |
20338 | case NT_GNU_BUILD_ID: | |
20339 | { | |
20340 | size_t i; | |
20341 | ||
20342 | printf (_(" Build ID: ")); | |
20343 | for (i = 0; i < pnote->descsz; ++i) | |
20344 | printf ("%02x", pnote->descdata[i] & 0xff); | |
20345 | printf ("\n"); | |
20346 | } | |
20347 | break; | |
20348 | ||
20349 | case NT_GNU_ABI_TAG: | |
20350 | { | |
20351 | unsigned int os, major, minor, subminor; | |
20352 | const char *osname; | |
20353 | ||
20354 | /* PR 17531: file: 030-599401-0.004. */ | |
20355 | if (pnote->descsz < 16) | |
20356 | { | |
20357 | printf (_(" <corrupt GNU_ABI_TAG>\n")); | |
20358 | break; | |
20359 | } | |
20360 | ||
20361 | os = byte_get ((unsigned char *) pnote->descdata, 4); | |
20362 | major = byte_get ((unsigned char *) pnote->descdata + 4, 4); | |
20363 | minor = byte_get ((unsigned char *) pnote->descdata + 8, 4); | |
20364 | subminor = byte_get ((unsigned char *) pnote->descdata + 12, 4); | |
20365 | ||
20366 | switch (os) | |
20367 | { | |
20368 | case GNU_ABI_TAG_LINUX: | |
20369 | osname = "Linux"; | |
20370 | break; | |
20371 | case GNU_ABI_TAG_HURD: | |
20372 | osname = "Hurd"; | |
20373 | break; | |
20374 | case GNU_ABI_TAG_SOLARIS: | |
20375 | osname = "Solaris"; | |
20376 | break; | |
20377 | case GNU_ABI_TAG_FREEBSD: | |
20378 | osname = "FreeBSD"; | |
20379 | break; | |
20380 | case GNU_ABI_TAG_NETBSD: | |
20381 | osname = "NetBSD"; | |
20382 | break; | |
20383 | case GNU_ABI_TAG_SYLLABLE: | |
20384 | osname = "Syllable"; | |
20385 | break; | |
20386 | case GNU_ABI_TAG_NACL: | |
20387 | osname = "NaCl"; | |
20388 | break; | |
20389 | default: | |
20390 | osname = "Unknown"; | |
20391 | break; | |
20392 | } | |
20393 | ||
20394 | printf (_(" OS: %s, ABI: %d.%d.%d\n"), osname, | |
20395 | major, minor, subminor); | |
20396 | } | |
20397 | break; | |
20398 | ||
20399 | case NT_GNU_GOLD_VERSION: | |
20400 | { | |
20401 | size_t i; | |
20402 | ||
20403 | printf (_(" Version: ")); | |
20404 | for (i = 0; i < pnote->descsz && pnote->descdata[i] != '\0'; ++i) | |
20405 | printf ("%c", pnote->descdata[i]); | |
20406 | printf ("\n"); | |
20407 | } | |
20408 | break; | |
20409 | ||
20410 | case NT_GNU_HWCAP: | |
20411 | { | |
20412 | unsigned int num_entries, mask; | |
20413 | ||
20414 | /* Hardware capabilities information. Word 0 is the number of entries. | |
20415 | Word 1 is a bitmask of enabled entries. The rest of the descriptor | |
20416 | is a series of entries, where each entry is a single byte followed | |
20417 | by a nul terminated string. The byte gives the bit number to test | |
20418 | if enabled in the bitmask. */ | |
20419 | printf (_(" Hardware Capabilities: ")); | |
20420 | if (pnote->descsz < 8) | |
20421 | { | |
20422 | error (_("<corrupt GNU_HWCAP>\n")); | |
20423 | return false; | |
20424 | } | |
20425 | num_entries = byte_get ((unsigned char *) pnote->descdata, 4); | |
20426 | mask = byte_get ((unsigned char *) pnote->descdata + 4, 4); | |
20427 | printf (_("num entries: %d, enabled mask: %x\n"), num_entries, mask); | |
20428 | /* FIXME: Add code to display the entries... */ | |
20429 | } | |
20430 | break; | |
20431 | ||
20432 | case NT_GNU_PROPERTY_TYPE_0: | |
20433 | print_gnu_property_note (filedata, pnote); | |
20434 | break; | |
20435 | ||
20436 | default: | |
20437 | /* Handle unrecognised types. An error message should have already been | |
20438 | created by get_gnu_elf_note_type(), so all that we need to do is to | |
20439 | display the data. */ | |
20440 | { | |
20441 | size_t i; | |
20442 | ||
20443 | printf (_(" Description data: ")); | |
20444 | for (i = 0; i < pnote->descsz; ++i) | |
20445 | printf ("%02x ", pnote->descdata[i] & 0xff); | |
20446 | printf ("\n"); | |
20447 | } | |
20448 | break; | |
20449 | } | |
20450 | ||
20451 | return true; | |
20452 | } | |
20453 | ||
20454 | static const char * | |
20455 | get_v850_elf_note_type (enum v850_notes n_type) | |
20456 | { | |
20457 | static char buff[64]; | |
20458 | ||
20459 | switch (n_type) | |
20460 | { | |
20461 | case V850_NOTE_ALIGNMENT: return _("Alignment of 8-byte objects"); | |
20462 | case V850_NOTE_DATA_SIZE: return _("Sizeof double and long double"); | |
20463 | case V850_NOTE_FPU_INFO: return _("Type of FPU support needed"); | |
20464 | case V850_NOTE_SIMD_INFO: return _("Use of SIMD instructions"); | |
20465 | case V850_NOTE_CACHE_INFO: return _("Use of cache"); | |
20466 | case V850_NOTE_MMU_INFO: return _("Use of MMU"); | |
20467 | default: | |
20468 | snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), n_type); | |
20469 | return buff; | |
20470 | } | |
20471 | } | |
20472 | ||
20473 | static bool | |
20474 | print_v850_note (Elf_Internal_Note * pnote) | |
20475 | { | |
20476 | unsigned int val; | |
20477 | ||
20478 | if (pnote->descsz != 4) | |
20479 | return false; | |
20480 | ||
20481 | val = byte_get ((unsigned char *) pnote->descdata, pnote->descsz); | |
20482 | ||
20483 | if (val == 0) | |
20484 | { | |
20485 | printf (_("not set\n")); | |
20486 | return true; | |
20487 | } | |
20488 | ||
20489 | switch (pnote->type) | |
20490 | { | |
20491 | case V850_NOTE_ALIGNMENT: | |
20492 | switch (val) | |
20493 | { | |
20494 | case EF_RH850_DATA_ALIGN4: printf (_("4-byte\n")); return true; | |
20495 | case EF_RH850_DATA_ALIGN8: printf (_("8-byte\n")); return true; | |
20496 | } | |
20497 | break; | |
20498 | ||
20499 | case V850_NOTE_DATA_SIZE: | |
20500 | switch (val) | |
20501 | { | |
20502 | case EF_RH850_DOUBLE32: printf (_("4-bytes\n")); return true; | |
20503 | case EF_RH850_DOUBLE64: printf (_("8-bytes\n")); return true; | |
20504 | } | |
20505 | break; | |
20506 | ||
20507 | case V850_NOTE_FPU_INFO: | |
20508 | switch (val) | |
20509 | { | |
20510 | case EF_RH850_FPU20: printf (_("FPU-2.0\n")); return true; | |
20511 | case EF_RH850_FPU30: printf (_("FPU-3.0\n")); return true; | |
20512 | } | |
20513 | break; | |
20514 | ||
20515 | case V850_NOTE_MMU_INFO: | |
20516 | case V850_NOTE_CACHE_INFO: | |
20517 | case V850_NOTE_SIMD_INFO: | |
20518 | if (val == EF_RH850_SIMD) | |
20519 | { | |
20520 | printf (_("yes\n")); | |
20521 | return true; | |
20522 | } | |
20523 | break; | |
20524 | ||
20525 | default: | |
20526 | /* An 'unknown note type' message will already have been displayed. */ | |
20527 | break; | |
20528 | } | |
20529 | ||
20530 | printf (_("unknown value: %x\n"), val); | |
20531 | return false; | |
20532 | } | |
20533 | ||
20534 | static bool | |
20535 | process_netbsd_elf_note (Elf_Internal_Note * pnote) | |
20536 | { | |
20537 | unsigned int version; | |
20538 | ||
20539 | switch (pnote->type) | |
20540 | { | |
20541 | case NT_NETBSD_IDENT: | |
20542 | if (pnote->descsz < 1) | |
20543 | break; | |
20544 | version = byte_get ((unsigned char *) pnote->descdata, sizeof (version)); | |
20545 | if ((version / 10000) % 100) | |
20546 | printf (" NetBSD\t\t0x%08lx\tIDENT %u (%u.%u%s%c)\n", pnote->descsz, | |
20547 | version, version / 100000000, (version / 1000000) % 100, | |
20548 | (version / 10000) % 100 > 26 ? "Z" : "", | |
20549 | 'A' + (version / 10000) % 26); | |
20550 | else | |
20551 | printf (" NetBSD\t\t0x%08lx\tIDENT %u (%u.%u.%u)\n", pnote->descsz, | |
20552 | version, version / 100000000, (version / 1000000) % 100, | |
20553 | (version / 100) % 100); | |
20554 | return true; | |
20555 | ||
20556 | case NT_NETBSD_MARCH: | |
20557 | printf (" NetBSD\t\t0x%08lx\tMARCH <%s>\n", pnote->descsz, | |
20558 | pnote->descdata); | |
20559 | return true; | |
20560 | ||
20561 | case NT_NETBSD_PAX: | |
20562 | if (pnote->descsz < 1) | |
20563 | break; | |
20564 | version = byte_get ((unsigned char *) pnote->descdata, sizeof (version)); | |
20565 | printf (" NetBSD\t\t0x%08lx\tPaX <%s%s%s%s%s%s>\n", pnote->descsz, | |
20566 | ((version & NT_NETBSD_PAX_MPROTECT) ? "+mprotect" : ""), | |
20567 | ((version & NT_NETBSD_PAX_NOMPROTECT) ? "-mprotect" : ""), | |
20568 | ((version & NT_NETBSD_PAX_GUARD) ? "+guard" : ""), | |
20569 | ((version & NT_NETBSD_PAX_NOGUARD) ? "-guard" : ""), | |
20570 | ((version & NT_NETBSD_PAX_ASLR) ? "+ASLR" : ""), | |
20571 | ((version & NT_NETBSD_PAX_NOASLR) ? "-ASLR" : "")); | |
20572 | return true; | |
20573 | } | |
20574 | ||
20575 | printf (" NetBSD\t0x%08lx\tUnknown note type: (0x%08lx)\n", | |
20576 | pnote->descsz, pnote->type); | |
20577 | return false; | |
20578 | } | |
20579 | ||
20580 | static const char * | |
20581 | get_freebsd_elfcore_note_type (Filedata * filedata, unsigned e_type) | |
20582 | { | |
20583 | switch (e_type) | |
20584 | { | |
20585 | case NT_FREEBSD_THRMISC: | |
20586 | return _("NT_THRMISC (thrmisc structure)"); | |
20587 | case NT_FREEBSD_PROCSTAT_PROC: | |
20588 | return _("NT_PROCSTAT_PROC (proc data)"); | |
20589 | case NT_FREEBSD_PROCSTAT_FILES: | |
20590 | return _("NT_PROCSTAT_FILES (files data)"); | |
20591 | case NT_FREEBSD_PROCSTAT_VMMAP: | |
20592 | return _("NT_PROCSTAT_VMMAP (vmmap data)"); | |
20593 | case NT_FREEBSD_PROCSTAT_GROUPS: | |
20594 | return _("NT_PROCSTAT_GROUPS (groups data)"); | |
20595 | case NT_FREEBSD_PROCSTAT_UMASK: | |
20596 | return _("NT_PROCSTAT_UMASK (umask data)"); | |
20597 | case NT_FREEBSD_PROCSTAT_RLIMIT: | |
20598 | return _("NT_PROCSTAT_RLIMIT (rlimit data)"); | |
20599 | case NT_FREEBSD_PROCSTAT_OSREL: | |
20600 | return _("NT_PROCSTAT_OSREL (osreldate data)"); | |
20601 | case NT_FREEBSD_PROCSTAT_PSSTRINGS: | |
20602 | return _("NT_PROCSTAT_PSSTRINGS (ps_strings data)"); | |
20603 | case NT_FREEBSD_PROCSTAT_AUXV: | |
20604 | return _("NT_PROCSTAT_AUXV (auxv data)"); | |
20605 | case NT_FREEBSD_PTLWPINFO: | |
20606 | return _("NT_PTLWPINFO (ptrace_lwpinfo structure)"); | |
20607 | case NT_FREEBSD_X86_SEGBASES: | |
20608 | return _("NT_X86_SEGBASES (x86 segment base registers)"); | |
20609 | } | |
20610 | return get_note_type (filedata, e_type); | |
20611 | } | |
20612 | ||
20613 | static const char * | |
20614 | get_netbsd_elfcore_note_type (Filedata * filedata, unsigned e_type) | |
20615 | { | |
20616 | static char buff[64]; | |
20617 | ||
20618 | switch (e_type) | |
20619 | { | |
20620 | case NT_NETBSDCORE_PROCINFO: | |
20621 | /* NetBSD core "procinfo" structure. */ | |
20622 | return _("NetBSD procinfo structure"); | |
20623 | ||
20624 | case NT_NETBSDCORE_AUXV: | |
20625 | return _("NetBSD ELF auxiliary vector data"); | |
20626 | ||
20627 | case NT_NETBSDCORE_LWPSTATUS: | |
20628 | return _("PT_LWPSTATUS (ptrace_lwpstatus structure)"); | |
20629 | ||
20630 | default: | |
20631 | /* As of Jan 2020 there are no other machine-independent notes | |
20632 | defined for NetBSD core files. If the note type is less | |
20633 | than the start of the machine-dependent note types, we don't | |
20634 | understand it. */ | |
20635 | ||
20636 | if (e_type < NT_NETBSDCORE_FIRSTMACH) | |
20637 | { | |
20638 | snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type); | |
20639 | return buff; | |
20640 | } | |
20641 | break; | |
20642 | } | |
20643 | ||
20644 | switch (filedata->file_header.e_machine) | |
20645 | { | |
20646 | /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0 | |
20647 | and PT_GETFPREGS == mach+2. */ | |
20648 | ||
20649 | case EM_OLD_ALPHA: | |
20650 | case EM_ALPHA: | |
20651 | case EM_SPARC: | |
20652 | case EM_SPARC32PLUS: | |
20653 | case EM_SPARCV9: | |
20654 | switch (e_type) | |
20655 | { | |
20656 | case NT_NETBSDCORE_FIRSTMACH + 0: | |
20657 | return _("PT_GETREGS (reg structure)"); | |
20658 | case NT_NETBSDCORE_FIRSTMACH + 2: | |
20659 | return _("PT_GETFPREGS (fpreg structure)"); | |
20660 | default: | |
20661 | break; | |
20662 | } | |
20663 | break; | |
20664 | ||
20665 | /* On SuperH, PT_GETREGS == mach+3 and PT_GETFPREGS == mach+5. | |
20666 | There's also old PT___GETREGS40 == mach + 1 for old reg | |
20667 | structure which lacks GBR. */ | |
20668 | case EM_SH: | |
20669 | switch (e_type) | |
20670 | { | |
20671 | case NT_NETBSDCORE_FIRSTMACH + 1: | |
20672 | return _("PT___GETREGS40 (old reg structure)"); | |
20673 | case NT_NETBSDCORE_FIRSTMACH + 3: | |
20674 | return _("PT_GETREGS (reg structure)"); | |
20675 | case NT_NETBSDCORE_FIRSTMACH + 5: | |
20676 | return _("PT_GETFPREGS (fpreg structure)"); | |
20677 | default: | |
20678 | break; | |
20679 | } | |
20680 | break; | |
20681 | ||
20682 | /* On all other arch's, PT_GETREGS == mach+1 and | |
20683 | PT_GETFPREGS == mach+3. */ | |
20684 | default: | |
20685 | switch (e_type) | |
20686 | { | |
20687 | case NT_NETBSDCORE_FIRSTMACH + 1: | |
20688 | return _("PT_GETREGS (reg structure)"); | |
20689 | case NT_NETBSDCORE_FIRSTMACH + 3: | |
20690 | return _("PT_GETFPREGS (fpreg structure)"); | |
20691 | default: | |
20692 | break; | |
20693 | } | |
20694 | } | |
20695 | ||
20696 | snprintf (buff, sizeof (buff), "PT_FIRSTMACH+%d", | |
20697 | e_type - NT_NETBSDCORE_FIRSTMACH); | |
20698 | return buff; | |
20699 | } | |
20700 | ||
20701 | static const char * | |
20702 | get_openbsd_elfcore_note_type (Filedata * filedata, unsigned e_type) | |
20703 | { | |
20704 | switch (e_type) | |
20705 | { | |
20706 | case NT_OPENBSD_PROCINFO: | |
20707 | return _("OpenBSD procinfo structure"); | |
20708 | case NT_OPENBSD_AUXV: | |
20709 | return _("OpenBSD ELF auxiliary vector data"); | |
20710 | case NT_OPENBSD_REGS: | |
20711 | return _("OpenBSD regular registers"); | |
20712 | case NT_OPENBSD_FPREGS: | |
20713 | return _("OpenBSD floating point registers"); | |
20714 | case NT_OPENBSD_WCOOKIE: | |
20715 | return _("OpenBSD window cookie"); | |
20716 | } | |
20717 | ||
20718 | return get_note_type (filedata, e_type); | |
20719 | } | |
20720 | ||
20721 | static const char * | |
20722 | get_stapsdt_note_type (unsigned e_type) | |
20723 | { | |
20724 | static char buff[64]; | |
20725 | ||
20726 | switch (e_type) | |
20727 | { | |
20728 | case NT_STAPSDT: | |
20729 | return _("NT_STAPSDT (SystemTap probe descriptors)"); | |
20730 | ||
20731 | default: | |
20732 | break; | |
20733 | } | |
20734 | ||
20735 | snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type); | |
20736 | return buff; | |
20737 | } | |
20738 | ||
20739 | static bool | |
20740 | print_stapsdt_note (Elf_Internal_Note *pnote) | |
20741 | { | |
20742 | size_t len, maxlen; | |
20743 | size_t addr_size = is_32bit_elf ? 4 : 8; | |
20744 | char *data = pnote->descdata; | |
20745 | char *data_end = pnote->descdata + pnote->descsz; | |
20746 | uint64_t pc, base_addr, semaphore; | |
20747 | char *provider, *probe, *arg_fmt; | |
20748 | ||
20749 | if (pnote->descsz < (addr_size * 3)) | |
20750 | goto stapdt_note_too_small; | |
20751 | ||
20752 | pc = byte_get ((unsigned char *) data, addr_size); | |
20753 | data += addr_size; | |
20754 | ||
20755 | base_addr = byte_get ((unsigned char *) data, addr_size); | |
20756 | data += addr_size; | |
20757 | ||
20758 | semaphore = byte_get ((unsigned char *) data, addr_size); | |
20759 | data += addr_size; | |
20760 | ||
20761 | if (data >= data_end) | |
20762 | goto stapdt_note_too_small; | |
20763 | maxlen = data_end - data; | |
20764 | len = strnlen (data, maxlen); | |
20765 | if (len < maxlen) | |
20766 | { | |
20767 | provider = data; | |
20768 | data += len + 1; | |
20769 | } | |
20770 | else | |
20771 | goto stapdt_note_too_small; | |
20772 | ||
20773 | if (data >= data_end) | |
20774 | goto stapdt_note_too_small; | |
20775 | maxlen = data_end - data; | |
20776 | len = strnlen (data, maxlen); | |
20777 | if (len < maxlen) | |
20778 | { | |
20779 | probe = data; | |
20780 | data += len + 1; | |
20781 | } | |
20782 | else | |
20783 | goto stapdt_note_too_small; | |
20784 | ||
20785 | if (data >= data_end) | |
20786 | goto stapdt_note_too_small; | |
20787 | maxlen = data_end - data; | |
20788 | len = strnlen (data, maxlen); | |
20789 | if (len < maxlen) | |
20790 | { | |
20791 | arg_fmt = data; | |
20792 | data += len + 1; | |
20793 | } | |
20794 | else | |
20795 | goto stapdt_note_too_small; | |
20796 | ||
20797 | printf (_(" Provider: %s\n"), provider); | |
20798 | printf (_(" Name: %s\n"), probe); | |
20799 | printf (_(" Location: ")); | |
20800 | print_vma (pc, FULL_HEX); | |
20801 | printf (_(", Base: ")); | |
20802 | print_vma (base_addr, FULL_HEX); | |
20803 | printf (_(", Semaphore: ")); | |
20804 | print_vma (semaphore, FULL_HEX); | |
20805 | printf ("\n"); | |
20806 | printf (_(" Arguments: %s\n"), arg_fmt); | |
20807 | ||
20808 | return data == data_end; | |
20809 | ||
20810 | stapdt_note_too_small: | |
20811 | printf (_(" <corrupt - note is too small>\n")); | |
20812 | error (_("corrupt stapdt note - the data size is too small\n")); | |
20813 | return false; | |
20814 | } | |
20815 | ||
20816 | static bool | |
20817 | print_fdo_note (Elf_Internal_Note * pnote) | |
20818 | { | |
20819 | if (pnote->descsz > 0 && pnote->type == FDO_PACKAGING_METADATA) | |
20820 | { | |
20821 | printf (_(" Packaging Metadata: %.*s\n"), (int) pnote->descsz, pnote->descdata); | |
20822 | return true; | |
20823 | } | |
20824 | return false; | |
20825 | } | |
20826 | ||
20827 | static const char * | |
20828 | get_ia64_vms_note_type (unsigned e_type) | |
20829 | { | |
20830 | static char buff[64]; | |
20831 | ||
20832 | switch (e_type) | |
20833 | { | |
20834 | case NT_VMS_MHD: | |
20835 | return _("NT_VMS_MHD (module header)"); | |
20836 | case NT_VMS_LNM: | |
20837 | return _("NT_VMS_LNM (language name)"); | |
20838 | case NT_VMS_SRC: | |
20839 | return _("NT_VMS_SRC (source files)"); | |
20840 | case NT_VMS_TITLE: | |
20841 | return "NT_VMS_TITLE"; | |
20842 | case NT_VMS_EIDC: | |
20843 | return _("NT_VMS_EIDC (consistency check)"); | |
20844 | case NT_VMS_FPMODE: | |
20845 | return _("NT_VMS_FPMODE (FP mode)"); | |
20846 | case NT_VMS_LINKTIME: | |
20847 | return "NT_VMS_LINKTIME"; | |
20848 | case NT_VMS_IMGNAM: | |
20849 | return _("NT_VMS_IMGNAM (image name)"); | |
20850 | case NT_VMS_IMGID: | |
20851 | return _("NT_VMS_IMGID (image id)"); | |
20852 | case NT_VMS_LINKID: | |
20853 | return _("NT_VMS_LINKID (link id)"); | |
20854 | case NT_VMS_IMGBID: | |
20855 | return _("NT_VMS_IMGBID (build id)"); | |
20856 | case NT_VMS_GSTNAM: | |
20857 | return _("NT_VMS_GSTNAM (sym table name)"); | |
20858 | case NT_VMS_ORIG_DYN: | |
20859 | return "NT_VMS_ORIG_DYN"; | |
20860 | case NT_VMS_PATCHTIME: | |
20861 | return "NT_VMS_PATCHTIME"; | |
20862 | default: | |
20863 | snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type); | |
20864 | return buff; | |
20865 | } | |
20866 | } | |
20867 | ||
20868 | static bool | |
20869 | print_ia64_vms_note (Elf_Internal_Note * pnote) | |
20870 | { | |
20871 | unsigned int maxlen = pnote->descsz; | |
20872 | ||
20873 | if (maxlen < 2 || maxlen != pnote->descsz) | |
20874 | goto desc_size_fail; | |
20875 | ||
20876 | switch (pnote->type) | |
20877 | { | |
20878 | case NT_VMS_MHD: | |
20879 | if (maxlen <= 36) | |
20880 | goto desc_size_fail; | |
20881 | ||
20882 | size_t l = strnlen (pnote->descdata + 34, maxlen - 34); | |
20883 | ||
20884 | printf (_(" Creation date : %.17s\n"), pnote->descdata); | |
20885 | printf (_(" Last patch date: %.17s\n"), pnote->descdata + 17); | |
20886 | if (l + 34 < maxlen) | |
20887 | { | |
20888 | printf (_(" Module name : %s\n"), pnote->descdata + 34); | |
20889 | if (l + 35 < maxlen) | |
20890 | printf (_(" Module version : %s\n"), pnote->descdata + 34 + l + 1); | |
20891 | else | |
20892 | printf (_(" Module version : <missing>\n")); | |
20893 | } | |
20894 | else | |
20895 | { | |
20896 | printf (_(" Module name : <missing>\n")); | |
20897 | printf (_(" Module version : <missing>\n")); | |
20898 | } | |
20899 | break; | |
20900 | ||
20901 | case NT_VMS_LNM: | |
20902 | printf (_(" Language: %.*s\n"), maxlen, pnote->descdata); | |
20903 | break; | |
20904 | ||
20905 | case NT_VMS_FPMODE: | |
20906 | printf (_(" Floating Point mode: ")); | |
20907 | if (maxlen < 8) | |
20908 | goto desc_size_fail; | |
20909 | /* FIXME: Generate an error if descsz > 8 ? */ | |
20910 | ||
20911 | printf ("0x%016" PRIx64 "\n", | |
20912 | byte_get ((unsigned char *) pnote->descdata, 8)); | |
20913 | break; | |
20914 | ||
20915 | case NT_VMS_LINKTIME: | |
20916 | printf (_(" Link time: ")); | |
20917 | if (maxlen < 8) | |
20918 | goto desc_size_fail; | |
20919 | /* FIXME: Generate an error if descsz > 8 ? */ | |
20920 | ||
20921 | print_vms_time (byte_get ((unsigned char *) pnote->descdata, 8)); | |
20922 | printf ("\n"); | |
20923 | break; | |
20924 | ||
20925 | case NT_VMS_PATCHTIME: | |
20926 | printf (_(" Patch time: ")); | |
20927 | if (maxlen < 8) | |
20928 | goto desc_size_fail; | |
20929 | /* FIXME: Generate an error if descsz > 8 ? */ | |
20930 | ||
20931 | print_vms_time (byte_get ((unsigned char *) pnote->descdata, 8)); | |
20932 | printf ("\n"); | |
20933 | break; | |
20934 | ||
20935 | case NT_VMS_ORIG_DYN: | |
20936 | if (maxlen < 34) | |
20937 | goto desc_size_fail; | |
20938 | ||
20939 | printf (_(" Major id: %u, minor id: %u\n"), | |
20940 | (unsigned) byte_get ((unsigned char *) pnote->descdata, 4), | |
20941 | (unsigned) byte_get ((unsigned char *) pnote->descdata + 4, 4)); | |
20942 | printf (_(" Last modified : ")); | |
20943 | print_vms_time (byte_get ((unsigned char *) pnote->descdata + 8, 8)); | |
20944 | printf (_("\n Link flags : ")); | |
20945 | printf ("0x%016" PRIx64 "\n", | |
20946 | byte_get ((unsigned char *) pnote->descdata + 16, 8)); | |
20947 | printf (_(" Header flags: 0x%08x\n"), | |
20948 | (unsigned) byte_get ((unsigned char *) pnote->descdata + 24, 4)); | |
20949 | printf (_(" Image id : %.*s\n"), maxlen - 32, pnote->descdata + 32); | |
20950 | break; | |
20951 | ||
20952 | case NT_VMS_IMGNAM: | |
20953 | printf (_(" Image name: %.*s\n"), maxlen, pnote->descdata); | |
20954 | break; | |
20955 | ||
20956 | case NT_VMS_GSTNAM: | |
20957 | printf (_(" Global symbol table name: %.*s\n"), maxlen, pnote->descdata); | |
20958 | break; | |
20959 | ||
20960 | case NT_VMS_IMGID: | |
20961 | printf (_(" Image id: %.*s\n"), maxlen, pnote->descdata); | |
20962 | break; | |
20963 | ||
20964 | case NT_VMS_LINKID: | |
20965 | printf (_(" Linker id: %.*s\n"), maxlen, pnote->descdata); | |
20966 | break; | |
20967 | ||
20968 | default: | |
20969 | return false; | |
20970 | } | |
20971 | ||
20972 | return true; | |
20973 | ||
20974 | desc_size_fail: | |
20975 | printf (_(" <corrupt - data size is too small>\n")); | |
20976 | error (_("corrupt IA64 note: data size is too small\n")); | |
20977 | return false; | |
20978 | } | |
20979 | ||
20980 | struct build_attr_cache { | |
20981 | Filedata *filedata; | |
20982 | char *strtab; | |
20983 | uint64_t strtablen; | |
20984 | Elf_Internal_Sym *symtab; | |
20985 | uint64_t nsyms; | |
20986 | } ba_cache; | |
20987 | ||
20988 | /* Find the symbol associated with a build attribute that is attached | |
20989 | to address OFFSET. If PNAME is non-NULL then store the name of | |
20990 | the symbol (if found) in the provided pointer, Returns NULL if a | |
20991 | symbol could not be found. */ | |
20992 | ||
20993 | static Elf_Internal_Sym * | |
20994 | get_symbol_for_build_attribute (Filedata *filedata, | |
20995 | uint64_t offset, | |
20996 | bool is_open_attr, | |
20997 | const char **pname) | |
20998 | { | |
20999 | Elf_Internal_Sym *saved_sym = NULL; | |
21000 | Elf_Internal_Sym *sym; | |
21001 | ||
21002 | if (filedata->section_headers != NULL | |
21003 | && (ba_cache.filedata == NULL || filedata != ba_cache.filedata)) | |
21004 | { | |
21005 | Elf_Internal_Shdr * symsec; | |
21006 | ||
21007 | free (ba_cache.strtab); | |
21008 | ba_cache.strtab = NULL; | |
21009 | free (ba_cache.symtab); | |
21010 | ba_cache.symtab = NULL; | |
21011 | ||
21012 | /* Load the symbol and string sections. */ | |
21013 | for (symsec = filedata->section_headers; | |
21014 | symsec < filedata->section_headers + filedata->file_header.e_shnum; | |
21015 | symsec ++) | |
21016 | { | |
21017 | if (symsec->sh_type == SHT_SYMTAB | |
21018 | && get_symtab (filedata, symsec, | |
21019 | &ba_cache.symtab, &ba_cache.nsyms, | |
21020 | &ba_cache.strtab, &ba_cache.strtablen)) | |
21021 | break; | |
21022 | } | |
21023 | ba_cache.filedata = filedata; | |
21024 | } | |
21025 | ||
21026 | if (ba_cache.symtab == NULL) | |
21027 | return NULL; | |
21028 | ||
21029 | /* Find a symbol whose value matches offset. */ | |
21030 | for (sym = ba_cache.symtab; sym < ba_cache.symtab + ba_cache.nsyms; sym ++) | |
21031 | if (sym->st_value == offset) | |
21032 | { | |
21033 | if (sym->st_name >= ba_cache.strtablen) | |
21034 | /* Huh ? This should not happen. */ | |
21035 | continue; | |
21036 | ||
21037 | if (ba_cache.strtab[sym->st_name] == 0) | |
21038 | continue; | |
21039 | ||
21040 | /* The AArch64, ARM and RISC-V architectures define mapping symbols | |
21041 | (eg $d, $x, $t) which we want to ignore. */ | |
21042 | if (ba_cache.strtab[sym->st_name] == '$' | |
21043 | && ba_cache.strtab[sym->st_name + 1] != 0 | |
21044 | && ba_cache.strtab[sym->st_name + 2] == 0) | |
21045 | continue; | |
21046 | ||
21047 | if (is_open_attr) | |
21048 | { | |
21049 | /* For OPEN attributes we prefer GLOBAL over LOCAL symbols | |
21050 | and FILE or OBJECT symbols over NOTYPE symbols. We skip | |
21051 | FUNC symbols entirely. */ | |
21052 | switch (ELF_ST_TYPE (sym->st_info)) | |
21053 | { | |
21054 | case STT_OBJECT: | |
21055 | case STT_FILE: | |
21056 | saved_sym = sym; | |
21057 | if (sym->st_size) | |
21058 | { | |
21059 | /* If the symbol has a size associated | |
21060 | with it then we can stop searching. */ | |
21061 | sym = ba_cache.symtab + ba_cache.nsyms; | |
21062 | } | |
21063 | continue; | |
21064 | ||
21065 | case STT_FUNC: | |
21066 | /* Ignore function symbols. */ | |
21067 | continue; | |
21068 | ||
21069 | default: | |
21070 | break; | |
21071 | } | |
21072 | ||
21073 | switch (ELF_ST_BIND (sym->st_info)) | |
21074 | { | |
21075 | case STB_GLOBAL: | |
21076 | if (saved_sym == NULL | |
21077 | || ELF_ST_TYPE (saved_sym->st_info) != STT_OBJECT) | |
21078 | saved_sym = sym; | |
21079 | break; | |
21080 | ||
21081 | case STB_LOCAL: | |
21082 | if (saved_sym == NULL) | |
21083 | saved_sym = sym; | |
21084 | break; | |
21085 | ||
21086 | default: | |
21087 | break; | |
21088 | } | |
21089 | } | |
21090 | else | |
21091 | { | |
21092 | if (ELF_ST_TYPE (sym->st_info) != STT_FUNC) | |
21093 | continue; | |
21094 | ||
21095 | saved_sym = sym; | |
21096 | break; | |
21097 | } | |
21098 | } | |
21099 | ||
21100 | if (saved_sym && pname) | |
21101 | * pname = ba_cache.strtab + saved_sym->st_name; | |
21102 | ||
21103 | return saved_sym; | |
21104 | } | |
21105 | ||
21106 | /* Returns true iff addr1 and addr2 are in the same section. */ | |
21107 | ||
21108 | static bool | |
21109 | same_section (Filedata * filedata, uint64_t addr1, uint64_t addr2) | |
21110 | { | |
21111 | Elf_Internal_Shdr * a1; | |
21112 | Elf_Internal_Shdr * a2; | |
21113 | ||
21114 | a1 = find_section_by_address (filedata, addr1); | |
21115 | a2 = find_section_by_address (filedata, addr2); | |
21116 | ||
21117 | return a1 == a2 && a1 != NULL; | |
21118 | } | |
21119 | ||
21120 | static bool | |
21121 | print_gnu_build_attribute_description (Elf_Internal_Note * pnote, | |
21122 | Filedata * filedata) | |
21123 | { | |
21124 | static uint64_t global_offset = 0; | |
21125 | static uint64_t global_end = 0; | |
21126 | static uint64_t func_offset = 0; | |
21127 | static uint64_t func_end = 0; | |
21128 | ||
21129 | Elf_Internal_Sym *sym; | |
21130 | const char *name; | |
21131 | uint64_t start; | |
21132 | uint64_t end; | |
21133 | bool is_open_attr = pnote->type == NT_GNU_BUILD_ATTRIBUTE_OPEN; | |
21134 | ||
21135 | switch (pnote->descsz) | |
21136 | { | |
21137 | case 0: | |
21138 | /* A zero-length description means that the range of | |
21139 | the previous note of the same type should be used. */ | |
21140 | if (is_open_attr) | |
21141 | { | |
21142 | if (global_end > global_offset) | |
21143 | printf (_(" Applies to region from %#" PRIx64 | |
21144 | " to %#" PRIx64 "\n"), global_offset, global_end); | |
21145 | else | |
21146 | printf (_(" Applies to region from %#" PRIx64 | |
21147 | "\n"), global_offset); | |
21148 | } | |
21149 | else | |
21150 | { | |
21151 | if (func_end > func_offset) | |
21152 | printf (_(" Applies to region from %#" PRIx64 | |
21153 | " to %#" PRIx64 "\n"), func_offset, func_end); | |
21154 | else | |
21155 | printf (_(" Applies to region from %#" PRIx64 | |
21156 | "\n"), func_offset); | |
21157 | } | |
21158 | return true; | |
21159 | ||
21160 | case 4: | |
21161 | start = byte_get ((unsigned char *) pnote->descdata, 4); | |
21162 | end = 0; | |
21163 | break; | |
21164 | ||
21165 | case 8: | |
21166 | start = byte_get ((unsigned char *) pnote->descdata, 4); | |
21167 | end = byte_get ((unsigned char *) pnote->descdata + 4, 4); | |
21168 | break; | |
21169 | ||
21170 | case 16: | |
21171 | start = byte_get ((unsigned char *) pnote->descdata, 8); | |
21172 | end = byte_get ((unsigned char *) pnote->descdata + 8, 8); | |
21173 | break; | |
21174 | ||
21175 | default: | |
21176 | error (_(" <invalid description size: %lx>\n"), pnote->descsz); | |
21177 | printf (_(" <invalid descsz>")); | |
21178 | return false; | |
21179 | } | |
21180 | ||
21181 | name = NULL; | |
21182 | sym = get_symbol_for_build_attribute (filedata, start, is_open_attr, & name); | |
21183 | /* As of version 5 of the annobin plugin, filename symbols are biased by 2 | |
21184 | in order to avoid them being confused with the start address of the | |
21185 | first function in the file... */ | |
21186 | if (sym == NULL && is_open_attr) | |
21187 | sym = get_symbol_for_build_attribute (filedata, start + 2, is_open_attr, | |
21188 | & name); | |
21189 | ||
21190 | if (end == 0 && sym != NULL && sym->st_size > 0) | |
21191 | end = start + sym->st_size; | |
21192 | ||
21193 | if (is_open_attr) | |
21194 | { | |
21195 | /* FIXME: Need to properly allow for section alignment. | |
21196 | 16 is just the alignment used on x86_64. */ | |
21197 | if (global_end > 0 | |
21198 | && start > BFD_ALIGN (global_end, 16) | |
21199 | /* Build notes are not guaranteed to be organised in order of | |
21200 | increasing address, but we should find the all of the notes | |
21201 | for one section in the same place. */ | |
21202 | && same_section (filedata, start, global_end)) | |
21203 | warn (_("Gap in build notes detected from %#" PRIx64 | |
21204 | " to %#" PRIx64 "\n"), | |
21205 | global_end + 1, start - 1); | |
21206 | ||
21207 | printf (_(" Applies to region from %#" PRIx64), start); | |
21208 | global_offset = start; | |
21209 | ||
21210 | if (end) | |
21211 | { | |
21212 | printf (_(" to %#" PRIx64), end); | |
21213 | global_end = end; | |
21214 | } | |
21215 | } | |
21216 | else | |
21217 | { | |
21218 | printf (_(" Applies to region from %#" PRIx64), start); | |
21219 | func_offset = start; | |
21220 | ||
21221 | if (end) | |
21222 | { | |
21223 | printf (_(" to %#" PRIx64), end); | |
21224 | func_end = end; | |
21225 | } | |
21226 | } | |
21227 | ||
21228 | if (sym && name) | |
21229 | printf (_(" (%s)"), name); | |
21230 | ||
21231 | printf ("\n"); | |
21232 | return true; | |
21233 | } | |
21234 | ||
21235 | static bool | |
21236 | print_gnu_build_attribute_name (Elf_Internal_Note * pnote) | |
21237 | { | |
21238 | static const char string_expected [2] = { GNU_BUILD_ATTRIBUTE_TYPE_STRING, 0 }; | |
21239 | static const char number_expected [2] = { GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC, 0 }; | |
21240 | static const char bool_expected [3] = { GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE, GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE, 0 }; | |
21241 | char name_type; | |
21242 | char name_attribute; | |
21243 | const char * expected_types; | |
21244 | const char * name = pnote->namedata; | |
21245 | const char * text; | |
21246 | signed int left; | |
21247 | ||
21248 | if (name == NULL || pnote->namesz < 2) | |
21249 | { | |
21250 | error (_("corrupt name field in GNU build attribute note: size = %ld\n"), pnote->namesz); | |
21251 | print_symbol (-20, _(" <corrupt name>")); | |
21252 | return false; | |
21253 | } | |
21254 | ||
21255 | if (do_wide) | |
21256 | left = 28; | |
21257 | else | |
21258 | left = 20; | |
21259 | ||
21260 | /* Version 2 of the spec adds a "GA" prefix to the name field. */ | |
21261 | if (name[0] == 'G' && name[1] == 'A') | |
21262 | { | |
21263 | if (pnote->namesz < 4) | |
21264 | { | |
21265 | error (_("corrupt name field in GNU build attribute note: size = %ld\n"), pnote->namesz); | |
21266 | print_symbol (-20, _(" <corrupt name>")); | |
21267 | return false; | |
21268 | } | |
21269 | ||
21270 | printf ("GA"); | |
21271 | name += 2; | |
21272 | left -= 2; | |
21273 | } | |
21274 | ||
21275 | switch ((name_type = * name)) | |
21276 | { | |
21277 | case GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC: | |
21278 | case GNU_BUILD_ATTRIBUTE_TYPE_STRING: | |
21279 | case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE: | |
21280 | case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE: | |
21281 | printf ("%c", * name); | |
21282 | left --; | |
21283 | break; | |
21284 | default: | |
21285 | error (_("unrecognised attribute type in name field: %d\n"), name_type); | |
21286 | print_symbol (-20, _("<unknown name type>")); | |
21287 | return false; | |
21288 | } | |
21289 | ||
21290 | ++ name; | |
21291 | text = NULL; | |
21292 | ||
21293 | switch ((name_attribute = * name)) | |
21294 | { | |
21295 | case GNU_BUILD_ATTRIBUTE_VERSION: | |
21296 | text = _("<version>"); | |
21297 | expected_types = string_expected; | |
21298 | ++ name; | |
21299 | break; | |
21300 | case GNU_BUILD_ATTRIBUTE_STACK_PROT: | |
21301 | text = _("<stack prot>"); | |
21302 | expected_types = "!+*"; | |
21303 | ++ name; | |
21304 | break; | |
21305 | case GNU_BUILD_ATTRIBUTE_RELRO: | |
21306 | text = _("<relro>"); | |
21307 | expected_types = bool_expected; | |
21308 | ++ name; | |
21309 | break; | |
21310 | case GNU_BUILD_ATTRIBUTE_STACK_SIZE: | |
21311 | text = _("<stack size>"); | |
21312 | expected_types = number_expected; | |
21313 | ++ name; | |
21314 | break; | |
21315 | case GNU_BUILD_ATTRIBUTE_TOOL: | |
21316 | text = _("<tool>"); | |
21317 | expected_types = string_expected; | |
21318 | ++ name; | |
21319 | break; | |
21320 | case GNU_BUILD_ATTRIBUTE_ABI: | |
21321 | text = _("<ABI>"); | |
21322 | expected_types = "$*"; | |
21323 | ++ name; | |
21324 | break; | |
21325 | case GNU_BUILD_ATTRIBUTE_PIC: | |
21326 | text = _("<PIC>"); | |
21327 | expected_types = number_expected; | |
21328 | ++ name; | |
21329 | break; | |
21330 | case GNU_BUILD_ATTRIBUTE_SHORT_ENUM: | |
21331 | text = _("<short enum>"); | |
21332 | expected_types = bool_expected; | |
21333 | ++ name; | |
21334 | break; | |
21335 | default: | |
21336 | if (ISPRINT (* name)) | |
21337 | { | |
21338 | int len = strnlen (name, pnote->namesz - (name - pnote->namedata)) + 1; | |
21339 | ||
21340 | if (len > left && ! do_wide) | |
21341 | len = left; | |
21342 | printf ("%.*s:", len, name); | |
21343 | left -= len; | |
21344 | name += len; | |
21345 | } | |
21346 | else | |
21347 | { | |
21348 | static char tmpbuf [128]; | |
21349 | ||
21350 | error (_("unrecognised byte in name field: %d\n"), * name); | |
21351 | sprintf (tmpbuf, _("<unknown:_%d>"), * name); | |
21352 | text = tmpbuf; | |
21353 | name ++; | |
21354 | } | |
21355 | expected_types = "*$!+"; | |
21356 | break; | |
21357 | } | |
21358 | ||
21359 | if (text) | |
21360 | left -= printf ("%s", text); | |
21361 | ||
21362 | if (strchr (expected_types, name_type) == NULL) | |
21363 | warn (_("attribute does not have an expected type (%c)\n"), name_type); | |
21364 | ||
21365 | if ((size_t) (name - pnote->namedata) > pnote->namesz) | |
21366 | { | |
21367 | error (_("corrupt name field: namesz: %lu but parsing gets to %td\n"), | |
21368 | pnote->namesz, | |
21369 | name - pnote->namedata); | |
21370 | return false; | |
21371 | } | |
21372 | ||
21373 | if (left < 1 && ! do_wide) | |
21374 | return true; | |
21375 | ||
21376 | switch (name_type) | |
21377 | { | |
21378 | case GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC: | |
21379 | { | |
21380 | unsigned int bytes; | |
21381 | uint64_t val = 0; | |
21382 | unsigned int shift = 0; | |
21383 | char *decoded = NULL; | |
21384 | ||
21385 | bytes = pnote->namesz - (name - pnote->namedata); | |
21386 | if (bytes > 0) | |
21387 | /* The -1 is because the name field is always 0 terminated, and we | |
21388 | want to be able to ensure that the shift in the while loop below | |
21389 | will not overflow. */ | |
21390 | -- bytes; | |
21391 | ||
21392 | if (bytes > sizeof (val)) | |
21393 | { | |
21394 | error (_("corrupt numeric name field: too many bytes in the value: %x\n"), | |
21395 | bytes); | |
21396 | bytes = sizeof (val); | |
21397 | } | |
21398 | /* We do not bother to warn if bytes == 0 as this can | |
21399 | happen with some early versions of the gcc plugin. */ | |
21400 | ||
21401 | while (bytes --) | |
21402 | { | |
21403 | uint64_t byte = *name++ & 0xff; | |
21404 | ||
21405 | val |= byte << shift; | |
21406 | shift += 8; | |
21407 | } | |
21408 | ||
21409 | switch (name_attribute) | |
21410 | { | |
21411 | case GNU_BUILD_ATTRIBUTE_PIC: | |
21412 | switch (val) | |
21413 | { | |
21414 | case 0: decoded = "static"; break; | |
21415 | case 1: decoded = "pic"; break; | |
21416 | case 2: decoded = "PIC"; break; | |
21417 | case 3: decoded = "pie"; break; | |
21418 | case 4: decoded = "PIE"; break; | |
21419 | default: break; | |
21420 | } | |
21421 | break; | |
21422 | case GNU_BUILD_ATTRIBUTE_STACK_PROT: | |
21423 | switch (val) | |
21424 | { | |
21425 | /* Based upon the SPCT_FLAG_xxx enum values in gcc/cfgexpand.c. */ | |
21426 | case 0: decoded = "off"; break; | |
21427 | case 1: decoded = "on"; break; | |
21428 | case 2: decoded = "all"; break; | |
21429 | case 3: decoded = "strong"; break; | |
21430 | case 4: decoded = "explicit"; break; | |
21431 | default: break; | |
21432 | } | |
21433 | break; | |
21434 | default: | |
21435 | break; | |
21436 | } | |
21437 | ||
21438 | if (decoded != NULL) | |
21439 | { | |
21440 | print_symbol (-left, decoded); | |
21441 | left = 0; | |
21442 | } | |
21443 | else if (val == 0) | |
21444 | { | |
21445 | printf ("0x0"); | |
21446 | left -= 3; | |
21447 | } | |
21448 | else | |
21449 | { | |
21450 | if (do_wide) | |
21451 | left -= printf ("0x%" PRIx64, val); | |
21452 | else | |
21453 | left -= printf ("0x%-.*" PRIx64, left, val); | |
21454 | } | |
21455 | } | |
21456 | break; | |
21457 | case GNU_BUILD_ATTRIBUTE_TYPE_STRING: | |
21458 | left -= print_symbol (- left, name); | |
21459 | break; | |
21460 | case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE: | |
21461 | left -= print_symbol (- left, "true"); | |
21462 | break; | |
21463 | case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE: | |
21464 | left -= print_symbol (- left, "false"); | |
21465 | break; | |
21466 | } | |
21467 | ||
21468 | if (do_wide && left > 0) | |
21469 | printf ("%-*s", left, " "); | |
21470 | ||
21471 | return true; | |
21472 | } | |
21473 | ||
21474 | /* Print the contents of PNOTE as hex. */ | |
21475 | ||
21476 | static void | |
21477 | print_note_contents_hex (Elf_Internal_Note *pnote) | |
21478 | { | |
21479 | if (pnote->descsz) | |
21480 | { | |
21481 | size_t i; | |
21482 | ||
21483 | printf (_(" description data: ")); | |
21484 | for (i = 0; i < pnote->descsz; i++) | |
21485 | printf ("%02x ", pnote->descdata[i] & 0xff); | |
21486 | if (!do_wide) | |
21487 | printf ("\n"); | |
21488 | } | |
21489 | ||
21490 | if (do_wide) | |
21491 | printf ("\n"); | |
21492 | } | |
21493 | ||
21494 | #if defined HAVE_MSGPACK | |
21495 | ||
21496 | static void | |
21497 | print_indents (int n) | |
21498 | { | |
21499 | printf (" "); | |
21500 | ||
21501 | for (int i = 0; i < n; i++) | |
21502 | printf (" "); | |
21503 | } | |
21504 | ||
21505 | /* Print OBJ in human-readable form. */ | |
21506 | ||
21507 | static void | |
21508 | dump_msgpack_obj (const msgpack_object *obj, int indent) | |
21509 | { | |
21510 | switch (obj->type) | |
21511 | { | |
21512 | case MSGPACK_OBJECT_NIL: | |
21513 | printf ("(nil)"); | |
21514 | break; | |
21515 | ||
21516 | case MSGPACK_OBJECT_BOOLEAN: | |
21517 | printf ("%s", obj->via.boolean ? "true" : "false"); | |
21518 | break; | |
21519 | ||
21520 | case MSGPACK_OBJECT_POSITIVE_INTEGER: | |
21521 | printf ("%" PRIu64, obj->via.u64); | |
21522 | break; | |
21523 | ||
21524 | case MSGPACK_OBJECT_NEGATIVE_INTEGER: | |
21525 | printf ("%" PRIi64, obj->via.i64); | |
21526 | break; | |
21527 | ||
21528 | case MSGPACK_OBJECT_FLOAT32: | |
21529 | case MSGPACK_OBJECT_FLOAT64: | |
21530 | printf ("%f", obj->via.f64); | |
21531 | break; | |
21532 | ||
21533 | case MSGPACK_OBJECT_STR: | |
21534 | printf ("\"%.*s\"", obj->via.str.size, obj->via.str.ptr); | |
21535 | break; | |
21536 | ||
21537 | case MSGPACK_OBJECT_ARRAY: | |
21538 | { | |
21539 | const msgpack_object_array *array = &obj->via.array; | |
21540 | ||
21541 | printf ("[\n"); | |
21542 | ++indent; | |
21543 | ||
21544 | for (uint32_t i = 0; i < array->size; ++i) | |
21545 | { | |
21546 | const msgpack_object *item = &array->ptr[i]; | |
21547 | ||
21548 | print_indents (indent); | |
21549 | dump_msgpack_obj (item, indent); | |
21550 | printf (",\n"); | |
21551 | } | |
21552 | ||
21553 | --indent; | |
21554 | print_indents (indent); | |
21555 | printf ("]"); | |
21556 | break; | |
21557 | } | |
21558 | break; | |
21559 | ||
21560 | case MSGPACK_OBJECT_MAP: | |
21561 | { | |
21562 | const msgpack_object_map *map = &obj->via.map; | |
21563 | ||
21564 | printf ("{\n"); | |
21565 | ++indent; | |
21566 | ||
21567 | for (uint32_t i = 0; i < map->size; ++i) | |
21568 | { | |
21569 | const msgpack_object_kv *kv = &map->ptr[i]; | |
21570 | const msgpack_object *key = &kv->key; | |
21571 | const msgpack_object *val = &kv->val; | |
21572 | ||
21573 | print_indents (indent); | |
21574 | dump_msgpack_obj (key, indent); | |
21575 | printf (": "); | |
21576 | dump_msgpack_obj (val, indent); | |
21577 | ||
21578 | printf (",\n"); | |
21579 | } | |
21580 | ||
21581 | --indent; | |
21582 | print_indents (indent); | |
21583 | printf ("}"); | |
21584 | ||
21585 | break; | |
21586 | } | |
21587 | ||
21588 | case MSGPACK_OBJECT_BIN: | |
21589 | printf ("(bin)"); | |
21590 | break; | |
21591 | ||
21592 | case MSGPACK_OBJECT_EXT: | |
21593 | printf ("(ext)"); | |
21594 | break; | |
21595 | } | |
21596 | } | |
21597 | ||
21598 | static void | |
21599 | dump_msgpack (const msgpack_unpacked *msg) | |
21600 | { | |
21601 | print_indents (0); | |
21602 | dump_msgpack_obj (&msg->data, 0); | |
21603 | printf ("\n"); | |
21604 | } | |
21605 | ||
21606 | #endif /* defined HAVE_MSGPACK */ | |
21607 | ||
21608 | static bool | |
21609 | print_amdgpu_note (Elf_Internal_Note *pnote) | |
21610 | { | |
21611 | #if defined HAVE_MSGPACK | |
21612 | /* If msgpack is available, decode and dump the note's content. */ | |
21613 | bool ret; | |
21614 | msgpack_unpacked msg; | |
21615 | msgpack_unpack_return msgpack_ret; | |
21616 | ||
21617 | assert (pnote->type == NT_AMDGPU_METADATA); | |
21618 | ||
21619 | msgpack_unpacked_init (&msg); | |
21620 | msgpack_ret = msgpack_unpack_next (&msg, pnote->descdata, pnote->descsz, | |
21621 | NULL); | |
21622 | ||
21623 | switch (msgpack_ret) | |
21624 | { | |
21625 | case MSGPACK_UNPACK_SUCCESS: | |
21626 | dump_msgpack (&msg); | |
21627 | ret = true; | |
21628 | break; | |
21629 | ||
21630 | default: | |
21631 | error (_("failed to unpack msgpack contents in NT_AMDGPU_METADATA note")); | |
21632 | ret = false; | |
21633 | break; | |
21634 | } | |
21635 | ||
21636 | msgpack_unpacked_destroy (&msg); | |
21637 | return ret; | |
21638 | #else | |
21639 | /* msgpack is not available, dump contents as hex. */ | |
21640 | print_note_contents_hex (pnote); | |
21641 | return true; | |
21642 | #endif | |
21643 | } | |
21644 | ||
21645 | /* Note that by the ELF standard, the name field is already null byte | |
21646 | terminated, and namesz includes the terminating null byte. | |
21647 | I.E. the value of namesz for the name "FSF" is 4. | |
21648 | ||
21649 | If the value of namesz is zero, there is no name present. */ | |
21650 | ||
21651 | static bool | |
21652 | process_note (Elf_Internal_Note * pnote, | |
21653 | Filedata * filedata) | |
21654 | { | |
21655 | const char * name = pnote->namesz ? pnote->namedata : "(NONE)"; | |
21656 | const char * nt; | |
21657 | ||
21658 | if (pnote->namesz == 0) | |
21659 | /* If there is no note name, then use the default set of | |
21660 | note type strings. */ | |
21661 | nt = get_note_type (filedata, pnote->type); | |
21662 | ||
21663 | else if (startswith (pnote->namedata, "GNU")) | |
21664 | /* GNU-specific object file notes. */ | |
21665 | nt = get_gnu_elf_note_type (pnote->type); | |
21666 | ||
21667 | else if (startswith (pnote->namedata, "AMDGPU")) | |
21668 | /* AMDGPU-specific object file notes. */ | |
21669 | nt = get_amdgpu_elf_note_type (pnote->type); | |
21670 | ||
21671 | else if (startswith (pnote->namedata, "FreeBSD")) | |
21672 | /* FreeBSD-specific core file notes. */ | |
21673 | nt = get_freebsd_elfcore_note_type (filedata, pnote->type); | |
21674 | ||
21675 | else if (startswith (pnote->namedata, "NetBSD-CORE")) | |
21676 | /* NetBSD-specific core file notes. */ | |
21677 | nt = get_netbsd_elfcore_note_type (filedata, pnote->type); | |
21678 | ||
21679 | else if (startswith (pnote->namedata, "NetBSD")) | |
21680 | /* NetBSD-specific core file notes. */ | |
21681 | return process_netbsd_elf_note (pnote); | |
21682 | ||
21683 | else if (startswith (pnote->namedata, "PaX")) | |
21684 | /* NetBSD-specific core file notes. */ | |
21685 | return process_netbsd_elf_note (pnote); | |
21686 | ||
21687 | else if (startswith (pnote->namedata, "OpenBSD")) | |
21688 | /* OpenBSD-specific core file notes. */ | |
21689 | nt = get_openbsd_elfcore_note_type (filedata, pnote->type); | |
21690 | ||
21691 | else if (startswith (pnote->namedata, "SPU/")) | |
21692 | { | |
21693 | /* SPU-specific core file notes. */ | |
21694 | nt = pnote->namedata + 4; | |
21695 | name = "SPU"; | |
21696 | } | |
21697 | ||
21698 | else if (startswith (pnote->namedata, "IPF/VMS")) | |
21699 | /* VMS/ia64-specific file notes. */ | |
21700 | nt = get_ia64_vms_note_type (pnote->type); | |
21701 | ||
21702 | else if (startswith (pnote->namedata, "stapsdt")) | |
21703 | nt = get_stapsdt_note_type (pnote->type); | |
21704 | ||
21705 | else | |
21706 | /* Don't recognize this note name; just use the default set of | |
21707 | note type strings. */ | |
21708 | nt = get_note_type (filedata, pnote->type); | |
21709 | ||
21710 | printf (" "); | |
21711 | ||
21712 | if (((startswith (pnote->namedata, "GA") | |
21713 | && strchr ("*$!+", pnote->namedata[2]) != NULL) | |
21714 | || strchr ("*$!+", pnote->namedata[0]) != NULL) | |
21715 | && (pnote->type == NT_GNU_BUILD_ATTRIBUTE_OPEN | |
21716 | || pnote->type == NT_GNU_BUILD_ATTRIBUTE_FUNC)) | |
21717 | print_gnu_build_attribute_name (pnote); | |
21718 | else | |
21719 | print_symbol (-20, name); | |
21720 | ||
21721 | if (do_wide) | |
21722 | printf (" 0x%08lx\t%s\t", pnote->descsz, nt); | |
21723 | else | |
21724 | printf (" 0x%08lx\t%s\n", pnote->descsz, nt); | |
21725 | ||
21726 | if (startswith (pnote->namedata, "IPF/VMS")) | |
21727 | return print_ia64_vms_note (pnote); | |
21728 | else if (startswith (pnote->namedata, "GNU")) | |
21729 | return print_gnu_note (filedata, pnote); | |
21730 | else if (startswith (pnote->namedata, "stapsdt")) | |
21731 | return print_stapsdt_note (pnote); | |
21732 | else if (startswith (pnote->namedata, "CORE")) | |
21733 | return print_core_note (pnote); | |
21734 | else if (startswith (pnote->namedata, "FDO")) | |
21735 | return print_fdo_note (pnote); | |
21736 | else if (((startswith (pnote->namedata, "GA") | |
21737 | && strchr ("*$!+", pnote->namedata[2]) != NULL) | |
21738 | || strchr ("*$!+", pnote->namedata[0]) != NULL) | |
21739 | && (pnote->type == NT_GNU_BUILD_ATTRIBUTE_OPEN | |
21740 | || pnote->type == NT_GNU_BUILD_ATTRIBUTE_FUNC)) | |
21741 | return print_gnu_build_attribute_description (pnote, filedata); | |
21742 | else if (startswith (pnote->namedata, "AMDGPU") | |
21743 | && pnote->type == NT_AMDGPU_METADATA) | |
21744 | return print_amdgpu_note (pnote); | |
21745 | ||
21746 | print_note_contents_hex (pnote); | |
21747 | return true; | |
21748 | } | |
21749 | ||
21750 | static bool | |
21751 | process_notes_at (Filedata * filedata, | |
21752 | Elf_Internal_Shdr * section, | |
21753 | uint64_t offset, | |
21754 | uint64_t length, | |
21755 | uint64_t align) | |
21756 | { | |
21757 | Elf_External_Note *pnotes; | |
21758 | Elf_External_Note *external; | |
21759 | char *end; | |
21760 | bool res = true; | |
21761 | ||
21762 | if (length <= 0) | |
21763 | return false; | |
21764 | ||
21765 | if (section) | |
21766 | { | |
21767 | pnotes = (Elf_External_Note *) get_section_contents (section, filedata); | |
21768 | if (pnotes) | |
21769 | { | |
21770 | if (! apply_relocations (filedata, section, (unsigned char *) pnotes, length, NULL, NULL)) | |
21771 | { | |
21772 | free (pnotes); | |
21773 | return false; | |
21774 | } | |
21775 | } | |
21776 | } | |
21777 | else | |
21778 | pnotes = (Elf_External_Note *) get_data (NULL, filedata, offset, 1, length, | |
21779 | _("notes")); | |
21780 | ||
21781 | if (pnotes == NULL) | |
21782 | return false; | |
21783 | ||
21784 | external = pnotes; | |
21785 | ||
21786 | if (filedata->is_separate) | |
21787 | printf (_("In linked file '%s': "), filedata->file_name); | |
21788 | else | |
21789 | printf ("\n"); | |
21790 | if (section) | |
21791 | printf (_("Displaying notes found in: %s\n"), printable_section_name (filedata, section)); | |
21792 | else | |
21793 | printf (_("Displaying notes found at file offset 0x%08" PRIx64 | |
21794 | " with length 0x%08" PRIx64 ":\n"), | |
21795 | offset, length); | |
21796 | ||
21797 | /* NB: Some note sections may have alignment value of 0 or 1. gABI | |
21798 | specifies that notes should be aligned to 4 bytes in 32-bit | |
21799 | objects and to 8 bytes in 64-bit objects. As a Linux extension, | |
21800 | we also support 4 byte alignment in 64-bit objects. If section | |
21801 | alignment is less than 4, we treate alignment as 4 bytes. */ | |
21802 | if (align < 4) | |
21803 | align = 4; | |
21804 | else if (align != 4 && align != 8) | |
21805 | { | |
21806 | warn (_("Corrupt note: alignment %" PRId64 ", expecting 4 or 8\n"), | |
21807 | align); | |
21808 | free (pnotes); | |
21809 | return false; | |
21810 | } | |
21811 | ||
21812 | printf (_(" %-20s %-10s\tDescription\n"), _("Owner"), _("Data size")); | |
21813 | ||
21814 | end = (char *) pnotes + length; | |
21815 | while ((char *) external < end) | |
21816 | { | |
21817 | Elf_Internal_Note inote; | |
21818 | size_t min_notesz; | |
21819 | char * next; | |
21820 | char * temp = NULL; | |
21821 | size_t data_remaining = end - (char *) external; | |
21822 | ||
21823 | if (!is_ia64_vms (filedata)) | |
21824 | { | |
21825 | /* PR binutils/15191 | |
21826 | Make sure that there is enough data to read. */ | |
21827 | min_notesz = offsetof (Elf_External_Note, name); | |
21828 | if (data_remaining < min_notesz) | |
21829 | { | |
21830 | warn (ngettext ("Corrupt note: only %zd byte remains, " | |
21831 | "not enough for a full note\n", | |
21832 | "Corrupt note: only %zd bytes remain, " | |
21833 | "not enough for a full note\n", | |
21834 | data_remaining), | |
21835 | data_remaining); | |
21836 | break; | |
21837 | } | |
21838 | data_remaining -= min_notesz; | |
21839 | ||
21840 | inote.type = BYTE_GET (external->type); | |
21841 | inote.namesz = BYTE_GET (external->namesz); | |
21842 | inote.namedata = external->name; | |
21843 | inote.descsz = BYTE_GET (external->descsz); | |
21844 | inote.descdata = ((char *) external | |
21845 | + ELF_NOTE_DESC_OFFSET (inote.namesz, align)); | |
21846 | inote.descpos = offset + (inote.descdata - (char *) pnotes); | |
21847 | next = ((char *) external | |
21848 | + ELF_NOTE_NEXT_OFFSET (inote.namesz, inote.descsz, align)); | |
21849 | } | |
21850 | else | |
21851 | { | |
21852 | Elf64_External_VMS_Note *vms_external; | |
21853 | ||
21854 | /* PR binutils/15191 | |
21855 | Make sure that there is enough data to read. */ | |
21856 | min_notesz = offsetof (Elf64_External_VMS_Note, name); | |
21857 | if (data_remaining < min_notesz) | |
21858 | { | |
21859 | warn (ngettext ("Corrupt note: only %zd byte remains, " | |
21860 | "not enough for a full note\n", | |
21861 | "Corrupt note: only %zd bytes remain, " | |
21862 | "not enough for a full note\n", | |
21863 | data_remaining), | |
21864 | data_remaining); | |
21865 | break; | |
21866 | } | |
21867 | data_remaining -= min_notesz; | |
21868 | ||
21869 | vms_external = (Elf64_External_VMS_Note *) external; | |
21870 | inote.type = BYTE_GET (vms_external->type); | |
21871 | inote.namesz = BYTE_GET (vms_external->namesz); | |
21872 | inote.namedata = vms_external->name; | |
21873 | inote.descsz = BYTE_GET (vms_external->descsz); | |
21874 | inote.descdata = inote.namedata + align_power (inote.namesz, 3); | |
21875 | inote.descpos = offset + (inote.descdata - (char *) pnotes); | |
21876 | next = inote.descdata + align_power (inote.descsz, 3); | |
21877 | } | |
21878 | ||
21879 | /* PR 17531: file: 3443835e. */ | |
21880 | /* PR 17531: file: id:000000,sig:11,src:006986,op:havoc,rep:4. */ | |
21881 | if ((size_t) (inote.descdata - inote.namedata) < inote.namesz | |
21882 | || (size_t) (inote.descdata - inote.namedata) > data_remaining | |
21883 | || (size_t) (next - inote.descdata) < inote.descsz | |
21884 | || ((size_t) (next - inote.descdata) | |
21885 | > data_remaining - (size_t) (inote.descdata - inote.namedata))) | |
21886 | { | |
21887 | warn (_("note with invalid namesz and/or descsz found at offset %#tx\n"), | |
21888 | (char *) external - (char *) pnotes); | |
21889 | warn (_(" type: %#lx, namesize: %#lx, descsize: %#lx, alignment: %u\n"), | |
21890 | inote.type, inote.namesz, inote.descsz, (int) align); | |
21891 | break; | |
21892 | } | |
21893 | ||
21894 | external = (Elf_External_Note *) next; | |
21895 | ||
21896 | /* Verify that name is null terminated. It appears that at least | |
21897 | one version of Linux (RedHat 6.0) generates corefiles that don't | |
21898 | comply with the ELF spec by failing to include the null byte in | |
21899 | namesz. */ | |
21900 | if (inote.namesz > 0 && inote.namedata[inote.namesz - 1] != '\0') | |
21901 | { | |
21902 | if ((size_t) (inote.descdata - inote.namedata) == inote.namesz) | |
21903 | { | |
21904 | temp = (char *) malloc (inote.namesz + 1); | |
21905 | if (temp == NULL) | |
21906 | { | |
21907 | error (_("Out of memory allocating space for inote name\n")); | |
21908 | res = false; | |
21909 | break; | |
21910 | } | |
21911 | ||
21912 | memcpy (temp, inote.namedata, inote.namesz); | |
21913 | inote.namedata = temp; | |
21914 | } | |
21915 | inote.namedata[inote.namesz] = 0; | |
21916 | } | |
21917 | ||
21918 | if (! process_note (& inote, filedata)) | |
21919 | res = false; | |
21920 | ||
21921 | free (temp); | |
21922 | temp = NULL; | |
21923 | } | |
21924 | ||
21925 | free (pnotes); | |
21926 | ||
21927 | return res; | |
21928 | } | |
21929 | ||
21930 | static bool | |
21931 | process_corefile_note_segments (Filedata * filedata) | |
21932 | { | |
21933 | Elf_Internal_Phdr *segment; | |
21934 | unsigned int i; | |
21935 | bool res = true; | |
21936 | ||
21937 | if (! get_program_headers (filedata)) | |
21938 | return true; | |
21939 | ||
21940 | for (i = 0, segment = filedata->program_headers; | |
21941 | i < filedata->file_header.e_phnum; | |
21942 | i++, segment++) | |
21943 | { | |
21944 | if (segment->p_type == PT_NOTE) | |
21945 | if (! process_notes_at (filedata, NULL, segment->p_offset, | |
21946 | segment->p_filesz, segment->p_align)) | |
21947 | res = false; | |
21948 | } | |
21949 | ||
21950 | return res; | |
21951 | } | |
21952 | ||
21953 | static bool | |
21954 | process_v850_notes (Filedata * filedata, uint64_t offset, uint64_t length) | |
21955 | { | |
21956 | Elf_External_Note * pnotes; | |
21957 | Elf_External_Note * external; | |
21958 | char * end; | |
21959 | bool res = true; | |
21960 | ||
21961 | if (length <= 0) | |
21962 | return false; | |
21963 | ||
21964 | pnotes = (Elf_External_Note *) get_data (NULL, filedata, offset, 1, length, | |
21965 | _("v850 notes")); | |
21966 | if (pnotes == NULL) | |
21967 | return false; | |
21968 | ||
21969 | external = pnotes; | |
21970 | end = (char*) pnotes + length; | |
21971 | ||
21972 | printf (_("\nDisplaying contents of Renesas V850 notes section at offset" | |
21973 | " %#" PRIx64 " with length %#" PRIx64 ":\n"), | |
21974 | offset, length); | |
21975 | ||
21976 | while ((char *) external + sizeof (Elf_External_Note) < end) | |
21977 | { | |
21978 | Elf_External_Note * next; | |
21979 | Elf_Internal_Note inote; | |
21980 | ||
21981 | inote.type = BYTE_GET (external->type); | |
21982 | inote.namesz = BYTE_GET (external->namesz); | |
21983 | inote.namedata = external->name; | |
21984 | inote.descsz = BYTE_GET (external->descsz); | |
21985 | inote.descdata = inote.namedata + align_power (inote.namesz, 2); | |
21986 | inote.descpos = offset + (inote.descdata - (char *) pnotes); | |
21987 | ||
21988 | if (inote.descdata < (char *) pnotes || inote.descdata >= end) | |
21989 | { | |
21990 | warn (_("Corrupt note: name size is too big: %lx\n"), inote.namesz); | |
21991 | inote.descdata = inote.namedata; | |
21992 | inote.namesz = 0; | |
21993 | } | |
21994 | ||
21995 | next = (Elf_External_Note *) (inote.descdata + align_power (inote.descsz, 2)); | |
21996 | ||
21997 | if ( ((char *) next > end) | |
21998 | || ((char *) next < (char *) pnotes)) | |
21999 | { | |
22000 | warn (_("corrupt descsz found in note at offset %#tx\n"), | |
22001 | (char *) external - (char *) pnotes); | |
22002 | warn (_(" type: %#lx, namesize: %#lx, descsize: %#lx\n"), | |
22003 | inote.type, inote.namesz, inote.descsz); | |
22004 | break; | |
22005 | } | |
22006 | ||
22007 | external = next; | |
22008 | ||
22009 | /* Prevent out-of-bounds indexing. */ | |
22010 | if ( inote.namedata + inote.namesz > end | |
22011 | || inote.namedata + inote.namesz < inote.namedata) | |
22012 | { | |
22013 | warn (_("corrupt namesz found in note at offset %#zx\n"), | |
22014 | (char *) external - (char *) pnotes); | |
22015 | warn (_(" type: %#lx, namesize: %#lx, descsize: %#lx\n"), | |
22016 | inote.type, inote.namesz, inote.descsz); | |
22017 | break; | |
22018 | } | |
22019 | ||
22020 | printf (" %s: ", get_v850_elf_note_type (inote.type)); | |
22021 | ||
22022 | if (! print_v850_note (& inote)) | |
22023 | { | |
22024 | res = false; | |
22025 | printf ("<corrupt sizes: namesz: %#lx, descsz: %#lx>\n", | |
22026 | inote.namesz, inote.descsz); | |
22027 | } | |
22028 | } | |
22029 | ||
22030 | free (pnotes); | |
22031 | ||
22032 | return res; | |
22033 | } | |
22034 | ||
22035 | static bool | |
22036 | process_note_sections (Filedata * filedata) | |
22037 | { | |
22038 | Elf_Internal_Shdr *section; | |
22039 | size_t i; | |
22040 | unsigned int n = 0; | |
22041 | bool res = true; | |
22042 | ||
22043 | for (i = 0, section = filedata->section_headers; | |
22044 | i < filedata->file_header.e_shnum && section != NULL; | |
22045 | i++, section++) | |
22046 | { | |
22047 | if (section->sh_type == SHT_NOTE) | |
22048 | { | |
22049 | if (! process_notes_at (filedata, section, section->sh_offset, | |
22050 | section->sh_size, section->sh_addralign)) | |
22051 | res = false; | |
22052 | n++; | |
22053 | } | |
22054 | ||
22055 | if (( filedata->file_header.e_machine == EM_V800 | |
22056 | || filedata->file_header.e_machine == EM_V850 | |
22057 | || filedata->file_header.e_machine == EM_CYGNUS_V850) | |
22058 | && section->sh_type == SHT_RENESAS_INFO) | |
22059 | { | |
22060 | if (! process_v850_notes (filedata, section->sh_offset, | |
22061 | section->sh_size)) | |
22062 | res = false; | |
22063 | n++; | |
22064 | } | |
22065 | } | |
22066 | ||
22067 | if (n == 0) | |
22068 | /* Try processing NOTE segments instead. */ | |
22069 | return process_corefile_note_segments (filedata); | |
22070 | ||
22071 | return res; | |
22072 | } | |
22073 | ||
22074 | static bool | |
22075 | process_notes (Filedata * filedata) | |
22076 | { | |
22077 | /* If we have not been asked to display the notes then do nothing. */ | |
22078 | if (! do_notes) | |
22079 | return true; | |
22080 | ||
22081 | if (filedata->file_header.e_type != ET_CORE) | |
22082 | return process_note_sections (filedata); | |
22083 | ||
22084 | /* No program headers means no NOTE segment. */ | |
22085 | if (filedata->file_header.e_phnum > 0) | |
22086 | return process_corefile_note_segments (filedata); | |
22087 | ||
22088 | if (filedata->is_separate) | |
22089 | printf (_("No notes found in linked file '%s'.\n"), | |
22090 | filedata->file_name); | |
22091 | else | |
22092 | printf (_("No notes found file.\n")); | |
22093 | ||
22094 | return true; | |
22095 | } | |
22096 | ||
22097 | static unsigned char * | |
22098 | display_public_gnu_attributes (unsigned char * start, | |
22099 | const unsigned char * const end) | |
22100 | { | |
22101 | printf (_(" Unknown GNU attribute: %s\n"), start); | |
22102 | ||
22103 | start += strnlen ((char *) start, end - start); | |
22104 | display_raw_attribute (start, end); | |
22105 | ||
22106 | return (unsigned char *) end; | |
22107 | } | |
22108 | ||
22109 | static unsigned char * | |
22110 | display_generic_attribute (unsigned char * start, | |
22111 | unsigned int tag, | |
22112 | const unsigned char * const end) | |
22113 | { | |
22114 | if (tag == 0) | |
22115 | return (unsigned char *) end; | |
22116 | ||
22117 | return display_tag_value (tag, start, end); | |
22118 | } | |
22119 | ||
22120 | static bool | |
22121 | process_arch_specific (Filedata * filedata) | |
22122 | { | |
22123 | if (! do_arch) | |
22124 | return true; | |
22125 | ||
22126 | switch (filedata->file_header.e_machine) | |
22127 | { | |
22128 | case EM_ARC: | |
22129 | case EM_ARC_COMPACT: | |
22130 | case EM_ARC_COMPACT2: | |
22131 | return process_attributes (filedata, "ARC", SHT_ARC_ATTRIBUTES, | |
22132 | display_arc_attribute, | |
22133 | display_generic_attribute); | |
22134 | case EM_ARM: | |
22135 | return process_attributes (filedata, "aeabi", SHT_ARM_ATTRIBUTES, | |
22136 | display_arm_attribute, | |
22137 | display_generic_attribute); | |
22138 | ||
22139 | case EM_MIPS: | |
22140 | case EM_MIPS_RS3_LE: | |
22141 | return process_mips_specific (filedata); | |
22142 | ||
22143 | case EM_MSP430: | |
22144 | return process_attributes (filedata, "mspabi", SHT_MSP430_ATTRIBUTES, | |
22145 | display_msp430_attribute, | |
22146 | display_msp430_gnu_attribute); | |
22147 | ||
22148 | case EM_RISCV: | |
22149 | return process_attributes (filedata, "riscv", SHT_RISCV_ATTRIBUTES, | |
22150 | display_riscv_attribute, | |
22151 | display_generic_attribute); | |
22152 | ||
22153 | case EM_NDS32: | |
22154 | return process_nds32_specific (filedata); | |
22155 | ||
22156 | case EM_68K: | |
22157 | return process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL, | |
22158 | display_m68k_gnu_attribute); | |
22159 | ||
22160 | case EM_PPC: | |
22161 | case EM_PPC64: | |
22162 | return process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL, | |
22163 | display_power_gnu_attribute); | |
22164 | ||
22165 | case EM_S390: | |
22166 | case EM_S390_OLD: | |
22167 | return process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL, | |
22168 | display_s390_gnu_attribute); | |
22169 | ||
22170 | case EM_SPARC: | |
22171 | case EM_SPARC32PLUS: | |
22172 | case EM_SPARCV9: | |
22173 | return process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL, | |
22174 | display_sparc_gnu_attribute); | |
22175 | ||
22176 | case EM_TI_C6000: | |
22177 | return process_attributes (filedata, "c6xabi", SHT_C6000_ATTRIBUTES, | |
22178 | display_tic6x_attribute, | |
22179 | display_generic_attribute); | |
22180 | ||
22181 | case EM_CSKY: | |
22182 | return process_attributes (filedata, "csky", SHT_CSKY_ATTRIBUTES, | |
22183 | display_csky_attribute, NULL); | |
22184 | ||
22185 | default: | |
22186 | return process_attributes (filedata, "gnu", SHT_GNU_ATTRIBUTES, | |
22187 | display_public_gnu_attributes, | |
22188 | display_generic_attribute); | |
22189 | } | |
22190 | } | |
22191 | ||
22192 | static bool | |
22193 | get_file_header (Filedata * filedata) | |
22194 | { | |
22195 | /* Read in the identity array. */ | |
22196 | if (fread (filedata->file_header.e_ident, EI_NIDENT, 1, filedata->handle) != 1) | |
22197 | return false; | |
22198 | ||
22199 | /* Determine how to read the rest of the header. */ | |
22200 | switch (filedata->file_header.e_ident[EI_DATA]) | |
22201 | { | |
22202 | default: | |
22203 | case ELFDATANONE: | |
22204 | case ELFDATA2LSB: | |
22205 | byte_get = byte_get_little_endian; | |
22206 | byte_put = byte_put_little_endian; | |
22207 | break; | |
22208 | case ELFDATA2MSB: | |
22209 | byte_get = byte_get_big_endian; | |
22210 | byte_put = byte_put_big_endian; | |
22211 | break; | |
22212 | } | |
22213 | ||
22214 | /* For now we only support 32 bit and 64 bit ELF files. */ | |
22215 | is_32bit_elf = (filedata->file_header.e_ident[EI_CLASS] != ELFCLASS64); | |
22216 | ||
22217 | /* Read in the rest of the header. */ | |
22218 | if (is_32bit_elf) | |
22219 | { | |
22220 | Elf32_External_Ehdr ehdr32; | |
22221 | ||
22222 | if (fread (ehdr32.e_type, sizeof (ehdr32) - EI_NIDENT, 1, filedata->handle) != 1) | |
22223 | return false; | |
22224 | ||
22225 | filedata->file_header.e_type = BYTE_GET (ehdr32.e_type); | |
22226 | filedata->file_header.e_machine = BYTE_GET (ehdr32.e_machine); | |
22227 | filedata->file_header.e_version = BYTE_GET (ehdr32.e_version); | |
22228 | filedata->file_header.e_entry = BYTE_GET (ehdr32.e_entry); | |
22229 | filedata->file_header.e_phoff = BYTE_GET (ehdr32.e_phoff); | |
22230 | filedata->file_header.e_shoff = BYTE_GET (ehdr32.e_shoff); | |
22231 | filedata->file_header.e_flags = BYTE_GET (ehdr32.e_flags); | |
22232 | filedata->file_header.e_ehsize = BYTE_GET (ehdr32.e_ehsize); | |
22233 | filedata->file_header.e_phentsize = BYTE_GET (ehdr32.e_phentsize); | |
22234 | filedata->file_header.e_phnum = BYTE_GET (ehdr32.e_phnum); | |
22235 | filedata->file_header.e_shentsize = BYTE_GET (ehdr32.e_shentsize); | |
22236 | filedata->file_header.e_shnum = BYTE_GET (ehdr32.e_shnum); | |
22237 | filedata->file_header.e_shstrndx = BYTE_GET (ehdr32.e_shstrndx); | |
22238 | } | |
22239 | else | |
22240 | { | |
22241 | Elf64_External_Ehdr ehdr64; | |
22242 | ||
22243 | if (fread (ehdr64.e_type, sizeof (ehdr64) - EI_NIDENT, 1, filedata->handle) != 1) | |
22244 | return false; | |
22245 | ||
22246 | filedata->file_header.e_type = BYTE_GET (ehdr64.e_type); | |
22247 | filedata->file_header.e_machine = BYTE_GET (ehdr64.e_machine); | |
22248 | filedata->file_header.e_version = BYTE_GET (ehdr64.e_version); | |
22249 | filedata->file_header.e_entry = BYTE_GET (ehdr64.e_entry); | |
22250 | filedata->file_header.e_phoff = BYTE_GET (ehdr64.e_phoff); | |
22251 | filedata->file_header.e_shoff = BYTE_GET (ehdr64.e_shoff); | |
22252 | filedata->file_header.e_flags = BYTE_GET (ehdr64.e_flags); | |
22253 | filedata->file_header.e_ehsize = BYTE_GET (ehdr64.e_ehsize); | |
22254 | filedata->file_header.e_phentsize = BYTE_GET (ehdr64.e_phentsize); | |
22255 | filedata->file_header.e_phnum = BYTE_GET (ehdr64.e_phnum); | |
22256 | filedata->file_header.e_shentsize = BYTE_GET (ehdr64.e_shentsize); | |
22257 | filedata->file_header.e_shnum = BYTE_GET (ehdr64.e_shnum); | |
22258 | filedata->file_header.e_shstrndx = BYTE_GET (ehdr64.e_shstrndx); | |
22259 | } | |
22260 | ||
22261 | return true; | |
22262 | } | |
22263 | ||
22264 | static void | |
22265 | free_filedata (Filedata *filedata) | |
22266 | { | |
22267 | free (filedata->program_interpreter); | |
22268 | free (filedata->program_headers); | |
22269 | free (filedata->section_headers); | |
22270 | free (filedata->string_table); | |
22271 | free (filedata->dump.dump_sects); | |
22272 | free (filedata->dynamic_strings); | |
22273 | free (filedata->dynamic_symbols); | |
22274 | free (filedata->dynamic_syminfo); | |
22275 | free (filedata->dynamic_section); | |
22276 | ||
22277 | while (filedata->symtab_shndx_list != NULL) | |
22278 | { | |
22279 | elf_section_list *next = filedata->symtab_shndx_list->next; | |
22280 | free (filedata->symtab_shndx_list); | |
22281 | filedata->symtab_shndx_list = next; | |
22282 | } | |
22283 | ||
22284 | free (filedata->section_headers_groups); | |
22285 | ||
22286 | if (filedata->section_groups) | |
22287 | { | |
22288 | size_t i; | |
22289 | struct group_list * g; | |
22290 | struct group_list * next; | |
22291 | ||
22292 | for (i = 0; i < filedata->group_count; i++) | |
22293 | { | |
22294 | for (g = filedata->section_groups [i].root; g != NULL; g = next) | |
22295 | { | |
22296 | next = g->next; | |
22297 | free (g); | |
22298 | } | |
22299 | } | |
22300 | ||
22301 | free (filedata->section_groups); | |
22302 | } | |
22303 | memset (&filedata->section_headers, 0, | |
22304 | sizeof (Filedata) - offsetof (Filedata, section_headers)); | |
22305 | } | |
22306 | ||
22307 | static void | |
22308 | close_file (Filedata * filedata) | |
22309 | { | |
22310 | if (filedata) | |
22311 | { | |
22312 | if (filedata->handle) | |
22313 | fclose (filedata->handle); | |
22314 | free (filedata); | |
22315 | } | |
22316 | } | |
22317 | ||
22318 | void | |
22319 | close_debug_file (void * data) | |
22320 | { | |
22321 | free_filedata ((Filedata *) data); | |
22322 | close_file ((Filedata *) data); | |
22323 | } | |
22324 | ||
22325 | static Filedata * | |
22326 | open_file (const char * pathname, bool is_separate) | |
22327 | { | |
22328 | struct stat statbuf; | |
22329 | Filedata * filedata = NULL; | |
22330 | ||
22331 | if (stat (pathname, & statbuf) < 0 | |
22332 | || ! S_ISREG (statbuf.st_mode)) | |
22333 | goto fail; | |
22334 | ||
22335 | filedata = calloc (1, sizeof * filedata); | |
22336 | if (filedata == NULL) | |
22337 | goto fail; | |
22338 | ||
22339 | filedata->handle = fopen (pathname, "rb"); | |
22340 | if (filedata->handle == NULL) | |
22341 | goto fail; | |
22342 | ||
22343 | filedata->file_size = statbuf.st_size; | |
22344 | filedata->file_name = pathname; | |
22345 | filedata->is_separate = is_separate; | |
22346 | ||
22347 | if (! get_file_header (filedata)) | |
22348 | goto fail; | |
22349 | ||
22350 | if (!get_section_headers (filedata, false)) | |
22351 | goto fail; | |
22352 | ||
22353 | return filedata; | |
22354 | ||
22355 | fail: | |
22356 | if (filedata) | |
22357 | { | |
22358 | if (filedata->handle) | |
22359 | fclose (filedata->handle); | |
22360 | free (filedata); | |
22361 | } | |
22362 | return NULL; | |
22363 | } | |
22364 | ||
22365 | void * | |
22366 | open_debug_file (const char * pathname) | |
22367 | { | |
22368 | return open_file (pathname, true); | |
22369 | } | |
22370 | ||
22371 | static void | |
22372 | initialise_dump_sects (Filedata * filedata) | |
22373 | { | |
22374 | /* Initialise the dump_sects array from the cmdline_dump_sects array. | |
22375 | Note we do this even if cmdline_dump_sects is empty because we | |
22376 | must make sure that the dump_sets array is zeroed out before each | |
22377 | object file is processed. */ | |
22378 | if (filedata->dump.num_dump_sects > cmdline.num_dump_sects) | |
22379 | memset (filedata->dump.dump_sects, 0, | |
22380 | filedata->dump.num_dump_sects * sizeof (*filedata->dump.dump_sects)); | |
22381 | ||
22382 | if (cmdline.num_dump_sects > 0) | |
22383 | { | |
22384 | if (filedata->dump.num_dump_sects == 0) | |
22385 | /* A sneaky way of allocating the dump_sects array. */ | |
22386 | request_dump_bynumber (&filedata->dump, cmdline.num_dump_sects, 0); | |
22387 | ||
22388 | assert (filedata->dump.num_dump_sects >= cmdline.num_dump_sects); | |
22389 | memcpy (filedata->dump.dump_sects, cmdline.dump_sects, | |
22390 | cmdline.num_dump_sects * sizeof (*filedata->dump.dump_sects)); | |
22391 | } | |
22392 | } | |
22393 | ||
22394 | static bool | |
22395 | might_need_separate_debug_info (Filedata * filedata) | |
22396 | { | |
22397 | /* Debuginfo files do not need further separate file loading. */ | |
22398 | if (filedata->file_header.e_shstrndx == SHN_UNDEF) | |
22399 | return false; | |
22400 | ||
22401 | /* Since do_follow_links might be enabled by default, only treat it as an | |
22402 | indication that separate files should be loaded if setting it was a | |
22403 | deliberate user action. */ | |
22404 | if (DEFAULT_FOR_FOLLOW_LINKS == 0 && do_follow_links) | |
22405 | return true; | |
22406 | ||
22407 | if (process_links || do_syms || do_unwind | |
22408 | || dump_any_debugging || do_dump || do_debugging) | |
22409 | return true; | |
22410 | ||
22411 | return false; | |
22412 | } | |
22413 | ||
22414 | /* Process one ELF object file according to the command line options. | |
22415 | This file may actually be stored in an archive. The file is | |
22416 | positioned at the start of the ELF object. Returns TRUE if no | |
22417 | problems were encountered, FALSE otherwise. */ | |
22418 | ||
22419 | static bool | |
22420 | process_object (Filedata * filedata) | |
22421 | { | |
22422 | bool have_separate_files; | |
22423 | unsigned int i; | |
22424 | bool res; | |
22425 | ||
22426 | if (! get_file_header (filedata)) | |
22427 | { | |
22428 | error (_("%s: Failed to read file header\n"), filedata->file_name); | |
22429 | return false; | |
22430 | } | |
22431 | ||
22432 | /* Initialise per file variables. */ | |
22433 | for (i = ARRAY_SIZE (filedata->version_info); i--;) | |
22434 | filedata->version_info[i] = 0; | |
22435 | ||
22436 | for (i = ARRAY_SIZE (filedata->dynamic_info); i--;) | |
22437 | filedata->dynamic_info[i] = 0; | |
22438 | filedata->dynamic_info_DT_GNU_HASH = 0; | |
22439 | filedata->dynamic_info_DT_MIPS_XHASH = 0; | |
22440 | ||
22441 | /* Process the file. */ | |
22442 | if (show_name) | |
22443 | printf (_("\nFile: %s\n"), filedata->file_name); | |
22444 | ||
22445 | initialise_dump_sects (filedata); | |
22446 | ||
22447 | /* There may be some extensions in the first section header. Don't | |
22448 | bomb if we can't read it. */ | |
22449 | get_section_headers (filedata, true); | |
22450 | ||
22451 | if (! process_file_header (filedata)) | |
22452 | { | |
22453 | res = false; | |
22454 | goto out; | |
22455 | } | |
22456 | ||
22457 | /* Throw away the single section header read above, so that we | |
22458 | re-read the entire set. */ | |
22459 | free (filedata->section_headers); | |
22460 | filedata->section_headers = NULL; | |
22461 | ||
22462 | if (! process_section_headers (filedata)) | |
22463 | { | |
22464 | /* Without loaded section headers we cannot process lots of things. */ | |
22465 | do_unwind = do_version = do_dump = do_arch = false; | |
22466 | ||
22467 | if (! do_using_dynamic) | |
22468 | do_syms = do_dyn_syms = do_reloc = false; | |
22469 | } | |
22470 | ||
22471 | if (! process_section_groups (filedata)) | |
22472 | /* Without loaded section groups we cannot process unwind. */ | |
22473 | do_unwind = false; | |
22474 | ||
22475 | process_program_headers (filedata); | |
22476 | ||
22477 | res = process_dynamic_section (filedata); | |
22478 | ||
22479 | if (! process_relocs (filedata)) | |
22480 | res = false; | |
22481 | ||
22482 | if (! process_unwind (filedata)) | |
22483 | res = false; | |
22484 | ||
22485 | if (! process_symbol_table (filedata)) | |
22486 | res = false; | |
22487 | ||
22488 | if (! process_lto_symbol_tables (filedata)) | |
22489 | res = false; | |
22490 | ||
22491 | if (! process_syminfo (filedata)) | |
22492 | res = false; | |
22493 | ||
22494 | if (! process_version_sections (filedata)) | |
22495 | res = false; | |
22496 | ||
22497 | if (might_need_separate_debug_info (filedata)) | |
22498 | have_separate_files = load_separate_debug_files (filedata, filedata->file_name); | |
22499 | else | |
22500 | have_separate_files = false; | |
22501 | ||
22502 | if (! process_section_contents (filedata)) | |
22503 | res = false; | |
22504 | ||
22505 | if (have_separate_files) | |
22506 | { | |
22507 | separate_info * d; | |
22508 | ||
22509 | for (d = first_separate_info; d != NULL; d = d->next) | |
22510 | { | |
22511 | initialise_dump_sects (d->handle); | |
22512 | ||
22513 | if (process_links && ! process_file_header (d->handle)) | |
22514 | res = false; | |
22515 | else if (! process_section_headers (d->handle)) | |
22516 | res = false; | |
22517 | else if (! process_section_contents (d->handle)) | |
22518 | res = false; | |
22519 | else if (process_links) | |
22520 | { | |
22521 | if (! process_section_groups (d->handle)) | |
22522 | res = false; | |
22523 | process_program_headers (d->handle); | |
22524 | if (! process_dynamic_section (d->handle)) | |
22525 | res = false; | |
22526 | if (! process_relocs (d->handle)) | |
22527 | res = false; | |
22528 | if (! process_unwind (d->handle)) | |
22529 | res = false; | |
22530 | if (! process_symbol_table (d->handle)) | |
22531 | res = false; | |
22532 | if (! process_lto_symbol_tables (d->handle)) | |
22533 | res = false; | |
22534 | if (! process_syminfo (d->handle)) | |
22535 | res = false; | |
22536 | if (! process_version_sections (d->handle)) | |
22537 | res = false; | |
22538 | if (! process_notes (d->handle)) | |
22539 | res = false; | |
22540 | } | |
22541 | } | |
22542 | ||
22543 | /* The file handles are closed by the call to free_debug_memory() below. */ | |
22544 | } | |
22545 | ||
22546 | if (! process_notes (filedata)) | |
22547 | res = false; | |
22548 | ||
22549 | if (! process_gnu_liblist (filedata)) | |
22550 | res = false; | |
22551 | ||
22552 | if (! process_arch_specific (filedata)) | |
22553 | res = false; | |
22554 | ||
22555 | out: | |
22556 | free_filedata (filedata); | |
22557 | ||
22558 | free_debug_memory (); | |
22559 | ||
22560 | return res; | |
22561 | } | |
22562 | ||
22563 | /* Process an ELF archive. | |
22564 | On entry the file is positioned just after the ARMAG string. | |
22565 | Returns TRUE upon success, FALSE otherwise. */ | |
22566 | ||
22567 | static bool | |
22568 | process_archive (Filedata * filedata, bool is_thin_archive) | |
22569 | { | |
22570 | struct archive_info arch; | |
22571 | struct archive_info nested_arch; | |
22572 | size_t got; | |
22573 | bool ret = true; | |
22574 | ||
22575 | show_name = true; | |
22576 | ||
22577 | /* The ARCH structure is used to hold information about this archive. */ | |
22578 | arch.file_name = NULL; | |
22579 | arch.file = NULL; | |
22580 | arch.index_array = NULL; | |
22581 | arch.sym_table = NULL; | |
22582 | arch.longnames = NULL; | |
22583 | ||
22584 | /* The NESTED_ARCH structure is used as a single-item cache of information | |
22585 | about a nested archive (when members of a thin archive reside within | |
22586 | another regular archive file). */ | |
22587 | nested_arch.file_name = NULL; | |
22588 | nested_arch.file = NULL; | |
22589 | nested_arch.index_array = NULL; | |
22590 | nested_arch.sym_table = NULL; | |
22591 | nested_arch.longnames = NULL; | |
22592 | ||
22593 | if (setup_archive (&arch, filedata->file_name, filedata->handle, | |
22594 | filedata->file_size, is_thin_archive, | |
22595 | do_archive_index) != 0) | |
22596 | { | |
22597 | ret = false; | |
22598 | goto out; | |
22599 | } | |
22600 | ||
22601 | if (do_archive_index) | |
22602 | { | |
22603 | if (arch.sym_table == NULL) | |
22604 | error (_("%s: unable to dump the index as none was found\n"), | |
22605 | filedata->file_name); | |
22606 | else | |
22607 | { | |
22608 | uint64_t i, l; | |
22609 | uint64_t current_pos; | |
22610 | ||
22611 | printf (_("Index of archive %s: (%" PRIu64 " entries," | |
22612 | " %#" PRIx64 " bytes in the symbol table)\n"), | |
22613 | filedata->file_name, arch.index_num, | |
22614 | arch.sym_size); | |
22615 | ||
22616 | current_pos = ftell (filedata->handle); | |
22617 | ||
22618 | for (i = l = 0; i < arch.index_num; i++) | |
22619 | { | |
22620 | if (i == 0 | |
22621 | || (i > 0 && arch.index_array[i] != arch.index_array[i - 1])) | |
22622 | { | |
22623 | char * member_name | |
22624 | = get_archive_member_name_at (&arch, arch.index_array[i], | |
22625 | &nested_arch); | |
22626 | ||
22627 | if (member_name != NULL) | |
22628 | { | |
22629 | char * qualified_name | |
22630 | = make_qualified_name (&arch, &nested_arch, | |
22631 | member_name); | |
22632 | ||
22633 | if (qualified_name != NULL) | |
22634 | { | |
22635 | printf (_("Contents of binary %s at offset "), | |
22636 | qualified_name); | |
22637 | (void) print_vma (arch.index_array[i], PREFIX_HEX); | |
22638 | putchar ('\n'); | |
22639 | free (qualified_name); | |
22640 | } | |
22641 | free (member_name); | |
22642 | } | |
22643 | } | |
22644 | ||
22645 | if (l >= arch.sym_size) | |
22646 | { | |
22647 | error (_("%s: end of the symbol table reached " | |
22648 | "before the end of the index\n"), | |
22649 | filedata->file_name); | |
22650 | ret = false; | |
22651 | break; | |
22652 | } | |
22653 | /* PR 17531: file: 0b6630b2. */ | |
22654 | printf ("\t%.*s\n", | |
22655 | (int) (arch.sym_size - l), arch.sym_table + l); | |
22656 | l += strnlen (arch.sym_table + l, arch.sym_size - l) + 1; | |
22657 | } | |
22658 | ||
22659 | if (arch.uses_64bit_indices) | |
22660 | l = (l + 7) & ~ 7; | |
22661 | else | |
22662 | l += l & 1; | |
22663 | ||
22664 | if (l < arch.sym_size) | |
22665 | { | |
22666 | error (ngettext ("%s: %" PRId64 " byte remains in the symbol table, " | |
22667 | "but without corresponding entries in " | |
22668 | "the index table\n", | |
22669 | "%s: %" PRId64 " bytes remain in the symbol table, " | |
22670 | "but without corresponding entries in " | |
22671 | "the index table\n", | |
22672 | arch.sym_size - l), | |
22673 | filedata->file_name, arch.sym_size - l); | |
22674 | ret = false; | |
22675 | } | |
22676 | ||
22677 | if (fseek64 (filedata->handle, current_pos, SEEK_SET) != 0) | |
22678 | { | |
22679 | error (_("%s: failed to seek back to start of object files " | |
22680 | "in the archive\n"), | |
22681 | filedata->file_name); | |
22682 | ret = false; | |
22683 | goto out; | |
22684 | } | |
22685 | } | |
22686 | ||
22687 | if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections | |
22688 | && !do_segments && !do_header && !do_dump && !do_version | |
22689 | && !do_histogram && !do_debugging && !do_arch && !do_notes | |
22690 | && !do_section_groups && !do_dyn_syms) | |
22691 | { | |
22692 | ret = true; /* Archive index only. */ | |
22693 | goto out; | |
22694 | } | |
22695 | } | |
22696 | ||
22697 | while (1) | |
22698 | { | |
22699 | char * name; | |
22700 | size_t namelen; | |
22701 | char * qualified_name; | |
22702 | ||
22703 | /* Read the next archive header. */ | |
22704 | if (fseek64 (filedata->handle, arch.next_arhdr_offset, SEEK_SET) != 0) | |
22705 | { | |
22706 | error (_("%s: failed to seek to next archive header\n"), | |
22707 | arch.file_name); | |
22708 | ret = false; | |
22709 | break; | |
22710 | } | |
22711 | got = fread (&arch.arhdr, 1, sizeof arch.arhdr, filedata->handle); | |
22712 | if (got != sizeof arch.arhdr) | |
22713 | { | |
22714 | if (got == 0) | |
22715 | break; | |
22716 | /* PR 24049 - we cannot use filedata->file_name as this will | |
22717 | have already been freed. */ | |
22718 | error (_("%s: failed to read archive header\n"), arch.file_name); | |
22719 | ||
22720 | ret = false; | |
22721 | break; | |
22722 | } | |
22723 | if (memcmp (arch.arhdr.ar_fmag, ARFMAG, 2) != 0) | |
22724 | { | |
22725 | error (_("%s: did not find a valid archive header\n"), | |
22726 | arch.file_name); | |
22727 | ret = false; | |
22728 | break; | |
22729 | } | |
22730 | ||
22731 | arch.next_arhdr_offset += sizeof arch.arhdr; | |
22732 | ||
22733 | filedata->archive_file_size = strtoul (arch.arhdr.ar_size, NULL, 10); | |
22734 | ||
22735 | name = get_archive_member_name (&arch, &nested_arch); | |
22736 | if (name == NULL) | |
22737 | { | |
22738 | error (_("%s: bad archive file name\n"), arch.file_name); | |
22739 | ret = false; | |
22740 | break; | |
22741 | } | |
22742 | namelen = strlen (name); | |
22743 | ||
22744 | qualified_name = make_qualified_name (&arch, &nested_arch, name); | |
22745 | if (qualified_name == NULL) | |
22746 | { | |
22747 | error (_("%s: bad archive file name\n"), arch.file_name); | |
22748 | free (name); | |
22749 | ret = false; | |
22750 | break; | |
22751 | } | |
22752 | ||
22753 | if (is_thin_archive && arch.nested_member_origin == 0) | |
22754 | { | |
22755 | /* This is a proxy for an external member of a thin archive. */ | |
22756 | Filedata * member_filedata; | |
22757 | char * member_file_name = adjust_relative_path | |
22758 | (filedata->file_name, name, namelen); | |
22759 | ||
22760 | free (name); | |
22761 | if (member_file_name == NULL) | |
22762 | { | |
22763 | free (qualified_name); | |
22764 | ret = false; | |
22765 | break; | |
22766 | } | |
22767 | ||
22768 | member_filedata = open_file (member_file_name, false); | |
22769 | if (member_filedata == NULL) | |
22770 | { | |
22771 | error (_("Input file '%s' is not readable.\n"), member_file_name); | |
22772 | free (member_file_name); | |
22773 | free (qualified_name); | |
22774 | ret = false; | |
22775 | break; | |
22776 | } | |
22777 | ||
22778 | filedata->archive_file_offset = arch.nested_member_origin; | |
22779 | member_filedata->file_name = qualified_name; | |
22780 | ||
22781 | /* The call to process_object() expects the file to be at the beginning. */ | |
22782 | rewind (member_filedata->handle); | |
22783 | ||
22784 | if (! process_object (member_filedata)) | |
22785 | ret = false; | |
22786 | ||
22787 | close_file (member_filedata); | |
22788 | free (member_file_name); | |
22789 | } | |
22790 | else if (is_thin_archive) | |
22791 | { | |
22792 | Filedata thin_filedata; | |
22793 | ||
22794 | memset (&thin_filedata, 0, sizeof (thin_filedata)); | |
22795 | ||
22796 | /* PR 15140: Allow for corrupt thin archives. */ | |
22797 | if (nested_arch.file == NULL) | |
22798 | { | |
22799 | error (_("%s: contains corrupt thin archive: %s\n"), | |
22800 | qualified_name, name); | |
22801 | free (qualified_name); | |
22802 | free (name); | |
22803 | ret = false; | |
22804 | break; | |
22805 | } | |
22806 | free (name); | |
22807 | ||
22808 | /* This is a proxy for a member of a nested archive. */ | |
22809 | filedata->archive_file_offset | |
22810 | = arch.nested_member_origin + sizeof arch.arhdr; | |
22811 | ||
22812 | /* The nested archive file will have been opened and setup by | |
22813 | get_archive_member_name. */ | |
22814 | if (fseek64 (nested_arch.file, filedata->archive_file_offset, | |
22815 | SEEK_SET) != 0) | |
22816 | { | |
22817 | error (_("%s: failed to seek to archive member.\n"), | |
22818 | nested_arch.file_name); | |
22819 | free (qualified_name); | |
22820 | ret = false; | |
22821 | break; | |
22822 | } | |
22823 | ||
22824 | thin_filedata.handle = nested_arch.file; | |
22825 | thin_filedata.file_name = qualified_name; | |
22826 | ||
22827 | if (! process_object (& thin_filedata)) | |
22828 | ret = false; | |
22829 | } | |
22830 | else | |
22831 | { | |
22832 | free (name); | |
22833 | filedata->archive_file_offset = arch.next_arhdr_offset; | |
22834 | filedata->file_name = qualified_name; | |
22835 | if (! process_object (filedata)) | |
22836 | ret = false; | |
22837 | arch.next_arhdr_offset += (filedata->archive_file_size + 1) & -2; | |
22838 | /* Stop looping with "negative" archive_file_size. */ | |
22839 | if (arch.next_arhdr_offset < filedata->archive_file_size) | |
22840 | arch.next_arhdr_offset = -1ul; | |
22841 | } | |
22842 | ||
22843 | free (qualified_name); | |
22844 | } | |
22845 | ||
22846 | out: | |
22847 | if (nested_arch.file != NULL) | |
22848 | fclose (nested_arch.file); | |
22849 | release_archive (&nested_arch); | |
22850 | release_archive (&arch); | |
22851 | ||
22852 | return ret; | |
22853 | } | |
22854 | ||
22855 | static bool | |
22856 | process_file (char * file_name) | |
22857 | { | |
22858 | Filedata * filedata = NULL; | |
22859 | struct stat statbuf; | |
22860 | char armag[SARMAG]; | |
22861 | bool ret = true; | |
22862 | ||
22863 | if (stat (file_name, &statbuf) < 0) | |
22864 | { | |
22865 | if (errno == ENOENT) | |
22866 | error (_("'%s': No such file\n"), file_name); | |
22867 | else | |
22868 | error (_("Could not locate '%s'. System error message: %s\n"), | |
22869 | file_name, strerror (errno)); | |
22870 | return false; | |
22871 | } | |
22872 | ||
22873 | if (! S_ISREG (statbuf.st_mode)) | |
22874 | { | |
22875 | error (_("'%s' is not an ordinary file\n"), file_name); | |
22876 | return false; | |
22877 | } | |
22878 | ||
22879 | filedata = calloc (1, sizeof * filedata); | |
22880 | if (filedata == NULL) | |
22881 | { | |
22882 | error (_("Out of memory allocating file data structure\n")); | |
22883 | return false; | |
22884 | } | |
22885 | ||
22886 | filedata->file_name = file_name; | |
22887 | filedata->handle = fopen (file_name, "rb"); | |
22888 | if (filedata->handle == NULL) | |
22889 | { | |
22890 | error (_("Input file '%s' is not readable.\n"), file_name); | |
22891 | free (filedata); | |
22892 | return false; | |
22893 | } | |
22894 | ||
22895 | if (fread (armag, SARMAG, 1, filedata->handle) != 1) | |
22896 | { | |
22897 | error (_("%s: Failed to read file's magic number\n"), file_name); | |
22898 | fclose (filedata->handle); | |
22899 | free (filedata); | |
22900 | return false; | |
22901 | } | |
22902 | ||
22903 | filedata->file_size = statbuf.st_size; | |
22904 | filedata->is_separate = false; | |
22905 | ||
22906 | if (memcmp (armag, ARMAG, SARMAG) == 0) | |
22907 | { | |
22908 | if (! process_archive (filedata, false)) | |
22909 | ret = false; | |
22910 | } | |
22911 | else if (memcmp (armag, ARMAGT, SARMAG) == 0) | |
22912 | { | |
22913 | if ( ! process_archive (filedata, true)) | |
22914 | ret = false; | |
22915 | } | |
22916 | else | |
22917 | { | |
22918 | if (do_archive_index && !check_all) | |
22919 | error (_("File %s is not an archive so its index cannot be displayed.\n"), | |
22920 | file_name); | |
22921 | ||
22922 | rewind (filedata->handle); | |
22923 | filedata->archive_file_size = filedata->archive_file_offset = 0; | |
22924 | ||
22925 | if (! process_object (filedata)) | |
22926 | ret = false; | |
22927 | } | |
22928 | ||
22929 | fclose (filedata->handle); | |
22930 | free (filedata->section_headers); | |
22931 | free (filedata->program_headers); | |
22932 | free (filedata->string_table); | |
22933 | free (filedata->dump.dump_sects); | |
22934 | free (filedata); | |
22935 | ||
22936 | free (ba_cache.strtab); | |
22937 | ba_cache.strtab = NULL; | |
22938 | free (ba_cache.symtab); | |
22939 | ba_cache.symtab = NULL; | |
22940 | ba_cache.filedata = NULL; | |
22941 | ||
22942 | return ret; | |
22943 | } | |
22944 | ||
22945 | #ifdef SUPPORT_DISASSEMBLY | |
22946 | /* Needed by the i386 disassembler. For extra credit, someone could | |
22947 | fix this so that we insert symbolic addresses here, esp for GOT/PLT | |
22948 | symbols. */ | |
22949 | ||
22950 | void | |
22951 | print_address (unsigned int addr, FILE * outfile) | |
22952 | { | |
22953 | fprintf (outfile,"0x%8.8x", addr); | |
22954 | } | |
22955 | ||
22956 | /* Needed by the i386 disassembler. */ | |
22957 | ||
22958 | void | |
22959 | db_task_printsym (unsigned int addr) | |
22960 | { | |
22961 | print_address (addr, stderr); | |
22962 | } | |
22963 | #endif | |
22964 | ||
22965 | int | |
22966 | main (int argc, char ** argv) | |
22967 | { | |
22968 | int err; | |
22969 | ||
22970 | #ifdef HAVE_LC_MESSAGES | |
22971 | setlocale (LC_MESSAGES, ""); | |
22972 | #endif | |
22973 | setlocale (LC_CTYPE, ""); | |
22974 | bindtextdomain (PACKAGE, LOCALEDIR); | |
22975 | textdomain (PACKAGE); | |
22976 | ||
22977 | expandargv (&argc, &argv); | |
22978 | ||
22979 | parse_args (& cmdline, argc, argv); | |
22980 | ||
22981 | if (optind < (argc - 1)) | |
22982 | /* When displaying information for more than one file, | |
22983 | prefix the information with the file name. */ | |
22984 | show_name = true; | |
22985 | else if (optind >= argc) | |
22986 | { | |
22987 | /* Ensure that the warning is always displayed. */ | |
22988 | do_checks = true; | |
22989 | ||
22990 | warn (_("Nothing to do.\n")); | |
22991 | usage (stderr); | |
22992 | } | |
22993 | ||
22994 | err = false; | |
22995 | while (optind < argc) | |
22996 | if (! process_file (argv[optind++])) | |
22997 | err = true; | |
22998 | ||
22999 | free (cmdline.dump_sects); | |
23000 | ||
23001 | free (dump_ctf_symtab_name); | |
23002 | free (dump_ctf_strtab_name); | |
23003 | free (dump_ctf_parent_name); | |
23004 | ||
23005 | return err ? EXIT_FAILURE : EXIT_SUCCESS; | |
23006 | } |