Lines Matching +full:bl +full:- +full:data +full:- +full:offset

1 /*-
2 * Copyright (c) 2007-2012 Kai Wang
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
53 ELFTC_VCSID("$Id: elfdump.c 3762 2019-06-28 21:06:24Z emaste $");
56 #include "native-elf-format.h"
77 #define ED_ALL ((1<<12)-1)
86 #define PRT(...) fprintf(ed->out, __VA_ARGS__)
88 /* Internal data structure for sections. */
92 uint64_t off; /* section offset */
108 /* Structure encapsulates the global data for readelf(1). */
123 STAILQ_HEAD(, spec_name) snl; /* list of names specified by -N. */
194 /* 0x6000000D - 0x6ffff000 operating system-specific semantics */ in d_tags()
224 /* 0x70000000 - 0x7fffffff processor-specific semantics */ in d_tags()
262 "(unknown machine) -- type 0x%x", mach); in e_machines()
316 elf_data_str(unsigned int data) in elf_data_str() argument
320 switch (data) { in elf_data_str()
325 snprintf(s_data, sizeof(s_data), "<unknown: %#x>", data); in elf_data_str()
380 if ((uint64_t)ndx < ed->shnum) in sh_name()
381 return (ed->sl[ndx].name); in sh_name()
415 /* 0x60000000-0x6fffffff operating system-specific semantics */ in sh_types()
427 /* 0x70000000 - 0x7fffffff processor-specific semantics */ in sh_types()
459 /* 0x80000000 - 0xffffffff application programs */ in sh_types()
501 flg[strlen(flg) - 1] = '\0'; /* Remove the trailing "|". */ in sh_flags()
608 Elf_Data *data);
610 Elf_Data *data);
653 STAILQ_INIT(&ed->snl); in main()
654 ed->out = stdout; in main()
656 elfdump_longopts, NULL)) != -1) in main()
659 ed->options = ED_ALL; in main()
662 ed->options |= ED_SHDR; in main()
665 ed->options |= ED_DYN; in main()
668 ed->options |= ED_EHDR; in main()
671 ed->options |= ED_INTERP; in main()
674 ed->options |= ED_GOT; in main()
677 ed->options |= ED_HASH; in main()
680 ed->options |= ED_CHECKSUM; in main()
683 ed->options |= ED_NOTE; in main()
689 ed->options |= ED_PHDR; in main()
692 ed->options |= ED_REL; in main()
695 ed->options |= ED_SYMTAB; in main()
698 ed->flags |= SOLARIS_FMT; in main()
701 ed->options |= ED_SYMVER; in main()
709 if ((ed->out = fopen(optarg, "w")) == NULL) in main()
718 ac -= optind; in main()
721 if (ed->options == 0) in main()
722 ed->options = ED_ALL; in main()
724 if (ed->options & ED_SYMTAB && in main()
725 (STAILQ_EMPTY(&ed->snl) || (sn = find_name(ed, "ARSYM")) != NULL)) { in main()
726 ed->flags |= PRINT_ARSYM; in main()
728 STAILQ_REMOVE(&ed->snl, sn, spec_name, sn_list); in main()
729 if (STAILQ_EMPTY(&ed->snl)) in main()
730 ed->flags |= ONLY_ARSYM; in main()
736 ed->flags |= PRINT_FILENAME; in main()
739 elf_errmsg(-1)); in main()
742 ed->filename = av[i]; in main()
743 ed->archive = NULL; in main()
778 r = -1; in ac_detect_ar()
806 if (lseek(fd, 0, SEEK_SET) == -1) in ac_print_ar()
839 * since we can not just "lseek" to a member offset and read in ac_print_ar()
842 if (!strcmp(name, "/") && ed->flags & PRINT_ARSYM) { in ac_print_ar()
861 if (ed->flags & SOLARIS_FMT) { in ac_print_ar()
863 PRT(" index offset symbol\n"); in ac_print_ar()
867 if (ed->flags & SOLARIS_FMT) { in ac_print_ar()
884 if (ed->flags & ONLY_ARSYM) { in ac_print_ar()
891 if ((ed->elf = elf_memory(buff, size)) == NULL) { in ac_print_ar()
893 elf_errmsg(-1)); in ac_print_ar()
897 /* Skip non-ELF member. */ in ac_print_ar()
898 if (elf_kind(ed->elf) == ELF_K_ELF) { in ac_print_ar()
899 printf("\n%s(%s):\n", ed->archive, name); in ac_print_ar()
902 elf_end(ed->elf); in ac_print_ar()
924 ed->ar = ed->elf; in elf_print_ar()
926 if (ed->flags & PRINT_ARSYM) { in elf_print_ar()
928 if ((arsym = elf_getarsym(ed->ar, &cnt)) == NULL) { in elf_print_ar()
929 warnx("elf_getarsym failed: %s", elf_errmsg(-1)); in elf_print_ar()
934 if (ed->flags & SOLARIS_FMT) { in elf_print_ar()
936 PRT(" index offset member name and symbol\n"); in elf_print_ar()
939 for (i = 0; i < cnt - 1; i++) { in elf_print_ar()
940 if (elf_rand(ed->ar, arsym[i].as_off) != in elf_print_ar()
942 warnx("elf_rand failed: %s", elf_errmsg(-1)); in elf_print_ar()
945 if ((e = elf_begin(fd, ELF_C_READ, ed->ar)) == NULL) { in elf_print_ar()
946 warnx("elf_begin failed: %s", elf_errmsg(-1)); in elf_print_ar()
951 elf_errmsg(-1)); in elf_print_ar()
954 if (ed->flags & SOLARIS_FMT) { in elf_print_ar()
959 PRT("(%s):%s\n", arh->ar_name, in elf_print_ar()
965 PRT("\tmember: %s\n", arh->ar_name); in elf_print_ar()
972 if (ed->flags & ONLY_ARSYM) in elf_print_ar()
979 if (elf_rand(ed->ar, SARMAG) != SARMAG) { in elf_print_ar()
980 warnx("elf_rand failed: %s", elf_errmsg(-1)); in elf_print_ar()
986 while ((ed->elf = elf_begin(fd, cmd, ed->ar)) != NULL) { in elf_print_ar()
987 /* Skip non-ELF member. */ in elf_print_ar()
988 if (elf_kind(ed->elf) == ELF_K_ELF) { in elf_print_ar()
989 if ((arh = elf_getarhdr(ed->elf)) == NULL) { in elf_print_ar()
991 elf_errmsg(-1)); in elf_print_ar()
994 printf("\n%s(%s):\n", ed->archive, arh->ar_name); in elf_print_ar()
997 cmd = elf_next(ed->elf); in elf_print_ar()
998 elf_end(ed->elf); in elf_print_ar()
1012 if ((fd = open(ed->filename, O_RDONLY)) == -1) { in elf_print_object()
1013 warn("open %s failed", ed->filename); in elf_print_object()
1019 ed->archive = ed->filename; in elf_print_object()
1025 if ((ed->elf = elf_begin(fd, ELF_C_READ, NULL)) == NULL) { in elf_print_object()
1026 warnx("elf_begin() failed: %s", elf_errmsg(-1)); in elf_print_object()
1030 switch (elf_kind(ed->elf)) { in elf_print_object()
1035 if (ed->flags & PRINT_FILENAME) in elf_print_object()
1036 printf("\n%s:\n", ed->filename); in elf_print_object()
1041 ed->archive = ed->filename; in elf_print_object()
1050 elf_end(ed->elf); in elf_print_object()
1060 if (gelf_getehdr(ed->elf, &ed->ehdr) == NULL) { in elf_print_elf()
1061 warnx("gelf_getehdr failed: %s", elf_errmsg(-1)); in elf_print_elf()
1064 if ((ed->ec = gelf_getclass(ed->elf)) == ELFCLASSNONE) { in elf_print_elf()
1065 warnx("gelf_getclass failed: %s", elf_errmsg(-1)); in elf_print_elf()
1069 if (ed->options & (ED_SHDR | ED_DYN | ED_REL | ED_GOT | ED_SYMTAB | in elf_print_elf()
1073 if (ed->options & ED_EHDR) in elf_print_elf()
1075 if (ed->options & ED_PHDR) in elf_print_elf()
1077 if (ed->options & ED_INTERP) in elf_print_elf()
1079 if (ed->options & ED_SHDR) in elf_print_elf()
1081 if (ed->options & ED_DYN) in elf_print_elf()
1083 if (ed->options & ED_REL) in elf_print_elf()
1085 if (ed->options & ED_GOT) in elf_print_elf()
1087 if (ed->options & ED_SYMTAB) in elf_print_elf()
1089 if (ed->options & ED_SYMVER) in elf_print_elf()
1091 if (ed->options & ED_NOTE) in elf_print_elf()
1093 if (ed->options & ED_HASH) in elf_print_elf()
1095 if (ed->options & ED_CHECKSUM) in elf_print_elf()
1115 assert(ed->sl == NULL); in load_sections()
1117 if (!elf_getshnum(ed->elf, &ed->shnum)) { in load_sections()
1118 warnx("elf_getshnum failed: %s", elf_errmsg(-1)); in load_sections()
1121 if (ed->shnum == 0) in load_sections()
1123 if ((ed->sl = calloc(ed->shnum, sizeof(*ed->sl))) == NULL) in load_sections()
1125 if (!elf_getshstrndx(ed->elf, &shstrndx)) { in load_sections()
1126 warnx("elf_getshstrndx failed: %s", elf_errmsg(-1)); in load_sections()
1129 if ((scn = elf_getscn(ed->elf, 0)) == NULL) { in load_sections()
1130 warnx("elf_getscn failed: %s", elf_errmsg(-1)); in load_sections()
1136 warnx("gelf_getshdr failed: %s", elf_errmsg(-1)); in load_sections()
1140 if ((name = elf_strptr(ed->elf, shstrndx, sh.sh_name)) == NULL) { in load_sections()
1150 if (ndx >= ed->shnum) { in load_sections()
1154 s = &ed->sl[ndx]; in load_sections()
1155 s->name = name; in load_sections()
1156 s->scn = scn; in load_sections()
1157 s->off = sh.sh_offset; in load_sections()
1158 s->sz = sh.sh_size; in load_sections()
1159 s->entsize = sh.sh_entsize; in load_sections()
1160 s->align = sh.sh_addralign; in load_sections()
1161 s->type = sh.sh_type; in load_sections()
1162 s->flags = sh.sh_flags; in load_sections()
1163 s->addr = sh.sh_addr; in load_sections()
1164 s->link = sh.sh_link; in load_sections()
1165 s->info = sh.sh_info; in load_sections()
1166 } while ((scn = elf_nextscn(ed->elf, scn)) != NULL); in load_sections()
1178 if (ed->sl != NULL) { in unload_sections()
1179 free(ed->sl); in unload_sections()
1180 ed->sl = NULL; in unload_sections()
1185 * Add a name to the '-N' name list.
1198 sn->name = name; in add_name()
1199 STAILQ_INSERT_TAIL(&ed->snl, sn, sn_list); in add_name()
1203 * Lookup a name in the '-N' name list.
1210 STAILQ_FOREACH(sn, &ed->snl, sn_list) { in find_name()
1211 if (!strcmp(sn->name, name)) in find_name()
1229 Elf_Data *data; in get_symbol_name() local
1232 if (symtab >= ed->shnum) in get_symbol_name()
1234 s = &ed->sl[symtab]; in get_symbol_name()
1235 if (s->type != SHT_SYMTAB && s->type != SHT_DYNSYM) in get_symbol_name()
1238 if ((data = elf_getdata(s->scn, NULL)) == NULL) { in get_symbol_name()
1244 if (gelf_getsym(data, i, &sym) != &sym) in get_symbol_name()
1247 if (sym.st_shndx < ed->shnum) { in get_symbol_name()
1249 ed->sl[sym.st_shndx].name); in get_symbol_name()
1254 if ((name = elf_strptr(ed->elf, s->link, sym.st_name)) == NULL) in get_symbol_name()
1261 * Retrieve a string using string table section index and the string offset.
1268 if ((name = elf_strptr(ed->elf, strtab, off)) == NULL) in get_string()
1281 if (!STAILQ_EMPTY(&ed->snl)) in elf_print_ehdr()
1284 if (ed->flags & SOLARIS_FMT) { in elf_print_ehdr()
1287 ed->ehdr.e_ident[0], ed->ehdr.e_ident[1], in elf_print_ehdr()
1288 ed->ehdr.e_ident[2], ed->ehdr.e_ident[3]); in elf_print_ehdr()
1289 PRT(" ei_class: %-18s", in elf_print_ehdr()
1290 elf_class_str(ed->ehdr.e_ident[EI_CLASS])); in elf_print_ehdr()
1292 elf_data_str(ed->ehdr.e_ident[EI_DATA])); in elf_print_ehdr()
1293 PRT(" e_machine: %-18s", e_machines(ed->ehdr.e_machine)); in elf_print_ehdr()
1295 elf_version_str(ed->ehdr.e_version)); in elf_print_ehdr()
1296 PRT(" e_type: %s\n", elf_type_str(ed->ehdr.e_type)); in elf_print_ehdr()
1297 PRT(" e_flags: %18d\n", ed->ehdr.e_flags); in elf_print_ehdr()
1298 PRT(" e_entry: %#18jx", (uintmax_t)ed->ehdr.e_entry); in elf_print_ehdr()
1299 PRT(" e_ehsize: %6d", ed->ehdr.e_ehsize); in elf_print_ehdr()
1300 PRT(" e_shstrndx:%5d\n", ed->ehdr.e_shstrndx); in elf_print_ehdr()
1301 PRT(" e_shoff: %#18jx", (uintmax_t)ed->ehdr.e_shoff); in elf_print_ehdr()
1302 PRT(" e_shentsize: %3d", ed->ehdr.e_shentsize); in elf_print_ehdr()
1303 PRT(" e_shnum: %5d\n", ed->ehdr.e_shnum); in elf_print_ehdr()
1304 PRT(" e_phoff: %#18jx", (uintmax_t)ed->ehdr.e_phoff); in elf_print_ehdr()
1305 PRT(" e_phentsize: %3d", ed->ehdr.e_phentsize); in elf_print_ehdr()
1306 PRT(" e_phnum: %5d\n", ed->ehdr.e_phnum); in elf_print_ehdr()
1311 elf_class_str(ed->ehdr.e_ident[EI_CLASS]), in elf_print_ehdr()
1312 elf_data_str(ed->ehdr.e_ident[EI_DATA]), in elf_print_ehdr()
1313 ei_abis[ed->ehdr.e_ident[EI_OSABI]]); in elf_print_ehdr()
1314 PRT("\te_type: %s\n", elf_type_str(ed->ehdr.e_type)); in elf_print_ehdr()
1315 PRT("\te_machine: %s\n", e_machines(ed->ehdr.e_machine)); in elf_print_ehdr()
1316 PRT("\te_version: %s\n", elf_version_str(ed->ehdr.e_version)); in elf_print_ehdr()
1317 PRT("\te_entry: %#jx\n", (uintmax_t)ed->ehdr.e_entry); in elf_print_ehdr()
1318 PRT("\te_phoff: %ju\n", (uintmax_t)ed->ehdr.e_phoff); in elf_print_ehdr()
1319 PRT("\te_shoff: %ju\n", (uintmax_t) ed->ehdr.e_shoff); in elf_print_ehdr()
1320 PRT("\te_flags: %u\n", ed->ehdr.e_flags); in elf_print_ehdr()
1321 PRT("\te_ehsize: %u\n", ed->ehdr.e_ehsize); in elf_print_ehdr()
1322 PRT("\te_phentsize: %u\n", ed->ehdr.e_phentsize); in elf_print_ehdr()
1323 PRT("\te_phnum: %u\n", ed->ehdr.e_phnum); in elf_print_ehdr()
1324 PRT("\te_shentsize: %u\n", ed->ehdr.e_shentsize); in elf_print_ehdr()
1325 PRT("\te_shnum: %u\n", ed->ehdr.e_shnum); in elf_print_ehdr()
1326 PRT("\te_shstrndx: %u\n", ed->ehdr.e_shstrndx); in elf_print_ehdr()
1340 if (elf_getphnum(ed->elf, &phnum) == 0) { in elf_print_phdr()
1341 warnx("elf_getphnum failed: %s", elf_errmsg(-1)); in elf_print_phdr()
1346 if (gelf_getphdr(ed->elf, i, &ph) != &ph) { in elf_print_phdr()
1347 warnx("elf_getphdr failed: %s", elf_errmsg(-1)); in elf_print_phdr()
1350 if (!STAILQ_EMPTY(&ed->snl) && in elf_print_phdr()
1353 if (ed->flags & SOLARIS_FMT) { in elf_print_phdr()
1355 PRT(" p_vaddr: %#-14jx", (uintmax_t)ph.p_vaddr); in elf_print_phdr()
1358 PRT(" p_paddr: %#-14jx", (uintmax_t)ph.p_paddr); in elf_print_phdr()
1361 PRT(" p_filesz: %#-14jx", in elf_print_phdr()
1364 PRT(" p_offset: %#-14jx", in elf_print_phdr()
1395 if (!STAILQ_EMPTY(&ed->snl)) in elf_print_shdr()
1398 if ((ed->flags & SOLARIS_FMT) == 0) in elf_print_shdr()
1400 for (i = 0; i < ed->shnum; i++) { in elf_print_shdr()
1401 s = &ed->sl[i]; in elf_print_shdr()
1402 if (ed->flags & SOLARIS_FMT) { in elf_print_shdr()
1406 PRT(" sh_name: %s\n", s->name); in elf_print_shdr()
1407 PRT(" sh_addr: %#-14jx", (uintmax_t)s->addr); in elf_print_shdr()
1408 if (s->flags != 0) in elf_print_shdr()
1409 PRT(" sh_flags: [ %s ]\n", sh_flags(s->flags)); in elf_print_shdr()
1412 PRT(" sh_size: %#-14jx", (uintmax_t)s->sz); in elf_print_shdr()
1414 sh_types(ed->ehdr.e_machine, s->type)); in elf_print_shdr()
1415 PRT(" sh_offset: %#-14jx", (uintmax_t)s->off); in elf_print_shdr()
1416 PRT(" sh_entsize: %#jx\n", (uintmax_t)s->entsize); in elf_print_shdr()
1417 PRT(" sh_link: %-14u", s->link); in elf_print_shdr()
1418 PRT(" sh_info: %u\n", s->info); in elf_print_shdr()
1419 PRT(" sh_addralign: %#jx\n", (uintmax_t)s->align); in elf_print_shdr()
1423 PRT("\tsh_name: %s\n", s->name); in elf_print_shdr()
1425 sh_types(ed->ehdr.e_machine, s->type)); in elf_print_shdr()
1426 PRT("\tsh_flags: %s\n", sh_flags(s->flags)); in elf_print_shdr()
1427 PRT("\tsh_addr: %#jx\n", (uintmax_t)s->addr); in elf_print_shdr()
1428 PRT("\tsh_offset: %ju\n", (uintmax_t)s->off); in elf_print_shdr()
1429 PRT("\tsh_size: %ju\n", (uintmax_t)s->sz); in elf_print_shdr()
1430 PRT("\tsh_link: %u\n", s->link); in elf_print_shdr()
1431 PRT("\tsh_info: %u\n", s->info); in elf_print_shdr()
1432 PRT("\tsh_addralign: %ju\n", (uintmax_t)s->align); in elf_print_shdr()
1433 PRT("\tsh_entsize: %ju\n", (uintmax_t)s->entsize); in elf_print_shdr()
1445 if (s->entsize == 0) { in get_ent_count()
1446 warnx("section %s has entry size 0", s->name); in get_ent_count()
1448 } else if (s->sz / s->entsize > INT_MAX) { in get_ent_count()
1449 warnx("section %s has invalid section count", s->name); in get_ent_count()
1452 *ent_count = (int)(s->sz / s->entsize); in get_ent_count()
1464 Elf_Data *data; in get_versym() local
1469 for (j = 0; j < ed->shnum; j++) { in get_versym()
1470 s = &ed->sl[j]; in get_versym()
1471 if (s->type == SHT_SUNW_versym && s->link == (uint32_t)i) in get_versym()
1474 if (j >= ed->shnum) { in get_versym()
1479 if ((data = elf_getdata(s->scn, NULL)) == NULL) { in get_versym()
1487 *vs = data->d_buf; in get_versym()
1488 assert(data->d_size == s->sz); in get_versym()
1503 Elf_Data *data; in elf_print_symtab() local
1507 s = &ed->sl[i]; in elf_print_symtab()
1508 if (ed->flags & SOLARIS_FMT) in elf_print_symtab()
1509 PRT("\nSymbol Table Section: %s\n", s->name); in elf_print_symtab()
1511 PRT("\nsymbol table (%s):\n", s->name); in elf_print_symtab()
1513 if ((data = elf_getdata(s->scn, NULL)) == NULL) { in elf_print_symtab()
1521 assert(data->d_size == s->sz); in elf_print_symtab()
1524 if (ed->flags & SOLARIS_FMT) { in elf_print_symtab()
1525 if (ed->ec == ELFCLASS32) in elf_print_symtab()
1537 if (gelf_getsym(data, j, &sym) != &sym) { in elf_print_symtab()
1538 warnx("gelf_getsym failed: %s", elf_errmsg(-1)); in elf_print_symtab()
1541 name = get_string(ed, s->link, sym.st_name); in elf_print_symtab()
1542 if (ed->flags & SOLARIS_FMT) { in elf_print_symtab()
1544 if (ed->ec == ELFCLASS32) in elf_print_symtab()
1549 if (ed->ec == ELFCLASS32) in elf_print_symtab()
1557 PRT("%-11.11s ", sh_name(ed, sym.st_shndx)); in elf_print_symtab()
1565 st_type(ed->ehdr.e_machine, in elf_print_symtab()
1581 for (i = 0; i < ed->shnum; i++) in elf_print_symtabs()
1582 if ((ed->sl[i].type == SHT_SYMTAB || in elf_print_symtabs()
1583 ed->sl[i].type == SHT_DYNSYM) && in elf_print_symtabs()
1584 (STAILQ_EMPTY(&ed->snl) || find_name(ed, ed->sl[i].name))) in elf_print_symtabs()
1597 Elf_Data *data; in elf_print_dynamic() local
1602 for (i = 0; (size_t)i < ed->shnum; i++) { in elf_print_dynamic()
1603 s = &ed->sl[i]; in elf_print_dynamic()
1604 if (s->type == SHT_DYNAMIC && in elf_print_dynamic()
1605 (STAILQ_EMPTY(&ed->snl) || find_name(ed, s->name))) in elf_print_dynamic()
1608 if ((size_t)i >= ed->shnum) in elf_print_dynamic()
1611 if (ed->flags & SOLARIS_FMT) { in elf_print_dynamic()
1612 PRT("Dynamic Section: %s\n", s->name); in elf_print_dynamic()
1617 if ((data = elf_getdata(s->scn, NULL)) == NULL) { in elf_print_dynamic()
1623 assert(data->d_size == s->sz); in elf_print_dynamic()
1627 if (gelf_getdyn(data, i, &dyn) != &dyn) { in elf_print_dynamic()
1628 warnx("gelf_getdyn failed: %s", elf_errmsg(-1)); in elf_print_dynamic()
1632 if (ed->flags & SOLARIS_FMT) { in elf_print_dynamic()
1634 PRT("%10s %-16s ", idx, d_tags(dyn.d_tag)); in elf_print_dynamic()
1645 if ((name = elf_strptr(ed->elf, s->link, in elf_print_dynamic()
1648 if (ed->flags & SOLARIS_FMT) in elf_print_dynamic()
1649 PRT("%#-16jx %s\n", (uintmax_t)dyn.d_un.d_val, in elf_print_dynamic()
1669 if (ed->flags & SOLARIS_FMT) in elf_print_dynamic()
1685 if (ed->flags & SOLARIS_FMT) in elf_print_dynamic()
1695 if (ed->flags & SOLARIS_FMT) in elf_print_dynamic()
1710 if (ed->flags & SOLARIS_FMT) { in elf_print_rel_entry()
1711 PRT(" %-23s ", elftc_reloc_type_str(ed->ehdr.e_machine, in elf_print_rel_entry()
1712 GELF_R_TYPE(r->u_r.rel.r_info))); in elf_print_rel_entry()
1713 PRT("%#12jx ", (uintmax_t)r->u_r.rel.r_offset); in elf_print_rel_entry()
1714 if (r->type == SHT_RELA) in elf_print_rel_entry()
1715 PRT("%10jd ", (intmax_t)r->u_r.rela.r_addend); in elf_print_rel_entry()
1718 PRT("%-14s ", s->name); in elf_print_rel_entry()
1719 PRT("%s\n", r->symn); in elf_print_rel_entry()
1723 PRT("\tr_offset: %#jx\n", (uintmax_t)r->u_r.rel.r_offset); in elf_print_rel_entry()
1724 if (ed->ec == ELFCLASS32) in elf_print_rel_entry()
1726 ELF32_R_INFO(ELF64_R_SYM(r->u_r.rel.r_info), in elf_print_rel_entry()
1727 ELF64_R_TYPE(r->u_r.rel.r_info))); in elf_print_rel_entry()
1729 PRT("\tr_info: %#jx\n", (uintmax_t)r->u_r.rel.r_info); in elf_print_rel_entry()
1730 if (r->type == SHT_RELA) in elf_print_rel_entry()
1732 (intmax_t)r->u_r.rela.r_addend); in elf_print_rel_entry()
1740 elf_print_rela(struct elfdump *ed, struct section *s, Elf_Data *data) in elf_print_rela() argument
1745 if (ed->flags & SOLARIS_FMT) { in elf_print_rela()
1746 PRT("\nRelocation Section: %s\n", s->name); in elf_print_rela()
1747 PRT(" type offset " in elf_print_rela()
1750 PRT("\nrelocation with addend (%s):\n", s->name); in elf_print_rela()
1752 assert(data->d_size == s->sz); in elf_print_rela()
1756 if (gelf_getrela(data, j, &r.u_r.rela) != &r.u_r.rela) { in elf_print_rela()
1758 elf_errmsg(-1)); in elf_print_rela()
1761 r.symn = get_symbol_name(ed, s->link, in elf_print_rela()
1771 elf_print_rel(struct elfdump *ed, struct section *s, Elf_Data *data) in elf_print_rel() argument
1776 if (ed->flags & SOLARIS_FMT) { in elf_print_rel()
1777 PRT("\nRelocation Section: %s\n", s->name); in elf_print_rel()
1778 PRT(" type offset " in elf_print_rel()
1781 PRT("\nrelocation (%s):\n", s->name); in elf_print_rel()
1783 assert(data->d_size == s->sz); in elf_print_rel()
1787 if (gelf_getrel(data, j, &r.u_r.rel) != &r.u_r.rel) { in elf_print_rel()
1788 warnx("gelf_getrel failed: %s", elf_errmsg(-1)); in elf_print_rel()
1791 r.symn = get_symbol_name(ed, s->link, in elf_print_rel()
1804 Elf_Data *data; in elf_print_reloc() local
1808 for (i = 0; i < ed->shnum; i++) { in elf_print_reloc()
1809 s = &ed->sl[i]; in elf_print_reloc()
1810 if ((s->type == SHT_REL || s->type == SHT_RELA) && in elf_print_reloc()
1811 (STAILQ_EMPTY(&ed->snl) || find_name(ed, s->name))) { in elf_print_reloc()
1813 if ((data = elf_getdata(s->scn, NULL)) == NULL) { in elf_print_reloc()
1820 if (s->type == SHT_REL) in elf_print_reloc()
1821 elf_print_rel(ed, s, data); in elf_print_reloc()
1823 elf_print_rela(ed, s, data); in elf_print_reloc()
1838 if (!STAILQ_EMPTY(&ed->snl) && find_name(ed, "PT_INTERP") == NULL) in elf_print_interp()
1841 if ((s = elf_rawfile(ed->elf, &filesize)) == NULL) { in elf_print_interp()
1842 warnx("elf_rawfile failed: %s", elf_errmsg(-1)); in elf_print_interp()
1845 if (!elf_getphnum(ed->elf, &phnum)) { in elf_print_interp()
1846 warnx("elf_getphnum failed: %s", elf_errmsg(-1)); in elf_print_interp()
1850 if (gelf_getphdr(ed->elf, i, &phdr) != &phdr) { in elf_print_interp()
1851 warnx("elf_getphdr failed: %s", elf_errmsg(-1)); in elf_print_interp()
1856 warnx("invalid phdr offset"); in elf_print_interp()
1873 Elf_Data *data; in find_gotrel() local
1877 for(i = 0; i < ed->shnum; i++) { in find_gotrel()
1878 s = &ed->sl[i]; in find_gotrel()
1879 if (s->type != SHT_REL && s->type != SHT_RELA) in find_gotrel()
1882 if ((data = elf_getdata(s->scn, NULL)) == NULL) { in find_gotrel()
1890 r.type = s->type; in find_gotrel()
1891 assert(data->d_size == s->sz); in find_gotrel()
1895 if (s->type == SHT_REL) { in find_gotrel()
1896 if (gelf_getrel(data, j, &r.u_r.rel) != in find_gotrel()
1899 elf_errmsg(-1)); in find_gotrel()
1903 if (gelf_getrela(data, j, &r.u_r.rela) != in find_gotrel()
1906 elf_errmsg(-1)); in find_gotrel()
1910 if (r.u_r.rel.r_offset >= gs->addr && in find_gotrel()
1911 r.u_r.rel.r_offset < gs->addr + gs->sz) { in find_gotrel()
1912 r.symn = get_symbol_name(ed, s->link, in find_gotrel()
1914 k = (r.u_r.rel.r_offset - gs->addr) / in find_gotrel()
1915 gs->entsize; in find_gotrel()
1926 Elf_Data *data, dst; in elf_print_got_section() local
1929 if (s->entsize == 0) { in elf_print_got_section()
1931 if (s->align != 0) in elf_print_got_section()
1932 s->entsize = s->align; in elf_print_got_section()
1939 if (ed->flags & SOLARIS_FMT) in elf_print_got_section()
1940 PRT("\nGlobal Offset Table Section: %s (%d entries)\n", in elf_print_got_section()
1941 s->name, len); in elf_print_got_section()
1943 PRT("\nglobal offset table: %s\n", s->name); in elf_print_got_section()
1945 if ((data = elf_getdata(s->scn, NULL)) == NULL) { in elf_print_got_section()
1958 if (ed->ec == ELFCLASS32) in elf_print_got_section()
1959 data->d_type = ELF_T_WORD; in elf_print_got_section()
1961 data->d_type = ELF_T_XWORD; in elf_print_got_section()
1962 memcpy(&dst, data, sizeof(Elf_Data)); in elf_print_got_section()
1963 if (gelf_xlatetom(ed->elf, &dst, data, ed->ehdr.e_ident[EI_DATA]) != in elf_print_got_section()
1965 warnx("gelf_xlatetom failed: %s", elf_errmsg(-1)); in elf_print_got_section()
1968 assert(dst.d_size == s->sz); in elf_print_got_section()
1969 if (ed->flags & SOLARIS_FMT) { in elf_print_got_section()
1978 if (ed->ec == ELFCLASS32) { in elf_print_got_section()
1987 if (ed->ec == ELFCLASS32) { in elf_print_got_section()
1988 PRT("%-8.8jx ", in elf_print_got_section()
1989 (uintmax_t) (s->addr + i * s->entsize)); in elf_print_got_section()
1990 PRT("%-8.8x ", *((uint32_t *)dst.d_buf + i)); in elf_print_got_section()
1992 PRT("%-16.16jx ", in elf_print_got_section()
1993 (uintmax_t) (s->addr + i * s->entsize)); in elf_print_got_section()
1994 PRT("%-16.16jx ", in elf_print_got_section()
1997 PRT("%-18s ", elftc_reloc_type_str(ed->ehdr.e_machine, in elf_print_got_section()
1999 if (ed->ec == ELFCLASS32) in elf_print_got_section()
2000 PRT("%-8.8jd ", in elf_print_got_section()
2003 PRT("%-12.12jd ", in elf_print_got_section()
2013 if (ed->ec == ELFCLASS32) in elf_print_got_section()
2023 * Dump the content of Global Offset Table section.
2031 if (!STAILQ_EMPTY(&ed->snl)) in elf_print_got()
2035 for (i = 0; i < ed->shnum; i++) { in elf_print_got()
2036 s = &ed->sl[i]; in elf_print_got()
2037 if (s->name && !strncmp(s->name, ".got", 4) && in elf_print_got()
2038 (STAILQ_EMPTY(&ed->snl) || find_name(ed, s->name))) in elf_print_got()
2044 * Dump the content of .note.ABI-tag section.
2050 Elf_Data *data; in elf_print_note() local
2061 for (i = 0; (size_t)i < ed->shnum; i++) { in elf_print_note()
2062 s = &ed->sl[i]; in elf_print_note()
2063 if (s->type == SHT_NOTE && s->name && in elf_print_note()
2064 !strcmp(s->name, ".note.ABI-tag") && in elf_print_note()
2065 (STAILQ_EMPTY(&ed->snl) || find_name(ed, s->name))) in elf_print_note()
2068 if ((size_t)i >= ed->shnum) in elf_print_note()
2070 if (ed->flags & SOLARIS_FMT) in elf_print_note()
2071 PRT("\nNote Section: %s\n", s->name); in elf_print_note()
2073 PRT("\nnote (%s):\n", s->name); in elf_print_note()
2075 if ((data = elf_getdata(s->scn, NULL)) == NULL) { in elf_print_note()
2081 src = data->d_buf; in elf_print_note()
2082 count = data->d_size; in elf_print_note()
2085 namesz = en->n_namesz; in elf_print_note()
2086 descsz = en->n_descsz; in elf_print_note()
2088 count -= sizeof(Elf_Note); in elf_print_note()
2093 if (ed->flags & SOLARIS_FMT) { in elf_print_note()
2094 PRT("\n type %#x\n", en->n_type); in elf_print_note()
2095 PRT(" namesz %#x:\n", en->n_namesz); in elf_print_note()
2100 count -= roundup2(namesz, 4); in elf_print_note()
2108 if (ed->flags & SOLARIS_FMT) { in elf_print_note()
2109 PRT(" descsz %#x:", en->n_descsz); in elf_print_note()
2114 PRT("\n %-9s", idx); in elf_print_note()
2121 if (ed->ehdr.e_ident[EI_DATA] == ELFDATA2MSB) in elf_print_note()
2128 count -= roundup2(descsz, 4); in elf_print_note()
2138 Elf_Data *data; in elf_print_svr4_hash() local
2142 uint32_t *bl, *c, maxl, total; in elf_print_svr4_hash() local
2147 if (ed->flags & SOLARIS_FMT) in elf_print_svr4_hash()
2148 PRT("\nHash Section: %s\n", s->name); in elf_print_svr4_hash()
2150 PRT("\nhash table (%s):\n", s->name); in elf_print_svr4_hash()
2152 if ((data = elf_getdata(s->scn, NULL)) == NULL) { in elf_print_svr4_hash()
2159 if (data->d_size < 2 * sizeof(uint32_t)) { in elf_print_svr4_hash()
2163 buf = data->d_buf; in elf_print_svr4_hash()
2170 if (data->d_size != in elf_print_svr4_hash()
2178 if (ed->flags & SOLARIS_FMT) { in elf_print_svr4_hash()
2180 if ((bl = calloc(nbucket, sizeof(*bl))) == NULL) in elf_print_svr4_hash()
2184 if (++bl[i] > maxl) in elf_print_svr4_hash()
2185 maxl = bl[i]; in elf_print_svr4_hash()
2189 c[bl[i]]++; in elf_print_svr4_hash()
2200 PRT("%-10s ", idx); in elf_print_svr4_hash()
2201 PRT("%s\n", get_symbol_name(ed, s->link, j)); in elf_print_svr4_hash()
2228 Elf_Data *data, dst; in elf_print_svr4_hash64() local
2232 uint64_t *bl, *c, j, maxl, total; in elf_print_svr4_hash64() local
2237 if (ed->flags & SOLARIS_FMT) in elf_print_svr4_hash64()
2238 PRT("\nHash Section: %s\n", s->name); in elf_print_svr4_hash64()
2240 PRT("\nhash table (%s):\n", s->name); in elf_print_svr4_hash64()
2243 * ALPHA uses 64-bit hash entries. Since libelf assumes that in elf_print_svr4_hash64()
2244 * .hash section contains only 32-bit entry, an explicit in elf_print_svr4_hash64()
2248 if ((data = elf_rawdata(s->scn, NULL)) == NULL) { in elf_print_svr4_hash64()
2255 data->d_type = ELF_T_XWORD; in elf_print_svr4_hash64()
2256 memcpy(&dst, data, sizeof(Elf_Data)); in elf_print_svr4_hash64()
2257 if (gelf_xlatetom(ed->elf, &dst, data, in elf_print_svr4_hash64()
2258 ed->ehdr.e_ident[EI_DATA]) != &dst) { in elf_print_svr4_hash64()
2259 warnx("gelf_xlatetom failed: %s", elf_errmsg(-1)); in elf_print_svr4_hash64()
2280 if (ed->flags & SOLARIS_FMT) { in elf_print_svr4_hash64()
2282 if ((bl = calloc(nbucket, sizeof(*bl))) == NULL) in elf_print_svr4_hash64()
2286 if (++bl[i] > maxl) in elf_print_svr4_hash64()
2287 maxl = bl[i]; in elf_print_svr4_hash64()
2291 c[bl[i]]++; in elf_print_svr4_hash64()
2302 PRT("%-10s ", idx); in elf_print_svr4_hash64()
2303 PRT("%s\n", get_symbol_name(ed, s->link, j)); in elf_print_svr4_hash64()
2333 Elf_Data *data; in elf_print_gnu_hash() local
2337 uint32_t *bl, *c, maxl, total; in elf_print_gnu_hash() local
2342 if (ed->flags & SOLARIS_FMT) in elf_print_gnu_hash()
2343 PRT("\nGNU Hash Section: %s\n", s->name); in elf_print_gnu_hash()
2345 PRT("\ngnu hash table (%s):\n", s->name); in elf_print_gnu_hash()
2347 if ((data = elf_getdata(s->scn, NULL)) == NULL) { in elf_print_gnu_hash()
2354 if (data->d_size < 4 * sizeof(uint32_t)) { in elf_print_gnu_hash()
2358 buf = data->d_buf; in elf_print_gnu_hash()
2364 if (s->link >= ed->shnum) { in elf_print_gnu_hash()
2368 ds = &ed->sl[s->link]; in elf_print_gnu_hash()
2375 nchain = dynsymcount - symndx; in elf_print_gnu_hash()
2376 if (data->d_size != 4 * sizeof(uint32_t) + maskwords * in elf_print_gnu_hash()
2377 (ed->ec == ELFCLASS32 ? sizeof(uint32_t) : sizeof(uint64_t)) + in elf_print_gnu_hash()
2382 bucket = buf + (ed->ec == ELFCLASS32 ? maskwords : maskwords * 2); in elf_print_gnu_hash()
2385 if (ed->flags & SOLARIS_FMT) { in elf_print_gnu_hash()
2387 if ((bl = calloc(nbucket, sizeof(*bl))) == NULL) in elf_print_gnu_hash()
2390 for (j = bucket[i]; j > 0 && j - symndx < nchain; j++) { in elf_print_gnu_hash()
2391 if (++bl[i] > maxl) in elf_print_gnu_hash()
2392 maxl = bl[i]; in elf_print_gnu_hash()
2393 if (chain[j - symndx] & 1) in elf_print_gnu_hash()
2399 c[bl[i]]++; in elf_print_gnu_hash()
2403 for (j = bucket[i]; j > 0 && j - symndx < nchain; j++) { in elf_print_gnu_hash()
2410 PRT("%-10s ", idx); in elf_print_gnu_hash()
2411 PRT("%s\n", get_symbol_name(ed, s->link, j)); in elf_print_gnu_hash()
2412 if (chain[j - symndx] & 1) in elf_print_gnu_hash()
2446 for (i = 0; i < ed->shnum; i++) { in elf_print_hash()
2447 s = &ed->sl[i]; in elf_print_hash()
2448 if ((s->type == SHT_HASH || s->type == SHT_GNU_HASH) && in elf_print_hash()
2449 (STAILQ_EMPTY(&ed->snl) || find_name(ed, s->name))) { in elf_print_hash()
2450 if (s->type == SHT_GNU_HASH) in elf_print_hash()
2452 else if (ed->ehdr.e_machine == EM_ALPHA && in elf_print_hash()
2453 s->entsize == 8) in elf_print_hash()
2467 Elf_Data *data; in elf_print_verdef() local
2475 if (ed->flags & SOLARIS_FMT) in elf_print_verdef()
2476 PRT("Version Definition Section: %s\n", s->name); in elf_print_verdef()
2478 PRT("\nversion definition section (%s):\n", s->name); in elf_print_verdef()
2480 if ((data = elf_getdata(s->scn, NULL)) == NULL) { in elf_print_verdef()
2487 buf = data->d_buf; in elf_print_verdef()
2488 end = buf + data->d_size; in elf_print_verdef()
2490 if (ed->flags & SOLARIS_FMT) in elf_print_verdef()
2494 if (ed->flags & SOLARIS_FMT) { in elf_print_verdef()
2495 snprintf(idx, sizeof(idx), "[%d]", vd->vd_ndx); in elf_print_verdef()
2499 PRT("\tvd_version: %u\n", vd->vd_version); in elf_print_verdef()
2500 PRT("\tvd_flags: %u\n", vd->vd_flags); in elf_print_verdef()
2501 PRT("\tvd_ndx: %u\n", vd->vd_ndx); in elf_print_verdef()
2502 PRT("\tvd_cnt: %u\n", vd->vd_cnt); in elf_print_verdef()
2503 PRT("\tvd_hash: %u\n", vd->vd_hash); in elf_print_verdef()
2504 PRT("\tvd_aux: %u\n", vd->vd_aux); in elf_print_verdef()
2505 PRT("\tvd_next: %u\n\n", vd->vd_next); in elf_print_verdef()
2507 buf2 = buf + vd->vd_aux; in elf_print_verdef()
2510 while (buf2 + sizeof(Elf32_Verdaux) <= end && j < vd->vd_cnt) { in elf_print_verdef()
2512 str = get_string(ed, s->link, vda->vda_name); in elf_print_verdef()
2513 if (ed->flags & SOLARIS_FMT) { in elf_print_verdef()
2515 PRT("%-26.26s", str); in elf_print_verdef()
2517 PRT(" %-20.20s", str); in elf_print_verdef()
2525 PRT("\t\t\tvda_next: %u\n", vda->vda_next); in elf_print_verdef()
2527 if (vda->vda_next == 0) { in elf_print_verdef()
2528 if (ed->flags & SOLARIS_FMT) { in elf_print_verdef()
2529 if (vd->vd_flags & VER_FLG_BASE) { in elf_print_verdef()
2531 PRT("%-20.20s", ""); in elf_print_verdef()
2538 if (ed->flags & SOLARIS_FMT) in elf_print_verdef()
2540 buf2 += vda->vda_next; in elf_print_verdef()
2542 if (vd->vd_next == 0) in elf_print_verdef()
2544 buf += vd->vd_next; in elf_print_verdef()
2554 Elf_Data *data; in elf_print_verneed() local
2560 if (ed->flags & SOLARIS_FMT) in elf_print_verneed()
2561 PRT("\nVersion Needed Section: %s\n", s->name); in elf_print_verneed()
2563 PRT("\nversion need section (%s):\n", s->name); in elf_print_verneed()
2565 if ((data = elf_getdata(s->scn, NULL)) == NULL) { in elf_print_verneed()
2572 buf = data->d_buf; in elf_print_verneed()
2573 end = buf + data->d_size; in elf_print_verneed()
2574 if (ed->flags & SOLARIS_FMT) in elf_print_verneed()
2579 if (ed->flags & SOLARIS_FMT) in elf_print_verneed()
2580 PRT(" %-26.26s ", in elf_print_verneed()
2581 get_string(ed, s->link, vn->vn_file)); in elf_print_verneed()
2584 PRT("\tvn_version: %u\n", vn->vn_version); in elf_print_verneed()
2585 PRT("\tvn_cnt: %u\n", vn->vn_cnt); in elf_print_verneed()
2587 get_string(ed, s->link, vn->vn_file)); in elf_print_verneed()
2588 PRT("\tvn_aux: %u\n", vn->vn_aux); in elf_print_verneed()
2589 PRT("\tvn_next: %u\n\n", vn->vn_next); in elf_print_verneed()
2591 buf2 = buf + vn->vn_aux; in elf_print_verneed()
2594 while (buf2 + sizeof(Elf32_Vernaux) <= end && j < vn->vn_cnt) { in elf_print_verneed()
2596 if (ed->flags & SOLARIS_FMT) { in elf_print_verneed()
2601 PRT("%s\n", get_string(ed, s->link, in elf_print_verneed()
2602 vna->vna_name)); in elf_print_verneed()
2605 PRT("\t\t\tvna_hash: %u\n", vna->vna_hash); in elf_print_verneed()
2606 PRT("\t\t\tvna_flags: %u\n", vna->vna_flags); in elf_print_verneed()
2607 PRT("\t\t\tvna_other: %u\n", vna->vna_other); in elf_print_verneed()
2609 get_string(ed, s->link, vna->vna_name)); in elf_print_verneed()
2610 PRT("\t\t\tvna_next: %u\n", vna->vna_next); in elf_print_verneed()
2612 if (vna->vna_next == 0) in elf_print_verneed()
2614 buf2 += vna->vna_next; in elf_print_verneed()
2616 if (vn->vn_next == 0) in elf_print_verneed()
2618 buf += vn->vn_next; in elf_print_verneed()
2623 * Dump the symbol-versioning sections.
2631 for (i = 0; i < ed->shnum; i++) { in elf_print_symver()
2632 s = &ed->sl[i]; in elf_print_symver()
2633 if (!STAILQ_EMPTY(&ed->snl) && !find_name(ed, s->name)) in elf_print_symver()
2635 if (s->type == SHT_SUNW_verdef) in elf_print_symver()
2637 if (s->type == SHT_SUNW_verneed) in elf_print_symver()
2649 if (!STAILQ_EMPTY(&ed->snl)) in elf_print_checksum()
2652 PRT("\nelf checksum: %#lx\n", gelf_checksum(ed->elf)); in elf_print_checksum()
2659 -a Show all information.\n\
2660 -c Show shared headers.\n\
2661 -d Show dynamic symbols.\n\
2662 -e Show the ELF header.\n\
2663 -G Show the GOT.\n\
2664 -H | --help Show a usage message and exit.\n\
2665 -h Show hash values.\n\
2666 -i Show the dynamic interpreter.\n\
2667 -k Show the ELF checksum.\n\
2668 -n Show the contents of note sections.\n\
2669 -N NAME Show the section named \"NAME\".\n\
2670 -p Show the program header.\n\
2671 -r Show relocations.\n\
2672 -s Show the symbol table.\n\
2673 -S Use the Solaris elfdump format.\n\
2674 -v Show symbol-versioning information.\n\
2675 -V | --version Print a version identifier and exit.\n\
2676 -w FILE Write output to \"FILE\".\n"