Print this page
10812 ctf tools shouldn't add blank labels
10813 ctf symbol mapping needs work
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libctf/common/ctf_lib.c
          +++ new/usr/src/lib/libctf/common/ctf_lib.c
↓ open down ↓ 16 lines elided ↑ open up ↑
  17   17   * fields enclosed by brackets "[]" replaced with your own identifying
  18   18   * information: Portions Copyright [yyyy] [name of copyright owner]
  19   19   *
  20   20   * CDDL HEADER END
  21   21   */
  22   22  /*
  23   23   * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
  24   24   * Use is subject to license terms.
  25   25   */
  26   26  /*
  27      - * Copyright (c) 2015, Joyent, Inc.
       27 + * Copyright (c) 2019, Joyent, Inc.
  28   28   */
  29   29  
  30   30  #include <sys/types.h>
  31   31  #include <sys/stat.h>
  32   32  #include <sys/mman.h>
  33      -#include <ctf_impl.h>
       33 +#include <libctf_impl.h>
  34   34  #include <unistd.h>
  35   35  #include <fcntl.h>
  36   36  #include <errno.h>
  37   37  #include <dlfcn.h>
  38   38  #include <gelf.h>
  39   39  #include <zlib.h>
  40   40  #include <sys/debug.h>
  41   41  
  42   42  #ifdef _LP64
  43   43  static const char *_libctf_zlib = "/usr/lib/64/libz.so.1";
↓ open down ↓ 696 lines elided ↑ open up ↑
 740  740                  _libctf_version = version;
 741  741          }
 742  742  
 743  743          return (_libctf_version);
 744  744  }
 745  745  
 746  746  /*
 747  747   * A utility function for folks debugging CTF conversion and merging.
 748  748   */
 749  749  void
 750      -ctf_phase_dump(ctf_file_t *fp, const char *phase)
      750 +ctf_phase_dump(ctf_file_t *fp, const char *phase, const char *name)
 751  751  {
 752  752          int fd;
 753  753          static char *base;
 754  754          char path[MAXPATHLEN];
 755  755  
 756  756          if (base == NULL && (base = getenv("LIBCTF_WRITE_PHASES")) == NULL)
 757  757                  return;
 758  758  
 759      -        (void) snprintf(path, sizeof (path), "%s/libctf.%s.%d.ctf", base,
      759 +        if (name == NULL)
      760 +                name = "libctf";
      761 +
      762 +        (void) snprintf(path, sizeof (path), "%s/%s.%s.%d.ctf", base, name,
 760  763              phase != NULL ? phase : "",
 761  764              ctf_phase);
 762  765          if ((fd = open(path, O_CREAT | O_TRUNC | O_RDWR, 0777)) < 0)
 763  766                  return;
 764  767          (void) ctf_write(fp, fd);
 765  768          (void) close(fd);
      769 +}
      770 +
      771 +void
      772 +ctf_phase_bump(void)
      773 +{
      774 +        ctf_phase++;
      775 +}
      776 +
      777 +int
      778 +ctf_symtab_iter(ctf_file_t *fp, ctf_symtab_f func, void *arg)
      779 +{
      780 +        ulong_t i;
      781 +        uintptr_t symbase;
      782 +        uintptr_t strbase;
      783 +        const char *file = NULL;
      784 +        boolean_t primary = B_TRUE;
      785 +
      786 +        if (fp->ctf_symtab.cts_data == NULL ||
      787 +            fp->ctf_strtab.cts_data == NULL) {
      788 +                return (ECTF_NOSYMTAB);
      789 +        }
      790 +
      791 +        symbase = (uintptr_t)fp->ctf_symtab.cts_data;
      792 +        strbase = (uintptr_t)fp->ctf_strtab.cts_data;
      793 +
      794 +        for (i = 0; i < fp->ctf_nsyms; i++) {
      795 +                const char *name;
      796 +                int ret;
      797 +                uint_t type;
      798 +                Elf64_Sym sym;
      799 +
      800 +                /*
      801 +                 * The CTF library has historically tried to handle large file
      802 +                 * offsets itself so that way clients can be unaware of such
      803 +                 * isseus. Therefore, we translate everything to a 64-bit ELF
      804 +                 * symbol, this is done to make it so that the rest of the
      805 +                 * library doesn't have to know about these differences. For
      806 +                 * more information see, lib/libctf/common/ctf_lib.c.
      807 +                 */
      808 +                if (fp->ctf_symtab.cts_entsize == sizeof (Elf32_Sym)) {
      809 +                        const Elf32_Sym *symp = (Elf32_Sym *)symbase + i;
      810 +                        uint_t bind, itype;
      811 +
      812 +                        sym.st_name = symp->st_name;
      813 +                        sym.st_value = symp->st_value;
      814 +                        sym.st_size = symp->st_size;
      815 +                        bind = ELF32_ST_BIND(symp->st_info);
      816 +                        itype = ELF32_ST_TYPE(symp->st_info);
      817 +                        sym.st_info = ELF64_ST_INFO(bind, itype);
      818 +                        sym.st_other = symp->st_other;
      819 +                        sym.st_shndx = symp->st_shndx;
      820 +                } else {
      821 +                        const Elf64_Sym *symp = (Elf64_Sym *)symbase + i;
      822 +
      823 +                        sym = *symp;
      824 +                }
      825 +
      826 +                type = ELF64_ST_TYPE(sym.st_info);
      827 +                name = (const char *)(strbase + sym.st_name);
      828 +
      829 +                /*
      830 +                 * Check first if we have an STT_FILE entry. This is used to
      831 +                 * distinguish between various local symbols when merging.
      832 +                 */
      833 +                if (type == STT_FILE) {
      834 +                        if (file != NULL) {
      835 +                                primary = B_FALSE;
      836 +                        }
      837 +                        file = name;
      838 +                        continue;
      839 +                }
      840 +
      841 +                /*
      842 +                 * Check if this is a symbol that we care about.
      843 +                 */
      844 +                if (!ctf_sym_valid(strbase, type, sym.st_shndx, sym.st_value,
      845 +                    sym.st_name)) {
      846 +                        continue;
      847 +                }
      848 +
      849 +                if ((ret = func(&sym, i, file, name, primary, arg)) != 0) {
      850 +                        return (ret);
      851 +                }
      852 +        }
      853 +
      854 +        return (0);
 766  855  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX