/[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.265 Revision 1.266
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/Attic/scanelf.c,v 1.265 2014/03/21 05:33:33 vapier Exp $ 4 * $Header: /var/cvsroot/gentoo-projects/pax-utils/Attic/scanelf.c,v 1.266 2014/06/18 03:16:52 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.265 2014/03/21 05:33:33 vapier Exp $"; 10static const char rcsid[] = "$Id: scanelf.c,v 1.266 2014/06/18 03:16:52 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 == '+')
1193 * filters. There are groups of modifiers. If you don't specify a member 1193 * filters. There are groups of modifiers. If you don't specify a member
1194 * of a group, then all types in that group are matched. The current 1194 * of a group, then all types in that group are matched. The current
1195 * groups and their types are: 1195 * groups and their types are:
1196 * STT group: STT_NOTYPE:n STT_OBJECT:o STT_FUNC:f STT_FILE:F 1196 * STT group: STT_NOTYPE:n STT_OBJECT:o STT_FUNC:f STT_FILE:F
1197 * STB group: STB_LOCAL:l STB_GLOBAL:g STB_WEAK:w 1197 * STB group: STB_LOCAL:l STB_GLOBAL:g STB_WEAK:w
1198 * STV group: STV_DEFAULT:p STV_INTERNAL:i STV_HIDDEN:h STV_PROTECTED:P
1198 * SHN group: SHN_UNDEF:u SHN_ABS:a SHN_COMMON:c {defined}:d 1199 * SHN group: SHN_UNDEF:u SHN_ABS:a SHN_COMMON:c {defined}:d
1199 * The "defined" value in the SHN group does not correspond to a SHN_xxx define. 1200 * The "defined" value in the SHN group does not correspond to a SHN_xxx define.
1200 * You can search for multiple symbols at once by seperating with a comma (","). 1201 * You can search for multiple symbols at once by seperating with a comma (",").
1201 * 1202 *
1202 * Some examples: 1203 * Some examples:
1211 * All global defined objects in an ELF: 1212 * All global defined objects in an ELF:
1212 * scanelf -s %ogd% <ELF> 1213 * scanelf -s %ogd% <ELF>
1213 */ 1214 */
1214static void 1215static void
1215scanelf_match_symname(elfobj *elf, char *found_sym, char **ret, size_t *ret_len, const char *symname, 1216scanelf_match_symname(elfobj *elf, char *found_sym, char **ret, size_t *ret_len, const char *symname,
1216 unsigned int stt, unsigned int stb, unsigned int shn, unsigned long size) 1217 unsigned int stt, unsigned int stb, unsigned int stv, unsigned int shn, unsigned long size)
1217{ 1218{
1218 const char *this_sym; 1219 const char *this_sym;
1219 size_t n; 1220 size_t n;
1220 1221
1221 array_for_each(find_sym_arr, n, this_sym) { 1222 array_for_each(find_sym_arr, n, this_sym) {
1222 bool inc_notype, inc_object, inc_func, inc_file, 1223 bool inc_notype, inc_object, inc_func, inc_file,
1223 inc_local, inc_global, inc_weak, 1224 inc_local, inc_global, inc_weak,
1225 inc_visdef, inc_intern, inc_hidden, inc_prot,
1224 inc_def, inc_undef, inc_abs, inc_common; 1226 inc_def, inc_undef, inc_abs, inc_common;
1225 1227
1226 /* symbol selection! */ 1228 /* symbol selection! */
1227 inc_notype = inc_object = inc_func = inc_file = \ 1229 inc_notype = inc_object = inc_func = inc_file =
1228 inc_local = inc_global = inc_weak = \ 1230 inc_local = inc_global = inc_weak =
1231 inc_visdef = inc_intern = inc_hidden = inc_prot =
1229 inc_def = inc_undef = inc_abs = inc_common = \ 1232 inc_def = inc_undef = inc_abs = inc_common =
1230 (*this_sym != '%'); 1233 (*this_sym != '%');
1231 1234
1232 /* parse the contents of %...% */ 1235 /* parse the contents of %...% */
1233 if (!inc_notype) { 1236 if (!inc_notype) {
1234 while (*(this_sym++)) { 1237 while (*(this_sym++)) {
1242 case 'f': inc_func = true; break; 1245 case 'f': inc_func = true; break;
1243 case 'F': inc_file = true; break; 1246 case 'F': inc_file = true; break;
1244 case 'l': inc_local = true; break; 1247 case 'l': inc_local = true; break;
1245 case 'g': inc_global = true; break; 1248 case 'g': inc_global = true; break;
1246 case 'w': inc_weak = true; break; 1249 case 'w': inc_weak = true; break;
1250 case 'p': inc_visdef = true; break;
1251 case 'i': inc_intern = true; break;
1252 case 'h': inc_hidden = true; break;
1253 case 'P': inc_prot = true; break;
1247 case 'd': inc_def = true; break; 1254 case 'd': inc_def = true; break;
1248 case 'u': inc_undef = true; break; 1255 case 'u': inc_undef = true; break;
1249 case 'a': inc_abs = true; break; 1256 case 'a': inc_abs = true; break;
1250 case 'c': inc_common = true; break; 1257 case 'c': inc_common = true; break;
1251 default: err("invalid symbol selector '%c'", *this_sym); 1258 default: err("invalid symbol selector '%c'", *this_sym);
1255 /* If no types are matched, not match all */ 1262 /* If no types are matched, not match all */
1256 if (!inc_notype && !inc_object && !inc_func && !inc_file) 1263 if (!inc_notype && !inc_object && !inc_func && !inc_file)
1257 inc_notype = inc_object = inc_func = inc_file = true; 1264 inc_notype = inc_object = inc_func = inc_file = true;
1258 if (!inc_local && !inc_global && !inc_weak) 1265 if (!inc_local && !inc_global && !inc_weak)
1259 inc_local = inc_global = inc_weak = true; 1266 inc_local = inc_global = inc_weak = true;
1267 if (!inc_visdef && !inc_intern && !inc_hidden && !inc_prot)
1268 inc_visdef = inc_intern = inc_hidden = inc_prot = true;
1260 if (!inc_def && !inc_undef && !inc_abs && !inc_common) 1269 if (!inc_def && !inc_undef && !inc_abs && !inc_common)
1261 inc_def = inc_undef = inc_abs = inc_common = true; 1270 inc_def = inc_undef = inc_abs = inc_common = true;
1262 1271
1263 /* backwards compat for defined/undefined short hand */ 1272 /* backwards compat for defined/undefined short hand */
1264 } else if (*this_sym == '+') { 1273 } else if (*this_sym == '+') {
1268 inc_def = inc_abs = inc_common = false; 1277 inc_def = inc_abs = inc_common = false;
1269 ++this_sym; 1278 ++this_sym;
1270 } 1279 }
1271 1280
1272 /* filter symbols */ 1281 /* filter symbols */
1273 if ((!inc_notype && stt == STT_NOTYPE) || \ 1282 if ((!inc_notype && stt == STT_NOTYPE ) || \
1274 (!inc_object && stt == STT_OBJECT) || \ 1283 (!inc_object && stt == STT_OBJECT ) || \
1275 (!inc_func && stt == STT_FUNC ) || \ 1284 (!inc_func && stt == STT_FUNC ) || \
1276 (!inc_file && stt == STT_FILE ) || \ 1285 (!inc_file && stt == STT_FILE ) || \
1277 (!inc_local && stb == STB_LOCAL ) || \ 1286 (!inc_local && stb == STB_LOCAL ) || \
1278 (!inc_global && stb == STB_GLOBAL) || \ 1287 (!inc_global && stb == STB_GLOBAL ) || \
1279 (!inc_weak && stb == STB_WEAK ) || \ 1288 (!inc_weak && stb == STB_WEAK ) || \
1289 (!inc_visdef && stv == STV_DEFAULT ) || \
1290 (!inc_intern && stv == STV_INTERNAL ) || \
1291 (!inc_hidden && stv == STV_HIDDEN ) || \
1292 (!inc_prot && stv == STV_PROTECTED) || \
1280 (!inc_def && shn && shn < SHN_LORESERVE) || \ 1293 (!inc_def && shn && shn < SHN_LORESERVE) || \
1281 (!inc_undef && shn == SHN_UNDEF ) || \ 1294 (!inc_undef && shn == SHN_UNDEF ) || \
1282 (!inc_abs && shn == SHN_ABS ) || \ 1295 (!inc_abs && shn == SHN_ABS ) || \
1283 (!inc_common && shn == SHN_COMMON)) 1296 (!inc_common && shn == SHN_COMMON ))
1284 continue; 1297 continue;
1285 1298
1286 if (*this_sym == '*') { 1299 if (*this_sym == '*') {
1287 /* a "*" symbol gets you debug output */ 1300 /* a "*" symbol gets you debug output */
1288 printf("%s(%s) %5lX %15s %15s %15s %s\n", 1301 printf("%s(%s) %5lX %-15s %-15s %-15s %-15s %s\n",
1289 ((*found_sym == 0) ? "\n\t" : "\t"), 1302 ((*found_sym == 0) ? "\n\t" : "\t"),
1290 elf->base_filename, 1303 elf->base_filename,
1291 size, 1304 size,
1292 get_elfstttype(stt), 1305 get_elfstttype(stt),
1293 get_elfstbtype(stb), 1306 get_elfstbtype(stb),
1307 get_elfstvtype(stv),
1294 get_elfshntype(shn), 1308 get_elfshntype(shn),
1295 symname); 1309 symname);
1296 goto matched; 1310 goto matched;
1297 1311
1298 } else { 1312 } else {
1368 } \ 1382 } \
1369 scanelf_match_symname(elf, found_sym, \ 1383 scanelf_match_symname(elf, found_sym, \
1370 &ret, &ret_len, symname, \ 1384 &ret, &ret_len, symname, \
1371 ELF##B##_ST_TYPE(EGET(sym->st_info)), \ 1385 ELF##B##_ST_TYPE(EGET(sym->st_info)), \
1372 ELF##B##_ST_BIND(EGET(sym->st_info)), \ 1386 ELF##B##_ST_BIND(EGET(sym->st_info)), \
1387 ELF##B##_ST_VISIBILITY(EGET(sym->st_other)), \
1373 EGET(sym->st_shndx), \ 1388 EGET(sym->st_shndx), \
1374 /* st_size can be 64bit, but no one is really that big, so screw em */ \ 1389 /* st_size can be 64bit, but no one is really that big, so screw em */ \
1375 EGET(sym->st_size)); \ 1390 EGET(sym->st_size)); \
1376 } \ 1391 } \
1377 ++sym; \ 1392 ++sym; \

Legend:
Removed from v.1.265  
changed lines
  Added in v.1.266

  ViewVC Help
Powered by ViewVC 1.1.20