/[gentoo-projects]/pax-utils/scanelf.c
Gentoo

Diff of /pax-utils/scanelf.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.196 Revision 1.197
1/* 1/*
2 * Copyright 2003-2007 Gentoo Foundation 2 * Copyright 2003-2007 Gentoo Foundation
3 * Distributed under the terms of the GNU General Public License v2 3 * Distributed under the terms of the GNU General Public License v2
4 * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.196 2008/10/22 17:03:17 flameeyes Exp $ 4 * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.197 2008/11/17 18:03:38 flameeyes Exp $
5 * 5 *
6 * Copyright 2003-2007 Ned Ludd - <solar@gentoo.org> 6 * Copyright 2003-2007 Ned Ludd - <solar@gentoo.org>
7 * Copyright 2004-2007 Mike Frysinger - <vapier@gentoo.org> 7 * Copyright 2004-2007 Mike Frysinger - <vapier@gentoo.org>
8 */ 8 */
9 9
10static const char *rcsid = "$Id: scanelf.c,v 1.196 2008/10/22 17:03:17 flameeyes Exp $"; 10static const char *rcsid = "$Id: scanelf.c,v 1.197 2008/11/17 18:03:38 flameeyes Exp $";
11const char * const argv0 = "scanelf"; 11const char * const argv0 = "scanelf";
12 12
13#include "paxinc.h" 13#include "paxinc.h"
14 14
15#define IS_MODIFIER(c) (c == '%' || c == '#' || c == '+') 15#define IS_MODIFIER(c) (c == '%' || c == '#' || c == '+')
975 } 975 }
976 976
977 return NULL; 977 return NULL;
978} 978}
979 979
980static int scanelf_match_symname(const char *compare, const char *symname, const char *symname_ver) {
981 /* We do things differently when checking with regexp */
982 if (g_match) {
983 return rematch(symname, compare, REG_EXTENDED) == 0 ||
984 rematch(symname_ver, compare, REG_EXTENDED) == 0;
985 } else {
986 const size_t symname_len = strlen(symname);
987 if (strncmp(symname, compare, symname_len) == 0 &&
988 /* Accept unversioned symbol names */
989 (compare[symname_len] == '\0' || compare[symname_len] == '@'))
990 return 1;
991
992 return strcmp(symname_ver, symname) == 0;
993 }
994}
995
980static char *scanelf_file_sym(elfobj *elf, char *found_sym) 996static char *scanelf_file_sym(elfobj *elf, char *found_sym)
981{ 997{
982 unsigned long i; 998 unsigned long i;
983 char *ret; 999 char *ret;
984 void *symtab_void, *strtab_void; 1000 void *symtab_void, *strtab_void;
1010 warnf("%s: corrupt ELF symbols", elf->filename); \ 1026 warnf("%s: corrupt ELF symbols", elf->filename); \
1011 ++sym; \ 1027 ++sym; \
1012 continue; \ 1028 continue; \
1013 } \ 1029 } \
1014 /* debug display ... show all symbols and some extra info */ \ 1030 /* debug display ... show all symbols and some extra info */ \
1015 if (g_match ? rematch(ret, symname, REG_EXTENDED) == 0 : *ret == '*') { \ 1031 if (0 && g_match ? rematch(ret, symname, REG_EXTENDED) == 0 : *ret == '*') { \
1016 printf("%s(%s) %5lX %15s %s %s\n", \ 1032 printf("%s(%s) %5lX %15s %s %s\n", \
1017 ((*found_sym == 0) ? "\n\t" : "\t"), \ 1033 ((*found_sym == 0) ? "\n\t" : "\t"), \
1018 elf->base_filename, \ 1034 elf->base_filename, \
1019 (unsigned long)sym->st_size, \ 1035 (unsigned long)sym->st_size, \
1020 get_elfstttype(sym->st_info), \ 1036 get_elfstttype(sym->st_info), \
1021 sym->st_shndx == SHN_UNDEF ? "U" : "D", symname); \ 1037 sym->st_shndx == SHN_UNDEF ? "U" : "D", symname); \
1022 *found_sym = 1; \ 1038 *found_sym = 1; \
1023 } else { \ 1039 } else { \
1024 /* allow the user to specify a comma delimited list of symbols to search for */ \ 1040 /* allow the user to specify a comma delimited list of symbols to search for */ \
1025 char *this_sym, *this_sym_ver, *next_sym; \ 1041 char *this_sym, *this_sym_ver, *next_sym; \
1026 this_sym = ret; \ 1042 next_sym = ret; \
1027 this_sym_ver = versioned_symname; \ 1043 this_sym_ver = versioned_symname; \
1028 do { \ 1044 while (next_sym) { \
1045 this_sym = next_sym; \
1029 next_sym = strchr(this_sym, ','); \ 1046 if ((next_sym = strchr(this_sym, ','))) \
1030 if (next_sym == NULL) \ 1047 next_sym += 1; /* Skip the comma */ \
1031 next_sym = this_sym + strlen(this_sym); \
1032 /* do we want a defined symbol ? */ \ 1048 /* do we want a defined symbol ? */ \
1033 if (*this_sym == '+') { \ 1049 if (*this_sym == '+') { \
1034 if (sym->st_shndx == SHN_UNDEF) \ 1050 if (sym->st_shndx == SHN_UNDEF) \
1035 goto skip_this_sym##B; \ 1051 continue; \
1036 ++this_sym; \ 1052 ++this_sym; \
1037 ++this_sym_ver; \ 1053 ++this_sym_ver; \
1038 /* do we want an undefined symbol ? */ \ 1054 /* do we want an undefined symbol ? */ \
1039 } else if (*this_sym == '-') { \ 1055 } else if (*this_sym == '-') { \
1040 if (sym->st_shndx != SHN_UNDEF) \ 1056 if (sym->st_shndx != SHN_UNDEF) \
1041 goto skip_this_sym##B; \ 1057 continue; \
1042 ++this_sym; \ 1058 ++this_sym; \
1043 ++this_sym_ver; \ 1059 ++this_sym_ver; \
1044 } \ 1060 } \
1061 if (next_sym) /* Copy it so that we don't have to worry about the final , */ \
1062 this_sym = strndup(this_sym, next_sym-this_sym); \
1045 /* ok, lets compare the name now */ \ 1063 /* ok, lets compare the name now */ \
1046 if ((strncmp(this_sym, symname, (next_sym-this_sym)) == 0 && symname[next_sym-this_sym] == '\0') || \ 1064 if (scanelf_match_symname(symname, this_sym, this_sym_ver)) { \
1047 (strncmp(this_sym_ver, symname, strlen(this_sym_ver)) == 0)) { \
1048 if (be_semi_verbose) { \ 1065 if (be_semi_verbose) { \
1049 char buf[126]; \ 1066 char buf[126]; \
1050 snprintf(buf, sizeof(buf), "%lX %s %s", \ 1067 snprintf(buf, sizeof(buf), "%lX %s %s", \
1051 (unsigned long)sym->st_size, get_elfstttype(sym->st_info), this_sym); \ 1068 (unsigned long)sym->st_size, get_elfstttype(sym->st_info), this_sym); \
1052 ret = buf; \ 1069 ret = buf; \
1053 } else \ 1070 } else \
1054 ret = this_sym; \ 1071 ret = symname; \
1055 (*found_sym)++; \ 1072 (*found_sym)++; \
1056 goto break_out; \ 1073 goto break_out; \
1057 } \ 1074 } \
1058 skip_this_sym##B: this_sym = next_sym + 1; \ 1075 if (next_sym) free(this_sym); \
1059 } while (*next_sym != '\0'); \ 1076 } \
1060 } \ 1077 } \
1061 } \ 1078 } \
1062 ++sym; \ 1079 ++sym; \
1063 } } 1080 } }
1064 FIND_SYM(32) 1081 FIND_SYM(32)

Legend:
Removed from v.1.196  
changed lines
  Added in v.1.197

  ViewVC Help
Powered by ViewVC 1.1.20