Lines Matching +full:ecx +full:- +full:1000
1 /*-
2 * Copyright (c) 2009-2015 Kai Wang
57 ELFTC_VCSID("$Id: readelf.c 3769 2019-06-29 15:15:02Z emaste $");
192 {"arch-specific", no_argument, NULL, 'A'},
193 {"archive-index", no_argument, NULL, 'c'},
194 {"debug-dump", optional_argument, NULL, OPTION_DEBUG_DUMP},
197 {"file-header", no_argument, NULL, 'h'},
198 {"full-section-name", no_argument, NULL, 'N'},
201 {"hex-dump", required_argument, NULL, 'x'},
204 {"program-headers", no_argument, NULL, 'l'},
207 {"section-headers", no_argument, NULL, 'S'},
208 {"section-groups", no_argument, NULL, 'g'},
209 {"section-details", no_argument, NULL, 't'},
211 {"string-dump", required_argument, NULL, 'p'},
215 {"use-dynamic", no_argument, NULL, 'D'},
216 {"version-info", no_argument, 0, 'V'},
448 {EF_PPC_RELOCATABLE_LIB, "relocatable-lib"},
512 case EM_MIPS: return "MIPS R3000 Big-Endian only"; in elf_machine()
514 case EM_MIPS_RS3_LE: return "MIPS R3000 Little-Endian"; in elf_machine()
515 case EM_PARISC: return "HP PA-RISC"; in elf_machine()
519 case EM_PPC: return "PowerPC 32-bit"; in elf_machine()
520 case EM_PPC64: return "PowerPC 64-bit"; in elf_machine()
524 case EM_RH32: return "TRW RH-32"; in elf_machine()
528 case EM_SPARCV9: return "SPARC v9 64-bit"; in elf_machine()
535 case EM_IA_64: return "Intel IA-64 Processor"; in elf_machine()
536 case EM_MIPS_X: return "Stanford MIPS-X"; in elf_machine()
547 case EM_X86_64: return "Advanced Micro Devices x86-64"; in elf_machine()
551 case EM_ST7: return "STmicroelectronics ST7 8-bit microcontroller"; in elf_machine()
557 case EM_ST19: return "STMicroelectronics ST19 8-bit mc"; in elf_machine()
559 case EM_CRIS: return "Axis Communications 32-bit embedded processor"; in elf_machine()
561 case EM_FIREPATH: return "Element 14 64-bit DSP Processor"; in elf_machine()
562 case EM_ZSP: return "LSI Logic 16-bit DSP Processor"; in elf_machine()
563 case EM_MMIX: return "Donald Knuth's educational 64-bit proc"; in elf_machine()
566 case EM_AVR: return "Atmel AVR 8-bit microcontroller"; in elf_machine()
575 case EM_OPENRISC: return "OpenRISC 32-bit embedded processor"; in elf_machine()
576 case EM_ARC_A5: return "ARC Cores Tangent-A5"; in elf_machine()
582 case EM_SNP1K: return "Trebia SNP 1000 processor"; in elf_machine()
593 case EM_UNICORE: return "Microprocessor series from PKU-Unity Ltd"; in elf_machine()
595 case EM_RISCV: return "RISC-V"; in elf_machine()
686 ptype - PT_LOPROC); in phdr_type()
708 ptype - PT_LOOS); in phdr_type()
780 stype - SHT_LOPROC); in section_type()
817 stype - SHT_LOOS); in section_type()
820 stype - SHT_LOUSER); in section_type()
1075 stype - STT_LOOS); in st_type()
1080 stype - STT_LOPROC); in st_type()
1417 case 0: return "Pre-V4"; in aeabi_cpu_arch()
1428 case 11: return "ARM v6-M"; in aeabi_cpu_arch()
1429 case 12: return "ARM v6S-M"; in aeabi_cpu_arch()
1430 case 13: return "ARM v7E-M"; in aeabi_cpu_arch()
1449 return "Real-Time Profile"; in aeabi_cpu_arch_profile()
1453 return "Application or Real-Time Profile"; in aeabi_cpu_arch_profile()
1483 case 1: return "16-bit Thumb"; in aeabi_thumb_isa()
1484 case 2: return "32-bit Thumb"; in aeabi_thumb_isa()
1502 case 4: return "VFPv3-D16"; in aeabi_fp_arch()
1504 case 6: return "VFPv4-D16"; in aeabi_fp_arch()
1588 case 1: return "PC-relative"; in aeabi_pcs_rw()
1589 case 2: return "SB-relative"; in aeabi_pcs_rw()
1604 case 1: return "PC-relative"; in aeabi_pcs_ro()
1651 case 2: return "32-bit"; in aeabi_enum_size()
1652 case 3: return "visible 32-bit"; in aeabi_enum_size()
1666 case 1: return "8-byte align"; in aeabi_align_needed()
1667 case 2: return "4-byte align"; in aeabi_align_needed()
1671 snprintf(s_align_n, sizeof(s_align_n), "8-byte align" in aeabi_align_needed()
1672 " and up to 2^%ju-byte extended align", in aeabi_align_needed()
1688 case 1: return "8-byte align"; in aeabi_align_preserved()
1689 case 2: return "8-byte align and SP % 8 == 0"; in aeabi_align_preserved()
1693 snprintf(s_align_p, sizeof(s_align_p), "8-byte align" in aeabi_align_preserved()
1694 " and SP %% 8 == 0 and up to 2^%ju-byte extended" in aeabi_align_preserved()
1818 case 0: return "Yes (V7-R/V7-M)"; in aeabi_div()
1820 case 2: return "Yes (V7-A)"; in aeabi_div()
1869 case 2: return "toolchain-specific"; in aeabi_vfp_args()
1884 case 2: return "toolchain-specific"; in aeabi_wmmx_args()
2032 case 4: return "64-bit float (-mips32r2 -mfp64)"; in mips_abi_fp()
2082 case 1: return "ecx"; in dwarf_reg()
2271 printf("%.2x ", re->ehdr.e_ident[i]); in dump_ehdr()
2275 printf("%-37s%s\n", " Class:", elf_class(re->ehdr.e_ident[EI_CLASS])); in dump_ehdr()
2278 printf("%-37s%s\n", " Data:", elf_endian(re->ehdr.e_ident[EI_DATA])); in dump_ehdr()
2281 printf("%-37s%d %s\n", " Version:", re->ehdr.e_ident[EI_VERSION], in dump_ehdr()
2282 elf_ver(re->ehdr.e_ident[EI_VERSION])); in dump_ehdr()
2285 printf("%-37s%s\n", " OS/ABI:", elf_osabi(re->ehdr.e_ident[EI_OSABI])); in dump_ehdr()
2288 printf("%-37s%d\n", " ABI Version:", re->ehdr.e_ident[EI_ABIVERSION]); in dump_ehdr()
2291 printf("%-37s%s\n", " Type:", elf_type(re->ehdr.e_type)); in dump_ehdr()
2294 printf("%-37s%s\n", " Machine:", elf_machine(re->ehdr.e_machine)); in dump_ehdr()
2297 printf("%-37s%#x\n", " Version:", re->ehdr.e_version); in dump_ehdr()
2300 printf("%-37s%#jx\n", " Entry point address:", in dump_ehdr()
2301 (uintmax_t)re->ehdr.e_entry); in dump_ehdr()
2304 printf("%-37s%ju (bytes into file)\n", " Start of program headers:", in dump_ehdr()
2305 (uintmax_t)re->ehdr.e_phoff); in dump_ehdr()
2308 printf("%-37s%ju (bytes into file)\n", " Start of section headers:", in dump_ehdr()
2309 (uintmax_t)re->ehdr.e_shoff); in dump_ehdr()
2312 printf("%-37s%#x", " Flags:", re->ehdr.e_flags); in dump_ehdr()
2313 dump_eflags(re, re->ehdr.e_flags); in dump_ehdr()
2317 printf("%-37s%u (bytes)\n", " Size of this header:", in dump_ehdr()
2318 re->ehdr.e_ehsize); in dump_ehdr()
2321 printf("%-37s%u (bytes)\n", " Size of program headers:", in dump_ehdr()
2322 re->ehdr.e_phentsize); in dump_ehdr()
2325 printf("%-37s%u", " Number of program headers:", re->ehdr.e_phnum); in dump_ehdr()
2326 if (re->ehdr.e_phnum == PN_XNUM) { in dump_ehdr()
2328 if (elf_getphnum(re->elf, &phnum)) in dump_ehdr()
2334 printf("%-37s%u (bytes)\n", " Size of section headers:", in dump_ehdr()
2335 re->ehdr.e_shentsize); in dump_ehdr()
2338 printf("%-37s%u", " Number of section headers:", re->ehdr.e_shnum); in dump_ehdr()
2339 if (re->ehdr.e_shnum == SHN_UNDEF) { in dump_ehdr()
2341 if (elf_getshnum(re->elf, &shnum)) in dump_ehdr()
2347 printf("%-37s%u", " Section header string table index:", in dump_ehdr()
2348 re->ehdr.e_shstrndx); in dump_ehdr()
2349 if (re->ehdr.e_shstrndx == SHN_XINDEX) { in dump_ehdr()
2351 if (elf_getshstrndx(re->elf, &shstrndx)) in dump_ehdr()
2364 switch (re->ehdr.e_machine) { in dump_eflags()
2400 case 0xa0: printf(", loongson-2e"); break; in dump_eflags()
2401 case 0xa1: printf(", loongson-2f"); break; in dump_eflags()
2427 printf(", soft-float ABI"); in dump_eflags()
2430 printf(", single-float ABI"); in dump_eflags()
2433 printf(", double-float ABI"); in dump_eflags()
2436 printf(", quad-float ABI"); in dump_eflags()
2457 while (edesc->desc != NULL) { in dump_eflags()
2458 if (e_flags & edesc->flag) in dump_eflags()
2459 printf(", %s", edesc->desc); in dump_eflags()
2475 #define PH_CT phdr_type(re->ehdr.e_machine, phdr.p_type), \ in dump_phdr()
2484 if (elf_getphnum(re->elf, &phnum) == 0) { in dump_phdr()
2485 warnx("elf_getphnum failed: %s", elf_errmsg(-1)); in dump_phdr()
2493 printf("\nElf file type is %s", elf_type(re->ehdr.e_type)); in dump_phdr()
2494 printf("\nEntry point 0x%jx\n", (uintmax_t)re->ehdr.e_entry); in dump_phdr()
2496 (uintmax_t)phnum, (uintmax_t)re->ehdr.e_phoff); in dump_phdr()
2500 if (re->ec == ELFCLASS32) in dump_phdr()
2501 printf(" %-15s%-9s%-11s%-11s%-8s%-8s%-4s%s\n", PH_HDR); in dump_phdr()
2502 else if (re->options & RE_WW) in dump_phdr()
2503 printf(" %-15s%-9s%-19s%-19s%-9s%-9s%-4s%s\n", PH_HDR); in dump_phdr()
2505 printf(" %-15s%-19s%-19s%s\n %-19s%-20s" in dump_phdr()
2506 "%-7s%s\n", PH_HDR); in dump_phdr()
2508 if (gelf_getphdr(re->elf, i, &phdr) != &phdr) { in dump_phdr()
2509 warnx("gelf_getphdr failed: %s", elf_errmsg(-1)); in dump_phdr()
2512 /* TODO: Add arch-specific segment type dump. */ in dump_phdr()
2513 if (re->ec == ELFCLASS32) in dump_phdr()
2514 printf(" %-14.14s 0x%6.6jx 0x%8.8jx 0x%8.8jx " in dump_phdr()
2516 else if (re->options & RE_WW) in dump_phdr()
2517 printf(" %-14.14s 0x%6.6jx 0x%16.16jx 0x%16.16jx " in dump_phdr()
2520 printf(" %-14.14s 0x%16.16jx 0x%16.16jx 0x%16.16jx\n" in dump_phdr()
2524 if ((rawfile = elf_rawfile(re->elf, &size)) == NULL) { in dump_phdr()
2525 warnx("elf_rawfile failed: %s", elf_errmsg(-1)); in dump_phdr()
2538 if (re->shnum == 0) in dump_phdr()
2543 if (gelf_getphdr(re->elf, i, &phdr) != &phdr) { in dump_phdr()
2544 warnx("gelf_getphdr failed: %s", elf_errmsg(-1)); in dump_phdr()
2549 for (j = 1; (size_t)j < re->shnum; j++) { in dump_phdr()
2550 if (re->sl[j].off < phdr.p_offset) in dump_phdr()
2552 if (re->sl[j].off + re->sl[j].sz > in dump_phdr()
2554 re->sl[j].type != SHT_NOBITS) in dump_phdr()
2556 if (re->sl[j].addr < phdr.p_vaddr || in dump_phdr()
2557 re->sl[j].addr + re->sl[j].sz > in dump_phdr()
2561 (re->sl[j].flags & SHF_TLS) == 0) in dump_phdr()
2563 printf("%s ", re->sl[j].name); in dump_phdr()
2579 nb = re->ec == ELFCLASS32 ? 8 : 16; in section_flags()
2580 if (re->options & RE_T) { in section_flags()
2582 (uintmax_t)s->flags); in section_flags()
2586 if ((s->flags & section_flag[i].value) == 0) in section_flags()
2588 if (re->options & RE_T) { in section_flags()
2589 snprintf(&buf[p], BUF_SZ - p, "%s, ", in section_flags()
2595 if (re->options & RE_T && p > nb + 4) in section_flags()
2596 p -= 2; in section_flags()
2616 #define S_CT i, s->name, section_type(re->ehdr.e_machine, s->type), \ in dump_shdr()
2617 (uintmax_t)s->addr, (uintmax_t)s->off, (uintmax_t)s->sz,\ in dump_shdr()
2618 (uintmax_t)s->entsize, section_flags(re, s), \ in dump_shdr()
2619 s->link, s->info, (uintmax_t)s->align in dump_shdr()
2620 #define ST_CT i, s->name, section_type(re->ehdr.e_machine, s->type), \ in dump_shdr()
2621 (uintmax_t)s->addr, (uintmax_t)s->off, (uintmax_t)s->sz,\ in dump_shdr()
2622 (uintmax_t)s->entsize, s->link, s->info, \ in dump_shdr()
2623 (uintmax_t)s->align, section_flags(re, s) in dump_shdr()
2624 #define ST_CTL i, s->name, section_type(re->ehdr.e_machine, s->type), \ in dump_shdr()
2625 (uintmax_t)s->addr, (uintmax_t)s->off, s->link, \ in dump_shdr()
2626 (uintmax_t)s->sz, (uintmax_t)s->entsize, s->info, \ in dump_shdr()
2627 (uintmax_t)s->align, section_flags(re, s) in dump_shdr()
2629 if (re->shnum == 0) { in dump_shdr()
2634 (uintmax_t)re->shnum, (uintmax_t)re->ehdr.e_shoff); in dump_shdr()
2636 if (re->ec == ELFCLASS32) { in dump_shdr()
2637 if (re->options & RE_T) in dump_shdr()
2638 printf(" %s\n %-16s%-9s%-7s%-7s%-5s%-3s%-4s%s\n" in dump_shdr()
2641 printf(" %-23s%-16s%-9s%-7s%-7s%-3s%-4s%-3s%-4s%s\n", in dump_shdr()
2643 } else if (re->options & RE_WW) { in dump_shdr()
2644 if (re->options & RE_T) in dump_shdr()
2645 printf(" %s\n %-16s%-17s%-7s%-7s%-5s%-3s%-4s%s\n" in dump_shdr()
2648 printf(" %-23s%-16s%-17s%-7s%-7s%-3s%-4s%-3s%-4s%s\n", in dump_shdr()
2651 if (re->options & RE_T) in dump_shdr()
2652 printf(" %s\n %-18s%-17s%-18s%s\n %-18s" in dump_shdr()
2653 "%-17s%-18s%s\n%12s\n", ST_HDRL); in dump_shdr()
2655 printf(" %-23s%-17s%-18s%s\n %-18s%-17s%-7s%" in dump_shdr()
2656 "-6s%-6s%s\n", S_HDRL); in dump_shdr()
2658 for (i = 0; (size_t)i < re->shnum; i++) { in dump_shdr()
2659 s = &re->sl[i]; in dump_shdr()
2660 if (re->ec == ELFCLASS32) { in dump_shdr()
2661 if (re->options & RE_T) in dump_shdr()
2662 printf(" [%2d] %s\n %-15.15s %8.8jx" in dump_shdr()
2666 if (re->options & RE_WW) in dump_shdr()
2667 printf(" [%2d] %-17s %-15.15s " in dump_shdr()
2671 printf(" [%2d] %-17.17s %-15.15s " in dump_shdr()
2674 } else if (re->options & RE_WW) { in dump_shdr()
2675 if (re->options & RE_T) in dump_shdr()
2676 printf(" [%2d] %s\n %-15.15s %16.16jx" in dump_shdr()
2680 printf(" [%2d] %-17s %-15.15s %16.16jx" in dump_shdr()
2684 if (re->options & RE_T) in dump_shdr()
2685 printf(" [%2d] %s\n %-15.15s %16.16jx" in dump_shdr()
2687 " %-16u %ju\n %s\n", ST_CTL); in dump_shdr()
2689 printf(" [%2d] %-17.17s %-15.15s %16.16jx" in dump_shdr()
2694 if ((re->options & RE_T) == 0) in dump_shdr()
2717 if (s->entsize == 0) { in get_ent_count()
2718 warnx("section %s has entry size 0", s->name); in get_ent_count()
2720 } else if (s->sz / s->entsize > INT_MAX) { in get_ent_count()
2721 warnx("section %s has invalid section count", s->name); in get_ent_count()
2724 *ent_count = (int)(s->sz / s->entsize); in get_ent_count()
2738 for (i = 0; (size_t)i < re->shnum; i++) { in dump_dynamic()
2739 s = &re->sl[i]; in dump_dynamic()
2740 if (s->type != SHT_DYNAMIC) in dump_dynamic()
2743 if ((d = elf_getdata(s->scn, NULL)) == NULL) { in dump_dynamic()
2746 warnx("elf_getdata failed: %s", elf_errmsg(-1)); in dump_dynamic()
2749 if (d->d_size <= 0) in dump_dynamic()
2761 elf_errmsg(-1)); in dump_dynamic()
2769 printf("\nDynamic section at offset 0x%jx", (uintmax_t)s->off); in dump_dynamic()
2772 if (re->ec == ELFCLASS32) in dump_dynamic()
2781 if (re->ec == ELFCLASS32) in dump_dynamic()
2785 printf(" %-20s", dt_type(re->ehdr.e_machine, in dump_dynamic()
2788 dump_dyn_val(re, &dyn, s->link); in dump_dynamic()
2803 snprintf(ts, sizeof(ts), "%04d-%02d-%02dT%02d:%02d:%02d", in timestamp()
2804 t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, in timestamp()
2805 t->tm_min, t->tm_sec); in timestamp()
2817 else if ((name = elf_strptr(re->elf, stab, d_val)) == NULL) { in dyn_str()
2828 switch (re->ehdr.e_machine) { in dump_arch_dyn_val()
2831 switch (dyn->d_tag) { in dump_arch_dyn_val()
2849 printf(" %ju\n", (uintmax_t) dyn->d_un.d_val); in dump_arch_dyn_val()
2876 printf(" 0x%jx\n", (uintmax_t) dyn->d_un.d_val); in dump_arch_dyn_val()
2881 printf(" %s\n", timestamp(dyn->d_un.d_val)); in dump_arch_dyn_val()
2899 for (fd = desc; fd->flag != 0; fd++) { in dump_flags()
2900 if (val & fd->flag) { in dump_flags()
2901 val &= ~fd->flag; in dump_flags()
2902 printf(" %s", fd->desc); in dump_flags()
2955 if (dyn->d_tag >= DT_LOPROC && dyn->d_tag <= DT_HIPROC && in dump_dyn_val()
2956 dyn->d_tag != DT_AUXILIARY && dyn->d_tag != DT_FILTER) { in dump_dyn_val()
2963 if (dyn->d_tag == DT_AUXILIARY || dyn->d_tag == DT_FILTER || in dump_dyn_val()
2964 dyn->d_tag == DT_NEEDED || dyn->d_tag == DT_SONAME || in dump_dyn_val()
2965 dyn->d_tag == DT_RPATH || dyn->d_tag == DT_RUNPATH) in dump_dyn_val()
2966 name = dyn_str(re, stab, dyn->d_un.d_val); in dump_dyn_val()
2968 switch(dyn->d_tag) { in dump_dyn_val()
2988 printf(" 0x%jx\n", (uintmax_t) dyn->d_un.d_val); in dump_dyn_val()
3002 printf(" %ju (bytes)\n", (uintmax_t) dyn->d_un.d_val); in dump_dyn_val()
3008 printf(" %ju\n", (uintmax_t) dyn->d_un.d_val); in dump_dyn_val()
3029 printf(" %s\n", dt_type(re->ehdr.e_machine, dyn->d_un.d_val)); in dump_dyn_val()
3032 printf(" %s\n", timestamp(dyn->d_un.d_val)); in dump_dyn_val()
3035 dump_flags(dt_flags, dyn->d_un.d_val); in dump_dyn_val()
3038 dump_flags(dt_flags_1, dyn->d_un.d_val); in dump_dyn_val()
3055 if (s->link >= re->shnum) in dump_rel()
3060 elftc_reloc_type_str(re->ehdr.e_machine, \ in dump_rel()
3063 elftc_reloc_type_str(re->ehdr.e_machine, type), \ in dump_rel()
3066 printf("\nRelocation section (%s):\n", s->name); in dump_rel()
3067 if (re->ec == ELFCLASS32) in dump_rel()
3068 printf("%-8s %-8s %-19s %-8s %s\n", REL_HDR); in dump_rel()
3070 if (re->options & RE_WW) in dump_rel()
3071 printf("%-16s %-16s %-24s %-16s %s\n", REL_HDR); in dump_rel()
3073 printf("%-12s %-12s %-19s %-16s %s\n", REL_HDR); in dump_rel()
3075 assert(d->d_size == s->sz); in dump_rel()
3080 warnx("gelf_getrel failed: %s", elf_errmsg(-1)); in dump_rel()
3083 symname = get_symbol_name(re, s->link, GELF_R_SYM(r.r_info)); in dump_rel()
3084 symval = get_symbol_value(re, s->link, GELF_R_SYM(r.r_info)); in dump_rel()
3085 if (re->ec == ELFCLASS32) { in dump_rel()
3088 printf("%8.8jx %8.8jx %-19.19s %8.8jx %s\n", REL_CT32); in dump_rel()
3091 if (re->ehdr.e_machine == EM_MIPS) { in dump_rel()
3098 if (re->options & RE_WW) in dump_rel()
3099 printf("%16.16jx %16.16jx %-24.24s" in dump_rel()
3102 printf("%12.12jx %12.12jx %-19.19s" in dump_rel()
3104 if (re->ehdr.e_machine == EM_MIPS) { in dump_rel()
3105 if (re->options & RE_WW) { in dump_rel()
3138 if (s->link >= re->shnum) in dump_rela()
3144 elftc_reloc_type_str(re->ehdr.e_machine, \ in dump_rela()
3147 elftc_reloc_type_str(re->ehdr.e_machine, type), \ in dump_rela()
3150 printf("\nRelocation section with addend (%s):\n", s->name); in dump_rela()
3151 if (re->ec == ELFCLASS32) in dump_rela()
3152 printf("%-8s %-8s %-19s %-8s %s\n", RELA_HDR); in dump_rela()
3154 if (re->options & RE_WW) in dump_rela()
3155 printf("%-16s %-16s %-24s %-16s %s\n", RELA_HDR); in dump_rela()
3157 printf("%-12s %-12s %-19s %-16s %s\n", RELA_HDR); in dump_rela()
3159 assert(d->d_size == s->sz); in dump_rela()
3164 warnx("gelf_getrel failed: %s", elf_errmsg(-1)); in dump_rela()
3167 symname = get_symbol_name(re, s->link, GELF_R_SYM(r.r_info)); in dump_rela()
3168 symval = get_symbol_value(re, s->link, GELF_R_SYM(r.r_info)); in dump_rela()
3169 if (re->ec == ELFCLASS32) { in dump_rela()
3172 printf("%8.8jx %8.8jx %-19.19s %8.8jx %s", RELA_CT32); in dump_rela()
3176 if (re->ehdr.e_machine == EM_MIPS) { in dump_rela()
3183 if (re->options & RE_WW) in dump_rela()
3184 printf("%16.16jx %16.16jx %-24.24s" in dump_rela()
3187 printf("%12.12jx %12.12jx %-19.19s" in dump_rela()
3190 if (re->ehdr.e_machine == EM_MIPS) { in dump_rela()
3191 if (re->options & RE_WW) { in dump_rela()
3221 for (i = 0; (size_t)i < re->shnum; i++) { in dump_reloc()
3222 s = &re->sl[i]; in dump_reloc()
3223 if (s->type == SHT_REL || s->type == SHT_RELA) { in dump_reloc()
3225 if ((d = elf_getdata(s->scn, NULL)) == NULL) { in dump_reloc()
3232 if (s->type == SHT_REL) in dump_reloc()
3251 s = &re->sl[i]; in dump_symtab()
3252 if (s->link >= re->shnum) in dump_symtab()
3254 stab = s->link; in dump_symtab()
3256 if ((d = elf_getdata(s->scn, NULL)) == NULL) { in dump_symtab()
3262 if (d->d_size <= 0) in dump_symtab()
3266 printf("\nSymbol table '%s' contains %d entries:\n", s->name, len); in dump_symtab()
3272 warnx("gelf_getsym failed: %s", elf_errmsg(-1)); in dump_symtab()
3278 printf(" %-7s", st_type(re->ehdr.e_machine, in dump_symtab()
3279 re->ehdr.e_ident[EI_OSABI], GELF_ST_TYPE(sym.st_info))); in dump_symtab()
3280 printf(" %-6s", st_bind(GELF_ST_BIND(sym.st_info))); in dump_symtab()
3281 printf(" %-8s", st_vis(GELF_ST_VISIBILITY(sym.st_other))); in dump_symtab()
3283 if ((name = elf_strptr(re->elf, stab, sym.st_name)) != NULL) in dump_symtab()
3286 if (s->type == SHT_DYNSYM && re->ver != NULL && in dump_symtab()
3287 re->vs != NULL && re->vs[j] > 1) { in dump_symtab()
3288 vs = re->vs[j] & VERSYM_VERSION; in dump_symtab()
3289 if (vs >= re->ver_sz || re->ver[vs].name == NULL) { in dump_symtab()
3293 if (re->vs[j] & VERSYM_HIDDEN || re->ver[vs].type == 0) in dump_symtab()
3294 printf("@%s (%d)", re->ver[vs].name, vs); in dump_symtab()
3296 printf("@@%s (%d)", re->ver[vs].name, vs); in dump_symtab()
3313 * If -D is specified, only dump the symbol table specified by in dump_symtabs()
3317 if (re->options & RE_DD) { in dump_symtabs()
3319 for (i = 0; (size_t)i < re->shnum; i++) in dump_symtabs()
3320 if (re->sl[i].type == SHT_DYNAMIC) { in dump_symtabs()
3321 s = &re->sl[i]; in dump_symtabs()
3327 if ((d = elf_getdata(s->scn, NULL)) == NULL) { in dump_symtabs()
3330 warnx("elf_getdata failed: %s", elf_errmsg(-1)); in dump_symtabs()
3333 if (d->d_size <= 0) in dump_symtabs()
3340 warnx("gelf_getdyn failed: %s", elf_errmsg(-1)); in dump_symtabs()
3351 for (i = 0; (size_t)i < re->shnum; i++) { in dump_symtabs()
3352 s = &re->sl[i]; in dump_symtabs()
3353 if (s->type == SHT_SYMTAB || s->type == SHT_DYNSYM) { in dump_symtabs()
3354 if (re->options & RE_DD) { in dump_symtabs()
3355 if (dyn_off == s->addr) { in dump_symtabs()
3377 if ((d = elf_getdata(s->scn, NULL)) == NULL) { in dump_svr4_hash()
3383 if (d->d_size < 2 * sizeof(uint32_t)) { in dump_svr4_hash()
3387 buf = d->d_buf; in dump_svr4_hash()
3394 if (d->d_size != (nbucket + nchain + 2) * sizeof(uint32_t)) { in dump_svr4_hash()
3418 printf("%7u\t%-10u\t(%5.1f%%)\t%5.1f%%\n", i, c[i], in dump_svr4_hash()
3419 c[i] * 100.0 / nbucket, total * 100.0 / (nchain - 1)); in dump_svr4_hash()
3436 * ALPHA uses 64-bit hash entries. Since libelf assumes that in dump_svr4_hash64()
3437 * .hash section contains only 32-bit entry, an explicit in dump_svr4_hash64()
3441 if ((d = elf_rawdata(s->scn, NULL)) == NULL) { in dump_svr4_hash64()
3448 d->d_type = ELF_T_XWORD; in dump_svr4_hash64()
3450 if (gelf_xlatetom(re->elf, &dst, d, in dump_svr4_hash64()
3451 re->ehdr.e_ident[EI_DATA]) != &dst) { in dump_svr4_hash64()
3452 warnx("gelf_xlatetom failed: %s", elf_errmsg(-1)); in dump_svr4_hash64()
3466 if (d->d_size != (nbucket + nchain + 2) * sizeof(uint32_t)) { in dump_svr4_hash64()
3490 printf("%7u\t%-10ju\t(%5.1f%%)\t%5.1f%%\n", i, (uintmax_t)c[i], in dump_svr4_hash64()
3491 c[i] * 100.0 / nbucket, total * 100.0 / (nchain - 1)); in dump_svr4_hash64()
3509 if ((d = elf_getdata(s->scn, NULL)) == NULL) { in dump_gnu_hash()
3516 if (d->d_size < 4 * sizeof(uint32_t)) { in dump_gnu_hash()
3520 buf = d->d_buf; in dump_gnu_hash()
3525 if (s->link >= re->shnum) in dump_gnu_hash()
3527 ds = &re->sl[s->link]; in dump_gnu_hash()
3534 nchain = dynsymcount - symndx; in dump_gnu_hash()
3535 if (d->d_size != 4 * sizeof(uint32_t) + maskwords * in dump_gnu_hash()
3536 (re->ec == ELFCLASS32 ? sizeof(uint32_t) : sizeof(uint64_t)) + in dump_gnu_hash()
3541 bucket = buf + (re->ec == ELFCLASS32 ? maskwords : maskwords * 2); in dump_gnu_hash()
3548 for (j = bucket[i]; j > 0 && (uint32_t)j - symndx < nchain; in dump_gnu_hash()
3552 if (chain[j - symndx] & 1) in dump_gnu_hash()
3565 printf("%7u\t%-10u\t(%5.1f%%)\t%5.1f%%\n", i, c[i], in dump_gnu_hash()
3566 c[i] * 100.0 / nbucket, total * 100.0 / (nchain - 1)); in dump_gnu_hash()
3627 sz -= 8; in dump_gnu_property_type_0()
3638 re->ehdr.e_machine) { in dump_gnu_property_type_0()
3646 re->ehdr.e_machine); in dump_gnu_property_type_0()
3667 sz -= roundup2(prop_sz, 8); in dump_gnu_property_type_0()
3685 for (i = 0; (size_t) i < re->shnum; i++) { in dump_hash()
3686 s = &re->sl[i]; in dump_hash()
3687 if (s->type == SHT_HASH || s->type == SHT_GNU_HASH) { in dump_hash()
3688 if (s->type == SHT_GNU_HASH) in dump_hash()
3690 else if (re->ehdr.e_machine == EM_ALPHA && in dump_hash()
3691 s->entsize == 8) in dump_hash()
3709 if (re->ehdr.e_type == ET_CORE) { in dump_notes()
3714 if (elf_getphnum(re->elf, &phnum) == 0) { in dump_notes()
3715 warnx("elf_getphnum failed: %s", elf_errmsg(-1)); in dump_notes()
3720 if ((rawfile = elf_rawfile(re->elf, &filesize)) == NULL) { in dump_notes()
3721 warnx("elf_rawfile failed: %s", elf_errmsg(-1)); in dump_notes()
3725 if (gelf_getphdr(re->elf, i, &phdr) != &phdr) { in dump_notes()
3727 elf_errmsg(-1)); in dump_notes()
3732 phdr.p_filesz > filesize - phdr.p_offset) { in dump_notes()
3746 for (i = 0; (size_t) i < re->shnum; i++) { in dump_notes()
3747 s = &re->sl[i]; in dump_notes()
3748 if (s->type == SHT_NOTE) { in dump_notes()
3750 if ((d = elf_getdata(s->scn, NULL)) == NULL) { in dump_notes()
3757 dump_notes_content(re, d->d_buf, d->d_size, in dump_notes()
3758 s->off); in dump_notes()
3778 if (len == 0 || s[--len] != '\0') { in dump_note_string()
3815 /* Note data is at least 4-byte aligned. */ in dump_notes_data()
3863 for (nd = xen_notes; nd->description != NULL; nd++) { in dump_notes_data()
3864 if (nd->type == type) { in dump_notes_data()
3865 if (nd->fp(nd->description, buf, sz)) in dump_notes_data()
3888 printf(" %-13s %-15s %s\n", "Owner", "Data size", "Description"); in dump_notes_content()
3896 namesz = roundup2(note->n_namesz, 4); in dump_notes_content()
3897 descsz = roundup2(note->n_descsz, 4); in dump_notes_content()
3898 if (namesz < note->n_namesz || descsz < note->n_descsz || in dump_notes_content()
3907 * The name field is required to be nul-terminated, and in dump_notes_content()
3909 * implementations (contrary to the ELF-64 spec). A special in dump_notes_content()
3914 if (note->n_namesz == 0) in dump_notes_content()
3916 else if (note->n_namesz == 4 && strncmp(name, "CORE", 4) == 0) in dump_notes_content()
3918 else if (strnlen(name, note->n_namesz) >= note->n_namesz) in dump_notes_content()
3920 printf(" %-13s %#010jx", name, (uintmax_t) note->n_descsz); in dump_notes_content()
3921 printf(" %s\n", note_type(name, re->ehdr.e_type, in dump_notes_content()
3922 note->n_type)); in dump_notes_content()
3923 dump_notes_data(re, name, note->n_type, buf, note->n_descsz); in dump_notes_content()
3939 while (x >= re->ver_sz) { \
3940 nv = realloc(re->ver, \
3941 sizeof(*re->ver) * re->ver_sz * 2); \
3944 free(re->ver); \
3947 re->ver = nv; \
3948 for (i = re->ver_sz; i < re->ver_sz * 2; i++) { \
3949 re->ver[i].name = NULL; \
3950 re->ver[i].type = 0; \
3952 re->ver_sz *= 2; \
3955 re->ver[x].name = n; \
3956 re->ver[x].type = t; \
3973 if ((s = re->vd_s) == NULL) in dump_verdef()
3975 if (s->link >= re->shnum) in dump_verdef()
3978 if (re->ver == NULL) { in dump_verdef()
3979 re->ver_sz = 16; in dump_verdef()
3980 if ((re->ver = calloc(re->ver_sz, sizeof(*re->ver))) == in dump_verdef()
3985 re->ver[0].name = "*local*"; in dump_verdef()
3986 re->ver[1].name = "*global*"; in dump_verdef()
3990 printf("\nVersion definition section (%s):\n", s->name); in dump_verdef()
3992 if ((d = elf_getdata(s->scn, NULL)) == NULL) { in dump_verdef()
3998 if (d->d_size == 0) in dump_verdef()
4001 buf = d->d_buf; in dump_verdef()
4002 end = buf + d->d_size; in dump_verdef()
4007 (buf - (uint8_t *)d->d_buf)); in dump_verdef()
4009 " vd_ndx: %u vd_cnt: %u", vd->vd_version, in dump_verdef()
4010 vd->vd_flags, vd->vd_ndx, vd->vd_cnt); in dump_verdef()
4012 buf2 = buf + vd->vd_aux; in dump_verdef()
4014 while (buf2 + sizeof(Elf_Verdaux) <= end && j < vd->vd_cnt) { in dump_verdef()
4016 name = get_string(re, s->link, vda->vda_name); in dump_verdef()
4020 SAVE_VERSION_NAME((int)vd->vd_ndx, name, 1); in dump_verdef()
4023 (unsigned long) (buf2 - in dump_verdef()
4024 (uint8_t *)d->d_buf), name); in dump_verdef()
4025 if (vda->vda_next == 0) in dump_verdef()
4027 buf2 += vda->vda_next; in dump_verdef()
4030 if (vd->vd_next == 0) in dump_verdef()
4032 buf += vd->vd_next; in dump_verdef()
4048 if ((s = re->vn_s) == NULL) in dump_verneed()
4050 if (s->link >= re->shnum) in dump_verneed()
4053 if (re->ver == NULL) { in dump_verneed()
4054 re->ver_sz = 16; in dump_verneed()
4055 if ((re->ver = calloc(re->ver_sz, sizeof(*re->ver))) == in dump_verneed()
4060 re->ver[0].name = "*local*"; in dump_verneed()
4061 re->ver[1].name = "*global*"; in dump_verneed()
4065 printf("\nVersion needed section (%s):\n", s->name); in dump_verneed()
4067 if ((d = elf_getdata(s->scn, NULL)) == NULL) { in dump_verneed()
4073 if (d->d_size == 0) in dump_verneed()
4076 buf = d->d_buf; in dump_verneed()
4077 end = buf + d->d_size; in dump_verneed()
4082 (buf - (uint8_t *)d->d_buf)); in dump_verneed()
4084 vn->vn_version, in dump_verneed()
4085 get_string(re, s->link, vn->vn_file), in dump_verneed()
4086 vn->vn_cnt); in dump_verneed()
4088 buf2 = buf + vn->vn_aux; in dump_verneed()
4090 while (buf2 + sizeof(Elf_Vernaux) <= end && j < vn->vn_cnt) { in dump_verneed()
4094 (buf2 - (uint8_t *)d->d_buf)); in dump_verneed()
4095 name = get_string(re, s->link, vna->vna_name); in dump_verneed()
4099 vna->vna_flags, vna->vna_other); in dump_verneed()
4100 SAVE_VERSION_NAME((int)vna->vna_other, name, 0); in dump_verneed()
4101 if (vna->vna_next == 0) in dump_verneed()
4103 buf2 += vna->vna_next; in dump_verneed()
4106 if (vn->vn_next == 0) in dump_verneed()
4108 buf += vn->vn_next; in dump_verneed()
4118 if (re->vs_s == NULL || re->ver == NULL || re->vs == NULL) in dump_versym()
4120 printf("\nVersion symbol section (%s):\n", re->vs_s->name); in dump_versym()
4121 for (i = 0; i < re->vs_sz; i++) { in dump_versym()
4127 vs = re->vs[i] & VERSYM_VERSION; in dump_versym()
4128 if (vs >= re->ver_sz || re->ver[vs].name == NULL) { in dump_versym()
4129 warnx("invalid versym version index %u", re->vs[i]); in dump_versym()
4132 if (re->vs[i] & VERSYM_HIDDEN) in dump_versym()
4133 printf(" %3xh %-12s ", vs, in dump_versym()
4134 re->ver[re->vs[i] & VERSYM_VERSION].name); in dump_versym()
4136 printf(" %3x %-12s ", vs, re->ver[re->vs[i]].name); in dump_versym()
4145 if (re->vs_s && re->ver && re->vs) in dump_ver()
4147 if (re->vd_s) in dump_ver()
4149 if (re->vn_s) in dump_ver()
4160 for (i = 0; (size_t) i < re->shnum; i++) { in search_ver()
4161 s = &re->sl[i]; in search_ver()
4162 if (s->type == SHT_SUNW_versym) in search_ver()
4163 re->vs_s = s; in search_ver()
4164 if (s->type == SHT_SUNW_verneed) in search_ver()
4165 re->vn_s = s; in search_ver()
4166 if (s->type == SHT_SUNW_verdef) in search_ver()
4167 re->vd_s = s; in search_ver()
4169 if (re->vd_s) in search_ver()
4171 if (re->vn_s) in search_ver()
4173 if (re->vs_s && re->ver != NULL) { in search_ver()
4175 if ((d = elf_getdata(re->vs_s->scn, NULL)) == NULL) { in search_ver()
4182 if (d->d_size == 0) in search_ver()
4184 re->vs = d->d_buf; in search_ver()
4185 re->vs_sz = d->d_size / sizeof(Elf32_Half); in search_ver()
4211 for (i = 0; (size_t) i < re->shnum; i++) { in dump_liblist()
4212 s = &re->sl[i]; in dump_liblist()
4213 if (s->type != SHT_GNU_LIBLIST) in dump_liblist()
4215 if (s->link >= re->shnum) in dump_liblist()
4218 if ((d = elf_getdata(s->scn, NULL)) == NULL) { in dump_liblist()
4225 if (d->d_size <= 0) in dump_liblist()
4227 lib = d->d_buf; in dump_liblist()
4230 printf("\nLibrary list section '%s' ", s->name); in dump_liblist()
4234 for (j = 0; (uint64_t) j < s->sz / s->entsize; j++) { in dump_liblist()
4236 printf("%-20.20s ", in dump_liblist()
4237 get_string(re, s->link, lib->l_name)); in dump_liblist()
4238 ti = lib->l_time_stamp; in dump_liblist()
4240 snprintf(tbuf, sizeof(tbuf), "%04d-%02d-%02dT%02d:%02d" in dump_liblist()
4241 ":%2d", t->tm_year + 1900, t->tm_mon + 1, in dump_liblist()
4242 t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec); in dump_liblist()
4243 printf("%-19.19s ", tbuf); in dump_liblist()
4244 printf("0x%08x ", lib->l_checksum); in dump_liblist()
4245 printf("%-7d %#x", lib->l_version, lib->l_flags); in dump_liblist()
4246 if (lib->l_flags != 0) { in dump_liblist()
4250 if ((l_flag[k].value & lib->l_flags) == in dump_liblist()
4279 for (i = 0; (size_t) i < re->shnum; i++) { in dump_section_groups()
4280 s = &re->sl[i]; in dump_section_groups()
4281 if (s->type != SHT_GROUP) in dump_section_groups()
4283 if (s->link >= re->shnum) in dump_section_groups()
4286 if ((d = elf_getdata(s->scn, NULL)) == NULL) { in dump_section_groups()
4293 if (d->d_size <= 0) in dump_section_groups()
4296 w = d->d_buf; in dump_section_groups()
4305 if (s->entsize == 0) in dump_section_groups()
4306 s->entsize = 4; in dump_section_groups()
4308 symname = get_symbol_name(re, s->link, s->info); in dump_section_groups()
4309 n = s->sz / s->entsize; in dump_section_groups()
4310 if (n-- < 1) in dump_section_groups()
4314 " sections:\n", i, s->name, symname, (uintmax_t)n); in dump_section_groups()
4315 printf(" %-10.10s %s\n", "[Index]", "Name"); in dump_section_groups()
4317 if (*w >= re->shnum) { in dump_section_groups()
4321 printf(" [%5u] %s\n", *w, re->sl[*w].name); in dump_section_groups()
4333 * a ULEB128 param and odd numbered ones have NUL-terminated in dump_unknown_tag()
4505 for (i = 0; (size_t) i < re->shnum; i++) { in dump_attributes()
4506 s = &re->sl[i]; in dump_attributes()
4507 if (s->type != SHT_GNU_ATTRIBUTES && in dump_attributes()
4508 (re->ehdr.e_machine != EM_ARM || s->type != SHT_LOPROC + 3)) in dump_attributes()
4511 if ((d = elf_rawdata(s->scn, NULL)) == NULL) { in dump_attributes()
4518 if (d->d_size <= 0) in dump_attributes()
4520 p = d->d_buf; in dump_attributes()
4521 pe = p + d->d_size; in dump_attributes()
4527 len = d->d_size - 1; in dump_attributes()
4534 seclen = re->dw_decode(&p, 4); in dump_attributes()
4539 len -= seclen; in dump_attributes()
4547 seclen -= nlen + 4; in dump_attributes()
4551 sublen = re->dw_decode(&p, 4); in dump_attributes()
4553 warnx("invalid attribute sub-section" in dump_attributes()
4557 seclen -= sublen; in dump_attributes()
4569 if (re->ehdr.e_machine == EM_ARM && in dump_attributes()
4570 s->type == SHT_LOPROC + 3) in dump_attributes()
4572 else if (re->ehdr.e_machine == EM_MIPS || in dump_attributes()
4573 re->ehdr.e_machine == EM_MIPS_RS3_LE) in dump_attributes()
4576 else if (re->ehdr.e_machine == EM_PPC) in dump_attributes()
4591 for (i = 0; (size_t) i < re->shnum; i++) { in dump_mips_specific_info()
4592 s = &re->sl[i]; in dump_mips_specific_info()
4593 if (s->name != NULL && (!strcmp(s->name, ".MIPS.options") || in dump_mips_specific_info()
4594 (s->type == SHT_MIPS_OPTIONS))) { in dump_mips_specific_info()
4599 if (s->name != NULL && (!strcmp(s->name, ".MIPS.abiflags") || in dump_mips_specific_info()
4600 (s->type == SHT_MIPS_ABIFLAGS))) in dump_mips_specific_info()
4607 for (i = 0; (size_t) i < re->shnum; i++) { in dump_mips_specific_info()
4608 s = &re->sl[i]; in dump_mips_specific_info()
4609 if (s->name != NULL && (!strcmp(s->name, ".reginfo") || in dump_mips_specific_info()
4610 (s->type == SHT_MIPS_REGINFO))) in dump_mips_specific_info()
4625 if ((d = elf_rawdata(s->scn, NULL)) == NULL) { in dump_mips_abiflags()
4632 if (d->d_size != 24) { in dump_mips_abiflags()
4637 p = d->d_buf; in dump_mips_abiflags()
4638 version = re->dw_decode(&p, 2); in dump_mips_abiflags()
4646 isa_level = re->dw_decode(&p, 1); in dump_mips_abiflags()
4647 isa_rev = re->dw_decode(&p, 1); in dump_mips_abiflags()
4648 gpr_size = re->dw_decode(&p, 1); in dump_mips_abiflags()
4649 cpr1_size = re->dw_decode(&p, 1); in dump_mips_abiflags()
4650 cpr2_size = re->dw_decode(&p, 1); in dump_mips_abiflags()
4651 fp_abi = re->dw_decode(&p, 1); in dump_mips_abiflags()
4652 isa_ext = re->dw_decode(&p, 4); in dump_mips_abiflags()
4653 ases = re->dw_decode(&p, 4); in dump_mips_abiflags()
4654 flags1 = re->dw_decode(&p, 4); in dump_mips_abiflags()
4655 flags2 = re->dw_decode(&p, 4); in dump_mips_abiflags()
4688 default: return -1; in get_mips_register_size()
4698 if ((d = elf_rawdata(s->scn, NULL)) == NULL) { in dump_mips_reginfo()
4705 if (d->d_size <= 0) in dump_mips_reginfo()
4710 printf("\nSection '%s' contains %d entries:\n", s->name, len); in dump_mips_reginfo()
4711 dump_mips_odk_reginfo(re, d->d_buf, d->d_size); in dump_mips_reginfo()
4725 if ((d = elf_rawdata(s->scn, NULL)) == NULL) { in dump_mips_options()
4732 if (d->d_size == 0) in dump_mips_options()
4735 printf("\nSection %s contains:\n", s->name); in dump_mips_options()
4736 p = d->d_buf; in dump_mips_options()
4737 pe = p + d->d_size; in dump_mips_options()
4739 if (pe - p < 8) { in dump_mips_options()
4743 kind = re->dw_decode(&p, 1); in dump_mips_options()
4744 size = re->dw_decode(&p, 1); in dump_mips_options()
4745 sndx = re->dw_decode(&p, 2); in dump_mips_options()
4746 info = re->dw_decode(&p, 4); in dump_mips_options()
4747 if (size < 8 || size - 8 > pe - p) { in dump_mips_options()
4751 size -= 8; in dump_mips_options()
4765 printf(" %-10.10s section: %ju\n", "OPAD", in dump_mips_options()
4780 printf(" %-10.10s %#jx\n", "FILL", (uintmax_t) info); in dump_mips_options()
4783 printf(" %-10.10s\n", "TAGS"); in dump_mips_options()
4786 printf(" %-10.10s GP group number: %#x\n", "GP_GROUP", in dump_mips_options()
4789 printf(" %-10.10s GP group is " in dump_mips_options()
4790 "self-contained\n", ""); in dump_mips_options()
4793 printf(" %-10.10s default GP group number: %#x\n", in dump_mips_options()
4796 printf(" %-10.10s default GP group is " in dump_mips_options()
4797 "self-contained\n", ""); in dump_mips_options()
4800 printf(" %-10.10s\n", "PAGESIZE"); in dump_mips_options()
4815 for (; opt->desc != NULL; opt++) { in dump_mips_option_flags()
4816 if (info & opt->flag) { in dump_mips_option_flags()
4817 printf(" %-10.10s %s\n", first ? name : "", in dump_mips_option_flags()
4818 opt->desc); in dump_mips_option_flags()
4835 ri_gprmask = re->dw_decode(&p, 4); in dump_mips_odk_reginfo()
4837 if (re->ec == ELFCLASS64) in dump_mips_odk_reginfo()
4838 re->dw_decode(&p, 4); in dump_mips_odk_reginfo()
4840 ri_cprmask[i] = re->dw_decode(&p, 4); in dump_mips_odk_reginfo()
4841 if (re->ec == ELFCLASS32) in dump_mips_odk_reginfo()
4842 ri_gp_value = re->dw_decode(&p, 4); in dump_mips_odk_reginfo()
4844 ri_gp_value = re->dw_decode(&p, 8); in dump_mips_odk_reginfo()
4862 switch (re->ehdr.e_machine) { in dump_arch_specific_info()
4877 if ((rn = dwarf_reg(re->ehdr.e_machine, num)) != NULL) in dwarf_regname()
4905 for (i = 0; (size_t) i < re->shnum; i++) { in dump_dwarf_line()
4906 s = &re->sl[i]; in dump_dwarf_line()
4907 if (s->name != NULL && !strcmp(s->name, ".debug_line")) in dump_dwarf_line()
4910 if ((size_t) i >= re->shnum) in dump_dwarf_line()
4914 if ((d = elf_getdata(s->scn, NULL)) == NULL) { in dump_dwarf_line()
4917 warnx("elf_getdata failed: %s", elf_errmsg(-1)); in dump_dwarf_line()
4920 if (d->d_size <= 0) in dump_dwarf_line()
4923 while ((ret = dwarf_next_cu_header(re->dbg, NULL, NULL, NULL, NULL, in dump_dwarf_line()
4926 while (dwarf_siblingof(re->dbg, die, &die, &de) == DW_DLV_OK) { in dump_dwarf_line()
4942 dwarf_dealloc(re->dbg, die, DW_DLA_DIE); in dump_dwarf_line()
4946 length = re->dw_read(d, &offset, 4); in dump_dwarf_line()
4949 length = re->dw_read(d, &offset, 8); in dump_dwarf_line()
4953 if (length > d->d_size - offset) { in dump_dwarf_line()
4955 dwarf_dealloc(re->dbg, die, DW_DLA_DIE); in dump_dwarf_line()
4960 pe = (uint8_t *) d->d_buf + endoff; in dump_dwarf_line()
4961 version = re->dw_read(d, &offset, 2); in dump_dwarf_line()
4962 hdrlen = re->dw_read(d, &offset, dwarf_size); in dump_dwarf_line()
4963 minlen = re->dw_read(d, &offset, 1); in dump_dwarf_line()
4964 defstmt = re->dw_read(d, &offset, 1); in dump_dwarf_line()
4965 lbase = re->dw_read(d, &offset, 1); in dump_dwarf_line()
4966 lrange = re->dw_read(d, &offset, 1); in dump_dwarf_line()
4967 opbase = re->dw_read(d, &offset, 1); in dump_dwarf_line()
4978 (void) dwarf_get_address_size(re->dbg, &pointer_size, &de); in dump_dwarf_line()
4984 oplen = re->dw_read(d, &offset, 1); in dump_dwarf_line()
4990 p = (uint8_t *) d->d_buf + offset; in dump_dwarf_line()
5022 #define LINE(x) (lbase + (((x) - opbase) % lrange)) in dump_dwarf_line()
5023 #define ADDRESS(x) ((((x) - opbase) / lrange) * minlen) in dump_dwarf_line()
5048 address = re->dw_decode(&p, in dump_dwarf_line()
5115 udelta = re->dw_decode(&p, 2); in dump_dwarf_line()
5136 *(p - 1)); in dump_dwarf_line()
5148 *p - opbase, (uintmax_t) ADDRESS(*p), in dump_dwarf_line()
5154 dwarf_dealloc(re->dbg, die, DW_DLA_DIE); in dump_dwarf_line()
5178 while ((ret = dwarf_next_cu_header(re->dbg, NULL, NULL, NULL, NULL, in dump_dwarf_line_decoded()
5180 if (dwarf_siblingof(re->dbg, NULL, &die, &de) != DW_DLV_OK) in dump_dwarf_line_decoded()
5194 printf("%-37s %11s %s\n", "Filename", "Line Number", in dump_dwarf_line_decoded()
5208 printf("%-37s %11ju %#18jx\n", in dump_dwarf_line_decoded()
5209 basename(srcfiles[fn - 1]), (uintmax_t) lineno, in dump_dwarf_line_decoded()
5214 dwarf_dealloc(re->dbg, die, DW_DLA_DIE); in dump_dwarf_line_decoded()
5291 printf(" <%jx> %-18s: ", (uintmax_t) attroff, attr_str); in dump_dwarf_die()
5397 printf("%ju byte block:", (uintmax_t) v_block->bl_len); in dump_dwarf_die()
5398 b = v_block->bl_data; in dump_dwarf_die()
5399 for (j = 0; (Dwarf_Unsigned) j < v_block->bl_len; j++) in dump_dwarf_die()
5402 dump_dwarf_block(re, v_block->bl_data, v_block->bl_len); in dump_dwarf_die()
5430 v_sig = re->dw_decode(&p, 8); in dump_dwarf_die()
5488 ret = dwarf_siblingof_b(re->dbg, die, &ret_die, is_info, &de); in dump_dwarf_die()
5494 dwarf_dealloc(re->dbg, die, DW_DLA_DIE); in dump_dwarf_die()
5502 re->cu_psize = psize; in set_cu_context()
5503 re->cu_osize = osize; in set_cu_context()
5504 re->cu_ver = ver; in set_cu_context()
5526 for (i = 0; (size_t) i < re->shnum; i++) { in dump_dwarf_info()
5527 s = &re->sl[i]; in dump_dwarf_info()
5528 if (s->name != NULL && !strcmp(s->name, sn)) in dump_dwarf_info()
5531 if ((size_t) i >= re->shnum) in dump_dwarf_info()
5537 while ((ret = dwarf_next_cu_header_c(re->dbg, is_info, NULL, in dump_dwarf_info()
5542 while (dwarf_siblingof_b(re->dbg, die, &die, is_info, in dump_dwarf_info()
5570 cu_length -= off_size == 4 ? 4 : 12; in dump_dwarf_info()
5575 sig = re->dw_decode(&p, 8); in dump_dwarf_info()
5580 printf(" Length:\t\t%#jx (%d-bit)\n", in dump_dwarf_info()
5599 } while (dwarf_next_types_section(re->dbg, &de) == DW_DLV_OK); in dump_dwarf_info()
5617 while ((ret = dwarf_next_cu_header(re->dbg, NULL, NULL, &aboff, in dump_dwarf_abbrev()
5621 while ((ret = dwarf_get_abbrev(re->dbg, aboff, &ab, &length, in dump_dwarf_abbrev()
5624 dwarf_dealloc(re->dbg, ab, DW_DLA_ABBREV); in dump_dwarf_abbrev()
5667 printf(" %-18s %s\n", attr_str, form_str); in dump_dwarf_abbrev()
5670 dwarf_dealloc(re->dbg, ab, DW_DLA_ABBREV); in dump_dwarf_abbrev()
5696 for (i = 0; (size_t) i < re->shnum; i++) { in dump_dwarf_pubnames()
5697 s = &re->sl[i]; in dump_dwarf_pubnames()
5698 if (s->name != NULL && !strcmp(s->name, ".debug_pubnames")) in dump_dwarf_pubnames()
5701 if ((size_t) i >= re->shnum) in dump_dwarf_pubnames()
5705 if ((d = elf_getdata(s->scn, NULL)) == NULL) { in dump_dwarf_pubnames()
5708 warnx("elf_getdata failed: %s", elf_errmsg(-1)); in dump_dwarf_pubnames()
5711 if (d->d_size <= 0) in dump_dwarf_pubnames()
5716 length = re->dw_read(d, &offset, 4); in dump_dwarf_pubnames()
5719 length = re->dw_read(d, &offset, 8); in dump_dwarf_pubnames()
5723 if (length > d->d_size - offset) { in dump_dwarf_pubnames()
5728 nt_version = re->dw_read(d, &offset, 2); in dump_dwarf_pubnames()
5729 nt_cu_offset = re->dw_read(d, &offset, dwarf_size); in dump_dwarf_pubnames()
5730 nt_cu_length = re->dw_read(d, &offset, dwarf_size); in dump_dwarf_pubnames()
5738 if (dwarf_get_globals(re->dbg, &globs, &cnt, &de) != DW_DLV_OK) { in dump_dwarf_pubnames()
5755 printf(" %-11ju %s\n", (uintmax_t) die_off, glob_name); in dump_dwarf_pubnames()
5776 for (i = 0; (size_t) i < re->shnum; i++) { in dump_dwarf_aranges()
5777 s = &re->sl[i]; in dump_dwarf_aranges()
5778 if (s->name != NULL && !strcmp(s->name, ".debug_aranges")) in dump_dwarf_aranges()
5781 if ((size_t) i >= re->shnum) in dump_dwarf_aranges()
5785 if ((d = elf_getdata(s->scn, NULL)) == NULL) { in dump_dwarf_aranges()
5788 warnx("elf_getdata failed: %s", elf_errmsg(-1)); in dump_dwarf_aranges()
5791 if (d->d_size <= 0) in dump_dwarf_aranges()
5796 length = re->dw_read(d, &offset, 4); in dump_dwarf_aranges()
5799 length = re->dw_read(d, &offset, 8); in dump_dwarf_aranges()
5803 if (length > d->d_size - offset) { in dump_dwarf_aranges()
5808 as_version = re->dw_read(d, &offset, 2); in dump_dwarf_aranges()
5809 as_cu_offset = re->dw_read(d, &offset, dwarf_size); in dump_dwarf_aranges()
5810 as_addrsz = re->dw_read(d, &offset, 1); in dump_dwarf_aranges()
5811 as_segsz = re->dw_read(d, &offset, 1); in dump_dwarf_aranges()
5819 if (dwarf_get_aranges(re->dbg, &aranges, &cnt, &de) != DW_DLV_OK) { in dump_dwarf_aranges()
5870 if (dwarf_get_ranges(re->dbg, off, &ranges, &cnt, in dump_dwarf_ranges_foreach()
5884 if (re->ec == ELFCLASS32) in dump_dwarf_ranges_foreach()
5904 ret = dwarf_siblingof(re->dbg, die, &ret_die, &de); in dump_dwarf_ranges_foreach()
5910 dwarf_dealloc(re->dbg, die, DW_DLA_DIE); in dump_dwarf_ranges_foreach()
5925 if (dwarf_get_ranges(re->dbg, 0, &ranges, &cnt, &bytecnt, &de) != in dump_dwarf_ranges()
5930 if (re->ec == ELFCLASS32) in dump_dwarf_ranges()
5931 printf(" %-8s %-8s %s\n", "Offset", "Begin", "End"); in dump_dwarf_ranges()
5933 printf(" %-8s %-16s %s\n", "Offset", "Begin", "End"); in dump_dwarf_ranges()
5935 while ((ret = dwarf_next_cu_header(re->dbg, NULL, NULL, NULL, NULL, in dump_dwarf_ranges()
5938 if (dwarf_siblingof(re->dbg, die, &die, &de) != DW_DLV_OK) in dump_dwarf_ranges()
5973 while (dwarf_get_macro_details(re->dbg, offset, _MAX_MACINFO_ENTRY, in dump_dwarf_macinfo()
5989 printf(" - lineno : %jd macro : %s\n", in dump_dwarf_macinfo()
5994 printf(" - lineno : %jd filenum : %jd\n", in dump_dwarf_macinfo()
6142 return (-1); in dump_dwarf_frame_regtable()
6159 printf("%-5s", in dump_dwarf_frame_regtable()
6174 return (-1); in dump_dwarf_frame_regtable()
6180 printf("%-8s ", get_regoff_str(re, RT(0).dw_regnum, in dump_dwarf_frame_regtable()
6184 printf("%-5s", get_regoff_str(re, in dump_dwarf_frame_regtable()
6218 printf("\nThe section %s contains:\n\n", s->name); in dump_dwarf_frame_section()
6220 if (!strcmp(s->name, ".debug_frame")) { in dump_dwarf_frame_section()
6222 if (dwarf_get_fde_list(re->dbg, &cie_list, &cie_count, in dump_dwarf_frame_section()
6228 } else if (!strcmp(s->name, ".eh_frame")) { in dump_dwarf_frame_section()
6230 ret = dwarf_get_fde_list_eh(re->dbg, &cie_list, &cie_count, in dump_dwarf_frame_section()
6294 re->dbg); in dump_dwarf_frame_section()
6313 (uintmax_t) (eh_frame ? fde_offset + 4 - cie_offset : in dump_dwarf_frame_section()
6318 cie_caf, cie_daf, low_pc, re->dbg); in dump_dwarf_frame_section()
6332 (void) dwarf_set_frame_cfa_value(re->dbg, DW_FRAME_CFA_COL); in dump_dwarf_frame()
6334 for (i = 0; (size_t) i < re->shnum; i++) { in dump_dwarf_frame()
6335 s = &re->sl[i]; in dump_dwarf_frame()
6336 if (s->name != NULL && (!strcmp(s->name, ".debug_frame") || in dump_dwarf_frame()
6337 !strcmp(s->name, ".eh_frame"))) in dump_dwarf_frame()
6353 for (i = 0; (size_t) i < re->shnum; i++) { in dump_dwarf_str()
6354 s = &re->sl[i]; in dump_dwarf_str()
6355 if (s->name != NULL && !strcmp(s->name, ".debug_str")) in dump_dwarf_str()
6358 if ((size_t) i >= re->shnum) in dump_dwarf_str()
6362 if ((d = elf_getdata(s->scn, NULL)) == NULL) { in dump_dwarf_str()
6365 warnx("elf_getdata failed: %s", elf_errmsg(-1)); in dump_dwarf_str()
6368 if (d->d_size <= 0) in dump_dwarf_str()
6371 for (i = 0, p = d->d_buf; (size_t) i < d->d_size; i += 16) { in dump_dwarf_str()
6373 if ((size_t) i + 16 > d->d_size) in dump_dwarf_str()
6374 end = d->d_size; in dump_dwarf_str()
6378 if ((j - i) % 4 == 0) in dump_dwarf_str()
6407 if (left->la_off > right->la_off) in loc_at_comparator()
6409 else if (left->la_off < right->la_off) in loc_at_comparator()
6410 return (-1); in loc_at_comparator()
6483 la->la_at = attr_list[i]; in search_loclist_at()
6484 la->la_off = off; in search_loclist_at()
6485 la->la_lowpc = lowpc; in search_loclist_at()
6486 la->la_cu_psize = re->cu_psize; in search_loclist_at()
6487 la->la_cu_osize = re->cu_osize; in search_loclist_at()
6488 la->la_cu_ver = re->cu_ver; in search_loclist_at()
6502 ret = dwarf_siblingof_b(re->dbg, die, &ret_die, is_info, &de); in search_loclist_at()
6518 if (dwarf_get_OP_name(lr->lr_atom, &op_str) != in dump_dwarf_loc()
6521 "[Unknown OP: %#x]", lr->lr_atom); in dump_dwarf_loc()
6527 switch (lr->lr_atom) { in dump_dwarf_loc()
6560 printf(" (%s)", dwarf_regname(re, lr->lr_atom - DW_OP_reg0)); in dump_dwarf_loc()
6645 lr->lr_number); in dump_dwarf_loc()
6654 lr->lr_number); in dump_dwarf_loc()
6690 dwarf_regname(re, lr->lr_atom - DW_OP_breg0), in dump_dwarf_loc()
6691 (intmax_t) lr->lr_number); in dump_dwarf_loc()
6696 lr->lr_number); in dump_dwarf_loc()
6701 (uintmax_t) lr->lr_number, in dump_dwarf_loc()
6702 dwarf_regname(re, (unsigned int) lr->lr_number), in dump_dwarf_loc()
6703 (intmax_t) lr->lr_number2); in dump_dwarf_loc()
6709 lr->lr_number); in dump_dwarf_loc()
6713 printf(": <0x%jx> %jd", (uintmax_t) lr->lr_number, in dump_dwarf_loc()
6714 (intmax_t) lr->lr_number2); in dump_dwarf_loc()
6718 printf(": %ju byte block:", (uintmax_t) lr->lr_number); in dump_dwarf_loc()
6719 b = (uint8_t *)(uintptr_t) lr->lr_number2; in dump_dwarf_loc()
6720 for (i = 0; (Dwarf_Unsigned) i < lr->lr_number; i++) in dump_dwarf_loc()
6726 dump_dwarf_block(re, (uint8_t *)(uintptr_t) lr->lr_number2, in dump_dwarf_loc()
6727 lr->lr_number); in dump_dwarf_loc()
6732 printf(": <0x%jx> ", (uintmax_t) lr->lr_number); in dump_dwarf_loc()
6733 b = (uint8_t *)(uintptr_t) lr->lr_number2; in dump_dwarf_loc()
6740 printf(": %ju (%s) <0x%jx>", (uintmax_t) lr->lr_number, in dump_dwarf_loc()
6741 dwarf_regname(re, (unsigned int) lr->lr_number), in dump_dwarf_loc()
6742 (uintmax_t) lr->lr_number2); in dump_dwarf_loc()
6749 printf(": <0x%jx>", (uintmax_t) lr->lr_number); in dump_dwarf_loc()
6765 if (dwarf_loclist_from_expr_b(re->dbg, b, len, re->cu_psize, in dump_dwarf_block()
6766 re->cu_osize, re->cu_ver, &llbuf, &lcnt, &de) != DW_DLV_OK) { in dump_dwarf_block()
6771 for (i = 0; (Dwarf_Half) i < llbuf->ld_cents; i++) { in dump_dwarf_block()
6772 dump_dwarf_loc(re, &llbuf->ld_s[i]); in dump_dwarf_block()
6773 if (i < llbuf->ld_cents - 1) in dump_dwarf_block()
6777 dwarf_dealloc(re->dbg, llbuf->ld_s, DW_DLA_LOC_BLOCK); in dump_dwarf_block()
6778 dwarf_dealloc(re->dbg, llbuf, DW_DLA_LOCDESC); in dump_dwarf_block()
6800 while ((ret = dwarf_next_cu_header_b(re->dbg, NULL, &version, NULL, in dump_dwarf_loclist()
6804 if (dwarf_siblingof(re->dbg, die, &die, &de) != DW_DLV_OK) in dump_dwarf_loclist()
6827 while ((ret = dwarf_next_cu_header_c(re->dbg, 0, NULL, in dump_dwarf_loclist()
6832 if (dwarf_siblingof(re->dbg, die, &die, &de) != in dump_dwarf_loclist()
6857 } while (dwarf_next_types_section(re->dbg, &de) == DW_DLV_OK); in dump_dwarf_loclist()
6870 left = &la_list[k - 1 - duplicates]; in dump_dwarf_loclist()
6873 if (left->la_off == right->la_off) in dump_dwarf_loclist()
6876 la_list[k - duplicates] = *right; in dump_dwarf_loclist()
6878 la_list_len -= duplicates; in dump_dwarf_loclist()
6883 if ((ret = dwarf_loclist_n(la->la_at, &llbuf, &lcnt, &de)) != in dump_dwarf_loclist()
6895 set_cu_context(re, la->la_cu_psize, la->la_cu_osize, in dump_dwarf_loclist()
6896 la->la_cu_ver); in dump_dwarf_loclist()
6898 printf(" %8.8jx ", (uintmax_t) la->la_off); in dump_dwarf_loclist()
6899 if (llbuf[i]->ld_lopc == 0 && llbuf[i]->ld_hipc == 0) { in dump_dwarf_loclist()
6907 (uintmax_t) (la->la_lowpc + llbuf[i]->ld_lopc), in dump_dwarf_loclist()
6908 (uintmax_t) (la->la_lowpc + llbuf[i]->ld_hipc)); in dump_dwarf_loclist()
6911 for (j = 0; (Dwarf_Half) j < llbuf[i]->ld_cents; j++) { in dump_dwarf_loclist()
6912 dump_dwarf_loc(re, &llbuf[i]->ld_s[j]); in dump_dwarf_loclist()
6913 if (j < llbuf[i]->ld_cents - 1) in dump_dwarf_loclist()
6918 if (llbuf[i]->ld_lopc == llbuf[i]->ld_hipc) in dump_dwarf_loclist()
6923 dwarf_dealloc(re->dbg, llbuf[i]->ld_s, in dump_dwarf_loclist()
6925 dwarf_dealloc(re->dbg, llbuf[i], DW_DLA_LOCDESC); in dump_dwarf_loclist()
6927 dwarf_dealloc(re->dbg, llbuf, DW_DLA_LIST); in dump_dwarf_loclist()
6944 if ((name = elf_strptr(re->elf, strtab, off)) == NULL) in get_string()
6963 s = &re->sl[symtab]; in get_symbol_name()
6964 if (s->type != SHT_SYMTAB && s->type != SHT_DYNSYM) in get_symbol_name()
6967 if ((data = elf_getdata(s->scn, NULL)) == NULL) { in get_symbol_name()
6977 if (sym.st_shndx < re->shnum && in get_symbol_name()
6978 re->sl[sym.st_shndx].name != NULL) in get_symbol_name()
6979 return (re->sl[sym.st_shndx].name); in get_symbol_name()
6982 if (s->link >= re->shnum || in get_symbol_name()
6983 (name = elf_strptr(re->elf, s->link, sym.st_name)) == NULL) in get_symbol_name()
6997 s = &re->sl[symtab]; in get_symbol_value()
6998 if (s->type != SHT_SYMTAB && s->type != SHT_DYNSYM) in get_symbol_value()
7001 if ((data = elf_getdata(s->scn, NULL)) == NULL) { in get_symbol_value()
7023 if (gelf_getshdr(s->scn, &sh) == NULL) in decompress_section()
7024 errx(EXIT_FAILURE, "gelf_getshdr() failed: %s", elf_errmsg(-1)); in decompress_section()
7034 if (gelf_getchdr(s->scn, &chdr) == NULL) in decompress_section()
7035 errx(EXIT_FAILURE, "gelf_getchdr() failed: %s", elf_errmsg(-1)); in decompress_section()
7045 compressed_size -= sizeof(chdr); in decompress_section()
7066 inflated_size = uncompressed_size - strm.avail_out; in decompress_section()
7101 for (i = 1; (size_t) i < re->shnum; i++) { in hex_dump()
7103 s = &re->sl[i]; in hex_dump()
7104 if (find_dumpop(re, (size_t) i, s->name, HEX_DUMP, -1) == NULL) in hex_dump()
7107 if ((d = elf_getdata(s->scn, NULL)) == NULL && in hex_dump()
7108 (d = elf_rawdata(s->scn, NULL)) == NULL) { in hex_dump()
7116 if (d->d_size <= 0 || d->d_buf == NULL) { in hex_dump()
7118 s->name); in hex_dump()
7121 buf = d->d_buf; in hex_dump()
7122 sz = d->d_size; in hex_dump()
7123 addr = s->addr; in hex_dump()
7124 if (re->options & RE_Z) { in hex_dump()
7125 if (decompress_section(s, d->d_buf, d->d_size, in hex_dump()
7129 printf("\nHex dump of section '%s':\n", s->name); in hex_dump()
7150 sz -= nbytes; in hex_dump()
7166 for (i = 1; (size_t) i < re->shnum; i++) { in str_dump()
7168 s = &re->sl[i]; in str_dump()
7169 if (find_dumpop(re, (size_t) i, s->name, STR_DUMP, -1) == NULL) in str_dump()
7172 if ((d = elf_getdata(s->scn, NULL)) == NULL && in str_dump()
7173 (d = elf_rawdata(s->scn, NULL)) == NULL) { in str_dump()
7181 if (d->d_size <= 0 || d->d_buf == NULL) { in str_dump()
7183 s->name); in str_dump()
7187 start = d->d_buf; in str_dump()
7188 sz = d->d_size; in str_dump()
7189 if (re->options & RE_Z) { in str_dump()
7190 if (decompress_section(s, d->d_buf, d->d_size, in str_dump()
7195 printf("\nString dump of section '%s':\n", s->name); in str_dump()
7205 (long) (start - (unsigned char *) d->d_buf)); in str_dump()
7206 len = end - start; in str_dump()
7233 if (!elf_getshnum(re->elf, &re->shnum)) { in load_sections()
7234 warnx("elf_getshnum failed: %s", elf_errmsg(-1)); in load_sections()
7237 if (re->sl != NULL) in load_sections()
7238 free(re->sl); in load_sections()
7239 if ((re->sl = calloc(re->shnum, sizeof(*re->sl))) == NULL) in load_sections()
7243 if (!elf_getshstrndx(re->elf, &shstrndx)) { in load_sections()
7244 warnx("elf_getshstrndx failed: %s", elf_errmsg(-1)); in load_sections()
7248 if ((scn = elf_getscn(re->elf, 0)) == NULL) in load_sections()
7254 warnx("gelf_getshdr failed: %s", elf_errmsg(-1)); in load_sections()
7258 if ((name = elf_strptr(re->elf, shstrndx, sh.sh_name)) == NULL) { in load_sections()
7260 name = "<no-name>"; in load_sections()
7269 if (ndx >= re->shnum) { in load_sections()
7273 if (sh.sh_link >= re->shnum) in load_sections()
7276 s = &re->sl[ndx]; in load_sections()
7277 s->name = name; in load_sections()
7278 s->scn = scn; in load_sections()
7279 s->off = sh.sh_offset; in load_sections()
7280 s->sz = sh.sh_size; in load_sections()
7281 s->entsize = sh.sh_entsize; in load_sections()
7282 s->align = sh.sh_addralign; in load_sections()
7283 s->type = sh.sh_type; in load_sections()
7284 s->flags = sh.sh_flags; in load_sections()
7285 s->addr = sh.sh_addr; in load_sections()
7286 s->link = sh.sh_link; in load_sections()
7287 s->info = sh.sh_info; in load_sections()
7288 } while ((scn = elf_nextscn(re->elf, scn)) != NULL); in load_sections()
7298 if (re->sl != NULL) { in unload_sections()
7299 free(re->sl); in unload_sections()
7300 re->sl = NULL; in unload_sections()
7302 re->shnum = 0; in unload_sections()
7303 re->vd_s = NULL; in unload_sections()
7304 re->vn_s = NULL; in unload_sections()
7305 re->vs_s = NULL; in unload_sections()
7306 re->vs = NULL; in unload_sections()
7307 re->vs_sz = 0; in unload_sections()
7308 if (re->ver != NULL) { in unload_sections()
7309 free(re->ver); in unload_sections()
7310 re->ver = NULL; in unload_sections()
7311 re->ver_sz = 0; in unload_sections()
7320 if (gelf_getehdr(re->elf, &re->ehdr) == NULL) { in dump_elf()
7321 warnx("gelf_getehdr failed: %s", elf_errmsg(-1)); in dump_elf()
7324 if ((re->ec = gelf_getclass(re->elf)) == ELFCLASSNONE) { in dump_elf()
7325 warnx("gelf_getclass failed: %s", elf_errmsg(-1)); in dump_elf()
7328 if (re->ehdr.e_ident[EI_DATA] == ELFDATA2MSB) { in dump_elf()
7329 re->dw_read = _read_msb; in dump_elf()
7330 re->dw_decode = _decode_msb; in dump_elf()
7332 re->dw_read = _read_lsb; in dump_elf()
7333 re->dw_decode = _decode_lsb; in dump_elf()
7336 if (re->options & ~RE_H) in dump_elf()
7338 if ((re->options & RE_VV) || (re->options & RE_S)) in dump_elf()
7340 if (re->options & RE_H) in dump_elf()
7342 if (re->options & RE_L) in dump_elf()
7344 if (re->options & RE_SS) in dump_elf()
7346 if (re->options & RE_G) in dump_elf()
7348 if (re->options & RE_D) in dump_elf()
7350 if (re->options & RE_R) in dump_elf()
7352 if (re->options & RE_S) in dump_elf()
7354 if (re->options & RE_N) in dump_elf()
7356 if (re->options & RE_II) in dump_elf()
7358 if (re->options & RE_X) in dump_elf()
7360 if (re->options & RE_P) in dump_elf()
7362 if (re->options & RE_VV) in dump_elf()
7364 if (re->options & RE_AA) in dump_elf()
7366 if (re->options & RE_W) in dump_elf()
7368 if (re->options & ~RE_H) in dump_elf()
7379 if (dwarf_elf_init(re->elf, DW_DLC_READ, NULL, NULL, &re->dbg, &de)) { in dump_dwarf()
7386 if (re->dop & DW_A) in dump_dwarf()
7388 if (re->dop & DW_L) in dump_dwarf()
7390 if (re->dop & DW_LL) in dump_dwarf()
7392 if (re->dop & DW_I) { in dump_dwarf()
7396 if (re->dop & DW_P) in dump_dwarf()
7398 if (re->dop & DW_R) in dump_dwarf()
7400 if (re->dop & DW_RR) in dump_dwarf()
7402 if (re->dop & DW_M) in dump_dwarf()
7404 if (re->dop & DW_F) in dump_dwarf()
7406 else if (re->dop & DW_FF) in dump_dwarf()
7408 if (re->dop & DW_S) in dump_dwarf()
7410 if (re->dop & DW_O) in dump_dwarf()
7413 dwarf_finish(re->dbg, &de); in dump_dwarf()
7427 re->ar = re->elf; in dump_ar()
7429 if (re->options & RE_C) { in dump_ar()
7430 if ((arsym = elf_getarsym(re->ar, &sz)) == NULL) { in dump_ar()
7431 warnx("elf_getarsym() failed: %s", elf_errmsg(-1)); in dump_ar()
7434 printf("Index of archive %s: (%ju entries)\n", re->filename, in dump_ar()
7435 (uintmax_t) sz - 1); in dump_ar()
7442 if (elf_rand(re->ar, off) != off) { in dump_ar()
7444 elf_errmsg(-1)); in dump_ar()
7447 if ((e = elf_begin(fd, ELF_C_READ, re->ar)) == in dump_ar()
7450 elf_errmsg(-1)); in dump_ar()
7455 elf_errmsg(-1)); in dump_ar()
7460 re->filename, arhdr->ar_name); in dump_ar()
7465 if (elf_rand(re->ar, SARMAG) != SARMAG) { in dump_ar()
7466 warnx("elf_rand() failed: %s", elf_errmsg(-1)); in dump_ar()
7473 if ((re->options & ~RE_C) == 0) in dump_ar()
7477 while ((re->elf = elf_begin(fd, cmd, re->ar)) != NULL) { in dump_ar()
7478 if ((arhdr = elf_getarhdr(re->elf)) == NULL) { in dump_ar()
7479 warnx("elf_getarhdr() failed: %s", elf_errmsg(-1)); in dump_ar()
7482 if (strcmp(arhdr->ar_name, "/") == 0 || in dump_ar()
7483 strcmp(arhdr->ar_name, "//") == 0 || in dump_ar()
7484 strcmp(arhdr->ar_name, "__.SYMDEF") == 0) in dump_ar()
7486 printf("\nFile: %s(%s)\n", re->filename, arhdr->ar_name); in dump_ar()
7490 cmd = elf_next(re->elf); in dump_ar()
7491 elf_end(re->elf); in dump_ar()
7493 re->elf = re->ar; in dump_ar()
7502 if ((re->flags & DISPLAY_FILENAME) != 0) in dump_object()
7503 printf("\nFile: %s\n", re->filename); in dump_object()
7505 if ((re->elf = elf_begin(fd, ELF_C_READ, NULL)) == NULL) { in dump_object()
7506 warnx("elf_begin() failed: %s", elf_errmsg(-1)); in dump_object()
7510 switch (elf_kind(re->elf)) { in dump_object()
7525 elf_end(re->elf); in dump_object()
7534 if ((d = find_dumpop(re, si, sn, -1, t)) == NULL) { in add_dumpop()
7538 d->u.si = si; in add_dumpop()
7540 d->u.sn = sn; in add_dumpop()
7541 d->type = t; in add_dumpop()
7542 d->op = op; in add_dumpop()
7543 STAILQ_INSERT_TAIL(&re->v_dumpop, d, dumpop_list); in add_dumpop()
7545 d->op |= op; in add_dumpop()
7553 STAILQ_FOREACH(d, &re->v_dumpop, dumpop_list) { in find_dumpop()
7554 if ((op == -1 || op & d->op) && in find_dumpop()
7555 (t == -1 || (unsigned) t == d->type)) { in find_dumpop()
7556 if ((d->type == DUMP_BY_INDEX && d->u.si == si) || in find_dumpop()
7557 (d->type == DUMP_BY_NAME && !strcmp(d->u.sn, sn))) in find_dumpop()
7580 {"frames-interp", 'F', DW_FF},
7592 re->dop |= DW_DEFAULT_OPTIONS; in parse_dwarf_op_short()
7599 re->dop |= dwarf_op[i].value; in parse_dwarf_op_short()
7613 re->dop |= DW_DEFAULT_OPTIONS; in parse_dwarf_op_long()
7624 re->dop |= dwarf_op[i].value; in parse_dwarf_op_long()
7639 src = (uint8_t *) d->d_buf + *offsetp; in _read_lsb()
7671 src = (uint8_t *) d->d_buf + *offsetp; in _read_msb()
7785 ret |= (-1 << shift); in _decode_sleb128()
7826 -a | --all Equivalent to specifying options '-dhIlrsASV'.\n\
7827 -c | --archive-index Print the archive symbol table for archives.\n\
7828 -d | --dynamic Print the contents of SHT_DYNAMIC sections.\n\
7829 -e | --headers Print all headers in the object.\n\
7830 -g | --section-groups Print the contents of the section groups.\n\
7831 -h | --file-header Print the file header for the object.\n\
7832 -l | --program-headers Print the PHDR table for the object.\n\
7833 -n | --notes Print the contents of SHT_NOTE sections.\n\
7834 -p INDEX | --string-dump=INDEX\n\
7836 -r | --relocs Print relocation information.\n\
7837 -s | --syms | --symbols Print symbol tables.\n\
7838 -t | --section-details Print additional information about sections.\n\
7839 -v | --version Print a version identifier and exit.\n\
7840 -w[afilmoprsFLR] | --debug-dump={abbrev,aranges,decodedline,frames,\n\
7841 frames-interp,info,loc,macro,pubnames,\n\
7844 -x INDEX | --hex-dump=INDEX\n\
7846 -z | --decompress Decompress the contents of a section before displaying it.\n\
7847 -A | --arch-specific (accepted, but ignored)\n\
7848 -D | --use-dynamic Print the symbol table specified by the DT_SYMTAB\n\
7850 -H | --help Print a help message.\n\
7851 -I | --histogram Print information on bucket list lengths for \n\
7853 -N | --full-section-name (accepted, but ignored)\n\
7854 -S | --sections | --section-headers\n\
7856 -V | --version-info Print symbol versoning information.\n\
7857 -W | --wide Print information without wrapping long lines.\n"
7879 STAILQ_INIT(&re->v_dumpop); in main()
7882 longopts, NULL)) != -1) { in main()
7888 re->options |= RE_AA; in main()
7891 re->options |= RE_AA | RE_D | RE_G | RE_H | RE_II | in main()
7895 re->options |= RE_C; in main()
7898 re->options |= RE_DD; in main()
7901 re->options |= RE_D; in main()
7904 re->options |= RE_H | RE_L | RE_SS; in main()
7907 re->options |= RE_G; in main()
7913 re->options |= RE_H; in main()
7916 re->options |= RE_II; in main()
7922 re->options |= RE_L; in main()
7925 re->options |= RE_NN; in main()
7928 re->options |= RE_N; in main()
7931 re->options |= RE_P; in main()
7941 re->options |= RE_R; in main()
7944 re->options |= RE_SS; in main()
7947 re->options |= RE_S; in main()
7950 re->options |= RE_SS | RE_T; in main()
7953 re->options |= RE_U; in main()
7956 re->options |= RE_VV; in main()
7962 re->options |= RE_WW; in main()
7965 re->options |= RE_W; in main()
7969 re->options |= RE_X; in main()
7979 re->options |= RE_Z; in main()
7982 re->options |= RE_W; in main()
7988 argc -= optind; in main()
7990 if (argc == 0 || re->options == 0) in main()
7994 re->flags |= DISPLAY_FILENAME; in main()
7998 elf_errmsg(-1)); in main()
8017 re->filename = argv[i]; in main()
8018 fd = fileargs_open(fa, re->filename); in main()
8020 warn("open %s failed", re->filename); in main()