/[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.247 Revision 1.248
1/* 1/*
2 * Copyright 2003-2012 Gentoo Foundation 2 * Copyright 2003-2012 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.247 2012/11/04 07:26:24 vapier Exp $ 4 * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.248 2012/11/04 07:48:42 vapier Exp $
5 * 5 *
6 * Copyright 2003-2012 Ned Ludd - <solar@gentoo.org> 6 * Copyright 2003-2012 Ned Ludd - <solar@gentoo.org>
7 * Copyright 2004-2012 Mike Frysinger - <vapier@gentoo.org> 7 * Copyright 2004-2012 Mike Frysinger - <vapier@gentoo.org>
8 */ 8 */
9 9
10static const char rcsid[] = "$Id: scanelf.c,v 1.247 2012/11/04 07:26:24 vapier Exp $"; 10static const char rcsid[] = "$Id: scanelf.c,v 1.248 2012/11/04 07:48:42 vapier Exp $";
11const char argv0[] = "scanelf"; 11const char 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 == '+')
44static char be_quiet = 0; 44static char be_quiet = 0;
45static char be_verbose = 0; 45static char be_verbose = 0;
46static char be_wewy_wewy_quiet = 0; 46static char be_wewy_wewy_quiet = 0;
47static char be_semi_verbose = 0; 47static char be_semi_verbose = 0;
48static char *find_sym = NULL; 48static char *find_sym = NULL;
49static array_t _find_sym_arr = array_init_decl, *find_sym_arr = &_find_sym_arr;
49static char *find_lib = NULL; 50static char *find_lib = NULL;
50static array_t _find_lib_arr = array_init_decl, *find_lib_arr = &_find_lib_arr; 51static array_t _find_lib_arr = array_init_decl, *find_lib_arr = &_find_lib_arr;
51static char *find_section = NULL; 52static char *find_section = NULL;
52static array_t _find_section_arr = array_init_decl, *find_section_arr = &_find_section_arr; 53static array_t _find_section_arr = array_init_decl, *find_section_arr = &_find_section_arr;
53static char *out_format = NULL; 54static char *out_format = NULL;
1171 */ 1172 */
1172static void 1173static void
1173scanelf_match_symname(elfobj *elf, char *found_sym, char **ret, size_t *ret_len, const char *symname, 1174scanelf_match_symname(elfobj *elf, char *found_sym, char **ret, size_t *ret_len, const char *symname,
1174 unsigned int stt, unsigned int stb, unsigned int shn, unsigned long size) 1175 unsigned int stt, unsigned int stb, unsigned int shn, unsigned long size)
1175{ 1176{
1176 char *this_sym, *next_sym, saved = saved; 1177 const char *this_sym;
1178 size_t n;
1177 1179
1178 /* allow the user to specify a comma delimited list of symbols to search for */ 1180 array_for_each(find_sym_arr, n, this_sym) {
1179 next_sym = NULL;
1180 do {
1181 bool inc_notype, inc_object, inc_func, inc_file, 1181 bool inc_notype, inc_object, inc_func, inc_file,
1182 inc_local, inc_global, inc_weak, 1182 inc_local, inc_global, inc_weak,
1183 inc_def, inc_undef, inc_abs, inc_common; 1183 inc_def, inc_undef, inc_abs, inc_common;
1184
1185 if (next_sym) {
1186 next_sym[-1] = saved;
1187 this_sym = next_sym;
1188 } else
1189 this_sym = find_sym;
1190 if ((next_sym = strchr(this_sym, ','))) {
1191 /* make parsing easier by killing the comma temporarily */
1192 saved = *next_sym;
1193 *next_sym = '\0';
1194 next_sym += 1;
1195 }
1196 1184
1197 /* symbol selection! */ 1185 /* symbol selection! */
1198 inc_notype = inc_object = inc_func = inc_file = \ 1186 inc_notype = inc_object = inc_func = inc_file = \
1199 inc_local = inc_global = inc_weak = \ 1187 inc_local = inc_global = inc_weak = \
1200 inc_def = inc_undef = inc_abs = inc_common = \ 1188 inc_def = inc_undef = inc_abs = inc_common = \
1296 xstrcat(ret, symname, ret_len); 1284 xstrcat(ret, symname, ret_len);
1297 } 1285 }
1298 1286
1299 goto matched; 1287 goto matched;
1300 } 1288 }
1301 } while (next_sym); 1289 }
1302 1290
1303 return; 1291 return;
1304 1292
1305 matched: 1293 matched:
1306 *found_sym = 1; 1294 *found_sym = 1;
1307 if (next_sym)
1308 next_sym[-1] = saved;
1309} 1295}
1310 1296
1311static const char *scanelf_file_sym(elfobj *elf, char *found_sym) 1297static const char *scanelf_file_sym(elfobj *elf, char *found_sym)
1312{ 1298{
1313 char *ret; 1299 char *ret;
2130 } 2116 }
2131 case 'k': 2117 case 'k':
2132 xarraypush_str(find_section_arr, optarg); 2118 xarraypush_str(find_section_arr, optarg);
2133 break; 2119 break;
2134 case 's': { 2120 case 's': {
2135 if (find_sym) warn("You prob don't want to specify -s twice"); 2121 /* historically, this was comma delimited */
2136 find_sym = optarg; 2122 char *this_sym = strtok(optarg, ",");
2123 while (this_sym) {
2124 xarraypush_str(find_sym_arr, this_sym);
2125 this_sym = strtok(NULL, ",");
2126 }
2137 break; 2127 break;
2138 } 2128 }
2139 case 'N': 2129 case 'N':
2140 xarraypush_str(find_lib_arr, optarg); 2130 xarraypush_str(find_lib_arr, optarg);
2141 break; 2131 break;
2229 } 2219 }
2230 } 2220 }
2231 if (show_textrels && be_verbose) 2221 if (show_textrels && be_verbose)
2232 has_objdump = bin_in_path("objdump"); 2222 has_objdump = bin_in_path("objdump");
2233 /* flatten arrays for display */ 2223 /* flatten arrays for display */
2224 if (array_cnt(find_sym_arr))
2225 find_sym = array_flatten_str(find_sym_arr);
2234 if (array_cnt(find_lib_arr)) 2226 if (array_cnt(find_lib_arr))
2235 find_lib = array_flatten_str(find_lib_arr); 2227 find_lib = array_flatten_str(find_lib_arr);
2236 if (array_cnt(find_section_arr)) 2228 if (array_cnt(find_section_arr))
2237 find_section = array_flatten_str(find_section_arr); 2229 find_section = array_flatten_str(find_section_arr);
2238 /* let the format option override all other options */ 2230 /* let the format option override all other options */
2322 ret = scanelf_dir(search_path); 2314 ret = scanelf_dir(search_path);
2323 } 2315 }
2324 2316
2325 /* clean up */ 2317 /* clean up */
2326 xarrayfree(ldpaths); 2318 xarrayfree(ldpaths);
2319 xarrayfree(find_sym_arr);
2327 xarrayfree(find_lib_arr); 2320 xarrayfree(find_lib_arr);
2328 xarrayfree(find_section_arr); 2321 xarrayfree(find_section_arr);
2322 free(find_sym);
2329 free(find_lib); 2323 free(find_lib);
2330 free(find_section); 2324 free(find_section);
2331 2325
2332 if (ldcache != 0) 2326 if (ldcache != 0)
2333 munmap(ldcache, ldcache_size); 2327 munmap(ldcache, ldcache_size);

Legend:
Removed from v.1.247  
changed lines
  Added in v.1.248

  ViewVC Help
Powered by ViewVC 1.1.20