460
461 if (strlen(sym_name))
462 (void) printf("%-20s", sym_name);
463 else {
464 (void) printf("%-20d", sym.st_name);
465 }
466 (void) printf("%-20s",
467 conv_reloc_type(p_ehdr->e_machine,
468 type, DUMP_CONVFMT, &inv_buf));
469 }
470 (void) printf("\n");
471 ndx++;
472 }
473 }
474
475 /* demangle C++ names */
476 static char *
477 demangled_name(char *s)
478 {
479 static char *buf = NULL;
480 const char *dn;
481 size_t len;
482
483 dn = conv_demangle_name(s);
484
485 /*
486 * If not demangled, just return the symbol name
487 */
488 if (strcmp(s, dn) == 0)
489 return (s);
490
491 /*
492 * Demangled. Format it
493 */
494 if (buf != NULL)
495 free(buf);
496
497 len = strlen(dn) + strlen(s) + 4;
498 if ((buf = malloc(len)) == NULL)
499 return (s);
500
501 (void) snprintf(buf, len, "%s\t[%s]", dn, s);
502 return (buf);
503 }
504
505 /*
506 * Print the symbol table. Input is an ELF file descriptor, a
507 * pointer to the symbol table SCNTAB structure,
508 * the number of symbols, a range of symbols to print,
509 * an index which is the number of the
510 * section in the file, and the filename. The number of sections,
511 * the range, and the index are set in
512 * dump_symbol_table, depending on whether -n or -T were set.
513 */
514 static void
515 print_symtab(Elf *elf_file, SCNTAB *p_symtab, Elf_Data *sym_data,
516 long range, int index)
517 {
518 GElf_Sym sym;
519 int adj = 0; /* field adjustment for elf64 */
520 Elf32_Word *symshndx = 0;
521 unsigned int nosymshndx = 0;
522 Conv_inv_buf_t inv_buf;
523
524
525 if (gelf_getclass(elf_file) == ELFCLASS64)
526 adj = 8;
527
528 while (range > 0) {
529 char *sym_name = (char *)0;
530 int type, bind;
531 int specsec;
532 unsigned int shndx;
533
534 (void) gelf_getsym(sym_data, index, &sym);
535 type = (int)GELF_ST_TYPE(sym.st_info);
536 bind = (int)GELF_ST_BIND(sym.st_info);
537
538 if ((sym.st_shndx == SHN_XINDEX) &&
539 (symshndx == 0) && (nosymshndx == 0)) {
540 Elf_Scn *_scn;
541 GElf_Shdr _shdr;
542 size_t symscnndx;
543
544 symscnndx = elf_ndxscn(p_symtab->p_sd);
545 _scn = 0;
546 while ((_scn = elf_nextscn(elf_file, _scn)) != 0) {
547 if (gelf_getshdr(_scn, &_shdr) == 0)
548 break;
549 if ((_shdr.sh_type == SHT_SYMTAB_SHNDX) &&
|
460
461 if (strlen(sym_name))
462 (void) printf("%-20s", sym_name);
463 else {
464 (void) printf("%-20d", sym.st_name);
465 }
466 (void) printf("%-20s",
467 conv_reloc_type(p_ehdr->e_machine,
468 type, DUMP_CONVFMT, &inv_buf));
469 }
470 (void) printf("\n");
471 ndx++;
472 }
473 }
474
475 /* demangle C++ names */
476 static char *
477 demangled_name(char *s)
478 {
479 static char *buf = NULL;
480 size_t buflen = 0;
481 char *dn;
482 size_t len;
483
484 dn = (char *)conv_demangle_name(s);
485
486 /*
487 * If not demangled, just return the symbol name
488 */
489 if (dn == s)
490 return (s);
491
492 len = strlen(dn) + strlen(s) + 4;
493
494 if (buflen < len) {
495 free(buf);
496 if ((buf = malloc(len)) == NULL)
497 return (s);
498 buflen = len;
499 }
500
501 /*
502 * Demangled. Format it
503 */
504 (void) snprintf(buf, buflen, "%s\t[%s]", dn, s);
505 free(dn);
506 return (buf);
507 }
508
509 /*
510 * Print the symbol table. Input is an ELF file descriptor, a
511 * pointer to the symbol table SCNTAB structure,
512 * the number of symbols, a range of symbols to print,
513 * an index which is the number of the
514 * section in the file, and the filename. The number of sections,
515 * the range, and the index are set in
516 * dump_symbol_table, depending on whether -n or -T were set.
517 */
518 static void
519 print_symtab(Elf *elf_file, SCNTAB *p_symtab, Elf_Data *sym_data,
520 long range, int index)
521 {
522 GElf_Sym sym;
523 int adj = 0; /* field adjustment for elf64 */
524 Elf32_Word *symshndx = 0;
525 unsigned int nosymshndx = 0;
526 Conv_inv_buf_t inv_buf;
527
528
529 if (gelf_getclass(elf_file) == ELFCLASS64)
530 adj = 8;
531
532 while (range > 0) {
533 char *sym_name = NULL;
534 int type, bind;
535 int specsec;
536 unsigned int shndx;
537
538 (void) gelf_getsym(sym_data, index, &sym);
539 type = (int)GELF_ST_TYPE(sym.st_info);
540 bind = (int)GELF_ST_BIND(sym.st_info);
541
542 if ((sym.st_shndx == SHN_XINDEX) &&
543 (symshndx == 0) && (nosymshndx == 0)) {
544 Elf_Scn *_scn;
545 GElf_Shdr _shdr;
546 size_t symscnndx;
547
548 symscnndx = elf_ndxscn(p_symtab->p_sd);
549 _scn = 0;
550 while ((_scn = elf_nextscn(elf_file, _scn)) != 0) {
551 if (gelf_getshdr(_scn, &_shdr) == 0)
552 break;
553 if ((_shdr.sh_type == SHT_SYMTAB_SHNDX) &&
|