]>
Commit | Line | Data |
---|---|---|
1 | /* readelf.c -- display contents of an ELF format file | |
2 | Copyright (C) 1998-2025 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/kvx.h" | |
125 | #include "elf/lm32.h" | |
126 | #include "elf/iq2000.h" | |
127 | #include "elf/m32c.h" | |
128 | #include "elf/m32r.h" | |
129 | #include "elf/m68k.h" | |
130 | #include "elf/m68hc11.h" | |
131 | #include "elf/s12z.h" | |
132 | #include "elf/mcore.h" | |
133 | #include "elf/mep.h" | |
134 | #include "elf/metag.h" | |
135 | #include "elf/microblaze.h" | |
136 | #include "elf/mips.h" | |
137 | #include "elf/mmix.h" | |
138 | #include "elf/mn10200.h" | |
139 | #include "elf/mn10300.h" | |
140 | #include "elf/moxie.h" | |
141 | #include "elf/mt.h" | |
142 | #include "elf/msp430.h" | |
143 | #include "elf/nds32.h" | |
144 | #include "elf/nfp.h" | |
145 | #include "elf/nios2.h" | |
146 | #include "elf/or1k.h" | |
147 | #include "elf/pj.h" | |
148 | #include "elf/ppc.h" | |
149 | #include "elf/ppc64.h" | |
150 | #include "elf/pru.h" | |
151 | #include "elf/riscv.h" | |
152 | #include "elf/rl78.h" | |
153 | #include "elf/rx.h" | |
154 | #include "elf/s390.h" | |
155 | #include "elf/score.h" | |
156 | #include "elf/sh.h" | |
157 | #include "elf/sparc.h" | |
158 | #include "elf/spu.h" | |
159 | #include "elf/tic6x.h" | |
160 | #include "elf/tilegx.h" | |
161 | #include "elf/tilepro.h" | |
162 | #include "elf/v850.h" | |
163 | #include "elf/vax.h" | |
164 | #include "elf/visium.h" | |
165 | #include "elf/wasm32.h" | |
166 | #include "elf/x86-64.h" | |
167 | #include "elf/xgate.h" | |
168 | #include "elf/xstormy16.h" | |
169 | #include "elf/xtensa.h" | |
170 | #include "elf/z80.h" | |
171 | #include "elf/loongarch.h" | |
172 | #include "elf/bpf.h" | |
173 | ||
174 | #include "getopt.h" | |
175 | #include "libiberty.h" | |
176 | #include "safe-ctype.h" | |
177 | #include "filenames.h" | |
178 | ||
179 | #ifndef offsetof | |
180 | #define offsetof(TYPE, MEMBER) ((size_t) &(((TYPE *) 0)->MEMBER)) | |
181 | #endif | |
182 | ||
183 | typedef struct elf_section_list | |
184 | { | |
185 | Elf_Internal_Shdr * hdr; | |
186 | struct elf_section_list * next; | |
187 | } elf_section_list; | |
188 | ||
189 | /* Flag bits indicating particular types of dump. */ | |
190 | #define HEX_DUMP (1 << 0) /* The -x command line switch. */ | |
191 | #ifdef SUPPORT_DISASSEMBLY | |
192 | #define DISASS_DUMP (1 << 1) /* The -i command line switch. */ | |
193 | #endif | |
194 | #define DEBUG_DUMP (1 << 2) /* The -w command line switch. */ | |
195 | #define STRING_DUMP (1 << 3) /* The -p command line switch. */ | |
196 | #define RELOC_DUMP (1 << 4) /* The -R command line switch. */ | |
197 | #define CTF_DUMP (1 << 5) /* The --ctf command line switch. */ | |
198 | #define SFRAME_DUMP (1 << 6) /* The --sframe command line switch. */ | |
199 | #define AUTO_DUMP (1 << 7) /* The -j command line switch. */ | |
200 | ||
201 | typedef unsigned char dump_type; | |
202 | ||
203 | /* A linked list of the section names for which dumps were requested. */ | |
204 | struct dump_list_entry | |
205 | { | |
206 | char * name; | |
207 | dump_type type; | |
208 | struct dump_list_entry * next; | |
209 | }; | |
210 | ||
211 | /* A dynamic array of flags indicating for which sections a dump | |
212 | has been requested via command line switches. */ | |
213 | struct dump_data | |
214 | { | |
215 | dump_type * dump_sects; | |
216 | unsigned int num_dump_sects; | |
217 | }; | |
218 | ||
219 | static struct dump_data cmdline; | |
220 | ||
221 | static struct dump_list_entry * dump_sects_byname; | |
222 | ||
223 | char * program_name = "readelf"; | |
224 | ||
225 | static bool show_name = false; | |
226 | static bool do_dynamic = false; | |
227 | static bool do_syms = false; | |
228 | static bool do_dyn_syms = false; | |
229 | static bool do_lto_syms = false; | |
230 | static bool do_reloc = false; | |
231 | static bool do_sections = false; | |
232 | static bool do_section_groups = false; | |
233 | static bool do_section_details = false; | |
234 | static bool do_segments = false; | |
235 | static bool do_unwind = false; | |
236 | static bool do_using_dynamic = false; | |
237 | static bool do_header = false; | |
238 | static bool do_dump = false; | |
239 | static bool do_version = false; | |
240 | static bool do_histogram = false; | |
241 | static bool do_debugging = false; | |
242 | static bool do_ctf = false; | |
243 | static bool do_sframe = false; | |
244 | static bool do_arch = false; | |
245 | static bool do_notes = false; | |
246 | static bool do_archive_index = false; | |
247 | static bool check_all = false; | |
248 | static bool is_32bit_elf = false; | |
249 | static bool decompress_dumps = false; | |
250 | static bool do_not_show_symbol_truncation = false; | |
251 | static bool do_demangle = false; /* Pretty print C++ symbol names. */ | |
252 | static bool process_links = false; | |
253 | static bool dump_any_debugging = false; | |
254 | static bool extra_sym_info = false; | |
255 | static int demangle_flags = DMGL_ANSI | DMGL_PARAMS; | |
256 | static int sym_base = 0; | |
257 | ||
258 | static char *dump_ctf_parent_name; | |
259 | static char *dump_ctf_symtab_name; | |
260 | static char *dump_ctf_strtab_name; | |
261 | ||
262 | struct group_list | |
263 | { | |
264 | struct group_list * next; | |
265 | unsigned int section_index; | |
266 | }; | |
267 | ||
268 | struct group | |
269 | { | |
270 | struct group_list * root; | |
271 | unsigned int group_index; | |
272 | }; | |
273 | ||
274 | typedef struct filedata | |
275 | { | |
276 | const char * file_name; | |
277 | bool is_separate; | |
278 | FILE * handle; | |
279 | uint64_t file_size; | |
280 | Elf_Internal_Ehdr file_header; | |
281 | uint64_t archive_file_offset; | |
282 | uint64_t archive_file_size; | |
283 | /* Everything below this point is cleared out by free_filedata. */ | |
284 | Elf_Internal_Shdr * section_headers; | |
285 | Elf_Internal_Phdr * program_headers; | |
286 | char * string_table; | |
287 | uint64_t string_table_length; | |
288 | uint64_t dynamic_addr; | |
289 | uint64_t dynamic_size; | |
290 | uint64_t dynamic_nent; | |
291 | Elf_Internal_Dyn * dynamic_section; | |
292 | Elf_Internal_Shdr * dynamic_strtab_section; | |
293 | char * dynamic_strings; | |
294 | uint64_t dynamic_strings_length; | |
295 | Elf_Internal_Shdr * dynamic_symtab_section; | |
296 | uint64_t num_dynamic_syms; | |
297 | Elf_Internal_Sym * dynamic_symbols; | |
298 | uint64_t version_info[16]; | |
299 | unsigned int dynamic_syminfo_nent; | |
300 | Elf_Internal_Syminfo * dynamic_syminfo; | |
301 | uint64_t dynamic_syminfo_offset; | |
302 | uint64_t nbuckets; | |
303 | uint64_t nchains; | |
304 | uint64_t * buckets; | |
305 | uint64_t * chains; | |
306 | uint64_t ngnubuckets; | |
307 | uint64_t ngnuchains; | |
308 | uint64_t * gnubuckets; | |
309 | uint64_t * gnuchains; | |
310 | uint64_t * mipsxlat; | |
311 | uint64_t gnusymidx; | |
312 | char * program_interpreter; | |
313 | uint64_t dynamic_info[DT_RELRENT + 1]; | |
314 | uint64_t dynamic_info_DT_GNU_HASH; | |
315 | uint64_t dynamic_info_DT_MIPS_XHASH; | |
316 | elf_section_list * symtab_shndx_list; | |
317 | size_t group_count; | |
318 | struct group * section_groups; | |
319 | struct group ** section_headers_groups; | |
320 | /* A dynamic array of flags indicating for which sections a dump of | |
321 | some kind has been requested. It is reset on a per-object file | |
322 | basis and then initialised from the cmdline_dump_sects array, | |
323 | the results of interpreting the -w switch, and the | |
324 | dump_sects_byname list. */ | |
325 | struct dump_data dump; | |
326 | } Filedata; | |
327 | ||
328 | /* How to print a vma value. */ | |
329 | typedef enum print_mode | |
330 | { | |
331 | HEX, | |
332 | HEX_5, | |
333 | DEC, | |
334 | DEC_5, | |
335 | UNSIGNED, | |
336 | UNSIGNED_5, | |
337 | PREFIX_HEX, | |
338 | PREFIX_HEX_5, | |
339 | FULL_HEX, | |
340 | LONG_HEX, | |
341 | ZERO_HEX, | |
342 | OCTAL, | |
343 | OCTAL_5 | |
344 | } | |
345 | print_mode; | |
346 | ||
347 | typedef enum unicode_display_type | |
348 | { | |
349 | unicode_default = 0, | |
350 | unicode_locale, | |
351 | unicode_escape, | |
352 | unicode_hex, | |
353 | unicode_highlight, | |
354 | unicode_invalid | |
355 | } unicode_display_type; | |
356 | ||
357 | static unicode_display_type unicode_display = unicode_default; | |
358 | ||
359 | typedef enum | |
360 | { | |
361 | reltype_unknown, | |
362 | reltype_rel, | |
363 | reltype_rela, | |
364 | reltype_relr | |
365 | } relocation_type; | |
366 | ||
367 | /* Versioned symbol info. */ | |
368 | enum versioned_symbol_info | |
369 | { | |
370 | symbol_undefined, | |
371 | symbol_hidden, | |
372 | symbol_public | |
373 | }; | |
374 | ||
375 | static int | |
376 | fseek64 (FILE *stream, int64_t offset, int whence) | |
377 | { | |
378 | #if defined (HAVE_FSEEKO64) | |
379 | off64_t o = offset; | |
380 | if (o != offset) | |
381 | { | |
382 | errno = EINVAL; | |
383 | return -1; | |
384 | } | |
385 | return fseeko64 (stream, o, whence); | |
386 | #elif defined (HAVE_FSEEKO) | |
387 | off_t o = offset; | |
388 | if (o != offset) | |
389 | { | |
390 | errno = EINVAL; | |
391 | return -1; | |
392 | } | |
393 | return fseeko (stream, o, whence); | |
394 | #else | |
395 | long o = offset; | |
396 | if (o != offset) | |
397 | { | |
398 | errno = EINVAL; | |
399 | return -1; | |
400 | } | |
401 | return fseek (stream, o, whence); | |
402 | #endif | |
403 | } | |
404 | ||
405 | static const char * get_symbol_version_string | |
406 | (Filedata *, bool, const char *, size_t, unsigned, | |
407 | Elf_Internal_Sym *, enum versioned_symbol_info *, unsigned short *); | |
408 | ||
409 | static bool process_notes_at | |
410 | (Filedata *, Elf_Internal_Shdr *, uint64_t, uint64_t, uint64_t); | |
411 | ||
412 | #define UNKNOWN -1 | |
413 | ||
414 | static inline const char * | |
415 | section_name (const Filedata *filedata, const Elf_Internal_Shdr *hdr) | |
416 | { | |
417 | return filedata->string_table + hdr->sh_name; | |
418 | } | |
419 | ||
420 | static inline bool | |
421 | section_name_valid (const Filedata *filedata, const Elf_Internal_Shdr *hdr) | |
422 | { | |
423 | return (filedata != NULL | |
424 | && hdr != NULL | |
425 | && filedata->string_table != NULL | |
426 | && hdr->sh_name < filedata->string_table_length); | |
427 | } | |
428 | ||
429 | /* Returns true if the given index is real/valid. Note: "real" here | |
430 | means "references a real section in the section header" and not | |
431 | "is a valid section index as per the ELF standard". */ | |
432 | ||
433 | static inline bool | |
434 | section_index_real (const Filedata *filedata, unsigned int ndx) | |
435 | { | |
436 | return (filedata != NULL | |
437 | && filedata->section_headers != NULL | |
438 | && ndx < filedata->file_header.e_shnum | |
439 | && ndx > 0); | |
440 | } | |
441 | ||
442 | #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */ | |
443 | ||
444 | static inline bool | |
445 | valid_symbol_name (const char *strtab, size_t strtab_size, uint64_t offset) | |
446 | { | |
447 | return strtab != NULL && offset < strtab_size; | |
448 | } | |
449 | ||
450 | static inline bool | |
451 | valid_dynamic_name (const Filedata *filedata, uint64_t offset) | |
452 | { | |
453 | return valid_symbol_name (filedata->dynamic_strings, | |
454 | filedata->dynamic_strings_length, offset); | |
455 | } | |
456 | ||
457 | /* GET_DYNAMIC_NAME asssumes that VALID_DYNAMIC_NAME has | |
458 | already been called and verified that the string exists. */ | |
459 | static inline const char * | |
460 | get_dynamic_name (const Filedata *filedata, size_t offset) | |
461 | { | |
462 | return filedata->dynamic_strings + offset; | |
463 | } | |
464 | ||
465 | #define REMOVE_ARCH_BITS(ADDR) \ | |
466 | do \ | |
467 | { \ | |
468 | if (filedata->file_header.e_machine == EM_ARM) \ | |
469 | (ADDR) &= ~1; \ | |
470 | } \ | |
471 | while (0) | |
472 | ||
473 | /* Get the correct GNU hash section name. */ | |
474 | #define GNU_HASH_SECTION_NAME(filedata) \ | |
475 | filedata->dynamic_info_DT_MIPS_XHASH ? ".MIPS.xhash" : ".gnu.hash" | |
476 | \f | |
477 | /* Retrieve NMEMB structures, each SIZE bytes long from FILEDATA starting at | |
478 | OFFSET + the offset of the current archive member, if we are examining an | |
479 | archive. Put the retrieved data into VAR, if it is not NULL. Otherwise | |
480 | allocate a buffer using malloc and fill that. In either case return the | |
481 | pointer to the start of the retrieved data or NULL if something went wrong. | |
482 | If something does go wrong and REASON is not NULL then emit an error | |
483 | message using REASON as part of the context. */ | |
484 | ||
485 | static void * | |
486 | get_data (void *var, | |
487 | Filedata *filedata, | |
488 | uint64_t offset, | |
489 | uint64_t size, | |
490 | uint64_t nmemb, | |
491 | const char *reason) | |
492 | { | |
493 | void * mvar; | |
494 | uint64_t amt = size * nmemb; | |
495 | ||
496 | if (size == 0 || nmemb == 0) | |
497 | return NULL; | |
498 | ||
499 | /* If size_t is smaller than uint64_t, eg because you are building | |
500 | on a 32-bit host, then make sure that when the sizes are cast to | |
501 | size_t no information is lost. */ | |
502 | if ((size_t) size != size | |
503 | || (size_t) nmemb != nmemb | |
504 | || (size_t) amt != amt | |
505 | || amt / size != nmemb | |
506 | || (size_t) amt + 1 == 0) | |
507 | { | |
508 | if (reason) | |
509 | error (_("Size overflow prevents reading %" PRIu64 | |
510 | " elements of size %" PRIu64 " for %s\n"), | |
511 | nmemb, size, reason); | |
512 | return NULL; | |
513 | } | |
514 | ||
515 | /* Be kind to memory checkers (eg valgrind, address sanitizer) by not | |
516 | attempting to allocate memory when the read is bound to fail. */ | |
517 | if (filedata->archive_file_offset > filedata->file_size | |
518 | || offset > filedata->file_size - filedata->archive_file_offset | |
519 | || amt > filedata->file_size - filedata->archive_file_offset - offset) | |
520 | { | |
521 | if (reason) | |
522 | error (_("Reading %" PRIu64 " bytes extends past end of file for %s\n"), | |
523 | amt, reason); | |
524 | return NULL; | |
525 | } | |
526 | ||
527 | if (fseek64 (filedata->handle, filedata->archive_file_offset + offset, | |
528 | SEEK_SET)) | |
529 | { | |
530 | if (reason) | |
531 | error (_("Unable to seek to %#" PRIx64 " for %s\n"), | |
532 | filedata->archive_file_offset + offset, reason); | |
533 | return NULL; | |
534 | } | |
535 | ||
536 | mvar = var; | |
537 | if (mvar == NULL) | |
538 | { | |
539 | /* + 1 so that we can '\0' terminate invalid string table sections. */ | |
540 | mvar = malloc ((size_t) amt + 1); | |
541 | ||
542 | if (mvar == NULL) | |
543 | { | |
544 | if (reason) | |
545 | error (_("Out of memory allocating %" PRIu64 " bytes for %s\n"), | |
546 | amt, reason); | |
547 | return NULL; | |
548 | } | |
549 | ||
550 | ((char *) mvar)[amt] = '\0'; | |
551 | } | |
552 | ||
553 | if (fread (mvar, (size_t) size, (size_t) nmemb, filedata->handle) != nmemb) | |
554 | { | |
555 | if (reason) | |
556 | error (_("Unable to read in %" PRIu64 " bytes of %s\n"), | |
557 | amt, reason); | |
558 | if (mvar != var) | |
559 | free (mvar); | |
560 | return NULL; | |
561 | } | |
562 | ||
563 | return mvar; | |
564 | } | |
565 | ||
566 | /* Print a VMA value in the MODE specified. | |
567 | Returns the number of characters displayed. */ | |
568 | ||
569 | static unsigned int | |
570 | print_vma (uint64_t vma, print_mode mode) | |
571 | { | |
572 | unsigned int nc = 0; | |
573 | ||
574 | switch (mode) | |
575 | { | |
576 | case FULL_HEX: | |
577 | nc = printf ("0x"); | |
578 | /* Fall through. */ | |
579 | case LONG_HEX: | |
580 | if (!is_32bit_elf) | |
581 | return nc + printf ("%16.16" PRIx64, vma); | |
582 | return nc + printf ("%8.8" PRIx64, vma); | |
583 | ||
584 | case ZERO_HEX: | |
585 | if (is_32bit_elf) | |
586 | return printf ("%08" PRIx64, vma); | |
587 | return printf ("%016" PRIx64, vma); | |
588 | ||
589 | case DEC_5: | |
590 | if (vma <= 99999) | |
591 | return printf ("%5" PRId64, vma); | |
592 | /* Fall through. */ | |
593 | case PREFIX_HEX: | |
594 | nc = printf ("0x"); | |
595 | /* Fall through. */ | |
596 | case HEX: | |
597 | return nc + printf ("%" PRIx64, vma); | |
598 | ||
599 | case PREFIX_HEX_5: | |
600 | nc = printf ("0x"); | |
601 | /* Fall through. */ | |
602 | case HEX_5: | |
603 | return nc + printf ("%05" PRIx64, vma); | |
604 | ||
605 | case DEC: | |
606 | return printf ("%" PRId64, vma); | |
607 | ||
608 | case UNSIGNED: | |
609 | return printf ("%" PRIu64, vma); | |
610 | ||
611 | case UNSIGNED_5: | |
612 | return printf ("%5" PRIu64, vma); | |
613 | ||
614 | case OCTAL: | |
615 | return printf ("%" PRIo64, vma); | |
616 | ||
617 | case OCTAL_5: | |
618 | return printf ("%5" PRIo64, vma); | |
619 | ||
620 | default: | |
621 | /* FIXME: Report unrecognised mode ? */ | |
622 | return 0; | |
623 | } | |
624 | } | |
625 | ||
626 | ||
627 | /* Display a symbol on stdout. Handles the display of control characters and | |
628 | multibye characters (assuming the host environment supports them). | |
629 | ||
630 | Display at most abs(WIDTH) characters, truncating as necessary, | |
631 | unless do_wide or extra_sym_info is true. | |
632 | ||
633 | If truncation will happen and do_not_show_symbol_truncation is FALSE then display | |
634 | abs(WIDTH) - 5 characters followed by "[...]". | |
635 | ||
636 | If WIDTH is negative then ensure that the output is at least (- WIDTH) characters, | |
637 | padding as necessary. | |
638 | ||
639 | Returns the number of emitted characters. */ | |
640 | ||
641 | static unsigned int | |
642 | print_symbol_name (signed int width, const char * symbol) | |
643 | { | |
644 | bool extra_padding = false; | |
645 | bool do_dots = false; | |
646 | signed int num_printed = 0; | |
647 | #ifdef HAVE_MBSTATE_T | |
648 | mbstate_t state; | |
649 | #endif | |
650 | unsigned int width_remaining; | |
651 | const void * alloced_symbol = NULL; | |
652 | ||
653 | if (width < 0) | |
654 | { | |
655 | /* Keep the width positive. This helps the code below. */ | |
656 | width = - width; | |
657 | extra_padding = true; | |
658 | } | |
659 | else if (width == 0) | |
660 | return 0; | |
661 | ||
662 | if (do_wide || extra_sym_info) | |
663 | /* Set the remaining width to a very large value. | |
664 | This simplifies the code below. */ | |
665 | width_remaining = INT_MAX; | |
666 | else | |
667 | { | |
668 | width_remaining = width; | |
669 | ||
670 | if (! do_not_show_symbol_truncation | |
671 | && (int) strlen (symbol) > width) | |
672 | { | |
673 | width_remaining -= 5; | |
674 | if ((int) width_remaining < 0) | |
675 | width_remaining = 0; | |
676 | do_dots = true; | |
677 | } | |
678 | } | |
679 | ||
680 | #ifdef HAVE_MBSTATE_T | |
681 | /* Initialise the multibyte conversion state. */ | |
682 | memset (& state, 0, sizeof (state)); | |
683 | #endif | |
684 | ||
685 | if (do_demangle && *symbol) | |
686 | { | |
687 | const char * res = cplus_demangle (symbol, demangle_flags); | |
688 | ||
689 | if (res != NULL) | |
690 | alloced_symbol = symbol = res; | |
691 | } | |
692 | ||
693 | while (width_remaining) | |
694 | { | |
695 | size_t n; | |
696 | const char c = *symbol++; | |
697 | ||
698 | if (c == 0) | |
699 | break; | |
700 | ||
701 | if (ISPRINT (c)) | |
702 | { | |
703 | putchar (c); | |
704 | width_remaining --; | |
705 | num_printed ++; | |
706 | } | |
707 | else if (ISCNTRL (c)) | |
708 | { | |
709 | /* Do not print control characters directly as they can affect terminal | |
710 | settings. Such characters usually appear in the names generated | |
711 | by the assembler for local labels. */ | |
712 | ||
713 | if (width_remaining < 2) | |
714 | break; | |
715 | ||
716 | printf ("^%c", c + 0x40); | |
717 | width_remaining -= 2; | |
718 | num_printed += 2; | |
719 | } | |
720 | else if (c == 0x7f) | |
721 | { | |
722 | if (width_remaining < 5) | |
723 | break; | |
724 | printf ("<DEL>"); | |
725 | width_remaining -= 5; | |
726 | num_printed += 5; | |
727 | } | |
728 | else if (unicode_display != unicode_locale | |
729 | && unicode_display != unicode_default) | |
730 | { | |
731 | /* Display unicode characters as something else. */ | |
732 | unsigned char bytes[4]; | |
733 | bool is_utf8; | |
734 | unsigned int nbytes; | |
735 | ||
736 | bytes[0] = c; | |
737 | ||
738 | if (bytes[0] < 0xc0) | |
739 | { | |
740 | nbytes = 1; | |
741 | is_utf8 = false; | |
742 | } | |
743 | else | |
744 | { | |
745 | bytes[1] = *symbol++; | |
746 | ||
747 | if ((bytes[1] & 0xc0) != 0x80) | |
748 | { | |
749 | is_utf8 = false; | |
750 | /* Do not consume this character. It may only | |
751 | be the first byte in the sequence that was | |
752 | corrupt. */ | |
753 | --symbol; | |
754 | nbytes = 1; | |
755 | } | |
756 | else if ((bytes[0] & 0x20) == 0) | |
757 | { | |
758 | is_utf8 = true; | |
759 | nbytes = 2; | |
760 | } | |
761 | else | |
762 | { | |
763 | bytes[2] = *symbol++; | |
764 | ||
765 | if ((bytes[2] & 0xc0) != 0x80) | |
766 | { | |
767 | is_utf8 = false; | |
768 | symbol -= 2; | |
769 | nbytes = 1; | |
770 | } | |
771 | else if ((bytes[0] & 0x10) == 0) | |
772 | { | |
773 | is_utf8 = true; | |
774 | nbytes = 3; | |
775 | } | |
776 | else | |
777 | { | |
778 | bytes[3] = *symbol++; | |
779 | ||
780 | nbytes = 4; | |
781 | ||
782 | if ((bytes[3] & 0xc0) != 0x80) | |
783 | { | |
784 | is_utf8 = false; | |
785 | symbol -= 3; | |
786 | nbytes = 1; | |
787 | } | |
788 | else | |
789 | is_utf8 = true; | |
790 | } | |
791 | } | |
792 | } | |
793 | ||
794 | if (unicode_display == unicode_invalid) | |
795 | is_utf8 = false; | |
796 | ||
797 | if (unicode_display == unicode_hex || ! is_utf8) | |
798 | { | |
799 | unsigned int i; | |
800 | ||
801 | if (width_remaining < (nbytes * 2) + 2) | |
802 | break; | |
803 | ||
804 | putchar (is_utf8 ? '<' : '{'); | |
805 | printf ("0x"); | |
806 | for (i = 0; i < nbytes; i++) | |
807 | printf ("%02x", bytes[i]); | |
808 | putchar (is_utf8 ? '>' : '}'); | |
809 | } | |
810 | else | |
811 | { | |
812 | if (unicode_display == unicode_highlight && isatty (1)) | |
813 | printf ("\x1B[31;47m"); /* Red. */ | |
814 | ||
815 | switch (nbytes) | |
816 | { | |
817 | case 2: | |
818 | if (width_remaining < 6) | |
819 | break; | |
820 | printf ("\\u%02x%02x", | |
821 | (bytes[0] & 0x1c) >> 2, | |
822 | ((bytes[0] & 0x03) << 6) | (bytes[1] & 0x3f)); | |
823 | break; | |
824 | case 3: | |
825 | if (width_remaining < 6) | |
826 | break; | |
827 | printf ("\\u%02x%02x", | |
828 | ((bytes[0] & 0x0f) << 4) | ((bytes[1] & 0x3c) >> 2), | |
829 | ((bytes[1] & 0x03) << 6) | (bytes[2] & 0x3f)); | |
830 | break; | |
831 | case 4: | |
832 | if (width_remaining < 8) | |
833 | break; | |
834 | printf ("\\u%02x%02x%02x", | |
835 | ((bytes[0] & 0x07) << 6) | ((bytes[1] & 0x3c) >> 2), | |
836 | ((bytes[1] & 0x03) << 6) | ((bytes[2] & 0x3c) >> 2), | |
837 | ((bytes[2] & 0x03) << 6) | (bytes[3] & 0x3f)); | |
838 | ||
839 | break; | |
840 | default: | |
841 | /* URG. */ | |
842 | break; | |
843 | } | |
844 | ||
845 | if (unicode_display == unicode_highlight && isatty (1)) | |
846 | printf ("\033[0m"); /* Default colour. */ | |
847 | } | |
848 | ||
849 | if (bytes[nbytes - 1] == 0) | |
850 | break; | |
851 | } | |
852 | else | |
853 | { | |
854 | #ifdef HAVE_MBSTATE_T | |
855 | wchar_t w; | |
856 | #endif | |
857 | /* Let printf do the hard work of displaying multibyte characters. */ | |
858 | printf ("%.1s", symbol - 1); | |
859 | width_remaining --; | |
860 | num_printed ++; | |
861 | ||
862 | #ifdef HAVE_MBSTATE_T | |
863 | /* Try to find out how many bytes made up the character that was | |
864 | just printed. Advance the symbol pointer past the bytes that | |
865 | were displayed. */ | |
866 | n = mbrtowc (& w, symbol - 1, MB_CUR_MAX, & state); | |
867 | #else | |
868 | n = 1; | |
869 | #endif | |
870 | if (n != (size_t) -1 && n != (size_t) -2 && n > 0) | |
871 | symbol += (n - 1); | |
872 | } | |
873 | } | |
874 | ||
875 | if (do_dots) | |
876 | num_printed += printf ("[...]"); | |
877 | ||
878 | if (extra_padding && num_printed < width) | |
879 | { | |
880 | /* Fill in the remaining spaces. */ | |
881 | printf ("%-*s", width - num_printed, " "); | |
882 | num_printed = width; | |
883 | } | |
884 | ||
885 | free ((void *) alloced_symbol); | |
886 | return num_printed; | |
887 | } | |
888 | ||
889 | /* Returns a pointer to a static buffer containing a printable version of | |
890 | STRING. Uses a rotating array of static buffers, so that multiple | |
891 | successive calls will still work. eg when used in a call to printf(). | |
892 | ||
893 | If supplied MAX_LEN is the maximum number of characters to be read | |
894 | starting from STRING. | |
895 | ||
896 | This function is similar to print_symbol_name(), except that it does | |
897 | not try to print multibyte characters, it just shows them as hex values. | |
898 | ||
899 | If the string is too long for the static buffer or if it is not | |
900 | terminated then a truncated version of the string will be returned. */ | |
901 | ||
902 | static const char * | |
903 | printable_string (const char * string, unsigned int max_len) | |
904 | { | |
905 | #define NUM_STRING_BUFS 5 | |
906 | #define MAX_STRING_LEN 256 | |
907 | ||
908 | static int string_buf_index = 0; | |
909 | static char string_buf [NUM_STRING_BUFS][MAX_STRING_LEN + 1]; | |
910 | ||
911 | char * buf; | |
912 | char * buf_start; | |
913 | ||
914 | /* Select a buffer to use. */ | |
915 | buf_start = buf = string_buf[string_buf_index]; | |
916 | if (++ string_buf_index >= NUM_STRING_BUFS) | |
917 | string_buf_index = 0; | |
918 | ||
919 | char c; | |
920 | unsigned int remaining = MAX_STRING_LEN; | |
921 | ||
922 | while ((c = * string ++) != 0) | |
923 | { | |
924 | if (ISCNTRL (c)) | |
925 | { | |
926 | if (remaining < 2) | |
927 | break; | |
928 | ||
929 | * buf ++ = '^'; | |
930 | * buf ++ = c + 0x40; | |
931 | remaining -= 2; | |
932 | } | |
933 | else if (ISPRINT (c)) | |
934 | { | |
935 | * buf ++ = c; | |
936 | remaining -= 1; | |
937 | } | |
938 | else | |
939 | { | |
940 | static char hex[17] = "0123456789ABCDEF"; | |
941 | ||
942 | if (remaining < 4) | |
943 | break; | |
944 | * buf ++ = '<'; | |
945 | * buf ++ = hex[(c & 0xf0) >> 4]; | |
946 | * buf ++ = hex[c & 0x0f]; | |
947 | * buf ++ = '>'; | |
948 | remaining -= 4; | |
949 | } | |
950 | ||
951 | if (remaining == 0) | |
952 | break; | |
953 | ||
954 | if (max_len > 0) | |
955 | { | |
956 | max_len -= 1; | |
957 | if (max_len == 0) | |
958 | break; | |
959 | } | |
960 | } | |
961 | ||
962 | * buf = 0; | |
963 | return buf_start; | |
964 | } | |
965 | ||
966 | /* Returns a pointer to a static buffer containing a | |
967 | printable version of the given section's name. */ | |
968 | ||
969 | static const char * | |
970 | printable_section_name (Filedata * filedata, const Elf_Internal_Shdr * sec) | |
971 | { | |
972 | /* Validate the input parameters. */ | |
973 | if (filedata == NULL) | |
974 | return _("<internal error>"); | |
975 | if (sec == NULL) | |
976 | return _("<none>"); | |
977 | if (filedata->string_table == NULL) | |
978 | return _("<no-strings>"); | |
979 | if (sec->sh_name >= filedata->string_table_length) | |
980 | return _("<corrupt>"); | |
981 | ||
982 | return printable_string (section_name (filedata, sec), | |
983 | filedata->string_table_length - sec->sh_name); | |
984 | } | |
985 | ||
986 | /* Return TRUE if the current file is for IA-64 machine and OpenVMS ABI. | |
987 | This OS has so many departures from the ELF standard that we test it at | |
988 | many places. */ | |
989 | ||
990 | static inline bool | |
991 | is_ia64_vms (Filedata * filedata) | |
992 | { | |
993 | return filedata->file_header.e_machine == EM_IA_64 | |
994 | && filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_OPENVMS; | |
995 | } | |
996 | ||
997 | static const char * | |
998 | printable_section_name_from_index (Filedata * filedata, | |
999 | size_t ndx, | |
1000 | bool * is_special) | |
1001 | { | |
1002 | if (is_special != NULL) | |
1003 | * is_special = true; | |
1004 | ||
1005 | switch (ndx) | |
1006 | { | |
1007 | case SHN_UNDEF: return "UND"; | |
1008 | case SHN_ABS: return "ABS"; | |
1009 | case SHN_COMMON: return "COM"; | |
1010 | break; | |
1011 | } | |
1012 | ||
1013 | if (filedata != NULL) | |
1014 | { | |
1015 | switch (filedata->file_header.e_machine) | |
1016 | { | |
1017 | case EM_MIPS: | |
1018 | if (ndx == SHN_MIPS_SCOMMON) | |
1019 | return "SCOMMON"; | |
1020 | if (ndx == SHN_MIPS_SUNDEFINED) | |
1021 | return "SUNDEF"; | |
1022 | break; | |
1023 | ||
1024 | case EM_TI_C6000: | |
1025 | if (ndx == SHN_TIC6X_SCOMMON) | |
1026 | return "SCOM"; | |
1027 | break; | |
1028 | ||
1029 | case EM_X86_64: | |
1030 | case EM_L1OM: | |
1031 | case EM_K1OM: | |
1032 | if (ndx == SHN_X86_64_LCOMMON) | |
1033 | return "LARGE_COM"; | |
1034 | break; | |
1035 | ||
1036 | case EM_IA_64: | |
1037 | if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_HPUX | |
1038 | && ndx == SHN_IA_64_ANSI_COMMON) | |
1039 | return "ANSI_COM"; | |
1040 | ||
1041 | if (is_ia64_vms (filedata) && ndx == SHN_IA_64_VMS_SYMVEC) | |
1042 | return "VMS_SYMVEC"; | |
1043 | break; | |
1044 | ||
1045 | default: | |
1046 | break; | |
1047 | } | |
1048 | ||
1049 | if (filedata->section_headers != NULL | |
1050 | && ndx < filedata->file_header.e_shnum) | |
1051 | { | |
1052 | const char * res; | |
1053 | ||
1054 | res = printable_section_name (filedata, filedata->section_headers + ndx); | |
1055 | if (is_special != NULL) | |
1056 | * is_special = (res[0] == '<'); | |
1057 | ||
1058 | return res; | |
1059 | } | |
1060 | } | |
1061 | ||
1062 | static char name_buf[40]; | |
1063 | unsigned int short_ndx = (unsigned int) (ndx & 0xffff); | |
1064 | ||
1065 | if (ndx >= SHN_LOPROC && ndx <= SHN_HIPROC) | |
1066 | sprintf (name_buf, "PRC[0x%04x]", short_ndx); | |
1067 | else if (ndx >= SHN_LOOS && ndx <= SHN_HIOS) | |
1068 | sprintf (name_buf, "OS [0x%04x]", short_ndx); | |
1069 | else if (ndx >= SHN_LORESERVE) | |
1070 | sprintf (name_buf, "RSV[0x%04x]", short_ndx); | |
1071 | else if (filedata->file_header.e_shnum != 0 | |
1072 | && ndx >= filedata->file_header.e_shnum) | |
1073 | sprintf (name_buf, _("BAD[0x%lx]"), (long) ndx); | |
1074 | else | |
1075 | sprintf (name_buf, "<section 0x%lx>", (long) ndx); | |
1076 | ||
1077 | return name_buf; | |
1078 | } | |
1079 | ||
1080 | /* Return a pointer to section NAME, or NULL if no such section exists. */ | |
1081 | ||
1082 | static Elf_Internal_Shdr * | |
1083 | find_section (Filedata * filedata, const char * name) | |
1084 | { | |
1085 | unsigned int i; | |
1086 | ||
1087 | if (filedata->section_headers == NULL) | |
1088 | return NULL; | |
1089 | ||
1090 | for (i = 0; i < filedata->file_header.e_shnum; i++) | |
1091 | if (section_name_valid (filedata, filedata->section_headers + i) | |
1092 | && streq (section_name (filedata, filedata->section_headers + i), | |
1093 | name)) | |
1094 | return filedata->section_headers + i; | |
1095 | ||
1096 | return NULL; | |
1097 | } | |
1098 | ||
1099 | /* Return a pointer to a section containing ADDR, or NULL if no such | |
1100 | section exists. */ | |
1101 | ||
1102 | static Elf_Internal_Shdr * | |
1103 | find_section_by_address (Filedata * filedata, uint64_t addr) | |
1104 | { | |
1105 | unsigned int i; | |
1106 | ||
1107 | if (filedata->section_headers == NULL) | |
1108 | return NULL; | |
1109 | ||
1110 | for (i = 0; i < filedata->file_header.e_shnum; i++) | |
1111 | { | |
1112 | Elf_Internal_Shdr *sec = filedata->section_headers + i; | |
1113 | ||
1114 | if (addr >= sec->sh_addr && addr < sec->sh_addr + sec->sh_size) | |
1115 | return sec; | |
1116 | } | |
1117 | ||
1118 | return NULL; | |
1119 | } | |
1120 | ||
1121 | static Elf_Internal_Shdr * | |
1122 | find_section_by_type (Filedata * filedata, unsigned int type) | |
1123 | { | |
1124 | unsigned int i; | |
1125 | ||
1126 | if (filedata->section_headers == NULL) | |
1127 | return NULL; | |
1128 | ||
1129 | for (i = 0; i < filedata->file_header.e_shnum; i++) | |
1130 | { | |
1131 | Elf_Internal_Shdr *sec = filedata->section_headers + i; | |
1132 | ||
1133 | if (sec->sh_type == type) | |
1134 | return sec; | |
1135 | } | |
1136 | ||
1137 | return NULL; | |
1138 | } | |
1139 | ||
1140 | static Elf_Internal_Shdr * | |
1141 | find_section_by_name (Filedata * filedata, const char * name) | |
1142 | { | |
1143 | unsigned int i; | |
1144 | ||
1145 | if (filedata->section_headers == NULL || filedata->string_table_length == 0) | |
1146 | return NULL; | |
1147 | ||
1148 | for (i = 0; i < filedata->file_header.e_shnum; i++) | |
1149 | { | |
1150 | Elf_Internal_Shdr *sec = filedata->section_headers + i; | |
1151 | ||
1152 | if (sec->sh_name < filedata->string_table_length | |
1153 | && streq (name, filedata->string_table + sec->sh_name)) | |
1154 | return sec; | |
1155 | } | |
1156 | ||
1157 | return NULL; | |
1158 | } | |
1159 | ||
1160 | /* Return a pointer to section NAME, or NULL if no such section exists, | |
1161 | restricted to the list of sections given in SET. */ | |
1162 | ||
1163 | static Elf_Internal_Shdr * | |
1164 | find_section_in_set (Filedata * filedata, const char * name, unsigned int * set) | |
1165 | { | |
1166 | unsigned int i; | |
1167 | ||
1168 | if (filedata->section_headers == NULL) | |
1169 | return NULL; | |
1170 | ||
1171 | if (set != NULL) | |
1172 | { | |
1173 | while ((i = *set++) > 0) | |
1174 | { | |
1175 | /* See PR 21156 for a reproducer. */ | |
1176 | if (i >= filedata->file_header.e_shnum) | |
1177 | continue; /* FIXME: Should we issue an error message ? */ | |
1178 | ||
1179 | if (section_name_valid (filedata, filedata->section_headers + i) | |
1180 | && streq (section_name (filedata, filedata->section_headers + i), | |
1181 | name)) | |
1182 | return filedata->section_headers + i; | |
1183 | } | |
1184 | } | |
1185 | ||
1186 | return find_section (filedata, name); | |
1187 | } | |
1188 | ||
1189 | /* Guess the relocation size commonly used by the specific machines. */ | |
1190 | ||
1191 | static bool | |
1192 | guess_is_rela (unsigned int e_machine) | |
1193 | { | |
1194 | switch (e_machine) | |
1195 | { | |
1196 | /* Targets that use REL relocations. */ | |
1197 | case EM_386: | |
1198 | case EM_IAMCU: | |
1199 | case EM_960: | |
1200 | case EM_ARM: | |
1201 | case EM_D10V: | |
1202 | case EM_CYGNUS_D10V: | |
1203 | case EM_DLX: | |
1204 | case EM_MIPS: | |
1205 | case EM_MIPS_RS3_LE: | |
1206 | case EM_CYGNUS_M32R: | |
1207 | case EM_SCORE: | |
1208 | case EM_XGATE: | |
1209 | case EM_NFP: | |
1210 | case EM_BPF: | |
1211 | return false; | |
1212 | ||
1213 | /* Targets that use RELA relocations. */ | |
1214 | case EM_68K: | |
1215 | case EM_860: | |
1216 | case EM_AARCH64: | |
1217 | case EM_ADAPTEVA_EPIPHANY: | |
1218 | case EM_ALPHA: | |
1219 | case EM_ALTERA_NIOS2: | |
1220 | case EM_ARC: | |
1221 | case EM_ARC_COMPACT: | |
1222 | case EM_ARC_COMPACT2: | |
1223 | case EM_ARC_COMPACT3: | |
1224 | case EM_ARC_COMPACT3_64: | |
1225 | case EM_AVR: | |
1226 | case EM_AVR_OLD: | |
1227 | case EM_BLACKFIN: | |
1228 | case EM_CR16: | |
1229 | case EM_CRIS: | |
1230 | case EM_CRX: | |
1231 | case EM_CSKY: | |
1232 | case EM_D30V: | |
1233 | case EM_CYGNUS_D30V: | |
1234 | case EM_FR30: | |
1235 | case EM_FT32: | |
1236 | case EM_CYGNUS_FR30: | |
1237 | case EM_CYGNUS_FRV: | |
1238 | case EM_H8S: | |
1239 | case EM_H8_300: | |
1240 | case EM_H8_300H: | |
1241 | case EM_IA_64: | |
1242 | case EM_IP2K: | |
1243 | case EM_IP2K_OLD: | |
1244 | case EM_IQ2000: | |
1245 | case EM_KVX: | |
1246 | case EM_LATTICEMICO32: | |
1247 | case EM_M32C_OLD: | |
1248 | case EM_M32C: | |
1249 | case EM_M32R: | |
1250 | case EM_MCORE: | |
1251 | case EM_CYGNUS_MEP: | |
1252 | case EM_METAG: | |
1253 | case EM_MMIX: | |
1254 | case EM_MN10200: | |
1255 | case EM_CYGNUS_MN10200: | |
1256 | case EM_MN10300: | |
1257 | case EM_CYGNUS_MN10300: | |
1258 | case EM_MOXIE: | |
1259 | case EM_MSP430: | |
1260 | case EM_MSP430_OLD: | |
1261 | case EM_MT: | |
1262 | case EM_NDS32: | |
1263 | case EM_NIOS32: | |
1264 | case EM_OR1K: | |
1265 | case EM_PPC64: | |
1266 | case EM_PPC: | |
1267 | case EM_TI_PRU: | |
1268 | case EM_RISCV: | |
1269 | case EM_RL78: | |
1270 | case EM_RX: | |
1271 | case EM_S390: | |
1272 | case EM_S390_OLD: | |
1273 | case EM_SH: | |
1274 | case EM_SPARC: | |
1275 | case EM_SPARC32PLUS: | |
1276 | case EM_SPARCV9: | |
1277 | case EM_SPU: | |
1278 | case EM_TI_C6000: | |
1279 | case EM_TILEGX: | |
1280 | case EM_TILEPRO: | |
1281 | case EM_V800: | |
1282 | case EM_V850: | |
1283 | case EM_CYGNUS_V850: | |
1284 | case EM_VAX: | |
1285 | case EM_VISIUM: | |
1286 | case EM_X86_64: | |
1287 | case EM_L1OM: | |
1288 | case EM_K1OM: | |
1289 | case EM_XSTORMY16: | |
1290 | case EM_XTENSA: | |
1291 | case EM_XTENSA_OLD: | |
1292 | case EM_MICROBLAZE: | |
1293 | case EM_MICROBLAZE_OLD: | |
1294 | case EM_WEBASSEMBLY: | |
1295 | return true; | |
1296 | ||
1297 | case EM_68HC05: | |
1298 | case EM_68HC08: | |
1299 | case EM_68HC11: | |
1300 | case EM_68HC16: | |
1301 | case EM_FX66: | |
1302 | case EM_ME16: | |
1303 | case EM_MMA: | |
1304 | case EM_NCPU: | |
1305 | case EM_NDR1: | |
1306 | case EM_PCP: | |
1307 | case EM_ST100: | |
1308 | case EM_ST19: | |
1309 | case EM_ST7: | |
1310 | case EM_ST9PLUS: | |
1311 | case EM_STARCORE: | |
1312 | case EM_SVX: | |
1313 | case EM_TINYJ: | |
1314 | default: | |
1315 | warn (_("Don't know about relocations on this machine architecture\n")); | |
1316 | return false; | |
1317 | } | |
1318 | } | |
1319 | ||
1320 | /* Load RELA type relocations from FILEDATA at REL_OFFSET extending for REL_SIZE bytes. | |
1321 | Returns TRUE upon success, FALSE otherwise. If successful then a | |
1322 | pointer to a malloc'ed buffer containing the relocs is placed in *RELASP, | |
1323 | and the number of relocs loaded is placed in *NRELASP. It is the caller's | |
1324 | responsibility to free the allocated buffer. */ | |
1325 | ||
1326 | static bool | |
1327 | slurp_rela_relocs (Filedata *filedata, | |
1328 | uint64_t rel_offset, | |
1329 | uint64_t rel_size, | |
1330 | Elf_Internal_Rela **relasp, | |
1331 | uint64_t *nrelasp) | |
1332 | { | |
1333 | Elf_Internal_Rela * relas; | |
1334 | uint64_t nrelas; | |
1335 | unsigned int i; | |
1336 | ||
1337 | if (is_32bit_elf) | |
1338 | { | |
1339 | Elf32_External_Rela * erelas; | |
1340 | ||
1341 | erelas = (Elf32_External_Rela *) get_data (NULL, filedata, rel_offset, 1, | |
1342 | rel_size, _("32-bit relocation data")); | |
1343 | if (!erelas) | |
1344 | return false; | |
1345 | ||
1346 | nrelas = rel_size / sizeof (Elf32_External_Rela); | |
1347 | ||
1348 | relas = (Elf_Internal_Rela *) cmalloc (nrelas, | |
1349 | sizeof (Elf_Internal_Rela)); | |
1350 | ||
1351 | if (relas == NULL) | |
1352 | { | |
1353 | free (erelas); | |
1354 | error (_("out of memory parsing relocs\n")); | |
1355 | return false; | |
1356 | } | |
1357 | ||
1358 | for (i = 0; i < nrelas; i++) | |
1359 | { | |
1360 | relas[i].r_offset = BYTE_GET (erelas[i].r_offset); | |
1361 | relas[i].r_info = BYTE_GET (erelas[i].r_info); | |
1362 | relas[i].r_addend = BYTE_GET_SIGNED (erelas[i].r_addend); | |
1363 | } | |
1364 | ||
1365 | free (erelas); | |
1366 | } | |
1367 | else | |
1368 | { | |
1369 | Elf64_External_Rela * erelas; | |
1370 | ||
1371 | erelas = (Elf64_External_Rela *) get_data (NULL, filedata, rel_offset, 1, | |
1372 | rel_size, _("64-bit relocation data")); | |
1373 | if (!erelas) | |
1374 | return false; | |
1375 | ||
1376 | nrelas = rel_size / sizeof (Elf64_External_Rela); | |
1377 | ||
1378 | relas = (Elf_Internal_Rela *) cmalloc (nrelas, | |
1379 | sizeof (Elf_Internal_Rela)); | |
1380 | ||
1381 | if (relas == NULL) | |
1382 | { | |
1383 | free (erelas); | |
1384 | error (_("out of memory parsing relocs\n")); | |
1385 | return false; | |
1386 | } | |
1387 | ||
1388 | for (i = 0; i < nrelas; i++) | |
1389 | { | |
1390 | relas[i].r_offset = BYTE_GET (erelas[i].r_offset); | |
1391 | relas[i].r_info = BYTE_GET (erelas[i].r_info); | |
1392 | relas[i].r_addend = BYTE_GET_SIGNED (erelas[i].r_addend); | |
1393 | ||
1394 | if (filedata->file_header.e_machine == EM_MIPS | |
1395 | && filedata->file_header.e_ident[EI_DATA] != ELFDATA2MSB) | |
1396 | { | |
1397 | /* In little-endian objects, r_info isn't really a | |
1398 | 64-bit little-endian value: it has a 32-bit | |
1399 | little-endian symbol index followed by four | |
1400 | individual byte fields. Reorder INFO | |
1401 | accordingly. */ | |
1402 | uint64_t inf = relas[i].r_info; | |
1403 | inf = (((inf & 0xffffffff) << 32) | |
1404 | | ((inf >> 56) & 0xff) | |
1405 | | ((inf >> 40) & 0xff00) | |
1406 | | ((inf >> 24) & 0xff0000) | |
1407 | | ((inf >> 8) & 0xff000000)); | |
1408 | relas[i].r_info = inf; | |
1409 | } | |
1410 | } | |
1411 | ||
1412 | free (erelas); | |
1413 | } | |
1414 | ||
1415 | *relasp = relas; | |
1416 | *nrelasp = nrelas; | |
1417 | return true; | |
1418 | } | |
1419 | ||
1420 | /* Load REL type relocations from FILEDATA at REL_OFFSET extending for REL_SIZE bytes. | |
1421 | Returns TRUE upon success, FALSE otherwise. If successful then a | |
1422 | pointer to a malloc'ed buffer containing the relocs is placed in *RELSP, | |
1423 | and the number of relocs loaded is placed in *NRELSP. It is the caller's | |
1424 | responsibility to free the allocated buffer. */ | |
1425 | ||
1426 | static bool | |
1427 | slurp_rel_relocs (Filedata *filedata, | |
1428 | uint64_t rel_offset, | |
1429 | uint64_t rel_size, | |
1430 | Elf_Internal_Rela **relsp, | |
1431 | uint64_t *nrelsp) | |
1432 | { | |
1433 | Elf_Internal_Rela * rels; | |
1434 | uint64_t nrels; | |
1435 | unsigned int i; | |
1436 | ||
1437 | if (is_32bit_elf) | |
1438 | { | |
1439 | Elf32_External_Rel * erels; | |
1440 | ||
1441 | erels = (Elf32_External_Rel *) get_data (NULL, filedata, rel_offset, 1, | |
1442 | rel_size, _("32-bit relocation data")); | |
1443 | if (!erels) | |
1444 | return false; | |
1445 | ||
1446 | nrels = rel_size / sizeof (Elf32_External_Rel); | |
1447 | ||
1448 | rels = (Elf_Internal_Rela *) cmalloc (nrels, sizeof (Elf_Internal_Rela)); | |
1449 | ||
1450 | if (rels == NULL) | |
1451 | { | |
1452 | free (erels); | |
1453 | error (_("out of memory parsing relocs\n")); | |
1454 | return false; | |
1455 | } | |
1456 | ||
1457 | for (i = 0; i < nrels; i++) | |
1458 | { | |
1459 | rels[i].r_offset = BYTE_GET (erels[i].r_offset); | |
1460 | rels[i].r_info = BYTE_GET (erels[i].r_info); | |
1461 | rels[i].r_addend = 0; | |
1462 | } | |
1463 | ||
1464 | free (erels); | |
1465 | } | |
1466 | else | |
1467 | { | |
1468 | Elf64_External_Rel * erels; | |
1469 | ||
1470 | erels = (Elf64_External_Rel *) get_data (NULL, filedata, rel_offset, 1, | |
1471 | rel_size, _("64-bit relocation data")); | |
1472 | if (!erels) | |
1473 | return false; | |
1474 | ||
1475 | nrels = rel_size / sizeof (Elf64_External_Rel); | |
1476 | ||
1477 | rels = (Elf_Internal_Rela *) cmalloc (nrels, sizeof (Elf_Internal_Rela)); | |
1478 | ||
1479 | if (rels == NULL) | |
1480 | { | |
1481 | free (erels); | |
1482 | error (_("out of memory parsing relocs\n")); | |
1483 | return false; | |
1484 | } | |
1485 | ||
1486 | for (i = 0; i < nrels; i++) | |
1487 | { | |
1488 | rels[i].r_offset = BYTE_GET (erels[i].r_offset); | |
1489 | rels[i].r_info = BYTE_GET (erels[i].r_info); | |
1490 | rels[i].r_addend = 0; | |
1491 | ||
1492 | if (filedata->file_header.e_machine == EM_MIPS | |
1493 | && filedata->file_header.e_ident[EI_DATA] != ELFDATA2MSB) | |
1494 | { | |
1495 | /* In little-endian objects, r_info isn't really a | |
1496 | 64-bit little-endian value: it has a 32-bit | |
1497 | little-endian symbol index followed by four | |
1498 | individual byte fields. Reorder INFO | |
1499 | accordingly. */ | |
1500 | uint64_t inf = rels[i].r_info; | |
1501 | inf = (((inf & 0xffffffff) << 32) | |
1502 | | ((inf >> 56) & 0xff) | |
1503 | | ((inf >> 40) & 0xff00) | |
1504 | | ((inf >> 24) & 0xff0000) | |
1505 | | ((inf >> 8) & 0xff000000)); | |
1506 | rels[i].r_info = inf; | |
1507 | } | |
1508 | } | |
1509 | ||
1510 | free (erels); | |
1511 | } | |
1512 | ||
1513 | *relsp = rels; | |
1514 | *nrelsp = nrels; | |
1515 | return true; | |
1516 | } | |
1517 | ||
1518 | /* Returns the reloc type extracted from the reloc info field. */ | |
1519 | ||
1520 | static unsigned int | |
1521 | get_reloc_type (Filedata * filedata, uint64_t reloc_info) | |
1522 | { | |
1523 | if (is_32bit_elf) | |
1524 | return ELF32_R_TYPE (reloc_info); | |
1525 | ||
1526 | switch (filedata->file_header.e_machine) | |
1527 | { | |
1528 | case EM_MIPS: | |
1529 | /* Note: We assume that reloc_info has already been adjusted for us. */ | |
1530 | return ELF64_MIPS_R_TYPE (reloc_info); | |
1531 | ||
1532 | case EM_SPARCV9: | |
1533 | return ELF64_R_TYPE_ID (reloc_info); | |
1534 | ||
1535 | default: | |
1536 | return ELF64_R_TYPE (reloc_info); | |
1537 | } | |
1538 | } | |
1539 | ||
1540 | /* Return the symbol index extracted from the reloc info field. */ | |
1541 | ||
1542 | static uint64_t | |
1543 | get_reloc_symindex (uint64_t reloc_info) | |
1544 | { | |
1545 | return is_32bit_elf ? ELF32_R_SYM (reloc_info) : ELF64_R_SYM (reloc_info); | |
1546 | } | |
1547 | ||
1548 | static inline bool | |
1549 | uses_msp430x_relocs (Filedata * filedata) | |
1550 | { | |
1551 | return | |
1552 | filedata->file_header.e_machine == EM_MSP430 /* Paranoia. */ | |
1553 | /* GCC uses osabi == ELFOSBI_STANDALONE. */ | |
1554 | && (((filedata->file_header.e_flags & EF_MSP430_MACH) == E_MSP430_MACH_MSP430X) | |
1555 | /* TI compiler uses ELFOSABI_NONE. */ | |
1556 | || (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_NONE)); | |
1557 | } | |
1558 | ||
1559 | ||
1560 | static const char * | |
1561 | get_symbol_at (Filedata * filedata, | |
1562 | Elf_Internal_Sym * symtab, | |
1563 | uint64_t nsyms, | |
1564 | char * strtab, | |
1565 | uint64_t where, | |
1566 | uint64_t * offset_return) | |
1567 | { | |
1568 | Elf_Internal_Sym * beg = symtab; | |
1569 | Elf_Internal_Sym * end = symtab + nsyms; | |
1570 | Elf_Internal_Sym * best = NULL; | |
1571 | uint64_t dist = 0x100000; | |
1572 | ||
1573 | /* FIXME: Since this function is likely to be called repeatedly with | |
1574 | slightly increasing addresses each time, we could speed things up by | |
1575 | caching the last returned value and starting our search from there. */ | |
1576 | while (beg < end) | |
1577 | { | |
1578 | Elf_Internal_Sym * sym; | |
1579 | uint64_t value; | |
1580 | ||
1581 | sym = beg + (end - beg) / 2; | |
1582 | ||
1583 | value = sym->st_value; | |
1584 | ||
1585 | if (where >= value | |
1586 | && where - value < dist) | |
1587 | { | |
1588 | best = sym; | |
1589 | dist = where - value; | |
1590 | if (dist == 0) | |
1591 | break; | |
1592 | } | |
1593 | ||
1594 | if (where < value) | |
1595 | end = sym; | |
1596 | else | |
1597 | beg = sym + 1; | |
1598 | } | |
1599 | ||
1600 | const char *name; | |
1601 | ||
1602 | /* If there is a section start closer than the found symbol then | |
1603 | use that for symbolizing the address. */ | |
1604 | Elf_Internal_Shdr *sec = find_section_by_address (filedata, where); | |
1605 | if (sec != NULL | |
1606 | && where - sec->sh_addr < dist | |
1607 | && section_name_valid (filedata, sec)) | |
1608 | { | |
1609 | name = section_name (filedata, sec); | |
1610 | dist = where - sec->sh_addr; | |
1611 | } | |
1612 | else if (best != NULL) | |
1613 | name = strtab + best->st_name; | |
1614 | else | |
1615 | return NULL; | |
1616 | ||
1617 | if (offset_return != NULL) | |
1618 | * offset_return = dist; | |
1619 | ||
1620 | return name; | |
1621 | } | |
1622 | ||
1623 | static void | |
1624 | print_relr_addr_and_sym (Filedata * filedata, | |
1625 | Elf_Internal_Sym * symtab, | |
1626 | uint64_t nsyms, | |
1627 | char * strtab, | |
1628 | uint64_t where) | |
1629 | { | |
1630 | const char * symname = NULL; | |
1631 | uint64_t offset = 0; | |
1632 | ||
1633 | print_vma (where, ZERO_HEX); | |
1634 | printf (" "); | |
1635 | ||
1636 | symname = get_symbol_at (filedata, symtab, nsyms, strtab, where, & offset); | |
1637 | ||
1638 | if (symname == NULL) | |
1639 | printf ("<no sym>"); | |
1640 | else if (offset == 0) | |
1641 | print_symbol_name (38, symname); | |
1642 | else | |
1643 | { | |
1644 | print_symbol_name (28, symname); | |
1645 | printf (" + "); | |
1646 | print_vma (offset, PREFIX_HEX); | |
1647 | } | |
1648 | } | |
1649 | ||
1650 | /* See bfd_is_aarch64_special_symbol_name. */ | |
1651 | ||
1652 | static bool | |
1653 | is_aarch64_special_symbol_name (const char *name) | |
1654 | { | |
1655 | if (!name || name[0] != '$') | |
1656 | return false; | |
1657 | if (name[1] == 'x' || name[1] == 'd') | |
1658 | /* Map. */; | |
1659 | else if (name[1] == 'm' || name[1] == 'f' || name[1] == 'p') | |
1660 | /* Tag. */; | |
1661 | else | |
1662 | return false; | |
1663 | return name[2] == 0 || name[2] == '.'; | |
1664 | } | |
1665 | ||
1666 | static bool | |
1667 | is_special_symbol_name (Filedata * filedata, const char * s) | |
1668 | { | |
1669 | switch (filedata->file_header.e_machine) | |
1670 | { | |
1671 | case EM_AARCH64: | |
1672 | return is_aarch64_special_symbol_name (s); | |
1673 | ||
1674 | default: | |
1675 | return false; | |
1676 | } | |
1677 | } | |
1678 | ||
1679 | /* Allows selecting the best symbol from a set for displaying addresses. | |
1680 | BEST is the current best or NULL if there are no good symbols yet. | |
1681 | SYM is the next symbol to consider, if it is better than BEST then | |
1682 | return SYM else return BEST. */ | |
1683 | ||
1684 | static Elf_Internal_Sym * | |
1685 | select_display_sym (Filedata * filedata, | |
1686 | char * strtab, | |
1687 | uint64_t strtablen, | |
1688 | Elf_Internal_Sym * best, | |
1689 | Elf_Internal_Sym * sym) | |
1690 | { | |
1691 | /* Ignore empty or invalid syms. */ | |
1692 | if (sym->st_name == 0) | |
1693 | return best; | |
1694 | if (sym->st_name >= strtablen) | |
1695 | return best; | |
1696 | /* Ignore undefined or TLS syms. */ | |
1697 | if (sym->st_shndx == SHN_UNDEF) | |
1698 | return best; | |
1699 | if (ELF_ST_TYPE (sym->st_info) == STT_TLS) | |
1700 | return best; | |
1701 | ||
1702 | char *s = strtab + sym->st_name; | |
1703 | ||
1704 | /* Don't display special symbols. */ | |
1705 | if (is_special_symbol_name (filedata, s)) | |
1706 | return best; | |
1707 | ||
1708 | /* Here SYM is good for display. */ | |
1709 | ||
1710 | if (best == NULL) | |
1711 | return sym; | |
1712 | ||
1713 | char *sbest = strtab + best->st_name; | |
1714 | ||
1715 | /* Prefer non-local symbols. */ | |
1716 | if (ELF_ST_BIND (sym->st_info) == STB_LOCAL | |
1717 | && ELF_ST_BIND (best->st_info) != STB_LOCAL) | |
1718 | return best; | |
1719 | if (ELF_ST_BIND (sym->st_info) != STB_LOCAL | |
1720 | && ELF_ST_BIND (best->st_info) == STB_LOCAL) | |
1721 | return sym; | |
1722 | ||
1723 | /* Select based on lexicographic order. */ | |
1724 | return strcmp (s, sbest) < 0 ? sym : best; | |
1725 | } | |
1726 | ||
1727 | /* Filter the sorted SYMTAB symbol array in-place to select at most one | |
1728 | symbol for an address and drop symbols that are not good to display. | |
1729 | Returns the new array length. */ | |
1730 | ||
1731 | static uint64_t | |
1732 | filter_display_syms (Filedata * filedata, | |
1733 | Elf_Internal_Sym * symtab, | |
1734 | uint64_t nsyms, | |
1735 | char * strtab, | |
1736 | uint64_t strtablen) | |
1737 | { | |
1738 | Elf_Internal_Sym *r = symtab; | |
1739 | Elf_Internal_Sym *w = symtab; | |
1740 | Elf_Internal_Sym *best = NULL; | |
1741 | Elf_Internal_Sym *end = symtab + nsyms; | |
1742 | while (r < end) | |
1743 | { | |
1744 | /* Select the best symbol for an address. */ | |
1745 | while (r < end | |
1746 | && (best == NULL || best->st_value == r->st_value)) | |
1747 | { | |
1748 | best = select_display_sym (filedata, strtab, strtablen, best, r); | |
1749 | r++; | |
1750 | } | |
1751 | if (best != NULL) | |
1752 | { | |
1753 | *w = *best; | |
1754 | w++; | |
1755 | best = NULL; | |
1756 | } | |
1757 | } | |
1758 | return w - symtab; | |
1759 | } | |
1760 | ||
1761 | static /* signed */ int | |
1762 | symcmp (const void *p, const void *q) | |
1763 | { | |
1764 | Elf_Internal_Sym *sp = (Elf_Internal_Sym *) p; | |
1765 | Elf_Internal_Sym *sq = (Elf_Internal_Sym *) q; | |
1766 | ||
1767 | return sp->st_value > sq->st_value ? 1 : (sp->st_value < sq->st_value ? -1 : 0); | |
1768 | } | |
1769 | ||
1770 | static uint64_t | |
1771 | count_relr_relocations (Filedata * filedata, | |
1772 | Elf_Internal_Shdr * section) | |
1773 | { | |
1774 | uint64_t * relrs; | |
1775 | uint64_t nentries; | |
1776 | uint64_t i; | |
1777 | uint64_t count; | |
1778 | int entsize; | |
1779 | ||
1780 | if (section == NULL | |
1781 | || section->sh_type != SHT_RELR | |
1782 | || section->sh_size == 0) | |
1783 | return 0; | |
1784 | ||
1785 | entsize = section->sh_entsize; | |
1786 | if (entsize == 0) | |
1787 | entsize = is_32bit_elf | |
1788 | ? sizeof (Elf32_External_Relr) : sizeof (Elf64_External_Relr); | |
1789 | else if (entsize != sizeof (Elf32_External_Relr) | |
1790 | && entsize != sizeof (Elf64_External_Relr)) | |
1791 | return 0; | |
1792 | ||
1793 | nentries = section->sh_size / entsize; | |
1794 | if (nentries == 0) | |
1795 | return 0; | |
1796 | ||
1797 | /* FIXME: This call to get_data duplicates one that follows in | |
1798 | dump_relr_relocations(). They could be combined into just | |
1799 | one call. */ | |
1800 | relrs = get_data (NULL, filedata, section->sh_offset, 1, | |
1801 | section->sh_size, _("RELR relocation data")); | |
1802 | if (relrs == NULL) | |
1803 | return 0; | |
1804 | ||
1805 | for (count = i = 0; i < nentries; i++) | |
1806 | { | |
1807 | uint64_t entry; | |
1808 | ||
1809 | if (entsize == sizeof (Elf32_External_Relr)) | |
1810 | entry = BYTE_GET (((Elf32_External_Relr *)relrs)[i].r_data); | |
1811 | else | |
1812 | entry = BYTE_GET (((Elf64_External_Relr *)relrs)[i].r_data); | |
1813 | ||
1814 | if ((entry & 1) == 0) | |
1815 | { | |
1816 | ++ count; | |
1817 | } | |
1818 | else | |
1819 | { | |
1820 | if (entry == 1) | |
1821 | continue; | |
1822 | ||
1823 | for (; entry >>= 1;) | |
1824 | if ((entry & 1) == 1) | |
1825 | ++ count; | |
1826 | } | |
1827 | } | |
1828 | ||
1829 | free (relrs); | |
1830 | return count; | |
1831 | } | |
1832 | ||
1833 | static bool | |
1834 | dump_relr_relocations (Filedata * filedata, | |
1835 | Elf_Internal_Shdr * section, | |
1836 | Elf_Internal_Sym * symtab, | |
1837 | uint64_t nsyms, | |
1838 | char * strtab, | |
1839 | uint64_t strtablen) | |
1840 | { | |
1841 | uint64_t * relrs; | |
1842 | uint64_t nentries, i; | |
1843 | uint64_t relr_size = section->sh_size; | |
1844 | int relr_entsize = section->sh_entsize; | |
1845 | uint64_t relr_offset = section->sh_offset; | |
1846 | uint64_t where = 0; | |
1847 | int num_bits_in_entry; | |
1848 | ||
1849 | if (relr_entsize == 0) | |
1850 | relr_entsize = is_32bit_elf | |
1851 | ? sizeof (Elf32_External_Relr) : sizeof (Elf64_External_Relr); | |
1852 | ||
1853 | nentries = relr_size / relr_entsize; | |
1854 | ||
1855 | if (nentries == 0) | |
1856 | return true; | |
1857 | ||
1858 | if (relr_entsize == sizeof (Elf32_External_Relr)) | |
1859 | num_bits_in_entry = 31; | |
1860 | else if (relr_entsize == sizeof (Elf64_External_Relr)) | |
1861 | num_bits_in_entry = 63; | |
1862 | else | |
1863 | { | |
1864 | warn (_("Unexpected entsize for RELR section\n")); | |
1865 | return false; | |
1866 | } | |
1867 | ||
1868 | relrs = get_data (NULL, filedata, relr_offset, 1, relr_size, _("RELR relocation data")); | |
1869 | if (relrs == NULL) | |
1870 | return false; | |
1871 | ||
1872 | /* Paranoia. */ | |
1873 | if (strtab == NULL) | |
1874 | strtablen = 0; | |
1875 | if (symtab == NULL) | |
1876 | nsyms = 0; | |
1877 | ||
1878 | if (symtab != NULL) | |
1879 | { | |
1880 | /* Symbol tables are not sorted on address, but we want a quick lookup | |
1881 | for the symbol associated with each address computed below, so sort | |
1882 | the table then filter out unwanted entries. FIXME: This assumes that | |
1883 | the symbol table will not be used later on for some other purpose. */ | |
1884 | qsort (symtab, nsyms, sizeof (Elf_Internal_Sym), symcmp); | |
1885 | nsyms = filter_display_syms (filedata, symtab, nsyms, strtab, strtablen); | |
1886 | } | |
1887 | ||
1888 | if (relr_entsize == sizeof (Elf32_External_Relr)) | |
1889 | printf (_ ("Index: Entry Address Symbolic Address\n")); | |
1890 | else | |
1891 | printf (_ ("Index: Entry Address Symbolic Address\n")); | |
1892 | ||
1893 | for (i = 0; i < nentries; i++) | |
1894 | { | |
1895 | uint64_t entry; | |
1896 | ||
1897 | if (relr_entsize == sizeof (Elf32_External_Relr)) | |
1898 | entry = BYTE_GET (((Elf32_External_Relr *)relrs)[i].r_data); | |
1899 | else | |
1900 | entry = BYTE_GET (((Elf64_External_Relr *)relrs)[i].r_data); | |
1901 | ||
1902 | /* We assume that there will never be more than 9999 entries. */ | |
1903 | printf (_("%04u: "), (unsigned int) i); | |
1904 | print_vma (entry, ZERO_HEX); | |
1905 | printf (" "); | |
1906 | ||
1907 | if ((entry & 1) == 0) | |
1908 | { | |
1909 | where = entry; | |
1910 | print_relr_addr_and_sym (filedata, symtab, nsyms, strtab, where); | |
1911 | printf ("\n"); | |
1912 | where += relr_entsize; | |
1913 | } | |
1914 | else | |
1915 | { | |
1916 | bool first = true; | |
1917 | int j; | |
1918 | ||
1919 | /* The least significant bit is ignored. */ | |
1920 | if (entry == 1) | |
1921 | /* This can actually happen when the linker is allowed to shrink | |
1922 | RELR sections. For more details see: https://reviews.llvm.org/D67164. */ | |
1923 | continue; | |
1924 | else if (i == 0) | |
1925 | warn (_("Unusual RELR bitmap - no previous entry to set the base address\n")); | |
1926 | ||
1927 | for (j = 0; entry >>= 1; j++) | |
1928 | if ((entry & 1) == 1) | |
1929 | { | |
1930 | uint64_t addr = where + (j * relr_entsize); | |
1931 | ||
1932 | if (first) | |
1933 | { | |
1934 | print_relr_addr_and_sym (filedata, symtab, nsyms, strtab, addr); | |
1935 | first = false; | |
1936 | } | |
1937 | else | |
1938 | { | |
1939 | printf (_("\n%*s "), relr_entsize == 4 ? 15 : 23, " "); | |
1940 | print_relr_addr_and_sym (filedata, symtab, nsyms, strtab, addr); | |
1941 | } | |
1942 | } | |
1943 | ||
1944 | printf ("\n"); | |
1945 | where += num_bits_in_entry * relr_entsize; | |
1946 | } | |
1947 | } | |
1948 | ||
1949 | free (relrs); | |
1950 | return true; | |
1951 | } | |
1952 | ||
1953 | /* Display the contents of the relocation data found at the specified | |
1954 | offset. */ | |
1955 | ||
1956 | static bool | |
1957 | dump_relocations (Filedata * filedata, | |
1958 | uint64_t rel_offset, | |
1959 | uint64_t rel_size, | |
1960 | Elf_Internal_Sym * symtab, | |
1961 | uint64_t nsyms, | |
1962 | char * strtab, | |
1963 | uint64_t strtablen, | |
1964 | relocation_type rel_type, | |
1965 | bool is_dynsym) | |
1966 | { | |
1967 | size_t i; | |
1968 | Elf_Internal_Rela * rels; | |
1969 | bool res = true; | |
1970 | ||
1971 | if (rel_type == reltype_unknown) | |
1972 | rel_type = guess_is_rela (filedata->file_header.e_machine) ? reltype_rela : reltype_rel; | |
1973 | ||
1974 | if (rel_type == reltype_rela) | |
1975 | { | |
1976 | if (!slurp_rela_relocs (filedata, rel_offset, rel_size, &rels, &rel_size)) | |
1977 | return false; | |
1978 | } | |
1979 | else if (rel_type == reltype_rel) | |
1980 | { | |
1981 | if (!slurp_rel_relocs (filedata, rel_offset, rel_size, &rels, &rel_size)) | |
1982 | return false; | |
1983 | } | |
1984 | else if (rel_type == reltype_relr) | |
1985 | { | |
1986 | /* This should have been handled by display_relocations(). */ | |
1987 | return false; | |
1988 | } | |
1989 | ||
1990 | if (is_32bit_elf) | |
1991 | { | |
1992 | if (rel_type == reltype_rela) | |
1993 | { | |
1994 | if (do_wide) | |
1995 | printf (_(" Offset Info Type Sym. Value Symbol's Name + Addend\n")); | |
1996 | else | |
1997 | printf (_(" Offset Info Type Sym.Value Sym. Name + Addend\n")); | |
1998 | } | |
1999 | else | |
2000 | { | |
2001 | if (do_wide) | |
2002 | printf (_(" Offset Info Type Sym. Value Symbol's Name\n")); | |
2003 | else | |
2004 | printf (_(" Offset Info Type Sym.Value Sym. Name\n")); | |
2005 | } | |
2006 | } | |
2007 | else | |
2008 | { | |
2009 | if (rel_type == reltype_rela) | |
2010 | { | |
2011 | if (do_wide) | |
2012 | printf (_(" Offset Info Type Symbol's Value Symbol's Name + Addend\n")); | |
2013 | else | |
2014 | printf (_(" Offset Info Type Sym. Value Sym. Name + Addend\n")); | |
2015 | } | |
2016 | else | |
2017 | { | |
2018 | if (do_wide) | |
2019 | printf (_(" Offset Info Type Symbol's Value Symbol's Name\n")); | |
2020 | else | |
2021 | printf (_(" Offset Info Type Sym. Value Sym. Name\n")); | |
2022 | } | |
2023 | } | |
2024 | ||
2025 | for (i = 0; i < rel_size; i++) | |
2026 | { | |
2027 | const char * rtype; | |
2028 | uint64_t offset; | |
2029 | uint64_t inf; | |
2030 | uint64_t symtab_index; | |
2031 | uint64_t type; | |
2032 | ||
2033 | offset = rels[i].r_offset; | |
2034 | inf = rels[i].r_info; | |
2035 | ||
2036 | type = get_reloc_type (filedata, inf); | |
2037 | symtab_index = get_reloc_symindex (inf); | |
2038 | ||
2039 | if (is_32bit_elf) | |
2040 | { | |
2041 | printf ("%8.8lx %8.8lx ", | |
2042 | (unsigned long) offset & 0xffffffff, | |
2043 | (unsigned long) inf & 0xffffffff); | |
2044 | } | |
2045 | else | |
2046 | { | |
2047 | printf (do_wide | |
2048 | ? "%16.16" PRIx64 " %16.16" PRIx64 " " | |
2049 | : "%12.12" PRIx64 " %12.12" PRIx64 " ", | |
2050 | offset, inf); | |
2051 | } | |
2052 | ||
2053 | switch (filedata->file_header.e_machine) | |
2054 | { | |
2055 | default: | |
2056 | rtype = NULL; | |
2057 | break; | |
2058 | ||
2059 | case EM_AARCH64: | |
2060 | rtype = elf_aarch64_reloc_type (type); | |
2061 | break; | |
2062 | ||
2063 | case EM_M32R: | |
2064 | case EM_CYGNUS_M32R: | |
2065 | rtype = elf_m32r_reloc_type (type); | |
2066 | break; | |
2067 | ||
2068 | case EM_386: | |
2069 | case EM_IAMCU: | |
2070 | rtype = elf_i386_reloc_type (type); | |
2071 | break; | |
2072 | ||
2073 | case EM_68HC11: | |
2074 | case EM_68HC12: | |
2075 | rtype = elf_m68hc11_reloc_type (type); | |
2076 | break; | |
2077 | ||
2078 | case EM_S12Z: | |
2079 | rtype = elf_s12z_reloc_type (type); | |
2080 | break; | |
2081 | ||
2082 | case EM_68K: | |
2083 | rtype = elf_m68k_reloc_type (type); | |
2084 | break; | |
2085 | ||
2086 | case EM_960: | |
2087 | rtype = elf_i960_reloc_type (type); | |
2088 | break; | |
2089 | ||
2090 | case EM_AVR: | |
2091 | case EM_AVR_OLD: | |
2092 | rtype = elf_avr_reloc_type (type); | |
2093 | break; | |
2094 | ||
2095 | case EM_OLD_SPARCV9: | |
2096 | case EM_SPARC32PLUS: | |
2097 | case EM_SPARCV9: | |
2098 | case EM_SPARC: | |
2099 | rtype = elf_sparc_reloc_type (type); | |
2100 | break; | |
2101 | ||
2102 | case EM_SPU: | |
2103 | rtype = elf_spu_reloc_type (type); | |
2104 | break; | |
2105 | ||
2106 | case EM_V800: | |
2107 | rtype = v800_reloc_type (type); | |
2108 | break; | |
2109 | case EM_V850: | |
2110 | case EM_CYGNUS_V850: | |
2111 | rtype = v850_reloc_type (type); | |
2112 | break; | |
2113 | ||
2114 | case EM_D10V: | |
2115 | case EM_CYGNUS_D10V: | |
2116 | rtype = elf_d10v_reloc_type (type); | |
2117 | break; | |
2118 | ||
2119 | case EM_D30V: | |
2120 | case EM_CYGNUS_D30V: | |
2121 | rtype = elf_d30v_reloc_type (type); | |
2122 | break; | |
2123 | ||
2124 | case EM_DLX: | |
2125 | rtype = elf_dlx_reloc_type (type); | |
2126 | break; | |
2127 | ||
2128 | case EM_SH: | |
2129 | rtype = elf_sh_reloc_type (type); | |
2130 | break; | |
2131 | ||
2132 | case EM_MN10300: | |
2133 | case EM_CYGNUS_MN10300: | |
2134 | rtype = elf_mn10300_reloc_type (type); | |
2135 | break; | |
2136 | ||
2137 | case EM_MN10200: | |
2138 | case EM_CYGNUS_MN10200: | |
2139 | rtype = elf_mn10200_reloc_type (type); | |
2140 | break; | |
2141 | ||
2142 | case EM_FR30: | |
2143 | case EM_CYGNUS_FR30: | |
2144 | rtype = elf_fr30_reloc_type (type); | |
2145 | break; | |
2146 | ||
2147 | case EM_CYGNUS_FRV: | |
2148 | rtype = elf_frv_reloc_type (type); | |
2149 | break; | |
2150 | ||
2151 | case EM_CSKY: | |
2152 | rtype = elf_csky_reloc_type (type); | |
2153 | break; | |
2154 | ||
2155 | case EM_FT32: | |
2156 | rtype = elf_ft32_reloc_type (type); | |
2157 | break; | |
2158 | ||
2159 | case EM_MCORE: | |
2160 | rtype = elf_mcore_reloc_type (type); | |
2161 | break; | |
2162 | ||
2163 | case EM_MMIX: | |
2164 | rtype = elf_mmix_reloc_type (type); | |
2165 | break; | |
2166 | ||
2167 | case EM_MOXIE: | |
2168 | rtype = elf_moxie_reloc_type (type); | |
2169 | break; | |
2170 | ||
2171 | case EM_MSP430: | |
2172 | if (uses_msp430x_relocs (filedata)) | |
2173 | { | |
2174 | rtype = elf_msp430x_reloc_type (type); | |
2175 | break; | |
2176 | } | |
2177 | /* Fall through. */ | |
2178 | case EM_MSP430_OLD: | |
2179 | rtype = elf_msp430_reloc_type (type); | |
2180 | break; | |
2181 | ||
2182 | case EM_NDS32: | |
2183 | rtype = elf_nds32_reloc_type (type); | |
2184 | break; | |
2185 | ||
2186 | case EM_PPC: | |
2187 | rtype = elf_ppc_reloc_type (type); | |
2188 | break; | |
2189 | ||
2190 | case EM_PPC64: | |
2191 | rtype = elf_ppc64_reloc_type (type); | |
2192 | break; | |
2193 | ||
2194 | case EM_MIPS: | |
2195 | case EM_MIPS_RS3_LE: | |
2196 | rtype = elf_mips_reloc_type (type); | |
2197 | break; | |
2198 | ||
2199 | case EM_RISCV: | |
2200 | rtype = elf_riscv_reloc_type (type); | |
2201 | break; | |
2202 | ||
2203 | case EM_ALPHA: | |
2204 | rtype = elf_alpha_reloc_type (type); | |
2205 | break; | |
2206 | ||
2207 | case EM_ARM: | |
2208 | rtype = elf_arm_reloc_type (type); | |
2209 | break; | |
2210 | ||
2211 | case EM_ARC: | |
2212 | case EM_ARC_COMPACT: | |
2213 | case EM_ARC_COMPACT2: | |
2214 | case EM_ARC_COMPACT3: | |
2215 | case EM_ARC_COMPACT3_64: | |
2216 | rtype = elf_arc_reloc_type (type); | |
2217 | break; | |
2218 | ||
2219 | case EM_PARISC: | |
2220 | rtype = elf_hppa_reloc_type (type); | |
2221 | break; | |
2222 | ||
2223 | case EM_H8_300: | |
2224 | case EM_H8_300H: | |
2225 | case EM_H8S: | |
2226 | rtype = elf_h8_reloc_type (type); | |
2227 | break; | |
2228 | ||
2229 | case EM_OR1K: | |
2230 | rtype = elf_or1k_reloc_type (type); | |
2231 | break; | |
2232 | ||
2233 | case EM_PJ: | |
2234 | case EM_PJ_OLD: | |
2235 | rtype = elf_pj_reloc_type (type); | |
2236 | break; | |
2237 | case EM_IA_64: | |
2238 | rtype = elf_ia64_reloc_type (type); | |
2239 | break; | |
2240 | ||
2241 | case EM_KVX: | |
2242 | rtype = elf_kvx_reloc_type (type); | |
2243 | break; | |
2244 | ||
2245 | case EM_CRIS: | |
2246 | rtype = elf_cris_reloc_type (type); | |
2247 | break; | |
2248 | ||
2249 | case EM_860: | |
2250 | rtype = elf_i860_reloc_type (type); | |
2251 | break; | |
2252 | ||
2253 | case EM_X86_64: | |
2254 | case EM_L1OM: | |
2255 | case EM_K1OM: | |
2256 | rtype = elf_x86_64_reloc_type (type); | |
2257 | break; | |
2258 | ||
2259 | case EM_S370: | |
2260 | rtype = i370_reloc_type (type); | |
2261 | break; | |
2262 | ||
2263 | case EM_S390_OLD: | |
2264 | case EM_S390: | |
2265 | rtype = elf_s390_reloc_type (type); | |
2266 | break; | |
2267 | ||
2268 | case EM_SCORE: | |
2269 | rtype = elf_score_reloc_type (type); | |
2270 | break; | |
2271 | ||
2272 | case EM_XSTORMY16: | |
2273 | rtype = elf_xstormy16_reloc_type (type); | |
2274 | break; | |
2275 | ||
2276 | case EM_CRX: | |
2277 | rtype = elf_crx_reloc_type (type); | |
2278 | break; | |
2279 | ||
2280 | case EM_VAX: | |
2281 | rtype = elf_vax_reloc_type (type); | |
2282 | break; | |
2283 | ||
2284 | case EM_VISIUM: | |
2285 | rtype = elf_visium_reloc_type (type); | |
2286 | break; | |
2287 | ||
2288 | case EM_BPF: | |
2289 | rtype = elf_bpf_reloc_type (type); | |
2290 | break; | |
2291 | ||
2292 | case EM_ADAPTEVA_EPIPHANY: | |
2293 | rtype = elf_epiphany_reloc_type (type); | |
2294 | break; | |
2295 | ||
2296 | case EM_IP2K: | |
2297 | case EM_IP2K_OLD: | |
2298 | rtype = elf_ip2k_reloc_type (type); | |
2299 | break; | |
2300 | ||
2301 | case EM_IQ2000: | |
2302 | rtype = elf_iq2000_reloc_type (type); | |
2303 | break; | |
2304 | ||
2305 | case EM_XTENSA_OLD: | |
2306 | case EM_XTENSA: | |
2307 | rtype = elf_xtensa_reloc_type (type); | |
2308 | break; | |
2309 | ||
2310 | case EM_LATTICEMICO32: | |
2311 | rtype = elf_lm32_reloc_type (type); | |
2312 | break; | |
2313 | ||
2314 | case EM_M32C_OLD: | |
2315 | case EM_M32C: | |
2316 | rtype = elf_m32c_reloc_type (type); | |
2317 | break; | |
2318 | ||
2319 | case EM_MT: | |
2320 | rtype = elf_mt_reloc_type (type); | |
2321 | break; | |
2322 | ||
2323 | case EM_BLACKFIN: | |
2324 | rtype = elf_bfin_reloc_type (type); | |
2325 | break; | |
2326 | ||
2327 | case EM_CYGNUS_MEP: | |
2328 | rtype = elf_mep_reloc_type (type); | |
2329 | break; | |
2330 | ||
2331 | case EM_CR16: | |
2332 | rtype = elf_cr16_reloc_type (type); | |
2333 | break; | |
2334 | ||
2335 | case EM_MICROBLAZE: | |
2336 | case EM_MICROBLAZE_OLD: | |
2337 | rtype = elf_microblaze_reloc_type (type); | |
2338 | break; | |
2339 | ||
2340 | case EM_RL78: | |
2341 | rtype = elf_rl78_reloc_type (type); | |
2342 | break; | |
2343 | ||
2344 | case EM_RX: | |
2345 | rtype = elf_rx_reloc_type (type); | |
2346 | break; | |
2347 | ||
2348 | case EM_METAG: | |
2349 | rtype = elf_metag_reloc_type (type); | |
2350 | break; | |
2351 | ||
2352 | case EM_TI_C6000: | |
2353 | rtype = elf_tic6x_reloc_type (type); | |
2354 | break; | |
2355 | ||
2356 | case EM_TILEGX: | |
2357 | rtype = elf_tilegx_reloc_type (type); | |
2358 | break; | |
2359 | ||
2360 | case EM_TILEPRO: | |
2361 | rtype = elf_tilepro_reloc_type (type); | |
2362 | break; | |
2363 | ||
2364 | case EM_WEBASSEMBLY: | |
2365 | rtype = elf_wasm32_reloc_type (type); | |
2366 | break; | |
2367 | ||
2368 | case EM_XGATE: | |
2369 | rtype = elf_xgate_reloc_type (type); | |
2370 | break; | |
2371 | ||
2372 | case EM_ALTERA_NIOS2: | |
2373 | rtype = elf_nios2_reloc_type (type); | |
2374 | break; | |
2375 | ||
2376 | case EM_TI_PRU: | |
2377 | rtype = elf_pru_reloc_type (type); | |
2378 | break; | |
2379 | ||
2380 | case EM_NFP: | |
2381 | if (EF_NFP_MACH (filedata->file_header.e_flags) == E_NFP_MACH_3200) | |
2382 | rtype = elf_nfp3200_reloc_type (type); | |
2383 | else | |
2384 | rtype = elf_nfp_reloc_type (type); | |
2385 | break; | |
2386 | ||
2387 | case EM_Z80: | |
2388 | rtype = elf_z80_reloc_type (type); | |
2389 | break; | |
2390 | ||
2391 | case EM_LOONGARCH: | |
2392 | rtype = elf_loongarch_reloc_type (type); | |
2393 | break; | |
2394 | ||
2395 | case EM_AMDGPU: | |
2396 | rtype = elf_amdgpu_reloc_type (type); | |
2397 | break; | |
2398 | } | |
2399 | ||
2400 | if (rtype == NULL) | |
2401 | printf (_("unrecognized: %-7lx"), (unsigned long) type & 0xffffffff); | |
2402 | else | |
2403 | printf (do_wide ? "%-22s" : "%-17.17s", rtype); | |
2404 | ||
2405 | if (filedata->file_header.e_machine == EM_ALPHA | |
2406 | && rtype != NULL | |
2407 | && streq (rtype, "R_ALPHA_LITUSE") | |
2408 | && rel_type == reltype_rela) | |
2409 | { | |
2410 | switch (rels[i].r_addend) | |
2411 | { | |
2412 | case LITUSE_ALPHA_ADDR: rtype = "ADDR"; break; | |
2413 | case LITUSE_ALPHA_BASE: rtype = "BASE"; break; | |
2414 | case LITUSE_ALPHA_BYTOFF: rtype = "BYTOFF"; break; | |
2415 | case LITUSE_ALPHA_JSR: rtype = "JSR"; break; | |
2416 | case LITUSE_ALPHA_TLSGD: rtype = "TLSGD"; break; | |
2417 | case LITUSE_ALPHA_TLSLDM: rtype = "TLSLDM"; break; | |
2418 | case LITUSE_ALPHA_JSRDIRECT: rtype = "JSRDIRECT"; break; | |
2419 | default: rtype = NULL; | |
2420 | } | |
2421 | ||
2422 | if (rtype) | |
2423 | printf (" (%s)", rtype); | |
2424 | else | |
2425 | { | |
2426 | putchar (' '); | |
2427 | printf (_("<unknown addend: %" PRIx64 ">"), | |
2428 | rels[i].r_addend); | |
2429 | res = false; | |
2430 | } | |
2431 | } | |
2432 | else if (symtab_index) | |
2433 | { | |
2434 | if (symtab == NULL || symtab_index >= nsyms) | |
2435 | { | |
2436 | error (_(" bad symbol index: %08lx in reloc\n"), | |
2437 | (unsigned long) symtab_index); | |
2438 | res = false; | |
2439 | } | |
2440 | else | |
2441 | { | |
2442 | Elf_Internal_Sym * psym; | |
2443 | const char * version_string; | |
2444 | enum versioned_symbol_info sym_info; | |
2445 | unsigned short vna_other; | |
2446 | ||
2447 | psym = symtab + symtab_index; | |
2448 | ||
2449 | version_string | |
2450 | = get_symbol_version_string (filedata, is_dynsym, | |
2451 | strtab, strtablen, | |
2452 | symtab_index, | |
2453 | psym, | |
2454 | &sym_info, | |
2455 | &vna_other); | |
2456 | ||
2457 | printf (" "); | |
2458 | ||
2459 | if (ELF_ST_TYPE (psym->st_info) == STT_GNU_IFUNC) | |
2460 | { | |
2461 | const char * name; | |
2462 | unsigned int len; | |
2463 | unsigned int width = is_32bit_elf ? 8 : 14; | |
2464 | ||
2465 | /* Relocations against GNU_IFUNC symbols do not use the value | |
2466 | of the symbol as the address to relocate against. Instead | |
2467 | they invoke the function named by the symbol and use its | |
2468 | result as the address for relocation. | |
2469 | ||
2470 | To indicate this to the user, do not display the value of | |
2471 | the symbol in the "Symbols's Value" field. Instead show | |
2472 | its name followed by () as a hint that the symbol is | |
2473 | invoked. */ | |
2474 | ||
2475 | if (strtab == NULL | |
2476 | || psym->st_name == 0 | |
2477 | || psym->st_name >= strtablen) | |
2478 | name = "??"; | |
2479 | else | |
2480 | name = strtab + psym->st_name; | |
2481 | ||
2482 | len = print_symbol_name (width, name); | |
2483 | if (version_string) | |
2484 | printf (sym_info == symbol_public ? "@@%s" : "@%s", | |
2485 | version_string); | |
2486 | printf ("()%-*s", len <= width ? (width + 1) - len : 1, " "); | |
2487 | } | |
2488 | else | |
2489 | { | |
2490 | print_vma (psym->st_value, LONG_HEX); | |
2491 | ||
2492 | printf (is_32bit_elf ? " " : " "); | |
2493 | } | |
2494 | ||
2495 | if (psym->st_name == 0) | |
2496 | { | |
2497 | const char * sec_name = "<null>"; | |
2498 | ||
2499 | if (ELF_ST_TYPE (psym->st_info) == STT_SECTION) | |
2500 | sec_name = printable_section_name_from_index | |
2501 | (filedata, psym->st_shndx, NULL); | |
2502 | ||
2503 | print_symbol_name (22, sec_name); | |
2504 | } | |
2505 | else if (strtab == NULL) | |
2506 | printf (_("<string table index: %3ld>"), psym->st_name); | |
2507 | else if (psym->st_name >= strtablen) | |
2508 | { | |
2509 | error (_("<corrupt string table index: %3ld>\n"), | |
2510 | psym->st_name); | |
2511 | res = false; | |
2512 | } | |
2513 | else | |
2514 | { | |
2515 | print_symbol_name (22, strtab + psym->st_name); | |
2516 | if (version_string) | |
2517 | printf (sym_info == symbol_public ? "@@%s" : "@%s", | |
2518 | version_string); | |
2519 | } | |
2520 | ||
2521 | if (rel_type == reltype_rela) | |
2522 | { | |
2523 | uint64_t off = rels[i].r_addend; | |
2524 | ||
2525 | if ((int64_t) off < 0) | |
2526 | printf (" - %" PRIx64, -off); | |
2527 | else | |
2528 | printf (" + %" PRIx64, off); | |
2529 | } | |
2530 | } | |
2531 | } | |
2532 | else if (rel_type == reltype_rela) | |
2533 | { | |
2534 | uint64_t off = rels[i].r_addend; | |
2535 | ||
2536 | printf ("%*c", is_32bit_elf ? 12 : 20, ' '); | |
2537 | if ((int64_t) off < 0) | |
2538 | printf ("-%" PRIx64, -off); | |
2539 | else | |
2540 | printf ("%" PRIx64, off); | |
2541 | } | |
2542 | ||
2543 | if (filedata->file_header.e_machine == EM_SPARCV9 | |
2544 | && rtype != NULL | |
2545 | && streq (rtype, "R_SPARC_OLO10")) | |
2546 | printf (" + %" PRIx64, ELF64_R_TYPE_DATA (inf)); | |
2547 | ||
2548 | putchar ('\n'); | |
2549 | ||
2550 | if (! is_32bit_elf && filedata->file_header.e_machine == EM_MIPS) | |
2551 | { | |
2552 | uint64_t type2 = ELF64_MIPS_R_TYPE2 (inf); | |
2553 | uint64_t type3 = ELF64_MIPS_R_TYPE3 (inf); | |
2554 | const char * rtype2 = elf_mips_reloc_type (type2); | |
2555 | const char * rtype3 = elf_mips_reloc_type (type3); | |
2556 | ||
2557 | printf (" Type2: "); | |
2558 | ||
2559 | if (rtype2 == NULL) | |
2560 | printf (_("unrecognized: %-7lx"), | |
2561 | (unsigned long) type2 & 0xffffffff); | |
2562 | else | |
2563 | printf ("%-17.17s", rtype2); | |
2564 | ||
2565 | printf ("\n Type3: "); | |
2566 | ||
2567 | if (rtype3 == NULL) | |
2568 | printf (_("unrecognized: %-7lx"), | |
2569 | (unsigned long) type3 & 0xffffffff); | |
2570 | else | |
2571 | printf ("%-17.17s", rtype3); | |
2572 | ||
2573 | putchar ('\n'); | |
2574 | } | |
2575 | } | |
2576 | ||
2577 | free (rels); | |
2578 | ||
2579 | return res; | |
2580 | } | |
2581 | ||
2582 | static const char * | |
2583 | get_aarch64_dynamic_type (unsigned long type) | |
2584 | { | |
2585 | switch (type) | |
2586 | { | |
2587 | case DT_AARCH64_BTI_PLT: return "AARCH64_BTI_PLT"; | |
2588 | case DT_AARCH64_PAC_PLT: return "AARCH64_PAC_PLT"; | |
2589 | case DT_AARCH64_VARIANT_PCS: return "AARCH64_VARIANT_PCS"; | |
2590 | case DT_AARCH64_MEMTAG_MODE: return "AARCH64_MEMTAG_MODE"; | |
2591 | case DT_AARCH64_MEMTAG_STACK: return "AARCH64_MEMTAG_STACK"; | |
2592 | ||
2593 | default: | |
2594 | return NULL; | |
2595 | } | |
2596 | } | |
2597 | ||
2598 | static const char * | |
2599 | get_mips_dynamic_type (unsigned long type) | |
2600 | { | |
2601 | switch (type) | |
2602 | { | |
2603 | case DT_MIPS_RLD_VERSION: return "MIPS_RLD_VERSION"; | |
2604 | case DT_MIPS_TIME_STAMP: return "MIPS_TIME_STAMP"; | |
2605 | case DT_MIPS_ICHECKSUM: return "MIPS_ICHECKSUM"; | |
2606 | case DT_MIPS_IVERSION: return "MIPS_IVERSION"; | |
2607 | case DT_MIPS_FLAGS: return "MIPS_FLAGS"; | |
2608 | case DT_MIPS_BASE_ADDRESS: return "MIPS_BASE_ADDRESS"; | |
2609 | case DT_MIPS_MSYM: return "MIPS_MSYM"; | |
2610 | case DT_MIPS_CONFLICT: return "MIPS_CONFLICT"; | |
2611 | case DT_MIPS_LIBLIST: return "MIPS_LIBLIST"; | |
2612 | case DT_MIPS_LOCAL_GOTNO: return "MIPS_LOCAL_GOTNO"; | |
2613 | case DT_MIPS_CONFLICTNO: return "MIPS_CONFLICTNO"; | |
2614 | case DT_MIPS_LIBLISTNO: return "MIPS_LIBLISTNO"; | |
2615 | case DT_MIPS_SYMTABNO: return "MIPS_SYMTABNO"; | |
2616 | case DT_MIPS_UNREFEXTNO: return "MIPS_UNREFEXTNO"; | |
2617 | case DT_MIPS_GOTSYM: return "MIPS_GOTSYM"; | |
2618 | case DT_MIPS_HIPAGENO: return "MIPS_HIPAGENO"; | |
2619 | case DT_MIPS_RLD_MAP: return "MIPS_RLD_MAP"; | |
2620 | case DT_MIPS_RLD_MAP_REL: return "MIPS_RLD_MAP_REL"; | |
2621 | case DT_MIPS_DELTA_CLASS: return "MIPS_DELTA_CLASS"; | |
2622 | case DT_MIPS_DELTA_CLASS_NO: return "MIPS_DELTA_CLASS_NO"; | |
2623 | case DT_MIPS_DELTA_INSTANCE: return "MIPS_DELTA_INSTANCE"; | |
2624 | case DT_MIPS_DELTA_INSTANCE_NO: return "MIPS_DELTA_INSTANCE_NO"; | |
2625 | case DT_MIPS_DELTA_RELOC: return "MIPS_DELTA_RELOC"; | |
2626 | case DT_MIPS_DELTA_RELOC_NO: return "MIPS_DELTA_RELOC_NO"; | |
2627 | case DT_MIPS_DELTA_SYM: return "MIPS_DELTA_SYM"; | |
2628 | case DT_MIPS_DELTA_SYM_NO: return "MIPS_DELTA_SYM_NO"; | |
2629 | case DT_MIPS_DELTA_CLASSSYM: return "MIPS_DELTA_CLASSSYM"; | |
2630 | case DT_MIPS_DELTA_CLASSSYM_NO: return "MIPS_DELTA_CLASSSYM_NO"; | |
2631 | case DT_MIPS_CXX_FLAGS: return "MIPS_CXX_FLAGS"; | |
2632 | case DT_MIPS_PIXIE_INIT: return "MIPS_PIXIE_INIT"; | |
2633 | case DT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB"; | |
2634 | case DT_MIPS_LOCALPAGE_GOTIDX: return "MIPS_LOCALPAGE_GOTIDX"; | |
2635 | case DT_MIPS_LOCAL_GOTIDX: return "MIPS_LOCAL_GOTIDX"; | |
2636 | case DT_MIPS_HIDDEN_GOTIDX: return "MIPS_HIDDEN_GOTIDX"; | |
2637 | case DT_MIPS_PROTECTED_GOTIDX: return "MIPS_PROTECTED_GOTIDX"; | |
2638 | case DT_MIPS_OPTIONS: return "MIPS_OPTIONS"; | |
2639 | case DT_MIPS_INTERFACE: return "MIPS_INTERFACE"; | |
2640 | case DT_MIPS_DYNSTR_ALIGN: return "MIPS_DYNSTR_ALIGN"; | |
2641 | case DT_MIPS_INTERFACE_SIZE: return "MIPS_INTERFACE_SIZE"; | |
2642 | case DT_MIPS_RLD_TEXT_RESOLVE_ADDR: return "MIPS_RLD_TEXT_RESOLVE_ADDR"; | |
2643 | case DT_MIPS_PERF_SUFFIX: return "MIPS_PERF_SUFFIX"; | |
2644 | case DT_MIPS_COMPACT_SIZE: return "MIPS_COMPACT_SIZE"; | |
2645 | case DT_MIPS_GP_VALUE: return "MIPS_GP_VALUE"; | |
2646 | case DT_MIPS_AUX_DYNAMIC: return "MIPS_AUX_DYNAMIC"; | |
2647 | case DT_MIPS_PLTGOT: return "MIPS_PLTGOT"; | |
2648 | case DT_MIPS_RWPLT: return "MIPS_RWPLT"; | |
2649 | case DT_MIPS_XHASH: return "MIPS_XHASH"; | |
2650 | default: | |
2651 | return NULL; | |
2652 | } | |
2653 | } | |
2654 | ||
2655 | static const char * | |
2656 | get_sparc64_dynamic_type (unsigned long type) | |
2657 | { | |
2658 | switch (type) | |
2659 | { | |
2660 | case DT_SPARC_REGISTER: return "SPARC_REGISTER"; | |
2661 | default: | |
2662 | return NULL; | |
2663 | } | |
2664 | } | |
2665 | ||
2666 | static const char * | |
2667 | get_ppc_dynamic_type (unsigned long type) | |
2668 | { | |
2669 | switch (type) | |
2670 | { | |
2671 | case DT_PPC_GOT: return "PPC_GOT"; | |
2672 | case DT_PPC_OPT: return "PPC_OPT"; | |
2673 | default: | |
2674 | return NULL; | |
2675 | } | |
2676 | } | |
2677 | ||
2678 | static const char * | |
2679 | get_ppc64_dynamic_type (unsigned long type) | |
2680 | { | |
2681 | switch (type) | |
2682 | { | |
2683 | case DT_PPC64_GLINK: return "PPC64_GLINK"; | |
2684 | case DT_PPC64_OPD: return "PPC64_OPD"; | |
2685 | case DT_PPC64_OPDSZ: return "PPC64_OPDSZ"; | |
2686 | case DT_PPC64_OPT: return "PPC64_OPT"; | |
2687 | default: | |
2688 | return NULL; | |
2689 | } | |
2690 | } | |
2691 | ||
2692 | static const char * | |
2693 | get_parisc_dynamic_type (unsigned long type) | |
2694 | { | |
2695 | switch (type) | |
2696 | { | |
2697 | case DT_HP_LOAD_MAP: return "HP_LOAD_MAP"; | |
2698 | case DT_HP_DLD_FLAGS: return "HP_DLD_FLAGS"; | |
2699 | case DT_HP_DLD_HOOK: return "HP_DLD_HOOK"; | |
2700 | case DT_HP_UX10_INIT: return "HP_UX10_INIT"; | |
2701 | case DT_HP_UX10_INITSZ: return "HP_UX10_INITSZ"; | |
2702 | case DT_HP_PREINIT: return "HP_PREINIT"; | |
2703 | case DT_HP_PREINITSZ: return "HP_PREINITSZ"; | |
2704 | case DT_HP_NEEDED: return "HP_NEEDED"; | |
2705 | case DT_HP_TIME_STAMP: return "HP_TIME_STAMP"; | |
2706 | case DT_HP_CHECKSUM: return "HP_CHECKSUM"; | |
2707 | case DT_HP_GST_SIZE: return "HP_GST_SIZE"; | |
2708 | case DT_HP_GST_VERSION: return "HP_GST_VERSION"; | |
2709 | case DT_HP_GST_HASHVAL: return "HP_GST_HASHVAL"; | |
2710 | case DT_HP_EPLTREL: return "HP_GST_EPLTREL"; | |
2711 | case DT_HP_EPLTRELSZ: return "HP_GST_EPLTRELSZ"; | |
2712 | case DT_HP_FILTERED: return "HP_FILTERED"; | |
2713 | case DT_HP_FILTER_TLS: return "HP_FILTER_TLS"; | |
2714 | case DT_HP_COMPAT_FILTERED: return "HP_COMPAT_FILTERED"; | |
2715 | case DT_HP_LAZYLOAD: return "HP_LAZYLOAD"; | |
2716 | case DT_HP_BIND_NOW_COUNT: return "HP_BIND_NOW_COUNT"; | |
2717 | case DT_PLT: return "PLT"; | |
2718 | case DT_PLT_SIZE: return "PLT_SIZE"; | |
2719 | case DT_DLT: return "DLT"; | |
2720 | case DT_DLT_SIZE: return "DLT_SIZE"; | |
2721 | default: | |
2722 | return NULL; | |
2723 | } | |
2724 | } | |
2725 | ||
2726 | static const char * | |
2727 | get_ia64_dynamic_type (unsigned long type) | |
2728 | { | |
2729 | switch (type) | |
2730 | { | |
2731 | case DT_IA_64_PLT_RESERVE: return "IA_64_PLT_RESERVE"; | |
2732 | case DT_IA_64_VMS_SUBTYPE: return "VMS_SUBTYPE"; | |
2733 | case DT_IA_64_VMS_IMGIOCNT: return "VMS_IMGIOCNT"; | |
2734 | case DT_IA_64_VMS_LNKFLAGS: return "VMS_LNKFLAGS"; | |
2735 | case DT_IA_64_VMS_VIR_MEM_BLK_SIZ: return "VMS_VIR_MEM_BLK_SIZ"; | |
2736 | case DT_IA_64_VMS_IDENT: return "VMS_IDENT"; | |
2737 | case DT_IA_64_VMS_NEEDED_IDENT: return "VMS_NEEDED_IDENT"; | |
2738 | case DT_IA_64_VMS_IMG_RELA_CNT: return "VMS_IMG_RELA_CNT"; | |
2739 | case DT_IA_64_VMS_SEG_RELA_CNT: return "VMS_SEG_RELA_CNT"; | |
2740 | case DT_IA_64_VMS_FIXUP_RELA_CNT: return "VMS_FIXUP_RELA_CNT"; | |
2741 | case DT_IA_64_VMS_FIXUP_NEEDED: return "VMS_FIXUP_NEEDED"; | |
2742 | case DT_IA_64_VMS_SYMVEC_CNT: return "VMS_SYMVEC_CNT"; | |
2743 | case DT_IA_64_VMS_XLATED: return "VMS_XLATED"; | |
2744 | case DT_IA_64_VMS_STACKSIZE: return "VMS_STACKSIZE"; | |
2745 | case DT_IA_64_VMS_UNWINDSZ: return "VMS_UNWINDSZ"; | |
2746 | case DT_IA_64_VMS_UNWIND_CODSEG: return "VMS_UNWIND_CODSEG"; | |
2747 | case DT_IA_64_VMS_UNWIND_INFOSEG: return "VMS_UNWIND_INFOSEG"; | |
2748 | case DT_IA_64_VMS_LINKTIME: return "VMS_LINKTIME"; | |
2749 | case DT_IA_64_VMS_SEG_NO: return "VMS_SEG_NO"; | |
2750 | case DT_IA_64_VMS_SYMVEC_OFFSET: return "VMS_SYMVEC_OFFSET"; | |
2751 | case DT_IA_64_VMS_SYMVEC_SEG: return "VMS_SYMVEC_SEG"; | |
2752 | case DT_IA_64_VMS_UNWIND_OFFSET: return "VMS_UNWIND_OFFSET"; | |
2753 | case DT_IA_64_VMS_UNWIND_SEG: return "VMS_UNWIND_SEG"; | |
2754 | case DT_IA_64_VMS_STRTAB_OFFSET: return "VMS_STRTAB_OFFSET"; | |
2755 | case DT_IA_64_VMS_SYSVER_OFFSET: return "VMS_SYSVER_OFFSET"; | |
2756 | case DT_IA_64_VMS_IMG_RELA_OFF: return "VMS_IMG_RELA_OFF"; | |
2757 | case DT_IA_64_VMS_SEG_RELA_OFF: return "VMS_SEG_RELA_OFF"; | |
2758 | case DT_IA_64_VMS_FIXUP_RELA_OFF: return "VMS_FIXUP_RELA_OFF"; | |
2759 | case DT_IA_64_VMS_PLTGOT_OFFSET: return "VMS_PLTGOT_OFFSET"; | |
2760 | case DT_IA_64_VMS_PLTGOT_SEG: return "VMS_PLTGOT_SEG"; | |
2761 | case DT_IA_64_VMS_FPMODE: return "VMS_FPMODE"; | |
2762 | default: | |
2763 | return NULL; | |
2764 | } | |
2765 | } | |
2766 | ||
2767 | static const char * | |
2768 | get_solaris_section_type (unsigned long type) | |
2769 | { | |
2770 | switch (type) | |
2771 | { | |
2772 | case 0x6fffffee: return "SUNW_ancillary"; | |
2773 | case 0x6fffffef: return "SUNW_capchain"; | |
2774 | case 0x6ffffff0: return "SUNW_capinfo"; | |
2775 | case 0x6ffffff1: return "SUNW_symsort"; | |
2776 | case 0x6ffffff2: return "SUNW_tlssort"; | |
2777 | case 0x6ffffff3: return "SUNW_LDYNSYM"; | |
2778 | case 0x6ffffff4: return "SUNW_dof"; | |
2779 | case 0x6ffffff5: return "SUNW_cap"; | |
2780 | case 0x6ffffff6: return "SUNW_SIGNATURE"; | |
2781 | case 0x6ffffff7: return "SUNW_ANNOTATE"; | |
2782 | case 0x6ffffff8: return "SUNW_DEBUGSTR"; | |
2783 | case 0x6ffffff9: return "SUNW_DEBUG"; | |
2784 | case 0x6ffffffa: return "SUNW_move"; | |
2785 | case 0x6ffffffb: return "SUNW_COMDAT"; | |
2786 | case 0x6ffffffc: return "SUNW_syminfo"; | |
2787 | case 0x6ffffffd: return "SUNW_verdef"; | |
2788 | case 0x6ffffffe: return "SUNW_verneed"; | |
2789 | case 0x6fffffff: return "SUNW_versym"; | |
2790 | case 0x70000000: return "SPARC_GOTDATA"; | |
2791 | default: return NULL; | |
2792 | } | |
2793 | } | |
2794 | ||
2795 | static const char * | |
2796 | get_alpha_dynamic_type (unsigned long type) | |
2797 | { | |
2798 | switch (type) | |
2799 | { | |
2800 | case DT_ALPHA_PLTRO: return "ALPHA_PLTRO"; | |
2801 | default: return NULL; | |
2802 | } | |
2803 | } | |
2804 | ||
2805 | static const char * | |
2806 | get_score_dynamic_type (unsigned long type) | |
2807 | { | |
2808 | switch (type) | |
2809 | { | |
2810 | case DT_SCORE_BASE_ADDRESS: return "SCORE_BASE_ADDRESS"; | |
2811 | case DT_SCORE_LOCAL_GOTNO: return "SCORE_LOCAL_GOTNO"; | |
2812 | case DT_SCORE_SYMTABNO: return "SCORE_SYMTABNO"; | |
2813 | case DT_SCORE_GOTSYM: return "SCORE_GOTSYM"; | |
2814 | case DT_SCORE_UNREFEXTNO: return "SCORE_UNREFEXTNO"; | |
2815 | case DT_SCORE_HIPAGENO: return "SCORE_HIPAGENO"; | |
2816 | default: return NULL; | |
2817 | } | |
2818 | } | |
2819 | ||
2820 | static const char * | |
2821 | get_tic6x_dynamic_type (unsigned long type) | |
2822 | { | |
2823 | switch (type) | |
2824 | { | |
2825 | case DT_C6000_GSYM_OFFSET: return "C6000_GSYM_OFFSET"; | |
2826 | case DT_C6000_GSTR_OFFSET: return "C6000_GSTR_OFFSET"; | |
2827 | case DT_C6000_DSBT_BASE: return "C6000_DSBT_BASE"; | |
2828 | case DT_C6000_DSBT_SIZE: return "C6000_DSBT_SIZE"; | |
2829 | case DT_C6000_PREEMPTMAP: return "C6000_PREEMPTMAP"; | |
2830 | case DT_C6000_DSBT_INDEX: return "C6000_DSBT_INDEX"; | |
2831 | default: return NULL; | |
2832 | } | |
2833 | } | |
2834 | ||
2835 | static const char * | |
2836 | get_nios2_dynamic_type (unsigned long type) | |
2837 | { | |
2838 | switch (type) | |
2839 | { | |
2840 | case DT_NIOS2_GP: return "NIOS2_GP"; | |
2841 | default: return NULL; | |
2842 | } | |
2843 | } | |
2844 | ||
2845 | static const char * | |
2846 | get_solaris_dynamic_type (unsigned long type) | |
2847 | { | |
2848 | switch (type) | |
2849 | { | |
2850 | case 0x6000000d: return "SUNW_AUXILIARY"; | |
2851 | case 0x6000000e: return "SUNW_RTLDINF"; | |
2852 | case 0x6000000f: return "SUNW_FILTER"; | |
2853 | case 0x60000010: return "SUNW_CAP"; | |
2854 | case 0x60000011: return "SUNW_SYMTAB"; | |
2855 | case 0x60000012: return "SUNW_SYMSZ"; | |
2856 | case 0x60000013: return "SUNW_SORTENT"; | |
2857 | case 0x60000014: return "SUNW_SYMSORT"; | |
2858 | case 0x60000015: return "SUNW_SYMSORTSZ"; | |
2859 | case 0x60000016: return "SUNW_TLSSORT"; | |
2860 | case 0x60000017: return "SUNW_TLSSORTSZ"; | |
2861 | case 0x60000018: return "SUNW_CAPINFO"; | |
2862 | case 0x60000019: return "SUNW_STRPAD"; | |
2863 | case 0x6000001a: return "SUNW_CAPCHAIN"; | |
2864 | case 0x6000001b: return "SUNW_LDMACH"; | |
2865 | case 0x6000001d: return "SUNW_CAPCHAINENT"; | |
2866 | case 0x6000001f: return "SUNW_CAPCHAINSZ"; | |
2867 | case 0x60000021: return "SUNW_PARENT"; | |
2868 | case 0x60000023: return "SUNW_ASLR"; | |
2869 | case 0x60000025: return "SUNW_RELAX"; | |
2870 | case 0x60000029: return "SUNW_NXHEAP"; | |
2871 | case 0x6000002b: return "SUNW_NXSTACK"; | |
2872 | ||
2873 | case 0x70000001: return "SPARC_REGISTER"; | |
2874 | case 0x7ffffffd: return "AUXILIARY"; | |
2875 | case 0x7ffffffe: return "USED"; | |
2876 | case 0x7fffffff: return "FILTER"; | |
2877 | ||
2878 | default: return NULL; | |
2879 | } | |
2880 | } | |
2881 | ||
2882 | static const char * | |
2883 | get_riscv_dynamic_type (unsigned long type) | |
2884 | { | |
2885 | switch (type) | |
2886 | { | |
2887 | case DT_RISCV_VARIANT_CC: return "RISCV_VARIANT_CC"; | |
2888 | default: | |
2889 | return NULL; | |
2890 | } | |
2891 | } | |
2892 | ||
2893 | static const char * | |
2894 | get_x86_64_dynamic_type (unsigned long type) | |
2895 | { | |
2896 | switch (type) | |
2897 | { | |
2898 | case DT_X86_64_PLT: | |
2899 | return "DT_X86_64_PLT"; | |
2900 | case DT_X86_64_PLTSZ: | |
2901 | return "DT_X86_64_PLTSZ"; | |
2902 | case DT_X86_64_PLTENT: | |
2903 | return "DT_X86_64_PLTENT"; | |
2904 | default: | |
2905 | return NULL; | |
2906 | } | |
2907 | } | |
2908 | ||
2909 | static const char * | |
2910 | get_dynamic_type (Filedata * filedata, unsigned long type) | |
2911 | { | |
2912 | static char buff[64]; | |
2913 | ||
2914 | switch (type) | |
2915 | { | |
2916 | case DT_NULL: return "NULL"; | |
2917 | case DT_NEEDED: return "NEEDED"; | |
2918 | case DT_PLTRELSZ: return "PLTRELSZ"; | |
2919 | case DT_PLTGOT: return "PLTGOT"; | |
2920 | case DT_HASH: return "HASH"; | |
2921 | case DT_STRTAB: return "STRTAB"; | |
2922 | case DT_SYMTAB: return "SYMTAB"; | |
2923 | case DT_RELA: return "RELA"; | |
2924 | case DT_RELASZ: return "RELASZ"; | |
2925 | case DT_RELAENT: return "RELAENT"; | |
2926 | case DT_STRSZ: return "STRSZ"; | |
2927 | case DT_SYMENT: return "SYMENT"; | |
2928 | case DT_INIT: return "INIT"; | |
2929 | case DT_FINI: return "FINI"; | |
2930 | case DT_SONAME: return "SONAME"; | |
2931 | case DT_RPATH: return "RPATH"; | |
2932 | case DT_SYMBOLIC: return "SYMBOLIC"; | |
2933 | case DT_REL: return "REL"; | |
2934 | case DT_RELSZ: return "RELSZ"; | |
2935 | case DT_RELENT: return "RELENT"; | |
2936 | case DT_RELR: return "RELR"; | |
2937 | case DT_RELRSZ: return "RELRSZ"; | |
2938 | case DT_RELRENT: return "RELRENT"; | |
2939 | case DT_PLTREL: return "PLTREL"; | |
2940 | case DT_DEBUG: return "DEBUG"; | |
2941 | case DT_TEXTREL: return "TEXTREL"; | |
2942 | case DT_JMPREL: return "JMPREL"; | |
2943 | case DT_BIND_NOW: return "BIND_NOW"; | |
2944 | case DT_INIT_ARRAY: return "INIT_ARRAY"; | |
2945 | case DT_FINI_ARRAY: return "FINI_ARRAY"; | |
2946 | case DT_INIT_ARRAYSZ: return "INIT_ARRAYSZ"; | |
2947 | case DT_FINI_ARRAYSZ: return "FINI_ARRAYSZ"; | |
2948 | case DT_RUNPATH: return "RUNPATH"; | |
2949 | case DT_FLAGS: return "FLAGS"; | |
2950 | ||
2951 | case DT_PREINIT_ARRAY: return "PREINIT_ARRAY"; | |
2952 | case DT_PREINIT_ARRAYSZ: return "PREINIT_ARRAYSZ"; | |
2953 | case DT_SYMTAB_SHNDX: return "SYMTAB_SHNDX"; | |
2954 | ||
2955 | case DT_CHECKSUM: return "CHECKSUM"; | |
2956 | case DT_PLTPADSZ: return "PLTPADSZ"; | |
2957 | case DT_MOVEENT: return "MOVEENT"; | |
2958 | case DT_MOVESZ: return "MOVESZ"; | |
2959 | case DT_FEATURE: return "FEATURE"; | |
2960 | case DT_POSFLAG_1: return "POSFLAG_1"; | |
2961 | case DT_SYMINSZ: return "SYMINSZ"; | |
2962 | case DT_SYMINENT: return "SYMINENT"; /* aka VALRNGHI */ | |
2963 | ||
2964 | case DT_ADDRRNGLO: return "ADDRRNGLO"; | |
2965 | case DT_CONFIG: return "CONFIG"; | |
2966 | case DT_DEPAUDIT: return "DEPAUDIT"; | |
2967 | case DT_AUDIT: return "AUDIT"; | |
2968 | case DT_PLTPAD: return "PLTPAD"; | |
2969 | case DT_MOVETAB: return "MOVETAB"; | |
2970 | case DT_SYMINFO: return "SYMINFO"; /* aka ADDRRNGHI */ | |
2971 | ||
2972 | case DT_VERSYM: return "VERSYM"; | |
2973 | ||
2974 | case DT_TLSDESC_GOT: return "TLSDESC_GOT"; | |
2975 | case DT_TLSDESC_PLT: return "TLSDESC_PLT"; | |
2976 | case DT_RELACOUNT: return "RELACOUNT"; | |
2977 | case DT_RELCOUNT: return "RELCOUNT"; | |
2978 | case DT_FLAGS_1: return "FLAGS_1"; | |
2979 | case DT_VERDEF: return "VERDEF"; | |
2980 | case DT_VERDEFNUM: return "VERDEFNUM"; | |
2981 | case DT_VERNEED: return "VERNEED"; | |
2982 | case DT_VERNEEDNUM: return "VERNEEDNUM"; | |
2983 | ||
2984 | case DT_AUXILIARY: return "AUXILIARY"; | |
2985 | case DT_USED: return "USED"; | |
2986 | case DT_FILTER: return "FILTER"; | |
2987 | ||
2988 | case DT_GNU_PRELINKED: return "GNU_PRELINKED"; | |
2989 | case DT_GNU_CONFLICT: return "GNU_CONFLICT"; | |
2990 | case DT_GNU_CONFLICTSZ: return "GNU_CONFLICTSZ"; | |
2991 | case DT_GNU_LIBLIST: return "GNU_LIBLIST"; | |
2992 | case DT_GNU_LIBLISTSZ: return "GNU_LIBLISTSZ"; | |
2993 | case DT_GNU_HASH: return "GNU_HASH"; | |
2994 | case DT_GNU_FLAGS_1: return "GNU_FLAGS_1"; | |
2995 | ||
2996 | default: | |
2997 | if ((type >= DT_LOPROC) && (type <= DT_HIPROC)) | |
2998 | { | |
2999 | const char * result; | |
3000 | ||
3001 | switch (filedata->file_header.e_machine) | |
3002 | { | |
3003 | case EM_AARCH64: | |
3004 | result = get_aarch64_dynamic_type (type); | |
3005 | break; | |
3006 | case EM_MIPS: | |
3007 | case EM_MIPS_RS3_LE: | |
3008 | result = get_mips_dynamic_type (type); | |
3009 | break; | |
3010 | case EM_SPARCV9: | |
3011 | result = get_sparc64_dynamic_type (type); | |
3012 | break; | |
3013 | case EM_PPC: | |
3014 | result = get_ppc_dynamic_type (type); | |
3015 | break; | |
3016 | case EM_PPC64: | |
3017 | result = get_ppc64_dynamic_type (type); | |
3018 | break; | |
3019 | case EM_IA_64: | |
3020 | result = get_ia64_dynamic_type (type); | |
3021 | break; | |
3022 | case EM_ALPHA: | |
3023 | result = get_alpha_dynamic_type (type); | |
3024 | break; | |
3025 | case EM_SCORE: | |
3026 | result = get_score_dynamic_type (type); | |
3027 | break; | |
3028 | case EM_TI_C6000: | |
3029 | result = get_tic6x_dynamic_type (type); | |
3030 | break; | |
3031 | case EM_ALTERA_NIOS2: | |
3032 | result = get_nios2_dynamic_type (type); | |
3033 | break; | |
3034 | case EM_RISCV: | |
3035 | result = get_riscv_dynamic_type (type); | |
3036 | break; | |
3037 | case EM_X86_64: | |
3038 | result = get_x86_64_dynamic_type (type); | |
3039 | break; | |
3040 | default: | |
3041 | if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS) | |
3042 | result = get_solaris_dynamic_type (type); | |
3043 | else | |
3044 | result = NULL; | |
3045 | break; | |
3046 | } | |
3047 | ||
3048 | if (result != NULL) | |
3049 | return result; | |
3050 | ||
3051 | snprintf (buff, sizeof (buff), _("Processor Specific: %lx"), type); | |
3052 | } | |
3053 | else if (((type >= DT_LOOS) && (type <= DT_HIOS)) | |
3054 | || (filedata->file_header.e_machine == EM_PARISC | |
3055 | && (type >= OLD_DT_LOOS) && (type <= OLD_DT_HIOS))) | |
3056 | { | |
3057 | const char * result; | |
3058 | ||
3059 | switch (filedata->file_header.e_machine) | |
3060 | { | |
3061 | case EM_PARISC: | |
3062 | result = get_parisc_dynamic_type (type); | |
3063 | break; | |
3064 | case EM_IA_64: | |
3065 | result = get_ia64_dynamic_type (type); | |
3066 | break; | |
3067 | default: | |
3068 | if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS) | |
3069 | result = get_solaris_dynamic_type (type); | |
3070 | else | |
3071 | result = NULL; | |
3072 | break; | |
3073 | } | |
3074 | ||
3075 | if (result != NULL) | |
3076 | return result; | |
3077 | ||
3078 | snprintf (buff, sizeof (buff), _("Operating System specific: %lx"), | |
3079 | type); | |
3080 | } | |
3081 | else | |
3082 | snprintf (buff, sizeof (buff), _("<unknown>: %lx"), type); | |
3083 | ||
3084 | return buff; | |
3085 | } | |
3086 | } | |
3087 | ||
3088 | static bool get_program_headers (Filedata *); | |
3089 | static bool get_dynamic_section (Filedata *); | |
3090 | ||
3091 | static void | |
3092 | locate_dynamic_section (Filedata *filedata) | |
3093 | { | |
3094 | uint64_t dynamic_addr = 0; | |
3095 | uint64_t dynamic_size = 0; | |
3096 | ||
3097 | if (filedata->file_header.e_phnum != 0 | |
3098 | && get_program_headers (filedata)) | |
3099 | { | |
3100 | Elf_Internal_Phdr *segment; | |
3101 | unsigned int i; | |
3102 | ||
3103 | for (i = 0, segment = filedata->program_headers; | |
3104 | i < filedata->file_header.e_phnum; | |
3105 | i++, segment++) | |
3106 | { | |
3107 | if (segment->p_type == PT_DYNAMIC) | |
3108 | { | |
3109 | dynamic_addr = segment->p_offset; | |
3110 | dynamic_size = segment->p_filesz; | |
3111 | ||
3112 | if (filedata->section_headers != NULL) | |
3113 | { | |
3114 | Elf_Internal_Shdr *sec; | |
3115 | ||
3116 | sec = find_section (filedata, ".dynamic"); | |
3117 | if (sec != NULL) | |
3118 | { | |
3119 | if (sec->sh_size == 0 | |
3120 | || sec->sh_type == SHT_NOBITS) | |
3121 | { | |
3122 | dynamic_addr = 0; | |
3123 | dynamic_size = 0; | |
3124 | } | |
3125 | else | |
3126 | { | |
3127 | dynamic_addr = sec->sh_offset; | |
3128 | dynamic_size = sec->sh_size; | |
3129 | } | |
3130 | } | |
3131 | } | |
3132 | ||
3133 | if (dynamic_addr > filedata->file_size | |
3134 | || (dynamic_size > filedata->file_size - dynamic_addr)) | |
3135 | { | |
3136 | dynamic_addr = 0; | |
3137 | dynamic_size = 0; | |
3138 | } | |
3139 | break; | |
3140 | } | |
3141 | } | |
3142 | } | |
3143 | filedata->dynamic_addr = dynamic_addr; | |
3144 | filedata->dynamic_size = dynamic_size ? dynamic_size : 1; | |
3145 | } | |
3146 | ||
3147 | static bool | |
3148 | is_pie (Filedata *filedata) | |
3149 | { | |
3150 | Elf_Internal_Dyn *entry; | |
3151 | ||
3152 | if (filedata->dynamic_size == 0) | |
3153 | locate_dynamic_section (filedata); | |
3154 | if (filedata->dynamic_size <= 1) | |
3155 | return false; | |
3156 | ||
3157 | if (!get_dynamic_section (filedata)) | |
3158 | return false; | |
3159 | ||
3160 | for (entry = filedata->dynamic_section; | |
3161 | entry < filedata->dynamic_section + filedata->dynamic_nent; | |
3162 | entry++) | |
3163 | { | |
3164 | if (entry->d_tag == DT_FLAGS_1) | |
3165 | { | |
3166 | if ((entry->d_un.d_val & DF_1_PIE) != 0) | |
3167 | return true; | |
3168 | break; | |
3169 | } | |
3170 | } | |
3171 | return false; | |
3172 | } | |
3173 | ||
3174 | static char * | |
3175 | get_file_type (Filedata *filedata) | |
3176 | { | |
3177 | unsigned e_type = filedata->file_header.e_type; | |
3178 | static char buff[64]; | |
3179 | ||
3180 | switch (e_type) | |
3181 | { | |
3182 | case ET_NONE: return _("NONE (None)"); | |
3183 | case ET_REL: return _("REL (Relocatable file)"); | |
3184 | case ET_EXEC: return _("EXEC (Executable file)"); | |
3185 | case ET_DYN: | |
3186 | if (is_pie (filedata)) | |
3187 | return _("DYN (Position-Independent Executable file)"); | |
3188 | else | |
3189 | return _("DYN (Shared object file)"); | |
3190 | case ET_CORE: return _("CORE (Core file)"); | |
3191 | ||
3192 | default: | |
3193 | if ((e_type >= ET_LOPROC) && (e_type <= ET_HIPROC)) | |
3194 | snprintf (buff, sizeof (buff), _("Processor Specific: (%x)"), e_type); | |
3195 | else if ((e_type >= ET_LOOS) && (e_type <= ET_HIOS)) | |
3196 | snprintf (buff, sizeof (buff), _("OS Specific: (%x)"), e_type); | |
3197 | else | |
3198 | snprintf (buff, sizeof (buff), _("<unknown>: %x"), e_type); | |
3199 | return buff; | |
3200 | } | |
3201 | } | |
3202 | ||
3203 | static char * | |
3204 | get_machine_name (unsigned e_machine) | |
3205 | { | |
3206 | static char buff[64]; /* XXX */ | |
3207 | ||
3208 | switch (e_machine) | |
3209 | { | |
3210 | /* Please keep this switch table sorted by increasing EM_ value. */ | |
3211 | /* 0 */ | |
3212 | case EM_NONE: return _("None"); | |
3213 | case EM_M32: return "WE32100"; | |
3214 | case EM_SPARC: return "Sparc"; | |
3215 | case EM_386: return "Intel 80386"; | |
3216 | case EM_68K: return "MC68000"; | |
3217 | case EM_88K: return "MC88000"; | |
3218 | case EM_IAMCU: return "Intel MCU"; | |
3219 | case EM_860: return "Intel 80860"; | |
3220 | case EM_MIPS: return "MIPS R3000"; | |
3221 | case EM_S370: return "IBM System/370"; | |
3222 | /* 10 */ | |
3223 | case EM_MIPS_RS3_LE: return "MIPS R4000 big-endian"; | |
3224 | case EM_OLD_SPARCV9: return "Sparc v9 (old)"; | |
3225 | case EM_PARISC: return "HPPA"; | |
3226 | case EM_VPP550: return "Fujitsu VPP500"; | |
3227 | case EM_SPARC32PLUS: return "Sparc v8+" ; | |
3228 | case EM_960: return "Intel 80960"; | |
3229 | case EM_PPC: return "PowerPC"; | |
3230 | /* 20 */ | |
3231 | case EM_PPC64: return "PowerPC64"; | |
3232 | case EM_S390_OLD: | |
3233 | case EM_S390: return "IBM S/390"; | |
3234 | case EM_SPU: return "SPU"; | |
3235 | /* 30 */ | |
3236 | case EM_V800: return "Renesas V850 (using RH850 ABI)"; | |
3237 | case EM_FR20: return "Fujitsu FR20"; | |
3238 | case EM_RH32: return "TRW RH32"; | |
3239 | case EM_MCORE: return "MCORE"; | |
3240 | /* 40 */ | |
3241 | case EM_ARM: return "ARM"; | |
3242 | case EM_OLD_ALPHA: return "Digital Alpha (old)"; | |
3243 | case EM_SH: return "Renesas / SuperH SH"; | |
3244 | case EM_SPARCV9: return "Sparc v9"; | |
3245 | case EM_TRICORE: return "Siemens Tricore"; | |
3246 | case EM_ARC: return "ARC"; | |
3247 | case EM_H8_300: return "Renesas H8/300"; | |
3248 | case EM_H8_300H: return "Renesas H8/300H"; | |
3249 | case EM_H8S: return "Renesas H8S"; | |
3250 | case EM_H8_500: return "Renesas H8/500"; | |
3251 | /* 50 */ | |
3252 | case EM_IA_64: return "Intel IA-64"; | |
3253 | case EM_MIPS_X: return "Stanford MIPS-X"; | |
3254 | case EM_COLDFIRE: return "Motorola Coldfire"; | |
3255 | case EM_68HC12: return "Motorola MC68HC12 Microcontroller"; | |
3256 | case EM_MMA: return "Fujitsu Multimedia Accelerator"; | |
3257 | case EM_PCP: return "Siemens PCP"; | |
3258 | case EM_NCPU: return "Sony nCPU embedded RISC processor"; | |
3259 | case EM_NDR1: return "Denso NDR1 microprocessor"; | |
3260 | case EM_STARCORE: return "Motorola Star*Core processor"; | |
3261 | case EM_ME16: return "Toyota ME16 processor"; | |
3262 | /* 60 */ | |
3263 | case EM_ST100: return "STMicroelectronics ST100 processor"; | |
3264 | case EM_TINYJ: return "Advanced Logic Corp. TinyJ embedded processor"; | |
3265 | case EM_X86_64: return "Advanced Micro Devices X86-64"; | |
3266 | case EM_PDSP: return "Sony DSP processor"; | |
3267 | case EM_PDP10: return "Digital Equipment Corp. PDP-10"; | |
3268 | case EM_PDP11: return "Digital Equipment Corp. PDP-11"; | |
3269 | case EM_FX66: return "Siemens FX66 microcontroller"; | |
3270 | case EM_ST9PLUS: return "STMicroelectronics ST9+ 8/16 bit microcontroller"; | |
3271 | case EM_ST7: return "STMicroelectronics ST7 8-bit microcontroller"; | |
3272 | case EM_68HC16: return "Motorola MC68HC16 Microcontroller"; | |
3273 | /* 70 */ | |
3274 | case EM_68HC11: return "Motorola MC68HC11 Microcontroller"; | |
3275 | case EM_68HC08: return "Motorola MC68HC08 Microcontroller"; | |
3276 | case EM_68HC05: return "Motorola MC68HC05 Microcontroller"; | |
3277 | case EM_SVX: return "Silicon Graphics SVx"; | |
3278 | case EM_ST19: return "STMicroelectronics ST19 8-bit microcontroller"; | |
3279 | case EM_VAX: return "Digital VAX"; | |
3280 | case EM_CRIS: return "Axis Communications 32-bit embedded processor"; | |
3281 | case EM_JAVELIN: return "Infineon Technologies 32-bit embedded cpu"; | |
3282 | case EM_FIREPATH: return "Element 14 64-bit DSP processor"; | |
3283 | case EM_ZSP: return "LSI Logic's 16-bit DSP processor"; | |
3284 | /* 80 */ | |
3285 | case EM_MMIX: return "Donald Knuth's educational 64-bit processor"; | |
3286 | case EM_HUANY: return "Harvard Universitys's machine-independent object format"; | |
3287 | case EM_PRISM: return "Vitesse Prism"; | |
3288 | case EM_AVR_OLD: | |
3289 | case EM_AVR: return "Atmel AVR 8-bit microcontroller"; | |
3290 | case EM_CYGNUS_FR30: | |
3291 | case EM_FR30: return "Fujitsu FR30"; | |
3292 | case EM_CYGNUS_D10V: | |
3293 | case EM_D10V: return "d10v"; | |
3294 | case EM_CYGNUS_D30V: | |
3295 | case EM_D30V: return "d30v"; | |
3296 | case EM_CYGNUS_V850: | |
3297 | case EM_V850: return "Renesas V850"; | |
3298 | case EM_CYGNUS_M32R: | |
3299 | case EM_M32R: return "Renesas M32R (formerly Mitsubishi M32r)"; | |
3300 | case EM_CYGNUS_MN10300: | |
3301 | case EM_MN10300: return "mn10300"; | |
3302 | /* 90 */ | |
3303 | case EM_CYGNUS_MN10200: | |
3304 | case EM_MN10200: return "mn10200"; | |
3305 | case EM_PJ: return "picoJava"; | |
3306 | case EM_OR1K: return "OpenRISC 1000"; | |
3307 | case EM_ARC_COMPACT: return "ARCompact"; | |
3308 | case EM_XTENSA_OLD: | |
3309 | case EM_XTENSA: return "Tensilica Xtensa Processor"; | |
3310 | case EM_VIDEOCORE: return "Alphamosaic VideoCore processor"; | |
3311 | case EM_TMM_GPP: return "Thompson Multimedia General Purpose Processor"; | |
3312 | case EM_NS32K: return "National Semiconductor 32000 series"; | |
3313 | case EM_TPC: return "Tenor Network TPC processor"; | |
3314 | case EM_SNP1K: return "Trebia SNP 1000 processor"; | |
3315 | /* 100 */ | |
3316 | case EM_ST200: return "STMicroelectronics ST200 microcontroller"; | |
3317 | case EM_IP2K_OLD: | |
3318 | case EM_IP2K: return "Ubicom IP2xxx 8-bit microcontrollers"; | |
3319 | case EM_MAX: return "MAX Processor"; | |
3320 | case EM_CR: return "National Semiconductor CompactRISC"; | |
3321 | case EM_F2MC16: return "Fujitsu F2MC16"; | |
3322 | case EM_MSP430: return "Texas Instruments msp430 microcontroller"; | |
3323 | case EM_BLACKFIN: return "Analog Devices Blackfin"; | |
3324 | case EM_SE_C33: return "S1C33 Family of Seiko Epson processors"; | |
3325 | case EM_SEP: return "Sharp embedded microprocessor"; | |
3326 | case EM_ARCA: return "Arca RISC microprocessor"; | |
3327 | /* 110 */ | |
3328 | case EM_UNICORE: return "Unicore"; | |
3329 | case EM_EXCESS: return "eXcess 16/32/64-bit configurable embedded CPU"; | |
3330 | case EM_DXP: return "Icera Semiconductor Inc. Deep Execution Processor"; | |
3331 | case EM_ALTERA_NIOS2: return "Altera Nios II"; | |
3332 | case EM_CRX: return "National Semiconductor CRX microprocessor"; | |
3333 | case EM_XGATE: return "Motorola XGATE embedded processor"; | |
3334 | case EM_C166: | |
3335 | case EM_XC16X: return "Infineon Technologies xc16x"; | |
3336 | case EM_M16C: return "Renesas M16C series microprocessors"; | |
3337 | case EM_DSPIC30F: return "Microchip Technology dsPIC30F Digital Signal Controller"; | |
3338 | case EM_CE: return "Freescale Communication Engine RISC core"; | |
3339 | /* 120 */ | |
3340 | case EM_M32C: return "Renesas M32c"; | |
3341 | /* 130 */ | |
3342 | case EM_TSK3000: return "Altium TSK3000 core"; | |
3343 | case EM_RS08: return "Freescale RS08 embedded processor"; | |
3344 | case EM_ECOG2: return "Cyan Technology eCOG2 microprocessor"; | |
3345 | case EM_SCORE: return "SUNPLUS S+Core"; | |
3346 | case EM_DSP24: return "New Japan Radio (NJR) 24-bit DSP Processor"; | |
3347 | case EM_VIDEOCORE3: return "Broadcom VideoCore III processor"; | |
3348 | case EM_LATTICEMICO32: return "Lattice Mico32"; | |
3349 | case EM_SE_C17: return "Seiko Epson C17 family"; | |
3350 | /* 140 */ | |
3351 | case EM_TI_C6000: return "Texas Instruments TMS320C6000 DSP family"; | |
3352 | case EM_TI_C2000: return "Texas Instruments TMS320C2000 DSP family"; | |
3353 | case EM_TI_C5500: return "Texas Instruments TMS320C55x DSP family"; | |
3354 | case EM_TI_PRU: return "TI PRU I/O processor"; | |
3355 | /* 160 */ | |
3356 | case EM_MMDSP_PLUS: return "STMicroelectronics 64bit VLIW Data Signal Processor"; | |
3357 | case EM_CYPRESS_M8C: return "Cypress M8C microprocessor"; | |
3358 | case EM_R32C: return "Renesas R32C series microprocessors"; | |
3359 | case EM_TRIMEDIA: return "NXP Semiconductors TriMedia architecture family"; | |
3360 | case EM_QDSP6: return "QUALCOMM DSP6 Processor"; | |
3361 | case EM_8051: return "Intel 8051 and variants"; | |
3362 | case EM_STXP7X: return "STMicroelectronics STxP7x family"; | |
3363 | case EM_NDS32: return "Andes Technology compact code size embedded RISC processor family"; | |
3364 | case EM_ECOG1X: return "Cyan Technology eCOG1X family"; | |
3365 | case EM_MAXQ30: return "Dallas Semiconductor MAXQ30 Core microcontrollers"; | |
3366 | /* 170 */ | |
3367 | case EM_XIMO16: return "New Japan Radio (NJR) 16-bit DSP Processor"; | |
3368 | case EM_MANIK: return "M2000 Reconfigurable RISC Microprocessor"; | |
3369 | case EM_CRAYNV2: return "Cray Inc. NV2 vector architecture"; | |
3370 | case EM_RX: return "Renesas RX"; | |
3371 | case EM_METAG: return "Imagination Technologies Meta processor architecture"; | |
3372 | case EM_MCST_ELBRUS: return "MCST Elbrus general purpose hardware architecture"; | |
3373 | case EM_ECOG16: return "Cyan Technology eCOG16 family"; | |
3374 | case EM_CR16: | |
3375 | case EM_MICROBLAZE: | |
3376 | case EM_MICROBLAZE_OLD: return "Xilinx MicroBlaze"; | |
3377 | case EM_ETPU: return "Freescale Extended Time Processing Unit"; | |
3378 | case EM_SLE9X: return "Infineon Technologies SLE9X core"; | |
3379 | /* 180 */ | |
3380 | case EM_L1OM: return "Intel L1OM"; | |
3381 | case EM_K1OM: return "Intel K1OM"; | |
3382 | case EM_INTEL182: return "Intel (reserved)"; | |
3383 | case EM_AARCH64: return "AArch64"; | |
3384 | case EM_ARM184: return "ARM (reserved)"; | |
3385 | case EM_AVR32: return "Atmel Corporation 32-bit microprocessor"; | |
3386 | case EM_STM8: return "STMicroeletronics STM8 8-bit microcontroller"; | |
3387 | case EM_TILE64: return "Tilera TILE64 multicore architecture family"; | |
3388 | case EM_TILEPRO: return "Tilera TILEPro multicore architecture family"; | |
3389 | /* 190 */ | |
3390 | case EM_CUDA: return "NVIDIA CUDA architecture"; | |
3391 | case EM_TILEGX: return "Tilera TILE-Gx multicore architecture family"; | |
3392 | case EM_CLOUDSHIELD: return "CloudShield architecture family"; | |
3393 | case EM_COREA_1ST: return "KIPO-KAIST Core-A 1st generation processor family"; | |
3394 | case EM_COREA_2ND: return "KIPO-KAIST Core-A 2nd generation processor family"; | |
3395 | case EM_ARC_COMPACT2: return "ARCv2"; | |
3396 | case EM_OPEN8: return "Open8 8-bit RISC soft processor core"; | |
3397 | case EM_RL78: return "Renesas RL78"; | |
3398 | case EM_VIDEOCORE5: return "Broadcom VideoCore V processor"; | |
3399 | case EM_78K0R: return "Renesas 78K0R"; | |
3400 | /* 200 */ | |
3401 | case EM_56800EX: return "Freescale 56800EX Digital Signal Controller (DSC)"; | |
3402 | case EM_BA1: return "Beyond BA1 CPU architecture"; | |
3403 | case EM_BA2: return "Beyond BA2 CPU architecture"; | |
3404 | case EM_XCORE: return "XMOS xCORE processor family"; | |
3405 | case EM_MCHP_PIC: return "Microchip 8-bit PIC(r) family"; | |
3406 | case EM_INTELGT: return "Intel Graphics Technology"; | |
3407 | /* 210 */ | |
3408 | case EM_KM32: return "KM211 KM32 32-bit processor"; | |
3409 | case EM_KMX32: return "KM211 KMX32 32-bit processor"; | |
3410 | case EM_KMX16: return "KM211 KMX16 16-bit processor"; | |
3411 | case EM_KMX8: return "KM211 KMX8 8-bit processor"; | |
3412 | case EM_KVARC: return "KM211 KVARC processor"; | |
3413 | case EM_CDP: return "Paneve CDP architecture family"; | |
3414 | case EM_COGE: return "Cognitive Smart Memory Processor"; | |
3415 | case EM_COOL: return "Bluechip Systems CoolEngine"; | |
3416 | case EM_NORC: return "Nanoradio Optimized RISC"; | |
3417 | case EM_CSR_KALIMBA: return "CSR Kalimba architecture family"; | |
3418 | /* 220 */ | |
3419 | case EM_Z80: return "Zilog Z80"; | |
3420 | case EM_VISIUM: return "CDS VISIUMcore processor"; | |
3421 | case EM_FT32: return "FTDI Chip FT32"; | |
3422 | case EM_MOXIE: return "Moxie"; | |
3423 | case EM_AMDGPU: return "AMD GPU"; | |
3424 | /* 230 (all reserved) */ | |
3425 | /* 240 */ | |
3426 | case EM_RISCV: return "RISC-V"; | |
3427 | case EM_LANAI: return "Lanai 32-bit processor"; | |
3428 | case EM_CEVA: return "CEVA Processor Architecture Family"; | |
3429 | case EM_CEVA_X2: return "CEVA X2 Processor Family"; | |
3430 | case EM_BPF: return "Linux BPF"; | |
3431 | case EM_GRAPHCORE_IPU: return "Graphcore Intelligent Processing Unit"; | |
3432 | case EM_IMG1: return "Imagination Technologies"; | |
3433 | /* 250 */ | |
3434 | case EM_NFP: return "Netronome Flow Processor"; | |
3435 | case EM_VE: return "NEC Vector Engine"; | |
3436 | case EM_CSKY: return "C-SKY"; | |
3437 | case EM_ARC_COMPACT3_64: return "Synopsys ARCv3 64-bit processor"; | |
3438 | case EM_MCS6502: return "MOS Technology MCS 6502 processor"; | |
3439 | case EM_ARC_COMPACT3: return "Synopsys ARCv3 32-bit processor"; | |
3440 | case EM_KVX: return "Kalray VLIW core of the MPPA processor family"; | |
3441 | case EM_65816: return "WDC 65816/65C816"; | |
3442 | case EM_LOONGARCH: return "LoongArch"; | |
3443 | case EM_KF32: return "ChipON KungFu32"; | |
3444 | ||
3445 | /* Large numbers... */ | |
3446 | case EM_MT: return "Morpho Techologies MT processor"; | |
3447 | case EM_ALPHA: return "Alpha"; | |
3448 | case EM_WEBASSEMBLY: return "Web Assembly"; | |
3449 | case EM_DLX: return "OpenDLX"; | |
3450 | case EM_XSTORMY16: return "Sanyo XStormy16 CPU core"; | |
3451 | case EM_IQ2000: return "Vitesse IQ2000"; | |
3452 | case EM_M32C_OLD: | |
3453 | case EM_NIOS32: return "Altera Nios"; | |
3454 | case EM_CYGNUS_MEP: return "Toshiba MeP Media Engine"; | |
3455 | case EM_ADAPTEVA_EPIPHANY: return "Adapteva EPIPHANY"; | |
3456 | case EM_CYGNUS_FRV: return "Fujitsu FR-V"; | |
3457 | case EM_S12Z: return "Freescale S12Z"; | |
3458 | ||
3459 | default: | |
3460 | snprintf (buff, sizeof (buff), _("<unknown>: 0x%x"), e_machine); | |
3461 | return buff; | |
3462 | } | |
3463 | } | |
3464 | ||
3465 | static char * | |
3466 | decode_ARC_machine_flags (char *out, unsigned e_flags, unsigned e_machine) | |
3467 | { | |
3468 | /* ARC has two machine types EM_ARC_COMPACT and EM_ARC_COMPACT2. Some | |
3469 | other compilers don't specify an architecture type in the e_flags, and | |
3470 | instead use EM_ARC_COMPACT for old ARC600, ARC601, and ARC700 | |
3471 | architectures, and switch to EM_ARC_COMPACT2 for newer ARCEM and ARCHS | |
3472 | architectures. | |
3473 | ||
3474 | Th GNU tools follows this use of EM_ARC_COMPACT and EM_ARC_COMPACT2, | |
3475 | but also sets a specific architecture type in the e_flags field. | |
3476 | ||
3477 | However, when decoding the flags we don't worry if we see an | |
3478 | unexpected pairing, for example EM_ARC_COMPACT machine type, with | |
3479 | ARCEM architecture type. */ | |
3480 | ||
3481 | switch (e_flags & EF_ARC_MACH_MSK) | |
3482 | { | |
3483 | /* We only expect these to occur for EM_ARC_COMPACT2. */ | |
3484 | case EF_ARC_CPU_ARCV2EM: | |
3485 | out = stpcpy (out, ", ARC EM"); | |
3486 | break; | |
3487 | case EF_ARC_CPU_ARCV2HS: | |
3488 | out = stpcpy (out, ", ARC HS"); | |
3489 | break; | |
3490 | ||
3491 | /* We only expect these to occur for EM_ARC_COMPACT. */ | |
3492 | case E_ARC_MACH_ARC600: | |
3493 | out = stpcpy (out, ", ARC600"); | |
3494 | break; | |
3495 | case E_ARC_MACH_ARC601: | |
3496 | out = stpcpy (out, ", ARC601"); | |
3497 | break; | |
3498 | case E_ARC_MACH_ARC700: | |
3499 | out = stpcpy (out, ", ARC700"); | |
3500 | break; | |
3501 | ||
3502 | /* The only times we should end up here are (a) A corrupt ELF, (b) A | |
3503 | new ELF with new architecture being read by an old version of | |
3504 | readelf, or (c) An ELF built with non-GNU compiler that does not | |
3505 | set the architecture in the e_flags. */ | |
3506 | default: | |
3507 | if (e_machine == EM_ARC_COMPACT) | |
3508 | out = stpcpy (out, ", Unknown ARCompact"); | |
3509 | else | |
3510 | out = stpcpy (out, ", Unknown ARC"); | |
3511 | break; | |
3512 | } | |
3513 | ||
3514 | switch (e_flags & EF_ARC_OSABI_MSK) | |
3515 | { | |
3516 | case E_ARC_OSABI_ORIG: | |
3517 | out = stpcpy (out, ", (ABI:legacy)"); | |
3518 | break; | |
3519 | case E_ARC_OSABI_V2: | |
3520 | out = stpcpy (out, ", (ABI:v2)"); | |
3521 | break; | |
3522 | /* Only upstream 3.9+ kernels will support ARCv2 ISA. */ | |
3523 | case E_ARC_OSABI_V3: | |
3524 | out = stpcpy (out, ", v3 no-legacy-syscalls ABI"); | |
3525 | break; | |
3526 | case E_ARC_OSABI_V4: | |
3527 | out = stpcpy (out, ", v4 ABI"); | |
3528 | break; | |
3529 | default: | |
3530 | out = stpcpy (out, ", unrecognised ARC OSABI flag"); | |
3531 | break; | |
3532 | } | |
3533 | return out; | |
3534 | } | |
3535 | ||
3536 | static char * | |
3537 | decode_ARM_machine_flags (char *out, unsigned e_flags) | |
3538 | { | |
3539 | unsigned eabi; | |
3540 | bool unknown_abi = false; | |
3541 | ||
3542 | eabi = EF_ARM_EABI_VERSION (e_flags); | |
3543 | e_flags &= ~ EF_ARM_EABIMASK; | |
3544 | ||
3545 | /* Handle "generic" ARM flags. */ | |
3546 | if (e_flags & EF_ARM_RELEXEC) | |
3547 | { | |
3548 | out = stpcpy (out, ", relocatable executable"); | |
3549 | e_flags &= ~ EF_ARM_RELEXEC; | |
3550 | } | |
3551 | ||
3552 | if (e_flags & EF_ARM_PIC) | |
3553 | { | |
3554 | out = stpcpy (out, ", position independent"); | |
3555 | e_flags &= ~ EF_ARM_PIC; | |
3556 | } | |
3557 | ||
3558 | /* Now handle EABI specific flags. */ | |
3559 | switch (eabi) | |
3560 | { | |
3561 | default: | |
3562 | out = stpcpy (out, ", <unrecognized EABI>"); | |
3563 | if (e_flags) | |
3564 | unknown_abi = true; | |
3565 | break; | |
3566 | ||
3567 | case EF_ARM_EABI_VER1: | |
3568 | out = stpcpy (out, ", Version1 EABI"); | |
3569 | while (e_flags) | |
3570 | { | |
3571 | unsigned flag; | |
3572 | ||
3573 | /* Process flags one bit at a time. */ | |
3574 | flag = e_flags & - e_flags; | |
3575 | e_flags &= ~ flag; | |
3576 | ||
3577 | switch (flag) | |
3578 | { | |
3579 | case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK. */ | |
3580 | out = stpcpy (out, ", sorted symbol tables"); | |
3581 | break; | |
3582 | ||
3583 | default: | |
3584 | unknown_abi = true; | |
3585 | break; | |
3586 | } | |
3587 | } | |
3588 | break; | |
3589 | ||
3590 | case EF_ARM_EABI_VER2: | |
3591 | out = stpcpy (out, ", Version2 EABI"); | |
3592 | while (e_flags) | |
3593 | { | |
3594 | unsigned flag; | |
3595 | ||
3596 | /* Process flags one bit at a time. */ | |
3597 | flag = e_flags & - e_flags; | |
3598 | e_flags &= ~ flag; | |
3599 | ||
3600 | switch (flag) | |
3601 | { | |
3602 | case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK. */ | |
3603 | out = stpcpy (out, ", sorted symbol tables"); | |
3604 | break; | |
3605 | ||
3606 | case EF_ARM_DYNSYMSUSESEGIDX: | |
3607 | out = stpcpy (out, ", dynamic symbols use segment index"); | |
3608 | break; | |
3609 | ||
3610 | case EF_ARM_MAPSYMSFIRST: | |
3611 | out = stpcpy (out, ", mapping symbols precede others"); | |
3612 | break; | |
3613 | ||
3614 | default: | |
3615 | unknown_abi = true; | |
3616 | break; | |
3617 | } | |
3618 | } | |
3619 | break; | |
3620 | ||
3621 | case EF_ARM_EABI_VER3: | |
3622 | out = stpcpy (out, ", Version3 EABI"); | |
3623 | break; | |
3624 | ||
3625 | case EF_ARM_EABI_VER4: | |
3626 | out = stpcpy (out, ", Version4 EABI"); | |
3627 | while (e_flags) | |
3628 | { | |
3629 | unsigned flag; | |
3630 | ||
3631 | /* Process flags one bit at a time. */ | |
3632 | flag = e_flags & - e_flags; | |
3633 | e_flags &= ~ flag; | |
3634 | ||
3635 | switch (flag) | |
3636 | { | |
3637 | case EF_ARM_BE8: | |
3638 | out = stpcpy (out, ", BE8"); | |
3639 | break; | |
3640 | ||
3641 | case EF_ARM_LE8: | |
3642 | out = stpcpy (out, ", LE8"); | |
3643 | break; | |
3644 | ||
3645 | default: | |
3646 | unknown_abi = true; | |
3647 | break; | |
3648 | } | |
3649 | } | |
3650 | break; | |
3651 | ||
3652 | case EF_ARM_EABI_VER5: | |
3653 | out = stpcpy (out, ", Version5 EABI"); | |
3654 | while (e_flags) | |
3655 | { | |
3656 | unsigned flag; | |
3657 | ||
3658 | /* Process flags one bit at a time. */ | |
3659 | flag = e_flags & - e_flags; | |
3660 | e_flags &= ~ flag; | |
3661 | ||
3662 | switch (flag) | |
3663 | { | |
3664 | case EF_ARM_BE8: | |
3665 | out = stpcpy (out, ", BE8"); | |
3666 | break; | |
3667 | ||
3668 | case EF_ARM_LE8: | |
3669 | out = stpcpy (out, ", LE8"); | |
3670 | break; | |
3671 | ||
3672 | case EF_ARM_ABI_FLOAT_SOFT: /* Conflicts with EF_ARM_SOFT_FLOAT. */ | |
3673 | out = stpcpy (out, ", soft-float ABI"); | |
3674 | break; | |
3675 | ||
3676 | case EF_ARM_ABI_FLOAT_HARD: /* Conflicts with EF_ARM_VFP_FLOAT. */ | |
3677 | out = stpcpy (out, ", hard-float ABI"); | |
3678 | break; | |
3679 | ||
3680 | default: | |
3681 | unknown_abi = true; | |
3682 | break; | |
3683 | } | |
3684 | } | |
3685 | break; | |
3686 | ||
3687 | case EF_ARM_EABI_UNKNOWN: | |
3688 | out = stpcpy (out, ", GNU EABI"); | |
3689 | while (e_flags) | |
3690 | { | |
3691 | unsigned flag; | |
3692 | ||
3693 | /* Process flags one bit at a time. */ | |
3694 | flag = e_flags & - e_flags; | |
3695 | e_flags &= ~ flag; | |
3696 | ||
3697 | switch (flag) | |
3698 | { | |
3699 | case EF_ARM_INTERWORK: | |
3700 | out = stpcpy (out, ", interworking enabled"); | |
3701 | break; | |
3702 | ||
3703 | case EF_ARM_APCS_26: | |
3704 | out = stpcpy (out, ", uses APCS/26"); | |
3705 | break; | |
3706 | ||
3707 | case EF_ARM_APCS_FLOAT: | |
3708 | out = stpcpy (out, ", uses APCS/float"); | |
3709 | break; | |
3710 | ||
3711 | case EF_ARM_PIC: | |
3712 | out = stpcpy (out, ", position independent"); | |
3713 | break; | |
3714 | ||
3715 | case EF_ARM_ALIGN8: | |
3716 | out = stpcpy (out, ", 8 bit structure alignment"); | |
3717 | break; | |
3718 | ||
3719 | case EF_ARM_NEW_ABI: | |
3720 | out = stpcpy (out, ", uses new ABI"); | |
3721 | break; | |
3722 | ||
3723 | case EF_ARM_OLD_ABI: | |
3724 | out = stpcpy (out, ", uses old ABI"); | |
3725 | break; | |
3726 | ||
3727 | case EF_ARM_SOFT_FLOAT: | |
3728 | out = stpcpy (out, ", software FP"); | |
3729 | break; | |
3730 | ||
3731 | case EF_ARM_VFP_FLOAT: | |
3732 | out = stpcpy (out, ", VFP"); | |
3733 | break; | |
3734 | ||
3735 | default: | |
3736 | unknown_abi = true; | |
3737 | break; | |
3738 | } | |
3739 | } | |
3740 | } | |
3741 | ||
3742 | if (unknown_abi) | |
3743 | out = stpcpy (out,_(", <unknown>")); | |
3744 | return out; | |
3745 | } | |
3746 | ||
3747 | static char * | |
3748 | decode_AVR_machine_flags (char *out, unsigned e_flags) | |
3749 | { | |
3750 | switch (e_flags & EF_AVR_MACH) | |
3751 | { | |
3752 | case E_AVR_MACH_AVR1: | |
3753 | out = stpcpy (out, ", avr:1"); | |
3754 | break; | |
3755 | case E_AVR_MACH_AVR2: | |
3756 | out = stpcpy (out, ", avr:2"); | |
3757 | break; | |
3758 | case E_AVR_MACH_AVR25: | |
3759 | out = stpcpy (out, ", avr:25"); | |
3760 | break; | |
3761 | case E_AVR_MACH_AVR3: | |
3762 | out = stpcpy (out, ", avr:3"); | |
3763 | break; | |
3764 | case E_AVR_MACH_AVR31: | |
3765 | out = stpcpy (out, ", avr:31"); | |
3766 | break; | |
3767 | case E_AVR_MACH_AVR35: | |
3768 | out = stpcpy (out, ", avr:35"); | |
3769 | break; | |
3770 | case E_AVR_MACH_AVR4: | |
3771 | out = stpcpy (out, ", avr:4"); | |
3772 | break; | |
3773 | case E_AVR_MACH_AVR5: | |
3774 | out = stpcpy (out, ", avr:5"); | |
3775 | break; | |
3776 | case E_AVR_MACH_AVR51: | |
3777 | out = stpcpy (out, ", avr:51"); | |
3778 | break; | |
3779 | case E_AVR_MACH_AVR6: | |
3780 | out = stpcpy (out, ", avr:6"); | |
3781 | break; | |
3782 | case E_AVR_MACH_AVRTINY: | |
3783 | out = stpcpy (out, ", avr:100"); | |
3784 | break; | |
3785 | case E_AVR_MACH_XMEGA1: | |
3786 | out = stpcpy (out, ", avr:101"); | |
3787 | break; | |
3788 | case E_AVR_MACH_XMEGA2: | |
3789 | out = stpcpy (out, ", avr:102"); | |
3790 | break; | |
3791 | case E_AVR_MACH_XMEGA3: | |
3792 | out = stpcpy (out, ", avr:103"); | |
3793 | break; | |
3794 | case E_AVR_MACH_XMEGA4: | |
3795 | out = stpcpy (out, ", avr:104"); | |
3796 | break; | |
3797 | case E_AVR_MACH_XMEGA5: | |
3798 | out = stpcpy (out, ", avr:105"); | |
3799 | break; | |
3800 | case E_AVR_MACH_XMEGA6: | |
3801 | out = stpcpy (out, ", avr:106"); | |
3802 | break; | |
3803 | case E_AVR_MACH_XMEGA7: | |
3804 | out = stpcpy (out, ", avr:107"); | |
3805 | break; | |
3806 | default: | |
3807 | out = stpcpy (out, ", avr:<unknown>"); | |
3808 | break; | |
3809 | } | |
3810 | ||
3811 | if (e_flags & EF_AVR_LINKRELAX_PREPARED) | |
3812 | out = stpcpy (out, ", link-relax"); | |
3813 | return out; | |
3814 | } | |
3815 | ||
3816 | static char * | |
3817 | decode_BLACKFIN_machine_flags (char *out, unsigned e_flags) | |
3818 | { | |
3819 | if (e_flags & EF_BFIN_PIC) | |
3820 | out = stpcpy (out, ", PIC"); | |
3821 | ||
3822 | if (e_flags & EF_BFIN_FDPIC) | |
3823 | out = stpcpy (out, ", FDPIC"); | |
3824 | ||
3825 | if (e_flags & EF_BFIN_CODE_IN_L1) | |
3826 | out = stpcpy (out, ", code in L1"); | |
3827 | ||
3828 | if (e_flags & EF_BFIN_DATA_IN_L1) | |
3829 | out = stpcpy (out, ", data in L1"); | |
3830 | return out; | |
3831 | } | |
3832 | ||
3833 | static char * | |
3834 | decode_FRV_machine_flags (char *out, unsigned e_flags) | |
3835 | { | |
3836 | switch (e_flags & EF_FRV_CPU_MASK) | |
3837 | { | |
3838 | case EF_FRV_CPU_GENERIC: | |
3839 | break; | |
3840 | ||
3841 | default: | |
3842 | out = stpcpy (out, ", fr???"); | |
3843 | break; | |
3844 | ||
3845 | case EF_FRV_CPU_FR300: | |
3846 | out = stpcpy (out, ", fr300"); | |
3847 | break; | |
3848 | ||
3849 | case EF_FRV_CPU_FR400: | |
3850 | out = stpcpy (out, ", fr400"); | |
3851 | break; | |
3852 | case EF_FRV_CPU_FR405: | |
3853 | out = stpcpy (out, ", fr405"); | |
3854 | break; | |
3855 | ||
3856 | case EF_FRV_CPU_FR450: | |
3857 | out = stpcpy (out, ", fr450"); | |
3858 | break; | |
3859 | ||
3860 | case EF_FRV_CPU_FR500: | |
3861 | out = stpcpy (out, ", fr500"); | |
3862 | break; | |
3863 | case EF_FRV_CPU_FR550: | |
3864 | out = stpcpy (out, ", fr550"); | |
3865 | break; | |
3866 | ||
3867 | case EF_FRV_CPU_SIMPLE: | |
3868 | out = stpcpy (out, ", simple"); | |
3869 | break; | |
3870 | case EF_FRV_CPU_TOMCAT: | |
3871 | out = stpcpy (out, ", tomcat"); | |
3872 | break; | |
3873 | } | |
3874 | return out; | |
3875 | } | |
3876 | ||
3877 | static char * | |
3878 | decode_IA64_machine_flags (char *out, unsigned e_flags, Filedata *filedata) | |
3879 | { | |
3880 | if ((e_flags & EF_IA_64_ABI64)) | |
3881 | out = stpcpy (out, ", 64-bit"); | |
3882 | else | |
3883 | out = stpcpy (out, ", 32-bit"); | |
3884 | if ((e_flags & EF_IA_64_REDUCEDFP)) | |
3885 | out = stpcpy (out, ", reduced fp model"); | |
3886 | if ((e_flags & EF_IA_64_NOFUNCDESC_CONS_GP)) | |
3887 | out = stpcpy (out, ", no function descriptors, constant gp"); | |
3888 | else if ((e_flags & EF_IA_64_CONS_GP)) | |
3889 | out = stpcpy (out, ", constant gp"); | |
3890 | if ((e_flags & EF_IA_64_ABSOLUTE)) | |
3891 | out = stpcpy (out, ", absolute"); | |
3892 | if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_OPENVMS) | |
3893 | { | |
3894 | if ((e_flags & EF_IA_64_VMS_LINKAGES)) | |
3895 | out = stpcpy (out, ", vms_linkages"); | |
3896 | switch ((e_flags & EF_IA_64_VMS_COMCOD)) | |
3897 | { | |
3898 | case EF_IA_64_VMS_COMCOD_SUCCESS: | |
3899 | break; | |
3900 | case EF_IA_64_VMS_COMCOD_WARNING: | |
3901 | out = stpcpy (out, ", warning"); | |
3902 | break; | |
3903 | case EF_IA_64_VMS_COMCOD_ERROR: | |
3904 | out = stpcpy (out, ", error"); | |
3905 | break; | |
3906 | case EF_IA_64_VMS_COMCOD_ABORT: | |
3907 | out = stpcpy (out, ", abort"); | |
3908 | break; | |
3909 | default: | |
3910 | warn (_("Unrecognised IA64 VMS Command Code: %x\n"), | |
3911 | e_flags & EF_IA_64_VMS_COMCOD); | |
3912 | out = stpcpy (out, ", <unknown>"); | |
3913 | } | |
3914 | } | |
3915 | return out; | |
3916 | } | |
3917 | ||
3918 | static char * | |
3919 | decode_LOONGARCH_machine_flags (char *out, unsigned int e_flags) | |
3920 | { | |
3921 | if (EF_LOONGARCH_IS_SOFT_FLOAT (e_flags)) | |
3922 | out = stpcpy (out, ", SOFT-FLOAT"); | |
3923 | else if (EF_LOONGARCH_IS_SINGLE_FLOAT (e_flags)) | |
3924 | out = stpcpy (out, ", SINGLE-FLOAT"); | |
3925 | else if (EF_LOONGARCH_IS_DOUBLE_FLOAT (e_flags)) | |
3926 | out = stpcpy (out, ", DOUBLE-FLOAT"); | |
3927 | ||
3928 | if (EF_LOONGARCH_IS_OBJ_V0 (e_flags)) | |
3929 | out = stpcpy (out, ", OBJ-v0"); | |
3930 | else if (EF_LOONGARCH_IS_OBJ_V1 (e_flags)) | |
3931 | out = stpcpy (out, ", OBJ-v1"); | |
3932 | return out; | |
3933 | } | |
3934 | ||
3935 | static char * | |
3936 | decode_M68K_machine_flags (char *out, unsigned int e_flags) | |
3937 | { | |
3938 | if ((e_flags & EF_M68K_ARCH_MASK) == EF_M68K_M68000) | |
3939 | out = stpcpy (out, ", m68000"); | |
3940 | else if ((e_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32) | |
3941 | out = stpcpy (out, ", cpu32"); | |
3942 | else if ((e_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO) | |
3943 | out = stpcpy (out, ", fido_a"); | |
3944 | else | |
3945 | { | |
3946 | char const *isa = _("unknown"); | |
3947 | char const *mac = _("unknown mac"); | |
3948 | char const *additional = NULL; | |
3949 | ||
3950 | switch (e_flags & EF_M68K_CF_ISA_MASK) | |
3951 | { | |
3952 | case EF_M68K_CF_ISA_A_NODIV: | |
3953 | isa = "A"; | |
3954 | additional = ", nodiv"; | |
3955 | break; | |
3956 | case EF_M68K_CF_ISA_A: | |
3957 | isa = "A"; | |
3958 | break; | |
3959 | case EF_M68K_CF_ISA_A_PLUS: | |
3960 | isa = "A+"; | |
3961 | break; | |
3962 | case EF_M68K_CF_ISA_B_NOUSP: | |
3963 | isa = "B"; | |
3964 | additional = ", nousp"; | |
3965 | break; | |
3966 | case EF_M68K_CF_ISA_B: | |
3967 | isa = "B"; | |
3968 | break; | |
3969 | case EF_M68K_CF_ISA_C: | |
3970 | isa = "C"; | |
3971 | break; | |
3972 | case EF_M68K_CF_ISA_C_NODIV: | |
3973 | isa = "C"; | |
3974 | additional = ", nodiv"; | |
3975 | break; | |
3976 | } | |
3977 | out = stpcpy (out, ", cf, isa "); | |
3978 | out = stpcpy (out, isa); | |
3979 | if (additional) | |
3980 | out = stpcpy (out, additional); | |
3981 | if (e_flags & EF_M68K_CF_FLOAT) | |
3982 | out = stpcpy (out, ", float"); | |
3983 | switch (e_flags & EF_M68K_CF_MAC_MASK) | |
3984 | { | |
3985 | case 0: | |
3986 | mac = NULL; | |
3987 | break; | |
3988 | case EF_M68K_CF_MAC: | |
3989 | mac = "mac"; | |
3990 | break; | |
3991 | case EF_M68K_CF_EMAC: | |
3992 | mac = "emac"; | |
3993 | break; | |
3994 | case EF_M68K_CF_EMAC_B: | |
3995 | mac = "emac_b"; | |
3996 | break; | |
3997 | } | |
3998 | if (mac) | |
3999 | { | |
4000 | out = stpcpy (out, ", "); | |
4001 | out = stpcpy (out, mac); | |
4002 | } | |
4003 | } | |
4004 | return out; | |
4005 | } | |
4006 | ||
4007 | static char * | |
4008 | decode_MeP_machine_flags (char *out, unsigned int e_flags) | |
4009 | { | |
4010 | switch (e_flags & EF_MEP_CPU_MASK) | |
4011 | { | |
4012 | case EF_MEP_CPU_MEP: | |
4013 | out = stpcpy (out, ", generic MeP"); | |
4014 | break; | |
4015 | case EF_MEP_CPU_C2: | |
4016 | out = stpcpy (out, ", MeP C2"); | |
4017 | break; | |
4018 | case EF_MEP_CPU_C3: | |
4019 | out = stpcpy (out, ", MeP C3"); | |
4020 | break; | |
4021 | case EF_MEP_CPU_C4: | |
4022 | out = stpcpy (out, ", MeP C4"); | |
4023 | break; | |
4024 | case EF_MEP_CPU_C5: | |
4025 | out = stpcpy (out, ", MeP C5"); | |
4026 | break; | |
4027 | case EF_MEP_CPU_H1: | |
4028 | out = stpcpy (out, ", MeP H1"); | |
4029 | break; | |
4030 | default: | |
4031 | out = stpcpy (out, _(", <unknown MeP cpu type>")); | |
4032 | break; | |
4033 | } | |
4034 | ||
4035 | switch (e_flags & EF_MEP_COP_MASK) | |
4036 | { | |
4037 | case EF_MEP_COP_NONE: | |
4038 | break; | |
4039 | case EF_MEP_COP_AVC: | |
4040 | out = stpcpy (out, ", AVC coprocessor"); | |
4041 | break; | |
4042 | case EF_MEP_COP_AVC2: | |
4043 | out = stpcpy (out, ", AVC2 coprocessor"); | |
4044 | break; | |
4045 | case EF_MEP_COP_FMAX: | |
4046 | out = stpcpy (out, ", FMAX coprocessor"); | |
4047 | break; | |
4048 | case EF_MEP_COP_IVC2: | |
4049 | out = stpcpy (out, ", IVC2 coprocessor"); | |
4050 | break; | |
4051 | default: | |
4052 | out = stpcpy (out, _("<unknown MeP copro type>")); | |
4053 | break; | |
4054 | } | |
4055 | ||
4056 | if (e_flags & EF_MEP_LIBRARY) | |
4057 | out = stpcpy (out, ", Built for Library"); | |
4058 | ||
4059 | if (e_flags & EF_MEP_INDEX_MASK) | |
4060 | out += sprintf (out, ", Configuration Index: %#x", | |
4061 | e_flags & EF_MEP_INDEX_MASK); | |
4062 | ||
4063 | if (e_flags & ~ EF_MEP_ALL_FLAGS) | |
4064 | out += sprintf (out, _(", unknown flags bits: %#x"), | |
4065 | e_flags & ~ EF_MEP_ALL_FLAGS); | |
4066 | return out; | |
4067 | } | |
4068 | ||
4069 | static char * | |
4070 | decode_MIPS_machine_flags (char *out, unsigned int e_flags) | |
4071 | { | |
4072 | if (e_flags & EF_MIPS_NOREORDER) | |
4073 | out = stpcpy (out, ", noreorder"); | |
4074 | ||
4075 | if (e_flags & EF_MIPS_PIC) | |
4076 | out = stpcpy (out, ", pic"); | |
4077 | ||
4078 | if (e_flags & EF_MIPS_CPIC) | |
4079 | out = stpcpy (out, ", cpic"); | |
4080 | ||
4081 | if (e_flags & EF_MIPS_UCODE) | |
4082 | out = stpcpy (out, ", ugen_reserved"); | |
4083 | ||
4084 | if (e_flags & EF_MIPS_ABI2) | |
4085 | out = stpcpy (out, ", abi2"); | |
4086 | ||
4087 | if (e_flags & EF_MIPS_OPTIONS_FIRST) | |
4088 | out = stpcpy (out, ", odk first"); | |
4089 | ||
4090 | if (e_flags & EF_MIPS_32BITMODE) | |
4091 | out = stpcpy (out, ", 32bitmode"); | |
4092 | ||
4093 | if (e_flags & EF_MIPS_NAN2008) | |
4094 | out = stpcpy (out, ", nan2008"); | |
4095 | ||
4096 | if (e_flags & EF_MIPS_FP64) | |
4097 | out = stpcpy (out, ", fp64"); | |
4098 | ||
4099 | switch ((e_flags & EF_MIPS_MACH)) | |
4100 | { | |
4101 | case EF_MIPS_MACH_3900: | |
4102 | out = stpcpy (out, ", 3900"); | |
4103 | break; | |
4104 | case EF_MIPS_MACH_4010: | |
4105 | out = stpcpy (out, ", 4010"); | |
4106 | break; | |
4107 | case EF_MIPS_MACH_4100: | |
4108 | out = stpcpy (out, ", 4100"); | |
4109 | break; | |
4110 | case EF_MIPS_MACH_4111: | |
4111 | out = stpcpy (out, ", 4111"); | |
4112 | break; | |
4113 | case EF_MIPS_MACH_4120: | |
4114 | out = stpcpy (out, ", 4120"); | |
4115 | break; | |
4116 | case EF_MIPS_MACH_4650: | |
4117 | out = stpcpy (out, ", 4650"); | |
4118 | break; | |
4119 | case EF_MIPS_MACH_5400: | |
4120 | out = stpcpy (out, ", 5400"); | |
4121 | break; | |
4122 | case EF_MIPS_MACH_5500: | |
4123 | out = stpcpy (out, ", 5500"); | |
4124 | break; | |
4125 | case EF_MIPS_MACH_5900: | |
4126 | out = stpcpy (out, ", 5900"); | |
4127 | break; | |
4128 | case EF_MIPS_MACH_SB1: | |
4129 | out = stpcpy (out, ", sb1"); | |
4130 | break; | |
4131 | case EF_MIPS_MACH_9000: | |
4132 | out = stpcpy (out, ", 9000"); | |
4133 | break; | |
4134 | case EF_MIPS_MACH_LS2E: | |
4135 | out = stpcpy (out, ", loongson-2e"); | |
4136 | break; | |
4137 | case EF_MIPS_MACH_LS2F: | |
4138 | out = stpcpy (out, ", loongson-2f"); | |
4139 | break; | |
4140 | case EF_MIPS_MACH_GS464: | |
4141 | out = stpcpy (out, ", gs464"); | |
4142 | break; | |
4143 | case EF_MIPS_MACH_GS464E: | |
4144 | out = stpcpy (out, ", gs464e"); | |
4145 | break; | |
4146 | case EF_MIPS_MACH_GS264E: | |
4147 | out = stpcpy (out, ", gs264e"); | |
4148 | break; | |
4149 | case EF_MIPS_MACH_OCTEON: | |
4150 | out = stpcpy (out, ", octeon"); | |
4151 | break; | |
4152 | case EF_MIPS_MACH_OCTEON2: | |
4153 | out = stpcpy (out, ", octeon2"); | |
4154 | break; | |
4155 | case EF_MIPS_MACH_OCTEON3: | |
4156 | out = stpcpy (out, ", octeon3"); | |
4157 | break; | |
4158 | case EF_MIPS_MACH_XLR: | |
4159 | out = stpcpy (out, ", xlr"); | |
4160 | break; | |
4161 | case EF_MIPS_MACH_IAMR2: | |
4162 | out = stpcpy (out, ", interaptiv-mr2"); | |
4163 | break; | |
4164 | case EF_MIPS_MACH_ALLEGREX: | |
4165 | out = stpcpy (out, ", allegrex"); | |
4166 | break; | |
4167 | case 0: | |
4168 | /* We simply ignore the field in this case to avoid confusion: | |
4169 | MIPS ELF does not specify EF_MIPS_MACH, it is a GNU | |
4170 | extension. */ | |
4171 | break; | |
4172 | default: | |
4173 | out = stpcpy (out, _(", unknown CPU")); | |
4174 | break; | |
4175 | } | |
4176 | ||
4177 | switch ((e_flags & EF_MIPS_ABI)) | |
4178 | { | |
4179 | case EF_MIPS_ABI_O32: | |
4180 | out = stpcpy (out, ", o32"); | |
4181 | break; | |
4182 | case EF_MIPS_ABI_O64: | |
4183 | out = stpcpy (out, ", o64"); | |
4184 | break; | |
4185 | case EF_MIPS_ABI_EABI32: | |
4186 | out = stpcpy (out, ", eabi32"); | |
4187 | break; | |
4188 | case EF_MIPS_ABI_EABI64: | |
4189 | out = stpcpy (out, ", eabi64"); | |
4190 | break; | |
4191 | case 0: | |
4192 | /* We simply ignore the field in this case to avoid confusion: | |
4193 | MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension. | |
4194 | This means it is likely to be an o32 file, but not for | |
4195 | sure. */ | |
4196 | break; | |
4197 | default: | |
4198 | out = stpcpy (out, _(", unknown ABI")); | |
4199 | break; | |
4200 | } | |
4201 | ||
4202 | if (e_flags & EF_MIPS_ARCH_ASE_MDMX) | |
4203 | out = stpcpy (out, ", mdmx"); | |
4204 | ||
4205 | if (e_flags & EF_MIPS_ARCH_ASE_M16) | |
4206 | out = stpcpy (out, ", mips16"); | |
4207 | ||
4208 | if (e_flags & EF_MIPS_ARCH_ASE_MICROMIPS) | |
4209 | out = stpcpy (out, ", micromips"); | |
4210 | ||
4211 | switch ((e_flags & EF_MIPS_ARCH)) | |
4212 | { | |
4213 | case EF_MIPS_ARCH_1: | |
4214 | out = stpcpy (out, ", mips1"); | |
4215 | break; | |
4216 | case EF_MIPS_ARCH_2: | |
4217 | out = stpcpy (out, ", mips2"); | |
4218 | break; | |
4219 | case EF_MIPS_ARCH_3: | |
4220 | out = stpcpy (out, ", mips3"); | |
4221 | break; | |
4222 | case EF_MIPS_ARCH_4: | |
4223 | out = stpcpy (out, ", mips4"); | |
4224 | break; | |
4225 | case EF_MIPS_ARCH_5: | |
4226 | out = stpcpy (out, ", mips5"); | |
4227 | break; | |
4228 | case EF_MIPS_ARCH_32: | |
4229 | out = stpcpy (out, ", mips32"); | |
4230 | break; | |
4231 | case EF_MIPS_ARCH_32R2: | |
4232 | out = stpcpy (out, ", mips32r2"); | |
4233 | break; | |
4234 | case EF_MIPS_ARCH_32R6: | |
4235 | out = stpcpy (out, ", mips32r6"); | |
4236 | break; | |
4237 | case EF_MIPS_ARCH_64: | |
4238 | out = stpcpy (out, ", mips64"); | |
4239 | break; | |
4240 | case EF_MIPS_ARCH_64R2: | |
4241 | out = stpcpy (out, ", mips64r2"); | |
4242 | break; | |
4243 | case EF_MIPS_ARCH_64R6: | |
4244 | out = stpcpy (out, ", mips64r6"); | |
4245 | break; | |
4246 | default: | |
4247 | out = stpcpy (out, _(", unknown ISA")); | |
4248 | break; | |
4249 | } | |
4250 | return out; | |
4251 | } | |
4252 | ||
4253 | static char * | |
4254 | decode_MSP430_machine_flags (char *out, unsigned e_flags) | |
4255 | { | |
4256 | out = stpcpy (out, _(": architecture variant: ")); | |
4257 | switch (e_flags & EF_MSP430_MACH) | |
4258 | { | |
4259 | case E_MSP430_MACH_MSP430x11: | |
4260 | out = stpcpy (out, "MSP430x11"); | |
4261 | break; | |
4262 | case E_MSP430_MACH_MSP430x11x1: | |
4263 | out = stpcpy (out, "MSP430x11x1 "); | |
4264 | break; | |
4265 | case E_MSP430_MACH_MSP430x12: | |
4266 | out = stpcpy (out, "MSP430x12"); | |
4267 | break; | |
4268 | case E_MSP430_MACH_MSP430x13: | |
4269 | out = stpcpy (out, "MSP430x13"); | |
4270 | break; | |
4271 | case E_MSP430_MACH_MSP430x14: | |
4272 | out = stpcpy (out, "MSP430x14"); | |
4273 | break; | |
4274 | case E_MSP430_MACH_MSP430x15: | |
4275 | out = stpcpy (out, "MSP430x15"); | |
4276 | break; | |
4277 | case E_MSP430_MACH_MSP430x16: | |
4278 | out = stpcpy (out, "MSP430x16"); | |
4279 | break; | |
4280 | case E_MSP430_MACH_MSP430x31: | |
4281 | out = stpcpy (out, "MSP430x31"); | |
4282 | break; | |
4283 | case E_MSP430_MACH_MSP430x32: | |
4284 | out = stpcpy (out, "MSP430x32"); | |
4285 | break; | |
4286 | case E_MSP430_MACH_MSP430x33: | |
4287 | out = stpcpy (out, "MSP430x33"); | |
4288 | break; | |
4289 | case E_MSP430_MACH_MSP430x41: | |
4290 | out = stpcpy (out, "MSP430x41"); | |
4291 | break; | |
4292 | case E_MSP430_MACH_MSP430x42: | |
4293 | out = stpcpy (out, "MSP430x42"); | |
4294 | break; | |
4295 | case E_MSP430_MACH_MSP430x43: | |
4296 | out = stpcpy (out, "MSP430x43"); | |
4297 | break; | |
4298 | case E_MSP430_MACH_MSP430x44: | |
4299 | out = stpcpy (out, "MSP430x44"); | |
4300 | break; | |
4301 | case E_MSP430_MACH_MSP430X : | |
4302 | out = stpcpy (out, "MSP430X"); | |
4303 | break; | |
4304 | default: | |
4305 | out = stpcpy (out, _(": unknown")); | |
4306 | break; | |
4307 | } | |
4308 | ||
4309 | if (e_flags & ~ EF_MSP430_MACH) | |
4310 | out = stpcpy (out, _(": unknown extra flag bits also present")); | |
4311 | return out; | |
4312 | } | |
4313 | ||
4314 | static char * | |
4315 | decode_NDS32_machine_flags (char *out, unsigned e_flags) | |
4316 | { | |
4317 | unsigned abi; | |
4318 | unsigned arch; | |
4319 | unsigned config; | |
4320 | unsigned version; | |
4321 | bool has_fpu = false; | |
4322 | ||
4323 | static const char *ABI_STRINGS[] = | |
4324 | { | |
4325 | "ABI v0", /* use r5 as return register; only used in N1213HC */ | |
4326 | "ABI v1", /* use r0 as return register */ | |
4327 | "ABI v2", /* use r0 as return register and don't reserve 24 bytes for arguments */ | |
4328 | "ABI v2fp", /* for FPU */ | |
4329 | "AABI", | |
4330 | "ABI2 FP+" | |
4331 | }; | |
4332 | static const char *VER_STRINGS[] = | |
4333 | { | |
4334 | "Andes ELF V1.3 or older", | |
4335 | "Andes ELF V1.3.1", | |
4336 | "Andes ELF V1.4" | |
4337 | }; | |
4338 | static const char *ARCH_STRINGS[] = | |
4339 | { | |
4340 | "", | |
4341 | "Andes Star v1.0", | |
4342 | "Andes Star v2.0", | |
4343 | "Andes Star v3.0", | |
4344 | "Andes Star v3.0m" | |
4345 | }; | |
4346 | ||
4347 | abi = EF_NDS_ABI & e_flags; | |
4348 | arch = EF_NDS_ARCH & e_flags; | |
4349 | config = EF_NDS_INST & e_flags; | |
4350 | version = EF_NDS32_ELF_VERSION & e_flags; | |
4351 | ||
4352 | switch (abi) | |
4353 | { | |
4354 | case E_NDS_ABI_V0: | |
4355 | case E_NDS_ABI_V1: | |
4356 | case E_NDS_ABI_V2: | |
4357 | case E_NDS_ABI_V2FP: | |
4358 | case E_NDS_ABI_AABI: | |
4359 | case E_NDS_ABI_V2FP_PLUS: | |
4360 | /* In case there are holes in the array. */ | |
4361 | out += sprintf (out, ", %s", ABI_STRINGS[abi >> EF_NDS_ABI_SHIFT]); | |
4362 | break; | |
4363 | ||
4364 | default: | |
4365 | out = stpcpy (out, ", <unrecognized ABI>"); | |
4366 | break; | |
4367 | } | |
4368 | ||
4369 | switch (version) | |
4370 | { | |
4371 | case E_NDS32_ELF_VER_1_2: | |
4372 | case E_NDS32_ELF_VER_1_3: | |
4373 | case E_NDS32_ELF_VER_1_4: | |
4374 | out += sprintf (out, ", %s", VER_STRINGS[version >> EF_NDS32_ELF_VERSION_SHIFT]); | |
4375 | break; | |
4376 | ||
4377 | default: | |
4378 | out = stpcpy (out, ", <unrecognized ELF version number>"); | |
4379 | break; | |
4380 | } | |
4381 | ||
4382 | if (E_NDS_ABI_V0 == abi) | |
4383 | { | |
4384 | /* OLD ABI; only used in N1213HC, has performance extension 1. */ | |
4385 | out = stpcpy (out, ", Andes Star v1.0, N1213HC, MAC, PERF1"); | |
4386 | if (arch == E_NDS_ARCH_STAR_V1_0) | |
4387 | out = stpcpy (out, ", 16b"); /* has 16-bit instructions */ | |
4388 | return out; | |
4389 | } | |
4390 | ||
4391 | switch (arch) | |
4392 | { | |
4393 | case E_NDS_ARCH_STAR_V1_0: | |
4394 | case E_NDS_ARCH_STAR_V2_0: | |
4395 | case E_NDS_ARCH_STAR_V3_0: | |
4396 | case E_NDS_ARCH_STAR_V3_M: | |
4397 | out += sprintf (out, ", %s", ARCH_STRINGS[arch >> EF_NDS_ARCH_SHIFT]); | |
4398 | break; | |
4399 | ||
4400 | default: | |
4401 | out = stpcpy (out, ", <unrecognized architecture>"); | |
4402 | /* ARCH version determines how the e_flags are interpreted. | |
4403 | If it is unknown, we cannot proceed. */ | |
4404 | return out; | |
4405 | } | |
4406 | ||
4407 | /* Newer ABI; Now handle architecture specific flags. */ | |
4408 | if (arch == E_NDS_ARCH_STAR_V1_0) | |
4409 | { | |
4410 | if (config & E_NDS32_HAS_MFUSR_PC_INST) | |
4411 | out = stpcpy (out, ", MFUSR_PC"); | |
4412 | ||
4413 | if (!(config & E_NDS32_HAS_NO_MAC_INST)) | |
4414 | out = stpcpy (out, ", MAC"); | |
4415 | ||
4416 | if (config & E_NDS32_HAS_DIV_INST) | |
4417 | out = stpcpy (out, ", DIV"); | |
4418 | ||
4419 | if (config & E_NDS32_HAS_16BIT_INST) | |
4420 | out = stpcpy (out, ", 16b"); | |
4421 | } | |
4422 | else | |
4423 | { | |
4424 | if (config & E_NDS32_HAS_MFUSR_PC_INST) | |
4425 | { | |
4426 | if (version <= E_NDS32_ELF_VER_1_3) | |
4427 | out = stpcpy (out, ", [B8]"); | |
4428 | else | |
4429 | out = stpcpy (out, ", EX9"); | |
4430 | } | |
4431 | ||
4432 | if (config & E_NDS32_HAS_MAC_DX_INST) | |
4433 | out = stpcpy (out, ", MAC_DX"); | |
4434 | ||
4435 | if (config & E_NDS32_HAS_DIV_DX_INST) | |
4436 | out = stpcpy (out, ", DIV_DX"); | |
4437 | ||
4438 | if (config & E_NDS32_HAS_16BIT_INST) | |
4439 | { | |
4440 | if (version <= E_NDS32_ELF_VER_1_3) | |
4441 | out = stpcpy (out, ", 16b"); | |
4442 | else | |
4443 | out = stpcpy (out, ", IFC"); | |
4444 | } | |
4445 | } | |
4446 | ||
4447 | if (config & E_NDS32_HAS_EXT_INST) | |
4448 | out = stpcpy (out, ", PERF1"); | |
4449 | ||
4450 | if (config & E_NDS32_HAS_EXT2_INST) | |
4451 | out = stpcpy (out, ", PERF2"); | |
4452 | ||
4453 | if (config & E_NDS32_HAS_FPU_INST) | |
4454 | { | |
4455 | has_fpu = true; | |
4456 | out = stpcpy (out, ", FPU_SP"); | |
4457 | } | |
4458 | ||
4459 | if (config & E_NDS32_HAS_FPU_DP_INST) | |
4460 | { | |
4461 | has_fpu = true; | |
4462 | out = stpcpy (out, ", FPU_DP"); | |
4463 | } | |
4464 | ||
4465 | if (config & E_NDS32_HAS_FPU_MAC_INST) | |
4466 | { | |
4467 | has_fpu = true; | |
4468 | out = stpcpy (out, ", FPU_MAC"); | |
4469 | } | |
4470 | ||
4471 | if (has_fpu) | |
4472 | { | |
4473 | switch ((config & E_NDS32_FPU_REG_CONF) >> E_NDS32_FPU_REG_CONF_SHIFT) | |
4474 | { | |
4475 | case E_NDS32_FPU_REG_8SP_4DP: | |
4476 | out = stpcpy (out, ", FPU_REG:8/4"); | |
4477 | break; | |
4478 | case E_NDS32_FPU_REG_16SP_8DP: | |
4479 | out = stpcpy (out, ", FPU_REG:16/8"); | |
4480 | break; | |
4481 | case E_NDS32_FPU_REG_32SP_16DP: | |
4482 | out = stpcpy (out, ", FPU_REG:32/16"); | |
4483 | break; | |
4484 | case E_NDS32_FPU_REG_32SP_32DP: | |
4485 | out = stpcpy (out, ", FPU_REG:32/32"); | |
4486 | break; | |
4487 | } | |
4488 | } | |
4489 | ||
4490 | if (config & E_NDS32_HAS_AUDIO_INST) | |
4491 | out = stpcpy (out, ", AUDIO"); | |
4492 | ||
4493 | if (config & E_NDS32_HAS_STRING_INST) | |
4494 | out = stpcpy (out, ", STR"); | |
4495 | ||
4496 | if (config & E_NDS32_HAS_REDUCED_REGS) | |
4497 | out = stpcpy (out, ", 16REG"); | |
4498 | ||
4499 | if (config & E_NDS32_HAS_VIDEO_INST) | |
4500 | { | |
4501 | if (version <= E_NDS32_ELF_VER_1_3) | |
4502 | out = stpcpy (out, ", VIDEO"); | |
4503 | else | |
4504 | out = stpcpy (out, ", SATURATION"); | |
4505 | } | |
4506 | ||
4507 | if (config & E_NDS32_HAS_ENCRIPT_INST) | |
4508 | out = stpcpy (out, ", ENCRP"); | |
4509 | ||
4510 | if (config & E_NDS32_HAS_L2C_INST) | |
4511 | out = stpcpy (out, ", L2C"); | |
4512 | ||
4513 | return out; | |
4514 | } | |
4515 | ||
4516 | static char * | |
4517 | decode_PARISC_machine_flags (char *out, unsigned e_flags) | |
4518 | { | |
4519 | switch (e_flags & EF_PARISC_ARCH) | |
4520 | { | |
4521 | case EFA_PARISC_1_0: | |
4522 | out = stpcpy (out, ", PA-RISC 1.0"); | |
4523 | break; | |
4524 | case EFA_PARISC_1_1: | |
4525 | out = stpcpy (out, ", PA-RISC 1.1"); | |
4526 | break; | |
4527 | case EFA_PARISC_2_0: | |
4528 | out = stpcpy (out, ", PA-RISC 2.0"); | |
4529 | break; | |
4530 | default: | |
4531 | break; | |
4532 | } | |
4533 | if (e_flags & EF_PARISC_TRAPNIL) | |
4534 | out = stpcpy (out, ", trapnil"); | |
4535 | if (e_flags & EF_PARISC_EXT) | |
4536 | out = stpcpy (out, ", ext"); | |
4537 | if (e_flags & EF_PARISC_LSB) | |
4538 | out = stpcpy (out, ", lsb"); | |
4539 | if (e_flags & EF_PARISC_WIDE) | |
4540 | out = stpcpy (out, ", wide"); | |
4541 | if (e_flags & EF_PARISC_NO_KABP) | |
4542 | out = stpcpy (out, ", no kabp"); | |
4543 | if (e_flags & EF_PARISC_LAZYSWAP) | |
4544 | out = stpcpy (out, ", lazyswap"); | |
4545 | return out; | |
4546 | } | |
4547 | ||
4548 | static char * | |
4549 | decode_RISCV_machine_flags (char *out, unsigned e_flags) | |
4550 | { | |
4551 | if (e_flags & EF_RISCV_RVC) | |
4552 | out = stpcpy (out, ", RVC"); | |
4553 | ||
4554 | if (e_flags & EF_RISCV_RVE) | |
4555 | out = stpcpy (out, ", RVE"); | |
4556 | ||
4557 | if (e_flags & EF_RISCV_TSO) | |
4558 | out = stpcpy (out, ", TSO"); | |
4559 | ||
4560 | switch (e_flags & EF_RISCV_FLOAT_ABI) | |
4561 | { | |
4562 | case EF_RISCV_FLOAT_ABI_SOFT: | |
4563 | out = stpcpy (out, ", soft-float ABI"); | |
4564 | break; | |
4565 | ||
4566 | case EF_RISCV_FLOAT_ABI_SINGLE: | |
4567 | out = stpcpy (out, ", single-float ABI"); | |
4568 | break; | |
4569 | ||
4570 | case EF_RISCV_FLOAT_ABI_DOUBLE: | |
4571 | out = stpcpy (out, ", double-float ABI"); | |
4572 | break; | |
4573 | ||
4574 | case EF_RISCV_FLOAT_ABI_QUAD: | |
4575 | out = stpcpy (out, ", quad-float ABI"); | |
4576 | break; | |
4577 | } | |
4578 | return out; | |
4579 | } | |
4580 | ||
4581 | static char * | |
4582 | decode_RL78_machine_flags (char *out, unsigned e_flags) | |
4583 | { | |
4584 | switch (e_flags & E_FLAG_RL78_CPU_MASK) | |
4585 | { | |
4586 | case E_FLAG_RL78_ANY_CPU: | |
4587 | break; | |
4588 | case E_FLAG_RL78_G10: | |
4589 | out = stpcpy (out, ", G10"); | |
4590 | break; | |
4591 | case E_FLAG_RL78_G13: | |
4592 | out = stpcpy (out, ", G13"); | |
4593 | break; | |
4594 | case E_FLAG_RL78_G14: | |
4595 | out = stpcpy (out, ", G14"); | |
4596 | break; | |
4597 | } | |
4598 | if (e_flags & E_FLAG_RL78_64BIT_DOUBLES) | |
4599 | out = stpcpy (out, ", 64-bit doubles"); | |
4600 | return out; | |
4601 | } | |
4602 | ||
4603 | static char * | |
4604 | decode_RX_machine_flags (char *out, unsigned e_flags) | |
4605 | { | |
4606 | if (e_flags & E_FLAG_RX_64BIT_DOUBLES) | |
4607 | out = stpcpy (out, ", 64-bit doubles"); | |
4608 | if (e_flags & E_FLAG_RX_DSP) | |
4609 | out = stpcpy (out, ", dsp"); | |
4610 | if (e_flags & E_FLAG_RX_PID) | |
4611 | out = stpcpy (out, ", pid"); | |
4612 | if (e_flags & E_FLAG_RX_ABI) | |
4613 | out = stpcpy (out, ", RX ABI"); | |
4614 | if (e_flags & E_FLAG_RX_SINSNS_SET) | |
4615 | out = stpcpy (out, (e_flags & E_FLAG_RX_SINSNS_YES | |
4616 | ? ", uses String instructions" | |
4617 | : ", bans String instructions")); | |
4618 | if (e_flags & E_FLAG_RX_V2) | |
4619 | out = stpcpy (out, ", V2"); | |
4620 | if (e_flags & E_FLAG_RX_V3) | |
4621 | out = stpcpy (out, ", V3"); | |
4622 | return out; | |
4623 | } | |
4624 | ||
4625 | static char * | |
4626 | decode_SH_machine_flags (char *out, unsigned e_flags) | |
4627 | { | |
4628 | switch ((e_flags & EF_SH_MACH_MASK)) | |
4629 | { | |
4630 | case EF_SH1: | |
4631 | out = stpcpy (out, ", sh1"); | |
4632 | break; | |
4633 | case EF_SH2: | |
4634 | out = stpcpy (out, ", sh2"); | |
4635 | break; | |
4636 | case EF_SH3: | |
4637 | out = stpcpy (out, ", sh3"); | |
4638 | break; | |
4639 | case EF_SH_DSP: | |
4640 | out = stpcpy (out, ", sh-dsp"); | |
4641 | break; | |
4642 | case EF_SH3_DSP: | |
4643 | out = stpcpy (out, ", sh3-dsp"); | |
4644 | break; | |
4645 | case EF_SH4AL_DSP: | |
4646 | out = stpcpy (out, ", sh4al-dsp"); | |
4647 | break; | |
4648 | case EF_SH3E: | |
4649 | out = stpcpy (out, ", sh3e"); | |
4650 | break; | |
4651 | case EF_SH4: | |
4652 | out = stpcpy (out, ", sh4"); | |
4653 | break; | |
4654 | case EF_SH5: | |
4655 | out = stpcpy (out, ", sh5"); | |
4656 | break; | |
4657 | case EF_SH2E: | |
4658 | out = stpcpy (out, ", sh2e"); | |
4659 | break; | |
4660 | case EF_SH4A: | |
4661 | out = stpcpy (out, ", sh4a"); | |
4662 | break; | |
4663 | case EF_SH2A: | |
4664 | out = stpcpy (out, ", sh2a"); | |
4665 | break; | |
4666 | case EF_SH4_NOFPU: | |
4667 | out = stpcpy (out, ", sh4-nofpu"); | |
4668 | break; | |
4669 | case EF_SH4A_NOFPU: | |
4670 | out = stpcpy (out, ", sh4a-nofpu"); | |
4671 | break; | |
4672 | case EF_SH2A_NOFPU: | |
4673 | out = stpcpy (out, ", sh2a-nofpu"); | |
4674 | break; | |
4675 | case EF_SH3_NOMMU: | |
4676 | out = stpcpy (out, ", sh3-nommu"); | |
4677 | break; | |
4678 | case EF_SH4_NOMMU_NOFPU: | |
4679 | out = stpcpy (out, ", sh4-nommu-nofpu"); | |
4680 | break; | |
4681 | case EF_SH2A_SH4_NOFPU: | |
4682 | out = stpcpy (out, ", sh2a-nofpu-or-sh4-nommu-nofpu"); | |
4683 | break; | |
4684 | case EF_SH2A_SH3_NOFPU: | |
4685 | out = stpcpy (out, ", sh2a-nofpu-or-sh3-nommu"); | |
4686 | break; | |
4687 | case EF_SH2A_SH4: | |
4688 | out = stpcpy (out, ", sh2a-or-sh4"); | |
4689 | break; | |
4690 | case EF_SH2A_SH3E: | |
4691 | out = stpcpy (out, ", sh2a-or-sh3e"); | |
4692 | break; | |
4693 | default: | |
4694 | out = stpcpy (out, _(", unknown ISA")); | |
4695 | break; | |
4696 | } | |
4697 | ||
4698 | if (e_flags & EF_SH_PIC) | |
4699 | out = stpcpy (out, ", pic"); | |
4700 | ||
4701 | if (e_flags & EF_SH_FDPIC) | |
4702 | out = stpcpy (out, ", fdpic"); | |
4703 | return out; | |
4704 | } | |
4705 | ||
4706 | static char * | |
4707 | decode_SPARC_machine_flags (char *out, unsigned e_flags) | |
4708 | { | |
4709 | if (e_flags & EF_SPARC_32PLUS) | |
4710 | out = stpcpy (out, ", v8+"); | |
4711 | ||
4712 | if (e_flags & EF_SPARC_SUN_US1) | |
4713 | out = stpcpy (out, ", ultrasparcI"); | |
4714 | ||
4715 | if (e_flags & EF_SPARC_SUN_US3) | |
4716 | out = stpcpy (out, ", ultrasparcIII"); | |
4717 | ||
4718 | if (e_flags & EF_SPARC_HAL_R1) | |
4719 | out = stpcpy (out, ", halr1"); | |
4720 | ||
4721 | if (e_flags & EF_SPARC_LEDATA) | |
4722 | out = stpcpy (out, ", ledata"); | |
4723 | ||
4724 | if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_TSO) | |
4725 | out = stpcpy (out, ", tso"); | |
4726 | ||
4727 | if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_PSO) | |
4728 | out = stpcpy (out, ", pso"); | |
4729 | ||
4730 | if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_RMO) | |
4731 | out = stpcpy (out, ", rmo"); | |
4732 | return out; | |
4733 | } | |
4734 | ||
4735 | static char * | |
4736 | decode_V800_machine_flags (char *out, unsigned int e_flags) | |
4737 | { | |
4738 | if ((e_flags & EF_RH850_ABI) == EF_RH850_ABI) | |
4739 | out = stpcpy (out, ", RH850 ABI"); | |
4740 | ||
4741 | if (e_flags & EF_V800_850E3) | |
4742 | out = stpcpy (out, ", V3 architecture"); | |
4743 | ||
4744 | if ((e_flags & (EF_RH850_FPU_DOUBLE | EF_RH850_FPU_SINGLE)) == 0) | |
4745 | out = stpcpy (out, ", FPU not used"); | |
4746 | ||
4747 | if ((e_flags & (EF_RH850_REGMODE22 | EF_RH850_REGMODE32)) == 0) | |
4748 | out = stpcpy (out, ", regmode: COMMON"); | |
4749 | ||
4750 | if ((e_flags & (EF_RH850_GP_FIX | EF_RH850_GP_NOFIX)) == 0) | |
4751 | out = stpcpy (out, ", r4 not used"); | |
4752 | ||
4753 | if ((e_flags & (EF_RH850_EP_FIX | EF_RH850_EP_NOFIX)) == 0) | |
4754 | out = stpcpy (out, ", r30 not used"); | |
4755 | ||
4756 | if ((e_flags & (EF_RH850_TP_FIX | EF_RH850_TP_NOFIX)) == 0) | |
4757 | out = stpcpy (out, ", r5 not used"); | |
4758 | ||
4759 | if ((e_flags & (EF_RH850_REG2_RESERVE | EF_RH850_REG2_NORESERVE)) == 0) | |
4760 | out = stpcpy (out, ", r2 not used"); | |
4761 | ||
4762 | for (e_flags &= 0xFFFF; e_flags; e_flags &= ~ (e_flags & - e_flags)) | |
4763 | { | |
4764 | switch (e_flags & - e_flags) | |
4765 | { | |
4766 | case EF_RH850_FPU_DOUBLE: | |
4767 | out = stpcpy (out, ", double precision FPU"); | |
4768 | break; | |
4769 | case EF_RH850_FPU_SINGLE: | |
4770 | out = stpcpy (out, ", single precision FPU"); | |
4771 | break; | |
4772 | case EF_RH850_REGMODE22: | |
4773 | out = stpcpy (out, ", regmode:22"); | |
4774 | break; | |
4775 | case EF_RH850_REGMODE32: | |
4776 | out = stpcpy (out, ", regmode:23"); | |
4777 | break; | |
4778 | case EF_RH850_GP_FIX: | |
4779 | out = stpcpy (out, ", r4 fixed"); | |
4780 | break; | |
4781 | case EF_RH850_GP_NOFIX: | |
4782 | out = stpcpy (out, ", r4 free"); | |
4783 | break; | |
4784 | case EF_RH850_EP_FIX: | |
4785 | out = stpcpy (out, ", r30 fixed"); | |
4786 | break; | |
4787 | case EF_RH850_EP_NOFIX: | |
4788 | out = stpcpy (out, ", r30 free"); | |
4789 | break; | |
4790 | case EF_RH850_TP_FIX: | |
4791 | out = stpcpy (out, ", r5 fixed"); | |
4792 | break; | |
4793 | case EF_RH850_TP_NOFIX: | |
4794 | out = stpcpy (out, ", r5 free"); | |
4795 | break; | |
4796 | case EF_RH850_REG2_RESERVE: | |
4797 | out = stpcpy (out, ", r2 fixed"); | |
4798 | break; | |
4799 | case EF_RH850_REG2_NORESERVE: | |
4800 | out = stpcpy (out, ", r2 free"); | |
4801 | break; | |
4802 | default: | |
4803 | break; | |
4804 | } | |
4805 | } | |
4806 | return out; | |
4807 | } | |
4808 | ||
4809 | static char * | |
4810 | decode_V850_machine_flags (char *out, unsigned int e_flags) | |
4811 | { | |
4812 | switch (e_flags & EF_V850_ARCH) | |
4813 | { | |
4814 | case E_V850E3V5_ARCH: | |
4815 | out = stpcpy (out, ", v850e3v5"); | |
4816 | break; | |
4817 | case E_V850E2V3_ARCH: | |
4818 | out = stpcpy (out, ", v850e2v3"); | |
4819 | break; | |
4820 | case E_V850E2_ARCH: | |
4821 | out = stpcpy (out, ", v850e2"); | |
4822 | break; | |
4823 | case E_V850E1_ARCH: | |
4824 | out = stpcpy (out, ", v850e1"); | |
4825 | break; | |
4826 | case E_V850E_ARCH: | |
4827 | out = stpcpy (out, ", v850e"); | |
4828 | break; | |
4829 | case E_V850_ARCH: | |
4830 | out = stpcpy (out, ", v850"); | |
4831 | break; | |
4832 | default: | |
4833 | out = stpcpy (out, _(", unknown v850 architecture variant")); | |
4834 | break; | |
4835 | } | |
4836 | return out; | |
4837 | } | |
4838 | ||
4839 | static char * | |
4840 | decode_Z80_machine_flags (char *out, unsigned int e_flags) | |
4841 | { | |
4842 | switch (e_flags & EF_Z80_MACH_MSK) | |
4843 | { | |
4844 | case EF_Z80_MACH_Z80: | |
4845 | out = stpcpy (out, ", Z80"); | |
4846 | break; | |
4847 | case EF_Z80_MACH_Z180: | |
4848 | out = stpcpy (out, ", Z180"); | |
4849 | break; | |
4850 | case EF_Z80_MACH_R800: | |
4851 | out = stpcpy (out, ", R800"); | |
4852 | break; | |
4853 | case EF_Z80_MACH_EZ80_Z80: | |
4854 | out = stpcpy (out, ", EZ80"); | |
4855 | break; | |
4856 | case EF_Z80_MACH_EZ80_ADL: | |
4857 | out = stpcpy (out, ", EZ80, ADL"); | |
4858 | break; | |
4859 | case EF_Z80_MACH_GBZ80: | |
4860 | out = stpcpy (out, ", GBZ80"); | |
4861 | break; | |
4862 | case EF_Z80_MACH_Z80N: | |
4863 | out = stpcpy (out, ", Z80N"); | |
4864 | break; | |
4865 | default: | |
4866 | out = stpcpy (out, _(", unknown")); | |
4867 | break; | |
4868 | } | |
4869 | return out; | |
4870 | } | |
4871 | ||
4872 | static char * | |
4873 | decode_AMDGPU_machine_flags (char *out, unsigned int e_flags, Filedata *filedata) | |
4874 | { | |
4875 | unsigned char *e_ident = filedata->file_header.e_ident; | |
4876 | unsigned char osabi = e_ident[EI_OSABI]; | |
4877 | unsigned char abiversion = e_ident[EI_ABIVERSION]; | |
4878 | unsigned int mach; | |
4879 | ||
4880 | /* HSA OS ABI v2 used a different encoding, but we don't need to support it, | |
4881 | it has been deprecated for a while. | |
4882 | ||
4883 | The PAL, MESA3D and NONE OS ABIs are not properly versioned, at the time | |
4884 | of writing, they use the same flags as HSA v3, so the code below uses that | |
4885 | assumption. */ | |
4886 | if (osabi == ELFOSABI_AMDGPU_HSA && abiversion < ELFABIVERSION_AMDGPU_HSA_V3) | |
4887 | return out; | |
4888 | ||
4889 | mach = e_flags & EF_AMDGPU_MACH; | |
4890 | switch (mach) | |
4891 | { | |
4892 | #define AMDGPU_CASE(code, string) \ | |
4893 | case code: out = stpcpy (out, ", " string); break; | |
4894 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX600, "gfx600") | |
4895 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX601, "gfx601") | |
4896 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX700, "gfx700") | |
4897 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX701, "gfx701") | |
4898 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX702, "gfx702") | |
4899 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX703, "gfx703") | |
4900 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX704, "gfx704") | |
4901 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX801, "gfx801") | |
4902 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX802, "gfx802") | |
4903 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX803, "gfx803") | |
4904 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX810, "gfx810") | |
4905 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX900, "gfx900") | |
4906 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX902, "gfx902") | |
4907 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX904, "gfx904") | |
4908 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX906, "gfx906") | |
4909 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX908, "gfx908") | |
4910 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX909, "gfx909") | |
4911 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX90C, "gfx90c") | |
4912 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1010, "gfx1010") | |
4913 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1011, "gfx1011") | |
4914 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1012, "gfx1012") | |
4915 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1030, "gfx1030") | |
4916 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1031, "gfx1031") | |
4917 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1032, "gfx1032") | |
4918 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1033, "gfx1033") | |
4919 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1100, "gfx1100") | |
4920 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1101, "gfx1101") | |
4921 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1102, "gfx1102") | |
4922 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX602, "gfx602") | |
4923 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX705, "gfx705") | |
4924 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX805, "gfx805") | |
4925 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1035, "gfx1035") | |
4926 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1034, "gfx1034") | |
4927 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX90A, "gfx90a") | |
4928 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX940, "gfx940") | |
4929 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1013, "gfx1013") | |
4930 | AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1036, "gfx1036") | |
4931 | default: | |
4932 | out += sprintf (out, _(", <unknown AMDGPU GPU type: %#x>"), mach); | |
4933 | break; | |
4934 | #undef AMDGPU_CASE | |
4935 | } | |
4936 | ||
4937 | e_flags &= ~EF_AMDGPU_MACH; | |
4938 | ||
4939 | if ((osabi == ELFOSABI_AMDGPU_HSA | |
4940 | && abiversion == ELFABIVERSION_AMDGPU_HSA_V3) | |
4941 | || osabi != ELFOSABI_AMDGPU_HSA) | |
4942 | { | |
4943 | /* For HSA v3 and other OS ABIs. */ | |
4944 | if (e_flags & EF_AMDGPU_FEATURE_XNACK_V3) | |
4945 | { | |
4946 | out = stpcpy (out, ", xnack on"); | |
4947 | e_flags &= ~EF_AMDGPU_FEATURE_XNACK_V3; | |
4948 | } | |
4949 | ||
4950 | if (e_flags & EF_AMDGPU_FEATURE_SRAMECC_V3) | |
4951 | { | |
4952 | out = stpcpy (out, ", sramecc on"); | |
4953 | e_flags &= ~EF_AMDGPU_FEATURE_SRAMECC_V3; | |
4954 | } | |
4955 | } | |
4956 | else | |
4957 | { | |
4958 | /* For HSA v4+. */ | |
4959 | int xnack, sramecc; | |
4960 | ||
4961 | xnack = e_flags & EF_AMDGPU_FEATURE_XNACK_V4; | |
4962 | switch (xnack) | |
4963 | { | |
4964 | case EF_AMDGPU_FEATURE_XNACK_UNSUPPORTED_V4: | |
4965 | break; | |
4966 | ||
4967 | case EF_AMDGPU_FEATURE_XNACK_ANY_V4: | |
4968 | out = stpcpy (out, ", xnack any"); | |
4969 | break; | |
4970 | ||
4971 | case EF_AMDGPU_FEATURE_XNACK_OFF_V4: | |
4972 | out = stpcpy (out, ", xnack off"); | |
4973 | break; | |
4974 | ||
4975 | case EF_AMDGPU_FEATURE_XNACK_ON_V4: | |
4976 | out = stpcpy (out, ", xnack on"); | |
4977 | break; | |
4978 | ||
4979 | default: | |
4980 | out += sprintf (out, _(", <unknown xnack value: %#x>"), xnack); | |
4981 | break; | |
4982 | } | |
4983 | ||
4984 | e_flags &= ~EF_AMDGPU_FEATURE_XNACK_V4; | |
4985 | ||
4986 | sramecc = e_flags & EF_AMDGPU_FEATURE_SRAMECC_V4; | |
4987 | switch (sramecc) | |
4988 | { | |
4989 | case EF_AMDGPU_FEATURE_SRAMECC_UNSUPPORTED_V4: | |
4990 | break; | |
4991 | ||
4992 | case EF_AMDGPU_FEATURE_SRAMECC_ANY_V4: | |
4993 | out = stpcpy (out, ", sramecc any"); | |
4994 | break; | |
4995 | ||
4996 | case EF_AMDGPU_FEATURE_SRAMECC_OFF_V4: | |
4997 | out = stpcpy (out, ", sramecc off"); | |
4998 | break; | |
4999 | ||
5000 | case EF_AMDGPU_FEATURE_SRAMECC_ON_V4: | |
5001 | out = stpcpy (out, ", sramecc on"); | |
5002 | break; | |
5003 | ||
5004 | default: | |
5005 | out += sprintf (out, _(", <unknown sramecc value: %#x>"), sramecc); | |
5006 | break; | |
5007 | } | |
5008 | ||
5009 | e_flags &= ~EF_AMDGPU_FEATURE_SRAMECC_V4; | |
5010 | } | |
5011 | ||
5012 | if (e_flags != 0) | |
5013 | out += sprintf (out, _(", unknown flags bits: %#x"), e_flags); | |
5014 | return out; | |
5015 | } | |
5016 | ||
5017 | static char * | |
5018 | get_machine_flags (Filedata * filedata, unsigned e_flags, unsigned e_machine) | |
5019 | { | |
5020 | static char buf[1024]; | |
5021 | char *out = buf; | |
5022 | ||
5023 | buf[0] = '\0'; | |
5024 | ||
5025 | if (e_flags) | |
5026 | { | |
5027 | switch (e_machine) | |
5028 | { | |
5029 | default: | |
5030 | break; | |
5031 | ||
5032 | case EM_ARC_COMPACT3: | |
5033 | out = stpcpy (out, ", HS5x"); | |
5034 | break; | |
5035 | ||
5036 | case EM_ARC_COMPACT3_64: | |
5037 | out = stpcpy (out, ", HS6x"); | |
5038 | break; | |
5039 | ||
5040 | case EM_ARC_COMPACT2: | |
5041 | case EM_ARC_COMPACT: | |
5042 | out = decode_ARC_machine_flags (out, e_flags, e_machine); | |
5043 | break; | |
5044 | ||
5045 | case EM_ARM: | |
5046 | out = decode_ARM_machine_flags (out, e_flags); | |
5047 | break; | |
5048 | ||
5049 | case EM_AVR: | |
5050 | out = decode_AVR_machine_flags (out, e_flags); | |
5051 | break; | |
5052 | ||
5053 | case EM_BLACKFIN: | |
5054 | out = decode_BLACKFIN_machine_flags (out, e_flags); | |
5055 | break; | |
5056 | ||
5057 | case EM_CYGNUS_FRV: | |
5058 | out = decode_FRV_machine_flags (out, e_flags); | |
5059 | break; | |
5060 | ||
5061 | case EM_68K: | |
5062 | out = decode_M68K_machine_flags (out, e_flags); | |
5063 | break; | |
5064 | ||
5065 | case EM_AMDGPU: | |
5066 | out = decode_AMDGPU_machine_flags (out, e_flags, filedata); | |
5067 | break; | |
5068 | ||
5069 | case EM_CYGNUS_MEP: | |
5070 | out = decode_MeP_machine_flags (out, e_flags); | |
5071 | break; | |
5072 | ||
5073 | case EM_PPC: | |
5074 | if (e_flags & EF_PPC_EMB) | |
5075 | out = stpcpy (out, ", emb"); | |
5076 | ||
5077 | if (e_flags & EF_PPC_RELOCATABLE) | |
5078 | out = stpcpy (out, _(", relocatable")); | |
5079 | ||
5080 | if (e_flags & EF_PPC_RELOCATABLE_LIB) | |
5081 | out = stpcpy (out, _(", relocatable-lib")); | |
5082 | break; | |
5083 | ||
5084 | case EM_PPC64: | |
5085 | if (e_flags & EF_PPC64_ABI) | |
5086 | out += sprintf (out, ", abiv%d", e_flags & EF_PPC64_ABI); | |
5087 | break; | |
5088 | ||
5089 | case EM_V800: | |
5090 | out = decode_V800_machine_flags (out, e_flags); | |
5091 | break; | |
5092 | ||
5093 | case EM_V850: | |
5094 | case EM_CYGNUS_V850: | |
5095 | out = decode_V850_machine_flags (out, e_flags); | |
5096 | break; | |
5097 | ||
5098 | case EM_M32R: | |
5099 | case EM_CYGNUS_M32R: | |
5100 | if ((e_flags & EF_M32R_ARCH) == E_M32R_ARCH) | |
5101 | out = stpcpy (out, ", m32r"); | |
5102 | break; | |
5103 | ||
5104 | case EM_MIPS: | |
5105 | case EM_MIPS_RS3_LE: | |
5106 | out = decode_MIPS_machine_flags (out, e_flags); | |
5107 | break; | |
5108 | ||
5109 | case EM_NDS32: | |
5110 | out = decode_NDS32_machine_flags (out, e_flags); | |
5111 | break; | |
5112 | ||
5113 | case EM_NFP: | |
5114 | switch (EF_NFP_MACH (e_flags)) | |
5115 | { | |
5116 | case E_NFP_MACH_3200: | |
5117 | out = stpcpy (out, ", NFP-32xx"); | |
5118 | break; | |
5119 | case E_NFP_MACH_6000: | |
5120 | out = stpcpy (out, ", NFP-6xxx"); | |
5121 | break; | |
5122 | } | |
5123 | break; | |
5124 | ||
5125 | case EM_RISCV: | |
5126 | out = decode_RISCV_machine_flags (out, e_flags); | |
5127 | break; | |
5128 | ||
5129 | case EM_SH: | |
5130 | out = decode_SH_machine_flags (out, e_flags); | |
5131 | break; | |
5132 | ||
5133 | case EM_OR1K: | |
5134 | if (e_flags & EF_OR1K_NODELAY) | |
5135 | out = stpcpy (out, ", no delay"); | |
5136 | break; | |
5137 | ||
5138 | case EM_BPF: | |
5139 | out += sprintf (out, ", CPU Version: %u", e_flags & EF_BPF_CPUVER); | |
5140 | break; | |
5141 | ||
5142 | case EM_SPARCV9: | |
5143 | out = decode_SPARC_machine_flags (out, e_flags); | |
5144 | break; | |
5145 | ||
5146 | case EM_PARISC: | |
5147 | out = decode_PARISC_machine_flags (out, e_flags); | |
5148 | break; | |
5149 | ||
5150 | case EM_PJ: | |
5151 | case EM_PJ_OLD: | |
5152 | if ((e_flags & EF_PICOJAVA_NEWCALLS) == EF_PICOJAVA_NEWCALLS) | |
5153 | out = stpcpy (out, ", new calling convention"); | |
5154 | ||
5155 | if ((e_flags & EF_PICOJAVA_GNUCALLS) == EF_PICOJAVA_GNUCALLS) | |
5156 | out = stpcpy (out, ", gnu calling convention"); | |
5157 | break; | |
5158 | ||
5159 | case EM_IA_64: | |
5160 | out = decode_IA64_machine_flags (out, e_flags, filedata); | |
5161 | break; | |
5162 | ||
5163 | case EM_VAX: | |
5164 | if ((e_flags & EF_VAX_NONPIC)) | |
5165 | out = stpcpy (out, ", non-PIC"); | |
5166 | if ((e_flags & EF_VAX_DFLOAT)) | |
5167 | out = stpcpy (out, ", D-Float"); | |
5168 | if ((e_flags & EF_VAX_GFLOAT)) | |
5169 | out = stpcpy (out, ", G-Float"); | |
5170 | break; | |
5171 | ||
5172 | case EM_VISIUM: | |
5173 | if (e_flags & EF_VISIUM_ARCH_MCM) | |
5174 | out = stpcpy (out, ", mcm"); | |
5175 | else if (e_flags & EF_VISIUM_ARCH_MCM24) | |
5176 | out = stpcpy (out, ", mcm24"); | |
5177 | if (e_flags & EF_VISIUM_ARCH_GR6) | |
5178 | out = stpcpy (out, ", gr6"); | |
5179 | break; | |
5180 | ||
5181 | case EM_RL78: | |
5182 | out = decode_RL78_machine_flags (out, e_flags); | |
5183 | break; | |
5184 | ||
5185 | case EM_RX: | |
5186 | out = decode_RX_machine_flags (out, e_flags); | |
5187 | break; | |
5188 | ||
5189 | case EM_S390: | |
5190 | if (e_flags & EF_S390_HIGH_GPRS) | |
5191 | out = stpcpy (out, ", highgprs"); | |
5192 | break; | |
5193 | ||
5194 | case EM_TI_C6000: | |
5195 | if ((e_flags & EF_C6000_REL)) | |
5196 | out = stpcpy (out, ", relocatable module"); | |
5197 | break; | |
5198 | ||
5199 | case EM_KVX: | |
5200 | if ((e_flags & (ELF_KVX_CORE_MAJOR_MASK | ELF_KVX_CORE_MINOR_MASK)) == ELF_KVX_CORE_KV3_1) | |
5201 | strcat (buf, ", Kalray VLIW kv3-1"); | |
5202 | else if ((e_flags & (ELF_KVX_CORE_MAJOR_MASK | ELF_KVX_CORE_MINOR_MASK)) == ELF_KVX_CORE_KV3_2) | |
5203 | strcat (buf, ", Kalray VLIW kv3-2"); | |
5204 | else if ((e_flags & (ELF_KVX_CORE_MAJOR_MASK | ELF_KVX_CORE_MINOR_MASK)) == ELF_KVX_CORE_KV4_1) | |
5205 | strcat (buf, ", Kalray VLIW kv4-1"); | |
5206 | else | |
5207 | strcat (buf, ", unknown KVX MPPA"); | |
5208 | break; | |
5209 | ||
5210 | case EM_MSP430: | |
5211 | out = decode_MSP430_machine_flags (out, e_flags); | |
5212 | break; | |
5213 | ||
5214 | case EM_Z80: | |
5215 | out = decode_Z80_machine_flags (out, e_flags); | |
5216 | break; | |
5217 | ||
5218 | case EM_LOONGARCH: | |
5219 | out = decode_LOONGARCH_machine_flags (out, e_flags); | |
5220 | break; | |
5221 | } | |
5222 | } | |
5223 | ||
5224 | return buf; | |
5225 | } | |
5226 | ||
5227 | static const char * | |
5228 | get_osabi_name (Filedata * filedata, unsigned int osabi) | |
5229 | { | |
5230 | static char buff[32]; | |
5231 | ||
5232 | switch (osabi) | |
5233 | { | |
5234 | case ELFOSABI_NONE: return "UNIX - System V"; | |
5235 | case ELFOSABI_HPUX: return "UNIX - HP-UX"; | |
5236 | case ELFOSABI_NETBSD: return "UNIX - NetBSD"; | |
5237 | case ELFOSABI_GNU: return "UNIX - GNU"; | |
5238 | case ELFOSABI_SOLARIS: return "UNIX - Solaris"; | |
5239 | case ELFOSABI_AIX: return "UNIX - AIX"; | |
5240 | case ELFOSABI_IRIX: return "UNIX - IRIX"; | |
5241 | case ELFOSABI_FREEBSD: return "UNIX - FreeBSD"; | |
5242 | case ELFOSABI_TRU64: return "UNIX - TRU64"; | |
5243 | case ELFOSABI_MODESTO: return "Novell - Modesto"; | |
5244 | case ELFOSABI_OPENBSD: return "UNIX - OpenBSD"; | |
5245 | case ELFOSABI_OPENVMS: return "VMS - OpenVMS"; | |
5246 | case ELFOSABI_NSK: return "HP - Non-Stop Kernel"; | |
5247 | case ELFOSABI_AROS: return "AROS"; | |
5248 | case ELFOSABI_FENIXOS: return "FenixOS"; | |
5249 | case ELFOSABI_CLOUDABI: return "Nuxi CloudABI"; | |
5250 | case ELFOSABI_OPENVOS: return "Stratus Technologies OpenVOS"; | |
5251 | case ELFOSABI_CUDA: return "CUDA"; | |
5252 | default: | |
5253 | if (osabi >= 64) | |
5254 | switch (filedata->file_header.e_machine) | |
5255 | { | |
5256 | case EM_AMDGPU: | |
5257 | switch (osabi) | |
5258 | { | |
5259 | case ELFOSABI_AMDGPU_HSA: return "AMD HSA"; | |
5260 | case ELFOSABI_AMDGPU_PAL: return "AMD PAL"; | |
5261 | case ELFOSABI_AMDGPU_MESA3D: return "AMD Mesa3D"; | |
5262 | default: | |
5263 | break; | |
5264 | } | |
5265 | break; | |
5266 | ||
5267 | case EM_ARM: | |
5268 | switch (osabi) | |
5269 | { | |
5270 | case ELFOSABI_ARM: return "ARM"; | |
5271 | case ELFOSABI_ARM_FDPIC: return "ARM FDPIC"; | |
5272 | default: | |
5273 | break; | |
5274 | } | |
5275 | break; | |
5276 | ||
5277 | case EM_MSP430: | |
5278 | case EM_MSP430_OLD: | |
5279 | case EM_VISIUM: | |
5280 | switch (osabi) | |
5281 | { | |
5282 | case ELFOSABI_STANDALONE: return _("Standalone App"); | |
5283 | default: | |
5284 | break; | |
5285 | } | |
5286 | break; | |
5287 | ||
5288 | case EM_TI_C6000: | |
5289 | switch (osabi) | |
5290 | { | |
5291 | case ELFOSABI_C6000_ELFABI: return _("Bare-metal C6000"); | |
5292 | case ELFOSABI_C6000_LINUX: return "Linux C6000"; | |
5293 | default: | |
5294 | break; | |
5295 | } | |
5296 | break; | |
5297 | ||
5298 | default: | |
5299 | break; | |
5300 | } | |
5301 | snprintf (buff, sizeof (buff), _("<unknown: %x>"), osabi); | |
5302 | return buff; | |
5303 | } | |
5304 | } | |
5305 | ||
5306 | static const char * | |
5307 | get_aarch64_segment_type (unsigned long type) | |
5308 | { | |
5309 | switch (type) | |
5310 | { | |
5311 | case PT_AARCH64_ARCHEXT: return "AARCH64_ARCHEXT"; | |
5312 | case PT_AARCH64_MEMTAG_MTE: return "AARCH64_MEMTAG_MTE"; | |
5313 | default: return NULL; | |
5314 | } | |
5315 | } | |
5316 | ||
5317 | static const char * | |
5318 | get_arm_segment_type (unsigned long type) | |
5319 | { | |
5320 | switch (type) | |
5321 | { | |
5322 | case PT_ARM_ARCHEXT: return "ARM_ARCHEXT"; | |
5323 | case PT_ARM_EXIDX: return "ARM_EXIDX"; | |
5324 | default: return NULL; | |
5325 | } | |
5326 | } | |
5327 | ||
5328 | static const char * | |
5329 | get_s390_segment_type (unsigned long type) | |
5330 | { | |
5331 | switch (type) | |
5332 | { | |
5333 | case PT_S390_PGSTE: return "S390_PGSTE"; | |
5334 | default: return NULL; | |
5335 | } | |
5336 | } | |
5337 | ||
5338 | static const char * | |
5339 | get_mips_segment_type (unsigned long type) | |
5340 | { | |
5341 | switch (type) | |
5342 | { | |
5343 | case PT_MIPS_REGINFO: return "REGINFO"; | |
5344 | case PT_MIPS_RTPROC: return "RTPROC"; | |
5345 | case PT_MIPS_OPTIONS: return "OPTIONS"; | |
5346 | case PT_MIPS_ABIFLAGS: return "ABIFLAGS"; | |
5347 | default: return NULL; | |
5348 | } | |
5349 | } | |
5350 | ||
5351 | static const char * | |
5352 | get_parisc_segment_type (unsigned long type) | |
5353 | { | |
5354 | switch (type) | |
5355 | { | |
5356 | case PT_PARISC_ARCHEXT: return "PARISC_ARCHEXT"; | |
5357 | case PT_PARISC_UNWIND: return "PARISC_UNWIND"; | |
5358 | case PT_PARISC_WEAKORDER: return "PARISC_WEAKORDER"; | |
5359 | default: return NULL; | |
5360 | } | |
5361 | } | |
5362 | ||
5363 | static const char * | |
5364 | get_ia64_segment_type (unsigned long type) | |
5365 | { | |
5366 | switch (type) | |
5367 | { | |
5368 | case PT_IA_64_ARCHEXT: return "IA_64_ARCHEXT"; | |
5369 | case PT_IA_64_UNWIND: return "IA_64_UNWIND"; | |
5370 | default: return NULL; | |
5371 | } | |
5372 | } | |
5373 | ||
5374 | static const char * | |
5375 | get_tic6x_segment_type (unsigned long type) | |
5376 | { | |
5377 | switch (type) | |
5378 | { | |
5379 | case PT_C6000_PHATTR: return "C6000_PHATTR"; | |
5380 | default: return NULL; | |
5381 | } | |
5382 | } | |
5383 | ||
5384 | static const char * | |
5385 | get_riscv_segment_type (unsigned long type) | |
5386 | { | |
5387 | switch (type) | |
5388 | { | |
5389 | case PT_RISCV_ATTRIBUTES: return "RISCV_ATTRIBUTES"; | |
5390 | default: return NULL; | |
5391 | } | |
5392 | } | |
5393 | ||
5394 | static const char * | |
5395 | get_hpux_segment_type (unsigned long type, unsigned e_machine) | |
5396 | { | |
5397 | if (e_machine == EM_PARISC) | |
5398 | switch (type) | |
5399 | { | |
5400 | case PT_HP_TLS: return "HP_TLS"; | |
5401 | case PT_HP_CORE_NONE: return "HP_CORE_NONE"; | |
5402 | case PT_HP_CORE_VERSION: return "HP_CORE_VERSION"; | |
5403 | case PT_HP_CORE_KERNEL: return "HP_CORE_KERNEL"; | |
5404 | case PT_HP_CORE_COMM: return "HP_CORE_COMM"; | |
5405 | case PT_HP_CORE_PROC: return "HP_CORE_PROC"; | |
5406 | case PT_HP_CORE_LOADABLE: return "HP_CORE_LOADABLE"; | |
5407 | case PT_HP_CORE_STACK: return "HP_CORE_STACK"; | |
5408 | case PT_HP_CORE_SHM: return "HP_CORE_SHM"; | |
5409 | case PT_HP_CORE_MMF: return "HP_CORE_MMF"; | |
5410 | case PT_HP_PARALLEL: return "HP_PARALLEL"; | |
5411 | case PT_HP_FASTBIND: return "HP_FASTBIND"; | |
5412 | case PT_HP_OPT_ANNOT: return "HP_OPT_ANNOT"; | |
5413 | case PT_HP_HSL_ANNOT: return "HP_HSL_ANNOT"; | |
5414 | case PT_HP_STACK: return "HP_STACK"; | |
5415 | case PT_HP_CORE_UTSNAME: return "HP_CORE_UTSNAME"; | |
5416 | default: | |
5417 | break; | |
5418 | } | |
5419 | ||
5420 | if (e_machine == EM_IA_64) | |
5421 | switch (type) | |
5422 | { | |
5423 | case PT_HP_TLS: return "HP_TLS"; | |
5424 | case PT_IA_64_HP_OPT_ANOT: return "HP_OPT_ANNOT"; | |
5425 | case PT_IA_64_HP_HSL_ANOT: return "HP_HSL_ANNOT"; | |
5426 | case PT_IA_64_HP_STACK: return "HP_STACK"; | |
5427 | default: | |
5428 | break; | |
5429 | } | |
5430 | ||
5431 | return NULL; | |
5432 | } | |
5433 | ||
5434 | static const char * | |
5435 | get_solaris_segment_type (unsigned long type) | |
5436 | { | |
5437 | switch (type) | |
5438 | { | |
5439 | case PT_SUNW_UNWIND: return "SUNW_UNWIND"; | |
5440 | case PT_SUNW_EH_FRAME: return "SUNW_EH_FRAME"; | |
5441 | case PT_SUNWBSS: return "SUNW_BSS"; | |
5442 | case PT_SUNWSTACK: return "SUNW_STACK"; | |
5443 | case PT_SUNWDTRACE: return "SUNW_DTRACE"; | |
5444 | case PT_SUNWCAP: return "SUNW_CAP"; | |
5445 | default: return NULL; | |
5446 | } | |
5447 | } | |
5448 | ||
5449 | static const char * | |
5450 | get_os_specific_segment_type (Filedata * filedata, unsigned long p_type) | |
5451 | { | |
5452 | static char buff[32]; | |
5453 | const char * result = NULL; | |
5454 | ||
5455 | switch (filedata->file_header.e_ident[EI_OSABI]) | |
5456 | { | |
5457 | case ELFOSABI_GNU: | |
5458 | case ELFOSABI_FREEBSD: | |
5459 | if (p_type >= PT_GNU_MBIND_LO && p_type <= PT_GNU_MBIND_HI) | |
5460 | { | |
5461 | sprintf (buff, "GNU_MBIND+%#lx", p_type - PT_GNU_MBIND_LO); | |
5462 | result = buff; | |
5463 | } | |
5464 | break; | |
5465 | ||
5466 | case ELFOSABI_HPUX: | |
5467 | result = get_hpux_segment_type (p_type, | |
5468 | filedata->file_header.e_machine); | |
5469 | break; | |
5470 | ||
5471 | case ELFOSABI_SOLARIS: | |
5472 | result = get_solaris_segment_type (p_type); | |
5473 | break; | |
5474 | ||
5475 | default: | |
5476 | break; | |
5477 | } | |
5478 | ||
5479 | if (result != NULL) | |
5480 | return result; | |
5481 | ||
5482 | switch (p_type) | |
5483 | { | |
5484 | case PT_GNU_EH_FRAME: return "GNU_EH_FRAME"; | |
5485 | case PT_GNU_STACK: return "GNU_STACK"; | |
5486 | case PT_GNU_RELRO: return "GNU_RELRO"; | |
5487 | case PT_GNU_PROPERTY: return "GNU_PROPERTY"; | |
5488 | case PT_GNU_SFRAME: return "GNU_SFRAME"; | |
5489 | ||
5490 | case PT_OPENBSD_MUTABLE: return "OPENBSD_MUTABLE"; | |
5491 | case PT_OPENBSD_RANDOMIZE: return "OPENBSD_RANDOMIZE"; | |
5492 | case PT_OPENBSD_WXNEEDED: return "OPENBSD_WXNEEDED"; | |
5493 | case PT_OPENBSD_NOBTCFI: return "OPENBSD_NOBTCFI"; | |
5494 | case PT_OPENBSD_SYSCALLS: return "OPENBSD_SYSCALLS"; | |
5495 | case PT_OPENBSD_BOOTDATA: return "OPENBSD_BOOTDATA"; | |
5496 | ||
5497 | default: | |
5498 | break; | |
5499 | } | |
5500 | ||
5501 | sprintf (buff, "LOOS+%#lx", p_type - PT_LOOS); | |
5502 | return buff; | |
5503 | } | |
5504 | ||
5505 | static const char * | |
5506 | get_processor_specific_segment_type (Filedata * filedata, unsigned long p_type) | |
5507 | { | |
5508 | static char buff[32]; | |
5509 | const char * result = NULL; | |
5510 | ||
5511 | switch (filedata->file_header.e_machine) | |
5512 | { | |
5513 | case EM_AARCH64: | |
5514 | result = get_aarch64_segment_type (p_type); | |
5515 | break; | |
5516 | ||
5517 | case EM_ARM: | |
5518 | result = get_arm_segment_type (p_type); | |
5519 | break; | |
5520 | ||
5521 | case EM_MIPS: | |
5522 | case EM_MIPS_RS3_LE: | |
5523 | result = get_mips_segment_type (p_type); | |
5524 | break; | |
5525 | ||
5526 | case EM_PARISC: | |
5527 | result = get_parisc_segment_type (p_type); | |
5528 | break; | |
5529 | ||
5530 | case EM_IA_64: | |
5531 | result = get_ia64_segment_type (p_type); | |
5532 | break; | |
5533 | ||
5534 | case EM_TI_C6000: | |
5535 | result = get_tic6x_segment_type (p_type); | |
5536 | break; | |
5537 | ||
5538 | case EM_S390: | |
5539 | case EM_S390_OLD: | |
5540 | result = get_s390_segment_type (p_type); | |
5541 | break; | |
5542 | ||
5543 | case EM_RISCV: | |
5544 | result = get_riscv_segment_type (p_type); | |
5545 | break; | |
5546 | ||
5547 | default: | |
5548 | result = NULL; | |
5549 | break; | |
5550 | } | |
5551 | ||
5552 | if (result != NULL) | |
5553 | return result; | |
5554 | ||
5555 | sprintf (buff, "LOPROC+%#lx", p_type - PT_LOPROC); | |
5556 | return buff; | |
5557 | } | |
5558 | ||
5559 | static const char * | |
5560 | get_segment_type (Filedata * filedata, unsigned long p_type) | |
5561 | { | |
5562 | static char buff[32]; | |
5563 | ||
5564 | switch (p_type) | |
5565 | { | |
5566 | case PT_NULL: return "NULL"; | |
5567 | case PT_LOAD: return "LOAD"; | |
5568 | case PT_DYNAMIC: return "DYNAMIC"; | |
5569 | case PT_INTERP: return "INTERP"; | |
5570 | case PT_NOTE: return "NOTE"; | |
5571 | case PT_SHLIB: return "SHLIB"; | |
5572 | case PT_PHDR: return "PHDR"; | |
5573 | case PT_TLS: return "TLS"; | |
5574 | case PT_NUM: return "NUM"; | |
5575 | } | |
5576 | ||
5577 | if ((p_type >= PT_LOOS) && (p_type <= PT_HIOS)) | |
5578 | return get_os_specific_segment_type (filedata, p_type); | |
5579 | ||
5580 | if ((p_type >= PT_LOPROC) && (p_type <= PT_HIPROC)) | |
5581 | return get_processor_specific_segment_type (filedata, p_type); | |
5582 | ||
5583 | snprintf (buff, sizeof (buff), _("<unknown>: %lx"), p_type); | |
5584 | return buff; | |
5585 | } | |
5586 | ||
5587 | static const char * | |
5588 | get_arc_section_type_name (unsigned int sh_type) | |
5589 | { | |
5590 | switch (sh_type) | |
5591 | { | |
5592 | case SHT_ARC_ATTRIBUTES: return "ARC_ATTRIBUTES"; | |
5593 | default: | |
5594 | break; | |
5595 | } | |
5596 | return NULL; | |
5597 | } | |
5598 | ||
5599 | static const char * | |
5600 | get_mips_section_type_name (unsigned int sh_type) | |
5601 | { | |
5602 | switch (sh_type) | |
5603 | { | |
5604 | case SHT_MIPS_LIBLIST: return "MIPS_LIBLIST"; | |
5605 | case SHT_MIPS_MSYM: return "MIPS_MSYM"; | |
5606 | case SHT_MIPS_CONFLICT: return "MIPS_CONFLICT"; | |
5607 | case SHT_MIPS_GPTAB: return "MIPS_GPTAB"; | |
5608 | case SHT_MIPS_UCODE: return "MIPS_UCODE"; | |
5609 | case SHT_MIPS_DEBUG: return "MIPS_DEBUG"; | |
5610 | case SHT_MIPS_REGINFO: return "MIPS_REGINFO"; | |
5611 | case SHT_MIPS_PACKAGE: return "MIPS_PACKAGE"; | |
5612 | case SHT_MIPS_PACKSYM: return "MIPS_PACKSYM"; | |
5613 | case SHT_MIPS_RELD: return "MIPS_RELD"; | |
5614 | case SHT_MIPS_IFACE: return "MIPS_IFACE"; | |
5615 | case SHT_MIPS_CONTENT: return "MIPS_CONTENT"; | |
5616 | case SHT_MIPS_OPTIONS: return "MIPS_OPTIONS"; | |
5617 | case SHT_MIPS_SHDR: return "MIPS_SHDR"; | |
5618 | case SHT_MIPS_FDESC: return "MIPS_FDESC"; | |
5619 | case SHT_MIPS_EXTSYM: return "MIPS_EXTSYM"; | |
5620 | case SHT_MIPS_DENSE: return "MIPS_DENSE"; | |
5621 | case SHT_MIPS_PDESC: return "MIPS_PDESC"; | |
5622 | case SHT_MIPS_LOCSYM: return "MIPS_LOCSYM"; | |
5623 | case SHT_MIPS_AUXSYM: return "MIPS_AUXSYM"; | |
5624 | case SHT_MIPS_OPTSYM: return "MIPS_OPTSYM"; | |
5625 | case SHT_MIPS_LOCSTR: return "MIPS_LOCSTR"; | |
5626 | case SHT_MIPS_LINE: return "MIPS_LINE"; | |
5627 | case SHT_MIPS_RFDESC: return "MIPS_RFDESC"; | |
5628 | case SHT_MIPS_DELTASYM: return "MIPS_DELTASYM"; | |
5629 | case SHT_MIPS_DELTAINST: return "MIPS_DELTAINST"; | |
5630 | case SHT_MIPS_DELTACLASS: return "MIPS_DELTACLASS"; | |
5631 | case SHT_MIPS_DWARF: return "MIPS_DWARF"; | |
5632 | case SHT_MIPS_DELTADECL: return "MIPS_DELTADECL"; | |
5633 | case SHT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB"; | |
5634 | case SHT_MIPS_EVENTS: return "MIPS_EVENTS"; | |
5635 | case SHT_MIPS_TRANSLATE: return "MIPS_TRANSLATE"; | |
5636 | case SHT_MIPS_PIXIE: return "MIPS_PIXIE"; | |
5637 | case SHT_MIPS_XLATE: return "MIPS_XLATE"; | |
5638 | case SHT_MIPS_XLATE_DEBUG: return "MIPS_XLATE_DEBUG"; | |
5639 | case SHT_MIPS_WHIRL: return "MIPS_WHIRL"; | |
5640 | case SHT_MIPS_EH_REGION: return "MIPS_EH_REGION"; | |
5641 | case SHT_MIPS_XLATE_OLD: return "MIPS_XLATE_OLD"; | |
5642 | case SHT_MIPS_PDR_EXCEPTION: return "MIPS_PDR_EXCEPTION"; | |
5643 | case SHT_MIPS_ABIFLAGS: return "MIPS_ABIFLAGS"; | |
5644 | case SHT_MIPS_XHASH: return "MIPS_XHASH"; | |
5645 | default: | |
5646 | break; | |
5647 | } | |
5648 | return NULL; | |
5649 | } | |
5650 | ||
5651 | static const char * | |
5652 | get_parisc_section_type_name (unsigned int sh_type) | |
5653 | { | |
5654 | switch (sh_type) | |
5655 | { | |
5656 | case SHT_PARISC_EXT: return "PARISC_EXT"; | |
5657 | case SHT_PARISC_UNWIND: return "PARISC_UNWIND"; | |
5658 | case SHT_PARISC_DOC: return "PARISC_DOC"; | |
5659 | case SHT_PARISC_ANNOT: return "PARISC_ANNOT"; | |
5660 | case SHT_PARISC_DLKM: return "PARISC_DLKM"; | |
5661 | case SHT_PARISC_SYMEXTN: return "PARISC_SYMEXTN"; | |
5662 | case SHT_PARISC_STUBS: return "PARISC_STUBS"; | |
5663 | default: return NULL; | |
5664 | } | |
5665 | } | |
5666 | ||
5667 | static const char * | |
5668 | get_ia64_section_type_name (Filedata * filedata, unsigned int sh_type) | |
5669 | { | |
5670 | /* If the top 8 bits are 0x78 the next 8 are the os/abi ID. */ | |
5671 | if ((sh_type & 0xFF000000) == SHT_IA_64_LOPSREG) | |
5672 | return get_osabi_name (filedata, (sh_type & 0x00FF0000) >> 16); | |
5673 | ||
5674 | switch (sh_type) | |
5675 | { | |
5676 | case SHT_IA_64_EXT: return "IA_64_EXT"; | |
5677 | case SHT_IA_64_UNWIND: return "IA_64_UNWIND"; | |
5678 | case SHT_IA_64_PRIORITY_INIT: return "IA_64_PRIORITY_INIT"; | |
5679 | default: | |
5680 | break; | |
5681 | } | |
5682 | return NULL; | |
5683 | } | |
5684 | ||
5685 | static const char * | |
5686 | get_vms_section_type_name (unsigned int sh_type) | |
5687 | { | |
5688 | switch (sh_type) | |
5689 | { | |
5690 | case SHT_IA_64_VMS_TRACE: return "VMS_TRACE"; | |
5691 | case SHT_IA_64_VMS_TIE_SIGNATURES: return "VMS_TIE_SIGNATURES"; | |
5692 | case SHT_IA_64_VMS_DEBUG: return "VMS_DEBUG"; | |
5693 | case SHT_IA_64_VMS_DEBUG_STR: return "VMS_DEBUG_STR"; | |
5694 | case SHT_IA_64_VMS_LINKAGES: return "VMS_LINKAGES"; | |
5695 | case SHT_IA_64_VMS_SYMBOL_VECTOR: return "VMS_SYMBOL_VECTOR"; | |
5696 | case SHT_IA_64_VMS_FIXUP: return "VMS_FIXUP"; | |
5697 | default: | |
5698 | break; | |
5699 | } | |
5700 | return NULL; | |
5701 | } | |
5702 | ||
5703 | static const char * | |
5704 | get_x86_64_section_type_name (unsigned int sh_type) | |
5705 | { | |
5706 | switch (sh_type) | |
5707 | { | |
5708 | case SHT_X86_64_UNWIND: return "X86_64_UNWIND"; | |
5709 | default: return NULL; | |
5710 | } | |
5711 | } | |
5712 | ||
5713 | static const char * | |
5714 | get_aarch64_section_type_name (unsigned int sh_type) | |
5715 | { | |
5716 | switch (sh_type) | |
5717 | { | |
5718 | case SHT_AARCH64_ATTRIBUTES: | |
5719 | return "AARCH64_ATTRIBUTES"; | |
5720 | case SHT_AARCH64_AUTH_RELR: | |
5721 | return "AARCH64_AUTH_RELR"; | |
5722 | case SHT_AARCH64_MEMTAG_GLOBALS_STATIC: | |
5723 | return "AARCH64_MEMTAG_GLOBALS_STATIC"; | |
5724 | case SHT_AARCH64_MEMTAG_GLOBALS_DYNAMIC: | |
5725 | return "AARCH64_MEMTAG_GLOBALS_DYNAMIC"; | |
5726 | default: | |
5727 | return NULL; | |
5728 | } | |
5729 | } | |
5730 | ||
5731 | static const char * | |
5732 | get_arm_section_type_name (unsigned int sh_type) | |
5733 | { | |
5734 | switch (sh_type) | |
5735 | { | |
5736 | case SHT_ARM_EXIDX: return "ARM_EXIDX"; | |
5737 | case SHT_ARM_PREEMPTMAP: return "ARM_PREEMPTMAP"; | |
5738 | case SHT_ARM_ATTRIBUTES: return "ARM_ATTRIBUTES"; | |
5739 | case SHT_ARM_DEBUGOVERLAY: return "ARM_DEBUGOVERLAY"; | |
5740 | case SHT_ARM_OVERLAYSECTION: return "ARM_OVERLAYSECTION"; | |
5741 | default: return NULL; | |
5742 | } | |
5743 | } | |
5744 | ||
5745 | static const char * | |
5746 | get_tic6x_section_type_name (unsigned int sh_type) | |
5747 | { | |
5748 | switch (sh_type) | |
5749 | { | |
5750 | case SHT_C6000_UNWIND: return "C6000_UNWIND"; | |
5751 | case SHT_C6000_PREEMPTMAP: return "C6000_PREEMPTMAP"; | |
5752 | case SHT_C6000_ATTRIBUTES: return "C6000_ATTRIBUTES"; | |
5753 | case SHT_TI_ICODE: return "TI_ICODE"; | |
5754 | case SHT_TI_XREF: return "TI_XREF"; | |
5755 | case SHT_TI_HANDLER: return "TI_HANDLER"; | |
5756 | case SHT_TI_INITINFO: return "TI_INITINFO"; | |
5757 | case SHT_TI_PHATTRS: return "TI_PHATTRS"; | |
5758 | default: return NULL; | |
5759 | } | |
5760 | } | |
5761 | ||
5762 | static const char * | |
5763 | get_msp430_section_type_name (unsigned int sh_type) | |
5764 | { | |
5765 | switch (sh_type) | |
5766 | { | |
5767 | case SHT_MSP430_SEC_FLAGS: return "MSP430_SEC_FLAGS"; | |
5768 | case SHT_MSP430_SYM_ALIASES: return "MSP430_SYM_ALIASES"; | |
5769 | case SHT_MSP430_ATTRIBUTES: return "MSP430_ATTRIBUTES"; | |
5770 | default: return NULL; | |
5771 | } | |
5772 | } | |
5773 | ||
5774 | static const char * | |
5775 | get_nfp_section_type_name (unsigned int sh_type) | |
5776 | { | |
5777 | switch (sh_type) | |
5778 | { | |
5779 | case SHT_NFP_MECONFIG: return "NFP_MECONFIG"; | |
5780 | case SHT_NFP_INITREG: return "NFP_INITREG"; | |
5781 | case SHT_NFP_UDEBUG: return "NFP_UDEBUG"; | |
5782 | default: return NULL; | |
5783 | } | |
5784 | } | |
5785 | ||
5786 | static const char * | |
5787 | get_v850_section_type_name (unsigned int sh_type) | |
5788 | { | |
5789 | switch (sh_type) | |
5790 | { | |
5791 | case SHT_V850_SCOMMON: return "V850 Small Common"; | |
5792 | case SHT_V850_TCOMMON: return "V850 Tiny Common"; | |
5793 | case SHT_V850_ZCOMMON: return "V850 Zero Common"; | |
5794 | case SHT_RENESAS_IOP: return "RENESAS IOP"; | |
5795 | case SHT_RENESAS_INFO: return "RENESAS INFO"; | |
5796 | default: return NULL; | |
5797 | } | |
5798 | } | |
5799 | ||
5800 | static const char * | |
5801 | get_riscv_section_type_name (unsigned int sh_type) | |
5802 | { | |
5803 | switch (sh_type) | |
5804 | { | |
5805 | case SHT_RISCV_ATTRIBUTES: return "RISCV_ATTRIBUTES"; | |
5806 | default: return NULL; | |
5807 | } | |
5808 | } | |
5809 | ||
5810 | static const char * | |
5811 | get_csky_section_type_name (unsigned int sh_type) | |
5812 | { | |
5813 | switch (sh_type) | |
5814 | { | |
5815 | case SHT_CSKY_ATTRIBUTES: return "CSKY_ATTRIBUTES"; | |
5816 | default: return NULL; | |
5817 | } | |
5818 | } | |
5819 | ||
5820 | static const char * | |
5821 | get_powerpc_section_type_name (unsigned int sh_type) | |
5822 | { | |
5823 | switch (sh_type) | |
5824 | { | |
5825 | case SHT_ORDERED: return "ORDERED"; | |
5826 | default: return NULL; | |
5827 | } | |
5828 | } | |
5829 | ||
5830 | static const char * | |
5831 | get_alpha_section_type_name (unsigned int sh_type) | |
5832 | { | |
5833 | switch (sh_type) | |
5834 | { | |
5835 | case SHT_ALPHA_DEBUG: return "DEBUG"; | |
5836 | case SHT_ALPHA_REGINFO: return "REGINFO"; | |
5837 | default: return NULL; | |
5838 | } | |
5839 | } | |
5840 | ||
5841 | static const char * | |
5842 | get_processor_specific_section_type_name (Filedata * filedata, unsigned int sh_type) | |
5843 | { | |
5844 | static char buff[32]; | |
5845 | const char * result = NULL; | |
5846 | ||
5847 | switch (filedata->file_header.e_machine) | |
5848 | { | |
5849 | case EM_AARCH64: | |
5850 | result = get_aarch64_section_type_name (sh_type); | |
5851 | break; | |
5852 | ||
5853 | case EM_ALPHA: | |
5854 | result = get_alpha_section_type_name (sh_type); | |
5855 | break; | |
5856 | ||
5857 | case EM_ARC: | |
5858 | case EM_ARC_COMPACT: | |
5859 | case EM_ARC_COMPACT2: | |
5860 | case EM_ARC_COMPACT3: | |
5861 | case EM_ARC_COMPACT3_64: | |
5862 | result = get_arc_section_type_name (sh_type); | |
5863 | break; | |
5864 | ||
5865 | case EM_ARM: | |
5866 | result = get_arm_section_type_name (sh_type); | |
5867 | break; | |
5868 | ||
5869 | case EM_CSKY: | |
5870 | result = get_csky_section_type_name (sh_type); | |
5871 | break; | |
5872 | ||
5873 | case EM_IA_64: | |
5874 | result = get_ia64_section_type_name (filedata, sh_type); | |
5875 | break; | |
5876 | ||
5877 | case EM_MIPS: | |
5878 | case EM_MIPS_RS3_LE: | |
5879 | result = get_mips_section_type_name (sh_type); | |
5880 | break; | |
5881 | ||
5882 | case EM_MSP430: | |
5883 | result = get_msp430_section_type_name (sh_type); | |
5884 | break; | |
5885 | ||
5886 | case EM_NFP: | |
5887 | result = get_nfp_section_type_name (sh_type); | |
5888 | break; | |
5889 | ||
5890 | case EM_PARISC: | |
5891 | result = get_parisc_section_type_name (sh_type); | |
5892 | break; | |
5893 | ||
5894 | case EM_PPC64: | |
5895 | case EM_PPC: | |
5896 | return get_powerpc_section_type_name (sh_type); | |
5897 | break; | |
5898 | ||
5899 | case EM_RISCV: | |
5900 | result = get_riscv_section_type_name (sh_type); | |
5901 | break; | |
5902 | ||
5903 | case EM_TI_C6000: | |
5904 | result = get_tic6x_section_type_name (sh_type); | |
5905 | break; | |
5906 | ||
5907 | case EM_V800: | |
5908 | case EM_V850: | |
5909 | case EM_CYGNUS_V850: | |
5910 | result = get_v850_section_type_name (sh_type); | |
5911 | break; | |
5912 | ||
5913 | case EM_X86_64: | |
5914 | case EM_L1OM: | |
5915 | case EM_K1OM: | |
5916 | result = get_x86_64_section_type_name (sh_type); | |
5917 | break; | |
5918 | ||
5919 | default: | |
5920 | break; | |
5921 | } | |
5922 | ||
5923 | if (result != NULL) | |
5924 | return result; | |
5925 | ||
5926 | switch (sh_type) | |
5927 | { | |
5928 | /* FIXME: Are these correct ? If so, why do they not have #define's ? */ | |
5929 | case 0x7ffffffd: return "AUXILIARY"; | |
5930 | case 0x7fffffff: return "FILTER"; | |
5931 | default: | |
5932 | break; | |
5933 | } | |
5934 | ||
5935 | sprintf (buff, "LOPROC+%#x", sh_type - SHT_LOPROC); | |
5936 | return buff; | |
5937 | } | |
5938 | ||
5939 | static const char * | |
5940 | get_os_specific_section_type_name (Filedata * filedata, unsigned int sh_type) | |
5941 | { | |
5942 | static char buff[32]; | |
5943 | const char * result = NULL; | |
5944 | ||
5945 | switch (filedata->file_header.e_machine) | |
5946 | { | |
5947 | case EM_IA_64: | |
5948 | result = get_vms_section_type_name (sh_type); | |
5949 | break; | |
5950 | default: | |
5951 | break; | |
5952 | } | |
5953 | ||
5954 | if (result != NULL) | |
5955 | return result; | |
5956 | ||
5957 | if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS) | |
5958 | result = get_solaris_section_type (sh_type); | |
5959 | ||
5960 | if (result != NULL) | |
5961 | return result; | |
5962 | ||
5963 | switch (sh_type) | |
5964 | { | |
5965 | case SHT_GNU_INCREMENTAL_INPUTS: return "GNU_INCREMENTAL_INPUTS"; | |
5966 | case SHT_GNU_ATTRIBUTES: return "GNU_ATTRIBUTES"; | |
5967 | case SHT_GNU_HASH: return "GNU_HASH"; | |
5968 | case SHT_GNU_LIBLIST: return "GNU_LIBLIST"; | |
5969 | case SHT_GNU_OBJECT_ONLY: return "GNU_OBJECT_ONLY"; | |
5970 | case SHT_GNU_SFRAME: return "GNU_SFRAME"; | |
5971 | ||
5972 | case SHT_SUNW_move: return "SUNW_MOVE"; | |
5973 | case SHT_SUNW_COMDAT: return "SUNW_COMDAT"; | |
5974 | case SHT_SUNW_syminfo: return "SUNW_SYMINFO"; | |
5975 | case SHT_GNU_verdef: return "VERDEF"; | |
5976 | case SHT_GNU_verneed: return "VERNEED"; | |
5977 | case SHT_GNU_versym: return "VERSYM"; | |
5978 | ||
5979 | case SHT_LLVM_ODRTAB: return "LLVM_ODRTAB"; | |
5980 | case SHT_LLVM_LINKER_OPTIONS: return "LLVM_LINKER_OPTIONS"; | |
5981 | case SHT_LLVM_ADDRSIG: return "LLVM_ADDRSIG"; | |
5982 | case SHT_LLVM_DEPENDENT_LIBRARIES: return "LLVM_DEPENDENT_LIBRARIES"; | |
5983 | case SHT_LLVM_SYMPART: return "LLVM_SYMPART"; | |
5984 | case SHT_LLVM_PART_EHDR: return "LLVM_PART_EHDR"; | |
5985 | case SHT_LLVM_PART_PHDR: return "LLVM_PART_PHDR"; | |
5986 | case SHT_LLVM_BB_ADDR_MAP_V0: return "LLVM_BB_ADDR_MAP_V0"; | |
5987 | case SHT_LLVM_CALL_GRAPH_PROFILE: return "LLVM_CALL_GRAPH_PROFILE"; | |
5988 | case SHT_LLVM_BB_ADDR_MAP: return "LLVM_BB_ADDR_MAP"; | |
5989 | case SHT_LLVM_OFFLOADING: return "LLVM_OFFLOADING"; | |
5990 | case SHT_LLVM_LTO: return "LLVM_LTO"; | |
5991 | ||
5992 | case SHT_ANDROID_REL: return "ANDROID_REL"; | |
5993 | case SHT_ANDROID_RELA: return "ANDROID_RELA"; | |
5994 | case SHT_ANDROID_RELR: return "ANDROID_RELR"; | |
5995 | ||
5996 | case SHT_CHECKSUM: return "CHECKSUM"; | |
5997 | ||
5998 | /* FIXME: Are these correct ? If so, why do they not have #define's ? */ | |
5999 | case 0x6ffffff0: return "VERSYM"; | |
6000 | ||
6001 | default: | |
6002 | break; | |
6003 | } | |
6004 | ||
6005 | sprintf (buff, "LOOS+%#x", sh_type - SHT_LOOS); | |
6006 | return buff; | |
6007 | } | |
6008 | ||
6009 | static const char * | |
6010 | get_user_specific_section_type_name (Filedata * filedata, unsigned int sh_type) | |
6011 | { | |
6012 | static char buff[32]; | |
6013 | const char * result; | |
6014 | ||
6015 | switch (filedata->file_header.e_machine) | |
6016 | { | |
6017 | case EM_V800: | |
6018 | case EM_V850: | |
6019 | case EM_CYGNUS_V850: | |
6020 | result = get_v850_section_type_name (sh_type); | |
6021 | break; | |
6022 | ||
6023 | default: | |
6024 | result = NULL; | |
6025 | break; | |
6026 | } | |
6027 | ||
6028 | if (result != NULL) | |
6029 | return result; | |
6030 | ||
6031 | sprintf (buff, "LOUSER+%#x", sh_type - SHT_LOUSER); | |
6032 | return buff; | |
6033 | } | |
6034 | ||
6035 | static const char * | |
6036 | get_section_type_name (Filedata * filedata, | |
6037 | unsigned int sh_type) | |
6038 | { | |
6039 | switch (sh_type) | |
6040 | { | |
6041 | case SHT_NULL: return "NULL"; | |
6042 | case SHT_PROGBITS: return "PROGBITS"; | |
6043 | case SHT_SYMTAB: return "SYMTAB"; | |
6044 | case SHT_STRTAB: return "STRTAB"; | |
6045 | case SHT_RELA: return "RELA"; | |
6046 | case SHT_HASH: return "HASH"; | |
6047 | case SHT_DYNAMIC: return "DYNAMIC"; | |
6048 | case SHT_NOTE: return "NOTE"; | |
6049 | case SHT_NOBITS: return "NOBITS"; | |
6050 | case SHT_REL: return "REL"; | |
6051 | case SHT_SHLIB: return "SHLIB"; | |
6052 | case SHT_DYNSYM: return "DYNSYM"; | |
6053 | /* 12 and 13 are not defined. */ | |
6054 | case SHT_INIT_ARRAY: return "INIT_ARRAY"; | |
6055 | case SHT_FINI_ARRAY: return "FINI_ARRAY"; | |
6056 | case SHT_PREINIT_ARRAY: return "PREINIT_ARRAY"; | |
6057 | case SHT_GROUP: return "GROUP"; | |
6058 | case SHT_SYMTAB_SHNDX: return "SYMTAB SECTION INDICES"; | |
6059 | case SHT_RELR: return "RELR"; | |
6060 | /* End of generic section types. */ | |
6061 | ||
6062 | default: | |
6063 | break; | |
6064 | } | |
6065 | ||
6066 | if ((sh_type >= SHT_LOPROC) && (sh_type <= SHT_HIPROC)) | |
6067 | return get_processor_specific_section_type_name (filedata, sh_type); | |
6068 | ||
6069 | if ((sh_type >= SHT_LOOS) && (sh_type <= SHT_HIOS)) | |
6070 | return get_os_specific_section_type_name (filedata, sh_type); | |
6071 | ||
6072 | if ((sh_type >= SHT_LOUSER) && (sh_type <= SHT_HIUSER)) | |
6073 | return get_user_specific_section_type_name (filedata, sh_type); | |
6074 | ||
6075 | static char buff[32]; | |
6076 | ||
6077 | /* This message is probably going to be displayed in a 15 | |
6078 | character wide field, so put the hex value first. */ | |
6079 | snprintf (buff, sizeof (buff), _("%08x: <unknown>"), sh_type); | |
6080 | return buff; | |
6081 | } | |
6082 | ||
6083 | enum long_option_values | |
6084 | { | |
6085 | OPTION_DEBUG_DUMP = 512, | |
6086 | OPTION_DYN_SYMS, | |
6087 | OPTION_LTO_SYMS, | |
6088 | OPTION_DWARF_DEPTH, | |
6089 | OPTION_DWARF_START, | |
6090 | OPTION_DWARF_CHECK, | |
6091 | OPTION_CTF_DUMP, | |
6092 | OPTION_CTF_PARENT, | |
6093 | OPTION_CTF_SYMBOLS, | |
6094 | OPTION_CTF_STRINGS, | |
6095 | OPTION_SFRAME_DUMP, | |
6096 | OPTION_WITH_SYMBOL_VERSIONS, | |
6097 | OPTION_RECURSE_LIMIT, | |
6098 | OPTION_NO_RECURSE_LIMIT, | |
6099 | OPTION_NO_DEMANGLING, | |
6100 | OPTION_NO_EXTRA_SYM_INFO, | |
6101 | OPTION_SYM_BASE | |
6102 | }; | |
6103 | ||
6104 | static struct option options[] = | |
6105 | { | |
6106 | /* Note - This table is alpha-sorted on the 'val' | |
6107 | field in order to make adding new options easier. */ | |
6108 | {"arch-specific", no_argument, 0, 'A'}, | |
6109 | {"all", no_argument, 0, 'a'}, | |
6110 | {"demangle", optional_argument, 0, 'C'}, | |
6111 | {"archive-index", no_argument, 0, 'c'}, | |
6112 | {"use-dynamic", no_argument, 0, 'D'}, | |
6113 | {"dynamic", no_argument, 0, 'd'}, | |
6114 | {"headers", no_argument, 0, 'e'}, | |
6115 | {"section-groups", no_argument, 0, 'g'}, | |
6116 | {"help", no_argument, 0, 'H'}, | |
6117 | {"file-header", no_argument, 0, 'h'}, | |
6118 | {"histogram", no_argument, 0, 'I'}, | |
6119 | {"display-section", required_argument, 0, 'j'}, | |
6120 | {"lint", no_argument, 0, 'L'}, | |
6121 | {"enable-checks", no_argument, 0, 'L'}, | |
6122 | {"program-headers", no_argument, 0, 'l'}, | |
6123 | {"segments", no_argument, 0, 'l'}, | |
6124 | {"full-section-name",no_argument, 0, 'N'}, | |
6125 | {"notes", no_argument, 0, 'n'}, | |
6126 | {"process-links", no_argument, 0, 'P'}, | |
6127 | {"string-dump", required_argument, 0, 'p'}, | |
6128 | {"relocated-dump", required_argument, 0, 'R'}, | |
6129 | {"relocs", no_argument, 0, 'r'}, | |
6130 | {"section-headers", no_argument, 0, 'S'}, | |
6131 | {"sections", no_argument, 0, 'S'}, | |
6132 | {"symbols", no_argument, 0, 's'}, | |
6133 | {"syms", no_argument, 0, 's'}, | |
6134 | {"silent-truncation",no_argument, 0, 'T'}, | |
6135 | {"section-details", no_argument, 0, 't'}, | |
6136 | {"unicode", required_argument, NULL, 'U'}, | |
6137 | {"unwind", no_argument, 0, 'u'}, | |
6138 | {"version-info", no_argument, 0, 'V'}, | |
6139 | {"version", no_argument, 0, 'v'}, | |
6140 | {"wide", no_argument, 0, 'W'}, | |
6141 | {"extra-sym-info", no_argument, 0, 'X'}, | |
6142 | {"hex-dump", required_argument, 0, 'x'}, | |
6143 | {"decompress", no_argument, 0, 'z'}, | |
6144 | ||
6145 | {"no-demangle", no_argument, 0, OPTION_NO_DEMANGLING}, | |
6146 | {"no-extra-sym-info",no_argument, 0, OPTION_NO_EXTRA_SYM_INFO}, | |
6147 | {"recurse-limit", no_argument, NULL, OPTION_RECURSE_LIMIT}, | |
6148 | {"no-recurse-limit", no_argument, NULL, OPTION_NO_RECURSE_LIMIT}, | |
6149 | {"no-recursion-limit", no_argument, NULL, OPTION_NO_RECURSE_LIMIT}, | |
6150 | {"dyn-syms", no_argument, 0, OPTION_DYN_SYMS}, | |
6151 | {"lto-syms", no_argument, 0, OPTION_LTO_SYMS}, | |
6152 | {"debug-dump", optional_argument, 0, OPTION_DEBUG_DUMP}, | |
6153 | {"dwarf-depth", required_argument, 0, OPTION_DWARF_DEPTH}, | |
6154 | {"dwarf-start", required_argument, 0, OPTION_DWARF_START}, | |
6155 | {"dwarf-check", no_argument, 0, OPTION_DWARF_CHECK}, | |
6156 | #ifdef ENABLE_LIBCTF | |
6157 | {"ctf", required_argument, 0, OPTION_CTF_DUMP}, | |
6158 | {"ctf-symbols", required_argument, 0, OPTION_CTF_SYMBOLS}, | |
6159 | {"ctf-strings", required_argument, 0, OPTION_CTF_STRINGS}, | |
6160 | {"ctf-parent", required_argument, 0, OPTION_CTF_PARENT}, | |
6161 | #endif | |
6162 | {"sframe", optional_argument, 0, OPTION_SFRAME_DUMP}, | |
6163 | {"sym-base", optional_argument, 0, OPTION_SYM_BASE}, | |
6164 | ||
6165 | {0, no_argument, 0, 0} | |
6166 | }; | |
6167 | ||
6168 | static void | |
6169 | usage (FILE * stream) | |
6170 | { | |
6171 | fprintf (stream, _("Usage: readelf <option(s)> elf-file(s)\n")); | |
6172 | fprintf (stream, _(" Display information about the contents of ELF format files\n")); | |
6173 | fprintf (stream, _(" Options are:\n")); | |
6174 | fprintf (stream, _("\ | |
6175 | -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n")); | |
6176 | fprintf (stream, _("\ | |
6177 | -h --file-header Display the ELF file header\n")); | |
6178 | fprintf (stream, _("\ | |
6179 | -l --program-headers Display the program headers\n")); | |
6180 | fprintf (stream, _("\ | |
6181 | --segments An alias for --program-headers\n")); | |
6182 | fprintf (stream, _("\ | |
6183 | -S --section-headers Display the sections' header\n")); | |
6184 | fprintf (stream, _("\ | |
6185 | --sections An alias for --section-headers\n")); | |
6186 | fprintf (stream, _("\ | |
6187 | -g --section-groups Display the section groups\n")); | |
6188 | fprintf (stream, _("\ | |
6189 | -t --section-details Display the section details\n")); | |
6190 | fprintf (stream, _("\ | |
6191 | -e --headers Equivalent to: -h -l -S\n")); | |
6192 | fprintf (stream, _("\ | |
6193 | -s --syms Display the symbol table\n")); | |
6194 | fprintf (stream, _("\ | |
6195 | --symbols An alias for --syms\n")); | |
6196 | fprintf (stream, _("\ | |
6197 | --dyn-syms Display the dynamic symbol table\n")); | |
6198 | fprintf (stream, _("\ | |
6199 | --lto-syms Display LTO symbol tables\n")); | |
6200 | fprintf (stream, _("\ | |
6201 | --sym-base=[0|8|10|16] \n\ | |
6202 | Force base for symbol sizes. The options are \n\ | |
6203 | mixed (the default), octal, decimal, hexadecimal.\n")); | |
6204 | fprintf (stream, _("\ | |
6205 | -C --demangle[=STYLE] Decode mangled/processed symbol names\n")); | |
6206 | display_demangler_styles (stream, _("\ | |
6207 | STYLE can be ")); | |
6208 | fprintf (stream, _("\ | |
6209 | --no-demangle Do not demangle low-level symbol names. (default)\n")); | |
6210 | fprintf (stream, _("\ | |
6211 | --recurse-limit Enable a demangling recursion limit. (default)\n")); | |
6212 | fprintf (stream, _("\ | |
6213 | --no-recurse-limit Disable a demangling recursion limit\n")); | |
6214 | fprintf (stream, _("\ | |
6215 | -U[dlexhi] --unicode=[default|locale|escape|hex|highlight|invalid]\n\ | |
6216 | Display unicode characters as determined by the current locale\n\ | |
6217 | (default), escape sequences, \"<hex sequences>\", highlighted\n\ | |
6218 | escape sequences, or treat them as invalid and display as\n\ | |
6219 | \"{hex sequences}\"\n")); | |
6220 | fprintf (stream, _("\ | |
6221 | -X --extra-sym-info Display extra information when showing symbols\n")); | |
6222 | fprintf (stream, _("\ | |
6223 | --no-extra-sym-info Do not display extra information when showing symbols (default)\n")); | |
6224 | fprintf (stream, _("\ | |
6225 | -n --notes Display the contents of note sections (if present)\n")); | |
6226 | fprintf (stream, _("\ | |
6227 | -r --relocs Display the relocations (if present)\n")); | |
6228 | fprintf (stream, _("\ | |
6229 | -u --unwind Display the unwind info (if present)\n")); | |
6230 | fprintf (stream, _("\ | |
6231 | -d --dynamic Display the dynamic section (if present)\n")); | |
6232 | fprintf (stream, _("\ | |
6233 | -V --version-info Display the version sections (if present)\n")); | |
6234 | fprintf (stream, _("\ | |
6235 | -A --arch-specific Display architecture specific information (if any)\n")); | |
6236 | fprintf (stream, _("\ | |
6237 | -c --archive-index Display the symbol/file index in an archive\n")); | |
6238 | fprintf (stream, _("\ | |
6239 | -D --use-dynamic Use the dynamic section info when displaying symbols\n")); | |
6240 | fprintf (stream, _("\ | |
6241 | -L --lint|--enable-checks\n\ | |
6242 | Display warning messages for possible problems\n")); | |
6243 | fprintf (stream, _("\ | |
6244 | -x --hex-dump=<number|name>\n\ | |
6245 | Dump the contents of section <number|name> as bytes\n")); | |
6246 | fprintf (stream, _("\ | |
6247 | -p --string-dump=<number|name>\n\ | |
6248 | Dump the contents of section <number|name> as strings\n")); | |
6249 | fprintf (stream, _("\ | |
6250 | -R --relocated-dump=<number|name>\n\ | |
6251 | Dump the relocated contents of section <number|name>\n")); | |
6252 | fprintf (stream, _("\ | |
6253 | -z --decompress Decompress section before dumping it\n")); | |
6254 | fprintf (stream, _("\n\ | |
6255 | -j --display-section=<name|number>\n\ | |
6256 | Display the contents of the indicated section. Can be repeated\n")); | |
6257 | fprintf (stream, _("\ | |
6258 | -w --debug-dump[a/=abbrev, A/=addr, r/=aranges, c/=cu_index, L/=decodedline,\n\ | |
6259 | f/=frames, F/=frames-interp, g/=gdb_index, i/=info, o/=loc,\n\ | |
6260 | m/=macro, p/=pubnames, t/=pubtypes, R/=Ranges, l/=rawline,\n\ | |
6261 | s/=str, O/=str-offsets, u/=trace_abbrev, T/=trace_aranges,\n\ | |
6262 | U/=trace_info]\n\ | |
6263 | Display the contents of DWARF debug sections\n")); | |
6264 | fprintf (stream, _("\ | |
6265 | -wk --debug-dump=links Display the contents of sections that link to separate\n\ | |
6266 | debuginfo files\n")); | |
6267 | fprintf (stream, _("\ | |
6268 | -P --process-links Display the contents of non-debug sections in separate\n\ | |
6269 | debuginfo files. (Implies -wK)\n")); | |
6270 | #if DEFAULT_FOR_FOLLOW_LINKS | |
6271 | fprintf (stream, _("\ | |
6272 | -wK --debug-dump=follow-links\n\ | |
6273 | Follow links to separate debug info files (default)\n")); | |
6274 | fprintf (stream, _("\ | |
6275 | -wN --debug-dump=no-follow-links\n\ | |
6276 | Do not follow links to separate debug info files\n")); | |
6277 | #else | |
6278 | fprintf (stream, _("\ | |
6279 | -wK --debug-dump=follow-links\n\ | |
6280 | Follow links to separate debug info files\n")); | |
6281 | fprintf (stream, _("\ | |
6282 | -wN --debug-dump=no-follow-links\n\ | |
6283 | Do not follow links to separate debug info files\n\ | |
6284 | (default)\n")); | |
6285 | #endif | |
6286 | #if HAVE_LIBDEBUGINFOD | |
6287 | fprintf (stream, _("\ | |
6288 | -wD --debug-dump=use-debuginfod\n\ | |
6289 | When following links, also query debuginfod servers (default)\n")); | |
6290 | fprintf (stream, _("\ | |
6291 | -wE --debug-dump=do-not-use-debuginfod\n\ | |
6292 | When following links, do not query debuginfod servers\n")); | |
6293 | #endif | |
6294 | fprintf (stream, _("\ | |
6295 | --dwarf-depth=N Do not display DIEs at depth N or greater\n")); | |
6296 | fprintf (stream, _("\ | |
6297 | --dwarf-start=N Display DIEs starting at offset N\n")); | |
6298 | #ifdef ENABLE_LIBCTF | |
6299 | fprintf (stream, _("\ | |
6300 | --ctf=<number|name> Display CTF info from section <number|name>\n")); | |
6301 | fprintf (stream, _("\ | |
6302 | --ctf-parent=<name> Use CTF archive member <name> as the CTF parent\n")); | |
6303 | fprintf (stream, _("\ | |
6304 | --ctf-symbols=<number|name>\n\ | |
6305 | Use section <number|name> as the CTF external symtab\n")); | |
6306 | fprintf (stream, _("\ | |
6307 | --ctf-strings=<number|name>\n\ | |
6308 | Use section <number|name> as the CTF external strtab\n")); | |
6309 | #endif | |
6310 | fprintf (stream, _("\ | |
6311 | --sframe[=NAME] Display SFrame info from section NAME, (default '.sframe')\n")); | |
6312 | ||
6313 | #ifdef SUPPORT_DISASSEMBLY | |
6314 | fprintf (stream, _("\ | |
6315 | -i --instruction-dump=<number|name>\n\ | |
6316 | Disassemble the contents of section <number|name>\n")); | |
6317 | #endif | |
6318 | fprintf (stream, _("\ | |
6319 | -I --histogram Display histogram of bucket list lengths\n")); | |
6320 | fprintf (stream, _("\ | |
6321 | -W --wide Allow output width to exceed 80 characters\n")); | |
6322 | fprintf (stream, _("\ | |
6323 | -T --silent-truncation If a symbol name is truncated, do not add [...] suffix\n")); | |
6324 | fprintf (stream, _("\ | |
6325 | @<file> Read options from <file>\n")); | |
6326 | fprintf (stream, _("\ | |
6327 | -H --help Display this information\n")); | |
6328 | fprintf (stream, _("\ | |
6329 | -v --version Display the version number of readelf\n")); | |
6330 | ||
6331 | if (REPORT_BUGS_TO[0] && stream == stdout) | |
6332 | fprintf (stdout, _("Report bugs to %s\n"), REPORT_BUGS_TO); | |
6333 | ||
6334 | exit (stream == stdout ? 0 : 1); | |
6335 | } | |
6336 | ||
6337 | /* Record the fact that the user wants the contents of section number | |
6338 | SECTION to be displayed using the method(s) encoded as flags bits | |
6339 | in TYPE. Note, TYPE can be zero if we are creating the array for | |
6340 | the first time. */ | |
6341 | ||
6342 | static void | |
6343 | request_dump_bynumber (struct dump_data *dumpdata, | |
6344 | unsigned int section, dump_type type) | |
6345 | { | |
6346 | if (section >= dumpdata->num_dump_sects) | |
6347 | { | |
6348 | dump_type * new_dump_sects; | |
6349 | ||
6350 | new_dump_sects = (dump_type *) calloc (section + 1, | |
6351 | sizeof (* new_dump_sects)); | |
6352 | ||
6353 | if (new_dump_sects == NULL) | |
6354 | error (_("Out of memory allocating dump request table.\n")); | |
6355 | else | |
6356 | { | |
6357 | if (dumpdata->dump_sects) | |
6358 | { | |
6359 | /* Copy current flag settings. */ | |
6360 | memcpy (new_dump_sects, dumpdata->dump_sects, | |
6361 | dumpdata->num_dump_sects * sizeof (* new_dump_sects)); | |
6362 | ||
6363 | free (dumpdata->dump_sects); | |
6364 | } | |
6365 | ||
6366 | dumpdata->dump_sects = new_dump_sects; | |
6367 | dumpdata->num_dump_sects = section + 1; | |
6368 | } | |
6369 | } | |
6370 | ||
6371 | if (dumpdata->dump_sects) | |
6372 | dumpdata->dump_sects[section] |= type; | |
6373 | } | |
6374 | ||
6375 | /* Request a dump by section name. */ | |
6376 | ||
6377 | static void | |
6378 | request_dump_byname (const char * section, dump_type type) | |
6379 | { | |
6380 | struct dump_list_entry * new_request; | |
6381 | ||
6382 | new_request = (struct dump_list_entry *) | |
6383 | malloc (sizeof (struct dump_list_entry)); | |
6384 | if (!new_request) | |
6385 | error (_("Out of memory allocating dump request table.\n")); | |
6386 | ||
6387 | new_request->name = strdup (section); | |
6388 | if (!new_request->name) | |
6389 | error (_("Out of memory allocating dump request table.\n")); | |
6390 | ||
6391 | new_request->type = type; | |
6392 | ||
6393 | new_request->next = dump_sects_byname; | |
6394 | dump_sects_byname = new_request; | |
6395 | } | |
6396 | ||
6397 | static inline void | |
6398 | request_dump (struct dump_data *dumpdata, dump_type type) | |
6399 | { | |
6400 | int section; | |
6401 | char * cp; | |
6402 | ||
6403 | do_dump = true; | |
6404 | section = strtoul (optarg, & cp, 0); | |
6405 | ||
6406 | if (! *cp && section >= 0) | |
6407 | request_dump_bynumber (dumpdata, section, type); | |
6408 | else | |
6409 | request_dump_byname (optarg, type); | |
6410 | } | |
6411 | ||
6412 | static void | |
6413 | parse_args (struct dump_data *dumpdata, int argc, char ** argv) | |
6414 | { | |
6415 | int c; | |
6416 | ||
6417 | if (argc < 2) | |
6418 | usage (stderr); | |
6419 | ||
6420 | while ((c = getopt_long | |
6421 | (argc, argv, "ACDHILNPR:STU:VWXacdeghi:j:lnp:rstuvw::x:z", options, NULL)) != EOF) | |
6422 | { | |
6423 | switch (c) | |
6424 | { | |
6425 | case 0: | |
6426 | /* Long options. */ | |
6427 | break; | |
6428 | case 'H': | |
6429 | usage (stdout); | |
6430 | break; | |
6431 | ||
6432 | case 'a': | |
6433 | do_syms = true; | |
6434 | do_reloc = true; | |
6435 | do_unwind = true; | |
6436 | do_dynamic = true; | |
6437 | do_header = true; | |
6438 | do_sections = true; | |
6439 | do_section_groups = true; | |
6440 | do_segments = true; | |
6441 | do_version = true; | |
6442 | do_histogram = true; | |
6443 | do_arch = true; | |
6444 | do_notes = true; | |
6445 | break; | |
6446 | ||
6447 | case 'g': | |
6448 | do_section_groups = true; | |
6449 | break; | |
6450 | case 't': | |
6451 | case 'N': | |
6452 | do_sections = true; | |
6453 | do_section_details = true; | |
6454 | break; | |
6455 | case 'e': | |
6456 | do_header = true; | |
6457 | do_sections = true; | |
6458 | do_segments = true; | |
6459 | break; | |
6460 | case 'A': | |
6461 | do_arch = true; | |
6462 | break; | |
6463 | case 'D': | |
6464 | do_using_dynamic = true; | |
6465 | break; | |
6466 | case 'r': | |
6467 | do_reloc = true; | |
6468 | break; | |
6469 | case 'u': | |
6470 | do_unwind = true; | |
6471 | break; | |
6472 | case 'h': | |
6473 | do_header = true; | |
6474 | break; | |
6475 | case 'l': | |
6476 | do_segments = true; | |
6477 | break; | |
6478 | case 's': | |
6479 | do_syms = true; | |
6480 | break; | |
6481 | case 'S': | |
6482 | do_sections = true; | |
6483 | break; | |
6484 | case 'd': | |
6485 | do_dynamic = true; | |
6486 | break; | |
6487 | case 'I': | |
6488 | do_histogram = true; | |
6489 | break; | |
6490 | case 'n': | |
6491 | do_notes = true; | |
6492 | break; | |
6493 | case 'c': | |
6494 | do_archive_index = true; | |
6495 | break; | |
6496 | case 'L': | |
6497 | do_checks = true; | |
6498 | break; | |
6499 | case 'P': | |
6500 | process_links = true; | |
6501 | do_follow_links = true; | |
6502 | dump_any_debugging = true; | |
6503 | break; | |
6504 | case 'j': | |
6505 | request_dump (dumpdata, AUTO_DUMP); | |
6506 | break; | |
6507 | case 'x': | |
6508 | request_dump (dumpdata, HEX_DUMP); | |
6509 | break; | |
6510 | case 'p': | |
6511 | request_dump (dumpdata, STRING_DUMP); | |
6512 | break; | |
6513 | case 'R': | |
6514 | request_dump (dumpdata, RELOC_DUMP); | |
6515 | break; | |
6516 | case 'z': | |
6517 | decompress_dumps = true; | |
6518 | break; | |
6519 | case 'w': | |
6520 | if (optarg == NULL) | |
6521 | { | |
6522 | do_debugging = true; | |
6523 | do_dump = true; | |
6524 | dump_any_debugging = true; | |
6525 | dwarf_select_sections_all (); | |
6526 | } | |
6527 | else | |
6528 | { | |
6529 | do_debugging = false; | |
6530 | if (dwarf_select_sections_by_letters (optarg)) | |
6531 | { | |
6532 | do_dump = true; | |
6533 | dump_any_debugging = true; | |
6534 | } | |
6535 | } | |
6536 | break; | |
6537 | case OPTION_DEBUG_DUMP: | |
6538 | if (optarg == NULL) | |
6539 | { | |
6540 | do_dump = true; | |
6541 | do_debugging = true; | |
6542 | dump_any_debugging = true; | |
6543 | dwarf_select_sections_all (); | |
6544 | } | |
6545 | else if (strcmp (optarg, "sframe-internal-only") == 0) | |
6546 | warn (_("Unrecognized debug option 'sframe-internal-only'\n")); | |
6547 | else | |
6548 | { | |
6549 | do_debugging = false; | |
6550 | if (dwarf_select_sections_by_names (optarg)) | |
6551 | { | |
6552 | do_dump = true; | |
6553 | dump_any_debugging = true; | |
6554 | } | |
6555 | } | |
6556 | break; | |
6557 | case OPTION_DWARF_DEPTH: | |
6558 | { | |
6559 | char *cp; | |
6560 | ||
6561 | dwarf_cutoff_level = strtoul (optarg, & cp, 0); | |
6562 | } | |
6563 | break; | |
6564 | case OPTION_DWARF_START: | |
6565 | { | |
6566 | char *cp; | |
6567 | ||
6568 | dwarf_start_die = strtoul (optarg, & cp, 0); | |
6569 | } | |
6570 | break; | |
6571 | case OPTION_DWARF_CHECK: | |
6572 | dwarf_check = true; | |
6573 | break; | |
6574 | case OPTION_CTF_DUMP: | |
6575 | do_ctf = true; | |
6576 | request_dump (dumpdata, CTF_DUMP); | |
6577 | break; | |
6578 | case OPTION_CTF_SYMBOLS: | |
6579 | free (dump_ctf_symtab_name); | |
6580 | dump_ctf_symtab_name = strdup (optarg); | |
6581 | break; | |
6582 | case OPTION_CTF_STRINGS: | |
6583 | free (dump_ctf_strtab_name); | |
6584 | dump_ctf_strtab_name = strdup (optarg); | |
6585 | break; | |
6586 | case OPTION_CTF_PARENT: | |
6587 | free (dump_ctf_parent_name); | |
6588 | dump_ctf_parent_name = strdup (optarg); | |
6589 | break; | |
6590 | case OPTION_SFRAME_DUMP: | |
6591 | do_sframe = true; | |
6592 | /* Fix PR/32589 but keep the error messaging same ? */ | |
6593 | if (optarg != NULL && strcmp (optarg, "") == 0) | |
6594 | { | |
6595 | do_dump = true; | |
6596 | error (_("Section name must be provided\n")); | |
6597 | } | |
6598 | /* Providing section name is optional. request_dump (), however, | |
6599 | thrives on non NULL optarg. Handle it explicitly here. */ | |
6600 | else if (optarg != NULL) | |
6601 | request_dump (dumpdata, SFRAME_DUMP); | |
6602 | else | |
6603 | { | |
6604 | do_dump = true; | |
6605 | const char *sframe_sec_name = strdup (".sframe"); | |
6606 | request_dump_byname (sframe_sec_name, SFRAME_DUMP); | |
6607 | } | |
6608 | break; | |
6609 | case OPTION_DYN_SYMS: | |
6610 | do_dyn_syms = true; | |
6611 | break; | |
6612 | case OPTION_LTO_SYMS: | |
6613 | do_lto_syms = true; | |
6614 | break; | |
6615 | case 'X': | |
6616 | extra_sym_info = true; | |
6617 | break; | |
6618 | case OPTION_NO_EXTRA_SYM_INFO: | |
6619 | extra_sym_info = false; | |
6620 | break; | |
6621 | ||
6622 | #ifdef SUPPORT_DISASSEMBLY | |
6623 | case 'i': | |
6624 | request_dump (dumpdata, DISASS_DUMP); | |
6625 | break; | |
6626 | #endif | |
6627 | case 'v': | |
6628 | print_version (program_name); | |
6629 | break; | |
6630 | case 'V': | |
6631 | do_version = true; | |
6632 | break; | |
6633 | case 'W': | |
6634 | do_wide = true; | |
6635 | break; | |
6636 | case 'T': | |
6637 | do_not_show_symbol_truncation = true; | |
6638 | break; | |
6639 | case 'C': | |
6640 | do_demangle = true; | |
6641 | if (optarg != NULL) | |
6642 | { | |
6643 | enum demangling_styles style; | |
6644 | ||
6645 | style = cplus_demangle_name_to_style (optarg); | |
6646 | if (style == unknown_demangling) | |
6647 | error (_("unknown demangling style `%s'"), optarg); | |
6648 | ||
6649 | cplus_demangle_set_style (style); | |
6650 | } | |
6651 | break; | |
6652 | case OPTION_NO_DEMANGLING: | |
6653 | do_demangle = false; | |
6654 | break; | |
6655 | case OPTION_RECURSE_LIMIT: | |
6656 | demangle_flags &= ~ DMGL_NO_RECURSE_LIMIT; | |
6657 | break; | |
6658 | case OPTION_NO_RECURSE_LIMIT: | |
6659 | demangle_flags |= DMGL_NO_RECURSE_LIMIT; | |
6660 | break; | |
6661 | case OPTION_WITH_SYMBOL_VERSIONS: | |
6662 | /* Ignored for backward compatibility. */ | |
6663 | break; | |
6664 | ||
6665 | case 'U': | |
6666 | if (optarg == NULL) | |
6667 | error (_("Missing arg to -U/--unicode")); /* Can this happen ? */ | |
6668 | else if (streq (optarg, "default") || streq (optarg, "d")) | |
6669 | unicode_display = unicode_default; | |
6670 | else if (streq (optarg, "locale") || streq (optarg, "l")) | |
6671 | unicode_display = unicode_locale; | |
6672 | else if (streq (optarg, "escape") || streq (optarg, "e")) | |
6673 | unicode_display = unicode_escape; | |
6674 | else if (streq (optarg, "invalid") || streq (optarg, "i")) | |
6675 | unicode_display = unicode_invalid; | |
6676 | else if (streq (optarg, "hex") || streq (optarg, "x")) | |
6677 | unicode_display = unicode_hex; | |
6678 | else if (streq (optarg, "highlight") || streq (optarg, "h")) | |
6679 | unicode_display = unicode_highlight; | |
6680 | else | |
6681 | error (_("invalid argument to -U/--unicode: %s"), optarg); | |
6682 | break; | |
6683 | ||
6684 | case OPTION_SYM_BASE: | |
6685 | sym_base = 0; | |
6686 | if (optarg != NULL) | |
6687 | { | |
6688 | sym_base = strtoul (optarg, NULL, 0); | |
6689 | switch (sym_base) | |
6690 | { | |
6691 | case 0: | |
6692 | case 8: | |
6693 | case 10: | |
6694 | case 16: | |
6695 | break; | |
6696 | ||
6697 | default: | |
6698 | sym_base = 0; | |
6699 | break; | |
6700 | } | |
6701 | } | |
6702 | break; | |
6703 | ||
6704 | default: | |
6705 | /* xgettext:c-format */ | |
6706 | error (_("Invalid option '-%c'\n"), c); | |
6707 | /* Fall through. */ | |
6708 | case '?': | |
6709 | usage (stderr); | |
6710 | } | |
6711 | } | |
6712 | ||
6713 | if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections | |
6714 | && !do_segments && !do_header && !do_dump && !do_version | |
6715 | && !do_histogram && !do_debugging && !do_arch && !do_notes | |
6716 | && !do_section_groups && !do_archive_index | |
6717 | && !do_dyn_syms && !do_lto_syms) | |
6718 | { | |
6719 | if (do_checks) | |
6720 | { | |
6721 | check_all = true; | |
6722 | do_dynamic = do_syms = do_reloc = do_unwind = do_sections = true; | |
6723 | do_segments = do_header = do_dump = do_version = true; | |
6724 | do_histogram = do_debugging = do_arch = do_notes = true; | |
6725 | do_section_groups = do_archive_index = do_dyn_syms = true; | |
6726 | do_lto_syms = true; | |
6727 | } | |
6728 | else | |
6729 | usage (stderr); | |
6730 | } | |
6731 | } | |
6732 | ||
6733 | static const char * | |
6734 | get_elf_class (unsigned int elf_class) | |
6735 | { | |
6736 | static char buff[32]; | |
6737 | ||
6738 | switch (elf_class) | |
6739 | { | |
6740 | case ELFCLASSNONE: return _("none"); | |
6741 | case ELFCLASS32: return "ELF32"; | |
6742 | case ELFCLASS64: return "ELF64"; | |
6743 | default: | |
6744 | snprintf (buff, sizeof (buff), _("<unknown: %x>"), elf_class); | |
6745 | return buff; | |
6746 | } | |
6747 | } | |
6748 | ||
6749 | static const char * | |
6750 | get_data_encoding (unsigned int encoding) | |
6751 | { | |
6752 | static char buff[32]; | |
6753 | ||
6754 | switch (encoding) | |
6755 | { | |
6756 | case ELFDATANONE: return _("none"); | |
6757 | case ELFDATA2LSB: return _("2's complement, little endian"); | |
6758 | case ELFDATA2MSB: return _("2's complement, big endian"); | |
6759 | default: | |
6760 | snprintf (buff, sizeof (buff), _("<unknown: %x>"), encoding); | |
6761 | return buff; | |
6762 | } | |
6763 | } | |
6764 | ||
6765 | static bool | |
6766 | check_magic_number (Filedata * filedata, Elf_Internal_Ehdr * header) | |
6767 | { | |
6768 | if (header->e_ident[EI_MAG0] == ELFMAG0 | |
6769 | && header->e_ident[EI_MAG1] == ELFMAG1 | |
6770 | && header->e_ident[EI_MAG2] == ELFMAG2 | |
6771 | && header->e_ident[EI_MAG3] == ELFMAG3) | |
6772 | return true; | |
6773 | ||
6774 | /* Some compilers produce object files that are not in the ELF file format. | |
6775 | As an aid to users of readelf, try to identify these cases and suggest | |
6776 | alternative tools. | |
6777 | ||
6778 | FIXME: It is not clear if all four bytes are used as constant magic | |
6779 | valus by all compilers. It may be necessary to recode this function if | |
6780 | different tools use different length sequences. */ | |
6781 | ||
6782 | static struct | |
6783 | { | |
6784 | unsigned char magic[4]; | |
6785 | const char * obj_message; | |
6786 | const char * ar_message; | |
6787 | } | |
6788 | known_magic[] = | |
6789 | { | |
6790 | { { 'B', 'C', 0xc0, 0xde }, | |
6791 | N_("This is a LLVM bitcode file - try using llvm-bcanalyzer\n"), | |
6792 | N_("This is a LLVM bitcode file - try extracting and then using llvm-bcanalyzer\n") | |
6793 | }, | |
6794 | { { 'g', 'o', ' ', 'o' }, | |
6795 | N_("This is a GO binary file - try using 'go tool objdump' or 'go tool nm'\n"), | |
6796 | NULL | |
6797 | } | |
6798 | }; | |
6799 | int i; | |
6800 | ||
6801 | for (i = ARRAY_SIZE (known_magic); i--;) | |
6802 | { | |
6803 | if (header->e_ident[EI_MAG0] == known_magic[i].magic[0] | |
6804 | && header->e_ident[EI_MAG1] == known_magic[i].magic[1] | |
6805 | && header->e_ident[EI_MAG2] == known_magic[i].magic[2] | |
6806 | && header->e_ident[EI_MAG3] == known_magic[i].magic[3]) | |
6807 | { | |
6808 | /* Some compiler's analyzer tools do not handle archives, | |
6809 | so we provide two different kinds of error message. */ | |
6810 | if (filedata->archive_file_size > 0 | |
6811 | && known_magic[i].ar_message != NULL) | |
6812 | error ("%s", known_magic[i].ar_message); | |
6813 | else | |
6814 | error ("%s", known_magic[i].obj_message); | |
6815 | return false; | |
6816 | } | |
6817 | } | |
6818 | ||
6819 | error (_("Not an ELF file - it has the wrong magic bytes at the start\n")); | |
6820 | return false; | |
6821 | } | |
6822 | ||
6823 | /* Decode the data held in 'filedata->file_header'. */ | |
6824 | ||
6825 | static bool | |
6826 | process_file_header (Filedata * filedata) | |
6827 | { | |
6828 | Elf_Internal_Ehdr * header = & filedata->file_header; | |
6829 | ||
6830 | if (! check_magic_number (filedata, header)) | |
6831 | return false; | |
6832 | ||
6833 | if (! filedata->is_separate) | |
6834 | init_dwarf_by_elf_machine_code (header->e_machine); | |
6835 | ||
6836 | if (do_header) | |
6837 | { | |
6838 | unsigned i; | |
6839 | ||
6840 | if (filedata->is_separate) | |
6841 | printf (_("ELF Header in linked file '%s':\n"), | |
6842 | printable_string (filedata->file_name, 0)); | |
6843 | else | |
6844 | printf (_("ELF Header:\n")); | |
6845 | printf (_(" Magic: ")); | |
6846 | for (i = 0; i < EI_NIDENT; i++) | |
6847 | printf ("%2.2x ", header->e_ident[i]); | |
6848 | printf ("\n"); | |
6849 | printf (_(" Class: %s\n"), | |
6850 | get_elf_class (header->e_ident[EI_CLASS])); | |
6851 | printf (_(" Data: %s\n"), | |
6852 | get_data_encoding (header->e_ident[EI_DATA])); | |
6853 | printf (_(" Version: %d%s\n"), | |
6854 | header->e_ident[EI_VERSION], | |
6855 | (header->e_ident[EI_VERSION] == EV_CURRENT | |
6856 | ? _(" (current)") | |
6857 | : (header->e_ident[EI_VERSION] != EV_NONE | |
6858 | ? _(" <unknown>") | |
6859 | : ""))); | |
6860 | printf (_(" OS/ABI: %s\n"), | |
6861 | get_osabi_name (filedata, header->e_ident[EI_OSABI])); | |
6862 | printf (_(" ABI Version: %d\n"), | |
6863 | header->e_ident[EI_ABIVERSION]); | |
6864 | printf (_(" Type: %s\n"), | |
6865 | get_file_type (filedata)); | |
6866 | printf (_(" Machine: %s\n"), | |
6867 | get_machine_name (header->e_machine)); | |
6868 | printf (_(" Version: 0x%lx\n"), | |
6869 | header->e_version); | |
6870 | ||
6871 | printf (_(" Entry point address: ")); | |
6872 | print_vma (header->e_entry, PREFIX_HEX); | |
6873 | printf (_("\n Start of program headers: ")); | |
6874 | print_vma (header->e_phoff, DEC); | |
6875 | printf (_(" (bytes into file)\n Start of section headers: ")); | |
6876 | print_vma (header->e_shoff, DEC); | |
6877 | printf (_(" (bytes into file)\n")); | |
6878 | ||
6879 | printf (_(" Flags: 0x%lx%s\n"), | |
6880 | header->e_flags, | |
6881 | get_machine_flags (filedata, header->e_flags, header->e_machine)); | |
6882 | printf (_(" Size of this header: %u (bytes)\n"), | |
6883 | header->e_ehsize); | |
6884 | printf (_(" Size of program headers: %u (bytes)\n"), | |
6885 | header->e_phentsize); | |
6886 | printf (_(" Number of program headers: %u"), | |
6887 | header->e_phnum); | |
6888 | if (filedata->section_headers != NULL | |
6889 | && header->e_phnum == PN_XNUM | |
6890 | && filedata->section_headers[0].sh_info != 0) | |
6891 | printf (" (%u)", filedata->section_headers[0].sh_info); | |
6892 | putc ('\n', stdout); | |
6893 | printf (_(" Size of section headers: %u (bytes)\n"), | |
6894 | header->e_shentsize); | |
6895 | printf (_(" Number of section headers: %u"), | |
6896 | header->e_shnum); | |
6897 | if (filedata->section_headers != NULL && header->e_shnum == SHN_UNDEF) | |
6898 | { | |
6899 | header->e_shnum = filedata->section_headers[0].sh_size; | |
6900 | printf (" (%u)", header->e_shnum); | |
6901 | } | |
6902 | putc ('\n', stdout); | |
6903 | printf (_(" Section header string table index: %u"), | |
6904 | header->e_shstrndx); | |
6905 | if (filedata->section_headers != NULL | |
6906 | && header->e_shstrndx == (SHN_XINDEX & 0xffff)) | |
6907 | { | |
6908 | header->e_shstrndx = filedata->section_headers[0].sh_link; | |
6909 | printf (" (%u)", header->e_shstrndx); | |
6910 | } | |
6911 | if (header->e_shstrndx != SHN_UNDEF | |
6912 | && header->e_shstrndx >= header->e_shnum) | |
6913 | { | |
6914 | header->e_shstrndx = SHN_UNDEF; | |
6915 | printf (_(" <corrupt: out of range>")); | |
6916 | } | |
6917 | putc ('\n', stdout); | |
6918 | } | |
6919 | ||
6920 | if (filedata->section_headers != NULL) | |
6921 | { | |
6922 | if (header->e_phnum == PN_XNUM | |
6923 | && filedata->section_headers[0].sh_info != 0) | |
6924 | { | |
6925 | /* Throw away any cached read of PN_XNUM headers. */ | |
6926 | free (filedata->program_headers); | |
6927 | filedata->program_headers = NULL; | |
6928 | header->e_phnum = filedata->section_headers[0].sh_info; | |
6929 | } | |
6930 | if (header->e_shnum == SHN_UNDEF) | |
6931 | header->e_shnum = filedata->section_headers[0].sh_size; | |
6932 | if (header->e_shstrndx == (SHN_XINDEX & 0xffff)) | |
6933 | header->e_shstrndx = filedata->section_headers[0].sh_link; | |
6934 | if (header->e_shstrndx >= header->e_shnum) | |
6935 | header->e_shstrndx = SHN_UNDEF; | |
6936 | } | |
6937 | ||
6938 | return true; | |
6939 | } | |
6940 | ||
6941 | /* Read in the program headers from FILEDATA and store them in PHEADERS. | |
6942 | Returns TRUE upon success, FALSE otherwise. Loads 32-bit headers. */ | |
6943 | ||
6944 | static bool | |
6945 | get_32bit_program_headers (Filedata * filedata, Elf_Internal_Phdr * pheaders) | |
6946 | { | |
6947 | Elf32_External_Phdr * phdrs; | |
6948 | Elf32_External_Phdr * external; | |
6949 | Elf_Internal_Phdr * internal; | |
6950 | unsigned int i; | |
6951 | unsigned int size = filedata->file_header.e_phentsize; | |
6952 | unsigned int num = filedata->file_header.e_phnum; | |
6953 | ||
6954 | /* PR binutils/17531: Cope with unexpected section header sizes. */ | |
6955 | if (size == 0 || num == 0) | |
6956 | return false; | |
6957 | if (size < sizeof * phdrs) | |
6958 | { | |
6959 | error (_("The e_phentsize field in the ELF header is less than the size of an ELF program header\n")); | |
6960 | return false; | |
6961 | } | |
6962 | if (size > sizeof * phdrs) | |
6963 | warn (_("The e_phentsize field in the ELF header is larger than the size of an ELF program header\n")); | |
6964 | ||
6965 | phdrs = (Elf32_External_Phdr *) get_data (NULL, filedata, filedata->file_header.e_phoff, | |
6966 | size, num, _("program headers")); | |
6967 | if (phdrs == NULL) | |
6968 | return false; | |
6969 | ||
6970 | for (i = 0, internal = pheaders, external = phdrs; | |
6971 | i < filedata->file_header.e_phnum; | |
6972 | i++, internal++, external++) | |
6973 | { | |
6974 | internal->p_type = BYTE_GET (external->p_type); | |
6975 | internal->p_offset = BYTE_GET (external->p_offset); | |
6976 | internal->p_vaddr = BYTE_GET (external->p_vaddr); | |
6977 | internal->p_paddr = BYTE_GET (external->p_paddr); | |
6978 | internal->p_filesz = BYTE_GET (external->p_filesz); | |
6979 | internal->p_memsz = BYTE_GET (external->p_memsz); | |
6980 | internal->p_flags = BYTE_GET (external->p_flags); | |
6981 | internal->p_align = BYTE_GET (external->p_align); | |
6982 | } | |
6983 | ||
6984 | free (phdrs); | |
6985 | return true; | |
6986 | } | |
6987 | ||
6988 | /* Read in the program headers from FILEDATA and store them in PHEADERS. | |
6989 | Returns TRUE upon success, FALSE otherwise. Loads 64-bit headers. */ | |
6990 | ||
6991 | static bool | |
6992 | get_64bit_program_headers (Filedata * filedata, Elf_Internal_Phdr * pheaders) | |
6993 | { | |
6994 | Elf64_External_Phdr * phdrs; | |
6995 | Elf64_External_Phdr * external; | |
6996 | Elf_Internal_Phdr * internal; | |
6997 | unsigned int i; | |
6998 | unsigned int size = filedata->file_header.e_phentsize; | |
6999 | unsigned int num = filedata->file_header.e_phnum; | |
7000 | ||
7001 | /* PR binutils/17531: Cope with unexpected section header sizes. */ | |
7002 | if (size == 0 || num == 0) | |
7003 | return false; | |
7004 | if (size < sizeof * phdrs) | |
7005 | { | |
7006 | error (_("The e_phentsize field in the ELF header is less than the size of an ELF program header\n")); | |
7007 | return false; | |
7008 | } | |
7009 | if (size > sizeof * phdrs) | |
7010 | warn (_("The e_phentsize field in the ELF header is larger than the size of an ELF program header\n")); | |
7011 | ||
7012 | phdrs = (Elf64_External_Phdr *) get_data (NULL, filedata, filedata->file_header.e_phoff, | |
7013 | size, num, _("program headers")); | |
7014 | if (!phdrs) | |
7015 | return false; | |
7016 | ||
7017 | for (i = 0, internal = pheaders, external = phdrs; | |
7018 | i < filedata->file_header.e_phnum; | |
7019 | i++, internal++, external++) | |
7020 | { | |
7021 | internal->p_type = BYTE_GET (external->p_type); | |
7022 | internal->p_flags = BYTE_GET (external->p_flags); | |
7023 | internal->p_offset = BYTE_GET (external->p_offset); | |
7024 | internal->p_vaddr = BYTE_GET (external->p_vaddr); | |
7025 | internal->p_paddr = BYTE_GET (external->p_paddr); | |
7026 | internal->p_filesz = BYTE_GET (external->p_filesz); | |
7027 | internal->p_memsz = BYTE_GET (external->p_memsz); | |
7028 | internal->p_align = BYTE_GET (external->p_align); | |
7029 | } | |
7030 | ||
7031 | free (phdrs); | |
7032 | return true; | |
7033 | } | |
7034 | ||
7035 | /* Returns TRUE if the program headers were read into `program_headers'. */ | |
7036 | ||
7037 | static bool | |
7038 | get_program_headers (Filedata * filedata) | |
7039 | { | |
7040 | Elf_Internal_Phdr * phdrs; | |
7041 | ||
7042 | /* Check cache of prior read. */ | |
7043 | if (filedata->program_headers != NULL) | |
7044 | return true; | |
7045 | ||
7046 | /* Be kind to memory checkers by looking for | |
7047 | e_phnum values which we know must be invalid. */ | |
7048 | if (filedata->file_header.e_phnum | |
7049 | * (is_32bit_elf ? sizeof (Elf32_External_Phdr) : sizeof (Elf64_External_Phdr)) | |
7050 | >= filedata->file_size) | |
7051 | { | |
7052 | error (_("Too many program headers - %#x - the file is not that big\n"), | |
7053 | filedata->file_header.e_phnum); | |
7054 | return false; | |
7055 | } | |
7056 | ||
7057 | phdrs = (Elf_Internal_Phdr *) cmalloc (filedata->file_header.e_phnum, | |
7058 | sizeof (Elf_Internal_Phdr)); | |
7059 | if (phdrs == NULL) | |
7060 | { | |
7061 | error (_("Out of memory reading %u program headers\n"), | |
7062 | filedata->file_header.e_phnum); | |
7063 | return false; | |
7064 | } | |
7065 | ||
7066 | if (is_32bit_elf | |
7067 | ? get_32bit_program_headers (filedata, phdrs) | |
7068 | : get_64bit_program_headers (filedata, phdrs)) | |
7069 | { | |
7070 | filedata->program_headers = phdrs; | |
7071 | return true; | |
7072 | } | |
7073 | ||
7074 | free (phdrs); | |
7075 | return false; | |
7076 | } | |
7077 | ||
7078 | /* Print program header info and locate dynamic section. */ | |
7079 | ||
7080 | static void | |
7081 | process_program_headers (Filedata * filedata) | |
7082 | { | |
7083 | Elf_Internal_Phdr * segment; | |
7084 | unsigned int i; | |
7085 | Elf_Internal_Phdr * previous_load = NULL; | |
7086 | ||
7087 | if (filedata->file_header.e_phnum == 0) | |
7088 | { | |
7089 | /* PR binutils/12467. */ | |
7090 | if (filedata->file_header.e_phoff != 0) | |
7091 | warn (_("possibly corrupt ELF header - it has a non-zero program" | |
7092 | " header offset, but no program headers\n")); | |
7093 | else if (do_segments) | |
7094 | { | |
7095 | if (filedata->is_separate) | |
7096 | printf (_("\nThere are no program headers in linked file '%s'.\n"), | |
7097 | printable_string (filedata->file_name, 0)); | |
7098 | else | |
7099 | printf (_("\nThere are no program headers in this file.\n")); | |
7100 | } | |
7101 | goto no_headers; | |
7102 | } | |
7103 | ||
7104 | if (do_segments && !do_header) | |
7105 | { | |
7106 | if (filedata->is_separate) | |
7107 | printf ("\nIn linked file '%s' the ELF file type is %s\n", | |
7108 | printable_string (filedata->file_name, 0), | |
7109 | get_file_type (filedata)); | |
7110 | else | |
7111 | printf (_("\nElf file type is %s\n"), get_file_type (filedata)); | |
7112 | printf (_("Entry point 0x%" PRIx64 "\n"), | |
7113 | filedata->file_header.e_entry); | |
7114 | printf (ngettext ("There is %d program header," | |
7115 | " starting at offset %" PRIu64 "\n", | |
7116 | "There are %d program headers," | |
7117 | " starting at offset %" PRIu64 "\n", | |
7118 | filedata->file_header.e_phnum), | |
7119 | filedata->file_header.e_phnum, | |
7120 | filedata->file_header.e_phoff); | |
7121 | } | |
7122 | ||
7123 | if (! get_program_headers (filedata)) | |
7124 | goto no_headers; | |
7125 | ||
7126 | if (do_segments) | |
7127 | { | |
7128 | if (filedata->file_header.e_phnum > 1) | |
7129 | printf (_("\nProgram Headers:\n")); | |
7130 | else | |
7131 | printf (_("\nProgram Headers:\n")); | |
7132 | ||
7133 | if (is_32bit_elf) | |
7134 | printf | |
7135 | (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n")); | |
7136 | else if (do_wide) | |
7137 | printf | |
7138 | (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n")); | |
7139 | else | |
7140 | { | |
7141 | printf | |
7142 | (_(" Type Offset VirtAddr PhysAddr\n")); | |
7143 | printf | |
7144 | (_(" FileSiz MemSiz Flags Align\n")); | |
7145 | } | |
7146 | } | |
7147 | ||
7148 | uint64_t dynamic_addr = 0; | |
7149 | uint64_t dynamic_size = 0; | |
7150 | for (i = 0, segment = filedata->program_headers; | |
7151 | i < filedata->file_header.e_phnum; | |
7152 | i++, segment++) | |
7153 | { | |
7154 | if (do_segments) | |
7155 | { | |
7156 | printf (" %-14.14s ", get_segment_type (filedata, segment->p_type)); | |
7157 | ||
7158 | if (is_32bit_elf) | |
7159 | { | |
7160 | printf ("0x%6.6lx ", (unsigned long) segment->p_offset); | |
7161 | printf ("0x%8.8lx ", (unsigned long) segment->p_vaddr); | |
7162 | printf ("0x%8.8lx ", (unsigned long) segment->p_paddr); | |
7163 | printf ("0x%5.5lx ", (unsigned long) segment->p_filesz); | |
7164 | printf ("0x%5.5lx ", (unsigned long) segment->p_memsz); | |
7165 | printf ("%c%c%c ", | |
7166 | (segment->p_flags & PF_R ? 'R' : ' '), | |
7167 | (segment->p_flags & PF_W ? 'W' : ' '), | |
7168 | (segment->p_flags & PF_X ? 'E' : ' ')); | |
7169 | printf ("%#lx", (unsigned long) segment->p_align); | |
7170 | } | |
7171 | else if (do_wide) | |
7172 | { | |
7173 | if ((unsigned long) segment->p_offset == segment->p_offset) | |
7174 | printf ("0x%6.6lx ", (unsigned long) segment->p_offset); | |
7175 | else | |
7176 | { | |
7177 | print_vma (segment->p_offset, FULL_HEX); | |
7178 | putchar (' '); | |
7179 | } | |
7180 | ||
7181 | print_vma (segment->p_vaddr, FULL_HEX); | |
7182 | putchar (' '); | |
7183 | print_vma (segment->p_paddr, FULL_HEX); | |
7184 | putchar (' '); | |
7185 | ||
7186 | if ((unsigned long) segment->p_filesz == segment->p_filesz) | |
7187 | printf ("0x%6.6lx ", (unsigned long) segment->p_filesz); | |
7188 | else | |
7189 | { | |
7190 | print_vma (segment->p_filesz, FULL_HEX); | |
7191 | putchar (' '); | |
7192 | } | |
7193 | ||
7194 | if ((unsigned long) segment->p_memsz == segment->p_memsz) | |
7195 | printf ("0x%6.6lx", (unsigned long) segment->p_memsz); | |
7196 | else | |
7197 | { | |
7198 | print_vma (segment->p_memsz, FULL_HEX); | |
7199 | } | |
7200 | ||
7201 | printf (" %c%c%c ", | |
7202 | (segment->p_flags & PF_R ? 'R' : ' '), | |
7203 | (segment->p_flags & PF_W ? 'W' : ' '), | |
7204 | (segment->p_flags & PF_X ? 'E' : ' ')); | |
7205 | ||
7206 | if ((unsigned long) segment->p_align == segment->p_align) | |
7207 | printf ("%#lx", (unsigned long) segment->p_align); | |
7208 | else | |
7209 | { | |
7210 | print_vma (segment->p_align, PREFIX_HEX); | |
7211 | } | |
7212 | } | |
7213 | else | |
7214 | { | |
7215 | print_vma (segment->p_offset, FULL_HEX); | |
7216 | putchar (' '); | |
7217 | print_vma (segment->p_vaddr, FULL_HEX); | |
7218 | putchar (' '); | |
7219 | print_vma (segment->p_paddr, FULL_HEX); | |
7220 | printf ("\n "); | |
7221 | print_vma (segment->p_filesz, FULL_HEX); | |
7222 | putchar (' '); | |
7223 | print_vma (segment->p_memsz, FULL_HEX); | |
7224 | printf (" %c%c%c ", | |
7225 | (segment->p_flags & PF_R ? 'R' : ' '), | |
7226 | (segment->p_flags & PF_W ? 'W' : ' '), | |
7227 | (segment->p_flags & PF_X ? 'E' : ' ')); | |
7228 | print_vma (segment->p_align, PREFIX_HEX); | |
7229 | } | |
7230 | ||
7231 | putc ('\n', stdout); | |
7232 | } | |
7233 | ||
7234 | switch (segment->p_type) | |
7235 | { | |
7236 | case PT_LOAD: | |
7237 | #if 0 /* Do not warn about out of order PT_LOAD segments. Although officially | |
7238 | required by the ELF standard, several programs, including the Linux | |
7239 | kernel, make use of non-ordered segments. */ | |
7240 | if (previous_load | |
7241 | && previous_load->p_vaddr > segment->p_vaddr) | |
7242 | error (_("LOAD segments must be sorted in order of increasing VirtAddr\n")); | |
7243 | #endif | |
7244 | if (segment->p_memsz < segment->p_filesz) | |
7245 | error (_("the segment's file size is larger than its memory size\n")); | |
7246 | previous_load = segment; | |
7247 | break; | |
7248 | ||
7249 | case PT_PHDR: | |
7250 | /* PR 20815 - Verify that the program header is loaded into memory. */ | |
7251 | if (i > 0 && previous_load != NULL) | |
7252 | error (_("the PHDR segment must occur before any LOAD segment\n")); | |
7253 | if (filedata->file_header.e_machine != EM_PARISC) | |
7254 | { | |
7255 | unsigned int j; | |
7256 | ||
7257 | for (j = 1; j < filedata->file_header.e_phnum; j++) | |
7258 | { | |
7259 | Elf_Internal_Phdr *load = filedata->program_headers + j; | |
7260 | if (load->p_type == PT_LOAD | |
7261 | && load->p_offset <= segment->p_offset | |
7262 | && (load->p_offset + load->p_filesz | |
7263 | >= segment->p_offset + segment->p_filesz) | |
7264 | && load->p_vaddr <= segment->p_vaddr | |
7265 | && (load->p_vaddr + load->p_filesz | |
7266 | >= segment->p_vaddr + segment->p_filesz)) | |
7267 | break; | |
7268 | } | |
7269 | if (j == filedata->file_header.e_phnum) | |
7270 | error (_("the PHDR segment is not covered by a LOAD segment\n")); | |
7271 | } | |
7272 | break; | |
7273 | ||
7274 | case PT_DYNAMIC: | |
7275 | if (dynamic_addr) | |
7276 | error (_("more than one dynamic segment\n")); | |
7277 | ||
7278 | /* By default, assume that the .dynamic section is the first | |
7279 | section in the DYNAMIC segment. */ | |
7280 | dynamic_addr = segment->p_offset; | |
7281 | dynamic_size = segment->p_filesz; | |
7282 | ||
7283 | /* Try to locate the .dynamic section. If there is | |
7284 | a section header table, we can easily locate it. */ | |
7285 | if (filedata->section_headers != NULL) | |
7286 | { | |
7287 | Elf_Internal_Shdr * sec; | |
7288 | ||
7289 | sec = find_section (filedata, ".dynamic"); | |
7290 | if (sec == NULL || sec->sh_size == 0) | |
7291 | { | |
7292 | /* A corresponding .dynamic section is expected, but on | |
7293 | IA-64/OpenVMS it is OK for it to be missing. */ | |
7294 | if (!is_ia64_vms (filedata)) | |
7295 | error (_("no .dynamic section in the dynamic segment\n")); | |
7296 | break; | |
7297 | } | |
7298 | ||
7299 | if (sec->sh_type == SHT_NOBITS) | |
7300 | { | |
7301 | dynamic_addr = 0; | |
7302 | dynamic_size = 0; | |
7303 | break; | |
7304 | } | |
7305 | ||
7306 | dynamic_addr = sec->sh_offset; | |
7307 | dynamic_size = sec->sh_size; | |
7308 | ||
7309 | /* The PT_DYNAMIC segment, which is used by the run-time | |
7310 | loader, should exactly match the .dynamic section. */ | |
7311 | if (do_checks | |
7312 | && (dynamic_addr != segment->p_offset | |
7313 | || dynamic_size != segment->p_filesz)) | |
7314 | warn (_("\ | |
7315 | the .dynamic section is not the same as the dynamic segment\n")); | |
7316 | } | |
7317 | ||
7318 | /* PR binutils/17512: Avoid corrupt dynamic section info in the | |
7319 | segment. Check this after matching against the section headers | |
7320 | so we don't warn on debuginfo file (which have NOBITS .dynamic | |
7321 | sections). */ | |
7322 | if (dynamic_addr > filedata->file_size | |
7323 | || (dynamic_size > filedata->file_size - dynamic_addr)) | |
7324 | { | |
7325 | error (_("the dynamic segment offset + size exceeds the size of the file\n")); | |
7326 | dynamic_addr = 0; | |
7327 | dynamic_size = 0; | |
7328 | } | |
7329 | break; | |
7330 | ||
7331 | case PT_INTERP: | |
7332 | if (segment->p_offset >= filedata->file_size | |
7333 | || segment->p_filesz > filedata->file_size - segment->p_offset | |
7334 | || segment->p_filesz - 1 >= (size_t) -2 | |
7335 | || fseek64 (filedata->handle, | |
7336 | filedata->archive_file_offset + segment->p_offset, | |
7337 | SEEK_SET)) | |
7338 | error (_("Unable to find program interpreter name\n")); | |
7339 | else | |
7340 | { | |
7341 | size_t len = segment->p_filesz; | |
7342 | free (filedata->program_interpreter); | |
7343 | filedata->program_interpreter = xmalloc (len + 1); | |
7344 | len = fread (filedata->program_interpreter, 1, len, | |
7345 | filedata->handle); | |
7346 | filedata->program_interpreter[len] = 0; | |
7347 | ||
7348 | if (do_segments) | |
7349 | printf (_(" [Requesting program interpreter: %s]\n"), | |
7350 | printable_string (filedata->program_interpreter, 0)); | |
7351 | } | |
7352 | break; | |
7353 | } | |
7354 | } | |
7355 | ||
7356 | if (do_segments | |
7357 | && filedata->section_headers != NULL | |
7358 | && filedata->string_table != NULL) | |
7359 | { | |
7360 | printf (_("\n Section to Segment mapping:\n")); | |
7361 | printf (_(" Segment Sections...\n")); | |
7362 | ||
7363 | for (i = 0; i < filedata->file_header.e_phnum; i++) | |
7364 | { | |
7365 | unsigned int j; | |
7366 | Elf_Internal_Shdr * section; | |
7367 | ||
7368 | segment = filedata->program_headers + i; | |
7369 | section = filedata->section_headers + 1; | |
7370 | ||
7371 | printf (" %2.2d ", i); | |
7372 | ||
7373 | for (j = 1; j < filedata->file_header.e_shnum; j++, section++) | |
7374 | { | |
7375 | if (!ELF_TBSS_SPECIAL (section, segment) | |
7376 | && ELF_SECTION_IN_SEGMENT_STRICT (section, segment)) | |
7377 | printf ("%s ", printable_section_name (filedata, section)); | |
7378 | } | |
7379 | ||
7380 | putc ('\n',stdout); | |
7381 | } | |
7382 | } | |
7383 | ||
7384 | filedata->dynamic_addr = dynamic_addr; | |
7385 | filedata->dynamic_size = dynamic_size ? dynamic_size : 1; | |
7386 | return; | |
7387 | ||
7388 | no_headers: | |
7389 | filedata->dynamic_addr = 0; | |
7390 | filedata->dynamic_size = 1; | |
7391 | } | |
7392 | ||
7393 | ||
7394 | /* Find the file offset corresponding to VMA by using the program headers. */ | |
7395 | ||
7396 | static int64_t | |
7397 | offset_from_vma (Filedata * filedata, uint64_t vma, uint64_t size) | |
7398 | { | |
7399 | Elf_Internal_Phdr * seg; | |
7400 | ||
7401 | if (! get_program_headers (filedata)) | |
7402 | { | |
7403 | warn (_("Cannot interpret virtual addresses without program headers.\n")); | |
7404 | return (long) vma; | |
7405 | } | |
7406 | ||
7407 | for (seg = filedata->program_headers; | |
7408 | seg < filedata->program_headers + filedata->file_header.e_phnum; | |
7409 | ++seg) | |
7410 | { | |
7411 | if (seg->p_type != PT_LOAD) | |
7412 | continue; | |
7413 | ||
7414 | if (vma >= (seg->p_vaddr & -seg->p_align) | |
7415 | && vma + size <= seg->p_vaddr + seg->p_filesz) | |
7416 | return vma - seg->p_vaddr + seg->p_offset; | |
7417 | } | |
7418 | ||
7419 | warn (_("Virtual address %#" PRIx64 | |
7420 | " not located in any PT_LOAD segment.\n"), vma); | |
7421 | return vma; | |
7422 | } | |
7423 | ||
7424 | ||
7425 | /* Allocate memory and load the sections headers into FILEDATA->filedata->section_headers. | |
7426 | If PROBE is true, this is just a probe and we do not generate any error | |
7427 | messages if the load fails. */ | |
7428 | ||
7429 | static bool | |
7430 | get_32bit_section_headers (Filedata * filedata, bool probe) | |
7431 | { | |
7432 | Elf32_External_Shdr * shdrs; | |
7433 | Elf_Internal_Shdr * internal; | |
7434 | unsigned int i; | |
7435 | unsigned int size = filedata->file_header.e_shentsize; | |
7436 | unsigned int num = probe ? 1 : filedata->file_header.e_shnum; | |
7437 | ||
7438 | /* PR binutils/17531: Cope with unexpected section header sizes. */ | |
7439 | if (size == 0 || num == 0) | |
7440 | return false; | |
7441 | ||
7442 | /* The section header cannot be at the start of the file - that is | |
7443 | where the ELF file header is located. A file with absolutely no | |
7444 | sections in it will use a shoff of 0. */ | |
7445 | if (filedata->file_header.e_shoff == 0) | |
7446 | return false; | |
7447 | ||
7448 | if (size < sizeof * shdrs) | |
7449 | { | |
7450 | if (! probe) | |
7451 | error (_("The e_shentsize field in the ELF header is less than the size of an ELF section header\n")); | |
7452 | return false; | |
7453 | } | |
7454 | if (!probe && size > sizeof * shdrs) | |
7455 | warn (_("The e_shentsize field in the ELF header is larger than the size of an ELF section header\n")); | |
7456 | ||
7457 | shdrs = (Elf32_External_Shdr *) get_data (NULL, filedata, filedata->file_header.e_shoff, | |
7458 | size, num, | |
7459 | probe ? NULL : _("section headers")); | |
7460 | if (shdrs == NULL) | |
7461 | return false; | |
7462 | ||
7463 | filedata->section_headers = (Elf_Internal_Shdr *) | |
7464 | cmalloc (num, sizeof (Elf_Internal_Shdr)); | |
7465 | if (filedata->section_headers == NULL) | |
7466 | { | |
7467 | if (!probe) | |
7468 | error (_("Out of memory reading %u section headers\n"), num); | |
7469 | free (shdrs); | |
7470 | return false; | |
7471 | } | |
7472 | ||
7473 | for (i = 0, internal = filedata->section_headers; | |
7474 | i < num; | |
7475 | i++, internal++) | |
7476 | { | |
7477 | internal->sh_name = BYTE_GET (shdrs[i].sh_name); | |
7478 | internal->sh_type = BYTE_GET (shdrs[i].sh_type); | |
7479 | internal->sh_flags = BYTE_GET (shdrs[i].sh_flags); | |
7480 | internal->sh_addr = BYTE_GET (shdrs[i].sh_addr); | |
7481 | internal->sh_offset = BYTE_GET (shdrs[i].sh_offset); | |
7482 | internal->sh_size = BYTE_GET (shdrs[i].sh_size); | |
7483 | internal->sh_link = BYTE_GET (shdrs[i].sh_link); | |
7484 | internal->sh_info = BYTE_GET (shdrs[i].sh_info); | |
7485 | internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign); | |
7486 | internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize); | |
7487 | if (!probe && internal->sh_link > num) | |
7488 | warn (_("Section %u has an out of range sh_link value of %u\n"), i, internal->sh_link); | |
7489 | if (!probe && internal->sh_flags & SHF_INFO_LINK && internal->sh_info > num) | |
7490 | warn (_("Section %u has an out of range sh_info value of %u\n"), i, internal->sh_info); | |
7491 | } | |
7492 | ||
7493 | free (shdrs); | |
7494 | return true; | |
7495 | } | |
7496 | ||
7497 | /* Like get_32bit_section_headers, except that it fetches 64-bit headers. */ | |
7498 | ||
7499 | static bool | |
7500 | get_64bit_section_headers (Filedata * filedata, bool probe) | |
7501 | { | |
7502 | Elf64_External_Shdr * shdrs; | |
7503 | Elf_Internal_Shdr * internal; | |
7504 | unsigned int i; | |
7505 | unsigned int size = filedata->file_header.e_shentsize; | |
7506 | unsigned int num = probe ? 1 : filedata->file_header.e_shnum; | |
7507 | ||
7508 | /* PR binutils/17531: Cope with unexpected section header sizes. */ | |
7509 | if (size == 0 || num == 0) | |
7510 | return false; | |
7511 | ||
7512 | /* The section header cannot be at the start of the file - that is | |
7513 | where the ELF file header is located. A file with absolutely no | |
7514 | sections in it will use a shoff of 0. */ | |
7515 | if (filedata->file_header.e_shoff == 0) | |
7516 | return false; | |
7517 | ||
7518 | if (size < sizeof * shdrs) | |
7519 | { | |
7520 | if (! probe) | |
7521 | error (_("The e_shentsize field in the ELF header is less than the size of an ELF section header\n")); | |
7522 | return false; | |
7523 | } | |
7524 | ||
7525 | if (! probe && size > sizeof * shdrs) | |
7526 | warn (_("The e_shentsize field in the ELF header is larger than the size of an ELF section header\n")); | |
7527 | ||
7528 | shdrs = (Elf64_External_Shdr *) get_data (NULL, filedata, | |
7529 | filedata->file_header.e_shoff, | |
7530 | size, num, | |
7531 | probe ? NULL : _("section headers")); | |
7532 | if (shdrs == NULL) | |
7533 | return false; | |
7534 | ||
7535 | filedata->section_headers = (Elf_Internal_Shdr *) | |
7536 | cmalloc (num, sizeof (Elf_Internal_Shdr)); | |
7537 | if (filedata->section_headers == NULL) | |
7538 | { | |
7539 | if (! probe) | |
7540 | error (_("Out of memory reading %u section headers\n"), num); | |
7541 | free (shdrs); | |
7542 | return false; | |
7543 | } | |
7544 | ||
7545 | for (i = 0, internal = filedata->section_headers; | |
7546 | i < num; | |
7547 | i++, internal++) | |
7548 | { | |
7549 | internal->sh_name = BYTE_GET (shdrs[i].sh_name); | |
7550 | internal->sh_type = BYTE_GET (shdrs[i].sh_type); | |
7551 | internal->sh_flags = BYTE_GET (shdrs[i].sh_flags); | |
7552 | internal->sh_addr = BYTE_GET (shdrs[i].sh_addr); | |
7553 | internal->sh_size = BYTE_GET (shdrs[i].sh_size); | |
7554 | internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize); | |
7555 | internal->sh_link = BYTE_GET (shdrs[i].sh_link); | |
7556 | internal->sh_info = BYTE_GET (shdrs[i].sh_info); | |
7557 | internal->sh_offset = BYTE_GET (shdrs[i].sh_offset); | |
7558 | internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign); | |
7559 | if (!probe && internal->sh_link > num) | |
7560 | warn (_("Section %u has an out of range sh_link value of %u\n"), i, internal->sh_link); | |
7561 | if (!probe && internal->sh_flags & SHF_INFO_LINK && internal->sh_info > num) | |
7562 | warn (_("Section %u has an out of range sh_info value of %u\n"), i, internal->sh_info); | |
7563 | } | |
7564 | ||
7565 | free (shdrs); | |
7566 | return true; | |
7567 | } | |
7568 | ||
7569 | static bool | |
7570 | get_section_headers (Filedata *filedata, bool probe) | |
7571 | { | |
7572 | if (filedata->section_headers != NULL) | |
7573 | return true; | |
7574 | ||
7575 | if (is_32bit_elf) | |
7576 | return get_32bit_section_headers (filedata, probe); | |
7577 | else | |
7578 | return get_64bit_section_headers (filedata, probe); | |
7579 | } | |
7580 | ||
7581 | static Elf_Internal_Sym * | |
7582 | get_32bit_elf_symbols (Filedata *filedata, | |
7583 | Elf_Internal_Shdr *section, | |
7584 | uint64_t *num_syms_return) | |
7585 | { | |
7586 | uint64_t number = 0; | |
7587 | Elf32_External_Sym * esyms = NULL; | |
7588 | Elf_External_Sym_Shndx * shndx = NULL; | |
7589 | Elf_Internal_Sym * isyms = NULL; | |
7590 | Elf_Internal_Sym * psym; | |
7591 | unsigned int j; | |
7592 | elf_section_list * entry; | |
7593 | ||
7594 | if (section->sh_size == 0) | |
7595 | { | |
7596 | if (num_syms_return != NULL) | |
7597 | * num_syms_return = 0; | |
7598 | return NULL; | |
7599 | } | |
7600 | ||
7601 | /* Run some sanity checks first. */ | |
7602 | if (section->sh_entsize == 0 || section->sh_entsize > section->sh_size) | |
7603 | { | |
7604 | error (_("Section %s has an invalid sh_entsize of %#" PRIx64 "\n"), | |
7605 | printable_section_name (filedata, section), | |
7606 | section->sh_entsize); | |
7607 | goto exit_point; | |
7608 | } | |
7609 | ||
7610 | if (section->sh_size > filedata->file_size) | |
7611 | { | |
7612 | error (_("Section %s has an invalid sh_size of %#" PRIx64 "\n"), | |
7613 | printable_section_name (filedata, section), | |
7614 | section->sh_size); | |
7615 | goto exit_point; | |
7616 | } | |
7617 | ||
7618 | number = section->sh_size / section->sh_entsize; | |
7619 | ||
7620 | if (number * sizeof (Elf32_External_Sym) > section->sh_size + 1) | |
7621 | { | |
7622 | error (_("Size (%#" PRIx64 ") of section %s " | |
7623 | "is not a multiple of its sh_entsize (%#" PRIx64 ")\n"), | |
7624 | section->sh_size, | |
7625 | printable_section_name (filedata, section), | |
7626 | section->sh_entsize); | |
7627 | goto exit_point; | |
7628 | } | |
7629 | ||
7630 | esyms = (Elf32_External_Sym *) get_data (NULL, filedata, section->sh_offset, 1, | |
7631 | section->sh_size, _("symbols")); | |
7632 | if (esyms == NULL) | |
7633 | goto exit_point; | |
7634 | ||
7635 | shndx = NULL; | |
7636 | for (entry = filedata->symtab_shndx_list; entry != NULL; entry = entry->next) | |
7637 | { | |
7638 | if (entry->hdr->sh_link != (size_t) (section - filedata->section_headers)) | |
7639 | continue; | |
7640 | ||
7641 | if (shndx != NULL) | |
7642 | { | |
7643 | error (_("Multiple symbol table index sections associated with the same symbol section\n")); | |
7644 | free (shndx); | |
7645 | } | |
7646 | ||
7647 | shndx = (Elf_External_Sym_Shndx *) get_data (NULL, filedata, | |
7648 | entry->hdr->sh_offset, | |
7649 | 1, entry->hdr->sh_size, | |
7650 | _("symbol table section indices")); | |
7651 | if (shndx == NULL) | |
7652 | goto exit_point; | |
7653 | ||
7654 | /* PR17531: file: heap-buffer-overflow */ | |
7655 | if (entry->hdr->sh_size / sizeof (Elf_External_Sym_Shndx) < number) | |
7656 | { | |
7657 | error (_("Index section %s has an sh_size of %#" PRIx64 " - expected %#" PRIx64 "\n"), | |
7658 | printable_section_name (filedata, entry->hdr), | |
7659 | entry->hdr->sh_size, | |
7660 | section->sh_size); | |
7661 | goto exit_point; | |
7662 | } | |
7663 | } | |
7664 | ||
7665 | isyms = (Elf_Internal_Sym *) cmalloc (number, sizeof (Elf_Internal_Sym)); | |
7666 | ||
7667 | if (isyms == NULL) | |
7668 | { | |
7669 | error (_("Out of memory reading %" PRIu64 " symbols\n"), number); | |
7670 | goto exit_point; | |
7671 | } | |
7672 | ||
7673 | for (j = 0, psym = isyms; j < number; j++, psym++) | |
7674 | { | |
7675 | psym->st_name = BYTE_GET (esyms[j].st_name); | |
7676 | psym->st_value = BYTE_GET (esyms[j].st_value); | |
7677 | psym->st_size = BYTE_GET (esyms[j].st_size); | |
7678 | psym->st_shndx = BYTE_GET (esyms[j].st_shndx); | |
7679 | if (psym->st_shndx == (SHN_XINDEX & 0xffff) && shndx != NULL) | |
7680 | psym->st_shndx | |
7681 | = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j])); | |
7682 | else if (psym->st_shndx >= (SHN_LORESERVE & 0xffff)) | |
7683 | psym->st_shndx += SHN_LORESERVE - (SHN_LORESERVE & 0xffff); | |
7684 | psym->st_info = BYTE_GET (esyms[j].st_info); | |
7685 | psym->st_other = BYTE_GET (esyms[j].st_other); | |
7686 | } | |
7687 | ||
7688 | exit_point: | |
7689 | free (shndx); | |
7690 | free (esyms); | |
7691 | ||
7692 | if (num_syms_return != NULL) | |
7693 | * num_syms_return = isyms == NULL ? 0 : number; | |
7694 | ||
7695 | return isyms; | |
7696 | } | |
7697 | ||
7698 | static Elf_Internal_Sym * | |
7699 | get_64bit_elf_symbols (Filedata *filedata, | |
7700 | Elf_Internal_Shdr *section, | |
7701 | uint64_t *num_syms_return) | |
7702 | { | |
7703 | uint64_t number = 0; | |
7704 | Elf64_External_Sym * esyms = NULL; | |
7705 | Elf_External_Sym_Shndx * shndx = NULL; | |
7706 | Elf_Internal_Sym * isyms = NULL; | |
7707 | Elf_Internal_Sym * psym; | |
7708 | unsigned int j; | |
7709 | elf_section_list * entry; | |
7710 | ||
7711 | if (section->sh_size == 0) | |
7712 | { | |
7713 | if (num_syms_return != NULL) | |
7714 | * num_syms_return = 0; | |
7715 | return NULL; | |
7716 | } | |
7717 | ||
7718 | /* Run some sanity checks first. */ | |
7719 | if (section->sh_entsize == 0 || section->sh_entsize > section->sh_size) | |
7720 | { | |
7721 | error (_("Section %s has an invalid sh_entsize of %#" PRIx64 "\n"), | |
7722 | printable_section_name (filedata, section), | |
7723 | section->sh_entsize); | |
7724 | goto exit_point; | |
7725 | } | |
7726 | ||
7727 | if (section->sh_size > filedata->file_size) | |
7728 | { | |
7729 | error (_("Section %s has an invalid sh_size of %#" PRIx64 "\n"), | |
7730 | printable_section_name (filedata, section), | |
7731 | section->sh_size); | |
7732 | goto exit_point; | |
7733 | } | |
7734 | ||
7735 | number = section->sh_size / section->sh_entsize; | |
7736 | ||
7737 | if (number * sizeof (Elf64_External_Sym) > section->sh_size + 1) | |
7738 | { | |
7739 | error (_("Size (%#" PRIx64 ") of section %s " | |
7740 | "is not a multiple of its sh_entsize (%#" PRIx64 ")\n"), | |
7741 | section->sh_size, | |
7742 | printable_section_name (filedata, section), | |
7743 | section->sh_entsize); | |
7744 | goto exit_point; | |
7745 | } | |
7746 | ||
7747 | esyms = (Elf64_External_Sym *) get_data (NULL, filedata, section->sh_offset, 1, | |
7748 | section->sh_size, _("symbols")); | |
7749 | if (!esyms) | |
7750 | goto exit_point; | |
7751 | ||
7752 | shndx = NULL; | |
7753 | for (entry = filedata->symtab_shndx_list; entry != NULL; entry = entry->next) | |
7754 | { | |
7755 | if (entry->hdr->sh_link != (size_t) (section - filedata->section_headers)) | |
7756 | continue; | |
7757 | ||
7758 | if (shndx != NULL) | |
7759 | { | |
7760 | error (_("Multiple symbol table index sections associated with the same symbol section\n")); | |
7761 | free (shndx); | |
7762 | } | |
7763 | ||
7764 | shndx = (Elf_External_Sym_Shndx *) get_data (NULL, filedata, | |
7765 | entry->hdr->sh_offset, | |
7766 | 1, entry->hdr->sh_size, | |
7767 | _("symbol table section indices")); | |
7768 | if (shndx == NULL) | |
7769 | goto exit_point; | |
7770 | ||
7771 | /* PR17531: file: heap-buffer-overflow */ | |
7772 | if (entry->hdr->sh_size / sizeof (Elf_External_Sym_Shndx) < number) | |
7773 | { | |
7774 | error (_("Index section %s has an sh_size of %#" PRIx64 " - expected %#" PRIx64 "\n"), | |
7775 | printable_section_name (filedata, entry->hdr), | |
7776 | entry->hdr->sh_size, | |
7777 | section->sh_size); | |
7778 | goto exit_point; | |
7779 | } | |
7780 | } | |
7781 | ||
7782 | isyms = (Elf_Internal_Sym *) cmalloc (number, sizeof (Elf_Internal_Sym)); | |
7783 | ||
7784 | if (isyms == NULL) | |
7785 | { | |
7786 | error (_("Out of memory reading %" PRIu64 " symbols\n"), number); | |
7787 | goto exit_point; | |
7788 | } | |
7789 | ||
7790 | for (j = 0, psym = isyms; j < number; j++, psym++) | |
7791 | { | |
7792 | psym->st_name = BYTE_GET (esyms[j].st_name); | |
7793 | psym->st_info = BYTE_GET (esyms[j].st_info); | |
7794 | psym->st_other = BYTE_GET (esyms[j].st_other); | |
7795 | psym->st_shndx = BYTE_GET (esyms[j].st_shndx); | |
7796 | ||
7797 | if (psym->st_shndx == (SHN_XINDEX & 0xffff) && shndx != NULL) | |
7798 | psym->st_shndx | |
7799 | = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j])); | |
7800 | else if (psym->st_shndx >= (SHN_LORESERVE & 0xffff)) | |
7801 | psym->st_shndx += SHN_LORESERVE - (SHN_LORESERVE & 0xffff); | |
7802 | ||
7803 | psym->st_value = BYTE_GET (esyms[j].st_value); | |
7804 | psym->st_size = BYTE_GET (esyms[j].st_size); | |
7805 | } | |
7806 | ||
7807 | exit_point: | |
7808 | free (shndx); | |
7809 | free (esyms); | |
7810 | ||
7811 | if (num_syms_return != NULL) | |
7812 | * num_syms_return = isyms == NULL ? 0 : number; | |
7813 | ||
7814 | return isyms; | |
7815 | } | |
7816 | ||
7817 | static Elf_Internal_Sym * | |
7818 | get_elf_symbols (Filedata *filedata, | |
7819 | Elf_Internal_Shdr *section, | |
7820 | uint64_t *num_syms_return) | |
7821 | { | |
7822 | if (is_32bit_elf) | |
7823 | return get_32bit_elf_symbols (filedata, section, num_syms_return); | |
7824 | else | |
7825 | return get_64bit_elf_symbols (filedata, section, num_syms_return); | |
7826 | } | |
7827 | ||
7828 | static const char * | |
7829 | get_elf_section_flags (Filedata * filedata, uint64_t sh_flags) | |
7830 | { | |
7831 | static char buff[1024]; | |
7832 | char * p = buff; | |
7833 | unsigned int field_size = is_32bit_elf ? 8 : 16; | |
7834 | signed int sindex; | |
7835 | unsigned int size = sizeof (buff) - (field_size + 4 + 1); | |
7836 | uint64_t os_flags = 0; | |
7837 | uint64_t proc_flags = 0; | |
7838 | uint64_t unknown_flags = 0; | |
7839 | static const struct | |
7840 | { | |
7841 | const char * str; | |
7842 | unsigned int len; | |
7843 | } | |
7844 | flags [] = | |
7845 | { | |
7846 | /* 0 */ { STRING_COMMA_LEN ("WRITE") }, | |
7847 | /* 1 */ { STRING_COMMA_LEN ("ALLOC") }, | |
7848 | /* 2 */ { STRING_COMMA_LEN ("EXEC") }, | |
7849 | /* 3 */ { STRING_COMMA_LEN ("MERGE") }, | |
7850 | /* 4 */ { STRING_COMMA_LEN ("STRINGS") }, | |
7851 | /* 5 */ { STRING_COMMA_LEN ("INFO LINK") }, | |
7852 | /* 6 */ { STRING_COMMA_LEN ("LINK ORDER") }, | |
7853 | /* 7 */ { STRING_COMMA_LEN ("OS NONCONF") }, | |
7854 | /* 8 */ { STRING_COMMA_LEN ("GROUP") }, | |
7855 | /* 9 */ { STRING_COMMA_LEN ("TLS") }, | |
7856 | /* IA-64 specific. */ | |
7857 | /* 10 */ { STRING_COMMA_LEN ("SHORT") }, | |
7858 | /* 11 */ { STRING_COMMA_LEN ("NORECOV") }, | |
7859 | /* IA-64 OpenVMS specific. */ | |
7860 | /* 12 */ { STRING_COMMA_LEN ("VMS_GLOBAL") }, | |
7861 | /* 13 */ { STRING_COMMA_LEN ("VMS_OVERLAID") }, | |
7862 | /* 14 */ { STRING_COMMA_LEN ("VMS_SHARED") }, | |
7863 | /* 15 */ { STRING_COMMA_LEN ("VMS_VECTOR") }, | |
7864 | /* 16 */ { STRING_COMMA_LEN ("VMS_ALLOC_64BIT") }, | |
7865 | /* 17 */ { STRING_COMMA_LEN ("VMS_PROTECTED") }, | |
7866 | /* Generic. */ | |
7867 | /* 18 */ { STRING_COMMA_LEN ("EXCLUDE") }, | |
7868 | /* SPARC specific. */ | |
7869 | /* 19 */ { STRING_COMMA_LEN ("ORDERED") }, | |
7870 | /* 20 */ { STRING_COMMA_LEN ("COMPRESSED") }, | |
7871 | /* ARM specific. */ | |
7872 | /* 21 */ { STRING_COMMA_LEN ("ENTRYSECT") }, | |
7873 | /* 22 */ { STRING_COMMA_LEN ("ARM_PURECODE") }, | |
7874 | /* 23 */ { STRING_COMMA_LEN ("COMDEF") }, | |
7875 | /* GNU specific. */ | |
7876 | /* 24 */ { STRING_COMMA_LEN ("GNU_MBIND") }, | |
7877 | /* VLE specific. */ | |
7878 | /* 25 */ { STRING_COMMA_LEN ("VLE") }, | |
7879 | /* GNU specific. */ | |
7880 | /* 26 */ { STRING_COMMA_LEN ("GNU_RETAIN") }, | |
7881 | }; | |
7882 | ||
7883 | if (do_section_details) | |
7884 | p += sprintf (p, "[%*.*lx]: ", | |
7885 | field_size, field_size, (unsigned long) sh_flags); | |
7886 | ||
7887 | while (sh_flags) | |
7888 | { | |
7889 | uint64_t flag; | |
7890 | ||
7891 | flag = sh_flags & - sh_flags; | |
7892 | sh_flags &= ~ flag; | |
7893 | ||
7894 | if (do_section_details) | |
7895 | { | |
7896 | switch (flag) | |
7897 | { | |
7898 | case SHF_WRITE: sindex = 0; break; | |
7899 | case SHF_ALLOC: sindex = 1; break; | |
7900 | case SHF_EXECINSTR: sindex = 2; break; | |
7901 | case SHF_MERGE: sindex = 3; break; | |
7902 | case SHF_STRINGS: sindex = 4; break; | |
7903 | case SHF_INFO_LINK: sindex = 5; break; | |
7904 | case SHF_LINK_ORDER: sindex = 6; break; | |
7905 | case SHF_OS_NONCONFORMING: sindex = 7; break; | |
7906 | case SHF_GROUP: sindex = 8; break; | |
7907 | case SHF_TLS: sindex = 9; break; | |
7908 | case SHF_EXCLUDE: sindex = 18; break; | |
7909 | case SHF_COMPRESSED: sindex = 20; break; | |
7910 | ||
7911 | default: | |
7912 | sindex = -1; | |
7913 | switch (filedata->file_header.e_machine) | |
7914 | { | |
7915 | case EM_IA_64: | |
7916 | if (flag == SHF_IA_64_SHORT) | |
7917 | sindex = 10; | |
7918 | else if (flag == SHF_IA_64_NORECOV) | |
7919 | sindex = 11; | |
7920 | else if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_OPENVMS) | |
7921 | switch (flag) | |
7922 | { | |
7923 | case SHF_IA_64_VMS_GLOBAL: sindex = 12; break; | |
7924 | case SHF_IA_64_VMS_OVERLAID: sindex = 13; break; | |
7925 | case SHF_IA_64_VMS_SHARED: sindex = 14; break; | |
7926 | case SHF_IA_64_VMS_VECTOR: sindex = 15; break; | |
7927 | case SHF_IA_64_VMS_ALLOC_64BIT: sindex = 16; break; | |
7928 | case SHF_IA_64_VMS_PROTECTED: sindex = 17; break; | |
7929 | default: break; | |
7930 | } | |
7931 | break; | |
7932 | ||
7933 | case EM_386: | |
7934 | case EM_IAMCU: | |
7935 | case EM_X86_64: | |
7936 | case EM_L1OM: | |
7937 | case EM_K1OM: | |
7938 | case EM_OLD_SPARCV9: | |
7939 | case EM_SPARC32PLUS: | |
7940 | case EM_SPARCV9: | |
7941 | case EM_SPARC: | |
7942 | if (flag == SHF_ORDERED) | |
7943 | sindex = 19; | |
7944 | break; | |
7945 | ||
7946 | case EM_ARM: | |
7947 | switch (flag) | |
7948 | { | |
7949 | case SHF_ENTRYSECT: sindex = 21; break; | |
7950 | case SHF_ARM_PURECODE: sindex = 22; break; | |
7951 | case SHF_COMDEF: sindex = 23; break; | |
7952 | default: break; | |
7953 | } | |
7954 | break; | |
7955 | case EM_PPC: | |
7956 | if (flag == SHF_PPC_VLE) | |
7957 | sindex = 25; | |
7958 | break; | |
7959 | default: | |
7960 | break; | |
7961 | } | |
7962 | ||
7963 | switch (filedata->file_header.e_ident[EI_OSABI]) | |
7964 | { | |
7965 | case ELFOSABI_GNU: | |
7966 | case ELFOSABI_FREEBSD: | |
7967 | if (flag == SHF_GNU_RETAIN) | |
7968 | sindex = 26; | |
7969 | /* Fall through */ | |
7970 | case ELFOSABI_NONE: | |
7971 | if (flag == SHF_GNU_MBIND) | |
7972 | /* We should not recognize SHF_GNU_MBIND for | |
7973 | ELFOSABI_NONE, but binutils as of 2019-07-23 did | |
7974 | not set the EI_OSABI header byte. */ | |
7975 | sindex = 24; | |
7976 | break; | |
7977 | default: | |
7978 | break; | |
7979 | } | |
7980 | break; | |
7981 | } | |
7982 | ||
7983 | if (sindex != -1) | |
7984 | { | |
7985 | if (p != buff + field_size + 4) | |
7986 | { | |
7987 | if (size < (10 + 2)) | |
7988 | { | |
7989 | warn (_("Internal error: not enough buffer room for section flag info")); | |
7990 | return _("<unknown>"); | |
7991 | } | |
7992 | size -= 2; | |
7993 | *p++ = ','; | |
7994 | *p++ = ' '; | |
7995 | } | |
7996 | ||
7997 | size -= flags [sindex].len; | |
7998 | p = stpcpy (p, flags [sindex].str); | |
7999 | } | |
8000 | else if (flag & SHF_MASKOS) | |
8001 | os_flags |= flag; | |
8002 | else if (flag & SHF_MASKPROC) | |
8003 | proc_flags |= flag; | |
8004 | else | |
8005 | unknown_flags |= flag; | |
8006 | } | |
8007 | else | |
8008 | { | |
8009 | switch (flag) | |
8010 | { | |
8011 | case SHF_WRITE: *p = 'W'; break; | |
8012 | case SHF_ALLOC: *p = 'A'; break; | |
8013 | case SHF_EXECINSTR: *p = 'X'; break; | |
8014 | case SHF_MERGE: *p = 'M'; break; | |
8015 | case SHF_STRINGS: *p = 'S'; break; | |
8016 | case SHF_INFO_LINK: *p = 'I'; break; | |
8017 | case SHF_LINK_ORDER: *p = 'L'; break; | |
8018 | case SHF_OS_NONCONFORMING: *p = 'O'; break; | |
8019 | case SHF_GROUP: *p = 'G'; break; | |
8020 | case SHF_TLS: *p = 'T'; break; | |
8021 | case SHF_EXCLUDE: *p = 'E'; break; | |
8022 | case SHF_COMPRESSED: *p = 'C'; break; | |
8023 | ||
8024 | default: | |
8025 | if ((filedata->file_header.e_machine == EM_X86_64 | |
8026 | || filedata->file_header.e_machine == EM_L1OM | |
8027 | || filedata->file_header.e_machine == EM_K1OM) | |
8028 | && flag == SHF_X86_64_LARGE) | |
8029 | *p = 'l'; | |
8030 | else if (filedata->file_header.e_machine == EM_ARM | |
8031 | && flag == SHF_ARM_PURECODE) | |
8032 | *p = 'y'; | |
8033 | else if (filedata->file_header.e_machine == EM_PPC | |
8034 | && flag == SHF_PPC_VLE) | |
8035 | *p = 'v'; | |
8036 | else if (flag & SHF_MASKOS) | |
8037 | { | |
8038 | switch (filedata->file_header.e_ident[EI_OSABI]) | |
8039 | { | |
8040 | case ELFOSABI_GNU: | |
8041 | case ELFOSABI_FREEBSD: | |
8042 | if (flag == SHF_GNU_RETAIN) | |
8043 | { | |
8044 | *p = 'R'; | |
8045 | break; | |
8046 | } | |
8047 | /* Fall through */ | |
8048 | case ELFOSABI_NONE: | |
8049 | if (flag == SHF_GNU_MBIND) | |
8050 | { | |
8051 | /* We should not recognize SHF_GNU_MBIND for | |
8052 | ELFOSABI_NONE, but binutils as of 2019-07-23 did | |
8053 | not set the EI_OSABI header byte. */ | |
8054 | *p = 'D'; | |
8055 | break; | |
8056 | } | |
8057 | /* Fall through */ | |
8058 | default: | |
8059 | *p = 'o'; | |
8060 | sh_flags &= ~SHF_MASKOS; | |
8061 | break; | |
8062 | } | |
8063 | } | |
8064 | else if (flag & SHF_MASKPROC) | |
8065 | { | |
8066 | *p = 'p'; | |
8067 | sh_flags &= ~ SHF_MASKPROC; | |
8068 | } | |
8069 | else | |
8070 | *p = 'x'; | |
8071 | break; | |
8072 | } | |
8073 | p++; | |
8074 | } | |
8075 | } | |
8076 | ||
8077 | if (do_section_details) | |
8078 | { | |
8079 | if (os_flags) | |
8080 | { | |
8081 | if (p != buff + field_size + 4) | |
8082 | { | |
8083 | if (size < 2 + 5 + field_size + 1) | |
8084 | { | |
8085 | warn (_("Internal error: not enough buffer room for section flag info")); | |
8086 | return _("<unknown>"); | |
8087 | } | |
8088 | size -= 2; | |
8089 | *p++ = ','; | |
8090 | *p++ = ' '; | |
8091 | } | |
8092 | size -= 5 + field_size; | |
8093 | p += sprintf (p, "OS (%*.*lx)", field_size, field_size, | |
8094 | (unsigned long) os_flags); | |
8095 | } | |
8096 | if (proc_flags) | |
8097 | { | |
8098 | if (p != buff + field_size + 4) | |
8099 | { | |
8100 | if (size < 2 + 7 + field_size + 1) | |
8101 | { | |
8102 | warn (_("Internal error: not enough buffer room for section flag info")); | |
8103 | return _("<unknown>"); | |
8104 | } | |
8105 | size -= 2; | |
8106 | *p++ = ','; | |
8107 | *p++ = ' '; | |
8108 | } | |
8109 | size -= 7 + field_size; | |
8110 | p += sprintf (p, "PROC (%*.*lx)", field_size, field_size, | |
8111 | (unsigned long) proc_flags); | |
8112 | } | |
8113 | if (unknown_flags) | |
8114 | { | |
8115 | if (p != buff + field_size + 4) | |
8116 | { | |
8117 | if (size < 2 + 10 + field_size + 1) | |
8118 | { | |
8119 | warn (_("Internal error: not enough buffer room for section flag info")); | |
8120 | return _("<unknown>"); | |
8121 | } | |
8122 | size -= 2; | |
8123 | *p++ = ','; | |
8124 | *p++ = ' '; | |
8125 | } | |
8126 | size -= 10 + field_size; | |
8127 | p += sprintf (p, _("UNKNOWN (%*.*lx)"), field_size, field_size, | |
8128 | (unsigned long) unknown_flags); | |
8129 | } | |
8130 | } | |
8131 | ||
8132 | *p = '\0'; | |
8133 | return buff; | |
8134 | } | |
8135 | ||
8136 | static unsigned int ATTRIBUTE_WARN_UNUSED_RESULT | |
8137 | get_compression_header (Elf_Internal_Chdr *chdr, unsigned char *buf, | |
8138 | uint64_t size) | |
8139 | { | |
8140 | if (is_32bit_elf) | |
8141 | { | |
8142 | Elf32_External_Chdr *echdr = (Elf32_External_Chdr *) buf; | |
8143 | ||
8144 | if (size < sizeof (* echdr)) | |
8145 | { | |
8146 | error (_("Compressed section is too small even for a compression header\n")); | |
8147 | return 0; | |
8148 | } | |
8149 | ||
8150 | chdr->ch_type = BYTE_GET (echdr->ch_type); | |
8151 | chdr->ch_size = BYTE_GET (echdr->ch_size); | |
8152 | chdr->ch_addralign = BYTE_GET (echdr->ch_addralign); | |
8153 | return sizeof (*echdr); | |
8154 | } | |
8155 | else | |
8156 | { | |
8157 | Elf64_External_Chdr *echdr = (Elf64_External_Chdr *) buf; | |
8158 | ||
8159 | if (size < sizeof (* echdr)) | |
8160 | { | |
8161 | error (_("Compressed section is too small even for a compression header\n")); | |
8162 | return 0; | |
8163 | } | |
8164 | ||
8165 | chdr->ch_type = BYTE_GET (echdr->ch_type); | |
8166 | chdr->ch_size = BYTE_GET (echdr->ch_size); | |
8167 | chdr->ch_addralign = BYTE_GET (echdr->ch_addralign); | |
8168 | return sizeof (*echdr); | |
8169 | } | |
8170 | } | |
8171 | ||
8172 | static bool | |
8173 | process_section_headers (Filedata * filedata) | |
8174 | { | |
8175 | Elf_Internal_Shdr * section; | |
8176 | unsigned int i; | |
8177 | ||
8178 | if (filedata->file_header.e_shnum == 0) | |
8179 | { | |
8180 | /* PR binutils/12467. */ | |
8181 | if (filedata->file_header.e_shoff != 0) | |
8182 | { | |
8183 | warn (_("possibly corrupt ELF file header - it has a non-zero" | |
8184 | " section header offset, but no section headers\n")); | |
8185 | return false; | |
8186 | } | |
8187 | else if (do_sections) | |
8188 | printf (_("\nThere are no sections in this file.\n")); | |
8189 | ||
8190 | return true; | |
8191 | } | |
8192 | ||
8193 | if (do_sections && !do_header) | |
8194 | { | |
8195 | if (filedata->is_separate && process_links) | |
8196 | printf (_("In linked file '%s': "), | |
8197 | printable_string (filedata->file_name, 0)); | |
8198 | if (! filedata->is_separate || process_links) | |
8199 | printf (ngettext ("There is %d section header, " | |
8200 | "starting at offset %#" PRIx64 ":\n", | |
8201 | "There are %d section headers, " | |
8202 | "starting at offset %#" PRIx64 ":\n", | |
8203 | filedata->file_header.e_shnum), | |
8204 | filedata->file_header.e_shnum, | |
8205 | filedata->file_header.e_shoff); | |
8206 | } | |
8207 | ||
8208 | if (!get_section_headers (filedata, false)) | |
8209 | return false; | |
8210 | ||
8211 | /* Read in the string table, so that we have names to display. */ | |
8212 | if (filedata->string_table == NULL | |
8213 | && filedata->file_header.e_shstrndx != SHN_UNDEF | |
8214 | && filedata->file_header.e_shstrndx < filedata->file_header.e_shnum) | |
8215 | { | |
8216 | section = filedata->section_headers + filedata->file_header.e_shstrndx; | |
8217 | ||
8218 | if (section->sh_size != 0) | |
8219 | { | |
8220 | filedata->string_table = (char *) get_data (NULL, filedata, section->sh_offset, | |
8221 | 1, section->sh_size, | |
8222 | _("string table")); | |
8223 | ||
8224 | filedata->string_table_length = filedata->string_table != NULL ? section->sh_size : 0; | |
8225 | } | |
8226 | } | |
8227 | ||
8228 | /* Scan the sections for the dynamic symbol table | |
8229 | and dynamic string table and debug sections. */ | |
8230 | eh_addr_size = is_32bit_elf ? 4 : 8; | |
8231 | switch (filedata->file_header.e_machine) | |
8232 | { | |
8233 | case EM_MIPS: | |
8234 | case EM_MIPS_RS3_LE: | |
8235 | /* The 64-bit MIPS EABI uses a combination of 32-bit ELF and 64-bit | |
8236 | FDE addresses. However, the ABI also has a semi-official ILP32 | |
8237 | variant for which the normal FDE address size rules apply. | |
8238 | ||
8239 | GCC 4.0 marks EABI64 objects with a dummy .gcc_compiled_longXX | |
8240 | section, where XX is the size of longs in bits. Unfortunately, | |
8241 | earlier compilers provided no way of distinguishing ILP32 objects | |
8242 | from LP64 objects, so if there's any doubt, we should assume that | |
8243 | the official LP64 form is being used. */ | |
8244 | if ((filedata->file_header.e_flags & EF_MIPS_ABI) == EF_MIPS_ABI_EABI64 | |
8245 | && find_section (filedata, ".gcc_compiled_long32") == NULL) | |
8246 | eh_addr_size = 8; | |
8247 | break; | |
8248 | ||
8249 | case EM_H8_300: | |
8250 | case EM_H8_300H: | |
8251 | switch (filedata->file_header.e_flags & EF_H8_MACH) | |
8252 | { | |
8253 | case E_H8_MACH_H8300: | |
8254 | case E_H8_MACH_H8300HN: | |
8255 | case E_H8_MACH_H8300SN: | |
8256 | case E_H8_MACH_H8300SXN: | |
8257 | eh_addr_size = 2; | |
8258 | break; | |
8259 | case E_H8_MACH_H8300H: | |
8260 | case E_H8_MACH_H8300S: | |
8261 | case E_H8_MACH_H8300SX: | |
8262 | eh_addr_size = 4; | |
8263 | break; | |
8264 | } | |
8265 | break; | |
8266 | ||
8267 | case EM_M32C_OLD: | |
8268 | case EM_M32C: | |
8269 | switch (filedata->file_header.e_flags & EF_M32C_CPU_MASK) | |
8270 | { | |
8271 | case EF_M32C_CPU_M16C: | |
8272 | eh_addr_size = 2; | |
8273 | break; | |
8274 | } | |
8275 | break; | |
8276 | } | |
8277 | ||
8278 | #define CHECK_ENTSIZE_VALUES(section, i, size32, size64) \ | |
8279 | do \ | |
8280 | { \ | |
8281 | uint64_t expected_entsize = is_32bit_elf ? size32 : size64; \ | |
8282 | if (section->sh_entsize != expected_entsize) \ | |
8283 | { \ | |
8284 | error (_("Section %d has invalid sh_entsize of %" PRIx64 "\n"), \ | |
8285 | i, section->sh_entsize); \ | |
8286 | error (_("(Using the expected size of %" PRIx64 " for the rest of this dump)\n"), \ | |
8287 | expected_entsize); \ | |
8288 | section->sh_entsize = expected_entsize; \ | |
8289 | } \ | |
8290 | } \ | |
8291 | while (0) | |
8292 | ||
8293 | #define CHECK_ENTSIZE(section, i, type) \ | |
8294 | CHECK_ENTSIZE_VALUES (section, i, sizeof (Elf32_External_##type), \ | |
8295 | sizeof (Elf64_External_##type)) | |
8296 | ||
8297 | for (i = 0, section = filedata->section_headers; | |
8298 | i < filedata->file_header.e_shnum; | |
8299 | i++, section++) | |
8300 | { | |
8301 | const char *name = printable_section_name (filedata, section); | |
8302 | ||
8303 | /* Run some sanity checks on the headers and | |
8304 | possibly fill in some file data as well. */ | |
8305 | switch (section->sh_type) | |
8306 | { | |
8307 | case SHT_DYNSYM: | |
8308 | if (filedata->dynamic_symbols != NULL) | |
8309 | { | |
8310 | error (_("File contains multiple dynamic symbol tables\n")); | |
8311 | continue; | |
8312 | } | |
8313 | ||
8314 | CHECK_ENTSIZE (section, i, Sym); | |
8315 | filedata->dynamic_symbols | |
8316 | = get_elf_symbols (filedata, section, &filedata->num_dynamic_syms); | |
8317 | filedata->dynamic_symtab_section = section; | |
8318 | break; | |
8319 | ||
8320 | case SHT_STRTAB: | |
8321 | if (streq (name, ".dynstr")) | |
8322 | { | |
8323 | if (filedata->dynamic_strings != NULL) | |
8324 | { | |
8325 | error (_("File contains multiple dynamic string tables\n")); | |
8326 | continue; | |
8327 | } | |
8328 | ||
8329 | filedata->dynamic_strings | |
8330 | = (char *) get_data (NULL, filedata, section->sh_offset, | |
8331 | 1, section->sh_size, _("dynamic strings")); | |
8332 | filedata->dynamic_strings_length | |
8333 | = filedata->dynamic_strings == NULL ? 0 : section->sh_size; | |
8334 | filedata->dynamic_strtab_section = section; | |
8335 | } | |
8336 | break; | |
8337 | ||
8338 | case SHT_SYMTAB_SHNDX: | |
8339 | { | |
8340 | elf_section_list * entry = xmalloc (sizeof * entry); | |
8341 | ||
8342 | entry->hdr = section; | |
8343 | entry->next = filedata->symtab_shndx_list; | |
8344 | filedata->symtab_shndx_list = entry; | |
8345 | } | |
8346 | break; | |
8347 | ||
8348 | case SHT_SYMTAB: | |
8349 | CHECK_ENTSIZE (section, i, Sym); | |
8350 | break; | |
8351 | ||
8352 | case SHT_GROUP: | |
8353 | CHECK_ENTSIZE_VALUES (section, i, GRP_ENTRY_SIZE, GRP_ENTRY_SIZE); | |
8354 | break; | |
8355 | ||
8356 | case SHT_REL: | |
8357 | CHECK_ENTSIZE (section, i, Rel); | |
8358 | if (do_checks && section->sh_size == 0) | |
8359 | warn (_("Section '%s': zero-sized relocation section\n"), name); | |
8360 | break; | |
8361 | ||
8362 | case SHT_RELA: | |
8363 | CHECK_ENTSIZE (section, i, Rela); | |
8364 | if (do_checks && section->sh_size == 0) | |
8365 | warn (_("Section '%s': zero-sized relocation section\n"), name); | |
8366 | break; | |
8367 | ||
8368 | case SHT_RELR: | |
8369 | CHECK_ENTSIZE (section, i, Relr); | |
8370 | break; | |
8371 | ||
8372 | case SHT_NOTE: | |
8373 | case SHT_PROGBITS: | |
8374 | case SHT_GNU_SFRAME: | |
8375 | /* Having a zero sized section is not illegal according to the | |
8376 | ELF standard, but it might be an indication that something | |
8377 | is wrong. So issue a warning if we are running in lint mode. */ | |
8378 | if (do_checks && section->sh_size == 0) | |
8379 | warn (_("Section '%s': has a size of zero - is this intended ?\n"), name); | |
8380 | break; | |
8381 | ||
8382 | default: | |
8383 | break; | |
8384 | } | |
8385 | ||
8386 | if ((do_debugging || do_debug_info || do_debug_abbrevs | |
8387 | || do_debug_lines || do_debug_pubnames || do_debug_pubtypes | |
8388 | || do_debug_aranges || do_debug_frames || do_debug_macinfo | |
8389 | || do_debug_str || do_debug_str_offsets || do_debug_loc | |
8390 | || do_debug_ranges | |
8391 | || do_debug_addr || do_debug_cu_index || do_debug_links) | |
8392 | && (startswith (name, ".debug_") | |
8393 | || startswith (name, ".zdebug_"))) | |
8394 | { | |
8395 | if (name[1] == 'z') | |
8396 | name += sizeof (".zdebug_") - 1; | |
8397 | else | |
8398 | name += sizeof (".debug_") - 1; | |
8399 | ||
8400 | if (do_debugging | |
8401 | || (do_debug_info && startswith (name, "info")) | |
8402 | || (do_debug_info && startswith (name, "types")) | |
8403 | || (do_debug_abbrevs && startswith (name, "abbrev")) | |
8404 | || (do_debug_lines && strcmp (name, "line") == 0) | |
8405 | || (do_debug_lines && startswith (name, "line.")) | |
8406 | || (do_debug_pubnames && startswith (name, "pubnames")) | |
8407 | || (do_debug_pubtypes && startswith (name, "pubtypes")) | |
8408 | || (do_debug_pubnames && startswith (name, "gnu_pubnames")) | |
8409 | || (do_debug_pubtypes && startswith (name, "gnu_pubtypes")) | |
8410 | || (do_debug_aranges && startswith (name, "aranges")) | |
8411 | || (do_debug_ranges && startswith (name, "ranges")) | |
8412 | || (do_debug_ranges && startswith (name, "rnglists")) | |
8413 | || (do_debug_frames && startswith (name, "frame")) | |
8414 | || (do_debug_macinfo && startswith (name, "macinfo")) | |
8415 | || (do_debug_macinfo && startswith (name, "macro")) | |
8416 | || (do_debug_str && startswith (name, "str")) | |
8417 | || (do_debug_links && startswith (name, "sup")) | |
8418 | || (do_debug_str_offsets && startswith (name, "str_offsets")) | |
8419 | || (do_debug_loc && startswith (name, "loc")) | |
8420 | || (do_debug_loc && startswith (name, "loclists")) | |
8421 | || (do_debug_addr && startswith (name, "addr")) | |
8422 | || (do_debug_cu_index && startswith (name, "cu_index")) | |
8423 | || (do_debug_cu_index && startswith (name, "tu_index")) | |
8424 | ) | |
8425 | request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP); | |
8426 | } | |
8427 | /* Linkonce section to be combined with .debug_info at link time. */ | |
8428 | else if ((do_debugging || do_debug_info) | |
8429 | && startswith (name, ".gnu.linkonce.wi.")) | |
8430 | request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP); | |
8431 | else if (do_debug_frames && streq (name, ".eh_frame")) | |
8432 | request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP); | |
8433 | else if (do_debug_frames && streq (name, ".eh_frame_hdr")) | |
8434 | request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP); | |
8435 | else if (do_gdb_index && (streq (name, ".gdb_index") | |
8436 | || streq (name, ".debug_names"))) | |
8437 | request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP); | |
8438 | /* Trace sections for Itanium VMS. */ | |
8439 | else if ((do_debugging || do_trace_info || do_trace_abbrevs | |
8440 | || do_trace_aranges) | |
8441 | && startswith (name, ".trace_")) | |
8442 | { | |
8443 | name += sizeof (".trace_") - 1; | |
8444 | ||
8445 | if (do_debugging | |
8446 | || (do_trace_info && streq (name, "info")) | |
8447 | || (do_trace_abbrevs && streq (name, "abbrev")) | |
8448 | || (do_trace_aranges && streq (name, "aranges")) | |
8449 | ) | |
8450 | request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP); | |
8451 | } | |
8452 | else if ((do_debugging || do_debug_links) | |
8453 | && (startswith (name, ".gnu_debuglink") | |
8454 | || startswith (name, ".gnu_debugaltlink"))) | |
8455 | request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP); | |
8456 | } | |
8457 | ||
8458 | if (! do_sections) | |
8459 | return true; | |
8460 | ||
8461 | if (filedata->is_separate && ! process_links) | |
8462 | return true; | |
8463 | ||
8464 | if (filedata->is_separate) | |
8465 | printf (_("\nSection Headers in linked file '%s':\n"), | |
8466 | printable_string (filedata->file_name, 0)); | |
8467 | else if (filedata->file_header.e_shnum > 1) | |
8468 | printf (_("\nSection Headers:\n")); | |
8469 | else | |
8470 | printf (_("\nSection Header:\n")); | |
8471 | ||
8472 | if (is_32bit_elf) | |
8473 | { | |
8474 | if (do_section_details) | |
8475 | { | |
8476 | printf (_(" [Nr] Name\n")); | |
8477 | printf (_(" Type Addr Off Size ES Lk Inf Al\n")); | |
8478 | } | |
8479 | else | |
8480 | printf | |
8481 | (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n")); | |
8482 | } | |
8483 | else if (do_wide) | |
8484 | { | |
8485 | if (do_section_details) | |
8486 | { | |
8487 | printf (_(" [Nr] Name\n")); | |
8488 | printf (_(" Type Address Off Size ES Lk Inf Al\n")); | |
8489 | } | |
8490 | else | |
8491 | printf | |
8492 | (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n")); | |
8493 | } | |
8494 | else | |
8495 | { | |
8496 | if (do_section_details) | |
8497 | { | |
8498 | printf (_(" [Nr] Name\n")); | |
8499 | printf (_(" Type Address Offset Link\n")); | |
8500 | printf (_(" Size EntSize Info Align\n")); | |
8501 | } | |
8502 | else | |
8503 | { | |
8504 | printf (_(" [Nr] Name Type Address Offset\n")); | |
8505 | printf (_(" Size EntSize Flags Link Info Align\n")); | |
8506 | } | |
8507 | } | |
8508 | ||
8509 | if (do_section_details) | |
8510 | printf (_(" Flags\n")); | |
8511 | ||
8512 | for (i = 0, section = filedata->section_headers; | |
8513 | i < filedata->file_header.e_shnum; | |
8514 | i++, section++) | |
8515 | { | |
8516 | /* Run some sanity checks on the section header. */ | |
8517 | ||
8518 | /* Check the sh_link field. */ | |
8519 | switch (section->sh_type) | |
8520 | { | |
8521 | case SHT_REL: | |
8522 | case SHT_RELR: | |
8523 | case SHT_RELA: | |
8524 | if (section->sh_link == 0 | |
8525 | && (filedata->file_header.e_type == ET_EXEC | |
8526 | || filedata->file_header.e_type == ET_DYN)) | |
8527 | /* A dynamic relocation section where all entries use a | |
8528 | zero symbol index need not specify a symtab section. */ | |
8529 | break; | |
8530 | /* Fall through. */ | |
8531 | case SHT_SYMTAB_SHNDX: | |
8532 | case SHT_GROUP: | |
8533 | case SHT_HASH: | |
8534 | case SHT_GNU_HASH: | |
8535 | case SHT_GNU_versym: | |
8536 | if (section->sh_link == 0 | |
8537 | || section->sh_link >= filedata->file_header.e_shnum | |
8538 | || (filedata->section_headers[section->sh_link].sh_type != SHT_SYMTAB | |
8539 | && filedata->section_headers[section->sh_link].sh_type != SHT_DYNSYM)) | |
8540 | warn (_("[%2u]: Link field (%u) should index a symtab section.\n"), | |
8541 | i, section->sh_link); | |
8542 | break; | |
8543 | ||
8544 | case SHT_DYNAMIC: | |
8545 | case SHT_SYMTAB: | |
8546 | case SHT_DYNSYM: | |
8547 | case SHT_GNU_verneed: | |
8548 | case SHT_GNU_verdef: | |
8549 | case SHT_GNU_LIBLIST: | |
8550 | if (section->sh_link == 0 | |
8551 | || section->sh_link >= filedata->file_header.e_shnum | |
8552 | || filedata->section_headers[section->sh_link].sh_type != SHT_STRTAB) | |
8553 | warn (_("[%2u]: Link field (%u) should index a string section.\n"), | |
8554 | i, section->sh_link); | |
8555 | break; | |
8556 | ||
8557 | case SHT_INIT_ARRAY: | |
8558 | case SHT_FINI_ARRAY: | |
8559 | case SHT_PREINIT_ARRAY: | |
8560 | if (section->sh_type < SHT_LOOS && section->sh_link != 0) | |
8561 | warn (_("[%2u]: Unexpected value (%u) in link field.\n"), | |
8562 | i, section->sh_link); | |
8563 | break; | |
8564 | ||
8565 | default: | |
8566 | /* FIXME: Add support for target specific section types. */ | |
8567 | #if 0 /* Currently we do not check other section types as there are too | |
8568 | many special cases. Stab sections for example have a type | |
8569 | of SHT_PROGBITS but an sh_link field that links to the .stabstr | |
8570 | section. */ | |
8571 | if (section->sh_type < SHT_LOOS && section->sh_link != 0) | |
8572 | warn (_("[%2u]: Unexpected value (%u) in link field.\n"), | |
8573 | i, section->sh_link); | |
8574 | #endif | |
8575 | break; | |
8576 | } | |
8577 | ||
8578 | /* Check the sh_info field. */ | |
8579 | switch (section->sh_type) | |
8580 | { | |
8581 | case SHT_REL: | |
8582 | case SHT_RELA: | |
8583 | if (section->sh_info == 0 | |
8584 | && (filedata->file_header.e_type == ET_EXEC | |
8585 | || filedata->file_header.e_type == ET_DYN)) | |
8586 | /* Dynamic relocations apply to segments, so they do not | |
8587 | need to specify the section they relocate. */ | |
8588 | break; | |
8589 | if (section->sh_info == 0 | |
8590 | || section->sh_info >= filedata->file_header.e_shnum | |
8591 | || (filedata->section_headers[section->sh_info].sh_type != SHT_PROGBITS | |
8592 | && filedata->section_headers[section->sh_info].sh_type != SHT_NOBITS | |
8593 | && filedata->section_headers[section->sh_info].sh_type != SHT_NOTE | |
8594 | && filedata->section_headers[section->sh_info].sh_type != SHT_INIT_ARRAY | |
8595 | && filedata->section_headers[section->sh_info].sh_type != SHT_FINI_ARRAY | |
8596 | && filedata->section_headers[section->sh_info].sh_type != SHT_PREINIT_ARRAY | |
8597 | /* FIXME: Are other section types valid ? */ | |
8598 | && filedata->section_headers[section->sh_info].sh_type < SHT_LOOS)) | |
8599 | warn (_("[%2u]: Info field (%u) should index a relocatable section.\n"), | |
8600 | i, section->sh_info); | |
8601 | break; | |
8602 | ||
8603 | case SHT_DYNAMIC: | |
8604 | case SHT_HASH: | |
8605 | case SHT_SYMTAB_SHNDX: | |
8606 | case SHT_INIT_ARRAY: | |
8607 | case SHT_FINI_ARRAY: | |
8608 | case SHT_PREINIT_ARRAY: | |
8609 | if (section->sh_info != 0) | |
8610 | warn (_("[%2u]: Unexpected value (%u) in info field.\n"), | |
8611 | i, section->sh_info); | |
8612 | break; | |
8613 | ||
8614 | case SHT_GROUP: | |
8615 | case SHT_SYMTAB: | |
8616 | case SHT_DYNSYM: | |
8617 | /* A symbol index - we assume that it is valid. */ | |
8618 | break; | |
8619 | ||
8620 | default: | |
8621 | /* FIXME: Add support for target specific section types. */ | |
8622 | if (section->sh_type == SHT_NOBITS) | |
8623 | /* NOBITS section headers with non-zero sh_info fields can be | |
8624 | created when a binary is stripped of everything but its debug | |
8625 | information. The stripped sections have their headers | |
8626 | preserved but their types set to SHT_NOBITS. So do not check | |
8627 | this type of section. */ | |
8628 | ; | |
8629 | else if (section->sh_flags & SHF_INFO_LINK) | |
8630 | { | |
8631 | if (section->sh_info < 1 || section->sh_info >= filedata->file_header.e_shnum) | |
8632 | warn (_("[%2u]: Expected link to another section in info field"), i); | |
8633 | } | |
8634 | else if (section->sh_type < SHT_LOOS | |
8635 | && (section->sh_flags & SHF_GNU_MBIND) == 0 | |
8636 | && section->sh_info != 0) | |
8637 | warn (_("[%2u]: Unexpected value (%u) in info field.\n"), | |
8638 | i, section->sh_info); | |
8639 | break; | |
8640 | } | |
8641 | ||
8642 | /* Check the sh_size field. */ | |
8643 | if (section->sh_size > filedata->file_size | |
8644 | && section->sh_type != SHT_NOBITS | |
8645 | && section->sh_type != SHT_NULL | |
8646 | && section->sh_type < SHT_LOOS) | |
8647 | warn (_("Size of section %u is larger than the entire file!\n"), i); | |
8648 | ||
8649 | printf (" [%2u] ", i); | |
8650 | if (do_section_details) | |
8651 | printf ("%s\n ", printable_section_name (filedata, section)); | |
8652 | else | |
8653 | print_symbol_name (-17, printable_section_name (filedata, section)); | |
8654 | ||
8655 | printf (do_wide ? " %-15s " : " %-15.15s ", | |
8656 | get_section_type_name (filedata, section->sh_type)); | |
8657 | ||
8658 | if (is_32bit_elf) | |
8659 | { | |
8660 | const char * link_too_big = NULL; | |
8661 | ||
8662 | print_vma (section->sh_addr, LONG_HEX); | |
8663 | ||
8664 | printf ( " %6.6lx %6.6lx %2.2lx", | |
8665 | (unsigned long) section->sh_offset, | |
8666 | (unsigned long) section->sh_size, | |
8667 | (unsigned long) section->sh_entsize); | |
8668 | ||
8669 | if (do_section_details) | |
8670 | fputs (" ", stdout); | |
8671 | else | |
8672 | printf (" %3s ", get_elf_section_flags (filedata, section->sh_flags)); | |
8673 | ||
8674 | if (section->sh_link >= filedata->file_header.e_shnum) | |
8675 | { | |
8676 | link_too_big = ""; | |
8677 | /* The sh_link value is out of range. Normally this indicates | |
8678 | an error but it can have special values in Solaris binaries. */ | |
8679 | switch (filedata->file_header.e_machine) | |
8680 | { | |
8681 | case EM_386: | |
8682 | case EM_IAMCU: | |
8683 | case EM_X86_64: | |
8684 | case EM_L1OM: | |
8685 | case EM_K1OM: | |
8686 | case EM_OLD_SPARCV9: | |
8687 | case EM_SPARC32PLUS: | |
8688 | case EM_SPARCV9: | |
8689 | case EM_SPARC: | |
8690 | if (section->sh_link == (SHN_BEFORE & 0xffff)) | |
8691 | link_too_big = "BEFORE"; | |
8692 | else if (section->sh_link == (SHN_AFTER & 0xffff)) | |
8693 | link_too_big = "AFTER"; | |
8694 | break; | |
8695 | default: | |
8696 | break; | |
8697 | } | |
8698 | } | |
8699 | ||
8700 | if (do_section_details) | |
8701 | { | |
8702 | if (link_too_big != NULL && * link_too_big) | |
8703 | printf ("<%s> ", link_too_big); | |
8704 | else | |
8705 | printf ("%2u ", section->sh_link); | |
8706 | printf ("%3u %2lu\n", section->sh_info, | |
8707 | (unsigned long) section->sh_addralign); | |
8708 | } | |
8709 | else | |
8710 | printf ("%2u %3u %2lu\n", | |
8711 | section->sh_link, | |
8712 | section->sh_info, | |
8713 | (unsigned long) section->sh_addralign); | |
8714 | ||
8715 | if (link_too_big && ! * link_too_big) | |
8716 | warn (_("section %u: sh_link value of %u is larger than the number of sections\n"), | |
8717 | i, section->sh_link); | |
8718 | } | |
8719 | else if (do_wide) | |
8720 | { | |
8721 | print_vma (section->sh_addr, LONG_HEX); | |
8722 | ||
8723 | if ((long) section->sh_offset == section->sh_offset) | |
8724 | printf (" %6.6lx", (unsigned long) section->sh_offset); | |
8725 | else | |
8726 | { | |
8727 | putchar (' '); | |
8728 | print_vma (section->sh_offset, LONG_HEX); | |
8729 | } | |
8730 | ||
8731 | if ((unsigned long) section->sh_size == section->sh_size) | |
8732 | printf (" %6.6lx", (unsigned long) section->sh_size); | |
8733 | else | |
8734 | { | |
8735 | putchar (' '); | |
8736 | print_vma (section->sh_size, LONG_HEX); | |
8737 | } | |
8738 | ||
8739 | if ((unsigned long) section->sh_entsize == section->sh_entsize) | |
8740 | printf (" %2.2lx", (unsigned long) section->sh_entsize); | |
8741 | else | |
8742 | { | |
8743 | putchar (' '); | |
8744 | print_vma (section->sh_entsize, LONG_HEX); | |
8745 | } | |
8746 | ||
8747 | if (do_section_details) | |
8748 | fputs (" ", stdout); | |
8749 | else | |
8750 | printf (" %3s ", get_elf_section_flags (filedata, section->sh_flags)); | |
8751 | ||
8752 | printf ("%2u %3u ", section->sh_link, section->sh_info); | |
8753 | ||
8754 | if ((unsigned long) section->sh_addralign == section->sh_addralign) | |
8755 | printf ("%2lu\n", (unsigned long) section->sh_addralign); | |
8756 | else | |
8757 | { | |
8758 | print_vma (section->sh_addralign, DEC); | |
8759 | putchar ('\n'); | |
8760 | } | |
8761 | } | |
8762 | else if (do_section_details) | |
8763 | { | |
8764 | putchar (' '); | |
8765 | print_vma (section->sh_addr, LONG_HEX); | |
8766 | if ((long) section->sh_offset == section->sh_offset) | |
8767 | printf (" %16.16lx", (unsigned long) section->sh_offset); | |
8768 | else | |
8769 | { | |
8770 | printf (" "); | |
8771 | print_vma (section->sh_offset, LONG_HEX); | |
8772 | } | |
8773 | printf (" %u\n ", section->sh_link); | |
8774 | print_vma (section->sh_size, LONG_HEX); | |
8775 | putchar (' '); | |
8776 | print_vma (section->sh_entsize, LONG_HEX); | |
8777 | ||
8778 | printf (" %-16u %lu\n", | |
8779 | section->sh_info, | |
8780 | (unsigned long) section->sh_addralign); | |
8781 | } | |
8782 | else | |
8783 | { | |
8784 | putchar (' '); | |
8785 | print_vma (section->sh_addr, LONG_HEX); | |
8786 | if ((long) section->sh_offset == section->sh_offset) | |
8787 | printf (" %8.8lx", (unsigned long) section->sh_offset); | |
8788 | else | |
8789 | { | |
8790 | printf (" "); | |
8791 | print_vma (section->sh_offset, LONG_HEX); | |
8792 | } | |
8793 | printf ("\n "); | |
8794 | print_vma (section->sh_size, LONG_HEX); | |
8795 | printf (" "); | |
8796 | print_vma (section->sh_entsize, LONG_HEX); | |
8797 | ||
8798 | printf (" %3s ", get_elf_section_flags (filedata, section->sh_flags)); | |
8799 | ||
8800 | printf (" %2u %3u %lu\n", | |
8801 | section->sh_link, | |
8802 | section->sh_info, | |
8803 | (unsigned long) section->sh_addralign); | |
8804 | } | |
8805 | ||
8806 | if (do_section_details) | |
8807 | { | |
8808 | printf (" %s\n", get_elf_section_flags (filedata, section->sh_flags)); | |
8809 | if ((section->sh_flags & SHF_COMPRESSED) != 0) | |
8810 | { | |
8811 | /* Minimum section size is 12 bytes for 32-bit compression | |
8812 | header + 12 bytes for compressed data header. */ | |
8813 | unsigned char buf[24]; | |
8814 | ||
8815 | assert (sizeof (buf) >= sizeof (Elf64_External_Chdr)); | |
8816 | if (get_data (&buf, filedata, section->sh_offset, 1, | |
8817 | sizeof (buf), _("compression header"))) | |
8818 | { | |
8819 | Elf_Internal_Chdr chdr; | |
8820 | ||
8821 | if (get_compression_header (&chdr, buf, sizeof (buf)) == 0) | |
8822 | printf (_(" [<corrupt>]\n")); | |
8823 | else | |
8824 | { | |
8825 | if (chdr.ch_type == ch_compress_zlib) | |
8826 | printf (" ZLIB, "); | |
8827 | else if (chdr.ch_type == ch_compress_zstd) | |
8828 | printf (" ZSTD, "); | |
8829 | else | |
8830 | printf (_(" [<unknown>: 0x%x], "), | |
8831 | chdr.ch_type); | |
8832 | print_vma (chdr.ch_size, LONG_HEX); | |
8833 | printf (", %lu\n", (unsigned long) chdr.ch_addralign); | |
8834 | } | |
8835 | } | |
8836 | } | |
8837 | } | |
8838 | } | |
8839 | ||
8840 | if (!do_section_details) | |
8841 | { | |
8842 | /* The ordering of the letters shown here matches the ordering of the | |
8843 | corresponding SHF_xxx values, and hence the order in which these | |
8844 | letters will be displayed to the user. */ | |
8845 | printf (_("Key to Flags:\n\ | |
8846 | W (write), A (alloc), X (execute), M (merge), S (strings), I (info),\n\ | |
8847 | L (link order), O (extra OS processing required), G (group), T (TLS),\n\ | |
8848 | C (compressed), x (unknown), o (OS specific), E (exclude),\n ")); | |
8849 | switch (filedata->file_header.e_ident[EI_OSABI]) | |
8850 | { | |
8851 | case ELFOSABI_GNU: | |
8852 | case ELFOSABI_FREEBSD: | |
8853 | printf (_("R (retain), ")); | |
8854 | /* Fall through */ | |
8855 | case ELFOSABI_NONE: | |
8856 | printf (_("D (mbind), ")); | |
8857 | break; | |
8858 | default: | |
8859 | break; | |
8860 | } | |
8861 | if (filedata->file_header.e_machine == EM_X86_64 | |
8862 | || filedata->file_header.e_machine == EM_L1OM | |
8863 | || filedata->file_header.e_machine == EM_K1OM) | |
8864 | printf (_("l (large), ")); | |
8865 | else if (filedata->file_header.e_machine == EM_ARM) | |
8866 | printf (_("y (purecode), ")); | |
8867 | else if (filedata->file_header.e_machine == EM_PPC) | |
8868 | printf (_("v (VLE), ")); | |
8869 | printf ("p (processor specific)\n"); | |
8870 | } | |
8871 | ||
8872 | return true; | |
8873 | } | |
8874 | ||
8875 | static bool | |
8876 | get_symtab (Filedata * filedata, | |
8877 | Elf_Internal_Shdr * symsec, | |
8878 | Elf_Internal_Sym ** symtab, | |
8879 | uint64_t * nsyms, | |
8880 | char ** strtab, | |
8881 | uint64_t * strtablen) | |
8882 | { | |
8883 | *strtab = NULL; | |
8884 | *strtablen = 0; | |
8885 | *symtab = get_elf_symbols (filedata, symsec, nsyms); | |
8886 | ||
8887 | if (*symtab == NULL) | |
8888 | return false; | |
8889 | ||
8890 | if (symsec->sh_link != 0) | |
8891 | { | |
8892 | Elf_Internal_Shdr *strsec; | |
8893 | ||
8894 | if (symsec->sh_link >= filedata->file_header.e_shnum) | |
8895 | { | |
8896 | error (_("Bad sh_link in symbol table section\n")); | |
8897 | free (*symtab); | |
8898 | *symtab = NULL; | |
8899 | *nsyms = 0; | |
8900 | return false; | |
8901 | } | |
8902 | ||
8903 | strsec = filedata->section_headers + symsec->sh_link; | |
8904 | ||
8905 | *strtab = (char *) get_data (NULL, filedata, strsec->sh_offset, | |
8906 | 1, strsec->sh_size, _("string table")); | |
8907 | if (*strtab == NULL) | |
8908 | { | |
8909 | free (*symtab); | |
8910 | *symtab = NULL; | |
8911 | *nsyms = 0; | |
8912 | return false; | |
8913 | } | |
8914 | *strtablen = strsec->sh_size; | |
8915 | } | |
8916 | return true; | |
8917 | } | |
8918 | ||
8919 | static const char * | |
8920 | get_group_flags (unsigned int flags) | |
8921 | { | |
8922 | static char buff[128]; | |
8923 | ||
8924 | if (flags == 0) | |
8925 | return ""; | |
8926 | else if (flags == GRP_COMDAT) | |
8927 | return "COMDAT "; | |
8928 | ||
8929 | snprintf (buff, sizeof buff, "[0x%x: %s%s%s]", | |
8930 | flags, | |
8931 | flags & GRP_MASKOS ? _("<OS specific>") : "", | |
8932 | flags & GRP_MASKPROC ? _("<PROC specific>") : "", | |
8933 | (flags & ~(GRP_COMDAT | GRP_MASKOS | GRP_MASKPROC) | |
8934 | ? _("<unknown>") : "")); | |
8935 | ||
8936 | return buff; | |
8937 | } | |
8938 | ||
8939 | static bool | |
8940 | process_section_groups (Filedata * filedata) | |
8941 | { | |
8942 | Elf_Internal_Shdr * section; | |
8943 | unsigned int i; | |
8944 | struct group * group; | |
8945 | Elf_Internal_Shdr * symtab_sec; | |
8946 | Elf_Internal_Shdr * strtab_sec; | |
8947 | Elf_Internal_Sym * symtab; | |
8948 | uint64_t num_syms; | |
8949 | char * strtab; | |
8950 | size_t strtab_size; | |
8951 | ||
8952 | /* Don't process section groups unless needed. */ | |
8953 | if (!do_unwind && !do_section_groups) | |
8954 | return true; | |
8955 | ||
8956 | if (filedata->file_header.e_shnum == 0) | |
8957 | { | |
8958 | if (do_section_groups) | |
8959 | { | |
8960 | if (filedata->is_separate) | |
8961 | printf (_("\nThere are no sections group in linked file '%s'.\n"), | |
8962 | printable_string (filedata->file_name, 0)); | |
8963 | else | |
8964 | printf (_("\nThere are no section groups in this file.\n")); | |
8965 | } | |
8966 | return true; | |
8967 | } | |
8968 | ||
8969 | if (filedata->section_headers == NULL) | |
8970 | { | |
8971 | error (_("Section headers are not available!\n")); | |
8972 | /* PR 13622: This can happen with a corrupt ELF header. */ | |
8973 | return false; | |
8974 | } | |
8975 | ||
8976 | filedata->section_headers_groups | |
8977 | = (struct group **) calloc (filedata->file_header.e_shnum, | |
8978 | sizeof (struct group *)); | |
8979 | ||
8980 | if (filedata->section_headers_groups == NULL) | |
8981 | { | |
8982 | error (_("Out of memory reading %u section group headers\n"), | |
8983 | filedata->file_header.e_shnum); | |
8984 | return false; | |
8985 | } | |
8986 | ||
8987 | /* Scan the sections for the group section. */ | |
8988 | filedata->group_count = 0; | |
8989 | for (i = 0, section = filedata->section_headers; | |
8990 | i < filedata->file_header.e_shnum; | |
8991 | i++, section++) | |
8992 | if (section->sh_type == SHT_GROUP) | |
8993 | filedata->group_count++; | |
8994 | ||
8995 | if (filedata->group_count == 0) | |
8996 | { | |
8997 | if (do_section_groups) | |
8998 | { | |
8999 | if (filedata->is_separate) | |
9000 | printf (_("\nThere are no section groups in linked file '%s'.\n"), | |
9001 | printable_string (filedata->file_name, 0)); | |
9002 | else | |
9003 | printf (_("\nThere are no section groups in this file.\n")); | |
9004 | } | |
9005 | ||
9006 | return true; | |
9007 | } | |
9008 | ||
9009 | filedata->section_groups = (struct group *) calloc (filedata->group_count, | |
9010 | sizeof (struct group)); | |
9011 | ||
9012 | if (filedata->section_groups == NULL) | |
9013 | { | |
9014 | error (_("Out of memory reading %zu groups\n"), filedata->group_count); | |
9015 | return false; | |
9016 | } | |
9017 | ||
9018 | symtab_sec = NULL; | |
9019 | strtab_sec = NULL; | |
9020 | symtab = NULL; | |
9021 | num_syms = 0; | |
9022 | strtab = NULL; | |
9023 | strtab_size = 0; | |
9024 | ||
9025 | if (filedata->is_separate) | |
9026 | printf (_("Section groups in linked file '%s'\n"), | |
9027 | printable_string (filedata->file_name, 0)); | |
9028 | ||
9029 | for (i = 0, section = filedata->section_headers, group = filedata->section_groups; | |
9030 | i < filedata->file_header.e_shnum; | |
9031 | i++, section++) | |
9032 | { | |
9033 | if (section->sh_type == SHT_GROUP) | |
9034 | { | |
9035 | const char * name = printable_section_name (filedata, section); | |
9036 | const char * group_name; | |
9037 | unsigned char * start; | |
9038 | unsigned char * indices; | |
9039 | unsigned int entry, j, size; | |
9040 | Elf_Internal_Shdr * sec; | |
9041 | Elf_Internal_Sym * sym; | |
9042 | ||
9043 | /* Get the symbol table. */ | |
9044 | if (section->sh_link >= filedata->file_header.e_shnum | |
9045 | || ((sec = filedata->section_headers + section->sh_link)->sh_type | |
9046 | != SHT_SYMTAB)) | |
9047 | { | |
9048 | error (_("Bad sh_link in group section `%s'\n"), name); | |
9049 | continue; | |
9050 | } | |
9051 | ||
9052 | if (symtab_sec != sec) | |
9053 | { | |
9054 | symtab_sec = sec; | |
9055 | free (symtab); | |
9056 | symtab = get_elf_symbols (filedata, symtab_sec, & num_syms); | |
9057 | } | |
9058 | ||
9059 | if (symtab == NULL) | |
9060 | { | |
9061 | error (_("Corrupt header in group section `%s'\n"), name); | |
9062 | continue; | |
9063 | } | |
9064 | ||
9065 | if (section->sh_info >= num_syms) | |
9066 | { | |
9067 | error (_("Bad sh_info in group section `%s'\n"), name); | |
9068 | continue; | |
9069 | } | |
9070 | ||
9071 | sym = symtab + section->sh_info; | |
9072 | ||
9073 | if (ELF_ST_TYPE (sym->st_info) == STT_SECTION) | |
9074 | { | |
9075 | if (sym->st_shndx == 0 | |
9076 | || sym->st_shndx >= filedata->file_header.e_shnum) | |
9077 | { | |
9078 | error (_("Bad sh_info in group section `%s'\n"), name); | |
9079 | continue; | |
9080 | } | |
9081 | ||
9082 | group_name = printable_section_name (filedata, | |
9083 | filedata->section_headers | |
9084 | + sym->st_shndx); | |
9085 | strtab_sec = NULL; | |
9086 | free (strtab); | |
9087 | strtab = NULL; | |
9088 | strtab_size = 0; | |
9089 | } | |
9090 | else | |
9091 | { | |
9092 | /* Get the string table. */ | |
9093 | if (symtab_sec->sh_link >= filedata->file_header.e_shnum) | |
9094 | { | |
9095 | strtab_sec = NULL; | |
9096 | free (strtab); | |
9097 | strtab = NULL; | |
9098 | strtab_size = 0; | |
9099 | } | |
9100 | else if (strtab_sec | |
9101 | != (sec = filedata->section_headers + symtab_sec->sh_link)) | |
9102 | { | |
9103 | strtab_sec = sec; | |
9104 | free (strtab); | |
9105 | ||
9106 | strtab = (char *) get_data (NULL, filedata, strtab_sec->sh_offset, | |
9107 | 1, strtab_sec->sh_size, | |
9108 | _("string table")); | |
9109 | strtab_size = strtab != NULL ? strtab_sec->sh_size : 0; | |
9110 | } | |
9111 | group_name = sym->st_name < strtab_size | |
9112 | ? strtab + sym->st_name : _("<corrupt>"); | |
9113 | } | |
9114 | ||
9115 | /* PR 17531: file: loop. */ | |
9116 | if (section->sh_entsize > section->sh_size) | |
9117 | { | |
9118 | error (_("Section %s has sh_entsize (%#" PRIx64 ")" | |
9119 | " which is larger than its size (%#" PRIx64 ")\n"), | |
9120 | printable_section_name (filedata, section), | |
9121 | section->sh_entsize, | |
9122 | section->sh_size); | |
9123 | continue; | |
9124 | } | |
9125 | ||
9126 | start = (unsigned char *) get_data (NULL, filedata, section->sh_offset, | |
9127 | 1, section->sh_size, | |
9128 | _("section data")); | |
9129 | if (start == NULL) | |
9130 | continue; | |
9131 | ||
9132 | indices = start; | |
9133 | size = (section->sh_size / section->sh_entsize) - 1; | |
9134 | entry = byte_get (indices, 4); | |
9135 | indices += 4; | |
9136 | ||
9137 | if (do_section_groups) | |
9138 | { | |
9139 | printf (_("\n%sgroup section [%5u] `%s' [%s] contains %u sections:\n"), | |
9140 | get_group_flags (entry), i, name, group_name, size); | |
9141 | ||
9142 | printf (_(" [Index] Name\n")); | |
9143 | } | |
9144 | ||
9145 | group->group_index = i; | |
9146 | ||
9147 | for (j = 0; j < size; j++) | |
9148 | { | |
9149 | struct group_list * g; | |
9150 | ||
9151 | entry = byte_get (indices, 4); | |
9152 | indices += 4; | |
9153 | ||
9154 | if (entry >= filedata->file_header.e_shnum) | |
9155 | { | |
9156 | static unsigned num_group_errors = 0; | |
9157 | ||
9158 | if (num_group_errors ++ < 10) | |
9159 | { | |
9160 | error (_("section [%5u] in group section [%5u] > maximum section [%5u]\n"), | |
9161 | entry, i, filedata->file_header.e_shnum - 1); | |
9162 | if (num_group_errors == 10) | |
9163 | warn (_("Further error messages about overlarge group section indices suppressed\n")); | |
9164 | } | |
9165 | continue; | |
9166 | } | |
9167 | ||
9168 | if (filedata->section_headers_groups [entry] != NULL) | |
9169 | { | |
9170 | if (entry) | |
9171 | { | |
9172 | static unsigned num_errs = 0; | |
9173 | ||
9174 | if (num_errs ++ < 10) | |
9175 | { | |
9176 | error (_("section [%5u] in group section [%5u] already in group section [%5u]\n"), | |
9177 | entry, i, | |
9178 | filedata->section_headers_groups [entry]->group_index); | |
9179 | if (num_errs == 10) | |
9180 | warn (_("Further error messages about already contained group sections suppressed\n")); | |
9181 | } | |
9182 | continue; | |
9183 | } | |
9184 | else | |
9185 | { | |
9186 | /* Intel C/C++ compiler may put section 0 in a | |
9187 | section group. We just warn it the first time | |
9188 | and ignore it afterwards. */ | |
9189 | static bool warned = false; | |
9190 | if (!warned) | |
9191 | { | |
9192 | error (_("section 0 in group section [%5u]\n"), | |
9193 | filedata->section_headers_groups [entry]->group_index); | |
9194 | warned = true; | |
9195 | } | |
9196 | } | |
9197 | } | |
9198 | ||
9199 | filedata->section_headers_groups [entry] = group; | |
9200 | ||
9201 | if (do_section_groups) | |
9202 | { | |
9203 | sec = filedata->section_headers + entry; | |
9204 | printf (" [%5u] %s\n", entry, printable_section_name (filedata, sec)); | |
9205 | } | |
9206 | ||
9207 | g = (struct group_list *) xmalloc (sizeof (struct group_list)); | |
9208 | g->section_index = entry; | |
9209 | g->next = group->root; | |
9210 | group->root = g; | |
9211 | } | |
9212 | ||
9213 | free (start); | |
9214 | ||
9215 | group++; | |
9216 | } | |
9217 | } | |
9218 | ||
9219 | free (symtab); | |
9220 | free (strtab); | |
9221 | return true; | |
9222 | } | |
9223 | ||
9224 | /* Data used to display dynamic fixups. */ | |
9225 | ||
9226 | struct ia64_vms_dynfixup | |
9227 | { | |
9228 | uint64_t needed_ident; /* Library ident number. */ | |
9229 | uint64_t needed; /* Index in the dstrtab of the library name. */ | |
9230 | uint64_t fixup_needed; /* Index of the library. */ | |
9231 | uint64_t fixup_rela_cnt; /* Number of fixups. */ | |
9232 | uint64_t fixup_rela_off; /* Fixups offset in the dynamic segment. */ | |
9233 | }; | |
9234 | ||
9235 | /* Data used to display dynamic relocations. */ | |
9236 | ||
9237 | struct ia64_vms_dynimgrela | |
9238 | { | |
9239 | uint64_t img_rela_cnt; /* Number of relocations. */ | |
9240 | uint64_t img_rela_off; /* Reloc offset in the dynamic segment. */ | |
9241 | }; | |
9242 | ||
9243 | /* Display IA-64 OpenVMS dynamic fixups (used to dynamically link a shared | |
9244 | library). */ | |
9245 | ||
9246 | static bool | |
9247 | dump_ia64_vms_dynamic_fixups (Filedata * filedata, | |
9248 | struct ia64_vms_dynfixup * fixup, | |
9249 | const char * strtab, | |
9250 | unsigned int strtab_sz) | |
9251 | { | |
9252 | Elf64_External_VMS_IMAGE_FIXUP * imfs; | |
9253 | size_t i; | |
9254 | const char * lib_name; | |
9255 | ||
9256 | imfs = get_data (NULL, filedata, | |
9257 | filedata->dynamic_addr + fixup->fixup_rela_off, | |
9258 | sizeof (*imfs), fixup->fixup_rela_cnt, | |
9259 | _("dynamic section image fixups")); | |
9260 | if (!imfs) | |
9261 | return false; | |
9262 | ||
9263 | if (fixup->needed < strtab_sz) | |
9264 | lib_name = strtab + fixup->needed; | |
9265 | else | |
9266 | { | |
9267 | warn (_("corrupt library name index of %#" PRIx64 | |
9268 | " found in dynamic entry"), fixup->needed); | |
9269 | lib_name = "???"; | |
9270 | } | |
9271 | ||
9272 | printf (_("\nImage fixups for needed library #%" PRId64 | |
9273 | ": %s - ident: %" PRIx64 "\n"), | |
9274 | fixup->fixup_needed, lib_name, fixup->needed_ident); | |
9275 | printf | |
9276 | (_("Seg Offset Type SymVec DataType\n")); | |
9277 | ||
9278 | for (i = 0; i < (size_t) fixup->fixup_rela_cnt; i++) | |
9279 | { | |
9280 | unsigned int type; | |
9281 | const char *rtype; | |
9282 | ||
9283 | printf ("%3u ", (unsigned) BYTE_GET (imfs [i].fixup_seg)); | |
9284 | printf ("%016" PRIx64 " ", BYTE_GET (imfs [i].fixup_offset)); | |
9285 | type = BYTE_GET (imfs [i].type); | |
9286 | rtype = elf_ia64_reloc_type (type); | |
9287 | if (rtype == NULL) | |
9288 | printf ("0x%08x ", type); | |
9289 | else | |
9290 | printf ("%-32s ", rtype); | |
9291 | printf ("%6u ", (unsigned) BYTE_GET (imfs [i].symvec_index)); | |
9292 | printf ("0x%08x\n", (unsigned) BYTE_GET (imfs [i].data_type)); | |
9293 | } | |
9294 | ||
9295 | free (imfs); | |
9296 | return true; | |
9297 | } | |
9298 | ||
9299 | /* Display IA-64 OpenVMS dynamic relocations (used to relocate an image). */ | |
9300 | ||
9301 | static bool | |
9302 | dump_ia64_vms_dynamic_relocs (Filedata * filedata, struct ia64_vms_dynimgrela *imgrela) | |
9303 | { | |
9304 | Elf64_External_VMS_IMAGE_RELA *imrs; | |
9305 | size_t i; | |
9306 | ||
9307 | imrs = get_data (NULL, filedata, | |
9308 | filedata->dynamic_addr + imgrela->img_rela_off, | |
9309 | sizeof (*imrs), imgrela->img_rela_cnt, | |
9310 | _("dynamic section image relocations")); | |
9311 | if (!imrs) | |
9312 | return false; | |
9313 | ||
9314 | printf (_("\nImage relocs\n")); | |
9315 | printf | |
9316 | (_("Seg Offset Type Addend Seg Sym Off\n")); | |
9317 | ||
9318 | for (i = 0; i < (size_t) imgrela->img_rela_cnt; i++) | |
9319 | { | |
9320 | unsigned int type; | |
9321 | const char *rtype; | |
9322 | ||
9323 | printf ("%3u ", (unsigned) BYTE_GET (imrs [i].rela_seg)); | |
9324 | printf ("%08" PRIx64 " ", BYTE_GET (imrs [i].rela_offset)); | |
9325 | type = BYTE_GET (imrs [i].type); | |
9326 | rtype = elf_ia64_reloc_type (type); | |
9327 | if (rtype == NULL) | |
9328 | printf ("0x%08x ", type); | |
9329 | else | |
9330 | printf ("%-31s ", rtype); | |
9331 | print_vma (BYTE_GET (imrs [i].addend), FULL_HEX); | |
9332 | printf ("%3u ", (unsigned) BYTE_GET (imrs [i].sym_seg)); | |
9333 | printf ("%08" PRIx64 "\n", BYTE_GET (imrs [i].sym_offset)); | |
9334 | } | |
9335 | ||
9336 | free (imrs); | |
9337 | return true; | |
9338 | } | |
9339 | ||
9340 | /* Display IA-64 OpenVMS dynamic relocations and fixups. */ | |
9341 | ||
9342 | static bool | |
9343 | process_ia64_vms_dynamic_relocs (Filedata * filedata) | |
9344 | { | |
9345 | struct ia64_vms_dynfixup fixup; | |
9346 | struct ia64_vms_dynimgrela imgrela; | |
9347 | Elf_Internal_Dyn *entry; | |
9348 | uint64_t strtab_off = 0; | |
9349 | uint64_t strtab_sz = 0; | |
9350 | char *strtab = NULL; | |
9351 | bool res = true; | |
9352 | ||
9353 | memset (&fixup, 0, sizeof (fixup)); | |
9354 | memset (&imgrela, 0, sizeof (imgrela)); | |
9355 | ||
9356 | /* Note: the order of the entries is specified by the OpenVMS specs. */ | |
9357 | for (entry = filedata->dynamic_section; | |
9358 | entry < filedata->dynamic_section + filedata->dynamic_nent; | |
9359 | entry++) | |
9360 | { | |
9361 | switch (entry->d_tag) | |
9362 | { | |
9363 | case DT_IA_64_VMS_STRTAB_OFFSET: | |
9364 | strtab_off = entry->d_un.d_val; | |
9365 | break; | |
9366 | case DT_STRSZ: | |
9367 | strtab_sz = entry->d_un.d_val; | |
9368 | if (strtab == NULL) | |
9369 | strtab = get_data (NULL, filedata, | |
9370 | filedata->dynamic_addr + strtab_off, | |
9371 | 1, strtab_sz, _("dynamic string section")); | |
9372 | if (strtab == NULL) | |
9373 | strtab_sz = 0; | |
9374 | break; | |
9375 | ||
9376 | case DT_IA_64_VMS_NEEDED_IDENT: | |
9377 | fixup.needed_ident = entry->d_un.d_val; | |
9378 | break; | |
9379 | case DT_NEEDED: | |
9380 | fixup.needed = entry->d_un.d_val; | |
9381 | break; | |
9382 | case DT_IA_64_VMS_FIXUP_NEEDED: | |
9383 | fixup.fixup_needed = entry->d_un.d_val; | |
9384 | break; | |
9385 | case DT_IA_64_VMS_FIXUP_RELA_CNT: | |
9386 | fixup.fixup_rela_cnt = entry->d_un.d_val; | |
9387 | break; | |
9388 | case DT_IA_64_VMS_FIXUP_RELA_OFF: | |
9389 | fixup.fixup_rela_off = entry->d_un.d_val; | |
9390 | if (! dump_ia64_vms_dynamic_fixups (filedata, &fixup, strtab, strtab_sz)) | |
9391 | res = false; | |
9392 | break; | |
9393 | case DT_IA_64_VMS_IMG_RELA_CNT: | |
9394 | imgrela.img_rela_cnt = entry->d_un.d_val; | |
9395 | break; | |
9396 | case DT_IA_64_VMS_IMG_RELA_OFF: | |
9397 | imgrela.img_rela_off = entry->d_un.d_val; | |
9398 | if (! dump_ia64_vms_dynamic_relocs (filedata, &imgrela)) | |
9399 | res = false; | |
9400 | break; | |
9401 | ||
9402 | default: | |
9403 | break; | |
9404 | } | |
9405 | } | |
9406 | ||
9407 | free (strtab); | |
9408 | ||
9409 | return res; | |
9410 | } | |
9411 | ||
9412 | static struct | |
9413 | { | |
9414 | const char * name; | |
9415 | int reloc; | |
9416 | int size; | |
9417 | relocation_type rel_type; | |
9418 | } | |
9419 | dynamic_relocations [] = | |
9420 | { | |
9421 | { "REL", DT_REL, DT_RELSZ, reltype_rel }, | |
9422 | { "RELA", DT_RELA, DT_RELASZ, reltype_rela }, | |
9423 | { "RELR", DT_RELR, DT_RELRSZ, reltype_relr }, | |
9424 | { "PLT", DT_JMPREL, DT_PLTRELSZ, reltype_unknown } | |
9425 | }; | |
9426 | ||
9427 | static relocation_type | |
9428 | rel_type_from_sh_type (unsigned int sh_type) | |
9429 | { | |
9430 | switch (sh_type) | |
9431 | { | |
9432 | case SHT_RELA: return reltype_rela; | |
9433 | case SHT_REL: return reltype_rel; | |
9434 | case SHT_RELR: return reltype_relr; | |
9435 | default: return reltype_unknown; | |
9436 | } | |
9437 | } | |
9438 | ||
9439 | static bool | |
9440 | display_relocations (Elf_Internal_Shdr * section, | |
9441 | Filedata * filedata) | |
9442 | { | |
9443 | relocation_type rel_type = rel_type_from_sh_type (section->sh_type); | |
9444 | ||
9445 | if (rel_type == reltype_unknown) | |
9446 | return false; | |
9447 | ||
9448 | uint64_t rel_size = section->sh_size; | |
9449 | ||
9450 | if (rel_size == 0) | |
9451 | return false; | |
9452 | ||
9453 | if (filedata->is_separate) | |
9454 | printf (_("\nIn linked file '%s' relocation section "), | |
9455 | printable_string (filedata->file_name, 0)); | |
9456 | else | |
9457 | printf (_("\nRelocation section ")); | |
9458 | ||
9459 | if (filedata->string_table == NULL) | |
9460 | printf ("%d", section->sh_name); | |
9461 | else | |
9462 | printf ("'%s'", printable_section_name (filedata, section)); | |
9463 | ||
9464 | uint64_t num_rela = rel_size / section->sh_entsize; | |
9465 | uint64_t rel_offset = section->sh_offset; | |
9466 | ||
9467 | if (rel_type == reltype_relr) | |
9468 | { | |
9469 | /* Just stating the 'number of entries' in a RELR section can be | |
9470 | misleading, since this is not the number of locations relocated, but | |
9471 | the number of words in the compressed RELR format. So also provide | |
9472 | the number of locations affected. */ | |
9473 | ||
9474 | uint64_t num_reloc = count_relr_relocations (filedata, section); | |
9475 | ||
9476 | printf (_(" at offset %#" PRIx64), rel_offset); | |
9477 | printf (ngettext (" contains %" PRIu64 " entry which relocates", | |
9478 | " contains %" PRIu64 " entries which relocate", | |
9479 | num_rela), num_rela); | |
9480 | printf (ngettext (" %" PRIu64 " location:\n", | |
9481 | " %" PRIu64 " locations:\n", | |
9482 | num_reloc), num_reloc); | |
9483 | } | |
9484 | else | |
9485 | { | |
9486 | printf (ngettext (" at offset %#" PRIx64 | |
9487 | " contains %" PRIu64 " entry:\n", | |
9488 | " at offset %#" PRIx64 | |
9489 | " contains %" PRIu64 " entries:\n", | |
9490 | num_rela), | |
9491 | rel_offset, num_rela); | |
9492 | } | |
9493 | ||
9494 | Elf_Internal_Shdr * symsec; | |
9495 | Elf_Internal_Sym * symtab = NULL; | |
9496 | uint64_t nsyms = 0; | |
9497 | uint64_t strtablen = 0; | |
9498 | char * strtab = NULL; | |
9499 | ||
9500 | if (section->sh_link == 0 | |
9501 | || section->sh_link >= filedata->file_header.e_shnum) | |
9502 | { | |
9503 | /* Symbol data not available. | |
9504 | This can happen, especially with RELR relocs. | |
9505 | See if there is a .symtab section present. | |
9506 | If so then use it. */ | |
9507 | symsec = find_section_by_name (filedata, ".symtab"); | |
9508 | } | |
9509 | else | |
9510 | { | |
9511 | symsec = filedata->section_headers + section->sh_link; | |
9512 | ||
9513 | if (symsec->sh_type != SHT_SYMTAB | |
9514 | && symsec->sh_type != SHT_DYNSYM) | |
9515 | return false; | |
9516 | } | |
9517 | ||
9518 | if (symsec != NULL | |
9519 | && !get_symtab (filedata, symsec, &symtab, &nsyms, &strtab, &strtablen)) | |
9520 | return false; | |
9521 | ||
9522 | bool res; | |
9523 | ||
9524 | if (rel_type == reltype_relr) | |
9525 | res = dump_relr_relocations (filedata, section, symtab, nsyms, strtab, strtablen); | |
9526 | else | |
9527 | res = dump_relocations (filedata, rel_offset, rel_size, | |
9528 | symtab, nsyms, strtab, strtablen, | |
9529 | rel_type, | |
9530 | symsec == NULL ? false : symsec->sh_type == SHT_DYNSYM); | |
9531 | free (strtab); | |
9532 | free (symtab); | |
9533 | ||
9534 | return res; | |
9535 | } | |
9536 | ||
9537 | /* Process the reloc section. */ | |
9538 | ||
9539 | static bool | |
9540 | process_relocs (Filedata * filedata) | |
9541 | { | |
9542 | uint64_t rel_size; | |
9543 | uint64_t rel_offset; | |
9544 | ||
9545 | if (!do_reloc) | |
9546 | return true; | |
9547 | ||
9548 | if (do_using_dynamic) | |
9549 | { | |
9550 | relocation_type rel_type; | |
9551 | const char * name; | |
9552 | bool has_dynamic_reloc; | |
9553 | unsigned int i; | |
9554 | ||
9555 | has_dynamic_reloc = false; | |
9556 | ||
9557 | for (i = 0; i < ARRAY_SIZE (dynamic_relocations); i++) | |
9558 | { | |
9559 | rel_type = dynamic_relocations [i].rel_type; | |
9560 | name = dynamic_relocations [i].name; | |
9561 | rel_size = filedata->dynamic_info[dynamic_relocations [i].size]; | |
9562 | rel_offset = filedata->dynamic_info[dynamic_relocations [i].reloc]; | |
9563 | ||
9564 | if (rel_size) | |
9565 | has_dynamic_reloc = true; | |
9566 | ||
9567 | if (rel_type == reltype_unknown) | |
9568 | { | |
9569 | if (dynamic_relocations [i].reloc == DT_JMPREL) | |
9570 | switch (filedata->dynamic_info[DT_PLTREL]) | |
9571 | { | |
9572 | case DT_REL: | |
9573 | rel_type = reltype_rel; | |
9574 | break; | |
9575 | case DT_RELA: | |
9576 | rel_type = reltype_rela; | |
9577 | break; | |
9578 | } | |
9579 | } | |
9580 | ||
9581 | if (rel_size) | |
9582 | { | |
9583 | if (filedata->is_separate) | |
9584 | printf | |
9585 | (_("\nIn linked file '%s' section '%s' at offset %#" PRIx64 | |
9586 | " contains %" PRId64 " bytes:\n"), | |
9587 | filedata->file_name, name, rel_offset, rel_size); | |
9588 | else | |
9589 | printf | |
9590 | (_("\n'%s' relocation section at offset %#" PRIx64 | |
9591 | " contains %" PRId64 " bytes:\n"), | |
9592 | name, rel_offset, rel_size); | |
9593 | ||
9594 | dump_relocations (filedata, | |
9595 | offset_from_vma (filedata, rel_offset, rel_size), | |
9596 | rel_size, | |
9597 | filedata->dynamic_symbols, | |
9598 | filedata->num_dynamic_syms, | |
9599 | filedata->dynamic_strings, | |
9600 | filedata->dynamic_strings_length, | |
9601 | rel_type, true /* is_dynamic */); | |
9602 | } | |
9603 | } | |
9604 | ||
9605 | if (is_ia64_vms (filedata)) | |
9606 | if (process_ia64_vms_dynamic_relocs (filedata)) | |
9607 | has_dynamic_reloc = true; | |
9608 | ||
9609 | if (! has_dynamic_reloc) | |
9610 | { | |
9611 | if (filedata->is_separate) | |
9612 | printf (_("\nThere are no dynamic relocations in linked file '%s'.\n"), | |
9613 | filedata->file_name); | |
9614 | else | |
9615 | printf (_("\nThere are no dynamic relocations in this file.\n")); | |
9616 | } | |
9617 | } | |
9618 | else | |
9619 | { | |
9620 | Elf_Internal_Shdr * section; | |
9621 | size_t i; | |
9622 | bool found = false; | |
9623 | ||
9624 | for (i = 0, section = filedata->section_headers; | |
9625 | i < filedata->file_header.e_shnum; | |
9626 | i++, section++) | |
9627 | { | |
9628 | if (display_relocations (section, filedata)) | |
9629 | found = true; | |
9630 | } | |
9631 | ||
9632 | if (! found) | |
9633 | { | |
9634 | /* Users sometimes forget the -D option, so try to be helpful. */ | |
9635 | for (i = 0; i < ARRAY_SIZE (dynamic_relocations); i++) | |
9636 | { | |
9637 | if (filedata->dynamic_info[dynamic_relocations [i].size]) | |
9638 | { | |
9639 | if (filedata->is_separate) | |
9640 | printf (_("\nThere are no static relocations in linked file '%s'."), | |
9641 | filedata->file_name); | |
9642 | else | |
9643 | printf (_("\nThere are no static relocations in this file.")); | |
9644 | printf (_("\nTo see the dynamic relocations add --use-dynamic to the command line.\n")); | |
9645 | ||
9646 | break; | |
9647 | } | |
9648 | } | |
9649 | if (i == ARRAY_SIZE (dynamic_relocations)) | |
9650 | { | |
9651 | if (filedata->is_separate) | |
9652 | printf (_("\nThere are no relocations in linked file '%s'.\n"), | |
9653 | filedata->file_name); | |
9654 | else | |
9655 | printf (_("\nThere are no relocations in this file.\n")); | |
9656 | } | |
9657 | } | |
9658 | } | |
9659 | ||
9660 | return true; | |
9661 | } | |
9662 | ||
9663 | /* An absolute address consists of a section and an offset. If the | |
9664 | section is NULL, the offset itself is the address, otherwise, the | |
9665 | address equals to LOAD_ADDRESS(section) + offset. */ | |
9666 | ||
9667 | struct absaddr | |
9668 | { | |
9669 | unsigned short section; | |
9670 | uint64_t offset; | |
9671 | }; | |
9672 | ||
9673 | /* Find the nearest symbol at or below ADDR. Returns the symbol | |
9674 | name, if found, and the offset from the symbol to ADDR. */ | |
9675 | ||
9676 | static void | |
9677 | find_symbol_for_address (Filedata *filedata, | |
9678 | Elf_Internal_Sym *symtab, | |
9679 | uint64_t nsyms, | |
9680 | const char *strtab, | |
9681 | uint64_t strtab_size, | |
9682 | struct absaddr addr, | |
9683 | const char **symname, | |
9684 | uint64_t *offset) | |
9685 | { | |
9686 | uint64_t dist = 0x100000; | |
9687 | Elf_Internal_Sym * sym; | |
9688 | Elf_Internal_Sym * beg; | |
9689 | Elf_Internal_Sym * end; | |
9690 | Elf_Internal_Sym * best = NULL; | |
9691 | ||
9692 | REMOVE_ARCH_BITS (addr.offset); | |
9693 | beg = symtab; | |
9694 | end = symtab + nsyms; | |
9695 | ||
9696 | while (beg < end) | |
9697 | { | |
9698 | uint64_t value; | |
9699 | ||
9700 | sym = beg + (end - beg) / 2; | |
9701 | ||
9702 | value = sym->st_value; | |
9703 | REMOVE_ARCH_BITS (value); | |
9704 | ||
9705 | if (sym->st_name != 0 | |
9706 | && (addr.section == SHN_UNDEF || addr.section == sym->st_shndx) | |
9707 | && addr.offset >= value | |
9708 | && addr.offset - value < dist) | |
9709 | { | |
9710 | best = sym; | |
9711 | dist = addr.offset - value; | |
9712 | if (!dist) | |
9713 | break; | |
9714 | } | |
9715 | ||
9716 | if (addr.offset < value) | |
9717 | end = sym; | |
9718 | else | |
9719 | beg = sym + 1; | |
9720 | } | |
9721 | ||
9722 | if (best) | |
9723 | { | |
9724 | *symname = (best->st_name >= strtab_size | |
9725 | ? _("<corrupt>") : strtab + best->st_name); | |
9726 | *offset = dist; | |
9727 | return; | |
9728 | } | |
9729 | ||
9730 | *symname = NULL; | |
9731 | *offset = addr.offset; | |
9732 | } | |
9733 | ||
9734 | /* Process the unwind section. */ | |
9735 | ||
9736 | #include "unwind-ia64.h" | |
9737 | ||
9738 | struct ia64_unw_table_entry | |
9739 | { | |
9740 | struct absaddr start; | |
9741 | struct absaddr end; | |
9742 | struct absaddr info; | |
9743 | }; | |
9744 | ||
9745 | struct ia64_unw_aux_info | |
9746 | { | |
9747 | struct ia64_unw_table_entry * table; /* Unwind table. */ | |
9748 | uint64_t table_len; /* Length of unwind table. */ | |
9749 | unsigned char * info; /* Unwind info. */ | |
9750 | uint64_t info_size; /* Size of unwind info. */ | |
9751 | uint64_t info_addr; /* Starting address of unwind info. */ | |
9752 | uint64_t seg_base; /* Starting address of segment. */ | |
9753 | Elf_Internal_Sym * symtab; /* The symbol table. */ | |
9754 | uint64_t nsyms; /* Number of symbols. */ | |
9755 | Elf_Internal_Sym * funtab; /* Sorted table of STT_FUNC symbols. */ | |
9756 | uint64_t nfuns; /* Number of entries in funtab. */ | |
9757 | char * strtab; /* The string table. */ | |
9758 | uint64_t strtab_size; /* Size of string table. */ | |
9759 | }; | |
9760 | ||
9761 | static bool | |
9762 | dump_ia64_unwind (Filedata * filedata, struct ia64_unw_aux_info * aux) | |
9763 | { | |
9764 | struct ia64_unw_table_entry * tp; | |
9765 | size_t j, nfuns; | |
9766 | int in_body; | |
9767 | bool res = true; | |
9768 | ||
9769 | aux->funtab = xmalloc (aux->nsyms * sizeof (Elf_Internal_Sym)); | |
9770 | for (nfuns = 0, j = 0; j < aux->nsyms; j++) | |
9771 | if (aux->symtab[j].st_value && ELF_ST_TYPE (aux->symtab[j].st_info) == STT_FUNC) | |
9772 | aux->funtab[nfuns++] = aux->symtab[j]; | |
9773 | aux->nfuns = nfuns; | |
9774 | qsort (aux->funtab, aux->nfuns, sizeof (Elf_Internal_Sym), symcmp); | |
9775 | ||
9776 | for (tp = aux->table; tp < aux->table + aux->table_len; ++tp) | |
9777 | { | |
9778 | uint64_t stamp; | |
9779 | uint64_t offset; | |
9780 | const unsigned char * dp; | |
9781 | const unsigned char * head; | |
9782 | const unsigned char * end; | |
9783 | const char * procname; | |
9784 | ||
9785 | find_symbol_for_address (filedata, aux->funtab, aux->nfuns, aux->strtab, | |
9786 | aux->strtab_size, tp->start, &procname, &offset); | |
9787 | ||
9788 | fputs ("\n<", stdout); | |
9789 | ||
9790 | if (procname) | |
9791 | { | |
9792 | fputs (procname, stdout); | |
9793 | ||
9794 | if (offset) | |
9795 | printf ("+%" PRIx64, offset); | |
9796 | } | |
9797 | ||
9798 | fputs (">: [", stdout); | |
9799 | print_vma (tp->start.offset, PREFIX_HEX); | |
9800 | fputc ('-', stdout); | |
9801 | print_vma (tp->end.offset, PREFIX_HEX); | |
9802 | printf ("], info at +0x%" PRIx64 "\n", | |
9803 | tp->info.offset - aux->seg_base); | |
9804 | ||
9805 | /* PR 17531: file: 86232b32. */ | |
9806 | if (aux->info == NULL) | |
9807 | continue; | |
9808 | ||
9809 | offset = tp->info.offset; | |
9810 | if (tp->info.section) | |
9811 | { | |
9812 | if (tp->info.section >= filedata->file_header.e_shnum) | |
9813 | { | |
9814 | warn (_("Invalid section %u in table entry %td\n"), | |
9815 | tp->info.section, tp - aux->table); | |
9816 | res = false; | |
9817 | continue; | |
9818 | } | |
9819 | offset += filedata->section_headers[tp->info.section].sh_addr; | |
9820 | } | |
9821 | offset -= aux->info_addr; | |
9822 | /* PR 17531: file: 0997b4d1. */ | |
9823 | if (offset >= aux->info_size | |
9824 | || aux->info_size - offset < 8) | |
9825 | { | |
9826 | warn (_("Invalid offset %" PRIx64 " in table entry %td\n"), | |
9827 | tp->info.offset, tp - aux->table); | |
9828 | res = false; | |
9829 | continue; | |
9830 | } | |
9831 | ||
9832 | head = aux->info + offset; | |
9833 | stamp = byte_get ((unsigned char *) head, sizeof (stamp)); | |
9834 | ||
9835 | printf (" v%u, flags=0x%lx (%s%s), len=%lu bytes\n", | |
9836 | (unsigned) UNW_VER (stamp), | |
9837 | (unsigned long) ((stamp & UNW_FLAG_MASK) >> 32), | |
9838 | UNW_FLAG_EHANDLER (stamp) ? " ehandler" : "", | |
9839 | UNW_FLAG_UHANDLER (stamp) ? " uhandler" : "", | |
9840 | (unsigned long) (eh_addr_size * UNW_LENGTH (stamp))); | |
9841 | ||
9842 | if (UNW_VER (stamp) != 1) | |
9843 | { | |
9844 | printf (_("\tUnknown version.\n")); | |
9845 | continue; | |
9846 | } | |
9847 | ||
9848 | in_body = 0; | |
9849 | end = head + 8 + eh_addr_size * UNW_LENGTH (stamp); | |
9850 | /* PR 17531: file: 16ceda89. */ | |
9851 | if (end > aux->info + aux->info_size) | |
9852 | end = aux->info + aux->info_size; | |
9853 | for (dp = head + 8; dp < end;) | |
9854 | dp = unw_decode (dp, in_body, & in_body, end); | |
9855 | } | |
9856 | ||
9857 | free (aux->funtab); | |
9858 | ||
9859 | return res; | |
9860 | } | |
9861 | ||
9862 | static bool | |
9863 | slurp_ia64_unwind_table (Filedata * filedata, | |
9864 | struct ia64_unw_aux_info * aux, | |
9865 | Elf_Internal_Shdr * sec) | |
9866 | { | |
9867 | uint64_t size, nrelas, i; | |
9868 | Elf_Internal_Phdr * seg; | |
9869 | struct ia64_unw_table_entry * tep; | |
9870 | Elf_Internal_Shdr * relsec; | |
9871 | Elf_Internal_Rela * rela; | |
9872 | Elf_Internal_Rela * rp; | |
9873 | unsigned char * table; | |
9874 | unsigned char * tp; | |
9875 | Elf_Internal_Sym * sym; | |
9876 | const char * relname; | |
9877 | ||
9878 | aux->table_len = 0; | |
9879 | ||
9880 | /* First, find the starting address of the segment that includes | |
9881 | this section: */ | |
9882 | ||
9883 | if (filedata->file_header.e_phnum) | |
9884 | { | |
9885 | if (! get_program_headers (filedata)) | |
9886 | return false; | |
9887 | ||
9888 | for (seg = filedata->program_headers; | |
9889 | seg < filedata->program_headers + filedata->file_header.e_phnum; | |
9890 | ++seg) | |
9891 | { | |
9892 | if (seg->p_type != PT_LOAD) | |
9893 | continue; | |
9894 | ||
9895 | if (sec->sh_addr >= seg->p_vaddr | |
9896 | && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz)) | |
9897 | { | |
9898 | aux->seg_base = seg->p_vaddr; | |
9899 | break; | |
9900 | } | |
9901 | } | |
9902 | } | |
9903 | ||
9904 | /* Second, build the unwind table from the contents of the unwind section: */ | |
9905 | size = sec->sh_size; | |
9906 | table = (unsigned char *) get_data (NULL, filedata, sec->sh_offset, 1, size, | |
9907 | _("unwind table")); | |
9908 | if (!table) | |
9909 | return false; | |
9910 | ||
9911 | aux->table_len = size / (3 * eh_addr_size); | |
9912 | aux->table = (struct ia64_unw_table_entry *) | |
9913 | xcmalloc (aux->table_len, sizeof (aux->table[0])); | |
9914 | tep = aux->table; | |
9915 | ||
9916 | for (tp = table; tp <= table + size - (3 * eh_addr_size); ++tep) | |
9917 | { | |
9918 | tep->start.section = SHN_UNDEF; | |
9919 | tep->end.section = SHN_UNDEF; | |
9920 | tep->info.section = SHN_UNDEF; | |
9921 | tep->start.offset = byte_get (tp, eh_addr_size); tp += eh_addr_size; | |
9922 | tep->end.offset = byte_get (tp, eh_addr_size); tp += eh_addr_size; | |
9923 | tep->info.offset = byte_get (tp, eh_addr_size); tp += eh_addr_size; | |
9924 | tep->start.offset += aux->seg_base; | |
9925 | tep->end.offset += aux->seg_base; | |
9926 | tep->info.offset += aux->seg_base; | |
9927 | } | |
9928 | free (table); | |
9929 | ||
9930 | /* Third, apply any relocations to the unwind table: */ | |
9931 | for (relsec = filedata->section_headers; | |
9932 | relsec < filedata->section_headers + filedata->file_header.e_shnum; | |
9933 | ++relsec) | |
9934 | { | |
9935 | if (relsec->sh_type != SHT_RELA | |
9936 | || relsec->sh_info >= filedata->file_header.e_shnum | |
9937 | || filedata->section_headers + relsec->sh_info != sec) | |
9938 | continue; | |
9939 | ||
9940 | if (!slurp_rela_relocs (filedata, relsec->sh_offset, relsec->sh_size, | |
9941 | & rela, & nrelas)) | |
9942 | { | |
9943 | free (aux->table); | |
9944 | aux->table = NULL; | |
9945 | aux->table_len = 0; | |
9946 | return false; | |
9947 | } | |
9948 | ||
9949 | for (rp = rela; rp < rela + nrelas; ++rp) | |
9950 | { | |
9951 | unsigned int sym_ndx; | |
9952 | unsigned int r_type = get_reloc_type (filedata, rp->r_info); | |
9953 | relname = elf_ia64_reloc_type (r_type); | |
9954 | ||
9955 | /* PR 17531: file: 9fa67536. */ | |
9956 | if (relname == NULL) | |
9957 | { | |
9958 | warn (_("Skipping unknown relocation type: %u\n"), r_type); | |
9959 | continue; | |
9960 | } | |
9961 | ||
9962 | if (! startswith (relname, "R_IA64_SEGREL")) | |
9963 | { | |
9964 | warn (_("Skipping unexpected relocation type: %s\n"), relname); | |
9965 | continue; | |
9966 | } | |
9967 | ||
9968 | i = rp->r_offset / (3 * eh_addr_size); | |
9969 | ||
9970 | /* PR 17531: file: 5bc8d9bf. */ | |
9971 | if (i >= aux->table_len) | |
9972 | { | |
9973 | warn (_("Skipping reloc with overlarge offset: %#" PRIx64 "\n"), | |
9974 | i); | |
9975 | continue; | |
9976 | } | |
9977 | ||
9978 | sym_ndx = get_reloc_symindex (rp->r_info); | |
9979 | if (sym_ndx >= aux->nsyms) | |
9980 | { | |
9981 | warn (_("Skipping reloc with invalid symbol index: %u\n"), | |
9982 | sym_ndx); | |
9983 | continue; | |
9984 | } | |
9985 | sym = aux->symtab + sym_ndx; | |
9986 | ||
9987 | switch (rp->r_offset / eh_addr_size % 3) | |
9988 | { | |
9989 | case 0: | |
9990 | aux->table[i].start.section = sym->st_shndx; | |
9991 | aux->table[i].start.offset = rp->r_addend + sym->st_value; | |
9992 | break; | |
9993 | case 1: | |
9994 | aux->table[i].end.section = sym->st_shndx; | |
9995 | aux->table[i].end.offset = rp->r_addend + sym->st_value; | |
9996 | break; | |
9997 | case 2: | |
9998 | aux->table[i].info.section = sym->st_shndx; | |
9999 | aux->table[i].info.offset = rp->r_addend + sym->st_value; | |
10000 | break; | |
10001 | default: | |
10002 | break; | |
10003 | } | |
10004 | } | |
10005 | ||
10006 | free (rela); | |
10007 | } | |
10008 | ||
10009 | return true; | |
10010 | } | |
10011 | ||
10012 | static bool | |
10013 | ia64_process_unwind (Filedata * filedata) | |
10014 | { | |
10015 | Elf_Internal_Shdr * sec; | |
10016 | Elf_Internal_Shdr * unwsec = NULL; | |
10017 | uint64_t i, unwcount = 0, unwstart = 0; | |
10018 | struct ia64_unw_aux_info aux; | |
10019 | bool res = true; | |
10020 | ||
10021 | memset (& aux, 0, sizeof (aux)); | |
10022 | ||
10023 | for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec) | |
10024 | { | |
10025 | if (sec->sh_type == SHT_SYMTAB) | |
10026 | { | |
10027 | if (aux.symtab) | |
10028 | { | |
10029 | error (_("Multiple symbol tables encountered\n")); | |
10030 | free (aux.symtab); | |
10031 | aux.symtab = NULL; | |
10032 | free (aux.strtab); | |
10033 | aux.strtab = NULL; | |
10034 | } | |
10035 | if (!get_symtab (filedata, sec, &aux.symtab, &aux.nsyms, | |
10036 | &aux.strtab, &aux.strtab_size)) | |
10037 | return false; | |
10038 | } | |
10039 | else if (sec->sh_type == SHT_IA_64_UNWIND) | |
10040 | unwcount++; | |
10041 | } | |
10042 | ||
10043 | if (!unwcount) | |
10044 | printf (_("\nThere are no unwind sections in this file.\n")); | |
10045 | ||
10046 | while (unwcount-- > 0) | |
10047 | { | |
10048 | const char *suffix; | |
10049 | size_t len, len2; | |
10050 | ||
10051 | for (i = unwstart, sec = filedata->section_headers + unwstart, unwsec = NULL; | |
10052 | i < filedata->file_header.e_shnum; ++i, ++sec) | |
10053 | if (sec->sh_type == SHT_IA_64_UNWIND) | |
10054 | { | |
10055 | unwsec = sec; | |
10056 | break; | |
10057 | } | |
10058 | /* We have already counted the number of SHT_IA64_UNWIND | |
10059 | sections so the loop above should never fail. */ | |
10060 | assert (unwsec != NULL); | |
10061 | ||
10062 | unwstart = i + 1; | |
10063 | len = sizeof (ELF_STRING_ia64_unwind_once) - 1; | |
10064 | ||
10065 | if ((unwsec->sh_flags & SHF_GROUP) != 0) | |
10066 | { | |
10067 | /* We need to find which section group it is in. */ | |
10068 | struct group_list * g; | |
10069 | ||
10070 | if (filedata->section_headers_groups == NULL | |
10071 | || filedata->section_headers_groups[i] == NULL) | |
10072 | i = filedata->file_header.e_shnum; | |
10073 | else | |
10074 | { | |
10075 | g = filedata->section_headers_groups[i]->root; | |
10076 | ||
10077 | for (; g != NULL; g = g->next) | |
10078 | { | |
10079 | sec = filedata->section_headers + g->section_index; | |
10080 | ||
10081 | if (section_name_valid (filedata, sec) | |
10082 | && streq (section_name (filedata, sec), | |
10083 | ELF_STRING_ia64_unwind_info)) | |
10084 | break; | |
10085 | } | |
10086 | ||
10087 | if (g == NULL) | |
10088 | i = filedata->file_header.e_shnum; | |
10089 | } | |
10090 | } | |
10091 | else if (section_name_valid (filedata, unwsec) | |
10092 | && startswith (section_name (filedata, unwsec), | |
10093 | ELF_STRING_ia64_unwind_once)) | |
10094 | { | |
10095 | /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO. */ | |
10096 | len2 = sizeof (ELF_STRING_ia64_unwind_info_once) - 1; | |
10097 | suffix = section_name (filedata, unwsec) + len; | |
10098 | for (i = 0, sec = filedata->section_headers; | |
10099 | i < filedata->file_header.e_shnum; | |
10100 | ++i, ++sec) | |
10101 | if (section_name_valid (filedata, sec) | |
10102 | && startswith (section_name (filedata, sec), | |
10103 | ELF_STRING_ia64_unwind_info_once) | |
10104 | && streq (section_name (filedata, sec) + len2, suffix)) | |
10105 | break; | |
10106 | } | |
10107 | else | |
10108 | { | |
10109 | /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO | |
10110 | .IA_64.unwind or BAR -> .IA_64.unwind_info. */ | |
10111 | len = sizeof (ELF_STRING_ia64_unwind) - 1; | |
10112 | len2 = sizeof (ELF_STRING_ia64_unwind_info) - 1; | |
10113 | suffix = ""; | |
10114 | if (section_name_valid (filedata, unwsec) | |
10115 | && startswith (section_name (filedata, unwsec), | |
10116 | ELF_STRING_ia64_unwind)) | |
10117 | suffix = section_name (filedata, unwsec) + len; | |
10118 | for (i = 0, sec = filedata->section_headers; | |
10119 | i < filedata->file_header.e_shnum; | |
10120 | ++i, ++sec) | |
10121 | if (section_name_valid (filedata, sec) | |
10122 | && startswith (section_name (filedata, sec), | |
10123 | ELF_STRING_ia64_unwind_info) | |
10124 | && streq (section_name (filedata, sec) + len2, suffix)) | |
10125 | break; | |
10126 | } | |
10127 | ||
10128 | if (i == filedata->file_header.e_shnum) | |
10129 | { | |
10130 | printf (_("\nCould not find unwind info section for ")); | |
10131 | ||
10132 | if (filedata->string_table == NULL) | |
10133 | printf ("%d", unwsec->sh_name); | |
10134 | else | |
10135 | printf ("'%s'", printable_section_name (filedata, unwsec)); | |
10136 | } | |
10137 | else | |
10138 | { | |
10139 | aux.info_addr = sec->sh_addr; | |
10140 | aux.info = (unsigned char *) get_data (NULL, filedata, sec->sh_offset, 1, | |
10141 | sec->sh_size, | |
10142 | _("unwind info")); | |
10143 | aux.info_size = aux.info == NULL ? 0 : sec->sh_size; | |
10144 | ||
10145 | printf (_("\nUnwind section ")); | |
10146 | ||
10147 | if (filedata->string_table == NULL) | |
10148 | printf ("%d", unwsec->sh_name); | |
10149 | else | |
10150 | printf ("'%s'", printable_section_name (filedata, unwsec)); | |
10151 | ||
10152 | printf (_(" at offset %#" PRIx64 " contains %" PRIu64 " entries:\n"), | |
10153 | unwsec->sh_offset, | |
10154 | unwsec->sh_size / (3 * eh_addr_size)); | |
10155 | ||
10156 | if (slurp_ia64_unwind_table (filedata, & aux, unwsec) | |
10157 | && aux.table_len > 0) | |
10158 | dump_ia64_unwind (filedata, & aux); | |
10159 | ||
10160 | free ((char *) aux.table); | |
10161 | free ((char *) aux.info); | |
10162 | aux.table = NULL; | |
10163 | aux.info = NULL; | |
10164 | } | |
10165 | } | |
10166 | ||
10167 | free (aux.symtab); | |
10168 | free ((char *) aux.strtab); | |
10169 | ||
10170 | return res; | |
10171 | } | |
10172 | ||
10173 | struct hppa_unw_table_entry | |
10174 | { | |
10175 | struct absaddr start; | |
10176 | struct absaddr end; | |
10177 | unsigned int Cannot_unwind:1; /* 0 */ | |
10178 | unsigned int Millicode:1; /* 1 */ | |
10179 | unsigned int Millicode_save_sr0:1; /* 2 */ | |
10180 | unsigned int Region_description:2; /* 3..4 */ | |
10181 | unsigned int reserved1:1; /* 5 */ | |
10182 | unsigned int Entry_SR:1; /* 6 */ | |
10183 | unsigned int Entry_FR:4; /* Number saved 7..10 */ | |
10184 | unsigned int Entry_GR:5; /* Number saved 11..15 */ | |
10185 | unsigned int Args_stored:1; /* 16 */ | |
10186 | unsigned int Variable_Frame:1; /* 17 */ | |
10187 | unsigned int Separate_Package_Body:1; /* 18 */ | |
10188 | unsigned int Frame_Extension_Millicode:1; /* 19 */ | |
10189 | unsigned int Stack_Overflow_Check:1; /* 20 */ | |
10190 | unsigned int Two_Instruction_SP_Increment:1; /* 21 */ | |
10191 | unsigned int Ada_Region:1; /* 22 */ | |
10192 | unsigned int cxx_info:1; /* 23 */ | |
10193 | unsigned int cxx_try_catch:1; /* 24 */ | |
10194 | unsigned int sched_entry_seq:1; /* 25 */ | |
10195 | unsigned int reserved2:1; /* 26 */ | |
10196 | unsigned int Save_SP:1; /* 27 */ | |
10197 | unsigned int Save_RP:1; /* 28 */ | |
10198 | unsigned int Save_MRP_in_frame:1; /* 29 */ | |
10199 | unsigned int extn_ptr_defined:1; /* 30 */ | |
10200 | unsigned int Cleanup_defined:1; /* 31 */ | |
10201 | ||
10202 | unsigned int MPE_XL_interrupt_marker:1; /* 0 */ | |
10203 | unsigned int HP_UX_interrupt_marker:1; /* 1 */ | |
10204 | unsigned int Large_frame:1; /* 2 */ | |
10205 | unsigned int Pseudo_SP_Set:1; /* 3 */ | |
10206 | unsigned int reserved4:1; /* 4 */ | |
10207 | unsigned int Total_frame_size:27; /* 5..31 */ | |
10208 | }; | |
10209 | ||
10210 | struct hppa_unw_aux_info | |
10211 | { | |
10212 | struct hppa_unw_table_entry * table; /* Unwind table. */ | |
10213 | uint64_t table_len; /* Length of unwind table. */ | |
10214 | uint64_t seg_base; /* Starting address of segment. */ | |
10215 | Elf_Internal_Sym * symtab; /* The symbol table. */ | |
10216 | uint64_t nsyms; /* Number of symbols. */ | |
10217 | Elf_Internal_Sym * funtab; /* Sorted table of STT_FUNC symbols. */ | |
10218 | uint64_t nfuns; /* Number of entries in funtab. */ | |
10219 | char * strtab; /* The string table. */ | |
10220 | uint64_t strtab_size; /* Size of string table. */ | |
10221 | }; | |
10222 | ||
10223 | static bool | |
10224 | dump_hppa_unwind (Filedata * filedata, struct hppa_unw_aux_info * aux) | |
10225 | { | |
10226 | struct hppa_unw_table_entry * tp; | |
10227 | uint64_t j, nfuns; | |
10228 | bool res = true; | |
10229 | ||
10230 | aux->funtab = xmalloc (aux->nsyms * sizeof (Elf_Internal_Sym)); | |
10231 | for (nfuns = 0, j = 0; j < aux->nsyms; j++) | |
10232 | if (aux->symtab[j].st_value && ELF_ST_TYPE (aux->symtab[j].st_info) == STT_FUNC) | |
10233 | aux->funtab[nfuns++] = aux->symtab[j]; | |
10234 | aux->nfuns = nfuns; | |
10235 | qsort (aux->funtab, aux->nfuns, sizeof (Elf_Internal_Sym), symcmp); | |
10236 | ||
10237 | for (tp = aux->table; tp < aux->table + aux->table_len; ++tp) | |
10238 | { | |
10239 | uint64_t offset; | |
10240 | const char * procname; | |
10241 | ||
10242 | find_symbol_for_address (filedata, aux->funtab, aux->nfuns, aux->strtab, | |
10243 | aux->strtab_size, tp->start, &procname, | |
10244 | &offset); | |
10245 | ||
10246 | fputs ("\n<", stdout); | |
10247 | ||
10248 | if (procname) | |
10249 | { | |
10250 | fputs (procname, stdout); | |
10251 | ||
10252 | if (offset) | |
10253 | printf ("+%" PRIx64, offset); | |
10254 | } | |
10255 | ||
10256 | fputs (">: [", stdout); | |
10257 | print_vma (tp->start.offset, PREFIX_HEX); | |
10258 | fputc ('-', stdout); | |
10259 | print_vma (tp->end.offset, PREFIX_HEX); | |
10260 | printf ("]\n\t"); | |
10261 | ||
10262 | #define PF(_m) if (tp->_m) printf (#_m " "); | |
10263 | #define PV(_m) if (tp->_m) printf (#_m "=%d ", tp->_m); | |
10264 | PF(Cannot_unwind); | |
10265 | PF(Millicode); | |
10266 | PF(Millicode_save_sr0); | |
10267 | /* PV(Region_description); */ | |
10268 | PF(Entry_SR); | |
10269 | PV(Entry_FR); | |
10270 | PV(Entry_GR); | |
10271 | PF(Args_stored); | |
10272 | PF(Variable_Frame); | |
10273 | PF(Separate_Package_Body); | |
10274 | PF(Frame_Extension_Millicode); | |
10275 | PF(Stack_Overflow_Check); | |
10276 | PF(Two_Instruction_SP_Increment); | |
10277 | PF(Ada_Region); | |
10278 | PF(cxx_info); | |
10279 | PF(cxx_try_catch); | |
10280 | PF(sched_entry_seq); | |
10281 | PF(Save_SP); | |
10282 | PF(Save_RP); | |
10283 | PF(Save_MRP_in_frame); | |
10284 | PF(extn_ptr_defined); | |
10285 | PF(Cleanup_defined); | |
10286 | PF(MPE_XL_interrupt_marker); | |
10287 | PF(HP_UX_interrupt_marker); | |
10288 | PF(Large_frame); | |
10289 | PF(Pseudo_SP_Set); | |
10290 | PV(Total_frame_size); | |
10291 | #undef PF | |
10292 | #undef PV | |
10293 | } | |
10294 | ||
10295 | printf ("\n"); | |
10296 | ||
10297 | free (aux->funtab); | |
10298 | ||
10299 | return res; | |
10300 | } | |
10301 | ||
10302 | static bool | |
10303 | slurp_hppa_unwind_table (Filedata * filedata, | |
10304 | struct hppa_unw_aux_info * aux, | |
10305 | Elf_Internal_Shdr * sec) | |
10306 | { | |
10307 | uint64_t size, unw_ent_size, nentries, nrelas, i; | |
10308 | Elf_Internal_Phdr * seg; | |
10309 | struct hppa_unw_table_entry * tep; | |
10310 | Elf_Internal_Shdr * relsec; | |
10311 | Elf_Internal_Rela * rela; | |
10312 | Elf_Internal_Rela * rp; | |
10313 | unsigned char * table; | |
10314 | unsigned char * tp; | |
10315 | Elf_Internal_Sym * sym; | |
10316 | const char * relname; | |
10317 | ||
10318 | /* First, find the starting address of the segment that includes | |
10319 | this section. */ | |
10320 | if (filedata->file_header.e_phnum) | |
10321 | { | |
10322 | if (! get_program_headers (filedata)) | |
10323 | return false; | |
10324 | ||
10325 | for (seg = filedata->program_headers; | |
10326 | seg < filedata->program_headers + filedata->file_header.e_phnum; | |
10327 | ++seg) | |
10328 | { | |
10329 | if (seg->p_type != PT_LOAD) | |
10330 | continue; | |
10331 | ||
10332 | if (sec->sh_addr >= seg->p_vaddr | |
10333 | && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz)) | |
10334 | { | |
10335 | aux->seg_base = seg->p_vaddr; | |
10336 | break; | |
10337 | } | |
10338 | } | |
10339 | } | |
10340 | ||
10341 | /* Second, build the unwind table from the contents of the unwind | |
10342 | section. */ | |
10343 | size = sec->sh_size; | |
10344 | table = (unsigned char *) get_data (NULL, filedata, sec->sh_offset, 1, size, | |
10345 | _("unwind table")); | |
10346 | if (!table) | |
10347 | return false; | |
10348 | ||
10349 | unw_ent_size = 16; | |
10350 | nentries = size / unw_ent_size; | |
10351 | size = unw_ent_size * nentries; | |
10352 | ||
10353 | aux->table_len = nentries; | |
10354 | tep = aux->table = (struct hppa_unw_table_entry *) | |
10355 | xcmalloc (nentries, sizeof (aux->table[0])); | |
10356 | ||
10357 | for (tp = table; tp < table + size; tp += unw_ent_size, ++tep) | |
10358 | { | |
10359 | unsigned int tmp1, tmp2; | |
10360 | ||
10361 | tep->start.section = SHN_UNDEF; | |
10362 | tep->end.section = SHN_UNDEF; | |
10363 | ||
10364 | tep->start.offset = byte_get ((unsigned char *) tp + 0, 4); | |
10365 | tep->end.offset = byte_get ((unsigned char *) tp + 4, 4); | |
10366 | tmp1 = byte_get ((unsigned char *) tp + 8, 4); | |
10367 | tmp2 = byte_get ((unsigned char *) tp + 12, 4); | |
10368 | ||
10369 | tep->start.offset += aux->seg_base; | |
10370 | tep->end.offset += aux->seg_base; | |
10371 | ||
10372 | tep->Cannot_unwind = (tmp1 >> 31) & 0x1; | |
10373 | tep->Millicode = (tmp1 >> 30) & 0x1; | |
10374 | tep->Millicode_save_sr0 = (tmp1 >> 29) & 0x1; | |
10375 | tep->Region_description = (tmp1 >> 27) & 0x3; | |
10376 | tep->reserved1 = (tmp1 >> 26) & 0x1; | |
10377 | tep->Entry_SR = (tmp1 >> 25) & 0x1; | |
10378 | tep->Entry_FR = (tmp1 >> 21) & 0xf; | |
10379 | tep->Entry_GR = (tmp1 >> 16) & 0x1f; | |
10380 | tep->Args_stored = (tmp1 >> 15) & 0x1; | |
10381 | tep->Variable_Frame = (tmp1 >> 14) & 0x1; | |
10382 | tep->Separate_Package_Body = (tmp1 >> 13) & 0x1; | |
10383 | tep->Frame_Extension_Millicode = (tmp1 >> 12) & 0x1; | |
10384 | tep->Stack_Overflow_Check = (tmp1 >> 11) & 0x1; | |
10385 | tep->Two_Instruction_SP_Increment = (tmp1 >> 10) & 0x1; | |
10386 | tep->Ada_Region = (tmp1 >> 9) & 0x1; | |
10387 | tep->cxx_info = (tmp1 >> 8) & 0x1; | |
10388 | tep->cxx_try_catch = (tmp1 >> 7) & 0x1; | |
10389 | tep->sched_entry_seq = (tmp1 >> 6) & 0x1; | |
10390 | tep->reserved2 = (tmp1 >> 5) & 0x1; | |
10391 | tep->Save_SP = (tmp1 >> 4) & 0x1; | |
10392 | tep->Save_RP = (tmp1 >> 3) & 0x1; | |
10393 | tep->Save_MRP_in_frame = (tmp1 >> 2) & 0x1; | |
10394 | tep->extn_ptr_defined = (tmp1 >> 1) & 0x1; | |
10395 | tep->Cleanup_defined = tmp1 & 0x1; | |
10396 | ||
10397 | tep->MPE_XL_interrupt_marker = (tmp2 >> 31) & 0x1; | |
10398 | tep->HP_UX_interrupt_marker = (tmp2 >> 30) & 0x1; | |
10399 | tep->Large_frame = (tmp2 >> 29) & 0x1; | |
10400 | tep->Pseudo_SP_Set = (tmp2 >> 28) & 0x1; | |
10401 | tep->reserved4 = (tmp2 >> 27) & 0x1; | |
10402 | tep->Total_frame_size = tmp2 & 0x7ffffff; | |
10403 | } | |
10404 | free (table); | |
10405 | ||
10406 | /* Third, apply any relocations to the unwind table. */ | |
10407 | for (relsec = filedata->section_headers; | |
10408 | relsec < filedata->section_headers + filedata->file_header.e_shnum; | |
10409 | ++relsec) | |
10410 | { | |
10411 | if (relsec->sh_type != SHT_RELA | |
10412 | || relsec->sh_info >= filedata->file_header.e_shnum | |
10413 | || filedata->section_headers + relsec->sh_info != sec) | |
10414 | continue; | |
10415 | ||
10416 | if (!slurp_rela_relocs (filedata, relsec->sh_offset, relsec->sh_size, | |
10417 | & rela, & nrelas)) | |
10418 | return false; | |
10419 | ||
10420 | for (rp = rela; rp < rela + nrelas; ++rp) | |
10421 | { | |
10422 | unsigned int sym_ndx; | |
10423 | unsigned int r_type = get_reloc_type (filedata, rp->r_info); | |
10424 | relname = elf_hppa_reloc_type (r_type); | |
10425 | ||
10426 | if (relname == NULL) | |
10427 | { | |
10428 | warn (_("Skipping unknown relocation type: %u\n"), r_type); | |
10429 | continue; | |
10430 | } | |
10431 | ||
10432 | /* R_PARISC_SEGREL32 or R_PARISC_SEGREL64. */ | |
10433 | if (! startswith (relname, "R_PARISC_SEGREL")) | |
10434 | { | |
10435 | warn (_("Skipping unexpected relocation type: %s\n"), relname); | |
10436 | continue; | |
10437 | } | |
10438 | ||
10439 | i = rp->r_offset / unw_ent_size; | |
10440 | if (i >= aux->table_len) | |
10441 | { | |
10442 | warn (_("Skipping reloc with overlarge offset: %#" PRIx64 "\n"), | |
10443 | i); | |
10444 | continue; | |
10445 | } | |
10446 | ||
10447 | sym_ndx = get_reloc_symindex (rp->r_info); | |
10448 | if (sym_ndx >= aux->nsyms) | |
10449 | { | |
10450 | warn (_("Skipping reloc with invalid symbol index: %u\n"), | |
10451 | sym_ndx); | |
10452 | continue; | |
10453 | } | |
10454 | sym = aux->symtab + sym_ndx; | |
10455 | ||
10456 | switch ((rp->r_offset % unw_ent_size) / 4) | |
10457 | { | |
10458 | case 0: | |
10459 | aux->table[i].start.section = sym->st_shndx; | |
10460 | aux->table[i].start.offset = sym->st_value + rp->r_addend; | |
10461 | break; | |
10462 | case 1: | |
10463 | aux->table[i].end.section = sym->st_shndx; | |
10464 | aux->table[i].end.offset = sym->st_value + rp->r_addend; | |
10465 | break; | |
10466 | default: | |
10467 | break; | |
10468 | } | |
10469 | } | |
10470 | ||
10471 | free (rela); | |
10472 | } | |
10473 | ||
10474 | return true; | |
10475 | } | |
10476 | ||
10477 | static bool | |
10478 | hppa_process_unwind (Filedata * filedata) | |
10479 | { | |
10480 | struct hppa_unw_aux_info aux; | |
10481 | Elf_Internal_Shdr * unwsec = NULL; | |
10482 | Elf_Internal_Shdr * sec; | |
10483 | size_t i; | |
10484 | bool res = true; | |
10485 | ||
10486 | if (filedata->string_table == NULL) | |
10487 | return false; | |
10488 | ||
10489 | memset (& aux, 0, sizeof (aux)); | |
10490 | ||
10491 | for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec) | |
10492 | { | |
10493 | if (sec->sh_type == SHT_SYMTAB) | |
10494 | { | |
10495 | if (aux.symtab) | |
10496 | { | |
10497 | error (_("Multiple symbol tables encountered\n")); | |
10498 | free (aux.symtab); | |
10499 | aux.symtab = NULL; | |
10500 | free (aux.strtab); | |
10501 | aux.strtab = NULL; | |
10502 | } | |
10503 | if (!get_symtab (filedata, sec, &aux.symtab, &aux.nsyms, | |
10504 | &aux.strtab, &aux.strtab_size)) | |
10505 | return false; | |
10506 | } | |
10507 | else if (section_name_valid (filedata, sec) | |
10508 | && streq (section_name (filedata, sec), ".PARISC.unwind")) | |
10509 | unwsec = sec; | |
10510 | } | |
10511 | ||
10512 | if (!unwsec) | |
10513 | printf (_("\nThere are no unwind sections in this file.\n")); | |
10514 | ||
10515 | for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec) | |
10516 | { | |
10517 | if (section_name_valid (filedata, sec) | |
10518 | && streq (section_name (filedata, sec), ".PARISC.unwind")) | |
10519 | { | |
10520 | uint64_t num_unwind = sec->sh_size / 16; | |
10521 | ||
10522 | printf (ngettext ("\nUnwind section '%s' at offset %#" PRIx64 " " | |
10523 | "contains %" PRIu64 " entry:\n", | |
10524 | "\nUnwind section '%s' at offset %#" PRIx64 " " | |
10525 | "contains %" PRIu64 " entries:\n", | |
10526 | num_unwind), | |
10527 | printable_section_name (filedata, sec), | |
10528 | sec->sh_offset, | |
10529 | num_unwind); | |
10530 | ||
10531 | if (! slurp_hppa_unwind_table (filedata, &aux, sec)) | |
10532 | res = false; | |
10533 | ||
10534 | if (res && aux.table_len > 0) | |
10535 | { | |
10536 | if (! dump_hppa_unwind (filedata, &aux)) | |
10537 | res = false; | |
10538 | } | |
10539 | ||
10540 | free ((char *) aux.table); | |
10541 | aux.table = NULL; | |
10542 | } | |
10543 | } | |
10544 | ||
10545 | free (aux.symtab); | |
10546 | free ((char *) aux.strtab); | |
10547 | ||
10548 | return res; | |
10549 | } | |
10550 | ||
10551 | struct arm_section | |
10552 | { | |
10553 | unsigned char * data; /* The unwind data. */ | |
10554 | Elf_Internal_Shdr * sec; /* The cached unwind section header. */ | |
10555 | Elf_Internal_Rela * rela; /* The cached relocations for this section. */ | |
10556 | uint64_t nrelas; /* The number of relocations. */ | |
10557 | unsigned int rel_type; /* REL or RELA ? */ | |
10558 | Elf_Internal_Rela * next_rela; /* Cyclic pointer to the next reloc to process. */ | |
10559 | }; | |
10560 | ||
10561 | struct arm_unw_aux_info | |
10562 | { | |
10563 | Filedata * filedata; /* The file containing the unwind sections. */ | |
10564 | Elf_Internal_Sym * symtab; /* The file's symbol table. */ | |
10565 | uint64_t nsyms; /* Number of symbols. */ | |
10566 | Elf_Internal_Sym * funtab; /* Sorted table of STT_FUNC symbols. */ | |
10567 | uint64_t nfuns; /* Number of these symbols. */ | |
10568 | char * strtab; /* The file's string table. */ | |
10569 | uint64_t strtab_size; /* Size of string table. */ | |
10570 | }; | |
10571 | ||
10572 | static const char * | |
10573 | arm_print_vma_and_name (Filedata * filedata, | |
10574 | struct arm_unw_aux_info * aux, | |
10575 | uint64_t fn, | |
10576 | struct absaddr addr) | |
10577 | { | |
10578 | const char *procname; | |
10579 | uint64_t sym_offset; | |
10580 | ||
10581 | if (addr.section == SHN_UNDEF) | |
10582 | addr.offset = fn; | |
10583 | ||
10584 | find_symbol_for_address (filedata, aux->funtab, aux->nfuns, aux->strtab, | |
10585 | aux->strtab_size, addr, &procname, | |
10586 | &sym_offset); | |
10587 | ||
10588 | print_vma (fn, PREFIX_HEX); | |
10589 | ||
10590 | if (procname) | |
10591 | { | |
10592 | fputs (" <", stdout); | |
10593 | fputs (procname, stdout); | |
10594 | ||
10595 | if (sym_offset) | |
10596 | printf ("+0x%" PRIx64, sym_offset); | |
10597 | fputc ('>', stdout); | |
10598 | } | |
10599 | ||
10600 | return procname; | |
10601 | } | |
10602 | ||
10603 | static void | |
10604 | arm_free_section (struct arm_section *arm_sec) | |
10605 | { | |
10606 | free (arm_sec->data); | |
10607 | free (arm_sec->rela); | |
10608 | } | |
10609 | ||
10610 | /* 1) If SEC does not match the one cached in ARM_SEC, then free the current | |
10611 | cached section and install SEC instead. | |
10612 | 2) Locate the 32-bit word at WORD_OFFSET in unwind section SEC | |
10613 | and return its valued in * WORDP, relocating if necessary. | |
10614 | 3) Update the NEXT_RELA field in ARM_SEC and store the section index and | |
10615 | relocation's offset in ADDR. | |
10616 | 4) If SYM_NAME is non-NULL and a relocation was applied, record the offset | |
10617 | into the string table of the symbol associated with the reloc. If no | |
10618 | reloc was applied store -1 there. | |
10619 | 5) Return TRUE upon success, FALSE otherwise. */ | |
10620 | ||
10621 | static bool | |
10622 | get_unwind_section_word (Filedata * filedata, | |
10623 | struct arm_unw_aux_info * aux, | |
10624 | struct arm_section * arm_sec, | |
10625 | Elf_Internal_Shdr * sec, | |
10626 | uint64_t word_offset, | |
10627 | unsigned int * wordp, | |
10628 | struct absaddr * addr, | |
10629 | uint64_t * sym_name) | |
10630 | { | |
10631 | Elf_Internal_Rela *rp; | |
10632 | Elf_Internal_Sym *sym; | |
10633 | const char * relname; | |
10634 | unsigned int word; | |
10635 | bool wrapped; | |
10636 | ||
10637 | if (sec == NULL || arm_sec == NULL) | |
10638 | return false; | |
10639 | ||
10640 | addr->section = SHN_UNDEF; | |
10641 | addr->offset = 0; | |
10642 | ||
10643 | if (sym_name != NULL) | |
10644 | *sym_name = (uint64_t) -1; | |
10645 | ||
10646 | /* If necessary, update the section cache. */ | |
10647 | if (sec != arm_sec->sec) | |
10648 | { | |
10649 | Elf_Internal_Shdr *relsec; | |
10650 | ||
10651 | arm_free_section (arm_sec); | |
10652 | ||
10653 | arm_sec->sec = sec; | |
10654 | arm_sec->data = get_data (NULL, aux->filedata, sec->sh_offset, 1, | |
10655 | sec->sh_size, _("unwind data")); | |
10656 | arm_sec->rela = NULL; | |
10657 | arm_sec->nrelas = 0; | |
10658 | ||
10659 | for (relsec = filedata->section_headers; | |
10660 | relsec < filedata->section_headers + filedata->file_header.e_shnum; | |
10661 | ++relsec) | |
10662 | { | |
10663 | if (relsec->sh_info >= filedata->file_header.e_shnum | |
10664 | || filedata->section_headers + relsec->sh_info != sec | |
10665 | /* PR 15745: Check the section type as well. */ | |
10666 | || (relsec->sh_type != SHT_REL | |
10667 | && relsec->sh_type != SHT_RELA)) | |
10668 | continue; | |
10669 | ||
10670 | arm_sec->rel_type = relsec->sh_type; | |
10671 | if (relsec->sh_type == SHT_REL) | |
10672 | { | |
10673 | if (!slurp_rel_relocs (aux->filedata, relsec->sh_offset, | |
10674 | relsec->sh_size, | |
10675 | & arm_sec->rela, & arm_sec->nrelas)) | |
10676 | return false; | |
10677 | } | |
10678 | else /* relsec->sh_type == SHT_RELA */ | |
10679 | { | |
10680 | if (!slurp_rela_relocs (aux->filedata, relsec->sh_offset, | |
10681 | relsec->sh_size, | |
10682 | & arm_sec->rela, & arm_sec->nrelas)) | |
10683 | return false; | |
10684 | } | |
10685 | break; | |
10686 | } | |
10687 | ||
10688 | arm_sec->next_rela = arm_sec->rela; | |
10689 | } | |
10690 | ||
10691 | /* If there is no unwind data we can do nothing. */ | |
10692 | if (arm_sec->data == NULL) | |
10693 | return false; | |
10694 | ||
10695 | /* If the offset is invalid then fail. */ | |
10696 | if (/* PR 21343 *//* PR 18879 */ | |
10697 | sec->sh_size < 4 | |
10698 | || word_offset > sec->sh_size - 4) | |
10699 | return false; | |
10700 | ||
10701 | /* Get the word at the required offset. */ | |
10702 | word = byte_get (arm_sec->data + word_offset, 4); | |
10703 | ||
10704 | /* PR 17531: file: id:000001,src:001266+003044,op:splice,rep:128. */ | |
10705 | if (arm_sec->rela == NULL) | |
10706 | { | |
10707 | * wordp = word; | |
10708 | return true; | |
10709 | } | |
10710 | ||
10711 | /* Look through the relocs to find the one that applies to the provided offset. */ | |
10712 | wrapped = false; | |
10713 | for (rp = arm_sec->next_rela; rp != arm_sec->rela + arm_sec->nrelas; rp++) | |
10714 | { | |
10715 | uint64_t prelval, offset; | |
10716 | ||
10717 | if (rp->r_offset > word_offset && !wrapped) | |
10718 | { | |
10719 | rp = arm_sec->rela; | |
10720 | wrapped = true; | |
10721 | } | |
10722 | if (rp->r_offset > word_offset) | |
10723 | break; | |
10724 | ||
10725 | if (rp->r_offset & 3) | |
10726 | { | |
10727 | warn (_("Skipping unexpected relocation at offset %#" PRIx64 "\n"), | |
10728 | rp->r_offset); | |
10729 | continue; | |
10730 | } | |
10731 | ||
10732 | if (rp->r_offset < word_offset) | |
10733 | continue; | |
10734 | ||
10735 | /* PR 17531: file: 027-161405-0.004 */ | |
10736 | if (aux->symtab == NULL) | |
10737 | continue; | |
10738 | ||
10739 | if (arm_sec->rel_type == SHT_REL) | |
10740 | { | |
10741 | offset = word & 0x7fffffff; | |
10742 | if (offset & 0x40000000) | |
10743 | offset |= ~ (uint64_t) 0x7fffffff; | |
10744 | } | |
10745 | else if (arm_sec->rel_type == SHT_RELA) | |
10746 | offset = rp->r_addend; | |
10747 | else | |
10748 | { | |
10749 | error (_("Unknown section relocation type %d encountered\n"), | |
10750 | arm_sec->rel_type); | |
10751 | break; | |
10752 | } | |
10753 | ||
10754 | /* PR 17531 file: 027-1241568-0.004. */ | |
10755 | if (ELF32_R_SYM (rp->r_info) >= aux->nsyms) | |
10756 | { | |
10757 | error (_("Bad symbol index in unwind relocation " | |
10758 | "(%" PRIu64 " > %" PRIu64 ")\n"), | |
10759 | ELF32_R_SYM (rp->r_info), aux->nsyms); | |
10760 | break; | |
10761 | } | |
10762 | ||
10763 | sym = aux->symtab + ELF32_R_SYM (rp->r_info); | |
10764 | offset += sym->st_value; | |
10765 | prelval = offset - (arm_sec->sec->sh_addr + rp->r_offset); | |
10766 | ||
10767 | /* Check that we are processing the expected reloc type. */ | |
10768 | if (filedata->file_header.e_machine == EM_ARM) | |
10769 | { | |
10770 | relname = elf_arm_reloc_type (ELF32_R_TYPE (rp->r_info)); | |
10771 | if (relname == NULL) | |
10772 | { | |
10773 | warn (_("Skipping unknown ARM relocation type: %d\n"), | |
10774 | (int) ELF32_R_TYPE (rp->r_info)); | |
10775 | continue; | |
10776 | } | |
10777 | ||
10778 | if (streq (relname, "R_ARM_NONE")) | |
10779 | continue; | |
10780 | ||
10781 | if (! streq (relname, "R_ARM_PREL31")) | |
10782 | { | |
10783 | warn (_("Skipping unexpected ARM relocation type %s\n"), relname); | |
10784 | continue; | |
10785 | } | |
10786 | } | |
10787 | else if (filedata->file_header.e_machine == EM_TI_C6000) | |
10788 | { | |
10789 | relname = elf_tic6x_reloc_type (ELF32_R_TYPE (rp->r_info)); | |
10790 | if (relname == NULL) | |
10791 | { | |
10792 | warn (_("Skipping unknown C6000 relocation type: %d\n"), | |
10793 | (int) ELF32_R_TYPE (rp->r_info)); | |
10794 | continue; | |
10795 | } | |
10796 | ||
10797 | if (streq (relname, "R_C6000_NONE")) | |
10798 | continue; | |
10799 | ||
10800 | if (! streq (relname, "R_C6000_PREL31")) | |
10801 | { | |
10802 | warn (_("Skipping unexpected C6000 relocation type %s\n"), relname); | |
10803 | continue; | |
10804 | } | |
10805 | ||
10806 | prelval >>= 1; | |
10807 | } | |
10808 | else | |
10809 | { | |
10810 | /* This function currently only supports ARM and TI unwinders. */ | |
10811 | warn (_("Only TI and ARM unwinders are currently supported\n")); | |
10812 | break; | |
10813 | } | |
10814 | ||
10815 | word = (word & ~ (uint64_t) 0x7fffffff) | (prelval & 0x7fffffff); | |
10816 | addr->section = sym->st_shndx; | |
10817 | addr->offset = offset; | |
10818 | ||
10819 | if (sym_name) | |
10820 | * sym_name = sym->st_name; | |
10821 | break; | |
10822 | } | |
10823 | ||
10824 | *wordp = word; | |
10825 | arm_sec->next_rela = rp; | |
10826 | ||
10827 | return true; | |
10828 | } | |
10829 | ||
10830 | static const char *tic6x_unwind_regnames[16] = | |
10831 | { | |
10832 | "A15", "B15", "B14", "B13", "B12", "B11", "B10", "B3", | |
10833 | "A14", "A13", "A12", "A11", "A10", | |
10834 | "[invalid reg 13]", "[invalid reg 14]", "[invalid reg 15]" | |
10835 | }; | |
10836 | ||
10837 | static void | |
10838 | decode_tic6x_unwind_regmask (unsigned int mask) | |
10839 | { | |
10840 | int i; | |
10841 | ||
10842 | for (i = 12; mask; mask >>= 1, i--) | |
10843 | { | |
10844 | if (mask & 1) | |
10845 | { | |
10846 | fputs (tic6x_unwind_regnames[i], stdout); | |
10847 | if (mask > 1) | |
10848 | fputs (", ", stdout); | |
10849 | } | |
10850 | } | |
10851 | } | |
10852 | ||
10853 | #define ADVANCE \ | |
10854 | if (remaining == 0 && more_words) \ | |
10855 | { \ | |
10856 | data_offset += 4; \ | |
10857 | if (! get_unwind_section_word (filedata, aux, data_arm_sec, data_sec, \ | |
10858 | data_offset, & word, & addr, NULL)) \ | |
10859 | return false; \ | |
10860 | remaining = 4; \ | |
10861 | more_words--; \ | |
10862 | } \ | |
10863 | ||
10864 | #define GET_OP(OP) \ | |
10865 | ADVANCE; \ | |
10866 | if (remaining) \ | |
10867 | { \ | |
10868 | remaining--; \ | |
10869 | (OP) = word >> 24; \ | |
10870 | word <<= 8; \ | |
10871 | } \ | |
10872 | else \ | |
10873 | { \ | |
10874 | printf (_("[Truncated opcode]\n")); \ | |
10875 | return false; \ | |
10876 | } \ | |
10877 | printf ("0x%02x ", OP) | |
10878 | ||
10879 | static bool | |
10880 | decode_arm_unwind_bytecode (Filedata * filedata, | |
10881 | struct arm_unw_aux_info * aux, | |
10882 | unsigned int word, | |
10883 | unsigned int remaining, | |
10884 | unsigned int more_words, | |
10885 | uint64_t data_offset, | |
10886 | Elf_Internal_Shdr * data_sec, | |
10887 | struct arm_section * data_arm_sec) | |
10888 | { | |
10889 | struct absaddr addr; | |
10890 | bool res = true; | |
10891 | ||
10892 | /* Decode the unwinding instructions. */ | |
10893 | while (1) | |
10894 | { | |
10895 | unsigned int op, op2; | |
10896 | ||
10897 | ADVANCE; | |
10898 | if (remaining == 0) | |
10899 | break; | |
10900 | remaining--; | |
10901 | op = word >> 24; | |
10902 | word <<= 8; | |
10903 | ||
10904 | printf (" 0x%02x ", op); | |
10905 | ||
10906 | if ((op & 0xc0) == 0x00) | |
10907 | { | |
10908 | int offset = ((op & 0x3f) << 2) + 4; | |
10909 | ||
10910 | printf (" vsp = vsp + %d", offset); | |
10911 | } | |
10912 | else if ((op & 0xc0) == 0x40) | |
10913 | { | |
10914 | int offset = ((op & 0x3f) << 2) + 4; | |
10915 | ||
10916 | printf (" vsp = vsp - %d", offset); | |
10917 | } | |
10918 | else if ((op & 0xf0) == 0x80) | |
10919 | { | |
10920 | GET_OP (op2); | |
10921 | if (op == 0x80 && op2 == 0) | |
10922 | printf (_("Refuse to unwind")); | |
10923 | else | |
10924 | { | |
10925 | unsigned int mask = ((op & 0x0f) << 8) | op2; | |
10926 | bool first = true; | |
10927 | int i; | |
10928 | ||
10929 | printf ("pop {"); | |
10930 | for (i = 0; i < 12; i++) | |
10931 | if (mask & (1 << i)) | |
10932 | { | |
10933 | if (first) | |
10934 | first = false; | |
10935 | else | |
10936 | printf (", "); | |
10937 | printf ("r%d", 4 + i); | |
10938 | } | |
10939 | printf ("}"); | |
10940 | } | |
10941 | } | |
10942 | else if ((op & 0xf0) == 0x90) | |
10943 | { | |
10944 | if (op == 0x9d || op == 0x9f) | |
10945 | printf (_(" [Reserved]")); | |
10946 | else | |
10947 | printf (" vsp = r%d", op & 0x0f); | |
10948 | } | |
10949 | else if ((op & 0xf0) == 0xa0) | |
10950 | { | |
10951 | int end = 4 + (op & 0x07); | |
10952 | bool first = true; | |
10953 | int i; | |
10954 | ||
10955 | printf (" pop {"); | |
10956 | for (i = 4; i <= end; i++) | |
10957 | { | |
10958 | if (first) | |
10959 | first = false; | |
10960 | else | |
10961 | printf (", "); | |
10962 | printf ("r%d", i); | |
10963 | } | |
10964 | if (op & 0x08) | |
10965 | { | |
10966 | if (!first) | |
10967 | printf (", "); | |
10968 | printf ("r14"); | |
10969 | } | |
10970 | printf ("}"); | |
10971 | } | |
10972 | else if (op == 0xb0) | |
10973 | printf (_(" finish")); | |
10974 | else if (op == 0xb1) | |
10975 | { | |
10976 | GET_OP (op2); | |
10977 | if (op2 == 0 || (op2 & 0xf0) != 0) | |
10978 | printf (_("[Spare]")); | |
10979 | else | |
10980 | { | |
10981 | unsigned int mask = op2 & 0x0f; | |
10982 | bool first = true; | |
10983 | int i; | |
10984 | ||
10985 | printf ("pop {"); | |
10986 | for (i = 0; i < 12; i++) | |
10987 | if (mask & (1 << i)) | |
10988 | { | |
10989 | if (first) | |
10990 | first = false; | |
10991 | else | |
10992 | printf (", "); | |
10993 | printf ("r%d", i); | |
10994 | } | |
10995 | printf ("}"); | |
10996 | } | |
10997 | } | |
10998 | else if (op == 0xb2) | |
10999 | { | |
11000 | unsigned char buf[9]; | |
11001 | unsigned int i, len; | |
11002 | uint64_t offset; | |
11003 | ||
11004 | for (i = 0; i < sizeof (buf); i++) | |
11005 | { | |
11006 | GET_OP (buf[i]); | |
11007 | if ((buf[i] & 0x80) == 0) | |
11008 | break; | |
11009 | } | |
11010 | if (i == sizeof (buf)) | |
11011 | { | |
11012 | error (_("corrupt change to vsp\n")); | |
11013 | res = false; | |
11014 | } | |
11015 | else | |
11016 | { | |
11017 | offset = read_leb128 (buf, buf + i + 1, false, &len, NULL); | |
11018 | assert (len == i + 1); | |
11019 | offset = offset * 4 + 0x204; | |
11020 | printf ("vsp = vsp + %" PRId64, offset); | |
11021 | } | |
11022 | } | |
11023 | else if (op == 0xb3 || op == 0xc8 || op == 0xc9) | |
11024 | { | |
11025 | unsigned int first, last; | |
11026 | ||
11027 | GET_OP (op2); | |
11028 | first = op2 >> 4; | |
11029 | last = op2 & 0x0f; | |
11030 | if (op == 0xc8) | |
11031 | first = first + 16; | |
11032 | printf ("pop {D%d", first); | |
11033 | if (last) | |
11034 | printf ("-D%d", first + last); | |
11035 | printf ("}"); | |
11036 | } | |
11037 | else if (op == 0xb4) | |
11038 | printf (_(" pop {ra_auth_code}")); | |
11039 | else if (op == 0xb5) | |
11040 | printf (_(" vsp as modifier for PAC validation")); | |
11041 | else if ((op & 0xf8) == 0xb8 || (op & 0xf8) == 0xd0) | |
11042 | { | |
11043 | unsigned int count = op & 0x07; | |
11044 | ||
11045 | printf ("pop {D8"); | |
11046 | if (count) | |
11047 | printf ("-D%d", 8 + count); | |
11048 | printf ("}"); | |
11049 | } | |
11050 | else if (op >= 0xc0 && op <= 0xc5) | |
11051 | { | |
11052 | unsigned int count = op & 0x07; | |
11053 | ||
11054 | printf (" pop {wR10"); | |
11055 | if (count) | |
11056 | printf ("-wR%d", 10 + count); | |
11057 | printf ("}"); | |
11058 | } | |
11059 | else if (op == 0xc6) | |
11060 | { | |
11061 | unsigned int first, last; | |
11062 | ||
11063 | GET_OP (op2); | |
11064 | first = op2 >> 4; | |
11065 | last = op2 & 0x0f; | |
11066 | printf ("pop {wR%d", first); | |
11067 | if (last) | |
11068 | printf ("-wR%d", first + last); | |
11069 | printf ("}"); | |
11070 | } | |
11071 | else if (op == 0xc7) | |
11072 | { | |
11073 | GET_OP (op2); | |
11074 | if (op2 == 0 || (op2 & 0xf0) != 0) | |
11075 | printf (_("[Spare]")); | |
11076 | else | |
11077 | { | |
11078 | unsigned int mask = op2 & 0x0f; | |
11079 | bool first = true; | |
11080 | int i; | |
11081 | ||
11082 | printf ("pop {"); | |
11083 | for (i = 0; i < 4; i++) | |
11084 | if (mask & (1 << i)) | |
11085 | { | |
11086 | if (first) | |
11087 | first = false; | |
11088 | else | |
11089 | printf (", "); | |
11090 | printf ("wCGR%d", i); | |
11091 | } | |
11092 | printf ("}"); | |
11093 | } | |
11094 | } | |
11095 | else | |
11096 | { | |
11097 | printf (_(" [unsupported opcode]")); | |
11098 | res = false; | |
11099 | } | |
11100 | ||
11101 | printf ("\n"); | |
11102 | } | |
11103 | ||
11104 | return res; | |
11105 | } | |
11106 | ||
11107 | static bool | |
11108 | decode_tic6x_unwind_bytecode (Filedata * filedata, | |
11109 | struct arm_unw_aux_info * aux, | |
11110 | unsigned int word, | |
11111 | unsigned int remaining, | |
11112 | unsigned int more_words, | |
11113 | uint64_t data_offset, | |
11114 | Elf_Internal_Shdr * data_sec, | |
11115 | struct arm_section * data_arm_sec) | |
11116 | { | |
11117 | struct absaddr addr; | |
11118 | ||
11119 | /* Decode the unwinding instructions. */ | |
11120 | while (1) | |
11121 | { | |
11122 | unsigned int op, op2; | |
11123 | ||
11124 | ADVANCE; | |
11125 | if (remaining == 0) | |
11126 | break; | |
11127 | remaining--; | |
11128 | op = word >> 24; | |
11129 | word <<= 8; | |
11130 | ||
11131 | printf (" 0x%02x ", op); | |
11132 | ||
11133 | if ((op & 0xc0) == 0x00) | |
11134 | { | |
11135 | int offset = ((op & 0x3f) << 3) + 8; | |
11136 | printf (" sp = sp + %d", offset); | |
11137 | } | |
11138 | else if ((op & 0xc0) == 0x80) | |
11139 | { | |
11140 | GET_OP (op2); | |
11141 | if (op == 0x80 && op2 == 0) | |
11142 | printf (_("Refuse to unwind")); | |
11143 | else | |
11144 | { | |
11145 | unsigned int mask = ((op & 0x1f) << 8) | op2; | |
11146 | if (op & 0x20) | |
11147 | printf ("pop compact {"); | |
11148 | else | |
11149 | printf ("pop {"); | |
11150 | ||
11151 | decode_tic6x_unwind_regmask (mask); | |
11152 | printf("}"); | |
11153 | } | |
11154 | } | |
11155 | else if ((op & 0xf0) == 0xc0) | |
11156 | { | |
11157 | unsigned int reg; | |
11158 | unsigned int nregs; | |
11159 | unsigned int i; | |
11160 | const char *name; | |
11161 | struct | |
11162 | { | |
11163 | unsigned int offset; | |
11164 | unsigned int reg; | |
11165 | } regpos[16]; | |
11166 | ||
11167 | /* Scan entire instruction first so that GET_OP output is not | |
11168 | interleaved with disassembly. */ | |
11169 | nregs = 0; | |
11170 | for (i = 0; nregs < (op & 0xf); i++) | |
11171 | { | |
11172 | GET_OP (op2); | |
11173 | reg = op2 >> 4; | |
11174 | if (reg != 0xf) | |
11175 | { | |
11176 | regpos[nregs].offset = i * 2; | |
11177 | regpos[nregs].reg = reg; | |
11178 | nregs++; | |
11179 | } | |
11180 | ||
11181 | reg = op2 & 0xf; | |
11182 | if (reg != 0xf) | |
11183 | { | |
11184 | regpos[nregs].offset = i * 2 + 1; | |
11185 | regpos[nregs].reg = reg; | |
11186 | nregs++; | |
11187 | } | |
11188 | } | |
11189 | ||
11190 | printf (_("pop frame {")); | |
11191 | if (nregs == 0) | |
11192 | { | |
11193 | printf (_("*corrupt* - no registers specified")); | |
11194 | } | |
11195 | else | |
11196 | { | |
11197 | reg = nregs - 1; | |
11198 | for (i = i * 2; i > 0; i--) | |
11199 | { | |
11200 | if (regpos[reg].offset == i - 1) | |
11201 | { | |
11202 | name = tic6x_unwind_regnames[regpos[reg].reg]; | |
11203 | if (reg > 0) | |
11204 | reg--; | |
11205 | } | |
11206 | else | |
11207 | name = _("[pad]"); | |
11208 | ||
11209 | fputs (name, stdout); | |
11210 | if (i > 1) | |
11211 | printf (", "); | |
11212 | } | |
11213 | } | |
11214 | ||
11215 | printf ("}"); | |
11216 | } | |
11217 | else if (op == 0xd0) | |
11218 | printf (" MOV FP, SP"); | |
11219 | else if (op == 0xd1) | |
11220 | printf (" __c6xabi_pop_rts"); | |
11221 | else if (op == 0xd2) | |
11222 | { | |
11223 | unsigned char buf[9]; | |
11224 | unsigned int i, len; | |
11225 | uint64_t offset; | |
11226 | ||
11227 | for (i = 0; i < sizeof (buf); i++) | |
11228 | { | |
11229 | GET_OP (buf[i]); | |
11230 | if ((buf[i] & 0x80) == 0) | |
11231 | break; | |
11232 | } | |
11233 | /* PR 17531: file: id:000001,src:001906+004739,op:splice,rep:2. */ | |
11234 | if (i == sizeof (buf)) | |
11235 | { | |
11236 | warn (_("Corrupt stack pointer adjustment detected\n")); | |
11237 | return false; | |
11238 | } | |
11239 | ||
11240 | offset = read_leb128 (buf, buf + i + 1, false, &len, NULL); | |
11241 | assert (len == i + 1); | |
11242 | offset = offset * 8 + 0x408; | |
11243 | printf (_("sp = sp + %" PRId64), offset); | |
11244 | } | |
11245 | else if ((op & 0xf0) == 0xe0) | |
11246 | { | |
11247 | if ((op & 0x0f) == 7) | |
11248 | printf (" RETURN"); | |
11249 | else | |
11250 | printf (" MV %s, B3", tic6x_unwind_regnames[op & 0x0f]); | |
11251 | } | |
11252 | else | |
11253 | { | |
11254 | printf (_(" [unsupported opcode]")); | |
11255 | } | |
11256 | putchar ('\n'); | |
11257 | } | |
11258 | ||
11259 | return true; | |
11260 | } | |
11261 | ||
11262 | static uint64_t | |
11263 | arm_expand_prel31 (Filedata * filedata, uint64_t word, uint64_t where) | |
11264 | { | |
11265 | uint64_t offset; | |
11266 | ||
11267 | offset = word & 0x7fffffff; | |
11268 | if (offset & 0x40000000) | |
11269 | offset |= ~ (uint64_t) 0x7fffffff; | |
11270 | ||
11271 | if (filedata->file_header.e_machine == EM_TI_C6000) | |
11272 | offset <<= 1; | |
11273 | ||
11274 | return offset + where; | |
11275 | } | |
11276 | ||
11277 | static bool | |
11278 | decode_arm_unwind (Filedata * filedata, | |
11279 | struct arm_unw_aux_info * aux, | |
11280 | unsigned int word, | |
11281 | unsigned int remaining, | |
11282 | uint64_t data_offset, | |
11283 | Elf_Internal_Shdr * data_sec, | |
11284 | struct arm_section * data_arm_sec) | |
11285 | { | |
11286 | int per_index; | |
11287 | unsigned int more_words = 0; | |
11288 | struct absaddr addr; | |
11289 | uint64_t sym_name = (uint64_t) -1; | |
11290 | bool res = true; | |
11291 | ||
11292 | if (remaining == 0) | |
11293 | { | |
11294 | /* Fetch the first word. | |
11295 | Note - when decoding an object file the address extracted | |
11296 | here will always be 0. So we also pass in the sym_name | |
11297 | parameter so that we can find the symbol associated with | |
11298 | the personality routine. */ | |
11299 | if (! get_unwind_section_word (filedata, aux, data_arm_sec, data_sec, data_offset, | |
11300 | & word, & addr, & sym_name)) | |
11301 | return false; | |
11302 | ||
11303 | remaining = 4; | |
11304 | } | |
11305 | else | |
11306 | { | |
11307 | addr.section = SHN_UNDEF; | |
11308 | addr.offset = 0; | |
11309 | } | |
11310 | ||
11311 | if ((word & 0x80000000) == 0) | |
11312 | { | |
11313 | /* Expand prel31 for personality routine. */ | |
11314 | uint64_t fn; | |
11315 | const char *procname; | |
11316 | ||
11317 | fn = arm_expand_prel31 (filedata, word, data_sec->sh_addr + data_offset); | |
11318 | printf (_(" Personality routine: ")); | |
11319 | if (fn == 0 | |
11320 | && addr.section == SHN_UNDEF && addr.offset == 0 | |
11321 | && sym_name != (uint64_t) -1 && sym_name < aux->strtab_size) | |
11322 | { | |
11323 | procname = aux->strtab + sym_name; | |
11324 | print_vma (fn, PREFIX_HEX); | |
11325 | if (procname) | |
11326 | { | |
11327 | fputs (" <", stdout); | |
11328 | fputs (procname, stdout); | |
11329 | fputc ('>', stdout); | |
11330 | } | |
11331 | } | |
11332 | else | |
11333 | procname = arm_print_vma_and_name (filedata, aux, fn, addr); | |
11334 | fputc ('\n', stdout); | |
11335 | ||
11336 | /* The GCC personality routines use the standard compact | |
11337 | encoding, starting with one byte giving the number of | |
11338 | words. */ | |
11339 | if (procname != NULL | |
11340 | && (startswith (procname, "__gcc_personality_v0") | |
11341 | || startswith (procname, "__gxx_personality_v0") | |
11342 | || startswith (procname, "__gcj_personality_v0") | |
11343 | || startswith (procname, "__gnu_objc_personality_v0"))) | |
11344 | { | |
11345 | remaining = 0; | |
11346 | more_words = 1; | |
11347 | ADVANCE; | |
11348 | if (!remaining) | |
11349 | { | |
11350 | printf (_(" [Truncated data]\n")); | |
11351 | return false; | |
11352 | } | |
11353 | more_words = word >> 24; | |
11354 | word <<= 8; | |
11355 | remaining--; | |
11356 | per_index = -1; | |
11357 | } | |
11358 | else | |
11359 | return true; | |
11360 | } | |
11361 | else | |
11362 | { | |
11363 | /* ARM EHABI Section 6.3: | |
11364 | ||
11365 | An exception-handling table entry for the compact model looks like: | |
11366 | ||
11367 | 31 30-28 27-24 23-0 | |
11368 | -- ----- ----- ---- | |
11369 | 1 0 index Data for personalityRoutine[index] */ | |
11370 | ||
11371 | if (filedata->file_header.e_machine == EM_ARM | |
11372 | && (word & 0x70000000)) | |
11373 | { | |
11374 | warn (_("Corrupt ARM compact model table entry: %x \n"), word); | |
11375 | res = false; | |
11376 | } | |
11377 | ||
11378 | per_index = (word >> 24) & 0x7f; | |
11379 | printf (_(" Compact model index: %d\n"), per_index); | |
11380 | if (per_index == 0) | |
11381 | { | |
11382 | more_words = 0; | |
11383 | word <<= 8; | |
11384 | remaining--; | |
11385 | } | |
11386 | else if (per_index < 3) | |
11387 | { | |
11388 | more_words = (word >> 16) & 0xff; | |
11389 | word <<= 16; | |
11390 | remaining -= 2; | |
11391 | } | |
11392 | } | |
11393 | ||
11394 | switch (filedata->file_header.e_machine) | |
11395 | { | |
11396 | case EM_ARM: | |
11397 | if (per_index < 3) | |
11398 | { | |
11399 | if (! decode_arm_unwind_bytecode (filedata, aux, word, remaining, more_words, | |
11400 | data_offset, data_sec, data_arm_sec)) | |
11401 | res = false; | |
11402 | } | |
11403 | else | |
11404 | { | |
11405 | warn (_("Unknown ARM compact model index encountered\n")); | |
11406 | printf (_(" [reserved]\n")); | |
11407 | res = false; | |
11408 | } | |
11409 | break; | |
11410 | ||
11411 | case EM_TI_C6000: | |
11412 | if (per_index < 3) | |
11413 | { | |
11414 | if (! decode_tic6x_unwind_bytecode (filedata, aux, word, remaining, more_words, | |
11415 | data_offset, data_sec, data_arm_sec)) | |
11416 | res = false; | |
11417 | } | |
11418 | else if (per_index < 5) | |
11419 | { | |
11420 | if (((word >> 17) & 0x7f) == 0x7f) | |
11421 | printf (_(" Restore stack from frame pointer\n")); | |
11422 | else | |
11423 | printf (_(" Stack increment %d\n"), (word >> 14) & 0x1fc); | |
11424 | printf (_(" Registers restored: ")); | |
11425 | if (per_index == 4) | |
11426 | printf (" (compact) "); | |
11427 | decode_tic6x_unwind_regmask ((word >> 4) & 0x1fff); | |
11428 | putchar ('\n'); | |
11429 | printf (_(" Return register: %s\n"), | |
11430 | tic6x_unwind_regnames[word & 0xf]); | |
11431 | } | |
11432 | else | |
11433 | printf (_(" [reserved (%d)]\n"), per_index); | |
11434 | break; | |
11435 | ||
11436 | default: | |
11437 | error (_("Unsupported architecture type %d encountered when decoding unwind table\n"), | |
11438 | filedata->file_header.e_machine); | |
11439 | res = false; | |
11440 | } | |
11441 | ||
11442 | /* Decode the descriptors. Not implemented. */ | |
11443 | ||
11444 | return res; | |
11445 | } | |
11446 | ||
11447 | static bool | |
11448 | dump_arm_unwind (Filedata * filedata, | |
11449 | struct arm_unw_aux_info * aux, | |
11450 | Elf_Internal_Shdr * exidx_sec) | |
11451 | { | |
11452 | struct arm_section exidx_arm_sec, extab_arm_sec; | |
11453 | unsigned int i, exidx_len; | |
11454 | uint64_t j, nfuns; | |
11455 | bool res = true; | |
11456 | ||
11457 | memset (&exidx_arm_sec, 0, sizeof (exidx_arm_sec)); | |
11458 | memset (&extab_arm_sec, 0, sizeof (extab_arm_sec)); | |
11459 | exidx_len = exidx_sec->sh_size / 8; | |
11460 | ||
11461 | aux->funtab = xmalloc (aux->nsyms * sizeof (Elf_Internal_Sym)); | |
11462 | for (nfuns = 0, j = 0; j < aux->nsyms; j++) | |
11463 | if (aux->symtab[j].st_value && ELF_ST_TYPE (aux->symtab[j].st_info) == STT_FUNC) | |
11464 | aux->funtab[nfuns++] = aux->symtab[j]; | |
11465 | aux->nfuns = nfuns; | |
11466 | qsort (aux->funtab, aux->nfuns, sizeof (Elf_Internal_Sym), symcmp); | |
11467 | ||
11468 | for (i = 0; i < exidx_len; i++) | |
11469 | { | |
11470 | unsigned int exidx_fn, exidx_entry; | |
11471 | struct absaddr fn_addr, entry_addr; | |
11472 | uint64_t fn; | |
11473 | ||
11474 | fputc ('\n', stdout); | |
11475 | ||
11476 | if (! get_unwind_section_word (filedata, aux, & exidx_arm_sec, exidx_sec, | |
11477 | 8 * i, & exidx_fn, & fn_addr, NULL) | |
11478 | || ! get_unwind_section_word (filedata, aux, & exidx_arm_sec, exidx_sec, | |
11479 | 8 * i + 4, & exidx_entry, & entry_addr, NULL)) | |
11480 | { | |
11481 | free (aux->funtab); | |
11482 | arm_free_section (& exidx_arm_sec); | |
11483 | arm_free_section (& extab_arm_sec); | |
11484 | return false; | |
11485 | } | |
11486 | ||
11487 | /* ARM EHABI, Section 5: | |
11488 | An index table entry consists of 2 words. | |
11489 | The first word contains a prel31 offset to the start of a function, with bit 31 clear. */ | |
11490 | if (exidx_fn & 0x80000000) | |
11491 | { | |
11492 | warn (_("corrupt index table entry: %x\n"), exidx_fn); | |
11493 | res = false; | |
11494 | } | |
11495 | ||
11496 | fn = arm_expand_prel31 (filedata, exidx_fn, exidx_sec->sh_addr + 8 * i); | |
11497 | ||
11498 | arm_print_vma_and_name (filedata, aux, fn, fn_addr); | |
11499 | fputs (": ", stdout); | |
11500 | ||
11501 | if (exidx_entry == 1) | |
11502 | { | |
11503 | print_vma (exidx_entry, PREFIX_HEX); | |
11504 | fputs (" [cantunwind]\n", stdout); | |
11505 | } | |
11506 | else if (exidx_entry & 0x80000000) | |
11507 | { | |
11508 | print_vma (exidx_entry, PREFIX_HEX); | |
11509 | fputc ('\n', stdout); | |
11510 | decode_arm_unwind (filedata, aux, exidx_entry, 4, 0, NULL, NULL); | |
11511 | } | |
11512 | else | |
11513 | { | |
11514 | uint64_t table, table_offset = 0; | |
11515 | Elf_Internal_Shdr *table_sec; | |
11516 | ||
11517 | fputs ("@", stdout); | |
11518 | table = arm_expand_prel31 (filedata, exidx_entry, exidx_sec->sh_addr + 8 * i + 4); | |
11519 | print_vma (table, PREFIX_HEX); | |
11520 | printf ("\n"); | |
11521 | ||
11522 | /* Locate the matching .ARM.extab. */ | |
11523 | if (entry_addr.section != SHN_UNDEF | |
11524 | && entry_addr.section < filedata->file_header.e_shnum) | |
11525 | { | |
11526 | table_sec = filedata->section_headers + entry_addr.section; | |
11527 | table_offset = entry_addr.offset; | |
11528 | /* PR 18879 */ | |
11529 | if (table_offset > table_sec->sh_size) | |
11530 | { | |
11531 | warn (_("Unwind entry contains corrupt offset (%#" PRIx64 ") into section %s\n"), | |
11532 | table_offset, | |
11533 | printable_section_name (filedata, table_sec)); | |
11534 | res = false; | |
11535 | continue; | |
11536 | } | |
11537 | } | |
11538 | else | |
11539 | { | |
11540 | table_sec = find_section_by_address (filedata, table); | |
11541 | if (table_sec != NULL) | |
11542 | table_offset = table - table_sec->sh_addr; | |
11543 | } | |
11544 | ||
11545 | if (table_sec == NULL) | |
11546 | { | |
11547 | warn (_("Could not locate .ARM.extab section containing %#" PRIx64 ".\n"), | |
11548 | table); | |
11549 | res = false; | |
11550 | continue; | |
11551 | } | |
11552 | ||
11553 | if (! decode_arm_unwind (filedata, aux, 0, 0, table_offset, table_sec, | |
11554 | &extab_arm_sec)) | |
11555 | res = false; | |
11556 | } | |
11557 | } | |
11558 | ||
11559 | printf ("\n"); | |
11560 | ||
11561 | free (aux->funtab); | |
11562 | arm_free_section (&exidx_arm_sec); | |
11563 | arm_free_section (&extab_arm_sec); | |
11564 | ||
11565 | return res; | |
11566 | } | |
11567 | ||
11568 | /* Used for both ARM and C6X unwinding tables. */ | |
11569 | ||
11570 | static bool | |
11571 | arm_process_unwind (Filedata * filedata) | |
11572 | { | |
11573 | struct arm_unw_aux_info aux; | |
11574 | Elf_Internal_Shdr *unwsec = NULL; | |
11575 | Elf_Internal_Shdr *sec; | |
11576 | size_t i; | |
11577 | unsigned int sec_type; | |
11578 | bool res = true; | |
11579 | ||
11580 | switch (filedata->file_header.e_machine) | |
11581 | { | |
11582 | case EM_ARM: | |
11583 | sec_type = SHT_ARM_EXIDX; | |
11584 | break; | |
11585 | ||
11586 | case EM_TI_C6000: | |
11587 | sec_type = SHT_C6000_UNWIND; | |
11588 | break; | |
11589 | ||
11590 | default: | |
11591 | error (_("Unsupported architecture type %d encountered when processing unwind table\n"), | |
11592 | filedata->file_header.e_machine); | |
11593 | return false; | |
11594 | } | |
11595 | ||
11596 | if (filedata->string_table == NULL) | |
11597 | return false; | |
11598 | ||
11599 | memset (& aux, 0, sizeof (aux)); | |
11600 | aux.filedata = filedata; | |
11601 | ||
11602 | for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec) | |
11603 | { | |
11604 | if (sec->sh_type == SHT_SYMTAB) | |
11605 | { | |
11606 | if (aux.symtab) | |
11607 | { | |
11608 | error (_("Multiple symbol tables encountered\n")); | |
11609 | free (aux.symtab); | |
11610 | aux.symtab = NULL; | |
11611 | free (aux.strtab); | |
11612 | aux.strtab = NULL; | |
11613 | } | |
11614 | if (!get_symtab (filedata, sec, &aux.symtab, &aux.nsyms, | |
11615 | &aux.strtab, &aux.strtab_size)) | |
11616 | return false; | |
11617 | } | |
11618 | else if (sec->sh_type == sec_type) | |
11619 | unwsec = sec; | |
11620 | } | |
11621 | ||
11622 | if (unwsec == NULL) | |
11623 | printf (_("\nThere are no unwind sections in this file.\n")); | |
11624 | else | |
11625 | for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec) | |
11626 | { | |
11627 | if (sec->sh_type == sec_type) | |
11628 | { | |
11629 | uint64_t num_unwind = sec->sh_size / (2 * eh_addr_size); | |
11630 | printf (ngettext ("\nUnwind section '%s' at offset %#" PRIx64 " " | |
11631 | "contains %" PRIu64 " entry:\n", | |
11632 | "\nUnwind section '%s' at offset %#" PRIx64 " " | |
11633 | "contains %" PRIu64 " entries:\n", | |
11634 | num_unwind), | |
11635 | printable_section_name (filedata, sec), | |
11636 | sec->sh_offset, | |
11637 | num_unwind); | |
11638 | ||
11639 | if (! dump_arm_unwind (filedata, &aux, sec)) | |
11640 | res = false; | |
11641 | } | |
11642 | } | |
11643 | ||
11644 | free (aux.symtab); | |
11645 | free ((char *) aux.strtab); | |
11646 | ||
11647 | return res; | |
11648 | } | |
11649 | ||
11650 | static bool | |
11651 | no_processor_specific_unwind (Filedata * filedata ATTRIBUTE_UNUSED) | |
11652 | { | |
11653 | printf (_("No processor specific unwind information to decode\n")); | |
11654 | return true; | |
11655 | } | |
11656 | ||
11657 | static bool | |
11658 | process_unwind (Filedata * filedata) | |
11659 | { | |
11660 | struct unwind_handler | |
11661 | { | |
11662 | unsigned int machtype; | |
11663 | bool (* handler)(Filedata *); | |
11664 | } handlers[] = | |
11665 | { | |
11666 | { EM_ARM, arm_process_unwind }, | |
11667 | { EM_IA_64, ia64_process_unwind }, | |
11668 | { EM_PARISC, hppa_process_unwind }, | |
11669 | { EM_TI_C6000, arm_process_unwind }, | |
11670 | { EM_386, no_processor_specific_unwind }, | |
11671 | { EM_X86_64, no_processor_specific_unwind }, | |
11672 | { 0, NULL } | |
11673 | }; | |
11674 | int i; | |
11675 | ||
11676 | if (!do_unwind) | |
11677 | return true; | |
11678 | ||
11679 | for (i = 0; handlers[i].handler != NULL; i++) | |
11680 | if (filedata->file_header.e_machine == handlers[i].machtype) | |
11681 | return handlers[i].handler (filedata); | |
11682 | ||
11683 | printf (_("\nThe decoding of unwind sections for machine type %s is not currently supported.\n"), | |
11684 | get_machine_name (filedata->file_header.e_machine)); | |
11685 | return true; | |
11686 | } | |
11687 | ||
11688 | static void | |
11689 | dynamic_section_aarch64_val (Elf_Internal_Dyn * entry) | |
11690 | { | |
11691 | switch (entry->d_tag) | |
11692 | { | |
11693 | case DT_AARCH64_BTI_PLT: | |
11694 | case DT_AARCH64_PAC_PLT: | |
11695 | break; | |
11696 | default: | |
11697 | print_vma (entry->d_un.d_ptr, PREFIX_HEX); | |
11698 | break; | |
11699 | } | |
11700 | putchar ('\n'); | |
11701 | } | |
11702 | ||
11703 | static void | |
11704 | dynamic_section_mips_val (Filedata * filedata, Elf_Internal_Dyn * entry) | |
11705 | { | |
11706 | switch (entry->d_tag) | |
11707 | { | |
11708 | case DT_MIPS_FLAGS: | |
11709 | if (entry->d_un.d_val == 0) | |
11710 | printf (_("NONE")); | |
11711 | else | |
11712 | { | |
11713 | static const char * opts[] = | |
11714 | { | |
11715 | "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT", | |
11716 | "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS", | |
11717 | "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD", | |
11718 | "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF", | |
11719 | "RLD_ORDER_SAFE" | |
11720 | }; | |
11721 | unsigned int cnt; | |
11722 | bool first = true; | |
11723 | ||
11724 | for (cnt = 0; cnt < ARRAY_SIZE (opts); ++cnt) | |
11725 | if (entry->d_un.d_val & (1 << cnt)) | |
11726 | { | |
11727 | printf ("%s%s", first ? "" : " ", opts[cnt]); | |
11728 | first = false; | |
11729 | } | |
11730 | } | |
11731 | break; | |
11732 | ||
11733 | case DT_MIPS_IVERSION: | |
11734 | if (valid_dynamic_name (filedata, entry->d_un.d_val)) | |
11735 | printf (_("Interface Version: %s"), | |
11736 | get_dynamic_name (filedata, entry->d_un.d_val)); | |
11737 | else | |
11738 | printf (_("Interface Version: <corrupt: %" PRIx64 ">"), | |
11739 | entry->d_un.d_ptr); | |
11740 | break; | |
11741 | ||
11742 | case DT_MIPS_TIME_STAMP: | |
11743 | { | |
11744 | char timebuf[128]; | |
11745 | struct tm * tmp; | |
11746 | time_t atime = entry->d_un.d_val; | |
11747 | ||
11748 | tmp = gmtime (&atime); | |
11749 | /* PR 17531: file: 6accc532. */ | |
11750 | if (tmp == NULL) | |
11751 | snprintf (timebuf, sizeof (timebuf), _("<corrupt>")); | |
11752 | else | |
11753 | snprintf (timebuf, sizeof (timebuf), "%04u-%02u-%02uT%02u:%02u:%02u", | |
11754 | tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday, | |
11755 | tmp->tm_hour, tmp->tm_min, tmp->tm_sec); | |
11756 | printf (_("Time Stamp: %s"), timebuf); | |
11757 | } | |
11758 | break; | |
11759 | ||
11760 | case DT_MIPS_RLD_VERSION: | |
11761 | case DT_MIPS_LOCAL_GOTNO: | |
11762 | case DT_MIPS_CONFLICTNO: | |
11763 | case DT_MIPS_LIBLISTNO: | |
11764 | case DT_MIPS_SYMTABNO: | |
11765 | case DT_MIPS_UNREFEXTNO: | |
11766 | case DT_MIPS_HIPAGENO: | |
11767 | case DT_MIPS_DELTA_CLASS_NO: | |
11768 | case DT_MIPS_DELTA_INSTANCE_NO: | |
11769 | case DT_MIPS_DELTA_RELOC_NO: | |
11770 | case DT_MIPS_DELTA_SYM_NO: | |
11771 | case DT_MIPS_DELTA_CLASSSYM_NO: | |
11772 | case DT_MIPS_COMPACT_SIZE: | |
11773 | print_vma (entry->d_un.d_val, DEC); | |
11774 | break; | |
11775 | ||
11776 | case DT_MIPS_XHASH: | |
11777 | filedata->dynamic_info_DT_MIPS_XHASH = entry->d_un.d_val; | |
11778 | filedata->dynamic_info_DT_GNU_HASH = entry->d_un.d_val; | |
11779 | /* Falls through. */ | |
11780 | ||
11781 | default: | |
11782 | print_vma (entry->d_un.d_ptr, PREFIX_HEX); | |
11783 | } | |
11784 | putchar ('\n'); | |
11785 | } | |
11786 | ||
11787 | static void | |
11788 | dynamic_section_parisc_val (Elf_Internal_Dyn * entry) | |
11789 | { | |
11790 | switch (entry->d_tag) | |
11791 | { | |
11792 | case DT_HP_DLD_FLAGS: | |
11793 | { | |
11794 | static struct | |
11795 | { | |
11796 | unsigned int bit; | |
11797 | const char * str; | |
11798 | } | |
11799 | flags[] = | |
11800 | { | |
11801 | { DT_HP_DEBUG_PRIVATE, "HP_DEBUG_PRIVATE" }, | |
11802 | { DT_HP_DEBUG_CALLBACK, "HP_DEBUG_CALLBACK" }, | |
11803 | { DT_HP_DEBUG_CALLBACK_BOR, "HP_DEBUG_CALLBACK_BOR" }, | |
11804 | { DT_HP_NO_ENVVAR, "HP_NO_ENVVAR" }, | |
11805 | { DT_HP_BIND_NOW, "HP_BIND_NOW" }, | |
11806 | { DT_HP_BIND_NONFATAL, "HP_BIND_NONFATAL" }, | |
11807 | { DT_HP_BIND_VERBOSE, "HP_BIND_VERBOSE" }, | |
11808 | { DT_HP_BIND_RESTRICTED, "HP_BIND_RESTRICTED" }, | |
11809 | { DT_HP_BIND_SYMBOLIC, "HP_BIND_SYMBOLIC" }, | |
11810 | { DT_HP_RPATH_FIRST, "HP_RPATH_FIRST" }, | |
11811 | { DT_HP_BIND_DEPTH_FIRST, "HP_BIND_DEPTH_FIRST" }, | |
11812 | { DT_HP_GST, "HP_GST" }, | |
11813 | { DT_HP_SHLIB_FIXED, "HP_SHLIB_FIXED" }, | |
11814 | { DT_HP_MERGE_SHLIB_SEG, "HP_MERGE_SHLIB_SEG" }, | |
11815 | { DT_HP_NODELETE, "HP_NODELETE" }, | |
11816 | { DT_HP_GROUP, "HP_GROUP" }, | |
11817 | { DT_HP_PROTECT_LINKAGE_TABLE, "HP_PROTECT_LINKAGE_TABLE" } | |
11818 | }; | |
11819 | bool first = true; | |
11820 | size_t cnt; | |
11821 | uint64_t val = entry->d_un.d_val; | |
11822 | ||
11823 | for (cnt = 0; cnt < ARRAY_SIZE (flags); ++cnt) | |
11824 | if (val & flags[cnt].bit) | |
11825 | { | |
11826 | if (! first) | |
11827 | putchar (' '); | |
11828 | fputs (flags[cnt].str, stdout); | |
11829 | first = false; | |
11830 | val ^= flags[cnt].bit; | |
11831 | } | |
11832 | ||
11833 | if (val != 0 || first) | |
11834 | { | |
11835 | if (! first) | |
11836 | putchar (' '); | |
11837 | print_vma (val, HEX); | |
11838 | } | |
11839 | } | |
11840 | break; | |
11841 | ||
11842 | default: | |
11843 | print_vma (entry->d_un.d_ptr, PREFIX_HEX); | |
11844 | break; | |
11845 | } | |
11846 | putchar ('\n'); | |
11847 | } | |
11848 | ||
11849 | /* VMS vs Unix time offset and factor. */ | |
11850 | ||
11851 | #define VMS_EPOCH_OFFSET 35067168000000000LL | |
11852 | #define VMS_GRANULARITY_FACTOR 10000000 | |
11853 | #ifndef INT64_MIN | |
11854 | #define INT64_MIN (-9223372036854775807LL - 1) | |
11855 | #endif | |
11856 | ||
11857 | /* Display a VMS time in a human readable format. */ | |
11858 | ||
11859 | static void | |
11860 | print_vms_time (int64_t vmstime) | |
11861 | { | |
11862 | struct tm *tm = NULL; | |
11863 | time_t unxtime; | |
11864 | ||
11865 | if (vmstime >= INT64_MIN + VMS_EPOCH_OFFSET) | |
11866 | { | |
11867 | vmstime = (vmstime - VMS_EPOCH_OFFSET) / VMS_GRANULARITY_FACTOR; | |
11868 | unxtime = vmstime; | |
11869 | if (unxtime == vmstime) | |
11870 | tm = gmtime (&unxtime); | |
11871 | } | |
11872 | if (tm != NULL) | |
11873 | printf ("%04u-%02u-%02uT%02u:%02u:%02u", | |
11874 | tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, | |
11875 | tm->tm_hour, tm->tm_min, tm->tm_sec); | |
11876 | } | |
11877 | ||
11878 | static void | |
11879 | dynamic_section_ia64_val (Elf_Internal_Dyn * entry) | |
11880 | { | |
11881 | switch (entry->d_tag) | |
11882 | { | |
11883 | case DT_IA_64_PLT_RESERVE: | |
11884 | /* First 3 slots reserved. */ | |
11885 | print_vma (entry->d_un.d_ptr, PREFIX_HEX); | |
11886 | printf (" -- "); | |
11887 | print_vma (entry->d_un.d_ptr + (3 * 8), PREFIX_HEX); | |
11888 | break; | |
11889 | ||
11890 | case DT_IA_64_VMS_LINKTIME: | |
11891 | print_vms_time (entry->d_un.d_val); | |
11892 | break; | |
11893 | ||
11894 | case DT_IA_64_VMS_LNKFLAGS: | |
11895 | print_vma (entry->d_un.d_ptr, PREFIX_HEX); | |
11896 | if (entry->d_un.d_val & VMS_LF_CALL_DEBUG) | |
11897 | printf (" CALL_DEBUG"); | |
11898 | if (entry->d_un.d_val & VMS_LF_NOP0BUFS) | |
11899 | printf (" NOP0BUFS"); | |
11900 | if (entry->d_un.d_val & VMS_LF_P0IMAGE) | |
11901 | printf (" P0IMAGE"); | |
11902 | if (entry->d_un.d_val & VMS_LF_MKTHREADS) | |
11903 | printf (" MKTHREADS"); | |
11904 | if (entry->d_un.d_val & VMS_LF_UPCALLS) | |
11905 | printf (" UPCALLS"); | |
11906 | if (entry->d_un.d_val & VMS_LF_IMGSTA) | |
11907 | printf (" IMGSTA"); | |
11908 | if (entry->d_un.d_val & VMS_LF_INITIALIZE) | |
11909 | printf (" INITIALIZE"); | |
11910 | if (entry->d_un.d_val & VMS_LF_MAIN) | |
11911 | printf (" MAIN"); | |
11912 | if (entry->d_un.d_val & VMS_LF_EXE_INIT) | |
11913 | printf (" EXE_INIT"); | |
11914 | if (entry->d_un.d_val & VMS_LF_TBK_IN_IMG) | |
11915 | printf (" TBK_IN_IMG"); | |
11916 | if (entry->d_un.d_val & VMS_LF_DBG_IN_IMG) | |
11917 | printf (" DBG_IN_IMG"); | |
11918 | if (entry->d_un.d_val & VMS_LF_TBK_IN_DSF) | |
11919 | printf (" TBK_IN_DSF"); | |
11920 | if (entry->d_un.d_val & VMS_LF_DBG_IN_DSF) | |
11921 | printf (" DBG_IN_DSF"); | |
11922 | if (entry->d_un.d_val & VMS_LF_SIGNATURES) | |
11923 | printf (" SIGNATURES"); | |
11924 | if (entry->d_un.d_val & VMS_LF_REL_SEG_OFF) | |
11925 | printf (" REL_SEG_OFF"); | |
11926 | break; | |
11927 | ||
11928 | default: | |
11929 | print_vma (entry->d_un.d_ptr, PREFIX_HEX); | |
11930 | break; | |
11931 | } | |
11932 | putchar ('\n'); | |
11933 | } | |
11934 | ||
11935 | static bool | |
11936 | get_32bit_dynamic_section (Filedata * filedata) | |
11937 | { | |
11938 | Elf32_External_Dyn * edyn; | |
11939 | Elf32_External_Dyn * ext; | |
11940 | Elf_Internal_Dyn * entry; | |
11941 | ||
11942 | edyn = (Elf32_External_Dyn *) get_data (NULL, filedata, | |
11943 | filedata->dynamic_addr, 1, | |
11944 | filedata->dynamic_size, | |
11945 | _("dynamic section")); | |
11946 | if (!edyn) | |
11947 | return false; | |
11948 | ||
11949 | /* SGI's ELF has more than one section in the DYNAMIC segment, and we | |
11950 | might not have the luxury of section headers. Look for the DT_NULL | |
11951 | terminator to determine the number of entries. */ | |
11952 | for (ext = edyn, filedata->dynamic_nent = 0; | |
11953 | (char *) (ext + 1) <= (char *) edyn + filedata->dynamic_size; | |
11954 | ext++) | |
11955 | { | |
11956 | filedata->dynamic_nent++; | |
11957 | if (BYTE_GET (ext->d_tag) == DT_NULL) | |
11958 | break; | |
11959 | } | |
11960 | ||
11961 | filedata->dynamic_section | |
11962 | = (Elf_Internal_Dyn *) cmalloc (filedata->dynamic_nent, sizeof (* entry)); | |
11963 | if (filedata->dynamic_section == NULL) | |
11964 | { | |
11965 | error (_("Out of memory allocating space for %" PRIu64 " dynamic entries\n"), | |
11966 | filedata->dynamic_nent); | |
11967 | free (edyn); | |
11968 | return false; | |
11969 | } | |
11970 | ||
11971 | for (ext = edyn, entry = filedata->dynamic_section; | |
11972 | entry < filedata->dynamic_section + filedata->dynamic_nent; | |
11973 | ext++, entry++) | |
11974 | { | |
11975 | entry->d_tag = BYTE_GET (ext->d_tag); | |
11976 | entry->d_un.d_val = BYTE_GET (ext->d_un.d_val); | |
11977 | } | |
11978 | ||
11979 | free (edyn); | |
11980 | ||
11981 | return true; | |
11982 | } | |
11983 | ||
11984 | static bool | |
11985 | get_64bit_dynamic_section (Filedata * filedata) | |
11986 | { | |
11987 | Elf64_External_Dyn * edyn; | |
11988 | Elf64_External_Dyn * ext; | |
11989 | Elf_Internal_Dyn * entry; | |
11990 | ||
11991 | /* Read in the data. */ | |
11992 | edyn = (Elf64_External_Dyn *) get_data (NULL, filedata, | |
11993 | filedata->dynamic_addr, 1, | |
11994 | filedata->dynamic_size, | |
11995 | _("dynamic section")); | |
11996 | if (!edyn) | |
11997 | return false; | |
11998 | ||
11999 | /* SGI's ELF has more than one section in the DYNAMIC segment, and we | |
12000 | might not have the luxury of section headers. Look for the DT_NULL | |
12001 | terminator to determine the number of entries. */ | |
12002 | for (ext = edyn, filedata->dynamic_nent = 0; | |
12003 | /* PR 17533 file: 033-67080-0.004 - do not read past end of buffer. */ | |
12004 | (char *) (ext + 1) <= (char *) edyn + filedata->dynamic_size; | |
12005 | ext++) | |
12006 | { | |
12007 | filedata->dynamic_nent++; | |
12008 | if (BYTE_GET (ext->d_tag) == DT_NULL) | |
12009 | break; | |
12010 | } | |
12011 | ||
12012 | filedata->dynamic_section | |
12013 | = (Elf_Internal_Dyn *) cmalloc (filedata->dynamic_nent, sizeof (* entry)); | |
12014 | if (filedata->dynamic_section == NULL) | |
12015 | { | |
12016 | error (_("Out of memory allocating space for %" PRIu64 " dynamic entries\n"), | |
12017 | filedata->dynamic_nent); | |
12018 | free (edyn); | |
12019 | return false; | |
12020 | } | |
12021 | ||
12022 | /* Convert from external to internal formats. */ | |
12023 | for (ext = edyn, entry = filedata->dynamic_section; | |
12024 | entry < filedata->dynamic_section + filedata->dynamic_nent; | |
12025 | ext++, entry++) | |
12026 | { | |
12027 | entry->d_tag = BYTE_GET (ext->d_tag); | |
12028 | entry->d_un.d_val = BYTE_GET (ext->d_un.d_val); | |
12029 | } | |
12030 | ||
12031 | free (edyn); | |
12032 | ||
12033 | return true; | |
12034 | } | |
12035 | ||
12036 | static bool | |
12037 | get_dynamic_section (Filedata *filedata) | |
12038 | { | |
12039 | if (filedata->dynamic_section) | |
12040 | return true; | |
12041 | ||
12042 | if (is_32bit_elf) | |
12043 | return get_32bit_dynamic_section (filedata); | |
12044 | else | |
12045 | return get_64bit_dynamic_section (filedata); | |
12046 | } | |
12047 | ||
12048 | static void | |
12049 | print_dynamic_flags (uint64_t flags) | |
12050 | { | |
12051 | bool first = true; | |
12052 | ||
12053 | while (flags) | |
12054 | { | |
12055 | uint64_t flag; | |
12056 | ||
12057 | flag = flags & - flags; | |
12058 | flags &= ~ flag; | |
12059 | ||
12060 | if (first) | |
12061 | first = false; | |
12062 | else | |
12063 | putc (' ', stdout); | |
12064 | ||
12065 | switch (flag) | |
12066 | { | |
12067 | case DF_ORIGIN: fputs ("ORIGIN", stdout); break; | |
12068 | case DF_SYMBOLIC: fputs ("SYMBOLIC", stdout); break; | |
12069 | case DF_TEXTREL: fputs ("TEXTREL", stdout); break; | |
12070 | case DF_BIND_NOW: fputs ("BIND_NOW", stdout); break; | |
12071 | case DF_STATIC_TLS: fputs ("STATIC_TLS", stdout); break; | |
12072 | default: fputs (_("unknown"), stdout); break; | |
12073 | } | |
12074 | } | |
12075 | puts (""); | |
12076 | } | |
12077 | ||
12078 | static uint64_t * | |
12079 | get_dynamic_data (Filedata * filedata, uint64_t number, unsigned int ent_size) | |
12080 | { | |
12081 | unsigned char * e_data; | |
12082 | uint64_t * i_data; | |
12083 | ||
12084 | /* If size_t is smaller than uint64_t, eg because you are building | |
12085 | on a 32-bit host, then make sure that when number is cast to | |
12086 | size_t no information is lost. */ | |
12087 | if ((size_t) number != number | |
12088 | || ent_size * number / ent_size != number) | |
12089 | { | |
12090 | error (_("Size overflow prevents reading %" PRIu64 | |
12091 | " elements of size %u\n"), | |
12092 | number, ent_size); | |
12093 | return NULL; | |
12094 | } | |
12095 | ||
12096 | /* Be kind to memory checkers (eg valgrind, address sanitizer) by not | |
12097 | attempting to allocate memory when the read is bound to fail. */ | |
12098 | if (ent_size * number > filedata->file_size) | |
12099 | { | |
12100 | error (_("Invalid number of dynamic entries: %" PRIu64 "\n"), | |
12101 | number); | |
12102 | return NULL; | |
12103 | } | |
12104 | ||
12105 | e_data = (unsigned char *) cmalloc ((size_t) number, ent_size); | |
12106 | if (e_data == NULL) | |
12107 | { | |
12108 | error (_("Out of memory reading %" PRIu64 " dynamic entries\n"), | |
12109 | number); | |
12110 | return NULL; | |
12111 | } | |
12112 | ||
12113 | if (fread (e_data, ent_size, (size_t) number, filedata->handle) != number) | |
12114 | { | |
12115 | error (_("Unable to read in %" PRIu64 " bytes of dynamic data\n"), | |
12116 | number * ent_size); | |
12117 | free (e_data); | |
12118 | return NULL; | |
12119 | } | |
12120 | ||
12121 | i_data = (uint64_t *) cmalloc ((size_t) number, sizeof (*i_data)); | |
12122 | if (i_data == NULL) | |
12123 | { | |
12124 | error (_("Out of memory allocating space for %" PRIu64 " dynamic entries\n"), | |
12125 | number); | |
12126 | free (e_data); | |
12127 | return NULL; | |
12128 | } | |
12129 | ||
12130 | while (number--) | |
12131 | i_data[number] = byte_get (e_data + number * ent_size, ent_size); | |
12132 | ||
12133 | free (e_data); | |
12134 | ||
12135 | return i_data; | |
12136 | } | |
12137 | ||
12138 | static uint64_t | |
12139 | get_num_dynamic_syms (Filedata * filedata) | |
12140 | { | |
12141 | uint64_t num_of_syms = 0; | |
12142 | ||
12143 | if (!do_histogram && (!do_using_dynamic || do_dyn_syms)) | |
12144 | return num_of_syms; | |
12145 | ||
12146 | if (filedata->dynamic_info[DT_HASH]) | |
12147 | { | |
12148 | unsigned char nb[8]; | |
12149 | unsigned char nc[8]; | |
12150 | unsigned int hash_ent_size = 4; | |
12151 | ||
12152 | if ((filedata->file_header.e_machine == EM_ALPHA | |
12153 | || filedata->file_header.e_machine == EM_S390 | |
12154 | || filedata->file_header.e_machine == EM_S390_OLD) | |
12155 | && filedata->file_header.e_ident[EI_CLASS] == ELFCLASS64) | |
12156 | hash_ent_size = 8; | |
12157 | ||
12158 | if (fseek64 (filedata->handle, | |
12159 | (filedata->archive_file_offset | |
12160 | + offset_from_vma (filedata, | |
12161 | filedata->dynamic_info[DT_HASH], | |
12162 | sizeof nb + sizeof nc)), | |
12163 | SEEK_SET)) | |
12164 | { | |
12165 | error (_("Unable to seek to start of dynamic information\n")); | |
12166 | goto no_hash; | |
12167 | } | |
12168 | ||
12169 | if (fread (nb, hash_ent_size, 1, filedata->handle) != 1) | |
12170 | { | |
12171 | error (_("Failed to read in number of buckets\n")); | |
12172 | goto no_hash; | |
12173 | } | |
12174 | ||
12175 | if (fread (nc, hash_ent_size, 1, filedata->handle) != 1) | |
12176 | { | |
12177 | error (_("Failed to read in number of chains\n")); | |
12178 | goto no_hash; | |
12179 | } | |
12180 | ||
12181 | filedata->nbuckets = byte_get (nb, hash_ent_size); | |
12182 | filedata->nchains = byte_get (nc, hash_ent_size); | |
12183 | ||
12184 | if (filedata->nbuckets != 0 && filedata->nchains != 0) | |
12185 | { | |
12186 | filedata->buckets = get_dynamic_data (filedata, filedata->nbuckets, | |
12187 | hash_ent_size); | |
12188 | filedata->chains = get_dynamic_data (filedata, filedata->nchains, | |
12189 | hash_ent_size); | |
12190 | ||
12191 | if (filedata->buckets != NULL && filedata->chains != NULL) | |
12192 | num_of_syms = filedata->nchains; | |
12193 | } | |
12194 | no_hash: | |
12195 | if (num_of_syms == 0) | |
12196 | { | |
12197 | free (filedata->buckets); | |
12198 | filedata->buckets = NULL; | |
12199 | free (filedata->chains); | |
12200 | filedata->chains = NULL; | |
12201 | filedata->nbuckets = 0; | |
12202 | } | |
12203 | } | |
12204 | ||
12205 | if (filedata->dynamic_info_DT_GNU_HASH) | |
12206 | { | |
12207 | unsigned char nb[16]; | |
12208 | uint64_t i, maxchain = 0xffffffff, bitmaskwords; | |
12209 | uint64_t buckets_vma; | |
12210 | uint64_t hn; | |
12211 | ||
12212 | if (fseek64 (filedata->handle, | |
12213 | (filedata->archive_file_offset | |
12214 | + offset_from_vma (filedata, | |
12215 | filedata->dynamic_info_DT_GNU_HASH, | |
12216 | sizeof nb)), | |
12217 | SEEK_SET)) | |
12218 | { | |
12219 | error (_("Unable to seek to start of dynamic information\n")); | |
12220 | goto no_gnu_hash; | |
12221 | } | |
12222 | ||
12223 | if (fread (nb, 16, 1, filedata->handle) != 1) | |
12224 | { | |
12225 | error (_("Failed to read in number of buckets\n")); | |
12226 | goto no_gnu_hash; | |
12227 | } | |
12228 | ||
12229 | filedata->ngnubuckets = byte_get (nb, 4); | |
12230 | filedata->gnusymidx = byte_get (nb + 4, 4); | |
12231 | bitmaskwords = byte_get (nb + 8, 4); | |
12232 | buckets_vma = filedata->dynamic_info_DT_GNU_HASH + 16; | |
12233 | if (is_32bit_elf) | |
12234 | buckets_vma += bitmaskwords * 4; | |
12235 | else | |
12236 | buckets_vma += bitmaskwords * 8; | |
12237 | ||
12238 | if (fseek64 (filedata->handle, | |
12239 | (filedata->archive_file_offset | |
12240 | + offset_from_vma (filedata, buckets_vma, 4)), | |
12241 | SEEK_SET)) | |
12242 | { | |
12243 | error (_("Unable to seek to start of dynamic information\n")); | |
12244 | goto no_gnu_hash; | |
12245 | } | |
12246 | ||
12247 | filedata->gnubuckets | |
12248 | = get_dynamic_data (filedata, filedata->ngnubuckets, 4); | |
12249 | ||
12250 | if (filedata->gnubuckets == NULL) | |
12251 | goto no_gnu_hash; | |
12252 | ||
12253 | for (i = 0; i < filedata->ngnubuckets; i++) | |
12254 | if (filedata->gnubuckets[i] != 0) | |
12255 | { | |
12256 | if (filedata->gnubuckets[i] < filedata->gnusymidx) | |
12257 | goto no_gnu_hash; | |
12258 | ||
12259 | if (maxchain == 0xffffffff || filedata->gnubuckets[i] > maxchain) | |
12260 | maxchain = filedata->gnubuckets[i]; | |
12261 | } | |
12262 | ||
12263 | if (maxchain == 0xffffffff) | |
12264 | goto no_gnu_hash; | |
12265 | ||
12266 | maxchain -= filedata->gnusymidx; | |
12267 | ||
12268 | if (fseek64 (filedata->handle, | |
12269 | (filedata->archive_file_offset | |
12270 | + offset_from_vma (filedata, | |
12271 | buckets_vma + 4 * (filedata->ngnubuckets | |
12272 | + maxchain), | |
12273 | 4)), | |
12274 | SEEK_SET)) | |
12275 | { | |
12276 | error (_("Unable to seek to start of dynamic information\n")); | |
12277 | goto no_gnu_hash; | |
12278 | } | |
12279 | ||
12280 | do | |
12281 | { | |
12282 | if (fread (nb, 4, 1, filedata->handle) != 1) | |
12283 | { | |
12284 | error (_("Failed to determine last chain length\n")); | |
12285 | goto no_gnu_hash; | |
12286 | } | |
12287 | ||
12288 | if (maxchain + 1 == 0) | |
12289 | goto no_gnu_hash; | |
12290 | ||
12291 | ++maxchain; | |
12292 | } | |
12293 | while ((byte_get (nb, 4) & 1) == 0); | |
12294 | ||
12295 | if (fseek64 (filedata->handle, | |
12296 | (filedata->archive_file_offset | |
12297 | + offset_from_vma (filedata, (buckets_vma | |
12298 | + 4 * filedata->ngnubuckets), | |
12299 | 4)), | |
12300 | SEEK_SET)) | |
12301 | { | |
12302 | error (_("Unable to seek to start of dynamic information\n")); | |
12303 | goto no_gnu_hash; | |
12304 | } | |
12305 | ||
12306 | filedata->gnuchains = get_dynamic_data (filedata, maxchain, 4); | |
12307 | filedata->ngnuchains = maxchain; | |
12308 | ||
12309 | if (filedata->gnuchains == NULL) | |
12310 | goto no_gnu_hash; | |
12311 | ||
12312 | if (filedata->dynamic_info_DT_MIPS_XHASH) | |
12313 | { | |
12314 | if (fseek64 (filedata->handle, | |
12315 | (filedata->archive_file_offset | |
12316 | + offset_from_vma (filedata, (buckets_vma | |
12317 | + 4 * (filedata->ngnubuckets | |
12318 | + maxchain)), 4)), | |
12319 | SEEK_SET)) | |
12320 | { | |
12321 | error (_("Unable to seek to start of dynamic information\n")); | |
12322 | goto no_gnu_hash; | |
12323 | } | |
12324 | ||
12325 | filedata->mipsxlat = get_dynamic_data (filedata, maxchain, 4); | |
12326 | if (filedata->mipsxlat == NULL) | |
12327 | goto no_gnu_hash; | |
12328 | } | |
12329 | ||
12330 | for (hn = 0; hn < filedata->ngnubuckets; ++hn) | |
12331 | if (filedata->gnubuckets[hn] != 0) | |
12332 | { | |
12333 | uint64_t si = filedata->gnubuckets[hn]; | |
12334 | uint64_t off = si - filedata->gnusymidx; | |
12335 | ||
12336 | do | |
12337 | { | |
12338 | if (filedata->dynamic_info_DT_MIPS_XHASH) | |
12339 | { | |
12340 | if (off < filedata->ngnuchains | |
12341 | && filedata->mipsxlat[off] >= num_of_syms) | |
12342 | num_of_syms = filedata->mipsxlat[off] + 1; | |
12343 | } | |
12344 | else | |
12345 | { | |
12346 | if (si >= num_of_syms) | |
12347 | num_of_syms = si + 1; | |
12348 | } | |
12349 | si++; | |
12350 | } | |
12351 | while (off < filedata->ngnuchains | |
12352 | && (filedata->gnuchains[off++] & 1) == 0); | |
12353 | } | |
12354 | ||
12355 | if (num_of_syms == 0) | |
12356 | { | |
12357 | no_gnu_hash: | |
12358 | free (filedata->mipsxlat); | |
12359 | filedata->mipsxlat = NULL; | |
12360 | free (filedata->gnuchains); | |
12361 | filedata->gnuchains = NULL; | |
12362 | free (filedata->gnubuckets); | |
12363 | filedata->gnubuckets = NULL; | |
12364 | filedata->ngnubuckets = 0; | |
12365 | filedata->ngnuchains = 0; | |
12366 | } | |
12367 | } | |
12368 | ||
12369 | return num_of_syms; | |
12370 | } | |
12371 | ||
12372 | /* Parse and display the contents of the dynamic section. */ | |
12373 | ||
12374 | static bool | |
12375 | process_dynamic_section (Filedata * filedata) | |
12376 | { | |
12377 | Elf_Internal_Dyn * entry; | |
12378 | ||
12379 | if (filedata->dynamic_size <= 1) | |
12380 | { | |
12381 | if (do_dynamic) | |
12382 | { | |
12383 | if (filedata->is_separate) | |
12384 | printf (_("\nThere is no dynamic section in linked file '%s'.\n"), | |
12385 | printable_string (filedata->file_name, 0)); | |
12386 | else | |
12387 | printf (_("\nThere is no dynamic section in this file.\n")); | |
12388 | } | |
12389 | ||
12390 | return true; | |
12391 | } | |
12392 | ||
12393 | if (!get_dynamic_section (filedata)) | |
12394 | return false; | |
12395 | ||
12396 | /* Find the appropriate symbol table. */ | |
12397 | if (filedata->dynamic_symbols == NULL || do_histogram) | |
12398 | { | |
12399 | uint64_t num_of_syms; | |
12400 | ||
12401 | for (entry = filedata->dynamic_section; | |
12402 | entry < filedata->dynamic_section + filedata->dynamic_nent; | |
12403 | ++entry) | |
12404 | if (entry->d_tag == DT_SYMTAB) | |
12405 | filedata->dynamic_info[DT_SYMTAB] = entry->d_un.d_val; | |
12406 | else if (entry->d_tag == DT_SYMENT) | |
12407 | filedata->dynamic_info[DT_SYMENT] = entry->d_un.d_val; | |
12408 | else if (entry->d_tag == DT_HASH) | |
12409 | filedata->dynamic_info[DT_HASH] = entry->d_un.d_val; | |
12410 | else if (entry->d_tag == DT_GNU_HASH) | |
12411 | filedata->dynamic_info_DT_GNU_HASH = entry->d_un.d_val; | |
12412 | else if ((filedata->file_header.e_machine == EM_MIPS | |
12413 | || filedata->file_header.e_machine == EM_MIPS_RS3_LE) | |
12414 | && entry->d_tag == DT_MIPS_XHASH) | |
12415 | { | |
12416 | filedata->dynamic_info_DT_MIPS_XHASH = entry->d_un.d_val; | |
12417 | filedata->dynamic_info_DT_GNU_HASH = entry->d_un.d_val; | |
12418 | } | |
12419 | ||
12420 | num_of_syms = get_num_dynamic_syms (filedata); | |
12421 | ||
12422 | if (num_of_syms != 0 | |
12423 | && filedata->dynamic_symbols == NULL | |
12424 | && filedata->dynamic_info[DT_SYMTAB] | |
12425 | && filedata->dynamic_info[DT_SYMENT]) | |
12426 | { | |
12427 | Elf_Internal_Phdr *seg; | |
12428 | uint64_t vma = filedata->dynamic_info[DT_SYMTAB]; | |
12429 | ||
12430 | if (! get_program_headers (filedata)) | |
12431 | { | |
12432 | error (_("Cannot interpret virtual addresses " | |
12433 | "without program headers.\n")); | |
12434 | return false; | |
12435 | } | |
12436 | ||
12437 | for (seg = filedata->program_headers; | |
12438 | seg < filedata->program_headers + filedata->file_header.e_phnum; | |
12439 | ++seg) | |
12440 | { | |
12441 | if (seg->p_type != PT_LOAD) | |
12442 | continue; | |
12443 | ||
12444 | if (seg->p_offset + seg->p_filesz > filedata->file_size) | |
12445 | { | |
12446 | /* See PR 21379 for a reproducer. */ | |
12447 | error (_("Invalid PT_LOAD entry\n")); | |
12448 | return false; | |
12449 | } | |
12450 | ||
12451 | if (vma >= (seg->p_vaddr & -seg->p_align) | |
12452 | && vma < seg->p_vaddr + seg->p_filesz) | |
12453 | { | |
12454 | /* Since we do not know how big the symbol table is, | |
12455 | we default to reading in up to the end of PT_LOAD | |
12456 | segment and processing that. This is overkill, I | |
12457 | know, but it should work. */ | |
12458 | Elf_Internal_Shdr section; | |
12459 | section.sh_offset = (vma - seg->p_vaddr | |
12460 | + seg->p_offset); | |
12461 | section.sh_size = (num_of_syms | |
12462 | * filedata->dynamic_info[DT_SYMENT]); | |
12463 | section.sh_entsize = filedata->dynamic_info[DT_SYMENT]; | |
12464 | ||
12465 | if (do_checks | |
12466 | && filedata->dynamic_symtab_section != NULL | |
12467 | && ((filedata->dynamic_symtab_section->sh_offset | |
12468 | != section.sh_offset) | |
12469 | || (filedata->dynamic_symtab_section->sh_size | |
12470 | != section.sh_size) | |
12471 | || (filedata->dynamic_symtab_section->sh_entsize | |
12472 | != section.sh_entsize))) | |
12473 | warn (_("\ | |
12474 | the .dynsym section doesn't match the DT_SYMTAB and DT_SYMENT tags\n")); | |
12475 | ||
12476 | section.sh_name = filedata->string_table_length; | |
12477 | filedata->dynamic_symbols | |
12478 | = get_elf_symbols (filedata, §ion, | |
12479 | &filedata->num_dynamic_syms); | |
12480 | if (filedata->dynamic_symbols == NULL | |
12481 | || filedata->num_dynamic_syms != num_of_syms) | |
12482 | { | |
12483 | error (_("Corrupt DT_SYMTAB dynamic entry\n")); | |
12484 | return false; | |
12485 | } | |
12486 | break; | |
12487 | } | |
12488 | } | |
12489 | } | |
12490 | } | |
12491 | ||
12492 | /* Similarly find a string table. */ | |
12493 | if (filedata->dynamic_strings == NULL) | |
12494 | for (entry = filedata->dynamic_section; | |
12495 | entry < filedata->dynamic_section + filedata->dynamic_nent; | |
12496 | ++entry) | |
12497 | { | |
12498 | if (entry->d_tag == DT_STRTAB) | |
12499 | filedata->dynamic_info[DT_STRTAB] = entry->d_un.d_val; | |
12500 | ||
12501 | if (entry->d_tag == DT_STRSZ) | |
12502 | filedata->dynamic_info[DT_STRSZ] = entry->d_un.d_val; | |
12503 | ||
12504 | if (filedata->dynamic_info[DT_STRTAB] | |
12505 | && filedata->dynamic_info[DT_STRSZ]) | |
12506 | { | |
12507 | uint64_t offset; | |
12508 | uint64_t str_tab_len = filedata->dynamic_info[DT_STRSZ]; | |
12509 | ||
12510 | offset = offset_from_vma (filedata, | |
12511 | filedata->dynamic_info[DT_STRTAB], | |
12512 | str_tab_len); | |
12513 | if (do_checks | |
12514 | && filedata->dynamic_strtab_section | |
12515 | && ((filedata->dynamic_strtab_section->sh_offset | |
12516 | != (file_ptr) offset) | |
12517 | || (filedata->dynamic_strtab_section->sh_size | |
12518 | != str_tab_len))) | |
12519 | warn (_("\ | |
12520 | the .dynstr section doesn't match the DT_STRTAB and DT_STRSZ tags\n")); | |
12521 | ||
12522 | filedata->dynamic_strings | |
12523 | = (char *) get_data (NULL, filedata, offset, 1, str_tab_len, | |
12524 | _("dynamic string table")); | |
12525 | if (filedata->dynamic_strings == NULL) | |
12526 | { | |
12527 | error (_("Corrupt DT_STRTAB dynamic entry\n")); | |
12528 | break; | |
12529 | } | |
12530 | ||
12531 | filedata->dynamic_strings_length = str_tab_len; | |
12532 | break; | |
12533 | } | |
12534 | } | |
12535 | ||
12536 | /* And find the syminfo section if available. */ | |
12537 | if (filedata->dynamic_syminfo == NULL) | |
12538 | { | |
12539 | uint64_t syminsz = 0; | |
12540 | ||
12541 | for (entry = filedata->dynamic_section; | |
12542 | entry < filedata->dynamic_section + filedata->dynamic_nent; | |
12543 | ++entry) | |
12544 | { | |
12545 | if (entry->d_tag == DT_SYMINENT) | |
12546 | { | |
12547 | /* Note: these braces are necessary to avoid a syntax | |
12548 | error from the SunOS4 C compiler. */ | |
12549 | /* PR binutils/17531: A corrupt file can trigger this test. | |
12550 | So do not use an assert, instead generate an error message. */ | |
12551 | if (sizeof (Elf_External_Syminfo) != entry->d_un.d_val) | |
12552 | error (_("Bad value (%d) for SYMINENT entry\n"), | |
12553 | (int) entry->d_un.d_val); | |
12554 | } | |
12555 | else if (entry->d_tag == DT_SYMINSZ) | |
12556 | syminsz = entry->d_un.d_val; | |
12557 | else if (entry->d_tag == DT_SYMINFO) | |
12558 | filedata->dynamic_syminfo_offset | |
12559 | = offset_from_vma (filedata, entry->d_un.d_val, syminsz); | |
12560 | } | |
12561 | ||
12562 | if (filedata->dynamic_syminfo_offset != 0 && syminsz != 0) | |
12563 | { | |
12564 | Elf_External_Syminfo * extsyminfo; | |
12565 | Elf_External_Syminfo * extsym; | |
12566 | Elf_Internal_Syminfo * syminfo; | |
12567 | ||
12568 | /* There is a syminfo section. Read the data. */ | |
12569 | extsyminfo = (Elf_External_Syminfo *) | |
12570 | get_data (NULL, filedata, filedata->dynamic_syminfo_offset, | |
12571 | 1, syminsz, _("symbol information")); | |
12572 | if (!extsyminfo) | |
12573 | return false; | |
12574 | ||
12575 | if (filedata->dynamic_syminfo != NULL) | |
12576 | { | |
12577 | error (_("Multiple dynamic symbol information sections found\n")); | |
12578 | free (filedata->dynamic_syminfo); | |
12579 | } | |
12580 | filedata->dynamic_syminfo = (Elf_Internal_Syminfo *) malloc (syminsz); | |
12581 | if (filedata->dynamic_syminfo == NULL) | |
12582 | { | |
12583 | error (_("Out of memory allocating %" PRIu64 | |
12584 | " bytes for dynamic symbol info\n"), | |
12585 | syminsz); | |
12586 | return false; | |
12587 | } | |
12588 | ||
12589 | filedata->dynamic_syminfo_nent | |
12590 | = syminsz / sizeof (Elf_External_Syminfo); | |
12591 | for (syminfo = filedata->dynamic_syminfo, extsym = extsyminfo; | |
12592 | syminfo < (filedata->dynamic_syminfo | |
12593 | + filedata->dynamic_syminfo_nent); | |
12594 | ++syminfo, ++extsym) | |
12595 | { | |
12596 | syminfo->si_boundto = BYTE_GET (extsym->si_boundto); | |
12597 | syminfo->si_flags = BYTE_GET (extsym->si_flags); | |
12598 | } | |
12599 | ||
12600 | free (extsyminfo); | |
12601 | } | |
12602 | } | |
12603 | ||
12604 | if (do_dynamic && filedata->dynamic_addr) | |
12605 | { | |
12606 | if (filedata->is_separate) | |
12607 | printf (ngettext ("\nIn linked file '%s' the dynamic section at offset %#" PRIx64 " contains %" PRIu64 " entry:\n", | |
12608 | "\nIn linked file '%s' the dynamic section at offset %#" PRIx64 " contains %" PRIu64 " entries:\n", | |
12609 | filedata->dynamic_nent), | |
12610 | filedata->file_name, | |
12611 | filedata->dynamic_addr, | |
12612 | filedata->dynamic_nent); | |
12613 | else | |
12614 | printf (ngettext ("\nDynamic section at offset %#" PRIx64 " contains %" PRIu64 " entry:\n", | |
12615 | "\nDynamic section at offset %#" PRIx64 " contains %" PRIu64 " entries:\n", | |
12616 | filedata->dynamic_nent), | |
12617 | filedata->dynamic_addr, | |
12618 | filedata->dynamic_nent); | |
12619 | } | |
12620 | if (do_dynamic) | |
12621 | printf (_(" Tag Type Name/Value\n")); | |
12622 | ||
12623 | for (entry = filedata->dynamic_section; | |
12624 | entry < filedata->dynamic_section + filedata->dynamic_nent; | |
12625 | entry++) | |
12626 | { | |
12627 | if (do_dynamic) | |
12628 | { | |
12629 | const char * dtype; | |
12630 | ||
12631 | putchar (' '); | |
12632 | print_vma (entry->d_tag, FULL_HEX); | |
12633 | dtype = get_dynamic_type (filedata, entry->d_tag); | |
12634 | printf (" (%s)%*s", dtype, | |
12635 | ((is_32bit_elf ? 27 : 19) - (int) strlen (dtype)), " "); | |
12636 | } | |
12637 | ||
12638 | switch (entry->d_tag) | |
12639 | { | |
12640 | case DT_FLAGS: | |
12641 | if (do_dynamic) | |
12642 | print_dynamic_flags (entry->d_un.d_val); | |
12643 | break; | |
12644 | ||
12645 | case DT_AUXILIARY: | |
12646 | case DT_FILTER: | |
12647 | case DT_CONFIG: | |
12648 | case DT_DEPAUDIT: | |
12649 | case DT_AUDIT: | |
12650 | if (do_dynamic) | |
12651 | { | |
12652 | switch (entry->d_tag) | |
12653 | { | |
12654 | case DT_AUXILIARY: | |
12655 | printf (_("Auxiliary library")); | |
12656 | break; | |
12657 | ||
12658 | case DT_FILTER: | |
12659 | printf (_("Filter library")); | |
12660 | break; | |
12661 | ||
12662 | case DT_CONFIG: | |
12663 | printf (_("Configuration file")); | |
12664 | break; | |
12665 | ||
12666 | case DT_DEPAUDIT: | |
12667 | printf (_("Dependency audit library")); | |
12668 | break; | |
12669 | ||
12670 | case DT_AUDIT: | |
12671 | printf (_("Audit library")); | |
12672 | break; | |
12673 | } | |
12674 | ||
12675 | if (valid_dynamic_name (filedata, entry->d_un.d_val)) | |
12676 | printf (": [%s]\n", | |
12677 | get_dynamic_name (filedata, entry->d_un.d_val)); | |
12678 | else | |
12679 | { | |
12680 | printf (": "); | |
12681 | print_vma (entry->d_un.d_val, PREFIX_HEX); | |
12682 | putchar ('\n'); | |
12683 | } | |
12684 | } | |
12685 | break; | |
12686 | ||
12687 | case DT_FEATURE: | |
12688 | if (do_dynamic) | |
12689 | { | |
12690 | printf (_("Flags:")); | |
12691 | ||
12692 | if (entry->d_un.d_val == 0) | |
12693 | printf (_(" None\n")); | |
12694 | else | |
12695 | { | |
12696 | uint64_t val = entry->d_un.d_val; | |
12697 | ||
12698 | if (val & DTF_1_PARINIT) | |
12699 | { | |
12700 | printf (" PARINIT"); | |
12701 | val ^= DTF_1_PARINIT; | |
12702 | } | |
12703 | if (val & DTF_1_CONFEXP) | |
12704 | { | |
12705 | printf (" CONFEXP"); | |
12706 | val ^= DTF_1_CONFEXP; | |
12707 | } | |
12708 | if (val != 0) | |
12709 | printf (" %" PRIx64, val); | |
12710 | puts (""); | |
12711 | } | |
12712 | } | |
12713 | break; | |
12714 | ||
12715 | case DT_POSFLAG_1: | |
12716 | if (do_dynamic) | |
12717 | { | |
12718 | printf (_("Flags:")); | |
12719 | ||
12720 | if (entry->d_un.d_val == 0) | |
12721 | printf (_(" None\n")); | |
12722 | else | |
12723 | { | |
12724 | uint64_t val = entry->d_un.d_val; | |
12725 | ||
12726 | if (val & DF_P1_LAZYLOAD) | |
12727 | { | |
12728 | printf (" LAZYLOAD"); | |
12729 | val ^= DF_P1_LAZYLOAD; | |
12730 | } | |
12731 | if (val & DF_P1_GROUPPERM) | |
12732 | { | |
12733 | printf (" GROUPPERM"); | |
12734 | val ^= DF_P1_GROUPPERM; | |
12735 | } | |
12736 | if (val != 0) | |
12737 | printf (" %" PRIx64, val); | |
12738 | puts (""); | |
12739 | } | |
12740 | } | |
12741 | break; | |
12742 | ||
12743 | case DT_FLAGS_1: | |
12744 | if (do_dynamic) | |
12745 | { | |
12746 | printf (_("Flags:")); | |
12747 | if (entry->d_un.d_val == 0) | |
12748 | printf (_(" None\n")); | |
12749 | else | |
12750 | { | |
12751 | uint64_t val = entry->d_un.d_val; | |
12752 | ||
12753 | if (val & DF_1_NOW) | |
12754 | { | |
12755 | printf (" NOW"); | |
12756 | val ^= DF_1_NOW; | |
12757 | } | |
12758 | if (val & DF_1_GLOBAL) | |
12759 | { | |
12760 | printf (" GLOBAL"); | |
12761 | val ^= DF_1_GLOBAL; | |
12762 | } | |
12763 | if (val & DF_1_GROUP) | |
12764 | { | |
12765 | printf (" GROUP"); | |
12766 | val ^= DF_1_GROUP; | |
12767 | } | |
12768 | if (val & DF_1_NODELETE) | |
12769 | { | |
12770 | printf (" NODELETE"); | |
12771 | val ^= DF_1_NODELETE; | |
12772 | } | |
12773 | if (val & DF_1_LOADFLTR) | |
12774 | { | |
12775 | printf (" LOADFLTR"); | |
12776 | val ^= DF_1_LOADFLTR; | |
12777 | } | |
12778 | if (val & DF_1_INITFIRST) | |
12779 | { | |
12780 | printf (" INITFIRST"); | |
12781 | val ^= DF_1_INITFIRST; | |
12782 | } | |
12783 | if (val & DF_1_NOOPEN) | |
12784 | { | |
12785 | printf (" NOOPEN"); | |
12786 | val ^= DF_1_NOOPEN; | |
12787 | } | |
12788 | if (val & DF_1_ORIGIN) | |
12789 | { | |
12790 | printf (" ORIGIN"); | |
12791 | val ^= DF_1_ORIGIN; | |
12792 | } | |
12793 | if (val & DF_1_DIRECT) | |
12794 | { | |
12795 | printf (" DIRECT"); | |
12796 | val ^= DF_1_DIRECT; | |
12797 | } | |
12798 | if (val & DF_1_TRANS) | |
12799 | { | |
12800 | printf (" TRANS"); | |
12801 | val ^= DF_1_TRANS; | |
12802 | } | |
12803 | if (val & DF_1_INTERPOSE) | |
12804 | { | |
12805 | printf (" INTERPOSE"); | |
12806 | val ^= DF_1_INTERPOSE; | |
12807 | } | |
12808 | if (val & DF_1_NODEFLIB) | |
12809 | { | |
12810 | printf (" NODEFLIB"); | |
12811 | val ^= DF_1_NODEFLIB; | |
12812 | } | |
12813 | if (val & DF_1_NODUMP) | |
12814 | { | |
12815 | printf (" NODUMP"); | |
12816 | val ^= DF_1_NODUMP; | |
12817 | } | |
12818 | if (val & DF_1_CONFALT) | |
12819 | { | |
12820 | printf (" CONFALT"); | |
12821 | val ^= DF_1_CONFALT; | |
12822 | } | |
12823 | if (val & DF_1_ENDFILTEE) | |
12824 | { | |
12825 | printf (" ENDFILTEE"); | |
12826 | val ^= DF_1_ENDFILTEE; | |
12827 | } | |
12828 | if (val & DF_1_DISPRELDNE) | |
12829 | { | |
12830 | printf (" DISPRELDNE"); | |
12831 | val ^= DF_1_DISPRELDNE; | |
12832 | } | |
12833 | if (val & DF_1_DISPRELPND) | |
12834 | { | |
12835 | printf (" DISPRELPND"); | |
12836 | val ^= DF_1_DISPRELPND; | |
12837 | } | |
12838 | if (val & DF_1_NODIRECT) | |
12839 | { | |
12840 | printf (" NODIRECT"); | |
12841 | val ^= DF_1_NODIRECT; | |
12842 | } | |
12843 | if (val & DF_1_IGNMULDEF) | |
12844 | { | |
12845 | printf (" IGNMULDEF"); | |
12846 | val ^= DF_1_IGNMULDEF; | |
12847 | } | |
12848 | if (val & DF_1_NOKSYMS) | |
12849 | { | |
12850 | printf (" NOKSYMS"); | |
12851 | val ^= DF_1_NOKSYMS; | |
12852 | } | |
12853 | if (val & DF_1_NOHDR) | |
12854 | { | |
12855 | printf (" NOHDR"); | |
12856 | val ^= DF_1_NOHDR; | |
12857 | } | |
12858 | if (val & DF_1_EDITED) | |
12859 | { | |
12860 | printf (" EDITED"); | |
12861 | val ^= DF_1_EDITED; | |
12862 | } | |
12863 | if (val & DF_1_NORELOC) | |
12864 | { | |
12865 | printf (" NORELOC"); | |
12866 | val ^= DF_1_NORELOC; | |
12867 | } | |
12868 | if (val & DF_1_SYMINTPOSE) | |
12869 | { | |
12870 | printf (" SYMINTPOSE"); | |
12871 | val ^= DF_1_SYMINTPOSE; | |
12872 | } | |
12873 | if (val & DF_1_GLOBAUDIT) | |
12874 | { | |
12875 | printf (" GLOBAUDIT"); | |
12876 | val ^= DF_1_GLOBAUDIT; | |
12877 | } | |
12878 | if (val & DF_1_SINGLETON) | |
12879 | { | |
12880 | printf (" SINGLETON"); | |
12881 | val ^= DF_1_SINGLETON; | |
12882 | } | |
12883 | if (val & DF_1_STUB) | |
12884 | { | |
12885 | printf (" STUB"); | |
12886 | val ^= DF_1_STUB; | |
12887 | } | |
12888 | if (val & DF_1_PIE) | |
12889 | { | |
12890 | printf (" PIE"); | |
12891 | val ^= DF_1_PIE; | |
12892 | } | |
12893 | if (val & DF_1_KMOD) | |
12894 | { | |
12895 | printf (" KMOD"); | |
12896 | val ^= DF_1_KMOD; | |
12897 | } | |
12898 | if (val & DF_1_WEAKFILTER) | |
12899 | { | |
12900 | printf (" WEAKFILTER"); | |
12901 | val ^= DF_1_WEAKFILTER; | |
12902 | } | |
12903 | if (val & DF_1_NOCOMMON) | |
12904 | { | |
12905 | printf (" NOCOMMON"); | |
12906 | val ^= DF_1_NOCOMMON; | |
12907 | } | |
12908 | if (val != 0) | |
12909 | printf (" %" PRIx64, val); | |
12910 | puts (""); | |
12911 | } | |
12912 | } | |
12913 | break; | |
12914 | ||
12915 | case DT_PLTREL: | |
12916 | filedata->dynamic_info[entry->d_tag] = entry->d_un.d_val; | |
12917 | if (do_dynamic) | |
12918 | puts (get_dynamic_type (filedata, entry->d_un.d_val)); | |
12919 | break; | |
12920 | ||
12921 | case DT_NULL : | |
12922 | case DT_NEEDED : | |
12923 | case DT_PLTGOT : | |
12924 | case DT_HASH : | |
12925 | case DT_STRTAB : | |
12926 | case DT_SYMTAB : | |
12927 | case DT_RELA : | |
12928 | case DT_INIT : | |
12929 | case DT_FINI : | |
12930 | case DT_SONAME : | |
12931 | case DT_RPATH : | |
12932 | case DT_SYMBOLIC: | |
12933 | case DT_REL : | |
12934 | case DT_RELR : | |
12935 | case DT_DEBUG : | |
12936 | case DT_TEXTREL : | |
12937 | case DT_JMPREL : | |
12938 | case DT_RUNPATH : | |
12939 | filedata->dynamic_info[entry->d_tag] = entry->d_un.d_val; | |
12940 | ||
12941 | if (do_dynamic) | |
12942 | { | |
12943 | const char *name; | |
12944 | ||
12945 | if (valid_dynamic_name (filedata, entry->d_un.d_val)) | |
12946 | name = get_dynamic_name (filedata, entry->d_un.d_val); | |
12947 | else | |
12948 | name = NULL; | |
12949 | ||
12950 | if (name) | |
12951 | { | |
12952 | switch (entry->d_tag) | |
12953 | { | |
12954 | case DT_NEEDED: | |
12955 | printf (_("Shared library: [%s]"), name); | |
12956 | ||
12957 | if (filedata->program_interpreter | |
12958 | && streq (name, filedata->program_interpreter)) | |
12959 | printf (_(" program interpreter")); | |
12960 | break; | |
12961 | ||
12962 | case DT_SONAME: | |
12963 | printf (_("Library soname: [%s]"), name); | |
12964 | break; | |
12965 | ||
12966 | case DT_RPATH: | |
12967 | printf (_("Library rpath: [%s]"), name); | |
12968 | break; | |
12969 | ||
12970 | case DT_RUNPATH: | |
12971 | printf (_("Library runpath: [%s]"), name); | |
12972 | break; | |
12973 | ||
12974 | default: | |
12975 | print_vma (entry->d_un.d_val, PREFIX_HEX); | |
12976 | break; | |
12977 | } | |
12978 | } | |
12979 | else | |
12980 | print_vma (entry->d_un.d_val, PREFIX_HEX); | |
12981 | ||
12982 | putchar ('\n'); | |
12983 | } | |
12984 | break; | |
12985 | ||
12986 | case DT_PLTRELSZ: | |
12987 | case DT_RELASZ : | |
12988 | case DT_STRSZ : | |
12989 | case DT_RELSZ : | |
12990 | case DT_RELAENT : | |
12991 | case DT_RELRENT : | |
12992 | case DT_RELRSZ : | |
12993 | case DT_SYMENT : | |
12994 | case DT_RELENT : | |
12995 | filedata->dynamic_info[entry->d_tag] = entry->d_un.d_val; | |
12996 | /* Fall through. */ | |
12997 | case DT_PLTPADSZ: | |
12998 | case DT_MOVEENT : | |
12999 | case DT_MOVESZ : | |
13000 | case DT_PREINIT_ARRAYSZ: | |
13001 | case DT_INIT_ARRAYSZ: | |
13002 | case DT_FINI_ARRAYSZ: | |
13003 | case DT_GNU_CONFLICTSZ: | |
13004 | case DT_GNU_LIBLISTSZ: | |
13005 | if (do_dynamic) | |
13006 | { | |
13007 | print_vma (entry->d_un.d_val, UNSIGNED); | |
13008 | printf (_(" (bytes)\n")); | |
13009 | } | |
13010 | break; | |
13011 | ||
13012 | case DT_VERDEFNUM: | |
13013 | case DT_VERNEEDNUM: | |
13014 | case DT_RELACOUNT: | |
13015 | case DT_RELCOUNT: | |
13016 | if (do_dynamic) | |
13017 | { | |
13018 | print_vma (entry->d_un.d_val, UNSIGNED); | |
13019 | putchar ('\n'); | |
13020 | } | |
13021 | break; | |
13022 | ||
13023 | case DT_SYMINSZ: | |
13024 | case DT_SYMINENT: | |
13025 | case DT_SYMINFO: | |
13026 | case DT_USED: | |
13027 | case DT_INIT_ARRAY: | |
13028 | case DT_FINI_ARRAY: | |
13029 | if (do_dynamic) | |
13030 | { | |
13031 | if (entry->d_tag == DT_USED | |
13032 | && valid_dynamic_name (filedata, entry->d_un.d_val)) | |
13033 | { | |
13034 | const char *name | |
13035 | = get_dynamic_name (filedata, entry->d_un.d_val); | |
13036 | ||
13037 | if (*name) | |
13038 | { | |
13039 | printf (_("Not needed object: [%s]\n"), name); | |
13040 | break; | |
13041 | } | |
13042 | } | |
13043 | ||
13044 | print_vma (entry->d_un.d_val, PREFIX_HEX); | |
13045 | putchar ('\n'); | |
13046 | } | |
13047 | break; | |
13048 | ||
13049 | case DT_BIND_NOW: | |
13050 | /* The value of this entry is ignored. */ | |
13051 | if (do_dynamic) | |
13052 | putchar ('\n'); | |
13053 | break; | |
13054 | ||
13055 | case DT_GNU_PRELINKED: | |
13056 | if (do_dynamic) | |
13057 | { | |
13058 | struct tm * tmp; | |
13059 | time_t atime = entry->d_un.d_val; | |
13060 | ||
13061 | tmp = gmtime (&atime); | |
13062 | /* PR 17533 file: 041-1244816-0.004. */ | |
13063 | if (tmp == NULL) | |
13064 | printf (_("<corrupt time val: %" PRIx64), | |
13065 | (uint64_t) atime); | |
13066 | else | |
13067 | printf ("%04u-%02u-%02uT%02u:%02u:%02u\n", | |
13068 | tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday, | |
13069 | tmp->tm_hour, tmp->tm_min, tmp->tm_sec); | |
13070 | ||
13071 | } | |
13072 | break; | |
13073 | ||
13074 | case DT_GNU_HASH: | |
13075 | filedata->dynamic_info_DT_GNU_HASH = entry->d_un.d_val; | |
13076 | if (do_dynamic) | |
13077 | { | |
13078 | print_vma (entry->d_un.d_val, PREFIX_HEX); | |
13079 | putchar ('\n'); | |
13080 | } | |
13081 | break; | |
13082 | ||
13083 | case DT_GNU_FLAGS_1: | |
13084 | if (do_dynamic) | |
13085 | { | |
13086 | printf (_("Flags:")); | |
13087 | if (entry->d_un.d_val == 0) | |
13088 | printf (_(" None\n")); | |
13089 | else | |
13090 | { | |
13091 | uint64_t val = entry->d_un.d_val; | |
13092 | ||
13093 | if (val & DF_GNU_1_UNIQUE) | |
13094 | { | |
13095 | printf (" UNIQUE"); | |
13096 | val ^= DF_GNU_1_UNIQUE; | |
13097 | } | |
13098 | if (val != 0) | |
13099 | printf (" %" PRIx64, val); | |
13100 | puts (""); | |
13101 | } | |
13102 | } | |
13103 | break; | |
13104 | ||
13105 | default: | |
13106 | if ((entry->d_tag >= DT_VERSYM) && (entry->d_tag <= DT_VERNEEDNUM)) | |
13107 | filedata->version_info[DT_VERSIONTAGIDX (entry->d_tag)] | |
13108 | = entry->d_un.d_val; | |
13109 | ||
13110 | if (do_dynamic) | |
13111 | { | |
13112 | switch (filedata->file_header.e_machine) | |
13113 | { | |
13114 | case EM_AARCH64: | |
13115 | dynamic_section_aarch64_val (entry); | |
13116 | break; | |
13117 | case EM_MIPS: | |
13118 | case EM_MIPS_RS3_LE: | |
13119 | dynamic_section_mips_val (filedata, entry); | |
13120 | break; | |
13121 | case EM_PARISC: | |
13122 | dynamic_section_parisc_val (entry); | |
13123 | break; | |
13124 | case EM_IA_64: | |
13125 | dynamic_section_ia64_val (entry); | |
13126 | break; | |
13127 | default: | |
13128 | print_vma (entry->d_un.d_val, PREFIX_HEX); | |
13129 | putchar ('\n'); | |
13130 | } | |
13131 | } | |
13132 | break; | |
13133 | } | |
13134 | } | |
13135 | ||
13136 | return true; | |
13137 | } | |
13138 | ||
13139 | static char * | |
13140 | get_ver_flags (unsigned int flags) | |
13141 | { | |
13142 | static char buff[128]; | |
13143 | ||
13144 | buff[0] = 0; | |
13145 | ||
13146 | if (flags == 0) | |
13147 | return _("none"); | |
13148 | ||
13149 | if (flags & VER_FLG_BASE) | |
13150 | strcat (buff, "BASE"); | |
13151 | ||
13152 | if (flags & VER_FLG_WEAK) | |
13153 | { | |
13154 | if (flags & VER_FLG_BASE) | |
13155 | strcat (buff, " | "); | |
13156 | ||
13157 | strcat (buff, "WEAK"); | |
13158 | } | |
13159 | ||
13160 | if (flags & VER_FLG_INFO) | |
13161 | { | |
13162 | if (flags & (VER_FLG_BASE|VER_FLG_WEAK)) | |
13163 | strcat (buff, " | "); | |
13164 | ||
13165 | strcat (buff, "INFO"); | |
13166 | } | |
13167 | ||
13168 | if (flags & ~(VER_FLG_BASE | VER_FLG_WEAK | VER_FLG_INFO)) | |
13169 | { | |
13170 | if (flags & (VER_FLG_BASE | VER_FLG_WEAK | VER_FLG_INFO)) | |
13171 | strcat (buff, " | "); | |
13172 | ||
13173 | strcat (buff, _("<unknown>")); | |
13174 | } | |
13175 | ||
13176 | return buff; | |
13177 | } | |
13178 | ||
13179 | /* Display the contents of the version sections. */ | |
13180 | ||
13181 | static bool | |
13182 | process_version_sections (Filedata * filedata) | |
13183 | { | |
13184 | Elf_Internal_Shdr * section; | |
13185 | unsigned i; | |
13186 | bool found = false; | |
13187 | ||
13188 | if (! do_version) | |
13189 | return true; | |
13190 | ||
13191 | for (i = 0, section = filedata->section_headers; | |
13192 | i < filedata->file_header.e_shnum; | |
13193 | i++, section++) | |
13194 | { | |
13195 | switch (section->sh_type) | |
13196 | { | |
13197 | case SHT_GNU_verdef: | |
13198 | { | |
13199 | Elf_External_Verdef * edefs; | |
13200 | size_t idx; | |
13201 | size_t cnt; | |
13202 | char * endbuf; | |
13203 | ||
13204 | found = true; | |
13205 | ||
13206 | if (filedata->is_separate) | |
13207 | printf (ngettext ("\nIn linked file '%s' the version definition section '%s' contains %u entry:\n", | |
13208 | "\nIn linked file '%s' the version definition section '%s' contains %u entries:\n", | |
13209 | section->sh_info), | |
13210 | filedata->file_name, | |
13211 | printable_section_name (filedata, section), | |
13212 | section->sh_info); | |
13213 | else | |
13214 | printf (ngettext ("\nVersion definition section '%s' " | |
13215 | "contains %u entry:\n", | |
13216 | "\nVersion definition section '%s' " | |
13217 | "contains %u entries:\n", | |
13218 | section->sh_info), | |
13219 | printable_section_name (filedata, section), | |
13220 | section->sh_info); | |
13221 | ||
13222 | printf (_(" Addr: 0x%016" PRIx64), section->sh_addr); | |
13223 | printf (_(" Offset: 0x%08" PRIx64 " Link: %u (%s)\n"), | |
13224 | section->sh_offset, section->sh_link, | |
13225 | printable_section_name_from_index (filedata, section->sh_link, NULL)); | |
13226 | ||
13227 | edefs = (Elf_External_Verdef *) | |
13228 | get_data (NULL, filedata, section->sh_offset, 1,section->sh_size, | |
13229 | _("version definition section")); | |
13230 | if (!edefs) | |
13231 | break; | |
13232 | endbuf = (char *) edefs + section->sh_size; | |
13233 | ||
13234 | for (idx = cnt = 0; cnt < section->sh_info; ++cnt) | |
13235 | { | |
13236 | char * vstart; | |
13237 | Elf_External_Verdef * edef; | |
13238 | Elf_Internal_Verdef ent; | |
13239 | Elf_External_Verdaux * eaux; | |
13240 | Elf_Internal_Verdaux aux; | |
13241 | size_t isum; | |
13242 | int j; | |
13243 | ||
13244 | vstart = ((char *) edefs) + idx; | |
13245 | if (vstart + sizeof (*edef) > endbuf) | |
13246 | break; | |
13247 | ||
13248 | edef = (Elf_External_Verdef *) vstart; | |
13249 | ||
13250 | ent.vd_version = BYTE_GET (edef->vd_version); | |
13251 | ent.vd_flags = BYTE_GET (edef->vd_flags); | |
13252 | ent.vd_ndx = BYTE_GET (edef->vd_ndx); | |
13253 | ent.vd_cnt = BYTE_GET (edef->vd_cnt); | |
13254 | ent.vd_hash = BYTE_GET (edef->vd_hash); | |
13255 | ent.vd_aux = BYTE_GET (edef->vd_aux); | |
13256 | ent.vd_next = BYTE_GET (edef->vd_next); | |
13257 | ||
13258 | printf (_(" %#06zx: Rev: %d Flags: %s"), | |
13259 | idx, ent.vd_version, get_ver_flags (ent.vd_flags)); | |
13260 | ||
13261 | printf (_(" Index: %d Cnt: %d "), | |
13262 | ent.vd_ndx, ent.vd_cnt); | |
13263 | ||
13264 | /* Check for overflow. */ | |
13265 | if (ent.vd_aux > (size_t) (endbuf - vstart)) | |
13266 | break; | |
13267 | ||
13268 | vstart += ent.vd_aux; | |
13269 | ||
13270 | if (vstart + sizeof (*eaux) > endbuf) | |
13271 | break; | |
13272 | eaux = (Elf_External_Verdaux *) vstart; | |
13273 | ||
13274 | aux.vda_name = BYTE_GET (eaux->vda_name); | |
13275 | aux.vda_next = BYTE_GET (eaux->vda_next); | |
13276 | ||
13277 | if (valid_dynamic_name (filedata, aux.vda_name)) | |
13278 | printf (_("Name: %s\n"), | |
13279 | get_dynamic_name (filedata, aux.vda_name)); | |
13280 | else | |
13281 | printf (_("Name index: %ld\n"), aux.vda_name); | |
13282 | ||
13283 | isum = idx + ent.vd_aux; | |
13284 | ||
13285 | for (j = 1; j < ent.vd_cnt; j++) | |
13286 | { | |
13287 | if (aux.vda_next < sizeof (*eaux) | |
13288 | && !(j == ent.vd_cnt - 1 && aux.vda_next == 0)) | |
13289 | { | |
13290 | warn (_("Invalid vda_next field of %lx\n"), | |
13291 | aux.vda_next); | |
13292 | j = ent.vd_cnt; | |
13293 | break; | |
13294 | } | |
13295 | /* Check for overflow. */ | |
13296 | if (aux.vda_next > (size_t) (endbuf - vstart)) | |
13297 | break; | |
13298 | ||
13299 | isum += aux.vda_next; | |
13300 | vstart += aux.vda_next; | |
13301 | ||
13302 | if (vstart + sizeof (*eaux) > endbuf) | |
13303 | break; | |
13304 | eaux = (Elf_External_Verdaux *) vstart; | |
13305 | ||
13306 | aux.vda_name = BYTE_GET (eaux->vda_name); | |
13307 | aux.vda_next = BYTE_GET (eaux->vda_next); | |
13308 | ||
13309 | if (valid_dynamic_name (filedata, aux.vda_name)) | |
13310 | printf (_(" %#06zx: Parent %d: %s\n"), | |
13311 | isum, j, | |
13312 | get_dynamic_name (filedata, aux.vda_name)); | |
13313 | else | |
13314 | printf (_(" %#06zx: Parent %d, name index: %ld\n"), | |
13315 | isum, j, aux.vda_name); | |
13316 | } | |
13317 | ||
13318 | if (j < ent.vd_cnt) | |
13319 | printf (_(" Version def aux past end of section\n")); | |
13320 | ||
13321 | /* PR 17531: | |
13322 | file: id:000001,src:000172+005151,op:splice,rep:2. */ | |
13323 | if (ent.vd_next < sizeof (*edef) | |
13324 | && !(cnt == section->sh_info - 1 && ent.vd_next == 0)) | |
13325 | { | |
13326 | warn (_("Invalid vd_next field of %lx\n"), ent.vd_next); | |
13327 | cnt = section->sh_info; | |
13328 | break; | |
13329 | } | |
13330 | if (ent.vd_next > (size_t) (endbuf - ((char *) edefs + idx))) | |
13331 | break; | |
13332 | ||
13333 | idx += ent.vd_next; | |
13334 | } | |
13335 | ||
13336 | if (cnt < section->sh_info) | |
13337 | printf (_(" Version definition past end of section\n")); | |
13338 | ||
13339 | free (edefs); | |
13340 | } | |
13341 | break; | |
13342 | ||
13343 | case SHT_GNU_verneed: | |
13344 | { | |
13345 | Elf_External_Verneed * eneed; | |
13346 | size_t idx; | |
13347 | size_t cnt; | |
13348 | char * endbuf; | |
13349 | ||
13350 | found = true; | |
13351 | ||
13352 | if (filedata->is_separate) | |
13353 | printf (ngettext ("\nIn linked file '%s' the version needs section '%s' contains %u entry:\n", | |
13354 | "\nIn linked file '%s' the version needs section '%s' contains %u entries:\n", | |
13355 | section->sh_info), | |
13356 | filedata->file_name, | |
13357 | printable_section_name (filedata, section), | |
13358 | section->sh_info); | |
13359 | else | |
13360 | printf (ngettext ("\nVersion needs section '%s' " | |
13361 | "contains %u entry:\n", | |
13362 | "\nVersion needs section '%s' " | |
13363 | "contains %u entries:\n", | |
13364 | section->sh_info), | |
13365 | printable_section_name (filedata, section), | |
13366 | section->sh_info); | |
13367 | ||
13368 | printf (_(" Addr: 0x%016" PRIx64), section->sh_addr); | |
13369 | printf (_(" Offset: 0x%08" PRIx64 " Link: %u (%s)\n"), | |
13370 | section->sh_offset, section->sh_link, | |
13371 | printable_section_name_from_index (filedata, section->sh_link, NULL)); | |
13372 | ||
13373 | eneed = (Elf_External_Verneed *) get_data (NULL, filedata, | |
13374 | section->sh_offset, 1, | |
13375 | section->sh_size, | |
13376 | _("Version Needs section")); | |
13377 | if (!eneed) | |
13378 | break; | |
13379 | endbuf = (char *) eneed + section->sh_size; | |
13380 | ||
13381 | for (idx = cnt = 0; cnt < section->sh_info; ++cnt) | |
13382 | { | |
13383 | Elf_External_Verneed * entry; | |
13384 | Elf_Internal_Verneed ent; | |
13385 | size_t isum; | |
13386 | int j; | |
13387 | char * vstart; | |
13388 | ||
13389 | vstart = ((char *) eneed) + idx; | |
13390 | if (vstart + sizeof (*entry) > endbuf) | |
13391 | break; | |
13392 | ||
13393 | entry = (Elf_External_Verneed *) vstart; | |
13394 | ||
13395 | ent.vn_version = BYTE_GET (entry->vn_version); | |
13396 | ent.vn_cnt = BYTE_GET (entry->vn_cnt); | |
13397 | ent.vn_file = BYTE_GET (entry->vn_file); | |
13398 | ent.vn_aux = BYTE_GET (entry->vn_aux); | |
13399 | ent.vn_next = BYTE_GET (entry->vn_next); | |
13400 | ||
13401 | printf (_(" %#06zx: Version: %d"), idx, ent.vn_version); | |
13402 | ||
13403 | if (valid_dynamic_name (filedata, ent.vn_file)) | |
13404 | printf (_(" File: %s"), | |
13405 | get_dynamic_name (filedata, ent.vn_file)); | |
13406 | else | |
13407 | printf (_(" File: %lx"), ent.vn_file); | |
13408 | ||
13409 | printf (_(" Cnt: %d\n"), ent.vn_cnt); | |
13410 | ||
13411 | /* Check for overflow. */ | |
13412 | if (ent.vn_aux > (size_t) (endbuf - vstart)) | |
13413 | break; | |
13414 | vstart += ent.vn_aux; | |
13415 | ||
13416 | for (j = 0, isum = idx + ent.vn_aux; j < ent.vn_cnt; ++j) | |
13417 | { | |
13418 | Elf_External_Vernaux * eaux; | |
13419 | Elf_Internal_Vernaux aux; | |
13420 | ||
13421 | if (vstart + sizeof (*eaux) > endbuf) | |
13422 | break; | |
13423 | eaux = (Elf_External_Vernaux *) vstart; | |
13424 | ||
13425 | aux.vna_hash = BYTE_GET (eaux->vna_hash); | |
13426 | aux.vna_flags = BYTE_GET (eaux->vna_flags); | |
13427 | aux.vna_other = BYTE_GET (eaux->vna_other); | |
13428 | aux.vna_name = BYTE_GET (eaux->vna_name); | |
13429 | aux.vna_next = BYTE_GET (eaux->vna_next); | |
13430 | ||
13431 | if (valid_dynamic_name (filedata, aux.vna_name)) | |
13432 | printf (_(" %#06zx: Name: %s"), | |
13433 | isum, get_dynamic_name (filedata, aux.vna_name)); | |
13434 | else | |
13435 | printf (_(" %#06zx: Name index: %lx"), | |
13436 | isum, aux.vna_name); | |
13437 | ||
13438 | printf (_(" Flags: %s Version: %d\n"), | |
13439 | get_ver_flags (aux.vna_flags), aux.vna_other); | |
13440 | ||
13441 | if (aux.vna_next < sizeof (*eaux) | |
13442 | && !(j == ent.vn_cnt - 1 && aux.vna_next == 0)) | |
13443 | { | |
13444 | warn (_("Invalid vna_next field of %lx\n"), | |
13445 | aux.vna_next); | |
13446 | j = ent.vn_cnt; | |
13447 | break; | |
13448 | } | |
13449 | /* Check for overflow. */ | |
13450 | if (aux.vna_next > (size_t) (endbuf - vstart)) | |
13451 | break; | |
13452 | isum += aux.vna_next; | |
13453 | vstart += aux.vna_next; | |
13454 | } | |
13455 | ||
13456 | if (j < ent.vn_cnt) | |
13457 | warn (_("Missing Version Needs auxiliary information\n")); | |
13458 | ||
13459 | if (ent.vn_next < sizeof (*entry) | |
13460 | && !(cnt == section->sh_info - 1 && ent.vn_next == 0)) | |
13461 | { | |
13462 | warn (_("Invalid vn_next field of %lx\n"), ent.vn_next); | |
13463 | cnt = section->sh_info; | |
13464 | break; | |
13465 | } | |
13466 | if (ent.vn_next > (size_t) (endbuf - ((char *) eneed + idx))) | |
13467 | break; | |
13468 | idx += ent.vn_next; | |
13469 | } | |
13470 | ||
13471 | if (cnt < section->sh_info) | |
13472 | warn (_("Missing Version Needs information\n")); | |
13473 | ||
13474 | free (eneed); | |
13475 | } | |
13476 | break; | |
13477 | ||
13478 | case SHT_GNU_versym: | |
13479 | { | |
13480 | Elf_Internal_Shdr * link_section; | |
13481 | uint64_t total; | |
13482 | unsigned int cnt; | |
13483 | unsigned char * edata; | |
13484 | unsigned short * data; | |
13485 | char * strtab; | |
13486 | Elf_Internal_Sym * symbols; | |
13487 | Elf_Internal_Shdr * string_sec; | |
13488 | uint64_t num_syms; | |
13489 | uint64_t off; | |
13490 | ||
13491 | if (section->sh_link >= filedata->file_header.e_shnum) | |
13492 | break; | |
13493 | ||
13494 | link_section = filedata->section_headers + section->sh_link; | |
13495 | total = section->sh_size / sizeof (Elf_External_Versym); | |
13496 | ||
13497 | if (link_section->sh_link >= filedata->file_header.e_shnum) | |
13498 | break; | |
13499 | ||
13500 | found = true; | |
13501 | ||
13502 | symbols = get_elf_symbols (filedata, link_section, & num_syms); | |
13503 | if (symbols == NULL) | |
13504 | break; | |
13505 | ||
13506 | string_sec = filedata->section_headers + link_section->sh_link; | |
13507 | ||
13508 | strtab = (char *) get_data (NULL, filedata, string_sec->sh_offset, 1, | |
13509 | string_sec->sh_size, | |
13510 | _("version string table")); | |
13511 | if (!strtab) | |
13512 | { | |
13513 | free (symbols); | |
13514 | break; | |
13515 | } | |
13516 | ||
13517 | if (filedata->is_separate) | |
13518 | printf (ngettext ("\nIn linked file '%s' the version symbols section '%s' contains %" PRIu64 " entry:\n", | |
13519 | "\nIn linked file '%s' the version symbols section '%s' contains %" PRIu64 " entries:\n", | |
13520 | total), | |
13521 | filedata->file_name, | |
13522 | printable_section_name (filedata, section), | |
13523 | total); | |
13524 | else | |
13525 | printf (ngettext ("\nVersion symbols section '%s' " | |
13526 | "contains %" PRIu64 " entry:\n", | |
13527 | "\nVersion symbols section '%s' " | |
13528 | "contains %" PRIu64 " entries:\n", | |
13529 | total), | |
13530 | printable_section_name (filedata, section), | |
13531 | total); | |
13532 | ||
13533 | printf (_(" Addr: 0x%016" PRIx64), section->sh_addr); | |
13534 | printf (_(" Offset: 0x%08" PRIx64 " Link: %u (%s)\n"), | |
13535 | section->sh_offset, section->sh_link, | |
13536 | printable_section_name (filedata, link_section)); | |
13537 | ||
13538 | off = offset_from_vma (filedata, | |
13539 | filedata->version_info[DT_VERSIONTAGIDX (DT_VERSYM)], | |
13540 | total * sizeof (short)); | |
13541 | edata = (unsigned char *) get_data (NULL, filedata, off, | |
13542 | sizeof (short), total, | |
13543 | _("version symbol data")); | |
13544 | if (!edata) | |
13545 | { | |
13546 | free (strtab); | |
13547 | free (symbols); | |
13548 | break; | |
13549 | } | |
13550 | ||
13551 | data = (short unsigned int *) cmalloc (total, sizeof (short)); | |
13552 | ||
13553 | for (cnt = total; cnt --;) | |
13554 | data[cnt] = byte_get (edata + cnt * sizeof (short), | |
13555 | sizeof (short)); | |
13556 | ||
13557 | free (edata); | |
13558 | ||
13559 | for (cnt = 0; cnt < total; cnt += 4) | |
13560 | { | |
13561 | int j, nn; | |
13562 | char *name; | |
13563 | char *invalid = _("*invalid*"); | |
13564 | ||
13565 | printf (" %03x:", cnt); | |
13566 | ||
13567 | for (j = 0; (j < 4) && (cnt + j) < total; ++j) | |
13568 | switch (data[cnt + j]) | |
13569 | { | |
13570 | case 0: | |
13571 | fputs (_(" 0 (*local*) "), stdout); | |
13572 | break; | |
13573 | ||
13574 | case 1: | |
13575 | fputs (_(" 1 (*global*) "), stdout); | |
13576 | break; | |
13577 | ||
13578 | default: | |
13579 | nn = printf ("%4x%c", data[cnt + j] & VERSYM_VERSION, | |
13580 | data[cnt + j] & VERSYM_HIDDEN ? 'h' : ' '); | |
13581 | ||
13582 | /* If this index value is greater than the size of the symbols | |
13583 | array, break to avoid an out-of-bounds read. */ | |
13584 | if (cnt + j >= num_syms) | |
13585 | { | |
13586 | warn (_("invalid index into symbol array\n")); | |
13587 | break; | |
13588 | } | |
13589 | ||
13590 | name = NULL; | |
13591 | if (filedata->version_info[DT_VERSIONTAGIDX (DT_VERNEED)]) | |
13592 | { | |
13593 | Elf_Internal_Verneed ivn; | |
13594 | uint64_t offset; | |
13595 | ||
13596 | offset = offset_from_vma | |
13597 | (filedata, | |
13598 | filedata->version_info[DT_VERSIONTAGIDX (DT_VERNEED)], | |
13599 | sizeof (Elf_External_Verneed)); | |
13600 | ||
13601 | do | |
13602 | { | |
13603 | Elf_Internal_Vernaux ivna; | |
13604 | Elf_External_Verneed evn; | |
13605 | Elf_External_Vernaux evna; | |
13606 | uint64_t a_off; | |
13607 | ||
13608 | if (get_data (&evn, filedata, offset, sizeof (evn), 1, | |
13609 | _("version need")) == NULL) | |
13610 | break; | |
13611 | ||
13612 | ivn.vn_aux = BYTE_GET (evn.vn_aux); | |
13613 | ivn.vn_next = BYTE_GET (evn.vn_next); | |
13614 | ||
13615 | a_off = offset + ivn.vn_aux; | |
13616 | ||
13617 | do | |
13618 | { | |
13619 | if (get_data (&evna, filedata, a_off, sizeof (evna), | |
13620 | 1, _("version need aux (2)")) == NULL) | |
13621 | { | |
13622 | ivna.vna_next = 0; | |
13623 | ivna.vna_other = 0; | |
13624 | } | |
13625 | else | |
13626 | { | |
13627 | ivna.vna_next = BYTE_GET (evna.vna_next); | |
13628 | ivna.vna_other = BYTE_GET (evna.vna_other); | |
13629 | } | |
13630 | ||
13631 | a_off += ivna.vna_next; | |
13632 | } | |
13633 | while (ivna.vna_other != data[cnt + j] | |
13634 | && ivna.vna_next != 0); | |
13635 | ||
13636 | if (ivna.vna_other == data[cnt + j]) | |
13637 | { | |
13638 | ivna.vna_name = BYTE_GET (evna.vna_name); | |
13639 | ||
13640 | if (ivna.vna_name >= string_sec->sh_size) | |
13641 | name = invalid; | |
13642 | else | |
13643 | name = strtab + ivna.vna_name; | |
13644 | break; | |
13645 | } | |
13646 | ||
13647 | offset += ivn.vn_next; | |
13648 | } | |
13649 | while (ivn.vn_next); | |
13650 | } | |
13651 | ||
13652 | if (data[cnt + j] != 0x8001 | |
13653 | && filedata->version_info[DT_VERSIONTAGIDX (DT_VERDEF)]) | |
13654 | { | |
13655 | Elf_Internal_Verdef ivd; | |
13656 | Elf_External_Verdef evd; | |
13657 | uint64_t offset; | |
13658 | ||
13659 | offset = offset_from_vma | |
13660 | (filedata, | |
13661 | filedata->version_info[DT_VERSIONTAGIDX (DT_VERDEF)], | |
13662 | sizeof evd); | |
13663 | ||
13664 | do | |
13665 | { | |
13666 | if (get_data (&evd, filedata, offset, sizeof (evd), 1, | |
13667 | _("version def")) == NULL) | |
13668 | { | |
13669 | ivd.vd_next = 0; | |
13670 | /* PR 17531: file: 046-1082287-0.004. */ | |
13671 | ivd.vd_ndx = (data[cnt + j] & VERSYM_VERSION) + 1; | |
13672 | break; | |
13673 | } | |
13674 | else | |
13675 | { | |
13676 | ivd.vd_next = BYTE_GET (evd.vd_next); | |
13677 | ivd.vd_ndx = BYTE_GET (evd.vd_ndx); | |
13678 | } | |
13679 | ||
13680 | offset += ivd.vd_next; | |
13681 | } | |
13682 | while (ivd.vd_ndx != (data[cnt + j] & VERSYM_VERSION) | |
13683 | && ivd.vd_next != 0); | |
13684 | ||
13685 | if (ivd.vd_ndx == (data[cnt + j] & VERSYM_VERSION)) | |
13686 | { | |
13687 | Elf_External_Verdaux evda; | |
13688 | Elf_Internal_Verdaux ivda; | |
13689 | ||
13690 | ivd.vd_aux = BYTE_GET (evd.vd_aux); | |
13691 | ||
13692 | if (get_data (&evda, filedata, | |
13693 | offset - ivd.vd_next + ivd.vd_aux, | |
13694 | sizeof (evda), 1, | |
13695 | _("version def aux")) == NULL) | |
13696 | break; | |
13697 | ||
13698 | ivda.vda_name = BYTE_GET (evda.vda_name); | |
13699 | ||
13700 | if (ivda.vda_name >= string_sec->sh_size) | |
13701 | name = invalid; | |
13702 | else if (name != NULL && name != invalid) | |
13703 | name = _("*both*"); | |
13704 | else | |
13705 | name = strtab + ivda.vda_name; | |
13706 | } | |
13707 | } | |
13708 | if (name != NULL) | |
13709 | nn += printf ("(%s%-*s", | |
13710 | name, | |
13711 | 12 - (int) strlen (name), | |
13712 | ")"); | |
13713 | ||
13714 | if (nn < 18) | |
13715 | printf ("%*c", 18 - nn, ' '); | |
13716 | } | |
13717 | ||
13718 | putchar ('\n'); | |
13719 | } | |
13720 | ||
13721 | free (data); | |
13722 | free (strtab); | |
13723 | free (symbols); | |
13724 | } | |
13725 | break; | |
13726 | ||
13727 | default: | |
13728 | break; | |
13729 | } | |
13730 | } | |
13731 | ||
13732 | if (! found) | |
13733 | { | |
13734 | if (filedata->is_separate) | |
13735 | printf (_("\nNo version information found in linked file '%s'.\n"), | |
13736 | filedata->file_name); | |
13737 | else | |
13738 | printf (_("\nNo version information found in this file.\n")); | |
13739 | } | |
13740 | ||
13741 | return true; | |
13742 | } | |
13743 | ||
13744 | static const char * | |
13745 | get_symbol_binding (Filedata * filedata, unsigned int binding) | |
13746 | { | |
13747 | static char buff[64]; | |
13748 | ||
13749 | switch (binding) | |
13750 | { | |
13751 | case STB_LOCAL: return "LOCAL"; | |
13752 | case STB_GLOBAL: return "GLOBAL"; | |
13753 | case STB_WEAK: return "WEAK"; | |
13754 | default: | |
13755 | if (binding >= STB_LOPROC && binding <= STB_HIPROC) | |
13756 | snprintf (buff, sizeof (buff), _("<processor specific>: %d"), | |
13757 | binding); | |
13758 | else if (binding >= STB_LOOS && binding <= STB_HIOS) | |
13759 | { | |
13760 | if (binding == STB_GNU_UNIQUE | |
13761 | && filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_GNU) | |
13762 | return "UNIQUE"; | |
13763 | snprintf (buff, sizeof (buff), _("<OS specific>: %d"), binding); | |
13764 | } | |
13765 | else | |
13766 | snprintf (buff, sizeof (buff), _("<unknown>: %d"), binding); | |
13767 | return buff; | |
13768 | } | |
13769 | } | |
13770 | ||
13771 | static const char * | |
13772 | get_symbol_type (Filedata * filedata, unsigned int type) | |
13773 | { | |
13774 | static char buff[64]; | |
13775 | ||
13776 | switch (type) | |
13777 | { | |
13778 | case STT_NOTYPE: return "NOTYPE"; | |
13779 | case STT_OBJECT: return "OBJECT"; | |
13780 | case STT_FUNC: return "FUNC"; | |
13781 | case STT_SECTION: return "SECTION"; | |
13782 | case STT_FILE: return "FILE"; | |
13783 | case STT_COMMON: return "COMMON"; | |
13784 | case STT_TLS: return "TLS"; | |
13785 | case STT_RELC: return "RELC"; | |
13786 | case STT_SRELC: return "SRELC"; | |
13787 | default: | |
13788 | if (type >= STT_LOPROC && type <= STT_HIPROC) | |
13789 | { | |
13790 | if (filedata->file_header.e_machine == EM_ARM && type == STT_ARM_TFUNC) | |
13791 | return "THUMB_FUNC"; | |
13792 | ||
13793 | if (filedata->file_header.e_machine == EM_SPARCV9 && type == STT_REGISTER) | |
13794 | return "REGISTER"; | |
13795 | ||
13796 | if (filedata->file_header.e_machine == EM_PARISC && type == STT_PARISC_MILLI) | |
13797 | return "PARISC_MILLI"; | |
13798 | ||
13799 | snprintf (buff, sizeof (buff), _("<processor specific>: %d"), type); | |
13800 | } | |
13801 | else if (type >= STT_LOOS && type <= STT_HIOS) | |
13802 | { | |
13803 | if (filedata->file_header.e_machine == EM_PARISC) | |
13804 | { | |
13805 | if (type == STT_HP_OPAQUE) | |
13806 | return "HP_OPAQUE"; | |
13807 | if (type == STT_HP_STUB) | |
13808 | return "HP_STUB"; | |
13809 | } | |
13810 | ||
13811 | if (type == STT_GNU_IFUNC | |
13812 | && (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_GNU | |
13813 | || filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_FREEBSD)) | |
13814 | return "IFUNC"; | |
13815 | ||
13816 | snprintf (buff, sizeof (buff), _("<OS specific>: %d"), type); | |
13817 | } | |
13818 | else | |
13819 | snprintf (buff, sizeof (buff), _("<unknown>: %d"), type); | |
13820 | return buff; | |
13821 | } | |
13822 | } | |
13823 | ||
13824 | static const char * | |
13825 | get_symbol_visibility (unsigned int visibility) | |
13826 | { | |
13827 | switch (visibility) | |
13828 | { | |
13829 | case STV_DEFAULT: return "DEFAULT"; | |
13830 | case STV_INTERNAL: return "INTERNAL"; | |
13831 | case STV_HIDDEN: return "HIDDEN"; | |
13832 | case STV_PROTECTED: return "PROTECTED"; | |
13833 | default: | |
13834 | error (_("Unrecognized visibility value: %u\n"), visibility); | |
13835 | return _("<unknown>"); | |
13836 | } | |
13837 | } | |
13838 | ||
13839 | static const char * | |
13840 | get_alpha_symbol_other (unsigned int other) | |
13841 | { | |
13842 | switch (other) | |
13843 | { | |
13844 | case STO_ALPHA_NOPV: return "NOPV"; | |
13845 | case STO_ALPHA_STD_GPLOAD: return "STD GPLOAD"; | |
13846 | default: | |
13847 | error (_("Unrecognized alpha specific other value: %u\n"), other); | |
13848 | return _("<unknown>"); | |
13849 | } | |
13850 | } | |
13851 | ||
13852 | static const char * | |
13853 | get_solaris_symbol_visibility (unsigned int visibility) | |
13854 | { | |
13855 | switch (visibility) | |
13856 | { | |
13857 | case 4: return "EXPORTED"; | |
13858 | case 5: return "SINGLETON"; | |
13859 | case 6: return "ELIMINATE"; | |
13860 | default: return get_symbol_visibility (visibility); | |
13861 | } | |
13862 | } | |
13863 | ||
13864 | static const char * | |
13865 | get_aarch64_symbol_other (unsigned int other) | |
13866 | { | |
13867 | static char buf[32]; | |
13868 | ||
13869 | if (other & STO_AARCH64_VARIANT_PCS) | |
13870 | { | |
13871 | other &= ~STO_AARCH64_VARIANT_PCS; | |
13872 | if (other == 0) | |
13873 | return "VARIANT_PCS"; | |
13874 | snprintf (buf, sizeof buf, "VARIANT_PCS | %x", other); | |
13875 | return buf; | |
13876 | } | |
13877 | return NULL; | |
13878 | } | |
13879 | ||
13880 | static const char * | |
13881 | get_mips_symbol_other (unsigned int other) | |
13882 | { | |
13883 | switch (other) | |
13884 | { | |
13885 | case STO_OPTIONAL: return "OPTIONAL"; | |
13886 | case STO_MIPS_PLT: return "MIPS PLT"; | |
13887 | case STO_MIPS_PIC: return "MIPS PIC"; | |
13888 | case STO_MICROMIPS: return "MICROMIPS"; | |
13889 | case STO_MICROMIPS | STO_MIPS_PIC: return "MICROMIPS, MIPS PIC"; | |
13890 | case STO_MIPS16: return "MIPS16"; | |
13891 | default: return NULL; | |
13892 | } | |
13893 | } | |
13894 | ||
13895 | static const char * | |
13896 | get_ia64_symbol_other (Filedata * filedata, unsigned int other) | |
13897 | { | |
13898 | if (is_ia64_vms (filedata)) | |
13899 | { | |
13900 | static char res[32]; | |
13901 | ||
13902 | res[0] = 0; | |
13903 | ||
13904 | /* Function types is for images and .STB files only. */ | |
13905 | switch (filedata->file_header.e_type) | |
13906 | { | |
13907 | case ET_DYN: | |
13908 | case ET_EXEC: | |
13909 | switch (VMS_ST_FUNC_TYPE (other)) | |
13910 | { | |
13911 | case VMS_SFT_CODE_ADDR: | |
13912 | strcat (res, " CA"); | |
13913 | break; | |
13914 | case VMS_SFT_SYMV_IDX: | |
13915 | strcat (res, " VEC"); | |
13916 | break; | |
13917 | case VMS_SFT_FD: | |
13918 | strcat (res, " FD"); | |
13919 | break; | |
13920 | case VMS_SFT_RESERVE: | |
13921 | strcat (res, " RSV"); | |
13922 | break; | |
13923 | default: | |
13924 | warn (_("Unrecognized IA64 VMS ST Function type: %d\n"), | |
13925 | VMS_ST_FUNC_TYPE (other)); | |
13926 | strcat (res, " <unknown>"); | |
13927 | break; | |
13928 | } | |
13929 | break; | |
13930 | default: | |
13931 | break; | |
13932 | } | |
13933 | switch (VMS_ST_LINKAGE (other)) | |
13934 | { | |
13935 | case VMS_STL_IGNORE: | |
13936 | strcat (res, " IGN"); | |
13937 | break; | |
13938 | case VMS_STL_RESERVE: | |
13939 | strcat (res, " RSV"); | |
13940 | break; | |
13941 | case VMS_STL_STD: | |
13942 | strcat (res, " STD"); | |
13943 | break; | |
13944 | case VMS_STL_LNK: | |
13945 | strcat (res, " LNK"); | |
13946 | break; | |
13947 | default: | |
13948 | warn (_("Unrecognized IA64 VMS ST Linkage: %d\n"), | |
13949 | VMS_ST_LINKAGE (other)); | |
13950 | strcat (res, " <unknown>"); | |
13951 | break; | |
13952 | } | |
13953 | ||
13954 | if (res[0] != 0) | |
13955 | return res + 1; | |
13956 | else | |
13957 | return res; | |
13958 | } | |
13959 | return NULL; | |
13960 | } | |
13961 | ||
13962 | static const char * | |
13963 | get_ppc64_symbol_other (unsigned int other) | |
13964 | { | |
13965 | if ((other & ~STO_PPC64_LOCAL_MASK) != 0) | |
13966 | return NULL; | |
13967 | ||
13968 | other >>= STO_PPC64_LOCAL_BIT; | |
13969 | if (other <= 6) | |
13970 | { | |
13971 | static char buf[64]; | |
13972 | if (other >= 2) | |
13973 | other = ppc64_decode_local_entry (other); | |
13974 | snprintf (buf, sizeof buf, _("<localentry>: %d"), other); | |
13975 | return buf; | |
13976 | } | |
13977 | return NULL; | |
13978 | } | |
13979 | ||
13980 | static const char * | |
13981 | get_riscv_symbol_other (unsigned int other) | |
13982 | { | |
13983 | static char buf[32]; | |
13984 | buf[0] = 0; | |
13985 | ||
13986 | if (other & STO_RISCV_VARIANT_CC) | |
13987 | { | |
13988 | strcat (buf, _(" VARIANT_CC")); | |
13989 | other &= ~STO_RISCV_VARIANT_CC; | |
13990 | } | |
13991 | ||
13992 | if (other != 0) | |
13993 | snprintf (buf, sizeof buf, " %x", other); | |
13994 | ||
13995 | ||
13996 | if (buf[0] != 0) | |
13997 | return buf + 1; | |
13998 | else | |
13999 | return buf; | |
14000 | } | |
14001 | ||
14002 | static const char * | |
14003 | get_symbol_other (Filedata * filedata, unsigned int other) | |
14004 | { | |
14005 | const char * result = NULL; | |
14006 | static char buff [64]; | |
14007 | ||
14008 | if (other == 0) | |
14009 | return ""; | |
14010 | ||
14011 | switch (filedata->file_header.e_machine) | |
14012 | { | |
14013 | case EM_ALPHA: | |
14014 | result = get_alpha_symbol_other (other); | |
14015 | break; | |
14016 | case EM_AARCH64: | |
14017 | result = get_aarch64_symbol_other (other); | |
14018 | break; | |
14019 | case EM_MIPS: | |
14020 | result = get_mips_symbol_other (other); | |
14021 | break; | |
14022 | case EM_IA_64: | |
14023 | result = get_ia64_symbol_other (filedata, other); | |
14024 | break; | |
14025 | case EM_PPC64: | |
14026 | result = get_ppc64_symbol_other (other); | |
14027 | break; | |
14028 | case EM_RISCV: | |
14029 | result = get_riscv_symbol_other (other); | |
14030 | break; | |
14031 | default: | |
14032 | result = NULL; | |
14033 | break; | |
14034 | } | |
14035 | ||
14036 | if (result) | |
14037 | return result; | |
14038 | ||
14039 | snprintf (buff, sizeof buff, _("<other>: %x"), other); | |
14040 | return buff; | |
14041 | } | |
14042 | ||
14043 | static const char * | |
14044 | get_symbol_version_string (Filedata *filedata, | |
14045 | bool is_dynsym, | |
14046 | const char *strtab, | |
14047 | size_t strtab_size, | |
14048 | unsigned int si, | |
14049 | Elf_Internal_Sym *psym, | |
14050 | enum versioned_symbol_info *sym_info, | |
14051 | unsigned short *vna_other) | |
14052 | { | |
14053 | unsigned char data[2]; | |
14054 | unsigned short vers_data; | |
14055 | uint64_t offset; | |
14056 | unsigned short max_vd_ndx; | |
14057 | ||
14058 | if (!is_dynsym | |
14059 | || filedata->version_info[DT_VERSIONTAGIDX (DT_VERSYM)] == 0) | |
14060 | return NULL; | |
14061 | ||
14062 | offset = offset_from_vma (filedata, | |
14063 | filedata->version_info[DT_VERSIONTAGIDX (DT_VERSYM)], | |
14064 | sizeof data + si * sizeof (vers_data)); | |
14065 | ||
14066 | if (get_data (&data, filedata, offset + si * sizeof (vers_data), | |
14067 | sizeof (data), 1, _("version data")) == NULL) | |
14068 | return NULL; | |
14069 | ||
14070 | vers_data = byte_get (data, 2); | |
14071 | ||
14072 | if ((vers_data & VERSYM_HIDDEN) == 0 && vers_data == 0) | |
14073 | return NULL; | |
14074 | ||
14075 | *sym_info = (vers_data & VERSYM_HIDDEN) != 0 ? symbol_hidden : symbol_public; | |
14076 | max_vd_ndx = 0; | |
14077 | ||
14078 | /* Usually we'd only see verdef for defined symbols, and verneed for | |
14079 | undefined symbols. However, symbols defined by the linker in | |
14080 | .dynbss for variables copied from a shared library in order to | |
14081 | avoid text relocations are defined yet have verneed. We could | |
14082 | use a heuristic to detect the special case, for example, check | |
14083 | for verneed first on symbols defined in SHT_NOBITS sections, but | |
14084 | it is simpler and more reliable to just look for both verdef and | |
14085 | verneed. .dynbss might not be mapped to a SHT_NOBITS section. */ | |
14086 | ||
14087 | if (psym->st_shndx != SHN_UNDEF | |
14088 | && vers_data != 0x8001 | |
14089 | && filedata->version_info[DT_VERSIONTAGIDX (DT_VERDEF)]) | |
14090 | { | |
14091 | Elf_Internal_Verdef ivd; | |
14092 | Elf_Internal_Verdaux ivda; | |
14093 | Elf_External_Verdaux evda; | |
14094 | uint64_t off; | |
14095 | ||
14096 | off = offset_from_vma (filedata, | |
14097 | filedata->version_info[DT_VERSIONTAGIDX (DT_VERDEF)], | |
14098 | sizeof (Elf_External_Verdef)); | |
14099 | ||
14100 | do | |
14101 | { | |
14102 | Elf_External_Verdef evd; | |
14103 | ||
14104 | if (get_data (&evd, filedata, off, sizeof (evd), 1, | |
14105 | _("version def")) == NULL) | |
14106 | { | |
14107 | ivd.vd_ndx = 0; | |
14108 | ivd.vd_aux = 0; | |
14109 | ivd.vd_next = 0; | |
14110 | ivd.vd_flags = 0; | |
14111 | } | |
14112 | else | |
14113 | { | |
14114 | ivd.vd_ndx = BYTE_GET (evd.vd_ndx); | |
14115 | ivd.vd_aux = BYTE_GET (evd.vd_aux); | |
14116 | ivd.vd_next = BYTE_GET (evd.vd_next); | |
14117 | ivd.vd_flags = BYTE_GET (evd.vd_flags); | |
14118 | } | |
14119 | ||
14120 | if ((ivd.vd_ndx & VERSYM_VERSION) > max_vd_ndx) | |
14121 | max_vd_ndx = ivd.vd_ndx & VERSYM_VERSION; | |
14122 | ||
14123 | off += ivd.vd_next; | |
14124 | } | |
14125 | while (ivd.vd_ndx != (vers_data & VERSYM_VERSION) && ivd.vd_next != 0); | |
14126 | ||
14127 | if (ivd.vd_ndx == (vers_data & VERSYM_VERSION)) | |
14128 | { | |
14129 | if (ivd.vd_ndx == 1 && ivd.vd_flags == VER_FLG_BASE) | |
14130 | return NULL; | |
14131 | ||
14132 | off -= ivd.vd_next; | |
14133 | off += ivd.vd_aux; | |
14134 | ||
14135 | if (get_data (&evda, filedata, off, sizeof (evda), 1, | |
14136 | _("version def aux")) != NULL) | |
14137 | { | |
14138 | ivda.vda_name = BYTE_GET (evda.vda_name); | |
14139 | ||
14140 | if (psym->st_name != ivda.vda_name) | |
14141 | return (ivda.vda_name < strtab_size | |
14142 | ? strtab + ivda.vda_name : _("<corrupt>")); | |
14143 | } | |
14144 | } | |
14145 | } | |
14146 | ||
14147 | if (filedata->version_info[DT_VERSIONTAGIDX (DT_VERNEED)]) | |
14148 | { | |
14149 | Elf_External_Verneed evn; | |
14150 | Elf_Internal_Verneed ivn; | |
14151 | Elf_Internal_Vernaux ivna; | |
14152 | ||
14153 | offset = offset_from_vma (filedata, | |
14154 | filedata->version_info[DT_VERSIONTAGIDX (DT_VERNEED)], | |
14155 | sizeof evn); | |
14156 | do | |
14157 | { | |
14158 | uint64_t vna_off; | |
14159 | ||
14160 | if (get_data (&evn, filedata, offset, sizeof (evn), 1, | |
14161 | _("version need")) == NULL) | |
14162 | { | |
14163 | ivna.vna_next = 0; | |
14164 | ivna.vna_other = 0; | |
14165 | ivna.vna_name = 0; | |
14166 | break; | |
14167 | } | |
14168 | ||
14169 | ivn.vn_aux = BYTE_GET (evn.vn_aux); | |
14170 | ivn.vn_next = BYTE_GET (evn.vn_next); | |
14171 | ||
14172 | vna_off = offset + ivn.vn_aux; | |
14173 | ||
14174 | do | |
14175 | { | |
14176 | Elf_External_Vernaux evna; | |
14177 | ||
14178 | if (get_data (&evna, filedata, vna_off, sizeof (evna), 1, | |
14179 | _("version need aux (3)")) == NULL) | |
14180 | { | |
14181 | ivna.vna_next = 0; | |
14182 | ivna.vna_other = 0; | |
14183 | ivna.vna_name = 0; | |
14184 | } | |
14185 | else | |
14186 | { | |
14187 | ivna.vna_other = BYTE_GET (evna.vna_other); | |
14188 | ivna.vna_next = BYTE_GET (evna.vna_next); | |
14189 | ivna.vna_name = BYTE_GET (evna.vna_name); | |
14190 | } | |
14191 | ||
14192 | vna_off += ivna.vna_next; | |
14193 | } | |
14194 | while (ivna.vna_other != vers_data && ivna.vna_next != 0); | |
14195 | ||
14196 | if (ivna.vna_other == vers_data) | |
14197 | break; | |
14198 | ||
14199 | offset += ivn.vn_next; | |
14200 | } | |
14201 | while (ivn.vn_next != 0); | |
14202 | ||
14203 | if (ivna.vna_other == vers_data) | |
14204 | { | |
14205 | *sym_info = symbol_undefined; | |
14206 | *vna_other = ivna.vna_other; | |
14207 | return (ivna.vna_name < strtab_size | |
14208 | ? strtab + ivna.vna_name : _("<corrupt>")); | |
14209 | } | |
14210 | else if ((max_vd_ndx || (vers_data & VERSYM_VERSION) != 1) | |
14211 | && (vers_data & VERSYM_VERSION) > max_vd_ndx) | |
14212 | return _("<corrupt>"); | |
14213 | } | |
14214 | return NULL; | |
14215 | } | |
14216 | ||
14217 | /* Display a symbol size on stdout. Format is based on --sym-base setting. */ | |
14218 | ||
14219 | static unsigned int | |
14220 | print_symbol_size (uint64_t vma, int base) | |
14221 | { | |
14222 | switch (base) | |
14223 | { | |
14224 | case 8: | |
14225 | return print_vma (vma, OCTAL_5); | |
14226 | ||
14227 | case 10: | |
14228 | return print_vma (vma, UNSIGNED_5); | |
14229 | ||
14230 | case 16: | |
14231 | return print_vma (vma, PREFIX_HEX_5); | |
14232 | ||
14233 | case 0: | |
14234 | default: | |
14235 | return print_vma (vma, DEC_5); | |
14236 | } | |
14237 | } | |
14238 | ||
14239 | /* Print information on a single symbol. */ | |
14240 | ||
14241 | static void | |
14242 | print_symbol (Filedata * filedata, | |
14243 | uint64_t symbol_index, | |
14244 | Elf_Internal_Sym * symtab, | |
14245 | Elf_Internal_Shdr * section, | |
14246 | char * strtab, | |
14247 | size_t strtab_size) | |
14248 | { | |
14249 | const char *version_string; | |
14250 | enum versioned_symbol_info sym_info; | |
14251 | unsigned short vna_other; | |
14252 | const char * sstr; | |
14253 | Elf_Internal_Sym *psym = symtab + symbol_index; | |
14254 | ||
14255 | /* FIXME: We should have a table of field widths, | |
14256 | rather than using hard coded constants. */ | |
14257 | printf ("%6" PRId64 ": ", symbol_index); | |
14258 | print_vma (psym->st_value, LONG_HEX); | |
14259 | putchar (' '); | |
14260 | print_symbol_size (psym->st_size, sym_base); | |
14261 | printf (" %-7s", get_symbol_type (filedata, ELF_ST_TYPE (psym->st_info))); | |
14262 | printf (" %-6s", get_symbol_binding (filedata, ELF_ST_BIND (psym->st_info))); | |
14263 | if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS) | |
14264 | printf (" %-7s", get_solaris_symbol_visibility (psym->st_other)); | |
14265 | else | |
14266 | { | |
14267 | unsigned int vis = ELF_ST_VISIBILITY (psym->st_other); | |
14268 | ||
14269 | printf (" %-7s", get_symbol_visibility (vis)); | |
14270 | ||
14271 | /* Check to see if any other bits in the st_other field are set. | |
14272 | FIXME: Displaying this information here disrupts the layout | |
14273 | of the table being generated. */ | |
14274 | if (psym->st_other ^ vis) | |
14275 | printf (" [%s] ", get_symbol_other (filedata, psym->st_other ^ vis)); | |
14276 | } | |
14277 | ||
14278 | bool is_special; | |
14279 | ||
14280 | sstr = printable_section_name_from_index (filedata, psym->st_shndx, & is_special); | |
14281 | ||
14282 | /* Print the symbol's section index. If the index is special | |
14283 | then print the index's name rather than its number. */ | |
14284 | if (is_special) | |
14285 | { | |
14286 | int printed; | |
14287 | ||
14288 | /* Special case: If there are no section headers, and the printable | |
14289 | name is "<section 0x...." then just display the section number | |
14290 | as a decimal. This happens when objcopy --strip -section-headers | |
14291 | is used. */ | |
14292 | if (filedata->file_header.e_shnum == 0 && startswith (sstr, "<section")) | |
14293 | printed = printf (" %4d ", psym->st_shndx); | |
14294 | else | |
14295 | printed = printf (" %4s ", sstr); | |
14296 | ||
14297 | if (extra_sym_info && printed < 16) | |
14298 | printf ("%*s", 16 - printed, ""); | |
14299 | } | |
14300 | else | |
14301 | { | |
14302 | printf (" %4u ", psym->st_shndx); | |
14303 | ||
14304 | if (extra_sym_info) | |
14305 | { | |
14306 | /* Display the section name referenced by the section index. */ | |
14307 | int printed = printf ("(%s) ", sstr); | |
14308 | if (printed < 10) | |
14309 | printf ("%*s", 10 - printed, ""); | |
14310 | } | |
14311 | } | |
14312 | ||
14313 | /* Get the symbol's name. For section symbols without a | |
14314 | specific name use the (already computed) section name. */ | |
14315 | if (ELF_ST_TYPE (psym->st_info) == STT_SECTION | |
14316 | && section_index_real (filedata, psym->st_shndx) | |
14317 | && psym->st_name == 0) | |
14318 | { | |
14319 | ; | |
14320 | } | |
14321 | else | |
14322 | { | |
14323 | bool is_valid; | |
14324 | ||
14325 | is_valid = valid_symbol_name (strtab, strtab_size, psym->st_name); | |
14326 | sstr = is_valid ? strtab + psym->st_name : _("<corrupt>"); | |
14327 | } | |
14328 | ||
14329 | version_string | |
14330 | = get_symbol_version_string (filedata, | |
14331 | (section == NULL | |
14332 | || section->sh_type == SHT_DYNSYM), | |
14333 | strtab, strtab_size, symbol_index, | |
14334 | psym, &sym_info, &vna_other); | |
14335 | ||
14336 | int len_avail = 21; | |
14337 | if (! do_wide && version_string != NULL) | |
14338 | { | |
14339 | char buffer[16]; | |
14340 | ||
14341 | len_avail -= 1 + strlen (version_string); | |
14342 | ||
14343 | if (sym_info == symbol_undefined) | |
14344 | len_avail -= sprintf (buffer," (%d)", vna_other); | |
14345 | else if (sym_info != symbol_hidden) | |
14346 | len_avail -= 1; | |
14347 | } | |
14348 | ||
14349 | print_symbol_name (len_avail, sstr); | |
14350 | ||
14351 | if (version_string) | |
14352 | { | |
14353 | if (sym_info == symbol_undefined) | |
14354 | printf ("@%s (%d)", version_string, vna_other); | |
14355 | else | |
14356 | printf (sym_info == symbol_hidden ? "@%s" : "@@%s", | |
14357 | version_string); | |
14358 | } | |
14359 | ||
14360 | putchar ('\n'); | |
14361 | ||
14362 | if (ELF_ST_BIND (psym->st_info) == STB_LOCAL | |
14363 | && section != NULL | |
14364 | && symbol_index >= section->sh_info | |
14365 | /* Irix 5 and 6 MIPS binaries are known to ignore this requirement. */ | |
14366 | && filedata->file_header.e_machine != EM_MIPS | |
14367 | /* Solaris binaries have been found to violate this requirement as | |
14368 | well. Not sure if this is a bug or an ABI requirement. */ | |
14369 | && filedata->file_header.e_ident[EI_OSABI] != ELFOSABI_SOLARIS) | |
14370 | warn (_("local symbol %" PRIu64 " found at index >= %s's sh_info value of %u\n"), | |
14371 | symbol_index, printable_section_name (filedata, section), section->sh_info); | |
14372 | } | |
14373 | ||
14374 | static const char * | |
14375 | get_lto_kind (unsigned int kind) | |
14376 | { | |
14377 | switch (kind) | |
14378 | { | |
14379 | case 0: return "DEF"; | |
14380 | case 1: return "WEAKDEF"; | |
14381 | case 2: return "UNDEF"; | |
14382 | case 3: return "WEAKUNDEF"; | |
14383 | case 4: return "COMMON"; | |
14384 | default: | |
14385 | break; | |
14386 | } | |
14387 | ||
14388 | static char buffer[30]; | |
14389 | error (_("Unknown LTO symbol definition encountered: %u\n"), kind); | |
14390 | sprintf (buffer, "<unknown: %u>", kind); | |
14391 | return buffer; | |
14392 | } | |
14393 | ||
14394 | static const char * | |
14395 | get_lto_visibility (unsigned int visibility) | |
14396 | { | |
14397 | switch (visibility) | |
14398 | { | |
14399 | case 0: return "DEFAULT"; | |
14400 | case 1: return "PROTECTED"; | |
14401 | case 2: return "INTERNAL"; | |
14402 | case 3: return "HIDDEN"; | |
14403 | default: | |
14404 | break; | |
14405 | } | |
14406 | ||
14407 | static char buffer[30]; | |
14408 | error (_("Unknown LTO symbol visibility encountered: %u\n"), visibility); | |
14409 | sprintf (buffer, "<unknown: %u>", visibility); | |
14410 | return buffer; | |
14411 | } | |
14412 | ||
14413 | static const char * | |
14414 | get_lto_sym_type (unsigned int sym_type) | |
14415 | { | |
14416 | switch (sym_type) | |
14417 | { | |
14418 | case 0: return "UNKNOWN"; | |
14419 | case 1: return "FUNCTION"; | |
14420 | case 2: return "VARIABLE"; | |
14421 | default: | |
14422 | break; | |
14423 | } | |
14424 | ||
14425 | static char buffer[30]; | |
14426 | error (_("Unknown LTO symbol type encountered: %u\n"), sym_type); | |
14427 | sprintf (buffer, "<unknown: %u>", sym_type); | |
14428 | return buffer; | |
14429 | } | |
14430 | ||
14431 | /* Display an LTO format symbol table. | |
14432 | FIXME: The format of LTO symbol tables is not formalized. | |
14433 | So this code could need changing in the future. */ | |
14434 | ||
14435 | static bool | |
14436 | display_lto_symtab (Filedata * filedata, | |
14437 | Elf_Internal_Shdr * section) | |
14438 | { | |
14439 | if (section->sh_size == 0) | |
14440 | { | |
14441 | if (filedata->is_separate) | |
14442 | printf (_("\nThe LTO Symbol table section '%s' in linked file '%s' is empty!\n"), | |
14443 | printable_section_name (filedata, section), | |
14444 | filedata->file_name); | |
14445 | else | |
14446 | printf (_("\nLTO Symbol table '%s' is empty!\n"), | |
14447 | printable_section_name (filedata, section)); | |
14448 | ||
14449 | return true; | |
14450 | } | |
14451 | ||
14452 | if (section->sh_size > filedata->file_size) | |
14453 | { | |
14454 | error (_("Section %s has an invalid sh_size of %#" PRIx64 "\n"), | |
14455 | printable_section_name (filedata, section), | |
14456 | section->sh_size); | |
14457 | return false; | |
14458 | } | |
14459 | ||
14460 | void * alloced_data = get_data (NULL, filedata, section->sh_offset, | |
14461 | section->sh_size, 1, _("LTO symbols")); | |
14462 | if (alloced_data == NULL) | |
14463 | return false; | |
14464 | ||
14465 | /* Look for extended data for the symbol table. */ | |
14466 | void * ext_data_orig = NULL; | |
14467 | char * ext_data = NULL; | |
14468 | char * ext_data_end = NULL; | |
14469 | char *ext_name = xasprintf (".gnu.lto_.ext_symtab.%s", | |
14470 | (section_name (filedata, section) | |
14471 | + sizeof (".gnu.lto_.symtab."))); | |
14472 | Elf_Internal_Shdr *ext = find_section (filedata, ext_name); | |
14473 | if (ext != NULL) | |
14474 | { | |
14475 | if (ext->sh_size < 3) | |
14476 | error (_("LTO Symbol extension table '%s' is empty!\n"), | |
14477 | printable_section_name (filedata, ext)); | |
14478 | else | |
14479 | { | |
14480 | ext_data_orig = ext_data = get_data (NULL, filedata, ext->sh_offset, | |
14481 | ext->sh_size, 1, | |
14482 | _("LTO ext symbol data")); | |
14483 | if (ext_data != NULL) | |
14484 | { | |
14485 | ext_data_end = ext_data + ext->sh_size; | |
14486 | if (* ext_data++ != 1) | |
14487 | error (_("Unexpected version number in symbol extension table\n")); | |
14488 | } | |
14489 | } | |
14490 | } | |
14491 | ||
14492 | const unsigned char * data = (const unsigned char *) alloced_data; | |
14493 | const unsigned char * end = data + section->sh_size; | |
14494 | ||
14495 | if (filedata->is_separate) | |
14496 | printf (_("\nIn linked file '%s': "), filedata->file_name); | |
14497 | else | |
14498 | printf ("\n"); | |
14499 | ||
14500 | if (ext_data_orig != NULL) | |
14501 | { | |
14502 | if (do_wide) | |
14503 | printf (_("LTO Symbol table '%s' and extension table '%s' contain:\n"), | |
14504 | printable_section_name (filedata, section), | |
14505 | printable_section_name (filedata, ext)); | |
14506 | else | |
14507 | { | |
14508 | printf (_("LTO Symbol table '%s'\n"), | |
14509 | printable_section_name (filedata, section)); | |
14510 | printf (_(" and extension table '%s' contain:\n"), | |
14511 | printable_section_name (filedata, ext)); | |
14512 | } | |
14513 | } | |
14514 | else | |
14515 | printf (_("LTO Symbol table '%s' contains:\n"), | |
14516 | printable_section_name (filedata, section)); | |
14517 | ||
14518 | /* FIXME: Add a wide version. */ | |
14519 | if (ext_data_orig != NULL) | |
14520 | printf (_(" Comdat_Key Kind Visibility Size Slot Type Section Name\n")); | |
14521 | else | |
14522 | printf (_(" Comdat_Key Kind Visibility Size Slot Name\n")); | |
14523 | ||
14524 | /* FIXME: We do not handle style prefixes. */ | |
14525 | ||
14526 | while (data < end) | |
14527 | { | |
14528 | const unsigned char * sym_name = data; | |
14529 | data += strnlen ((const char *) sym_name, end - data) + 1; | |
14530 | if (data >= end) | |
14531 | goto fail; | |
14532 | ||
14533 | const unsigned char * comdat_key = data; | |
14534 | data += strnlen ((const char *) comdat_key, end - data) + 1; | |
14535 | if (data >= end) | |
14536 | goto fail; | |
14537 | ||
14538 | if (data + 2 + 8 + 4 > end) | |
14539 | goto fail; | |
14540 | ||
14541 | unsigned int kind = *data++; | |
14542 | unsigned int visibility = *data++; | |
14543 | ||
14544 | uint64_t size = byte_get (data, 8); | |
14545 | data += 8; | |
14546 | ||
14547 | uint64_t slot = byte_get (data, 4); | |
14548 | data += 4; | |
14549 | ||
14550 | if (ext_data != NULL) | |
14551 | { | |
14552 | if (ext_data < (ext_data_end - 1)) | |
14553 | { | |
14554 | unsigned int sym_type = * ext_data ++; | |
14555 | unsigned int sec_kind = * ext_data ++; | |
14556 | ||
14557 | printf (" %10s %10s %11s %08" PRIx64 " %08" PRIx64 " %9s %08x _", | |
14558 | * comdat_key == 0 ? "-" : (char *) comdat_key, | |
14559 | get_lto_kind (kind), | |
14560 | get_lto_visibility (visibility), | |
14561 | size, | |
14562 | slot, | |
14563 | get_lto_sym_type (sym_type), | |
14564 | sec_kind); | |
14565 | print_symbol_name (6, (const char *) sym_name); | |
14566 | } | |
14567 | else | |
14568 | { | |
14569 | error (_("Ran out of LTO symbol extension data\n")); | |
14570 | ext_data = NULL; | |
14571 | /* FIXME: return FAIL result ? */ | |
14572 | } | |
14573 | } | |
14574 | else | |
14575 | { | |
14576 | printf (" %10s %10s %11s %08" PRIx64 " %08" PRIx64 " _", | |
14577 | * comdat_key == 0 ? "-" : (char *) comdat_key, | |
14578 | get_lto_kind (kind), | |
14579 | get_lto_visibility (visibility), | |
14580 | size, | |
14581 | slot); | |
14582 | print_symbol_name (21, (const char *) sym_name); | |
14583 | } | |
14584 | putchar ('\n'); | |
14585 | } | |
14586 | ||
14587 | if (ext_data != NULL && ext_data < ext_data_end) | |
14588 | { | |
14589 | error (_("Data remains in the LTO symbol extension table\n")); | |
14590 | goto fail; | |
14591 | } | |
14592 | ||
14593 | free (alloced_data); | |
14594 | free (ext_data_orig); | |
14595 | free (ext_name); | |
14596 | return true; | |
14597 | ||
14598 | fail: | |
14599 | error (_("Buffer overrun encountered whilst decoding LTO symbol table\n")); | |
14600 | free (alloced_data); | |
14601 | free (ext_data_orig); | |
14602 | free (ext_name); | |
14603 | return false; | |
14604 | } | |
14605 | ||
14606 | /* Display LTO symbol tables. */ | |
14607 | ||
14608 | static bool | |
14609 | process_lto_symbol_tables (Filedata * filedata) | |
14610 | { | |
14611 | Elf_Internal_Shdr * section; | |
14612 | unsigned int i; | |
14613 | bool res = true; | |
14614 | ||
14615 | if (!do_lto_syms) | |
14616 | return true; | |
14617 | ||
14618 | if (filedata->section_headers == NULL) | |
14619 | return true; | |
14620 | ||
14621 | for (i = 0, section = filedata->section_headers; | |
14622 | i < filedata->file_header.e_shnum; | |
14623 | i++, section++) | |
14624 | if (section_name_valid (filedata, section) | |
14625 | && startswith (section_name (filedata, section), ".gnu.lto_.symtab.")) | |
14626 | res &= display_lto_symtab (filedata, section); | |
14627 | ||
14628 | return res; | |
14629 | } | |
14630 | ||
14631 | static void | |
14632 | print_symbol_table_heading (void) | |
14633 | { | |
14634 | /* FIXME: We should store the size of each field in the display in a table and | |
14635 | then use the values inside print_symbol(), instead of that function using | |
14636 | hard coded constants. */ | |
14637 | if (is_32bit_elf) | |
14638 | { | |
14639 | if (extra_sym_info) | |
14640 | { | |
14641 | printf (_(" Num: Value Size Type Bind Vis+Other Ndx(SecName) Name [+ Version Info]\n")); | |
14642 | /* |--6-|: |--8---| |-5-| |--7--| |-6--| |--7--| |---8--| |----13.....| |........... */ | |
14643 | /* eg: 5: 00000000 14 FUNC LOCAL DEFAULT 1 (.text) get_sections */ | |
14644 | } | |
14645 | else if (do_wide) | |
14646 | { | |
14647 | printf (_(" Num: Value Size Type Bind Vis Ndx Name\n")); | |
14648 | /* |--6-|: |--8---| |-5-| |--7--| |-6--| |--7--| |-4| |........... */ | |
14649 | /* eg: 5: 00000000 14 FUNC LOCAL DEFAULT 1 get_sections */ | |
14650 | } | |
14651 | else | |
14652 | { | |
14653 | printf (_(" Num: Value Size Type Bind Vis Ndx Name\n")); | |
14654 | /* |--6-|: |--8---| |-5-| |--7--| |-6--| |--7--| |-4| |------------29-------------| */ | |
14655 | /* eg: 5: 00000000 14 FUNC LOCAL DEFAULT 1 get_sections */ | |
14656 | } | |
14657 | } | |
14658 | else | |
14659 | { | |
14660 | if (extra_sym_info) | |
14661 | { | |
14662 | printf (_(" Num: Value Size Type Bind Vis+Other Ndx(SecName) Name [+ Version Info]\n")); | |
14663 | /* |--6-|: |------16------| |-5-| |--7--| |-6--| |--7--| |-------14---| |..... */ | |
14664 | /* eg: 2: 0000000000000000 0 FUNC LOCAL DEFAULT 1 (.text) .very_long_function_name */ | |
14665 | ||
14666 | } | |
14667 | else if (do_wide) | |
14668 | { | |
14669 | printf (_(" Num: Value Size Type Bind Vis Ndx Name\n")); | |
14670 | /* |--6-|: |------16------| |-5-| |--7--| |-6--| |--7--| |-4| |........... */ | |
14671 | /* eg: 5: 0000000000000000 14 FUNC LOCAL DEFAULT 1 very_long_function_name */ | |
14672 | } | |
14673 | else | |
14674 | { | |
14675 | printf (_(" Num: Value Size Type Bind Vis Ndx Name\n")); | |
14676 | /* |--6-|: |------16------| |-5-| |--7--| |-6--| |--7--| |-4| |--------21---------| */ | |
14677 | /* eg: 5: 0000000000000000 14 FUNC LOCAL DEFAULT 1 very_long_functi[...] */ | |
14678 | } | |
14679 | } | |
14680 | } | |
14681 | ||
14682 | static bool | |
14683 | dump_symbol_section (Elf_Internal_Shdr * section, | |
14684 | Filedata * filedata) | |
14685 | { | |
14686 | if (section->sh_entsize == 0) | |
14687 | { | |
14688 | printf (_("\nSymbol table '%s' has a sh_entsize of zero!\n"), | |
14689 | printable_section_name (filedata, section)); | |
14690 | return false; | |
14691 | } | |
14692 | ||
14693 | uint64_t num_syms = section->sh_size / section->sh_entsize; | |
14694 | ||
14695 | if (filedata->is_separate) | |
14696 | printf (ngettext ("\nIn linked file '%s' symbol section '%s'" | |
14697 | " contains %" PRIu64 " entry:\n", | |
14698 | "\nIn linked file '%s' symbol section '%s'" | |
14699 | " contains %" PRIu64 " entries:\n", | |
14700 | num_syms), | |
14701 | filedata->file_name, | |
14702 | printable_section_name (filedata, section), | |
14703 | num_syms); | |
14704 | else | |
14705 | printf (ngettext ("\nSymbol table '%s' contains %" PRIu64 | |
14706 | " entry:\n", | |
14707 | "\nSymbol table '%s' contains %" PRIu64 | |
14708 | " entries:\n", | |
14709 | num_syms), | |
14710 | printable_section_name (filedata, section), | |
14711 | num_syms); | |
14712 | ||
14713 | print_symbol_table_heading (); | |
14714 | ||
14715 | Elf_Internal_Sym * symtab = get_elf_symbols (filedata, section, & num_syms); | |
14716 | if (symtab == NULL) | |
14717 | /* An error message will have already been displayed. */ | |
14718 | return false; | |
14719 | ||
14720 | char * strtab = NULL; | |
14721 | uint64_t strtab_size = 0; | |
14722 | ||
14723 | if (section->sh_link == filedata->file_header.e_shstrndx) | |
14724 | { | |
14725 | strtab = filedata->string_table; | |
14726 | strtab_size = filedata->string_table_length; | |
14727 | } | |
14728 | else if (section->sh_link < filedata->file_header.e_shnum) | |
14729 | { | |
14730 | Elf_Internal_Shdr * string_sec; | |
14731 | ||
14732 | string_sec = filedata->section_headers + section->sh_link; | |
14733 | ||
14734 | strtab = (char *) get_data (NULL, filedata, string_sec->sh_offset, | |
14735 | 1, string_sec->sh_size, | |
14736 | _("string table")); | |
14737 | strtab_size = strtab != NULL ? string_sec->sh_size : 0; | |
14738 | } | |
14739 | ||
14740 | uint64_t si; | |
14741 | ||
14742 | for (si = 0; si < num_syms; si++) | |
14743 | print_symbol (filedata, si, symtab, section, strtab, strtab_size); | |
14744 | ||
14745 | free (symtab); | |
14746 | ||
14747 | if (strtab != filedata->string_table) | |
14748 | free (strtab); | |
14749 | ||
14750 | return true; | |
14751 | } | |
14752 | ||
14753 | /* Dump the symbol table. */ | |
14754 | ||
14755 | static bool | |
14756 | process_symbol_table (Filedata * filedata) | |
14757 | { | |
14758 | Elf_Internal_Shdr * section; | |
14759 | ||
14760 | if (!do_syms && !do_dyn_syms && !do_histogram) | |
14761 | return true; | |
14762 | ||
14763 | if ((filedata->dynamic_info[DT_HASH] || filedata->dynamic_info_DT_GNU_HASH) | |
14764 | && do_syms | |
14765 | && do_using_dynamic | |
14766 | && filedata->dynamic_strings != NULL | |
14767 | && filedata->dynamic_symbols != NULL) | |
14768 | { | |
14769 | uint64_t si; | |
14770 | ||
14771 | if (filedata->is_separate) | |
14772 | { | |
14773 | printf (ngettext ("\nIn linked file '%s' the dynamic symbol table" | |
14774 | " contains %" PRIu64 " entry:\n", | |
14775 | "\nIn linked file '%s' the dynamic symbol table" | |
14776 | " contains %" PRIu64 " entries:\n", | |
14777 | filedata->num_dynamic_syms), | |
14778 | filedata->file_name, | |
14779 | filedata->num_dynamic_syms); | |
14780 | } | |
14781 | else | |
14782 | { | |
14783 | printf (ngettext ("\nSymbol table for image contains %" PRIu64 | |
14784 | " entry:\n", | |
14785 | "\nSymbol table for image contains %" PRIu64 | |
14786 | " entries:\n", | |
14787 | filedata->num_dynamic_syms), | |
14788 | filedata->num_dynamic_syms); | |
14789 | } | |
14790 | ||
14791 | print_symbol_table_heading (); | |
14792 | ||
14793 | for (si = 0; si < filedata->num_dynamic_syms; si++) | |
14794 | print_symbol (filedata, si, filedata->dynamic_symbols, NULL, | |
14795 | filedata->dynamic_strings, | |
14796 | filedata->dynamic_strings_length); | |
14797 | } | |
14798 | else if ((do_dyn_syms || (do_syms && !do_using_dynamic)) | |
14799 | && filedata->section_headers != NULL) | |
14800 | { | |
14801 | unsigned int i; | |
14802 | ||
14803 | for (i = 0, section = filedata->section_headers; | |
14804 | i < filedata->file_header.e_shnum; | |
14805 | i++, section++) | |
14806 | { | |
14807 | if ((section->sh_type != SHT_SYMTAB | |
14808 | && section->sh_type != SHT_DYNSYM) | |
14809 | || (!do_syms | |
14810 | && section->sh_type == SHT_SYMTAB)) | |
14811 | continue; | |
14812 | ||
14813 | dump_symbol_section (section, filedata); | |
14814 | } | |
14815 | } | |
14816 | else if (do_syms) | |
14817 | printf | |
14818 | (_("\nDynamic symbol information is not available for displaying symbols.\n")); | |
14819 | ||
14820 | if (do_histogram && filedata->buckets != NULL) | |
14821 | { | |
14822 | uint64_t *lengths; | |
14823 | uint64_t *counts; | |
14824 | uint64_t hn; | |
14825 | uint64_t si; | |
14826 | uint64_t maxlength = 0; | |
14827 | uint64_t nzero_counts = 0; | |
14828 | uint64_t nsyms = 0; | |
14829 | char *visited; | |
14830 | ||
14831 | printf (ngettext ("\nHistogram for bucket list length " | |
14832 | "(total of %" PRIu64 " bucket):\n", | |
14833 | "\nHistogram for bucket list length " | |
14834 | "(total of %" PRIu64 " buckets):\n", | |
14835 | filedata->nbuckets), | |
14836 | filedata->nbuckets); | |
14837 | ||
14838 | lengths = calloc (filedata->nbuckets, sizeof (*lengths)); | |
14839 | if (lengths == NULL) | |
14840 | { | |
14841 | error (_("Out of memory allocating space for histogram buckets\n")); | |
14842 | goto err_out; | |
14843 | } | |
14844 | visited = xcmalloc (filedata->nchains, 1); | |
14845 | memset (visited, 0, filedata->nchains); | |
14846 | ||
14847 | printf (_(" Length Number %% of total Coverage\n")); | |
14848 | for (hn = 0; hn < filedata->nbuckets; ++hn) | |
14849 | { | |
14850 | for (si = filedata->buckets[hn]; si > 0; si = filedata->chains[si]) | |
14851 | { | |
14852 | ++nsyms; | |
14853 | if (maxlength < ++lengths[hn]) | |
14854 | ++maxlength; | |
14855 | if (si >= filedata->nchains || visited[si]) | |
14856 | { | |
14857 | error (_("histogram chain is corrupt\n")); | |
14858 | break; | |
14859 | } | |
14860 | visited[si] = 1; | |
14861 | } | |
14862 | } | |
14863 | free (visited); | |
14864 | ||
14865 | counts = calloc (maxlength + 1, sizeof (*counts)); | |
14866 | if (counts == NULL) | |
14867 | { | |
14868 | free (lengths); | |
14869 | error (_("Out of memory allocating space for histogram counts\n")); | |
14870 | goto err_out; | |
14871 | } | |
14872 | ||
14873 | for (hn = 0; hn < filedata->nbuckets; ++hn) | |
14874 | ++counts[lengths[hn]]; | |
14875 | ||
14876 | if (filedata->nbuckets > 0) | |
14877 | { | |
14878 | uint64_t i; | |
14879 | printf (" 0 %-10" PRIu64 " (%5.1f%%)\n", | |
14880 | counts[0], (counts[0] * 100.0) / filedata->nbuckets); | |
14881 | for (i = 1; i <= maxlength; ++i) | |
14882 | { | |
14883 | nzero_counts += counts[i] * i; | |
14884 | printf ("%7" PRIu64 " %-10" PRIu64 " (%5.1f%%) %5.1f%%\n", | |
14885 | i, counts[i], (counts[i] * 100.0) / filedata->nbuckets, | |
14886 | (nzero_counts * 100.0) / nsyms); | |
14887 | } | |
14888 | } | |
14889 | ||
14890 | free (counts); | |
14891 | free (lengths); | |
14892 | } | |
14893 | ||
14894 | free (filedata->buckets); | |
14895 | filedata->buckets = NULL; | |
14896 | filedata->nbuckets = 0; | |
14897 | free (filedata->chains); | |
14898 | filedata->chains = NULL; | |
14899 | ||
14900 | if (do_histogram && filedata->gnubuckets != NULL) | |
14901 | { | |
14902 | uint64_t *lengths; | |
14903 | uint64_t *counts; | |
14904 | uint64_t hn; | |
14905 | uint64_t maxlength = 0; | |
14906 | uint64_t nzero_counts = 0; | |
14907 | uint64_t nsyms = 0; | |
14908 | ||
14909 | printf (ngettext ("\nHistogram for `%s' bucket list length " | |
14910 | "(total of %" PRIu64 " bucket):\n", | |
14911 | "\nHistogram for `%s' bucket list length " | |
14912 | "(total of %" PRIu64 " buckets):\n", | |
14913 | filedata->ngnubuckets), | |
14914 | GNU_HASH_SECTION_NAME (filedata), | |
14915 | filedata->ngnubuckets); | |
14916 | ||
14917 | lengths = calloc (filedata->ngnubuckets, sizeof (*lengths)); | |
14918 | if (lengths == NULL) | |
14919 | { | |
14920 | error (_("Out of memory allocating space for gnu histogram buckets\n")); | |
14921 | goto err_out; | |
14922 | } | |
14923 | ||
14924 | printf (_(" Length Number %% of total Coverage\n")); | |
14925 | ||
14926 | for (hn = 0; hn < filedata->ngnubuckets; ++hn) | |
14927 | if (filedata->gnubuckets[hn] != 0) | |
14928 | { | |
14929 | uint64_t off, length = 1; | |
14930 | ||
14931 | for (off = filedata->gnubuckets[hn] - filedata->gnusymidx; | |
14932 | /* PR 17531 file: 010-77222-0.004. */ | |
14933 | off < filedata->ngnuchains | |
14934 | && (filedata->gnuchains[off] & 1) == 0; | |
14935 | ++off) | |
14936 | ++length; | |
14937 | lengths[hn] = length; | |
14938 | if (length > maxlength) | |
14939 | maxlength = length; | |
14940 | nsyms += length; | |
14941 | } | |
14942 | ||
14943 | counts = calloc (maxlength + 1, sizeof (*counts)); | |
14944 | if (counts == NULL) | |
14945 | { | |
14946 | free (lengths); | |
14947 | error (_("Out of memory allocating space for gnu histogram counts\n")); | |
14948 | goto err_out; | |
14949 | } | |
14950 | ||
14951 | for (hn = 0; hn < filedata->ngnubuckets; ++hn) | |
14952 | ++counts[lengths[hn]]; | |
14953 | ||
14954 | if (filedata->ngnubuckets > 0) | |
14955 | { | |
14956 | uint64_t j; | |
14957 | printf (" 0 %-10" PRIu64 " (%5.1f%%)\n", | |
14958 | counts[0], (counts[0] * 100.0) / filedata->ngnubuckets); | |
14959 | for (j = 1; j <= maxlength; ++j) | |
14960 | { | |
14961 | nzero_counts += counts[j] * j; | |
14962 | printf ("%7" PRIu64 " %-10" PRIu64 " (%5.1f%%) %5.1f%%\n", | |
14963 | j, counts[j], (counts[j] * 100.0) / filedata->ngnubuckets, | |
14964 | (nzero_counts * 100.0) / nsyms); | |
14965 | } | |
14966 | } | |
14967 | ||
14968 | free (counts); | |
14969 | free (lengths); | |
14970 | } | |
14971 | free (filedata->gnubuckets); | |
14972 | filedata->gnubuckets = NULL; | |
14973 | filedata->ngnubuckets = 0; | |
14974 | free (filedata->gnuchains); | |
14975 | filedata->gnuchains = NULL; | |
14976 | filedata->ngnuchains = 0; | |
14977 | free (filedata->mipsxlat); | |
14978 | filedata->mipsxlat = NULL; | |
14979 | return true; | |
14980 | ||
14981 | err_out: | |
14982 | free (filedata->gnubuckets); | |
14983 | filedata->gnubuckets = NULL; | |
14984 | filedata->ngnubuckets = 0; | |
14985 | free (filedata->gnuchains); | |
14986 | filedata->gnuchains = NULL; | |
14987 | filedata->ngnuchains = 0; | |
14988 | free (filedata->mipsxlat); | |
14989 | filedata->mipsxlat = NULL; | |
14990 | free (filedata->buckets); | |
14991 | filedata->buckets = NULL; | |
14992 | filedata->nbuckets = 0; | |
14993 | free (filedata->chains); | |
14994 | filedata->chains = NULL; | |
14995 | return false; | |
14996 | } | |
14997 | ||
14998 | static bool | |
14999 | process_syminfo (Filedata * filedata) | |
15000 | { | |
15001 | unsigned int i; | |
15002 | ||
15003 | if (filedata->dynamic_syminfo == NULL | |
15004 | || !do_dynamic) | |
15005 | /* No syminfo, this is ok. */ | |
15006 | return true; | |
15007 | ||
15008 | /* There better should be a dynamic symbol section. */ | |
15009 | if (filedata->dynamic_symbols == NULL || filedata->dynamic_strings == NULL) | |
15010 | return false; | |
15011 | ||
15012 | if (filedata->is_separate) | |
15013 | printf (ngettext ("\nIn linked file '%s: the dynamic info segment at offset %#" PRIx64 " contains %d entry:\n", | |
15014 | "\nIn linked file '%s: the dynamic info segment at offset %#" PRIx64 " contains %d entries:\n", | |
15015 | filedata->dynamic_syminfo_nent), | |
15016 | filedata->file_name, | |
15017 | filedata->dynamic_syminfo_offset, | |
15018 | filedata->dynamic_syminfo_nent); | |
15019 | else | |
15020 | printf (ngettext ("\nDynamic info segment at offset %#" PRIx64 | |
15021 | " contains %d entry:\n", | |
15022 | "\nDynamic info segment at offset %#" PRIx64 | |
15023 | " contains %d entries:\n", | |
15024 | filedata->dynamic_syminfo_nent), | |
15025 | filedata->dynamic_syminfo_offset, | |
15026 | filedata->dynamic_syminfo_nent); | |
15027 | ||
15028 | printf (_(" Num: Name BoundTo Flags\n")); | |
15029 | for (i = 0; i < filedata->dynamic_syminfo_nent; ++i) | |
15030 | { | |
15031 | unsigned short int flags = filedata->dynamic_syminfo[i].si_flags; | |
15032 | ||
15033 | printf ("%4d: ", i); | |
15034 | if (i >= filedata->num_dynamic_syms) | |
15035 | printf (_("<corrupt index>")); | |
15036 | else if (valid_dynamic_name (filedata, filedata->dynamic_symbols[i].st_name)) | |
15037 | print_symbol_name (30, get_dynamic_name (filedata, | |
15038 | filedata->dynamic_symbols[i].st_name)); | |
15039 | else | |
15040 | printf (_("<corrupt: %19ld>"), filedata->dynamic_symbols[i].st_name); | |
15041 | putchar (' '); | |
15042 | ||
15043 | switch (filedata->dynamic_syminfo[i].si_boundto) | |
15044 | { | |
15045 | case SYMINFO_BT_SELF: | |
15046 | fputs ("SELF ", stdout); | |
15047 | break; | |
15048 | case SYMINFO_BT_PARENT: | |
15049 | fputs ("PARENT ", stdout); | |
15050 | break; | |
15051 | default: | |
15052 | if (filedata->dynamic_syminfo[i].si_boundto > 0 | |
15053 | && filedata->dynamic_syminfo[i].si_boundto < filedata->dynamic_nent | |
15054 | && valid_dynamic_name (filedata, | |
15055 | filedata->dynamic_section[filedata->dynamic_syminfo[i].si_boundto].d_un.d_val)) | |
15056 | { | |
15057 | print_symbol_name (10, get_dynamic_name (filedata, | |
15058 | filedata->dynamic_section[filedata->dynamic_syminfo[i].si_boundto].d_un.d_val)); | |
15059 | putchar (' ' ); | |
15060 | } | |
15061 | else | |
15062 | printf ("%-10d ", filedata->dynamic_syminfo[i].si_boundto); | |
15063 | break; | |
15064 | } | |
15065 | ||
15066 | if (flags & SYMINFO_FLG_DIRECT) | |
15067 | printf (" DIRECT"); | |
15068 | if (flags & SYMINFO_FLG_PASSTHRU) | |
15069 | printf (" PASSTHRU"); | |
15070 | if (flags & SYMINFO_FLG_COPY) | |
15071 | printf (" COPY"); | |
15072 | if (flags & SYMINFO_FLG_LAZYLOAD) | |
15073 | printf (" LAZYLOAD"); | |
15074 | ||
15075 | puts (""); | |
15076 | } | |
15077 | ||
15078 | return true; | |
15079 | } | |
15080 | ||
15081 | /* A macro which evaluates to TRUE if the region ADDR .. ADDR + NELEM | |
15082 | is contained by the region START .. END. The types of ADDR, START | |
15083 | and END should all be the same. Note both ADDR + NELEM and END | |
15084 | point to just beyond the end of the regions that are being tested. */ | |
15085 | #define IN_RANGE(START,END,ADDR,NELEM) \ | |
15086 | (((ADDR) >= (START)) && ((ADDR) < (END)) && ((ADDR) + (NELEM) <= (END))) | |
15087 | ||
15088 | /* Check to see if the given reloc needs to be handled in a target specific | |
15089 | manner. If so then process the reloc and return TRUE otherwise return | |
15090 | FALSE. | |
15091 | ||
15092 | If called with reloc == NULL, then this is a signal that reloc processing | |
15093 | for the current section has finished, and any saved state should be | |
15094 | discarded. */ | |
15095 | ||
15096 | static bool | |
15097 | target_specific_reloc_handling (Filedata *filedata, | |
15098 | Elf_Internal_Rela *reloc, | |
15099 | unsigned char *start, | |
15100 | unsigned char *end, | |
15101 | Elf_Internal_Sym *symtab, | |
15102 | uint64_t num_syms) | |
15103 | { | |
15104 | unsigned int reloc_type = 0; | |
15105 | uint64_t sym_index = 0; | |
15106 | ||
15107 | if (reloc) | |
15108 | { | |
15109 | reloc_type = get_reloc_type (filedata, reloc->r_info); | |
15110 | sym_index = get_reloc_symindex (reloc->r_info); | |
15111 | } | |
15112 | ||
15113 | switch (filedata->file_header.e_machine) | |
15114 | { | |
15115 | case EM_LOONGARCH: | |
15116 | { | |
15117 | switch (reloc_type) | |
15118 | { | |
15119 | /* For .uleb128 .LFE1-.LFB1, loongarch write 0 to object file | |
15120 | at assembly time. */ | |
15121 | case 107: /* R_LARCH_ADD_ULEB128. */ | |
15122 | case 108: /* R_LARCH_SUB_ULEB128. */ | |
15123 | { | |
15124 | uint64_t value = 0; | |
15125 | unsigned int reloc_size = 0; | |
15126 | int leb_ret = 0; | |
15127 | ||
15128 | if (reloc->r_offset < (size_t) (end - start)) | |
15129 | value = read_leb128 (start + reloc->r_offset, end, false, | |
15130 | &reloc_size, &leb_ret); | |
15131 | if (leb_ret != 0 || reloc_size == 0 || reloc_size > 8) | |
15132 | error (_("LoongArch ULEB128 field at 0x%lx contains invalid " | |
15133 | "ULEB128 value\n"), | |
15134 | (long) reloc->r_offset); | |
15135 | ||
15136 | else if (sym_index >= num_syms) | |
15137 | error (_("%s reloc contains invalid symbol index " | |
15138 | "%" PRIu64 "\n"), | |
15139 | (reloc_type == 107 | |
15140 | ? "R_LARCH_ADD_ULEB128" | |
15141 | : "R_LARCH_SUB_ULEB128"), | |
15142 | sym_index); | |
15143 | else | |
15144 | { | |
15145 | if (reloc_type == 107) | |
15146 | value += reloc->r_addend + symtab[sym_index].st_value; | |
15147 | else | |
15148 | value -= reloc->r_addend + symtab[sym_index].st_value; | |
15149 | ||
15150 | /* Write uleb128 value to p. */ | |
15151 | bfd_byte *p = start + reloc->r_offset; | |
15152 | do | |
15153 | { | |
15154 | bfd_byte c = value & 0x7f; | |
15155 | value >>= 7; | |
15156 | if (--reloc_size != 0) | |
15157 | c |= 0x80; | |
15158 | *p++ = c; | |
15159 | } | |
15160 | while (reloc_size); | |
15161 | } | |
15162 | ||
15163 | return true; | |
15164 | } | |
15165 | } | |
15166 | break; | |
15167 | } | |
15168 | ||
15169 | case EM_MSP430: | |
15170 | case EM_MSP430_OLD: | |
15171 | { | |
15172 | static Elf_Internal_Sym * saved_sym = NULL; | |
15173 | ||
15174 | if (reloc == NULL) | |
15175 | { | |
15176 | saved_sym = NULL; | |
15177 | return true; | |
15178 | } | |
15179 | ||
15180 | switch (reloc_type) | |
15181 | { | |
15182 | case 10: /* R_MSP430_SYM_DIFF */ | |
15183 | case 12: /* R_MSP430_GNU_SUB_ULEB128 */ | |
15184 | if (uses_msp430x_relocs (filedata)) | |
15185 | break; | |
15186 | /* Fall through. */ | |
15187 | case 21: /* R_MSP430X_SYM_DIFF */ | |
15188 | case 23: /* R_MSP430X_GNU_SUB_ULEB128 */ | |
15189 | /* PR 21139. */ | |
15190 | if (sym_index >= num_syms) | |
15191 | error (_("%s reloc contains invalid symbol index " | |
15192 | "%" PRIu64 "\n"), "MSP430 SYM_DIFF", sym_index); | |
15193 | else | |
15194 | saved_sym = symtab + sym_index; | |
15195 | return true; | |
15196 | ||
15197 | case 1: /* R_MSP430_32 or R_MSP430_ABS32 */ | |
15198 | case 3: /* R_MSP430_16 or R_MSP430_ABS8 */ | |
15199 | goto handle_sym_diff; | |
15200 | ||
15201 | case 5: /* R_MSP430_16_BYTE */ | |
15202 | case 9: /* R_MSP430_8 */ | |
15203 | case 11: /* R_MSP430_GNU_SET_ULEB128 */ | |
15204 | if (uses_msp430x_relocs (filedata)) | |
15205 | break; | |
15206 | goto handle_sym_diff; | |
15207 | ||
15208 | case 2: /* R_MSP430_ABS16 */ | |
15209 | case 15: /* R_MSP430X_ABS16 */ | |
15210 | case 22: /* R_MSP430X_GNU_SET_ULEB128 */ | |
15211 | if (! uses_msp430x_relocs (filedata)) | |
15212 | break; | |
15213 | goto handle_sym_diff; | |
15214 | ||
15215 | handle_sym_diff: | |
15216 | if (saved_sym != NULL) | |
15217 | { | |
15218 | uint64_t value; | |
15219 | unsigned int reloc_size = 0; | |
15220 | int leb_ret = 0; | |
15221 | switch (reloc_type) | |
15222 | { | |
15223 | case 1: /* R_MSP430_32 or R_MSP430_ABS32 */ | |
15224 | reloc_size = 4; | |
15225 | break; | |
15226 | case 11: /* R_MSP430_GNU_SET_ULEB128 */ | |
15227 | case 22: /* R_MSP430X_GNU_SET_ULEB128 */ | |
15228 | if (reloc->r_offset < (size_t) (end - start)) | |
15229 | read_leb128 (start + reloc->r_offset, end, false, | |
15230 | &reloc_size, &leb_ret); | |
15231 | break; | |
15232 | default: | |
15233 | reloc_size = 2; | |
15234 | break; | |
15235 | } | |
15236 | ||
15237 | if (leb_ret != 0 || reloc_size == 0 || reloc_size > 8) | |
15238 | error (_("MSP430 ULEB128 field at %#" PRIx64 | |
15239 | " contains invalid ULEB128 value\n"), | |
15240 | reloc->r_offset); | |
15241 | else if (sym_index >= num_syms) | |
15242 | error (_("%s reloc contains invalid symbol index " | |
15243 | "%" PRIu64 "\n"), "MSP430", sym_index); | |
15244 | else | |
15245 | { | |
15246 | value = reloc->r_addend + (symtab[sym_index].st_value | |
15247 | - saved_sym->st_value); | |
15248 | ||
15249 | if (IN_RANGE (start, end, start + reloc->r_offset, reloc_size)) | |
15250 | byte_put (start + reloc->r_offset, value, reloc_size); | |
15251 | else | |
15252 | /* PR 21137 */ | |
15253 | error (_("MSP430 sym diff reloc contains invalid offset: " | |
15254 | "%#" PRIx64 "\n"), | |
15255 | reloc->r_offset); | |
15256 | } | |
15257 | ||
15258 | saved_sym = NULL; | |
15259 | return true; | |
15260 | } | |
15261 | break; | |
15262 | ||
15263 | default: | |
15264 | if (saved_sym != NULL) | |
15265 | error (_("Unhandled MSP430 reloc type found after SYM_DIFF reloc\n")); | |
15266 | break; | |
15267 | } | |
15268 | break; | |
15269 | } | |
15270 | ||
15271 | case EM_MN10300: | |
15272 | case EM_CYGNUS_MN10300: | |
15273 | { | |
15274 | static Elf_Internal_Sym * saved_sym = NULL; | |
15275 | ||
15276 | if (reloc == NULL) | |
15277 | { | |
15278 | saved_sym = NULL; | |
15279 | return true; | |
15280 | } | |
15281 | ||
15282 | switch (reloc_type) | |
15283 | { | |
15284 | case 34: /* R_MN10300_ALIGN */ | |
15285 | return true; | |
15286 | case 33: /* R_MN10300_SYM_DIFF */ | |
15287 | if (sym_index >= num_syms) | |
15288 | error (_("%s reloc contains invalid symbol index " | |
15289 | "%" PRIu64 "\n"), "MN10300_SYM_DIFF", sym_index); | |
15290 | else | |
15291 | saved_sym = symtab + sym_index; | |
15292 | return true; | |
15293 | ||
15294 | case 1: /* R_MN10300_32 */ | |
15295 | case 2: /* R_MN10300_16 */ | |
15296 | if (saved_sym != NULL) | |
15297 | { | |
15298 | int reloc_size = reloc_type == 1 ? 4 : 2; | |
15299 | uint64_t value; | |
15300 | ||
15301 | if (sym_index >= num_syms) | |
15302 | error (_("%s reloc contains invalid symbol index " | |
15303 | "%" PRIu64 "\n"), "MN10300", sym_index); | |
15304 | else | |
15305 | { | |
15306 | value = reloc->r_addend + (symtab[sym_index].st_value | |
15307 | - saved_sym->st_value); | |
15308 | ||
15309 | if (IN_RANGE (start, end, start + reloc->r_offset, reloc_size)) | |
15310 | byte_put (start + reloc->r_offset, value, reloc_size); | |
15311 | else | |
15312 | error (_("MN10300 sym diff reloc contains invalid offset:" | |
15313 | " %#" PRIx64 "\n"), | |
15314 | reloc->r_offset); | |
15315 | } | |
15316 | ||
15317 | saved_sym = NULL; | |
15318 | return true; | |
15319 | } | |
15320 | break; | |
15321 | default: | |
15322 | if (saved_sym != NULL) | |
15323 | error (_("Unhandled MN10300 reloc type found after SYM_DIFF reloc\n")); | |
15324 | break; | |
15325 | } | |
15326 | break; | |
15327 | } | |
15328 | ||
15329 | case EM_RL78: | |
15330 | { | |
15331 | static uint64_t saved_sym1 = 0; | |
15332 | static uint64_t saved_sym2 = 0; | |
15333 | static uint64_t value; | |
15334 | ||
15335 | if (reloc == NULL) | |
15336 | { | |
15337 | saved_sym1 = saved_sym2 = 0; | |
15338 | return true; | |
15339 | } | |
15340 | ||
15341 | switch (reloc_type) | |
15342 | { | |
15343 | case 0x80: /* R_RL78_SYM. */ | |
15344 | saved_sym1 = saved_sym2; | |
15345 | if (sym_index >= num_syms) | |
15346 | error (_("%s reloc contains invalid symbol index " | |
15347 | "%" PRIu64 "\n"), "RL78_SYM", sym_index); | |
15348 | else | |
15349 | { | |
15350 | saved_sym2 = symtab[sym_index].st_value; | |
15351 | saved_sym2 += reloc->r_addend; | |
15352 | } | |
15353 | return true; | |
15354 | ||
15355 | case 0x83: /* R_RL78_OPsub. */ | |
15356 | value = saved_sym1 - saved_sym2; | |
15357 | saved_sym2 = saved_sym1 = 0; | |
15358 | return true; | |
15359 | break; | |
15360 | ||
15361 | case 0x41: /* R_RL78_ABS32. */ | |
15362 | if (IN_RANGE (start, end, start + reloc->r_offset, 4)) | |
15363 | byte_put (start + reloc->r_offset, value, 4); | |
15364 | else | |
15365 | error (_("RL78 sym diff reloc contains invalid offset: " | |
15366 | "%#" PRIx64 "\n"), | |
15367 | reloc->r_offset); | |
15368 | value = 0; | |
15369 | return true; | |
15370 | ||
15371 | case 0x43: /* R_RL78_ABS16. */ | |
15372 | if (IN_RANGE (start, end, start + reloc->r_offset, 2)) | |
15373 | byte_put (start + reloc->r_offset, value, 2); | |
15374 | else | |
15375 | error (_("RL78 sym diff reloc contains invalid offset: " | |
15376 | "%#" PRIx64 "\n"), | |
15377 | reloc->r_offset); | |
15378 | value = 0; | |
15379 | return true; | |
15380 | ||
15381 | default: | |
15382 | break; | |
15383 | } | |
15384 | break; | |
15385 | } | |
15386 | } | |
15387 | ||
15388 | return false; | |
15389 | } | |
15390 | ||
15391 | /* Returns TRUE iff RELOC_TYPE is a 32-bit absolute RELA relocation used in | |
15392 | DWARF debug sections. This is a target specific test. Note - we do not | |
15393 | go through the whole including-target-headers-multiple-times route, (as | |
15394 | we have already done with <elf/h8.h>) because this would become very | |
15395 | messy and even then this function would have to contain target specific | |
15396 | information (the names of the relocs instead of their numeric values). | |
15397 | FIXME: This is not the correct way to solve this problem. The proper way | |
15398 | is to have target specific reloc sizing and typing functions created by | |
15399 | the reloc-macros.h header, in the same way that it already creates the | |
15400 | reloc naming functions. */ | |
15401 | ||
15402 | static bool | |
15403 | is_32bit_abs_reloc (Filedata * filedata, unsigned int reloc_type) | |
15404 | { | |
15405 | /* Please keep this table alpha-sorted for ease of visual lookup. */ | |
15406 | switch (filedata->file_header.e_machine) | |
15407 | { | |
15408 | case EM_386: | |
15409 | case EM_IAMCU: | |
15410 | return reloc_type == 1; /* R_386_32. */ | |
15411 | case EM_68K: | |
15412 | return reloc_type == 1; /* R_68K_32. */ | |
15413 | case EM_860: | |
15414 | return reloc_type == 1; /* R_860_32. */ | |
15415 | case EM_960: | |
15416 | return reloc_type == 2; /* R_960_32. */ | |
15417 | case EM_AARCH64: | |
15418 | return (reloc_type == 258 | |
15419 | || reloc_type == 1); /* R_AARCH64_ABS32 || R_AARCH64_P32_ABS32 */ | |
15420 | case EM_BPF: | |
15421 | return reloc_type == 11; /* R_BPF_DATA_32 */ | |
15422 | case EM_ADAPTEVA_EPIPHANY: | |
15423 | return reloc_type == 3; | |
15424 | case EM_ALPHA: | |
15425 | return reloc_type == 1; /* R_ALPHA_REFLONG. */ | |
15426 | case EM_ARC: | |
15427 | return reloc_type == 1; /* R_ARC_32. */ | |
15428 | case EM_ARC_COMPACT: | |
15429 | case EM_ARC_COMPACT2: | |
15430 | case EM_ARC_COMPACT3: | |
15431 | case EM_ARC_COMPACT3_64: | |
15432 | return reloc_type == 4; /* R_ARC_32. */ | |
15433 | case EM_ARM: | |
15434 | return reloc_type == 2; /* R_ARM_ABS32 */ | |
15435 | case EM_AVR_OLD: | |
15436 | case EM_AVR: | |
15437 | return reloc_type == 1; | |
15438 | case EM_BLACKFIN: | |
15439 | return reloc_type == 0x12; /* R_byte4_data. */ | |
15440 | case EM_CRIS: | |
15441 | return reloc_type == 3; /* R_CRIS_32. */ | |
15442 | case EM_CR16: | |
15443 | return reloc_type == 3; /* R_CR16_NUM32. */ | |
15444 | case EM_CRX: | |
15445 | return reloc_type == 15; /* R_CRX_NUM32. */ | |
15446 | case EM_CSKY: | |
15447 | return reloc_type == 1; /* R_CKCORE_ADDR32. */ | |
15448 | case EM_CYGNUS_FRV: | |
15449 | return reloc_type == 1; | |
15450 | case EM_CYGNUS_D10V: | |
15451 | case EM_D10V: | |
15452 | return reloc_type == 6; /* R_D10V_32. */ | |
15453 | case EM_CYGNUS_D30V: | |
15454 | case EM_D30V: | |
15455 | return reloc_type == 12; /* R_D30V_32_NORMAL. */ | |
15456 | case EM_DLX: | |
15457 | return reloc_type == 3; /* R_DLX_RELOC_32. */ | |
15458 | case EM_CYGNUS_FR30: | |
15459 | case EM_FR30: | |
15460 | return reloc_type == 3; /* R_FR30_32. */ | |
15461 | case EM_FT32: | |
15462 | return reloc_type == 1; /* R_FT32_32. */ | |
15463 | case EM_H8S: | |
15464 | case EM_H8_300: | |
15465 | case EM_H8_300H: | |
15466 | return reloc_type == 1; /* R_H8_DIR32. */ | |
15467 | case EM_IA_64: | |
15468 | return (reloc_type == 0x64 /* R_IA64_SECREL32MSB. */ | |
15469 | || reloc_type == 0x65 /* R_IA64_SECREL32LSB. */ | |
15470 | || reloc_type == 0x24 /* R_IA64_DIR32MSB. */ | |
15471 | || reloc_type == 0x25 /* R_IA64_DIR32LSB. */); | |
15472 | case EM_IP2K_OLD: | |
15473 | case EM_IP2K: | |
15474 | return reloc_type == 2; /* R_IP2K_32. */ | |
15475 | case EM_IQ2000: | |
15476 | return reloc_type == 2; /* R_IQ2000_32. */ | |
15477 | case EM_KVX: | |
15478 | return reloc_type == 2; /* R_KVX_32. */ | |
15479 | case EM_LATTICEMICO32: | |
15480 | return reloc_type == 3; /* R_LM32_32. */ | |
15481 | case EM_LOONGARCH: | |
15482 | return reloc_type == 1; /* R_LARCH_32. */ | |
15483 | case EM_M32C_OLD: | |
15484 | case EM_M32C: | |
15485 | return reloc_type == 3; /* R_M32C_32. */ | |
15486 | case EM_M32R: | |
15487 | return reloc_type == 34; /* R_M32R_32_RELA. */ | |
15488 | case EM_68HC11: | |
15489 | case EM_68HC12: | |
15490 | return reloc_type == 6; /* R_M68HC11_32. */ | |
15491 | case EM_S12Z: | |
15492 | return reloc_type == 7 || /* R_S12Z_EXT32 */ | |
15493 | reloc_type == 6; /* R_S12Z_CW32. */ | |
15494 | case EM_MCORE: | |
15495 | return reloc_type == 1; /* R_MCORE_ADDR32. */ | |
15496 | case EM_CYGNUS_MEP: | |
15497 | return reloc_type == 4; /* R_MEP_32. */ | |
15498 | case EM_METAG: | |
15499 | return reloc_type == 2; /* R_METAG_ADDR32. */ | |
15500 | case EM_MICROBLAZE: | |
15501 | return reloc_type == 1; /* R_MICROBLAZE_32. */ | |
15502 | case EM_MIPS: | |
15503 | return reloc_type == 2; /* R_MIPS_32. */ | |
15504 | case EM_MMIX: | |
15505 | return reloc_type == 4; /* R_MMIX_32. */ | |
15506 | case EM_CYGNUS_MN10200: | |
15507 | case EM_MN10200: | |
15508 | return reloc_type == 1; /* R_MN10200_32. */ | |
15509 | case EM_CYGNUS_MN10300: | |
15510 | case EM_MN10300: | |
15511 | return reloc_type == 1; /* R_MN10300_32. */ | |
15512 | case EM_MOXIE: | |
15513 | return reloc_type == 1; /* R_MOXIE_32. */ | |
15514 | case EM_MSP430_OLD: | |
15515 | case EM_MSP430: | |
15516 | return reloc_type == 1; /* R_MSP430_32 or R_MSP320_ABS32. */ | |
15517 | case EM_MT: | |
15518 | return reloc_type == 2; /* R_MT_32. */ | |
15519 | case EM_NDS32: | |
15520 | return reloc_type == 20; /* R_NDS32_32_RELA. */ | |
15521 | case EM_ALTERA_NIOS2: | |
15522 | return reloc_type == 12; /* R_NIOS2_BFD_RELOC_32. */ | |
15523 | case EM_NIOS32: | |
15524 | return reloc_type == 1; /* R_NIOS_32. */ | |
15525 | case EM_OR1K: | |
15526 | return reloc_type == 1; /* R_OR1K_32. */ | |
15527 | case EM_PARISC: | |
15528 | return (reloc_type == 1 /* R_PARISC_DIR32. */ | |
15529 | || reloc_type == 2 /* R_PARISC_DIR21L. */ | |
15530 | || reloc_type == 41); /* R_PARISC_SECREL32. */ | |
15531 | case EM_PJ: | |
15532 | case EM_PJ_OLD: | |
15533 | return reloc_type == 1; /* R_PJ_DATA_DIR32. */ | |
15534 | case EM_PPC64: | |
15535 | return reloc_type == 1; /* R_PPC64_ADDR32. */ | |
15536 | case EM_PPC: | |
15537 | return reloc_type == 1; /* R_PPC_ADDR32. */ | |
15538 | case EM_TI_PRU: | |
15539 | return reloc_type == 11; /* R_PRU_BFD_RELOC_32. */ | |
15540 | case EM_RISCV: | |
15541 | return reloc_type == 1; /* R_RISCV_32. */ | |
15542 | case EM_RL78: | |
15543 | return reloc_type == 1; /* R_RL78_DIR32. */ | |
15544 | case EM_RX: | |
15545 | return reloc_type == 1; /* R_RX_DIR32. */ | |
15546 | case EM_S370: | |
15547 | return reloc_type == 1; /* R_I370_ADDR31. */ | |
15548 | case EM_S390_OLD: | |
15549 | case EM_S390: | |
15550 | return reloc_type == 4; /* R_S390_32. */ | |
15551 | case EM_SCORE: | |
15552 | return reloc_type == 8; /* R_SCORE_ABS32. */ | |
15553 | case EM_SH: | |
15554 | return reloc_type == 1; /* R_SH_DIR32. */ | |
15555 | case EM_SPARC32PLUS: | |
15556 | case EM_SPARCV9: | |
15557 | case EM_SPARC: | |
15558 | return reloc_type == 3 /* R_SPARC_32. */ | |
15559 | || reloc_type == 23; /* R_SPARC_UA32. */ | |
15560 | case EM_SPU: | |
15561 | return reloc_type == 6; /* R_SPU_ADDR32 */ | |
15562 | case EM_TI_C6000: | |
15563 | return reloc_type == 1; /* R_C6000_ABS32. */ | |
15564 | case EM_TILEGX: | |
15565 | return reloc_type == 2; /* R_TILEGX_32. */ | |
15566 | case EM_TILEPRO: | |
15567 | return reloc_type == 1; /* R_TILEPRO_32. */ | |
15568 | case EM_CYGNUS_V850: | |
15569 | case EM_V850: | |
15570 | return reloc_type == 6; /* R_V850_ABS32. */ | |
15571 | case EM_V800: | |
15572 | return reloc_type == 0x33; /* R_V810_WORD. */ | |
15573 | case EM_VAX: | |
15574 | return reloc_type == 1; /* R_VAX_32. */ | |
15575 | case EM_VISIUM: | |
15576 | return reloc_type == 3; /* R_VISIUM_32. */ | |
15577 | case EM_WEBASSEMBLY: | |
15578 | return reloc_type == 1; /* R_WASM32_32. */ | |
15579 | case EM_X86_64: | |
15580 | case EM_L1OM: | |
15581 | case EM_K1OM: | |
15582 | return reloc_type == 10; /* R_X86_64_32. */ | |
15583 | case EM_XGATE: | |
15584 | return reloc_type == 4; /* R_XGATE_32. */ | |
15585 | case EM_XSTORMY16: | |
15586 | return reloc_type == 1; /* R_XSTROMY16_32. */ | |
15587 | case EM_XTENSA_OLD: | |
15588 | case EM_XTENSA: | |
15589 | return reloc_type == 1; /* R_XTENSA_32. */ | |
15590 | case EM_Z80: | |
15591 | return reloc_type == 6; /* R_Z80_32. */ | |
15592 | default: | |
15593 | { | |
15594 | static unsigned int prev_warn = 0; | |
15595 | ||
15596 | /* Avoid repeating the same warning multiple times. */ | |
15597 | if (prev_warn != filedata->file_header.e_machine) | |
15598 | error (_("Missing knowledge of 32-bit reloc types used in DWARF sections of machine number %d\n"), | |
15599 | filedata->file_header.e_machine); | |
15600 | prev_warn = filedata->file_header.e_machine; | |
15601 | return false; | |
15602 | } | |
15603 | } | |
15604 | } | |
15605 | ||
15606 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
15607 | a 32-bit pc-relative RELA relocation used in DWARF debug sections. */ | |
15608 | ||
15609 | static bool | |
15610 | is_32bit_pcrel_reloc (Filedata * filedata, unsigned int reloc_type) | |
15611 | { | |
15612 | switch (filedata->file_header.e_machine) | |
15613 | /* Please keep this table alpha-sorted for ease of visual lookup. */ | |
15614 | { | |
15615 | case EM_386: | |
15616 | case EM_IAMCU: | |
15617 | return reloc_type == 2; /* R_386_PC32. */ | |
15618 | case EM_68K: | |
15619 | return reloc_type == 4; /* R_68K_PC32. */ | |
15620 | case EM_AARCH64: | |
15621 | return reloc_type == 261; /* R_AARCH64_PREL32 */ | |
15622 | case EM_ADAPTEVA_EPIPHANY: | |
15623 | return reloc_type == 6; | |
15624 | case EM_ALPHA: | |
15625 | return reloc_type == 10; /* R_ALPHA_SREL32. */ | |
15626 | case EM_ARC_COMPACT: | |
15627 | case EM_ARC_COMPACT2: | |
15628 | case EM_ARC_COMPACT3: | |
15629 | case EM_ARC_COMPACT3_64: | |
15630 | return reloc_type == 49; /* R_ARC_32_PCREL. */ | |
15631 | case EM_ARM: | |
15632 | return reloc_type == 3; /* R_ARM_REL32 */ | |
15633 | case EM_AVR_OLD: | |
15634 | case EM_AVR: | |
15635 | return reloc_type == 36; /* R_AVR_32_PCREL. */ | |
15636 | case EM_LOONGARCH: | |
15637 | return reloc_type == 99; /* R_LARCH_32_PCREL. */ | |
15638 | case EM_MICROBLAZE: | |
15639 | return reloc_type == 2; /* R_MICROBLAZE_32_PCREL. */ | |
15640 | case EM_OR1K: | |
15641 | return reloc_type == 9; /* R_OR1K_32_PCREL. */ | |
15642 | case EM_PARISC: | |
15643 | return reloc_type == 9; /* R_PARISC_PCREL32. */ | |
15644 | case EM_PPC: | |
15645 | return reloc_type == 26; /* R_PPC_REL32. */ | |
15646 | case EM_PPC64: | |
15647 | return reloc_type == 26; /* R_PPC64_REL32. */ | |
15648 | case EM_RISCV: | |
15649 | return reloc_type == 57; /* R_RISCV_32_PCREL. */ | |
15650 | case EM_S390_OLD: | |
15651 | case EM_S390: | |
15652 | return reloc_type == 5; /* R_390_PC32. */ | |
15653 | case EM_SH: | |
15654 | return reloc_type == 2; /* R_SH_REL32. */ | |
15655 | case EM_SPARC32PLUS: | |
15656 | case EM_SPARCV9: | |
15657 | case EM_SPARC: | |
15658 | return reloc_type == 6; /* R_SPARC_DISP32. */ | |
15659 | case EM_SPU: | |
15660 | return reloc_type == 13; /* R_SPU_REL32. */ | |
15661 | case EM_TILEGX: | |
15662 | return reloc_type == 6; /* R_TILEGX_32_PCREL. */ | |
15663 | case EM_TILEPRO: | |
15664 | return reloc_type == 4; /* R_TILEPRO_32_PCREL. */ | |
15665 | case EM_VISIUM: | |
15666 | return reloc_type == 6; /* R_VISIUM_32_PCREL */ | |
15667 | case EM_X86_64: | |
15668 | case EM_L1OM: | |
15669 | case EM_K1OM: | |
15670 | return reloc_type == 2; /* R_X86_64_PC32. */ | |
15671 | case EM_VAX: | |
15672 | return reloc_type == 4; /* R_VAX_PCREL32. */ | |
15673 | case EM_XTENSA_OLD: | |
15674 | case EM_XTENSA: | |
15675 | return reloc_type == 14; /* R_XTENSA_32_PCREL. */ | |
15676 | case EM_KVX: | |
15677 | return reloc_type == 7; /* R_KVX_32_PCREL */ | |
15678 | default: | |
15679 | /* Do not abort or issue an error message here. Not all targets use | |
15680 | pc-relative 32-bit relocs in their DWARF debug information and we | |
15681 | have already tested for target coverage in is_32bit_abs_reloc. A | |
15682 | more helpful warning message will be generated by apply_relocations | |
15683 | anyway, so just return. */ | |
15684 | return false; | |
15685 | } | |
15686 | } | |
15687 | ||
15688 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
15689 | a 64-bit absolute RELA relocation used in DWARF debug sections. */ | |
15690 | ||
15691 | static bool | |
15692 | is_64bit_abs_reloc (Filedata * filedata, unsigned int reloc_type) | |
15693 | { | |
15694 | switch (filedata->file_header.e_machine) | |
15695 | { | |
15696 | case EM_AARCH64: | |
15697 | return reloc_type == 257; /* R_AARCH64_ABS64. */ | |
15698 | case EM_ARC_COMPACT3_64: | |
15699 | return reloc_type == 5; /* R_ARC_64. */ | |
15700 | case EM_ALPHA: | |
15701 | return reloc_type == 2; /* R_ALPHA_REFQUAD. */ | |
15702 | case EM_IA_64: | |
15703 | return (reloc_type == 0x26 /* R_IA64_DIR64MSB. */ | |
15704 | || reloc_type == 0x27 /* R_IA64_DIR64LSB. */); | |
15705 | case EM_LOONGARCH: | |
15706 | return reloc_type == 2; /* R_LARCH_64 */ | |
15707 | case EM_PARISC: | |
15708 | return reloc_type == 80; /* R_PARISC_DIR64. */ | |
15709 | case EM_PPC64: | |
15710 | return reloc_type == 38; /* R_PPC64_ADDR64. */ | |
15711 | case EM_RISCV: | |
15712 | return reloc_type == 2; /* R_RISCV_64. */ | |
15713 | case EM_SPARC32PLUS: | |
15714 | case EM_SPARCV9: | |
15715 | case EM_SPARC: | |
15716 | return reloc_type == 32 /* R_SPARC_64. */ | |
15717 | || reloc_type == 54; /* R_SPARC_UA64. */ | |
15718 | case EM_X86_64: | |
15719 | case EM_L1OM: | |
15720 | case EM_K1OM: | |
15721 | return reloc_type == 1; /* R_X86_64_64. */ | |
15722 | case EM_S390_OLD: | |
15723 | case EM_S390: | |
15724 | return reloc_type == 22; /* R_S390_64. */ | |
15725 | case EM_TILEGX: | |
15726 | return reloc_type == 1; /* R_TILEGX_64. */ | |
15727 | case EM_MIPS: | |
15728 | return reloc_type == 18; /* R_MIPS_64. */ | |
15729 | case EM_KVX: | |
15730 | return reloc_type == 3; /* R_KVX_64 */ | |
15731 | default: | |
15732 | return false; | |
15733 | } | |
15734 | } | |
15735 | ||
15736 | /* Like is_32bit_pcrel_reloc except that it returns TRUE iff RELOC_TYPE is | |
15737 | a 64-bit pc-relative RELA relocation used in DWARF debug sections. */ | |
15738 | ||
15739 | static bool | |
15740 | is_64bit_pcrel_reloc (Filedata * filedata, unsigned int reloc_type) | |
15741 | { | |
15742 | switch (filedata->file_header.e_machine) | |
15743 | { | |
15744 | case EM_AARCH64: | |
15745 | return reloc_type == 260; /* R_AARCH64_PREL64. */ | |
15746 | case EM_ALPHA: | |
15747 | return reloc_type == 11; /* R_ALPHA_SREL64. */ | |
15748 | case EM_IA_64: | |
15749 | return (reloc_type == 0x4e /* R_IA64_PCREL64MSB. */ | |
15750 | || reloc_type == 0x4f /* R_IA64_PCREL64LSB. */); | |
15751 | case EM_PARISC: | |
15752 | return reloc_type == 72; /* R_PARISC_PCREL64. */ | |
15753 | case EM_PPC64: | |
15754 | return reloc_type == 44; /* R_PPC64_REL64. */ | |
15755 | case EM_SPARC32PLUS: | |
15756 | case EM_SPARCV9: | |
15757 | case EM_SPARC: | |
15758 | return reloc_type == 46; /* R_SPARC_DISP64. */ | |
15759 | case EM_X86_64: | |
15760 | case EM_L1OM: | |
15761 | case EM_K1OM: | |
15762 | return reloc_type == 24; /* R_X86_64_PC64. */ | |
15763 | case EM_S390_OLD: | |
15764 | case EM_S390: | |
15765 | return reloc_type == 23; /* R_S390_PC64. */ | |
15766 | case EM_TILEGX: | |
15767 | return reloc_type == 5; /* R_TILEGX_64_PCREL. */ | |
15768 | default: | |
15769 | return false; | |
15770 | } | |
15771 | } | |
15772 | ||
15773 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
15774 | a 24-bit absolute RELA relocation used in DWARF debug sections. */ | |
15775 | ||
15776 | static bool | |
15777 | is_24bit_abs_reloc (Filedata * filedata, unsigned int reloc_type) | |
15778 | { | |
15779 | switch (filedata->file_header.e_machine) | |
15780 | { | |
15781 | case EM_CYGNUS_MN10200: | |
15782 | case EM_MN10200: | |
15783 | return reloc_type == 4; /* R_MN10200_24. */ | |
15784 | case EM_FT32: | |
15785 | return reloc_type == 5; /* R_FT32_20. */ | |
15786 | case EM_Z80: | |
15787 | return reloc_type == 5; /* R_Z80_24. */ | |
15788 | default: | |
15789 | return false; | |
15790 | } | |
15791 | } | |
15792 | ||
15793 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
15794 | a 16-bit absolute RELA relocation used in DWARF debug sections. */ | |
15795 | ||
15796 | static bool | |
15797 | is_16bit_abs_reloc (Filedata * filedata, unsigned int reloc_type) | |
15798 | { | |
15799 | /* Please keep this table alpha-sorted for ease of visual lookup. */ | |
15800 | switch (filedata->file_header.e_machine) | |
15801 | { | |
15802 | case EM_ARC: | |
15803 | case EM_ARC_COMPACT: | |
15804 | case EM_ARC_COMPACT2: | |
15805 | case EM_ARC_COMPACT3: | |
15806 | case EM_ARC_COMPACT3_64: | |
15807 | return reloc_type == 2; /* R_ARC_16. */ | |
15808 | case EM_ADAPTEVA_EPIPHANY: | |
15809 | return reloc_type == 5; | |
15810 | case EM_AVR_OLD: | |
15811 | case EM_AVR: | |
15812 | return reloc_type == 4; /* R_AVR_16. */ | |
15813 | case EM_CYGNUS_D10V: | |
15814 | case EM_D10V: | |
15815 | return reloc_type == 3; /* R_D10V_16. */ | |
15816 | case EM_FT32: | |
15817 | return reloc_type == 2; /* R_FT32_16. */ | |
15818 | case EM_H8S: | |
15819 | case EM_H8_300: | |
15820 | case EM_H8_300H: | |
15821 | return reloc_type == R_H8_DIR16; | |
15822 | case EM_IP2K_OLD: | |
15823 | case EM_IP2K: | |
15824 | return reloc_type == 1; /* R_IP2K_16. */ | |
15825 | case EM_M32C_OLD: | |
15826 | case EM_M32C: | |
15827 | return reloc_type == 1; /* R_M32C_16 */ | |
15828 | case EM_CYGNUS_MN10200: | |
15829 | case EM_MN10200: | |
15830 | return reloc_type == 2; /* R_MN10200_16. */ | |
15831 | case EM_CYGNUS_MN10300: | |
15832 | case EM_MN10300: | |
15833 | return reloc_type == 2; /* R_MN10300_16. */ | |
15834 | case EM_KVX: | |
15835 | return reloc_type == 1; /* R_KVX_16 */ | |
15836 | case EM_MSP430: | |
15837 | if (uses_msp430x_relocs (filedata)) | |
15838 | return reloc_type == 2; /* R_MSP430_ABS16. */ | |
15839 | /* Fall through. */ | |
15840 | case EM_MSP430_OLD: | |
15841 | return reloc_type == 5; /* R_MSP430_16_BYTE. */ | |
15842 | case EM_NDS32: | |
15843 | return reloc_type == 19; /* R_NDS32_16_RELA. */ | |
15844 | case EM_ALTERA_NIOS2: | |
15845 | return reloc_type == 13; /* R_NIOS2_BFD_RELOC_16. */ | |
15846 | case EM_NIOS32: | |
15847 | return reloc_type == 9; /* R_NIOS_16. */ | |
15848 | case EM_OR1K: | |
15849 | return reloc_type == 2; /* R_OR1K_16. */ | |
15850 | case EM_RISCV: | |
15851 | return reloc_type == 55; /* R_RISCV_SET16. */ | |
15852 | case EM_TI_PRU: | |
15853 | return reloc_type == 8; /* R_PRU_BFD_RELOC_16. */ | |
15854 | case EM_TI_C6000: | |
15855 | return reloc_type == 2; /* R_C6000_ABS16. */ | |
15856 | case EM_VISIUM: | |
15857 | return reloc_type == 2; /* R_VISIUM_16. */ | |
15858 | case EM_XGATE: | |
15859 | return reloc_type == 3; /* R_XGATE_16. */ | |
15860 | case EM_Z80: | |
15861 | return reloc_type == 4; /* R_Z80_16. */ | |
15862 | default: | |
15863 | return false; | |
15864 | } | |
15865 | } | |
15866 | ||
15867 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
15868 | a 8-bit absolute RELA relocation used in DWARF debug sections. */ | |
15869 | ||
15870 | static bool | |
15871 | is_8bit_abs_reloc (Filedata * filedata, unsigned int reloc_type) | |
15872 | { | |
15873 | switch (filedata->file_header.e_machine) | |
15874 | { | |
15875 | case EM_RISCV: | |
15876 | return reloc_type == 54; /* R_RISCV_SET8. */ | |
15877 | case EM_Z80: | |
15878 | return reloc_type == 1; /* R_Z80_8. */ | |
15879 | case EM_MICROBLAZE: | |
15880 | return (reloc_type == 33 /* R_MICROBLAZE_32_NONE. */ | |
15881 | || reloc_type == 0 /* R_MICROBLAZE_NONE. */ | |
15882 | || reloc_type == 9 /* R_MICROBLAZE_64_NONE. */); | |
15883 | default: | |
15884 | return false; | |
15885 | } | |
15886 | } | |
15887 | ||
15888 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
15889 | a 6-bit absolute RELA relocation used in DWARF debug sections. */ | |
15890 | ||
15891 | static bool | |
15892 | is_6bit_abs_reloc (Filedata * filedata, unsigned int reloc_type) | |
15893 | { | |
15894 | switch (filedata->file_header.e_machine) | |
15895 | { | |
15896 | case EM_RISCV: | |
15897 | return reloc_type == 53; /* R_RISCV_SET6. */ | |
15898 | default: | |
15899 | return false; | |
15900 | } | |
15901 | } | |
15902 | ||
15903 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
15904 | a 32-bit inplace add RELA relocation used in DWARF debug sections. */ | |
15905 | ||
15906 | static bool | |
15907 | is_32bit_inplace_add_reloc (Filedata * filedata, unsigned int reloc_type) | |
15908 | { | |
15909 | /* Please keep this table alpha-sorted for ease of visual lookup. */ | |
15910 | switch (filedata->file_header.e_machine) | |
15911 | { | |
15912 | case EM_LOONGARCH: | |
15913 | return reloc_type == 50; /* R_LARCH_ADD32. */ | |
15914 | case EM_RISCV: | |
15915 | return reloc_type == 35; /* R_RISCV_ADD32. */ | |
15916 | default: | |
15917 | return false; | |
15918 | } | |
15919 | } | |
15920 | ||
15921 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
15922 | a 32-bit inplace sub RELA relocation used in DWARF debug sections. */ | |
15923 | ||
15924 | static bool | |
15925 | is_32bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type) | |
15926 | { | |
15927 | /* Please keep this table alpha-sorted for ease of visual lookup. */ | |
15928 | switch (filedata->file_header.e_machine) | |
15929 | { | |
15930 | case EM_LOONGARCH: | |
15931 | return reloc_type == 55; /* R_LARCH_SUB32. */ | |
15932 | case EM_RISCV: | |
15933 | return reloc_type == 39; /* R_RISCV_SUB32. */ | |
15934 | default: | |
15935 | return false; | |
15936 | } | |
15937 | } | |
15938 | ||
15939 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
15940 | a 64-bit inplace add RELA relocation used in DWARF debug sections. */ | |
15941 | ||
15942 | static bool | |
15943 | is_64bit_inplace_add_reloc (Filedata * filedata, unsigned int reloc_type) | |
15944 | { | |
15945 | /* Please keep this table alpha-sorted for ease of visual lookup. */ | |
15946 | switch (filedata->file_header.e_machine) | |
15947 | { | |
15948 | case EM_LOONGARCH: | |
15949 | return reloc_type == 51; /* R_LARCH_ADD64. */ | |
15950 | case EM_RISCV: | |
15951 | return reloc_type == 36; /* R_RISCV_ADD64. */ | |
15952 | default: | |
15953 | return false; | |
15954 | } | |
15955 | } | |
15956 | ||
15957 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
15958 | a 64-bit inplace sub RELA relocation used in DWARF debug sections. */ | |
15959 | ||
15960 | static bool | |
15961 | is_64bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type) | |
15962 | { | |
15963 | /* Please keep this table alpha-sorted for ease of visual lookup. */ | |
15964 | switch (filedata->file_header.e_machine) | |
15965 | { | |
15966 | case EM_LOONGARCH: | |
15967 | return reloc_type == 56; /* R_LARCH_SUB64. */ | |
15968 | case EM_RISCV: | |
15969 | return reloc_type == 40; /* R_RISCV_SUB64. */ | |
15970 | default: | |
15971 | return false; | |
15972 | } | |
15973 | } | |
15974 | ||
15975 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
15976 | a 16-bit inplace add RELA relocation used in DWARF debug sections. */ | |
15977 | ||
15978 | static bool | |
15979 | is_16bit_inplace_add_reloc (Filedata * filedata, unsigned int reloc_type) | |
15980 | { | |
15981 | /* Please keep this table alpha-sorted for ease of visual lookup. */ | |
15982 | switch (filedata->file_header.e_machine) | |
15983 | { | |
15984 | case EM_LOONGARCH: | |
15985 | return reloc_type == 48; /* R_LARCH_ADD16. */ | |
15986 | case EM_RISCV: | |
15987 | return reloc_type == 34; /* R_RISCV_ADD16. */ | |
15988 | default: | |
15989 | return false; | |
15990 | } | |
15991 | } | |
15992 | ||
15993 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
15994 | a 16-bit inplace sub RELA relocation used in DWARF debug sections. */ | |
15995 | ||
15996 | static bool | |
15997 | is_16bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type) | |
15998 | { | |
15999 | /* Please keep this table alpha-sorted for ease of visual lookup. */ | |
16000 | switch (filedata->file_header.e_machine) | |
16001 | { | |
16002 | case EM_LOONGARCH: | |
16003 | return reloc_type == 53; /* R_LARCH_SUB16. */ | |
16004 | case EM_RISCV: | |
16005 | return reloc_type == 38; /* R_RISCV_SUB16. */ | |
16006 | default: | |
16007 | return false; | |
16008 | } | |
16009 | } | |
16010 | ||
16011 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
16012 | a 8-bit inplace add RELA relocation used in DWARF debug sections. */ | |
16013 | ||
16014 | static bool | |
16015 | is_8bit_inplace_add_reloc (Filedata * filedata, unsigned int reloc_type) | |
16016 | { | |
16017 | /* Please keep this table alpha-sorted for ease of visual lookup. */ | |
16018 | switch (filedata->file_header.e_machine) | |
16019 | { | |
16020 | case EM_LOONGARCH: | |
16021 | return reloc_type == 47; /* R_LARCH_ADD8. */ | |
16022 | case EM_RISCV: | |
16023 | return reloc_type == 33; /* R_RISCV_ADD8. */ | |
16024 | default: | |
16025 | return false; | |
16026 | } | |
16027 | } | |
16028 | ||
16029 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
16030 | a 8-bit inplace sub RELA relocation used in DWARF debug sections. */ | |
16031 | ||
16032 | static bool | |
16033 | is_8bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type) | |
16034 | { | |
16035 | /* Please keep this table alpha-sorted for ease of visual lookup. */ | |
16036 | switch (filedata->file_header.e_machine) | |
16037 | { | |
16038 | case EM_LOONGARCH: | |
16039 | return reloc_type == 52; /* R_LARCH_SUB8. */ | |
16040 | case EM_RISCV: | |
16041 | return reloc_type == 37; /* R_RISCV_SUB8. */ | |
16042 | default: | |
16043 | return false; | |
16044 | } | |
16045 | } | |
16046 | ||
16047 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
16048 | a 6-bit inplace add RELA relocation used in DWARF debug sections. */ | |
16049 | ||
16050 | static bool | |
16051 | is_6bit_inplace_add_reloc (Filedata * filedata, unsigned int reloc_type) | |
16052 | { | |
16053 | switch (filedata->file_header.e_machine) | |
16054 | { | |
16055 | case EM_LOONGARCH: | |
16056 | return reloc_type == 105; /* R_LARCH_ADD6. */ | |
16057 | default: | |
16058 | return false; | |
16059 | } | |
16060 | } | |
16061 | ||
16062 | /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is | |
16063 | a 6-bit inplace sub RELA relocation used in DWARF debug sections. */ | |
16064 | ||
16065 | static bool | |
16066 | is_6bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type) | |
16067 | { | |
16068 | switch (filedata->file_header.e_machine) | |
16069 | { | |
16070 | case EM_LOONGARCH: | |
16071 | return reloc_type == 106; /* R_LARCH_SUB6. */ | |
16072 | case EM_RISCV: | |
16073 | return reloc_type == 52; /* R_RISCV_SUB6. */ | |
16074 | default: | |
16075 | return false; | |
16076 | } | |
16077 | } | |
16078 | ||
16079 | /* Returns TRUE iff RELOC_TYPE is a NONE relocation used for discarded | |
16080 | relocation entries (possibly formerly used for SHT_GROUP sections). */ | |
16081 | ||
16082 | static bool | |
16083 | is_none_reloc (Filedata * filedata, unsigned int reloc_type) | |
16084 | { | |
16085 | switch (filedata->file_header.e_machine) | |
16086 | { | |
16087 | case EM_386: /* R_386_NONE. */ | |
16088 | case EM_68K: /* R_68K_NONE. */ | |
16089 | case EM_ADAPTEVA_EPIPHANY: | |
16090 | case EM_ALPHA: /* R_ALPHA_NONE. */ | |
16091 | case EM_ALTERA_NIOS2: /* R_NIOS2_NONE. */ | |
16092 | case EM_ARC: /* R_ARC_NONE. */ | |
16093 | case EM_ARC_COMPACT2: /* R_ARC_NONE. */ | |
16094 | case EM_ARC_COMPACT: /* R_ARC_NONE. */ | |
16095 | case EM_ARC_COMPACT3: /* R_ARC_NONE. */ | |
16096 | case EM_ARC_COMPACT3_64: /* R_ARC_NONE. */ | |
16097 | case EM_ARM: /* R_ARM_NONE. */ | |
16098 | case EM_CRIS: /* R_CRIS_NONE. */ | |
16099 | case EM_FT32: /* R_FT32_NONE. */ | |
16100 | case EM_IA_64: /* R_IA64_NONE. */ | |
16101 | case EM_K1OM: /* R_X86_64_NONE. */ | |
16102 | case EM_KVX: /* R_KVX_NONE. */ | |
16103 | case EM_L1OM: /* R_X86_64_NONE. */ | |
16104 | case EM_M32R: /* R_M32R_NONE. */ | |
16105 | case EM_MIPS: /* R_MIPS_NONE. */ | |
16106 | case EM_MN10300: /* R_MN10300_NONE. */ | |
16107 | case EM_MOXIE: /* R_MOXIE_NONE. */ | |
16108 | case EM_NIOS32: /* R_NIOS_NONE. */ | |
16109 | case EM_OR1K: /* R_OR1K_NONE. */ | |
16110 | case EM_PARISC: /* R_PARISC_NONE. */ | |
16111 | case EM_PPC64: /* R_PPC64_NONE. */ | |
16112 | case EM_PPC: /* R_PPC_NONE. */ | |
16113 | case EM_RISCV: /* R_RISCV_NONE. */ | |
16114 | case EM_S390: /* R_390_NONE. */ | |
16115 | case EM_S390_OLD: | |
16116 | case EM_SH: /* R_SH_NONE. */ | |
16117 | case EM_SPARC32PLUS: | |
16118 | case EM_SPARC: /* R_SPARC_NONE. */ | |
16119 | case EM_SPARCV9: | |
16120 | case EM_TILEGX: /* R_TILEGX_NONE. */ | |
16121 | case EM_TILEPRO: /* R_TILEPRO_NONE. */ | |
16122 | case EM_TI_C6000:/* R_C6000_NONE. */ | |
16123 | case EM_X86_64: /* R_X86_64_NONE. */ | |
16124 | case EM_Z80: /* R_Z80_NONE. */ | |
16125 | case EM_WEBASSEMBLY: /* R_WASM32_NONE. */ | |
16126 | return reloc_type == 0; | |
16127 | ||
16128 | case EM_AARCH64: | |
16129 | return reloc_type == 0 || reloc_type == 256; | |
16130 | case EM_AVR_OLD: | |
16131 | case EM_AVR: | |
16132 | return (reloc_type == 0 /* R_AVR_NONE. */ | |
16133 | || reloc_type == 30 /* R_AVR_DIFF8. */ | |
16134 | || reloc_type == 31 /* R_AVR_DIFF16. */ | |
16135 | || reloc_type == 32 /* R_AVR_DIFF32. */); | |
16136 | case EM_METAG: | |
16137 | return reloc_type == 3; /* R_METAG_NONE. */ | |
16138 | case EM_NDS32: | |
16139 | return (reloc_type == 0 /* R_NDS32_NONE. */ | |
16140 | || reloc_type == 205 /* R_NDS32_DIFF8. */ | |
16141 | || reloc_type == 206 /* R_NDS32_DIFF16. */ | |
16142 | || reloc_type == 207 /* R_NDS32_DIFF32. */ | |
16143 | || reloc_type == 208 /* R_NDS32_DIFF_ULEB128. */); | |
16144 | case EM_TI_PRU: | |
16145 | return (reloc_type == 0 /* R_PRU_NONE. */ | |
16146 | || reloc_type == 65 /* R_PRU_DIFF8. */ | |
16147 | || reloc_type == 66 /* R_PRU_DIFF16. */ | |
16148 | || reloc_type == 67 /* R_PRU_DIFF32. */); | |
16149 | case EM_XTENSA_OLD: | |
16150 | case EM_XTENSA: | |
16151 | return (reloc_type == 0 /* R_XTENSA_NONE. */ | |
16152 | || reloc_type == 17 /* R_XTENSA_DIFF8. */ | |
16153 | || reloc_type == 18 /* R_XTENSA_DIFF16. */ | |
16154 | || reloc_type == 19 /* R_XTENSA_DIFF32. */ | |
16155 | || reloc_type == 57 /* R_XTENSA_PDIFF8. */ | |
16156 | || reloc_type == 58 /* R_XTENSA_PDIFF16. */ | |
16157 | || reloc_type == 59 /* R_XTENSA_PDIFF32. */ | |
16158 | || reloc_type == 60 /* R_XTENSA_NDIFF8. */ | |
16159 | || reloc_type == 61 /* R_XTENSA_NDIFF16. */ | |
16160 | || reloc_type == 62 /* R_XTENSA_NDIFF32. */); | |
16161 | } | |
16162 | return false; | |
16163 | } | |
16164 | ||
16165 | /* Returns TRUE if there is a relocation against | |
16166 | section NAME at OFFSET bytes. */ | |
16167 | ||
16168 | bool | |
16169 | reloc_at (struct dwarf_section * dsec, uint64_t offset) | |
16170 | { | |
16171 | Elf_Internal_Rela * relocs; | |
16172 | Elf_Internal_Rela * rp; | |
16173 | ||
16174 | if (dsec == NULL || dsec->reloc_info == NULL) | |
16175 | return false; | |
16176 | ||
16177 | relocs = (Elf_Internal_Rela *) dsec->reloc_info; | |
16178 | ||
16179 | for (rp = relocs; rp < relocs + dsec->num_relocs; ++rp) | |
16180 | if (rp->r_offset == offset) | |
16181 | return true; | |
16182 | ||
16183 | return false; | |
16184 | } | |
16185 | ||
16186 | /* Apply relocations to a section. | |
16187 | Returns TRUE upon success, FALSE otherwise. | |
16188 | If RELOCS_RETURN is non-NULL then it is set to point to the loaded relocs. | |
16189 | It is then the caller's responsibility to free them. NUM_RELOCS_RETURN | |
16190 | will be set to the number of relocs loaded. | |
16191 | ||
16192 | Note: So far support has been added only for those relocations | |
16193 | which can be found in debug sections. FIXME: Add support for | |
16194 | more relocations ? */ | |
16195 | ||
16196 | static bool | |
16197 | apply_relocations (Filedata *filedata, | |
16198 | const Elf_Internal_Shdr *section, | |
16199 | unsigned char *start, | |
16200 | size_t size, | |
16201 | void **relocs_return, | |
16202 | uint64_t *num_relocs_return) | |
16203 | { | |
16204 | Elf_Internal_Shdr * relsec; | |
16205 | unsigned char * end = start + size; | |
16206 | ||
16207 | if (relocs_return != NULL) | |
16208 | { | |
16209 | * (Elf_Internal_Rela **) relocs_return = NULL; | |
16210 | * num_relocs_return = 0; | |
16211 | } | |
16212 | ||
16213 | if (filedata->file_header.e_type != ET_REL) | |
16214 | /* No relocs to apply. */ | |
16215 | return true; | |
16216 | ||
16217 | /* Find the reloc section associated with the section. */ | |
16218 | for (relsec = filedata->section_headers; | |
16219 | relsec < filedata->section_headers + filedata->file_header.e_shnum; | |
16220 | ++relsec) | |
16221 | { | |
16222 | bool is_rela; | |
16223 | uint64_t num_relocs; | |
16224 | Elf_Internal_Rela * relocs; | |
16225 | Elf_Internal_Rela * rp; | |
16226 | Elf_Internal_Shdr * symsec; | |
16227 | Elf_Internal_Sym * symtab; | |
16228 | uint64_t num_syms; | |
16229 | Elf_Internal_Sym * sym; | |
16230 | ||
16231 | if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL) | |
16232 | || relsec->sh_info >= filedata->file_header.e_shnum | |
16233 | || filedata->section_headers + relsec->sh_info != section | |
16234 | || relsec->sh_size == 0 | |
16235 | || relsec->sh_link >= filedata->file_header.e_shnum) | |
16236 | continue; | |
16237 | ||
16238 | symsec = filedata->section_headers + relsec->sh_link; | |
16239 | if (symsec->sh_type != SHT_SYMTAB | |
16240 | && symsec->sh_type != SHT_DYNSYM) | |
16241 | return false; | |
16242 | ||
16243 | is_rela = relsec->sh_type == SHT_RELA; | |
16244 | ||
16245 | if (is_rela) | |
16246 | { | |
16247 | if (!slurp_rela_relocs (filedata, relsec->sh_offset, | |
16248 | relsec->sh_size, & relocs, & num_relocs)) | |
16249 | return false; | |
16250 | } | |
16251 | else | |
16252 | { | |
16253 | if (!slurp_rel_relocs (filedata, relsec->sh_offset, | |
16254 | relsec->sh_size, & relocs, & num_relocs)) | |
16255 | return false; | |
16256 | } | |
16257 | ||
16258 | /* SH uses RELA but uses in place value instead of the addend field. */ | |
16259 | if (filedata->file_header.e_machine == EM_SH) | |
16260 | is_rela = false; | |
16261 | ||
16262 | symtab = get_elf_symbols (filedata, symsec, & num_syms); | |
16263 | ||
16264 | for (rp = relocs; rp < relocs + num_relocs; ++rp) | |
16265 | { | |
16266 | uint64_t addend; | |
16267 | unsigned int reloc_type; | |
16268 | unsigned int reloc_size; | |
16269 | bool reloc_inplace = false; | |
16270 | bool reloc_subtract = false; | |
16271 | unsigned char *rloc; | |
16272 | uint64_t sym_index; | |
16273 | ||
16274 | reloc_type = get_reloc_type (filedata, rp->r_info); | |
16275 | ||
16276 | if (target_specific_reloc_handling (filedata, rp, start, end, symtab, num_syms)) | |
16277 | continue; | |
16278 | else if (is_none_reloc (filedata, reloc_type)) | |
16279 | continue; | |
16280 | else if (is_32bit_abs_reloc (filedata, reloc_type) | |
16281 | || is_32bit_pcrel_reloc (filedata, reloc_type)) | |
16282 | reloc_size = 4; | |
16283 | else if (is_64bit_abs_reloc (filedata, reloc_type) | |
16284 | || is_64bit_pcrel_reloc (filedata, reloc_type)) | |
16285 | reloc_size = 8; | |
16286 | else if (is_24bit_abs_reloc (filedata, reloc_type)) | |
16287 | reloc_size = 3; | |
16288 | else if (is_16bit_abs_reloc (filedata, reloc_type)) | |
16289 | reloc_size = 2; | |
16290 | else if (is_8bit_abs_reloc (filedata, reloc_type) | |
16291 | || is_6bit_abs_reloc (filedata, reloc_type)) | |
16292 | reloc_size = 1; | |
16293 | else if ((reloc_subtract = is_32bit_inplace_sub_reloc (filedata, | |
16294 | reloc_type)) | |
16295 | || is_32bit_inplace_add_reloc (filedata, reloc_type)) | |
16296 | { | |
16297 | reloc_size = 4; | |
16298 | reloc_inplace = true; | |
16299 | } | |
16300 | else if ((reloc_subtract = is_64bit_inplace_sub_reloc (filedata, | |
16301 | reloc_type)) | |
16302 | || is_64bit_inplace_add_reloc (filedata, reloc_type)) | |
16303 | { | |
16304 | reloc_size = 8; | |
16305 | reloc_inplace = true; | |
16306 | } | |
16307 | else if ((reloc_subtract = is_16bit_inplace_sub_reloc (filedata, | |
16308 | reloc_type)) | |
16309 | || is_16bit_inplace_add_reloc (filedata, reloc_type)) | |
16310 | { | |
16311 | reloc_size = 2; | |
16312 | reloc_inplace = true; | |
16313 | } | |
16314 | else if ((reloc_subtract = is_8bit_inplace_sub_reloc (filedata, | |
16315 | reloc_type)) | |
16316 | || is_8bit_inplace_add_reloc (filedata, reloc_type)) | |
16317 | { | |
16318 | reloc_size = 1; | |
16319 | reloc_inplace = true; | |
16320 | } | |
16321 | else if ((reloc_subtract = is_6bit_inplace_sub_reloc (filedata, | |
16322 | reloc_type)) | |
16323 | || is_6bit_inplace_add_reloc (filedata, reloc_type)) | |
16324 | { | |
16325 | reloc_size = 1; | |
16326 | reloc_inplace = true; | |
16327 | } | |
16328 | else | |
16329 | { | |
16330 | static unsigned int prev_reloc = 0; | |
16331 | ||
16332 | if (reloc_type != prev_reloc) | |
16333 | warn (_("unable to apply unsupported reloc type %d to section %s\n"), | |
16334 | reloc_type, printable_section_name (filedata, section)); | |
16335 | prev_reloc = reloc_type; | |
16336 | continue; | |
16337 | } | |
16338 | ||
16339 | rloc = start + rp->r_offset; | |
16340 | if (!IN_RANGE (start, end, rloc, reloc_size)) | |
16341 | { | |
16342 | warn (_("skipping invalid relocation offset %#" PRIx64 | |
16343 | " in section %s\n"), | |
16344 | rp->r_offset, | |
16345 | printable_section_name (filedata, section)); | |
16346 | continue; | |
16347 | } | |
16348 | ||
16349 | sym_index = get_reloc_symindex (rp->r_info); | |
16350 | if (sym_index >= num_syms) | |
16351 | { | |
16352 | warn (_("skipping invalid relocation symbol index %#" PRIx64 | |
16353 | " in section %s\n"), | |
16354 | sym_index, printable_section_name (filedata, section)); | |
16355 | continue; | |
16356 | } | |
16357 | sym = symtab + sym_index; | |
16358 | ||
16359 | /* If the reloc has a symbol associated with it, | |
16360 | make sure that it is of an appropriate type. | |
16361 | ||
16362 | Relocations against symbols without type can happen. | |
16363 | Gcc -feliminate-dwarf2-dups may generate symbols | |
16364 | without type for debug info. | |
16365 | ||
16366 | Icc generates relocations against function symbols | |
16367 | instead of local labels. | |
16368 | ||
16369 | Relocations against object symbols can happen, eg when | |
16370 | referencing a global array. For an example of this see | |
16371 | the _clz.o binary in libgcc.a. */ | |
16372 | if (sym != symtab | |
16373 | && ELF_ST_TYPE (sym->st_info) != STT_COMMON | |
16374 | && ELF_ST_TYPE (sym->st_info) > STT_SECTION) | |
16375 | { | |
16376 | warn (_("skipping unexpected symbol type %s in section %s relocation %tu\n"), | |
16377 | get_symbol_type (filedata, ELF_ST_TYPE (sym->st_info)), | |
16378 | printable_section_name (filedata, relsec), | |
16379 | rp - relocs); | |
16380 | continue; | |
16381 | } | |
16382 | ||
16383 | addend = 0; | |
16384 | if (is_rela) | |
16385 | addend += rp->r_addend; | |
16386 | /* R_XTENSA_32, R_PJ_DATA_DIR32 and R_D30V_32_NORMAL are | |
16387 | partial_inplace. */ | |
16388 | if (!is_rela | |
16389 | || (filedata->file_header.e_machine == EM_XTENSA | |
16390 | && reloc_type == 1) | |
16391 | || ((filedata->file_header.e_machine == EM_PJ | |
16392 | || filedata->file_header.e_machine == EM_PJ_OLD) | |
16393 | && reloc_type == 1) | |
16394 | || ((filedata->file_header.e_machine == EM_D30V | |
16395 | || filedata->file_header.e_machine == EM_CYGNUS_D30V) | |
16396 | && reloc_type == 12) | |
16397 | || reloc_inplace) | |
16398 | { | |
16399 | if (is_6bit_inplace_sub_reloc (filedata, reloc_type)) | |
16400 | addend += byte_get (rloc, reloc_size) & 0x3f; | |
16401 | else | |
16402 | addend += byte_get (rloc, reloc_size); | |
16403 | } | |
16404 | ||
16405 | if (is_32bit_pcrel_reloc (filedata, reloc_type) | |
16406 | || is_64bit_pcrel_reloc (filedata, reloc_type)) | |
16407 | { | |
16408 | /* On HPPA, all pc-relative relocations are biased by 8. */ | |
16409 | if (filedata->file_header.e_machine == EM_PARISC) | |
16410 | addend -= 8; | |
16411 | byte_put (rloc, (addend + sym->st_value) - rp->r_offset, | |
16412 | reloc_size); | |
16413 | } | |
16414 | else if (is_6bit_abs_reloc (filedata, reloc_type) | |
16415 | || is_6bit_inplace_sub_reloc (filedata, reloc_type) | |
16416 | || is_6bit_inplace_add_reloc (filedata, reloc_type)) | |
16417 | { | |
16418 | if (reloc_subtract) | |
16419 | addend -= sym->st_value; | |
16420 | else | |
16421 | addend += sym->st_value; | |
16422 | addend = (addend & 0x3f) | (byte_get (rloc, reloc_size) & 0xc0); | |
16423 | byte_put (rloc, addend, reloc_size); | |
16424 | } | |
16425 | else if (reloc_subtract) | |
16426 | byte_put (rloc, addend - sym->st_value, reloc_size); | |
16427 | else | |
16428 | byte_put (rloc, addend + sym->st_value, reloc_size); | |
16429 | } | |
16430 | ||
16431 | free (symtab); | |
16432 | /* Let the target specific reloc processing code know that | |
16433 | we have finished with these relocs. */ | |
16434 | target_specific_reloc_handling (filedata, NULL, NULL, NULL, NULL, 0); | |
16435 | ||
16436 | if (relocs_return) | |
16437 | { | |
16438 | * (Elf_Internal_Rela **) relocs_return = relocs; | |
16439 | * num_relocs_return = num_relocs; | |
16440 | } | |
16441 | else | |
16442 | free (relocs); | |
16443 | ||
16444 | break; | |
16445 | } | |
16446 | ||
16447 | return true; | |
16448 | } | |
16449 | ||
16450 | #ifdef SUPPORT_DISASSEMBLY | |
16451 | static bool | |
16452 | disassemble_section (Elf_Internal_Shdr * section, Filedata * filedata) | |
16453 | { | |
16454 | printf (_("\nAssembly dump of section %s\n"), printable_section_name (filedata, section)); | |
16455 | ||
16456 | /* FIXME: XXX -- to be done --- XXX */ | |
16457 | ||
16458 | return true; | |
16459 | } | |
16460 | #endif | |
16461 | ||
16462 | /* Reads in the contents of SECTION from FILE, returning a pointer | |
16463 | to a malloc'ed buffer or NULL if something went wrong. */ | |
16464 | ||
16465 | static char * | |
16466 | get_section_contents (Elf_Internal_Shdr * section, Filedata * filedata) | |
16467 | { | |
16468 | uint64_t num_bytes = section->sh_size; | |
16469 | ||
16470 | if (num_bytes == 0 || section->sh_type == SHT_NOBITS) | |
16471 | { | |
16472 | printf (_("Section '%s' has no data to dump.\n"), | |
16473 | printable_section_name (filedata, section)); | |
16474 | return NULL; | |
16475 | } | |
16476 | ||
16477 | return (char *) get_data (NULL, filedata, section->sh_offset, 1, num_bytes, | |
16478 | _("section contents")); | |
16479 | } | |
16480 | ||
16481 | /* Uncompresses a section that was compressed using zlib/zstd, in place. */ | |
16482 | ||
16483 | static bool | |
16484 | uncompress_section_contents (bool is_zstd, | |
16485 | unsigned char ** buffer, | |
16486 | uint64_t uncompressed_size, | |
16487 | uint64_t * size, | |
16488 | uint64_t file_size) | |
16489 | { | |
16490 | uint64_t compressed_size = *size; | |
16491 | unsigned char *compressed_buffer = *buffer; | |
16492 | unsigned char *uncompressed_buffer = NULL; | |
16493 | z_stream strm; | |
16494 | int rc; | |
16495 | ||
16496 | /* Similar to bfd_section_size_insane() in the BFD library we expect an | |
16497 | upper limit of ~10x compression. Any compression larger than that is | |
16498 | thought to be due to fuzzing of the compression header. */ | |
16499 | if (uncompressed_size > file_size * 10) | |
16500 | { | |
16501 | error (_("Uncompressed section size is suspiciously large: 0x%" PRIu64 "\n"), | |
16502 | uncompressed_size); | |
16503 | goto fail; | |
16504 | } | |
16505 | ||
16506 | uncompressed_buffer = xmalloc (uncompressed_size); | |
16507 | ||
16508 | if (is_zstd) | |
16509 | { | |
16510 | #ifdef HAVE_ZSTD | |
16511 | size_t ret = ZSTD_decompress (uncompressed_buffer, uncompressed_size, | |
16512 | compressed_buffer, compressed_size); | |
16513 | if (ZSTD_isError (ret)) | |
16514 | goto fail; | |
16515 | #endif | |
16516 | } | |
16517 | else | |
16518 | { | |
16519 | /* It is possible the section consists of several compressed | |
16520 | buffers concatenated together, so we uncompress in a loop. */ | |
16521 | /* PR 18313: The state field in the z_stream structure is supposed | |
16522 | to be invisible to the user (ie us), but some compilers will | |
16523 | still complain about it being used without initialisation. So | |
16524 | we first zero the entire z_stream structure and then set the fields | |
16525 | that we need. */ | |
16526 | memset (&strm, 0, sizeof strm); | |
16527 | strm.avail_in = compressed_size; | |
16528 | strm.next_in = (Bytef *)compressed_buffer; | |
16529 | strm.avail_out = uncompressed_size; | |
16530 | ||
16531 | rc = inflateInit (&strm); | |
16532 | while (strm.avail_in > 0) | |
16533 | { | |
16534 | if (rc != Z_OK) | |
16535 | break; | |
16536 | strm.next_out = ((Bytef *)uncompressed_buffer | |
16537 | + (uncompressed_size - strm.avail_out)); | |
16538 | rc = inflate (&strm, Z_FINISH); | |
16539 | if (rc != Z_STREAM_END) | |
16540 | break; | |
16541 | rc = inflateReset (&strm); | |
16542 | } | |
16543 | if (inflateEnd (&strm) != Z_OK || rc != Z_OK || strm.avail_out != 0) | |
16544 | goto fail; | |
16545 | } | |
16546 | ||
16547 | *buffer = uncompressed_buffer; | |
16548 | *size = uncompressed_size; | |
16549 | return true; | |
16550 | ||
16551 | fail: | |
16552 | free (uncompressed_buffer); | |
16553 | /* Indicate decompression failure. */ | |
16554 | *buffer = NULL; | |
16555 | return false; | |
16556 | } | |
16557 | ||
16558 | static uint64_t | |
16559 | maybe_expand_or_relocate_section (Elf_Internal_Shdr * section, | |
16560 | Filedata * filedata, | |
16561 | unsigned char ** start_ptr, | |
16562 | unsigned char ** decomp_buf, | |
16563 | bool relocate) | |
16564 | { | |
16565 | uint64_t section_size = section->sh_size; | |
16566 | unsigned char * start = * start_ptr; | |
16567 | ||
16568 | if (decompress_dumps) | |
16569 | { | |
16570 | uint64_t new_size = section_size; | |
16571 | uint64_t uncompressed_size = 0; | |
16572 | bool is_zstd = false; | |
16573 | ||
16574 | if ((section->sh_flags & SHF_COMPRESSED) != 0) | |
16575 | { | |
16576 | Elf_Internal_Chdr chdr; | |
16577 | unsigned int compression_header_size | |
16578 | = get_compression_header (& chdr, start, section_size); | |
16579 | ||
16580 | if (compression_header_size == 0) | |
16581 | /* An error message will have already been generated | |
16582 | by get_compression_header. */ | |
16583 | return (uint64_t) -1; | |
16584 | ||
16585 | if (chdr.ch_type == ch_compress_zlib) | |
16586 | ; | |
16587 | #ifdef HAVE_ZSTD | |
16588 | else if (chdr.ch_type == ch_compress_zstd) | |
16589 | is_zstd = true; | |
16590 | #endif | |
16591 | else | |
16592 | { | |
16593 | warn (_("section '%s' has unsupported compress type: %d\n"), | |
16594 | printable_section_name (filedata, section), chdr.ch_type); | |
16595 | return (uint64_t) -1; | |
16596 | } | |
16597 | ||
16598 | uncompressed_size = chdr.ch_size; | |
16599 | start += compression_header_size; | |
16600 | new_size -= compression_header_size; | |
16601 | } | |
16602 | else if (new_size > 12 && streq ((char *) start, "ZLIB")) | |
16603 | { | |
16604 | /* Read the zlib header. In this case, it should be "ZLIB" | |
16605 | followed by the uncompressed section size, 8 bytes in | |
16606 | big-endian order. */ | |
16607 | uncompressed_size = start[4]; uncompressed_size <<= 8; | |
16608 | uncompressed_size += start[5]; uncompressed_size <<= 8; | |
16609 | uncompressed_size += start[6]; uncompressed_size <<= 8; | |
16610 | uncompressed_size += start[7]; uncompressed_size <<= 8; | |
16611 | uncompressed_size += start[8]; uncompressed_size <<= 8; | |
16612 | uncompressed_size += start[9]; uncompressed_size <<= 8; | |
16613 | uncompressed_size += start[10]; uncompressed_size <<= 8; | |
16614 | uncompressed_size += start[11]; | |
16615 | start += 12; | |
16616 | new_size -= 12; | |
16617 | } | |
16618 | ||
16619 | if (uncompressed_size) | |
16620 | { | |
16621 | if (uncompress_section_contents (is_zstd, &start, uncompressed_size, | |
16622 | &new_size, filedata->file_size)) | |
16623 | { | |
16624 | *decomp_buf = start; | |
16625 | section_size = new_size; | |
16626 | } | |
16627 | else | |
16628 | { | |
16629 | error (_("Unable to decompress section %s\n"), | |
16630 | printable_section_name (filedata, section)); | |
16631 | return (uint64_t) -1; | |
16632 | } | |
16633 | } | |
16634 | else | |
16635 | start = * start_ptr; | |
16636 | } | |
16637 | else if (((section->sh_flags & SHF_COMPRESSED) != 0) | |
16638 | || (section_size > 12 && streq ((char *) start, "ZLIB"))) | |
16639 | { | |
16640 | printf (_(" NOTE: This section is compressed, but its contents have NOT been expanded for this dump.\n")); | |
16641 | } | |
16642 | ||
16643 | if (relocate) | |
16644 | { | |
16645 | if (! apply_relocations (filedata, section, start, section_size, NULL, NULL)) | |
16646 | return (uint64_t) -1; | |
16647 | } | |
16648 | else | |
16649 | { | |
16650 | Elf_Internal_Shdr *relsec; | |
16651 | ||
16652 | /* If the section being dumped has relocations against it the user might | |
16653 | be expecting these relocations to have been applied. Check for this | |
16654 | case and issue a warning message in order to avoid confusion. | |
16655 | FIXME: Maybe we ought to have an option that dumps a section with | |
16656 | relocs applied ? */ | |
16657 | for (relsec = filedata->section_headers; | |
16658 | relsec < filedata->section_headers + filedata->file_header.e_shnum; | |
16659 | ++relsec) | |
16660 | { | |
16661 | if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL) | |
16662 | || relsec->sh_info >= filedata->file_header.e_shnum | |
16663 | || filedata->section_headers + relsec->sh_info != section | |
16664 | || relsec->sh_size == 0 | |
16665 | || relsec->sh_link >= filedata->file_header.e_shnum) | |
16666 | continue; | |
16667 | ||
16668 | printf (_(" NOTE: This section has relocations against it, but these have NOT been applied to this dump.\n")); | |
16669 | break; | |
16670 | } | |
16671 | } | |
16672 | ||
16673 | * start_ptr = start; | |
16674 | return section_size; | |
16675 | } | |
16676 | ||
16677 | static bool | |
16678 | dump_section_as_strings (Elf_Internal_Shdr * section, Filedata * filedata) | |
16679 | { | |
16680 | uint64_t num_bytes; | |
16681 | unsigned char *data; | |
16682 | unsigned char *end; | |
16683 | unsigned char *real_start; | |
16684 | unsigned char *start; | |
16685 | unsigned char *decomp_buf; | |
16686 | bool some_strings_shown; | |
16687 | ||
16688 | real_start = start = (unsigned char *) get_section_contents (section, filedata); | |
16689 | if (start == NULL) | |
16690 | /* PR 21820: Do not fail if the section was empty. */ | |
16691 | return section->sh_size == 0 || section->sh_type == SHT_NOBITS; | |
16692 | ||
16693 | num_bytes = section->sh_size; | |
16694 | ||
16695 | if (filedata->is_separate) | |
16696 | printf (_("\nString dump of section '%s' in linked file %s:\n"), | |
16697 | printable_section_name (filedata, section), | |
16698 | filedata->file_name); | |
16699 | else | |
16700 | printf (_("\nString dump of section '%s':\n"), | |
16701 | printable_section_name (filedata, section)); | |
16702 | ||
16703 | decomp_buf = NULL; | |
16704 | num_bytes = maybe_expand_or_relocate_section (section, filedata, &start, | |
16705 | &decomp_buf, false); | |
16706 | if (num_bytes == (uint64_t) -1) | |
16707 | goto error_out; | |
16708 | ||
16709 | data = start; | |
16710 | end = start + num_bytes; | |
16711 | some_strings_shown = false; | |
16712 | ||
16713 | #ifdef HAVE_MBSTATE_T | |
16714 | mbstate_t state; | |
16715 | /* Initialise the multibyte conversion state. */ | |
16716 | memset (& state, 0, sizeof (state)); | |
16717 | #endif | |
16718 | ||
16719 | bool continuing = false; | |
16720 | ||
16721 | while (data < end) | |
16722 | { | |
16723 | while (!ISPRINT (* data)) | |
16724 | if (++ data >= end) | |
16725 | break; | |
16726 | ||
16727 | if (data < end) | |
16728 | { | |
16729 | size_t maxlen = end - data; | |
16730 | ||
16731 | if (continuing) | |
16732 | { | |
16733 | printf (" "); | |
16734 | continuing = false; | |
16735 | } | |
16736 | else | |
16737 | { | |
16738 | printf (" [%6tx] ", data - start); | |
16739 | } | |
16740 | ||
16741 | if (maxlen > 0) | |
16742 | { | |
16743 | char c = 0; | |
16744 | ||
16745 | while (maxlen) | |
16746 | { | |
16747 | c = *data++; | |
16748 | ||
16749 | if (c == 0) | |
16750 | break; | |
16751 | ||
16752 | /* PR 25543: Treat new-lines as string-ending characters. */ | |
16753 | if (c == '\n') | |
16754 | { | |
16755 | printf ("\\n\n"); | |
16756 | if (*data != 0) | |
16757 | continuing = true; | |
16758 | break; | |
16759 | } | |
16760 | ||
16761 | /* Do not print control characters directly as they can affect terminal | |
16762 | settings. Such characters usually appear in the names generated | |
16763 | by the assembler for local labels. */ | |
16764 | if (ISCNTRL (c)) | |
16765 | { | |
16766 | printf ("^%c", c + 0x40); | |
16767 | } | |
16768 | else if (ISPRINT (c)) | |
16769 | { | |
16770 | putchar (c); | |
16771 | } | |
16772 | else | |
16773 | { | |
16774 | size_t n; | |
16775 | #ifdef HAVE_MBSTATE_T | |
16776 | wchar_t w; | |
16777 | #endif | |
16778 | /* Let printf do the hard work of displaying multibyte characters. */ | |
16779 | printf ("%.1s", data - 1); | |
16780 | #ifdef HAVE_MBSTATE_T | |
16781 | /* Try to find out how many bytes made up the character that was | |
16782 | just printed. Advance the symbol pointer past the bytes that | |
16783 | were displayed. */ | |
16784 | n = mbrtowc (& w, (char *)(data - 1), MB_CUR_MAX, & state); | |
16785 | #else | |
16786 | n = 1; | |
16787 | #endif | |
16788 | if (n != (size_t) -1 && n != (size_t) -2 && n > 0) | |
16789 | data += (n - 1); | |
16790 | } | |
16791 | } | |
16792 | ||
16793 | if (c != '\n') | |
16794 | putchar ('\n'); | |
16795 | } | |
16796 | else | |
16797 | { | |
16798 | printf (_("<corrupt>\n")); | |
16799 | data = end; | |
16800 | } | |
16801 | some_strings_shown = true; | |
16802 | } | |
16803 | } | |
16804 | ||
16805 | if (! some_strings_shown) | |
16806 | printf (_(" No strings found in this section.")); | |
16807 | ||
16808 | free (decomp_buf); | |
16809 | free (real_start); | |
16810 | ||
16811 | putchar ('\n'); | |
16812 | return true; | |
16813 | ||
16814 | error_out: | |
16815 | free (decomp_buf); | |
16816 | free (real_start); | |
16817 | return false; | |
16818 | } | |
16819 | ||
16820 | static bool | |
16821 | dump_section_as_bytes (Elf_Internal_Shdr *section, | |
16822 | Filedata *filedata, | |
16823 | bool relocate) | |
16824 | { | |
16825 | size_t bytes; | |
16826 | uint64_t section_size; | |
16827 | uint64_t addr; | |
16828 | unsigned char *data; | |
16829 | unsigned char *real_start; | |
16830 | unsigned char *start; | |
16831 | unsigned char *decomp_buf; | |
16832 | ||
16833 | real_start = start = (unsigned char *) get_section_contents (section, filedata); | |
16834 | if (start == NULL) | |
16835 | /* PR 21820: Do not fail if the section was empty. */ | |
16836 | return section->sh_size == 0 || section->sh_type == SHT_NOBITS; | |
16837 | ||
16838 | section_size = section->sh_size; | |
16839 | ||
16840 | if (filedata->is_separate) | |
16841 | printf (_("\nHex dump of section '%s' in linked file %s:\n"), | |
16842 | printable_section_name (filedata, section), | |
16843 | filedata->file_name); | |
16844 | else | |
16845 | printf (_("\nHex dump of section '%s':\n"), | |
16846 | printable_section_name (filedata, section)); | |
16847 | ||
16848 | decomp_buf = NULL; | |
16849 | section_size = maybe_expand_or_relocate_section (section, filedata, &start, | |
16850 | &decomp_buf, relocate); | |
16851 | if (section_size == (uint64_t) -1) | |
16852 | goto error_out; | |
16853 | ||
16854 | addr = section->sh_addr; | |
16855 | bytes = section_size; | |
16856 | data = start; | |
16857 | ||
16858 | while (bytes) | |
16859 | { | |
16860 | int j; | |
16861 | int k; | |
16862 | int lbytes; | |
16863 | ||
16864 | lbytes = (bytes > 16 ? 16 : bytes); | |
16865 | ||
16866 | printf (" 0x%8.8" PRIx64 " ", addr); | |
16867 | ||
16868 | for (j = 0; j < 16; j++) | |
16869 | { | |
16870 | if (j < lbytes) | |
16871 | printf ("%2.2x", data[j]); | |
16872 | else | |
16873 | printf (" "); | |
16874 | ||
16875 | if ((j & 3) == 3) | |
16876 | printf (" "); | |
16877 | } | |
16878 | ||
16879 | for (j = 0; j < lbytes; j++) | |
16880 | { | |
16881 | k = data[j]; | |
16882 | if (k >= ' ' && k < 0x7f) | |
16883 | printf ("%c", k); | |
16884 | else | |
16885 | printf ("."); | |
16886 | } | |
16887 | ||
16888 | putchar ('\n'); | |
16889 | ||
16890 | data += lbytes; | |
16891 | addr += lbytes; | |
16892 | bytes -= lbytes; | |
16893 | } | |
16894 | ||
16895 | free (decomp_buf); | |
16896 | free (real_start); | |
16897 | ||
16898 | putchar ('\n'); | |
16899 | return true; | |
16900 | ||
16901 | error_out: | |
16902 | free (decomp_buf); | |
16903 | free (real_start); | |
16904 | return false; | |
16905 | } | |
16906 | ||
16907 | #ifdef ENABLE_LIBCTF | |
16908 | static ctf_sect_t * | |
16909 | shdr_to_ctf_sect (ctf_sect_t *buf, Elf_Internal_Shdr *shdr, Filedata *filedata) | |
16910 | { | |
16911 | buf->cts_name = printable_section_name (filedata, shdr); | |
16912 | buf->cts_size = shdr->sh_size; | |
16913 | buf->cts_entsize = shdr->sh_entsize; | |
16914 | ||
16915 | return buf; | |
16916 | } | |
16917 | ||
16918 | /* Formatting callback function passed to ctf_dump. Returns either the pointer | |
16919 | it is passed, or a pointer to newly-allocated storage, in which case | |
16920 | dump_ctf() will free it when it no longer needs it. */ | |
16921 | ||
16922 | static char * | |
16923 | dump_ctf_indent_lines (ctf_sect_names_t sect ATTRIBUTE_UNUSED, | |
16924 | char *s, void *arg) | |
16925 | { | |
16926 | const char *blanks = arg; | |
16927 | return xasprintf ("%s%s", blanks, s); | |
16928 | } | |
16929 | ||
16930 | /* Dump CTF errors/warnings. */ | |
16931 | static void | |
16932 | dump_ctf_errs (ctf_dict_t *fp) | |
16933 | { | |
16934 | ctf_next_t *it = NULL; | |
16935 | char *errtext; | |
16936 | int is_warning; | |
16937 | int err; | |
16938 | ||
16939 | /* Dump accumulated errors and warnings. */ | |
16940 | while ((errtext = ctf_errwarning_next (fp, &it, &is_warning, &err)) != NULL) | |
16941 | { | |
16942 | error (_("%s: %s"), is_warning ? _("warning"): _("error"), | |
16943 | errtext); | |
16944 | free (errtext); | |
16945 | } | |
16946 | if (err != ECTF_NEXT_END) | |
16947 | error (_("CTF error: cannot get CTF errors: `%s'"), ctf_errmsg (err)); | |
16948 | } | |
16949 | ||
16950 | /* Dump one CTF archive member. */ | |
16951 | ||
16952 | static void | |
16953 | dump_ctf_archive_member (ctf_dict_t *ctf, const char *name, ctf_dict_t *parent, | |
16954 | size_t member) | |
16955 | { | |
16956 | const char *things[] = {"Header", "Labels", "Data objects", | |
16957 | "Function objects", "Variables", "Types", "Strings", | |
16958 | ""}; | |
16959 | const char **thing; | |
16960 | size_t i; | |
16961 | ||
16962 | /* Don't print out the name of the default-named archive member if it appears | |
16963 | first in the list. The name .ctf appears everywhere, even for things that | |
16964 | aren't really archives, so printing it out is liable to be confusing; also, | |
16965 | the common case by far is for only one archive member to exist, and hiding | |
16966 | it in that case seems worthwhile. */ | |
16967 | ||
16968 | if (strcmp (name, ".ctf") != 0 || member != 0) | |
16969 | printf (_("\nCTF archive member: %s:\n"), name); | |
16970 | ||
16971 | if (ctf_parent_name (ctf) != NULL) | |
16972 | ctf_import (ctf, parent); | |
16973 | ||
16974 | for (i = 0, thing = things; *thing[0]; thing++, i++) | |
16975 | { | |
16976 | ctf_dump_state_t *s = NULL; | |
16977 | char *item; | |
16978 | ||
16979 | printf ("\n %s:\n", *thing); | |
16980 | while ((item = ctf_dump (ctf, &s, i, dump_ctf_indent_lines, | |
16981 | (void *) " ")) != NULL) | |
16982 | { | |
16983 | printf ("%s\n", item); | |
16984 | free (item); | |
16985 | } | |
16986 | ||
16987 | if (ctf_errno (ctf)) | |
16988 | { | |
16989 | error (_("Iteration failed: %s, %s\n"), *thing, | |
16990 | ctf_errmsg (ctf_errno (ctf))); | |
16991 | break; | |
16992 | } | |
16993 | } | |
16994 | ||
16995 | dump_ctf_errs (ctf); | |
16996 | } | |
16997 | ||
16998 | static bool | |
16999 | dump_section_as_ctf (Elf_Internal_Shdr * section, Filedata * filedata) | |
17000 | { | |
17001 | Elf_Internal_Shdr * symtab_sec = NULL; | |
17002 | Elf_Internal_Shdr * strtab_sec = NULL; | |
17003 | void * data = NULL; | |
17004 | void * symdata = NULL; | |
17005 | void * strdata = NULL; | |
17006 | ctf_sect_t ctfsect, symsect, strsect; | |
17007 | ctf_sect_t * symsectp = NULL; | |
17008 | ctf_sect_t * strsectp = NULL; | |
17009 | ctf_archive_t * ctfa = NULL; | |
17010 | ctf_dict_t * parent = NULL; | |
17011 | ctf_dict_t * fp; | |
17012 | ||
17013 | ctf_next_t *i = NULL; | |
17014 | const char *name; | |
17015 | size_t member = 0; | |
17016 | int err; | |
17017 | bool ret = false; | |
17018 | ||
17019 | shdr_to_ctf_sect (&ctfsect, section, filedata); | |
17020 | data = get_section_contents (section, filedata); | |
17021 | ctfsect.cts_data = data; | |
17022 | ||
17023 | if (!dump_ctf_symtab_name) | |
17024 | dump_ctf_symtab_name = strdup (".dynsym"); | |
17025 | ||
17026 | if (!dump_ctf_strtab_name) | |
17027 | dump_ctf_strtab_name = strdup (".dynstr"); | |
17028 | ||
17029 | if (dump_ctf_symtab_name && dump_ctf_symtab_name[0] != 0) | |
17030 | { | |
17031 | if ((symtab_sec = find_section (filedata, dump_ctf_symtab_name)) == NULL) | |
17032 | { | |
17033 | error (_("No symbol section named %s\n"), dump_ctf_symtab_name); | |
17034 | goto fail; | |
17035 | } | |
17036 | if ((symdata = (void *) get_data (NULL, filedata, | |
17037 | symtab_sec->sh_offset, 1, | |
17038 | symtab_sec->sh_size, | |
17039 | _("symbols"))) == NULL) | |
17040 | goto fail; | |
17041 | symsectp = shdr_to_ctf_sect (&symsect, symtab_sec, filedata); | |
17042 | symsect.cts_data = symdata; | |
17043 | } | |
17044 | ||
17045 | if (dump_ctf_strtab_name && dump_ctf_strtab_name[0] != 0) | |
17046 | { | |
17047 | if ((strtab_sec = find_section (filedata, dump_ctf_strtab_name)) == NULL) | |
17048 | { | |
17049 | error (_("No string table section named %s\n"), | |
17050 | dump_ctf_strtab_name); | |
17051 | goto fail; | |
17052 | } | |
17053 | if ((strdata = (void *) get_data (NULL, filedata, | |
17054 | strtab_sec->sh_offset, 1, | |
17055 | strtab_sec->sh_size, | |
17056 | _("strings"))) == NULL) | |
17057 | goto fail; | |
17058 | strsectp = shdr_to_ctf_sect (&strsect, strtab_sec, filedata); | |
17059 | strsect.cts_data = strdata; | |
17060 | } | |
17061 | ||
17062 | /* Load the CTF file and dump it. It may be a raw CTF section, or an archive: | |
17063 | libctf papers over the difference, so we can pretend it is always an | |
17064 | archive. */ | |
17065 | ||
17066 | if ((ctfa = ctf_arc_bufopen (&ctfsect, symsectp, strsectp, &err)) == NULL) | |
17067 | { | |
17068 | dump_ctf_errs (NULL); | |
17069 | error (_("CTF open failure: %s\n"), ctf_errmsg (err)); | |
17070 | goto fail; | |
17071 | } | |
17072 | ||
17073 | ctf_arc_symsect_endianness (ctfa, filedata->file_header.e_ident[EI_DATA] | |
17074 | != ELFDATA2MSB); | |
17075 | ||
17076 | /* Preload the parent dict, since it will need to be imported into every | |
17077 | child in turn. */ | |
17078 | if ((parent = ctf_dict_open (ctfa, dump_ctf_parent_name, &err)) == NULL) | |
17079 | { | |
17080 | dump_ctf_errs (NULL); | |
17081 | error (_("CTF open failure: %s\n"), ctf_errmsg (err)); | |
17082 | goto fail; | |
17083 | } | |
17084 | ||
17085 | ret = true; | |
17086 | ||
17087 | if (filedata->is_separate) | |
17088 | printf (_("\nDump of CTF section '%s' in linked file %s:\n"), | |
17089 | printable_section_name (filedata, section), | |
17090 | filedata->file_name); | |
17091 | else | |
17092 | printf (_("\nDump of CTF section '%s':\n"), | |
17093 | printable_section_name (filedata, section)); | |
17094 | ||
17095 | while ((fp = ctf_archive_next (ctfa, &i, &name, 0, &err)) != NULL) | |
17096 | { | |
17097 | dump_ctf_archive_member (fp, name, parent, member++); | |
17098 | ctf_dict_close (fp); | |
17099 | } | |
17100 | if (err != ECTF_NEXT_END) | |
17101 | { | |
17102 | dump_ctf_errs (NULL); | |
17103 | error (_("CTF member open failure: %s\n"), ctf_errmsg (err)); | |
17104 | ret = false; | |
17105 | } | |
17106 | ||
17107 | fail: | |
17108 | ctf_dict_close (parent); | |
17109 | ctf_close (ctfa); | |
17110 | free (data); | |
17111 | free (symdata); | |
17112 | free (strdata); | |
17113 | return ret; | |
17114 | } | |
17115 | #endif | |
17116 | ||
17117 | static bool | |
17118 | load_specific_debug_section (enum dwarf_section_display_enum debug, | |
17119 | const Elf_Internal_Shdr * sec, | |
17120 | void * data) | |
17121 | { | |
17122 | struct dwarf_section * section = &debug_displays [debug].section; | |
17123 | char buf [64]; | |
17124 | Filedata * filedata = (Filedata *) data; | |
17125 | ||
17126 | if (section->start != NULL) | |
17127 | { | |
17128 | /* If it is already loaded, do nothing. */ | |
17129 | if (streq (section->filename, filedata->file_name)) | |
17130 | return true; | |
17131 | free (section->start); | |
17132 | } | |
17133 | ||
17134 | snprintf (buf, sizeof (buf), _("%s section data"), section->name); | |
17135 | section->address = sec->sh_addr; | |
17136 | section->filename = filedata->file_name; | |
17137 | section->start = (unsigned char *) get_data (NULL, filedata, | |
17138 | sec->sh_offset, 1, | |
17139 | sec->sh_size, buf); | |
17140 | if (section->start == NULL) | |
17141 | section->size = 0; | |
17142 | else | |
17143 | { | |
17144 | unsigned char *start = section->start; | |
17145 | uint64_t size = sec->sh_size; | |
17146 | uint64_t uncompressed_size = 0; | |
17147 | bool is_zstd = false; | |
17148 | ||
17149 | if ((sec->sh_flags & SHF_COMPRESSED) != 0) | |
17150 | { | |
17151 | Elf_Internal_Chdr chdr; | |
17152 | unsigned int compression_header_size; | |
17153 | ||
17154 | if (size < (is_32bit_elf | |
17155 | ? sizeof (Elf32_External_Chdr) | |
17156 | : sizeof (Elf64_External_Chdr))) | |
17157 | { | |
17158 | warn (_("compressed section %s is too small to contain a compression header\n"), | |
17159 | section->name); | |
17160 | return false; | |
17161 | } | |
17162 | ||
17163 | compression_header_size = get_compression_header (&chdr, start, size); | |
17164 | if (compression_header_size == 0) | |
17165 | /* An error message will have already been generated | |
17166 | by get_compression_header. */ | |
17167 | return false; | |
17168 | ||
17169 | if (chdr.ch_type == ch_compress_zlib) | |
17170 | ; | |
17171 | #ifdef HAVE_ZSTD | |
17172 | else if (chdr.ch_type == ch_compress_zstd) | |
17173 | is_zstd = true; | |
17174 | #endif | |
17175 | else | |
17176 | { | |
17177 | warn (_("section '%s' has unsupported compress type: %d\n"), | |
17178 | section->name, chdr.ch_type); | |
17179 | return false; | |
17180 | } | |
17181 | uncompressed_size = chdr.ch_size; | |
17182 | start += compression_header_size; | |
17183 | size -= compression_header_size; | |
17184 | } | |
17185 | else if (size > 12 && streq ((char *) start, "ZLIB")) | |
17186 | { | |
17187 | /* Read the zlib header. In this case, it should be "ZLIB" | |
17188 | followed by the uncompressed section size, 8 bytes in | |
17189 | big-endian order. */ | |
17190 | uncompressed_size = start[4]; uncompressed_size <<= 8; | |
17191 | uncompressed_size += start[5]; uncompressed_size <<= 8; | |
17192 | uncompressed_size += start[6]; uncompressed_size <<= 8; | |
17193 | uncompressed_size += start[7]; uncompressed_size <<= 8; | |
17194 | uncompressed_size += start[8]; uncompressed_size <<= 8; | |
17195 | uncompressed_size += start[9]; uncompressed_size <<= 8; | |
17196 | uncompressed_size += start[10]; uncompressed_size <<= 8; | |
17197 | uncompressed_size += start[11]; | |
17198 | start += 12; | |
17199 | size -= 12; | |
17200 | } | |
17201 | ||
17202 | if (uncompressed_size) | |
17203 | { | |
17204 | if (uncompress_section_contents (is_zstd, &start, uncompressed_size, | |
17205 | &size, filedata->file_size)) | |
17206 | { | |
17207 | /* Free the compressed buffer, update the section buffer | |
17208 | and the section size if uncompress is successful. */ | |
17209 | free (section->start); | |
17210 | section->start = start; | |
17211 | } | |
17212 | else | |
17213 | { | |
17214 | error (_("Unable to decompress section %s\n"), | |
17215 | printable_section_name (filedata, sec)); | |
17216 | return false; | |
17217 | } | |
17218 | } | |
17219 | ||
17220 | section->size = size; | |
17221 | } | |
17222 | ||
17223 | if (section->start == NULL) | |
17224 | return false; | |
17225 | ||
17226 | if (debug_displays [debug].relocate) | |
17227 | { | |
17228 | if (! apply_relocations (filedata, sec, section->start, section->size, | |
17229 | & section->reloc_info, & section->num_relocs)) | |
17230 | return false; | |
17231 | } | |
17232 | else | |
17233 | { | |
17234 | section->reloc_info = NULL; | |
17235 | section->num_relocs = 0; | |
17236 | } | |
17237 | ||
17238 | return true; | |
17239 | } | |
17240 | ||
17241 | #if HAVE_LIBDEBUGINFOD | |
17242 | /* Return a hex string representation of the build-id. */ | |
17243 | unsigned char * | |
17244 | get_build_id (void * data) | |
17245 | { | |
17246 | Filedata * filedata = (Filedata *) data; | |
17247 | Elf_Internal_Shdr * shdr; | |
17248 | size_t i; | |
17249 | ||
17250 | /* Iterate through notes to find note.gnu.build-id. | |
17251 | FIXME: Only the first note in any note section is examined. */ | |
17252 | for (i = 0, shdr = filedata->section_headers; | |
17253 | i < filedata->file_header.e_shnum && shdr != NULL; | |
17254 | i++, shdr++) | |
17255 | { | |
17256 | if (shdr->sh_type != SHT_NOTE) | |
17257 | continue; | |
17258 | ||
17259 | char * next; | |
17260 | char * end; | |
17261 | size_t data_remaining; | |
17262 | size_t min_notesz; | |
17263 | Elf_External_Note * enote; | |
17264 | Elf_Internal_Note inote; | |
17265 | ||
17266 | uint64_t offset = shdr->sh_offset; | |
17267 | uint64_t align = shdr->sh_addralign; | |
17268 | uint64_t length = shdr->sh_size; | |
17269 | ||
17270 | enote = (Elf_External_Note *) get_section_contents (shdr, filedata); | |
17271 | if (enote == NULL) | |
17272 | continue; | |
17273 | ||
17274 | if (align < 4) | |
17275 | align = 4; | |
17276 | else if (align != 4 && align != 8) | |
17277 | { | |
17278 | free (enote); | |
17279 | continue; | |
17280 | } | |
17281 | ||
17282 | end = (char *) enote + length; | |
17283 | data_remaining = end - (char *) enote; | |
17284 | ||
17285 | if (!is_ia64_vms (filedata)) | |
17286 | { | |
17287 | min_notesz = offsetof (Elf_External_Note, name); | |
17288 | if (data_remaining < min_notesz) | |
17289 | { | |
17290 | warn (_("\ | |
17291 | malformed note encountered in section %s whilst scanning for build-id note\n"), | |
17292 | printable_section_name (filedata, shdr)); | |
17293 | free (enote); | |
17294 | continue; | |
17295 | } | |
17296 | data_remaining -= min_notesz; | |
17297 | ||
17298 | inote.type = BYTE_GET (enote->type); | |
17299 | inote.namesz = BYTE_GET (enote->namesz); | |
17300 | inote.namedata = enote->name; | |
17301 | inote.descsz = BYTE_GET (enote->descsz); | |
17302 | inote.descdata = ((char *) enote | |
17303 | + ELF_NOTE_DESC_OFFSET (inote.namesz, align)); | |
17304 | inote.descpos = offset + (inote.descdata - (char *) enote); | |
17305 | next = ((char *) enote | |
17306 | + ELF_NOTE_NEXT_OFFSET (inote.namesz, inote.descsz, align)); | |
17307 | } | |
17308 | else | |
17309 | { | |
17310 | Elf64_External_VMS_Note *vms_enote; | |
17311 | ||
17312 | /* PR binutils/15191 | |
17313 | Make sure that there is enough data to read. */ | |
17314 | min_notesz = offsetof (Elf64_External_VMS_Note, name); | |
17315 | if (data_remaining < min_notesz) | |
17316 | { | |
17317 | warn (_("\ | |
17318 | malformed note encountered in section %s whilst scanning for build-id note\n"), | |
17319 | printable_section_name (filedata, shdr)); | |
17320 | free (enote); | |
17321 | continue; | |
17322 | } | |
17323 | data_remaining -= min_notesz; | |
17324 | ||
17325 | vms_enote = (Elf64_External_VMS_Note *) enote; | |
17326 | inote.type = BYTE_GET (vms_enote->type); | |
17327 | inote.namesz = BYTE_GET (vms_enote->namesz); | |
17328 | inote.namedata = vms_enote->name; | |
17329 | inote.descsz = BYTE_GET (vms_enote->descsz); | |
17330 | inote.descdata = inote.namedata + align_power (inote.namesz, 3); | |
17331 | inote.descpos = offset + (inote.descdata - (char *) enote); | |
17332 | next = inote.descdata + align_power (inote.descsz, 3); | |
17333 | } | |
17334 | ||
17335 | /* Skip malformed notes. */ | |
17336 | if ((size_t) (inote.descdata - inote.namedata) < inote.namesz | |
17337 | || (size_t) (inote.descdata - inote.namedata) > data_remaining | |
17338 | || (size_t) (next - inote.descdata) < inote.descsz | |
17339 | || ((size_t) (next - inote.descdata) | |
17340 | > data_remaining - (size_t) (inote.descdata - inote.namedata))) | |
17341 | { | |
17342 | warn (_("\ | |
17343 | malformed note encountered in section %s whilst scanning for build-id note\n"), | |
17344 | printable_section_name (filedata, shdr)); | |
17345 | free (enote); | |
17346 | continue; | |
17347 | } | |
17348 | ||
17349 | /* Check if this is the build-id note. If so then convert the build-id | |
17350 | bytes to a hex string. */ | |
17351 | if (inote.namesz > 0 | |
17352 | && startswith (inote.namedata, "GNU") | |
17353 | && inote.type == NT_GNU_BUILD_ID) | |
17354 | { | |
17355 | size_t j; | |
17356 | char * build_id; | |
17357 | ||
17358 | build_id = malloc (inote.descsz * 2 + 1); | |
17359 | if (build_id == NULL) | |
17360 | { | |
17361 | free (enote); | |
17362 | return NULL; | |
17363 | } | |
17364 | ||
17365 | for (j = 0; j < inote.descsz; ++j) | |
17366 | sprintf (build_id + (j * 2), "%02x", inote.descdata[j] & 0xff); | |
17367 | build_id[inote.descsz * 2] = '\0'; | |
17368 | free (enote); | |
17369 | ||
17370 | return (unsigned char *) build_id; | |
17371 | } | |
17372 | free (enote); | |
17373 | } | |
17374 | ||
17375 | return NULL; | |
17376 | } | |
17377 | #endif /* HAVE_LIBDEBUGINFOD */ | |
17378 | ||
17379 | /* If this is not NULL, load_debug_section will only look for sections | |
17380 | within the list of sections given here. */ | |
17381 | static unsigned int * section_subset = NULL; | |
17382 | ||
17383 | bool | |
17384 | load_debug_section (enum dwarf_section_display_enum debug, void * data) | |
17385 | { | |
17386 | struct dwarf_section * section = &debug_displays [debug].section; | |
17387 | Elf_Internal_Shdr * sec; | |
17388 | Filedata * filedata = (Filedata *) data; | |
17389 | ||
17390 | if (!dump_any_debugging) | |
17391 | return false; | |
17392 | ||
17393 | /* Without section headers we cannot find any sections. */ | |
17394 | if (filedata->section_headers == NULL) | |
17395 | return false; | |
17396 | ||
17397 | if (filedata->string_table == NULL | |
17398 | && filedata->file_header.e_shstrndx != SHN_UNDEF | |
17399 | && filedata->file_header.e_shstrndx < filedata->file_header.e_shnum) | |
17400 | { | |
17401 | Elf_Internal_Shdr * strs; | |
17402 | ||
17403 | /* Read in the string table, so that we have section names to scan. */ | |
17404 | strs = filedata->section_headers + filedata->file_header.e_shstrndx; | |
17405 | ||
17406 | if (strs != NULL && strs->sh_size != 0) | |
17407 | { | |
17408 | filedata->string_table | |
17409 | = (char *) get_data (NULL, filedata, strs->sh_offset, | |
17410 | 1, strs->sh_size, _("string table")); | |
17411 | ||
17412 | filedata->string_table_length | |
17413 | = filedata->string_table != NULL ? strs->sh_size : 0; | |
17414 | } | |
17415 | } | |
17416 | ||
17417 | /* Locate the debug section. */ | |
17418 | sec = find_section_in_set (filedata, section->uncompressed_name, section_subset); | |
17419 | if (sec != NULL) | |
17420 | section->name = section->uncompressed_name; | |
17421 | else | |
17422 | { | |
17423 | sec = find_section_in_set (filedata, section->compressed_name, section_subset); | |
17424 | if (sec != NULL) | |
17425 | section->name = section->compressed_name; | |
17426 | } | |
17427 | if (sec == NULL) | |
17428 | return false; | |
17429 | ||
17430 | /* If we're loading from a subset of sections, and we've loaded | |
17431 | a section matching this name before, it's likely that it's a | |
17432 | different one. */ | |
17433 | if (section_subset != NULL) | |
17434 | free_debug_section (debug); | |
17435 | ||
17436 | return load_specific_debug_section (debug, sec, data); | |
17437 | } | |
17438 | ||
17439 | void | |
17440 | free_debug_section (enum dwarf_section_display_enum debug) | |
17441 | { | |
17442 | struct dwarf_section * section = &debug_displays [debug].section; | |
17443 | ||
17444 | if (section->start == NULL) | |
17445 | return; | |
17446 | ||
17447 | free ((char *) section->start); | |
17448 | section->start = NULL; | |
17449 | section->address = 0; | |
17450 | section->size = 0; | |
17451 | ||
17452 | free (section->reloc_info); | |
17453 | section->reloc_info = NULL; | |
17454 | section->num_relocs = 0; | |
17455 | } | |
17456 | ||
17457 | static bool | |
17458 | display_debug_section (int shndx, Elf_Internal_Shdr * section, Filedata * filedata) | |
17459 | { | |
17460 | const char *name = (section_name_valid (filedata, section) | |
17461 | ? section_name (filedata, section) : ""); | |
17462 | const char *print_name = printable_section_name (filedata, section); | |
17463 | uint64_t length; | |
17464 | bool result = true; | |
17465 | int i; | |
17466 | ||
17467 | length = section->sh_size; | |
17468 | if (length == 0) | |
17469 | { | |
17470 | printf (_("\nSection '%s' has no debugging data.\n"), print_name); | |
17471 | return true; | |
17472 | } | |
17473 | if (section->sh_type == SHT_NOBITS) | |
17474 | { | |
17475 | /* There is no point in dumping the contents of a debugging section | |
17476 | which has the NOBITS type - the bits in the file will be random. | |
17477 | This can happen when a file containing a .eh_frame section is | |
17478 | stripped with the --only-keep-debug command line option. */ | |
17479 | printf (_("section '%s' has the NOBITS type - its contents are unreliable.\n"), | |
17480 | print_name); | |
17481 | return false; | |
17482 | } | |
17483 | ||
17484 | if (startswith (name, ".gnu.linkonce.wi.")) | |
17485 | name = ".debug_info"; | |
17486 | ||
17487 | /* See if we know how to display the contents of this section. */ | |
17488 | for (i = 0; i < max; i++) | |
17489 | { | |
17490 | enum dwarf_section_display_enum id = (enum dwarf_section_display_enum) i; | |
17491 | struct dwarf_section_display * display = debug_displays + i; | |
17492 | struct dwarf_section * sec = & display->section; | |
17493 | ||
17494 | if (streq (sec->uncompressed_name, name) | |
17495 | || (id == line && startswith (name, ".debug_line.")) | |
17496 | || streq (sec->compressed_name, name)) | |
17497 | { | |
17498 | bool secondary = (section != find_section (filedata, name)); | |
17499 | ||
17500 | if (secondary) | |
17501 | free_debug_section (id); | |
17502 | ||
17503 | if (i == line && startswith (name, ".debug_line.")) | |
17504 | sec->name = name; | |
17505 | else if (streq (sec->uncompressed_name, name)) | |
17506 | sec->name = sec->uncompressed_name; | |
17507 | else | |
17508 | sec->name = sec->compressed_name; | |
17509 | ||
17510 | if (load_specific_debug_section (id, section, filedata)) | |
17511 | { | |
17512 | /* If this debug section is part of a CU/TU set in a .dwp file, | |
17513 | restrict load_debug_section to the sections in that set. */ | |
17514 | section_subset = find_cu_tu_set (filedata, shndx); | |
17515 | ||
17516 | result &= display->display (sec, filedata); | |
17517 | ||
17518 | section_subset = NULL; | |
17519 | ||
17520 | if (secondary || (id != info && id != abbrev && id != debug_addr)) | |
17521 | free_debug_section (id); | |
17522 | } | |
17523 | break; | |
17524 | } | |
17525 | } | |
17526 | ||
17527 | if (i == max) | |
17528 | { | |
17529 | printf (_("Unrecognized debug section: %s\n"), print_name); | |
17530 | result = false; | |
17531 | } | |
17532 | ||
17533 | return result; | |
17534 | } | |
17535 | ||
17536 | /* Set DUMP_SECTS for all sections where dumps were requested | |
17537 | based on section name. */ | |
17538 | ||
17539 | static void | |
17540 | initialise_dumps_byname (Filedata * filedata) | |
17541 | { | |
17542 | struct dump_list_entry * cur; | |
17543 | ||
17544 | for (cur = dump_sects_byname; cur; cur = cur->next) | |
17545 | { | |
17546 | unsigned int i; | |
17547 | bool any = false; | |
17548 | ||
17549 | for (i = 0; i < filedata->file_header.e_shnum; i++) | |
17550 | if (section_name_valid (filedata, filedata->section_headers + i) | |
17551 | && streq (section_name (filedata, filedata->section_headers + i), | |
17552 | cur->name)) | |
17553 | { | |
17554 | request_dump_bynumber (&filedata->dump, i, cur->type); | |
17555 | any = true; | |
17556 | } | |
17557 | ||
17558 | if (!any && !filedata->is_separate) | |
17559 | warn (_("Section '%s' was not dumped because it does not exist\n"), | |
17560 | cur->name); | |
17561 | } | |
17562 | } | |
17563 | ||
17564 | static bool | |
17565 | process_section_contents (Filedata * filedata) | |
17566 | { | |
17567 | Elf_Internal_Shdr * section; | |
17568 | unsigned int i; | |
17569 | bool res = true; | |
17570 | ||
17571 | if (! do_dump) | |
17572 | return true; | |
17573 | ||
17574 | initialise_dumps_byname (filedata); | |
17575 | ||
17576 | for (i = 0, section = filedata->section_headers; | |
17577 | i < filedata->file_header.e_shnum && i < filedata->dump.num_dump_sects; | |
17578 | i++, section++) | |
17579 | { | |
17580 | dump_type dump = filedata->dump.dump_sects[i]; | |
17581 | ||
17582 | if (filedata->is_separate && ! process_links) | |
17583 | dump &= DEBUG_DUMP; | |
17584 | ||
17585 | if (dump & AUTO_DUMP) | |
17586 | { | |
17587 | switch (section->sh_type) | |
17588 | { | |
17589 | case SHT_PROGBITS: | |
17590 | /* FIXME: There are lots of different type of section that have | |
17591 | SHT_PROGBITS set in their header - code, debug info, etc. So | |
17592 | we should check the section's name and interpret its contents | |
17593 | that way, rather than just defaulting to a byte dump. */ | |
17594 | #ifdef SUPPORT_DISASSEMBLY | |
17595 | res &= disassemble_section (section, filedata); | |
17596 | #else | |
17597 | res &= dump_section_as_bytes (section, filedata, false); | |
17598 | #endif | |
17599 | break; | |
17600 | ||
17601 | case SHT_DYNSYM: | |
17602 | case SHT_SYMTAB: | |
17603 | res &= dump_symbol_section (section, filedata); | |
17604 | break; | |
17605 | ||
17606 | case SHT_STRTAB: | |
17607 | res &= dump_section_as_strings (section, filedata); | |
17608 | break; | |
17609 | ||
17610 | case SHT_RELA: | |
17611 | case SHT_REL: | |
17612 | case SHT_RELR: | |
17613 | res &= display_relocations (section, filedata); | |
17614 | break; | |
17615 | ||
17616 | case SHT_NOTE: | |
17617 | res &= process_notes_at (filedata, section, section->sh_offset, | |
17618 | section->sh_size, section->sh_addralign); | |
17619 | break; | |
17620 | ||
17621 | case SHT_NULL: | |
17622 | inform (_("Unable to display section %d - it has a NULL type\n"), i); | |
17623 | break; | |
17624 | ||
17625 | case SHT_NOBITS: | |
17626 | inform (_("Unable to display section %d - it has no contents\n"), i); | |
17627 | break; | |
17628 | ||
17629 | case SHT_HASH: | |
17630 | case SHT_DYNAMIC: | |
17631 | case SHT_GROUP: | |
17632 | case SHT_GNU_ATTRIBUTES: | |
17633 | /* FIXME: Implement these. */ | |
17634 | /* Fall through. */ | |
17635 | default: | |
17636 | /* FIXME: Add Proc and OS specific section types ? */ | |
17637 | warn (_("Unable to determine how to dump section %d (type %#x)\n"), | |
17638 | i, section->sh_type); | |
17639 | res = false; | |
17640 | break; | |
17641 | } | |
17642 | } | |
17643 | ||
17644 | #ifdef SUPPORT_DISASSEMBLY | |
17645 | if (dump & DISASS_DUMP) | |
17646 | { | |
17647 | if (! disassemble_section (section, filedata)) | |
17648 | res = false; | |
17649 | } | |
17650 | #endif | |
17651 | if (dump & HEX_DUMP) | |
17652 | { | |
17653 | if (! dump_section_as_bytes (section, filedata, false)) | |
17654 | res = false; | |
17655 | } | |
17656 | ||
17657 | if (dump & RELOC_DUMP) | |
17658 | { | |
17659 | if (! dump_section_as_bytes (section, filedata, true)) | |
17660 | res = false; | |
17661 | } | |
17662 | ||
17663 | if (dump & STRING_DUMP) | |
17664 | { | |
17665 | if (! dump_section_as_strings (section, filedata)) | |
17666 | res = false; | |
17667 | } | |
17668 | ||
17669 | if (dump & DEBUG_DUMP) | |
17670 | { | |
17671 | if (! display_debug_section (i, section, filedata)) | |
17672 | res = false; | |
17673 | } | |
17674 | ||
17675 | #ifdef ENABLE_LIBCTF | |
17676 | if (dump & CTF_DUMP) | |
17677 | { | |
17678 | if (! dump_section_as_ctf (section, filedata)) | |
17679 | res = false; | |
17680 | } | |
17681 | #endif | |
17682 | if (dump & SFRAME_DUMP) | |
17683 | { | |
17684 | if (! display_debug_section (i, section, filedata)) | |
17685 | res = false; | |
17686 | } | |
17687 | } | |
17688 | ||
17689 | if (! filedata->is_separate) | |
17690 | { | |
17691 | /* Check to see if the user requested a | |
17692 | dump of a section that does not exist. */ | |
17693 | for (; i < filedata->dump.num_dump_sects; i++) | |
17694 | if (filedata->dump.dump_sects[i]) | |
17695 | { | |
17696 | warn (_("Section %d was not dumped because it does not exist!\n"), i); | |
17697 | res = false; | |
17698 | } | |
17699 | } | |
17700 | ||
17701 | return res; | |
17702 | } | |
17703 | ||
17704 | static void | |
17705 | process_mips_fpe_exception (int mask) | |
17706 | { | |
17707 | if (mask) | |
17708 | { | |
17709 | bool first = true; | |
17710 | ||
17711 | if (mask & OEX_FPU_INEX) | |
17712 | fputs ("INEX", stdout), first = false; | |
17713 | if (mask & OEX_FPU_UFLO) | |
17714 | printf ("%sUFLO", first ? "" : "|"), first = false; | |
17715 | if (mask & OEX_FPU_OFLO) | |
17716 | printf ("%sOFLO", first ? "" : "|"), first = false; | |
17717 | if (mask & OEX_FPU_DIV0) | |
17718 | printf ("%sDIV0", first ? "" : "|"), first = false; | |
17719 | if (mask & OEX_FPU_INVAL) | |
17720 | printf ("%sINVAL", first ? "" : "|"); | |
17721 | } | |
17722 | else | |
17723 | fputs ("0", stdout); | |
17724 | } | |
17725 | ||
17726 | /* Display's the value of TAG at location P. If TAG is | |
17727 | greater than 0 it is assumed to be an unknown tag, and | |
17728 | a message is printed to this effect. Otherwise it is | |
17729 | assumed that a message has already been printed. | |
17730 | ||
17731 | If the bottom bit of TAG is set it assumed to have a | |
17732 | string value, otherwise it is assumed to have an integer | |
17733 | value. | |
17734 | ||
17735 | Returns an updated P pointing to the first unread byte | |
17736 | beyond the end of TAG's value. | |
17737 | ||
17738 | Reads at or beyond END will not be made. */ | |
17739 | ||
17740 | static unsigned char * | |
17741 | display_tag_value (signed int tag, | |
17742 | unsigned char * p, | |
17743 | const unsigned char * const end) | |
17744 | { | |
17745 | uint64_t val; | |
17746 | ||
17747 | if (tag > 0) | |
17748 | printf (" Tag_unknown_%d: ", tag); | |
17749 | ||
17750 | if (p >= end) | |
17751 | { | |
17752 | warn (_("<corrupt tag>\n")); | |
17753 | } | |
17754 | else if (tag & 1) | |
17755 | { | |
17756 | /* PR 17531 file: 027-19978-0.004. */ | |
17757 | size_t maxlen = end - p; | |
17758 | ||
17759 | putchar ('"'); | |
17760 | if (maxlen > 0) | |
17761 | { | |
17762 | maxlen -= 1; /* Remove \0 from the character count. */ | |
17763 | print_symbol_name ((int) maxlen, (const char *) p); | |
17764 | size_t len = strnlen ((char *) p, maxlen); | |
17765 | if (len == maxlen && p[maxlen] != '\0') | |
17766 | printf (_("<corrupt string tag>")); | |
17767 | p += len + 1; | |
17768 | } | |
17769 | else | |
17770 | { | |
17771 | printf (_("<corrupt string tag>")); | |
17772 | p = (unsigned char *) end; | |
17773 | } | |
17774 | printf ("\"\n"); | |
17775 | } | |
17776 | else | |
17777 | { | |
17778 | READ_ULEB (val, p, end); | |
17779 | printf ("%" PRId64 " (0x%" PRIx64 ")\n", val, val); | |
17780 | } | |
17781 | ||
17782 | assert (p <= end); | |
17783 | return p; | |
17784 | } | |
17785 | ||
17786 | /* ARC ABI attributes section. */ | |
17787 | ||
17788 | static unsigned char * | |
17789 | display_arc_attribute (unsigned char * p, | |
17790 | const unsigned char * const end) | |
17791 | { | |
17792 | unsigned int tag; | |
17793 | unsigned int val; | |
17794 | ||
17795 | READ_ULEB (tag, p, end); | |
17796 | ||
17797 | switch (tag) | |
17798 | { | |
17799 | case Tag_ARC_PCS_config: | |
17800 | READ_ULEB (val, p, end); | |
17801 | printf (" Tag_ARC_PCS_config: "); | |
17802 | switch (val) | |
17803 | { | |
17804 | case 0: | |
17805 | printf (_("Absent/Non standard\n")); | |
17806 | break; | |
17807 | case 1: | |
17808 | printf (_("Bare metal/mwdt\n")); | |
17809 | break; | |
17810 | case 2: | |
17811 | printf (_("Bare metal/newlib\n")); | |
17812 | break; | |
17813 | case 3: | |
17814 | printf (_("Linux/uclibc\n")); | |
17815 | break; | |
17816 | case 4: | |
17817 | printf (_("Linux/glibc\n")); | |
17818 | break; | |
17819 | default: | |
17820 | printf (_("Unknown\n")); | |
17821 | break; | |
17822 | } | |
17823 | break; | |
17824 | ||
17825 | case Tag_ARC_CPU_base: | |
17826 | READ_ULEB (val, p, end); | |
17827 | printf (" Tag_ARC_CPU_base: "); | |
17828 | switch (val) | |
17829 | { | |
17830 | default: | |
17831 | case TAG_CPU_NONE: | |
17832 | printf (_("Absent\n")); | |
17833 | break; | |
17834 | case TAG_CPU_ARC6xx: | |
17835 | printf ("ARC6xx\n"); | |
17836 | break; | |
17837 | case TAG_CPU_ARC7xx: | |
17838 | printf ("ARC7xx\n"); | |
17839 | break; | |
17840 | case TAG_CPU_ARCEM: | |
17841 | printf ("ARCEM\n"); | |
17842 | break; | |
17843 | case TAG_CPU_ARCHS: | |
17844 | printf ("ARCHS\n"); | |
17845 | break; | |
17846 | } | |
17847 | break; | |
17848 | ||
17849 | case Tag_ARC_CPU_variation: | |
17850 | READ_ULEB (val, p, end); | |
17851 | printf (" Tag_ARC_CPU_variation: "); | |
17852 | switch (val) | |
17853 | { | |
17854 | default: | |
17855 | if (val > 0 && val < 16) | |
17856 | printf ("Core%d\n", val); | |
17857 | else | |
17858 | printf ("Unknown\n"); | |
17859 | break; | |
17860 | ||
17861 | case 0: | |
17862 | printf (_("Absent\n")); | |
17863 | break; | |
17864 | } | |
17865 | break; | |
17866 | ||
17867 | case Tag_ARC_CPU_name: | |
17868 | printf (" Tag_ARC_CPU_name: "); | |
17869 | p = display_tag_value (-1, p, end); | |
17870 | break; | |
17871 | ||
17872 | case Tag_ARC_ABI_rf16: | |
17873 | READ_ULEB (val, p, end); | |
17874 | printf (" Tag_ARC_ABI_rf16: %s\n", val ? _("yes") : _("no")); | |
17875 | break; | |
17876 | ||
17877 | case Tag_ARC_ABI_osver: | |
17878 | READ_ULEB (val, p, end); | |
17879 | printf (" Tag_ARC_ABI_osver: v%d\n", val); | |
17880 | break; | |
17881 | ||
17882 | case Tag_ARC_ABI_pic: | |
17883 | case Tag_ARC_ABI_sda: | |
17884 | READ_ULEB (val, p, end); | |
17885 | printf (tag == Tag_ARC_ABI_sda ? " Tag_ARC_ABI_sda: " | |
17886 | : " Tag_ARC_ABI_pic: "); | |
17887 | switch (val) | |
17888 | { | |
17889 | case 0: | |
17890 | printf (_("Absent\n")); | |
17891 | break; | |
17892 | case 1: | |
17893 | printf ("MWDT\n"); | |
17894 | break; | |
17895 | case 2: | |
17896 | printf ("GNU\n"); | |
17897 | break; | |
17898 | default: | |
17899 | printf (_("Unknown\n")); | |
17900 | break; | |
17901 | } | |
17902 | break; | |
17903 | ||
17904 | case Tag_ARC_ABI_tls: | |
17905 | READ_ULEB (val, p, end); | |
17906 | printf (" Tag_ARC_ABI_tls: %s\n", val ? "r25": "none"); | |
17907 | break; | |
17908 | ||
17909 | case Tag_ARC_ABI_enumsize: | |
17910 | READ_ULEB (val, p, end); | |
17911 | printf (" Tag_ARC_ABI_enumsize: %s\n", val ? _("default") : | |
17912 | _("smallest")); | |
17913 | break; | |
17914 | ||
17915 | case Tag_ARC_ABI_exceptions: | |
17916 | READ_ULEB (val, p, end); | |
17917 | printf (" Tag_ARC_ABI_exceptions: %s\n", val ? _("OPTFP") | |
17918 | : _("default")); | |
17919 | break; | |
17920 | ||
17921 | case Tag_ARC_ABI_double_size: | |
17922 | READ_ULEB (val, p, end); | |
17923 | printf (" Tag_ARC_ABI_double_size: %d\n", val); | |
17924 | break; | |
17925 | ||
17926 | case Tag_ARC_ISA_config: | |
17927 | printf (" Tag_ARC_ISA_config: "); | |
17928 | p = display_tag_value (-1, p, end); | |
17929 | break; | |
17930 | ||
17931 | case Tag_ARC_ISA_apex: | |
17932 | printf (" Tag_ARC_ISA_apex: "); | |
17933 | p = display_tag_value (-1, p, end); | |
17934 | break; | |
17935 | ||
17936 | case Tag_ARC_ISA_mpy_option: | |
17937 | READ_ULEB (val, p, end); | |
17938 | printf (" Tag_ARC_ISA_mpy_option: %d\n", val); | |
17939 | break; | |
17940 | ||
17941 | case Tag_ARC_ATR_version: | |
17942 | READ_ULEB (val, p, end); | |
17943 | printf (" Tag_ARC_ATR_version: %d\n", val); | |
17944 | break; | |
17945 | ||
17946 | default: | |
17947 | return display_tag_value (tag & 1, p, end); | |
17948 | } | |
17949 | ||
17950 | return p; | |
17951 | } | |
17952 | ||
17953 | /* ARM EABI attributes section. */ | |
17954 | typedef struct | |
17955 | { | |
17956 | unsigned int tag; | |
17957 | const char * name; | |
17958 | /* 0 = special, 1 = string, 2 = uleb123, > 0x80 == table lookup. */ | |
17959 | unsigned int type; | |
17960 | const char *const *table; | |
17961 | } arm_attr_public_tag; | |
17962 | ||
17963 | static const char *const arm_attr_tag_CPU_arch[] = | |
17964 | {"Pre-v4", "v4", "v4T", "v5T", "v5TE", "v5TEJ", "v6", "v6KZ", "v6T2", | |
17965 | "v6K", "v7", "v6-M", "v6S-M", "v7E-M", "v8", "v8-R", "v8-M.baseline", | |
17966 | "v8-M.mainline", "v8.1-A", "v8.2-A", "v8.3-A", | |
17967 | "v8.1-M.mainline", "v9"}; | |
17968 | static const char *const arm_attr_tag_ARM_ISA_use[] = {"No", "Yes"}; | |
17969 | static const char *const arm_attr_tag_THUMB_ISA_use[] = | |
17970 | {"No", "Thumb-1", "Thumb-2", "Yes"}; | |
17971 | static const char *const arm_attr_tag_FP_arch[] = | |
17972 | {"No", "VFPv1", "VFPv2", "VFPv3", "VFPv3-D16", "VFPv4", "VFPv4-D16", | |
17973 | "FP for ARMv8", "FPv5/FP-D16 for ARMv8"}; | |
17974 | static const char *const arm_attr_tag_WMMX_arch[] = {"No", "WMMXv1", "WMMXv2"}; | |
17975 | static const char *const arm_attr_tag_Advanced_SIMD_arch[] = | |
17976 | {"No", "NEONv1", "NEONv1 with Fused-MAC", "NEON for ARMv8", | |
17977 | "NEON for ARMv8.1"}; | |
17978 | static const char *const arm_attr_tag_PCS_config[] = | |
17979 | {"None", "Bare platform", "Linux application", "Linux DSO", "PalmOS 2004", | |
17980 | "PalmOS (reserved)", "SymbianOS 2004", "SymbianOS (reserved)"}; | |
17981 | static const char *const arm_attr_tag_ABI_PCS_R9_use[] = | |
17982 | {"V6", "SB", "TLS", "Unused"}; | |
17983 | static const char *const arm_attr_tag_ABI_PCS_RW_data[] = | |
17984 | {"Absolute", "PC-relative", "SB-relative", "None"}; | |
17985 | static const char *const arm_attr_tag_ABI_PCS_RO_data[] = | |
17986 | {"Absolute", "PC-relative", "None"}; | |
17987 | static const char *const arm_attr_tag_ABI_PCS_GOT_use[] = | |
17988 | {"None", "direct", "GOT-indirect"}; | |
17989 | static const char *const arm_attr_tag_ABI_PCS_wchar_t[] = | |
17990 | {"None", "??? 1", "2", "??? 3", "4"}; | |
17991 | static const char *const arm_attr_tag_ABI_FP_rounding[] = {"Unused", "Needed"}; | |
17992 | static const char *const arm_attr_tag_ABI_FP_denormal[] = | |
17993 | {"Unused", "Needed", "Sign only"}; | |
17994 | static const char *const arm_attr_tag_ABI_FP_exceptions[] = {"Unused", "Needed"}; | |
17995 | static const char *const arm_attr_tag_ABI_FP_user_exceptions[] = {"Unused", "Needed"}; | |
17996 | static const char *const arm_attr_tag_ABI_FP_number_model[] = | |
17997 | {"Unused", "Finite", "RTABI", "IEEE 754"}; | |
17998 | static const char *const arm_attr_tag_ABI_enum_size[] = | |
17999 | {"Unused", "small", "int", "forced to int"}; | |
18000 | static const char *const arm_attr_tag_ABI_HardFP_use[] = | |
18001 | {"As Tag_FP_arch", "SP only", "Reserved", "Deprecated"}; | |
18002 | static const char *const arm_attr_tag_ABI_VFP_args[] = | |
18003 | {"AAPCS", "VFP registers", "custom", "compatible"}; | |
18004 | static const char *const arm_attr_tag_ABI_WMMX_args[] = | |
18005 | {"AAPCS", "WMMX registers", "custom"}; | |
18006 | static const char *const arm_attr_tag_ABI_optimization_goals[] = | |
18007 | {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size", | |
18008 | "Aggressive Size", "Prefer Debug", "Aggressive Debug"}; | |
18009 | static const char *const arm_attr_tag_ABI_FP_optimization_goals[] = | |
18010 | {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size", | |
18011 | "Aggressive Size", "Prefer Accuracy", "Aggressive Accuracy"}; | |
18012 | static const char *const arm_attr_tag_CPU_unaligned_access[] = {"None", "v6"}; | |
18013 | static const char *const arm_attr_tag_FP_HP_extension[] = | |
18014 | {"Not Allowed", "Allowed"}; | |
18015 | static const char *const arm_attr_tag_ABI_FP_16bit_format[] = | |
18016 | {"None", "IEEE 754", "Alternative Format"}; | |
18017 | static const char *const arm_attr_tag_DSP_extension[] = | |
18018 | {"Follow architecture", "Allowed"}; | |
18019 | static const char *const arm_attr_tag_MPextension_use[] = | |
18020 | {"Not Allowed", "Allowed"}; | |
18021 | static const char *const arm_attr_tag_DIV_use[] = | |
18022 | {"Allowed in Thumb-ISA, v7-R or v7-M", "Not allowed", | |
18023 | "Allowed in v7-A with integer division extension"}; | |
18024 | static const char *const arm_attr_tag_T2EE_use[] = {"Not Allowed", "Allowed"}; | |
18025 | static const char *const arm_attr_tag_Virtualization_use[] = | |
18026 | {"Not Allowed", "TrustZone", "Virtualization Extensions", | |
18027 | "TrustZone and Virtualization Extensions"}; | |
18028 | static const char *const arm_attr_tag_MPextension_use_legacy[] = | |
18029 | {"Not Allowed", "Allowed"}; | |
18030 | ||
18031 | static const char *const arm_attr_tag_MVE_arch[] = | |
18032 | {"No MVE", "MVE Integer only", "MVE Integer and FP"}; | |
18033 | ||
18034 | static const char * arm_attr_tag_PAC_extension[] = | |
18035 | {"No PAC/AUT instructions", | |
18036 | "PAC/AUT instructions permitted in the NOP space", | |
18037 | "PAC/AUT instructions permitted in the NOP and in the non-NOP space"}; | |
18038 | ||
18039 | static const char * arm_attr_tag_BTI_extension[] = | |
18040 | {"BTI instructions not permitted", | |
18041 | "BTI instructions permitted in the NOP space", | |
18042 | "BTI instructions permitted in the NOP and in the non-NOP space"}; | |
18043 | ||
18044 | static const char * arm_attr_tag_BTI_use[] = | |
18045 | {"Compiled without branch target enforcement", | |
18046 | "Compiled with branch target enforcement"}; | |
18047 | ||
18048 | static const char * arm_attr_tag_PACRET_use[] = | |
18049 | {"Compiled without return address signing and authentication", | |
18050 | "Compiled with return address signing and authentication"}; | |
18051 | ||
18052 | #define LOOKUP(id, name) \ | |
18053 | {id, #name, 0x80 | ARRAY_SIZE(arm_attr_tag_##name), arm_attr_tag_##name} | |
18054 | static arm_attr_public_tag arm_attr_public_tags[] = | |
18055 | { | |
18056 | {4, "CPU_raw_name", 1, NULL}, | |
18057 | {5, "CPU_name", 1, NULL}, | |
18058 | LOOKUP(6, CPU_arch), | |
18059 | {7, "CPU_arch_profile", 0, NULL}, | |
18060 | LOOKUP(8, ARM_ISA_use), | |
18061 | LOOKUP(9, THUMB_ISA_use), | |
18062 | LOOKUP(10, FP_arch), | |
18063 | LOOKUP(11, WMMX_arch), | |
18064 | LOOKUP(12, Advanced_SIMD_arch), | |
18065 | LOOKUP(13, PCS_config), | |
18066 | LOOKUP(14, ABI_PCS_R9_use), | |
18067 | LOOKUP(15, ABI_PCS_RW_data), | |
18068 | LOOKUP(16, ABI_PCS_RO_data), | |
18069 | LOOKUP(17, ABI_PCS_GOT_use), | |
18070 | LOOKUP(18, ABI_PCS_wchar_t), | |
18071 | LOOKUP(19, ABI_FP_rounding), | |
18072 | LOOKUP(20, ABI_FP_denormal), | |
18073 | LOOKUP(21, ABI_FP_exceptions), | |
18074 | LOOKUP(22, ABI_FP_user_exceptions), | |
18075 | LOOKUP(23, ABI_FP_number_model), | |
18076 | {24, "ABI_align_needed", 0, NULL}, | |
18077 | {25, "ABI_align_preserved", 0, NULL}, | |
18078 | LOOKUP(26, ABI_enum_size), | |
18079 | LOOKUP(27, ABI_HardFP_use), | |
18080 | LOOKUP(28, ABI_VFP_args), | |
18081 | LOOKUP(29, ABI_WMMX_args), | |
18082 | LOOKUP(30, ABI_optimization_goals), | |
18083 | LOOKUP(31, ABI_FP_optimization_goals), | |
18084 | {32, "compatibility", 0, NULL}, | |
18085 | LOOKUP(34, CPU_unaligned_access), | |
18086 | LOOKUP(36, FP_HP_extension), | |
18087 | LOOKUP(38, ABI_FP_16bit_format), | |
18088 | LOOKUP(42, MPextension_use), | |
18089 | LOOKUP(44, DIV_use), | |
18090 | LOOKUP(46, DSP_extension), | |
18091 | LOOKUP(48, MVE_arch), | |
18092 | LOOKUP(50, PAC_extension), | |
18093 | LOOKUP(52, BTI_extension), | |
18094 | LOOKUP(74, BTI_use), | |
18095 | LOOKUP(76, PACRET_use), | |
18096 | {64, "nodefaults", 0, NULL}, | |
18097 | {65, "also_compatible_with", 0, NULL}, | |
18098 | LOOKUP(66, T2EE_use), | |
18099 | {67, "conformance", 1, NULL}, | |
18100 | LOOKUP(68, Virtualization_use), | |
18101 | LOOKUP(70, MPextension_use_legacy) | |
18102 | }; | |
18103 | #undef LOOKUP | |
18104 | ||
18105 | static unsigned char * | |
18106 | display_arm_attribute (unsigned char * p, | |
18107 | const unsigned char * const end) | |
18108 | { | |
18109 | unsigned int tag; | |
18110 | unsigned int val; | |
18111 | arm_attr_public_tag * attr; | |
18112 | unsigned i; | |
18113 | unsigned int type; | |
18114 | ||
18115 | READ_ULEB (tag, p, end); | |
18116 | attr = NULL; | |
18117 | for (i = 0; i < ARRAY_SIZE (arm_attr_public_tags); i++) | |
18118 | { | |
18119 | if (arm_attr_public_tags[i].tag == tag) | |
18120 | { | |
18121 | attr = &arm_attr_public_tags[i]; | |
18122 | break; | |
18123 | } | |
18124 | } | |
18125 | ||
18126 | if (attr) | |
18127 | { | |
18128 | printf (" Tag_%s: ", attr->name); | |
18129 | switch (attr->type) | |
18130 | { | |
18131 | case 0: | |
18132 | switch (tag) | |
18133 | { | |
18134 | case 7: /* Tag_CPU_arch_profile. */ | |
18135 | READ_ULEB (val, p, end); | |
18136 | switch (val) | |
18137 | { | |
18138 | case 0: printf (_("None\n")); break; | |
18139 | case 'A': printf (_("Application\n")); break; | |
18140 | case 'R': printf (_("Realtime\n")); break; | |
18141 | case 'M': printf (_("Microcontroller\n")); break; | |
18142 | case 'S': printf (_("Application or Realtime\n")); break; | |
18143 | default: printf ("??? (%d)\n", val); break; | |
18144 | } | |
18145 | break; | |
18146 | ||
18147 | case 24: /* Tag_align_needed. */ | |
18148 | READ_ULEB (val, p, end); | |
18149 | switch (val) | |
18150 | { | |
18151 | case 0: printf (_("None\n")); break; | |
18152 | case 1: printf (_("8-byte\n")); break; | |
18153 | case 2: printf (_("4-byte\n")); break; | |
18154 | case 3: printf ("??? 3\n"); break; | |
18155 | default: | |
18156 | if (val <= 12) | |
18157 | printf (_("8-byte and up to %d-byte extended\n"), | |
18158 | 1 << val); | |
18159 | else | |
18160 | printf ("??? (%d)\n", val); | |
18161 | break; | |
18162 | } | |
18163 | break; | |
18164 | ||
18165 | case 25: /* Tag_align_preserved. */ | |
18166 | READ_ULEB (val, p, end); | |
18167 | switch (val) | |
18168 | { | |
18169 | case 0: printf (_("None\n")); break; | |
18170 | case 1: printf (_("8-byte, except leaf SP\n")); break; | |
18171 | case 2: printf (_("8-byte\n")); break; | |
18172 | case 3: printf ("??? 3\n"); break; | |
18173 | default: | |
18174 | if (val <= 12) | |
18175 | printf (_("8-byte and up to %d-byte extended\n"), | |
18176 | 1 << val); | |
18177 | else | |
18178 | printf ("??? (%d)\n", val); | |
18179 | break; | |
18180 | } | |
18181 | break; | |
18182 | ||
18183 | case 32: /* Tag_compatibility. */ | |
18184 | { | |
18185 | READ_ULEB (val, p, end); | |
18186 | printf (_("flag = %d, vendor = "), val); | |
18187 | if (p < end - 1) | |
18188 | { | |
18189 | size_t maxlen = (end - p) - 1; | |
18190 | ||
18191 | print_symbol_name ((int) maxlen, (const char *) p); | |
18192 | p += strnlen ((char *) p, maxlen) + 1; | |
18193 | } | |
18194 | else | |
18195 | { | |
18196 | printf (_("<corrupt>")); | |
18197 | p = (unsigned char *) end; | |
18198 | } | |
18199 | putchar ('\n'); | |
18200 | } | |
18201 | break; | |
18202 | ||
18203 | case 64: /* Tag_nodefaults. */ | |
18204 | /* PR 17531: file: 001-505008-0.01. */ | |
18205 | if (p < end) | |
18206 | p++; | |
18207 | printf (_("True\n")); | |
18208 | break; | |
18209 | ||
18210 | case 65: /* Tag_also_compatible_with. */ | |
18211 | READ_ULEB (val, p, end); | |
18212 | if (val == 6 /* Tag_CPU_arch. */) | |
18213 | { | |
18214 | READ_ULEB (val, p, end); | |
18215 | if ((unsigned int) val >= ARRAY_SIZE (arm_attr_tag_CPU_arch)) | |
18216 | printf ("??? (%d)\n", val); | |
18217 | else | |
18218 | printf ("%s\n", arm_attr_tag_CPU_arch[val]); | |
18219 | } | |
18220 | else | |
18221 | printf ("???\n"); | |
18222 | while (p < end && *(p++) != '\0' /* NUL terminator. */) | |
18223 | ; | |
18224 | break; | |
18225 | ||
18226 | default: | |
18227 | printf (_("<unknown: %d>\n"), tag); | |
18228 | break; | |
18229 | } | |
18230 | return p; | |
18231 | ||
18232 | case 1: | |
18233 | return display_tag_value (-1, p, end); | |
18234 | case 2: | |
18235 | return display_tag_value (0, p, end); | |
18236 | ||
18237 | default: | |
18238 | assert (attr->type & 0x80); | |
18239 | READ_ULEB (val, p, end); | |
18240 | type = attr->type & 0x7f; | |
18241 | if (val >= type) | |
18242 | printf ("??? (%d)\n", val); | |
18243 | else | |
18244 | printf ("%s\n", attr->table[val]); | |
18245 | return p; | |
18246 | } | |
18247 | } | |
18248 | ||
18249 | return display_tag_value (tag, p, end); | |
18250 | } | |
18251 | ||
18252 | static unsigned char * | |
18253 | display_gnu_attribute (unsigned char * p, | |
18254 | unsigned char * (* display_proc_gnu_attribute) | |
18255 | (unsigned char *, unsigned int, const unsigned char * const), | |
18256 | const unsigned char * const end) | |
18257 | { | |
18258 | unsigned int tag; | |
18259 | unsigned int val; | |
18260 | ||
18261 | READ_ULEB (tag, p, end); | |
18262 | ||
18263 | /* Tag_compatibility is the only generic GNU attribute defined at | |
18264 | present. */ | |
18265 | if (tag == 32) | |
18266 | { | |
18267 | READ_ULEB (val, p, end); | |
18268 | ||
18269 | printf (_("flag = %d, vendor = "), val); | |
18270 | if (p == end) | |
18271 | { | |
18272 | printf (_("<corrupt>\n")); | |
18273 | warn (_("corrupt vendor attribute\n")); | |
18274 | } | |
18275 | else | |
18276 | { | |
18277 | if (p < end - 1) | |
18278 | { | |
18279 | size_t maxlen = (end - p) - 1; | |
18280 | ||
18281 | print_symbol_name ((int) maxlen, (const char *) p); | |
18282 | p += strnlen ((char *) p, maxlen) + 1; | |
18283 | } | |
18284 | else | |
18285 | { | |
18286 | printf (_("<corrupt>")); | |
18287 | p = (unsigned char *) end; | |
18288 | } | |
18289 | putchar ('\n'); | |
18290 | } | |
18291 | return p; | |
18292 | } | |
18293 | ||
18294 | if ((tag & 2) == 0 && display_proc_gnu_attribute) | |
18295 | return display_proc_gnu_attribute (p, tag, end); | |
18296 | ||
18297 | return display_tag_value (tag, p, end); | |
18298 | } | |
18299 | ||
18300 | static unsigned char * | |
18301 | display_m68k_gnu_attribute (unsigned char * p, | |
18302 | unsigned int tag, | |
18303 | const unsigned char * const end) | |
18304 | { | |
18305 | unsigned int val; | |
18306 | ||
18307 | if (tag == Tag_GNU_M68K_ABI_FP) | |
18308 | { | |
18309 | printf (" Tag_GNU_M68K_ABI_FP: "); | |
18310 | if (p == end) | |
18311 | { | |
18312 | printf (_("<corrupt>\n")); | |
18313 | return p; | |
18314 | } | |
18315 | READ_ULEB (val, p, end); | |
18316 | ||
18317 | if (val > 3) | |
18318 | printf ("(%#x), ", val); | |
18319 | ||
18320 | switch (val & 3) | |
18321 | { | |
18322 | case 0: | |
18323 | printf (_("unspecified hard/soft float\n")); | |
18324 | break; | |
18325 | case 1: | |
18326 | printf (_("hard float\n")); | |
18327 | break; | |
18328 | case 2: | |
18329 | printf (_("soft float\n")); | |
18330 | break; | |
18331 | } | |
18332 | return p; | |
18333 | } | |
18334 | ||
18335 | return display_tag_value (tag & 1, p, end); | |
18336 | } | |
18337 | ||
18338 | static unsigned char * | |
18339 | display_power_gnu_attribute (unsigned char * p, | |
18340 | unsigned int tag, | |
18341 | const unsigned char * const end) | |
18342 | { | |
18343 | unsigned int val; | |
18344 | ||
18345 | if (tag == Tag_GNU_Power_ABI_FP) | |
18346 | { | |
18347 | printf (" Tag_GNU_Power_ABI_FP: "); | |
18348 | if (p == end) | |
18349 | { | |
18350 | printf (_("<corrupt>\n")); | |
18351 | return p; | |
18352 | } | |
18353 | READ_ULEB (val, p, end); | |
18354 | ||
18355 | if (val > 15) | |
18356 | printf ("(%#x), ", val); | |
18357 | ||
18358 | switch (val & 3) | |
18359 | { | |
18360 | case 0: | |
18361 | printf (_("unspecified hard/soft float, ")); | |
18362 | break; | |
18363 | case 1: | |
18364 | printf (_("hard float, ")); | |
18365 | break; | |
18366 | case 2: | |
18367 | printf (_("soft float, ")); | |
18368 | break; | |
18369 | case 3: | |
18370 | printf (_("single-precision hard float, ")); | |
18371 | break; | |
18372 | } | |
18373 | ||
18374 | switch (val & 0xC) | |
18375 | { | |
18376 | case 0: | |
18377 | printf (_("unspecified long double\n")); | |
18378 | break; | |
18379 | case 4: | |
18380 | printf (_("128-bit IBM long double\n")); | |
18381 | break; | |
18382 | case 8: | |
18383 | printf (_("64-bit long double\n")); | |
18384 | break; | |
18385 | case 12: | |
18386 | printf (_("128-bit IEEE long double\n")); | |
18387 | break; | |
18388 | } | |
18389 | return p; | |
18390 | } | |
18391 | ||
18392 | if (tag == Tag_GNU_Power_ABI_Vector) | |
18393 | { | |
18394 | printf (" Tag_GNU_Power_ABI_Vector: "); | |
18395 | if (p == end) | |
18396 | { | |
18397 | printf (_("<corrupt>\n")); | |
18398 | return p; | |
18399 | } | |
18400 | READ_ULEB (val, p, end); | |
18401 | ||
18402 | if (val > 3) | |
18403 | printf ("(%#x), ", val); | |
18404 | ||
18405 | switch (val & 3) | |
18406 | { | |
18407 | case 0: | |
18408 | printf (_("unspecified\n")); | |
18409 | break; | |
18410 | case 1: | |
18411 | printf (_("generic\n")); | |
18412 | break; | |
18413 | case 2: | |
18414 | printf ("AltiVec\n"); | |
18415 | break; | |
18416 | case 3: | |
18417 | printf ("SPE\n"); | |
18418 | break; | |
18419 | } | |
18420 | return p; | |
18421 | } | |
18422 | ||
18423 | if (tag == Tag_GNU_Power_ABI_Struct_Return) | |
18424 | { | |
18425 | printf (" Tag_GNU_Power_ABI_Struct_Return: "); | |
18426 | if (p == end) | |
18427 | { | |
18428 | printf (_("<corrupt>\n")); | |
18429 | return p; | |
18430 | } | |
18431 | READ_ULEB (val, p, end); | |
18432 | ||
18433 | if (val > 2) | |
18434 | printf ("(%#x), ", val); | |
18435 | ||
18436 | switch (val & 3) | |
18437 | { | |
18438 | case 0: | |
18439 | printf (_("unspecified\n")); | |
18440 | break; | |
18441 | case 1: | |
18442 | printf ("r3/r4\n"); | |
18443 | break; | |
18444 | case 2: | |
18445 | printf (_("memory\n")); | |
18446 | break; | |
18447 | case 3: | |
18448 | printf ("???\n"); | |
18449 | break; | |
18450 | } | |
18451 | return p; | |
18452 | } | |
18453 | ||
18454 | return display_tag_value (tag & 1, p, end); | |
18455 | } | |
18456 | ||
18457 | static unsigned char * | |
18458 | display_s390_gnu_attribute (unsigned char * p, | |
18459 | unsigned int tag, | |
18460 | const unsigned char * const end) | |
18461 | { | |
18462 | unsigned int val; | |
18463 | ||
18464 | if (tag == Tag_GNU_S390_ABI_Vector) | |
18465 | { | |
18466 | printf (" Tag_GNU_S390_ABI_Vector: "); | |
18467 | READ_ULEB (val, p, end); | |
18468 | ||
18469 | switch (val) | |
18470 | { | |
18471 | case 0: | |
18472 | printf (_("any\n")); | |
18473 | break; | |
18474 | case 1: | |
18475 | printf (_("software\n")); | |
18476 | break; | |
18477 | case 2: | |
18478 | printf (_("hardware\n")); | |
18479 | break; | |
18480 | default: | |
18481 | printf ("??? (%d)\n", val); | |
18482 | break; | |
18483 | } | |
18484 | return p; | |
18485 | } | |
18486 | ||
18487 | return display_tag_value (tag & 1, p, end); | |
18488 | } | |
18489 | ||
18490 | static void | |
18491 | display_sparc_hwcaps (unsigned int mask) | |
18492 | { | |
18493 | if (mask) | |
18494 | { | |
18495 | bool first = true; | |
18496 | ||
18497 | if (mask & ELF_SPARC_HWCAP_MUL32) | |
18498 | fputs ("mul32", stdout), first = false; | |
18499 | if (mask & ELF_SPARC_HWCAP_DIV32) | |
18500 | printf ("%sdiv32", first ? "" : "|"), first = false; | |
18501 | if (mask & ELF_SPARC_HWCAP_FSMULD) | |
18502 | printf ("%sfsmuld", first ? "" : "|"), first = false; | |
18503 | if (mask & ELF_SPARC_HWCAP_V8PLUS) | |
18504 | printf ("%sv8plus", first ? "" : "|"), first = false; | |
18505 | if (mask & ELF_SPARC_HWCAP_POPC) | |
18506 | printf ("%spopc", first ? "" : "|"), first = false; | |
18507 | if (mask & ELF_SPARC_HWCAP_VIS) | |
18508 | printf ("%svis", first ? "" : "|"), first = false; | |
18509 | if (mask & ELF_SPARC_HWCAP_VIS2) | |
18510 | printf ("%svis2", first ? "" : "|"), first = false; | |
18511 | if (mask & ELF_SPARC_HWCAP_ASI_BLK_INIT) | |
18512 | printf ("%sASIBlkInit", first ? "" : "|"), first = false; | |
18513 | if (mask & ELF_SPARC_HWCAP_FMAF) | |
18514 | printf ("%sfmaf", first ? "" : "|"), first = false; | |
18515 | if (mask & ELF_SPARC_HWCAP_VIS3) | |
18516 | printf ("%svis3", first ? "" : "|"), first = false; | |
18517 | if (mask & ELF_SPARC_HWCAP_HPC) | |
18518 | printf ("%shpc", first ? "" : "|"), first = false; | |
18519 | if (mask & ELF_SPARC_HWCAP_RANDOM) | |
18520 | printf ("%srandom", first ? "" : "|"), first = false; | |
18521 | if (mask & ELF_SPARC_HWCAP_TRANS) | |
18522 | printf ("%strans", first ? "" : "|"), first = false; | |
18523 | if (mask & ELF_SPARC_HWCAP_FJFMAU) | |
18524 | printf ("%sfjfmau", first ? "" : "|"), first = false; | |
18525 | if (mask & ELF_SPARC_HWCAP_IMA) | |
18526 | printf ("%sima", first ? "" : "|"), first = false; | |
18527 | if (mask & ELF_SPARC_HWCAP_ASI_CACHE_SPARING) | |
18528 | printf ("%scspare", first ? "" : "|"), first = false; | |
18529 | } | |
18530 | else | |
18531 | fputc ('0', stdout); | |
18532 | fputc ('\n', stdout); | |
18533 | } | |
18534 | ||
18535 | static void | |
18536 | display_sparc_hwcaps2 (unsigned int mask) | |
18537 | { | |
18538 | if (mask) | |
18539 | { | |
18540 | bool first = true; | |
18541 | ||
18542 | if (mask & ELF_SPARC_HWCAP2_FJATHPLUS) | |
18543 | fputs ("fjathplus", stdout), first = false; | |
18544 | if (mask & ELF_SPARC_HWCAP2_VIS3B) | |
18545 | printf ("%svis3b", first ? "" : "|"), first = false; | |
18546 | if (mask & ELF_SPARC_HWCAP2_ADP) | |
18547 | printf ("%sadp", first ? "" : "|"), first = false; | |
18548 | if (mask & ELF_SPARC_HWCAP2_SPARC5) | |
18549 | printf ("%ssparc5", first ? "" : "|"), first = false; | |
18550 | if (mask & ELF_SPARC_HWCAP2_MWAIT) | |
18551 | printf ("%smwait", first ? "" : "|"), first = false; | |
18552 | if (mask & ELF_SPARC_HWCAP2_XMPMUL) | |
18553 | printf ("%sxmpmul", first ? "" : "|"), first = false; | |
18554 | if (mask & ELF_SPARC_HWCAP2_XMONT) | |
18555 | printf ("%sxmont2", first ? "" : "|"), first = false; | |
18556 | if (mask & ELF_SPARC_HWCAP2_NSEC) | |
18557 | printf ("%snsec", first ? "" : "|"), first = false; | |
18558 | if (mask & ELF_SPARC_HWCAP2_FJATHHPC) | |
18559 | printf ("%sfjathhpc", first ? "" : "|"), first = false; | |
18560 | if (mask & ELF_SPARC_HWCAP2_FJDES) | |
18561 | printf ("%sfjdes", first ? "" : "|"), first = false; | |
18562 | if (mask & ELF_SPARC_HWCAP2_FJAES) | |
18563 | printf ("%sfjaes", first ? "" : "|"), first = false; | |
18564 | } | |
18565 | else | |
18566 | fputc ('0', stdout); | |
18567 | fputc ('\n', stdout); | |
18568 | } | |
18569 | ||
18570 | static unsigned char * | |
18571 | display_sparc_gnu_attribute (unsigned char * p, | |
18572 | unsigned int tag, | |
18573 | const unsigned char * const end) | |
18574 | { | |
18575 | unsigned int val; | |
18576 | ||
18577 | if (tag == Tag_GNU_Sparc_HWCAPS) | |
18578 | { | |
18579 | READ_ULEB (val, p, end); | |
18580 | printf (" Tag_GNU_Sparc_HWCAPS: "); | |
18581 | display_sparc_hwcaps (val); | |
18582 | return p; | |
18583 | } | |
18584 | if (tag == Tag_GNU_Sparc_HWCAPS2) | |
18585 | { | |
18586 | READ_ULEB (val, p, end); | |
18587 | printf (" Tag_GNU_Sparc_HWCAPS2: "); | |
18588 | display_sparc_hwcaps2 (val); | |
18589 | return p; | |
18590 | } | |
18591 | ||
18592 | return display_tag_value (tag, p, end); | |
18593 | } | |
18594 | ||
18595 | static void | |
18596 | print_mips_fp_abi_value (unsigned int val) | |
18597 | { | |
18598 | switch (val) | |
18599 | { | |
18600 | case Val_GNU_MIPS_ABI_FP_ANY: | |
18601 | printf (_("Hard or soft float\n")); | |
18602 | break; | |
18603 | case Val_GNU_MIPS_ABI_FP_DOUBLE: | |
18604 | printf (_("Hard float (double precision)\n")); | |
18605 | break; | |
18606 | case Val_GNU_MIPS_ABI_FP_SINGLE: | |
18607 | printf (_("Hard float (single precision)\n")); | |
18608 | break; | |
18609 | case Val_GNU_MIPS_ABI_FP_SOFT: | |
18610 | printf (_("Soft float\n")); | |
18611 | break; | |
18612 | case Val_GNU_MIPS_ABI_FP_OLD_64: | |
18613 | printf (_("Hard float (MIPS32r2 64-bit FPU 12 callee-saved)\n")); | |
18614 | break; | |
18615 | case Val_GNU_MIPS_ABI_FP_XX: | |
18616 | printf (_("Hard float (32-bit CPU, Any FPU)\n")); | |
18617 | break; | |
18618 | case Val_GNU_MIPS_ABI_FP_64: | |
18619 | printf (_("Hard float (32-bit CPU, 64-bit FPU)\n")); | |
18620 | break; | |
18621 | case Val_GNU_MIPS_ABI_FP_64A: | |
18622 | printf (_("Hard float compat (32-bit CPU, 64-bit FPU)\n")); | |
18623 | break; | |
18624 | case Val_GNU_MIPS_ABI_FP_NAN2008: | |
18625 | printf (_("NaN 2008 compatibility\n")); | |
18626 | break; | |
18627 | default: | |
18628 | printf ("??? (%d)\n", val); | |
18629 | break; | |
18630 | } | |
18631 | } | |
18632 | ||
18633 | static unsigned char * | |
18634 | display_mips_gnu_attribute (unsigned char * p, | |
18635 | unsigned int tag, | |
18636 | const unsigned char * const end) | |
18637 | { | |
18638 | if (tag == Tag_GNU_MIPS_ABI_FP) | |
18639 | { | |
18640 | unsigned int val; | |
18641 | ||
18642 | printf (" Tag_GNU_MIPS_ABI_FP: "); | |
18643 | READ_ULEB (val, p, end); | |
18644 | print_mips_fp_abi_value (val); | |
18645 | return p; | |
18646 | } | |
18647 | ||
18648 | if (tag == Tag_GNU_MIPS_ABI_MSA) | |
18649 | { | |
18650 | unsigned int val; | |
18651 | ||
18652 | printf (" Tag_GNU_MIPS_ABI_MSA: "); | |
18653 | READ_ULEB (val, p, end); | |
18654 | ||
18655 | switch (val) | |
18656 | { | |
18657 | case Val_GNU_MIPS_ABI_MSA_ANY: | |
18658 | printf (_("Any MSA or not\n")); | |
18659 | break; | |
18660 | case Val_GNU_MIPS_ABI_MSA_128: | |
18661 | printf (_("128-bit MSA\n")); | |
18662 | break; | |
18663 | default: | |
18664 | printf ("??? (%d)\n", val); | |
18665 | break; | |
18666 | } | |
18667 | return p; | |
18668 | } | |
18669 | ||
18670 | return display_tag_value (tag & 1, p, end); | |
18671 | } | |
18672 | ||
18673 | static unsigned char * | |
18674 | display_tic6x_attribute (unsigned char * p, | |
18675 | const unsigned char * const end) | |
18676 | { | |
18677 | unsigned int tag; | |
18678 | unsigned int val; | |
18679 | ||
18680 | READ_ULEB (tag, p, end); | |
18681 | ||
18682 | switch (tag) | |
18683 | { | |
18684 | case Tag_ISA: | |
18685 | printf (" Tag_ISA: "); | |
18686 | READ_ULEB (val, p, end); | |
18687 | ||
18688 | switch (val) | |
18689 | { | |
18690 | case C6XABI_Tag_ISA_none: | |
18691 | printf (_("None\n")); | |
18692 | break; | |
18693 | case C6XABI_Tag_ISA_C62X: | |
18694 | printf ("C62x\n"); | |
18695 | break; | |
18696 | case C6XABI_Tag_ISA_C67X: | |
18697 | printf ("C67x\n"); | |
18698 | break; | |
18699 | case C6XABI_Tag_ISA_C67XP: | |
18700 | printf ("C67x+\n"); | |
18701 | break; | |
18702 | case C6XABI_Tag_ISA_C64X: | |
18703 | printf ("C64x\n"); | |
18704 | break; | |
18705 | case C6XABI_Tag_ISA_C64XP: | |
18706 | printf ("C64x+\n"); | |
18707 | break; | |
18708 | case C6XABI_Tag_ISA_C674X: | |
18709 | printf ("C674x\n"); | |
18710 | break; | |
18711 | default: | |
18712 | printf ("??? (%d)\n", val); | |
18713 | break; | |
18714 | } | |
18715 | return p; | |
18716 | ||
18717 | case Tag_ABI_wchar_t: | |
18718 | printf (" Tag_ABI_wchar_t: "); | |
18719 | READ_ULEB (val, p, end); | |
18720 | switch (val) | |
18721 | { | |
18722 | case 0: | |
18723 | printf (_("Not used\n")); | |
18724 | break; | |
18725 | case 1: | |
18726 | printf (_("2 bytes\n")); | |
18727 | break; | |
18728 | case 2: | |
18729 | printf (_("4 bytes\n")); | |
18730 | break; | |
18731 | default: | |
18732 | printf ("??? (%d)\n", val); | |
18733 | break; | |
18734 | } | |
18735 | return p; | |
18736 | ||
18737 | case Tag_ABI_stack_align_needed: | |
18738 | printf (" Tag_ABI_stack_align_needed: "); | |
18739 | READ_ULEB (val, p, end); | |
18740 | switch (val) | |
18741 | { | |
18742 | case 0: | |
18743 | printf (_("8-byte\n")); | |
18744 | break; | |
18745 | case 1: | |
18746 | printf (_("16-byte\n")); | |
18747 | break; | |
18748 | default: | |
18749 | printf ("??? (%d)\n", val); | |
18750 | break; | |
18751 | } | |
18752 | return p; | |
18753 | ||
18754 | case Tag_ABI_stack_align_preserved: | |
18755 | READ_ULEB (val, p, end); | |
18756 | printf (" Tag_ABI_stack_align_preserved: "); | |
18757 | switch (val) | |
18758 | { | |
18759 | case 0: | |
18760 | printf (_("8-byte\n")); | |
18761 | break; | |
18762 | case 1: | |
18763 | printf (_("16-byte\n")); | |
18764 | break; | |
18765 | default: | |
18766 | printf ("??? (%d)\n", val); | |
18767 | break; | |
18768 | } | |
18769 | return p; | |
18770 | ||
18771 | case Tag_ABI_DSBT: | |
18772 | READ_ULEB (val, p, end); | |
18773 | printf (" Tag_ABI_DSBT: "); | |
18774 | switch (val) | |
18775 | { | |
18776 | case 0: | |
18777 | printf (_("DSBT addressing not used\n")); | |
18778 | break; | |
18779 | case 1: | |
18780 | printf (_("DSBT addressing used\n")); | |
18781 | break; | |
18782 | default: | |
18783 | printf ("??? (%d)\n", val); | |
18784 | break; | |
18785 | } | |
18786 | return p; | |
18787 | ||
18788 | case Tag_ABI_PID: | |
18789 | READ_ULEB (val, p, end); | |
18790 | printf (" Tag_ABI_PID: "); | |
18791 | switch (val) | |
18792 | { | |
18793 | case 0: | |
18794 | printf (_("Data addressing position-dependent\n")); | |
18795 | break; | |
18796 | case 1: | |
18797 | printf (_("Data addressing position-independent, GOT near DP\n")); | |
18798 | break; | |
18799 | case 2: | |
18800 | printf (_("Data addressing position-independent, GOT far from DP\n")); | |
18801 | break; | |
18802 | default: | |
18803 | printf ("??? (%d)\n", val); | |
18804 | break; | |
18805 | } | |
18806 | return p; | |
18807 | ||
18808 | case Tag_ABI_PIC: | |
18809 | READ_ULEB (val, p, end); | |
18810 | printf (" Tag_ABI_PIC: "); | |
18811 | switch (val) | |
18812 | { | |
18813 | case 0: | |
18814 | printf (_("Code addressing position-dependent\n")); | |
18815 | break; | |
18816 | case 1: | |
18817 | printf (_("Code addressing position-independent\n")); | |
18818 | break; | |
18819 | default: | |
18820 | printf ("??? (%d)\n", val); | |
18821 | break; | |
18822 | } | |
18823 | return p; | |
18824 | ||
18825 | case Tag_ABI_array_object_alignment: | |
18826 | READ_ULEB (val, p, end); | |
18827 | printf (" Tag_ABI_array_object_alignment: "); | |
18828 | switch (val) | |
18829 | { | |
18830 | case 0: | |
18831 | printf (_("8-byte\n")); | |
18832 | break; | |
18833 | case 1: | |
18834 | printf (_("4-byte\n")); | |
18835 | break; | |
18836 | case 2: | |
18837 | printf (_("16-byte\n")); | |
18838 | break; | |
18839 | default: | |
18840 | printf ("??? (%d)\n", val); | |
18841 | break; | |
18842 | } | |
18843 | return p; | |
18844 | ||
18845 | case Tag_ABI_array_object_align_expected: | |
18846 | READ_ULEB (val, p, end); | |
18847 | printf (" Tag_ABI_array_object_align_expected: "); | |
18848 | switch (val) | |
18849 | { | |
18850 | case 0: | |
18851 | printf (_("8-byte\n")); | |
18852 | break; | |
18853 | case 1: | |
18854 | printf (_("4-byte\n")); | |
18855 | break; | |
18856 | case 2: | |
18857 | printf (_("16-byte\n")); | |
18858 | break; | |
18859 | default: | |
18860 | printf ("??? (%d)\n", val); | |
18861 | break; | |
18862 | } | |
18863 | return p; | |
18864 | ||
18865 | case Tag_ABI_compatibility: | |
18866 | { | |
18867 | READ_ULEB (val, p, end); | |
18868 | printf (" Tag_ABI_compatibility: "); | |
18869 | printf (_("flag = %d, vendor = "), val); | |
18870 | if (p < end - 1) | |
18871 | { | |
18872 | size_t maxlen = (end - p) - 1; | |
18873 | ||
18874 | print_symbol_name ((int) maxlen, (const char *) p); | |
18875 | p += strnlen ((char *) p, maxlen) + 1; | |
18876 | } | |
18877 | else | |
18878 | { | |
18879 | printf (_("<corrupt>")); | |
18880 | p = (unsigned char *) end; | |
18881 | } | |
18882 | putchar ('\n'); | |
18883 | return p; | |
18884 | } | |
18885 | ||
18886 | case Tag_ABI_conformance: | |
18887 | { | |
18888 | printf (" Tag_ABI_conformance: \""); | |
18889 | if (p < end - 1) | |
18890 | { | |
18891 | size_t maxlen = (end - p) - 1; | |
18892 | ||
18893 | print_symbol_name ((int) maxlen, (const char *) p); | |
18894 | p += strnlen ((char *) p, maxlen) + 1; | |
18895 | } | |
18896 | else | |
18897 | { | |
18898 | printf (_("<corrupt>")); | |
18899 | p = (unsigned char *) end; | |
18900 | } | |
18901 | printf ("\"\n"); | |
18902 | return p; | |
18903 | } | |
18904 | } | |
18905 | ||
18906 | return display_tag_value (tag, p, end); | |
18907 | } | |
18908 | ||
18909 | static void | |
18910 | display_raw_attribute (unsigned char * p, unsigned char const * const end) | |
18911 | { | |
18912 | uint64_t addr = 0; | |
18913 | size_t bytes = end - p; | |
18914 | ||
18915 | assert (end >= p); | |
18916 | while (bytes) | |
18917 | { | |
18918 | int j; | |
18919 | int k; | |
18920 | int lbytes = (bytes > 16 ? 16 : bytes); | |
18921 | ||
18922 | printf (" 0x%8.8" PRIx64 " ", addr); | |
18923 | ||
18924 | for (j = 0; j < 16; j++) | |
18925 | { | |
18926 | if (j < lbytes) | |
18927 | printf ("%2.2x", p[j]); | |
18928 | else | |
18929 | printf (" "); | |
18930 | ||
18931 | if ((j & 3) == 3) | |
18932 | printf (" "); | |
18933 | } | |
18934 | ||
18935 | for (j = 0; j < lbytes; j++) | |
18936 | { | |
18937 | k = p[j]; | |
18938 | if (k >= ' ' && k < 0x7f) | |
18939 | printf ("%c", k); | |
18940 | else | |
18941 | printf ("."); | |
18942 | } | |
18943 | ||
18944 | putchar ('\n'); | |
18945 | ||
18946 | p += lbytes; | |
18947 | bytes -= lbytes; | |
18948 | addr += lbytes; | |
18949 | } | |
18950 | ||
18951 | putchar ('\n'); | |
18952 | } | |
18953 | ||
18954 | static unsigned char * | |
18955 | display_msp430_attribute (unsigned char * p, | |
18956 | const unsigned char * const end) | |
18957 | { | |
18958 | uint64_t val; | |
18959 | uint64_t tag; | |
18960 | ||
18961 | READ_ULEB (tag, p, end); | |
18962 | ||
18963 | switch (tag) | |
18964 | { | |
18965 | case OFBA_MSPABI_Tag_ISA: | |
18966 | printf (" Tag_ISA: "); | |
18967 | READ_ULEB (val, p, end); | |
18968 | switch (val) | |
18969 | { | |
18970 | case 0: printf (_("None\n")); break; | |
18971 | case 1: printf (_("MSP430\n")); break; | |
18972 | case 2: printf (_("MSP430X\n")); break; | |
18973 | default: printf ("??? (%" PRId64 ")\n", val); break; | |
18974 | } | |
18975 | break; | |
18976 | ||
18977 | case OFBA_MSPABI_Tag_Code_Model: | |
18978 | printf (" Tag_Code_Model: "); | |
18979 | READ_ULEB (val, p, end); | |
18980 | switch (val) | |
18981 | { | |
18982 | case 0: printf (_("None\n")); break; | |
18983 | case 1: printf (_("Small\n")); break; | |
18984 | case 2: printf (_("Large\n")); break; | |
18985 | default: printf ("??? (%" PRId64 ")\n", val); break; | |
18986 | } | |
18987 | break; | |
18988 | ||
18989 | case OFBA_MSPABI_Tag_Data_Model: | |
18990 | printf (" Tag_Data_Model: "); | |
18991 | READ_ULEB (val, p, end); | |
18992 | switch (val) | |
18993 | { | |
18994 | case 0: printf (_("None\n")); break; | |
18995 | case 1: printf (_("Small\n")); break; | |
18996 | case 2: printf (_("Large\n")); break; | |
18997 | case 3: printf (_("Restricted Large\n")); break; | |
18998 | default: printf ("??? (%" PRId64 ")\n", val); break; | |
18999 | } | |
19000 | break; | |
19001 | ||
19002 | default: | |
19003 | printf (_(" <unknown tag %" PRId64 ">: "), tag); | |
19004 | ||
19005 | if (tag & 1) | |
19006 | { | |
19007 | putchar ('"'); | |
19008 | if (p < end - 1) | |
19009 | { | |
19010 | size_t maxlen = (end - p) - 1; | |
19011 | ||
19012 | print_symbol_name ((int) maxlen, (const char *) p); | |
19013 | p += strnlen ((char *) p, maxlen) + 1; | |
19014 | } | |
19015 | else | |
19016 | { | |
19017 | printf (_("<corrupt>")); | |
19018 | p = (unsigned char *) end; | |
19019 | } | |
19020 | printf ("\"\n"); | |
19021 | } | |
19022 | else | |
19023 | { | |
19024 | READ_ULEB (val, p, end); | |
19025 | printf ("%" PRId64 " (0x%" PRIx64 ")\n", val, val); | |
19026 | } | |
19027 | break; | |
19028 | } | |
19029 | ||
19030 | assert (p <= end); | |
19031 | return p; | |
19032 | } | |
19033 | ||
19034 | static unsigned char * | |
19035 | display_msp430_gnu_attribute (unsigned char * p, | |
19036 | unsigned int tag, | |
19037 | const unsigned char * const end) | |
19038 | { | |
19039 | if (tag == Tag_GNU_MSP430_Data_Region) | |
19040 | { | |
19041 | uint64_t val; | |
19042 | ||
19043 | printf (" Tag_GNU_MSP430_Data_Region: "); | |
19044 | READ_ULEB (val, p, end); | |
19045 | ||
19046 | switch (val) | |
19047 | { | |
19048 | case Val_GNU_MSP430_Data_Region_Any: | |
19049 | printf (_("Any Region\n")); | |
19050 | break; | |
19051 | case Val_GNU_MSP430_Data_Region_Lower: | |
19052 | printf (_("Lower Region Only\n")); | |
19053 | break; | |
19054 | default: | |
19055 | printf ("??? (%" PRIu64 ")\n", val); | |
19056 | } | |
19057 | return p; | |
19058 | } | |
19059 | return display_tag_value (tag & 1, p, end); | |
19060 | } | |
19061 | ||
19062 | struct riscv_attr_tag_t { | |
19063 | const char *name; | |
19064 | unsigned int tag; | |
19065 | }; | |
19066 | ||
19067 | static struct riscv_attr_tag_t riscv_attr_tag[] = | |
19068 | { | |
19069 | #define T(tag) {"Tag_RISCV_" #tag, Tag_RISCV_##tag} | |
19070 | T(arch), | |
19071 | T(priv_spec), | |
19072 | T(priv_spec_minor), | |
19073 | T(priv_spec_revision), | |
19074 | T(unaligned_access), | |
19075 | T(stack_align), | |
19076 | #undef T | |
19077 | }; | |
19078 | ||
19079 | static unsigned char * | |
19080 | display_riscv_attribute (unsigned char *p, | |
19081 | const unsigned char * const end) | |
19082 | { | |
19083 | uint64_t val; | |
19084 | uint64_t tag; | |
19085 | struct riscv_attr_tag_t *attr = NULL; | |
19086 | unsigned i; | |
19087 | ||
19088 | READ_ULEB (tag, p, end); | |
19089 | ||
19090 | /* Find the name of attribute. */ | |
19091 | for (i = 0; i < ARRAY_SIZE (riscv_attr_tag); i++) | |
19092 | { | |
19093 | if (riscv_attr_tag[i].tag == tag) | |
19094 | { | |
19095 | attr = &riscv_attr_tag[i]; | |
19096 | break; | |
19097 | } | |
19098 | } | |
19099 | ||
19100 | if (attr) | |
19101 | printf (" %s: ", attr->name); | |
19102 | else | |
19103 | return display_tag_value (tag, p, end); | |
19104 | ||
19105 | switch (tag) | |
19106 | { | |
19107 | case Tag_RISCV_priv_spec: | |
19108 | case Tag_RISCV_priv_spec_minor: | |
19109 | case Tag_RISCV_priv_spec_revision: | |
19110 | READ_ULEB (val, p, end); | |
19111 | printf ("%" PRIu64 "\n", val); | |
19112 | break; | |
19113 | case Tag_RISCV_unaligned_access: | |
19114 | READ_ULEB (val, p, end); | |
19115 | switch (val) | |
19116 | { | |
19117 | case 0: | |
19118 | printf (_("No unaligned access\n")); | |
19119 | break; | |
19120 | case 1: | |
19121 | printf (_("Unaligned access\n")); | |
19122 | break; | |
19123 | } | |
19124 | break; | |
19125 | case Tag_RISCV_stack_align: | |
19126 | READ_ULEB (val, p, end); | |
19127 | printf (_("%" PRIu64 "-bytes\n"), val); | |
19128 | break; | |
19129 | case Tag_RISCV_arch: | |
19130 | p = display_tag_value (-1, p, end); | |
19131 | break; | |
19132 | default: | |
19133 | return display_tag_value (tag, p, end); | |
19134 | } | |
19135 | ||
19136 | return p; | |
19137 | } | |
19138 | ||
19139 | static unsigned char * | |
19140 | display_csky_attribute (unsigned char * p, | |
19141 | const unsigned char * const end) | |
19142 | { | |
19143 | uint64_t tag; | |
19144 | uint64_t val; | |
19145 | READ_ULEB (tag, p, end); | |
19146 | ||
19147 | if (tag >= Tag_CSKY_MAX) | |
19148 | { | |
19149 | return display_tag_value (-1, p, end); | |
19150 | } | |
19151 | ||
19152 | switch (tag) | |
19153 | { | |
19154 | case Tag_CSKY_ARCH_NAME: | |
19155 | printf (" Tag_CSKY_ARCH_NAME:\t\t"); | |
19156 | return display_tag_value (-1, p, end); | |
19157 | case Tag_CSKY_CPU_NAME: | |
19158 | printf (" Tag_CSKY_CPU_NAME:\t\t"); | |
19159 | return display_tag_value (-1, p, end); | |
19160 | ||
19161 | case Tag_CSKY_ISA_FLAGS: | |
19162 | printf (" Tag_CSKY_ISA_FLAGS:\t\t"); | |
19163 | return display_tag_value (0, p, end); | |
19164 | case Tag_CSKY_ISA_EXT_FLAGS: | |
19165 | printf (" Tag_CSKY_ISA_EXT_FLAGS:\t"); | |
19166 | return display_tag_value (0, p, end); | |
19167 | ||
19168 | case Tag_CSKY_DSP_VERSION: | |
19169 | printf (" Tag_CSKY_DSP_VERSION:\t\t"); | |
19170 | READ_ULEB (val, p, end); | |
19171 | if (val == VAL_CSKY_DSP_VERSION_EXTENSION) | |
19172 | printf ("DSP Extension\n"); | |
19173 | else if (val == VAL_CSKY_DSP_VERSION_2) | |
19174 | printf ("DSP 2.0\n"); | |
19175 | break; | |
19176 | ||
19177 | case Tag_CSKY_VDSP_VERSION: | |
19178 | printf (" Tag_CSKY_VDSP_VERSION:\t"); | |
19179 | READ_ULEB (val, p, end); | |
19180 | printf ("VDSP Version %" PRId64 "\n", val); | |
19181 | break; | |
19182 | ||
19183 | case Tag_CSKY_FPU_VERSION: | |
19184 | printf (" Tag_CSKY_FPU_VERSION:\t\t"); | |
19185 | READ_ULEB (val, p, end); | |
19186 | if (val == VAL_CSKY_FPU_VERSION_1) | |
19187 | printf ("ABIV1 FPU Version 1\n"); | |
19188 | else if (val == VAL_CSKY_FPU_VERSION_2) | |
19189 | printf ("FPU Version 2\n"); | |
19190 | break; | |
19191 | ||
19192 | case Tag_CSKY_FPU_ABI: | |
19193 | printf (" Tag_CSKY_FPU_ABI:\t\t"); | |
19194 | READ_ULEB (val, p, end); | |
19195 | if (val == VAL_CSKY_FPU_ABI_HARD) | |
19196 | printf ("Hard\n"); | |
19197 | else if (val == VAL_CSKY_FPU_ABI_SOFTFP) | |
19198 | printf ("SoftFP\n"); | |
19199 | else if (val == VAL_CSKY_FPU_ABI_SOFT) | |
19200 | printf ("Soft\n"); | |
19201 | break; | |
19202 | case Tag_CSKY_FPU_ROUNDING: | |
19203 | READ_ULEB (val, p, end); | |
19204 | if (val == 1) | |
19205 | { | |
19206 | printf (" Tag_CSKY_FPU_ROUNDING:\t"); | |
19207 | printf ("Needed\n"); | |
19208 | } | |
19209 | break; | |
19210 | case Tag_CSKY_FPU_DENORMAL: | |
19211 | READ_ULEB (val, p, end); | |
19212 | if (val == 1) | |
19213 | { | |
19214 | printf (" Tag_CSKY_FPU_DENORMAL:\t"); | |
19215 | printf ("Needed\n"); | |
19216 | } | |
19217 | break; | |
19218 | case Tag_CSKY_FPU_Exception: | |
19219 | READ_ULEB (val, p, end); | |
19220 | if (val == 1) | |
19221 | { | |
19222 | printf (" Tag_CSKY_FPU_Exception:\t"); | |
19223 | printf ("Needed\n"); | |
19224 | } | |
19225 | break; | |
19226 | case Tag_CSKY_FPU_NUMBER_MODULE: | |
19227 | printf (" Tag_CSKY_FPU_NUMBER_MODULE:\t"); | |
19228 | return display_tag_value (-1, p, end); | |
19229 | case Tag_CSKY_FPU_HARDFP: | |
19230 | printf (" Tag_CSKY_FPU_HARDFP:\t\t"); | |
19231 | READ_ULEB (val, p, end); | |
19232 | if (val & VAL_CSKY_FPU_HARDFP_HALF) | |
19233 | printf (" Half"); | |
19234 | if (val & VAL_CSKY_FPU_HARDFP_SINGLE) | |
19235 | printf (" Single"); | |
19236 | if (val & VAL_CSKY_FPU_HARDFP_DOUBLE) | |
19237 | printf (" Double"); | |
19238 | printf ("\n"); | |
19239 | break; | |
19240 | default: | |
19241 | return display_tag_value (tag, p, end); | |
19242 | } | |
19243 | return p; | |
19244 | } | |
19245 | ||
19246 | static bool | |
19247 | process_attributes (Filedata * filedata, | |
19248 | const char * public_name, | |
19249 | unsigned int proc_type, | |
19250 | unsigned char * (* display_pub_attribute) (unsigned char *, const unsigned char * const), | |
19251 | unsigned char * (* display_proc_gnu_attribute) (unsigned char *, unsigned int, const unsigned char * const)) | |
19252 | { | |
19253 | /* Find the section header so that we get the size. */ | |
19254 | Elf_Internal_Shdr * sect = find_section_by_type (filedata, proc_type); | |
19255 | if (sect == NULL) | |
19256 | sect = find_section_by_type (filedata, SHT_GNU_ATTRIBUTES); | |
19257 | ||
19258 | if (sect == NULL) | |
19259 | /* No section, exit without error. */ | |
19260 | return true; | |
19261 | ||
19262 | unsigned char * contents = (unsigned char *) | |
19263 | get_data (NULL, filedata, sect->sh_offset, 1, sect->sh_size, _("attributes")); | |
19264 | if (contents == NULL) | |
19265 | return false; | |
19266 | ||
19267 | bool res = true; | |
19268 | unsigned char * p = contents; | |
19269 | /* The first character is the version of the attributes. | |
19270 | Currently only version 1, (aka 'A') is recognised here. */ | |
19271 | if (*p != 'A') | |
19272 | { | |
19273 | printf (_("Unknown attributes version '%c'(%d) - expecting 'A'\n"), *p, *p); | |
19274 | res = false; | |
19275 | goto free_data; | |
19276 | } | |
19277 | ||
19278 | uint64_t section_len = sect->sh_size - 1; | |
19279 | p++; | |
19280 | ||
19281 | while (section_len > 0) | |
19282 | { | |
19283 | uint64_t attr_len; | |
19284 | unsigned int namelen; | |
19285 | bool public_section; | |
19286 | bool gnu_section; | |
19287 | ||
19288 | if (section_len <= 4) | |
19289 | { | |
19290 | error (_("Tag section ends prematurely\n")); | |
19291 | res = false; | |
19292 | break; | |
19293 | } | |
19294 | attr_len = byte_get (p, 4); | |
19295 | p += 4; | |
19296 | ||
19297 | if (attr_len > section_len) | |
19298 | { | |
19299 | error (_("Bad attribute length (%u > %u)\n"), | |
19300 | (unsigned) attr_len, (unsigned) section_len); | |
19301 | attr_len = section_len; | |
19302 | res = false; | |
19303 | } | |
19304 | /* PR 17531: file: 001-101425-0.004 */ | |
19305 | else if (attr_len < 5) | |
19306 | { | |
19307 | error (_("Attribute length of %u is too small\n"), (unsigned) attr_len); | |
19308 | res = false; | |
19309 | break; | |
19310 | } | |
19311 | ||
19312 | section_len -= attr_len; | |
19313 | attr_len -= 4; | |
19314 | ||
19315 | namelen = strnlen ((char *) p, attr_len) + 1; | |
19316 | if (namelen == 0 || namelen >= attr_len) | |
19317 | { | |
19318 | error (_("Corrupt attribute section name\n")); | |
19319 | res = false; | |
19320 | break; | |
19321 | } | |
19322 | ||
19323 | printf (_("Attribute Section: ")); | |
19324 | print_symbol_name (INT_MAX, (const char *) p); | |
19325 | putchar ('\n'); | |
19326 | ||
19327 | if (public_name && streq ((char *) p, public_name)) | |
19328 | public_section = true; | |
19329 | else | |
19330 | public_section = false; | |
19331 | ||
19332 | if (streq ((char *) p, "gnu")) | |
19333 | gnu_section = true; | |
19334 | else | |
19335 | gnu_section = false; | |
19336 | ||
19337 | p += namelen; | |
19338 | attr_len -= namelen; | |
19339 | ||
19340 | while (attr_len > 0 && p < contents + sect->sh_size) | |
19341 | { | |
19342 | int tag; | |
19343 | unsigned int val; | |
19344 | uint64_t size; | |
19345 | unsigned char * end; | |
19346 | ||
19347 | /* PR binutils/17531: Safe handling of corrupt files. */ | |
19348 | if (attr_len < 6) | |
19349 | { | |
19350 | error (_("Unused bytes at end of section\n")); | |
19351 | res = false; | |
19352 | section_len = 0; | |
19353 | break; | |
19354 | } | |
19355 | ||
19356 | tag = *(p++); | |
19357 | size = byte_get (p, 4); | |
19358 | if (size > attr_len) | |
19359 | { | |
19360 | error (_("Bad subsection length (%u > %u)\n"), | |
19361 | (unsigned) size, (unsigned) attr_len); | |
19362 | res = false; | |
19363 | size = attr_len; | |
19364 | } | |
19365 | /* PR binutils/17531: Safe handling of corrupt files. */ | |
19366 | if (size < 6) | |
19367 | { | |
19368 | error (_("Bad subsection length (%u < 6)\n"), | |
19369 | (unsigned) size); | |
19370 | res = false; | |
19371 | section_len = 0; | |
19372 | break; | |
19373 | } | |
19374 | ||
19375 | attr_len -= size; | |
19376 | end = p + size - 1; | |
19377 | assert (end <= contents + sect->sh_size); | |
19378 | p += 4; | |
19379 | ||
19380 | switch (tag) | |
19381 | { | |
19382 | case 1: | |
19383 | printf (_("File Attributes\n")); | |
19384 | break; | |
19385 | case 2: | |
19386 | printf (_("Section Attributes:")); | |
19387 | goto do_numlist; | |
19388 | case 3: | |
19389 | printf (_("Symbol Attributes:")); | |
19390 | /* Fall through. */ | |
19391 | do_numlist: | |
19392 | for (;;) | |
19393 | { | |
19394 | READ_ULEB (val, p, end); | |
19395 | if (val == 0) | |
19396 | break; | |
19397 | printf (" %d", val); | |
19398 | } | |
19399 | printf ("\n"); | |
19400 | break; | |
19401 | default: | |
19402 | printf (_("Unknown tag: %d\n"), tag); | |
19403 | public_section = false; | |
19404 | break; | |
19405 | } | |
19406 | ||
19407 | if (public_section && display_pub_attribute != NULL) | |
19408 | { | |
19409 | while (p < end) | |
19410 | p = display_pub_attribute (p, end); | |
19411 | assert (p == end); | |
19412 | } | |
19413 | else if (gnu_section && display_proc_gnu_attribute != NULL) | |
19414 | { | |
19415 | while (p < end) | |
19416 | p = display_gnu_attribute (p, | |
19417 | display_proc_gnu_attribute, | |
19418 | end); | |
19419 | assert (p == end); | |
19420 | } | |
19421 | else if (p < end) | |
19422 | { | |
19423 | printf (_(" Unknown attribute:\n")); | |
19424 | display_raw_attribute (p, end); | |
19425 | p = end; | |
19426 | } | |
19427 | else | |
19428 | attr_len = 0; | |
19429 | } | |
19430 | } | |
19431 | ||
19432 | free_data: | |
19433 | free (contents); | |
19434 | ||
19435 | return res; | |
19436 | } | |
19437 | ||
19438 | /* DATA points to the contents of a MIPS GOT that starts at VMA PLTGOT. | |
19439 | Print the Address, Access and Initial fields of an entry at VMA ADDR | |
19440 | and return the VMA of the next entry, or -1 if there was a problem. | |
19441 | Does not read from DATA_END or beyond. */ | |
19442 | ||
19443 | static uint64_t | |
19444 | print_mips_got_entry (unsigned char * data, uint64_t pltgot, uint64_t addr, | |
19445 | unsigned char * data_end) | |
19446 | { | |
19447 | printf (" "); | |
19448 | print_vma (addr, LONG_HEX); | |
19449 | printf (" "); | |
19450 | if (addr < pltgot + 0xfff0) | |
19451 | printf ("%6d(gp)", (int) (addr - pltgot - 0x7ff0)); | |
19452 | else | |
19453 | printf ("%10s", ""); | |
19454 | printf (" "); | |
19455 | if (data == NULL) | |
19456 | printf ("%*s", is_32bit_elf ? 8 : 16, _("<unknown>")); | |
19457 | else | |
19458 | { | |
19459 | uint64_t entry; | |
19460 | unsigned char * from = data + addr - pltgot; | |
19461 | ||
19462 | if (from + (is_32bit_elf ? 4 : 8) > data_end) | |
19463 | { | |
19464 | warn (_("MIPS GOT entry extends beyond the end of available data\n")); | |
19465 | printf ("%*s", is_32bit_elf ? 8 : 16, _("<corrupt>")); | |
19466 | return (uint64_t) -1; | |
19467 | } | |
19468 | else | |
19469 | { | |
19470 | entry = byte_get (data + addr - pltgot, is_32bit_elf ? 4 : 8); | |
19471 | print_vma (entry, LONG_HEX); | |
19472 | } | |
19473 | } | |
19474 | return addr + (is_32bit_elf ? 4 : 8); | |
19475 | } | |
19476 | ||
19477 | /* DATA points to the contents of a MIPS PLT GOT that starts at VMA | |
19478 | PLTGOT. Print the Address and Initial fields of an entry at VMA | |
19479 | ADDR and return the VMA of the next entry. */ | |
19480 | ||
19481 | static uint64_t | |
19482 | print_mips_pltgot_entry (unsigned char * data, uint64_t pltgot, uint64_t addr) | |
19483 | { | |
19484 | printf (" "); | |
19485 | print_vma (addr, LONG_HEX); | |
19486 | printf (" "); | |
19487 | if (data == NULL) | |
19488 | printf ("%*s", is_32bit_elf ? 8 : 16, _("<unknown>")); | |
19489 | else | |
19490 | { | |
19491 | uint64_t entry; | |
19492 | ||
19493 | entry = byte_get (data + addr - pltgot, is_32bit_elf ? 4 : 8); | |
19494 | print_vma (entry, LONG_HEX); | |
19495 | } | |
19496 | return addr + (is_32bit_elf ? 4 : 8); | |
19497 | } | |
19498 | ||
19499 | static void | |
19500 | print_mips_ases (unsigned int mask) | |
19501 | { | |
19502 | if (mask & AFL_ASE_DSP) | |
19503 | fputs ("\n\tDSP ASE", stdout); | |
19504 | if (mask & AFL_ASE_DSPR2) | |
19505 | fputs ("\n\tDSP R2 ASE", stdout); | |
19506 | if (mask & AFL_ASE_DSPR3) | |
19507 | fputs ("\n\tDSP R3 ASE", stdout); | |
19508 | if (mask & AFL_ASE_EVA) | |
19509 | fputs ("\n\tEnhanced VA Scheme", stdout); | |
19510 | if (mask & AFL_ASE_MCU) | |
19511 | fputs ("\n\tMCU (MicroController) ASE", stdout); | |
19512 | if (mask & AFL_ASE_MDMX) | |
19513 | fputs ("\n\tMDMX ASE", stdout); | |
19514 | if (mask & AFL_ASE_MIPS3D) | |
19515 | fputs ("\n\tMIPS-3D ASE", stdout); | |
19516 | if (mask & AFL_ASE_MT) | |
19517 | fputs ("\n\tMT ASE", stdout); | |
19518 | if (mask & AFL_ASE_SMARTMIPS) | |
19519 | fputs ("\n\tSmartMIPS ASE", stdout); | |
19520 | if (mask & AFL_ASE_VIRT) | |
19521 | fputs ("\n\tVZ ASE", stdout); | |
19522 | if (mask & AFL_ASE_MSA) | |
19523 | fputs ("\n\tMSA ASE", stdout); | |
19524 | if (mask & AFL_ASE_MIPS16) | |
19525 | fputs ("\n\tMIPS16 ASE", stdout); | |
19526 | if (mask & AFL_ASE_MICROMIPS) | |
19527 | fputs ("\n\tMICROMIPS ASE", stdout); | |
19528 | if (mask & AFL_ASE_XPA) | |
19529 | fputs ("\n\tXPA ASE", stdout); | |
19530 | if (mask & AFL_ASE_MIPS16E2) | |
19531 | fputs ("\n\tMIPS16e2 ASE", stdout); | |
19532 | if (mask & AFL_ASE_CRC) | |
19533 | fputs ("\n\tCRC ASE", stdout); | |
19534 | if (mask & AFL_ASE_GINV) | |
19535 | fputs ("\n\tGINV ASE", stdout); | |
19536 | if (mask & AFL_ASE_LOONGSON_MMI) | |
19537 | fputs ("\n\tLoongson MMI ASE", stdout); | |
19538 | if (mask & AFL_ASE_LOONGSON_CAM) | |
19539 | fputs ("\n\tLoongson CAM ASE", stdout); | |
19540 | if (mask & AFL_ASE_LOONGSON_EXT) | |
19541 | fputs ("\n\tLoongson EXT ASE", stdout); | |
19542 | if (mask & AFL_ASE_LOONGSON_EXT2) | |
19543 | fputs ("\n\tLoongson EXT2 ASE", stdout); | |
19544 | if (mask == 0) | |
19545 | fprintf (stdout, "\n\t%s", _("None")); | |
19546 | else if ((mask & ~AFL_ASE_MASK) != 0) | |
19547 | fprintf (stdout, "\n\t%s (%x)", _("Unknown"), mask & ~AFL_ASE_MASK); | |
19548 | } | |
19549 | ||
19550 | static void | |
19551 | print_mips_isa_ext (unsigned int isa_ext) | |
19552 | { | |
19553 | switch (isa_ext) | |
19554 | { | |
19555 | case 0: | |
19556 | fputs (_("None"), stdout); | |
19557 | break; | |
19558 | case AFL_EXT_XLR: | |
19559 | fputs ("RMI XLR", stdout); | |
19560 | break; | |
19561 | case AFL_EXT_OCTEON3: | |
19562 | fputs ("Cavium Networks Octeon3", stdout); | |
19563 | break; | |
19564 | case AFL_EXT_OCTEON2: | |
19565 | fputs ("Cavium Networks Octeon2", stdout); | |
19566 | break; | |
19567 | case AFL_EXT_OCTEONP: | |
19568 | fputs ("Cavium Networks OcteonP", stdout); | |
19569 | break; | |
19570 | case AFL_EXT_OCTEON: | |
19571 | fputs ("Cavium Networks Octeon", stdout); | |
19572 | break; | |
19573 | case AFL_EXT_5900: | |
19574 | fputs ("Toshiba R5900", stdout); | |
19575 | break; | |
19576 | case AFL_EXT_4650: | |
19577 | fputs ("MIPS R4650", stdout); | |
19578 | break; | |
19579 | case AFL_EXT_4010: | |
19580 | fputs ("LSI R4010", stdout); | |
19581 | break; | |
19582 | case AFL_EXT_4100: | |
19583 | fputs ("NEC VR4100", stdout); | |
19584 | break; | |
19585 | case AFL_EXT_3900: | |
19586 | fputs ("Toshiba R3900", stdout); | |
19587 | break; | |
19588 | case AFL_EXT_10000: | |
19589 | fputs ("MIPS R10000", stdout); | |
19590 | break; | |
19591 | case AFL_EXT_SB1: | |
19592 | fputs ("Broadcom SB-1", stdout); | |
19593 | break; | |
19594 | case AFL_EXT_4111: | |
19595 | fputs ("NEC VR4111/VR4181", stdout); | |
19596 | break; | |
19597 | case AFL_EXT_4120: | |
19598 | fputs ("NEC VR4120", stdout); | |
19599 | break; | |
19600 | case AFL_EXT_5400: | |
19601 | fputs ("NEC VR5400", stdout); | |
19602 | break; | |
19603 | case AFL_EXT_5500: | |
19604 | fputs ("NEC VR5500", stdout); | |
19605 | break; | |
19606 | case AFL_EXT_LOONGSON_2E: | |
19607 | fputs ("ST Microelectronics Loongson 2E", stdout); | |
19608 | break; | |
19609 | case AFL_EXT_LOONGSON_2F: | |
19610 | fputs ("ST Microelectronics Loongson 2F", stdout); | |
19611 | break; | |
19612 | case AFL_EXT_INTERAPTIV_MR2: | |
19613 | fputs ("Imagination interAptiv MR2", stdout); | |
19614 | break; | |
19615 | default: | |
19616 | fprintf (stdout, "%s (%d)", _("Unknown"), isa_ext); | |
19617 | } | |
19618 | } | |
19619 | ||
19620 | static signed int | |
19621 | get_mips_reg_size (int reg_size) | |
19622 | { | |
19623 | return (reg_size == AFL_REG_NONE) ? 0 | |
19624 | : (reg_size == AFL_REG_32) ? 32 | |
19625 | : (reg_size == AFL_REG_64) ? 64 | |
19626 | : (reg_size == AFL_REG_128) ? 128 | |
19627 | : -1; | |
19628 | } | |
19629 | ||
19630 | static bool | |
19631 | process_mips_specific (Filedata * filedata) | |
19632 | { | |
19633 | Elf_Internal_Dyn * entry; | |
19634 | Elf_Internal_Shdr *sect = NULL; | |
19635 | size_t liblist_offset = 0; | |
19636 | size_t liblistno = 0; | |
19637 | size_t conflictsno = 0; | |
19638 | size_t options_offset = 0; | |
19639 | size_t conflicts_offset = 0; | |
19640 | size_t pltrelsz = 0; | |
19641 | size_t pltrel = 0; | |
19642 | uint64_t pltgot = 0; | |
19643 | uint64_t mips_pltgot = 0; | |
19644 | uint64_t jmprel = 0; | |
19645 | uint64_t local_gotno = 0; | |
19646 | uint64_t gotsym = 0; | |
19647 | uint64_t symtabno = 0; | |
19648 | bool res = true; | |
19649 | ||
19650 | if (! process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL, | |
19651 | display_mips_gnu_attribute)) | |
19652 | res = false; | |
19653 | ||
19654 | sect = find_section (filedata, ".MIPS.abiflags"); | |
19655 | ||
19656 | if (sect != NULL) | |
19657 | { | |
19658 | Elf_External_ABIFlags_v0 *abiflags_ext; | |
19659 | Elf_Internal_ABIFlags_v0 abiflags_in; | |
19660 | ||
19661 | if (sizeof (Elf_External_ABIFlags_v0) != sect->sh_size) | |
19662 | { | |
19663 | error (_("Corrupt MIPS ABI Flags section.\n")); | |
19664 | res = false; | |
19665 | } | |
19666 | else | |
19667 | { | |
19668 | abiflags_ext = get_data (NULL, filedata, sect->sh_offset, 1, | |
19669 | sect->sh_size, _("MIPS ABI Flags section")); | |
19670 | if (abiflags_ext) | |
19671 | { | |
19672 | abiflags_in.version = BYTE_GET (abiflags_ext->version); | |
19673 | abiflags_in.isa_level = BYTE_GET (abiflags_ext->isa_level); | |
19674 | abiflags_in.isa_rev = BYTE_GET (abiflags_ext->isa_rev); | |
19675 | abiflags_in.gpr_size = BYTE_GET (abiflags_ext->gpr_size); | |
19676 | abiflags_in.cpr1_size = BYTE_GET (abiflags_ext->cpr1_size); | |
19677 | abiflags_in.cpr2_size = BYTE_GET (abiflags_ext->cpr2_size); | |
19678 | abiflags_in.fp_abi = BYTE_GET (abiflags_ext->fp_abi); | |
19679 | abiflags_in.isa_ext = BYTE_GET (abiflags_ext->isa_ext); | |
19680 | abiflags_in.ases = BYTE_GET (abiflags_ext->ases); | |
19681 | abiflags_in.flags1 = BYTE_GET (abiflags_ext->flags1); | |
19682 | abiflags_in.flags2 = BYTE_GET (abiflags_ext->flags2); | |
19683 | ||
19684 | printf ("\nMIPS ABI Flags Version: %d\n", abiflags_in.version); | |
19685 | printf ("\nISA: MIPS%d", abiflags_in.isa_level); | |
19686 | if (abiflags_in.isa_rev > 1) | |
19687 | printf ("r%d", abiflags_in.isa_rev); | |
19688 | printf ("\nGPR size: %d", | |
19689 | get_mips_reg_size (abiflags_in.gpr_size)); | |
19690 | printf ("\nCPR1 size: %d", | |
19691 | get_mips_reg_size (abiflags_in.cpr1_size)); | |
19692 | printf ("\nCPR2 size: %d", | |
19693 | get_mips_reg_size (abiflags_in.cpr2_size)); | |
19694 | fputs ("\nFP ABI: ", stdout); | |
19695 | print_mips_fp_abi_value (abiflags_in.fp_abi); | |
19696 | fputs ("ISA Extension: ", stdout); | |
19697 | print_mips_isa_ext (abiflags_in.isa_ext); | |
19698 | fputs ("\nASEs:", stdout); | |
19699 | print_mips_ases (abiflags_in.ases); | |
19700 | printf ("\nFLAGS 1: %8.8lx", abiflags_in.flags1); | |
19701 | printf ("\nFLAGS 2: %8.8lx", abiflags_in.flags2); | |
19702 | fputc ('\n', stdout); | |
19703 | free (abiflags_ext); | |
19704 | } | |
19705 | } | |
19706 | } | |
19707 | ||
19708 | /* We have a lot of special sections. Thanks SGI! */ | |
19709 | if (filedata->dynamic_section == NULL) | |
19710 | { | |
19711 | /* No dynamic information available. See if there is static GOT. */ | |
19712 | sect = find_section (filedata, ".got"); | |
19713 | if (sect != NULL) | |
19714 | { | |
19715 | unsigned char *data_end; | |
19716 | unsigned char *data; | |
19717 | uint64_t ent, end; | |
19718 | int addr_size; | |
19719 | ||
19720 | pltgot = sect->sh_addr; | |
19721 | ||
19722 | ent = pltgot; | |
19723 | addr_size = (is_32bit_elf ? 4 : 8); | |
19724 | end = pltgot + sect->sh_size; | |
19725 | ||
19726 | data = (unsigned char *) get_data (NULL, filedata, sect->sh_offset, | |
19727 | end - pltgot, 1, | |
19728 | _("Global Offset Table data")); | |
19729 | /* PR 12855: Null data is handled gracefully throughout. */ | |
19730 | data_end = data + (end - pltgot); | |
19731 | ||
19732 | printf (_("\nStatic GOT:\n")); | |
19733 | printf (_(" Canonical gp value: ")); | |
19734 | print_vma (ent + 0x7ff0, LONG_HEX); | |
19735 | printf ("\n\n"); | |
19736 | ||
19737 | /* In a dynamic binary GOT[0] is reserved for the dynamic | |
19738 | loader to store the lazy resolver pointer, however in | |
19739 | a static binary it may well have been omitted and GOT | |
19740 | reduced to a table of addresses. | |
19741 | PR 21344: Check for the entry being fully available | |
19742 | before fetching it. */ | |
19743 | if (data | |
19744 | && data + ent - pltgot + addr_size <= data_end | |
19745 | && byte_get (data + ent - pltgot, addr_size) == 0) | |
19746 | { | |
19747 | printf (_(" Reserved entries:\n")); | |
19748 | printf (_(" %*s %10s %*s\n"), | |
19749 | addr_size * 2, _("Address"), _("Access"), | |
19750 | addr_size * 2, _("Value")); | |
19751 | ent = print_mips_got_entry (data, pltgot, ent, data_end); | |
19752 | printf ("\n"); | |
19753 | if (ent == (uint64_t) -1) | |
19754 | goto sgot_print_fail; | |
19755 | ||
19756 | /* Check for the MSB of GOT[1] being set, identifying a | |
19757 | GNU object. This entry will be used by some runtime | |
19758 | loaders, to store the module pointer. Otherwise this | |
19759 | is an ordinary local entry. | |
19760 | PR 21344: Check for the entry being fully available | |
19761 | before fetching it. */ | |
19762 | if (data | |
19763 | && data + ent - pltgot + addr_size <= data_end | |
19764 | && (byte_get (data + ent - pltgot, addr_size) | |
19765 | >> (addr_size * 8 - 1)) != 0) | |
19766 | { | |
19767 | ent = print_mips_got_entry (data, pltgot, ent, data_end); | |
19768 | printf ("\n"); | |
19769 | if (ent == (uint64_t) -1) | |
19770 | goto sgot_print_fail; | |
19771 | } | |
19772 | printf ("\n"); | |
19773 | } | |
19774 | ||
19775 | if (data != NULL && ent < end) | |
19776 | { | |
19777 | printf (_(" Local entries:\n")); | |
19778 | printf (" %*s %10s %*s\n", | |
19779 | addr_size * 2, _("Address"), _("Access"), | |
19780 | addr_size * 2, _("Value")); | |
19781 | while (ent < end) | |
19782 | { | |
19783 | ent = print_mips_got_entry (data, pltgot, ent, data_end); | |
19784 | printf ("\n"); | |
19785 | if (ent == (uint64_t) -1) | |
19786 | goto sgot_print_fail; | |
19787 | } | |
19788 | printf ("\n"); | |
19789 | } | |
19790 | ||
19791 | sgot_print_fail: | |
19792 | free (data); | |
19793 | } | |
19794 | return res; | |
19795 | } | |
19796 | ||
19797 | for (entry = filedata->dynamic_section; | |
19798 | /* PR 17531 file: 012-50589-0.004. */ | |
19799 | (entry < filedata->dynamic_section + filedata->dynamic_nent | |
19800 | && entry->d_tag != DT_NULL); | |
19801 | ++entry) | |
19802 | switch (entry->d_tag) | |
19803 | { | |
19804 | case DT_MIPS_LIBLIST: | |
19805 | liblist_offset | |
19806 | = offset_from_vma (filedata, entry->d_un.d_val, | |
19807 | liblistno * sizeof (Elf32_External_Lib)); | |
19808 | break; | |
19809 | case DT_MIPS_LIBLISTNO: | |
19810 | liblistno = entry->d_un.d_val; | |
19811 | break; | |
19812 | case DT_MIPS_OPTIONS: | |
19813 | options_offset = offset_from_vma (filedata, entry->d_un.d_val, 0); | |
19814 | break; | |
19815 | case DT_MIPS_CONFLICT: | |
19816 | conflicts_offset | |
19817 | = offset_from_vma (filedata, entry->d_un.d_val, | |
19818 | conflictsno * sizeof (Elf32_External_Conflict)); | |
19819 | break; | |
19820 | case DT_MIPS_CONFLICTNO: | |
19821 | conflictsno = entry->d_un.d_val; | |
19822 | break; | |
19823 | case DT_PLTGOT: | |
19824 | pltgot = entry->d_un.d_ptr; | |
19825 | break; | |
19826 | case DT_MIPS_LOCAL_GOTNO: | |
19827 | local_gotno = entry->d_un.d_val; | |
19828 | break; | |
19829 | case DT_MIPS_GOTSYM: | |
19830 | gotsym = entry->d_un.d_val; | |
19831 | break; | |
19832 | case DT_MIPS_SYMTABNO: | |
19833 | symtabno = entry->d_un.d_val; | |
19834 | break; | |
19835 | case DT_MIPS_PLTGOT: | |
19836 | mips_pltgot = entry->d_un.d_ptr; | |
19837 | break; | |
19838 | case DT_PLTREL: | |
19839 | pltrel = entry->d_un.d_val; | |
19840 | break; | |
19841 | case DT_PLTRELSZ: | |
19842 | pltrelsz = entry->d_un.d_val; | |
19843 | break; | |
19844 | case DT_JMPREL: | |
19845 | jmprel = entry->d_un.d_ptr; | |
19846 | break; | |
19847 | default: | |
19848 | break; | |
19849 | } | |
19850 | ||
19851 | if (liblist_offset != 0 && liblistno != 0 && do_dynamic) | |
19852 | { | |
19853 | Elf32_External_Lib * elib; | |
19854 | size_t cnt; | |
19855 | ||
19856 | elib = (Elf32_External_Lib *) get_data (NULL, filedata, liblist_offset, | |
19857 | sizeof (Elf32_External_Lib), | |
19858 | liblistno, | |
19859 | _("liblist section data")); | |
19860 | if (elib) | |
19861 | { | |
19862 | printf (ngettext ("\nSection '.liblist' contains %zu entry:\n", | |
19863 | "\nSection '.liblist' contains %zu entries:\n", | |
19864 | liblistno), | |
19865 | liblistno); | |
19866 | fputs (_(" Library Time Stamp Checksum Version Flags\n"), | |
19867 | stdout); | |
19868 | ||
19869 | for (cnt = 0; cnt < liblistno; ++cnt) | |
19870 | { | |
19871 | Elf32_Lib liblist; | |
19872 | time_t atime; | |
19873 | char timebuf[128]; | |
19874 | struct tm * tmp; | |
19875 | ||
19876 | liblist.l_name = BYTE_GET (elib[cnt].l_name); | |
19877 | atime = BYTE_GET (elib[cnt].l_time_stamp); | |
19878 | liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum); | |
19879 | liblist.l_version = BYTE_GET (elib[cnt].l_version); | |
19880 | liblist.l_flags = BYTE_GET (elib[cnt].l_flags); | |
19881 | ||
19882 | tmp = gmtime (&atime); | |
19883 | snprintf (timebuf, sizeof (timebuf), | |
19884 | "%04u-%02u-%02uT%02u:%02u:%02u", | |
19885 | tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday, | |
19886 | tmp->tm_hour, tmp->tm_min, tmp->tm_sec); | |
19887 | ||
19888 | printf ("%3zu: ", cnt); | |
19889 | if (valid_dynamic_name (filedata, liblist.l_name)) | |
19890 | print_symbol_name (20, get_dynamic_name (filedata, liblist.l_name)); | |
19891 | else | |
19892 | printf (_("<corrupt: %9ld>"), liblist.l_name); | |
19893 | printf (" %s %#10lx %-7ld", timebuf, liblist.l_checksum, | |
19894 | liblist.l_version); | |
19895 | ||
19896 | if (liblist.l_flags == 0) | |
19897 | puts (_(" NONE")); | |
19898 | else | |
19899 | { | |
19900 | static const struct | |
19901 | { | |
19902 | const char * name; | |
19903 | int bit; | |
19904 | } | |
19905 | l_flags_vals[] = | |
19906 | { | |
19907 | { " EXACT_MATCH", LL_EXACT_MATCH }, | |
19908 | { " IGNORE_INT_VER", LL_IGNORE_INT_VER }, | |
19909 | { " REQUIRE_MINOR", LL_REQUIRE_MINOR }, | |
19910 | { " EXPORTS", LL_EXPORTS }, | |
19911 | { " DELAY_LOAD", LL_DELAY_LOAD }, | |
19912 | { " DELTA", LL_DELTA } | |
19913 | }; | |
19914 | int flags = liblist.l_flags; | |
19915 | size_t fcnt; | |
19916 | ||
19917 | for (fcnt = 0; fcnt < ARRAY_SIZE (l_flags_vals); ++fcnt) | |
19918 | if ((flags & l_flags_vals[fcnt].bit) != 0) | |
19919 | { | |
19920 | fputs (l_flags_vals[fcnt].name, stdout); | |
19921 | flags ^= l_flags_vals[fcnt].bit; | |
19922 | } | |
19923 | if (flags != 0) | |
19924 | printf (" %#x", (unsigned int) flags); | |
19925 | ||
19926 | puts (""); | |
19927 | } | |
19928 | } | |
19929 | ||
19930 | free (elib); | |
19931 | } | |
19932 | else | |
19933 | res = false; | |
19934 | } | |
19935 | ||
19936 | if (options_offset != 0) | |
19937 | { | |
19938 | Elf_External_Options * eopt; | |
19939 | size_t offset; | |
19940 | int cnt; | |
19941 | ||
19942 | /* Find the section header so that we get the size. */ | |
19943 | sect = find_section_by_type (filedata, SHT_MIPS_OPTIONS); | |
19944 | /* PR 17533 file: 012-277276-0.004. */ | |
19945 | if (sect == NULL) | |
19946 | { | |
19947 | error (_("No MIPS_OPTIONS header found\n")); | |
19948 | return false; | |
19949 | } | |
19950 | /* PR 24243 */ | |
19951 | if (sect->sh_size < sizeof (* eopt)) | |
19952 | { | |
19953 | error (_("The MIPS options section is too small.\n")); | |
19954 | return false; | |
19955 | } | |
19956 | ||
19957 | eopt = (Elf_External_Options *) get_data (NULL, filedata, options_offset, 1, | |
19958 | sect->sh_size, _("options")); | |
19959 | if (eopt) | |
19960 | { | |
19961 | Elf_Internal_Options option; | |
19962 | ||
19963 | offset = cnt = 0; | |
19964 | while (offset <= sect->sh_size - sizeof (* eopt)) | |
19965 | { | |
19966 | Elf_External_Options * eoption; | |
19967 | unsigned int optsize; | |
19968 | ||
19969 | eoption = (Elf_External_Options *) ((char *) eopt + offset); | |
19970 | ||
19971 | optsize = BYTE_GET (eoption->size); | |
19972 | ||
19973 | /* PR 17531: file: ffa0fa3b. */ | |
19974 | if (optsize < sizeof (* eopt) | |
19975 | || optsize > sect->sh_size - offset) | |
19976 | { | |
19977 | error (_("Invalid size (%u) for MIPS option\n"), | |
19978 | optsize); | |
19979 | free (eopt); | |
19980 | return false; | |
19981 | } | |
19982 | offset += optsize; | |
19983 | ++cnt; | |
19984 | } | |
19985 | ||
19986 | printf (ngettext ("\nSection '%s' contains %d entry:\n", | |
19987 | "\nSection '%s' contains %d entries:\n", | |
19988 | cnt), | |
19989 | printable_section_name (filedata, sect), cnt); | |
19990 | ||
19991 | offset = 0; | |
19992 | while (cnt-- > 0) | |
19993 | { | |
19994 | size_t len; | |
19995 | Elf_External_Options * eoption; | |
19996 | ||
19997 | eoption = (Elf_External_Options *) ((char *) eopt + offset); | |
19998 | ||
19999 | option.kind = BYTE_GET (eoption->kind); | |
20000 | option.size = BYTE_GET (eoption->size); | |
20001 | option.section = BYTE_GET (eoption->section); | |
20002 | option.info = BYTE_GET (eoption->info); | |
20003 | ||
20004 | switch (option.kind) | |
20005 | { | |
20006 | case ODK_NULL: | |
20007 | /* This shouldn't happen. */ | |
20008 | printf (" NULL %" PRId16 " %" PRIx32, | |
20009 | option.section, option.info); | |
20010 | break; | |
20011 | ||
20012 | case ODK_REGINFO: | |
20013 | printf (" REGINFO "); | |
20014 | if (filedata->file_header.e_machine == EM_MIPS) | |
20015 | { | |
20016 | Elf32_External_RegInfo * ereg; | |
20017 | Elf32_RegInfo reginfo; | |
20018 | ||
20019 | /* 32bit form. */ | |
20020 | if (option.size < (sizeof (Elf_External_Options) | |
20021 | + sizeof (Elf32_External_RegInfo))) | |
20022 | { | |
20023 | printf (_("<corrupt>\n")); | |
20024 | error (_("Truncated MIPS REGINFO option\n")); | |
20025 | cnt = 0; | |
20026 | break; | |
20027 | } | |
20028 | ||
20029 | ereg = (Elf32_External_RegInfo *) (eoption + 1); | |
20030 | ||
20031 | reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask); | |
20032 | reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]); | |
20033 | reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]); | |
20034 | reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]); | |
20035 | reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]); | |
20036 | reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value); | |
20037 | ||
20038 | printf ("GPR %08" PRIx32 " GP 0x%" PRIx32 "\n", | |
20039 | reginfo.ri_gprmask, reginfo.ri_gp_value); | |
20040 | printf (" " | |
20041 | " CPR0 %08" PRIx32 " CPR1 %08" PRIx32 | |
20042 | " CPR2 %08" PRIx32 " CPR3 %08" PRIx32 "\n", | |
20043 | reginfo.ri_cprmask[0], reginfo.ri_cprmask[1], | |
20044 | reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]); | |
20045 | } | |
20046 | else | |
20047 | { | |
20048 | /* 64 bit form. */ | |
20049 | Elf64_External_RegInfo * ereg; | |
20050 | Elf64_Internal_RegInfo reginfo; | |
20051 | ||
20052 | if (option.size < (sizeof (Elf_External_Options) | |
20053 | + sizeof (Elf64_External_RegInfo))) | |
20054 | { | |
20055 | printf (_("<corrupt>\n")); | |
20056 | error (_("Truncated MIPS REGINFO option\n")); | |
20057 | cnt = 0; | |
20058 | break; | |
20059 | } | |
20060 | ||
20061 | ereg = (Elf64_External_RegInfo *) (eoption + 1); | |
20062 | reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask); | |
20063 | reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]); | |
20064 | reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]); | |
20065 | reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]); | |
20066 | reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]); | |
20067 | reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value); | |
20068 | ||
20069 | printf ("GPR %08" PRIx32 " GP 0x%" PRIx64 "\n", | |
20070 | reginfo.ri_gprmask, reginfo.ri_gp_value); | |
20071 | printf (" " | |
20072 | " CPR0 %08" PRIx32 " CPR1 %08" PRIx32 | |
20073 | " CPR2 %08" PRIx32 " CPR3 %08" PRIx32 "\n", | |
20074 | reginfo.ri_cprmask[0], reginfo.ri_cprmask[1], | |
20075 | reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]); | |
20076 | } | |
20077 | offset += option.size; | |
20078 | continue; | |
20079 | ||
20080 | case ODK_EXCEPTIONS: | |
20081 | fputs (" EXCEPTIONS fpe_min(", stdout); | |
20082 | process_mips_fpe_exception (option.info & OEX_FPU_MIN); | |
20083 | fputs (") fpe_max(", stdout); | |
20084 | process_mips_fpe_exception ((option.info & OEX_FPU_MAX) >> 8); | |
20085 | fputs (")", stdout); | |
20086 | ||
20087 | if (option.info & OEX_PAGE0) | |
20088 | fputs (" PAGE0", stdout); | |
20089 | if (option.info & OEX_SMM) | |
20090 | fputs (" SMM", stdout); | |
20091 | if (option.info & OEX_FPDBUG) | |
20092 | fputs (" FPDBUG", stdout); | |
20093 | if (option.info & OEX_DISMISS) | |
20094 | fputs (" DISMISS", stdout); | |
20095 | break; | |
20096 | ||
20097 | case ODK_PAD: | |
20098 | fputs (" PAD ", stdout); | |
20099 | if (option.info & OPAD_PREFIX) | |
20100 | fputs (" PREFIX", stdout); | |
20101 | if (option.info & OPAD_POSTFIX) | |
20102 | fputs (" POSTFIX", stdout); | |
20103 | if (option.info & OPAD_SYMBOL) | |
20104 | fputs (" SYMBOL", stdout); | |
20105 | break; | |
20106 | ||
20107 | case ODK_HWPATCH: | |
20108 | fputs (" HWPATCH ", stdout); | |
20109 | if (option.info & OHW_R4KEOP) | |
20110 | fputs (" R4KEOP", stdout); | |
20111 | if (option.info & OHW_R8KPFETCH) | |
20112 | fputs (" R8KPFETCH", stdout); | |
20113 | if (option.info & OHW_R5KEOP) | |
20114 | fputs (" R5KEOP", stdout); | |
20115 | if (option.info & OHW_R5KCVTL) | |
20116 | fputs (" R5KCVTL", stdout); | |
20117 | break; | |
20118 | ||
20119 | case ODK_FILL: | |
20120 | fputs (" FILL ", stdout); | |
20121 | /* XXX Print content of info word? */ | |
20122 | break; | |
20123 | ||
20124 | case ODK_TAGS: | |
20125 | fputs (" TAGS ", stdout); | |
20126 | /* XXX Print content of info word? */ | |
20127 | break; | |
20128 | ||
20129 | case ODK_HWAND: | |
20130 | fputs (" HWAND ", stdout); | |
20131 | if (option.info & OHWA0_R4KEOP_CHECKED) | |
20132 | fputs (" R4KEOP_CHECKED", stdout); | |
20133 | if (option.info & OHWA0_R4KEOP_CLEAN) | |
20134 | fputs (" R4KEOP_CLEAN", stdout); | |
20135 | break; | |
20136 | ||
20137 | case ODK_HWOR: | |
20138 | fputs (" HWOR ", stdout); | |
20139 | if (option.info & OHWA0_R4KEOP_CHECKED) | |
20140 | fputs (" R4KEOP_CHECKED", stdout); | |
20141 | if (option.info & OHWA0_R4KEOP_CLEAN) | |
20142 | fputs (" R4KEOP_CLEAN", stdout); | |
20143 | break; | |
20144 | ||
20145 | case ODK_GP_GROUP: | |
20146 | printf (" GP_GROUP %#06x self-contained %#06x", | |
20147 | option.info & OGP_GROUP, | |
20148 | (option.info & OGP_SELF) >> 16); | |
20149 | break; | |
20150 | ||
20151 | case ODK_IDENT: | |
20152 | printf (" IDENT %#06x self-contained %#06x", | |
20153 | option.info & OGP_GROUP, | |
20154 | (option.info & OGP_SELF) >> 16); | |
20155 | break; | |
20156 | ||
20157 | default: | |
20158 | /* This shouldn't happen. */ | |
20159 | printf (" %3d ??? %" PRId16 " %" PRIx32, | |
20160 | option.kind, option.section, option.info); | |
20161 | break; | |
20162 | } | |
20163 | ||
20164 | len = sizeof (* eopt); | |
20165 | while (len < option.size) | |
20166 | { | |
20167 | unsigned char datum = *((unsigned char *) eoption + len); | |
20168 | ||
20169 | if (ISPRINT (datum)) | |
20170 | printf ("%c", datum); | |
20171 | else | |
20172 | printf ("\\%03o", datum); | |
20173 | len ++; | |
20174 | } | |
20175 | fputs ("\n", stdout); | |
20176 | ||
20177 | offset += option.size; | |
20178 | } | |
20179 | free (eopt); | |
20180 | } | |
20181 | else | |
20182 | res = false; | |
20183 | } | |
20184 | ||
20185 | if (conflicts_offset != 0 && conflictsno != 0) | |
20186 | { | |
20187 | Elf32_Conflict * iconf; | |
20188 | size_t cnt; | |
20189 | ||
20190 | if (filedata->dynamic_symbols == NULL) | |
20191 | { | |
20192 | error (_("conflict list found without a dynamic symbol table\n")); | |
20193 | return false; | |
20194 | } | |
20195 | ||
20196 | /* PR 21345 - print a slightly more helpful error message | |
20197 | if we are sure that the cmalloc will fail. */ | |
20198 | if (conflictsno > filedata->file_size / sizeof (* iconf)) | |
20199 | { | |
20200 | error (_("Overlarge number of conflicts detected: %zx\n"), | |
20201 | conflictsno); | |
20202 | return false; | |
20203 | } | |
20204 | ||
20205 | iconf = (Elf32_Conflict *) cmalloc (conflictsno, sizeof (* iconf)); | |
20206 | if (iconf == NULL) | |
20207 | { | |
20208 | error (_("Out of memory allocating space for dynamic conflicts\n")); | |
20209 | return false; | |
20210 | } | |
20211 | ||
20212 | if (is_32bit_elf) | |
20213 | { | |
20214 | Elf32_External_Conflict * econf32; | |
20215 | ||
20216 | econf32 = (Elf32_External_Conflict *) | |
20217 | get_data (NULL, filedata, conflicts_offset, | |
20218 | sizeof (*econf32), conflictsno, _("conflict")); | |
20219 | if (!econf32) | |
20220 | { | |
20221 | free (iconf); | |
20222 | return false; | |
20223 | } | |
20224 | ||
20225 | for (cnt = 0; cnt < conflictsno; ++cnt) | |
20226 | iconf[cnt] = BYTE_GET (econf32[cnt]); | |
20227 | ||
20228 | free (econf32); | |
20229 | } | |
20230 | else | |
20231 | { | |
20232 | Elf64_External_Conflict * econf64; | |
20233 | ||
20234 | econf64 = (Elf64_External_Conflict *) | |
20235 | get_data (NULL, filedata, conflicts_offset, | |
20236 | sizeof (*econf64), conflictsno, _("conflict")); | |
20237 | if (!econf64) | |
20238 | { | |
20239 | free (iconf); | |
20240 | return false; | |
20241 | } | |
20242 | ||
20243 | for (cnt = 0; cnt < conflictsno; ++cnt) | |
20244 | iconf[cnt] = BYTE_GET (econf64[cnt]); | |
20245 | ||
20246 | free (econf64); | |
20247 | } | |
20248 | ||
20249 | printf (ngettext ("\nSection '.conflict' contains %zu entry:\n", | |
20250 | "\nSection '.conflict' contains %zu entries:\n", | |
20251 | conflictsno), | |
20252 | conflictsno); | |
20253 | puts (_(" Num: Index Value Name")); | |
20254 | ||
20255 | for (cnt = 0; cnt < conflictsno; ++cnt) | |
20256 | { | |
20257 | printf ("%5zu: %8lu ", cnt, iconf[cnt]); | |
20258 | ||
20259 | if (iconf[cnt] >= filedata->num_dynamic_syms) | |
20260 | printf (_("<corrupt symbol index>")); | |
20261 | else | |
20262 | { | |
20263 | Elf_Internal_Sym * psym; | |
20264 | ||
20265 | psym = & filedata->dynamic_symbols[iconf[cnt]]; | |
20266 | print_vma (psym->st_value, FULL_HEX); | |
20267 | putchar (' '); | |
20268 | if (valid_dynamic_name (filedata, psym->st_name)) | |
20269 | print_symbol_name (25, get_dynamic_name (filedata, psym->st_name)); | |
20270 | else | |
20271 | printf (_("<corrupt: %14ld>"), psym->st_name); | |
20272 | } | |
20273 | putchar ('\n'); | |
20274 | } | |
20275 | ||
20276 | free (iconf); | |
20277 | } | |
20278 | ||
20279 | if (pltgot != 0 && local_gotno != 0) | |
20280 | { | |
20281 | uint64_t ent, local_end, global_end; | |
20282 | size_t i, offset; | |
20283 | unsigned char * data; | |
20284 | unsigned char * data_end; | |
20285 | int addr_size; | |
20286 | ||
20287 | ent = pltgot; | |
20288 | addr_size = (is_32bit_elf ? 4 : 8); | |
20289 | local_end = pltgot + local_gotno * addr_size; | |
20290 | ||
20291 | /* PR binutils/17533 file: 012-111227-0.004 */ | |
20292 | if (symtabno < gotsym) | |
20293 | { | |
20294 | error (_("The GOT symbol offset (%" PRIu64 | |
20295 | ") is greater than the symbol table size (%" PRIu64 ")\n"), | |
20296 | gotsym, symtabno); | |
20297 | return false; | |
20298 | } | |
20299 | ||
20300 | global_end = local_end + (symtabno - gotsym) * addr_size; | |
20301 | /* PR 17531: file: 54c91a34. */ | |
20302 | if (global_end < local_end) | |
20303 | { | |
20304 | error (_("Too many GOT symbols: %" PRIu64 "\n"), symtabno); | |
20305 | return false; | |
20306 | } | |
20307 | ||
20308 | offset = offset_from_vma (filedata, pltgot, global_end - pltgot); | |
20309 | data = (unsigned char *) get_data (NULL, filedata, offset, | |
20310 | global_end - pltgot, 1, | |
20311 | _("Global Offset Table data")); | |
20312 | /* PR 12855: Null data is handled gracefully throughout. */ | |
20313 | data_end = data + (global_end - pltgot); | |
20314 | ||
20315 | printf (_("\nPrimary GOT:\n")); | |
20316 | printf (_(" Canonical gp value: ")); | |
20317 | print_vma (pltgot + 0x7ff0, LONG_HEX); | |
20318 | printf ("\n\n"); | |
20319 | ||
20320 | printf (_(" Reserved entries:\n")); | |
20321 | printf (_(" %*s %10s %*s Purpose\n"), | |
20322 | addr_size * 2, _("Address"), _("Access"), | |
20323 | addr_size * 2, _("Initial")); | |
20324 | ent = print_mips_got_entry (data, pltgot, ent, data_end); | |
20325 | printf (_(" Lazy resolver\n")); | |
20326 | if (ent == (uint64_t) -1) | |
20327 | goto got_print_fail; | |
20328 | ||
20329 | /* Check for the MSB of GOT[1] being set, denoting a GNU object. | |
20330 | This entry will be used by some runtime loaders, to store the | |
20331 | module pointer. Otherwise this is an ordinary local entry. | |
20332 | PR 21344: Check for the entry being fully available before | |
20333 | fetching it. */ | |
20334 | if (data | |
20335 | && data + ent - pltgot + addr_size <= data_end | |
20336 | && (byte_get (data + ent - pltgot, addr_size) | |
20337 | >> (addr_size * 8 - 1)) != 0) | |
20338 | { | |
20339 | ent = print_mips_got_entry (data, pltgot, ent, data_end); | |
20340 | printf (_(" Module pointer (GNU extension)\n")); | |
20341 | if (ent == (uint64_t) -1) | |
20342 | goto got_print_fail; | |
20343 | } | |
20344 | printf ("\n"); | |
20345 | ||
20346 | if (data != NULL && ent < local_end) | |
20347 | { | |
20348 | printf (_(" Local entries:\n")); | |
20349 | printf (" %*s %10s %*s\n", | |
20350 | addr_size * 2, _("Address"), _("Access"), | |
20351 | addr_size * 2, _("Initial")); | |
20352 | while (ent < local_end) | |
20353 | { | |
20354 | ent = print_mips_got_entry (data, pltgot, ent, data_end); | |
20355 | printf ("\n"); | |
20356 | if (ent == (uint64_t) -1) | |
20357 | goto got_print_fail; | |
20358 | } | |
20359 | printf ("\n"); | |
20360 | } | |
20361 | ||
20362 | if (data != NULL && gotsym < symtabno) | |
20363 | { | |
20364 | int sym_width; | |
20365 | ||
20366 | printf (_(" Global entries:\n")); | |
20367 | printf (" %*s %10s %*s %*s %-7s %3s %s\n", | |
20368 | addr_size * 2, _("Address"), | |
20369 | _("Access"), | |
20370 | addr_size * 2, _("Initial"), | |
20371 | addr_size * 2, _("Sym.Val."), | |
20372 | _("Type"), | |
20373 | /* Note for translators: "Ndx" = abbreviated form of "Index". */ | |
20374 | _("Ndx"), _("Name")); | |
20375 | ||
20376 | sym_width = (is_32bit_elf ? 80 : 160) - 28 - addr_size * 6 - 1; | |
20377 | ||
20378 | for (i = gotsym; i < symtabno; i++) | |
20379 | { | |
20380 | ent = print_mips_got_entry (data, pltgot, ent, data_end); | |
20381 | printf (" "); | |
20382 | ||
20383 | if (filedata->dynamic_symbols == NULL) | |
20384 | printf (_("<no dynamic symbols>")); | |
20385 | else if (i < filedata->num_dynamic_syms) | |
20386 | { | |
20387 | Elf_Internal_Sym * psym = filedata->dynamic_symbols + i; | |
20388 | ||
20389 | print_vma (psym->st_value, LONG_HEX); | |
20390 | printf (" %-7s ", get_symbol_type (filedata, ELF_ST_TYPE (psym->st_info))); | |
20391 | ||
20392 | bool is_special; | |
20393 | const char * s = printable_section_name_from_index (filedata, psym->st_shndx, & is_special); | |
20394 | if (is_special) | |
20395 | printf ("%3s ", s); | |
20396 | else | |
20397 | printf ("%3u ", psym->st_shndx); | |
20398 | ||
20399 | if (valid_dynamic_name (filedata, psym->st_name)) | |
20400 | print_symbol_name (sym_width, | |
20401 | get_dynamic_name (filedata, psym->st_name)); | |
20402 | else | |
20403 | printf (_("<corrupt: %14ld>"), psym->st_name); | |
20404 | } | |
20405 | else | |
20406 | printf (_("<symbol index %zu exceeds number of dynamic symbols>"), | |
20407 | i); | |
20408 | ||
20409 | printf ("\n"); | |
20410 | if (ent == (uint64_t) -1) | |
20411 | break; | |
20412 | } | |
20413 | printf ("\n"); | |
20414 | } | |
20415 | ||
20416 | got_print_fail: | |
20417 | free (data); | |
20418 | } | |
20419 | ||
20420 | if (mips_pltgot != 0 && jmprel != 0 && pltrel != 0 && pltrelsz != 0) | |
20421 | { | |
20422 | uint64_t ent, end; | |
20423 | uint64_t offset, rel_offset; | |
20424 | uint64_t count, i; | |
20425 | unsigned char * data; | |
20426 | int addr_size, sym_width; | |
20427 | Elf_Internal_Rela * rels; | |
20428 | ||
20429 | rel_offset = offset_from_vma (filedata, jmprel, pltrelsz); | |
20430 | if (pltrel == DT_RELA) | |
20431 | { | |
20432 | if (!slurp_rela_relocs (filedata, rel_offset, pltrelsz, &rels, &count)) | |
20433 | return false; | |
20434 | } | |
20435 | else | |
20436 | { | |
20437 | if (!slurp_rel_relocs (filedata, rel_offset, pltrelsz, &rels, &count)) | |
20438 | return false; | |
20439 | } | |
20440 | ||
20441 | ent = mips_pltgot; | |
20442 | addr_size = (is_32bit_elf ? 4 : 8); | |
20443 | end = mips_pltgot + (2 + count) * addr_size; | |
20444 | ||
20445 | offset = offset_from_vma (filedata, mips_pltgot, end - mips_pltgot); | |
20446 | data = (unsigned char *) get_data (NULL, filedata, offset, end - mips_pltgot, | |
20447 | 1, _("Procedure Linkage Table data")); | |
20448 | if (data == NULL) | |
20449 | { | |
20450 | free (rels); | |
20451 | return false; | |
20452 | } | |
20453 | ||
20454 | printf ("\nPLT GOT:\n\n"); | |
20455 | printf (_(" Reserved entries:\n")); | |
20456 | printf (_(" %*s %*s Purpose\n"), | |
20457 | addr_size * 2, _("Address"), addr_size * 2, _("Initial")); | |
20458 | ent = print_mips_pltgot_entry (data, mips_pltgot, ent); | |
20459 | printf (_(" PLT lazy resolver\n")); | |
20460 | ent = print_mips_pltgot_entry (data, mips_pltgot, ent); | |
20461 | printf (_(" Module pointer\n")); | |
20462 | printf ("\n"); | |
20463 | ||
20464 | printf (_(" Entries:\n")); | |
20465 | printf (" %*s %*s %*s %-7s %3s %s\n", | |
20466 | addr_size * 2, _("Address"), | |
20467 | addr_size * 2, _("Initial"), | |
20468 | addr_size * 2, _("Sym.Val."), _("Type"), _("Ndx"), _("Name")); | |
20469 | sym_width = (is_32bit_elf ? 80 : 160) - 17 - addr_size * 6 - 1; | |
20470 | for (i = 0; i < count; i++) | |
20471 | { | |
20472 | uint64_t idx = get_reloc_symindex (rels[i].r_info); | |
20473 | ||
20474 | ent = print_mips_pltgot_entry (data, mips_pltgot, ent); | |
20475 | printf (" "); | |
20476 | ||
20477 | if (idx >= filedata->num_dynamic_syms) | |
20478 | printf (_("<corrupt symbol index: %" PRIu64 ">"), idx); | |
20479 | else | |
20480 | { | |
20481 | Elf_Internal_Sym * psym = filedata->dynamic_symbols + idx; | |
20482 | ||
20483 | print_vma (psym->st_value, LONG_HEX); | |
20484 | printf (" %-7s %3s ", | |
20485 | get_symbol_type (filedata, ELF_ST_TYPE (psym->st_info)), | |
20486 | printable_section_name_from_index (filedata, psym->st_shndx, NULL)); | |
20487 | if (valid_dynamic_name (filedata, psym->st_name)) | |
20488 | print_symbol_name (sym_width, | |
20489 | get_dynamic_name (filedata, psym->st_name)); | |
20490 | else | |
20491 | printf (_("<corrupt: %14ld>"), psym->st_name); | |
20492 | } | |
20493 | printf ("\n"); | |
20494 | } | |
20495 | printf ("\n"); | |
20496 | ||
20497 | free (data); | |
20498 | free (rels); | |
20499 | } | |
20500 | ||
20501 | return res; | |
20502 | } | |
20503 | ||
20504 | static bool | |
20505 | process_nds32_specific (Filedata * filedata) | |
20506 | { | |
20507 | Elf_Internal_Shdr *sect = NULL; | |
20508 | ||
20509 | sect = find_section (filedata, ".nds32_e_flags"); | |
20510 | if (sect != NULL && sect->sh_size >= 4) | |
20511 | { | |
20512 | unsigned char *buf; | |
20513 | unsigned int flag; | |
20514 | ||
20515 | printf ("\nNDS32 elf flags section:\n"); | |
20516 | buf = get_data (NULL, filedata, sect->sh_offset, 1, 4, | |
20517 | _("NDS32 elf flags section")); | |
20518 | ||
20519 | if (buf == NULL) | |
20520 | return false; | |
20521 | ||
20522 | flag = byte_get (buf, 4); | |
20523 | free (buf); | |
20524 | switch (flag & 0x3) | |
20525 | { | |
20526 | case 0: | |
20527 | printf ("(VEC_SIZE):\tNo entry.\n"); | |
20528 | break; | |
20529 | case 1: | |
20530 | printf ("(VEC_SIZE):\t4 bytes\n"); | |
20531 | break; | |
20532 | case 2: | |
20533 | printf ("(VEC_SIZE):\t16 bytes\n"); | |
20534 | break; | |
20535 | case 3: | |
20536 | printf ("(VEC_SIZE):\treserved\n"); | |
20537 | break; | |
20538 | } | |
20539 | } | |
20540 | ||
20541 | return true; | |
20542 | } | |
20543 | ||
20544 | static bool | |
20545 | process_gnu_liblist (Filedata * filedata) | |
20546 | { | |
20547 | Elf_Internal_Shdr * section; | |
20548 | Elf_Internal_Shdr * string_sec; | |
20549 | Elf32_External_Lib * elib; | |
20550 | char * strtab; | |
20551 | size_t strtab_size; | |
20552 | size_t cnt; | |
20553 | uint64_t num_liblist; | |
20554 | unsigned i; | |
20555 | bool res = true; | |
20556 | ||
20557 | if (! do_arch) | |
20558 | return true; | |
20559 | ||
20560 | for (i = 0, section = filedata->section_headers; | |
20561 | i < filedata->file_header.e_shnum; | |
20562 | i++, section++) | |
20563 | { | |
20564 | switch (section->sh_type) | |
20565 | { | |
20566 | case SHT_GNU_LIBLIST: | |
20567 | if (section->sh_link >= filedata->file_header.e_shnum) | |
20568 | break; | |
20569 | ||
20570 | elib = (Elf32_External_Lib *) | |
20571 | get_data (NULL, filedata, section->sh_offset, 1, section->sh_size, | |
20572 | _("liblist section data")); | |
20573 | ||
20574 | if (elib == NULL) | |
20575 | { | |
20576 | res = false; | |
20577 | break; | |
20578 | } | |
20579 | ||
20580 | string_sec = filedata->section_headers + section->sh_link; | |
20581 | strtab = (char *) get_data (NULL, filedata, string_sec->sh_offset, 1, | |
20582 | string_sec->sh_size, | |
20583 | _("liblist string table")); | |
20584 | if (strtab == NULL | |
20585 | || section->sh_entsize != sizeof (Elf32_External_Lib)) | |
20586 | { | |
20587 | free (elib); | |
20588 | free (strtab); | |
20589 | res = false; | |
20590 | break; | |
20591 | } | |
20592 | strtab_size = string_sec->sh_size; | |
20593 | ||
20594 | num_liblist = section->sh_size / sizeof (Elf32_External_Lib); | |
20595 | printf (ngettext ("\nLibrary list section '%s' contains %" PRIu64 | |
20596 | " entries:\n", | |
20597 | "\nLibrary list section '%s' contains %" PRIu64 | |
20598 | " entries:\n", | |
20599 | num_liblist), | |
20600 | printable_section_name (filedata, section), | |
20601 | num_liblist); | |
20602 | ||
20603 | puts (_(" Library Time Stamp Checksum Version Flags")); | |
20604 | ||
20605 | for (cnt = 0; cnt < section->sh_size / sizeof (Elf32_External_Lib); | |
20606 | ++cnt) | |
20607 | { | |
20608 | Elf32_Lib liblist; | |
20609 | time_t atime; | |
20610 | char timebuf[128]; | |
20611 | struct tm * tmp; | |
20612 | ||
20613 | liblist.l_name = BYTE_GET (elib[cnt].l_name); | |
20614 | atime = BYTE_GET (elib[cnt].l_time_stamp); | |
20615 | liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum); | |
20616 | liblist.l_version = BYTE_GET (elib[cnt].l_version); | |
20617 | liblist.l_flags = BYTE_GET (elib[cnt].l_flags); | |
20618 | ||
20619 | tmp = gmtime (&atime); | |
20620 | snprintf (timebuf, sizeof (timebuf), | |
20621 | "%04u-%02u-%02uT%02u:%02u:%02u", | |
20622 | tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday, | |
20623 | tmp->tm_hour, tmp->tm_min, tmp->tm_sec); | |
20624 | ||
20625 | printf ("%3zu: ", cnt); | |
20626 | if (do_wide) | |
20627 | printf ("%-20s", liblist.l_name < strtab_size | |
20628 | ? strtab + liblist.l_name : _("<corrupt>")); | |
20629 | else | |
20630 | printf ("%-20.20s", liblist.l_name < strtab_size | |
20631 | ? strtab + liblist.l_name : _("<corrupt>")); | |
20632 | printf (" %s %#010lx %-7ld %-7ld\n", timebuf, liblist.l_checksum, | |
20633 | liblist.l_version, liblist.l_flags); | |
20634 | } | |
20635 | ||
20636 | free (elib); | |
20637 | free (strtab); | |
20638 | } | |
20639 | } | |
20640 | ||
20641 | return res; | |
20642 | } | |
20643 | ||
20644 | static const char * | |
20645 | get_note_type (Filedata * filedata, unsigned e_type) | |
20646 | { | |
20647 | static char buff[64]; | |
20648 | ||
20649 | if (filedata->file_header.e_type == ET_CORE) | |
20650 | switch (e_type) | |
20651 | { | |
20652 | case NT_AUXV: | |
20653 | return _("NT_AUXV (auxiliary vector)"); | |
20654 | case NT_PRSTATUS: | |
20655 | return _("NT_PRSTATUS (prstatus structure)"); | |
20656 | case NT_FPREGSET: | |
20657 | return _("NT_FPREGSET (floating point registers)"); | |
20658 | case NT_PRPSINFO: | |
20659 | return _("NT_PRPSINFO (prpsinfo structure)"); | |
20660 | case NT_TASKSTRUCT: | |
20661 | return _("NT_TASKSTRUCT (task structure)"); | |
20662 | case NT_GDB_TDESC: | |
20663 | return _("NT_GDB_TDESC (GDB XML target description)"); | |
20664 | case NT_PRXFPREG: | |
20665 | return _("NT_PRXFPREG (user_xfpregs structure)"); | |
20666 | case NT_PPC_VMX: | |
20667 | return _("NT_PPC_VMX (ppc Altivec registers)"); | |
20668 | case NT_PPC_VSX: | |
20669 | return _("NT_PPC_VSX (ppc VSX registers)"); | |
20670 | case NT_PPC_TAR: | |
20671 | return _("NT_PPC_TAR (ppc TAR register)"); | |
20672 | case NT_PPC_PPR: | |
20673 | return _("NT_PPC_PPR (ppc PPR register)"); | |
20674 | case NT_PPC_DSCR: | |
20675 | return _("NT_PPC_DSCR (ppc DSCR register)"); | |
20676 | case NT_PPC_EBB: | |
20677 | return _("NT_PPC_EBB (ppc EBB registers)"); | |
20678 | case NT_PPC_PMU: | |
20679 | return _("NT_PPC_PMU (ppc PMU registers)"); | |
20680 | case NT_PPC_TM_CGPR: | |
20681 | return _("NT_PPC_TM_CGPR (ppc checkpointed GPR registers)"); | |
20682 | case NT_PPC_TM_CFPR: | |
20683 | return _("NT_PPC_TM_CFPR (ppc checkpointed floating point registers)"); | |
20684 | case NT_PPC_TM_CVMX: | |
20685 | return _("NT_PPC_TM_CVMX (ppc checkpointed Altivec registers)"); | |
20686 | case NT_PPC_TM_CVSX: | |
20687 | return _("NT_PPC_TM_CVSX (ppc checkpointed VSX registers)"); | |
20688 | case NT_PPC_TM_SPR: | |
20689 | return _("NT_PPC_TM_SPR (ppc TM special purpose registers)"); | |
20690 | case NT_PPC_TM_CTAR: | |
20691 | return _("NT_PPC_TM_CTAR (ppc checkpointed TAR register)"); | |
20692 | case NT_PPC_TM_CPPR: | |
20693 | return _("NT_PPC_TM_CPPR (ppc checkpointed PPR register)"); | |
20694 | case NT_PPC_TM_CDSCR: | |
20695 | return _("NT_PPC_TM_CDSCR (ppc checkpointed DSCR register)"); | |
20696 | case NT_386_TLS: | |
20697 | return _("NT_386_TLS (x86 TLS information)"); | |
20698 | case NT_386_IOPERM: | |
20699 | return _("NT_386_IOPERM (x86 I/O permissions)"); | |
20700 | case NT_X86_XSTATE: | |
20701 | return _("NT_X86_XSTATE (x86 XSAVE extended state)"); | |
20702 | case NT_X86_CET: | |
20703 | return _("NT_X86_CET (x86 CET state)"); | |
20704 | case NT_X86_SHSTK: | |
20705 | return _("NT_X86_SHSTK (x86 SHSTK state)"); | |
20706 | case NT_S390_HIGH_GPRS: | |
20707 | return _("NT_S390_HIGH_GPRS (s390 upper register halves)"); | |
20708 | case NT_S390_TIMER: | |
20709 | return _("NT_S390_TIMER (s390 timer register)"); | |
20710 | case NT_S390_TODCMP: | |
20711 | return _("NT_S390_TODCMP (s390 TOD comparator register)"); | |
20712 | case NT_S390_TODPREG: | |
20713 | return _("NT_S390_TODPREG (s390 TOD programmable register)"); | |
20714 | case NT_S390_CTRS: | |
20715 | return _("NT_S390_CTRS (s390 control registers)"); | |
20716 | case NT_S390_PREFIX: | |
20717 | return _("NT_S390_PREFIX (s390 prefix register)"); | |
20718 | case NT_S390_LAST_BREAK: | |
20719 | return _("NT_S390_LAST_BREAK (s390 last breaking event address)"); | |
20720 | case NT_S390_SYSTEM_CALL: | |
20721 | return _("NT_S390_SYSTEM_CALL (s390 system call restart data)"); | |
20722 | case NT_S390_TDB: | |
20723 | return _("NT_S390_TDB (s390 transaction diagnostic block)"); | |
20724 | case NT_S390_VXRS_LOW: | |
20725 | return _("NT_S390_VXRS_LOW (s390 vector registers 0-15 upper half)"); | |
20726 | case NT_S390_VXRS_HIGH: | |
20727 | return _("NT_S390_VXRS_HIGH (s390 vector registers 16-31)"); | |
20728 | case NT_S390_GS_CB: | |
20729 | return _("NT_S390_GS_CB (s390 guarded-storage registers)"); | |
20730 | case NT_S390_GS_BC: | |
20731 | return _("NT_S390_GS_BC (s390 guarded-storage broadcast control)"); | |
20732 | case NT_ARM_VFP: | |
20733 | return _("NT_ARM_VFP (arm VFP registers)"); | |
20734 | case NT_ARM_TLS: | |
20735 | return _("NT_ARM_TLS (AArch TLS registers)"); | |
20736 | case NT_ARM_HW_BREAK: | |
20737 | return _("NT_ARM_HW_BREAK (AArch hardware breakpoint registers)"); | |
20738 | case NT_ARM_HW_WATCH: | |
20739 | return _("NT_ARM_HW_WATCH (AArch hardware watchpoint registers)"); | |
20740 | case NT_ARM_SYSTEM_CALL: | |
20741 | return _("NT_ARM_SYSTEM_CALL (AArch system call number)"); | |
20742 | case NT_ARM_SVE: | |
20743 | return _("NT_ARM_SVE (AArch SVE registers)"); | |
20744 | case NT_ARM_PAC_MASK: | |
20745 | return _("NT_ARM_PAC_MASK (AArch pointer authentication code masks)"); | |
20746 | case NT_ARM_PACA_KEYS: | |
20747 | return _("NT_ARM_PACA_KEYS (ARM pointer authentication address keys)"); | |
20748 | case NT_ARM_PACG_KEYS: | |
20749 | return _("NT_ARM_PACG_KEYS (ARM pointer authentication generic keys)"); | |
20750 | case NT_ARM_TAGGED_ADDR_CTRL: | |
20751 | return _("NT_ARM_TAGGED_ADDR_CTRL (AArch tagged address control)"); | |
20752 | case NT_ARM_SSVE: | |
20753 | return _("NT_ARM_SSVE (AArch64 streaming SVE registers)"); | |
20754 | case NT_ARM_ZA: | |
20755 | return _("NT_ARM_ZA (AArch64 SME ZA register)"); | |
20756 | case NT_ARM_ZT: | |
20757 | return _("NT_ARM_ZT (AArch64 SME2 ZT registers)"); | |
20758 | case NT_ARM_PAC_ENABLED_KEYS: | |
20759 | return _("NT_ARM_PAC_ENABLED_KEYS (AArch64 pointer authentication enabled keys)"); | |
20760 | case NT_ARC_V2: | |
20761 | return _("NT_ARC_V2 (ARC HS accumulator/extra registers)"); | |
20762 | case NT_RISCV_CSR: | |
20763 | return _("NT_RISCV_CSR (RISC-V control and status registers)"); | |
20764 | case NT_PSTATUS: | |
20765 | return _("NT_PSTATUS (pstatus structure)"); | |
20766 | case NT_FPREGS: | |
20767 | return _("NT_FPREGS (floating point registers)"); | |
20768 | case NT_PSINFO: | |
20769 | return _("NT_PSINFO (psinfo structure)"); | |
20770 | case NT_LWPSTATUS: | |
20771 | return _("NT_LWPSTATUS (lwpstatus_t structure)"); | |
20772 | case NT_LWPSINFO: | |
20773 | return _("NT_LWPSINFO (lwpsinfo_t structure)"); | |
20774 | case NT_WIN32PSTATUS: | |
20775 | return _("NT_WIN32PSTATUS (win32_pstatus structure)"); | |
20776 | case NT_SIGINFO: | |
20777 | return _("NT_SIGINFO (siginfo_t data)"); | |
20778 | case NT_FILE: | |
20779 | return _("NT_FILE (mapped files)"); | |
20780 | default: | |
20781 | break; | |
20782 | } | |
20783 | else | |
20784 | switch (e_type) | |
20785 | { | |
20786 | case NT_VERSION: | |
20787 | return _("NT_VERSION (version)"); | |
20788 | case NT_ARCH: | |
20789 | return _("NT_ARCH (architecture)"); | |
20790 | case NT_GNU_BUILD_ATTRIBUTE_OPEN: | |
20791 | return _("OPEN"); | |
20792 | case NT_GNU_BUILD_ATTRIBUTE_FUNC: | |
20793 | return _("func"); | |
20794 | case NT_GO_BUILDID: | |
20795 | return _("GO BUILDID"); | |
20796 | case FDO_PACKAGING_METADATA: | |
20797 | return _("FDO_PACKAGING_METADATA"); | |
20798 | case FDO_DLOPEN_METADATA: | |
20799 | return _("FDO_DLOPEN_METADATA"); | |
20800 | default: | |
20801 | break; | |
20802 | } | |
20803 | ||
20804 | snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type); | |
20805 | return buff; | |
20806 | } | |
20807 | ||
20808 | static bool | |
20809 | print_core_note (Elf_Internal_Note *pnote) | |
20810 | { | |
20811 | unsigned int addr_size = is_32bit_elf ? 4 : 8; | |
20812 | uint64_t count, page_size; | |
20813 | unsigned char *descdata, *filenames, *descend; | |
20814 | ||
20815 | if (pnote->type != NT_FILE) | |
20816 | { | |
20817 | if (do_wide) | |
20818 | printf ("\n"); | |
20819 | return true; | |
20820 | } | |
20821 | ||
20822 | if (pnote->descsz < 2 * addr_size) | |
20823 | { | |
20824 | error (_(" Malformed note - too short for header\n")); | |
20825 | return false; | |
20826 | } | |
20827 | ||
20828 | descdata = (unsigned char *) pnote->descdata; | |
20829 | descend = descdata + pnote->descsz; | |
20830 | ||
20831 | if (descdata[pnote->descsz - 1] != '\0') | |
20832 | { | |
20833 | error (_(" Malformed note - does not end with \\0\n")); | |
20834 | return false; | |
20835 | } | |
20836 | ||
20837 | count = byte_get (descdata, addr_size); | |
20838 | descdata += addr_size; | |
20839 | ||
20840 | page_size = byte_get (descdata, addr_size); | |
20841 | descdata += addr_size; | |
20842 | ||
20843 | if (count > ((uint64_t) -1 - 2 * addr_size) / (3 * addr_size) | |
20844 | || pnote->descsz < 2 * addr_size + count * 3 * addr_size) | |
20845 | { | |
20846 | error (_(" Malformed note - too short for supplied file count\n")); | |
20847 | return false; | |
20848 | } | |
20849 | ||
20850 | printf (_(" Page size: ")); | |
20851 | print_vma (page_size, DEC); | |
20852 | printf ("\n"); | |
20853 | ||
20854 | printf (_(" %*s%*s%*s\n"), | |
20855 | (int) (2 + 2 * addr_size), _("Start"), | |
20856 | (int) (4 + 2 * addr_size), _("End"), | |
20857 | (int) (4 + 2 * addr_size), _("Page Offset")); | |
20858 | filenames = descdata + count * 3 * addr_size; | |
20859 | while (count-- > 0) | |
20860 | { | |
20861 | uint64_t start, end, file_ofs; | |
20862 | ||
20863 | if (filenames == descend) | |
20864 | { | |
20865 | error (_(" Malformed note - filenames end too early\n")); | |
20866 | return false; | |
20867 | } | |
20868 | ||
20869 | start = byte_get (descdata, addr_size); | |
20870 | descdata += addr_size; | |
20871 | end = byte_get (descdata, addr_size); | |
20872 | descdata += addr_size; | |
20873 | file_ofs = byte_get (descdata, addr_size); | |
20874 | descdata += addr_size; | |
20875 | ||
20876 | printf (" "); | |
20877 | print_vma (start, FULL_HEX); | |
20878 | printf (" "); | |
20879 | print_vma (end, FULL_HEX); | |
20880 | printf (" "); | |
20881 | print_vma (file_ofs, FULL_HEX); | |
20882 | printf ("\n %s\n", filenames); | |
20883 | ||
20884 | filenames += 1 + strlen ((char *) filenames); | |
20885 | } | |
20886 | ||
20887 | return true; | |
20888 | } | |
20889 | ||
20890 | static const char * | |
20891 | get_gnu_elf_note_type (unsigned e_type) | |
20892 | { | |
20893 | /* NB/ Keep this switch statement in sync with print_gnu_note (). */ | |
20894 | switch (e_type) | |
20895 | { | |
20896 | case NT_GNU_ABI_TAG: | |
20897 | return _("NT_GNU_ABI_TAG (ABI version tag)"); | |
20898 | case NT_GNU_HWCAP: | |
20899 | return _("NT_GNU_HWCAP (DSO-supplied software HWCAP info)"); | |
20900 | case NT_GNU_BUILD_ID: | |
20901 | return _("NT_GNU_BUILD_ID (unique build ID bitstring)"); | |
20902 | case NT_GNU_GOLD_VERSION: | |
20903 | return _("NT_GNU_GOLD_VERSION (gold version)"); | |
20904 | case NT_GNU_PROPERTY_TYPE_0: | |
20905 | return _("NT_GNU_PROPERTY_TYPE_0"); | |
20906 | case NT_GNU_BUILD_ATTRIBUTE_OPEN: | |
20907 | return _("NT_GNU_BUILD_ATTRIBUTE_OPEN"); | |
20908 | case NT_GNU_BUILD_ATTRIBUTE_FUNC: | |
20909 | return _("NT_GNU_BUILD_ATTRIBUTE_FUNC"); | |
20910 | default: | |
20911 | { | |
20912 | static char buff[64]; | |
20913 | ||
20914 | snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type); | |
20915 | return buff; | |
20916 | } | |
20917 | } | |
20918 | } | |
20919 | ||
20920 | static void | |
20921 | decode_x86_compat_isa (unsigned int bitmask) | |
20922 | { | |
20923 | while (bitmask) | |
20924 | { | |
20925 | unsigned int bit = bitmask & (- bitmask); | |
20926 | ||
20927 | bitmask &= ~ bit; | |
20928 | switch (bit) | |
20929 | { | |
20930 | case GNU_PROPERTY_X86_COMPAT_ISA_1_486: | |
20931 | printf ("i486"); | |
20932 | break; | |
20933 | case GNU_PROPERTY_X86_COMPAT_ISA_1_586: | |
20934 | printf ("586"); | |
20935 | break; | |
20936 | case GNU_PROPERTY_X86_COMPAT_ISA_1_686: | |
20937 | printf ("686"); | |
20938 | break; | |
20939 | case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE: | |
20940 | printf ("SSE"); | |
20941 | break; | |
20942 | case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE2: | |
20943 | printf ("SSE2"); | |
20944 | break; | |
20945 | case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE3: | |
20946 | printf ("SSE3"); | |
20947 | break; | |
20948 | case GNU_PROPERTY_X86_COMPAT_ISA_1_SSSE3: | |
20949 | printf ("SSSE3"); | |
20950 | break; | |
20951 | case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE4_1: | |
20952 | printf ("SSE4_1"); | |
20953 | break; | |
20954 | case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE4_2: | |
20955 | printf ("SSE4_2"); | |
20956 | break; | |
20957 | case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX: | |
20958 | printf ("AVX"); | |
20959 | break; | |
20960 | case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX2: | |
20961 | printf ("AVX2"); | |
20962 | break; | |
20963 | case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512F: | |
20964 | printf ("AVX512F"); | |
20965 | break; | |
20966 | case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512CD: | |
20967 | printf ("AVX512CD"); | |
20968 | break; | |
20969 | case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512ER: | |
20970 | printf ("AVX512ER"); | |
20971 | break; | |
20972 | case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512PF: | |
20973 | printf ("AVX512PF"); | |
20974 | break; | |
20975 | case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512VL: | |
20976 | printf ("AVX512VL"); | |
20977 | break; | |
20978 | case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512DQ: | |
20979 | printf ("AVX512DQ"); | |
20980 | break; | |
20981 | case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512BW: | |
20982 | printf ("AVX512BW"); | |
20983 | break; | |
20984 | default: | |
20985 | printf (_("<unknown: %x>"), bit); | |
20986 | break; | |
20987 | } | |
20988 | if (bitmask) | |
20989 | printf (", "); | |
20990 | } | |
20991 | } | |
20992 | ||
20993 | static void | |
20994 | decode_x86_compat_2_isa (unsigned int bitmask) | |
20995 | { | |
20996 | if (!bitmask) | |
20997 | { | |
20998 | printf (_("<None>")); | |
20999 | return; | |
21000 | } | |
21001 | ||
21002 | while (bitmask) | |
21003 | { | |
21004 | unsigned int bit = bitmask & (- bitmask); | |
21005 | ||
21006 | bitmask &= ~ bit; | |
21007 | switch (bit) | |
21008 | { | |
21009 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_CMOV: | |
21010 | printf ("CMOV"); | |
21011 | break; | |
21012 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE: | |
21013 | printf ("SSE"); | |
21014 | break; | |
21015 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE2: | |
21016 | printf ("SSE2"); | |
21017 | break; | |
21018 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE3: | |
21019 | printf ("SSE3"); | |
21020 | break; | |
21021 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSSE3: | |
21022 | printf ("SSSE3"); | |
21023 | break; | |
21024 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE4_1: | |
21025 | printf ("SSE4_1"); | |
21026 | break; | |
21027 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE4_2: | |
21028 | printf ("SSE4_2"); | |
21029 | break; | |
21030 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX: | |
21031 | printf ("AVX"); | |
21032 | break; | |
21033 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX2: | |
21034 | printf ("AVX2"); | |
21035 | break; | |
21036 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_FMA: | |
21037 | printf ("FMA"); | |
21038 | break; | |
21039 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512F: | |
21040 | printf ("AVX512F"); | |
21041 | break; | |
21042 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512CD: | |
21043 | printf ("AVX512CD"); | |
21044 | break; | |
21045 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512ER: | |
21046 | printf ("AVX512ER"); | |
21047 | break; | |
21048 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512PF: | |
21049 | printf ("AVX512PF"); | |
21050 | break; | |
21051 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512VL: | |
21052 | printf ("AVX512VL"); | |
21053 | break; | |
21054 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512DQ: | |
21055 | printf ("AVX512DQ"); | |
21056 | break; | |
21057 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512BW: | |
21058 | printf ("AVX512BW"); | |
21059 | break; | |
21060 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_4FMAPS: | |
21061 | printf ("AVX512_4FMAPS"); | |
21062 | break; | |
21063 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_4VNNIW: | |
21064 | printf ("AVX512_4VNNIW"); | |
21065 | break; | |
21066 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_BITALG: | |
21067 | printf ("AVX512_BITALG"); | |
21068 | break; | |
21069 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_IFMA: | |
21070 | printf ("AVX512_IFMA"); | |
21071 | break; | |
21072 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_VBMI: | |
21073 | printf ("AVX512_VBMI"); | |
21074 | break; | |
21075 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_VBMI2: | |
21076 | printf ("AVX512_VBMI2"); | |
21077 | break; | |
21078 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_VNNI: | |
21079 | printf ("AVX512_VNNI"); | |
21080 | break; | |
21081 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_BF16: | |
21082 | printf ("AVX512_BF16"); | |
21083 | break; | |
21084 | default: | |
21085 | printf (_("<unknown: %x>"), bit); | |
21086 | break; | |
21087 | } | |
21088 | if (bitmask) | |
21089 | printf (", "); | |
21090 | } | |
21091 | } | |
21092 | ||
21093 | static const char * | |
21094 | get_amdgpu_elf_note_type (unsigned int e_type) | |
21095 | { | |
21096 | switch (e_type) | |
21097 | { | |
21098 | case NT_AMDGPU_METADATA: | |
21099 | return _("NT_AMDGPU_METADATA (code object metadata)"); | |
21100 | default: | |
21101 | { | |
21102 | static char buf[64]; | |
21103 | snprintf (buf, sizeof (buf), _("Unknown note type: (0x%08x)"), e_type); | |
21104 | return buf; | |
21105 | } | |
21106 | } | |
21107 | } | |
21108 | ||
21109 | static void | |
21110 | decode_x86_isa (unsigned int bitmask) | |
21111 | { | |
21112 | while (bitmask) | |
21113 | { | |
21114 | unsigned int bit = bitmask & (- bitmask); | |
21115 | ||
21116 | bitmask &= ~ bit; | |
21117 | switch (bit) | |
21118 | { | |
21119 | case GNU_PROPERTY_X86_ISA_1_BASELINE: | |
21120 | printf ("x86-64-baseline"); | |
21121 | break; | |
21122 | case GNU_PROPERTY_X86_ISA_1_V2: | |
21123 | printf ("x86-64-v2"); | |
21124 | break; | |
21125 | case GNU_PROPERTY_X86_ISA_1_V3: | |
21126 | printf ("x86-64-v3"); | |
21127 | break; | |
21128 | case GNU_PROPERTY_X86_ISA_1_V4: | |
21129 | printf ("x86-64-v4"); | |
21130 | break; | |
21131 | default: | |
21132 | printf (_("<unknown: %x>"), bit); | |
21133 | break; | |
21134 | } | |
21135 | if (bitmask) | |
21136 | printf (", "); | |
21137 | } | |
21138 | } | |
21139 | ||
21140 | static void | |
21141 | decode_x86_feature_1 (unsigned int bitmask) | |
21142 | { | |
21143 | if (!bitmask) | |
21144 | { | |
21145 | printf (_("<None>")); | |
21146 | return; | |
21147 | } | |
21148 | ||
21149 | while (bitmask) | |
21150 | { | |
21151 | unsigned int bit = bitmask & (- bitmask); | |
21152 | ||
21153 | bitmask &= ~ bit; | |
21154 | switch (bit) | |
21155 | { | |
21156 | case GNU_PROPERTY_X86_FEATURE_1_IBT: | |
21157 | printf ("IBT"); | |
21158 | break; | |
21159 | case GNU_PROPERTY_X86_FEATURE_1_SHSTK: | |
21160 | printf ("SHSTK"); | |
21161 | break; | |
21162 | case GNU_PROPERTY_X86_FEATURE_1_LAM_U48: | |
21163 | printf ("LAM_U48"); | |
21164 | break; | |
21165 | case GNU_PROPERTY_X86_FEATURE_1_LAM_U57: | |
21166 | printf ("LAM_U57"); | |
21167 | break; | |
21168 | default: | |
21169 | printf (_("<unknown: %x>"), bit); | |
21170 | break; | |
21171 | } | |
21172 | if (bitmask) | |
21173 | printf (", "); | |
21174 | } | |
21175 | } | |
21176 | ||
21177 | static void | |
21178 | decode_x86_feature_2 (unsigned int bitmask) | |
21179 | { | |
21180 | if (!bitmask) | |
21181 | { | |
21182 | printf (_("<None>")); | |
21183 | return; | |
21184 | } | |
21185 | ||
21186 | while (bitmask) | |
21187 | { | |
21188 | unsigned int bit = bitmask & (- bitmask); | |
21189 | ||
21190 | bitmask &= ~ bit; | |
21191 | switch (bit) | |
21192 | { | |
21193 | case GNU_PROPERTY_X86_FEATURE_2_X86: | |
21194 | printf ("x86"); | |
21195 | break; | |
21196 | case GNU_PROPERTY_X86_FEATURE_2_X87: | |
21197 | printf ("x87"); | |
21198 | break; | |
21199 | case GNU_PROPERTY_X86_FEATURE_2_MMX: | |
21200 | printf ("MMX"); | |
21201 | break; | |
21202 | case GNU_PROPERTY_X86_FEATURE_2_XMM: | |
21203 | printf ("XMM"); | |
21204 | break; | |
21205 | case GNU_PROPERTY_X86_FEATURE_2_YMM: | |
21206 | printf ("YMM"); | |
21207 | break; | |
21208 | case GNU_PROPERTY_X86_FEATURE_2_ZMM: | |
21209 | printf ("ZMM"); | |
21210 | break; | |
21211 | case GNU_PROPERTY_X86_FEATURE_2_TMM: | |
21212 | printf ("TMM"); | |
21213 | break; | |
21214 | case GNU_PROPERTY_X86_FEATURE_2_MASK: | |
21215 | printf ("MASK"); | |
21216 | break; | |
21217 | case GNU_PROPERTY_X86_FEATURE_2_FXSR: | |
21218 | printf ("FXSR"); | |
21219 | break; | |
21220 | case GNU_PROPERTY_X86_FEATURE_2_XSAVE: | |
21221 | printf ("XSAVE"); | |
21222 | break; | |
21223 | case GNU_PROPERTY_X86_FEATURE_2_XSAVEOPT: | |
21224 | printf ("XSAVEOPT"); | |
21225 | break; | |
21226 | case GNU_PROPERTY_X86_FEATURE_2_XSAVEC: | |
21227 | printf ("XSAVEC"); | |
21228 | break; | |
21229 | default: | |
21230 | printf (_("<unknown: %x>"), bit); | |
21231 | break; | |
21232 | } | |
21233 | if (bitmask) | |
21234 | printf (", "); | |
21235 | } | |
21236 | } | |
21237 | ||
21238 | static void | |
21239 | decode_aarch64_feature_1_and (unsigned int bitmask) | |
21240 | { | |
21241 | while (bitmask) | |
21242 | { | |
21243 | unsigned int bit = bitmask & (- bitmask); | |
21244 | ||
21245 | bitmask &= ~ bit; | |
21246 | switch (bit) | |
21247 | { | |
21248 | case GNU_PROPERTY_AARCH64_FEATURE_1_BTI: | |
21249 | printf ("BTI"); | |
21250 | break; | |
21251 | ||
21252 | case GNU_PROPERTY_AARCH64_FEATURE_1_PAC: | |
21253 | printf ("PAC"); | |
21254 | break; | |
21255 | ||
21256 | case GNU_PROPERTY_AARCH64_FEATURE_1_GCS: | |
21257 | printf ("GCS"); | |
21258 | break; | |
21259 | ||
21260 | default: | |
21261 | printf (_("<unknown: %x>"), bit); | |
21262 | break; | |
21263 | } | |
21264 | if (bitmask) | |
21265 | printf (", "); | |
21266 | } | |
21267 | } | |
21268 | ||
21269 | static void | |
21270 | decode_riscv_feature_1_and (unsigned int bitmask) | |
21271 | { | |
21272 | while (bitmask) | |
21273 | { | |
21274 | unsigned int bit = bitmask & (- bitmask); | |
21275 | ||
21276 | bitmask &= ~ bit; | |
21277 | switch (bit) | |
21278 | { | |
21279 | case GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_UNLABELED: | |
21280 | printf ("CFI_LP_UNLABELED"); | |
21281 | break; | |
21282 | ||
21283 | case GNU_PROPERTY_RISCV_FEATURE_1_CFI_SS: | |
21284 | printf ("CFI_SS"); | |
21285 | break; | |
21286 | ||
21287 | default: | |
21288 | printf (_("<unknown: %x>"), bit); | |
21289 | break; | |
21290 | } | |
21291 | if (bitmask) | |
21292 | printf (", "); | |
21293 | } | |
21294 | } | |
21295 | ||
21296 | static void | |
21297 | decode_1_needed (unsigned int bitmask) | |
21298 | { | |
21299 | while (bitmask) | |
21300 | { | |
21301 | unsigned int bit = bitmask & (- bitmask); | |
21302 | ||
21303 | bitmask &= ~ bit; | |
21304 | switch (bit) | |
21305 | { | |
21306 | case GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS: | |
21307 | printf ("indirect external access"); | |
21308 | break; | |
21309 | default: | |
21310 | printf (_("<unknown: %x>"), bit); | |
21311 | break; | |
21312 | } | |
21313 | if (bitmask) | |
21314 | printf (", "); | |
21315 | } | |
21316 | } | |
21317 | ||
21318 | static void | |
21319 | print_gnu_property_note (Filedata * filedata, Elf_Internal_Note * pnote) | |
21320 | { | |
21321 | unsigned char * ptr = (unsigned char *) pnote->descdata; | |
21322 | unsigned char * ptr_end = ptr + pnote->descsz; | |
21323 | unsigned int size = is_32bit_elf ? 4 : 8; | |
21324 | ||
21325 | printf (_(" Properties: ")); | |
21326 | ||
21327 | if (pnote->descsz < 8 || (pnote->descsz % size) != 0) | |
21328 | { | |
21329 | printf (_("<corrupt GNU_PROPERTY_TYPE, size = %#lx>\n"), pnote->descsz); | |
21330 | return; | |
21331 | } | |
21332 | ||
21333 | while (ptr < ptr_end) | |
21334 | { | |
21335 | unsigned int j; | |
21336 | unsigned int type; | |
21337 | unsigned int datasz; | |
21338 | ||
21339 | if ((size_t) (ptr_end - ptr) < 8) | |
21340 | { | |
21341 | printf (_("<corrupt descsz: %#lx>\n"), pnote->descsz); | |
21342 | break; | |
21343 | } | |
21344 | ||
21345 | type = byte_get (ptr, 4); | |
21346 | datasz = byte_get (ptr + 4, 4); | |
21347 | ||
21348 | ptr += 8; | |
21349 | ||
21350 | if (datasz > (size_t) (ptr_end - ptr)) | |
21351 | { | |
21352 | printf (_("<corrupt type (%#x) datasz: %#x>\n"), | |
21353 | type, datasz); | |
21354 | break; | |
21355 | } | |
21356 | ||
21357 | if (type >= GNU_PROPERTY_LOPROC && type <= GNU_PROPERTY_HIPROC) | |
21358 | { | |
21359 | if (filedata->file_header.e_machine == EM_X86_64 | |
21360 | || filedata->file_header.e_machine == EM_IAMCU | |
21361 | || filedata->file_header.e_machine == EM_386) | |
21362 | { | |
21363 | unsigned int bitmask; | |
21364 | ||
21365 | if (datasz == 4) | |
21366 | bitmask = byte_get (ptr, 4); | |
21367 | else | |
21368 | bitmask = 0; | |
21369 | ||
21370 | switch (type) | |
21371 | { | |
21372 | case GNU_PROPERTY_X86_ISA_1_USED: | |
21373 | if (datasz != 4) | |
21374 | printf (_("x86 ISA used: <corrupt length: %#x> "), | |
21375 | datasz); | |
21376 | else | |
21377 | { | |
21378 | printf ("x86 ISA used: "); | |
21379 | decode_x86_isa (bitmask); | |
21380 | } | |
21381 | goto next; | |
21382 | ||
21383 | case GNU_PROPERTY_X86_ISA_1_NEEDED: | |
21384 | if (datasz != 4) | |
21385 | printf (_("x86 ISA needed: <corrupt length: %#x> "), | |
21386 | datasz); | |
21387 | else | |
21388 | { | |
21389 | printf ("x86 ISA needed: "); | |
21390 | decode_x86_isa (bitmask); | |
21391 | } | |
21392 | goto next; | |
21393 | ||
21394 | case GNU_PROPERTY_X86_FEATURE_1_AND: | |
21395 | if (datasz != 4) | |
21396 | printf (_("x86 feature: <corrupt length: %#x> "), | |
21397 | datasz); | |
21398 | else | |
21399 | { | |
21400 | printf ("x86 feature: "); | |
21401 | decode_x86_feature_1 (bitmask); | |
21402 | } | |
21403 | goto next; | |
21404 | ||
21405 | case GNU_PROPERTY_X86_FEATURE_2_USED: | |
21406 | if (datasz != 4) | |
21407 | printf (_("x86 feature used: <corrupt length: %#x> "), | |
21408 | datasz); | |
21409 | else | |
21410 | { | |
21411 | printf ("x86 feature used: "); | |
21412 | decode_x86_feature_2 (bitmask); | |
21413 | } | |
21414 | goto next; | |
21415 | ||
21416 | case GNU_PROPERTY_X86_FEATURE_2_NEEDED: | |
21417 | if (datasz != 4) | |
21418 | printf (_("x86 feature needed: <corrupt length: %#x> "), datasz); | |
21419 | else | |
21420 | { | |
21421 | printf ("x86 feature needed: "); | |
21422 | decode_x86_feature_2 (bitmask); | |
21423 | } | |
21424 | goto next; | |
21425 | ||
21426 | case GNU_PROPERTY_X86_COMPAT_ISA_1_USED: | |
21427 | if (datasz != 4) | |
21428 | printf (_("x86 ISA used: <corrupt length: %#x> "), | |
21429 | datasz); | |
21430 | else | |
21431 | { | |
21432 | printf ("x86 ISA used: "); | |
21433 | decode_x86_compat_isa (bitmask); | |
21434 | } | |
21435 | goto next; | |
21436 | ||
21437 | case GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED: | |
21438 | if (datasz != 4) | |
21439 | printf (_("x86 ISA needed: <corrupt length: %#x> "), | |
21440 | datasz); | |
21441 | else | |
21442 | { | |
21443 | printf ("x86 ISA needed: "); | |
21444 | decode_x86_compat_isa (bitmask); | |
21445 | } | |
21446 | goto next; | |
21447 | ||
21448 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_USED: | |
21449 | if (datasz != 4) | |
21450 | printf (_("x86 ISA used: <corrupt length: %#x> "), | |
21451 | datasz); | |
21452 | else | |
21453 | { | |
21454 | printf ("x86 ISA used: "); | |
21455 | decode_x86_compat_2_isa (bitmask); | |
21456 | } | |
21457 | goto next; | |
21458 | ||
21459 | case GNU_PROPERTY_X86_COMPAT_2_ISA_1_NEEDED: | |
21460 | if (datasz != 4) | |
21461 | printf (_("x86 ISA needed: <corrupt length: %#x> "), | |
21462 | datasz); | |
21463 | else | |
21464 | { | |
21465 | printf ("x86 ISA needed: "); | |
21466 | decode_x86_compat_2_isa (bitmask); | |
21467 | } | |
21468 | goto next; | |
21469 | ||
21470 | default: | |
21471 | break; | |
21472 | } | |
21473 | } | |
21474 | else if (filedata->file_header.e_machine == EM_AARCH64) | |
21475 | { | |
21476 | if (type == GNU_PROPERTY_AARCH64_FEATURE_1_AND) | |
21477 | { | |
21478 | printf ("AArch64 feature: "); | |
21479 | if (datasz != 4) | |
21480 | printf (_("<corrupt length: %#x> "), datasz); | |
21481 | else | |
21482 | decode_aarch64_feature_1_and (byte_get (ptr, 4)); | |
21483 | goto next; | |
21484 | } | |
21485 | } | |
21486 | else if (filedata->file_header.e_machine == EM_RISCV) | |
21487 | { | |
21488 | if (type == GNU_PROPERTY_RISCV_FEATURE_1_AND) | |
21489 | { | |
21490 | printf ("RISC-V AND feature: "); | |
21491 | if (datasz != 4) | |
21492 | printf (_("<corrupt length: %#x> "), datasz); | |
21493 | else | |
21494 | decode_riscv_feature_1_and (byte_get (ptr, 4)); | |
21495 | goto next; | |
21496 | } | |
21497 | } | |
21498 | } | |
21499 | else | |
21500 | { | |
21501 | switch (type) | |
21502 | { | |
21503 | case GNU_PROPERTY_STACK_SIZE: | |
21504 | printf (_("stack size: ")); | |
21505 | if (datasz != size) | |
21506 | printf (_("<corrupt length: %#x> "), datasz); | |
21507 | else | |
21508 | printf ("%#" PRIx64, byte_get (ptr, size)); | |
21509 | goto next; | |
21510 | ||
21511 | case GNU_PROPERTY_NO_COPY_ON_PROTECTED: | |
21512 | printf ("no copy on protected "); | |
21513 | if (datasz) | |
21514 | printf (_("<corrupt length: %#x> "), datasz); | |
21515 | goto next; | |
21516 | ||
21517 | case GNU_PROPERTY_MEMORY_SEAL: | |
21518 | printf ("memory seal "); | |
21519 | if (datasz) | |
21520 | printf (_("<corrupt length: %#x> "), datasz); | |
21521 | goto next; | |
21522 | ||
21523 | default: | |
21524 | if ((type >= GNU_PROPERTY_UINT32_AND_LO | |
21525 | && type <= GNU_PROPERTY_UINT32_AND_HI) | |
21526 | || (type >= GNU_PROPERTY_UINT32_OR_LO | |
21527 | && type <= GNU_PROPERTY_UINT32_OR_HI)) | |
21528 | { | |
21529 | switch (type) | |
21530 | { | |
21531 | case GNU_PROPERTY_1_NEEDED: | |
21532 | if (datasz != 4) | |
21533 | printf (_("1_needed: <corrupt length: %#x> "), | |
21534 | datasz); | |
21535 | else | |
21536 | { | |
21537 | unsigned int bitmask = byte_get (ptr, 4); | |
21538 | printf ("1_needed: "); | |
21539 | decode_1_needed (bitmask); | |
21540 | } | |
21541 | goto next; | |
21542 | ||
21543 | default: | |
21544 | break; | |
21545 | } | |
21546 | if (type <= GNU_PROPERTY_UINT32_AND_HI) | |
21547 | printf (_("UINT32_AND (%#x): "), type); | |
21548 | else | |
21549 | printf (_("UINT32_OR (%#x): "), type); | |
21550 | if (datasz != 4) | |
21551 | printf (_("<corrupt length: %#x> "), datasz); | |
21552 | else | |
21553 | printf ("%#x", (unsigned int) byte_get (ptr, 4)); | |
21554 | goto next; | |
21555 | } | |
21556 | break; | |
21557 | } | |
21558 | } | |
21559 | ||
21560 | if (type < GNU_PROPERTY_LOPROC) | |
21561 | printf (_("<unknown type %#x data: "), type); | |
21562 | else if (type < GNU_PROPERTY_LOUSER) | |
21563 | printf (_("<processor-specific type %#x data: "), type); | |
21564 | else | |
21565 | printf (_("<application-specific type %#x data: "), type); | |
21566 | for (j = 0; j < datasz; ++j) | |
21567 | printf ("%02x ", ptr[j] & 0xff); | |
21568 | printf (">"); | |
21569 | ||
21570 | next: | |
21571 | ptr += ((datasz + (size - 1)) & ~ (size - 1)); | |
21572 | if (ptr == ptr_end) | |
21573 | break; | |
21574 | ||
21575 | if (do_wide) | |
21576 | printf (", "); | |
21577 | else | |
21578 | printf ("\n\t"); | |
21579 | } | |
21580 | ||
21581 | printf ("\n"); | |
21582 | } | |
21583 | ||
21584 | static bool | |
21585 | print_gnu_note (Filedata * filedata, Elf_Internal_Note *pnote) | |
21586 | { | |
21587 | /* NB/ Keep this switch statement in sync with get_gnu_elf_note_type (). */ | |
21588 | switch (pnote->type) | |
21589 | { | |
21590 | case NT_GNU_BUILD_ID: | |
21591 | { | |
21592 | size_t i; | |
21593 | ||
21594 | printf (_(" Build ID: ")); | |
21595 | for (i = 0; i < pnote->descsz; ++i) | |
21596 | printf ("%02x", pnote->descdata[i] & 0xff); | |
21597 | printf ("\n"); | |
21598 | } | |
21599 | break; | |
21600 | ||
21601 | case NT_GNU_ABI_TAG: | |
21602 | { | |
21603 | unsigned int os, major, minor, subminor; | |
21604 | const char *osname; | |
21605 | ||
21606 | /* PR 17531: file: 030-599401-0.004. */ | |
21607 | if (pnote->descsz < 16) | |
21608 | { | |
21609 | printf (_(" <corrupt GNU_ABI_TAG>\n")); | |
21610 | break; | |
21611 | } | |
21612 | ||
21613 | os = byte_get ((unsigned char *) pnote->descdata, 4); | |
21614 | major = byte_get ((unsigned char *) pnote->descdata + 4, 4); | |
21615 | minor = byte_get ((unsigned char *) pnote->descdata + 8, 4); | |
21616 | subminor = byte_get ((unsigned char *) pnote->descdata + 12, 4); | |
21617 | ||
21618 | switch (os) | |
21619 | { | |
21620 | case GNU_ABI_TAG_LINUX: | |
21621 | osname = "Linux"; | |
21622 | break; | |
21623 | case GNU_ABI_TAG_HURD: | |
21624 | osname = "Hurd"; | |
21625 | break; | |
21626 | case GNU_ABI_TAG_SOLARIS: | |
21627 | osname = "Solaris"; | |
21628 | break; | |
21629 | case GNU_ABI_TAG_FREEBSD: | |
21630 | osname = "FreeBSD"; | |
21631 | break; | |
21632 | case GNU_ABI_TAG_NETBSD: | |
21633 | osname = "NetBSD"; | |
21634 | break; | |
21635 | case GNU_ABI_TAG_SYLLABLE: | |
21636 | osname = "Syllable"; | |
21637 | break; | |
21638 | case GNU_ABI_TAG_NACL: | |
21639 | osname = "NaCl"; | |
21640 | break; | |
21641 | default: | |
21642 | osname = "Unknown"; | |
21643 | break; | |
21644 | } | |
21645 | ||
21646 | printf (_(" OS: %s, ABI: %d.%d.%d\n"), osname, | |
21647 | major, minor, subminor); | |
21648 | } | |
21649 | break; | |
21650 | ||
21651 | case NT_GNU_GOLD_VERSION: | |
21652 | { | |
21653 | size_t i; | |
21654 | ||
21655 | printf (_(" Version: ")); | |
21656 | for (i = 0; i < pnote->descsz && pnote->descdata[i] != '\0'; ++i) | |
21657 | printf ("%c", pnote->descdata[i]); | |
21658 | printf ("\n"); | |
21659 | } | |
21660 | break; | |
21661 | ||
21662 | case NT_GNU_HWCAP: | |
21663 | { | |
21664 | unsigned int num_entries, mask; | |
21665 | ||
21666 | /* Hardware capabilities information. Word 0 is the number of entries. | |
21667 | Word 1 is a bitmask of enabled entries. The rest of the descriptor | |
21668 | is a series of entries, where each entry is a single byte followed | |
21669 | by a nul terminated string. The byte gives the bit number to test | |
21670 | if enabled in the bitmask. */ | |
21671 | printf (_(" Hardware Capabilities: ")); | |
21672 | if (pnote->descsz < 8) | |
21673 | { | |
21674 | error (_("<corrupt GNU_HWCAP>\n")); | |
21675 | return false; | |
21676 | } | |
21677 | num_entries = byte_get ((unsigned char *) pnote->descdata, 4); | |
21678 | mask = byte_get ((unsigned char *) pnote->descdata + 4, 4); | |
21679 | printf (_("num entries: %d, enabled mask: %x\n"), num_entries, mask); | |
21680 | /* FIXME: Add code to display the entries... */ | |
21681 | } | |
21682 | break; | |
21683 | ||
21684 | case NT_GNU_PROPERTY_TYPE_0: | |
21685 | print_gnu_property_note (filedata, pnote); | |
21686 | break; | |
21687 | ||
21688 | default: | |
21689 | /* Handle unrecognised types. An error message should have already been | |
21690 | created by get_gnu_elf_note_type(), so all that we need to do is to | |
21691 | display the data. */ | |
21692 | { | |
21693 | size_t i; | |
21694 | ||
21695 | printf (_(" Description data: ")); | |
21696 | for (i = 0; i < pnote->descsz; ++i) | |
21697 | printf ("%02x ", pnote->descdata[i] & 0xff); | |
21698 | printf ("\n"); | |
21699 | } | |
21700 | break; | |
21701 | } | |
21702 | ||
21703 | return true; | |
21704 | } | |
21705 | ||
21706 | static const char * | |
21707 | get_v850_elf_note_type (enum v850_notes n_type) | |
21708 | { | |
21709 | static char buff[64]; | |
21710 | ||
21711 | switch (n_type) | |
21712 | { | |
21713 | case V850_NOTE_ALIGNMENT: return _("Alignment of 8-byte objects"); | |
21714 | case V850_NOTE_DATA_SIZE: return _("Sizeof double and long double"); | |
21715 | case V850_NOTE_FPU_INFO: return _("Type of FPU support needed"); | |
21716 | case V850_NOTE_SIMD_INFO: return _("Use of SIMD instructions"); | |
21717 | case V850_NOTE_CACHE_INFO: return _("Use of cache"); | |
21718 | case V850_NOTE_MMU_INFO: return _("Use of MMU"); | |
21719 | default: | |
21720 | snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), n_type); | |
21721 | return buff; | |
21722 | } | |
21723 | } | |
21724 | ||
21725 | static bool | |
21726 | print_v850_note (Elf_Internal_Note * pnote) | |
21727 | { | |
21728 | unsigned int val; | |
21729 | ||
21730 | if (pnote->descsz != 4) | |
21731 | return false; | |
21732 | ||
21733 | val = byte_get ((unsigned char *) pnote->descdata, pnote->descsz); | |
21734 | ||
21735 | if (val == 0) | |
21736 | { | |
21737 | printf (_("not set\n")); | |
21738 | return true; | |
21739 | } | |
21740 | ||
21741 | switch (pnote->type) | |
21742 | { | |
21743 | case V850_NOTE_ALIGNMENT: | |
21744 | switch (val) | |
21745 | { | |
21746 | case EF_RH850_DATA_ALIGN4: printf (_("4-byte\n")); return true; | |
21747 | case EF_RH850_DATA_ALIGN8: printf (_("8-byte\n")); return true; | |
21748 | } | |
21749 | break; | |
21750 | ||
21751 | case V850_NOTE_DATA_SIZE: | |
21752 | switch (val) | |
21753 | { | |
21754 | case EF_RH850_DOUBLE32: printf (_("4-bytes\n")); return true; | |
21755 | case EF_RH850_DOUBLE64: printf (_("8-bytes\n")); return true; | |
21756 | } | |
21757 | break; | |
21758 | ||
21759 | case V850_NOTE_FPU_INFO: | |
21760 | switch (val) | |
21761 | { | |
21762 | case EF_RH850_FPU20: printf (_("FPU-2.0\n")); return true; | |
21763 | case EF_RH850_FPU30: printf (_("FPU-3.0\n")); return true; | |
21764 | } | |
21765 | break; | |
21766 | ||
21767 | case V850_NOTE_MMU_INFO: | |
21768 | case V850_NOTE_CACHE_INFO: | |
21769 | case V850_NOTE_SIMD_INFO: | |
21770 | if (val == EF_RH850_SIMD) | |
21771 | { | |
21772 | printf (_("yes\n")); | |
21773 | return true; | |
21774 | } | |
21775 | break; | |
21776 | ||
21777 | default: | |
21778 | /* An 'unknown note type' message will already have been displayed. */ | |
21779 | break; | |
21780 | } | |
21781 | ||
21782 | printf (_("unknown value: %x\n"), val); | |
21783 | return false; | |
21784 | } | |
21785 | ||
21786 | static bool | |
21787 | process_netbsd_elf_note (Elf_Internal_Note * pnote) | |
21788 | { | |
21789 | unsigned int version; | |
21790 | ||
21791 | switch (pnote->type) | |
21792 | { | |
21793 | case NT_NETBSD_IDENT: | |
21794 | if (pnote->descsz < 1) | |
21795 | break; | |
21796 | version = byte_get ((unsigned char *) pnote->descdata, sizeof (version)); | |
21797 | if ((version / 10000) % 100) | |
21798 | printf (" NetBSD\t\t0x%08lx\tIDENT %u (%u.%u%s%c)\n", pnote->descsz, | |
21799 | version, version / 100000000, (version / 1000000) % 100, | |
21800 | (version / 10000) % 100 > 26 ? "Z" : "", | |
21801 | 'A' + (version / 10000) % 26); | |
21802 | else | |
21803 | printf (" NetBSD\t\t0x%08lx\tIDENT %u (%u.%u.%u)\n", pnote->descsz, | |
21804 | version, version / 100000000, (version / 1000000) % 100, | |
21805 | (version / 100) % 100); | |
21806 | return true; | |
21807 | ||
21808 | case NT_NETBSD_MARCH: | |
21809 | printf (" NetBSD\t\t0x%08lx\tMARCH <%s>\n", pnote->descsz, | |
21810 | pnote->descdata); | |
21811 | return true; | |
21812 | ||
21813 | case NT_NETBSD_PAX: | |
21814 | if (pnote->descsz < 1) | |
21815 | break; | |
21816 | version = byte_get ((unsigned char *) pnote->descdata, sizeof (version)); | |
21817 | printf (" NetBSD\t\t0x%08lx\tPaX <%s%s%s%s%s%s>\n", pnote->descsz, | |
21818 | ((version & NT_NETBSD_PAX_MPROTECT) ? "+mprotect" : ""), | |
21819 | ((version & NT_NETBSD_PAX_NOMPROTECT) ? "-mprotect" : ""), | |
21820 | ((version & NT_NETBSD_PAX_GUARD) ? "+guard" : ""), | |
21821 | ((version & NT_NETBSD_PAX_NOGUARD) ? "-guard" : ""), | |
21822 | ((version & NT_NETBSD_PAX_ASLR) ? "+ASLR" : ""), | |
21823 | ((version & NT_NETBSD_PAX_NOASLR) ? "-ASLR" : "")); | |
21824 | return true; | |
21825 | } | |
21826 | ||
21827 | printf (" NetBSD\t0x%08lx\tUnknown note type: (0x%08lx)\n", | |
21828 | pnote->descsz, pnote->type); | |
21829 | return false; | |
21830 | } | |
21831 | ||
21832 | static const char * | |
21833 | get_freebsd_elfcore_note_type (Filedata * filedata, unsigned e_type) | |
21834 | { | |
21835 | switch (e_type) | |
21836 | { | |
21837 | case NT_FREEBSD_THRMISC: | |
21838 | return _("NT_THRMISC (thrmisc structure)"); | |
21839 | case NT_FREEBSD_PROCSTAT_PROC: | |
21840 | return _("NT_PROCSTAT_PROC (proc data)"); | |
21841 | case NT_FREEBSD_PROCSTAT_FILES: | |
21842 | return _("NT_PROCSTAT_FILES (files data)"); | |
21843 | case NT_FREEBSD_PROCSTAT_VMMAP: | |
21844 | return _("NT_PROCSTAT_VMMAP (vmmap data)"); | |
21845 | case NT_FREEBSD_PROCSTAT_GROUPS: | |
21846 | return _("NT_PROCSTAT_GROUPS (groups data)"); | |
21847 | case NT_FREEBSD_PROCSTAT_UMASK: | |
21848 | return _("NT_PROCSTAT_UMASK (umask data)"); | |
21849 | case NT_FREEBSD_PROCSTAT_RLIMIT: | |
21850 | return _("NT_PROCSTAT_RLIMIT (rlimit data)"); | |
21851 | case NT_FREEBSD_PROCSTAT_OSREL: | |
21852 | return _("NT_PROCSTAT_OSREL (osreldate data)"); | |
21853 | case NT_FREEBSD_PROCSTAT_PSSTRINGS: | |
21854 | return _("NT_PROCSTAT_PSSTRINGS (ps_strings data)"); | |
21855 | case NT_FREEBSD_PROCSTAT_AUXV: | |
21856 | return _("NT_PROCSTAT_AUXV (auxv data)"); | |
21857 | case NT_FREEBSD_PTLWPINFO: | |
21858 | return _("NT_PTLWPINFO (ptrace_lwpinfo structure)"); | |
21859 | case NT_FREEBSD_X86_SEGBASES: | |
21860 | return _("NT_X86_SEGBASES (x86 segment base registers)"); | |
21861 | } | |
21862 | return get_note_type (filedata, e_type); | |
21863 | } | |
21864 | ||
21865 | static const char * | |
21866 | get_netbsd_elfcore_note_type (Filedata * filedata, unsigned e_type) | |
21867 | { | |
21868 | static char buff[64]; | |
21869 | ||
21870 | switch (e_type) | |
21871 | { | |
21872 | case NT_NETBSDCORE_PROCINFO: | |
21873 | /* NetBSD core "procinfo" structure. */ | |
21874 | return _("NetBSD procinfo structure"); | |
21875 | ||
21876 | case NT_NETBSDCORE_AUXV: | |
21877 | return _("NetBSD ELF auxiliary vector data"); | |
21878 | ||
21879 | case NT_NETBSDCORE_LWPSTATUS: | |
21880 | return _("PT_LWPSTATUS (ptrace_lwpstatus structure)"); | |
21881 | ||
21882 | default: | |
21883 | /* As of Jan 2020 there are no other machine-independent notes | |
21884 | defined for NetBSD core files. If the note type is less | |
21885 | than the start of the machine-dependent note types, we don't | |
21886 | understand it. */ | |
21887 | ||
21888 | if (e_type < NT_NETBSDCORE_FIRSTMACH) | |
21889 | { | |
21890 | snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type); | |
21891 | return buff; | |
21892 | } | |
21893 | break; | |
21894 | } | |
21895 | ||
21896 | switch (filedata->file_header.e_machine) | |
21897 | { | |
21898 | /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0 | |
21899 | and PT_GETFPREGS == mach+2. */ | |
21900 | ||
21901 | case EM_OLD_ALPHA: | |
21902 | case EM_ALPHA: | |
21903 | case EM_SPARC: | |
21904 | case EM_SPARC32PLUS: | |
21905 | case EM_SPARCV9: | |
21906 | switch (e_type) | |
21907 | { | |
21908 | case NT_NETBSDCORE_FIRSTMACH + 0: | |
21909 | return _("PT_GETREGS (reg structure)"); | |
21910 | case NT_NETBSDCORE_FIRSTMACH + 2: | |
21911 | return _("PT_GETFPREGS (fpreg structure)"); | |
21912 | default: | |
21913 | break; | |
21914 | } | |
21915 | break; | |
21916 | ||
21917 | /* On SuperH, PT_GETREGS == mach+3 and PT_GETFPREGS == mach+5. | |
21918 | There's also old PT___GETREGS40 == mach + 1 for old reg | |
21919 | structure which lacks GBR. */ | |
21920 | case EM_SH: | |
21921 | switch (e_type) | |
21922 | { | |
21923 | case NT_NETBSDCORE_FIRSTMACH + 1: | |
21924 | return _("PT___GETREGS40 (old reg structure)"); | |
21925 | case NT_NETBSDCORE_FIRSTMACH + 3: | |
21926 | return _("PT_GETREGS (reg structure)"); | |
21927 | case NT_NETBSDCORE_FIRSTMACH + 5: | |
21928 | return _("PT_GETFPREGS (fpreg structure)"); | |
21929 | default: | |
21930 | break; | |
21931 | } | |
21932 | break; | |
21933 | ||
21934 | /* On all other arch's, PT_GETREGS == mach+1 and | |
21935 | PT_GETFPREGS == mach+3. */ | |
21936 | default: | |
21937 | switch (e_type) | |
21938 | { | |
21939 | case NT_NETBSDCORE_FIRSTMACH + 1: | |
21940 | return _("PT_GETREGS (reg structure)"); | |
21941 | case NT_NETBSDCORE_FIRSTMACH + 3: | |
21942 | return _("PT_GETFPREGS (fpreg structure)"); | |
21943 | default: | |
21944 | break; | |
21945 | } | |
21946 | } | |
21947 | ||
21948 | snprintf (buff, sizeof (buff), "PT_FIRSTMACH+%d", | |
21949 | e_type - NT_NETBSDCORE_FIRSTMACH); | |
21950 | return buff; | |
21951 | } | |
21952 | ||
21953 | static const char * | |
21954 | get_openbsd_elfcore_note_type (Filedata * filedata, unsigned e_type) | |
21955 | { | |
21956 | switch (e_type) | |
21957 | { | |
21958 | case NT_OPENBSD_PROCINFO: | |
21959 | return _("OpenBSD procinfo structure"); | |
21960 | case NT_OPENBSD_AUXV: | |
21961 | return _("OpenBSD ELF auxiliary vector data"); | |
21962 | case NT_OPENBSD_REGS: | |
21963 | return _("OpenBSD regular registers"); | |
21964 | case NT_OPENBSD_FPREGS: | |
21965 | return _("OpenBSD floating point registers"); | |
21966 | case NT_OPENBSD_WCOOKIE: | |
21967 | return _("OpenBSD window cookie"); | |
21968 | } | |
21969 | ||
21970 | return get_note_type (filedata, e_type); | |
21971 | } | |
21972 | ||
21973 | static const char * | |
21974 | get_qnx_elfcore_note_type (Filedata * filedata, unsigned e_type) | |
21975 | { | |
21976 | switch (e_type) | |
21977 | { | |
21978 | case QNT_DEBUG_FULLPATH: | |
21979 | return _("QNX debug fullpath"); | |
21980 | case QNT_DEBUG_RELOC: | |
21981 | return _("QNX debug relocation"); | |
21982 | case QNT_STACK: | |
21983 | return _("QNX stack"); | |
21984 | case QNT_GENERATOR: | |
21985 | return _("QNX generator"); | |
21986 | case QNT_DEFAULT_LIB: | |
21987 | return _("QNX default library"); | |
21988 | case QNT_CORE_SYSINFO: | |
21989 | return _("QNX core sysinfo"); | |
21990 | case QNT_CORE_INFO: | |
21991 | return _("QNX core info"); | |
21992 | case QNT_CORE_STATUS: | |
21993 | return _("QNX core status"); | |
21994 | case QNT_CORE_GREG: | |
21995 | return _("QNX general registers"); | |
21996 | case QNT_CORE_FPREG: | |
21997 | return _("QNX floating point registers"); | |
21998 | case QNT_LINK_MAP: | |
21999 | return _("QNX link map"); | |
22000 | } | |
22001 | ||
22002 | return get_note_type (filedata, e_type); | |
22003 | } | |
22004 | ||
22005 | static const char * | |
22006 | get_stapsdt_note_type (unsigned e_type) | |
22007 | { | |
22008 | static char buff[64]; | |
22009 | ||
22010 | switch (e_type) | |
22011 | { | |
22012 | case NT_STAPSDT: | |
22013 | return _("NT_STAPSDT (SystemTap probe descriptors)"); | |
22014 | ||
22015 | default: | |
22016 | break; | |
22017 | } | |
22018 | ||
22019 | snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type); | |
22020 | return buff; | |
22021 | } | |
22022 | ||
22023 | static bool | |
22024 | print_stapsdt_note (Elf_Internal_Note *pnote) | |
22025 | { | |
22026 | size_t len, maxlen; | |
22027 | size_t addr_size = is_32bit_elf ? 4 : 8; | |
22028 | char *data = pnote->descdata; | |
22029 | char *data_end = pnote->descdata + pnote->descsz; | |
22030 | uint64_t pc, base_addr, semaphore; | |
22031 | char *provider, *probe, *arg_fmt; | |
22032 | ||
22033 | if (pnote->descsz < (addr_size * 3)) | |
22034 | goto stapdt_note_too_small; | |
22035 | ||
22036 | pc = byte_get ((unsigned char *) data, addr_size); | |
22037 | data += addr_size; | |
22038 | ||
22039 | base_addr = byte_get ((unsigned char *) data, addr_size); | |
22040 | data += addr_size; | |
22041 | ||
22042 | semaphore = byte_get ((unsigned char *) data, addr_size); | |
22043 | data += addr_size; | |
22044 | ||
22045 | if (data >= data_end) | |
22046 | goto stapdt_note_too_small; | |
22047 | maxlen = data_end - data; | |
22048 | len = strnlen (data, maxlen); | |
22049 | if (len < maxlen) | |
22050 | { | |
22051 | provider = data; | |
22052 | data += len + 1; | |
22053 | } | |
22054 | else | |
22055 | goto stapdt_note_too_small; | |
22056 | ||
22057 | if (data >= data_end) | |
22058 | goto stapdt_note_too_small; | |
22059 | maxlen = data_end - data; | |
22060 | len = strnlen (data, maxlen); | |
22061 | if (len < maxlen) | |
22062 | { | |
22063 | probe = data; | |
22064 | data += len + 1; | |
22065 | } | |
22066 | else | |
22067 | goto stapdt_note_too_small; | |
22068 | ||
22069 | if (data >= data_end) | |
22070 | goto stapdt_note_too_small; | |
22071 | maxlen = data_end - data; | |
22072 | len = strnlen (data, maxlen); | |
22073 | if (len < maxlen) | |
22074 | { | |
22075 | arg_fmt = data; | |
22076 | data += len + 1; | |
22077 | } | |
22078 | else | |
22079 | goto stapdt_note_too_small; | |
22080 | ||
22081 | printf (_(" Provider: %s\n"), provider); | |
22082 | printf (_(" Name: %s\n"), probe); | |
22083 | printf (_(" Location: ")); | |
22084 | print_vma (pc, FULL_HEX); | |
22085 | printf (_(", Base: ")); | |
22086 | print_vma (base_addr, FULL_HEX); | |
22087 | printf (_(", Semaphore: ")); | |
22088 | print_vma (semaphore, FULL_HEX); | |
22089 | printf ("\n"); | |
22090 | printf (_(" Arguments: %s\n"), arg_fmt); | |
22091 | ||
22092 | return data == data_end; | |
22093 | ||
22094 | stapdt_note_too_small: | |
22095 | printf (_(" <corrupt - note is too small>\n")); | |
22096 | error (_("corrupt stapdt note - the data size is too small\n")); | |
22097 | return false; | |
22098 | } | |
22099 | ||
22100 | static bool | |
22101 | print_fdo_note (Elf_Internal_Note * pnote) | |
22102 | { | |
22103 | if (pnote->descsz > 0 && pnote->type == FDO_PACKAGING_METADATA) | |
22104 | { | |
22105 | printf (_(" Packaging Metadata: %.*s\n"), (int) pnote->descsz, pnote->descdata); | |
22106 | return true; | |
22107 | } | |
22108 | if (pnote->descsz > 0 && pnote->type == FDO_DLOPEN_METADATA) | |
22109 | { | |
22110 | printf (_(" Dlopen Metadata: %.*s\n"), (int) pnote->descsz, pnote->descdata); | |
22111 | return true; | |
22112 | } | |
22113 | return false; | |
22114 | } | |
22115 | ||
22116 | static const char * | |
22117 | get_ia64_vms_note_type (unsigned e_type) | |
22118 | { | |
22119 | static char buff[64]; | |
22120 | ||
22121 | switch (e_type) | |
22122 | { | |
22123 | case NT_VMS_MHD: | |
22124 | return _("NT_VMS_MHD (module header)"); | |
22125 | case NT_VMS_LNM: | |
22126 | return _("NT_VMS_LNM (language name)"); | |
22127 | case NT_VMS_SRC: | |
22128 | return _("NT_VMS_SRC (source files)"); | |
22129 | case NT_VMS_TITLE: | |
22130 | return "NT_VMS_TITLE"; | |
22131 | case NT_VMS_EIDC: | |
22132 | return _("NT_VMS_EIDC (consistency check)"); | |
22133 | case NT_VMS_FPMODE: | |
22134 | return _("NT_VMS_FPMODE (FP mode)"); | |
22135 | case NT_VMS_LINKTIME: | |
22136 | return "NT_VMS_LINKTIME"; | |
22137 | case NT_VMS_IMGNAM: | |
22138 | return _("NT_VMS_IMGNAM (image name)"); | |
22139 | case NT_VMS_IMGID: | |
22140 | return _("NT_VMS_IMGID (image id)"); | |
22141 | case NT_VMS_LINKID: | |
22142 | return _("NT_VMS_LINKID (link id)"); | |
22143 | case NT_VMS_IMGBID: | |
22144 | return _("NT_VMS_IMGBID (build id)"); | |
22145 | case NT_VMS_GSTNAM: | |
22146 | return _("NT_VMS_GSTNAM (sym table name)"); | |
22147 | case NT_VMS_ORIG_DYN: | |
22148 | return "NT_VMS_ORIG_DYN"; | |
22149 | case NT_VMS_PATCHTIME: | |
22150 | return "NT_VMS_PATCHTIME"; | |
22151 | default: | |
22152 | snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type); | |
22153 | return buff; | |
22154 | } | |
22155 | } | |
22156 | ||
22157 | static bool | |
22158 | print_ia64_vms_note (Elf_Internal_Note * pnote) | |
22159 | { | |
22160 | unsigned int maxlen = pnote->descsz; | |
22161 | ||
22162 | if (maxlen < 2 || maxlen != pnote->descsz) | |
22163 | goto desc_size_fail; | |
22164 | ||
22165 | switch (pnote->type) | |
22166 | { | |
22167 | case NT_VMS_MHD: | |
22168 | if (maxlen <= 36) | |
22169 | goto desc_size_fail; | |
22170 | ||
22171 | size_t l = strnlen (pnote->descdata + 34, maxlen - 34); | |
22172 | ||
22173 | printf (_(" Creation date : %.17s\n"), pnote->descdata); | |
22174 | printf (_(" Last patch date: %.17s\n"), pnote->descdata + 17); | |
22175 | if (l + 34 < maxlen) | |
22176 | { | |
22177 | printf (_(" Module name : %s\n"), pnote->descdata + 34); | |
22178 | if (l + 35 < maxlen) | |
22179 | printf (_(" Module version : %s\n"), pnote->descdata + 34 + l + 1); | |
22180 | else | |
22181 | printf (_(" Module version : <missing>\n")); | |
22182 | } | |
22183 | else | |
22184 | { | |
22185 | printf (_(" Module name : <missing>\n")); | |
22186 | printf (_(" Module version : <missing>\n")); | |
22187 | } | |
22188 | break; | |
22189 | ||
22190 | case NT_VMS_LNM: | |
22191 | printf (_(" Language: %.*s\n"), maxlen, pnote->descdata); | |
22192 | break; | |
22193 | ||
22194 | case NT_VMS_FPMODE: | |
22195 | printf (_(" Floating Point mode: ")); | |
22196 | if (maxlen < 8) | |
22197 | goto desc_size_fail; | |
22198 | /* FIXME: Generate an error if descsz > 8 ? */ | |
22199 | ||
22200 | printf ("0x%016" PRIx64 "\n", | |
22201 | byte_get ((unsigned char *) pnote->descdata, 8)); | |
22202 | break; | |
22203 | ||
22204 | case NT_VMS_LINKTIME: | |
22205 | printf (_(" Link time: ")); | |
22206 | if (maxlen < 8) | |
22207 | goto desc_size_fail; | |
22208 | /* FIXME: Generate an error if descsz > 8 ? */ | |
22209 | ||
22210 | print_vms_time (byte_get ((unsigned char *) pnote->descdata, 8)); | |
22211 | printf ("\n"); | |
22212 | break; | |
22213 | ||
22214 | case NT_VMS_PATCHTIME: | |
22215 | printf (_(" Patch time: ")); | |
22216 | if (maxlen < 8) | |
22217 | goto desc_size_fail; | |
22218 | /* FIXME: Generate an error if descsz > 8 ? */ | |
22219 | ||
22220 | print_vms_time (byte_get ((unsigned char *) pnote->descdata, 8)); | |
22221 | printf ("\n"); | |
22222 | break; | |
22223 | ||
22224 | case NT_VMS_ORIG_DYN: | |
22225 | if (maxlen < 34) | |
22226 | goto desc_size_fail; | |
22227 | ||
22228 | printf (_(" Major id: %u, minor id: %u\n"), | |
22229 | (unsigned) byte_get ((unsigned char *) pnote->descdata, 4), | |
22230 | (unsigned) byte_get ((unsigned char *) pnote->descdata + 4, 4)); | |
22231 | printf (_(" Last modified : ")); | |
22232 | print_vms_time (byte_get ((unsigned char *) pnote->descdata + 8, 8)); | |
22233 | printf (_("\n Link flags : ")); | |
22234 | printf ("0x%016" PRIx64 "\n", | |
22235 | byte_get ((unsigned char *) pnote->descdata + 16, 8)); | |
22236 | printf (_(" Header flags: 0x%08x\n"), | |
22237 | (unsigned) byte_get ((unsigned char *) pnote->descdata + 24, 4)); | |
22238 | printf (_(" Image id : %.*s\n"), maxlen - 32, pnote->descdata + 32); | |
22239 | break; | |
22240 | ||
22241 | case NT_VMS_IMGNAM: | |
22242 | printf (_(" Image name: %.*s\n"), maxlen, pnote->descdata); | |
22243 | break; | |
22244 | ||
22245 | case NT_VMS_GSTNAM: | |
22246 | printf (_(" Global symbol table name: %.*s\n"), maxlen, pnote->descdata); | |
22247 | break; | |
22248 | ||
22249 | case NT_VMS_IMGID: | |
22250 | printf (_(" Image id: %.*s\n"), maxlen, pnote->descdata); | |
22251 | break; | |
22252 | ||
22253 | case NT_VMS_LINKID: | |
22254 | printf (_(" Linker id: %.*s\n"), maxlen, pnote->descdata); | |
22255 | break; | |
22256 | ||
22257 | default: | |
22258 | return false; | |
22259 | } | |
22260 | ||
22261 | return true; | |
22262 | ||
22263 | desc_size_fail: | |
22264 | printf (_(" <corrupt - data size is too small>\n")); | |
22265 | error (_("corrupt IA64 note: data size is too small\n")); | |
22266 | return false; | |
22267 | } | |
22268 | ||
22269 | struct build_attr_cache { | |
22270 | Filedata *filedata; | |
22271 | char *strtab; | |
22272 | uint64_t strtablen; | |
22273 | Elf_Internal_Sym *symtab; | |
22274 | uint64_t nsyms; | |
22275 | } ba_cache; | |
22276 | ||
22277 | /* Find the symbol associated with a build attribute that is attached | |
22278 | to address OFFSET. If PNAME is non-NULL then store the name of | |
22279 | the symbol (if found) in the provided pointer, Returns NULL if a | |
22280 | symbol could not be found. */ | |
22281 | ||
22282 | static Elf_Internal_Sym * | |
22283 | get_symbol_for_build_attribute (Filedata *filedata, | |
22284 | uint64_t offset, | |
22285 | bool is_open_attr, | |
22286 | const char **pname) | |
22287 | { | |
22288 | Elf_Internal_Sym *saved_sym = NULL; | |
22289 | Elf_Internal_Sym *sym; | |
22290 | ||
22291 | if (filedata->section_headers != NULL | |
22292 | && (ba_cache.filedata == NULL || filedata != ba_cache.filedata)) | |
22293 | { | |
22294 | Elf_Internal_Shdr * symsec; | |
22295 | ||
22296 | free (ba_cache.strtab); | |
22297 | ba_cache.strtab = NULL; | |
22298 | free (ba_cache.symtab); | |
22299 | ba_cache.symtab = NULL; | |
22300 | ||
22301 | /* Load the symbol and string sections. */ | |
22302 | for (symsec = filedata->section_headers; | |
22303 | symsec < filedata->section_headers + filedata->file_header.e_shnum; | |
22304 | symsec ++) | |
22305 | { | |
22306 | if (symsec->sh_type == SHT_SYMTAB | |
22307 | && get_symtab (filedata, symsec, | |
22308 | &ba_cache.symtab, &ba_cache.nsyms, | |
22309 | &ba_cache.strtab, &ba_cache.strtablen)) | |
22310 | break; | |
22311 | } | |
22312 | ba_cache.filedata = filedata; | |
22313 | } | |
22314 | ||
22315 | if (ba_cache.symtab == NULL) | |
22316 | return NULL; | |
22317 | ||
22318 | /* Find a symbol whose value matches offset. */ | |
22319 | for (sym = ba_cache.symtab; sym < ba_cache.symtab + ba_cache.nsyms; sym ++) | |
22320 | if (sym->st_value == offset) | |
22321 | { | |
22322 | if (sym->st_name >= ba_cache.strtablen) | |
22323 | /* Huh ? This should not happen. */ | |
22324 | continue; | |
22325 | ||
22326 | if (ba_cache.strtab[sym->st_name] == 0) | |
22327 | continue; | |
22328 | ||
22329 | /* The AArch64, ARM and RISC-V architectures define mapping symbols | |
22330 | (eg $d, $x, $t) which we want to ignore. */ | |
22331 | if (ba_cache.strtab[sym->st_name] == '$' | |
22332 | && ba_cache.strtab[sym->st_name + 1] != 0 | |
22333 | && ba_cache.strtab[sym->st_name + 2] == 0) | |
22334 | continue; | |
22335 | ||
22336 | if (is_open_attr) | |
22337 | { | |
22338 | /* For OPEN attributes we prefer GLOBAL over LOCAL symbols | |
22339 | and FILE or OBJECT symbols over NOTYPE symbols. We skip | |
22340 | FUNC symbols entirely. */ | |
22341 | switch (ELF_ST_TYPE (sym->st_info)) | |
22342 | { | |
22343 | case STT_OBJECT: | |
22344 | case STT_FILE: | |
22345 | saved_sym = sym; | |
22346 | if (sym->st_size) | |
22347 | { | |
22348 | /* If the symbol has a size associated | |
22349 | with it then we can stop searching. */ | |
22350 | sym = ba_cache.symtab + ba_cache.nsyms; | |
22351 | } | |
22352 | continue; | |
22353 | ||
22354 | case STT_FUNC: | |
22355 | /* Ignore function symbols. */ | |
22356 | continue; | |
22357 | ||
22358 | default: | |
22359 | break; | |
22360 | } | |
22361 | ||
22362 | switch (ELF_ST_BIND (sym->st_info)) | |
22363 | { | |
22364 | case STB_GLOBAL: | |
22365 | if (saved_sym == NULL | |
22366 | || ELF_ST_TYPE (saved_sym->st_info) != STT_OBJECT) | |
22367 | saved_sym = sym; | |
22368 | break; | |
22369 | ||
22370 | case STB_LOCAL: | |
22371 | if (saved_sym == NULL) | |
22372 | saved_sym = sym; | |
22373 | break; | |
22374 | ||
22375 | default: | |
22376 | break; | |
22377 | } | |
22378 | } | |
22379 | else | |
22380 | { | |
22381 | if (ELF_ST_TYPE (sym->st_info) != STT_FUNC) | |
22382 | continue; | |
22383 | ||
22384 | saved_sym = sym; | |
22385 | break; | |
22386 | } | |
22387 | } | |
22388 | ||
22389 | if (saved_sym && pname) | |
22390 | * pname = ba_cache.strtab + saved_sym->st_name; | |
22391 | ||
22392 | return saved_sym; | |
22393 | } | |
22394 | ||
22395 | /* Returns true iff addr1 and addr2 are in the same section. */ | |
22396 | ||
22397 | static bool | |
22398 | same_section (Filedata * filedata, uint64_t addr1, uint64_t addr2) | |
22399 | { | |
22400 | Elf_Internal_Shdr * a1; | |
22401 | Elf_Internal_Shdr * a2; | |
22402 | ||
22403 | a1 = find_section_by_address (filedata, addr1); | |
22404 | a2 = find_section_by_address (filedata, addr2); | |
22405 | ||
22406 | return a1 == a2 && a1 != NULL; | |
22407 | } | |
22408 | ||
22409 | static bool | |
22410 | print_gnu_build_attribute_description (Elf_Internal_Note * pnote, | |
22411 | Filedata * filedata) | |
22412 | { | |
22413 | static uint64_t global_offset = 0; | |
22414 | static uint64_t global_end = 0; | |
22415 | static uint64_t func_offset = 0; | |
22416 | static uint64_t func_end = 0; | |
22417 | ||
22418 | Elf_Internal_Sym *sym; | |
22419 | const char *name; | |
22420 | uint64_t start; | |
22421 | uint64_t end; | |
22422 | bool is_open_attr = pnote->type == NT_GNU_BUILD_ATTRIBUTE_OPEN; | |
22423 | ||
22424 | switch (pnote->descsz) | |
22425 | { | |
22426 | case 0: | |
22427 | /* A zero-length description means that the range of | |
22428 | the previous note of the same type should be used. */ | |
22429 | if (is_open_attr) | |
22430 | { | |
22431 | if (global_end > global_offset) | |
22432 | printf (_(" Applies to region from %#" PRIx64 | |
22433 | " to %#" PRIx64 "\n"), global_offset, global_end); | |
22434 | else | |
22435 | printf (_(" Applies to region from %#" PRIx64 | |
22436 | "\n"), global_offset); | |
22437 | } | |
22438 | else | |
22439 | { | |
22440 | if (func_end > func_offset) | |
22441 | printf (_(" Applies to region from %#" PRIx64 | |
22442 | " to %#" PRIx64 "\n"), func_offset, func_end); | |
22443 | else | |
22444 | printf (_(" Applies to region from %#" PRIx64 | |
22445 | "\n"), func_offset); | |
22446 | } | |
22447 | return true; | |
22448 | ||
22449 | case 4: | |
22450 | start = byte_get ((unsigned char *) pnote->descdata, 4); | |
22451 | end = 0; | |
22452 | break; | |
22453 | ||
22454 | case 8: | |
22455 | start = byte_get ((unsigned char *) pnote->descdata, 4); | |
22456 | end = byte_get ((unsigned char *) pnote->descdata + 4, 4); | |
22457 | break; | |
22458 | ||
22459 | case 16: | |
22460 | start = byte_get ((unsigned char *) pnote->descdata, 8); | |
22461 | end = byte_get ((unsigned char *) pnote->descdata + 8, 8); | |
22462 | break; | |
22463 | ||
22464 | default: | |
22465 | error (_(" <invalid description size: %lx>\n"), pnote->descsz); | |
22466 | printf (_(" <invalid descsz>")); | |
22467 | return false; | |
22468 | } | |
22469 | ||
22470 | name = NULL; | |
22471 | sym = get_symbol_for_build_attribute (filedata, start, is_open_attr, & name); | |
22472 | /* As of version 5 of the annobin plugin, filename symbols are biased by 2 | |
22473 | in order to avoid them being confused with the start address of the | |
22474 | first function in the file... */ | |
22475 | if (sym == NULL && is_open_attr) | |
22476 | sym = get_symbol_for_build_attribute (filedata, start + 2, is_open_attr, | |
22477 | & name); | |
22478 | ||
22479 | if (end == 0 && sym != NULL && sym->st_size > 0) | |
22480 | end = start + sym->st_size; | |
22481 | ||
22482 | if (is_open_attr) | |
22483 | { | |
22484 | /* FIXME: Need to properly allow for section alignment. | |
22485 | 16 is just the alignment used on x86_64. */ | |
22486 | if (global_end > 0 | |
22487 | && start > BFD_ALIGN (global_end, 16) | |
22488 | /* Build notes are not guaranteed to be organised in order of | |
22489 | increasing address, but we should find the all of the notes | |
22490 | for one section in the same place. */ | |
22491 | && same_section (filedata, start, global_end)) | |
22492 | warn (_("Gap in build notes detected from %#" PRIx64 | |
22493 | " to %#" PRIx64 "\n"), | |
22494 | global_end + 1, start - 1); | |
22495 | ||
22496 | printf (_(" Applies to region from %#" PRIx64), start); | |
22497 | global_offset = start; | |
22498 | ||
22499 | if (end) | |
22500 | { | |
22501 | printf (_(" to %#" PRIx64), end); | |
22502 | global_end = end; | |
22503 | } | |
22504 | } | |
22505 | else | |
22506 | { | |
22507 | printf (_(" Applies to region from %#" PRIx64), start); | |
22508 | func_offset = start; | |
22509 | ||
22510 | if (end) | |
22511 | { | |
22512 | printf (_(" to %#" PRIx64), end); | |
22513 | func_end = end; | |
22514 | } | |
22515 | } | |
22516 | ||
22517 | if (sym && name) | |
22518 | printf (_(" (%s)"), name); | |
22519 | ||
22520 | printf ("\n"); | |
22521 | return true; | |
22522 | } | |
22523 | ||
22524 | static bool | |
22525 | print_gnu_build_attribute_name (Elf_Internal_Note * pnote) | |
22526 | { | |
22527 | static const char string_expected [2] = { GNU_BUILD_ATTRIBUTE_TYPE_STRING, 0 }; | |
22528 | static const char number_expected [2] = { GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC, 0 }; | |
22529 | static const char bool_expected [3] = { GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE, GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE, 0 }; | |
22530 | char name_type; | |
22531 | char name_attribute; | |
22532 | const char * expected_types; | |
22533 | const char * name = pnote->namedata; | |
22534 | const char * text; | |
22535 | signed int left; | |
22536 | ||
22537 | if (name == NULL || pnote->namesz < 2) | |
22538 | { | |
22539 | error (_("corrupt name field in GNU build attribute note: size = %ld\n"), pnote->namesz); | |
22540 | print_symbol_name (-20, _(" <corrupt name>")); | |
22541 | return false; | |
22542 | } | |
22543 | ||
22544 | if (do_wide) | |
22545 | left = 28; | |
22546 | else | |
22547 | left = 20; | |
22548 | ||
22549 | /* Version 2 of the spec adds a "GA" prefix to the name field. */ | |
22550 | if (name[0] == 'G' && name[1] == 'A') | |
22551 | { | |
22552 | if (pnote->namesz < 4) | |
22553 | { | |
22554 | error (_("corrupt name field in GNU build attribute note: size = %ld\n"), pnote->namesz); | |
22555 | print_symbol_name (-20, _(" <corrupt name>")); | |
22556 | return false; | |
22557 | } | |
22558 | ||
22559 | printf ("GA"); | |
22560 | name += 2; | |
22561 | left -= 2; | |
22562 | } | |
22563 | ||
22564 | switch ((name_type = * name)) | |
22565 | { | |
22566 | case GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC: | |
22567 | case GNU_BUILD_ATTRIBUTE_TYPE_STRING: | |
22568 | case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE: | |
22569 | case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE: | |
22570 | printf ("%c", * name); | |
22571 | left --; | |
22572 | break; | |
22573 | default: | |
22574 | error (_("unrecognised attribute type in name field: %d\n"), name_type); | |
22575 | print_symbol_name (-20, _("<unknown name type>")); | |
22576 | return false; | |
22577 | } | |
22578 | ||
22579 | ++ name; | |
22580 | text = NULL; | |
22581 | ||
22582 | switch ((name_attribute = * name)) | |
22583 | { | |
22584 | case GNU_BUILD_ATTRIBUTE_VERSION: | |
22585 | text = _("<version>"); | |
22586 | expected_types = string_expected; | |
22587 | ++ name; | |
22588 | break; | |
22589 | case GNU_BUILD_ATTRIBUTE_STACK_PROT: | |
22590 | text = _("<stack prot>"); | |
22591 | expected_types = "!+*"; | |
22592 | ++ name; | |
22593 | break; | |
22594 | case GNU_BUILD_ATTRIBUTE_RELRO: | |
22595 | text = _("<relro>"); | |
22596 | expected_types = bool_expected; | |
22597 | ++ name; | |
22598 | break; | |
22599 | case GNU_BUILD_ATTRIBUTE_STACK_SIZE: | |
22600 | text = _("<stack size>"); | |
22601 | expected_types = number_expected; | |
22602 | ++ name; | |
22603 | break; | |
22604 | case GNU_BUILD_ATTRIBUTE_TOOL: | |
22605 | text = _("<tool>"); | |
22606 | expected_types = string_expected; | |
22607 | ++ name; | |
22608 | break; | |
22609 | case GNU_BUILD_ATTRIBUTE_ABI: | |
22610 | text = _("<ABI>"); | |
22611 | expected_types = "$*"; | |
22612 | ++ name; | |
22613 | break; | |
22614 | case GNU_BUILD_ATTRIBUTE_PIC: | |
22615 | text = _("<PIC>"); | |
22616 | expected_types = number_expected; | |
22617 | ++ name; | |
22618 | break; | |
22619 | case GNU_BUILD_ATTRIBUTE_SHORT_ENUM: | |
22620 | text = _("<short enum>"); | |
22621 | expected_types = bool_expected; | |
22622 | ++ name; | |
22623 | break; | |
22624 | default: | |
22625 | if (ISPRINT (* name)) | |
22626 | { | |
22627 | int len = strnlen (name, pnote->namesz - (name - pnote->namedata)) + 1; | |
22628 | ||
22629 | if (len > left && ! do_wide) | |
22630 | len = left; | |
22631 | printf ("%.*s:", len, name); | |
22632 | left -= len; | |
22633 | name += len; | |
22634 | } | |
22635 | else | |
22636 | { | |
22637 | static char tmpbuf [128]; | |
22638 | ||
22639 | error (_("unrecognised byte in name field: %d\n"), * name); | |
22640 | sprintf (tmpbuf, _("<unknown:_%d>"), * name); | |
22641 | text = tmpbuf; | |
22642 | name ++; | |
22643 | } | |
22644 | expected_types = "*$!+"; | |
22645 | break; | |
22646 | } | |
22647 | ||
22648 | if (text) | |
22649 | left -= printf ("%s", text); | |
22650 | ||
22651 | if (strchr (expected_types, name_type) == NULL) | |
22652 | warn (_("attribute does not have an expected type (%c)\n"), name_type); | |
22653 | ||
22654 | if ((size_t) (name - pnote->namedata) > pnote->namesz) | |
22655 | { | |
22656 | error (_("corrupt name field: namesz: %lu but parsing gets to %td\n"), | |
22657 | pnote->namesz, | |
22658 | name - pnote->namedata); | |
22659 | return false; | |
22660 | } | |
22661 | ||
22662 | if (left < 1 && ! do_wide) | |
22663 | return true; | |
22664 | ||
22665 | switch (name_type) | |
22666 | { | |
22667 | case GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC: | |
22668 | { | |
22669 | unsigned int bytes; | |
22670 | uint64_t val = 0; | |
22671 | unsigned int shift = 0; | |
22672 | char *decoded = NULL; | |
22673 | ||
22674 | bytes = pnote->namesz - (name - pnote->namedata); | |
22675 | if (bytes > 0) | |
22676 | /* The -1 is because the name field is always 0 terminated, and we | |
22677 | want to be able to ensure that the shift in the while loop below | |
22678 | will not overflow. */ | |
22679 | -- bytes; | |
22680 | ||
22681 | if (bytes > sizeof (val)) | |
22682 | { | |
22683 | error (_("corrupt numeric name field: too many bytes in the value: %x\n"), | |
22684 | bytes); | |
22685 | bytes = sizeof (val); | |
22686 | } | |
22687 | /* We do not bother to warn if bytes == 0 as this can | |
22688 | happen with some early versions of the gcc plugin. */ | |
22689 | ||
22690 | while (bytes --) | |
22691 | { | |
22692 | uint64_t byte = *name++ & 0xff; | |
22693 | ||
22694 | val |= byte << shift; | |
22695 | shift += 8; | |
22696 | } | |
22697 | ||
22698 | switch (name_attribute) | |
22699 | { | |
22700 | case GNU_BUILD_ATTRIBUTE_PIC: | |
22701 | switch (val) | |
22702 | { | |
22703 | case 0: decoded = "static"; break; | |
22704 | case 1: decoded = "pic"; break; | |
22705 | case 2: decoded = "PIC"; break; | |
22706 | case 3: decoded = "pie"; break; | |
22707 | case 4: decoded = "PIE"; break; | |
22708 | default: break; | |
22709 | } | |
22710 | break; | |
22711 | case GNU_BUILD_ATTRIBUTE_STACK_PROT: | |
22712 | switch (val) | |
22713 | { | |
22714 | /* Based upon the SPCT_FLAG_xxx enum values in gcc/cfgexpand.c. */ | |
22715 | case 0: decoded = "off"; break; | |
22716 | case 1: decoded = "on"; break; | |
22717 | case 2: decoded = "all"; break; | |
22718 | case 3: decoded = "strong"; break; | |
22719 | case 4: decoded = "explicit"; break; | |
22720 | default: break; | |
22721 | } | |
22722 | break; | |
22723 | default: | |
22724 | break; | |
22725 | } | |
22726 | ||
22727 | if (decoded != NULL) | |
22728 | { | |
22729 | print_symbol_name (-left, decoded); | |
22730 | left = 0; | |
22731 | } | |
22732 | else if (val == 0) | |
22733 | { | |
22734 | printf ("0x0"); | |
22735 | left -= 3; | |
22736 | } | |
22737 | else | |
22738 | { | |
22739 | if (do_wide) | |
22740 | left -= printf ("0x%" PRIx64, val); | |
22741 | else | |
22742 | left -= printf ("0x%-.*" PRIx64, left, val); | |
22743 | } | |
22744 | } | |
22745 | break; | |
22746 | case GNU_BUILD_ATTRIBUTE_TYPE_STRING: | |
22747 | left -= print_symbol_name (- left, name); | |
22748 | break; | |
22749 | case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE: | |
22750 | left -= print_symbol_name (- left, "true"); | |
22751 | break; | |
22752 | case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE: | |
22753 | left -= print_symbol_name (- left, "false"); | |
22754 | break; | |
22755 | } | |
22756 | ||
22757 | if (do_wide && left > 0) | |
22758 | printf ("%-*s", left, " "); | |
22759 | ||
22760 | return true; | |
22761 | } | |
22762 | ||
22763 | /* Print the contents of PNOTE as hex. */ | |
22764 | ||
22765 | static void | |
22766 | print_note_contents_hex (Elf_Internal_Note *pnote) | |
22767 | { | |
22768 | if (pnote->descsz) | |
22769 | { | |
22770 | size_t i; | |
22771 | ||
22772 | printf (_(" description data: ")); | |
22773 | for (i = 0; i < pnote->descsz; i++) | |
22774 | printf ("%02x ", pnote->descdata[i] & 0xff); | |
22775 | if (!do_wide) | |
22776 | printf ("\n"); | |
22777 | } | |
22778 | ||
22779 | if (do_wide) | |
22780 | printf ("\n"); | |
22781 | } | |
22782 | ||
22783 | #if defined HAVE_MSGPACK | |
22784 | ||
22785 | static void | |
22786 | print_indents (int n) | |
22787 | { | |
22788 | printf (" "); | |
22789 | ||
22790 | for (int i = 0; i < n; i++) | |
22791 | printf (" "); | |
22792 | } | |
22793 | ||
22794 | /* Print OBJ in human-readable form. */ | |
22795 | ||
22796 | static void | |
22797 | dump_msgpack_obj (const msgpack_object *obj, int indent) | |
22798 | { | |
22799 | switch (obj->type) | |
22800 | { | |
22801 | case MSGPACK_OBJECT_NIL: | |
22802 | printf ("(nil)"); | |
22803 | break; | |
22804 | ||
22805 | case MSGPACK_OBJECT_BOOLEAN: | |
22806 | printf ("%s", obj->via.boolean ? "true" : "false"); | |
22807 | break; | |
22808 | ||
22809 | case MSGPACK_OBJECT_POSITIVE_INTEGER: | |
22810 | printf ("%" PRIu64, obj->via.u64); | |
22811 | break; | |
22812 | ||
22813 | case MSGPACK_OBJECT_NEGATIVE_INTEGER: | |
22814 | printf ("%" PRIi64, obj->via.i64); | |
22815 | break; | |
22816 | ||
22817 | case MSGPACK_OBJECT_FLOAT32: | |
22818 | case MSGPACK_OBJECT_FLOAT64: | |
22819 | printf ("%f", obj->via.f64); | |
22820 | break; | |
22821 | ||
22822 | case MSGPACK_OBJECT_STR: | |
22823 | printf ("\"%.*s\"", obj->via.str.size, obj->via.str.ptr); | |
22824 | break; | |
22825 | ||
22826 | case MSGPACK_OBJECT_ARRAY: | |
22827 | { | |
22828 | const msgpack_object_array *array = &obj->via.array; | |
22829 | ||
22830 | printf ("[\n"); | |
22831 | ++indent; | |
22832 | ||
22833 | for (uint32_t i = 0; i < array->size; ++i) | |
22834 | { | |
22835 | const msgpack_object *item = &array->ptr[i]; | |
22836 | ||
22837 | print_indents (indent); | |
22838 | dump_msgpack_obj (item, indent); | |
22839 | printf (",\n"); | |
22840 | } | |
22841 | ||
22842 | --indent; | |
22843 | print_indents (indent); | |
22844 | printf ("]"); | |
22845 | break; | |
22846 | } | |
22847 | break; | |
22848 | ||
22849 | case MSGPACK_OBJECT_MAP: | |
22850 | { | |
22851 | const msgpack_object_map *map = &obj->via.map; | |
22852 | ||
22853 | printf ("{\n"); | |
22854 | ++indent; | |
22855 | ||
22856 | for (uint32_t i = 0; i < map->size; ++i) | |
22857 | { | |
22858 | const msgpack_object_kv *kv = &map->ptr[i]; | |
22859 | const msgpack_object *key = &kv->key; | |
22860 | const msgpack_object *val = &kv->val; | |
22861 | ||
22862 | print_indents (indent); | |
22863 | dump_msgpack_obj (key, indent); | |
22864 | printf (": "); | |
22865 | dump_msgpack_obj (val, indent); | |
22866 | ||
22867 | printf (",\n"); | |
22868 | } | |
22869 | ||
22870 | --indent; | |
22871 | print_indents (indent); | |
22872 | printf ("}"); | |
22873 | ||
22874 | break; | |
22875 | } | |
22876 | ||
22877 | case MSGPACK_OBJECT_BIN: | |
22878 | printf ("(bin)"); | |
22879 | break; | |
22880 | ||
22881 | case MSGPACK_OBJECT_EXT: | |
22882 | printf ("(ext)"); | |
22883 | break; | |
22884 | } | |
22885 | } | |
22886 | ||
22887 | static void | |
22888 | dump_msgpack (const msgpack_unpacked *msg) | |
22889 | { | |
22890 | print_indents (0); | |
22891 | dump_msgpack_obj (&msg->data, 0); | |
22892 | printf ("\n"); | |
22893 | } | |
22894 | ||
22895 | #endif /* defined HAVE_MSGPACK */ | |
22896 | ||
22897 | static bool | |
22898 | print_amdgpu_note (Elf_Internal_Note *pnote) | |
22899 | { | |
22900 | #if defined HAVE_MSGPACK | |
22901 | /* If msgpack is available, decode and dump the note's content. */ | |
22902 | bool ret; | |
22903 | msgpack_unpacked msg; | |
22904 | msgpack_unpack_return msgpack_ret; | |
22905 | ||
22906 | assert (pnote->type == NT_AMDGPU_METADATA); | |
22907 | ||
22908 | msgpack_unpacked_init (&msg); | |
22909 | msgpack_ret = msgpack_unpack_next (&msg, pnote->descdata, pnote->descsz, | |
22910 | NULL); | |
22911 | ||
22912 | switch (msgpack_ret) | |
22913 | { | |
22914 | case MSGPACK_UNPACK_SUCCESS: | |
22915 | dump_msgpack (&msg); | |
22916 | ret = true; | |
22917 | break; | |
22918 | ||
22919 | default: | |
22920 | error (_("failed to unpack msgpack contents in NT_AMDGPU_METADATA note")); | |
22921 | ret = false; | |
22922 | break; | |
22923 | } | |
22924 | ||
22925 | msgpack_unpacked_destroy (&msg); | |
22926 | return ret; | |
22927 | #else | |
22928 | /* msgpack is not available, dump contents as hex. */ | |
22929 | print_note_contents_hex (pnote); | |
22930 | return true; | |
22931 | #endif | |
22932 | } | |
22933 | ||
22934 | static bool | |
22935 | print_qnx_note (Elf_Internal_Note *pnote) | |
22936 | { | |
22937 | switch (pnote->type) | |
22938 | { | |
22939 | case QNT_STACK: | |
22940 | if (pnote->descsz != 12) | |
22941 | goto desc_size_fail; | |
22942 | ||
22943 | printf (_(" Stack Size: 0x%" PRIx32 "\n"), | |
22944 | (unsigned) byte_get ((unsigned char *) pnote->descdata, 4)); | |
22945 | printf (_(" Stack allocated: %" PRIx32 "\n"), | |
22946 | (unsigned) byte_get ((unsigned char *) pnote->descdata + 4, 4)); | |
22947 | printf (_(" Executable: %s\n"), | |
22948 | ((unsigned) byte_get ((unsigned char *) pnote->descdata + 8, 1)) ? "no": "yes"); | |
22949 | break; | |
22950 | ||
22951 | default: | |
22952 | print_note_contents_hex(pnote); | |
22953 | } | |
22954 | return true; | |
22955 | ||
22956 | desc_size_fail: | |
22957 | printf (_(" <corrupt - data size is too small>\n")); | |
22958 | error (_("corrupt QNX note: data size is too small\n")); | |
22959 | return false; | |
22960 | } | |
22961 | ||
22962 | ||
22963 | /* Note that by the ELF standard, the name field is already null byte | |
22964 | terminated, and namesz includes the terminating null byte. | |
22965 | I.E. the value of namesz for the name "FSF" is 4. | |
22966 | ||
22967 | If the value of namesz is zero, there is no name present. */ | |
22968 | ||
22969 | static bool | |
22970 | process_note (Elf_Internal_Note * pnote, | |
22971 | Filedata * filedata) | |
22972 | { | |
22973 | const char * name = pnote->namesz ? pnote->namedata : "(NONE)"; | |
22974 | const char * nt; | |
22975 | ||
22976 | if (pnote->namesz == 0) | |
22977 | /* If there is no note name, then use the default set of | |
22978 | note type strings. */ | |
22979 | nt = get_note_type (filedata, pnote->type); | |
22980 | ||
22981 | else if (startswith (pnote->namedata, "GNU")) | |
22982 | /* GNU-specific object file notes. */ | |
22983 | nt = get_gnu_elf_note_type (pnote->type); | |
22984 | ||
22985 | else if (startswith (pnote->namedata, "AMDGPU")) | |
22986 | /* AMDGPU-specific object file notes. */ | |
22987 | nt = get_amdgpu_elf_note_type (pnote->type); | |
22988 | ||
22989 | else if (startswith (pnote->namedata, "FreeBSD")) | |
22990 | /* FreeBSD-specific core file notes. */ | |
22991 | nt = get_freebsd_elfcore_note_type (filedata, pnote->type); | |
22992 | ||
22993 | else if (startswith (pnote->namedata, "NetBSD-CORE")) | |
22994 | /* NetBSD-specific core file notes. */ | |
22995 | nt = get_netbsd_elfcore_note_type (filedata, pnote->type); | |
22996 | ||
22997 | else if (startswith (pnote->namedata, "NetBSD")) | |
22998 | /* NetBSD-specific core file notes. */ | |
22999 | return process_netbsd_elf_note (pnote); | |
23000 | ||
23001 | else if (startswith (pnote->namedata, "PaX")) | |
23002 | /* NetBSD-specific core file notes. */ | |
23003 | return process_netbsd_elf_note (pnote); | |
23004 | ||
23005 | else if (startswith (pnote->namedata, "OpenBSD")) | |
23006 | /* OpenBSD-specific core file notes. */ | |
23007 | nt = get_openbsd_elfcore_note_type (filedata, pnote->type); | |
23008 | ||
23009 | else if (startswith (pnote->namedata, "QNX")) | |
23010 | /* QNX-specific core file notes. */ | |
23011 | nt = get_qnx_elfcore_note_type (filedata, pnote->type); | |
23012 | ||
23013 | else if (startswith (pnote->namedata, "SPU/")) | |
23014 | { | |
23015 | /* SPU-specific core file notes. */ | |
23016 | nt = pnote->namedata + 4; | |
23017 | name = "SPU"; | |
23018 | } | |
23019 | ||
23020 | else if (startswith (pnote->namedata, "IPF/VMS")) | |
23021 | /* VMS/ia64-specific file notes. */ | |
23022 | nt = get_ia64_vms_note_type (pnote->type); | |
23023 | ||
23024 | else if (startswith (pnote->namedata, "stapsdt")) | |
23025 | nt = get_stapsdt_note_type (pnote->type); | |
23026 | ||
23027 | else | |
23028 | /* Don't recognize this note name; just use the default set of | |
23029 | note type strings. */ | |
23030 | nt = get_note_type (filedata, pnote->type); | |
23031 | ||
23032 | printf (" "); | |
23033 | ||
23034 | if (((startswith (pnote->namedata, "GA") | |
23035 | && strchr ("*$!+", pnote->namedata[2]) != NULL) | |
23036 | || strchr ("*$!+", pnote->namedata[0]) != NULL) | |
23037 | && (pnote->type == NT_GNU_BUILD_ATTRIBUTE_OPEN | |
23038 | || pnote->type == NT_GNU_BUILD_ATTRIBUTE_FUNC)) | |
23039 | print_gnu_build_attribute_name (pnote); | |
23040 | else | |
23041 | print_symbol_name (-20, name); | |
23042 | ||
23043 | if (do_wide) | |
23044 | printf (" 0x%08lx\t%s\t", pnote->descsz, nt); | |
23045 | else | |
23046 | printf (" 0x%08lx\t%s\n", pnote->descsz, nt); | |
23047 | ||
23048 | if (startswith (pnote->namedata, "IPF/VMS")) | |
23049 | return print_ia64_vms_note (pnote); | |
23050 | else if (startswith (pnote->namedata, "GNU")) | |
23051 | return print_gnu_note (filedata, pnote); | |
23052 | else if (startswith (pnote->namedata, "stapsdt")) | |
23053 | return print_stapsdt_note (pnote); | |
23054 | else if (startswith (pnote->namedata, "CORE")) | |
23055 | return print_core_note (pnote); | |
23056 | else if (startswith (pnote->namedata, "FDO")) | |
23057 | return print_fdo_note (pnote); | |
23058 | else if (((startswith (pnote->namedata, "GA") | |
23059 | && strchr ("*$!+", pnote->namedata[2]) != NULL) | |
23060 | || strchr ("*$!+", pnote->namedata[0]) != NULL) | |
23061 | && (pnote->type == NT_GNU_BUILD_ATTRIBUTE_OPEN | |
23062 | || pnote->type == NT_GNU_BUILD_ATTRIBUTE_FUNC)) | |
23063 | return print_gnu_build_attribute_description (pnote, filedata); | |
23064 | else if (startswith (pnote->namedata, "AMDGPU") | |
23065 | && pnote->type == NT_AMDGPU_METADATA) | |
23066 | return print_amdgpu_note (pnote); | |
23067 | else if (startswith (pnote->namedata, "QNX")) | |
23068 | return print_qnx_note (pnote); | |
23069 | ||
23070 | print_note_contents_hex (pnote); | |
23071 | return true; | |
23072 | } | |
23073 | ||
23074 | static bool | |
23075 | process_notes_at (Filedata * filedata, | |
23076 | Elf_Internal_Shdr * section, | |
23077 | uint64_t offset, | |
23078 | uint64_t length, | |
23079 | uint64_t align) | |
23080 | { | |
23081 | Elf_External_Note *pnotes; | |
23082 | Elf_External_Note *external; | |
23083 | char *end; | |
23084 | bool res = true; | |
23085 | ||
23086 | if (length <= 0) | |
23087 | return false; | |
23088 | ||
23089 | if (section) | |
23090 | { | |
23091 | pnotes = (Elf_External_Note *) get_section_contents (section, filedata); | |
23092 | if (pnotes) | |
23093 | { | |
23094 | if (! apply_relocations (filedata, section, (unsigned char *) pnotes, length, NULL, NULL)) | |
23095 | { | |
23096 | free (pnotes); | |
23097 | return false; | |
23098 | } | |
23099 | } | |
23100 | } | |
23101 | else | |
23102 | pnotes = (Elf_External_Note *) get_data (NULL, filedata, offset, 1, length, | |
23103 | _("notes")); | |
23104 | ||
23105 | if (pnotes == NULL) | |
23106 | return false; | |
23107 | ||
23108 | external = pnotes; | |
23109 | ||
23110 | if (filedata->is_separate) | |
23111 | printf (_("In linked file '%s': "), filedata->file_name); | |
23112 | else | |
23113 | printf ("\n"); | |
23114 | if (section) | |
23115 | printf (_("Displaying notes found in: %s\n"), printable_section_name (filedata, section)); | |
23116 | else | |
23117 | printf (_("Displaying notes found at file offset 0x%08" PRIx64 | |
23118 | " with length 0x%08" PRIx64 ":\n"), | |
23119 | offset, length); | |
23120 | ||
23121 | /* NB: Some note sections may have alignment value of 0 or 1. gABI | |
23122 | specifies that notes should be aligned to 4 bytes in 32-bit | |
23123 | objects and to 8 bytes in 64-bit objects. As a Linux extension, | |
23124 | we also support 4 byte alignment in 64-bit objects. If section | |
23125 | alignment is less than 4, we treate alignment as 4 bytes. */ | |
23126 | if (align < 4) | |
23127 | align = 4; | |
23128 | else if (align != 4 && align != 8) | |
23129 | { | |
23130 | warn (_("Corrupt note: alignment %" PRId64 ", expecting 4 or 8\n"), | |
23131 | align); | |
23132 | free (pnotes); | |
23133 | return false; | |
23134 | } | |
23135 | ||
23136 | printf (_(" %-20s %-10s\tDescription\n"), _("Owner"), _("Data size")); | |
23137 | ||
23138 | end = (char *) pnotes + length; | |
23139 | while ((char *) external < end) | |
23140 | { | |
23141 | Elf_Internal_Note inote; | |
23142 | size_t min_notesz; | |
23143 | char * next; | |
23144 | char * temp = NULL; | |
23145 | size_t data_remaining = end - (char *) external; | |
23146 | ||
23147 | if (!is_ia64_vms (filedata)) | |
23148 | { | |
23149 | /* PR binutils/15191 | |
23150 | Make sure that there is enough data to read. */ | |
23151 | min_notesz = offsetof (Elf_External_Note, name); | |
23152 | if (data_remaining < min_notesz) | |
23153 | { | |
23154 | warn (ngettext ("Corrupt note: only %zd byte remains, " | |
23155 | "not enough for a full note\n", | |
23156 | "Corrupt note: only %zd bytes remain, " | |
23157 | "not enough for a full note\n", | |
23158 | data_remaining), | |
23159 | data_remaining); | |
23160 | break; | |
23161 | } | |
23162 | data_remaining -= min_notesz; | |
23163 | ||
23164 | inote.type = BYTE_GET (external->type); | |
23165 | inote.namesz = BYTE_GET (external->namesz); | |
23166 | inote.namedata = external->name; | |
23167 | inote.descsz = BYTE_GET (external->descsz); | |
23168 | inote.descdata = ((char *) external | |
23169 | + ELF_NOTE_DESC_OFFSET (inote.namesz, align)); | |
23170 | inote.descpos = offset + (inote.descdata - (char *) pnotes); | |
23171 | next = ((char *) external | |
23172 | + ELF_NOTE_NEXT_OFFSET (inote.namesz, inote.descsz, align)); | |
23173 | } | |
23174 | else | |
23175 | { | |
23176 | Elf64_External_VMS_Note *vms_external; | |
23177 | ||
23178 | /* PR binutils/15191 | |
23179 | Make sure that there is enough data to read. */ | |
23180 | min_notesz = offsetof (Elf64_External_VMS_Note, name); | |
23181 | if (data_remaining < min_notesz) | |
23182 | { | |
23183 | warn (ngettext ("Corrupt note: only %zd byte remains, " | |
23184 | "not enough for a full note\n", | |
23185 | "Corrupt note: only %zd bytes remain, " | |
23186 | "not enough for a full note\n", | |
23187 | data_remaining), | |
23188 | data_remaining); | |
23189 | break; | |
23190 | } | |
23191 | data_remaining -= min_notesz; | |
23192 | ||
23193 | vms_external = (Elf64_External_VMS_Note *) external; | |
23194 | inote.type = BYTE_GET (vms_external->type); | |
23195 | inote.namesz = BYTE_GET (vms_external->namesz); | |
23196 | inote.namedata = vms_external->name; | |
23197 | inote.descsz = BYTE_GET (vms_external->descsz); | |
23198 | inote.descdata = inote.namedata + align_power (inote.namesz, 3); | |
23199 | inote.descpos = offset + (inote.descdata - (char *) pnotes); | |
23200 | next = inote.descdata + align_power (inote.descsz, 3); | |
23201 | } | |
23202 | ||
23203 | /* PR 17531: file: 3443835e. */ | |
23204 | /* PR 17531: file: id:000000,sig:11,src:006986,op:havoc,rep:4. */ | |
23205 | if ((size_t) (inote.descdata - inote.namedata) < inote.namesz | |
23206 | || (size_t) (inote.descdata - inote.namedata) > data_remaining | |
23207 | || (size_t) (next - inote.descdata) < inote.descsz | |
23208 | || ((size_t) (next - inote.descdata) | |
23209 | > data_remaining - (size_t) (inote.descdata - inote.namedata))) | |
23210 | { | |
23211 | warn (_("note with invalid namesz and/or descsz found at offset %#tx\n"), | |
23212 | (char *) external - (char *) pnotes); | |
23213 | warn (_(" type: %#lx, namesize: %#lx, descsize: %#lx, alignment: %u\n"), | |
23214 | inote.type, inote.namesz, inote.descsz, (int) align); | |
23215 | break; | |
23216 | } | |
23217 | ||
23218 | external = (Elf_External_Note *) next; | |
23219 | ||
23220 | /* Verify that name is null terminated. It appears that at least | |
23221 | one version of Linux (RedHat 6.0) generates corefiles that don't | |
23222 | comply with the ELF spec by failing to include the null byte in | |
23223 | namesz. */ | |
23224 | if (inote.namesz > 0 && inote.namedata[inote.namesz - 1] != '\0') | |
23225 | { | |
23226 | if ((size_t) (inote.descdata - inote.namedata) == inote.namesz) | |
23227 | { | |
23228 | temp = (char *) malloc (inote.namesz + 1); | |
23229 | if (temp == NULL) | |
23230 | { | |
23231 | error (_("Out of memory allocating space for inote name\n")); | |
23232 | res = false; | |
23233 | break; | |
23234 | } | |
23235 | ||
23236 | memcpy (temp, inote.namedata, inote.namesz); | |
23237 | inote.namedata = temp; | |
23238 | } | |
23239 | inote.namedata[inote.namesz] = 0; | |
23240 | } | |
23241 | ||
23242 | if (! process_note (& inote, filedata)) | |
23243 | res = false; | |
23244 | ||
23245 | free (temp); | |
23246 | temp = NULL; | |
23247 | } | |
23248 | ||
23249 | free (pnotes); | |
23250 | ||
23251 | return res; | |
23252 | } | |
23253 | ||
23254 | static bool | |
23255 | process_corefile_note_segments (Filedata * filedata) | |
23256 | { | |
23257 | Elf_Internal_Phdr *segment; | |
23258 | unsigned int i; | |
23259 | bool res = true; | |
23260 | ||
23261 | if (! get_program_headers (filedata)) | |
23262 | return true; | |
23263 | ||
23264 | for (i = 0, segment = filedata->program_headers; | |
23265 | i < filedata->file_header.e_phnum; | |
23266 | i++, segment++) | |
23267 | { | |
23268 | if (segment->p_type == PT_NOTE) | |
23269 | if (! process_notes_at (filedata, NULL, segment->p_offset, | |
23270 | segment->p_filesz, segment->p_align)) | |
23271 | res = false; | |
23272 | } | |
23273 | ||
23274 | return res; | |
23275 | } | |
23276 | ||
23277 | static bool | |
23278 | process_v850_notes (Filedata * filedata, uint64_t offset, uint64_t length) | |
23279 | { | |
23280 | Elf_External_Note * pnotes; | |
23281 | Elf_External_Note * external; | |
23282 | char * end; | |
23283 | bool res = true; | |
23284 | ||
23285 | if (length <= 0) | |
23286 | return false; | |
23287 | ||
23288 | pnotes = (Elf_External_Note *) get_data (NULL, filedata, offset, 1, length, | |
23289 | _("v850 notes")); | |
23290 | if (pnotes == NULL) | |
23291 | return false; | |
23292 | ||
23293 | external = pnotes; | |
23294 | end = (char*) pnotes + length; | |
23295 | ||
23296 | printf (_("\nDisplaying contents of Renesas V850 notes section at offset" | |
23297 | " %#" PRIx64 " with length %#" PRIx64 ":\n"), | |
23298 | offset, length); | |
23299 | ||
23300 | while ((char *) external + sizeof (Elf_External_Note) < end) | |
23301 | { | |
23302 | Elf_External_Note * next; | |
23303 | Elf_Internal_Note inote; | |
23304 | ||
23305 | inote.type = BYTE_GET (external->type); | |
23306 | inote.namesz = BYTE_GET (external->namesz); | |
23307 | inote.namedata = external->name; | |
23308 | inote.descsz = BYTE_GET (external->descsz); | |
23309 | inote.descdata = inote.namedata + align_power (inote.namesz, 2); | |
23310 | inote.descpos = offset + (inote.descdata - (char *) pnotes); | |
23311 | ||
23312 | if (inote.descdata < (char *) pnotes || inote.descdata >= end) | |
23313 | { | |
23314 | warn (_("Corrupt note: name size is too big: %lx\n"), inote.namesz); | |
23315 | inote.descdata = inote.namedata; | |
23316 | inote.namesz = 0; | |
23317 | } | |
23318 | ||
23319 | next = (Elf_External_Note *) (inote.descdata + align_power (inote.descsz, 2)); | |
23320 | ||
23321 | if ( ((char *) next > end) | |
23322 | || ((char *) next < (char *) pnotes)) | |
23323 | { | |
23324 | warn (_("corrupt descsz found in note at offset %#tx\n"), | |
23325 | (char *) external - (char *) pnotes); | |
23326 | warn (_(" type: %#lx, namesize: %#lx, descsize: %#lx\n"), | |
23327 | inote.type, inote.namesz, inote.descsz); | |
23328 | break; | |
23329 | } | |
23330 | ||
23331 | external = next; | |
23332 | ||
23333 | /* Prevent out-of-bounds indexing. */ | |
23334 | if ( inote.namedata + inote.namesz > end | |
23335 | || inote.namedata + inote.namesz < inote.namedata) | |
23336 | { | |
23337 | warn (_("corrupt namesz found in note at offset %#zx\n"), | |
23338 | (char *) external - (char *) pnotes); | |
23339 | warn (_(" type: %#lx, namesize: %#lx, descsize: %#lx\n"), | |
23340 | inote.type, inote.namesz, inote.descsz); | |
23341 | break; | |
23342 | } | |
23343 | ||
23344 | printf (" %s: ", get_v850_elf_note_type (inote.type)); | |
23345 | ||
23346 | if (! print_v850_note (& inote)) | |
23347 | { | |
23348 | res = false; | |
23349 | printf ("<corrupt sizes: namesz: %#lx, descsz: %#lx>\n", | |
23350 | inote.namesz, inote.descsz); | |
23351 | } | |
23352 | } | |
23353 | ||
23354 | free (pnotes); | |
23355 | ||
23356 | return res; | |
23357 | } | |
23358 | ||
23359 | static bool | |
23360 | process_note_sections (Filedata * filedata) | |
23361 | { | |
23362 | Elf_Internal_Shdr *section; | |
23363 | size_t i; | |
23364 | unsigned int n = 0; | |
23365 | bool res = true; | |
23366 | ||
23367 | for (i = 0, section = filedata->section_headers; | |
23368 | i < filedata->file_header.e_shnum && section != NULL; | |
23369 | i++, section++) | |
23370 | { | |
23371 | if (section->sh_type == SHT_NOTE) | |
23372 | { | |
23373 | if (! process_notes_at (filedata, section, section->sh_offset, | |
23374 | section->sh_size, section->sh_addralign)) | |
23375 | res = false; | |
23376 | n++; | |
23377 | } | |
23378 | ||
23379 | if (( filedata->file_header.e_machine == EM_V800 | |
23380 | || filedata->file_header.e_machine == EM_V850 | |
23381 | || filedata->file_header.e_machine == EM_CYGNUS_V850) | |
23382 | && section->sh_type == SHT_RENESAS_INFO) | |
23383 | { | |
23384 | if (! process_v850_notes (filedata, section->sh_offset, | |
23385 | section->sh_size)) | |
23386 | res = false; | |
23387 | n++; | |
23388 | } | |
23389 | } | |
23390 | ||
23391 | if (n == 0) | |
23392 | /* Try processing NOTE segments instead. */ | |
23393 | return process_corefile_note_segments (filedata); | |
23394 | ||
23395 | return res; | |
23396 | } | |
23397 | ||
23398 | static bool | |
23399 | process_notes (Filedata * filedata) | |
23400 | { | |
23401 | /* If we have not been asked to display the notes then do nothing. */ | |
23402 | if (! do_notes) | |
23403 | return true; | |
23404 | ||
23405 | if (filedata->file_header.e_type != ET_CORE) | |
23406 | return process_note_sections (filedata); | |
23407 | ||
23408 | /* No program headers means no NOTE segment. */ | |
23409 | if (filedata->file_header.e_phnum > 0) | |
23410 | return process_corefile_note_segments (filedata); | |
23411 | ||
23412 | if (filedata->is_separate) | |
23413 | printf (_("No notes found in linked file '%s'.\n"), | |
23414 | filedata->file_name); | |
23415 | else | |
23416 | printf (_("No notes found file.\n")); | |
23417 | ||
23418 | return true; | |
23419 | } | |
23420 | ||
23421 | static unsigned char * | |
23422 | display_public_gnu_attributes (unsigned char * start, | |
23423 | const unsigned char * const end) | |
23424 | { | |
23425 | printf (_(" Unknown GNU attribute: %s\n"), start); | |
23426 | ||
23427 | start += strnlen ((char *) start, end - start); | |
23428 | display_raw_attribute (start, end); | |
23429 | ||
23430 | return (unsigned char *) end; | |
23431 | } | |
23432 | ||
23433 | static unsigned char * | |
23434 | display_generic_attribute (unsigned char * start, | |
23435 | unsigned int tag, | |
23436 | const unsigned char * const end) | |
23437 | { | |
23438 | if (tag == 0) | |
23439 | return (unsigned char *) end; | |
23440 | ||
23441 | return display_tag_value (tag, start, end); | |
23442 | } | |
23443 | ||
23444 | static bool | |
23445 | process_arch_specific (Filedata * filedata) | |
23446 | { | |
23447 | if (! do_arch) | |
23448 | return true; | |
23449 | ||
23450 | switch (filedata->file_header.e_machine) | |
23451 | { | |
23452 | case EM_ARC: | |
23453 | case EM_ARC_COMPACT: | |
23454 | case EM_ARC_COMPACT2: | |
23455 | case EM_ARC_COMPACT3: | |
23456 | case EM_ARC_COMPACT3_64: | |
23457 | return process_attributes (filedata, "ARC", SHT_ARC_ATTRIBUTES, | |
23458 | display_arc_attribute, | |
23459 | display_generic_attribute); | |
23460 | case EM_ARM: | |
23461 | return process_attributes (filedata, "aeabi", SHT_ARM_ATTRIBUTES, | |
23462 | display_arm_attribute, | |
23463 | display_generic_attribute); | |
23464 | ||
23465 | case EM_MIPS: | |
23466 | case EM_MIPS_RS3_LE: | |
23467 | return process_mips_specific (filedata); | |
23468 | ||
23469 | case EM_MSP430: | |
23470 | return process_attributes (filedata, "mspabi", SHT_MSP430_ATTRIBUTES, | |
23471 | display_msp430_attribute, | |
23472 | display_msp430_gnu_attribute); | |
23473 | ||
23474 | case EM_RISCV: | |
23475 | return process_attributes (filedata, "riscv", SHT_RISCV_ATTRIBUTES, | |
23476 | display_riscv_attribute, | |
23477 | display_generic_attribute); | |
23478 | ||
23479 | case EM_NDS32: | |
23480 | return process_nds32_specific (filedata); | |
23481 | ||
23482 | case EM_68K: | |
23483 | return process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL, | |
23484 | display_m68k_gnu_attribute); | |
23485 | ||
23486 | case EM_PPC: | |
23487 | case EM_PPC64: | |
23488 | return process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL, | |
23489 | display_power_gnu_attribute); | |
23490 | ||
23491 | case EM_S390: | |
23492 | case EM_S390_OLD: | |
23493 | return process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL, | |
23494 | display_s390_gnu_attribute); | |
23495 | ||
23496 | case EM_SPARC: | |
23497 | case EM_SPARC32PLUS: | |
23498 | case EM_SPARCV9: | |
23499 | return process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL, | |
23500 | display_sparc_gnu_attribute); | |
23501 | ||
23502 | case EM_TI_C6000: | |
23503 | return process_attributes (filedata, "c6xabi", SHT_C6000_ATTRIBUTES, | |
23504 | display_tic6x_attribute, | |
23505 | display_generic_attribute); | |
23506 | ||
23507 | case EM_CSKY: | |
23508 | return process_attributes (filedata, "csky", SHT_CSKY_ATTRIBUTES, | |
23509 | display_csky_attribute, NULL); | |
23510 | ||
23511 | default: | |
23512 | return process_attributes (filedata, "gnu", SHT_GNU_ATTRIBUTES, | |
23513 | display_public_gnu_attributes, | |
23514 | display_generic_attribute); | |
23515 | } | |
23516 | } | |
23517 | ||
23518 | static bool | |
23519 | get_file_header (Filedata * filedata) | |
23520 | { | |
23521 | /* Read in the identity array. */ | |
23522 | if (fread (filedata->file_header.e_ident, EI_NIDENT, 1, filedata->handle) != 1) | |
23523 | return false; | |
23524 | ||
23525 | /* Determine how to read the rest of the header. */ | |
23526 | switch (filedata->file_header.e_ident[EI_DATA]) | |
23527 | { | |
23528 | default: | |
23529 | case ELFDATANONE: | |
23530 | case ELFDATA2LSB: | |
23531 | byte_get = byte_get_little_endian; | |
23532 | byte_put = byte_put_little_endian; | |
23533 | break; | |
23534 | case ELFDATA2MSB: | |
23535 | byte_get = byte_get_big_endian; | |
23536 | byte_put = byte_put_big_endian; | |
23537 | break; | |
23538 | } | |
23539 | ||
23540 | /* For now we only support 32 bit and 64 bit ELF files. */ | |
23541 | is_32bit_elf = (filedata->file_header.e_ident[EI_CLASS] != ELFCLASS64); | |
23542 | ||
23543 | /* Read in the rest of the header. */ | |
23544 | if (is_32bit_elf) | |
23545 | { | |
23546 | Elf32_External_Ehdr ehdr32; | |
23547 | ||
23548 | if (fread (ehdr32.e_type, sizeof (ehdr32) - EI_NIDENT, 1, filedata->handle) != 1) | |
23549 | return false; | |
23550 | ||
23551 | filedata->file_header.e_type = BYTE_GET (ehdr32.e_type); | |
23552 | filedata->file_header.e_machine = BYTE_GET (ehdr32.e_machine); | |
23553 | filedata->file_header.e_version = BYTE_GET (ehdr32.e_version); | |
23554 | filedata->file_header.e_entry = BYTE_GET (ehdr32.e_entry); | |
23555 | filedata->file_header.e_phoff = BYTE_GET (ehdr32.e_phoff); | |
23556 | filedata->file_header.e_shoff = BYTE_GET (ehdr32.e_shoff); | |
23557 | filedata->file_header.e_flags = BYTE_GET (ehdr32.e_flags); | |
23558 | filedata->file_header.e_ehsize = BYTE_GET (ehdr32.e_ehsize); | |
23559 | filedata->file_header.e_phentsize = BYTE_GET (ehdr32.e_phentsize); | |
23560 | filedata->file_header.e_phnum = BYTE_GET (ehdr32.e_phnum); | |
23561 | filedata->file_header.e_shentsize = BYTE_GET (ehdr32.e_shentsize); | |
23562 | filedata->file_header.e_shnum = BYTE_GET (ehdr32.e_shnum); | |
23563 | filedata->file_header.e_shstrndx = BYTE_GET (ehdr32.e_shstrndx); | |
23564 | } | |
23565 | else | |
23566 | { | |
23567 | Elf64_External_Ehdr ehdr64; | |
23568 | ||
23569 | if (fread (ehdr64.e_type, sizeof (ehdr64) - EI_NIDENT, 1, filedata->handle) != 1) | |
23570 | return false; | |
23571 | ||
23572 | filedata->file_header.e_type = BYTE_GET (ehdr64.e_type); | |
23573 | filedata->file_header.e_machine = BYTE_GET (ehdr64.e_machine); | |
23574 | filedata->file_header.e_version = BYTE_GET (ehdr64.e_version); | |
23575 | filedata->file_header.e_entry = BYTE_GET (ehdr64.e_entry); | |
23576 | filedata->file_header.e_phoff = BYTE_GET (ehdr64.e_phoff); | |
23577 | filedata->file_header.e_shoff = BYTE_GET (ehdr64.e_shoff); | |
23578 | filedata->file_header.e_flags = BYTE_GET (ehdr64.e_flags); | |
23579 | filedata->file_header.e_ehsize = BYTE_GET (ehdr64.e_ehsize); | |
23580 | filedata->file_header.e_phentsize = BYTE_GET (ehdr64.e_phentsize); | |
23581 | filedata->file_header.e_phnum = BYTE_GET (ehdr64.e_phnum); | |
23582 | filedata->file_header.e_shentsize = BYTE_GET (ehdr64.e_shentsize); | |
23583 | filedata->file_header.e_shnum = BYTE_GET (ehdr64.e_shnum); | |
23584 | filedata->file_header.e_shstrndx = BYTE_GET (ehdr64.e_shstrndx); | |
23585 | } | |
23586 | ||
23587 | return true; | |
23588 | } | |
23589 | ||
23590 | static void | |
23591 | free_filedata (Filedata *filedata) | |
23592 | { | |
23593 | free (filedata->program_interpreter); | |
23594 | free (filedata->program_headers); | |
23595 | free (filedata->section_headers); | |
23596 | free (filedata->string_table); | |
23597 | free (filedata->dump.dump_sects); | |
23598 | free (filedata->dynamic_strings); | |
23599 | free (filedata->dynamic_symbols); | |
23600 | free (filedata->dynamic_syminfo); | |
23601 | free (filedata->dynamic_section); | |
23602 | ||
23603 | while (filedata->symtab_shndx_list != NULL) | |
23604 | { | |
23605 | elf_section_list *next = filedata->symtab_shndx_list->next; | |
23606 | free (filedata->symtab_shndx_list); | |
23607 | filedata->symtab_shndx_list = next; | |
23608 | } | |
23609 | ||
23610 | free (filedata->section_headers_groups); | |
23611 | ||
23612 | if (filedata->section_groups) | |
23613 | { | |
23614 | size_t i; | |
23615 | struct group_list * g; | |
23616 | struct group_list * next; | |
23617 | ||
23618 | for (i = 0; i < filedata->group_count; i++) | |
23619 | { | |
23620 | for (g = filedata->section_groups [i].root; g != NULL; g = next) | |
23621 | { | |
23622 | next = g->next; | |
23623 | free (g); | |
23624 | } | |
23625 | } | |
23626 | ||
23627 | free (filedata->section_groups); | |
23628 | } | |
23629 | memset (&filedata->section_headers, 0, | |
23630 | sizeof (Filedata) - offsetof (Filedata, section_headers)); | |
23631 | } | |
23632 | ||
23633 | static void | |
23634 | close_file (Filedata * filedata) | |
23635 | { | |
23636 | if (filedata) | |
23637 | { | |
23638 | if (filedata->handle) | |
23639 | fclose (filedata->handle); | |
23640 | free (filedata); | |
23641 | } | |
23642 | } | |
23643 | ||
23644 | void | |
23645 | close_debug_file (void * data) | |
23646 | { | |
23647 | free_filedata ((Filedata *) data); | |
23648 | close_file ((Filedata *) data); | |
23649 | } | |
23650 | ||
23651 | static Filedata * | |
23652 | open_file (const char * pathname, bool is_separate) | |
23653 | { | |
23654 | struct stat statbuf; | |
23655 | Filedata * filedata = NULL; | |
23656 | ||
23657 | if (stat (pathname, & statbuf) < 0 | |
23658 | || ! S_ISREG (statbuf.st_mode)) | |
23659 | goto fail; | |
23660 | ||
23661 | filedata = calloc (1, sizeof * filedata); | |
23662 | if (filedata == NULL) | |
23663 | goto fail; | |
23664 | ||
23665 | filedata->handle = fopen (pathname, "rb"); | |
23666 | if (filedata->handle == NULL) | |
23667 | goto fail; | |
23668 | ||
23669 | filedata->file_size = statbuf.st_size; | |
23670 | filedata->file_name = pathname; | |
23671 | filedata->is_separate = is_separate; | |
23672 | ||
23673 | if (! get_file_header (filedata)) | |
23674 | goto fail; | |
23675 | ||
23676 | if (!get_section_headers (filedata, false)) | |
23677 | goto fail; | |
23678 | ||
23679 | return filedata; | |
23680 | ||
23681 | fail: | |
23682 | if (filedata) | |
23683 | { | |
23684 | if (filedata->handle) | |
23685 | fclose (filedata->handle); | |
23686 | free (filedata); | |
23687 | } | |
23688 | return NULL; | |
23689 | } | |
23690 | ||
23691 | void * | |
23692 | open_debug_file (const char * pathname) | |
23693 | { | |
23694 | return open_file (pathname, true); | |
23695 | } | |
23696 | ||
23697 | static void | |
23698 | initialise_dump_sects (Filedata * filedata) | |
23699 | { | |
23700 | /* Initialise the dump_sects array from the cmdline_dump_sects array. | |
23701 | Note we do this even if cmdline_dump_sects is empty because we | |
23702 | must make sure that the dump_sets array is zeroed out before each | |
23703 | object file is processed. */ | |
23704 | if (filedata->dump.num_dump_sects > cmdline.num_dump_sects) | |
23705 | memset (filedata->dump.dump_sects, 0, | |
23706 | filedata->dump.num_dump_sects * sizeof (*filedata->dump.dump_sects)); | |
23707 | ||
23708 | if (cmdline.num_dump_sects > 0) | |
23709 | { | |
23710 | if (filedata->dump.num_dump_sects == 0) | |
23711 | /* A sneaky way of allocating the dump_sects array. */ | |
23712 | request_dump_bynumber (&filedata->dump, cmdline.num_dump_sects, 0); | |
23713 | ||
23714 | assert (filedata->dump.num_dump_sects >= cmdline.num_dump_sects); | |
23715 | memcpy (filedata->dump.dump_sects, cmdline.dump_sects, | |
23716 | cmdline.num_dump_sects * sizeof (*filedata->dump.dump_sects)); | |
23717 | } | |
23718 | } | |
23719 | ||
23720 | static bool | |
23721 | might_need_separate_debug_info (Filedata * filedata) | |
23722 | { | |
23723 | /* Debuginfo files do not need further separate file loading. */ | |
23724 | if (filedata->file_header.e_shstrndx == SHN_UNDEF) | |
23725 | return false; | |
23726 | ||
23727 | /* Since do_follow_links might be enabled by default, only treat it as an | |
23728 | indication that separate files should be loaded if setting it was a | |
23729 | deliberate user action. */ | |
23730 | if (DEFAULT_FOR_FOLLOW_LINKS == 0 && do_follow_links) | |
23731 | return true; | |
23732 | ||
23733 | if (process_links || do_syms || do_unwind | |
23734 | || dump_any_debugging || do_dump || do_debugging) | |
23735 | return true; | |
23736 | ||
23737 | return false; | |
23738 | } | |
23739 | ||
23740 | /* Process one ELF object file according to the command line options. | |
23741 | This file may actually be stored in an archive. The file is | |
23742 | positioned at the start of the ELF object. Returns TRUE if no | |
23743 | problems were encountered, FALSE otherwise. */ | |
23744 | ||
23745 | static bool | |
23746 | process_object (Filedata * filedata) | |
23747 | { | |
23748 | bool have_separate_files; | |
23749 | unsigned int i; | |
23750 | bool res; | |
23751 | ||
23752 | if (! get_file_header (filedata)) | |
23753 | { | |
23754 | error (_("%s: Failed to read file header\n"), filedata->file_name); | |
23755 | return false; | |
23756 | } | |
23757 | ||
23758 | /* Initialise per file variables. */ | |
23759 | for (i = ARRAY_SIZE (filedata->version_info); i--;) | |
23760 | filedata->version_info[i] = 0; | |
23761 | ||
23762 | for (i = ARRAY_SIZE (filedata->dynamic_info); i--;) | |
23763 | filedata->dynamic_info[i] = 0; | |
23764 | filedata->dynamic_info_DT_GNU_HASH = 0; | |
23765 | filedata->dynamic_info_DT_MIPS_XHASH = 0; | |
23766 | ||
23767 | /* Process the file. */ | |
23768 | if (show_name) | |
23769 | printf (_("\nFile: %s\n"), filedata->file_name); | |
23770 | ||
23771 | initialise_dump_sects (filedata); | |
23772 | ||
23773 | /* There may be some extensions in the first section header. Don't | |
23774 | bomb if we can't read it. */ | |
23775 | get_section_headers (filedata, true); | |
23776 | ||
23777 | if (! process_file_header (filedata)) | |
23778 | { | |
23779 | res = false; | |
23780 | goto out; | |
23781 | } | |
23782 | ||
23783 | /* Throw away the single section header read above, so that we | |
23784 | re-read the entire set. */ | |
23785 | free (filedata->section_headers); | |
23786 | filedata->section_headers = NULL; | |
23787 | ||
23788 | if (! process_section_headers (filedata)) | |
23789 | { | |
23790 | /* Without loaded section headers we cannot process lots of things. */ | |
23791 | do_unwind = do_version = do_dump = do_arch = false; | |
23792 | ||
23793 | if (! do_using_dynamic) | |
23794 | do_syms = do_dyn_syms = do_reloc = false; | |
23795 | } | |
23796 | ||
23797 | if (! process_section_groups (filedata)) | |
23798 | /* Without loaded section groups we cannot process unwind. */ | |
23799 | do_unwind = false; | |
23800 | ||
23801 | process_program_headers (filedata); | |
23802 | ||
23803 | res = process_dynamic_section (filedata); | |
23804 | ||
23805 | if (! process_relocs (filedata)) | |
23806 | res = false; | |
23807 | ||
23808 | if (! process_unwind (filedata)) | |
23809 | res = false; | |
23810 | ||
23811 | if (! process_symbol_table (filedata)) | |
23812 | res = false; | |
23813 | ||
23814 | if (! process_lto_symbol_tables (filedata)) | |
23815 | res = false; | |
23816 | ||
23817 | if (! process_syminfo (filedata)) | |
23818 | res = false; | |
23819 | ||
23820 | if (! process_version_sections (filedata)) | |
23821 | res = false; | |
23822 | ||
23823 | if (might_need_separate_debug_info (filedata)) | |
23824 | have_separate_files = load_separate_debug_files (filedata, filedata->file_name); | |
23825 | else | |
23826 | have_separate_files = false; | |
23827 | ||
23828 | if (! process_section_contents (filedata)) | |
23829 | res = false; | |
23830 | ||
23831 | if (have_separate_files) | |
23832 | { | |
23833 | separate_info * d; | |
23834 | ||
23835 | for (d = first_separate_info; d != NULL; d = d->next) | |
23836 | { | |
23837 | initialise_dump_sects (d->handle); | |
23838 | ||
23839 | if (process_links && ! process_file_header (d->handle)) | |
23840 | res = false; | |
23841 | else if (! process_section_headers (d->handle)) | |
23842 | res = false; | |
23843 | else if (! process_section_contents (d->handle)) | |
23844 | res = false; | |
23845 | else if (process_links) | |
23846 | { | |
23847 | if (! process_section_groups (d->handle)) | |
23848 | res = false; | |
23849 | process_program_headers (d->handle); | |
23850 | if (! process_dynamic_section (d->handle)) | |
23851 | res = false; | |
23852 | if (! process_relocs (d->handle)) | |
23853 | res = false; | |
23854 | if (! process_unwind (d->handle)) | |
23855 | res = false; | |
23856 | if (! process_symbol_table (d->handle)) | |
23857 | res = false; | |
23858 | if (! process_lto_symbol_tables (d->handle)) | |
23859 | res = false; | |
23860 | if (! process_syminfo (d->handle)) | |
23861 | res = false; | |
23862 | if (! process_version_sections (d->handle)) | |
23863 | res = false; | |
23864 | if (! process_notes (d->handle)) | |
23865 | res = false; | |
23866 | } | |
23867 | } | |
23868 | ||
23869 | /* The file handles are closed by the call to free_debug_memory() below. */ | |
23870 | } | |
23871 | ||
23872 | if (! process_notes (filedata)) | |
23873 | res = false; | |
23874 | ||
23875 | if (! process_gnu_liblist (filedata)) | |
23876 | res = false; | |
23877 | ||
23878 | if (! process_arch_specific (filedata)) | |
23879 | res = false; | |
23880 | ||
23881 | out: | |
23882 | free_filedata (filedata); | |
23883 | ||
23884 | free_debug_memory (); | |
23885 | ||
23886 | return res; | |
23887 | } | |
23888 | ||
23889 | /* Process an ELF archive. | |
23890 | On entry the file is positioned just after the ARMAG string. | |
23891 | Returns TRUE upon success, FALSE otherwise. */ | |
23892 | ||
23893 | static bool | |
23894 | process_archive (Filedata * filedata, bool is_thin_archive) | |
23895 | { | |
23896 | struct archive_info arch; | |
23897 | struct archive_info nested_arch; | |
23898 | size_t got; | |
23899 | bool ret = true; | |
23900 | ||
23901 | show_name = true; | |
23902 | ||
23903 | /* The ARCH structure is used to hold information about this archive. */ | |
23904 | arch.file_name = NULL; | |
23905 | arch.file = NULL; | |
23906 | arch.index_array = NULL; | |
23907 | arch.sym_table = NULL; | |
23908 | arch.longnames = NULL; | |
23909 | ||
23910 | /* The NESTED_ARCH structure is used as a single-item cache of information | |
23911 | about a nested archive (when members of a thin archive reside within | |
23912 | another regular archive file). */ | |
23913 | nested_arch.file_name = NULL; | |
23914 | nested_arch.file = NULL; | |
23915 | nested_arch.index_array = NULL; | |
23916 | nested_arch.sym_table = NULL; | |
23917 | nested_arch.longnames = NULL; | |
23918 | ||
23919 | if (setup_archive (&arch, filedata->file_name, filedata->handle, | |
23920 | filedata->file_size, is_thin_archive, | |
23921 | do_archive_index) != 0) | |
23922 | { | |
23923 | ret = false; | |
23924 | goto out; | |
23925 | } | |
23926 | ||
23927 | if (do_archive_index) | |
23928 | { | |
23929 | if (arch.sym_table == NULL) | |
23930 | error (_("%s: unable to dump the index as none was found\n"), | |
23931 | filedata->file_name); | |
23932 | else | |
23933 | { | |
23934 | uint64_t i, l; | |
23935 | uint64_t current_pos; | |
23936 | ||
23937 | printf (_("Index of archive %s: (%" PRIu64 " entries," | |
23938 | " %#" PRIx64 " bytes in the symbol table)\n"), | |
23939 | filedata->file_name, arch.index_num, | |
23940 | arch.sym_size); | |
23941 | ||
23942 | current_pos = ftell (filedata->handle); | |
23943 | ||
23944 | for (i = l = 0; i < arch.index_num; i++) | |
23945 | { | |
23946 | if (i == 0 | |
23947 | || (i > 0 && arch.index_array[i] != arch.index_array[i - 1])) | |
23948 | { | |
23949 | char * member_name | |
23950 | = get_archive_member_name_at (&arch, arch.index_array[i], | |
23951 | &nested_arch); | |
23952 | ||
23953 | if (member_name != NULL) | |
23954 | { | |
23955 | char * qualified_name | |
23956 | = make_qualified_name (&arch, &nested_arch, | |
23957 | member_name); | |
23958 | ||
23959 | if (qualified_name != NULL) | |
23960 | { | |
23961 | printf (_("Contents of binary %s at offset "), | |
23962 | qualified_name); | |
23963 | (void) print_vma (arch.index_array[i], PREFIX_HEX); | |
23964 | putchar ('\n'); | |
23965 | free (qualified_name); | |
23966 | } | |
23967 | free (member_name); | |
23968 | } | |
23969 | } | |
23970 | ||
23971 | if (l >= arch.sym_size) | |
23972 | { | |
23973 | error (_("%s: end of the symbol table reached " | |
23974 | "before the end of the index\n"), | |
23975 | filedata->file_name); | |
23976 | ret = false; | |
23977 | break; | |
23978 | } | |
23979 | /* PR 17531: file: 0b6630b2. */ | |
23980 | printf ("\t%.*s\n", | |
23981 | (int) (arch.sym_size - l), arch.sym_table + l); | |
23982 | l += strnlen (arch.sym_table + l, arch.sym_size - l) + 1; | |
23983 | } | |
23984 | ||
23985 | if (arch.uses_64bit_indices) | |
23986 | l = (l + 7) & ~ 7; | |
23987 | else | |
23988 | l += l & 1; | |
23989 | ||
23990 | if (l < arch.sym_size) | |
23991 | { | |
23992 | error (ngettext ("%s: %" PRId64 " byte remains in the symbol table, " | |
23993 | "but without corresponding entries in " | |
23994 | "the index table\n", | |
23995 | "%s: %" PRId64 " bytes remain in the symbol table, " | |
23996 | "but without corresponding entries in " | |
23997 | "the index table\n", | |
23998 | arch.sym_size - l), | |
23999 | filedata->file_name, arch.sym_size - l); | |
24000 | ret = false; | |
24001 | } | |
24002 | ||
24003 | if (fseek64 (filedata->handle, current_pos, SEEK_SET) != 0) | |
24004 | { | |
24005 | error (_("%s: failed to seek back to start of object files " | |
24006 | "in the archive\n"), | |
24007 | filedata->file_name); | |
24008 | ret = false; | |
24009 | goto out; | |
24010 | } | |
24011 | } | |
24012 | ||
24013 | if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections | |
24014 | && !do_segments && !do_header && !do_dump && !do_version | |
24015 | && !do_histogram && !do_debugging && !do_arch && !do_notes | |
24016 | && !do_section_groups && !do_dyn_syms) | |
24017 | { | |
24018 | ret = true; /* Archive index only. */ | |
24019 | goto out; | |
24020 | } | |
24021 | } | |
24022 | ||
24023 | while (1) | |
24024 | { | |
24025 | char * name; | |
24026 | size_t namelen; | |
24027 | char * qualified_name; | |
24028 | ||
24029 | /* Read the next archive header. */ | |
24030 | if (fseek64 (filedata->handle, arch.next_arhdr_offset, SEEK_SET) != 0) | |
24031 | { | |
24032 | error (_("%s: failed to seek to next archive header\n"), | |
24033 | arch.file_name); | |
24034 | ret = false; | |
24035 | break; | |
24036 | } | |
24037 | got = fread (&arch.arhdr, 1, sizeof arch.arhdr, filedata->handle); | |
24038 | if (got != sizeof arch.arhdr) | |
24039 | { | |
24040 | if (got == 0) | |
24041 | break; | |
24042 | /* PR 24049 - we cannot use filedata->file_name as this will | |
24043 | have already been freed. */ | |
24044 | error (_("%s: failed to read archive header\n"), arch.file_name); | |
24045 | ||
24046 | ret = false; | |
24047 | break; | |
24048 | } | |
24049 | if (memcmp (arch.arhdr.ar_fmag, ARFMAG, 2) != 0) | |
24050 | { | |
24051 | error (_("%s: did not find a valid archive header\n"), | |
24052 | arch.file_name); | |
24053 | ret = false; | |
24054 | break; | |
24055 | } | |
24056 | ||
24057 | arch.next_arhdr_offset += sizeof arch.arhdr; | |
24058 | ||
24059 | filedata->archive_file_size = strtoul (arch.arhdr.ar_size, NULL, 10); | |
24060 | ||
24061 | name = get_archive_member_name (&arch, &nested_arch); | |
24062 | if (name == NULL) | |
24063 | { | |
24064 | error (_("%s: bad archive file name\n"), arch.file_name); | |
24065 | ret = false; | |
24066 | break; | |
24067 | } | |
24068 | namelen = strlen (name); | |
24069 | ||
24070 | qualified_name = make_qualified_name (&arch, &nested_arch, name); | |
24071 | if (qualified_name == NULL) | |
24072 | { | |
24073 | error (_("%s: bad archive file name\n"), arch.file_name); | |
24074 | free (name); | |
24075 | ret = false; | |
24076 | break; | |
24077 | } | |
24078 | ||
24079 | if (is_thin_archive && arch.nested_member_origin == 0) | |
24080 | { | |
24081 | /* This is a proxy for an external member of a thin archive. */ | |
24082 | Filedata * member_filedata; | |
24083 | char * member_file_name = adjust_relative_path | |
24084 | (filedata->file_name, name, namelen); | |
24085 | ||
24086 | free (name); | |
24087 | if (member_file_name == NULL) | |
24088 | { | |
24089 | free (qualified_name); | |
24090 | ret = false; | |
24091 | break; | |
24092 | } | |
24093 | ||
24094 | member_filedata = open_file (member_file_name, false); | |
24095 | if (member_filedata == NULL) | |
24096 | { | |
24097 | error (_("Input file '%s' is not readable.\n"), member_file_name); | |
24098 | free (member_file_name); | |
24099 | free (qualified_name); | |
24100 | ret = false; | |
24101 | break; | |
24102 | } | |
24103 | ||
24104 | filedata->archive_file_offset = arch.nested_member_origin; | |
24105 | member_filedata->file_name = qualified_name; | |
24106 | ||
24107 | /* The call to process_object() expects the file to be at the beginning. */ | |
24108 | rewind (member_filedata->handle); | |
24109 | ||
24110 | if (! process_object (member_filedata)) | |
24111 | ret = false; | |
24112 | ||
24113 | close_file (member_filedata); | |
24114 | free (member_file_name); | |
24115 | } | |
24116 | else if (is_thin_archive) | |
24117 | { | |
24118 | Filedata thin_filedata; | |
24119 | ||
24120 | memset (&thin_filedata, 0, sizeof (thin_filedata)); | |
24121 | ||
24122 | /* PR 15140: Allow for corrupt thin archives. */ | |
24123 | if (nested_arch.file == NULL) | |
24124 | { | |
24125 | error (_("%s: contains corrupt thin archive: %s\n"), | |
24126 | qualified_name, name); | |
24127 | free (qualified_name); | |
24128 | free (name); | |
24129 | ret = false; | |
24130 | break; | |
24131 | } | |
24132 | free (name); | |
24133 | ||
24134 | /* This is a proxy for a member of a nested archive. */ | |
24135 | filedata->archive_file_offset | |
24136 | = arch.nested_member_origin + sizeof arch.arhdr; | |
24137 | ||
24138 | /* The nested archive file will have been opened and setup by | |
24139 | get_archive_member_name. */ | |
24140 | if (fseek64 (nested_arch.file, filedata->archive_file_offset, | |
24141 | SEEK_SET) != 0) | |
24142 | { | |
24143 | error (_("%s: failed to seek to archive member.\n"), | |
24144 | nested_arch.file_name); | |
24145 | free (qualified_name); | |
24146 | ret = false; | |
24147 | break; | |
24148 | } | |
24149 | ||
24150 | thin_filedata.handle = nested_arch.file; | |
24151 | thin_filedata.file_name = qualified_name; | |
24152 | ||
24153 | if (! process_object (& thin_filedata)) | |
24154 | ret = false; | |
24155 | } | |
24156 | else | |
24157 | { | |
24158 | free (name); | |
24159 | filedata->archive_file_offset = arch.next_arhdr_offset; | |
24160 | filedata->file_name = qualified_name; | |
24161 | if (! process_object (filedata)) | |
24162 | ret = false; | |
24163 | arch.next_arhdr_offset += (filedata->archive_file_size + 1) & -2; | |
24164 | /* Stop looping with "negative" archive_file_size. */ | |
24165 | if (arch.next_arhdr_offset < filedata->archive_file_size) | |
24166 | arch.next_arhdr_offset = -1ul; | |
24167 | } | |
24168 | ||
24169 | free (qualified_name); | |
24170 | } | |
24171 | ||
24172 | out: | |
24173 | if (nested_arch.file != NULL) | |
24174 | fclose (nested_arch.file); | |
24175 | release_archive (&nested_arch); | |
24176 | release_archive (&arch); | |
24177 | ||
24178 | return ret; | |
24179 | } | |
24180 | ||
24181 | static bool | |
24182 | process_file (char * file_name) | |
24183 | { | |
24184 | Filedata * filedata = NULL; | |
24185 | struct stat statbuf; | |
24186 | char armag[SARMAG]; | |
24187 | bool ret = true; | |
24188 | ||
24189 | if (stat (file_name, &statbuf) < 0) | |
24190 | { | |
24191 | if (errno == ENOENT) | |
24192 | error (_("'%s': No such file\n"), file_name); | |
24193 | else | |
24194 | error (_("Could not locate '%s'. System error message: %s\n"), | |
24195 | file_name, strerror (errno)); | |
24196 | return false; | |
24197 | } | |
24198 | ||
24199 | if (! S_ISREG (statbuf.st_mode)) | |
24200 | { | |
24201 | error (_("'%s' is not an ordinary file\n"), file_name); | |
24202 | return false; | |
24203 | } | |
24204 | ||
24205 | filedata = calloc (1, sizeof * filedata); | |
24206 | if (filedata == NULL) | |
24207 | { | |
24208 | error (_("Out of memory allocating file data structure\n")); | |
24209 | return false; | |
24210 | } | |
24211 | ||
24212 | filedata->file_name = file_name; | |
24213 | filedata->handle = fopen (file_name, "rb"); | |
24214 | if (filedata->handle == NULL) | |
24215 | { | |
24216 | error (_("Input file '%s' is not readable.\n"), file_name); | |
24217 | free (filedata); | |
24218 | return false; | |
24219 | } | |
24220 | ||
24221 | if (fread (armag, SARMAG, 1, filedata->handle) != 1) | |
24222 | { | |
24223 | error (_("%s: Failed to read file's magic number\n"), file_name); | |
24224 | fclose (filedata->handle); | |
24225 | free (filedata); | |
24226 | return false; | |
24227 | } | |
24228 | ||
24229 | filedata->file_size = statbuf.st_size; | |
24230 | filedata->is_separate = false; | |
24231 | ||
24232 | if (memcmp (armag, ARMAG, SARMAG) == 0) | |
24233 | { | |
24234 | if (! process_archive (filedata, false)) | |
24235 | ret = false; | |
24236 | } | |
24237 | else if (memcmp (armag, ARMAGT, SARMAG) == 0) | |
24238 | { | |
24239 | if ( ! process_archive (filedata, true)) | |
24240 | ret = false; | |
24241 | } | |
24242 | else | |
24243 | { | |
24244 | if (do_archive_index && !check_all) | |
24245 | error (_("File %s is not an archive so its index cannot be displayed.\n"), | |
24246 | file_name); | |
24247 | ||
24248 | rewind (filedata->handle); | |
24249 | filedata->archive_file_size = filedata->archive_file_offset = 0; | |
24250 | ||
24251 | if (! process_object (filedata)) | |
24252 | ret = false; | |
24253 | } | |
24254 | ||
24255 | close_debug_file (filedata); | |
24256 | ||
24257 | free (ba_cache.strtab); | |
24258 | ba_cache.strtab = NULL; | |
24259 | free (ba_cache.symtab); | |
24260 | ba_cache.symtab = NULL; | |
24261 | ba_cache.filedata = NULL; | |
24262 | ||
24263 | return ret; | |
24264 | } | |
24265 | ||
24266 | #ifdef SUPPORT_DISASSEMBLY | |
24267 | /* Needed by the i386 disassembler. For extra credit, someone could | |
24268 | fix this so that we insert symbolic addresses here, esp for GOT/PLT | |
24269 | symbols. */ | |
24270 | ||
24271 | void | |
24272 | print_address (unsigned int addr, FILE * outfile) | |
24273 | { | |
24274 | fprintf (outfile,"0x%8.8x", addr); | |
24275 | } | |
24276 | ||
24277 | /* Needed by the i386 disassembler. */ | |
24278 | ||
24279 | void | |
24280 | db_task_printsym (unsigned int addr) | |
24281 | { | |
24282 | print_address (addr, stderr); | |
24283 | } | |
24284 | #endif | |
24285 | ||
24286 | int | |
24287 | main (int argc, char ** argv) | |
24288 | { | |
24289 | int err; | |
24290 | ||
24291 | #ifdef HAVE_LC_MESSAGES | |
24292 | setlocale (LC_MESSAGES, ""); | |
24293 | #endif | |
24294 | setlocale (LC_CTYPE, ""); | |
24295 | bindtextdomain (PACKAGE, LOCALEDIR); | |
24296 | textdomain (PACKAGE); | |
24297 | ||
24298 | expandargv (&argc, &argv); | |
24299 | ||
24300 | parse_args (& cmdline, argc, argv); | |
24301 | ||
24302 | if (optind < (argc - 1)) | |
24303 | /* When displaying information for more than one file, | |
24304 | prefix the information with the file name. */ | |
24305 | show_name = true; | |
24306 | else if (optind >= argc) | |
24307 | { | |
24308 | /* Ensure that the warning is always displayed. */ | |
24309 | do_checks = true; | |
24310 | ||
24311 | warn (_("Nothing to do.\n")); | |
24312 | usage (stderr); | |
24313 | } | |
24314 | ||
24315 | err = false; | |
24316 | while (optind < argc) | |
24317 | if (! process_file (argv[optind++])) | |
24318 | err = true; | |
24319 | ||
24320 | free (cmdline.dump_sects); | |
24321 | ||
24322 | free (dump_ctf_symtab_name); | |
24323 | free (dump_ctf_strtab_name); | |
24324 | free (dump_ctf_parent_name); | |
24325 | ||
24326 | return err ? EXIT_FAILURE : EXIT_SUCCESS; | |
24327 | } |