Print this page
libconv


   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 1988 AT&T
  24  * Copyright (c) 1989 AT&T
  25  * All Rights Reserved
  26  *
  27  * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.

  28  */
  29 
  30 #include <stdio.h>
  31 #include <stdlib.h>
  32 #include <unistd.h>
  33 #include <ctype.h>
  34 #include <locale.h>
  35 #include <libelf.h>
  36 #include <sys/elf_SPARC.h>
  37 
  38 
  39 /* exit return codes */
  40 #define NOARGS  1
  41 #define BADELF  2
  42 #define NOALLOC 3
  43 
  44 #include <fcntl.h>
  45 #include <sys/stat.h>
  46 #include <errno.h>
  47 #include <string.h>


 788         Elf32_Word      *symshndx = 0;
 789         unsigned int    nosymshndx = 0;
 790         int             i;
 791 
 792         if ((buf = calloc(num, sizeof (SYM))) == NULL) {
 793                 (void) fprintf(stderr, gettext("%s: cannot allocate memory\n"),
 794                     prog_name);
 795                 return (NULL);
 796         }
 797 
 798         s = buf;        /* save pointer to head of array */
 799 
 800         for (i = 1; i < num; i++, buf++) {
 801                 (void) gelf_getsym(data, i, &sym);
 802 
 803                 buf->indx = i;
 804                 /* allow to work on machines where NULL-derefs dump core */
 805                 if (sym.st_name == 0)
 806                         buf->name = "";
 807                 else if (C_flag) {
 808                         const char *dn;
 809                         char *name = (char *)elf_strptr(elf, link, sym.st_name);

 810                         dn = conv_demangle_name(name);
 811                         if (strcmp(dn, name) == 0) {    /* Not demangled */
 812                                 if (exotic(name)) {


 813                                         name = FormatName(name, d_buf);
 814                                 }
 815                         } else {  /* name demangled */
 816                                 name = FormatName(name, dn);
 817                         }
 818                         buf->name = name;
 819                 }
 820                 else
 821                         buf->name = (char *)elf_strptr(elf, link, sym.st_name);
 822 
 823                 buf->value   = sym.st_value;
 824                 buf->size    = sym.st_size;
 825                 buf->type    = GELF_ST_TYPE(sym.st_info);
 826                 buf->bind    = GELF_ST_BIND(sym.st_info);
 827                 buf->other   = sym.st_other;
 828                 if ((sym.st_shndx == SHN_XINDEX) &&
 829                     (symshndx == 0) && (nosymshndx == 0)) {
 830                         Elf_Scn         *_scn;
 831                         GElf_Shdr       _shdr;
 832                         _scn = 0;
 833                         while ((_scn = elf_nextscn(elf, _scn)) != 0) {
 834                                 if (gelf_getshdr(_scn, &_shdr) == 0)
 835                                         break;
 836                                 if ((_shdr.sh_type == SHT_SYMTAB_SHNDX) &&
 837                                     (_shdr.sh_link == symscnndx)) {




   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 1988 AT&T
  24  * Copyright (c) 1989 AT&T
  25  * All Rights Reserved
  26  *
  27  * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
  28  * Copyright 2018 Jason King
  29  */
  30 
  31 #include <stdio.h>
  32 #include <stdlib.h>
  33 #include <unistd.h>
  34 #include <ctype.h>
  35 #include <locale.h>
  36 #include <libelf.h>
  37 #include <sys/elf_SPARC.h>
  38 
  39 
  40 /* exit return codes */
  41 #define NOARGS  1
  42 #define BADELF  2
  43 #define NOALLOC 3
  44 
  45 #include <fcntl.h>
  46 #include <sys/stat.h>
  47 #include <errno.h>
  48 #include <string.h>


 789         Elf32_Word      *symshndx = 0;
 790         unsigned int    nosymshndx = 0;
 791         int             i;
 792 
 793         if ((buf = calloc(num, sizeof (SYM))) == NULL) {
 794                 (void) fprintf(stderr, gettext("%s: cannot allocate memory\n"),
 795                     prog_name);
 796                 return (NULL);
 797         }
 798 
 799         s = buf;        /* save pointer to head of array */
 800 
 801         for (i = 1; i < num; i++, buf++) {
 802                 (void) gelf_getsym(data, i, &sym);
 803 
 804                 buf->indx = i;
 805                 /* allow to work on machines where NULL-derefs dump core */
 806                 if (sym.st_name == 0)
 807                         buf->name = "";
 808                 else if (C_flag) {
 809                         const char *dn = NULL;
 810                         char *name = (char *)elf_strptr(elf, link, sym.st_name);
 811 
 812                         dn = conv_demangle_name(name);
 813                         if (dn != name) {
 814                                 name = FormatName(name, dn);
 815                                 free((void *)dn);
 816                         } else if (exotic(name)) {
 817                                 name = FormatName(name, d_buf);
 818                         }



 819                         buf->name = name;
 820                 }
 821                 else
 822                         buf->name = (char *)elf_strptr(elf, link, sym.st_name);
 823 
 824                 buf->value   = sym.st_value;
 825                 buf->size    = sym.st_size;
 826                 buf->type    = GELF_ST_TYPE(sym.st_info);
 827                 buf->bind    = GELF_ST_BIND(sym.st_info);
 828                 buf->other   = sym.st_other;
 829                 if ((sym.st_shndx == SHN_XINDEX) &&
 830                     (symshndx == 0) && (nosymshndx == 0)) {
 831                         Elf_Scn         *_scn;
 832                         GElf_Shdr       _shdr;
 833                         _scn = 0;
 834                         while ((_scn = elf_nextscn(elf, _scn)) != 0) {
 835                                 if (gelf_getshdr(_scn, &_shdr) == 0)
 836                                         break;
 837                                 if ((_shdr.sh_type == SHT_SYMTAB_SHNDX) &&
 838                                     (_shdr.sh_link == symscnndx)) {