/[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.197 Revision 1.198
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.197 2008/11/17 18:03:38 flameeyes Exp $ 4 * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.198 2008/11/17 18:09:55 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.197 2008/11/17 18:03:38 flameeyes Exp $"; 10static const char *rcsid = "$Id: scanelf.c,v 1.198 2008/11/17 18:09:55 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 == '+')
55static char show_eabi = 0; 55static char show_eabi = 0;
56static char be_quiet = 0; 56static char be_quiet = 0;
57static char be_verbose = 0; 57static char be_verbose = 0;
58static char be_wewy_wewy_quiet = 0; 58static char be_wewy_wewy_quiet = 0;
59static char be_semi_verbose = 0; 59static char be_semi_verbose = 0;
60static char *find_sym = NULL, *versioned_symname = NULL; 60static char *find_sym = NULL;
61static char *find_lib = NULL; 61static char *find_lib = NULL;
62static char *find_section = NULL; 62static char *find_section = NULL;
63static char *out_format = NULL; 63static char *out_format = NULL;
64static char *search_path = NULL; 64static char *search_path = NULL;
65static char fix_elf = 0; 65static char fix_elf = 0;
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) { 980static int scanelf_match_symname(const char *symname, const char *tomatch) {
981 /* We do things differently when checking with regexp */ 981 /* We do things differently when checking with regexp */
982 if (g_match) { 982 if (g_match) {
983 return rematch(symname, compare, REG_EXTENDED) == 0 || 983 return rematch(symname, tomatch, REG_EXTENDED) == 0;
984 rematch(symname_ver, compare, REG_EXTENDED) == 0;
985 } else { 984 } else {
986 const size_t symname_len = strlen(symname); 985 const size_t symname_len = strlen(symname);
987 if (strncmp(symname, compare, symname_len) == 0 && 986 return (strncmp(symname, tomatch, symname_len) == 0 &&
988 /* Accept unversioned symbol names */ 987 /* Accept unversioned symbol names */
989 (compare[symname_len] == '\0' || compare[symname_len] == '@')) 988 (tomatch[symname_len] == '\0' || tomatch[symname_len] == '@'));
990 return 1;
991
992 return strcmp(symname_ver, symname) == 0;
993 } 989 }
994} 990}
995 991
996static char *scanelf_file_sym(elfobj *elf, char *found_sym) 992static char *scanelf_file_sym(elfobj *elf, char *found_sym)
997{ 993{
1036 get_elfstttype(sym->st_info), \ 1032 get_elfstttype(sym->st_info), \
1037 sym->st_shndx == SHN_UNDEF ? "U" : "D", symname); \ 1033 sym->st_shndx == SHN_UNDEF ? "U" : "D", symname); \
1038 *found_sym = 1; \ 1034 *found_sym = 1; \
1039 } else { \ 1035 } else { \
1040 /* allow the user to specify a comma delimited list of symbols to search for */ \ 1036 /* allow the user to specify a comma delimited list of symbols to search for */ \
1041 char *this_sym, *this_sym_ver, *next_sym; \ 1037 char *this_sym, *next_sym; \
1042 next_sym = ret; \ 1038 next_sym = ret; \
1043 this_sym_ver = versioned_symname; \
1044 while (next_sym) { \ 1039 while (next_sym) { \
1045 this_sym = next_sym; \ 1040 this_sym = next_sym; \
1046 if ((next_sym = strchr(this_sym, ','))) \ 1041 if ((next_sym = strchr(this_sym, ','))) \
1047 next_sym += 1; /* Skip the comma */ \ 1042 next_sym += 1; /* Skip the comma */ \
1048 /* do we want a defined symbol ? */ \ 1043 /* do we want a defined symbol ? */ \
1049 if (*this_sym == '+') { \ 1044 if (*this_sym == '+') { \
1050 if (sym->st_shndx == SHN_UNDEF) \ 1045 if (sym->st_shndx == SHN_UNDEF) \
1051 continue; \ 1046 continue; \
1052 ++this_sym; \ 1047 ++this_sym; \
1053 ++this_sym_ver; \
1054 /* do we want an undefined symbol ? */ \ 1048 /* do we want an undefined symbol ? */ \
1055 } else if (*this_sym == '-') { \ 1049 } else if (*this_sym == '-') { \
1056 if (sym->st_shndx != SHN_UNDEF) \ 1050 if (sym->st_shndx != SHN_UNDEF) \
1057 continue; \ 1051 continue; \
1058 ++this_sym; \ 1052 ++this_sym; \
1059 ++this_sym_ver; \
1060 } \ 1053 } \
1061 if (next_sym) /* Copy it so that we don't have to worry about the final , */ \ 1054 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); \ 1055 this_sym = strndup(this_sym, next_sym-this_sym); \
1063 /* ok, lets compare the name now */ \ 1056 /* ok, lets compare the name now */ \
1064 if (scanelf_match_symname(symname, this_sym, this_sym_ver)) { \ 1057 if (scanelf_match_symname(this_sym, symname)) { \
1065 if (be_semi_verbose) { \ 1058 if (be_semi_verbose) { \
1066 char buf[126]; \ 1059 char buf[126]; \
1067 snprintf(buf, sizeof(buf), "%lX %s %s", \ 1060 snprintf(buf, sizeof(buf), "%lX %s %s", \
1068 (unsigned long)sym->st_size, get_elfstttype(sym->st_info), this_sym); \ 1061 (unsigned long)sym->st_size, get_elfstttype(sym->st_info), this_sym); \
1069 ret = buf; \ 1062 ret = buf; \
1783 find_section = optarg; 1776 find_section = optarg;
1784 break; 1777 break;
1785 case 's': { 1778 case 's': {
1786 if (find_sym) warn("You prob don't want to specify -s twice"); 1779 if (find_sym) warn("You prob don't want to specify -s twice");
1787 find_sym = optarg; 1780 find_sym = optarg;
1788 versioned_symname = xmalloc(sizeof(char) * (strlen(find_sym)+1+1));
1789 sprintf(versioned_symname, "%s@", find_sym);
1790 break; 1781 break;
1791 } 1782 }
1792 case 'N': { 1783 case 'N': {
1793 if (find_lib) warn("You prob don't want to specify -N twice"); 1784 if (find_lib) warn("You prob don't want to specify -N twice");
1794 find_lib = optarg; 1785 find_lib = optarg;
1967 search_path = argv[optind++]; 1958 search_path = argv[optind++];
1968 ret = scanelf_dir(search_path); 1959 ret = scanelf_dir(search_path);
1969 } 1960 }
1970 1961
1971 /* clean up */ 1962 /* clean up */
1972 free(versioned_symname);
1973 for (i = 0; ldpaths[i]; ++i) 1963 for (i = 0; ldpaths[i]; ++i)
1974 free(ldpaths[i]); 1964 free(ldpaths[i]);
1975 1965
1976 if (ldcache != 0) 1966 if (ldcache != 0)
1977 munmap(ldcache, ldcache_size); 1967 munmap(ldcache, ldcache_size);

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

  ViewVC Help
Powered by ViewVC 1.1.20