/[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.27 Revision 1.28
1/* 1/*
2 * Copyright 2003 Ned Ludd <solar@gentoo.org> 2 * Copyright 2003 Ned Ludd <solar@gentoo.org>
3 * Copyright 1999-2005 Gentoo Foundation 3 * Copyright 1999-2005 Gentoo Foundation
4 * Distributed under the terms of the GNU General Public License v2 4 * Distributed under the terms of the GNU General Public License v2
5 * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.27 2005/04/05 01:44:08 vapier Exp $ 5 * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.28 2005/04/05 03:41:27 solar Exp $
6 * 6 *
7 ******************************************************************** 7 ********************************************************************
8 * This program is free software; you can redistribute it and/or 8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as 9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of the 10 * published by the Free Software Foundation; either version 2 of the
22 */ 22 */
23 23
24#include <stdio.h> 24#include <stdio.h>
25#include <stdlib.h> 25#include <stdlib.h>
26#include <sys/types.h> 26#include <sys/types.h>
27#define __USE_GNU
27#include <string.h> 28#include <string.h>
28#include <errno.h> 29#include <errno.h>
29#include <unistd.h> 30#include <unistd.h>
30#include <sys/stat.h> 31#include <sys/stat.h>
31#include <dirent.h> 32#include <dirent.h>
32#include <getopt.h> 33#include <getopt.h>
33#include <assert.h> 34#include <assert.h>
34 35
35#include "paxelf.h" 36#include "paxelf.h"
36 37
37static const char *rcsid = "$Id: scanelf.c,v 1.27 2005/04/05 01:44:08 vapier Exp $"; 38static const char *rcsid = "$Id: scanelf.c,v 1.28 2005/04/05 03:41:27 solar Exp $";
38 39
39 40
40/* helper functions for showing errors */ 41/* helper functions for showing errors */
41#define argv0 "scanelf" /*((*argv != NULL) ? argv[0] : __FILE__ "\b\b")*/ 42#define argv0 "scanelf" /*((*argv != NULL) ? argv[0] : __FILE__ "\b\b")*/
42#define warn(fmt, args...) \ 43#define warn(fmt, args...) \
209 printf("%-5s ", (runpath ? runpath : rpath)); 210 printf("%-5s ", (runpath ? runpath : rpath));
210 else if (!be_quiet && !found_rpath) 211 else if (!be_quiet && !found_rpath)
211 printf(" - "); 212 printf(" - ");
212 } 213 }
213 214
214 if (!be_quiet || found_pax || found_stack || found_textrel || found_rpath)
215 printf("%s\n", filename);
216
217 if (find_sym) { 215 if (find_sym) {
218 void *symtab_void, *strtab_void; 216 void *symtab_void, *strtab_void;
217 char found_sym = 0;
218 char *versioned_symname = malloc(strlen(find_sym)+1);
219
220 sprintf(versioned_symname, "%s@", find_sym);
219 symtab_void = elf_findsecbyname(elf, ".symtab"); 221 symtab_void = elf_findsecbyname(elf, ".symtab");
220 strtab_void = elf_findsecbyname(elf, ".strtab"); 222 strtab_void = elf_findsecbyname(elf, ".strtab");
221 223
222 if (symtab_void && strtab_void) { 224 if (symtab_void && strtab_void) {
223#define FIND_SYM(B) \ 225#define FIND_SYM(B) \
225 Elf ## B ## _Shdr *symtab = SHDR ## B (symtab_void); \ 227 Elf ## B ## _Shdr *symtab = SHDR ## B (symtab_void); \
226 Elf ## B ## _Shdr *strtab = SHDR ## B (strtab_void); \ 228 Elf ## B ## _Shdr *strtab = SHDR ## B (strtab_void); \
227 Elf ## B ## _Sym *sym = SYM ## B (elf->data + EGET(symtab->sh_offset)); \ 229 Elf ## B ## _Sym *sym = SYM ## B (elf->data + EGET(symtab->sh_offset)); \
228 int cnt = EGET(symtab->sh_size) / EGET(symtab->sh_entsize); \ 230 int cnt = EGET(symtab->sh_size) / EGET(symtab->sh_entsize); \
229 char *symname; \ 231 char *symname; \
230 if (be_verbose > 1) \
231 printf("%s: .symtab has %i entries\n", filename, cnt); \
232 for (i = 0; i < cnt; ++i) { \ 232 for (i = 0; i < cnt; ++i) { \
233 if (sym->st_name) { \ 233 if (sym->st_name) { \
234 symname = (char *)(elf->data + EGET(strtab->sh_offset) + EGET(sym->st_name)); \ 234 symname = (char *)(elf->data + EGET(strtab->sh_offset) + EGET(sym->st_name)); \
235 if (*find_sym == '*' || !strcmp(find_sym, symname)) \ 235 if (*find_sym == '*') { \
236 printf("%s: %5lX %15s %s\n", \ 236 printf("%s(%s) %5lX %15s %s\n", ((found_sym == 0) ? "\n\t" : "\t"), \
237 filename, \ 237 (char *) basename(filename), \
238 (long)sym->st_size, \
239 (char *)get_elfstttype(sym->st_info & 0xF), \ 238 (long)sym->st_size, (char *) get_elfstttype(sym->st_info & 0xF), \
240 symname); \ 239 symname); \
240 found_sym = 1; \
241 } \
242 if ((strcmp(find_sym, symname) == 0) || \
243 (strncmp(symname, versioned_symname, strlen(versioned_symname)) == 0)) \
244 found_sym++; \
241 } \ 245 } \
242 ++sym; \ 246 ++sym; \
243 } } 247 } }
244 FIND_SYM(32) 248 FIND_SYM(32)
245 FIND_SYM(64) 249 FIND_SYM(64)
246 } 250 }
251 free(versioned_symname);
252 if (*find_sym != '*')
253 printf(" %s ", (found_sym == 0) ? "-" : find_sym);
247 } 254 }
255
256 if (!be_quiet || found_pax || found_stack || found_textrel || found_rpath)
257 printf("%s\n", filename);
248 258
249 unreadelf(elf); 259 unreadelf(elf);
250} 260}
251 261
252/* scan a directory for ET_EXEC files and print when we find one */ 262/* scan a directory for ET_EXEC files and print when we find one */

Legend:
Removed from v.1.27  
changed lines
  Added in v.1.28

  ViewVC Help
Powered by ViewVC 1.1.20