/[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.206 Revision 1.211
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/Attic/scanelf.c,v 1.206 2008/12/30 13:34:46 vapier Exp $ 4 * $Header: /var/cvsroot/gentoo-projects/pax-utils/Attic/scanelf.c,v 1.211 2009/03/15 09:01:48 vapier 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.206 2008/12/30 13:34:46 vapier Exp $"; 10static const char *rcsid = "$Id: scanelf.c,v 1.211 2009/03/15 09:01:48 vapier 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 == '+')
79static int has_objdump = 0; 79static int has_objdump = 0;
80 80
81/* find the path to a file by name */ 81/* find the path to a file by name */
82static char *which(const char *fname) 82static char *which(const char *fname)
83{ 83{
84 static char fullpath[BUFSIZ]; 84 static char fullpath[__PAX_UTILS_PATH_MAX];
85 char *path, *p; 85 char *path, *p;
86 86
87 path = getenv("PATH"); 87 path = getenv("PATH");
88 if (!path) 88 if (!path)
89 return NULL; 89 return NULL;
473 printf(" [0x%lX]\n", (unsigned long)offset_tmp); \ 473 printf(" [0x%lX]\n", (unsigned long)offset_tmp); \
474 if (be_verbose && has_objdump) { \ 474 if (be_verbose && has_objdump) { \
475 Elf ## B ## _Addr end_addr = offset_tmp + EGET(func->st_size); \ 475 Elf ## B ## _Addr end_addr = offset_tmp + EGET(func->st_size); \
476 char *sysbuf; \ 476 char *sysbuf; \
477 size_t syslen; \ 477 size_t syslen; \
478 int sysret; \
478 const char sysfmt[] = "objdump -r -R -d -w -l --start-address=0x%lX --stop-address=0x%lX %s | grep --color -i -C 3 '.*[[:space:]]%lX:[[:space:]]*R_.*'\n"; \ 479 const char sysfmt[] = "objdump -r -R -d -w -l --start-address=0x%lX --stop-address=0x%lX %s | grep --color -i -C 3 '.*[[:space:]]%lX:[[:space:]]*R_.*'\n"; \
479 syslen = sizeof(sysfmt) + strlen(elf->filename) + 3 * sizeof(unsigned long) + 1; \ 480 syslen = sizeof(sysfmt) + strlen(elf->filename) + 3 * sizeof(unsigned long) + 1; \
480 sysbuf = xmalloc(syslen); \ 481 sysbuf = xmalloc(syslen); \
481 if (end_addr < r_offset) \ 482 if (end_addr < r_offset) \
482 /* not uncommon when things are optimized out */ \ 483 /* not uncommon when things are optimized out */ \
485 (unsigned long)offset_tmp, \ 486 (unsigned long)offset_tmp, \
486 (unsigned long)end_addr, \ 487 (unsigned long)end_addr, \
487 elf->filename, \ 488 elf->filename, \
488 (unsigned long)r_offset); \ 489 (unsigned long)r_offset); \
489 fflush(stdout); \ 490 fflush(stdout); \
490 system(sysbuf); \ 491 sysret = system(sysbuf); \
491 fflush(stdout); \ 492 fflush(stdout); \
492 free(sysbuf); \ 493 free(sysbuf); \
493 } \ 494 } \
494 } \ 495 } \
495 } } 496 } }
1036 if (sym->st_shndx != SHN_UNDEF) \ 1037 if (sym->st_shndx != SHN_UNDEF) \
1037 continue; \ 1038 continue; \
1038 ++this_sym; \ 1039 ++this_sym; \
1039 } \ 1040 } \
1040 if (next_sym) /* Copy it so that we don't have to worry about the final , */ \ 1041 if (next_sym) /* Copy it so that we don't have to worry about the final , */ \
1041 this_sym = strndup(this_sym, next_sym-this_sym); \ 1042 this_sym = xstrndup(this_sym, next_sym-this_sym); \
1042 /* ok, lets compare the name now */ \ 1043 /* ok, lets compare the name now */ \
1043 if (scanelf_match_symname(this_sym, symname)) { \ 1044 if (scanelf_match_symname(this_sym, symname)) { \
1044 if (be_semi_verbose) { \ 1045 if (be_semi_verbose) { \
1045 char buf[126]; \ 1046 char buf[126]; \
1046 snprintf(buf, sizeof(buf), "%lX %s %s", \ 1047 snprintf(buf, sizeof(buf), "%lX %s %s", \
1100 else 1101 else
1101 return (char *)" - "; 1102 return (char *)" - ";
1102} 1103}
1103 1104
1104/* scan an elf file and show all the fun stuff */ 1105/* scan an elf file and show all the fun stuff */
1105#define prints(str) write(fileno(stdout), str, strlen(str)) 1106#define prints(str) ({ ssize_t ret = write(fileno(stdout), str, strlen(str)); ret; })
1106static int scanelf_elfobj(elfobj *elf) 1107static int scanelf_elfobj(elfobj *elf)
1107{ 1108{
1108 unsigned long i; 1109 unsigned long i;
1109 char found_pax, found_phdr, found_relro, found_load, found_textrel, 1110 char found_pax, found_phdr, found_relro, found_load, found_textrel,
1110 found_rpath, found_needed, found_interp, found_bind, found_soname, 1111 found_rpath, found_needed, found_interp, found_bind, found_soname,
1502 1503
1503 fclose(fp); 1504 fclose(fp);
1504 return i; 1505 return i;
1505} 1506}
1506 1507
1507#elif defined(__FreeBSD__) || (__DragonFly__) 1508#elif defined(__FreeBSD__) || defined(__DragonFly__)
1508 1509
1509static int load_ld_cache_config(int i, const char *fname) 1510static int load_ld_cache_config(int i, const char *fname)
1510{ 1511{
1511 FILE *fp = NULL; 1512 FILE *fp = NULL;
1512 char *b = NULL, *p; 1513 char *b = NULL, *p;
1568 err("Unable to load any paths from ld.so.conf"); 1569 err("Unable to load any paths from ld.so.conf");
1569 1570
1570 scan_l = scan_ul = scan_ull = 0; 1571 scan_l = scan_ul = scan_ull = 0;
1571 1572
1572 while (ldpaths[i]) { 1573 while (ldpaths[i]) {
1573 if (!scan_l && !strcmp(ldpaths[i], "/lib")) scan_l = 1; 1574 if (!scan_l && !strcmp(ldpaths[i], "/lib")) scan_l = 1;
1574 if (!scan_ul && !strcmp(ldpaths[i], "/usr/lib")) scan_ul = 1; 1575 if (!scan_ul && !strcmp(ldpaths[i], "/usr/lib")) scan_ul = 1;
1575 if (!scan_ull && !strcmp(ldpaths[i], "/usr/local/lib")) scan_ull = 1; 1576 if (!scan_ull && !strcmp(ldpaths[i], "/usr/local/lib")) scan_ull = 1;
1576 scanelf_dir(ldpaths[i]); 1577 scanelf_dir(ldpaths[i]);
1577 ++i; 1578 ++i;
1578 } 1579 }
1579 1580

Legend:
Removed from v.1.206  
changed lines
  Added in v.1.211

  ViewVC Help
Powered by ViewVC 1.1.20